@camstack/addon-admin-ui 1.2.59 → 1.2.61

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 (151) hide show
  1. package/dist/assets/AddLocationWizard-BVrPN8yV.js +1 -0
  2. package/dist/assets/AddonCollectionPage-Cluggqrl.js +1 -0
  3. package/dist/assets/Addons-pf4_6Np6.js +1 -0
  4. package/dist/assets/{AdminPage-Dq33XE9j.js → AdminPage-CCD07UMs.js} +1 -1
  5. package/dist/assets/{AdminTabs-Co61VJ4U.js → AdminTabs-D4DXIa-o.js} +1 -1
  6. package/dist/assets/AiProfiles-Dc-3w9Z5.js +3 -0
  7. package/dist/assets/BrokerForm-DpZEb2oo.js +1 -0
  8. package/dist/assets/Build-DFf7JJQN.js +32 -0
  9. package/dist/assets/Capabilities-fyyhemKk.js +1 -0
  10. package/dist/assets/{CapabilityBadges-Do48_jzx.js → CapabilityBadges-CFAqIVEN.js} +1 -1
  11. package/dist/assets/Cluster-BI79yXHi.js +1 -0
  12. package/dist/assets/Data-BnH1FBcv.js +1 -0
  13. package/dist/assets/DetectionIntelligence-pZ34_QKw.js +1 -0
  14. package/dist/assets/{DeviceAggregateSection-n3hYy5qm.js → DeviceAggregateSection-DcU4HtPo.js} +1 -1
  15. package/dist/assets/DeviceDetail-D4IEMIPA.js +2 -0
  16. package/dist/assets/Devices-Qvmjz6OV.js +1 -0
  17. package/dist/assets/EmbedPlayerPage-BiOYECZo.js +1 -0
  18. package/dist/assets/Events-BkGGzjc6.js +1 -0
  19. package/dist/assets/FormBuilder-Ce9uWxtp.js +1 -0
  20. package/dist/assets/Identity-Dz2q6O35.js +1 -0
  21. package/dist/assets/IntegrationDetail-BgYnCOqc.js +1 -0
  22. package/dist/assets/Integrations-CGDgpbY3.js +1 -0
  23. package/dist/assets/Integrations-JZkpFkbO.js +1 -0
  24. package/dist/assets/Logs-Dc8myuGB.js +1 -0
  25. package/dist/assets/{MaskShapeCanvas-pGn6MKOi.js → MaskShapeCanvas-Dcpby34M.js} +1 -1
  26. package/dist/assets/MotionZonesSettings-CNAneuwi.js +1 -0
  27. package/dist/assets/MyAccess-BplkKorv.js +2 -0
  28. package/dist/assets/Network-DkXgbHRL.js +1 -0
  29. package/dist/assets/NodeAddonsSettingsPanel-qSFnzXqZ.js +1 -0
  30. package/dist/assets/NodeInferenceDevices-B7RYmrXb.js +1 -0
  31. package/dist/assets/Notifications-CsUJcPdF.js +1 -0
  32. package/dist/assets/Pipeline-BVix_5wm.js +1 -0
  33. package/dist/assets/Plates-Cn1Al2WA.js +1 -0
  34. package/dist/assets/PrivacyMaskSettings-GAkxAsA3.js +1 -0
  35. package/dist/assets/{ProviderIcon-B5c5wlw9.js → ProviderIcon-CQo4yDQS.js} +1 -1
  36. package/dist/assets/Recordings-DZMmDA_4.js +1 -0
  37. package/dist/assets/ScanNetworkModal-TrU5QhWB.js +1 -0
  38. package/dist/assets/SceneMonitorEditor-DcTfkrW3.js +1 -0
  39. package/dist/assets/Scenes-bMn8sgm0.js +1 -0
  40. package/dist/assets/{SchemaTabBar-BrF8ZUiR.js → SchemaTabBar-DC28nb9j.js} +1 -1
  41. package/dist/assets/Settings-B1YsrVcn.js +1 -0
  42. package/dist/assets/{Showroom-CBvbRA83.js → Showroom-Cik2ivrC.js} +1 -1
  43. package/dist/assets/{StableTabPanel-p16epZGa.js → StableTabPanel-Dc954AQl.js} +1 -1
  44. package/dist/assets/{StatusBadge-Dcr2bw58.js → StatusBadge-CeptlsPG.js} +1 -1
  45. package/dist/assets/{Terminal-BSwEKm0g.js → Terminal-BWct2hhL.js} +2 -2
  46. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-xKOm5ETc.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-B59PxHv9.js} +1 -1
  47. package/dist/assets/_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DhP-Lgiq.js +1 -0
  48. package/dist/assets/_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_client__loadShare__.js-8kv6pj9W.js +6 -0
  49. package/dist/assets/{_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DkcC9IVF.js → _virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_react_mf_2_query__loadShare__.js-DN3UpM8E.js} +1 -1
  50. package/dist/assets/{_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.js-D9-wIasd.js → _virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom__loadShare__.js-BsvPG3BX.js} +1 -1
  51. package/dist/assets/{_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-DstpX0yz.js → _virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_dom_mf_1_client__loadShare__.js-DtoGixA1.js} +1 -1
  52. package/dist/assets/{_virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_konva__loadShare__.js-BBBrLLEa.js → _virtual_mf___mfe_internal__admin_ui_host__loadShare__react_mf_2_konva__loadShare__.js-PmiLsYEK.js} +1 -1
  53. package/dist/assets/{authed-media-B8T1dsFh.js → authed-media-BPd_L9jr.js} +1 -1
  54. package/dist/assets/{bell-ring-BqgJ8dnI.js → bell-ring-CtdRZtjG.js} +1 -1
  55. package/dist/assets/{boxes-BCCj5PaE.js → boxes-BN_wTQoj.js} +1 -1
  56. package/dist/assets/build-cluster-graph-JVj1fl5o.js +7 -0
  57. package/dist/assets/circle-check-big-KvCernzh.js +1 -0
  58. package/dist/assets/{circle-x-DmD78bDU.js → circle-x-DKEv2fk-.js} +1 -1
  59. package/dist/assets/clock-Ddu_eThB.js +1 -0
  60. package/dist/assets/{copy-lMFz0Is-.js → copy-C0Y9pMFE.js} +1 -1
  61. package/dist/assets/{debounced-invalidate-CCYTebYW.js → debounced-invalidate-CYoigLZW.js} +1 -1
  62. package/dist/assets/dist-Bz6O5BsH.js +345 -0
  63. package/dist/assets/{dist-CK_B4BKB.js → dist-DVOPUibu.js} +1 -1
  64. package/dist/assets/{download-CXXQf3fF.js → download-B538th-h.js} +1 -1
  65. package/dist/assets/{face-bbox-DAP66Zl4.js → face-bbox-0omHJ2v9.js} +1 -1
  66. package/dist/assets/{hard-drive-gxnGyiw0.js → hard-drive-DFBgqBxK.js} +1 -1
  67. package/dist/assets/{hostInit-B_AsKiXE.js → hostInit-CiIhfzzr.js} +1 -1
  68. package/dist/assets/index-Dr-ap6SH.js +4 -0
  69. package/dist/assets/{key-round-ClzJuSaS.js → key-round-D1XSxvLS.js} +1 -1
  70. package/dist/assets/{mf-entry-bootstrap-0-53feb26e.js → mf-entry-bootstrap-0-82869dcc.js} +2 -2
  71. package/dist/assets/{pencil-OtLKJIw8.js → pencil-CZ2gMyTB.js} +1 -1
  72. package/dist/assets/play-BrdA8mXB.js +1 -0
  73. package/dist/assets/player-overlays-7AKPeTm-.js +1 -0
  74. package/dist/assets/plus-ChsVL8uT.js +1 -0
  75. package/dist/assets/power-Dz2il9ai.js +1 -0
  76. package/dist/assets/{radio-B8HIjRjm.js → radio-C0T0_Ki5.js} +1 -1
  77. package/dist/assets/{refresh-cw-BwezRSth.js → refresh-cw-DuE4ONv-.js} +1 -1
  78. package/dist/assets/remoteEntry-CgpjK5QJ.js +1 -0
  79. package/dist/assets/rotate-ccw-DS5e2J2f.js +1 -0
  80. package/dist/assets/rotate-cw-Bb9OhnRT.js +1 -0
  81. package/dist/assets/search-BunRfhTv.js +1 -0
  82. package/dist/assets/{send-DLoLyQZY.js → send-CiGeFhM_.js} +1 -1
  83. package/dist/assets/{server-jIBmmmio.js → server-BBJTl0ih.js} +1 -1
  84. package/dist/assets/square-BlgtgcV9.js +1 -0
  85. package/dist/assets/{square-check-big-CKAjnVKI.js → square-check-big-DEpi1DZf.js} +1 -1
  86. package/dist/assets/src-BaVKQIP9.js +345 -0
  87. package/dist/assets/src-CgOOvCVA.js +67 -0
  88. package/dist/assets/{undo-2-8_qvXX1O.js → undo-2-BEASNScj.js} +1 -1
  89. package/dist/assets/{upload-DUXkaKq1.js → upload-CCWw0hX4.js} +1 -1
  90. package/dist/assets/use-scenes-feed-BrAVTu20.js +1 -0
  91. package/dist/assets/{useBodyScrollLock-B_rtaBV1.js → useBodyScrollLock-BDocajQE.js} +1 -1
  92. package/dist/assets/useEventInvalidation-CnCqhaHZ.js +1 -0
  93. package/dist/assets/{video-DKFg6rjo.js → video-BEAVV4bf.js} +1 -1
  94. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-DRkfmg3i.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-D8I8UoDY.js} +2 -2
  95. package/dist/assets/{wifi-DT5Z6S_y.js → wifi-sgX03Yna.js} +1 -1
  96. package/dist/assets/{zap-B5xlyN9v.js → zap-DVVII2tr.js} +1 -1
  97. package/dist/index.html +5 -5
  98. package/dist/server/addon.js +314 -45
  99. package/package.json +1 -1
  100. package/dist/assets/AddLocationWizard-BXcL90QM.js +0 -1
  101. package/dist/assets/AddonCollectionPage-C7QSc0L5.js +0 -1
  102. package/dist/assets/Addons-BjibMtF0.js +0 -1
  103. package/dist/assets/AiProfiles-BTRgo8wQ.js +0 -3
  104. package/dist/assets/BrokerForm-dYfcx-yx.js +0 -1
  105. package/dist/assets/Build-CeZh7cjz.js +0 -32
  106. package/dist/assets/Capabilities-DqpHPDt5.js +0 -1
  107. package/dist/assets/Cluster-C1ow3yuB.js +0 -1
  108. package/dist/assets/Data-Bmealxcc.js +0 -1
  109. package/dist/assets/DetectionIntelligence-DSjppxYS.js +0 -1
  110. package/dist/assets/DeviceDetail-f12eUwKC.js +0 -2
  111. package/dist/assets/Devices-CMuMzwTK.js +0 -1
  112. package/dist/assets/EmbedPlayerPage-D5CGJj62.js +0 -1
  113. package/dist/assets/Events-CWhiAlpv.js +0 -1
  114. package/dist/assets/FormBuilder-DVbN4jV5.js +0 -1
  115. package/dist/assets/Identity-BxlWiwaZ.js +0 -1
  116. package/dist/assets/IntegrationDetail-D-EyePxA.js +0 -1
  117. package/dist/assets/Integrations-CVh8WXwB.js +0 -1
  118. package/dist/assets/Integrations-fubIeAyS.js +0 -1
  119. package/dist/assets/Logs-BRgM3t9y.js +0 -1
  120. package/dist/assets/MotionZonesSettings-BQz60XWV.js +0 -1
  121. package/dist/assets/MyAccess-kWZq3W2o.js +0 -2
  122. package/dist/assets/Network-CgSVh1De.js +0 -1
  123. package/dist/assets/NodeAddonsSettingsPanel-DJKQxT7V.js +0 -1
  124. package/dist/assets/NodeInferenceDevices-BTPZ_wyg.js +0 -1
  125. package/dist/assets/Notifications-NpPQQefM.js +0 -1
  126. package/dist/assets/Pipeline-BaYygdkg.js +0 -1
  127. package/dist/assets/Plates-jNVVmALy.js +0 -1
  128. package/dist/assets/PrivacyMaskSettings-C4YaoDu_.js +0 -1
  129. package/dist/assets/Recordings-D5v6ma1R.js +0 -1
  130. package/dist/assets/ScanNetworkModal-WPD06cKp.js +0 -1
  131. package/dist/assets/SceneMonitorEditor-Czf-iZgv.js +0 -1
  132. package/dist/assets/Settings-DvWeXqKw.js +0 -1
  133. package/dist/assets/_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js +0 -1
  134. package/dist/assets/_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_trpc_mf_1_client__loadShare__.js-CSJxMxg6.js +0 -6
  135. package/dist/assets/build-cluster-graph-DMQ4vDW2.js +0 -7
  136. package/dist/assets/circle-check-big-CQsfhCrZ.js +0 -1
  137. package/dist/assets/clock-0kqs7-NB.js +0 -1
  138. package/dist/assets/dist-BX6atE5N.js +0 -345
  139. package/dist/assets/index-B6kDpXr5.js +0 -4
  140. package/dist/assets/play-Q-R5vHEh.js +0 -1
  141. package/dist/assets/plus-vrCV3Fn-.js +0 -1
  142. package/dist/assets/power-Dw-9Qin8.js +0 -1
  143. package/dist/assets/remoteEntry-DOOomD9n.js +0 -1
  144. package/dist/assets/rotate-ccw-uOQBDtri.js +0 -1
  145. package/dist/assets/rotate-cw-B6qXQ5pJ.js +0 -1
  146. package/dist/assets/search-iOwuoJNQ.js +0 -1
  147. package/dist/assets/square-CgzDPTwM.js +0 -1
  148. package/dist/assets/src-BizjMCcy.js +0 -345
  149. package/dist/assets/src-BmAmiAXy.js +0 -67
  150. package/dist/assets/useEventInvalidation-Dovpg3no.js +0 -1
  151. package/dist/assets/widget-panel-BF8s8cZY.js +0 -1
