@camstack/addon-admin-ui 1.2.438 → 1.2.439

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 (115) hide show
  1. package/dist/assets/{AddonAssetIcon-n8Qr5_Kp.js → AddonAssetIcon-BDSwFXgm.js} +1 -1
  2. package/dist/assets/{Addons-Dtpom4zF.js → Addons-BNdKgh4A.js} +1 -1
  3. package/dist/assets/{AdminPage-D2JwPYR7.js → AdminPage-CgbWYJ_a.js} +1 -1
  4. package/dist/assets/{AdminSectionedPage-5tMwz6Be.js → AdminSectionedPage-Cx5lBMEy.js} +1 -1
  5. package/dist/assets/{AiProfiles-CrkwNINl.js → AiProfiles-Bcw_Zupz.js} +1 -1
  6. package/dist/assets/{BrokerForm-Dbt1v9HX.js → BrokerForm-vhYWxL3G.js} +1 -1
  7. package/dist/assets/{Build-Bv-SRt3z.js → Build-DU8TYYdP.js} +1 -1
  8. package/dist/assets/{Calendars-CPdNc3AH.js → Calendars-nXT3Wrbf.js} +1 -1
  9. package/dist/assets/{Cluster-iOH_2qVx.js → Cluster-i581brrb.js} +1 -1
  10. package/dist/assets/{ClusterStepModel-vvtitbie.js → ClusterStepModel-COT7-UPr.js} +1 -1
  11. package/dist/assets/{CompositionEditor-BP-AGI3Y.js → CompositionEditor-ChpgaVIC.js} +1 -1
  12. package/dist/assets/{CompositionEditorPage-BRatBKGt.js → CompositionEditorPage-ChGD20-A.js} +1 -1
  13. package/dist/assets/{Data-Bk8YwGJK.js → Data-NVQyqefj.js} +1 -1
  14. package/dist/assets/{DeviceDetail-BtiSYWZr.js → DeviceDetail-UQPY3O77.js} +1 -1
  15. package/dist/assets/{DeviceDoActionFields-CBs8E-hd.js → DeviceDoActionFields-B1mTzp5D.js} +1 -1
  16. package/dist/assets/{Devices-Bgd8Iyo4.js → Devices-DNkljEPT.js} +1 -1
  17. package/dist/assets/{EmbedPlayerPage-OppPi2oS.js → EmbedPlayerPage-BPwqAqDS.js} +1 -1
  18. package/dist/assets/{Identity-BlDv0gjH.js → Identity-SFG32MYD.js} +1 -1
  19. package/dist/assets/{IntegrationDetail-CLiGGiDO.js → IntegrationDetail-DOpZe3Ca.js} +1 -1
  20. package/dist/assets/{IntegrationHub-elusTiRh.js → IntegrationHub-DbxSPB_Z.js} +1 -1
  21. package/dist/assets/{Integrations-DlLfaKrk.js → Integrations--ssC4t1F.js} +1 -1
  22. package/dist/assets/{Integrations-BX33zgRF.js → Integrations-6eDOiK1G.js} +1 -1
  23. package/dist/assets/{Library-CGx2d-jp.js → Library-Bi_LuV1_.js} +1 -1
  24. package/dist/assets/{Locations-CFU7VvDI.js → Locations-Cg0m1b4l.js} +1 -1
  25. package/dist/assets/{Logs-BppneNXQ.js → Logs-DQzkH4DL.js} +1 -1
  26. package/dist/assets/{MaskShapeCanvas-Bwqusno0.js → MaskShapeCanvas-B01TLLz0.js} +1 -1
  27. package/dist/assets/{MotionZonesSettings-CZbGV_dv.js → MotionZonesSettings-Ccp-7wRO.js} +1 -1
  28. package/dist/assets/{MyAccess-7TTQLj-6.js → MyAccess-d8Soqp8x.js} +1 -1
  29. package/dist/assets/{Network-D4qKoubf.js → Network-DUXIj2Zk.js} +1 -1
  30. package/dist/assets/{NodeAddonsSettingsPanel-DOLEqwOJ.js → NodeAddonsSettingsPanel-BfK00QUN.js} +1 -1
  31. package/dist/assets/{Notifications--kvb7ubW.js → Notifications-M4WZNbHV.js} +1 -1
  32. package/dist/assets/{PrivacyMaskSettings-CTKUYU5o.js → PrivacyMaskSettings-BnmGNc7h.js} +1 -1
  33. package/dist/assets/{Recordings-C3Ikd7pB.js → Recordings-DalG2LLq.js} +1 -1
  34. package/dist/assets/{ScanNetworkModal-O2KH9u3g.js → ScanNetworkModal-BuYymusi.js} +1 -1
  35. package/dist/assets/{SceneMonitorEditor-CG4pADlP.js → SceneMonitorEditor-COIi86yu.js} +1 -1
  36. package/dist/assets/{SessionsList-DCXslvk3.js → SessionsList-CoUCGhgk.js} +1 -1
  37. package/dist/assets/{Showroom-BXD3terh.js → Showroom-B-HvuRyq.js} +1 -1
  38. package/dist/assets/{System-CHwXBdVd.js → System-D1S9FZIN.js} +1 -1
  39. package/dist/assets/{Terminal-D2WVII9y.js → Terminal-VExSxhFn.js} +1 -1
  40. package/dist/assets/{Viewer-BdY4QQPs.js → Viewer-CNtlq-6t.js} +1 -1
  41. package/dist/assets/{_virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-D8hkm2kB.js → _virtual_mf-localSharedImportMap___mfe_internal__admin_ui_host-B5lRPMSE.js} +1 -1
  42. package/dist/assets/{addon-icons-context-Drfj1y7k.js → addon-icons-context-O3QiZWCa.js} +1 -1
  43. package/dist/assets/{archive-Bcg0gLgY.js → archive-NnMWQRLb.js} +1 -1
  44. package/dist/assets/{authed-media-CFsHrcXx.js → authed-media-B64j5Vsu.js} +1 -1
  45. package/dist/assets/{bell-off-BnByNJjy.js → bell-off-DR6rLD11.js} +1 -1
  46. package/dist/assets/{board-model-D8m2YmcS.js → board-model-CUEDqTvL.js} +1 -1
  47. package/dist/assets/{boxes-V2c7jrxe.js → boxes-B64NRkVe.js} +1 -1
  48. package/dist/assets/circle-slash-CEYz4tuU.js +1 -0
  49. package/dist/assets/client-Ca-96r9I.js +358 -0
  50. package/dist/assets/{cloud-upload-aziKggfg.js → cloud-upload-Ck1AcqSa.js} +1 -1
  51. package/dist/assets/crop-C-IooyeF.js +1 -0
  52. package/dist/assets/{device-integration-icon-Bd49r785.js → device-integration-icon-CdWFmoUD.js} +1 -1
  53. package/dist/assets/device-picker-model-Dep-E57-.js +1 -0
  54. package/dist/assets/dist-BSOkO07t.js +1 -0
  55. package/dist/assets/dist-vJSNSRqs.js +358 -0
  56. package/dist/assets/{eraser-CsYhDDbY.js → eraser-CHm7ildU.js} +1 -1
  57. package/dist/assets/{hard-drive-download-CWqd_JKb.js → hard-drive-download-DVmQAuw3.js} +1 -1
  58. package/dist/assets/{history-DOf9zSG-.js → history-2q2gbNuR.js} +1 -1
  59. package/dist/assets/{hostInit-C_3liyhx.js → hostInit-BJE3f_CH.js} +1 -1
  60. package/dist/assets/i18n-ATfMbes1.js +1 -0
  61. package/dist/assets/{icons-BrAHwVJD.js → icons-DQaWDMUW.js} +1 -1
  62. package/dist/assets/index-CIQcOfrF.js +4 -0
  63. package/dist/assets/{key-D0VHbthb.js → key-N9xPL69Y.js} +1 -1
  64. package/dist/assets/{key-round-CasJ848Z.js → key-round-DetnHyGS.js} +1 -1
  65. package/dist/assets/{layers-CFb4zoU6.js → layers-DdcQNtFW.js} +1 -1
  66. package/dist/assets/{linked-devices-model-B7EZaQcp.js → linked-devices-model-Ca0JeX-b.js} +1 -1
  67. package/dist/assets/{list-ordered-B14sQnH2.js → list-ordered-CG0tknH1.js} +1 -1
  68. package/dist/assets/{location-owned-usage-CEUpeKPu.js → location-owned-usage-CPVIHMbS.js} +1 -1
  69. package/dist/assets/{log-in-UZRiT8Rq.js → log-in-eXylJY9j.js} +1 -1
  70. package/dist/assets/{memory-stick-l6hXPEuG.js → memory-stick-DASwwt0F.js} +1 -1
  71. package/dist/assets/{message-square-plus-C3grB9GT.js → message-square-plus-DqkHZSG8.js} +1 -1
  72. package/dist/assets/{mf-entry-bootstrap-0-aa799d5d.js → mf-entry-bootstrap-0-3bcba670.js} +2 -2
  73. package/dist/assets/{mic-off-wol-RBiS.js → mic-off-Dn3D8U5T.js} +1 -1
  74. package/dist/assets/{monitor-off-BUehkWHc.js → monitor-off-BFFE28-j.js} +1 -1
  75. package/dist/assets/{monitor-smartphone-CCDiXDn-.js → monitor-smartphone-Df6JhoUF.js} +1 -1
  76. package/dist/assets/mount-Dep-E57-.js +1 -0
  77. package/dist/assets/{notification-schedule-field-3QjzRWF0.js → notification-schedule-field-DX8l1Z0c.js} +1 -1
  78. package/dist/assets/{player-overlays-Db_o1Zm2.js → player-overlays-CikRdqm6.js} +1 -1
  79. package/dist/assets/{recycle-BVxTT0po.js → recycle-CeQJmMoH.js} +1 -1
  80. package/dist/assets/remoteEntry-B_6E82lR.js +1 -0
  81. package/dist/assets/{scan-eye-C5EKCLMY.js → scan-eye-uX_isL7a.js} +1 -1
  82. package/dist/assets/{scissors-DjP6Unuk.js → scissors-Bi6HP2Jp.js} +1 -1
  83. package/dist/assets/{search-x-gjRI7PKB.js → search-x-CScyd-pU.js} +1 -1
  84. package/dist/assets/{send-CV6GWVOX.js → send-D2QbbJQk.js} +1 -1
  85. package/dist/assets/{settings-2--KyzHb5N.js → settings-2-CkjM7VHr.js} +1 -1
  86. package/dist/assets/{speaker-CnmwOCLp.js → speaker-C3Z3o0NO.js} +1 -1
  87. package/dist/assets/src-Bt0KiIin.js +67 -0
  88. package/dist/assets/{timer-reset-nORqwwje.js → timer-reset-C_TvCMnb.js} +1 -1
  89. package/dist/assets/{ungroup-BQTGGbbf.js → ungroup-IELE1M3H.js} +1 -1
  90. package/dist/assets/{unlink-669jprEf.js → unlink-CLHtJAsY.js} +1 -1
  91. package/dist/assets/{usb-BT4hzhxS.js → usb-DncvObAi.js} +1 -1
  92. package/dist/assets/{use-scenes-feed-CAUwbJgh.js → use-scenes-feed-BgX1JX4l.js} +1 -1
  93. package/dist/assets/{use-stationary-objects-CwdwiqSu.js → use-stationary-objects-BzSycd9M.js} +1 -1
  94. package/dist/assets/useEventInvalidation-Dep-E57-.js +1 -0
  95. package/dist/assets/{useNodeUrlSelection-2GpIyOt_.js → useNodeUrlSelection-D3zWAXku.js} +1 -1
  96. package/dist/assets/user-round-BCHxFTod.js +1 -0
  97. package/dist/assets/{user-x-Drhirj9Y.js → user-x-B-NhZXl-.js} +1 -1
  98. package/dist/assets/{video-Dzs93Xor.js → video-IXUGebu2.js} +1 -1
  99. package/dist/assets/{virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-CVZRr77d.js → virtual_mf-REMOTE_ENTRY_ID___mfe_internal__admin_ui_host__remoteEntry-_hash_-5Br3X_S3.js} +2 -2
  100. package/dist/index.html +10 -10
  101. package/dist/server/addon.js +83 -3
  102. package/package.json +1 -1
  103. package/dist/assets/circle-slash-B_FzZotu.js +0 -1
  104. package/dist/assets/client-CUuI767h.js +0 -358
  105. package/dist/assets/crop-DzZyuK_f.js +0 -1
  106. package/dist/assets/device-picker-model-BQdOI8yn.js +0 -1
  107. package/dist/assets/dist-DsAwO6-i.js +0 -358
  108. package/dist/assets/dist-t-gGaOd0.js +0 -1
  109. package/dist/assets/i18n-RHwbGLC0.js +0 -1
  110. package/dist/assets/index-DrWxDgY9.js +0 -4
  111. package/dist/assets/mount-BQdOI8yn.js +0 -1
  112. package/dist/assets/remoteEntry-CavKhY-Z.js +0 -1
  113. package/dist/assets/src-BpDNu6in.js +0 -67
  114. package/dist/assets/useEventInvalidation-BQdOI8yn.js +0 -1
  115. package/dist/assets/user-round-NWWWc7PC.js +0 -1
