@camstack/addon-admin-ui 1.1.76 → 1.1.77
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-2u_gFK5r.js → AddLocationWizard-WvmqxLGx.js} +1 -1
- package/dist/assets/{AddonCollectionPage-BtQi77vB.js → AddonCollectionPage-07_tB4Bs.js} +1 -1
- package/dist/assets/{Addons-q0boPiKK.js → Addons-ZT8aKXKy.js} +1 -1
- package/dist/assets/{AdminTabs-CfA0_5OD.js → AdminTabs-CSuSxCi3.js} +1 -1
- package/dist/assets/{AiProfiles-12yfskcw.js → AiProfiles-D1ZY-SZY.js} +1 -1
- package/dist/assets/{BrokerForm-nhcwidi1.js → BrokerForm-BPJHXmKe.js} +1 -1
- package/dist/assets/{Capabilities-BjMQsKTo.js → Capabilities-IFCBlDWs.js} +1 -1
- package/dist/assets/{CapabilityBadges-BakiZcjD.js → CapabilityBadges-Ckq9Mycx.js} +1 -1
- package/dist/assets/{Cluster-BwgzopHZ.js → Cluster-CwoTXn3F.js} +1 -1
- package/dist/assets/{ClusterRecordingTab-B0_gkStF.js → ClusterRecordingTab-B2YXJnWA.js} +1 -1
- package/dist/assets/{Dashboard-pQbzHfgq.js → Dashboard-B9QWTbys.js} +1 -1
- package/dist/assets/{Data-CzQQRAUi.js → Data-CpaCVIc4.js} +1 -1
- package/dist/assets/{DetectionIntelligence-soDZAfMX.js → DetectionIntelligence-Ifsew1GV.js} +1 -1
- package/dist/assets/{DeviceDetail-CDSavlTS.js → DeviceDetail-BuiL7I05.js} +1 -1
- package/dist/assets/{Devices-B6mG0goh.js → Devices-214Im5Tx.js} +1 -1
- package/dist/assets/{Events-C4TJ3f2M.js → Events-CZS3yW8S.js} +1 -1
- package/dist/assets/{FormBuilder-CJZT56JQ.js → FormBuilder-CKd7U6PQ.js} +1 -1
- package/dist/assets/{Identity-DJpfxWAy.js → Identity-7YdZbThU.js} +1 -1
- package/dist/assets/{IntegrationDetail-D_3Eadi3.js → IntegrationDetail-BBu4MxIr.js} +1 -1
- package/dist/assets/{Integrations-BlgB2KB5.js → Integrations-BOn1jaw7.js} +1 -1
- package/dist/assets/{Integrations-CUYz_Tx5.js → Integrations-TiuoTHdl.js} +1 -1
- package/dist/assets/{MyAccess-lJjPepDE.js → MyAccess-CwU6BK8E.js} +1 -1
- package/dist/assets/{Network-DEyTei_w.js → Network-BZnyWjBW.js} +1 -1
- package/dist/assets/{NodeAddonsSettingsPanel-xN6mgN_r.js → NodeAddonsSettingsPanel-CCcTKMq-.js} +1 -1
- package/dist/assets/{NodeInferenceDevices-BE0uWzGx.js → NodeInferenceDevices-Dt8WyD79.js} +1 -1
- package/dist/assets/{NotificationTargets-CBBur-rQ.js → NotificationTargets-DIcqRK5c.js} +1 -1
- package/dist/assets/{Pipeline-BZDLzg9Y.js → Pipeline-BFUBApua.js} +1 -1
- package/dist/assets/{Plates-DjJCFBtx.js → Plates-BaRkWDMF.js} +1 -1
- package/dist/assets/{ProviderIcon-D0fT0ngj.js → ProviderIcon-DX6PHSUD.js} +1 -1
- package/dist/assets/{Recordings-BwUOe7Le.js → Recordings-CrC16ONd.js} +1 -1
- package/dist/assets/{ScanNetworkModal-DH_k2Fpq.js → ScanNetworkModal-C8_aTQus.js} +1 -1
- package/dist/assets/{Settings-CcUo6aya.js → Settings-CUbjQRq2.js} +1 -1
- package/dist/assets/{Showroom-CG48sUa4.js → Showroom-D3gqnil5.js} +1 -1
- package/dist/assets/{build-cluster-graph-DHfHni5F.js → build-cluster-graph-D6vNpgZU.js} +1 -1
- package/dist/assets/circle-check-big-DxUdDrBY.js +1 -0
- package/dist/assets/clock-wm5Gg7Bk.js +1 -0
- package/dist/assets/{copy-BQOTIQgm.js → copy-CdEI-tHh.js} +1 -1
- package/dist/assets/{debounced-invalidate-DugdMzxI.js → debounced-invalidate-DrbGD620.js} +1 -1
- package/dist/assets/{download-CkwWo7hu.js → download-C8vWESxG.js} +1 -1
- package/dist/assets/{face-bbox-baLQCp2_.js → face-bbox-CO0C9-fS.js} +1 -1
- package/dist/assets/{index-Cf-I6XLC.js → index-B_KY_Mml.js} +2 -2
- package/dist/assets/{key-round-Bmr95jCJ.js → key-round-CncbzrvE.js} +1 -1
- package/dist/assets/{mf-entry-bootstrap-0-0623438d.js → mf-entry-bootstrap-0-458fa37e.js} +1 -1
- package/dist/assets/{pencil-B1DqIkdM.js → pencil-DbuWOCim.js} +1 -1
- package/dist/assets/plus-DUDfG-ml.js +1 -0
- package/dist/assets/{radio-BZuhT7Gn.js → radio-C6fjCnWo.js} +1 -1
- package/dist/assets/{refresh-cw-BmmNps1s.js → refresh-cw-DWk04DIC.js} +1 -1
- package/dist/assets/{rotate-ccw-ShbJ-WX6.js → rotate-ccw-B6sOx3m_.js} +1 -1
- package/dist/assets/rotate-cw-Cjewz_pr.js +1 -0
- package/dist/assets/search-De-JtIxP.js +1 -0
- package/dist/assets/{send-BeH97ECp.js → send-DBAj2ECl.js} +1 -1
- package/dist/assets/{server-v0X3NJkl.js → server-ESggM91w.js} +1 -1
- package/dist/assets/square-B088IYto.js +1 -0
- package/dist/assets/{square-check-big-DnKLHlgq.js → square-check-big-C0BtosG_.js} +1 -1
- package/dist/assets/{upload-DDoEZa7L.js → upload-B5sB6Z9M.js} +1 -1
- package/dist/assets/{wifi-FAJILiwT.js → wifi-BFZqIDoC.js} +1 -1
- package/dist/assets/{zap-Daoo8ovU.js → zap-Cywg_7qu.js} +1 -1
- package/dist/index.html +2 -2
- package/dist/server/addon.js +1 -1
- package/package.json +1 -1
- package/dist/assets/circle-check-big-CI9FWu6l.js +0 -1
- package/dist/assets/clock-4_YZJVgL.js +0 -1
- package/dist/assets/plus-MB1SLBFq.js +0 -1
- package/dist/assets/rotate-cw-BVat1OfU.js +0 -1
- package/dist/assets/search-BmUqqa8F.js +0 -1
- package/dist/assets/square-DNYsOuV5.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Cr as e,Dr as t,Er as n,Mr as r,Nr as i,Or as a,Ra as o,Sr as s,Tr as c,Za as l,_a as u,bo as d,br as f,bt as p,jr as m,vo as h,wr as g,xr as _,xt as v,yo as y,yr as ee}from"./src-CjsGEszD.js";import{I as b,Q as x,S,W as C,b as w,o as T,q as E,x as D,z as te}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{o as O,s as k}from"./src-CCZM6rtM.js";import{p as A}from"./player-overlays-BfnV1C0Q.js";import{n as j,t as ne}from"./rotate-ccw-ShbJ-WX6.js";import{t as M}from"./copy-BQOTIQgm.js";import{n as re,t as N}from"./AddonCollectionPage-BtQi77vB.js";import{t as ie}from"./refresh-cw-BmmNps1s.js";import{t as P}from"./server-v0X3NJkl.js";import{t as ae}from"./square-DNYsOuV5.js";import{t as oe}from"./wifi-FAJILiwT.js";import{L as se,S as F,T as I,W as L,b as ce,i as le,k as R,l as ue,o as z,v as B,x as de}from"./index-Cf-I6XLC.js";import{t as V}from"./AdminPage-BwmGKnRf.js";import{t as H}from"./AdminTabs-CfA0_5OD.js";import{t as U}from"./addon-display-names-DvSEQty-.js";var fe=L(`log-in`,[[`path`,{d:`m10 17 5-5-5-5`,key:`1bsop3`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`,key:`u53s6r`}]]),W=L(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]),G=L(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]);x();var K=5e3,pe={connected:!1,endpoint:null};function me(){let e=T(),t=v({capName:`network-access`},{refetchInterval:K}),n=p(void 0,{refetchInterval:K}),a=C(()=>U(n.data??[]),[n.data]),o=C(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:a.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,a]),[s,c]=E(null),[l,u]=E({}),d=(t,n)=>{let r=n?.addonId;e.invalidateQueries({queryKey:[[`networkAccess`,`getStatus`],{input:{addonId:r},type:`query`}]}),c(null),u(e=>{if(r===void 0||!(r in e))return e;let t={...e};return delete t[r],t})},f=(e,t)=>{c(null);let n=t?.addonId;if(n===void 0)return;let r=e instanceof Error?e.message:String(e);u(e=>({...e,[n]:r}))},m=r({onSuccess:d,onError:f}),h=i({onSuccess:d,onError:f});return D(N,{title:`Remote Access`,subtitle:`Public-facing tunnels that expose this hub to the internet (Cloudflare Tunnel, ngrok, …). Settings, Logs and Events are docked under every provider.`,pageIcon:I,itemIcon:I,capability:`network-access`,installButtonLabel:`Add tunnel`,items:o,isLoading:t.isLoading,emptyTitle:`No remote-access providers installed`,emptyDescription:`Install a tunnel addon (e.g. @camstack/addon-cloudflare) to expose this hub publicly.`,renderStatusBadges:e=>D(he,{addonId:e.addonId}),itemError:e=>l[e.addonId]??null,renderPrimaryAction:e=>D(ge,{addonId:e.addonId,busyId:s,onStart:e=>{c(e),m.mutate({addonId:e})},onStop:e=>{c(e),h.mutate({addonId:e})}})})}function q(e){let{data:t}=m({addonId:e},{refetchInterval:K,retry:!1}),n=t?k.safeParse(t):null;return n?.success?n.data:pe}function he({addonId:e}){let t=q(e);return S(w,{children:[D(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.connected?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.connected?`Connected`:`Disconnected`}),t.endpoint&&S(`a`,{href:t.endpoint.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-[10px] text-emerald-700 dark:text-emerald-300 hover:underline flex items-center gap-1`,children:[D(R,{className:`h-3 w-3`}),t.endpoint.url]})]})}function ge({addonId:e,busyId:t,onStart:n,onStop:r}){let i=q(e),a=t===e;return i.connected?S(d,{size:`sm`,variant:`secondary`,disabled:a,onClick:()=>r(e),children:[a?D(F,{className:`h-3 w-3 animate-spin`}):D(ae,{className:`h-3 w-3`}),`Stop`]}):S(d,{size:`sm`,variant:`primary`,disabled:a,onClick:()=>n(e),children:[a?D(F,{className:`h-3 w-3 animate-spin`}):D(re,{className:`h-3 w-3`}),`Start`]})}x();var J=3e4;function _e(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function ve(){let e=v({capName:`turn-provider`},{refetchInterval:J}),t=p(void 0,{refetchInterval:J}),n=u(),r=n.data??[],i=C(()=>U(t.data??[]),[t.data]);return D(N,{title:`TURN Servers`,subtitle:`ICE servers used for WebRTC NAT traversal. Multiple providers can coexist — the WebRTC layer concatenates servers from all enabled providers per session.`,pageIcon:B,itemIcon:B,capability:`turn-provider`,installButtonLabel:`Add provider`,items:C(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:i.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,i]),isLoading:e.isLoading,emptyTitle:`No TURN providers installed`,emptyDescription:`Install a TURN addon (e.g. @camstack/addon-cloudflare) to enable WebRTC behind restrictive NATs.`,renderExpandedPanel:e=>D(ye,{addonId:e.addonId,enabled:e.isActive}),trailing:S(h,{children:[S(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[S(`div`,{children:[D(`div`,{className:`text-sm font-semibold`,children:`Combined ICE server list`}),D(`div`,{className:`text-xs text-foreground-subtle`,children:`What the WebRTC layer fetches per-session.`})]}),D(d,{size:`sm`,variant:`secondary`,onClick:()=>n.refetch(),disabled:n.isFetching,children:`Refresh`})]}),D(`div`,{className:`p-4`,children:r.length===0?D(`div`,{className:`text-xs text-foreground-subtle`,children:`No servers from enabled providers.`}):D(`div`,{className:`flex flex-col gap-3`,children:r.map((e,t)=>{let n=Array.isArray(e.urls)?e.urls:[e.urls];return S(`div`,{className:`rounded border border-border bg-surface`,children:[(e.username||e.credential)&&S(`div`,{className:`px-3 py-1.5 border-b border-border text-[10px] font-mono text-foreground-subtle flex items-center gap-3`,children:[e.username&&S(`span`,{children:[D(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,D(`span`,{className:`text-foreground`,children:e.username})]}),e.credential&&S(`span`,{children:[D(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,D(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),D(`ul`,{className:`divide-y divide-border`,children:n.map(e=>D(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},t)})})})]})})}function ye({addonId:e,enabled:t}){let n=u({addonId:e},{enabled:t,retry:!1}),r=C(()=>_e(n.data??[]),[n.data]);return!t||r.length===0?null:S(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[S(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Discovered ICE servers (`,r.length,`)`]}),D(`div`,{className:`flex flex-wrap gap-1`,children:r.map(e=>D(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground`,children:e},e))})]})}x();var be={lan:B,wifi:oe,docker:j,vpn:de,loopback:P,other:P},xe={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},Se=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function Ce(e){let{interfaces:t,disabled:n,hideLoopback:r,ipv4Only:i,emptyMessage:a}=e,o=C(()=>t.filter(e=>!(r&&e.kind===`loopback`||i&&e.family!==`IPv4`)),[t,r,i]),s=C(()=>{let e=new Map;for(let t of o){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return Se.filter(t=>e.has(t)).map(t=>({kind:t,items:e.get(t)}))},[o]),c=t=>e.mode===`single`?e.value===t:e.value.includes(t),l=t=>{if(n||t.kind===`loopback`)return;if(e.mode===`single`){e.onChange(e.value===t.address?null:t.address);return}let r=new Set(e.value);r.has(t.address)?r.delete(t.address):r.add(t.address),e.onChange([...r])};return o.length===0?D(`div`,{className:`text-xs text-foreground-subtle italic`,children:a??`No addresses available.`}):D(`div`,{className:`flex flex-col gap-3`,children:s.map(({kind:t,items:r})=>S(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[S(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[D(be[t]??P,{className:`h-3.5 w-3.5 text-foreground-subtle`}),D(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:xe[t]??t}),S(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,r.length]})]}),D(`ul`,{className:`divide-y divide-border`,children:r.map(t=>{let r=c(t.address),i=t.kind===`loopback`,a=!t.plausible&&!i;return S(`li`,{className:`flex items-center gap-3 px-3 py-2 ${i?`opacity-60 cursor-not-allowed`:n?`opacity-60`:a?`cursor-pointer hover:bg-surface-hover/30 bg-amber-500/[0.04]`:`cursor-pointer hover:bg-surface-hover/30`}`,onClick:()=>l(t),children:[D(`span`,{className:`flex items-center justify-center h-4 w-4 rounded ${e.mode===`single`?`rounded-full`:`rounded`} border ${r?`border-primary bg-primary text-primary-foreground`:`border-border bg-surface`}`,children:r&&D(se,{className:`h-3 w-3`})}),S(`div`,{className:`flex-1 min-w-0 ${a?`text-foreground-subtle`:``}`,children:[S(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[D(`span`,{className:`font-mono text-xs font-semibold ${a?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),D(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-mono`,children:t.family}),t.preferred&&D(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:`Auto-preferred`}),i&&D(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:`Always included`}),a&&S(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:t.plausibleReason||void 0,children:[D(z,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]}),S(`div`,{className:`text-xs text-foreground-subtle mt-0.5 font-mono break-all`,children:[t.address,t.cidr&&t.cidr!==t.address?` (${t.cidr})`:``]})]})]},`${t.name}-${t.family}-${t.address}`)})})]},t))})}x();var Y={"lan-ipv4":`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,"lan-ipv6":`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`,loopback:`bg-foreground-subtle/15 text-foreground-subtle`};function we(){let t=T(),n=A(),r=_(void 0,{refetchInterval:3e4}),i=ee(void 0),a=e({onSuccess:()=>{t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),o=s({onSuccess:e=>{p(e.addresses),t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),c=C(()=>r.data?.interfaces??[],[r.data]),l=f({port:typeof window<`u`?Number(window.location.port)||(window.location.protocol===`https:`?443:80):4e3,scheme:typeof window<`u`&&window.location.protocol===`https:`?`https`:`http`},{refetchInterval:3e4}),[u,p]=E([]),[m,g]=E(!1);te(()=>{!m&&i.data&&(p(i.data.addresses),g(!0))},[i.data,m]);let v=i.data?.addresses??[],y=C(()=>{if(u.length!==v.length)return!0;let e=[...u].toSorted(),t=[...v].toSorted();return e.some((e,n)=>e!==t[n])},[u,v]),b=()=>{a.mutate({addresses:[...u]})},x=()=>{p(v)},w=()=>{p([])},O=()=>{r.refetch(),l.refetch(),i.refetch()},k=async()=>{try{let e=await n.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info(`[network-addresses] race result`,e)}catch(e){console.warn(`[network-addresses] race failed`,e)}},j=l.data?.endpoints??[];return S(V,{children:[S(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[D(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Pick the local addresses SDK clients should race for the fastest path to this hub. Empty selection (auto) lets every non-loopback / non-link-local interface participate.`}),S(`div`,{className:`flex items-center gap-2 shrink-0`,children:[S(d,{size:`sm`,variant:`secondary`,onClick:O,disabled:r.isLoading,children:[D(ie,{className:`h-3 w-3 ${r.isLoading?`animate-spin`:``}`}),`Refresh`]}),D(d,{size:`sm`,variant:`secondary`,onClick:k,children:`Probe race`})]})]}),S(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[S(h,{children:[S(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[S(`div`,{children:[D(`div`,{className:`text-sm font-semibold`,children:`Allowed addresses`}),D(`div`,{className:`text-xs text-foreground-subtle`,children:u.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${u.length} pinned`})]}),S(`div`,{className:`flex items-center gap-1`,children:[S(d,{size:`sm`,variant:`secondary`,onClick:()=>o.mutate(void 0),disabled:o.isPending||a.isPending,title:`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`,children:[D(ue,{className:`h-3 w-3`}),o.isPending?`Detecting…`:`Best match`]}),S(d,{size:`sm`,variant:`secondary`,onClick:w,disabled:u.length===0||a.isPending,children:[D(ne,{className:`h-3 w-3`}),`Clear`]}),y&&D(d,{size:`sm`,variant:`secondary`,onClick:x,disabled:a.isPending,children:`Discard`}),S(d,{size:`sm`,variant:`primary`,onClick:b,disabled:!y||a.isPending,children:[D(W,{className:`h-3 w-3`}),a.isPending?`Saving…`:`Save`]})]})]}),D(`div`,{className:`p-4`,children:D(Ce,{mode:`multiple`,interfaces:c,value:u,onChange:p,disabled:a.isPending,emptyMessage:r.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),S(h,{children:[S(`div`,{className:`px-4 py-3 border-b border-border`,children:[D(`div`,{className:`text-sm font-semibold`,children:`Connection endpoints — priority order`}),D(`div`,{className:`text-xs text-foreground-subtle`,children:`Live preview of the ranked candidate list the SDK would race against. Updates with each Save.`})]}),D(`div`,{className:`p-4`,children:j.length===0?D(`div`,{className:`text-xs text-foreground-subtle italic`,children:l.isLoading?`Loading…`:`No endpoints available.`}):D(`ul`,{className:`space-y-1 text-xs`,children:j.map(e=>S(`li`,{className:`flex items-center gap-2 flex-wrap ${e.plausible?``:`opacity-80`}`,children:[D(`span`,{className:`font-mono text-[10px] w-10 text-foreground-subtle`,children:String(e.priority).padStart(4,`0`)}),D(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${Y[e.kind]??Y.loopback}`,children:e.kind}),e.interfaceKind!==`lan`&&e.interfaceKind!==`public`&&D(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-medium uppercase`,children:e.interfaceKind}),!e.plausible&&e.interfaceKind!==`loopback`&&S(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:e.plausibleReason||void 0,children:[D(z,{className:`h-2.5 w-2.5`}),`Unlikely usable`]}),D(`span`,{className:`font-mono break-all ${e.plausible?`text-foreground`:`text-foreground-subtle`}`,children:e.baseUrl}),S(`span`,{className:`text-foreground-subtle`,children:[`— `,e.label]})]},`${e.priority}-${e.baseUrl}`))})})]})]})]})}x();var Te={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},X=5e3,Ee=3e4,De={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function Oe(){let e=v({capName:`mesh-network`},{refetchInterval:X}),t=p(void 0,{refetchInterval:X}),n=C(()=>U(t.data??[]),[t.data]);return D(N,{title:`Mesh Networks`,subtitle:`Private VPN meshes that connect CamStack to your other devices (Tailscale, Headscale, …). Each provider can also expose this hub publicly via its ingress (Tailscale Funnel).`,pageIcon:j,itemIcon:B,capability:`mesh-network`,installButtonLabel:`Add mesh`,items:C(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,n]),isLoading:e.isLoading,emptyTitle:`No mesh-network providers installed`,emptyDescription:`Install a mesh addon (e.g. @camstack/addon-tailscale) to join this hub into a private VPN mesh.`,renderStatusBadges:e=>D(ke,{addonId:e.addonId}),renderPrimaryAction:e=>D(Ae,{addonId:e.addonId}),renderExpandedPanel:e=>D(je,{addonId:e.addonId})})}function Z(e){let{data:t,isLoading:n}=g({addonId:e},{refetchInterval:X,retry:!1}),r=t?O.safeParse(t):null;return{status:r?.success?r.data:De,isLoading:n}}function ke({addonId:e}){let{status:t}=Z(e);return S(w,{children:[D(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.joined?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.joined?`Joined`:`Not joined`}),t.joined&&S(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:[t.peerCount,` peer`,t.peerCount===1?``:`s`]})]})}function Ae({addonId:e}){let n=T(),[r,i]=E(!1),[o,s]=E(null),l=A(),{status:u}=Z(e),f=b(()=>{n.invalidateQueries({queryKey:[[`meshNetwork`]]})},[n]),p=a(),m=c({onSuccess:f}),h=t({onSuccess:f}),g=b(async()=>{i(!0);let t={cancelled:!1};s(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 Ie(2e3),!t.cancelled);){let t=await l.trpcClient.meshNetwork.getStatus.query({addonId:e}).catch(()=>null),n=t?O.safeParse(t):null;if(n?.success&&n.data.joined){f();break}if(Date.now()-r>6e5)break}}finally{i(!1),s(null)}},[e,f,p,l]),_=b(()=>{o&&(o.cancelled=!0),i(!1),s(null)},[o]);return D(w,{children:u.joined?S(w,{children:[S(d,{size:`sm`,variant:`secondary`,disabled:m.isPending,onClick:()=>m.mutate({addonId:e}),children:[m.isPending?D(F,{className:`h-3 w-3 animate-spin`}):D(ce,{className:`h-3 w-3`}),`Disconnect`]}),S(d,{size:`sm`,variant:`ghost`,disabled:h.isPending,onClick:()=>h.mutate({addonId:e}),children:[h.isPending?D(F,{className:`h-3 w-3 animate-spin`}):D(G,{className:`h-3 w-3`}),`Log out`]})]}):r?S(d,{size:`sm`,variant:`ghost`,onClick:_,children:[D(le,{className:`h-3 w-3 mr-1`}),` Cancel`]}):S(w,{children:[S(d,{size:`sm`,variant:`primary`,onClick:()=>void g(),children:[D(fe,{className:`h-3 w-3`}),`Connect`]}),S(d,{size:`sm`,variant:`ghost`,disabled:h.isPending,onClick:()=>h.mutate({addonId:e}),children:[h.isPending?D(F,{className:`h-3 w-3 animate-spin`}):D(G,{className:`h-3 w-3`}),`Log out`]})]})})}function je({addonId:e}){let{status:t}=Z(e),r=n({addonId:e},{refetchInterval:Ee,retry:!1});return S(`div`,{className:`rounded-lg border border-border bg-surface`,children:[S(`div`,{className:`p-4 space-y-4`,children:[t.error&&D(o,{message:t.error}),D(Me,{status:t}),t.endpoints.length>0&&S(`div`,{className:`space-y-1.5`,children:[D(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Endpoints`}),t.endpoints.map(e=>S(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[S(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${Te[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?D(I,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),S(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-emerald-700 dark:text-emerald-300 hover:underline break-all flex items-center gap-1`,children:[D(R,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),D(`div`,{className:`border-t border-border`,children:D(Pe,{peers:r.data?.peers??[],loading:r.isLoading})})]})}function Me({status:e}){return D(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-1.5`,children:[{label:`Tenant`,value:e.tenantName||`—`},{label:`User`,value:e.userLogin??`—`},{label:`Control plane`,value:e.controlPlaneUrl||`—`},{label:`Mesh IP`,value:e.meshIp||`—`,mono:!0},{label:`MagicDNS`,value:e.magicDnsHostname||`—`,mono:!0},{label:`DNS suffix`,value:e.magicDnsSuffix||`—`,mono:!0},{label:`Peers`,value:String(e.peerCount)},{label:`Key expiry`,value:e.keyExpiry?Ne(e.keyExpiry):`—`}].map(e=>S(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[D(`span`,{className:`text-foreground-subtle shrink-0`,children:e.label}),D(`span`,{className:`text-foreground truncate ${e.mono?`font-mono`:``}`,children:e.value})]},e.label))})}function Ne(e){let t=e-Date.now();if(t<0)return`Expired ${$(e)}`;let n=Math.floor(t/864e5);if(n>60)return new Date(e).toLocaleDateString();if(n>1)return`in ${n} days`;let r=Math.floor(t/36e5);return r>1?`in ${r}h`:`in ${Math.max(1,Math.floor(t/6e4))} min`}function Pe({peers:e,loading:t}){let n=C(()=>e.map(e=>({...e,_id:e.id})),[e]),r=b(e=>{e&&navigator.clipboard?.writeText(e)},[]),i=C(()=>[{key:`hostname`,header:`Hostname`,render:e=>S(`div`,{className:`flex flex-col`,children:[S(`div`,{className:`flex items-center gap-1.5`,children:[D(`span`,{className:`font-medium text-foreground`,children:e.hostname||`(unknown)`}),e.isSelf&&D(y,{variant:`info`,children:`self`}),e.exitNodeOption&&D(y,{variant:`warning`,children:`exit-node`})]}),e.userLogin&&D(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.userLogin})]})},{key:`magicDns`,header:`MagicDNS`,render:e=>e.magicDns?S(`div`,{className:`flex items-center gap-1`,children:[D(`span`,{className:`font-mono text-xs truncate`,children:e.magicDns}),D(`button`,{onClick:()=>r(e.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy MagicDNS`,children:D(M,{className:`h-3 w-3 text-foreground-subtle`})})]}):D(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:e=>{let t=e.addresses[0]??``;return t?S(`div`,{className:`flex items-center gap-1`,children:[D(`span`,{className:`font-mono text-xs`,children:t}),D(`button`,{onClick:()=>r(t),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy IP`,children:D(M,{className:`h-3 w-3 text-foreground-subtle`})})]}):D(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:`Connection`,render:e=>S(`div`,{className:`flex items-center gap-1.5`,children:[D(y,{variant:Fe(e.connection),children:e.connection}),e.relay&&D(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.relay})]})},{key:`routes`,header:`Routes`,render:e=>e.advertisedRoutes.length>0?D(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):D(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:`TX / RX`,render:e=>S(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,Q(e.txBytes),` · ↓ `,Q(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>D(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?$(e.lastSeenMs):`—`})}],[r]);return t&&e.length===0?S(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[D(F,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):e.length===0?D(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No peers visible — your tailnet may be empty or the host is not joined.`}):D(`div`,{className:`p-4`,children:D(l,{columns:i,rows:n,rowKey:e=>e._id,minWidthPx:820})})}function Fe(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function Q(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)}MB`:`${(e/1024/1024/1024).toFixed(2)}GB`}function $(e){let t=Date.now()-e;return t<6e4?`just now`:t<36e5?`${Math.round(t/6e4)}m ago`:t<864e5?`${Math.round(t/36e5)}h ago`:`${Math.round(t/864e5)}d ago`}function Ie(e){return new Promise(t=>setTimeout(t,e))}function Le(){return D(`div`,{className:`flex flex-col p-4`,children:D(H,{tabs:[{id:`addresses`,label:`Network Addresses`,icon:P,content:D(we,{})},{id:`remote-access`,label:`Remote Access`,icon:I,content:D(me,{})},{id:`mesh`,label:`Mesh Networks`,icon:j,content:D(Oe,{})},{id:`turn`,label:`TURN Servers`,icon:B,content:D(ve,{})}]})})}export{Le as NetworkPage};
|
|
1
|
+
import{Cr as e,Dr as t,Er as n,Mr as r,Nr as i,Or as a,Ra as o,Sr as s,Tr as c,Za as l,_a as u,bo as d,br as f,bt as p,jr as m,vo as h,wr as g,xr as _,xt as v,yo as y,yr as ee}from"./src-CjsGEszD.js";import{I as b,Q as x,S,W as C,b as w,o as T,q as E,x as D,z as te}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{o as O,s as k}from"./src-CCZM6rtM.js";import{p as A}from"./player-overlays-BfnV1C0Q.js";import{n as j,t as ne}from"./rotate-ccw-B6sOx3m_.js";import{t as M}from"./copy-CdEI-tHh.js";import{n as re,t as N}from"./AddonCollectionPage-07_tB4Bs.js";import{t as ie}from"./refresh-cw-DWk04DIC.js";import{t as P}from"./server-ESggM91w.js";import{t as ae}from"./square-B088IYto.js";import{t as oe}from"./wifi-BFZqIDoC.js";import{L as se,S as F,T as I,W as L,b as ce,i as le,k as R,l as ue,o as z,v as B,x as de}from"./index-B_KY_Mml.js";import{t as V}from"./AdminPage-BwmGKnRf.js";import{t as H}from"./AdminTabs-CSuSxCi3.js";import{t as U}from"./addon-display-names-DvSEQty-.js";var fe=L(`log-in`,[[`path`,{d:`m10 17 5-5-5-5`,key:`1bsop3`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`,key:`u53s6r`}]]),W=L(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]),G=L(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]);x();var K=5e3,pe={connected:!1,endpoint:null};function me(){let e=T(),t=v({capName:`network-access`},{refetchInterval:K}),n=p(void 0,{refetchInterval:K}),a=C(()=>U(n.data??[]),[n.data]),o=C(()=>(t.data??[]).map(e=>({addonId:e.addonId,displayName:a.get(e.addonId)??e.addonId,isActive:e.isActive})),[t.data,a]),[s,c]=E(null),[l,u]=E({}),d=(t,n)=>{let r=n?.addonId;e.invalidateQueries({queryKey:[[`networkAccess`,`getStatus`],{input:{addonId:r},type:`query`}]}),c(null),u(e=>{if(r===void 0||!(r in e))return e;let t={...e};return delete t[r],t})},f=(e,t)=>{c(null);let n=t?.addonId;if(n===void 0)return;let r=e instanceof Error?e.message:String(e);u(e=>({...e,[n]:r}))},m=r({onSuccess:d,onError:f}),h=i({onSuccess:d,onError:f});return D(N,{title:`Remote Access`,subtitle:`Public-facing tunnels that expose this hub to the internet (Cloudflare Tunnel, ngrok, …). Settings, Logs and Events are docked under every provider.`,pageIcon:I,itemIcon:I,capability:`network-access`,installButtonLabel:`Add tunnel`,items:o,isLoading:t.isLoading,emptyTitle:`No remote-access providers installed`,emptyDescription:`Install a tunnel addon (e.g. @camstack/addon-cloudflare) to expose this hub publicly.`,renderStatusBadges:e=>D(he,{addonId:e.addonId}),itemError:e=>l[e.addonId]??null,renderPrimaryAction:e=>D(ge,{addonId:e.addonId,busyId:s,onStart:e=>{c(e),m.mutate({addonId:e})},onStop:e=>{c(e),h.mutate({addonId:e})}})})}function q(e){let{data:t}=m({addonId:e},{refetchInterval:K,retry:!1}),n=t?k.safeParse(t):null;return n?.success?n.data:pe}function he({addonId:e}){let t=q(e);return S(w,{children:[D(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.connected?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.connected?`Connected`:`Disconnected`}),t.endpoint&&S(`a`,{href:t.endpoint.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-[10px] text-emerald-700 dark:text-emerald-300 hover:underline flex items-center gap-1`,children:[D(R,{className:`h-3 w-3`}),t.endpoint.url]})]})}function ge({addonId:e,busyId:t,onStart:n,onStop:r}){let i=q(e),a=t===e;return i.connected?S(d,{size:`sm`,variant:`secondary`,disabled:a,onClick:()=>r(e),children:[a?D(F,{className:`h-3 w-3 animate-spin`}):D(ae,{className:`h-3 w-3`}),`Stop`]}):S(d,{size:`sm`,variant:`primary`,disabled:a,onClick:()=>n(e),children:[a?D(F,{className:`h-3 w-3 animate-spin`}):D(re,{className:`h-3 w-3`}),`Start`]})}x();var J=3e4;function _e(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function ve(){let e=v({capName:`turn-provider`},{refetchInterval:J}),t=p(void 0,{refetchInterval:J}),n=u(),r=n.data??[],i=C(()=>U(t.data??[]),[t.data]);return D(N,{title:`TURN Servers`,subtitle:`ICE servers used for WebRTC NAT traversal. Multiple providers can coexist — the WebRTC layer concatenates servers from all enabled providers per session.`,pageIcon:B,itemIcon:B,capability:`turn-provider`,installButtonLabel:`Add provider`,items:C(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:i.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,i]),isLoading:e.isLoading,emptyTitle:`No TURN providers installed`,emptyDescription:`Install a TURN addon (e.g. @camstack/addon-cloudflare) to enable WebRTC behind restrictive NATs.`,renderExpandedPanel:e=>D(ye,{addonId:e.addonId,enabled:e.isActive}),trailing:S(h,{children:[S(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[S(`div`,{children:[D(`div`,{className:`text-sm font-semibold`,children:`Combined ICE server list`}),D(`div`,{className:`text-xs text-foreground-subtle`,children:`What the WebRTC layer fetches per-session.`})]}),D(d,{size:`sm`,variant:`secondary`,onClick:()=>n.refetch(),disabled:n.isFetching,children:`Refresh`})]}),D(`div`,{className:`p-4`,children:r.length===0?D(`div`,{className:`text-xs text-foreground-subtle`,children:`No servers from enabled providers.`}):D(`div`,{className:`flex flex-col gap-3`,children:r.map((e,t)=>{let n=Array.isArray(e.urls)?e.urls:[e.urls];return S(`div`,{className:`rounded border border-border bg-surface`,children:[(e.username||e.credential)&&S(`div`,{className:`px-3 py-1.5 border-b border-border text-[10px] font-mono text-foreground-subtle flex items-center gap-3`,children:[e.username&&S(`span`,{children:[D(`span`,{className:`text-foreground-subtle`,children:`user:`}),` `,D(`span`,{className:`text-foreground`,children:e.username})]}),e.credential&&S(`span`,{children:[D(`span`,{className:`text-foreground-subtle`,children:`credential:`}),` `,D(`span`,{className:`text-foreground`,children:`••••••••`})]})]}),D(`ul`,{className:`divide-y divide-border`,children:n.map(e=>D(`li`,{className:`px-3 py-1.5 font-mono text-xs text-foreground break-all`,children:e},e))})]},t)})})})]})})}function ye({addonId:e,enabled:t}){let n=u({addonId:e},{enabled:t,retry:!1}),r=C(()=>_e(n.data??[]),[n.data]);return!t||r.length===0?null:S(`div`,{className:`rounded-lg border border-border bg-surface p-3`,children:[S(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Discovered ICE servers (`,r.length,`)`]}),D(`div`,{className:`flex flex-wrap gap-1`,children:r.map(e=>D(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-[10px] font-mono bg-foreground-subtle/10 text-foreground`,children:e},e))})]})}x();var be={lan:B,wifi:oe,docker:j,vpn:de,loopback:P,other:P},xe={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},Se=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function Ce(e){let{interfaces:t,disabled:n,hideLoopback:r,ipv4Only:i,emptyMessage:a}=e,o=C(()=>t.filter(e=>!(r&&e.kind===`loopback`||i&&e.family!==`IPv4`)),[t,r,i]),s=C(()=>{let e=new Map;for(let t of o){let n=e.get(t.kind)??[];n.push(t),e.set(t.kind,n)}return Se.filter(t=>e.has(t)).map(t=>({kind:t,items:e.get(t)}))},[o]),c=t=>e.mode===`single`?e.value===t:e.value.includes(t),l=t=>{if(n||t.kind===`loopback`)return;if(e.mode===`single`){e.onChange(e.value===t.address?null:t.address);return}let r=new Set(e.value);r.has(t.address)?r.delete(t.address):r.add(t.address),e.onChange([...r])};return o.length===0?D(`div`,{className:`text-xs text-foreground-subtle italic`,children:a??`No addresses available.`}):D(`div`,{className:`flex flex-col gap-3`,children:s.map(({kind:t,items:r})=>S(`div`,{className:`rounded-md border border-border overflow-hidden`,children:[S(`div`,{className:`flex items-center gap-2 px-3 py-1.5 bg-surface-hover/30 border-b border-border`,children:[D(be[t]??P,{className:`h-3.5 w-3.5 text-foreground-subtle`}),D(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:xe[t]??t}),S(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`· `,r.length]})]}),D(`ul`,{className:`divide-y divide-border`,children:r.map(t=>{let r=c(t.address),i=t.kind===`loopback`,a=!t.plausible&&!i;return S(`li`,{className:`flex items-center gap-3 px-3 py-2 ${i?`opacity-60 cursor-not-allowed`:n?`opacity-60`:a?`cursor-pointer hover:bg-surface-hover/30 bg-amber-500/[0.04]`:`cursor-pointer hover:bg-surface-hover/30`}`,onClick:()=>l(t),children:[D(`span`,{className:`flex items-center justify-center h-4 w-4 rounded ${e.mode===`single`?`rounded-full`:`rounded`} border ${r?`border-primary bg-primary text-primary-foreground`:`border-border bg-surface`}`,children:r&&D(se,{className:`h-3 w-3`})}),S(`div`,{className:`flex-1 min-w-0 ${a?`text-foreground-subtle`:``}`,children:[S(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[D(`span`,{className:`font-mono text-xs font-semibold ${a?`text-foreground-subtle`:`text-foreground`}`,children:t.name}),D(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-mono`,children:t.family}),t.preferred&&D(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-primary/15 text-primary`,children:`Auto-preferred`}),i&&D(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:`Always included`}),a&&S(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:t.plausibleReason||void 0,children:[D(z,{className:`h-2.5 w-2.5`}),`Unlikely usable`]})]}),S(`div`,{className:`text-xs text-foreground-subtle mt-0.5 font-mono break-all`,children:[t.address,t.cidr&&t.cidr!==t.address?` (${t.cidr})`:``]})]})]},`${t.name}-${t.family}-${t.address}`)})})]},t))})}x();var Y={"lan-ipv4":`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,"lan-ipv6":`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`,loopback:`bg-foreground-subtle/15 text-foreground-subtle`};function we(){let t=T(),n=A(),r=_(void 0,{refetchInterval:3e4}),i=ee(void 0),a=e({onSuccess:()=>{t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),o=s({onSuccess:e=>{p(e.addresses),t.invalidateQueries({queryKey:[[`localNetwork`]]})}}),c=C(()=>r.data?.interfaces??[],[r.data]),l=f({port:typeof window<`u`?Number(window.location.port)||(window.location.protocol===`https:`?443:80):4e3,scheme:typeof window<`u`&&window.location.protocol===`https:`?`https`:`http`},{refetchInterval:3e4}),[u,p]=E([]),[m,g]=E(!1);te(()=>{!m&&i.data&&(p(i.data.addresses),g(!0))},[i.data,m]);let v=i.data?.addresses??[],y=C(()=>{if(u.length!==v.length)return!0;let e=[...u].toSorted(),t=[...v].toSorted();return e.some((e,n)=>e!==t[n])},[u,v]),b=()=>{a.mutate({addresses:[...u]})},x=()=>{p(v)},w=()=>{p([])},O=()=>{r.refetch(),l.refetch(),i.refetch()},k=async()=>{try{let e=await n.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info(`[network-addresses] race result`,e)}catch(e){console.warn(`[network-addresses] race failed`,e)}},j=l.data?.endpoints??[];return S(V,{children:[S(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[D(`p`,{className:`text-xs text-foreground-subtle max-w-2xl`,children:`Pick the local addresses SDK clients should race for the fastest path to this hub. Empty selection (auto) lets every non-loopback / non-link-local interface participate.`}),S(`div`,{className:`flex items-center gap-2 shrink-0`,children:[S(d,{size:`sm`,variant:`secondary`,onClick:O,disabled:r.isLoading,children:[D(ie,{className:`h-3 w-3 ${r.isLoading?`animate-spin`:``}`}),`Refresh`]}),D(d,{size:`sm`,variant:`secondary`,onClick:k,children:`Probe race`})]})]}),S(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[S(h,{children:[S(`div`,{className:`px-4 py-3 border-b border-border flex items-center justify-between`,children:[S(`div`,{children:[D(`div`,{className:`text-sm font-semibold`,children:`Allowed addresses`}),D(`div`,{className:`text-xs text-foreground-subtle`,children:u.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${u.length} pinned`})]}),S(`div`,{className:`flex items-center gap-1`,children:[S(d,{size:`sm`,variant:`secondary`,onClick:()=>o.mutate(void 0),disabled:o.isPending||a.isPending,title:`Re-run the auto-detection heuristic + overwrite the current allowlist with the best matches.`,children:[D(ue,{className:`h-3 w-3`}),o.isPending?`Detecting…`:`Best match`]}),S(d,{size:`sm`,variant:`secondary`,onClick:w,disabled:u.length===0||a.isPending,children:[D(ne,{className:`h-3 w-3`}),`Clear`]}),y&&D(d,{size:`sm`,variant:`secondary`,onClick:x,disabled:a.isPending,children:`Discard`}),S(d,{size:`sm`,variant:`primary`,onClick:b,disabled:!y||a.isPending,children:[D(W,{className:`h-3 w-3`}),a.isPending?`Saving…`:`Save`]})]})]}),D(`div`,{className:`p-4`,children:D(Ce,{mode:`multiple`,interfaces:c,value:u,onChange:p,disabled:a.isPending,emptyMessage:r.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),S(h,{children:[S(`div`,{className:`px-4 py-3 border-b border-border`,children:[D(`div`,{className:`text-sm font-semibold`,children:`Connection endpoints — priority order`}),D(`div`,{className:`text-xs text-foreground-subtle`,children:`Live preview of the ranked candidate list the SDK would race against. Updates with each Save.`})]}),D(`div`,{className:`p-4`,children:j.length===0?D(`div`,{className:`text-xs text-foreground-subtle italic`,children:l.isLoading?`Loading…`:`No endpoints available.`}):D(`ul`,{className:`space-y-1 text-xs`,children:j.map(e=>S(`li`,{className:`flex items-center gap-2 flex-wrap ${e.plausible?``:`opacity-80`}`,children:[D(`span`,{className:`font-mono text-[10px] w-10 text-foreground-subtle`,children:String(e.priority).padStart(4,`0`)}),D(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${Y[e.kind]??Y.loopback}`,children:e.kind}),e.interfaceKind!==`lan`&&e.interfaceKind!==`public`&&D(`span`,{className:`text-[10px] rounded px-1.5 py-0.5 bg-foreground-subtle/10 text-foreground-subtle font-medium uppercase`,children:e.interfaceKind}),!e.plausible&&e.interfaceKind!==`loopback`&&S(`span`,{className:`inline-flex items-center gap-1 text-[10px] rounded-full px-2 py-0.5 font-medium bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:e.plausibleReason||void 0,children:[D(z,{className:`h-2.5 w-2.5`}),`Unlikely usable`]}),D(`span`,{className:`font-mono break-all ${e.plausible?`text-foreground`:`text-foreground-subtle`}`,children:e.baseUrl}),S(`span`,{className:`text-foreground-subtle`,children:[`— `,e.label]})]},`${e.priority}-${e.baseUrl}`))})})]})]})]})}x();var Te={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},X=5e3,Ee=3e4,De={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function Oe(){let e=v({capName:`mesh-network`},{refetchInterval:X}),t=p(void 0,{refetchInterval:X}),n=C(()=>U(t.data??[]),[t.data]);return D(N,{title:`Mesh Networks`,subtitle:`Private VPN meshes that connect CamStack to your other devices (Tailscale, Headscale, …). Each provider can also expose this hub publicly via its ingress (Tailscale Funnel).`,pageIcon:j,itemIcon:B,capability:`mesh-network`,installButtonLabel:`Add mesh`,items:C(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive})),[e.data,n]),isLoading:e.isLoading,emptyTitle:`No mesh-network providers installed`,emptyDescription:`Install a mesh addon (e.g. @camstack/addon-tailscale) to join this hub into a private VPN mesh.`,renderStatusBadges:e=>D(ke,{addonId:e.addonId}),renderPrimaryAction:e=>D(Ae,{addonId:e.addonId}),renderExpandedPanel:e=>D(je,{addonId:e.addonId})})}function Z(e){let{data:t,isLoading:n}=g({addonId:e},{refetchInterval:X,retry:!1}),r=t?O.safeParse(t):null;return{status:r?.success?r.data:De,isLoading:n}}function ke({addonId:e}){let{status:t}=Z(e);return S(w,{children:[D(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${t.joined?`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`:`bg-foreground-subtle/15 text-foreground-subtle`}`,children:t.joined?`Joined`:`Not joined`}),t.joined&&S(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium bg-foreground-subtle/15 text-foreground-subtle`,children:[t.peerCount,` peer`,t.peerCount===1?``:`s`]})]})}function Ae({addonId:e}){let n=T(),[r,i]=E(!1),[o,s]=E(null),l=A(),{status:u}=Z(e),f=b(()=>{n.invalidateQueries({queryKey:[[`meshNetwork`]]})},[n]),p=a(),m=c({onSuccess:f}),h=t({onSuccess:f}),g=b(async()=>{i(!0);let t={cancelled:!1};s(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 Ie(2e3),!t.cancelled);){let t=await l.trpcClient.meshNetwork.getStatus.query({addonId:e}).catch(()=>null),n=t?O.safeParse(t):null;if(n?.success&&n.data.joined){f();break}if(Date.now()-r>6e5)break}}finally{i(!1),s(null)}},[e,f,p,l]),_=b(()=>{o&&(o.cancelled=!0),i(!1),s(null)},[o]);return D(w,{children:u.joined?S(w,{children:[S(d,{size:`sm`,variant:`secondary`,disabled:m.isPending,onClick:()=>m.mutate({addonId:e}),children:[m.isPending?D(F,{className:`h-3 w-3 animate-spin`}):D(ce,{className:`h-3 w-3`}),`Disconnect`]}),S(d,{size:`sm`,variant:`ghost`,disabled:h.isPending,onClick:()=>h.mutate({addonId:e}),children:[h.isPending?D(F,{className:`h-3 w-3 animate-spin`}):D(G,{className:`h-3 w-3`}),`Log out`]})]}):r?S(d,{size:`sm`,variant:`ghost`,onClick:_,children:[D(le,{className:`h-3 w-3 mr-1`}),` Cancel`]}):S(w,{children:[S(d,{size:`sm`,variant:`primary`,onClick:()=>void g(),children:[D(fe,{className:`h-3 w-3`}),`Connect`]}),S(d,{size:`sm`,variant:`ghost`,disabled:h.isPending,onClick:()=>h.mutate({addonId:e}),children:[h.isPending?D(F,{className:`h-3 w-3 animate-spin`}):D(G,{className:`h-3 w-3`}),`Log out`]})]})})}function je({addonId:e}){let{status:t}=Z(e),r=n({addonId:e},{refetchInterval:Ee,retry:!1});return S(`div`,{className:`rounded-lg border border-border bg-surface`,children:[S(`div`,{className:`p-4 space-y-4`,children:[t.error&&D(o,{message:t.error}),D(Me,{status:t}),t.endpoints.length>0&&S(`div`,{className:`space-y-1.5`,children:[D(`div`,{className:`text-[11px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:`Endpoints`}),t.endpoints.map(e=>S(`div`,{className:`flex items-center gap-2 text-xs flex-wrap`,children:[S(`span`,{className:`text-[10px] rounded-full px-2 py-0.5 font-medium ${Te[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?D(I,{className:`inline h-2.5 w-2.5 mr-0.5`}):null,e.label]}),S(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`text-emerald-700 dark:text-emerald-300 hover:underline break-all flex items-center gap-1`,children:[D(R,{className:`h-3 w-3 shrink-0`}),e.url]})]},e.id))]})]}),D(`div`,{className:`border-t border-border`,children:D(Pe,{peers:r.data?.peers??[],loading:r.isLoading})})]})}function Me({status:e}){return D(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-x-6 gap-y-1.5`,children:[{label:`Tenant`,value:e.tenantName||`—`},{label:`User`,value:e.userLogin??`—`},{label:`Control plane`,value:e.controlPlaneUrl||`—`},{label:`Mesh IP`,value:e.meshIp||`—`,mono:!0},{label:`MagicDNS`,value:e.magicDnsHostname||`—`,mono:!0},{label:`DNS suffix`,value:e.magicDnsSuffix||`—`,mono:!0},{label:`Peers`,value:String(e.peerCount)},{label:`Key expiry`,value:e.keyExpiry?Ne(e.keyExpiry):`—`}].map(e=>S(`div`,{className:`flex items-baseline justify-between gap-3 text-xs`,children:[D(`span`,{className:`text-foreground-subtle shrink-0`,children:e.label}),D(`span`,{className:`text-foreground truncate ${e.mono?`font-mono`:``}`,children:e.value})]},e.label))})}function Ne(e){let t=e-Date.now();if(t<0)return`Expired ${$(e)}`;let n=Math.floor(t/864e5);if(n>60)return new Date(e).toLocaleDateString();if(n>1)return`in ${n} days`;let r=Math.floor(t/36e5);return r>1?`in ${r}h`:`in ${Math.max(1,Math.floor(t/6e4))} min`}function Pe({peers:e,loading:t}){let n=C(()=>e.map(e=>({...e,_id:e.id})),[e]),r=b(e=>{e&&navigator.clipboard?.writeText(e)},[]),i=C(()=>[{key:`hostname`,header:`Hostname`,render:e=>S(`div`,{className:`flex flex-col`,children:[S(`div`,{className:`flex items-center gap-1.5`,children:[D(`span`,{className:`font-medium text-foreground`,children:e.hostname||`(unknown)`}),e.isSelf&&D(y,{variant:`info`,children:`self`}),e.exitNodeOption&&D(y,{variant:`warning`,children:`exit-node`})]}),e.userLogin&&D(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.userLogin})]})},{key:`magicDns`,header:`MagicDNS`,render:e=>e.magicDns?S(`div`,{className:`flex items-center gap-1`,children:[D(`span`,{className:`font-mono text-xs truncate`,children:e.magicDns}),D(`button`,{onClick:()=>r(e.magicDns),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy MagicDNS`,children:D(M,{className:`h-3 w-3 text-foreground-subtle`})})]}):D(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`addresses`,header:`IP`,render:e=>{let t=e.addresses[0]??``;return t?S(`div`,{className:`flex items-center gap-1`,children:[D(`span`,{className:`font-mono text-xs`,children:t}),D(`button`,{onClick:()=>r(t),className:`p-0.5 hover:bg-foreground-subtle/10 rounded`,"aria-label":`Copy IP`,children:D(M,{className:`h-3 w-3 text-foreground-subtle`})})]}):D(`span`,{className:`text-foreground-subtle`,children:`—`})}},{key:`connection`,header:`Connection`,render:e=>S(`div`,{className:`flex items-center gap-1.5`,children:[D(y,{variant:Fe(e.connection),children:e.connection}),e.relay&&D(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.relay})]})},{key:`routes`,header:`Routes`,render:e=>e.advertisedRoutes.length>0?D(`span`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,children:e.advertisedRoutes.join(`, `)}):D(`span`,{className:`text-foreground-subtle`,children:`—`})},{key:`tx`,header:`TX / RX`,render:e=>S(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`↑ `,Q(e.txBytes),` · ↓ `,Q(e.rxBytes)]})},{key:`lastSeen`,header:`Last seen`,render:e=>D(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.lastSeenMs>0?$(e.lastSeenMs):`—`})}],[r]);return t&&e.length===0?S(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[D(F,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):e.length===0?D(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:`No peers visible — your tailnet may be empty or the host is not joined.`}):D(`div`,{className:`p-4`,children:D(l,{columns:i,rows:n,rowKey:e=>e._id,minWidthPx:820})})}function Fe(e){return e===`direct`?`success`:e===`relay`?`warning`:`info`}function Q(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)}MB`:`${(e/1024/1024/1024).toFixed(2)}GB`}function $(e){let t=Date.now()-e;return t<6e4?`just now`:t<36e5?`${Math.round(t/6e4)}m ago`:t<864e5?`${Math.round(t/36e5)}h ago`:`${Math.round(t/864e5)}d ago`}function Ie(e){return new Promise(t=>setTimeout(t,e))}function Le(){return D(`div`,{className:`flex flex-col p-4`,children:D(H,{tabs:[{id:`addresses`,label:`Network Addresses`,icon:P,content:D(we,{})},{id:`remote-access`,label:`Remote Access`,icon:I,content:D(me,{})},{id:`mesh`,label:`Mesh Networks`,icon:j,content:D(Oe,{})},{id:`turn`,label:`TURN Servers`,icon:B,content:D(ve,{})}]})})}export{Le as NetworkPage};
|
package/dist/assets/{NodeAddonsSettingsPanel-xN6mgN_r.js → NodeAddonsSettingsPanel-CCcTKMq-.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{bt as e,dt as t,ft as n,on as r,zt as i}from"./src-CjsGEszD.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-CCZM6rtM.js";import{p as ee}from"./player-overlays-BfnV1C0Q.js";import{t as b}from"./FormBuilder-CJZT56JQ.js";import{n as te,r as x,t as ne}from"./SchemaTabBar-DhsmEGyn.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 re(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}){let D=p(),O=ee().trpcClient,k=n(),A=t(),j=r(),M=i(),N=!!(C&&C.length>0),[P,ae]=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]),oe=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),se=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}=re(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,ce]=h(new Map),le=o(e=>{ce(t=>{let n=new Map(t);return n.set(e.addonId,e),n})},[]),Y=s(new Map),ue=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]),de=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]),fe=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`]]})}}),pe=o(()=>{for(let e of Y.current.values())e.discard()},[]),me=u(()=>{let e=0;for(let t of q){let n=J.get(t.addonId);n&&(e+=n.pendingKeys.length)}return e},[q,J]),he=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:oe.get(e)??e})),activeId:H,onChange:ae,pendingByTab:he}),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)]}),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&&_(ie,{entries:n,paneStates:J,displayNames:se,disabled:$,setPaneRef:ue,onPaneStateChange:le,onImmediateSave:fe,onAction:de,inline:N||!!S}),a.map((e,t)=>_(`div`,{children:e.content},`extra-after-${t}`))]})})(),!L&&_(te,{pendingCount:me,onSave:()=>Z.mutate(),onDiscard:pe,saving:$})]})}function ie({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-CjsGEszD.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-CCZM6rtM.js";import{p as ee}from"./player-overlays-BfnV1C0Q.js";import{t as b}from"./FormBuilder-CKd7U6PQ.js";import{n as te,r as x,t as ne}from"./SchemaTabBar-DhsmEGyn.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 re(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}){let D=p(),O=ee().trpcClient,k=n(),A=t(),j=r(),M=i(),N=!!(C&&C.length>0),[P,ae]=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]),oe=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),se=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}=re(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,ce]=h(new Map),le=o(e=>{ce(t=>{let n=new Map(t);return n.set(e.addonId,e),n})},[]),Y=s(new Map),ue=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]),de=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]),fe=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`]]})}}),pe=o(()=>{for(let e of Y.current.values())e.discard()},[]),me=u(()=>{let e=0;for(let t of q){let n=J.get(t.addonId);n&&(e+=n.pendingKeys.length)}return e},[q,J]),he=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:oe.get(e)??e})),activeId:H,onChange:ae,pendingByTab:he}),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)]}),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&&_(ie,{entries:n,paneStates:J,displayNames:se,disabled:$,setPaneRef:ue,onPaneStateChange:le,onImmediateSave:fe,onAction:de,inline:N||!!S}),a.map((e,t)=>_(`div`,{children:e.content},`extra-after-${t}`))]})})(),!L&&_(te,{pendingCount:me,onSave:()=>Z.mutate(),onDiscard:pe,saving:$})]})}function ie({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,go as n,jn as r,mi as i,wn as a,yo as o}from"./src-CjsGEszD.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-Daoo8ovU.js";import{P as _,W as v,a as y,j as b,x}from"./index-Cf-I6XLC.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(o,{variant:`default`,style:`outline`,className:`font-mono text-[9px]`,children:e.format}),!e.available&&m(o,{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(n,{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,go as n,jn as r,mi as i,wn as a,yo as o}from"./src-CjsGEszD.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-Cywg_7qu.js";import{P as _,W as v,a as y,j as b,x}from"./index-B_KY_Mml.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(o,{variant:`default`,style:`outline`,className:`font-mono text-[9px]`,children:e.format}),!e.available&&m(o,{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(n,{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{Ra as e,S as t,bo as n,do as r,go as i,ho as a,mo as o,po as s,uo as c,vo as l,yo as u}from"./src-CjsGEszD.js";import{Q as d,S as f,W as p,a as m,q as h,t as g,x as _}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as v}from"./player-overlays-BfnV1C0Q.js";import{t as y}from"./circle-check-big-CI9FWu6l.js";import{t as b}from"./pencil-B1DqIkdM.js";import{t as x}from"./plus-MB1SLBFq.js";import{t as S}from"./search-BmUqqa8F.js";import{t as C}from"./send-BeH97ECp.js";import{N as w,S as T,V as E,s as D}from"./index-Cf-I6XLC.js";import{t as O}from"./AdminPage-BwmGKnRf.js";d();var k=e=>typeof e==`string`&&e.length>0;function A(e){return{levels:e.levels,formats:e.format,bodyMaxLen:e.bodyMaxLen,attachmentSlots:e.attachments.mediaTypes,attachmentMode:e.attachments.mode,attachmentMax:e.attachments.max,attachmentMaxBytes:e.attachments.maxBytes,maxActions:e.actions,showActions:e.actions>0,showClickUrl:e.clickUrl,showSound:e.sound,showTtl:e.ttl,showTag:!0}}function j(e,t){return e.format.includes(t)?t:e.format[0]??`text`}function M(e,t){let n=[];for(let r of e.attachments.mediaTypes){if(n.length>=e.attachments.max)break;let i=t[r];k(i)&&n.push({mediaType:r,url:i})}return n}function N(e,t){if(e.actions<=0)return[];let n=[];for(let r of t){if(n.length>=e.actions)break;let t=k(r.label),i=k(r.url);!t&&!i||n.push({id:`test-${n.length+1}`,label:t?r.label:`Action ${n.length+1}`,...i?{url:r.url}:{}})}return n}function P(e,t){let n=e.levels.some(e=>e.id===t.level)?t.level:void 0,r=M(e,t.attachmentUrls),i=N(e,t.actions),a=e.ttl&&k(t.ttl)?Number(t.ttl):void 0;return{body:t.body,format:j(e,t.format),priority:F(t.priority),...k(t.title)?{title:t.title}:{},...n?{level:n}:{},...r.length>0?{attachments:r}:{},...i.length>0?{actions:i}:{},...e.clickUrl&&k(t.clickUrl)?{clickUrl:t.clickUrl}:{},...e.sound&&k(t.sound)?{sound:t.sound}:{},...a!==void 0&&Number.isFinite(a)?{ttl:a}:{},...k(t.tag)?{tag:t.tag}:{}}}function F(e){return Number.isFinite(e)?Math.min(5,Math.max(1,Math.round(e))):3}function I(e){return e.levels.find(e=>e.flags?.critical===!0)||e.levels.filter(e=>typeof e.ordinal==`number`).sort((e,t)=>t.ordinal-e.ordinal)[0]}function L(e){return{level:``,priority:3,format:e.format[0]??`text`,title:``,body:``,attachmentUrls:{},actions:[],clickUrl:``,sound:``,ttl:``,tag:``}}var R={image:`https://example.com/sample.jpg`,video:`https://example.com/sample.mp4`,gif:`https://example.com/sample.gif`,audio:`https://example.com/sample.mp3`,icon:`https://example.com/icon.png`};function z(e,t){let n=L(e);switch(t){case`minimal`:return{...n,body:`Test notification`};case`overflow`:return{...n,body:`X`.repeat(e.bodyMaxLen+50)};case`critical`:{let t=I(e);return{...n,body:`Critical test notification`,priority:5,level:t?.id??``}}case`everything`:{let t={},n=0;for(let r of e.attachments.mediaTypes){if(n>=e.attachments.max)break;t[r]=R[r],n+=1}let r=Array.from({length:e.actions},(e,t)=>({label:`Action ${t+1}`,url:`https://example.com/action/${t+1}`}));return{level:``,priority:4,format:e.format.includes(`markdown`)?`markdown`:e.format.includes(`html`)?`html`:e.format[0]??`text`,title:`Everything the kind supports`,body:`This sample fills every control the kind advertises.`,attachmentUrls:t,actions:r,clickUrl:e.clickUrl?`https://example.com/open`:``,sound:e.sound?`default`:``,ttl:e.ttl?`3600`:``,tag:`camstack-test`}}}}var B=[{id:`minimal`,label:`Minimal (body only)`},{id:`everything`,label:`Everything supported`},{id:`overflow`,label:`Overflow`},{id:`critical`,label:`Critical`}],V=`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none`,H=`block text-[11px] font-medium text-foreground mb-1`;function U({target:e,kind:t,open:i,onClose:l}){let d=v(),m=p(()=>A(t.caps),[t.caps]),[y,b]=h(()=>L(t.caps)),[x,S]=h(null),w=p(()=>P(t.caps,y),[t.caps,y]),E=y.body.length,D=E>m.bodyMaxLen,O=e=>b(t=>({...t,...e})),k=g({mutationFn:()=>d.trpcClient.notificationOutput.testTarget.mutate({addonId:e.addonId,targetId:e.id,sample:P(t.caps,y)}),onMutate:()=>S(null),onSuccess:e=>S(e),onError:e=>S({success:!1,error:e instanceof Error?e.message:`Test failed`})}),j=e=>{b(z(t.caps,e)),S(null)},M=(e,t,n)=>{let r=y.actions.length>0?[...y.actions]:[];for(;r.length<=e;)r.push({label:``,url:``});r[e]={...r[e],[t]:n},O({actions:r})};return _(c,{open:i,onOpenChange:e=>!e&&l(),children:f(r,{width:`lg`,className:`!max-w-2xl`,children:[_(o,{children:f(a,{children:[`Test "`,e.name,`" (`,t.label,`)`]})}),f(`div`,{className:`space-y-4 max-h-[60vh] overflow-y-auto pr-1`,children:[_(`div`,{className:`flex flex-wrap gap-1.5`,children:B.map(e=>_(n,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>j(e.id),children:e.label},e.id))}),f(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[m.levels.length>0&&f(`div`,{children:[_(`label`,{className:H,children:`Level`}),f(`select`,{className:V,value:y.level,onChange:e=>O({level:e.target.value}),children:[_(`option`,{value:``,children:`— derive from priority —`}),m.levels.map(e=>f(`option`,{value:e.id,children:[e.label,e.ordinal===null?` (qualitative)`:` (p${e.ordinal})`]},e.id))]}),(()=>{let e=m.levels.find(e=>e.id===y.level);return e?f(`div`,{className:`mt-1 space-y-1`,children:[e.description&&_(`p`,{className:`text-[10px] text-foreground-subtle`,children:e.description}),f(`div`,{className:`flex flex-wrap gap-1`,children:[e.flags?.critical&&_(u,{variant:`danger`,"data-testid":`flag-critical`,children:`critical`}),e.flags?.silent&&_(u,{variant:`info`,children:`silent`}),e.flags?.noPush&&_(u,{variant:`warning`,children:`no-push`})]}),e.requires&&e.requires.length>0&&f(`p`,{className:`text-[10px] text-warning`,children:[`Requires target config: `,e.requires.join(`, `)]})]}):null})()]}),f(`div`,{children:[f(`label`,{className:H,children:[`Priority (ordinal): `,y.priority]}),_(`input`,{type:`range`,min:1,max:5,step:1,value:y.priority,onChange:e=>O({priority:Number(e.target.value)}),className:`w-full accent-primary`,"aria-label":`priority`})]})]}),m.formats.length>0&&f(`div`,{children:[_(`label`,{className:H,children:`Format`}),_(`div`,{className:`flex flex-wrap gap-2`,children:m.formats.map(e=>f(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[_(`input`,{type:`radio`,name:`format`,className:`accent-primary`,checked:y.format===e,onChange:()=>O({format:e})}),e]},e))})]}),f(`div`,{children:[_(`label`,{className:H,children:`Title`}),_(`input`,{className:V,value:y.title,onChange:e=>O({title:e.target.value})})]}),f(`div`,{children:[f(`label`,{className:H,children:[`Body`,` `,f(`span`,{className:D?`text-danger`:`text-foreground-subtle`,children:[`(`,E,`/`,m.bodyMaxLen,D?` — overflow`:``,`)`]})]}),_(`textarea`,{className:`${V} min-h-[80px] resize-y`,value:y.body,onChange:e=>O({body:e.target.value})})]}),m.attachmentSlots.length>0&&f(`div`,{children:[f(`label`,{className:H,children:[`Attachments`,` `,f(`span`,{className:`text-foreground-subtle`,children:[`(mode: `,m.attachmentMode,`, max `,m.attachmentMax,m.attachmentMaxBytes?`, ≤${Math.round(m.attachmentMaxBytes/1024/1024)}MB`:``,`)`]})]}),_(`div`,{className:`space-y-1.5`,children:m.attachmentSlots.map(e=>f(`div`,{className:`flex items-center gap-2`,children:[_(`span`,{className:`text-[10px] w-12 shrink-0 text-foreground-subtle`,children:e}),_(`input`,{className:V,placeholder:`${e} URL`,value:y.attachmentUrls[e]??``,onChange:t=>O({attachmentUrls:{...y.attachmentUrls,[e]:t.target.value}})})]},e))})]}),m.showActions&&f(`div`,{children:[f(`label`,{className:H,children:[`Actions (up to `,m.maxActions,`)`]}),_(`div`,{className:`space-y-1.5`,children:Array.from({length:Math.min(m.maxActions,3)},(e,t)=>f(`div`,{className:`flex items-center gap-2`,children:[_(`input`,{className:V,placeholder:`label`,value:y.actions[t]?.label??``,onChange:e=>M(t,`label`,e.target.value)}),_(`input`,{className:V,placeholder:`url`,value:y.actions[t]?.url??``,onChange:e=>M(t,`url`,e.target.value)})]},t))})]}),f(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[m.showClickUrl&&f(`div`,{children:[_(`label`,{className:H,children:`Click URL`}),_(`input`,{className:V,value:y.clickUrl,onChange:e=>O({clickUrl:e.target.value})})]}),m.showSound&&f(`div`,{children:[_(`label`,{className:H,children:`Sound`}),_(`input`,{className:V,value:y.sound,onChange:e=>O({sound:e.target.value})})]}),m.showTtl&&f(`div`,{children:[_(`label`,{className:H,children:`TTL (seconds)`}),_(`input`,{className:V,type:`number`,value:y.ttl,onChange:e=>O({ttl:e.target.value})})]}),m.showTag&&f(`div`,{children:[_(`label`,{className:H,children:`Tag`}),_(`input`,{className:V,value:y.tag,onChange:e=>O({tag:e.target.value})})]})]}),x&&_(W,{result:x}),f(`details`,{className:`text-[10px]`,children:[_(`summary`,{className:`cursor-pointer text-foreground-subtle`,children:`Payload preview`}),_(`pre`,{className:`mt-1 overflow-x-auto rounded bg-surface p-2 text-foreground-subtle`,children:JSON.stringify(w,null,2)})]})]}),f(s,{children:[_(n,{variant:`secondary`,size:`sm`,type:`button`,onClick:l,children:`Close`}),f(n,{size:`sm`,type:`button`,disabled:k.isPending||y.body.length===0,onClick:()=>k.mutate(),children:[k.isPending?_(T,{className:`h-3.5 w-3.5 animate-spin`}):_(C,{className:`h-3.5 w-3.5`}),`Send test`]})]})]})})}function W({result:e}){let t=e.renderedAs;return f(`div`,{className:`rounded-md border px-3 py-2 text-xs ${e.success?`border-success/40 bg-success/10`:`border-danger/40 bg-danger/10`}`,"data-testid":`test-result`,children:[f(`div`,{className:`flex items-center gap-2 font-medium`,children:[e.success?_(y,{className:`h-3.5 w-3.5 text-success`}):_(w,{className:`h-3.5 w-3.5 text-danger`}),_(`span`,{children:e.success?`Delivered`:`Failed`})]}),e.error&&_(`p`,{className:`mt-1 text-danger`,children:e.error}),t&&f(`dl`,{className:`mt-2 grid grid-cols-2 gap-x-3 gap-y-0.5 text-[11px] text-foreground-subtle`,children:[_(`dt`,{children:`Resolved level`}),_(`dd`,{className:`text-foreground`,children:t.level}),_(`dt`,{children:`Format sent`}),_(`dd`,{className:`text-foreground`,children:t.format}),_(`dt`,{children:`Attachments sent`}),_(`dd`,{className:`text-foreground`,children:t.attachmentsSent}),_(`dt`,{children:`Actions sent`}),_(`dd`,{className:`text-foreground`,children:t.actionsSent}),_(`dt`,{children:`Truncated`}),_(`dd`,{className:`text-foreground`,children:t.truncated?`yes`:`no`}),_(`dt`,{children:`Dropped`}),_(`dd`,{className:`text-foreground`,children:t.dropped.length>0?t.dropped.join(`, `):`—`})]})]})}function G(e){let t=[],n=new Map;for(let r of e){let e=n.get(r.addonId);e?e.push(r):(n.set(r.addonId,[r]),t.push(r.addonId))}return t.map(e=>({addonId:e,kinds:n.get(e)??[]}))}function K(e){let t=[],n=e=>{for(let r of e){if(r.type===`password`){t.push(r.key);continue}if(r.type===`group`){n(r.fields);continue}if(r.type===`sub-tabs`)for(let e of r.tabs)n(e.fields)}};for(let t of e.sections)n(t.fields);return t}function q(e,t,n){let r=new Set(n),i={};for(let[n,a]of Object.entries(e)){if(!r.has(n)){i[n]=a;continue}a==null||a===``||a!==t[n]&&(i[n]=a)}return i}function J(e,t){let n=new Set(t),r={};for(let[t,i]of Object.entries(e))r[t]=n.has(t)?``:i;return r}d();var Y=[`notificationOutput`,`listTargets`],X=[`notificationOutput`,`listTargetKinds`];function Z({kind:e,imgClassName:t,fallbackClassName:n}){return e?.iconUrl?_(`img`,{src:e.iconUrl,alt:e.label,className:t,loading:`lazy`,draggable:!1}):_(`span`,{className:n,children:e?.icon??`🔔`})}function Q(){let t=v(),[r,a]=h({mode:`closed`}),[o,s]=h(null),c=m({queryKey:Y,queryFn:()=>t.trpcClient.notificationOutput.listTargets.query({})}),d=m({queryKey:X,queryFn:async()=>(await t.trpcClient.notificationOutput.listTargetKinds.query({})).map(e=>{let t=e.iconUrl;return{...e,configSchema:e.configSchema,iconUrl:t}})}),y=p(()=>d.data??[],[d.data]),S=p(()=>{let e=new Map;for(let t of y)e.set(t.kind,t);return e},[y]),w=g({mutationFn:e=>t.trpcClient.notificationOutput.setTargetEnabled.mutate({addonId:e.target.addonId,targetId:e.target.id,enabled:e.enabled}),onSuccess:()=>void c.refetch()}),k=g({mutationFn:e=>t.trpcClient.notificationOutput.deleteTarget.mutate({addonId:e.addonId,targetId:e.id}),onSuccess:()=>void c.refetch()}),A=o?S.get(o.kind):void 0;return f(O,{icon:E,title:`Notification Targets`,subtitle:`Deliver notifications to ntfy, Pushover, Telegram, Home Assistant and more. Each target's kind declares its capabilities; the test panel shows exactly what a message degrades to.`,actions:f(n,{size:`sm`,type:`button`,onClick:()=>a({mode:`pick-kind`}),children:[_(x,{className:`h-3.5 w-3.5`}),`Add target`]}),children:[c.isLoading&&_(`div`,{className:`flex items-center justify-center py-16`,children:_(T,{className:`h-6 w-6 animate-spin text-primary`})}),c.isError&&!c.isLoading&&_(e,{title:`Failed to load targets`,message:c.error instanceof Error?c.error.message:`Unknown error`,onRetry:()=>void c.refetch()}),!c.isLoading&&!c.isError&&(c.data??[]).length===0&&_(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No notification targets yet. Click "Add target" to configure one.`}),(c.data??[]).length>0&&_(l,{children:_(`ul`,{className:`divide-y divide-border`,children:(c.data??[]).map(e=>{let t=S.get(e.kind);return f(`li`,{className:`flex items-center gap-3 px-4 py-2.5`,children:[_(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface text-xs`,title:t?.label??e.kind,children:_(Z,{kind:t,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:``})}),f(`div`,{className:`min-w-0 flex-1`,children:[_(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),_(`div`,{className:`text-[11px] text-foreground-subtle`,children:t?.label??e.kind})]}),!e.enabled&&_(u,{variant:`warning`,children:`disabled`}),_(i,{checked:e.enabled,onCheckedChange:t=>w.mutate({target:e,enabled:t}),"aria-label":`toggle ${e.name}`}),_(n,{size:`sm`,variant:`ghost`,type:`button`,disabled:!t,onClick:()=>s(e),title:`Test`,children:_(C,{className:`h-3.5 w-3.5`})}),_(n,{size:`sm`,variant:`ghost`,type:`button`,disabled:!t,onClick:()=>t&&a({mode:`form`,kind:t,target:e}),title:`Edit`,children:_(b,{className:`h-3.5 w-3.5`})}),_(n,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>k.mutate(e),title:`Delete`,children:_(D,{className:`h-3.5 w-3.5 text-danger`})})]},e.id)})})}),r.mode===`pick-kind`&&_($,{kinds:y,onCancel:()=>a({mode:`closed`}),onPick:e=>a({mode:`form`,kind:e,target:null})}),r.mode===`form`&&_(ee,{kind:r.kind,target:r.target,onCancel:()=>a({mode:`closed`}),onSaved:()=>{a({mode:`closed`}),c.refetch()}}),o&&A&&_(U,{target:o,kind:A,open:!0,onClose:()=>s(null)})]})}function $({kinds:e,onPick:t,onCancel:r}){let i=p(()=>G(e),[e]);return f(l,{className:`p-4 space-y-4`,children:[f(`div`,{className:`flex items-center justify-between`,children:[_(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Choose a notification kind`}),_(n,{size:`sm`,variant:`ghost`,type:`button`,onClick:r,children:`Cancel`})]}),i.length===0&&_(`p`,{className:`text-xs text-foreground-subtle`,children:`No notification providers are installed. Install the notifiers addon (or connect Home Assistant) to add targets.`}),i.map(e=>f(`div`,{children:[_(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1.5`,children:e.addonId}),_(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-2`,children:e.kinds.map(n=>f(`button`,{type:`button`,onClick:()=>t(n),className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-xs hover:border-primary/50 hover:bg-surface-hover transition-colors`,children:[_(Z,{kind:n,imgClassName:`h-7 w-7 object-contain`,fallbackClassName:`text-lg leading-7`}),_(`span`,{className:`font-medium text-foreground`,children:n.label}),n.supportsDiscovery&&_(u,{variant:`info`,style:`outline`,children:`discover`})]},`${e.addonId}:${n.kind}`))})]},e.addonId))]})}function ee({kind:e,target:r,onSaved:i,onCancel:a}){let o=v(),s=p(()=>K(e.configSchema),[e.configSchema]),c=p(()=>r?.config??{},[r]),[u,d]=h(r?.name??e.label),[m,y]=h(()=>r?J(r.config,s):{}),[b,x]=h(null),[C,w]=h(null),E=g({mutationFn:()=>o.trpcClient.notificationOutput.discoverTargets.query({addonId:e.addonId,kind:e.kind,config:m}),onSuccess:e=>x(e),onError:e=>w(e instanceof Error?e.message:`Discovery failed`)}),D=g({mutationFn:()=>{let t=q(m,c,s),n={id:r?.id??`${e.kind}-${Date.now()}`,name:u,kind:e.kind,addonId:e.addonId,enabled:r?.enabled??!0,config:t};return o.trpcClient.notificationOutput.upsertTarget.mutate({addonId:e.addonId,target:n})},onSuccess:i,onError:e=>w(e instanceof Error?e.message:`Save failed`)}),O=e=>{d(e.suggestedName),y(t=>({...t,...e.config})),x(null)};return f(l,{className:`p-4 space-y-4`,children:[f(`div`,{className:`flex items-center justify-between`,children:[f(`h3`,{className:`text-sm font-semibold text-foreground flex items-center gap-2`,children:[_(Z,{kind:e,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:`text-lg`}),r?`Edit ${r.name}`:`Add ${e.label} target`]}),_(n,{size:`sm`,variant:`ghost`,type:`button`,onClick:a,children:`Cancel`})]}),C&&_(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:C}),f(`div`,{children:[_(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Name`}),_(`input`,{className:`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none`,value:u,onChange:e=>d(e.target.value)})]}),e.supportsDiscovery&&f(`div`,{className:`space-y-2`,children:[f(n,{size:`sm`,variant:`outline`,type:`button`,disabled:E.isPending,onClick:()=>{w(null),E.mutate()},children:[E.isPending?_(T,{className:`h-3.5 w-3.5 animate-spin`}):_(S,{className:`h-3.5 w-3.5`}),`Discover`]}),b&&b.length===0&&_(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No candidates discovered.`}),b&&b.length>0&&_(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:b.map((e,t)=>f(`button`,{type:`button`,onClick:()=>O(e),className:`flex w-full items-center justify-between px-3 py-1.5 text-xs hover:bg-surface-hover`,children:[_(`span`,{className:`text-foreground`,children:e.suggestedName}),_(`span`,{className:`text-[10px] text-primary`,children:`use`})]},`${e.suggestedName}-${t}`))})]}),s.length>0&&r&&_(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Secret fields are hidden. Leave them blank to keep the stored value; type a new value to replace it.`}),_(t,{schema:e.configSchema,values:m,onChange:y}),f(`div`,{className:`flex justify-end gap-2`,children:[_(n,{variant:`secondary`,size:`sm`,type:`button`,onClick:a,children:`Cancel`}),f(n,{size:`sm`,type:`button`,disabled:D.isPending||u.trim().length===0,onClick:()=>{w(null),D.mutate()},children:[D.isPending&&_(T,{className:`h-3.5 w-3.5 animate-spin`}),r?`Save changes`:`Create target`]})]})]})}export{Q as NotificationTargetsPage,Q as default};
|
|
1
|
+
import{Ra as e,S as t,bo as n,do as r,go as i,ho as a,mo as o,po as s,uo as c,vo as l,yo as u}from"./src-CjsGEszD.js";import{Q as d,S as f,W as p,a as m,q as h,t as g,x as _}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as v}from"./player-overlays-BfnV1C0Q.js";import{t as y}from"./circle-check-big-DxUdDrBY.js";import{t as b}from"./pencil-DbuWOCim.js";import{t as x}from"./plus-DUDfG-ml.js";import{t as S}from"./search-De-JtIxP.js";import{t as C}from"./send-DBAj2ECl.js";import{N as w,S as T,V as E,s as D}from"./index-B_KY_Mml.js";import{t as O}from"./AdminPage-BwmGKnRf.js";d();var k=e=>typeof e==`string`&&e.length>0;function A(e){return{levels:e.levels,formats:e.format,bodyMaxLen:e.bodyMaxLen,attachmentSlots:e.attachments.mediaTypes,attachmentMode:e.attachments.mode,attachmentMax:e.attachments.max,attachmentMaxBytes:e.attachments.maxBytes,maxActions:e.actions,showActions:e.actions>0,showClickUrl:e.clickUrl,showSound:e.sound,showTtl:e.ttl,showTag:!0}}function j(e,t){return e.format.includes(t)?t:e.format[0]??`text`}function M(e,t){let n=[];for(let r of e.attachments.mediaTypes){if(n.length>=e.attachments.max)break;let i=t[r];k(i)&&n.push({mediaType:r,url:i})}return n}function N(e,t){if(e.actions<=0)return[];let n=[];for(let r of t){if(n.length>=e.actions)break;let t=k(r.label),i=k(r.url);!t&&!i||n.push({id:`test-${n.length+1}`,label:t?r.label:`Action ${n.length+1}`,...i?{url:r.url}:{}})}return n}function P(e,t){let n=e.levels.some(e=>e.id===t.level)?t.level:void 0,r=M(e,t.attachmentUrls),i=N(e,t.actions),a=e.ttl&&k(t.ttl)?Number(t.ttl):void 0;return{body:t.body,format:j(e,t.format),priority:F(t.priority),...k(t.title)?{title:t.title}:{},...n?{level:n}:{},...r.length>0?{attachments:r}:{},...i.length>0?{actions:i}:{},...e.clickUrl&&k(t.clickUrl)?{clickUrl:t.clickUrl}:{},...e.sound&&k(t.sound)?{sound:t.sound}:{},...a!==void 0&&Number.isFinite(a)?{ttl:a}:{},...k(t.tag)?{tag:t.tag}:{}}}function F(e){return Number.isFinite(e)?Math.min(5,Math.max(1,Math.round(e))):3}function I(e){return e.levels.find(e=>e.flags?.critical===!0)||e.levels.filter(e=>typeof e.ordinal==`number`).sort((e,t)=>t.ordinal-e.ordinal)[0]}function L(e){return{level:``,priority:3,format:e.format[0]??`text`,title:``,body:``,attachmentUrls:{},actions:[],clickUrl:``,sound:``,ttl:``,tag:``}}var R={image:`https://example.com/sample.jpg`,video:`https://example.com/sample.mp4`,gif:`https://example.com/sample.gif`,audio:`https://example.com/sample.mp3`,icon:`https://example.com/icon.png`};function z(e,t){let n=L(e);switch(t){case`minimal`:return{...n,body:`Test notification`};case`overflow`:return{...n,body:`X`.repeat(e.bodyMaxLen+50)};case`critical`:{let t=I(e);return{...n,body:`Critical test notification`,priority:5,level:t?.id??``}}case`everything`:{let t={},n=0;for(let r of e.attachments.mediaTypes){if(n>=e.attachments.max)break;t[r]=R[r],n+=1}let r=Array.from({length:e.actions},(e,t)=>({label:`Action ${t+1}`,url:`https://example.com/action/${t+1}`}));return{level:``,priority:4,format:e.format.includes(`markdown`)?`markdown`:e.format.includes(`html`)?`html`:e.format[0]??`text`,title:`Everything the kind supports`,body:`This sample fills every control the kind advertises.`,attachmentUrls:t,actions:r,clickUrl:e.clickUrl?`https://example.com/open`:``,sound:e.sound?`default`:``,ttl:e.ttl?`3600`:``,tag:`camstack-test`}}}}var B=[{id:`minimal`,label:`Minimal (body only)`},{id:`everything`,label:`Everything supported`},{id:`overflow`,label:`Overflow`},{id:`critical`,label:`Critical`}],V=`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none`,H=`block text-[11px] font-medium text-foreground mb-1`;function U({target:e,kind:t,open:i,onClose:l}){let d=v(),m=p(()=>A(t.caps),[t.caps]),[y,b]=h(()=>L(t.caps)),[x,S]=h(null),w=p(()=>P(t.caps,y),[t.caps,y]),E=y.body.length,D=E>m.bodyMaxLen,O=e=>b(t=>({...t,...e})),k=g({mutationFn:()=>d.trpcClient.notificationOutput.testTarget.mutate({addonId:e.addonId,targetId:e.id,sample:P(t.caps,y)}),onMutate:()=>S(null),onSuccess:e=>S(e),onError:e=>S({success:!1,error:e instanceof Error?e.message:`Test failed`})}),j=e=>{b(z(t.caps,e)),S(null)},M=(e,t,n)=>{let r=y.actions.length>0?[...y.actions]:[];for(;r.length<=e;)r.push({label:``,url:``});r[e]={...r[e],[t]:n},O({actions:r})};return _(c,{open:i,onOpenChange:e=>!e&&l(),children:f(r,{width:`lg`,className:`!max-w-2xl`,children:[_(o,{children:f(a,{children:[`Test "`,e.name,`" (`,t.label,`)`]})}),f(`div`,{className:`space-y-4 max-h-[60vh] overflow-y-auto pr-1`,children:[_(`div`,{className:`flex flex-wrap gap-1.5`,children:B.map(e=>_(n,{size:`sm`,variant:`outline`,type:`button`,onClick:()=>j(e.id),children:e.label},e.id))}),f(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[m.levels.length>0&&f(`div`,{children:[_(`label`,{className:H,children:`Level`}),f(`select`,{className:V,value:y.level,onChange:e=>O({level:e.target.value}),children:[_(`option`,{value:``,children:`— derive from priority —`}),m.levels.map(e=>f(`option`,{value:e.id,children:[e.label,e.ordinal===null?` (qualitative)`:` (p${e.ordinal})`]},e.id))]}),(()=>{let e=m.levels.find(e=>e.id===y.level);return e?f(`div`,{className:`mt-1 space-y-1`,children:[e.description&&_(`p`,{className:`text-[10px] text-foreground-subtle`,children:e.description}),f(`div`,{className:`flex flex-wrap gap-1`,children:[e.flags?.critical&&_(u,{variant:`danger`,"data-testid":`flag-critical`,children:`critical`}),e.flags?.silent&&_(u,{variant:`info`,children:`silent`}),e.flags?.noPush&&_(u,{variant:`warning`,children:`no-push`})]}),e.requires&&e.requires.length>0&&f(`p`,{className:`text-[10px] text-warning`,children:[`Requires target config: `,e.requires.join(`, `)]})]}):null})()]}),f(`div`,{children:[f(`label`,{className:H,children:[`Priority (ordinal): `,y.priority]}),_(`input`,{type:`range`,min:1,max:5,step:1,value:y.priority,onChange:e=>O({priority:Number(e.target.value)}),className:`w-full accent-primary`,"aria-label":`priority`})]})]}),m.formats.length>0&&f(`div`,{children:[_(`label`,{className:H,children:`Format`}),_(`div`,{className:`flex flex-wrap gap-2`,children:m.formats.map(e=>f(`label`,{className:`flex items-center gap-1.5 text-xs cursor-pointer`,children:[_(`input`,{type:`radio`,name:`format`,className:`accent-primary`,checked:y.format===e,onChange:()=>O({format:e})}),e]},e))})]}),f(`div`,{children:[_(`label`,{className:H,children:`Title`}),_(`input`,{className:V,value:y.title,onChange:e=>O({title:e.target.value})})]}),f(`div`,{children:[f(`label`,{className:H,children:[`Body`,` `,f(`span`,{className:D?`text-danger`:`text-foreground-subtle`,children:[`(`,E,`/`,m.bodyMaxLen,D?` — overflow`:``,`)`]})]}),_(`textarea`,{className:`${V} min-h-[80px] resize-y`,value:y.body,onChange:e=>O({body:e.target.value})})]}),m.attachmentSlots.length>0&&f(`div`,{children:[f(`label`,{className:H,children:[`Attachments`,` `,f(`span`,{className:`text-foreground-subtle`,children:[`(mode: `,m.attachmentMode,`, max `,m.attachmentMax,m.attachmentMaxBytes?`, ≤${Math.round(m.attachmentMaxBytes/1024/1024)}MB`:``,`)`]})]}),_(`div`,{className:`space-y-1.5`,children:m.attachmentSlots.map(e=>f(`div`,{className:`flex items-center gap-2`,children:[_(`span`,{className:`text-[10px] w-12 shrink-0 text-foreground-subtle`,children:e}),_(`input`,{className:V,placeholder:`${e} URL`,value:y.attachmentUrls[e]??``,onChange:t=>O({attachmentUrls:{...y.attachmentUrls,[e]:t.target.value}})})]},e))})]}),m.showActions&&f(`div`,{children:[f(`label`,{className:H,children:[`Actions (up to `,m.maxActions,`)`]}),_(`div`,{className:`space-y-1.5`,children:Array.from({length:Math.min(m.maxActions,3)},(e,t)=>f(`div`,{className:`flex items-center gap-2`,children:[_(`input`,{className:V,placeholder:`label`,value:y.actions[t]?.label??``,onChange:e=>M(t,`label`,e.target.value)}),_(`input`,{className:V,placeholder:`url`,value:y.actions[t]?.url??``,onChange:e=>M(t,`url`,e.target.value)})]},t))})]}),f(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[m.showClickUrl&&f(`div`,{children:[_(`label`,{className:H,children:`Click URL`}),_(`input`,{className:V,value:y.clickUrl,onChange:e=>O({clickUrl:e.target.value})})]}),m.showSound&&f(`div`,{children:[_(`label`,{className:H,children:`Sound`}),_(`input`,{className:V,value:y.sound,onChange:e=>O({sound:e.target.value})})]}),m.showTtl&&f(`div`,{children:[_(`label`,{className:H,children:`TTL (seconds)`}),_(`input`,{className:V,type:`number`,value:y.ttl,onChange:e=>O({ttl:e.target.value})})]}),m.showTag&&f(`div`,{children:[_(`label`,{className:H,children:`Tag`}),_(`input`,{className:V,value:y.tag,onChange:e=>O({tag:e.target.value})})]})]}),x&&_(W,{result:x}),f(`details`,{className:`text-[10px]`,children:[_(`summary`,{className:`cursor-pointer text-foreground-subtle`,children:`Payload preview`}),_(`pre`,{className:`mt-1 overflow-x-auto rounded bg-surface p-2 text-foreground-subtle`,children:JSON.stringify(w,null,2)})]})]}),f(s,{children:[_(n,{variant:`secondary`,size:`sm`,type:`button`,onClick:l,children:`Close`}),f(n,{size:`sm`,type:`button`,disabled:k.isPending||y.body.length===0,onClick:()=>k.mutate(),children:[k.isPending?_(T,{className:`h-3.5 w-3.5 animate-spin`}):_(C,{className:`h-3.5 w-3.5`}),`Send test`]})]})]})})}function W({result:e}){let t=e.renderedAs;return f(`div`,{className:`rounded-md border px-3 py-2 text-xs ${e.success?`border-success/40 bg-success/10`:`border-danger/40 bg-danger/10`}`,"data-testid":`test-result`,children:[f(`div`,{className:`flex items-center gap-2 font-medium`,children:[e.success?_(y,{className:`h-3.5 w-3.5 text-success`}):_(w,{className:`h-3.5 w-3.5 text-danger`}),_(`span`,{children:e.success?`Delivered`:`Failed`})]}),e.error&&_(`p`,{className:`mt-1 text-danger`,children:e.error}),t&&f(`dl`,{className:`mt-2 grid grid-cols-2 gap-x-3 gap-y-0.5 text-[11px] text-foreground-subtle`,children:[_(`dt`,{children:`Resolved level`}),_(`dd`,{className:`text-foreground`,children:t.level}),_(`dt`,{children:`Format sent`}),_(`dd`,{className:`text-foreground`,children:t.format}),_(`dt`,{children:`Attachments sent`}),_(`dd`,{className:`text-foreground`,children:t.attachmentsSent}),_(`dt`,{children:`Actions sent`}),_(`dd`,{className:`text-foreground`,children:t.actionsSent}),_(`dt`,{children:`Truncated`}),_(`dd`,{className:`text-foreground`,children:t.truncated?`yes`:`no`}),_(`dt`,{children:`Dropped`}),_(`dd`,{className:`text-foreground`,children:t.dropped.length>0?t.dropped.join(`, `):`—`})]})]})}function G(e){let t=[],n=new Map;for(let r of e){let e=n.get(r.addonId);e?e.push(r):(n.set(r.addonId,[r]),t.push(r.addonId))}return t.map(e=>({addonId:e,kinds:n.get(e)??[]}))}function K(e){let t=[],n=e=>{for(let r of e){if(r.type===`password`){t.push(r.key);continue}if(r.type===`group`){n(r.fields);continue}if(r.type===`sub-tabs`)for(let e of r.tabs)n(e.fields)}};for(let t of e.sections)n(t.fields);return t}function q(e,t,n){let r=new Set(n),i={};for(let[n,a]of Object.entries(e)){if(!r.has(n)){i[n]=a;continue}a==null||a===``||a!==t[n]&&(i[n]=a)}return i}function J(e,t){let n=new Set(t),r={};for(let[t,i]of Object.entries(e))r[t]=n.has(t)?``:i;return r}d();var Y=[`notificationOutput`,`listTargets`],X=[`notificationOutput`,`listTargetKinds`];function Z({kind:e,imgClassName:t,fallbackClassName:n}){return e?.iconUrl?_(`img`,{src:e.iconUrl,alt:e.label,className:t,loading:`lazy`,draggable:!1}):_(`span`,{className:n,children:e?.icon??`🔔`})}function Q(){let t=v(),[r,a]=h({mode:`closed`}),[o,s]=h(null),c=m({queryKey:Y,queryFn:()=>t.trpcClient.notificationOutput.listTargets.query({})}),d=m({queryKey:X,queryFn:async()=>(await t.trpcClient.notificationOutput.listTargetKinds.query({})).map(e=>{let t=e.iconUrl;return{...e,configSchema:e.configSchema,iconUrl:t}})}),y=p(()=>d.data??[],[d.data]),S=p(()=>{let e=new Map;for(let t of y)e.set(t.kind,t);return e},[y]),w=g({mutationFn:e=>t.trpcClient.notificationOutput.setTargetEnabled.mutate({addonId:e.target.addonId,targetId:e.target.id,enabled:e.enabled}),onSuccess:()=>void c.refetch()}),k=g({mutationFn:e=>t.trpcClient.notificationOutput.deleteTarget.mutate({addonId:e.addonId,targetId:e.id}),onSuccess:()=>void c.refetch()}),A=o?S.get(o.kind):void 0;return f(O,{icon:E,title:`Notification Targets`,subtitle:`Deliver notifications to ntfy, Pushover, Telegram, Home Assistant and more. Each target's kind declares its capabilities; the test panel shows exactly what a message degrades to.`,actions:f(n,{size:`sm`,type:`button`,onClick:()=>a({mode:`pick-kind`}),children:[_(x,{className:`h-3.5 w-3.5`}),`Add target`]}),children:[c.isLoading&&_(`div`,{className:`flex items-center justify-center py-16`,children:_(T,{className:`h-6 w-6 animate-spin text-primary`})}),c.isError&&!c.isLoading&&_(e,{title:`Failed to load targets`,message:c.error instanceof Error?c.error.message:`Unknown error`,onRetry:()=>void c.refetch()}),!c.isLoading&&!c.isError&&(c.data??[]).length===0&&_(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No notification targets yet. Click "Add target" to configure one.`}),(c.data??[]).length>0&&_(l,{children:_(`ul`,{className:`divide-y divide-border`,children:(c.data??[]).map(e=>{let t=S.get(e.kind);return f(`li`,{className:`flex items-center gap-3 px-4 py-2.5`,children:[_(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface text-xs`,title:t?.label??e.kind,children:_(Z,{kind:t,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:``})}),f(`div`,{className:`min-w-0 flex-1`,children:[_(`div`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),_(`div`,{className:`text-[11px] text-foreground-subtle`,children:t?.label??e.kind})]}),!e.enabled&&_(u,{variant:`warning`,children:`disabled`}),_(i,{checked:e.enabled,onCheckedChange:t=>w.mutate({target:e,enabled:t}),"aria-label":`toggle ${e.name}`}),_(n,{size:`sm`,variant:`ghost`,type:`button`,disabled:!t,onClick:()=>s(e),title:`Test`,children:_(C,{className:`h-3.5 w-3.5`})}),_(n,{size:`sm`,variant:`ghost`,type:`button`,disabled:!t,onClick:()=>t&&a({mode:`form`,kind:t,target:e}),title:`Edit`,children:_(b,{className:`h-3.5 w-3.5`})}),_(n,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>k.mutate(e),title:`Delete`,children:_(D,{className:`h-3.5 w-3.5 text-danger`})})]},e.id)})})}),r.mode===`pick-kind`&&_($,{kinds:y,onCancel:()=>a({mode:`closed`}),onPick:e=>a({mode:`form`,kind:e,target:null})}),r.mode===`form`&&_(ee,{kind:r.kind,target:r.target,onCancel:()=>a({mode:`closed`}),onSaved:()=>{a({mode:`closed`}),c.refetch()}}),o&&A&&_(U,{target:o,kind:A,open:!0,onClose:()=>s(null)})]})}function $({kinds:e,onPick:t,onCancel:r}){let i=p(()=>G(e),[e]);return f(l,{className:`p-4 space-y-4`,children:[f(`div`,{className:`flex items-center justify-between`,children:[_(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Choose a notification kind`}),_(n,{size:`sm`,variant:`ghost`,type:`button`,onClick:r,children:`Cancel`})]}),i.length===0&&_(`p`,{className:`text-xs text-foreground-subtle`,children:`No notification providers are installed. Install the notifiers addon (or connect Home Assistant) to add targets.`}),i.map(e=>f(`div`,{children:[_(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle mb-1.5`,children:e.addonId}),_(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-2`,children:e.kinds.map(n=>f(`button`,{type:`button`,onClick:()=>t(n),className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-xs hover:border-primary/50 hover:bg-surface-hover transition-colors`,children:[_(Z,{kind:n,imgClassName:`h-7 w-7 object-contain`,fallbackClassName:`text-lg leading-7`}),_(`span`,{className:`font-medium text-foreground`,children:n.label}),n.supportsDiscovery&&_(u,{variant:`info`,style:`outline`,children:`discover`})]},`${e.addonId}:${n.kind}`))})]},e.addonId))]})}function ee({kind:e,target:r,onSaved:i,onCancel:a}){let o=v(),s=p(()=>K(e.configSchema),[e.configSchema]),c=p(()=>r?.config??{},[r]),[u,d]=h(r?.name??e.label),[m,y]=h(()=>r?J(r.config,s):{}),[b,x]=h(null),[C,w]=h(null),E=g({mutationFn:()=>o.trpcClient.notificationOutput.discoverTargets.query({addonId:e.addonId,kind:e.kind,config:m}),onSuccess:e=>x(e),onError:e=>w(e instanceof Error?e.message:`Discovery failed`)}),D=g({mutationFn:()=>{let t=q(m,c,s),n={id:r?.id??`${e.kind}-${Date.now()}`,name:u,kind:e.kind,addonId:e.addonId,enabled:r?.enabled??!0,config:t};return o.trpcClient.notificationOutput.upsertTarget.mutate({addonId:e.addonId,target:n})},onSuccess:i,onError:e=>w(e instanceof Error?e.message:`Save failed`)}),O=e=>{d(e.suggestedName),y(t=>({...t,...e.config})),x(null)};return f(l,{className:`p-4 space-y-4`,children:[f(`div`,{className:`flex items-center justify-between`,children:[f(`h3`,{className:`text-sm font-semibold text-foreground flex items-center gap-2`,children:[_(Z,{kind:e,imgClassName:`h-5 w-5 object-contain`,fallbackClassName:`text-lg`}),r?`Edit ${r.name}`:`Add ${e.label} target`]}),_(n,{size:`sm`,variant:`ghost`,type:`button`,onClick:a,children:`Cancel`})]}),C&&_(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:C}),f(`div`,{children:[_(`label`,{className:`block text-[11px] font-medium text-foreground mb-1`,children:`Name`}),_(`input`,{className:`w-full rounded-md border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:border-primary focus:ring-1 focus:ring-primary/30 outline-none`,value:u,onChange:e=>d(e.target.value)})]}),e.supportsDiscovery&&f(`div`,{className:`space-y-2`,children:[f(n,{size:`sm`,variant:`outline`,type:`button`,disabled:E.isPending,onClick:()=>{w(null),E.mutate()},children:[E.isPending?_(T,{className:`h-3.5 w-3.5 animate-spin`}):_(S,{className:`h-3.5 w-3.5`}),`Discover`]}),b&&b.length===0&&_(`p`,{className:`text-[11px] text-foreground-subtle`,children:`No candidates discovered.`}),b&&b.length>0&&_(`div`,{className:`rounded-md border border-border divide-y divide-border`,children:b.map((e,t)=>f(`button`,{type:`button`,onClick:()=>O(e),className:`flex w-full items-center justify-between px-3 py-1.5 text-xs hover:bg-surface-hover`,children:[_(`span`,{className:`text-foreground`,children:e.suggestedName}),_(`span`,{className:`text-[10px] text-primary`,children:`use`})]},`${e.suggestedName}-${t}`))})]}),s.length>0&&r&&_(`p`,{className:`text-[10px] text-foreground-subtle`,children:`Secret fields are hidden. Leave them blank to keep the stored value; type a new value to replace it.`}),_(t,{schema:e.configSchema,values:m,onChange:y}),f(`div`,{className:`flex justify-end gap-2`,children:[_(n,{variant:`secondary`,size:`sm`,type:`button`,onClick:a,children:`Cancel`}),f(n,{size:`sm`,type:`button`,disabled:D.isPending||u.trim().length===0,onClick:()=>{w(null),D.mutate()},children:[D.isPending&&_(T,{className:`h-3.5 w-3.5 animate-spin`}),r?`Save changes`:`Create target`]})]})]})}export{Q as NotificationTargetsPage,Q as default};
|