@@ -1 +0,0 @@
1
- import{Ao as e,Ct as t,Do as n,Dt as r,Et as i,Ft as a,Hr as o,It as s,Jr as c,Lt as l,Mt as u,Nt as d,Ot as f,St as p,_t as m,b as h,bt as g,g as _,jt as v,kt as y,v as ee,vt as b,wo as te,wt as ne,xt as re,yt as x}from"./src-BmAmiAXy.js";import{I as S,K as C,Q as w,R as ie,S as T,W as E,b as D,o as ae,q as O,x as k,z as A}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{yt as oe}from"./src-BizjMCcy.js";import{c as se}from"./widget-panel-BF8s8cZY.js";import{t as j}from"./clock-0kqs7-NB.js";import{t as M}from"./download-CXXQf3fF.js";import{t as ce}from"./plus-vrCV3Fn-.js";import{t as N}from"./refresh-cw-BwezRSth.js";import{t as le}from"./search-iOwuoJNQ.js";import{t as P}from"./upload-DUXkaKq1.js";import{G as F,L as I,N as ue,R as L,S as R,Y as z,g as de,i as B,m as V,p as fe,q as H,s as U}from"./index-B6kDpXr5.js";import{t as W}from"./AdminPage-Dq33XE9j.js";import{t as pe}from"./NodeAddonsSettingsPanel-DJKQxT7V.js";var me=F(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),G=F(`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`}]]),he=F(`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=F(`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`}]]);w();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:t}=i({activeOnly:!0},{refetchOnWindowFocus:!1,refetchInterval:e=>(e.state.data?.length??0)>0?3e3:!1}),{map:n}=e(oe.AddonsJobProgress,e=>e.job.jobId);return E(()=>{let e=new Map;for(let n of t??[])e.set(n.jobId,n);for(let[t,r]of n)e.set(t,r.job);return ge([...e.values()],Date.now())},[t,n])}var X={queued:{icon:j,cls:`bg-muted text-foreground-subtle`,label:`queued`},fetching:{icon:R,cls:`bg-primary/10 text-primary`,label:`fetching`,spin:!0},staged:{icon:R,cls:`bg-primary/10 text-primary`,label:`staged`,spin:!0},validating:{icon:R,cls:`bg-primary/10 text-primary`,label:`validating`,spin:!0},applying:{icon:R,cls:`bg-primary/10 text-primary`,label:`applying`,spin:!0},restarting:{icon:R,cls:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,label:`restarting`,spin:!0},applied:{icon:R,cls:`bg-primary/10 text-primary`,label:`finalizing`,spin:!0},done:{icon:L,cls:`bg-success/10 text-success`,label:`updated`},failed:{icon:G,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 T(`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:[k(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label,T(`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 T(`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:[T(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[k(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle font-medium`,children:`Versions`}),k(`button`,{type:`button`,onClick:i,className:`text-foreground-subtle hover:text-foreground`,children:k(B,{className:`h-3 w-3`})})]}),s&&T(`div`,{className:`flex items-start gap-2 px-3 py-2 border-b border-border bg-cyan-500/10 text-[10px]`,children:[k(P,{className:`h-3 w-3 mt-0.5 text-cyan-500 shrink-0`}),T(`div`,{className:`text-cyan-700 dark:text-cyan-200`,children:[T(`span`,{className:`font-semibold`,children:[n===`upload`?`Uploaded copy`:`Local copy`,` in place.`]}),` `,`Re-install `,k(`span`,{className:`font-mono`,children:t}),` from npm to track upstream releases again.`]})]}),l&&T(`div`,{className:`flex items-center justify-center gap-2 py-6 text-[10px] text-foreground-subtle`,children:[k(R,{className:`h-3.5 w-3.5 animate-spin`}),`Loading versions...`]}),c&&k(`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=T(D,{children:[k(`span`,{className:`font-mono flex-1 text-left ${n?`text-primary font-semibold`:c?`text-amber-400`:`text-foreground`}`,children:e.version}),n&&k(`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=>k(`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&&k(`span`,{className:`text-[9px] text-red-400 line-through`,children:`deprecated`}),k(`span`,{className:`text-[9px] text-foreground-subtle shrink-0`,children:new Date(e.publishedAt).toLocaleDateString()})]});return a?T(`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?k(L,{className:`h-3 w-3 text-primary shrink-0`}):k(`span`,{className:`w-3 shrink-0`})]},e.version):T(`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?k(L,{className:`h-3 w-3 text-primary shrink-0`}):k(`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:k(M,{className:`h-3 w-3`})})]},e.version)})}),c&&c.length===0&&k(`div`,{className:`py-4 text-center text-[10px] text-foreground-subtle`,children:`No versions found`})]})}var be={queued:{icon:j,bg:`bg-muted text-foreground-subtle`,label:`queued`},updating:{icon:R,bg:`bg-primary/10 text-primary`,label:`updating`,spin:!0},"done-pending-restart":{icon:N,bg:`bg-amber-500/10 text-amber-700`,label:`pending restart`},done:{icon:L,bg:`bg-success/10 text-success`,label:`done`},failed:{icon:G,bg:`bg-danger/10 text-danger`,label:`failed`}};function xe({item:e}){let t=be[e.status],n=t.icon;return T(`span`,{className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded ${t.bg}`,title:e.error,children:[k(n,{className:`w-2.5 h-2.5 ${t.spin?`animate-spin`:``}`}),t.label]})}w();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]=O(!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 T(`div`,{className:`relative flex-shrink-0`,children:[k(`div`,{className:`h-9 w-9 rounded-lg flex items-center justify-center ${s?``:c}`,style:s,children:u?k(`img`,{src:l,alt:n,className:`h-5 w-5`,onError:()=>o(!0)}):k(e?he:de,{className:`h-4 w-4`})}),t===`local`&&k(`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`&&k(`span`,{className:`absolute -top-1 -left-1 w-4 h-4 rounded bg-[#cb3837] flex items-center justify-center -rotate-12 shadow-sm`,children:k(`svg`,{viewBox:`0 0 780 250`,className:`w-[11px] h-[11px]`,children:k(`path`,{fill:`#fff`,d:`M240 250h100V50h100v200h340V0H0v250z`})})}),t===`upload`&&k(`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:k(P,{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 T(`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:[k(R,{className:`h-3 w-3 animate-spin`}),`Updating…`]});if(t){let r=n??t;return T(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[o&&T(`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:[k(M,{className:`h-3 w-3`}),`Update`]}),T(`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:[k(`span`,{className:`font-normal opacity-70`,children:e}),k(`span`,{className:`font-normal opacity-70`,children:`→`}),r,k(I,{className:`h-3 w-3`})]}),c]})}return T(`div`,{className:`relative inline-flex items-center gap-1 shrink-0`,children:[T(`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,k(I,{className:`h-3 w-3 opacity-50`})]}),c]})}function Te({addonId:e}){let t=ae(),{data:n=`inherit`}=x({addonId:e}),r=d({onSuccess:()=>{t.invalidateQueries({queryKey:[[`addons`,`getAddonAutoUpdate`]]})}});return k(`div`,{className:`flex rounded-lg border border-border overflow-hidden text-[10px] font-medium`,children:[`inherit`,`off`,`latest`,`beta`].map(t=>k(`button`,{type:`button`,onClick:n=>{n.stopPropagation(),r.mutate({addonId:e,channel:t})},disabled:r.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:e,agents:n=[],clusterStatus:r,hideVersion:i,availableUpdate:a,onUpdate:o,isUpdating:c,jobProgress:l,bundle:u,bulkItem:d,disabledByBulk:f,isSystem:p}){let[m,g]=O(!1),[b,ne]=O(!1),[re,x]=O(!1),[S,C]=O(null);A(()=>{C(null)},[a]);let w=S??a,[ie,E]=O(!1),[oe,j]=O(!1),[M,le]=O(`logs`),P=ae(),F=se(),ue=H(),L=te(),{manifest:R}=e,z=e.installedOn??[],de=!u&&!R.protected&&R.removable!==!1,W=!!u,K=u?.displayName??R.name,q=u?.packageName??R.packageName,J=u?.version??R.packageVersion??R.version,Y=u?.installSource??e.installSource,ge=u?u.bundle?.description??u.addons[0]?.manifest.description:R.description,_e=s({onSuccess:()=>{P.invalidateQueries({queryKey:[[`addons`]]}),P.invalidateQueries({queryKey:[[`addonPages`]]}),P.invalidateQueries({queryKey:[[`capabilities`]]})}}),X=y({onSuccess:()=>{P.invalidateQueries({queryKey:[[`addons`]]})}}),be=t({onSuccess:()=>{P.invalidateQueries({queryKey:[[`addons`]]}),P.invalidateQueries({queryKey:[[`addonPages`]]}),P.invalidateQueries({queryKey:[[`capabilities`]]}),P.invalidateQueries({queryKey:[[`integrations`]]})}}),Z=v({onSuccess:()=>{P.invalidateQueries({queryKey:[[`addons`]]}),P.invalidateQueries({queryKey:[[`alerts`]]})}}),Q=e.health,De=Q?.phase===`failed`&&!Q.inGracePeriod,Oe=De&&Q?.nextRetryAt&&!Q.retrying;return T(`div`,{className:`rounded-lg border bg-surface overflow-hidden ${De?`border-red-500/50`:`border-border`}`,children:[De&&Q&&T(`div`,{className:`bg-danger/10 border-b border-danger/30 px-4 py-2.5 flex items-start gap-2.5`,children:[k(G,{className:`h-4 w-4 text-danger shrink-0 mt-0.5`}),T(`div`,{className:`flex-1 min-w-0`,children:[T(`div`,{className:`text-xs font-semibold text-danger`,children:[`Failed to load (attempt #`,Q.retryCount,`)`]}),k(`div`,{className:`text-[11px] text-foreground mt-0.5 break-words font-mono`,children:Q.lastError?.message??`Unknown error`}),Oe&&Q.nextRetryAt&&T(`div`,{className:`text-[10px] text-foreground-subtle mt-1`,children:[`Auto-retry at `,new Date(Q.nextRetryAt).toLocaleTimeString()]})]}),T(`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:[k(N,{className:`h-3 w-3 ${Z.isPending||Q.retrying?`animate-spin`:``}`}),`Retry now`]})]}),T(`div`,{className:`flex items-start gap-3 px-4 py-3`,children:[k(Ce,{isBundle:W||!!R.components&&R.components.length>1,installSource:Y,addonId:W?u.addons[0]?.manifest.id:R.id,iconPath:W?u.bundle?.icon??u.addons[0]?.manifest.icon:R.icon,color:W?u.addons[0]?.manifest.color:R.color}),T(`div`,{className:`flex-1 min-w-0`,children:[T(`div`,{className:`flex items-start justify-between gap-2`,children:[k(`span`,{className:`text-sm font-semibold text-foreground truncate min-w-0`,children:K}),!i&&k(we,{version:J,availableUpdate:a,...w===void 0?{}:{selectedVersion:w},isUpdating:c,installSource:Y,disabled:f,...o&&w!==void 0?{onUpdate:()=>o(w)}:{},onOpenPicker:()=>x(e=>!e),children:re&&k(ye,{packageName:q,currentVersion:J,...Y?{installSource:Y}:{},...a!==void 0&&w!==void 0?{selectedVersion:w,onSelect:e=>{C(e),x(!1)}}:{},onInstall:e=>{x(!1),be.mutate({packageName:q,version:e})},onClose:()=>x(!1)})})]}),T(`div`,{className:`flex flex-wrap items-center gap-x-1.5 gap-y-1 mt-0.5`,children:[q!==K&&k(`span`,{className:`text-[10px] text-foreground-subtle font-mono truncate max-w-full`,children:q}),W&&T(`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:[k(he,{className:`h-3 w-3`}),u.addons.length]}),p&&T(`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:[k(N,{className:`h-3 w-3`}),`System`]}),d!=null&&k(xe,{item:d}),l!=null&&k(ve,{progress:l})]}),ge&&k(`p`,{className:`text-[10px] text-foreground-subtle mt-1 line-clamp-1`,children:ge}),!W&&e.process&&T(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[k(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.mode===`forked`?`bg-blue-500/15 text-blue-400`:`bg-gray-500/15 text-gray-400`}`,children:e.process.mode===`forked`?`forked`:`in-process`}),e.process.pid!=null&&T(`span`,{className:`text-[9px] font-mono text-foreground-subtle`,children:[`PID `,e.process.pid]}),k(`span`,{className:`text-[9px] rounded-full px-1.5 py-0.5 font-medium ${e.process.state===`running`?`bg-emerald-500/15 text-emerald-400`:e.process.state===`crashed`||e.process.state===`failed`?`bg-red-500/15 text-red-400`:`bg-gray-500/15 text-gray-400`}`,children:e.process.state})]})]})]}),!W&&T(`div`,{className:`flex items-center gap-1 px-4 py-1.5 border-t border-border/50 bg-surface-hover/20`,children:[T(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),X.mutate({addonId:R.id})},disabled:X.isPending||f,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:[k(N,{className:`h-3 w-3 ${X.isPending?`animate-spin`:``}`}),`Restart`]}),T(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),E(e=>!e)},className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-medium border transition-colors ${ie?`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:[k(V,{className:`h-3 w-3`}),`Logs`]}),!W&&T(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),j(!0)},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:[k(fe,{className:`h-3 w-3`}),`Settings`]}),k(`div`,{className:`flex-1`}),de&&T(`button`,{type:`button`,onClick:async e=>{e.stopPropagation(),await L({title:`Uninstall ${R.name}?`,message:`This will remove the addon package and all its data. This action cannot be undone.`,confirmLabel:`Uninstall`,variant:`danger`})&&_e.mutate({packageName:R.packageName})},disabled:_e.isPending||f,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:[k(U,{className:`h-3 w-3`}),_e.isPending?`Removing...`:`Uninstall`]})]}),r&&r.nodes.length>1&&!W&&T(`div`,{className:`border-t border-border px-4 py-2 bg-muted/10`,children:[k(`div`,{className:`text-[10px] font-medium text-foreground-subtle mb-1.5`,children:`Cluster Deployment`}),k(`div`,{className:`space-y-1`,children:r.nodes.map(e=>T(`div`,{className:`flex items-center gap-2 text-[10px]`,children:[k(`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`}`}),k(`span`,{className:`font-medium text-foreground min-w-[60px]`,children:e.name}),k(`span`,{className:`font-mono text-foreground-subtle`,children:e.version}),!e.synced&&e.status!==`offline`&&k(`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`&&k(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-muted text-muted-foreground`,children:`offline`}),e.synced&&e.status!==`offline`&&k(`span`,{className:`text-[9px] text-success`,children:`synced`})]},e.nodeId))})]}),ie&&!W&&T(`div`,{className:`border-t border-border`,children:[T(`div`,{className:`flex items-center px-4 py-1 bg-surface-hover/20 border-b border-border/50`,children:[T(`div`,{className:`flex rounded border border-border overflow-hidden text-[9px]`,children:[k(`button`,{type:`button`,onClick:()=>le(`logs`),className:`px-2 py-0.5 transition-colors ${M===`logs`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Logs`}),k(`button`,{type:`button`,onClick:()=>le(`events`),className:`px-2 py-0.5 border-l border-border transition-colors ${M===`events`?`bg-primary/10 text-primary`:`text-foreground-subtle hover:bg-surface-hover`}`,children:`Events`})]}),k(`div`,{className:`flex-1`}),k(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),E(!1)},className:`text-foreground-subtle hover:text-foreground`,children:k(B,{className:`h-3.5 w-3.5`})})]}),M===`logs`&&k(ee,{addonId:R.id,maxHeight:`max-h-64`,showFilters:!1}),M===`events`&&k(_,{addonId:R.id,category:`addon.*`,maxHeight:`max-h-64`})]}),W&&T(D,{children:[k(`button`,{type:`button`,onClick:()=>g(e=>!e),className:`w-full flex items-center justify-center border-t border-border py-1 hover:bg-surface-hover/50 transition-colors`,children:k(m?me:I,{className:`h-3.5 w-3.5 text-foreground-subtle`})}),m&&k(`div`,{className:`border-t border-border px-3 py-2 space-y-2`,children:u.addons.map(e=>k(Ee,{addon:e,agents:n,hideVersion:!0},e.manifest.id))})]}),oe&&!W&&k(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4`,onClick:()=>j(!1),children:T(`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:[T(`div`,{className:`flex items-center justify-between px-5 py-3 border-b border-border flex-shrink-0`,children:[T(`div`,{className:`flex items-center gap-2`,children:[k(fe,{className:`h-4 w-4 text-primary`}),T(`h2`,{className:`text-sm font-semibold text-foreground`,children:[K,` Settings`]})]}),k(`button`,{onClick:()=>j(!1),className:`text-foreground-subtle hover:text-foreground transition-colors p-1 rounded`,children:k(B,{className:`h-4 w-4`})})]}),T(`div`,{className:`flex-1 overflow-y-auto px-5 py-4 space-y-4`,children:[k(pe,{nodeId:`hub`,addonIds:[R.id],level:`global`}),Se(R)&&T(`div`,{children:[k(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Device export`}),k(h,{addonId:R.id,trpc:F.trpcClient,onOpenDevice:e=>ue(`/devices/${e}`)})]}),Y===`npm`&&T(`div`,{children:[k(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Auto-Update`}),k(Te,{addonId:R.id})]}),R.components&&R.components.length>0&&T(`div`,{children:[T(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:[`Components (`,R.components.length,`)`]}),k(`div`,{className:`flex flex-wrap gap-1`,children:R.components.map(e=>k(`span`,{className:`text-[10px] rounded bg-background border border-border px-1.5 py-0.5 text-foreground-subtle font-mono`,children:e},e))})]}),n.length>=2&&T(`div`,{children:[k(`div`,{className:`text-[10px] font-medium text-foreground-subtle uppercase tracking-wide mb-2`,children:`Installed on`}),T(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[z.length===0&&k(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Hub (local)`}),z.map(e=>k(`span`,{className:`rounded-full bg-surface-hover border border-border px-2 py-0.5 text-[10px] text-foreground-subtle`,children:e},e)),T(`div`,{className:`relative`,children:[T(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ne(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:[k(ce,{className:`h-3 w-3`}),`Add agent`]}),b&&T(`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:[n.filter(e=>!e.isHub&&!z.includes(e.name)).map(e=>k(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ne(!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)),n.filter(e=>!e.isHub&&!z.includes(e.name)).length===0&&k(`div`,{className:`px-3 py-1.5 text-[10px] text-foreground-subtle`,children:`No available agents`})]})]})]})]})]}),k(`div`,{className:`flex items-center justify-end px-5 py-3 border-t border-border flex-shrink-0`,children:k(`button`,{type:`button`,onClick:()=>j(!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`})})]})})]})}w();var Q=`.tgz,.tar.gz,.zip`;function De({onUploadSuccess:e}){let[t,n]=O(!1),r=C(null),i=S(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 T(D,{children:[k(`input`,{ref:r,type:`file`,accept:Q,onChange:S(e=>{let t=e.target.files?.[0];t&&i(t),e.target.value=``},[i]),className:`hidden`}),T(`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?k(R,{className:`w-3.5 h-3.5 animate-spin`}):k(P,{className:`w-3.5 h-3.5`}),t?`Uploading...`:`Upload`]})]})}w();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:n,selectedNode:i,onRefresh:o,isRefreshing:s}){let c=ae(),[d,f]=O(``),p=ie(d),[h,_]=O(!1),v=C(null);A(()=>{if(!h)return;let e=e=>{v.current&&!v.current.contains(e.target)&&_(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[h]);let{data:y}=r({nodeId:i.id}),ee=E(()=>{let e=new Map;for(let t of y??[])e.set(t.name,t.latestVersion);return e},[y]),b=E(()=>(y??[]).filter(e=>!e.isSystem).length,[y]),[ne,x]=O(()=>new Set),[w,D]=O(()=>new Map),oe=S(e=>{x(t=>new Set(t).add(e))},[]),se=S(e=>{x(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),j=S((e,t)=>{D(n=>new Map(n).set(e,t))},[]),ce=S(e=>{D(t=>{if(!t.has(e))return t;let n=new Map(t);return n.delete(e),n})},[]),P=l({onMutate:e=>{oe(e.name),ce(e.name)},onSuccess:(e,t)=>{se(t.name);let n=e;if(n&&n.success===!1){j(t.name,n.error??`Update failed (no error message returned by server)`);return}c.invalidateQueries({queryKey:[[`addons`]]}),c.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]})},onError:(e,t)=>{se(t.name),j(t.name,e instanceof Error?e.message:String(e))}}),F=_e(),I=C(new Set);A(()=>{let e=new Set;for(let[t,n]of F)Y(n)&&e.add(t);let t=[...I.current].some(t=>!e.has(t));I.current=e,t&&(c.invalidateQueries({queryKey:[[`addons`]]}),c.invalidateQueries({queryKey:[[`addons`,`listUpdates`]]}))},[F,c]);let{data:de}=g(void 0),B=m({onSuccess:()=>{c.invalidateQueries({queryKey:[[`addons`,`getAutoUpdateSettings`]]})}}),{data:V,isFetching:fe}=u({query:p||void 0},{enabled:h}),H=a(),{data:U}=re(void 0),W=U?.requestedAt,[pe,me]=O(null),[G,he]=O(!1);A(()=>{if(U?.kind===`framework-bulk-update`&&U.requestedAt!==pe){me(U.requestedAt),he(!0);let e=window.setTimeout(()=>he(!1),6e3);return()=>window.clearTimeout(e)}},[W,pe,U]),te();let K=S(async()=>{let e=(y??[]).filter(e=>!e.isSystem);if(e.length!==0){if(!i.isHub){for(let t of e)await P.mutateAsync({name:t.name,version:t.latestVersion,nodeId:i.id});return}await H.mutateAsync({kind:`update`,targets:e.map(e=>({name:e.name,version:e.latestVersion})),nodeIds:[i.id]})}},[y,i.id,i.isHub,H,P]),q=t({onSuccess:()=>{c.invalidateQueries({queryKey:[[`addons`]]}),c.invalidateQueries({queryKey:[[`addonPages`]]}),c.invalidateQueries({queryKey:[[`capabilities`]]}),c.invalidateQueries({queryKey:[[`integrations`]]})}}),[J,ge]=O(`type`),[X,ve]=O(()=>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]=z(),Z=be.get(`capability`),Se=E(()=>{let t=e.filter(e=>!ke(e.manifest.packageName));return i.isHub||(t=t.filter(e=>Ae(e.placement,i.isHub))),Z&&(t=t.filter(e=>(e.manifest.capabilities??[]).some(e=>(typeof e==`string`?e:e.name)===Z))),t},[e,i.isHub,Z]),Ce=()=>{let e=new URLSearchParams(be);e.delete(`capability`),xe(e,{replace:!0})},we=X===`flat`?Se:Me(Se),Te=E(()=>{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 T(`div`,{className:`space-y-4`,children:[[...w.entries()].map(([e,t])=>k(`div`,{className:`rounded-md border border-danger/30 bg-danger/5 px-3 py-2 text-[11px]`,children:T(`div`,{className:`flex items-start justify-between gap-3`,children:[T(`div`,{className:`space-y-0.5`,children:[T(`div`,{className:`font-medium text-danger`,children:[`Failed to update `,e]}),k(`div`,{className:`text-foreground-subtle font-mono`,children:t})]}),k(`button`,{type:`button`,onClick:()=>ce(e),className:`text-foreground-subtle hover:text-foreground text-[10px]`,children:`dismiss`})]})},e)),T(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[T(`div`,{className:`flex items-center gap-1.5`,children:[k(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Sort:`}),T(`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:[k(`option`,{value:`type`,children:`Bundles first`}),k(`option`,{value:`name`,children:`Name`}),k(`option`,{value:`source`,children:`Install source`})]})]}),T(`div`,{className:`flex items-center gap-1.5`,children:[k(`span`,{className:`text-[10px] text-foreground-subtle`,children:`View:`}),k(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`grouped`,`flat`].map(e=>k(`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))})]}),i.isHub&&T(`div`,{className:`flex items-center gap-1.5`,children:[k(N,{className:`h-3 w-3 text-foreground-subtle`}),k(`span`,{className:`text-[10px] text-foreground-subtle`,children:`Auto-Update:`}),k(`div`,{className:`flex rounded-md border border-border overflow-hidden text-[10px] font-medium`,children:[`off`,`latest`,`beta`].map(e=>k(`button`,{type:`button`,onClick:()=>B.mutate({channel:e}),disabled:B.isPending,className:`px-2.5 py-1.5 transition-colors capitalize ${de?.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))})]}),b>0&&T(`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?k(R,{className:`w-3 h-3 animate-spin`}):k(M,{className:`w-3 h-3`}),H.isPending?`Updating…`:`Update All (${b})`]}),T(`button`,{type:`button`,onClick:o,disabled:s||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:[k(N,{className:`w-3 h-3 ${s?`animate-spin`:``}`}),`Refresh`]})]}),T(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[T(`div`,{className:`relative flex-1 min-w-0 sm:min-w-[200px]`,ref:v,children:[k(le,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-foreground-subtle`}),k(`input`,{type:`text`,value:d,onChange:e=>{f(e.target.value),_(!0)},onFocus:()=>_(!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`}),fe&&k(R,{className:`absolute right-2.5 top-1/2 -translate-y-1/2 h-3 w-3 text-foreground-subtle animate-spin`}),h&&V&&V.length>0&&T(`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:[V.length>0&&T(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wide text-foreground-subtle border-b border-border`,children:[`npm results (`,V.length,`)`]}),V&&V.length>0&&k(`div`,{className:`max-h-72 overflow-auto divide-y divide-border`,children:V.map(e=>T(`div`,{className:`flex items-center gap-3 px-3 py-2 hover:bg-surface-hover transition-colors`,children:[k(`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()}),T(`div`,{className:`flex-1 min-w-0`,children:[T(`div`,{className:`flex items-baseline gap-2 min-w-0`,children:[k(`span`,{className:`text-[11px] font-semibold break-words`,children:e.name.replace(/^@camstack\/(addon-)?/,``)}),T(`span`,{className:`text-[10px] text-foreground-subtle shrink-0`,children:[`v`,e.version]})]}),k(`div`,{className:`font-mono text-[9px] text-foreground-subtle/80 truncate`,children:e.name}),e.description&&k(`div`,{className:`text-[10px] text-foreground-subtle truncate`,children:e.description})]}),e.installed?T(`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:[k(L,{className:`h-3 w-3`}),e.installedVersion??`Installed`]}):T(`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?k(R,{className:`h-3 w-3 animate-spin`}):k(M,{className:`h-3 w-3`}),`Install`]})]},e.name))})]})]}),k(De,{onUploadSuccess:()=>{c.invalidateQueries({queryKey:[[`addons`]]}),o()}})]}),Z&&T(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-primary/10 border border-primary/30 text-sm`,children:[k(`span`,{className:`text-foreground-subtle`,children:`Filtering by capability:`}),k(`span`,{className:`font-mono text-primary font-semibold`,children:Z}),k(`button`,{type:`button`,onClick:Ce,className:`ml-auto text-xs text-foreground-subtle hover:text-foreground underline`,children:`Clear`})]}),G&&T(`div`,{className:`fixed top-[calc(env(safe-area-inset-top)+1rem)] right-[calc(env(safe-area-inset-right)+1rem)] 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:[k(ue,{className:`w-4 h-4 shrink-0 mt-0.5 text-green-400`}),T(`div`,{children:[k(`div`,{className:`text-[11px] font-semibold text-foreground`,children:`Bulk update completed`}),k(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:`System packages updated — hub restarted successfully.`})]})]}),Se.length===0&&k(`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 ${i.name} (placement filter active)`}),k(`div`,{className:`space-y-2`,children:Te.map(e=>{let t=$(e)?e.bundle.packageName:e.manifest.packageName,r=ee.get(t),a=$(e)?e.representative:e,o=r?e=>P.mutate({name:t,version:e,nodeId:i.id}):void 0,s=F.get(t)??null,c=s!==null&&Y(s);return k(Ee,{addon:a,clusterStatus:n?.[a.manifest.id],bundle:$(e)?e.bundle:void 0,availableUpdate:r,isUpdating:ne.has(t)||c,jobProgress:s,onUpdate:o,disabledByBulk:H.isPending},$(e)?t:e.manifest.id)})})]})}function Pe(){let e=ae(),{data:t,isLoading:r,isError:i}=ne(),{data:a}=o(void 0),{data:s}=c(void 0,{refetchInterval:1e4}),l=E(()=>{let e=new Map;e.set(`hub`,{id:`hub`,name:`Hub`,isHub:!0});for(let t of s??[]){let n=String(t.id??``);n&&e.set(n,{id:n,name:String(t.name??n),isHub:!!t.isHub})}return[...e.values()]},[s]),[u,d]=O(`hub`),p=l.find(e=>e.id===u)??l[0],m=b(),h=f(),g=m.isPending||h.isPending,_=async()=>{await m.mutateAsync({nodeId:u}),await h.mutateAsync(),e.invalidateQueries({queryKey:[[`addons`]]})},v=C(m);v.current=m,A(()=>{v.current.mutate({nodeId:`hub`})},[]);let y=(t??[]).map(je).filter(e=>e!==null);return T(W,{children:[T(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[k(n,{selectedNodeId:u,onSelect:d}),T(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[!r&&!i&&T(`span`,{className:`text-[10px] rounded-full bg-primary/10 text-primary px-2 py-0.5 font-medium`,children:[y.length,` installed`]}),T(`button`,{type:`button`,onClick:()=>void _(),disabled:g,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:[k(N,{className:`w-3 h-3 ${g?`animate-spin`:``}`}),`Check for updates`]})]})]}),!p.isHub&&T(`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`,` `,k(`span`,{className:`font-medium text-foreground`,children:p.name}),` — agents only run`,` `,k(`code`,{className:`font-mono`,children:`agent-only`}),` and`,` `,k(`code`,{className:`font-mono`,children:`any-node`}),` addons. Install / uninstall is hub-driven; agents auto-sync from the hub.`]}),r&&k(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading…`}),i&&k(`div`,{className:`text-xs text-danger`,children:`Failed to load addons`}),!r&&!i&&k(Ne,{addons:y,clusterStatus:a,selectedNode:p,onRefresh:()=>void _(),isRefreshing:g})]})}export{Pe as AddonsPage};
@@ -1,3 +0,0 @@
1
- import{D as e,Do as t,Ro as n,To as r,_s as i,as as a,cs as o,ds as s,gs as c,hs as l,is as u,ls as d,ms as f,nt as p,os as m,ps as h,us as g,zo as _}from"./src-BmAmiAXy.js";import{I as v,K as y,Q as b,S as x,W as S,a as C,b as w,q as T,t 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{c as k}from"./widget-panel-BF8s8cZY.js";import{t as A}from"./boxes-BCCj5PaE.js";import{n as j,t as M}from"./send-DLoLyQZY.js";import{t as N}from"./pencil-OtLKJIw8.js";import{t as P}from"./plus-vrCV3Fn-.js";import{t as F}from"./server-jIBmmmio.js";import{t as I}from"./square-CgzDPTwM.js";import{B as L,E as R,G as z,M as B,S as V,V as H,_ as U,i as ee,l as W,s as te,t as G}from"./index-B6kDpXr5.js";import{t as K}from"./AdminPage-Dq33XE9j.js";import{t as ne}from"./AdminTabs-Co61VJ4U.js";var q=z(`cloud`,[[`path`,{d:`M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z`,key:`p7xjir`}]]);b();var J=[`llm`,`listProfiles`],re=[`llm`,`listProfileKinds`],ie=[`llm`,`getDefaults`],ae=[`llm`,`listRuntimeNodes`],oe=[`llm`,`listModelCatalog`],se=[`llm`,`getUsage`],ce=[{purpose:`vision`,visionOnly:!0},{purpose:`text`,visionOnly:!1}],le=new Map(Object.entries({openai:q,anthropic:q,google:q,"openai-compatible":U,"managed-local":B}));function ue(e){return le.get(e)??null}function Y(e){return typeof e==`string`&&e.length>0?e:void 0}function X(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 Z(e){return e===!0}function de(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 fe(e,t,n){let r=X(e.threads);return{nodeId:t,engine:`llama-cpp`,model:{kind:`catalog`,catalogId:n},contextSize:X(e.contextSize)??4096,gpuLayers:X(e.gpuLayers)??0,...r===void 0?{}:{threads:r},parallel:X(e.parallel)??1,autoStart:Z(e.autoStart),idleStopMinutes:X(e.idleStopMinutes)??30}}function pe(e,t,n,r,i){let a={id:n?.id??crypto.randomUUID(),name:t,kind:e,addonId:`ai`,enabled:n?.enabled??!0,model:Y(r.model)??n?.model??``,supportsVision:i?.supportsVision??Z(r.supportsVision),timeoutMs:X(r.timeoutMs)??6e4},o=Y(r.baseUrl),s=Y(r.apiKey),c=X(r.temperature),l=X(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:fe(r,i.nodeId,i.catalogId)}}}function me(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.entries()].map(([e,t])=>({addonId:e,kinds:t}))}function Q({kind:e,className:t}){let n=ue(e.kind);return n===null?D(`span`,{className:t,children:e.icon}):D(n,{className:t})}function he({kinds:e,onPick:t,onCancel:n}){let{t:r}=G(),s=S(()=>me(e),[e]);return D(u,{open:!0,onOpenChange:e=>!e&&n(),children:x(m,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[D(d,{children:D(g,{children:r(`ai.chooseKind`,`Choose a profile type`)})}),x(a,{className:`space-y-4 pr-1`,children:[s.length===0&&D(`p`,{className:`text-xs text-foreground-subtle`,children:r(`ai.noKinds`,`No AI provider is installed.`)}),s.map(e=>x(`div`,{children:[D(`div`,{className:`mb-1.5 text-[10px] font-semibold uppercase tracking-wider text-foreground-subtle`,children:e.addonId}),D(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-3`,children:e.kinds.map(n=>x(`button`,{type:`button`,onClick:()=>t(n),className:`flex flex-col items-center gap-1.5 rounded-lg border border-border bg-surface px-3 py-3 text-xs transition-colors hover:border-primary/50 hover:bg-surface-hover`,children:[D(Q,{kind:n,className:`h-5 w-5 text-foreground-subtle`}),D(`span`,{className:`font-medium text-foreground`,children:n.label})]},`${e.addonId}:${n.kind}`))})]},e.addonId))]}),D(o,{children:D(i,{size:`sm`,variant:`secondary`,type:`button`,onClick:n,children:r(`common.cancel`,`Cancel`)})})]})})}function ge({kind:n,existing:r,onSave:s,onCancel:l,saving:p,error:_}){let{t:v}=G(),y=k(),b=n.kind===`managed-local`,[E,O]=T(r?.name??n.label),[A,j]=T(()=>r===null?{}:de(r)),[M,N]=T(r?.runtime?.nodeId??`hub`),[P,F]=T(r?.runtime?.model.kind===`catalog`?r.runtime.model.catalogId:``),I=C({queryKey:oe,enabled:b,queryFn:()=>y.trpcClient.llm.listModelCatalog.query({})}),L=S(()=>[{value:``,label:v(`ai.selectModel`,`Select a model…`)},...(I.data??[]).map(e=>({value:e.id,label:`${e.label} · ${e.quantization} · ${(e.sizeBytes/1e9).toFixed(1)} GB`}))],[I.data,v]),R=()=>{if(!b){s(pe(n.kind,E,r,A));return}let e=I.data?.find(e=>e.id===P);s(pe(n.kind,E,r,A,{nodeId:M,catalogId:P,supportsVision:e?.purpose===`vision`}))},z=p||E.trim()===``||b&&P===``;return D(u,{open:!0,onOpenChange:e=>!e&&l(),children:x(m,{width:`lg`,placement:`sheet-on-mobile`,scroll:`body`,children:[D(d,{children:x(g,{className:`flex items-center gap-2`,children:[D(Q,{kind:n,className:`h-4 w-4 text-foreground-subtle`}),r===null?v(`ai.newProfile`,`New {{kind}} profile`,{kind:n.label}):v(`ai.editProfile`,`Edit {{name}}`,{name:r.name})]})}),x(a,{className:`space-y-3 pr-1`,children:[_!==null&&D(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs text-danger`,children:_}),x(`div`,{children:[D(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-profile-name`,children:v(`ai.name`,`Name`)}),D(f,{id:`ai-profile-name`,value:E,onChange:e=>O(e.target.value),placeholder:n.label})]}),b&&x(w,{children:[D(t,{selectedNodeId:M,onSelect:N,label:v(`ai.runtimeNode`,`Runtime node`),alwaysShow:!0}),x(`div`,{children:[D(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-profile-catalog`,children:v(`ai.model`,`Model`)}),D(h,{id:`ai-profile-catalog`,value:P,options:L,onChange:e=>F(e.target.value)})]})]}),D(e,{schema:n.configSchema,values:A,onChange:j}),r!==null&&D(`p`,{className:`text-[10px] text-foreground-subtle`,children:v(`ai.secretHint`,`A stored API key is never shown. Leave it as-is to keep it; type a new value to replace it.`)})]}),x(o,{children:[b&&P===``&&D(c,{variant:`warning`,children:v(`ai.pickModelFirst`,`pick a model`)}),D(i,{size:`sm`,variant:`secondary`,type:`button`,onClick:l,children:v(`common.cancel`,`Cancel`)}),x(i,{size:`sm`,type:`button`,disabled:z,onClick:R,children:[p&&D(V,{className:`h-3.5 w-3.5 animate-spin`}),r===null?v(`ai.createProfile`,`Create profile`):v(`ai.saveChanges`,`Save changes`)]})]})]})})}b();function _e(e){return[{key:`name`,header:e.t(`ai.colProfile`,`Profile`),render:t=>{let n=e.kindByName.get(t.kind);return x(`span`,{className:`flex items-center gap-2`,children:[D(`span`,{className:`flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-surface`,title:n?.label??t.kind,children:n===void 0?D(`span`,{className:`text-xs text-foreground-subtle`,children:`?`}):D(Q,{kind:n,className:`h-4 w-4 text-foreground-subtle`})}),x(`span`,{className:`min-w-0`,children:[D(`span`,{className:`block truncate text-sm font-medium text-foreground`,children:t.name}),e.testResult?.id===t.id&&D(`span`,{className:`block truncate text-[10px] ${e.testResult.ok?`text-success`:`text-danger`}`,children:e.testResult.text})]})]})}},{key:`kind`,header:e.t(`ai.colKind`,`Kind`),nowrap:!0,render:t=>D(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.kindByName.get(t.kind)?.label??t.kind})},{key:`model`,header:e.t(`ai.colModel`,`Model`),render:e=>D(`span`,{className:`text-[11px] text-foreground`,children:e.model})},{key:`vision`,header:e.t(`ai.colVision`,`Vision`),align:`center`,nowrap:!0,render:t=>t.supportsVision?D(c,{variant:`info`,style:`outline`,children:e.t(`ai.vision`,`vision`)}):D(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`})},{key:`node`,header:e.t(`ai.colNode`,`Node`),nowrap:!0,render:e=>e.runtime===void 0?D(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):D(c,{variant:`default`,children:e.runtime.nodeId})},{key:`enabled`,header:e.t(`ai.colOn`,`On`),align:`center`,nowrap:!0,render:t=>D(s,{checked:t.enabled,onCheckedChange:()=>e.onToggle(t),"aria-label":`toggle ${t.name}`})},{key:`actions`,header:``,align:`right`,nowrap:!0,render:t=>x(`span`,{className:`flex items-center justify-end gap-1`,children:[D(i,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onTest(t),title:e.t(`ai.test`,`Test`),children:e.testingId===t.id?D(V,{className:`h-3.5 w-3.5 animate-spin`}):D(M,{className:`h-3.5 w-3.5`})}),D(i,{size:`sm`,variant:`ghost`,type:`button`,disabled:!e.kindByName.has(t.kind),onClick:()=>e.onEdit(t),title:e.t(`common.edit`,`Edit`),children:D(N,{className:`h-3.5 w-3.5`})}),D(i,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>e.onDelete(t),title:e.t(`common.delete`,`Delete`),children:D(te,{className:`h-3.5 w-3.5 text-danger`})})]})}]}function ve(){let{t:e}=G(),t=k(),[a,o]=T({mode:`closed`}),[s,c]=T(null),[u,d]=T(null),f=C({queryKey:J,queryFn:()=>t.trpcClient.llm.listProfiles.query({})}),p=C({queryKey:re,queryFn:async()=>(await t.trpcClient.llm.listProfileKinds.query({})).map(e=>({...e,configSchema:e.configSchema}))}),m=()=>{f.refetch()},h=E({mutationFn:e=>t.trpcClient.llm.upsertProfile.mutate({profile:e}),onSuccess:()=>{o({mode:`closed`}),d(null),m()},onError:t=>d(t instanceof Error?t.message:e(`ai.saveFailed`,`Save failed`))}),g=E({mutationFn:e=>t.trpcClient.llm.deleteProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:m}),_=E({mutationFn:e=>t.trpcClient.llm.testProfile.mutate({addonId:e.addonId,profileId:e.id}),onSuccess:(e,t)=>c({id:t.id,ok:e.ok,text:e.ok?`${e.text} (${String(e.usage.outputTokens)} tok, ${String(e.latencyMs)}ms)`:`${e.code}: ${e.message}`})}),v=f.data??[],y=S(()=>p.data??[],[p.data]),b=S(()=>{let e=new Map;for(let t of y)e.set(t.kind,t);return e},[y]);return x(K,{icon:W,title:e(`ai.profilesTitle`,`AI profiles`),subtitle:e(`ai.profilesSubtitle`,`One row = one usable model endpoint. The defaults below decide who answers when a feature names no profile.`),actions:x(i,{size:`sm`,type:`button`,onClick:()=>{d(null),o({mode:`pick-kind`})},children:[D(P,{className:`h-3.5 w-3.5`}),e(`ai.addProfile`,`Add profile`)]}),children:[f.isError&&D(r,{title:e(`ai.loadFailed`,`Failed to load profiles`),message:f.error instanceof Error?f.error.message:e(`common.error`,`Error`),onRetry:()=>void f.refetch()}),D(ye,{profiles:v}),f.isLoading&&D(`div`,{className:`flex items-center justify-center py-16`,children:D(V,{className:`h-6 w-6 animate-spin text-primary`})}),!f.isLoading&&v.length===0&&D(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:e(`ai.noProfiles`,`No AI profiles yet. Click "Add profile" to configure one.`)}),v.length>0&&D(l,{children:D(n,{columns:_e({kindByName:b,testResult:s,testingId:_.isPending?_.variables?.id??null:null,t:e,onToggle:e=>h.mutate({...e,enabled:!e.enabled,apiKey:`__redacted__`}),onTest:e=>_.mutate(e),onEdit:e=>{let t=b.get(e.kind);t!==void 0&&(d(null),o({mode:`form`,kind:t,profile:e}))},onDelete:e=>g.mutate(e)}),rows:v,rowKey:e=>e.id,minWidthPx:760,bordered:!1,mobileMode:`scroll`,maxBodyHeight:`max-h-[60vh]`})}),a.mode===`pick-kind`&&D(he,{kinds:y,onCancel:()=>o({mode:`closed`}),onPick:e=>o({mode:`form`,kind:e,profile:null})}),a.mode===`form`&&D(ge,{kind:a.kind,existing:a.profile,saving:h.isPending,error:u,onSave:e=>h.mutate(e),onCancel:()=>o({mode:`closed`})})]})}function ye({profiles:e}){let{t}=G(),n=k(),r=C({queryKey:ie,queryFn:()=>n.trpcClient.llm.getDefaults.query({})}),i=E({mutationFn:e=>n.trpcClient.llm.setDefault.mutate({selector:{purpose:e.purpose},profileId:e.profileId}),onSuccess:()=>{r.refetch()}}),a=e=>(r.data??[]).find(t=>`purpose`in t.selector&&t.selector.purpose===e)?.profileId??``,o=e=>e===`vision`?t(`ai.defaultVision`,`Default vision profile`):t(`ai.defaultText`,`Default text profile`);return D(l,{children:D(`div`,{className:`grid gap-4 p-4 sm:grid-cols-2`,children:ce.map(({purpose:n,visionOnly:r})=>{let s=r?e.filter(e=>e.supportsVision):e,c=a(n),l=e.find(e=>e.id===c);return x(`div`,{children:[D(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`llm-default-${n}`,children:o(n)}),x(`select`,{id:`llm-default-${n}`,"aria-label":o(n),className:`h-7 w-full rounded-md border border-border bg-surface px-2.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,value:c,onChange:e=>i.mutate({purpose:n,profileId:e.target.value===``?null:e.target.value}),children:[D(`option`,{value:``,children:t(`ai.none`,`None`)}),c!==``&&!s.some(e=>e.id===c)&&D(`option`,{value:c,children:l?.name??c}),s.map(e=>x(`option`,{value:e.id,children:[e.name,` · `,e.model]},e.id))]}),c!==``&&l===void 0&&D(`p`,{className:`mt-1 text-[10px] text-danger`,children:t(`ai.defaultMissing`,`This default names a profile that no longer exists.`)}),l!==void 0&&!l.enabled&&D(`p`,{className:`mt-1 text-[10px] text-warning`,children:t(`ai.defaultDisabled`,`This default profile is disabled — callers resolve to no profile.`)}),i.error!=null&&D(`p`,{className:`mt-1 text-[10px] text-danger`,children:String(i.error)})]},n)})})})}b();var be=5e3;function xe(e){return`${(e/1e9).toFixed(1)} GB`}function Se(){let{t:e}=G(),t=k(),i=C({queryKey:ae,refetchInterval:be,queryFn:()=>t.trpcClient.llm.listRuntimeNodes.query({})}),a=S(()=>[{key:`node`,header:e(`ai.colNode`,`Node`),render:e=>D(`span`,{className:`text-sm font-medium text-foreground`,children:e.nodeId})},{key:`state`,header:e(`ai.colState`,`State`),nowrap:!0,render:t=>x(`span`,{className:`flex items-center gap-1.5`,children:[D(c,{variant:t.reachable?`success`:`danger`,children:t.reachable?t.status?.state??e(`ai.ready`,`ready`):e(`ai.unreachable`,`unreachable`)}),t.status?.downloadProgress!==void 0&&D(c,{variant:`info`,children:`${String(Math.round(t.status.downloadProgress*100))}%`})]})},{key:`model`,header:e(`ai.colModel`,`Model`),render:e=>D(`span`,{className:`text-[11px] text-foreground`,children:e.status?.modelId??`—`})},{key:`disk`,header:e(`ai.colDisk`,`On disk`),align:`right`,nowrap:!0,render:e=>D(`span`,{className:`text-[11px] text-foreground-subtle`,children:e.disk===void 0?`—`:xe(e.disk.modelsBytes)})},{key:`error`,header:e(`ai.colError`,`Error`),render:e=>e.error===void 0?D(`span`,{className:`text-[11px] text-foreground-subtle`,children:`—`}):D(`span`,{className:`text-[11px] text-danger`,children:e.error})}],[e]),o=i.data??[];return x(K,{icon:F,title:e(`ai.runtimesTitle`,`Managed runtimes`),subtitle:e(`ai.runtimesSubtitle`,`Nodes advertising the llm-runtime capability: what each has loaded, what it is downloading, and how much model data sits on its disk.`),children:[i.isError&&D(r,{title:e(`ai.runtimesFailed`,`Failed to read runtime nodes`),message:i.error instanceof Error?i.error.message:e(`common.error`,`Error`),onRetry:()=>void i.refetch()}),o.length===0?D(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:e(`ai.noRuntimes`,`No node advertises the llm-runtime capability.`)}):D(l,{children:D(n,{columns:a,rows:o,rowKey:e=>e.nodeId,minWidthPx:640,bordered:!1,mobileMode:`scroll`,maxBodyHeight:_})})]})}var Ce=`/addon/ai/test-chat`;function we(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Te(e){if(!we(e))return null;let t=e.kind;return t!==`snapshot`&&t!==`track`||typeof e.mimeType!=`string`||typeof e.sizeBytes!=`number`?null:{kind:t,mimeType:e.mimeType,sizeBytes:e.sizeBytes,...typeof e.mediaKind==`string`?{mediaKind:e.mediaKind}:{},...typeof e.capturedAt==`number`?{capturedAt:e.capturedAt}:{}}}var Ee=[`resolving-image`,`connecting`,`first-token-wait`,`streaming`];function De(e){let t;try{t=JSON.parse(e)}catch{return null}if(!we(t))return null;switch(t.kind){case`status`:{let e=Ee.find(e=>e===t.phase);return e===void 0?null:{kind:`status`,phase:e}}case`meta`:return typeof t.profileName!=`string`||typeof t.model!=`string`?null:{kind:`meta`,profileName:t.profileName,model:t.model,mediaSent:Te(t.mediaSent),streamed:t.streamed===!0,firstTokenTimeoutMs:typeof t.firstTokenTimeoutMs==`number`?t.firstTokenTimeoutMs:0};case`token`:return typeof t.text==`string`?{kind:`token`,text:t.text}:null;case`done`:return{kind:`done`,inputTokens:typeof t.inputTokens==`number`?t.inputTokens:0,outputTokens:typeof t.outputTokens==`number`?t.outputTokens:0,latencyMs:typeof t.latencyMs==`number`?t.latencyMs:0,truncated:t.truncated===!0};case`error`:return{kind:`error`,code:typeof t.code==`string`?t.code:`adapter-error`,message:typeof t.message==`string`?t.message:`the provider returned an error`};default:return null}}async function*Oe(e){let t=e.getReader(),n=new TextDecoder,r=``;try{for(;;){let{done:e,value:i}=await t.read();if(e)break;r+=n.decode(i,{stream:!0});let a=r.indexOf(`
2
- `);for(;a>=0;){let e=r.slice(0,a).trim();if(r=r.slice(a+1),e.length>0){let t=De(e);t!==null&&(yield t)}a=r.indexOf(`
3
- `)}}let e=r.trim();if(e.length>0){let t=De(e);t!==null&&(yield t)}}finally{t.releaseLock()}}function ke(e){return e.filter(e=>e.failed!==!0&&e.content.length>0).map(e=>({role:e.role,content:e.content}))}function Ae(e){let t=e.sizeBytes<1024*1024?`${(e.sizeBytes/1024).toFixed(0)} KB`:`${(e.sizeBytes/(1024*1024)).toFixed(1)} MB`,n=[e.kind===`snapshot`?`camera snapshot`:`track best-shot`,t];return e.mediaKind!==void 0&&n.push(e.mediaKind),e.capturedAt!==void 0&&n.push(new Date(e.capturedAt).toLocaleTimeString()),n.join(` · `)}function je(e,t){switch(e){case`resolving-image`:return`fetching the picture…`;case`connecting`:return`connecting to the provider…`;case`first-token-wait`:return`waiting for the model — a cold load can take a while (up to ${String(Math.round(t/1e3))}s)`;case`streaming`:return`answering…`}}b();var Me=[`deviceManager`,`listAll`,`cameras`],Ne=[`pipelineAnalytics`,`listRecentTracks`,`ai-test`],Pe=360*60*1e3,Fe=40,Ie=160,$={phase:`connecting`,firstTokenTimeoutMs:0,text:``,mediaSent:null};function Le(){let{t:e}=G(),t=k(),[n,a]=T(``),[o,s]=T(``),[c,u]=T(``),[d,p]=T([]),[m,g]=T(null),[_,b]=T(`none`),[w,E]=T(null),[A,N]=T(null),P=y(null);O(()=>()=>P.current?.abort(),[]);let F=C({queryKey:J,queryFn:()=>t.trpcClient.llm.listProfiles.query({})}),R=S(()=>(F.data??[]).filter(e=>e.enabled),[F.data]),z=R.find(e=>e.id===n)??null,B=A!==null,V=v(async(t,r)=>{let i=new AbortController;P.current=i,E(null),N($);let a=``,s=null,c,l=null,u=null;try{let e=await fetch(Ce,{method:`POST`,headers:{"content-type":`application/json`},credentials:`same-origin`,signal:i.signal,body:JSON.stringify({profileId:n,messages:t,...o.trim()===``?{}:{system:o.trim()},...r===void 0?{}:{attachment:r}})});if(!e.ok||e.body===null){let t=await e.text().catch(()=>``);throw Error(t.length>0?t:`HTTP ${String(e.status)}`)}for await(let t of Oe(e.body))switch(t.kind){case`status`:N(e=>({...e??$,phase:t.phase}));break;case`meta`:s=t.mediaSent,c=t.model,N(e=>({...e??$,firstTokenTimeoutMs:t.firstTokenTimeoutMs,mediaSent:t.mediaSent}));break;case`token`:a+=t.text,N(e=>({...e??$,text:a}));break;case`done`:u={outputTokens:t.outputTokens,latencyMs:t.latencyMs};break;case`error`:l=`${t.code}: ${t.message}`;break}}catch(t){i.signal.aborted||E(t instanceof Error?t.message:e(`common.error`,`Error`))}finally{P.current=null,N(null)}let d=i.signal.aborted&&a.length>0;l===null&&a.length===0&&!d||p(e=>[...e,{id:`a-${String(Date.now())}`,role:`assistant`,content:l??a,...l===null?{}:{failed:!0},...s===null?{}:{attachment:s},...c!==void 0&&l===null?{model:c}:{},...u===null?{}:u}])},[n,o,e]),U=v(()=>{let e=c.trim();if(e===``||n===``||B)return;let t={id:`u-${String(Date.now())}`,role:`user`,content:e,...m===null?{}:{attachmentLabel:m.label,attachmentKind:m.ref.kind}},r=[...d,t];p(r),u(``);let i=m?.ref;g(null),b(`none`),V(ke(r),i)},[c,m,n,V,B,d]),W=()=>P.current?.abort();return x(K,{icon:j,title:e(`ai.testTitle`,`Test chat`),subtitle:e(`ai.testSubtitle`,`A throwaway conversation with one profile. Attach a live camera snapshot or a recent track to check the model can actually read a picture. Nothing is saved — only the usage row.`),actions:x(i,{size:`sm`,variant:`secondary`,type:`button`,disabled:d.length===0&&m===null,onClick:()=>{P.current?.abort(),p([]),g(null),u(``),E(null),N(null)},children:[D(te,{className:`h-3.5 w-3.5`}),e(`ai.clearChat`,`Clear`)]}),children:[x(l,{className:`space-y-3 p-4`,children:[x(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[x(`div`,{children:[D(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-test-profile`,children:e(`ai.profile`,`Profile`)}),D(h,{id:`ai-test-profile`,value:n,onChange:e=>a(e.target.value),options:[{value:``,label:e(`ai.selectProfile`,`Select a profile…`)},...R.map(e=>({value:e.id,label:`${e.name} · ${e.model}${e.supportsVision?` · vision`:``}`}))]}),R.length===0&&!F.isLoading&&D(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:e(`ai.noEnabledProfiles`,`No enabled profile. Add one on the Profiles tab.`)})]}),x(`div`,{children:[D(`label`,{className:`mb-1 block text-[11px] font-medium text-foreground`,htmlFor:`ai-test-system`,children:e(`ai.systemPrompt`,`System prompt (optional)`)}),D(f,{id:`ai-test-system`,value:o,onChange:e=>s(e.target.value),placeholder:e(`ai.systemPlaceholder`,`Answer in one short sentence.`)})]})]}),D(`p`,{className:`text-[10px] text-foreground-subtle`,children:e(`ai.streamNote`,`The answer streams as the model produces it. A cold model can take a while to load — the status line says which phase it is in.`)}),z!==null&&!z.supportsVision&&D(`p`,{className:`text-[10px] text-warning`,children:e(`ai.notVision`,`This profile is not vision-capable — an attached image will be refused before anything is read.`)})]}),w!==null&&D(r,{title:e(`ai.chatFailed`,`The test call failed`),message:w}),D(Re,{turns:d,live:A}),x(l,{className:`space-y-2 p-3`,children:[m!==null&&x(`div`,{className:`flex items-center gap-2 rounded-md border border-border bg-surface px-2.5 py-1.5`,children:[m.ref.kind===`snapshot`?D(L,{className:`h-3.5 w-3.5 text-foreground-subtle`}):D(H,{className:`h-3.5 w-3.5 text-foreground-subtle`}),D(`span`,{className:`min-w-0 flex-1 truncate text-[11px] text-foreground`,children:m.label}),D(i,{size:`sm`,variant:`ghost`,type:`button`,onClick:()=>g(null),children:D(ee,{className:`h-3.5 w-3.5`})})]}),x(`div`,{className:`flex flex-wrap items-center gap-2`,children:[x(i,{size:`sm`,variant:_===`snapshot`?`primary`:`outline`,type:`button`,onClick:()=>b(_===`snapshot`?`none`:`snapshot`),children:[D(L,{className:`h-3.5 w-3.5`}),e(`ai.attachSnapshot`,`Camera snapshot`)]}),x(i,{size:`sm`,variant:_===`track`?`primary`:`outline`,type:`button`,onClick:()=>b(_===`track`?`none`:`track`),children:[D(H,{className:`h-3.5 w-3.5`}),e(`ai.attachTrack`,`Recent track`)]})]}),_===`snapshot`&&D(Be,{onPick:t=>{g({ref:{kind:`snapshot`,deviceId:t.id},label:e(`ai.snapshotOf`,`Snapshot of {{name}}`,{name:t.name})}),b(`none`)}}),_===`track`&&D(He,{onPick:(t,n)=>{g({ref:{kind:`track`,trackId:t.trackId},label:e(`ai.trackOf`,`{{class}} on {{name}}`,{class:t.label??t.className,name:n})}),b(`none`)}}),x(`div`,{className:`flex items-center gap-2`,children:[D(f,{value:c,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),U())},placeholder:e(`ai.messagePlaceholder`,`Ask the model something…`),"aria-label":e(`ai.message`,`Message`)}),B?x(i,{size:`sm`,variant:`secondary`,type:`button`,onClick:W,children:[D(I,{className:`h-3.5 w-3.5`}),e(`ai.stop`,`Stop`)]}):x(i,{size:`sm`,type:`button`,disabled:c.trim()===``||n===``,onClick:U,children:[D(M,{className:`h-3.5 w-3.5`}),e(`ai.send`,`Send`)]})]})]})]})}function Re({turns:e,live:t}){let{t:n}=G();return e.length===0&&t===null?D(`div`,{className:`py-12 text-center text-xs text-foreground-subtle`,children:n(`ai.chatEmpty`,`Pick a profile, optionally attach a camera snapshot or a recent track, and send a message. Nothing here is saved.`)}):D(l,{children:x(`div`,{className:`max-h-[50vh] space-y-2 overflow-y-auto p-3`,children:[e.map(e=>D(ze,{turn:e},e.id)),t!==null&&x(`div`,{className:`space-y-1`,children:[t.text.length>0&&D(ze,{turn:{id:`live`,role:`assistant`,content:t.text},streaming:!0}),x(`div`,{className:`flex items-center gap-2 text-[11px] text-foreground-subtle`,children:[D(V,{className:`h-3.5 w-3.5 animate-spin`}),je(t.phase,t.firstTokenTimeoutMs)]})]})]})})}function ze({turn:e,streaming:t=!1}){let n=e.role===`user`,r=e.failed===!0?`border-danger/40 bg-danger/10`:`border-border bg-surface`;return D(`div`,{className:`flex ${n?`justify-end`:`justify-start`}`,children:x(`div`,{className:`max-w-[85%] rounded-lg border px-3 py-2 ${n?`border-primary/40 bg-primary/10`:r}`,children:[x(`p`,{className:`whitespace-pre-wrap break-words text-xs text-foreground`,children:[e.content,t&&D(`span`,{className:`ml-0.5 animate-pulse text-primary`,children:`▌`})]}),e.attachmentLabel!==void 0&&x(`p`,{className:`mt-1 flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[e.attachmentKind===`track`?D(H,{className:`h-3 w-3`}):D(L,{className:`h-3 w-3`}),e.attachmentLabel]}),e.attachment!==void 0&&x(`p`,{className:`mt-1 flex items-center gap-1 text-[10px] text-foreground-subtle`,children:[e.attachment.kind===`snapshot`?D(L,{className:`h-3 w-3`}):D(H,{className:`h-3 w-3`}),Ae(e.attachment)]}),e.model!==void 0&&D(`p`,{className:`mt-1 text-[10px] text-foreground-subtle`,children:`${e.model} · ${String(e.outputTokens??0)} tok · ${String(e.latencyMs??0)} ms`})]})})}function Be({onPick:e}){let{t}=G(),n=k(),r=C({queryKey:Me,queryFn:()=>n.trpcClient.deviceManager.listAll.query({isCamera:!0,projection:`slim`})}),i=(r.data??[]).filter(e=>!e.disabled);return r.isLoading?D(V,{className:`h-4 w-4 animate-spin text-foreground-subtle`}):i.length===0?D(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`ai.noCameras`,`No camera found.`)}):D(`div`,{className:`grid max-h-56 grid-cols-2 gap-2 overflow-y-auto sm:grid-cols-4`,children:i.map(t=>D(Ve,{device:t,onPick:e},t.id))})}function Ve({device:e,onPick:t}){let{src:n}=p(e.id,{width:Ie});return x(`button`,{type:`button`,onClick:()=>t(e),className:`overflow-hidden rounded-md border border-border bg-surface text-left transition-colors hover:border-primary/50`,children:[D(`span`,{className:`block aspect-video w-full bg-background-elevated`,children:n!==null&&D(`img`,{src:n,alt:``,className:`h-full w-full object-cover`,loading:`lazy`})}),x(`span`,{className:`flex items-center gap-1 px-2 py-1`,children:[!e.online&&D(c,{variant:`warning`,children:`off`}),D(`span`,{className:`truncate text-[10px] text-foreground`,children:e.name})]})]})}function He({onPick:e}){let{t}=G(),n=k(),r=C({queryKey:Me,queryFn:()=>n.trpcClient.deviceManager.listAll.query({isCamera:!0,projection:`slim`})}),i=S(()=>(r.data??[]).map(e=>e.id),[r.data]),a=S(()=>{let e=new Map;for(let t of r.data??[])e.set(t.id,t.name);return e},[r.data]),o=C({queryKey:[...Ne,i.length],enabled:i.length>0,queryFn:()=>n.trpcClient.pipelineAnalytics.listRecentTracks.query({deviceIds:[...i],since:Date.now()-Pe,limit:Fe,projection:`slim`})});if(r.isLoading||o.isLoading)return D(V,{className:`h-4 w-4 animate-spin text-foreground-subtle`});let s=o.data?.tracks??[];return s.length===0?D(`p`,{className:`text-[11px] text-foreground-subtle`,children:t(`ai.noTracks`,`No track in the last 6 hours.`)}):D(`div`,{className:`max-h-56 divide-y divide-border overflow-y-auto rounded-md border border-border`,children:s.map(t=>x(`button`,{type:`button`,onClick:()=>e(t,a.get(t.deviceId)??String(t.deviceId)),className:`flex w-full items-center gap-2 px-2.5 py-1.5 text-left text-[11px] hover:bg-surface-hover`,children:[D(H,{className:`h-3.5 w-3.5 shrink-0 text-foreground-subtle`}),D(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:t.label??t.className}),D(`span`,{className:`shrink-0 text-foreground-subtle`,children:a.get(t.deviceId)??t.deviceId}),D(`span`,{className:`shrink-0 text-foreground-subtle`,children:new Date(t.lastSeen).toLocaleTimeString()})]},t.trackId))})}b();var Ue=1440*60*1e3,We=[1,7,30,90];function Ge(){let{t:e}=G(),t=k(),[i,a]=T(7),o=S(()=>{let e=new Date;return e.setHours(0,0,0,0),e.getTime()-(i-1)*Ue},[i]),s=C({queryKey:J,queryFn:()=>t.trpcClient.llm.listProfiles.query({})}),c=C({queryKey:[...se,i],queryFn:()=>t.trpcClient.llm.getUsage.query({since:o})}),u=S(()=>{let e=new Map;for(let t of s.data??[])e.set(t.id,t.name);return e},[s.data]),d=S(()=>[{key:`day`,header:e(`ai.colDay`,`Day`),nowrap:!0,render:e=>e.day},{key:`consumer`,header:e(`ai.colConsumer`,`Consumer`),nowrap:!0,render:e=>D(`span`,{className:`text-[11px] text-foreground`,children:e.consumer})},{key:`profile`,header:e(`ai.colProfile`,`Profile`),render:e=>D(`span`,{className:`text-[11px] text-foreground`,children:u.get(e.profileId)??e.profileId})},{key:`calls`,header:e(`ai.colCalls`,`Calls`),align:`right`,nowrap:!0,render:e=>String(e.calls)},{key:`okErr`,header:e(`ai.colOkErr`,`OK / err`),align:`right`,nowrap:!0,render:e=>D(`span`,{className:e.errorCalls>0?`text-danger`:void 0,children:`${String(e.okCalls)} / ${String(e.errorCalls)}`})},{key:`tokens`,header:e(`ai.colTokens`,`In / out tok`),align:`right`,nowrap:!0,render:e=>`${String(e.inputTokens)} / ${String(e.outputTokens)}`},{key:`latency`,header:e(`ai.colAvgMs`,`Avg ms`),align:`right`,nowrap:!0,render:e=>String(Math.round(e.avgLatencyMs))}],[u,e]),f=c.data??[];return x(K,{icon:R,title:e(`ai.usageTitle`,`Usage`),subtitle:e(`ai.usageSubtitle`,`Server-side rollup per day, consumer and profile — never raw call rows. Errors are counted, so a profile that always fails is visible here before a feature reports it.`),actions:D(`div`,{className:`w-40`,children:D(h,{"aria-label":e(`ai.window`,`Window`),value:String(i),options:We.map(t=>({value:String(t),label:e(`ai.lastDays`,`Last {{days}} days`,{days:t})})),onChange:e=>a(Number(e.target.value))})}),children:[c.isError&&D(r,{title:e(`ai.usageFailed`,`Failed to read usage`),message:c.error instanceof Error?c.error.message:e(`common.error`,`Error`),onRetry:()=>void c.refetch()}),f.length===0?D(`div`,{className:`py-16 text-center text-xs text-foreground-subtle`,children:e(`ai.noUsage`,`No AI calls in this window.`)}):D(l,{children:D(n,{columns:d,rows:f,rowKey:e=>`${e.day}|${e.consumer}|${e.profileId}`,minWidthPx:720,bordered:!1,mobileMode:`scroll`,maxBodyHeight:_})})]})}function Ke(){let{t:e}=G();return D(`div`,{className:`flex flex-col p-4`,children:D(ne,{tabs:[{id:`profiles`,label:e(`ai.tabProfiles`,`Profiles`),icon:A,content:D(ve,{})},{id:`runtimes`,label:e(`ai.tabRuntimes`,`Runtimes`),icon:F,content:D(Se,{})},{id:`usage`,label:e(`ai.tabUsage`,`Usage`),icon:R,content:D(Ge,{})},{id:`test`,label:e(`ai.tabTest`,`Test`),icon:j,content:D(Le,{})}]})})}export{Ke as AiProfilesPage,Ke as default};
@@ -1 +0,0 @@
1
- import{k as e,rn as t,un as n}from"./src-BmAmiAXy.js";import{Q as r,S as i,W as a,q as o,x as s}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 c}from"./FormBuilder-DVbN4jV5.js";import{S as l}from"./index-B6kDpXr5.js";r();function u(t,n){if(!t)return n;let r=new Set;for(let i of t.sections){let t=i.fields;for(let i of t)!(`key`in i)||typeof i.key!=`string`||e(i,n,t)&&r.add(i.key)}let i={};for(let[e,t]of Object.entries(n))r.has(e)&&(i[e]=t);return i}function d({kind:e,addonId:r,initialValues:d,onSubmit:f,onCancel:p,submitLabel:m,disabled:h}){let[g,_]=o(d??{}),[v,y]=o(null),b=t({kind:e,...r===void 0?{}:{addonId:r}}),x=a(()=>{let e=b.data;if(e&&typeof e==`object`&&`sections`in e&&Array.isArray(e.sections))return e},[b.data]),S=n(),C=async()=>{y(null);let t=u(x,g);try{let n=await S.mutateAsync({kind:e,settings:t,...r===void 0?{}:{addonId:r}});y(n.ok?{ok:!0}:{ok:!1,error:n.error})}catch(e){y({ok:!1,error:e instanceof Error?e.message:String(e)})}};return i(`div`,{className:`space-y-3`,children:[b.isLoading&&i(`div`,{className:`flex items-center gap-2 text-xs text-foreground-subtle`,children:[s(l,{className:`h-3.5 w-3.5 animate-spin`}),` Loading schema…`]}),x&&s(c,{schema:x,values:g,onChange:_}),b.isError&&i(`div`,{className:`rounded border border-danger/30 bg-danger/5 text-danger px-3 py-2 text-[11px]`,children:[`Failed to load settings schema:`,` `,b.error instanceof Error?b.error.message:`Unknown error`]}),!x&&!b.isLoading&&!b.isError&&i(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:[`No settings schema available for kind `,s(`code`,{className:`font-mono`,children:e}),`. Its broker addon may not be installed or running.`]}),v&&s(`div`,{className:`rounded border px-3 py-2 text-[11px] ${v.ok?`border-success/30 bg-success/5 text-success`:`border-danger/30 bg-danger/5 text-danger`}`,children:v.ok?`Connection OK.`:`Test failed: ${v.error??`unknown error`}`}),i(`div`,{className:`flex items-center justify-between gap-2 pt-1`,children:[s(`button`,{type:`button`,onClick:p,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),i(`div`,{className:`flex items-center gap-2`,children:[s(`button`,{type:`button`,onClick:()=>{C()},disabled:S.isPending||!x,className:`rounded border border-border px-3 py-1.5 text-xs text-foreground hover:bg-primary/10 disabled:opacity-50`,children:S.isPending?`Testing…`:`Test connection`}),s(`button`,{type:`button`,onClick:()=>{f(u(x,g))},disabled:!x||h,className:`inline-flex items-center gap-1.5 rounded bg-primary px-4 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:m??`Save`})]})]})]})}export{d as t};
@@ -1,32 +0,0 @@
1
- import{$o as e,As as t,Do as n,Go as r,Ho as i,Ms as a,Qo as o,So as s,To as c,Uo as l,Wo as u,Zo as d,_s as f,fs as p,gs as m,hs as h,ms as g,ps as _,v,wo as y}from"./src-BmAmiAXy.js";import{I as b,K as x,M as S,Q as C,S as w,T,W as E,a as D,b as O,q as k,t as A,x as j,z as M}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{$ as N,J as P,et as F,k as I,nt as ee,rt as L,tt as R,yt as te}from"./src-BizjMCcy.js";import{c as z}from"./widget-panel-BF8s8cZY.js";import{t as ne}from"./boxes-BCCj5PaE.js";import{t as re}from"./pencil-OtLKJIw8.js";import{t as ie}from"./play-Q-R5vHEh.js";import{t as B}from"./plus-vrCV3Fn-.js";import{t as ae}from"./rotate-cw-B6qXQ5pJ.js";import{F as oe,G as se,L as ce,N as le,S as ue,Y as de,b as fe,m as pe,o as me,s as V,w as he}from"./index-B6kDpXr5.js";import{t as ge}from"./AdminPage-Dq33XE9j.js";var _e=se(`arrow-down`,[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]),ve=se(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),ye=se(`braces`,[[`path`,{d:`M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1`,key:`ezmyqa`}],[`path`,{d:`M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1`,key:`e1hn23`}]]),be=se(`ungroup`,[[`rect`,{width:`8`,height:`6`,x:`5`,y:`4`,rx:`1`,key:`nzclkv`}],[`rect`,{width:`8`,height:`6`,x:`11`,y:`14`,rx:`1`,key:`4tytwb`}]]);C();var xe=6e4;function Se(){let e=z();return D({queryKey:[`automation`,`devices`],staleTime:xe,queryFn:async()=>(await e.trpcClient.deviceManager.listAll.query({projection:`slim`})).map(e=>({id:e.id,name:e.name,stableId:e.stableId})).sort((e,t)=>e.name.localeCompare(t.name))})}function Ce(e){let t=z();return D({queryKey:[`automation`,`device-caps`,e],enabled:e>0,staleTime:xe,queryFn:async()=>{let n=await t.trpcClient.deviceManager.getBindings.query({deviceId:e});return[...new Set(n.entries.map(e=>e.capName))].sort((e,t)=>e.localeCompare(t))}})}function we(e){let t=z();return D({queryKey:[`automation`,`wireable-fields`,e],enabled:e>0,staleTime:xe,queryFn:async()=>(await t.trpcClient.deviceManager.getWireableFields.query({deviceId:e})).caps})}function Te(e,t){return e.find(e=>e.cap===t)?.fields??[]}function Ee(){let e=new Set;for(let t of Object.values(I))t.capScope===`device`&&e.add(t.capName);return[...e].sort((e,t)=>e.localeCompare(t))}function De(e){if(e===``)return[];let t=new Set;for(let[n,r]of Object.entries(I)){if(r.capName!==e||r.capScope!==`device`||r.access===`view`)continue;let i=n.slice(n.indexOf(`.`)+1);i!==``&&t.add(i)}return[...t].sort((e,t)=>e.localeCompare(t))}function H({children:e}){return j(`span`,{className:`mb-1 block text-xs text-foreground-subtle`,children:e})}function Oe(e){let t=we(e.deviceId);if(t.data!==void 0)return Te(t.data,e.cap).find(t=>t.path===e.fieldPath)}function ke({value:e,devices:t,onChange:n}){let r=we(e.deviceId),i=r.data??[],a=Te(i,e.cap);return w(O,{children:[w(`label`,{className:`min-w-[10rem] flex-1`,children:[j(H,{children:`Device`}),j(_,{value:String(e.deviceId),onChange:e=>n({deviceId:Number(e.target.value),cap:``,fieldPath:``}),options:[{value:`0`,label:`Select a device…`},...t.map(e=>({value:String(e.id),label:e.name}))]})]}),w(`label`,{className:`min-w-[9rem] flex-1`,children:[j(H,{children:`Capability`}),j(_,{value:e.cap,disabled:e.deviceId===0,onChange:t=>n({...e,cap:t.target.value,fieldPath:``}),options:[{value:``,label:Ae(e.deviceId,i.length,r.isLoading)},...i.map(e=>({value:e.cap,label:e.cap}))]})]}),w(`label`,{className:`min-w-[9rem] flex-1`,children:[j(H,{children:`Field`}),j(_,{value:e.fieldPath,disabled:e.cap===``,onChange:t=>n({...e,fieldPath:t.target.value}),options:[{value:``,label:a.length===0?`No readable fields`:`Select a field…`},...a.map(e=>({value:e.path,label:`${e.path} (${e.kind})`}))]})]})]})}function Ae(e,t,n){return e===0?`Pick a device first`:n?`Reading this device…`:t===0?`This device reports no readable capabilities`:`Select a capability…`}var je=[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`,`contains`,`in`];function Me(e){switch(e){case`boolean`:return[`eq`,`ne`];case`number`:return[`eq`,`ne`,`gt`,`gte`,`lt`,`lte`];case`string`:case`enum`:return[`eq`,`ne`,`contains`,`in`];default:return je}}function Ne(e){switch(e){case`eq`:return`is`;case`ne`:return`is not`;case`gt`:return`is above`;case`gte`:return`is at least`;case`lt`:return`is below`;case`lte`:return`is at most`;case`contains`:return`contains`;default:return`is one of`}}function Pe(e){return Me(e).map(e=>({value:e,label:Ne(e)}))}function Fe(e){switch(e){case`device-state`:return`A device field changes`;case`device-event`:return`An event happens`;case`schedule`:return`On a schedule`;default:return`Only when run by hand`}}var Ie={triggers:[],actions:[]};function Le(e){switch(e){case`device-state`:return{kind:e,deviceId:0,cap:``,fieldPath:``};case`device-event`:return{kind:e,category:``};case`schedule`:return{kind:e,cron:`0 30 23 * * *`};default:return{kind:`manual`}}}function Re(e){switch(e){case`wait`:return{kind:e,seconds:5};case`code`:return{kind:e,code:`// runs inside this automation, with ctx in scope
2
- `};default:return{kind:`cap`,deviceId:0,cap:``,method:``}}}function ze(){return{kind:`condition`,deviceId:0,cap:``,fieldPath:``,operator:`eq`,value:``}}function Be(){return{kind:`expression`,expr:``,bindings:{}}}function Ve(e,t,n){return e.map((e,r)=>r===t?n:e)}function He(e,t){return e.filter((e,n)=>n!==t)}function Ue(e,t,n){let r=e[t];if(r===void 0)return e;let i=Math.min(Math.max(n,0),e.length-1);if(i===t)return e;let a=He(e,t);return[...a.slice(0,i),r,...a.slice(i)]}function We(e,t){return{...e,triggers:[...t]}}function Ge(e,t){return{...e,actions:[...t]}}var Ke=`deviceId`,qe=`$trigger`,Je=[{value:`cap`,label:`Do something`},{value:`wait`,label:`Wait`},{value:`code`,label:`Run code`}];function Ye({actions:e,devices:t,onChange:n}){return w(`div`,{className:`space-y-2`,children:[e.length===0&&j(`p`,{className:`text-xs text-warning`,children:`No actions yet. An automation that does nothing is not an automation.`}),e.map((r,i)=>w(`div`,{className:`rounded border border-border p-3 space-y-2`,children:[w(`div`,{className:`flex flex-wrap items-end gap-2`,children:[j(m,{variant:`default`,children:i+1}),w(`label`,{className:`w-40`,children:[j(H,{children:`Step`}),j(_,{value:r.kind,onChange:t=>n(Ve(e,i,Re(Xe(t.target.value)))),options:Je.map(e=>({value:e.value,label:e.label}))})]}),w(`div`,{className:`ml-auto flex items-center gap-1`,children:[j(f,{variant:`ghost`,disabled:i===0,onClick:()=>n(Ue(e,i,i-1)),title:`Run this step earlier`,children:j(ve,{className:`h-3.5 w-3.5`})}),j(f,{variant:`ghost`,disabled:i===e.length-1,onClick:()=>n(Ue(e,i,i+1)),title:`Run this step later`,children:j(_e,{className:`h-3.5 w-3.5`})}),j(f,{variant:`ghost`,onClick:()=>n(He(e,i)),title:`Remove this step`,children:j(V,{className:`h-3.5 w-3.5`})})]})]}),r.kind===`wait`&&w(`label`,{className:`block w-32`,children:[j(H,{children:`Seconds`}),j(g,{type:`number`,min:0,max:300,value:String(r.seconds),onChange:t=>n(Ve(e,i,{kind:`wait`,seconds:Number(t.target.value)}))})]}),r.kind===`code`&&w(`label`,{className:`block`,children:[j(H,{children:`Code`}),j(`textarea`,{className:`h-32 w-full rounded-md border border-border bg-surface p-2 font-mono text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,value:r.code,spellCheck:!1,onChange:t=>n(Ve(e,i,{kind:`code`,code:t.target.value}))}),w(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:[`Compiled into this automation's own block by the same compiler as a script — not evaluated at run time. `,j(`code`,{children:`ctx`}),` and `,j(`code`,{children:`vars`}),` are in scope.`]})]}),r.kind===`cap`&&j(Ze,{action:r,devices:t,onChange:t=>n(Ve(e,i,t))})]},`${r.kind}-${String(i)}`)),w(`div`,{className:`flex items-center gap-2`,children:[w(f,{variant:`outline`,onClick:()=>n([...e,Re(`cap`)]),children:[j(B,{className:`h-4 w-4`}),` Step`]}),e.length>1&&j(`span`,{className:`text-xs text-foreground-subtle`,children:`Steps run in order and stop at the first failure.`})]})]})}function Xe(e){return Je.find(t=>t.value===e)?.value??`cap`}function Ze({action:e,devices:t,onChange:n}){let r=typeof e.deviceId!=`number`,i=typeof e.deviceId==`number`?e.deviceId:0,a=Ce(i),o=r?Ee():a.data??[],s=De(e.cap);return w(`div`,{className:`flex flex-wrap items-end gap-2`,children:[w(`label`,{className:`min-w-[11rem] flex-1`,children:[j(H,{children:`Device`}),j(_,{value:r?qe:String(i),onChange:t=>n({...e,deviceId:t.target.value===qe?{$var:Ke}:Number(t.target.value),cap:``,method:``}),options:[{value:`0`,label:`Select a device…`},{value:qe,label:`The device that triggered this run`},...t.map(e=>({value:String(e.id),label:e.name}))]})]}),w(`label`,{className:`min-w-[10rem] flex-1`,children:[j(H,{children:`Capability`}),j(_,{value:e.cap,disabled:o.length===0,onChange:t=>n({...e,cap:t.target.value,method:``}),options:[{value:``,label:o.length===0?`Pick a device first`:`Select a capability…`},...o.map(e=>({value:e,label:e}))]})]}),w(`label`,{className:`min-w-[9rem] flex-1`,children:[j(H,{children:`Method`}),j(_,{value:e.method,disabled:s.length===0,onChange:t=>n({...e,method:t.target.value}),options:[{value:``,label:s.length===0?`Pick a capability first`:`Select a method…`},...s.map(e=>({value:e,label:e}))]})]}),w(`label`,{className:`min-w-[10rem] flex-1`,children:[j(H,{children:`Arguments (JSON)`}),j(g,{value:e.args===void 0?``:JSON.stringify(e.args),placeholder:`{"mode":"away"}`,onChange:t=>n(Qe(e,t.target.value))})]})]})}function Qe(e,t){if(t.trim()===``)return{kind:`cap`,deviceId:e.deviceId,cap:e.cap,method:e.method};try{let n=JSON.parse(t);if(typeof n!=`object`||!n||Array.isArray(n))return e;let r={};for(let[e,t]of Object.entries(n))r[e]=t;return{...e,args:r}}catch{return e}}function $e({value:e,field:t,onChange:n}){return t?.kind===`boolean`?j(_,{value:e===!0?`true`:`false`,onChange:e=>n(e.target.value===`true`),options:[{value:`true`,label:`true`},{value:`false`,label:`false`}]}):t?.kind===`enum`&&t.enumValues!==void 0&&t.enumValues.length>0?j(_,{value:String(e),onChange:e=>n(e.target.value),options:t.enumValues.map(e=>({value:e,label:e}))}):t?.kind===`number`?j(g,{type:`number`,value:typeof e==`number`?String(e):``,placeholder:`0`,onChange:e=>{let t=Number(e.target.value);e.target.value!==``&&!Number.isNaN(t)&&n(t)}}):j(g,{value:String(e),placeholder:`value`,onChange:e=>n(e.target.value)})}function et({value:e,field:t,onChange:n}){return j(g,{value:e.join(`, `),placeholder:`one, two, three`,onChange:e=>{let r=e.target.value.split(`,`).map(e=>e.trim()).filter(e=>e!==``);n(t?.kind===`number`?r.map(e=>Number(e)).filter(e=>!Number.isNaN(e)):r)}})}function tt(e){return typeof e==`object`}function nt(e){return tt(e)?e[0]??``:e}function rt(e){return tt(e)?e:typeof e==`boolean`?[]:[e]}function it({leaf:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},i=Oe(r),a=Pe(i?.kind),o=e.operator===`in`,s=t=>{n({...e,deviceId:t.deviceId,cap:t.cap,fieldPath:t.fieldPath})},c=t=>{let r=at(t,a);n({...e,operator:r,value:r===`in`?rt(e.value):nt(e.value)})};return w(`div`,{className:`flex flex-wrap items-end gap-2`,children:[j(ke,{value:r,devices:t,onChange:s}),w(`label`,{className:`min-w-[8rem]`,children:[j(H,{children:`Comparison`}),j(_,{value:e.operator,onChange:e=>c(e.target.value),options:a.map(e=>({value:e.value,label:e.label}))})]}),w(`label`,{className:`min-w-[9rem] flex-1`,children:[j(H,{children:`Value`}),o?j(et,{value:rt(e.value),field:i,onChange:t=>n({...e,value:t})}):j($e,{value:nt(e.value),field:i,onChange:t=>n({...e,value:t})})]})]})}function at(e,t){return t.find(t=>t.value===e)?.value??`eq`}var ot={kind:`global`,sourceStableId:``,cap:``,fieldPath:``};function st({leaf:e,devices:t,onChange:n}){let r=Object.entries(e.bindings),i=t=>{n({kind:`expression`,expr:e.expr,bindings:t})};return w(`div`,{className:`space-y-2`,children:[w(`label`,{className:`block`,children:[j(H,{children:`Expression`}),j(g,{value:e.expr,placeholder:`indoor - outdoor > 5`,onChange:t=>n({kind:`expression`,expr:t.target.value,bindings:e.bindings})}),j(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:`Must evaluate to true or false. Every name in it has to be bound below — an unbound name is refused when the automation is saved, not when it runs.`})]}),w(`div`,{className:`space-y-1.5`,children:[r.length===0&&j(`p`,{className:`text-xs text-foreground-subtle`,children:`No names bound yet. An expression reads devices only through these.`}),r.map(([n,r])=>j(ct,{alias:n,source:r,devices:t,onRename:t=>i(mt(e.bindings,n,t)),onChange:t=>i({...e.bindings,[n]:t}),onRemove:()=>i(ht(e.bindings,n))},n)),w(f,{variant:`ghost`,onClick:()=>i({...e.bindings,[pt(e.bindings)]:ot}),children:[j(B,{className:`h-3.5 w-3.5`}),` Name`]})]})]})}function ct({alias:e,source:t,devices:n,onRename:r,onChange:i,onRemove:a}){let o=t.kind===`literal`,s=o?{deviceId:0,cap:``,fieldPath:``}:{deviceId:dt(n,ut(t)),cap:t.cap,fieldPath:t.fieldPath};return w(`div`,{className:`flex flex-wrap items-end gap-2 rounded border border-border p-2`,children:[w(`label`,{className:`w-32`,children:[j(H,{children:`Name`}),j(g,{value:e,placeholder:`indoor`,onChange:e=>r(e.target.value)})]}),w(`label`,{className:`w-36`,children:[j(H,{children:`Reads`}),j(_,{value:o?`literal`:`global`,onChange:e=>i(e.target.value===`literal`?{kind:`literal`,value:``}:ot),options:[{value:`global`,label:`A device field`},{value:`literal`,label:`A constant`}]})]}),o?w(`label`,{className:`min-w-[9rem] flex-1`,children:[j(H,{children:`Constant`}),j(g,{value:t.value===null?``:String(t.value),placeholder:`5`,onChange:e=>i({kind:`literal`,value:lt(e.target.value)})})]}):j(ke,{value:s,devices:n,onChange:e=>i({kind:`global`,sourceStableId:ft(n,e.deviceId),cap:e.cap,fieldPath:e.fieldPath})}),j(f,{variant:`ghost`,onClick:a,title:`Remove this name`,children:j(V,{className:`h-3.5 w-3.5`})})]})}function lt(e){let t=e.trim();return t===`true`?!0:t===`false`?!1:t!==``&&!Number.isNaN(Number(t))?Number(t):e}function ut(e){return e.kind===`global`?e.sourceStableId:``}function dt(e,t){return e.find(e=>e.stableId===t)?.id??0}function ft(e,t){return e.find(e=>e.id===t)?.stableId??``}function pt(e){for(let t=0;t<26;t+=1){let n=String.fromCharCode(97+t);if(!(n in e))return n}return`n${String(Object.keys(e).length)}`}function mt(e,t,n){let r={};for(let[i,a]of Object.entries(e))i===t?r[n]=a:r[i]=a;return r}function ht(e,t){let n={};for(let[r,i]of Object.entries(e))r!==t&&(n[r]=i);return n}function U(e){return e.kind===`all`||e.kind===`any`}function W(e){let t=e.conditions;return t===void 0?{kind:`all`,children:[]}:U(t)?t:{kind:`all`,children:[t]}}function gt(e,t){return t===null||U(t)&&t.children.length===0?{triggers:e.triggers,actions:e.actions}:{triggers:e.triggers,actions:e.actions,conditions:t}}function _t(e){return gt(e,W(e))}function G(e,t){if(t.length===0)return e;let[n,...r]=t;if(n===void 0)return e;if(e.kind===`not`)return n===0?G(e.child,r):null;if(!U(e))return null;let i=e.children[n];return i===void 0?null:G(i,r)}function K(e,t,n){if(t.length===0)return n(e);let[r,...i]=t;if(r===void 0)return n(e);if(e.kind===`not`){if(r!==0)return e;let t=K(e.child,i,n);return t===null?null:{kind:`not`,child:t}}if(!U(e))return e;let a=e.children[r];if(a===void 0)return e;let o=K(a,i,n),s=o===null?[...e.children.slice(0,r),...e.children.slice(r+1)]:[...e.children.slice(0,r),o,...e.children.slice(r+1)];return s.length===0?null:{kind:e.kind,children:s}}function vt(e){return e===null?null:L({triggers:[{kind:`manual`}],actions:[{kind:`wait`,seconds:0}],conditions:e})}function yt(e){let t=W(e);return{depth:t.children.length===0?0:R(t),leaves:t.children.length===0?0:ee(t),depthLimit:3,leafLimit:32}}function bt(e,t){let n=vt(t);return n===null?{ok:!0,recipe:gt(e,t)}:{ok:!1,reason:n}}function xt(e,t){let n=W(e);return bt(e,{kind:n.kind,children:[...n.children,t]})}function St(e,t,n){return gt(e,K(W(e),t,()=>n))}function Ct(e,t){return gt(e,K(W(e),t,()=>null))}function wt(e,t,n){return gt(e,K(W(e),t,e=>U(e)?{kind:n,children:e.children}:e))}function Tt(e,t){return G(W(e),t)===null?{ok:!1,reason:`that row is no longer there`}:bt(e,K(W(e),t,e=>e.kind===`not`?e.child:{kind:`not`,child:e}))}function Et(e){if(e.length===0)return null;let t=e[e.length-1];return t===void 0?null:{path:e.slice(0,-1),index:t}}function Dt(e,t,n){if(t.length<2)return{ok:!1,reason:`select at least two rows — a group of one is just the row`};if(new Set(t.map(e=>e.slice(0,-1).join(`/`))).size!==1)return{ok:!1,reason:`those rows are in different groups — a group can only be made from rows side by side`};let r=Et(t[0]??[]);if(r===null)return{ok:!1,reason:`the root list cannot be grouped into itself`};let i=W(e),a=G(i,r.path);if(a===null||!U(a))return{ok:!1,reason:`those rows are inside a NOT — remove it before grouping them`};let o=[...t.map(e=>e[e.length-1]??-1)].sort((e,t)=>e-t),s=o.map(e=>a.children[e]).filter(e=>e!==void 0);if(s.length!==o.length)return{ok:!1,reason:`one of the selected rows is no longer there`};let c=a.children.filter((e,t)=>!o.includes(t)),l=o[0]??0,u={kind:n,children:s},d={kind:a.kind,children:[...c.slice(0,l),u,...c.slice(l)]};return bt(e,K(i,r.path,()=>d))}function Ot(e,t){if(t.length===0)return{ok:!1,reason:`the outer list is not a group — there is nothing to dissolve`};let n=W(e),r=G(n,t);if(r===null)return{ok:!1,reason:`that group is no longer there`};if(r.kind===`not`)return bt(e,K(n,t,()=>r.child));if(!U(r))return{ok:!1,reason:`that row is a condition, not a group`};let i=Et(t);if(i===null)return{ok:!1,reason:`that group has no parent to dissolve into`};let a=G(n,i.path);if(a===null||!U(a))return{ok:!1,reason:`a group inside a NOT cannot be dissolved in place`};let o={kind:a.kind,children:[...a.children.slice(0,i.index),...r.children,...a.children.slice(i.index+1)]};return bt(e,K(n,i.path,()=>o))}var kt=[{value:`all`,label:`ALL of`},{value:`any`,label:`ANY of`}];function At(e){return e.join(`/`)}function jt(e){return e===``?[]:e.split(`/`).map(e=>Number(e))}function Mt({recipe:e,devices:t,onChange:n}){let[r,i]=k([]),[a,o]=k(null),s=W(e),c=yt(e),l=E(()=>r.map(jt),[r]),u=e=>{if(!e.ok){o(e.reason);return}o(null),i([]),n(e.recipe)},d=Dt(e,l,`all`),p=Dt(e,l,`any`),h=l.length===1?Tt(e,l[0]??[]):{ok:!1,reason:`select exactly one row to negate`},g={devices:t,selected:new Set(r),onToggleSelect:e=>i(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),onUpdate:(t,r)=>n(St(e,t,r)),onRemove:t=>{i([]),n(Ct(e,t))},onSetKind:(t,r)=>n(wt(e,t,r)),onUngroup:t=>u(Ot(e,t))};return w(`div`,{className:`space-y-2`,children:[w(`div`,{className:`flex flex-wrap items-center gap-2`,children:[j(m,{variant:`default`,children:`And only if`}),j(`div`,{className:`w-32`,children:j(_,{value:s.kind,onChange:t=>n(wt(e,[],Nt(t.target.value))),options:kt})}),w(`span`,{className:`text-xs text-foreground-subtle`,children:[`depth `,c.depth,`/`,c.depthLimit,` · `,c.leaves,`/`,c.leafLimit,` conditions`]})]}),s.children.length===0?j(`p`,{className:`text-xs text-foreground-subtle`,children:`No conditions. The actions run every time a trigger fires.`}):j(Pt,{container:s,path:[],handlers:g}),w(`div`,{className:`flex flex-wrap items-center gap-2`,children:[w(f,{variant:`outline`,onClick:()=>u(xt(e,ze())),title:`Compare one device field to a value`,children:[j(B,{className:`h-4 w-4`}),` Condition`]}),w(f,{variant:`outline`,onClick:()=>u(xt(e,Be())),title:`Arithmetic across device fields — the bounded expression engine`,children:[j(ye,{className:`h-4 w-4`}),` Expression`]}),j(`span`,{className:`mx-1 h-5 w-px bg-border`}),j(f,{variant:`ghost`,disabled:!d.ok,onClick:()=>u(d),title:d.ok?`All selected rows must be true`:d.reason,children:`Group as ALL`}),j(f,{variant:`ghost`,disabled:!p.ok,onClick:()=>u(p),title:p.ok?`Any one of the selected rows is enough`:p.reason,children:`Group as ANY`}),j(f,{variant:`ghost`,disabled:!h.ok,onClick:()=>u(h),title:h.ok?`Invert the selected row`:h.reason,children:`NOT`}),r.length>0&&w(`span`,{className:`text-xs text-foreground-subtle`,children:[r.length,` selected`]})]}),a!==null&&j(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-2 text-xs text-warning`,children:a})]})}function Nt(e){return e===`any`?`any`:`all`}function Pt({container:e,path:t,handlers:n}){return j(`div`,{className:`space-y-1.5`,children:e.children.map((e,r)=>j(Ft,{node:e,path:[...t,r],handlers:n},At([...t,r])))})}function Ft({node:e,path:t,handlers:n}){let r=At(t),i=j(p,{checked:n.selected.has(r),onChange:()=>n.onToggleSelect(r),"aria-label":`Select this row for grouping`});return U(e)?w(`div`,{className:`rounded border border-border bg-surface-subtle/40 p-2`,children:[w(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[i,j(`div`,{className:`w-32`,children:j(_,{value:e.kind,onChange:e=>n.onSetKind(t,Nt(e.target.value)),options:kt})}),w(f,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Dissolve this group, keeping its rows`,children:[j(be,{className:`h-3.5 w-3.5`}),` Ungroup`]}),j(f,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Delete this group and everything in it`,children:j(V,{className:`h-3.5 w-3.5`})})]}),j(`div`,{className:`pl-4`,children:j(Pt,{container:e,path:t,handlers:n})})]}):e.kind===`not`?w(`div`,{className:`rounded border border-border p-2`,children:[w(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[i,j(m,{variant:`warning`,children:`NOT`}),w(f,{variant:`ghost`,onClick:()=>n.onUngroup(t),title:`Remove the NOT, keeping the row`,children:[j(be,{className:`h-3.5 w-3.5`}),` Remove NOT`]})]}),j(`div`,{className:`pl-4`,children:j(Ft,{node:e.child,path:[...t,0],handlers:n})})]}):w(`div`,{className:`flex items-start gap-2 rounded border border-border p-2`,children:[j(`div`,{className:`pt-6`,children:i}),j(`div`,{className:`min-w-0 flex-1`,children:e.kind===`condition`?j(it,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)}):j(st,{leaf:e,devices:n.devices,onChange:e=>n.onUpdate(t,e)})}),j(f,{variant:`ghost`,onClick:()=>n.onRemove(t),title:`Remove this condition`,children:j(V,{className:`h-3.5 w-3.5`})})]})}C();function It({code:e,error:t,canEject:n,ejecting:r,onEject:i}){let[a,o]=k(!1),c=y(),l=async()=>{await c({title:`Eject to code — this cannot be undone`,message:`The recipe is removed from the block and it becomes an ordinary script. The visual editor will no longer open it, and there is no way back to it except authoring a new automation from scratch. The code itself is kept exactly as it is now.`,confirmLabel:`Eject to code`,cancelLabel:`Keep it visual`,variant:`warning`})&&i()};return w(`div`,{className:`rounded border border-border`,children:[w(`div`,{className:`flex flex-wrap items-center gap-2 px-3 py-2`,children:[w(f,{variant:`ghost`,onClick:()=>o(!a),children:[j(a?ce:oe,{className:`h-4 w-4`}),`Generated code`]}),j(`span`,{className:`text-xs text-foreground-subtle`,children:`Derived from the recipe above — regenerated on every save, never edited here.`}),w(f,{className:`ml-auto`,variant:`ghost`,disabled:!n||e===null||r,onClick:()=>void l(),title:n?`Take permanent ownership of this code as a script`:`Save the automation first — there is no stored block to eject yet`,children:[j(fe,{className:`h-4 w-4`}),` Eject to code`]})]}),a&&j(`div`,{className:`border-t border-border p-3`,children:e===null?j(`p`,{className:`text-xs text-warning`,children:t??`The recipe is not complete enough to generate a block yet.`}):j(s,{maxHeight:420,children:e})})]})}var Lt=[`device-state`,`device-event`,`schedule`,`manual`],Rt=Object.values(te).sort((e,t)=>e.localeCompare(t));function zt({triggers:e,devices:t,onChange:n}){return w(`div`,{className:`space-y-2`,children:[e.length===0&&j(`p`,{className:`text-xs text-warning`,children:`No triggers yet. Without one nothing can ever start this automation — not even "Run actions", which needs a manual trigger to have somewhere to arrive.`}),e.map((r,i)=>j(Bt,{trigger:r,devices:t,position:i,onChange:t=>n(Ve(e,i,t)),onRemove:()=>n(He(e,i))},`${r.kind}-${String(i)}`)),w(f,{variant:`outline`,onClick:()=>n([...e,Le(`device-state`)]),title:`Add another way this automation can start`,children:[j(B,{className:`h-4 w-4`}),` Trigger`]})]})}function Bt({trigger:e,devices:t,position:n,onChange:r,onRemove:i}){return w(`div`,{className:`rounded border border-border p-3`,children:[w(`div`,{className:`flex flex-wrap items-end gap-2`,children:[j(m,{variant:`default`,children:n===0?`When`:`or when`}),w(`label`,{className:`min-w-[13rem] flex-1`,children:[j(H,{children:`Trigger`}),j(_,{value:e.kind,onChange:e=>r(Le(Vt(e.target.value))),options:Lt.map(e=>({value:e,label:Fe(e)}))})]}),j(f,{variant:`ghost`,onClick:i,title:`Remove this trigger`,children:j(V,{className:`h-4 w-4`})})]}),w(`div`,{className:`mt-2 flex flex-wrap items-end gap-2`,children:[e.kind===`device-state`&&j(Ht,{trigger:e,devices:t,onChange:r}),e.kind===`device-event`&&j(Wt,{trigger:e,devices:t,onChange:r}),e.kind===`schedule`&&w(`label`,{className:`min-w-[14rem] flex-1`,children:[j(H,{children:`Cron expression`}),j(g,{value:e.cron,placeholder:`0 30 23 * * *`,onChange:e=>r({kind:`schedule`,cron:e.target.value})}),w(`span`,{className:`mt-1 block text-xs text-foreground-subtle`,children:[`Six fields, seconds first. `,j(`code`,{children:`0 30 23 * * *`}),` is every night at 23:30.`]})]}),e.kind===`manual`&&w(`p`,{className:`text-xs text-foreground-subtle`,children:[`Runs only when someone presses `,j(`strong`,{children:`Run actions`}),`. The conditions are still evaluated — a manual run is a run, not an override.`]})]})]})}function Vt(e){return Lt.find(t=>t===e)??`manual`}function q(e,t){return{kind:`device-state`,deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath,...t.becomes===void 0?{}:{becomes:t.becomes},...t.edge===void 0?{}:{edge:t.edge},...t.forMs===void 0?{}:{forMs:t.forMs},...t.debounceMs===void 0?{}:{debounceMs:t.debounceMs}}}function Ht({trigger:e,devices:t,onChange:n}){let r={deviceId:e.deviceId,cap:e.cap,fieldPath:e.fieldPath},i=Oe(r),a={...e.becomes===void 0?{}:{becomes:e.becomes},...e.edge===void 0?{}:{edge:e.edge},...e.forMs===void 0?{}:{forMs:e.forMs},...e.debounceMs===void 0?{}:{debounceMs:e.debounceMs}};return w(O,{children:[j(ke,{value:r,devices:t,onChange:e=>n(q(e,a))}),w(`div`,{className:`min-w-[11rem] flex-1`,children:[j(H,{children:`Becomes`}),w(`div`,{className:`flex items-center gap-2`,children:[w(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[j(p,{checked:e.becomes===void 0,onChange:e=>n(q(r,{...a,...e.target.checked?{becomes:void 0}:{becomes:``}}))}),`any change`]}),e.becomes!==void 0&&j($e,{value:e.becomes,field:i,onChange:e=>n(q(r,{...a,becomes:e}))})]})]}),w(`label`,{className:`flex items-center gap-1.5 text-xs text-foreground-subtle`,children:[j(p,{checked:e.edge===!0,onChange:e=>n(q(r,{...a,...e.target.checked?{edge:!0}:{edge:void 0}}))}),`only on a change`]}),w(`label`,{className:`w-28`,children:[j(H,{children:`Held for (s)`}),j(g,{type:`number`,min:0,value:e.forMs===void 0?``:String(e.forMs/1e3),placeholder:`0`,onChange:e=>n(q(r,{...a,forMs:Ut(e.target.value)}))})]}),w(`label`,{className:`w-28`,children:[j(H,{children:`Debounce (s)`}),j(g,{type:`number`,min:0,value:e.debounceMs===void 0?``:String(e.debounceMs/1e3),placeholder:`0`,onChange:e=>n(q(r,{...a,debounceMs:Ut(e.target.value)}))})]})]})}function Ut(e){if(e.trim()===``)return;let t=Number(e);if(!(Number.isNaN(t)||t<0))return Math.round(t*1e3)}function Wt({trigger:e,devices:t,onChange:n}){return w(O,{children:[w(`label`,{className:`min-w-[15rem] flex-1`,children:[j(H,{children:`Event category`}),j(_,{value:e.category,onChange:t=>n({kind:`device-event`,category:t.target.value,...e.deviceId===void 0?{}:{deviceId:e.deviceId}}),options:[{value:``,label:`Select an event…`},...Rt.map(e=>({value:e,label:e}))]})]}),w(`label`,{className:`min-w-[11rem] flex-1`,children:[j(H,{children:`From device`}),j(_,{value:e.deviceId===void 0?``:String(e.deviceId),onChange:t=>n({kind:`device-event`,category:e.category,...t.target.value===``?{}:{deviceId:Number(t.target.value)}}),options:[{value:``,label:`Any device`},...t.map(e=>({value:String(e.id),label:e.name}))]})]})]})}C();var Gt=`hub`;function Kt({existing:e,initialRecipe:t,saving:n,saveError:r,ejecting:i,onSave:a,onEject:o,onCancel:s}){let[c,l]=k(e?.name??``),[u,d]=k(()=>_t(t)),[p,_]=k(!1),y=Se().data??[],b=L(u),x=E(()=>Jt(u),[u]),S=E(()=>Yt(c.trim()===``?`Untitled automation`:c.trim(),u),[c,u]),C=c.trim()===``,T=C||b!==null||x!==null||S.code===null;return j(h,{children:w(`div`,{className:`space-y-4 p-4`,children:[w(`div`,{className:`flex flex-wrap items-center gap-2`,children:[j(`h3`,{className:`font-medium`,children:e===null?`New automation`:`Edit ${e.name}`}),j(m,{variant:`info`,children:`runs on the hub`})]}),w(`label`,{className:`block max-w-md text-sm`,children:[j(`span`,{className:`text-foreground-subtle`,children:`Name`}),j(g,{className:`mt-1`,value:c,onChange:e=>l(e.target.value),placeholder:`What this automation does`})]}),j(qt,{step:`1`,title:`When`,subtitle:`Any one of these starts a run.`,children:j(zt,{triggers:u.triggers,devices:y,onChange:e=>d(We(u,e))})}),j(qt,{step:`2`,title:`And only if`,subtitle:`Checked after a trigger fires. Nothing runs unless this is true.`,children:j(Mt,{recipe:u,devices:y,onChange:d})}),j(qt,{step:`3`,title:`Then`,subtitle:`In this order, stopping at the first failure.`,children:j(Ye,{actions:u.actions,devices:y,onChange:e=>d(Ge(u,e))})}),j(It,{code:S.code,error:S.error,canEject:e!==null,ejecting:i,onEject:o}),p&&e!==null&&w(`div`,{className:`rounded border border-border`,children:[w(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,j(`code`,{children:P(e.id)})]}),j(v,{addonId:P(e.id),maxHeight:`max-h-64`,showFilters:!1})]}),b!==null&&j(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:b}),b===null&&x!==null&&j(`p`,{className:`rounded border border-warning/40 bg-warning/10 p-3 text-xs text-warning`,children:x}),r!==null&&j(`p`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:r}),w(`div`,{className:`flex flex-wrap items-center gap-2`,children:[w(f,{onClick:()=>{S.code!==null&&a({name:c.trim(),code:S.code,enabled:e?.enabled??!0,placement:Gt})},disabled:n||T,children:[n&&j(ue,{className:`h-4 w-4 animate-spin`}),` Save`]}),w(f,{variant:`ghost`,onClick:()=>_(!p),disabled:e===null,title:e===null?`Logs appear once the automation has been saved and started`:`Show this automation's process logs`,children:[j(pe,{className:`h-4 w-4`}),` Logs`]}),j(f,{variant:`ghost`,onClick:s,disabled:n,children:`Close`}),C&&j(m,{variant:`warning`,children:`Name required`})]})]})})}function qt({step:e,title:t,subtitle:n,children:r}){return w(`section`,{className:`border-l-2 border-border pl-4`,children:[w(`div`,{className:`mb-2 flex flex-wrap items-baseline gap-2`,children:[j(`span`,{className:`text-xs font-mono text-foreground-subtle`,children:e}),j(`h4`,{className:`text-sm font-medium uppercase tracking-wide`,children:t}),j(`span`,{className:`text-xs text-foreground-subtle`,children:n})]}),r]})}function Jt(e){let t=F.safeParse(e);if(t.success)return null;let n=t.error.issues[0];return n===void 0?`this automation is not complete yet`:`${n.path.length===0?``:`${n.path.join(`.`)}: `}${n.message}`}function Yt(e,t){try{return{code:N({name:e,recipe:t}),error:null}}catch(e){return{code:null,error:e instanceof Error?e.message:String(e)}}}function J(e){if(!e.enabled)return{tone:`idle`,label:`Disabled`,detail:`Not started — the block is turned off.`};switch(e.status){case`running`:return{tone:`ok`,label:`Running`,detail:`One process, supervised.`};case`starting`:return{tone:`pending`,label:`Starting`,detail:e.lastError??`Waiting for the process to report ready.`};case`failed`:return{tone:`error`,label:`Failed`,detail:e.lastError??`Failed with no reason recorded — check the node logs.`};default:return{tone:`error`,label:`Not running`,detail:e.lastError??`Enabled but no process is running. The supervisor reconciles every 15s; if this persists, the node may not be running a block supervisor.`}}}function Xt(e){switch(e){case`ok`:return`success`;case`pending`:return`warning`;case`error`:return`danger`;default:return`default`}}function Zt(e,t){let n=e.find(e=>e.id===t.id);return n===void 0?t:n.updatedAt>=t.updatedAt?n:t}function Qt(e){let t=e=>{let t=J(e).tone;return t===`error`?0:t===`pending`?1:t===`ok`?2:3};return[...e].sort((e,n)=>t(e)-t(n)||e.name.localeCompare(n.name))}function $t(e){if(e.length===0)return`No blocks yet.`;let t=e.filter(e=>J(e).tone===`error`).length,n=e.filter(e=>J(e).tone===`ok`).length,r=[`${String(e.length)} block${e.length===1?``:`s`}`];return n>0&&r.push(`${String(n)} running`),t>0&&r.push(`${String(t)} NOT running`),r.join(` · `)}function en({block:n,busy:r,confirming:i,logsOpen:a,unreadable:s,onEdit:c,onToggle:l,onToggleLogs:u,onAskDelete:p,onCancelDelete:h,onConfirmDelete:g}){let _=J(n),y=t(n.updatedAt);return w(`li`,{className:`flex flex-col gap-2 p-3`,children:[w(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[w(`div`,{className:`min-w-0 flex-1`,children:[w(`div`,{className:`flex flex-wrap items-center gap-2`,children:[j(`span`,{className:`truncate font-medium`,children:n.name}),j(m,{variant:Xt(_.tone),children:_.label}),y!==null&&w(`span`,{className:`text-xs text-foreground-subtle`,children:[`edited `,y]})]}),j(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:_.detail}),s!==null&&w(`p`,{className:`mt-0.5 text-xs text-warning`,children:[`Its recipe cannot be read (`,s,`), so it cannot be opened visually. The code is intact and still running — edit it as a script.`]})]}),i?w(`div`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`text-xs text-foreground-subtle`,children:`Delete this automation?`}),j(f,{variant:`danger`,onClick:g,disabled:r,children:`Delete`}),j(f,{variant:`ghost`,onClick:h,children:`Cancel`})]}):w(`div`,{className:`flex items-center gap-2`,children:[j(f,{variant:`ghost`,onClick:c,disabled:s!==null,title:s===null?`Edit`:`This block cannot be opened visually`,children:j(re,{className:`h-4 w-4`})}),w(d,{children:[j(e,{children:j(f,{variant:`ghost`,disabled:!0,title:`Run actions`,children:j(ie,{className:`h-4 w-4`})})}),j(o,{children:`Running an automation by hand needs the automation-control authority, which is not wired up yet. There is deliberately no second way to execute one.`})]}),j(f,{variant:`ghost`,onClick:u,title:`Logs`,children:j(pe,{className:`h-4 w-4`})}),j(f,{variant:`ghost`,onClick:()=>l(!n.enabled),disabled:r,title:n.enabled?`Disable`:`Enable`,children:n.enabled?`Disable`:`Enable`}),j(f,{variant:`ghost`,onClick:p,title:`Delete`,children:j(V,{className:`h-4 w-4`})})]})]}),a&&w(`div`,{className:`rounded border border-border`,children:[w(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,j(`code`,{children:P(n.id)})]}),j(v,{addonId:P(n.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}function tn({onCreate:e}){return j(h,{children:w(`div`,{className:`space-y-2 p-4`,children:[j(`p`,{className:`text-sm text-foreground`,children:`No automations yet.`}),j(`p`,{className:`max-w-2xl text-xs text-foreground-subtle`,children:`An automation is a trigger, a set of conditions and a list of actions. It compiles to an ordinary block and runs in its own supervised process — there is no separate engine, so anything that goes wrong shows up here with a reason.`}),j(f,{onClick:e,children:`New automation`})]})})}var nn=`const AUTOMATION_RECIPE =`,rn=`// EJECTED from the visual automation editor — this file is now hand-owned.
3
- // The recipe that produced it was removed with it, on purpose: while it was
4
- // here the editor could re-open this block and overwrite everything below.`;function an(e){return e.includes(nn)}function on(e){let t=e.indexOf(nn);if(t<0)return null;let n=e.indexOf(`{`,t+25);if(n<0)return null;let r=0,i=!1,a=!1;for(let o=n;o<e.length;o+=1){let s=e.charAt(o);if(i){a?a=!1:s===`\\`?a=!0:s===`"`&&(i=!1);continue}if(s===`"`){i=!0;continue}if(s===`{`)r+=1;else if(s===`}`&&(--r,r===0))return{declStart:t,literalEnd:o+1,json:e.slice(n,o+1)}}return null}function sn(e){let t=on(e);if(t===null)return{ok:!1,reason:`this block carries no AUTOMATION_RECIPE literal`};let n;try{n=JSON.parse(t.json)}catch(e){return{ok:!1,reason:`the embedded recipe is not readable JSON: ${e instanceof Error?e.message:String(e)}`}}let r=F.safeParse(n);if(!r.success){let e=r.error.issues[0];return{ok:!1,reason:`the embedded recipe does not match the recipe schema${e===void 0?``:` at ${e.path.join(`.`)}: ${e.message}`}`}}return{ok:!0,recipe:r.data}}function cn(e){let t=on(e);if(t===null)return e;let n=e.slice(t.literalEnd),r=/^\s*as\s+const/.exec(n),i=t.literalEnd+(r===null?0:r[0].length);return`${e.slice(0,t.declStart)}${rn}${e.slice(i)}`}C();var ln=[`coreBlocks`,`list`],un=5e3;function Y(e){return e instanceof Error?e.message:String(e)}function dn({onOpenScripts:e}){let t=z(),[n,r]=k({mode:`closed`}),[i,a]=k(null),[o,s]=k(null),l=D({queryKey:ln,refetchInterval:un,queryFn:async()=>(await t.trpcClient.coreBlocks.list.query({})).blocks}),u=()=>{l.refetch()},d=A({mutationFn:e=>t.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{r({mode:`edit`,block:e.block}),u()}}),p=A({mutationFn:e=>t.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{r({mode:`edit`,block:e.block}),u()}}),m=A({mutationFn:e=>t.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{a(null),u()}}),g=A({mutationFn:e=>t.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:u}),_=A({mutationFn:e=>t.trpcClient.coreBlocks.update.mutate({blockId:e.id,block:{name:e.name,code:cn(e.code),enabled:e.enabled,placement:e.placement,...e.integrationId===void 0?{}:{integrationId:e.integrationId}}}),onSuccess:t=>{r({mode:`closed`}),u(),e(t.block.id)}}),v=l.data,y=Qt((v??[]).filter(e=>an(e.code))),b=v!==void 0&&y.length===0,x=n.mode===`edit`&&n.block!==null?Zt(y,n.block):null,S=x===null?null:sn(x.code),C=d.error===null?p.error===null?_.error===null?null:Y(_.error):Y(p.error):Y(d.error);return w(`div`,{className:`space-y-3`,children:[w(`div`,{className:`flex items-center justify-between gap-3`,children:[j(`p`,{className:`text-xs text-foreground-subtle`,children:v===void 0?``:$t(y)}),w(f,{onClick:()=>r({mode:`edit`,block:null}),children:[j(B,{className:`h-4 w-4`}),` New automation`]})]}),l.error!=null&&j(c,{title:`Could not read the automations`,message:Y(l.error),onRetry:u}),n.mode===`edit`&&j(Kt,{existing:x,initialRecipe:S!==null&&S.ok?S.recipe:Ie,saving:d.isPending||p.isPending,saveError:C,ejecting:_.isPending,onSave:e=>{x===null?d.mutate(e):p.mutate({blockId:x.id,block:e})},onEject:()=>{x!==null&&_.mutate(x)},onCancel:()=>{d.reset(),p.reset(),_.reset(),r({mode:`closed`})}},x?.id??`new`),b&&j(tn,{onCreate:()=>r({mode:`edit`,block:null})}),y.length>0&&j(h,{children:j(`ul`,{className:`divide-y divide-border`,children:y.map(e=>{let t=sn(e.code);return j(en,{block:e,busy:g.isPending||m.isPending,confirming:i===e.id,logsOpen:o===e.id,unreadable:t.ok?null:t.reason,onEdit:()=>r({mode:`edit`,block:e}),onToggle:t=>g.mutate({blockId:e.id,enabled:t}),onToggleLogs:()=>s(o===e.id?null:e.id),onAskDelete:()=>a(e.id),onCancelDelete:()=>a(null),onConfirmDelete:()=>m.mutate(e.id)},e.id)})})}),m.error!=null&&j(c,{message:Y(m.error)}),g.error!=null&&j(c,{message:Y(g.error)})]})}function fn({onOpenScripts:e}){return j(h,{children:w(`div`,{className:`max-w-2xl space-y-3 p-6`,children:[w(`div`,{className:`flex items-center gap-2`,children:[j(ne,{className:`h-5 w-5 text-foreground-subtle`}),j(`h3`,{className:`font-medium`,children:`Composed devices are not built yet`})]}),w(`p`,{className:`text-sm text-foreground-subtle`,children:[`A composed device will be a real device — its own row, its own name, its own on/off — with its state `,j(`strong`,{children:`derived from other devices`}),` and, optionally, methods that forward to them. Because it is a device row and not an overlay, it reaches HomeKit, Alexa, Home Assistant and the notification rules with nothing having to learn about it.`]}),w(`p`,{className:`text-sm text-foreground-subtle`,children:[`Nothing is hidden behind this section: no device can be declared this way yet, so there is no list to show and no form that would work. A `,j(`strong`,{children:`script`}),` is the surface that exists today — it runs in its own supervised process with the full addon context, which is the same context a composed device will be built on.`]}),j(f,{variant:`outline`,onClick:e,children:`Write a script instead`})]})})}function pn(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function mn(e){if(Array.isArray(e))return e}function hn(e,t,n){return(t=wn(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function gn(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t!==0)for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function _n(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
5
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function vn(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function yn(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?vn(Object(n),!0).forEach(function(t){hn(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):vn(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function bn(e,t){if(e==null)return{};var n,r,i=xn(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function xn(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function Sn(e,t){return mn(e)||gn(e,t)||Tn(e,t)||_n()}function Cn(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function wn(e){var t=Cn(e,`string`);return typeof t==`symbol`?t:t+``}function Tn(e,t){if(e){if(typeof e==`string`)return pn(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?pn(e,t):void 0}}function En(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Dn(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function On(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Dn(Object(n),!0).forEach(function(t){En(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Dn(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function kn(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}}function An(e){return function t(){var n=this,r=[...arguments];return r.length>=e.length?e.apply(this,r):function(){var e=[...arguments];return t.apply(n,[].concat(r,e))}}}function jn(e){return{}.toString.call(e).includes(`Object`)}function Mn(e){return!Object.keys(e).length}function Nn(e){return typeof e==`function`}function Pn(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Fn(e,t){return jn(t)||X(`changeType`),Object.keys(t).some(function(t){return!Pn(e,t)})&&X(`changeField`),t}function In(e){Nn(e)||X(`selectorType`)}function Ln(e){Nn(e)||jn(e)||X(`handlerType`),jn(e)&&Object.values(e).some(function(e){return!Nn(e)})&&X(`handlersType`)}function Rn(e){e||X(`initialIsRequired`),jn(e)||X(`initialType`),Mn(e)&&X(`initialContent`)}function zn(e,t){throw Error(e[t]||e.default)}var X=An(zn)({initialIsRequired:`initial state is required`,initialType:`initial state should be an object`,initialContent:`initial state shouldn't be an empty object`,handlerType:`handler should be an object or a function`,handlersType:`all handlers should be a functions`,selectorType:`selector should be a function`,changeType:`provided value of changes should be an object`,changeField:`it seams you want to change a field in the state which is not specified in the "initial" state`,default:"an unknown error accured in `state-local` package"}),Bn={changes:Fn,selector:In,handler:Ln,initial:Rn};function Vn(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};Bn.initial(e),Bn.handler(t);var n={current:e},r=An(Wn)(n,t),i=An(Un)(n),a=An(Bn.changes)(e),o=An(Hn)(n);function s(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:function(e){return e};return Bn.selector(e),e(n.current)}function c(e){kn(r,i,a,o)(e)}return[s,c]}function Hn(e,t){return Nn(t)?t(e.current):t}function Un(e,t){return e.current=On(On({},e.current),t),t}function Wn(e,t,n){return Nn(t)?t(e.current):Object.keys(n).forEach(function(n){return t[n]?.call(t,e.current[n])}),n}var Gn={create:Vn},Kn={paths:{vs:`https://cdn.jsdelivr.net/npm/monaco-editor@0.55.1/min/vs`}};function qn(e){return function t(){var n=this,r=[...arguments];return r.length>=e.length?e.apply(this,r):function(){var e=[...arguments];return t.apply(n,[].concat(r,e))}}}function Jn(e){return{}.toString.call(e).includes(`Object`)}function Yn(e){return e||$n(`configIsRequired`),Jn(e)||$n(`configType`),e.urls?(Xn(),{paths:{vs:e.urls.monacoBase}}):e}function Xn(){console.warn(Qn.deprecation)}function Zn(e,t){throw Error(e[t]||e.default)}var Qn={configIsRequired:`the configuration object is required`,configType:`the configuration object should be an object`,default:"an unknown error accured in `@monaco-editor/loader` package",deprecation:`Deprecation warning!
6
- You are using deprecated way of configuration.
7
-
8
- Instead of using
9
- monaco.config({ urls: { monacoBase: '...' } })
10
- use
11
- monaco.config({ paths: { vs: '...' } })
12
-
13
- For more please check the link https://github.com/suren-atoyan/monaco-loader#config
14
- `},$n=qn(Zn)(Qn),er={config:Yn},tr=function(){var e=[...arguments];return function(t){return e.reduceRight(function(e,t){return t(e)},t)}};function nr(e,t){return Object.keys(t).forEach(function(n){t[n]instanceof Object&&e[n]&&Object.assign(t[n],nr(e[n],t[n]))}),yn(yn({},e),t)}var rr={type:`cancelation`,msg:`operation is manually canceled`};function ir(e){var t=!1,n=new Promise(function(n,r){e.then(function(e){return t?r(rr):n(e)}),e.catch(r)});return n.cancel=function(){return t=!0},n}var ar=[`monaco`],or=Sn(Gn.create({config:Kn,isInitialized:!1,resolve:null,reject:null,monaco:null}),2),sr=or[0],cr=or[1];function lr(e){var t=er.config(e),n=t.monaco,r=bn(t,ar);cr(function(e){return{config:nr(e.config,r),monaco:n}})}function ur(){var e=sr(function(e){return{monaco:e.monaco,isInitialized:e.isInitialized,resolve:e.resolve}});if(!e.isInitialized){if(cr({isInitialized:!0}),e.monaco)return e.resolve(e.monaco),ir(_r);if(window.monaco&&window.monaco.editor)return hr(window.monaco),e.resolve(window.monaco),ir(_r);tr(dr,pr)(mr)}return ir(_r)}function dr(e){return document.body.appendChild(e)}function fr(e){var t=document.createElement(`script`);return e&&(t.src=e),t}function pr(e){var t=sr(function(e){return{config:e.config,reject:e.reject}}),n=fr(`${t.config.paths.vs}/loader.js`);return n.onload=function(){return e()},n.onerror=t.reject,n}function mr(){var e=sr(function(e){return{config:e.config,resolve:e.resolve,reject:e.reject}}),t=window.require;t.config(e.config),t([`vs/editor/editor.main`],function(t){var n=t.m||t;hr(n),e.resolve(n)},function(t){e.reject(t)})}function hr(e){sr().monaco||cr({monaco:e})}function gr(){return sr(function(e){return e.monaco})}var _r=new Promise(function(e,t){return cr({resolve:e,reject:t})}),vr={config:lr,init:ur,__getMonacoInstance:gr};C();var yr={wrapper:{display:`flex`,position:`relative`,textAlign:`initial`},fullWidth:{width:`100%`},hide:{display:`none`}},br={container:{display:`flex`,height:`100%`,width:`100%`,justifyContent:`center`,alignItems:`center`}};function xr({children:e}){return T.createElement(`div`,{style:br.container},e)}var Sr=xr;function Cr({width:e,height:t,isEditorReady:n,loading:r,_ref:i,className:a,wrapperProps:o}){return T.createElement(`section`,{style:{...yr.wrapper,width:e,height:t},...o},!n&&T.createElement(Sr,null,r),T.createElement(`div`,{ref:i,style:{...yr.fullWidth,...!n&&yr.hide},className:a}))}var wr=S(Cr);function Tr(e){M(e,[])}var Er=Tr;function Dr(e,t,n=!0){let r=x(!0);M(r.current||!n?()=>{r.current=!1}:e,t)}var Z=Dr;function Or(){}function Q(e,t,n,r){return kr(e,r)||Ar(e,t,n,r)}function kr(e,t){return e.editor.getModel(jr(e,t))}function Ar(e,t,n,r){return e.editor.createModel(t,n,r?jr(e,r):void 0)}function jr(e,t){return e.Uri.parse(t)}function Mr({original:e,modified:t,language:n,originalLanguage:r,modifiedLanguage:i,originalModelPath:a,modifiedModelPath:o,keepCurrentOriginalModel:s=!1,keepCurrentModifiedModel:c=!1,theme:l=`light`,loading:u=`Loading...`,options:d={},height:f=`100%`,width:p=`100%`,className:m,wrapperProps:h={},beforeMount:g=Or,onMount:_=Or}){let[v,y]=k(!1),[S,C]=k(!0),w=x(null),E=x(null),D=x(null),O=x(_),A=x(g),j=x(!1);Er(()=>{let e=vr.init();return e.then(e=>(E.current=e)&&C(!1)).catch(e=>e?.type!==`cancelation`&&console.error(`Monaco initialization: error:`,e)),()=>w.current?F():e.cancel()}),Z(()=>{if(w.current&&E.current){let t=w.current.getOriginalEditor(),i=Q(E.current,e||``,r||n||`text`,a||``);i!==t.getModel()&&t.setModel(i)}},[a],v),Z(()=>{if(w.current&&E.current){let e=w.current.getModifiedEditor(),r=Q(E.current,t||``,i||n||`text`,o||``);r!==e.getModel()&&e.setModel(r)}},[o],v),Z(()=>{let e=w.current.getModifiedEditor();e.getOption(E.current.editor.EditorOption.readOnly)?e.setValue(t||``):t!==e.getValue()&&(e.executeEdits(``,[{range:e.getModel().getFullModelRange(),text:t||``,forceMoveMarkers:!0}]),e.pushUndoStop())},[t],v),Z(()=>{w.current?.getModel()?.original.setValue(e||``)},[e],v),Z(()=>{let{original:e,modified:t}=w.current.getModel();E.current.editor.setModelLanguage(e,r||n||`text`),E.current.editor.setModelLanguage(t,i||n||`text`)},[n,r,i],v),Z(()=>{E.current?.editor.setTheme(l)},[l],v),Z(()=>{w.current?.updateOptions(d)},[d],v);let N=b(()=>{if(!E.current)return;A.current(E.current);let s=Q(E.current,e||``,r||n||`text`,a||``),c=Q(E.current,t||``,i||n||`text`,o||``);w.current?.setModel({original:s,modified:c})},[n,t,i,e,r,a,o]),P=b(()=>{!j.current&&D.current&&(w.current=E.current.editor.createDiffEditor(D.current,{automaticLayout:!0,...d}),N(),E.current?.editor.setTheme(l),y(!0),j.current=!0)},[d,l,N]);M(()=>{v&&O.current(w.current,E.current)},[v]),M(()=>{!S&&!v&&P()},[S,v,P]);function F(){let e=w.current?.getModel();s||e?.original?.dispose(),c||e?.modified?.dispose(),w.current?.dispose()}return T.createElement(wr,{width:p,height:f,isEditorReady:v,loading:u,_ref:D,className:m,wrapperProps:h})}S(Mr);function Nr(e){let t=x();return M(()=>{t.current=e},[e]),t.current}var Pr=Nr,Fr=new Map;function Ir({defaultValue:e,defaultLanguage:t,defaultPath:n,value:r,language:i,path:a,theme:o=`light`,line:s,loading:c=`Loading...`,options:l={},overrideServices:u={},saveViewState:d=!0,keepCurrentModel:f=!1,width:p=`100%`,height:m=`100%`,className:h,wrapperProps:g={},beforeMount:_=Or,onMount:v=Or,onChange:y,onValidate:S=Or}){let[C,w]=k(!1),[E,D]=k(!0),O=x(null),A=x(null),j=x(null),N=x(v),P=x(_),F=x(),I=x(r),ee=Pr(a),L=x(!1),R=x(!1);Er(()=>{let e=vr.init();return e.then(e=>(O.current=e)&&D(!1)).catch(e=>e?.type!==`cancelation`&&console.error(`Monaco initialization: error:`,e)),()=>A.current?z():e.cancel()}),Z(()=>{let o=Q(O.current,e||r||``,t||i||``,a||n||``);o!==A.current?.getModel()&&(d&&Fr.set(ee,A.current?.saveViewState()),A.current?.setModel(o),d&&A.current?.restoreViewState(Fr.get(a)))},[a],C),Z(()=>{A.current?.updateOptions(l)},[l],C),Z(()=>{!A.current||r===void 0||(A.current.getOption(O.current.editor.EditorOption.readOnly)?A.current.setValue(r):r!==A.current.getValue()&&(R.current=!0,A.current.executeEdits(``,[{range:A.current.getModel().getFullModelRange(),text:r,forceMoveMarkers:!0}]),A.current.pushUndoStop(),R.current=!1))},[r],C),Z(()=>{let e=A.current?.getModel();e&&i&&O.current?.editor.setModelLanguage(e,i)},[i],C),Z(()=>{s!==void 0&&A.current?.revealLine(s)},[s],C),Z(()=>{O.current?.editor.setTheme(o)},[o],C);let te=b(()=>{if(!(!j.current||!O.current)&&!L.current){P.current(O.current);let c=a||n,f=Q(O.current,r||e||``,t||i||``,c||``);A.current=O.current?.editor.create(j.current,{model:f,automaticLayout:!0,...l},u),d&&A.current.restoreViewState(Fr.get(c)),O.current.editor.setTheme(o),s!==void 0&&A.current.revealLine(s),w(!0),L.current=!0}},[e,t,n,r,i,a,l,u,d,o,s]);M(()=>{C&&N.current(A.current,O.current)},[C]),M(()=>{!E&&!C&&te()},[E,C,te]),I.current=r,M(()=>{C&&y&&(F.current?.dispose(),F.current=A.current?.onDidChangeModelContent(e=>{R.current||y(A.current.getValue(),e)}))},[C,y]),M(()=>{if(C){let e=O.current.editor.onDidChangeMarkers(e=>{let t=A.current.getModel()?.uri;if(t&&e.find(e=>e.path===t.path)){let e=O.current.editor.getModelMarkers({resource:t});S?.(e)}});return()=>{e?.dispose()}}return()=>{}},[C,S]);function z(){F.current?.dispose(),f?d&&Fr.set(a,A.current.saveViewState()):A.current.getModel()?.dispose(),A.current.dispose()}return T.createElement(wr,{width:p,height:m,isEditorReady:C,loading:c,_ref:j,className:h,wrapperProps:g})}var Lr=S(Ir);C();var Rr={target:99,module:99,moduleResolution:2,strict:!0,noImplicitAny:!0,strictNullChecks:!0,allowNonTsExtensions:!0,isolatedModules:!0};function zr(e,t){let n=e.languages.typescript.typescriptDefaults;n.setCompilerOptions({...n.getCompilerOptions(),...Rr}),n.setExtraLibs(t.map(e=>({filePath:e.filePath,content:e.content})))}function Br({value:e,onChange:t,extraLibs:n=[],onDiagnostics:r,readOnly:i=!1,heightPx:a=420,dark:o=!0}){let s=x(null),c=b((e,t)=>{if(s.current=t,zr(t,n),r===void 0)return;let i=e.getModel();if(i===null)return;let a=()=>{r(t.editor.getModelMarkers({resource:i.uri}).map(e=>({line:e.startLineNumber,column:e.startColumn,message:e.message,severity:e.severity})))};t.editor.onDidChangeMarkers(a),a()},[n,r]);return j(Lr,{height:a,defaultLanguage:`typescript`,path:`file:///block.ts`,theme:o?`vs-dark`:`vs`,value:e,onChange:e=>t(e??``),onMount:c,options:{readOnly:i,minimap:{enabled:!1},fontSize:12,lineNumbers:`on`,scrollBeyondLastLine:!1,automaticLayout:!0,tabSize:2,renderWhitespace:`selection`}})}function Vr(e){return e.some(e=>e.severity>=8)}var Hr=`import type { AddonContext } from '@camstack/types'
15
-
16
- /**
17
- * A core block. Runs in its own process, with the same \`ctx\` an addon gets.
18
- * Return a function to release whatever you took (timers, sockets, listeners) —
19
- * it is awaited on shutdown.
20
- */
21
- export default function block(ctx: AddonContext) {
22
- ctx.logger.info('hello from a core block')
23
-
24
- const timer = setInterval(() => {
25
- ctx.logger.info('tick')
26
- }, 60_000)
27
-
28
- return () => {
29
- clearInterval(timer)
30
- }
31
- }
32
- `;function Ur({existing:e,dirty:t,saving:n,restarting:r}){return e===null?`Save the script first — there is no process to restart yet.`:n?`Saving…`:r?`Restarting…`:t?`Save first — a restart now would run the last SAVED code, not what is on screen.`:e.enabled?null:`This script is disabled. Enable it instead of restarting it.`}C();var Wr=`hub`;function Gr({existing:e,typeDefs:t,typeDefsLoading:r,saving:i,saveError:o,restarting:s,restartError:c,onRestart:l,onSave:u,onCancel:d}){let p=z(),{resolvedMode:_}=a(),[y,b]=k(e?.name??``),[x,S]=k(e?.code??Hr),[C,T]=k(e?.placement??Wr),[D,M]=k(e?.integrationId??``),[N,F]=k([]),[I,ee]=k(!1),L=A({mutationFn:e=>p.trpcClient.coreBlocks.compile.mutate({code:e})}),R=E(()=>N.filter(e=>e.severity>=8),[N]),te=Vr(N),ne=y.trim()===``,re=e===null||x!==e.code||y.trim()!==e.name||C!==e.placement||(D.trim()===``?void 0:D.trim())!==e.integrationId,ie=()=>{L.reset(),u({name:y.trim(),code:x,enabled:e?.enabled??!0,placement:C,...D.trim()===``?{}:{integrationId:D.trim()}})},B=e===null?null:J(e),oe=Ur({existing:e,dirty:re,saving:i,restarting:s});return j(h,{children:w(`div`,{className:`space-y-4 p-4`,children:[w(`div`,{className:`flex flex-wrap items-center gap-2`,children:[j(`h3`,{className:`font-medium`,children:e===null?`New script`:`Edit ${e.name}`}),B!==null&&j(m,{variant:Xt(B.tone),children:B.label})]}),w(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[w(`label`,{className:`block text-sm`,children:[j(`span`,{className:`text-foreground-subtle`,children:`Name`}),j(g,{className:`mt-1`,value:y,onChange:e=>b(e.target.value),placeholder:`What this script does`})]}),w(`label`,{className:`block text-sm`,children:[j(`span`,{className:`text-foreground-subtle`,children:`Integration (optional)`}),j(g,{className:`mt-1`,value:D,onChange:e=>M(e.target.value),placeholder:`Leave empty for the shared system integration`})]})]}),w(`div`,{children:[j(n,{selectedNodeId:C,onSelect:T,label:`Runs on`,alwaysShow:!0}),C!==Wr&&w(`p`,{className:`mt-2 flex items-start gap-2 text-xs text-warning`,children:[j(me,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),w(`span`,{children:[`Block execution is hub-only today. Saved with this placement the block will be stored and compiled, but it will report `,j(`strong`,{children:`Failed`}),` instead of running.`]})]})]}),w(`div`,{className:I?`grid gap-3 lg:grid-cols-2`:``,children:[j(`div`,{className:`rounded border border-border`,children:r?j(`p`,{className:`p-4 text-sm text-foreground-subtle`,children:`Loading the node's type definitions…`}):j(Br,{value:x,onChange:S,extraLibs:t?.libs??[],onDiagnostics:F,dark:_===`dark`,heightPx:420})}),I&&w(`div`,{className:`rounded border border-border`,children:[j(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:e===null?`Logs appear once the script has been saved and started.`:w(O,{children:[`Logs — `,j(`code`,{children:P(e.id)})]})}),e!==null&&j(v,{addonId:P(e.id),maxHeight:`max-h-[420px]`,showFilters:!1})]})]}),t!==void 0&&t.libs.length===0&&j(`p`,{className:`text-xs text-warning`,children:`The node returned no type definitions, so this code is NOT being checked against the system's types. The server-side compile still applies on save.`}),R.length>0&&w(`div`,{className:`space-y-1 rounded border border-danger/40 bg-danger/10 p-3 text-xs`,children:[w(`p`,{className:`font-medium text-danger`,children:[R.length,` error`,R.length===1?``:`s`,` — the block cannot be saved.`]}),R.slice(0,5).map(e=>w(`p`,{className:`text-danger`,children:[`line `,e.line,`: `,e.message]},`${String(e.line)}:${String(e.column)}:${e.message}`)),R.length>5&&w(`p`,{className:`text-foreground-subtle`,children:[`…and `,R.length-5,` more.`]})]}),L.data!==void 0&&(L.data.ok?w(`p`,{className:`flex items-center gap-2 text-xs text-success`,children:[j(le,{className:`h-3.5 w-3.5`}),` The node compiled this code. Nothing was saved.`]}):w(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[L.data.line===void 0?``:`line ${String(L.data.line)}: `,L.data.error??`the code does not compile`]})),L.error!==null&&w(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:[`Could not reach the compiler: `,Kr(L.error)]}),o!==null&&j(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:o}),c!==null&&j(`div`,{className:`rounded border border-danger/40 bg-danger/10 p-3 text-xs text-danger`,children:c}),w(`div`,{className:`flex flex-wrap items-center gap-2`,children:[w(f,{variant:`outline`,onClick:()=>L.mutate(x),disabled:L.isPending||i,title:`Type-check on the node without saving`,children:[L.isPending&&j(ue,{className:`h-4 w-4 animate-spin`}),` Compile`]}),w(f,{onClick:ie,disabled:i||te||ne,children:[i&&j(ue,{className:`h-4 w-4 animate-spin`}),` Save`]}),w(f,{variant:`outline`,onClick:()=>l?.(),disabled:oe!==null||l===void 0,title:oe??`Stop the process and let the supervisor bring it back`,children:[s?j(ae,{className:`h-4 w-4 animate-spin`}):j(ae,{className:`h-4 w-4`}),` `,`Restart`]}),w(f,{variant:`ghost`,onClick:()=>ee(!I),title:`Show this script's process logs`,children:[j(pe,{className:`h-4 w-4`}),` Logs `,I?`⇤`:`⇄`]}),j(f,{variant:`ghost`,onClick:d,disabled:i,children:`Close`}),w(`span`,{className:`ml-auto text-xs text-foreground-subtle`,children:[`errors: `,R.length,re&&e!==null?` · unsaved changes`:``]}),ne&&j(m,{variant:`warning`,children:`Name required`})]})]})})}function Kr(e){return e instanceof Error?e.message:String(e)}C();var qr=[`coreBlocks`,`list`],Jr=[`coreBlocks`,`getTypeDefs`],Yr=5e3;function $(e){return e instanceof Error?e.message:String(e)}function Xr({initialBlockId:e}={}){let t=z(),[n,r]=k({mode:`closed`}),[i,a]=k(null),[o,s]=k(null),l=D({queryKey:qr,refetchInterval:Yr,queryFn:async()=>(await t.trpcClient.coreBlocks.list.query({})).blocks}),u=D({queryKey:Jr,enabled:n.mode===`edit`,staleTime:1/0,gcTime:1/0,queryFn:()=>t.trpcClient.coreBlocks.getTypeDefs.query({})}),d=()=>{l.refetch()},p=x(null),m=l.data;M(()=>{if(e===void 0||p.current===e)return;let t=m?.find(t=>t.id===e);t!==void 0&&(p.current=e,r({mode:`edit`,block:t}))},[e,m]);let g=A({mutationFn:e=>t.trpcClient.coreBlocks.create.mutate({block:e}),onSuccess:e=>{r({mode:`edit`,block:e.block}),d()}}),_=A({mutationFn:e=>t.trpcClient.coreBlocks.update.mutate(e),onSuccess:e=>{r({mode:`edit`,block:e.block}),d()}}),v=A({mutationFn:e=>t.trpcClient.coreBlocks.delete.mutate({blockId:e}),onSuccess:()=>{a(null),d()}}),y=A({mutationFn:e=>t.trpcClient.coreBlocks.setEnabled.mutate(e),onSuccess:d}),b=A({mutationFn:e=>t.trpcClient.coreBlocks.restart.mutate({blockId:e}),onSuccess:d}),S=Qt(l.data??[]),C=l.data!==void 0&&S.length===0,T=g.isPending||_.isPending,E=g.error===null?_.error===null?null:$(_.error):$(g.error),O=n.mode===`edit`&&n.block!==null?Zt(S,n.block):null;return w(`div`,{className:`space-y-3`,children:[w(`div`,{className:`flex items-center justify-between gap-3`,children:[j(`p`,{className:`text-xs text-foreground-subtle`,children:l.data===void 0?``:$t(S)}),w(f,{onClick:()=>r({mode:`edit`,block:null}),children:[j(B,{className:`h-4 w-4`}),` New script`]})]}),l.error!=null&&j(c,{title:`Could not read the scripts`,message:$(l.error),onRetry:d}),n.mode===`edit`&&j(Gr,{existing:O,typeDefs:u.data,typeDefsLoading:u.isLoading,saving:T,saveError:E,restarting:b.isPending,restartError:b.error===null?null:$(b.error),onRestart:O===null?void 0:()=>b.mutate(O.id),onSave:e=>{let t=O;t===null?g.mutate(e):_.mutate({blockId:t.id,block:e})},onCancel:()=>{g.reset(),_.reset(),b.reset(),r({mode:`closed`})}}),C&&j(h,{children:w(`div`,{className:`space-y-1 p-4`,children:[j(`p`,{className:`text-sm text-foreground`,children:`No scripts yet.`}),j(`p`,{className:`text-xs text-foreground-subtle`,children:`A script is TypeScript the hub runs in its own process, with the same context an addon gets — devices, storage, the event bus. It is supervised: one that throws or hangs is marked failed and shown here, not left silently absent.`})]})}),S.length>0&&j(h,{children:j(`ul`,{className:`divide-y divide-border`,children:S.map(e=>j(Zr,{block:e,busy:y.isPending||v.isPending,restarting:b.isPending&&b.variables===e.id,confirming:i===e.id,logsOpen:o===e.id,onToggle:t=>y.mutate({blockId:e.id,enabled:t}),onRestart:()=>b.mutate(e.id),onToggleLogs:()=>s(o===e.id?null:e.id),onEdit:()=>r({mode:`edit`,block:e}),onAskDelete:()=>a(e.id),onCancelDelete:()=>a(null),onConfirmDelete:()=>v.mutate(e.id)},e.id))})}),v.error!=null&&j(c,{message:$(v.error)}),y.error!=null&&j(c,{message:$(y.error)}),b.error!=null&&j(c,{message:$(b.error)})]})}function Zr({block:e,busy:n,restarting:r,confirming:i,logsOpen:a,onToggle:o,onRestart:s,onToggleLogs:c,onEdit:l,onAskDelete:u,onCancelDelete:d,onConfirmDelete:p}){let h=J(e),g=t(e.updatedAt);return w(`li`,{className:`flex flex-col gap-2 p-3`,children:[w(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3`,children:[w(`div`,{className:`min-w-0 flex-1`,children:[w(`div`,{className:`flex flex-wrap items-center gap-2`,children:[j(`span`,{className:`truncate font-medium`,children:e.name}),j(m,{variant:Xt(h.tone),children:h.label}),j(m,{variant:`info`,children:e.placement}),g!==null&&w(`span`,{className:`text-xs text-foreground-subtle`,children:[`edited `,g]})]}),j(`p`,{className:`mt-0.5 text-xs text-foreground-subtle`,children:h.detail})]}),i?w(`div`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`text-xs text-foreground-subtle`,children:`Delete this script?`}),j(f,{variant:`danger`,onClick:p,disabled:n,children:`Delete`}),j(f,{variant:`ghost`,onClick:d,children:`Cancel`})]}):w(`div`,{className:`flex items-center gap-2`,children:[j(f,{variant:`ghost`,onClick:l,title:`Edit`,children:j(re,{className:`h-4 w-4`})}),j(f,{variant:`ghost`,onClick:s,disabled:n||r||!e.enabled,title:e.enabled?`Restart`:`Enable it instead — a disabled script has no process`,children:j(ae,{className:`h-4 w-4${r?` animate-spin`:``}`})}),j(f,{variant:`ghost`,onClick:c,title:`Logs`,children:j(pe,{className:`h-4 w-4`})}),j(f,{variant:`ghost`,onClick:()=>o(!e.enabled),disabled:n,title:e.enabled?`Disable`:`Enable`,children:e.enabled?`Disable`:`Enable`}),j(f,{variant:`ghost`,onClick:u,title:`Delete`,children:j(V,{className:`h-4 w-4`})})]})]}),a&&w(`div`,{className:`rounded border border-border`,children:[w(`div`,{className:`border-b border-border px-3 py-1.5 text-xs text-foreground-subtle`,children:[`Logs — `,j(`code`,{children:P(e.id)})]}),j(v,{addonId:P(e.id),maxHeight:`max-h-64`,showFilters:!1})]})]})}var Qr=[`automations`,`scripts`,`custom-device`];function $r(e){return e!==null&&Qr.some(t=>t===e)}function ei(){let[e,t]=de(),n=e.get(`tab`),a=$r(n)?n:`automations`,o=e=>{t(t=>{let n=new URLSearchParams(t);return n.set(`tab`,e),n.delete(`block`),n},{replace:!0})};return j(ge,{icon:he,title:`Build-your-self`,subtitle:`Automations, scripts and composed devices — what this installation does on its own.`,children:w(i,{value:a,onValueChange:o,children:[w(u,{children:[j(r,{value:`automations`,children:`Automations`}),j(r,{value:`scripts`,children:`Scripts`}),j(r,{value:`custom-device`,children:`Custom Device`})]}),j(l,{value:`automations`,children:j(dn,{onOpenScripts:e=>{t(t=>{let n=new URLSearchParams(t);return n.set(`tab`,`scripts`),e===void 0?n.delete(`block`):n.set(`block`,e),n},{replace:!0})}})}),j(l,{value:`scripts`,children:j(Xr,{initialBlockId:e.get(`block`)??void 0})}),j(l,{value:`custom-device`,children:j(fn,{onOpenScripts:()=>o(`scripts`)})})]})})}export{ei as BuildPage};
@@ -1 +0,0 @@
1
- import{To as e}from"./src-BmAmiAXy.js";import{Q as t,S as n,W as r,a as i,q as a,t as o,x as s}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{c}from"./widget-panel-BF8s8cZY.js";import{t as l}from"./circle-check-big-CQsfhCrZ.js";import{P as u,S as d,d as f}from"./index-B6kDpXr5.js";import{t as p}from"./AdminPage-Dq33XE9j.js";t();var m={detection:`border-green-500`,detector:`border-green-500`,streaming:`border-blue-500`,decode:`border-blue-500`,decoder:`border-blue-500`,recording:`border-orange-500`,recorder:`border-orange-500`,transcoding:`border-purple-500`,transcoder:`border-purple-500`,restream:`border-cyan-500`,restreamer:`border-cyan-500`,storage:`border-yellow-500`,notification:`border-pink-500`,notifier:`border-pink-500`,faces:`border-indigo-500`},h={detection:`bg-green-500/5`,detector:`bg-green-500/5`,streaming:`bg-blue-500/5`,decode:`bg-blue-500/5`,decoder:`bg-blue-500/5`,recording:`bg-orange-500/5`,recorder:`bg-orange-500/5`,transcoding:`bg-purple-500/5`,transcoder:`bg-purple-500/5`,restream:`bg-cyan-500/5`,restreamer:`bg-cyan-500/5`,storage:`bg-yellow-500/5`,notification:`bg-pink-500/5`,notifier:`bg-pink-500/5`,faces:`bg-indigo-500/5`};function g({entry:e,actions:t}){let r=e.name.toLowerCase(),i=m[r]??`border-primary`,a=h[r]??`bg-primary/5`,o=e.providers.find(e=>e.active),c=t?.pendingCapability===e.name;return n(`div`,{className:`rounded-lg border-t-2 border border-border ${i} ${a} p-3 space-y-2`,children:[n(`div`,{className:`flex items-center justify-between gap-2`,children:[n(`span`,{className:`text-xs font-semibold text-foreground capitalize flex items-center gap-1.5`,children:[e.name,c&&s(d,{className:`h-3 w-3 animate-spin text-primary`})]}),s(`span`,{className:`rounded-full px-2 py-0.5 text-[10px] font-medium ${e.mode===`singleton`?`bg-primary/10 text-primary`:`bg-info/10 text-info`}`,children:e.mode})]}),e.mode===`singleton`?s(_,{entry:e,actions:t,activeProvider:o,isPending:c}):s(v,{entry:e,actions:t,isPending:c})]})}function _({entry:e,actions:t,activeProvider:r,isPending:i}){if(!t)return s(`div`,{children:r?n(`div`,{className:`flex items-center gap-1.5 text-[10px] text-foreground`,children:[s(l,{className:`h-3 w-3 text-green-400 shrink-0`}),s(`span`,{className:`font-medium`,children:r.addonName}),s(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto`,children:`ACTIVE`})]}):s(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No active provider`})});if(e.providers.length===0)return s(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});let a=`__inherit__`;return n(`div`,{className:`space-y-2`,children:[s(`div`,{className:`space-y-1`,children:e.providers.map(r=>{let a=r.active;return n(`button`,{type:`button`,disabled:i||a,onClick:()=>t.onSelectSingleton(e.name,r.addonId),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${a?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[s(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${a?`border-green-400 bg-green-400`:`border-border`}`}),s(`span`,{className:`font-medium truncate`,children:r.addonName}),a&&s(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},r.addonId)})}),e.perNode&&e.perNode.length>0&&s(`div`,{className:`space-y-2 pt-1 border-t border-border/40`,children:e.perNode.map(r=>{let o=r.hasOverride&&r.resolvedActive?r.resolvedActive:a,c=[{value:a,label:`Inherit global${r.resolvedActive?` (${r.resolvedActive})`:``}`},...r.providers.map(e=>({value:e,label:e}))],l=n=>{n===a?t.onClearNodeSingleton(e.name,r.nodeId):t.onSelectNodeSingleton(e.name,r.nodeId,n)},u=i;return n(`div`,{className:`space-y-0.5`,children:[n(`div`,{className:`text-[9px] font-semibold uppercase tracking-widest text-foreground-subtle/60 px-1.5`,children:[r.nodeId,r.hasOverride&&s(`span`,{className:`ml-1.5 rounded-full bg-primary/10 text-primary px-1 py-0.5 normal-case tracking-normal font-medium`,children:`override`})]}),c.map(e=>{let t=o===e.value;return n(`button`,{type:`button`,disabled:u||t,onClick:()=>l(e.value),className:`flex w-full items-center gap-1.5 rounded px-1.5 py-1 text-[10px] text-left transition-colors ${t?`bg-green-500/10 text-foreground cursor-default`:`text-foreground-subtle hover:bg-surface-hover hover:text-foreground disabled:opacity-50`}`,children:[s(`span`,{className:`h-2.5 w-2.5 rounded-full border shrink-0 ${t?`border-green-400 bg-green-400`:`border-border`}`}),s(`span`,{className:`font-medium truncate`,children:e.label}),t&&e.value!==a&&s(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium ml-auto shrink-0`,children:`ACTIVE`})]},e.value)})]},r.nodeId)})})]})}function v({entry:e,actions:t,isPending:r}){if(e.providers.length===0)return s(`div`,{className:`text-[10px] text-foreground-subtle italic`,children:`No providers`});if(!t)return s(`div`,{className:`space-y-1`,children:e.providers.map(e=>n(`div`,{className:`flex items-center justify-between gap-2 text-[10px]`,children:[s(`span`,{className:`text-foreground-subtle`,children:e.addonName}),e.active&&s(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium`,children:`ACTIVE`})]},e.addonId))});let i=e.providers.filter(e=>e.active).map(e=>e.addonId),a=(n,r)=>{let a=r?[...new Set([...i,n])]:i.filter(e=>e!==n);t.onToggleCollection(e.name,a)};return s(`div`,{className:`space-y-1`,children:e.providers.map(e=>n(`label`,{className:`flex items-center justify-between gap-2 text-[10px] rounded px-1.5 py-1 transition-colors ${r?`opacity-50`:`hover:bg-surface-hover cursor-pointer`}`,children:[n(`span`,{className:`flex items-center gap-1.5 min-w-0`,children:[s(`input`,{type:`checkbox`,checked:e.active,disabled:r,onChange:t=>a(e.addonId,t.target.checked),className:`h-3 w-3 accent-green-500 shrink-0`}),s(`span`,{className:`text-foreground truncate`,children:e.addonName})]}),e.active&&s(`span`,{className:`rounded-full bg-green-500/10 text-green-400 px-1.5 py-0.5 font-medium shrink-0`,children:`ACTIVE`})]},e.addonId))})}function y({capabilities:e,actions:t}){return e.length===0?s(`div`,{className:`text-xs text-foreground-subtle text-center py-8`,children:`No capabilities registered`}):s(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3`,children:e.map(e=>s(g,{entry:e,actions:t},e.name))})}var b=[`capabilities`,`listCapabilities`];function x(e){return e===`singleton`||e===`collection`}function S(e){let t=e.indexOf(`@`);return t===-1?`${e} (hub)`:`${e.slice(0,t)} (${e.slice(t+1)})`}function C(e,t){return{name:e.name,mode:t,providers:e.providers.map(n=>({addonId:n,addonName:S(n),active:t===`singleton`?e.activeProvider===n:!e.disabledProviders.includes(n)})),...t===`singleton`&&e.perNode?{perNode:e.perNode}:{}}}function w(){let t=c(),[d,m]=a(null),[h,g]=a(null),_=i({queryKey:b,queryFn:()=>t.trpcClient.capabilities.listCapabilities.query()}),v=r(()=>{let e=(_.data??[]).flatMap(e=>x(e.mode)?[C(e,e.mode)]:[]),t=e.filter(e=>e.mode===`singleton`).toSorted((e,t)=>e.name.localeCompare(t.name)),n=e.filter(e=>e.mode===`collection`).toSorted((e,t)=>e.name.localeCompare(t.name));return[...t,...n]},[_.data]),S=r(()=>v.filter(e=>e.mode===`singleton`),[v]),w=r(()=>v.filter(e=>e.mode===`collection`),[v]),T=o({mutationFn:e=>t.trpcClient.capabilities.setActiveSingleton.mutate({capability:e.capName,addonId:e.addonId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} → ${t.addonId} is now active.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),E=o({mutationFn:e=>t.trpcClient.capabilities.setActiveSingleton.mutate({capability:e.capName,addonId:e.addonId,nodeId:e.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} → ${t.addonId}.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to set ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),D=o({mutationFn:e=>t.trpcClient.capabilities.clearSingletonNodeOverride.mutate({capability:e.capName,nodeId:e.nodeId}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName} @ ${t.nodeId} now inherits the global default.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to clear ${t.capName} @ ${t.nodeId}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),O=o({mutationFn:e=>t.trpcClient.capabilities.setCollectionEnabledProviders.mutate({capability:e.capName,enabledAddonIds:[...e.enabledAddonIds]}),onMutate:e=>{m(e.capName),g(null)},onSuccess:async(e,t)=>{g({kind:`success`,message:`${t.capName}: ${t.enabledAddonIds.length} provider(s) enabled.`}),await _.refetch()},onError:(e,t)=>{g({kind:`error`,message:`Failed to update ${t.capName}: ${e instanceof Error?e.message:`unknown error`}`})},onSettled:()=>m(null)}),k={onSelectSingleton:(e,t)=>T.mutate({capName:e,addonId:t}),onSelectNodeSingleton:(e,t,n)=>E.mutate({capName:e,nodeId:t,addonId:n}),onClearNodeSingleton:(e,t)=>D.mutate({capName:e,nodeId:t}),onToggleCollection:(e,t)=>O.mutate({capName:e,enabledAddonIds:t}),pendingCapability:d};return n(p,{icon:f,title:`Capabilities`,subtitle:`Choose which provider is active for each system capability. Singleton caps pick exactly one provider; collection caps enable a set.`,children:[h&&n(`div`,{className:`flex items-center gap-2 rounded-md border px-3 py-2 text-xs ${h.kind===`success`?`border-green-500/30 bg-green-500/10 text-green-700 dark:text-green-300`:`border-danger/40 bg-danger/10 text-danger`}`,children:[h.kind===`success`?s(l,{className:`h-3.5 w-3.5 shrink-0`}):s(u,{className:`h-3.5 w-3.5 shrink-0`}),s(`span`,{children:h.message})]}),_.isLoading&&s(`div`,{className:`flex items-center justify-center py-16`,children:s(`div`,{className:`animate-spin h-6 w-6 border-2 border-primary border-t-transparent rounded-full`})}),_.isError&&!_.isLoading&&s(e,{title:`Failed to load capabilities`,message:_.error instanceof Error?_.error.message:`Unknown error`,onRetry:()=>void _.refetch()}),!_.isLoading&&!_.isError&&v.length===0&&s(`div`,{className:`text-xs text-foreground-subtle text-center py-16`,children:`No capabilities registered.`}),!_.isLoading&&!_.isError&&v.length>0&&n(`div`,{className:`space-y-6`,children:[S.length>0&&n(`section`,{className:`space-y-2`,children:[s(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Singleton — pick one provider`}),s(y,{capabilities:S,actions:k})]}),w.length>0&&n(`section`,{className:`space-y-2`,children:[s(`h2`,{className:`text-[11px] font-semibold uppercase tracking-widest text-foreground-subtle/70`,children:`Collection — enable a set`}),s(y,{capabilities:w,actions:k})]})]})]})}export{w as CapabilitiesPage,w as default};
@@ -1 +0,0 @@
1
- import{Aa as e,Gr as t,Ir as n,Jr as r,Kr as i,Lr as a,Oa as o,Pi as s,Ur as c,Wr as l,Yr as u,Zi as d,es as f,g as p,ja as m,jo as h,ka as g,ko as _,ns as v,qr as y,rs as b,ts as x,v as S,wo as C}from"./src-BmAmiAXy.js";import{I as w,K as T,Q as E,S as D,W as O,o as k,q as A,x as j,z as M}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{c as N}from"./widget-panel-BF8s8cZY.js";import{t as P}from"./pencil-OtLKJIw8.js";import{t as F}from"./radio-B8HIjRjm.js";import{t as I}from"./refresh-cw-BwezRSth.js";import{t as L}from"./rotate-cw-B6qXQ5pJ.js";import{t as ee}from"./server-jIBmmmio.js";import{t as R}from"./upload-DUXkaKq1.js";import{F as z,G as B,L as te,M as ne,R as re,S as V,V as ie,i as ae,m as H,o as U,s as W,t as G}from"./index-B6kDpXr5.js";import{n as K,t as q}from"./build-cluster-graph-DMQ4vDW2.js";import{t as J}from"./format-size-CO9d3C3-.js";import{t as oe}from"./NodeAddonsSettingsPanel-DJKQxT7V.js";var Y=B(`arrow-down-to-line`,[[`path`,{d:`M12 17V3`,key:`1cwfxf`}],[`path`,{d:`m6 11 6 6 6-6`,key:`12ii2o`}],[`path`,{d:`M19 21H5`,key:`150jfl`}]]),se=B(`git-fork`,[[`circle`,{cx:`12`,cy:`18`,r:`3`,key:`1mpf1b`}],[`circle`,{cx:`6`,cy:`6`,r:`3`,key:`1lh9wr`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`path`,{d:`M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9`,key:`1uq4wg`}],[`path`,{d:`M12 12v3`,key:`158kv8`}]]),ce=B(`hard-drive-download`,[[`path`,{d:`M12 2v8`,key:`1q4o3n`}],[`path`,{d:`m16 6-4 4-4-4`,key:`6wukr`}],[`rect`,{width:`20`,height:`8`,x:`2`,y:`14`,rx:`2`,key:`w68u3i`}],[`path`,{d:`M6 18h.01`,key:`uhywen`}],[`path`,{d:`M10 18h.01`,key:`h775k`}]]),le=B(`memory-stick`,[[`path`,{d:`M6 19v-3`,key:`1nvgqn`}],[`path`,{d:`M10 19v-3`,key:`iu8nkm`}],[`path`,{d:`M14 19v-3`,key:`kcehxu`}],[`path`,{d:`M18 19v-3`,key:`1vh91z`}],[`path`,{d:`M8 11V9`,key:`63erz4`}],[`path`,{d:`M16 11V9`,key:`fru6f3`}],[`path`,{d:`M12 11V9`,key:`ha00sb`}],[`path`,{d:`M2 15h20`,key:`16ne18`}],[`path`,{d:`M2 7a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v1.1a2 2 0 0 0 0 3.837V17a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-5.1a2 2 0 0 0 0-3.837Z`,key:`lhddv3`}]]),X=B(`skull`,[[`path`,{d:`m12.5 17-.5-1-.5 1h1z`,key:`3me087`}],[`path`,{d:`M15 22a1 1 0 0 0 1-1v-1a2 2 0 0 0 1.56-3.25 8 8 0 1 0-11.12 0A2 2 0 0 0 8 20v1a1 1 0 0 0 1 1z`,key:`1o5pge`}],[`circle`,{cx:`15`,cy:`12`,r:`1`,key:`1tmaij`}],[`circle`,{cx:`9`,cy:`12`,r:`1`,key:`1vctgf`}]]),ue=B(`table-2`,[[`path`,{d:`M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18`,key:`gugj83`}]]);E();function de(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 fe({nodeId:e,addons:n,isHub:r}){let i=k(),a=C(),[o,s]=A(null),[l,d]=A(null),[f,p]=A(!1),[m,h]=A(null),[g,_]=A(0),v=T(null),y=t(),b=u(),x=c({nodeId:e}),S=x.data??[],w=new Map(n.map(e=>[e.id,e.capabilities])),E=S.length>0?S.map(e=>({id:e.id,status:e.status,capabilities:w.get(e.id)??[],version:e.version,packageName:e.packageName})):n.map(e=>({id:e.id,status:e.status,capabilities:e.capabilities,version:void 0,packageName:void 0})),O=()=>{i.invalidateQueries({queryKey:[[`nodes`,`topology`]]}),x.refetch()},M=async t=>{s(t);try{await y.mutateAsync({nodeId:e,addonId:t}),O()}catch(e){console.error(`Failed to restart addon:`,e)}finally{s(null)}},N=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`})){d(t);try{await b.mutateAsync({nodeId:e,addonId:t}),O()}catch(e){console.error(`Failed to uninstall addon:`,e)}finally{d(null)}}},P=D(`div`,{className:`flex items-center gap-2 mb-2`,children:[j(`input`,{ref:v,type:`file`,accept:`.tgz,.tar.gz`,className:`hidden`,onChange:async t=>{let n=t.target.files?.[0];if(n){t.target.value=``,h(null),p(!0),_(0);try{await de({file:n,nodeId:e,token:localStorage.getItem(`camstack_admin_token`),onProgress:_}),O()}catch(e){h(e instanceof Error?e.message:String(e))}finally{p(!1),_(0)}}}}),D(`button`,{onClick:()=>v.current?.click(),disabled:f,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:[f?j(V,{className:`h-3 w-3 animate-spin`}):j(R,{className:`h-3 w-3`}),f?`Uploading… ${g}%`:`Upload addon (.tgz)`]}),f&&j(`div`,{className:`flex-1 h-1 rounded-full bg-muted overflow-hidden max-w-[140px]`,children:j(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${g}%`}})}),m&&j(`span`,{className:`text-[10px] text-destructive`,children:m})]});return E.length===0?D(`div`,{children:[P,j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:x.isLoading?`Loading addons…`:`No addons on this node`})]}):D(`div`,{children:[P,j(`div`,{className:`rounded-lg border border-border max-h-[60vh] overflow-auto`,children:D(`table`,{className:`w-full text-xs`,children:[j(`thead`,{className:`sticky top-0 z-10 bg-surface`,children:D(`tr`,{className:`text-muted-foreground text-left`,children:[j(`th`,{className:`px-3 py-2 font-medium`,children:`Addon`}),j(`th`,{className:`px-3 py-2 font-medium`,children:`Version`}),j(`th`,{className:`px-3 py-2 font-medium`,children:`Capabilities`}),j(`th`,{className:`px-3 py-2 font-medium`,children:`Status`}),j(`th`,{className:`px-3 py-2 font-medium w-16`})]})}),j(`tbody`,{children:E.map(e=>D(`tr`,{className:`border-t border-border/50`,children:[D(`td`,{className:`px-3 py-2 font-medium`,children:[j(`div`,{children:e.id}),e.packageName&&j(`div`,{className:`text-[9px] text-muted-foreground`,children:e.packageName})]}),j(`td`,{className:`px-3 py-2 text-muted-foreground`,children:e.version??`—`}),j(`td`,{className:`px-3 py-2`,children:j(`div`,{className:`flex flex-wrap gap-1`,children:e.capabilities.length>0?e.capabilities.map(e=>j(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-400`,children:e},e)):j(`span`,{className:`text-muted-foreground`,children:`—`})})}),j(`td`,{className:`px-3 py-2`,children:j(`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})}),j(`td`,{className:`px-3 py-2`,children:D(`div`,{className:`flex items-center gap-1 justify-end`,children:[j(`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:j(L,{className:`h-3 w-3 ${o===e.id?`animate-spin`:``}`})}),j(`button`,{onClick:()=>N(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?j(V,{className:`h-3 w-3 animate-spin`}):j(W,{className:`h-3 w-3`})})]})})]},e.id))})]})})]})}E();function pe(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 me({state:e}){return j(`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 he=[`trace`,`debug`,`info`,`warn`,`error`];function ge({proc:e,nodeId:n,defaultExpanded:r,activePanel:a,onTogglePanel:o}){let s=e.services??[],c=s.length===1,[l,u]=A(c||r),[d,m]=A(null),[h,g]=A(`info`),_=e.name.includes(`(core)`),C=t(),w=i(),T=y(),E=async e=>{m(e);try{await C.mutateAsync({nodeId:n,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{m(null)}},O=async()=>{m(e.name);try{await w.mutateAsync({nodeId:n,processName:e.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{m(null)}},k=async t=>{let r=`${n}/${e.name}`;try{await T.mutateAsync({nodeId:r,level:t}),g(t)}catch(e){console.error(`Failed to set log level:`,e)}};return D(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[D(`div`,{role:c?void 0:`button`,tabIndex:c?void 0:0,onClick:c?void 0:()=>u(!l),onKeyDown:c?void 0:e=>{(e.key===`Enter`||e.key===` `)&&u(!l)},className:`flex items-center gap-2 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${c?``:`hover:bg-muted/40 cursor-pointer`}`,children:[c?j(`span`,{className:`h-3 w-3 shrink-0`}):j(l?te:z,{className:`h-3 w-3 text-muted-foreground shrink-0`}),_?j(ee,{className:`h-3.5 w-3.5 text-primary shrink-0`}):j(ie,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),j(`span`,{className:`text-xs font-semibold flex-1`,children:e.name}),D(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[`PID `,e.pid]}),j(me,{state:e.state}),D(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[e.cpuPercent,`% CPU`]}),j(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:J(e.memoryRss)}),j(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:pe(e.uptimeSeconds)}),!_&&D(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[D(f,{children:[j(b,{className:`text-[9px] px-1.5 py-0.5 rounded border border-border text-muted-foreground hover:text-foreground hover:bg-muted transition-colors font-mono`,title:`Set log level`,children:h}),j(x,{align:`end`,className:`min-w-[70px] py-0.5`,children:he.map(e=>j(v,{onClick:()=>k(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===h?`text-primary font-semibold`:``}`,children:e},e))})]}),j(`button`,{onClick:O,disabled:d===e.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart process`,children:j(L,{className:`h-3 w-3 ${d===e.name?`animate-spin`:``}`})})]})]}),l&&s.length>0&&j(`div`,{className:`divide-y divide-border/30`,children:s.map(e=>D(`div`,{children:[D(`div`,{className:`flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors`,children:[j(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`running`?`bg-success`:`bg-muted-foreground/30`}`}),j(`span`,{className:`text-xs font-medium flex-1 min-w-0 truncate`,children:e.addonId}),e.capabilities.length>0&&D(`div`,{className:`flex gap-1 flex-shrink-0`,children:[e.capabilities.slice(0,3).map(e=>j(`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&&D(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,e.capabilities.length-3]})]}),D(`div`,{className:`flex items-center gap-1 shrink-0`,children:[j(`button`,{onClick:()=>o(e.addonId,`logs`),className:`p-0.5 rounded transition-colors ${a?.addonId===e.addonId&&a.type===`logs`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show logs for ${e.addonId}`,children:j(H,{className:`h-3 w-3`})}),j(`button`,{onClick:()=>o(e.addonId,`events`),className:`p-0.5 rounded transition-colors ${a?.addonId===e.addonId&&a.type===`events`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:`Show events for ${e.addonId}`,children:j(F,{className:`h-3 w-3`})}),j(`button`,{onClick:()=>E(e.addonId),disabled:d===e.addonId,className:`p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:`Restart ${e.addonId}`,children:j(L,{className:`h-3 w-3 ${d===e.addonId?`animate-spin`:``}`})})]})]}),a?.addonId===e.addonId&&a.type===`logs`&&j(`div`,{className:`border-t border-border/40 bg-muted/5`,children:j(S,{addonId:e.addonId,agentId:n,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>o(e.addonId,`logs`)})}),a?.addonId===e.addonId&&a.type===`events`&&j(`div`,{className:`border-t border-border/40 bg-muted/5`,children:j(p,{addonId:e.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>o(e.addonId,`events`)})})]},e.addonId))}),l&&s.length===0&&j(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:`No services`})]})}function _e({nodeId:e,processes:t}){let[n,r]=A(null),i=(e,t)=>{r(n=>n?.addonId===e&&n.type===t?null:{addonId:e,type:t})};return t.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No processes on this node`}):j(`div`,{className:`space-y-2 py-1`,children:t.map((t,r)=>j(ge,{proc:t,nodeId:e,defaultExpanded:r===0,activePanel:n,onTogglePanel:i},t.name))})}E();function ve(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 ye(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function be({nodeId:e}){let t=k(),r=C(),[i,o]=A(`all`),s=_(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:c}=a({nodeId:e}),l=s?.processes??c,u=O(()=>l?[...l]:[],[l]),d=O(()=>i===`ghost`?u.filter(e=>e.classification===`ghost`):u,[u,i]),f=O(()=>{let e=u.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)},[u]),p=n({onSettled:()=>{t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]})}}),m=O(()=>{let e=new Map;for(let t of u)e.set(t.pid,t.classification);return e},[u]),h=async(t,n)=>{if(t.classification===`root`||t.classification===`system`)return;let i=t.classification===`ghost`?`ghost`:t.addonId??`process`,a=n?`SIGKILL`:`SIGTERM`;await r({title:`Send ${a}?`,message:`Target pid ${t.pid} (${i}) on node ${e}.`,confirmLabel:`Send ${a}`,variant:`danger`})&&p.mutate({nodeId:e,pid:t.pid,force:n})},g=async(t,n)=>{try{await p.mutateAsync({nodeId:e,pid:t,force:n})}catch{}},v=async n=>{let i=m.get(n.ppid);if(i===`root`||i===`system`){await r({title:`Cannot kill protected ancestor`,message:i===`root`?`pid ${n.ppid} is the current node supervisor. Restart the node via the cluster page instead.`:`pid ${n.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 r({title:`Kill ghost parent + ${n.children.length} child(ren)?`,message:`SIGKILL parent pid ${n.ppid} and SIGTERM ${n.children.length} ghost child(ren) on node ${e}.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all([g(n.ppid,!0),...n.children.map(e=>g(e.pid,!1))]),t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},y=async()=>{let n=u.filter(e=>e.classification===`ghost`);n.length!==0&&await r({title:`Kill all ${n.length} ghost process(es)?`,message:`SIGKILL ${n.length} ghost process(es) on node ${e}. This is irreversible.`,confirmLabel:`Kill all`,variant:`danger`})&&(await Promise.all(n.map(e=>g(e.pid,!0))),t.invalidateQueries({queryKey:[[`metricsProvider`,`listNodeProcesses`]]}))},b=u.filter(e=>e.classification===`ghost`).length,x=u.filter(e=>e.classification===`managed`).length,S=u.filter(e=>e.classification===`root`).length,w=u.filter(e=>e.classification===`system`).length;return D(`div`,{className:`space-y-4`,children:[D(`div`,{className:`flex items-start justify-between gap-4`,children:[D(`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."]}),D(`button`,{type:`button`,onClick:()=>t.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:[j(I,{className:`h-3 w-3`}),` Refresh`]})]}),D(`div`,{className:`grid grid-cols-4 gap-3`,children:[D(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Root`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:S})]}),D(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`Managed`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:x})]}),D(`div`,{className:`rounded-lg border border-border p-3`,children:[j(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:`System`}),j(`div`,{className:`text-xl font-semibold text-foreground`,children:w})]}),D(`div`,{className:`rounded-lg border p-3 ${b>0?`border-destructive/40 bg-destructive/5`:`border-border`}`,children:[D(`div`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle flex items-center gap-1`,children:[b>0&&j(X,{className:`h-3 w-3 text-destructive`}),` Ghosts`]}),j(`div`,{className:`text-xl font-semibold ${b>0?`text-destructive`:`text-foreground`}`,children:b})]})]}),f.length>0&&D(`div`,{className:`rounded-lg border border-amber-500/40 bg-amber-500/5 p-3`,children:[D(`div`,{className:`flex items-center gap-1 text-[11px] font-semibold text-amber-400 mb-2`,children:[j(U,{className:`h-3 w-3`}),` Recurring ghost parents (`,f.length,`)`]}),j(`div`,{className:`space-y-1.5`,children:f.map(e=>D(`div`,{className:`text-[11px] text-foreground flex items-center justify-between gap-2`,children:[D(`div`,{className:`flex items-center gap-2`,children:[D(`span`,{className:`font-mono text-foreground-subtle`,children:[`ppid `,e.ppid]}),D(`span`,{children:[`→ `,e.children.length,` ghost(s)`]})]}),D(`button`,{type:`button`,disabled:p.isPending,onClick:()=>{v(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:[j(X,{className:`h-3 w-3`}),` Kill parent + `,e.children.length]})]},e.ppid))})]}),D(`div`,{className:`flex items-center justify-between gap-2 text-[11px]`,children:[D(`div`,{className:`flex items-center gap-2`,children:[j(`span`,{className:`text-foreground-subtle`,children:`Filter:`}),D(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${i===`all`?`bg-primary text-primary-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>o(`all`),children:[`All (`,u.length,`)`]}),D(`button`,{type:`button`,className:`px-2 py-0.5 rounded ${i===`ghost`?`bg-destructive text-destructive-foreground`:`border border-border text-foreground hover:bg-surface-hover`}`,onClick:()=>o(`ghost`),children:[`Ghost only (`,b,`)`]})]}),b>0&&D(`button`,{type:`button`,disabled:p.isPending,onClick:()=>{y()},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:[j(X,{className:`h-3 w-3`}),` Kill all `,b,` ghost(s)`]})]}),j(`div`,{className:`rounded-lg border border-border max-h-[60vh] overflow-auto`,children:D(`table`,{className:`w-full text-xs`,children:[j(`thead`,{className:`sticky top-0 z-10 bg-surface`,children:D(`tr`,{className:`text-foreground-subtle text-[10px] uppercase tracking-wider`,children:[j(`th`,{className:`text-left px-3 py-2`,children:`Class`}),j(`th`,{className:`text-right px-3 py-2`,children:`PID`}),j(`th`,{className:`text-right px-3 py-2`,children:`PPID`}),j(`th`,{className:`text-left px-3 py-2`,children:`Addon`}),j(`th`,{className:`text-left px-3 py-2`,children:`Command`}),j(`th`,{className:`text-right px-3 py-2`,children:`CPU%`}),j(`th`,{className:`text-right px-3 py-2`,children:`RSS`}),j(`th`,{className:`text-right px-3 py-2`,children:`Uptime`}),j(`th`,{className:`w-44`})]})}),D(`tbody`,{children:[d.length===0&&j(`tr`,{children:j(`td`,{colSpan:9,className:`px-3 py-4 text-center text-foreground-subtle text-[11px]`,children:i===`ghost`?`No ghost processes detected.`:`Scanning…`})}),d.map(e=>D(`tr`,{className:`border-t border-border ${e.classification===`ghost`?`bg-destructive/5`:``}`,children:[j(`td`,{className:`px-3 py-2`,children:j(`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})}),j(`td`,{className:`px-3 py-2 text-right font-mono text-foreground`,children:e.pid}),D(`td`,{className:`px-3 py-2 text-right font-mono text-foreground-subtle`,children:[e.ppid,e.orphaned?` ⚠`:``]}),j(`td`,{className:`px-3 py-2 text-foreground-subtle text-[11px]`,children:e.addonId??`—`}),j(`td`,{className:`px-3 py-2 font-mono text-[10px] text-foreground-subtle break-all`,children:ye(e.command)}),j(`td`,{className:`px-3 py-2 text-right text-foreground`,children:e.cpuPercent.toFixed(1)}),j(`td`,{className:`px-3 py-2 text-right text-foreground`,children:J(e.memoryRssBytes)}),j(`td`,{className:`px-3 py-2 text-right text-foreground-subtle`,children:ve(e.uptimeSec)}),j(`td`,{className:`px-3 py-2 text-right`,children:D(`div`,{className:`inline-flex gap-1`,children:[D(`button`,{type:`button`,disabled:p.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{h(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:[j(W,{className:`h-3 w-3`}),` Term`]}),D(`button`,{type:`button`,disabled:p.isPending||e.classification===`root`||e.classification===`system`,onClick:()=>{h(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:[j(X,{className:`h-3 w-3`}),` Kill`]})]})})]},e.pid))]})]})}),p.isError&&D(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[`Kill failed:`,` `,p.error instanceof Error?p.error.message:`unknown`]})]})}function xe({nodeId:e,addonIds:t}){return t.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No addons on this node`}):j(`div`,{className:`w-full py-2`,children:j(oe,{nodeId:e,addonIds:t,level:`global`,selfTabbed:!0})})}E();function Se({nodeId:e,addons:t}){let n=k(),{data:r,isLoading:i}=s({nodeId:e}),a=O(()=>{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=d({onSuccess:()=>{n.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCapabilityBindings`]]})}});return a.length===0?j(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:`No capabilities on this node`}):j(`div`,{className:`rounded-lg border border-border max-h-[60vh] overflow-auto`,children:D(`table`,{className:`w-full text-xs`,children:[j(`thead`,{className:`sticky top-0 z-10 bg-surface`,children:D(`tr`,{className:`text-muted-foreground text-left`,children:[j(`th`,{className:`px-3 py-2 font-medium w-1/2`,children:`Capability`}),j(`th`,{className:`px-3 py-2 font-medium`,children:`Bound provider`})]})}),j(`tbody`,{children:a.map(({capName:t,providers:n})=>{let a=r?.[t]??n[0]??``,s=n.length===1;return D(`tr`,{className:`border-t border-border/50`,children:[j(`td`,{className:`px-3 py-2 font-medium`,children:t}),j(`td`,{className:`px-3 py-2`,children:j(`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=>j(`option`,{value:e,children:e},e))})})]},t)})})]})})}E();function Z(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 Ce(e){let[t,n]=A(!1),[r,i]=A(e.name),a=k(),o=l({onSuccess:()=>{a.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}}),s=(e.localIps??[]).filter(e=>!e.includes(`:`)),c=(e.localIps??[]).filter(e=>e.includes(`:`)),u=async()=>{if(!r.trim()||r===e.name){n(!1);return}try{await o.mutateAsync({nodeId:e.nodeId,name:r.trim()}),n(!1)}catch(e){console.error(`Rename failed:`,e)}},d=[[`Node ID`,j(`span`,{className:`font-mono text-xs`,children:e.nodeId})],[`Display Name`,t?D(`div`,{className:`flex items-center gap-1.5`,children:[j(`input`,{type:`text`,className:`flex-1 px-2 py-0.5 text-xs border border-border rounded bg-background focus:outline-none focus:ring-1 focus:ring-primary`,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&u(),e.key===`Escape`&&n(!1)},disabled:o.isPending,autoFocus:!0}),j(`button`,{onClick:()=>void u(),disabled:o.isPending,className:`p-0.5 text-success hover:bg-success/10 rounded`,title:`Save`,children:j(re,{className:`h-3.5 w-3.5`})}),j(`button`,{onClick:()=>n(!1),className:`p-0.5 text-muted-foreground hover:bg-muted rounded`,title:`Cancel`,children:j(ae,{className:`h-3.5 w-3.5`})})]}):D(`div`,{className:`flex items-center gap-1.5`,children:[j(`span`,{className:`text-xs`,children:e.name}),!e.isHub&&j(`button`,{onClick:()=>{i(e.name),n(!0)},className:`p-0.5 text-muted-foreground hover:text-primary rounded`,title:`Rename`,children:j(P,{className:`h-3 w-3`})})]})],[`Hostname`,j(`span`,{className:`text-xs`,children:e.hostname})],[`Role`,e.isHub?j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary font-medium`,children:`Hub`}):j(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium`,children:`Agent`})],[`Root Package`,e.rootPackage?D(`span`,{className:`font-mono text-xs`,children:[e.rootPackage.name,`@`,e.rootPackage.version]}):j(`span`,{className:`text-xs text-muted-foreground`,children:`—`})],[`Platform`,D(`span`,{className:`text-xs`,children:[e.platform,` / `,e.arch]})],[`CPU`,D(`span`,{className:`text-xs`,children:[e.cpuModel??`—`,` (`,e.cpuCores,` cores)`]})],[`Memory`,j(`span`,{className:`text-xs`,children:e.memoryMB>0?`${(e.memoryMB/1024).toFixed(1)} GB`:`—`})],[`Uptime`,j(`span`,{className:`text-xs`,children:Z(e.uptime)})],[`Engines`,e.engines.length>0?j(`div`,{className:`flex flex-wrap gap-1`,children:e.engines.map(e=>j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e))}):j(`span`,{className:`text-xs text-muted-foreground`,children:`—`})]];return s.length>0&&d.push([`IPv4`,j(`div`,{className:`flex flex-wrap gap-1.5`,children:s.map((e,t)=>j(`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`,j(`div`,{className:`flex flex-wrap gap-1.5`,children:c.map((e,t)=>j(`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}`))})]),j(`div`,{className:`py-2`,children:j(`table`,{className:`w-full text-sm`,children:j(`tbody`,{children:d.map(([e,t],n)=>D(`tr`,{className:n%2==0?`bg-muted/20`:``,children:[j(`td`,{className:`py-1.5 px-2 text-xs font-medium text-muted-foreground w-28 align-top whitespace-nowrap`,children:e}),j(`td`,{className:`py-1.5 px-2`,children:t})]},e))})})})}E();var we=[[`serverManagement`,`getServerPackageStatus`]];function Q({label:e,tone:t}){return j(`span`,{className:`inline-flex items-center rounded px-2 py-0.5 text-[11px] font-medium ${{neutral:`bg-surface-muted text-foreground-subtle`,ok:`bg-emerald-500/15 text-emerald-500`,info:`bg-sky-500/15 text-sky-500`,warn:`bg-amber-500/15 text-amber-500`,error:`bg-red-500/15 text-red-500`}[t]}`,children:e})}function $({label:e,value:t}){return D(`div`,{className:`flex items-center justify-between gap-4 text-sm`,children:[j(`span`,{className:`text-foreground-subtle`,children:e}),j(`span`,{className:`font-mono text-foreground`,children:t??`—`})]})}function Te({node:t}){let{t:n}=G(),r=k(),i=C(),[a,s]=A(!1),c=t.isHub?void 0:{nodeId:t.id},l=e(c,{refetchInterval:1e4,enabled:t.isOnline,retry:1}),u=l.data??null,d=w(()=>{r.invalidateQueries({queryKey:we})},[r]),f=g({onSettled:d}),p=o({onSettled:d}),h=m({onSettled:d}),_=w(async()=>{u?.latestVersion!=null&&await i({title:n(`serverManagement.confirmUpdateTitle`,`Update node root package`),message:n(`serverManagement.confirmUpdateBody`,`Install {{pkg}}@{{version}} on "{{node}}" and restart to apply.`,{pkg:u.packageName,version:u.latestVersion,node:t.name}),confirmLabel:n(`serverManagement.confirmUpdateAction`,`Update & restart`)})&&(await p.mutateAsync({version:u.latestVersion,...c})).restarting&&s(!0)},[p,i,t.name,c,u,n]),v=w(async()=>{await i({title:n(`serverManagement.confirmRestartTitle`,`Restart node`),message:n(`serverManagement.confirmRestartBody`,`Restart "{{node}}"? In-flight requests to this node are dropped.`,{node:t.name}),confirmLabel:n(`serverManagement.confirmRestartAction`,`Restart`),variant:`warning`})&&(await h.mutateAsync(c)).restarting&&s(!0)},[i,t.name,h,c,n]),y=()=>{switch(u?.bootMode){case`data-root`:return{label:n(`serverManagement.bootDataRoot`,`runtime-updatable`),tone:`ok`};case`workspace`:return{label:n(`serverManagement.bootWorkspace`,`dev workspace`),tone:`info`};default:return{label:n(`serverManagement.bootBaked`,`baked image seed`),tone:`neutral`}}},b=()=>{if(u==null)return null;switch(u.updateState){case`checking`:return{label:n(`serverManagement.stateChecking`,`checking…`),tone:`info`};case`staging`:return{label:n(`serverManagement.stateStaging`,`updating…`),tone:`info`};case`pending-restart`:return{label:n(`serverManagement.statePending`,`restart pending`),tone:`warn`};default:return u.updateAvailable?{label:n(`serverManagement.stateUpdateAvailable`,`update available`),tone:`warn`}:{label:n(`serverManagement.stateUpToDate`,`up to date`),tone:`ok`}}},x=u?.bootMode===`workspace`,S=t.isOnline&&u!=null&&!x&&u.updateAvailable&&u.updateState===`idle`&&!p.isPending,T=t.isOnline&&u!=null&&u.updateState===`idle`&&!h.isPending,E=t.isOnline?b():null;return D(`div`,{className:`space-y-4 py-2`,children:[D(`div`,{className:`flex items-center justify-between gap-3`,children:[D(`div`,{className:`flex items-center gap-2 min-w-0`,children:[j(`span`,{className:`font-mono text-xs text-foreground-subtle truncate`,children:u?.packageName??t.rootPackage?.name??`@camstack/server`}),t.isOnline&&u!=null&&j(Q,{...y()})]}),E!=null&&j(Q,{...E})]}),!t.isOnline&&j($,{label:n(`serverManagement.lastReportedVersion`,`Last reported version`),value:t.rootPackage?.version??null}),t.isOnline&&l.isLoading&&D(`div`,{className:`flex items-center gap-2 text-sm text-foreground-subtle`,children:[j(V,{className:`h-4 w-4 animate-spin`}),n(`common.loading`,`Loading…`)]}),t.isOnline&&l.isError&&D(`div`,{className:`space-y-1.5`,children:[j(`p`,{className:`text-sm text-red-500`,children:n(`serverManagement.loadError`,`Could not load the node root-package status.`)}),t.rootPackage!=null&&j($,{label:n(`serverManagement.lastReportedVersion`,`Last reported version`),value:t.rootPackage.version})]}),t.isOnline&&u!=null&&D(`div`,{className:`space-y-1.5`,children:[j($,{label:n(`serverManagement.runningVersion`,`Running version`),value:u.runningVersion}),j($,{label:n(`serverManagement.latestVersion`,`Latest on registry`),value:u.latestVersion}),j($,{label:n(`serverManagement.imageSeedVersion`,`Image seed (baked)`),value:u.seedVersion}),j($,{label:n(`serverManagement.nodeRuntimeVersion`,`Node.js runtime`),value:u.nodeRuntimeVersion}),u.pendingVersion!=null&&j($,{label:n(`serverManagement.pendingVersion`,`Staged (applies on restart)`),value:u.pendingVersion})]}),t.isOnline&&(u?.imageContract?.state===`behind-series`||u?.imageContract?.state===`behind-patch`)&&D(`div`,{className:`rounded-md border px-3 py-2 text-xs leading-relaxed ${u.imageContract.state===`behind-series`?`border-red-500/40 bg-red-500/10 text-red-500`:`border-amber-500/40 bg-amber-500/10 text-amber-500`}`,children:[j(`p`,{className:`mb-0.5 font-semibold`,children:n(`serverManagement.imageContractDiverged`,`Container image diverges from the deployment contract`)}),j(`p`,{children:u.imageContract.message})]}),t.isOnline&&x&&j(`p`,{className:`text-xs text-foreground-subtle`,children:n(`serverManagement.workspaceNote`,`Development workspace detected — runtime updates are disabled (the dev loop resolves code from the workspace).`)}),a&&D(`div`,{className:`flex items-center gap-2 text-sm text-amber-500`,children:[j(V,{className:`h-4 w-4 animate-spin`}),n(`serverManagement.nodeRestarting`,`The node is restarting to apply the change…`)]}),t.isOnline&&D(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[D(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-surface-muted disabled:opacity-50`,disabled:f.isPending||u?.updateState===`staging`,onClick:()=>f.mutate(c),children:[f.isPending?j(V,{className:`h-3.5 w-3.5 animate-spin`}):j(I,{className:`h-3.5 w-3.5`}),n(`serverManagement.checkForUpdate`,`Check for update`)]}),S&&D(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-2.5 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50`,onClick:()=>void _(),children:[p.isPending?j(V,{className:`h-3.5 w-3.5 animate-spin`}):j(Y,{className:`h-3.5 w-3.5`}),n(`serverManagement.updateTo`,`Update to {{version}}`,{version:u?.latestVersion??``})]}),D(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-xs font-medium text-foreground hover:bg-surface-muted disabled:opacity-50`,disabled:!T,onClick:()=>void v(),children:[h.isPending?j(V,{className:`h-3.5 w-3.5 animate-spin`}):j(L,{className:`h-3.5 w-3.5`}),n(`serverManagement.restart`,`Restart`)]})]}),t.isOnline&&u?.lastCheckedAtMs!=null&&D(`p`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[j(ce,{className:`h-3 w-3`}),n(`serverManagement.lastChecked`,`Last checked: {{when}}`,{when:new Date(u.lastCheckedAtMs).toLocaleString()})]})]})}E();function Ee({node:e}){let t=N(),[n,r]=A(`info`),[i,a]=A(!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?D(`div`,{className:`border border-border rounded-xl`,children:[D(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30 border-b border-border rounded-t-xl`,children:[j(`div`,{className:`w-2.5 h-2.5 rounded-full bg-success`}),j(`span`,{className:`text-sm font-semibold`,children:e.name}),D(`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=>j(`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(`div`,{className:`ml-auto flex gap-3 text-xs text-muted-foreground`,children:[D(`span`,{className:`flex items-center gap-1`,children:[j(ne,{className:`h-3 w-3`}),` `,e.cpuPercent,`%`]}),D(`span`,{className:`flex items-center gap-1`,children:[j(le,{className:`h-3 w-3`}),` `,e.memoryPercent,`%`]})]})]}),j(`div`,{className:`sticky top-0 z-20 flex border-b border-border px-4 bg-background overflow-x-auto`,children:[`info`,`addons`,`forks`,`processes`,`settings`,`capabilities`].map(t=>j(`button`,{onClick:()=>r(t),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${n===t?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:t===`info`?`General`:t===`addons`?`Addons (${e.addons.length})`:t===`forks`?`Forks (${o.length})`:t===`processes`?`Processes`:t===`settings`?`Settings`:`Capabilities`},t))}),D(`div`,{className:`px-4 py-2`,children:[n===`info`&&D(`div`,{className:`space-y-3`,children:[j(Ce,{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}),j(`div`,{className:`border-t border-border pt-1`,children:j(Te,{node:{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,rootPackage:e.rootPackage??null}})})]}),n===`addons`&&j(fe,{nodeId:e.id,addons:e.addons,isHub:e.isHub}),n===`forks`&&j(_e,{nodeId:e.id,processes:o}),n===`processes`&&j(be,{nodeId:e.id}),n===`settings`&&j(xe,{nodeId:e.id,addonIds:s}),n===`capabilities`&&j(Se,{nodeId:e.id,addons:e.addons})]})]}):D(`div`,{className:`border border-border rounded-xl overflow-hidden opacity-60`,children:[D(`div`,{className:`flex items-center gap-3 px-4 py-3 bg-muted/30`,children:[j(`div`,{className:`w-2.5 h-2.5 rounded-full bg-destructive`}),j(`span`,{className:`text-sm font-semibold`,children:e.name}),D(`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=>j(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-purple-500/10 text-purple-400 font-medium`,children:e},e)),e.rootPackage&&D(`span`,{className:`text-[10px] font-mono px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:[e.rootPackage.name,`@`,e.rootPackage.version]}),j(`span`,{className:`ml-auto text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:`offline`})]}),D(`div`,{className:`flex items-center justify-between gap-3 px-4 py-3`,children:[D(`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`]}),D(`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:[j(W,{className:`h-3 w-3`}),i?`Forgetting…`:`Forget node`]})]})]})}E();function De({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=T(null);return M(()=>{if(!t)return;let e=i.current?.querySelector(`#node-card-${CSS.escape(t)}`);e&&e.scrollIntoView({behavior:`smooth`,block:`start`})},[t,n]),j(`div`,{ref:i,className:`flex flex-col gap-4`,children:r.map(e=>j(`div`,{id:`node-card-${e.id}`,children:j(Ee,{node:e})},e.id))})}E();function Oe(e){let[t,n]=A(()=>typeof window<`u`?window.matchMedia(e).matches:!1);return M(()=>{let t=window.matchMedia(e),r=e=>n(e.matches);return t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t}function ke(){let{data:e,isLoading:t}=r(void 0,{staleTime:1/0}),[n,i]=A(null);return h(`cluster.topology-snapshot`,e=>{let t=e.data?.nodes;Array.isArray(t)&&i(t)}),{nodes:O(()=>n??e??[],[n,e]),isLoading:t&&!n}}function Ae(){let{t:e}=G(),t=C(),[n,r]=A(`table`),[i,a]=A(void 0),[s,c]=A(0),l=Oe(`(max-width: 767px)`),u=l&&n===`graph`?`table`:n,{nodes:d,isLoading:f}=ke(),p=O(()=>q(d),[d]),m=O(()=>d.filter(e=>e.isOnline),[d]),h=m.length,g=d.filter(e=>!e.isOnline).length,_=o(),[v,y]=A(!1),b=w(async()=>{let n=[...m].sort((e,t)=>e.isHub===t.isHub?0:e.isHub?1:-1);if(await t({title:e(`serverManagement.confirmUpdateAllTitle`,`Update all nodes`),message:e(`serverManagement.confirmUpdateAllBody`,`Update and restart every online node, agents first, hub last. Up-to-date nodes are skipped; this page reconnects when the hub comes back.`),confirmLabel:e(`serverManagement.confirmUpdateAllAction`,`Update all & restart`),variant:`warning`})){y(!0);try{for(let e of n)try{await _.mutateAsync(e.isHub?{}:{nodeId:e.id})}catch{}}finally{y(!1)}}},[_,t,m,e]),x=w(e=>{r(`table`),a(e),c(e=>e+1)},[]),S=(e,t,i)=>D(`button`,{onClick:()=>r(e),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-xs font-medium transition-colors ${n===e?`bg-primary text-primary-foreground`:`text-muted-foreground hover:text-foreground`}`,children:[j(i,{className:`h-3.5 w-3.5`}),t]});return D(`div`,{className:`flex flex-col h-full gap-4 p-4`,children:[D(`div`,{className:`flex items-center justify-between gap-2 flex-wrap`,children:[D(`div`,{className:`flex items-center gap-2`,children:[h>0&&D(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-success/10 text-success`,children:[h,` online`]}),g>0&&D(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:[g,` offline`]})]}),D(`div`,{className:`flex items-center gap-2`,children:[h>1&&D(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:opacity-90 disabled:opacity-50`,disabled:v,title:e(`serverManagement.updateAllHint`,`Sequenced agents-first, hub-last — up-to-date nodes are skipped.`),onClick:()=>void b(),children:[v?j(V,{className:`h-3.5 w-3.5 animate-spin`}):j(Y,{className:`h-3.5 w-3.5`}),e(`serverManagement.updateAll`,`Update all nodes`)]}),D(`div`,{className:`flex gap-0.5 p-1 rounded-lg bg-muted`,children:[S(`table`,`Table`,ue),!l&&S(`graph`,`Graph`,se)]})]})]}),f?j(`div`,{className:`flex items-center justify-center flex-1 text-muted-foreground`,children:`Loading cluster topology...`}):u===`graph`?j(K,{graph:p,onOpenNodeDetail:x}):j(`div`,{className:`flex-1 overflow-auto`,children:j(De,{nodes:d,focusNodeId:i,focusNonce:s})})]})}export{Ae as ClusterPage};
@@ -1 +0,0 @@
1
- import{$t as e,At as t,Ba as n,Gt as r,Jt as i,Kt as a,Ma as o,Na as s,Pa as c,Qt as l,Tt as u,Xt as d,Yt as f,Zt as p,en as m,qt as h,wo as g,wt as _}from"./src-BmAmiAXy.js";import{I as v,Q as y,S as b,W as x,b as S,o as C,q as w,x as T,z as E}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-DTufy7Ue.js";import{t as D}from"./download-CXXQf3fF.js";import{t as O}from"./hard-drive-gxnGyiw0.js";import{t as k}from"./pencil-OtLKJIw8.js";import{t as A}from"./play-Q-R5vHEh.js";import{t as j}from"./plus-vrCV3Fn-.js";import{t as M}from"./rotate-cw-B6qXQ5pJ.js";import{i as N,n as P,r as F,t as I}from"./AddLocationWizard-BXcL90QM.js";import{F as ee,G as L,L as te,S as R,U as ne,i as z,m as B,s as V}from"./index-B6kDpXr5.js";import{t as H}from"./AdminPage-Dq33XE9j.js";import{r as re}from"./authed-media-B8T1dsFh.js";import{t as ie}from"./AdminTabs-Co61VJ4U.js";import{t as U}from"./format-size-CO9d3C3-.js";import{t as ae}from"./AddonCollectionPage-C7QSc0L5.js";import{t as W}from"./addon-display-names-DvSEQty-.js";var G=L(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),K=L(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),q=L(`calendar-clock`,[[`path`,{d:`M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5`,key:`1osxxc`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`path`,{d:`M3 10h5`,key:`r794hk`}],[`path`,{d:`M17.5 17.5 16 16.3V14`,key:`akvzfd`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]),J=L(`file-text`,[[`path`,{d:`M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z`,key:`1rqfz7`}],[`path`,{d:`M14 2v4a2 2 0 0 0 2 2h4`,key:`tnqrlb`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]);y();function oe(){let e=C(),t=g(),{data:r,isLoading:i,isError:a}=c({}),l=s(),u=x(()=>l.data??[],[l.data]),[d,f]=w(null),[p,m]=w(null),h=o({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),_=n({onSuccess:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]})}}),v=e=>{e.isDefault||_.mutate(N(e,{isDefault:!0}))},y=(e,t)=>{_.mutate(N(e,{enabled:t}))},S=async e=>{if(e.isDefault){await t({title:`Cannot delete default location`,message:`"${e.displayName}" is the default for type "${e.type}". Mark another location as default first, then delete this one.`,confirmLabel:`OK`,variant:`warning`});return}await t({title:`Delete location "${e.displayName}"?`,message:`This removes the location record. Files on disk are not deleted; the underlying directory or remote path stays untouched.`,confirmLabel:`Delete`,variant:`danger`})&&h.mutate({id:e.id})},E=x(()=>{let e=new Map;for(let t of r??[]){let n=e.get(t.type);n?n.push(t):e.set(t.type,[t])}return e},[r]),D=i||l.isLoading,O=a||l.isError;return b(H,{children:[D&&T(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading locations…`}),O&&T(`div`,{className:`text-xs text-danger`,children:`Failed to load storage locations.`}),!D&&!O&&b(`div`,{className:`space-y-3`,children:[u.length===0&&T(`div`,{className:`rounded-lg border border-border bg-surface px-3 py-4 text-center text-[11px] text-foreground-subtle italic`,children:`No storage locations declared by any installed addon.`}),u.map(e=>T(F,{type:e.id,displayName:e.displayName,description:e.description,cardinality:e.cardinality,locations:E.get(e.id)??[],onAdd:e=>f(e),onEdit:e=>m(e),onDelete:e=>{S(e)},onSetDefault:e=>v(e),onToggleEnabled:(e,t)=>y(e,t)},e.id))]}),d!==null&&T(I,{initialType:d,onClose:()=>f(null),onCreated:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),f(null)}}),p!==null&&T(P,{location:p,onClose:()=>m(null),onSaved:()=>{e.invalidateQueries({queryKey:[[`storage`,`listLocations`]]}),m(null)}})]})}y();var se=[[`backup`,`listDestinations`]],ce=[`backup`,`listArchives`];function le({destinationId:e,restoreSupported:t,onOpenRestoreWizard:n}){let a=C(),o=g(),{data:s,isLoading:c,isError:l}=i({destinationId:e}),u=s??[],d=r({onSuccess:()=>{a.invalidateQueries({queryKey:[[...ce]]}),a.invalidateQueries({queryKey:se})}}),f=v(async t=>{await o({title:`Delete this archive?`,message:`Permanently deletes "${t.label??t.id}" and frees ${U(t.sizeBytes)}.`,confirmLabel:`Delete`,variant:`danger`})&&d.mutate({destinationId:e,backupId:t.id})},[o,e,d]),[p,m]=w(null),h=v(async t=>{m(t.id);try{let n=await re(ue(e,t.id)),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${t.label??t.id}.tar.gz`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}finally{m(null)}},[e]),_=x(()=>[...u].toSorted((e,t)=>t.createdAt-e.createdAt),[u]);return c?T(`div`,{className:`text-xs text-foreground-subtle animate-pulse py-2`,children:`Loading archives…`}):l?T(`div`,{className:`text-xs text-danger py-2`,children:`Failed to read manifest for this destination`}):_.length===0?T(`div`,{className:`text-xs text-foreground-subtle italic py-2`,children:`No archives at this destination yet.`}):T(`div`,{className:`rounded border border-border bg-surface overflow-x-auto`,children:b(`table`,{className:`w-full text-xs min-w-[640px]`,children:[T(`thead`,{children:b(`tr`,{className:`text-foreground-subtle bg-background/30`,children:[T(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`When`}),T(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Label`}),T(`th`,{className:`text-left px-3 py-1.5 font-medium`,children:`Includes`}),T(`th`,{className:`text-right px-3 py-1.5 font-medium`,children:`Size`}),T(`th`,{className:`text-right px-3 py-1.5 font-medium w-52`,children:`Actions`})]})}),T(`tbody`,{children:_.map(r=>b(`tr`,{className:`border-t border-border hover:bg-primary/5`,children:[T(`td`,{className:`px-3 py-1.5 text-foreground tabular-nums`,children:de(r.createdAt)}),T(`td`,{className:`px-3 py-1.5 text-foreground`,children:r.label??T(`span`,{className:`text-foreground-subtle italic`,children:`—`})}),T(`td`,{className:`px-3 py-1.5 text-foreground-subtle`,children:r.locations.join(`, `)}),T(`td`,{className:`px-3 py-1.5 text-foreground text-right tabular-nums`,children:U(r.sizeBytes)}),T(`td`,{className:`px-3 py-1.5`,children:b(`div`,{className:`flex items-center justify-end gap-1`,children:[b(`button`,{onClick:()=>{h(r)},disabled:p===r.id,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-foreground-subtle hover:text-foreground hover:bg-primary/10 disabled:opacity-50`,title:`Download archive`,children:[p===r.id?T(R,{className:`h-3 w-3 animate-spin`}):T(D,{className:`h-3 w-3`}),`Download`]}),t&&n&&b(`button`,{onClick:()=>n({destinationId:e,archiveId:r.id}),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-primary hover:bg-primary/10`,title:`Restore from this archive`,children:[T(M,{className:`h-3 w-3`}),`Restore`]}),T(`button`,{onClick:()=>{f(r)},disabled:d.isPending,className:`inline-flex items-center gap-1 rounded px-2 py-1 text-[10px] font-medium text-danger hover:bg-danger/10 disabled:opacity-50`,title:`Delete archive`,children:d.isPending?T(R,{className:`h-3 w-3 animate-spin`}):T(V,{className:`h-3 w-3`})})]})})]},r.id))})]})})}function ue(e,t){return`/api/backup/download/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}function de(e){return new Date(e).toLocaleString(void 0,{day:`2-digit`,month:`short`,year:`numeric`,hour:`2-digit`,minute:`2-digit`})}y();var Y=[[`backup`,`listSchedules`]];function fe({onEdit:e,onOpenRestoreWizard:t}){let{data:n,isLoading:r,isError:i}=d(),a=n??[],o=f().data??[],s=x(()=>{let e=new Map;for(let t of o)e.set(t.id,t);return e},[o]),[c,l]=w(null),u=e=>{l(t=>t===e?null:e)};return r?T(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Loading backup entries…`}):i?T(`div`,{className:`text-xs text-danger`,children:`Failed to load backup entries`}):a.length===0?T(`div`,{className:`rounded-lg border border-border bg-surface px-4 py-8 text-center`,children:T(`p`,{className:`text-xs text-foreground-subtle`,children:`No backup entries yet. Create one to schedule backups across one or more storage locations.`})}):T(`div`,{className:`rounded-lg border border-border bg-surface overflow-x-auto`,children:b(`table`,{className:`w-full text-xs min-w-[820px]`,children:[T(`thead`,{children:b(`tr`,{className:`text-foreground-subtle border-b border-border bg-background/40`,children:[T(`th`,{className:`text-left px-3 py-2 font-medium w-6`}),T(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Entry`}),T(`th`,{className:`text-left px-3 py-2 font-medium w-20`,children:`Enabled`}),T(`th`,{className:`text-left px-3 py-2 font-medium`,children:`Locations`}),T(`th`,{className:`text-left px-3 py-2 font-medium w-24`,children:`Retention`}),T(`th`,{className:`text-left px-3 py-2 font-medium w-48`,children:`Schedule`}),T(`th`,{className:`text-right px-3 py-2 font-medium w-52`,children:`Actions`})]})}),T(`tbody`,{children:a.map(n=>T(pe,{row:n,destById:s,isOpen:c===n.id,onToggle:()=>u(n.id),onEdit:()=>e(n),...t?{onOpenRestoreWizard:t}:{}},n.id))})]})})}function pe({row:t,destById:n,isOpen:r,onToggle:i,onEdit:o,onOpenRestoreWizard:s}){let c=C(),l=g(),u=m({onSuccess:()=>{c.invalidateQueries({queryKey:Y})}}),d=a({onSuccess:()=>{c.invalidateQueries({queryKey:Y})}}),f=e({onSuccess:()=>{c.invalidateQueries({queryKey:[[`backup`,`listArchives`]]}),c.invalidateQueries({queryKey:[[`backup`,`listDestinations`]]})}}),[p,h]=w(String(t.retentionCount));E(()=>{h(String(t.retentionCount))},[t.retentionCount]);let _=x(()=>({id:t.id,label:t.label,cron:t.cron,locationIds:[...t.locationIds],retentionCount:t.retentionCount,...t.dataSources?{dataSources:[...t.dataSources]}:{}}),[t]),y=v(e=>{u.mutate({..._,enabled:e})},[u,_]),D=v(()=>{let e=Number.parseInt(p,10);if(Number.isNaN(e)||e<1){h(String(t.retentionCount));return}e!==t.retentionCount&&u.mutate({..._,enabled:t.enabled,retentionCount:e})},[u,_,p,t.retentionCount,t.enabled]),O=v(()=>{t.locationIds.length!==0&&f.mutate({destinations:[...t.locationIds],...t.dataSources&&t.dataSources.length>0?{locations:[...t.dataSources]}:{},label:t.label,retentionCount:t.retentionCount})},[f,t]),j=v(async()=>{await l({title:`Delete backup entry?`,message:`"${t.label||t.id}" will stop running. Existing archives are kept.`,confirmLabel:`Delete`,variant:`warning`})&&d.mutate({id:t.id})},[l,d,t.id,t.label]),M=t.cron.trim().length>0,N=u.isPending||d.isPending;return b(S,{children:[b(`tr`,{className:`border-t border-border first:border-t-0 hover:bg-primary/5`,children:[T(`td`,{className:`px-2 py-2`,children:T(`button`,{onClick:i,className:`inline-flex items-center justify-center rounded p-1 text-foreground-subtle hover:bg-primary/10 hover:text-foreground`,title:r?`Hide archives`:`Show archives`,children:T(r?te:ee,{className:`h-3.5 w-3.5`})})}),T(`td`,{className:`px-3 py-2`,children:b(`button`,{onClick:o,className:`text-left hover:underline focus:outline-none`,children:[T(`div`,{className:`text-foreground font-medium`,children:t.label||`(unnamed)`}),t.lastRunAt!==void 0&&b(`div`,{className:`text-[10px] text-foreground-subtle mt-0.5`,children:[`last run `,new Date(t.lastRunAt).toLocaleString()]})]})}),T(`td`,{className:`px-3 py-2`,children:T(`label`,{className:`inline-flex items-center cursor-pointer`,children:T(`input`,{type:`checkbox`,className:`accent-primary`,checked:t.enabled,disabled:N,onChange:e=>y(e.target.checked)})})}),T(`td`,{className:`px-3 py-2`,children:b(`div`,{className:`flex flex-wrap gap-1`,children:[t.locationIds.length===0&&T(`span`,{className:`text-[11px] text-danger italic`,children:`No locations`}),t.locationIds.map(e=>T(`span`,{className:`inline-flex items-center rounded border border-border bg-background px-1.5 py-0.5 text-[10px] text-foreground`,title:e,children:n.get(e)?.displayName??e},e))]})}),T(`td`,{className:`px-3 py-2`,children:T(`input`,{type:`number`,min:1,max:1e3,value:p,disabled:N,onChange:e=>h(e.target.value),onBlur:D,onKeyDown:e=>{e.key===`Enter`&&e.target.blur(),e.key===`Escape`&&h(String(t.retentionCount))},className:`w-16 rounded border border-border bg-background px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})}),T(`td`,{className:`px-3 py-2`,children:b(`button`,{onClick:o,className:`group flex flex-col items-start gap-0.5 text-left`,title:`Edit schedule`,children:[b(`span`,{className:`inline-flex items-center gap-1`,children:[T(q,{className:`h-3 w-3 text-foreground-subtle group-hover:text-foreground`}),T(`span`,{className:`font-mono text-[11px] text-foreground`,children:M?t.cron:`Manual`})]}),M&&t.nextRunAt!==void 0&&b(`span`,{className:`text-[10px] text-foreground-subtle`,children:[`next `,new Date(t.nextRunAt).toLocaleString()]})]})}),T(`td`,{className:`px-3 py-2`,children:b(`div`,{className:`flex items-center justify-end gap-1.5`,children:[b(`button`,{onClick:O,disabled:f.isPending||t.locationIds.length===0,className:`inline-flex items-center gap-1 rounded bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,title:`Run this entry now`,children:[f.isPending?T(R,{className:`h-3 w-3 animate-spin`}):T(A,{className:`h-3 w-3`}),`Run now`]}),T(`button`,{onClick:o,className:`inline-flex items-center justify-center rounded border border-border p-1 text-foreground-subtle hover:text-foreground hover:bg-primary/5`,title:`Edit entry`,children:T(k,{className:`h-3 w-3`})}),T(`button`,{onClick:()=>{j()},disabled:N,className:`inline-flex items-center justify-center rounded border border-border p-1 text-foreground-subtle hover:text-danger hover:border-danger/40 disabled:opacity-50`,title:`Delete entry`,children:T(V,{className:`h-3 w-3`})})]})})]}),r&&T(`tr`,{className:`border-t border-border bg-background/30`,children:b(`td`,{colSpan:7,className:`px-4 py-3 space-y-4`,children:[t.locationIds.length===0&&T(`p`,{className:`text-xs text-foreground-subtle italic`,children:`This entry has no locations selected.`}),t.locationIds.map(e=>b(`div`,{className:`space-y-1.5`,children:[T(`div`,{className:`text-[11px] font-medium text-foreground-subtle`,children:n.get(e)?.displayName??e}),T(le,{destinationId:e,restoreSupported:n.get(e)?.restoreSupported??!0,...s?{onOpenRestoreWizard:s}:{}})]},e))]})})]})}y();var X=[{id:`manual`,label:`Manual only`,cron:``},{id:`hourly`,label:`Every hour`,cron:`0 * * * *`,description:`On the hour`},{id:`every-3h`,label:`Every 3 hours`,cron:`0 */3 * * *`,description:`00:00, 03:00, 06:00, 09:00 …`},{id:`every-6h`,label:`Every 6 hours`,cron:`0 */6 * * *`,description:`00:00, 06:00, 12:00, 18:00`},{id:`daily-3am`,label:`Daily at 03:00`,cron:`0 3 * * *`,description:`Every night at 3 AM`},{id:`weekly-sun`,label:`Weekly Sunday 03:00`,cron:`0 3 * * 0`,description:`Sunday morning at 3 AM`}];function me(e){let t=e.trim();for(let e of X)if(e.cron===t)return e.id;return`custom`}function he({value:e,onChange:t,previewCount:n=5,disabled:r=!1}){let i=me(e),[a,o]=w(i===`custom`);E(()=>{i!==`custom`&&o(!1)},[i]);let s=ve(e,250),c=p({cron:s,count:n},{enabled:s.trim().length>0}),l=c.data??null,u=e=>{o(!1),t(e.cron)},d=a||i===`custom`;return b(`div`,{className:`space-y-3`,children:[b(`div`,{className:`space-y-1`,children:[T(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Schedule preset`}),b(`div`,{className:`flex flex-wrap gap-1.5`,children:[X.map(e=>T(`button`,{type:`button`,onClick:()=>u(e),disabled:r,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(!a&&i===e.id?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),title:e.description??e.label,children:e.label},e.id)),T(`button`,{type:`button`,onClick:()=>{o(!0),e.trim().length===0&&t(`0 3 * * *`)},disabled:r,className:`rounded border px-2 py-1 text-[11px] transition-colors disabled:opacity-50 `+(d?`border-primary bg-primary/10 text-primary`:`border-border bg-background text-foreground-subtle hover:bg-primary/5 hover:text-foreground`),children:`Custom…`})]})]}),d&&b(`div`,{className:`space-y-1`,children:[T(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Cron expression (5-field POSIX)`}),T(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),disabled:r,placeholder:`0 3 * * *`,spellCheck:!1,className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs font-mono text-foreground placeholder:text-foreground-subtle focus:outline-none focus:ring-1 focus:ring-primary`}),b(`p`,{className:`text-[10px] text-foreground-subtle`,children:[`Format: `,T(`span`,{className:`font-mono`,children:`minute hour day-of-month month day-of-week`}),` · all times server-local`]})]}),T(ge,{cron:s,preview:l,loading:c.isFetching})]})}function ge({cron:e,preview:t,loading:n}){return n&&t===null?b(`div`,{className:`flex items-center gap-2 rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:[T(R,{className:`h-3 w-3 animate-spin`}),`Validating…`]}):t===null?null:t.ok?t.nextRuns.length===0?T(`div`,{className:`rounded border border-border bg-background/40 px-3 py-2 text-[11px] text-foreground-subtle`,children:`No future runs match this expression.`}):b(`div`,{className:`space-y-1`,children:[T(`div`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle`,children:`Next runs`}),T(`ul`,{className:`rounded border border-border bg-background/40 divide-y divide-border`,children:t.nextRuns.map((e,t)=>b(`li`,{className:`flex items-center justify-between px-3 py-1.5 text-[11px]`,children:[T(`span`,{className:`text-foreground tabular-nums`,children:new Date(e).toLocaleString()}),T(`span`,{className:`text-foreground-subtle text-[10px] tabular-nums`,children:_e(e)})]},`${e}-${t}`))})]}):T(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:t.error??`Invalid cron expression`})}function _e(e){let t=e-Date.now();if(t<=0)return`now`;let n=Math.floor(t/1e3);if(n<60)return`in ${n}s`;let r=Math.floor(n/60);if(r<60)return`in ${r}m`;let i=Math.floor(r/60);return i<24?`in ${i}h`:`in ${Math.floor(i/24)}d`}function ve(e,t){let[n,r]=w(e),i=x(()=>e,[e]);return E(()=>{let e=setTimeout(()=>r(i),t);return()=>clearTimeout(e)},[i,t]),n}y();var ye=[[`backup`,`listSchedules`]];function be({entry:e,onClose:t,onSaved:n}){let r=C(),i=f(),a=i.data??[],[o,s]=w(e?.label??``),[c,l]=w(e?.cron??`0 3 * * *`),[u,d]=w(e?.enabled??!0),[p,h]=w(String(e?.retentionCount??7)),[g,_]=w(new Set(e?.locationIds??[])),v=m({onSuccess:()=>{r.invalidateQueries({queryKey:ye}),n()}}),y=e=>{_(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},S=Number.parseInt(p,10),E=x(()=>o.trim().length>0&&g.size>0&&!Number.isNaN(S)&&S>=1&&S<=1e3,[o,g,S]),D=()=>{E&&v.mutate({...e?{id:e.id}:{},label:o.trim(),cron:c.trim(),enabled:u,locationIds:Array.from(g),retentionCount:S})},O=v.error instanceof Error?v.error.message:null;return T(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:t,children:b(`div`,{className:`w-full max-w-lg rounded-xl border border-border bg-surface shadow-2xl max-h-[90vh] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:[b(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3 sticky top-0 bg-surface`,children:[T(`h2`,{className:`text-sm font-semibold text-foreground`,children:e?`Edit backup entry`:`New backup entry`}),T(`button`,{onClick:t,className:`text-foreground-subtle hover:text-foreground`,children:T(z,{className:`h-4 w-4`})})]}),b(`div`,{className:`p-4 space-y-4`,children:[b(`div`,{className:`space-y-1`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Name`}),T(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),placeholder:`Nightly offsite`,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`})]}),b(`div`,{className:`space-y-1.5`,children:[b(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:[`Locations (`,g.size,` selected)`]}),i.isLoading&&b(`div`,{className:`flex items-center gap-2 px-1 py-2 text-xs text-foreground-subtle`,children:[T(R,{className:`h-3.5 w-3.5 animate-spin`}),`Loading locations…`]}),!i.isLoading&&a.length===0&&T(`div`,{className:`rounded border border-border bg-background px-3 py-2 text-xs text-foreground-subtle italic`,children:"No `backups` storage locations configured. Add one in Settings → Storage first."}),a.length>0&&T(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-52 overflow-y-auto`,children:a.map(e=>b(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[b(`div`,{className:`flex items-center gap-2`,children:[T(`input`,{type:`checkbox`,checked:g.has(e.id),onChange:()=>y(e.id),className:`accent-primary`}),T(`span`,{className:`text-foreground`,children:e.displayName})]}),b(`div`,{className:`flex items-center gap-1.5`,children:[T(`span`,{className:`text-[10px] uppercase tracking-wide text-foreground-subtle bg-surface border border-border rounded px-1.5 py-0.5`,children:e.kind}),T(`span`,{className:`text-[10px] text-foreground-subtle font-mono`,children:e.id})]})]},e.id))})]}),b(`div`,{className:`grid grid-cols-2 gap-3`,children:[b(`div`,{className:`space-y-1`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Retention (archives kept)`}),T(`input`,{type:`number`,min:1,max:1e3,value:p,onChange:e=>h(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`})]}),b(`div`,{className:`space-y-1`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Enabled`}),b(`label`,{className:`inline-flex items-center gap-2 py-1.5 cursor-pointer`,children:[T(`input`,{type:`checkbox`,checked:u,onChange:e=>d(e.target.checked),className:`accent-primary`}),T(`span`,{className:`text-xs text-foreground-subtle`,children:`Run on schedule`})]})]})]}),b(`div`,{className:`space-y-1.5 border-t border-border pt-3`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Schedule`}),T(he,{value:c,onChange:l,disabled:v.isPending})]}),O&&T(`div`,{className:`rounded border border-danger/40 bg-danger/10 px-3 py-2 text-[11px] text-danger`,children:O})]}),b(`div`,{className:`flex justify-end gap-2 border-t border-border px-4 py-3 sticky bottom-0 bg-surface`,children:[T(`button`,{onClick:t,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),b(`button`,{onClick:D,disabled:!E||v.isPending,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:[v.isPending&&T(R,{className:`h-3.5 w-3.5 animate-spin`}),e?`Save`:`Create entry`]})]})]})})}y();var xe=[[`backup`,`list`]];function Se({initialDestinationId:e,initialArchiveId:t,onClose:n,onScheduled:r}){let a=C(),[o,s]=w(e&&t?2:1),[c,u]=w(e),[d,p]=w(t),[m,g]=w(new Set),{data:_}=f(),v=_??[],{data:y,isLoading:S}=i({destinationId:c??``},{enabled:!!c}),D=y??[];E(()=>{if(c!==void 0)return;let e=v.filter(e=>e.restoreSupported);e.length===1&&u(e[0].id)},[c,v]);let{data:O}=h({destinationId:c??``,backupId:d??``},{enabled:!!c&&!!d}),k=x(()=>O?.locations??[],[O]);E(()=>{k.length!==0&&g(e=>e.size===0?new Set(k):e)},[k]);let A=l({onSuccess:()=>{a.invalidateQueries({queryKey:xe}),r(),n()}}),j=e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},N=!!c&&!!d,P=m.size>0,F=N&&P&&!A.isPending,I=()=>{!c||!d||A.mutate({destinationId:c,backupId:d,locations:[...m]})};return T(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm`,onClick:n,children:b(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-surface shadow-2xl`,onClick:e=>e.stopPropagation(),children:[b(`div`,{className:`flex items-start justify-between border-b border-border px-4 py-3`,children:[b(`div`,{className:`space-y-0.5`,children:[T(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Restore Backup`}),b(`p`,{className:`text-xs text-foreground-subtle`,children:[`Step `,o,` of 3 —`,` `,o===1?`pick source`:o===2?`pick locations`:`confirm`]})]}),T(`button`,{onClick:n,className:`text-foreground-subtle hover:text-foreground`,children:T(z,{className:`h-4 w-4`})})]}),o===1&&T(Ce,{destinations:v,destinationId:c,onPickDestination:e=>{u(e),p(void 0),g(new Set)},archives:D,archivesLoading:S,archiveId:d,onPickArchive:p}),o===2&&T(Z,{locations:k,picked:m,onToggle:j}),o===3&&T(we,{destinationName:v.find(e=>e.id===c)?.displayName??c??``,archive:D.find(e=>e.id===d),picked:[...m]}),b(`div`,{className:`flex justify-between gap-2 border-t border-border px-4 py-3`,children:[T(`div`,{children:o>1&&b(`button`,{onClick:()=>s(e=>e===3?2:1),className:`inline-flex items-center gap-1 rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:[T(ne,{className:`h-3 w-3`}),`Back`]})}),b(`div`,{className:`flex items-center gap-2`,children:[T(`button`,{onClick:n,className:`rounded px-3 py-1.5 text-xs text-foreground-subtle border border-border hover:text-foreground`,children:`Cancel`}),o<3?b(`button`,{disabled:o===1&&!N||o===2&&!P,onClick:()=>s(e=>e===1?2:3),className:`inline-flex items-center gap-1 rounded bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,children:[`Next`,T(K,{className:`h-3 w-3`})]}):b(`button`,{onClick:I,disabled:!F,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:[A.isPending?T(R,{className:`h-3.5 w-3.5 animate-spin`}):T(M,{className:`h-3.5 w-3.5`}),`Schedule Restore`]})]})]})]})})}function Ce({destinations:e,destinationId:t,onPickDestination:n,archives:r,archivesLoading:i,archiveId:a,onPickArchive:o}){let s=e.filter(e=>e.restoreSupported);return b(`div`,{className:`p-4 space-y-3`,children:[b(`div`,{className:`space-y-1.5`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Destination`}),b(`select`,{value:t??``,onChange:e=>n(e.target.value),className:`w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,children:[T(`option`,{value:``,disabled:!0,children:`Select destination…`}),s.map(e=>b(`option`,{value:e.id,children:[e.displayName,` (`,e.kind,`)`]},e.id))]})]}),b(`div`,{className:`space-y-1.5`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Archive`}),!t&&T(`div`,{className:`text-xs text-foreground-subtle italic`,children:`Pick a destination first.`}),t&&i&&T(`div`,{className:`text-xs text-foreground-subtle animate-pulse`,children:`Reading archives…`}),t&&!i&&r.length===0&&T(`div`,{className:`text-xs text-foreground-subtle italic`,children:`No archives available at this destination.`}),t&&r.length>0&&T(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:r.map(e=>{let t=a===e.id;return b(`label`,{className:`flex items-center justify-between px-3 py-2 text-xs cursor-pointer ${t?`bg-primary/10`:`hover:bg-primary/5`}`,children:[b(`div`,{className:`flex items-center gap-2`,children:[T(`input`,{type:`radio`,name:`archive`,checked:t,onChange:()=>o(e.id),className:`accent-primary`}),b(`div`,{children:[T(`div`,{className:`font-medium text-foreground`,children:e.label??e.id}),T(`div`,{className:`text-[10px] text-foreground-subtle`,children:new Date(e.createdAt).toLocaleString()})]})]}),T(`span`,{className:`text-[10px] text-foreground-subtle tabular-nums`,children:U(e.sizeBytes)})]},e.id)})})]})]})}function Z({locations:e,picked:t,onToggle:n}){return e.length===0?T(`div`,{className:`p-4`,children:T(`div`,{className:`text-xs text-foreground-subtle`,children:`Loading archive manifest… If this persists, the archive may predate manifests — restoring will apply everything in the tarball.`})}):b(`div`,{className:`p-4 space-y-3`,children:[T(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-[11px] text-amber-700 dark:text-amber-300`,children:`Selected entries will overwrite live data on the next server restart. Unchecked entries stay current.`}),b(`div`,{className:`space-y-1.5`,children:[T(`label`,{className:`text-[10px] text-foreground-subtle uppercase tracking-wide`,children:`Apply`}),T(`div`,{className:`rounded border border-border bg-background divide-y divide-border max-h-64 overflow-y-auto`,children:e.map(e=>b(`label`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-primary/5 cursor-pointer`,children:[T(`input`,{type:`checkbox`,checked:t.has(e),onChange:()=>n(e),className:`accent-primary`}),T(`span`,{className:`font-mono text-foreground`,children:e}),T(`span`,{className:`ml-auto text-[10px] text-foreground-subtle`,children:Ee(e)})]},e))})]})]})}function we({destinationName:e,archive:t,picked:n}){return b(`div`,{className:`p-4 space-y-3 text-xs`,children:[T(`div`,{className:`rounded border border-amber-500/30 bg-amber-500/10 px-3 py-2 text-amber-700 dark:text-amber-300`,children:`Restore is applied at next server boot. Active connections will drop when you restart.`}),b(`dl`,{className:`space-y-1.5`,children:[T(Q,{term:`Destination`,value:e}),T(Q,{term:`Archive`,value:t?.label??t?.id??`—`}),t&&T(Q,{term:`Created`,value:`${new Date(t.createdAt).toLocaleString()} · ${U(t.sizeBytes)}`}),T(Q,{term:`Locations`,value:n.length>0?n.join(`, `):`— (full archive)`})]})]})}function Q({term:e,value:t}){return b(`div`,{className:`flex justify-between gap-3`,children:[T(`dt`,{className:`text-foreground-subtle`,children:e}),T(`dd`,{className:`text-foreground font-mono text-right truncate`,children:t})]})}var Te={db:`Database`,addons:`Addon configs`,"addons-data":`Addon data`,tls:`TLS certificates`,cache:`Cache`,data:`Top-level data`};function Ee(e){return Te[e]??``}y();function De(){let e=g(),n=t(),[r,i]=w(null),[a,o]=w(!1),[s,c]=w(!1),[l,u]=w(void 0),d=async()=>{await e({title:`Restart server now?`,message:`Active connections will drop and the apply-backup hook will run before boot.`,confirmLabel:`Restart`,variant:`warning`})&&n.mutate({confirm:!0})};return b(H,{children:[b(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[b(`button`,{onClick:()=>o(!0),className:`inline-flex items-center gap-1.5 rounded-lg 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:[T(M,{className:`h-3.5 w-3.5`}),`Restore…`]}),b(`button`,{onClick:()=>u(null),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`,children:[T(j,{className:`h-3.5 w-3.5`}),`New entry`]})]}),s&&T(`div`,{className:`rounded-lg border border-amber-500/30 bg-amber-500/10 px-3 py-2.5 text-xs text-amber-700 dark:text-amber-300`,children:b(`div`,{className:`flex items-center justify-between gap-3`,children:[b(`div`,{className:`flex items-center gap-2`,children:[T(M,{className:`h-3.5 w-3.5`}),T(`span`,{children:`Restore scheduled. Restart the server to apply.`})]}),b(`button`,{onClick:()=>{d()},disabled:n.isPending,className:`inline-flex items-center gap-1.5 rounded bg-amber-500/20 px-2 py-1 font-medium text-amber-800 dark:text-amber-200 hover:bg-amber-500/30 disabled:opacity-50`,children:[n.isPending?T(R,{className:`h-3.5 w-3.5 animate-spin`}):T(M,{className:`h-3.5 w-3.5`}),`Restart Now`]})]})}),T(fe,{onEdit:e=>u(e),onOpenRestoreWizard:e=>i(e)}),l!==void 0&&T(be,{entry:l,onClose:()=>u(void 0),onSaved:()=>u(void 0)}),(r||a)&&T(Se,{...r?{initialDestinationId:r.destinationId,initialArchiveId:r.archiveId}:{},onClose:()=>{i(null),o(!1)},onScheduled:()=>c(!0)})]})}y();var $=5e3,Oe={"winston-logging":`Rotated log files on this node’s disk.`,"console-logging":`stdout / stderr of the node process.`,"loki-logging":`Pushes to a Grafana Loki instance. Off until enabled with a URL.`,"hub-forwarder":`Agent-only — forwards this node’s entries to the hub.`};function ke(){let e=u({capName:`log-destination`},{refetchInterval:$}),t=_(void 0,{refetchInterval:$}),n=x(()=>W(t.data??[]),[t.data]),r=x(()=>{let e=new Map;for(let n of t.data??[]){let t=n.description,r=n.id;typeof r==`string`&&typeof t==`string`&&t.length>0&&e.set(r,t)}return e},[t.data]);return T(ae,{title:`Logging`,subtitle:`Every registered log destination. Entries are fanned to all enabled destinations at once — enabling one does not disable another. Each destination's own configuration is docked under it.`,pageIcon:B,itemIcon:J,capability:`log-destination`,installButtonLabel:`Add destination`,items:x(()=>(e.data??[]).map(e=>({addonId:e.addonId,displayName:n.get(e.addonId)??e.addonId,isActive:e.isActive,caption:r.get(e.addonId)??Oe[e.addonId]??``})),[e.data,n,r]),isLoading:e.isLoading,emptyTitle:`No log destinations registered`,emptyDescription:`This should not happen — the console and rotated-file destinations are builtins. If the list is empty, the node is still booting.`,renderStatusBadges:e=>e.caption.length>0?T(`span`,{className:`text-[10px] text-foreground-subtle`,children:e.caption}):null})}function Ae(){return T(`div`,{className:`flex flex-col p-4`,children:T(ie,{tabs:[{id:`storage`,label:`Storage`,icon:O,content:T(oe,{})},{id:`backup`,label:`Backup`,icon:G,content:T(De,{})},{id:`logging`,label:`Logging`,icon:B,content:T(ke,{})}]})})}export{Ae as DataPage};