@camstack/addon-admin-ui 1.2.6 → 1.2.8
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-EQfBerh6.js → AddLocationWizard-DZT8c1Gh.js} +1 -1
- package/dist/assets/{AddonCollectionPage-DULW5cZ3.js → AddonCollectionPage-CnbUqGtk.js} +1 -1
- package/dist/assets/{Addons-B3DP5tRM.js → Addons-BoHKHT6D.js} +1 -1
- package/dist/assets/{AdminTabs-B4tsypGK.js → AdminTabs-DoJIdigB.js} +1 -1
- package/dist/assets/{AiProfiles-BCyCuA57.js → AiProfiles-B5iQGj0g.js} +1 -1
- package/dist/assets/{BrokerForm-De3Iwxlh.js → BrokerForm-JP0u8lMv.js} +1 -1
- package/dist/assets/{Capabilities-Dnw_Fl5A.js → Capabilities-D6S3xNBX.js} +1 -1
- package/dist/assets/{CapabilityBadges-BG2fH0DU.js → CapabilityBadges-DLAfx4tg.js} +1 -1
- package/dist/assets/Cluster-Br9H32NH.js +1 -0
- package/dist/assets/{ClusterRecordingTab-B3ux__O1.js → ClusterRecordingTab-CEo7_iKE.js} +1 -1
- package/dist/assets/{Dashboard-BBsLQGfW.js → Dashboard-B8lmGL4Z.js} +1 -1
- package/dist/assets/{Data-DgR-nCIw.js → Data-DR7Vuym7.js} +1 -1
- package/dist/assets/{DetectionIntelligence-CA9CerKH.js → DetectionIntelligence-CRF-M2IN.js} +1 -1
- package/dist/assets/{DeviceDetail-BFkCUHjM.js → DeviceDetail-D6VFBen5.js} +2 -2
- package/dist/assets/{Devices-2sOMm4Z3.js → Devices-CZ2wQtyI.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-myZ504-w.js → EmbedPlayerPage-lT7iR0O_.js} +1 -1
- package/dist/assets/Events-BQKzjNhF.js +1 -0
- package/dist/assets/{FormBuilder-RfZE3uEJ.js → FormBuilder-BxN8f0nT.js} +1 -1
- package/dist/assets/Identity-Cb6ECkDX.js +1 -0
- package/dist/assets/{IntegrationDetail-eyBgthFS.js → IntegrationDetail-CpI_ICc1.js} +1 -1
- package/dist/assets/{Integrations-OooxdXTt.js → Integrations-D9uRl2ae.js} +1 -1
- package/dist/assets/{Integrations-COMfE3Fi.js → Integrations-VyVneDyb.js} +1 -1
- package/dist/assets/{Logs-DmBxt8yx.js → Logs-wn4_EjbH.js} +1 -1
- package/dist/assets/{MotionZonesSettings-D6KN4zvp.js → MotionZonesSettings-WsP8vtl5.js} +1 -1
- package/dist/assets/{MyAccess-CSLqgoOR.js → MyAccess-BYwIrleo.js} +1 -1
- package/dist/assets/Network-BvWfcFc3.js +1 -0
- package/dist/assets/{NodeAddonsSettingsPanel-BFFloAuk.js → NodeAddonsSettingsPanel-COOdNAE-.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-CHEAdiG1.js → NodeInferenceDevices-CKFylLYO.js} +1 -1
- package/dist/assets/Notifications-CpjTFB_4.js +1 -0
- package/dist/assets/Pipeline-L18VOJ84.js +1 -0
- package/dist/assets/{Plates-CblU2DMo.js → Plates-CsufxUMt.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-CixY6Cwe.js → PrivacyMaskSettings-CEP-TRt9.js} +1 -1
- package/dist/assets/{ProviderIcon-J2-hlNmu.js → ProviderIcon-BUhDaDzj.js} +1 -1
- package/dist/assets/{Recordings-fPuPc-OU.js → Recordings-BUYsGeTn.js} +1 -1
- package/dist/assets/{ScanNetworkModal-BUfKHATN.js → ScanNetworkModal-CZI_Y2cA.js} +1 -1
- package/dist/assets/{Settings-4ZY027uK.js → Settings-DFWv-6mZ.js} +1 -1
- package/dist/assets/{Showroom-D5piXffc.js → Showroom-C-zwer-u.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BfUxp5nc.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-B6IsqzCN.js} +1 -1
- package/dist/assets/{build-cluster-graph-BH4yKfdg.js → build-cluster-graph-C2qQbNkr.js} +1 -1
- package/dist/assets/circle-check-big-sPqnrKad.js +1 -0
- package/dist/assets/clock-B96wFCLt.js +1 -0
- package/dist/assets/{copy-DmdM3wEU.js → copy-D5oufG5Q.js} +1 -1
- package/dist/assets/{debounced-invalidate-D__X_AAz.js → debounced-invalidate-CRCuY4xi.js} +1 -1
- package/dist/assets/{dist-36zhpE3X.js → dist-6bufrn_9.js} +1 -1
- package/dist/assets/dist-D5Idz-si.js +7 -0
- package/dist/assets/{download-BxlCQ1_R.js → download-Dfq_dNdv.js} +1 -1
- package/dist/assets/{face-bbox-DUL58Rsf.js → face-bbox-B8GTLKhX.js} +1 -1
- package/dist/assets/history-CGNeCFev.js +1 -0
- package/dist/assets/{hostInit-Qpz1K2M9.js → hostInit-6V2rStu6.js} +1 -1
- package/dist/assets/index-BIxHon5T.js +4 -0
- package/dist/assets/index-BTiaHVM4.css +2 -0
- package/dist/assets/{key-round-C0B7hV3u.js → key-round-BfkBDb0w.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-bbcce2df.js → mf-entry-bootstrap-0-6c20c631.js} +2 -2
- package/dist/assets/{pencil-CkuaFJis.js → pencil-DRb48wcw.js} +1 -1
- package/dist/assets/{player-overlays-BUEqEqaL.js → player-overlays-BlOdAA3b.js} +1 -1
- package/dist/assets/plus-Ecpq7H2e.js +1 -0
- package/dist/assets/{radio-CT33fKey.js → radio-Dra-qtSX.js} +1 -1
- package/dist/assets/{refresh-cw-DZAB0JuF.js → refresh-cw-DWkaxiHf.js} +1 -1
- package/dist/assets/remoteEntry-DzvkbuOH.js +1 -0
- package/dist/assets/{rotate-ccw-BsVOOlvm.js → rotate-ccw-ZwrMVXrr.js} +1 -1
- package/dist/assets/rotate-cw-DFCIBZWX.js +1 -0
- package/dist/assets/search-DKK_bhK4.js +1 -0
- package/dist/assets/{send-C9E6gIVU.js → send-Bx-Qr3_Q.js} +1 -1
- package/dist/assets/{server-BGfq1DMy.js → server-Cso-UurU.js} +1 -1
- package/dist/assets/square-CEkhTs0-.js +1 -0
- package/dist/assets/{square-check-big-C_5pAcZk.js → square-check-big-CH9QT5C_.js} +1 -1
- package/dist/assets/src-GxiMH1Sc.js +7 -0
- package/dist/assets/{src-CBUFBhQs.js → src-Wny3-FFU.js} +10 -10
- package/dist/assets/{upload-BnZt396k.js → upload-BNtucejS.js} +1 -1
- package/dist/assets/{useEventInvalidation-B1H1s0pw.js → useEventInvalidation-CPx5I8W4.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-pkB5RcG9.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-B1_rU1SX.js} +2 -2
- package/dist/assets/{wifi-B_qoHnYl.js → wifi-CwFWxUko.js} +1 -1
- package/dist/assets/{zap-RpM6rAnv.js → zap-By2kL6s3.js} +1 -1
- package/dist/index.html +6 -6
- package/dist/server/addon.js +1385 -890
- package/package.json +1 -1
- package/dist/assets/Cluster-BSSc7Zsu.js +0 -1
- package/dist/assets/Events-R-IvRKr1.js +0 -1
- package/dist/assets/Identity-HEVxedLA.js +0 -1
- package/dist/assets/Network-Zoyc7mWr.js +0 -1
- package/dist/assets/NotificationTargets-vr9QgP0A.js +0 -1
- package/dist/assets/Pipeline-CdJSmNto.js +0 -1
- package/dist/assets/circle-check-big-C8-7HmH_.js +0 -1
- package/dist/assets/clock-PeR4eBHx.js +0 -1
- package/dist/assets/dist-CdjHNRwY.js +0 -7
- package/dist/assets/index-C-ZEPJCU.css +0 -2
- package/dist/assets/index-DdNXL04K.js +0 -4
- package/dist/assets/plus-DXtZevee.js +0 -1
- package/dist/assets/remoteEntry-Dvr0F_Y-.js +0 -1
- package/dist/assets/rotate-cw-vnfGyppg.js +0 -1
- package/dist/assets/search-DW0Hs-NC.js +0 -1
- package/dist/assets/square-BELgWOxZ.js +0 -1
- package/dist/assets/src-DNEnYGfh.js +0 -7
package/package.json
CHANGED
|
@@ -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-CBUFBhQs.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-BUEqEqaL.js";import{t as ee}from"./pencil-CkuaFJis.js";import{t as te}from"./radio-CT33fKey.js";import{t as F}from"./refresh-cw-DZAB0JuF.js";import{t as I}from"./rotate-cw-vnfGyppg.js";import{t as L}from"./server-BGfq1DMy.js";import{t as R}from"./upload-BnZt396k.js";import{B as ne,I as re,L as ie,P as ae,S as z,W as B,i as oe,j as V,m as H,o as U,s as W,t as G}from"./index-DdNXL04K.js";import{n as K,t as q}from"./build-cluster-graph-BH4yKfdg.js";import{t as J}from"./format-size-CO9d3C3-.js";import{t as se}from"./NodeAddonsSettingsPanel-BFFloAuk.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`}]]),ce=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`}]]),le=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`}]]),ue=B(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),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(R,{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(I,{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(W,{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?re:ae,{className:`h-3 w-3 text-muted-foreground shrink-0`}),y?M(L,{className:`h-3.5 w-3.5 text-primary shrink-0`}):M(ne,{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(I,{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(H,{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(I,{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(F,{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(U,{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(W,{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(se,{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(ie,{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(oe,{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(ee,{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}=G(),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(F,{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(ue,{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(I,{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(le,{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(V,{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(W,{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}=G(),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(()=>q(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`,ce)]})]})]}),f?M(`div`,{className:`flex items-center justify-center flex-1 text-muted-foreground`,children:`Loading cluster topology...`}):u===`graph`?M(K,{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 +0,0 @@
|
|
|
1
|
-
import{B as e,Gr as t,Jr as n,Na as r,Wa as i,Wr as a,Zr as o,do as s,fo as c,jn as l,jr as u,q as d,qr as f,xo as p,xt as m,z as h}from"./src-CBUFBhQs.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-DNEnYGfh.js";import{p as j}from"./player-overlays-BUEqEqaL.js";import{t as M}from"./clock-PeR4eBHx.js";import{t as N}from"./copy-DmdM3wEU.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 ie,p as L,r as ae,s as R,t as z}from"./debounced-invalidate-D__X_AAz.js";import{t as B}from"./search-DW0Hs-NC.js";import{t as V}from"./square-check-big-C_5pAcZk.js";import{t as oe}from"./square-BELgWOxZ.js";import{E as se,I as H,L as U,P as ce,S as W,U as G,W as K,i as le,s as ue,t as de}from"./index-DdNXL04K.js";import{t as fe}from"./AdminPage-BwmGKnRf.js";import{r as pe,t as q}from"./authed-media-XfBD4Ma-.js";var me=K(`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=K(`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=K(`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 a==`function`,Ce=`Track deletion arrives with the next server update`;function we(){return{mutateAsync:async()=>{throw Error(`deleteTracks unavailable`)},isPending:!1}}var Te=Y?a: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||=z({delayMs:Ae,invalidate:()=>{t.current.invalidateQueries({queryKey:ke})}}),E(()=>()=>n.current?.cancel(),[]),i(O.PipelineAnalyticsDetectionEvent,()=>{n.current?.trigger()}),i(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}=de(),[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(H,{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(B,{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?H:ce,{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}${q}/${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?U: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}=u({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:i,deleteAvailable:a,onClose:o,onDeleted:l}){let u=j(),d=Te(),m=e!==null,h=e?.deviceId??0,_=e?.trackId??``,v=e?.bestEventId??``,S=e?.timestamp??0,C=e?.windowMs??0,{data:D}=f({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 ie=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]),ae=pe(ie?`${q}/${encodeURIComponent(ie.key)}`:void 0),R=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]),z=b(()=>R.find(e=>Qe.has(e.kind))??null,[R]),B=et(z?`data:image/jpeg;base64,${z.base64}`:null),V=b(()=>Le(D?.positions??[],B,{snapshots:(D?.snapshots??[]).map(e=>({x:e.position.x,y:e.position.y,mediaKey:e.mediaKey}))}),[D?.positions,D?.snapshots,B]),oe=g(e=>{let t=R.find(t=>t.key===e);t&&N(t)},[R]);if(e===null)return null;let H=M?`data:image/jpeg;base64,${M.base64}`:ae.src,U=M?.kind??ie?.kind,ce=U!==void 0&&$e.has(U)&&B!==null&&(D?.positions.length??0)>=2,G=A&&A.length>0?A[0]:null,K=()=>{G&&(te(!0),(async()=>{try{let t=await u.trpcClient.videoclips.getClipPlayback.query({deviceId:e.deviceId,clipId:G.id});window.open(t.playbackUrl,`_blank`,`noopener`)}catch{window.alert(`Could not resolve clip playback. Check the server logs.`)}finally{te(!1)}})())},de=()=>{!a||d.isPending||window.confirm(`Delete this track and all its media? This cannot be undone.`)&&(async()=>{try{await d.mutateAsync({deviceId:e.deviceId,trackIds:[e.trackId]}),l()}catch{window.alert(`Failed to delete this track. Check the server logs.`)}})()},fe=Math.round(e.importance*100),me=D?.importanceReason?`${String(fe)}% · ${D.importanceReason}`:`${String(fe)}%`,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=L(D?D.firstSeen:S),ye=D?L(D.lastSeen):`—`;return T(s,{open:!0,onOpenChange:e=>!e&&o(),children:y(c,{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:i})]}),T(`button`,{type:`button`,onClick:o,className:`rounded p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":`Close`,children:T(le,{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:[H?T(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:T(ne,{src:H,alt:`Key frame from ${i}`,fit:`natural`,className:`w-full`,overlay:ce?T(tt,{overlay:V,onPickSnapshot:oe}):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:ae.failed?y(x,{children:[T(I,{className:`h-8 w-8 opacity-60`}),T(`span`,{className:`text-[11px]`,children:`Key-frame media unavailable`})]}):T(W,{className:`h-6 w-6 animate-spin opacity-70`})}),R.length>0&&T(`div`,{className:`-mx-1 flex gap-2 overflow-x-auto px-1 pb-1`,children:R.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} · ${L(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:L(e.timestamp),children:P(e.timestamp)})]}),T(Ge,{localUrl:r,publicUrl:i})]},e.key)})}),re,G&&y(p,{variant:`secondary`,onClick:K,disabled:ee,children:[ee?T(W,{className:`h-3.5 w-3.5 animate-spin`}):T(se,{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:i}),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:a?void 0:Ce,children:y(p,{variant:`secondary`,onClick:de,disabled:!a||d.isPending,children:[d.isPending?T(W,{className:`h-3.5 w-3.5 animate-spin`}):T(ue,{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=pe(e.bestEventId?`${q}/${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(V,{className:`h-4 w-4 text-primary`}):T(oe,{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(R),[r,i]=w(new Set),[a,o]=w(new Set),[s,c]=w(0),[u,d]=w(`time`),[f,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}=l({}),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:s>0?s:void 0,classFilter:a.size===1?[...a][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)}`,L=b(()=>te(P).map(e=>({id:e,name:I(e)})).sort((e,t)=>e.name.localeCompare(t.name)),[P,ne]),z=b(()=>ye(be(P,{cameras:r,classes:a,minImportance:s}),u),[P,r,a,s,u]),B=re(z,ot,b(()=>JSON.stringify([[...r].sort((e,t)=>e-t),[...a].sort(),s,u,S,O]),[r,a,s,u,S,O])),V=()=>{e.invalidateQueries({queryKey:at})},oe=()=>m(new Set);function se(e){m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function H(){if(f.size===0||!Y)return;let e=xe(P,f),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=>{V();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 U=z.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(ie,{cameras:L,selected:r,onChange:i}),T(Ne,{selected:a,onChange:o}),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:s,onChange:e=>c(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(s*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:()=>d(e.value),className:`flex items-center gap-1 rounded px-2 py-1 text-[11px] transition-colors ${u===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:U?`${String(z.length)} of ${String(P.length)} events`:`${String(z.length)} event${z.length===1?``:`s`}`})]}),f.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:[f.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(p,{variant:`secondary`,onClick:H,disabled:!Y||N,children:[N?T(W,{className:`h-3.5 w-3.5 animate-spin`}):T(ue,{className:`h-3.5 w-3.5`}),` `,`Delete`]})}),T(p,{variant:`ghost`,onClick:oe,disabled:N,children:T(le,{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(W,{className:`h-4 w-4 animate-spin`}),` Loading events…`]}),!F&&z.length===0&&T(`p`,{className:`py-4 text-xs text-foreground-subtle`,children:`No key events in this window.`}),!F&&z.length>0&&y(x,{children:[T(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(11rem,1fr))] gap-2`,children:B.pageItems.map(e=>T(it,{row:e,cameraName:I(e.deviceId),nowMs:_,selected:f.has(J(e.deviceId,e.trackId)),onToggleSelect:se,onOpenDetail:g},J(e.deviceId,e.trackId)))}),T(ae,{currentPage:B.page,totalItems:B.totalItems,pageSize:B.pageSize,onPageChange:B.setPage,itemNoun:`events`})]}),h&&T(nt,{row:h,cameraName:I(h.deviceId),deleteAvailable:Y,onClose:()=>g(null),onDeleted:()=>{V(),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,s]=w(null),[c,u]=w(null),[f,p]=w(null),m=d(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}=l({}),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}=o({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){s(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(B,{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(le,{className:`h-3.5 w-3.5`})})]}),k&&h&&T(W,{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=>u(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(W,{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))})]}),f&&T(nt,{row:f,cameraName:C(f.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=pe(r?`${q}/${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}=l({}),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?H:ce,{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(fe,{icon:G,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,Ta as l,ba as u,bt as d,c as f,ja as p,ka as m,s as h,va as g,wa as _,xa as v,xo as y,xt as b,ya as x}from"./src-CBUFBhQs.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-C8-7HmH_.js";import{t as A}from"./copy-DmdM3wEU.js";import{t as j}from"./key-round-C0B7hV3u.js";import{t as M}from"./AddonCollectionPage-DULW5cZ3.js";import{t as ee}from"./plus-DXtZevee.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-DdNXL04K.js";import{t as U}from"./AdminPage-BwmGKnRf.js";import{t as W}from"./AdminTabs-B4tsypGK.js";import{t as G}from"./addon-display-names-DvSEQty-.js";var K=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`}]]),te=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`}]]),ne=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`}]]),q=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`}]]),re=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 ie({userId:e,username:t,onClose:n}){let r=E(),a=i(),o=c({userId:e}),s=o.data,l=()=>r.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),u=v({onSuccess:()=>{l(),n()}}),d=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:[d===`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…`]}),d===`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.`})]})]}),d===`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(y,{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`})&&u.mutate({userId:e})},disabled:u.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:[u.isPending?O(P,{className:`h-3 w-3 animate-spin`}):O(R,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function ae(){let e=E(),{user:t}=z(),[o,c]=D(!1),[l,d]=D(``),[f,m]=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),d(``),m(``),g(!1),v(null)},onError:e=>{v(e instanceof Error?e.message:`Failed to create user`)}}),A=u({onSuccess:T}),j=a({onSuccess:T}),M=n({onSuccess:T}),N=p({onSuccess:()=>{T(),I(null)}}),[F,I]=D(null),[H,W]=D(null),G=y??[];async function K(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 te(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 q(e,t){t!==e.isAdmin&&j.mutate({id:e.id,isAdmin:t})}function re(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=>d(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=>m(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=>q(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:re(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:()=>te(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(ne,{className:`h-3 w-3`}),`Reset password`]}),C(`button`,{onClick:()=>K(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(ie,{userId:H.id,username:H.username,onClose:()=>W(null)}),F&&O(oe,{user:F,onClose:()=>I(null),onSubmit:e=>N.mutate({userId:F.id,scopes:e}),submitting:N.isPending})]})}function oe(e){let{user:t}=z(),n=t?.isAdmin===!0;return O(se,{...e,callerScopes:n?null:t?.scopes??[]})}function se({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=f(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(h,{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 ce=`bg-primary/10 text-primary`,le=`bg-foreground-subtle/10 text-foreground-subtle`;function J(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function ue(e){return e?e===`*`?`*`:e.join(`, `):``}function de(){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),[_,v]=D(null),y=o({onSuccess:f}),b=g({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(fe,{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(fe,{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?ce:le}`,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:ue(e.allowedProviders)||`all`}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.createdAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(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}),_&&O(ve,{token:_.token,label:_.label,onClose:()=>v(null)})]})}function fe({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}=l({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:J(e.expiresAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.lastUsedAt)}),O(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(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`]}]),[p,m]=D(``),g=f(u),_=o!==``&&c.trim().length>0&&u.length>0&&g===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(h,{value:u,onChange:d,clampToParent:a}),g&&O(`p`,{className:`mt-1 text-[10px] text-danger`,children:g})]}),O(Y,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:O(`input`,{type:`number`,min:1,value:p,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(p,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}=_(),a=w(()=>n??[],[n]),o=m({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:q,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:te,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=d(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(K,{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:re,content:O(ae,{})},{id:`api-keys`,label:`Tokens`,icon:j,content:O(de,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:q,content:O(Te,{})},{id:`authentication`,label:`Authentication`,icon:L,content:O(De,{})}]})})}export{ke as IdentityPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Cr as e,Dr as t,Er as n,Mr as r,Nr as i,Or as a,Qa as o,Ra as s,Sr as c,Tr as l,_a as u,bo as d,br as f,bt as p,jr as m,wr as h,xo as g,xr as _,xt as v,yo as y,yr as ee}from"./src-CBUFBhQs.js";import{I as b,Q as x,S,W as C,b as w,o as T,q as E,x as D,z as te}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{o as O,s as k}from"./src-DNEnYGfh.js";import{p as A}from"./player-overlays-BUEqEqaL.js";import{n as j,t as ne}from"./rotate-ccw-BsVOOlvm.js";import{t as M}from"./copy-DmdM3wEU.js";import{n as re,t as N}from"./AddonCollectionPage-DULW5cZ3.js";import{t as ie}from"./refresh-cw-DZAB0JuF.js";import{t as P}from"./server-BGfq1DMy.js";import{t as ae}from"./square-BELgWOxZ.js";import{t as oe}from"./wifi-B_qoHnYl.js";import{L as se,S as F,T as I,W as L,b as ce,i as le,k as R,l as ue,o as z,v as B,x as de}from"./index-DdNXL04K.js";import{t as V}from"./AdminPage-BwmGKnRf.js";import{t as H}from"./AdminTabs-B4tsypGK.js";import{t as U}from"./addon-display-names-DvSEQty-.js";var fe=L(`log-in`,[[`path`,{d:`m10 17 5-5-5-5`,key:`1bsop3`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`,key:`u53s6r`}]]),W=L(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]),G=L(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]);x();var K=5e3,pe={connected:!1,endpoint:null};function me(){let e=T(),t=v({capName:`network-access`},{refetchInterval:K}),n=p(void 0,{refetchInterval:K}),a=C(()=>U(n.data??[]),[n.data]),o=C(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:a.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,a]),[s,c]=E(null),[l,u]=E({}),d=(t,n)=>{let r=n?.addonId;e.invalidateQueries({queryKey:[[`networkAccess`,`getStatus`],{input:{addonId:r},type:`query`}]}),c(null),u(e=>{if(r===void 0||!(r in e))return e;let t={...e};return delete t[r],t})},f=(e,t)=>{c(null);let n=t?.addonId;if(n===void 0)return;let r=e instanceof Error?e.message:String(e);u(e=>({...e,[n]:r}))},m=r({onSuccess:d,onError:f}),h=i({onSuccess:d,onError:f});return D(N,{title:`Remote Access`,subtitle:`Public-facing tunnels that expose this hub to the internet (Cloudflare Tunnel, ngrok, …). Settings, Logs and Events are docked under every provider.`,pageIcon:I,itemIcon:I,capability:`network-access`,installButtonLabel:`Add tunnel`,items:o,isLoading:t.isLoading,emptyTitle:`No remote-access providers installed`,emptyDescription:`Install a tunnel addon (e.g. @camstack/addon-cloudflare) to expose this hub publicly.`,renderStatusBadges:e=>D(he,{addonId:e.addonId}),itemError:e=>l[e.addonId]??null,renderPrimaryAction:e=>D(ge,{addonId:e.addonId,busyId:s,onStart:e=>{c(e),m.mutate({addonId:e})},onStop:e=>{c(e),h.mutate({addonId:e})}})})}function q(e){let{data:t}=m({addonId:e},{refetchInterval:K,retry:!1}),n=t?k.safeParse(t):null;return n?.success?n.data:pe}function he({addonId:e}){let t=q(e);return S(w,{children:[D(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.connected?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.connected?`Connected`:`Disconnected`}),t.endpoint&&S(`a`,{href:t.endpoint.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-[10px] text-emerald-700 dark:text-emerald-300 hover:underline flex items-center gap-1`,children:[D(R,{className:`h-3 w-3`}),t.endpoint.url]})]})}function ge({addonId:e,busyId:t,onStart:n,onStop:r}){let i=q(e),a=t===e;return i.connected?S(g,{size:`sm`,variant:`secondary`,disabled:a,onClick:()=>r(e),children:[a?D(F,{className:`h-3 w-3 animate-spin`}):D(ae,{className:`h-3 w-3`}),`Stop`]}):S(g,{size:`sm`,variant:`primary`,disabled:a,onClick:()=>n(e),children:[a?D(F,{className:`h-3 w-3 animate-spin`}):D(re,{className:`h-3 w-3`}),`Start`]})}x();var J=3e4;function _e(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function ve(){let e=v({capName:`turn-provider`},{refetchInterval:J}),t=p(void 0,{refetchInterval:J}),n=u(),r=n.data??[],i=C(()=>U(t.data??[]),[t.data]);return D(N,{title:`TURN Servers`,subtitle:`ICE servers used for WebRTC NAT traversal. Multiple providers can coexist — the WebRTC layer concatenates servers from all enabled providers per session.`,pageIcon:B,itemIcon:B,capability:`turn-provider`,installButtonLabel:`Add provider`,items:C(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:i.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,i]),isLoading:e.isLoading,emptyTitle:`No TURN providers installed`,emptyDescription:`Install a TURN addon (e.g. @camstack/addon-cloudflare) to enable WebRTC behind restrictive NATs.`,renderExpandedPanel:e=>D(ye,{addonId:e.addonId,enabled:e.isActive}),trailing:S(y,{children:[S(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[S(`div`,{children:[D(`div`,{className:`text-sm font-semibold`,children:`Combined ICE server list`}),D(`div`,{className:`text-xs text-foreground-subtle`,children:`What the WebRTC layer fetches per-session.`})]}),D(g,{size:`sm`,variant:`secondary`,onClick:()=>n.refetch(),disabled:n.isFetching,children:`Refresh`})]}),D(`div`,{className:`p-4`,children:r.length===0?D(`div`,{className:`text-xs text-foreground-subtle`,children:`No servers from enabled providers.`}):D(`div`,{className:`flex flex-col gap-3`,children:r.map((e,t)=>{let n=Array.isArray(e.urls)?e.urls:[e.urls];return S(`div`,{className:`rounded border border-border bg-surface`,children:[(e.username||e.credential)&&S(`div`,{className:`px-3 py-1.5 border-b border-border text-[10px] font-mono text-foreground-subtle flex items-center gap-3`,children:[e.username&&S(`span`,{children:[D(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,D(`span`,{className:`text-foreground`,children:e.username})]}),e.credential&&S(`span`,{children:[D(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,D(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),D(`ul`,{className:`divide-y divide-border`,children:n.map(e=>D(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},t)})})})]})})}function ye({addonId:e,enabled:t}){let n=u({addonId:e},{enabled:t,retry:!1}),r=C(()=>_e(n.data??[]),[n.data]);return!t||r.length===0?null:S(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[S(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Discovered ICE servers (`,r.length,`)`]}),D(`div`,{className:`flex flex-wrap gap-1`,children:r.map(e=>D(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground`,children:e},e))})]})}x();var be={lan:B,wifi:oe,docker:j,vpn:de,loopback:P,other:P},xe={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},Se=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function Ce(e){let{interfaces:t,disabled:n,hideLoopback:r,ipv4Only:i,emptyMessage:a}=e,o=C(()=>t.filter(e=>!(r&&e.kind===`loopback`||i&&e.family!==`IPv4`)),[t,r,i]),s=C(()=>{let e=new Map;for(let t of o){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return Se.filter(t=>e.has(t)).map(t=>({kind:t,items:e.get(t)}))},[o]),c=t=>e.mode===`single`?e.value===t:e.value.includes(t),l=t=>{if(n||t.kind===`loopback`)return;if(e.mode===`single`){e.onChange(e.value===t.address?null:t.address);return}let r=new Set(e.value);r.has(t.address)?r.delete(t.address):r.add(t.address),e.onChange([...r])};return o.length===0?D(`div`,{className:`text-xs text-foreground-subtle italic`,children:a??`No addresses available.`}):D(`div`,{className:`flex flex-col gap-3`,children:s.map(({kind:t,items:r})=>S(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[S(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[D(be[t]??P,{className:`h-3.5 w-3.5 text-foreground-subtle`}),D(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:xe[t]??t}),S(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,r.length]})]}),D(`ul`,{className:`divide-y divide-border`,children:r.map(t=>{let r=c(t.address),i=t.kind===`loopback`,a=!t.plausible&&!i;return S(`li`,{className:`flex items-center gap-3 px-3 py-2 ${i?`opacity-60 cursor-not-allowed`:n?`opacity-60`:a?`cursor-pointer hover:bg-surface-hover/30 bg-amber-500/[0.04]`:`cursor-pointer hover:bg-surface-hover/30`}`,onClick:()=>l(t),children:[D(`span`,{className:`flex items-center justify-center h-4 w-4 rounded ${e.mode===`single`?`rounded-full`:`rounded`} border ${r?`border-primary bg-primary text-primary-foreground`:`border-border bg-surface`}`,children:r&&D(se,{className:`h-3 w-3`})}),S(`div`,{className:`flex-1 min-w-0 ${a?`text-foreground-subtle`:``}`,children:[S(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[D(`span`,{className:`font-mono text-xs font-semibold ${a?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),D(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-mono`,children:t.family}),t.preferred&&D(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:`Auto-preferred`}),i&&D(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:`Always included`}),a&&S(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:t.plausibleReason||void 0,children:[D(z,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]}),S(`div`,{className:`text-xs text-foreground-subtle mt-0.5 font-mono break-all`,children:[t.address,t.cidr&&t.cidr!==t.address?` (${t.cidr})`:``]})]})]},`${t.name}-${t.family}-${t.address}`)})})]},t))})}x();var Y={"lan-ipv4":`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,"lan-ipv6":`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`,loopback:`bg-foreground-subtle/15 text-foreground-subtle`};function we(){let t=T(),n=A(),r=_(void 0,{refetchInterval:3e4}),i=ee(void 0),a=e({onSuccess:()=>{t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),o=c({onSuccess:e=>{d(e.addresses),t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),s=C(()=>r.data?.interfaces??[],[r.data]),l=f({port:typeof window<`u`?Number(window.location.port)||(window.location.protocol===`https:`?443:80):4e3,scheme:typeof window<`u`&&window.location.protocol===`https:`?`https`:`http`},{refetchInterval:3e4}),[u,d]=E([]),[p,m]=E(!1);te(()=>{!p&&i.data&&(d(i.data.addresses),m(!0))},[i.data,p]);let h=i.data?.addresses??[],v=C(()=>{if(u.length!==h.length)return!0;let e=[...u].toSorted(),t=[...h].toSorted();return e.some((e,n)=>e!==t[n])},[u,h]),b=()=>{a.mutate({addresses:[...u]})},x=()=>{d(h)},w=()=>{d([])},O=()=>{r.refetch(),l.refetch(),i.refetch()},k=async()=>{try{let e=await n.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info(`[network-addresses] race result`,e)}catch(e){console.warn(`[network-addresses] race failed`,e)}},j=l.data?.endpoints??[];return S(V,{children:[S(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[D(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Pick the local addresses SDK clients should race for the fastest path to this hub. Empty selection (auto) lets every non-loopback / non-link-local interface participate.`}),S(`div`,{className:`flex items-center gap-2 shrink-0`,children:[S(g,{size:`sm`,variant:`secondary`,onClick:O,disabled:r.isLoading,children:[D(ie,{className:`h-3 w-3 ${r.isLoading?`animate-spin`:``}`}),`Refresh`]}),D(g,{size:`sm`,variant:`secondary`,onClick:k,children:`Probe race`})]})]}),S(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[S(y,{children:[S(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[S(`div`,{children:[D(`div`,{className:`text-sm font-semibold`,children:`Allowed addresses`}),D(`div`,{className:`text-xs text-foreground-subtle`,children:u.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${u.length} pinned`})]}),S(`div`,{className:`flex items-center gap-1`,children:[S(g,{size:`sm`,variant:`secondary`,onClick:()=>o.mutate(void 0),disabled:o.isPending||a.isPending,title:`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`,children:[D(ue,{className:`h-3 w-3`}),o.isPending?`Detecting…`:`Best match`]}),S(g,{size:`sm`,variant:`secondary`,onClick:w,disabled:u.length===0||a.isPending,children:[D(ne,{className:`h-3 w-3`}),`Clear`]}),v&&D(g,{size:`sm`,variant:`secondary`,onClick:x,disabled:a.isPending,children:`Discard`}),S(g,{size:`sm`,variant:`primary`,onClick:b,disabled:!v||a.isPending,children:[D(W,{className:`h-3 w-3`}),a.isPending?`Saving…`:`Save`]})]})]}),D(`div`,{className:`p-4`,children:D(Ce,{mode:`multiple`,interfaces:s,value:u,onChange:d,disabled:a.isPending,emptyMessage:r.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),S(y,{children:[S(`div`,{className:`px-4 py-3 border-b border-border`,children:[D(`div`,{className:`text-sm font-semibold`,children:`Connection endpoints — priority order`}),D(`div`,{className:`text-xs text-foreground-subtle`,children:`Live preview of the ranked candidate list the SDK would race against. Updates with each Save.`})]}),D(`div`,{className:`p-4`,children:j.length===0?D(`div`,{className:`text-xs text-foreground-subtle italic`,children:l.isLoading?`Loading…`:`No endpoints available.`}):D(`ul`,{className:`space-y-1 text-xs`,children:j.map(e=>S(`li`,{className:`flex items-center gap-2 flex-wrap ${e.plausible?``:`opacity-80`}`,children:[D(`span`,{className:`font-mono text-[10px] w-10 text-foreground-subtle`,children:String(e.priority).padStart(4,`0`)}),D(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${Y[e.kind]??Y.loopback}`,children:e.kind}),e.interfaceKind!==`lan`&&e.interfaceKind!==`public`&&D(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-medium uppercase`,children:e.interfaceKind}),!e.plausible&&e.interfaceKind!==`loopback`&&S(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:e.plausibleReason||void 0,children:[D(z,{className:`h-2.5 w-2.5`}),`Unlikely usable`]}),D(`span`,{className:`font-mono break-all ${e.plausible?`text-foreground`:`text-foreground-subtle`}`,children:e.baseUrl}),S(`span`,{className:`text-foreground-subtle`,children:[`— `,e.label]})]},`${e.priority}-${e.baseUrl}`))})})]})]})]})}x();var Te={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},X=5e3,Ee=3e4,De={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function Oe(){let e=v({capName:`mesh-network`},{refetchInterval:X}),t=p(void 0,{refetchInterval:X}),n=C(()=>U(t.data??[]),[t.data]);return D(N,{title:`Mesh Networks`,subtitle:`Private VPN meshes that connect CamStack to your other devices (Tailscale, Headscale, …). Each provider can also expose this hub publicly via its ingress (Tailscale Funnel).`,pageIcon:j,itemIcon:B,capability:`mesh-network`,installButtonLabel:`Add mesh`,items:C(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,n]),isLoading:e.isLoading,emptyTitle:`No mesh-network providers installed`,emptyDescription:`Install a mesh addon (e.g. @camstack/addon-tailscale) to join this hub into a private VPN mesh.`,renderStatusBadges:e=>D(ke,{addonId:e.addonId}),renderPrimaryAction:e=>D(Ae,{addonId:e.addonId}),renderExpandedPanel:e=>D(je,{addonId:e.addonId})})}function Z(e){let{data:t,isLoading:n}=h({addonId:e},{refetchInterval:X,retry:!1}),r=t?O.safeParse(t):null;return{status:r?.success?r.data:De,isLoading:n}}function ke({addonId:e}){let{status:t}=Z(e);return S(w,{children:[D(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.joined?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.joined?`Joined`:`Not joined`}),t.joined&&S(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:[t.peerCount,` peer`,t.peerCount===1?``:`s`]})]})}function Ae({addonId:e}){let n=T(),[r,i]=E(!1),[o,s]=E(null),c=A(),{status:u}=Z(e),d=b(()=>{n.invalidateQueries({queryKey:[[`meshNetwork`]]})},[n]),f=a(),p=l({onSuccess:d}),m=t({onSuccess:d}),h=b(async()=>{i(!0);let t={cancelled:!1};s(t);try{let n=await f.mutateAsync({addonId:e});if(t.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!t.cancelled&&(await Ie(2e3),!t.cancelled);){let t=await c.trpcClient.meshNetwork.getStatus.query({addonId:e}).catch(()=>null),n=t?O.safeParse(t):null;if(n?.success&&n.data.joined){d();break}if(Date.now()-r>6e5)break}}finally{i(!1),s(null)}},[e,d,f,c]),_=b(()=>{o&&(o.cancelled=!0),i(!1),s(null)},[o]);return D(w,{children:u.joined?S(w,{children:[S(g,{size:`sm`,variant:`secondary`,disabled:p.isPending,onClick:()=>p.mutate({addonId:e}),children:[p.isPending?D(F,{className:`h-3 w-3 animate-spin`}):D(ce,{className:`h-3 w-3`}),`Disconnect`]}),S(g,{size:`sm`,variant:`ghost`,disabled:m.isPending,onClick:()=>m.mutate({addonId:e}),children:[m.isPending?D(F,{className:`h-3 w-3 animate-spin`}):D(G,{className:`h-3 w-3`}),`Log out`]})]}):r?S(g,{size:`sm`,variant:`ghost`,onClick:_,children:[D(le,{className:`h-3 w-3 mr-1`}),` Cancel`]}):S(w,{children:[S(g,{size:`sm`,variant:`primary`,onClick:()=>void h(),children:[D(fe,{className:`h-3 w-3`}),`Connect`]}),S(g,{size:`sm`,variant:`ghost`,disabled:m.isPending,onClick:()=>m.mutate({addonId:e}),children:[m.isPending?D(F,{className:`h-3 w-3 animate-spin`}):D(G,{className:`h-3 w-3`}),`Log out`]})]})})}function je({addonId:e}){let{status:t}=Z(e),r=n({addonId:e},{refetchInterval:Ee,retry:!1});return S(`div`,{className:`rounded-lg border border-border bg-surface`,children:[S(`div`,{className:`p-4 space-y-4`,children:[t.error&&D(s,{message:t.error}),D(Me,{status:t}),t.endpoints.length>0&&S(`div`,{className:`space-y-1.5`,children:[D(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Endpoints`}),t.endpoints.map(e=>S(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[S(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${Te[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?D(I,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),S(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-emerald-700 dark:text-emerald-300 hover:underline break-all flex items-center gap-1`,children:[D(R,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),D(`div`,{className:`border-t border-border`,children:D(Pe,{peers:r.data?.peers??[],loading:r.isLoading})})]})}function Me({status:e}){return D(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-1.5`,children:[{label:`Tenant`,value:e.tenantName||`—`},{label:`User`,value:e.userLogin??`—`},{label:`Control plane`,value:e.controlPlaneUrl||`—`},{label:`Mesh IP`,value:e.meshIp||`—`,mono:!0},{label:`MagicDNS`,value:e.magicDnsHostname||`—`,mono:!0},{label:`DNS suffix`,value:e.magicDnsSuffix||`—`,mono:!0},{label:`Peers`,value:String(e.peerCount)},{label:`Key expiry`,value:e.keyExpiry?Ne(e.keyExpiry):`—`}].map(e=>S(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[D(`span`,{className:`text-foreground-subtle shrink-0`,children:e.label}),D(`span`,{className:`text-foreground truncate ${e.mono?`font-mono`:``}`,children:e.value})]},e.label))})}function Ne(e){let t=e-Date.now();if(t<0)return`Expired ${$(e)}`;let n=Math.floor(t/864e5);if(n>60)return new Date(e).toLocaleDateString();if(n>1)return`in ${n} days`;let r=Math.floor(t/36e5);return r>1?`in ${r}h`:`in ${Math.max(1,Math.floor(t/6e4))} min`}function Pe({peers:e,loading:t}){let n=C(()=>e.map(e=>({...e,_id:e.id})),[e]),r=b(e=>{e&&navigator.clipboard?.writeText(e)},[]),i=C(()=>[{key:`hostname`,header:`Hostname`,render:e=>S(`div`,{className:`flex flex-col`,children:[S(`div`,{className:`flex items-center gap-1.5`,children:[D(`span`,{className:`font-medium text-foreground`,children:e.hostname||`(unknown)`}),e.isSelf&&D(d,{variant:`info`,children:`self`}),e.exitNodeOption&&D(d,{variant:`warning`,children:`exit-node`})]}),e.userLogin&&D(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.userLogin})]})},{key:`magicDns`,header:`MagicDNS`,render:e=>e.magicDns?S(`div`,{className:`flex items-center gap-1`,children:[D(`span`,{className:`font-mono text-xs truncate`,children:e.magicDns}),D(`button`,{onClick:()=>r(e.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy MagicDNS`,children:D(M,{className:`h-3 w-3 text-foreground-subtle`})})]}):D(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:e=>{let t=e.addresses[0]??``;return t?S(`div`,{className:`flex items-center gap-1`,children:[D(`span`,{className:`font-mono text-xs`,children:t}),D(`button`,{onClick:()=>r(t),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy IP`,children:D(M,{className:`h-3 w-3 text-foreground-subtle`})})]}):D(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:`Connection`,render:e=>S(`div`,{className:`flex items-center gap-1.5`,children:[D(d,{variant:Fe(e.connection),children:e.connection}),e.relay&&D(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.relay})]})},{key:`routes`,header:`Routes`,render:e=>e.advertisedRoutes.length>0?D(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):D(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:`TX / RX`,render:e=>S(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,Q(e.txBytes),` · ↓ `,Q(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>D(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?$(e.lastSeenMs):`—`})}],[r]);return t&&e.length===0?S(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[D(F,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):e.length===0?D(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No peers visible — your tailnet may be empty or the host is not joined.`}):D(`div`,{className:`p-4`,children:D(o,{columns:i,rows:n,rowKey:e=>e._id,minWidthPx:820})})}function Fe(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function Q(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)}MB`:`${(e/1024/1024/1024).toFixed(2)}GB`}function $(e){let t=Date.now()-e;return t<6e4?`just now`:t<36e5?`${Math.round(t/6e4)}m ago`:t<864e5?`${Math.round(t/36e5)}h ago`:`${Math.round(t/864e5)}d ago`}function Ie(e){return new Promise(t=>setTimeout(t,e))}function Le(){return D(`div`,{className:`flex flex-col p-4`,children:D(H,{tabs:[{id:`addresses`,label:`Network Addresses`,icon:P,content:D(we,{})},{id:`remote-access`,label:`Remote Access`,icon:I,content:D(me,{})},{id:`mesh`,label:`Mesh Networks`,icon:j,content:D(Oe,{})},{id:`turn`,label:`TURN Servers`,icon:B,content:D(ve,{})}]})})}export{Le as NetworkPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Ra as e,S as t,_o as n,bo as r,do as i,fo as a,go as o,ho as s,mo as c,xo as l,yo as u}from"./src-CBUFBhQs.js";import{Q as d,S as f,W as p,a as m,q as h,t as g,x as _}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 v}from"./player-overlays-BUEqEqaL.js";import{t as y}from"./circle-check-big-C8-7HmH_.js";import{t as b}from"./pencil-CkuaFJis.js";import{t as x}from"./plus-DXtZevee.js";import{t as S}from"./search-DW0Hs-NC.js";import{t as C}from"./send-C9E6gIVU.js";import{N as w,S as T,V as E,s as D}from"./index-DdNXL04K.js";import{t as O}from"./AdminPage-BwmGKnRf.js";d();var k=e=>typeof e==`string`&&e.length>0;function A(e){return{levels:e.levels,formats:e.format,bodyMaxLen:e.bodyMaxLen,attachmentSlots:e.attachments.mediaTypes,attachmentMode:e.attachments.mode,attachmentMax:e.attachments.max,attachmentMaxBytes:e.attachments.maxBytes,maxActions:e.actions,showActions:e.actions>0,showClickUrl:e.clickUrl,showSound:e.sound,showTtl:e.ttl,showTag:!0}}function j(e,t){return e.format.includes(t)?t:e.format[0]??`text`}function M(e,t){let n=[];for(let r of e.attachments.mediaTypes){if(n.length>=e.attachments.max)break;let i=t[r];k(i)&&n.push({mediaType:r,url:i})}return n}function N(e,t){if(e.actions<=0)return[];let n=[];for(let r of t){if(n.length>=e.actions)break;let t=k(r.label),i=k(r.url);!t&&!i||n.push({id:`test-${n.length+1}`,label:t?r.label:`Action ${n.length+1}`,...i?{url:r.url}:{}})}return n}function P(e,t){let n=e.levels.some(e=>e.id===t.level)?t.level:void 0,r=M(e,t.attachmentUrls),i=N(e,t.actions),a=e.ttl&&k(t.ttl)?Number(t.ttl):void 0;return{body:t.body,format:j(e,t.format),priority:F(t.priority),...k(t.title)?{title:t.title}:{},...n?{level:n}:{},...r.length>0?{attachments:r}:{},...i.length>0?{actions:i}:{},...e.clickUrl&&k(t.clickUrl)?{clickUrl:t.clickUrl}:{},...e.sound&&k(t.sound)?{sound:t.sound}:{},...a!==void 0&&Number.isFinite(a)?{ttl:a}:{},...k(t.tag)?{tag:t.tag}:{}}}function F(e){return Number.isFinite(e)?Math.min(5,Math.max(1,Math.round(e))):3}function I(e){return e.levels.find(e=>e.flags?.critical===!0)||e.levels.filter(e=>typeof e.ordinal==`number`).sort((e,t)=>t.ordinal-e.ordinal)[0]}function L(e){return{level:``,priority:3,format:e.format[0]??`text`,title:``,body:``,attachmentUrls:{},actions:[],clickUrl:``,sound:``,ttl:``,tag:``}}var R={image:`https://example.com/sample.jpg`,video:`https://example.com/sample.mp4`,gif:`https://example.com/sample.gif`,audio:`https://example.com/sample.mp3`,icon:`https://example.com/icon.png`};function z(e,t){let n=L(e);switch(t){case`minimal`:return{...n,body:`Test notification`};case`overflow`:return{...n,body:`X`.repeat(e.bodyMaxLen+50)};case`critical`:{let t=I(e);return{...n,body:`Critical test notification`,priority:5,level:t?.id??``}}case`everything`:{let t={},n=0;for(let r of e.attachments.mediaTypes){if(n>=e.attachments.max)break;t[r]=R[r],n+=1}let r=Array.from({length:e.actions},(e,t)=>({label:`Action ${t+1}`,url:`https://example.com/action/${t+1}`}));return{level:``,priority:4,format:e.format.includes(`markdown`)?`markdown`:e.format.includes(`html`)?`html`:e.format[0]??`text`,title:`Everything the kind supports`,body:`This sample fills every control the kind advertises.`,attachmentUrls:t,actions:r,clickUrl:e.clickUrl?`https://example.com/open`:``,sound:e.sound?`default`:``,ttl:e.ttl?`3600`:``,tag:`camstack-test`}}}}var B=[{id:`minimal`,label:`Minimal (body only)`},{id:`everything`,label:`Everything supported`},{id:`overflow`,label:`Overflow`},{id:`critical`,label:`Critical`}],V=`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none`,H=`block text-[11px] font-medium text-foreground mb-1`;function U({target:e,kind:t,open:n,onClose:u}){let d=v(),m=p(()=>A(t.caps),[t.caps]),[y,b]=h(()=>L(t.caps)),[x,S]=h(null),w=p(()=>P(t.caps,y),[t.caps,y]),E=y.body.length,D=E>m.bodyMaxLen,O=e=>b(t=>({...t,...e})),k=g({mutationFn:()=>d.trpcClient.notificationOutput.testTarget.mutate({addonId:e.addonId,targetId:e.id,sample:P(t.caps,y)}),onMutate:()=>S(null),onSuccess:e=>S(e),onError:e=>S({success:!1,error:e instanceof Error?e.message:`Test failed`})}),j=e=>{b(z(t.caps,e)),S(null)},M=(e,t,n)=>{let r=y.actions.length>0?[...y.actions]:[];for(;r.length<=e;)r.push({label:``,url:``});r[e]={...r[e],[t]:n},O({actions:r})};return _(i,{open:n,onOpenChange:e=>!e&&u(),children:f(a,{width:`lg`,className:`!max-w-2xl`,children:[_(s,{children:f(o,{children:[`Test "`,e.name,`" (`,t.label,`)`]})}),f(`div`,{className:`space-y-4 max-h-[60vh] overflow-y-auto pr-1`,children:[_(`div`,{className:`flex flex-wrap gap-1.5`,children:B.map(e=>_(l,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>j(e.id),children:e.label},e.id))}),f(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[m.levels.length>0&&f(`div`,{children:[_(`label`,{className:H,children:`Level`}),f(`select`,{className:V,value:y.level,onChange:e=>O({level:e.target.value}),children:[_(`option`,{value:``,children:`— derive from priority —`}),m.levels.map(e=>f(`option`,{value:e.id,children:[e.label,e.ordinal===null?` (qualitative)`:` (p${e.ordinal})`]},e.id))]}),(()=>{let e=m.levels.find(e=>e.id===y.level);return e?f(`div`,{className:`mt-1 space-y-1`,children:[e.description&&_(`p`,{className:`text-[10px] text-foreground-subtle`,children:e.description}),f(`div`,{className:`flex flex-wrap gap-1`,children:[e.flags?.critical&&_(r,{variant:`danger`,"data-testid":`flag-critical`,children:`critical`}),e.flags?.silent&&_(r,{variant:`info`,children:`silent`}),e.flags?.noPush&&_(r,{variant:`warning`,children:`no-push`})]}),e.requires&&e.requires.length>0&&f(`p`,{className:`text-[10px] text-warning`,children:[`Requires target config: `,e.requires.join(`, `)]})]}):null})()]}),f(`div`,{children:[f(`label`,{className:H,children:[`Priority (ordinal): `,y.priority]}),_(`input`,{type:`range`,min:1,max:5,step:1,value:y.priority,onChange:e=>O({priority:Number(e.target.value)}),className:`w-full accent-primary`,"aria-label":`priority`})]})]}),m.formats.length>0&&f(`div`,{children:[_(`label`,{className:H,children:`Format`}),_(`div`,{className:`flex flex-wrap gap-2`,children:m.formats.map(e=>f(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[_(`input`,{type:`radio`,name:`format`,className:`accent-primary`,checked:y.format===e,onChange:()=>O({format:e})}),e]},e))})]}),f(`div`,{children:[_(`label`,{className:H,children:`Title`}),_(`input`,{className:V,value:y.title,onChange:e=>O({title:e.target.value})})]}),f(`div`,{children:[f(`label`,{className:H,children:[`Body`,` `,f(`span`,{className:D?`text-danger`:`text-foreground-subtle`,children:[`(`,E,`/`,m.bodyMaxLen,D?` — overflow`:``,`)`]})]}),_(`textarea`,{className:`${V} min-h-[80px] resize-y`,value:y.body,onChange:e=>O({body:e.target.value})})]}),m.attachmentSlots.length>0&&f(`div`,{children:[f(`label`,{className:H,children:[`Attachments`,` `,f(`span`,{className:`text-foreground-subtle`,children:[`(mode: `,m.attachmentMode,`, max `,m.attachmentMax,m.attachmentMaxBytes?`, ≤${Math.round(m.attachmentMaxBytes/1024/1024)}MB`:``,`)`]})]}),_(`div`,{className:`space-y-1.5`,children:m.attachmentSlots.map(e=>f(`div`,{className:`flex items-center gap-2`,children:[_(`span`,{className:`text-[10px] w-12 shrink-0 text-foreground-subtle`,children:e}),_(`input`,{className:V,placeholder:`${e} URL`,value:y.attachmentUrls[e]??``,onChange:t=>O({attachmentUrls:{...y.attachmentUrls,[e]:t.target.value}})})]},e))})]}),m.showActions&&f(`div`,{children:[f(`label`,{className:H,children:[`Actions (up to `,m.maxActions,`)`]}),_(`div`,{className:`space-y-1.5`,children:Array.from({length:Math.min(m.maxActions,3)},(e,t)=>f(`div`,{className:`flex items-center gap-2`,children:[_(`input`,{className:V,placeholder:`label`,value:y.actions[t]?.label??``,onChange:e=>M(t,`label`,e.target.value)}),_(`input`,{className:V,placeholder:`url`,value:y.actions[t]?.url??``,onChange:e=>M(t,`url`,e.target.value)})]},t))})]}),f(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[m.showClickUrl&&f(`div`,{children:[_(`label`,{className:H,children:`Click URL`}),_(`input`,{className:V,value:y.clickUrl,onChange:e=>O({clickUrl:e.target.value})})]}),m.showSound&&f(`div`,{children:[_(`label`,{className:H,children:`Sound`}),_(`input`,{className:V,value:y.sound,onChange:e=>O({sound:e.target.value})})]}),m.showTtl&&f(`div`,{children:[_(`label`,{className:H,children:`TTL (seconds)`}),_(`input`,{className:V,type:`number`,value:y.ttl,onChange:e=>O({ttl:e.target.value})})]}),m.showTag&&f(`div`,{children:[_(`label`,{className:H,children:`Tag`}),_(`input`,{className:V,value:y.tag,onChange:e=>O({tag:e.target.value})})]})]}),x&&_(W,{result:x}),f(`details`,{className:`text-[10px]`,children:[_(`summary`,{className:`cursor-pointer text-foreground-subtle`,children:`Payload preview`}),_(`pre`,{className:`mt-1 overflow-x-auto rounded bg-surface p-2 text-foreground-subtle`,children:JSON.stringify(w,null,2)})]})]}),f(c,{children:[_(l,{variant:`secondary`,size:`sm`,type:`button`,onClick:u,children:`Close`}),f(l,{size:`sm`,type:`button`,disabled:k.isPending||y.body.length===0,onClick:()=>k.mutate(),children:[k.isPending?_(T,{className:`h-3.5 w-3.5 animate-spin`}):_(C,{className:`h-3.5 w-3.5`}),`Send test`]})]})]})})}function W({result:e}){let t=e.renderedAs;return f(`div`,{className:`rounded-md border px-3 py-2 text-xs ${e.success?`border-success/40 bg-success/10`:`border-danger/40 bg-danger/10`}`,"data-testid":`test-result`,children:[f(`div`,{className:`flex items-center gap-2 font-medium`,children:[e.success?_(y,{className:`h-3.5 w-3.5 text-success`}):_(w,{className:`h-3.5 w-3.5 text-danger`}),_(`span`,{children:e.success?`Delivered`:`Failed`})]}),e.error&&_(`p`,{className:`mt-1 text-danger`,children:e.error}),t&&f(`dl`,{className:`mt-2 grid grid-cols-2 gap-x-3 gap-y-0.5 text-[11px] text-foreground-subtle`,children:[_(`dt`,{children:`Resolved level`}),_(`dd`,{className:`text-foreground`,children:t.level}),_(`dt`,{children:`Format sent`}),_(`dd`,{className:`text-foreground`,children:t.format}),_(`dt`,{children:`Attachments sent`}),_(`dd`,{className:`text-foreground`,children:t.attachmentsSent}),_(`dt`,{children:`Actions sent`}),_(`dd`,{className:`text-foreground`,children:t.actionsSent}),_(`dt`,{children:`Truncated`}),_(`dd`,{className:`text-foreground`,children:t.truncated?`yes`:`no`}),_(`dt`,{children:`Dropped`}),_(`dd`,{className:`text-foreground`,children:t.dropped.length>0?t.dropped.join(`, `):`—`})]})]})}function G(e){let t=[],n=new Map;for(let r of e){let e=n.get(r.addonId);e?e.push(r):(n.set(r.addonId,[r]),t.push(r.addonId))}return t.map(e=>({addonId:e,kinds:n.get(e)??[]}))}function K(e){let t=[],n=e=>{for(let r of e){if(r.type===`password`){t.push(r.key);continue}if(r.type===`group`){n(r.fields);continue}if(r.type===`sub-tabs`)for(let e of r.tabs)n(e.fields)}};for(let t of e.sections)n(t.fields);return t}function q(e,t,n){let r=new Set(n),i={};for(let[n,a]of Object.entries(e)){if(!r.has(n)){i[n]=a;continue}a==null||a===``||a!==t[n]&&(i[n]=a)}return i}function J(e,t){let n=new Set(t),r={};for(let[t,i]of Object.entries(e))r[t]=n.has(t)?``:i;return r}d();var Y=[`notificationOutput`,`listTargets`],X=[`notificationOutput`,`listTargetKinds`];function Z({kind:e,imgClassName:t,fallbackClassName:n}){return e?.iconUrl?_(`img`,{src:e.iconUrl,alt:e.label,className:t,loading:`lazy`,draggable:!1}):_(`span`,{className:n,children:e?.icon??`🔔`})}function Q(){let t=v(),[i,a]=h({mode:`closed`}),[o,s]=h(null),c=m({queryKey:Y,queryFn:()=>t.trpcClient.notificationOutput.listTargets.query({})}),d=m({queryKey:X,queryFn:async()=>(await t.trpcClient.notificationOutput.listTargetKinds.query({})).map(e=>{let t=e.iconUrl;return{...e,configSchema:e.configSchema,iconUrl:t}})}),y=p(()=>d.data??[],[d.data]),S=p(()=>{let e=new Map;for(let t of y)e.set(t.kind,t);return e},[y]),w=g({mutationFn:e=>t.trpcClient.notificationOutput.setTargetEnabled.mutate({addonId:e.target.addonId,targetId:e.target.id,enabled:e.enabled}),onSuccess:()=>void c.refetch()}),k=g({mutationFn:e=>t.trpcClient.notificationOutput.deleteTarget.mutate({addonId:e.addonId,targetId:e.id}),onSuccess:()=>void c.refetch()}),A=o?S.get(o.kind):void 0;return f(O,{icon:E,title:`Notification Targets`,subtitle:`Deliver notifications to ntfy, Pushover, Telegram, Home Assistant and more. Each target's kind declares its capabilities; the test panel shows exactly what a message degrades to.`,actions:f(l,{size:`sm`,type:`button`,onClick:()=>a({mode:`pick-kind`}),children:[_(x,{className:`h-3.5 w-3.5`}),`Add target`]}),children:[c.isLoading&&_(`div`,{className:`flex items-center justify-center py-16`,children:_(T,{className:`h-6 w-6 animate-spin text-primary`})}),c.isError&&!c.isLoading&&_(e,{title:`Failed to load targets`,message:c.error instanceof Error?c.error.message:`Unknown error`,onRetry:()=>void c.refetch()}),!c.isLoading&&!c.isError&&(c.data??[]).length===0&&_(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No notification targets yet. Click "Add target" to configure one.`}),(c.data??[]).length>0&&_(u,{children:_(`ul`,{className:`divide-y divide-border`,children:(c.data??[]).map(e=>{let t=S.get(e.kind);return f(`li`,{className:`flex items-center gap-3 px-4 py-2.5`,children:[_(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface text-xs`,title:t?.label??e.kind,children:_(Z,{kind:t,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:``})}),f(`div`,{className:`min-w-0 flex-1`,children:[_(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),_(`div`,{className:`text-[11px] text-foreground-subtle`,children:t?.label??e.kind})]}),!e.enabled&&_(r,{variant:`warning`,children:`disabled`}),_(n,{checked:e.enabled,onCheckedChange:t=>w.mutate({target:e,enabled:t}),"aria-label":`toggle ${e.name}`}),_(l,{size:`sm`,variant:`ghost`,type:`button`,disabled:!t,onClick:()=>s(e),title:`Test`,children:_(C,{className:`h-3.5 w-3.5`})}),_(l,{size:`sm`,variant:`ghost`,type:`button`,disabled:!t,onClick:()=>t&&a({mode:`form`,kind:t,target:e}),title:`Edit`,children:_(b,{className:`h-3.5 w-3.5`})}),_(l,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>k.mutate(e),title:`Delete`,children:_(D,{className:`h-3.5 w-3.5 text-danger`})})]},e.id)})})}),i.mode===`pick-kind`&&_($,{kinds:y,onCancel:()=>a({mode:`closed`}),onPick:e=>a({mode:`form`,kind:e,target:null})}),i.mode===`form`&&_(ee,{kind:i.kind,target:i.target,onCancel:()=>a({mode:`closed`}),onSaved:()=>{a({mode:`closed`}),c.refetch()}}),o&&A&&_(U,{target:o,kind:A,open:!0,onClose:()=>s(null)})]})}function $({kinds:e,onPick:t,onCancel:n}){let i=p(()=>G(e),[e]);return f(u,{className:`p-4 space-y-4`,children:[f(`div`,{className:`flex items-center justify-between`,children:[_(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Choose a notification kind`}),_(l,{size:`sm`,variant:`ghost`,type:`button`,onClick:n,children:`Cancel`})]}),i.length===0&&_(`p`,{className:`text-xs text-foreground-subtle`,children:`No notification providers are installed. Install the notifiers addon (or connect Home Assistant) to add targets.`}),i.map(e=>f(`div`,{children:[_(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1.5`,children:e.addonId}),_(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-2`,children:e.kinds.map(n=>f(`button`,{type:`button`,onClick:()=>t(n),className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-xs hover:border-primary/50 hover:bg-surface-hover transition-colors`,children:[_(Z,{kind:n,imgClassName:`h-7 w-7 object-contain`,fallbackClassName:`text-lg leading-7`}),_(`span`,{className:`font-medium text-foreground`,children:n.label}),n.supportsDiscovery&&_(r,{variant:`info`,style:`outline`,children:`discover`})]},`${e.addonId}:${n.kind}`))})]},e.addonId))]})}function ee({kind:e,target:n,onSaved:r,onCancel:i}){let a=v(),o=p(()=>K(e.configSchema),[e.configSchema]),s=p(()=>n?.config??{},[n]),[c,d]=h(n?.name??e.label),[m,y]=h(()=>n?J(n.config,o):{}),[b,x]=h(null),[C,w]=h(null),E=g({mutationFn:()=>a.trpcClient.notificationOutput.discoverTargets.query({addonId:e.addonId,kind:e.kind,config:m}),onSuccess:e=>x(e),onError:e=>w(e instanceof Error?e.message:`Discovery failed`)}),D=g({mutationFn:()=>{let t=q(m,s,o),r={id:n?.id??`${e.kind}-${Date.now()}`,name:c,kind:e.kind,addonId:e.addonId,enabled:n?.enabled??!0,config:t};return a.trpcClient.notificationOutput.upsertTarget.mutate({addonId:e.addonId,target:r})},onSuccess:r,onError:e=>w(e instanceof Error?e.message:`Save failed`)}),O=e=>{d(e.suggestedName),y(t=>({...t,...e.config})),x(null)};return f(u,{className:`p-4 space-y-4`,children:[f(`div`,{className:`flex items-center justify-between`,children:[f(`h3`,{className:`text-sm font-semibold text-foreground flex items-center gap-2`,children:[_(Z,{kind:e,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:`text-lg`}),n?`Edit ${n.name}`:`Add ${e.label} target`]}),_(l,{size:`sm`,variant:`ghost`,type:`button`,onClick:i,children:`Cancel`})]}),C&&_(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:C}),f(`div`,{children:[_(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Name`}),_(`input`,{className:`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none`,value:c,onChange:e=>d(e.target.value)})]}),e.supportsDiscovery&&f(`div`,{className:`space-y-2`,children:[f(l,{size:`sm`,variant:`outline`,type:`button`,disabled:E.isPending,onClick:()=>{w(null),E.mutate()},children:[E.isPending?_(T,{className:`h-3.5 w-3.5 animate-spin`}):_(S,{className:`h-3.5 w-3.5`}),`Discover`]}),b&&b.length===0&&_(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No candidates discovered.`}),b&&b.length>0&&_(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:b.map((e,t)=>f(`button`,{type:`button`,onClick:()=>O(e),className:`flex w-full items-center justify-between px-3 py-1.5 text-xs hover:bg-surface-hover`,children:[_(`span`,{className:`text-foreground`,children:e.suggestedName}),_(`span`,{className:`text-[10px] text-primary`,children:`use`})]},`${e.suggestedName}-${t}`))})]}),o.length>0&&n&&_(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Secret fields are hidden. Leave them blank to keep the stored value; type a new value to replace it.`}),_(t,{schema:e.configSchema,values:m,onChange:y}),f(`div`,{className:`flex justify-end gap-2`,children:[_(l,{variant:`secondary`,size:`sm`,type:`button`,onClick:i,children:`Cancel`}),f(l,{size:`sm`,type:`button`,disabled:D.isPending||c.trim().length===0,onClick:()=>{w(null),D.mutate()},children:[D.isPending&&_(T,{className:`h-3.5 w-3.5 animate-spin`}),n?`Save changes`:`Create target`]})]})]})}export{Q as NotificationTargetsPage,Q as default};
|