@camstack/addon-admin-ui 1.1.63 → 1.1.76

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.
Files changed (78) hide show
  1. package/dist/assets/{AddLocationWizard-VuBsssbs.js → AddLocationWizard-2u_gFK5r.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-rY0iw4Lx.js → AddonCollectionPage-BtQi77vB.js} +1 -1
  3. package/dist/assets/{Addons-waDrxMrF.js → Addons-q0boPiKK.js} +1 -1
  4. package/dist/assets/{AdminTabs-DdlxkzYF.js → AdminTabs-CfA0_5OD.js} +1 -1
  5. package/dist/assets/{AiProfiles-CXfreEns.js → AiProfiles-12yfskcw.js} +1 -1
  6. package/dist/assets/{BrokerForm-Bi1zDzJU.js → BrokerForm-nhcwidi1.js} +1 -1
  7. package/dist/assets/{Capabilities-CBqnCVAQ.js → Capabilities-BjMQsKTo.js} +1 -1
  8. package/dist/assets/{CapabilityBadges-bb3Kp76B.js → CapabilityBadges-BakiZcjD.js} +1 -1
  9. package/dist/assets/{Cluster-CkmNDo_z.js → Cluster-BwgzopHZ.js} +1 -1
  10. package/dist/assets/{ClusterRecordingTab-qj7qdRav.js → ClusterRecordingTab-B0_gkStF.js} +1 -1
  11. package/dist/assets/{Dashboard-0L-WtwHw.js → Dashboard-pQbzHfgq.js} +1 -1
  12. package/dist/assets/{Data-B-KdcyYb.js → Data-CzQQRAUi.js} +1 -1
  13. package/dist/assets/{DetectionIntelligence-DH2CerYz.js → DetectionIntelligence-soDZAfMX.js} +1 -1
  14. package/dist/assets/{DeviceDetail-C0xHmlNy.js → DeviceDetail-CDSavlTS.js} +1 -1
  15. package/dist/assets/{Devices-BqWTi9bF.js → Devices-B6mG0goh.js} +1 -1
  16. package/dist/assets/{EmbedPlayerPage-BmllV_ir.js → EmbedPlayerPage-DvdfwqWo.js} +1 -1
  17. package/dist/assets/{Events-Cg33ehHw.js → Events-C4TJ3f2M.js} +1 -1
  18. package/dist/assets/{FormBuilder-DDOu77Pz.js → FormBuilder-CJZT56JQ.js} +1 -1
  19. package/dist/assets/{Identity-DokGTNX5.js → Identity-DJpfxWAy.js} +1 -1
  20. package/dist/assets/{IntegrationDetail-HKDhoWtW.js → IntegrationDetail-D_3Eadi3.js} +1 -1
  21. package/dist/assets/{Integrations-qqFL0Gs0.js → Integrations-BlgB2KB5.js} +1 -1
  22. package/dist/assets/{Integrations-as3Ez0fd.js → Integrations-CUYz_Tx5.js} +1 -1
  23. package/dist/assets/{Logs-C0i-qXwM.js → Logs-woqSpCCD.js} +1 -1
  24. package/dist/assets/{MyAccess-52fP18AF.js → MyAccess-lJjPepDE.js} +1 -1
  25. package/dist/assets/{Network-s1InxtpH.js → Network-DEyTei_w.js} +1 -1
  26. package/dist/assets/{NodeAddonsSettingsPanel-PSaY411C.js → NodeAddonsSettingsPanel-xN6mgN_r.js} +1 -1
  27. package/dist/assets/NodeInferenceDevices-BE0uWzGx.js +1 -0
  28. package/dist/assets/{NotificationTargets-BYTjEwxL.js → NotificationTargets-CBBur-rQ.js} +1 -1
  29. package/dist/assets/Pipeline-BZDLzg9Y.js +1 -0
  30. package/dist/assets/{Plates-BwI8RHl9.js → Plates-DjJCFBtx.js} +1 -1
  31. package/dist/assets/{PrivacyMaskSettings-DDk6LoXQ.js → PrivacyMaskSettings-sho_DfbI.js} +1 -1
  32. package/dist/assets/{ProviderIcon-CWyyzoZB.js → ProviderIcon-D0fT0ngj.js} +1 -1
  33. package/dist/assets/{Recordings-D5IKi_ba.js → Recordings-BwUOe7Le.js} +1 -1
  34. package/dist/assets/{ScanNetworkModal-B2bUhuZ1.js → ScanNetworkModal-DH_k2Fpq.js} +1 -1
  35. package/dist/assets/{Settings-DKkqVGNC.js → Settings-CcUo6aya.js} +1 -1
  36. package/dist/assets/{Showroom-ablwi-TX.js → Showroom-CG48sUa4.js} +1 -1
  37. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-CCcHjOIo.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-DUxbvgWS.js} +1 -1
  38. package/dist/assets/{build-cluster-graph-C1vd_7m_.js → build-cluster-graph-DHfHni5F.js} +1 -1
  39. package/dist/assets/circle-check-big-CI9FWu6l.js +1 -0
  40. package/dist/assets/clock-4_YZJVgL.js +1 -0
  41. package/dist/assets/{copy-St-1O01R.js → copy-BQOTIQgm.js} +1 -1
  42. package/dist/assets/{debounced-invalidate-DlIKzA73.js → debounced-invalidate-DugdMzxI.js} +1 -1
  43. package/dist/assets/{download-CJ-1cdDh.js → download-CkwWo7hu.js} +1 -1
  44. package/dist/assets/{face-bbox-CTcnAI8I.js → face-bbox-baLQCp2_.js} +1 -1
  45. package/dist/assets/{hostInit-D4IGCyt3.js → hostInit-BMvgR8TY.js} +1 -1
  46. package/dist/assets/{index-Cjto-EXm.js → index-Cf-I6XLC.js} +3 -3
  47. package/dist/assets/{key-round-LcTErOxf.js → key-round-Bmr95jCJ.js} +1 -1
  48. package/dist/assets/{mf-entry-bootstrap-0-c57c6485.js → mf-entry-bootstrap-0-0623438d.js} +2 -2
  49. package/dist/assets/{pencil-BkXeyiDf.js → pencil-B1DqIkdM.js} +1 -1
  50. package/dist/assets/plus-MB1SLBFq.js +1 -0
  51. package/dist/assets/{radio-CGyv3voN.js → radio-BZuhT7Gn.js} +1 -1
  52. package/dist/assets/{refresh-cw-DC4KMLsa.js → refresh-cw-BmmNps1s.js} +1 -1
  53. package/dist/assets/remoteEntry-CoA55rjc.js +1 -0
  54. package/dist/assets/{rotate-ccw-DlNmHkpr.js → rotate-ccw-ShbJ-WX6.js} +1 -1
  55. package/dist/assets/rotate-cw-BVat1OfU.js +1 -0
  56. package/dist/assets/search-BmUqqa8F.js +1 -0
  57. package/dist/assets/{send-CeJ2J9V3.js → send-BeH97ECp.js} +1 -1
  58. package/dist/assets/{server-CArIZ-KL.js → server-v0X3NJkl.js} +1 -1
  59. package/dist/assets/square-DNYsOuV5.js +1 -0
  60. package/dist/assets/{square-check-big--y441eG8.js → square-check-big-DnKLHlgq.js} +1 -1
  61. package/dist/assets/{src-CfZUxvPx.js → src-CjsGEszD.js} +5 -5
  62. package/dist/assets/{upload-D6H_84gF.js → upload-DDoEZa7L.js} +1 -1
  63. package/dist/assets/{useEventInvalidation-DxjiYIcd.js → useEventInvalidation-DXhf2xEu.js} +1 -1
  64. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-zgU2Aw4J.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BcCLnA5F.js} +2 -2
  65. package/dist/assets/{wifi-B0toFYT9.js → wifi-FAJILiwT.js} +1 -1
  66. package/dist/assets/{zap-d6IKZFEN.js → zap-Daoo8ovU.js} +1 -1
  67. package/dist/index.html +3 -3
  68. package/dist/server/addon.js +1 -1
  69. package/package.json +1 -1
  70. package/dist/assets/NodeInferenceDevices-CoLAPH96.js +0 -1
  71. package/dist/assets/Pipeline-D3jI3Huf.js +0 -1
  72. package/dist/assets/circle-check-big-GmO5fdEl.js +0 -1
  73. package/dist/assets/clock-OUNfpFX_.js +0 -1
  74. package/dist/assets/plus-DXXZ8pd7.js +0 -1
  75. package/dist/assets/remoteEntry-CXtVdVO7.js +0 -1
  76. package/dist/assets/rotate-cw-d8IjPUYX.js +0 -1
  77. package/dist/assets/search-DkClo4ZA.js +0 -1
  78. package/dist/assets/square-BFjZ9GUs.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-CfZUxvPx.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-DlNmHkpr.js";import{t as M}from"./copy-St-1O01R.js";import{n as re,t as N}from"./AddonCollectionPage-rY0iw4Lx.js";import{t as ie}from"./refresh-cw-DC4KMLsa.js";import{t as P}from"./server-CArIZ-KL.js";import{t as ae}from"./square-BFjZ9GUs.js";import{t as oe}from"./wifi-B0toFYT9.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-Cjto-EXm.js";import{t as V}from"./AdminPage-BwmGKnRf.js";import{t as H}from"./AdminTabs-DdlxkzYF.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-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 +1 @@
