@camstack/addon-admin-ui 1.1.52 → 1.1.53

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 (93) hide show
  1. package/dist/assets/{AddLocationWizard-Uf0yJnjR.js → AddLocationWizard-B2-uyYmP.js} +1 -1
  2. package/dist/assets/{AddonCollectionPage-DqaY4er4.js → AddonCollectionPage-FU3E6QGz.js} +1 -1
  3. package/dist/assets/Addons-DU5z1ZvU.js +1 -0
  4. package/dist/assets/{AdminTabs-BbJVdoRX.js → AdminTabs-CICieyaN.js} +1 -1
  5. package/dist/assets/AiProfiles-BRTUYeoH.js +1 -0
  6. package/dist/assets/{BrokerForm-u3y0YqZe.js → BrokerForm-CuIg_iOf.js} +1 -1
  7. package/dist/assets/{Capabilities-CMfsYieK.js → Capabilities-CEZc9Dcc.js} +1 -1
  8. package/dist/assets/{CapabilityBadges-Ribk0vnA.js → CapabilityBadges-DDSnGBgk.js} +1 -1
  9. package/dist/assets/Cluster-DjZVaBCZ.js +1 -0
  10. package/dist/assets/{Dashboard-qRfzfjPv.js → Dashboard-CLWVhKF4.js} +1 -1
  11. package/dist/assets/{Data-DHhlstKQ.js → Data-aqRyEVJp.js} +1 -1
  12. package/dist/assets/{DetectionIntelligence-DV-yQXDw.js → DetectionIntelligence-Bvw_e-lH.js} +1 -1
  13. package/dist/assets/{DeviceDetail-DHrSmXXI.js → DeviceDetail-Bt08IJis.js} +2 -2
  14. package/dist/assets/{Devices-SsSi-4nJ.js → Devices-CZ_Moh5w.js} +1 -1
  15. package/dist/assets/{EmbedPlayerPage-CzcNBQ3L.js → EmbedPlayerPage-DAeQe0Bf.js} +1 -1
  16. package/dist/assets/{Events-C0-Ts8gr.js → Events-OajEJc_n.js} +1 -1
  17. package/dist/assets/{FormBuilder-BsMr0Lyl.js → FormBuilder-B69YBaq9.js} +1 -1
  18. package/dist/assets/Identity-DWgcf-tI.js +1 -0
  19. package/dist/assets/IntegrationDetail-BOTeJU5I.js +1 -0
  20. package/dist/assets/{Integrations-Cab4Dh8j.js → Integrations-CMT2Jroo.js} +1 -1
  21. package/dist/assets/{Integrations-DZAnOMWG.js → Integrations-nY6HlQUf.js} +1 -1
  22. package/dist/assets/{Logs-DxdTei3J.js → Logs-BTWVO572.js} +1 -1
  23. package/dist/assets/{MotionZonesSettings-Dk5S6Yey.js → MotionZonesSettings-BWhNWsPJ.js} +1 -1
  24. package/dist/assets/{MyAccess-DnZwl6il.js → MyAccess-CJLeYWfN.js} +1 -1
  25. package/dist/assets/Network-DTQVXNuu.js +1 -0
  26. package/dist/assets/{NodeAddonsSettingsPanel-CJbUr7pj.js → NodeAddonsSettingsPanel-BQWXa7vq.js} +1 -1
  27. package/dist/assets/{NotificationTargets-ZY0oUqQy.js → NotificationTargets-DqrqQvJN.js} +1 -1
  28. package/dist/assets/Pipeline-BZPrco_d.js +1 -0
  29. package/dist/assets/{Plates-CpuUTsMF.js → Plates-Cy7kPDK4.js} +1 -1
  30. package/dist/assets/{PrivacyMaskSettings-CsjSf0ui.js → PrivacyMaskSettings-DTEI02Vz.js} +1 -1
  31. package/dist/assets/ProviderIcon-Ba4DQXPs.js +1 -0
  32. package/dist/assets/ScanNetworkModal-CbDd4Bl9.js +1 -0
  33. package/dist/assets/{Settings-Cg40p72B.js → Settings-BxK0kuED.js} +1 -1
  34. package/dist/assets/{Showroom-WqyHrFZ8.js → Showroom-BLBcs7XJ.js} +1 -1
  35. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-mb1uqJnX.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-jFLPXlhw.js} +1 -1
  36. package/dist/assets/{build-cluster-graph-CWEgvPHm.js → build-cluster-graph-CIiqGgZL.js} +1 -1
  37. package/dist/assets/circle-check-big-B-tT2CHM.js +1 -0
  38. package/dist/assets/clock-cwKSxYZs.js +1 -0
  39. package/dist/assets/{copy-uF3P0mCb.js → copy-CTAQpm07.js} +1 -1
  40. package/dist/assets/{debounced-invalidate-CmrI3MX6.js → debounced-invalidate-DZ3oxQDl.js} +1 -1
  41. package/dist/assets/{dist-BIF_0i8X.js → dist-BMrXztkM.js} +1 -1
  42. package/dist/assets/{dist-B39mAyWB.js → dist-tu4iBgMD.js} +2 -2
  43. package/dist/assets/{download-C6gtaH_N.js → download-DjYX33pK.js} +1 -1
  44. package/dist/assets/{face-bbox-C6BZci_u.js → face-bbox-vlSxiLet.js} +1 -1
  45. package/dist/assets/{film-Ce3Puhhw.js → film-lIXZ0TIf.js} +1 -1
  46. package/dist/assets/{hostInit-fNwBYqHp.js → hostInit-BhKkSxQn.js} +1 -1
  47. package/dist/assets/index-Cdp6OaKK.js +4 -0
  48. package/dist/assets/{index-CQGeAf4R.css → index-Cmln2hC6.css} +1 -1
  49. package/dist/assets/{key-round-CTt4GMO-.js → key-round-D6koQlXg.js} +1 -1
  50. package/dist/assets/{mf-entry-bootstrap-0-13957685.js → mf-entry-bootstrap-0-1af432ca.js} +2 -2
  51. package/dist/assets/{pencil-B2rRCbs4.js → pencil-CUVzuL3L.js} +1 -1
  52. package/dist/assets/{player-overlays-G3UGtBzC.js → player-overlays-BrjDKJA9.js} +1 -1
  53. package/dist/assets/plus-CTLCXGgQ.js +1 -0
  54. package/dist/assets/{radio-D3U_70dZ.js → radio-_KFBV9h-.js} +1 -1
  55. package/dist/assets/{refresh-cw-NUBl_9F6.js → refresh-cw-BM18Lfvw.js} +1 -1
  56. package/dist/assets/remoteEntry-xwnWPwER.js +1 -0
  57. package/dist/assets/{rotate-ccw-C9aSKyTE.js → rotate-ccw-EdLXWeWN.js} +1 -1
  58. package/dist/assets/rotate-cw-CE0Ns6Fz.js +1 -0
  59. package/dist/assets/search-mDjJzMoX.js +1 -0
  60. package/dist/assets/{send-Cjr4zHvT.js → send-C5a5_8YJ.js} +1 -1
  61. package/dist/assets/server-CTi1sPfP.js +1 -0
  62. package/dist/assets/square-CfQwX-85.js +1 -0
  63. package/dist/assets/{square-check-big-CSjE0FM_.js → square-check-big-DqE0lyuf.js} +1 -1
  64. package/dist/assets/{src-DJCxIXmd.js → src-BIAY4cjr.js} +1 -1
  65. package/dist/assets/src-Bx1PCCWV.js +67 -0
  66. package/dist/assets/{upload-DY7S1CIX.js → upload-CBvWlRd4.js} +1 -1
  67. package/dist/assets/{useDevice-Ch_9qauD.js → useDevice-CRWDjGkB.js} +1 -1
  68. package/dist/assets/{useEventInvalidation-h9LIsvjv.js → useEventInvalidation-BgQYjLEl.js} +1 -1
  69. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CPN4r1AG.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-BzCJlGIx.js} +2 -2
  70. package/dist/assets/{wifi-0f3nqfEf.js → wifi-D9LNVG6Y.js} +1 -1
  71. package/dist/assets/{zap-BZHvm4pV.js → zap-CjGIHi-s.js} +1 -1
  72. package/dist/index.html +6 -6
  73. package/dist/server/addon.js +4648 -4640
  74. package/package.json +1 -1
  75. package/dist/assets/Addons-an5qhtPG.js +0 -1
  76. package/dist/assets/AiProfiles-DdWPLcwR.js +0 -1
  77. package/dist/assets/Cluster-CYnROh4T.js +0 -1
  78. package/dist/assets/Identity-eIowJSpV.js +0 -1
  79. package/dist/assets/IntegrationDetail-B8wj47uz.js +0 -1
  80. package/dist/assets/Network-dhnXr-jY.js +0 -1
  81. package/dist/assets/Pipeline-DaPp8qeN.js +0 -1
  82. package/dist/assets/ProviderIcon-BSvVPouG.js +0 -1
  83. package/dist/assets/ScanNetworkModal-ByX1qWEM.js +0 -1
  84. package/dist/assets/ServerManagement-BtFGaYJa.js +0 -1
  85. package/dist/assets/circle-check-big-DVa9F7JF.js +0 -1
  86. package/dist/assets/clock-CuFB6vbo.js +0 -1
  87. package/dist/assets/index-BXAOUGFx.js +0 -4
  88. package/dist/assets/plus-DIHRelRK.js +0 -1
  89. package/dist/assets/remoteEntry-tIxTqhi3.js +0 -1
  90. package/dist/assets/rotate-cw-CWQEKQOp.js +0 -1
  91. package/dist/assets/search-CNcDC4RH.js +0 -1
  92. package/dist/assets/square-DCFTa1lw.js +0 -1
  93. package/dist/assets/src-C9tUE6VN.js +0 -67
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/addon-admin-ui",
3
- "version": "1.1.52",
3
+ "version": "1.1.53",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "CamStack Admin UI — Vite frontend build and server-side addon",
@@ -1 +0,0 @@
1
- import{At as e,Ct as t,Da as n,Dt as r,Et as i,Mr as a,Rr as o,St as s,Tt as c,_t as l,bt as u,dt as ee,ft as d,g as f,gt as p,ht as m,jt as h,kt as g,m as _,mt as v,pt as te,v as ne,vt as re,wa as ie,xa as ae,xt as y}from"./src-C9tUE6VN.js";import{I as b,K as x,Q as S,R as oe,S as C,W as w,b as T,o as E,q as D,x as O,z as k}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{R as se}from"./src-DJCxIXmd.js";import{p as ce}from"./player-overlays-G3UGtBzC.js";import{t as A}from"./clock-CuFB6vbo.js";import{t as j}from"./download-C6gtaH_N.js";import{t as le}from"./plus-DIHRelRK.js";import{t as M}from"./refresh-cw-NUBl_9F6.js";import{t as ue}from"./search-CNcDC4RH.js";import{t as N}from"./upload-DY7S1CIX.js";import{C as P,I as F,J as de,K as fe,L as I,M as L,W as R,_ as z,h as B,i as V,p as H,s as U}from"./index-BXAOUGFx.js";import{t as W}from"./AdminPage-BwmGKnRf.js";import{t as pe}from"./NodeAddonsSettingsPanel-CJbUr7pj.js";var me=R(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),he=R(`octagon-alert`,[[`path`,{d:`M12 16h.01`,key:`1drbdi`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M15.312 2a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586l-4.688-4.688A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2z`,key:`1fd625`}]]),G=R(`package`,[[`path`,{d:`M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z`,key:`1a0edw`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}],[`polyline`,{points:`3.29 7 12 12 20.71 7`,key:`ousv84`}],[`path`,{d:`m7.5 4.27 9 5.15`,key:`1c824w`}]]),K=R(`skip-forward`,[[`polygon`,{points:`5 4 15 12 5 20 5 4`,key:`16p6eg`}],[`line`,{x1:`19`,x2:`19`,y1:`5`,y2:`19`,key:`futhcm`}]]);S();var q=new Set([`completed`,`failed`,`partially-failed`,`cancelled`]),J=new Set([`done`,`failed`,`skipped`]);function Y(e){return!J.has(e.phase)&&!q.has(e.jobState)}function ge(e,t){let n=new Map,r=[...e].sort((e,t)=>e.createdAtMs-t.createdAtMs);for(let e of r){let r=q.has(e.state);for(let i of e.tasks)r&&i.finishedAtMs!==null&&t-i.finishedAtMs>6e4||n.set(i.packageName,{jobId:e.jobId,packageName:i.packageName,phase:i.phase,fromVersion:i.fromVersion,toVersion:i.toVersion,error:i.error,jobState:e.state,finishedAtMs:i.finishedAtMs})}return n}function _e(){let{data:e}=u({activeOnly:!0},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data?.length??0)>0?3e3:!1}),{map:t}=n(se.AddonsJobProgress,e=>e.job.jobId);return w(()=>{let n=new Map;for(let t of e??[])n.set(t.jobId,t);for(let[e,r]of t)n.set(e,r.job);return ge([...n.values()],Date.now())},[e,t])}var X={queued:{icon:A,cls:`bg-muted text-foreground-subtle`,label:`queued`},fetching:{icon:P,cls:`bg-primary/10 text-primary`,label:`fetching`,spin:!0},staged:{icon:P,cls:`bg-primary/10 text-primary`,label:`staged`,spin:!0},validating:{icon:P,cls:`bg-primary/10 text-primary`,label:`validating`,spin:!0},applying:{icon:P,cls:`bg-primary/10 text-primary`,label:`applying`,spin:!0},restarting:{icon:P,cls:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,label:`restarting`,spin:!0},applied:{icon:P,cls:`bg-primary/10 text-primary`,label:`finalizing`,spin:!0},done:{icon:I,cls:`bg-success/10 text-success`,label:`updated`},failed:{icon:he,cls:`bg-danger/10 text-danger`,label:`failed`},skipped:{icon:K,cls:`bg-muted text-foreground-subtle`,label:`skipped`}};function ve({progress:e}){let t=X[e.phase],n=t.icon,r=e.error??`${e.packageName}: ${e.fromVersion??`?`} → ${e.toVersion}`;return C(`span`,{"data-testid":`addon-job-progress`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded shrink-0 ${t.cls}`,title:r,children:[O(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label,C(`span`,{className:`font-mono`,children:[`→ `,e.toVersion]})]})}function ye({packageName:e,currentVersion:t,installSource:n,onInstall:r,onClose:i,onSelect:a,selectedVersion:o}){let s=n===`upload`||n===`local`,{data:c,isLoading:l}=p({name:e});return C(`div`,{className:`fixed z-50 w-72 rounded-lg border border-border bg-surface shadow-xl overflow-hidden`,style:{top:`auto`,bottom:`auto`},ref:e=>{if(!e)return;let t=e.parentElement?.getBoundingClientRect();if(!t)return;let n=window.innerHeight-t.bottom,r=t.top;n<280&&r>n?(e.style.bottom=`${window.innerHeight-t.top+4}px`,e.style.top=`auto`):(e.style.top=`${t.bottom+4}px`,e.style.bottom=`auto`),e.style.right=`${window.innerWidth-t.right}px`},onClick:e=>e.stopPropagation(),children:[C(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[O(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:`Versions`}),O(`button`,{type:`button`,onClick:i,className:`text-foreground-subtle hover:text-foreground`,children:O(V,{className:`h-3 w-3`})})]}),s&&C(`div`,{className:`flex items-start gap-2 px-3 py-2 border-b border-border bg-cyan-500/10 text-[10px]`,children:[O(N,{className:`h-3 w-3 mt-0.5 text-cyan-500 shrink-0`}),C(`div`,{className:`text-cyan-700 dark:text-cyan-200`,children:[C(`span`,{className:`font-semibold`,children:[n===`upload`?`Uploaded copy`:`Local copy`,` in place.`]}),` `,`Re-install `,O(`span`,{className:`font-mono`,children:t}),` from npm to track upstream releases again.`]})]}),l&&C(`div`,{className:`flex items-center justify-center gap-2 py-6 text-[10px] text-foreground-subtle`,children:[O(P,{className:`h-3.5 w-3.5 animate-spin`}),`Loading versions...`]}),c&&O(`div`,{className:`max-h-64 overflow-auto divide-y divide-border`,children:c.map(e=>{let n=e.version===t,i=a!==void 0&&e.version===o,c=/-(alpha|beta|rc|dev|canary|next)/i.test(e.version),l=C(T,{children:[O(`span`,{className:`font-mono flex-1 text-left ${n?`text-primary font-semibold`:c?`text-amber-400`:`text-foreground`}`,children:e.version}),n&&O(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium bg-primary/10 text-primary`,children:`current`}),e.distTags.map(e=>O(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e===`latest`?`bg-emerald-500/15 text-emerald-400`:e===`beta`?`bg-amber-500/15 text-amber-400`:`bg-gray-500/15 text-gray-400`}`,children:e},e)),e.deprecated&&O(`span`,{className:`text-[9px] text-red-400 line-through`,children:`deprecated`}),O(`span`,{className:`text-[9px] text-foreground-subtle shrink-0`,children:new Date(e.publishedAt).toLocaleDateString()})]});return a?C(`button`,{type:`button`,"aria-label":`Select ${e.version}`,onClick:()=>a(e.version),className:`w-full flex items-center gap-2 px-3 py-2 text-[11px] ${i?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[l,i?O(I,{className:`h-3 w-3 text-primary shrink-0`}):O(`span`,{className:`w-3 shrink-0`})]},e.version):C(`div`,{className:`flex items-center gap-2 px-3 py-2 text-[11px] ${n?`bg-primary/5`:`hover:bg-surface-hover`} transition-colors`,children:[l,n&&!s?O(I,{className:`h-3 w-3 text-primary shrink-0`}):O(`button`,{type:`button`,onClick:()=>r(e.version),className:`shrink-0 rounded p-0.5 hover:bg-primary/20 text-foreground-subtle hover:text-primary transition-colors`,title:n?`Re-install ${e.version} from npm`:`Install ${e.version}`,children:O(j,{className:`h-3 w-3`})})]},e.version)})}),c&&c.length===0&&O(`div`,{className:`py-4 text-center text-[10px] text-foreground-subtle`,children:`No versions found`})]})}var be={queued:{icon:A,bg:`bg-muted text-foreground-subtle`,label:`queued`},updating:{icon:P,bg:`bg-primary/10 text-primary`,label:`updating`,spin:!0},"done-pending-restart":{icon:M,bg:`bg-amber-500/10 text-amber-700`,label:`pending restart`},done:{icon:I,bg:`bg-success/10 text-success`,label:`done`},failed:{icon:he,bg:`bg-danger/10 text-danger`,label:`failed`}};function xe({item:e}){let t=be[e.status],n=t.icon;return C(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded ${t.bg}`,title:e.error,children:[O(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label]})}S();var Z=`device-export`;function Se(e){return e.capabilities.some(e=>(typeof e==`string`?e:e.name)===Z)}function Ce({isBundle:e,installSource:t,addonId:n,iconPath:r,color:i}){let[a,o]=D(!1),s=i?{backgroundColor:`${i.startsWith(`#`)?i:`#${i}`}26`}:void 0,c=e?`bg-indigo-500/20 text-indigo-700 dark:text-indigo-300`:`bg-purple-500/20 text-purple-700 dark:text-purple-300`,l=n&&r?`/api/addon-assets/${n}/${r}`:null,u=!!l&&!a;return C(`div`,{className:`relative flex-shrink-0`,children:[O(`div`,{className:`h-9 w-9 rounded-lg flex items-center justify-center ${s?``:c}`,style:s,children:u?O(`img`,{src:l,alt:n,className:`h-5 w-5`,onError:()=>o(!0)}):O(e?G:z,{className:`h-4 w-4`})}),t===`local`&&O(`span`,{className:`absolute -top-1.5 -left-1.5 text-[7px] font-bold leading-none bg-orange-500 text-white px-1 py-0.5 rounded -rotate-12 shadow-sm`,children:`DEV`}),t===`npm`&&O(`span`,{className:`absolute -top-1 -left-1 w-4 h-4 rounded bg-[#cb3837] flex items-center justify-center -rotate-12 shadow-sm`,children:O(`svg`,{viewBox:`0 0 780 250`,className:`w-[11px] h-[11px]`,children:O(`path`,{fill:`#fff`,d:`M240 250h100V50h100v200h340V0H0v250z`})})}),t===`upload`&&O(`span`,{className:`absolute -top-1.5 -left-1.5 flex items-center justify-center h-4 w-4 rounded bg-cyan-500 -rotate-12 shadow-sm`,children:O(N,{className:`h-2.5 w-2.5 text-white`})})]})}function we({version:e,availableUpdate:t,selectedVersion:n,isUpdating:r,installSource:i,disabled:a,onUpdate:o,onOpenPicker:s,children:c}){if(r)return C(`span`,{className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-blue-500/30 bg-blue-500/10 text-blue-400 shrink-0`,children:[O(P,{className:`h-3 w-3 animate-spin`}),`Updating…`]});if(t){let r=n??t;return C(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[o&&C(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o()},disabled:a,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-semibold border border-blue-500/30 bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,title:`Update to ${r}`,children:[O(j,{className:`h-3 w-3`}),`Update`]}),C(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s()},disabled:a,"aria-label":`Select version to install`,title:`Installed ${e} — update available. Selected ${r}; tap to choose another version.`,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-bold font-mono border border-amber-500/40 bg-amber-500/15 text-amber-500 hover:bg-amber-500/25 animate-pulse disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[O(`span`,{className:`font-normal opacity-70`,children:e}),O(`span`,{className:`font-normal opacity-70`,children:`→`}),r,O(F,{className:`h-3 w-3`})]}),c]})}return C(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[C(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s()},disabled:a,className:[`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-bold font-mono border transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,i===`local`?`border-orange-500/30 bg-orange-500/10 text-orange-400 hover:bg-orange-500/20`:`border-emerald-500/30 bg-emerald-500/10 text-emerald-400 hover:bg-emerald-500/20`].join(` `),title:`Version ${e} — tap to view all versions`,children:[e,O(F,{className:`h-3 w-3 opacity-50`})]}),c]})}function Te({addonId:e}){let t=E(),{data:n=`inherit`}=te({addonId:e}),i=r({onSuccess:()=>{t.invalidateQueries({queryKey:[[`addons`,`getAddonAutoUpdate`]]})}});return O(`div`,{className:`flex rounded-lg border border-border overflow-hidden text-[10px] font-medium`,children:[`inherit`,`off`,`latest`,`beta`].map(t=>O(`button`,{type:`button`,onClick:n=>{n.stopPropagation(),i.mutate({addonId:e,channel:t})},disabled:i.isPending,className:`px-2.5 py-1 transition-colors capitalize ${n===t?t===`inherit`?`bg-gray-700/50 text-gray-700 dark:text-gray-300`:t===`off`?`bg-gray-700 text-gray-700 dark:text-gray-300`:t===`latest`?`bg-blue-500/20 text-blue-400`:`bg-amber-500/20 text-amber-400`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`} ${t===`inherit`?``:`border-l border-border`}`,children:t},t))})}function Ee({addon:n,agents:r=[],clusterStatus:i,hideVersion:a,availableUpdate:o,onUpdate:s,isUpdating:u,jobProgress:ee,bundle:d,bulkItem:p,disabledByBulk:m,isSystem:h}){let[g,v]=D(!1),[te,re]=D(!1),[ie,y]=D(!1),[b,x]=D(null);k(()=>{x(null)},[o]);let S=b??o,[oe,w]=D(!1),[se,A]=D(!1),[j,ue]=D(`logs`),N=E(),P=ce(),de=fe(),I=ae(),{manifest:L}=n,R=n.installedOn??[],z=!d&&!L.protected&&L.removable!==!1,W=!!d,K=d?.displayName??L.name,q=d?.packageName??L.packageName,J=d?.version??L.packageVersion??L.version,Y=d?.installSource??n.installSource,ge=d?d.bundle?.description??d.addons[0]?.manifest.description:L.description,_e=e({onSuccess:()=>{N.invalidateQueries({queryKey:[[`addons`]]}),N.invalidateQueries({queryKey:[[`addonPages`]]}),N.invalidateQueries({queryKey:[[`capabilities`]]})}}),X=t({onSuccess:()=>{N.invalidateQueries({queryKey:[[`addons`]]})}}),be=l({onSuccess:()=>{N.invalidateQueries({queryKey:[[`addons`]]}),N.invalidateQueries({queryKey:[[`addonPages`]]}),N.invalidateQueries({queryKey:[[`capabilities`]]}),N.invalidateQueries({queryKey:[[`integrations`]]})}}),Z=c({onSuccess:()=>{N.invalidateQueries({queryKey:[[`addons`]]}),N.invalidateQueries({queryKey:[[`alerts`]]})}}),Q=n.health,De=Q?.phase===`failed`&&!Q.inGracePeriod,Oe=De&&Q?.nextRetryAt&&!Q.retrying;return C(`div`,{className:`rounded-lg border bg-surface overflow-hidden ${De?`border-red-500/50`:`border-border`}`,children:[De&&Q&&C(`div`,{className:`bg-danger/10 border-b border-danger/30 px-4 py-2.5 flex items-start gap-2.5`,children:[O(he,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),C(`div`,{className:`flex-1 min-w-0`,children:[C(`div`,{className:`text-xs font-semibold text-danger`,children:[`Failed to load (attempt #`,Q.retryCount,`)`]}),O(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:Q.lastError?.message??`Unknown error`}),Oe&&Q.nextRetryAt&&C(`div`,{className:`text-[10px] text-foreground-subtle mt-1`,children:[`Auto-retry at `,new Date(Q.nextRetryAt).toLocaleTimeString()]})]}),C(`button`,{type:`button`,disabled:Z.isPending||Q.retrying,onClick:e=>{e.stopPropagation(),Z.mutate({packageName:q})},className:`inline-flex items-center gap-1.5 rounded-md px-2.5 py-1 text-[11px] font-semibold border border-red-400/40 bg-red-400/10 text-red-700 dark:text-red-300 hover:bg-red-400/20 disabled:opacity-50 disabled:cursor-not-allowed transition-colors shrink-0`,title:`Reset retry counter and force immediate reload`,children:[O(M,{className:`h-3 w-3 ${Z.isPending||Q.retrying?`animate-spin`:``}`}),`Retry now`]})]}),C(`div`,{className:`flex items-start gap-3 px-4 py-3`,children:[O(Ce,{isBundle:W||!!L.components&&L.components.length>1,installSource:Y,addonId:W?d.addons[0]?.manifest.id:L.id,iconPath:W?d.bundle?.icon??d.addons[0]?.manifest.icon:L.icon,color:W?d.addons[0]?.manifest.color:L.color}),C(`div`,{className:`flex-1 min-w-0`,children:[C(`div`,{className:`flex items-start justify-between gap-2`,children:[O(`span`,{className:`text-sm font-semibold text-foreground truncate min-w-0`,children:K}),!a&&O(we,{version:J,availableUpdate:o,...S===void 0?{}:{selectedVersion:S},isUpdating:u,installSource:Y,disabled:m,...s&&S!==void 0?{onUpdate:()=>s(S)}:{},onOpenPicker:()=>y(e=>!e),children:ie&&O(ye,{packageName:q,currentVersion:J,...Y?{installSource:Y}:{},...o!==void 0&&S!==void 0?{selectedVersion:S,onSelect:e=>{x(e),y(!1)}}:{},onInstall:e=>{y(!1),be.mutate({packageName:q,version:e})},onClose:()=>y(!1)})})]}),C(`div`,{className:`flex flex-wrap items-center gap-x-1.5 gap-y-1 mt-0.5`,children:[q!==K&&O(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate max-w-full`,children:q}),W&&C(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1`,children:[O(G,{className:`h-3 w-3`}),d.addons.length]}),h&&C(`span`,{className:`text-[10px] rounded-full bg-amber-500/15 text-amber-700 dark:text-amber-300 px-2 py-0.5 font-medium shrink-0 inline-flex items-center gap-1`,title:`System package — updating restarts the hub`,children:[O(M,{className:`h-3 w-3`}),`System`]}),p!=null&&O(xe,{item:p}),ee!=null&&O(ve,{progress:ee})]}),ge&&O(`p`,{className:`text-[10px] text-foreground-subtle mt-1 line-clamp-1`,children:ge}),!W&&n.process&&C(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[O(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${n.process.mode===`forked`?`bg-blue-500/15 text-blue-400`:`bg-gray-500/15 text-gray-400`}`,children:n.process.mode===`forked`?`forked`:`in-process`}),n.process.pid!=null&&C(`span`,{className:`text-[9px] font-mono text-foreground-subtle`,children:[`PID `,n.process.pid]}),O(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${n.process.state===`running`?`bg-emerald-500/15 text-emerald-400`:n.process.state===`crashed`||n.process.state===`failed`?`bg-red-500/15 text-red-400`:`bg-gray-500/15 text-gray-400`}`,children:n.process.state})]})]})]}),!W&&C(`div`,{className:`flex items-center gap-1 px-4 py-1.5 border-t border-border/50 bg-surface-hover/20`,children:[C(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),X.mutate({addonId:L.id})},disabled:X.isPending||m,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-border text-foreground-subtle hover:text-blue-400 hover:border-blue-500/30 hover:bg-blue-500/10 disabled:opacity-50 transition-colors`,children:[O(M,{className:`h-3 w-3 ${X.isPending?`animate-spin`:``}`}),`Restart`]}),C(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),w(e=>!e)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${oe?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[O(B,{className:`h-3 w-3`}),`Logs`]}),!W&&C(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),A(!0)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${se?`border-primary/30 bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground hover:border-primary/30 hover:bg-primary/10`}`,children:[O(H,{className:`h-3 w-3`}),`Settings`]}),O(`div`,{className:`flex-1`}),z&&C(`button`,{type:`button`,onClick:async e=>{e.stopPropagation(),await I({title:`Uninstall ${L.name}?`,message:`This will remove the addon package and all its data. This action cannot be undone.`,confirmLabel:`Uninstall`,variant:`danger`})&&_e.mutate({packageName:L.packageName})},disabled:_e.isPending||m,className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border border-border text-foreground-subtle hover:text-red-400 hover:border-red-500/30 hover:bg-red-500/10 disabled:opacity-50 transition-colors`,children:[O(U,{className:`h-3 w-3`}),_e.isPending?`Removing...`:`Uninstall`]})]}),i&&i.nodes.length>1&&!W&&C(`div`,{className:`border-t border-border px-4 py-2 bg-muted/10`,children:[O(`div`,{className:`text-[10px] font-medium text-foreground-subtle mb-1.5`,children:`Cluster Deployment`}),O(`div`,{className:`space-y-1`,children:i.nodes.map(e=>C(`div`,{className:`flex items-center gap-2 text-[10px]`,children:[O(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`offline`?`bg-muted-foreground/30`:e.synced?`bg-success`:`bg-amber-500`}`}),O(`span`,{className:`font-medium text-foreground min-w-[60px]`,children:e.name}),O(`span`,{className:`font-mono text-foreground-subtle`,children:e.version}),!e.synced&&e.status!==`offline`&&O(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-amber-500/10 text-amber-400 border border-amber-500/20`,children:`outdated`}),e.status===`offline`&&O(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground`,children:`offline`}),e.synced&&e.status!==`offline`&&O(`span`,{className:`text-[9px] text-success`,children:`synced`})]},e.nodeId))})]}),oe&&!W&&C(`div`,{className:`border-t border-border`,children:[C(`div`,{className:`flex items-center px-4 py-1 bg-surface-hover/20 border-b border-border/50`,children:[C(`div`,{className:`flex rounded border border-border overflow-hidden text-[9px]`,children:[O(`button`,{type:`button`,onClick:()=>ue(`logs`),className:`px-2 py-0.5 transition-colors ${j===`logs`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Logs`}),O(`button`,{type:`button`,onClick:()=>ue(`events`),className:`px-2 py-0.5 border-l border-border transition-colors ${j===`events`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Events`})]}),O(`div`,{className:`flex-1`}),O(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),w(!1)},className:`text-foreground-subtle hover:text-foreground`,children:O(V,{className:`h-3.5 w-3.5`})})]}),j===`logs`&&O(f,{addonId:L.id,maxHeight:`max-h-64`,showFilters:!1}),j===`events`&&O(_,{addonId:L.id,category:`addon.*`,maxHeight:`max-h-64`})]}),W&&C(T,{children:[O(`button`,{type:`button`,onClick:()=>v(e=>!e),className:`w-full flex items-center justify-center border-t border-border py-1 hover:bg-surface-hover/50 transition-colors`,children:O(g?me:F,{className:`h-3.5 w-3.5 text-foreground-subtle`})}),g&&O(`div`,{className:`border-t border-border px-3 py-2 space-y-2`,children:d.addons.map(e=>O(Ee,{addon:e,agents:r,hideVersion:!0},e.manifest.id))})]}),se&&!W&&O(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4`,onClick:()=>A(!1),children:C(`div`,{className:`w-full max-w-lg max-h-[80vh] rounded-xl border border-border bg-surface shadow-2xl flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),children:[C(`div`,{className:`flex items-center justify-between px-5 py-3 border-b border-border flex-shrink-0`,children:[C(`div`,{className:`flex items-center gap-2`,children:[O(H,{className:`h-4 w-4 text-primary`}),C(`h2`,{className:`text-sm font-semibold text-foreground`,children:[K,` Settings`]})]}),O(`button`,{onClick:()=>A(!1),className:`text-foreground-subtle hover:text-foreground transition-colors p-1 rounded`,children:O(V,{className:`h-4 w-4`})})]}),C(`div`,{className:`flex-1 overflow-y-auto px-5 py-4 space-y-4`,children:[O(pe,{nodeId:`hub`,addonIds:[L.id],level:`global`}),Se(L)&&C(`div`,{children:[O(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Device export`}),O(ne,{addonId:L.id,trpc:P.trpcClient,onOpenDevice:e=>de(`/devices/${e}`)})]}),Y===`npm`&&C(`div`,{children:[O(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Auto-Update`}),O(Te,{addonId:L.id})]}),L.components&&L.components.length>0&&C(`div`,{children:[C(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Components (`,L.components.length,`)`]}),O(`div`,{className:`flex flex-wrap gap-1`,children:L.components.map(e=>O(`span`,{className:`text-[10px] rounded bg-background border border-border px-1.5 py-0.5 text-foreground-subtle font-mono`,children:e},e))})]}),r.length>=2&&C(`div`,{children:[O(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Installed on`}),C(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[R.length===0&&O(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Hub (local)`}),R.map(e=>O(`span`,{className:`rounded-full bg-surface-hover border border-border px-2 py-0.5 text-[10px] text-foreground-subtle`,children:e},e)),C(`div`,{className:`relative`,children:[C(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),re(e=>!e)},className:`inline-flex items-center gap-1 rounded-full border border-dashed border-border px-2 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground hover:border-primary transition-colors`,title:`Install on more agents`,children:[O(le,{className:`h-3 w-3`}),`Add agent`]}),te&&C(`div`,{className:`absolute left-0 top-full mt-1 z-10 min-w-[160px] rounded-md border border-border bg-surface shadow-lg overflow-hidden`,children:[r.filter(e=>!e.isHub&&!R.includes(e.name)).map(e=>O(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),re(!1)},className:`w-full text-left px-3 py-1.5 text-[10px] text-foreground hover:bg-surface-hover transition-colors`,children:e.name},e.id)),r.filter(e=>!e.isHub&&!R.includes(e.name)).length===0&&O(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle`,children:`No available agents`})]})]})]})]})]}),O(`div`,{className:`flex items-center justify-end px-5 py-3 border-t border-border flex-shrink-0`,children:O(`button`,{type:`button`,onClick:()=>A(!1),className:`rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:`Close`})})]})})]})}S();var Q=`.tgz,.tar.gz,.zip`;function De({onUploadSuccess:e}){let[t,n]=D(!1),r=x(null),i=b(async t=>{n(!0);let r=new FormData;r.append(`file`,t);let i=localStorage.getItem(`camstack_admin_token`)??``;try{(await(await fetch(`/api/addons/upload`,{method:`POST`,headers:{Authorization:`Bearer ${i}`},body:r})).json()).success&&e()}finally{n(!1)}},[e]);return C(T,{children:[O(`input`,{ref:r,type:`file`,accept:Q,onChange:b(e=>{let t=e.target.files?.[0];t&&i(t),e.target.value=``},[i]),className:`hidden`}),C(`button`,{type:`button`,onClick:()=>r.current?.click(),disabled:t,className:`flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,children:[t?O(P,{className:`w-3.5 h-3.5 animate-spin`}):O(N,{className:`w-3.5 h-3.5`}),t?`Uploading...`:`Upload`]})]})}S();var Oe=new Set([`@camstack/system`,`@camstack/types`,`@camstack/sdk`,`@camstack/shm-ring`,`@camstack/ui-library`]);function ke(e){return e!==void 0&&Oe.has(e)}function Ae(e,t){let n=e??`hub-only`;return n===`any-node`?!0:n===`hub-only`?t:!t}function je(e){let t=e;if(!t?.manifest)return null;let n={...t.manifest,name:t.manifest.name??t.manifest.id,version:t.manifest.version??`0.0.0`,capabilities:t.manifest.capabilities??[]},r=t.process,i=r?{pid:r.pid,mode:r.mode===`forked`?`forked`:`in-process`,state:r.state??`unknown`}:void 0,a=t.health,o=t.declaration?.execution,s=t.manifest.execution,c=o?.placement??s?.placement;return{manifest:n,enabled:!0,source:t.source,installSource:t.installSource,installedOn:[],...i?{process:i}:{},hasBackup:t.hasBackup,...a?{health:a}:{},...c?{placement:c}:{}}}function Me(e){let t=new Map,n=[];for(let r of e){let e=r.manifest.packageName;if(!e){n.push(r);continue}let i=t.get(e);if(i)i.addons.push(r);else{let n=r.manifest.bundle,i={packageName:e,displayName:n?.displayName??r.manifest.packageDisplayName??r.manifest.name,version:r.manifest.packageVersion,addons:[r],...r.installSource===void 0?{}:{installSource:r.installSource},...n===void 0?{}:{bundle:n}};t.set(e,i)}}let r=[];for(let e of t.values())e.bundle!==void 0||e.addons.length>=2?r.push({bundle:e,representative:e.addons[0]}):r.push(e.addons[0]);return r.push(...n),r}function $(e){return`bundle`in e}function Ne({addons:e,clusterStatus:t,selectedNode:n,onRefresh:r,isRefreshing:a}){let o=E(),[s,c]=D(``),u=oe(s),[d,f]=D(!1),p=x(null);k(()=>{if(!d)return;let e=e=>{p.current&&!p.current.contains(e.target)&&f(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[d]);let{data:_}=y({nodeId:n.id}),te=w(()=>{let e=new Map;for(let t of _??[])e.set(t.name,t.latestVersion);return e},[_]),ne=w(()=>(_??[]).filter(e=>!e.isSystem).length,[_]),[re,ie]=D(()=>new Set),[S,T]=D(()=>new Map),se=b(e=>{ie(t=>new Set(t).add(e))},[]),ce=b(e=>{ie(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),A=b((e,t)=>{T(n=>new Map(n).set(e,t))},[]),le=b(e=>{T(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]),N=h({onMutate:e=>{se(e.name),le(e.name)},onSuccess:(e,t)=>{ce(t.name);let n=e;if(n&&n.success===!1){A(t.name,n.error??`Update failed (no error message returned by server)`);return}o.invalidateQueries({queryKey:[[`addons`]]}),o.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]})},onError:(e,t)=>{ce(t.name),A(t.name,e instanceof Error?e.message:String(e))}}),F=_e(),fe=x(new Set);k(()=>{let e=new Set;for(let[t,n]of F)Y(n)&&e.add(t);let t=[...fe.current].some(t=>!e.has(t));fe.current=e,t&&(o.invalidateQueries({queryKey:[[`addons`]]}),o.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]}))},[F,o]);let{data:R}=v(void 0),z=ee({onSuccess:()=>{o.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),{data:B,isFetching:V}=i({query:u||void 0},{enabled:d}),H=g(),{data:U}=m(void 0),W=U?.requestedAt,[pe,me]=D(null),[he,G]=D(!1);k(()=>{if(U?.kind===`framework-bulk-update`&&U.requestedAt!==pe){me(U.requestedAt),G(!0);let e=window.setTimeout(()=>G(!1),6e3);return()=>window.clearTimeout(e)}},[W,pe,U]),ae();let K=b(async()=>{let e=(_??[]).filter(e=>!e.isSystem);e.length!==0&&await H.mutateAsync({kind:`update`,targets:e.map(e=>({name:e.name,version:e.latestVersion})),nodeIds:[n.id]})},[_,n.id,H]),q=l({onSuccess:()=>{o.invalidateQueries({queryKey:[[`addons`]]}),o.invalidateQueries({queryKey:[[`addonPages`]]}),o.invalidateQueries({queryKey:[[`capabilities`]]}),o.invalidateQueries({queryKey:[[`integrations`]]})}}),[J,ge]=D(`type`),[X,ve]=D(()=>typeof window>`u`?`grouped`:window.localStorage.getItem(`camstack.addons.viewMode`)===`flat`?`flat`:`grouped`),ye=e=>{ve(e),typeof window<`u`&&window.localStorage.setItem(`camstack.addons.viewMode`,e)},[be,xe]=de(),Z=be.get(`capability`),Se=w(()=>{let t=e.filter(e=>!ke(e.manifest.packageName));return n.isHub||(t=t.filter(e=>Ae(e.placement,n.isHub))),Z&&(t=t.filter(e=>(e.manifest.capabilities??[]).some(e=>(typeof e==`string`?e:e.name)===Z))),t},[e,n.isHub,Z]),Ce=()=>{let e=new URLSearchParams(be);e.delete(`capability`),xe(e,{replace:!0})},we=X===`flat`?Se:Me(Se),Te=w(()=>{let e=[...we];switch(J){case`type`:e.sort((e,t)=>{let n=+!$(e),r=+!$(t);if(n!==r)return n-r;let i=$(e)?e.bundle.displayName:e.manifest.name,a=$(t)?t.bundle.displayName:t.manifest.name;return i.localeCompare(a)});break;case`name`:e.sort((e,t)=>{let n=$(e)?e.bundle.displayName:e.manifest.name,r=$(t)?t.bundle.displayName:t.manifest.name;return n.localeCompare(r)});break;case`source`:e.sort((e,t)=>{let n=$(e)?e.bundle.installSource??``:e.installSource??``,r=$(t)?t.bundle.installSource??``:t.installSource??``;return n.localeCompare(r)});break}return e},[we,J]);return C(`div`,{className:`space-y-4`,children:[[...S.entries()].map(([e,t])=>O(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px]`,children:C(`div`,{className:`flex items-start justify-between gap-3`,children:[C(`div`,{className:`space-y-0.5`,children:[C(`div`,{className:`font-medium text-danger`,children:[`Failed to update `,e]}),O(`div`,{className:`text-foreground-subtle font-mono`,children:t})]}),O(`button`,{type:`button`,onClick:()=>le(e),className:`text-foreground-subtle hover:text-foreground text-[10px]`,children:`dismiss`})]})},e)),C(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[C(`div`,{className:`flex items-center gap-1.5`,children:[O(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Sort:`}),C(`select`,{value:J,onChange:e=>ge(e.target.value),className:`rounded-md border border-border bg-surface px-2 py-1.5 text-[11px] text-foreground focus:outline-none focus:border-primary/50`,children:[O(`option`,{value:`type`,children:`Bundles first`}),O(`option`,{value:`name`,children:`Name`}),O(`option`,{value:`source`,children:`Install source`})]})]}),C(`div`,{className:`flex items-center gap-1.5`,children:[O(`span`,{className:`text-[10px] text-foreground-subtle`,children:`View:`}),O(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`grouped`,`flat`].map(e=>O(`button`,{type:`button`,onClick:()=>ye(e),className:`px-2.5 py-1.5 transition-colors capitalize ${X===e?`bg-primary/10 text-primary`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`}`,title:e===`grouped`?`Group multi-addon packages into a bundle card`:`Show every addon as its own card`,children:e},e))})]}),n.isHub&&C(`div`,{className:`flex items-center gap-1.5`,children:[O(M,{className:`h-3 w-3 text-foreground-subtle`}),O(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Auto-Update:`}),O(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`off`,`latest`,`beta`].map(e=>O(`button`,{type:`button`,onClick:()=>z.mutate({channel:e}),disabled:z.isPending,className:`px-2.5 py-1.5 transition-colors capitalize ${R?.channel===e?e===`off`?`bg-gray-700 text-gray-200`:e===`latest`?`bg-blue-500/20 text-blue-400`:`bg-amber-500/20 text-amber-400`:`bg-transparent text-foreground-subtle hover:bg-surface-hover`} ${e===`off`?``:`border-l border-border`}`,children:e},e))})]}),ne>0&&C(`button`,{type:`button`,onClick:()=>void K(),disabled:H.isPending,className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-blue-500/10 text-blue-400 hover:bg-blue-500/20 border border-blue-500/30 disabled:opacity-50 transition-colors font-medium`,children:[H.isPending?O(P,{className:`w-3 h-3 animate-spin`}):O(j,{className:`w-3 h-3`}),H.isPending?`Updating…`:`Update All (${ne})`]}),C(`button`,{type:`button`,onClick:r,disabled:a||H.isPending,className:`flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,children:[O(M,{className:`w-3 h-3 ${a?`animate-spin`:``}`}),`Refresh`]})]}),C(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[C(`div`,{className:`relative flex-1 min-w-0 sm:min-w-[200px]`,ref:p,children:[O(ue,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),O(`input`,{type:`text`,value:s,onChange:e=>{c(e.target.value),f(!0)},onFocus:()=>f(!0),placeholder:`Search addons on npm...`,disabled:H.isPending,className:`w-full rounded-lg border border-border bg-background pl-9 pr-3 py-2 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-50 disabled:cursor-not-allowed`}),V&&O(P,{className:`absolute right-2.5 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle animate-spin`}),d&&B&&B.length>0&&C(`div`,{className:`absolute left-0 right-0 top-full mt-1 z-40 rounded-lg border border-border bg-surface shadow-xl overflow-hidden`,children:[B.length>0&&C(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[`npm results (`,B.length,`)`]}),B&&B.length>0&&O(`div`,{className:`max-h-72 overflow-auto divide-y divide-border`,children:B.map(e=>C(`div`,{className:`flex items-center gap-3 px-3 py-2 hover:bg-surface-hover transition-colors`,children:[O(`div`,{className:`w-6 h-6 rounded-md bg-primary/10 flex items-center justify-center text-primary text-[9px] font-bold shrink-0`,children:e.name.replace(`@camstack/addon-`,``).charAt(0).toUpperCase()}),C(`div`,{className:`flex-1 min-w-0`,children:[C(`div`,{className:`flex items-baseline gap-2 min-w-0`,children:[O(`span`,{className:`text-[11px] font-semibold break-words`,children:e.name.replace(/^@camstack\/(addon-)?/,``)}),C(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`v`,e.version]})]}),O(`div`,{className:`font-mono text-[9px] text-foreground-subtle/80 truncate`,children:e.name}),e.description&&O(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.description})]}),e.installed?C(`span`,{className:`inline-flex items-center gap-1 px-2 py-1 text-[10px] font-medium rounded-md border border-emerald-500/30 bg-emerald-500/10 text-emerald-400 shrink-0`,children:[O(I,{className:`h-3 w-3`}),e.installedVersion??`Installed`]}):C(`button`,{type:`button`,onClick:()=>q.mutate({packageName:e.name}),disabled:q.isPending,className:`inline-flex items-center gap-1 px-2 py-1 text-[10px] font-medium rounded-md bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors shrink-0`,children:[q.isPending?O(P,{className:`h-3 w-3 animate-spin`}):O(j,{className:`h-3 w-3`}),`Install`]})]},e.name))})]})]}),O(De,{onUploadSuccess:()=>{o.invalidateQueries({queryKey:[[`addons`]]}),r()}})]}),Z&&C(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-primary/10 border border-primary/30 text-sm`,children:[O(`span`,{className:`text-foreground-subtle`,children:`Filtering by capability:`}),O(`span`,{className:`font-mono text-primary font-semibold`,children:Z}),O(`button`,{type:`button`,onClick:Ce,className:`ml-auto text-xs text-foreground-subtle hover:text-foreground underline`,children:`Clear`})]}),he&&C(`div`,{className:`fixed top-4 right-4 z-50 flex items-start gap-2 px-3 py-2.5 rounded-md border border-green-500/30 bg-green-500/10 shadow-lg backdrop-blur-sm max-w-sm pointer-events-auto`,children:[O(L,{className:`w-4 h-4 shrink-0 mt-0.5 text-green-400`}),C(`div`,{children:[O(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`Bulk update completed`}),O(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:`System packages updated — hub restarted successfully.`})]})]}),Se.length===0&&O(`div`,{className:`text-xs text-foreground-subtle`,children:e.length===0?`No addons installed`:Z?`No installed addons declare the "${Z}" capability. Browse the npm catalog above to find a compatible addon.`:`No addons compatible with ${n.name} (placement filter active)`}),O(`div`,{className:`space-y-2`,children:Te.map(e=>{let r=$(e)?e.bundle.packageName:e.manifest.packageName,i=te.get(r),a=$(e)?e.representative:e,o=i?e=>N.mutate({name:r,version:e,nodeId:n.id}):void 0,s=F.get(r)??null,c=s!==null&&Y(s);return O(Ee,{addon:a,clusterStatus:t?.[a.manifest.id],bundle:$(e)?e.bundle:void 0,availableUpdate:i,isUpdating:re.has(r)||c,jobProgress:s,onUpdate:o,disabledByBulk:H.isPending},$(e)?r:e.manifest.id)})})]})}function Pe(){let e=E(),{data:t,isLoading:n,isError:r}=re(),{data:i}=a(void 0),{data:c}=o(void 0,{refetchInterval:1e4}),l=w(()=>{let e=new Map;e.set(`hub`,{id:`hub`,name:`Hub`,isHub:!0});for(let t of c??[]){let n=String(t.id??``);n&&e.set(n,{id:n,name:String(t.name??n),isHub:!!t.isHub})}return[...e.values()]},[c]),[u,ee]=D(`hub`),f=l.find(e=>e.id===u)??l[0],p=d(),m=s(),h=p.isPending||m.isPending,g=async()=>{await p.mutateAsync({nodeId:u}),await m.mutateAsync(),e.invalidateQueries({queryKey:[[`addons`]]})},_=x(p);_.current=p,k(()=>{_.current.mutate({nodeId:`hub`})},[]);let v=(t??[]).map(je).filter(e=>e!==null);return C(W,{children:[C(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[O(ie,{selectedNodeId:u,onSelect:ee}),C(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[!n&&!r&&C(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium`,children:[v.length,` installed`]}),C(`button`,{type:`button`,onClick:()=>void g(),disabled:h,className:`inline-flex items-center gap-1.5 px-2.5 py-1.5 text-[11px] rounded-md bg-surface hover:bg-surface-hover border border-border disabled:opacity-50 transition-colors`,title:`Re-fetch addons + check npm for new versions`,children:[O(M,{className:`w-3 h-3 ${h?`animate-spin`:``}`}),`Check for updates`]})]})]}),!f.isHub&&C(`div`,{className:`rounded-md border border-warning/30 bg-warning/5 px-3 py-2 text-[11px] text-foreground-subtle`,children:[`Showing only addons compatible with`,` `,O(`span`,{className:`font-medium text-foreground`,children:f.name}),` — agents only run`,` `,O(`code`,{className:`font-mono`,children:`agent-only`}),` and`,` `,O(`code`,{className:`font-mono`,children:`any-node`}),` addons. Install / uninstall is hub-driven; agents auto-sync from the hub.`]}),n&&O(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading…`}),r&&O(`div`,{className:`text-xs text-danger`,children:`Failed to load addons`}),!n&&!r&&O(Ne,{addons:v,clusterStatus:i,selectedNode:f,onRefresh:()=>void g(),isRefreshing:h})]})}export{Pe as AddonsPage};
@@ -1 +0,0 @@
1
- import{$a as e,Qa as t,S as n,Sa as r,Xa as i,eo as a,wa as o}from"./src-C9tUE6VN.js";import{Q as s,S as c,W as l,a as u,q as d,t as f,x as p}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 m}from"./player-overlays-G3UGtBzC.js";import{t as h}from"./pencil-B2rRCbs4.js";import{t as g}from"./plus-DIHRelRK.js";import{t as _}from"./send-Cjr4zHvT.js";import{C as v,l as y,m as b,s as x}from"./index-BXAOUGFx.js";import{t as S}from"./AdminPage-BwmGKnRf.js";s();var C=`__redacted__`,w=`ai`,T=[`llm`,`listProfiles`],E=[`llm`,`listProfileKinds`],D=[`llm`,`listRuntimeNodes`],O=[`llm`,`listModelCatalog`],k=[`llm`,`getUsage`];function A(e){return typeof e==`string`&&e.length>0?e:void 0}function j(e){if(typeof e==`number`&&Number.isFinite(e))return e;if(typeof e==`string`&&e.trim()!==``){let t=Number(e);return Number.isFinite(t)?t:void 0}}function M(e){return e===!0}function N(e){return{model:e.model,baseUrl:e.baseUrl,apiKey:e.apiKey,supportsVision:e.supportsVision,temperature:e.temperature,maxTokens:e.maxTokens,timeoutMs:e.timeoutMs,contextSize:e.runtime?.contextSize,gpuLayers:e.runtime?.gpuLayers,threads:e.runtime?.threads,parallel:e.runtime?.parallel,idleStopMinutes:e.runtime?.idleStopMinutes}}function P(e,t,n){return{nodeId:t,engine:`llama-cpp`,model:{kind:`catalog`,catalogId:n},contextSize:j(e.contextSize)??4096,gpuLayers:j(e.gpuLayers)??0,...j(e.threads)===void 0?{}:{threads:j(e.threads)},parallel:j(e.parallel)??1,autoStart:M(e.autoStart),idleStopMinutes:j(e.idleStopMinutes)??30}}function F(e,t,n,r,i){let a={id:n?.id??crypto.randomUUID(),name:t,kind:e,addonId:w,enabled:n?.enabled??!0,model:A(r.model)??n?.model??``,supportsVision:i?.supportsVision??M(r.supportsVision),timeoutMs:j(r.timeoutMs)??6e4},o=A(r.baseUrl),s=A(r.apiKey),c=j(r.temperature),l=j(r.maxTokens);return{...a,...o===void 0?{}:{baseUrl:o},...s===void 0?{}:{apiKey:s},...c===void 0?{}:{temperature:c},...l===void 0?{}:{maxTokens:l},...i===void 0?{}:{model:i.catalogId,runtime:P(r,i.nodeId,i.catalogId)}}}function I(e){let t=new Map;for(let n of e){let e=t.get(n.addonId)??[];e.push(n),t.set(n.addonId,e)}return t}function L(){let e=m(),[t,n]=d(`profiles`),[i,o]=d({mode:`closed`}),[s,l]=d(null),h=u({queryKey:T,queryFn:()=>e.trpcClient.llm.listProfiles.query({})}),_=u({queryKey:E,queryFn:async()=>(await e.trpcClient.llm.listProfileKinds.query({})).map(e=>({...e,configSchema:e.configSchema}))}),v=()=>{h.refetch()},b=f({mutationFn:t=>e.trpcClient.llm.upsertProfile.mutate({profile:t}),onSuccess:()=>{o({mode:`closed`}),v()}}),x=f({mutationFn:t=>e.trpcClient.llm.deleteProfile.mutate({addonId:t.addonId,profileId:t.id}),onSuccess:v}),w=f({mutationFn:t=>e.trpcClient.llm.testProfile.mutate({addonId:t.addonId,profileId:t.id}),onSuccess:(e,t)=>l({id:t.id,ok:e.ok,text:e.ok?`${e.text} (${e.usage.outputTokens} tok, ${e.latencyMs}ms)`:`${e.code}: ${e.message}`})}),D=e=>b.mutate({...e,enabled:!e.enabled,apiKey:C}),O=h.data??[];return c(S,{icon:y,title:`AI`,subtitle:`LLM profiles, managed runtimes and usage`,actions:c(a,{onClick:()=>o({mode:`pick-kind`}),children:[p(g,{className:`h-4 w-4`}),` Add profile`]}),children:[p(`div`,{className:`mb-4 flex gap-2`,children:[`profiles`,`runtimes`,`usage`].map(e=>p(a,{variant:t===e?`primary`:`ghost`,onClick:()=>n(e),children:e[0].toUpperCase()+e.slice(1)},e))}),h.error!=null&&p(r,{message:String(h.error)}),t===`profiles`&&p(R,{profiles:O,testResult:s,onToggle:D,onEdit:e=>{let t=_.data?.find(t=>t.kind===e.kind);t!==void 0&&o({mode:`form`,kind:t,profile:e})},onTest:e=>w.mutate(e),onDelete:e=>x.mutate(e)}),t===`runtimes`&&p(V,{}),t===`usage`&&p(H,{profiles:O}),i.mode===`pick-kind`&&p(z,{kinds:_.data??[],onPick:e=>o({mode:`form`,kind:e,profile:null}),onCancel:()=>o({mode:`closed`})}),i.mode===`form`&&p(B,{kind:i.kind,existing:i.profile,catalog:i.kind.kind===`managed-local`,onSave:e=>b.mutate(e),onCancel:()=>o({mode:`closed`}),saving:b.isPending})]})}function R({profiles:n,testResult:r,onToggle:o,onEdit:s,onTest:l,onDelete:u}){return n.length===0?p(t,{children:p(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`No profiles yet.`})}):p(t,{children:p(`ul`,{className:`divide-y divide-border`,children:n.map(t=>c(`li`,{className:`flex items-center gap-3 p-3`,children:[p(`span`,{className:`text-lg`,children:t.kind===`managed-local`?`🖥️`:`🔌`}),c(`div`,{className:`min-w-0 flex-1`,children:[c(`div`,{className:`flex items-center gap-2`,children:[p(`span`,{className:`truncate font-medium`,children:t.name}),t.kind===`managed-local`&&t.runtime!==void 0&&p(e,{variant:`info`,children:t.runtime.nodeId}),!t.enabled&&p(e,{variant:`warning`,children:`disabled`})]}),c(`p`,{className:`truncate text-xs text-foreground-subtle`,children:[t.kind,` · `,t.model]}),r?.id===t.id&&p(`p`,{className:`text-xs ${r.ok?`text-success`:`text-danger`}`,children:r.text})]}),p(i,{checked:t.enabled,onCheckedChange:()=>o(t)}),p(a,{variant:`ghost`,onClick:()=>l(t),title:`Test`,children:p(_,{className:`h-4 w-4`})}),p(a,{variant:`ghost`,onClick:()=>s(t),title:`Edit`,children:p(h,{className:`h-4 w-4`})}),p(a,{variant:`ghost`,onClick:()=>u(t),title:`Delete`,children:p(x,{className:`h-4 w-4`})})]},t.id))})})}function z({kinds:e,onPick:n,onCancel:r}){let i=l(()=>I(e),[e]);return p(t,{children:c(`div`,{className:`p-4`,children:[p(`h3`,{className:`mb-3 font-medium`,children:`Choose a profile type`}),[...i.entries()].map(([e,t])=>p(`div`,{className:`mb-3`,children:p(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-3`,children:t.map(e=>c(a,{variant:`ghost`,onClick:()=>n(e),children:[p(`span`,{className:`mr-2`,children:e.icon}),e.label]},e.kind))})},e)),p(a,{variant:`ghost`,onClick:r,children:`Cancel`})]})})}function B({kind:e,existing:r,catalog:i,onSave:s,onCancel:l,saving:f}){let h=m(),[g,_]=d(r?.name??``),[y,b]=d(r===null?{}:N(r)),[x,S]=d(r?.runtime?.nodeId??`hub`),[C,w]=d(r?.runtime?.model.kind===`catalog`?r.runtime.model.catalogId:``),T=u({queryKey:O,enabled:i,queryFn:()=>h.trpcClient.llm.listModelCatalog.query({})});return p(t,{children:c(`div`,{className:`space-y-4 p-4`,children:[c(`h3`,{className:`font-medium`,children:[r===null?`New`:`Edit`,` `,e.label]}),c(`label`,{className:`block text-sm`,children:[p(`span`,{className:`text-foreground-subtle`,children:`Name`}),p(`input`,{className:`mt-1 w-full rounded border border-border bg-background px-2 py-1`,value:g,onChange:e=>_(e.target.value)})]}),i&&c(`div`,{className:`space-y-3`,children:[p(o,{selectedNodeId:x,onSelect:S,label:`Runtime node`,alwaysShow:!0}),c(`label`,{className:`block text-sm`,children:[p(`span`,{className:`text-foreground-subtle`,children:`Model`}),c(`select`,{className:`mt-1 w-full rounded border border-border bg-background px-2 py-1`,value:C,onChange:e=>w(e.target.value),children:[p(`option`,{value:``,children:`Select a model…`}),(T.data??[]).map(e=>c(`option`,{value:e.id,children:[e.label,` · `,e.quantization,` ·`,` `,(e.sizeBytes/1e9).toFixed(1),` GB`]},e.id))]})]})]}),p(n,{schema:e.configSchema,values:y,onChange:b}),c(`div`,{className:`flex gap-2`,children:[c(a,{onClick:()=>{if(i){let t=T.data?.find(e=>e.id===C);s(F(e.kind,g,r,y,{nodeId:x,catalogId:C,supportsVision:t?.purpose===`vision`}))}else s(F(e.kind,g,r,y))},disabled:f||g.trim()===``||i&&C===``,children:[f&&p(v,{className:`h-4 w-4 animate-spin`}),` Save`]}),p(a,{variant:`ghost`,onClick:l,children:`Cancel`})]})]})})}function V(){let n=m(),r=u({queryKey:D,refetchInterval:5e3,queryFn:()=>n.trpcClient.llm.listRuntimeNodes.query({})}).data??[];return r.length===0?p(t,{children:p(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`No runtime nodes advertise the llm-runtime capability.`})}):p(t,{children:p(`ul`,{className:`divide-y divide-border`,children:r.map(t=>c(`li`,{className:`flex items-center gap-3 p-3`,children:[p(b,{className:`h-4 w-4 text-foreground-subtle`}),c(`div`,{className:`min-w-0 flex-1`,children:[c(`div`,{className:`flex items-center gap-2`,children:[p(`span`,{className:`font-medium`,children:t.nodeId}),p(e,{variant:t.reachable?`success`:`danger`,children:t.reachable?t.status?.state??`ready`:`unreachable`}),t.status?.downloadProgress!==void 0&&c(e,{variant:`info`,children:[Math.round(t.status.downloadProgress*100),`%`]})]}),c(`p`,{className:`truncate text-xs text-foreground-subtle`,children:[t.status?.modelId??`—`,t.disk!==void 0&&` · ${(t.disk.modelsBytes/1e9).toFixed(1)} GB on disk`,t.error!==void 0&&` · ${t.error}`]})]})]},t.nodeId))})})}function H({profiles:e}){let n=m(),r=l(()=>Date.now()-10080*60*1e3,[]),i=u({queryKey:[...k,r],queryFn:()=>n.trpcClient.llm.getUsage.query({since:r})}),a=t=>e.find(e=>e.id===t)?.name??t,o=i.data??[];return o.length===0?p(t,{children:p(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`No usage in the last 7 days.`})}):p(t,{children:p(`div`,{className:`overflow-x-auto`,children:c(`table`,{className:`w-full text-sm`,children:[p(`thead`,{children:c(`tr`,{className:`text-left text-foreground-subtle`,children:[p(`th`,{className:`p-2`,children:`Day`}),p(`th`,{className:`p-2`,children:`Consumer`}),p(`th`,{className:`p-2`,children:`Profile`}),p(`th`,{className:`p-2`,children:`Calls`}),p(`th`,{className:`p-2`,children:`OK/Err`}),p(`th`,{className:`p-2`,children:`In/Out tok`}),p(`th`,{className:`p-2`,children:`Avg ms`})]})}),p(`tbody`,{children:o.map(e=>c(`tr`,{className:`border-t border-border`,children:[p(`td`,{className:`p-2`,children:e.day}),p(`td`,{className:`p-2`,children:e.consumer}),p(`td`,{className:`p-2`,children:a(e.profileId)}),p(`td`,{className:`p-2`,children:e.calls}),c(`td`,{className:`p-2`,children:[e.okCalls,`/`,e.errorCalls]}),c(`td`,{className:`p-2`,children:[e.inputTokens,`/`,e.outputTokens]}),p(`td`,{className:`p-2`,children:Math.round(e.avgLatencyMs)})]},`${e.day}|${e.consumer}|${e.profileId}`))})]})})})}export{L as AiProfilesPage};
@@ -1 +0,0 @@
1
- import{Ba as e,Dr as t,Ea as n,Er as r,Fr as i,Ha as a,Ir as o,Lr as s,Nr as c,Oa as l,Pr as u,Rr as d,Si as f,Ua as p,Va as m,g as h,m as g,si as _,xa as v,zr as y}from"./src-C9tUE6VN.js";import{I as b,K as x,Q as S,S as C,W as w,o as T,q as E,x as D,z as O}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{p as k}from"./player-overlays-G3UGtBzC.js";import{t as A}from"./pencil-B2rRCbs4.js";import{t as j}from"./radio-D3U_70dZ.js";import{t as M}from"./refresh-cw-NUBl_9F6.js";import{t as N}from"./rotate-cw-CWQEKQOp.js";import{t as P}from"./upload-DY7S1CIX.js";import{B as F,C as I,I as L,L as R,P as ee,W as z,h as B,i as V,j as H,m as U,o as W,s as G}from"./index-BXAOUGFx.js";import{n as K,t as q}from"./build-cluster-graph-CWEgvPHm.js";import{t as J}from"./format-size-CO9d3C3-.js";import{t as Y}from"./NodeAddonsSettingsPanel-CJbUr7pj.js";var X=z(`git-fork`,[[`circle`,{cx:`12`,cy:`18`,r:`3`,key:`1mpf1b`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`path`,{d:`M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9`,key:`1uq4wg`}],[`path`,{d:`M12 12v3`,key:`158kv8`}]]),Z=z(`memory-stick`,[[`path`,{d:`M6 19v-3`,key:`1nvgqn`}],[`path`,{d:`M10 19v-3`,key:`iu8nkm`}],[`path`,{d:`M14 19v-3`,key:`kcehxu`}],[`path`,{d:`M18 19v-3`,key:`1vh91z`}],[`path`,{d:`M8 11V9`,key:`63erz4`}],[`path`,{d:`M16 11V9`,key:`fru6f3`}],[`path`,{d:`M12 11V9`,key:`ha00sb`}],[`path`,{d:`M2 15h20`,key:`16ne18`}],[`path`,{d:`M2 7a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v1.1a2 2 0 0 0 0 3.837V17a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-5.1a2 2 0 0 0 0-3.837Z`,key:`lhddv3`}]]),Q=z(`skull`,[[`path`,{d:`m12.5 17-.5-1-.5 1h1z`,key:`3me087`}],[`path`,{d:`M15 22a1 1 0 0 0 1-1v-1a2 2 0 0 0 1.56-3.25 8 8 0 1 0-11.12 0A2 2 0 0 0 8 20v1a1 1 0 0 0 1 1z`,key:`1o5pge`}],[`circle`,{cx:`15`,cy:`12`,r:`1`,key:`1tmaij`}],[`circle`,{cx:`9`,cy:`12`,r:`1`,key:`1vctgf`}]]),te=z(`table-2`,[[`path`,{d:`M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18`,key:`gugj83`}]]);S();function $(e){let t=new FormData;return t.append(`file`,e.file,e.file.name),t.append(`nodeId`,e.nodeId),e.addonId&&t.append(`addonId`,e.addonId),new Promise((n,r)=>{let i=new XMLHttpRequest;i.open(`POST`,`/api/addons/upload`),e.token&&i.setRequestHeader(`Authorization`,`Bearer ${e.token}`),i.upload.addEventListener(`progress`,t=>{t.lengthComputable&&e.onProgress(Math.round(t.loaded/t.total*100))}),i.addEventListener(`load`,()=>{let e;try{e=JSON.parse(i.responseText)}catch{r(Error(`HTTP ${i.status}`));return}i.status>=200&&i.status<300?n(e):r(Error(e.error??`HTTP ${i.status}`))}),i.addEventListener(`error`,()=>r(Error(`Network error during upload`))),i.addEventListener(`abort`,()=>r(Error(`Upload aborted`))),i.send(t)})}function ne({nodeId:e,addons:t,isHub:n}){let r=T(),a=v(),[o,s]=E(null),[l,u]=E(null),[d,f]=E(!1),[p,m]=E(null),[h,g]=E(0),_=x(null),b=i(),S=y(),w=c({nodeId:e}),O=w.data??[],k=new Map(t.map(e=>[e.id,e.capabilities])),A=O.length>0?O.map(e=>({id:e.id,status:e.status,capabilities:k.get(e.id)??[],version:e.version,packageName:e.packageName})):t.map(e=>({id:e.id,status:e.status,capabilities:e.capabilities,version:void 0,packageName:void 0})),j=()=>{r.invalidateQueries({queryKey:[[`nodes`,`topology`]]}),w.refetch()},M=async t=>{s(t);try{await b.mutateAsync({nodeId:e,addonId:t}),j()}catch(e){console.error(`Failed to restart addon:`,e)}finally{s(null)}},F=async t=>{if(await a({title:`Uninstall addon`,message:`Remove "${t}" from ${e}? The addon directory will be deleted on disk.`,confirmLabel:`Uninstall`,variant:`danger`})){u(t);try{await S.mutateAsync({nodeId:e,addonId:t}),j()}catch(e){console.error(`Failed to uninstall addon:`,e)}finally{u(null)}}},L=C(`div`,{className:`flex items-center gap-2 mb-2`,children:[D(`input`,{ref:_,type:`file`,accept:`.tgz,.tar.gz`,className:`hidden`,onChange:async t=>{let n=t.target.files?.[0];if(n){t.target.value=``,m(null),f(!0),g(0);try{await $({file:n,nodeId:e,token:localStorage.getItem(`camstack_admin_token`),onProgress:g}),j()}catch(e){m(e instanceof Error?e.message:String(e))}finally{f(!1),g(0)}}}}),C(`button`,{onClick:()=>_.current?.click(),disabled:d,className:`inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1 text-[11px] font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[d?D(I,{className:`h-3 w-3 animate-spin`}):D(P,{className:`h-3 w-3`}),d?`Uploading… ${h}%`:`Upload addon (.tgz)`]}),d&&D(`div`,{className:`flex-1 h-1 rounded-full bg-muted overflow-hidden max-w-[140px]`,children:D(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${h}%`}})}),p&&D(`span`,{className:`text-[10px] text-destructive`,children:p})]});return A.length===0?C(`div`,{children:[L,D(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:w.isLoading?`Loading addons…`:`No addons on this node`})]}):C(`div`,{children:[L,C(`table`,{className:`w-full text-xs`,children:[D(`thead`,{children:C(`tr`,{className:`text-muted-foreground text-left`,children:[D(`th`,{className:`py-2 font-medium`,children:`Addon`}),D(`th`,{className:`py-2 font-medium`,children:`Version`}),D(`th`,{className:`py-2 font-medium`,children:`Capabilities`}),D(`th`,{className:`py-2 font-medium`,children:`Status`}),D(`th`,{className:`py-2 font-medium w-16`})]})}),D(`tbody`,{children:A.map(e=>C(`tr`,{className:`border-t border-border/50`,children:[C(`td`,{className:`py-2 font-medium`,children:[D(`div`,{children:e.id}),e.packageName&&D(`div`,{className:`text-[9px] text-muted-foreground`,children:e.packageName})]}),D(`td`,{className:`py-2 text-muted-foreground`,children:e.version??`—`}),D(`td`,{className:`py-2`,children:D(`div`,{className:`flex flex-wrap gap-1`,children:e.capabilities.length>0?e.capabilities.map(e=>D(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400`,children:e},e)):D(`span`,{className:`text-muted-foreground`,children:`—`})})}),D(`td`,{className:`py-2`,children:D(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e.status===`running`?`bg-success/10 text-success`:e.status===`error`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e.status})}),D(`td`,{className:`py-2`,children:C(`div`,{className:`flex items-center gap-1 justify-end`,children:[D(`button`,{onClick:()=>M(e.id),disabled:o===e.id||l===e.id,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.id}`,children:D(N,{className:`h-3 w-3 ${o===e.id?`animate-spin`:``}`})}),D(`button`,{onClick:()=>F(e.id),disabled:o===e.id||l===e.id,className:`p-1 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50`,title:`Uninstall ${e.id}`,children:l===e.id?D(I,{className:`h-3 w-3 animate-spin`}):D(G,{className:`h-3 w-3`})})]})})]},e.id))})]})]})}S();function re(e){if(e<60)return`${e}s`;let t=Math.floor(e/60);if(t<60)return`${t}m`;let n=Math.floor(t/60);return n<24?`${n}h ${t%60}m`:`${Math.floor(n/24)}d ${n%24}h`}function ie({state:e}){return D(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full ${e===`running`?`bg-success/10 text-success`:e===`crashed`||e===`failed`?`bg-destructive/10 text-destructive`:`bg-muted text-muted-foreground`}`,children:e})}var ae=[`trace`,`debug`,`info`,`warn`,`error`];function oe({proc:t,nodeId:n,defaultExpanded:r,activePanel:c,onTogglePanel:l}){let u=t.services??[],d=u.length===1,[f,_]=E(d||r),[v,y]=E(null),[b,x]=E(`info`),S=t.name.includes(`(core)`),w=i(),T=o(),O=s(),k=async e=>{y(e);try{await w.mutateAsync({nodeId:n,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{y(null)}},A=async()=>{y(t.name);try{await T.mutateAsync({nodeId:n,processName:t.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{y(null)}},M=async e=>{let r=`${n}/${t.name}`;try{await O.mutateAsync({nodeId:r,level:e}),x(e)}catch(e){console.error(`Failed to set log level:`,e)}};return C(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[C(`div`,{role:d?void 0:`button`,tabIndex:d?void 0:0,onClick:d?void 0:()=>_(!f),onKeyDown:d?void 0:e=>{(e.key===`Enter`||e.key===` `)&&_(!f)},className:`flex items-center gap-2 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${d?``:`hover:bg-muted/40 cursor-pointer`}`,children:[d?D(`span`,{className:`h-3 w-3 shrink-0`}):D(f?L:ee,{className:`h-3 w-3 text-muted-foreground shrink-0`}),S?D(U,{className:`h-3.5 w-3.5 text-primary shrink-0`}):D(F,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),D(`span`,{className:`text-xs font-semibold flex-1`,children:t.name}),C(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[`PID `,t.pid]}),D(ie,{state:t.state}),C(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[t.cpuPercent,`% CPU`]}),D(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:J(t.memoryRss)}),D(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:re(t.uptimeSeconds)}),!S&&C(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[C(e,{children:[D(p,{className:`text-[9px] px-1.5 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors font-mono`,title:`Set log level`,children:b}),D(m,{align:`end`,className:`min-w-[70px] py-0.5`,children:ae.map(e=>D(a,{onClick:()=>M(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===b?`text-primary font-semibold`:``}`,children:e},e))})]}),D(`button`,{onClick:A,disabled:v===t.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart process`,children:D(N,{className:`h-3 w-3 ${v===t.name?`animate-spin`:``}`})})]})]}),f&&u.length>0&&D(`div`,{className:`divide-y divide-border/30`,children:u.map(e=>C(`div`,{children:[C(`div`,{className:`flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors`,children:[D(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`running`?`bg-success`:`bg-muted-foreground/30`}`}),D(`span`,{className:`text-xs font-medium flex-1 min-w-0 truncate`,children:e.addonId}),e.capabilities.length>0&&C(`div`,{className:`flex gap-1 flex-shrink-0`,children:[e.capabilities.slice(0,3).map(e=>D(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400 truncate max-w-[80px]`,children:e},e)),e.capabilities.length>3&&C(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,e.capabilities.length-3]})]}),C(`div`,{className:`flex items-center gap-1 shrink-0`,children:[D(`button`,{onClick:()=>l(e.addonId,`logs`),className:`p-0.5 rounded transition-colors ${c?.addonId===e.addonId&&c.type===`logs`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show logs for ${e.addonId}`,children:D(B,{className:`h-3 w-3`})}),D(`button`,{onClick:()=>l(e.addonId,`events`),className:`p-0.5 rounded transition-colors ${c?.addonId===e.addonId&&c.type===`events`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show events for ${e.addonId}`,children:D(j,{className:`h-3 w-3`})}),D(`button`,{onClick:()=>k(e.addonId),disabled:v===e.addonId,className:`p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.addonId}`,children:D(N,{className:`h-3 w-3 ${v===e.addonId?`animate-spin`:``}`})})]})]}),c?.addonId===e.addonId&&c.type===`logs`&&D(`div`,{className:`border-t border-border/40 bg-muted/5`,children:D(h,{addonId:e.addonId,agentId:n,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>l(e.addonId,`logs`)})}),c?.addonId===e.addonId&&c.type===`events`&&D(`div`,{className:`border-t border-border/40 bg-muted/5`,children:D(g,{addonId:e.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>l(e.addonId,`events`)})})]},e.addonId))}),f&&u.length===0&&D(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:`No services`})]})}function se({nodeId:e,processes:t}){let[n,r]=E(null),i=(e,t)=>{r(n=>n?.addonId===e&&n.type===t?null:{addonId:e,type:t})};return t.length===0?D(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No processes on this node`}):D(`div`,{className:`space-y-2 py-1`,children:t.map((t,r)=>D(oe,{proc:t,nodeId:e,defaultExpanded:r===0,activePanel:n,onTogglePanel:i},t.name))})}S();function ce(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m ${e%60}s`:e<86400?`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`:`${Math.floor(e/86400)}d ${Math.floor(e%86400/3600)}h`}function le(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function ue({nodeId:e}){let i=T(),a=v(),[o,s]=E(`all`),c=n(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:l}=t({nodeId:e}),u=c?.processes??l,d=w(()=>u?[...u]:[],[u]),f=w(()=>o===`ghost`?d.filter(e=>e.classification===`ghost`):d,[d,o]),p=w(()=>{let e=d.filter(e=>e.classification===`ghost`),t=new Map;for(let n of e)t.has(n.ppid)||t.set(n.ppid,[]),t.get(n.ppid).push(n);return[...t.entries()].filter(([,e])=>e.length>1).map(([e,t])=>({ppid:e,children:t})).toSorted((e,t)=>t.children.length-e.children.length)},[d]),m=r({onSettled:()=>{i.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]})}}),h=w(()=>{let e=new Map;for(let t of d)e.set(t.pid,t.classification);return e},[d]),g=async(t,n)=>{if(t.classification===`root`||t.classification===`system`)return;let r=t.classification===`ghost`?`ghost`:t.addonId??`process`,i=n?`SIGKILL`:`SIGTERM`;await a({title:`Send ${i}?`,message:`Target pid ${t.pid} (${r}) on node ${e}.`,confirmLabel:`Send ${i}`,variant:`danger`})&&m.mutate({nodeId:e,pid:t.pid,force:n})},_=async(t,n)=>{try{await m.mutateAsync({nodeId:e,pid:t,force:n})}catch{}},y=async t=>{let n=h.get(t.ppid);if(n===`root`||n===`system`){await a({title:`Cannot kill protected ancestor`,message:n===`root`?`pid ${t.ppid} is the current node supervisor. Restart the node via the cluster page instead.`:`pid ${t.ppid} is a system ancestor (concurrently / vite / npm wrapper). Killing it would tear down the dev tree.`,confirmLabel:`OK`,cancelLabel:`Close`,variant:`warning`});return}await a({title:`Kill ghost parent + ${t.children.length} child(ren)?`,message:`SIGKILL parent pid ${t.ppid} and SIGTERM ${t.children.length} ghost child(ren) on node ${e}.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all([_(t.ppid,!0),...t.children.map(e=>_(e.pid,!1))]),i.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},b=async()=>{let t=d.filter(e=>e.classification===`ghost`);t.length!==0&&await a({title:`Kill all ${t.length} ghost process(es)?`,message:`SIGKILL ${t.length} ghost process(es) on node ${e}. This is irreversible.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all(t.map(e=>_(e.pid,!0))),i.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},x=d.filter(e=>e.classification===`ghost`).length,S=d.filter(e=>e.classification===`managed`).length,O=d.filter(e=>e.classification===`root`).length,k=d.filter(e=>e.classification===`system`).length;return C(`div`,{className:`space-y-4`,children:[C(`div`,{className:`flex items-start justify-between gap-4`,children:[C(`p`,{className:`text-[11px] text-foreground-subtle`,children:[`ps`," scan + kernel `$process.list` cross-reference. Ghosts = camstack-shaped commands with no managed binding (usually orphaned to ppid=1). Refreshes every 10s."]}),C(`button`,{type:`button`,onClick:()=>i.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}),className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-[11px] text-foreground hover:bg-surface-hover`,children:[D(M,{className:`h-3 w-3`}),` Refresh`]})]}),C(`div`,{className:`grid grid-cols-4 gap-3`,children:[C(`div`,{className:`rounded-lg border border-border p-3`,children:[D(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Root`}),D(`div`,{className:`text-xl font-semibold text-foreground`,children:O})]}),C(`div`,{className:`rounded-lg border border-border p-3`,children:[D(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Managed`}),D(`div`,{className:`text-xl font-semibold text-foreground`,children:S})]}),C(`div`,{className:`rounded-lg border border-border p-3`,children:[D(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`System`}),D(`div`,{className:`text-xl font-semibold text-foreground`,children:k})]}),C(`div`,{className:`rounded-lg border p-3 ${x>0?`border-destructive/40 bg-destructive/5`:`border-border`}`,children:[C(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle flex items-center gap-1`,children:[x>0&&D(Q,{className:`h-3 w-3 text-destructive`}),` Ghosts`]}),D(`div`,{className:`text-xl font-semibold ${x>0?`text-destructive`:`text-foreground`}`,children:x})]})]}),p.length>0&&C(`div`,{className:`rounded-lg border border-amber-500/40 bg-amber-500/5 p-3`,children:[C(`div`,{className:`flex items-center gap-1 text-[11px] font-semibold text-amber-400 mb-2`,children:[D(W,{className:`h-3 w-3`}),` Recurring ghost parents (`,p.length,`)`]}),D(`div`,{className:`space-y-1.5`,children:p.map(e=>C(`div`,{className:`text-[11px] text-foreground flex items-center justify-between gap-2`,children:[C(`div`,{className:`flex items-center gap-2`,children:[C(`span`,{className:`font-mono text-foreground-subtle`,children:[`ppid `,e.ppid]}),C(`span`,{children:[`→ `,e.children.length,` ghost(s)`]})]}),C(`button`,{type:`button`,disabled:m.isPending,onClick:()=>{y(e)},className:`inline-flex items-center gap-1 rounded border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 text-[10px] text-amber-400 hover:bg-amber-500/20 disabled:opacity-30`,children:[D(Q,{className:`h-3 w-3`}),` Kill parent + `,e.children.length]})]},e.ppid))})]}),C(`div`,{className:`flex items-center justify-between gap-2 text-[11px]`,children:[C(`div`,{className:`flex items-center gap-2`,children:[D(`span`,{className:`text-foreground-subtle`,children:`Filter:`}),C(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${o===`all`?`bg-primary text-primary-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>s(`all`),children:[`All (`,d.length,`)`]}),C(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${o===`ghost`?`bg-destructive text-destructive-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>s(`ghost`),children:[`Ghost only (`,x,`)`]})]}),x>0&&C(`button`,{type:`button`,disabled:m.isPending,onClick:()=>{b()},className:`inline-flex items-center gap-1 rounded border border-destructive/40 bg-destructive/10 px-2 py-1 text-[11px] font-medium text-destructive hover:bg-destructive/20 disabled:opacity-30`,children:[D(Q,{className:`h-3 w-3`}),` Kill all `,x,` ghost(s)`]})]}),D(`div`,{className:`rounded-lg border border-border overflow-x-auto`,children:C(`table`,{className:`w-full text-xs`,children:[D(`thead`,{className:`bg-surface`,children:C(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[D(`th`,{className:`text-left px-3 py-2`,children:`Class`}),D(`th`,{className:`text-right px-3 py-2`,children:`PID`}),D(`th`,{className:`text-right px-3 py-2`,children:`PPID`}),D(`th`,{className:`text-left px-3 py-2`,children:`Addon`}),D(`th`,{className:`text-left px-3 py-2`,children:`Command`}),D(`th`,{className:`text-right px-3 py-2`,children:`CPU%`}),D(`th`,{className:`text-right px-3 py-2`,children:`RSS`}),D(`th`,{className:`text-right px-3 py-2`,children:`Uptime`}),D(`th`,{className:`w-44`})]})}),C(`tbody`,{children:[f.length===0&&D(`tr`,{children:D(`td`,{colSpan:9,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:o===`ghost`?`No ghost processes detected.`:`Scanning…`})}),f.map(e=>C(`tr`,{className:`border-t border-border ${e.classification===`ghost`?`bg-destructive/5`:``}`,children:[D(`td`,{className:`px-3 py-2`,children:D(`span`,{className:`inline-block rounded-full px-1.5 py-0.5 text-[10px] font-medium ${e.classification===`ghost`?`bg-destructive/20 text-destructive`:e.classification===`root`?`bg-sky-500/20 text-sky-400`:e.classification===`system`?`bg-foreground-subtle/20 text-foreground-subtle`:`bg-success/20 text-success`}`,children:e.classification})}),D(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.pid}),C(`td`,{className:`px-3 py-2 text-right font-mono text-foreground-subtle`,children:[e.ppid,e.orphaned?` ⚠`:``]}),D(`td`,{className:`px-3 py-2 text-foreground-subtle text-[11px]`,children:e.addonId??`—`}),D(`td`,{className:`px-3 py-2 font-mono text-[10px] text-foreground-subtle break-all`,children:le(e.command)}),D(`td`,{className:`px-3 py-2 text-right text-foreground`,children:e.cpuPercent.toFixed(1)}),D(`td`,{className:`px-3 py-2 text-right text-foreground`,children:J(e.memoryRssBytes)}),D(`td`,{className:`px-3 py-2 text-right text-foreground-subtle`,children:ce(e.uptimeSec)}),D(`td`,{className:`px-3 py-2 text-right`,children:C(`div`,{className:`inline-flex gap-1`,children:[C(`button`,{type:`button`,disabled:m.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{g(e,!1)},title:`SIGTERM`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-border text-[10px] text-foreground hover:bg-surface-hover disabled:opacity-30`,children:[D(G,{className:`h-3 w-3`}),` Term`]}),C(`button`,{type:`button`,disabled:m.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{g(e,!0)},title:`SIGKILL`,className:`inline-flex items-center gap-1 px-1.5 py-0.5 rounded border border-destructive/30 text-[10px] text-destructive hover:bg-destructive/10 disabled:opacity-30`,children:[D(Q,{className:`h-3 w-3`}),` Kill`]})]})})]},e.pid))]})]})}),m.isError&&C(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,m.error instanceof Error?m.error.message:`unknown`]})]})}function de({nodeId:e,addonIds:t}){return t.length===0?D(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No addons on this node`}):D(`div`,{className:`w-full py-2`,children:D(Y,{nodeId:e,addonIds:t,level:`global`})})}S();function fe({nodeId:e,addons:t}){let n=T(),{data:r,isLoading:i}=_({nodeId:e}),a=w(()=>{let e=new Map;for(let n of t)for(let t of n.capabilities){let r=e.get(t)??[];r.push(n.id),e.set(t,r)}return[...e.entries()].toSorted(([e],[t])=>e.localeCompare(t)).map(([e,t])=>({capName:e,providers:t}))},[t]),o=f({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCapabilityBindings`]]})}});return a.length===0?D(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No capabilities on this node`}):C(`table`,{className:`w-full text-xs`,children:[D(`thead`,{children:C(`tr`,{className:`text-muted-foreground text-left`,children:[D(`th`,{className:`py-2 font-medium w-1/2`,children:`Capability`}),D(`th`,{className:`py-2 font-medium`,children:`Bound provider`})]})}),D(`tbody`,{children:a.map(({capName:t,providers:n})=>{let a=r?.[t]??n[0]??``,s=n.length===1;return C(`tr`,{className:`border-t border-border/50`,children:[D(`td`,{className:`py-2 font-medium`,children:t}),D(`td`,{className:`py-2`,children:D(`select`,{value:a,onChange:n=>o.mutate({nodeId:e,capName:t,addonId:n.target.value}),disabled:s||o.isPending||i,className:`w-full rounded-md border border-border bg-surface px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary disabled:opacity-60`,title:s?`Only one provider installed — choice becomes available once a second addon registers this capability`:void 0,children:n.map(e=>D(`option`,{value:e,children:e},e))})})]},t)})})]})}S();function pe(e){if(e==null)return`—`;let t=Math.floor(e/1e3),n=Math.floor(t/86400),r=Math.floor(t%86400/3600),i=Math.floor(t%3600/60);return n>0?`${n}d ${r}h ${i}m`:r>0?`${r}h ${i}m`:`${i}m`}function me(e){let[t,n]=E(!1),[r,i]=E(e.name),a=T(),o=u({onSuccess:()=>{a.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}}),s=(e.localIps??[]).filter(e=>!e.includes(`:`)),c=(e.localIps??[]).filter(e=>e.includes(`:`)),l=async()=>{if(!r.trim()||r===e.name){n(!1);return}try{await o.mutateAsync({nodeId:e.nodeId,name:r.trim()}),n(!1)}catch(e){console.error(`Rename failed:`,e)}},d=[[`Node ID`,D(`span`,{className:`font-mono text-xs`,children:e.nodeId})],[`Display Name`,t?C(`div`,{className:`flex items-center gap-1.5`,children:[D(`input`,{type:`text`,className:`flex-1 px-2 py-0.5 text-xs border border-border rounded bg-background focus:outline-none focus:ring-1 focus:ring-primary`,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&l(),e.key===`Escape`&&n(!1)},disabled:o.isPending,autoFocus:!0}),D(`button`,{onClick:()=>void l(),disabled:o.isPending,className:`p-0.5 text-success hover:bg-success/10 rounded`,title:`Save`,children:D(R,{className:`h-3.5 w-3.5`})}),D(`button`,{onClick:()=>n(!1),className:`p-0.5 text-muted-foreground hover:bg-muted rounded`,title:`Cancel`,children:D(V,{className:`h-3.5 w-3.5`})})]}):C(`div`,{className:`flex items-center gap-1.5`,children:[D(`span`,{className:`text-xs`,children:e.name}),!e.isHub&&D(`button`,{onClick:()=>{i(e.name),n(!0)},className:`p-0.5 text-muted-foreground hover:text-primary rounded`,title:`Rename`,children:D(A,{className:`h-3 w-3`})})]})],[`Hostname`,D(`span`,{className:`text-xs`,children:e.hostname})],[`Role`,e.isHub?D(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary font-medium`,children:`Hub`}):D(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium`,children:`Agent`})],[`Root Package`,e.rootPackage?C(`span`,{className:`font-mono text-xs`,children:[e.rootPackage.name,`@`,e.rootPackage.version]}):D(`span`,{className:`text-xs text-muted-foreground`,children:`—`})],[`Platform`,C(`span`,{className:`text-xs`,children:[e.platform,` / `,e.arch]})],[`CPU`,C(`span`,{className:`text-xs`,children:[e.cpuModel??`—`,` (`,e.cpuCores,` cores)`]})],[`Memory`,D(`span`,{className:`text-xs`,children:e.memoryMB>0?`${(e.memoryMB/1024).toFixed(1)} GB`:`—`})],[`Uptime`,D(`span`,{className:`text-xs`,children:pe(e.uptime)})],[`Engines`,e.engines.length>0?D(`div`,{className:`flex flex-wrap gap-1`,children:e.engines.map(e=>D(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e))}):D(`span`,{className:`text-xs text-muted-foreground`,children:`—`})]];return s.length>0&&d.push([`IPv4`,D(`div`,{className:`flex flex-wrap gap-1.5`,children:s.map((e,t)=>D(`span`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted`,children:e},`${e}-${t}`))})]),c.length>0&&d.push([`IPv6`,D(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map((e,t)=>D(`span`,{className:`font-mono text-[10px] px-1.5 py-0.5 rounded bg-muted truncate max-w-[280px]`,title:e,children:e},`${e}-${t}`))})]),D(`div`,{className:`py-2`,children:D(`table`,{className:`w-full text-sm`,children:D(`tbody`,{children:d.map(([e,t],n)=>C(`tr`,{className:n%2==0?`bg-muted/20`:``,children:[D(`td`,{className:`py-1.5 px-2 text-xs font-medium text-muted-foreground w-28 align-top whitespace-nowrap`,children:e}),D(`td`,{className:`py-1.5 px-2`,children:t})]},e))})})})}S();function he({node:e}){let t=k(),[n,r]=E(`info`),[i,a]=E(!1),o=e.processes??[],s=e.addons.map(e=>e.id),c=async()=>{if(!i){a(!0);try{await Promise.allSettled([t.trpcClient.pipelineOrchestrator.removeAgentSettings.mutate({agentNodeId:e.id}),t.trpcClient.clusterNodes.forgetNode.mutate({nodeId:e.id})])}finally{a(!1)}}};return e.isOnline?C(`div`,{className:`border border-border rounded-xl overflow-hidden`,children:[C(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30 border-b border-border`,children:[D(`div`,{className:`w-2.5 h-2.5 rounded-full bg-success`}),D(`span`,{className:`text-sm font-semibold`,children:e.name}),C(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>D(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),C(`div`,{className:`ml-auto flex gap-3 text-xs text-muted-foreground`,children:[C(`span`,{className:`flex items-center gap-1`,children:[D(H,{className:`h-3 w-3`}),` `,e.cpuPercent,`%`]}),C(`span`,{className:`flex items-center gap-1`,children:[D(Z,{className:`h-3 w-3`}),` `,e.memoryPercent,`%`]})]})]}),D(`div`,{className:`flex border-b border-border px-4`,children:[`info`,`addons`,`forks`,`processes`,`settings`,`capabilities`].map(t=>D(`button`,{onClick:()=>r(t),className:`px-3 py-2 text-xs font-medium border-b-2 transition-colors ${n===t?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:t===`info`?`Info`:t===`addons`?`Addons (${e.addons.length})`:t===`forks`?`Forks (${o.length})`:t===`processes`?`Processes`:t===`settings`?`Settings`:`Capabilities`},t))}),C(`div`,{className:`px-4 py-2`,children:[n===`info`&&D(me,{nodeId:e.id,name:e.name,hostname:e.hostname,platform:e.platform,arch:e.arch,cpuModel:e.cpuModel,cpuCores:e.cpuCores,memoryMB:e.memoryMB,engines:e.engines,isHub:e.isHub,uptime:e.uptime,localIps:e.localIps,rootPackage:e.rootPackage}),n===`addons`&&D(ne,{nodeId:e.id,addons:e.addons,isHub:e.isHub}),n===`forks`&&D(se,{nodeId:e.id,processes:o}),n===`processes`&&D(ue,{nodeId:e.id}),n===`settings`&&D(de,{nodeId:e.id,addonIds:s}),n===`capabilities`&&D(fe,{nodeId:e.id,addons:e.addons})]})]}):C(`div`,{className:`border border-border rounded-xl overflow-hidden opacity-60`,children:[C(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30`,children:[D(`div`,{className:`w-2.5 h-2.5 rounded-full bg-destructive`}),D(`span`,{className:`text-sm font-semibold`,children:e.name}),C(`span`,{className:`text-xs text-muted-foreground`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?`${Math.round(e.memoryMB/1024)}GB`:``,` · `,e.arch]}),e.engines.map(e=>D(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),D(`span`,{className:`ml-auto text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`})]}),C(`div`,{className:`flex items-center justify-between gap-3 px-4 py-3`,children:[C(`span`,{className:`text-xs text-muted-foreground`,children:[e.lastSeen?`Last seen ${new Date(e.lastSeen).toLocaleString()} — `:``,e.addons.length,` addon`,e.addons.length===1?``:`s`,` assigned; will resume when node reconnects`]}),C(`button`,{type:`button`,onClick:()=>void c(),disabled:i,title:`Forget this node — removes its saved history and pipeline assignments`,className:`flex items-center gap-1 text-xs px-2 py-1 rounded-md border border-border text-muted-foreground hover:text-destructive hover:border-destructive/50 disabled:opacity-50 transition-colors`,children:[D(G,{className:`h-3 w-3`}),i?`Forgetting…`:`Forget node`]})]})]})}S();function ge({nodes:e,focusNodeId:t,focusNonce:n}){let r=[...e].toSorted((e,t)=>e.isHub?-1:t.isHub?1:e.isOnline&&!t.isOnline?-1:!e.isOnline&&t.isOnline?1:e.name.localeCompare(t.name)),i=x(null);return O(()=>{if(!t)return;let e=i.current?.querySelector(`#node-card-${CSS.escape(t)}`);e&&e.scrollIntoView({behavior:`smooth`,block:`start`})},[t,n]),D(`div`,{ref:i,className:`flex flex-col gap-4`,children:r.map(e=>D(`div`,{id:`node-card-${e.id}`,children:D(he,{node:e})},e.id))})}S();function _e(e){let[t,n]=E(()=>typeof window<`u`?window.matchMedia(e).matches:!1);return O(()=>{let t=window.matchMedia(e),r=e=>n(e.matches);return t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t}function ve(){let{data:e,isLoading:t}=d(void 0,{staleTime:1/0}),[n,r]=E(null);return l(`cluster.topology-snapshot`,e=>{let t=e.data?.nodes;Array.isArray(t)&&r(t)}),{nodes:w(()=>n??e??[],[n,e]),isLoading:t&&!n}}function ye(){let[e,t]=E(`table`),[n,r]=E(void 0),[i,a]=E(0),o=_e(`(max-width: 767px)`),s=o&&e===`graph`?`table`:e,{nodes:c,isLoading:l}=ve(),u=w(()=>q(c),[c]),d=c.filter(e=>e.isOnline).length,f=c.filter(e=>!e.isOnline).length,p=b(e=>{t(`table`),r(e),a(e=>e+1)},[]),m=(n,r,i)=>C(`button`,{onClick:()=>t(n),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${e===n?`bg-primary text-primary-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[D(i,{className:`h-3.5 w-3.5`}),r]});return C(`div`,{className:`flex flex-col h-full gap-4 p-4`,children:[C(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[C(`div`,{className:`flex items-center gap-2`,children:[d>0&&C(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-success/10 text-success`,children:[d,` online`]}),f>0&&C(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:[f,` offline`]})]}),C(`div`,{className:`flex gap-0.5 p-1 rounded-lg bg-muted`,children:[m(`table`,`Table`,te),!o&&m(`graph`,`Graph`,X)]})]}),l?D(`div`,{className:`flex items-center justify-center flex-1 text-muted-foreground`,children:`Loading cluster topology...`}):s===`graph`?D(K,{graph:u,onOpenNodeDetail:p}):D(`div`,{className:`flex-1 overflow-auto`,children:D(ge,{nodes:c,focusNodeId:n,focusNonce:i})})]})}export{ye as ClusterPage};
@@ -1 +0,0 @@
1
- import{Fa as e,aa as t,c as n,ca as r,da as i,eo as a,fa as o,ga as s,ha as c,ia as l,la as u,ma as d,na as f,oa as p,pa as m,ra as h,s as g,sa as _,ua as ee,vt as v,xa as y,yt as b}from"./src-C9tUE6VN.js";import{Q as x,S,W as C,b as w,o as T,q as E,x as D}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 O}from"./circle-check-big-DVa9F7JF.js";import{t as k}from"./copy-uF3P0mCb.js";import{t as A}from"./key-round-CTt4GMO-.js";import{t as j}from"./AddonCollectionPage-DqaY4er4.js";import{t as te}from"./plus-DIHRelRK.js";import{C as M,E as N,L as P,T as F,W as I,f as L,i as R,r as z,s as B,u as V}from"./index-BXAOUGFx.js";import{t as H}from"./AdminPage-BwmGKnRf.js";import{t as U}from"./AdminTabs-BbJVdoRX.js";import{t as W}from"./addon-display-names-DvSEQty-.js";var G=I(`book-open`,[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z`,key:`ruj8y`}]]),K=I(`key-square`,[[`path`,{d:`M12.4 2.7a2.5 2.5 0 0 1 3.4 0l5.5 5.5a2.5 2.5 0 0 1 0 3.4l-3.7 3.7a2.5 2.5 0 0 1-3.4 0L8.7 9.8a2.5 2.5 0 0 1 0-3.4z`,key:`165ttr`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`m9.4 10.6-6.814 6.814A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814`,key:`1ubxi2`}]]),ne=I(`key`,[[`path`,{d:`m15.5 7.5 2.3 2.3a1 1 0 0 0 1.4 0l2.1-2.1a1 1 0 0 0 0-1.4L19 4`,key:`g0fldk`}],[`path`,{d:`m21 2-9.6 9.6`,key:`1j0ho8`}],[`circle`,{cx:`7.5`,cy:`15.5`,r:`5.5`,key:`yqb3hr`}]]),q=I(`link`,[[`path`,{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`,key:`1cjeqo`}],[`path`,{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`,key:`19qd67`}]]),re=I(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]);x();function ie({userId:e,username:n,onClose:r}){let i=T(),o=y(),s=p({userId:e}),c=s.data,l=()=>i.invalidateQueries({queryKey:[[`userManagement`,`getTotpStatus`]]}),u=t({onSuccess:()=>{l(),r()}}),d=s.isLoading?`loading`:c?.enabled?`enrolled`:`not_enrolled`;return D(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm p-4`,children:S(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl overflow-hidden`,children:[S(`div`,{className:`flex items-center justify-between px-4 py-3 border-b border-border`,children:[S(`div`,{className:`flex items-center gap-2`,children:[D(V,{className:`h-4 w-4 text-primary`}),S(`div`,{children:[D(`div`,{className:`text-sm font-medium text-foreground`,children:`Two-factor authentication`}),S(`div`,{className:`text-[11px] text-foreground-subtle`,children:[`User: `,D(`span`,{className:`font-mono`,children:n})]})]})]}),D(`button`,{onClick:r,className:`p-1 rounded hover:bg-foreground-subtle/10 text-foreground-subtle`,children:D(R,{className:`h-4 w-4`})})]}),S(`div`,{className:`p-4 space-y-4`,children:[d===`loading`&&S(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[D(M,{className:`h-3.5 w-3.5 animate-spin`}),`Checking status…`]}),d===`not_enrolled`&&S(`div`,{className:`rounded-md border border-border bg-surface-hover/30 px-3 py-2.5 flex items-start gap-2.5 text-xs text-foreground-subtle`,children:[D(F,{className:`h-4 w-4 mt-0.5 shrink-0`}),S(`div`,{children:[D(`div`,{className:`font-medium text-foreground`,children:`2FA not enrolled`}),D(`p`,{className:`mt-0.5`,children:`Only the user themselves can enable 2FA, from their own profile page.`})]})]}),d===`enrolled`&&c&&S(w,{children:[S(`div`,{className:`rounded-md border border-emerald-500/30 bg-emerald-500/5 px-3 py-2.5 flex items-start gap-2.5`,children:[D(O,{className:`h-4 w-4 mt-0.5 text-emerald-500 shrink-0`}),S(`div`,{className:`text-xs text-foreground space-y-0.5`,children:[D(`div`,{className:`font-medium`,children:`2FA is active`}),S(`div`,{className:`text-foreground-subtle`,children:[`Enrolled on`,` `,c.confirmedAt?new Date(c.confirmedAt).toLocaleString():`—`]})]})]}),D(`div`,{className:`text-[11px] text-foreground-subtle`,children:`Removing here clears the server-side secret. Use this only when the user has lost access — they'll have to re-enroll from their profile page afterwards.`}),S(`div`,{className:`flex justify-end gap-2`,children:[D(a,{onClick:r,variant:`secondary`,children:`Close`}),S(`button`,{onClick:async()=>{await o({title:`Remove 2FA`,message:`Remove two-factor authentication for "${n}"? They'll be able to log in with just their password until they re-enroll from their own profile page.`,confirmLabel:`Remove`,variant:`danger`})&&u.mutate({userId:e})},disabled:u.isPending,className:`rounded bg-danger px-3 py-1.5 text-xs font-medium text-white hover:bg-danger/90 disabled:opacity-50 inline-flex items-center gap-1`,children:[u.isPending?D(M,{className:`h-3 w-3 animate-spin`}):D(R,{className:`h-3 w-3`}),`Remove 2FA`]})]})]})]})]})})}function ae(){let t=T(),{user:n}=z(),[r,a]=E(!1),[o,u]=E(``),[d,f]=E(``),[p,m]=E(!1),[g,_]=E(null),{data:v,isLoading:b,isError:x}=ee(),C=y(),w=()=>t.invalidateQueries({queryKey:[[`userManagement`,`listUsers`]]}),O=h({onSuccess:()=>{w(),a(!1),u(``),f(``),m(!1),_(null)},onError:e=>{_(e instanceof Error?e.message:`Failed to create user`)}}),k=l({onSuccess:w}),A=s({onSuccess:w}),j=i({onSuccess:w}),N=c({onSuccess:()=>{w(),F(null)}}),[P,F]=E(null),[I,U]=E(null),W=v??[];async function G(e){await C({title:`Delete user`,message:`Permanently delete user "${e.username}"? This cannot be undone — any active sessions will be revoked on next request.`,confirmLabel:`Delete`,variant:`danger`})&&k.mutate({id:e.id})}async function K(e){let t=window.prompt(`New password for "${e.username}":`);if(t){if(t.length<8){window.alert(`Password must be at least 8 characters.`);return}await C({title:`Reset password`,message:`Reset the password for "${e.username}"? They will need to use the new password on their next login.`,confirmLabel:`Reset`})&&j.mutate({id:e.id,newPassword:t})}}function q(e,t){t!==e.isAdmin&&A.mutate({id:e.id,isAdmin:t})}function re(e){return e?new Date(typeof e==`number`?e:String(e)).toLocaleDateString(`en-GB`,{day:`2-digit`,month:`short`,year:`numeric`}):`—`}return S(H,{children:[D(`div`,{className:`flex items-center justify-end`,children:S(`button`,{onClick:()=>a(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm hover:bg-primary/90`,children:[D(te,{className:`h-3.5 w-3.5`}),`Create User`]})}),r&&S(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[S(`div`,{className:`flex items-center justify-between`,children:[D(`span`,{className:`text-xs font-medium text-foreground`,children:`New User`}),D(`button`,{onClick:()=>a(!1),className:`text-foreground-subtle hover:text-foreground`,children:D(R,{className:`h-4 w-4`})})]}),S(`div`,{className:`grid grid-cols-3 gap-3`,children:[S(`div`,{className:`space-y-1`,children:[D(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Username`}),D(`input`,{type:`text`,value:o,onChange:e=>u(e.target.value),placeholder:`john`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),S(`div`,{className:`space-y-1`,children:[D(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Password`}),D(`input`,{type:`password`,value:d,onChange:e=>f(e.target.value),placeholder:`••••••••`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`})]}),S(`div`,{className:`space-y-1`,children:[D(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Admin`}),S(`label`,{className:`flex items-center gap-2 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground cursor-pointer`,children:[D(`input`,{type:`checkbox`,checked:p,onChange:e=>m(e.target.checked),className:`rounded border-border focus:ring-primary`}),D(`span`,{className:`text-foreground-subtle`,children:`Unrestricted access`})]})]})]}),g&&D(`p`,{className:`text-[10px] text-danger`,children:g}),S(`div`,{className:`flex justify-end gap-2`,children:[D(`button`,{onClick:()=>a(!1),className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),D(`button`,{onClick:()=>O.mutate({username:o,password:d,isAdmin:p}),disabled:O.isPending||!o||!d,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:O.isPending?`Creating...`:`Create`})]})]}),b&&D(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading...`}),x&&D(`div`,{className:`text-xs text-danger`,children:`Failed to load`}),!b&&!x&&W.length===0&&D(`div`,{className:`text-xs text-foreground-subtle`,children:`No data`}),(()=>{let t=e=>k.isPending&&k.variables?.id===e.id||A.isPending&&A.variables?.id===e.id||j.isPending&&j.variables?.id===e.id;return D(e,{columns:[{key:`username`,header:`Username`,render:e=>e.username},{key:`isAdmin`,header:`Admin`,render:e=>S(`label`,{className:`inline-flex items-center gap-1.5 text-xs cursor-pointer`,children:[D(`input`,{type:`checkbox`,checked:e.isAdmin,onChange:t=>q(e,t.target.checked),disabled:t(e),className:`rounded border-border focus:ring-primary disabled:opacity-50`}),D(`span`,{className:e.isAdmin?`text-primary font-medium`:`text-foreground-subtle`,children:e.isAdmin?`Admin`:`Regular`})]})},{key:`scopes`,header:`Scopes`,render:e=>{if(e.isAdmin)return D(`span`,{className:`text-[10px] text-foreground-subtle italic`,children:`unscoped`});let t=e.scopes??[];return S(`button`,{onClick:()=>F(e),className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground`,title:`Edit scope grants`,children:[D(L,{className:`h-3 w-3`}),t.length===0?`no access`:`${t.length} grant${t.length===1?``:`s`}`]})}},{key:`createdAt`,header:`Created`,render:e=>D(`span`,{className:`text-foreground-subtle`,children:re(e.createdAt)})},{key:`actions`,header:`Actions`,align:`right`,render:e=>{let r=t(e);return S(`div`,{className:`flex items-center justify-end gap-1`,children:[e.id!==n?.id&&e.totpEnabled&&S(`button`,{onClick:()=>U(e),disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Remove two-factor authentication`,children:[D(V,{className:`h-3 w-3`}),`Remove 2FA`]}),S(`button`,{onClick:()=>K(e),disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-foreground-subtle hover:bg-foreground-subtle/10 hover:text-foreground disabled:opacity-50`,title:`Reset password`,children:[D(ne,{className:`h-3 w-3`}),`Reset password`]}),S(`button`,{onClick:()=>G(e),disabled:r,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete user`,children:[r?D(M,{className:`h-3 w-3 animate-spin`}):D(B,{className:`h-3 w-3`}),`Delete`]})]})}}],rows:W,rowKey:e=>e.id,minWidthPx:560})})(),I&&D(ie,{userId:I.id,username:I.username,onClose:()=>U(null)}),P&&D(oe,{user:P,onClose:()=>F(null),onSubmit:e=>N.mutate({userId:P.id,scopes:e}),submitting:N.isPending})]})}function oe(e){let{user:t}=z(),n=t?.isAdmin===!0;return D(se,{...e,callerScopes:n?null:t?.scopes??[]})}function se({user:e,onClose:t,onSubmit:r,submitting:i,callerScopes:a}){let[o,s]=E(C(()=>(e.scopes??[]).map(e=>({...e,access:[...e.access]})),[e.scopes])),c=n(o);return D(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4`,children:S(`div`,{className:`w-full max-w-2xl rounded-lg border border-border bg-surface shadow-xl`,children:[S(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-3`,children:[S(`div`,{children:[S(`div`,{className:`text-sm font-semibold text-foreground`,children:[`Edit scopes — `,e.username]}),D(`div`,{className:`text-[10px] text-foreground-subtle`,children:e.isAdmin?`Admin users bypass the scope check; this list is ignored.`:`Pick which capabilities this user can call, and which access flavours within each.`})]}),D(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:D(R,{className:`h-4 w-4`})})]}),S(`div`,{className:`px-4 py-4`,children:[D(g,{value:o,onChange:s,clampToParent:a,emptyHint:S(w,{children:[`No scopes granted.`,` `,D(`span`,{className:`font-medium text-foreground`,children:e.username}),` cannot call any protected endpoint until a scope is added.`]})}),c&&D(`p`,{className:`mt-2 text-[10px] text-danger`,children:c})]}),S(`div`,{className:`flex items-center justify-end gap-2 border-t border-border px-4 py-3`,children:[D(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),D(`button`,{onClick:()=>r(o),disabled:i||c!==null,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:i?D(M,{className:`h-3 w-3 animate-spin`}):`Save scopes`})]})]})})}x();var ce=`bg-primary/10 text-primary`,le=`bg-foreground-subtle/10 text-foreground-subtle`;function J(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function ue(e){return e?e===`*`?`*`:e.join(`, `):``}function de(){let e=T(),t=y(),{data:n,isLoading:r}=_(),{data:i}=ee(),a=C(()=>n??[],[n]),s=C(()=>i??[],[i]),c=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listApiKeys`]]}),l=()=>e.invalidateQueries({queryKey:[[`userManagement`,`listScopedTokens`]]}),[u,p]=E(!1),[m,h]=E(null),g=o({onSuccess:c}),v=f({onSuccess:({token:e,record:t})=>{l(),p(!1),h({token:e,label:t.name})}}),b=d({onSuccess:l}),x=async(e,n)=>{await t({title:`Revoke "${n}"?`,message:`Any client using this token will lose access immediately. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&g.mutate({id:e})},w=async(e,n)=>{await t({title:`Revoke "${n}"?`,message:`The scoped token will be invalid on its next use.`,confirmLabel:`Revoke`,variant:`danger`})&&b.mutate({id:e})};return S(H,{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:`Issue scoped tokens to grant a user a narrow surface — a specific addon, integration, or capability. Every token MUST be scoped: revoking it has predictable blast radius.`}),S(`button`,{onClick:()=>p(!0),className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,disabled:s.length===0,title:s.length===0?`Create a user first`:`Issue a scoped token`,children:[D(L,{className:`h-3.5 w-3.5`}),`New token`]})]}),S(fe,{title:`Scoped tokens`,subtitle:`Grouped per user`,children:[s.length===0&&D(me,{text:`No users yet — scoped tokens are issued on behalf of an existing user.`}),s.map(e=>D(ge,{userId:e.id,username:e.username,onRevoke:(e,t)=>{w(e,t)},revokePending:b.isPending,revokeId:b.variables?.id},e.id))]}),a.length>0&&D(fe,{title:`Legacy API keys`,subtitle:`${a.length} pre-existing — revoke only`,children:D(he,{headers:[`Label`,`Admin`,`Prefix`,`Allowed providers`,`Created`,`Last used`,``],rows:a.map(e=>{let t=!!e.isAdmin,n=g.isPending&&g.variables?.id===e.id;return S(`tr`,{className:`hover:bg-primary/5`,children:[D(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.label}),D(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:D(`span`,{className:`inline-block rounded px-2 py-0.5 text-[10px] uppercase tracking-wide ${t?ce:le}`,children:t?`admin`:`regular`})}),S(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),D(`td`,{className:`px-3 py-2 text-foreground border-b border-border text-foreground-subtle`,children:ue(e.allowedProviders)||`all`}),D(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.createdAt)}),D(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.lastUsedAt)}),D(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:S(`button`,{onClick:()=>{x(e.id,e.label)},disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[n?D(M,{className:`h-3 w-3 animate-spin`}):D(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})}),r&&D(pe,{}),u&&D(_e,{users:s.map(e=>({id:e.id,username:e.username})),onClose:()=>p(!1),onSubmit:e=>v.mutate({userId:e.userId,name:e.name,scopes:e.scopes,...e.expiresAt===void 0?{}:{expiresAt:e.expiresAt}}),submitting:v.isPending}),m&&D(ve,{token:m.token,label:m.label,onClose:()=>h(null)})]})}function fe({title:e,subtitle:t,children:n}){return S(`div`,{className:`space-y-2`,children:[S(`div`,{className:`flex items-baseline justify-between`,children:[D(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),t&&D(`span`,{className:`text-[10px] text-foreground-subtle`,children:t})]}),n]})}function pe(){return D(`div`,{className:`space-y-2`,children:[1,2].map(e=>D(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function me({text:e}){return D(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function he({headers:e,rows:t}){return D(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:S(`table`,{className:`w-full text-xs min-w-[640px]`,children:[D(`thead`,{children:D(`tr`,{children:e.map((t,n)=>D(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),D(`tbody`,{children:t})]})})}function ge({userId:e,username:t,onRevoke:n,revokePending:r,revokeId:i}){let{data:a,isLoading:o}=u({userId:e}),s=a??[];return o||s.length===0?null:S(`div`,{className:`space-y-1.5`,children:[D(`div`,{className:`text-[11px] font-medium text-foreground`,children:t}),D(he,{headers:[`Name`,`Prefix`,`Scopes`,`Expires`,`Last used`,`Created`,``],rows:s.map(e=>{let t=r&&i===e.id;return S(`tr`,{className:`hover:bg-primary/5`,children:[D(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.name}),S(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-mono text-[11px]`,children:[e.tokenPrefix,`…`]}),D(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:D(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>S(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:[e.type,`:`,e.type===`device`?`[${e.targets.join(`,`)}]`:e.target]},t))})}),D(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.expiresAt)}),D(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.lastUsedAt)}),D(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:J(e.createdAt)}),D(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:S(`button`,{onClick:()=>n(e.id,e.name),disabled:t,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,children:[t?D(M,{className:`h-3 w-3 animate-spin`}):D(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}function _e({users:e,onClose:t,onSubmit:r,submitting:i}){let{user:a}=z(),o=a?.isAdmin===!0?null:a?.scopes??[],[s,c]=E(e[0]?.id??``),[l,u]=E(``),[d,f]=E([{type:`capability`,target:``,access:[`view`,`create`]}]),[p,m]=E(``),h=n(d),_=s!==``&&l.trim().length>0&&d.length>0&&h===null&&!i;return S(ye,{title:`Create scoped token`,onClose:t,children:[S(`div`,{className:`space-y-3`,children:[D(Y,{label:`On behalf of user`,children:D(`select`,{value:s,onChange:e=>c(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`,children:e.map(e=>D(`option`,{value:e.id,children:e.username},e.id))})}),D(Y,{label:`Name`,children:D(`input`,{value:l,onChange:e=>u(e.target.value),placeholder:`cloudflare-tunnel-route`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})}),S(Y,{label:`Scopes`,hint:`Each scope picks a (cap or addon) target + one or more access flavours. The token can access ONLY what's listed.`,children:[D(g,{value:d,onChange:f,clampToParent:o}),h&&D(`p`,{className:`mt-1 text-[10px] text-danger`,children:h})]}),D(Y,{label:`Expires in (days)`,hint:`Leave blank for non-expiring.`,children:D(`input`,{type:`number`,min:1,value:p,onChange:e=>m(e.target.value),placeholder:`30`,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs focus:outline-none focus:ring-1 focus:ring-primary`})})]}),S(be,{children:[D(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),S(`button`,{onClick:()=>{let e=parseInt(p,10),t=Number.isFinite(e)&&e>0?Date.now()+e*864e5:void 0;r({userId:s,name:l.trim(),scopes:d,expiresAt:t})},disabled:!_,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[i?D(M,{className:`h-3.5 w-3.5 animate-spin`}):D(L,{className:`h-3.5 w-3.5`}),`Issue token`]})]})]})}function ve({token:e,label:t,onClose:n}){let[r,i]=E(!1),a=async()=>{try{await navigator.clipboard.writeText(e),i(!0)}catch{}};return S(ye,{title:`Token: ${t}`,onClose:n,children:[S(`div`,{className:`space-y-3`,children:[D(`div`,{className:`rounded border border-warning/30 bg-warning/10 px-3 py-2 text-xs text-warning`,children:`Copy this token now. Once you close this dialog the secret cannot be displayed again.`}),D(`div`,{className:`rounded border border-border bg-background p-2 font-mono text-[11px] break-all select-all`,children:e})]}),S(be,{children:[S(`button`,{onClick:()=>{a()},className:`inline-flex items-center gap-1.5 rounded bg-surface border border-border px-3 py-1.5 text-xs font-medium text-foreground hover:bg-primary/5 hover:border-primary/30`,children:[r?D(P,{className:`h-3.5 w-3.5 text-primary`}):D(k,{className:`h-3.5 w-3.5`}),r?`Copied`:`Copy`]}),D(`button`,{onClick:n,className:`rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:`Done`})]})]})}function ye({title:e,onClose:t,children:n}){return D(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:S(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[S(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[D(`h2`,{className:`text-sm font-semibold text-foreground`,children:e}),D(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:D(R,{className:`h-4 w-4`})})]}),D(`div`,{className:`p-4`,children:n})]})})}function be({children:e}){return D(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3`,children:e})}function Y({label:e,hint:t,children:n}){return S(`div`,{className:`space-y-1`,children:[D(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:e}),n,t&&D(`p`,{className:`text-[10px] text-foreground-subtle`,children:t})]})}x();function X(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?`—`:t.toLocaleString()}function xe(e){if(e.type===`category`){let t=e.target??``;return t===`device`?`all devices`:`all ${t}`}if(e.type===`device`)return`device:[${(e.targets??[]).join(`,`)}]`;let t=e;return`${t.type}:${t.target??``}`}function Se(){return D(`div`,{className:`space-y-2`,children:[1,2].map(e=>D(`div`,{className:`h-10 rounded border border-border bg-surface animate-pulse`},e))})}function Ce({text:e}){return D(`div`,{className:`rounded border border-dashed border-border bg-surface px-3 py-4 text-xs text-foreground-subtle text-center`,children:e})}function we({headers:e,rows:t}){return D(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:S(`table`,{className:`w-full text-xs min-w-[640px]`,children:[D(`thead`,{children:D(`tr`,{children:e.map((t,n)=>D(`th`,{className:`px-3 py-2 text-foreground-subtle font-medium bg-surface border-b border-border whitespace-nowrap ${n===e.length-1?`text-right`:`text-left`}`,children:t},n))})}),D(`tbody`,{children:t})]})})}function Te(){let e=T(),t=y(),{data:n,isLoading:i}=r(),a=C(()=>n??[],[n]),o=m({onSuccess:()=>e.invalidateQueries({queryKey:[[`userManagement`,`listOauthSessions`]]})}),s=async(e,n)=>{await t({title:`Revoke "${n}" session?`,message:`This integration will lose access immediately on its next API call. This cannot be undone.`,confirmLabel:`Revoke`,variant:`danger`})&&o.mutate({id:e})};return S(H,{icon:q,title:`Linked Sessions`,subtitle:`External integrations (Alexa, …) linked to this hub via OAuth. Revoke a session to immediately invalidate that integration's access.`,children:[i&&D(Se,{}),!i&&a.length===0&&D(Ce,{text:`No linked sessions — once an external integration completes the OAuth flow its session will appear here.`}),!i&&a.length>0&&D(we,{headers:[`Integration`,`User`,`Scopes`,`Created`,`Last used`,`Status`,``],rows:a.map(e=>{let t=e.revokedAt!==null,n=(o.isPending?o.variables?.id:void 0)===e.id;return S(`tr`,{className:`hover:bg-primary/5`,children:[D(`td`,{className:`px-3 py-2 text-foreground border-b border-border font-medium`,children:e.integrationId}),D(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:e.username}),D(`td`,{className:`px-3 py-2 text-foreground border-b border-border`,children:D(`div`,{className:`flex flex-wrap gap-1`,children:e.scopes.map((e,t)=>D(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-1.5 py-0.5 text-[10px] font-mono`,children:xe(e)},t))})}),D(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.createdAt)}),D(`td`,{className:`px-3 py-2 text-foreground-subtle border-b border-border`,children:X(e.lastUsedAt)}),D(`td`,{className:`px-3 py-2 border-b border-border`,children:t?S(`span`,{className:`inline-block rounded bg-foreground-subtle/10 px-2 py-0.5 text-[10px] text-foreground-subtle`,children:[`Revoked `,X(e.revokedAt)]}):D(`span`,{className:`inline-block rounded bg-emerald-500/15 px-2 py-0.5 text-[10px] text-emerald-700 dark:text-emerald-300`,children:`Active`})}),D(`td`,{className:`px-3 py-2 border-b border-border text-right`,children:!t&&S(`button`,{onClick:()=>{s(e.id,e.integrationId)},disabled:n,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Revoke`,children:[n?D(M,{className:`h-3 w-3 animate-spin`}):D(B,{className:`h-3 w-3`}),`Revoke`]})})]},e.id)})})]})}x();var Z=3e4,Q=[{capName:`auth-provider`,stageBadge:null},{capName:`user-passkeys`,stageBadge:`Second factor`}],$={title:`Authentication providers`,subtitle:`Every registered authentication surface in one list: login providers (local password, OIDC, SAML, magic-link) and second-factor providers (passkeys / WebAuthn — configure the relying-party RP ID + origin inline; users enroll from My access → Passkeys). Multiple providers run in parallel — enable/disable each independently. Disabling one only removes that method; local password login is unaffected.`,emptyTitle:`No authentication providers registered`,emptyDescription:`Local auth should always be available — if this list is empty the local-auth builtin failed to register. Check the Addons page for load errors.`,installLabel:`Add provider`};function Ee(e){return e===`local-auth`?{headline:`Username + password (local).`,icon:K,bullets:[`Users live in the hub’s SQLite database — no IdP roundtrip.`,`TOTP / 2FA is self-enrolled: each user enables it from their own profile page (My access → Two-factor authentication).`,`API keys + scoped tokens are managed from the API Keys page.`],setupSteps:[`Add users from Users → New user (or seed via CAMSTACK_ADMIN_USER / CAMSTACK_ADMIN_PASS).`,`Hand out either passwords or scoped tokens — both validate through this provider.`]}:e.startsWith(`auth-oidc`)?{headline:`OpenID Connect (Google, Microsoft, Okta, Keycloak, …).`,icon:N,bullets:[`Three-leg redirect flow with PKCE S256 + nonce.`,`id_token is signature-verified against the IdP’s JWKS — no implicit trust.`,`First-time sign-ins are auto-provisioned with the configured Default Role.`],setupSteps:[`Register a web app at your IdP and copy the client_id + client_secret.`,"Set the redirect URI to `https://<this-hub>/addon/<addon-id>/callback`.",`Paste issuer + credentials in the Settings panel below — saves on every change.`]}:e.startsWith(`auth-saml`)?{headline:`SAML 2.0 — enterprise SSO (Azure AD, Okta, OneLogin).`,icon:N,bullets:[`Heavier handshake than OIDC — exchange metadata XML with your IdP.`,`Group → role mapping via SAML assertions.`]}:e.startsWith(`auth-webauthn`)||e.startsWith(`auth-passkey`)?{headline:`Passkeys / WebAuthn — passwordless second factor.`,icon:V,bullets:[`Enroll a YubiKey, Touch ID, or platform passkey per user.`,`Resistant to phishing — the browser binds the credential to your hub origin.`]}:e.startsWith(`auth-totp`)||e.startsWith(`auth-magic-link`)?{headline:`TOTP / magic-link — second factor or passwordless sign-in.`,icon:V,bullets:[`Codes / links delivered out-of-band (RFC 6238 for TOTP).`,`Compatible with Google Authenticator, Aegis, 1Password, Bitwarden, etc.`]}:{headline:`Authentication provider.`,icon:L,bullets:[`Generic authentication provider. No additional hints registered.`]}}function De(){let e=b({capName:Q[0].capName},{refetchInterval:Z}),t=b({capName:Q[1].capName},{refetchInterval:Z}),n=v(void 0,{refetchInterval:Z}),r=C(()=>W(n.data??[]),[n.data]),i=C(()=>{let n=[],i=[e.data??[],t.data??[]];for(let[e,t]of Q.entries())for(let a of i[e]??[])n.push({addonId:a.addonId,displayName:r.get(a.addonId)??a.addonId,isActive:a.isActive,capName:t.capName,stageBadge:t.stageBadge});return n},[e.data,t.data,r]);return D(j,{title:$.title,subtitle:$.subtitle,pageIcon:L,itemIcon:L,capability:Q[0].capName,installButtonLabel:$.installLabel,items:i,isLoading:e.isLoading||t.isLoading,emptyTitle:$.emptyTitle,emptyDescription:$.emptyDescription,renderStatusBadges:e=>e.stageBadge===null?null:D(`span`,{className:`inline-flex items-center rounded-full border border-primary/30 bg-primary/10 px-2 py-0.5 text-[10px] font-medium text-primary`,children:e.stageBadge}),renderExpandedPanel:e=>D(Oe,{addonId:e.addonId})})}function Oe({addonId:e}){let t=Ee(e),n=t.icon;return S(`div`,{className:`rounded-lg border border-border bg-surface p-4 space-y-3`,children:[S(`div`,{className:`flex items-start gap-2.5`,children:[D(n,{className:`h-4 w-4 mt-0.5 text-primary shrink-0`}),D(`div`,{className:`text-xs text-foreground font-medium`,children:t.headline})]}),D(`ul`,{className:`text-xs text-foreground-subtle space-y-1.5 pl-6 list-disc`,children:t.bullets.map((e,t)=>D(`li`,{children:e},t))}),t.setupSteps&&t.setupSteps.length>0&&S(`div`,{className:`rounded-md border border-border bg-surface-hover/40 px-3 py-2.5 space-y-1.5`,children:[S(`div`,{className:`flex items-center gap-1.5 text-[10px] font-semibold text-foreground-subtle uppercase tracking-wide`,children:[D(G,{className:`h-3 w-3`}),`Setup steps`]}),D(`ol`,{className:`text-xs text-foreground space-y-0.5 pl-4 list-decimal`,children:t.setupSteps.map((e,t)=>D(`li`,{children:e},t))})]}),e===`local-auth`&&S(`div`,{className:`rounded-md border border-blue-500/30 bg-blue-500/5 px-3 py-2 flex items-start gap-2 text-[11px] text-foreground`,children:[D(F,{className:`h-3.5 w-3.5 mt-0.5 text-blue-500 shrink-0`}),S(`span`,{children:[`TOTP / 2FA is self-service: each user enrols from their own profile page —`,` `,D(`a`,{href:`/system/my-access`,className:`underline text-primary`,children:`My access`}),` `,`→ “Two-factor authentication” → Enable 2FA. Admins can only remove a user’s active enrollment (lost device) from the`,` `,D(`a`,{href:`/system/users`,className:`underline text-primary`,children:`Users`}),` `,`page via Actions → “Remove 2FA”.`]})]})]})}function ke(){return D(`div`,{className:`flex flex-col p-4`,children:D(U,{tabs:[{id:`users`,label:`Users`,icon:re,content:D(ae,{})},{id:`api-keys`,label:`Tokens`,icon:A,content:D(de,{})},{id:`linked-sessions`,label:`Linked Sessions`,icon:q,content:D(Te,{})},{id:`authentication`,label:`Authentication`,icon:L,content:D(De,{})}]})})}export{ke as IdentityPage};
@@ -1 +0,0 @@
1
- import{Cn as e,Ct as t,Hn as n,Ia as r,Nn as i,On as a,U as o,W as s,Xa as c,ar as l,bn as u,cr as d,ct as f,d as p,dn as m,et as ee,fn as h,fr as g,g as _,hn as v,ir as y,jn as b,ln as x,mn as S,nt as C,or as te,un as ne,ur as w,x as T,yn as E}from"./src-C9tUE6VN.js";import{I as D,K as re,Q as O,S as k,W as A,b as j,o as M,q as N,x as P,z as ie}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 F}from"./src-DJCxIXmd.js";import{p as I}from"./player-overlays-G3UGtBzC.js";import{t as L}from"./ProviderIcon-BSvVPouG.js";import{t as R}from"./plus-DIHRelRK.js";import{n as z,r as B,t as ae}from"./ScanNetworkModal-ByX1qWEM.js";import{t as oe}from"./refresh-cw-NUBl_9F6.js";import{t as V}from"./rotate-cw-CWQEKQOp.js";import{t as se}from"./wifi-0f3nqfEf.js";import{C as H,D as U,H as ce,I as W,J as le,K as ue,L as G,O as K,P as de,W as fe,h as pe,i as me,o as q,p as he,q as ge,s as _e,t as ve}from"./index-BXAOUGFx.js";import{t as J}from"./FormBuilder-BsMr0Lyl.js";var ye=fe(`search-x`,[[`path`,{d:`m13.5 8.5-5 5`,key:`1cs55j`}],[`path`,{d:`m8.5 8.5 5 5`,key:`a8mexj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]);O();function be(e){let t=[];for(let n of e)n.type===`probe`&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...be(n.fields));return t}function xe(e,t,n){let[r,i]=N(`idle`),[a,o]=N({}),s=A(()=>{let t=[];for(let n of e.sections)t.push(...be(n.fields));return t},[e]),c=s.length>0&&n!==void 0,l=D(e=>{o(t=>{if(!t[e])return t;let n={...t};return delete n[e],n})},[]);return{testAllStatus:r,hasProbeFields:c,probeResults:a,handleTestAll:D(async()=>{if(!n)return;let e=s.filter(e=>{let n=t[e];return n!=null&&String(n).trim()!==``});if(e.length===0)return;i(`testing`);let r={};for(let t of e)r[t]={status:`probing`};o(r);let a=await Promise.allSettled(e.map(async e=>{try{return{key:e,result:await n(e,t[e])}}catch(t){return{key:e,result:{status:`error`,error:t instanceof Error?t.message:String(t)}}}})),c={};for(let e of a)if(e.status===`fulfilled`){let{key:t,result:n}=e.value;c[t]={status:n.status===`ok`?`ok`:`error`,result:n}}o(c),i(`idle`)},[n,s,t]),clearProbeResult:l}}O();function Se(e){let t=[];for(let n of e)`required`in n&&n.required===!0&&`key`in n&&n.key&&t.push(n.key),n.type===`group`&&`fields`in n&&t.push(...Se(n.fields));return t}function Ce(e){return e==null?!0:typeof e==`string`?e.trim()===``:!1}function Y(e,t={}){for(let n of e){if(n.type===`group`&&`fields`in n){Y(n.fields,t);continue}`key`in n&&n.key&&`default`in n&&n.default!==void 0&&(t[n.key]=n.default)}return t}function X(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`probe-${crypto.randomUUID()}`:`probe-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function we({open:t,integrationId:r,addonId:i,onClose:a}){let{t:o}=ve(),s=M(),[c,l]=N({}),[u,d]=N(!1),[f,p]=N(null),[m,ee]=N(X),h=b({addonId:i},{enabled:t}),g=h.data?.deviceType??null,v=e({addonId:i,type:g??F.Camera},{enabled:t&&h.isSuccess&&g!==null}),y=v.data??null;ie(()=>{t&&(l(y?Y(y.sections.flatMap(e=>e.fields)):{}),ee(X()),d(!1),p(null))},[t,r,y]);let x=A(()=>({...c,_probeRequestId:m}),[c,m]),C=S({onSuccess:()=>{s.invalidateQueries({queryKey:[[`deviceManager`]]})}}),te=n(),ne=D(async(e,t)=>{d(!0);let n=await te.mutateAsync({addonId:i,type:g??F.Camera,key:e,value:t,formValues:x});return n.status===`ok`&&n.suggestedValues&&l(e=>{let t=!1,r={...e};for(let[i,a]of Object.entries(n.suggestedValues??{}))Ce(e[i])&&!Ce(a)&&(r[i]=a,t=!0);return t?r:e}),n},[te,i,x,g]),{testAllStatus:w,hasProbeFields:T,probeResults:E,handleTestAll:re,clearProbeResult:O}=xe(y??{sections:[]},c,ne);async function j(e){p(null);try{await C.mutateAsync({addonId:i,type:g??F.Camera,config:c,integrationId:r}),e?l(y?Y(y.sections.flatMap(e=>e.fields)):{}):a()}catch(e){p(e instanceof Error?e.message:String(e))}}if(!t)return null;let I=Se((y?.sections??[]).flatMap(e=>e.fields)).filter(e=>Ce(c[e])),L=I.length===0,R=h.isLoading||g!==null&&v.isLoading,z=h.isError||h.isSuccess&&g===null||v.isError||v.isSuccess&&y===null;return k(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[P(`div`,{className:`absolute inset-0 bg-black/60`,onClick:a}),k(`div`,{className:`relative z-10 flex w-full max-w-2xl flex-col max-h-[90vh] rounded-xl border border-border bg-background shadow-2xl`,children:[k(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[P(`h2`,{className:`text-sm font-semibold text-foreground`,children:o(`integrations.addDevice`)}),P(`button`,{onClick:a,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:P(me,{className:`h-4 w-4`})})]}),P(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-5 py-4 space-y-3`,children:R?P(`div`,{className:`flex items-center justify-center py-8`,children:P(H,{className:`h-5 w-5 animate-spin text-primary`})}):z?k(`div`,{className:`flex items-start gap-3 rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-3`,children:[P(q,{className:`h-4 w-4 text-destructive mt-0.5 shrink-0`}),k(`div`,{className:`space-y-1`,children:[P(`p`,{className:`text-xs font-medium text-destructive`,children:`Provider unavailable`}),k(`p`,{className:`text-xs text-foreground-subtle`,children:[`The addon `,P(`span`,{className:`font-mono`,children:i}),` is not ready or does not support manual device creation. Check that the integration is online and try again.`]})]})]}):P(J,{schema:y,values:c,onChange:l,onTestField:ne,probeResults:E,onClearProbe:O})}),!z&&!R&&k(`div`,{className:`border-t border-border bg-surface/50 shrink-0`,children:[k(`button`,{type:`button`,onClick:()=>d(e=>!e),className:`flex w-full items-center justify-between px-5 py-2 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[k(`span`,{className:`flex items-center gap-2`,children:[P(pe,{className:`h-3.5 w-3.5`}),`Test logs`,P(`span`,{className:`font-mono text-[9px] opacity-60`,children:m.slice(0,14)})]}),P(W,{className:`h-3.5 w-3.5 transition-transform ${u?`rotate-180`:``}`})]}),u&&P(`div`,{className:`border-t border-border max-h-64 overflow-hidden`,children:P(_,{addonId:i,requestId:m,limit:50,maxHeight:`max-h-64`,showFilters:!1,showScope:!1,className:`border-0 rounded-none`})})]}),!z&&!R&&(f||I.length>0)&&P(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:k(`div`,{className:`flex items-start gap-2`,children:[P(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),P(`p`,{className:`text-[11px] text-destructive`,children:f||`Required: ${I.join(`, `)}`})]})}),k(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[k(`div`,{className:`flex items-center gap-2`,children:[P(`button`,{onClick:a,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:o(`integrations.cancel`)}),!z&&T&&k(`button`,{type:`button`,onClick:re,disabled:w===`testing`,className:`inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:[w===`testing`?P(H,{className:`h-3.5 w-3.5 animate-spin`}):P(se,{className:`h-3.5 w-3.5`}),`Test All`]})]}),k(`div`,{className:`flex items-center gap-2`,children:[P(`button`,{onClick:()=>j(!0),disabled:z||!L||C.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground hover:bg-surface-hover transition-colors disabled:opacity-50`,children:o(`integrations.saveAndNew`)}),P(`button`,{onClick:()=>j(!1),disabled:z||!L||C.isPending,className:`rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50`,children:C.isPending?o(`integrations.saving`):o(`integrations.save`)})]})]})]})]})}function Z(e){let t=e.metadata;return[e.name,e.childNativeId,t.model,t.manufacturer,t.integration,t.externalLocation].filter(e=>typeof e==`string`&&e.length>0).join(` `)}O();var Q=`devices`,Te={id:Q,label:`Devices`,isDefault:!0},Ee=2e4,De=100;function Oe({addonId:e,integrationId:t,onClose:n}){let{t:r}=ve(),[i,a]=N(new Set),[s,c]=N(new Set),[l,u]=N(new Map),[d,f]=N(null),{data:p}=te(),g=(p??[]).find(t=>t.addonId===e)?.supportsLocationImport??!1,[_,v]=N(!0),y=ne({addonId:e,integrationId:t}).data?.filters,b=y&&y.length>0?y:[Te],[S,w]=N(b.find(e=>e.isDefault)?.id??(b.some(e=>e.id===Q)?Q:b[0].id)),T=S!==Q,E=h(),O=m({addonId:e,integrationId:t,page:1,pageSize:Ee,filter:S}),A=O.refetch,j=E.mutate,M=D(()=>{j({addonId:e,integrationId:t},{onSettled:()=>{A()}})},[j,e,t,A]),F=re(null);ie(()=>{let n=`${e}::${t}`;F.current===n||O.isLoading||(F.current=n,(O.data?.candidates.length??0)===0&&M())},[e,t,O.isLoading,O.data,M]);let I=E.isPending,L=E.isError?E.error instanceof Error?E.error.message:String(E.error):null,R=O.data?.candidates??[],z=O.isError?O.error instanceof Error?O.error.message:String(O.error):null,B=x(),ae=D(e=>{e.alreadyAdopted||a(t=>{let n=new Set(t);return n.has(e.childNativeId)?n.delete(e.childNativeId):n.add(e.childNativeId),n})},[]),oe=D(e=>{c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),se=D((e,t)=>{u(n=>{let r=new Map(n),i=r.get(e)?.hiddenChildIds??new Set,a=new Set(i);return a.has(t)?a.delete(t):a.add(t),a.size===0?r.delete(e):r.set(e,{hiddenChildIds:a}),r})},[]),U=D(e=>{let t={};for(let n of e){let e=l.get(n);e&&e.hiddenChildIds.size>0&&(t[n]={hiddenChildIds:[...e.hiddenChildIds]})}return Object.keys(t).length>0?t:void 0},[l]),ce=D(async()=>{f(null);let r=[...i];if(r.length!==0)try{let i=U(r);await B.mutateAsync({addonId:e,integrationId:t,filter:S,childNativeIds:r,...i?{perCandidate:i}:{},...g?{importLocations:_}:{}}),a(new Set),u(new Map),await A(),n()}catch(e){f(e instanceof Error?e.message:String(e))}},[i,U,B,e,t,S,A,g,_]),W=D(e=>{w(e),a(new Set),c(new Set),u(new Map),f(null)},[]),le=i.size;return k(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center`,children:[P(`div`,{className:`absolute inset-0 bg-black/60`,onClick:n}),k(`div`,{className:`relative z-10 flex w-full max-w-3xl flex-col h-[85vh] rounded-xl border border-border bg-background shadow-2xl`,children:[k(`div`,{className:`flex items-center justify-between border-b border-border px-5 py-4 shrink-0`,children:[k(`div`,{className:`min-w-0`,children:[P(`h2`,{className:`text-sm font-semibold text-foreground`,children:r(`integrations.adoptDevices`,{defaultValue:`Adopt devices`})}),P(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5`,children:r(`integrations.adoptDevicesHint`,{defaultValue:`Preview the candidate devices and add the ones you want.`})})]}),k(`div`,{className:`flex items-center gap-3 shrink-0`,children:[g&&k(`label`,{className:`flex items-center gap-1.5 cursor-pointer text-[11px] text-foreground-subtle hover:text-foreground transition-colors`,children:[P(`input`,{type:`checkbox`,checked:_,onChange:e=>v(e.target.checked),className:`accent-primary`}),r(`integrations.importLocations`,{defaultValue:`Import locations from the integration`})]}),P(`button`,{onClick:n,className:`rounded-md p-1 text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close`,children:P(me,{className:`h-4 w-4`})})]})]}),k(`div`,{className:`flex-1 min-h-0 px-5 py-3 flex flex-col gap-2 overflow-hidden`,children:[(L??z)&&R.length===0&&P(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-3 shrink-0`,children:k(`div`,{className:`flex items-start gap-2`,children:[P(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),k(`div`,{className:`min-w-0`,children:[P(`p`,{className:`text-xs font-medium text-destructive`,children:r(`integrations.adoptRefreshFailed`,{defaultValue:`Could not discover devices.`})}),P(`p`,{className:`text-[11px] text-destructive/90 mt-0.5`,children:L??z})]})]})}),b.length>1&&P(ke,{filters:b,activeFilter:S,onSelect:W}),P(`div`,{className:`flex-1 min-h-0`,children:P(o,{mode:`generic`,items:R,pageSize:De,getKey:e=>e.childNativeId,getSearchText:Z,getFilterType:e=>e.type,filterOptions:ee(),filterLabel:r(`integrations.adoptColType`,{defaultValue:`Type`}),isLoading:O.isLoading||I&&R.length===0,searchPlaceholder:r(`integrations.adoptSearch`,{defaultValue:`Search candidates…`}),emptyLabel:(L??z)&&R.length===0?``:r(`integrations.adoptNoCandidates`,{defaultValue:`No candidate devices found.`}),toolbar:k(`button`,{type:`button`,onClick:M,disabled:I,title:r(`integrations.adoptRefreshTitle`,{defaultValue:`Re-scan Home Assistant for devices`}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors disabled:opacity-60 shrink-0`,children:[P(V,{className:`h-3.5 w-3.5 ${I?`animate-spin`:``}`}),r(`integrations.adoptRefresh`,{defaultValue:`Refresh`})]}),columns:[{key:`name`,header:r(`integrations.adoptColName`,{defaultValue:`Name`}),headerClassName:`w-[55%]`,cell:e=>P($,{candidate:e,expandable:!T,expanded:s.has(e.childNativeId),onToggleExpand:()=>oe(e.childNativeId),adoptedLabel:r(`integrations.adoptAlready`,{defaultValue:`Adopted`})})},{key:`type`,header:r(`integrations.adoptColType`,{defaultValue:`Type`}),headerClassName:`w-[30%] hidden sm:table-cell`,cellClassName:`hidden sm:table-cell`,cell:e=>{let t=C(e.type),n=t.icon;return k(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] text-foreground-subtle`,children:[P(n,{className:`h-3.5 w-3.5 shrink-0`}),t.label]})}},{key:`select`,header:``,headerClassName:`w-[15%] text-right`,cellClassName:`text-right`,cell:e=>P(`div`,{className:`flex items-center justify-end`,children:P(`button`,{onClick:()=>ae(e),disabled:e.alreadyAdopted,"aria-label":i.has(e.childNativeId)?`Deselect`:`Select`,className:`inline-flex h-5 w-5 items-center justify-center rounded border ${i.has(e.childNativeId)?`border-primary bg-primary`:`border-border`} ${e.alreadyAdopted?`cursor-not-allowed opacity-50`:``}`,children:i.has(e.childNativeId)&&P(G,{className:`h-3 w-3 text-primary-foreground`})})})}],isExpanded:e=>!T&&s.has(e.childNativeId),renderExpanded:T?void 0:e=>P(Ae,{candidate:e,hiddenChildIds:l.get(e.childNativeId)?.hiddenChildIds??new Set,onToggleChildHidden:t=>se(e.childNativeId,t)}),rowClassName:e=>e.alreadyAdopted?`opacity-60`:i.has(e.childNativeId)?`bg-primary/5`:``})})]}),d&&P(`div`,{className:`border-t border-destructive/30 bg-destructive/5 px-5 py-2 shrink-0`,children:k(`div`,{className:`flex items-start gap-2`,children:[P(q,{className:`h-3.5 w-3.5 text-destructive mt-0.5 shrink-0`}),P(`p`,{className:`text-[11px] text-destructive`,children:d})]})}),k(`div`,{className:`flex items-center justify-between border-t border-border px-5 py-3 shrink-0`,children:[P(`div`,{}),k(`div`,{className:`flex items-center gap-2`,children:[P(`button`,{onClick:n,className:`rounded-lg border border-border px-3 py-1.5 text-xs text-foreground-subtle hover:text-foreground transition-colors`,children:r(`integrations.cancel`,{defaultValue:`Cancel`})}),k(`button`,{onClick:ce,disabled:le===0||B.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,children:[B.isPending&&P(H,{className:`h-3.5 w-3.5 animate-spin`}),r(`integrations.addSelected`,{defaultValue:`Add selected`}),le>0?` (${le})`:``]})]})]})]})]})}function ke({filters:e,activeFilter:t,onSelect:n}){return P(`div`,{role:`tablist`,"aria-label":`Discovery granularity`,className:`inline-flex shrink-0 self-start rounded-lg border border-border bg-surface p-0.5`,children:e.map(e=>{let r=e.id===t;return P(`button`,{type:`button`,role:`tab`,"aria-selected":r,onClick:()=>n(e.id),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${r?`bg-primary text-primary-foreground shadow-sm`:`text-foreground-subtle hover:text-foreground hover:bg-surface-hover`}`,children:e.label},e.id)})})}function $({candidate:e,expandable:t,expanded:n,onToggleExpand:r,adoptedLabel:i}){let a=(e.children??[]).length;return k(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[t&&a>0?k(`button`,{type:`button`,onClick:r,"aria-label":n?`Collapse`:`Expand`,"aria-expanded":n,className:`flex h-5 flex-shrink-0 items-center justify-center gap-0.5 rounded px-0.5 text-[10px] text-foreground-subtle transition-colors hover:bg-surface-hover hover:text-foreground`,children:[P(n?W:de,{className:`h-3.5 w-3.5`}),a]}):P(`span`,{className:`flex h-5 w-5 flex-shrink-0 items-center justify-center text-foreground-subtle/40`,children:`—`}),P(`span`,{className:`truncate text-xs font-medium text-foreground`,children:e.name}),e.alreadyAdopted&&P(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-[9px] font-medium text-success shrink-0`,children:i})]})}function Ae({candidate:e,hiddenChildIds:t,onToggleChildHidden:n}){let r=e.children??[];return r.length===0?null:P(`div`,{className:`space-y-1 py-1`,children:r.map(e=>{let r=t.has(e.childNativeId),i=e.capabilities??[];return k(`div`,{className:`flex items-center gap-2 rounded px-2 py-1 ${r?`opacity-50`:``}`,children:[P(`span`,{className:`text-[11px] text-foreground truncate flex-1 min-w-0`,children:e.name}),i.length>0&&P(`span`,{className:`text-[9px] text-foreground-subtle truncate`,children:i.join(`, `)}),P(`button`,{onClick:()=>n(e.childNativeId),"aria-label":r?`Show child`:`Hide child`,title:r?`Show after adopt`:`Hide after adopt`,className:`flex h-5 w-5 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors flex-shrink-0`,children:P(r?K:U,{className:`h-3 w-3`})})]},e.childNativeId)})})}O();function je({integrationId:e,addonId:t,name:n,kind:r,brokerKind:i,trpc:a,onClose:o}){let{t:s}=ve(),c=M(),l=r===`device-adoption`,{data:u}=d({id:e},{enabled:l}),f=A(()=>{let e=u?.brokerId;return typeof e==`string`?e:null},[u]),p=w();return P(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,onClick:o,children:k(`div`,{className:`max-h-[85vh] w-full max-w-md overflow-y-auto rounded-xl border border-border bg-surface p-5 shadow-xl`,onClick:e=>e.stopPropagation(),children:[k(`div`,{className:`mb-3 flex items-center justify-between`,children:[k(`h2`,{className:`text-sm font-semibold text-foreground`,children:[s(`integrations.editConfig`,{defaultValue:`Edit configuration`}),` — `,n]}),P(`button`,{onClick:o,className:`rounded-md p-1 text-foreground-subtle hover:bg-surface-hover hover:text-foreground`,"aria-label":s(`common.close`,{defaultValue:`Close`}),children:P(me,{className:`h-4 w-4`})})]}),l?i?k(`div`,{className:`space-y-3`,children:[P(`p`,{className:`text-[11px] text-foreground-subtle`,children:s(`integrations.relinkBrokerHelp`,{defaultValue:`Choose the broker this integration connects through. Picking a different broker re-points it and restarts the addon.`})}),f&&k(`p`,{className:`text-[11px] text-foreground`,children:[s(`integrations.currentBroker`,{defaultValue:`Current broker`}),`:`,` `,P(`span`,{className:`font-mono text-foreground-subtle`,children:f})]}),p.isPending?k(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[P(H,{className:`h-3 w-3 animate-spin`}),s(`integrations.saving`,{defaultValue:`Saving…`})]}):P(z,{kind:i,onResolved:t=>{p.mutate({id:e,settings:{brokerId:t}},{onSuccess:()=>{c.invalidateQueries(),o()}})},onBack:o}),p.isError&&P(`p`,{className:`text-[11px] text-danger`,children:s(`integrations.relinkFailed`,{defaultValue:`Failed to update broker link.`})})]}):P(`p`,{className:`text-[11px] text-danger`,children:s(`integrations.noBrokerKind`,{defaultValue:`This integration declares device-adoption but its addon manifest has no brokerKind.`})}):P(T,{trpc:a,addonId:t,nodeId:`hub`,title:n})]})})}O();function Me(){let{t:e}=ve(),{integrationId:n}=ge(),d=M(),m=ue(),[ee,h]=le(),b=I(),[x,S]=N(!1),[C,ne]=N(!1),[w,T]=N(!1),[re,O]=N(!1),[F,z]=N(!1),{data:V,isLoading:se}=l({id:n??``},{enabled:!!n}),{data:U}=f({addonId:V?.addonId??``,nodeId:`hub`},{enabled:!!V?.addonId}),{data:W,isSuccess:G}=te(),K=A(()=>{let e=V?.addonId;return!e||!G?null:(W??[]).find(t=>t.addonId===e)?.kind===`device-adoption`?`device-adoption`:`device-provider`},[W,V?.addonId,G]),{data:de}=E({}),fe=A(()=>(de?.providers??[]).some(e=>e.addonId===V?.addonId),[de,V?.addonId]),J=K!==null,be=J?K===`device-adoption`?e(`integrations.adoptDevices`,{defaultValue:`Adopt devices`}):e(`integrations.addDevice`):e(`integrations.addDeviceLoading`,{defaultValue:`Loading…`}),xe=A(()=>{let e=V?.addonId;return!e||!G?null:(W??[]).find(t=>t.addonId===e)?.brokerKind??null},[W,V?.addonId,G]),Se=A(()=>{let e=V?.addonId;return!e||!G?null:(W??[]).find(t=>t.addonId===e)?.mode??null},[W,V?.addonId,G]);ie(()=>{ee.get(`add`)===`1`&&J&&(S(!0),h(e=>{let t=new URLSearchParams(e);return t.delete(`add`),t},{replace:!0}))},[ee,J,h]);let Ce=U!=null&&Array.isArray(U.sections)&&U.sections.some(e=>e.fields.length>0),{data:Y}=a({},{refetchInterval:5e3}),X=[[`integrations`,`get`],{input:{id:n??``},type:`query`}],Z=g({onMutate:async e=>{await d.cancelQueries({queryKey:X});let t=d.getQueryData(X);return t!=null&&d.setQueryData(X,{...t,enabled:e.enabled}),{previous:t}},onError:(e,t,n)=>{let r=n;r?.previous!=null&&d.setQueryData(X,r.previous)},onSettled:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Q=y({onSuccess:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]}),O(!1),m(`/integrations`)}}),Te=t({onSuccess:()=>{d.invalidateQueries({queryKey:[[`integrations`]]}),d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),Ee=i({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),De=v({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),ke=u({onSuccess:()=>{d.invalidateQueries({queryKey:[[`deviceManager`]]})}}),$=A(()=>Y??[],[Y]),Ae=A(()=>{let e=new Map;for(let t of $)e.set(t.id,{id:t.id,name:t.name??t.stableId??`#${String(t.id)}`});return e},[$]),Me=D(e=>Ae.get(e)??null,[Ae]),Ne=D(e=>P(L,{type:e,size:`sm`}),[]),Pe=D(e=>m(`/devices/${String(e)}`),[m]),Fe=A(()=>{let e=V?.addonId;return e?$.filter(t=>t.addonId===e):[]},[$,V?.addonId]),Ie=A(()=>s(Fe).length,[Fe]);return se?k(`div`,{className:`p-4`,children:[P(`div`,{className:`h-16 rounded-lg bg-surface animate-pulse mb-4`}),P(`div`,{className:`h-40 rounded-lg bg-surface animate-pulse`})]}):V?k(`div`,{className:`p-4 space-y-4 overflow-x-hidden`,children:[P(r,{items:[{label:`Integrations`,onClick:()=>m(`/integrations`)},{label:V.name}]}),k(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[k(`div`,{className:`flex items-center gap-3 min-w-0`,children:[P(`img`,{src:`/api/addon-assets/${V.addonId}/assets/icon.svg`,alt:``,className:`h-8 w-8 rounded-lg shrink-0`,onError:e=>{e.target.style.display=`none`}}),k(`div`,{className:`min-w-0`,children:[P(`h1`,{className:`text-lg font-semibold text-foreground truncate`,children:V.name}),k(`p`,{className:`text-[11px] text-foreground-subtle mt-0.5 truncate`,children:[V.addonId,` · `,Ie,` `,e(`integrations.devices`)]})]})]}),k(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[fe&&k(`button`,{onClick:()=>ne(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-2.5 py-1.5 text-xs font-medium text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:`Scan the network for devices (incl. a different subnet)`,children:[P(B,{className:`h-3.5 w-3.5`}),`Scan network`]}),k(`button`,{onClick:()=>S(!0),disabled:!J,className:`flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground shadow-sm disabled:opacity-50 disabled:cursor-not-allowed`,title:be,children:[P(R,{className:`h-3.5 w-3.5`}),be]}),k(`div`,{className:`inline-flex items-center gap-2 rounded-lg border px-3 py-1.5 transition-colors ${Z.isPending?`opacity-60`:``} ${V.enabled?`border-success/30 bg-success/5`:`border-border bg-surface`}`,title:e(`integrations.toggleHint`,{defaultValue:`Click to toggle`}),children:[P(c,{checked:V.enabled,onCheckedChange:e=>Z.mutate({id:n,enabled:e}),disabled:Z.isPending,"aria-label":V.enabled?`Disable integration`:`Enable integration`}),P(`span`,{className:`text-[11px] font-medium ${V.enabled?`text-success`:`text-foreground-subtle`}`,children:V.enabled?`Enabled`:`Disabled`}),Z.isPending&&P(H,{className:`h-3 w-3 animate-spin text-foreground-subtle`})]}),Se!==`standalone`&&(Ce||K===`device-adoption`)&&k(`button`,{onClick:()=>T(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,children:[P(he,{className:`h-3 w-3`}),e(`integrations.config`)]}),k(`button`,{onClick:()=>z(!0),className:`flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,title:e(`integrations.logs`,{defaultValue:`View logs`}),children:[P(pe,{className:`h-3 w-3`}),e(`integrations.logs`,{defaultValue:`Logs`})]}),P(p,{label:`Restart`,icon:oe,title:`Restart "${V.name}"?`,description:`Restarting the addon will briefly disconnect every device backed by it (${Ie} active). Streams will reconnect automatically.`,confirmLabel:`Restart`,triggerVariant:`outline`,confirmVariant:`danger`,disabled:Te.isPending,action:()=>Te.mutateAsync({addonId:V.addonId})}),k(`button`,{onClick:()=>O(!0),className:`flex items-center gap-1.5 rounded-lg border border-danger bg-danger/10 px-3 py-1.5 text-[11px] font-medium text-danger hover:bg-danger hover:text-background transition-colors`,title:e(`integrations.delete`,{defaultValue:`Delete integration`}),children:[P(_e,{className:`h-3 w-3`}),e(`integrations.delete`,{defaultValue:`Delete`})]})]})]}),P(o,{context:`integration-detail`,devices:$,trpc:b.trpcClient,defaultView:`cards`,forceAddon:V.addonId,urlScope:`root`,lsKey:`integration-detail:${V.addonId}`,resolveIntegrationIcon:Ne,resolveParent:Me,onNavigate:Pe,batchActions:{remove:Ee.mutate,disable:De.mutate,enable:ke.mutate},onDeleteDevice:e=>Ee.mutate({deviceId:e.id})}),x&&n&&K===`device-adoption`&&P(Oe,{addonId:V.addonId,integrationId:n,onClose:()=>S(!1)}),x&&n&&K===`device-provider`&&P(we,{open:x,integrationId:n,addonId:V.addonId,onClose:()=>S(!1)}),C&&V&&P(ae,{open:C,scope:{addonId:V.addonId,label:V.name},onClose:()=>ne(!1)}),w&&n&&K!==null&&P(je,{integrationId:n,addonId:V.addonId,name:V.name,kind:K,brokerKind:xe,trpc:b.trpcClient,onClose:()=>T(!1)}),F&&P(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-6`,onClick:()=>z(!1),children:k(`div`,{className:`flex flex-col rounded-xl border border-border bg-surface shadow-xl w-full max-w-5xl h-[80vh]`,onClick:e=>e.stopPropagation(),children:[k(`div`,{className:`flex items-center justify-between border-b border-border px-4 py-2.5`,children:[k(`div`,{className:`flex items-center gap-2 min-w-0`,children:[P(pe,{className:`h-4 w-4 text-primary shrink-0`}),P(`h2`,{className:`text-sm font-semibold text-foreground truncate`,children:V.name}),k(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate`,children:[V.addonId,n?` · ${n}`:``]})]}),P(`button`,{onClick:()=>z(!1),className:`flex h-7 w-7 items-center justify-center rounded text-foreground-subtle hover:text-foreground hover:bg-surface-hover transition-colors`,"aria-label":`Close logs`,children:P(me,{className:`h-4 w-4`})})]}),P(`div`,{className:`flex-1 min-h-0 overflow-hidden`,children:P(_,{addonId:V.addonId,limit:200,maxHeight:`max-h-full`,showScope:!1,className:`h-full border-0 rounded-none`})})]})}),re&&P(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60`,onClick:()=>!Q.isPending&&O(!1),children:k(`div`,{className:`rounded-xl border border-border bg-background p-5 shadow-2xl w-96 space-y-3`,onClick:e=>e.stopPropagation(),children:[k(`div`,{className:`flex items-start gap-3`,children:[P(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-lg bg-danger/10 shrink-0`,children:P(q,{className:`h-4 w-4 text-danger`})}),k(`div`,{className:`min-w-0`,children:[P(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`integrations.deleteTitle`,{defaultValue:`Delete integration?`})}),P(`p`,{className:`mt-1 text-[11px] text-foreground-subtle`,children:e(`integrations.deleteWarning`,{defaultValue:`This removes the integration "{{name}}" and its {{count}} device(s). The addon will restart. This cannot be undone.`,name:V.name,count:Ie})})]})]}),Q.error&&P(`div`,{className:`rounded-lg border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:Q.error instanceof Error?Q.error.message:String(Q.error)}),k(`div`,{className:`flex items-center justify-end gap-2 pt-1`,children:[P(`button`,{onClick:()=>O(!1),disabled:Q.isPending,className:`rounded-lg border border-border px-3 py-1.5 text-[11px] text-foreground-subtle hover:text-foreground transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,children:e(`integrations.cancel`,{defaultValue:`Cancel`})}),P(`button`,{onClick:()=>Q.mutate({id:n}),disabled:Q.isPending,className:`inline-flex items-center gap-1.5 rounded-lg bg-danger px-3 py-1.5 text-[11px] font-medium text-background hover:bg-danger/90 transition-colors disabled:opacity-60 disabled:cursor-not-allowed`,children:Q.isPending?k(j,{children:[P(H,{className:`h-3 w-3 animate-spin`}),e(`integrations.deleting`,{defaultValue:`Deleting…`})]}):k(j,{children:[P(_e,{className:`h-3 w-3`}),e(`integrations.confirmDelete`,{defaultValue:`Delete integration`})]})})]})]})})]}):k(`div`,{className:`flex flex-col items-center justify-center py-20 px-6 text-center gap-4`,children:[P(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-foreground-subtle/10`,children:P(ye,{className:`h-6 w-6 text-foreground-subtle`})}),k(`div`,{className:`space-y-1 max-w-sm`,children:[P(`h2`,{className:`text-sm font-semibold text-foreground`,children:e(`integrations.integrationNotFound`,{defaultValue:`Integration not found`})}),P(`p`,{className:`text-[11px] text-foreground-subtle`,children:e(`integrations.integrationNotFoundHint`,{defaultValue:`The integration "{{id}}" does not exist. It may have been deleted, or the URL may be wrong.`,id:n??``})})]}),k(`button`,{onClick:()=>m(`/integrations`),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-1.5 text-[11px] font-medium text-foreground hover:bg-surface-hover transition-colors`,children:[P(ce,{className:`h-3 w-3`}),e(`integrations.backToList`,{defaultValue:`Back to integrations`})]})]})}export{Me as IntegrationDetailPage};
@@ -1 +0,0 @@
1
- import{$a as e,Ar as t,Cr as n,Fa as r,Or as i,Qa as a,Sa as o,Sr as s,Tr as c,_r as l,br as u,eo as d,gr as f,kr as p,ta as m,vr as h,vt as g,wr as _,xr as v,yr as ee,yt as y}from"./src-C9tUE6VN.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-DJCxIXmd.js";import{p as A}from"./player-overlays-G3UGtBzC.js";import{n as j,t as ne}from"./rotate-ccw-C9aSKyTE.js";import{t as M}from"./copy-uF3P0mCb.js";import{n as re,t as N}from"./AddonCollectionPage-DqaY4er4.js";import{t as ie}from"./refresh-cw-NUBl_9F6.js";import{t as ae}from"./square-DCFTa1lw.js";import{t as oe}from"./wifi-0f3nqfEf.js";import{C as P,E as F,L as se,S as ce,W as I,i as le,k as L,l as ue,m as R,o as z,x as de,y as B}from"./index-BXAOUGFx.js";import{t as V}from"./AdminPage-BwmGKnRf.js";import{t as H}from"./AdminTabs-BbJVdoRX.js";import{t as U}from"./addon-display-names-DvSEQty-.js";var fe=I(`log-in`,[[`path`,{d:`m10 17 5-5-5-5`,key:`1bsop3`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`,key:`u53s6r`}]]),pe=I(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]),W=I(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]);x();var G=5e3,me={connected:!1,endpoint:null};function he(){let e=T(),n=y({capName:`network-access`},{refetchInterval:G}),r=g(void 0,{refetchInterval:G}),i=C(()=>U(r.data??[]),[r.data]),a=C(()=>(n.data??[]).map(e=>({addonId:e.addonId,displayName:i.get(e.addonId)??e.addonId,isActive:e.isActive})),[n.data,i]),[o,s]=E(null),[c,l]=E({}),u=(t,n)=>{let r=n?.addonId;e.invalidateQueries({queryKey:[[`networkAccess`,`getStatus`],{input:{addonId:r},type:`query`}]}),s(null),l(e=>{if(r===void 0||!(r in e))return e;let t={...e};return delete t[r],t})},d=(e,t)=>{s(null);let n=t?.addonId;if(n===void 0)return;let r=e instanceof Error?e.message:String(e);l(e=>({...e,[n]:r}))},f=p({onSuccess:u,onError:d}),m=t({onSuccess:u,onError:d});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:F,itemIcon:F,capability:`network-access`,installButtonLabel:`Add tunnel`,items:a,isLoading:n.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(ge,{addonId:e.addonId}),itemError:e=>c[e.addonId]??null,renderPrimaryAction:e=>D(_e,{addonId:e.addonId,busyId:o,onStart:e=>{s(e),f.mutate({addonId:e})},onStop:e=>{s(e),m.mutate({addonId:e})}})})}function K(e){let{data:t}=i({addonId:e},{refetchInterval:G,retry:!1}),n=t?k.safeParse(t):null;return n?.success?n.data:me}function ge({addonId:e}){let t=K(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(L,{className:`h-3 w-3`}),t.endpoint.url]})]})}function _e({addonId:e,busyId:t,onStart:n,onStop:r}){let i=K(e),a=t===e;return i.connected?S(d,{size:`sm`,variant:`secondary`,disabled:a,onClick:()=>r(e),children:[a?D(P,{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(P,{className:`h-3 w-3 animate-spin`}):D(re,{className:`h-3 w-3`}),`Start`]})}x();var q=3e4;function ve(e){let t=[];for(let n of e)typeof n.urls==`string`?t.push(n.urls):t.push(...n.urls);return t}function ye(){let e=y({capName:`turn-provider`},{refetchInterval:q}),t=g(void 0,{refetchInterval:q}),n=m(),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(be,{addonId:e.addonId,enabled:e.isActive}),trailing:S(a,{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 be({addonId:e,enabled:t}){let n=m({addonId:e},{enabled:t,retry:!1}),r=C(()=>ve(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 xe={lan:B,wifi:oe,docker:j,vpn:ce,loopback:R,other:R},Se={lan:`LAN`,wifi:`Wi-Fi`,docker:`Docker`,vpn:`VPN`,loopback:`Loopback`,other:`Other`},Ce=[`lan`,`wifi`,`vpn`,`docker`,`other`,`loopback`];function we(e){let{interfaces:t,disabled:n,hideLoopback:r,ipv4Only:i,emptyMessage:a}=e,o=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 Ce.filter(t=>e.has(t)).map(t=>({kind:t,items:e.get(t)}))},[o]),c=t=>e.mode===`single`?e.value===t:e.value.includes(t),l=t=>{if(n||t.kind===`loopback`)return;if(e.mode===`single`){e.onChange(e.value===t.address?null:t.address);return}let r=new Set(e.value);r.has(t.address)?r.delete(t.address):r.add(t.address),e.onChange([...r])};return o.length===0?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(xe[t]??R,{className:`h-3.5 w-3.5 text-foreground-subtle`}),D(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-foreground-subtle`,children:Se[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 J={"lan-ipv4":`bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,"lan-ipv6":`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`,loopback:`bg-foreground-subtle/15 text-foreground-subtle`};function Te(){let e=T(),t=A(),n=h(void 0,{refetchInterval:3e4}),r=f(void 0),i=u({onSuccess:()=>{e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),o=ee({onSuccess:t=>{m(t.addresses),e.invalidateQueries({queryKey:[[`localNetwork`]]})}}),s=C(()=>n.data?.interfaces??[],[n.data]),c=l({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}),[p,m]=E([]),[g,_]=E(!1);te(()=>{!g&&r.data&&(m(r.data.addresses),_(!0))},[r.data,g]);let v=r.data?.addresses??[],y=C(()=>{if(p.length!==v.length)return!0;let e=[...p].toSorted(),t=[...v].toSorted();return e.some((e,n)=>e!==t[n])},[p,v]),b=()=>{i.mutate({addresses:[...p]})},x=()=>{m(v)},w=()=>{m([])},O=()=>{n.refetch(),c.refetch(),r.refetch()},k=async()=>{try{let e=await t.raceConnectionEndpoints({perCandidateTimeoutMs:1500});console.info(`[network-addresses] race result`,e)}catch(e){console.warn(`[network-addresses] race failed`,e)}},j=c.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:n.isLoading,children:[D(ie,{className:`h-3 w-3 ${n.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(a,{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:p.length===0?`Auto — every non-loopback / non-link-local interface participates.`:`${p.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||i.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:p.length===0||i.isPending,children:[D(ne,{className:`h-3 w-3`}),`Clear`]}),y&&D(d,{size:`sm`,variant:`secondary`,onClick:x,disabled:i.isPending,children:`Discard`}),S(d,{size:`sm`,variant:`primary`,onClick:b,disabled:!y||i.isPending,children:[D(pe,{className:`h-3 w-3`}),i.isPending?`Saving…`:`Save`]})]})]}),D(`div`,{className:`p-4`,children:D(we,{mode:`multiple`,interfaces:s,value:p,onChange:m,disabled:i.isPending,emptyMessage:n.isLoading?`Loading interfaces…`:`No interfaces detected.`})})]}),S(a,{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:c.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 ${J[e.kind]??J.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 Ee={mesh:`bg-violet-500/15 text-violet-700 dark:text-violet-300`,public:`bg-blue-500/15 text-blue-700 dark:text-blue-300`},Y=5e3,De=3e4,Oe={joined:!1,meshIp:``,magicDnsHostname:``,peerCount:0,endpoints:[],tenantName:``,magicDnsSuffix:``,userLogin:null,controlPlaneUrl:``,keyExpiry:null};function ke(){let e=y({capName:`mesh-network`},{refetchInterval:Y}),t=g(void 0,{refetchInterval:Y}),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(Z,{addonId:e.addonId}),renderPrimaryAction:e=>D(Ae,{addonId:e.addonId}),renderExpandedPanel:e=>D(je,{addonId:e.addonId})})}function X(e){let{data:t,isLoading:n}=v({addonId:e},{refetchInterval:Y,retry:!1}),r=t?O.safeParse(t):null;return{status:r?.success?r.data:Oe,isLoading:n}}function Z({addonId:e}){let{status:t}=X(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 t=T(),[n,r]=E(!1),[i,a]=E(null),o=A(),{status:l}=X(e),u=b(()=>{t.invalidateQueries({queryKey:[[`meshNetwork`]]})},[t]),f=c(),p=s({onSuccess:u}),m=_({onSuccess:u}),h=b(async()=>{r(!0);let t={cancelled:!1};a(t);try{let n=await f.mutateAsync({addonId:e});if(t.cancelled)return;n.loginUrl&&window.open(n.loginUrl,`_blank`,`noopener,noreferrer`);let r=Date.now();for(;!t.cancelled&&(await Ie(2e3),!t.cancelled);){let t=await o.trpcClient.meshNetwork.getStatus.query({addonId:e}).catch(()=>null),n=t?O.safeParse(t):null;if(n?.success&&n.data.joined){u();break}if(Date.now()-r>6e5)break}}finally{r(!1),a(null)}},[e,u,f,o]),g=b(()=>{i&&(i.cancelled=!0),r(!1),a(null)},[i]);return D(w,{children:l.joined?S(w,{children:[S(d,{size:`sm`,variant:`secondary`,disabled:p.isPending,onClick:()=>p.mutate({addonId:e}),children:[p.isPending?D(P,{className:`h-3 w-3 animate-spin`}):D(de,{className:`h-3 w-3`}),`Disconnect`]}),S(d,{size:`sm`,variant:`ghost`,disabled:m.isPending,onClick:()=>m.mutate({addonId:e}),children:[m.isPending?D(P,{className:`h-3 w-3 animate-spin`}):D(W,{className:`h-3 w-3`}),`Log out`]})]}):n?S(d,{size:`sm`,variant:`ghost`,onClick:g,children:[D(le,{className:`h-3 w-3 mr-1`}),` Cancel`]}):S(w,{children:[S(d,{size:`sm`,variant:`primary`,onClick:()=>void h(),children:[D(fe,{className:`h-3 w-3`}),`Connect`]}),S(d,{size:`sm`,variant:`ghost`,disabled:m.isPending,onClick:()=>m.mutate({addonId:e}),children:[m.isPending?D(P,{className:`h-3 w-3 animate-spin`}):D(W,{className:`h-3 w-3`}),`Log out`]})]})})}function je({addonId:e}){let{status:t}=X(e),r=n({addonId:e},{refetchInterval:De,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 ${Ee[e.scope]??`bg-foreground-subtle/15 text-foreground-subtle`}`,children:[e.scope===`public`?D(F,{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(L,{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:t,loading:n}){let i=C(()=>t.map(e=>({...e,_id:e.id})),[t]),a=b(e=>{e&&navigator.clipboard?.writeText(e)},[]),o=C(()=>[{key:`hostname`,header:`Hostname`,render:t=>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:t.hostname||`(unknown)`}),t.isSelf&&D(e,{variant:`info`,children:`self`}),t.exitNodeOption&&D(e,{variant:`warning`,children:`exit-node`})]}),t.userLogin&&D(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:t.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:()=>a(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:()=>a(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:t=>S(`div`,{className:`flex items-center gap-1.5`,children:[D(e,{variant:Fe(t.connection),children:t.connection}),t.relay&&D(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:t.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):`—`})}],[a]);return n&&t.length===0?S(`div`,{className:`p-4 text-xs text-foreground-subtle`,children:[D(P,{className:`h-3 w-3 animate-spin inline mr-1`}),` Loading peers…`]}):t.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(r,{columns:o,rows:i,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:R,content:D(Te,{})},{id:`remote-access`,label:`Remote Access`,icon:F,content:D(he,{})},{id:`mesh`,label:`Mesh Networks`,icon:j,content:D(ke,{})},{id:`turn`,label:`TURN Servers`,icon:B,content:D(ye,{})}]})})}export{Le as NetworkPage};