@@ -1 +1 @@
1
- import{$ as e,B as t,G as n,H as r,J as i,L as a,S as o,b as s,o as c,q as l,x as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Ai as d,Br as f,Cn as p,D as m,Fn as h,It as g,Nt as _,Si as v,Xr as y,Zi as b,bn as x,dn as S,dt as C,fn as w,hi as T,kn as E,or as D,ot as O,pi as k,pn as A,si as j,sn as M,vn as N,xi as ee,xn as te,yi as P,zn as F}from"./player-overlays-Db_o1Zm2.js";import{$r as ne,Qr as re,ei as ie,ri as ae}from"./client-CUuI767h.js";import{t as oe}from"./hard-drive-download-CWqd_JKb.js";import{t as se}from"./memory-stick-l6hXPEuG.js";import{t as ce}from"./unlink-669jprEf.js";import{$t as le,An as ue,Bc as de,Bn as I,Cu as L,Dt as fe,Gt as pe,Hc as me,J as he,K as ge,Ks as _e,Kt as ve,M as ye,Mn as be,Nn as xe,On as Se,Ot as Ce,Pn as we,Rs as Te,Uc as Ee,Un as R,Vc as De,Vn as Oe,Wt as ke,Xo as Ae,Yo as je,as as Me,bu as Ne,cc as Pe,cr as Fe,dr as Ie,er as z,fr as Le,is as Re,jn as ze,kn as Be,mr as Ve,ns as He,pr as Ue,qt as We,rs as Ge,ru as B,tc as Ke,ul as qe,va as Je,yu as Ye}from"./src-BpDNu6in.js";import{t as V}from"./i18n-RHwbGLC0.js";import{t as H}from"./useTranslation-D3Is_4B6.js";import{C as Xe,tt as Ze}from"./index-DrWxDgY9.js";import{t as Qe}from"./AdminPage-D2JwPYR7.js";import{t as $e}from"./NodeAddonsSettingsPanel-DOLEqwOJ.js";import{f as et,l as tt,m as nt,u as rt}from"./board-model-D8m2YmcS.js";import{t as U}from"./format-size-DIxKXxtj.js";import{n as it,t as at}from"./useNodeUrlSelection-2GpIyOt_.js";e();var ot={unpaired:`Not paired`,pending:`Pairing…`,paired:`Paired`},st=new Set([`paired`,`rejected`,`failed`,`expired`]);function W(e){return st.has(e)}function ct(e){return e.replace(/\D/g,``).slice(0,6)}function lt(e){return e.length===6}function ut(e,t){let n=Math.max(0,Math.ceil((e-t)/1e3)),r=Math.floor(n/60),i=n%60;return`${r}:${String(i).padStart(2,`0`)}`}function dt(e,t){return e.includes(`:`)?`[${e}]:${t}`:`${e}:${t}`}function ft(e){return e.length<=23?e:`${e.slice(0,20)}…`}function pt({view:e,beginError:t}){if(e===null)return t===null?`sending`:`send-failed`;switch(e.state){case`paired`:return`paired`;case`rejected`:return`rejected`;case`failed`:return`failed`;case`expired`:return`expired`;case`completing`:return`completing`;case`awaiting-confirmation`:return e.hubConfirmed&&!e.agentConfirmed?`awaiting-agent`:e.agentConfirmed&&!e.hubConfirmed?`awaiting-hub`:`awaiting-both`}}function mt(e){return e===`awaiting-both`||e===`awaiting-hub`}var ht={sending:`Sending the pairing offer to the agent…`,"send-failed":`The agent could not be reached`,"awaiting-both":`Waiting for both confirmations`,"awaiting-agent":`Confirmed here — waiting for the agent`,"awaiting-hub":`The agent is confirmed — now confirm here`,completing:`Issuing the node certificate…`,paired:`Paired`,rejected:`Pairing was rejected`,failed:`Pairing failed`,expired:`The pairing expired`},gt=2e3,_t=1e3;function vt(e){return e.message.length>0?e.message:V.t(`pairing.agentsFoundSection.requestFailed`)}function yt(e){return e.length===6?`${e.slice(0,3)} ${e.slice(3)}`:e}function bt(e){let[n,r]=i(()=>Date.now());return t(()=>{if(!e)return;let t=setInterval(()=>r(Date.now()),_t);return()=>clearInterval(t)},[e]),n}function xt({target:e,onClose:n,onSettled:r,onOpenNode:a}){let{t:c}=H(),[d,f]=i(null),[p,m]=i(null),[h,g]=i(``),[_,v]=i(null),y=l(null),b=L.agentPairing.beginPairing.useMutation(),x=L.agentPairing.confirmPairing.useMutation(),S=L.agentPairing.rejectPairing.useMutation();t(()=>{if(e===null){y.current=null,f(null),m(null),g(``),v(null);return}y.current!==e&&(y.current=e,b.mutateAsync({host:e.host,port:e.port}).then(t=>{y.current===e&&f(t.pairingId)}).catch(t=>{y.current===e&&m(vt(t))}))},[e]);let C=L.agentPairing.getPairing.useQuery({pairingId:d??``},{enabled:d!==null,refetchInterval:e=>{let t=e.state.data?.state;return t!==void 0&&W(t)?!1:gt}}),w=St(x.data??S.data??null,C.data??null),T=pt({view:w,beginError:p}),E=w!==null&&W(w.state),O=l(!1);t(()=>{if(!E){O.current=!1;return}O.current||(O.current=!0,r())},[E,r]);let k=bt(w!==null&&!E),A=()=>{d===null||!lt(h)||(v(null),x.mutate({pairingId:d,code:h},{onError:e=>{v(vt(e)),g(``)}}))};return u(Se,{open:e!==null,onOpenChange:e=>!e&&n(),children:o(ue,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[o(xe,{children:[u(we,{children:c(`pairing.pairingDialog.title`,{node:e?.nodeId??``})}),u(ze,{children:e===null?``:c(`pairing.pairingDialog.eachScreenShowsACode`,`Each screen shows a code; you type the code from the OTHER screen. Agent at {{value1}}`,{value1:dt(e.host,e.port)})})]}),o(Be,{className:`space-y-4`,children:[u(Ct,{phase:T}),T===`send-failed`&&p!==null&&u(I,{title:c(`pairing.pairingDialog.couldNotStartThePairing`,`Could not start the pairing`),message:p}),w!==null&&!E&&u(wt,{view:w,phase:T,now:k,typed:h,onType:e=>g(ct(e)),onSubmit:A,confirmError:_,busy:x.isPending}),T===`paired`&&w!==null&&u(Tt,{nodeId:w.nodeId,onOpenNode:a,onClose:n}),E&&T!==`paired`&&w?.failure!=null&&u(I,{message:w.failure})]}),u(be,{children:E||T===`send-failed`?u(R,{type:`button`,variant:`outline`,onClick:n,children:c(`common.close`,`Close`)}):o(s,{children:[u(R,{type:`button`,variant:`outline`,disabled:S.isPending,onClick:()=>{if(d===null){n();return}S.mutate({pairingId:d},{onSettled:n})},children:c(`pairing.pairingDialog.reject`,`Reject`)}),mt(T)&&o(R,{type:`button`,disabled:!lt(h)||x.isPending,onClick:A,children:[x.isPending&&u(D,{className:`h-4 w-4 animate-spin`}),c(`common.confirm`,`Confirm`)]})]})})]})})}function St(e,t){if(t===null)return e;if(e===null)return t;let n=e=>(W(e.state)?10:e.state===`completing`?5:0)+ +!!e.hubConfirmed+ +!!e.agentConfirmed;return n(e)>n(t)?e:t}function Ct({phase:e}){let t=e===`sending`||e===`completing`,n=e===`paired`,r=e===`rejected`||e===`failed`||e===`expired`||e===`send-failed`;return o(`p`,{role:`status`,className:`flex items-center gap-2 text-sm font-medium ${n?`text-success`:r?`text-danger`:`text-foreground`}`,children:[t&&u(D,{className:`h-4 w-4 animate-spin`}),n&&u(k,{className:`h-4 w-4`}),r&&u(j,{className:`h-4 w-4`}),ht[e]]})}function wt({view:e,phase:t,now:n,typed:r,onType:i,onSubmit:a,confirmError:s,busy:c}){let{t:l}=H();return o(`div`,{className:`space-y-4`,children:[o(`section`,{"aria-label":l(`pairing.pairingDialog.codeOnThisHub`,`Code on this hub`),className:`rounded-md border border-border bg-surface p-3`,children:[u(`p`,{className:`text-xs text-foreground-muted`,children:l(`pairing.pairingDialog.codeOnThisHubRead`,`Code on this hub — read it out to the agent`)}),u(`p`,{"data-testid":`hub-code`,className:`mt-1 font-mono text-3xl font-semibold tracking-widest text-foreground`,children:yt(e.code)}),u(`p`,{className:`mt-2 text-xs text-foreground-muted`,children:l(`pairing.pairingDialog.onTheAgentEnterThis`,`On the agent, enter this code and the agent’s local PIN (shown on the agent’s console or log, or on its own screen).`)})]}),mt(t)?u(`form`,{className:`space-y-2`,onSubmit:e=>{e.preventDefault(),a()},children:u(he,{label:l(`pairing.pairingDialog.codeShownOnTheAgent`,`Code shown on the agent`),description:l(`pairing.pairingDialog.typeTheSixDigitsThe`,`Type the six digits the agent displays. Do not copy the code above.`),...s===null?{}:{error:s},children:u(B,{value:r,onChange:e=>i(e.target.value),inputMode:`numeric`,autoComplete:`off`,spellCheck:!1,placeholder:`000000`,maxLength:6,disabled:c,"aria-label":l(`pairing.pairingDialog.codeShownOnTheAgent`,`Code shown on the agent`),className:`font-mono tracking-widest`})})}):u(`p`,{className:`text-xs text-foreground-muted`,children:t===`awaiting-agent`?l(`pairing.pairingDialog.youConfirmedHereTheAgent`,`You confirmed here. The agent still has to enter the hub code and its PIN.`):l(`pairing.pairingDialog.working`,`Working…`)}),o(`ul`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-xs text-foreground-muted`,children:[u(`li`,{children:e.hubConfirmed?l(`pairing.pairingDialog.hubConfirmed`,`Hub: confirmed`):l(`pairing.pairingDialog.hubNotConfirmed`,`Hub: not confirmed`)}),u(`li`,{children:e.agentConfirmed?l(`pairing.pairingDialog.agentConfirmed`,`Agent: confirmed`):l(`pairing.pairingDialog.agentNotConfirmed`,`Agent: not confirmed`)}),u(`li`,{"data-testid":`countdown`,children:l(`pairing.pairingDialog.expiresIn`,{countdown:ut(e.expiresAt,n)})})]})]})}function Tt({nodeId:e,onOpenNode:t,onClose:n}){let{t:r}=H(),{nodes:i}=Ye(),a=i?.some(t=>t.id===e&&t.isOnline)===!0;return o(`div`,{className:`space-y-2 rounded-md border border-success/40 bg-success/10 p-3 text-sm`,children:[o(`p`,{className:`flex items-center gap-2 text-success`,children:[u(M,{className:`h-4 w-4`}),a?r(`pairing.pairingDialog.joinedAndRegisteredItsCapabilities`,`{{nodeId}} joined and registered its capabilities.`,{nodeId:e}):r(`pairing.pairingDialog.holdsItsCertificateWaitingFor`,`{{nodeId}} holds its certificate. Waiting for it to connect and register its capabilities…`,{nodeId:e})]}),u(R,{type:`button`,size:`sm`,variant:`outline`,disabled:!a,onClick:()=>{n(),t(e)},children:r(`pairing.pairingDialog.openNode`,`Open node`)})]})}var Et={paired:`success`,pending:`warning`,unpaired:`default`};function Dt({state:e,connected:t}){let{t:n}=H();return o(`span`,{className:`inline-flex items-center gap-1.5`,children:[u(Fe,{variant:Et[e],className:`text-[10px]`,children:ot[e]}),e===`paired`&&u(`span`,{className:`text-[10px] text-foreground-muted`,children:t?n(`common.connected`):n(`pairing.agentStateBadge.notConnected`,`not connected`)})]})}e();var G={pending:0,unpaired:1,paired:2};function Ot(e){if(e.trim().length===0)return;let t=Number(e);return Number.isInteger(t)&&t>=1&&t<=65535?t:null}function kt({onOpenNode:e}){let{t}=H(),r=z(),a=L.useUtils(),c=L.agentPairing.listDiscoveredAgents.useQuery(void 0,{refetchInterval:15e3}),[l,d]=i(null),[f,h]=i(null),[g,_]=i(!1),[v,y]=i(``),[b,S]=i(``),[C,w]=i(null),[T,O]=i(!1),k=()=>void a.agentPairing.listDiscoveredAgents.invalidate(),A=L.agentPairing.addAgentByAddress.useMutation({onSuccess:()=>{_(!1),y(``),S(``),w(null),k()},onError:e=>w(e.message)}),j=L.agentPairing.unpairAgent.useMutation({onSuccess:e=>{h({tone:`success`,message:`${e.nodeId}: ${e.next}${e.agentNotified?``:` The agent could not be told; forget the hub on its own page.`}`}),k()},onError:e=>h({tone:`danger`,message:t(`pairing.agentsFoundSection.unpairFailed`,`Unpair failed: {{message}}`,{message:e.message})})}),M=n(()=>(c.data?.agents??[]).toSorted((e,t)=>G[e.state]-G[t.state]),[c.data]),N=async()=>{O(!0);try{await a.agentPairing.listDiscoveredAgents.fetch({refresh:!0}),k()}finally{O(!1)}},ee=()=>{let e=Ot(b);if(e===null){w(`The port must be a whole number between 1 and 65535.`);return}w(null),A.mutate({host:v.trim(),...e===void 0?{}:{port:e}})},te=async e=>{await r({title:t(`pairing.agentsFoundSection.unpair`,`Unpair {{nodeId}}`,{nodeId:e.nodeId}),message:t(`pairing.agentsFoundSection.sCertificatesAreRevokedAt`,`{{nodeId}}'s certificates are revoked at once and it is disconnected from the mesh. It must be paired again before it can rejoin.`,{nodeId:e.nodeId}),confirmLabel:t(`pairing.agentsFoundSection.unpair2`,`Unpair`),variant:`danger`})&&(h(null),j.mutate({nodeId:e.nodeId}))},P=n(()=>[{key:`node`,header:t(`pairing.agentsFoundSection.node`,`Node`),render:e=>u(`span`,{className:`font-medium text-foreground`,children:e.nodeId}),sortValue:e=>e.nodeId},{key:`address`,header:t(`pairing.agentsFoundSection.address`,`Address`),render:e=>u(`span`,{className:`font-mono text-xs`,children:dt(e.host,e.port)}),sortValue:e=>e.host},{key:`version`,header:t(`pairing.agentsFoundSection.version`,`Version`),render:e=>e.version??`—`,sortValue:e=>e.version},{key:`state`,header:t(`pairing.agentsFoundSection.state`,`State`),render:e=>u(Dt,{state:e.state,connected:e.connected}),sortValue:e=>G[e.state]},{key:`fingerprint`,header:t(`pairing.agentsFoundSection.certificate`,`Certificate`),render:e=>e.fingerprint===null?`—`:u(`span`,{className:`font-mono text-xs`,title:e.fingerprint,children:ft(e.fingerprint)}),sortValue:e=>e.fingerprint},{key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,render:e=>e.state===`unpaired`?u(R,{type:`button`,size:`sm`,onClick:()=>d({nodeId:e.nodeId,host:e.host,port:e.port}),children:t(`pairing.agentsFoundSection.pair`,`Pair`)}):e.state===`paired`?u(R,{type:`button`,size:`sm`,variant:`outline`,disabled:j.isPending,onClick:()=>void te(e),children:t(`pairing.agentsFoundSection.unpair2`,`Unpair`)}):null}],[j.isPending,t]);return o(ke,{headingId:`agents-found`,title:t(`pairing.agentsFoundSection.agentsFoundOnTheNetwork`,`Agents found on the network`),icon:p,testId:`agents-found`,actions:o(s,{children:[o(R,{type:`button`,size:`sm`,variant:`outline`,disabled:T,onClick:()=>void N(),children:[T?u(D,{className:`h-3.5 w-3.5 animate-spin`}):u(x,{className:`h-3.5 w-3.5`}),t(`pairing.agentsFoundSection.scan`,`Scan`)]}),o(R,{type:`button`,size:`sm`,onClick:()=>_(e=>!e),children:[u(E,{className:`h-3.5 w-3.5`}),t(`pairing.agentsFoundSection.addByAddress`,`Add by address`)]})]}),children:[o(`div`,{className:`${m} space-y-3`,children:[u(`p`,{className:`text-[11px] leading-relaxed text-foreground-muted`,children:t(`pairing.agentsFoundSection.anAgentHoldsNoSecret`,`An agent holds no secret: pairing issues it a certificate after you confirm the same six digits on this page and on the agent. Discovery needs the agent on its own IP or host networking; a Docker bridge hides it — add it by address.`)}),g&&o(`form`,{"aria-label":t(`pairing.agentsFoundSection.addAgentByAddress`,`Add agent by address`),className:`flex flex-wrap items-start gap-2`,onSubmit:e=>{e.preventDefault(),v.trim().length>0&&!A.isPending&&ee()},children:[u(he,{label:t(`pairing.agentsFoundSection.address`,`Address`),description:t(`pairing.agentsFoundSection.aPrivateOrLocalAddress`,`A private or local address only.`),...C===null?{}:{error:C},children:u(B,{value:v,onChange:e=>y(e.target.value),placeholder:`192.168.1.50`,"aria-label":t(`pairing.agentsFoundSection.agentAddress`,`Agent address`),autoComplete:`off`})}),u(he,{label:t(`pairing.agentsFoundSection.port`,`Port`),description:t(`pairing.agentsFoundSection.optional`,`Optional.`),children:u(B,{value:b,onChange:e=>S(e.target.value),placeholder:`4444`,inputMode:`numeric`,"aria-label":t(`pairing.agentsFoundSection.agentPort`,`Agent port`),className:`w-24`})}),o(R,{type:`submit`,size:`sm`,className:`mt-5`,disabled:v.trim().length===0||A.isPending,children:[A.isPending&&u(D,{className:`h-3.5 w-3.5 animate-spin`}),t(`common.add`,`Add`)]})]}),f!==null&&u(`p`,{role:`status`,className:`rounded border px-3 py-2 text-xs ${f.tone===`success`?`border-success/30 text-foreground`:`border-danger/40 text-danger`}`,children:f.message}),c.isError?u(I,{title:t(`pairing.agentsFoundSection.couldNotListAgents`,`Could not list agents`),message:c.error?.message??t(`pairing.agentsFoundSection.requestFailed`,`Request failed`),onRetry:k}):c.isLoading?u(`p`,{className:`py-4 text-center text-xs text-foreground-muted`,children:t(`pairing.agentsFoundSection.lookingForAgents`,`Looking for agents…`)}):M.length===0?u(Oe,{icon:p,title:t(`pairing.agentsFoundSection.noAgentsFound`,`No agents found`),description:t(`pairing.agentsFoundSection.nothingIsAdvertisingOnThis`,`Nothing is advertising on this network. Start the agent on its own IP (or host networking), or add it by address.`)}):u(ve,{columns:P,rows:M,rowKey:e=>e.nodeId,minWidthPx:720,defaultSort:{columnKey:`state`,dir:`asc`}})]}),u(xt,{target:l,onClose:()=>d(null),onSettled:k,onOpenNode:e})]})}function At(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function jt(e){if(!At(e))return null;let t=e.ticket;if(typeof t!=`string`||t.length===0)return null;let n=e.dashboardUrl;return typeof n==`string`&&n.length>0?{ticket:t,dashboardUrl:n}:{ticket:t}}function Mt(e){let t=e.trim();return!(t.length===0||t.includes(`/`)||t.includes(`?`)||t.includes(`#`)||t.includes(`@`)||t.includes(`:`))}function K(e){return e.startsWith(`172.17.`)}function Nt(e){let t=/^100\.(\d+)\./.exec(e);if(t===null)return!1;let n=Number(t[1]);return n>=64&&n<=127}function Pt(e){if(e.startsWith(`10.`)||e.startsWith(`192.168.`))return!0;let t=/^172\.(\d+)\./.exec(e);if(t===null)return!1;let n=Number(t[1]);return n>=16&&n<=31&&!K(e)}function Ft(e,t){if(typeof t==`string`&&Mt(t))return t.trim();let n=e.filter(e=>!e.includes(`:`)),r=n.find(e=>!e.startsWith(`127.`)&&!e.startsWith(`169.254.`)&&!K(e)&&!Nt(e)&&Pt(e));if(r!==void 0)return r;for(let e of n)if(!e.startsWith(`127.`)&&!e.startsWith(`169.254.`)&&!K(e))return e;return null}function It(e){return`http://${e}:4444/`}function Lt(e,t){let n=new URL(It(e));return n.searchParams.set(`ticket`,t),n.toString()}function Rt(){return window.open(`about:blank`,`_blank`)}function zt(e,t){return e===null||e.closed?!1:(e.location.href=t,!0)}function Bt({node:e}){let{info:t}=Xe();return!e.isHub||t===null?u(`span`,{className:`text-sm font-semibold shrink-0`,children:e.name}):o(s,{children:[u(`span`,{className:`text-sm font-semibold shrink-0`,"data-testid":`node-title-name`,children:t.name}),t.name!==e.id&&u(`span`,{className:`text-xs text-foreground-subtle shrink-0`,"data-testid":`node-title-id`,children:e.id})]})}e();function Vt(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 Ht(e){return e===`running`?`running`:e===`crashed`||e===`failed`?`error`:`stopped`}var Ut=[`trace`,`debug`,`info`,`warn`,`error`];function Wt({proc:e,nodeId:t,defaultExpanded:n,activePanel:r,onTogglePanel:a}){let{t:s}=H(),c=e.services??[],l=c.length===1,[f,p]=i(l||n),[m,h]=i(null),[g,_]=i(`info`),v=e.name.includes(`(core)`),y=Ge(),b=Re(),x=Me(),C=async e=>{h(e);try{await y.mutateAsync({nodeId:t,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{h(null)}},w=async()=>{h(e.name);try{await b.mutateAsync({nodeId:t,processName:e.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{h(null)}},T=async n=>{let r=`${t}/${e.name}`;try{await x.mutateAsync({nodeId:r,level:n}),_(n)}catch(e){console.error(`Failed to set log level:`,e)}};return o(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[o(`div`,{role:l?void 0:`button`,tabIndex:l?void 0:0,onClick:l?void 0:()=>p(!f),onKeyDown:l?void 0:e=>{(e.key===`Enter`||e.key===` `)&&p(!f)},className:`flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${l?``:`hover:bg-muted/40 cursor-pointer`}`,children:[l?u(`span`,{className:`h-3 w-3 shrink-0`}):u(f?ee:P,{className:`h-3 w-3 text-muted-foreground shrink-0`}),v?u(S,{className:`h-3.5 w-3.5 text-primary shrink-0`}):u(d,{className:`h-3.5 w-3.5 text-warning shrink-0`}),u(`span`,{className:`text-xs font-semibold min-w-0 flex-1 basis-full truncate sm:basis-auto`,children:e.name}),o(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0`,children:[`PID `,e.pid]}),u(ye,{status:Ht(e.state),label:e.state}),u(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0`,children:s(`cluster.forksTab.cpu`,{percent:e.cpuPercent})}),u(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0`,children:U(e.memoryRss)}),u(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0`,children:Vt(e.uptimeSeconds)}),!v&&o(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[o(Ie,{children:[u(Ve,{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:s(`cluster.forksTab.setLogLevel`,`Set log level`),children:g}),u(Le,{align:`end`,className:`min-w-[70px] py-0.5`,children:Ut.map(e=>u(Ue,{onClick:()=>T(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===g?`text-primary font-semibold`:``}`,children:e},e))})]}),u(`button`,{onClick:w,disabled:m===e.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:s(`cluster.forksTab.restartProcess`,`Restart process`),children:u(N,{className:`h-3 w-3 ${m===e.name?`animate-spin`:``}`})})]})]}),f&&c.length>0&&u(`div`,{className:`divide-y divide-border/30`,children:c.map(e=>o(`div`,{children:[o(`div`,{className:`flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors`,children:[u(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`running`?`bg-success`:`bg-muted-foreground/30`}`}),u(`span`,{className:`text-xs font-medium flex-1 min-w-0 truncate`,children:e.addonId}),e.capabilities.length>0&&o(`div`,{className:`flex gap-1 flex-shrink-0`,children:[e.capabilities.slice(0,3).map(e=>u(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-info/10 text-info truncate max-w-[80px]`,children:e},e)),e.capabilities.length>3&&o(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,e.capabilities.length-3]})]}),o(`div`,{className:`flex items-center gap-1 shrink-0`,children:[u(`button`,{onClick:()=>a(e.addonId,`logs`),className:`p-0.5 rounded transition-colors ${r?.addonId===e.addonId&&r.type===`logs`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:s(`cluster.forksTab.showLogsFor`,`Show logs for {{addonId}}`,{addonId:e.addonId}),children:u(A,{className:`h-3 w-3`})}),u(`button`,{onClick:()=>a(e.addonId,`events`),className:`p-0.5 rounded transition-colors ${r?.addonId===e.addonId&&r.type===`events`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:s(`cluster.forksTab.showEventsFor`,`Show events for {{addonId}}`,{addonId:e.addonId}),children:u(te,{className:`h-3 w-3`})}),u(`button`,{onClick:()=>C(e.addonId),disabled:m===e.addonId,className:`p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:s(`cluster.forksTab.restart`,`Restart {{addonId}}`,{addonId:e.addonId}),children:u(N,{className:`h-3 w-3 ${m===e.addonId?`animate-spin`:``}`})})]})]}),r?.addonId===e.addonId&&r.type===`logs`&&u(`div`,{className:`border-t border-border/40 bg-muted/5`,children:u(Ce,{addonId:e.addonId,agentId:t,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>a(e.addonId,`logs`)})}),r?.addonId===e.addonId&&r.type===`events`&&u(`div`,{className:`border-t border-border/40 bg-muted/5`,children:u(fe,{addonId:e.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>a(e.addonId,`events`)})})]},e.addonId))}),f&&c.length===0&&u(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:s(`cluster.forksTab.noServices`,`No services`)})]})}function Gt({nodeId:e,processes:t}){let{t:n}=H(),[r,a]=i(null),o=(e,t)=>{a(n=>n?.addonId===e&&n.type===t?null:{addonId:e,type:t})};return t.length===0?u(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:n(`cluster.forksTab.noProcessesOnThisNode`,`No processes on this node`)}):u(`div`,{className:`space-y-2 py-1`,children:t.map((t,n)=>u(Wt,{proc:t,nodeId:e,defaultExpanded:n===0,activePanel:r,onTogglePanel:o},t.name))})}var Kt={system:0,managed:1,root:2};e();function qt(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 Jt(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function Yt({nodeId:e}){let{t}=H(),r=c(),i=Ne(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:a}=Ae({nodeId:e}),s=i?.processes??a,l=n(()=>s?[...s]:[],[s]),d=n(()=>[{key:`classification`,header:t(`cluster.processesTab.class`,`Class`),sortValue:e=>Kt[e.classification],render:e=>u(`span`,{className:`inline-block rounded-full px-1.5 py-0.5 text-[10px] font-medium ${e.classification===`root`?`bg-info/20 text-info`:e.classification===`system`?`bg-foreground-subtle/20 text-foreground-subtle`:`bg-success/20 text-success`}`,children:e.classification})},{key:`pid`,header:`PID`,align:`right`,sortValue:e=>e.pid,render:e=>u(`span`,{className:`font-mono`,children:e.pid})},{key:`ppid`,header:`PPID`,align:`right`,sortValue:e=>e.ppid,render:e=>u(`span`,{className:`font-mono text-foreground-subtle`,children:e.ppid})},{key:`addonId`,header:t(`cluster.processesTab.addon`,`Addon`),sortValue:e=>e.addonId,render:e=>u(`span`,{className:`text-foreground-subtle text-[11px]`,children:e.addonId??`—`})},{key:`command`,header:t(`cluster.processesTab.command`,`Command`),nowrap:!1,render:e=>u(`span`,{className:`font-mono text-[10px] text-foreground-subtle break-all`,children:Jt(e.command)})},{key:`cpuPercent`,header:t(`cluster.processesTab.cpu`,`CPU%`),align:`right`,sortValue:e=>e.cpuPercent,render:e=>e.cpuPercent.toFixed(1)},{key:`memoryRssBytes`,header:`RSS`,align:`right`,sortValue:e=>e.memoryRssBytes,render:e=>U(e.memoryRssBytes)},{key:`uptimeSec`,header:t(`cluster.processesTab.uptime`,`Uptime`),align:`right`,sortValue:e=>e.uptimeSec,render:e=>u(`span`,{className:`text-foreground-subtle`,children:qt(e.uptimeSec)})}],[t]);return o(`div`,{className:`space-y-4`,children:[u(`div`,{className:`flex items-start justify-end gap-4`,children:o(`button`,{type:`button`,onClick:()=>r.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:[u(x,{className:`h-3 w-3`}),` `,t(`common.refresh`)]})}),u(ve,{columns:d,rows:l,rowKey:e=>e.pid,minWidthPx:880,maxBodyHeight:We,emptyMessage:t(`cluster.processesTab.scanning`,`Scanning…`)})]})}var q={width:320,height:64},Xt=.8,J=Math.ceil(8*Xt-3)+1,Y=q.width+34,Zt=q.height+J+1+11,Qt=J+q.height+1+3+Math.ceil(8*Xt),$t=[1,2,5,10],en=[1,2,4,8,16,32,64,128,256,512,1024],tn=[1,1.5,2,2.5,3,4,5],nn=[4,3,5,2],rn=1e-9;function an(e,t){if(!Number.isFinite(e)||e<=0)return!1;if(t===`bytes`){if(!Number.isInteger(e))return!1;let t=e/1024**Math.floor(Math.log(e)/Math.log(1024));return tn.some(e=>Math.abs(t-e)<rn)}let n=e/10**Math.floor(Math.log10(e));return tn.some(e=>Math.abs(n-e)<rn)}function on(e,t,n){let r=0;for(let t of e)t!==null&&t>r&&(r=t);if(r<=t)return t;if(n===`bytes`){let e=1024**Math.floor(Math.log(r)/Math.log(1024));for(let t of en){let n=t*e;if(n>=r)return n}return 1024*e}let i=10**Math.floor(Math.log10(r));for(let e of $t){let t=e*i;if(t>=r)return t}return 10*i}function sn(e,t){if(!Number.isFinite(e)||e<=0)return[];let n=nn.find(n=>an(e/n,t))??nn[nn.length-1],r=e/n,i=[];for(let e=1;e<=n;e++)i.push(r*e);return i}var cn=2.5;function ln(e){return e*cn}function un(e,t,n,r){if(e.length===0)return[];let i=e[0].atMs,a=e.at(-1).atMs-i,o=n<=0?1:n,s=r!==void 0&&r>0?r:null;return e.map((r,c)=>{let l=a>0?(r.atMs-i)/a*t.width:c/Math.max(1,e.length-1)*t.width,u=c>0?e[c-1]:void 0;return{x:l,y:r.value===null?null:t.height-Math.min(r.value,n)/o*t.height,gapBefore:s!==null&&u!==void 0&&r.atMs-u.atMs>s}})}function dn(e){let t=[],n=!1;for(let r of e){if(r.y===null){n=!1;continue}r.gapBefore&&(n=!1),t.push(`${n?`L`:`M`}${r.x.toFixed(1)},${r.y.toFixed(1)}`),n=!0}return t.join(` `)}function fn(e,t){let n=[],r=[],i=()=>{if(r.length<2){r=[];return}let e=r.map((e,t)=>`${t===0?`M`:`L`}${e.x.toFixed(1)},${e.top.toFixed(1)}`),t=[...r].reverse().map(e=>`L${e.x.toFixed(1)},${e.bottom.toFixed(1)}`);n.push(`${e.join(` `)} ${t.join(` `)} Z`),r=[]};for(let n=0;n<e.length;n++){let a=e[n],o=t[n];if(!a||!o||a.y===null||o.y===null){i();continue}(a.gapBefore||o.gapBefore)&&i(),r.push({x:a.x,top:a.y,bottom:o.y})}return i(),n.join(` `)}function pn(e,t,n=3){if(e.length<2||n<2)return[];let r=e[0].atMs,i=e.at(-1).atMs-r;if(i<=0)return[];let a=[];for(let e=0;e<n;e++){let o=e/(n-1);a.push({atMs:r+i*o,x:o*t.width,anchor:e===0?`start`:e===n-1?`end`:`middle`})}return a}function mn(e){return e.length<2?0:Math.max(0,e.at(-1).atMs-e[0].atMs)}function hn(e){let t=[];for(let n=1;n<e.length;n++){let r=e[n];r.gapBefore&&t.push({fromX:e[n-1].x,toX:r.x})}return t}function gn(e,t){if(e.length===0)return null;let n=0,r=1/0;for(let i=0;i<e.length;i++){let a=Math.abs(e[i].x-t);a<r&&(r=a,n=i)}return n}e();var X={main:`var(--color-chart-series-a)`,gc:`var(--color-chart-series-b)`},Z=q,_n={height:Zt};function vn({title:e,points:t,mainLabel:a,gcLabel:c,formatValue:d,emptyMessage:f,gapMs:p}){let{t:m}=H(),h=r(),g=l(null),[_,v]=i(null),y=n(()=>{let e=t.map(e=>({atMs:e.atMs,value:e.main===null||e.gc===null?null:e.main+e.gc})),n=t.map(e=>({atMs:e.atMs,value:e.main})),r=on(e.map(e=>e.value),25,`linear`),i=un(e,Z,r,p),a=un(n,Z,r,p),o=a.map(e=>({x:e.x,y:e.y===null?null:Z.height,gapBefore:e.gapBefore}));return{max:r,ticks:sn(r,`linear`),upper:i,middle:a,base:o,gaps:hn(i),times:pn(e,Z),spanMs:mn(e)}},[t,p]),b=t.at(-1),x=_===null?void 0:t[_.index],S=x??b;return t.length===0||y.upper.every(e=>e.y===null)?u(Q,{title:e,children:u(An,{message:f})}):u(Q,{title:e,legend:o(s,{children:[u(On,{color:X.main,label:a}),u(On,{color:X.gc,label:c})]}),readout:S&&S.main!==null&&S.gc!==null?o(s,{children:[x!==void 0&&u(Dn,{atMs:x.atMs,spanMs:y.spanMs}),u(kn,{color:X.main,text:d(S.main)}),u(kn,{color:X.gc,text:d(S.gc)})]}):null,children:o(`svg`,{ref:g,viewBox:`0 0 ${Y} ${Zt}`,preserveAspectRatio:`none`,className:`w-full`,style:_n,role:`img`,"aria-label":m(`load.loadChart.andOverTime`,`{{title}}: {{mainLabel}} and {{gcLabel}} over time`,{title:e,mainLabel:a,gcLabel:c}),onMouseLeave:()=>v(null),onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();if(t.width===0)return;let n=(e.clientX-t.left)/t.width*Y-34,r=gn(y.upper,n);r!==null&&v({index:r,xPx:y.upper[r].x})},children:[u(bn,{ticks:y.ticks,max:y.max,formatValue:d}),u(En,{ticks:y.times,spanMs:y.spanMs}),o(`g`,{transform:`translate(34,${J})`,clipPath:`url(#${h})`,children:[u(`clipPath`,{id:h,children:u(`rect`,{x:0,y:0,width:Z.width,height:Z.height})}),u(xn,{spans:y.gaps}),u(`path`,{d:fn(y.middle,y.base),fill:X.main,fillOpacity:.85}),u(`path`,{d:fn(y.upper,y.middle),fill:X.gc,fillOpacity:.85,stroke:`var(--color-surface, transparent)`,strokeWidth:2}),u(`path`,{d:dn(y.upper),fill:`none`,stroke:X.gc,strokeWidth:2}),_!==null&&u(`line`,{x1:_.xPx,x2:_.xPx,y1:0,y2:Z.height,stroke:`currentColor`,strokeWidth:1,className:`text-foreground-subtle`})]})]})})}function yn({title:e,points:t,formatValue:r,emptyMessage:a,axisFloor:c,axisScale:d=`linear`,gapMs:f}){let p=l(null),[m,h]=i(null),g=n(()=>{let e=on(t.map(e=>e.value),c,d),n=un(t,Z,e,f);return{max:e,ticks:sn(e,d),projected:n,gaps:hn(n),times:pn(t,Z),spanMs:mn(t)}},[t,c,d,f]),_=m===null?void 0:t[m.index],v=_??t.at(-1)??void 0;return t.length===0||g.projected.every(e=>e.y===null)?u(Q,{title:e,children:u(An,{message:a})}):u(Q,{title:e,readout:v&&v.value!==null?o(s,{children:[_!==void 0&&u(Dn,{atMs:_.atMs,spanMs:g.spanMs}),u(kn,{color:X.main,text:r(v.value)})]}):null,children:o(`svg`,{ref:p,viewBox:`0 0 ${Y} ${Zt}`,preserveAspectRatio:`none`,className:`w-full`,style:_n,role:`img`,"aria-label":e,onMouseLeave:()=>h(null),onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();if(t.width===0)return;let n=(e.clientX-t.left)/t.width*Y-34,r=gn(g.projected,n);r!==null&&h({index:r,xPx:g.projected[r].x})},children:[u(bn,{ticks:g.ticks,max:g.max,formatValue:r}),u(En,{ticks:g.times,spanMs:g.spanMs}),o(`g`,{transform:`translate(34,${J})`,children:[u(xn,{spans:g.gaps}),u(`path`,{d:dn(g.projected),fill:`none`,stroke:X.main,strokeWidth:2}),m!==null&&u(`line`,{x1:m.xPx,x2:m.xPx,y1:0,y2:Z.height,stroke:`currentColor`,strokeWidth:1,className:`text-foreground-subtle`})]})]})})}function bn({ticks:e,max:t,formatValue:n}){let r=t<=0?1:t;return u(`g`,{className:`text-foreground-subtle`,children:e.map(e=>{let t=J+Z.height-e/r*Z.height;return o(`g`,{children:[u(`line`,{x1:34,x2:34+Z.width,y1:t,y2:t,stroke:`currentColor`,strokeWidth:.5,strokeOpacity:.3}),u(`text`,{x:0,y:t+3,fontSize:8,fill:`currentColor`,children:n(e)})]},e)})})}function xn({spans:e}){let{t}=H();return e.length===0?null:u(`g`,{className:`text-foreground-subtle`,children:e.map(e=>u(`rect`,{x:e.fromX,y:0,width:Math.max(1,e.toX-e.fromX),height:Z.height,fill:`currentColor`,fillOpacity:.12,children:u(`title`,{children:t(`load.loadChart.noSamplesInThisInterval`,`No samples in this interval — nothing was measured, nothing is drawn.`)})},`${e.fromX}-${e.toX}`))})}var Sn=10*6e4,Cn={hour:`2-digit`,minute:`2-digit`},wn={hour:`2-digit`,minute:`2-digit`,second:`2-digit`};function Tn(e,t){return new Date(e).toLocaleTimeString(void 0,t<Sn?wn:Cn)}function En({ticks:e,spanMs:t}){return e.length===0?null:u(`g`,{className:`text-foreground-subtle`,children:e.map(e=>u(`text`,{x:34+e.x,y:Qt,fontSize:8,textAnchor:e.anchor,fill:`currentColor`,children:Tn(e.atMs,t)},e.atMs))})}function Dn({atMs:e,spanMs:t}){return u(`span`,{className:`text-[10px] tabular-nums text-foreground-subtle`,children:Tn(e,t)})}function Q({title:e,legend:t,readout:n,children:r}){return o(`div`,{className:`min-w-0`,children:[o(`div`,{className:`flex items-baseline justify-between gap-2 mb-1`,children:[u(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:e}),u(`div`,{className:`flex items-center gap-2`,children:n})]}),r,t&&u(`div`,{className:`flex items-center gap-3 mt-1`,children:t})]})}function On({color:e,label:t}){return o(`span`,{className:`inline-flex items-center gap-1 text-[9px] text-foreground-subtle`,children:[u(`span`,{className:`inline-block h-2 w-2 rounded-[2px]`,style:{backgroundColor:e}}),t]})}function kn({color:e,text:t}){return o(`span`,{className:`inline-flex items-center gap-1 text-[11px] tabular-nums text-foreground`,children:[u(`span`,{className:`inline-block h-2 w-2 rounded-[2px]`,style:{backgroundColor:e}}),t]})}function An({message:e}){return u(`div`,{className:`h-16 flex items-center justify-center rounded border border-dashed border-border text-[10px] text-foreground-subtle text-center px-2`,children:e})}function jn(e,t){let n=e.at(-1);return n===void 0?[t]:t.atMs>n.atMs?[...e,t]:e.some(e=>e.atMs===t.atMs)?e:[...e,t].toSorted((e,t)=>e.atMs-t.atMs)}function Mn(e,t,n,r){let i=e.get(t),a=jn(i?.points??[],r);if(i!==void 0&&a===i.points)return e;let o=new Map(e);return o.set(t,{key:t,kind:n,points:a.slice(Math.max(0,a.length-720))}),o}function Nn(e,t,n){let r=e;for(let e of ae(t,n))r=Mn(r,e.key,e.kind,e.point);return r}function Pn(e,t){let n=e;for(let e of t)for(let t of e.points)n=Mn(n,e.key,e.kind,t);return n}function Fn(e){let t=null;for(let n of e.values()){let e=n.points.at(-1);e!==void 0&&(t===null||e.atMs>t)&&(t=e.atMs)}return t}var In=12e4;function Ln(e,t){return e===null?!1:t-e>In}function Rn(e){let t=e=>{let t=e.points.at(-1);return t===void 0?-1:t.cpuMainPercent!==null&&t.cpuGcPercent!==null?t.cpuMainPercent+t.cpuGcPercent:t.cpuLifetimePercent};return[...e.values()].toSorted((e,n)=>{let r=t(n)-t(e);return r===0?e.key.localeCompare(n.key):r})}function zn(e){for(let t of e.values()){let e=t.points.at(-1);if(e&&e.cpuMainPercent!==null)return!0}return!1}var Bn={key:`cpu`,dir:`desc`};function Vn(e){let t=e.points.at(-1);return t===void 0?null:t.cpuMainPercent!==null&&t.cpuGcPercent!==null?t.cpuMainPercent+t.cpuGcPercent:t.cpuLifetimePercent}function Hn(e){return e.points.at(-1)?.memoryRssBytes??null}function Un(e,t,n){let r=n.trim().toLowerCase();return r===``?!0:e.toLowerCase().includes(r)||t.toLowerCase().includes(r)}function Wn(e,t){return t===`memory`?Hn(e):Vn(e)}function Gn(e,t,n){let r=e.filter(e=>t.selectedKeys.size>0&&!t.selectedKeys.has(e.key)?!1:Un(n(e),e.key,t.search)),i=(e,t)=>e.key.localeCompare(t.key);return[...r].toSorted((e,r)=>{if(t.sort.key===`name`){let a=n(e).localeCompare(n(r)),o=t.sort.dir===`asc`?a:-a;return o===0?i(e,r):o}let a=Wn(e,t.sort.key),o=Wn(r,t.sort.key);if(a===null&&o===null)return i(e,r);if(a===null)return 1;if(o===null)return-1;let s=t.sort.dir===`desc`?o-a:a-o;return s===0?i(e,r):s})}e();function Kn(e,n=720){let r=Ne(`metrics.node-processes-snapshot`,t=>t.nodeId===e),[a,o]=i(new Map),[s,c]=i(void 0),u=l(null),{data:d,isPending:f}=je({forNodeId:e,sinceMs:s,maxPoints:n});t(()=>{d!==void 0&&o(e=>{let t=Pn(e,d.series);return u.current=Fn(t),t})},[d]);let p=r?.timestamp;t(()=>{r==null||p===void 0||(Ln(u.current,p)&&c(u.current??0),o(e=>{let t=Nn(e,r.processes,p);return u.current=Fn(t),t}))},[p]),t(()=>{o(new Map),c(void 0),u.current=null},[e]);let m=0;for(let e of a.values())m=Math.max(m,e.points.length);return{series:Rn(a),sampleCount:m,threadSplitAvailable:zn(a),loadingRetained:f,durable:d?.durable??null,bucketMs:d?.bucketMs??null,cadenceMs:d?.cadenceMs??null,retainedSamples:d?.retainedSamples??null}}var qn=`__unclaimed__`;function Jn(e,t){return{kind:e,deviceId:t,cpu:0,cpuKnown:!0,rss:0,rssKnown:!0,count:0,roles:new Set}}function Yn(e,t){return{key:e,kind:t.kind,deviceId:t.deviceId,cpuSeconds:t.cpuKnown?Math.round(t.cpu*100)/100:null,rssBytes:t.rssKnown?t.rss:null,unitCount:t.count,roles:[...t.roles].sort()}}function Xn(e,t){let n=new Map,r=new Set;for(let t of e){t.pid!==void 0&&r.add(t.pid);let e=t.deviceId!==null&&t.attribution!==`unattributable`,i=e?`device:${t.deviceId}`:`shared:${t.role}`,a=n.get(i)??Jn(e?`camera`:`shared`,e?t.deviceId:null);a.count+=1,a.roles.add(t.role),t.cpuSeconds===void 0?a.cpuKnown=!1:a.cpu+=t.cpuSeconds,t.rssBytes===void 0?a.rssKnown=!1:a.rss+=t.rssBytes,n.set(i,a)}let i=[...n.entries()].map(([e,t])=>Yn(e,t));if(t===void 0)return i;let a=t.filter(e=>!r.has(e.pid));if(a.length===0)return i;let o=Jn(`unclaimed`,null);for(let e of a)o.count+=1,o.rss+=e.memoryRssBytes;return o.cpuKnown=!1,[...i,Yn(qn,o)]}var Zn=[{family:`decode`,attribution:`measured`,unit:`one forked decode-worker child per decode SESSION`,perCamera:!0,wiredToday:!0,missingLink:``,evidence:[`packages/addon-pipeline/src/session-decode/fork-decode-worker.ts:118`,`packages/addon-pipeline/src/session-decode/fork-decode-worker.ts:131`,`packages/addon-pipeline/src/pipeline-runner/index.ts:2765`,`packages/types/src/process/child-cost-registry.ts:188`]},{family:`transcode`,attribution:`measured`,unit:`one ffmpeg child per (camera, encode plan)`,perCamera:!0,wiredToday:!0,missingLink:``,evidence:[`packages/addon-pipeline/src/stream-broker/stream-broker/egress-transcode-manager.ts:960`,`packages/addon-pipeline/src/stream-broker/stream-broker/transcode-egress.ts:282`,`packages/addon-pipeline/src/stream-broker/stream-broker/transcode-egress.ts:324`,`packages/types/src/ffmpeg/sharing-key.ts:139`]},{family:`recording`,attribution:`measured`,unit:`one passthrough ffmpeg per (camera, profile)`,perCamera:!0,wiredToday:!0,missingLink:``,evidence:[`packages/addon-pipeline/src/recorder/addon/segment-writer.ts:33`,`packages/addon-pipeline/src/recorder/addon/segment-writer.ts:217`,`packages/addon-pipeline/src/recorder/addon/segment-writer.ts:279`,`packages/addon-pipeline/src/recorder/addon/recording-controller.ts:1710`]},{family:`detection`,attribution:`accounted`,unit:`a SHARED inference pool per (node, runtime, device) — no per-camera process`,perCamera:!1,wiredToday:!0,missingLink:"Nothing is missing for COUNTING — per-camera inference milliseconds, processed/shed frames and bytes-to-pool are already accumulated. What is missing is any basis for CPU seconds: `deviceId` reaches the pool as a diagnostic label and selects nothing, so cost can only ever be apportioned, never measured. Since 2026-08-27 the pool DECLARES this itself, contributing `deviceId: null` + `attribution: unattributable` rather than leaving an observer to infer it — the renunciation is data, and it is still refused by the chart gate.",evidence:[`packages/addon-pipeline/src/detection-pipeline/provider.ts:540`,`packages/addon-pipeline/src/detection-pipeline/engine/shared-inference-pool.ts:413`,`packages/types/src/interfaces/inference-engine.ts:24`,`packages/addon-pipeline/src/pipeline-runner/timing-sampler.ts:63`,`packages/addon-pipeline/src/pipeline-runner/runner.ts:353`,`packages/addon-pipeline/src/pipeline-runner/runner.ts:849`,`packages/addon-pipeline/src/pipeline-runner/frame-lazy-metrics.ts:100`]},{family:`streaming`,attribution:`measured`,unit:"one StreamBroker per `${deviceId}/${camStreamId}`, with an exact RTP ring byte counter",perCamera:!0,wiredToday:!1,missingLink:"The ffmpeg-backed ingest is now reported per camera, but that is the minority path. `rtpRingBytes` — the exact figure for the in-process case — is maintained on every push and drop and is still private and absent from `getStats()`. The three `EncodedRingBuffer`s track packets and duration and have no byte accumulator at all; the only byte figure they offer is `preRollBudgetBytes`, which is a BUDGET, not an occupancy.",evidence:[`packages/addon-pipeline/src/stream-broker/stream-broker/stream-broker.ts:2895`,`packages/addon-pipeline/src/stream-broker/rtsp/ffmpeg-push-reader.ts:189`,`packages/addon-pipeline/src/stream-broker/stream-broker/stream-broker.ts:494`,`packages/addon-pipeline/src/stream-broker/stream-broker/stream-broker.ts:498`,`packages/addon-pipeline/src/stream-broker/stream-broker/stream-broker.ts:2505`,`packages/addon-pipeline/src/stream-broker/stream-broker/pre-roll.ts:269`]}];function Qn(e){return e.attribution===`measured`&&e.wiredToday}function $n(){let e=new Set;for(let t of Zn)Qn(t)&&e.add(t.family);return e}var er=$n();function tr(e){return!er.has(e.role)||e.deviceId===null?!1:e.attribution===`measured`}function nr(e){return`${e.addonId}${e.role}${e.unit}${e.pid??`-`}`}function rr(){return{cpuSeconds:0,cpuKnown:!0,rssBytes:0,rssKnown:!0,unitCount:0,roles:new Set}}function ir(e,t,n){if(t.cpuSeconds===void 0)return null;if(e===void 0)return t.startedAtMs===void 0||t.startedAtMs<n?null:t.cpuSeconds;if(e.cpuSeconds===void 0||e.startedAtMs===void 0||t.startedAtMs===void 0||e.startedAtMs!==t.startedAtMs)return null;let r=t.cpuSeconds-e.cpuSeconds;return r<0?null:r}function ar(e){return Math.round(e*10)/10}function or(e,t){let n=t.atMs-e.atMs;if(n<=0)return[];let r=n/1e3,i=new Map;for(let t of e.entries)tr(t)&&i.set(nr(t),t);let a=new Map,o=new Set;for(let n of t.entries){if(!tr(n)||n.deviceId===null)continue;let t=nr(n);o.add(t);let r=a.get(n.deviceId)??rr();r.unitCount+=1,r.roles.add(n.role);let s=ir(i.get(t),n,e.atMs);s===null?r.cpuKnown=!1:r.cpuSeconds+=s,n.rssBytes===void 0?r.rssKnown=!1:r.rssBytes+=n.rssBytes,a.set(n.deviceId,r)}for(let[e,t]of i){if(o.has(e)||t.deviceId===null)continue;let n=a.get(t.deviceId);n!==void 0&&(n.cpuKnown=!1)}return[...a.entries()].map(([e,n])=>({deviceId:e,point:{atMs:t.atMs,cpuPercent:n.cpuKnown?ar(n.cpuSeconds/r*100):null,rssBytes:n.rssKnown?n.rssBytes:null,unitCount:n.unitCount,roles:[...n.roles].toSorted()}}))}function sr(e,t){if(t.length===0)return e;let n=new Map(e);for(let e of t){let t=n.get(e.deviceId),r=t?.points.at(-1);if(r!==void 0&&e.point.atMs<=r.atMs)continue;let i=[...t?.points??[],e.point];n.set(e.deviceId,{deviceId:e.deviceId,points:i.slice(Math.max(0,i.length-720))})}return n}function cr(e){let t=e=>{for(let t=e.points.length-1;t>=0;t--){let n=e.points[t]?.cpuPercent;if(n!=null)return n}return-1};return[...e.values()].toSorted((e,n)=>{let r=t(n)-t(e);return r===0?e.deviceId-n.deviceId:r})}function lr(e){let t=e.indexOf(`@`);return t===-1?{addonId:e,nodeId:null}:{addonId:e.slice(0,t),nodeId:e.slice(t+1)}}function ur(e,t){let n=lr(e);return n.nodeId===null?t.isHub:n.nodeId===t.nodeId}function dr(e,t){return e.filter(e=>ur(e.addonId,t))}e();function fr(e){let n=Ne(`metrics.node-processes-snapshot`,t=>t.nodeId===e.nodeId),r=qe(void 0,{staleTime:1/0,refetchOnWindowFocus:!1}),[a,o]=i(new Map),s=l(null),c=l(r.refetch);c.current=r.refetch;let u=n?.timestamp;t(()=>{u!==void 0&&c.current()},[u]),t(()=>{o(new Map),s.current=null},[e.nodeId,e.isHub]);let d=r.data,f=r.dataUpdatedAt;t(()=>{if(d===void 0||f===0)return;let t={atMs:f,entries:dr(d,e)},n=s.current;if(s.current=t,n===null)return;let r=or(n,t);r.length!==0&&o(e=>sr(e,r))},[d,f,e.nodeId,e.isHub]);let p=d===void 0?[]:dr(d,e),m=n?.processes,h=Xn(p,m);return{series:cr(a),unclaimed:h.find(e=>e.kind===`unclaimed`)??null,loading:r.isPending,error:r.error===null?null:r.error.message}}function pr(e){let t=new Map;for(let n of e){let e=n.name?.trim();e===void 0||e===``||t.set(n.id,e)}return t}var mr=25,hr=64*1024*1024,gr=1e4;function _r({scope:e,cadenceMs:t}){let{t:n}=H(),r=fr(e),{data:i=[]}=Je({isCamera:!0,projection:`slim`}),a=pr(i),s=ln(t??gr);return o(`section`,{className:`space-y-3`,children:[r.error!==null&&o(`div`,{className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[u(_,{className:`h-3 w-3 mt-0.5 shrink-0`}),u(`span`,{children:n(`cameraLoad.readFailed`,`Could not read the load contributions: {{error}}. This is a failed read, NOT an idle cluster.`,{error:r.error})})]}),u(yr,{unclaimed:r.unclaimed}),r.series.length===0&&r.error===null&&u(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:r.loading?n(`cameraLoad.loading`,`Reading what the addons report…`):n(`cameraLoad.waitingWindow`,`No per-camera window yet.`)}),u(`div`,{className:`space-y-3`,children:r.series.map(e=>o(`div`,{className:`rounded-lg border border-border p-3`,children:[o(`div`,{className:`flex items-baseline justify-between gap-2 mb-2`,children:[u(vr,{deviceId:e.deviceId,name:a.get(e.deviceId)}),u(`span`,{className:`text-[10px] text-foreground-subtle`,children:n(`cameraLoad.unitCount`,`{{count}} unit(s): {{roles}}`,{count:e.points.at(-1)?.unitCount??0,roles:(e.points.at(-1)?.roles??[]).join(`, `)})})]}),o(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[u(yn,{title:n(`cameraLoad.cpuTitle`,`CPU % of one core (delta)`),points:e.points.map(e=>({atMs:e.atMs,value:e.cpuPercent})),formatValue:e=>`${e.toFixed(1)}%`,axisFloor:mr,gapMs:s,emptyMessage:n(`cameraLoad.cpuUnavailable`,`No measurable window yet.`)}),u(yn,{title:n(`cameraLoad.memoryTitle`,`Memory RSS`),points:e.points.map(e=>({atMs:e.atMs,value:e.rssBytes})),formatValue:U,axisFloor:hr,axisScale:`bytes`,gapMs:s,emptyMessage:n(`cameraLoad.memoryUnavailable`,`No memory reported.`)})]})]},e.deviceId))})]})}function vr({deviceId:e,name:t}){let{t:n}=H();return t===void 0?u(`span`,{className:`text-xs font-medium text-foreground`,children:n(`cameraLoad.deviceLabel`,`Camera {{deviceId}}`,{deviceId:e})}):o(`span`,{className:`flex items-baseline gap-1.5 min-w-0`,children:[u(`span`,{className:`text-xs font-medium text-foreground truncate`,children:t}),o(`span`,{className:`shrink-0 text-[10px] font-mono text-foreground-subtle`,children:[`#`,e]})]})}function yr({unclaimed:e}){let{t}=H();return e===null||e.unitCount===0?null:u(`div`,{className:`flex items-center gap-2`,children:u(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full bg-warning/10 text-warning font-medium tabular-nums`,children:t(`cameraLoad.unclaimedBadge`,`{{count}} unclaimed · {{rss}}`,{count:e.unitCount,rss:e.rssBytes===null?`—`:U(e.rssBytes)})})})}e();var br=256*1024*1024,xr=1e4;function Sr({nodeId:e,isHub:t}){let{t:r}=H(),{series:a,sampleCount:s,threadSplitAvailable:c,loadingRetained:l,bucketMs:d,cadenceMs:f}=Kn(e),[p,m]=i(``),[h,g]=i(new Set),[v,y]=i(Bn),b=e=>e.key===`__root__`?r(`clusterLoad.bucketRoot`,`Node supervisor`):e.key===`__unattributed__`?r(`clusterLoad.bucketUnattributed`,`Unattributed processes`):e.key,x=ln(d??f??xr),S=n(()=>Gn(a,{search:p,selectedKeys:h,sort:v},b),[a,p,h,v]),T=e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return o(`div`,{className:`space-y-4`,children:[u(Cr,{bucketMs:d,cadenceMs:f}),!c&&s>0&&o(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/40 bg-warning/5 px-3 py-2 text-[11px] text-warning`,children:[u(_,{className:`h-3 w-3 mt-0.5 shrink-0`}),u(`span`,{children:r(`clusterLoad.noThreadSplit`,`No thread-level CPU split on this node — /proc/<pid>/task is Linux-only, and the first sample after a restart has no window to measure. CPU below falls back to the ps lifetime AVERAGE, which is not a rate.`)})]}),s===0&&u(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:l?r(`clusterLoad.loadingRetained`,`Reading the retained series from this node…`):r(`clusterLoad.waitingFirstSample`,`No retained samples for this node — waiting for the next snapshot (up to 20s). The chart needs two to draw a rate.`)}),a.length>0&&o(`div`,{className:`space-y-2`,children:[o(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(`label`,{className:`relative flex-1 min-w-[160px]`,children:[u(w,{className:`pointer-events-none absolute left-2 top-1/2 h-3 w-3 -translate-y-1/2 text-foreground-subtle`}),u(`input`,{type:`search`,value:p,onChange:e=>m(e.target.value),placeholder:r(`clusterLoad.searchPlaceholder`,`Find a runner…`),"aria-label":r(`clusterLoad.searchLabel`,`Find a runner`),className:`w-full rounded border border-border bg-background py-1 pl-7 pr-2 text-[11px] text-foreground placeholder:text-foreground-subtle`})]}),u(wr,{sort:v,onChange:y})]}),o(`div`,{className:`flex flex-wrap items-center gap-1`,children:[a.map(e=>{let t=h.has(e.key);return u(`button`,{type:`button`,"aria-pressed":t,onClick:()=>T(e.key),className:`rounded-full border px-2 py-0.5 text-[10px] transition-colors ${t?`border-primary bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground`}`,children:b(e)},e.key)}),h.size>0&&o(`button`,{type:`button`,onClick:()=>g(new Set),className:`inline-flex items-center gap-1 rounded-full border border-border px-2 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground`,children:[u(C,{className:`h-2.5 w-2.5`}),r(`clusterLoad.clearFilter`,`All runners`)]})]})]}),a.length>0&&S.length===0&&u(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:r(`clusterLoad.noMatches`,`No runner matches this search on {{count}} present. The node is reporting — the filter is hiding them.`,{count:a.length})}),u(`div`,{className:`space-y-3`,children:S.map(e=>o(`div`,{className:`rounded-lg border border-border p-3`,children:[o(`div`,{className:`flex items-baseline justify-between gap-2 mb-2`,children:[u(`span`,{className:`text-xs font-medium text-foreground`,children:b(e)}),u(`span`,{className:`text-[10px] text-foreground-subtle`,children:r(`clusterLoad.processCount`,`{{count}} process(es)`,{count:e.points.at(-1)?.processCount??0})})]}),o(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[u(vn,{title:c?r(`clusterLoad.cpuTitle`,`CPU % of one core`):r(`clusterLoad.cpuTitleLifetime`,`CPU % (ps lifetime average)`),mainLabel:r(`clusterLoad.seriesMain`,`Main threads`),gcLabel:r(`clusterLoad.seriesGc`,`GC / V8 helpers`),points:e.points.map(e=>({atMs:e.atMs,main:e.cpuMainPercent,gc:e.cpuGcPercent})),formatValue:e=>`${e.toFixed(0)}%`,gapMs:x,emptyMessage:r(`clusterLoad.cpuUnavailable`,`No thread split on this node. Lifetime average: {{avg}}%`,{avg:(e.points.at(-1)?.cpuLifetimePercent??0).toFixed(1)})}),u(yn,{title:r(`clusterLoad.memoryTitle`,`Memory RSS`),points:e.points.map(e=>({atMs:e.atMs,value:e.memoryRssBytes})),formatValue:U,axisFloor:br,axisScale:`bytes`,gapMs:x,emptyMessage:r(`clusterLoad.memoryUnavailable`,`No memory samples yet.`)})]})]},e.key))}),u(_r,{scope:{nodeId:e,isHub:t},cadenceMs:f})]})}function Cr({bucketMs:e,cadenceMs:t}){let{t:n}=H();return e===null?null:u(`p`,{className:`text-[10px] text-foreground-subtle`,children:t!==null&&e>t?n(`clusterLoad.captionBucket`,`1 point = {{bucket}}s (bucket MAXIMUM, not a mean)`,{bucket:Math.round(e/1e3)}):n(`clusterLoad.captionRaw`,`1 point = 1 snapshot`)})}function wr({sort:e,onChange:t}){let{t:n}=H(),r=[{key:`cpu`,label:n(`clusterLoad.sortCpu`,`CPU`)},{key:`memory`,label:n(`clusterLoad.sortMemory`,`Memory`)},{key:`name`,label:n(`clusterLoad.sortName`,`Name`)}];return o(`div`,{className:`flex items-center gap-1`,children:[u(`span`,{className:`text-[10px] text-foreground-subtle`,children:n(`clusterLoad.sortBy`,`Sort by`)}),r.map(n=>{let r=e.key===n.key;return o(`button`,{type:`button`,"aria-pressed":r,onClick:()=>t(r?{key:n.key,dir:e.dir===`desc`?`asc`:`desc`}:{key:n.key,dir:n.key===`name`?`asc`:`desc`}),className:`rounded border px-1.5 py-0.5 text-[10px] transition-colors ${r?`border-primary bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground`}`,children:[n.label,r&&(e.dir===`desc`?` ↓`:` ↑`)]},n.key)})]})}var Tr=`No per-node settings on this node. Every other setting these addons expose is one value for the whole cluster — edit those in System → Settings, not here.`;function Er({nodeId:e,addonIds:t}){let{t:n}=H();return t.length===0?u(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:n(`cluster.nodeDetailSettingsTab.noAddonsOnThisNode`,`No addons on this node`)}):u(`div`,{className:`w-full py-2`,children:u($e,{nodeId:e,addonIds:t,level:`global`,fieldScope:`perNode`,emptyMessage:Tr,selfTabbed:!0})})}e();function Dr({nodeId:e,addons:t}){let{t:r}=H(),i=c(),{data:a,isLoading:o}=Te({nodeId:e}),s=n(()=>{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]),l=Pe({onSuccess:()=>{i.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCapabilityBindings`]]})}});return s.length===0?u(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:r(`cluster.nodeDetailCapabilitiesTab.noCapabilitiesOnThisNode`,`No capabilities on this node`)}):u(ve,{columns:[{key:`capName`,header:r(`cluster.nodeDetailCapabilitiesTab.capability`,`Capability`),width:`w-1/2`,sortValue:e=>e.capName,render:e=>u(`span`,{className:`font-medium`,children:e.capName})},{key:`provider`,header:r(`cluster.nodeDetailCapabilitiesTab.boundProvider`,`Bound provider`),render:t=>{let n=a?.[t.capName]??t.providers[0]??``,i=t.providers.length===1;return u(`select`,{value:n,onChange:n=>l.mutate({nodeId:e,capName:t.capName,addonId:n.target.value}),disabled:i||l.isPending||o,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:i?r(`cluster.nodeDetailCapabilitiesTab.onlyOneProviderInstalledChoice`,`Only one provider installed — choice becomes available once a second addon registers this capability`):void 0,children:t.providers.map(e=>u(`option`,{value:e,children:e},e))})}}],rows:s,rowKey:e=>e.capName,minWidthPx:520,maxBodyHeight:We})}e();function Or(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 kr(e){let{t}=H(),[n,r]=i(!1),[a,s]=i(e.name),l=c(),d=He({onSuccess:()=>{l.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}}),f=(e.localIps??[]).filter(e=>!e.includes(`:`)),p=(e.localIps??[]).filter(e=>e.includes(`:`)),m=async()=>{if(!a.trim()||a===e.name){r(!1);return}try{await d.mutateAsync({nodeId:e.nodeId,name:a.trim()}),r(!1)}catch(e){console.error(`Rename failed:`,e)}},g=[[`Node ID`,u(`span`,{className:`font-mono text-xs`,children:e.nodeId})],[`Display Name`,n?o(`div`,{className:`flex items-center gap-1.5`,children:[u(`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:a,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&m(),e.key===`Escape`&&r(!1)},disabled:d.isPending,autoFocus:!0}),u(`button`,{onClick:()=>void m(),disabled:d.isPending,className:`p-0.5 text-success hover:bg-success/10 rounded`,title:t(`common.save`,`Save`),children:u(v,{className:`h-3.5 w-3.5`})}),u(`button`,{onClick:()=>r(!1),className:`p-0.5 text-muted-foreground hover:bg-muted rounded`,title:t(`common.cancel`,`Cancel`),children:u(C,{className:`h-3.5 w-3.5`})})]}):o(`div`,{className:`flex items-center gap-1.5`,children:[u(`span`,{className:`text-xs`,children:e.name}),!e.isHub&&u(`button`,{onClick:()=>{s(e.name),r(!0)},className:`p-0.5 text-muted-foreground hover:text-primary rounded`,title:t(`cluster.nodeInfoTab.rename`,`Rename`),children:u(h,{className:`h-3 w-3`})})]})],[`Hostname`,u(`span`,{className:`text-xs`,children:e.hostname})],[`Role`,e.isHub?u(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary font-medium`,children:t(`cluster.nodeInfoTab.hub`,`Hub`)}):u(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium`,children:t(`cluster.nodeInfoTab.agent`,`Agent`)})],[`Root Package`,e.rootPackage?o(`span`,{className:`font-mono text-xs`,children:[e.rootPackage.name,`@`,e.rootPackage.version]}):u(`span`,{className:`text-xs text-muted-foreground`,children:`—`})],[`Platform`,o(`span`,{className:`text-xs`,children:[e.platform,` / `,e.arch]})],[`CPU`,o(`span`,{className:`text-xs`,children:[e.cpuModel??`—`,` (`,t(`cluster.nodeInfoTab.cores`,{count:e.cpuCores}),`)`]})],[`Memory`,u(`span`,{className:`text-xs`,children:e.memoryMB>0?t(`cluster.nodeInfoTab.gb`,`{{value1}} GB`,{value1:(e.memoryMB/1024).toFixed(1)}):`—`})],[`Uptime`,u(`span`,{className:`text-xs`,children:Or(e.uptime)})],[`Engines`,e.engines.length>0?u(`div`,{className:`flex flex-wrap gap-1`,children:e.engines.map(e=>u(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium`,children:e},e))}):u(`span`,{className:`text-xs text-muted-foreground`,children:`—`})]];return f.length>0&&g.push([`IPv4`,u(`div`,{className:`flex flex-wrap gap-1.5`,children:f.map((e,t)=>u(`span`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted`,children:e},`${e}-${t}`))})]),p.length>0&&g.push([`IPv6`,u(`div`,{className:`flex flex-wrap gap-1.5`,children:p.map((e,t)=>u(`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}`))})]),u(`div`,{className:`py-2`,children:u(`table`,{className:`w-full text-sm`,children:u(`tbody`,{children:g.map(([e,t],n)=>o(`tr`,{className:n%2==0?`bg-muted/20`:``,children:[u(`td`,{className:`py-1.5 px-2 text-xs font-medium text-muted-foreground w-28 align-top whitespace-nowrap`,children:e}),u(`td`,{className:`py-1.5 px-2`,children:t})]},e))})})})}e();function Ar({nodeId:e,value:n,detectedHosts:r,status:a,errorMessage:s,onCommit:c}){let{t:l}=H(),[d,f]=i(n??``);t(()=>{f(n??``)},[n]);let p=r[0],m=p===void 0?`auto-detect`:`auto: ${p}`,h=a===`pending`,g=d.trim(),_=g!==(n??``),y=_&&!h,b=()=>{y&&c(e,g.length>0?g:null)};return o(`div`,{className:`flex items-center gap-1.5`,children:[u(B,{"aria-label":l(`placementBoard.reachableHostInput.reachableHostFor`,`Reachable host for {{nodeId}}`,{nodeId:e}),type:`text`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:m,value:d,disabled:h,onChange:e=>f(e.target.value),onBlur:b,onKeyDown:e=>{e.key===`Enter`&&b(),e.key===`Escape`&&f(n??``)},className:`w-36`}),o(R,{variant:`outline`,size:`sm`,onClick:b,disabled:!y,"aria-label":l(`placementBoard.reachableHostInput.saveReachableHostFor`,`Save reachable host for {{nodeId}}`,{nodeId:e}),title:l(`placementBoard.reachableHostInput.saveReachableHost`,`Save reachable host`),children:[h?u(D,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):u(v,{className:`h-3 w-3`,"aria-hidden":`true`}),l(`common.save`,`Save`)]}),!_&&!h&&a===`success`&&u(v,{className:`h-3.5 w-3.5 shrink-0 text-success`,"aria-label":l(`placementBoard.reachableHostInput.saved`,`Saved`),role:`img`}),a===`error`&&u(`span`,{title:s??l(`placementBoard.reachableHostInput.failedToSaveReachableHost`,`Failed to save reachable host`),children:u(T,{className:`h-3.5 w-3.5 shrink-0 text-danger`,"aria-label":s??l(`placementBoard.reachableHostInput.failedToSaveReachableHost`,`Failed to save reachable host`),role:`img`})})]})}e();function jr(e){let t=ne.safeParse(et(e,`color`));return t.success?t.data:null}function Mr(e,t){return t.variables?.agentNodeId===e?t.isPending?`pending`:t.isError?`error`:t.isSuccess?`success`:`idle`:`idle`}function Nr({nodeId:e,detectedHosts:t}){let{t:r}=H(),i=c(),a=_e(void 0),s=Ke({onSuccess:()=>tt(i)}),l=Ke({onSuccess:()=>tt(i)}),d=n(()=>a.data?.find(t=>t.nodeId===e)?.settings,[a.data,e]),f=jr(d)??(a.isLoading?null:ie(e)),p=nt(d,`reachableHost`),m=Mr(e,s),h=m===`error`?rt(s.error):null,g=t.filter(e=>!e.includes(`:`)),_=t=>{t!==f&&l.mutate({agentNodeId:e,color:t})};return o(`div`,{className:`rounded-lg border border-border bg-surface/40 divide-y divide-border px-3`,children:[u(pe,{label:r(`nodes.general.nodeColour`,`Node colour`),children:u(`div`,{role:`group`,"aria-label":r(`nodes.general.nodeColourGroup`,`Node colour`),className:`flex flex-wrap gap-2`,children:re.map(e=>{let t=f===e;return u(R,{type:`button`,role:`radio`,"aria-checked":t,"aria-label":e,variant:`outline`,size:`sm`,disabled:a.isLoading||l.isPending,title:e,onClick:()=>_(e),className:`h-6 w-6 min-w-6 shrink-0 rounded-full border-0 p-0 ${le(e)} ${t?`ring-2 ring-primary ring-offset-2 ring-offset-background`:`opacity-80 hover:opacity-100`}`,children:u(`span`,{className:`sr-only`,children:e})},e)})})}),u(pe,{label:r(`nodes.general.reachableHost`,`Reachable host`),children:u(Ar,{nodeId:e,value:p,detectedHosts:g,status:m,errorMessage:h,onCommit:(e,t)=>{s.mutate({agentNodeId:e,reachableHost:t})}})})]})}e();var Pr=[[`serverManagement`,`getServerPackageStatus`]];function Fr({label:e,tone:t}){return u(`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-success/15 text-success`,info:`bg-info/15 text-info`,warn:`bg-warning/15 text-warning`,error:`bg-danger/15 text-danger`}[t]}`,children:e})}function $({label:e,value:t}){return o(`div`,{className:`flex items-center justify-between gap-4 text-sm`,children:[u(`span`,{className:`text-foreground-subtle`,children:e}),u(`span`,{className:`font-mono text-foreground`,children:t??`—`})]})}function Ir({runningVersion:e,latestVersion:t,seedVersion:n,nodeRuntimeVersion:r,labelRunning:i,labelLatest:a,labelSeed:s,labelRuntime:c}){return u(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1 text-sm`,children:[{key:`running`,label:i,value:e},{key:`latest`,label:a,value:t},{key:`seed`,label:s,value:n},{key:`runtime`,label:c,value:r}].map(({key:e,label:t,value:n})=>o(`span`,{className:`inline-flex items-baseline gap-1`,children:[u(`span`,{className:`text-foreground-subtle`,children:t}),u(`span`,{className:`font-mono text-foreground`,children:n??`—`})]},e))})}var Lr={ok:`border-success/40 bg-success/10 text-success`,warn:`border-warning/40 bg-warning/10 text-warning`,error:`border-danger/40 bg-danger/10 text-danger`};function Rr(e){return e.outcome===`failed`?`error`:(e.outcome,e.accepted?`ok`:`warn`)}function zr(e,t){let n=t instanceof Error?t.message:String(t);return`${e(`serverManagement.outcomeDropped`,`The connection dropped and the result could not be confirmed. The node may be restarting — re-check the version above.`)} — ${n}`}function Br({node:e}){let{t}=H(),n=c(),r=z(),[s,l]=i(!1),[d,f]=i(null),p=e.isHub?void 0:{nodeId:e.id},m=me(p,{refetchInterval:1e4,enabled:e.isOnline,retry:1}),h=m.data??null,g=a(()=>{n.invalidateQueries({queryKey:Pr})},[n]),_=De({onSettled:g}),v=de({onSettled:g}),y=Ee({onSettled:g}),S=a(async()=>{if(h?.latestVersion==null){f({tone:`warn`,text:t(`serverManagement.outcomeNoTarget`,`No target version is known for this node — run "Check for update" first.`)});return}if(await r({title:t(`serverManagement.confirmUpdateTitle`,`Update node root package`),message:t(`serverManagement.confirmUpdateBody`,`Install {{pkg}}@{{version}} on "{{node}}" and restart to apply.`,{pkg:h.packageName,version:h.latestVersion,node:e.name}),confirmLabel:t(`serverManagement.confirmUpdateAction`,`Update & restart`)})){f(null);try{let e=await v.mutateAsync({version:h.latestVersion,...p});f({tone:Rr(e),text:e.message}),e.restarting&&l(!0)}catch(e){f({tone:`warn`,text:zr(t,e)})}}},[v,r,e.name,p,h,t]),C=a(async()=>{if(await r({title:t(`serverManagement.confirmRestartTitle`,`Restart node`),message:t(`serverManagement.confirmRestartBody`,`Restart "{{node}}"? In-flight requests to this node are dropped.`,{node:e.name}),confirmLabel:t(`serverManagement.confirmRestartAction`,`Restart`),variant:`warning`})){f(null);try{let e=await y.mutateAsync(p);f({tone:Rr(e),text:e.message}),e.restarting&&l(!0)}catch(e){f({tone:`warn`,text:zr(t,e)})}}},[r,e.name,y,p,t]),w=()=>{switch(h?.bootMode){case`data-root`:return{label:t(`serverManagement.bootDataRoot`,`runtime-updatable`),tone:`ok`};case`workspace`:return{label:t(`serverManagement.bootWorkspace`,`dev workspace`),tone:`info`};default:return{label:t(`serverManagement.bootBaked`,`baked image seed`),tone:`neutral`}}},T=()=>{if(h==null)return null;switch(h.updateState){case`checking`:return{label:t(`serverManagement.stateChecking`,`checking…`),tone:`info`};case`staging`:return{label:t(`serverManagement.stateStaging`,`updating…`),tone:`info`};case`pending-restart`:return{label:t(`serverManagement.statePending`,`restart pending`),tone:`warn`};default:return h.restartRequired===!0?{label:t(`serverManagement.stateRestartRequired`,`restart required`),tone:`warn`}:h.updateAvailable?{label:t(`serverManagement.stateUpdateAvailable`,`update available`),tone:`warn`}:{label:t(`serverManagement.stateUpToDate`,`up to date`),tone:`ok`}}},E=h?.bootMode===`workspace`,O=e.isOnline&&h!=null&&!E&&h.updateAvailable&&h.updateState===`idle`&&!v.isPending,k=e.isOnline&&h!=null&&h.updateState===`idle`&&!y.isPending,A=e.isOnline?T():null;return o(`div`,{className:`space-y-4 py-2`,children:[o(`div`,{className:`flex items-center justify-between gap-3`,children:[o(`div`,{className:`flex items-center gap-2 min-w-0`,children:[u(`span`,{className:`font-mono text-xs text-foreground-subtle truncate`,children:h?.packageName??e.rootPackage?.name??`@camstack/server`}),e.isOnline&&h!=null&&u(Fr,{...w()})]}),A!=null&&u(Fr,{...A})]}),!e.isOnline&&u($,{label:t(`serverManagement.lastReportedVersion`,`Last reported version`),value:e.rootPackage?.version??null}),e.isOnline&&m.isLoading&&o(`div`,{className:`flex items-center gap-2 text-sm text-foreground-subtle`,children:[u(D,{className:`h-4 w-4 animate-spin`}),t(`common.loading`,`Loading…`)]}),e.isOnline&&m.isError&&o(`div`,{className:`space-y-1.5`,children:[u(`p`,{className:`text-sm text-danger`,children:t(`serverManagement.loadError`,`Could not load the node root-package status.`)}),e.rootPackage!=null&&u($,{label:t(`serverManagement.lastReportedVersion`,`Last reported version`),value:e.rootPackage.version})]}),e.isOnline&&h!=null&&o(`div`,{className:`space-y-1.5`,children:[u(Ir,{runningVersion:h.runningVersion,latestVersion:h.latestVersion,seedVersion:h.seedVersion,nodeRuntimeVersion:h.nodeRuntimeVersion,labelRunning:t(`serverManagement.runningVersionShort`,`Running`),labelLatest:t(`serverManagement.latestVersionShort`,`Latest`),labelSeed:t(`serverManagement.imageSeedShort`,`Seed`),labelRuntime:t(`serverManagement.nodeRuntimeVersionShort`,`Node.js`)}),h.pendingVersion!=null&&u($,{label:t(`serverManagement.pendingVersion`,`Staged (applies on restart)`),value:h.pendingVersion}),h.installedVersion!=null&&h.installedVersion!==h.runningVersion&&u($,{label:t(`serverManagement.installedVersion`,`Installed on disk (runs after restart)`),value:h.installedVersion})]}),e.isOnline&&h?.imageContract?.state===`behind-series`&&o(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs leading-relaxed text-danger`,children:[u(`p`,{className:`mb-0.5 font-semibold`,children:t(`serverManagement.imageContractDiverged`,`Container image diverges from the deployment contract`)}),u(`p`,{children:h.imageContract.message})]}),e.isOnline&&E&&u(`p`,{className:`text-xs text-foreground-subtle`,children:t(`serverManagement.workspaceNote`,`Development workspace detected — runtime updates are disabled (the dev loop resolves code from the workspace).`)}),d!=null&&u(`p`,{role:`status`,className:`rounded border px-2 py-1.5 text-xs leading-relaxed ${Lr[d.tone]}`,children:d.text}),s&&o(`div`,{className:`flex items-center gap-2 text-sm text-warning`,children:[u(D,{className:`h-4 w-4 animate-spin`}),t(`serverManagement.nodeRestarting`,`The node is restarting to apply the change…`)]}),e.isOnline&&o(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[o(`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:_.isPending||h?.updateState===`staging`,onClick:()=>_.mutate(p),children:[_.isPending?u(D,{className:`h-3.5 w-3.5 animate-spin`}):u(x,{className:`h-3.5 w-3.5`}),t(`serverManagement.checkForUpdate`,`Check for update`)]}),O&&o(`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 S(),children:[v.isPending?u(D,{className:`h-3.5 w-3.5 animate-spin`}):u(b,{className:`h-3.5 w-3.5`}),t(`serverManagement.updateTo`,`Update to {{version}}`,{version:h?.latestVersion??``})]}),o(`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:!k,onClick:()=>void C(),children:[y.isPending?u(D,{className:`h-3.5 w-3.5 animate-spin`}):u(N,{className:`h-3.5 w-3.5`}),t(`serverManagement.restart`,`Restart`)]})]}),e.isOnline&&h?.lastCheckedAtMs!=null&&o(`p`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[u(oe,{className:`h-3 w-3`}),t(`serverManagement.lastChecked`,`Last checked: {{when}}`,{when:new Date(h.lastCheckedAtMs).toLocaleString()})]})]})}e();function Vr(e){if(typeof e!=`object`||!e||Array.isArray(e))return null;let t=Reflect.get(e,`reachableHost`);return typeof t==`string`&&t.length>0?t:null}function Hr({node:e}){let{t}=H(),r=O(),l=c(),d=z(),[p,m]=i(!1),[h,_]=i(`info`),[v,b]=i(!1),[x,S]=i(null),C=e.processes??[],w=e.addons.map(e=>e.id),T=_e(void 0),E=n(()=>{let t=T.data?.find(t=>t.nodeId===e.id);return Vr(t?.settings)},[T.data,e.id]),[D,k]=i(!1),[A,j]=i(null),[M,N]=i(null),ee=a(async()=>{if(D||e.isHub)return;let t=Ft(e.localIps??[],E);if(t===null){j(`No LAN IPv4 on this node — open its :4444 URL by hand.`),N(null);return}let n=Rt();k(!0),j(null),N(null);try{let i=jt(await r.trpcClient.addons.custom.mutate({addonId:`system-config`,action:`mintAgentUiUnlockTicket`,input:{nodeId:e.id,dashboardBaseUrl:It(t)}})),a=i===null?null:i.dashboardUrl??Lt(t,i.ticket);if(a===null){n?.close(),j(`Hub did not return an unlock ticket.`);return}zt(n,a)||(N(a),j(`Browser blocked the new tab — click the link below (or allow popups for this site).`))}catch(e){n?.close(),j(e instanceof Error?e.message:String(e))}finally{k(!1)}},[e.id,e.isHub,e.localIps,D,E,r.trpcClient]),te=async()=>{if(!v){b(!0),S(null);try{await r.trpcClient.pipelineOrchestrator.removeAgentSettings.mutate({agentNodeId:e.id}).catch(()=>void 0);let t=await r.trpcClient.clusterNodes.forgetNode.mutate({nodeId:e.id});S({tone:t.stillListed?`warn`:`ok`,text:t.message}),t.stillListed||l.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}catch(e){S({tone:`warn`,text:t(`cluster.nodeCard.forgetFailed`,{error:e instanceof Error?e.message:String(e)})})}finally{b(!1)}}},P=async()=>{if(!p&&await d({title:t(`cluster.nodeCard.unpair`,`Unpair {{name}}`,{name:e.name}),message:t(`cluster.nodeCard.unpairItDisconnectsAndMust`,`Unpair {{name}}? It disconnects and must be paired again.`,{name:e.name}),confirmLabel:t(`cluster.nodeCard.unpair2`,`Unpair`),variant:`danger`})){m(!0),S(null);try{let t=await r.trpcClient.agentPairing.unpairAgent.mutate({nodeId:e.id});S({tone:t.agentNotified?`ok`:`warn`,text:`${t.nodeId}: ${t.next}${t.agentNotified?``:` The agent could not be told; forget the hub on its own page.`}`}),l.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}catch(e){S({tone:`warn`,text:t(`cluster.nodeCard.unpairFailed`,{error:e instanceof Error?e.message:String(e)})})}finally{m(!1)}}},F=e.isHub?null:o(R,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void P(),disabled:p,title:t(`cluster.nodeCard.unpairThisNodeRevokesIts`,`Unpair this node — revokes its certificates; it must be paired again to rejoin`),children:[u(ce,{className:`h-3 w-3`,"aria-hidden":!0}),p?t(`cluster.nodeCard.unpairing`,`Unpairing…`):t(`cluster.nodeCard.unpair2`,`Unpair`)]});return e.isOnline?o(`div`,{className:`border border-border rounded-xl`,children:[o(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2 px-4 py-3 bg-muted/30 border-b border-border rounded-t-xl`,children:[o(`div`,{className:`flex min-w-0 flex-1 basis-full items-center gap-x-2 gap-y-1 sm:basis-auto sm:flex-initial`,children:[u(`div`,{className:`w-2.5 h-2.5 rounded-full bg-success shrink-0`}),u(Bt,{node:e}),o(`span`,{className:`text-xs text-muted-foreground min-w-0 truncate`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?t(`cluster.nodeCard.gb`,`{{value1}}GB`,{value1:Math.round(e.memoryMB/1024)}):``,` `,`· `,e.arch]})]}),e.engines.map(e=>u(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium shrink-0`,children:e},e)),o(`div`,{className:`flex min-w-0 flex-wrap items-center justify-end gap-x-3 gap-y-1 text-xs text-muted-foreground w-full sm:ml-auto sm:w-auto`,children:[!e.isHub&&o(`button`,{type:`button`,onClick:()=>void ee(),disabled:D,title:t(`cluster.nodeCard.openThisAgentSStatus`,`Open this agent's status dashboard (unlocks with a short-lived hub ticket)`),className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-xs text-foreground hover:bg-surface-hover disabled:opacity-50`,children:[u(f,{className:`h-3 w-3`}),D?t(`cluster.nodeCard.opening`,`Opening…`):t(`cluster.nodeCard.openDashboard`,`Open dashboard`)]}),F,o(`span`,{className:`flex items-center gap-1`,children:[u(y,{className:`h-3 w-3`}),` `,e.cpuPercent,`%`]}),o(`span`,{className:`flex items-center gap-1`,children:[u(se,{className:`h-3 w-3`}),` `,e.memoryPercent,`%`]})]})]}),x!=null&&u(`p`,{role:`status`,className:`px-4 pt-2 text-xs ${x.tone===`ok`?`text-success`:`text-warning`}`,children:x.text}),(A!==null||M!==null)&&o(`p`,{role:`status`,className:`px-4 pt-2 text-xs text-warning`,children:[A,M!==null&&o(s,{children:[` `,u(`a`,{href:M,target:`_blank`,rel:`noreferrer`,className:`underline text-foreground`,children:t(`cluster.nodeCard.openDashboard`,`Open dashboard`)})]})]}),u(`div`,{className:`sticky top-0 z-20 flex border-b border-border px-4 bg-background overflow-x-auto`,children:[`info`,`forks`,`processes`,`load`,`settings`,`capabilities`].map(e=>u(`button`,{onClick:()=>_(e),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${h===e?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:e===`info`?t(`cluster.nodeCard.general`,`General`):e===`forks`?t(`cluster.nodeCard.forks`,`Forks ({{length}})`,{length:C.length}):e===`processes`?t(`cluster.nodeCard.processes`,`Processes`):e===`load`?t(`cluster.nodeCard.load`,`Load`):e===`settings`?t(`cluster.nodeCard.settings`,`Settings`):t(`cluster.nodeCard.capabilities`,`Capabilities`)},e))}),o(`div`,{className:`px-4 py-2`,children:[h===`info`&&o(`div`,{className:`space-y-3`,children:[u(kr,{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}),u(Nr,{nodeId:e.id,detectedHosts:e.localIps??[]}),u(`div`,{className:`border-t border-border pt-1`,children:u(Br,{node:{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,rootPackage:e.rootPackage??null}})})]}),h===`forks`&&u(Gt,{nodeId:e.id,processes:C}),h===`processes`&&u(Yt,{nodeId:e.id}),h===`load`&&u(Sr,{nodeId:e.id,isHub:e.isHub}),h===`settings`&&u(Er,{nodeId:e.id,addonIds:w}),h===`capabilities`&&u(Dr,{nodeId:e.id,addons:e.addons})]})]}):o(`div`,{className:`border border-border rounded-xl overflow-hidden opacity-60`,children:[o(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2 px-4 py-3 bg-muted/30`,children:[u(`div`,{className:`w-2.5 h-2.5 rounded-full bg-destructive shrink-0`}),u(Bt,{node:e}),o(`span`,{className:`text-xs text-muted-foreground min-w-0 truncate`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?t(`cluster.nodeCard.gb`,`{{value1}}GB`,{value1:Math.round(e.memoryMB/1024)}):``,` `,`· `,e.arch]}),e.engines.map(e=>u(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium`,children:e},e)),e.rootPackage&&o(`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]}),u(`span`,{className:`ml-auto text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:t(`common.offline`)})]}),o(`div`,{className:`flex items-center justify-between gap-3 px-4 py-3`,children:[o(`span`,{className:`text-xs text-muted-foreground`,children:[e.lastSeen?u(`span`,{className:`mr-1`,children:t(`cluster.nodeCard.lastSeen`,{when:new Date(e.lastSeen).toLocaleString()})}):null,t(`cluster.nodeCard.addonsAssigned`,{count:e.addons.length})]}),o(`div`,{className:`flex shrink-0 items-center gap-2`,children:[F,o(`button`,{type:`button`,onClick:()=>void te(),disabled:v,title:t(`cluster.nodeCard.forgetThisNodeRemovesIts`,`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:[u(g,{className:`h-3 w-3`}),v?t(`cluster.nodeCard.forgetting`,`Forgetting…`):t(`cluster.nodeCard.forgetNode`,`Forget node`)]})]})]}),x!=null&&u(`p`,{role:`status`,className:`px-4 pb-3 text-xs leading-relaxed ${x.tone===`ok`?`text-success`:`text-warning`}`,children:x.text})]})}var Ur=3,Wr=7e3;function Gr(e){return[...e].sort((e,t)=>e.isHub===t.isHub?0:e.isHub?1:-1)}function Kr(e){return e.isHub?{}:{nodeId:e.id}}function qr(e){return e.updateState===`staging`||e.updateState===`pending-restart`||e.pendingVersion!==null?!0:!e.updateAvailable}async function Jr(e,t){let n=Kr(e),r=V.t(`helpers.clusterUpdateAll.noAnswer`);for(let i=1;i<=Ur;i+=1)try{let r=await t.readStatus(n);return qr(r)?{nodeId:e.id,nodeName:e.name,outcome:`applied`,detail:V.t(`helpers.clusterUpdateAll.landed`,{state:r.updateState,version:r.runningVersion??V.t(`helpers.clusterUpdateAll.unknown`)})}:{nodeId:e.id,nodeName:e.name,outcome:`failed`,detail:V.t(`helpers.clusterUpdateAll.unchanged`,{version:r.runningVersion??V.t(`helpers.clusterUpdateAll.unknown`)})}}catch(e){r=e instanceof Error?e.message:String(e),i<Ur&&await t.wait(Wr)}return{nodeId:e.id,nodeName:e.name,outcome:`unconfirmed`,detail:V.t(`helpers.clusterUpdateAll.unconfirmed`,{attempts:Ur,error:r})}}function Yr(e){return e.accepted?`applied`:e.outcome===`failed`?`failed`:`refused`}async function Xr(e,t){let n=[];for(let r of Gr(e))try{let e=await t.apply(Kr(r));n.push({nodeId:r.id,nodeName:r.name,outcome:Yr(e),detail:e.message})}catch{n.push(await Jr(r,t))}return n}e();function Zr(){let{nodes:e,isLoading:t}=Ye(),r=n(()=>e??[],[e]);return{nodes:r,isLoading:t&&r.length===0}}var Qr={applied:`border-success/40 bg-success/10 text-success`,refused:`border-warning/40 bg-warning/10 text-warning`,failed:`border-danger/40 bg-danger/10 text-danger`,unconfirmed:`border-warning/40 bg-warning/10 text-warning`};function $r(){let{t:e}=H(),r=z(),{nodes:c,isLoading:l}=Zr(),[d,f]=Ze(),{selection:p,selectNode:m}=at(c),h=p.node,g=n(()=>c.filter(e=>e.isOnline),[c]),_=g.length,v=c.filter(e=>!e.isOnline).length,y=de(),x=O(),[S,C]=i(!1),[w,T]=i([]),E=d.get(`unlockNode`),k=d.get(`returnTo`),[A,j]=i(null);t(()=>{if(E===null||k===null)return;let e=!1;return(async()=>{try{let t=await x.trpcClient.addons.custom.mutate({addonId:`system-config`,action:`mintAgentUiUnlockTicket`,input:{nodeId:E,dashboardBaseUrl:k}});if(e)return;let n=jt(t),r=n===null?null:n.dashboardUrl??(()=>{let e=new URL(k);return e.searchParams.set(`ticket`,n.ticket),e.toString()})();if(r===null){j(`Could not mint an unlock ticket.`);return}let i=new URLSearchParams(d);i.delete(`unlockNode`),i.delete(`returnTo`),f(i,{replace:!0}),window.location.assign(r)}catch(t){e||j(t instanceof Error?t.message:String(t))}})(),()=>{e=!0}},[E,k,d,f,x.trpcClient]);let M=a(async()=>{let t=g.map(e=>({id:e.id,name:e.name,isHub:e.isHub}));if(await r({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`})){C(!0),T([]);try{T(await Xr(t,{apply:e=>y.mutateAsync(e),readStatus:e=>x.trpcClient.serverManagement.getServerPackageStatus.query(e),wait:e=>new Promise(t=>setTimeout(t,e))}))}finally{C(!1)}}},[y,r,g,x,e]);return o(Qe,{icon:F,title:e(`nav.nodes`,`Nodes`),subtitle:e(`cluster.subtitle`,`One node at a time — topology and packages. Agents join by pairing (certificate, no shared secret).`),actions:o(s,{children:[_>0&&u(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-xs text-success`,children:e(`common.onlineCount`,{count:_})}),v>0&&u(`span`,{className:`rounded-full bg-destructive/10 px-2 py-0.5 text-xs text-destructive`,children:e(`common.offlineCount`,{count:v})}),_>1&&o(R,{type:`button`,size:`sm`,disabled:S,title:e(`serverManagement.updateAllHint`,`Sequenced agents-first, hub-last — up-to-date nodes are skipped.`),onClick:()=>void M(),children:[S?u(D,{className:`h-3.5 w-3.5 animate-spin`}):u(b,{className:`h-3.5 w-3.5`}),e(`serverManagement.updateAll`,`Update all nodes`)]})]}),children:[w.length>0&&u(`ul`,{"aria-label":`update-all-report`,className:`flex flex-col gap-1 text-xs`,children:w.map(e=>o(`li`,{"data-outcome":e.outcome,className:`rounded border px-2 py-1 ${Qr[e.outcome]}`,children:[u(`span`,{className:`font-medium`,children:e.nodeName}),u(`span`,{className:`mx-1 uppercase tracking-wide`,children:e.outcome}),u(`span`,{className:`opacity-80`,children:e.detail})]},e.nodeId))}),A!==null&&o(`p`,{role:`alert`,className:`rounded border border-warning/40 bg-warning/10 px-3 py-2 text-xs text-warning`,children:[e(`system.cluster.unlockFromAgentFailed`,`Unlock from agent failed:`),` `,A]}),u(kt,{onOpenNode:m}),l?u(`div`,{className:`flex items-center justify-center py-12 text-muted-foreground`,children:e(`system.cluster.loadingClusterTopology`,`Loading cluster topology...`)}):h===null?u(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-xs text-foreground-subtle`,children:e(`cluster.noNodes`,`No nodes in this cluster yet.`)}):o(`div`,{className:`flex flex-col gap-3`,children:[u(it,{staleNodeId:p.staleNodeId,shownNodeName:h.name}),u(ge,{selectedNodeId:h.id,onSelect:m,allowOffline:!0,alwaysShow:!0}),u(Hr,{node:h})]})]})}export{$r as ClusterPage};
1
+ import{$ as e,B as t,G as n,H as r,J as i,L as a,S as o,b as s,o as c,q as l,x as u}from"./_virtual_mf___mfe_internal__admin_ui_host__loadShare___mf_0_tanstack_mf_1_react_mf_2_query__loadShare__.js-CEHpkaJP.js";import{Ai as d,Br as f,Cn as p,D as m,Fn as h,It as g,Nt as _,Si as v,Xr as y,Zi as b,bn as x,dn as S,dt as C,fn as w,hi as T,kn as E,or as D,ot as O,pi as k,pn as A,si as j,sn as M,vn as N,xi as ee,xn as te,yi as P,zn as F}from"./player-overlays-CikRdqm6.js";import{$r as ne,Qr as re,ei as ie,ri as ae}from"./client-Ca-96r9I.js";import{t as oe}from"./hard-drive-download-DVmQAuw3.js";import{t as se}from"./memory-stick-DASwwt0F.js";import{t as ce}from"./unlink-CLHtJAsY.js";import{$t as le,An as ue,Bc as de,Bn as I,Cu as L,Dt as fe,Gt as pe,Hc as me,J as he,K as ge,Ks as _e,Kt as ve,M as ye,Mn as be,Nn as xe,On as Se,Ot as Ce,Pn as we,Rs as Te,Uc as Ee,Un as R,Vc as De,Vn as Oe,Wt as ke,Xo as Ae,Yo as je,as as Me,bu as Ne,cc as Pe,cr as Fe,dr as Ie,er as z,fr as Le,is as Re,jn as ze,kn as Be,mr as Ve,ns as He,pr as Ue,qt as We,rs as Ge,ru as B,tc as Ke,ul as qe,va as Je,yu as Ye}from"./src-Bt0KiIin.js";import{t as V}from"./i18n-ATfMbes1.js";import{t as H}from"./useTranslation-D3Is_4B6.js";import{C as Xe,tt as Ze}from"./index-CIQcOfrF.js";import{t as Qe}from"./AdminPage-CgbWYJ_a.js";import{t as $e}from"./NodeAddonsSettingsPanel-BfK00QUN.js";import{f as et,l as tt,m as nt,u as rt}from"./board-model-CUEDqTvL.js";import{t as U}from"./format-size-DIxKXxtj.js";import{n as it,t as at}from"./useNodeUrlSelection-D3zWAXku.js";e();var ot={unpaired:`Not paired`,pending:`Pairing…`,paired:`Paired`},st=new Set([`paired`,`rejected`,`failed`,`expired`]);function W(e){return st.has(e)}function ct(e){return e.replace(/\D/g,``).slice(0,6)}function lt(e){return e.length===6}function ut(e,t){let n=Math.max(0,Math.ceil((e-t)/1e3)),r=Math.floor(n/60),i=n%60;return`${r}:${String(i).padStart(2,`0`)}`}function dt(e,t){return e.includes(`:`)?`[${e}]:${t}`:`${e}:${t}`}function ft(e){return e.length<=23?e:`${e.slice(0,20)}…`}function pt({view:e,beginError:t}){if(e===null)return t===null?`sending`:`send-failed`;switch(e.state){case`paired`:return`paired`;case`rejected`:return`rejected`;case`failed`:return`failed`;case`expired`:return`expired`;case`completing`:return`completing`;case`awaiting-confirmation`:return e.hubConfirmed&&!e.agentConfirmed?`awaiting-agent`:e.agentConfirmed&&!e.hubConfirmed?`awaiting-hub`:`awaiting-both`}}function mt(e){return e===`awaiting-both`||e===`awaiting-hub`}var ht={sending:`Sending the pairing offer to the agent…`,"send-failed":`The agent could not be reached`,"awaiting-both":`Waiting for both confirmations`,"awaiting-agent":`Confirmed here — waiting for the agent`,"awaiting-hub":`The agent is confirmed — now confirm here`,completing:`Issuing the node certificate…`,paired:`Paired`,rejected:`Pairing was rejected`,failed:`Pairing failed`,expired:`The pairing expired`},gt=2e3,_t=1e3;function vt(e){return e.message.length>0?e.message:V.t(`pairing.agentsFoundSection.requestFailed`)}function yt(e){return e.length===6?`${e.slice(0,3)} ${e.slice(3)}`:e}function bt(e){let[n,r]=i(()=>Date.now());return t(()=>{if(!e)return;let t=setInterval(()=>r(Date.now()),_t);return()=>clearInterval(t)},[e]),n}function xt({target:e,onClose:n,onSettled:r,onOpenNode:a}){let{t:c}=H(),[d,f]=i(null),[p,m]=i(null),[h,g]=i(``),[_,v]=i(null),y=l(null),b=L.agentPairing.beginPairing.useMutation(),x=L.agentPairing.confirmPairing.useMutation(),S=L.agentPairing.rejectPairing.useMutation();t(()=>{if(e===null){y.current=null,f(null),m(null),g(``),v(null);return}y.current!==e&&(y.current=e,b.mutateAsync({host:e.host,port:e.port}).then(t=>{y.current===e&&f(t.pairingId)}).catch(t=>{y.current===e&&m(vt(t))}))},[e]);let C=L.agentPairing.getPairing.useQuery({pairingId:d??``},{enabled:d!==null,refetchInterval:e=>{let t=e.state.data?.state;return t!==void 0&&W(t)?!1:gt}}),w=St(x.data??S.data??null,C.data??null),T=pt({view:w,beginError:p}),E=w!==null&&W(w.state),O=l(!1);t(()=>{if(!E){O.current=!1;return}O.current||(O.current=!0,r())},[E,r]);let k=bt(w!==null&&!E),A=()=>{d===null||!lt(h)||(v(null),x.mutate({pairingId:d,code:h},{onError:e=>{v(vt(e)),g(``)}}))};return u(Se,{open:e!==null,onOpenChange:e=>!e&&n(),children:o(ue,{width:`md`,placement:`sheet-on-mobile`,scroll:`body`,children:[o(xe,{children:[u(we,{children:c(`pairing.pairingDialog.title`,{node:e?.nodeId??``})}),u(ze,{children:e===null?``:c(`pairing.pairingDialog.eachScreenShowsACode`,`Each screen shows a code; you type the code from the OTHER screen. Agent at {{value1}}`,{value1:dt(e.host,e.port)})})]}),o(Be,{className:`space-y-4`,children:[u(Ct,{phase:T}),T===`send-failed`&&p!==null&&u(I,{title:c(`pairing.pairingDialog.couldNotStartThePairing`,`Could not start the pairing`),message:p}),w!==null&&!E&&u(wt,{view:w,phase:T,now:k,typed:h,onType:e=>g(ct(e)),onSubmit:A,confirmError:_,busy:x.isPending}),T===`paired`&&w!==null&&u(Tt,{nodeId:w.nodeId,onOpenNode:a,onClose:n}),E&&T!==`paired`&&w?.failure!=null&&u(I,{message:w.failure})]}),u(be,{children:E||T===`send-failed`?u(R,{type:`button`,variant:`outline`,onClick:n,children:c(`common.close`,`Close`)}):o(s,{children:[u(R,{type:`button`,variant:`outline`,disabled:S.isPending,onClick:()=>{if(d===null){n();return}S.mutate({pairingId:d},{onSettled:n})},children:c(`pairing.pairingDialog.reject`,`Reject`)}),mt(T)&&o(R,{type:`button`,disabled:!lt(h)||x.isPending,onClick:A,children:[x.isPending&&u(D,{className:`h-4 w-4 animate-spin`}),c(`common.confirm`,`Confirm`)]})]})})]})})}function St(e,t){if(t===null)return e;if(e===null)return t;let n=e=>(W(e.state)?10:e.state===`completing`?5:0)+ +!!e.hubConfirmed+ +!!e.agentConfirmed;return n(e)>n(t)?e:t}function Ct({phase:e}){let t=e===`sending`||e===`completing`,n=e===`paired`,r=e===`rejected`||e===`failed`||e===`expired`||e===`send-failed`;return o(`p`,{role:`status`,className:`flex items-center gap-2 text-sm font-medium ${n?`text-success`:r?`text-danger`:`text-foreground`}`,children:[t&&u(D,{className:`h-4 w-4 animate-spin`}),n&&u(k,{className:`h-4 w-4`}),r&&u(j,{className:`h-4 w-4`}),ht[e]]})}function wt({view:e,phase:t,now:n,typed:r,onType:i,onSubmit:a,confirmError:s,busy:c}){let{t:l}=H();return o(`div`,{className:`space-y-4`,children:[o(`section`,{"aria-label":l(`pairing.pairingDialog.codeOnThisHub`,`Code on this hub`),className:`rounded-md border border-border bg-surface p-3`,children:[u(`p`,{className:`text-xs text-foreground-muted`,children:l(`pairing.pairingDialog.codeOnThisHubRead`,`Code on this hub — read it out to the agent`)}),u(`p`,{"data-testid":`hub-code`,className:`mt-1 font-mono text-3xl font-semibold tracking-widest text-foreground`,children:yt(e.code)}),u(`p`,{className:`mt-2 text-xs text-foreground-muted`,children:l(`pairing.pairingDialog.onTheAgentEnterThis`,`On the agent, enter this code and the agent’s local PIN (shown on the agent’s console or log, or on its own screen).`)})]}),mt(t)?u(`form`,{className:`space-y-2`,onSubmit:e=>{e.preventDefault(),a()},children:u(he,{label:l(`pairing.pairingDialog.codeShownOnTheAgent`,`Code shown on the agent`),description:l(`pairing.pairingDialog.typeTheSixDigitsThe`,`Type the six digits the agent displays. Do not copy the code above.`),...s===null?{}:{error:s},children:u(B,{value:r,onChange:e=>i(e.target.value),inputMode:`numeric`,autoComplete:`off`,spellCheck:!1,placeholder:`000000`,maxLength:6,disabled:c,"aria-label":l(`pairing.pairingDialog.codeShownOnTheAgent`,`Code shown on the agent`),className:`font-mono tracking-widest`})})}):u(`p`,{className:`text-xs text-foreground-muted`,children:t===`awaiting-agent`?l(`pairing.pairingDialog.youConfirmedHereTheAgent`,`You confirmed here. The agent still has to enter the hub code and its PIN.`):l(`pairing.pairingDialog.working`,`Working…`)}),o(`ul`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-xs text-foreground-muted`,children:[u(`li`,{children:e.hubConfirmed?l(`pairing.pairingDialog.hubConfirmed`,`Hub: confirmed`):l(`pairing.pairingDialog.hubNotConfirmed`,`Hub: not confirmed`)}),u(`li`,{children:e.agentConfirmed?l(`pairing.pairingDialog.agentConfirmed`,`Agent: confirmed`):l(`pairing.pairingDialog.agentNotConfirmed`,`Agent: not confirmed`)}),u(`li`,{"data-testid":`countdown`,children:l(`pairing.pairingDialog.expiresIn`,{countdown:ut(e.expiresAt,n)})})]})]})}function Tt({nodeId:e,onOpenNode:t,onClose:n}){let{t:r}=H(),{nodes:i}=Ye(),a=i?.some(t=>t.id===e&&t.isOnline)===!0;return o(`div`,{className:`space-y-2 rounded-md border border-success/40 bg-success/10 p-3 text-sm`,children:[o(`p`,{className:`flex items-center gap-2 text-success`,children:[u(M,{className:`h-4 w-4`}),a?r(`pairing.pairingDialog.joinedAndRegisteredItsCapabilities`,`{{nodeId}} joined and registered its capabilities.`,{nodeId:e}):r(`pairing.pairingDialog.holdsItsCertificateWaitingFor`,`{{nodeId}} holds its certificate. Waiting for it to connect and register its capabilities…`,{nodeId:e})]}),u(R,{type:`button`,size:`sm`,variant:`outline`,disabled:!a,onClick:()=>{n(),t(e)},children:r(`pairing.pairingDialog.openNode`,`Open node`)})]})}var Et={paired:`success`,pending:`warning`,unpaired:`default`};function Dt({state:e,connected:t}){let{t:n}=H();return o(`span`,{className:`inline-flex items-center gap-1.5`,children:[u(Fe,{variant:Et[e],className:`text-[10px]`,children:ot[e]}),e===`paired`&&u(`span`,{className:`text-[10px] text-foreground-muted`,children:t?n(`common.connected`):n(`pairing.agentStateBadge.notConnected`,`not connected`)})]})}e();var G={pending:0,unpaired:1,paired:2};function Ot(e){if(e.trim().length===0)return;let t=Number(e);return Number.isInteger(t)&&t>=1&&t<=65535?t:null}function kt({onOpenNode:e}){let{t}=H(),r=z(),a=L.useUtils(),c=L.agentPairing.listDiscoveredAgents.useQuery(void 0,{refetchInterval:15e3}),[l,d]=i(null),[f,h]=i(null),[g,_]=i(!1),[v,y]=i(``),[b,S]=i(``),[C,w]=i(null),[T,O]=i(!1),k=()=>void a.agentPairing.listDiscoveredAgents.invalidate(),A=L.agentPairing.addAgentByAddress.useMutation({onSuccess:()=>{_(!1),y(``),S(``),w(null),k()},onError:e=>w(e.message)}),j=L.agentPairing.unpairAgent.useMutation({onSuccess:e=>{h({tone:`success`,message:`${e.nodeId}: ${e.next}${e.agentNotified?``:` The agent could not be told; forget the hub on its own page.`}`}),k()},onError:e=>h({tone:`danger`,message:t(`pairing.agentsFoundSection.unpairFailed`,`Unpair failed: {{message}}`,{message:e.message})})}),M=n(()=>(c.data?.agents??[]).toSorted((e,t)=>G[e.state]-G[t.state]),[c.data]),N=async()=>{O(!0);try{await a.agentPairing.listDiscoveredAgents.fetch({refresh:!0}),k()}finally{O(!1)}},ee=()=>{let e=Ot(b);if(e===null){w(`The port must be a whole number between 1 and 65535.`);return}w(null),A.mutate({host:v.trim(),...e===void 0?{}:{port:e}})},te=async e=>{await r({title:t(`pairing.agentsFoundSection.unpair`,`Unpair {{nodeId}}`,{nodeId:e.nodeId}),message:t(`pairing.agentsFoundSection.sCertificatesAreRevokedAt`,`{{nodeId}}'s certificates are revoked at once and it is disconnected from the mesh. It must be paired again before it can rejoin.`,{nodeId:e.nodeId}),confirmLabel:t(`pairing.agentsFoundSection.unpair2`,`Unpair`),variant:`danger`})&&(h(null),j.mutate({nodeId:e.nodeId}))},P=n(()=>[{key:`node`,header:t(`pairing.agentsFoundSection.node`,`Node`),render:e=>u(`span`,{className:`font-medium text-foreground`,children:e.nodeId}),sortValue:e=>e.nodeId},{key:`address`,header:t(`pairing.agentsFoundSection.address`,`Address`),render:e=>u(`span`,{className:`font-mono text-xs`,children:dt(e.host,e.port)}),sortValue:e=>e.host},{key:`version`,header:t(`pairing.agentsFoundSection.version`,`Version`),render:e=>e.version??`—`,sortValue:e=>e.version},{key:`state`,header:t(`pairing.agentsFoundSection.state`,`State`),render:e=>u(Dt,{state:e.state,connected:e.connected}),sortValue:e=>G[e.state]},{key:`fingerprint`,header:t(`pairing.agentsFoundSection.certificate`,`Certificate`),render:e=>e.fingerprint===null?`—`:u(`span`,{className:`font-mono text-xs`,title:e.fingerprint,children:ft(e.fingerprint)}),sortValue:e=>e.fingerprint},{key:`actions`,header:``,align:`right`,notSortableReason:`Row actions`,render:e=>e.state===`unpaired`?u(R,{type:`button`,size:`sm`,onClick:()=>d({nodeId:e.nodeId,host:e.host,port:e.port}),children:t(`pairing.agentsFoundSection.pair`,`Pair`)}):e.state===`paired`?u(R,{type:`button`,size:`sm`,variant:`outline`,disabled:j.isPending,onClick:()=>void te(e),children:t(`pairing.agentsFoundSection.unpair2`,`Unpair`)}):null}],[j.isPending,t]);return o(ke,{headingId:`agents-found`,title:t(`pairing.agentsFoundSection.agentsFoundOnTheNetwork`,`Agents found on the network`),icon:p,testId:`agents-found`,actions:o(s,{children:[o(R,{type:`button`,size:`sm`,variant:`outline`,disabled:T,onClick:()=>void N(),children:[T?u(D,{className:`h-3.5 w-3.5 animate-spin`}):u(x,{className:`h-3.5 w-3.5`}),t(`pairing.agentsFoundSection.scan`,`Scan`)]}),o(R,{type:`button`,size:`sm`,onClick:()=>_(e=>!e),children:[u(E,{className:`h-3.5 w-3.5`}),t(`pairing.agentsFoundSection.addByAddress`,`Add by address`)]})]}),children:[o(`div`,{className:`${m} space-y-3`,children:[u(`p`,{className:`text-[11px] leading-relaxed text-foreground-muted`,children:t(`pairing.agentsFoundSection.anAgentHoldsNoSecret`,`An agent holds no secret: pairing issues it a certificate after you confirm the same six digits on this page and on the agent. Discovery needs the agent on its own IP or host networking; a Docker bridge hides it — add it by address.`)}),g&&o(`form`,{"aria-label":t(`pairing.agentsFoundSection.addAgentByAddress`,`Add agent by address`),className:`flex flex-wrap items-start gap-2`,onSubmit:e=>{e.preventDefault(),v.trim().length>0&&!A.isPending&&ee()},children:[u(he,{label:t(`pairing.agentsFoundSection.address`,`Address`),description:t(`pairing.agentsFoundSection.aPrivateOrLocalAddress`,`A private or local address only.`),...C===null?{}:{error:C},children:u(B,{value:v,onChange:e=>y(e.target.value),placeholder:`192.168.1.50`,"aria-label":t(`pairing.agentsFoundSection.agentAddress`,`Agent address`),autoComplete:`off`})}),u(he,{label:t(`pairing.agentsFoundSection.port`,`Port`),description:t(`pairing.agentsFoundSection.optional`,`Optional.`),children:u(B,{value:b,onChange:e=>S(e.target.value),placeholder:`4444`,inputMode:`numeric`,"aria-label":t(`pairing.agentsFoundSection.agentPort`,`Agent port`),className:`w-24`})}),o(R,{type:`submit`,size:`sm`,className:`mt-5`,disabled:v.trim().length===0||A.isPending,children:[A.isPending&&u(D,{className:`h-3.5 w-3.5 animate-spin`}),t(`common.add`,`Add`)]})]}),f!==null&&u(`p`,{role:`status`,className:`rounded border px-3 py-2 text-xs ${f.tone===`success`?`border-success/30 text-foreground`:`border-danger/40 text-danger`}`,children:f.message}),c.isError?u(I,{title:t(`pairing.agentsFoundSection.couldNotListAgents`,`Could not list agents`),message:c.error?.message??t(`pairing.agentsFoundSection.requestFailed`,`Request failed`),onRetry:k}):c.isLoading?u(`p`,{className:`py-4 text-center text-xs text-foreground-muted`,children:t(`pairing.agentsFoundSection.lookingForAgents`,`Looking for agents…`)}):M.length===0?u(Oe,{icon:p,title:t(`pairing.agentsFoundSection.noAgentsFound`,`No agents found`),description:t(`pairing.agentsFoundSection.nothingIsAdvertisingOnThis`,`Nothing is advertising on this network. Start the agent on its own IP (or host networking), or add it by address.`)}):u(ve,{columns:P,rows:M,rowKey:e=>e.nodeId,minWidthPx:720,defaultSort:{columnKey:`state`,dir:`asc`}})]}),u(xt,{target:l,onClose:()=>d(null),onSettled:k,onOpenNode:e})]})}function At(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function jt(e){if(!At(e))return null;let t=e.ticket;if(typeof t!=`string`||t.length===0)return null;let n=e.dashboardUrl;return typeof n==`string`&&n.length>0?{ticket:t,dashboardUrl:n}:{ticket:t}}function Mt(e){let t=e.trim();return!(t.length===0||t.includes(`/`)||t.includes(`?`)||t.includes(`#`)||t.includes(`@`)||t.includes(`:`))}function K(e){return e.startsWith(`172.17.`)}function Nt(e){let t=/^100\.(\d+)\./.exec(e);if(t===null)return!1;let n=Number(t[1]);return n>=64&&n<=127}function Pt(e){if(e.startsWith(`10.`)||e.startsWith(`192.168.`))return!0;let t=/^172\.(\d+)\./.exec(e);if(t===null)return!1;let n=Number(t[1]);return n>=16&&n<=31&&!K(e)}function Ft(e,t){if(typeof t==`string`&&Mt(t))return t.trim();let n=e.filter(e=>!e.includes(`:`)),r=n.find(e=>!e.startsWith(`127.`)&&!e.startsWith(`169.254.`)&&!K(e)&&!Nt(e)&&Pt(e));if(r!==void 0)return r;for(let e of n)if(!e.startsWith(`127.`)&&!e.startsWith(`169.254.`)&&!K(e))return e;return null}function It(e){return`http://${e}:4444/`}function Lt(e,t){let n=new URL(It(e));return n.searchParams.set(`ticket`,t),n.toString()}function Rt(){return window.open(`about:blank`,`_blank`)}function zt(e,t){return e===null||e.closed?!1:(e.location.href=t,!0)}function Bt({node:e}){let{info:t}=Xe();return!e.isHub||t===null?u(`span`,{className:`text-sm font-semibold shrink-0`,children:e.name}):o(s,{children:[u(`span`,{className:`text-sm font-semibold shrink-0`,"data-testid":`node-title-name`,children:t.name}),t.name!==e.id&&u(`span`,{className:`text-xs text-foreground-subtle shrink-0`,"data-testid":`node-title-id`,children:e.id})]})}e();function Vt(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 Ht(e){return e===`running`?`running`:e===`crashed`||e===`failed`?`error`:`stopped`}var Ut=[`trace`,`debug`,`info`,`warn`,`error`];function Wt({proc:e,nodeId:t,defaultExpanded:n,activePanel:r,onTogglePanel:a}){let{t:s}=H(),c=e.services??[],l=c.length===1,[f,p]=i(l||n),[m,h]=i(null),[g,_]=i(`info`),v=e.name.includes(`(core)`),y=Ge(),b=Re(),x=Me(),C=async e=>{h(e);try{await y.mutateAsync({nodeId:t,addonId:e})}catch(e){console.error(`Failed to restart addon:`,e)}finally{h(null)}},w=async()=>{h(e.name);try{await b.mutateAsync({nodeId:t,processName:e.name})}catch(e){console.error(`Failed to restart process:`,e)}finally{h(null)}},T=async n=>{let r=`${t}/${e.name}`;try{await x.mutateAsync({nodeId:r,level:n}),_(n)}catch(e){console.error(`Failed to set log level:`,e)}};return o(`div`,{className:`border border-border/50 rounded-lg overflow-hidden`,children:[o(`div`,{role:l?void 0:`button`,tabIndex:l?void 0:0,onClick:l?void 0:()=>p(!f),onKeyDown:l?void 0:e=>{(e.key===`Enter`||e.key===` `)&&p(!f)},className:`flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 w-full px-3 py-2 bg-muted/20 transition-colors text-left select-none ${l?``:`hover:bg-muted/40 cursor-pointer`}`,children:[l?u(`span`,{className:`h-3 w-3 shrink-0`}):u(f?ee:P,{className:`h-3 w-3 text-muted-foreground shrink-0`}),v?u(S,{className:`h-3.5 w-3.5 text-primary shrink-0`}):u(d,{className:`h-3.5 w-3.5 text-warning shrink-0`}),u(`span`,{className:`text-xs font-semibold min-w-0 flex-1 basis-full truncate sm:basis-auto`,children:e.name}),o(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0`,children:[`PID `,e.pid]}),u(ye,{status:Ht(e.state),label:e.state}),u(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0`,children:s(`cluster.forksTab.cpu`,{percent:e.cpuPercent})}),u(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0`,children:U(e.memoryRss)}),u(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0`,children:Vt(e.uptimeSeconds)}),!v&&o(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[o(Ie,{children:[u(Ve,{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:s(`cluster.forksTab.setLogLevel`,`Set log level`),children:g}),u(Le,{align:`end`,className:`min-w-[70px] py-0.5`,children:Ut.map(e=>u(Ue,{onClick:()=>T(e),className:`h-auto px-2 py-1 text-[10px] font-mono ${e===g?`text-primary font-semibold`:``}`,children:e},e))})]}),u(`button`,{onClick:w,disabled:m===e.name,className:`p-1 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:s(`cluster.forksTab.restartProcess`,`Restart process`),children:u(N,{className:`h-3 w-3 ${m===e.name?`animate-spin`:``}`})})]})]}),f&&c.length>0&&u(`div`,{className:`divide-y divide-border/30`,children:c.map(e=>o(`div`,{children:[o(`div`,{className:`flex items-center gap-2 px-3 py-1.5 pl-9 hover:bg-muted/10 transition-colors`,children:[u(`div`,{className:`h-1.5 w-1.5 rounded-full shrink-0 ${e.status===`running`?`bg-success`:`bg-muted-foreground/30`}`}),u(`span`,{className:`text-xs font-medium flex-1 min-w-0 truncate`,children:e.addonId}),e.capabilities.length>0&&o(`div`,{className:`flex gap-1 flex-shrink-0`,children:[e.capabilities.slice(0,3).map(e=>u(`span`,{className:`text-[9px] px-1 py-0.5 rounded bg-info/10 text-info truncate max-w-[80px]`,children:e},e)),e.capabilities.length>3&&o(`span`,{className:`text-[9px] text-muted-foreground`,children:[`+`,e.capabilities.length-3]})]}),o(`div`,{className:`flex items-center gap-1 shrink-0`,children:[u(`button`,{onClick:()=>a(e.addonId,`logs`),className:`p-0.5 rounded transition-colors ${r?.addonId===e.addonId&&r.type===`logs`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:s(`cluster.forksTab.showLogsFor`,`Show logs for {{addonId}}`,{addonId:e.addonId}),children:u(A,{className:`h-3 w-3`})}),u(`button`,{onClick:()=>a(e.addonId,`events`),className:`p-0.5 rounded transition-colors ${r?.addonId===e.addonId&&r.type===`events`?`bg-primary/10 text-primary`:`hover:bg-muted text-muted-foreground hover:text-foreground`}`,title:s(`cluster.forksTab.showEventsFor`,`Show events for {{addonId}}`,{addonId:e.addonId}),children:u(te,{className:`h-3 w-3`})}),u(`button`,{onClick:()=>C(e.addonId),disabled:m===e.addonId,className:`p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50`,title:s(`cluster.forksTab.restart`,`Restart {{addonId}}`,{addonId:e.addonId}),children:u(N,{className:`h-3 w-3 ${m===e.addonId?`animate-spin`:``}`})})]})]}),r?.addonId===e.addonId&&r.type===`logs`&&u(`div`,{className:`border-t border-border/40 bg-muted/5`,children:u(Ce,{addonId:e.addonId,agentId:t,maxHeight:`max-h-48`,showFilters:!1,onClose:()=>a(e.addonId,`logs`)})}),r?.addonId===e.addonId&&r.type===`events`&&u(`div`,{className:`border-t border-border/40 bg-muted/5`,children:u(fe,{addonId:e.addonId,category:`addon.*`,maxHeight:`max-h-48`,onClose:()=>a(e.addonId,`events`)})})]},e.addonId))}),f&&c.length===0&&u(`div`,{className:`px-3 py-2 pl-9 text-[10px] text-muted-foreground`,children:s(`cluster.forksTab.noServices`,`No services`)})]})}function Gt({nodeId:e,processes:t}){let{t:n}=H(),[r,a]=i(null),o=(e,t)=>{a(n=>n?.addonId===e&&n.type===t?null:{addonId:e,type:t})};return t.length===0?u(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:n(`cluster.forksTab.noProcessesOnThisNode`,`No processes on this node`)}):u(`div`,{className:`space-y-2 py-1`,children:t.map((t,n)=>u(Wt,{proc:t,nodeId:e,defaultExpanded:n===0,activePanel:r,onTogglePanel:o},t.name))})}var Kt={system:0,managed:1,root:2};e();function qt(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 Jt(e,t=80){return e.length<=t?e:`…${e.slice(e.length-t+1)}`}function Yt({nodeId:e}){let{t}=H(),r=c(),i=Ne(`metrics.node-processes-snapshot`,t=>t.nodeId===e),{data:a}=Ae({nodeId:e}),s=i?.processes??a,l=n(()=>s?[...s]:[],[s]),d=n(()=>[{key:`classification`,header:t(`cluster.processesTab.class`,`Class`),sortValue:e=>Kt[e.classification],render:e=>u(`span`,{className:`inline-block rounded-full px-1.5 py-0.5 text-[10px] font-medium ${e.classification===`root`?`bg-info/20 text-info`:e.classification===`system`?`bg-foreground-subtle/20 text-foreground-subtle`:`bg-success/20 text-success`}`,children:e.classification})},{key:`pid`,header:`PID`,align:`right`,sortValue:e=>e.pid,render:e=>u(`span`,{className:`font-mono`,children:e.pid})},{key:`ppid`,header:`PPID`,align:`right`,sortValue:e=>e.ppid,render:e=>u(`span`,{className:`font-mono text-foreground-subtle`,children:e.ppid})},{key:`addonId`,header:t(`cluster.processesTab.addon`,`Addon`),sortValue:e=>e.addonId,render:e=>u(`span`,{className:`text-foreground-subtle text-[11px]`,children:e.addonId??`—`})},{key:`command`,header:t(`cluster.processesTab.command`,`Command`),nowrap:!1,render:e=>u(`span`,{className:`font-mono text-[10px] text-foreground-subtle break-all`,children:Jt(e.command)})},{key:`cpuPercent`,header:t(`cluster.processesTab.cpu`,`CPU%`),align:`right`,sortValue:e=>e.cpuPercent,render:e=>e.cpuPercent.toFixed(1)},{key:`memoryRssBytes`,header:`RSS`,align:`right`,sortValue:e=>e.memoryRssBytes,render:e=>U(e.memoryRssBytes)},{key:`uptimeSec`,header:t(`cluster.processesTab.uptime`,`Uptime`),align:`right`,sortValue:e=>e.uptimeSec,render:e=>u(`span`,{className:`text-foreground-subtle`,children:qt(e.uptimeSec)})}],[t]);return o(`div`,{className:`space-y-4`,children:[u(`div`,{className:`flex items-start justify-end gap-4`,children:o(`button`,{type:`button`,onClick:()=>r.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:[u(x,{className:`h-3 w-3`}),` `,t(`common.refresh`)]})}),u(ve,{columns:d,rows:l,rowKey:e=>e.pid,minWidthPx:880,maxBodyHeight:We,emptyMessage:t(`cluster.processesTab.scanning`,`Scanning…`)})]})}var q={width:320,height:64},Xt=.8,J=Math.ceil(8*Xt-3)+1,Y=q.width+34,Zt=q.height+J+1+11,Qt=J+q.height+1+3+Math.ceil(8*Xt),$t=[1,2,5,10],en=[1,2,4,8,16,32,64,128,256,512,1024],tn=[1,1.5,2,2.5,3,4,5],nn=[4,3,5,2],rn=1e-9;function an(e,t){if(!Number.isFinite(e)||e<=0)return!1;if(t===`bytes`){if(!Number.isInteger(e))return!1;let t=e/1024**Math.floor(Math.log(e)/Math.log(1024));return tn.some(e=>Math.abs(t-e)<rn)}let n=e/10**Math.floor(Math.log10(e));return tn.some(e=>Math.abs(n-e)<rn)}function on(e,t,n){let r=0;for(let t of e)t!==null&&t>r&&(r=t);if(r<=t)return t;if(n===`bytes`){let e=1024**Math.floor(Math.log(r)/Math.log(1024));for(let t of en){let n=t*e;if(n>=r)return n}return 1024*e}let i=10**Math.floor(Math.log10(r));for(let e of $t){let t=e*i;if(t>=r)return t}return 10*i}function sn(e,t){if(!Number.isFinite(e)||e<=0)return[];let n=nn.find(n=>an(e/n,t))??nn[nn.length-1],r=e/n,i=[];for(let e=1;e<=n;e++)i.push(r*e);return i}var cn=2.5;function ln(e){return e*cn}function un(e,t,n,r){if(e.length===0)return[];let i=e[0].atMs,a=e.at(-1).atMs-i,o=n<=0?1:n,s=r!==void 0&&r>0?r:null;return e.map((r,c)=>{let l=a>0?(r.atMs-i)/a*t.width:c/Math.max(1,e.length-1)*t.width,u=c>0?e[c-1]:void 0;return{x:l,y:r.value===null?null:t.height-Math.min(r.value,n)/o*t.height,gapBefore:s!==null&&u!==void 0&&r.atMs-u.atMs>s}})}function dn(e){let t=[],n=!1;for(let r of e){if(r.y===null){n=!1;continue}r.gapBefore&&(n=!1),t.push(`${n?`L`:`M`}${r.x.toFixed(1)},${r.y.toFixed(1)}`),n=!0}return t.join(` `)}function fn(e,t){let n=[],r=[],i=()=>{if(r.length<2){r=[];return}let e=r.map((e,t)=>`${t===0?`M`:`L`}${e.x.toFixed(1)},${e.top.toFixed(1)}`),t=[...r].reverse().map(e=>`L${e.x.toFixed(1)},${e.bottom.toFixed(1)}`);n.push(`${e.join(` `)} ${t.join(` `)} Z`),r=[]};for(let n=0;n<e.length;n++){let a=e[n],o=t[n];if(!a||!o||a.y===null||o.y===null){i();continue}(a.gapBefore||o.gapBefore)&&i(),r.push({x:a.x,top:a.y,bottom:o.y})}return i(),n.join(` `)}function pn(e,t,n=3){if(e.length<2||n<2)return[];let r=e[0].atMs,i=e.at(-1).atMs-r;if(i<=0)return[];let a=[];for(let e=0;e<n;e++){let o=e/(n-1);a.push({atMs:r+i*o,x:o*t.width,anchor:e===0?`start`:e===n-1?`end`:`middle`})}return a}function mn(e){return e.length<2?0:Math.max(0,e.at(-1).atMs-e[0].atMs)}function hn(e){let t=[];for(let n=1;n<e.length;n++){let r=e[n];r.gapBefore&&t.push({fromX:e[n-1].x,toX:r.x})}return t}function gn(e,t){if(e.length===0)return null;let n=0,r=1/0;for(let i=0;i<e.length;i++){let a=Math.abs(e[i].x-t);a<r&&(r=a,n=i)}return n}e();var X={main:`var(--color-chart-series-a)`,gc:`var(--color-chart-series-b)`},Z=q,_n={height:Zt};function vn({title:e,points:t,mainLabel:a,gcLabel:c,formatValue:d,emptyMessage:f,gapMs:p}){let{t:m}=H(),h=r(),g=l(null),[_,v]=i(null),y=n(()=>{let e=t.map(e=>({atMs:e.atMs,value:e.main===null||e.gc===null?null:e.main+e.gc})),n=t.map(e=>({atMs:e.atMs,value:e.main})),r=on(e.map(e=>e.value),25,`linear`),i=un(e,Z,r,p),a=un(n,Z,r,p),o=a.map(e=>({x:e.x,y:e.y===null?null:Z.height,gapBefore:e.gapBefore}));return{max:r,ticks:sn(r,`linear`),upper:i,middle:a,base:o,gaps:hn(i),times:pn(e,Z),spanMs:mn(e)}},[t,p]),b=t.at(-1),x=_===null?void 0:t[_.index],S=x??b;return t.length===0||y.upper.every(e=>e.y===null)?u(Q,{title:e,children:u(An,{message:f})}):u(Q,{title:e,legend:o(s,{children:[u(On,{color:X.main,label:a}),u(On,{color:X.gc,label:c})]}),readout:S&&S.main!==null&&S.gc!==null?o(s,{children:[x!==void 0&&u(Dn,{atMs:x.atMs,spanMs:y.spanMs}),u(kn,{color:X.main,text:d(S.main)}),u(kn,{color:X.gc,text:d(S.gc)})]}):null,children:o(`svg`,{ref:g,viewBox:`0 0 ${Y} ${Zt}`,preserveAspectRatio:`none`,className:`w-full`,style:_n,role:`img`,"aria-label":m(`load.loadChart.andOverTime`,`{{title}}: {{mainLabel}} and {{gcLabel}} over time`,{title:e,mainLabel:a,gcLabel:c}),onMouseLeave:()=>v(null),onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();if(t.width===0)return;let n=(e.clientX-t.left)/t.width*Y-34,r=gn(y.upper,n);r!==null&&v({index:r,xPx:y.upper[r].x})},children:[u(bn,{ticks:y.ticks,max:y.max,formatValue:d}),u(En,{ticks:y.times,spanMs:y.spanMs}),o(`g`,{transform:`translate(34,${J})`,clipPath:`url(#${h})`,children:[u(`clipPath`,{id:h,children:u(`rect`,{x:0,y:0,width:Z.width,height:Z.height})}),u(xn,{spans:y.gaps}),u(`path`,{d:fn(y.middle,y.base),fill:X.main,fillOpacity:.85}),u(`path`,{d:fn(y.upper,y.middle),fill:X.gc,fillOpacity:.85,stroke:`var(--color-surface, transparent)`,strokeWidth:2}),u(`path`,{d:dn(y.upper),fill:`none`,stroke:X.gc,strokeWidth:2}),_!==null&&u(`line`,{x1:_.xPx,x2:_.xPx,y1:0,y2:Z.height,stroke:`currentColor`,strokeWidth:1,className:`text-foreground-subtle`})]})]})})}function yn({title:e,points:t,formatValue:r,emptyMessage:a,axisFloor:c,axisScale:d=`linear`,gapMs:f}){let p=l(null),[m,h]=i(null),g=n(()=>{let e=on(t.map(e=>e.value),c,d),n=un(t,Z,e,f);return{max:e,ticks:sn(e,d),projected:n,gaps:hn(n),times:pn(t,Z),spanMs:mn(t)}},[t,c,d,f]),_=m===null?void 0:t[m.index],v=_??t.at(-1)??void 0;return t.length===0||g.projected.every(e=>e.y===null)?u(Q,{title:e,children:u(An,{message:a})}):u(Q,{title:e,readout:v&&v.value!==null?o(s,{children:[_!==void 0&&u(Dn,{atMs:_.atMs,spanMs:g.spanMs}),u(kn,{color:X.main,text:r(v.value)})]}):null,children:o(`svg`,{ref:p,viewBox:`0 0 ${Y} ${Zt}`,preserveAspectRatio:`none`,className:`w-full`,style:_n,role:`img`,"aria-label":e,onMouseLeave:()=>h(null),onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect();if(t.width===0)return;let n=(e.clientX-t.left)/t.width*Y-34,r=gn(g.projected,n);r!==null&&h({index:r,xPx:g.projected[r].x})},children:[u(bn,{ticks:g.ticks,max:g.max,formatValue:r}),u(En,{ticks:g.times,spanMs:g.spanMs}),o(`g`,{transform:`translate(34,${J})`,children:[u(xn,{spans:g.gaps}),u(`path`,{d:dn(g.projected),fill:`none`,stroke:X.main,strokeWidth:2}),m!==null&&u(`line`,{x1:m.xPx,x2:m.xPx,y1:0,y2:Z.height,stroke:`currentColor`,strokeWidth:1,className:`text-foreground-subtle`})]})]})})}function bn({ticks:e,max:t,formatValue:n}){let r=t<=0?1:t;return u(`g`,{className:`text-foreground-subtle`,children:e.map(e=>{let t=J+Z.height-e/r*Z.height;return o(`g`,{children:[u(`line`,{x1:34,x2:34+Z.width,y1:t,y2:t,stroke:`currentColor`,strokeWidth:.5,strokeOpacity:.3}),u(`text`,{x:0,y:t+3,fontSize:8,fill:`currentColor`,children:n(e)})]},e)})})}function xn({spans:e}){let{t}=H();return e.length===0?null:u(`g`,{className:`text-foreground-subtle`,children:e.map(e=>u(`rect`,{x:e.fromX,y:0,width:Math.max(1,e.toX-e.fromX),height:Z.height,fill:`currentColor`,fillOpacity:.12,children:u(`title`,{children:t(`load.loadChart.noSamplesInThisInterval`,`No samples in this interval — nothing was measured, nothing is drawn.`)})},`${e.fromX}-${e.toX}`))})}var Sn=10*6e4,Cn={hour:`2-digit`,minute:`2-digit`},wn={hour:`2-digit`,minute:`2-digit`,second:`2-digit`};function Tn(e,t){return new Date(e).toLocaleTimeString(void 0,t<Sn?wn:Cn)}function En({ticks:e,spanMs:t}){return e.length===0?null:u(`g`,{className:`text-foreground-subtle`,children:e.map(e=>u(`text`,{x:34+e.x,y:Qt,fontSize:8,textAnchor:e.anchor,fill:`currentColor`,children:Tn(e.atMs,t)},e.atMs))})}function Dn({atMs:e,spanMs:t}){return u(`span`,{className:`text-[10px] tabular-nums text-foreground-subtle`,children:Tn(e,t)})}function Q({title:e,legend:t,readout:n,children:r}){return o(`div`,{className:`min-w-0`,children:[o(`div`,{className:`flex items-baseline justify-between gap-2 mb-1`,children:[u(`span`,{className:`text-[10px] uppercase tracking-wider text-foreground-subtle`,children:e}),u(`div`,{className:`flex items-center gap-2`,children:n})]}),r,t&&u(`div`,{className:`flex items-center gap-3 mt-1`,children:t})]})}function On({color:e,label:t}){return o(`span`,{className:`inline-flex items-center gap-1 text-[9px] text-foreground-subtle`,children:[u(`span`,{className:`inline-block h-2 w-2 rounded-[2px]`,style:{backgroundColor:e}}),t]})}function kn({color:e,text:t}){return o(`span`,{className:`inline-flex items-center gap-1 text-[11px] tabular-nums text-foreground`,children:[u(`span`,{className:`inline-block h-2 w-2 rounded-[2px]`,style:{backgroundColor:e}}),t]})}function An({message:e}){return u(`div`,{className:`h-16 flex items-center justify-center rounded border border-dashed border-border text-[10px] text-foreground-subtle text-center px-2`,children:e})}function jn(e,t){let n=e.at(-1);return n===void 0?[t]:t.atMs>n.atMs?[...e,t]:e.some(e=>e.atMs===t.atMs)?e:[...e,t].toSorted((e,t)=>e.atMs-t.atMs)}function Mn(e,t,n,r){let i=e.get(t),a=jn(i?.points??[],r);if(i!==void 0&&a===i.points)return e;let o=new Map(e);return o.set(t,{key:t,kind:n,points:a.slice(Math.max(0,a.length-720))}),o}function Nn(e,t,n){let r=e;for(let e of ae(t,n))r=Mn(r,e.key,e.kind,e.point);return r}function Pn(e,t){let n=e;for(let e of t)for(let t of e.points)n=Mn(n,e.key,e.kind,t);return n}function Fn(e){let t=null;for(let n of e.values()){let e=n.points.at(-1);e!==void 0&&(t===null||e.atMs>t)&&(t=e.atMs)}return t}var In=12e4;function Ln(e,t){return e===null?!1:t-e>In}function Rn(e){let t=e=>{let t=e.points.at(-1);return t===void 0?-1:t.cpuMainPercent!==null&&t.cpuGcPercent!==null?t.cpuMainPercent+t.cpuGcPercent:t.cpuLifetimePercent};return[...e.values()].toSorted((e,n)=>{let r=t(n)-t(e);return r===0?e.key.localeCompare(n.key):r})}function zn(e){for(let t of e.values()){let e=t.points.at(-1);if(e&&e.cpuMainPercent!==null)return!0}return!1}var Bn={key:`cpu`,dir:`desc`};function Vn(e){let t=e.points.at(-1);return t===void 0?null:t.cpuMainPercent!==null&&t.cpuGcPercent!==null?t.cpuMainPercent+t.cpuGcPercent:t.cpuLifetimePercent}function Hn(e){return e.points.at(-1)?.memoryRssBytes??null}function Un(e,t,n){let r=n.trim().toLowerCase();return r===``?!0:e.toLowerCase().includes(r)||t.toLowerCase().includes(r)}function Wn(e,t){return t===`memory`?Hn(e):Vn(e)}function Gn(e,t,n){let r=e.filter(e=>t.selectedKeys.size>0&&!t.selectedKeys.has(e.key)?!1:Un(n(e),e.key,t.search)),i=(e,t)=>e.key.localeCompare(t.key);return[...r].toSorted((e,r)=>{if(t.sort.key===`name`){let a=n(e).localeCompare(n(r)),o=t.sort.dir===`asc`?a:-a;return o===0?i(e,r):o}let a=Wn(e,t.sort.key),o=Wn(r,t.sort.key);if(a===null&&o===null)return i(e,r);if(a===null)return 1;if(o===null)return-1;let s=t.sort.dir===`desc`?o-a:a-o;return s===0?i(e,r):s})}e();function Kn(e,n=720){let r=Ne(`metrics.node-processes-snapshot`,t=>t.nodeId===e),[a,o]=i(new Map),[s,c]=i(void 0),u=l(null),{data:d,isPending:f}=je({forNodeId:e,sinceMs:s,maxPoints:n});t(()=>{d!==void 0&&o(e=>{let t=Pn(e,d.series);return u.current=Fn(t),t})},[d]);let p=r?.timestamp;t(()=>{r==null||p===void 0||(Ln(u.current,p)&&c(u.current??0),o(e=>{let t=Nn(e,r.processes,p);return u.current=Fn(t),t}))},[p]),t(()=>{o(new Map),c(void 0),u.current=null},[e]);let m=0;for(let e of a.values())m=Math.max(m,e.points.length);return{series:Rn(a),sampleCount:m,threadSplitAvailable:zn(a),loadingRetained:f,durable:d?.durable??null,bucketMs:d?.bucketMs??null,cadenceMs:d?.cadenceMs??null,retainedSamples:d?.retainedSamples??null}}var qn=`__unclaimed__`;function Jn(e,t){return{kind:e,deviceId:t,cpu:0,cpuKnown:!0,rss:0,rssKnown:!0,count:0,roles:new Set}}function Yn(e,t){return{key:e,kind:t.kind,deviceId:t.deviceId,cpuSeconds:t.cpuKnown?Math.round(t.cpu*100)/100:null,rssBytes:t.rssKnown?t.rss:null,unitCount:t.count,roles:[...t.roles].sort()}}function Xn(e,t){let n=new Map,r=new Set;for(let t of e){t.pid!==void 0&&r.add(t.pid);let e=t.deviceId!==null&&t.attribution!==`unattributable`,i=e?`device:${t.deviceId}`:`shared:${t.role}`,a=n.get(i)??Jn(e?`camera`:`shared`,e?t.deviceId:null);a.count+=1,a.roles.add(t.role),t.cpuSeconds===void 0?a.cpuKnown=!1:a.cpu+=t.cpuSeconds,t.rssBytes===void 0?a.rssKnown=!1:a.rss+=t.rssBytes,n.set(i,a)}let i=[...n.entries()].map(([e,t])=>Yn(e,t));if(t===void 0)return i;let a=t.filter(e=>!r.has(e.pid));if(a.length===0)return i;let o=Jn(`unclaimed`,null);for(let e of a)o.count+=1,o.rss+=e.memoryRssBytes;return o.cpuKnown=!1,[...i,Yn(qn,o)]}var Zn=[{family:`decode`,attribution:`measured`,unit:`one forked decode-worker child per decode SESSION`,perCamera:!0,wiredToday:!0,missingLink:``,evidence:[`packages/addon-pipeline/src/session-decode/fork-decode-worker.ts:118`,`packages/addon-pipeline/src/session-decode/fork-decode-worker.ts:131`,`packages/addon-pipeline/src/pipeline-runner/index.ts:2765`,`packages/types/src/process/child-cost-registry.ts:188`]},{family:`transcode`,attribution:`measured`,unit:`one ffmpeg child per (camera, encode plan)`,perCamera:!0,wiredToday:!0,missingLink:``,evidence:[`packages/addon-pipeline/src/stream-broker/stream-broker/egress-transcode-manager.ts:960`,`packages/addon-pipeline/src/stream-broker/stream-broker/transcode-egress.ts:282`,`packages/addon-pipeline/src/stream-broker/stream-broker/transcode-egress.ts:324`,`packages/types/src/ffmpeg/sharing-key.ts:139`]},{family:`recording`,attribution:`measured`,unit:`one passthrough ffmpeg per (camera, profile)`,perCamera:!0,wiredToday:!0,missingLink:``,evidence:[`packages/addon-pipeline/src/recorder/addon/segment-writer.ts:33`,`packages/addon-pipeline/src/recorder/addon/segment-writer.ts:217`,`packages/addon-pipeline/src/recorder/addon/segment-writer.ts:279`,`packages/addon-pipeline/src/recorder/addon/recording-controller.ts:1710`]},{family:`detection`,attribution:`accounted`,unit:`a SHARED inference pool per (node, runtime, device) — no per-camera process`,perCamera:!1,wiredToday:!0,missingLink:"Nothing is missing for COUNTING — per-camera inference milliseconds, processed/shed frames and bytes-to-pool are already accumulated. What is missing is any basis for CPU seconds: `deviceId` reaches the pool as a diagnostic label and selects nothing, so cost can only ever be apportioned, never measured. Since 2026-08-27 the pool DECLARES this itself, contributing `deviceId: null` + `attribution: unattributable` rather than leaving an observer to infer it — the renunciation is data, and it is still refused by the chart gate.",evidence:[`packages/addon-pipeline/src/detection-pipeline/provider.ts:540`,`packages/addon-pipeline/src/detection-pipeline/engine/shared-inference-pool.ts:413`,`packages/types/src/interfaces/inference-engine.ts:24`,`packages/addon-pipeline/src/pipeline-runner/timing-sampler.ts:63`,`packages/addon-pipeline/src/pipeline-runner/runner.ts:353`,`packages/addon-pipeline/src/pipeline-runner/runner.ts:849`,`packages/addon-pipeline/src/pipeline-runner/frame-lazy-metrics.ts:100`]},{family:`streaming`,attribution:`measured`,unit:"one StreamBroker per `${deviceId}/${camStreamId}`, with an exact RTP ring byte counter",perCamera:!0,wiredToday:!1,missingLink:"The ffmpeg-backed ingest is now reported per camera, but that is the minority path. `rtpRingBytes` — the exact figure for the in-process case — is maintained on every push and drop and is still private and absent from `getStats()`. The three `EncodedRingBuffer`s track packets and duration and have no byte accumulator at all; the only byte figure they offer is `preRollBudgetBytes`, which is a BUDGET, not an occupancy.",evidence:[`packages/addon-pipeline/src/stream-broker/stream-broker/stream-broker.ts:2895`,`packages/addon-pipeline/src/stream-broker/rtsp/ffmpeg-push-reader.ts:189`,`packages/addon-pipeline/src/stream-broker/stream-broker/stream-broker.ts:494`,`packages/addon-pipeline/src/stream-broker/stream-broker/stream-broker.ts:498`,`packages/addon-pipeline/src/stream-broker/stream-broker/stream-broker.ts:2505`,`packages/addon-pipeline/src/stream-broker/stream-broker/pre-roll.ts:269`]}];function Qn(e){return e.attribution===`measured`&&e.wiredToday}function $n(){let e=new Set;for(let t of Zn)Qn(t)&&e.add(t.family);return e}var er=$n();function tr(e){return!er.has(e.role)||e.deviceId===null?!1:e.attribution===`measured`}function nr(e){return`${e.addonId}${e.role}${e.unit}${e.pid??`-`}`}function rr(){return{cpuSeconds:0,cpuKnown:!0,rssBytes:0,rssKnown:!0,unitCount:0,roles:new Set}}function ir(e,t,n){if(t.cpuSeconds===void 0)return null;if(e===void 0)return t.startedAtMs===void 0||t.startedAtMs<n?null:t.cpuSeconds;if(e.cpuSeconds===void 0||e.startedAtMs===void 0||t.startedAtMs===void 0||e.startedAtMs!==t.startedAtMs)return null;let r=t.cpuSeconds-e.cpuSeconds;return r<0?null:r}function ar(e){return Math.round(e*10)/10}function or(e,t){let n=t.atMs-e.atMs;if(n<=0)return[];let r=n/1e3,i=new Map;for(let t of e.entries)tr(t)&&i.set(nr(t),t);let a=new Map,o=new Set;for(let n of t.entries){if(!tr(n)||n.deviceId===null)continue;let t=nr(n);o.add(t);let r=a.get(n.deviceId)??rr();r.unitCount+=1,r.roles.add(n.role);let s=ir(i.get(t),n,e.atMs);s===null?r.cpuKnown=!1:r.cpuSeconds+=s,n.rssBytes===void 0?r.rssKnown=!1:r.rssBytes+=n.rssBytes,a.set(n.deviceId,r)}for(let[e,t]of i){if(o.has(e)||t.deviceId===null)continue;let n=a.get(t.deviceId);n!==void 0&&(n.cpuKnown=!1)}return[...a.entries()].map(([e,n])=>({deviceId:e,point:{atMs:t.atMs,cpuPercent:n.cpuKnown?ar(n.cpuSeconds/r*100):null,rssBytes:n.rssKnown?n.rssBytes:null,unitCount:n.unitCount,roles:[...n.roles].toSorted()}}))}function sr(e,t){if(t.length===0)return e;let n=new Map(e);for(let e of t){let t=n.get(e.deviceId),r=t?.points.at(-1);if(r!==void 0&&e.point.atMs<=r.atMs)continue;let i=[...t?.points??[],e.point];n.set(e.deviceId,{deviceId:e.deviceId,points:i.slice(Math.max(0,i.length-720))})}return n}function cr(e){let t=e=>{for(let t=e.points.length-1;t>=0;t--){let n=e.points[t]?.cpuPercent;if(n!=null)return n}return-1};return[...e.values()].toSorted((e,n)=>{let r=t(n)-t(e);return r===0?e.deviceId-n.deviceId:r})}function lr(e){let t=e.indexOf(`@`);return t===-1?{addonId:e,nodeId:null}:{addonId:e.slice(0,t),nodeId:e.slice(t+1)}}function ur(e,t){let n=lr(e);return n.nodeId===null?t.isHub:n.nodeId===t.nodeId}function dr(e,t){return e.filter(e=>ur(e.addonId,t))}e();function fr(e){let n=Ne(`metrics.node-processes-snapshot`,t=>t.nodeId===e.nodeId),r=qe(void 0,{staleTime:1/0,refetchOnWindowFocus:!1}),[a,o]=i(new Map),s=l(null),c=l(r.refetch);c.current=r.refetch;let u=n?.timestamp;t(()=>{u!==void 0&&c.current()},[u]),t(()=>{o(new Map),s.current=null},[e.nodeId,e.isHub]);let d=r.data,f=r.dataUpdatedAt;t(()=>{if(d===void 0||f===0)return;let t={atMs:f,entries:dr(d,e)},n=s.current;if(s.current=t,n===null)return;let r=or(n,t);r.length!==0&&o(e=>sr(e,r))},[d,f,e.nodeId,e.isHub]);let p=d===void 0?[]:dr(d,e),m=n?.processes,h=Xn(p,m);return{series:cr(a),unclaimed:h.find(e=>e.kind===`unclaimed`)??null,loading:r.isPending,error:r.error===null?null:r.error.message}}function pr(e){let t=new Map;for(let n of e){let e=n.name?.trim();e===void 0||e===``||t.set(n.id,e)}return t}var mr=25,hr=64*1024*1024,gr=1e4;function _r({scope:e,cadenceMs:t}){let{t:n}=H(),r=fr(e),{data:i=[]}=Je({isCamera:!0,projection:`slim`}),a=pr(i),s=ln(t??gr);return o(`section`,{className:`space-y-3`,children:[r.error!==null&&o(`div`,{className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-[11px] text-destructive`,children:[u(_,{className:`h-3 w-3 mt-0.5 shrink-0`}),u(`span`,{children:n(`cameraLoad.readFailed`,`Could not read the load contributions: {{error}}. This is a failed read, NOT an idle cluster.`,{error:r.error})})]}),u(yr,{unclaimed:r.unclaimed}),r.series.length===0&&r.error===null&&u(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:r.loading?n(`cameraLoad.loading`,`Reading what the addons report…`):n(`cameraLoad.waitingWindow`,`No per-camera window yet.`)}),u(`div`,{className:`space-y-3`,children:r.series.map(e=>o(`div`,{className:`rounded-lg border border-border p-3`,children:[o(`div`,{className:`flex items-baseline justify-between gap-2 mb-2`,children:[u(vr,{deviceId:e.deviceId,name:a.get(e.deviceId)}),u(`span`,{className:`text-[10px] text-foreground-subtle`,children:n(`cameraLoad.unitCount`,`{{count}} unit(s): {{roles}}`,{count:e.points.at(-1)?.unitCount??0,roles:(e.points.at(-1)?.roles??[]).join(`, `)})})]}),o(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[u(yn,{title:n(`cameraLoad.cpuTitle`,`CPU % of one core (delta)`),points:e.points.map(e=>({atMs:e.atMs,value:e.cpuPercent})),formatValue:e=>`${e.toFixed(1)}%`,axisFloor:mr,gapMs:s,emptyMessage:n(`cameraLoad.cpuUnavailable`,`No measurable window yet.`)}),u(yn,{title:n(`cameraLoad.memoryTitle`,`Memory RSS`),points:e.points.map(e=>({atMs:e.atMs,value:e.rssBytes})),formatValue:U,axisFloor:hr,axisScale:`bytes`,gapMs:s,emptyMessage:n(`cameraLoad.memoryUnavailable`,`No memory reported.`)})]})]},e.deviceId))})]})}function vr({deviceId:e,name:t}){let{t:n}=H();return t===void 0?u(`span`,{className:`text-xs font-medium text-foreground`,children:n(`cameraLoad.deviceLabel`,`Camera {{deviceId}}`,{deviceId:e})}):o(`span`,{className:`flex items-baseline gap-1.5 min-w-0`,children:[u(`span`,{className:`text-xs font-medium text-foreground truncate`,children:t}),o(`span`,{className:`shrink-0 text-[10px] font-mono text-foreground-subtle`,children:[`#`,e]})]})}function yr({unclaimed:e}){let{t}=H();return e===null||e.unitCount===0?null:u(`div`,{className:`flex items-center gap-2`,children:u(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded-full bg-warning/10 text-warning font-medium tabular-nums`,children:t(`cameraLoad.unclaimedBadge`,`{{count}} unclaimed · {{rss}}`,{count:e.unitCount,rss:e.rssBytes===null?`—`:U(e.rssBytes)})})})}e();var br=256*1024*1024,xr=1e4;function Sr({nodeId:e,isHub:t}){let{t:r}=H(),{series:a,sampleCount:s,threadSplitAvailable:c,loadingRetained:l,bucketMs:d,cadenceMs:f}=Kn(e),[p,m]=i(``),[h,g]=i(new Set),[v,y]=i(Bn),b=e=>e.key===`__root__`?r(`clusterLoad.bucketRoot`,`Node supervisor`):e.key===`__unattributed__`?r(`clusterLoad.bucketUnattributed`,`Unattributed processes`):e.key,x=ln(d??f??xr),S=n(()=>Gn(a,{search:p,selectedKeys:h,sort:v},b),[a,p,h,v]),T=e=>{g(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})};return o(`div`,{className:`space-y-4`,children:[u(Cr,{bucketMs:d,cadenceMs:f}),!c&&s>0&&o(`div`,{className:`flex items-start gap-2 rounded-md border border-warning/40 bg-warning/5 px-3 py-2 text-[11px] text-warning`,children:[u(_,{className:`h-3 w-3 mt-0.5 shrink-0`}),u(`span`,{children:r(`clusterLoad.noThreadSplit`,`No thread-level CPU split on this node — /proc/<pid>/task is Linux-only, and the first sample after a restart has no window to measure. CPU below falls back to the ps lifetime AVERAGE, which is not a rate.`)})]}),s===0&&u(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:l?r(`clusterLoad.loadingRetained`,`Reading the retained series from this node…`):r(`clusterLoad.waitingFirstSample`,`No retained samples for this node — waiting for the next snapshot (up to 20s). The chart needs two to draw a rate.`)}),a.length>0&&o(`div`,{className:`space-y-2`,children:[o(`div`,{className:`flex flex-wrap items-center gap-2`,children:[o(`label`,{className:`relative flex-1 min-w-[160px]`,children:[u(w,{className:`pointer-events-none absolute left-2 top-1/2 h-3 w-3 -translate-y-1/2 text-foreground-subtle`}),u(`input`,{type:`search`,value:p,onChange:e=>m(e.target.value),placeholder:r(`clusterLoad.searchPlaceholder`,`Find a runner…`),"aria-label":r(`clusterLoad.searchLabel`,`Find a runner`),className:`w-full rounded border border-border bg-background py-1 pl-7 pr-2 text-[11px] text-foreground placeholder:text-foreground-subtle`})]}),u(wr,{sort:v,onChange:y})]}),o(`div`,{className:`flex flex-wrap items-center gap-1`,children:[a.map(e=>{let t=h.has(e.key);return u(`button`,{type:`button`,"aria-pressed":t,onClick:()=>T(e.key),className:`rounded-full border px-2 py-0.5 text-[10px] transition-colors ${t?`border-primary bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground`}`,children:b(e)},e.key)}),h.size>0&&o(`button`,{type:`button`,onClick:()=>g(new Set),className:`inline-flex items-center gap-1 rounded-full border border-border px-2 py-0.5 text-[10px] text-foreground-subtle hover:text-foreground`,children:[u(C,{className:`h-2.5 w-2.5`}),r(`clusterLoad.clearFilter`,`All runners`)]})]})]}),a.length>0&&S.length===0&&u(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-[11px] text-foreground-subtle`,children:r(`clusterLoad.noMatches`,`No runner matches this search on {{count}} present. The node is reporting — the filter is hiding them.`,{count:a.length})}),u(`div`,{className:`space-y-3`,children:S.map(e=>o(`div`,{className:`rounded-lg border border-border p-3`,children:[o(`div`,{className:`flex items-baseline justify-between gap-2 mb-2`,children:[u(`span`,{className:`text-xs font-medium text-foreground`,children:b(e)}),u(`span`,{className:`text-[10px] text-foreground-subtle`,children:r(`clusterLoad.processCount`,`{{count}} process(es)`,{count:e.points.at(-1)?.processCount??0})})]}),o(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[u(vn,{title:c?r(`clusterLoad.cpuTitle`,`CPU % of one core`):r(`clusterLoad.cpuTitleLifetime`,`CPU % (ps lifetime average)`),mainLabel:r(`clusterLoad.seriesMain`,`Main threads`),gcLabel:r(`clusterLoad.seriesGc`,`GC / V8 helpers`),points:e.points.map(e=>({atMs:e.atMs,main:e.cpuMainPercent,gc:e.cpuGcPercent})),formatValue:e=>`${e.toFixed(0)}%`,gapMs:x,emptyMessage:r(`clusterLoad.cpuUnavailable`,`No thread split on this node. Lifetime average: {{avg}}%`,{avg:(e.points.at(-1)?.cpuLifetimePercent??0).toFixed(1)})}),u(yn,{title:r(`clusterLoad.memoryTitle`,`Memory RSS`),points:e.points.map(e=>({atMs:e.atMs,value:e.memoryRssBytes})),formatValue:U,axisFloor:br,axisScale:`bytes`,gapMs:x,emptyMessage:r(`clusterLoad.memoryUnavailable`,`No memory samples yet.`)})]})]},e.key))}),u(_r,{scope:{nodeId:e,isHub:t},cadenceMs:f})]})}function Cr({bucketMs:e,cadenceMs:t}){let{t:n}=H();return e===null?null:u(`p`,{className:`text-[10px] text-foreground-subtle`,children:t!==null&&e>t?n(`clusterLoad.captionBucket`,`1 point = {{bucket}}s (bucket MAXIMUM, not a mean)`,{bucket:Math.round(e/1e3)}):n(`clusterLoad.captionRaw`,`1 point = 1 snapshot`)})}function wr({sort:e,onChange:t}){let{t:n}=H(),r=[{key:`cpu`,label:n(`clusterLoad.sortCpu`,`CPU`)},{key:`memory`,label:n(`clusterLoad.sortMemory`,`Memory`)},{key:`name`,label:n(`clusterLoad.sortName`,`Name`)}];return o(`div`,{className:`flex items-center gap-1`,children:[u(`span`,{className:`text-[10px] text-foreground-subtle`,children:n(`clusterLoad.sortBy`,`Sort by`)}),r.map(n=>{let r=e.key===n.key;return o(`button`,{type:`button`,"aria-pressed":r,onClick:()=>t(r?{key:n.key,dir:e.dir===`desc`?`asc`:`desc`}:{key:n.key,dir:n.key===`name`?`asc`:`desc`}),className:`rounded border px-1.5 py-0.5 text-[10px] transition-colors ${r?`border-primary bg-primary/10 text-primary`:`border-border text-foreground-subtle hover:text-foreground`}`,children:[n.label,r&&(e.dir===`desc`?` ↓`:` ↑`)]},n.key)})]})}var Tr=`No per-node settings on this node. Every other setting these addons expose is one value for the whole cluster — edit those in System → Settings, not here.`;function Er({nodeId:e,addonIds:t}){let{t:n}=H();return t.length===0?u(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:n(`cluster.nodeDetailSettingsTab.noAddonsOnThisNode`,`No addons on this node`)}):u(`div`,{className:`w-full py-2`,children:u($e,{nodeId:e,addonIds:t,level:`global`,fieldScope:`perNode`,emptyMessage:Tr,selfTabbed:!0})})}e();function Dr({nodeId:e,addons:t}){let{t:r}=H(),i=c(),{data:a,isLoading:o}=Te({nodeId:e}),s=n(()=>{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]),l=Pe({onSuccess:()=>{i.invalidateQueries({queryKey:[[`pipelineOrchestrator`,`getCapabilityBindings`]]})}});return s.length===0?u(`div`,{className:`py-4 text-xs text-muted-foreground text-center`,children:r(`cluster.nodeDetailCapabilitiesTab.noCapabilitiesOnThisNode`,`No capabilities on this node`)}):u(ve,{columns:[{key:`capName`,header:r(`cluster.nodeDetailCapabilitiesTab.capability`,`Capability`),width:`w-1/2`,sortValue:e=>e.capName,render:e=>u(`span`,{className:`font-medium`,children:e.capName})},{key:`provider`,header:r(`cluster.nodeDetailCapabilitiesTab.boundProvider`,`Bound provider`),render:t=>{let n=a?.[t.capName]??t.providers[0]??``,i=t.providers.length===1;return u(`select`,{value:n,onChange:n=>l.mutate({nodeId:e,capName:t.capName,addonId:n.target.value}),disabled:i||l.isPending||o,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:i?r(`cluster.nodeDetailCapabilitiesTab.onlyOneProviderInstalledChoice`,`Only one provider installed — choice becomes available once a second addon registers this capability`):void 0,children:t.providers.map(e=>u(`option`,{value:e,children:e},e))})}}],rows:s,rowKey:e=>e.capName,minWidthPx:520,maxBodyHeight:We})}e();function Or(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 kr(e){let{t}=H(),[n,r]=i(!1),[a,s]=i(e.name),l=c(),d=He({onSuccess:()=>{l.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}}),f=(e.localIps??[]).filter(e=>!e.includes(`:`)),p=(e.localIps??[]).filter(e=>e.includes(`:`)),m=async()=>{if(!a.trim()||a===e.name){r(!1);return}try{await d.mutateAsync({nodeId:e.nodeId,name:a.trim()}),r(!1)}catch(e){console.error(`Rename failed:`,e)}},g=[[`Node ID`,u(`span`,{className:`font-mono text-xs`,children:e.nodeId})],[`Display Name`,n?o(`div`,{className:`flex items-center gap-1.5`,children:[u(`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:a,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&m(),e.key===`Escape`&&r(!1)},disabled:d.isPending,autoFocus:!0}),u(`button`,{onClick:()=>void m(),disabled:d.isPending,className:`p-0.5 text-success hover:bg-success/10 rounded`,title:t(`common.save`,`Save`),children:u(v,{className:`h-3.5 w-3.5`})}),u(`button`,{onClick:()=>r(!1),className:`p-0.5 text-muted-foreground hover:bg-muted rounded`,title:t(`common.cancel`,`Cancel`),children:u(C,{className:`h-3.5 w-3.5`})})]}):o(`div`,{className:`flex items-center gap-1.5`,children:[u(`span`,{className:`text-xs`,children:e.name}),!e.isHub&&u(`button`,{onClick:()=>{s(e.name),r(!0)},className:`p-0.5 text-muted-foreground hover:text-primary rounded`,title:t(`cluster.nodeInfoTab.rename`,`Rename`),children:u(h,{className:`h-3 w-3`})})]})],[`Hostname`,u(`span`,{className:`text-xs`,children:e.hostname})],[`Role`,e.isHub?u(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary font-medium`,children:t(`cluster.nodeInfoTab.hub`,`Hub`)}):u(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground font-medium`,children:t(`cluster.nodeInfoTab.agent`,`Agent`)})],[`Root Package`,e.rootPackage?o(`span`,{className:`font-mono text-xs`,children:[e.rootPackage.name,`@`,e.rootPackage.version]}):u(`span`,{className:`text-xs text-muted-foreground`,children:`—`})],[`Platform`,o(`span`,{className:`text-xs`,children:[e.platform,` / `,e.arch]})],[`CPU`,o(`span`,{className:`text-xs`,children:[e.cpuModel??`—`,` (`,t(`cluster.nodeInfoTab.cores`,{count:e.cpuCores}),`)`]})],[`Memory`,u(`span`,{className:`text-xs`,children:e.memoryMB>0?t(`cluster.nodeInfoTab.gb`,`{{value1}} GB`,{value1:(e.memoryMB/1024).toFixed(1)}):`—`})],[`Uptime`,u(`span`,{className:`text-xs`,children:Or(e.uptime)})],[`Engines`,e.engines.length>0?u(`div`,{className:`flex flex-wrap gap-1`,children:e.engines.map(e=>u(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium`,children:e},e))}):u(`span`,{className:`text-xs text-muted-foreground`,children:`—`})]];return f.length>0&&g.push([`IPv4`,u(`div`,{className:`flex flex-wrap gap-1.5`,children:f.map((e,t)=>u(`span`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted`,children:e},`${e}-${t}`))})]),p.length>0&&g.push([`IPv6`,u(`div`,{className:`flex flex-wrap gap-1.5`,children:p.map((e,t)=>u(`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}`))})]),u(`div`,{className:`py-2`,children:u(`table`,{className:`w-full text-sm`,children:u(`tbody`,{children:g.map(([e,t],n)=>o(`tr`,{className:n%2==0?`bg-muted/20`:``,children:[u(`td`,{className:`py-1.5 px-2 text-xs font-medium text-muted-foreground w-28 align-top whitespace-nowrap`,children:e}),u(`td`,{className:`py-1.5 px-2`,children:t})]},e))})})})}e();function Ar({nodeId:e,value:n,detectedHosts:r,status:a,errorMessage:s,onCommit:c}){let{t:l}=H(),[d,f]=i(n??``);t(()=>{f(n??``)},[n]);let p=r[0],m=p===void 0?`auto-detect`:`auto: ${p}`,h=a===`pending`,g=d.trim(),_=g!==(n??``),y=_&&!h,b=()=>{y&&c(e,g.length>0?g:null)};return o(`div`,{className:`flex items-center gap-1.5`,children:[u(B,{"aria-label":l(`placementBoard.reachableHostInput.reachableHostFor`,`Reachable host for {{nodeId}}`,{nodeId:e}),type:`text`,inputMode:`url`,autoComplete:`off`,spellCheck:!1,placeholder:m,value:d,disabled:h,onChange:e=>f(e.target.value),onBlur:b,onKeyDown:e=>{e.key===`Enter`&&b(),e.key===`Escape`&&f(n??``)},className:`w-36`}),o(R,{variant:`outline`,size:`sm`,onClick:b,disabled:!y,"aria-label":l(`placementBoard.reachableHostInput.saveReachableHostFor`,`Save reachable host for {{nodeId}}`,{nodeId:e}),title:l(`placementBoard.reachableHostInput.saveReachableHost`,`Save reachable host`),children:[h?u(D,{className:`h-3 w-3 animate-spin`,"aria-hidden":`true`}):u(v,{className:`h-3 w-3`,"aria-hidden":`true`}),l(`common.save`,`Save`)]}),!_&&!h&&a===`success`&&u(v,{className:`h-3.5 w-3.5 shrink-0 text-success`,"aria-label":l(`placementBoard.reachableHostInput.saved`,`Saved`),role:`img`}),a===`error`&&u(`span`,{title:s??l(`placementBoard.reachableHostInput.failedToSaveReachableHost`,`Failed to save reachable host`),children:u(T,{className:`h-3.5 w-3.5 shrink-0 text-danger`,"aria-label":s??l(`placementBoard.reachableHostInput.failedToSaveReachableHost`,`Failed to save reachable host`),role:`img`})})]})}e();function jr(e){let t=ne.safeParse(et(e,`color`));return t.success?t.data:null}function Mr(e,t){return t.variables?.agentNodeId===e?t.isPending?`pending`:t.isError?`error`:t.isSuccess?`success`:`idle`:`idle`}function Nr({nodeId:e,detectedHosts:t}){let{t:r}=H(),i=c(),a=_e(void 0),s=Ke({onSuccess:()=>tt(i)}),l=Ke({onSuccess:()=>tt(i)}),d=n(()=>a.data?.find(t=>t.nodeId===e)?.settings,[a.data,e]),f=jr(d)??(a.isLoading?null:ie(e)),p=nt(d,`reachableHost`),m=Mr(e,s),h=m===`error`?rt(s.error):null,g=t.filter(e=>!e.includes(`:`)),_=t=>{t!==f&&l.mutate({agentNodeId:e,color:t})};return o(`div`,{className:`rounded-lg border border-border bg-surface/40 divide-y divide-border px-3`,children:[u(pe,{label:r(`nodes.general.nodeColour`,`Node colour`),children:u(`div`,{role:`group`,"aria-label":r(`nodes.general.nodeColourGroup`,`Node colour`),className:`flex flex-wrap gap-2`,children:re.map(e=>{let t=f===e;return u(R,{type:`button`,role:`radio`,"aria-checked":t,"aria-label":e,variant:`outline`,size:`sm`,disabled:a.isLoading||l.isPending,title:e,onClick:()=>_(e),className:`h-6 w-6 min-w-6 shrink-0 rounded-full border-0 p-0 ${le(e)} ${t?`ring-2 ring-primary ring-offset-2 ring-offset-background`:`opacity-80 hover:opacity-100`}`,children:u(`span`,{className:`sr-only`,children:e})},e)})})}),u(pe,{label:r(`nodes.general.reachableHost`,`Reachable host`),children:u(Ar,{nodeId:e,value:p,detectedHosts:g,status:m,errorMessage:h,onCommit:(e,t)=>{s.mutate({agentNodeId:e,reachableHost:t})}})})]})}e();var Pr=[[`serverManagement`,`getServerPackageStatus`]];function Fr({label:e,tone:t}){return u(`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-success/15 text-success`,info:`bg-info/15 text-info`,warn:`bg-warning/15 text-warning`,error:`bg-danger/15 text-danger`}[t]}`,children:e})}function $({label:e,value:t}){return o(`div`,{className:`flex items-center justify-between gap-4 text-sm`,children:[u(`span`,{className:`text-foreground-subtle`,children:e}),u(`span`,{className:`font-mono text-foreground`,children:t??`—`})]})}function Ir({runningVersion:e,latestVersion:t,seedVersion:n,nodeRuntimeVersion:r,labelRunning:i,labelLatest:a,labelSeed:s,labelRuntime:c}){return u(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1 text-sm`,children:[{key:`running`,label:i,value:e},{key:`latest`,label:a,value:t},{key:`seed`,label:s,value:n},{key:`runtime`,label:c,value:r}].map(({key:e,label:t,value:n})=>o(`span`,{className:`inline-flex items-baseline gap-1`,children:[u(`span`,{className:`text-foreground-subtle`,children:t}),u(`span`,{className:`font-mono text-foreground`,children:n??`—`})]},e))})}var Lr={ok:`border-success/40 bg-success/10 text-success`,warn:`border-warning/40 bg-warning/10 text-warning`,error:`border-danger/40 bg-danger/10 text-danger`};function Rr(e){return e.outcome===`failed`?`error`:(e.outcome,e.accepted?`ok`:`warn`)}function zr(e,t){let n=t instanceof Error?t.message:String(t);return`${e(`serverManagement.outcomeDropped`,`The connection dropped and the result could not be confirmed. The node may be restarting — re-check the version above.`)} — ${n}`}function Br({node:e}){let{t}=H(),n=c(),r=z(),[s,l]=i(!1),[d,f]=i(null),p=e.isHub?void 0:{nodeId:e.id},m=me(p,{refetchInterval:1e4,enabled:e.isOnline,retry:1}),h=m.data??null,g=a(()=>{n.invalidateQueries({queryKey:Pr})},[n]),_=De({onSettled:g}),v=de({onSettled:g}),y=Ee({onSettled:g}),S=a(async()=>{if(h?.latestVersion==null){f({tone:`warn`,text:t(`serverManagement.outcomeNoTarget`,`No target version is known for this node — run "Check for update" first.`)});return}if(await r({title:t(`serverManagement.confirmUpdateTitle`,`Update node root package`),message:t(`serverManagement.confirmUpdateBody`,`Install {{pkg}}@{{version}} on "{{node}}" and restart to apply.`,{pkg:h.packageName,version:h.latestVersion,node:e.name}),confirmLabel:t(`serverManagement.confirmUpdateAction`,`Update & restart`)})){f(null);try{let e=await v.mutateAsync({version:h.latestVersion,...p});f({tone:Rr(e),text:e.message}),e.restarting&&l(!0)}catch(e){f({tone:`warn`,text:zr(t,e)})}}},[v,r,e.name,p,h,t]),C=a(async()=>{if(await r({title:t(`serverManagement.confirmRestartTitle`,`Restart node`),message:t(`serverManagement.confirmRestartBody`,`Restart "{{node}}"? In-flight requests to this node are dropped.`,{node:e.name}),confirmLabel:t(`serverManagement.confirmRestartAction`,`Restart`),variant:`warning`})){f(null);try{let e=await y.mutateAsync(p);f({tone:Rr(e),text:e.message}),e.restarting&&l(!0)}catch(e){f({tone:`warn`,text:zr(t,e)})}}},[r,e.name,y,p,t]),w=()=>{switch(h?.bootMode){case`data-root`:return{label:t(`serverManagement.bootDataRoot`,`runtime-updatable`),tone:`ok`};case`workspace`:return{label:t(`serverManagement.bootWorkspace`,`dev workspace`),tone:`info`};default:return{label:t(`serverManagement.bootBaked`,`baked image seed`),tone:`neutral`}}},T=()=>{if(h==null)return null;switch(h.updateState){case`checking`:return{label:t(`serverManagement.stateChecking`,`checking…`),tone:`info`};case`staging`:return{label:t(`serverManagement.stateStaging`,`updating…`),tone:`info`};case`pending-restart`:return{label:t(`serverManagement.statePending`,`restart pending`),tone:`warn`};default:return h.restartRequired===!0?{label:t(`serverManagement.stateRestartRequired`,`restart required`),tone:`warn`}:h.updateAvailable?{label:t(`serverManagement.stateUpdateAvailable`,`update available`),tone:`warn`}:{label:t(`serverManagement.stateUpToDate`,`up to date`),tone:`ok`}}},E=h?.bootMode===`workspace`,O=e.isOnline&&h!=null&&!E&&h.updateAvailable&&h.updateState===`idle`&&!v.isPending,k=e.isOnline&&h!=null&&h.updateState===`idle`&&!y.isPending,A=e.isOnline?T():null;return o(`div`,{className:`space-y-4 py-2`,children:[o(`div`,{className:`flex items-center justify-between gap-3`,children:[o(`div`,{className:`flex items-center gap-2 min-w-0`,children:[u(`span`,{className:`font-mono text-xs text-foreground-subtle truncate`,children:h?.packageName??e.rootPackage?.name??`@camstack/server`}),e.isOnline&&h!=null&&u(Fr,{...w()})]}),A!=null&&u(Fr,{...A})]}),!e.isOnline&&u($,{label:t(`serverManagement.lastReportedVersion`,`Last reported version`),value:e.rootPackage?.version??null}),e.isOnline&&m.isLoading&&o(`div`,{className:`flex items-center gap-2 text-sm text-foreground-subtle`,children:[u(D,{className:`h-4 w-4 animate-spin`}),t(`common.loading`,`Loading…`)]}),e.isOnline&&m.isError&&o(`div`,{className:`space-y-1.5`,children:[u(`p`,{className:`text-sm text-danger`,children:t(`serverManagement.loadError`,`Could not load the node root-package status.`)}),e.rootPackage!=null&&u($,{label:t(`serverManagement.lastReportedVersion`,`Last reported version`),value:e.rootPackage.version})]}),e.isOnline&&h!=null&&o(`div`,{className:`space-y-1.5`,children:[u(Ir,{runningVersion:h.runningVersion,latestVersion:h.latestVersion,seedVersion:h.seedVersion,nodeRuntimeVersion:h.nodeRuntimeVersion,labelRunning:t(`serverManagement.runningVersionShort`,`Running`),labelLatest:t(`serverManagement.latestVersionShort`,`Latest`),labelSeed:t(`serverManagement.imageSeedShort`,`Seed`),labelRuntime:t(`serverManagement.nodeRuntimeVersionShort`,`Node.js`)}),h.pendingVersion!=null&&u($,{label:t(`serverManagement.pendingVersion`,`Staged (applies on restart)`),value:h.pendingVersion}),h.installedVersion!=null&&h.installedVersion!==h.runningVersion&&u($,{label:t(`serverManagement.installedVersion`,`Installed on disk (runs after restart)`),value:h.installedVersion})]}),e.isOnline&&h?.imageContract?.state===`behind-series`&&o(`div`,{className:`rounded-md border border-danger/40 bg-danger/10 px-3 py-2 text-xs leading-relaxed text-danger`,children:[u(`p`,{className:`mb-0.5 font-semibold`,children:t(`serverManagement.imageContractDiverged`,`Container image diverges from the deployment contract`)}),u(`p`,{children:h.imageContract.message})]}),e.isOnline&&E&&u(`p`,{className:`text-xs text-foreground-subtle`,children:t(`serverManagement.workspaceNote`,`Development workspace detected — runtime updates are disabled (the dev loop resolves code from the workspace).`)}),d!=null&&u(`p`,{role:`status`,className:`rounded border px-2 py-1.5 text-xs leading-relaxed ${Lr[d.tone]}`,children:d.text}),s&&o(`div`,{className:`flex items-center gap-2 text-sm text-warning`,children:[u(D,{className:`h-4 w-4 animate-spin`}),t(`serverManagement.nodeRestarting`,`The node is restarting to apply the change…`)]}),e.isOnline&&o(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[o(`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:_.isPending||h?.updateState===`staging`,onClick:()=>_.mutate(p),children:[_.isPending?u(D,{className:`h-3.5 w-3.5 animate-spin`}):u(x,{className:`h-3.5 w-3.5`}),t(`serverManagement.checkForUpdate`,`Check for update`)]}),O&&o(`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 S(),children:[v.isPending?u(D,{className:`h-3.5 w-3.5 animate-spin`}):u(b,{className:`h-3.5 w-3.5`}),t(`serverManagement.updateTo`,`Update to {{version}}`,{version:h?.latestVersion??``})]}),o(`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:!k,onClick:()=>void C(),children:[y.isPending?u(D,{className:`h-3.5 w-3.5 animate-spin`}):u(N,{className:`h-3.5 w-3.5`}),t(`serverManagement.restart`,`Restart`)]})]}),e.isOnline&&h?.lastCheckedAtMs!=null&&o(`p`,{className:`flex items-center gap-1.5 text-[11px] text-foreground-subtle`,children:[u(oe,{className:`h-3 w-3`}),t(`serverManagement.lastChecked`,`Last checked: {{when}}`,{when:new Date(h.lastCheckedAtMs).toLocaleString()})]})]})}e();function Vr(e){if(typeof e!=`object`||!e||Array.isArray(e))return null;let t=Reflect.get(e,`reachableHost`);return typeof t==`string`&&t.length>0?t:null}function Hr({node:e}){let{t}=H(),r=O(),l=c(),d=z(),[p,m]=i(!1),[h,_]=i(`info`),[v,b]=i(!1),[x,S]=i(null),C=e.processes??[],w=e.addons.map(e=>e.id),T=_e(void 0),E=n(()=>{let t=T.data?.find(t=>t.nodeId===e.id);return Vr(t?.settings)},[T.data,e.id]),[D,k]=i(!1),[A,j]=i(null),[M,N]=i(null),ee=a(async()=>{if(D||e.isHub)return;let t=Ft(e.localIps??[],E);if(t===null){j(`No LAN IPv4 on this node — open its :4444 URL by hand.`),N(null);return}let n=Rt();k(!0),j(null),N(null);try{let i=jt(await r.trpcClient.addons.custom.mutate({addonId:`system-config`,action:`mintAgentUiUnlockTicket`,input:{nodeId:e.id,dashboardBaseUrl:It(t)}})),a=i===null?null:i.dashboardUrl??Lt(t,i.ticket);if(a===null){n?.close(),j(`Hub did not return an unlock ticket.`);return}zt(n,a)||(N(a),j(`Browser blocked the new tab — click the link below (or allow popups for this site).`))}catch(e){n?.close(),j(e instanceof Error?e.message:String(e))}finally{k(!1)}},[e.id,e.isHub,e.localIps,D,E,r.trpcClient]),te=async()=>{if(!v){b(!0),S(null);try{await r.trpcClient.pipelineOrchestrator.removeAgentSettings.mutate({agentNodeId:e.id}).catch(()=>void 0);let t=await r.trpcClient.clusterNodes.forgetNode.mutate({nodeId:e.id});S({tone:t.stillListed?`warn`:`ok`,text:t.message}),t.stillListed||l.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}catch(e){S({tone:`warn`,text:t(`cluster.nodeCard.forgetFailed`,{error:e instanceof Error?e.message:String(e)})})}finally{b(!1)}}},P=async()=>{if(!p&&await d({title:t(`cluster.nodeCard.unpair`,`Unpair {{name}}`,{name:e.name}),message:t(`cluster.nodeCard.unpairItDisconnectsAndMust`,`Unpair {{name}}? It disconnects and must be paired again.`,{name:e.name}),confirmLabel:t(`cluster.nodeCard.unpair2`,`Unpair`),variant:`danger`})){m(!0),S(null);try{let t=await r.trpcClient.agentPairing.unpairAgent.mutate({nodeId:e.id});S({tone:t.agentNotified?`ok`:`warn`,text:`${t.nodeId}: ${t.next}${t.agentNotified?``:` The agent could not be told; forget the hub on its own page.`}`}),l.invalidateQueries({queryKey:[[`nodes`,`topology`]]})}catch(e){S({tone:`warn`,text:t(`cluster.nodeCard.unpairFailed`,{error:e instanceof Error?e.message:String(e)})})}finally{m(!1)}}},F=e.isHub?null:o(R,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void P(),disabled:p,title:t(`cluster.nodeCard.unpairThisNodeRevokesIts`,`Unpair this node — revokes its certificates; it must be paired again to rejoin`),children:[u(ce,{className:`h-3 w-3`,"aria-hidden":!0}),p?t(`cluster.nodeCard.unpairing`,`Unpairing…`):t(`cluster.nodeCard.unpair2`,`Unpair`)]});return e.isOnline?o(`div`,{className:`border border-border rounded-xl`,children:[o(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2 px-4 py-3 bg-muted/30 border-b border-border rounded-t-xl`,children:[o(`div`,{className:`flex min-w-0 flex-1 basis-full items-center gap-x-2 gap-y-1 sm:basis-auto sm:flex-initial`,children:[u(`div`,{className:`w-2.5 h-2.5 rounded-full bg-success shrink-0`}),u(Bt,{node:e}),o(`span`,{className:`text-xs text-muted-foreground min-w-0 truncate`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?t(`cluster.nodeCard.gb`,`{{value1}}GB`,{value1:Math.round(e.memoryMB/1024)}):``,` `,`· `,e.arch]})]}),e.engines.map(e=>u(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium shrink-0`,children:e},e)),o(`div`,{className:`flex min-w-0 flex-wrap items-center justify-end gap-x-3 gap-y-1 text-xs text-muted-foreground w-full sm:ml-auto sm:w-auto`,children:[!e.isHub&&o(`button`,{type:`button`,onClick:()=>void ee(),disabled:D,title:t(`cluster.nodeCard.openThisAgentSStatus`,`Open this agent's status dashboard (unlocks with a short-lived hub ticket)`),className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-xs text-foreground hover:bg-surface-hover disabled:opacity-50`,children:[u(f,{className:`h-3 w-3`}),D?t(`cluster.nodeCard.opening`,`Opening…`):t(`cluster.nodeCard.openDashboard`,`Open dashboard`)]}),F,o(`span`,{className:`flex items-center gap-1`,children:[u(y,{className:`h-3 w-3`}),` `,e.cpuPercent,`%`]}),o(`span`,{className:`flex items-center gap-1`,children:[u(se,{className:`h-3 w-3`}),` `,e.memoryPercent,`%`]})]})]}),x!=null&&u(`p`,{role:`status`,className:`px-4 pt-2 text-xs ${x.tone===`ok`?`text-success`:`text-warning`}`,children:x.text}),(A!==null||M!==null)&&o(`p`,{role:`status`,className:`px-4 pt-2 text-xs text-warning`,children:[A,M!==null&&o(s,{children:[` `,u(`a`,{href:M,target:`_blank`,rel:`noreferrer`,className:`underline text-foreground`,children:t(`cluster.nodeCard.openDashboard`,`Open dashboard`)})]})]}),u(`div`,{className:`sticky top-0 z-20 flex border-b border-border px-4 bg-background overflow-x-auto`,children:[`info`,`forks`,`processes`,`load`,`settings`,`capabilities`].map(e=>u(`button`,{onClick:()=>_(e),className:`shrink-0 whitespace-nowrap px-3 py-2 text-xs font-medium border-b-2 transition-colors ${h===e?`border-primary text-primary`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:e===`info`?t(`cluster.nodeCard.general`,`General`):e===`forks`?t(`cluster.nodeCard.forks`,`Forks ({{length}})`,{length:C.length}):e===`processes`?t(`cluster.nodeCard.processes`,`Processes`):e===`load`?t(`cluster.nodeCard.load`,`Load`):e===`settings`?t(`cluster.nodeCard.settings`,`Settings`):t(`cluster.nodeCard.capabilities`,`Capabilities`)},e))}),o(`div`,{className:`px-4 py-2`,children:[h===`info`&&o(`div`,{className:`space-y-3`,children:[u(kr,{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}),u(Nr,{nodeId:e.id,detectedHosts:e.localIps??[]}),u(`div`,{className:`border-t border-border pt-1`,children:u(Br,{node:{id:e.id,name:e.name,isHub:e.isHub,isOnline:e.isOnline,rootPackage:e.rootPackage??null}})})]}),h===`forks`&&u(Gt,{nodeId:e.id,processes:C}),h===`processes`&&u(Yt,{nodeId:e.id}),h===`load`&&u(Sr,{nodeId:e.id,isHub:e.isHub}),h===`settings`&&u(Er,{nodeId:e.id,addonIds:w}),h===`capabilities`&&u(Dr,{nodeId:e.id,addons:e.addons})]})]}):o(`div`,{className:`border border-border rounded-xl overflow-hidden opacity-60`,children:[o(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2 px-4 py-3 bg-muted/30`,children:[u(`div`,{className:`w-2.5 h-2.5 rounded-full bg-destructive shrink-0`}),u(Bt,{node:e}),o(`span`,{className:`text-xs text-muted-foreground min-w-0 truncate`,children:[e.cpuModel??e.platform,` ·`,` `,e.memoryMB>0?t(`cluster.nodeCard.gb`,`{{value1}}GB`,{value1:Math.round(e.memoryMB/1024)}):``,` `,`· `,e.arch]}),e.engines.map(e=>u(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium`,children:e},e)),e.rootPackage&&o(`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]}),u(`span`,{className:`ml-auto text-xs px-2 py-0.5 rounded-full bg-destructive/10 text-destructive`,children:t(`common.offline`)})]}),o(`div`,{className:`flex items-center justify-between gap-3 px-4 py-3`,children:[o(`span`,{className:`text-xs text-muted-foreground`,children:[e.lastSeen?u(`span`,{className:`mr-1`,children:t(`cluster.nodeCard.lastSeen`,{when:new Date(e.lastSeen).toLocaleString()})}):null,t(`cluster.nodeCard.addonsAssigned`,{count:e.addons.length})]}),o(`div`,{className:`flex shrink-0 items-center gap-2`,children:[F,o(`button`,{type:`button`,onClick:()=>void te(),disabled:v,title:t(`cluster.nodeCard.forgetThisNodeRemovesIts`,`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:[u(g,{className:`h-3 w-3`}),v?t(`cluster.nodeCard.forgetting`,`Forgetting…`):t(`cluster.nodeCard.forgetNode`,`Forget node`)]})]})]}),x!=null&&u(`p`,{role:`status`,className:`px-4 pb-3 text-xs leading-relaxed ${x.tone===`ok`?`text-success`:`text-warning`}`,children:x.text})]})}var Ur=3,Wr=7e3;function Gr(e){return[...e].sort((e,t)=>e.isHub===t.isHub?0:e.isHub?1:-1)}function Kr(e){return e.isHub?{}:{nodeId:e.id}}function qr(e){return e.updateState===`staging`||e.updateState===`pending-restart`||e.pendingVersion!==null?!0:!e.updateAvailable}async function Jr(e,t){let n=Kr(e),r=V.t(`helpers.clusterUpdateAll.noAnswer`);for(let i=1;i<=Ur;i+=1)try{let r=await t.readStatus(n);return qr(r)?{nodeId:e.id,nodeName:e.name,outcome:`applied`,detail:V.t(`helpers.clusterUpdateAll.landed`,{state:r.updateState,version:r.runningVersion??V.t(`helpers.clusterUpdateAll.unknown`)})}:{nodeId:e.id,nodeName:e.name,outcome:`failed`,detail:V.t(`helpers.clusterUpdateAll.unchanged`,{version:r.runningVersion??V.t(`helpers.clusterUpdateAll.unknown`)})}}catch(e){r=e instanceof Error?e.message:String(e),i<Ur&&await t.wait(Wr)}return{nodeId:e.id,nodeName:e.name,outcome:`unconfirmed`,detail:V.t(`helpers.clusterUpdateAll.unconfirmed`,{attempts:Ur,error:r})}}function Yr(e){return e.accepted?`applied`:e.outcome===`failed`?`failed`:`refused`}async function Xr(e,t){let n=[];for(let r of Gr(e))try{let e=await t.apply(Kr(r));n.push({nodeId:r.id,nodeName:r.name,outcome:Yr(e),detail:e.message})}catch{n.push(await Jr(r,t))}return n}e();function Zr(){let{nodes:e,isLoading:t}=Ye(),r=n(()=>e??[],[e]);return{nodes:r,isLoading:t&&r.length===0}}var Qr={applied:`border-success/40 bg-success/10 text-success`,refused:`border-warning/40 bg-warning/10 text-warning`,failed:`border-danger/40 bg-danger/10 text-danger`,unconfirmed:`border-warning/40 bg-warning/10 text-warning`};function $r(){let{t:e}=H(),r=z(),{nodes:c,isLoading:l}=Zr(),[d,f]=Ze(),{selection:p,selectNode:m}=at(c),h=p.node,g=n(()=>c.filter(e=>e.isOnline),[c]),_=g.length,v=c.filter(e=>!e.isOnline).length,y=de(),x=O(),[S,C]=i(!1),[w,T]=i([]),E=d.get(`unlockNode`),k=d.get(`returnTo`),[A,j]=i(null);t(()=>{if(E===null||k===null)return;let e=!1;return(async()=>{try{let t=await x.trpcClient.addons.custom.mutate({addonId:`system-config`,action:`mintAgentUiUnlockTicket`,input:{nodeId:E,dashboardBaseUrl:k}});if(e)return;let n=jt(t),r=n===null?null:n.dashboardUrl??(()=>{let e=new URL(k);return e.searchParams.set(`ticket`,n.ticket),e.toString()})();if(r===null){j(`Could not mint an unlock ticket.`);return}let i=new URLSearchParams(d);i.delete(`unlockNode`),i.delete(`returnTo`),f(i,{replace:!0}),window.location.assign(r)}catch(t){e||j(t instanceof Error?t.message:String(t))}})(),()=>{e=!0}},[E,k,d,f,x.trpcClient]);let M=a(async()=>{let t=g.map(e=>({id:e.id,name:e.name,isHub:e.isHub}));if(await r({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`})){C(!0),T([]);try{T(await Xr(t,{apply:e=>y.mutateAsync(e),readStatus:e=>x.trpcClient.serverManagement.getServerPackageStatus.query(e),wait:e=>new Promise(t=>setTimeout(t,e))}))}finally{C(!1)}}},[y,r,g,x,e]);return o(Qe,{icon:F,title:e(`nav.nodes`,`Nodes`),subtitle:e(`cluster.subtitle`,`One node at a time — topology and packages. Agents join by pairing (certificate, no shared secret).`),actions:o(s,{children:[_>0&&u(`span`,{className:`rounded-full bg-success/10 px-2 py-0.5 text-xs text-success`,children:e(`common.onlineCount`,{count:_})}),v>0&&u(`span`,{className:`rounded-full bg-destructive/10 px-2 py-0.5 text-xs text-destructive`,children:e(`common.offlineCount`,{count:v})}),_>1&&o(R,{type:`button`,size:`sm`,disabled:S,title:e(`serverManagement.updateAllHint`,`Sequenced agents-first, hub-last — up-to-date nodes are skipped.`),onClick:()=>void M(),children:[S?u(D,{className:`h-3.5 w-3.5 animate-spin`}):u(b,{className:`h-3.5 w-3.5`}),e(`serverManagement.updateAll`,`Update all nodes`)]})]}),children:[w.length>0&&u(`ul`,{"aria-label":`update-all-report`,className:`flex flex-col gap-1 text-xs`,children:w.map(e=>o(`li`,{"data-outcome":e.outcome,className:`rounded border px-2 py-1 ${Qr[e.outcome]}`,children:[u(`span`,{className:`font-medium`,children:e.nodeName}),u(`span`,{className:`mx-1 uppercase tracking-wide`,children:e.outcome}),u(`span`,{className:`opacity-80`,children:e.detail})]},e.nodeId))}),A!==null&&o(`p`,{role:`alert`,className:`rounded border border-warning/40 bg-warning/10 px-3 py-2 text-xs text-warning`,children:[e(`system.cluster.unlockFromAgentFailed`,`Unlock from agent failed:`),` `,A]}),u(kt,{onOpenNode:m}),l?u(`div`,{className:`flex items-center justify-center py-12 text-muted-foreground`,children:e(`system.cluster.loadingClusterTopology`,`Loading cluster topology...`)}):h===null?u(`div`,{className:`rounded-md border border-dashed border-border px-3 py-6 text-center text-xs text-foreground-subtle`,children:e(`cluster.noNodes`,`No nodes in this cluster yet.`)}):o(`div`,{className:`flex flex-col gap-3`,children:[u(it,{staleNodeId:p.staleNodeId,shownNodeName:h.name}),u(ge,{selectedNodeId:h.id,onSelect:m,allowOffline:!0,alwaysShow:!0}),u(Hr,{node:h})]})]})}export{$r as ClusterPage};