@camstack/addon-admin-ui 1.2.9 → 1.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AddLocationWizard-BsfRBmG0.js → AddLocationWizard-DJKIj4Vq.js} +1 -1
- package/dist/assets/{AddonCollectionPage-CXHeV-JA.js → AddonCollectionPage-DBwmh-7p.js} +1 -1
- package/dist/assets/Addons-BAVyYmSd.js +1 -0
- package/dist/assets/{AdminTabs-DPHt9Vrr.js → AdminTabs-C86tkpHf.js} +1 -1
- package/dist/assets/{AiProfiles-CrBHGY9x.js → AiProfiles-CwbozdZH.js} +1 -1
- package/dist/assets/{BrokerForm-ySM02NYp.js → BrokerForm-Ceit7i5a.js} +1 -1
- package/dist/assets/{Capabilities-RJVgwEI-.js → Capabilities-DVjMp0LA.js} +1 -1
- package/dist/assets/{CapabilityBadges-BfPStFDD.js → CapabilityBadges-wHMHjcxI.js} +1 -1
- package/dist/assets/Cluster-Bi6Jof0s.js +1 -0
- package/dist/assets/{ClusterRecordingTab-ZjVaVby-.js → ClusterRecordingTab-C60FGsQQ.js} +1 -1
- package/dist/assets/{Dashboard-BZ5hmETC.js → Dashboard-D6Aicmbz.js} +1 -1
- package/dist/assets/{Data-wAV4YBKT.js → Data-6Mll2i9v.js} +1 -1
- package/dist/assets/{DetectionIntelligence-Bg7TpnIp.js → DetectionIntelligence-CI8mQm8z.js} +1 -1
- package/dist/assets/DeviceDetail-CpGmfDch.js +2 -0
- package/dist/assets/{Devices-CfdnyBPp.js → Devices-BTHZe1eP.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-Bcoa9QdA.js → EmbedPlayerPage-C5cjRT3R.js} +1 -1
- package/dist/assets/Events-TCtnhueX.js +1 -0
- package/dist/assets/{FormBuilder-6mYk-4qC.js → FormBuilder-DX4uNlbA.js} +1 -1
- package/dist/assets/Identity-CTvkbYQu.js +1 -0
- package/dist/assets/IntegrationDetail-DVufAZqC.js +1 -0
- package/dist/assets/{Integrations-gznlBNQL.js → Integrations--Ex0QHHn.js} +1 -1
- package/dist/assets/{Integrations-BaTJ1efj.js → Integrations-CP6MwGF_.js} +1 -1
- package/dist/assets/{Logs-BYB5TxRZ.js → Logs-BYdTwtAG.js} +1 -1
- package/dist/assets/{MyAccess-UCG3zSEN.js → MyAccess-BpzdZjnF.js} +1 -1
- package/dist/assets/Network-WWM7yysW.js +1 -0
- package/dist/assets/NodeAddonsSettingsPanel-Zb7zIgPq.js +1 -0
- package/dist/assets/{NodeInferenceDevices-DlG9HB9Y.js → NodeInferenceDevices-Br3NpxU9.js} +1 -1
- package/dist/assets/Notifications-DPOcyXOv.js +1 -0
- package/dist/assets/Pipeline-Bq_zgLIK.js +1 -0
- package/dist/assets/{Plates-Bx_hE0aw.js → Plates-Dg0UQBzd.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-BJvJ34n1.js → PrivacyMaskSettings-H2Rkbk7c.js} +1 -1
- package/dist/assets/{ProviderIcon-CQTRNfxg.js → ProviderIcon-CbniiQ2T.js} +1 -1
- package/dist/assets/{Recordings-Crcm4LyU.js → Recordings-B9VeDyTg.js} +1 -1
- package/dist/assets/{ScanNetworkModal-CXbSxWid.js → ScanNetworkModal-BbMeBlgb.js} +1 -1
- package/dist/assets/{Settings-cYqjCG75.js → Settings-D2du_aL0.js} +1 -1
- package/dist/assets/{Showroom-B6fhw1D9.js → Showroom-B1CeddX4.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CHN43utV.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DNJ_bxKM.js} +1 -1
- package/dist/assets/{build-cluster-graph-BN5pfFK1.js → build-cluster-graph-B2o-tJsx.js} +1 -1
- package/dist/assets/circle-check-big-GofM13qt.js +1 -0
- package/dist/assets/clock-BzqRmwQW.js +1 -0
- package/dist/assets/{copy-BmgVaD29.js → copy-DZq-D128.js} +1 -1
- package/dist/assets/{debounced-invalidate-DCtq_NHc.js → debounced-invalidate-BdSeV9Ur.js} +1 -1
- package/dist/assets/{download-NKkCvEeB.js → download-Bk-h3QfT.js} +1 -1
- package/dist/assets/{face-bbox-C2co2f2G.js → face-bbox-rZ8C-B5u.js} +1 -1
- package/dist/assets/{hostInit-Cfj52F2C.js → hostInit-DNYnPeaE.js} +1 -1
- package/dist/assets/index-BZeaUVWu.js +4 -0
- package/dist/assets/{key-round-Cblg8i0e.js → key-round-CLISgDFt.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-1aa09b03.js → mf-entry-bootstrap-0-d13392b8.js} +2 -2
- package/dist/assets/{pencil-Ik1l3G_8.js → pencil-D1X7sD6V.js} +1 -1
- package/dist/assets/plus-CO0o82bd.js +1 -0
- package/dist/assets/{radio-BtzRHQBo.js → radio-BGOieuIp.js} +1 -1
- package/dist/assets/{refresh-cw-D92Y26QW.js → refresh-cw-CLfX2afX.js} +1 -1
- package/dist/assets/remoteEntry-D6COYK6a.js +1 -0
- package/dist/assets/{rotate-ccw-ByTFEZ8o.js → rotate-ccw-DRI24saO.js} +1 -1
- package/dist/assets/rotate-cw-PcEY8RfB.js +1 -0
- package/dist/assets/search-CZ7LK1Yj.js +1 -0
- package/dist/assets/{send-CGqdmApb.js → send-DSh5Ra_L.js} +1 -1
- package/dist/assets/{server-BwAvkFi_.js → server-BLUgyuUB.js} +1 -1
- package/dist/assets/square-T3rkAjgn.js +1 -0
- package/dist/assets/{square-check-big-tgpBR4IT.js → square-check-big-D_0rGgCa.js} +1 -1
- package/dist/assets/{src-Bwet06Ih.js → src-DvkErVKO.js} +4 -4
- package/dist/assets/{upload-BNU4vgq-.js → upload-x64qPzUI.js} +1 -1
- package/dist/assets/{useEventInvalidation-BslmDCfY.js → useEventInvalidation-DNKOmbzS.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-5Zi8N25y.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DPVzZjZM.js} +2 -2
- package/dist/assets/{wifi-C-i5Y8G3.js → wifi-6r257Xq_.js} +1 -1
- package/dist/assets/{zap-DWRzzBU1.js → zap-DsJvd0xN.js} +1 -1
- package/dist/index.html +3 -3
- package/dist/server/addon.js +1 -1
- package/package.json +1 -1
- package/dist/assets/Addons-CqINXARB.js +0 -1
- package/dist/assets/Cluster-dRepFsEe.js +0 -1
- package/dist/assets/DeviceDetail-DqhElVhT.js +0 -2
- package/dist/assets/Events-DVCiXgvH.js +0 -1
- package/dist/assets/Identity-DoJbe6Tm.js +0 -1
- package/dist/assets/IntegrationDetail-C-TlCYIU.js +0 -1
- package/dist/assets/Network-DL8hq6nl.js +0 -1
- package/dist/assets/NodeAddonsSettingsPanel-DY-AneF0.js +0 -1
- package/dist/assets/Notifications-BKw_GWsb.js +0 -1
- package/dist/assets/Pipeline-cxfq6x3v.js +0 -1
- package/dist/assets/circle-check-big-B9HIwiFo.js +0 -1
- package/dist/assets/clock-HmbKVCZT.js +0 -1
- package/dist/assets/history-CaP7eXW2.js +0 -1
- package/dist/assets/index-RegSp4ae.js +0 -4
- package/dist/assets/plus-B0OPxy2A.js +0 -1
- package/dist/assets/remoteEntry-f6PDtaSI.js +0 -1
- package/dist/assets/rotate-cw-C6p7zQhm.js +0 -1
- package/dist/assets/search-BUbY58eR.js +0 -1
- package/dist/assets/square-Ckdv6ORu.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Ai as e,Ar as t,Br as n,Ha as r,Hr as i,Ir as a,La as o,Lr as s,Rr as c,Vr as l,Wa as u,aa as d,ca as f,co as p,g as m,ia as h,kr as g,lo as _,m as v,oa as y,pi as b,sa as x,so as S,uo as C,zr as w}from"./src-Bwet06Ih.js";import{I as T,K as E,Q as D,S as O,W as k,o as A,q as j,x as M,z as N}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as P}from"./player-overlays-BlOdAA3b.js";import{t as ee}from"./history-CaP7eXW2.js";import{t as F}from"./pencil-Ik1l3G_8.js";import{t as te}from"./radio-BtzRHQBo.js";import{t as I}from"./refresh-cw-D92Y26QW.js";import{t as L}from"./rotate-cw-C6p7zQhm.js";import{t as R}from"./server-BwAvkFi_.js";import{t as ne}from"./upload-BNU4vgq-.js";import{B as re,I as ie,L as ae,P as oe,S as z,W as B,i as V,j as H,m as U,o as W,s as G,t as K}from"./index-RegSp4ae.js";import{n as q,t as se}from"./build-cluster-graph-BN5pfFK1.js";import{t as J}from"./format-size-CO9d3C3-.js";import{t as ce}from"./NodeAddonsSettingsPanel-DY-AneF0.js";var Y=B(`arrow-down-to-line`,[[`path`,{d:`M12 17V3`,key:`1cwfxf`}],[`path`,{d:`m6 11 6 6 6-6`,key:`12ii2o`}],[`path`,{d:`M19 21H5`,key:`150jfl`}]]),le=B(`git-fork`,[[`circle`,{cx:`12`,cy:`18`,r:`3`,key:`1mpf1b`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`path`,{d:`M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9`,key:`1uq4wg`}],[`path`,{d:`M12 12v3`,key:`158kv8`}]]),ue=B(`hard-drive-download`,[[`path`,{d:`M12 2v8`,key:`1q4o3n`}],[`path`,{d:`m16 6-4 4-4-4`,key:`6wukr`}],[`rect`,{width:`20`,height:`8`,x:`2`,y:`14`,rx:`2`,key:`w68u3i`}],[`path`,{d:`M6 18h.01`,key:`uhywen`}],[`path`,{d:`M10 18h.01`,key:`h775k`}]]),de=B(`memory-stick`,[[`path`,{d:`M6 19v-3`,key:`1nvgqn`}],[`path`,{d:`M10 19v-3`,key:`iu8nkm`}],[`path`,{d:`M14 19v-3`,key:`kcehxu`}],[`path`,{d:`M18 19v-3`,key:`1vh91z`}],[`path`,{d:`M8 11V9`,key:`63erz4`}],[`path`,{d:`M16 11V9`,key:`fru6f3`}],[`path`,{d:`M12 11V9`,key:`ha00sb`}],[`path`,{d:`M2 15h20`,key:`16ne18`}],[`path`,{d:`M2 7a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v1.1a2 2 0 0 0 0 3.837V17a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-5.1a2 2 0 0 0 0-3.837Z`,key:`lhddv3`}]]),X=B(`skull`,[[`path`,{d:`m12.5 17-.5-1-.5 1h1z`,key:`3me087`}],[`path`,{d:`M15 22a1 1 0 0 0 1-1v-1a2 2 0 0 0 1.56-3.25 8 8 0 1 0-11.12 0A2 2 0 0 0 8 20v1a1 1 0 0 0 1 1z`,key:`1o5pge`}],[`circle`,{cx:`15`,cy:`12`,r:`1`,key:`1tmaij`}],[`circle`,{cx:`9`,cy:`12`,r:`1`,key:`1vctgf`}]]),fe=B(`table-2`,[[`path`,{d:`M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18`,key:`gugj83`}]]);D();function pe(e){let t=new FormData;return t.append(`file`,e.file,e.file.name),t.append(`nodeId`,e.nodeId),e.addonId&&t.append(`addonId`,e.addonId),new Promise((n,r)=>{let i=new XMLHttpRequest;i.open(`POST`,`/api/addons/upload`),e.token&&i.setRequestHeader(`Authorization`,`Bearer ${e.token}`),i.upload.addEventListener(`progress`,t=>{t.lengthComputable&&e.onProgress(Math.round(t.loaded/t.total*100))}),i.addEventListener(`load`,()=>{let e;try{e=JSON.parse(i.responseText)}catch{r(Error(`HTTP ${i.status}`));return}i.status>=200&&i.status<300?n(e):r(Error(e.error??`HTTP ${i.status}`))}),i.addEventListener(`error`,()=>r(Error(`Network error during upload`))),i.addEventListener(`abort`,()=>r(Error(`Upload aborted`))),i.send(t)})}function me({nodeId:e,addons:t,isHub:n}){let r=A(),s=o(),[l,u]=j(null),[d,f]=j(null),[p,m]=j(!1),[h,g]=j(null),[_,v]=j(0),y=E(null),b=c(),x=i(),S=a({nodeId:e}),C=S.data??[],w=new Map(t.map(e=>[e.id,e.capabilities])),T=C.length>0?C.map(e=>({id:e.id,status:e.status,capabilities:w.get(e.id)??[],version:e.version,packageName:e.packageName})):t.map(e=>({id:e.id,status:e.status,capabilities:e.capabilities,version:void 0,packageName:void 0})),D=()=>{r.invalidateQueries({queryKey:[[`nodes`,`topology`]]}),S.refetch()},k=async t=>{u(t);try{await b.mutateAsync({nodeId:e,addonId:t}),D()}catch(e){console.error(`Failed to restart addon:`,e)}finally{u(null)}},N=async t=>{if(await s({title:`Uninstall addon`,message:`Remove "${t}" from ${e}? The addon directory will be deleted on disk.`,confirmLabel:`Uninstall`,variant:`danger`})){f(t);try{await x.mutateAsync({nodeId:e,addonId:t}),D()}catch(e){console.error(`Failed to uninstall addon:`,e)}finally{f(null)}}},P=O(`div`,{className:`flex items-center gap-2 mb-2`,children:[M(`input`,{ref:y,type:`file`,accept:`.tgz,.tar.gz`,className:`hidden`,onChange:async t=>{let n=t.target.files?.[0];if(n){t.target.value=``,g(null),m(!0),v(0);try{await pe({file:n,nodeId:e,token:localStorage.getItem(`camstack_admin_token`),onProgress:v}),D()}catch(e){g(e instanceof Error?e.message:String(e))}finally{m(!1),v(0)}}}}),O(`button`,{onClick:()=>y.current?.click(),disabled:p,className:`inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[p?M(z,{className:`h-3 w-3 animate-spin`}):M(ne,{className:`h-3 w-3`}),p?`Uploading… ${_}%`:`Upload addon (.tgz)`]}),p&&M(`div`,{className:`flex-1 h-1 rounded-full bg-muted overflow-hidden max-w-[140px]`,children:M(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${_}%`}})}),h&&M(`span`,{className:`text-[10px] text-destructive`,children:h})]});return T.length===0?O(`div`,{children:[P,M(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:S.isLoading?`Loading addons…`:`No addons on this node`})]}):O(`div`,{children:[P,O(`table`,{className:`w-full text-xs`,children:[M(`thead`,{children:O(`tr`,{className:`text-muted-foreground text-left`,children:[M(`th`,{className:`py-2 font-medium`,children:`Addon`}),M(`th`,{className:`py-2 font-medium`,children:`Version`}),M(`th`,{className:`py-2 font-medium`,children:`Capabilities`}),M(`th`,{className:`py-2 font-medium`,children:`Status`}),M(`th`,{className:`py-2 font-medium w-16`})]})}),M(`tbody`,{children:T.map(e=>O(`tr`,{className:`border-t border-border/50`,children:[O(`td`,{className:`py-2 font-medium`,children:[M(`div`,{children:e.id}),e.packageName&&M(`div`,{className:`text-[9px] text-muted-foreground`,children:e.packageName})]}),M(`td`,{className:`py-2 text-muted-foreground`,children:e.version??`—`}),M(`td`,{className:`py-2`,children:M(`div`,{className:`flex flex-wrap gap-1`,children:e.capabilities.length>0?e.capabilities.map(e=>M(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400`,children:e},e)):M(`span`,{className:`text-muted-foreground`,children:`—`})})}),M(`td`,{className:`py-2`,children:M(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e.status===`running`?`bg-success/10 text-success`:e.status===`error`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e.status})}),M(`td`,{className:`py-2`,children:O(`div`,{className:`flex items-center gap-1 justify-end`,children:[M(`button`,{onClick:()=>k(e.id),disabled:l===e.id||d===e.id,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.id}`,children:M(L,{className:`h-3 w-3 ${l===e.id?`animate-spin`:``}`})}),M(`button`,{onClick:()=>N(e.id),disabled:l===e.id||d===e.id,className:`p-1 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50`,title:`Uninstall ${e.id}`,children:d===e.id?M(z,{className:`h-3 w-3 animate-spin`}):M(G,{className:`h-3 w-3`})})]})})]},e.id))})]})]})}D();function he(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60);return n<24?`${n}h ${t%60}m`:`${Math.floor(n/24)}d ${n%24}h`}function ge({state:e}){return M(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e===`running`?`bg-success/10 text-success`:e===`crashed`||e===`failed`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e})}var _e=[`trace`,`debug`,`info`,`warn`,`error`];function ve({proc:e,nodeId:t,defaultExpanded:r,activePanel:i,onTogglePanel:a}){let o=e.services??[],s=o.length===1,[l,u]=j(s||r),[d,f]=j(null),[h,g]=j(`info`),y=e.name.includes(`(core)`),b=c(),x=w(),T=n(),E=async e=>{f(e);try{await b.mutateAsync({nodeId:t,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{f(null)}},D=async()=>{f(e.name);try{await x.mutateAsync({nodeId:t,processName:e.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{f(null)}},k=async n=>{let r=`${t}/${e.name}`;try{await T.mutateAsync({nodeId:r,level:n}),g(n)}catch(e){console.error(`Failed to set log level:`,e)}};return O(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[O(`div`,{role:s?void 0:`button`,tabIndex:s?void 0:0,onClick:s?void 0:()=>u(!l),onKeyDown:s?void 0:e=>{(e.key===`Enter`||e.key===` `)&&u(!l)},className:`flex items-center gap-2 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${s?``:`hover:bg-muted/40 cursor-pointer`}`,children:[s?M(`span`,{className:`h-3 w-3 shrink-0`}):M(l?ie:oe,{className:`h-3 w-3 text-muted-foreground shrink-0`}),y?M(R,{className:`h-3.5 w-3.5 text-primary shrink-0`}):M(re,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),M(`span`,{className:`text-xs font-semibold flex-1`,children:e.name}),O(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[`PID `,e.pid]}),M(ge,{state:e.state}),O(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[e.cpuPercent,`% CPU`]}),M(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:J(e.memoryRss)}),M(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:he(e.uptimeSeconds)}),!y&&O(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[O(S,{children:[M(C,{className:`text-[9px] px-1.5 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors font-mono`,title:`Set log level`,children:h}),M(p,{align:`end`,className:`min-w-[70px] py-0.5`,children:_e.map(e=>M(_,{onClick:()=>k(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===h?`text-primary font-semibold`:``}`,children:e},e))})]}),M(`button`,{onClick:D,disabled:d===e.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart process`,children:M(L,{className:`h-3 w-3 ${d===e.name?`animate-spin`:``}`})})]})]}),l&&o.length>0&&M(`div`,{className:`divide-y divide-border/30`,children:o.map(e=>O(`div`,{children:[O(`div`,{className:`flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors`,children:[M(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`running`?`bg-success`:`bg-muted-foreground/30`}`}),M(`span`,{className:`text-xs font-medium flex-1 min-w-0 truncate`,children:e.addonId}),e.capabilities.length>0&&O(`div`,{className:`flex gap-1 flex-shrink-0`,children:[e.capabilities.slice(0,3).map(e=>M(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400 truncate max-w-[80px]`,children:e},e)),e.capabilities.length>3&&O(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,e.capabilities.length-3]})]}),O(`div`,{className:`flex items-center gap-1 shrink-0`,children:[M(`button`,{onClick:()=>a(e.addonId,`logs`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`logs`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show logs for ${e.addonId}`,children:M(U,{className:`h-3 w-3`})}),M(`button`,{onClick:()=>a(e.addonId,`events`),className:`p-0.5 rounded transition-colors ${i?.addonId===e.addonId&&i.type===`events`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show events for ${e.addonId}`,children:M(te,{className:`h-3 w-3`})}),M(`button`,{onClick:()=>E(e.addonId),disabled:d===e.addonId,className:`p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.addonId}`,children:M(L,{className:`h-3 w-3 ${d===e.addonId?`animate-spin`:``}`})})]})]}),i?.addonId===e.addonId&&i.type===`logs`&&M(`div`,{className:`border-t border-border/40 bg-muted/5`,children:M(m,{addonId:e.addonId,agentId:t,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>a(e.addonId,`logs`)})}),i?.addonId===e.addonId&&i.type===`events`&&M(`div`,{className:`border-t border-border/40 bg-muted/5`,children:M(v,{addonId:e.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>a(e.addonId,`events`)})})]},e.addonId))}),l&&o.length===0&&M(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:`No services`})]})}function ye({nodeId:e,processes:t}){let[n,r]=j(null),i=(e,t)=>{r(n=>n?.addonId===e&&n.type===t?null:{addonId:e,type:t})};return t.length===0?M(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No processes on this node`}):M(`div`,{className:`space-y-2 py-1`,children:t.map((t,r)=>M(ve,{proc:t,nodeId:e,defaultExpanded:r===0,activePanel:n,onTogglePanel:i},t.name))})}D();function be(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m ${e%60}s`:e<86400?`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`:`${Math.floor(e/86400)}d ${Math.floor(e%86400/3600)}h`}function xe(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function Se({nodeId:e}){let n=A(),i=o(),[a,s]=j(`all`),c=r(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:l}=t({nodeId:e}),u=c?.processes??l,d=k(()=>u?[...u]:[],[u]),f=k(()=>a===`ghost`?d.filter(e=>e.classification===`ghost`):d,[d,a]),p=k(()=>{let e=d.filter(e=>e.classification===`ghost`),t=new Map;for(let n of e)t.has(n.ppid)||t.set(n.ppid,[]),t.get(n.ppid).push(n);return[...t.entries()].filter(([,e])=>e.length>1).map(([e,t])=>({ppid:e,children:t})).toSorted((e,t)=>t.children.length-e.children.length)},[d]),m=g({onSettled:()=>{n.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]})}}),h=k(()=>{let e=new Map;for(let t of d)e.set(t.pid,t.classification);return e},[d]),_=async(t,n)=>{if(t.classification===`root`||t.classification===`system`)return;let r=t.classification===`ghost`?`ghost`:t.addonId??`process`,a=n?`SIGKILL`:`SIGTERM`;await i({title:`Send ${a}?`,message:`Target pid ${t.pid} (${r}) on node ${e}.`,confirmLabel:`Send ${a}`,variant:`danger`})&&m.mutate({nodeId:e,pid:t.pid,force:n})},v=async(t,n)=>{try{await m.mutateAsync({nodeId:e,pid:t,force:n})}catch{}},y=async t=>{let r=h.get(t.ppid);if(r===`root`||r===`system`){await i({title:`Cannot kill protected ancestor`,message:r===`root`?`pid ${t.ppid} is the current node supervisor. Restart the node via the cluster page instead.`:`pid ${t.ppid} is a system ancestor (concurrently / vite / npm wrapper). Killing it would tear down the dev tree.`,confirmLabel:`OK`,cancelLabel:`Close`,variant:`warning`});return}await i({title:`Kill ghost parent + ${t.children.length} child(ren)?`,message:`SIGKILL parent pid ${t.ppid} and SIGTERM ${t.children.length} ghost child(ren) on node ${e}.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all([v(t.ppid,!0),...t.children.map(e=>v(e.pid,!1))]),n.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},b=async()=>{let t=d.filter(e=>e.classification===`ghost`);t.length!==0&&await i({title:`Kill all ${t.length} ghost process(es)?`,message:`SIGKILL ${t.length} ghost process(es) on node ${e}. This is irreversible.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all(t.map(e=>v(e.pid,!0))),n.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},x=d.filter(e=>e.classification===`ghost`).length,S=d.filter(e=>e.classification===`managed`).length,C=d.filter(e=>e.classification===`root`).length,w=d.filter(e=>e.classification===`system`).length;return O(`div`,{className:`space-y-4`,children:[O(`div`,{className:`flex items-start justify-between gap-4`,children:[O(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`ps`," scan + kernel `$process.list` cross-reference. Ghosts = camstack-shaped commands with no managed binding (usually orphaned to ppid=1). Refreshes every 10s."]}),O(`button`,{type:`button`,onClick:()=>n.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}),className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[M(I,{className:`h-3 w-3`}),` Refresh`]})]}),O(`div`,{className:`grid grid-cols-4 gap-3`,children:[O(`div`,{className:`rounded-lg border border-border p-3`,children:[M(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Root`}),M(`div`,{className:`text-xl font-semibold text-foreground`,children:C})]}),O(`div`,{className:`rounded-lg border border-border p-3`,children:[M(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Managed`}),M(`div`,{className:`text-xl font-semibold text-foreground`,children:S})]}),O(`div`,{className:`rounded-lg border border-border p-3`,children:[M(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`System`}),M(`div`,{className:`text-xl font-semibold text-foreground`,children:w})]}),O(`div`,{className:`rounded-lg border p-3 ${x>0?`border-destructive/40 bg-destructive/5`:`border-border`}`,children:[O(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle flex items-center gap-1`,children:[x>0&&M(X,{className:`h-3 w-3 text-destructive`}),` Ghosts`]}),M(`div`,{className:`text-xl font-semibold ${x>0?`text-destructive`:`text-foreground`}`,children:x})]})]}),p.length>0&&O(`div`,{className:`rounded-lg border border-amber-500/40 bg-amber-500/5 p-3`,children:[O(`div`,{className:`flex items-center gap-1 text-[11px] font-semibold text-amber-400 mb-2`,children:[M(W,{className:`h-3 w-3`}),` Recurring ghost parents (`,p.length,`)`]}),M(`div`,{className:`space-y-1.5`,children:p.map(e=>O(`div`,{className:`text-[11px] text-foreground flex items-center justify-between gap-2`,children:[O(`div`,{className:`flex items-center gap-2`,children:[O(`span`,{className:`font-mono text-foreground-subtle`,children:[`ppid `,e.ppid]}),O(`span`,{children:[`→ `,e.children.length,` ghost(s)`]})]}),O(`button`,{type:`button`,disabled:m.isPending,onClick:()=>{y(e)},className:`inline-flex items-center gap-1 rounded border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 text-[10px] text-amber-400 hover:bg-amber-500/20 disabled:opacity-30`,children:[M(X,{className:`h-3 w-3`}),` Kill parent + `,e.children.length]})]},e.ppid))})]}),O(`div`,{className:`flex items-center justify-between gap-2 text-[11px]`,children:[O(`div`,{className:`flex items-center gap-2`,children:[M(`span`,{className:`text-foreground-subtle`,children:`Filter:`}),O(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${a===`all`?`bg-primary text-primary-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>s(`all`),children:[`All (`,d.length,`)`]}),O(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${a===`ghost`?`bg-destructive text-destructive-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>s(`ghost`),children:[`Ghost only (`,x,`)`]})]}),x>0&&O(`button`,{type:`button`,disabled:m.isPending,onClick:()=>{b()},className:`inline-flex items-center gap-1 rounded border border-destructive/40 bg-destructive/10 px-2 py-1 text-[11px] font-medium text-destructive hover:bg-destructive/20 disabled:opacity-30`,children:[M(X,{className:`h-3 w-3`}),` Kill all `,x,` ghost(s)`]})]}),M(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:O(`table`,{className:`w-full text-xs`,children:[M(`thead`,{className:`bg-surface`,children:O(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[M(`th`,{className:`text-left px-3 py-2`,children:`Class`}),M(`th`,{className:`text-right px-3 py-2`,children:`PID`}),M(`th`,{className:`text-right px-3 py-2`,children:`PPID`}),M(`th`,{className:`text-left px-3 py-2`,children:`Addon`}),M(`th`,{className:`text-left px-3 py-2`,children:`Command`}),M(`th`,{className:`text-right px-3 py-2`,children:`CPU%`}),M(`th`,{className:`text-right px-3 py-2`,children:`RSS`}),M(`th`,{className:`text-right px-3 py-2`,children:`Uptime`}),M(`th`,{className:`w-44`})]})}),O(`tbody`,{children:[f.length===0&&M(`tr`,{children:M(`td`,{colSpan:9,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:a===`ghost`?`No ghost processes detected.`:`Scanning…`})}),f.map(e=>O(`tr`,{className:`border-t border-border ${e.classification===`ghost`?`bg-destructive/5`:``}`,children:[M(`td`,{className:`px-3 py-2`,children:M(`span`,{className:`inline-block rounded-full px-1.5 py-0.5 text-[10px] font-medium ${e.classification===`ghost`?`bg-destructive/20 text-destructive`:e.classification===`root`?`bg-sky-500/20 text-sky-400`:e.classification===`system`?`bg-foreground-subtle/20 text-foreground-subtle`:`bg-success/20 text-success`}`,children:e.classification})}),M(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.pid}),O(`td`,{className:`px-3 py-2 text-right font-mono text-foreground-subtle`,children:[e.ppid,e.orphaned?` ⚠`:``]}),M(`td`,{className:`px-3 py-2 text-foreground-subtle text-[11px]`,children:e.addonId??`—`}),M(`td`,{className:`px-3 py-2 font-mono text-[10px] text-foreground-subtle break-all`,children:xe(e.command)}),M(`td`,{className:`px-3 py-2 text-right text-foreground`,children:e.cpuPercent.toFixed(1)}),M(`td`,{className:`px-3 py-2 text-right text-foreground`,children:J(e.memoryRssBytes)}),M(`td`,{className:`px-3 py-2 text-right text-foreground-subtle`,children:be(e.uptimeSec)}),M(`td`,{className:`px-3 py-2 text-right`,children:O(`div`,{className:`inline-flex gap-1`,children:[O(`button`,{type:`button`,disabled:m.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{_(e,!1)},title:`SIGTERM`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-border text-[10px] text-foreground hover:bg-surface-hover disabled:opacity-30`,children:[M(G,{className:`h-3 w-3`}),` Term`]}),O(`button`,{type:`button`,disabled:m.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{_(e,!0)},title:`SIGKILL`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-destructive/30 text-[10px] text-destructive hover:bg-destructive/10 disabled:opacity-30`,children:[M(X,{className:`h-3 w-3`}),` Kill`]})]})})]},e.pid))]})]})}),m.isError&&O(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,m.error instanceof Error?m.error.message:`unknown`]})]})}function Z({nodeId:e,addonIds:t}){return t.length===0?M(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No addons on this node`}):M(`div`,{className:`w-full py-2`,children:M(ce,{nodeId:e,addonIds:t,level:`global`})})}D();function Ce({nodeId:t,addons:n}){let r=A(),{data:i,isLoading:a}=b({nodeId:t}),o=k(()=>{let e=new Map;for(let t of n)for(let n of t.capabilities){let r=e.get(n)??[];r.push(t.id),e.set(n,r)}return[...e.entries()].toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({capName:e,providers:t}))},[n]),s=e({onSuccess:()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCapabilityBindings`]]})}});return o.length===0?M(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No capabilities on this node`}):O(`table`,{className:`w-full text-xs`,children:[M(`thead`,{children:O(`tr`,{className:`text-muted-foreground text-left`,children:[M(`th`,{className:`py-2 font-medium w-1/2`,children:`Capability`}),M(`th`,{className:`py-2 font-medium`,children:`Bound provider`})]})}),M(`tbody`,{children:o.map(({capName:e,providers:n})=>{let r=i?.[e]??n[0]??``,o=n.length===1;return O(`tr`,{className:`border-t border-border/50`,children:[M(`td`,{className:`py-2 font-medium`,children:e}),M(`td`,{className:`py-2`,children:M(`select`,{value:r,onChange:n=>s.mutate({nodeId:t,capName:e,addonId:n.target.value}),disabled:o||s.isPending||a,className:`w-full rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-60`,title:o?`Only one provider installed — choice becomes available once a second addon registers this capability`:void 0,children:n.map(e=>M(`option`,{value:e,children:e},e))})})]},e)})})]})}D();function we(e){if(e==null)return`—`;let t=Math.floor(e/1e3),n=Math.floor(t/86400),r=Math.floor(t%86400/3600),i=Math.floor(t%3600/60);return n>0?`${n}d ${r}h ${i}m`:r>0?`${r}h ${i}m`:`${i}m`}function Te(e){let[t,n]=j(!1),[r,i]=j(e.name),a=A(),o=s({onSuccess:()=>{a.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}}),c=(e.localIps??[]).filter(e=>!e.includes(`:`)),l=(e.localIps??[]).filter(e=>e.includes(`:`)),u=async()=>{if(!r.trim()||r===e.name){n(!1);return}try{await o.mutateAsync({nodeId:e.nodeId,name:r.trim()}),n(!1)}catch(e){console.error(`Rename failed:`,e)}},d=[[`Node ID`,M(`span`,{className:`font-mono text-xs`,children:e.nodeId})],[`Display Name`,t?O(`div`,{className:`flex items-center gap-1.5`,children:[M(`input`,{type:`text`,className:`flex-1 px-2 py-0.5 text-xs border border-border rounded bg-background focus:outline-none focus:ring-1 focus:ring-primary`,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&u(),e.key===`Escape`&&n(!1)},disabled:o.isPending,autoFocus:!0}),M(`button`,{onClick:()=>void u(),disabled:o.isPending,className:`p-0.5 text-success hover:bg-success/10 rounded`,title:`Save`,children:M(ae,{className:`h-3.5 w-3.5`})}),M(`button`,{onClick:()=>n(!1),className:`p-0.5 text-muted-foreground hover:bg-muted rounded`,title:`Cancel`,children:M(V,{className:`h-3.5 w-3.5`})})]}):O(`div`,{className:`flex items-center gap-1.5`,children:[M(`span`,{className:`text-xs`,children:e.name}),!e.isHub&&M(`button`,{onClick:()=>{i(e.name),n(!0)},className:`p-0.5 text-muted-foreground hover:text-primary rounded`,title:`Rename`,children:M(F,{className:`h-3 w-3`})})]})],[`Hostname`,M(`span`,{className:`text-xs`,children:e.hostname})],[`Role`,e.isHub?M(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary font-medium`,children:`Hub`}):M(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium`,children:`Agent`})],[`Root Package`,e.rootPackage?O(`span`,{className:`font-mono text-xs`,children:[e.rootPackage.name,`@`,e.rootPackage.version]}):M(`span`,{className:`text-xs text-muted-foreground`,children:`—`})],[`Platform`,O(`span`,{className:`text-xs`,children:[e.platform,` / `,e.arch]})],[`CPU`,O(`span`,{className:`text-xs`,children:[e.cpuModel??`—`,` (`,e.cpuCores,` cores)`]})],[`Memory`,M(`span`,{className:`text-xs`,children:e.memoryMB>0?`${(e.memoryMB/1024).toFixed(1)} GB`:`—`})],[`Uptime`,M(`span`,{className:`text-xs`,children:we(e.uptime)})],[`Engines`,e.engines.length>0?M(`div`,{className:`flex flex-wrap gap-1`,children:e.engines.map(e=>M(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e))}):M(`span`,{className:`text-xs text-muted-foreground`,children:`—`})]];return c.length>0&&d.push([`IPv4`,M(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map((e,t)=>M(`span`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted`,children:e},`${e}-${t}`))})]),l.length>0&&d.push([`IPv6`,M(`div`,{className:`flex flex-wrap gap-1.5`,children:l.map((e,t)=>M(`span`,{className:`font-mono text-[10px] px-1.5 py-0.5 rounded bg-muted truncate max-w-[280px]`,title:e,children:e},`${e}-${t}`))})]),M(`div`,{className:`py-2`,children:M(`table`,{className:`w-full text-sm`,children:M(`tbody`,{children:d.map(([e,t],n)=>O(`tr`,{className:n%2==0?`bg-muted/20`:``,children:[M(`td`,{className:`py-1.5 px-2 text-xs font-medium text-muted-foreground w-28 align-top whitespace-nowrap`,children:e}),M(`td`,{className:`py-1.5 px-2`,children:t})]},e))})})})}D();var Ee=[[`serverManagement`,`getServerPackageStatus`]];function Q({label:e,tone:t}){return M(`span`,{className:`inline-flex items-center rounded px-2 py-0.5 text-[11px] font-medium ${{neutral:`bg-surface-muted text-foreground-subtle`,ok:`bg-emerald-500/15 text-emerald-500`,info:`bg-sky-500/15 text-sky-500`,warn:`bg-amber-500/15 text-amber-500`,error:`bg-red-500/15 text-red-500`}[t]}`,children:e})}function $({label:e,value:t}){return O(`div`,{className:`flex items-center justify-between gap-4 text-sm`,children:[M(`span`,{className:`text-foreground-subtle`,children:e}),M(`span`,{className:`font-mono text-foreground`,children:t??`—`})]})}function De({node:e}){let{t}=K(),n=A(),r=o(),[i,a]=j(!1),s=e.isHub?void 0:{nodeId:e.id},c=y(s,{refetchInterval:1e4,enabled:e.isOnline,retry:1}),l=c.data??null,u=T(()=>{n.invalidateQueries({queryKey:Ee})},[n]),p=d({onSettled:u}),m=h({onSettled:u}),g=f({onSettled:u}),_=x({onSettled:u}),v=T(async()=>{l?.latestVersion!=null&&await r({title:t(`serverManagement.confirmUpdateTitle`,`Update node root package`),message:t(`serverManagement.confirmUpdateBody`,`Install {{pkg}}@{{version}} on node "{{node}}" and restart it to apply. The new version boots on probation: if it fails to reach ready, the node automatically rolls back to the current version. Requires an always-relaunching supervisor (Docker restart policy "unless-stopped" or "always"), otherwise the node stays down after exiting to apply.`,{pkg:l.packageName,version:l.latestVersion,node:e.name}),confirmLabel:t(`serverManagement.confirmUpdateAction`,`Update & restart`)})&&(await m.mutateAsync({version:l.latestVersion,...s})).restarting&&a(!0)},[m,r,e.name,s,l,t]),b=T(async()=>{l?.previousVersion!=null&&await r({title:t(`serverManagement.confirmRollbackTitle`,`Roll back node root package`),message:t(`serverManagement.confirmRollbackBody`,`Restart node "{{node}}" on the previous version ({{version}})?`,{node:e.name,version:l.previousVersion}),confirmLabel:t(`serverManagement.confirmRollbackAction`,`Roll back & restart`)})&&(await g.mutateAsync(s)).restarting&&a(!0)},[r,e.name,g,s,l,t]),S=T(async()=>{await r({title:t(`serverManagement.confirmRestartTitle`,`Restart node`),message:t(`serverManagement.confirmRestartBody`,`Restart node "{{node}}" now? The process exits and its supervisor relaunches it on the same version. In-flight requests to this node are dropped.`,{node:e.name}),confirmLabel:t(`serverManagement.confirmRestartAction`,`Restart`),variant:`warning`})&&(await _.mutateAsync(s)).restarting&&a(!0)},[r,e.name,_,s,t]),C=()=>{switch(l?.bootMode){case`data-root`:return{label:t(`serverManagement.bootDataRoot`,`runtime-updatable`),tone:`ok`};case`workspace`:return{label:t(`serverManagement.bootWorkspace`,`dev workspace`),tone:`info`};default:return{label:t(`serverManagement.bootBaked`,`baked image seed`),tone:`neutral`}}},w=()=>{if(l==null)return null;if(l.rolledBack!=null)return{label:t(`serverManagement.stateRolledBack`,`rolled back (update failed)`),tone:`error`};switch(l.updateState){case`checking`:return{label:t(`serverManagement.stateChecking`,`checking…`),tone:`info`};case`staging`:return{label:t(`serverManagement.stateStaging`,`updating…`),tone:`info`};case`pending-restart`:return{label:t(`serverManagement.statePending`,`restart pending`),tone:`warn`};case`awaiting-confirmation`:return{label:t(`serverManagement.stateAwaitingConfirmation`,`awaiting confirmation`),tone:`warn`};default:return l.updateAvailable?{label:t(`serverManagement.stateUpdateAvailable`,`update available`),tone:`warn`}:{label:t(`serverManagement.stateUpToDate`,`up to date`),tone:`ok`}}},E=l?.bootMode===`workspace`,D=e.isOnline&&l!=null&&!E&&l.updateAvailable&&l.updateState===`idle`&&!m.isPending,k=e.isOnline&&l!=null&&!E&&l.previousVersion!=null&&l.updateState===`idle`&&!g.isPending,N=e.isOnline&&l!=null&&l.updateState===`idle`&&!_.isPending,P=e.isOnline?w():null;return O(`div`,{className:`space-y-4 py-2`,children:[O(`div`,{className:`flex items-center justify-between gap-3`,children:[O(`div`,{className:`flex items-center gap-2 min-w-0`,children:[M(`span`,{className:`font-mono text-xs text-foreground-subtle truncate`,children:l?.packageName??e.rootPackage?.name??`@camstack/server`}),e.isOnline&&l!=null&&M(Q,{...C()})]}),P!=null&&M(Q,{...P})]}),!e.isOnline&&M($,{label:t(`serverManagement.lastReportedVersion`,`Last reported version`),value:e.rootPackage?.version??null}),e.isOnline&&c.isLoading&&O(`div`,{className:`flex items-center gap-2 text-sm text-foreground-subtle`,children:[M(z,{className:`h-4 w-4 animate-spin`}),t(`common.loading`,`Loading…`)]}),e.isOnline&&c.isError&&O(`div`,{className:`space-y-1.5`,children:[M(`p`,{className:`text-sm text-red-500`,children:t(`serverManagement.loadError`,`Could not load the node root-package status.`)}),e.rootPackage!=null&&M($,{label:t(`serverManagement.lastReportedVersion`,`Last reported version`),value:e.rootPackage.version})]}),e.isOnline&&l!=null&&O(`div`,{className:`space-y-1.5`,children:[M($,{label:t(`serverManagement.runningVersion`,`Running version`),value:l.runningVersion}),M($,{label:t(`serverManagement.latestVersion`,`Latest on registry`),value:l.latestVersion}),M($,{label:t(`serverManagement.previousVersion`,`Previous (rollback target)`),value:l.previousVersion}),M($,{label:t(`serverManagement.seedVersion`,`Image seed version`),value:l.seedVersion}),M($,{label:t(`serverManagement.nodeRuntimeVersion`,`Node.js runtime`),value:l.nodeRuntimeVersion}),l.pendingVersion!=null&&M($,{label:t(`serverManagement.pendingVersion`,`Staged (applies on restart)`),value:l.pendingVersion})]}),e.isOnline&&l?.updateState===`awaiting-confirmation`&&M(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 p-2.5 text-xs text-amber-500`,children:t(`serverManagement.awaitingConfirmationWarning`,`This node restarted onto {{version}} and is confirming boot health — avoid restarting it now. Update and rollback are temporarily unavailable until the probation boot confirms; a manual restart during this window would auto-roll-back the update.`,{version:l.pendingVersion??l.runningVersion??``})}),e.isOnline&&l?.stateFileCorrupt===!0&&M(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 p-2.5 text-xs text-amber-500`,children:t(`serverManagement.stateCorruptWarning`,`The server-root state file on this node is corrupt — it booted from the baked seed and any installed data-directory versions are being ignored. Applying an update will rewrite the state file.`)}),e.isOnline&&l?.rolledBack!=null&&M(`div`,{className:`rounded border border-red-500/30 bg-red-500/10 p-2.5 text-xs text-red-400`,children:t(`serverManagement.rolledBackDetail`,`Update to {{from}} failed and was rolled back to {{to}}: {{reason}}`,{from:l.rolledBack.fromVersion,to:l.rolledBack.toVersion??t(`serverManagement.bakedSeed`,`the baked seed`),reason:l.rolledBack.reason})}),e.isOnline&&E&&M(`p`,{className:`text-xs text-foreground-subtle`,children:t(`serverManagement.workspaceNote`,`Development workspace detected — runtime updates are disabled (the dev loop resolves code from the workspace).`)}),i&&O(`div`,{className:`flex items-center gap-2 text-sm text-amber-500`,children:[M(z,{className:`h-4 w-4 animate-spin`}),t(`serverManagement.nodeRestarting`,`The node is restarting to apply the change…`)]}),e.isOnline&&O(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[O(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-surface-muted disabled:opacity-50`,disabled:p.isPending||l?.updateState===`staging`,onClick:()=>p.mutate(s),children:[p.isPending?M(z,{className:`h-3.5 w-3.5 animate-spin`}):M(I,{className:`h-3.5 w-3.5`}),t(`serverManagement.checkForUpdate`,`Check for update`)]}),D&&O(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-2.5 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50`,onClick:()=>void v(),children:[m.isPending?M(z,{className:`h-3.5 w-3.5 animate-spin`}):M(Y,{className:`h-3.5 w-3.5`}),t(`serverManagement.updateTo`,`Update to {{version}}`,{version:l?.latestVersion??``})]}),k&&O(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-amber-500/40 px-2.5 py-1.5 text-xs font-medium text-amber-500 hover:bg-amber-500/10 disabled:opacity-50`,onClick:()=>void b(),children:[g.isPending?M(z,{className:`h-3.5 w-3.5 animate-spin`}):M(ee,{className:`h-3.5 w-3.5`}),t(`serverManagement.rollback`,`Roll back to {{version}}`,{version:l?.previousVersion??``})]}),O(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-surface-muted disabled:opacity-50`,disabled:!N,onClick:()=>void S(),children:[_.isPending?M(z,{className:`h-3.5 w-3.5 animate-spin`}):M(L,{className:`h-3.5 w-3.5`}),t(`serverManagement.restart`,`Restart`)]})]}),e.isOnline&&l?.lastCheckedAtMs!=null&&O(`p`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[M(ue,{className:`h-3 w-3`}),t(`serverManagement.lastChecked`,`Last checked: {{when}}`,{when:new Date(l.lastCheckedAtMs).toLocaleString()})]})]})}D();function Oe({node:e}){let t=P(),[n,r]=j(`info`),[i,a]=j(!1),o=e.processes??[],s=e.addons.map(e=>e.id),c=async()=>{if(!i){a(!0);try{await Promise.allSettled([t.trpcClient.pipelineOrchestrator.removeAgentSettings.mutate({agentNodeId:e.id}),t.trpcClient.clusterNodes.forgetNode.mutate({nodeId:e.id})])}finally{a(!1)}}};return e.isOnline?O(`div`,{className:`border border-border rounded-xl overflow-hidden`,children:[O(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30 border-b border-border`,children:[M(`div`,{className:`w-2.5 h-2.5 rounded-full bg-success`}),M(`span`,{className:`text-sm font-semibold`,children:e.name}),O(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>M(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),O(`div`,{className:`ml-auto flex gap-3 text-xs text-muted-foreground`,children:[O(`span`,{className:`flex items-center gap-1`,children:[M(H,{className:`h-3 w-3`}),` `,e.cpuPercent,`%`]}),O(`span`,{className:`flex items-center gap-1`,children:[M(de,{className:`h-3 w-3`}),` `,e.memoryPercent,`%`]})]})]}),M(`div`,{className:`flex border-b border-border px-4`,children:[`info`,`addons`,`forks`,`processes`,`settings`,`capabilities`].map(t=>M(`button`,{onClick:()=>r(t),className:`px-3 py-2 text-xs font-medium border-b-2 transition-colors ${n===t?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:t===`info`?`General`:t===`addons`?`Addons (${e.addons.length})`:t===`forks`?`Forks (${o.length})`:t===`processes`?`Processes`:t===`settings`?`Settings`:`Capabilities`},t))}),O(`div`,{className:`px-4 py-2`,children:[n===`info`&&O(`div`,{className:`space-y-3`,children:[M(Te,{nodeId:e.id,name:e.name,hostname:e.hostname,platform:e.platform,arch:e.arch,cpuModel:e.cpuModel,cpuCores:e.cpuCores,memoryMB:e.memoryMB,engines:e.engines,isHub:e.isHub,uptime:e.uptime,localIps:e.localIps,rootPackage:e.rootPackage}),M(`div`,{className:`border-t border-border pt-1`,children:M(De,{node:{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,rootPackage:e.rootPackage??null}})})]}),n===`addons`&&M(me,{nodeId:e.id,addons:e.addons,isHub:e.isHub}),n===`forks`&&M(ye,{nodeId:e.id,processes:o}),n===`processes`&&M(Se,{nodeId:e.id}),n===`settings`&&M(Z,{nodeId:e.id,addonIds:s}),n===`capabilities`&&M(Ce,{nodeId:e.id,addons:e.addons})]})]}):O(`div`,{className:`border border-border rounded-xl overflow-hidden opacity-60`,children:[O(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30`,children:[M(`div`,{className:`w-2.5 h-2.5 rounded-full bg-destructive`}),M(`span`,{className:`text-sm font-semibold`,children:e.name}),O(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>M(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),e.rootPackage&&O(`span`,{className:`text-[10px] font-mono px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:[e.rootPackage.name,`@`,e.rootPackage.version]}),M(`span`,{className:`ml-auto text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`})]}),O(`div`,{className:`flex items-center justify-between gap-3 px-4 py-3`,children:[O(`span`,{className:`text-xs text-muted-foreground`,children:[e.lastSeen?`Last seen ${new Date(e.lastSeen).toLocaleString()} — `:``,e.addons.length,` addon`,e.addons.length===1?``:`s`,` assigned; will resume when node reconnects`]}),O(`button`,{type:`button`,onClick:()=>void c(),disabled:i,title:`Forget this node — removes its saved history and pipeline assignments`,className:`flex items-center gap-1 text-xs px-2 py-1 rounded-md border border-border text-muted-foreground hover:text-destructive hover:border-destructive/50 disabled:opacity-50 transition-colors`,children:[M(G,{className:`h-3 w-3`}),i?`Forgetting…`:`Forget node`]})]})]})}D();function ke({nodes:e,focusNodeId:t,focusNonce:n}){let r=[...e].toSorted((e,t)=>e.isHub?-1:t.isHub?1:e.isOnline&&!t.isOnline?-1:!e.isOnline&&t.isOnline?1:e.name.localeCompare(t.name)),i=E(null);return N(()=>{if(!t)return;let e=i.current?.querySelector(`#node-card-${CSS.escape(t)}`);e&&e.scrollIntoView({behavior:`smooth`,block:`start`})},[t,n]),M(`div`,{ref:i,className:`flex flex-col gap-4`,children:r.map(e=>M(`div`,{id:`node-card-${e.id}`,children:M(Oe,{node:e})},e.id))})}D();function Ae(e){let[t,n]=j(()=>typeof window<`u`?window.matchMedia(e).matches:!1);return N(()=>{let t=window.matchMedia(e),r=e=>n(e.matches);return t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t}function je(){let{data:e,isLoading:t}=l(void 0,{staleTime:1/0}),[n,r]=j(null);return u(`cluster.topology-snapshot`,e=>{let t=e.data?.nodes;Array.isArray(t)&&r(t)}),{nodes:k(()=>n??e??[],[n,e]),isLoading:t&&!n}}function Me(){let{t:e}=K(),t=o(),[n,r]=j(`table`),[i,a]=j(void 0),[s,c]=j(0),l=Ae(`(max-width: 767px)`),u=l&&n===`graph`?`table`:n,{nodes:d,isLoading:f}=je(),p=k(()=>se(d),[d]),m=k(()=>d.filter(e=>e.isOnline),[d]),g=m.length,_=d.filter(e=>!e.isOnline).length,v=h(),[y,b]=j(!1),x=T(async()=>{let n=[...m].sort((e,t)=>e.isHub===t.isHub?0:e.isHub?1:-1);if(await t({title:e(`serverManagement.confirmUpdateAllTitle`,`Update all nodes`),message:e(`serverManagement.confirmUpdateAllBody`,`Sequentially update every online node to its latest published version — agents first, the hub last. Each node installs its root package (only if newer than what it runs) and restarts on probation with automatic rollback; already-current nodes are skipped. The hub restarts last, so this page will reconnect afterwards.`),confirmLabel:e(`serverManagement.confirmUpdateAllAction`,`Update all & restart`),variant:`warning`})){b(!0);try{for(let e of n)try{await v.mutateAsync(e.isHub?{}:{nodeId:e.id})}catch{}}finally{b(!1)}}},[v,t,m,e]),S=T(e=>{r(`table`),a(e),c(e=>e+1)},[]),C=(e,t,i)=>O(`button`,{onClick:()=>r(e),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${n===e?`bg-primary text-primary-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[M(i,{className:`h-3.5 w-3.5`}),t]});return O(`div`,{className:`flex flex-col h-full gap-4 p-4`,children:[O(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[O(`div`,{className:`flex items-center gap-2`,children:[g>0&&O(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-success/10 text-success`,children:[g,` online`]}),_>0&&O(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:[_,` offline`]})]}),O(`div`,{className:`flex items-center gap-2`,children:[g>1&&O(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50`,disabled:y,title:e(`serverManagement.updateAllHint`,`Sequenced agents-first, hub-last — up-to-date nodes are skipped.`),onClick:()=>void x(),children:[y?M(z,{className:`h-3.5 w-3.5 animate-spin`}):M(Y,{className:`h-3.5 w-3.5`}),e(`serverManagement.updateAll`,`Update all nodes`)]}),O(`div`,{className:`flex gap-0.5 p-1 rounded-lg bg-muted`,children:[C(`table`,`Table`,fe),!l&&C(`graph`,`Graph`,le)]})]})]}),f?M(`div`,{className:`flex items-center justify-center flex-1 text-muted-foreground`,children:`Loading cluster topology...`}):u===`graph`?M(q,{graph:p,onOpenNodeDetail:S}):M(`div`,{className:`flex-1 overflow-auto`,children:M(ke,{nodes:d,focusNodeId:i,focusNonce:s})})]})}export{Me as ClusterPage};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{$ as e,$a as t,An as n,Bn as r,Bt as i,Cn as a,D as o,Dn as s,Do as c,E as l,En as u,F as d,Fa as f,Fi as p,Gn as m,H as h,Hn as g,In as _,J as v,Ja as y,Ka as b,Kn as x,La as S,Ln as C,Mn as w,N as T,Nn as E,O as D,Oi as ee,P as O,Pa as k,Pr as te,Q as ne,Qa as A,Rn as j,Sn as re,T as M,Tt as ie,U as N,Un as ae,Vn as oe,Vr as P,W as F,Wn as I,X as se,Xa as ce,Xi as le,Y as ue,Z as de,Za as fe,_n as pe,_r as L,a as me,at as he,cn as ge,et as _e,f as R,fi as z,g as ve,gr as ye,ha as be,hi as xe,hn as Se,i as Ce,io as we,jn as Te,ki as Ee,kn as De,l as Oe,m as ke,ma as Ae,n as je,no as Me,o as Ne,oo as Pe,ot as Fe,p as Ie,qa as Le,r as Re,ro as ze,rt as Be,sn as Ve,st as He,ti as Ue,to as We,tt as Ge,u as Ke,ui as qe,ur as Je,vi as Ye,vr as Xe,y as Ze,zn as Qe}from"./src-Bwet06Ih.js";import{I as B,K as V,Q as H,S as U,W,a as $e,b as et,o as G,q as K,t as tt,x as q,z as J}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{A as nt,D as rt,E as Y,M as it,O as at,S as ot,V as st,W as ct,j as lt,k as ut,v as dt,w as ft,x as pt}from"./src-GxiMH1Sc.js";import{c as mt,k as ht,p as X,r as gt,t as _t,u as vt}from"./player-overlays-BlOdAA3b.js";import{t as yt}from"./CapabilityBadges-BfPStFDD.js";import{n as bt,t as xt}from"./rotate-ccw-ByTFEZ8o.js";import{t as St}from"./ProviderIcon-CQTRNfxg.js";import{a as Ct,c as wt,i as Tt,n as Et,s as Dt}from"./NodeInferenceDevices-DlG9HB9Y.js";import{n as Ot,t as kt}from"./FormBuilder-6mYk-4qC.js";import{t as At}from"./pencil-Ik1l3G_8.js";import{t as jt}from"./plus-B0OPxy2A.js";import{t as Mt}from"./refresh-cw-D92Y26QW.js";import{t as Nt}from"./rotate-cw-C6p7zQhm.js";import{t as Pt}from"./server-BwAvkFi_.js";import{t as Ft}from"./wifi-C-i5Y8G3.js";import{A as It,J as Lt,K as Rt,L as zt,S as Bt,U as Vt,V as Ht,W as Ut,a as Wt,c as Gt,i as Kt,j as qt,m as Jt,q as Yt,r as Xt,s as Zt,t as Qt,v as $t,y as en,z as tn}from"./index-RegSp4ae.js";import{t as nn}from"./StatusBadge-Dcr2bw58.js";import{t as rn}from"./useEventInvalidation-BslmDCfY.js";import{n as an,r as on,t as sn}from"./SchemaTabBar-DhsmEGyn.js";var cn=Ut(`circle-help`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),ln=Ut(`link-2-off`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7`,key:`10o201`}],[`path`,{d:`M15 7h2a5 5 0 0 1 4 8`,key:`1d3206`}],[`line`,{x1:`8`,x2:`12`,y1:`12`,y2:`12`,key:`rvw6j4`}],[`line`,{x1:`2`,x2:`22`,y1:`2`,y2:`22`,key:`a6p6uj`}]]),un=Ut(`link-2`,[[`path`,{d:`M9 17H7A5 5 0 0 1 7 7h2`,key:`8i5ue5`}],[`path`,{d:`M15 7h2a5 5 0 1 1 0 10h-2`,key:`1b9ql8`}],[`line`,{x1:`8`,x2:`16`,y1:`12`,y2:`12`,key:`1jonct`}]]),dn=Ut(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),fn=Ut(`volume-2`,[[`path`,{d:`M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z`,key:`uqj9uw`}],[`path`,{d:`M16 9a5 5 0 0 1 0 6`,key:`1q6k2b`}],[`path`,{d:`M19.364 18.364a9 9 0 0 0 0-12.728`,key:`ijwkga`}]]);H();function pn({parentDeviceId:e}){let{t}=Qt(),n=Rt(),r=X(),{data:i,isLoading:a,isError:o}=Ct(e),{data:s}=u({deviceId:e},{enabled:Number.isFinite(e)});if(a)return q(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:q(`p`,{className:`text-[10px] text-foreground-subtle`,children:t(`common.loading`,{defaultValue:`Loading…`})})});if(o)return q(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:q(`p`,{className:`text-[10px] text-warning`,children:t(`integrations.childrenLoadError`,{defaultValue:`Failed to load children`})})});let c=(i??[]).filter(e=>e.display?.hidden!==!0);if(c.length===0)return null;let l=se(s?.stableId??``,c,s?.childLayout),d=l.ungrouped,f=e=>n(`/devices/${String(e)}`),p=s?.name??``,m=(e,t)=>q(v,{trpc:r.trpcClient,device:{...t,name:_e(t,p)},variant:`minimal`,onNavigate:f},e),h=d.some(e=>!!e.role),g=d.some(e=>!e.role),_=h&&!g?t(`device.accessories`,{defaultValue:`Accessories`}):!h&&g?t(`device.adoptedDevices`,{defaultValue:`Adopted devices`}):t(`device.children`,{defaultValue:`Children`}),y=d.length>0?U(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[q(`div`,{className:`text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle mb-1.5`,children:_}),q(`div`,{className:`space-y-1`,children:d.map(e=>m(e.id,e))})]}):null,b=l.disabledSection===void 0?null:q(ue,{title:t(`device.disabledSection`,{defaultValue:`Disabled`}),count:l.disabledSection.children.length,defaultOpen:!1,children:q(`div`,{className:`opacity-60 space-y-1`,children:l.disabledSection.children.map(e=>m(e.id,e))})},l.disabledSection.title);return l.sections.length===0?b===null?y:U(`div`,{className:`space-y-2`,children:[y,b]}):U(`div`,{className:`space-y-2`,children:[l.sections.map(e=>q(ue,{title:e.title,count:e.children.length,defaultOpen:e.defaultOpen,children:e.children.map(e=>m(e.id,e))},e.title)),y,b]})}function mn({deviceName:e,deviceType:t,provider:n,isOnline:r,features:i}){return U(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-border bg-surface p-6 text-center`,children:[q(St,{type:n,size:`lg`}),U(`div`,{children:[q(`div`,{className:`text-sm font-semibold text-foreground`,children:e}),q(`div`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wider mt-0.5`,children:t})]}),U(`div`,{className:`flex items-center gap-2 flex-wrap justify-center`,children:[q(nn,{status:r?`online`:`offline`}),i.length>0&&q(yt,{capabilities:i})]}),q(`div`,{className:`text-[10px] text-foreground-subtle italic max-w-xs mt-1`,children:`No live view for this device type. Use the Config tab or the shortcut row to interact.`})]})}function hn({deviceId:e}){let t=G(),n=Ve({deviceId:e},{refetchInterval:1e4,retry:!1}),r=ge({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceDiscovery`,`listDiscovered`]]}),t.invalidateQueries({queryKey:[[`deviceDiscovery`,`getStatus`]]})}}),i=W(()=>gn(n.data??[]),[n.data]);return U(`div`,{className:`flex h-full w-full flex-col gap-3 p-3 sm:p-4`,children:[U(`div`,{className:`flex flex-wrap items-stretch gap-2 sm:gap-3`,children:[q(_n,{label:`Discovered`,value:i.total,icon:q($t,{className:`h-3.5 w-3.5`})}),q(_n,{label:`Adopted`,value:i.adopted,accent:`success`}),q(_n,{label:`Available`,value:i.available,accent:i.available>0?`primary`:void 0}),U(`button`,{type:`button`,onClick:()=>{r.mutateAsync({deviceId:e}).catch(()=>{})},disabled:r.isPending,className:`inline-flex items-center justify-center gap-1.5 rounded-lg border border-border px-3 py-2 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50 self-stretch shrink-0`,children:[r.isPending?q(Bt,{className:`h-3.5 w-3.5 animate-spin`}):q(Mt,{className:`h-3.5 w-3.5`}),q(`span`,{className:`hidden sm:inline`,children:`Discover`})]})]}),U(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-foreground-subtle border-t border-border-subtle pt-2`,children:[q(vn,{icon:q(Ft,{className:`h-3 w-3 text-emerald-500`}),label:`${i.online} online`}),q(vn,{icon:q(en,{className:`h-3 w-3 text-amber-500`}),label:`${i.sleeping} sleeping`}),q(vn,{icon:q(Wt,{className:`h-3 w-3 text-destructive`}),label:`${i.offline} offline`}),i.unknown>0?q(vn,{icon:q(cn,{className:`h-3 w-3 text-foreground-subtle`}),label:`${i.unknown} unknown`}):null]})]})}function gn(e){let t={total:e.length,adopted:0,available:0,online:0,sleeping:0,offline:0,unknown:0};for(let n of e)n.alreadyAdopted?t.adopted+=1:t.available+=1,t[n.status]+=1;return t}function _n({label:e,value:t,icon:n,accent:r}){return U(`div`,{className:`flex flex-1 basis-[140px] min-w-0 flex-col gap-1 rounded-lg border px-2 py-1.5 sm:px-3 sm:py-2 ${r===`success`?`bg-emerald-500/10 border-emerald-500/30 text-emerald-500`:r===`primary`?`bg-primary/10 border-primary/30 text-primary`:`bg-surface-hover border-border text-foreground`}`,children:[U(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider opacity-70 truncate`,children:[n,q(`span`,{className:`truncate`,children:e})]}),q(`div`,{className:`text-xl sm:text-2xl font-semibold tabular-nums leading-none`,children:t})]})}function vn({icon:e,label:t}){return U(`span`,{className:`inline-flex items-center gap-1`,children:[e,q(`span`,{children:t})]})}function yn({deviceId:e,features:t}){return q(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:q(f,{trpc:X().trpcClient,deviceId:e,features:t})})}function bn({deviceId:e,features:t}){return q(`div`,{className:`flex h-full w-full flex-col items-stretch p-3 sm:p-4`,children:q(k,{trpc:X().trpcClient,deviceId:e,features:t})})}H();function xn({dev:e,busy:t,setBusy:n}){let r=e?.motionTrigger,i=vt(e?.state.motionTrigger),[a,o]=K(!1);if(!r)return null;let s=i?.enabled===!0,c=i!==void 0,l=async()=>{if(t||!c)return;let e=!s;n(!0),o(!0);try{await r.setMotionTrigger({enabled:e})}finally{n(!1),o(!1)}};return U(`button`,{type:`button`,onClick:()=>{l()},disabled:t||!c,title:c?s?`Disable trigger on motion`:`Enable trigger on motion`:`Awaiting state…`,"aria-pressed":s,className:`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-[11px] font-medium transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${s?`border-primary/50 bg-primary/15 text-primary`:`border-border bg-surface text-foreground-subtle hover:text-foreground`}`,children:[q(Vt,{className:`h-3 w-3`}),q(`span`,{children:a?s?`Disabling…`:`Enabling…`:c?s?`On motion: on`:`On motion: off`:`On motion: …`})]})}H();function Z({deviceId:e,deviceType:t,features:n}){let r=X(),i=Fe(t)?.HeroCard??k,a=mt(r.trpcClient,e),o=vt(a?.state.deviceStatus),[s,c]=K(!1),l=o!==void 0&&o.online===!1,u=l?o.lastChangedAt:null;return U(`div`,{className:`flex h-full w-full flex-col items-stretch gap-3 p-3 sm:p-4`,children:[l?q(`div`,{className:`flex justify-center`,children:q(F,{lastChangedAt:u})}):null,q(i,{trpc:r.trpcClient,deviceId:e,features:n}),q(`div`,{className:`flex justify-center`,children:q(xn,{dev:a,busy:s,setBusy:c})})]})}function Sn({deviceId:e}){let t=X(),{data:n,isLoading:r}=Tt(e),{data:i,isLoading:a}=Ct(e),o=r||a,s=(i??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,features:e.features,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),c=typeof n?.linkDeviceId==`number`?n.linkDeviceId:null,l=typeof n?.primaryChildEntityId==`string`?n.primaryChildEntityId:null;return o?q(`div`,{className:`h-full min-h-32 w-full animate-pulse rounded-lg bg-surface`,"aria-hidden":`true`}):q(`div`,{className:`flex h-full w-full flex-col`,children:q(N,{trpc:t.trpcClient,children:s,linkDeviceId:c,primaryChildEntityId:l})})}var Cn={[Y.Switch]:Z,[Y.Siren]:Z,[Y.Light]:Z,[Y.Sensor]:Z,[Y.Button]:Z,[Y.Hub]:hn,[Y.Cover]:yn,[Y.Valve]:Z,[Y.Humidifier]:Z,[Y.WaterHeater]:Z,[Y.Container]:Sn,[Y.Lock]:Z,[Y.Fan]:Z,[Y.Thermostat]:Z,[Y.Climate]:Z,[Y.MediaPlayer]:Z,[Y.Control]:Z,[Y.AlarmPanel]:bn,[Y.EventEmitter]:bn,[Y.Notifier]:bn,[Y.Script]:bn,[Y.Automation]:bn,[Y.Presence]:Z,[Y.Update]:Z,[Y.Vacuum]:Z,[Y.LawnMower]:Z,[Y.Weather]:Z,[Y.Image]:Z,[Y.PetFeeder]:Z};function wn(e){return q(Cn[e.deviceType]??mn,{...e})}function Tn(e){return me(X().trpcClient,e)}H();function En(e){let[t,n]=K(`idle`),[r,i]=K(null),a=V(null),o=V(null),s=V(null),c=V(!0),l=L(),u=ye(),d=Xe(),f=B(()=>{if(a.current){try{a.current.close()}catch{}a.current=null}if(o.current){for(let e of o.current.getTracks())try{e.stop()}catch{}o.current=null}s.current=null},[]),p=B(async()=>{if(t===`idle`)return;n(`stopping`);let r=s.current;if(r&&e!==null)try{await Promise.race([d.mutateAsync({deviceId:e,sessionId:r}),new Promise((e,t)=>setTimeout(()=>t(Error(`server stopSession timeout`)),2e3))])}catch(e){console.warn(`[intercom] server stopSession failed (continuing teardown)`,e)}f(),c.current&&(n(`idle`),i(null))},[t,e,d,f]),m=B(async()=>{if(e===null||t!==`idle`&&t!==`error`)return;i(null);let r=null,f=null,m=null;try{n(`requesting-mic`),r=await navigator.mediaDevices.getUserMedia({audio:!0,video:!1}),o.current=r,n(`starting`);let t=await l.mutateAsync({deviceId:e});m=t.sessionId,s.current=m,n(`connecting`),f=new RTCPeerConnection,a.current=f,f.oniceconnectionstatechange=()=>{if(!c.current)return;let e=f.iceConnectionState;e===`connected`||e===`completed`?n(`talking`):(e===`failed`||e===`closed`||e===`disconnected`)&&c.current&&(i(e===`failed`?`WebRTC connection failed`:null),p())};for(let e of r.getAudioTracks())f.addTrack(e,r);await f.setRemoteDescription({type:`offer`,sdp:t.sdpOffer});let d=await f.createAnswer();await f.setLocalDescription(d);let h=f.localDescription?.sdp??d.sdp??``;await u.mutateAsync({deviceId:e,sessionId:m,sdpAnswer:h})}catch(t){let l=t instanceof Error?t.message:String(t);if(console.warn(`[intercom] start failed`,t),f)try{f.close()}catch{}if(r)for(let e of r.getTracks())try{e.stop()}catch{}if(a.current=null,o.current=null,m!==null)try{await d.mutateAsync({deviceId:e,sessionId:m})}catch{}s.current=null,c.current&&(i(l),n(`error`))}},[e,t,l,u,d,p]);return J(()=>(c.current=!0,()=>{c.current=!1;let t=s.current;if(t!==null&&e!==null&&d.mutate({deviceId:e,sessionId:t}),a.current){try{a.current.close()}catch{}a.current=null}if(o.current){for(let e of o.current.getTracks())try{e.stop()}catch{}o.current=null}s.current=null}),[e]),{state:t,error:r,start:m,stop:p,isTalking:t===`talking`}}H();var Dn=0;function Q(){return++Dn}function On(e){switch(e.type){case`system`:return`system`;case`device`:return`#${e.deviceId}`;case`provider`:return e.providerId;case`addon`:return e.addonId}}function kn(e){return[``,`Commands`,` help Show this help`,` examples Show usage examples for the current scope`,` context Show every available variable + full API surface`,` clear Clear terminal (also Ctrl+L)`,``,`Shortcuts`,` Enter Execute expression`,` Arrow Up/Down Navigate command history`,` Ctrl+L Clear terminal`,``,`Try: ${{system:` sm.summary() // fleet overview`,device:` device.state.battery.value?.sleeping // sync read`,provider:` devices.map(d => d.name)`,addon:` manifest.version`}[e.type]}`,``,`Top-level objects: sm (SystemMirror), DeviceType, Math, JSON, Date, …`]}function An(e){switch(e.type){case`device`:return[``,`── State (sync, zero round-trip) ─────────────────────────`,` device.state.battery.value`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,``,`── Actions (async, through wrapper chain) ────────────────`,` await device.snapshot.getSnapshot({})`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.switch.setState({ on: true })`,``,`── Wait for condition ───────────────────────────────────`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`── Subscribe to changes ─────────────────────────────────`,` const off = device.state.battery.subscribe(s => console.log(s))`,``,`── Quick info ───────────────────────────────────────────`,` info.name device name`,` info.addonId owning addon`,` sm.dump(deviceId) full debug dump`];case`system`:return[``,`── Lookups ──────────────────────────────────────────────`,` sm.getDeviceById(8)`,` sm.getDeviceByName('Sala da pranzo')`,` sm.getDevicesByAddon('reolink')`,` sm.getDevicesByType(DeviceType.Camera)`,``,`── Filters (typed query) ────────────────────────────────`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] })`,` sm.query({ name: /^Cam-/ })`,``,`── Cross-device ─────────────────────────────────────────`,` sm.whereState('battery', s => s.percentage < 20).length`,` sm.mapState('battery', s => s.percentage)`,` sm.countByCap('snapshot')`,``,`── Batch action ─────────────────────────────────────────`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,``,`── Listen ───────────────────────────────────────────────`,` sm.listenCap('motion', (id, s) => console.log(id, s))`,` sm.onDeviceAdded((id, info) => console.log('+', info.name))`,``,`── Diagnostics ──────────────────────────────────────────`,` sm.summary()`,` sm.dump(8)`];case`provider`:return[``,` devices.map(d => d.name)`,` await getIntegration()`,` sm.getDevicesByAddon('<this-addon-id>').length`];case`addon`:return[``,` manifest.name`,` manifest.version`,` declaration`]}}function jn(e){let t=[``,`Scope: ${e.type}`,``];switch(e.type){case`system`:return[...t,`Primary API — sm (SystemMirror):`,` sm.getDeviceById(id) DeviceProxy | null (sync)`,` sm.getDeviceByName(name) DeviceProxy | null`,` sm.getDeviceByStableId(sid) DeviceProxy | null`,` sm.getAllDevices() readonly DeviceProxy[]`,` sm.getDeviceInfo(id) DeviceInfo | null`,` sm.summary() fleet stats`,``,`Filters — sm.query({...}):`,` sm.query({ addonId: 'reolink', online: true })`,` sm.query({ caps: ['battery', 'snapshot'] }) // ALL caps required`,` sm.query({ anyCap: ['ptz', 'motion'] }) // ANY cap`,` sm.query({ name: { contains: 'sala' } }) // case-insensitive`,` sm.query({ name: /^Cam-\\d+$/ })`,` sm.query({ type: DeviceType.Camera })`,` sm.query({ parentDeviceId: 8 }) // accessories of cam 8`,` sm.query({ where: (info, dev) => dev.state.battery.value?.sleeping })`,``,`State queries:`,` sm.whereState('battery', s => s.percentage < 20)`,` sm.mapState('battery', s => s.percentage)`,` sm.findState('motion', s => s.detected)`,` sm.countByCap('snapshot')`,``,`Listeners (return unsubscribe fn):`,` sm.listen((id, cap, slice) => …) // every state change`,` sm.listenCap('motion', (id, slice) => …)`,` sm.listenDevice(8, (id, cap, slice) => …)`,` sm.onDeviceAdded((id, info) => …)`,` sm.onDeviceRemoved((id, info) => …)`,``,`Wait primitives:`,` await sm.waitForState(8, 'battery', s => !s.sleeping, 30_000)`,` await sm.waitForDevice(99, 30_000)`,``,`Batch:`,` await sm.invokeCap('snapshot', 'getSnapshot', {}, { parallelism: 4 })`,` await sm.forEachCap('reboot', d => d.reboot.reboot({}))`,``,`Diagnostics:`,` sm.dump(8) debug dump (one device)`,` sm.dump() full fleet dump`,` sm.summary() breakdown by cap/addon/type`,``,`Legacy: deviceRegistry, addonRegistry, eventBus, devices(), addons()`];case`device`:return[...t,`Pre-bound variables:`,` device DeviceProxy for this device (sync state + async methods)`,` deviceId number`,` info DeviceInfo metadata (name, addonId, type, online, …)`,` sm SystemMirror (full cluster view)`,` rawDevice legacy IDevice instance (escape hatch)`,``,`Reactive state (sync, zero round-trip):`,` device.state.battery.value BatteryStatus | undefined`,` device.state.battery.value?.sleeping`,` device.state.battery.value?.percentage`,` device.state.motion.value?.detected`,` device.state.switch.value?.on`,` device.state.brightness.value?.percentage`,` device.state.doorbell.value?.lastPressedAt`,``,`Cap actions (async, through wrapper chain):`,` await device.snapshot.getSnapshot({})`,` await device.snapshot.getSnapshot({ streamId: 'high' })`,` await device.ptz.move({ direction: 'left', steps: 1 })`,` await device.ptz.goToPreset({ presetId: 'home' })`,` await device.switch.setState({ on: true })`,` await device.brightness.setBrightness({ percentage: 60 })`,` await device.reboot.reboot({})`,``,`Subscribe to slice changes:`,` const off = device.state.battery.subscribe(s => console.log(s))`,` // off() to unsubscribe`,``,`Wait for a state condition:`,` await sm.waitForState(deviceId, 'battery', s => !s.sleeping, 30_000)`,``,`Diagnostics:`,` info.name device name`,` info.addonId which addon owns it`,` info.online transport health`,` sm.dump(deviceId) full debug dump (binding + state + info)`];case`provider`:return[...t,`Pre-bound variables:`,` devices Devices belonging to this provider (raw IDevice[])`,` getIntegration() Integration metadata`,``,`For typed device access use the SystemMirror:`,` await getSystemMirror()`,` sm.getDevicesByAddon('this-addon-id')`];case`addon`:return[...t,`Pre-bound variables:`,` manifest { name, version, ... }`,` declaration addon declaration`,` source addon source location`,``,`Examples:`,` manifest.name`,` manifest.version`]}}function Mn({scope:e,greeting:t,className:n}){let r=X(),[i,a]=K(()=>{let n=[];return t&&n.push({id:Q(),kind:`info`,text:t}),n.push({id:Q(),kind:`info`,text:`scope: ${On(e)} — type help or context for available commands`}),n}),[o,s]=K(``),[c,l]=K([]),[u,d]=K(-1),f=V(null),p=V(null);J(()=>{let e=p.current;e&&(e.scrollTop=e.scrollHeight)},[i]);let m=B(()=>{f.current?.focus()},[]),h=tt({mutationFn:t=>r.trpcClient.repl.execute.mutate({code:t,scope:e}),onSuccess:e=>{let t=e??{},n=typeof t.output==`string`?t.output:e==null?`undefined`:typeof e==`string`?e:JSON.stringify(e,null,2),r=t.type===`error`;a(e=>[...e,{id:Q(),kind:r?`error`:`result`,text:n}])},onError:e=>{let t=e instanceof Error?e.message:String(e);a(e=>[...e,{id:Q(),kind:`error`,text:t}])}});function g(t){let n=t.trim();if(n){if(n===`clear`){a([{id:Q(),kind:`info`,text:`scope: ${On(e)}`}]),s(``);return}if(n===`help`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...kn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`context`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...jn(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}if(n===`examples`){a(t=>[...t,{id:Q(),kind:`input`,text:`> ${n}`},...An(e).map(e=>({id:Q(),kind:`info`,text:e}))]),s(``);return}l(e=>[...e,n]),d(-1),a(e=>[...e,{id:Q(),kind:`input`,text:`> ${n}`}]),s(``),h.mutate(n)}}function _(t){if(t.key===`Enter`){t.preventDefault(),g(o);return}if(t.key===`ArrowUp`){if(t.preventDefault(),c.length===0)return;let e=u===-1?c.length-1:Math.max(0,u-1);d(e),s(c[e]??``);return}if(t.key===`ArrowDown`){if(t.preventDefault(),u===-1)return;let e=u+1;e>=c.length?(d(-1),s(``)):(d(e),s(c[e]??``));return}t.ctrlKey&&t.key===`l`&&(t.preventDefault(),a([{id:Q(),kind:`info`,text:`scope: ${On(e)}`}]))}let v={input:`text-zinc-300`,result:`text-emerald-300`,error:`text-red-300`,info:`text-zinc-400`};return U(`div`,{className:`flex flex-col bg-[#0c0a09] rounded-lg border border-border overflow-hidden font-mono text-xs ${n??``}`,onClick:m,children:[U(`div`,{ref:p,className:`flex-1 overflow-y-auto p-3 space-y-1 min-h-[120px]`,children:[i.map(e=>q(`pre`,{className:`whitespace-pre-wrap break-words leading-relaxed ${v[e.kind]}`,children:e.text},e.id)),h.isPending&&q(`span`,{className:`text-zinc-500 animate-pulse`,children:`…thinking`})]}),U(`div`,{className:`flex items-center gap-2 border-t border-zinc-800 px-3 py-2 bg-[#0c0a09]`,children:[q(`span`,{className:`text-emerald-400 flex-shrink-0 select-none font-bold`,children:`>`}),q(`input`,{ref:f,value:o,onChange:e=>s(e.target.value),onKeyDown:_,disabled:h.isPending,placeholder:`device.state.battery.value`,autoFocus:!0,className:`flex-1 bg-transparent text-zinc-100 placeholder:text-zinc-600 focus:outline-none caret-emerald-400 disabled:opacity-50`,spellCheck:!1,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`})]})]})}function Nn({deviceId:e,intercomAvailable:t=!1}){let n=X(),r=typeof window<`u`?window.location.origin:``,i=Number.isFinite(e),a=Tn(i?e:null),{streams:o,pipelineMetrics:s,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h}=Ce(n.trpcClient,i?e:null),g=ne(n.trpcClient,i?e:null),_=En(i&&t?e:null),v=_.state===`requesting-mic`||_.state===`starting`||_.state===`connecting`||_.state===`stopping`,y=_.isTalking||v,b=()=>{_.state===`idle`||_.state===`error`?_.start():_.state!==`stopping`&&_.stop()},x=gt(),S=D(),C=typeof window<`u`?window.localStorage.getItem(`camstack_admin_token`):null,w=x.length>0?q(et,{children:x.map(e=>q(`div`,{className:`absolute inset-0`,children:e.node},e.id))}):null;return q(Ze,{serverUrl:r,createSession:c,sendAnswer:l,handleOffer:u,getIceServers:d,addIceCandidate:f,getIceCandidates:p,closeSession:m,getSessionState:h,...S.request?{playbackUrl:S.request.url,playbackAuthToken:C,...S.request.label?{playbackLabel:S.request.label}:{},onExitPlayback:()=>S.clear()}:{},streams:o,pipelineMetrics:s,phase:a.phase,detections:a,defaultShowDetections:!0,defaultShowMotion:!0,showPlayStop:!0,snapshotSrc:g.src,...g.src?{posterUrl:g.src}:{},snapshotLoading:g.loading,onRefreshSnapshot:g.refresh,intercomAvailable:t,intercomShown:y,onIntercomToggle:b,extraOverlay:w,chromeless:!0,className:`h-full`})}function Pn({deviceId:e,containerDeviceId:t}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full`,children:q(ve,{...t===void 0?{deviceId:e}:{containerDeviceId:t},limit:50,maxHeight:`max-h-full`,showScope:!1,showFilters:!1})}):U(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function Fn({deviceId:e}){if(!Number.isFinite(e))return U(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]});let t=[`CamStack REPL — device #${e}`,``,` device.state.battery.value sync state read`,` await device.snapshot.getSnapshot({}) cap action`,``,` type 'examples' for more, 'context' for the full API`].join(`
|
|
2
|
-
`);return q(Mn,{scope:{type:`device`,deviceId:e},greeting:t,className:`h-full border-0 rounded-none`})}function In({deviceId:e}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:q(ke,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):U(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function Ln({deviceId:e}){return Number.isFinite(e)?q(`div`,{className:`flex flex-col h-full overflow-y-auto`,children:q(R,{deviceId:e,limit:50,maxHeight:`max-h-full`})}):U(`div`,{className:`flex items-center justify-center h-full text-[11px] text-foreground-subtle italic`,children:[`Device #`,e,` not loaded.`]})}function Rn({deviceId:e}){let t=G(),n=Number.isFinite(e),{data:r}=u({deviceId:e},{enabled:n}),i=typeof r?.type==`string`?r.type:`camera`;rn([`deviceManager`,`getBindings`],[`capability.binding-changed`]);let{data:o,isLoading:s,isError:c,error:l}=a({deviceId:e},{enabled:n}),{data:d}=w({deviceType:i},{enabled:!!i}),f=I({onSuccess:()=>{t.invalidateQueries({queryKey:[[`deviceManager`,`getBindings`]]})}});if(s)return q(`div`,{className:`p-4`,children:q(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})});if(c)return U(`div`,{className:`p-4 text-xs text-red-400`,children:[`Failed to load bindings: `,l instanceof Error?l.message:String(l)]});let p=new Map,m={};for(let e of d??[])m[e.capName]=e.wrappers;for(let e of o?.entries??[])p.set(e.capName,{...e,wrappers:m[e.capName]??[]});for(let e of d??[])p.has(e.capName)||p.set(e.capName,{capName:e.capName,kind:`unbound`,providerAddonId:``,providerNodeId:``,nativeAddonId:``,wrappers:e.wrappers});let h=[...p.values()].toSorted((e,t)=>e.capName.localeCompare(t.capName));if(h.length===0)return U(`div`,{className:`flex flex-col items-center justify-center gap-2 p-8 text-foreground-subtle`,children:[q(bt,{className:`h-8 w-8 opacity-40`}),q(`p`,{className:`text-xs`,children:`No capability providers applicable to this device yet.`}),q(`p`,{className:`text-[10px] opacity-60`,children:`Native providers show up here as soon as the owning addon registers them.`})]});let g=h.filter(e=>e.kind!==`unbound`).length;return U(`div`,{className:`flex flex-col gap-3 p-1`,children:[U(`div`,{className:`text-[11px] text-foreground-subtle`,children:[q(`span`,{className:`font-medium text-foreground`,children:g}),` of `,h.length,` capabilit`,h.length===1?`y`:`ies`,` bound — rows marked `,q(`em`,{children:`unbound`}),` have a wrapper available you can activate.`]}),q(A,{columns:[{key:`capability`,header:`Capability`,render:e=>q(`span`,{className:`font-mono text-foreground`,children:e.capName})},{key:`kind`,header:`Kind`,render:e=>q(zn,{kind:e.kind})},{key:`provider`,header:`Active Provider`,render:e=>q(`span`,{className:`font-mono text-foreground-subtle`,children:e.providerAddonId||q(`span`,{className:`opacity-40`,children:`—`})})},{key:`node`,header:`Node`,render:e=>e.providerNodeId?q(Bn,{nodeId:e.providerNodeId}):q(`span`,{className:`text-[10px] opacity-40`,children:`—`})},{key:`native`,header:`Native`,render:e=>q(`span`,{className:`font-mono text-foreground-subtle`,children:e.nativeAddonId||q(`span`,{className:`opacity-40`,children:`—`})})},{key:`wrapper`,header:`Wrapper`,render:t=>{let n=t.kind===`wrapped`?t.providerAddonId:null;return q(Vn,{wrappers:t.wrappers,activeWrapperId:n,disabled:f.isPending,onPick:r=>{let i=n===r;f.mutate({deviceId:e,capName:t.capName,wrapperAddonId:r,active:!i})}})}}],rows:h,rowKey:e=>e.capName,minWidthPx:720})]})}function zn({kind:e}){return e===`native`?U(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-success/30 text-success bg-success/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[q(Pt,{className:`h-3 w-3`}),`native`]}):e===`wrapped`?U(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-primary/30 text-primary bg-primary/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[q(wt,{className:`h-3 w-3`}),`wrapped`]}):e===`linked`?U(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-warning/30 text-warning bg-warning/5 px-1.5 py-0.5 text-[10px] font-medium`,children:[q(un,{className:`h-3 w-3`}),`linked`]}):U(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-border text-foreground-subtle/70 px-1.5 py-0.5 text-[10px] font-medium`,children:[q(Dt,{className:`h-3 w-3`}),`unbound`]})}function Bn({nodeId:e}){return q(`span`,{className:`inline-flex items-center rounded-md border border-border px-1.5 py-0.5 font-mono text-[10px] ${e===`hub`?`text-foreground-subtle`:`text-foreground`}`,children:e})}function Vn({wrappers:e,activeWrapperId:t,disabled:n,onPick:r}){return e.length===0?q(`span`,{className:`text-[10px] opacity-40`,children:`none available`}):q(`div`,{className:`flex flex-wrap gap-1`,children:e.map(e=>{let i=e===t;return U(`button`,{disabled:n,onClick:()=>r(e),title:i?`Click to deactivate (revert to native)`:`Activate wrapper ${e}`,className:`inline-flex items-center gap-1 rounded-md border px-1.5 py-0.5 font-mono text-[10px] transition-colors disabled:opacity-50 ${i?`border-primary/40 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[q(i?zt:xt,{className:`h-3 w-3`}),e]},e)})})}H();function Hn({schema:e,values:t,pendingKeys:n,onChange:r,onAction:i,onSave:a,onDiscard:o,disabled:s,activeSubTab:c,onSubTabChange:l,flattenTabs:u=!1,deviceId:d}){let f=e.tabs??[],p=W(()=>{let t=new Map;for(let n of e.sections){let e=n.tab??`general`,r=t.get(e)??[];r.push(n),t.set(e,r)}return t},[e.sections]),m=new Set(f.map(e=>e.id)),h=[...f,...[...p.keys()].filter(e=>!m.has(e)).map(e=>({id:e,label:e,icon:`wrench`,order:100}))],g=h[0]?.id??`general`,[_,v]=K(g),y=l!==void 0,b=new Set(h.map(e=>e.id)),x=y?c&&b.has(c)?c:g:b.has(_)?_:g,S=e=>{y?l(e):v(e)},C=p.get(x)??[],w={sections:C.length<=1?C.length===1?[{...C[0],title:``}]:C:C.every(e=>!e.title)?[{...C[0],title:``,fields:C.flatMap(e=>e.fields)}]:C},T=q(an,{pendingCount:n.length,onSave:()=>a(n),onDiscard:()=>o(n),saving:s});if(u||h.length<=1)return U(`div`,{className:`flex flex-col gap-3`,children:[q(kt,{schema:e,values:t,onChange:r,onAction:i,disabled:s,deviceId:d}),T]});let E=new Map,D=new Map;for(let[e,t]of p){E.set(e,t.length);let r=new Set,i=e=>{for(let t of e)if(`key`in t&&typeof t.key==`string`&&r.add(t.key),t.type===`group`)i(t.fields);else if(t.type===`sub-tabs`)for(let e of t.tabs)i(e.fields)};for(let e of t)i(e.fields);let a=n.filter(e=>r.has(e)).length;a>0&&D.set(e,a)}return U(`div`,{className:`flex flex-col gap-3`,children:[q(sn,{tabs:h.map(e=>({id:e.id,label:e.label})),activeId:x,onChange:S,countByTab:E,pendingByTab:D}),q(kt,{schema:w,values:t,onChange:r,onAction:i,disabled:s,deviceId:d}),T]})}var Un=`device-export`,Wn=`export`,Gn=`Export`;function Kn(e){return e.type===`separator`||e.type===`info`||e.type===`object-array`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`?!1:e.type===`group`?e.fields.some(Kn):e.type===`sub-tabs`?e.tabs.some(e=>e.fields.some(Kn)):e.writerCapName===Un}function qn(e){return e.fields.some(Kn)}H();function Jn(e,t){return t&&t===`admin`?e:!0}function Yn(e){if(!e)return null;let t={sections:[...e.sections].toSorted((e,t)=>{let n=e.tab??`general`,r=t.tab??`general`;return n===r?qn(e)&&qn(t)?e.id.localeCompare(t.id):(e.order??0)-(t.order??0):n.localeCompare(r)})};return e.tabs?{...t,tabs:e.tabs}:t}function Xn(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`widget`||e.type===`addon-action-button`||e.type===`device-action-button`}function Zn(e){return e.key}function Qn(e){if(!Xn(e))return e.value}function $n(e){return Xn(e)?null:e}function er(e,t){for(let n of e)if(t(n),n.type===`group`)er(n.fields,t);else if(n.type===`sub-tabs`)for(let e of n.tabs)er(e.fields,t)}function tr(e){if(!e)return{};let t={};for(let n of e.sections)er(n.fields,e=>{let n=Zn(e);n!==null&&(t[n]=Qn(e))});return t}function nr(e,t){if(!e)return null;let n=null;for(let r of e.sections)if(er(r.fields,e=>{if(n!==null||Zn(e)!==t)return;let r=$n(e);r&&r.writerCapName&&r.writerAddonId&&(n={capName:r.writerCapName,addonId:r.writerAddonId})}),n!==null)break;return n}function rr(e){return{...e,fields:e.fields.map(ir)}}function ir(e){return e.type===`separator`||e.type===`info`||e.type===`button`||e.type===`object-array`?e:{...e,readonlyField:!0}}function ar(e,t){return e&&{...e,sections:e.sections.map(e=>({...e,fields:e.fields.map(e=>{let n=$n(e);return n?Jn(t,n.minRole)?e:ir(e):e})}))}}function or({deviceId:e,sectionFilter:t,activeSubTab:n,onSubTabChange:r,flattenSubTabs:i,subTabGrouping:a}){let o=G(),{user:c}=Xt(),l=c?.isAdmin===!0,d=V(!1),{data:f,isLoading:p}=s({deviceId:e},{refetchInterval:()=>d.current?!1:2500,enabled:Number.isFinite(e)}),{data:h}=u({deviceId:e},{enabled:Number.isFinite(e)}),g=f?.settings??null,_=f?.live??null,v=W(()=>{if(!g&&!_)return null;let e=g?.sections??[],n=(_?.sections??[]).map(rr),r=[...e,...n],i=t?r.filter(t):r.filter(e=>e.location!==`top-tab`&&!qn(e));if(i.length===0)return null;if(a){let e=i.map(e=>({...e,tab:a.groupOf(e)})),t=new Set(e.map(e=>e.tab)),n=a.tabs.filter(e=>t.has(e.id));return n.length>0?{tabs:n,sections:e}:{sections:e}}let o=new Set;for(let e of i)o.add(e.tab??`general`);let s=[...g?.tabs??[],...(_?.tabs??[]).filter(e=>!(g?.tabs??[]).some(t=>t.id===e.id))].filter(e=>o.has(e.id));return s.length>0?{tabs:s,sections:i}:{sections:i}},[g,_,t,a]),y=W(()=>Yn(v),[v]),b=W(()=>ar(y,l),[y,l]),S=W(()=>tr(b),[b]),w=be(),T=Ae(),E=m(),D=C(),ee=x({onSuccess:()=>{o.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),O={isPending:ee.isPending,mutate:t=>{ee.mutate({deviceId:e,changes:[...t]})}},k=on({schema:b,serverValues:S,onImmediateSave:B(e=>{let t=Object.entries(e).map(([e,t])=>{let n=nr(b,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&O.mutate(t)},[b,O]),onDeferredSave:B(e=>{let t=Object.entries(e).map(([e,t])=>{let n=nr(b,e);return n?{writerCapName:n.capName,writerAddonId:n.addonId,key:e,value:t}:null}).filter(e=>e!==null);t.length>0&&O.mutate(t)},[b,O])}),{values:te,pendingKeys:ne,handleChange:A,handleSave:j,handleDiscard:re}=k;if(d.current=k.editingPaused,p)return U(`div`,{className:`flex items-center justify-center py-12 text-foreground-subtle`,children:[q(Bt,{className:`h-4 w-4 animate-spin mr-2`}),q(`span`,{className:`text-xs`,children:`Loading device aggregate…`})]});if(!b||b.sections.length===0)return q(`div`,{className:`text-xs text-foreground-subtle italic py-4 text-center`,children:`No aggregate contributions for this device.`});async function M(t,n,r){if(t===`regenerate-rtsp-token`){let t=[`rtspUrl:`,`regenerateToken:`].find(e=>n.startsWith(e));if(!t)throw Error(`regenerate-rtsp-token: unrecognised key "${n}" (expected "rtspUrl:<streamId>" or "regenerateToken:<streamId>")`);let r=n.slice(t.length);if(!r)throw Error(`regenerate-rtsp-token: key "${n}" has no streamId after prefix`);let i=st(e,r);await w.mutateAsync({brokerId:i}),o.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]});return}if(t===`test-probe`){if(!h)return{status:`error`,error:`Device metadata not loaded yet`};try{return await E.mutateAsync({addonId:h.addonId,type:h.type,key:n,value:r})}catch(e){return{status:`error`,error:e instanceof Error?e.message:String(e)}}}if(t===`refresh-probe`){if(!n.startsWith(`probedInfo:`))throw Error(`refresh-probe: unrecognised key "${n}" (expected "probedInfo:<streamId>")`);let t=n.slice(11);if(!t)throw Error(`refresh-probe: key "${n}" has no streamId after prefix`);let r=st(e,t),i=await T.mutateAsync({brokerId:r});return o.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),i}if(t===`device-custom-action`){let t=await D.mutateAsync({deviceId:e,action:n,input:r});return o.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),t}throw Error(`[device-aggregate] unknown action "${t}"`)}return q(Hn,{schema:b,values:te,pendingKeys:ne,onChange:A,onAction:M,onSave:j,onDiscard:re,disabled:O.isPending,activeSubTab:n,onSubTabChange:r,flattenTabs:i,deviceId:e})}function sr({deviceId:e,activeSubTab:t,onSubTabChange:n}){return q(`div`,{className:`flex flex-col gap-3`,children:q(or,{deviceId:e,activeSubTab:t,onSubTabChange:n})})}H();var cr=new Set([`package-detection`]);function lr(e,t){if(!e)return null;for(let n of e.slots)for(let e of n.addons)if(e.id===t)return e;return null}function ur(e){return e?e.modelId!==void 0||e.settings!==void 0:!1}function dr({deviceId:e,refreshToken:t}){let n=G(),r=X().trpcClient,[i,a]=K(null),[o,s]=K(null),[c,l]=K(null),u=qe({deviceId:e},{refetchOnMount:`always`}),d=z({deviceId:e},{refetchOnMount:`always`}),f=Ye(void 0,{refetchOnMount:`always`});rn([`nodes`,`topology`],[`agent.online`,`agent.offline`,`agent.unregistered`,`addon.installed`,`addon.uninstalled`]);let p=P(void 0,{refetchOnMount:`always`}),m=W(()=>{let e=new Set;for(let t of p.data??[])t.isOnline&&e.add(t.id);return e},[p.data]),h=W(()=>(f.data??[]).filter(e=>m.has(e.nodeId)).map(e=>e.nodeId),[f.data,m]),g=h[0]??``,_=Ue({nodeId:g},{enabled:g!==``,refetchOnMount:`always`}),v=$e({enabled:h.length>0,queryKey:[[`pipelineOrchestrator`,`getNodeInferenceDevices`],`device-step`,h.join(`,`),t],queryFn:async()=>{let e={};for(let t of h)try{e[t]=(await r.pipelineOrchestrator.getNodeInferenceDevices.query({nodeId:t})).devices}catch{e[t]=[]}return e}}),x=()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraSettings`]]}),n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStepOverrides`]]})},S=ee({onSuccess:x}),C=Ee({onSuccess:x}),w=W(()=>_.data?ce(_.data):[],[_.data]),T=W(()=>{let e=f.data??[],t=m.size===0?[]:e.filter(e=>m.has(e.nodeId)),n=[];for(let e of t){let t=(v.data?.[e.nodeId]??[]).filter(e=>e.enabled&&e.available);if(t.length>=2)for(let r of t)n.push({agentNodeId:e.nodeId,engineLabel:r.format,deviceKey:r.key,deviceLabel:Et(r).label});else n.push({agentNodeId:e.nodeId,engineLabel:t[0]?.format??`(engine unknown)`})}return n},[f.data,v.data,m]),E=(e,t)=>v.data?.[e]?.find(e=>e.key===t)??null,D=e=>{if(e.deviceKey!==void 0)return e.deviceKey;let t=v.data?.[e.agentNodeId]??[],n=t.filter(e=>e.enabled&&e.available);return n.length>=1?n[0].key:t.find(e=>e.available)?.key??t[0]?.key??null},O=(e,t,n)=>d.data?.[e]?.[t]?.[n]??null,k=e=>{if(cr.has(e))return{kind:`zone-driven`};let t=lr(_.data??null,e)?.enabledByDefault??!0,n=u.data?.stepToggles?.[e];return{kind:`gate`,effectiveOn:n??t,defaultOn:t,explicit:n!==void 0}},te=(e,t)=>{let n=lr(_.data??null,e),r=t?.format;if(!(!n||r===void 0))return(n.slot===`detector`?t?.defaultModelId:void 0)??b(n,r)},ne=(e,t)=>{let n=k(e),r=n.kind===`gate`?n.effectiveOn:!1,i=lr(_.data??null,e),a=D(t),o=a===null?null:E(t.agentNodeId,a),s=o?.format;if(!(i?.models.some(e=>s!==void 0&&!!e.formats[s])??!1))return r?{kind:`skip`}:{kind:`na`};let c=a===null?null:O(t.agentNodeId,a,e),l=o?.steps?.[e];return{kind:`enabled`,modelId:c?.modelId??l?.modelId??te(e,o)??`Auto`,overridden:ur(c)}},A=i&&_.data?lr(_.data,i.addonId):null,j=i?E(i.agentNodeId,i.deviceKey):null,re=j?.format??`coreml`,M=i?ur(O(i.agentNodeId,i.deviceKey,i.addonId)):!1,ie=i?te(i.addonId,j):void 0,N=W(()=>{if(!i||!j)return null;let e=j.steps?.[i.addonId];return{enabled:!0,...e?.modelId===void 0?{}:{modelId:e.modelId},settings:e?.settings??{}}},[i,j]),ae=()=>{a(null),s(null)},oe=(e,t)=>{let n=D(t);n!==null&&(a({addonId:e,agentNodeId:t.agentNodeId,deviceKey:n}),s(O(t.agentNodeId,n,e)))},F=(t,n)=>{C.mutate({deviceId:e,addonId:t,enabled:n})},I=()=>{i&&S.mutate({deviceId:e,agentNodeId:i.agentNodeId,deviceKey:i.deviceKey,addonId:i.addonId,patch:o},{onSuccess:ae})},se=()=>{i&&S.mutate({deviceId:e,agentNodeId:i.agentNodeId,deviceKey:i.deviceKey,addonId:i.addonId,patch:null},{onSuccess:ae})};if(f.isLoading||g!==``&&_.isLoading)return q(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(T.length===0)return q(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`No online agents.`});if(!_.data)return q(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let le=i!==null&&A!==null&&j!==null;return U(`div`,{className:`relative h-full w-full space-y-3`,children:[U(`div`,{className:`rounded-md border border-border bg-muted/20 px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[q(`span`,{className:`font-medium text-foreground`,children:`Gate`}),` (col 1) decides whether this camera runs a step — independent of nodes. Each`,` `,q(`span`,{className:`font-medium text-foreground`,children:`node column`}),` shows the model that node runs; click a cell to pin a per-camera model override for that accelerator. A gated-on step with no model on a device shows a clickable `,q(`span`,{className:`text-amber-500`,children:`⚠ skip`}),` `,`and won't run there.`]}),U(`div`,{className:`rounded-md border border-sky-500/25 bg-sky-500/[0.06] px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[q(`span`,{className:`font-medium text-sky-400`,children:`Placement is dynamic.`}),` When a node has multiple inference accelerators, each session is balanced across them per-session at dispatch time — these device columns show each accelerator's effective model (override ?? device default), not a fixed assignment.`]}),q(`div`,{className:le?`md:pr-[360px]`:``,children:w.length>0?q(Le,{tree:w,agents:T,gateFor:k,getCellState:ne,onCellClick:oe,selectedCell:i,onSetGate:F,gateBusy:C.isPending,fallbackNodeId:c,onFallbackNodeChange:l}):q(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),q(fe,{open:le,onClose:ae,title:A?.name??``,subtitle:i&&j?`${i.agentNodeId} · ${Et(j).label} · ${j.format}`:``,footer:U(et,{children:[q(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted text-foreground-subtle disabled:opacity-50`,disabled:!M||S.isPending,onClick:se,children:`Clear override`}),q(`div`,{className:`flex-1`}),q(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:ae,children:`Cancel`}),q(`button`,{type:`button`,disabled:!i||!N||S.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:I,children:S.isPending?`Saving…`:`Save`})]}),children:A&&i&&N?q(y,{mode:`device`,addon:A,agentDefault:N,agentNodeId:i.agentNodeId,currentPatch:o,engineFormat:re,effectiveModelId:ie,onChangePatch:s}):q(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-300`,children:`This accelerator is no longer reported by the node, so there is nothing to provision here.`})})]})}var fr=[{id:`object-detection`,label:`Object detection`,icon:`scan-search`},{id:`tracking`,label:`Tracking`,icon:`route`},{id:`motion`,label:`Motion`,icon:`activity`},{id:`stationary`,label:`Stationary`,icon:`square-parking`},{id:`zones`,label:`Zones`,icon:`shapes`},{id:`audio`,label:`Audio`,icon:`volume-2`},{id:`cluster`,label:`Cluster`,icon:`server`}],pr={"pipeline-object-detection":`object-detection`,"detection-sensitivity":`object-detection`,"onboard-object-detection":`object-detection`,tracking:`tracking`,"tracking-core":`tracking`,"motion-tuning":`motion`,"stationary-objects":`stationary`,occupancy:`stationary`,zones:`zones`,"pipeline-audio":`audio`,"cluster-assignment":`cluster`,"orchestrator-live":`cluster`};function mr(e){return pr[e]??`object-detection`}H();var hr=`steps`,gr=`settings`,_r=new Set([hr,gr]);function vr(e){return e.location===`top-tab`&&(e.tab===`detection-pipeline`||e.tab===`zones`)}function yr({deviceId:e,activeSubTab:t,onSubTabChange:n}){return U(We,{value:t&&_r.has(t)?t:hr,onValueChange:B(e=>{n?.(e)},[n]),className:`flex flex-col`,children:[U(ze,{className:`flex-shrink-0`,children:[q(we,{value:hr,children:`Steps`}),q(we,{value:gr,children:`Settings`})]}),q(Me,{value:hr,children:q(dr,{deviceId:e,refreshToken:0})}),q(Me,{value:gr,children:q(or,{deviceId:e,sectionFilter:vr,subTabGrouping:{groupOf:e=>mr(e.id),tabs:fr}})})]})}function $({label:e,value:t}){return U(`div`,{className:`${ht} flex items-start gap-2 sm:gap-3`,children:[q(`span`,{className:`w-20 sm:w-28 flex-shrink-0 text-[11px] text-foreground-subtle`,children:e}),q(`div`,{className:`flex-1 min-w-0 text-[11px] text-foreground`,children:t})]})}H();function br({deviceId:e,initialName:t}){let n=G(),[r,i]=K(!1),[a,o]=K(t),[s,c]=K(!1),l=V(null);J(()=>{r||o(t)},[t,r]),J(()=>{r&&l.current?.focus()},[r]);let u=oe({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]})}}),d=async()=>{let n=a.trim();if(n.length===0||n===t){i(!1),o(t);return}c(!0);try{await u.mutateAsync({deviceId:e,name:n}),i(!1)}catch{}finally{c(!1)}},f=()=>{o(t),i(!1)};return r?q($,{label:`Name`,value:U(`div`,{className:`flex items-center gap-1`,children:[q(`input`,{ref:l,type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`?d():e.key===`Escape`&&f()},disabled:s,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),q(`button`,{type:`button`,onClick:()=>void d(),disabled:s,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:q(zt,{className:`h-3 w-3`})}),q(`button`,{type:`button`,onClick:f,disabled:s,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:q(Kt,{className:`h-3 w-3`})})]})}):q($,{label:`Name`,value:U(`div`,{className:`flex items-center gap-2 group`,children:[q(`span`,{className:`truncate`,children:t}),q(`button`,{type:`button`,onClick:()=>i(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit name`,children:q(At,{className:`h-3.5 w-3.5`})})]})})}H();function xr({deviceId:e,initialLocation:t}){let n=G(),[i,a]=K(!1),[o,s]=K(t??``),[c,l]=K(!1),u=V(null),{data:d}=E(void 0,{enabled:i}),f=d??[];J(()=>{i||s(t??``)},[t,i]),J(()=>{i&&u.current?.focus()},[i]);let p=r({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`,`getDevice`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listAll`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`getDeviceAggregate`]]}),n.invalidateQueries({queryKey:[[`deviceManager`,`listLocations`]]})}}),m=W(()=>{let e=o.trim().toLowerCase();return e.length===0?f:f.filter(t=>t.toLowerCase()!==e&&t.toLowerCase().includes(e))},[f,o]),h=o.trim().length>0&&!f.some(e=>e.toLowerCase()===o.trim().toLowerCase()),g=async n=>{let r=(n??o).trim(),i=r.length===0?null:r;if(i===(t??null)){a(!1);return}l(!0);try{await p.mutateAsync({deviceId:e,location:i}),a(!1)}catch{}finally{l(!1)}},_=()=>{s(t??``),a(!1)};return i?q($,{label:`Location`,value:U(`div`,{className:`relative`,children:[U(`div`,{className:`flex items-center gap-1`,children:[q(`input`,{ref:u,type:`text`,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`?g():e.key===`Escape`&&_()},disabled:c,placeholder:`Room / area (or leave empty to clear)`,className:`flex-1 min-w-0 px-1.5 py-0.5 text-[11px] bg-background border border-border rounded focus:outline-none focus:border-primary`}),q(`button`,{type:`button`,onClick:()=>void g(),disabled:c,className:`p-0.5 rounded hover:bg-success/10 text-success disabled:opacity-50`,"aria-label":`Save`,children:q(zt,{className:`h-3 w-3`})}),q(`button`,{type:`button`,onClick:_,disabled:c,className:`p-0.5 rounded hover:bg-danger/10 text-danger disabled:opacity-50`,"aria-label":`Cancel`,children:q(Kt,{className:`h-3 w-3`})})]}),(m.length>0||h)&&U(`div`,{className:`absolute z-10 left-0 right-0 mt-0.5 max-h-40 overflow-y-auto rounded-md border border-border bg-surface shadow-md`,children:[m.map(e=>U(`button`,{type:`button`,onClick:()=>{s(e),g(e)},className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover`,children:[q(Ot,{className:`h-3 w-3 text-foreground-subtle flex-shrink-0`}),q(`span`,{className:`truncate`,children:e})]},e)),h&&U(`button`,{type:`button`,onClick:()=>void g(),className:`w-full flex items-center gap-2 px-2 py-1 text-left text-[11px] hover:bg-surface-hover border-t border-border`,children:[q(`span`,{className:`text-foreground-subtle`,children:`Create`}),U(`span`,{className:`font-medium truncate`,children:[`"`,o.trim(),`"`]})]})]})]})}):q($,{label:`Location`,value:U(`div`,{className:`flex items-center gap-2 group`,children:[t?q(`span`,{className:`truncate`,children:t}):q(`span`,{className:`italic text-foreground-subtle`,children:`unset`}),q(`button`,{type:`button`,onClick:()=>a(!0),className:`p-0.5 rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Edit location`,children:q(At,{className:`h-3.5 w-3.5`})})]})})}H();function Sr({deviceId:e}){let t=G(),{data:n}=Tt(e),{data:r}=Ct(e),[i,a]=K(null),o=g({onSuccess:()=>{a(null),t.invalidateQueries({queryKey:[[`deviceManager`]]})},onError:e=>{a(`Could not change primary child: ${e.message}`)}});if(n==null||String(n.type??``)!==Y.Container)return null;let s=(r??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,name:e.name,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}}));if(s.length<=1)return null;let c=he(s,typeof n.linkDeviceId==`number`?n.linkDeviceId:null,typeof n.primaryChildEntityId==`string`?n.primaryChildEntityId:null);return U(et,{children:[q($,{label:`Primary child`,value:q(h,{childrenList:s,selectedId:c===null?s[0].id:c.id,onSetPrimary:t=>o.mutate({deviceId:e,primaryChildEntityId:t}),disabled:o.isPending})}),i!==null&&q(`p`,{role:`alert`,className:`px-3 sm:px-4 py-1.5 text-[11px] text-danger`,children:i})]})}H();var Cr=[`manufacturer`,`model`,`hardware`,`firmware`,`serialNumber`,`uid`,`mac`,`itemNo`];function wr(e){return e.replace(/([a-z])([A-Z])/g,`$1 $2`).replace(/^./,e=>e.toUpperCase())}function Tr(e){return e==null?`—`:typeof e==`string`||typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function Er(){let e=O(),t=d(),{data:n}=u({deviceId:e??0},{enabled:e!==null}),{data:r}=a({deviceId:e??0},{enabled:e!==null}),i=n??t??null,[o,s]=K(`identity`);if(e===null||!i)return null;let c=String(i.stableId??``),l=String(i.name??``),f=String(i.type??``),p=String(i.addonId??``),m=i.features??[],h=new Set([`device-status`,`feature-probe`,`device-ops`]),g=(r?.entries??[]).filter(e=>e.kind===`native`&&!h.has(e.capName)).map(e=>e.capName),_=m.length>0?m:g,v=i.location??null,y=i.metadata??null,b=y!==null&&Object.keys(y).length>0;return U(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[U(`div`,{className:`border-b border-border px-3 sm:px-4 py-2 flex items-center justify-between gap-3`,children:[q(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Device Info`}),b&&U(`div`,{className:`flex items-center gap-1 rounded-md bg-surface-hover p-0.5`,children:[q(Dr,{active:o===`identity`,onClick:()=>s(`identity`),label:`Identity`}),q(Dr,{active:o===`hardware`,onClick:()=>s(`hardware`),label:`Hardware`})]})]}),(!b||o===`identity`)&&U(`div`,{className:`divide-y divide-border`,children:[q($,{label:`ID`,value:U(`span`,{className:`font-mono text-[11px] text-foreground`,children:[`#${e}`,U(`span`,{className:`ml-1.5 text-foreground-subtle`,children:[`(`,c,`)`]})]})}),q(br,{deviceId:e,initialName:l}),q(xr,{deviceId:e,initialLocation:v}),q(Sr,{deviceId:e}),q($,{label:`Type`,value:f}),q($,{label:`Provider`,value:q(St,{type:p,size:`sm`,showLabel:!0})}),q($,{label:`Capabilities`,value:_.length>0?q(yt,{capabilities:_,showLabels:!0}):q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`None`})})]}),b&&o===`hardware`&&q(Or,{metadata:y})]})}function Dr({active:e,onClick:t,label:n}){return q(`button`,{type:`button`,onClick:t,className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${e?`bg-surface text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`}`,children:n})}function Or({metadata:e}){let t=Cr.filter(t=>t in e),n=Object.keys(e).filter(e=>!Cr.includes(e)).toSorted(),r=[...t,...n];return U(`div`,{children:[q(`div`,{className:`px-3 sm:px-4 py-1.5 text-[10px] text-foreground-subtle border-b border-border bg-surface-subtle/40`,children:`Auto-populated by the driver on every connect. Read-only.`}),q(`div`,{className:`divide-y divide-border`,children:r.map(t=>q($,{label:wr(t),value:q(`span`,{className:`font-mono text-[11px] text-foreground break-all`,children:Tr(e[t])})},t))})]})}H();function kr({deviceId:e}){let[t,n]=K(null),r=Se({onSuccess:e=>{n(e.changed?`Re-aligned with source — ${e.rebuiltChildren} child${e.rebuiltChildren===1?``:`ren`} rebuilt.`:`Already up to date.`)},onError:e=>n(`Re-sync failed: ${e.message}`)});return U(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-3`,children:[U(`div`,{className:`flex items-center justify-between gap-3`,children:[U(`div`,{children:[q(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-foreground`,children:`Re-sync`}),q(`p`,{className:`mt-0.5 text-[11px] text-foreground-subtle`,children:`Re-align this device's type, role, capabilities and units with its source.`})]}),U(`button`,{type:`button`,disabled:r.isPending,onClick:()=>{n(null),r.mutate({camDeviceId:e})},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground hover:bg-surface disabled:opacity-50`,children:[q(Mt,{className:`h-3 w-3 ${r.isPending?`animate-spin`:``}`}),r.isPending?`Re-syncing…`:`Re-sync`]})]}),t!==null&&q(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:t})]})}H();var Ar={icon:``,label:``,unit:``,precision:``,hidden:!1};function jr(e){return{icon:e?.icon??``,label:e?.label??``,unit:e?.unit??``,precision:e?.precision===void 0?``:String(e.precision),hidden:e?.hidden===!0}}function Mr(e){if(typeof e!=`object`||!e)return;let t=e.unit;return typeof t==`string`?t:void 0}function Nr(e){let t=e.precision.trim()===``?void 0:Number.parseInt(e.precision,10),n={...e.icon===``?{}:{icon:e.icon},...e.label.trim()===``?{}:{label:e.label.trim()},...e.unit===``?{}:{unit:e.unit},...t!==void 0&&Number.isFinite(t)?{precision:t}:{},...e.hidden?{hidden:!0}:{}};return Object.keys(n).length===0?null:n}function Pr({deviceId:e}){let t=X(),n=G(),{data:r}=u({deviceId:e},{enabled:e>0}),i=typeof r?.role==`string`?r.role:null,a=i===null?void 0:He[i],o=a?.kind===`numeric`,s=je(t.trpcClient,e,i??``),c=a?.kind===`numeric`?a.canonicalUnit:void 0,l=Mr(s)??c,d=l===void 0?void 0:pt(l),f=W(()=>d===void 0?[]:ot(d),[d]),[p,m]=K(null),h=p??jr(r?.display),g=Qe({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}}),{data:_}=De({},{staleTime:6e4}),v=ae({onSuccess:()=>{n.invalidateQueries({queryKey:[[`deviceManager`]]})}});if(r===void 0||i===null)return null;let y=e=>{m({...h,...e})},b=()=>{g.mutate({deviceId:e,display:Nr(h)})},x=()=>{m(Ar),g.mutate({deviceId:e,display:null})},S=()=>{let e={...h.icon===``?{}:{icon:h.icon},...h.unit===``?{}:{unit:h.unit},...h.precision.trim()!==``&&Number.isFinite(Number.parseInt(h.precision,10))?{precision:Number.parseInt(h.precision,10)}:{}},t={..._?.defaults??{},[i]:e};v.mutate({defaults:t})},C=Be(i).label,w=Object.keys(Ge);return U(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[q(`div`,{className:`border-b border-border px-4 py-2`,children:q(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Display`})}),U(`div`,{className:`p-4 space-y-3`,children:[U(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Icon`}),U(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,value:h.icon,onChange:e=>y({icon:e.target.value}),children:[U(`option`,{value:``,children:[`Default (`,C,`)`]}),w.map(e=>q(`option`,{value:e,children:e},e))]})]}),U(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Label`}),q(`input`,{type:`text`,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,placeholder:C,value:h.label,onChange:e=>y({label:e.target.value})})]}),o&&U(`div`,{className:`grid grid-cols-2 gap-3`,children:[U(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Unit`}),U(`select`,{className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,value:h.unit,onChange:e=>y({unit:e.target.value}),disabled:f.length===0,children:[U(`option`,{value:``,children:[`Source`,l?` (${l})`:``]}),f.map(e=>q(`option`,{value:e,children:e},e))]})]}),U(`label`,{className:`block`,children:[q(`span`,{className:`text-[11px] text-foreground-subtle`,children:`Precision`}),q(`input`,{type:`number`,min:0,max:10,step:1,className:`mt-1 w-full rounded border border-border bg-surface px-2 py-1 text-sm text-foreground`,placeholder:`inherit`,value:h.precision,onChange:e=>y({precision:e.target.value})})]})]}),U(`label`,{className:`flex items-center gap-2`,children:[q(`input`,{type:`checkbox`,checked:h.hidden,onChange:e=>y({hidden:e.target.checked})}),q(`span`,{className:`text-sm text-foreground`,children:`Hide from device lists`})]}),U(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[q(`button`,{type:`button`,className:`rounded bg-primary px-3 py-1 text-sm font-medium text-primary-foreground disabled:opacity-50`,onClick:b,disabled:g.isPending,children:`Save`}),q(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:x,disabled:g.isPending,children:`Reset`}),U(`button`,{type:`button`,className:`rounded border border-border px-3 py-1 text-sm text-foreground-subtle`,onClick:S,disabled:v.isPending,title:`Apply this unit / precision / icon as the default for every ${C} sensor`,children:[`Set as default for all `,C,` sensors`]})]})]})]})}function Fr(e){return e<1e3?`${e.toFixed(0)} kbps`:`${(e/1e3).toFixed(1)} Mbps`}function Ir({device:e}){let t=Rt(),n=typeof e.id==`number`?e.id:null,r=String(e.type??``),i=r===Y.Camera,a=r===Y.Hub,o=typeof e.role==`string`&&e.role.length>0,s=e.features??[],c=s.includes(ft.Resyncable),{data:l}=te({deviceId:n??0},{enabled:n!==null&&i,refetchInterval:5e3}),u=l?.streams??{},d=Object.entries(u),f=s.includes(ft.DoorbellButton),p=Re(f?{deviceId:n??void 0,historyLimit:10}:void 0),m=p.latest?Date.now()-p.latest.timestamp<3e4:!1;return U(`div`,{className:`space-y-5`,children:[a&&n!==null&&q(Ie,{deviceId:n,onOpenChild:e=>t(`/devices/${e}`)}),c&&n!==null&&q(kr,{deviceId:n}),i&&n!==null&&q(M,{widgetId:`pipeline-orchestrator/pipeline-quick-stats`,host:`device-tab`,deviceId:n}),f&&q(Ke,{history:p.history,latestIsFresh:m}),i&&n!==null&&q(M,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:n}),i&&d.length>0&&U(`div`,{className:`@container rounded-lg border border-border bg-surface overflow-hidden`,style:{containerType:`inline-size`},children:[q(`div`,{className:`border-b border-border px-4 py-2`,children:q(`h2`,{className:`text-xs font-semibold text-foreground uppercase tracking-wider`,children:`Stream Network`})}),q(`div`,{className:`divide-y divide-border`,children:d.map(([e,t])=>U(`div`,{className:`px-4 py-2.5`,children:[U(`div`,{className:`flex items-center gap-2 mb-2`,children:[q(Ft,{className:`h-3 w-3 text-foreground-subtle`}),q(`span`,{className:`text-[11px] font-medium text-foreground`,children:e})]}),U(`div`,{className:`grid grid-cols-2 @[640px]:grid-cols-4 gap-2`,children:[q(Lr,{label:`Nominal`,value:Fr(t.nominalBitrateKbps??0)}),q(Lr,{label:`Observed`,value:Fr(t.observedBitrateKbps??0)}),q(Lr,{label:`Peak`,value:Fr(t.peakBitrateKbps??0)}),q(Lr,{label:`Packet Loss`,value:`${(t.packetLossPercent??0).toFixed(2)}%`,warning:(t.packetLossPercent??0)>1})]})]},e))})]}),q(Er,{}),o&&n!==null&&q(Pr,{deviceId:n})]})}function Lr({label:e,value:t,warning:n}){return U(`div`,{children:[q(`p`,{className:`text-[10px] text-foreground-subtle`,children:e}),q(`p`,{className:`text-xs font-medium ${n?`text-warning`:`text-foreground`}`,children:t})]})}H();function Rr(e,t){if(t===`number`){let t=Number(e);return Number.isNaN(t)?e:t}return t===`boolean`?e===`true`:e}function zr(e,t){let n={};for(let r of e)r.key!==``&&r.value!==``&&(n[r.key]=Rr(r.value,t));return n}function Br(e,t){return e?.kind===`enum-map`?Object.entries(e.mapping).map(([e,t])=>({key:e,value:String(t)})):t?.kind===`enum`&&t.enumValues?t.enumValues.map(e=>({key:e,value:``})):[{key:``,value:``}]}function Vr(e){return e?.kind===`linear`?{scale:String(e.scale),offset:String(e.offset),clampMin:e.clamp?String(e.clamp[0]):``,clampMax:e.clamp?String(e.clamp[1]):``,useClamp:e.clamp!=null}:{scale:`1`,offset:`0`,clampMin:``,clampMax:``,useClamp:!1}}function Hr(e){return e==null?`identity`:e.kind}function Ur({value:e,onChange:t,sourceField:n,targetKind:r}){let[i,a]=K(()=>Hr(e)),[o,s]=K(()=>Br(e,n)),[c,l]=K(()=>e?.kind===`enum-map`&&e.fallback!=null?String(e.fallback):``),[u,d]=K(()=>Vr(e));J(()=>{if(i===`enum-map`&&n?.kind===`enum`&&n.enumValues){let e=n.enumValues;s(t=>e.map(e=>({key:e,value:t.find(t=>t.key===e)?.value??``})))}},[n,i]),J(()=>{if(i===`identity`){t(void 0);return}if(i===`enum-map`){let e=zr(o,r),n=c===``?void 0:Rr(c,r);t({kind:`enum-map`,mapping:e,...n===void 0?{}:{fallback:n}});return}if(i===`linear`){let e=Number(u.scale),n=Number(u.offset);if(Number.isNaN(e)||Number.isNaN(n))return;let r=Number(u.clampMin),i=Number(u.clampMax),a=u.useClamp&&!Number.isNaN(r)&&!Number.isNaN(i)?[r,i]:void 0;t({kind:`linear`,scale:e,offset:n,...a?{clamp:a}:{}})}},[i,o,c,u,r,t]);let f=e=>{a(e),e===`enum-map`&&s(Br(void 0,n)),e===`linear`&&d(Vr(void 0))},p=(e,t,n)=>{s(r=>r.map((r,i)=>i===e?{...r,[t]:n}:r))},m=()=>s(e=>[...e,{key:``,value:``}]),h=e=>s(t=>t.filter((t,n)=>n!==e));return U(`div`,{className:`flex flex-col gap-3`,children:[U(`div`,{children:[q(`p`,{className:`text-[11px] font-medium text-foreground-subtle mb-1.5`,children:`Transform`}),q(`div`,{className:`flex items-center gap-4`,children:[`identity`,`enum-map`,`linear`].map(e=>U(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[q(`input`,{type:`radio`,name:`transform-kind`,value:e,checked:i===e,onChange:()=>f(e),className:`accent-primary`}),e===`identity`?`None`:e]},e))})]}),i===`enum-map`&&U(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[q(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Key → Value mapping`}),o.map((e,t)=>U(`div`,{className:`flex items-center gap-1.5`,children:[q(`input`,{"aria-label":`enum key ${t}`,type:`text`,value:e.key,readOnly:n?.kind===`enum`,onChange:e=>p(t,`key`,e.target.value),placeholder:`source value`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs font-mono text-foreground focus:border-primary outline-none read-only:opacity-70`}),q(`span`,{className:`text-foreground-subtle/50 text-xs`,children:`→`}),r===`boolean`?U(`select`,{"aria-label":`enum value ${t}`,value:e.value,onChange:e=>p(t,`value`,e.target.value),className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`,children:[q(`option`,{value:``,children:`—`}),q(`option`,{value:`true`,children:`true`}),q(`option`,{value:`false`,children:`false`})]}):q(`input`,{"aria-label":`enum value ${t}`,type:r===`number`?`number`:`text`,value:e.value,onChange:e=>p(t,`value`,e.target.value),placeholder:`target value`,className:`flex-1 rounded border border-border bg-background px-2 py-1 text-xs font-mono text-foreground focus:border-primary outline-none`}),n?.kind!==`enum`&&q(`button`,{type:`button`,onClick:()=>h(t),className:`shrink-0 rounded px-1.5 py-0.5 text-[10px] border border-border/80 text-foreground-subtle hover:text-danger hover:border-danger/50 transition-colors`,children:`✕`})]},t)),n?.kind!==`enum`&&q(`button`,{type:`button`,onClick:m,className:`self-start text-[10px] text-primary/70 hover:text-primary transition-colors`,children:`+ Add row`}),U(`div`,{className:`flex items-center gap-2 pt-1 border-t border-border/50`,children:[q(`label`,{className:`text-[10px] text-foreground-subtle/70 whitespace-nowrap`,children:`Fallback:`}),q(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`(leave empty for none)`,className:`flex-1 rounded border border-border bg-background px-2 py-0.5 text-xs font-mono text-foreground focus:border-primary outline-none`})]})]}),i===`linear`&&U(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-surface p-3`,children:[q(`p`,{className:`text-[10px] font-medium text-foreground-subtle/70 uppercase tracking-wide`,children:`Linear: value × scale + offset`}),U(`div`,{className:`grid grid-cols-2 gap-2`,children:[U(`label`,{className:`flex flex-col gap-0.5`,children:[q(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Scale`}),q(`input`,{type:`number`,value:u.scale,onChange:e=>d(t=>({...t,scale:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),U(`label`,{className:`flex flex-col gap-0.5`,children:[q(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Offset`}),q(`input`,{type:`number`,value:u.offset,onChange:e=>d(t=>({...t,offset:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]})]}),U(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[q(`input`,{type:`checkbox`,checked:u.useClamp,onChange:e=>d(t=>({...t,useClamp:e.target.checked})),className:`accent-primary`}),q(`span`,{className:`text-foreground-subtle`,children:`Clamp output`})]}),u.useClamp&&U(`div`,{className:`grid grid-cols-2 gap-2`,children:[U(`label`,{className:`flex flex-col gap-0.5`,children:[q(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Min`}),q(`input`,{type:`number`,value:u.clampMin,onChange:e=>d(t=>({...t,clampMin:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]}),U(`label`,{className:`flex flex-col gap-0.5`,children:[q(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Max`}),q(`input`,{type:`number`,value:u.clampMax,onChange:e=>d(t=>({...t,clampMax:e.target.value})),className:`rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:border-primary outline-none`})]})]})]})]})}var Wr=`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none disabled:opacity-50`;function Gr({mode:e,idPrefix:t,labelPrefix:r,pickerDevices:i,value:a,onChange:o,search:s,onSearchChange:c}){let{data:l}=n({deviceId:a.sourceId??0},{enabled:a.sourceId!=null}),u=l?.caps??[],d=u.find(e=>e.cap===a.cap)?.fields??[],f=e=>{o(e,(u.find(t=>t.cap===e.cap)?.fields??[]).find(t=>t.path===e.fieldPath))},p=e=>{f({sourceId:e===``?null:Number(e),cap:``,fieldPath:``})},m=e=>{f({sourceId:a.sourceId,cap:e,fieldPath:``})},h=e=>{f({sourceId:a.sourceId,cap:a.cap,fieldPath:e})};return U(et,{children:[e===`global`&&c&&U(`div`,{children:[q(`label`,{htmlFor:`${t}-search`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Search devices`}),q(`input`,{id:`${t}-search`,type:`text`,value:s??``,placeholder:`Filter by name, stable id or #id`,onChange:e=>c(e.target.value),className:Wr})]}),U(`div`,{children:[U(`label`,{htmlFor:`${t}-device`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:[r,` device`]}),U(`select`,{id:`${t}-device`,value:a.sourceId??``,onChange:e=>p(e.target.value),className:Wr,children:[q(`option`,{value:``,children:`— select a device —`}),i.map(e=>U(`option`,{value:e.id,children:[e.name??e.stableId,` (#`,e.id,`)`]},e.id))]})]}),U(`div`,{children:[U(`label`,{htmlFor:`${t}-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:[r,` cap`]}),U(`select`,{id:`${t}-cap`,value:a.cap,disabled:a.sourceId==null,onChange:e=>m(e.target.value),className:Wr,children:[q(`option`,{value:``,children:`— select a cap —`}),u.map(e=>q(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),U(`div`,{children:[U(`label`,{htmlFor:`${t}-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:[r,` field`]}),U(`select`,{id:`${t}-field`,value:a.fieldPath,disabled:a.cap===``,onChange:e=>h(e.target.value),className:Wr,children:[q(`option`,{value:``,children:`— select a field —`}),d.map(e=>U(`option`,{value:e.path,children:[e.path,` (`,e.kind,`)`]},e.path))]})]})]})}function Kr(e,t){switch(e){case`null`:return{value:null};case`string`:return t===``?null:{value:t};case`number`:{if(t.trim()===``)return null;let e=Number(t);return Number.isFinite(e)?{value:e}:null}case`boolean`:return t===`true`?{value:!0}:t===`false`?{value:!1}:null}}function qr(e){return e===null?`null`:typeof e==`number`?`number`:typeof e==`boolean`?`boolean`:`string`}function Jr(e){return e===null?``:String(e)}H();var Yr=`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none disabled:opacity-50`,Xr=`min, max, abs, round, floor, ceil, sqrt, pow, clamp, avg, sum, coalesce, age, convert`,Zr=0;function Qr(){return Zr+=1,`b${Zr}`}function $r(e){return{key:Qr(),name:e,mode:`sibling`,sourceId:null,cap:``,fieldPath:``,search:``,literalType:`number`,literalText:``,sampleText:``}}function ei(e,t,n){if(e===null)return[$r(`a`)];let r=[];for(let[i,a]of Object.entries(e.bindings)){if(a.kind===`literal`){r.push({...$r(i),mode:`literal`,literalType:qr(a.value),literalText:Jr(a.value)});continue}if(a.kind===`global`){r.push({...$r(i),mode:`global`,sourceId:t.find(e=>e.stableId===a.sourceStableId)?.id??null,cap:a.cap,fieldPath:a.fieldPath});continue}r.push({...$r(i),mode:`sibling`,sourceId:t.find(e=>e.stableId===`${n}-${a.sourceKey}`)?.id??null,cap:a.cap,fieldPath:a.fieldPath})}return r.length>0?r:[$r(`a`)]}function ti(e,t,n){if(e.mode===`literal`){let t=Kr(e.literalType,e.literalText);return t===null?null:{kind:`literal`,value:t.value}}let r=t.find(t=>t.id===e.sourceId);if(!r||e.cap===``||e.fieldPath===``)return null;if(e.mode===`global`)return{kind:`global`,sourceStableId:r.stableId,cap:e.cap,fieldPath:e.fieldPath};let i=`${n}-`,a=r.stableId.startsWith(i)?r.stableId.slice(i.length):``;return a===``?null:{kind:`field`,sourceKey:a,cap:e.cap,fieldPath:e.fieldPath}}function ni(e){if(e.mode===`literal`)return Kr(e.literalType,e.literalText)?.value??null;let t=e.sampleText.trim();if(t===``)return null;let n=Number(t);return Number.isFinite(n)?n:e.sampleText}function ri({devices:e,siblings:t,targetDeviceId:n,containerStableId:r,initial:i,onChange:a}){let[o,s]=K(i?.expr??``),[c,l]=K(()=>ei(i,e,r)),u=W(()=>{let t={},n=c.length>0,i=new Set;for(let a of c){let o=a.name.trim();if(o===``||i.has(o)){n=!1;continue}i.add(o);let s=ti(a,e,r);if(s===null){n=!1;continue}t[o]=s}return{source:{kind:`expression`,expr:o,bindings:t},complete:n}},[c,o,e,r]),d=W(()=>at({expr:u.source.expr,bindings:u.source.bindings}),[u.source]),f=W(()=>{if(o.trim()===``)return null;let e=ut(o);return e.ok?null:e.error},[o]),p=W(()=>{if(u.source.expr.trim()===``)return null;let e={};for(let t of c){let n=t.name.trim();n!==``&&(e[n]=ni(t))}return rt(u.source.expr,e,Date.now())},[u.source.expr,c]),m=u.complete&&d===null&&o.trim()!==``;J(()=>{a(m?u.source:null)},[m?JSON.stringify(u.source):`null`]);let h=e=>{let t=e.name.trim();return t===``?`required`:lt.test(t)?it.has(t)?`reserved`:nt.has(t)?`shadows builtin`:c.filter(e=>e.name.trim()===t).length>1?`duplicate`:null:`invalid name`},g=(e,t)=>{l(n=>n.map(n=>n.key===e?{...n,...t}:n))},_=()=>{c.length>=32||l(e=>[...e,$r(ii(e))])},v=e=>{l(t=>t.length<=1?t:t.filter(t=>t.key!==e))};return U(`div`,{className:`flex flex-col gap-3`,children:[U(`div`,{className:`flex flex-col gap-2`,children:[q(`span`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Bindings`}),c.map((r,i)=>q(ai,{row:r,ordinal:i+1,devices:e,siblings:t,targetDeviceId:n,nameError:h(r),onPatch:e=>g(r.key,e),onRemove:()=>v(r.key),canRemove:c.length>1},r.key)),q(`button`,{type:`button`,onClick:_,disabled:c.length>=32,className:`self-start px-2 py-1 rounded-md text-[11px] font-medium border border-border text-foreground-subtle hover:bg-surface-hover disabled:opacity-50`,children:`+ Add binding`})]}),U(`div`,{children:[q(`label`,{htmlFor:`link-expr-input`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Expression`}),q(`textarea`,{id:`link-expr-input`,value:o,rows:2,spellCheck:!1,placeholder:`e.g. clamp(avg(a, b) + 5, 0, 100)`,onChange:e=>s(e.target.value),className:`${Yr} font-mono resize-y`}),U(`p`,{className:`mt-1 text-[10px] text-foreground-subtle/60`,children:[`Functions: `,Xr]}),f&&q(`p`,{className:`mt-1 text-[10px] text-danger`,children:f}),f===null&&d&&q(`p`,{className:`mt-1 text-[10px] text-danger`,children:d})]}),U(`div`,{className:`rounded-md border border-border bg-surface/50 px-2 py-1.5`,children:[q(`span`,{className:`text-[10px] uppercase tracking-widest text-foreground-subtle/60`,children:`Preview`}),` `,p===null?q(`span`,{className:`text-[11px] text-foreground-subtle/60`,children:`enter an expression`}):p.ok?q(`span`,{className:`font-mono text-[11px] text-foreground`,children:JSON.stringify(p.value)}):q(`span`,{className:`font-mono text-[11px] text-danger`,children:p.error})]})]})}function ii(e){let t=new Set(e.map(e=>e.name.trim()));for(let e=0;e<26;e++){let n=String.fromCharCode(97+e);if(!t.has(n))return n}return`b${e.length+1}`}function ai({row:e,ordinal:t,devices:n,siblings:r,targetDeviceId:i,nameError:a,onPatch:o,onRemove:s,canRemove:c}){let l=e.search.trim().toLowerCase(),u=n.filter(e=>e.id===i?!1:l===``?!0:e.name.toLowerCase().includes(l)||e.stableId.toLowerCase().includes(l)||String(e.id).includes(l)),d=e.mode===`global`?u:r;return U(`div`,{className:`flex flex-col gap-2 rounded-md border border-border/60 p-2`,children:[U(`div`,{className:`flex items-center gap-2`,children:[q(`input`,{type:`text`,"aria-label":`binding ${t} name`,value:e.name,placeholder:`name`,onChange:e=>o({name:e.target.value}),className:`${Yr} max-w-[8rem] font-mono`}),U(`select`,{"aria-label":`binding ${t} mode`,value:e.mode,onChange:e=>{let t=e.target.value;(t===`sibling`||t===`global`||t===`literal`)&&o({mode:t,sourceId:null,cap:``,fieldPath:``,search:``})},className:`${Yr} max-w-[9rem]`,children:[q(`option`,{value:`sibling`,children:`Sibling`}),q(`option`,{value:`global`,children:`Any device`}),q(`option`,{value:`literal`,children:`Literal`})]}),c&&q(`button`,{type:`button`,"aria-label":`remove binding ${t}`,onClick:s,className:`px-2 py-1 rounded-md text-[11px] text-danger hover:bg-surface-hover`,children:`✕`})]}),a&&U(`span`,{className:`text-[10px] text-danger`,children:[`name: `,a]}),e.mode===`literal`?U(`div`,{className:`flex items-center gap-2`,children:[U(`select`,{"aria-label":`binding ${t} literal type`,value:e.literalType,onChange:e=>{let t=e.target.value;(t===`string`||t===`number`||t===`boolean`||t===`null`)&&o({literalType:t,literalText:t===`boolean`?`true`:``})},className:`${Yr} max-w-[7rem]`,children:[q(`option`,{value:`string`,children:`string`}),q(`option`,{value:`number`,children:`number`}),q(`option`,{value:`boolean`,children:`boolean`}),q(`option`,{value:`null`,children:`null`})]}),e.literalType!==`null`&&q(`input`,{type:`text`,"aria-label":`binding ${t} literal value`,value:e.literalText,placeholder:e.literalType===`number`?`e.g. 42`:`value`,onChange:e=>o({literalText:e.target.value}),className:Yr})]}):U(et,{children:[q(Gr,{mode:e.mode,idPrefix:`binding-${t}`,labelPrefix:`Binding`,pickerDevices:d,value:{sourceId:e.sourceId,cap:e.cap,fieldPath:e.fieldPath},onChange:e=>o({sourceId:e.sourceId,cap:e.cap,fieldPath:e.fieldPath}),search:e.search,onSearchChange:e=>o({search:e})}),q(`input`,{type:`text`,"aria-label":`binding ${t} sample`,value:e.sampleText,placeholder:`sample value (preview only)`,onChange:e=>o({sampleText:e.target.value}),className:`${Yr} text-[10px]`})]})]})}H();function oi(e,t,n){return(n===void 0?[e,t]:[e,n,t]).map(e=>e.replace(/[^a-z0-9]/gi,`-`)).join(`-`)}function si(e,t,n){let r=`${t}-${e}`;return n.find(e=>e.stableId===r)?.id??null}function ci(e,t){return t.find(t=>t.stableId===e)?.id??null}function li(e){return e==null?`sibling`:e.source.kind===`literal`?`literal`:e.source.kind===`global`?`global`:e.source.kind===`expression`?`expression`:`sibling`}function ui(e){return e==null||e.source.kind!==`literal`?`string`:qr(e.source.value)}function di(e){return e==null||e.source.kind!==`literal`?``:Jr(e.source.value)}function fi({deviceId:e,parentDeviceId:t,deviceStableId:r,initial:i,onSave:a,onCancel:o}){let{data:s}=Te({}),c=s??[],l=t==null?r:c.find(e=>e.id===t)?.stableId??r,u=c.filter(n=>n.parentDeviceId===t&&n.id!==e),{data:d}=n({deviceId:e,includeSynthesizable:!0}),f=d?.caps??[],p=i!=null&&(i.source.kind===void 0||i.source.kind===`field`)?i.source:null,m=i!=null&&i.source.kind===`global`?i.source:null,h=i!=null&&i.source.kind===`expression`?i.source:null,g=p==null?m==null?null:ci(m.sourceStableId,c):si(p.sourceKey,l,c),[_,v]=K(li(i)),[y,b]=K(i?.target.cap??``),[x,S]=K(i?.target.fieldPath??``),[C,w]=K(i?.target.itemKey??``),[T,E]=K(g),[D,ee]=K((p??m)?.cap??``),[O,k]=K((p??m)?.fieldPath??``),[te,ne]=K(void 0),[A,j]=K(``),[re,M]=K(ui(i)),[ie,N]=K(di(i)),[ae,oe]=K(h),[P,F]=K(i?.transform);J(()=>{if((p??m)==null||T!==null||c.length===0)return;let e=p==null?m==null?null:ci(m.sourceStableId,c):si(p.sourceKey,l,c);e!==null&&E(e)},[p,m,T,c,l]);let I=f.find(e=>e.cap===y)?.fields??[],se=I.find(e=>e.path===x),ce=se?.item===!0,le=A.trim().toLowerCase(),ue=c.filter(t=>t.id===e?!1:le===``?!0:t.name.toLowerCase().includes(le)||t.stableId.toLowerCase().includes(le)||String(t.id).includes(le)),de=_===`global`?ue:u,fe=e=>{b(e),S(``),w(``)},pe=e=>{e!==`sibling`&&e!==`global`&&e!==`literal`&&e!==`expression`||(v(e),E(null),ee(``),k(``),ne(void 0),j(``))},L=Kr(re,ie),me=_===`literal`?L!==null:_===`expression`?ae!==null:T!=null&&D!==``&&O!==``,he=y!==``&&x!==``&&(!ce||C.trim()!==``)&&me,ge=()=>{if(_===`literal`)return L===null?null:{kind:`literal`,value:L.value};if(_===`expression`)return ae;let e=c.find(e=>e.id===T);if(!e||D===``||O===``)return null;if(_===`global`)return{kind:`global`,sourceStableId:e.stableId,cap:D,fieldPath:O};let t=`${l}-`;return{sourceKey:e.stableId.startsWith(t)?e.stableId.slice(t.length):``,cap:D,fieldPath:O}},_e=()=>{if(!he)return;let e=ge();if(e===null)return;let t=ce?C.trim():void 0;a({id:i?.id??oi(y,x,t),source:e,target:{cap:y,fieldPath:x,...t===void 0?{}:{itemKey:t}},...P==null?{}:{transform:P}})},R=`w-full rounded-md border border-border bg-surface px-2 py-1.5 text-foreground text-xs focus:border-primary outline-none disabled:opacity-50`;return U(`div`,{className:`flex flex-col gap-4 p-3`,children:[U(`fieldset`,{className:`flex flex-col gap-3`,children:[q(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Target (this device)`}),U(`div`,{children:[q(`label`,{htmlFor:`link-target-cap`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target cap`}),U(`select`,{id:`link-target-cap`,value:y,onChange:e=>fe(e.target.value),className:R,children:[q(`option`,{value:``,children:`— select a cap —`}),f.map(e=>q(`option`,{value:e.cap,children:e.cap},e.cap))]})]}),U(`div`,{children:[q(`label`,{htmlFor:`link-target-field`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Target field`}),U(`select`,{id:`link-target-field`,value:x,disabled:y===``,onChange:e=>S(e.target.value),className:R,children:[q(`option`,{value:``,children:`— select a field —`}),I.map(e=>q(`option`,{value:e.path,children:e.item===!0?`${e.path} (per item, ${e.kind})`:`${e.path} (${e.kind})`},e.path))]})]}),ce&&U(`div`,{children:[q(`label`,{htmlFor:`link-target-item-key`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Item key`}),q(`input`,{id:`link-target-item-key`,type:`text`,value:C,placeholder:`e.g. main-brush`,onChange:e=>w(e.target.value),className:R}),q(`p`,{className:`mt-1 text-[10px] text-foreground-subtle/60`,children:`Links sharing the same item key build one item (e.g. one consumable).`})]})]}),U(`fieldset`,{className:`flex flex-col gap-3`,children:[q(`legend`,{className:`text-[10px] font-semibold uppercase tracking-widest text-foreground-subtle/70 mb-1`,children:`Source`}),U(`div`,{children:[q(`label`,{htmlFor:`link-source-mode`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Source mode`}),U(`select`,{id:`link-source-mode`,value:_,onChange:e=>pe(e.target.value),className:R,children:[q(`option`,{value:`sibling`,children:`Sibling device (same container)`}),q(`option`,{value:`global`,children:`Any device`}),q(`option`,{value:`literal`,children:`Literal constant`}),q(`option`,{value:`expression`,children:`Expression (computed)`})]})]}),_===`literal`&&U(et,{children:[U(`div`,{children:[q(`label`,{htmlFor:`link-literal-type`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Literal type`}),U(`select`,{id:`link-literal-type`,value:re,onChange:e=>{let t=e.target.value;(t===`string`||t===`number`||t===`boolean`||t===`null`)&&(M(t),t===`boolean`&&N(`true`),t===`null`&&N(``))},className:R,children:[q(`option`,{value:`string`,children:`string`}),q(`option`,{value:`number`,children:`number`}),q(`option`,{value:`boolean`,children:`boolean`}),q(`option`,{value:`null`,children:`null`})]})]}),re!==`null`&&(re===`boolean`?U(`div`,{children:[q(`label`,{htmlFor:`link-literal-value`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Literal value`}),U(`select`,{id:`link-literal-value`,value:ie,onChange:e=>N(e.target.value),className:R,children:[q(`option`,{value:`true`,children:`true`}),q(`option`,{value:`false`,children:`false`})]})]}):U(`div`,{children:[q(`label`,{htmlFor:`link-literal-value`,className:`block text-[11px] font-medium text-foreground-subtle mb-1`,children:`Literal value`}),q(`input`,{id:`link-literal-value`,type:`text`,value:ie,placeholder:re===`number`?`e.g. 42`:`e.g. main-brush`,onChange:e=>N(e.target.value),className:R})]}))]}),_===`expression`&&q(ri,{devices:c,siblings:u,targetDeviceId:e,containerStableId:l,initial:h,onChange:oe}),(_===`sibling`||_===`global`)&&q(Gr,{mode:_,idPrefix:`link-source`,labelPrefix:`Source`,pickerDevices:de,value:{sourceId:T,cap:D,fieldPath:O},onChange:(e,t)=>{E(e.sourceId),ee(e.cap),k(e.fieldPath),ne(t)},search:A,onSearchChange:j})]}),q(Ur,{value:P,onChange:F,sourceField:_===`literal`||_===`expression`?void 0:te,targetKind:se?.kind}),U(`div`,{className:`flex items-center justify-end gap-2 pt-2 border-t border-border`,children:[q(`button`,{type:`button`,onClick:o,className:`px-3 py-1.5 rounded-md text-xs font-medium border border-border text-foreground-subtle hover:bg-surface-hover hover:text-foreground transition-colors`,children:`Cancel`}),q(`button`,{type:`button`,disabled:!he,onClick:_e,className:`px-3 py-1.5 rounded-md text-xs font-medium bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:`Save`})]})]})}H();function pi({deviceId:e}){let t=X(),r=G(),i=Number.isFinite(e),{data:a,isLoading:o}=u({deviceId:e},{enabled:i,refetchInterval:1e4}),{data:s}=n({deviceId:e,includeSynthesizable:!0},{enabled:i}),c=new Map;for(let e of s?.caps??[])e.itemArray&&c.set(e.cap,e.itemArray);let l=j({onSuccess:()=>{r.invalidateQueries({queryKey:[[`deviceManager`]]})}}),d=a?.deviceLinks??[],f=typeof a?.parentDeviceId==`number`?a.parentDeviceId:null,p=typeof a?.stableId==`string`?a.stableId:``,[m,h]=K(null),g=t=>{l.mutate({deviceId:e,deviceLinks:d.filter(e=>e.id!==t)})};return o?q(`div`,{className:`p-4`,children:q(`div`,{className:`h-20 rounded-lg border border-border bg-surface animate-pulse`})}):m===null?U(`div`,{className:`flex flex-col gap-3 p-1`,children:[U(`div`,{className:`flex items-center justify-between`,children:[q(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Wiring`}),U(`button`,{type:`button`,onClick:()=>h(`new`),title:`Add a cross-device link`,className:`inline-flex items-center gap-1 rounded-md border border-border px-2 py-1 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[q(jt,{className:`h-3 w-3`}),`Add link`]})]}),d.length===0?U(`div`,{className:`flex flex-col items-center justify-center gap-2 py-8 text-foreground-subtle`,children:[q(ln,{className:`h-8 w-8 opacity-30`}),q(`p`,{className:`text-xs`,children:`No links yet.`}),q(`p`,{className:`text-[10px] opacity-60`,children:`Cross-device field wirings will appear here once authored.`})]}):q(`div`,{className:`flex flex-col divide-y divide-border rounded-lg border border-border overflow-hidden`,children:d.map(n=>q(hi,{deviceId:e,link:n,itemArray:c.get(n.target.cap),trpcClient:t.trpcClient,onDelete:()=>g(n.id),onEdit:()=>h(n),isPending:l.isPending},n.id))})]}):U(`div`,{className:`flex flex-col gap-3 p-1`,children:[q(`div`,{className:`flex items-center justify-between`,children:q(`h3`,{className:`text-xs font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:m===`new`?`Add link`:`Edit link`})}),q(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:q(fi,{deviceId:e,parentDeviceId:f,deviceStableId:p,initial:m===`new`?null:m,onSave:t=>{let n=d.some(e=>e.id===t.id)?d.map(e=>e.id===t.id?t:e):[...d,t];l.mutate({deviceId:e,deviceLinks:n}),h(null)},onCancel:()=>{h(null)}})})]})}function mi(e,t,n,r){let i=dt(e,t.path);if(!Array.isArray(i))return;let a=i.find(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Reflect.get(e,t.keyField)===n);return a===void 0?void 0:dt(a,r)}function hi({deviceId:e,link:t,itemArray:n,trpcClient:r,onDelete:i,onEdit:a,isPending:o}){let s=je(r,e,t.target.cap),c=t.target.itemKey,l=s===void 0?void 0:c!==void 0&&n!==void 0?mi(s,n,c,t.target.fieldPath):c===void 0?dt(s,t.target.fieldPath):void 0,u=l==null?`—`:String(l);return U(`div`,{className:`flex items-center gap-3 px-3 py-2.5 bg-surface hover:bg-surface-hover transition-colors`,children:[q(un,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle/40`}),U(`div`,{className:`min-w-0 flex-1 flex flex-col gap-0.5`,children:[U(`div`,{className:`flex items-baseline gap-1 flex-wrap`,children:[q(`span`,{className:`font-mono text-[11px] font-medium text-foreground`,children:t.target.cap}),q(`span`,{className:`text-[10px] text-foreground-subtle/60`,children:`.`}),q(`span`,{className:`font-mono text-[11px] text-foreground-subtle`,children:t.target.fieldPath}),c!==void 0&&q(`span`,{className:`rounded bg-surface-hover px-1 py-px font-mono text-[9px] text-foreground-subtle`,title:`Item key — links sharing it build one array item`,children:c})]}),U(`div`,{className:`flex items-baseline gap-1 flex-wrap text-[10px] text-foreground-subtle/70`,children:[q(`span`,{children:`←`}),t.source.kind===`literal`?U(`span`,{className:`font-mono`,children:[`literal: `,String(t.source.value)]}):t.source.kind===`expression`?U(et,{children:[U(`span`,{className:`font-mono`,title:t.source.expr,children:[`ƒ`,` `,t.source.expr.length>40?`${t.source.expr.slice(0,40)}…`:t.source.expr]}),U(`span`,{className:`rounded bg-surface-hover px-1 py-px font-mono text-[9px] text-foreground-subtle`,title:`Number of source bindings`,children:[Object.keys(t.source.bindings).length,` bindings`]})]}):U(et,{children:[q(`span`,{className:`font-mono`,children:t.source.kind===`global`?t.source.sourceStableId:t.source.sourceKey}),q(`span`,{className:`opacity-60`,children:`/`}),q(`span`,{className:`font-mono`,children:t.source.cap}),q(`span`,{className:`opacity-60`,children:`.`}),q(`span`,{className:`font-mono`,children:t.source.fieldPath})]})]})]}),t.transform&&q(gi,{kind:t.transform.kind}),q(`span`,{className:`font-mono text-[11px] tabular-nums min-w-[2.5rem] text-right text-foreground-subtle`,title:`Live resolved value (from this device's runtime-state slice)`,children:u}),q(`button`,{type:`button`,"aria-label":`Edit link`,title:`Edit this link`,disabled:o,onClick:a,className:`shrink-0 inline-flex items-center gap-1 rounded-md border border-border/80 px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:`Edit`}),q(`button`,{type:`button`,"aria-label":`Delete link`,title:`Remove this link`,disabled:o,onClick:i,className:`shrink-0 inline-flex items-center gap-1 rounded-md border border-border/80 px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:text-danger hover:border-danger/50 hover:bg-danger/5 transition-colors disabled:opacity-50`,children:`Delete`})]})}function gi({kind:e}){return q(`span`,{className:`inline-flex items-center rounded-md border border-primary/20 bg-primary/5 px-1.5 py-0.5 font-mono text-[10px] text-primary/80 shrink-0`,children:e})}H();var _i=[{id:`overview`,label:`Overview`,cameraOnly:!1},{id:`config`,label:`Config`,cameraOnly:!1},{id:`detection-pipeline`,label:`Detection pipeline`,cameraOnly:!0},{id:`bindings`,label:`Bindings`,cameraOnly:!0},{id:`wiring`,label:`Wiring`,cameraOnly:!1}];function vi(e){let t=e===Y.Camera;return _i.filter(e=>t||!e.cameraOnly).map(({id:e,label:t})=>({id:e,label:t}))}var yi=[{id:`logs`,icon:Jt,label:`Logs`},{id:`repl`,icon:Gt,label:`REPL`},{id:`events`,icon:Ht,label:`Events`},{id:`state`,icon:It,label:`State`}];function bi(){let r=Yt(),a=Number(r.deviceId),c=Number.isFinite(a),d=Rt(),f=G(),m=S(),h=X(),[g,v]=Lt(),y=g.get(`tab`)??`overview`,b=g.get(`sub`),[x,C]=K(`logs`),w=`device-detail.left-col-width-px`,[E,D]=K(()=>{if(typeof window>`u`)return null;let e=window.localStorage.getItem(w),t=e?Number(e):NaN;return Number.isFinite(t)&&t>0?t:null}),ee=V(E);ee.current=E;function O(e){e.preventDefault();let t=e.clientX,n=e.currentTarget.previousElementSibling?.getBoundingClientRect().width??E??0,r=Math.max(330,Math.floor(window.innerWidth*.7)),i=e=>{D(Math.max(280,Math.min(r,n+(e.clientX-t))))},a=()=>{document.removeEventListener(`mousemove`,i),document.removeEventListener(`mouseup`,a);let e=ee.current;if(e!==null)try{window.localStorage.setItem(w,String(Math.round(e)))}catch{}document.body.style.userSelect=``,document.body.style.cursor=``};document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,document.addEventListener(`mousemove`,i),document.addEventListener(`mouseup`,a)}let{data:k,isLoading:te,isError:ne}=u({deviceId:a},{enabled:c,refetchInterval:5e3,retry:1}),{data:A}=s({deviceId:a},{enabled:c}),j=W(()=>{let e=A?.settings?.sections??[],t=A?.live?.sections??[],n=[...e,...t],r=new Set;for(let e of n)e.location===`top-tab`&&e.tab&&r.add(e.tab===`zones`?`detection-pipeline`:e.tab);return n.some(qn)&&r.add(Wn),[...r].map(e=>e===`export`?{id:e,label:Gn,isAddonContrib:!0}:{id:e,label:ct[e]?.label??e,isAddonContrib:!0})},[A]),M=k,N=String(M?.name??r.deviceId??`Device`),ae=M?.online===!0,oe=ae?`online`:`offline`,P=String(M?.addonId??`rtsp`),F=M?.features??[],I=M?.type,se=I===Y.Camera,{data:ce}=Ct(c?a:0),ue=I===Y.Container,fe=W(()=>(ce??[]).map(e=>({id:e.id,stableId:e.stableId,type:e.type,...e.sourceInfo?{sourceInfo:{id:e.sourceInfo.id}}:{}})),[ce]),L=W(()=>ue?he(fe,typeof M?.linkDeviceId==`number`?M.linkDeviceId:null,typeof M?.primaryChildEntityId==`string`?M.primaryChildEntityId:null)?.id??null:null,[ue,fe,M?.linkDeviceId,M?.primaryChildEntityId]),{data:me}=s({deviceId:L??0},{enabled:L!==null}),ge=W(()=>{if(L===null)return[];let e=me?.settings?.sections??[],t=me?.live?.sections??[],n=new Set;for(let r of[...e,...t])r.location===`top-tab`&&r.tab&&n.add(r.tab);return[...n].map(e=>({id:e,label:ct[e]?.label??e,isAddonContrib:!0,childDeviceId:L}))},[L,me]),_e=typeof M?.parentDeviceId==`number`?M.parentDeviceId:null,{data:R}=u({deviceId:_e??0},{enabled:_e!==null}),z=Pe(),ve=M?.disabled!==!0,{data:ye}=n({deviceId:a},{enabled:c}),be=(ye?.caps.length??0)>0,Se=W(()=>{let e=new Set,t=[];for(let n of[...vi(I),...j,...ge])e.has(n.id)||(e.add(n.id),!(n.id===`wiring`&&!be)&&t.push(n));return t},[I,j,ge,be]),Ce=W(()=>Se.some(e=>e.id===y)?y:`overview`,[Se,y]),we=B(e=>{v(t=>{let n=new URLSearchParams(t);return e===`overview`?n.delete(`tab`):n.set(`tab`,e),n.delete(`sub`),n},{replace:!0})},[v]),Te=B(e=>{v(t=>{let n=new URLSearchParams(t);return n.set(`sub`,e),n},{replace:!0})},[v]),Ee=(ce??[]).length>0,De=W(()=>yi.filter(({featureGate:e})=>!e||F.includes(e)),[F]),{data:ke}=Je({addonId:P},{enabled:!!P&&P!==`rtsp`}),Ae=_({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]}),d(ke?.id?`/integrations/${ke.id}`:`/integrations`)}}),je=re({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Me=pe({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Fe=le(),Ie=ie({onSuccess:()=>{f.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Le=F.includes(ft.Rebootable),Re=F.includes(ft.BatteryOperated),ze=e(h.trpcClient,Re&&c?a:null),[Be,Ve]=K(!1),He=mt(h.trpcClient,c?a:null),Ue=async()=>{if(!(Be||!He)){Ve(!0);try{await He.snapshot?.invalidateCache({});let e=await He.snapshot?.getSnapshot({});if(!e)return;let t=`data:${e.contentType};base64,${e.base64}`,n=e.contentType.includes(`png`)?`png`:`jpg`,r=N.replace(/[^a-zA-Z0-9_.-]+/g,`_`),i=new Date().toISOString().replace(/[:.]/g,`-`),a=document.createElement(`a`);a.href=t,a.download=`${r}-${i}.${n}`,document.body.appendChild(a),a.click(),document.body.removeChild(a)}finally{Ve(!1)}}},We=je.isPending||Me.isPending,{data:Ge}=xe({deviceId:a},{enabled:c,refetchInterval:1e4}),Ke=Ge?.agentNodeId??null,qe=typeof Ke==`string`&&Ke.length>0&&!Ke.startsWith(`addon:`)?Ke:void 0,{data:Ye}=p({deviceId:a,...qe?{nodeId:qe}:{}},{enabled:c,refetchInterval:3e3,retry:!1}),{data:Xe}=i({deviceId:a},{enabled:c,refetchInterval:3e3,retry:!1}),Ze=Xe?.level?.dbfs??null;function Qe(){if(!c)return null;switch(Ce){case`overview`:return q(Ir,{device:M??{}});case`config`:return q(sr,{deviceId:a,activeSubTab:b,onSubTabChange:Te});case`detection-pipeline`:return q(yr,{deviceId:a,activeSubTab:b,onSubTabChange:Te});case`bindings`:return q(Rn,{deviceId:a});case`wiring`:return q(pi,{deviceId:a});default:{let e=Ce,t=j.some(t=>t.id===e),n=ge.find(t=>t.id===e);if(!t&&n===void 0)return null;let r=n?.childDeviceId??a;if(e===`export`)return q(or,{deviceId:a,sectionFilter:qn,activeSubTab:b,onSubTabChange:Te});let i=q(or,{deviceId:r,sectionFilter:t=>t.location===`top-tab`&&(t.tab===e||e===`detection-pipeline`&&t.tab===`zones`),flattenSubTabs:e===`detection-pipeline`,activeSubTab:b,onSubTabChange:Te});return n!==void 0&&r!==a?q(T,{deviceId:r,children:i}):i}}}return c?te?U(`div`,{className:`flex flex-col h-full`,children:[U(`div`,{className:`border-b border-border bg-surface px-6 py-4`,children:[q(`div`,{className:`h-4 w-48 rounded bg-surface-hover animate-pulse mb-3`}),q(`div`,{className:`h-8 w-64 rounded bg-surface-hover animate-pulse`})]}),q(`div`,{className:`flex-1 p-6`,children:q(`div`,{className:`h-40 rounded-lg border border-border bg-surface animate-pulse`})})]}):ne||!k?U(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[q(`p`,{className:`text-lg font-semibold text-foreground`,children:`Device not found`}),U(`p`,{className:`text-xs`,children:[`No device with ID`,` `,U(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:[`#`,a]})]}),q(`button`,{onClick:()=>d(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]}):U(`div`,{className:`absolute inset-0 flex flex-col overflow-hidden`,children:[U(`div`,{className:`border-b border-border bg-surface px-6 py-3 flex-shrink-0`,children:[q(`div`,{className:`mb-2`,children:q(t,{items:[{label:`Integrations`,onClick:()=>d(`/integrations`)},{label:ke?.name??P,onClick:()=>ke?.id&&d(`/integrations/${ke.id}`)},{label:N}]})}),U(`div`,{className:`flex items-center gap-2 sm:gap-3`,children:[q(St,{type:P,size:`lg`}),U(`div`,{className:`min-w-0 flex-1`,children:[U(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[q(`h1`,{className:`text-sm sm:text-base font-semibold text-foreground truncate`,children:N}),q(nn,{status:oe}),Re&&q(de,{status:ze,variant:`full`})]}),_e!==null&&R&&U(`button`,{type:`button`,onClick:()=>d(`/devices/${_e}`),className:`text-[10px] text-foreground-subtle hover:text-primary transition-colors mt-0.5 inline-flex items-center gap-1`,title:`Open parent device ${R.name}`,children:[q(`span`,{children:`↑`}),q(`span`,{className:`truncate`,children:String(R.name??`Device #${_e}`)})]}),q(`div`,{className:`hidden md:flex items-center gap-3 mt-0.5 text-[10px] text-foreground-subtle`,children:F.length>0&&q(yt,{capabilities:F})})]}),Ye&&q(`div`,{className:`hidden lg:flex`,children:q(xi,{metrics:Ye,dbfs:Ze})}),U(`div`,{className:`flex items-center gap-1 shrink-0`,children:[U(`button`,{onClick:async()=>{ve?await m({title:`Disable "${N}"?`,message:`The device will stop processing streams and events. You can re-enable it later.`,confirmLabel:`Disable`,variant:`danger`})&&Me.mutate({deviceId:a}):je.mutate({deviceId:a})},disabled:We,title:ve?`Disable device`:`Enable device`,className:`inline-flex items-center gap-1.5 rounded-lg px-2 sm:px-2.5 py-1.5 text-[11px] font-medium border transition-colors disabled:opacity-50 ${ve?`border-success/30 text-success hover:bg-success/10`:`border-border text-foreground-subtle/50 hover:text-foreground hover:bg-surface-hover`}`,children:[q(dn,{className:`h-3.5 w-3.5`}),q(`span`,{className:`hidden sm:inline`,children:We?`Updating…`:ve?`Enabled`:`Disabled`})]}),q(`div`,{className:`hidden sm:block h-5 w-px bg-border mx-1`}),q(Oe,{triggerClassName:`ml-1`,items:[{id:`snapshot`,label:`Take snapshot`,description:`Fetch a fresh frame and download it.`,icon:tn,disabled:Be,onClick:()=>{Ue()}},{id:`reboot`,label:`Reboot device`,description:`Camera goes offline for ~30 seconds.`,icon:Nt,hidden:!Le,disabled:Fe.isPending,danger:!0,onClick:async()=>{await m({title:`Reboot "${N}"?`,message:`The camera will go offline for around 30 seconds while the firmware reboots.`,confirmLabel:`Reboot`,variant:`danger`})&&Fe.mutate({deviceId:a})}},{id:`restart-addon`,label:`Restart addon`,description:`Bounces every device served by ${ke?.name??P}.`,icon:Mt,disabled:Ie.isPending,danger:!0,onClick:async()=>{await m({title:`Restart "${ke?.name??P}"?`,message:`Restarting the addon will briefly disconnect every device served by it (not just "${N}"). Streams will reconnect automatically.`,confirmLabel:`Restart`,variant:`danger`})&&Ie.mutate({addonId:P})}},{id:`delete`,label:`Delete device`,description:`Remove the device and all its settings.`,icon:Zt,separatorBefore:!0,disabled:Ae.isPending,danger:!0,onClick:async()=>{await m({title:`Delete "${N}"?`,message:`This will remove the device and all its settings. This action cannot be undone.`,confirmLabel:`Delete`,variant:`danger`})&&Ae.mutate({deviceId:a})}}]})]})]})]}),q(T,{deviceId:a,device:M??void 0,children:q(o,{children:q(l,{children:q(_t,{children:q(Ne,{children:U(`main`,{className:z?`flex-1 overflow-y-auto flex flex-col`:`flex-1 min-h-0 overflow-hidden flex flex-row`,children:[U(`div`,{className:z?`flex flex-col bg-surface`:`${E===null?`w-1/2 lg:w-1/3`:``} flex-shrink-0 flex flex-col bg-surface min-h-0 overflow-hidden`,style:!z&&E!==null?{width:`${String(E)}px`}:void 0,children:[q(`div`,{className:se?`flex-shrink-0 border-b border-border-subtle bg-black`:z?`flex-shrink-0 border-b border-border-subtle bg-surface`:`max-h-[55%] shrink-0 overflow-y-auto border-b border-border-subtle bg-surface`,children:se?q(Nn,{deviceId:a,intercomAvailable:F.includes(ft.TwoWayAudio)}):q(wn,{deviceId:a,deviceName:N,deviceType:I??`unknown`,provider:P,isOnline:ae,features:F})}),U(`div`,{className:z?`flex flex-col border-b border-border`:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[q(`div`,{className:`flex-shrink-0 border-b border-border-subtle px-2 py-1.5`,children:q(`div`,{className:`flex gap-1 overflow-x-auto -mx-1 px-1 pb-0.5`,children:De.map(({id:e,label:t,icon:n})=>U(`button`,{onClick:()=>C(e),title:t,className:`flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors flex-shrink-0 ${x===e?`bg-primary/15 text-primary`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:[q(n,{className:`h-3 w-3`}),t]},e))})}),U(`div`,{className:z?`h-72 overflow-hidden`:`flex-1 min-h-0 overflow-hidden`,children:[x===`logs`&&q(Pn,{deviceId:a,containerDeviceId:I===`container`?a:void 0}),x===`repl`&&q(Fn,{deviceId:a}),x===`events`&&q(In,{deviceId:a}),x===`state`&&q(Ln,{deviceId:a})]})]})]}),!z&&q(`div`,{role:`separator`,"aria-orientation":`vertical`,title:`Drag to resize`,onMouseDown:O,className:`flex-shrink-0 w-1 cursor-col-resize bg-border hover:bg-primary/40 transition-colors group relative z-10`,children:q(`span`,{className:`absolute inset-y-0 -left-1 -right-1`})}),U(`div`,{className:z?`flex flex-col`:`flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden`,children:[q(`div`,{className:`flex-shrink-0 border-b border-border bg-surface px-4`,children:q(`div`,{className:`flex flex-nowrap overflow-x-auto md:flex-wrap md:overflow-x-visible items-center gap-0`,children:Se.map(e=>{let t=Ce===e.id;return U(`button`,{onClick:()=>we(e.id),className:`relative flex-shrink-0 px-3 py-2 text-xs font-medium transition-colors ${t?`text-primary`:`text-foreground-subtle hover:text-foreground`}`,children:[e.label,t&&q(`span`,{className:`absolute bottom-0 left-0 right-0 h-0.5 rounded-full bg-primary`})]},e.id)})})}),U(`div`,{className:z?`p-3 flex flex-col gap-3`:`flex-1 min-h-0 overflow-y-auto p-4 flex flex-col gap-3`,children:[Ce===`overview`&&Ee&&q(pn,{parentDeviceId:a}),Qe()]})]})]})})})})})})]}):U(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-foreground-subtle`,children:[q(`p`,{className:`text-lg font-semibold text-foreground`,children:`Invalid device id`}),U(`p`,{className:`text-xs`,children:[`The URL segment`,` `,q(`code`,{className:`font-mono bg-surface px-1.5 py-0.5 rounded text-[11px]`,children:r.deviceId}),` `,`is not a number.`]}),q(`button`,{onClick:()=>d(`/integrations`),className:`mt-2 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:`Back to Integrations`})]})}function xi({metrics:e,dbfs:t}){let n=c(e.phase??`idle`);return U(`div`,{className:`flex items-center gap-3 flex-shrink-0`,children:[U(`div`,{className:`flex items-center gap-1.5`,children:[q(`span`,{className:`h-1.5 w-1.5 rounded-full ${n.dotClass}`}),q(`span`,{className:`text-[10px] font-medium ${n.textColor}`,children:n.label})]}),q(`div`,{className:`h-3 w-px bg-border`}),U(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[q(Vt,{className:`h-3 w-3`}),q(`span`,{className:`text-foreground tabular-nums`,children:(e.actualFps??0).toFixed(1)}),q(`span`,{children:`fps`})]}),U(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[q(qt,{className:`h-3 w-3`}),q(`span`,{className:`text-foreground tabular-nums`,children:(e.avgInferenceTimeMs??0).toFixed(0)}),q(`span`,{children:`ms`})]}),U(`div`,{className:`flex items-center gap-1 text-[10px] text-foreground-subtle`,title:`Current audio level (dBFS)`,children:[q(fn,{className:`h-3 w-3`}),q(`span`,{className:`text-foreground tabular-nums`,children:t==null?`—`:t.toFixed(0)}),q(`span`,{children:`dB`})]}),(e.queueDepth??0)>0&&U(`span`,{className:`text-[10px] text-warning tabular-nums`,children:[`q:`,e.queueDepth]})]})}export{bi as DeviceDetailPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{B as e,Gr as t,Jr as n,Na as r,So as i,Wa as a,Wr as o,Zr as s,do as c,fo as l,jn as u,jr as d,q as f,qr as p,xt as m,z as h}from"./src-Bwet06Ih.js";import{I as g,K as _,Q as v,S as y,W as b,b as x,i as S,o as C,q as w,x as T,z as E}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{E as D,K as O,P as k,s as A}from"./src-GxiMH1Sc.js";import{p as j}from"./player-overlays-BlOdAA3b.js";import{t as M}from"./clock-HmbKVCZT.js";import{t as N}from"./copy-BmgVaD29.js";import{a as ee,c as te,d as P,f as F,i as ne,m as I,n as re,o as L,p as R,r as ie,s as z,t as B}from"./debounced-invalidate-DCtq_NHc.js";import{t as V}from"./search-BUbY58eR.js";import{t as H}from"./square-check-big-tgpBR4IT.js";import{t as ae}from"./square-Ckdv6ORu.js";import{E as oe,I as U,L as W,P as se,S as G,U as K,W as q,i as ce,s as le,t as ue}from"./index-RegSp4ae.js";import{t as de}from"./AdminPage-BwmGKnRf.js";import{r as fe,t as pe}from"./authed-media-XfBD4Ma-.js";var me=q(`arrow-down-wide-narrow`,[[`path`,{d:`m3 16 4 4 4-4`,key:`1co6wj`}],[`path`,{d:`M7 20V4`,key:`1yoxec`}],[`path`,{d:`M11 4h10`,key:`1w87gc`}],[`path`,{d:`M11 8h7`,key:`djye34`}],[`path`,{d:`M11 12h4`,key:`q8tih4`}]]),he=q(`square-parking`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 17V7h4a3 3 0 0 1 0 6H9`,key:`1dfk2c`}]]),ge=q(`tag`,[[`path`,{d:`M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z`,key:`vktsd0`}],[`circle`,{cx:`7.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`kqv944`}]]);v();var _e=720*60*60*1e3;function ve(e){let t=[];for(let n of e)t.push(...n);return t}function ye(e,t){let n=[...e];return n.sort((e,n)=>t===`importance`?n.importance-e.importance:n.timestamp-e.timestamp),n}function be(e,t){return e.filter(e=>!(e.importance<t.minImportance||t.cameras.size>0&&!t.cameras.has(e.deviceId)||t.classes.size>0&&!t.classes.has(e.className)))}function J(e,t){return`${String(e)}:${t}`}function xe(e,t){let n=new Map,r=new Set;for(let i of e){let e=J(i.deviceId,i.trackId);if(!t.has(e)||r.has(e))continue;r.add(e);let a=n.get(i.deviceId);a?a.push(i.trackId):n.set(i.deviceId,[i.trackId])}return n}function Se(e,t){return{since:e.fromMs??t-_e,until:e.toMs??t}}var Y=typeof o==`function`,Ce=`Track deletion arrives with the next server update`;function we(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var Te=Y?o:we,Ee=200,De=3e4;function Oe(e){let t=j(),n=S({queries:e.deviceIds.map(n=>({queryKey:[`events-feed`,n,e.since,e.until,e.minImportance??null,e.classFilter??null],staleTime:De,refetchInterval:De,queryFn:async()=>(await t.trpcClient.pipelineAnalytics.getKeyEvents.query({deviceId:n,since:e.since,until:e.until,limit:Ee,...e.minImportance===void 0?{}:{minImportance:e.minImportance},...e.classFilter===void 0?{}:{classFilter:e.classFilter}})).map(e=>({...e,deviceId:n}))}))});return{rows:ye(ve(n.map(e=>e.data??[])),`importance`),isLoading:n.some(e=>e.isLoading)}}var ke=[`events-feed`],Ae=2e3;function je(){let e=C(),t=_(e);t.current=e;let n=_(void 0);n.current||=B({delayMs:Ae,invalidate:()=>{t.current.invalidateQueries({queryKey:ke})}}),E(()=>()=>n.current?.cancel(),[]),a(O.PipelineAnalyticsDetectionEvent,()=>{n.current?.trigger()}),a(O.PipelineAnalyticsTrackEnded,()=>{n.current?.trigger()})}v();function Me(){return Object.values(k).filter(e=>e.level===`macro`).map(e=>({macro:e,subs:Object.values(k).filter(t=>t.parentKind===e.kind).sort((e,t)=>e.label.localeCompare(t.label))})).sort((e,t)=>e.macro.label.localeCompare(t.macro.label))}function Ne({selected:t,onChange:n}){let{t:r}=ue(),[i,a]=w(!1),[o,s]=w(``),[c,l]=w(new Set),u=b(Me,[]),d=o.trim().toLowerCase(),f=e=>d.length===0||h(e,r).toLowerCase().includes(d),p=b(()=>u.map(e=>({macro:e.macro,subs:e.subs.filter(t=>f(t)||f(e.macro))})).filter(e=>f(e.macro)||e.subs.length>0),[u,d]),m=e=>l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),g=e=>{let r=new Set(t),i=t.has(e.macro.kind)&&e.subs.every(e=>t.has(e.kind)),a=[e.macro.kind,...e.subs.map(e=>e.kind)];if(i)for(let e of a)r.delete(e);else for(let e of a)r.add(e);n(r)},_=e=>{let r=new Set(t);r.has(e)?r.delete(e):r.add(e),n(r)},v=()=>n(new Set),x=t.size;return y(`div`,{className:`relative`,children:[y(`button`,{type:`button`,onClick:()=>a(e=>!e),className:`flex items-center gap-1 rounded-md px-2.5 py-1 text-xs transition-colors ${x>0?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[T(ge,{className:`h-3.5 w-3.5`}),x>0?`Kinds (${String(x)})`:`Kinds`,T(U,{className:`h-3 w-3`})]}),i&&y(`div`,{className:`absolute z-20 mt-1 max-h-80 w-64 overflow-auto rounded-md border border-border bg-surface p-2 shadow-lg`,children:[y(`div`,{className:`mb-2 flex items-center gap-1 rounded border border-border px-1.5`,children:[T(V,{className:`h-3.5 w-3.5 text-foreground-subtle`}),T(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:`Search kinds…`,className:`w-full bg-transparent py-1 text-xs outline-none`}),x>0&&T(`button`,{type:`button`,onClick:v,className:`text-[10px] text-foreground-subtle hover:text-foreground`,children:`Clear`})]}),p.map(n=>{let i=e(n.macro.iconId),a=c.has(n.macro.kind)||d.length>0,o=t.has(n.macro.kind);return y(`div`,{className:`mb-0.5`,children:[y(`div`,{className:`flex items-center gap-1`,children:[n.subs.length>0?T(`button`,{type:`button`,onClick:()=>m(n.macro.kind),className:`text-foreground-subtle hover:text-foreground`,"aria-label":`Expand`,children:T(a?U:se,{className:`h-3 w-3`})}):T(`span`,{className:`w-3`}),y(`label`,{className:`flex flex-1 cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[T(`input`,{type:`checkbox`,checked:o,onChange:()=>g(n),className:`accent-primary`}),T(i,{className:`h-3.5 w-3.5`,style:{color:n.macro.color}}),T(`span`,{className:`font-medium`,children:h(n.macro,r)})]})]}),a&&n.subs.map(n=>{let i=e(n.iconId);return y(`label`,{className:`ml-5 flex cursor-pointer items-center gap-1.5 rounded px-1 py-0.5 text-xs hover:bg-surface-hover`,children:[T(`input`,{type:`checkbox`,checked:t.has(n.kind),onChange:()=>_(n.kind),className:`accent-primary`}),T(i,{className:`h-3.5 w-3.5`,style:{color:n.color}}),T(`span`,{children:h(n,r)})]},n.kind)})]},n.macro.kind)})]})]})}var X=100,Pe=120,Fe={polyline:``,points:[],snapshots:[],start:null,end:null,peakBox:null},Z=e=>e<0?0:e>1?1:e,Q=e=>Math.round(e*100)/100;function Ie(e,t){if(e.length<=t)return[...e];let n=(e.length-1)/(t-1),r=[];for(let i=0;i<t;i++)r.push(e[Math.round(i*n)]);return r[r.length-1]=e[e.length-1],r}function Le(e,t,n){if(e.length===0||t===null)return Fe;let{width:r,height:i}=t;if(!Number.isFinite(r)||!Number.isFinite(i)||r<=0||i<=0)return Fe;let a=Ie(e,n?.maxPoints??Pe).map(e=>({x:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X)})),o=a[0]??null,s=a[a.length-1]??null,c=a.length>=2?a.map(e=>`${e.x},${e.y}`).join(` `):``,l=(n?.snapshots??[]).map(e=>({x:Q(Z(e.x/r)*X),y:Q(Z(e.y/i)*X),mediaKey:e.mediaKey})),u=null,d=-1;for(let t of e){let e=Z(t.bbox.w/r)*Z(t.bbox.h/i);e>d&&(d=e,u=t)}return{polyline:c,points:a,snapshots:l,start:o,end:s,peakBox:u?{x:Q(Z(u.bbox.x/r)*X),y:Q(Z(u.bbox.y/i)*X),w:Q(Z(u.bbox.w/r)*X),h:Q(Z(u.bbox.h/i)*X)}:null}}var Re={firstFrame:`First frame (track start)`,lastFrame:`Last frame (track end)`,thumbnail:`Best detection`,thumbnailSmall:`Best detection (480)`,snapshot:`Snapshot`,keyFrame:`Key frame (native-res)`,keyFrameSmall:`Key frame (960)`,crop:`Object crop`,fullFrame:`Full frame`,fullFrameBoxed:`Full frame (boxed)`,faceCrop:`Face crop`,plateCrop:`Plate crop`};function ze(e){return e in Re}function Be(e){return ze(e)?Re[e]:e}function Ve(e,t){return`${e}${pe}/${encodeURIComponent(t)}`}v();var He=1400,Ue=`Admin-gated URL — opens only inside an authenticated session`;function We({label:e,value:t,title:n}){let[r,i]=w(!1);return E(()=>{if(!r)return;let e=setTimeout(()=>i(!1),He);return()=>clearTimeout(e)},[r]),y(`button`,{type:`button`,onClick:g(()=>{(async()=>{try{await navigator.clipboard.writeText(t),i(!0)}catch{window.prompt(`Copy the media URL:`,t)}})()},[t]),title:n,"aria-label":`Copy ${e} URL`,className:`flex min-w-0 items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium transition-colors ${r?`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:`border-border text-foreground-subtle hover:border-primary hover:text-foreground`}`,children:[T(r?W:N,{className:`h-2.5 w-2.5 shrink-0`}),T(`span`,{className:`truncate`,children:r?`Copied`:e})]})}function Ge({localUrl:e,publicUrl:t}){return y(`div`,{className:`flex flex-wrap gap-1`,children:[T(We,{label:`Local`,value:e,title:`Copy LAN URL — ${Ue}`}),t&&T(We,{label:`Public`,value:t,title:`Copy public URL — ${Ue}`})]})}v();var Ke=3e4;function qe(e){let[t,n]=w(null),r=g(e=>{n(t=>t??e)},[]);return E(()=>{e||n(null)},[e]),{publicOrigin:t,probes:e?T(Je,{onOrigin:r}):null}}function Je({onOrigin:e}){let{data:t}=m({capName:`network-access`});return T(x,{children:(t??[]).map(t=>T(Ye,{addonId:t.addonId,onOrigin:e},t.addonId))})}function Ye({addonId:e,onOrigin:t}){let{data:n}=d({addonId:e},{refetchInterval:Ke,retry:!1});return E(()=>{let e=n?A.safeParse(n):null,r=e?.success?e.data.endpoint?.url:void 0;if(r)try{t(new URL(r).origin)}catch{}},[n,t]),null}v();var Xe=15e3,Ze=window.location.origin,Qe=new Set([`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]),$e=new Set([`keyFrame`,`fullFrame`,`fullFrameBoxed`,`firstFrame`,`lastFrame`,`thumbnail`,`snapshot`]);function et(e){let[t,n]=w(null);return E(()=>{if(n(null),!e)return;let t=!1,r=new Image;return r.onload=()=>{t||n({width:r.naturalWidth,height:r.naturalHeight})},r.src=e,()=>{t=!0,r.onload=null}},[e]),t}function tt({overlay:e,onPickSnapshot:t}){return!e.polyline&&!e.peakBox&&e.snapshots.length===0?null:y(`svg`,{viewBox:`0 0 100 100`,preserveAspectRatio:`none`,className:`pointer-events-none absolute inset-0 h-full w-full`,children:[e.peakBox&&T(`rect`,{x:e.peakBox.x,y:e.peakBox.y,width:e.peakBox.w,height:e.peakBox.h,fill:`none`,stroke:`#f59e0b`,strokeWidth:2,vectorEffect:`non-scaling-stroke`,rx:1}),e.polyline&&T(`polyline`,{points:e.polyline,fill:`none`,stroke:`#38bdf8`,strokeWidth:2,strokeLinejoin:`round`,strokeLinecap:`round`,strokeOpacity:.85,vectorEffect:`non-scaling-stroke`}),e.points.map((e,t)=>T(`circle`,{cx:e.x,cy:e.y,r:1,fill:`#38bdf8`,fillOpacity:.6,vectorEffect:`non-scaling-stroke`},`${String(e.x)}-${String(e.y)}-${String(t)}`)),e.snapshots.map((e,n)=>T(`circle`,{cx:e.x,cy:e.y,r:1.9,fill:`#0ea5e9`,fillOpacity:.95,stroke:`#082f49`,strokeWidth:.7,vectorEffect:`non-scaling-stroke`,className:t?`pointer-events-auto cursor-pointer`:void 0,onClick:t?n=>{n.stopPropagation(),t(e.mediaKey)}:void 0,children:T(`title`,{children:`Snapshot checkpoint — click to view this frame`})},`snap-${e.mediaKey}-${String(n)}`)),e.start&&T(`circle`,{cx:e.start.x,cy:e.start.y,r:2.4,fill:`#22c55e`,stroke:`#052e16`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`}),e.end&&T(`circle`,{cx:e.end.x,cy:e.end.y,r:2.4,fill:`#ef4444`,stroke:`#450a0a`,strokeWidth:.6,vectorEffect:`non-scaling-stroke`})]})}function $({label:e,value:t,mono:n}){return y(`div`,{className:`flex items-baseline justify-between gap-3 border-b border-border/60 py-1.5 last:border-0`,children:[T(`span`,{className:`shrink-0 text-[11px] uppercase tracking-wide text-foreground-subtle`,children:e}),T(`span`,{className:`min-w-0 truncate text-right text-xs font-medium text-foreground ${n?`font-mono text-[11px]`:``}`,title:t,children:t})]})}function nt({row:e,cameraName:a,deleteAvailable:o,onClose:s,onDeleted:u}){let d=j(),f=Te(),m=e!==null,h=e?.deviceId??0,_=e?.trackId??``,v=e?.bestEventId??``,S=e?.timestamp??0,C=e?.windowMs??0,{data:D}=p({deviceId:h,trackId:_},{enabled:m}),{data:O}=n({trackId:_},{enabled:m}),{data:k}=t({eventId:v},{enabled:m&&v!==``}),{data:A}=r({deviceId:h,since:S-Xe,until:S+C+Xe},{enabled:m}),[M,N]=w(null),[ee,te]=w(!1),{publicOrigin:F,probes:re}=qe(m);E(()=>{N(null)},[h,_]);let L=b(()=>{let e=O??[],t=k??[];return e.find(e=>e.kind===`keyFrame`)||t.find(e=>e.kind===`fullFrameBoxed`)||([...t,...e].find(e=>e.kind===`crop`)??null)},[O,k]),ie=fe(L?`${pe}/${encodeURIComponent(L.key)}`:void 0),z=b(()=>{let e=new Set,t=[];for(let n of[...k??[],...O??[]])!n.base64||e.has(n.key)||(e.add(n.key),t.push(n));return t},[k,O]),B=b(()=>z.find(e=>Qe.has(e.kind))??null,[z]),V=et(B?`data:image/jpeg;base64,${B.base64}`:null),H=b(()=>Le(D?.positions??[],V,{snapshots:(D?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaKey:e.mediaKey}))}),[D?.positions,D?.snapshots,V]),ae=g(e=>{let t=z.find(t=>t.key===e);t&&N(t)},[z]);if(e===null)return null;let U=M?`data:image/jpeg;base64,${M.base64}`:ie.src,W=M?.kind??L?.kind,se=W!==void 0&&$e.has(W)&&V!==null&&(D?.positions.length??0)>=2,K=A&&A.length>0?A[0]:null,q=()=>{K&&(te(!0),(async()=>{try{let t=await d.trpcClient.videoclips.getClipPlayback.query({deviceId:e.deviceId,clipId:K.id});window.open(t.playbackUrl,`_blank`,`noopener`)}catch{window.alert(`Could not resolve clip playback. Check the server logs.`)}finally{te(!1)}})())},ue=()=>{!o||f.isPending||window.confirm(`Delete this track and all its media? This cannot be undone.`)&&(async()=>{try{await f.mutateAsync({deviceId:e.deviceId,trackIds:[e.trackId]}),u()}catch{window.alert(`Failed to delete this track. Check the server logs.`)}})()},de=Math.round(e.importance*100),me=D?.importanceReason?`${String(de)}% · ${D.importanceReason}`:`${String(de)}%`,he=D?.zonesVisited&&D.zonesVisited.length>0?D.zonesVisited.join(`, `):`—`,ge=D?.audioLabels&&D.audioLabels.length>0?D.audioLabels.map(e=>`${e.label} ×${String(e.count)} (${String(Math.round(e.peakScore*100))}%)`).join(` · `):`—`,_e=D?D.totalDistance.toFixed(2):`—`,ve=R(D?D.firstSeen:S),ye=D?R(D.lastSeen):`—`;return T(c,{open:!0,onOpenChange:e=>!e&&s(),children:y(l,{width:`lg`,placement:`sheet-on-mobile`,"aria-label":`Event detail`,className:`flex h-[92dvh] flex-col gap-0 overflow-hidden p-0 bottom-0 left-0 right-0 top-auto w-full max-w-full translate-x-0 translate-y-0 rounded-b-none md:bottom-auto md:left-1/2 md:right-auto md:top-1/2 md:h-auto md:w-[calc(100vw-2rem)] md:max-w-xl md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-lg md:max-h-[calc(100dvh-2rem)]`,children:[y(`header`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-border px-4 py-3`,children:[y(`div`,{className:`min-w-0`,children:[y(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:[e.className,e.label?y(`span`,{className:`text-foreground-subtle`,children:[` · `,e.label]}):null]}),T(`div`,{className:`mt-0.5 truncate text-[11px] text-foreground-subtle`,children:a})]}),T(`button`,{type:`button`,onClick:s,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:T(ce,{className:`h-4 w-4`})})]}),y(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-y-auto overscroll-contain px-4 py-3`,children:[U?T(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:T(ne,{src:U,alt:`Key frame from ${a}`,fit:`natural`,className:`w-full`,overlay:se?T(tt,{overlay:H,onPickSnapshot:ae}):void 0})}):T(`div`,{className:`flex aspect-video w-full flex-col items-center justify-center gap-1.5 rounded-lg border border-border bg-surface-hover text-foreground-subtle`,children:ie.failed?y(x,{children:[T(I,{className:`h-8 w-8 opacity-60`}),T(`span`,{className:`text-[11px]`,children:`Key-frame media unavailable`})]}):T(G,{className:`h-6 w-6 animate-spin opacity-70`})}),z.length>0&&T(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:z.map(e=>{let t=`data:image/jpeg;base64,${e.base64}`,n=Be(e.kind),r=Ve(Ze,e.key),i=F?Ve(F,e.key):null;return y(`figure`,{className:`flex w-32 shrink-0 flex-col gap-1`,children:[T(`button`,{type:`button`,onClick:()=>N(e),className:`relative h-16 w-full overflow-hidden rounded border border-border hover:border-primary`,title:`${n} · ${R(e.timestamp)}`,children:T(`img`,{src:t,alt:n,className:`h-full w-full object-cover`})}),y(`figcaption`,{className:`min-w-0 px-0.5`,children:[T(`div`,{className:`truncate text-[10px] font-medium leading-tight text-foreground`,title:n,children:n}),T(`div`,{className:`text-[10px] leading-tight text-foreground-subtle`,title:R(e.timestamp),children:P(e.timestamp)})]}),T(Ge,{localUrl:r,publicUrl:i})]},e.key)})}),re,K&&y(i,{variant:`secondary`,onClick:q,disabled:ee,children:[ee?T(G,{className:`h-3.5 w-3.5 animate-spin`}):T(oe,{className:`h-3.5 w-3.5`}),` `,`View clip`]}),y(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-1`,children:[T($,{label:`Camera`,value:a}),T($,{label:`Class`,value:e.className}),T($,{label:`Label`,value:e.label??`—`}),T($,{label:`Importance`,value:me}),T($,{label:`Zones visited`,value:he}),T($,{label:`Audio heard`,value:ge}),T($,{label:`Total distance`,value:_e}),T($,{label:`First seen`,value:ve}),T($,{label:`Last seen`,value:ye}),T($,{label:`Track`,value:e.trackId,mono:!0})]})]}),T(`footer`,{className:`flex shrink-0 items-center justify-end gap-2 border-t border-border px-4 py-3 pb-[max(0.75rem,env(safe-area-inset-bottom))]`,children:T(`span`,{title:o?void 0:Ce,children:y(i,{variant:`secondary`,onClick:ue,disabled:!o||f.isPending,children:[f.isPending?T(G,{className:`h-3.5 w-3.5 animate-spin`}):T(le,{className:`h-3.5 w-3.5`}),` `,`Delete track`]})})})]})})}function rt(e){if(e===void 0||!Number.isFinite(e)||e<=0)return``;let t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return`${String(n)}m ${String(r).padStart(2,`0`)}s`}function it({row:e,cameraName:t,nowMs:n,onOpenDetail:r,selected:i=!1,onToggleSelect:a,score:o}){let s=fe(e.bestEventId?`${pe}/${e.bestEventId}`:void 0),c=Math.round(e.importance*100),l=o===void 0?void 0:Math.round(o*100),u=rt(e.windowMs),d=()=>r(e);return y(`div`,{className:`relative flex flex-col rounded-md border bg-surface overflow-hidden ${i?`border-primary ring-1 ring-primary`:`border-border`}`,children:[y(`div`,{className:`aspect-video relative overflow-hidden bg-surface-hover`,children:[s.src?T(`img`,{src:s.src,alt:`Event from ${t}`,onClick:d,className:`h-full w-full cursor-zoom-in object-cover`}):T(`button`,{type:`button`,onClick:d,className:`flex h-full w-full flex-col items-center justify-center gap-1 bg-surface-hover text-foreground-subtle`,title:s.failed?`Key-event media unavailable`:`No key-event media`,children:T(I,{className:`h-6 w-6 opacity-60`})}),a&&T(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),a(J(e.deviceId,e.trackId))},className:`absolute left-0 top-0 z-10 rounded-br-md bg-black/50 p-1.5 text-white hover:bg-black/70`,"aria-label":i?`Deselect`:`Select`,children:i?T(H,{className:`h-4 w-4 text-primary`}):T(ae,{className:`h-4 w-4`})}),l!==void 0&&y(`span`,{className:`absolute left-1 top-1 z-10 rounded bg-primary/85 px-1.5 py-0.5 text-[10px] font-semibold text-white tabular-nums`,title:`CLIP semantic-match score`,children:[String(l),`%`]}),c>0&&T(`span`,{className:`absolute right-1 top-1 z-10 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-semibold text-white`,children:String(c)})]}),y(`button`,{type:`button`,onClick:d,className:`min-w-0 px-2 py-1.5 text-left space-y-0.5`,children:[y(`p`,{className:`text-[11px] font-medium text-foreground truncate`,title:e.className,children:[e.className,e.label?y(`span`,{className:`text-foreground-subtle`,children:[` · `,e.label]}):null]}),T(`p`,{className:`text-[10px] text-foreground-subtle truncate`,title:t,children:t}),y(`div`,{className:`flex items-center justify-between gap-2`,children:[T(`span`,{className:`text-[10px] text-foreground-subtle truncate`,children:F(e.timestamp,n)}),u&&T(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:u})]})]})]})}v();var at=[`events-feed`],ot=60,st=[{value:`importance`,label:`Importance`,icon:me},{value:`time`,label:`Recent`,icon:M}];function ct(){let e=C(),[t,n]=w(z),[r,a]=w(new Set),[o,s]=w(new Set),[c,l]=w(0),[d,f]=w(`time`),[p,m]=w(new Set),[h,g]=w(null),[_,v]=w(()=>Date.now());E(()=>{let e=setInterval(()=>v(Date.now()),6e4);return()=>clearInterval(e)},[]);let{since:S,until:O}=b(()=>Se({fromMs:t.fromMs,toMs:t.toMs},_),[t.fromMs,t.toMs,_]);je();let{data:k}=u({}),A=b(()=>(k??[]).filter(e=>e.type===D.Camera),[k]),j=b(()=>A.map(e=>e.id),[A]),M=Te(),N=M.isPending,{rows:P,isLoading:F}=Oe({deviceIds:j,since:S,until:O,minImportance:c>0?c:void 0,classFilter:o.size===1?[...o][0]:void 0}),ne=b(()=>{let e=new Map;for(let t of A??[])e.set(t.id,t.name);return e},[A]),I=e=>ne.get(e)??`Camera #${String(e)}`,R=b(()=>te(P).map(e=>({id:e,name:I(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[P,ne]),B=b(()=>ye(be(P,{cameras:r,classes:o,minImportance:c}),d),[P,r,o,c,d]),V=re(B,ot,b(()=>JSON.stringify([[...r].sort((e,t)=>e-t),[...o].sort(),c,d,S,O]),[r,o,c,d,S,O])),H=()=>{e.invalidateQueries({queryKey:at})},ae=()=>m(new Set);function oe(e){m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function U(){if(p.size===0||!Y)return;let e=xe(P,p),t=[...e.values()].reduce((e,t)=>e+t.length,0);if(t===0||!window.confirm(`Delete ${String(t)} track${t===1?``:`s`} and all their media? This cannot be undone.`))return;let n=[...e];Promise.allSettled(n.map(([e,t])=>M.mutateAsync({deviceId:e,trackIds:t}))).then(e=>{H();let t=[],r=new Set;if(e.forEach((e,i)=>{let a=n[i];if(!a)return;let[o,s]=a;if(e.status===`fulfilled`)for(let e of s)r.add(J(o,e));else t.push(o)}),m(e=>{let t=new Set(e);for(let e of r)t.delete(e);return t}),t.length>0){let e=t.map(e=>I(e)).join(`, `);window.alert(`Failed to delete tracks on: ${e}. They remain selected — retry, or check the server logs.`)}})}let W=B.length!==P.length;return y(`div`,{className:`relative space-y-3`,children:[y(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[T(ee,{onChange:n}),T(L,{cameras:R,selected:r,onChange:a}),T(Ne,{selected:o,onChange:s}),y(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[T(`span`,{children:`Min score`}),T(`input`,{type:`range`,min:0,max:1,step:.05,value:c,onChange:e=>l(Number(e.target.value)),className:`h-1 w-24 cursor-pointer accent-primary`,"aria-label":`Minimum importance`}),T(`span`,{className:`w-6 tabular-nums text-foreground`,children:Math.round(c*100)})]}),T(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:st.map(e=>{let t=e.icon;return y(`button`,{type:`button`,onClick:()=>f(e.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${d===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:[T(t,{className:`h-3.5 w-3.5`}),` `,e.label]},e.value)})}),!F&&T(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:W?`${String(B.length)} of ${String(P.length)} events`:`${String(B.length)} event${B.length===1?``:`s`}`})]}),p.size>0&&y(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-primary/40 bg-primary/8 px-3 py-2`,children:[y(`span`,{className:`text-xs font-medium text-foreground`,children:[p.size,` selected`]}),y(`div`,{className:`ml-auto flex flex-wrap items-center gap-1.5`,children:[T(`span`,{title:Y?void 0:`Track deletion arrives with the next server update`,children:y(i,{variant:`secondary`,onClick:U,disabled:!Y||N,children:[N?T(G,{className:`h-3.5 w-3.5 animate-spin`}):T(le,{className:`h-3.5 w-3.5`}),` `,`Delete`]})}),T(i,{variant:`ghost`,onClick:ae,disabled:N,children:T(ce,{className:`h-3.5 w-3.5`})})]})]}),F&&y(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[T(G,{className:`h-4 w-4 animate-spin`}),` Loading events…`]}),!F&&B.length===0&&T(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No key events in this window.`}),!F&&B.length>0&&y(x,{children:[T(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:V.pageItems.map(e=>T(it,{row:e,cameraName:I(e.deviceId),nowMs:_,selected:p.has(J(e.deviceId,e.trackId)),onToggleSelect:oe,onOpenDetail:g},J(e.deviceId,e.trackId)))}),T(ie,{currentPage:V.page,totalItems:V.totalItems,pageSize:V.pageSize,onPageChange:V.setPage,itemNoun:`events`})]}),h&&T(nt,{row:h,cameraName:I(h.deviceId),deleteAvailable:Y,onClose:()=>g(null),onDeleted:()=>{H(),g(null)}})]})}v();var lt=50,ut=350,dt=[`person`,`vehicle`,`animal`],ft=[{value:.2,label:`Loose`},{value:.25,label:`Balanced`},{value:.3,label:`Strict`}];function pt(e){return{id:e.id,trackId:e.trackId??e.id,deviceId:e.deviceId,timestamp:e.timestamp,className:e.className,label:e.label,importance:e.importance??0,bestEventId:e.mediaKey??e.trackId??e.id,windowMs:void 0}}function mt({onActiveChange:e}){let[t,n]=w(``),[r,i]=w(.2),[a,o]=w(null),[c,l]=w(null),[d,p]=w(null),m=f(t,ut).trim(),h=m.length>0;E(()=>{e(h)},[h,e]);let[g,_]=w(()=>Date.now());E(()=>{let e=setInterval(()=>_(Date.now()),6e4);return()=>clearInterval(e)},[]);let{data:v}=u({}),x=b(()=>(v??[]).filter(e=>e.type===D.Camera),[v]),S=b(()=>{let e=new Map;for(let t of v??[])e.set(t.id,t.name);return e},[v]),C=e=>S.get(e)??`Camera #${String(e)}`,{data:O,isFetching:k,isError:A,error:j}=s({text:m,minScore:r,limit:lt,classFilter:a??void 0,deviceId:c??void 0},{enabled:h}),M=b(()=>[...O??[]].sort((e,t)=>t.score-e.score).map(e=>({...pt(e),score:e.score})),[O]);function N(e){o(t=>t===e?null:e)}return y(`div`,{className:`space-y-3`,children:[y(`div`,{className:`rounded-lg border border-border bg-surface p-3 space-y-3`,children:[y(`div`,{className:`flex flex-wrap items-center gap-2`,children:[y(`div`,{className:`relative min-w-[16rem] flex-1`,children:[T(V,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-foreground-subtle`}),T(`input`,{type:`text`,value:t,onChange:e=>n(e.target.value),placeholder:`Semantic search — describe what you're looking for…`,className:`h-9 w-full rounded-md border border-border bg-background pl-8 pr-8 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary`,"aria-label":`Semantic event search`}),t&&T(`button`,{type:`button`,onClick:()=>n(``),className:`absolute right-2 top-1/2 -translate-y-1/2 rounded p-0.5 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Clear search`,children:T(ce,{className:`h-3.5 w-3.5`})})]}),k&&h&&T(G,{className:`h-4 w-4 shrink-0 animate-spin text-foreground-subtle`})]}),y(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[T(`div`,{className:`flex items-center gap-1`,children:dt.map(e=>T(`button`,{type:`button`,onClick:()=>N(e),className:`rounded-md px-2.5 py-1 text-xs capitalize transition-colors ${a===e?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,children:e},e))}),y(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[T(`span`,{children:`Camera`}),y(`select`,{value:c===null?``:String(c),onChange:e=>l(e.target.value===``?null:Number(e.target.value)),className:`h-7 rounded-md border border-border bg-background px-1.5 text-xs text-foreground focus:border-primary focus:outline-none`,"aria-label":`Filter by camera`,children:[T(`option`,{value:``,children:`All`}),x.map(e=>T(`option`,{value:String(e.id),children:e.name},e.id))]})]}),y(`div`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[T(`span`,{children:`Match`}),T(`div`,{className:`flex items-center gap-1 rounded-md border border-border p-0.5`,children:ft.map(e=>T(`button`,{type:`button`,onClick:()=>i(e.value),className:`rounded px-2 py-1 text-[11px] transition-colors ${r===e.value?`bg-primary/12 text-primary font-medium`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground`}`,title:`Minimum CLIP score ${e.value.toFixed(2)}`,children:e.label},e.value))})]}),h&&!k&&!A&&y(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:[M.length,` match`,M.length===1?``:`es`]})]})]}),h&&y(`div`,{className:`space-y-3`,children:[A&&y(`p`,{className:`py-4 text-xs text-danger`,children:[`Search failed: `,j instanceof Error?j.message:`unknown error`,`. Check that the CLIP embedding step is enabled.`]}),!A&&k&&M.length===0&&y(`div`,{className:`flex items-center gap-2 py-4 text-xs text-foreground-subtle`,children:[T(G,{className:`h-4 w-4 animate-spin`}),` Searching…`]}),!A&&!k&&M.length===0&&y(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:[`No semantic matches for “`,m,`”. Try a looser match threshold or a different phrasing.`]}),!A&&M.length>0&&T(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:M.map(e=>T(it,{row:e,cameraName:C(e.deviceId),nowMs:g,score:e.score,onOpenDetail:p},e.id))})]}),d&&T(nt,{row:d,cameraName:C(d.deviceId),deleteAvailable:Y,onClose:()=>p(null),onDeleted:()=>p(null)})]})}var ht=15e3;function gt(e){let t=j(),n=S({queries:e.map(e=>({queryKey:[`stationary-objects`,e],staleTime:ht,refetchInterval:ht,queryFn:async()=>((await t.trpcClient.zoneAnalytics.getCurrentSnapshot.query({deviceId:e}))?.stationaryObjects??[]).map(t=>({...t,deviceId:e}))}))});return{rows:n.flatMap(e=>e.data??[]).toSorted((e,t)=>t.becameStationaryAt-e.becameStationaryAt),isLoading:n.some(e=>e.isLoading)}}v();function _t(e,t){let n=Math.max(0,Math.round((e-t)/6e4));if(n<1)return`just now`;if(n<60)return`${String(n)}m`;let r=Math.floor(n/60);return`${String(r)}h ${String(n%60)}m`}function vt({row:e,cameraName:t,nowMs:n}){let r=e.keyFrameMediaKey?.startsWith(`track:`)?e.keyFrameMediaKey.split(`:`)[1]:e.keyFrameMediaKey,i=fe(r?`${pe}/${r}`:void 0);return y(`div`,{className:`flex flex-col overflow-hidden rounded-md border border-border bg-surface`,children:[y(`div`,{className:`relative aspect-video overflow-hidden bg-surface-hover`,children:[i.src?T(`img`,{src:i.src,alt:`Parked ${e.className} on ${t}`,className:`h-full w-full object-cover`}):T(`div`,{className:`flex h-full w-full items-center justify-center text-foreground-subtle`,children:T(he,{className:`h-6 w-6`})}),T(`span`,{className:`absolute left-1 top-1 rounded bg-black/60 px-1.5 py-0.5 text-[10px] font-medium capitalize text-white`,children:e.label??e.className})]}),y(`div`,{className:`flex flex-col gap-0.5 p-1.5`,children:[T(`span`,{className:`truncate text-[11px] text-foreground`,children:t}),y(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`parked `,_t(n,e.becameStationaryAt)]})]})]})}function yt(){let[e,t]=w(!1),n=Date.now(),{data:r}=u({}),i=b(()=>(r??[]).filter(e=>e.type===D.Camera),[r]),a=b(()=>i.map(e=>e.id),[i]),o=b(()=>{let e=new Map;for(let t of i)e.set(t.id,t.name);return e},[i]),{rows:s}=gt(a);return s.length===0?null:y(`div`,{className:`rounded-md border border-border bg-surface/40`,children:[y(`button`,{type:`button`,onClick:()=>t(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,children:[T(e?U:se,{className:`h-4 w-4 text-foreground-subtle`}),T(he,{className:`h-4 w-4 text-foreground-subtle`}),T(`span`,{className:`text-sm font-semibold text-foreground`,children:`Stationary`}),T(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[10px] font-medium text-foreground-subtle`,children:s.length}),T(`span`,{className:`ml-2 text-[11px] text-foreground-subtle`,children:`Parked objects — kept out of the event feed`})]}),e&&T(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(9rem,1fr))] gap-2 p-3 pt-0`,children:s.map(e=>T(vt,{row:e,cameraName:o.get(e.deviceId)??`Camera #${String(e.deviceId)}`,nowMs:n},e.id))})]})}v();function bt(){je();let[e,t]=w(!1);return T(de,{icon:K,title:`Events`,subtitle:`Every captured key event across all cameras — trajectory, media, and clips.`,children:y(`section`,{className:`space-y-3`,children:[T(mt,{onActiveChange:t}),!e&&T(yt,{}),!e&&T(ct,{})]})})}export{bt as EventsPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Aa as e,Ca as t,Da as n,Ea as r,La as i,Ma as a,Oa as o,Qa as s,Sa as c,So as l,Ta as u,ba as d,bt as f,c as p,ja as m,ka as h,s as g,va as _,wa as v,xa as y,xt as b,ya as x}from"./src-Bwet06Ih.js";import{Q as S,S as C,W as w,b as T,o as E,q as D,x as O}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as k}from"./circle-check-big-B9HIwiFo.js";import{t as A}from"./copy-BmgVaD29.js";import{t as j}from"./key-round-Cblg8i0e.js";import{t as M}from"./AddonCollectionPage-CXHeV-JA.js";import{t as ee}from"./plus-B0OPxy2A.js";import{L as N,S as P,T as F,W as I,f as L,i as R,r as z,s as B,u as V,w as H}from"./index-RegSp4ae.js";import{t as U}from"./AdminPage-BwmGKnRf.js";import{t as W}from"./AdminTabs-DPHt9Vrr.js";import{t as G}from"./addon-display-names-DvSEQty-.js";var te=I(`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`}]]),ne=I(`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`}]]),re=I(`key`,[[`path`,{d:`m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4`,key:`g0fldk`}],[`path`,{d:`m21 2-9.6 9.6`,key:`1j0ho8`}],[`circle`,{cx:`7.5`,cy:`15.5`,r:`5.5`,key:`yqb3hr`}]]),K=I(`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`}]]),ie=I(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]);S();function ae({userId:e,username:t,onClose:n}){let r=E(),a=i(),o=c({userId:e}),s=o.data,u=()=>r.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),d=y({onSuccess:()=>{u(),n()}}),f=o.isLoading?`loading`:s?.enabled?`enrolled`:`not_enrolled`;return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4`,children:C(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden`,children:[C(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-border`,children:[C(`div`,{className:`flex items-center gap-2`,children:[O(V,{className:`h-4 w-4 text-primary`}),C(`div`,{children:[O(`div`,{className:`text-sm font-medium text-foreground`,children:`Two-factor authentication`}),C(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,O(`span`,{className:`font-mono`,children:t})]})]})]}),O(`button`,{onClick:n,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:O(R,{className:`h-4 w-4`})})]}),C(`div`,{className:`p-4 space-y-4`,children:[f===`loading`&&C(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[O(P,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),f===`not_enrolled`&&C(`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:[O(H,{className:`h-4 w-4 mt-0.5 shrink-0`}),C(`div`,{children:[O(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),O(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),f===`enrolled`&&s&&C(T,{children:[C(`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:[O(k,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),C(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[O(`div`,{className:`font-medium`,children:`2FA is active`}),C(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,s.confirmedAt?new Date(s.confirmedAt).toLocaleString():`—`]})]})]}),O(`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.`}),C(`div`,{className:`flex justify-end gap-2`,children:[O(l,{onClick:n,variant:`secondary`,children:`Close`}),C(`button`,{onClick:async()=>{await a({title:`Remove 2FA`,message:`Remove two-factor authentication for "${t}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,confirmLabel:`Remove`,variant:`danger`})&&d.mutate({userId:e})},disabled:d.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:[d.isPending?O(P,{className:`h-3 w-3 animate-spin`}):O(R,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function oe(){let e=E(),{user:t}=z(),[o,c]=D(!1),[l,u]=D(``),[f,p]=D(``),[h,g]=D(!1),[_,v]=D(null),{data:y,isLoading:b,isError:S}=r(),w=i(),T=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),k=x({onSuccess:()=>{T(),c(!1),u(``),p(``),g(!1),v(null)},onError:e=>{v(e instanceof Error?e.message:`Failed to create user`)}}),A=d({onSuccess:T}),j=a({onSuccess:T}),M=n({onSuccess:T}),N=m({onSuccess:()=>{T(),I(null)}}),[F,I]=D(null),[H,W]=D(null),G=y??[];async function te(e){await w({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`})&&A.mutate({id:e.id})}async function ne(e){let t=window.prompt(`New password for "${e.username}":`);if(t){if(t.length<8){window.alert(`Password must be at least 8 characters.`);return}await w({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&M.mutate({id:e.id,newPassword:t})}}function K(e,t){t!==e.isAdmin&&j.mutate({id:e.id,isAdmin:t})}function ie(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}return C(U,{children:[O(`div`,{className:`flex items-center justify-end`,children:C(`button`,{onClick:()=>c(!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:[O(ee,{className:`h-3.5 w-3.5`}),`Create User`]})}),o&&C(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[C(`div`,{className:`flex items-center justify-between`,children:[O(`span`,{className:`text-xs font-medium text-foreground`,children:`New User`}),O(`button`,{onClick:()=>c(!1),className:`text-foreground-subtle hover:text-foreground`,children:O(R,{className:`h-4 w-4`})})]}),C(`div`,{className:`grid grid-cols-3 gap-3`,children:[C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),O(`input`,{type:`text`,value:l,onChange:e=>u(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`})]}),C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Password`}),O(`input`,{type:`password`,value:f,onChange:e=>p(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`})]}),C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),C(`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:[O(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked),className:`rounded border-border focus:ring-primary`}),O(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),_&&O(`p`,{className:`text-[10px] text-danger`,children:_}),C(`div`,{className:`flex justify-end gap-2`,children:[O(`button`,{onClick:()=>c(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),O(`button`,{onClick:()=>k.mutate({username:l,password:f,isAdmin:h}),disabled:k.isPending||!l||!f,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:k.isPending?`Creating...`:`Create`})]})]}),b&&O(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),S&&O(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!b&&!S&&G.length===0&&O(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let e=e=>A.isPending&&A.variables?.id===e.id||j.isPending&&j.variables?.id===e.id||M.isPending&&M.variables?.id===e.id;return O(s,{columns:[{key:`username`,header:`Username`,render:e=>e.username},{key:`isAdmin`,header:`Admin`,render:t=>C(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[O(`input`,{type:`checkbox`,checked:t.isAdmin,onChange:e=>K(t,e.target.checked),disabled:e(t),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),O(`span`,{className:t.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:t.isAdmin?`Admin`:`Regular`})]})},{key:`scopes`,header:`Scopes`,render:e=>{if(e.isAdmin)return O(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`unscoped`});let t=e.scopes??[];return C(`button`,{onClick:()=>I(e),className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground`,title:`Edit scope grants`,children:[O(L,{className:`h-3 w-3`}),t.length===0?`no access`:`${t.length} grant${t.length===1?``:`s`}`]})}},{key:`createdAt`,header:`Created`,render:e=>O(`span`,{className:`text-foreground-subtle`,children:ie(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:n=>{let r=e(n);return C(`div`,{className:`flex items-center justify-end gap-1`,children:[n.id!==t?.id&&n.totpEnabled&&C(`button`,{onClick:()=>W(n),disabled:r,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:[O(V,{className:`h-3 w-3`}),`Remove 2FA`]}),C(`button`,{onClick:()=>ne(n),disabled:r,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:[O(re,{className:`h-3 w-3`}),`Reset password`]}),C(`button`,{onClick:()=>te(n),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:`Delete user`,children:[r?O(P,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:G,rowKey:e=>e.id,minWidthPx:560})})(),H&&O(ae,{userId:H.id,username:H.username,onClose:()=>W(null)}),F&&O(se,{user:F,onClose:()=>I(null),onSubmit:e=>N.mutate({userId:F.id,scopes:e}),submitting:N.isPending})]})}function se(e){let{user:t}=z(),n=t?.isAdmin===!0;return O(ce,{...e,callerScopes:n?null:t?.scopes??[]})}function ce({user:e,onClose:t,onSubmit:n,submitting:r,callerScopes:i}){let[a,o]=D(w(()=>(e.scopes??[]).map(e=>({...e,access:[...e.access]})),[e.scopes])),s=p(a);return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4`,children:C(`div`,{className:`w-full max-w-2xl rounded-lg border border-border bg-surface shadow-xl`,children:[C(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-3`,children:[C(`div`,{children:[C(`div`,{className:`text-sm font-semibold text-foreground`,children:[`Edit scopes — `,e.username]}),O(`div`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?`Admin users bypass the scope check; this list is ignored.`:`Pick which capabilities this user can call, and which access flavours within each.`})]}),O(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:O(R,{className:`h-4 w-4`})})]}),C(`div`,{className:`px-4 py-4`,children:[O(g,{value:a,onChange:o,clampToParent:i,emptyHint:C(T,{children:[`No scopes granted.`,` `,O(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until a scope is added.`]})}),s&&O(`p`,{className:`mt-2 text-[10px] text-danger`,children:s})]}),C(`div`,{className:`flex items-center justify-end gap-2 border-t border-border px-4 py-3`,children:[O(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),O(`button`,{onClick:()=>n(a),disabled:r||s!==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:r?O(P,{className:`h-3 w-3 animate-spin`}):`Save scopes`})]})]})})}S();var le=`bg-primary/10 text-primary`,ue=`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 de(e){return e?e===`*`?`*`:e.join(`, `):``}function fe(){let n=E(),a=i(),{data:s,isLoading:c}=t(),{data:l}=r(),u=w(()=>s??[],[s]),d=w(()=>l??[],[l]),f=()=>n.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),p=()=>n.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[m,h]=D(!1),[g,v]=D(null),y=o({onSuccess:f}),b=_({onSuccess:({token:e,record:t})=>{p(),h(!1),v({token:e,label:t.name})}}),x=e({onSuccess:p}),S=async(e,t)=>{await a({title:`Revoke "${t}"?`,message:`Any client using this token will lose access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&y.mutate({id:e})},T=async(e,t)=>{await a({title:`Revoke "${t}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&x.mutate({id:e})};return C(U,{children:[C(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[O(`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.`}),C(`button`,{onClick:()=>h(!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:d.length===0,title:d.length===0?`Create a user first`:`Issue a scoped token`,children:[O(L,{className:`h-3.5 w-3.5`}),`New token`]})]}),C(J,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[d.length===0&&O(me,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),d.map(e=>O(ge,{userId:e.id,username:e.username,onRevoke:(e,t)=>{T(e,t)},revokePending:x.isPending,revokeId:x.variables?.id},e.id))]}),u.length>0&&O(J,{title:`Legacy API keys`,subtitle:`${u.length} pre-existing — revoke only`,children:O(he,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:u.map(e=>{let t=!!e.isAdmin,n=y.isPending&&y.variables?.id===e.id;return C(`tr`,{className:`hover:bg-primary/5`,children:[O(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.label}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:O(`span`,{className:`inline-block rounded px-2 py-0.5 text-[10px] uppercase tracking-wide ${t?le:ue}`,children:t?`admin`:`regular`})}),C(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border text-foreground-subtle`,children:de(e.allowedProviders)||`all`}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:q(e.createdAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:q(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:C(`button`,{onClick:()=>{S(e.id,e.label)},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`,title:`Revoke`,children:[n?O(P,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),c&&O(pe,{}),m&&O(_e,{users:d.map(e=>({id:e.id,username:e.username})),onClose:()=>h(!1),onSubmit:e=>b.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:b.isPending}),g&&O(ve,{token:g.token,label:g.label,onClose:()=>v(null)})]})}function J({title:e,subtitle:t,children:n}){return C(`div`,{className:`space-y-2`,children:[C(`div`,{className:`flex items-baseline justify-between`,children:[O(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),t&&O(`span`,{className:`text-[10px] text-foreground-subtle`,children:t})]}),n]})}function pe(){return O(`div`,{className:`space-y-2`,children:[1,2].map(e=>O(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function me({text:e}){return O(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function he({headers:e,rows:t}){return O(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:C(`table`,{className:`w-full text-xs min-w-[640px]`,children:[O(`thead`,{children:O(`tr`,{children:e.map((t,n)=>O(`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))})}),O(`tbody`,{children:t})]})})}function ge({userId:e,username:t,onRevoke:n,revokePending:r,revokeId:i}){let{data:a,isLoading:o}=u({userId:e}),s=a??[];return o||s.length===0?null:C(`div`,{className:`space-y-1.5`,children:[O(`div`,{className:`text-[11px] font-medium text-foreground`,children:t}),O(he,{headers:[`Name`,`Prefix`,`Scopes`,`Expires`,`Last used`,`Created`,``],rows:s.map(e=>{let t=r&&i===e.id;return C(`tr`,{className:`hover:bg-primary/5`,children:[O(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.name}),C(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:O(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>C(`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`?`[${e.targets.join(`,`)}]`:e.target]},t))})}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:q(e.expiresAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:q(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:q(e.createdAt)}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:C(`button`,{onClick:()=>n(e.id,e.name),disabled:t,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[t?O(P,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function _e({users:e,onClose:t,onSubmit:n,submitting:r}){let{user:i}=z(),a=i?.isAdmin===!0?null:i?.scopes??[],[o,s]=D(e[0]?.id??``),[c,l]=D(``),[u,d]=D([{type:`capability`,target:``,access:[`view`,`create`]}]),[f,m]=D(``),h=p(u),_=o!==``&&c.trim().length>0&&u.length>0&&h===null&&!r;return C(ye,{title:`Create scoped token`,onClose:t,children:[C(`div`,{className:`space-y-3`,children:[O(Y,{label:`On behalf of user`,children:O(`select`,{value:o,onChange:e=>s(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=>O(`option`,{value:e.id,children:e.username},e.id))})}),O(Y,{label:`Name`,children:O(`input`,{value:c,onChange:e=>l(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`})}),C(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:[O(g,{value:u,onChange:d,clampToParent:a}),h&&O(`p`,{className:`mt-1 text-[10px] text-danger`,children:h})]}),O(Y,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:O(`input`,{type:`number`,min:1,value:f,onChange:e=>m(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`})})]}),C(be,{children:[O(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),C(`button`,{onClick:()=>{let e=parseInt(f,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;n({userId:o,name:c.trim(),scopes:u,expiresAt:t})},disabled:!_,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:[r?O(P,{className:`h-3.5 w-3.5 animate-spin`}):O(L,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function ve({token:e,label:t,onClose:n}){let[r,i]=D(!1),a=async()=>{try{await navigator.clipboard.writeText(e),i(!0)}catch{}};return C(ye,{title:`Token: ${t}`,onClose:n,children:[C(`div`,{className:`space-y-3`,children:[O(`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.`}),O(`div`,{className:`rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all`,children:e})]}),C(be,{children:[C(`button`,{onClick:()=>{a()},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:[r?O(N,{className:`h-3.5 w-3.5 text-primary`}):O(A,{className:`h-3.5 w-3.5`}),r?`Copied`:`Copy`]}),O(`button`,{onClick:n,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Done`})]})]})}function ye({title:e,onClose:t,children:n}){return O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:C(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[C(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[O(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),O(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:O(R,{className:`h-4 w-4`})})]}),O(`div`,{className:`p-4`,children:n})]})})}function be({children:e}){return O(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:e})}function Y({label:e,hint:t,children:n}){return C(`div`,{className:`space-y-1`,children:[O(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:e}),n,t&&O(`p`,{className:`text-[10px] text-foreground-subtle`,children:t})]})}S();function X(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function xe(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 Se(){return O(`div`,{className:`space-y-2`,children:[1,2].map(e=>O(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function Ce({text:e}){return O(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function we({headers:e,rows:t}){return O(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:C(`table`,{className:`w-full text-xs min-w-[640px]`,children:[O(`thead`,{children:O(`tr`,{children:e.map((t,n)=>O(`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))})}),O(`tbody`,{children:t})]})})}function Te(){let e=E(),t=i(),{data:n,isLoading:r}=v(),a=w(()=>n??[],[n]),o=h({onSuccess:()=>e.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),s=async(e,n)=>{await t({title:`Revoke "${n}" session?`,message:`This integration will lose access immediately on its next API call. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&o.mutate({id:e})};return C(U,{icon:K,title:`Linked Sessions`,subtitle:`External integrations (Alexa, …) linked to this hub via OAuth. Revoke a session to immediately invalidate that integration's access.`,children:[r&&O(Se,{}),!r&&a.length===0&&O(Ce,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!r&&a.length>0&&O(we,{headers:[`Integration`,`User`,`Scopes`,`Created`,`Last used`,`Status`,``],rows:a.map(e=>{let t=e.revokedAt!==null,n=(o.isPending?o.variables?.id:void 0)===e.id;return C(`tr`,{className:`hover:bg-primary/5`,children:[O(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.integrationId}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:e.username}),O(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:O(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>O(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:xe(e)},t))})}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 border-b border-border`,children:t?C(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-2 py-0.5 text-[10px] text-foreground-subtle`,children:[`Revoked `,X(e.revokedAt)]}):O(`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`})}),O(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:!t&&C(`button`,{onClick:()=>{s(e.id,e.integrationId)},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`,title:`Revoke`,children:[n?O(P,{className:`h-3 w-3 animate-spin`}):O(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}S();var Z=3e4,Q=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],$={title:`Authentication providers`,subtitle:`Every registered authentication surface in one list: login providers (local password, OIDC, SAML, magic-link) and second-factor providers (passkeys / WebAuthn — configure the relying-party RP ID + origin inline; users enroll from My access → Passkeys). Multiple providers run in parallel — enable/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 Ee(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:ne,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:F,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`First-time sign-ins are auto-provisioned with the configured Default Role.`],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.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:F,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:V,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)||e.startsWith(`auth-magic-link`)?{headline:`TOTP / magic-link — second factor or passwordless sign-in.`,icon:V,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:L,bullets:[`Generic authentication provider. No additional hints registered.`]}}function De(){let e=b({capName:Q[0].capName},{refetchInterval:Z}),t=b({capName:Q[1].capName},{refetchInterval:Z}),n=f(void 0,{refetchInterval:Z}),r=w(()=>G(n.data??[]),[n.data]),i=w(()=>{let n=[],i=[e.data??[],t.data??[]];for(let[e,t]of Q.entries())for(let a of i[e]??[])n.push({addonId:a.addonId,displayName:r.get(a.addonId)??a.addonId,isActive:a.isActive,capName:t.capName,stageBadge:t.stageBadge});return n},[e.data,t.data,r]);return O(M,{title:$.title,subtitle:$.subtitle,pageIcon:L,itemIcon:L,capability:Q[0].capName,installButtonLabel:$.installLabel,items:i,isLoading:e.isLoading||t.isLoading,emptyTitle:$.emptyTitle,emptyDescription:$.emptyDescription,renderStatusBadges:e=>e.stageBadge===null?null:O(`span`,{className:`inline-flex items-center rounded-full border border-primary/30 bg-primary/10 px-2 py-0.5 text-[10px] font-medium text-primary`,children:e.stageBadge}),renderExpandedPanel:e=>O(Oe,{addonId:e.addonId})})}function Oe({addonId:e}){let t=Ee(e),n=t.icon;return C(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[C(`div`,{className:`flex items-start gap-2.5`,children:[O(n,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),O(`div`,{className:`text-xs text-foreground font-medium`,children:t.headline})]}),O(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:t.bullets.map((e,t)=>O(`li`,{children:e},t))}),t.setupSteps&&t.setupSteps.length>0&&C(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[C(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[O(te,{className:`h-3 w-3`}),`Setup steps`]}),O(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:t.setupSteps.map((e,t)=>O(`li`,{children:e},t))})]}),e===`local-auth`&&C(`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:[O(H,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),C(`span`,{children:[`TOTP / 2FA is self-service: each user enrols from their own profile page —`,` `,O(`a`,{href:`/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`,` `,O(`a`,{href:`/system/users`,className:`underline text-primary`,children:`Users`}),` `,`page via Actions → “Remove 2FA”.`]})]})]})}function ke(){return O(`div`,{className:`flex flex-col p-4`,children:O(W,{tabs:[{id:`users`,label:`Users`,icon:ie,content:O(oe,{})},{id:`api-keys`,label:`Tokens`,icon:j,content:O(fe,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:K,content:O(Te,{})},{id:`authentication`,label:`Authentication`,icon:L,content:O(De,{})}]})})}export{ke as IdentityPage};
|