@camstack/addon-admin-ui 1.2.14 → 1.2.15
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-BzfZuUFE.js +1 -0
- package/dist/assets/{AddonCollectionPage-BjOAYgTp.js → AddonCollectionPage-D4dNkjD9.js} +1 -1
- package/dist/assets/{Addons-DUHpUyAO.js → Addons-KlOfEhx8.js} +1 -1
- package/dist/assets/{AdminTabs-CMgSLZC6.js → AdminTabs-B6qnIaak.js} +1 -1
- package/dist/assets/{AiProfiles-us468lxu.js → AiProfiles-DnuLTZqB.js} +1 -1
- package/dist/assets/{BrokerForm-BkmcCE6M.js → BrokerForm-C99fSuRo.js} +1 -1
- package/dist/assets/{Capabilities-CjbVCuen.js → Capabilities-B8SGK49R.js} +1 -1
- package/dist/assets/{CapabilityBadges-D_UAYLhu.js → CapabilityBadges-BTZKlfM2.js} +1 -1
- package/dist/assets/{Cluster-CNr4iFeW.js → Cluster-COcBiWpg.js} +1 -1
- package/dist/assets/{ClusterRecordingTab-DIyqhjCX.js → ClusterRecordingTab-BPSdzcK3.js} +1 -1
- package/dist/assets/{Dashboard-Cb-fZsKI.js → Dashboard-DCFIPV11.js} +1 -1
- package/dist/assets/{Data-CzcFURIH.js → Data-_pY_q5xu.js} +1 -1
- package/dist/assets/{DetectionIntelligence-C0Rnc9MV.js → DetectionIntelligence-B6Dj5dVX.js} +1 -1
- package/dist/assets/{DeviceDetail-C3gXyjmL.js → DeviceDetail-N6WvCekZ.js} +1 -1
- package/dist/assets/{Devices-CJFFKapv.js → Devices-Dzpvq_f7.js} +1 -1
- package/dist/assets/{EmbedPlayerPage-G8qGznqX.js → EmbedPlayerPage-CNBEeRdP.js} +1 -1
- package/dist/assets/{Events-Bxpsq4KB.js → Events-B5T59IPR.js} +1 -1
- package/dist/assets/{FormBuilder-Bc2pF861.js → FormBuilder-CMFZXwvq.js} +1 -1
- package/dist/assets/{Identity-6aYmMRAa.js → Identity-BbNZdgPf.js} +1 -1
- package/dist/assets/{IntegrationDetail-BJd5rQIs.js → IntegrationDetail-DEPSilP_.js} +1 -1
- package/dist/assets/{Integrations-DkYiGFY6.js → Integrations-B1Ld1HH1.js} +1 -1
- package/dist/assets/{Integrations-BCZXTSBl.js → Integrations-B3rD6hIo.js} +1 -1
- package/dist/assets/{Logs-DeLi7LBK.js → Logs-CYpS3BpR.js} +1 -1
- package/dist/assets/{MyAccess-Bu4oP6WT.js → MyAccess-D3_q9-33.js} +1 -1
- package/dist/assets/{Network-ctXMCHEq.js → Network-DIVAg_f5.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-Vn552ZEg.js → NodeAddonsSettingsPanel-CgGvimGW.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-Bsjb7t1J.js → NodeInferenceDevices-COSPUL-L.js} +1 -1
- package/dist/assets/{Notifications-DSIwFsWT.js → Notifications-Bv4whDil.js} +1 -1
- package/dist/assets/{Pipeline-BTuhtRiQ.js → Pipeline-l_vZ2VML.js} +1 -1
- package/dist/assets/{Plates-Cd8Z5Tay.js → Plates-C96Mahmu.js} +1 -1
- package/dist/assets/{PrivacyMaskSettings-DWiwjf-C.js → PrivacyMaskSettings-C2PIvv63.js} +1 -1
- package/dist/assets/{ProviderIcon-BFPr29U9.js → ProviderIcon-DQ9yuo_L.js} +1 -1
- package/dist/assets/{Recordings-Do1btyjT.js → Recordings-C2R7zGta.js} +1 -1
- package/dist/assets/{ScanNetworkModal-CZEpkk-H.js → ScanNetworkModal-Cl1Mdjki.js} +1 -1
- package/dist/assets/{Settings-DEasv6Oh.js → Settings-CvCaq_zC.js} +1 -1
- package/dist/assets/{Showroom-B5GNdTBu.js → Showroom-BCsIYYwv.js} +1 -1
- package/dist/assets/{Terminal-iwoPCo8t.js → Terminal-BpPIZ0or.js} +1 -1
- package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CKOAyUXR.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-BALp_9qY.js} +1 -1
- package/dist/assets/{build-cluster-graph-BGsdvgDr.js → build-cluster-graph-cp3KQH-1.js} +1 -1
- package/dist/assets/circle-check-big-4_1SeqzL.js +1 -0
- package/dist/assets/clock-CmbYDH1e.js +1 -0
- package/dist/assets/{copy-BHNZnaCo.js → copy-UBfFgSz-.js} +1 -1
- package/dist/assets/{debounced-invalidate-CVNW7HLi.js → debounced-invalidate-BsGZbF6v.js} +1 -1
- package/dist/assets/dist-CphRM5WA.js +7 -0
- package/dist/assets/{download-DZHIT1DT.js → download-BpNiVwyM.js} +1 -1
- package/dist/assets/{face-bbox-DsjjfQwd.js → face-bbox-BScALk_z.js} +1 -1
- package/dist/assets/{hostInit-Dlv5jSIt.js → hostInit-DFZvs0Jw.js} +1 -1
- package/dist/assets/{index-DYyqoGLR.js → index-Cl-M8KBA.js} +3 -3
- package/dist/assets/{key-round-D7FdBlDG.js → key-round-BPb5gRuL.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-531f61ab.js → mf-entry-bootstrap-0-1f1c06da.js} +2 -2
- package/dist/assets/{pencil-CxGqjkCs.js → pencil-Bcfk7YmX.js} +1 -1
- package/dist/assets/plus-z-WZstU2.js +1 -0
- package/dist/assets/{radio-DPtbdTls.js → radio-BH-ZU1HE.js} +1 -1
- package/dist/assets/{refresh-cw-BkfWa5Iq.js → refresh-cw-hhKexEfo.js} +1 -1
- package/dist/assets/remoteEntry-C6sBv4xP.js +1 -0
- package/dist/assets/{rotate-ccw-CgYFUcC2.js → rotate-ccw-CbpUNSqs.js} +1 -1
- package/dist/assets/rotate-cw-CQj7EyBl.js +1 -0
- package/dist/assets/search-DqoMv21b.js +1 -0
- package/dist/assets/{send-BCdV_ME0.js → send-Cyy_G5i9.js} +1 -1
- package/dist/assets/{server-TXHYGvjM.js → server-BxRe5xIW.js} +1 -1
- package/dist/assets/square-CEBWDX93.js +1 -0
- package/dist/assets/{square-check-big-_NruEFe2.js → square-check-big-hPLl5NdC.js} +1 -1
- package/dist/assets/{src-DyTBJAFT.js → src-DHFCkQHW.js} +4 -4
- package/dist/assets/{upload-BVtkUUdn.js → upload-C6Q1-uQx.js} +1 -1
- package/dist/assets/{useEventInvalidation-BVRFuqPz.js → useEventInvalidation-Bh_CgFlD.js} +1 -1
- package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DHIz6BpV.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-C9LrTlPE.js} +2 -2
- package/dist/assets/{wifi-BAI9tmCw.js → wifi-CL8vr9lV.js} +1 -1
- package/dist/assets/{zap-BVDN24DL.js → zap-DZXxY1Hy.js} +1 -1
- package/dist/index.html +3 -3
- package/dist/server/addon.js +1 -1
- package/package.json +1 -1
- package/dist/assets/AddLocationWizard-D14hUBJh.js +0 -1
- package/dist/assets/circle-check-big-BQNarKjk.js +0 -1
- package/dist/assets/clock-Dbl5VjGx.js +0 -1
- package/dist/assets/dist-BJiKlhGI.js +0 -7
- package/dist/assets/plus-99l7KI-i.js +0 -1
- package/dist/assets/remoteEntry-D2YV4TdV.js +0 -1
- package/dist/assets/rotate-cw-D2AVuTNL.js +0 -1
- package/dist/assets/search-D-KPSJSm.js +0 -1
- package/dist/assets/square-CrobJTfv.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Cr as e,Dr as t,Eo as n,Er as r,Ha as i,Mr as a,Nr as o,Or as s,Sr as c,To as l,Tr as u,br as d,bt as f,jr as p,no as m,wo as h,wr as g,xa as _,xr as ee,xt as v,yr as te}from"./src-DyTBJAFT.js";import{I as y,Q as b,S as x,W as S,b as C,o as w,q as T,x as E,z as ne}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 D,s as O}from"./src-Cv9CvT8c.js";import{p as k}from"./player-overlays-CpNYQPHP.js";import{n as A,t as re}from"./rotate-ccw-CgYFUcC2.js";import{t as j}from"./copy-BHNZnaCo.js";import{n as ie,t as M}from"./AddonCollectionPage-BjOAYgTp.js";import{t as ae}from"./refresh-cw-BkfWa5Iq.js";import{t as N}from"./server-TXHYGvjM.js";import{t as oe}from"./square-CrobJTfv.js";import{t as se}from"./wifi-BAI9tmCw.js";import{L as ce,S as P,T as F,W as I,b as le,i as ue,k as L,l as de,o as R,v as z,x as B}from"./index-DYyqoGLR.js";import{t as V}from"./AdminPage-Dq33XE9j.js";import{t as H}from"./AdminTabs-CMgSLZC6.js";import{t as U}from"./addon-display-names-DvSEQty-.js";var fe=I(`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`}]]),pe=I(`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`}]]),W=I(`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`}]]);b();var G=5e3,me={connected:!1,endpoint:null};function he(){let e=w(),t=v({capName:`network-access`},{refetchInterval:G}),n=f(void 0,{refetchInterval:G}),r=S(()=>U(n.data??[]),[n.data]),i=S(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:r.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,r]),[s,c]=T(null),[l,u]=T({}),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})},p=(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=a({onSuccess:d,onError:p}),h=o({onSuccess:d,onError:p});return E(M,{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:F,itemIcon:F,capability:`network-access`,installButtonLabel:`Add tunnel`,items:i,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=>E(ge,{addonId:e.addonId}),itemError:e=>l[e.addonId]??null,renderPrimaryAction:e=>E(_e,{addonId:e.addonId,busyId:s,onStart:e=>{c(e),m.mutate({addonId:e})},onStop:e=>{c(e),h.mutate({addonId:e})}})})}function K(e){let{data:t}=p({addonId:e},{refetchInterval:G,retry:!1}),n=t?O.safeParse(t):null;return n?.success?n.data:me}function ge({addonId:e}){let t=K(e);return x(C,{children:[E(`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&&x(`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:[E(L,{className:`h-3 w-3`}),t.endpoint.url]})]})}function _e({addonId:e,busyId:t,onStart:r,onStop:i}){let a=K(e),o=t===e;return a.connected?x(n,{size:`sm`,variant:`secondary`,disabled:o,onClick:()=>i(e),children:[o?E(P,{className:`h-3 w-3 animate-spin`}):E(oe,{className:`h-3 w-3`}),`Stop`]}):x(n,{size:`sm`,variant:`primary`,disabled:o,onClick:()=>r(e),children:[o?E(P,{className:`h-3 w-3 animate-spin`}):E(ie,{className:`h-3 w-3`}),`Start`]})}b();var q=3e4;function ve(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function ye(){let e=v({capName:`turn-provider`},{refetchInterval:q}),t=f(void 0,{refetchInterval:q}),r=_(),i=r.data??[],a=S(()=>U(t.data??[]),[t.data]);return E(M,{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:z,itemIcon:z,capability:`turn-provider`,installButtonLabel:`Add provider`,items:S(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:a.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,a]),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=>E(be,{addonId:e.addonId,enabled:e.isActive}),trailing:x(h,{children:[x(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[x(`div`,{children:[E(`div`,{className:`text-sm font-semibold`,children:`Combined ICE server list`}),E(`div`,{className:`text-xs text-foreground-subtle`,children:`What the WebRTC layer fetches per-session.`})]}),E(n,{size:`sm`,variant:`secondary`,onClick:()=>r.refetch(),disabled:r.isFetching,children:`Refresh`})]}),E(`div`,{className:`p-4`,children:i.length===0?E(`div`,{className:`text-xs text-foreground-subtle`,children:`No servers from enabled providers.`}):E(`div`,{className:`flex flex-col gap-3`,children:i.map((e,t)=>{let n=Array.isArray(e.urls)?e.urls:[e.urls];return x(`div`,{className:`rounded border border-border bg-surface`,children:[(e.username||e.credential)&&x(`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&&x(`span`,{children:[E(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,E(`span`,{className:`text-foreground`,children:e.username})]}),e.credential&&x(`span`,{children:[E(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,E(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),E(`ul`,{className:`divide-y divide-border`,children:n.map(e=>E(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},t)})})})]})})}function be({addonId:e,enabled:t}){let n=_({addonId:e},{enabled:t,retry:!1}),r=S(()=>ve(n.data??[]),[n.data]);return!t||r.length===0?null:x(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[x(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Discovered ICE servers (`,r.length,`)`]}),E(`div`,{className:`flex flex-wrap gap-1`,children:r.map(e=>E(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground`,children:e},e))})]})}b();var xe={lan:z,wifi:se,docker:A,vpn:B,loopback:N,other:N},Se={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},Ce=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function we(e){let{interfaces:t,disabled:n,hideLoopback:r,ipv4Only:i,emptyMessage:a}=e,o=S(()=>t.filter(e=>!(r&&e.kind===`loopback`||i&&e.family!==`IPv4`)),[t,r,i]),s=S(()=>{let e=new Map;for(let t of o){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return Ce.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?E(`div`,{className:`text-xs text-foreground-subtle italic`,children:a??`No addresses available.`}):E(`div`,{className:`flex flex-col gap-3`,children:s.map(({kind:t,items:r})=>x(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[x(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[E(xe[t]??N,{className:`h-3.5 w-3.5 text-foreground-subtle`}),E(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:Se[t]??t}),x(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,r.length]})]}),E(`ul`,{className:`divide-y divide-border`,children:r.map(t=>{let r=c(t.address),i=t.kind===`loopback`,a=!t.plausible&&!i;return x(`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:[E(`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&&E(ce,{className:`h-3 w-3`})}),x(`div`,{className:`flex-1 min-w-0 ${a?`text-foreground-subtle`:``}`,children:[x(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[E(`span`,{className:`font-mono text-xs font-semibold ${a?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),E(`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&&E(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:`Auto-preferred`}),i&&E(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:`Always included`}),a&&x(`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:[E(R,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]}),x(`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))})}b();var J={"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 Te(){let t=w(),r=k(),i=ee(void 0,{refetchInterval:3e4}),a=te(void 0),o=e({onSuccess:()=>{t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),s=c({onSuccess:e=>{p(e.addresses),t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),l=S(()=>i.data?.interfaces??[],[i.data]),u=d({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}),[f,p]=T([]),[m,g]=T(!1);ne(()=>{!m&&a.data&&(p(a.data.addresses),g(!0))},[a.data,m]);let _=a.data?.addresses??[],v=S(()=>{if(f.length!==_.length)return!0;let e=[...f].toSorted(),t=[..._].toSorted();return e.some((e,n)=>e!==t[n])},[f,_]),y=()=>{o.mutate({addresses:[...f]})},b=()=>{p(_)},C=()=>{p([])},D=()=>{i.refetch(),u.refetch(),a.refetch()},O=async()=>{try{let e=await r.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info(`[network-addresses] race result`,e)}catch(e){console.warn(`[network-addresses] race failed`,e)}},A=u.data?.endpoints??[];return x(V,{children:[x(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[E(`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.`}),x(`div`,{className:`flex items-center gap-2 shrink-0`,children:[x(n,{size:`sm`,variant:`secondary`,onClick:D,disabled:i.isLoading,children:[E(ae,{className:`h-3 w-3 ${i.isLoading?`animate-spin`:``}`}),`Refresh`]}),E(n,{size:`sm`,variant:`secondary`,onClick:O,children:`Probe race`})]})]}),x(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[x(h,{children:[x(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[x(`div`,{children:[E(`div`,{className:`text-sm font-semibold`,children:`Allowed addresses`}),E(`div`,{className:`text-xs text-foreground-subtle`,children:f.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${f.length} pinned`})]}),x(`div`,{className:`flex items-center gap-1`,children:[x(n,{size:`sm`,variant:`secondary`,onClick:()=>s.mutate(void 0),disabled:s.isPending||o.isPending,title:`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`,children:[E(de,{className:`h-3 w-3`}),s.isPending?`Detecting…`:`Best match`]}),x(n,{size:`sm`,variant:`secondary`,onClick:C,disabled:f.length===0||o.isPending,children:[E(re,{className:`h-3 w-3`}),`Clear`]}),v&&E(n,{size:`sm`,variant:`secondary`,onClick:b,disabled:o.isPending,children:`Discard`}),x(n,{size:`sm`,variant:`primary`,onClick:y,disabled:!v||o.isPending,children:[E(pe,{className:`h-3 w-3`}),o.isPending?`Saving…`:`Save`]})]})]}),E(`div`,{className:`p-4`,children:E(we,{mode:`multiple`,interfaces:l,value:f,onChange:p,disabled:o.isPending,emptyMessage:i.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),x(h,{children:[x(`div`,{className:`px-4 py-3 border-b border-border`,children:[E(`div`,{className:`text-sm font-semibold`,children:`Connection endpoints — priority order`}),E(`div`,{className:`text-xs text-foreground-subtle`,children:`Live preview of the ranked candidate list the SDK would race against. Updates with each Save.`})]}),E(`div`,{className:`p-4`,children:A.length===0?E(`div`,{className:`text-xs text-foreground-subtle italic`,children:u.isLoading?`Loading…`:`No endpoints available.`}):E(`ul`,{className:`space-y-1 text-xs`,children:A.map(e=>x(`li`,{className:`flex items-center gap-2 flex-wrap ${e.plausible?``:`opacity-80`}`,children:[E(`span`,{className:`font-mono text-[10px] w-10 text-foreground-subtle`,children:String(e.priority).padStart(4,`0`)}),E(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${J[e.kind]??J.loopback}`,children:e.kind}),e.interfaceKind!==`lan`&&e.interfaceKind!==`public`&&E(`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`&&x(`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:[E(R,{className:`h-2.5 w-2.5`}),`Unlikely usable`]}),E(`span`,{className:`font-mono break-all ${e.plausible?`text-foreground`:`text-foreground-subtle`}`,children:e.baseUrl}),x(`span`,{className:`text-foreground-subtle`,children:[`— `,e.label]})]},`${e.priority}-${e.baseUrl}`))})})]})]})]})}b();var Ee={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},Y=5e3,De=3e4,Oe={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function ke(){let e=v({capName:`mesh-network`},{refetchInterval:Y}),t=f(void 0,{refetchInterval:Y}),n=S(()=>U(t.data??[]),[t.data]);return E(M,{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:A,itemIcon:z,capability:`mesh-network`,installButtonLabel:`Add mesh`,items:S(()=>(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=>E(Ae,{addonId:e.addonId}),renderPrimaryAction:e=>E(je,{addonId:e.addonId}),renderExpandedPanel:e=>E(Me,{addonId:e.addonId})})}function X(e){let{data:t,isLoading:n}=g({addonId:e},{refetchInterval:Y,retry:!1}),r=t?D.safeParse(t):null;return{status:r?.success?r.data:Oe,isLoading:n}}function Ae({addonId:e}){let{status:t}=X(e);return x(C,{children:[E(`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&&x(`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 je({addonId:e}){let r=w(),[i,a]=T(!1),[o,c]=T(null),l=k(),{status:d}=X(e),f=y(()=>{r.invalidateQueries({queryKey:[[`meshNetwork`]]})},[r]),p=s(),m=u({onSuccess:f}),h=t({onSuccess:f}),g=y(async()=>{a(!0);let t={cancelled:!1};c(t);try{let n=await p.mutateAsync({addonId:e});if(t.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!t.cancelled&&(await Le(2e3),!t.cancelled);){let t=await l.trpcClient.meshNetwork.getStatus.query({addonId:e}).catch(()=>null),n=t?D.safeParse(t):null;if(n?.success&&n.data.joined){f();break}if(Date.now()-r>6e5)break}}finally{a(!1),c(null)}},[e,f,p,l]),_=y(()=>{o&&(o.cancelled=!0),a(!1),c(null)},[o]);return E(C,{children:d.joined?x(C,{children:[x(n,{size:`sm`,variant:`secondary`,disabled:m.isPending,onClick:()=>m.mutate({addonId:e}),children:[m.isPending?E(P,{className:`h-3 w-3 animate-spin`}):E(le,{className:`h-3 w-3`}),`Disconnect`]}),x(n,{size:`sm`,variant:`ghost`,disabled:h.isPending,onClick:()=>h.mutate({addonId:e}),children:[h.isPending?E(P,{className:`h-3 w-3 animate-spin`}):E(W,{className:`h-3 w-3`}),`Log out`]})]}):i?x(n,{size:`sm`,variant:`ghost`,onClick:_,children:[E(ue,{className:`h-3 w-3 mr-1`}),` Cancel`]}):x(C,{children:[x(n,{size:`sm`,variant:`primary`,onClick:()=>void g(),children:[E(fe,{className:`h-3 w-3`}),`Connect`]}),x(n,{size:`sm`,variant:`ghost`,disabled:h.isPending,onClick:()=>h.mutate({addonId:e}),children:[h.isPending?E(P,{className:`h-3 w-3 animate-spin`}):E(W,{className:`h-3 w-3`}),`Log out`]})]})})}function Me({addonId:e}){let{status:t}=X(e),n=r({addonId:e},{refetchInterval:De,retry:!1});return x(`div`,{className:`rounded-lg border border-border bg-surface`,children:[x(`div`,{className:`p-4 space-y-4`,children:[t.error&&E(i,{message:t.error}),E(Ne,{status:t}),t.endpoints.length>0&&x(`div`,{className:`space-y-1.5`,children:[E(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Endpoints`}),t.endpoints.map(e=>x(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[x(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${Ee[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?E(F,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),x(`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:[E(L,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),E(`div`,{className:`border-t border-border`,children:E(Fe,{peers:n.data?.peers??[],loading:n.isLoading})})]})}function Ne({status:e}){return E(`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?Pe(e.keyExpiry):`—`}].map(e=>x(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[E(`span`,{className:`text-foreground-subtle shrink-0`,children:e.label}),E(`span`,{className:`text-foreground truncate ${e.mono?`font-mono`:``}`,children:e.value})]},e.label))})}function Pe(e){let t=e-Date.now();if(t<0)return`Expired ${Q(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 Fe({peers:e,loading:t}){let n=S(()=>e.map(e=>({...e,_id:e.id})),[e]),r=y(e=>{e&&navigator.clipboard?.writeText(e)},[]),i=S(()=>[{key:`hostname`,header:`Hostname`,render:e=>x(`div`,{className:`flex flex-col`,children:[x(`div`,{className:`flex items-center gap-1.5`,children:[E(`span`,{className:`font-medium text-foreground`,children:e.hostname||`(unknown)`}),e.isSelf&&E(l,{variant:`info`,children:`self`}),e.exitNodeOption&&E(l,{variant:`warning`,children:`exit-node`})]}),e.userLogin&&E(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.userLogin})]})},{key:`magicDns`,header:`MagicDNS`,render:e=>e.magicDns?x(`div`,{className:`flex items-center gap-1`,children:[E(`span`,{className:`font-mono text-xs truncate`,children:e.magicDns}),E(`button`,{onClick:()=>r(e.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy MagicDNS`,children:E(j,{className:`h-3 w-3 text-foreground-subtle`})})]}):E(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:e=>{let t=e.addresses[0]??``;return t?x(`div`,{className:`flex items-center gap-1`,children:[E(`span`,{className:`font-mono text-xs`,children:t}),E(`button`,{onClick:()=>r(t),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy IP`,children:E(j,{className:`h-3 w-3 text-foreground-subtle`})})]}):E(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:`Connection`,render:e=>x(`div`,{className:`flex items-center gap-1.5`,children:[E(l,{variant:Ie(e.connection),children:e.connection}),e.relay&&E(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.relay})]})},{key:`routes`,header:`Routes`,render:e=>e.advertisedRoutes.length>0?E(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):E(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:`TX / RX`,render:e=>x(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,Z(e.txBytes),` · ↓ `,Z(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>E(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?Q(e.lastSeenMs):`—`})}],[r]);return t&&e.length===0?x(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[E(P,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):e.length===0?E(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No peers visible — your tailnet may be empty or the host is not joined.`}):E(`div`,{className:`p-4`,children:E(m,{columns:i,rows:n,rowKey:e=>e._id,minWidthPx:820})})}function Ie(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function Z(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 Q(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 Le(e){return new Promise(t=>setTimeout(t,e))}function $(){return E(`div`,{className:`flex flex-col p-4`,children:E(H,{tabs:[{id:`addresses`,label:`Network Addresses`,icon:N,content:E(Te,{})},{id:`remote-access`,label:`Remote Access`,icon:F,content:E(he,{})},{id:`mesh`,label:`Mesh Networks`,icon:A,content:E(ke,{})},{id:`turn`,label:`TURN Servers`,icon:z,content:E(ye,{})}]})})}export{$ as NetworkPage};
|
|
1
|
+
import{Cr as e,Dr as t,Eo as n,Er as r,Ha as i,Mr as a,Nr as o,Or as s,Sr as c,To as l,Tr as u,br as d,bt as f,jr as p,no as m,wo as h,wr as g,xa as _,xr as ee,xt as v,yr as te}from"./src-DHFCkQHW.js";import{I as y,Q as b,S as x,W as S,b as C,o as w,q as T,x as E,z as ne}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 D,s as O}from"./src-Cv9CvT8c.js";import{p as k}from"./player-overlays-CpNYQPHP.js";import{n as A,t as re}from"./rotate-ccw-CbpUNSqs.js";import{t as j}from"./copy-UBfFgSz-.js";import{n as ie,t as M}from"./AddonCollectionPage-D4dNkjD9.js";import{t as ae}from"./refresh-cw-hhKexEfo.js";import{t as N}from"./server-BxRe5xIW.js";import{t as oe}from"./square-CEBWDX93.js";import{t as se}from"./wifi-CL8vr9lV.js";import{L as ce,S as P,T as F,W as I,b as le,i as ue,k as L,l as de,o as R,v as z,x as B}from"./index-Cl-M8KBA.js";import{t as V}from"./AdminPage-Dq33XE9j.js";import{t as H}from"./AdminTabs-B6qnIaak.js";import{t as U}from"./addon-display-names-DvSEQty-.js";var fe=I(`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`}]]),pe=I(`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`}]]),W=I(`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`}]]);b();var G=5e3,me={connected:!1,endpoint:null};function he(){let e=w(),t=v({capName:`network-access`},{refetchInterval:G}),n=f(void 0,{refetchInterval:G}),r=S(()=>U(n.data??[]),[n.data]),i=S(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:r.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,r]),[s,c]=T(null),[l,u]=T({}),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})},p=(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=a({onSuccess:d,onError:p}),h=o({onSuccess:d,onError:p});return E(M,{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:F,itemIcon:F,capability:`network-access`,installButtonLabel:`Add tunnel`,items:i,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=>E(ge,{addonId:e.addonId}),itemError:e=>l[e.addonId]??null,renderPrimaryAction:e=>E(_e,{addonId:e.addonId,busyId:s,onStart:e=>{c(e),m.mutate({addonId:e})},onStop:e=>{c(e),h.mutate({addonId:e})}})})}function K(e){let{data:t}=p({addonId:e},{refetchInterval:G,retry:!1}),n=t?O.safeParse(t):null;return n?.success?n.data:me}function ge({addonId:e}){let t=K(e);return x(C,{children:[E(`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&&x(`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:[E(L,{className:`h-3 w-3`}),t.endpoint.url]})]})}function _e({addonId:e,busyId:t,onStart:r,onStop:i}){let a=K(e),o=t===e;return a.connected?x(n,{size:`sm`,variant:`secondary`,disabled:o,onClick:()=>i(e),children:[o?E(P,{className:`h-3 w-3 animate-spin`}):E(oe,{className:`h-3 w-3`}),`Stop`]}):x(n,{size:`sm`,variant:`primary`,disabled:o,onClick:()=>r(e),children:[o?E(P,{className:`h-3 w-3 animate-spin`}):E(ie,{className:`h-3 w-3`}),`Start`]})}b();var q=3e4;function ve(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function ye(){let e=v({capName:`turn-provider`},{refetchInterval:q}),t=f(void 0,{refetchInterval:q}),r=_(),i=r.data??[],a=S(()=>U(t.data??[]),[t.data]);return E(M,{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:z,itemIcon:z,capability:`turn-provider`,installButtonLabel:`Add provider`,items:S(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:a.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,a]),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=>E(be,{addonId:e.addonId,enabled:e.isActive}),trailing:x(h,{children:[x(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[x(`div`,{children:[E(`div`,{className:`text-sm font-semibold`,children:`Combined ICE server list`}),E(`div`,{className:`text-xs text-foreground-subtle`,children:`What the WebRTC layer fetches per-session.`})]}),E(n,{size:`sm`,variant:`secondary`,onClick:()=>r.refetch(),disabled:r.isFetching,children:`Refresh`})]}),E(`div`,{className:`p-4`,children:i.length===0?E(`div`,{className:`text-xs text-foreground-subtle`,children:`No servers from enabled providers.`}):E(`div`,{className:`flex flex-col gap-3`,children:i.map((e,t)=>{let n=Array.isArray(e.urls)?e.urls:[e.urls];return x(`div`,{className:`rounded border border-border bg-surface`,children:[(e.username||e.credential)&&x(`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&&x(`span`,{children:[E(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,E(`span`,{className:`text-foreground`,children:e.username})]}),e.credential&&x(`span`,{children:[E(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,E(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),E(`ul`,{className:`divide-y divide-border`,children:n.map(e=>E(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},t)})})})]})})}function be({addonId:e,enabled:t}){let n=_({addonId:e},{enabled:t,retry:!1}),r=S(()=>ve(n.data??[]),[n.data]);return!t||r.length===0?null:x(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[x(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Discovered ICE servers (`,r.length,`)`]}),E(`div`,{className:`flex flex-wrap gap-1`,children:r.map(e=>E(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground`,children:e},e))})]})}b();var xe={lan:z,wifi:se,docker:A,vpn:B,loopback:N,other:N},Se={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},Ce=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function we(e){let{interfaces:t,disabled:n,hideLoopback:r,ipv4Only:i,emptyMessage:a}=e,o=S(()=>t.filter(e=>!(r&&e.kind===`loopback`||i&&e.family!==`IPv4`)),[t,r,i]),s=S(()=>{let e=new Map;for(let t of o){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return Ce.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?E(`div`,{className:`text-xs text-foreground-subtle italic`,children:a??`No addresses available.`}):E(`div`,{className:`flex flex-col gap-3`,children:s.map(({kind:t,items:r})=>x(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[x(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[E(xe[t]??N,{className:`h-3.5 w-3.5 text-foreground-subtle`}),E(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:Se[t]??t}),x(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,r.length]})]}),E(`ul`,{className:`divide-y divide-border`,children:r.map(t=>{let r=c(t.address),i=t.kind===`loopback`,a=!t.plausible&&!i;return x(`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:[E(`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&&E(ce,{className:`h-3 w-3`})}),x(`div`,{className:`flex-1 min-w-0 ${a?`text-foreground-subtle`:``}`,children:[x(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[E(`span`,{className:`font-mono text-xs font-semibold ${a?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),E(`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&&E(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:`Auto-preferred`}),i&&E(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:`Always included`}),a&&x(`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:[E(R,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]}),x(`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))})}b();var J={"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 Te(){let t=w(),r=k(),i=ee(void 0,{refetchInterval:3e4}),a=te(void 0),o=e({onSuccess:()=>{t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),s=c({onSuccess:e=>{p(e.addresses),t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),l=S(()=>i.data?.interfaces??[],[i.data]),u=d({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}),[f,p]=T([]),[m,g]=T(!1);ne(()=>{!m&&a.data&&(p(a.data.addresses),g(!0))},[a.data,m]);let _=a.data?.addresses??[],v=S(()=>{if(f.length!==_.length)return!0;let e=[...f].toSorted(),t=[..._].toSorted();return e.some((e,n)=>e!==t[n])},[f,_]),y=()=>{o.mutate({addresses:[...f]})},b=()=>{p(_)},C=()=>{p([])},D=()=>{i.refetch(),u.refetch(),a.refetch()},O=async()=>{try{let e=await r.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info(`[network-addresses] race result`,e)}catch(e){console.warn(`[network-addresses] race failed`,e)}},A=u.data?.endpoints??[];return x(V,{children:[x(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[E(`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.`}),x(`div`,{className:`flex items-center gap-2 shrink-0`,children:[x(n,{size:`sm`,variant:`secondary`,onClick:D,disabled:i.isLoading,children:[E(ae,{className:`h-3 w-3 ${i.isLoading?`animate-spin`:``}`}),`Refresh`]}),E(n,{size:`sm`,variant:`secondary`,onClick:O,children:`Probe race`})]})]}),x(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[x(h,{children:[x(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[x(`div`,{children:[E(`div`,{className:`text-sm font-semibold`,children:`Allowed addresses`}),E(`div`,{className:`text-xs text-foreground-subtle`,children:f.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${f.length} pinned`})]}),x(`div`,{className:`flex items-center gap-1`,children:[x(n,{size:`sm`,variant:`secondary`,onClick:()=>s.mutate(void 0),disabled:s.isPending||o.isPending,title:`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`,children:[E(de,{className:`h-3 w-3`}),s.isPending?`Detecting…`:`Best match`]}),x(n,{size:`sm`,variant:`secondary`,onClick:C,disabled:f.length===0||o.isPending,children:[E(re,{className:`h-3 w-3`}),`Clear`]}),v&&E(n,{size:`sm`,variant:`secondary`,onClick:b,disabled:o.isPending,children:`Discard`}),x(n,{size:`sm`,variant:`primary`,onClick:y,disabled:!v||o.isPending,children:[E(pe,{className:`h-3 w-3`}),o.isPending?`Saving…`:`Save`]})]})]}),E(`div`,{className:`p-4`,children:E(we,{mode:`multiple`,interfaces:l,value:f,onChange:p,disabled:o.isPending,emptyMessage:i.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),x(h,{children:[x(`div`,{className:`px-4 py-3 border-b border-border`,children:[E(`div`,{className:`text-sm font-semibold`,children:`Connection endpoints — priority order`}),E(`div`,{className:`text-xs text-foreground-subtle`,children:`Live preview of the ranked candidate list the SDK would race against. Updates with each Save.`})]}),E(`div`,{className:`p-4`,children:A.length===0?E(`div`,{className:`text-xs text-foreground-subtle italic`,children:u.isLoading?`Loading…`:`No endpoints available.`}):E(`ul`,{className:`space-y-1 text-xs`,children:A.map(e=>x(`li`,{className:`flex items-center gap-2 flex-wrap ${e.plausible?``:`opacity-80`}`,children:[E(`span`,{className:`font-mono text-[10px] w-10 text-foreground-subtle`,children:String(e.priority).padStart(4,`0`)}),E(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${J[e.kind]??J.loopback}`,children:e.kind}),e.interfaceKind!==`lan`&&e.interfaceKind!==`public`&&E(`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`&&x(`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:[E(R,{className:`h-2.5 w-2.5`}),`Unlikely usable`]}),E(`span`,{className:`font-mono break-all ${e.plausible?`text-foreground`:`text-foreground-subtle`}`,children:e.baseUrl}),x(`span`,{className:`text-foreground-subtle`,children:[`— `,e.label]})]},`${e.priority}-${e.baseUrl}`))})})]})]})]})}b();var Ee={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},Y=5e3,De=3e4,Oe={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function ke(){let e=v({capName:`mesh-network`},{refetchInterval:Y}),t=f(void 0,{refetchInterval:Y}),n=S(()=>U(t.data??[]),[t.data]);return E(M,{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:A,itemIcon:z,capability:`mesh-network`,installButtonLabel:`Add mesh`,items:S(()=>(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=>E(Ae,{addonId:e.addonId}),renderPrimaryAction:e=>E(je,{addonId:e.addonId}),renderExpandedPanel:e=>E(Me,{addonId:e.addonId})})}function X(e){let{data:t,isLoading:n}=g({addonId:e},{refetchInterval:Y,retry:!1}),r=t?D.safeParse(t):null;return{status:r?.success?r.data:Oe,isLoading:n}}function Ae({addonId:e}){let{status:t}=X(e);return x(C,{children:[E(`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&&x(`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 je({addonId:e}){let r=w(),[i,a]=T(!1),[o,c]=T(null),l=k(),{status:d}=X(e),f=y(()=>{r.invalidateQueries({queryKey:[[`meshNetwork`]]})},[r]),p=s(),m=u({onSuccess:f}),h=t({onSuccess:f}),g=y(async()=>{a(!0);let t={cancelled:!1};c(t);try{let n=await p.mutateAsync({addonId:e});if(t.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!t.cancelled&&(await Le(2e3),!t.cancelled);){let t=await l.trpcClient.meshNetwork.getStatus.query({addonId:e}).catch(()=>null),n=t?D.safeParse(t):null;if(n?.success&&n.data.joined){f();break}if(Date.now()-r>6e5)break}}finally{a(!1),c(null)}},[e,f,p,l]),_=y(()=>{o&&(o.cancelled=!0),a(!1),c(null)},[o]);return E(C,{children:d.joined?x(C,{children:[x(n,{size:`sm`,variant:`secondary`,disabled:m.isPending,onClick:()=>m.mutate({addonId:e}),children:[m.isPending?E(P,{className:`h-3 w-3 animate-spin`}):E(le,{className:`h-3 w-3`}),`Disconnect`]}),x(n,{size:`sm`,variant:`ghost`,disabled:h.isPending,onClick:()=>h.mutate({addonId:e}),children:[h.isPending?E(P,{className:`h-3 w-3 animate-spin`}):E(W,{className:`h-3 w-3`}),`Log out`]})]}):i?x(n,{size:`sm`,variant:`ghost`,onClick:_,children:[E(ue,{className:`h-3 w-3 mr-1`}),` Cancel`]}):x(C,{children:[x(n,{size:`sm`,variant:`primary`,onClick:()=>void g(),children:[E(fe,{className:`h-3 w-3`}),`Connect`]}),x(n,{size:`sm`,variant:`ghost`,disabled:h.isPending,onClick:()=>h.mutate({addonId:e}),children:[h.isPending?E(P,{className:`h-3 w-3 animate-spin`}):E(W,{className:`h-3 w-3`}),`Log out`]})]})})}function Me({addonId:e}){let{status:t}=X(e),n=r({addonId:e},{refetchInterval:De,retry:!1});return x(`div`,{className:`rounded-lg border border-border bg-surface`,children:[x(`div`,{className:`p-4 space-y-4`,children:[t.error&&E(i,{message:t.error}),E(Ne,{status:t}),t.endpoints.length>0&&x(`div`,{className:`space-y-1.5`,children:[E(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Endpoints`}),t.endpoints.map(e=>x(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[x(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${Ee[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?E(F,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),x(`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:[E(L,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),E(`div`,{className:`border-t border-border`,children:E(Fe,{peers:n.data?.peers??[],loading:n.isLoading})})]})}function Ne({status:e}){return E(`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?Pe(e.keyExpiry):`—`}].map(e=>x(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[E(`span`,{className:`text-foreground-subtle shrink-0`,children:e.label}),E(`span`,{className:`text-foreground truncate ${e.mono?`font-mono`:``}`,children:e.value})]},e.label))})}function Pe(e){let t=e-Date.now();if(t<0)return`Expired ${Q(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 Fe({peers:e,loading:t}){let n=S(()=>e.map(e=>({...e,_id:e.id})),[e]),r=y(e=>{e&&navigator.clipboard?.writeText(e)},[]),i=S(()=>[{key:`hostname`,header:`Hostname`,render:e=>x(`div`,{className:`flex flex-col`,children:[x(`div`,{className:`flex items-center gap-1.5`,children:[E(`span`,{className:`font-medium text-foreground`,children:e.hostname||`(unknown)`}),e.isSelf&&E(l,{variant:`info`,children:`self`}),e.exitNodeOption&&E(l,{variant:`warning`,children:`exit-node`})]}),e.userLogin&&E(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.userLogin})]})},{key:`magicDns`,header:`MagicDNS`,render:e=>e.magicDns?x(`div`,{className:`flex items-center gap-1`,children:[E(`span`,{className:`font-mono text-xs truncate`,children:e.magicDns}),E(`button`,{onClick:()=>r(e.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy MagicDNS`,children:E(j,{className:`h-3 w-3 text-foreground-subtle`})})]}):E(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:e=>{let t=e.addresses[0]??``;return t?x(`div`,{className:`flex items-center gap-1`,children:[E(`span`,{className:`font-mono text-xs`,children:t}),E(`button`,{onClick:()=>r(t),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy IP`,children:E(j,{className:`h-3 w-3 text-foreground-subtle`})})]}):E(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:`Connection`,render:e=>x(`div`,{className:`flex items-center gap-1.5`,children:[E(l,{variant:Ie(e.connection),children:e.connection}),e.relay&&E(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.relay})]})},{key:`routes`,header:`Routes`,render:e=>e.advertisedRoutes.length>0?E(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):E(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:`TX / RX`,render:e=>x(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,Z(e.txBytes),` · ↓ `,Z(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>E(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?Q(e.lastSeenMs):`—`})}],[r]);return t&&e.length===0?x(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[E(P,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):e.length===0?E(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No peers visible — your tailnet may be empty or the host is not joined.`}):E(`div`,{className:`p-4`,children:E(m,{columns:i,rows:n,rowKey:e=>e._id,minWidthPx:820})})}function Ie(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function Z(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 Q(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 Le(e){return new Promise(t=>setTimeout(t,e))}function $(){return E(`div`,{className:`flex flex-col p-4`,children:E(H,{tabs:[{id:`addresses`,label:`Network Addresses`,icon:N,content:E(Te,{})},{id:`remote-access`,label:`Remote Access`,icon:F,content:E(he,{})},{id:`mesh`,label:`Mesh Networks`,icon:A,content:E(ke,{})},{id:`turn`,label:`TURN Servers`,icon:z,content:E(ye,{})}]})})}export{$ as NetworkPage};
|
package/dist/assets/{NodeAddonsSettingsPanel-Vn552ZEg.js → NodeAddonsSettingsPanel-CgGvimGW.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{bt as e,dt as t,ft as n,on as r,zt as i}from"./src-DyTBJAFT.js";import{H as a,I as o,K as s,Q as c,S as l,W as u,i as d,k as f,o as p,p as m,q as h,t as g,x as _,z as v}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{W as y}from"./src-Cv9CvT8c.js";import{p as ee}from"./player-overlays-CpNYQPHP.js";import{t as b}from"./FormBuilder-Bc2pF861.js";import{n as te,r as x,t as ne}from"./SchemaTabBar-BrF8ZUiR.js";import{t as re}from"./StableTabPanel-p16epZGa.js";c();var S=f(function({addonId:e,schema:t,serverValues:n,onImmediateSave:r,onStateChange:i,onAction:c,disabled:l},d){let f=x({schema:t,serverValues:n,onImmediateSave:o(t=>r(e,t),[e,r]),onDeferredSave:o(()=>{},[])});a(d,()=>({flush:()=>{let e={};for(let t of f.pendingKeys)e[t]=f.values[t];return f.handleDiscard(f.pendingKeys),e},discard:()=>f.resetAll()}),[f]);let p=f.pendingKeys,m=p.join(`|`),h=u(()=>p.map(e=>`${e}=${JSON.stringify(f.values[e])}`).join(`,`),[p,f.values]),g=s(i);v(()=>{g.current=i},[i]),v(()=>{let t={};for(let e of p)t[e]=f.values[e];g.current({addonId:e,pendingKeys:p,pendingValues:t})},[e,m,h]);let y=u(()=>{if(c)return(t,n,r)=>c(e,t,n,r)},[e,c]);return _(b,{schema:t,values:f.values,onChange:f.handleChange,disabled:l,onAction:y})});c();function C(e,t){if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`){let n=e.fields.map(e=>C(e,t));return{...e,fields:n}}let n=e;t[e.key]=n.value;let{value:r,...i}=n;return i}function w(e,t){return{...e,fields:e.fields.map(e=>C(e,t))}}function ie(e){let t={};return{schema:{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>w(e,t))},values:t}}function T({nodeId:a,addonIds:c,level:f,deviceId:v,capability:b,sectionIds:x,sectionTab:S,extraTabs:C,schemaTabExtras:w,title:T,description:E,selfTabbed:oe}){let D=p(),O=ee().trpcClient,k=n(),A=t(),j=r(),M=i(),N=oe===!0||!!(C&&C.length>0),[P,se]=h(null);if(f===`device`&&!v)throw Error(`NodeAddonsSettingsPanel: deviceId is required when level === "device"`);let F=a??`hub`,I=d({queries:c.map(e=>({queryKey:[[`addonSettings`,f===`global`?`getGlobalSettings`:`getDeviceSettings`],{addonId:e,nodeId:F,deviceId:v??null,cap:b??null}],queryFn:async()=>f===`global`?{addonId:e,result:await O.addonSettings.getGlobalSettings.query({addonId:e,nodeId:F,...b?{cap:b}:{}})}:{addonId:e,result:await O.addonSettings.getDeviceSettings.query({addonId:e,deviceId:v,nodeId:F})},placeholderData:m}))}),L=I.some(e=>e.isLoading),R=I.map(e=>{if(!e.data)return`-`;if(e.data.result===null)return`${e.data.addonId}:n`;let t=[];for(let n of e.data.result.sections){t.push(`s:${n.id}:${n.tab??`general`}`);for(let e of n.fields){if(!(`key`in e))continue;let n=`options`in e&&Array.isArray(e.options)?e.options.map(e=>e.value).join(`,`):``,r=e.value,i=r===void 0?``:typeof r==`string`?r:JSON.stringify(r);t.push(`f:${e.key}:${n}:${i}`)}}return`${e.data.addonId}:${t.join(`|`)}`}).join(`||`),z=u(()=>{let e=new Set;for(let t of I){let n=t.data?.result?.sections;if(n)for(let t of n)e.add(t.tab??`general`)}return[...e]},[R+`::`+I.map(e=>(e.data?.result?.sections??[]).map(e=>e.tab??`general`).join(`,`)).join(`::`)]),B=u(()=>new Map((C??[]).map(e=>[e.id,e])),[C]),V=u(()=>{if(!N)return[];let e=[...new Set([...z,...(C??[]).map(e=>e.id),...(w??[]).map(e=>e.tabId)])],t=e=>{let t=B.get(e);if(t?.order!==void 0)return t.order;let n=y[e];return n?n.order:50};return e.toSorted((e,n)=>{let r=t(e),i=t(n);return r===i?e.localeCompare(n):r-i})},[N,z,C,B,w]),ce=u(()=>{let e=new Map,t=e=>y[e]?.label??e.charAt(0).toUpperCase()+e.slice(1);for(let n of z)e.set(n,t(n));for(let n of w??[])e.has(n.tabId)||e.set(n.tabId,t(n.tabId));for(let t of C??[])e.set(t.id,t.label);return e},[z,C,w]),H=N?P&&V.includes(P)?P:V[0]??null:null,U=H!==null&&B.has(H),W=N?H&&!U?H:void 0:S,{data:G}=e(void 0),le=u(()=>{let e=new Map;for(let t of G??[]){let n=t.manifest?.id;if(!n)continue;let r=t.manifest?.name??t.manifest?.packageDisplayName??n;e.set(n,r)}return e},[G]),K=s(new Map),q=u(()=>{let e=x?new Set(x):null,t=[];for(let n of I){if(!n.data)continue;let r=n.data.result??K.current.get(n.data.addonId)??null;if(n.data.result!==null&&K.current.set(n.data.addonId,n.data.result),r===null)continue;let{schema:i,values:a}=ie(r),o=i.sections.filter(t=>e?e.has(t.id):!0);if(o.length===0)continue;let s={...r,sections:r.sections.filter(t=>e?e.has(t.id):!0)},c={...i,sections:o};t.push({addonId:n.data.addonId,schemaWithValues:s,schema:c,serverValues:a})}return t},[R,x]),[J,ue]=h(new Map),de=o(e=>{ue(t=>{let n=new Map(t);return n.set(e.addonId,e),n})},[]),Y=s(new Map),fe=o(e=>t=>{t?Y.current.set(e,t):Y.current.delete(e)},[]),X=o(async(e,t)=>{f===`global`?await k.mutateAsync({addonId:e,nodeId:F,patch:t}):await A.mutateAsync({addonId:e,deviceId:v,nodeId:F,patch:t}),D.invalidateQueries({queryKey:[[`addonSettings`]]})},[k,A,F,f,v,D]),pe=o(async(e,t,n,r)=>{let i=F;try{switch(t){case`reprobe-hwaccel`:await j.mutateAsync({nodeId:i}),D.invalidateQueries({queryKey:[[`addonSettings`]]});return;case`reprobe-audio-engine`:await M.mutateAsync({nodeId:i}),D.invalidateQueries({queryKey:[[`addonSettings`]]});return;default:{let n=await O.addons.custom.mutate({addonId:e,action:t,input:r});return D.invalidateQueries({queryKey:[[`addonSettings`]]}),n}}}catch(n){throw console.error(`[NodeAddonsSettingsPanel] action failed`,{addonId:e,action:t,err:n}),n}},[j,M,F,D,O]),me=o((e,t)=>{X(e,t)},[X]),Z=g({mutationFn:async()=>{let e=[];for(let t of q){let n=J.get(t.addonId);!n||n.pendingKeys.length===0||e.push({addonId:t.addonId,patch:n.pendingValues})}return e.length===0?{saved:[]}:{saved:await Promise.all(e.map(async({addonId:e,patch:t})=>(f===`global`?await k.mutateAsync({addonId:e,nodeId:F,patch:t}):await A.mutateAsync({addonId:e,deviceId:v,nodeId:F,patch:t}),e)))}},onSuccess:({saved:e})=>{for(let t of e)Y.current.get(t)?.discard();D.invalidateQueries({queryKey:[[`addonSettings`]]})}}),he=o(()=>{for(let e of Y.current.values())e.discard()},[]),ge=u(()=>{let e=0;for(let t of q){let n=J.get(t.addonId);n&&(e+=n.pendingKeys.length)}return e},[q,J]),_e=u(()=>{let e=new Map;for(let t of q){let n=J.get(t.addonId);if(!n||n.pendingKeys.length===0)continue;let r=new Set(n.pendingKeys);for(let n of t.schema.sections){let t=n.tab??`general`;for(let i of n.fields)`key`in i&&r.has(i.key)&&e.set(t,(e.get(t)??0)+1)}}return e},[q,J]);if(L)return _(`div`,{className:`h-24 rounded-lg border border-border bg-surface animate-pulse`});let Q=H&&U?B.get(H):void 0;if(!N&&q.length===0)return l(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:[`No addons in `,c.length>0?`[${c.join(`, `)}]`:`the current selection`,` `,`expose `,f,`-level settings on this node.`]});let $=Z.isPending;return l(`div`,{className:`space-y-4`,children:[(T||E)&&l(`div`,{className:`border-b border-border pb-2`,children:[T&&_(`h2`,{className:`text-sm font-semibold text-foreground`,children:T}),E&&_(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:E})]}),N&&_(ne,{tabs:V.map(e=>({id:e,label:ce.get(e)??e})),activeId:H,onChange:se,pendingByTab:_e}),Z.isError&&l(`div`,{className:`rounded-md border border-red-500/40 bg-red-500/10 px-3 py-2 text-[11px] text-red-400`,children:[`Save failed: `,String(Z.error?.message??Z.error)]}),_(re,{tabKey:Q?`extra:${H??``}`:`tab:${H??``}`,children:Q?Q.content:(()=>{let e=W?q.reduce((e,t)=>e+t.schemaWithValues.sections.filter(e=>(e.tab??`general`)===W).length,0):0,t=W!==null&&e<=1,n=q.map(e=>({...e,renderedWithValues:{...e.schemaWithValues,sections:e.schemaWithValues.sections.filter(e=>W?(e.tab??`general`)===W:!0).map(e=>t?{...e,title:``,description:void 0}:e)}})).filter(e=>e.renderedWithValues.sections.length>0).toSorted((e,t)=>{let n=e=>{let t=1/0;for(let n of e)typeof n.order==`number`&&n.order<t&&(t=n.order);return t},r=n(e.renderedWithValues.sections),i=n(t.renderedWithValues.sections);return r===i?0:r-i}),r=(w??[]).filter(e=>e.tabId===W),i=r.filter(e=>(e.placement??`before`)===`before`),a=r.filter(e=>e.placement===`after`);return n.length===0&&r.length===0?_(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:`Nothing to configure here for this node.`}):l(`div`,{className:`space-y-6`,children:[i.map((e,t)=>_(`div`,{children:e.content},`extra-before-${t}`)),n.length>0&&_(ae,{entries:n,paneStates:J,displayNames:le,disabled:$,setPaneRef:fe,onPaneStateChange:de,onImmediateSave:me,onAction:pe,inline:N||!!S}),a.map((e,t)=>_(`div`,{children:e.content},`extra-after-${t}`))]})})()}),!L&&_(te,{pendingCount:ge,onSave:()=>Z.mutate(),onDiscard:he,saving:$})]})}function ae({entries:e,paneStates:t,displayNames:n,disabled:r,setPaneRef:i,onPaneStateChange:a,onImmediateSave:o,onAction:s,inline:c}){let d=u(()=>[...e].toSorted((e,t)=>{if(e.addonId===`system-config`)return-1;if(t.addonId===`system-config`)return 1;let r=n.get(e.addonId)??e.addonId,i=n.get(t.addonId)??t.addonId;return r.localeCompare(i)}),[e,n]),[f,p]=h(d[0]?.addonId??``);v(()=>{d.length!==0&&(d.find(e=>e.addonId===f)||p(d[0].addonId))},[d,f]);let m=d.find(e=>e.addonId===f)??d[0];if(!m)return null;let g=u(()=>s?(e,t,n,r)=>s(e,t,n,r):void 0,[s]),y=e=>_(S,{ref:i(e.addonId),addonId:e.addonId,schema:e.renderedWithValues,serverValues:e.serverValues,onImmediateSave:o,onStateChange:a,onAction:g,disabled:r},e.addonId);return d.length===1||c?_(`div`,{className:`flex flex-col gap-4`,children:d.map(y)}):l(`div`,{className:`flex flex-col gap-3`,children:[_(`div`,{className:`flex flex-wrap items-center gap-1 border-b border-border shrink-0`,children:d.map(e=>{let r=n.get(e.addonId)??e.addonId,i=e.addonId===m.addonId,a=(t.get(e.addonId)?.pendingKeys.length??0)>0;return l(`button`,{type:`button`,onClick:()=>p(e.addonId),className:`relative px-3 py-1.5 text-xs font-medium rounded-t-md transition-colors -mb-px border-b-2 whitespace-nowrap ${i?`text-primary border-primary bg-primary/5`:`text-foreground-subtle border-transparent hover:text-foreground hover:bg-surface-hover`}`,children:[r,a&&_(`span`,{className:`ml-1.5 inline-flex h-1.5 w-1.5 rounded-full bg-amber-400`})]},e.addonId)})}),_(`div`,{className:`space-y-2`,children:d.map(e=>_(`div`,{style:e.addonId===m.addonId?void 0:{display:`none`},children:y(e)},e.addonId))})]})}export{T as t};
|
|
1
|
+
import{bt as e,dt as t,ft as n,on as r,zt as i}from"./src-DHFCkQHW.js";import{H as a,I as o,K as s,Q as c,S as l,W as u,i as d,k as f,o as p,p as m,q as h,t as g,x as _,z as v}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{W as y}from"./src-Cv9CvT8c.js";import{p as ee}from"./player-overlays-CpNYQPHP.js";import{t as b}from"./FormBuilder-CMFZXwvq.js";import{n as te,r as x,t as ne}from"./SchemaTabBar-BrF8ZUiR.js";import{t as re}from"./StableTabPanel-p16epZGa.js";c();var S=f(function({addonId:e,schema:t,serverValues:n,onImmediateSave:r,onStateChange:i,onAction:c,disabled:l},d){let f=x({schema:t,serverValues:n,onImmediateSave:o(t=>r(e,t),[e,r]),onDeferredSave:o(()=>{},[])});a(d,()=>({flush:()=>{let e={};for(let t of f.pendingKeys)e[t]=f.values[t];return f.handleDiscard(f.pendingKeys),e},discard:()=>f.resetAll()}),[f]);let p=f.pendingKeys,m=p.join(`|`),h=u(()=>p.map(e=>`${e}=${JSON.stringify(f.values[e])}`).join(`,`),[p,f.values]),g=s(i);v(()=>{g.current=i},[i]),v(()=>{let t={};for(let e of p)t[e]=f.values[e];g.current({addonId:e,pendingKeys:p,pendingValues:t})},[e,m,h]);let y=u(()=>{if(c)return(t,n,r)=>c(e,t,n,r)},[e,c]);return _(b,{schema:t,values:f.values,onChange:f.handleChange,disabled:l,onAction:y})});c();function C(e,t){if(e.type===`separator`||e.type===`info`||e.type===`button`)return e;if(e.type===`group`){let n=e.fields.map(e=>C(e,t));return{...e,fields:n}}let n=e;t[e.key]=n.value;let{value:r,...i}=n;return i}function w(e,t){return{...e,fields:e.fields.map(e=>C(e,t))}}function ie(e){let t={};return{schema:{...e.tabs?{tabs:e.tabs}:{},sections:e.sections.map(e=>w(e,t))},values:t}}function T({nodeId:a,addonIds:c,level:f,deviceId:v,capability:b,sectionIds:x,sectionTab:S,extraTabs:C,schemaTabExtras:w,title:T,description:E,selfTabbed:oe}){let D=p(),O=ee().trpcClient,k=n(),A=t(),j=r(),M=i(),N=oe===!0||!!(C&&C.length>0),[P,se]=h(null);if(f===`device`&&!v)throw Error(`NodeAddonsSettingsPanel: deviceId is required when level === "device"`);let F=a??`hub`,I=d({queries:c.map(e=>({queryKey:[[`addonSettings`,f===`global`?`getGlobalSettings`:`getDeviceSettings`],{addonId:e,nodeId:F,deviceId:v??null,cap:b??null}],queryFn:async()=>f===`global`?{addonId:e,result:await O.addonSettings.getGlobalSettings.query({addonId:e,nodeId:F,...b?{cap:b}:{}})}:{addonId:e,result:await O.addonSettings.getDeviceSettings.query({addonId:e,deviceId:v,nodeId:F})},placeholderData:m}))}),L=I.some(e=>e.isLoading),R=I.map(e=>{if(!e.data)return`-`;if(e.data.result===null)return`${e.data.addonId}:n`;let t=[];for(let n of e.data.result.sections){t.push(`s:${n.id}:${n.tab??`general`}`);for(let e of n.fields){if(!(`key`in e))continue;let n=`options`in e&&Array.isArray(e.options)?e.options.map(e=>e.value).join(`,`):``,r=e.value,i=r===void 0?``:typeof r==`string`?r:JSON.stringify(r);t.push(`f:${e.key}:${n}:${i}`)}}return`${e.data.addonId}:${t.join(`|`)}`}).join(`||`),z=u(()=>{let e=new Set;for(let t of I){let n=t.data?.result?.sections;if(n)for(let t of n)e.add(t.tab??`general`)}return[...e]},[R+`::`+I.map(e=>(e.data?.result?.sections??[]).map(e=>e.tab??`general`).join(`,`)).join(`::`)]),B=u(()=>new Map((C??[]).map(e=>[e.id,e])),[C]),V=u(()=>{if(!N)return[];let e=[...new Set([...z,...(C??[]).map(e=>e.id),...(w??[]).map(e=>e.tabId)])],t=e=>{let t=B.get(e);if(t?.order!==void 0)return t.order;let n=y[e];return n?n.order:50};return e.toSorted((e,n)=>{let r=t(e),i=t(n);return r===i?e.localeCompare(n):r-i})},[N,z,C,B,w]),ce=u(()=>{let e=new Map,t=e=>y[e]?.label??e.charAt(0).toUpperCase()+e.slice(1);for(let n of z)e.set(n,t(n));for(let n of w??[])e.has(n.tabId)||e.set(n.tabId,t(n.tabId));for(let t of C??[])e.set(t.id,t.label);return e},[z,C,w]),H=N?P&&V.includes(P)?P:V[0]??null:null,U=H!==null&&B.has(H),W=N?H&&!U?H:void 0:S,{data:G}=e(void 0),le=u(()=>{let e=new Map;for(let t of G??[]){let n=t.manifest?.id;if(!n)continue;let r=t.manifest?.name??t.manifest?.packageDisplayName??n;e.set(n,r)}return e},[G]),K=s(new Map),q=u(()=>{let e=x?new Set(x):null,t=[];for(let n of I){if(!n.data)continue;let r=n.data.result??K.current.get(n.data.addonId)??null;if(n.data.result!==null&&K.current.set(n.data.addonId,n.data.result),r===null)continue;let{schema:i,values:a}=ie(r),o=i.sections.filter(t=>e?e.has(t.id):!0);if(o.length===0)continue;let s={...r,sections:r.sections.filter(t=>e?e.has(t.id):!0)},c={...i,sections:o};t.push({addonId:n.data.addonId,schemaWithValues:s,schema:c,serverValues:a})}return t},[R,x]),[J,ue]=h(new Map),de=o(e=>{ue(t=>{let n=new Map(t);return n.set(e.addonId,e),n})},[]),Y=s(new Map),fe=o(e=>t=>{t?Y.current.set(e,t):Y.current.delete(e)},[]),X=o(async(e,t)=>{f===`global`?await k.mutateAsync({addonId:e,nodeId:F,patch:t}):await A.mutateAsync({addonId:e,deviceId:v,nodeId:F,patch:t}),D.invalidateQueries({queryKey:[[`addonSettings`]]})},[k,A,F,f,v,D]),pe=o(async(e,t,n,r)=>{let i=F;try{switch(t){case`reprobe-hwaccel`:await j.mutateAsync({nodeId:i}),D.invalidateQueries({queryKey:[[`addonSettings`]]});return;case`reprobe-audio-engine`:await M.mutateAsync({nodeId:i}),D.invalidateQueries({queryKey:[[`addonSettings`]]});return;default:{let n=await O.addons.custom.mutate({addonId:e,action:t,input:r});return D.invalidateQueries({queryKey:[[`addonSettings`]]}),n}}}catch(n){throw console.error(`[NodeAddonsSettingsPanel] action failed`,{addonId:e,action:t,err:n}),n}},[j,M,F,D,O]),me=o((e,t)=>{X(e,t)},[X]),Z=g({mutationFn:async()=>{let e=[];for(let t of q){let n=J.get(t.addonId);!n||n.pendingKeys.length===0||e.push({addonId:t.addonId,patch:n.pendingValues})}return e.length===0?{saved:[]}:{saved:await Promise.all(e.map(async({addonId:e,patch:t})=>(f===`global`?await k.mutateAsync({addonId:e,nodeId:F,patch:t}):await A.mutateAsync({addonId:e,deviceId:v,nodeId:F,patch:t}),e)))}},onSuccess:({saved:e})=>{for(let t of e)Y.current.get(t)?.discard();D.invalidateQueries({queryKey:[[`addonSettings`]]})}}),he=o(()=>{for(let e of Y.current.values())e.discard()},[]),ge=u(()=>{let e=0;for(let t of q){let n=J.get(t.addonId);n&&(e+=n.pendingKeys.length)}return e},[q,J]),_e=u(()=>{let e=new Map;for(let t of q){let n=J.get(t.addonId);if(!n||n.pendingKeys.length===0)continue;let r=new Set(n.pendingKeys);for(let n of t.schema.sections){let t=n.tab??`general`;for(let i of n.fields)`key`in i&&r.has(i.key)&&e.set(t,(e.get(t)??0)+1)}}return e},[q,J]);if(L)return _(`div`,{className:`h-24 rounded-lg border border-border bg-surface animate-pulse`});let Q=H&&U?B.get(H):void 0;if(!N&&q.length===0)return l(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:[`No addons in `,c.length>0?`[${c.join(`, `)}]`:`the current selection`,` `,`expose `,f,`-level settings on this node.`]});let $=Z.isPending;return l(`div`,{className:`space-y-4`,children:[(T||E)&&l(`div`,{className:`border-b border-border pb-2`,children:[T&&_(`h2`,{className:`text-sm font-semibold text-foreground`,children:T}),E&&_(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:E})]}),N&&_(ne,{tabs:V.map(e=>({id:e,label:ce.get(e)??e})),activeId:H,onChange:se,pendingByTab:_e}),Z.isError&&l(`div`,{className:`rounded-md border border-red-500/40 bg-red-500/10 px-3 py-2 text-[11px] text-red-400`,children:[`Save failed: `,String(Z.error?.message??Z.error)]}),_(re,{tabKey:Q?`extra:${H??``}`:`tab:${H??``}`,children:Q?Q.content:(()=>{let e=W?q.reduce((e,t)=>e+t.schemaWithValues.sections.filter(e=>(e.tab??`general`)===W).length,0):0,t=W!==null&&e<=1,n=q.map(e=>({...e,renderedWithValues:{...e.schemaWithValues,sections:e.schemaWithValues.sections.filter(e=>W?(e.tab??`general`)===W:!0).map(e=>t?{...e,title:``,description:void 0}:e)}})).filter(e=>e.renderedWithValues.sections.length>0).toSorted((e,t)=>{let n=e=>{let t=1/0;for(let n of e)typeof n.order==`number`&&n.order<t&&(t=n.order);return t},r=n(e.renderedWithValues.sections),i=n(t.renderedWithValues.sections);return r===i?0:r-i}),r=(w??[]).filter(e=>e.tabId===W),i=r.filter(e=>(e.placement??`before`)===`before`),a=r.filter(e=>e.placement===`after`);return n.length===0&&r.length===0?_(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:`Nothing to configure here for this node.`}):l(`div`,{className:`space-y-6`,children:[i.map((e,t)=>_(`div`,{children:e.content},`extra-before-${t}`)),n.length>0&&_(ae,{entries:n,paneStates:J,displayNames:le,disabled:$,setPaneRef:fe,onPaneStateChange:de,onImmediateSave:me,onAction:pe,inline:N||!!S}),a.map((e,t)=>_(`div`,{children:e.content},`extra-after-${t}`))]})})()}),!L&&_(te,{pendingCount:ge,onSave:()=>Z.mutate(),onDiscard:he,saving:$})]})}function ae({entries:e,paneStates:t,displayNames:n,disabled:r,setPaneRef:i,onPaneStateChange:a,onImmediateSave:o,onAction:s,inline:c}){let d=u(()=>[...e].toSorted((e,t)=>{if(e.addonId===`system-config`)return-1;if(t.addonId===`system-config`)return 1;let r=n.get(e.addonId)??e.addonId,i=n.get(t.addonId)??t.addonId;return r.localeCompare(i)}),[e,n]),[f,p]=h(d[0]?.addonId??``);v(()=>{d.length!==0&&(d.find(e=>e.addonId===f)||p(d[0].addonId))},[d,f]);let m=d.find(e=>e.addonId===f)??d[0];if(!m)return null;let g=u(()=>s?(e,t,n,r)=>s(e,t,n,r):void 0,[s]),y=e=>_(S,{ref:i(e.addonId),addonId:e.addonId,schema:e.renderedWithValues,serverValues:e.serverValues,onImmediateSave:o,onStateChange:a,onAction:g,disabled:r},e.addonId);return d.length===1||c?_(`div`,{className:`flex flex-col gap-4`,children:d.map(y)}):l(`div`,{className:`flex flex-col gap-3`,children:[_(`div`,{className:`flex flex-wrap items-center gap-1 border-b border-border shrink-0`,children:d.map(e=>{let r=n.get(e.addonId)??e.addonId,i=e.addonId===m.addonId,a=(t.get(e.addonId)?.pendingKeys.length??0)>0;return l(`button`,{type:`button`,onClick:()=>p(e.addonId),className:`relative px-3 py-1.5 text-xs font-medium rounded-t-md transition-colors -mb-px border-b-2 whitespace-nowrap ${i?`text-primary border-primary bg-primary/5`:`text-foreground-subtle border-transparent hover:text-foreground hover:bg-surface-hover`}`,children:[r,a&&_(`span`,{className:`ml-1.5 inline-flex h-1.5 w-1.5 rounded-full bg-amber-400`})]},e.addonId)})}),_(`div`,{className:`space-y-2`,children:d.map(e=>_(`div`,{style:e.addonId===m.addonId?void 0:{display:`none`},children:y(e)},e.addonId))})]})}export{T as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{En as e,Ti as t,To as n,jn as r,mi as i,wn as a,xo as o}from"./src-DyTBJAFT.js";import{K as s,Q as c,S as l,W as u,b as d,o as f,q as p,x as m,z as h}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 g}from"./zap-BVDN24DL.js";import{P as _,W as v,a as y,j as b,x}from"./index-DYyqoGLR.js";var S=v(`circuit-board`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M11 9h4a2 2 0 0 0 2-2V3`,key:`1ve2rv`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`M7 21v-4a2 2 0 0 1 2-2h4`,key:`1fwkro`}],[`circle`,{cx:`15`,cy:`15`,r:`2`,key:`3i40o0`}]]),C=v(`layers`,[[`path`,{d:`M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z`,key:`zw3jo`}],[`path`,{d:`M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12`,key:`1wduqc`}],[`path`,{d:`M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17`,key:`kqbvx6`}]]),w=v(`lock-open`,[[`rect`,{width:`18`,height:`11`,x:`3`,y:`11`,rx:`2`,ry:`2`,key:`1w4ew1`}],[`path`,{d:`M7 11V7a5 5 0 0 1 9.9-1`,key:`1mm8w8`}]]),T=v(`minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),E=v(`scale`,[[`path`,{d:`m16 16 3-8 3 8c-.87.65-1.92 1-3 1s-2.13-.35-3-1Z`,key:`7g6ntu`}],[`path`,{d:`m2 16 3-8 3 8c-.87.65-1.92 1-3 1s-2.13-.35-3-1Z`,key:`ijws7r`}],[`path`,{d:`M7 21h10`,key:`1b0cd5`}],[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`M3 7h2c2 0 5-1 7-2 2 1 5 2 7 2h2`,key:`3gwbw2`}]]),D=v(`usb`,[[`circle`,{cx:`10`,cy:`7`,r:`1`,key:`dypaad`}],[`circle`,{cx:`4`,cy:`20`,r:`1`,key:`22iqad`}],[`path`,{d:`M4.7 19.3 19 5`,key:`1enqfc`}],[`path`,{d:`m21 3-3 1 2 2Z`,key:`d3ov82`}],[`path`,{d:`M9.26 7.68 5 12l2 5`,key:`1esawj`}],[`path`,{d:`m10 14 5 2 3.5-3.5`,key:`v8oal5`}],[`path`,{d:`m18 12 1-1 1 1-1 1Z`,key:`1bh22v`}]]);c();function O(e){return r({addonId:e})}function k(t){return e({deviceId:t},{enabled:Number.isFinite(t)})}var A=3e4,j=2e3;function M(e){let t=s(0);return t.current===0&&(t.current=Date.now()),a({parentDeviceId:e},{enabled:Number.isFinite(e),staleTime:0,refetchOnMount:`always`,refetchInterval:e=>{let n=e.state.data;return n&&n.length>0||Date.now()-t.current>=A?!1:j}})}c();function N(e,t,n){return Math.min(Math.max(e,t),n)}function P(e){let t=e.reduce((e,t)=>e+Math.max(t.weight,0),0);if(t<=0){let t=e.length>0?100/e.length:0;return Object.fromEntries(e.map(e=>[e.id,t]))}return Object.fromEntries(e.map(e=>[e.id,Math.max(e.weight,0)/t*100]))}function F(e,t,n,r,i){let a=i.filter(e=>e!==t&&r.has(e)).reduce((t,n)=>t+Math.max(e[n]??0,0),0),o=Math.max(0,100-a),s=i.filter(e=>e!==t&&!r.has(e)),c=s.length===0?o:N(n,0,o),l={...e,[t]:c};if(s.length>0){let e=Math.max(0,o-c)/s.length;for(let t of s)l[t]=e}return l}function I(e,t,n){let r={},i=0,a=[];for(let o of t){let t=Math.max(e[o]??0,0);if(n.has(o)){let e=Math.round(t);r[o]=e,i+=e}else{let e=Math.floor(t);r[o]=e,a.push({id:o,floor:e,frac:t-e})}}let o=Math.max(0,100-i)-a.reduce((e,t)=>e+t.floor,0),s=[...a].sort((e,t)=>t.frac-e.frac);for(let e=0;o>0&&s.length>0;e+=1)r[s[e%s.length].id]+=1,--o;let c=[...a].sort((e,t)=>e.frac-t.frac);for(let e=0;o<0&&c.length>0;e+=1){let t=c[e%c.length].id;r[t]>0&&(--r[t],o+=1)}return r}function L({nodes:e,pending:t,onCommitWeights:n,weightLabel:r=`Detection weight`,emptyHint:i,footnote:a}){let[o,s]=p(()=>P(e)),[c,u]=p(new Set);h(()=>{s(P(e)),u(t=>new Set([...t].filter(t=>e.some(e=>e.id===t))))},[e.map(e=>`${e.id}:${e.weight}`).join(`|`)]);let f=e.map(e=>e.id),g=e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},_=(e,t)=>{s(n=>F(n,e,t,c,f))},v=()=>{let t=I(o,f,c),r=e.filter(e=>(t[e.id]??0)!==e.weight).map(e=>e.id);if(r.length===0)return;let i=new Set([...r,...c]);n(e.filter(e=>i.has(e.id)).map(e=>({nodeId:e.id,weight:t[e.id]??0})))};if(e.length===0)return m(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:i??`No detect-enabled nodes. Enable “Detect” on a node above to distribute detection weight.`});let y=e.length===1;return l(`div`,{className:`space-y-3`,children:[e.map(e=>{let n=o[e.id]??0,i=c.has(e.id);return l(`div`,{className:`flex items-center gap-3`,children:[m(`span`,{className:`w-28 shrink-0 truncate text-xs font-medium text-foreground`,title:e.name,children:e.name}),m(`input`,{"aria-label":`${r} for ${e.name}`,type:`range`,min:0,max:100,step:1,value:Math.round(n),disabled:t||i||y,onChange:t=>_(e.id,Number(t.target.value)),onPointerUp:()=>v(),onKeyUp:()=>v(),className:`h-1.5 flex-1 cursor-pointer accent-primary disabled:cursor-not-allowed disabled:opacity-50`}),l(`span`,{className:`w-10 shrink-0 text-right font-mono text-xs tabular-nums text-foreground`,children:[Math.round(n),`%`]}),m(`button`,{type:`button`,onClick:()=>g(e.id),disabled:t||y,"aria-pressed":i,title:i?`Unlock — allow rebalancing`:`Lock this share when others change`,className:`shrink-0 rounded p-1 hover:bg-surface-hover disabled:opacity-40 ${i?`text-amber-400`:`text-foreground-subtle`}`,children:m(i?x:w,{className:`h-3.5 w-3.5`})})]},e.id)}),m(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:a??m(d,{children:`Dragging one slider splits the rest equally across the unlocked nodes; lock a node to pin its share — locked nodes never move and the total always stays at 100%, so a drag is bounded by the room the unlocked nodes leave. Detection only distributes across nodes that can source a camera’s frames.`})})]})}c();function R(e){let t=e.backend.toLowerCase(),n=e.device.toLowerCase();return e.key===`cpu`||n===`cpu`?{label:`CPU`,Icon:b,hue:`slate`}:t===`openvino`&&n===`npu`?{label:`Intel NPU (AI Boost)`,Icon:g,hue:`sky`}:t===`openvino`&&(n===`gpu`||n===`igpu`)?{label:`Intel iGPU`,Icon:S,hue:`violet`}:t===`edgetpu`?{label:`Coral Edge TPU`,Icon:D,hue:`emerald`}:{label:`${e.backend} ${e.device}`.replace(/\b\w/g,e=>e.toUpperCase()).trim(),Icon:b,hue:`slate`}}var z={sky:`bg-sky-500/12 text-sky-400 ring-sky-500/25`,violet:`bg-violet-500/12 text-violet-400 ring-violet-500/25`,emerald:`bg-emerald-500/12 text-emerald-400 ring-emerald-500/25`,slate:`bg-surface-hover text-foreground-subtle ring-border`};function B({nodeId:e,nodeName:r,isOnline:a}){let s=f(),{data:c,isLoading:g}=i({nodeId:e},{refetchInterval:15e3}),v=t({onSettled:()=>{s.invalidateQueries({queryKey:[`pipelineOrchestrator`,`getNodeInferenceDevices`]})}}),b=c?.devices??[],x=c?.reachable??a,[S,w]=p({});h(()=>{w(Object.fromEntries(b.map(e=>[e.key,{enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}])))},[b.map(e=>`${e.key}:${e.enabled}:${e.weight}:${e.maxSessions}:${JSON.stringify(e.steps??{})}`).join(`|`)]);let T=u(()=>b.filter(e=>S[e.key]?.enabled??e.enabled).length,[b,S]),[D,O]=p(null),k=D??T>0,A=t=>{let n={};for(let[e,r]of Object.entries(t)){if(!r.enabled)continue;let t=Object.keys(r.steps).length>0;n[e]={enabled:!0,weight:Math.max(1,r.weight),...r.maxSessions!=null&&r.maxSessions>0?{maxSessions:r.maxSessions}:{},...t?{steps:r.steps}:{}}}v.mutate({agentNodeId:e,inferenceDevices:n})},j=e=>({enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}),M=e=>{if(!e.available)return;let t=S[e.key]??j(e),n={...S,[e.key]:{...t,enabled:!t.enabled}};w(n),A(n)},N=(e,t)=>{let n=S[e.key]??j(e),r={...S,[e.key]:{...n,maxSessions:t}};w(r),A(r)},P=u(()=>b.filter(e=>(S[e.key]?.enabled??e.enabled)&&e.available),[b,S]),F=u(()=>P.map(e=>({id:e.key,name:R(e).label,weight:S[e.key]?.weight??e.weight})),[P,S]);return l(`div`,{className:`rounded-lg border border-border bg-surface/60`,children:[l(`button`,{type:`button`,onClick:()=>O(!k),className:`flex w-full items-center gap-2.5 px-3.5 py-2.5 text-left`,"aria-expanded":k,children:[m(_,{className:`h-4 w-4 shrink-0 text-foreground-subtle transition-transform ${k?`rotate-90`:``}`}),m(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:r}),m(`span`,{className:`ml-auto flex items-center gap-2 text-[11px]`,children:x?T>=2?l(`span`,{className:`inline-flex items-center gap-1 text-emerald-400`,children:[m(C,{className:`h-3.5 w-3.5`}),T,` accelerators`]}):T===1?m(`span`,{className:`text-foreground-subtle`,children:`single default`}):m(`span`,{className:`text-foreground-subtle/70`,children:`auto default`}):l(`span`,{className:`inline-flex items-center gap-1 text-foreground-subtle`,children:[m(y,{className:`h-3.5 w-3.5`}),` unreachable`]})})]}),k&&l(`div`,{className:`space-y-3 border-t border-border px-3.5 py-3`,children:[x?g&&b.length===0?m(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`Probing accelerators…`}):b.length===0?m(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No inference devices reported by this node's platform probe.`}):m(`ul`,{className:`space-y-2`,children:b.map(e=>{let t=R(e),r=S[e.key]??j(e),i=r.enabled&&e.available;return l(`li`,{className:`flex items-center gap-3 rounded-lg border px-3 py-2.5 transition-colors ${e.available?i?`border-primary/40 bg-primary/[0.04] ring-1 ring-inset ring-primary/20`:`border-border bg-surface`:`border-border/60 bg-background opacity-55`}`,children:[m(`span`,{className:`grid h-9 w-9 shrink-0 place-items-center rounded-md ring-1 ring-inset ${z[t.hue]}`,children:m(t.Icon,{className:`h-4.5 w-4.5`})}),l(`div`,{className:`min-w-0 flex-1`,children:[l(`div`,{className:`flex items-center gap-2`,children:[m(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t.label}),m(n,{variant:`default`,style:`outline`,className:`font-mono text-[9px]`,children:e.format}),!e.available&&m(n,{variant:`warning`,className:`text-[9px]`,children:`unavailable`})]}),l(`div`,{className:`mt-0.5 flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[m(`span`,{className:`font-mono`,children:e.key}),!i&&l(d,{children:[m(`span`,{"aria-hidden":!0,children:`·`}),l(`span`,{children:[`default model`,` `,m(`span`,{className:`font-mono text-foreground/80`,children:e.defaultModelId})]})]})]})]}),i&&l(`label`,{className:`flex shrink-0 items-center gap-1 text-[10px] text-foreground-subtle`,children:[m(`span`,{className:`hidden @sm/clustertab:inline`,children:`cap`}),m(`input`,{type:`number`,min:1,placeholder:`∞`,value:r.maxSessions??``,onChange:t=>{let n=t.target.value.trim(),r=n===``?null:Number.parseInt(n,10);N(e,r!=null&&r>0?r:null)},disabled:v.isPending,"aria-label":`Max concurrent sessions for ${t.label}`,className:`w-14 rounded border border-border bg-background px-1.5 py-1 text-right font-mono text-[11px] text-foreground focus:border-primary focus:outline-none`})]}),m(o,{checked:i,onCheckedChange:()=>M(e),disabled:!e.available||v.isPending,"aria-label":`Enable ${t.label}`,className:e.available?``:`cursor-not-allowed opacity-50`})]},e.key)})}):m(V,{}),x&&P.length>=2&&l(`div`,{className:`space-y-3 rounded-lg border border-border bg-background/60 p-3.5`,children:[l(`h4`,{className:`flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:[m(E,{className:`h-3.5 w-3.5`}),`Balancer weight`]}),m(L,{nodes:F,pending:v.isPending,onCommitWeights:e=>{let t={...S};for(let n of e){let e=t[n.nodeId];e&&(t[n.nodeId]={...e,weight:n.weight})}w(t),A(t)},weightLabel:`Balancer weight`,footnote:m(d,{children:`Drag to shift the share of detection sessions each accelerator handles; lock one to pin its share while the others rebalance. Shares always sum to 100%.`})})]}),v.isError&&l(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px] text-danger`,children:[`Failed to save inference devices:`,` `,v.error instanceof Error?v.error.message:`unknown error`]})]})]})}function V(){return l(`div`,{className:`flex flex-col items-center gap-2 rounded-lg border border-dashed border-border bg-background px-4 py-8 text-center`,children:[m(y,{className:`h-6 w-6 text-foreground-subtle/60`}),m(`p`,{className:`text-xs font-medium text-foreground`,children:`Node unreachable`}),m(`p`,{className:`max-w-sm text-[11px] text-foreground-subtle`,children:`The platform probe couldn't be reached, so its live accelerator set is unavailable. Settings resume once the node reconnects.`})]})}export{M as a,C as c,k as i,R as n,O as o,L as r,T as s,B as t};
|
|
1
|
+
import{En as e,Ti as t,To as n,jn as r,mi as i,wn as a,xo as o}from"./src-DHFCkQHW.js";import{K as s,Q as c,S as l,W as u,b as d,o as f,q as p,x as m,z as h}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 g}from"./zap-DZXxY1Hy.js";import{P as _,W as v,a as y,j as b,x}from"./index-Cl-M8KBA.js";var S=v(`circuit-board`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M11 9h4a2 2 0 0 0 2-2V3`,key:`1ve2rv`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`M7 21v-4a2 2 0 0 1 2-2h4`,key:`1fwkro`}],[`circle`,{cx:`15`,cy:`15`,r:`2`,key:`3i40o0`}]]),C=v(`layers`,[[`path`,{d:`M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z`,key:`zw3jo`}],[`path`,{d:`M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12`,key:`1wduqc`}],[`path`,{d:`M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17`,key:`kqbvx6`}]]),w=v(`lock-open`,[[`rect`,{width:`18`,height:`11`,x:`3`,y:`11`,rx:`2`,ry:`2`,key:`1w4ew1`}],[`path`,{d:`M7 11V7a5 5 0 0 1 9.9-1`,key:`1mm8w8`}]]),T=v(`minus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]),E=v(`scale`,[[`path`,{d:`m16 16 3-8 3 8c-.87.65-1.92 1-3 1s-2.13-.35-3-1Z`,key:`7g6ntu`}],[`path`,{d:`m2 16 3-8 3 8c-.87.65-1.92 1-3 1s-2.13-.35-3-1Z`,key:`ijws7r`}],[`path`,{d:`M7 21h10`,key:`1b0cd5`}],[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`M3 7h2c2 0 5-1 7-2 2 1 5 2 7 2h2`,key:`3gwbw2`}]]),D=v(`usb`,[[`circle`,{cx:`10`,cy:`7`,r:`1`,key:`dypaad`}],[`circle`,{cx:`4`,cy:`20`,r:`1`,key:`22iqad`}],[`path`,{d:`M4.7 19.3 19 5`,key:`1enqfc`}],[`path`,{d:`m21 3-3 1 2 2Z`,key:`d3ov82`}],[`path`,{d:`M9.26 7.68 5 12l2 5`,key:`1esawj`}],[`path`,{d:`m10 14 5 2 3.5-3.5`,key:`v8oal5`}],[`path`,{d:`m18 12 1-1 1 1-1 1Z`,key:`1bh22v`}]]);c();function O(e){return r({addonId:e})}function k(t){return e({deviceId:t},{enabled:Number.isFinite(t)})}var A=3e4,j=2e3;function M(e){let t=s(0);return t.current===0&&(t.current=Date.now()),a({parentDeviceId:e},{enabled:Number.isFinite(e),staleTime:0,refetchOnMount:`always`,refetchInterval:e=>{let n=e.state.data;return n&&n.length>0||Date.now()-t.current>=A?!1:j}})}c();function N(e,t,n){return Math.min(Math.max(e,t),n)}function P(e){let t=e.reduce((e,t)=>e+Math.max(t.weight,0),0);if(t<=0){let t=e.length>0?100/e.length:0;return Object.fromEntries(e.map(e=>[e.id,t]))}return Object.fromEntries(e.map(e=>[e.id,Math.max(e.weight,0)/t*100]))}function F(e,t,n,r,i){let a=i.filter(e=>e!==t&&r.has(e)).reduce((t,n)=>t+Math.max(e[n]??0,0),0),o=Math.max(0,100-a),s=i.filter(e=>e!==t&&!r.has(e)),c=s.length===0?o:N(n,0,o),l={...e,[t]:c};if(s.length>0){let e=Math.max(0,o-c)/s.length;for(let t of s)l[t]=e}return l}function I(e,t,n){let r={},i=0,a=[];for(let o of t){let t=Math.max(e[o]??0,0);if(n.has(o)){let e=Math.round(t);r[o]=e,i+=e}else{let e=Math.floor(t);r[o]=e,a.push({id:o,floor:e,frac:t-e})}}let o=Math.max(0,100-i)-a.reduce((e,t)=>e+t.floor,0),s=[...a].sort((e,t)=>t.frac-e.frac);for(let e=0;o>0&&s.length>0;e+=1)r[s[e%s.length].id]+=1,--o;let c=[...a].sort((e,t)=>e.frac-t.frac);for(let e=0;o<0&&c.length>0;e+=1){let t=c[e%c.length].id;r[t]>0&&(--r[t],o+=1)}return r}function L({nodes:e,pending:t,onCommitWeights:n,weightLabel:r=`Detection weight`,emptyHint:i,footnote:a}){let[o,s]=p(()=>P(e)),[c,u]=p(new Set);h(()=>{s(P(e)),u(t=>new Set([...t].filter(t=>e.some(e=>e.id===t))))},[e.map(e=>`${e.id}:${e.weight}`).join(`|`)]);let f=e.map(e=>e.id),g=e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},_=(e,t)=>{s(n=>F(n,e,t,c,f))},v=()=>{let t=I(o,f,c),r=e.filter(e=>(t[e.id]??0)!==e.weight).map(e=>e.id);if(r.length===0)return;let i=new Set([...r,...c]);n(e.filter(e=>i.has(e.id)).map(e=>({nodeId:e.id,weight:t[e.id]??0})))};if(e.length===0)return m(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:i??`No detect-enabled nodes. Enable “Detect” on a node above to distribute detection weight.`});let y=e.length===1;return l(`div`,{className:`space-y-3`,children:[e.map(e=>{let n=o[e.id]??0,i=c.has(e.id);return l(`div`,{className:`flex items-center gap-3`,children:[m(`span`,{className:`w-28 shrink-0 truncate text-xs font-medium text-foreground`,title:e.name,children:e.name}),m(`input`,{"aria-label":`${r} for ${e.name}`,type:`range`,min:0,max:100,step:1,value:Math.round(n),disabled:t||i||y,onChange:t=>_(e.id,Number(t.target.value)),onPointerUp:()=>v(),onKeyUp:()=>v(),className:`h-1.5 flex-1 cursor-pointer accent-primary disabled:cursor-not-allowed disabled:opacity-50`}),l(`span`,{className:`w-10 shrink-0 text-right font-mono text-xs tabular-nums text-foreground`,children:[Math.round(n),`%`]}),m(`button`,{type:`button`,onClick:()=>g(e.id),disabled:t||y,"aria-pressed":i,title:i?`Unlock — allow rebalancing`:`Lock this share when others change`,className:`shrink-0 rounded p-1 hover:bg-surface-hover disabled:opacity-40 ${i?`text-amber-400`:`text-foreground-subtle`}`,children:m(i?x:w,{className:`h-3.5 w-3.5`})})]},e.id)}),m(`p`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:a??m(d,{children:`Dragging one slider splits the rest equally across the unlocked nodes; lock a node to pin its share — locked nodes never move and the total always stays at 100%, so a drag is bounded by the room the unlocked nodes leave. Detection only distributes across nodes that can source a camera’s frames.`})})]})}c();function R(e){let t=e.backend.toLowerCase(),n=e.device.toLowerCase();return e.key===`cpu`||n===`cpu`?{label:`CPU`,Icon:b,hue:`slate`}:t===`openvino`&&n===`npu`?{label:`Intel NPU (AI Boost)`,Icon:g,hue:`sky`}:t===`openvino`&&(n===`gpu`||n===`igpu`)?{label:`Intel iGPU`,Icon:S,hue:`violet`}:t===`edgetpu`?{label:`Coral Edge TPU`,Icon:D,hue:`emerald`}:{label:`${e.backend} ${e.device}`.replace(/\b\w/g,e=>e.toUpperCase()).trim(),Icon:b,hue:`slate`}}var z={sky:`bg-sky-500/12 text-sky-400 ring-sky-500/25`,violet:`bg-violet-500/12 text-violet-400 ring-violet-500/25`,emerald:`bg-emerald-500/12 text-emerald-400 ring-emerald-500/25`,slate:`bg-surface-hover text-foreground-subtle ring-border`};function B({nodeId:e,nodeName:r,isOnline:a}){let s=f(),{data:c,isLoading:g}=i({nodeId:e},{refetchInterval:15e3}),v=t({onSettled:()=>{s.invalidateQueries({queryKey:[`pipelineOrchestrator`,`getNodeInferenceDevices`]})}}),b=c?.devices??[],x=c?.reachable??a,[S,w]=p({});h(()=>{w(Object.fromEntries(b.map(e=>[e.key,{enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}])))},[b.map(e=>`${e.key}:${e.enabled}:${e.weight}:${e.maxSessions}:${JSON.stringify(e.steps??{})}`).join(`|`)]);let T=u(()=>b.filter(e=>S[e.key]?.enabled??e.enabled).length,[b,S]),[D,O]=p(null),k=D??T>0,A=t=>{let n={};for(let[e,r]of Object.entries(t)){if(!r.enabled)continue;let t=Object.keys(r.steps).length>0;n[e]={enabled:!0,weight:Math.max(1,r.weight),...r.maxSessions!=null&&r.maxSessions>0?{maxSessions:r.maxSessions}:{},...t?{steps:r.steps}:{}}}v.mutate({agentNodeId:e,inferenceDevices:n})},j=e=>({enabled:e.enabled,weight:e.weight,maxSessions:e.maxSessions,steps:e.steps??{}}),M=e=>{if(!e.available)return;let t=S[e.key]??j(e),n={...S,[e.key]:{...t,enabled:!t.enabled}};w(n),A(n)},N=(e,t)=>{let n=S[e.key]??j(e),r={...S,[e.key]:{...n,maxSessions:t}};w(r),A(r)},P=u(()=>b.filter(e=>(S[e.key]?.enabled??e.enabled)&&e.available),[b,S]),F=u(()=>P.map(e=>({id:e.key,name:R(e).label,weight:S[e.key]?.weight??e.weight})),[P,S]);return l(`div`,{className:`rounded-lg border border-border bg-surface/60`,children:[l(`button`,{type:`button`,onClick:()=>O(!k),className:`flex w-full items-center gap-2.5 px-3.5 py-2.5 text-left`,"aria-expanded":k,children:[m(_,{className:`h-4 w-4 shrink-0 text-foreground-subtle transition-transform ${k?`rotate-90`:``}`}),m(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:r}),m(`span`,{className:`ml-auto flex items-center gap-2 text-[11px]`,children:x?T>=2?l(`span`,{className:`inline-flex items-center gap-1 text-emerald-400`,children:[m(C,{className:`h-3.5 w-3.5`}),T,` accelerators`]}):T===1?m(`span`,{className:`text-foreground-subtle`,children:`single default`}):m(`span`,{className:`text-foreground-subtle/70`,children:`auto default`}):l(`span`,{className:`inline-flex items-center gap-1 text-foreground-subtle`,children:[m(y,{className:`h-3.5 w-3.5`}),` unreachable`]})})]}),k&&l(`div`,{className:`space-y-3 border-t border-border px-3.5 py-3`,children:[x?g&&b.length===0?m(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`Probing accelerators…`}):b.length===0?m(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No inference devices reported by this node's platform probe.`}):m(`ul`,{className:`space-y-2`,children:b.map(e=>{let t=R(e),r=S[e.key]??j(e),i=r.enabled&&e.available;return l(`li`,{className:`flex items-center gap-3 rounded-lg border px-3 py-2.5 transition-colors ${e.available?i?`border-primary/40 bg-primary/[0.04] ring-1 ring-inset ring-primary/20`:`border-border bg-surface`:`border-border/60 bg-background opacity-55`}`,children:[m(`span`,{className:`grid h-9 w-9 shrink-0 place-items-center rounded-md ring-1 ring-inset ${z[t.hue]}`,children:m(t.Icon,{className:`h-4.5 w-4.5`})}),l(`div`,{className:`min-w-0 flex-1`,children:[l(`div`,{className:`flex items-center gap-2`,children:[m(`span`,{className:`truncate text-[13px] font-medium text-foreground`,children:t.label}),m(n,{variant:`default`,style:`outline`,className:`font-mono text-[9px]`,children:e.format}),!e.available&&m(n,{variant:`warning`,className:`text-[9px]`,children:`unavailable`})]}),l(`div`,{className:`mt-0.5 flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[m(`span`,{className:`font-mono`,children:e.key}),!i&&l(d,{children:[m(`span`,{"aria-hidden":!0,children:`·`}),l(`span`,{children:[`default model`,` `,m(`span`,{className:`font-mono text-foreground/80`,children:e.defaultModelId})]})]})]})]}),i&&l(`label`,{className:`flex shrink-0 items-center gap-1 text-[10px] text-foreground-subtle`,children:[m(`span`,{className:`hidden @sm/clustertab:inline`,children:`cap`}),m(`input`,{type:`number`,min:1,placeholder:`∞`,value:r.maxSessions??``,onChange:t=>{let n=t.target.value.trim(),r=n===``?null:Number.parseInt(n,10);N(e,r!=null&&r>0?r:null)},disabled:v.isPending,"aria-label":`Max concurrent sessions for ${t.label}`,className:`w-14 rounded border border-border bg-background px-1.5 py-1 text-right font-mono text-[11px] text-foreground focus:border-primary focus:outline-none`})]}),m(o,{checked:i,onCheckedChange:()=>M(e),disabled:!e.available||v.isPending,"aria-label":`Enable ${t.label}`,className:e.available?``:`cursor-not-allowed opacity-50`})]},e.key)})}):m(V,{}),x&&P.length>=2&&l(`div`,{className:`space-y-3 rounded-lg border border-border bg-background/60 p-3.5`,children:[l(`h4`,{className:`flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:[m(E,{className:`h-3.5 w-3.5`}),`Balancer weight`]}),m(L,{nodes:F,pending:v.isPending,onCommitWeights:e=>{let t={...S};for(let n of e){let e=t[n.nodeId];e&&(t[n.nodeId]={...e,weight:n.weight})}w(t),A(t)},weightLabel:`Balancer weight`,footnote:m(d,{children:`Drag to shift the share of detection sessions each accelerator handles; lock one to pin its share while the others rebalance. Shares always sum to 100%.`})})]}),v.isError&&l(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px] text-danger`,children:[`Failed to save inference devices:`,` `,v.error instanceof Error?v.error.message:`unknown error`]})]})]})}function V(){return l(`div`,{className:`flex flex-col items-center gap-2 rounded-lg border border-dashed border-border bg-background px-4 py-8 text-center`,children:[m(y,{className:`h-6 w-6 text-foreground-subtle/60`}),m(`p`,{className:`text-xs font-medium text-foreground`,children:`Node unreachable`}),m(`p`,{className:`max-w-sm text-[11px] text-foreground-subtle`,children:`The platform probe couldn't be reached, so its live accelerator set is unavailable. Settings resume once the node reconnects.`})]})}export{M as a,C as c,k as i,R as n,O as o,L as r,T as s,B as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Co as e,Eo as t,Ha as n,S as r,So as i,To as a,bo as o,go as s,ho as c,vo as l,wo as u,xo as d,yo as f}from"./src-DyTBJAFT.js";import{Q as p,S as m,W as h,a as g,b as _,q as v,t as y,x as b}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 x}from"./src-Cv9CvT8c.js";import{p as S}from"./player-overlays-CpNYQPHP.js";import{t as C}from"./circle-check-big-BQNarKjk.js";import{t as w}from"./copy-BHNZnaCo.js";import{t as T}from"./pencil-CxGqjkCs.js";import{t as E}from"./plus-99l7KI-i.js";import{t as D}from"./refresh-cw-BkfWa5Iq.js";import{t as O}from"./search-D-KPSJSm.js";import{t as k}from"./send-BCdV_ME0.js";import{N as A,S as j,V as M,W as N,i as ee,s as P}from"./index-DYyqoGLR.js";import{t as F}from"./AdminPage-Dq33XE9j.js";import{t as te}from"./AdminTabs-CMgSLZC6.js";var I=N(`bell-ring`,[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M22 8c0-2.3-.8-4.3-2-6`,key:`5bb3ad`}],[`path`,{d:`M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326`,key:`11g9vi`}],[`path`,{d:`M4 2C2.8 3.7 2 5.7 2 8`,key:`tap9e0`}]]),ne=N(`flask-conical`,[[`path`,{d:`M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2`,key:`18mbvz`}],[`path`,{d:`M6.453 15h11.094`,key:`3shlmq`}],[`path`,{d:`M8.5 2h7`,key:`csnxdl`}]]),L=N(`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`}]]);p();var R=e=>typeof e==`string`&&e.length>0;function re(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 ie(e,t){return e.format.includes(t)?t:e.format[0]??`text`}function ae(e,t){let n=[];for(let r of e.attachments.mediaTypes){if(n.length>=e.attachments.max)break;let i=t[r];R(i)&&n.push({mediaType:r,url:i})}return n}function oe(e,t){if(e.actions<=0)return[];let n=[];for(let r of t){if(n.length>=e.actions)break;let t=R(r.label),i=R(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 z(e,t){let n=e.levels.some(e=>e.id===t.level)?t.level:void 0,r=ae(e,t.attachmentUrls),i=oe(e,t.actions),a=e.ttl&&R(t.ttl)?Number(t.ttl):void 0;return{body:t.body,format:ie(e,t.format),priority:se(t.priority),...R(t.title)?{title:t.title}:{},...n?{level:n}:{},...r.length>0?{attachments:r}:{},...i.length>0?{actions:i}:{},...e.clickUrl&&R(t.clickUrl)?{clickUrl:t.clickUrl}:{},...e.sound&&R(t.sound)?{sound:t.sound}:{},...a!==void 0&&Number.isFinite(a)?{ttl:a}:{},...R(t.tag)?{tag:t.tag}:{}}}function se(e){return Number.isFinite(e)?Math.min(5,Math.max(1,Math.round(e))):3}function ce(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 B(e){return{level:``,priority:3,format:e.format[0]??`text`,title:``,body:``,attachmentUrls:{},actions:[],clickUrl:``,sound:``,ttl:``,tag:``}}var le={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 ue(e,t){let n=B(e);switch(t){case`minimal`:return{...n,body:`Test notification`};case`overflow`:return{...n,body:`X`.repeat(e.bodyMaxLen+50)};case`critical`:{let t=ce(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]=le[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 de=[{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 fe({target:e,kind:n,open:r,onClose:i}){let u=S(),d=h(()=>re(n.caps),[n.caps]),[p,g]=v(()=>B(n.caps)),[_,x]=v(null),C=h(()=>z(n.caps,p),[n.caps,p]),w=p.body.length,T=w>d.bodyMaxLen,E=e=>g(t=>({...t,...e})),D=y({mutationFn:()=>u.trpcClient.notificationOutput.testTarget.mutate({addonId:e.addonId,targetId:e.id,sample:z(n.caps,p)}),onMutate:()=>x(null),onSuccess:e=>x(e),onError:e=>x({success:!1,error:e instanceof Error?e.message:`Test failed`})}),O=e=>{g(ue(n.caps,e)),x(null)},A=(e,t,n)=>{let r=p.actions.length>0?[...p.actions]:[];for(;r.length<=e;)r.push({label:``,url:``});r[e]={...r[e],[t]:n},E({actions:r})};return b(c,{open:r,onOpenChange:e=>!e&&i(),children:m(s,{width:`lg`,className:`!max-w-2xl`,children:[b(f,{children:m(o,{children:[`Test "`,e.name,`" (`,n.label,`)`]})}),m(`div`,{className:`space-y-4 max-h-[60vh] overflow-y-auto pr-1`,children:[b(`div`,{className:`flex flex-wrap gap-1.5`,children:de.map(e=>b(t,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>O(e.id),children:e.label},e.id))}),m(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[d.levels.length>0&&m(`div`,{children:[b(`label`,{className:H,children:`Level`}),m(`select`,{className:V,value:p.level,onChange:e=>E({level:e.target.value}),children:[b(`option`,{value:``,children:`— derive from priority —`}),d.levels.map(e=>m(`option`,{value:e.id,children:[e.label,e.ordinal===null?` (qualitative)`:` (p${e.ordinal})`]},e.id))]}),(()=>{let e=d.levels.find(e=>e.id===p.level);return e?m(`div`,{className:`mt-1 space-y-1`,children:[e.description&&b(`p`,{className:`text-[10px] text-foreground-subtle`,children:e.description}),m(`div`,{className:`flex flex-wrap gap-1`,children:[e.flags?.critical&&b(a,{variant:`danger`,"data-testid":`flag-critical`,children:`critical`}),e.flags?.silent&&b(a,{variant:`info`,children:`silent`}),e.flags?.noPush&&b(a,{variant:`warning`,children:`no-push`})]}),e.requires&&e.requires.length>0&&m(`p`,{className:`text-[10px] text-warning`,children:[`Requires target config: `,e.requires.join(`, `)]})]}):null})()]}),m(`div`,{children:[m(`label`,{className:H,children:[`Priority (ordinal): `,p.priority]}),b(`input`,{type:`range`,min:1,max:5,step:1,value:p.priority,onChange:e=>E({priority:Number(e.target.value)}),className:`w-full accent-primary`,"aria-label":`priority`})]})]}),d.formats.length>0&&m(`div`,{children:[b(`label`,{className:H,children:`Format`}),b(`div`,{className:`flex flex-wrap gap-2`,children:d.formats.map(e=>m(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[b(`input`,{type:`radio`,name:`format`,className:`accent-primary`,checked:p.format===e,onChange:()=>E({format:e})}),e]},e))})]}),m(`div`,{children:[b(`label`,{className:H,children:`Title`}),b(`input`,{className:V,value:p.title,onChange:e=>E({title:e.target.value})})]}),m(`div`,{children:[m(`label`,{className:H,children:[`Body`,` `,m(`span`,{className:T?`text-danger`:`text-foreground-subtle`,children:[`(`,w,`/`,d.bodyMaxLen,T?` — overflow`:``,`)`]})]}),b(`textarea`,{className:`${V} min-h-[80px] resize-y`,value:p.body,onChange:e=>E({body:e.target.value})})]}),d.attachmentSlots.length>0&&m(`div`,{children:[m(`label`,{className:H,children:[`Attachments`,` `,m(`span`,{className:`text-foreground-subtle`,children:[`(mode: `,d.attachmentMode,`, max `,d.attachmentMax,d.attachmentMaxBytes?`, ≤${Math.round(d.attachmentMaxBytes/1024/1024)}MB`:``,`)`]})]}),b(`div`,{className:`space-y-1.5`,children:d.attachmentSlots.map(e=>m(`div`,{className:`flex items-center gap-2`,children:[b(`span`,{className:`text-[10px] w-12 shrink-0 text-foreground-subtle`,children:e}),b(`input`,{className:V,placeholder:`${e} URL`,value:p.attachmentUrls[e]??``,onChange:t=>E({attachmentUrls:{...p.attachmentUrls,[e]:t.target.value}})})]},e))})]}),d.showActions&&m(`div`,{children:[m(`label`,{className:H,children:[`Actions (up to `,d.maxActions,`)`]}),b(`div`,{className:`space-y-1.5`,children:Array.from({length:Math.min(d.maxActions,3)},(e,t)=>m(`div`,{className:`flex items-center gap-2`,children:[b(`input`,{className:V,placeholder:`label`,value:p.actions[t]?.label??``,onChange:e=>A(t,`label`,e.target.value)}),b(`input`,{className:V,placeholder:`url`,value:p.actions[t]?.url??``,onChange:e=>A(t,`url`,e.target.value)})]},t))})]}),m(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[d.showClickUrl&&m(`div`,{children:[b(`label`,{className:H,children:`Click URL`}),b(`input`,{className:V,value:p.clickUrl,onChange:e=>E({clickUrl:e.target.value})})]}),d.showSound&&m(`div`,{children:[b(`label`,{className:H,children:`Sound`}),b(`input`,{className:V,value:p.sound,onChange:e=>E({sound:e.target.value})})]}),d.showTtl&&m(`div`,{children:[b(`label`,{className:H,children:`TTL (seconds)`}),b(`input`,{className:V,type:`number`,value:p.ttl,onChange:e=>E({ttl:e.target.value})})]}),d.showTag&&m(`div`,{children:[b(`label`,{className:H,children:`Tag`}),b(`input`,{className:V,value:p.tag,onChange:e=>E({tag:e.target.value})})]})]}),_&&b(pe,{result:_}),m(`details`,{className:`text-[10px]`,children:[b(`summary`,{className:`cursor-pointer text-foreground-subtle`,children:`Payload preview`}),b(`pre`,{className:`mt-1 overflow-x-auto rounded bg-surface p-2 text-foreground-subtle`,children:JSON.stringify(C,null,2)})]})]}),m(l,{children:[b(t,{variant:`secondary`,size:`sm`,type:`button`,onClick:i,children:`Close`}),m(t,{size:`sm`,type:`button`,disabled:D.isPending||p.body.length===0,onClick:()=>D.mutate(),children:[D.isPending?b(j,{className:`h-3.5 w-3.5 animate-spin`}):b(k,{className:`h-3.5 w-3.5`}),`Send test`]})]})]})})}function pe({result:e}){let t=e.renderedAs;return m(`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:[m(`div`,{className:`flex items-center gap-2 font-medium`,children:[e.success?b(C,{className:`h-3.5 w-3.5 text-success`}):b(A,{className:`h-3.5 w-3.5 text-danger`}),b(`span`,{children:e.success?`Delivered`:`Failed`})]}),e.error&&b(`p`,{className:`mt-1 text-danger`,children:e.error}),t&&m(`dl`,{className:`mt-2 grid grid-cols-2 gap-x-3 gap-y-0.5 text-[11px] text-foreground-subtle`,children:[b(`dt`,{children:`Resolved level`}),b(`dd`,{className:`text-foreground`,children:t.level}),b(`dt`,{children:`Format sent`}),b(`dd`,{className:`text-foreground`,children:t.format}),b(`dt`,{children:`Attachments sent`}),b(`dd`,{className:`text-foreground`,children:t.attachmentsSent}),b(`dt`,{children:`Actions sent`}),b(`dd`,{className:`text-foreground`,children:t.actionsSent}),b(`dt`,{children:`Truncated`}),b(`dd`,{className:`text-foreground`,children:t.truncated?`yes`:`no`}),b(`dt`,{children:`Dropped`}),b(`dd`,{className:`text-foreground`,children:t.dropped.length>0?t.dropped.join(`, `):`—`})]})]})}function me(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 he(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 ge(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 _e(e,t){let n=new Set(t),r={};for(let[t,i]of Object.entries(e))r[t]=n.has(t)?``:i;return r}p();var ve=[`notificationOutput`,`listTargets`],ye=[`notificationOutput`,`listTargetKinds`];function U({kind:e,imgClassName:t,fallbackClassName:n}){return e?.iconUrl?b(`img`,{src:e.iconUrl,alt:e.label,className:t,loading:`lazy`,draggable:!1}):b(`span`,{className:n,children:e?.icon??`🔔`})}function be(){let e=S(),[r,i]=v({mode:`closed`}),[o,s]=v(null),c=g({queryKey:ve,queryFn:()=>e.trpcClient.notificationOutput.listTargets.query({})}),l=g({queryKey:ye,queryFn:async()=>(await e.trpcClient.notificationOutput.listTargetKinds.query({})).map(e=>{let t=e.iconUrl;return{...e,configSchema:e.configSchema,iconUrl:t}})}),f=h(()=>l.data??[],[l.data]),p=h(()=>{let e=new Map;for(let t of f)e.set(t.kind,t);return e},[f]),_=y({mutationFn:t=>e.trpcClient.notificationOutput.setTargetEnabled.mutate({addonId:t.target.addonId,targetId:t.target.id,enabled:t.enabled}),onSuccess:()=>void c.refetch()}),x=y({mutationFn:t=>e.trpcClient.notificationOutput.deleteTarget.mutate({addonId:t.addonId,targetId:t.id}),onSuccess:()=>void c.refetch()}),C=o?p.get(o.kind):void 0;return m(F,{icon:M,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:m(t,{size:`sm`,type:`button`,onClick:()=>i({mode:`pick-kind`}),children:[b(E,{className:`h-3.5 w-3.5`}),`Add target`]}),children:[c.isLoading&&b(`div`,{className:`flex items-center justify-center py-16`,children:b(j,{className:`h-6 w-6 animate-spin text-primary`})}),c.isError&&!c.isLoading&&b(n,{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&&b(`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&&b(u,{children:b(`ul`,{className:`divide-y divide-border`,children:(c.data??[]).map(e=>{let n=p.get(e.kind);return m(`li`,{className:`flex items-center gap-3 px-4 py-2.5`,children:[b(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface text-xs`,title:n?.label??e.kind,children:b(U,{kind:n,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:``})}),m(`div`,{className:`min-w-0 flex-1`,children:[b(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),b(`div`,{className:`text-[11px] text-foreground-subtle`,children:n?.label??e.kind})]}),!e.enabled&&b(a,{variant:`warning`,children:`disabled`}),b(d,{checked:e.enabled,onCheckedChange:t=>_.mutate({target:e,enabled:t}),"aria-label":`toggle ${e.name}`}),b(t,{size:`sm`,variant:`ghost`,type:`button`,disabled:!n,onClick:()=>s(e),title:`Test`,children:b(k,{className:`h-3.5 w-3.5`})}),b(t,{size:`sm`,variant:`ghost`,type:`button`,disabled:!n,onClick:()=>n&&i({mode:`form`,kind:n,target:e}),title:`Edit`,children:b(T,{className:`h-3.5 w-3.5`})}),b(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>x.mutate(e),title:`Delete`,children:b(P,{className:`h-3.5 w-3.5 text-danger`})})]},e.id)})})}),r.mode===`pick-kind`&&b(xe,{kinds:f,onCancel:()=>i({mode:`closed`}),onPick:e=>i({mode:`form`,kind:e,target:null})}),r.mode===`form`&&b(Se,{kind:r.kind,target:r.target,onCancel:()=>i({mode:`closed`}),onSaved:()=>{i({mode:`closed`}),c.refetch()}}),o&&C&&b(fe,{target:o,kind:C,open:!0,onClose:()=>s(null)})]})}function xe({kinds:e,onPick:n,onCancel:r}){let i=h(()=>me(e),[e]);return m(u,{className:`p-4 space-y-4`,children:[m(`div`,{className:`flex items-center justify-between`,children:[b(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Choose a notification kind`}),b(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:r,children:`Cancel`})]}),i.length===0&&b(`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=>m(`div`,{children:[b(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1.5`,children:e.addonId}),b(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-2`,children:e.kinds.map(t=>m(`button`,{type:`button`,onClick:()=>n(t),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:[b(U,{kind:t,imgClassName:`h-7 w-7 object-contain`,fallbackClassName:`text-lg leading-7`}),b(`span`,{className:`font-medium text-foreground`,children:t.label}),t.supportsDiscovery&&b(a,{variant:`info`,style:`outline`,children:`discover`})]},`${e.addonId}:${t.kind}`))})]},e.addonId))]})}function Se({kind:e,target:n,onSaved:i,onCancel:a}){let o=S(),s=h(()=>he(e.configSchema),[e.configSchema]),c=h(()=>n?.config??{},[n]),[l,d]=v(n?.name??e.label),[f,p]=v(()=>n?_e(n.config,s):{}),[g,_]=v(null),[x,C]=v(null),w=y({mutationFn:()=>o.trpcClient.notificationOutput.discoverTargets.query({addonId:e.addonId,kind:e.kind,config:f}),onSuccess:e=>_(e),onError:e=>C(e instanceof Error?e.message:`Discovery failed`)}),T=y({mutationFn:()=>{let t=ge(f,c,s),r={id:n?.id??`${e.kind}-${Date.now()}`,name:l,kind:e.kind,addonId:e.addonId,enabled:n?.enabled??!0,config:t};return o.trpcClient.notificationOutput.upsertTarget.mutate({addonId:e.addonId,target:r})},onSuccess:i,onError:e=>C(e instanceof Error?e.message:`Save failed`)}),E=e=>{d(e.suggestedName),p(t=>({...t,...e.config})),_(null)};return m(u,{className:`p-4 space-y-4`,children:[m(`div`,{className:`flex items-center justify-between`,children:[m(`h3`,{className:`text-sm font-semibold text-foreground flex items-center gap-2`,children:[b(U,{kind:e,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:`text-lg`}),n?`Edit ${n.name}`:`Add ${e.label} target`]}),b(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:a,children:`Cancel`})]}),x&&b(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:x}),m(`div`,{children:[b(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Name`}),b(`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:l,onChange:e=>d(e.target.value)})]}),e.supportsDiscovery&&m(`div`,{className:`space-y-2`,children:[m(t,{size:`sm`,variant:`outline`,type:`button`,disabled:w.isPending,onClick:()=>{C(null),w.mutate()},children:[w.isPending?b(j,{className:`h-3.5 w-3.5 animate-spin`}):b(O,{className:`h-3.5 w-3.5`}),`Discover`]}),g&&g.length===0&&b(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No candidates discovered.`}),g&&g.length>0&&b(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:g.map((e,t)=>m(`button`,{type:`button`,onClick:()=>E(e),className:`flex w-full items-center justify-between px-3 py-1.5 text-xs hover:bg-surface-hover`,children:[b(`span`,{className:`text-foreground`,children:e.suggestedName}),b(`span`,{className:`text-[10px] text-primary`,children:`use`})]},`${e.suggestedName}-${t}`))})]}),s.length>0&&n&&b(`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.`}),b(r,{schema:e.configSchema,values:f,onChange:p}),m(`div`,{className:`flex justify-end gap-2`,children:[b(t,{variant:`secondary`,size:`sm`,type:`button`,onClick:a,children:`Cancel`}),m(t,{size:`sm`,type:`button`,disabled:T.isPending||l.trim().length===0,onClick:()=>{C(null),T.mutate()},children:[T.isPending&&b(j,{className:`h-3.5 w-3.5 animate-spin`}),n?`Save changes`:`Create target`]})]})]})}var W=[{value:`immediate`,label:`Immediate`,hint:`Fires on the first matching detection of a track (lowest latency).`},{value:`track-end`,label:`Track end`,hint:`Evaluates the finalised track record when it closes.`},{value:`device-event`,label:`Device event`,hint:`Doorbell press / sensor state change on a linked device.`},{value:`package-event`,label:`Package event`,hint:`A parcel delivery or pick-up.`}];function Ce(e){return W.find(t=>t.value===e)?.label??e}function we(e){return W.find(t=>t.value===e)?.value}var G=[{value:`best`,label:`Best available image`,description:`The best subject crop available when the notification is sent.`},{value:`best-matching`,label:`Best matching image`,description:`The image that explains why the rule fired — the face crop for an identity rule, the plate crop for a plate rule; falls back to the best image otherwise.`},{value:`keyFrame`,label:`Key frame`,description:`The clean full scene frame with no subject box.`},{value:`none`,label:`No attachment`,description:`Send the notification with no image.`}];function Te(e){return G.find(t=>t.value===e)?.value}var Ee=[{value:`any`,label:`Any source`},{value:`pipeline`,label:`Pipeline`},{value:`onboard`,label:`Onboard (camera)`},{value:`sensor`,label:`Sensor`}],K=[{value:`delivered`,label:`Delivered`},{value:`picked-up`,label:`Picked up`},{value:`both`,label:`Both`}],De=[{value:`any`,label:`Any of`},{value:`all`,label:`All of`}],Oe=[{value:1,label:`1 — Min`},{value:2,label:`2 — Low`},{value:3,label:`3 — Default`},{value:4,label:`4 — High`},{value:5,label:`5 — Max`}];function ke(){return{name:``,enabled:!0,delivery:`immediate`,targetIds:[],targetParams:{},priority:3,mediaAttach:`best`,templateTitle:``,templateBody:``,conditions:{},schedule:void 0}}function Ae(e){let t={};for(let n of e.targets)n.params&&Object.keys(n.params).length>0&&(t[n.targetId]=n.params);return{name:e.name,enabled:e.enabled,delivery:e.delivery,targetIds:e.targets.map(e=>e.targetId),targetParams:t,priority:e.priority,mediaAttach:e.media.attach,templateTitle:e.template?.title??``,templateBody:e.template?.body??``,conditions:e.conditions,schedule:e.schedule}}function q(e){return e.name.trim().length>0&&e.targetIds.length>0}function J(e,t){return e.appliesTo.includes(t)}function je(e){if(e==null)return!0;if(Array.isArray(e))return e.length===0;if(typeof e==`string`)return e.length===0||e===`any`;if(typeof e==`number`)return!Number.isFinite(e);if(typeof e==`object`){if(`ids`in e){let t=e.ids;return!Array.isArray(t)||t.length===0}if(`values`in e){let t=e.values;return!Array.isArray(t)||t.length===0}return!1}return!1}function Me(e,t,n){let r=n.length===0?null:new Set(n.filter(e=>e.id!==`schedule`&&J(e,t)).map(e=>e.id)),i={};for(let[t,n]of Object.entries(e))r!==null&&!r.has(t)||je(n)||(i[t]=n);return i}function Ne(e){return e!==void 0&&e.windows.length>0}function Y(e,t,n=[]){let r=e.templateTitle.trim(),i=e.templateBody.trim(),a=r.length>0||i.length>0?{...r.length>0?{title:r}:{},...i.length>0?{body:i}:{}}:void 0,o=(n.length===0||n.some(t=>t.id===`schedule`&&J(t,e.delivery)))&&Ne(e.schedule)?e.schedule:void 0;return{name:e.name.trim(),enabled:e.enabled,delivery:e.delivery,conditions:Me(e.conditions,e.delivery,n),...o?{schedule:o}:{},targets:e.targetIds.map(t=>{let n=e.targetParams[t];return n&&Object.keys(n).length>0?{targetId:t,params:n}:{targetId:t}}),media:{attach:e.mediaAttach},throttle:t?.throttle??{cooldownSec:60,scope:`rule-device`},priority:e.priority,...a?{template:a}:{}}}p();var Pe=[{id:`scope`,label:`Scope`},{id:`class`,label:`Classes`},{id:`zones`,label:`Zones`},{id:`quality`,label:`Quality`},{id:`label`,label:`Identity & plates`},{id:`device`,label:`Device event`},{id:`package`,label:`Package`},{id:`schedule`,label:`Schedule`}],Fe=`block text-[11px] font-medium text-foreground`,X=`text-[10px] text-foreground-subtle mt-0.5`;function Ie({catalog:e,delivery:t,conditions:n,schedule:r,cameras:i,onConditionsChange:o,onScheduleChange:s}){let c=(e,t)=>{let r={...n};t===void 0?delete r[e]:r[e]=t,o(r)};return b(`div`,{className:`space-y-4`,children:Pe.map(t=>({...t,descriptors:e.filter(e=>e.group===t.id)})).filter(e=>e.descriptors.length>0).map(e=>m(`div`,{className:`space-y-2.5`,children:[b(`div`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:e.label}),e.descriptors.map(e=>{let o=J(e,t);return m(`div`,{className:o?``:`opacity-50`,"data-testid":`condition-${e.id}`,children:[m(`div`,{className:`flex items-center justify-between gap-2`,children:[b(`label`,{className:Fe,children:e.label}),!o&&m(a,{variant:`default`,children:[`not for `,e.appliesTo.join(` / `)]})]}),o?b(Le,{descriptor:e,conditions:n,schedule:r,cameras:i,onFieldChange:c,onScheduleChange:s}):b(`p`,{className:X,children:`Not evaluated for the selected trigger — switch the trigger to use it.`}),o&&e.description&&b(`p`,{className:X,children:e.description})]},e.id)})]},e.id))})}function Le({descriptor:e,conditions:t,schedule:n,cameras:r,onFieldChange:a,onScheduleChange:o}){switch(e.valueType){case`deviceIdList`:return b(Ke,{cameras:r,value:t.devices??[],onChange:e=>a(`devices`,e.length>0?e:void 0)});case`stringList`:{if(!ze(e.id))return null;let n=e.id;return b(Z,{value:He(t,n),placeholder:`Add value…`,onChange:e=>a(n,e.length>0?e:void 0)})}case`zoneIdList`:return b(Z,{value:t.zonesExclude??[],placeholder:`Zone id…`,onChange:e=>a(`zonesExclude`,e.length>0?e:void 0)});case`number01`:{if(!Ve(e.id))return null;let n=e.id;return b(Q,{value:Ue(t,n),min:0,max:1,step:.05,onChange:e=>a(n,e)})}case`number`:return b(Q,{value:t.minDwellSeconds,min:0,step:1,onChange:e=>a(`minDwellSeconds`,e)});case`sourceSelect`:return b(i,{value:t.source??`any`,options:Ee.map(e=>({value:e.value,label:e.label})),onChange:e=>a(`source`,We(e.target.value))});case`packagePhase`:return b(i,{value:t.packagePhase??``,options:[{value:``,label:`— any phase —`},...K.map(e=>({value:e.value,label:e.label}))],onChange:e=>a(`packagePhase`,Ge(e.target.value))});case`zoneSelection`:return b(qe,{value:t.zones,onChange:e=>a(`zones`,e)});case`plateMatcher`:return b(Je,{value:t.plates,onChange:e=>a(`plates`,e)});case`schedule`:return b(Qe,{value:n,onChange:o});default:return null}}var Re={classes:!0,classesExclude:!0,labelEquals:!0,identities:!0,identitiesExclude:!0,zonesExclude:!0,eventTypeTokens:!0,sensorKinds:!0};function ze(e){return Object.prototype.hasOwnProperty.call(Re,e)}var Be={minConfidence:!0,minImportance:!0,minLabelConfidence:!0};function Ve(e){return Object.prototype.hasOwnProperty.call(Be,e)}function He(e,t){let n=e[t];return Array.isArray(n)?n:[]}function Ue(e,t){let n=e[t];return typeof n==`number`?n:void 0}function We(e){if(e===`pipeline`||e===`onboard`||e===`sensor`||e===`any`)return e}function Ge(e){return K.find(t=>t.value===e)?.value}function Ke({cameras:e,value:t,onChange:n}){if(e.length===0)return b(`p`,{className:X,children:`No cameras available — the rule applies to all devices.`});let r=e=>n(t.includes(e)?t.filter(t=>t!==e):[...t,e]);return b(`div`,{className:`mt-1 max-h-40 overflow-y-auto rounded-md border border-border divide-y divide-border`,children:e.map(e=>m(`label`,{className:`flex items-center gap-2.5 px-3 py-1.5 text-xs text-foreground cursor-pointer hover:bg-surface-hover`,children:[b(`input`,{type:`checkbox`,checked:t.includes(e.id),onChange:()=>r(e.id),className:`accent-primary`}),b(`span`,{className:`flex-1 truncate`,children:e.name})]},e.id))})}function Z({value:t,placeholder:n,onChange:r}){let[i,a]=v(``),o=()=>{let e=i.trim();if(e.length===0||t.includes(e)){a(``);return}r([...t,e]),a(``)},s=e=>r(t.filter(t=>t!==e));return m(`div`,{className:`mt-1 space-y-1.5`,children:[t.length>0&&b(`div`,{className:`flex flex-wrap gap-1`,children:t.map(e=>m(`span`,{className:`inline-flex items-center gap-1 rounded bg-surface-hover px-1.5 py-0.5 text-[11px] text-foreground`,children:[e,b(`button`,{type:`button`,onClick:()=>s(e),"aria-label":`remove ${e}`,className:`text-foreground-subtle hover:text-danger`,children:b(ee,{className:`h-3 w-3`})})]},e))}),b(e,{value:i,placeholder:n,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),o())},onBlur:o})]})}function Q({value:t,min:n,max:r,step:i,onChange:a}){return m(`div`,{className:`mt-1 flex items-center gap-2`,children:[b(e,{type:`number`,value:t??``,min:n,max:r,step:i,className:`max-w-[8rem]`,onChange:e=>{let t=e.target.value;if(t===``){a(void 0);return}let n=Number(t);a(Number.isFinite(n)?n:void 0)}}),t!==void 0&&r!==void 0&&b(`input`,{type:`range`,min:n,max:r,step:i,value:t,onChange:e=>a(Number(e.target.value)),className:`flex-1 accent-primary`,"aria-label":`value`})]})}function qe({value:e,onChange:t}){let n=e?.ids??[],r=e?.match??`any`,a=e=>t(e.length>0?{ids:e,match:r}:void 0),o=e=>t(n.length>0?{ids:n,match:e}:void 0);return m(`div`,{className:`mt-1 space-y-1.5`,children:[b(`div`,{className:`max-w-[10rem]`,children:b(i,{value:r,options:De.map(e=>({value:e.value,label:e.label})),onChange:e=>o(e.target.value===`all`?`all`:`any`)})}),b(Z,{value:n,placeholder:`Zone id…`,onChange:a})]})}function Je({value:t,onChange:n}){let r=t?.values??[],i=t?.maxDistance??1,a=e=>n(e.length>0?{values:e,maxDistance:i}:void 0),o=e=>n(r.length>0?{values:r,maxDistance:e}:void 0);return m(`div`,{className:`mt-1 space-y-1.5`,children:[b(Z,{value:r,placeholder:`Plate text…`,onChange:a}),m(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Max distance`,b(e,{type:`number`,min:0,max:3,step:1,value:i,className:`max-w-[5rem]`,onChange:e=>{let t=Number(e.target.value);o(Number.isFinite(t)?Math.max(0,Math.min(3,t)):1)}})]})]})}var Ye=[{value:1,label:`Mon`},{value:2,label:`Tue`},{value:3,label:`Wed`},{value:4,label:`Thu`},{value:5,label:`Fri`},{value:6,label:`Sat`},{value:0,label:`Sun`}];function $(e){let t=Math.floor(e/60),n=e%60;return`${String(t).padStart(2,`0`)}:${String(n).padStart(2,`0`)}`}function Xe(e){let[t,n]=e.split(`:`),r=Number(t)*60+Number(n);return Number.isFinite(r)?Math.max(0,Math.min(1439,r)):0}function Ze(){return{days:[1,2,3,4,5],startMinute:540,endMinute:1080}}function Qe({value:e,onChange:t}){let n=e?.windows??[],r=e?.invert??!1,i=(n,r)=>{if(n.length===0){t(void 0);return}t({windows:n,...r?{invert:!0}:{},...e?.timezone?{timezone:e.timezone}:{}})},a=()=>i([...n,Ze()],r),o=e=>i(n.filter((t,n)=>n!==e),r),s=(e,t)=>i(n.map((n,r)=>r===e?t:n),r);return m(`div`,{className:`mt-1 space-y-2`,children:[n.length===0?b(`p`,{className:X,children:`Always active — add a window to restrict when the rule fires.`}):n.map((e,t)=>b($e,{window:e,onChange:e=>s(t,e),onRemove:()=>o(t)},t)),m(`div`,{className:`flex items-center gap-3`,children:[m(`button`,{type:`button`,onClick:a,className:`flex items-center gap-1 rounded-md bg-surface-hover px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground`,children:[b(E,{className:`h-3 w-3`}),` Add window`]}),n.length>0&&m(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[b(`input`,{type:`checkbox`,checked:r,onChange:e=>i([...n],e.target.checked),className:`accent-primary`}),`Active outside the windows`]})]})]})}function $e({window:e,onChange:t,onRemove:n}){let r=n=>{let r=e.days.includes(n)?e.days.filter(e=>e!==n):[...e.days,n];r.length!==0&&t({...e,days:r})};return m(`div`,{className:`space-y-1.5 rounded-md border border-border p-2`,children:[m(`div`,{className:`flex items-center gap-2 text-xs`,children:[b(`input`,{type:`time`,value:$(e.startMinute),onChange:n=>t({...e,startMinute:Xe(n.target.value)}),className:`rounded-md border border-border bg-background px-1 py-0.5`}),b(`span`,{className:`text-foreground-subtle`,children:`→`}),b(`input`,{type:`time`,value:$(e.endMinute),onChange:n=>t({...e,endMinute:Xe(n.target.value)}),className:`rounded-md border border-border bg-background px-1 py-0.5`}),b(`span`,{className:`flex-1`}),b(`button`,{type:`button`,onClick:n,"aria-label":`Remove window`,className:`text-foreground-subtle hover:text-danger`,children:b(P,{className:`h-3.5 w-3.5`})})]}),b(`div`,{className:`flex flex-wrap gap-1`,children:Ye.map(t=>b(`button`,{type:`button`,onClick:()=>r(t.value),className:`rounded px-1.5 py-0.5 text-[10px] ${e.days.includes(t.value)?`bg-primary text-primary-foreground`:`bg-surface-hover text-foreground-subtle`}`,children:t.label},t.value))})]})}p();var et=[`notificationRules`,`listRules`],tt=[`notificationOutput`,`listTargets`,`forRules`],nt=[`notificationRules`,`getConditionCatalog`],rt=[`deviceManager`,`listAll`,`forRules`];function it(){let e=S(),[r,i]=v({mode:`closed`}),[o,s]=v(null),c=g({queryKey:et,queryFn:async()=>(await e.trpcClient.notificationRules.listRules.query({})).rules}),l=g({queryKey:tt,queryFn:()=>e.trpcClient.notificationOutput.listTargets.query({})}),f=g({queryKey:nt,queryFn:async()=>(await e.trpcClient.notificationRules.getConditionCatalog.query({})).catalog}),p=g({queryKey:rt,queryFn:async()=>(await e.trpcClient.deviceManager.listAll.query({})).filter(e=>e.type===x.Camera).map(e=>({id:e.id,name:e.name}))}),_=h(()=>{let e=new Map;for(let t of l.data??[])e.set(t.id,t.name);return e},[l.data]),C=y({mutationFn:t=>e.trpcClient.notificationRules.setRuleEnabled.mutate(t),onSuccess:()=>void c.refetch()}),D=y({mutationFn:t=>e.trpcClient.notificationRules.deleteRule.mutate({ruleId:t}),onSuccess:()=>{s(null),c.refetch()}}),O=c.data??[];return m(F,{icon:I,title:`Notification Rules`,subtitle:`Author rules that turn detections, doorbell presses and package events into notifications. Each rule picks a trigger, matches conditions and fans out to one or more delivery targets.`,actions:m(t,{size:`sm`,type:`button`,onClick:()=>i({mode:`form`,rule:null}),children:[b(E,{className:`h-3.5 w-3.5`}),`New rule`]}),children:[c.isLoading&&b(`div`,{className:`flex items-center justify-center py-16`,children:b(j,{className:`h-6 w-6 animate-spin text-primary`})}),c.isError&&!c.isLoading&&b(n,{title:`Failed to load rules`,message:c.error instanceof Error?c.error.message:`Unknown error`,onRetry:()=>void c.refetch()}),!c.isLoading&&!c.isError&&O.length===0&&b(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No notification rules yet. Click "New rule" to author one.`}),O.length>0&&b(u,{children:b(`ul`,{className:`divide-y divide-border`,children:O.map(e=>{let n=e.targets.length,r=e.targets[0]?_.get(e.targets[0].targetId)??e.targets[0].targetId:null,c=o===e.id;return m(`li`,{className:`flex flex-wrap items-center gap-3 px-4 py-2.5`,children:[m(`div`,{className:`min-w-0 flex-1`,children:[b(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),m(`div`,{className:`text-[11px] text-foreground-subtle flex flex-wrap items-center gap-x-2 gap-y-0.5`,children:[b(`span`,{children:Ce(e.delivery)}),b(`span`,{"aria-hidden":!0,children:`·`}),m(`span`,{children:[n,` target`,n===1?``:`s`,r&&n===1?` (${r})`:``]}),b(`span`,{"aria-hidden":!0,children:`·`}),m(`span`,{children:[`priority `,e.priority]})]})]}),!e.enabled&&b(a,{variant:`warning`,children:`disabled`}),b(d,{checked:e.enabled,onCheckedChange:t=>C.mutate({ruleId:e.id,enabled:t}),"aria-label":`toggle ${e.name}`}),b(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>i({mode:`form`,rule:e}),title:`Edit`,children:b(T,{className:`h-3.5 w-3.5`})}),b(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>i({mode:`form`,rule:{...e,id:``,name:`${e.name} (copy)`}}),title:`Duplicate`,children:b(w,{className:`h-3.5 w-3.5`})}),c?m(`span`,{className:`flex items-center gap-1.5`,children:[m(t,{size:`sm`,variant:`danger`,type:`button`,disabled:D.isPending,onClick:()=>D.mutate(e.id),children:[D.isPending&&b(j,{className:`h-3.5 w-3.5 animate-spin`}),`Confirm`]}),b(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>s(null),children:`Cancel`})]}):b(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>s(e.id),title:`Delete`,children:b(P,{className:`h-3.5 w-3.5 text-danger`})})]},e.id)})})}),r.mode===`form`&&b(at,{rule:r.rule,targets:l.data??[],catalog:f.data??[],cameras:p.data??[],onCancel:()=>i({mode:`closed`}),onSaved:()=>{i({mode:`closed`}),c.refetch()}})]})}function at({rule:n,targets:r,catalog:o,cameras:l,onSaved:u,onCancel:f}){let p=S(),h=n!=null&&n.id.length>0,[g,_]=v(()=>n?Ae(n):ke()),[x,C]=v(null),[w,T]=v(null),E=e=>_(t=>({...t,...e})),D=h&&n?{throttle:n.throttle}:void 0,O=y({mutationFn:async()=>{let e=Y(g,D,o);h&&n?await p.trpcClient.notificationRules.updateRule.mutate({ruleId:n.id,patch:e}):await p.trpcClient.notificationRules.createRule.mutate({rule:e})},onSuccess:u,onError:e=>C(e instanceof Error?e.message:`Save failed`)}),k=y({mutationFn:async()=>{let e=Y(g,D,o);return(await p.trpcClient.notificationRules.testRule.mutate({rule:e,lookbackMinutes:60})).results},onMutate:()=>T(null),onSuccess:e=>T(e),onError:e=>C(e instanceof Error?e.message:`Test failed`)}),A=g.targetIds.map(e=>r.find(t=>t.id===e)?.name??e),M=e=>E({targetIds:g.targetIds.includes(e)?g.targetIds.filter(t=>t!==e):[...g.targetIds,e]}),N=W.find(e=>e.value===g.delivery)?.hint;return b(c,{open:!0,onOpenChange:e=>!e&&f(),children:m(s,{width:`lg`,placement:`sheet-on-mobile`,children:[m(`div`,{className:`flex items-center justify-between mb-3`,children:[m(`h3`,{className:`text-sm font-semibold text-foreground flex items-center gap-2`,children:[b(I,{className:`h-4 w-4 text-foreground-subtle`}),h?`Edit ${n?.name}`:`New notification rule`]}),b(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:f,children:`Cancel`})]}),x&&b(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger mb-3`,children:x}),m(`div`,{className:`space-y-4`,children:[m(`div`,{className:`flex items-end gap-3`,children:[m(`div`,{className:`min-w-0 flex-1`,children:[b(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Name`}),b(e,{value:g.name,onChange:e=>E({name:e.target.value}),placeholder:`e.g. Front door package`})]}),m(`label`,{className:`flex items-center gap-2 pb-1.5 text-[11px] font-medium text-foreground`,children:[b(d,{checked:g.enabled,onCheckedChange:e=>E({enabled:e}),"aria-label":`enabled`}),`Enabled`]})]}),m(`div`,{children:[b(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Trigger`}),b(i,{value:g.delivery,onChange:e=>{let t=we(e.target.value);t&&E({delivery:t})},options:W.map(e=>({value:e.value,label:e.label}))}),N&&b(`p`,{className:`text-[10px] text-foreground-subtle mt-1`,children:N})]}),m(`div`,{children:[b(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Delivery targets`}),r.length===0?b(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No delivery targets configured. Add one under the Targets tab first.`}):b(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:r.map(e=>m(`label`,{className:`flex items-center gap-2.5 px-3 py-1.5 text-xs text-foreground cursor-pointer hover:bg-surface-hover`,children:[b(`input`,{type:`checkbox`,checked:g.targetIds.includes(e.id),onChange:()=>M(e.id),className:`accent-primary`}),b(`span`,{className:`flex-1 truncate`,children:e.name}),!e.enabled&&b(a,{variant:`warning`,children:`disabled`})]},e.id))})]}),m(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[m(`div`,{children:[b(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Priority`}),b(i,{value:String(g.priority),onChange:e=>E({priority:Number(e.target.value)}),options:Oe.map(e=>({value:String(e.value),label:e.label}))})]}),m(`div`,{children:[b(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Media attachment`}),b(i,{value:g.mediaAttach,onChange:e=>{let t=Te(e.target.value);t&&E({mediaAttach:t})},options:G.map(e=>({value:e.value,label:e.label}))}),b(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:G.find(e=>e.value===g.mediaAttach)?.description})]})]}),m(`div`,{className:`space-y-2`,children:[m(`div`,{children:[b(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Notification title`}),b(e,{value:g.templateTitle,onChange:e=>E({templateTitle:e.target.value}),placeholder:`{{camera}} — {{class}}`})]}),m(`div`,{children:[b(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Notification body`}),b(`textarea`,{value:g.templateBody,onChange:e=>E({templateBody:e.target.value}),rows:2,placeholder:`{{label}} seen in {{zone}} at {{time}}`,className:`w-full rounded-md border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),m(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Leave blank to use the backend default text. Supported variables include`,` `,b(`code`,{children:`{{camera}}`}),`, `,b(`code`,{children:`{{class}}`}),`, `,b(`code`,{children:`{{label}}`}),`,`,` `,b(`code`,{children:`{{zone}}`}),`, `,b(`code`,{children:`{{confidence}}`}),`, `,b(`code`,{children:`{{time}}`}),`.`]})]}),m(`div`,{className:`rounded-md border border-border px-3 py-3`,children:[b(`div`,{className:`mb-2 text-[11px] font-semibold text-foreground`,children:`Conditions`}),o.length===0?b(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Condition catalog unavailable — this rule matches on its trigger and targets alone.`}):b(Ie,{catalog:o,delivery:g.delivery,conditions:g.conditions,schedule:g.schedule,cameras:l,onConditionsChange:e=>E({conditions:e}),onScheduleChange:e=>E({schedule:e})})]}),m(`div`,{className:`rounded-md border border-border px-3 py-3`,children:[m(`div`,{className:`flex items-center justify-between gap-2`,children:[b(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`Test rule`}),m(t,{size:`sm`,variant:`outline`,type:`button`,disabled:k.isPending||!q(g),onClick:()=>{C(null),k.mutate()},children:[k.isPending?b(j,{className:`h-3.5 w-3.5 animate-spin`}):b(ne,{className:`h-3.5 w-3.5`}),`Dry-run (last 60 min)`]})]}),b(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:`Evaluate the CURRENT (unsaved) rule against recently persisted records — no notification is sent.`}),w!==null&&b(ot,{delivery:g.delivery,results:w,targetNames:A})]})]}),m(`div`,{className:`flex justify-end gap-2 mt-4`,children:[b(t,{variant:`secondary`,size:`sm`,type:`button`,onClick:f,children:`Cancel`}),m(t,{size:`sm`,type:`button`,disabled:O.isPending||!q(g),onClick:()=>{C(null),O.mutate()},children:[O.isPending&&b(j,{className:`h-3.5 w-3.5 animate-spin`}),h?`Save changes`:`Create rule`]})]})]})})}function ot({delivery:e,results:t,targetNames:n}){if(e===`device-event`)return b(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:`Device-event rules cannot be dry-run: the sensor-event store has no cross-device scan surface, so a test returns no candidate records. The rule still fires live on a matching doorbell press / sensor change.`});if(t.length===0)return b(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:`No records in the last 60 minutes matched — nothing to evaluate.`});let r=t.filter(e=>e.wouldFire).length;return m(`div`,{className:`mt-2 space-y-1.5`,children:[m(`div`,{className:`text-[11px] text-foreground-subtle`,children:[r,` of `,t.length,` evaluated record`,t.length===1?``:`s`,` would fire.`]}),b(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:t.slice(0,50).map(e=>m(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5 text-[11px]`,children:[e.wouldFire?b(C,{className:`h-3.5 w-3.5 shrink-0 text-success`}):b(A,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),b(`span`,{className:`w-32 shrink-0 text-foreground-subtle`,children:new Date(e.timestamp).toLocaleString()}),m(`span`,{className:`w-14 shrink-0 text-foreground-subtle`,children:[`#`,e.deviceId]}),b(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:e.label??e.className??`object`}),e.wouldFire?m(`span`,{className:`shrink-0 truncate text-success`,children:[`→ `,n.join(`, `)||`targets`]}):e.failedCondition&&m(`span`,{className:`shrink-0 text-foreground-subtle`,children:[`failed: `,e.failedCondition]})]},e.recordId))})]})}p();var st=[{value:1,label:`Last hour`},{value:24,label:`Last 24 hours`},{value:168,label:`Last 7 days`},{value:0,label:`All time`}],ct=[{value:``,label:`Any status`},{value:`pending`,label:`Pending`},{value:`sent`,label:`Sent`},{value:`dead`,label:`Dead`}],lt=[50,100,250,500];function ut(){return{ruleId:``,deviceId:``,status:``,windowHours:24,limit:100}}function dt(e){return e===`pending`||e===`sent`||e===`dead`?e:void 0}function ft(e){switch(e){case`pending`:return`info`;case`sent`:return`success`;case`dead`:return`danger`}}function pt(){let e=S(),[t,n]=v(ut),r=e=>n(t=>({...t,...e})),a=g({queryKey:[`notificationRules`,`listRules`,`forHistory`],queryFn:async()=>(await e.trpcClient.notificationRules.listRules.query({})).rules}),o=g({queryKey:[`deviceManager`,`listAll`,`forHistory`],queryFn:async()=>(await e.trpcClient.deviceManager.listAll.query({})).filter(e=>e.type===x.Camera).map(e=>({id:e.id,name:e.name}))}),s=Date.now(),c=g({queryKey:[`notificationRules`,`getHistory`,t],retry:!1,queryFn:async()=>{let n=t.windowHours>0?s-t.windowHours*36e5:void 0;return(await e.trpcClient.notificationRules.getHistory.query({filter:{limit:t.limit,...t.ruleId?{ruleId:t.ruleId}:{},...t.deviceId?{deviceId:Number(t.deviceId)}:{},...dt(t.status)?{status:dt(t.status)}:{},...n===void 0?{}:{since:n}}})).entries}}),l=h(()=>{let e=new Map;for(let t of o.data??[])e.set(t.id,t.name);return e},[o.data]),d=e=>l.get(e)??`Camera #${String(e)}`,f=c.data??[],p=c.isError;return m(F,{icon:L,title:`Delivery history`,subtitle:`A searchable log of every notification the rules delivered (or failed to deliver).`,children:[m(`div`,{className:`mb-4 grid grid-cols-2 gap-2 sm:grid-cols-5`,children:[m(`div`,{children:[b(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Rule`}),b(i,{value:t.ruleId,onChange:e=>r({ruleId:e.target.value}),options:[{value:``,label:`All rules`},...(a.data??[]).map(e=>({value:e.id,label:e.name}))]})]}),m(`div`,{children:[b(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Camera`}),b(i,{value:t.deviceId,onChange:e=>r({deviceId:e.target.value}),options:[{value:``,label:`All cameras`},...(o.data??[]).map(e=>({value:String(e.id),label:e.name}))]})]}),m(`div`,{children:[b(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Status`}),b(i,{value:t.status,onChange:e=>r({status:e.target.value}),options:ct.map(e=>({value:e.value,label:e.label}))})]}),m(`div`,{children:[b(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Window`}),b(i,{value:String(t.windowHours),onChange:e=>r({windowHours:Number(e.target.value)}),options:st.map(e=>({value:String(e.value),label:e.label}))})]}),m(`div`,{children:[b(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Limit`}),b(i,{value:String(t.limit),onChange:e=>r({limit:Number(e.target.value)}),options:lt.map(e=>({value:String(e),label:String(e)}))})]})]}),c.isLoading&&b(`div`,{className:`flex items-center justify-center py-16`,children:b(j,{className:`h-6 w-6 animate-spin text-primary`})}),p&&!c.isLoading&&b(u,{children:m(`div`,{className:`flex flex-col items-center gap-2 px-4 py-14 text-center`,children:[b(L,{className:`h-6 w-6 text-foreground-subtle`}),b(`div`,{className:`text-sm font-medium text-foreground`,children:`Delivery history requires a server update`}),b(`p`,{className:`max-w-md text-xs text-foreground-subtle`,children:`The history query is not available on this hub yet. It becomes queryable after the next server update ships the notification-center history endpoint. Rules still deliver and record their outcome in the meantime.`}),m(`button`,{type:`button`,onClick:()=>void c.refetch(),className:`mt-1 inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:[b(D,{className:`h-3 w-3`}),` Retry`]})]})}),!p&&!c.isLoading&&f.length===0&&b(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:`No deliveries match these filters.`}),!p&&f.length>0&&b(u,{children:b(`ul`,{className:`divide-y divide-border`,children:f.map(e=>b(mt,{entry:e,cameraName:d},e.id))})})]})}function mt({entry:e,cameraName:t}){let n=new Date(e.createdAt).toLocaleString(),r=e.subject.label??e.subject.className;return b(`li`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 px-4 py-2.5`,children:m(`div`,{className:`min-w-0 flex-1`,children:[m(`div`,{className:`flex items-center gap-2`,children:[b(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.ruleName}),b(a,{variant:ft(e.status),children:e.status})]}),m(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5 text-[11px] text-foreground-subtle`,children:[b(`span`,{children:n}),b(`span`,{"aria-hidden":!0,children:`·`}),b(`span`,{children:t(e.deviceId)}),b(`span`,{"aria-hidden":!0,children:`·`}),b(`span`,{children:r}),e.subject.confidence!==void 0&&m(_,{children:[b(`span`,{"aria-hidden":!0,children:`·`}),m(`span`,{children:[Math.round(e.subject.confidence*100),`%`]})]}),e.attempts>1&&m(_,{children:[b(`span`,{"aria-hidden":!0,children:`·`}),m(`span`,{children:[e.attempts,` attempts`]})]})]}),e.status===`dead`&&e.error&&b(`div`,{className:`mt-1 rounded border border-danger/30 bg-danger/10 px-2 py-1 text-[11px] text-danger`,children:e.error})]})})}function ht(){return b(`div`,{className:`flex flex-col p-4`,children:b(te,{tabs:[{id:`targets`,label:`Targets`,icon:M,content:b(be,{})},{id:`rules`,label:`Rules`,icon:I,content:b(it,{})},{id:`history`,label:`History`,icon:L,content:b(pt,{})}]})})}export{ht as NotificationsPage,ht as default};
|
|
1
|
+
import{Co as e,Eo as t,Ha as n,S as r,So as i,To as a,bo as o,go as s,ho as c,vo as l,wo as u,xo as d,yo as f}from"./src-DHFCkQHW.js";import{Q as p,S as m,W as h,a as g,b as _,q as v,t as y,x as b}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 x}from"./src-Cv9CvT8c.js";import{p as S}from"./player-overlays-CpNYQPHP.js";import{t as C}from"./circle-check-big-4_1SeqzL.js";import{t as w}from"./copy-UBfFgSz-.js";import{t as T}from"./pencil-Bcfk7YmX.js";import{t as E}from"./plus-z-WZstU2.js";import{t as D}from"./refresh-cw-hhKexEfo.js";import{t as O}from"./search-DqoMv21b.js";import{t as k}from"./send-Cyy_G5i9.js";import{N as A,S as j,V as M,W as N,i as ee,s as P}from"./index-Cl-M8KBA.js";import{t as F}from"./AdminPage-Dq33XE9j.js";import{t as te}from"./AdminTabs-B6qnIaak.js";var I=N(`bell-ring`,[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M22 8c0-2.3-.8-4.3-2-6`,key:`5bb3ad`}],[`path`,{d:`M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326`,key:`11g9vi`}],[`path`,{d:`M4 2C2.8 3.7 2 5.7 2 8`,key:`tap9e0`}]]),ne=N(`flask-conical`,[[`path`,{d:`M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2`,key:`18mbvz`}],[`path`,{d:`M6.453 15h11.094`,key:`3shlmq`}],[`path`,{d:`M8.5 2h7`,key:`csnxdl`}]]),L=N(`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`}]]);p();var R=e=>typeof e==`string`&&e.length>0;function re(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 ie(e,t){return e.format.includes(t)?t:e.format[0]??`text`}function ae(e,t){let n=[];for(let r of e.attachments.mediaTypes){if(n.length>=e.attachments.max)break;let i=t[r];R(i)&&n.push({mediaType:r,url:i})}return n}function oe(e,t){if(e.actions<=0)return[];let n=[];for(let r of t){if(n.length>=e.actions)break;let t=R(r.label),i=R(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 z(e,t){let n=e.levels.some(e=>e.id===t.level)?t.level:void 0,r=ae(e,t.attachmentUrls),i=oe(e,t.actions),a=e.ttl&&R(t.ttl)?Number(t.ttl):void 0;return{body:t.body,format:ie(e,t.format),priority:se(t.priority),...R(t.title)?{title:t.title}:{},...n?{level:n}:{},...r.length>0?{attachments:r}:{},...i.length>0?{actions:i}:{},...e.clickUrl&&R(t.clickUrl)?{clickUrl:t.clickUrl}:{},...e.sound&&R(t.sound)?{sound:t.sound}:{},...a!==void 0&&Number.isFinite(a)?{ttl:a}:{},...R(t.tag)?{tag:t.tag}:{}}}function se(e){return Number.isFinite(e)?Math.min(5,Math.max(1,Math.round(e))):3}function ce(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 B(e){return{level:``,priority:3,format:e.format[0]??`text`,title:``,body:``,attachmentUrls:{},actions:[],clickUrl:``,sound:``,ttl:``,tag:``}}var le={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 ue(e,t){let n=B(e);switch(t){case`minimal`:return{...n,body:`Test notification`};case`overflow`:return{...n,body:`X`.repeat(e.bodyMaxLen+50)};case`critical`:{let t=ce(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]=le[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 de=[{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 fe({target:e,kind:n,open:r,onClose:i}){let u=S(),d=h(()=>re(n.caps),[n.caps]),[p,g]=v(()=>B(n.caps)),[_,x]=v(null),C=h(()=>z(n.caps,p),[n.caps,p]),w=p.body.length,T=w>d.bodyMaxLen,E=e=>g(t=>({...t,...e})),D=y({mutationFn:()=>u.trpcClient.notificationOutput.testTarget.mutate({addonId:e.addonId,targetId:e.id,sample:z(n.caps,p)}),onMutate:()=>x(null),onSuccess:e=>x(e),onError:e=>x({success:!1,error:e instanceof Error?e.message:`Test failed`})}),O=e=>{g(ue(n.caps,e)),x(null)},A=(e,t,n)=>{let r=p.actions.length>0?[...p.actions]:[];for(;r.length<=e;)r.push({label:``,url:``});r[e]={...r[e],[t]:n},E({actions:r})};return b(c,{open:r,onOpenChange:e=>!e&&i(),children:m(s,{width:`lg`,className:`!max-w-2xl`,children:[b(f,{children:m(o,{children:[`Test "`,e.name,`" (`,n.label,`)`]})}),m(`div`,{className:`space-y-4 max-h-[60vh] overflow-y-auto pr-1`,children:[b(`div`,{className:`flex flex-wrap gap-1.5`,children:de.map(e=>b(t,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>O(e.id),children:e.label},e.id))}),m(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[d.levels.length>0&&m(`div`,{children:[b(`label`,{className:H,children:`Level`}),m(`select`,{className:V,value:p.level,onChange:e=>E({level:e.target.value}),children:[b(`option`,{value:``,children:`— derive from priority —`}),d.levels.map(e=>m(`option`,{value:e.id,children:[e.label,e.ordinal===null?` (qualitative)`:` (p${e.ordinal})`]},e.id))]}),(()=>{let e=d.levels.find(e=>e.id===p.level);return e?m(`div`,{className:`mt-1 space-y-1`,children:[e.description&&b(`p`,{className:`text-[10px] text-foreground-subtle`,children:e.description}),m(`div`,{className:`flex flex-wrap gap-1`,children:[e.flags?.critical&&b(a,{variant:`danger`,"data-testid":`flag-critical`,children:`critical`}),e.flags?.silent&&b(a,{variant:`info`,children:`silent`}),e.flags?.noPush&&b(a,{variant:`warning`,children:`no-push`})]}),e.requires&&e.requires.length>0&&m(`p`,{className:`text-[10px] text-warning`,children:[`Requires target config: `,e.requires.join(`, `)]})]}):null})()]}),m(`div`,{children:[m(`label`,{className:H,children:[`Priority (ordinal): `,p.priority]}),b(`input`,{type:`range`,min:1,max:5,step:1,value:p.priority,onChange:e=>E({priority:Number(e.target.value)}),className:`w-full accent-primary`,"aria-label":`priority`})]})]}),d.formats.length>0&&m(`div`,{children:[b(`label`,{className:H,children:`Format`}),b(`div`,{className:`flex flex-wrap gap-2`,children:d.formats.map(e=>m(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[b(`input`,{type:`radio`,name:`format`,className:`accent-primary`,checked:p.format===e,onChange:()=>E({format:e})}),e]},e))})]}),m(`div`,{children:[b(`label`,{className:H,children:`Title`}),b(`input`,{className:V,value:p.title,onChange:e=>E({title:e.target.value})})]}),m(`div`,{children:[m(`label`,{className:H,children:[`Body`,` `,m(`span`,{className:T?`text-danger`:`text-foreground-subtle`,children:[`(`,w,`/`,d.bodyMaxLen,T?` — overflow`:``,`)`]})]}),b(`textarea`,{className:`${V} min-h-[80px] resize-y`,value:p.body,onChange:e=>E({body:e.target.value})})]}),d.attachmentSlots.length>0&&m(`div`,{children:[m(`label`,{className:H,children:[`Attachments`,` `,m(`span`,{className:`text-foreground-subtle`,children:[`(mode: `,d.attachmentMode,`, max `,d.attachmentMax,d.attachmentMaxBytes?`, ≤${Math.round(d.attachmentMaxBytes/1024/1024)}MB`:``,`)`]})]}),b(`div`,{className:`space-y-1.5`,children:d.attachmentSlots.map(e=>m(`div`,{className:`flex items-center gap-2`,children:[b(`span`,{className:`text-[10px] w-12 shrink-0 text-foreground-subtle`,children:e}),b(`input`,{className:V,placeholder:`${e} URL`,value:p.attachmentUrls[e]??``,onChange:t=>E({attachmentUrls:{...p.attachmentUrls,[e]:t.target.value}})})]},e))})]}),d.showActions&&m(`div`,{children:[m(`label`,{className:H,children:[`Actions (up to `,d.maxActions,`)`]}),b(`div`,{className:`space-y-1.5`,children:Array.from({length:Math.min(d.maxActions,3)},(e,t)=>m(`div`,{className:`flex items-center gap-2`,children:[b(`input`,{className:V,placeholder:`label`,value:p.actions[t]?.label??``,onChange:e=>A(t,`label`,e.target.value)}),b(`input`,{className:V,placeholder:`url`,value:p.actions[t]?.url??``,onChange:e=>A(t,`url`,e.target.value)})]},t))})]}),m(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[d.showClickUrl&&m(`div`,{children:[b(`label`,{className:H,children:`Click URL`}),b(`input`,{className:V,value:p.clickUrl,onChange:e=>E({clickUrl:e.target.value})})]}),d.showSound&&m(`div`,{children:[b(`label`,{className:H,children:`Sound`}),b(`input`,{className:V,value:p.sound,onChange:e=>E({sound:e.target.value})})]}),d.showTtl&&m(`div`,{children:[b(`label`,{className:H,children:`TTL (seconds)`}),b(`input`,{className:V,type:`number`,value:p.ttl,onChange:e=>E({ttl:e.target.value})})]}),d.showTag&&m(`div`,{children:[b(`label`,{className:H,children:`Tag`}),b(`input`,{className:V,value:p.tag,onChange:e=>E({tag:e.target.value})})]})]}),_&&b(pe,{result:_}),m(`details`,{className:`text-[10px]`,children:[b(`summary`,{className:`cursor-pointer text-foreground-subtle`,children:`Payload preview`}),b(`pre`,{className:`mt-1 overflow-x-auto rounded bg-surface p-2 text-foreground-subtle`,children:JSON.stringify(C,null,2)})]})]}),m(l,{children:[b(t,{variant:`secondary`,size:`sm`,type:`button`,onClick:i,children:`Close`}),m(t,{size:`sm`,type:`button`,disabled:D.isPending||p.body.length===0,onClick:()=>D.mutate(),children:[D.isPending?b(j,{className:`h-3.5 w-3.5 animate-spin`}):b(k,{className:`h-3.5 w-3.5`}),`Send test`]})]})]})})}function pe({result:e}){let t=e.renderedAs;return m(`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:[m(`div`,{className:`flex items-center gap-2 font-medium`,children:[e.success?b(C,{className:`h-3.5 w-3.5 text-success`}):b(A,{className:`h-3.5 w-3.5 text-danger`}),b(`span`,{children:e.success?`Delivered`:`Failed`})]}),e.error&&b(`p`,{className:`mt-1 text-danger`,children:e.error}),t&&m(`dl`,{className:`mt-2 grid grid-cols-2 gap-x-3 gap-y-0.5 text-[11px] text-foreground-subtle`,children:[b(`dt`,{children:`Resolved level`}),b(`dd`,{className:`text-foreground`,children:t.level}),b(`dt`,{children:`Format sent`}),b(`dd`,{className:`text-foreground`,children:t.format}),b(`dt`,{children:`Attachments sent`}),b(`dd`,{className:`text-foreground`,children:t.attachmentsSent}),b(`dt`,{children:`Actions sent`}),b(`dd`,{className:`text-foreground`,children:t.actionsSent}),b(`dt`,{children:`Truncated`}),b(`dd`,{className:`text-foreground`,children:t.truncated?`yes`:`no`}),b(`dt`,{children:`Dropped`}),b(`dd`,{className:`text-foreground`,children:t.dropped.length>0?t.dropped.join(`, `):`—`})]})]})}function me(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 he(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 ge(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 _e(e,t){let n=new Set(t),r={};for(let[t,i]of Object.entries(e))r[t]=n.has(t)?``:i;return r}p();var ve=[`notificationOutput`,`listTargets`],ye=[`notificationOutput`,`listTargetKinds`];function U({kind:e,imgClassName:t,fallbackClassName:n}){return e?.iconUrl?b(`img`,{src:e.iconUrl,alt:e.label,className:t,loading:`lazy`,draggable:!1}):b(`span`,{className:n,children:e?.icon??`🔔`})}function be(){let e=S(),[r,i]=v({mode:`closed`}),[o,s]=v(null),c=g({queryKey:ve,queryFn:()=>e.trpcClient.notificationOutput.listTargets.query({})}),l=g({queryKey:ye,queryFn:async()=>(await e.trpcClient.notificationOutput.listTargetKinds.query({})).map(e=>{let t=e.iconUrl;return{...e,configSchema:e.configSchema,iconUrl:t}})}),f=h(()=>l.data??[],[l.data]),p=h(()=>{let e=new Map;for(let t of f)e.set(t.kind,t);return e},[f]),_=y({mutationFn:t=>e.trpcClient.notificationOutput.setTargetEnabled.mutate({addonId:t.target.addonId,targetId:t.target.id,enabled:t.enabled}),onSuccess:()=>void c.refetch()}),x=y({mutationFn:t=>e.trpcClient.notificationOutput.deleteTarget.mutate({addonId:t.addonId,targetId:t.id}),onSuccess:()=>void c.refetch()}),C=o?p.get(o.kind):void 0;return m(F,{icon:M,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:m(t,{size:`sm`,type:`button`,onClick:()=>i({mode:`pick-kind`}),children:[b(E,{className:`h-3.5 w-3.5`}),`Add target`]}),children:[c.isLoading&&b(`div`,{className:`flex items-center justify-center py-16`,children:b(j,{className:`h-6 w-6 animate-spin text-primary`})}),c.isError&&!c.isLoading&&b(n,{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&&b(`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&&b(u,{children:b(`ul`,{className:`divide-y divide-border`,children:(c.data??[]).map(e=>{let n=p.get(e.kind);return m(`li`,{className:`flex items-center gap-3 px-4 py-2.5`,children:[b(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface text-xs`,title:n?.label??e.kind,children:b(U,{kind:n,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:``})}),m(`div`,{className:`min-w-0 flex-1`,children:[b(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),b(`div`,{className:`text-[11px] text-foreground-subtle`,children:n?.label??e.kind})]}),!e.enabled&&b(a,{variant:`warning`,children:`disabled`}),b(d,{checked:e.enabled,onCheckedChange:t=>_.mutate({target:e,enabled:t}),"aria-label":`toggle ${e.name}`}),b(t,{size:`sm`,variant:`ghost`,type:`button`,disabled:!n,onClick:()=>s(e),title:`Test`,children:b(k,{className:`h-3.5 w-3.5`})}),b(t,{size:`sm`,variant:`ghost`,type:`button`,disabled:!n,onClick:()=>n&&i({mode:`form`,kind:n,target:e}),title:`Edit`,children:b(T,{className:`h-3.5 w-3.5`})}),b(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>x.mutate(e),title:`Delete`,children:b(P,{className:`h-3.5 w-3.5 text-danger`})})]},e.id)})})}),r.mode===`pick-kind`&&b(xe,{kinds:f,onCancel:()=>i({mode:`closed`}),onPick:e=>i({mode:`form`,kind:e,target:null})}),r.mode===`form`&&b(Se,{kind:r.kind,target:r.target,onCancel:()=>i({mode:`closed`}),onSaved:()=>{i({mode:`closed`}),c.refetch()}}),o&&C&&b(fe,{target:o,kind:C,open:!0,onClose:()=>s(null)})]})}function xe({kinds:e,onPick:n,onCancel:r}){let i=h(()=>me(e),[e]);return m(u,{className:`p-4 space-y-4`,children:[m(`div`,{className:`flex items-center justify-between`,children:[b(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Choose a notification kind`}),b(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:r,children:`Cancel`})]}),i.length===0&&b(`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=>m(`div`,{children:[b(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1.5`,children:e.addonId}),b(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-2`,children:e.kinds.map(t=>m(`button`,{type:`button`,onClick:()=>n(t),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:[b(U,{kind:t,imgClassName:`h-7 w-7 object-contain`,fallbackClassName:`text-lg leading-7`}),b(`span`,{className:`font-medium text-foreground`,children:t.label}),t.supportsDiscovery&&b(a,{variant:`info`,style:`outline`,children:`discover`})]},`${e.addonId}:${t.kind}`))})]},e.addonId))]})}function Se({kind:e,target:n,onSaved:i,onCancel:a}){let o=S(),s=h(()=>he(e.configSchema),[e.configSchema]),c=h(()=>n?.config??{},[n]),[l,d]=v(n?.name??e.label),[f,p]=v(()=>n?_e(n.config,s):{}),[g,_]=v(null),[x,C]=v(null),w=y({mutationFn:()=>o.trpcClient.notificationOutput.discoverTargets.query({addonId:e.addonId,kind:e.kind,config:f}),onSuccess:e=>_(e),onError:e=>C(e instanceof Error?e.message:`Discovery failed`)}),T=y({mutationFn:()=>{let t=ge(f,c,s),r={id:n?.id??`${e.kind}-${Date.now()}`,name:l,kind:e.kind,addonId:e.addonId,enabled:n?.enabled??!0,config:t};return o.trpcClient.notificationOutput.upsertTarget.mutate({addonId:e.addonId,target:r})},onSuccess:i,onError:e=>C(e instanceof Error?e.message:`Save failed`)}),E=e=>{d(e.suggestedName),p(t=>({...t,...e.config})),_(null)};return m(u,{className:`p-4 space-y-4`,children:[m(`div`,{className:`flex items-center justify-between`,children:[m(`h3`,{className:`text-sm font-semibold text-foreground flex items-center gap-2`,children:[b(U,{kind:e,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:`text-lg`}),n?`Edit ${n.name}`:`Add ${e.label} target`]}),b(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:a,children:`Cancel`})]}),x&&b(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:x}),m(`div`,{children:[b(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Name`}),b(`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:l,onChange:e=>d(e.target.value)})]}),e.supportsDiscovery&&m(`div`,{className:`space-y-2`,children:[m(t,{size:`sm`,variant:`outline`,type:`button`,disabled:w.isPending,onClick:()=>{C(null),w.mutate()},children:[w.isPending?b(j,{className:`h-3.5 w-3.5 animate-spin`}):b(O,{className:`h-3.5 w-3.5`}),`Discover`]}),g&&g.length===0&&b(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No candidates discovered.`}),g&&g.length>0&&b(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:g.map((e,t)=>m(`button`,{type:`button`,onClick:()=>E(e),className:`flex w-full items-center justify-between px-3 py-1.5 text-xs hover:bg-surface-hover`,children:[b(`span`,{className:`text-foreground`,children:e.suggestedName}),b(`span`,{className:`text-[10px] text-primary`,children:`use`})]},`${e.suggestedName}-${t}`))})]}),s.length>0&&n&&b(`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.`}),b(r,{schema:e.configSchema,values:f,onChange:p}),m(`div`,{className:`flex justify-end gap-2`,children:[b(t,{variant:`secondary`,size:`sm`,type:`button`,onClick:a,children:`Cancel`}),m(t,{size:`sm`,type:`button`,disabled:T.isPending||l.trim().length===0,onClick:()=>{C(null),T.mutate()},children:[T.isPending&&b(j,{className:`h-3.5 w-3.5 animate-spin`}),n?`Save changes`:`Create target`]})]})]})}var W=[{value:`immediate`,label:`Immediate`,hint:`Fires on the first matching detection of a track (lowest latency).`},{value:`track-end`,label:`Track end`,hint:`Evaluates the finalised track record when it closes.`},{value:`device-event`,label:`Device event`,hint:`Doorbell press / sensor state change on a linked device.`},{value:`package-event`,label:`Package event`,hint:`A parcel delivery or pick-up.`}];function Ce(e){return W.find(t=>t.value===e)?.label??e}function we(e){return W.find(t=>t.value===e)?.value}var G=[{value:`best`,label:`Best available image`,description:`The best subject crop available when the notification is sent.`},{value:`best-matching`,label:`Best matching image`,description:`The image that explains why the rule fired — the face crop for an identity rule, the plate crop for a plate rule; falls back to the best image otherwise.`},{value:`keyFrame`,label:`Key frame`,description:`The clean full scene frame with no subject box.`},{value:`none`,label:`No attachment`,description:`Send the notification with no image.`}];function Te(e){return G.find(t=>t.value===e)?.value}var Ee=[{value:`any`,label:`Any source`},{value:`pipeline`,label:`Pipeline`},{value:`onboard`,label:`Onboard (camera)`},{value:`sensor`,label:`Sensor`}],K=[{value:`delivered`,label:`Delivered`},{value:`picked-up`,label:`Picked up`},{value:`both`,label:`Both`}],De=[{value:`any`,label:`Any of`},{value:`all`,label:`All of`}],Oe=[{value:1,label:`1 — Min`},{value:2,label:`2 — Low`},{value:3,label:`3 — Default`},{value:4,label:`4 — High`},{value:5,label:`5 — Max`}];function ke(){return{name:``,enabled:!0,delivery:`immediate`,targetIds:[],targetParams:{},priority:3,mediaAttach:`best`,templateTitle:``,templateBody:``,conditions:{},schedule:void 0}}function Ae(e){let t={};for(let n of e.targets)n.params&&Object.keys(n.params).length>0&&(t[n.targetId]=n.params);return{name:e.name,enabled:e.enabled,delivery:e.delivery,targetIds:e.targets.map(e=>e.targetId),targetParams:t,priority:e.priority,mediaAttach:e.media.attach,templateTitle:e.template?.title??``,templateBody:e.template?.body??``,conditions:e.conditions,schedule:e.schedule}}function q(e){return e.name.trim().length>0&&e.targetIds.length>0}function J(e,t){return e.appliesTo.includes(t)}function je(e){if(e==null)return!0;if(Array.isArray(e))return e.length===0;if(typeof e==`string`)return e.length===0||e===`any`;if(typeof e==`number`)return!Number.isFinite(e);if(typeof e==`object`){if(`ids`in e){let t=e.ids;return!Array.isArray(t)||t.length===0}if(`values`in e){let t=e.values;return!Array.isArray(t)||t.length===0}return!1}return!1}function Me(e,t,n){let r=n.length===0?null:new Set(n.filter(e=>e.id!==`schedule`&&J(e,t)).map(e=>e.id)),i={};for(let[t,n]of Object.entries(e))r!==null&&!r.has(t)||je(n)||(i[t]=n);return i}function Ne(e){return e!==void 0&&e.windows.length>0}function Y(e,t,n=[]){let r=e.templateTitle.trim(),i=e.templateBody.trim(),a=r.length>0||i.length>0?{...r.length>0?{title:r}:{},...i.length>0?{body:i}:{}}:void 0,o=(n.length===0||n.some(t=>t.id===`schedule`&&J(t,e.delivery)))&&Ne(e.schedule)?e.schedule:void 0;return{name:e.name.trim(),enabled:e.enabled,delivery:e.delivery,conditions:Me(e.conditions,e.delivery,n),...o?{schedule:o}:{},targets:e.targetIds.map(t=>{let n=e.targetParams[t];return n&&Object.keys(n).length>0?{targetId:t,params:n}:{targetId:t}}),media:{attach:e.mediaAttach},throttle:t?.throttle??{cooldownSec:60,scope:`rule-device`},priority:e.priority,...a?{template:a}:{}}}p();var Pe=[{id:`scope`,label:`Scope`},{id:`class`,label:`Classes`},{id:`zones`,label:`Zones`},{id:`quality`,label:`Quality`},{id:`label`,label:`Identity & plates`},{id:`device`,label:`Device event`},{id:`package`,label:`Package`},{id:`schedule`,label:`Schedule`}],Fe=`block text-[11px] font-medium text-foreground`,X=`text-[10px] text-foreground-subtle mt-0.5`;function Ie({catalog:e,delivery:t,conditions:n,schedule:r,cameras:i,onConditionsChange:o,onScheduleChange:s}){let c=(e,t)=>{let r={...n};t===void 0?delete r[e]:r[e]=t,o(r)};return b(`div`,{className:`space-y-4`,children:Pe.map(t=>({...t,descriptors:e.filter(e=>e.group===t.id)})).filter(e=>e.descriptors.length>0).map(e=>m(`div`,{className:`space-y-2.5`,children:[b(`div`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:e.label}),e.descriptors.map(e=>{let o=J(e,t);return m(`div`,{className:o?``:`opacity-50`,"data-testid":`condition-${e.id}`,children:[m(`div`,{className:`flex items-center justify-between gap-2`,children:[b(`label`,{className:Fe,children:e.label}),!o&&m(a,{variant:`default`,children:[`not for `,e.appliesTo.join(` / `)]})]}),o?b(Le,{descriptor:e,conditions:n,schedule:r,cameras:i,onFieldChange:c,onScheduleChange:s}):b(`p`,{className:X,children:`Not evaluated for the selected trigger — switch the trigger to use it.`}),o&&e.description&&b(`p`,{className:X,children:e.description})]},e.id)})]},e.id))})}function Le({descriptor:e,conditions:t,schedule:n,cameras:r,onFieldChange:a,onScheduleChange:o}){switch(e.valueType){case`deviceIdList`:return b(Ke,{cameras:r,value:t.devices??[],onChange:e=>a(`devices`,e.length>0?e:void 0)});case`stringList`:{if(!ze(e.id))return null;let n=e.id;return b(Z,{value:He(t,n),placeholder:`Add value…`,onChange:e=>a(n,e.length>0?e:void 0)})}case`zoneIdList`:return b(Z,{value:t.zonesExclude??[],placeholder:`Zone id…`,onChange:e=>a(`zonesExclude`,e.length>0?e:void 0)});case`number01`:{if(!Ve(e.id))return null;let n=e.id;return b(Q,{value:Ue(t,n),min:0,max:1,step:.05,onChange:e=>a(n,e)})}case`number`:return b(Q,{value:t.minDwellSeconds,min:0,step:1,onChange:e=>a(`minDwellSeconds`,e)});case`sourceSelect`:return b(i,{value:t.source??`any`,options:Ee.map(e=>({value:e.value,label:e.label})),onChange:e=>a(`source`,We(e.target.value))});case`packagePhase`:return b(i,{value:t.packagePhase??``,options:[{value:``,label:`— any phase —`},...K.map(e=>({value:e.value,label:e.label}))],onChange:e=>a(`packagePhase`,Ge(e.target.value))});case`zoneSelection`:return b(qe,{value:t.zones,onChange:e=>a(`zones`,e)});case`plateMatcher`:return b(Je,{value:t.plates,onChange:e=>a(`plates`,e)});case`schedule`:return b(Qe,{value:n,onChange:o});default:return null}}var Re={classes:!0,classesExclude:!0,labelEquals:!0,identities:!0,identitiesExclude:!0,zonesExclude:!0,eventTypeTokens:!0,sensorKinds:!0};function ze(e){return Object.prototype.hasOwnProperty.call(Re,e)}var Be={minConfidence:!0,minImportance:!0,minLabelConfidence:!0};function Ve(e){return Object.prototype.hasOwnProperty.call(Be,e)}function He(e,t){let n=e[t];return Array.isArray(n)?n:[]}function Ue(e,t){let n=e[t];return typeof n==`number`?n:void 0}function We(e){if(e===`pipeline`||e===`onboard`||e===`sensor`||e===`any`)return e}function Ge(e){return K.find(t=>t.value===e)?.value}function Ke({cameras:e,value:t,onChange:n}){if(e.length===0)return b(`p`,{className:X,children:`No cameras available — the rule applies to all devices.`});let r=e=>n(t.includes(e)?t.filter(t=>t!==e):[...t,e]);return b(`div`,{className:`mt-1 max-h-40 overflow-y-auto rounded-md border border-border divide-y divide-border`,children:e.map(e=>m(`label`,{className:`flex items-center gap-2.5 px-3 py-1.5 text-xs text-foreground cursor-pointer hover:bg-surface-hover`,children:[b(`input`,{type:`checkbox`,checked:t.includes(e.id),onChange:()=>r(e.id),className:`accent-primary`}),b(`span`,{className:`flex-1 truncate`,children:e.name})]},e.id))})}function Z({value:t,placeholder:n,onChange:r}){let[i,a]=v(``),o=()=>{let e=i.trim();if(e.length===0||t.includes(e)){a(``);return}r([...t,e]),a(``)},s=e=>r(t.filter(t=>t!==e));return m(`div`,{className:`mt-1 space-y-1.5`,children:[t.length>0&&b(`div`,{className:`flex flex-wrap gap-1`,children:t.map(e=>m(`span`,{className:`inline-flex items-center gap-1 rounded bg-surface-hover px-1.5 py-0.5 text-[11px] text-foreground`,children:[e,b(`button`,{type:`button`,onClick:()=>s(e),"aria-label":`remove ${e}`,className:`text-foreground-subtle hover:text-danger`,children:b(ee,{className:`h-3 w-3`})})]},e))}),b(e,{value:i,placeholder:n,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),o())},onBlur:o})]})}function Q({value:t,min:n,max:r,step:i,onChange:a}){return m(`div`,{className:`mt-1 flex items-center gap-2`,children:[b(e,{type:`number`,value:t??``,min:n,max:r,step:i,className:`max-w-[8rem]`,onChange:e=>{let t=e.target.value;if(t===``){a(void 0);return}let n=Number(t);a(Number.isFinite(n)?n:void 0)}}),t!==void 0&&r!==void 0&&b(`input`,{type:`range`,min:n,max:r,step:i,value:t,onChange:e=>a(Number(e.target.value)),className:`flex-1 accent-primary`,"aria-label":`value`})]})}function qe({value:e,onChange:t}){let n=e?.ids??[],r=e?.match??`any`,a=e=>t(e.length>0?{ids:e,match:r}:void 0),o=e=>t(n.length>0?{ids:n,match:e}:void 0);return m(`div`,{className:`mt-1 space-y-1.5`,children:[b(`div`,{className:`max-w-[10rem]`,children:b(i,{value:r,options:De.map(e=>({value:e.value,label:e.label})),onChange:e=>o(e.target.value===`all`?`all`:`any`)})}),b(Z,{value:n,placeholder:`Zone id…`,onChange:a})]})}function Je({value:t,onChange:n}){let r=t?.values??[],i=t?.maxDistance??1,a=e=>n(e.length>0?{values:e,maxDistance:i}:void 0),o=e=>n(r.length>0?{values:r,maxDistance:e}:void 0);return m(`div`,{className:`mt-1 space-y-1.5`,children:[b(Z,{value:r,placeholder:`Plate text…`,onChange:a}),m(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[`Max distance`,b(e,{type:`number`,min:0,max:3,step:1,value:i,className:`max-w-[5rem]`,onChange:e=>{let t=Number(e.target.value);o(Number.isFinite(t)?Math.max(0,Math.min(3,t)):1)}})]})]})}var Ye=[{value:1,label:`Mon`},{value:2,label:`Tue`},{value:3,label:`Wed`},{value:4,label:`Thu`},{value:5,label:`Fri`},{value:6,label:`Sat`},{value:0,label:`Sun`}];function $(e){let t=Math.floor(e/60),n=e%60;return`${String(t).padStart(2,`0`)}:${String(n).padStart(2,`0`)}`}function Xe(e){let[t,n]=e.split(`:`),r=Number(t)*60+Number(n);return Number.isFinite(r)?Math.max(0,Math.min(1439,r)):0}function Ze(){return{days:[1,2,3,4,5],startMinute:540,endMinute:1080}}function Qe({value:e,onChange:t}){let n=e?.windows??[],r=e?.invert??!1,i=(n,r)=>{if(n.length===0){t(void 0);return}t({windows:n,...r?{invert:!0}:{},...e?.timezone?{timezone:e.timezone}:{}})},a=()=>i([...n,Ze()],r),o=e=>i(n.filter((t,n)=>n!==e),r),s=(e,t)=>i(n.map((n,r)=>r===e?t:n),r);return m(`div`,{className:`mt-1 space-y-2`,children:[n.length===0?b(`p`,{className:X,children:`Always active — add a window to restrict when the rule fires.`}):n.map((e,t)=>b($e,{window:e,onChange:e=>s(t,e),onRemove:()=>o(t)},t)),m(`div`,{className:`flex items-center gap-3`,children:[m(`button`,{type:`button`,onClick:a,className:`flex items-center gap-1 rounded-md bg-surface-hover px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground`,children:[b(E,{className:`h-3 w-3`}),` Add window`]}),n.length>0&&m(`label`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[b(`input`,{type:`checkbox`,checked:r,onChange:e=>i([...n],e.target.checked),className:`accent-primary`}),`Active outside the windows`]})]})]})}function $e({window:e,onChange:t,onRemove:n}){let r=n=>{let r=e.days.includes(n)?e.days.filter(e=>e!==n):[...e.days,n];r.length!==0&&t({...e,days:r})};return m(`div`,{className:`space-y-1.5 rounded-md border border-border p-2`,children:[m(`div`,{className:`flex items-center gap-2 text-xs`,children:[b(`input`,{type:`time`,value:$(e.startMinute),onChange:n=>t({...e,startMinute:Xe(n.target.value)}),className:`rounded-md border border-border bg-background px-1 py-0.5`}),b(`span`,{className:`text-foreground-subtle`,children:`→`}),b(`input`,{type:`time`,value:$(e.endMinute),onChange:n=>t({...e,endMinute:Xe(n.target.value)}),className:`rounded-md border border-border bg-background px-1 py-0.5`}),b(`span`,{className:`flex-1`}),b(`button`,{type:`button`,onClick:n,"aria-label":`Remove window`,className:`text-foreground-subtle hover:text-danger`,children:b(P,{className:`h-3.5 w-3.5`})})]}),b(`div`,{className:`flex flex-wrap gap-1`,children:Ye.map(t=>b(`button`,{type:`button`,onClick:()=>r(t.value),className:`rounded px-1.5 py-0.5 text-[10px] ${e.days.includes(t.value)?`bg-primary text-primary-foreground`:`bg-surface-hover text-foreground-subtle`}`,children:t.label},t.value))})]})}p();var et=[`notificationRules`,`listRules`],tt=[`notificationOutput`,`listTargets`,`forRules`],nt=[`notificationRules`,`getConditionCatalog`],rt=[`deviceManager`,`listAll`,`forRules`];function it(){let e=S(),[r,i]=v({mode:`closed`}),[o,s]=v(null),c=g({queryKey:et,queryFn:async()=>(await e.trpcClient.notificationRules.listRules.query({})).rules}),l=g({queryKey:tt,queryFn:()=>e.trpcClient.notificationOutput.listTargets.query({})}),f=g({queryKey:nt,queryFn:async()=>(await e.trpcClient.notificationRules.getConditionCatalog.query({})).catalog}),p=g({queryKey:rt,queryFn:async()=>(await e.trpcClient.deviceManager.listAll.query({})).filter(e=>e.type===x.Camera).map(e=>({id:e.id,name:e.name}))}),_=h(()=>{let e=new Map;for(let t of l.data??[])e.set(t.id,t.name);return e},[l.data]),C=y({mutationFn:t=>e.trpcClient.notificationRules.setRuleEnabled.mutate(t),onSuccess:()=>void c.refetch()}),D=y({mutationFn:t=>e.trpcClient.notificationRules.deleteRule.mutate({ruleId:t}),onSuccess:()=>{s(null),c.refetch()}}),O=c.data??[];return m(F,{icon:I,title:`Notification Rules`,subtitle:`Author rules that turn detections, doorbell presses and package events into notifications. Each rule picks a trigger, matches conditions and fans out to one or more delivery targets.`,actions:m(t,{size:`sm`,type:`button`,onClick:()=>i({mode:`form`,rule:null}),children:[b(E,{className:`h-3.5 w-3.5`}),`New rule`]}),children:[c.isLoading&&b(`div`,{className:`flex items-center justify-center py-16`,children:b(j,{className:`h-6 w-6 animate-spin text-primary`})}),c.isError&&!c.isLoading&&b(n,{title:`Failed to load rules`,message:c.error instanceof Error?c.error.message:`Unknown error`,onRetry:()=>void c.refetch()}),!c.isLoading&&!c.isError&&O.length===0&&b(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No notification rules yet. Click "New rule" to author one.`}),O.length>0&&b(u,{children:b(`ul`,{className:`divide-y divide-border`,children:O.map(e=>{let n=e.targets.length,r=e.targets[0]?_.get(e.targets[0].targetId)??e.targets[0].targetId:null,c=o===e.id;return m(`li`,{className:`flex flex-wrap items-center gap-3 px-4 py-2.5`,children:[m(`div`,{className:`min-w-0 flex-1`,children:[b(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),m(`div`,{className:`text-[11px] text-foreground-subtle flex flex-wrap items-center gap-x-2 gap-y-0.5`,children:[b(`span`,{children:Ce(e.delivery)}),b(`span`,{"aria-hidden":!0,children:`·`}),m(`span`,{children:[n,` target`,n===1?``:`s`,r&&n===1?` (${r})`:``]}),b(`span`,{"aria-hidden":!0,children:`·`}),m(`span`,{children:[`priority `,e.priority]})]})]}),!e.enabled&&b(a,{variant:`warning`,children:`disabled`}),b(d,{checked:e.enabled,onCheckedChange:t=>C.mutate({ruleId:e.id,enabled:t}),"aria-label":`toggle ${e.name}`}),b(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>i({mode:`form`,rule:e}),title:`Edit`,children:b(T,{className:`h-3.5 w-3.5`})}),b(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>i({mode:`form`,rule:{...e,id:``,name:`${e.name} (copy)`}}),title:`Duplicate`,children:b(w,{className:`h-3.5 w-3.5`})}),c?m(`span`,{className:`flex items-center gap-1.5`,children:[m(t,{size:`sm`,variant:`danger`,type:`button`,disabled:D.isPending,onClick:()=>D.mutate(e.id),children:[D.isPending&&b(j,{className:`h-3.5 w-3.5 animate-spin`}),`Confirm`]}),b(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>s(null),children:`Cancel`})]}):b(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>s(e.id),title:`Delete`,children:b(P,{className:`h-3.5 w-3.5 text-danger`})})]},e.id)})})}),r.mode===`form`&&b(at,{rule:r.rule,targets:l.data??[],catalog:f.data??[],cameras:p.data??[],onCancel:()=>i({mode:`closed`}),onSaved:()=>{i({mode:`closed`}),c.refetch()}})]})}function at({rule:n,targets:r,catalog:o,cameras:l,onSaved:u,onCancel:f}){let p=S(),h=n!=null&&n.id.length>0,[g,_]=v(()=>n?Ae(n):ke()),[x,C]=v(null),[w,T]=v(null),E=e=>_(t=>({...t,...e})),D=h&&n?{throttle:n.throttle}:void 0,O=y({mutationFn:async()=>{let e=Y(g,D,o);h&&n?await p.trpcClient.notificationRules.updateRule.mutate({ruleId:n.id,patch:e}):await p.trpcClient.notificationRules.createRule.mutate({rule:e})},onSuccess:u,onError:e=>C(e instanceof Error?e.message:`Save failed`)}),k=y({mutationFn:async()=>{let e=Y(g,D,o);return(await p.trpcClient.notificationRules.testRule.mutate({rule:e,lookbackMinutes:60})).results},onMutate:()=>T(null),onSuccess:e=>T(e),onError:e=>C(e instanceof Error?e.message:`Test failed`)}),A=g.targetIds.map(e=>r.find(t=>t.id===e)?.name??e),M=e=>E({targetIds:g.targetIds.includes(e)?g.targetIds.filter(t=>t!==e):[...g.targetIds,e]}),N=W.find(e=>e.value===g.delivery)?.hint;return b(c,{open:!0,onOpenChange:e=>!e&&f(),children:m(s,{width:`lg`,placement:`sheet-on-mobile`,children:[m(`div`,{className:`flex items-center justify-between mb-3`,children:[m(`h3`,{className:`text-sm font-semibold text-foreground flex items-center gap-2`,children:[b(I,{className:`h-4 w-4 text-foreground-subtle`}),h?`Edit ${n?.name}`:`New notification rule`]}),b(t,{size:`sm`,variant:`ghost`,type:`button`,onClick:f,children:`Cancel`})]}),x&&b(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger mb-3`,children:x}),m(`div`,{className:`space-y-4`,children:[m(`div`,{className:`flex items-end gap-3`,children:[m(`div`,{className:`min-w-0 flex-1`,children:[b(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Name`}),b(e,{value:g.name,onChange:e=>E({name:e.target.value}),placeholder:`e.g. Front door package`})]}),m(`label`,{className:`flex items-center gap-2 pb-1.5 text-[11px] font-medium text-foreground`,children:[b(d,{checked:g.enabled,onCheckedChange:e=>E({enabled:e}),"aria-label":`enabled`}),`Enabled`]})]}),m(`div`,{children:[b(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Trigger`}),b(i,{value:g.delivery,onChange:e=>{let t=we(e.target.value);t&&E({delivery:t})},options:W.map(e=>({value:e.value,label:e.label}))}),N&&b(`p`,{className:`text-[10px] text-foreground-subtle mt-1`,children:N})]}),m(`div`,{children:[b(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Delivery targets`}),r.length===0?b(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No delivery targets configured. Add one under the Targets tab first.`}):b(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:r.map(e=>m(`label`,{className:`flex items-center gap-2.5 px-3 py-1.5 text-xs text-foreground cursor-pointer hover:bg-surface-hover`,children:[b(`input`,{type:`checkbox`,checked:g.targetIds.includes(e.id),onChange:()=>M(e.id),className:`accent-primary`}),b(`span`,{className:`flex-1 truncate`,children:e.name}),!e.enabled&&b(a,{variant:`warning`,children:`disabled`})]},e.id))})]}),m(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[m(`div`,{children:[b(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Priority`}),b(i,{value:String(g.priority),onChange:e=>E({priority:Number(e.target.value)}),options:Oe.map(e=>({value:String(e.value),label:e.label}))})]}),m(`div`,{children:[b(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Media attachment`}),b(i,{value:g.mediaAttach,onChange:e=>{let t=Te(e.target.value);t&&E({mediaAttach:t})},options:G.map(e=>({value:e.value,label:e.label}))}),b(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:G.find(e=>e.value===g.mediaAttach)?.description})]})]}),m(`div`,{className:`space-y-2`,children:[m(`div`,{children:[b(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Notification title`}),b(e,{value:g.templateTitle,onChange:e=>E({templateTitle:e.target.value}),placeholder:`{{camera}} — {{class}}`})]}),m(`div`,{children:[b(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Notification body`}),b(`textarea`,{value:g.templateBody,onChange:e=>E({templateBody:e.target.value}),rows:2,placeholder:`{{label}} seen in {{zone}} at {{time}}`,className:`w-full rounded-md border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),m(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Leave blank to use the backend default text. Supported variables include`,` `,b(`code`,{children:`{{camera}}`}),`, `,b(`code`,{children:`{{class}}`}),`, `,b(`code`,{children:`{{label}}`}),`,`,` `,b(`code`,{children:`{{zone}}`}),`, `,b(`code`,{children:`{{confidence}}`}),`, `,b(`code`,{children:`{{time}}`}),`.`]})]}),m(`div`,{className:`rounded-md border border-border px-3 py-3`,children:[b(`div`,{className:`mb-2 text-[11px] font-semibold text-foreground`,children:`Conditions`}),o.length===0?b(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Condition catalog unavailable — this rule matches on its trigger and targets alone.`}):b(Ie,{catalog:o,delivery:g.delivery,conditions:g.conditions,schedule:g.schedule,cameras:l,onConditionsChange:e=>E({conditions:e}),onScheduleChange:e=>E({schedule:e})})]}),m(`div`,{className:`rounded-md border border-border px-3 py-3`,children:[m(`div`,{className:`flex items-center justify-between gap-2`,children:[b(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`Test rule`}),m(t,{size:`sm`,variant:`outline`,type:`button`,disabled:k.isPending||!q(g),onClick:()=>{C(null),k.mutate()},children:[k.isPending?b(j,{className:`h-3.5 w-3.5 animate-spin`}):b(ne,{className:`h-3.5 w-3.5`}),`Dry-run (last 60 min)`]})]}),b(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:`Evaluate the CURRENT (unsaved) rule against recently persisted records — no notification is sent.`}),w!==null&&b(ot,{delivery:g.delivery,results:w,targetNames:A})]})]}),m(`div`,{className:`flex justify-end gap-2 mt-4`,children:[b(t,{variant:`secondary`,size:`sm`,type:`button`,onClick:f,children:`Cancel`}),m(t,{size:`sm`,type:`button`,disabled:O.isPending||!q(g),onClick:()=>{C(null),O.mutate()},children:[O.isPending&&b(j,{className:`h-3.5 w-3.5 animate-spin`}),h?`Save changes`:`Create rule`]})]})]})})}function ot({delivery:e,results:t,targetNames:n}){if(e===`device-event`)return b(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:`Device-event rules cannot be dry-run: the sensor-event store has no cross-device scan surface, so a test returns no candidate records. The rule still fires live on a matching doorbell press / sensor change.`});if(t.length===0)return b(`p`,{className:`mt-2 text-[11px] text-foreground-subtle`,children:`No records in the last 60 minutes matched — nothing to evaluate.`});let r=t.filter(e=>e.wouldFire).length;return m(`div`,{className:`mt-2 space-y-1.5`,children:[m(`div`,{className:`text-[11px] text-foreground-subtle`,children:[r,` of `,t.length,` evaluated record`,t.length===1?``:`s`,` would fire.`]}),b(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:t.slice(0,50).map(e=>m(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5 text-[11px]`,children:[e.wouldFire?b(C,{className:`h-3.5 w-3.5 shrink-0 text-success`}):b(A,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),b(`span`,{className:`w-32 shrink-0 text-foreground-subtle`,children:new Date(e.timestamp).toLocaleString()}),m(`span`,{className:`w-14 shrink-0 text-foreground-subtle`,children:[`#`,e.deviceId]}),b(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:e.label??e.className??`object`}),e.wouldFire?m(`span`,{className:`shrink-0 truncate text-success`,children:[`→ `,n.join(`, `)||`targets`]}):e.failedCondition&&m(`span`,{className:`shrink-0 text-foreground-subtle`,children:[`failed: `,e.failedCondition]})]},e.recordId))})]})}p();var st=[{value:1,label:`Last hour`},{value:24,label:`Last 24 hours`},{value:168,label:`Last 7 days`},{value:0,label:`All time`}],ct=[{value:``,label:`Any status`},{value:`pending`,label:`Pending`},{value:`sent`,label:`Sent`},{value:`dead`,label:`Dead`}],lt=[50,100,250,500];function ut(){return{ruleId:``,deviceId:``,status:``,windowHours:24,limit:100}}function dt(e){return e===`pending`||e===`sent`||e===`dead`?e:void 0}function ft(e){switch(e){case`pending`:return`info`;case`sent`:return`success`;case`dead`:return`danger`}}function pt(){let e=S(),[t,n]=v(ut),r=e=>n(t=>({...t,...e})),a=g({queryKey:[`notificationRules`,`listRules`,`forHistory`],queryFn:async()=>(await e.trpcClient.notificationRules.listRules.query({})).rules}),o=g({queryKey:[`deviceManager`,`listAll`,`forHistory`],queryFn:async()=>(await e.trpcClient.deviceManager.listAll.query({})).filter(e=>e.type===x.Camera).map(e=>({id:e.id,name:e.name}))}),s=Date.now(),c=g({queryKey:[`notificationRules`,`getHistory`,t],retry:!1,queryFn:async()=>{let n=t.windowHours>0?s-t.windowHours*36e5:void 0;return(await e.trpcClient.notificationRules.getHistory.query({filter:{limit:t.limit,...t.ruleId?{ruleId:t.ruleId}:{},...t.deviceId?{deviceId:Number(t.deviceId)}:{},...dt(t.status)?{status:dt(t.status)}:{},...n===void 0?{}:{since:n}}})).entries}}),l=h(()=>{let e=new Map;for(let t of o.data??[])e.set(t.id,t.name);return e},[o.data]),d=e=>l.get(e)??`Camera #${String(e)}`,f=c.data??[],p=c.isError;return m(F,{icon:L,title:`Delivery history`,subtitle:`A searchable log of every notification the rules delivered (or failed to deliver).`,children:[m(`div`,{className:`mb-4 grid grid-cols-2 gap-2 sm:grid-cols-5`,children:[m(`div`,{children:[b(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Rule`}),b(i,{value:t.ruleId,onChange:e=>r({ruleId:e.target.value}),options:[{value:``,label:`All rules`},...(a.data??[]).map(e=>({value:e.id,label:e.name}))]})]}),m(`div`,{children:[b(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Camera`}),b(i,{value:t.deviceId,onChange:e=>r({deviceId:e.target.value}),options:[{value:``,label:`All cameras`},...(o.data??[]).map(e=>({value:String(e.id),label:e.name}))]})]}),m(`div`,{children:[b(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Status`}),b(i,{value:t.status,onChange:e=>r({status:e.target.value}),options:ct.map(e=>({value:e.value,label:e.label}))})]}),m(`div`,{children:[b(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Window`}),b(i,{value:String(t.windowHours),onChange:e=>r({windowHours:Number(e.target.value)}),options:st.map(e=>({value:String(e.value),label:e.label}))})]}),m(`div`,{children:[b(`label`,{className:`mb-1 block text-[10px] font-medium text-foreground-subtle`,children:`Limit`}),b(i,{value:String(t.limit),onChange:e=>r({limit:Number(e.target.value)}),options:lt.map(e=>({value:String(e),label:String(e)}))})]})]}),c.isLoading&&b(`div`,{className:`flex items-center justify-center py-16`,children:b(j,{className:`h-6 w-6 animate-spin text-primary`})}),p&&!c.isLoading&&b(u,{children:m(`div`,{className:`flex flex-col items-center gap-2 px-4 py-14 text-center`,children:[b(L,{className:`h-6 w-6 text-foreground-subtle`}),b(`div`,{className:`text-sm font-medium text-foreground`,children:`Delivery history requires a server update`}),b(`p`,{className:`max-w-md text-xs text-foreground-subtle`,children:`The history query is not available on this hub yet. It becomes queryable after the next server update ships the notification-center history endpoint. Rules still deliver and record their outcome in the meantime.`}),m(`button`,{type:`button`,onClick:()=>void c.refetch(),className:`mt-1 inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,children:[b(D,{className:`h-3 w-3`}),` Retry`]})]})}),!p&&!c.isLoading&&f.length===0&&b(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:`No deliveries match these filters.`}),!p&&f.length>0&&b(u,{children:b(`ul`,{className:`divide-y divide-border`,children:f.map(e=>b(mt,{entry:e,cameraName:d},e.id))})})]})}function mt({entry:e,cameraName:t}){let n=new Date(e.createdAt).toLocaleString(),r=e.subject.label??e.subject.className;return b(`li`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 px-4 py-2.5`,children:m(`div`,{className:`min-w-0 flex-1`,children:[m(`div`,{className:`flex items-center gap-2`,children:[b(`span`,{className:`truncate text-sm font-medium text-foreground`,children:e.ruleName}),b(a,{variant:ft(e.status),children:e.status})]}),m(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5 text-[11px] text-foreground-subtle`,children:[b(`span`,{children:n}),b(`span`,{"aria-hidden":!0,children:`·`}),b(`span`,{children:t(e.deviceId)}),b(`span`,{"aria-hidden":!0,children:`·`}),b(`span`,{children:r}),e.subject.confidence!==void 0&&m(_,{children:[b(`span`,{"aria-hidden":!0,children:`·`}),m(`span`,{children:[Math.round(e.subject.confidence*100),`%`]})]}),e.attempts>1&&m(_,{children:[b(`span`,{"aria-hidden":!0,children:`·`}),m(`span`,{children:[e.attempts,` attempts`]})]})]}),e.status===`dead`&&e.error&&b(`div`,{className:`mt-1 rounded border border-danger/30 bg-danger/10 px-2 py-1 text-[11px] text-danger`,children:e.error})]})})}function ht(){return b(`div`,{className:`flex flex-col p-4`,children:b(te,{tabs:[{id:`targets`,label:`Targets`,icon:M,content:b(be,{})},{id:`rules`,label:`Rules`,icon:I,content:b(it,{})},{id:`history`,label:`History`,icon:L,content:b(pt,{})}]})})}export{ht as NotificationsPage,ht as default};
|