1
- import{bt as e,dt as t,ft as n,on as r,zt as i}from"./src-CfZUxvPx.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-DDOu77Pz.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-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};
@@ -0,0 +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 +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-CfZUxvPx.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-GmO5fdEl.js";import{t as b}from"./pencil-BkXeyiDf.js";import{t as x}from"./plus-DXXZ8pd7.js";import{t as S}from"./search-DkClo4ZA.js";import{t as C}from"./send-CeJ2J9V3.js";import{N as w,S as T,V as E,s as D}from"./index-Cjto-EXm.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-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};
@@ -0,0 +1 @@
1
+ import{$r as e,Ci as t,Ei as n,Eo as r,Ha as i,Ii as a,Ka as o,La as s,Mi as c,Ni as l,Pi as u,Qr as d,Si as f,T as p,Ti as m,To as h,Ua as g,Va as _,Vr as v,Wa as y,Xa as b,Ya as x,_ as S,_i as C,ai as w,bi as T,ci as E,di as D,ei as O,ft as k,g as A,gi as j,ii as M,ji as N,li as ee,lt as te,mi as P,ni as ne,oi as re,qa as ie,ri as ae,si as oe,ti as se,ut as ce,vi as le,wi as ue,xi as de,yi as fe,yo as F}from"./src-CjsGEszD.js";import{I as pe,K as me,Q as I,S as L,T as he,W as R,b as z,o as B,q as V,x as H,z as U}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{G as ge,K as _e,X as ve}from"./src-CCZM6rtM.js";import{c as ye,n as be,o as xe,r as Se,s as Ce,t as we}from"./NodeInferenceDevices-BE0uWzGx.js";import{t as Te}from"./download-CkwWo7hu.js";import{i as Ee}from"./AddLocationWizard-2u_gFK5r.js";import{n as De,r as Oe,t as ke}from"./zap-Daoo8ovU.js";import{t as Ae}from"./pencil-B1DqIkdM.js";import{t as je}from"./plus-MB1SLBFq.js";import{t as Me}from"./radio-BZuhT7Gn.js";import{t as Ne}from"./refresh-cw-BmmNps1s.js";import{t as Pe}from"./search-BmUqqa8F.js";import{t as Fe}from"./server-v0X3NJkl.js";import{t as Ie}from"./square-check-big-DnKLHlgq.js";import{t as Le}from"./square-DNYsOuV5.js";import{E as Re,I as ze,J as Be,L as W,M as Ve,N as He,P as Ue,S as G,T as We,W as Ge,i as Ke,j as K,o as qe,s as Je}from"./index-Cf-I6XLC.js";import{t as Ye}from"./AdminPage-BwmGKnRf.js";import{t as Xe}from"./useEventInvalidation-DXhf2xEu.js";import{r as Ze,t as Qe}from"./build-cluster-graph-DHfHni5F.js";import{n as $e}from"./format-size-CO9d3C3-.js";import{t as et}from"./NodeAddonsSettingsPanel-xN6mgN_r.js";import{n as tt,t as nt}from"./ClusterRecordingTab-B0_gkStF.js";var rt=Ge(`ellipsis-vertical`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]]),it=Ge(`flame`,[[`path`,{d:`M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 0 0 2.5 2.5z`,key:`96xj49`}]]),at=Ge(`pin`,[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z`,key:`1nkz8b`}]]);I();function ot(e){return e}function st(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function ct(e,t){return typeof e==`boolean`?e:ot(t)}function lt(e,t){return{pipeline:ct(st(e,`detect`),t),audio:ct(st(e,`audio`),t),ingest:ct(st(e,`ingest`),t)}}function ut(e,t,n){let r=e?.find(e=>e.nodeId===t);return lt(r?.settings,n)}function dt({selectedNodeId:e,onSelect:t,refreshToken:n}){let{data:i}=v(void 0),{data:a}=j(void 0),{data:o}=le(void 0),s=new Map;for(let e of a??[])s.set(e.agentNodeId,(s.get(e.agentNodeId)??0)+1);let c=i??[],l=c.filter(e=>e.isOnline).length,u=c.filter(e=>!e.isOnline).length;return L(`div`,{className:`flex flex-col h-full`,children:[L(`button`,{type:`button`,onClick:()=>t(yr),className:`flex items-center gap-3 px-4 py-3 border-b border-border text-left transition-colors ${e===`__cluster__`?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}`,children:[H(We,{className:`h-4 w-4 flex-shrink-0`}),L(`div`,{className:`min-w-0 flex-1`,children:[H(`div`,{className:`text-xs font-semibold truncate`,children:`Cluster`}),H(`div`,{className:`text-[10px] text-foreground-subtle`,children:`Balancer + failover + assignments`})]})]}),H(`div`,{className:`flex-1 overflow-y-auto`,children:c.map(n=>{let i=e===n.id,a=s.get(n.id)??0,c=n.isHub?Fe:K,l=ut(o,n.id,n.isHub),u=n.isOnline?null:r(Ze(n.lastSeen));return L(`button`,{type:`button`,onClick:()=>t(n.id),className:`flex items-center gap-3 w-full px-4 py-3 border-b border-border text-left transition-colors ${i?`bg-primary/10 text-primary`:`text-foreground hover:bg-surface-hover`}${n.isOnline?``:` opacity-60`}`,children:[H(c,{className:`h-4 w-4 flex-shrink-0`}),L(`div`,{className:`min-w-0 flex-1`,children:[L(`div`,{className:`flex items-center gap-2`,children:[H(`span`,{className:`text-xs font-semibold truncate`,children:n.name}),n.isHub&&H(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`}),!n.isOnline&&H(`span`,{className:`h-1.5 w-1.5 rounded-full bg-destructive flex-shrink-0`}),n.isOnline&&H(`span`,{className:`h-1.5 w-1.5 rounded-full bg-success flex-shrink-0`})]}),L(`div`,{className:`text-[10px] text-foreground-subtle flex items-center gap-2 mt-0.5`,children:[L(`span`,{children:[n.cpuCores,` cores`]}),H(`span`,{children:`•`}),L(`span`,{children:[Math.round(n.memoryMB/1024),` GB`]}),a>0&&L(z,{children:[H(`span`,{children:`•`}),L(`span`,{className:`inline-flex items-center gap-0.5 text-foreground`,children:[H(De,{className:`h-2.5 w-2.5`}),a]})]}),!n.isOnline&&L(z,{children:[H(`span`,{children:`•`}),L(`span`,{className:`text-destructive`,children:[`offline`,u===null?``:` · ${u}`]})]})]}),L(`div`,{className:`mt-0.5 flex items-center gap-1`,children:[H(F,{variant:l.pipeline?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:l.pipeline?`Pipeline: enabled`:`Pipeline: not enabled (agent capability)`,children:`Pipe`}),H(F,{variant:l.audio?`success`:`danger`,className:`px-1 py-0 text-[9px] leading-3`,title:l.audio?`Audio: enabled`:`Audio: not enabled (agent capability)`,children:`Aud`})]})]})]},n.id)})}),L(`div`,{className:`px-4 py-2 border-t border-border text-[10px] text-foreground-subtle flex items-center justify-between`,children:[L(`span`,{children:[l,` online`]}),u>0&&L(`span`,{className:`text-destructive`,children:[u,` offline`]})]})]})}function ft({nodeId:e,refreshToken:t}){let{data:n}=v(void 0),r=n?.find(t=>t.id===e),a=i(`pipeline.runner-load-snapshot`,t=>t.nodeId===e)?.load??null;return r?L(`div`,{className:`px-6 py-4 border-b border-border`,children:[L(`div`,{className:`flex items-center gap-2 mb-1`,children:[H(`h2`,{className:`text-base font-semibold text-foreground`,children:r.name}),r.isOnline?H(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-success/10 text-success`,children:`online`}):H(`span`,{className:`text-[10px] px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`}),r.isHub&&H(`span`,{className:`text-[9px] uppercase tracking-wider text-foreground-subtle border border-border rounded px-1 py-0.5`,children:`hub`})]}),L(`div`,{className:`text-[11px] text-foreground-subtle flex items-center gap-2 flex-wrap`,children:[H(`span`,{children:r.cpuModel??`CPU`}),H(`span`,{children:`•`}),L(`span`,{children:[r.cpuCores,` cores`]}),H(`span`,{children:`•`}),L(`span`,{children:[Math.round(r.memoryMB/1024),` GB`]}),a&&L(z,{children:[H(`span`,{children:`•`}),L(`span`,{children:[a.attachedCameras,` cameras (`,a.activeCameras,` active)`]}),H(`span`,{children:`•`}),L(`span`,{children:[a.avgInferenceTimeMs.toFixed(0),`ms avg inference`]}),H(`span`,{children:`•`}),L(`span`,{children:[`queue `,a.queueDepthTotal]}),a.hardware.hasGpu&&L(z,{children:[H(`span`,{children:`•`}),H(`span`,{className:`text-success`,children:`GPU`})]})]})]})]}):H(`div`,{className:`px-6 py-4 border-b border-border`,children:L(`div`,{className:`text-xs text-foreground-subtle`,children:[`Node not found: `,e]})})}function pt({refreshToken:e,nodeId:t}){let[n,r]=V(new Map),{nodes:i}=_();y(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t?.deviceId==`number`&&r(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})});let{data:a}=ee(void 0),o=R(()=>{let e=new Map;for(let t of a??[])e.set(t.nodeId,t.deviceCount);return e},[a]),s=R(()=>{let e=new Map,t=Date.now()-3e4;for(let r of n.values()){if(r.timestamp<t)continue;let n=r.nodeId??`hub`,i=e.get(n)??{attachedCameras:0,activeCameras:0,totalFps:0,totalInferenceWeighted:0,queueDepth:0};i.attachedCameras++,r.metrics.phase===`active`&&i.activeCameras++,i.totalFps+=r.metrics.actualFps,i.totalInferenceWeighted+=r.metrics.avgInferenceTimeMs,i.queueDepth+=r.metrics.queueDepth,e.set(n,i)}return e},[n]),c=R(()=>{let e=new Map;for(let t of i)e.set(t.id,t.shortName);return e},[i]),l=R(()=>{let e=0,t=0,n=0,r=0,a=0;for(let i of s.values())e+=i.attachedCameras,t+=i.activeCameras,n+=i.totalFps,r+=i.totalInferenceWeighted,a+=i.queueDepth;let o=e>0?r/e:0;return{totalAgents:i.length,onlineAgents:i.filter(e=>e.isOnline).length,attachedCameras:e,activeCameras:t,avgInferenceTimeMs:o,queueDepth:a,totalFps:n}},[s,i]);if(t){let e=s.get(t);return L(`div`,{className:`@container/liveload`,children:[H(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),L(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 mb-3`,children:[H(q,{label:`FPS`,value:e?e.totalFps.toFixed(1):`—`}),H(q,{label:`Active / Attached`,value:e?`${e.activeCameras}/${e.attachedCameras}`:`—`}),H(q,{label:`Avg infer ms`,value:e&&e.attachedCameras>0?(e.totalInferenceWeighted/e.attachedCameras).toFixed(0):`—`}),H(q,{label:`Queue`,value:e?String(e.queueDepth):`—`}),H(q,{label:`Audio`,value:String(o.get(t)??`—`)})]})]})}let u=[...s.entries()].toSorted(([e],[t])=>e===`hub`?-1:t===`hub`?1:e.localeCompare(t));return L(`div`,{className:`@container/liveload`,children:[H(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:`Live load`}),L(`div`,{className:`grid grid-cols-2 @md/liveload:grid-cols-3 @3xl/liveload:grid-cols-5 gap-2 sm:gap-3 mb-3`,children:[H(q,{label:`Total agents`,value:`${l.onlineAgents}/${l.totalAgents}`}),H(q,{label:`Active / Attached`,value:`${l.activeCameras}/${l.attachedCameras}`}),H(q,{label:`Total FPS`,value:l.totalFps.toFixed(1)}),H(q,{label:`Avg inference ms`,value:l.avgInferenceTimeMs.toFixed(0)}),H(q,{label:`Queue depth`,value:String(l.queueDepth)})]}),H(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:L(`table`,{className:`w-full text-xs min-w-[480px]`,children:[H(`thead`,{className:`bg-surface`,children:L(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[H(`th`,{className:`text-left px-3 py-2`,children:`Agent`}),H(`th`,{className:`text-right px-3 py-2`,children:`FPS`}),H(`th`,{className:`text-right px-3 py-2`,children:`Cameras`}),H(`th`,{className:`text-right px-3 py-2`,children:`Inference ms`}),H(`th`,{className:`text-right px-3 py-2`,children:`Queue`}),H(`th`,{className:`text-right px-3 py-2`,children:`Audio`})]})}),L(`tbody`,{children:[u.map(([e,t])=>L(`tr`,{className:`border-t border-border`,children:[H(`td`,{className:`px-3 py-2 text-foreground font-medium`,children:c.get(e)??e}),H(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.totalFps.toFixed(1)}),H(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras}),H(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.attachedCameras>0?(t.totalInferenceWeighted/t.attachedCameras).toFixed(0):`—`}),H(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t.queueDepth}),H(`td`,{className:`px-3 py-2 text-right text-foreground`,children:o.get(e)??`—`})]},e)),u.length===0&&H(`tr`,{children:H(`td`,{colSpan:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No camera metrics received yet`})})]})]})})]})}function q({label:e,value:t}){return L(`div`,{className:`rounded-lg border border-border bg-surface/60 p-3`,children:[H(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle mb-1`,children:e}),H(`div`,{className:`text-lg font-semibold text-foreground`,children:t})]})}I();var mt={active:!1,pinned:!1,nodeId:null,reason:``},ht=[`pipeline.camera-assigned`,`pipeline.camera-unassigned`,`pipeline.camera-updated`,`agent.online`,`agent.offline`],gt={pipeline:K,decoder:Re,audio:Oe},_t={pipeline:`Pipeline`,decoder:`Decoder`,audio:`Audio`};function vt({mode:e,nodeId:t,compact:n=!1}){if(e===`agent`&&!t)throw Error(`CameraAssignmentsTable: nodeId is required when mode === "agent"`);let r=B(),[i,a]=V(null),[o,s]=V(null),[u,d]=V(new Map);Xe([`pipelineOrchestrator`,`getPipelineAssignments`],ht),Xe([`pipelineOrchestrator`,`getAudioAssignments`],ht),Xe([`pipelineOrchestrator`,`getCameraStatuses`],ht);let{data:f}=j(void 0),{data:m}=E(void 0),{data:h}=D({},{enabled:e===`agent`}),{nodes:g}=_(),{data:v}=xe();y(`pipeline.camera-metrics-snapshot`,e=>{let t=e.data;typeof t.deviceId==`number`&&d(e=>{let n=new Map(e);return n.set(t.deviceId,t),n})}),U(()=>{if(u.size===0)return;let e=setInterval(()=>{d(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[u.size]);let b=R(()=>{let e=new Map;for(let t of v??[])e.set(t.id,t.name);return e},[v]),x=R(()=>{if(e===`agent`){let e=[];for(let n of h??[]){let r=n.assignment,i=(e,n,r)=>({active:e!==null&&e===t,pinned:n,nodeId:e,reason:r??``}),a=i(r.detectionNodeId,r.pinned.detection,r.reasons.detection),o=i(r.decoderNodeId,r.pinned.decoder,r.reasons.decoder),s=i(r.audioNodeId,r.pinned.audio,r.reasons.audio);!a.active&&!o.active&&!s.active||e.push({deviceId:n.deviceId,deviceName:b.get(n.deviceId)??`Device ${n.deviceId}`,pipeline:a,decoder:o,audio:s})}return e.sort((e,t)=>e.deviceId-t.deviceId),e}let n=new Map,r=e=>{let t=n.get(e);if(t)return t;let r={deviceId:e,deviceName:b.get(e)??`Device ${e}`,pipeline:mt,decoder:mt,audio:mt};return n.set(e,r),r};for(let i of f??[]){let a=r(i.deviceId);n.set(i.deviceId,{...a,pipeline:{active:!0,pinned:i.pinned,nodeId:i.agentNodeId,reason:i.reason??``},decoder:{active:e===`cluster`?!0:i.agentNodeId===t,pinned:!1,nodeId:i.agentNodeId,reason:`co-located`}})}for(let e of m??[]){let t=r(e.deviceId);n.set(e.deviceId,{...t,audio:{active:!0,pinned:e.pinned,nodeId:e.nodeId,reason:`capacity`}})}let i=[...n.values()];return i.sort((e,t)=>e.deviceId-t.deviceId),i},[f,m,h,b,e,t]),S=R(()=>(g??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[g]),C=()=>{r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]}),r.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},T=re({onSuccess:C}),O=l({onSuccess:C}),k=w({onSuccess:C}),A=c({onSuccess:C}),M=(e,t,n)=>{t===`pipeline`?T.mutate({deviceId:e,agentNodeId:n}):k.mutate({deviceId:e,nodeId:n}),a(null)},N=(e,t)=>{t===`pipeline`?O.mutate({deviceId:e}):A.mutate({deviceId:e}),a(null)};return H(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:L(`table`,{className:`w-full text-xs min-w-[760px] table-fixed`,children:[H(`thead`,{className:`bg-surface`,children:L(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[!n&&H(`th`,{className:`w-10`}),H(`th`,{className:`min-w-[200px] text-left px-3 py-2 align-middle`,children:`Camera`}),e===`cluster`?L(z,{children:[H(`th`,{className:`w-[168px] text-left px-3 py-2 align-middle`,children:`Auto | Pin`}),H(`th`,{className:`w-[188px] text-left px-3 py-2 align-middle`,children:`Resolved placement`})]}):L(z,{children:[H(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Pipeline`}),H(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Decoder`}),H(`th`,{className:`w-[120px] text-left px-3 py-2 align-middle`,children:`Audio`})]}),H(`th`,{className:`w-[132px] text-left px-3 py-2 align-middle`,children:`Status`})]})}),L(`tbody`,{children:[x.map(t=>{let r=u.get(t.deviceId),c=o===t.deviceId;return L(he.Fragment,{children:[L(`tr`,{className:`border-t border-border align-middle relative`,children:[!n&&H(`td`,{className:`px-2 py-2 align-middle`,children:H(`button`,{type:`button`,onClick:()=>s(c?null:t.deviceId),className:`p-1 rounded hover:bg-surface-hover text-foreground-subtle`,"aria-label":c?`Collapse broker details`:`Expand broker details`,children:H(c?ze:Ue,{className:`h-3.5 w-3.5`})})}),L(`td`,{className:`px-3 py-2 align-middle min-w-0`,children:[H(`div`,{className:`text-foreground font-medium leading-tight line-clamp-2 break-words`,title:t.deviceName,children:t.deviceName}),L(`div`,{className:`text-[10px] text-foreground-subtle leading-tight`,children:[`#`,t.deviceId]})]}),e===`cluster`?L(z,{children:[H(`td`,{className:`px-3 py-2 align-middle`,children:H(bt,{state:t.pipeline,onlineNodes:S,pending:T.isPending||O.isPending,onChange:e=>{e===`auto`?N(t.deviceId,`pipeline`):M(t.deviceId,`pipeline`,e)}})}),H(`td`,{className:`px-3 py-2 align-middle`,children:H(xt,{state:t.pipeline})})]}):L(z,{children:[H(St,{role:`pipeline`,state:t.pipeline,mode:e,deviceId:t.deviceId,onlineNodes:S,isMenuOpen:i?.deviceId===t.deviceId&&i.role===`pipeline`,onToggleMenu:()=>a(i?.deviceId===t.deviceId&&i.role===`pipeline`?null:{deviceId:t.deviceId,role:`pipeline`}),onCloseMenu:()=>a(null),onMove:e=>M(t.deviceId,`pipeline`,e),onUnpin:()=>N(t.deviceId,`pipeline`)}),H(St,{role:`decoder`,state:t.decoder,mode:e,deviceId:t.deviceId,onlineNodes:S,readOnly:!0,isMenuOpen:!1,onToggleMenu:()=>void 0,onCloseMenu:()=>void 0,onMove:()=>void 0,onUnpin:()=>void 0}),H(St,{role:`audio`,state:t.audio,mode:e,deviceId:t.deviceId,onlineNodes:S,isMenuOpen:i?.deviceId===t.deviceId&&i.role===`audio`,onToggleMenu:()=>a(i?.deviceId===t.deviceId&&i.role===`audio`?null:{deviceId:t.deviceId,role:`audio`}),onCloseMenu:()=>a(null),onMove:e=>M(t.deviceId,`audio`,e),onUnpin:()=>N(t.deviceId,`audio`)})]}),H(`td`,{className:`px-3 py-2 align-middle`,children:H(Et,{snap:r})})]}),c&&!n&&L(`tr`,{className:`bg-surface/50`,children:[H(`td`,{}),L(`td`,{colSpan:e===`cluster`?4:5,className:`px-3 py-2 space-y-3`,children:[t.pipeline.nodeId&&H(yt,{deviceId:t.deviceId,nodeId:t.pipeline.nodeId}),H(p,{widgetId:`stream-broker/stream-broker-panel`,host:`device-tab`,deviceId:t.deviceId,instanceId:`pipeline-row/${t.deviceId}`,config:{variant:`compact`,title:`Stream brokers & clients`}})]})]})]},t.deviceId)}),x.length===0&&H(`tr`,{children:H(`td`,{colSpan:n?e===`cluster`?4:5:e===`cluster`?5:6,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:e===`agent`?`No cameras assigned to this node`:`No cameras currently assigned`})})]})]})})}function yt({deviceId:e,nodeId:t}){let n=B(),{data:r}=P({nodeId:t}),{data:i}=C({deviceId:e}),a=N({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineDevicePin`]]})}}),o=r?.devices??[],s=i?.deviceKey??`auto`,c=s!==`auto`&&!o.some(e=>e.key===s);return L(`label`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[H(`span`,{className:`shrink-0 font-medium text-foreground`,children:`Inference device`}),L(`select`,{value:s,disabled:a.isPending,"aria-label":`Inference device pin`,onChange:t=>a.mutate({deviceId:e,deviceKey:t.target.value}),className:`rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[H(`option`,{value:`auto`,children:`Auto (balanced)`}),c&&L(`option`,{value:s,children:[`Pin → `,s,` (not on this node)`]}),o.map(e=>L(`option`,{value:e.key,children:[`Pin → `,e.key,e.available?``:` (unavailable)`]},e.key))]}),a.isPending&&H(`span`,{className:`text-[10px] opacity-70`,children:`saving…`})]})}function bt({state:e,onlineNodes:t,pending:n,onChange:r}){let i=e.pinned&&e.nodeId?e.nodeId:`auto`,a=[...new Set([...e.nodeId?[e.nodeId]:[],...t.map(e=>e.id)])];return L(`select`,{value:i,disabled:n,"aria-label":`Pipeline placement pin`,onChange:e=>r(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground`,children:[H(`option`,{value:`auto`,children:`Auto`}),a.map(e=>L(`option`,{value:e,children:[`Pin → `,t.find(t=>t.id===e)?.name??e]},e))]})}function xt({state:e}){if(!e.active||!e.nodeId)return H(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`});let t=e.pinned?`pinned · manual`:`auto · ${e.reason||`capacity`}`;return L(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[H(`span`,{className:`font-mono text-[11px] text-foreground truncate`,title:e.nodeId,children:e.nodeId}),H(`span`,{className:`truncate ${e.pinned?`text-amber-400 text-[10px]`:`text-foreground-subtle text-[10px]`}`,title:t,children:t})]})}function St({role:e,state:t,mode:n,onlineNodes:r,readOnly:i=!1,isMenuOpen:a,onToggleMenu:o,onCloseMenu:s,onMove:c,onUnpin:l}){let u=gt[e],d=r.filter(e=>e.id!==(t.nodeId??``)),f=!i&&(t.active||n===`cluster`)&&(d.length>0||t.pinned);return L(`td`,{className:`px-3 py-2 align-middle relative min-w-0`,children:[L(`div`,{className:`flex items-center gap-2 min-w-0`,children:[H(n===`agent`?Ct:wt,{state:t,Icon:u}),H(`div`,{className:`ml-auto shrink-0`,children:f&&H(`button`,{type:`button`,onClick:o,className:`p-1 rounded hover:bg-surface-hover`,"aria-label":`${_t[e]} actions`,children:H(rt,{className:`h-3 w-3 text-foreground-subtle`})})})]}),a&&f&&H(Dt,{title:_t[e],targets:d,pinned:t.pinned,onMove:c,onUnpin:l,onClose:s})]})}function Ct({state:e,Icon:t}){return L(`div`,{className:`flex items-center gap-1.5`,children:[H(e.active?Ie:Le,{className:`h-3.5 w-3.5 ${e.active?`text-success`:`text-foreground-subtle/50`}`}),H(t,{className:`h-3 w-3 ${e.active?`text-foreground-subtle`:`text-foreground-subtle/40`}`}),e.pinned&&H(at,{className:`h-2.5 w-2.5 text-amber-400`})]})}function wt({state:e,Icon:t}){return!e.active||!e.nodeId?L(`div`,{className:`flex items-center gap-1.5 text-foreground-subtle/60`,children:[H(t,{className:`h-3 w-3`}),H(`span`,{className:`text-[10px] italic`,children:`—`})]}):L(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[H(t,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),L(`div`,{className:`flex flex-col leading-tight min-w-0`,children:[H(`span`,{className:`font-mono text-[11px] text-foreground truncate`,children:e.nodeId}),H(`span`,{className:`flex items-center gap-1 text-[10px]`,children:e.pinned?L(`span`,{className:`inline-flex items-center gap-0.5 text-amber-400`,children:[H(at,{className:`h-2.5 w-2.5`}),` manual`]}):L(`span`,{className:`text-foreground-subtle truncate`,children:[`auto · `,e.reason||`capacity`]})})]})]})}var Tt=`min-h-[3.25rem]`;function Et({snap:e}){if(!e)return H(`div`,{className:`flex items-center ${Tt}`,children:H(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`—`})});let{phase:t,actualFps:n,avgInferenceTimeMs:r,queueDepth:i,configuredFps:a,droppedFrames:o}=e.metrics,s=h(t);return L(`div`,{className:`flex flex-col justify-center gap-0.5 font-mono text-[10px] tabular-nums leading-tight min-w-0 ${Tt}`,children:[L(`span`,{className:`inline-flex items-center gap-1 min-w-0 ${s.textColor}`,children:[H(S,{phase:t,className:`h-2.5 w-2.5 shrink-0`}),H(`span`,{className:`font-semibold uppercase tracking-wider truncate`,children:s.label})]}),L(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[H(`span`,{className:`text-foreground`,children:n.toFixed(1)}),L(`span`,{children:[`/`,a.toFixed(0),` fps`]})]}),L(`span`,{className:`text-foreground-subtle whitespace-nowrap truncate`,children:[H(`span`,{className:`text-foreground`,children:r.toFixed(0)}),H(`span`,{children:` ms`}),i>0&&L(`span`,{className:`text-warning ml-1`,children:[`q`,i]})]}),L(`span`,{className:`whitespace-nowrap truncate ${o>0?`text-warning`:`text-foreground-subtle`}`,children:[`drops `,H(`span`,{className:`text-foreground`,children:o})]})]})}function Dt({title:e,targets:t,pinned:n,onMove:r,onUnpin:i,onClose:a}){let o=me(null);return U(()=>{let e=e=>{o.current?.contains(e.target)||a()};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[a]),L(`div`,{ref:o,className:`absolute right-2 top-full mt-1 w-48 rounded-lg border border-border bg-surface shadow-lg z-20 text-left`,children:[H(`div`,{className:`px-3 py-1 text-[9px] uppercase tracking-wider text-foreground-subtle border-b border-border`,children:e}),t.length>0&&H(`div`,{className:`py-1`,children:t.map(e=>L(`button`,{type:`button`,onClick:()=>r(e.id),className:`block w-full text-left px-3 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[`Move to `,e.name]},e.id))}),n&&L(`button`,{type:`button`,onClick:i,className:`block w-full text-left px-3 py-1.5 text-[11px] text-destructive hover:bg-destructive/10 border-t border-border`,children:[`Unpin `,e.toLowerCase()]}),t.length===0&&!n&&H(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle italic`,children:`Already auto · no other nodes online`})]})}function Ot({nodeId:e,refreshToken:t}){return L(`div`,{className:`space-y-6`,children:[H(pt,{refreshToken:t,nodeId:e}),L(`div`,{children:[H(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Cameras on this node`}),L(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`Checkboxes mark the roles currently running on `,e,`. Use the kebab to move a role to another node or unpin it; live KPIs come from the runner snapshot stream.`]})]}),H(vt,{mode:`agent`,nodeId:e,compact:!0})]})}I();function kt(e,t){let n=Math.max(0,t-e);return`${Math.floor(e/1e3)}s idle · ${Math.floor(n/1e3)}s left`}function At({nodeId:e,refreshToken:t}){let n=B(),r=ae({onSettled:()=>{n.invalidateQueries({queryKey:[`pipelineExecutor`,`listLoadedEngines`]})}}),{data:o}=M({nodeId:e}),s=i(`pipeline.engine-metrics-snapshot`,t=>t.nodeId===e)?.engines??o??null,c=s===null;Xe([`pipelineRunner`,`getLocalCameras`],[`pipeline.camera-assigned`,`pipeline.camera-unassigned`]);let{data:l}=a({nodeId:e}),{values:u}=g(`pipeline.camera-metrics-snapshot`,e=>e.deviceId,t=>t.nodeId===e),d=R(()=>u.filter(e=>e.metrics.phase===`active`).length,[u]),f=t=>{let n=l??[];n.length>0&&!window.confirm(`${n.length} camera(s) are dispatching through this engine. Killing it forces a respawn on the next frame. Continue?`)||r.mutate({nodeId:e,engine:t,force:n.length>0})};return L(`div`,{className:`space-y-6`,children:[L(`div`,{children:[H(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Inference engines on this node`}),L(`p`,{className:`text-[11px] text-foreground-subtle`,children:[(s??[]).length,` engine(s) resident in RAM. `,(l??[]).length,` `,`camera(s) attached, `,d,` actively dispatching frames. Refreshes every 5s.`]})]}),H(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:L(`table`,{className:`w-full text-xs min-w-[640px]`,children:[H(`thead`,{className:`bg-surface`,children:L(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[H(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Kind`}),H(`th`,{className:`text-left px-3 py-2 whitespace-nowrap`,children:`Runtime / Backend / Device`}),H(`th`,{className:`text-left px-3 py-2`,children:`Models`}),H(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Pool PID`}),H(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`Auto-kill`}),H(`th`,{className:`text-right px-3 py-2 whitespace-nowrap`,children:`In use`}),H(`th`,{className:`w-20`})]})}),L(`tbody`,{children:[c&&H(`tr`,{children:H(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`Loading…`})}),!c&&(s??[]).map(e=>{let t=e.kind===`warm-override`,n=e.kind===`device-pool`;return L(`tr`,{className:`border-t border-border ${t?`bg-amber-500/5`:n?`bg-primary/[0.05]`:``}`,children:[H(`td`,{className:`px-3 py-2`,children:L(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-medium ${t?`bg-amber-500/15 text-amber-400`:n?`bg-primary/15 text-primary`:`bg-success/15 text-success`}`,children:[H(t?it:n?ye:K,{className:`h-3 w-3`}),t?`warm`:n?`pool`:`runtime`]})}),H(`td`,{className:`px-3 py-2`,children:L(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-sky-400`,children:[H(ke,{className:`h-3 w-3`}),e.engine.runtime,`/`,e.engine.backend,e.engine.device?`/${e.engine.device}`:``,e.engine.format?` · ${e.engine.format}`:``]})}),H(`td`,{className:`px-3 py-2`,children:e.modelsLoaded.length===0?H(`span`,{className:`text-foreground-subtle text-[11px]`,children:`—`}):H(`div`,{className:`flex flex-wrap gap-1`,children:e.modelsLoaded.map(e=>H(`span`,{className:`inline-block rounded bg-surface px-1.5 py-0.5 text-[10px] font-mono text-foreground-subtle`,children:e},e))})}),H(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.poolPid??`—`}),H(`td`,{className:`px-3 py-2 text-right text-[11px]`,children:e.idleMs!==null&&e.idleTtlMs!==null?H(`span`,{className:`text-foreground-subtle`,children:kt(e.idleMs,e.idleTtlMs)}):H(`span`,{className:`text-foreground-subtle/50`,children:`never`})}),H(`td`,{className:`px-3 py-2 text-right text-foreground`,children:t?`—`:(l??[]).length}),H(`td`,{className:`px-3 py-2 text-right`,children:n?H(`span`,{className:`text-[11px] text-foreground-subtle`,children:`auto`}):L(`button`,{type:`button`,disabled:r.isPending,onClick:()=>f(e.engine),className:`inline-flex items-center gap-1 px-2 py-1 rounded border border-destructive/30 text-destructive text-[11px] hover:bg-destructive/10 disabled:opacity-50`,children:[H(Je,{className:`h-3 w-3`}),`Kill`]})})]},e.engineKey)}),!c&&(s??[]).length===0&&H(`tr`,{children:H(`td`,{colSpan:7,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:`No engines resident — the factory spins up on the first pipeline run.`})})]})]})}),L(`div`,{className:`text-[10px] text-foreground-subtle leading-relaxed`,children:[H(`strong`,{className:`text-foreground`,children:`runtime`}),`: main camera-serving engine; never auto-killed while cameras attached. `,H(`strong`,{className:`text-foreground`,children:`warm`}),`: benchmark/test override held in cache for fast re-use; auto-disposed after the idle TTL.`,` `,H(`strong`,{className:`text-foreground`,children:`pool`}),`: a per-device balanced inference pool (one per enabled accelerator, running concurrently); reaper-managed on its own idle TTL.`]}),r.isError&&L(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,r.error instanceof Error?r.error.message:`unknown`]})]})}I();var jt=new Set(ve);function Mt(e){return jt.has(e)}function Nt(e,t,n){return`${e}/${t}/${n}`}function Pt(e){return{coreml:`CoreML`,openvino:`OpenVINO`,onnx:`ONNX`}[e.format]??e.format.toUpperCase()}function Ft(e){return{coreml:`Apple Neural Engine / GPU — .mlpackage`,openvino:`Intel CPU / GPU / NPU — .xml`,onnx:`CPU, CUDA, Node.js — .onnx`}[e.format]??`.${e.format}`}function J(e){return e.format}function It(e,t){let n=0,r=0,i=0;for(let a of e)for(let e of a.addons)for(let a of e.models){let e=a.formats[t];e&&(n++,e.downloaded&&(r++,i+=e.sizeMB))}return{total:n,downloaded:r,downloadedSizeMB:i}}function Lt({addonId:e,model:t,format:n,isActive:r,progress:i,errorMsg:a,onDownload:o,onDelete:s}){let c=t.formats[n];return c?L(`div`,{className:`flex items-center gap-3 px-4 py-3 border-b border-border/50 last:border-b-0 hover:bg-surface-hover/30 transition-colors`,children:[H(`div`,{className:`h-2 w-2 rounded-full shrink-0 ${c.downloaded?`bg-success`:`bg-foreground-subtle/30`}`}),L(`div`,{className:`flex-1 min-w-0`,children:[L(`div`,{className:`flex items-center gap-2`,children:[H(`span`,{className:`text-sm font-medium text-foreground`,children:t.name}),L(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:[`(`,t.id,`)`]})]}),i&&i.progress>=0&&i.progress<100&&L(`div`,{className:`mt-1.5 flex items-center gap-2 max-w-xs`,children:[H(`div`,{className:`flex-1 h-1 bg-surface-hover rounded-full overflow-hidden`,children:H(`div`,{className:`bg-primary h-full rounded-full transition-all duration-300`,style:{width:`${i.progress}%`}})}),L(`span`,{className:`text-[9px] text-primary font-mono tabular-nums shrink-0`,children:[Math.round(i.progress),`%`]})]})]}),H(`span`,{className:`text-xs text-foreground-subtle tabular-nums shrink-0`,children:$e(c.sizeMB)}),a&&L(`span`,{className:`flex items-center gap-1 text-[10px] text-danger max-w-[160px] truncate shrink-0`,title:a,children:[H(He,{className:`h-3 w-3 shrink-0`}),a]}),c.downloaded?L(`button`,{onClick:s,disabled:r,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md border border-danger/30 text-danger hover:bg-danger/10 disabled:opacity-50 transition-colors shrink-0`,children:[r?H(G,{className:`h-3 w-3 animate-spin`}):H(Je,{className:`h-3 w-3`}),r?`Deleting...`:`Delete`]}):L(`button`,{onClick:o,disabled:r,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors shrink-0`,children:[r?H(G,{className:`h-3 w-3 animate-spin`}):H(Te,{className:`h-3 w-3`}),r?`Downloading...`:`Download`]})]}):null}function Rt({engines:e,activeEngine:t,viewEngine:n,onSelect:r}){let[i,a]=V(!1);return L(`div`,{className:`relative`,children:[L(`button`,{type:`button`,onClick:()=>a(!i),className:`flex items-center gap-2 rounded-lg border border-border bg-surface px-4 py-2.5 w-full text-left hover:bg-surface-hover transition-colors`,children:[H(K,{className:`h-4 w-4 text-primary shrink-0`}),L(`div`,{className:`flex-1 min-w-0`,children:[L(`div`,{className:`flex items-center gap-2`,children:[H(`span`,{className:`text-sm font-medium text-foreground`,children:Pt(n)}),J(n)===J(t)&&H(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),H(`div`,{className:`text-[10px] text-foreground-subtle`,children:Ft(n)})]}),H(ze,{className:`h-4 w-4 text-foreground-subtle transition-transform ${i?`rotate-180`:``}`})]}),i&&H(`div`,{className:`absolute top-full left-0 right-0 mt-1 rounded-lg border border-border bg-surface shadow-lg z-50 overflow-hidden`,children:e.map(e=>{let i=J(e)===J(n),o=J(e)===J(t);return L(`button`,{type:`button`,onClick:()=>{r(e),a(!1)},className:`flex items-center gap-3 px-4 py-2.5 w-full text-left transition-colors ${i?`bg-primary/5`:`hover:bg-surface-hover`}`,children:[H(K,{className:`h-4 w-4 shrink-0 ${i?`text-primary`:`text-foreground-subtle`}`}),L(`div`,{className:`flex-1`,children:[L(`div`,{className:`flex items-center gap-2`,children:[H(`span`,{className:`text-sm font-medium ${i?`text-primary`:`text-foreground`}`,children:Pt(e)}),o&&H(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-success/10 text-success font-medium`,children:`Active`})]}),H(`div`,{className:`text-[10px] text-foreground-subtle`,children:Ft(e)})]}),i&&H(Ve,{className:`h-4 w-4 text-primary shrink-0`})]},J(e))})})]})}function zt({embedded:t=!1,nodeId:n}={}){let r=B(),i=n??`hub`,[a,o]=V(null),[s,c]=V(new Set),[l,u]=V(new Map),[f,p]=V(new Map),[m,h]=V(``),{data:g=[]}=O({nodeId:i}),_=g.filter((e,t,n)=>n.findIndex(t=>t.format===e.format)===t),{data:v}=ne({nodeId:i}),b=v,{data:x,isLoading:S}=se({nodeId:i}),C=e(),w=d();y(`model.download.progress`,e=>{let t=e.data,n=typeof t.modelId==`string`?t.modelId:void 0,i=typeof t.progress==`number`?t.progress:void 0,a=typeof t.totalMB==`number`?t.totalMB:0;n===void 0||i===void 0||(u(e=>{let t=new Map(e);return i===100||i===-1?t.delete(n):t.set(n,{modelId:n,progress:i,totalMB:a}),t}),i===100&&r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]}))});let T=b??{runtime:`node`,backend:`cpu`,format:`onnx`},E=_.find(e=>e.format===a)??T,D=E.format,k=x?.slots??[],A=k.map(e=>({...e,addons:e.addons.map(e=>({...e,models:e.models.filter(e=>e.formats[D]!==void 0)})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0),j=It(A,D),M=pe(async(e,t,n)=>{if(!Mt(n))return;let a=Nt(e,t,n);c(e=>new Set([...e,a])),p(e=>{let t=new Map(e);return t.delete(a),t});try{await C.mutateAsync({addonId:e,modelId:t,format:n,nodeId:i}),r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){p(t=>new Map([...t,[a,e instanceof Error?e.message:`Download failed`]]))}finally{c(e=>{let t=new Set(e);return t.delete(a),t})}},[C,r,i]),N=pe(async(e,t,n)=>{if(!Mt(n))return;let a=Nt(e,t,n);c(e=>new Set([...e,a])),p(e=>{let t=new Map(e);return t.delete(a),t});try{await w.mutateAsync({addonId:e,modelId:t,format:n,nodeId:i}),r.invalidateQueries({queryKey:[[`pipelineExecutor`,`getSchema`]]})}catch(e){p(t=>new Map([...t,[a,e instanceof Error?e.message:`Delete failed`]]))}finally{c(e=>{let t=new Set(e);return t.delete(a),t})}},[w,r,i]),ee=pe(e=>{o(e.format)},[]),te=m.trim()?A.map(e=>({...e,addons:e.addons.map(e=>({...e,models:e.models.filter(t=>t.name.toLowerCase().includes(m.toLowerCase())||t.id.toLowerCase().includes(m.toLowerCase())||e.name.toLowerCase().includes(m.toLowerCase()))})).filter(e=>e.models.length>0)})).filter(e=>e.addons.length>0):A,P=L(z,{children:[S&&H(`div`,{className:`flex items-center justify-center py-16`,children:H(G,{className:`h-5 w-5 animate-spin text-foreground-subtle`})}),!S&&k.length===0&&L(`div`,{className:`flex flex-col items-center justify-center py-16 text-foreground-subtle`,children:[H(Ee,{className:`h-8 w-8 mb-3 opacity-30`}),H(`span`,{className:`text-sm`,children:`No pipeline steps available`}),H(`span`,{className:`text-xs mt-1`,children:`Configure the detection pipeline to see available models.`})]}),!S&&k.length>0&&L(z,{children:[H(Rt,{engines:_,activeEngine:T,viewEngine:E,onSelect:ee}),L(`div`,{className:`flex items-center gap-4 text-xs text-foreground-subtle`,children:[L(`span`,{children:[H(`span`,{className:`font-semibold text-foreground tabular-nums`,children:j.total}),H(`span`,{className:`ml-1`,children:`compatible models`})]}),H(`span`,{className:`text-border`,children:`|`}),L(`span`,{children:[H(`span`,{className:`font-semibold text-success tabular-nums`,children:j.downloaded}),H(`span`,{className:`ml-1`,children:`downloaded`})]}),H(`span`,{className:`text-border`,children:`|`}),L(`span`,{className:`tabular-nums`,children:[$e(j.downloadedSizeMB),H(`span`,{className:`ml-1`,children:`on disk`})]})]}),j.total>5&&L(`div`,{className:`relative`,children:[H(Pe,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),H(`input`,{type:`text`,value:m,onChange:e=>h(e.target.value),placeholder:`Search models...`,className:`w-full pl-9 pr-3 py-2 text-sm rounded-lg border border-border bg-surface text-foreground placeholder:text-foreground-subtle/50 focus:outline-none focus:ring-1 focus:ring-primary`})]}),te.map(e=>{let t=e.addons.reduce((e,t)=>e+t.models.length,0),n=e.addons.reduce((e,t)=>e+t.models.filter(e=>e.formats[D]?.downloaded).length,0);return L(`div`,{children:[L(`div`,{className:`flex items-center gap-2 mb-2`,children:[H(`h2`,{className:`text-sm font-semibold text-foreground`,children:e.label}),H(`div`,{className:`flex-1 h-px bg-border`}),L(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:[n,`/`,t]})]}),H(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:e.addons.map(e=>e.models.map(t=>{let n=Nt(e.id,t.id,D);return H(Lt,{addonId:e.id,model:t,format:D,isActive:s.has(n),progress:l.get(t.id),errorMsg:f.get(n),onDownload:()=>M(e.id,t.id,D),onDelete:()=>N(e.id,t.id,D)},`${e.id}/${t.id}`)}))})]},e.id)}),te.length===0&&H(`div`,{className:`text-center py-8 text-sm text-foreground-subtle`,children:m.trim()?L(z,{children:[`No models matching “`,m,`”`]}):L(z,{children:[`No models available for `,Pt(E),` format`]})})]})]});return t?H(`div`,{className:`space-y-4`,children:P}):H(Ye,{children:P})}function Bt({nodeId:e,refreshToken:t}){return H(zt,{embedded:!0,nodeId:e})}var Vt=`pipeline-runner`,Ht=200;function Ut({nodeId:e}){return L(`div`,{className:`flex flex-col gap-3`,children:[L(`div`,{children:[H(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Runner logs`}),L(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`pipeline-runner activity on `,e,` — camera attach/detach, engine phases and pipeline errors. Streaming live; the device chip on a line tells which camera it refers to.`]})]}),H(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:H(A,{agentId:e,addonId:Vt,limit:Ht,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}I(),I();function Wt({nodeId:e,title:t}){let{data:n}=xe(),{data:r}=j(void 0),i=R(()=>{let e=new Map;for(let t of n??[])e.set(t.id,t.name);return e},[n]),a=R(()=>{if(!e)return null;let t=new Set;for(let n of r??[])n.agentNodeId===e&&t.add(n.deviceId);return t},[e,r]),[o,s]=V(new Map);y(`pipeline.camera-metrics-snapshot`,t=>{let n=t.data;typeof n.deviceId==`number`&&(e&&n.nodeId!==e||s(e=>{let t=new Map(e);return t.set(n.deviceId,n),t}))}),U(()=>{if(o.size===0)return;let e=setInterval(()=>{s(e=>{let t=Date.now()-1e4,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},5e3);return()=>clearInterval(e)},[o.size]);let c=R(()=>{let e=[];for(let t of o.values())a&&!a.has(t.deviceId)||e.push(t);return e.sort((e,t)=>e.deviceId-t.deviceId),e},[o,a]);return c.length===0?L(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2 text-[11px] text-foreground-subtle italic`,children:[t??`Cameras`,`: no live snapshots yet`]}):L(`div`,{className:`rounded-md border border-border bg-surface px-3 py-2`,children:[L(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[H(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:t??`Cameras`}),H(`span`,{className:`text-[10px] text-foreground-subtle`,children:c.length})]}),H(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map(e=>{let t=i.get(e.deviceId)??`#${e.deviceId}`,n=h(e.metrics.phase);return L(`div`,{title:`${t} · ${n.label} · ${e.metrics.actualFps.toFixed(1)} fps · ${e.metrics.avgInferenceTimeMs.toFixed(0)}ms infer · q=${e.metrics.queueDepth}`,className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] ${n.badgeClass}`,children:[H(S,{phase:e.metrics.phase,className:`h-2.5 w-2.5`}),H(`span`,{className:`font-medium text-foreground/90 max-w-[220px] truncate`,children:t}),H(`span`,{className:`font-mono tabular-nums`,children:e.metrics.actualFps.toFixed(1)}),H(`span`,{className:`opacity-60`,children:`fps`})]},e.deviceId)})})]})}I();function Gt(e,t){if(!e)return null;for(let n of e.slots)for(let e of n.addons)if(e.id===t)return e;return null}function Kt(e){if(!e)return null;let t=e.modelId!==void 0&&e.modelId!==``?e.modelId:void 0,n=e.settings&&Object.keys(e.settings).length>0?e.settings:void 0;return t===void 0&&n===void 0?null:{...t===void 0?{}:{modelId:t},...n===void 0?{}:{settings:n}}}function qt({nodeId:e,refreshToken:t}){let n=B(),[r,i]=V(null),[a,s]=V(null),[c,l]=V(null),u=P({nodeId:e},{refetchOnMount:`always`}),d=se({nodeId:e},{refetchOnMount:`always`}),f=u.data?.devices??[],p=m({onSuccess:()=>{n.invalidateQueries({queryKey:[`pipelineOrchestrator`,`getNodeInferenceDevices`]})}}),h=R(()=>d.data?x(d.data):[],[d.data]),g=R(()=>f.map(t=>({agentNodeId:e,engineLabel:t.format,deviceKey:t.key,deviceLabel:be(t).label})),[f,e]),_=e=>f.find(t=>t.key===e)??null,v=e=>{let t=Gt(d.data??null,e)?.enabledByDefault??!0;return{kind:`gate`,effectiveOn:t,defaultOn:t,explicit:!1}},y=(e,t)=>{let n=v(e),r=n.kind===`gate`?n.effectiveOn:!1,i=Gt(d.data??null,e),a=t.deviceKey===void 0?null:_(t.deviceKey),o=a?.format;return i?.models.some(e=>o!==void 0&&!!e.formats[o])??!1?{kind:`enabled`,modelId:a?.steps?.[e]?.modelId??a?.defaultModelId??`Auto`}:r?{kind:`skip`}:{kind:`na`}},S=r&&d.data?Gt(d.data,r.addonId):null,C=r?_(r.deviceKey):null,w=C?.format??`coreml`,T=()=>{i(null),s(null)},E=(e,t)=>{if(t.deviceKey===void 0)return;let n=_(t.deviceKey)?.steps?.[e];i({addonId:e,deviceKey:t.deviceKey}),s({enabled:!0,...n?.modelId===void 0?{}:{modelId:n.modelId},settings:n?.settings??{}})},D=()=>{if(!r)return;let t=Kt(a),n={};for(let e of f){if(!e.enabled&&e.key!==r.deviceKey)continue;let i={...e.steps??{}};e.key===r.deviceKey&&(t?i[r.addonId]=t:delete i[r.addonId]);let a=Object.keys(i).length>0;n[e.key]={enabled:!0,weight:Math.max(1,e.weight),...e.maxSessions!=null&&e.maxSessions>0?{maxSessions:e.maxSessions}:{},...a?{steps:i}:{}}}p.mutate({agentNodeId:e,inferenceDevices:n},{onSuccess:T})};if(u.isLoading||d.isLoading)return H(`div`,{className:`text-xs text-foreground-subtle animate-pulse p-4`,children:`Loading pipeline…`});if(f.length===0)return H(`div`,{className:`rounded-md 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.`});if(!d.data)return H(`div`,{className:`text-xs text-foreground-subtle p-4`,children:`Catalog unavailable.`});let O=r!==null&&S!==null&&C!==null;return L(`div`,{className:`relative h-full w-full space-y-3`,children:[L(`div`,{className:`rounded-md border border-border bg-muted/20 px-3 py-2 text-[11px] leading-relaxed text-foreground-subtle`,children:[`Each column is one of this node's inference accelerators. A cell shows the`,` `,H(`span`,{className:`font-medium text-foreground`,children:`base model`}),` every camera landing on that accelerator runs; click to change it. Whether a camera runs a step is set per-camera on that camera's Detection pipeline tab — there is no gate here.`]}),H(`div`,{className:O?`md:pr-[360px]`:``,children:h.length>0?H(o,{tree:h,agents:g,gateFor:v,getCellState:y,onCellClick:E,selectedCell:r?{addonId:r.addonId,agentNodeId:e,deviceKey:r.deviceKey}:null,onSetGate:()=>{},fallbackNodeId:c,onFallbackNodeChange:l,hideGate:!0}):H(`div`,{className:`text-xs text-foreground-subtle`,children:`Catalog empty.`})}),H(b,{open:O,onClose:T,title:S?.name??``,subtitle:r&&C?`${e} · ${be(C).label} · ${C.format}`:``,footer:L(z,{children:[H(`div`,{className:`flex-1`}),H(`button`,{type:`button`,className:`px-3 py-1 text-xs border border-border rounded bg-surface hover:bg-muted`,onClick:T,children:`Cancel`}),H(`button`,{type:`button`,disabled:!r||!a||p.isPending,className:`px-3 py-1 text-xs bg-primary text-primary-foreground rounded disabled:opacity-50`,onClick:D,children:p.isPending?`Saving…`:`Save`})]}),children:S&&r&&a?H(ie,{mode:`agent`,addon:S,agentDefault:a,agentNodeId:e,engineFormat:w,onChangeAgentConfig:s}):H(`div`,{className:`rounded-md border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-300`,children:`This accelerator is no longer reported by the node, so there is nothing to provision here.`})})]})}I();var Jt=[`pipeline-orchestrator`],Yt=[`decoder`],Xt=!1;function Zt({nodeId:e,refreshToken:t}){let n=s(),[r,i]=V(null),[a,o]=V(null),c=(v(void 0).data??[]).find(t=>t.id===e),l=c?.name??e,u=c?.isOnline??!1,d=de({onSuccess:e=>{o(e.effectiveModelId===null?`Reset done — model config cleared (node offline: effective model resolves on reconnect)`:`Reset done — effective detection model: ${e.effectiveModelId} (Auto)`)}}),f=async()=>{await n({title:`Reset ${l} to hardware-aware defaults?`,message:`This clears every per-device model default on this node (back to the format default) and every per-camera step override scoped to it. Existing per-camera customisations on this node are lost.`,confirmLabel:`Reset`,variant:`danger`})&&(o(null),d.mutate({agentNodeId:e}))};return L(`div`,{className:`relative h-full w-full space-y-3`,children:[L(`div`,{className:`flex items-center justify-end gap-2 text-xs`,children:[a&&H(`span`,{className:`text-emerald-400`,children:a}),d.isError&&H(`span`,{className:`text-red-400`,children:d.error instanceof Error?d.error.message:`Reset failed`}),H(`button`,{type:`button`,onClick:()=>{f()},disabled:d.isPending,className:`rounded border border-amber-500/40 bg-surface px-2 py-0.5 text-amber-300 hover:bg-surface-hover disabled:opacity-50`,title:`Clear this node's per-device model defaults + per-camera overrides scoped to this node`,children:d.isPending?`Resetting…`:`Reset to default`})]}),H(Wt,{nodeId:e}),H(et,{nodeId:e,addonIds:Jt,level:`global`,sectionIds:Yt}),Xt,Xt,L(`div`,{children:[H(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices — default model per accelerator`}),H(we,{nodeId:e,nodeName:l,isOnline:u})]}),L(`div`,{children:[H(`h3`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection steps — model per accelerator`}),H(qt,{nodeId:e,refreshToken:t})]})]})}var Qt=[`detection-pipeline`,`audio-analyzer`,`pipeline-runner`],$t=`decoder-nodeav`;function en({nodeId:e,refreshToken:t}){let{data:n}=v(void 0),r=n?.find(t=>t.id===e)?.addons.find(e=>e.capabilities.includes(`decoder`))?.id??$t,i=[...Qt,r];return L(`div`,{className:`flex flex-col h-full`,children:[H(ft,{nodeId:e,refreshToken:t}),H(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-6`,children:H(et,{nodeId:e,addonIds:i,level:`global`,extraTabs:[{id:`assignments`,label:`Assignments`,order:-10,content:H(Ot,{nodeId:e,refreshToken:t})},{id:`tree`,label:`Pipeline`,order:39,content:H(Zt,{nodeId:e,refreshToken:t})},{id:`engines`,label:`Warm instances`,order:180,content:H(At,{nodeId:e,refreshToken:t})},{id:`models`,label:`Models`,order:200,content:H(Bt,{nodeId:e,refreshToken:t})},{id:`logs`,label:`Logs`,order:300,content:H(Ut,{nodeId:e})}]})})]})}var tn=`pipeline-orchestrator`,nn=`recorder`,rn=`recordingNodeId`,an=[`ingestNode`,`recordingNode`,`audioNode`,`motionNode`],on=[{key:`detect`,label:`Detect`,hint:`Runs the detection pipeline (decode + inference) for assigned cameras`}];function sn(e,t){for(let n of e?.sections??[])for(let e of n.fields??[])if(e.key===t)return e.value}function cn(e,t){for(let[n,r]of Object.entries(e??{}))if(n===t)return r}function ln(e,t,n){let r=sn(e,t);return typeof r==`string`&&r.length>0?r:n}function un(e,t,n){let r=sn(e,t);return typeof r==`number`&&Number.isFinite(r)?r:n}function dn(e,t){let n=cn(e,t);return typeof n==`number`&&Number.isFinite(n)?n:null}function fn(e,t){let n=cn(e,t);return typeof n==`string`&&n.length>0?n:null}function pn(e){return e===`ingestNode`?`Ingest`:e===`recordingNode`?`Recording`:e===`audioNode`?`Audio`:`Motion Node`}function mn(e){return e===`ingestNode`?`Node that terminates default camera ingest`:e===`recordingNode`?`Node that owns the recorder (recording-node)`:e===`audioNode`?`Node that runs singleton audio work`:`Runs software (analyzer) motion-watch. Onboard cameras are unaffected.`}function hn(e,t){switch(t){case`detect`:return e.pipeline}}function gn(e){return e instanceof Error?e.message:`Failed to save`}function _n(e){e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listAgentSettings`]]}),e.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAgentSettings`]]}),e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}function vn({capability:e,label:t,hint:n,nodeId:r,active:i,pending:a,layout:o,onToggle:s}){let c=i?`border-success/30 bg-success/15 text-success hover:bg-success/25`:`border-border bg-surface-hover text-foreground-subtle hover:bg-surface hover:text-foreground`,l=o===`card`?`w-full justify-center px-3 py-2 text-xs`:`px-2.5 py-1 text-[11px]`,u=i?W:Ce;return L(`button`,{type:`button`,role:`switch`,"aria-checked":i,"aria-label":`${t} capability for ${r}`,title:`${t} — ${n}`,disabled:a,onClick:()=>s(e,!i),className:`inline-flex items-center gap-1.5 rounded-full border font-medium transition-colors disabled:opacity-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/40 ${c} ${l}`,children:[H(u,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":`true`}),H(`span`,{children:t})]})}function yn({node:e,emphasis:t=!1}){let n=e.isHub?Fe:K;return L(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[H(`span`,{className:`h-2 w-2 shrink-0 rounded-full ${e.isOnline?`bg-success`:`bg-danger`}`,"aria-hidden":`true`}),H(n,{className:`h-4 w-4 shrink-0 text-foreground-subtle`,"aria-hidden":`true`}),L(`div`,{className:`min-w-0`,children:[L(`div`,{className:`flex items-center gap-1.5 ${t?`text-sm`:`text-xs`} font-semibold text-foreground`,children:[H(`span`,{className:`truncate`,children:e.name}),e.isHub&&H(F,{variant:`info`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`hub`}),!e.isOnline&&H(F,{variant:`danger`,className:`px-1.5 py-0 text-[9px] uppercase tracking-wider`,children:`offline`})]}),H(`div`,{className:`font-mono text-[10px] text-foreground-subtle truncate`,children:e.id})]})]})}I();function bn({nodeId:e,value:t,detectedHosts:n,status:r,errorMessage:i,onCommit:a}){let[o,s]=V(t??``);U(()=>{s(t??``)},[t]);let c=n[0],l=c===void 0?`auto-detect`:`auto: ${c}`,u=r===`pending`,d=o.trim(),f=d!==(t??``),p=f&&!u,m=()=>{p&&a(e,d.length>0?d:null)};return L(`div`,{className:`flex items-center gap-1.5`,children:[H(`input`,{"aria-label":`Reachable host for ${e}`,type:`text`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:l,value:o,disabled:u,onChange:e=>s(e.target.value),onBlur:m,onKeyDown:e=>{e.key===`Enter`&&m(),e.key===`Escape`&&s(t??``)},className:`w-40 rounded-md border border-border bg-background px-2.5 py-1.5 text-sm text-foreground placeholder:text-foreground-subtle focus:border-primary focus:outline-none disabled:opacity-50`}),L(`button`,{type:`button`,onClick:m,disabled:!p,"aria-label":`Save reachable host for ${e}`,title:`Save reachable host`,className:`inline-flex shrink-0 items-center gap-1 rounded-md px-2 py-1.5 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-40 disabled:cursor-not-allowed`,children:[u?H(G,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):H(W,{className:`h-3 w-3`,"aria-hidden":`true`}),`Save`]}),!f&&!u&&r===`success`&&H(W,{className:`h-3.5 w-3.5 shrink-0 text-emerald-400`,"aria-label":`Saved`,role:`img`}),r===`error`&&H(`span`,{title:i??`Failed to save reachable host`,children:H(He,{className:`h-3.5 w-3.5 shrink-0 text-red-400`,"aria-label":i??`Failed to save reachable host`,role:`img`})})]})}function xn({label:e,children:t}){return L(`div`,{className:`flex items-center justify-between gap-3`,children:[H(`span`,{className:`text-[11px] font-medium uppercase tracking-wide text-foreground-subtle`,children:e}),t]})}function Sn({node:e,actions:t}){return L(`div`,{className:`rounded-xl border border-border bg-background p-4 space-y-4 ${e.isOnline?``:`opacity-60`}`,children:[H(yn,{node:e,emphasis:!0}),H(`div`,{className:`grid grid-cols-2 gap-2`,children:on.map(n=>H(vn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:hn(e.effective,n.key),pending:t.capabilityPending,layout:`card`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)},n.key))}),H(`div`,{className:`space-y-3 border-t border-border pt-3`,children:H(xn,{label:`Reachable host`,children:H(bn,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})})})]})}function Cn(){return L(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1.5 text-[10px] text-foreground-subtle`,children:[L(`span`,{className:`inline-flex items-center gap-1.5`,children:[H(`span`,{className:`h-2.5 w-2.5 rounded-full border border-success/30 bg-success/15`}),`Active capability`]}),L(`span`,{className:`inline-flex items-center gap-1.5`,children:[H(`span`,{className:`h-2.5 w-2.5 rounded-full border border-border bg-surface-hover`}),`Idle`]}),L(`span`,{className:`inline-flex items-center gap-1.5`,children:[H(`span`,{className:`h-2 w-2 rounded-full bg-success`}),`Node online`]}),L(`span`,{className:`inline-flex items-center gap-1.5`,children:[H(`span`,{className:`h-2 w-2 rounded-full bg-danger`}),`Node offline`]})]})}function wn({nodes:e,actions:t}){return H(`div`,{className:`overflow-x-auto rounded-lg border border-border`,children:L(`table`,{className:`w-full min-w-[720px] border-collapse text-sm`,children:[H(`thead`,{children:L(`tr`,{className:`border-b border-border bg-background text-[10px] uppercase tracking-wider text-foreground-subtle`,children:[H(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Node`}),on.map(e=>H(`th`,{className:`px-3 py-3 text-center font-semibold`,children:e.label},e.key)),H(`th`,{className:`px-4 py-3 text-left font-semibold`,children:`Reachable host`})]})}),H(`tbody`,{children:e.map(e=>L(`tr`,{className:`border-b border-border last:border-b-0 transition-colors hover:bg-surface-hover/40 ${e.isOnline?``:`opacity-60`}`,children:[H(`td`,{className:`px-4 py-3 align-middle`,children:H(yn,{node:e})}),on.map(n=>H(`td`,{className:`px-3 py-3 text-center align-middle`,children:H(vn,{capability:n.key,label:n.label,hint:n.hint,nodeId:e.id,active:hn(e.effective,n.key),pending:t.capabilityPending,layout:`cell`,onToggle:(n,r)=>t.onToggleCapability(e.id,n,r)})},n.key)),H(`td`,{className:`px-4 py-3 align-middle`,children:H(bn,{nodeId:e.id,value:e.reachableHost,detectedHosts:e.detectedHosts,status:t.reachableHostStatus(e.id),errorMessage:t.reachableHostErrorMessage(e.id),onCommit:t.onCommitReachableHost})})]},e.id))})]})})}function Tn({role:e,value:t,options:n,pending:r,onChange:i}){return L(`label`,{className:`flex flex-col gap-1.5 rounded-lg border border-border bg-background p-3`,children:[H(`span`,{className:`text-xs font-semibold text-foreground`,children:pn(e)}),H(`select`,{value:t,disabled:r,onChange:t=>i(e,t.target.value),className:`rounded-md border border-border bg-surface px-2.5 py-1.5 text-sm text-foreground focus:border-primary focus:outline-none disabled:opacity-50`,children:n.map(e=>H(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),H(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:mn(e)})]})}function En({roleValues:e,options:t,pending:n,lowFpsEnabled:r,fpsMinThreshold:i,onRoleChange:a,onLowFpsToggle:o}){return L(`div`,{className:`grid gap-3 @lg/clustertab:grid-cols-2 @3xl/clustertab:grid-cols-4`,children:[an.map(r=>H(Tn,{role:r,value:e[r],options:t,pending:n,onChange:a},r)),L(`label`,{className:`flex items-start gap-2.5 rounded-lg border border-border bg-background p-3 text-sm text-foreground`,children:[H(`input`,{type:`checkbox`,checked:r,disabled:n,onChange:e=>o(e.target.checked),className:`mt-0.5 h-4 w-4 shrink-0 accent-primary`}),L(`span`,{className:`flex flex-col gap-0.5`,children:[H(`span`,{className:`text-xs font-semibold`,children:`Low-fps relocate/shed`}),L(`span`,{className:`text-[10px] leading-tight text-foreground-subtle`,children:[`fpsMinThreshold `,r?`${i} fps`:`disabled`]})]})]})]})}I();function Dn(){let e=B(),{nodes:r}=_(),i=le(void 0),a=ce({addonId:tn}),o=ce({addonId:nn}),s=()=>_n(e),c=t({onSuccess:s}),l=ue(),u=n({onSuccess:s}),d=k({onSuccess:s}),[f,p]=V(!1),m=R(()=>{let e=new Map;for(let t of i.data??[])e.set(t.nodeId,t.settings);return e},[i.data]),h=R(()=>r.map(e=>{let t=m.get(e.id),n=lt(t,e.isHub),r=dn(t,`detectWeight`);return{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,settings:t,effective:n,weight:r??1,maxCameras:dn(t,`maxCameras`),reachableHost:fn(t,`reachableHost`),detectedHosts:e.localIps}}),[r,m]),g=h.filter(e=>e.effective.pipeline),v={ingestNode:ln(a.data,`ingestNode`,`hub`),recordingNode:ln(o.data,rn,`hub`),audioNode:ln(a.data,`audioNode`,`hub`),motionNode:ln(a.data,`motionNode`,`hub`)},y=R(()=>{let e=r.filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,...an.map(e=>v[e]),...e])].filter(e=>e.length>0)},[r,v]),b=un(a.data,`fpsMinThreshold`,0),x=b>0,S=i.isLoading||a.isLoading||o.isLoading,C=(e,t,n)=>{c.mutate({agentNodeId:e,[t]:n})},w=(e,t)=>{if(e===`recordingNode`){d.mutate({addonId:nn,patch:{[rn]:t}});return}d.mutate({addonId:tn,patch:{[e]:t}})},T=e=>{d.mutate({addonId:tn,patch:{fpsMinThreshold:e?Math.max(1,b):0}})},E=e=>u.variables?.agentNodeId===e?u.isPending?`pending`:u.isError?`error`:u.isSuccess?`success`:`idle`:`idle`,D=e=>E(e)===`error`?gn(u.error):null,O=async e=>{p(!0);try{for(let t of e)await l.mutateAsync({agentNodeId:t.nodeId,detectWeight:t.weight})}finally{p(!1),s()}},A={capabilityPending:c.isPending,onToggleCapability:C,onCommitReachableHost:(e,t)=>u.mutate({agentNodeId:e,reachableHost:t}),reachableHostStatus:E,reachableHostErrorMessage:D};return L(`section`,{className:`rounded-xl border border-border bg-surface p-5 @3xl/clustertab:p-6 space-y-6`,children:[L(`header`,{className:`flex items-start justify-between gap-4`,children:[L(`div`,{className:`space-y-1`,children:[H(`h3`,{className:`text-base font-semibold text-foreground`,children:`Pipeline placement`}),H(`p`,{className:`max-w-prose text-xs leading-relaxed text-foreground-subtle`,children:`Toggle which node runs each pipeline capability, distribute detection weight across detect-capable nodes, and choose the singleton cluster roles.`})]}),S&&H(G,{className:`h-5 w-5 shrink-0 animate-spin text-foreground-subtle`,"aria-label":`Loading`})]}),L(`div`,{className:`space-y-3`,children:[H(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Singleton cluster roles`}),H(En,{roleValues:v,options:y,pending:d.isPending,lowFpsEnabled:x,fpsMinThreshold:b,onRoleChange:w,onLowFpsToggle:T})]}),L(`div`,{className:`space-y-3`,children:[L(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[H(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Per-node capabilities`}),H(Cn,{})]}),h.length===0?H(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No cluster nodes reporting yet.`}):L(z,{children:[H(`div`,{className:`grid gap-4 @xl/clustertab:grid-cols-2 @3xl/clustertab:hidden`,children:h.map(e=>H(Sn,{node:e,actions:A},e.id))}),H(`div`,{className:`hidden @3xl/clustertab:block`,children:H(wn,{nodes:h,actions:A})})]})]}),L(`div`,{className:`space-y-3`,children:[H(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Detection weight`}),H(Se,{nodes:g,pending:f,onCommitWeights:e=>void O(e)})]}),L(`div`,{className:`space-y-3`,children:[H(`h4`,{className:`text-xs font-semibold uppercase tracking-wide text-foreground-subtle`,children:`Inference devices`}),g.length===0?H(`p`,{className:`rounded-lg border border-dashed border-border bg-background px-4 py-6 text-center text-xs text-foreground-subtle`,children:`No detect-capable nodes — enable detection on a node above to configure its accelerators.`}):H(`div`,{className:`space-y-2`,children:g.map(e=>H(we,{nodeId:e.id,nodeName:e.name,isOnline:e.isOnline},e.id))})]})]})}I();var On=!1;function kn({refreshToken:e}){let t=B(),{data:n}=v(void 0);R(()=>Qe(n??[]),[n]);let r=T({onSuccess:()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]}),t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getAudioAssignments`]]})}});return L(`div`,{className:`space-y-6`,children:[H(Wt,{title:`Cluster cameras`}),H(pt,{refreshToken:e}),H(Dn,{}),On,L(`div`,{className:`flex flex-col gap-3 @md/clustertab:flex-row @md/clustertab:items-center @md/clustertab:justify-between`,children:[L(`div`,{className:`min-w-0`,children:[H(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Placement matrix`}),H(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Pipeline · audio assignments per camera (decode always runs co-located with the pipeline). Click the kebab to pin / unpin / move a role; expand the chevron for the per-camera broker drill-down.`})]}),L(`button`,{type:`button`,onClick:()=>r.mutate(void 0),disabled:r.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-white hover:bg-primary/90 disabled:opacity-50 shrink-0 self-start @md/clustertab:self-auto whitespace-nowrap`,children:[H(ke,{className:`h-3.5 w-3.5`}),r.isPending?`Rebalancing…`:`Rebalance pipelines`]})]}),H(vt,{mode:`cluster`})]})}var An=[`pipeline-orchestrator`];function jn({refreshToken:e}){return H(`div`,{className:`space-y-4 max-w-3xl`,children:H(et,{nodeId:`hub`,addonIds:An,level:`global`,title:`Cluster settings`,description:`Cluster-wide orchestration knobs: enabled nodes, load balancer thresholds, and failover policy. Per-camera pipelines live in Device Overrides; live cluster load is on the Assignments tab.`})})}I();function Mn({refreshToken:e}){let t=B(),{data:n,isLoading:r}=fe(),[i,a]=V(null),[o,s]=V(``),[c,l]=V(``),d=()=>{t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`listTemplates`]]})},f=u({onSuccess:()=>{a(null),d()}}),p=oe({onSuccess:d}),m=e=>{a(e.id),s(e.name),l(e.description??``)},h=()=>{a(null),s(``),l(``)},g=()=>{if(!i)return;let e=c.trim();f.mutate({id:i,name:o.trim()||`Untitled`,...e?{description:e}:{}})};if(r)return H(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading templates…`});let _=[...n??[]].toSorted((e,t)=>e.name.localeCompare(t.name));return H(`div`,{className:`space-y-6 max-w-4xl`,children:L(`section`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:[L(`div`,{className:`border-b border-border px-4 py-3 flex items-center justify-between`,children:[L(`div`,{children:[H(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Templates`}),H(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:`Curated pipeline presets operators can apply to any camera. Apply-time is a copy — future edits to a template don't retroactively change cameras that were seeded from it. Save a template from the device Pipeline tab.`})]}),L(`div`,{className:`text-[11px] text-foreground-subtle`,children:[_.length,` template`,_.length===1?``:`s`]})]}),_.length===0?L(`div`,{className:`px-4 py-8 text-xs text-foreground-subtle flex flex-col items-center gap-2`,children:[H(je,{className:`h-6 w-6 opacity-40`}),H(`div`,{children:`No templates yet. Create one from a device Pipeline tab ("Save as template").`})]}):H(`ul`,{className:`divide-y divide-border`,children:_.map(e=>{let t=i===e.id;return H(`li`,{className:`px-4 py-3 text-xs`,children:L(`div`,{className:`flex items-start gap-3`,children:[H(`div`,{className:`flex-1 min-w-0`,children:t?L(`div`,{className:`space-y-2`,children:[H(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-xs text-foreground focus:outline-none focus:border-primary`,value:o,onChange:e=>s(e.target.value),placeholder:`Template name`,autoFocus:!0}),H(`input`,{className:`w-full rounded border border-border bg-surface-hover px-2 py-1 text-[11px] text-foreground focus:outline-none focus:border-primary`,value:c,onChange:e=>l(e.target.value),placeholder:`Description (optional)`})]}):L(z,{children:[H(`div`,{className:`font-medium text-foreground`,children:e.name}),e.description&&H(`div`,{className:`text-foreground-subtle mt-0.5`,children:e.description}),L(`div`,{className:`mt-1 font-mono text-[10px] text-foreground-subtle`,children:[e.config.steps.length,` step(s)`,e.config.audio?.enabled?` · audio`:``,L(`span`,{className:`ml-2`,children:[`updated `,new Date(e.updatedAt).toLocaleString()]})]})]})}),H(`div`,{className:`flex items-center gap-1 shrink-0`,children:t?L(z,{children:[L(`button`,{type:`button`,onClick:g,disabled:f.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] font-medium bg-primary text-white hover:bg-primary/90 disabled:opacity-50`,children:[H(W,{className:`h-3 w-3`}),`Save`]}),L(`button`,{type:`button`,onClick:h,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:bg-surface-hover`,children:[H(Ke,{className:`h-3 w-3`}),`Cancel`]})]}):L(z,{children:[H(`button`,{type:`button`,onClick:()=>m(e),title:`Rename`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover`,children:H(Ae,{className:`h-3 w-3`})}),H(`button`,{type:`button`,onClick:()=>{confirm(`Delete template "${e.name}"?`)&&p.mutate({id:e.id})},disabled:p.isPending,title:`Delete`,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[11px] text-foreground-subtle hover:text-red-400 hover:bg-surface-hover disabled:opacity-50`,children:H(Je,{className:`h-3 w-3`})})]})})]})},e.id)})})]})})}I();var Nn=`pipeline-analytics`;function Pn(e){for(let t of e?.sections??[])for(let e of t.fields??[])if(e.key===`postProcessingNodeId`&&typeof e.value==`string`)return e.value;return`hub`}function Fn(){let e=B(),{data:t}=v(void 0),{data:n,isLoading:r}=ce({addonId:Nn}),i=Pn(n),a=k({onSuccess:()=>{e.invalidateQueries({queryKey:[[`addonSettings`,`getGlobalSettings`]]})}}),o=R(()=>{let e=(t??[]).filter(e=>e.isOnline).map(e=>e.id);return[...new Set([`hub`,i,...e])].filter(Boolean)},[t,i]);return L(`div`,{className:`flex flex-col gap-6`,children:[L(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[H(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Post-processing node`}),H(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:`The single node that runs detection post-processing (events, media, audio & motion). Every other node stays inert — no multi-node balancing. Takes effect on addon restart.`}),L(`div`,{className:`mt-3 flex items-center gap-2`,children:[r?H(G,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):H(`select`,{value:i,onChange:e=>{e.target.value!==i&&a.mutate({addonId:Nn,patch:{postProcessingNodeId:e.target.value}})},disabled:a.isPending,className:`rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground`,children:o.map(e=>H(`option`,{value:e,children:e===`hub`?`hub (default)`:e},e))}),a.isPending&&H(G,{className:`h-4 w-4 animate-spin text-primary`})]})]}),L(`section`,{className:`rounded-md border border-border bg-surface p-4`,children:[H(`h3`,{className:`mb-1 text-sm font-semibold text-foreground`,children:`Events folder`}),H(`p`,{className:`mb-3 text-[11px] text-foreground-subtle`,children:`Where event crops / full frames are stored. A single folder — no collection / equal-splitting.`}),H(tt,{types:[`eventMedia`]})]})]})}var In=`pipeline-orchestrator`,Ln=200;function Rn(){return L(`div`,{className:`flex flex-col gap-3`,children:[L(`div`,{children:[H(`h3`,{className:`text-sm font-semibold text-foreground mb-1`,children:`Orchestrator logs`}),H(`p`,{className:`text-[11px] text-foreground-subtle`,children:`Dispatch decisions, balancer moves and failover events from the pipeline orchestrator. Streaming live; the device chip on a line tells which camera it refers to.`})]}),H(`div`,{className:`rounded-lg border border-border bg-surface overflow-hidden`,children:H(A,{addonId:In,limit:Ln,maxHeight:`max-h-[calc(100vh-360px)]`,showScope:!0,showDeviceChip:!0,showFilters:!1})})]})}I();var zn=[{id:`assignments`,label:`Assignments`},{id:`events`,label:`Events`},{id:`recording`,label:`Recording`},{id:`settings`,label:`Settings`},{id:`templates`,label:`Templates`},{id:`logs`,label:`Logs`}];function Bn({refreshToken:e}){let[t,n]=V(`assignments`);return L(`div`,{className:`flex flex-col h-full`,children:[L(`div`,{className:`px-4 sm:px-6 py-4 border-b border-border`,children:[H(`h2`,{className:`text-base font-semibold text-foreground`,children:`Cluster Orchestration`}),H(`div`,{className:`text-[11px] text-foreground-subtle mt-1`,children:`Assignments with live load, cluster-wide settings, pipeline template library, per-camera pipeline overrides.`})]}),H(`div`,{className:`flex items-center gap-1 px-4 sm:px-6 border-b border-border overflow-x-auto`,children:zn.map(e=>H(`button`,{type:`button`,onClick:()=>n(e.id),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${t===e.id?`border-primary text-primary`:`border-transparent text-foreground-subtle hover:text-foreground`}`,children:e.label},e.id))}),L(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-4 sm:p-6 @container/clustertab`,children:[t===`assignments`&&H(kn,{refreshToken:e}),t===`events`&&H(Fn,{}),t===`recording`&&H(nt,{}),t===`settings`&&H(jn,{refreshToken:e}),t===`templates`&&H(Mn,{refreshToken:e}),t===`logs`&&H(Rn,{})]})]})}function Vn(e){let t=[],n=[],{assignment:r,detection:i,decoder:a,broker:o}=e;i!==null&&i.provisioning.state===`failed`&&t.push({code:`provisioning-failed`,severity:`error`,message:i.provisioning.error!==void 0&&i.provisioning.error.length>0?`Engine provisioning failed: ${i.provisioning.error}`:`Engine provisioning failed on the detection node`}),i!==null&&i.phase===`active`&&i.actualFps===0&&t.push({code:`detection-black-hole`,severity:`error`,message:`Detection phase is ACTIVE but 0 fps are being processed — frames are not reaching the detector (cross-node black-hole signature)`}),i!==null&&i.phase===`active`&&a!==null&&a.shm.framesWritten===0&&t.push({code:`decoder-black-hole`,severity:`error`,message:`Decoder on ${a.nodeId} has written 0 frames to the shared-memory plane while detection is active — the decode path is stalled`}),r.detectionNodeId===null&&i===null&&n.push({code:`unassigned`,severity:`warning`,message:`Not placed on any detection node — no pipeline is running for this camera`});for(let e of o?.profiles??[])e.status===`streaming`&&e.inFps===0&&n.push({code:`broker-stalled`,severity:`warning`,message:`Broker profile "${e.profile}" reports streaming but 0 in-fps — the source pull may be stalled`});return[...t,...n]}function Hn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Y(e){return typeof e==`string`&&e.length>0?e:null}function Un(e){return typeof e==`number`&&Number.isFinite(e)?e:null}function Wn(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function Gn(e,t){return e==null?!1:JSON.stringify(e)!==JSON.stringify(t??null)}var Kn={detectionMode:null,detectionStreamProfile:null,detectionFps:null,motionSources:[],motionFps:null,motionCooldownMs:null,motionStreamProfile:null,audioMode:null,pipelineNodeId:null,decoderNodeId:null,audioNodeId:null,overriddenKeys:new Set};function qn(e){if(!Hn(e)||!Array.isArray(e.sections))return Kn;let t=ge(e),n=e=>{let n=t.get(e);if(n!==void 0)return n.value??n.default},r=new Set;for(let[e,n]of t)Gn(n.value,n.default)&&r.add(e);return{detectionMode:Y(n(`detectionMode`)),detectionStreamProfile:Y(n(`detectionStreamProfile`)),detectionFps:Un(n(`detectionFps`)),motionSources:Wn(n(`motionSources`)),motionFps:Un(n(`motionFps`)),motionCooldownMs:Un(n(`motionCooldownMs`)),motionStreamProfile:Y(n(`motionStreamProfile`)),audioMode:Y(n(`audioMode`)),pipelineNodeId:Y(n(`pipelineNodeId`)),decoderNodeId:Y(n(`decoderNodeId`)),audioNodeId:Y(n(`audioNodeId`)),overriddenKeys:r}}function Jn(e,t=0){let n=[];for(let r of e)n.push({addonId:r.addonId,modelId:r.modelId??null,enabled:r.enabled,depth:t}),r.children!==void 0&&r.children.length>0&&n.push(...Jn(r.children,t+1));return n}function Yn(e){let{assignment:t,detection:n}=e;return n!==null&&n.provisioning.state===`failed`||t.detectionNodeId===null&&n===null?`error`:n!==null&&n.phase===`active`?`healthy`:`idle`}function X({title:e,children:t}){return L(`div`,{className:`bg-background px-3.5 py-3 min-w-0`,children:[H(`div`,{className:`text-[9px] font-semibold uppercase tracking-[0.14em] text-foreground-subtle mb-2`,children:e}),H(`div`,{className:`flex flex-col gap-1 min-w-0`,children:t})]})}function Z({label:e,children:t,overridden:n=!1}){return L(`div`,{className:`flex items-baseline gap-2 text-[11px] leading-snug min-w-0`,children:[H(`span`,{className:`text-foreground-subtle shrink-0 w-24 truncate`,title:e,children:e}),H(`span`,{className:`font-mono tabular-nums text-foreground min-w-0 truncate flex-1`,children:t}),n&&H(Xn,{})]})}function Xn(){return H(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0 self-center`,title:`Device-level override active`,"aria-label":`Device-level override active`,role:`img`})}var Zn={neutral:`border-border text-foreground-muted`,success:`border-success/40 text-success`,warning:`border-warning/40 text-warning`,danger:`border-danger/40 text-danger`,info:`border-info/40 text-info`};function Q({tone:e=`neutral`,children:t,title:n}){return H(`span`,{title:n,className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-medium leading-tight whitespace-nowrap ${Zn[e]}`,children:t})}function $({children:e}){return H(`div`,{className:`text-[11px] text-foreground-subtle italic`,children:e})}function Qn({icon:e,label:t,nodeId:n,pinned:r,reason:i,overridden:a}){return L(`div`,{className:`flex items-center gap-2 text-[11px] leading-snug min-w-0`,children:[H(e,{className:`h-3 w-3 text-foreground-subtle shrink-0`}),H(`span`,{className:`text-foreground-subtle w-[4.5rem] shrink-0`,children:t}),n===null?H(`span`,{className:`text-foreground-subtle italic`,children:`unassigned`}):L(z,{children:[H(`span`,{className:`font-mono text-foreground truncate`,title:n,children:n}),r?L(`span`,{className:`inline-flex items-center gap-0.5 text-[10px] text-warning shrink-0`,title:`Manually pinned`,children:[H(at,{className:`h-2.5 w-2.5`}),` manual`]}):L(`span`,{className:`text-[10px] text-foreground-subtle shrink-0 truncate`,children:[`auto · `,i!==void 0&&i.length>0?i:`capacity`]}),a&&H(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-warning shrink-0`,title:`Persisted settings pin for this role`})]})]})}function $n({assignment:e,settings:t,onlineNodes:n,pinPending:r,onDetectionPinChange:i}){let a=e.pinned.detection&&e.detectionNodeId!==null?e.detectionNodeId:`auto`,o=[...new Set([...e.detectionNodeId===null?[]:[e.detectionNodeId],...n.map(e=>e.id)])];return L(X,{title:`Where it runs`,children:[H(Qn,{icon:K,label:`Detection`,nodeId:e.detectionNodeId,pinned:e.pinned.detection,reason:e.reasons.detection,overridden:t.overriddenKeys.has(`pipelineNodeId`)}),H(Qn,{icon:Re,label:`Decoder`,nodeId:e.decoderNodeId,pinned:e.pinned.decoder,reason:e.reasons.decoder,overridden:t.overriddenKeys.has(`decoderNodeId`)}),H(Qn,{icon:Oe,label:`Audio`,nodeId:e.audioNodeId,pinned:e.pinned.audio,reason:e.reasons.audio,overridden:t.overriddenKeys.has(`audioNodeId`)}),H(Qn,{icon:Me,label:`Source`,nodeId:e.sourceNodeId,pinned:!1,reason:`ingest owner`,overridden:!1}),H(`div`,{className:`mt-1.5`,children:L(`select`,{value:a,disabled:r,"aria-label":`Detection placement pin`,onChange:e=>i(e.target.value),className:`w-full min-w-0 rounded-md border border-border bg-background px-2 py-1 text-[11px] text-foreground disabled:opacity-50`,children:[H(`option`,{value:`auto`,children:`Auto (load balanced)`}),o.map(e=>L(`option`,{value:e,children:[`Pin detection → `,n.find(t=>t.id===e)?.name??e]},e))]})})]})}function er(e){return`${e.width}×${e.height} ${e.codec} @${e.fps}fps`}function tr(e,t){if(!(t===null||e===void 0))return e.find(e=>e.profile===t)}function nr(e){return e===null?`default`:e===0?`native (no throttle)`:`${e} fps`}function rr({streams:e,brokerProfiles:t,settings:n,motionEnabled:r,motionFpsLive:i}){let a=tr(t,n.detectionStreamProfile),o=tr(t,n.motionStreamProfile),s=n.motionSources.includes(`analyzer`);return L(X,{title:`Streams & motion`,children:[L(Z,{label:`Detect stream`,overridden:n.overriddenKeys.has(`detectionStreamProfile`),children:[n.detectionStreamProfile??`—`,a!==void 0&&` · ${a.width}×${a.height} ${a.codec}`]}),H(Z,{label:`Detect FPS`,overridden:n.overriddenKeys.has(`detectionFps`),children:nr(n.detectionFps)}),L(Z,{label:`Motion src`,overridden:n.overriddenKeys.has(`motionSources`),children:[n.motionSources.length>0?n.motionSources.join(` + `):`none`,r===!1&&` · inactive`]}),s&&L(z,{children:[L(Z,{label:`Motion stream`,overridden:n.overriddenKeys.has(`motionStreamProfile`),children:[n.motionStreamProfile??`—`,o!==void 0&&` · ${o.width}×${o.height} ${o.codec}`]}),L(Z,{label:`Motion FPS`,overridden:n.overriddenKeys.has(`motionFps`),children:[nr(n.motionFps),i!==null&&` · live ${i.toFixed(1)}`]})]}),H(Z,{label:`Cooldown`,overridden:n.overriddenKeys.has(`motionCooldownMs`),children:n.motionCooldownMs===null?`default`:`${n.motionCooldownMs/1e3}s`}),H(`div`,{className:`mt-1.5 flex flex-col gap-0.5`,children:e.length===0?H($,{children:`No streams registered`}):e.map(e=>L(`div`,{className:`text-[10px] font-mono text-foreground-subtle truncate`,title:e.camStreamId,children:[H(`span`,{className:`text-foreground-muted`,children:e.kind}),` `,er(e)]},e.camStreamId))})]})}function ir({steps:e,audioModelId:t,audioEnabled:n,audioMode:r}){return L(X,{title:`Pipeline steps`,children:[e===void 0?H($,{children:`Resolving…`}):e.length===0?H($,{children:`No steps configured`}):H(`div`,{className:`flex flex-wrap gap-1`,children:e.map((e,t)=>H(Q,{tone:e.enabled&&e.depth===0?`info`:`neutral`,title:e.modelId??e.addonId,children:L(`span`,{className:e.enabled?``:`line-through opacity-60`,children:[e.depth>0&&H(`span`,{className:`opacity-50`,children:`↳ `}),e.addonId,e.modelId!==null&&L(`span`,{className:`font-mono opacity-75`,children:[` · `,e.modelId]})]})},`${e.addonId}-${t}`))}),H(`div`,{className:`mt-1`,children:L(Z,{label:`Audio class.`,children:[r??`—`,n!==null&&(n?` · running`:` · off`),t!==null&&` · ${t}`]})})]})}var ar={ready:`success`,installing:`info`,verifying:`info`,idle:`neutral`,failed:`danger`};function or({detection:e,live:t,detectionMode:n,modeOverridden:r}){if(e===null)return L(X,{title:`Detection runtime`,children:[H(Z,{label:`Mode`,overridden:r,children:n??`—`}),H($,{children:`Detection stage inactive or unreachable`})]});let i=t?.phase??e.phase,a=t?.actualFps??e.actualFps,o=t?.configuredFps??e.configuredFps,s=t?.avgInferenceTimeMs??e.avgInferenceMs,c=t?.queueDepth??e.queueDepth,l=h(i),u=i===`active`&&a===0;return L(X,{title:`Detection runtime`,children:[L(`div`,{className:`flex items-center gap-1.5 mb-0.5`,children:[L(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-px text-[10px] font-semibold uppercase tracking-wider ${l.badgeClass}`,children:[H(S,{phase:i,className:`h-2.5 w-2.5`}),l.label]}),t!==void 0&&H(`span`,{className:`text-[9px] text-foreground-subtle uppercase tracking-wider`,children:`live`})]}),H(Z,{label:`Mode`,overridden:r,children:n??`—`}),L(Z,{label:`FPS`,children:[H(`span`,{className:u?`text-danger font-semibold`:``,children:a.toFixed(1)}),L(`span`,{className:`text-foreground-subtle`,children:[` / `,o.toFixed(0),` configured`]})]}),L(Z,{label:`Inference`,children:[s.toFixed(0),` ms`,c>0&&L(`span`,{className:`text-warning`,children:[` · queue `,c]}),t!==void 0&&t.droppedFrames>0&&L(`span`,{className:`text-warning`,children:[` · drops `,t.droppedFrames]})]}),L(Z,{label:`Engine`,children:[e.engine.backend,` · `,e.engine.device]}),L(Z,{label:`Provisioning`,children:[H(Q,{tone:ar[e.provisioning.state]??`neutral`,children:e.provisioning.state}),e.provisioning.error!==void 0&&L(`span`,{className:`text-danger text-[10px]`,children:[` `,e.provisioning.error]})]})]})}function sr({broker:e}){return e===null?H(X,{title:`Stream broker`,children:H($,{children:`Broker stage inactive or unreachable`})}):L(X,{title:`Stream broker`,children:[e.profiles.length===0?H($,{children:`No broker profiles`}):H(`div`,{className:`flex flex-col gap-1`,children:e.profiles.map(e=>{let t=e.status===`streaming`,n=t&&e.inFps===0;return L(`div`,{className:`flex items-center gap-2 text-[11px] font-mono tabular-nums min-w-0`,children:[H(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full shrink-0 ${n?`bg-danger`:t?`bg-success animate-pulse`:`bg-border`}`,title:e.status}),H(`span`,{className:`text-foreground w-10 shrink-0 truncate`,title:e.profile,children:e.profile}),L(`span`,{className:`text-foreground-subtle truncate`,children:[e.width,`×`,e.height,` `,e.codec]}),L(`span`,{className:`ml-auto shrink-0 ${n?`text-danger`:`text-foreground`}`,children:[e.inFps.toFixed(0),`→`,e.outFps.toFixed(0),`fps`]}),L(`span`,{className:`text-foreground-subtle shrink-0`,title:`Subscribers`,children:[`×`,e.subscribers]})]},e.profile)})}),L(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:[L(Q,{tone:e.webrtcSessions>0?`info`:`neutral`,children:[`WebRTC `,e.webrtcSessions]}),L(Q,{tone:e.rtspRestream?`success`:`neutral`,children:[`restream `,e.rtspRestream?`on`:`off`]})]})]})}function cr({decoder:e,detectionActive:t}){if(e===null)return H(X,{title:`Decoder`,children:H($,{children:`Decoder stage inactive or unreachable`})});let n=t&&e.shm.framesWritten===0;return L(X,{title:`Decoder`,children:[H(Z,{label:`Node`,children:e.nodeId}),H(Z,{label:`Sessions`,children:e.sessionCount}),L(Z,{label:`SHM frames`,children:[H(`span`,{className:n?`text-danger font-semibold`:``,children:e.shm.framesWritten}),H(`span`,{className:`text-foreground-subtle`,children:` written`})]}),L(Z,{label:`SHM reads`,children:[e.shm.getFrameHits,` hits`,e.shm.getFrameMisses>0&&L(`span`,{className:`text-warning`,children:[` · `,e.shm.getFrameMisses,` misses`]})]}),L(Z,{label:`SHM budget`,children:[e.shm.budgetMb,` MB`]}),e.formats.length>0&&H(Z,{label:`Formats`,children:e.formats.join(`, `)})]})}I();var lr=`pipeline-orchestrator`,ur={healthy:`bg-success`,idle:`bg-warning`,error:`bg-danger`},dr={healthy:`Healthy`,idle:`Idle`,error:`Error`};function fr({problems:e}){return H(`div`,{role:`alert`,className:`flex flex-col border-b border-border`,children:e.map(e=>L(`div`,{className:`flex items-start gap-2 px-4 py-1.5 text-[11px] font-medium ${e.severity===`error`?`bg-danger/10 text-danger`:`bg-warning/10 text-warning`}`,children:[H(qe,{className:`h-3.5 w-3.5 shrink-0 mt-px`}),H(`span`,{className:`min-w-0`,children:e.message})]},e.code))})}function pr({deviceId:e,name:t,online:n,status:r,live:i,onlineNodes:a}){let o=B(),{data:s}=te({addonId:lr,deviceId:e,nodeId:`hub`},{staleTime:3e4}),{data:c}=f({deviceId:e},{staleTime:3e4}),u=R(()=>qn(s),[s]),d=R(()=>c===void 0?void 0:Jn(c.steps),[c]),p=R(()=>r===void 0?[]:Vn(r),[r]),m=()=>{o.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]}),o.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getPipelineAssignments`]]})},h=re({onSuccess:m}),g=l({onSuccess:m}),_=t=>{t===`auto`?g.mutate({deviceId:e}):h.mutate({deviceId:e,agentNodeId:t})},v=r===void 0?`idle`:Yn(r),y=p.some(e=>e.severity===`error`),b=p.length>0,x=y?`border-danger/50`:b?`border-warning/40`:`border-border`;return L(`article`,{"aria-label":`${t} pipeline status`,className:`rounded-lg border ${x} bg-background overflow-hidden`,children:[L(`header`,{className:`flex items-center gap-2.5 px-4 py-2.5 border-b border-border bg-surface/50 min-w-0`,children:[H(`span`,{className:`inline-block h-2 w-2 rounded-full shrink-0 ${y?`bg-danger`:ur[v]}`,title:y?`Error`:dr[v],"aria-label":y?`Error`:dr[v],role:`img`}),H(`h3`,{className:`text-[13px] font-semibold text-foreground truncate`,title:t,children:t}),L(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`#`,e]}),!n&&H(Q,{tone:`danger`,children:`offline`}),L(`span`,{className:`ml-auto flex items-center gap-1.5 shrink-0`,children:[u.detectionMode!==null&&H(Q,{tone:u.detectionMode===`disabled`?`warning`:u.detectionMode===`always-on`?`info`:`neutral`,title:`Object detection mode`,children:u.detectionMode===`disabled`?`detection off`:u.detectionMode}),r?.recording!=null&&(r.recording.active?L(Q,{tone:`danger`,title:`Recording (${r.recording.mode})`,children:[H(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-danger animate-pulse`}),`REC`]}):r.recording.mode!==`off`&&L(Q,{tone:`neutral`,title:`Recording mode`,children:[`rec `,r.recording.mode]}))]})]}),p.length>0&&H(fr,{problems:p}),r===void 0?H(`div`,{className:`px-4 py-5 text-[11px] text-foreground-subtle italic`,children:`No pipeline status yet — the orchestrator has not composed a snapshot for this camera.`}):L(`div`,{className:`grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-px bg-border`,children:[H($n,{assignment:r.assignment,settings:u,onlineNodes:a,pinPending:h.isPending||g.isPending,onDetectionPinChange:_}),H(or,{detection:r.detection,live:i,detectionMode:u.detectionMode,modeOverridden:u.overriddenKeys.has(`detectionMode`)}),H(ir,{steps:d,audioModelId:c?.audio?.modelId??null,audioEnabled:r.audio?.enabled??c?.audio?.enabled??null,audioMode:u.audioMode}),H(rr,{streams:r.source.streams,brokerProfiles:r.broker?.profiles,settings:u,motionEnabled:r.motion?.enabled??null,motionFpsLive:r.motion?.fps??null}),H(sr,{broker:r.broker}),H(cr,{decoder:r.decoder,detectionActive:r.detection?.phase===`active`})]})]})}I();var mr=5e3,hr=1e4,gr=5e3;function _r(e){let t=B(),{data:n,isLoading:r}=xe(),{data:i,isLoading:a}=D({},{refetchInterval:mr}),{nodes:o}=_();U(()=>{e!==0&&t.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCameraStatuses`]]})},[e,t]);let[s,c]=V(new Map);y(_e.PipelineCameraMetricsSnapshot,e=>{let t=e.data;typeof t.deviceId==`number`&&c(e=>{let n=new Map(e);return n.set(t.deviceId,{phase:t.metrics.phase,configuredFps:t.metrics.configuredFps,actualFps:t.metrics.actualFps,queueDepth:t.metrics.queueDepth,avgInferenceTimeMs:t.metrics.avgInferenceTimeMs,droppedFrames:t.metrics.droppedFrames,timestamp:t.timestamp}),n})}),U(()=>{if(s.size===0)return;let e=setInterval(()=>{c(e=>{let t=Date.now()-hr,n=!1,r=new Map(e);for(let[i,a]of e)a.timestamp<t&&(r.delete(i),n=!0);return n?r:e})},gr);return()=>clearInterval(e)},[s.size]);let l=R(()=>{let e=new Map;for(let t of i??[])e.set(t.deviceId,t);return e},[i]);return{rows:R(()=>(n??[]).filter(e=>e.isCamera).map(e=>({deviceId:e.id,name:e.name,online:e.online,status:l.get(e.id)})).sort((e,t)=>e.name.localeCompare(t.name)),[n,l]),liveMetrics:s,onlineNodes:R(()=>(o??[]).filter(e=>e.isOnline).map(e=>({id:e.id,name:e.name})),[o]),isLoading:r||a}}I();function vr({refreshToken:e}){let{rows:t,liveMetrics:n,onlineNodes:r,isLoading:i}=_r(e),a=R(()=>[...t.map(e=>{let t=e.status===void 0?[]:Vn(e.status);return{row:e,errorCount:t.filter(e=>e.severity===`error`).length,warningCount:t.filter(e=>e.severity===`warning`).length}})].sort((e,t)=>e.errorCount===t.errorCount?e.warningCount===t.warningCount?0:t.warningCount-e.warningCount:t.errorCount-e.errorCount),[t]),o=R(()=>{let e=0,t=0;for(let r of a)(r.errorCount>0||r.warningCount>0)&&(t+=1),(n.get(r.row.deviceId)?.phase??r.row.status?.detection?.phase)===`active`&&(e+=1);return{total:a.length,active:e,issues:t}},[a,n]);return i&&t.length===0?H(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`Loading camera pipelines…`}):t.length===0?H(`div`,{className:`flex items-center justify-center h-full text-sm text-foreground-subtle`,children:`No cameras found`}):H(`div`,{className:`h-full overflow-y-auto`,children:L(`div`,{className:`max-w-6xl mx-auto flex flex-col gap-3 px-4 py-4`,children:[L(`div`,{className:`flex items-center gap-4 text-[11px] text-foreground-subtle px-1`,children:[L(`span`,{children:[H(`span`,{className:`font-semibold text-foreground`,children:o.total}),` cameras`]}),L(`span`,{children:[H(`span`,{className:`font-semibold text-success`,children:o.active}),` actively inferring`]}),L(`span`,{children:[H(`span`,{className:`font-semibold ${o.issues>0?`text-danger`:`text-foreground`}`,children:o.issues}),` `,`with issues`]}),H(`span`,{className:`ml-auto hidden sm:inline text-[10px]`,children:`polled every 5 s · detection metrics live at 1 Hz`})]}),a.map(({row:e})=>H(pr,{deviceId:e.deviceId,name:e.name,online:e.online,status:e.status,live:n.get(e.deviceId),onlineNodes:r},e.deviceId))]})})}I();var yr=`__cluster__`;function br(e){return e===`cameras`?`cameras`:`nodes`}function xr(){let[e,t]=Be(),n=br(e.get(`view`)),r=e.get(`node`)??`__cluster__`,[i,a]=V(0),[o,s]=V(!1);return U(()=>{n===`nodes`&&!e.get(`node`)&&t({view:`nodes`,node:yr},{replace:!0})},[n,e,t]),L(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[L(`div`,{className:`flex items-center justify-between gap-4 px-4 py-3 border-b border-border shrink-0`,children:[L(`div`,{className:`flex items-center gap-1 rounded-lg border border-border p-0.5 bg-surface`,children:[H(`button`,{type:`button`,onClick:()=>{t({view:`nodes`,node:r},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,n===`nodes`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Nodes`}),H(`button`,{type:`button`,onClick:()=>{t({view:`cameras`},{replace:!0})},className:[`px-3 py-1 rounded-md text-[11px] font-medium transition-colors`,n===`cameras`?`bg-background text-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground`].join(` `),children:`Cameras`})]}),L(`button`,{type:`button`,onClick:()=>a(e=>e+1),title:`Refresh`,className:`inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1.5 text-[11px] font-medium border border-border text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[H(Ne,{className:`h-3.5 w-3.5`}),`Refresh`]})]}),n===`nodes`&&L(`button`,{type:`button`,onClick:()=>s(e=>!e),"aria-expanded":o,className:`md:hidden flex items-center justify-between gap-2 px-4 py-2 border-b border-border shrink-0 text-[11px] font-medium text-foreground-subtle hover:text-foreground transition-colors`,children:[L(`span`,{children:[o?`Hide`:`Show`,` node list`]}),H(ze,{className:[`h-4 w-4 transition-transform`,o?`rotate-180`:``].join(` `)})]}),H(`div`,{className:`flex-1 flex flex-col md:flex-row overflow-hidden min-h-0`,children:n===`nodes`?L(z,{children:[H(`aside`,{className:[o?`block`:`hidden`,`md:block w-full md:w-72 shrink-0 border-b md:border-b-0 md:border-r border-border`,`max-h-[60vh] md:max-h-none overflow-y-auto`].join(` `),children:H(dt,{selectedNodeId:r,onSelect:e=>{t({view:`nodes`,node:e},{replace:!0}),s(!1)},refreshToken:i})}),H(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:r===`__cluster__`?H(Bn,{refreshToken:i}):H(en,{nodeId:r,refreshToken:i})})]}):H(`section`,{className:`flex-1 min-h-0 overflow-hidden`,children:H(vr,{refreshToken:i})})})]})}export{xr as PipelinePage};