@rubytech/create-sitedesk-code 0.1.610 → 0.1.611

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 (178) hide show
  1. package/package.json +1 -1
  2. package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +45 -23
  3. package/payload/platform/plugins/admin/skills/whats-new/SKILL.md +5 -0
  4. package/payload/platform/plugins/docs/references/telegram-guide.md +44 -22
  5. package/payload/server/public/activity.html +6 -6
  6. package/payload/server/public/agents.html +5 -5
  7. package/payload/server/public/assets/{AdminLoginScreens-uk2gBvI9.js → AdminLoginScreens-Bjsr45ed.js} +1 -1
  8. package/payload/server/public/assets/AdminLoginScreens-Bjsr45ed.js.br +0 -0
  9. package/payload/server/public/assets/AdminLoginScreens-Bjsr45ed.js.gz +0 -0
  10. package/payload/server/public/assets/{AdminShell-DyOPTLdb.js → AdminShell-Dm_nY4jF.js} +1 -1
  11. package/payload/server/public/assets/AdminShell-Dm_nY4jF.js.br +0 -0
  12. package/payload/server/public/assets/AdminShell-Dm_nY4jF.js.gz +0 -0
  13. package/payload/server/public/assets/{activity-DfIud5UH.js → activity-Dz5eWZze.js} +1 -1
  14. package/payload/server/public/assets/activity-Dz5eWZze.js.br +0 -0
  15. package/payload/server/public/assets/activity-Dz5eWZze.js.gz +0 -0
  16. package/payload/server/public/assets/{admin-Duy2d3ks.js → admin-B2IkUoSc.js} +1 -1
  17. package/payload/server/public/assets/admin-B2IkUoSc.js.br +0 -0
  18. package/payload/server/public/assets/admin-B2IkUoSc.js.gz +0 -0
  19. package/payload/server/public/assets/{agents-Rcdk-pni.js → agents-DjDwemOg.js} +1 -1
  20. package/payload/server/public/assets/agents-DjDwemOg.js.br +0 -0
  21. package/payload/server/public/assets/agents-DjDwemOg.js.gz +0 -0
  22. package/payload/server/public/assets/{browser-Bt6h1Pjb.js → browser-BDFx14YM.js} +1 -1
  23. package/payload/server/public/assets/browser-BDFx14YM.js.br +0 -0
  24. package/payload/server/public/assets/browser-BDFx14YM.js.gz +0 -0
  25. package/payload/server/public/assets/{calendar-Di0yArmc.js → calendar-BbUsdMKW.js} +1 -1
  26. package/payload/server/public/assets/calendar-BbUsdMKW.js.br +0 -0
  27. package/payload/server/public/assets/calendar-BbUsdMKW.js.gz +0 -0
  28. package/payload/server/public/assets/chat-fP4sE4pU.js +1 -0
  29. package/payload/server/public/assets/chat-fP4sE4pU.js.br +2 -0
  30. package/payload/server/public/assets/chat-fP4sE4pU.js.gz +0 -0
  31. package/payload/server/public/assets/{chevron-left-QGcFX-3R.js → chevron-left-D3_hiHLC.js} +1 -1
  32. package/payload/server/public/assets/chevron-left-D3_hiHLC.js.br +0 -0
  33. package/payload/server/public/assets/clock-kLje910u.js +1 -0
  34. package/payload/server/public/assets/clock-kLje910u.js.br +0 -0
  35. package/payload/server/public/assets/clock-kLje910u.js.gz +0 -0
  36. package/payload/server/public/assets/{copy-RSaF-402.js → copy-Dnw0TkVh.js} +1 -1
  37. package/payload/server/public/assets/copy-Dnw0TkVh.js.br +0 -0
  38. package/payload/server/public/assets/copy-Dnw0TkVh.js.gz +0 -0
  39. package/payload/server/public/assets/data-DKz9_73S.js +1 -0
  40. package/payload/server/public/assets/data-DKz9_73S.js.br +1 -0
  41. package/payload/server/public/assets/data-DKz9_73S.js.gz +0 -0
  42. package/payload/server/public/assets/{field-nfpVNHyk.js → field-mhgbdofr.js} +1 -1
  43. package/payload/server/public/assets/field-mhgbdofr.js.br +0 -0
  44. package/payload/server/public/assets/field-mhgbdofr.js.gz +0 -0
  45. package/payload/server/public/assets/{file-text-Cws2LExM.js → file-text-CVZAL3Er.js} +1 -1
  46. package/payload/server/public/assets/file-text-CVZAL3Er.js.br +0 -0
  47. package/payload/server/public/assets/file-text-CVZAL3Er.js.gz +0 -0
  48. package/payload/server/public/assets/{graph-56nTCvKa.js → graph-NmOxFNdx.js} +1 -1
  49. package/payload/server/public/assets/graph-NmOxFNdx.js.br +0 -0
  50. package/payload/server/public/assets/graph-NmOxFNdx.js.gz +0 -0
  51. package/payload/server/public/assets/{graph-labels-qHDVYalh.js → graph-labels-BTFUSc63.js} +1 -1
  52. package/payload/server/public/assets/graph-labels-BTFUSc63.js.br +0 -0
  53. package/payload/server/public/assets/graph-labels-BTFUSc63.js.gz +0 -0
  54. package/payload/server/public/assets/{jsx-runtime-B5zQuMcr.css → jsx-runtime-dao9WPN0.css} +1 -1
  55. package/payload/server/public/assets/jsx-runtime-dao9WPN0.css.br +0 -0
  56. package/payload/server/public/assets/{jsx-runtime-B5zQuMcr.css.gz → jsx-runtime-dao9WPN0.css.gz} +0 -0
  57. package/payload/server/public/assets/{operator-D-P6oemk.js → operator-CO5ma-ky.js} +1 -1
  58. package/payload/server/public/assets/operator-CO5ma-ky.js.br +0 -0
  59. package/payload/server/public/assets/operator-CO5ma-ky.js.gz +0 -0
  60. package/payload/server/public/assets/{page-8goE0IWS.js → page-BBRWbFzG.js} +1 -1
  61. package/payload/server/public/assets/page-BBRWbFzG.js.br +0 -0
  62. package/payload/server/public/assets/page-BBRWbFzG.js.gz +0 -0
  63. package/payload/server/public/assets/page-CdRrpkky.js +1 -0
  64. package/payload/server/public/assets/page-CdRrpkky.js.br +0 -0
  65. package/payload/server/public/assets/page-CdRrpkky.js.gz +0 -0
  66. package/payload/server/public/assets/play-eeQX0FtC.js +1 -0
  67. package/payload/server/public/assets/play-eeQX0FtC.js.br +0 -0
  68. package/payload/server/public/assets/play-eeQX0FtC.js.gz +0 -0
  69. package/payload/server/public/assets/{public-BwfIj7tM.js → public-2mLo4k7L.js} +1 -1
  70. package/payload/server/public/assets/public-2mLo4k7L.js.br +0 -0
  71. package/payload/server/public/assets/public-2mLo4k7L.js.gz +0 -0
  72. package/payload/server/public/assets/{rotate-ccw-X7-7vE7t.js → rotate-ccw-D-2d4YGp.js} +1 -1
  73. package/payload/server/public/assets/rotate-ccw-D-2d4YGp.js.br +0 -0
  74. package/payload/server/public/assets/rotate-ccw-D-2d4YGp.js.gz +0 -0
  75. package/payload/server/public/assets/{routines-sFud5tka.js → routines-CMW8sm10.js} +1 -1
  76. package/payload/server/public/assets/routines-CMW8sm10.js.br +0 -0
  77. package/payload/server/public/assets/routines-CMW8sm10.js.gz +0 -0
  78. package/payload/server/public/assets/{skills-_Dc3eG9T.js → skills-BQC7SM0J.js} +1 -1
  79. package/payload/server/public/assets/skills-BQC7SM0J.js.br +0 -0
  80. package/payload/server/public/assets/skills-BQC7SM0J.js.gz +0 -0
  81. package/payload/server/public/assets/{tasks-C0u8AtqT.js → tasks-CIs0y00-.js} +1 -1
  82. package/payload/server/public/assets/tasks-CIs0y00-.js.br +0 -0
  83. package/payload/server/public/assets/tasks-CIs0y00-.js.gz +0 -0
  84. package/payload/server/public/assets/{triangle-alert-DD4kSK45.js → triangle-alert-C_68TrTq.js} +1 -1
  85. package/payload/server/public/assets/triangle-alert-C_68TrTq.js.br +0 -0
  86. package/payload/server/public/assets/triangle-alert-C_68TrTq.js.gz +0 -0
  87. package/payload/server/public/assets/{useCopyFeedback-Dq-Putj7.js → useCopyFeedback-1MKNUzp3.js} +1 -1
  88. package/payload/server/public/assets/useCopyFeedback-1MKNUzp3.js.br +0 -0
  89. package/payload/server/public/assets/useCopyFeedback-1MKNUzp3.js.gz +0 -0
  90. package/payload/server/public/assets/{useMediaQuery-Cm_fvNIH.js → useMediaQuery-e4ciNiuO.js} +1 -1
  91. package/payload/server/public/assets/useMediaQuery-e4ciNiuO.js.br +0 -0
  92. package/payload/server/public/assets/useMediaQuery-e4ciNiuO.js.gz +0 -0
  93. package/payload/server/public/assets/{useVoiceRecorder-C6xqnm7i.js → useVoiceRecorder-D7_wLtrS.js} +1 -1
  94. package/payload/server/public/assets/useVoiceRecorder-D7_wLtrS.js.br +0 -0
  95. package/payload/server/public/assets/{useVoiceRecorder-C6xqnm7i.js.gz → useVoiceRecorder-D7_wLtrS.js.gz} +0 -0
  96. package/payload/server/public/assets/{wrench-Bjw6eVl_.js → wrench-BI28h1JF.js} +1 -1
  97. package/payload/server/public/assets/wrench-BI28h1JF.js.br +0 -0
  98. package/payload/server/public/assets/wrench-BI28h1JF.js.gz +0 -0
  99. package/payload/server/public/browser.html +5 -5
  100. package/payload/server/public/calendar.html +8 -8
  101. package/payload/server/public/chat.html +14 -14
  102. package/payload/server/public/data.html +12 -12
  103. package/payload/server/public/field.html +3 -3
  104. package/payload/server/public/graph.html +10 -10
  105. package/payload/server/public/index.html +14 -14
  106. package/payload/server/public/operator.html +16 -16
  107. package/payload/server/public/public.html +14 -14
  108. package/payload/server/public/routines.html +8 -8
  109. package/payload/server/public/skills.html +6 -6
  110. package/payload/server/public/tasks.html +7 -7
  111. package/payload/server/server.js +650 -528
  112. package/payload/server/public/assets/AdminLoginScreens-uk2gBvI9.js.br +0 -0
  113. package/payload/server/public/assets/AdminLoginScreens-uk2gBvI9.js.gz +0 -0
  114. package/payload/server/public/assets/AdminShell-DyOPTLdb.js.br +0 -0
  115. package/payload/server/public/assets/AdminShell-DyOPTLdb.js.gz +0 -0
  116. package/payload/server/public/assets/activity-DfIud5UH.js.br +0 -0
  117. package/payload/server/public/assets/activity-DfIud5UH.js.gz +0 -0
  118. package/payload/server/public/assets/admin-Duy2d3ks.js.br +0 -0
  119. package/payload/server/public/assets/admin-Duy2d3ks.js.gz +0 -0
  120. package/payload/server/public/assets/agents-Rcdk-pni.js.br +0 -0
  121. package/payload/server/public/assets/agents-Rcdk-pni.js.gz +0 -0
  122. package/payload/server/public/assets/browser-Bt6h1Pjb.js.br +0 -0
  123. package/payload/server/public/assets/browser-Bt6h1Pjb.js.gz +0 -0
  124. package/payload/server/public/assets/calendar-Di0yArmc.js.br +0 -0
  125. package/payload/server/public/assets/calendar-Di0yArmc.js.gz +0 -0
  126. package/payload/server/public/assets/chat-xJTrFY2U.js +0 -1
  127. package/payload/server/public/assets/chat-xJTrFY2U.js.br +0 -1
  128. package/payload/server/public/assets/chat-xJTrFY2U.js.gz +0 -0
  129. package/payload/server/public/assets/chevron-left-QGcFX-3R.js.br +0 -0
  130. package/payload/server/public/assets/clock-PkEm8y4i.js +0 -1
  131. package/payload/server/public/assets/clock-PkEm8y4i.js.br +0 -0
  132. package/payload/server/public/assets/clock-PkEm8y4i.js.gz +0 -0
  133. package/payload/server/public/assets/copy-RSaF-402.js.br +0 -0
  134. package/payload/server/public/assets/copy-RSaF-402.js.gz +0 -0
  135. package/payload/server/public/assets/data-CLmmCyzs.js +0 -1
  136. package/payload/server/public/assets/data-CLmmCyzs.js.br +0 -1
  137. package/payload/server/public/assets/data-CLmmCyzs.js.gz +0 -0
  138. package/payload/server/public/assets/field-nfpVNHyk.js.br +0 -0
  139. package/payload/server/public/assets/field-nfpVNHyk.js.gz +0 -0
  140. package/payload/server/public/assets/file-text-Cws2LExM.js.br +0 -0
  141. package/payload/server/public/assets/file-text-Cws2LExM.js.gz +0 -0
  142. package/payload/server/public/assets/graph-56nTCvKa.js.br +0 -0
  143. package/payload/server/public/assets/graph-56nTCvKa.js.gz +0 -0
  144. package/payload/server/public/assets/graph-labels-qHDVYalh.js.br +0 -0
  145. package/payload/server/public/assets/graph-labels-qHDVYalh.js.gz +0 -0
  146. package/payload/server/public/assets/jsx-runtime-B5zQuMcr.css.br +0 -0
  147. package/payload/server/public/assets/operator-D-P6oemk.js.br +0 -2
  148. package/payload/server/public/assets/operator-D-P6oemk.js.gz +0 -0
  149. package/payload/server/public/assets/page-8goE0IWS.js.br +0 -0
  150. package/payload/server/public/assets/page-8goE0IWS.js.gz +0 -0
  151. package/payload/server/public/assets/page-iL446JAc.js +0 -1
  152. package/payload/server/public/assets/page-iL446JAc.js.br +0 -0
  153. package/payload/server/public/assets/page-iL446JAc.js.gz +0 -0
  154. package/payload/server/public/assets/play-B8bxRax6.js +0 -1
  155. package/payload/server/public/assets/play-B8bxRax6.js.br +0 -0
  156. package/payload/server/public/assets/play-B8bxRax6.js.gz +0 -0
  157. package/payload/server/public/assets/public-BwfIj7tM.js.br +0 -0
  158. package/payload/server/public/assets/public-BwfIj7tM.js.gz +0 -0
  159. package/payload/server/public/assets/rotate-ccw-X7-7vE7t.js.br +0 -0
  160. package/payload/server/public/assets/rotate-ccw-X7-7vE7t.js.gz +0 -0
  161. package/payload/server/public/assets/routines-sFud5tka.js.br +0 -0
  162. package/payload/server/public/assets/routines-sFud5tka.js.gz +0 -0
  163. package/payload/server/public/assets/skills-_Dc3eG9T.js.br +0 -0
  164. package/payload/server/public/assets/skills-_Dc3eG9T.js.gz +0 -0
  165. package/payload/server/public/assets/tasks-C0u8AtqT.js.br +0 -0
  166. package/payload/server/public/assets/tasks-C0u8AtqT.js.gz +0 -0
  167. package/payload/server/public/assets/triangle-alert-DD4kSK45.js.br +0 -0
  168. package/payload/server/public/assets/triangle-alert-DD4kSK45.js.gz +0 -0
  169. package/payload/server/public/assets/useCopyFeedback-Dq-Putj7.js.br +0 -0
  170. package/payload/server/public/assets/useCopyFeedback-Dq-Putj7.js.gz +0 -0
  171. package/payload/server/public/assets/useMediaQuery-Cm_fvNIH.js.br +0 -0
  172. package/payload/server/public/assets/useMediaQuery-Cm_fvNIH.js.gz +0 -0
  173. package/payload/server/public/assets/useVoiceRecorder-C6xqnm7i.js.br +0 -0
  174. package/payload/server/public/assets/wrench-Bjw6eVl_.js.br +0 -0
  175. package/payload/server/public/assets/wrench-Bjw6eVl_.js.gz +0 -0
  176. /package/payload/server/public/assets/{jsx-runtime-DeRQuYlX.js → jsx-runtime-BY35JYDT.js} +0 -0
  177. /package/payload/server/public/assets/{jsx-runtime-DeRQuYlX.js.br → jsx-runtime-BY35JYDT.js.br} +0 -0
  178. /package/payload/server/public/assets/{jsx-runtime-DeRQuYlX.js.gz → jsx-runtime-BY35JYDT.js.gz} +0 -0
@@ -1,3 +1,3 @@
1
- import{o as e}from"./chunk-BycB0eMI.js";import{i as t,r as n,t as r}from"./jsx-runtime-DeRQuYlX.js";import{A as i,B as a,C as o,F as s,G as c,H as l,I as u,J as d,K as f,L as p,M as m,N as h,Q as g,R as _,S as v,U as y,V as b,W as x,X as ee,Y as te,Z as S,at as ne,b as re,c as ie,ct as ae,d as C,et as w,it as T,j as E,m as D,n as oe,nt as se,p as O,q as k,rt as A,st as ce,t as le,tt as j,u as M,x as ue,y as de}from"./useMediaQuery-Cm_fvNIH.js";async function N(){try{let e=await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`logout`})});return e.ok?(await e.json().catch(()=>({})))?.logged_out===!0:(console.error(`[admin-ui] claude-logout http-status=${e.status}`),!1)}catch(e){return console.error(`[admin-ui] claude-logout fetch failed: ${e instanceof Error?e.message:String(e)}`),!1}}var P=r();function fe({checked:e,onChange:t,label:n,disabled:r,ariaLabel:i=n}){return(0,P.jsxs)(`label`,{className:`maxy-checkbox${r?` maxy-checkbox--disabled`:``}`,children:[(0,P.jsx)(`input`,{type:`checkbox`,"aria-label":i,checked:e,onChange:e=>t(e.target.checked),disabled:r}),(0,P.jsx)(`span`,{className:`maxy-checkbox__box`,children:`✱`}),n&&(0,P.jsx)(`span`,{className:`maxy-checkbox__label`,children:n})]})}var F=e(t(),1),I={sm:14,md:16,lg:18},pe={sm:30,md:38,lg:46};function L({variant:e=`primary`,size:t=`md`,icon:n,iconPosition:r=`leading`,loading:i=!1,fullWidth:a=!1,disabled:o=!1,type:s=`button`,onClick:c,"aria-label":l,"aria-pressed":u,style:d,className:f,children:p}){let m=[`btn`,`btn--${e}`,t===`md`?``:`btn--${t}`,a?`btn--full`:``,f].filter(Boolean).join(` `),h=I[t],g={...e===`send`?{width:pe[t],height:pe[t]}:{},...d},_=Object.keys(g).length>0;return(0,P.jsxs)(`button`,{type:s,className:m,disabled:i||o,onClick:c,"aria-label":l,"aria-pressed":u,style:_?g:void 0,children:[(0,P.jsxs)(`span`,{className:`btn__content`,style:{visibility:i?`hidden`:`visible`},children:[n&&r===`leading`&&(0,P.jsx)(n,{size:h}),p,n&&r===`trailing`&&(0,P.jsx)(n,{size:h})]}),i&&(0,P.jsx)(`span`,{className:`btn__spinner`,children:`✱`})]})}var me=A(`archive-restore`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h2`,key:`tvwodi`}],[`path`,{d:`M20 8v11a2 2 0 0 1-2 2h-2`,key:`1gkqxj`}],[`path`,{d:`m9 15 3-3 3 3`,key:`1pd0qc`}],[`path`,{d:`M12 12v9`,key:`192myk`}]]),he=A(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),R=A(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),ge=A(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),_e=A(`chevron-right`,[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]),ve=A(`ellipsis-vertical`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]]),ye=A(`external-link`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]),be=A(`gauge`,[[`path`,{d:`m12 14 4-4`,key:`9kzdfg`}],[`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`,key:`19p75a`}]]),xe=A(`list-todo`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),Se=A(`message-square`,[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}]]),Ce=A(`minimize-2`,[[`path`,{d:`m14 10 7-7`,key:`oa77jy`}],[`path`,{d:`M20 10h-6V4`,key:`mjg0md`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M4 14h6v6`,key:`rmj7iw`}]]),z=A(`panel-left`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}]]),we=A(`rotate-cw`,[[`path`,{d:`M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8`,key:`1p45f6`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}]]),Te=A(`sliders-horizontal`,[[`path`,{d:`M10 5H3`,key:`1qgfaw`}],[`path`,{d:`M12 19H3`,key:`yhmn1j`}],[`path`,{d:`M14 3v4`,key:`1sua03`}],[`path`,{d:`M16 17v4`,key:`1q0r14`}],[`path`,{d:`M21 12h-9`,key:`1o4lsq`}],[`path`,{d:`M21 19h-5`,key:`1rlt1p`}],[`path`,{d:`M21 5h-7`,key:`1oszz2`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M8 12H3`,key:`a7s4jb`}]]),Ee=A(`wand-sparkles`,[[`path`,{d:`m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72`,key:`ul74o6`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`M5 6v4`,key:`ilb8ba`}],[`path`,{d:`M19 14v4`,key:`blhpug`}],[`path`,{d:`M10 2v2`,key:`7u0qdc`}],[`path`,{d:`M7 8H3`,key:`zfb6yr`}],[`path`,{d:`M21 16h-4`,key:`1cnmox`}],[`path`,{d:`M11 3H9`,key:`1obp7u`}]]),De=A(`waypoints`,[[`path`,{d:`m10.586 5.414-5.172 5.172`,key:`4mc350`}],[`path`,{d:`m18.586 13.414-5.172 5.172`,key:`8c96vv`}],[`path`,{d:`M6 12h12`,key:`8npq4p`}],[`circle`,{cx:`12`,cy:`20`,r:`2`,key:`144qzu`}],[`circle`,{cx:`12`,cy:`4`,r:`2`,key:`muu5ef`}],[`circle`,{cx:`20`,cy:`12`,r:`2`,key:`1xzzfp`}],[`circle`,{cx:`4`,cy:`12`,r:`2`,key:`1hvhnz`}]]),Oe=A(`zap`,[[`path`,{d:`M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z`,key:`1xq2db`}]]),ke=`/cdp-screencast`;function Ae(e){return{format:`jpeg`,quality:60,maxWidth:e?Math.max(320,Math.round(e.width)):1280,maxHeight:e?Math.max(320,Math.round(e.height)):800,everyNthFrame:1}}var je=1e3,Me=3e4,Ne=[0,1e3,2e3,4e3];function B(e,t,n,r){return n.width<=0||n.height<=0?{x:0,y:0}:{x:e/n.width*r.deviceWidth,y:t/n.height*r.deviceHeight}}function Pe(e){return e&1?0:e&4?1:e&2?2:-1}function Fe(e){return e===0?`left`:e===1?`middle`:e===2?`right`:`none`}function Ie(e,t){let n=Fe(t.button);return{type:e,x:t.x,y:t.y,button:n,buttons:t.buttons,clickCount:e===`mouseMoved`?0:1,modifiers:t.modifiers}}function Le(e){return{type:`mouseWheel`,x:e.x,y:e.y,button:`none`,buttons:0,clickCount:0,modifiers:e.modifiers,deltaX:e.deltaX,deltaY:e.deltaY}}var Re={Backspace:8,Tab:9,Enter:13,Escape:27,PageUp:33,PageDown:34,End:35,Home:36,ArrowLeft:37,ArrowUp:38,ArrowRight:39,ArrowDown:40,Delete:46},ze={Enter:`\r`,Tab:` `};function Be(e,t){let n=t.key.length===1,r=n&&/[a-z0-9]/i.test(t.key)?t.key.toUpperCase().charCodeAt(0):Re[t.key]??0,i={type:e,key:t.key,code:t.code,modifiers:t.modifiers,windowsVirtualKeyCode:r,nativeVirtualKeyCode:r};if(e===`keyDown`){let e=n?t.key:ze[t.key];e!==void 0&&(i.text=e,i.unmodifiedText=e)}return i}function Ve(e){let t=e.trim();return t?/^[a-z][a-z0-9+.-]*:/i.test(t)?t:`https://${t}`:``}function He(e){try{return new URL(Ve(e)).host}catch{return``}}function Ue(e,t,n){return`${e.protocol===`https:`?`wss`:`ws`}://${e.host}${ke}?targetId=${encodeURIComponent(t)}&sid=${encodeURIComponent(n)}`}var We=class{nextId=1;startId=null;frames=0;stopped=!1;lastMetadata=null;lastInputLogAtMs=null;inputsSinceLog=0;lastFrameAtMs=null;inputsSinceFrame=0;pending=new Map;constructor(e,t){this.ws=e,this.opts=t}frameCount(){return this.frames}sinceLastFrameMs(){return this.lastFrameAtMs===null?null:(this.opts.now??Date.now)()-this.lastFrameAtMs}inputsSinceLastFrame(){return this.inputsSinceFrame}reload(){this.send(`Page.reload`,{})}start(e){this.send(`Page.bringToFront`,{}),this.send(`Page.enable`,{}),e&&this.setPaneSize(e);let t=Ae(e);this.startId=this.send(`Page.startScreencast`,t)}setPaneSize(e){let t=Math.max(1,Math.round(e.width)),n=Math.max(1,Math.round(e.height));this.send(`Emulation.setDeviceMetricsOverride`,{width:t,height:n,deviceScaleFactor:0,mobile:!1})}stop(){if(this.stopped)return;this.stopped=!0;let e=this.send(`Page.stopScreencast`,{})!==null;this.send(`Emulation.clearDeviceMetricsOverride`,{}),this.opts.onLog(`teardown`,{stopSent:e})}handleMessage(e){let t;try{t=JSON.parse(e)}catch{return}if(typeof t.id==`number`){let e=this.pending.get(t.id);if(e){this.pending.delete(t.id),e(t.error?null:t.result);return}}if(typeof t.id==`number`&&t.id===this.startId){if(t.error)this.opts.onLog(`start-failed`,{err:t.error.message??`unknown`});else{let e=Ae();this.opts.onLog(`screencast-started`,{format:e.format,everyNthFrame:e.everyNthFrame})}return}if(t.method===`Page.frameNavigated`){let e=t.params?.frame;e&&e.parentId===void 0&&typeof e.url==`string`&&this.opts.onUrlChange?.(e.url);return}if(t.method!==`Page.screencastFrame`||this.stopped)return;let n=t.params;if(typeof n?.data!=`string`){this.opts.onLog(`frame-dropped`,{reason:`no-data`});return}if(typeof n?.metadata!=`object`||n.metadata===null){this.opts.onLog(`frame-dropped`,{reason:`no-metadata`});return}let r=n.metadata;typeof n.sessionId==`number`?this.send(`Page.screencastFrameAck`,{sessionId:n.sessionId}):this.opts.onLog(`frame-unacked`,{}),this.frames+=1,this.lastFrameAtMs=(this.opts.now??Date.now)(),this.inputsSinceFrame=0,this.lastMetadata=r,this.frames%30==0&&this.opts.onLog(`frame`,{seq:this.frames}),this.opts.onFrame({data:n.data,metadata:r})}dispatchMouse(e,t){let n=this.lastMetadata;if(!n)return;let r=B(t.canvasX,t.canvasY,t.rendered,n);this.send(`Input.dispatchMouseEvent`,Ie(e,{x:r.x,y:r.y,button:t.button,buttons:t.buttons,modifiers:t.modifiers})),this.logInput(`mouse`)}dispatchWheel(e){let t=this.lastMetadata;if(!t)return;let n=B(e.canvasX,e.canvasY,e.rendered,t);this.send(`Input.dispatchMouseEvent`,Le({x:n.x,y:n.y,deltaX:e.deltaX,deltaY:e.deltaY,modifiers:e.modifiers})),this.logInput(`wheel`)}dispatchKey(e,t){this.send(`Input.dispatchKeyEvent`,Be(e,t)),this.logInput(`key`)}insertText(e){e&&(this.send(`Input.insertText`,{text:e}),this.logInput(`paste`))}navigate(e){let t=Ve(e);t&&(this.send(`Page.navigate`,{url:t}),this.opts.onLog(`navigate`,{host:He(t)}))}async goHistory(e){let t=e<0?`back`:`forward`,n=await this.command(`Page.getNavigationHistory`,{});if(!n){this.opts.onLog(`history`,{dir:t,outcome:`no-result`});return}let{currentIndex:r,entries:i}=n,a=typeof r==`number`?i?.[r+e]:void 0;if(!a||typeof a.id!=`number`){this.opts.onLog(`history`,{dir:t,outcome:`no-entry`});return}this.send(`Page.navigateToHistoryEntry`,{entryId:a.id}),this.opts.onLog(`history`,{dir:t})}command(e,t){let n=this.send(e,t);return n===null?Promise.resolve(null):new Promise(e=>this.pending.set(n,e))}logInput(e){this.inputsSinceFrame+=1,this.inputsSinceLog+=1;let t=(this.opts.now??Date.now)();if(this.lastInputLogAtMs!==null&&t-this.lastInputLogAtMs<1e3)return;this.lastInputLogAtMs=t;let n=this.inputsSinceLog;this.inputsSinceLog=0,this.opts.onLog(`input`,{kind:e,count:n})}send(e,t){let n=this.nextId++;try{return this.ws.send(JSON.stringify({id:n,method:e,params:t})),n}catch(t){return this.opts.onLog(`send-failed`,{method:e,err:t instanceof Error?t.message:String(t)}),null}}};function V(e){let{targets:t,activeId:n,url:r,busy:i}=e,[a,o]=(0,F.useState)(r),s=(0,F.useRef)(null);return(0,F.useEffect)(()=>{s.current&&document.activeElement===s.current||o(r)},[r]),(0,F.useEffect)(()=>{o(e.url)},[n]),(0,P.jsxs)(`div`,{className:`browser-chrome`,children:[(0,P.jsxs)(`div`,{className:`browser-chrome__tabrow`,children:[(0,P.jsxs)(`div`,{className:`browser-chrome__tabs`,role:`tablist`,children:[t.map(t=>(0,P.jsxs)(`div`,{className:t.id===n?`browser-chrome__tab is-active`:`browser-chrome__tab`,role:`tab`,"aria-selected":t.id===n,children:[(0,P.jsx)(`button`,{type:`button`,className:`browser-chrome__tab-label`,onClick:()=>e.onSelect(t.id),title:t.url,children:t.title}),(0,P.jsx)(`button`,{type:`button`,className:`browser-chrome__tab-close`,"aria-label":`Close ${t.title}`,onClick:()=>e.onClose(t.id),disabled:i,children:(0,P.jsx)(u,{size:12,strokeWidth:2})})]},t.id)),(0,P.jsx)(`button`,{type:`button`,className:`browser-chrome__new`,"aria-label":`New tab`,title:`New tab`,onClick:e.onNew,disabled:i,children:(0,P.jsx)(b,{size:14,strokeWidth:2})})]}),(e.onToggleFull||e.onClosePane)&&(0,P.jsxs)(`div`,{className:`browser-chrome__window`,children:[e.onToggleFull&&(0,P.jsx)(`button`,{type:`button`,className:`browser-chrome__nav`,"aria-label":e.isFull?`Exit full screen`:`Full screen`,title:e.isFull?`Exit full screen`:`Full screen`,onClick:e.onToggleFull,children:e.isFull?(0,P.jsx)(Ce,{size:15,strokeWidth:1.75}):(0,P.jsx)(c,{size:15,strokeWidth:1.75})}),e.onClosePane&&(0,P.jsx)(`button`,{type:`button`,className:`browser-chrome__nav`,"aria-label":`Close browser`,title:`Close browser`,onClick:e.onClosePane,children:(0,P.jsx)(u,{size:16,strokeWidth:1.75})})]})]}),(0,P.jsxs)(`form`,{className:`browser-chrome__bar`,onSubmit:t=>{t.preventDefault(),e.onNavigate(a)},children:[(0,P.jsx)(`button`,{type:`button`,className:`browser-chrome__nav`,"aria-label":`Back`,title:`Back`,onClick:e.onBack,children:(0,P.jsx)(j,{size:16,strokeWidth:1.75})}),(0,P.jsx)(`button`,{type:`button`,className:`browser-chrome__nav`,"aria-label":`Forward`,title:`Forward`,onClick:e.onForward,children:(0,P.jsx)(R,{size:16,strokeWidth:1.75})}),(0,P.jsx)(`button`,{type:`button`,className:`browser-chrome__nav`,"aria-label":`Reload`,title:`Reload`,onClick:e.onReload,children:(0,P.jsx)(we,{size:15,strokeWidth:1.75})}),(0,P.jsx)(`input`,{ref:s,className:`browser-chrome__url`,"aria-label":`Address`,placeholder:`Type a URL`,value:a,onChange:e=>o(e.target.value)})]})]})}function Ge(e){return(e.altKey?1:0)|(e.ctrlKey?2:0)|(e.metaKey?4:0)|(e.shiftKey?8:0)}function H({preferTargetId:e=null,cacheKey:t=null,chrome:n=!0,surface:r=`browser`,onToggleFull:i,onClosePane:a,isFull:o=!1}={}){let[c,l]=(0,F.useState)(`probing`),[u,p]=(0,F.useState)([]),[m,h]=(0,F.useState)(null),[g,_]=(0,F.useState)(!1),[v,y]=(0,F.useState)(null),[b,x]=(0,F.useState)(!1),[ee,te]=(0,F.useState)(``),S=s(t),[ne,re]=(0,F.useState)(0),ie=(0,F.useRef)(null),ae=(0,F.useRef)(null),C=(0,F.useRef)(null),w=(0,F.useRef)(null),T=(0,F.useRef)(``),E=(0,F.useRef)(0),D=(0,F.useRef)(null),oe=(0,F.useRef)(!1),se=(0,F.useRef)(e);se.current=e,T.current||=`sc-${Math.random().toString(36).slice(2,10)}`;let O=(0,F.useCallback)((e,t={})=>{S(`/api/admin/browser/screencast-event`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({sid:T.current,op:e,...t})}).catch(()=>{})},[S]),k=(0,F.useCallback)(async()=>{try{let e=await S(`/api/admin/browser/screencast-targets`);if(!e.ok){l(`unavailable`);return}let t=await e.json().catch(()=>({})),n=Array.isArray(t.targets)?t.targets:[];if(p(n),n.length===0){h(null),l(`no-tabs`);return}let r=se.current;h(e=>r&&n.some(e=>e.id===r)?r:e&&n.some(t=>t.id===e)?e:n[0].id),l(`live`)}catch{l(`unavailable`)}},[S]);(0,F.useEffect)(()=>{O(`request`),k()},[k,O]),(0,F.useEffect)(()=>{n&&O(`chrome-mounted`,{surface:r,chrome:`v2`})},[n,r,O]),(0,F.useEffect)(()=>{te(u.find(e=>e.id===m)?.url??``)},[u,m]);let A=(0,F.useRef)(null);(0,F.useEffect)(()=>{if(e){if(u.some(t=>t.id===e)){h(e);return}A.current!==e&&(A.current=e,k())}},[e,u,k]);let ce=(0,F.useCallback)(e=>{let t=ie.current;if(!t)return;let n=new Image;n.onload=()=>{t.width=n.naturalWidth,t.height=n.naturalHeight,t.getContext(`2d`)?.drawImage(n,0,0)},n.src=`data:image/jpeg;base64,${e.data}`},[]),le=(0,F.useCallback)(()=>{let e=ae.current;if(!e)return;let t=e.getBoundingClientRect(),n=getComputedStyle(e),r=e=>Number.parseFloat(e)||0,i=t.width-r(n.paddingLeft)-r(n.paddingRight),a=t.height-r(n.paddingTop)-r(n.paddingBottom);if(!(i<1||a<1))return{width:i,height:a}},[]);(0,F.useEffect)(()=>{let e=ae.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{let e=le();e&&C.current?.setPaneSize(e)});return t.observe(e),()=>t.disconnect()},[c,le]);let j=(0,F.useCallback)(e=>{if(D.current!==null)return;let t=E.current;if(t>=Ne.length){O(`reconnect-exhausted`,{attempt:t}),l(`unavailable`);return}E.current=t+1,O(`reconnect`,{attempt:t+1,reason:e}),D.current=setTimeout(()=>{D.current=null,re(e=>e+1)},Ne[t])},[O]);(0,F.useEffect)(()=>()=>{D.current!==null&&clearTimeout(D.current)},[]),(0,F.useEffect)(()=>{if(c!==`live`||!m)return;let e=Ue({protocol:window.location.protocol,host:window.location.host},m,T.current),t=new WebSocket(e),n=new We(t,{onFrame:ce,onLog:O,onUrlChange:te});C.current=n,w.current=t;let r=!1;t.addEventListener(`open`,()=>{E.current=0,n.start(le()),oe.current&&(oe.current=!1,n.reload())}),t.addEventListener(`message`,e=>{typeof e.data==`string`&&n.handleMessage(e.data)});let i=e=>()=>{r||j(e)};return t.addEventListener(`close`,i(`close`)),t.addEventListener(`error`,i(`error`)),()=>{r=!0,n.stop(),t.close(),C.current=null,w.current=null}},[c,m,ne,ce,O,le,j]),(0,F.useEffect)(()=>{if(c!==`live`)return;let e=setInterval(()=>{let e=C.current;if(!e)return;let t=e.sinceLastFrameMs();if(t===null)return;let n=e.inputsSinceLastFrame();n===0||t<5e3||D.current===null&&(O(`frame-stall`,{sinceLastFrameMs:t,inputsSince:n}),j(`stall`))},je);return()=>clearInterval(e)},[c,ne,O,j]),(0,F.useEffect)(()=>{if(c!==`live`)return;let e=e=>e===0?`connecting`:e===1?`open`:e===2?`closing`:`closed`,t=setInterval(()=>{O(`viewer-census`,{socketState:e(w.current?.readyState),sinceLastFrameMs:C.current?.sinceLastFrameMs()??-1})},Me);return()=>clearInterval(t)},[c,O]);let M=(0,F.useCallback)(e=>t=>{let n=ie.current;if(!n)return;let r=n.getBoundingClientRect();C.current?.dispatchMouse(e,{canvasX:t.clientX-r.left,canvasY:t.clientY-r.top,rendered:{width:r.width,height:r.height},button:e===`mouseMoved`?Pe(t.buttons):t.button,buttons:t.buttons,modifiers:Ge(t)})},[]);(0,F.useEffect)(()=>{let e=ie.current;if(!e)return;let t=t=>{t.preventDefault();let n=e.getBoundingClientRect();C.current?.dispatchWheel({canvasX:t.clientX-n.left,canvasY:t.clientY-n.top,rendered:{width:n.width,height:n.height},deltaX:t.deltaX,deltaY:t.deltaY,modifiers:Ge(t)})};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[c]);let ue=(0,F.useCallback)(e=>t=>{t.preventDefault(),C.current?.dispatchKey(e,{key:t.key,code:t.code,modifiers:Ge(t)})},[]),de=(0,F.useCallback)(e=>{e.preventDefault();let t=e.clipboardData.getData(`text`);t&&C.current?.insertText(t)},[]),N=(0,F.useCallback)(async()=>{_(!0),y(null);try{let e=await S(`/api/admin/browser/launch`,{method:`POST`});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error||`Launch failed (${e.status})`)}await k()}catch(e){y(e instanceof Error?e.message:String(e))}finally{_(!1)}},[S,k]),fe=(0,F.useCallback)(async()=>{x(!0),y(null);try{c===`no-tabs`&&await S(`/api/admin/browser/launch`,{method:`POST`});let e=await S(`/api/admin/browser/tabs`,{method:`POST`});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error||`New tab failed (${e.status})`)}let t=await e.json().catch(()=>({}));await k(),t.id&&h(t.id)}catch(e){y(e instanceof Error?e.message:String(e))}finally{x(!1)}},[S,k,c]),I=(0,F.useCallback)(async e=>{x(!0),y(null);try{let t=await S(`/api/admin/browser/tabs/${encodeURIComponent(e)}`,{method:`DELETE`});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error||`Close failed (${t.status})`)}await k()}catch(e){y(e instanceof Error?e.message:String(e))}finally{x(!1)}},[S,k]),pe=(0,F.useCallback)(e=>{C.current?.navigate(e)},[]),L=(0,F.useCallback)(e=>{C.current?.goHistory(e)},[]),me=(0,F.useCallback)(()=>{if(O(`reload`,{}),E.current=0,c===`live`){oe.current=!0,re(e=>e+1);return}k()},[O,c,k]),he=c===`probing`?(0,P.jsxs)(`div`,{className:`data-loading`,children:[(0,P.jsx)(f,{size:18,className:`spin`}),` Connecting to the device browser…`]}):c===`unavailable`?(0,P.jsxs)(`div`,{className:`cdp-screencast__unavailable`,children:[(0,P.jsx)(d,{size:28,strokeWidth:1.75}),(0,P.jsx)(`p`,{children:`The device browser is not reachable.`})]}):null;return he===null?(0,P.jsxs)(`div`,{className:`cdp-screencast`,children:[n&&(0,P.jsx)(V,{targets:u,activeId:m,url:ee,busy:b,onSelect:h,onClose:I,onNew:fe,onBack:()=>L(-1),onForward:()=>L(1),onNavigate:pe,onReload:me,onToggleFull:i,onClosePane:a,isFull:o}),v&&(0,P.jsx)(`div`,{className:`cdp-screencast__toolbar`,children:(0,P.jsx)(`span`,{className:`cdp-screencast__error`,children:v})}),c===`no-tabs`?(0,P.jsxs)(`div`,{className:`cdp-screencast__unavailable`,children:[(0,P.jsx)(d,{size:28,strokeWidth:1.75}),(0,P.jsx)(`p`,{children:`No open tabs on the device browser.`}),(0,P.jsxs)(`button`,{type:`button`,className:`cdp-screencast__btn`,onClick:N,disabled:g,children:[g?(0,P.jsx)(f,{size:14,className:`spin`}):(0,P.jsx)(d,{size:14}),` Launch browser`]})]}):(0,P.jsxs)(P.Fragment,{children:[!n&&(0,P.jsx)(`div`,{className:`cdp-screencast__tabs`,children:u.map(e=>(0,P.jsx)(`button`,{type:`button`,className:e.id===m?`cdp-screencast__tab is-active`:`cdp-screencast__tab`,onClick:()=>h(e.id),title:e.url,children:e.title},e.id))}),(0,P.jsx)(`div`,{className:`cdp-screencast__viewport`,ref:ae,children:(0,P.jsx)(`canvas`,{ref:ie,className:`cdp-screencast__canvas`,tabIndex:0,onMouseDown:M(`mousePressed`),onMouseUp:M(`mouseReleased`),onMouseMove:M(`mouseMoved`),onKeyDown:ue(`keyDown`),onKeyUp:ue(`keyUp`),onPaste:de})})]})]}):(0,P.jsxs)(`div`,{className:`cdp-screencast`,children:[n&&(0,P.jsx)(V,{targets:u,activeId:m,url:ee,busy:b,onSelect:h,onClose:I,onNew:fe,onBack:()=>L(-1),onForward:()=>L(1),onNavigate:pe,onReload:me,onToggleFull:i,onClosePane:a,isFull:o}),he]})}var Ke=5e3,qe=1200;function U(e){return Math.max(qe,Math.round(Ke/(e<1?1:e)))}var Je=500,W=new Set;function Ye(e,t,n){let r=n??(typeof globalThis.fetch==`function`?globalThis.fetch:void 0);if(W.has(e)||!r)return!1;if(W.size>=Je){for(let e of W)if(W.delete(e),W.size<Je)break}W.add(e);try{Promise.resolve(r(`/api/admin/events`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({event:`channel-notify:rendered`,fields:{msgId:e,senderType:t}})})).catch(()=>{})}catch{}return!0}function Xe({type:e}){return e===`admin`?(0,P.jsx)(`svg`,{className:`channel-notify-icon`,viewBox:`0 0 16 16`,"aria-hidden":`true`,children:(0,P.jsx)(`path`,{d:`M8 1.5 13 3.5v4c0 3-2.1 5.8-5 7-2.9-1.2-5-4-5-7v-4z`})}):e===`manager-active`?(0,P.jsx)(`svg`,{className:`channel-notify-icon`,viewBox:`0 0 16 16`,"aria-hidden":`true`,children:(0,P.jsx)(`path`,{d:`M2 5.5h9l-2.5-2.5 1-1L14 6l-4.5 4-1-1L11 6.5H2zM14 10.5H5l2.5 2.5-1 1L2 10l4.5-4 1 1L5 9.5h9z`})}):e===`manager-passive`?(0,P.jsx)(`svg`,{className:`channel-notify-icon`,viewBox:`0 0 16 16`,"aria-hidden":`true`,children:(0,P.jsx)(`path`,{d:`M8 3C4.5 3 1.7 5.4 1 8c.7 2.6 3.5 5 7 5s6.3-2.4 7-5c-.7-2.6-3.5-5-7-5m0 8a3 3 0 1 1 0-6 3 3 0 0 1 0 6`})}):(0,P.jsx)(`svg`,{className:`channel-notify-icon`,viewBox:`0 0 16 16`,"aria-hidden":`true`,children:(0,P.jsx)(`path`,{d:`M8 8a3 3 0 1 0 0-6 3 3 0 0 0 0 6m0 1.5c-3 0-5.5 1.6-5.5 3.5v1h11v-1c0-1.9-2.5-3.5-5.5-3.5`})})}function Ze({frames:e,onExpire:t}){let n=(0,F.useRef)(new Map),r=(0,F.useRef)(new Map);return(0,F.useEffect)(()=>{let i=Date.now(),a=U(e.length),o=new Set(e.map(e=>e.messageId));for(let e of[...n.current.keys()])o.has(e)||(n.current.delete(e),r.current.delete(e));let s=[];for(let o of e){let e=o.messageId;n.current.has(e)||(n.current.set(e,i),Ye(e,o.senderType));let c=r.current.get(e),l=c===void 0?a:Math.min(c,a);r.current.set(e,l);let u=i-(n.current.get(e)??i);s.push(setTimeout(()=>t(e),Math.max(0,l-u)))}return()=>{for(let e of s)clearTimeout(e)}},[e,t]),e.length===0?null:(0,P.jsx)(`div`,{className:`channel-notify-host`,children:[...e].reverse().map(e=>(0,P.jsxs)(`div`,{className:`channel-notify-card channel-notify-card-${e.channel}`,role:`status`,children:[(0,P.jsxs)(`div`,{className:`channel-notify-head`,children:[(0,P.jsx)(`span`,{className:`channel-notify-pill channel-notify-pill-${e.channel}-${e.senderType}`,children:(0,P.jsx)(Xe,{type:e.senderType})}),(0,P.jsx)(`span`,{className:`channel-notify-account`,children:e.accountName})]}),(0,P.jsx)(`div`,{className:`channel-notify-sender`,children:e.senderDisplay}),(0,P.jsxs)(`div`,{className:`channel-notify-body`,children:[e.body,e.truncated?`…`:``]})]},e.messageId))})}var Qe=`channel-notify`;function $e({connected:e,onConnectClaude:t}){return e?(0,P.jsxs)(`span`,{className:`claude-status-pill`,"data-connected":`true`,title:`Claude is connected`,children:[(0,P.jsx)(`img`,{src:`/brand/claude.png`,alt:``,className:`claude-status-pill__mark`}),(0,P.jsx)(`span`,{className:`claude-status-pill__label`,children:`Connected`}),(0,P.jsx)(`span`,{className:`claude-status-pill__dot claude-status-pill__dot--live`,"aria-hidden":`true`})]}):(0,P.jsxs)(`button`,{type:`button`,className:`claude-status-pill claude-status-pill--action`,"data-connected":`false`,onClick:t,title:`Connect Claude`,children:[(0,P.jsx)(`img`,{src:`/brand/claude.png`,alt:``,className:`claude-status-pill__mark`}),(0,P.jsx)(`span`,{className:`claude-status-pill__label`,children:`Connect`}),(0,P.jsx)(`span`,{className:`claude-status-pill__dot claude-status-pill__dot--down`,"aria-hidden":`true`})]})}function et(e){return e===`/`||e===``?`Dashboard`:e.startsWith(`/chat`)?`Chat`:e.startsWith(`/tasks`)?`Tasks`:e.startsWith(`/data`)?`Data`:e.startsWith(`/calendar`)?`Calendar`:e.startsWith(`/graph`)?`Graph`:e.startsWith(`/activity`)?`Activity`:e.startsWith(`/browser`)?`Browser`:e.startsWith(`/routines`)?`Routines`:e.startsWith(`/skills`)?`Skills`:e.startsWith(`/agents`)?`Agents`:`Dashboard`}function tt({title:e,sidebarOpen:t,onToggleSidebar:n,claudeConnected:r,onConnectClaude:i,onOpenBrowser:a}){let o=e??et(typeof window<`u`?window.location.pathname:`/`),s=r!==void 0&&i!==void 0,c=a!==void 0;return(0,P.jsxs)(`header`,{className:`admin-page-header`,children:[(0,P.jsxs)(`button`,{type:`button`,className:`admin-page-header__toggle`,"aria-label":t?`Hide sidebar`:`Show sidebar`,title:t?`Hide sidebar`:`Show sidebar`,"aria-expanded":t,onClick:n,children:[(0,P.jsx)(z,{className:`admin-page-header__toggle-desktop`,size:18,strokeWidth:1.75}),(0,P.jsx)(x,{className:`admin-page-header__toggle-mobile`,size:22,strokeWidth:1.75})]}),(0,P.jsx)(`h1`,{className:`admin-page-header__title`,children:o}),(0,P.jsxs)(`div`,{className:`admin-page-header__right`,children:[(0,P.jsx)(re,{}),s&&(0,P.jsx)($e,{connected:r,onConnectClaude:i}),c&&(0,P.jsx)(`button`,{type:`button`,className:`admin-page-header__icon`,"aria-label":`Show browser`,title:`Show browser`,onClick:a,children:(0,P.jsx)(d,{size:18,strokeWidth:1.75})})]})]})}var nt=[{label:`Home`,href:`/`,Icon:k,match:e=>e===`/`||e===``},{label:`Chat`,href:`/chat`,Icon:y,match:e=>e.startsWith(`/chat`)},{label:`Tasks`,href:`/tasks`,Icon:xe,match:e=>e.startsWith(`/tasks`)},{label:`Data`,href:`/data`,Icon:S,match:e=>e.startsWith(`/data`)},{label:`Calendar`,href:`/calendar`,Icon:w,match:e=>e.startsWith(`/calendar`)}],rt=[{label:`Chat`,href:`/`,Icon:y,match:e=>e===`/`||e===``||e.startsWith(`/chat`)},{label:`Data`,href:`/data`,Icon:S,match:e=>e.startsWith(`/data`)}];function it(e){let t=nt.find(t=>t.match(e));return t?t.href:`/`}function G({variant:e=`admin`,onOpenConversations:t}={}){let n=typeof window<`u`?window.location.pathname:`/`,r=e===`operator`?rt:nt,i=e===`operator`?rt.find(e=>e.match(n))?.href??`/`:it(n),a=e=>{let t=e.href===i,{Icon:n}=e;return(0,P.jsxs)(`a`,{href:e.href,className:`bottom-tab${t?` is-active`:``}`,"aria-current":t?`page`:void 0,children:[(0,P.jsx)(n,{size:19,strokeWidth:1.75}),(0,P.jsx)(`span`,{className:`bottom-tab__label`,children:e.label})]},e.href)};return(0,P.jsxs)(`nav`,{className:`bottom-tab-bar`,"aria-label":`Primary`,children:[r.slice(0,1).map(a),e===`operator`&&t&&(0,P.jsxs)(`button`,{type:`button`,className:`bottom-tab`,onClick:t,children:[(0,P.jsx)(y,{size:19,strokeWidth:1.75}),(0,P.jsx)(`span`,{className:`bottom-tab__label`,children:`Conversations`})]}),r.slice(1).map(a)]})}var at=`maxy-shell-side-px`;function ot(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .artefact`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function st(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=Math.max(248,t-480-ot());return Math.min(Math.max(e,248),n)}function ct(){if(typeof window>`u`)return 264;try{let e=window.localStorage.getItem(at);if(!e)return 264;let t=parseInt(e,10);if(!Number.isFinite(t))return console.warn(`[admin-ui] sidebar-width-parse-failed stored=${JSON.stringify(e)} fallback=264`),264;if(t>=248)return st(t)}catch{}return 264}function lt({targetSelector:e=`.platform`}){let t=(0,F.useRef)(null),[n,r]=(0,F.useState)(()=>ct()),i=(0,F.useRef)(n);(0,F.useLayoutEffect)(()=>{let t=document.querySelector(e);!t||!(t instanceof HTMLElement)||(t.style.setProperty(`--side-px`,`${n}px`),i.current=n)},[n,e]);let a=(0,F.useCallback)(()=>{r(e=>{let t=st(e);return t===e?e:t})},[]);(0,F.useEffect)(()=>{a(),window.addEventListener(`resize`,a);let t=document.querySelector(e),n=null;return t instanceof HTMLElement&&(n=new MutationObserver(a),n.observe(t,{attributes:!0,attributeFilter:[`data-artefact`,`class`]})),()=>{window.removeEventListener(`resize`,a),n?.disconnect()}},[a,e]);let o=e=>{e.preventDefault();let n=t.current;if(!n)return;n.setPointerCapture(e.pointerId),n.classList.add(`dragging`);let a=!1,o=e=>{a=!0,r(st(Math.round(e.clientX)))},s=()=>{if(n.releasePointerCapture(e.pointerId),n.classList.remove(`dragging`),window.removeEventListener(`pointermove`,o),window.removeEventListener(`pointerup`,s),!a)return;let t=i.current;try{window.localStorage.setItem(at,String(t))}catch{}};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{r(st(264));try{window.localStorage.removeItem(at)}catch{}};return(0,P.jsx)(`div`,{ref:t,className:`side-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize sidebar`,onPointerDown:o,onDoubleClick:s})}var ut=n();function dt(e){return Math.max(14,e/2-386)}function K(e){return e.left===0&&e.top===0&&e.width===0&&e.height===0}var ft={position:`fixed`,visibility:`hidden`};function q({anchorRef:e,onClose:t,className:n,role:r,ariaLabel:i,anchorId:a,children:o}){let s=(0,F.useRef)(null),[c,l]=(0,F.useState)(ft),u=(0,F.useCallback)(()=>{let t=s.current;if(!t)return;let r=e.current,i=[n,a].filter(Boolean).join(`:`)||`unknown`,o=t.getBoundingClientRect(),c=window.innerWidth,u=window.innerHeight,d=o.width>0&&o.height>0,f=r?r.getBoundingClientRect():null,p=(e,t)=>console.error(`[anchored-popover] op=offscreen id=${i} left=${e} top=${t} w=${o.width} h=${o.height} viewport=${c},${u}`);if(!f){l({position:`fixed`,left:Math.max(4,c-o.width-dt(c)),top:Math.max(4,u-o.height-14),visibility:`visible`});return}if(d&&K(f)){l(ft),p(f.left,f.top);return}let m=f.right-o.width,h=c-o.width-4;m>h&&(m=h),m<4&&(m=4);let g=u-f.bottom-4,_=f.top-4,v=o.height+8<=g?!1:o.height+8<=_?!0:_>g,y=Math.max(0,v?_:g),b=v?Math.max(4,f.top-Math.min(o.height,y)):f.bottom;l({position:`fixed`,left:m,top:b,maxHeight:y,visibility:`visible`});let x=Math.min(o.height,y);d&&(m+o.width<=0||m>=c||b+x<=0||b>=u)&&p(m,b)},[e,a,n]);return(0,F.useLayoutEffect)(()=>{if(u(),typeof ResizeObserver>`u`)return;let e=new ResizeObserver(()=>u());return s.current&&e.observe(s.current),()=>e.disconnect()},[u]),(0,F.useEffect)(()=>{let n=e=>{e.key===`Escape`&&t()},r=n=>{let r=n.target;e.current?.contains(r)||s.current?.contains(r)||t()},i=n=>{let r=e.current;r&&n.target instanceof Node&&n.target.contains(r)&&t()},a=()=>t();return document.addEventListener(`keydown`,n),document.addEventListener(`pointerdown`,r),window.addEventListener(`scroll`,i,!0),window.addEventListener(`resize`,a),()=>{document.removeEventListener(`keydown`,n),document.removeEventListener(`pointerdown`,r),window.removeEventListener(`scroll`,i,!0),window.removeEventListener(`resize`,a)}},[e,t]),(0,ut.createPortal)((0,P.jsx)(`div`,{ref:s,className:n,role:r,"aria-label":i,style:c,children:o}),document.body)}function pt({actions:e,disabled:t,label:n=`Session actions`}){let[r,i]=(0,F.useState)(!1),[a,o]=(0,F.useState)(null),s=(0,F.useRef)(null),c=(0,F.useCallback)(()=>{i(!1),o(null)},[]);return(0,P.jsxs)(`div`,{className:`conv-actions`,children:[(0,P.jsx)(`button`,{ref:s,type:`button`,className:`conv-action conv-actions-overflow`,onClick:()=>i(e=>!e),disabled:t,"aria-haspopup":`menu`,"aria-expanded":r,"aria-label":n,title:n,children:(0,P.jsx)(x,{size:12})}),r&&(0,P.jsx)(q,{anchorRef:s,onClose:c,className:`conv-actions-menu`,role:`menu`,children:e.map(e=>e.panel?(0,P.jsxs)(`div`,{className:`conv-actions-menu-disclosure`,children:[(0,P.jsxs)(`button`,{type:`button`,role:`menuitem`,"aria-haspopup":`dialog`,"aria-expanded":a===e.key,title:e.title,disabled:t||e.disabled,onClick:()=>o(t=>t===e.key?null:e.key),children:[e.icon,(0,P.jsx)(`span`,{children:e.menuLabel})]}),a===e.key&&(0,P.jsx)(`div`,{className:`conv-actions-menu-panel`,children:e.panel()})]},e.key):(0,P.jsxs)(`button`,{type:`button`,role:`menuitem`,className:e.danger?`conv-action-danger`:void 0,"aria-busy":e.busy,title:e.title,disabled:t||e.disabled,onClick:t=>{e.onClick?.(t),c()},children:[e.icon,(0,P.jsx)(`span`,{children:e.menuLabel})]},e.key))})]})}var J=`claude-opus-5[1m]`,mt=`claude-sonnet-5`,ht=`claude-haiku-4-5`,gt={[J]:`Opus 5 (1M context)`,[mt]:`Sonnet 5`,[ht]:`Haiku 4.5`};function _t(e){return gt[e]??e}var vt=[J,mt,ht];function yt(e){return e.replace(/\[1m\]$/,``)}function bt(e){return vt.find(t=>yt(t)===yt(e))??e}var xt=[`default`,`acceptEdits`,`plan`,`auto`,`bypassPermissions`],St=[`low`,`medium`,`high`,`xhigh`];[...xt],[...St],[...St];var Ct=[J,mt,ht],wt={default:`Ask permissions`,acceptEdits:`Accept edits`,plan:`Plan mode`,auto:`Auto mode`,bypassPermissions:`Bypass permissions`},Tt=xt.map(e=>({value:e,label:wt[e]??e})),Et={low:`Low`,medium:`Medium`,high:`High`,xhigh:`Highest`},Dt=St.map(e=>({value:e,label:Et[e]??e}));function Ot(e){if(e){let t=Ct.find(t=>yt(t)===yt(e));if(t)return t}return J}function kt({row:e,adminFetch:t,onError:n}){let[r,i]=(0,F.useState)(()=>Ot(e.model)),[a,o]=(0,F.useState)(``),[s,c]=(0,F.useState)(``),[l,u]=(0,F.useState)(!1),d=(0,F.useRef)(!1);(0,F.useEffect)(()=>{i(Ot(e.model))},[e.model]);let p=async()=>{if(!d.current){d.current=!0,u(!0);try{let i=await t(`/api/admin/session-reseat`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({fromSessionId:e.sessionId,model:r,...a?{permissionMode:a}:{},...s?{effort:s}:{}})});if(!i.ok){n(`Could not reset ${e.title} (status ${i.status})`),console.error(`[admin-ui] dashboard-reseat-failed sessionId=${e.sessionId} status=${i.status}`),d.current=!1,u(!1);return}let o=await i.json().catch(()=>({}));o.target?window.location.assign(o.target):(n(`Reset of ${e.title} returned no target`),d.current=!1,u(!1))}catch(t){n(`Could not reset ${e.title} (network error)`),console.error(`[admin-ui] dashboard-reseat-failed sessionId=${e.sessionId} error=${t instanceof Error?t.message:String(t)}`),d.current=!1,u(!1)}}};return(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`label`,{className:`reseat-field`,children:[(0,P.jsx)(`span`,{children:`Model`}),(0,P.jsx)(`select`,{"data-kind":`model`,value:r,disabled:l,onChange:e=>i(e.target.value),children:Ct.map(e=>(0,P.jsx)(`option`,{value:e,children:_t(e)},e))})]}),(0,P.jsxs)(`label`,{className:`reseat-field`,children:[(0,P.jsx)(`span`,{children:`Mode`}),(0,P.jsxs)(`select`,{"data-kind":`mode`,value:a,disabled:l,onChange:e=>o(e.target.value),children:[(0,P.jsx)(`option`,{value:``,children:`Keep current`}),Tt.map(e=>(0,P.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,P.jsxs)(`label`,{className:`reseat-field`,children:[(0,P.jsx)(`span`,{children:`Effort`}),(0,P.jsxs)(`select`,{"data-kind":`effort`,value:s,disabled:l,onChange:e=>c(e.target.value),children:[(0,P.jsx)(`option`,{value:``,children:`Keep current`}),Dt.map(e=>(0,P.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,P.jsx)(`button`,{type:`button`,className:`reseat-apply`,disabled:l,"aria-busy":l,onClick:()=>void p(),children:l?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(f,{size:12,className:`spin`,"aria-hidden":`true`}),`Resetting…`]}):`Reset`})]})}function At(e){if(e<60)return`${e}s`;let t=Math.floor(e/60),n=e%60;return n>0?`${t}m ${n}s`:`${t}m`}function jt(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Mt({target:e,anchorEl:t,onConfirm:n,onCancel:r}){let i=(0,F.useRef)(null);return i.current=t,e?(0,P.jsxs)(q,{anchorRef:i,onClose:r,className:`conv-delete-confirm`,role:`alertdialog`,ariaLabel:`Confirm delete session`,children:[(0,P.jsxs)(`div`,{className:`claude-info-header`,children:[(0,P.jsx)(`span`,{children:`Delete this conversation?`}),(0,P.jsx)(`button`,{className:`claude-info-close`,onClick:r,"aria-label":`Close`,children:`✕`})]}),(0,P.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[(0,P.jsxs)(`div`,{className:`conv-delete-target`,children:[(0,P.jsx)(`span`,{className:`conv-delete-label`,title:e.title,children:e.title||`Untitled session`}),(0,P.jsx)(`code`,{className:`conv-delete-id`,title:e.sessionId,children:e.sessionId.slice(0,8)})]}),(0,P.jsx)(`div`,{style:{marginTop:`8px`},children:`This permanently removes the transcript. It is not moved to Archive and cannot be recovered.`}),e.live&&(0,P.jsx)(`div`,{style:{marginTop:`8px`},children:`This session is running; deleting stops it first.`})]}),(0,P.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,P.jsx)(L,{variant:`danger`,size:`sm`,style:{flex:1},onClick:n,children:`Delete`}),(0,P.jsx)(L,{variant:`secondary`,size:`sm`,style:{flex:1},onClick:r,children:`Cancel`})]})]}):null}function Nt({target:e,anchorEl:t,onConfirm:n,onCancel:r}){let i=(0,F.useRef)(null);return i.current=t,e?(0,P.jsxs)(q,{anchorRef:i,onClose:r,className:`conv-delete-confirm`,role:`alertdialog`,ariaLabel:`Confirm delete task`,children:[(0,P.jsxs)(`div`,{className:`claude-info-header`,children:[(0,P.jsx)(`span`,{children:`Delete this task?`}),(0,P.jsx)(`button`,{className:`claude-info-close`,onClick:r,"aria-label":`Close`,children:`✕`})]}),(0,P.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[(0,P.jsxs)(`div`,{className:`conv-delete-target`,children:[(0,P.jsx)(`span`,{className:`conv-delete-label`,title:e.name,children:e.name}),(0,P.jsx)(`code`,{className:`conv-delete-id`,children:C(e.secondsLogged)})]}),(0,P.jsx)(`div`,{style:{marginTop:`8px`},children:`This permanently removes the task and every time record on it. It cannot be recovered.`})]}),(0,P.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,P.jsx)(L,{variant:`danger`,size:`sm`,style:{flex:1},onClick:n,children:`Delete`}),(0,P.jsx)(L,{variant:`secondary`,size:`sm`,style:{flex:1},onClick:r,children:`Cancel`})]})]}):null}function Pt({open:e,count:t,liveCount:n,onConfirm:r,onCancel:i}){if(!e)return null;let a=t===1?``:`s`;return(0,P.jsx)(`div`,{className:`claude-info-overlay`,onClick:i,children:(0,P.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Confirm delete sessions`,children:[(0,P.jsxs)(`div`,{className:`claude-info-header`,children:[(0,P.jsxs)(`span`,{children:[`Delete `,t,` conversation`,a,`?`]}),(0,P.jsx)(`button`,{className:`claude-info-close`,onClick:i,"aria-label":`Close`,children:`✕`})]}),(0,P.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[`This permanently removes `,t,` transcript`,a,`. `,t===1?`It is`:`They are`,` not moved to Archive and cannot be recovered.`,n>0&&(0,P.jsxs)(`div`,{style:{marginTop:`8px`},children:[n,` `,n===1?`is`:`are`,` running and will be stopped first.`]})]}),(0,P.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,P.jsxs)(L,{variant:`danger`,size:`sm`,style:{flex:1},onClick:r,children:[`Delete `,t]}),(0,P.jsx)(L,{variant:`secondary`,size:`sm`,style:{flex:1},onClick:i,children:`Cancel`})]})]})})}function Ft(e,t){return`New session: ${v(e.toISOString(),t)}`}function It({open:e,pending:t,onConfirm:n,onCancel:r,now:i}){let{zone:a}=o(),[s,c]=(0,F.useState)(``),l=(0,F.useRef)(null),u=(0,F.useRef)(null),d=(0,F.useRef)(!1);if((0,F.useEffect)(()=>{if(!e){u.current=null,d.current=!1;return}if(u.current!==null)return;let t=Ft(i?i():new Date,a);u.current=t,c(t)},[e,i]),(0,F.useEffect)(()=>{if(!e||d.current||u.current===null||s!==u.current)return;let t=l.current;t&&(d.current=!0,t.focus(),t.setSelectionRange(0,t.value.length))},[e,s]),!e)return null;let f=s.trim(),p=f.length>0&&f.length<=200,m=()=>{p&&!t&&n(f)},h=e=>{t||r(e)};return(0,P.jsx)(`div`,{className:`claude-info-overlay`,onClick:()=>h(`backdrop`),children:(0,P.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`dialog`,"aria-label":`Name this session`,children:[(0,P.jsxs)(`div`,{className:`claude-info-header`,children:[(0,P.jsx)(`span`,{children:`Name this session`}),(0,P.jsx)(`button`,{className:`claude-info-close`,onClick:()=>h(`cancel`),"aria-label":`Close`,disabled:t,children:`✕`})]}),(0,P.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`},children:[(0,P.jsx)(`input`,{ref:l,className:`new-session-name-input`,"aria-label":`Session name`,value:s,disabled:t,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),m()),e.key===`Escape`&&(e.preventDefault(),h(`escape`))}}),(0,P.jsx)(`div`,{className:`new-session-name-hint`,children:f.length>200?`Too long by ${f.length-200}`:`You can rename it later from the session menu.`})]}),(0,P.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,P.jsx)(L,{variant:`primary`,size:`sm`,style:{flex:1},disabled:!p||t,onClick:m,children:t?`Starting…`:`Start session`}),(0,P.jsx)(L,{variant:`secondary`,size:`sm`,style:{flex:1},disabled:t,onClick:()=>h(`cancel`),children:`Cancel`})]})]})})}var Lt=`auth-refresh-failed`;function Rt({error:e,onClose:t}){if(!e)return null;let n=e.reason===Lt,r=n?`Claude sign-in expired`:`Session didn’t open`,i=n?`Your claude.ai login has expired. Re-authenticate to resume sessions.`:`The session did not bind within 60 seconds, so there is no live conversation to open.`;return(0,P.jsx)(`div`,{className:`claude-info-overlay`,onClick:t,children:(0,P.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Session could not be opened`,children:[(0,P.jsxs)(`div`,{className:`claude-info-header`,children:[(0,P.jsx)(`span`,{children:r}),(0,P.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:`✕`})]}),(0,P.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[i,(0,P.jsxs)(`div`,{className:`claude-info-row`,style:{marginTop:`8px`},children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Reason`}),(0,P.jsx)(`span`,{className:`claude-info-value`,children:e.reason})]}),e.sessionId&&(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,P.jsxs)(`span`,{className:`claude-info-value`,children:[e.sessionId.slice(0,8),`…`]})]})]})]})})}function zt(e){let{show:t,onClose:n,claudeInfo:r,messages:i,sessionElapsed:a,sessionId:o,cacheKey:s}=e,[c,l]=(0,F.useState)(null);if(!t)return null;let u=i.flatMap(e=>e.events?.filter(e=>e.type===`usage`)??[]),d=u.at(-1),f=d?.peak_request_pct==null?d?.context_window?Math.round((d.input_tokens+d.cache_creation_tokens+d.cache_read_tokens)/d.context_window*100):0:Math.round(d.peak_request_pct*100),p=u.reduce((e,t)=>e+t.input_tokens+t.cache_creation_tokens+t.cache_read_tokens+t.output_tokens,0),m=i.flatMap(e=>e.events?.filter(e=>e.type===`rate_limit`)??[]).at(-1),h=u.reduce((e,t)=>e+(t.total_cost_usd??0),0),g=r?.account?.subscriptionType,_=e=>{let t=e*1e3-Date.now();if(t<=0)return`now`;let n=Math.floor(t/36e5),r=Math.floor(t%36e5/6e4);return n>0?`${n}h ${r}m`:`${r}m`};return(0,P.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,P.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,P.jsxs)(`div`,{className:`claude-info-header`,children:[(0,P.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`claude-info-icon`}),(0,P.jsx)(`span`,{children:`Claude Code`}),(0,P.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,P.jsxs)(`div`,{className:`claude-info-section`,children:[(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Version`}),(0,P.jsx)(`span`,{className:`claude-info-value`,children:r?r.version:`…`})]}),(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Email`}),(0,P.jsx)(`span`,{className:`claude-info-value`,children:r?.account?.email??`…`})]})]}),(g||m||h>0)&&(0,P.jsxs)(`div`,{className:`claude-info-section`,children:[g&&(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Plan`}),(0,P.jsx)(`span`,{className:`claude-info-value`,style:{textTransform:`capitalize`},children:g})]}),m&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Usage`}),(0,P.jsxs)(`span`,{className:`claude-info-value`,children:[Math.round(m.utilization*100),`%`]})]}),(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Resets in`}),(0,P.jsx)(`span`,{className:`claude-info-value`,children:_(m.resetsAt)})]}),m.isUsingOverage&&(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Overage`}),(0,P.jsx)(`span`,{className:`claude-info-value`,children:`Active`})]})]}),h>0&&(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Session cost`}),(0,P.jsxs)(`span`,{className:`claude-info-value`,children:[`$`,h<.01?h.toFixed(4):h.toFixed(2)]})]})]}),(0,P.jsxs)(`div`,{className:`claude-info-section`,children:[(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Model`}),(0,P.jsx)(`span`,{className:`claude-info-value`,children:r?.model??`…`})]}),(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Context used`}),(0,P.jsx)(`span`,{className:`claude-info-value`,children:f>0?`${f}%`:`—`})]}),(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Tokens`}),(0,P.jsx)(`span`,{className:`claude-info-value`,children:p>0?jt(p):`—`})]}),(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,P.jsx)(`span`,{className:`claude-info-value`,children:At(a)})]}),(o||s)&&(()=>{let e=o??s??``;return(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,P.jsx)(`button`,{type:`button`,className:`claude-info-value claude-info-id-copy`,title:`${e} (${o?`flushed`:`pre-flush`}) — click to copy`,onClick:async()=>{l(await M(e)?`copied`:`failed`),setTimeout(()=>l(null),1200)},children:c===`copied`?`copied ✓`:c===`failed`?`copy failed ✕`:`${e.slice(0,8)}…`})]})})()]})]})})}function Bt({open:e,installed:t,latest:n,initialActionId:r,onClose:i}){let[a,o]=(0,F.useState)(r),[s,c]=(0,F.useState)(``),[l,u]=(0,F.useState)(!1),[d,f]=(0,F.useState)(!1),[p,m]=(0,F.useState)(null),[h,g]=(0,F.useState)(null),_=(0,F.useRef)(null);(0,F.useEffect)(()=>{o(r)},[r]),(0,F.useEffect)(()=>{if(!e||!a)return;let t=new EventSource(`/api/admin/actions/${a}/stream`);return t.onmessage=e=>{f(!1),c(t=>t+e.data+`
1
+ import{o as e}from"./chunk-BycB0eMI.js";import{i as t,r as n,t as r}from"./jsx-runtime-BY35JYDT.js";import{A as i,B as a,C as o,F as s,G as c,H as l,I as u,J as d,K as f,L as p,M as m,N as h,Q as g,R as _,S as v,U as y,V as b,W as x,X as ee,Y as te,Z as S,at as ne,b as re,c as ie,ct as ae,d as C,et as w,it as T,j as E,m as D,n as oe,nt as se,p as O,q as k,rt as A,st as ce,t as le,tt as j,u as M,x as ue,y as de}from"./useMediaQuery-e4ciNiuO.js";async function N(){try{let e=await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`logout`})});return e.ok?(await e.json().catch(()=>({})))?.logged_out===!0:(console.error(`[admin-ui] claude-logout http-status=${e.status}`),!1)}catch(e){return console.error(`[admin-ui] claude-logout fetch failed: ${e instanceof Error?e.message:String(e)}`),!1}}var P=r();function fe({checked:e,onChange:t,label:n,disabled:r,ariaLabel:i=n}){return(0,P.jsxs)(`label`,{className:`maxy-checkbox${r?` maxy-checkbox--disabled`:``}`,children:[(0,P.jsx)(`input`,{type:`checkbox`,"aria-label":i,checked:e,onChange:e=>t(e.target.checked),disabled:r}),(0,P.jsx)(`span`,{className:`maxy-checkbox__box`,children:`✱`}),n&&(0,P.jsx)(`span`,{className:`maxy-checkbox__label`,children:n})]})}var F=e(t(),1),I={sm:14,md:16,lg:18},pe={sm:30,md:38,lg:46};function L({variant:e=`primary`,size:t=`md`,icon:n,iconPosition:r=`leading`,loading:i=!1,fullWidth:a=!1,disabled:o=!1,type:s=`button`,onClick:c,"aria-label":l,"aria-pressed":u,style:d,className:f,children:p}){let m=[`btn`,`btn--${e}`,t===`md`?``:`btn--${t}`,a?`btn--full`:``,f].filter(Boolean).join(` `),h=I[t],g={...e===`send`?{width:pe[t],height:pe[t]}:{},...d},_=Object.keys(g).length>0;return(0,P.jsxs)(`button`,{type:s,className:m,disabled:i||o,onClick:c,"aria-label":l,"aria-pressed":u,style:_?g:void 0,children:[(0,P.jsxs)(`span`,{className:`btn__content`,style:{visibility:i?`hidden`:`visible`},children:[n&&r===`leading`&&(0,P.jsx)(n,{size:h}),p,n&&r===`trailing`&&(0,P.jsx)(n,{size:h})]}),i&&(0,P.jsx)(`span`,{className:`btn__spinner`,children:`✱`})]})}var me=A(`archive-restore`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h2`,key:`tvwodi`}],[`path`,{d:`M20 8v11a2 2 0 0 1-2 2h-2`,key:`1gkqxj`}],[`path`,{d:`m9 15 3-3 3 3`,key:`1pd0qc`}],[`path`,{d:`M12 12v9`,key:`192myk`}]]),he=A(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),R=A(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),ge=A(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),_e=A(`chevron-right`,[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]),ve=A(`ellipsis-vertical`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]]),ye=A(`external-link`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]),be=A(`gauge`,[[`path`,{d:`m12 14 4-4`,key:`9kzdfg`}],[`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`,key:`19p75a`}]]),xe=A(`list-todo`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),Se=A(`message-square`,[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}]]),Ce=A(`minimize-2`,[[`path`,{d:`m14 10 7-7`,key:`oa77jy`}],[`path`,{d:`M20 10h-6V4`,key:`mjg0md`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M4 14h6v6`,key:`rmj7iw`}]]),z=A(`panel-left`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}]]),we=A(`rotate-cw`,[[`path`,{d:`M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8`,key:`1p45f6`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}]]),Te=A(`sliders-horizontal`,[[`path`,{d:`M10 5H3`,key:`1qgfaw`}],[`path`,{d:`M12 19H3`,key:`yhmn1j`}],[`path`,{d:`M14 3v4`,key:`1sua03`}],[`path`,{d:`M16 17v4`,key:`1q0r14`}],[`path`,{d:`M21 12h-9`,key:`1o4lsq`}],[`path`,{d:`M21 19h-5`,key:`1rlt1p`}],[`path`,{d:`M21 5h-7`,key:`1oszz2`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M8 12H3`,key:`a7s4jb`}]]),Ee=A(`wand-sparkles`,[[`path`,{d:`m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72`,key:`ul74o6`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`M5 6v4`,key:`ilb8ba`}],[`path`,{d:`M19 14v4`,key:`blhpug`}],[`path`,{d:`M10 2v2`,key:`7u0qdc`}],[`path`,{d:`M7 8H3`,key:`zfb6yr`}],[`path`,{d:`M21 16h-4`,key:`1cnmox`}],[`path`,{d:`M11 3H9`,key:`1obp7u`}]]),De=A(`waypoints`,[[`path`,{d:`m10.586 5.414-5.172 5.172`,key:`4mc350`}],[`path`,{d:`m18.586 13.414-5.172 5.172`,key:`8c96vv`}],[`path`,{d:`M6 12h12`,key:`8npq4p`}],[`circle`,{cx:`12`,cy:`20`,r:`2`,key:`144qzu`}],[`circle`,{cx:`12`,cy:`4`,r:`2`,key:`muu5ef`}],[`circle`,{cx:`20`,cy:`12`,r:`2`,key:`1xzzfp`}],[`circle`,{cx:`4`,cy:`12`,r:`2`,key:`1hvhnz`}]]),Oe=A(`zap`,[[`path`,{d:`M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z`,key:`1xq2db`}]]),ke=`/cdp-screencast`;function Ae(e){return{format:`jpeg`,quality:60,maxWidth:e?Math.max(320,Math.round(e.width)):1280,maxHeight:e?Math.max(320,Math.round(e.height)):800,everyNthFrame:1}}var je=1e3,Me=3e4,Ne=[0,1e3,2e3,4e3];function B(e,t,n,r){return n.width<=0||n.height<=0?{x:0,y:0}:{x:e/n.width*r.deviceWidth,y:t/n.height*r.deviceHeight}}function Pe(e){return e&1?0:e&4?1:e&2?2:-1}function Fe(e){return e===0?`left`:e===1?`middle`:e===2?`right`:`none`}function Ie(e,t){let n=Fe(t.button);return{type:e,x:t.x,y:t.y,button:n,buttons:t.buttons,clickCount:e===`mouseMoved`?0:1,modifiers:t.modifiers}}function Le(e){return{type:`mouseWheel`,x:e.x,y:e.y,button:`none`,buttons:0,clickCount:0,modifiers:e.modifiers,deltaX:e.deltaX,deltaY:e.deltaY}}var Re={Backspace:8,Tab:9,Enter:13,Escape:27,PageUp:33,PageDown:34,End:35,Home:36,ArrowLeft:37,ArrowUp:38,ArrowRight:39,ArrowDown:40,Delete:46},ze={Enter:`\r`,Tab:` `};function Be(e,t){let n=t.key.length===1,r=n&&/[a-z0-9]/i.test(t.key)?t.key.toUpperCase().charCodeAt(0):Re[t.key]??0,i={type:e,key:t.key,code:t.code,modifiers:t.modifiers,windowsVirtualKeyCode:r,nativeVirtualKeyCode:r};if(e===`keyDown`){let e=n?t.key:ze[t.key];e!==void 0&&(i.text=e,i.unmodifiedText=e)}return i}function Ve(e){let t=e.trim();return t?/^[a-z][a-z0-9+.-]*:/i.test(t)?t:`https://${t}`:``}function He(e){try{return new URL(Ve(e)).host}catch{return``}}function Ue(e,t,n){return`${e.protocol===`https:`?`wss`:`ws`}://${e.host}${ke}?targetId=${encodeURIComponent(t)}&sid=${encodeURIComponent(n)}`}var We=class{nextId=1;startId=null;frames=0;stopped=!1;lastMetadata=null;lastInputLogAtMs=null;inputsSinceLog=0;lastFrameAtMs=null;inputsSinceFrame=0;pending=new Map;constructor(e,t){this.ws=e,this.opts=t}frameCount(){return this.frames}sinceLastFrameMs(){return this.lastFrameAtMs===null?null:(this.opts.now??Date.now)()-this.lastFrameAtMs}inputsSinceLastFrame(){return this.inputsSinceFrame}reload(){this.send(`Page.reload`,{})}start(e){this.send(`Page.bringToFront`,{}),this.send(`Page.enable`,{}),e&&this.setPaneSize(e);let t=Ae(e);this.startId=this.send(`Page.startScreencast`,t)}setPaneSize(e){let t=Math.max(1,Math.round(e.width)),n=Math.max(1,Math.round(e.height));this.send(`Emulation.setDeviceMetricsOverride`,{width:t,height:n,deviceScaleFactor:0,mobile:!1})}stop(){if(this.stopped)return;this.stopped=!0;let e=this.send(`Page.stopScreencast`,{})!==null;this.send(`Emulation.clearDeviceMetricsOverride`,{}),this.opts.onLog(`teardown`,{stopSent:e})}handleMessage(e){let t;try{t=JSON.parse(e)}catch{return}if(typeof t.id==`number`){let e=this.pending.get(t.id);if(e){this.pending.delete(t.id),e(t.error?null:t.result);return}}if(typeof t.id==`number`&&t.id===this.startId){if(t.error)this.opts.onLog(`start-failed`,{err:t.error.message??`unknown`});else{let e=Ae();this.opts.onLog(`screencast-started`,{format:e.format,everyNthFrame:e.everyNthFrame})}return}if(t.method===`Page.frameNavigated`){let e=t.params?.frame;e&&e.parentId===void 0&&typeof e.url==`string`&&this.opts.onUrlChange?.(e.url);return}if(t.method!==`Page.screencastFrame`||this.stopped)return;let n=t.params;if(typeof n?.data!=`string`){this.opts.onLog(`frame-dropped`,{reason:`no-data`});return}if(typeof n?.metadata!=`object`||n.metadata===null){this.opts.onLog(`frame-dropped`,{reason:`no-metadata`});return}let r=n.metadata;typeof n.sessionId==`number`?this.send(`Page.screencastFrameAck`,{sessionId:n.sessionId}):this.opts.onLog(`frame-unacked`,{}),this.frames+=1,this.lastFrameAtMs=(this.opts.now??Date.now)(),this.inputsSinceFrame=0,this.lastMetadata=r,this.frames%30==0&&this.opts.onLog(`frame`,{seq:this.frames}),this.opts.onFrame({data:n.data,metadata:r})}dispatchMouse(e,t){let n=this.lastMetadata;if(!n)return;let r=B(t.canvasX,t.canvasY,t.rendered,n);this.send(`Input.dispatchMouseEvent`,Ie(e,{x:r.x,y:r.y,button:t.button,buttons:t.buttons,modifiers:t.modifiers})),this.logInput(`mouse`)}dispatchWheel(e){let t=this.lastMetadata;if(!t)return;let n=B(e.canvasX,e.canvasY,e.rendered,t);this.send(`Input.dispatchMouseEvent`,Le({x:n.x,y:n.y,deltaX:e.deltaX,deltaY:e.deltaY,modifiers:e.modifiers})),this.logInput(`wheel`)}dispatchKey(e,t){this.send(`Input.dispatchKeyEvent`,Be(e,t)),this.logInput(`key`)}insertText(e){e&&(this.send(`Input.insertText`,{text:e}),this.logInput(`paste`))}navigate(e){let t=Ve(e);t&&(this.send(`Page.navigate`,{url:t}),this.opts.onLog(`navigate`,{host:He(t)}))}async goHistory(e){let t=e<0?`back`:`forward`,n=await this.command(`Page.getNavigationHistory`,{});if(!n){this.opts.onLog(`history`,{dir:t,outcome:`no-result`});return}let{currentIndex:r,entries:i}=n,a=typeof r==`number`?i?.[r+e]:void 0;if(!a||typeof a.id!=`number`){this.opts.onLog(`history`,{dir:t,outcome:`no-entry`});return}this.send(`Page.navigateToHistoryEntry`,{entryId:a.id}),this.opts.onLog(`history`,{dir:t})}command(e,t){let n=this.send(e,t);return n===null?Promise.resolve(null):new Promise(e=>this.pending.set(n,e))}logInput(e){this.inputsSinceFrame+=1,this.inputsSinceLog+=1;let t=(this.opts.now??Date.now)();if(this.lastInputLogAtMs!==null&&t-this.lastInputLogAtMs<1e3)return;this.lastInputLogAtMs=t;let n=this.inputsSinceLog;this.inputsSinceLog=0,this.opts.onLog(`input`,{kind:e,count:n})}send(e,t){let n=this.nextId++;try{return this.ws.send(JSON.stringify({id:n,method:e,params:t})),n}catch(t){return this.opts.onLog(`send-failed`,{method:e,err:t instanceof Error?t.message:String(t)}),null}}};function V(e){let{targets:t,activeId:n,url:r,busy:i}=e,[a,o]=(0,F.useState)(r),s=(0,F.useRef)(null);return(0,F.useEffect)(()=>{s.current&&document.activeElement===s.current||o(r)},[r]),(0,F.useEffect)(()=>{o(e.url)},[n]),(0,P.jsxs)(`div`,{className:`browser-chrome`,children:[(0,P.jsxs)(`div`,{className:`browser-chrome__tabrow`,children:[(0,P.jsxs)(`div`,{className:`browser-chrome__tabs`,role:`tablist`,children:[t.map(t=>(0,P.jsxs)(`div`,{className:t.id===n?`browser-chrome__tab is-active`:`browser-chrome__tab`,role:`tab`,"aria-selected":t.id===n,children:[(0,P.jsx)(`button`,{type:`button`,className:`browser-chrome__tab-label`,onClick:()=>e.onSelect(t.id),title:t.url,children:t.title}),(0,P.jsx)(`button`,{type:`button`,className:`browser-chrome__tab-close`,"aria-label":`Close ${t.title}`,onClick:()=>e.onClose(t.id),disabled:i,children:(0,P.jsx)(u,{size:12,strokeWidth:2})})]},t.id)),(0,P.jsx)(`button`,{type:`button`,className:`browser-chrome__new`,"aria-label":`New tab`,title:`New tab`,onClick:e.onNew,disabled:i,children:(0,P.jsx)(b,{size:14,strokeWidth:2})})]}),(e.onToggleFull||e.onClosePane)&&(0,P.jsxs)(`div`,{className:`browser-chrome__window`,children:[e.onToggleFull&&(0,P.jsx)(`button`,{type:`button`,className:`browser-chrome__nav`,"aria-label":e.isFull?`Exit full screen`:`Full screen`,title:e.isFull?`Exit full screen`:`Full screen`,onClick:e.onToggleFull,children:e.isFull?(0,P.jsx)(Ce,{size:15,strokeWidth:1.75}):(0,P.jsx)(c,{size:15,strokeWidth:1.75})}),e.onClosePane&&(0,P.jsx)(`button`,{type:`button`,className:`browser-chrome__nav`,"aria-label":`Close browser`,title:`Close browser`,onClick:e.onClosePane,children:(0,P.jsx)(u,{size:16,strokeWidth:1.75})})]})]}),(0,P.jsxs)(`form`,{className:`browser-chrome__bar`,onSubmit:t=>{t.preventDefault(),e.onNavigate(a)},children:[(0,P.jsx)(`button`,{type:`button`,className:`browser-chrome__nav`,"aria-label":`Back`,title:`Back`,onClick:e.onBack,children:(0,P.jsx)(j,{size:16,strokeWidth:1.75})}),(0,P.jsx)(`button`,{type:`button`,className:`browser-chrome__nav`,"aria-label":`Forward`,title:`Forward`,onClick:e.onForward,children:(0,P.jsx)(R,{size:16,strokeWidth:1.75})}),(0,P.jsx)(`button`,{type:`button`,className:`browser-chrome__nav`,"aria-label":`Reload`,title:`Reload`,onClick:e.onReload,children:(0,P.jsx)(we,{size:15,strokeWidth:1.75})}),(0,P.jsx)(`input`,{ref:s,className:`browser-chrome__url`,"aria-label":`Address`,placeholder:`Type a URL`,value:a,onChange:e=>o(e.target.value)})]})]})}function Ge(e){return(e.altKey?1:0)|(e.ctrlKey?2:0)|(e.metaKey?4:0)|(e.shiftKey?8:0)}function H({preferTargetId:e=null,cacheKey:t=null,chrome:n=!0,surface:r=`browser`,onToggleFull:i,onClosePane:a,isFull:o=!1}={}){let[c,l]=(0,F.useState)(`probing`),[u,p]=(0,F.useState)([]),[m,h]=(0,F.useState)(null),[g,_]=(0,F.useState)(!1),[v,y]=(0,F.useState)(null),[b,x]=(0,F.useState)(!1),[ee,te]=(0,F.useState)(``),S=s(t),[ne,re]=(0,F.useState)(0),ie=(0,F.useRef)(null),ae=(0,F.useRef)(null),C=(0,F.useRef)(null),w=(0,F.useRef)(null),T=(0,F.useRef)(``),E=(0,F.useRef)(0),D=(0,F.useRef)(null),oe=(0,F.useRef)(!1),se=(0,F.useRef)(e);se.current=e,T.current||=`sc-${Math.random().toString(36).slice(2,10)}`;let O=(0,F.useCallback)((e,t={})=>{S(`/api/admin/browser/screencast-event`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({sid:T.current,op:e,...t})}).catch(()=>{})},[S]),k=(0,F.useCallback)(async()=>{try{let e=await S(`/api/admin/browser/screencast-targets`);if(!e.ok){l(`unavailable`);return}let t=await e.json().catch(()=>({})),n=Array.isArray(t.targets)?t.targets:[];if(p(n),n.length===0){h(null),l(`no-tabs`);return}let r=se.current;h(e=>r&&n.some(e=>e.id===r)?r:e&&n.some(t=>t.id===e)?e:n[0].id),l(`live`)}catch{l(`unavailable`)}},[S]);(0,F.useEffect)(()=>{O(`request`),k()},[k,O]),(0,F.useEffect)(()=>{n&&O(`chrome-mounted`,{surface:r,chrome:`v2`})},[n,r,O]),(0,F.useEffect)(()=>{te(u.find(e=>e.id===m)?.url??``)},[u,m]);let A=(0,F.useRef)(null);(0,F.useEffect)(()=>{if(e){if(u.some(t=>t.id===e)){h(e);return}A.current!==e&&(A.current=e,k())}},[e,u,k]);let ce=(0,F.useCallback)(e=>{let t=ie.current;if(!t)return;let n=new Image;n.onload=()=>{t.width=n.naturalWidth,t.height=n.naturalHeight,t.getContext(`2d`)?.drawImage(n,0,0)},n.src=`data:image/jpeg;base64,${e.data}`},[]),le=(0,F.useCallback)(()=>{let e=ae.current;if(!e)return;let t=e.getBoundingClientRect(),n=getComputedStyle(e),r=e=>Number.parseFloat(e)||0,i=t.width-r(n.paddingLeft)-r(n.paddingRight),a=t.height-r(n.paddingTop)-r(n.paddingBottom);if(!(i<1||a<1))return{width:i,height:a}},[]);(0,F.useEffect)(()=>{let e=ae.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{let e=le();e&&C.current?.setPaneSize(e)});return t.observe(e),()=>t.disconnect()},[c,le]);let j=(0,F.useCallback)(e=>{if(D.current!==null)return;let t=E.current;if(t>=Ne.length){O(`reconnect-exhausted`,{attempt:t}),l(`unavailable`);return}E.current=t+1,O(`reconnect`,{attempt:t+1,reason:e}),D.current=setTimeout(()=>{D.current=null,re(e=>e+1)},Ne[t])},[O]);(0,F.useEffect)(()=>()=>{D.current!==null&&clearTimeout(D.current)},[]),(0,F.useEffect)(()=>{if(c!==`live`||!m)return;let e=Ue({protocol:window.location.protocol,host:window.location.host},m,T.current),t=new WebSocket(e),n=new We(t,{onFrame:ce,onLog:O,onUrlChange:te});C.current=n,w.current=t;let r=!1;t.addEventListener(`open`,()=>{E.current=0,n.start(le()),oe.current&&(oe.current=!1,n.reload())}),t.addEventListener(`message`,e=>{typeof e.data==`string`&&n.handleMessage(e.data)});let i=e=>()=>{r||j(e)};return t.addEventListener(`close`,i(`close`)),t.addEventListener(`error`,i(`error`)),()=>{r=!0,n.stop(),t.close(),C.current=null,w.current=null}},[c,m,ne,ce,O,le,j]),(0,F.useEffect)(()=>{if(c!==`live`)return;let e=setInterval(()=>{let e=C.current;if(!e)return;let t=e.sinceLastFrameMs();if(t===null)return;let n=e.inputsSinceLastFrame();n===0||t<5e3||D.current===null&&(O(`frame-stall`,{sinceLastFrameMs:t,inputsSince:n}),j(`stall`))},je);return()=>clearInterval(e)},[c,ne,O,j]),(0,F.useEffect)(()=>{if(c!==`live`)return;let e=e=>e===0?`connecting`:e===1?`open`:e===2?`closing`:`closed`,t=setInterval(()=>{O(`viewer-census`,{socketState:e(w.current?.readyState),sinceLastFrameMs:C.current?.sinceLastFrameMs()??-1})},Me);return()=>clearInterval(t)},[c,O]);let M=(0,F.useCallback)(e=>t=>{let n=ie.current;if(!n)return;let r=n.getBoundingClientRect();C.current?.dispatchMouse(e,{canvasX:t.clientX-r.left,canvasY:t.clientY-r.top,rendered:{width:r.width,height:r.height},button:e===`mouseMoved`?Pe(t.buttons):t.button,buttons:t.buttons,modifiers:Ge(t)})},[]);(0,F.useEffect)(()=>{let e=ie.current;if(!e)return;let t=t=>{t.preventDefault();let n=e.getBoundingClientRect();C.current?.dispatchWheel({canvasX:t.clientX-n.left,canvasY:t.clientY-n.top,rendered:{width:n.width,height:n.height},deltaX:t.deltaX,deltaY:t.deltaY,modifiers:Ge(t)})};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[c]);let ue=(0,F.useCallback)(e=>t=>{t.preventDefault(),C.current?.dispatchKey(e,{key:t.key,code:t.code,modifiers:Ge(t)})},[]),de=(0,F.useCallback)(e=>{e.preventDefault();let t=e.clipboardData.getData(`text`);t&&C.current?.insertText(t)},[]),N=(0,F.useCallback)(async()=>{_(!0),y(null);try{let e=await S(`/api/admin/browser/launch`,{method:`POST`});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error||`Launch failed (${e.status})`)}await k()}catch(e){y(e instanceof Error?e.message:String(e))}finally{_(!1)}},[S,k]),fe=(0,F.useCallback)(async()=>{x(!0),y(null);try{c===`no-tabs`&&await S(`/api/admin/browser/launch`,{method:`POST`});let e=await S(`/api/admin/browser/tabs`,{method:`POST`});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error||`New tab failed (${e.status})`)}let t=await e.json().catch(()=>({}));await k(),t.id&&h(t.id)}catch(e){y(e instanceof Error?e.message:String(e))}finally{x(!1)}},[S,k,c]),I=(0,F.useCallback)(async e=>{x(!0),y(null);try{let t=await S(`/api/admin/browser/tabs/${encodeURIComponent(e)}`,{method:`DELETE`});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error||`Close failed (${t.status})`)}await k()}catch(e){y(e instanceof Error?e.message:String(e))}finally{x(!1)}},[S,k]),pe=(0,F.useCallback)(e=>{C.current?.navigate(e)},[]),L=(0,F.useCallback)(e=>{C.current?.goHistory(e)},[]),me=(0,F.useCallback)(()=>{if(O(`reload`,{}),E.current=0,c===`live`){oe.current=!0,re(e=>e+1);return}k()},[O,c,k]),he=c===`probing`?(0,P.jsxs)(`div`,{className:`data-loading`,children:[(0,P.jsx)(f,{size:18,className:`spin`}),` Connecting to the device browser…`]}):c===`unavailable`?(0,P.jsxs)(`div`,{className:`cdp-screencast__unavailable`,children:[(0,P.jsx)(d,{size:28,strokeWidth:1.75}),(0,P.jsx)(`p`,{children:`The device browser is not reachable.`})]}):null;return he===null?(0,P.jsxs)(`div`,{className:`cdp-screencast`,children:[n&&(0,P.jsx)(V,{targets:u,activeId:m,url:ee,busy:b,onSelect:h,onClose:I,onNew:fe,onBack:()=>L(-1),onForward:()=>L(1),onNavigate:pe,onReload:me,onToggleFull:i,onClosePane:a,isFull:o}),v&&(0,P.jsx)(`div`,{className:`cdp-screencast__toolbar`,children:(0,P.jsx)(`span`,{className:`cdp-screencast__error`,children:v})}),c===`no-tabs`?(0,P.jsxs)(`div`,{className:`cdp-screencast__unavailable`,children:[(0,P.jsx)(d,{size:28,strokeWidth:1.75}),(0,P.jsx)(`p`,{children:`No open tabs on the device browser.`}),(0,P.jsxs)(`button`,{type:`button`,className:`cdp-screencast__btn`,onClick:N,disabled:g,children:[g?(0,P.jsx)(f,{size:14,className:`spin`}):(0,P.jsx)(d,{size:14}),` Launch browser`]})]}):(0,P.jsxs)(P.Fragment,{children:[!n&&(0,P.jsx)(`div`,{className:`cdp-screencast__tabs`,children:u.map(e=>(0,P.jsx)(`button`,{type:`button`,className:e.id===m?`cdp-screencast__tab is-active`:`cdp-screencast__tab`,onClick:()=>h(e.id),title:e.url,children:e.title},e.id))}),(0,P.jsx)(`div`,{className:`cdp-screencast__viewport`,ref:ae,children:(0,P.jsx)(`canvas`,{ref:ie,className:`cdp-screencast__canvas`,tabIndex:0,onMouseDown:M(`mousePressed`),onMouseUp:M(`mouseReleased`),onMouseMove:M(`mouseMoved`),onKeyDown:ue(`keyDown`),onKeyUp:ue(`keyUp`),onPaste:de})})]})]}):(0,P.jsxs)(`div`,{className:`cdp-screencast`,children:[n&&(0,P.jsx)(V,{targets:u,activeId:m,url:ee,busy:b,onSelect:h,onClose:I,onNew:fe,onBack:()=>L(-1),onForward:()=>L(1),onNavigate:pe,onReload:me,onToggleFull:i,onClosePane:a,isFull:o}),he]})}var Ke=5e3,qe=1200;function U(e){return Math.max(qe,Math.round(Ke/(e<1?1:e)))}var Je=500,W=new Set;function Ye(e,t,n){let r=n??(typeof globalThis.fetch==`function`?globalThis.fetch:void 0);if(W.has(e)||!r)return!1;if(W.size>=Je){for(let e of W)if(W.delete(e),W.size<Je)break}W.add(e);try{Promise.resolve(r(`/api/admin/events`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({event:`channel-notify:rendered`,fields:{msgId:e,senderType:t}})})).catch(()=>{})}catch{}return!0}function Xe({type:e}){return e===`admin`?(0,P.jsx)(`svg`,{className:`channel-notify-icon`,viewBox:`0 0 16 16`,"aria-hidden":`true`,children:(0,P.jsx)(`path`,{d:`M8 1.5 13 3.5v4c0 3-2.1 5.8-5 7-2.9-1.2-5-4-5-7v-4z`})}):e===`manager-active`?(0,P.jsx)(`svg`,{className:`channel-notify-icon`,viewBox:`0 0 16 16`,"aria-hidden":`true`,children:(0,P.jsx)(`path`,{d:`M2 5.5h9l-2.5-2.5 1-1L14 6l-4.5 4-1-1L11 6.5H2zM14 10.5H5l2.5 2.5-1 1L2 10l4.5-4 1 1L5 9.5h9z`})}):e===`manager-passive`?(0,P.jsx)(`svg`,{className:`channel-notify-icon`,viewBox:`0 0 16 16`,"aria-hidden":`true`,children:(0,P.jsx)(`path`,{d:`M8 3C4.5 3 1.7 5.4 1 8c.7 2.6 3.5 5 7 5s6.3-2.4 7-5c-.7-2.6-3.5-5-7-5m0 8a3 3 0 1 1 0-6 3 3 0 0 1 0 6`})}):(0,P.jsx)(`svg`,{className:`channel-notify-icon`,viewBox:`0 0 16 16`,"aria-hidden":`true`,children:(0,P.jsx)(`path`,{d:`M8 8a3 3 0 1 0 0-6 3 3 0 0 0 0 6m0 1.5c-3 0-5.5 1.6-5.5 3.5v1h11v-1c0-1.9-2.5-3.5-5.5-3.5`})})}function Ze({frames:e,onExpire:t}){let n=(0,F.useRef)(new Map),r=(0,F.useRef)(new Map);return(0,F.useEffect)(()=>{let i=Date.now(),a=U(e.length),o=new Set(e.map(e=>e.messageId));for(let e of[...n.current.keys()])o.has(e)||(n.current.delete(e),r.current.delete(e));let s=[];for(let o of e){let e=o.messageId;n.current.has(e)||(n.current.set(e,i),Ye(e,o.senderType));let c=r.current.get(e),l=c===void 0?a:Math.min(c,a);r.current.set(e,l);let u=i-(n.current.get(e)??i);s.push(setTimeout(()=>t(e),Math.max(0,l-u)))}return()=>{for(let e of s)clearTimeout(e)}},[e,t]),e.length===0?null:(0,P.jsx)(`div`,{className:`channel-notify-host`,children:[...e].reverse().map(e=>(0,P.jsxs)(`div`,{className:`channel-notify-card channel-notify-card-${e.channel}`,role:`status`,children:[(0,P.jsxs)(`div`,{className:`channel-notify-head`,children:[(0,P.jsx)(`span`,{className:`channel-notify-pill channel-notify-pill-${e.channel}-${e.senderType}`,children:(0,P.jsx)(Xe,{type:e.senderType})}),(0,P.jsx)(`span`,{className:`channel-notify-account`,children:e.accountName})]}),(0,P.jsx)(`div`,{className:`channel-notify-sender`,children:e.senderDisplay}),(0,P.jsxs)(`div`,{className:`channel-notify-body`,children:[e.body,e.truncated?`…`:``]})]},e.messageId))})}var Qe=`channel-notify`;function $e({connected:e,onConnectClaude:t}){return e?(0,P.jsxs)(`span`,{className:`claude-status-pill`,"data-connected":`true`,title:`Claude is connected`,children:[(0,P.jsx)(`img`,{src:`/brand/claude.png`,alt:``,className:`claude-status-pill__mark`}),(0,P.jsx)(`span`,{className:`claude-status-pill__label`,children:`Connected`}),(0,P.jsx)(`span`,{className:`claude-status-pill__dot claude-status-pill__dot--live`,"aria-hidden":`true`})]}):(0,P.jsxs)(`button`,{type:`button`,className:`claude-status-pill claude-status-pill--action`,"data-connected":`false`,onClick:t,title:`Connect Claude`,children:[(0,P.jsx)(`img`,{src:`/brand/claude.png`,alt:``,className:`claude-status-pill__mark`}),(0,P.jsx)(`span`,{className:`claude-status-pill__label`,children:`Connect`}),(0,P.jsx)(`span`,{className:`claude-status-pill__dot claude-status-pill__dot--down`,"aria-hidden":`true`})]})}function et(e){return e===`/`||e===``?`Dashboard`:e.startsWith(`/chat`)?`Chat`:e.startsWith(`/tasks`)?`Tasks`:e.startsWith(`/data`)?`Data`:e.startsWith(`/calendar`)?`Calendar`:e.startsWith(`/graph`)?`Graph`:e.startsWith(`/activity`)?`Activity`:e.startsWith(`/browser`)?`Browser`:e.startsWith(`/routines`)?`Routines`:e.startsWith(`/skills`)?`Skills`:e.startsWith(`/agents`)?`Agents`:`Dashboard`}function tt({title:e,sidebarOpen:t,onToggleSidebar:n,claudeConnected:r,onConnectClaude:i,onOpenBrowser:a}){let o=e??et(typeof window<`u`?window.location.pathname:`/`),s=r!==void 0&&i!==void 0,c=a!==void 0;return(0,P.jsxs)(`header`,{className:`admin-page-header`,children:[(0,P.jsxs)(`button`,{type:`button`,className:`admin-page-header__toggle`,"aria-label":t?`Hide sidebar`:`Show sidebar`,title:t?`Hide sidebar`:`Show sidebar`,"aria-expanded":t,onClick:n,children:[(0,P.jsx)(z,{className:`admin-page-header__toggle-desktop`,size:18,strokeWidth:1.75}),(0,P.jsx)(x,{className:`admin-page-header__toggle-mobile`,size:22,strokeWidth:1.75})]}),(0,P.jsx)(`h1`,{className:`admin-page-header__title`,children:o}),(0,P.jsxs)(`div`,{className:`admin-page-header__right`,children:[(0,P.jsx)(re,{}),s&&(0,P.jsx)($e,{connected:r,onConnectClaude:i}),c&&(0,P.jsx)(`button`,{type:`button`,className:`admin-page-header__icon`,"aria-label":`Show browser`,title:`Show browser`,onClick:a,children:(0,P.jsx)(d,{size:18,strokeWidth:1.75})})]})]})}var nt=[{label:`Home`,href:`/`,Icon:k,match:e=>e===`/`||e===``},{label:`Chat`,href:`/chat`,Icon:y,match:e=>e.startsWith(`/chat`)},{label:`Tasks`,href:`/tasks`,Icon:xe,match:e=>e.startsWith(`/tasks`)},{label:`Data`,href:`/data`,Icon:S,match:e=>e.startsWith(`/data`)},{label:`Calendar`,href:`/calendar`,Icon:w,match:e=>e.startsWith(`/calendar`)}],rt=[{label:`Chat`,href:`/`,Icon:y,match:e=>e===`/`||e===``||e.startsWith(`/chat`)},{label:`Data`,href:`/data`,Icon:S,match:e=>e.startsWith(`/data`)}];function it(e){let t=nt.find(t=>t.match(e));return t?t.href:`/`}function G({variant:e=`admin`,onOpenConversations:t}={}){let n=typeof window<`u`?window.location.pathname:`/`,r=e===`operator`?rt:nt,i=e===`operator`?rt.find(e=>e.match(n))?.href??`/`:it(n),a=e=>{let t=e.href===i,{Icon:n}=e;return(0,P.jsxs)(`a`,{href:e.href,className:`bottom-tab${t?` is-active`:``}`,"aria-current":t?`page`:void 0,children:[(0,P.jsx)(n,{size:19,strokeWidth:1.75}),(0,P.jsx)(`span`,{className:`bottom-tab__label`,children:e.label})]},e.href)};return(0,P.jsxs)(`nav`,{className:`bottom-tab-bar`,"aria-label":`Primary`,children:[r.slice(0,1).map(a),e===`operator`&&t&&(0,P.jsxs)(`button`,{type:`button`,className:`bottom-tab`,onClick:t,children:[(0,P.jsx)(y,{size:19,strokeWidth:1.75}),(0,P.jsx)(`span`,{className:`bottom-tab__label`,children:`Conversations`})]}),r.slice(1).map(a)]})}var at=`maxy-shell-side-px`;function ot(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .artefact`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function st(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=Math.max(248,t-480-ot());return Math.min(Math.max(e,248),n)}function ct(){if(typeof window>`u`)return 264;try{let e=window.localStorage.getItem(at);if(!e)return 264;let t=parseInt(e,10);if(!Number.isFinite(t))return console.warn(`[admin-ui] sidebar-width-parse-failed stored=${JSON.stringify(e)} fallback=264`),264;if(t>=248)return st(t)}catch{}return 264}function lt({targetSelector:e=`.platform`}){let t=(0,F.useRef)(null),[n,r]=(0,F.useState)(()=>ct()),i=(0,F.useRef)(n);(0,F.useLayoutEffect)(()=>{let t=document.querySelector(e);!t||!(t instanceof HTMLElement)||(t.style.setProperty(`--side-px`,`${n}px`),i.current=n)},[n,e]);let a=(0,F.useCallback)(()=>{r(e=>{let t=st(e);return t===e?e:t})},[]);(0,F.useEffect)(()=>{a(),window.addEventListener(`resize`,a);let t=document.querySelector(e),n=null;return t instanceof HTMLElement&&(n=new MutationObserver(a),n.observe(t,{attributes:!0,attributeFilter:[`data-artefact`,`class`]})),()=>{window.removeEventListener(`resize`,a),n?.disconnect()}},[a,e]);let o=e=>{e.preventDefault();let n=t.current;if(!n)return;n.setPointerCapture(e.pointerId),n.classList.add(`dragging`);let a=!1,o=e=>{a=!0,r(st(Math.round(e.clientX)))},s=()=>{if(n.releasePointerCapture(e.pointerId),n.classList.remove(`dragging`),window.removeEventListener(`pointermove`,o),window.removeEventListener(`pointerup`,s),!a)return;let t=i.current;try{window.localStorage.setItem(at,String(t))}catch{}};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{r(st(264));try{window.localStorage.removeItem(at)}catch{}};return(0,P.jsx)(`div`,{ref:t,className:`side-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize sidebar`,onPointerDown:o,onDoubleClick:s})}var ut=n();function dt(e){return Math.max(14,e/2-386)}function K(e){return e.left===0&&e.top===0&&e.width===0&&e.height===0}var ft={position:`fixed`,visibility:`hidden`};function q({anchorRef:e,onClose:t,className:n,role:r,ariaLabel:i,anchorId:a,children:o}){let s=(0,F.useRef)(null),[c,l]=(0,F.useState)(ft),u=(0,F.useCallback)(()=>{let t=s.current;if(!t)return;let r=e.current,i=[n,a].filter(Boolean).join(`:`)||`unknown`,o=t.getBoundingClientRect(),c=window.innerWidth,u=window.innerHeight,d=o.width>0&&o.height>0,f=r?r.getBoundingClientRect():null,p=(e,t)=>console.error(`[anchored-popover] op=offscreen id=${i} left=${e} top=${t} w=${o.width} h=${o.height} viewport=${c},${u}`);if(!f){l({position:`fixed`,left:Math.max(4,c-o.width-dt(c)),top:Math.max(4,u-o.height-14),visibility:`visible`});return}if(d&&K(f)){l(ft),p(f.left,f.top);return}let m=f.right-o.width,h=c-o.width-4;m>h&&(m=h),m<4&&(m=4);let g=u-f.bottom-4,_=f.top-4,v=o.height+8<=g?!1:o.height+8<=_?!0:_>g,y=Math.max(0,v?_:g),b=v?Math.max(4,f.top-Math.min(o.height,y)):f.bottom;l({position:`fixed`,left:m,top:b,maxHeight:y,visibility:`visible`});let x=Math.min(o.height,y);d&&(m+o.width<=0||m>=c||b+x<=0||b>=u)&&p(m,b)},[e,a,n]);return(0,F.useLayoutEffect)(()=>{if(u(),typeof ResizeObserver>`u`)return;let e=new ResizeObserver(()=>u());return s.current&&e.observe(s.current),()=>e.disconnect()},[u]),(0,F.useEffect)(()=>{let n=e=>{e.key===`Escape`&&t()},r=n=>{let r=n.target;e.current?.contains(r)||s.current?.contains(r)||t()},i=n=>{let r=e.current;r&&n.target instanceof Node&&n.target.contains(r)&&t()},a=()=>t();return document.addEventListener(`keydown`,n),document.addEventListener(`pointerdown`,r),window.addEventListener(`scroll`,i,!0),window.addEventListener(`resize`,a),()=>{document.removeEventListener(`keydown`,n),document.removeEventListener(`pointerdown`,r),window.removeEventListener(`scroll`,i,!0),window.removeEventListener(`resize`,a)}},[e,t]),(0,ut.createPortal)((0,P.jsx)(`div`,{ref:s,className:n,role:r,"aria-label":i,style:c,children:o}),document.body)}function pt({actions:e,disabled:t,label:n=`Session actions`}){let[r,i]=(0,F.useState)(!1),[a,o]=(0,F.useState)(null),s=(0,F.useRef)(null),c=(0,F.useCallback)(()=>{i(!1),o(null)},[]);return(0,P.jsxs)(`div`,{className:`conv-actions`,children:[(0,P.jsx)(`button`,{ref:s,type:`button`,className:`conv-action conv-actions-overflow`,onClick:()=>i(e=>!e),disabled:t,"aria-haspopup":`menu`,"aria-expanded":r,"aria-label":n,title:n,children:(0,P.jsx)(x,{size:12})}),r&&(0,P.jsx)(q,{anchorRef:s,onClose:c,className:`conv-actions-menu`,role:`menu`,children:e.map(e=>e.panel?(0,P.jsxs)(`div`,{className:`conv-actions-menu-disclosure`,children:[(0,P.jsxs)(`button`,{type:`button`,role:`menuitem`,"aria-haspopup":`dialog`,"aria-expanded":a===e.key,title:e.title,disabled:t||e.disabled,onClick:()=>o(t=>t===e.key?null:e.key),children:[e.icon,(0,P.jsx)(`span`,{children:e.menuLabel})]}),a===e.key&&(0,P.jsx)(`div`,{className:`conv-actions-menu-panel`,children:e.panel()})]},e.key):(0,P.jsxs)(`button`,{type:`button`,role:`menuitem`,className:e.danger?`conv-action-danger`:void 0,"aria-busy":e.busy,title:e.title,disabled:t||e.disabled,onClick:t=>{e.onClick?.(t),c()},children:[e.icon,(0,P.jsx)(`span`,{children:e.menuLabel})]},e.key))})]})}var J=`claude-opus-5[1m]`,mt=`claude-sonnet-5`,ht=`claude-haiku-4-5`,gt={[J]:`Opus 5 (1M context)`,[mt]:`Sonnet 5`,[ht]:`Haiku 4.5`};function _t(e){return gt[e]??e}var vt=[J,mt,ht];function yt(e){return e.replace(/\[1m\]$/,``)}function bt(e){return vt.find(t=>yt(t)===yt(e))??e}var xt=[`default`,`acceptEdits`,`plan`,`auto`,`bypassPermissions`],St=[`low`,`medium`,`high`,`xhigh`];[...xt],[...St],[...St];var Ct=[J,mt,ht],wt={default:`Ask permissions`,acceptEdits:`Accept edits`,plan:`Plan mode`,auto:`Auto mode`,bypassPermissions:`Bypass permissions`},Tt=xt.map(e=>({value:e,label:wt[e]??e})),Et={low:`Low`,medium:`Medium`,high:`High`,xhigh:`Highest`},Dt=St.map(e=>({value:e,label:Et[e]??e}));function Ot(e){if(e){let t=Ct.find(t=>yt(t)===yt(e));if(t)return t}return J}function kt({row:e,adminFetch:t,onError:n}){let[r,i]=(0,F.useState)(()=>Ot(e.model)),[a,o]=(0,F.useState)(``),[s,c]=(0,F.useState)(``),[l,u]=(0,F.useState)(!1),d=(0,F.useRef)(!1);(0,F.useEffect)(()=>{i(Ot(e.model))},[e.model]);let p=async()=>{if(!d.current){d.current=!0,u(!0);try{let i=await t(`/api/admin/session-reseat`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({fromSessionId:e.sessionId,model:r,...a?{permissionMode:a}:{},...s?{effort:s}:{}})});if(!i.ok){n(`Could not reset ${e.title} (status ${i.status})`),console.error(`[admin-ui] dashboard-reseat-failed sessionId=${e.sessionId} status=${i.status}`),d.current=!1,u(!1);return}let o=await i.json().catch(()=>({}));o.target?window.location.assign(o.target):(n(`Reset of ${e.title} returned no target`),d.current=!1,u(!1))}catch(t){n(`Could not reset ${e.title} (network error)`),console.error(`[admin-ui] dashboard-reseat-failed sessionId=${e.sessionId} error=${t instanceof Error?t.message:String(t)}`),d.current=!1,u(!1)}}};return(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`label`,{className:`reseat-field`,children:[(0,P.jsx)(`span`,{children:`Model`}),(0,P.jsx)(`select`,{"data-kind":`model`,value:r,disabled:l,onChange:e=>i(e.target.value),children:Ct.map(e=>(0,P.jsx)(`option`,{value:e,children:_t(e)},e))})]}),(0,P.jsxs)(`label`,{className:`reseat-field`,children:[(0,P.jsx)(`span`,{children:`Mode`}),(0,P.jsxs)(`select`,{"data-kind":`mode`,value:a,disabled:l,onChange:e=>o(e.target.value),children:[(0,P.jsx)(`option`,{value:``,children:`Keep current`}),Tt.map(e=>(0,P.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,P.jsxs)(`label`,{className:`reseat-field`,children:[(0,P.jsx)(`span`,{children:`Effort`}),(0,P.jsxs)(`select`,{"data-kind":`effort`,value:s,disabled:l,onChange:e=>c(e.target.value),children:[(0,P.jsx)(`option`,{value:``,children:`Keep current`}),Dt.map(e=>(0,P.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,P.jsx)(`button`,{type:`button`,className:`reseat-apply`,disabled:l,"aria-busy":l,onClick:()=>void p(),children:l?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(f,{size:12,className:`spin`,"aria-hidden":`true`}),`Resetting…`]}):`Reset`})]})}function At(e){if(e<60)return`${e}s`;let t=Math.floor(e/60),n=e%60;return n>0?`${t}m ${n}s`:`${t}m`}function jt(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Mt({target:e,anchorEl:t,onConfirm:n,onCancel:r}){let i=(0,F.useRef)(null);return i.current=t,e?(0,P.jsxs)(q,{anchorRef:i,onClose:r,className:`conv-delete-confirm`,role:`alertdialog`,ariaLabel:`Confirm delete session`,children:[(0,P.jsxs)(`div`,{className:`claude-info-header`,children:[(0,P.jsx)(`span`,{children:`Delete this conversation?`}),(0,P.jsx)(`button`,{className:`claude-info-close`,onClick:r,"aria-label":`Close`,children:`✕`})]}),(0,P.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[(0,P.jsxs)(`div`,{className:`conv-delete-target`,children:[(0,P.jsx)(`span`,{className:`conv-delete-label`,title:e.title,children:e.title||`Untitled session`}),(0,P.jsx)(`code`,{className:`conv-delete-id`,title:e.sessionId,children:e.sessionId.slice(0,8)})]}),(0,P.jsx)(`div`,{style:{marginTop:`8px`},children:`This permanently removes the transcript. It is not moved to Archive and cannot be recovered.`}),e.live&&(0,P.jsx)(`div`,{style:{marginTop:`8px`},children:`This session is running; deleting stops it first.`})]}),(0,P.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,P.jsx)(L,{variant:`danger`,size:`sm`,style:{flex:1},onClick:n,children:`Delete`}),(0,P.jsx)(L,{variant:`secondary`,size:`sm`,style:{flex:1},onClick:r,children:`Cancel`})]})]}):null}function Nt({target:e,anchorEl:t,onConfirm:n,onCancel:r}){let i=(0,F.useRef)(null);return i.current=t,e?(0,P.jsxs)(q,{anchorRef:i,onClose:r,className:`conv-delete-confirm`,role:`alertdialog`,ariaLabel:`Confirm delete task`,children:[(0,P.jsxs)(`div`,{className:`claude-info-header`,children:[(0,P.jsx)(`span`,{children:`Delete this task?`}),(0,P.jsx)(`button`,{className:`claude-info-close`,onClick:r,"aria-label":`Close`,children:`✕`})]}),(0,P.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[(0,P.jsxs)(`div`,{className:`conv-delete-target`,children:[(0,P.jsx)(`span`,{className:`conv-delete-label`,title:e.name,children:e.name}),(0,P.jsx)(`code`,{className:`conv-delete-id`,children:C(e.secondsLogged)})]}),(0,P.jsx)(`div`,{style:{marginTop:`8px`},children:`This permanently removes the task and every time record on it. It cannot be recovered.`})]}),(0,P.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,P.jsx)(L,{variant:`danger`,size:`sm`,style:{flex:1},onClick:n,children:`Delete`}),(0,P.jsx)(L,{variant:`secondary`,size:`sm`,style:{flex:1},onClick:r,children:`Cancel`})]})]}):null}function Pt({open:e,count:t,liveCount:n,onConfirm:r,onCancel:i}){if(!e)return null;let a=t===1?``:`s`;return(0,P.jsx)(`div`,{className:`claude-info-overlay`,onClick:i,children:(0,P.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Confirm delete sessions`,children:[(0,P.jsxs)(`div`,{className:`claude-info-header`,children:[(0,P.jsxs)(`span`,{children:[`Delete `,t,` conversation`,a,`?`]}),(0,P.jsx)(`button`,{className:`claude-info-close`,onClick:i,"aria-label":`Close`,children:`✕`})]}),(0,P.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[`This permanently removes `,t,` transcript`,a,`. `,t===1?`It is`:`They are`,` not moved to Archive and cannot be recovered.`,n>0&&(0,P.jsxs)(`div`,{style:{marginTop:`8px`},children:[n,` `,n===1?`is`:`are`,` running and will be stopped first.`]})]}),(0,P.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,P.jsxs)(L,{variant:`danger`,size:`sm`,style:{flex:1},onClick:r,children:[`Delete `,t]}),(0,P.jsx)(L,{variant:`secondary`,size:`sm`,style:{flex:1},onClick:i,children:`Cancel`})]})]})})}function Ft(e,t){return`New session: ${v(e.toISOString(),t)}`}function It({open:e,pending:t,onConfirm:n,onCancel:r,now:i}){let{zone:a}=o(),[s,c]=(0,F.useState)(``),l=(0,F.useRef)(null),u=(0,F.useRef)(null),d=(0,F.useRef)(!1);if((0,F.useEffect)(()=>{if(!e){u.current=null,d.current=!1;return}if(u.current!==null)return;let t=Ft(i?i():new Date,a);u.current=t,c(t)},[e,i]),(0,F.useEffect)(()=>{if(!e||d.current||u.current===null||s!==u.current)return;let t=l.current;t&&(d.current=!0,t.focus(),t.setSelectionRange(0,t.value.length))},[e,s]),!e)return null;let f=s.trim(),p=f.length>0&&f.length<=200,m=()=>{p&&!t&&n(f)},h=e=>{t||r(e)};return(0,P.jsx)(`div`,{className:`claude-info-overlay`,onClick:()=>h(`backdrop`),children:(0,P.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`dialog`,"aria-label":`Name this session`,children:[(0,P.jsxs)(`div`,{className:`claude-info-header`,children:[(0,P.jsx)(`span`,{children:`Name this session`}),(0,P.jsx)(`button`,{className:`claude-info-close`,onClick:()=>h(`cancel`),"aria-label":`Close`,disabled:t,children:`✕`})]}),(0,P.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`},children:[(0,P.jsx)(`input`,{ref:l,className:`new-session-name-input`,"aria-label":`Session name`,value:s,disabled:t,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),m()),e.key===`Escape`&&(e.preventDefault(),h(`escape`))}}),(0,P.jsx)(`div`,{className:`new-session-name-hint`,children:f.length>200?`Too long by ${f.length-200}`:`You can rename it later from the session menu.`})]}),(0,P.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,P.jsx)(L,{variant:`primary`,size:`sm`,style:{flex:1},disabled:!p||t,onClick:m,children:t?`Starting…`:`Start session`}),(0,P.jsx)(L,{variant:`secondary`,size:`sm`,style:{flex:1},disabled:t,onClick:()=>h(`cancel`),children:`Cancel`})]})]})})}var Lt=`auth-refresh-failed`;function Rt({error:e,onClose:t}){if(!e)return null;let n=e.reason===Lt,r=n?`Claude sign-in expired`:`Session didn’t open`,i=n?`Your claude.ai login has expired. Re-authenticate to resume sessions.`:`The session did not bind within 60 seconds, so there is no live conversation to open.`;return(0,P.jsx)(`div`,{className:`claude-info-overlay`,onClick:t,children:(0,P.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Session could not be opened`,children:[(0,P.jsxs)(`div`,{className:`claude-info-header`,children:[(0,P.jsx)(`span`,{children:r}),(0,P.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:`✕`})]}),(0,P.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[i,(0,P.jsxs)(`div`,{className:`claude-info-row`,style:{marginTop:`8px`},children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Reason`}),(0,P.jsx)(`span`,{className:`claude-info-value`,children:e.reason})]}),e.sessionId&&(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,P.jsxs)(`span`,{className:`claude-info-value`,children:[e.sessionId.slice(0,8),`…`]})]})]})]})})}function zt(e){let{show:t,onClose:n,claudeInfo:r,messages:i,sessionElapsed:a,sessionId:o,cacheKey:s}=e,[c,l]=(0,F.useState)(null);if(!t)return null;let u=i.flatMap(e=>e.events?.filter(e=>e.type===`usage`)??[]),d=u.at(-1),f=d?.peak_request_pct==null?d?.context_window?Math.round((d.input_tokens+d.cache_creation_tokens+d.cache_read_tokens)/d.context_window*100):0:Math.round(d.peak_request_pct*100),p=u.reduce((e,t)=>e+t.input_tokens+t.cache_creation_tokens+t.cache_read_tokens+t.output_tokens,0),m=i.flatMap(e=>e.events?.filter(e=>e.type===`rate_limit`)??[]).at(-1),h=u.reduce((e,t)=>e+(t.total_cost_usd??0),0),g=r?.account?.subscriptionType,_=e=>{let t=e*1e3-Date.now();if(t<=0)return`now`;let n=Math.floor(t/36e5),r=Math.floor(t%36e5/6e4);return n>0?`${n}h ${r}m`:`${r}m`};return(0,P.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,P.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,P.jsxs)(`div`,{className:`claude-info-header`,children:[(0,P.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`claude-info-icon`}),(0,P.jsx)(`span`,{children:`Claude Code`}),(0,P.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,P.jsxs)(`div`,{className:`claude-info-section`,children:[(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Version`}),(0,P.jsx)(`span`,{className:`claude-info-value`,children:r?r.version:`…`})]}),(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Email`}),(0,P.jsx)(`span`,{className:`claude-info-value`,children:r?.account?.email??`…`})]})]}),(g||m||h>0)&&(0,P.jsxs)(`div`,{className:`claude-info-section`,children:[g&&(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Plan`}),(0,P.jsx)(`span`,{className:`claude-info-value`,style:{textTransform:`capitalize`},children:g})]}),m&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Usage`}),(0,P.jsxs)(`span`,{className:`claude-info-value`,children:[Math.round(m.utilization*100),`%`]})]}),(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Resets in`}),(0,P.jsx)(`span`,{className:`claude-info-value`,children:_(m.resetsAt)})]}),m.isUsingOverage&&(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Overage`}),(0,P.jsx)(`span`,{className:`claude-info-value`,children:`Active`})]})]}),h>0&&(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Session cost`}),(0,P.jsxs)(`span`,{className:`claude-info-value`,children:[`$`,h<.01?h.toFixed(4):h.toFixed(2)]})]})]}),(0,P.jsxs)(`div`,{className:`claude-info-section`,children:[(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Model`}),(0,P.jsx)(`span`,{className:`claude-info-value`,children:r?.model??`…`})]}),(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Context used`}),(0,P.jsx)(`span`,{className:`claude-info-value`,children:f>0?`${f}%`:`—`})]}),(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Tokens`}),(0,P.jsx)(`span`,{className:`claude-info-value`,children:p>0?jt(p):`—`})]}),(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,P.jsx)(`span`,{className:`claude-info-value`,children:At(a)})]}),(o||s)&&(()=>{let e=o??s??``;return(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,P.jsx)(`button`,{type:`button`,className:`claude-info-value claude-info-id-copy`,title:`${e} (${o?`flushed`:`pre-flush`}) — click to copy`,onClick:async()=>{l(await M(e)?`copied`:`failed`),setTimeout(()=>l(null),1200)},children:c===`copied`?`copied ✓`:c===`failed`?`copy failed ✕`:`${e.slice(0,8)}…`})]})})()]})]})})}function Bt({open:e,installed:t,latest:n,initialActionId:r,onClose:i}){let[a,o]=(0,F.useState)(r),[s,c]=(0,F.useState)(``),[l,u]=(0,F.useState)(!1),[d,f]=(0,F.useState)(!1),[p,m]=(0,F.useState)(null),[h,g]=(0,F.useState)(null),_=(0,F.useRef)(null);(0,F.useEffect)(()=>{o(r)},[r]),(0,F.useEffect)(()=>{if(!e||!a)return;let t=new EventSource(`/api/admin/actions/${a}/stream`);return t.onmessage=e=>{f(!1),c(t=>t+e.data+`
2
2
  `)},t.addEventListener(`done`,e=>{m(JSON.parse(e.data)),t.close()}),t.onerror=()=>{f(!0)},()=>{t.close()}},[e,a]),(0,F.useEffect)(()=>{let e=_.current;e&&(e.scrollTop=e.scrollHeight)},[s]);let v=(0,F.useCallback)(async()=>{u(!0),g(null);try{let e=await fetch(`/api/admin/actions/upgrade`,{method:`POST`}),t=await e.json().catch(()=>({}));if(!e.ok){g(t?.reason===`systemd-run-absent`?`This host has no systemd, so the installer cannot be started from here.`:`Could not start the update (HTTP ${e.status}).`);return}o(t.actionId)}catch(e){console.error(`[admin-ui] update-start failed:`,e),g(e instanceof Error?e.message:String(e))}finally{u(!1)}},[]);return e?(0,P.jsx)(`div`,{className:`claude-info-overlay`,onClick:i,children:(0,P.jsxs)(`div`,{className:`claude-info-modal update-modal`,onClick:e=>e.stopPropagation(),role:`dialog`,"aria-label":`Software update`,children:[(0,P.jsxs)(`div`,{className:`claude-info-header`,children:[(0,P.jsx)(`span`,{children:`Software update`}),(0,P.jsx)(`button`,{className:`claude-info-close`,onClick:i,"aria-label":`Close`,children:`✕`})]}),(0,P.jsxs)(`div`,{className:`update-modal-body`,children:[(0,P.jsxs)(`div`,{className:`update-modal-versions`,children:[(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Installed`}),(0,P.jsx)(`span`,{className:`claude-info-value`,children:t})]}),(0,P.jsxs)(`div`,{className:`claude-info-row`,children:[(0,P.jsx)(`span`,{className:`claude-info-label`,children:`Latest`}),(0,P.jsx)(`span`,{className:`claude-info-value update-version-new`,children:n??`unknown`})]})]}),h&&(0,P.jsx)(`div`,{className:`update-modal-launch-error`,children:h}),!a&&(0,P.jsx)(L,{variant:`primary`,size:`sm`,className:`update-modal-btn`,disabled:l,onClick:()=>{v()},children:l?`Starting…`:`Update`}),a&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`pre`,{className:`update-modal-output`,ref:_,children:s}),d&&!p&&(0,P.jsx)(`div`,{className:`update-modal-reconnecting`,children:`Reconnecting. The update restarts the server, so this gap is expected and the install keeps running.`}),p&&(0,P.jsx)(`div`,{className:`update-modal-result`,children:p.code===0&&p.changed?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`span`,{className:`update-success-icon`,children:`✓`}),` Updated to `,p.versionAfter,`.`]}):p.code===0?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`span`,{className:`update-error-icon`,children:`!`}),` The installer finished but the version is still `,p.versionAfter,`.`]}):(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`span`,{className:`update-error-icon`,children:`!`}),` The installer exited with code `,p.code,`.`]})})]})]})]})}):null}function Vt({open:e,onConnect:t,onClose:n}){return e?(0,P.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,P.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Claude is not connected`,children:[(0,P.jsxs)(`div`,{className:`claude-info-header`,children:[(0,P.jsx)(`span`,{children:`Claude isn’t connected`}),(0,P.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,P.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`,display:`flex`,flexDirection:`column`,gap:`10px`},children:[(0,P.jsx)(`span`,{children:`This needs Claude, which is currently disconnected. Connect to continue — the rest of the dashboard stays available either way.`}),(0,P.jsxs)(`div`,{style:{display:`flex`,gap:`8px`,alignItems:`center`},children:[(0,P.jsx)(L,{variant:`primary`,size:`sm`,onClick:t,children:`Connect Claude`}),(0,P.jsx)(`button`,{type:`button`,className:`claude-info-close`,style:{fontSize:`11px`},onClick:n,children:`Not now`})]})]})]})}):null}function Ht(e){let t=Math.round(e/6e4),n=Math.floor(t/60),r=t%60;return`${n}h ${String(r).padStart(2,`0`)}m`}function Ut(e){return e.activeMs.thinking+e.activeMs.messaging+e.activeMs.toolUse}function Y(e){return e.toLocaleString(`en-GB`)}function X(e){return`£${e.toFixed(2)}`}function Wt(e){let t=[`Day`,`Active`,`Output tokens`,`Input tokens`,`Cache write`,`Cache read`,`Opus 5 (GBP)`,`Sonnet 5 (GBP)`],n=(e,t)=>[e,Ht(Ut(t)),String(t.tokens.output),String(t.tokens.input),String(t.tokens.cacheWrite),String(t.tokens.cacheRead),t.costGBP.opus.toFixed(2),t.costGBP.sonnet.toFixed(2)];return[t,...e.days.map(e=>n(e.date,e)),n(`TOTAL (${e.days.length} d)`,e.totals)].map(e=>e.join(`,`)).join(`
3
3
  `)}function Gt({label:e,d:t,bold:n}){let r=n?`th`:`td`;return(0,P.jsxs)(`tr`,{className:n?`usage-total-row`:void 0,children:[(0,P.jsx)(r,{className:`usage-day`,children:e}),(0,P.jsx)(r,{children:Ht(Ut(t))}),(0,P.jsx)(r,{children:Y(t.tokens.output)}),(0,P.jsx)(r,{children:Y(t.tokens.input)}),(0,P.jsx)(r,{children:Y(t.tokens.cacheWrite)}),(0,P.jsx)(r,{children:Y(t.tokens.cacheRead)}),(0,P.jsx)(r,{children:X(t.costGBP.opus)}),(0,P.jsx)(r,{children:X(t.costGBP.sonnet)})]})}function Kt({show:e,onClose:t,anchorEl:n,sessionId:r,summary:i,loading:a,error:o}){let s=(0,F.useRef)(null);if(s.current=n,!e)return null;let c=!!i&&i.days.length>0;return(0,P.jsxs)(q,{anchorRef:s,onClose:t,className:`usage-popover`,role:`dialog`,ariaLabel:`Session usage and cost`,anchorId:r??void 0,children:[(0,P.jsxs)(`div`,{className:`claude-info-header`,children:[(0,P.jsxs)(`span`,{children:[`Usage & cost`,r?` · ${r.slice(0,8)}`:``]}),c&&(0,P.jsx)(`button`,{className:`usage-download`,onClick:()=>{if(!i)return;let e=new Blob([Wt(i)],{type:`text/csv;charset=utf-8`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`usage-${r?r.slice(0,8):`session`}.csv`,document.body.appendChild(n),n.click(),n.remove(),URL.revokeObjectURL(t)},"aria-label":`Download as CSV`,title:`Download as CSV`,children:(0,P.jsx)(ee,{size:14})}),(0,P.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:(0,P.jsx)(u,{size:14})})]}),(0,P.jsxs)(`div`,{className:`claude-info-section usage-body`,children:[a&&(0,P.jsx)(`div`,{className:`usage-note`,children:`Computing usage…`}),!a&&o&&(0,P.jsx)(`div`,{className:`usage-note usage-error`,children:o}),!a&&!o&&i&&i.days.length===0&&(0,P.jsx)(`div`,{className:`usage-note`,children:`No usage recorded for this session yet.`}),!a&&!o&&i&&i.days.length>0&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`div`,{className:`usage-table-scroll`,children:(0,P.jsxs)(`table`,{className:`usage-table`,children:[(0,P.jsx)(`thead`,{children:(0,P.jsxs)(`tr`,{children:[(0,P.jsx)(`th`,{className:`usage-day`,children:`Day`}),(0,P.jsx)(`th`,{children:`Active`}),(0,P.jsx)(`th`,{children:`Output tok`}),(0,P.jsx)(`th`,{children:`Input tok`}),(0,P.jsx)(`th`,{children:`Cache write`}),(0,P.jsx)(`th`,{children:`Cache read`}),(0,P.jsx)(`th`,{children:`Opus 5 (£)`}),(0,P.jsx)(`th`,{children:`Sonnet 5 (£)`})]})}),(0,P.jsxs)(`tbody`,{children:[i.days.map(e=>(0,P.jsx)(Gt,{label:e.date,d:e},e.date)),(0,P.jsx)(Gt,{label:`TOTAL (${i.days.length} d)`,d:i.totals,bold:!0})]})]})}),(0,P.jsxs)(`div`,{className:`usage-note usage-caveats`,children:[`Prices dated `,i.pricing.opusPriceDate,` · £/$ `,i.pricing.usdPerGbp,` · Sonnet tokenizer factor `,i.pricing.tokenizerFactor,`. Idle human-wait dominates the calendar span; cache-read tokens dominate cost.`]})]})]})]})}var qt=`https://claude.ai/code`,Jt=200,Yt=[500,1e3,1500,2e3,2500,3e3,3e3];function Xt(e,t,n){if(e&&n.target)return{kind:`navigate`,url:n.target,sameOrigin:!0};let r=n.slug??n.bridgeSessionId??null;if(e&&r)return{kind:`navigate`,url:`${qt}/${r}`,sameOrigin:!1};let i=n.reason||n.error||`status ${t}`;return{kind:`error`,sessionId:n.sessionId??null,reason:i}}var Zt=`maxy:sidebar:nav-collapsed`;function Qt(e,t){return v(e,t)}function $t(e){let{zone:t}=o(),{businessName:n,cacheKey:r,onConnectClaude:i,role:c,userName:u,userAvatar:d,onSelectProjects:h,onSelectTasks:v,onCloseMobileDrawer:x,collapsed:re,onSelectData:ie,initialDataSurface:ae=!1,onLogout:C,onDisconnect:oe,disconnecting:A,claudeConnected:le=!0,subAccounts:j,activeAccountId:M,switchingAccount:ue,onSwitchAccount:N,refreshAccounts:I,onOpenConversations:pe}=e,L=s(r),R=(0,F.useCallback)(e=>({key:`reseat`,label:`Reset session ${e.title} (model, mode, effort)`,menuLabel:`Reset`,title:`Reset — move this session onto a chosen model, mode, and effort`,icon:(0,P.jsx)(Te,{size:12}),panel:()=>(0,P.jsx)(kt,{row:e,adminFetch:L,onError:e=>V({message:e,failed:!0})})}),[L]),Ce=T.productName,z=n||Ce,we=typeof u==`string`?u:u===null?`name unavailable`:z,ke=(we.trim().charAt(0)||`?`).toUpperCase(),[Ae,je]=(0,F.useState)(ae?`data`:`sessions`),[Me,Ne]=(0,F.useState)(!1),[B,Pe]=(0,F.useState)(null),[Fe,Ie]=(0,F.useState)(!1),[Le,Re]=(0,F.useState)(null);(0,F.useEffect)(()=>{let e=!1;return L(`/api/admin/version`).then(e=>e.json()).then(t=>{e||Pe(t)}).catch(e=>console.error(`[admin-ui] sidebar-version fetch failed:`,e)),L(`/api/admin/actions/latest`).then(e=>e.json()).then(t=>{e||Re(t?.action?.running?t.action.actionId:null)}).catch(e=>console.error(`[admin-ui] sidebar-latest-action fetch failed:`,e)),()=>{e=!0}},[L]);let[ze,Be]=(0,F.useState)(!1),Ve=!re&&(j?.length??0)>1&&!!N,He=j?.find(e=>e.isHouse)??null,Ue=(0,F.useCallback)(()=>{He&&He.accountId!==M&&(Be(!1),N?.(He.accountId,`/`))},[He,M,N]),[We,V]=(0,F.useState)(null),[Ge,H]=(0,F.useState)(null),[Ke,qe]=(0,F.useState)(!1),[U,Je]=(0,F.useState)([]),[W]=(0,F.useState)(()=>typeof window>`u`?null:new URLSearchParams(window.location.search).get(`session`)),[Ye,Xe]=(0,F.useState)(!1),[Ze,Qe]=(0,F.useState)(null),[$e,et]=(0,F.useState)(!1),[tt,nt]=(0,F.useState)(!1),[rt,it]=(0,F.useState)(!1),[G,at]=(0,F.useState)(!1);(0,F.useEffect)(()=>{let e=null;try{e=window.localStorage.getItem(Zt)}catch{e=null}at(e===`1`)},[]);let ot=(0,F.useCallback)(()=>{let e=!G;try{window.localStorage.setItem(Zt,e?`1`:`0`)}catch(e){console.warn(`[admin-ui] sidebar-nav-collapse op=persist-failed error=${e instanceof Error?e.message:String(e)}`)}at(e)},[G]),[st,ct]=(0,F.useState)(null),[lt,ut]=(0,F.useState)(new Set),dt=(0,F.useRef)(new Map),[K,ft]=(0,F.useState)(!1),[q,J]=(0,F.useState)(new Set),[mt,ht]=(0,F.useState)(!1),[gt,_t]=(0,F.useState)(null),[vt,yt]=(0,F.useState)(new Set),[bt,xt]=(0,F.useState)(new Set),[St,Ct]=(0,F.useState)(new Set),[wt,Tt]=(0,F.useState)(null),[Et,Dt]=(0,F.useState)(``),[Ot,At]=(0,F.useState)(!1),[jt,Nt]=(0,F.useState)(null),[Ft,Lt]=(0,F.useState)(null),[zt,Ht]=(0,F.useState)(!1),[Ut,Y]=(0,F.useState)(null),[X,Wt]=(0,F.useState)(!1),[Gt,qt]=(0,F.useState)(!1),$t=(0,F.useRef)(0);(0,F.useEffect)(()=>{if(!We)return;let e=setTimeout(()=>V(null),2500);return()=>clearTimeout(e)},[We]);let Z=(0,F.useCallback)(async()=>{if(!r)return null;let e=++$t.current;et(!0),Qe(null);try{let t=await L(`/api/admin/sidebar-sessions`);if(!t.ok)throw Error(`status ${t.status}`);let n=await t.json(),r=n.sessions??[];return e===$t.current?(Je(r),ct(n.accountId??null),Xe(!0),r):r}catch(t){let n=t instanceof Error?t.message:String(t);return e===$t.current&&Qe(`Failed to load sessions: ${n}`),console.error(`[admin-ui] sidebar-sessions fetch failed: ${n}`),null}finally{e===$t.current&&et(!1)}},[r,L]);(0,F.useEffect)(()=>{!r||Ye||Z()},[r,Ye,Z]),(0,F.useEffect)(()=>{if(!r)return;let e=null;function t(){Z()}function n(){e===null&&(e=setInterval(t,en))}function i(){e!==null&&(clearInterval(e),e=null)}function a(){document.hidden?i():(t(),n())}return document.hidden||n(),document.addEventListener(`visibilitychange`,a),()=>{i(),document.removeEventListener(`visibilitychange`,a)}},[r,Z]);let nn=()=>{Z()},rn=()=>{je(`data`),ie(),x()},Q=typeof window<`u`&&window.location?.pathname||`/`,an=Ae===`data`,on=typeof window<`u`&&window.location?.search||``,sn=new URLSearchParams(on),cn=sn.has(`label`)&&!sn.has(`nodeId`),$=e=>{x(),window.location.href=e},ln=[{key:`dashboard`,label:`Dashboard`,icon:(0,P.jsx)(k,{size:17,strokeWidth:1.75}),active:Q===`/`&&!an,onClick:()=>$(`/`)},{key:`chat`,label:`Chat`,icon:(0,P.jsx)(y,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/chat`),onClick:()=>$(`/chat`)},{key:`tasks`,label:`Tasks`,icon:(0,P.jsx)(xe,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/tasks`),onClick:()=>{v(),x()}},{key:`calendar`,label:`Calendar`,icon:(0,P.jsx)(w,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/calendar`),onClick:()=>$(`/calendar`)},{key:`routines`,label:`Routines`,icon:(0,P.jsx)(Oe,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/routines`),onClick:()=>$(`/routines`)},{key:`skills`,label:`Skills`,icon:(0,P.jsx)(Ee,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/skills`),onClick:()=>$(`/skills`)},{key:`agents`,label:`Agents`,icon:(0,P.jsx)(ge,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/agents`),onClick:()=>$(`/agents`)},{key:`data`,label:`Data`,icon:(0,P.jsx)(S,{size:17,strokeWidth:1.75}),active:an,onClick:rn},{key:`container`,label:ce().term,icon:(0,P.jsx)(te,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/graph`)&&cn,onClick:()=>{h(),x()}},{key:`graph`,label:`Graph`,icon:(0,P.jsx)(De,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/graph`)&&!cn,onClick:()=>$(`/graph`)},{key:`activity`,label:`Activity`,icon:(0,P.jsx)(se,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/activity`),onClick:()=>$(`/activity`)}],un=(0,F.useCallback)(async e=>{if(vt.has(e.sessionId))return;yt(t=>{let n=new Set(t);return n.add(e.sessionId),n});let t=window.open(``,`_blank`);try{let n=await L(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e.sessionId,name:e.title||e.sessionId,...e.accountId?{targetAccountId:e.accountId}:{}})}),r=await n.json().catch(()=>({})),i=Xt(n.ok,n.status,{...r,sessionId:r.sessionId??e.sessionId});i.kind===`navigate`?(x(),t?t.location.href=i.url:window.open(i.url,`_blank`)):(t?.close(),console.error(`[admin-ui] sidebar-session-resume-failed sessionId=${e.sessionId} status=${n.status} reason=${i.reason}`),H(i))}catch(n){t?.close();let r=n instanceof Error?n.message:String(n);console.error(`[admin-ui] sidebar-session-resume-failed sessionId=${e.sessionId} error=${r}`),H({sessionId:e.sessionId,reason:r})}finally{yt(t=>{let n=new Set(t);return n.delete(e.sessionId),n})}},[L,x,vt]),dn=(0,F.useCallback)(async e=>{let t=e.slice(0,8);for(let t=1;t<=Yt.length;t++){await new Promise(e=>setTimeout(e,Yt[t-1]));let n=await Z();if(n&&n.some(t=>t.sessionId===e))return}console.error(`[admin-ui] sidebar-new-session-converge-timeout sessionId=${t}`)},[Z]),fn=(0,F.useCallback)(async e=>{if(!X){Wt(!0);try{let t=await L(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({title:e})}),n=await t.json().catch(()=>({})),r=Xt(t.ok,t.status,n);r.kind===`navigate`?r.sameOrigin?window.location.assign(r.url):(window.open(r.url,`_blank`),n.sessionId?dn(n.sessionId):console.error(`[admin-ui] sidebar-new-session-converge-skipped reason=no-session-id`)):t.status===503||r.reason===`claude-auth-dead`?(qt(!1),qe(!0)):(console.error(`[admin-ui] sidebar-new-session-failed status=${t.status} reason=${r.reason}`),qt(!1),H(r))}catch(e){let t=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-new-session-failed error=${t}`),qt(!1),H({sessionId:null,reason:t})}finally{Wt(!1)}}},[L,X,dn]),pn=(0,F.useCallback)((e,t)=>{e.stopPropagation(),_t(t)},[]),mn=(0,F.useCallback)(async(e,t)=>{e.stopPropagation(),Nt(t),Lt(null),Y(null),Ht(!0);try{let e=await L(`/api/admin/session-usage?sessionId=${encodeURIComponent(t.sessionId)}`),n=await e.json().catch(()=>({}));e.ok?Lt(n):Y(n.error??`status ${e.status}`)}catch(e){Y(e instanceof Error?e.message:String(e))}finally{Ht(!1)}},[L]),hn=(0,F.useCallback)(async(e,t={})=>{let n=t.refresh??!0;if(lt.has(e.sessionId))return!1;ut(t=>{let n=new Set(t);return n.add(e.sessionId),n});try{let t=await L(`/api/admin/session-delete`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e.sessionId})});if(!t.ok){let n=await t.json().catch(()=>({}));return console.error(`[admin-ui] sidebar-session-delete-failed sessionId=${e.sessionId} status=${t.status} error=${n.error??`unknown`}`),V({message:`Delete failed: ${n.error??`status ${t.status}`}`,failed:!0}),!1}return await t.json(),Je(t=>t.filter(t=>t.sessionId!==e.sessionId)),n&&Z(),!0}catch(t){let n=t instanceof Error?t.message:String(t);return console.error(`[admin-ui] sidebar-session-delete-failed sessionId=${e.sessionId} error=${n}`),V({message:`Delete failed: ${n}`,failed:!0}),!1}finally{ut(t=>{let n=new Set(t);return n.delete(e.sessionId),n})}},[L,lt,Z]),gn=(0,F.useCallback)(e=>{J(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),_n=(0,F.useCallback)(()=>{ft(!1),J(new Set)},[]),vn=(0,F.useCallback)(async()=>{let e=[...q].map(e=>U.find(t=>t.sessionId===e)).filter(e=>!!e),t=(await Promise.all(e.map(e=>hn(e,{refresh:!1})))).filter(Boolean).length,n=e.length-t;n>0&&console.warn(`[admin-ui] sidebar-bulk-delete op=done requested=${e.length} ok=${t} failed=${n}`),Z(),_n()},[q,U,hn,Z,_n]),yn=(0,F.useCallback)(async(e,t)=>{if(e.stopPropagation(),!bt.has(t.sessionId)){xt(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await L(`/api/admin/session-stop`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:t.sessionId})});if(!e.ok){let n=await e.json().catch(()=>({}));console.error(`[admin-ui] sidebar-session-stop-failed sessionId=${t.sessionId} status=${e.status} error=${n.error??`unknown`}`),V({message:`Stop failed: ${n.error??`status ${e.status}`}`,failed:!0});return}Z()}catch(e){let n=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-session-stop-failed sessionId=${t.sessionId} error=${n}`),V({message:`Stop failed: ${n}`,failed:!0})}finally{xt(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[L,bt,Z]),bn=(0,F.useCallback)(async(e,t,n)=>{if(e.stopPropagation(),!St.has(t.sessionId)){Ct(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await L(`/api/admin/session-archive`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:t.sessionId,mode:n})});if(!e.ok){let r=await e.json().catch(()=>({})),i=r.detail??r.error??`status ${e.status}`;console.error(`[admin-ui] sidebar-session-archive-failed sessionId=${t.sessionId} mode=${n} status=${e.status} error=${r.error??`unknown`}`),V({message:`${n===`archive`?`Archive`:`Unarchive`} failed: ${i}`,failed:!0});return}Z()}catch(e){let r=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-session-archive-failed sessionId=${t.sessionId} mode=${n} error=${r}`),V({message:`${n===`archive`?`Archive`:`Unarchive`} failed: ${r}`,failed:!0})}finally{Ct(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[L,St,Z]),xn=(0,F.useCallback)(async e=>{let t=Et.trim();if(!t){V({message:`Title can’t be empty`,failed:!0});return}if(t.length>Jt){V({message:`Title too long (max ${Jt})`,failed:!0});return}At(!0);try{let n=await L(`/api/admin/session-rename`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e.sessionId,title:t})});if(!n.ok){let t=await n.json().catch(()=>({})),r=t.reason??t.error??`status ${n.status}`;console.error(`[admin-ui] sidebar-session-rename sessionId=${e.sessionId.slice(0,8)} outcome=rejected reason=${r}`),V({message:`Rename failed: ${r}`,failed:!0});return}Tt(null),Dt(``),Z()}catch(t){let n=t instanceof Error?t.message:String(t);console.error(`[admin-ui] sidebar-session-rename sessionId=${e.sessionId.slice(0,8)} outcome=rejected reason=${n}`),V({message:`Rename failed: ${n}`,failed:!0})}finally{At(!1)}},[L,Et,Z]);return(0,P.jsxs)(`aside`,{className:`side`,children:[(0,P.jsxs)(`div`,{className:`side-brand`,children:[Ve?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`button`,{type:`button`,className:`side-brand-icon-btn`,"aria-label":`Switch to house account`,disabled:!He,onClick:Ue,children:(0,P.jsx)(`img`,{className:`side-brand-icon`,src:ne,alt:``,"aria-hidden":`true`})}),(0,P.jsxs)(`button`,{type:`button`,className:`side-brand-trigger`,"aria-haspopup":`menu`,"aria-expanded":ze,"aria-label":`Switch sub-account`,onClick:()=>{let e=!ze;Be(e),e&&I?.()},children:[(0,P.jsxs)(`span`,{className:`side-brand-lockup`,children:[(0,P.jsx)(`span`,{className:`side-brand-business`,children:z}),(0,P.jsx)(`span`,{className:`side-brand-product`,children:T.productName}),B&&(0,P.jsxs)(`span`,{className:`side-brand-version`,children:[`v`,B.installed]})]}),(0,P.jsx)(g,{size:14,className:`side-brand-caret`,"aria-hidden":`true`})]})]}):(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`img`,{className:`side-brand-icon`,src:ne,alt:``,"aria-hidden":`true`}),(0,P.jsxs)(`span`,{className:`side-brand-lockup`,children:[(0,P.jsx)(`span`,{className:`side-brand-business`,children:z}),(0,P.jsx)(`span`,{className:`side-brand-product`,children:T.productName}),B&&(0,P.jsxs)(`span`,{className:`side-brand-version`,children:[`v`,B.installed]})]})]}),B?.updateAvailable&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`button`,{type:`button`,className:`side-brand-update`,"aria-label":`Software update available`,title:`Software update available`,onClick:()=>Ie(!0),children:(0,P.jsx)(ee,{size:14})}),(0,P.jsx)(`span`,{className:`side-brand-icon-dot`,"aria-hidden":`true`})]}),ze&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`div`,{className:`side-brand-scrim`,"aria-hidden":`true`,onClick:()=>Be(!1)}),(0,P.jsx)(m,{open:ze,accounts:j??[],activeAccountId:M??null,switching:ue??!1,onSelect:e=>N?.(e),onClose:()=>Be(!1)})]})]}),(0,P.jsxs)(`nav`,{className:`side-nav${G?` side-nav--collapsed`:``}`,children:[(0,P.jsxs)(`div`,{className:`group-head`,children:[(0,P.jsx)(`span`,{children:`Menu`}),(0,P.jsx)(`button`,{type:`button`,className:`side-nav-toggle`,"aria-expanded":!G,"aria-controls":`side-nav-rows`,"aria-label":G?`Expand the menu`:`Collapse the menu`,title:G?`Expand the menu`:`Collapse the menu`,onClick:ot,children:G?(0,P.jsx)(_e,{size:12}):(0,P.jsx)(g,{size:12})})]}),(0,P.jsx)(`div`,{id:`side-nav-rows`,children:ln.map(e=>(0,P.jsxs)(`button`,{type:`button`,className:`admin-row nav-row${e.active?` active`:``}`,"aria-current":e.active?`page`:void 0,onClick:e.onClick,children:[e.icon,(0,P.jsx)(`span`,{className:`label`,children:e.label}),(0,P.jsx)(`span`,{className:`kbd`})]},e.key))})]}),(()=>{let e=U.filter(e=>tt?!0:!e.isSubagent).filter(e=>rt?!0:!e.archived),n=U.some(e=>e.isSubagent),r=U.some(e=>e.archived);return(0,P.jsx)(`div`,{className:`side-sessions`,children:(0,P.jsxs)(`div`,{className:`side-list`,children:[(0,P.jsxs)(`div`,{className:`group-head`,children:[(0,P.jsx)(`span`,{children:`Sessions`}),(0,P.jsxs)(`span`,{className:`group-head-meta`,children:[(0,P.jsx)(`button`,{type:`button`,className:`group-head-select${K?` active`:``}`,"aria-pressed":K,title:K?`Exit select mode`:`Select multiple sessions to delete`,onClick:()=>{ft(e=>!e),J(new Set),Tt(null),Dt(``)},children:`Select`}),(0,P.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh sessions`,"aria-label":`Refresh sessions`,onClick:nn,disabled:$e,children:(0,P.jsx)(a,{size:12,className:$e?`spinning`:void 0})}),(0,P.jsx)(`span`,{children:$e?`…`:String(e.length)}),(0,P.jsxs)(`button`,{type:`button`,className:`admin-btn-cta side-sessions-new`,onClick:()=>{qt(!0)},disabled:X,"aria-busy":X,"aria-label":X?`Spawning session`:`New session`,title:X?`Spawning session`:`New session`,children:[X?(0,P.jsx)(f,{size:13,className:`spinning`}):(0,P.jsx)(b,{size:13}),(0,P.jsx)(`span`,{children:X?`Spawning…`:`New session`})]})]})]}),K&&(0,P.jsxs)(`div`,{className:`session-select-bar`,children:[(0,P.jsxs)(`span`,{className:`session-select-count`,children:[q.size,` selected`]}),(0,P.jsxs)(`button`,{type:`button`,className:`session-select-delete`,disabled:q.size===0,onClick:()=>ht(!0),children:[`Delete `,q.size]}),(0,P.jsx)(`button`,{type:`button`,className:`session-select-cancel`,onClick:_n,children:`Cancel`})]}),st&&(0,P.jsx)(`div`,{className:`side-account-id`,title:`This install's accountId. The first 8 characters match the truncated UUID label on the live Remote Control daemon entry in claude.ai/code.`,children:(0,P.jsx)(`code`,{children:st})}),(n||r)&&(0,P.jsxs)(`div`,{className:`artefact-filter-chips`,children:[n&&(0,P.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${tt?` active`:``}`,"aria-pressed":tt,onClick:()=>nt(e=>!e),title:tt?`Hide subagent sessions`:`Show subagent sessions`,children:`Subagents`}),r&&(0,P.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${rt?` active`:``}`,"aria-pressed":rt,onClick:()=>it(e=>!e),title:rt?`Hide archived sessions`:`Show archived sessions`,children:`Archived`})]}),Ze&&(0,P.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:Ze}),Ye&&!Ze&&e.length===0&&(0,P.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No sessions yet`}),e.map(e=>{let n=Qt(e.startedAt,t),r=vt.has(e.sessionId),i=lt.has(e.sessionId),a=bt.has(e.sessionId),o=St.has(e.sessionId),s=r||i||a||o,c=()=>{window.location.assign(`/chat?session=${e.sessionId}`)},u=[{key:`open`,label:`Resume session ${e.title} in claude.ai/code`,menuLabel:`Resume in claude.ai/code`,title:`Resume in a fresh local Remote Control PTY`,icon:(0,P.jsx)(ye,{size:12}),busy:r,onClick:()=>{un(e)}},{key:`message`,label:`Open session ${e.title} in admin webchat`,menuLabel:`Open in webchat`,title:`Open in admin webchat (/chat) — sending resumes this session`,icon:(0,P.jsx)(Se,{size:12}),onClick:()=>{c()}},{key:`usage`,label:`Usage and cost for session ${e.title}`,menuLabel:`Usage & cost`,title:`Per-day active time, tokens, and estimated GBP cost`,icon:(0,P.jsx)(be,{size:12}),onClick:t=>{mn(t,e)}},...e.live?[{key:`stop`,label:`Stop session ${e.title}`,menuLabel:`Stop`,title:`Stop session process (keeps the conversation, can resume later)`,icon:(0,P.jsx)(_,{size:12}),busy:a,onClick:t=>{yn(t,e)}}]:[],e.archived?{key:`unarchive`,label:`Unarchive session ${e.title}`,menuLabel:`Unarchive`,title:`Unarchive (move back to the active list)`,icon:(0,P.jsx)(me,{size:12}),busy:o,onClick:t=>{bn(t,e,`unarchive`)}}:{key:`archive`,label:`Archive session ${e.title}`,menuLabel:`Archive`,title:`Archive (hide from the list, keeps the conversation resumable)`,icon:(0,P.jsx)(he,{size:12}),busy:o,onClick:t=>{bn(t,e,`archive`)}},{key:`rename`,label:`Rename session ${e.title}`,menuLabel:`Rename`,title:`Rename this session`,icon:(0,P.jsx)(l,{size:12}),busy:Ot&&wt===e.sessionId,onClick:t=>{t.stopPropagation(),Tt(e.sessionId),Dt(e.personName??e.title)}},{key:`delete`,label:`Delete session ${e.title}`,menuLabel:`Delete`,title:`Delete session (stops the process, removes the conversation)`,icon:(0,P.jsx)(p,{size:12}),danger:!0,busy:i,onClick:t=>{pn(t,e)}},R({sessionId:e.sessionId,model:e.model??null,title:e.personName??e.title})],d=e.channel===`whatsapp`?` conv-channel-whatsapp`:e.channel===`telegram`?` conv-channel-telegram`:``,f=e.channel===`whatsapp`||e.channel===`telegram`||e.channel===`webchat`,m=D.includes(e.channel??``)&&e.senderId&&e.titleSource===`prefix`?O({operatorName:e.personName??null,whatsappName:e.whatsappName??null,senderId:e.senderId,title:e.title,channel:e.channel}):e.personName??e.title;return(0,P.jsxs)(`div`,{ref:t=>{let n=dt.current;t?n.set(e.sessionId,t):n.delete(e.sessionId)},className:`conv conv-with-actions${d}${e.sessionId===W?` active`:``}`,children:[(0,P.jsxs)(`div`,{className:`conv-main-static conv-main-clickable`,role:`button`,tabIndex:0,"aria-label":`Open ${m} in webchat`,onClick:()=>{if(wt!==e.sessionId){if(K){gn(e.sessionId);return}c()}},onKeyDown:t=>{wt!==e.sessionId&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),K?gn(e.sessionId):c())},children:[K&&(0,P.jsx)(`span`,{className:`conv-select-check`,onClick:e=>e.stopPropagation(),children:(0,P.jsx)(fe,{checked:q.has(e.sessionId),ariaLabel:`Select ${m}`,onChange:()=>gn(e.sessionId)})}),(0,P.jsx)(`span`,{className:`conv-live-dot`,"data-live":e.live?`1`:`0`,"data-archived":e.archived?`1`:`0`,"aria-label":e.archived?`archived session`:e.live?`live session`:`ended session`}),(0,P.jsxs)(`span`,{className:`conv-stack`,children:[(0,P.jsxs)(`span`,{className:`conv-name-line`,children:[f&&(0,P.jsx)(de,{channel:e.channel,size:13}),wt===e.sessionId?(0,P.jsx)(`input`,{className:`conv-name conv-name-edit`,autoFocus:!0,onFocus:e=>e.currentTarget.select(),value:Et,disabled:Ot,"aria-label":`New title for session ${e.title}`,onChange:e=>Dt(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),xn(e)):t.key===`Escape`&&(t.preventDefault(),Tt(null),Dt(``))},onBlur:()=>{wt===e.sessionId&&!Ot&&(Tt(null),Dt(``))}}):(0,P.jsx)(`span`,{className:`conv-name`,title:m,children:m})]}),(0,P.jsxs)(`span`,{className:`conv-timestamp`,children:[(0,P.jsx)(`code`,{className:`conv-session-id`,title:`First 8 characters of this session's id — distinguishes rows with identical auto-titles. The resume/delete buttons act on the full id.`,children:e.sessionId.slice(0,8)}),n&&(0,P.jsxs)(`span`,{children:[` · `,n]})]})]})]}),!K&&(0,P.jsx)(pt,{actions:u,disabled:s})]},e.sessionId)})]})})})(),(0,P.jsxs)(`div`,{className:`side-foot`,children:[(0,P.jsx)(`div`,{className:`avatar`,children:d?(0,P.jsx)(`img`,{src:d,alt:we}):ke}),(0,P.jsxs)(`div`,{className:`who`,children:[(0,P.jsx)(`span`,{className:`name`,children:we}),(0,P.jsx)(tn,{})]}),(0,P.jsx)(`button`,{type:`button`,className:`side-foot-kebab`,"aria-label":`Account menu`,"aria-haspopup":`menu`,"aria-expanded":Me,onClick:()=>Ne(e=>!e),children:(0,P.jsx)(ve,{size:16})}),Me&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`div`,{className:`side-foot-menu-scrim`,"aria-hidden":`true`,onClick:()=>Ne(!1)}),(0,P.jsx)(`div`,{className:`side-foot-menu`,role:`menu`,children:(0,P.jsx)(E,{variant:`admin`,onCloseMenu:()=>Ne(!1),onLogout:C??(()=>{}),onDisconnect:oe,disconnecting:A,claudeConnected:le,onConnectClaude:i,cacheKey:r,onOpenConversations:pe})})]})]}),We&&(0,P.jsx)(`div`,{className:`copy-toast${We.failed?` copy-toast-failed`:``}`,role:`status`,children:We.message}),(0,P.jsx)(It,{open:Gt,pending:X,onConfirm:e=>{fn(e)},onCancel:e=>{qt(!1)}}),(0,P.jsx)(Rt,{error:Ge,onClose:()=>H(null)}),(0,P.jsx)(Bt,{open:Fe,installed:B?.installed??`unknown`,latest:B?.latest??null,initialActionId:Le,onClose:()=>Ie(!1)}),(0,P.jsx)(Vt,{open:Ke,onConnect:()=>{qe(!1),i?.()},onClose:()=>qe(!1)}),(0,P.jsx)(Mt,{target:gt,anchorEl:gt?dt.current.get(gt.sessionId)??null:null,onCancel:()=>_t(null),onConfirm:()=>{let e=gt;_t(null),e&&hn(e)}},gt?.sessionId??`none`),(0,P.jsx)(Pt,{open:mt,count:q.size,liveCount:U.filter(e=>q.has(e.sessionId)&&e.live).length,onConfirm:()=>{ht(!1),vn()},onCancel:()=>ht(!1)}),(0,P.jsx)(Kt,{show:jt!==null,onClose:()=>{Nt(null),Lt(null),Y(null)},anchorEl:jt?dt.current.get(jt.sessionId)??null:null,sessionId:jt?.sessionId??null,summary:Ft,loading:zt,error:Ut},jt?.sessionId??`none`)]})}var Z=5e3,en=3e4;function tn(){let[e,t]=(0,F.useState)(null);if((0,F.useEffect)(()=>{let e=!1,n=null;async function r(){try{let n=await fetch(`/api/admin/system-stats`);if(!n.ok){console.error(`[admin-ui] system-stats-fetch-failed status=${n.status}`);return}let r=await n.json();e||t(r)}catch(e){console.error(`[admin-ui] system-stats-fetch-failed reason=${e instanceof Error?e.message:String(e)}`)}}function i(){n===null&&(r(),n=setInterval(()=>{r()},Z))}function a(){n!==null&&(clearInterval(n),n=null)}function o(){document.hidden?a():i()}return document.hidden||i(),document.addEventListener(`visibilitychange`,o),()=>{e=!0,a(),document.removeEventListener(`visibilitychange`,o)}},[]),!e||e.platform===`darwin`)return null;let n=e.cpuPct,r=e.memUsedPct,i=n!==null&&n>=.9,a=n!==null&&n>=.98,o=r!==null&&r>=.9,s=r!==null&&r>=.98,c=i||o,l=a||s,u=e=>e===null?`—`:`${Math.round(e*100)}%`,d=[`system-stats`];return c&&d.push(`system-stats--warn`),l&&d.push(`system-stats--crit`),(0,P.jsxs)(`span`,{className:d.join(` `),role:`status`,"aria-label":`host CPU and RAM`,children:[(0,P.jsxs)(`span`,{className:i?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`CPU `,u(n)]}),` · `,(0,P.jsxs)(`span`,{className:o?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`RAM `,u(r)]})]})}var nn=`maxy-shell-browser-px`;function rn(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .side`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function Q(){return typeof window>`u`?360:an(Math.round((window.innerWidth-rn())/2))}function an(e){if(typeof window>`u`)return e;let t=Math.max(360,window.innerWidth-rn()-480);return Math.min(Math.max(e,360),t)}function on(){if(typeof window>`u`)return 360;try{let e=window.localStorage.getItem(nn);if(!e)return Q();let t=parseInt(e,10);return Number.isFinite(t)?an(t):(console.warn(`[admin-ui] browser-width-parse-failed stored=${JSON.stringify(e)}`),Q())}catch{return Q()}}function sn({targetSelector:e=`.platform`}={}){let t=(0,F.useRef)(null),n=(0,F.useRef)(360),[,r]=(0,F.useState)(0),i=(0,F.useCallback)(t=>{n.current=t;let i=document.querySelector(e);i instanceof HTMLElement&&i.style.setProperty(`--artefact-px`,`${t}px`),r(e=>e+1)},[e]);(0,F.useLayoutEffect)(()=>{i(on())},[i]),(0,F.useEffect)(()=>{let e=()=>i(an(n.current));return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[i]);let a=e=>{e.preventDefault();let r=t.current;if(!r)return;r.setPointerCapture(e.pointerId),r.classList.add(`dragging`);let a=!1,o=e=>{a=!0,i(an(Math.round(window.innerWidth-e.clientX)))},s=()=>{if(r.releasePointerCapture(e.pointerId),r.classList.remove(`dragging`),window.removeEventListener(`pointermove`,o),window.removeEventListener(`pointerup`,s),a)try{window.localStorage.setItem(nn,String(n.current))}catch{}};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},o=()=>{i(Q());try{window.localStorage.removeItem(nn)}catch{}};return(0,P.jsx)(`div`,{ref:t,className:`browser-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize browser`,onPointerDown:a,onDoubleClick:o})}var cn=1;function $(e){let t=e.className,n=(typeof t==`string`?t:t?.baseVal??``).trim().split(/\s+/).filter(Boolean);return[e.tagName.toUpperCase(),...n].join(`.`)}function ln(e,t){let n=t.extent-t.vw;return n<cn?null:{op:`layout-overflow`,route:e,vw:t.vw,extent:Math.round(t.extent),delta:Math.round(n),offender:t.offender??``}}function un(e,t){if(!e||!t)return null;let n=e.documentElement?.clientWidth??0;if(n<=0)return null;let r=n,i=null;for(let t of Array.from(e.body?.querySelectorAll(`*`)??[])){let e=t.getBoundingClientRect().right;e>=r&&e>n+.5&&(r=e,i=$(t))}return{vw:n,extent:r,offender:i}}function dn(e){return e?`${e.route}|${e.delta}|${e.offender}`:null}function fn(e,t){if(!t)return;let n=ln(e,t);if(n)try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`event`,source:`layout-overflow`,...n}),keepalive:!0}).catch(()=>{})}catch{}}function pn(e,t,n=400){let r=0,i,a=0,o=null,s=()=>{if(a>=5)return;let n=t.location.pathname,r=un(e,t),i=dn(r&&ln(n,r));if(!i){o=null;return}i!==o&&(o=i,a+=1,fn(n,r))},c=()=>{t.cancelAnimationFrame(r),r=t.requestAnimationFrame(s)},l=()=>{i!==void 0&&clearTimeout(i),i=setTimeout(c,n)};c(),t.addEventListener(`resize`,c);let u=new MutationObserver(l);return e.body&&u.observe(e.body,{childList:!0,subtree:!0}),()=>{t.cancelAnimationFrame(r),i!==void 0&&clearTimeout(i),t.removeEventListener(`resize`,c),u.disconnect()}}function mn(e){return e.supported?e.secureContext?e.permission===`denied`?{show:!1,reason:`permission-denied`}:e.permission===`granted`?e.focused?{show:!1,reason:`focused`}:{show:!0}:{show:!1,reason:`permission-default`}:{show:!1,reason:`insecure-context`}:{show:!1,reason:`unsupported`}}function hn(){let e=typeof window<`u`&&`Notification`in window;return{supported:e,secureContext:typeof window<`u`&&window.isSecureContext===!0,permission:e?Notification.permission:`default`,focused:typeof document<`u`&&typeof document.hasFocus==`function`?document.hasFocus():!0}}var gn=500,_n=new Set,vn=new Set;function yn(e,t){if(e.size>=gn){for(let t of e)if(e.delete(t),e.size<gn)break}e.add(t)}function bn(e){return e??(typeof globalThis.fetch==`function`?globalThis.fetch:void 0)}function xn(e,t,n){try{Promise.resolve(e(`/api/admin/events`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({event:t,fields:n})})).catch(()=>{})}catch{}}function Sn(e,t){let n=bn(t);return n?(xn(n,`channel-notify:desktop-capability`,{supported:e.supported,secure:e.secureContext,permission:e.permission}),!0):!1}function Cn(e,t,n,r){if(_n.has(e))return!1;let i=bn(r);return i?(yn(_n,e),xn(i,`channel-notify:desktop-outcome`,{msgId:e,senderType:t,reason:n}),!0):!1}function wn(e,t,n){try{if(vn.has(e.messageId))return;yn(vn,e.messageId);let r=mn(hn());if(!r.show){Cn(e.messageId,e.senderType,r.reason,n);return}new Notification(`${e.accountName} · ${e.senderDisplay}`,{body:e.body+(e.truncated?`…`:``),icon:t,tag:e.messageId}),Cn(e.messageId,e.senderType,`shown`,n)}catch{Cn(e.messageId,e.senderType,`construct-failed`,n)}}var Tn=`admin-sidebar-collapsed`,En=`admin-sidebar-drawer-open`,Dn=1080;function On(){if(typeof window>`u`)return!1;let e=null;try{e=window.sessionStorage.getItem(Tn)}catch{e=null}return e===null?typeof window.matchMedia==`function`?window.matchMedia(`(min-width: 721px) and (max-width: ${Dn}px)`).matches:!1:e===`1`}function kn(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(Tn,`1`):window.sessionStorage.removeItem(Tn)}catch{}}function An(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(En)===`1`}catch{return!1}}function jn(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(En,`1`):window.sessionStorage.removeItem(En)}catch{}}var Mn=720;function Nn(e,t){return e===`/`?{via:`in-place`}:{via:`navigate`,href:`/?wa=${encodeURIComponent(t.remoteJid??``)}&acct=${encodeURIComponent(t.accountId??``)}`}}function Pn(e){return e===`/`?{via:`in-place`}:{via:`navigate`,href:`/?data=1`}}function Fn(e,t){if(e!==`/`)return null;let n=new URLSearchParams(t),r=n.get(`wa`),i=n.get(`acct`);return!r||!i?null:{sessionId:``,projectDir:``,title:``,senderId:null,startedAt:``,channel:`whatsapp`,role:`public`,operatorName:null,whatsappName:null,lastMessageAt:null,modelGated:!1,model:null,source:`store`,accountId:i,remoteJid:r}}function In(e,t){return e===`/`?new URLSearchParams(t).has(`data`):!1}function Ln(e,t){return t===`operator`&&e===`chat`||e===`dashboard`?`/`:e===`data`?`/data`:e===`graph`?`/graph`:e===`calendar`?`/calendar`:e===`chat`?`/chat`:e===`activity`?`/activity`:`/browser`}var Rn=`maxy-webchat-browser-pane`;function zn(){try{let e=window.localStorage.getItem(Rn);return e===`split`||e===`full`?e:`closed`}catch{return`closed`}}function Bn(){return typeof window<`u`&&window.location.pathname.startsWith(`/chat`)}function Vn(e){let{cacheKey:t,businessName:n,variant:r=`admin`,onLogout:a,onDisconnect:o,disconnecting:s,claudeConnected:c,onConnectClaude:l,userName:u,userAvatar:d,role:f,onOpenConversations:p,children:m,footer:g}=e,{subAccounts:_,activeAccountId:v,switching:y,switchAccount:b,refreshAccounts:x}=oe(t),[ee,te]=(0,F.useState)([]),[S,C]=(0,F.useState)(!1),[w,T]=(0,F.useState)(`closed`);(0,F.useEffect)(()=>{let e=Bn();C(e),e&&T(zn())},[]);let E=(0,F.useCallback)(e=>{T(e);try{window.localStorage.setItem(Rn,e)}catch{}},[]),D=(0,F.useCallback)(()=>E(`split`),[E]),se=(0,F.useCallback)(()=>{E(w===`full`?`split`:`full`)},[w,E]),O=(0,F.useCallback)(()=>E(`closed`),[E]),k=S?w:`closed`,A=k!==`closed`,j=(0,F.useCallback)(e=>{te(t=>t.filter(t=>t.messageId!==e))},[]);(0,F.useEffect)(()=>{if(!t)return;let e=null;try{e=new EventSource(ae(`/api/admin/events`,t)),e.addEventListener(Qe,e=>{try{let t=JSON.parse(e.data);if(!t||typeof t.messageId!=`string`)return;te(e=>e.some(e=>e.messageId===t.messageId)?e:[...e,t]),wn(t,ne)}catch{}}),e.onerror=()=>{console.error(`[admin-ui] channel-notify stream error`)}}catch(e){console.error(`[admin-ui] channel-notify unavailable reason=${e instanceof Error?e.message:String(e)}`)}return()=>{e?.close()}},[t]),(0,F.useEffect)(()=>{Sn(hn())},[]);let[M,de]=(0,F.useState)(!0);(0,F.useEffect)(()=>{if(c!==void 0||r!==`admin`)return;let e=!1,t=async()=>{try{let t=await fetch(`/api/health`);if(!t.ok)return;let n=await t.json();e||de(n.auth_status!==`dead`&&n.auth_status!==`missing`)}catch{}};t();let n=setInterval(t,6e4);return()=>{e=!0,clearInterval(n)}},[c,r]);let N=c??M,fe=l??(()=>{window.location.assign(`/?connect=claude`)}),[I,pe]=(0,F.useState)(()=>On()),[L,me]=(0,F.useState)(!1),he=(0,F.useRef)(!0);(0,F.useEffect)(()=>{if(he.current){he.current=!1;return}me(!0);let e=setTimeout(()=>me(!1),260);return()=>clearTimeout(e)},[I]);let[R,ge]=(0,F.useState)(()=>An()),_e=le(`(max-width: ${Mn}px)`),[ve,ye]=(0,F.useState)(()=>typeof window>`u`||In(window.location.pathname,window.location.search)?null:Fn(window.location.pathname,window.location.search)),[be,xe]=(0,F.useState)(()=>typeof window>`u`?!1:In(window.location.pathname,window.location.search)),[Se]=(0,F.useState)(()=>be),Ce=(0,F.useCallback)(e=>{kn(e),pe(e)},[]),z=(0,F.useCallback)(e=>{jn(e),ge(e)},[]);(0,F.useEffect)(()=>{typeof window>`u`||window.location?.pathname},[]),(0,F.useEffect)(()=>{typeof window>`u`||!ve||window.history.replaceState(null,``,`/`)},[]),(0,F.useEffect)(()=>{typeof window>`u`||!be||window.history.replaceState(null,``,`/`)},[]);let we=(0,F.useCallback)(e=>{if(xe(!1),e===null){ye(null);return}let t=Nn(typeof window<`u`?window.location.pathname:`/`,e);t.via===`in-place`?ye(e):window.location.href=t.href},[]),Te=(0,F.useCallback)(()=>{let e=Pn(typeof window<`u`?window.location.pathname:`/`);if(e.via===`navigate`){window.location.href=e.href;return}ye(null),xe(!0)},[]),Ee=_e?R:!I,De=(0,F.useCallback)(()=>{typeof window>`u`||(window.matchMedia(`(max-width: ${Mn}px)`).matches?z(!R):Ce(!I))},[I,R,Ce,z]);(0,F.useEffect)(()=>{if(!(typeof window>`u`))return pn(document,window)},[]),(0,F.useEffect)(()=>{if(!(typeof window>`u`))return ie(document,window)},[]);let Oe=(0,F.useCallback)(e=>{let t=Ln(e,r);window.location.href=t},[r]),ke={collapsed:I,mobileDrawerOpen:R,sidebarOpen:Ee,onToggleSidebar:De,setMobileDrawerOpen:z,selectedWhatsapp:ve,onClearWhatsapp:()=>ye(null),onSelectWhatsappConversation:we,dataOpen:be};return r===`operator`?(0,P.jsx)(ue,{cacheKey:t,children:(0,P.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[y&&(0,P.jsx)(h,{surface:`switch`}),(0,P.jsx)(i,{businessName:n,variant:r,onNavigate:Oe,onOpenConversations:p,onToggleSidebar:De,sidebarOpen:Ee,onLogout:a,onDisconnect:o,disconnecting:s,cacheKey:t,subAccounts:_,activeAccountId:v,switchingAccount:y,onSwitchAccount:b,refreshAccounts:x}),(0,P.jsxs)(`div`,{className:`platform platform-operator`,children:[(0,P.jsx)(re,{}),typeof m==`function`?m(ke):m]}),(0,P.jsx)(G,{variant:`operator`,onOpenConversations:p}),g,(0,P.jsx)(Ze,{frames:ee,onExpire:j})]})}):(0,P.jsx)(ue,{cacheKey:t,children:(0,P.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[y&&(0,P.jsx)(h,{surface:`switch`}),(0,P.jsxs)(`div`,{className:`platform${R?` menu-open`:``}${!_e&&I?` sidebar-collapsed`:``}${L?` sidebar-animating`:``}`,"data-artefact":A?`browser`:`closed`,"data-browser-pane":k,children:[(0,P.jsx)($t,{businessName:n,cacheKey:t,onConnectClaude:fe,role:f??null,userName:u,userAvatar:d??null,onSelectProjects:()=>{window.location.href=`/graph?label=${ce().label}`},onSelectTasks:()=>{window.location.href=`/tasks`},onCloseMobileDrawer:()=>z(!1),collapsed:I,mobileDrawerOpen:R,onSelectData:Te,onCloseData:()=>xe(!1),initialDataSurface:Se,onLogout:a,onDisconnect:o,disconnecting:s,claudeConnected:N,subAccounts:_,activeAccountId:v,switchingAccount:y,onSwitchAccount:b,refreshAccounts:x,onOpenConversations:p}),!_e&&(0,P.jsx)(lt,{}),(0,P.jsx)(tt,{sidebarOpen:Ee,onToggleSidebar:De,claudeConnected:N,onConnectClaude:fe,onOpenBrowser:S&&!A?D:void 0}),typeof m==`function`?m(ke):m,A&&(0,P.jsxs)(`div`,{className:`webchat-browser-pane`,children:[k===`split`&&(0,P.jsx)(sn,{}),(0,P.jsx)(H,{cacheKey:e.cacheKey,surface:`webchat`,onToggleFull:se,onClosePane:O,isFull:k===`full`})]})]}),R&&(0,P.jsx)(`div`,{className:`sidebar-backdrop menu-open`,"aria-hidden":`true`,onClick:()=>z(!1)}),(0,P.jsx)(G,{}),g,(0,P.jsx)(Ze,{frames:ee,onExpire:j})]})})}export{_e as C,L as D,me as E,fe as O,ve as S,he as T,Ce as _,Nt as a,be as b,J as c,_t as d,pt as f,Te as g,Ee as h,zt as i,N as k,mt as l,Oe as m,Xt as n,It as o,H as p,Vt as r,ht as s,Vn as t,bt as u,Se as v,ge as w,ye as x,xe as y};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-BycB0eMI.js";import{i as t,n,t as r}from"./jsx-runtime-DeRQuYlX.js";import{C as i,N as a,P as o,k as s,nt as c,r as l,ut as u}from"./useMediaQuery-Cm_fvNIH.js";import{D as d,O as f,k as p,t as m}from"./AdminShell-DyOPTLdb.js";import{t as h}from"./triangle-alert-DD4kSK45.js";var g=n(),_=e(t(),1),v=r(),y=`—`;function b(e){switch(e){case`waiting`:return`Waiting`;case`never-run`:return`Never run`;case`never-succeeded`:return`Never succeeded`;case`failing`:return`Failing`;case`stalled`:return`Stalled`;case`running`:return`Running`;case`ok`:return`Healthy`}}var x={waiting:`Armed and not due yet. It has no start-up run and its first interval has not elapsed, so it has correctly not fired.`,"never-run":`Its interval has elapsed and it still has not fired once. This is not the same as waiting its turn.`,"never-succeeded":`It has fired, and not one run has finished. The work this loop exists to do has never happened.`,failing:`It worked before and is failing now.`,stalled:`It has not started within three of its own intervals. Something is holding it up.`,running:`A run is in progress right now.`,ok:`The last run finished and the next is due within the interval.`},S=new Set([`never-run`,`never-succeeded`,`failing`,`stalled`]),C=10;function w(e){return e===null||!Number.isFinite(e)?y:`${e.toFixed(1)}%`}function T(e){return e<6e4?`${Math.round(e/1e3)}s`:e<36e5?`${Math.round(e/6e4)}m`:`${Math.round(e/36e5)}h`}function E(e,t){if(e===null)return y;let n=t-e;return n<0?`in ${T(-n)}`:n<6e4?`${Math.round(n/1e3)}s ago`:n<36e5?`${Math.round(n/6e4)}m ago`:`${Math.round(n/36e5)}h ago`}function D(e,t){if(e===null)return y;let n=e-t;return n>=0?`in ${T(n)}`:`overdue by ${T(-n)}`}function ee({loops:e,nowMs:t=Date.now()}){let[n,r]=(0,_.useState)(!1);if(!e)return(0,v.jsxs)(`section`,{className:`activity-loops`,children:[(0,v.jsx)(`h2`,{className:`activity-loops-heading`,children:`Scheduled work`}),(0,v.jsx)(`p`,{className:`activity-loops-empty`,children:`Scheduled work could not be read from the server.`})]});let i=e.armed-e.rows.length,a=e.rows.filter(e=>S.has(e.state)),o=e.rows.filter(e=>!S.has(e.state)&&typeof e.cpuPct==`number`&&e.cpuPct>=C),s=n?e.rows:[...a,...o];return(0,v.jsxs)(`section`,{className:`activity-loops`,children:[(0,v.jsx)(`h2`,{className:`activity-loops-heading`,children:`Scheduled work`}),(0,v.jsxs)(`p`,{className:`activity-loops-sub`,children:[e.armed,` `,e.armed===1?`loop`:`loops`,` armed`,a.length>0?` · ${a.length} ${a.length===1?`needs`:`need`} attention`:` · all healthy`,o.length>0&&` · ${o.length} using significant processor`,`. `,(0,v.jsx)(`button`,{type:`button`,className:`activity-loops-toggle`,"aria-expanded":n,onClick:()=>r(e=>!e),children:n?`Show less`:`Show all`})]}),typeof e.processPct==`number`&&(0,v.jsxs)(`p`,{className:`activity-loops-cpu`,children:[`Server process at `,e.processPct.toFixed(1),`% of one core`,typeof e.attributedPct==`number`&&(0,v.jsxs)(v.Fragment,{children:[` · these loops explain `,e.attributedPct.toFixed(1),`%`]}),typeof e.unattributedPct==`number`&&e.unattributedPct>=1&&(0,v.jsxs)(v.Fragment,{children:[` · `,(0,v.jsxs)(`strong`,{children:[e.unattributedPct.toFixed(1),`% is not from these loops`]})]})]}),i>0&&(0,v.jsxs)(`p`,{className:`activity-loops-omission`,role:`status`,children:[i,` armed `,i===1?`loop is`:`loops are`,` missing from this list. The server armed `,e.armed,` but sent `,e.rows.length,`.`]}),s.length===0?null:(0,v.jsx)(`div`,{className:`activity-table-scroll`,children:(0,v.jsxs)(`table`,{className:`activity-table`,children:[(0,v.jsx)(`thead`,{children:(0,v.jsxs)(`tr`,{children:[(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Loop`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`State`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Every`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Last run`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Last OK`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Took`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`CPU`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Runs`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Produced`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Next due`})]})}),(0,v.jsx)(`tbody`,{children:s.map(e=>(0,v.jsxs)(`tr`,{className:S.has(e.state)?`activity-loop-row activity-loop-unhealthy`:`activity-loop-row`,children:[(0,v.jsx)(`td`,{className:`activity-td`,children:e.name}),(0,v.jsx)(`td`,{className:`activity-td`,title:x[e.state],children:(0,v.jsxs)(`span`,{className:`activity-state`,children:[(0,v.jsx)(`span`,{className:e.state===`ok`?`activity-state-dot is-healthy`:S.has(e.state)?`activity-state-dot is-unhealthy`:`activity-state-dot`,"aria-hidden":`true`}),b(e.state)]})}),(0,v.jsx)(`td`,{className:`activity-td activity-num`,children:T(e.intervalMs)}),(0,v.jsx)(`td`,{className:`activity-td activity-num`,children:E(e.lastStartMs,t)}),(0,v.jsx)(`td`,{className:`activity-td activity-num`,children:E(e.lastSuccessMs,t)}),(0,v.jsx)(`td`,{className:`activity-td activity-num`,children:e.lastDurationMs===null?y:`${e.lastDurationMs} ms`}),(0,v.jsx)(`td`,{className:`activity-td activity-num`,title:e.cpuAttributable?e.detached?`Includes the processor time of the separate process this loop starts.`:void 0:`This loop waits on other work while it runs, so the processor time it uses cannot be separated from the rest of the server.`,children:w(e.cpuPct)}),(0,v.jsxs)(`td`,{className:`activity-td activity-num`,children:[e.successCount,`/`,e.runCount]}),(0,v.jsx)(`td`,{className:`activity-td activity-loop-note`,children:(0,v.jsx)(`span`,{className:`activity-loop-note-text`,title:e.lastError??e.lastNote??void 0,children:e.lastError??e.lastNote??y})}),(0,v.jsx)(`td`,{className:`activity-td activity-num`,children:D(e.nextDueMs,t)})]},e.name))})]})}),(0,v.jsxs)(`dl`,{className:`activity-legend`,children:[(0,v.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,v.jsx)(`dt`,{className:`activity-legend-term`,children:`Runs`}),(0,v.jsx)(`dd`,{className:`activity-legend-def`,children:`Finished runs out of attempted runs since the server started. 0 out of a large number means it has tried many times and never once finished.`})]}),(0,v.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,v.jsx)(`dt`,{className:`activity-legend-term`,children:`CPU`}),(0,v.jsx)(`dd`,{className:`activity-legend-def`,children:`Share of one processor core this loop is using, measured between the last two refreshes. It includes any separate process the loop starts, and can pass 100% because those run alongside each other. A dash means it could not be measured: the loop waits on other work while it runs, so its share cannot be separated from the rest of the server.`})]}),(0,v.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,v.jsx)(`dt`,{className:`activity-legend-term`,children:y}),(0,v.jsx)(`dd`,{className:`activity-legend-def`,children:`Not measured. It does not mean zero.`})]})]})]})}var O=`maxy-admin-session-key`;function te(e){switch(e.costUnavailable){case`metering-failed`:return`Cost could not be calculated: ${e.meteringError??`the transcript could not be read`}`;case`model-not-priced`:return`No published price for this model, so cost cannot be estimated.`;case`no-transcript`:return`This session has no transcript yet, so there is nothing to cost.`;default:return}}var k=[{key:`lastMessageAt`,label:`Last activity`,dir:-1},{key:`activeMsInRange`,label:`Active time`,dir:-1},{key:`costGbp`,label:`Cost`,dir:-1},{key:`accountId`,label:`Account name`,dir:1}],A=[{key:`title`,label:`Session`,help:`The conversation name, or its short id when it has none yet.`},{key:`model`,label:`Model`,help:`The model that answered the most recent turn.`},{key:`status`,label:`Status`,help:`What the process is doing right now.`},{key:`activeMsInRange`,label:`Active`,help:`Time this session spent thinking, writing and running tools inside the selected range. This is worked time, not elapsed time.`},{key:`ageMs`,label:`Age`,help:`How long ago this conversation started. Wall-clock, so it counts every hour nobody was working.`},{key:`lastMessageAt`,label:`Last activity`,help:`The clock time of the most recent message, in your timezone. A date appears once it is not today.`},{key:`turnCount`,label:`Turns`,help:`Messages exchanged. A trailing + means the count is a minimum — the conversation is too long to count exactly.`},{key:`rssKb`,label:`RAM`,help:`Memory held by this session and all its helper processes together.`},{key:`cpuPct`,label:`CPU (avg)`,help:`AVERAGE share of one processor core over the last census interval, up to 60 seconds. It is not a reading of this instant, so a session that answered a turn a minute ago still shows a high figure while sitting quiet now. Can exceed 100% because a session runs many processes at once.`},{key:`tokensInRange`,label:`Tokens`,help:`Total tokens billed inside the selected range, added up across every day in it. A cumulative total, not the size of the conversation the model currently reads back.`},{key:`costGbp`,label:`Cost`,help:`Estimated spend inside the selected range, at published prices for this model.`}],j=[`activeMsInRange`,`lastMessageAt`,`cpuPct`,`tokensInRange`],M={label:`Account`,help:`The business this session belongs to. "untagged" means the session records no account.`};function ne(e,t){let n=t?.[e];return n&&n.trim()!==``?n:e.slice(0,8)}var N=`—`;function P(e){if(e===null||!Number.isFinite(e)||e<0)return N;let t=Math.floor(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);if(n<60)return`${n}m`;let r=Math.floor(n/60);return r<24?`${r}h ${n%60}m`:`${Math.floor(r/24)}d ${r%24}h`}function F(e){return e===null||!Number.isFinite(e)?N:`${(e/1024/1024).toFixed(1)} GB`}function I(e,t,n){if(!e)return N;let r=Date.parse(e);if(!Number.isFinite(r))return N;let i=s(new Date(r),n),a=s(new Date(t),n),o=`${String(i.hh).padStart(2,`0`)}:${String(i.mm).padStart(2,`0`)}`;return i.y===a.y&&i.m===a.m&&i.d===a.d?o:`${i.d} ${L[i.m-1]} ${o}`}var L=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`];function R(e){return e===null||!Number.isFinite(e)?N:`${e.toFixed(1)}%`}function z(e){return e===null||!Number.isFinite(e)?N:e<1e3?String(e):e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(2)}M`}function B(e){return e===null||!Number.isFinite(e)?N:`£${e.toFixed(2)}`}function V(e){if(e===null||!Number.isFinite(e)||e<0)return N;let t=Math.floor(e/6e4);return`${Math.floor(t/60)}h ${t%60}m`}function H(e,t,n,r){let i=e[n],a=t[n];if(i===null&&a===null)return 0;if(i===null)return 1;if(a===null)return-1;if(n===`lastMessageAt`){let e=Date.parse(String(i)),t=Date.parse(String(a));return!Number.isFinite(e)&&!Number.isFinite(t)?0:Number.isFinite(e)?Number.isFinite(t)?(e-t)*r:-1:1}return typeof i==`number`&&typeof a==`number`?(i-a)*r:String(i).localeCompare(String(a))*r}function U(e){return e.toISOString().slice(0,10)}function W(e){let t=e.getUTCFullYear(),n=e.getUTCMonth();return{from:U(new Date(Date.UTC(t,n,1))),to:U(new Date(Date.UTC(t,n+1,0)))}}function G(e,t){let n=new Date(`${e}T00:00:00.000Z`);return W(new Date(Date.UTC(n.getUTCFullYear(),n.getUTCMonth()+t,1)))}function K(e,t){return{from:U(new Date(t-(e-1)*864e5)),to:U(new Date(t))}}function q(e){return new Date(`${e}T00:00:00.000Z`).toLocaleString(`en-GB`,{month:`long`,year:`numeric`,timeZone:`UTC`})}function J(e){if(e===null)return!1;let t=W(new Date(`${e.from}T00:00:00.000Z`));return t.from===e.from&&t.to===e.to}function Y(e,t,n,r){switch(e){case`title`:return t.title??t.sessionId.slice(0,8);case`model`:return t.model??N;case`status`:return t.status??N;case`activeMsInRange`:return V(t.activeMsInRange);case`ageMs`:return P(t.ageMs);case`lastMessageAt`:return I(t.lastMessageAt,n,r);case`turnCount`:return t.turnCount===null?N:`${t.turnCount}${t.turnCountCapped?`+`:``}`;case`rssKb`:return F(t.rssKb);case`cpuPct`:return R(t.cpuPct);case`tokensInRange`:return z(t.tokensInRange);case`costGbp`:return B(t.costGbp);default:return N}}function X({adminFetch:e,cacheKey:t}){let{zone:n}=i(),[r,o]=(0,_.useState)(null),[s,u]=(0,_.useState)(null),[p,m]=(0,_.useState)(!1),[g,y]=(0,_.useState)(`lastMessageAt`),[b,x]=(0,_.useState)(-1),[S,C]=(0,_.useState)(()=>W(new Date)),[w,T]=(0,_.useState)(!0),[E,D]=(0,_.useState)(!0),[O,F]=(0,_.useState)(!1),I=(0,_.useCallback)(async(e,n)=>{t&&await l(t,e)&&window.location.assign(`/chat?session=${encodeURIComponent(n)}`)},[t]),L=(0,_.useRef)(!1),R=(0,_.useRef)(void 0),z=(0,_.useCallback)(async t=>{if(L.current){R.current=t;return}L.current=!0;try{let n=await e(`/api/admin/activity${t?`?from=${t.from}&to=${t.to}`:``}`);if(n.status===403){u(`This view is available to the house account only.`),m(!0);return}if(!n.ok){u(`The session manager did not answer (status ${n.status}).`),m(!0);return}o(await n.json()),u(null)}catch(e){u(e instanceof Error?e.message:String(e))}finally{m(!0),L.current=!1;let e=R.current;R.current=void 0,e!==void 0&&z(e)}},[e]);(0,_.useEffect)(()=>{z(S);let e=setInterval(()=>void z(S),15e3);return()=>clearInterval(e)},[z,S]);let B=(0,_.useMemo)(()=>r?[...r.rows].sort((e,t)=>H(e,t,g,b)):[],[r,g,b]),V=(0,_.useMemo)(()=>B.filter(e=>e.status===`busy`?w:e.status===`idle`?E:!0),[B,w,E]),U=B.length-V.length;if(!p)return(0,v.jsx)(a,{surface:`gate`});if(s)return(0,v.jsx)(`div`,{className:`activity-empty`,children:s});if(!r)return(0,v.jsx)(`div`,{className:`activity-empty`,children:`No response.`});let{accounts:X,census:Z,censusAgeMs:Q}=r,re=Date.now(),ie=X.onDisk!==null&&X.onDisk>X.valid,$=r.range===void 0?S:r.range;return(0,v.jsxs)(`div`,{className:`ui-page ui-page--full activity-body`,children:[(0,v.jsxs)(`div`,{className:`activity-head`,children:[(0,v.jsxs)(`span`,{className:`activity-title`,children:[(0,v.jsx)(c,{size:16}),` Live sessions`]}),(0,v.jsxs)(`span`,{className:`activity-meta`,children:[U>0?`${V.length} of ${B.length} live · ${U} hidden`:`${B.length} live`,` · `,X.valid,` accounts`,X.untaggedCount>0?` · ${X.untaggedCount} untagged`:``]})]}),(0,v.jsxs)(`div`,{className:`activity-controls`,children:[(0,v.jsxs)(`div`,{className:`activity-control activity-range`,children:[(0,v.jsx)(d,{variant:`secondary`,size:`sm`,"aria-label":`Previous month`,disabled:!J(S),onClick:()=>C(e=>e&&G(e.from,-1)),children:`‹`}),(0,v.jsx)(`span`,{className:`activity-range-label`,children:S===null?`All time`:J(S)?q(S.from):`${S.from} → ${S.to}`}),(0,v.jsx)(d,{variant:`secondary`,size:`sm`,"aria-label":`Next month`,disabled:!J(S),onClick:()=>C(e=>e&&G(e.from,1)),children:`›`})]}),(0,v.jsxs)(`div`,{className:`activity-control activity-presets`,children:[(0,v.jsx)(d,{variant:`secondary`,size:`sm`,"aria-pressed":S!==null&&J(S)&&S.from===W(new Date).from,onClick:()=>C(W(new Date)),children:`This month`}),(0,v.jsx)(d,{variant:`secondary`,size:`sm`,"aria-pressed":S!==null&&!J(S),onClick:()=>C(K(7,Date.now())),children:`Last 7 days`}),(0,v.jsx)(d,{variant:`secondary`,size:`sm`,"aria-pressed":S===null,onClick:()=>C(null),children:`All time`})]}),(0,v.jsxs)(`div`,{className:`activity-control`,children:[(0,v.jsx)(`label`,{className:`activity-control-label`,htmlFor:`activity-sort`,children:`Sort by`}),(0,v.jsx)(`span`,{className:`activity-select-wrap`,children:(0,v.jsx)(`select`,{id:`activity-sort`,className:`activity-select`,value:g,onChange:e=>{let t=k.find(t=>t.key===e.target.value);t&&(y(t.key),x(t.dir))},children:k.map(e=>(0,v.jsx)(`option`,{value:e.key,children:e.label},e.key))})})]}),(0,v.jsxs)(`div`,{className:`activity-control activity-visibility`,children:[(0,v.jsx)(f,{checked:w,onChange:T,label:`Busy`}),(0,v.jsx)(f,{checked:E,onChange:D,label:`Idle`})]})]}),(0,v.jsxs)(`div`,{className:`activity-range-note`,children:[$===null?`Active time, tokens and cost cover each conversation’s whole history.`:`Active time, tokens and cost cover ${$.from} to ${$.to} (UTC), inclusive.`,r.fullRangeFallback&&(0,v.jsxs)(`strong`,{className:`activity-range-rejected`,children:[` `,`The range was not accepted, so these are all-time figures.`]})]}),(0,v.jsx)(`div`,{className:`activity-census`,children:Z===null?`No census collected yet, so memory and CPU are unavailable.`:`Memory and CPU measured ${P(Q)} ago, averaged over the minute before that · ${Z.cpuNull} of ${Z.live} without a CPU reading`}),ie&&(0,v.jsxs)(`div`,{className:`activity-warning`,children:[(0,v.jsx)(h,{size:14}),` `,X.onDisk,` account folders on disk but only`,` `,X.valid,` are readable. Sessions belonging to the rest cannot be attributed.`]}),B.length===0?(0,v.jsx)(`div`,{className:`activity-empty`,children:`No sessions are running.`}):V.length===0?(0,v.jsxs)(`div`,{className:`activity-empty`,children:[`All `,B.length,` running sessions are hidden by the Busy and Idle filters.`]}):(0,v.jsx)(`div`,{className:`activity-grid`,children:V.map(e=>{let r=e.accountId!==null&&!!t,i=r?()=>void I(e.accountId,e.sessionId):void 0;return(0,v.jsxs)(`article`,{className:`activity-card${r?` activity-card-clickable`:``}`,"data-testid":`activity-card`,"data-session-id":e.sessionId,role:r?`button`:void 0,tabIndex:r?0:void 0,onClick:i,onKeyDown:r?e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),i())}:void 0,children:[(0,v.jsx)(`h3`,{className:`activity-card-heading`,title:e.accountId??void 0,children:e.accountId===null?(0,v.jsx)(`span`,{className:`activity-untagged`,title:`This session records no account, so it cannot be attributed to a business.`,children:`untagged`}):ne(e.accountId,X.names)}),(0,v.jsx)(`dl`,{className:`activity-card-rows`,children:A.map(t=>(0,v.jsxs)(`div`,{className:`activity-card-row`,children:[(0,v.jsx)(`dt`,{className:`activity-card-label`,"data-testid":`activity-card-label`,title:t.help,children:t.label}),(0,v.jsx)(`dd`,{className:`activity-card-value`,title:t.key===`costGbp`?te(e):void 0,children:Y(t.key,e,re,n)})]},t.key))})]},e.sessionId)})}),B.length>0&&(0,v.jsxs)(`div`,{className:`activity-glossary`,children:[(0,v.jsxs)(`dl`,{className:`activity-legend`,children:[O&&(0,v.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,v.jsx)(`dt`,{className:`activity-legend-term`,"data-testid":`activity-glossary-term`,children:M.label}),(0,v.jsx)(`dd`,{className:`activity-legend-def`,children:M.help})]},`heading`),(O?A:A.filter(e=>j.includes(e.key))).map(e=>(0,v.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,v.jsx)(`dt`,{className:`activity-legend-term`,"data-testid":`activity-glossary-term`,children:e.label}),(0,v.jsx)(`dd`,{className:`activity-legend-def`,children:e.help})]},e.key)),(0,v.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,v.jsx)(`dt`,{className:`activity-legend-term`,children:N}),(0,v.jsxs)(`dd`,{className:`activity-legend-def`,children:[`Not measured. It does not mean zero — a measured zero is written as a figure, so `,(0,v.jsx)(`em`,{children:`0h 0m`}),` and `,(0,v.jsx)(`em`,{children:`£0.00`}),` are real readings. Hover a dashed value for the reason where one exists.`]})]})]}),(0,v.jsx)(d,{variant:`secondary`,size:`sm`,className:`activity-glossary-toggle`,onClick:()=>F(e=>!e),children:O?`Show fewer`:`Explain every figure`})]}),(0,v.jsx)(ee,{loops:r?.loops})]})}function Z({cacheKey:e}){let{adminFetch:t}=u({initialCacheKey:e,surface:`activity`});return(0,v.jsx)(X,{adminFetch:t,cacheKey:e})}function Q(){let[e,t]=(0,_.useState)(null),[n,r]=(0,_.useState)(!1),[i,s]=(0,_.useState)(void 0),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)(null),[f,h]=(0,_.useState)(null),[g,y]=(0,_.useState)(null);(0,_.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(O)}catch{}if(!n){t(null),r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(O)}catch{}window.location.href=`/`;return}if(i.ok)try{let e=await i.json();typeof e.businessName==`string`&&s(e.businessName),e.sessionId!==void 0&&l(e.sessionId??null),d(e.role??null),h(e.userName===void 0?null:e.userName),y(e.avatar??null)}catch{}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]);let b=(0,_.useCallback)(()=>{try{sessionStorage.removeItem(O)}catch{}window.location.href=`/`},[]),[x,S]=(0,_.useState)(!1),C=(0,_.useCallback)(async()=>{S(!0);try{let e=await p();if(e){try{sessionStorage.removeItem(O)}catch{}window.location.href=`/`}return e}finally{S(!1)}},[]);return n?e?(0,v.jsx)(o,{cacheKey:e,surface:`activity`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=activity`);try{sessionStorage.removeItem(O)}catch{}window.location.href=`/`},children:(0,v.jsx)(m,{cacheKey:e,businessName:i,sessionId:c,onLogout:b,onDisconnect:C,disconnecting:x,userName:f,userAvatar:g,role:u,children:(0,v.jsx)(Z,{cacheKey:e})})}):(0,v.jsx)(`div`,{className:`activity-page`,children:(0,v.jsxs)(`div`,{className:`activity-empty`,children:[(0,v.jsx)(`p`,{children:`You are not signed in.`}),(0,v.jsxs)(`p`,{children:[`Open the `,(0,v.jsx)(`a`,{href:`/`,className:`activity-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,v.jsx)(a,{surface:`gate`})}(0,g.createRoot)(document.getElementById(`root`)).render((0,v.jsx)(Q,{}));
1
+ import{o as e}from"./chunk-BycB0eMI.js";import{i as t,n,t as r}from"./jsx-runtime-BY35JYDT.js";import{C as i,N as a,P as o,k as s,nt as c,r as l,ut as u}from"./useMediaQuery-e4ciNiuO.js";import{D as d,O as f,k as p,t as m}from"./AdminShell-Dm_nY4jF.js";import{t as h}from"./triangle-alert-C_68TrTq.js";var g=n(),_=e(t(),1),v=r(),y=`—`;function b(e){switch(e){case`waiting`:return`Waiting`;case`never-run`:return`Never run`;case`never-succeeded`:return`Never succeeded`;case`failing`:return`Failing`;case`stalled`:return`Stalled`;case`running`:return`Running`;case`ok`:return`Healthy`}}var x={waiting:`Armed and not due yet. It has no start-up run and its first interval has not elapsed, so it has correctly not fired.`,"never-run":`Its interval has elapsed and it still has not fired once. This is not the same as waiting its turn.`,"never-succeeded":`It has fired, and not one run has finished. The work this loop exists to do has never happened.`,failing:`It worked before and is failing now.`,stalled:`It has not started within three of its own intervals. Something is holding it up.`,running:`A run is in progress right now.`,ok:`The last run finished and the next is due within the interval.`},S=new Set([`never-run`,`never-succeeded`,`failing`,`stalled`]),C=10;function w(e){return e===null||!Number.isFinite(e)?y:`${e.toFixed(1)}%`}function T(e){return e<6e4?`${Math.round(e/1e3)}s`:e<36e5?`${Math.round(e/6e4)}m`:`${Math.round(e/36e5)}h`}function E(e,t){if(e===null)return y;let n=t-e;return n<0?`in ${T(-n)}`:n<6e4?`${Math.round(n/1e3)}s ago`:n<36e5?`${Math.round(n/6e4)}m ago`:`${Math.round(n/36e5)}h ago`}function D(e,t){if(e===null)return y;let n=e-t;return n>=0?`in ${T(n)}`:`overdue by ${T(-n)}`}function ee({loops:e,nowMs:t=Date.now()}){let[n,r]=(0,_.useState)(!1);if(!e)return(0,v.jsxs)(`section`,{className:`activity-loops`,children:[(0,v.jsx)(`h2`,{className:`activity-loops-heading`,children:`Scheduled work`}),(0,v.jsx)(`p`,{className:`activity-loops-empty`,children:`Scheduled work could not be read from the server.`})]});let i=e.armed-e.rows.length,a=e.rows.filter(e=>S.has(e.state)),o=e.rows.filter(e=>!S.has(e.state)&&typeof e.cpuPct==`number`&&e.cpuPct>=C),s=n?e.rows:[...a,...o];return(0,v.jsxs)(`section`,{className:`activity-loops`,children:[(0,v.jsx)(`h2`,{className:`activity-loops-heading`,children:`Scheduled work`}),(0,v.jsxs)(`p`,{className:`activity-loops-sub`,children:[e.armed,` `,e.armed===1?`loop`:`loops`,` armed`,a.length>0?` · ${a.length} ${a.length===1?`needs`:`need`} attention`:` · all healthy`,o.length>0&&` · ${o.length} using significant processor`,`. `,(0,v.jsx)(`button`,{type:`button`,className:`activity-loops-toggle`,"aria-expanded":n,onClick:()=>r(e=>!e),children:n?`Show less`:`Show all`})]}),typeof e.processPct==`number`&&(0,v.jsxs)(`p`,{className:`activity-loops-cpu`,children:[`Server process at `,e.processPct.toFixed(1),`% of one core`,typeof e.attributedPct==`number`&&(0,v.jsxs)(v.Fragment,{children:[` · these loops explain `,e.attributedPct.toFixed(1),`%`]}),typeof e.unattributedPct==`number`&&e.unattributedPct>=1&&(0,v.jsxs)(v.Fragment,{children:[` · `,(0,v.jsxs)(`strong`,{children:[e.unattributedPct.toFixed(1),`% is not from these loops`]})]})]}),i>0&&(0,v.jsxs)(`p`,{className:`activity-loops-omission`,role:`status`,children:[i,` armed `,i===1?`loop is`:`loops are`,` missing from this list. The server armed `,e.armed,` but sent `,e.rows.length,`.`]}),s.length===0?null:(0,v.jsx)(`div`,{className:`activity-table-scroll`,children:(0,v.jsxs)(`table`,{className:`activity-table`,children:[(0,v.jsx)(`thead`,{children:(0,v.jsxs)(`tr`,{children:[(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Loop`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`State`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Every`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Last run`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Last OK`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Took`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`CPU`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Runs`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Produced`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Next due`})]})}),(0,v.jsx)(`tbody`,{children:s.map(e=>(0,v.jsxs)(`tr`,{className:S.has(e.state)?`activity-loop-row activity-loop-unhealthy`:`activity-loop-row`,children:[(0,v.jsx)(`td`,{className:`activity-td`,children:e.name}),(0,v.jsx)(`td`,{className:`activity-td`,title:x[e.state],children:(0,v.jsxs)(`span`,{className:`activity-state`,children:[(0,v.jsx)(`span`,{className:e.state===`ok`?`activity-state-dot is-healthy`:S.has(e.state)?`activity-state-dot is-unhealthy`:`activity-state-dot`,"aria-hidden":`true`}),b(e.state)]})}),(0,v.jsx)(`td`,{className:`activity-td activity-num`,children:T(e.intervalMs)}),(0,v.jsx)(`td`,{className:`activity-td activity-num`,children:E(e.lastStartMs,t)}),(0,v.jsx)(`td`,{className:`activity-td activity-num`,children:E(e.lastSuccessMs,t)}),(0,v.jsx)(`td`,{className:`activity-td activity-num`,children:e.lastDurationMs===null?y:`${e.lastDurationMs} ms`}),(0,v.jsx)(`td`,{className:`activity-td activity-num`,title:e.cpuAttributable?e.detached?`Includes the processor time of the separate process this loop starts.`:void 0:`This loop waits on other work while it runs, so the processor time it uses cannot be separated from the rest of the server.`,children:w(e.cpuPct)}),(0,v.jsxs)(`td`,{className:`activity-td activity-num`,children:[e.successCount,`/`,e.runCount]}),(0,v.jsx)(`td`,{className:`activity-td activity-loop-note`,children:(0,v.jsx)(`span`,{className:`activity-loop-note-text`,title:e.lastError??e.lastNote??void 0,children:e.lastError??e.lastNote??y})}),(0,v.jsx)(`td`,{className:`activity-td activity-num`,children:D(e.nextDueMs,t)})]},e.name))})]})}),(0,v.jsxs)(`dl`,{className:`activity-legend`,children:[(0,v.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,v.jsx)(`dt`,{className:`activity-legend-term`,children:`Runs`}),(0,v.jsx)(`dd`,{className:`activity-legend-def`,children:`Finished runs out of attempted runs since the server started. 0 out of a large number means it has tried many times and never once finished.`})]}),(0,v.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,v.jsx)(`dt`,{className:`activity-legend-term`,children:`CPU`}),(0,v.jsx)(`dd`,{className:`activity-legend-def`,children:`Share of one processor core this loop is using, measured between the last two refreshes. It includes any separate process the loop starts, and can pass 100% because those run alongside each other. A dash means it could not be measured: the loop waits on other work while it runs, so its share cannot be separated from the rest of the server.`})]}),(0,v.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,v.jsx)(`dt`,{className:`activity-legend-term`,children:y}),(0,v.jsx)(`dd`,{className:`activity-legend-def`,children:`Not measured. It does not mean zero.`})]})]})]})}var O=`maxy-admin-session-key`;function te(e){switch(e.costUnavailable){case`metering-failed`:return`Cost could not be calculated: ${e.meteringError??`the transcript could not be read`}`;case`model-not-priced`:return`No published price for this model, so cost cannot be estimated.`;case`no-transcript`:return`This session has no transcript yet, so there is nothing to cost.`;default:return}}var k=[{key:`lastMessageAt`,label:`Last activity`,dir:-1},{key:`activeMsInRange`,label:`Active time`,dir:-1},{key:`costGbp`,label:`Cost`,dir:-1},{key:`accountId`,label:`Account name`,dir:1}],A=[{key:`title`,label:`Session`,help:`The conversation name, or its short id when it has none yet.`},{key:`model`,label:`Model`,help:`The model that answered the most recent turn.`},{key:`status`,label:`Status`,help:`What the process is doing right now.`},{key:`activeMsInRange`,label:`Active`,help:`Time this session spent thinking, writing and running tools inside the selected range. This is worked time, not elapsed time.`},{key:`ageMs`,label:`Age`,help:`How long ago this conversation started. Wall-clock, so it counts every hour nobody was working.`},{key:`lastMessageAt`,label:`Last activity`,help:`The clock time of the most recent message, in your timezone. A date appears once it is not today.`},{key:`turnCount`,label:`Turns`,help:`Messages exchanged. A trailing + means the count is a minimum — the conversation is too long to count exactly.`},{key:`rssKb`,label:`RAM`,help:`Memory held by this session and all its helper processes together.`},{key:`cpuPct`,label:`CPU (avg)`,help:`AVERAGE share of one processor core over the last census interval, up to 60 seconds. It is not a reading of this instant, so a session that answered a turn a minute ago still shows a high figure while sitting quiet now. Can exceed 100% because a session runs many processes at once.`},{key:`tokensInRange`,label:`Tokens`,help:`Total tokens billed inside the selected range, added up across every day in it. A cumulative total, not the size of the conversation the model currently reads back.`},{key:`costGbp`,label:`Cost`,help:`Estimated spend inside the selected range, at published prices for this model.`}],j=[`activeMsInRange`,`lastMessageAt`,`cpuPct`,`tokensInRange`],M={label:`Account`,help:`The business this session belongs to. "untagged" means the session records no account.`};function ne(e,t){let n=t?.[e];return n&&n.trim()!==``?n:e.slice(0,8)}var N=`—`;function P(e){if(e===null||!Number.isFinite(e)||e<0)return N;let t=Math.floor(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);if(n<60)return`${n}m`;let r=Math.floor(n/60);return r<24?`${r}h ${n%60}m`:`${Math.floor(r/24)}d ${r%24}h`}function F(e){return e===null||!Number.isFinite(e)?N:`${(e/1024/1024).toFixed(1)} GB`}function I(e,t,n){if(!e)return N;let r=Date.parse(e);if(!Number.isFinite(r))return N;let i=s(new Date(r),n),a=s(new Date(t),n),o=`${String(i.hh).padStart(2,`0`)}:${String(i.mm).padStart(2,`0`)}`;return i.y===a.y&&i.m===a.m&&i.d===a.d?o:`${i.d} ${L[i.m-1]} ${o}`}var L=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`];function R(e){return e===null||!Number.isFinite(e)?N:`${e.toFixed(1)}%`}function z(e){return e===null||!Number.isFinite(e)?N:e<1e3?String(e):e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(2)}M`}function B(e){return e===null||!Number.isFinite(e)?N:`£${e.toFixed(2)}`}function V(e){if(e===null||!Number.isFinite(e)||e<0)return N;let t=Math.floor(e/6e4);return`${Math.floor(t/60)}h ${t%60}m`}function H(e,t,n,r){let i=e[n],a=t[n];if(i===null&&a===null)return 0;if(i===null)return 1;if(a===null)return-1;if(n===`lastMessageAt`){let e=Date.parse(String(i)),t=Date.parse(String(a));return!Number.isFinite(e)&&!Number.isFinite(t)?0:Number.isFinite(e)?Number.isFinite(t)?(e-t)*r:-1:1}return typeof i==`number`&&typeof a==`number`?(i-a)*r:String(i).localeCompare(String(a))*r}function U(e){return e.toISOString().slice(0,10)}function W(e){let t=e.getUTCFullYear(),n=e.getUTCMonth();return{from:U(new Date(Date.UTC(t,n,1))),to:U(new Date(Date.UTC(t,n+1,0)))}}function G(e,t){let n=new Date(`${e}T00:00:00.000Z`);return W(new Date(Date.UTC(n.getUTCFullYear(),n.getUTCMonth()+t,1)))}function K(e,t){return{from:U(new Date(t-(e-1)*864e5)),to:U(new Date(t))}}function q(e){return new Date(`${e}T00:00:00.000Z`).toLocaleString(`en-GB`,{month:`long`,year:`numeric`,timeZone:`UTC`})}function J(e){if(e===null)return!1;let t=W(new Date(`${e.from}T00:00:00.000Z`));return t.from===e.from&&t.to===e.to}function Y(e,t,n,r){switch(e){case`title`:return t.title??t.sessionId.slice(0,8);case`model`:return t.model??N;case`status`:return t.status??N;case`activeMsInRange`:return V(t.activeMsInRange);case`ageMs`:return P(t.ageMs);case`lastMessageAt`:return I(t.lastMessageAt,n,r);case`turnCount`:return t.turnCount===null?N:`${t.turnCount}${t.turnCountCapped?`+`:``}`;case`rssKb`:return F(t.rssKb);case`cpuPct`:return R(t.cpuPct);case`tokensInRange`:return z(t.tokensInRange);case`costGbp`:return B(t.costGbp);default:return N}}function X({adminFetch:e,cacheKey:t}){let{zone:n}=i(),[r,o]=(0,_.useState)(null),[s,u]=(0,_.useState)(null),[p,m]=(0,_.useState)(!1),[g,y]=(0,_.useState)(`lastMessageAt`),[b,x]=(0,_.useState)(-1),[S,C]=(0,_.useState)(()=>W(new Date)),[w,T]=(0,_.useState)(!0),[E,D]=(0,_.useState)(!0),[O,F]=(0,_.useState)(!1),I=(0,_.useCallback)(async(e,n)=>{t&&await l(t,e)&&window.location.assign(`/chat?session=${encodeURIComponent(n)}`)},[t]),L=(0,_.useRef)(!1),R=(0,_.useRef)(void 0),z=(0,_.useCallback)(async t=>{if(L.current){R.current=t;return}L.current=!0;try{let n=await e(`/api/admin/activity${t?`?from=${t.from}&to=${t.to}`:``}`);if(n.status===403){u(`This view is available to the house account only.`),m(!0);return}if(!n.ok){u(`The session manager did not answer (status ${n.status}).`),m(!0);return}o(await n.json()),u(null)}catch(e){u(e instanceof Error?e.message:String(e))}finally{m(!0),L.current=!1;let e=R.current;R.current=void 0,e!==void 0&&z(e)}},[e]);(0,_.useEffect)(()=>{z(S);let e=setInterval(()=>void z(S),15e3);return()=>clearInterval(e)},[z,S]);let B=(0,_.useMemo)(()=>r?[...r.rows].sort((e,t)=>H(e,t,g,b)):[],[r,g,b]),V=(0,_.useMemo)(()=>B.filter(e=>e.status===`busy`?w:e.status===`idle`?E:!0),[B,w,E]),U=B.length-V.length;if(!p)return(0,v.jsx)(a,{surface:`gate`});if(s)return(0,v.jsx)(`div`,{className:`activity-empty`,children:s});if(!r)return(0,v.jsx)(`div`,{className:`activity-empty`,children:`No response.`});let{accounts:X,census:Z,censusAgeMs:Q}=r,re=Date.now(),ie=X.onDisk!==null&&X.onDisk>X.valid,$=r.range===void 0?S:r.range;return(0,v.jsxs)(`div`,{className:`ui-page ui-page--full activity-body`,children:[(0,v.jsxs)(`div`,{className:`activity-head`,children:[(0,v.jsxs)(`span`,{className:`activity-title`,children:[(0,v.jsx)(c,{size:16}),` Live sessions`]}),(0,v.jsxs)(`span`,{className:`activity-meta`,children:[U>0?`${V.length} of ${B.length} live · ${U} hidden`:`${B.length} live`,` · `,X.valid,` accounts`,X.untaggedCount>0?` · ${X.untaggedCount} untagged`:``]})]}),(0,v.jsxs)(`div`,{className:`activity-controls`,children:[(0,v.jsxs)(`div`,{className:`activity-control activity-range`,children:[(0,v.jsx)(d,{variant:`secondary`,size:`sm`,"aria-label":`Previous month`,disabled:!J(S),onClick:()=>C(e=>e&&G(e.from,-1)),children:`‹`}),(0,v.jsx)(`span`,{className:`activity-range-label`,children:S===null?`All time`:J(S)?q(S.from):`${S.from} → ${S.to}`}),(0,v.jsx)(d,{variant:`secondary`,size:`sm`,"aria-label":`Next month`,disabled:!J(S),onClick:()=>C(e=>e&&G(e.from,1)),children:`›`})]}),(0,v.jsxs)(`div`,{className:`activity-control activity-presets`,children:[(0,v.jsx)(d,{variant:`secondary`,size:`sm`,"aria-pressed":S!==null&&J(S)&&S.from===W(new Date).from,onClick:()=>C(W(new Date)),children:`This month`}),(0,v.jsx)(d,{variant:`secondary`,size:`sm`,"aria-pressed":S!==null&&!J(S),onClick:()=>C(K(7,Date.now())),children:`Last 7 days`}),(0,v.jsx)(d,{variant:`secondary`,size:`sm`,"aria-pressed":S===null,onClick:()=>C(null),children:`All time`})]}),(0,v.jsxs)(`div`,{className:`activity-control`,children:[(0,v.jsx)(`label`,{className:`activity-control-label`,htmlFor:`activity-sort`,children:`Sort by`}),(0,v.jsx)(`span`,{className:`activity-select-wrap`,children:(0,v.jsx)(`select`,{id:`activity-sort`,className:`activity-select`,value:g,onChange:e=>{let t=k.find(t=>t.key===e.target.value);t&&(y(t.key),x(t.dir))},children:k.map(e=>(0,v.jsx)(`option`,{value:e.key,children:e.label},e.key))})})]}),(0,v.jsxs)(`div`,{className:`activity-control activity-visibility`,children:[(0,v.jsx)(f,{checked:w,onChange:T,label:`Busy`}),(0,v.jsx)(f,{checked:E,onChange:D,label:`Idle`})]})]}),(0,v.jsxs)(`div`,{className:`activity-range-note`,children:[$===null?`Active time, tokens and cost cover each conversation’s whole history.`:`Active time, tokens and cost cover ${$.from} to ${$.to} (UTC), inclusive.`,r.fullRangeFallback&&(0,v.jsxs)(`strong`,{className:`activity-range-rejected`,children:[` `,`The range was not accepted, so these are all-time figures.`]})]}),(0,v.jsx)(`div`,{className:`activity-census`,children:Z===null?`No census collected yet, so memory and CPU are unavailable.`:`Memory and CPU measured ${P(Q)} ago, averaged over the minute before that · ${Z.cpuNull} of ${Z.live} without a CPU reading`}),ie&&(0,v.jsxs)(`div`,{className:`activity-warning`,children:[(0,v.jsx)(h,{size:14}),` `,X.onDisk,` account folders on disk but only`,` `,X.valid,` are readable. Sessions belonging to the rest cannot be attributed.`]}),B.length===0?(0,v.jsx)(`div`,{className:`activity-empty`,children:`No sessions are running.`}):V.length===0?(0,v.jsxs)(`div`,{className:`activity-empty`,children:[`All `,B.length,` running sessions are hidden by the Busy and Idle filters.`]}):(0,v.jsx)(`div`,{className:`activity-grid`,children:V.map(e=>{let r=e.accountId!==null&&!!t,i=r?()=>void I(e.accountId,e.sessionId):void 0;return(0,v.jsxs)(`article`,{className:`activity-card${r?` activity-card-clickable`:``}`,"data-testid":`activity-card`,"data-session-id":e.sessionId,role:r?`button`:void 0,tabIndex:r?0:void 0,onClick:i,onKeyDown:r?e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),i())}:void 0,children:[(0,v.jsx)(`h3`,{className:`activity-card-heading`,title:e.accountId??void 0,children:e.accountId===null?(0,v.jsx)(`span`,{className:`activity-untagged`,title:`This session records no account, so it cannot be attributed to a business.`,children:`untagged`}):ne(e.accountId,X.names)}),(0,v.jsx)(`dl`,{className:`activity-card-rows`,children:A.map(t=>(0,v.jsxs)(`div`,{className:`activity-card-row`,children:[(0,v.jsx)(`dt`,{className:`activity-card-label`,"data-testid":`activity-card-label`,title:t.help,children:t.label}),(0,v.jsx)(`dd`,{className:`activity-card-value`,title:t.key===`costGbp`?te(e):void 0,children:Y(t.key,e,re,n)})]},t.key))})]},e.sessionId)})}),B.length>0&&(0,v.jsxs)(`div`,{className:`activity-glossary`,children:[(0,v.jsxs)(`dl`,{className:`activity-legend`,children:[O&&(0,v.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,v.jsx)(`dt`,{className:`activity-legend-term`,"data-testid":`activity-glossary-term`,children:M.label}),(0,v.jsx)(`dd`,{className:`activity-legend-def`,children:M.help})]},`heading`),(O?A:A.filter(e=>j.includes(e.key))).map(e=>(0,v.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,v.jsx)(`dt`,{className:`activity-legend-term`,"data-testid":`activity-glossary-term`,children:e.label}),(0,v.jsx)(`dd`,{className:`activity-legend-def`,children:e.help})]},e.key)),(0,v.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,v.jsx)(`dt`,{className:`activity-legend-term`,children:N}),(0,v.jsxs)(`dd`,{className:`activity-legend-def`,children:[`Not measured. It does not mean zero — a measured zero is written as a figure, so `,(0,v.jsx)(`em`,{children:`0h 0m`}),` and `,(0,v.jsx)(`em`,{children:`£0.00`}),` are real readings. Hover a dashed value for the reason where one exists.`]})]})]}),(0,v.jsx)(d,{variant:`secondary`,size:`sm`,className:`activity-glossary-toggle`,onClick:()=>F(e=>!e),children:O?`Show fewer`:`Explain every figure`})]}),(0,v.jsx)(ee,{loops:r?.loops})]})}function Z({cacheKey:e}){let{adminFetch:t}=u({initialCacheKey:e,surface:`activity`});return(0,v.jsx)(X,{adminFetch:t,cacheKey:e})}function Q(){let[e,t]=(0,_.useState)(null),[n,r]=(0,_.useState)(!1),[i,s]=(0,_.useState)(void 0),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)(null),[f,h]=(0,_.useState)(null),[g,y]=(0,_.useState)(null);(0,_.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(O)}catch{}if(!n){t(null),r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(O)}catch{}window.location.href=`/`;return}if(i.ok)try{let e=await i.json();typeof e.businessName==`string`&&s(e.businessName),e.sessionId!==void 0&&l(e.sessionId??null),d(e.role??null),h(e.userName===void 0?null:e.userName),y(e.avatar??null)}catch{}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]);let b=(0,_.useCallback)(()=>{try{sessionStorage.removeItem(O)}catch{}window.location.href=`/`},[]),[x,S]=(0,_.useState)(!1),C=(0,_.useCallback)(async()=>{S(!0);try{let e=await p();if(e){try{sessionStorage.removeItem(O)}catch{}window.location.href=`/`}return e}finally{S(!1)}},[]);return n?e?(0,v.jsx)(o,{cacheKey:e,surface:`activity`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=activity`);try{sessionStorage.removeItem(O)}catch{}window.location.href=`/`},children:(0,v.jsx)(m,{cacheKey:e,businessName:i,sessionId:c,onLogout:b,onDisconnect:C,disconnecting:x,userName:f,userAvatar:g,role:u,children:(0,v.jsx)(Z,{cacheKey:e})})}):(0,v.jsx)(`div`,{className:`activity-page`,children:(0,v.jsxs)(`div`,{className:`activity-empty`,children:[(0,v.jsx)(`p`,{children:`You are not signed in.`}),(0,v.jsxs)(`p`,{children:[`Open the `,(0,v.jsx)(`a`,{href:`/`,className:`activity-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,v.jsx)(a,{surface:`gate`})}(0,g.createRoot)(document.getElementById(`root`)).render((0,v.jsx)(Q,{}));
@@ -1 +1 @@
1
- import{o as e}from"./chunk-BycB0eMI.js";import{i as t,n,t as r}from"./jsx-runtime-DeRQuYlX.js";import{C as i,E as a,F as o,P as s,R as c,ct as l,h as u,i as d,k as f,p,y as ee}from"./useMediaQuery-Cm_fvNIH.js";import{n as m,t as h}from"./AdminLoginScreens-uk2gBvI9.js";import{T as g,c as _,p as te}from"./useVoiceRecorder-C6xqnm7i.js";import{h as ne,i as v,t as y,w as re,x as b}from"./AdminShell-DyOPTLdb.js";import{t as x}from"./chevron-left-QGcFX-3R.js";import{i as S,n as C,r as ie}from"./page-iL446JAc.js";import{t as ae}from"./file-text-Cws2LExM.js";import"./graph-labels-qHDVYalh.js";import{n as oe}from"./file-download-B7zwa78w.js";var w=n(),T=e(t(),1),E=r();function D({onOpen:e}){return(0,E.jsx)(`footer`,{className:`admin-footer`,children:(0,E.jsxs)(`div`,{className:`powered-by`,role:`button`,tabIndex:0,onClick:e,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),e())},"aria-label":`Powered by Claude Code — show details`,children:[(0,E.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`powered-by-icon`}),(0,E.jsx)(`span`,{children:`Powered by Claude Code`})]})})}function O({sessionId:e,projectDir:t,sessionKey:n,contactName:r,onBack:i}){return(0,E.jsxs)(`div`,{className:`wa-web`,children:[(0,E.jsxs)(`header`,{className:`wa-web-header`,children:[i&&(0,E.jsx)(`button`,{type:`button`,className:`wa-web-back`,onClick:i,"aria-label":`Back`,children:(0,E.jsx)(x,{size:20})}),(0,E.jsx)(`span`,{className:`wa-web-avatar`,"aria-hidden":!0,children:(0,E.jsx)(g,{size:20})}),(0,E.jsx)(`div`,{className:`wa-web-titles`,children:(0,E.jsx)(`span`,{className:`wa-web-name`,children:r})})]}),(0,E.jsx)(`div`,{className:`wa-web-body`,children:(0,E.jsx)(_,{sessionId:e,projectDir:t,sessionKey:n,forceDeliveredOnly:!0})})]})}var k=6e4,A=60*k,j=24*A,M=k,N=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],P=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function F(e){return e<10?`0${e}`:String(e)}function I(e,t){let n=f(e,t);return Date.UTC(n.y,n.m-1,n.d)}function L(e,t,n){if(!Number.isFinite(e)||e<=0||!Number.isFinite(t))return`—`;let r=t-e;if(r<-M)return`—`;let i=r<0?0:r;if(i<k)return`just now`;if(i<A)return`${Math.floor(i/k)}m`;if(i<j)return`${Math.floor(i/A)}h`;let a=I(new Date(t),n),o=I(new Date(e),n),s=Math.round((a-o)/j);if(s===1)return`yesterday`;let c=f(new Date(e),n);if(s>=2&&s<=6)return P[new Date(o).getUTCDay()];let l=F(c.d),u=N[c.m-1],d=f(new Date(t),n).y;return c.y===d?`${l} ${u}`:`${l} ${u} ${c.y}`}function R({variant:e=`row`,count:t=1}){return(0,E.jsx)(E.Fragment,{children:Array.from({length:t},(t,n)=>(0,E.jsx)(`span`,{className:`dashboard-skeleton dashboard-skeleton--${e}`,"data-testid":`dashboard-skeleton`,"aria-hidden":`true`},n))})}var se=6e4;function ce(e){return e<12?`morning`:e<18?`afternoon`:`evening`}function z(e){return e&&e.trim().split(/\s+/)[0]||`there`}function le(e){if(!e)return`everything is running normally.`;let t=e.cpuPct,n=e.memUsedPct;return t!==null&&t>=.98||n!==null&&n>=.98?`system load is critical.`:t!==null&&t>=.9||n!==null&&n>=.9?`system load is high.`:`everything is running normally.`}function B(e){return e==null?`—`:`${Math.round(e*100)}%`}function V(e){let t=Date.parse(e.lastMessageAt??``);return Number.isFinite(t)?t:-1/0}function ue(e,t,n){if(!e)return!1;let r=Date.parse(e);return Number.isFinite(r)?a(new Date(r),n)===a(new Date(t),n):!1}function de(e){return e?e.replace(/^claude-/,``):null}function fe(e,t,n,r,i){let a=0;for(let e=1;e<n.length;e+=1)V(n[e-1])<V(n[e])&&(a+=1);let o=!1;for(let e=1;e<t.length;e+=1)if(t[e-1].channel!==t[e].channel){o=!0;break}let s=new Map;for(let t of e)s.set(t.channel,(s.get(t.channel)??0)+1);return{feedRows:e.length,renderedRows:n.length,cap:r,hidden:e.length-n.length,expanded:i,outOfOrder:a,undated:e.filter(e=>V(e)===-1/0).length,channels:[...s.entries()].map(([e,t])=>`${e}:${t}`).join(`,`),interleaved:o}}var H=new Set([`sessions`,`conversations`,`tasks`,`artefacts`,`skills`,`stats`]),U=!1;function pe(e,t,n,r){let i=e=>t.get(e)??null,a=r?r.getEntriesByType(`navigation`)[0]:void 0,o=r?r.getEntriesByType(`resource`).filter(e=>new URL(e.name,`http://x`).pathname.startsWith(`/assets/`)):[],s=e=>e===void 0||!Number.isFinite(e)?null:Math.round(e),c=e=>e?s(e):null;return{batchMs:e,sessionsMs:i(`sessions`),conversationsMs:i(`conversations`),tasksMs:i(`tasks`),artefactsMs:i(`artefacts`),skillsMs:i(`skills`),statsMs:i(`stats`),failed:[...H].filter(e=>n.has(e)).join(`,`)||`none`,ttfbMs:s(a?.responseStart),domContentLoadedMs:c(a?.domContentLoadedEventEnd),loadMs:c(a?.loadEventEnd),assetCount:o.length,assetBytes:o.reduce((e,t)=>e+(t.transferSize||0),0),assetMs:o.length?s(Math.max(...o.map(e=>e.responseEnd))):null}}function W({cacheKey:e,userName:t,onSelectWhatsappConversation:n}){let{zone:r}=i(),a=o(e),[s,f]=(0,T.useState)(null),[m,h]=(0,T.useState)(null),[g,_]=(0,T.useState)(null),[v,y]=(0,T.useState)(null),[x,S]=(0,T.useState)(null),[C,ie]=(0,T.useState)(null),[w,D]=(0,T.useState)(null),[O,k]=(0,T.useState)(null),[A,j]=(0,T.useState)(null),[M,N]=(0,T.useState)(new Set),[P,F]=(0,T.useState)(()=>new Set),I=(0,T.useCallback)(e=>{F(t=>t.has(e)?t:new Set(t).add(e))},[]),H=Date.now(),W=(0,T.useRef)(!1),G=(0,T.useRef)(new Map),me=(0,T.useRef)(new Set),K=(0,T.useRef)(null);(0,T.useEffect)(()=>{if(!e)return;let t=!1;async function n(e,n,r,i){let o=Date.now(),s=typeof n==`string`?n:`unresolved`;try{typeof n!=`string`&&(s=await n());let e=await a(s);if(!e.ok)throw Error(`status ${e.status}`);let o=await e.json();t||i(r(o))}catch(t){me.current.add(e),console.error(`[admin-ui] dashboard-fetch-failed slice=${e} url=${s} ms=${Date.now()-o} reason=${t instanceof Error?t.message:String(t)}`)}finally{G.current.set(e,Date.now()-o),I(e)}}async function r(){if(!K.current){let e=await a(`/api/admin/accounts`);if(!e.ok)throw Error(`accounts status ${e.status}`);let t=await e.json(),n=t.accounts??[],r=t.activeAccountId??null,i=n.find(e=>e.accountId===r);if(!i)throw Error(`accounts: active ${r??`none`} absent from list of ${n.length}`);let o=i.isHouse||n.length===1;K.current={accountId:i.accountId,isHouse:o}}let{accountId:e,isHouse:t}=K.current;return t?`/api/operator-conversations/conversations-all`:`/api/operator-conversations/conversations`}let i={"sidebar-sessions":()=>n(`sessions`,`/api/admin/sidebar-sessions`,e=>e.sessions??[],f),"conversations-all":()=>n(`conversations`,r,e=>e.conversations??[],h),"tasks-list":()=>n(`tasks`,`/api/admin/tasks-list`,e=>e,y),"sidebar-artefacts":()=>n(`artefacts`,`/api/admin/sidebar-artefacts`,e=>e.artefacts??[],S),skills:()=>n(`skills`,`/api/admin/skills`,e=>e.skills??[],ie)};async function o(){if(W.current)return;W.current=!0;let e=Date.now();try{await Promise.all([...Object.values(i).map(e=>e()),n(`stats`,`/api/admin/system-stats`,e=>e,_),n(`bookingLink`,`/api/admin/calendar/booking-link`,e=>e.bookingDomain??null,D),n(`portalLink`,`/api/admin/data-portal/portal-link`,e=>e.portalDomain??null,k),n(`plannerLink`,`/api/admin/dispatch-planner/planner-link`,e=>e.plannerUrl??null,j)])}finally{W.current=!1;let t=Date.now()-e;if(!U){U=!0;try{let e=pe(t,G.current,me.current,typeof performance>`u`?null:performance);fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`event`,source:`dashboard-load`,...e}),keepalive:!0}).catch(()=>{})}catch{}}}}o();let s=null;try{s=new EventSource(l(`/api/admin/events`,e)),s.onmessage=e=>{if(document.visibilityState===`visible`)try{let{resource:t}=JSON.parse(e.data),n=t?i[t]:void 0;n&&n()}catch{}},s.onerror=()=>{console.error(`[admin-ui] dashboard-events stream error`)}}catch(e){console.error(`[admin-ui] dashboard-events unavailable reason=${e instanceof Error?e.message:String(e)}`)}let c=setInterval(()=>{document.visibilityState===`visible`&&o()},se),u=()=>{document.visibilityState===`visible`&&o()};return document.addEventListener(`visibilitychange`,u),()=>{t=!0,W.current=!1,clearInterval(c),s?.close(),document.removeEventListener(`visibilitychange`,u)}},[e,a]);let q=(0,T.useMemo)(()=>(s??[]).filter(e=>!e.isSubagent),[s]),J=(0,T.useMemo)(()=>q.filter(e=>e.live),[q]),he=(0,T.useMemo)(()=>(m??[]).filter(e=>ue(e.lastMessageAt,H,r)).length,[m,H]),ge=v?.open.length??0,Y=(0,T.useMemo)(()=>[...m??[]].sort((e,t)=>{let n=V(e),r=V(t);return n===r?0:r>n?1:-1}),[m]),[X,_e]=(0,T.useState)(!1),Z=X?Y:Y.slice(0,8),ve=Y.length-Z.length,ye=(0,T.useRef)(null),Q=(0,T.useRef)(null);(0,T.useEffect)(()=>{if(!P.has(`conversations`))return;let e=fe(m??[],Y,Z,8,X),t=JSON.stringify(e);ye.current!==t&&(ye.current=t,Q.current===null&&(Q.current=d()),fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`event`,source:`channels-card`,renderId:Q.current,...e})}).catch(()=>{}))},[P,m,Y,Z,X]);let be=(0,T.useRef)(!1);(0,T.useEffect)(()=>{be.current||!P.has(`bookingLink`)||!P.has(`portalLink`)||!P.has(`plannerLink`)||(be.current=!0)},[P,w,O,A]);let xe=(0,T.useCallback)(async e=>{if(!M.has(e)){N(t=>new Set(t).add(e));try{let t=await a(`/api/admin/session-stop`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e})});if(!t.ok){console.error(`[admin-ui] dashboard-session-stop-failed sessionId=${e} status=${t.status}`);return}f(t=>(t??[]).map(t=>t.sessionId===e?{...t,live:!1}:t))}catch(t){console.error(`[admin-ui] dashboard-session-stop-failed sessionId=${e} reason=${t instanceof Error?t.message:String(t)}`)}finally{N(t=>{let n=new Set(t);return n.delete(e),n})}}},[a,M]),Se=(0,T.useCallback)(t=>{if(!e||!t.downloadPath){console.error(`[admin-ui] dashboard-artefact-download-blocked id=${t.id} reason=${e?`not-downloadable`:`no-cache-key`}`);return}oe(e,t.downloadPath,t.downloadRoot??`data`)},[e]),$=ce(new Date(H).getHours());return(0,E.jsxs)(`div`,{className:`ui-page ui-page--full dashboard-home`,children:[(0,E.jsx)(`p`,{className:`dashboard-greeting`,children:P.has(`stats`)?`Good ${$}, ${z(t)} — ${le(g)}`:`Good ${$}, ${z(t)}`}),(0,E.jsxs)(`div`,{className:`dashboard-stats`,children:[(0,E.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,E.jsx)(`span`,{className:`dashboard-stat-label`,children:`Live sessions`}),P.has(`sessions`)?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`span`,{className:`dashboard-stat-value`,children:J.length}),(0,E.jsxs)(`span`,{className:`dashboard-stat-delta`,children:[`of `,q.length,` total`]})]}):(0,E.jsx)(R,{variant:`value`})]}),(0,E.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,E.jsx)(`span`,{className:`dashboard-stat-label`,children:`Messages today`}),P.has(`conversations`)?(0,E.jsx)(`span`,{className:`dashboard-stat-value`,children:he}):(0,E.jsx)(R,{variant:`value`})]}),(0,E.jsxs)(`a`,{className:`admin-stat-card dashboard-stat-card dashboard-stat-card--link`,href:`/tasks`,children:[(0,E.jsx)(`span`,{className:`dashboard-stat-label`,children:`Open tasks`}),P.has(`tasks`)?(0,E.jsx)(`span`,{className:`dashboard-stat-value`,children:ge}):(0,E.jsx)(R,{variant:`value`})]}),(0,E.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,E.jsx)(`span`,{className:`dashboard-stat-label`,children:`Host CPU`}),P.has(`stats`)?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`span`,{className:`dashboard-stat-value`,children:B(g?.cpuPct??null)}),(0,E.jsxs)(`span`,{className:`dashboard-stat-delta`,children:[`RAM `,B(g?.memUsedPct??null)]})]}):(0,E.jsx)(R,{variant:`value`})]})]}),(0,E.jsxs)(`div`,{className:`dashboard-columns`,children:[(0,E.jsxs)(`div`,{className:`dashboard-col`,children:[(w||O||A)&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Public pages`}),(0,E.jsxs)(`div`,{className:`admin-card dashboard-public-pages`,children:[w&&(0,E.jsxs)(`a`,{className:`admin-row dashboard-public-row`,href:`https://${w}`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,E.jsx)(`span`,{className:`dashboard-public-icon`,children:(0,E.jsx)(b,{size:16})}),(0,E.jsx)(`span`,{className:`dashboard-public-name`,children:`Booking page`})]}),O&&(0,E.jsxs)(`a`,{className:`admin-row dashboard-public-row`,href:`https://${O}`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,E.jsx)(`span`,{className:`dashboard-public-icon`,children:(0,E.jsx)(b,{size:16})}),(0,E.jsx)(`span`,{className:`dashboard-public-name`,children:`File drop`})]}),A&&(0,E.jsxs)(`a`,{className:`admin-row dashboard-public-row`,href:A,target:`_blank`,rel:`noopener noreferrer`,children:[(0,E.jsx)(`span`,{className:`dashboard-public-icon`,children:(0,E.jsx)(b,{size:16})}),(0,E.jsx)(`span`,{className:`dashboard-public-name`,children:`Planner`})]})]})]}),(0,E.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Live now`}),P.has(`sessions`)?J.length===0?(0,E.jsx)(`div`,{className:`admin-card dashboard-empty`,children:`No live sessions right now.`}):J.map(e=>{let t=[e.sessionId.slice(0,8),de(e.model),L(Date.parse(e.startedAt),H,r)].filter(Boolean).join(` · `);return(0,E.jsxs)(`div`,{className:`admin-card dashboard-live-card`,children:[(0,E.jsx)(`span`,{className:`admin-status-dot is-live`}),(0,E.jsxs)(`div`,{className:`dashboard-live-main`,children:[(0,E.jsx)(`span`,{className:`dashboard-live-name`,children:e.title}),(0,E.jsx)(`span`,{className:`dashboard-live-meta`,children:t})]}),(0,E.jsx)(`a`,{className:`admin-btn-cta dashboard-open-btn`,href:`/chat?session=${encodeURIComponent(e.sessionId)}`,children:`Open`}),(0,E.jsx)(`button`,{type:`button`,className:`dashboard-stop-btn`,"aria-label":`Stop ${e.title}`,disabled:M.has(e.sessionId),onClick:()=>void xe(e.sessionId),children:(0,E.jsx)(c,{size:12})})]},e.sessionId)}):(0,E.jsx)(R,{variant:`card`,count:2}),(0,E.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Recent artefacts`}),(0,E.jsx)(`div`,{className:`admin-card dashboard-artefacts`,children:P.has(`artefacts`)?(x??[]).length===0?(0,E.jsx)(`div`,{className:`dashboard-empty`,children:`No recent artefacts.`}):(x??[]).slice(0,6).map(e=>(0,E.jsxs)(`button`,{type:`button`,className:`admin-row dashboard-artefact-row`,onClick:()=>Se(e),children:[(0,E.jsx)(`span`,{className:`dashboard-artefact-icon`,children:e.kind===`agent-template`?(0,E.jsx)(re,{size:16}):(0,E.jsx)(ae,{size:16})}),(0,E.jsx)(`div`,{className:`dashboard-artefact-body`,children:(0,E.jsx)(`span`,{className:`dashboard-artefact-name`,children:e.name})}),(0,E.jsx)(`span`,{className:`dashboard-artefact-time`,children:L(Date.parse(e.updatedAt),H,r)})]},e.id)):(0,E.jsx)(R,{count:3})}),(0,E.jsx)(`a`,{className:`admin-section-label dashboard-col-label dashboard-skills-label`,href:`/skills`,children:`Skills`}),(0,E.jsx)(`div`,{className:`admin-card dashboard-skills`,children:P.has(`skills`)?(C??[]).length===0?(0,E.jsx)(`div`,{className:`dashboard-empty`,children:`No skills yet.`}):(C??[]).map(e=>(0,E.jsxs)(`a`,{className:`admin-row dashboard-skill-row`,href:`/skills`,children:[(0,E.jsx)(`span`,{className:`dashboard-skill-icon`,children:(0,E.jsx)(ne,{size:16})}),(0,E.jsxs)(`div`,{className:`dashboard-skill-body`,children:[(0,E.jsx)(`span`,{className:`dashboard-skill-name`,children:e.skill}),(0,E.jsx)(`span`,{className:`dashboard-skill-plugin`,children:e.plugin})]})]},`${e.plugin}/${e.skill}`)):(0,E.jsx)(R,{count:2})})]}),(0,E.jsxs)(`div`,{className:`dashboard-col`,children:[(0,E.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Channels`}),P.has(`conversations`)?Y.length===0?(0,E.jsx)(`div`,{className:`admin-card dashboard-empty`,children:`No channel activity.`}):(0,E.jsxs)(`div`,{className:`admin-card dashboard-channel-card`,children:[(0,E.jsx)(`div`,{className:`dashboard-channel-convs`,children:Z.map(t=>(0,E.jsxs)(`button`,{type:`button`,className:`admin-row dashboard-channel-conv-row`,onClick:()=>n(t),title:t.title,children:[(0,E.jsxs)(`span`,{className:`dashboard-channel-conv-line`,children:[(0,E.jsx)(`span`,{className:`dashboard-channel-conv-glyph`,children:(0,E.jsx)(ee,{channel:t.channel,size:13})}),(0,E.jsx)(te,{accountId:t.accountId??``,jid:t.remoteJid,sessionKey:e??``,className:`dashboard-channel-conv-avatar`,size:16}),(0,E.jsx)(`span`,{className:`dashboard-channel-conv-name`,children:p(t)}),t.isGroup===!0&&(0,E.jsx)(`span`,{className:`dashboard-channel-conv-tag is-group`,children:`Group`}),t.role===`public`&&(0,E.jsx)(`span`,{className:`dashboard-channel-conv-tag is-public`,children:`Public`}),(0,E.jsx)(`span`,{className:`dashboard-channel-conv-tag`,children:t.isHouse?`House`:`Client`}),!t.preview&&t.lastMessageAt&&(0,E.jsx)(`span`,{className:`dashboard-channel-conv-time`,children:L(Date.parse(t.lastMessageAt),H,r)})]}),t.preview?(0,E.jsxs)(`span`,{className:`dashboard-channel-conv-sub`,children:[(0,E.jsx)(`span`,{className:`dashboard-channel-conv-preview`,children:t.preview}),t.lastMessageAt&&(0,E.jsx)(`span`,{className:`dashboard-channel-conv-time`,children:L(Date.parse(t.lastMessageAt),H,r)})]}):null]},u(t)))}),ve>0&&(0,E.jsxs)(`button`,{type:`button`,className:`dashboard-channel-more`,onClick:()=>_e(!0),children:[`Show `,ve,` more`]})]}):(0,E.jsx)(R,{variant:`card`,count:2})]})]})]})}function G(){let e=m(),[t,n]=(0,T.useState)(!1);(0,T.useEffect)(()=>{if(!t)return;let e=e=>{e.key===`Escape`&&n(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let r=(0,T.useCallback)(async()=>{let t=e.claudeInfo!=null;if(n(!0),t)return;let r=Date.now();if(!e.cacheKey){console.error(`[admin-ui] claude-info-fetch-skipped reason=no-session-key`);return}try{let t=await fetch(`/api/admin/claude-info?session_key=${encodeURIComponent(e.cacheKey)}`);if(t.ok){let n=await t.json();e.setClaudeInfo(n)}}catch(e){console.error(`[admin-ui] claude-info-fetch-failed ms=${Date.now()-r} error="${e instanceof Error?e.message:String(e)}"`)}},[e]),i=(0,T.useCallback)(({code:t,path:n})=>{console.warn(`[admin-auth] outcome=chat-tab-logout-on-401 code=${t} path=${n}`),e.handleLogout()},[e]);return e.appState===`chat`?(0,E.jsx)(s,{cacheKey:e.cacheKey,onSessionExpired:i,surface:`chat`,children:(0,E.jsx)(y,{cacheKey:e.cacheKey,businessName:e.businessName,sessionId:e.sessionId,onLogout:e.handleLogout,onDisconnect:e.handleDisconnect,disconnecting:e.disconnecting,claudeConnected:e.claudeConnected,onConnectClaude:()=>e.setAppState(`connect-claude`),userName:e.userName,userAvatar:e.userAvatar,role:e.role,footer:(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(D,{onOpen:r}),(0,E.jsx)(v,{show:t,onClose:()=>n(!1),claudeInfo:e.claudeInfo,messages:[],sessionElapsed:0,sessionId:e.sessionId,cacheKey:e.cacheKey})]}),children:t=>(0,E.jsx)(E.Fragment,{children:t.dataOpen&&e.cacheKey?(0,E.jsx)(C,{cacheKey:e.cacheKey}):t.selectedWhatsapp&&e.cacheKey?t.selectedWhatsapp.source===`store`&&t.selectedWhatsapp.channel===`telegram`&&t.selectedWhatsapp.channelKey&&t.selectedWhatsapp.accountId?(0,E.jsx)(S,{accountId:t.selectedWhatsapp.accountId,channelKey:t.selectedWhatsapp.channelKey,contactName:p(t.selectedWhatsapp),sessionKey:e.cacheKey,onBack:t.onClearWhatsapp},u(t.selectedWhatsapp)):t.selectedWhatsapp.source===`store`&&t.selectedWhatsapp.remoteJid&&t.selectedWhatsapp.accountId?(0,E.jsx)(ie,{accountId:t.selectedWhatsapp.accountId,remoteJid:t.selectedWhatsapp.remoteJid,contactName:p(t.selectedWhatsapp),sessionKey:e.cacheKey,onBack:t.onClearWhatsapp},u(t.selectedWhatsapp)):(0,E.jsx)(O,{sessionId:t.selectedWhatsapp.sessionId,projectDir:t.selectedWhatsapp.projectDir,sessionKey:e.cacheKey,contactName:p(t.selectedWhatsapp),onBack:t.onClearWhatsapp},u(t.selectedWhatsapp)):(0,E.jsx)(W,{cacheKey:e.cacheKey,userName:e.userName,onSelectWhatsappConversation:t.onSelectWhatsappConversation})})})}):(0,E.jsx)(h,{auth:e})}(0,w.createRoot)(document.getElementById(`root`)).render((0,E.jsx)(G,{}));
1
+ import{o as e}from"./chunk-BycB0eMI.js";import{i as t,n,t as r}from"./jsx-runtime-BY35JYDT.js";import{C as i,E as a,F as o,P as s,R as c,ct as l,h as u,i as d,k as f,p,y as ee}from"./useMediaQuery-e4ciNiuO.js";import{n as m,t as h}from"./AdminLoginScreens-Bjsr45ed.js";import{T as g,c as _,p as te}from"./useVoiceRecorder-D7_wLtrS.js";import{h as ne,i as v,t as y,w as re,x as b}from"./AdminShell-Dm_nY4jF.js";import{t as x}from"./chevron-left-D3_hiHLC.js";import{i as S,n as C,r as ie}from"./page-CdRrpkky.js";import{t as ae}from"./file-text-CVZAL3Er.js";import"./graph-labels-BTFUSc63.js";import{n as oe}from"./file-download-B7zwa78w.js";var w=n(),T=e(t(),1),E=r();function D({onOpen:e}){return(0,E.jsx)(`footer`,{className:`admin-footer`,children:(0,E.jsxs)(`div`,{className:`powered-by`,role:`button`,tabIndex:0,onClick:e,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),e())},"aria-label":`Powered by Claude Code — show details`,children:[(0,E.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`powered-by-icon`}),(0,E.jsx)(`span`,{children:`Powered by Claude Code`})]})})}function O({sessionId:e,projectDir:t,sessionKey:n,contactName:r,onBack:i}){return(0,E.jsxs)(`div`,{className:`wa-web`,children:[(0,E.jsxs)(`header`,{className:`wa-web-header`,children:[i&&(0,E.jsx)(`button`,{type:`button`,className:`wa-web-back`,onClick:i,"aria-label":`Back`,children:(0,E.jsx)(x,{size:20})}),(0,E.jsx)(`span`,{className:`wa-web-avatar`,"aria-hidden":!0,children:(0,E.jsx)(g,{size:20})}),(0,E.jsx)(`div`,{className:`wa-web-titles`,children:(0,E.jsx)(`span`,{className:`wa-web-name`,children:r})})]}),(0,E.jsx)(`div`,{className:`wa-web-body`,children:(0,E.jsx)(_,{sessionId:e,projectDir:t,sessionKey:n,forceDeliveredOnly:!0})})]})}var k=6e4,A=60*k,j=24*A,M=k,N=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],P=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function F(e){return e<10?`0${e}`:String(e)}function I(e,t){let n=f(e,t);return Date.UTC(n.y,n.m-1,n.d)}function L(e,t,n){if(!Number.isFinite(e)||e<=0||!Number.isFinite(t))return`—`;let r=t-e;if(r<-M)return`—`;let i=r<0?0:r;if(i<k)return`just now`;if(i<A)return`${Math.floor(i/k)}m`;if(i<j)return`${Math.floor(i/A)}h`;let a=I(new Date(t),n),o=I(new Date(e),n),s=Math.round((a-o)/j);if(s===1)return`yesterday`;let c=f(new Date(e),n);if(s>=2&&s<=6)return P[new Date(o).getUTCDay()];let l=F(c.d),u=N[c.m-1],d=f(new Date(t),n).y;return c.y===d?`${l} ${u}`:`${l} ${u} ${c.y}`}function R({variant:e=`row`,count:t=1}){return(0,E.jsx)(E.Fragment,{children:Array.from({length:t},(t,n)=>(0,E.jsx)(`span`,{className:`dashboard-skeleton dashboard-skeleton--${e}`,"data-testid":`dashboard-skeleton`,"aria-hidden":`true`},n))})}var se=6e4;function ce(e){return e<12?`morning`:e<18?`afternoon`:`evening`}function z(e){return e&&e.trim().split(/\s+/)[0]||`there`}function le(e){if(!e)return`everything is running normally.`;let t=e.cpuPct,n=e.memUsedPct;return t!==null&&t>=.98||n!==null&&n>=.98?`system load is critical.`:t!==null&&t>=.9||n!==null&&n>=.9?`system load is high.`:`everything is running normally.`}function B(e){return e==null?`—`:`${Math.round(e*100)}%`}function V(e){let t=Date.parse(e.lastMessageAt??``);return Number.isFinite(t)?t:-1/0}function ue(e,t,n){if(!e)return!1;let r=Date.parse(e);return Number.isFinite(r)?a(new Date(r),n)===a(new Date(t),n):!1}function de(e){return e?e.replace(/^claude-/,``):null}function fe(e,t,n,r,i){let a=0;for(let e=1;e<n.length;e+=1)V(n[e-1])<V(n[e])&&(a+=1);let o=!1;for(let e=1;e<t.length;e+=1)if(t[e-1].channel!==t[e].channel){o=!0;break}let s=new Map;for(let t of e)s.set(t.channel,(s.get(t.channel)??0)+1);return{feedRows:e.length,renderedRows:n.length,cap:r,hidden:e.length-n.length,expanded:i,outOfOrder:a,undated:e.filter(e=>V(e)===-1/0).length,channels:[...s.entries()].map(([e,t])=>`${e}:${t}`).join(`,`),interleaved:o}}var H=new Set([`sessions`,`conversations`,`tasks`,`artefacts`,`skills`,`stats`]),U=!1;function pe(e,t,n,r){let i=e=>t.get(e)??null,a=r?r.getEntriesByType(`navigation`)[0]:void 0,o=r?r.getEntriesByType(`resource`).filter(e=>new URL(e.name,`http://x`).pathname.startsWith(`/assets/`)):[],s=e=>e===void 0||!Number.isFinite(e)?null:Math.round(e),c=e=>e?s(e):null;return{batchMs:e,sessionsMs:i(`sessions`),conversationsMs:i(`conversations`),tasksMs:i(`tasks`),artefactsMs:i(`artefacts`),skillsMs:i(`skills`),statsMs:i(`stats`),failed:[...H].filter(e=>n.has(e)).join(`,`)||`none`,ttfbMs:s(a?.responseStart),domContentLoadedMs:c(a?.domContentLoadedEventEnd),loadMs:c(a?.loadEventEnd),assetCount:o.length,assetBytes:o.reduce((e,t)=>e+(t.transferSize||0),0),assetMs:o.length?s(Math.max(...o.map(e=>e.responseEnd))):null}}function W({cacheKey:e,userName:t,onSelectWhatsappConversation:n}){let{zone:r}=i(),a=o(e),[s,f]=(0,T.useState)(null),[m,h]=(0,T.useState)(null),[g,_]=(0,T.useState)(null),[v,y]=(0,T.useState)(null),[x,S]=(0,T.useState)(null),[C,ie]=(0,T.useState)(null),[w,D]=(0,T.useState)(null),[O,k]=(0,T.useState)(null),[A,j]=(0,T.useState)(null),[M,N]=(0,T.useState)(new Set),[P,F]=(0,T.useState)(()=>new Set),I=(0,T.useCallback)(e=>{F(t=>t.has(e)?t:new Set(t).add(e))},[]),H=Date.now(),W=(0,T.useRef)(!1),G=(0,T.useRef)(new Map),me=(0,T.useRef)(new Set),K=(0,T.useRef)(null);(0,T.useEffect)(()=>{if(!e)return;let t=!1;async function n(e,n,r,i){let o=Date.now(),s=typeof n==`string`?n:`unresolved`;try{typeof n!=`string`&&(s=await n());let e=await a(s);if(!e.ok)throw Error(`status ${e.status}`);let o=await e.json();t||i(r(o))}catch(t){me.current.add(e),console.error(`[admin-ui] dashboard-fetch-failed slice=${e} url=${s} ms=${Date.now()-o} reason=${t instanceof Error?t.message:String(t)}`)}finally{G.current.set(e,Date.now()-o),I(e)}}async function r(){if(!K.current){let e=await a(`/api/admin/accounts`);if(!e.ok)throw Error(`accounts status ${e.status}`);let t=await e.json(),n=t.accounts??[],r=t.activeAccountId??null,i=n.find(e=>e.accountId===r);if(!i)throw Error(`accounts: active ${r??`none`} absent from list of ${n.length}`);let o=i.isHouse||n.length===1;K.current={accountId:i.accountId,isHouse:o}}let{accountId:e,isHouse:t}=K.current;return t?`/api/operator-conversations/conversations-all`:`/api/operator-conversations/conversations`}let i={"sidebar-sessions":()=>n(`sessions`,`/api/admin/sidebar-sessions`,e=>e.sessions??[],f),"conversations-all":()=>n(`conversations`,r,e=>e.conversations??[],h),"tasks-list":()=>n(`tasks`,`/api/admin/tasks-list`,e=>e,y),"sidebar-artefacts":()=>n(`artefacts`,`/api/admin/sidebar-artefacts`,e=>e.artefacts??[],S),skills:()=>n(`skills`,`/api/admin/skills`,e=>e.skills??[],ie)};async function o(){if(W.current)return;W.current=!0;let e=Date.now();try{await Promise.all([...Object.values(i).map(e=>e()),n(`stats`,`/api/admin/system-stats`,e=>e,_),n(`bookingLink`,`/api/admin/calendar/booking-link`,e=>e.bookingDomain??null,D),n(`portalLink`,`/api/admin/data-portal/portal-link`,e=>e.portalDomain??null,k),n(`plannerLink`,`/api/admin/dispatch-planner/planner-link`,e=>e.plannerUrl??null,j)])}finally{W.current=!1;let t=Date.now()-e;if(!U){U=!0;try{let e=pe(t,G.current,me.current,typeof performance>`u`?null:performance);fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`event`,source:`dashboard-load`,...e}),keepalive:!0}).catch(()=>{})}catch{}}}}o();let s=null;try{s=new EventSource(l(`/api/admin/events`,e)),s.onmessage=e=>{if(document.visibilityState===`visible`)try{let{resource:t}=JSON.parse(e.data),n=t?i[t]:void 0;n&&n()}catch{}},s.onerror=()=>{console.error(`[admin-ui] dashboard-events stream error`)}}catch(e){console.error(`[admin-ui] dashboard-events unavailable reason=${e instanceof Error?e.message:String(e)}`)}let c=setInterval(()=>{document.visibilityState===`visible`&&o()},se),u=()=>{document.visibilityState===`visible`&&o()};return document.addEventListener(`visibilitychange`,u),()=>{t=!0,W.current=!1,clearInterval(c),s?.close(),document.removeEventListener(`visibilitychange`,u)}},[e,a]);let q=(0,T.useMemo)(()=>(s??[]).filter(e=>!e.isSubagent),[s]),J=(0,T.useMemo)(()=>q.filter(e=>e.live),[q]),he=(0,T.useMemo)(()=>(m??[]).filter(e=>ue(e.lastMessageAt,H,r)).length,[m,H]),ge=v?.open.length??0,Y=(0,T.useMemo)(()=>[...m??[]].sort((e,t)=>{let n=V(e),r=V(t);return n===r?0:r>n?1:-1}),[m]),[X,_e]=(0,T.useState)(!1),Z=X?Y:Y.slice(0,8),ve=Y.length-Z.length,ye=(0,T.useRef)(null),Q=(0,T.useRef)(null);(0,T.useEffect)(()=>{if(!P.has(`conversations`))return;let e=fe(m??[],Y,Z,8,X),t=JSON.stringify(e);ye.current!==t&&(ye.current=t,Q.current===null&&(Q.current=d()),fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`event`,source:`channels-card`,renderId:Q.current,...e})}).catch(()=>{}))},[P,m,Y,Z,X]);let be=(0,T.useRef)(!1);(0,T.useEffect)(()=>{be.current||!P.has(`bookingLink`)||!P.has(`portalLink`)||!P.has(`plannerLink`)||(be.current=!0)},[P,w,O,A]);let xe=(0,T.useCallback)(async e=>{if(!M.has(e)){N(t=>new Set(t).add(e));try{let t=await a(`/api/admin/session-stop`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e})});if(!t.ok){console.error(`[admin-ui] dashboard-session-stop-failed sessionId=${e} status=${t.status}`);return}f(t=>(t??[]).map(t=>t.sessionId===e?{...t,live:!1}:t))}catch(t){console.error(`[admin-ui] dashboard-session-stop-failed sessionId=${e} reason=${t instanceof Error?t.message:String(t)}`)}finally{N(t=>{let n=new Set(t);return n.delete(e),n})}}},[a,M]),Se=(0,T.useCallback)(t=>{if(!e||!t.downloadPath){console.error(`[admin-ui] dashboard-artefact-download-blocked id=${t.id} reason=${e?`not-downloadable`:`no-cache-key`}`);return}oe(e,t.downloadPath,t.downloadRoot??`data`)},[e]),$=ce(new Date(H).getHours());return(0,E.jsxs)(`div`,{className:`ui-page ui-page--full dashboard-home`,children:[(0,E.jsx)(`p`,{className:`dashboard-greeting`,children:P.has(`stats`)?`Good ${$}, ${z(t)} — ${le(g)}`:`Good ${$}, ${z(t)}`}),(0,E.jsxs)(`div`,{className:`dashboard-stats`,children:[(0,E.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,E.jsx)(`span`,{className:`dashboard-stat-label`,children:`Live sessions`}),P.has(`sessions`)?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`span`,{className:`dashboard-stat-value`,children:J.length}),(0,E.jsxs)(`span`,{className:`dashboard-stat-delta`,children:[`of `,q.length,` total`]})]}):(0,E.jsx)(R,{variant:`value`})]}),(0,E.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,E.jsx)(`span`,{className:`dashboard-stat-label`,children:`Messages today`}),P.has(`conversations`)?(0,E.jsx)(`span`,{className:`dashboard-stat-value`,children:he}):(0,E.jsx)(R,{variant:`value`})]}),(0,E.jsxs)(`a`,{className:`admin-stat-card dashboard-stat-card dashboard-stat-card--link`,href:`/tasks`,children:[(0,E.jsx)(`span`,{className:`dashboard-stat-label`,children:`Open tasks`}),P.has(`tasks`)?(0,E.jsx)(`span`,{className:`dashboard-stat-value`,children:ge}):(0,E.jsx)(R,{variant:`value`})]}),(0,E.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,E.jsx)(`span`,{className:`dashboard-stat-label`,children:`Host CPU`}),P.has(`stats`)?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`span`,{className:`dashboard-stat-value`,children:B(g?.cpuPct??null)}),(0,E.jsxs)(`span`,{className:`dashboard-stat-delta`,children:[`RAM `,B(g?.memUsedPct??null)]})]}):(0,E.jsx)(R,{variant:`value`})]})]}),(0,E.jsxs)(`div`,{className:`dashboard-columns`,children:[(0,E.jsxs)(`div`,{className:`dashboard-col`,children:[(w||O||A)&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Public pages`}),(0,E.jsxs)(`div`,{className:`admin-card dashboard-public-pages`,children:[w&&(0,E.jsxs)(`a`,{className:`admin-row dashboard-public-row`,href:`https://${w}`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,E.jsx)(`span`,{className:`dashboard-public-icon`,children:(0,E.jsx)(b,{size:16})}),(0,E.jsx)(`span`,{className:`dashboard-public-name`,children:`Booking page`})]}),O&&(0,E.jsxs)(`a`,{className:`admin-row dashboard-public-row`,href:`https://${O}`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,E.jsx)(`span`,{className:`dashboard-public-icon`,children:(0,E.jsx)(b,{size:16})}),(0,E.jsx)(`span`,{className:`dashboard-public-name`,children:`File drop`})]}),A&&(0,E.jsxs)(`a`,{className:`admin-row dashboard-public-row`,href:A,target:`_blank`,rel:`noopener noreferrer`,children:[(0,E.jsx)(`span`,{className:`dashboard-public-icon`,children:(0,E.jsx)(b,{size:16})}),(0,E.jsx)(`span`,{className:`dashboard-public-name`,children:`Planner`})]})]})]}),(0,E.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Live now`}),P.has(`sessions`)?J.length===0?(0,E.jsx)(`div`,{className:`admin-card dashboard-empty`,children:`No live sessions right now.`}):J.map(e=>{let t=[e.sessionId.slice(0,8),de(e.model),L(Date.parse(e.startedAt),H,r)].filter(Boolean).join(` · `);return(0,E.jsxs)(`div`,{className:`admin-card dashboard-live-card`,children:[(0,E.jsx)(`span`,{className:`admin-status-dot is-live`}),(0,E.jsxs)(`div`,{className:`dashboard-live-main`,children:[(0,E.jsx)(`span`,{className:`dashboard-live-name`,children:e.title}),(0,E.jsx)(`span`,{className:`dashboard-live-meta`,children:t})]}),(0,E.jsx)(`a`,{className:`admin-btn-cta dashboard-open-btn`,href:`/chat?session=${encodeURIComponent(e.sessionId)}`,children:`Open`}),(0,E.jsx)(`button`,{type:`button`,className:`dashboard-stop-btn`,"aria-label":`Stop ${e.title}`,disabled:M.has(e.sessionId),onClick:()=>void xe(e.sessionId),children:(0,E.jsx)(c,{size:12})})]},e.sessionId)}):(0,E.jsx)(R,{variant:`card`,count:2}),(0,E.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Recent artefacts`}),(0,E.jsx)(`div`,{className:`admin-card dashboard-artefacts`,children:P.has(`artefacts`)?(x??[]).length===0?(0,E.jsx)(`div`,{className:`dashboard-empty`,children:`No recent artefacts.`}):(x??[]).slice(0,6).map(e=>(0,E.jsxs)(`button`,{type:`button`,className:`admin-row dashboard-artefact-row`,onClick:()=>Se(e),children:[(0,E.jsx)(`span`,{className:`dashboard-artefact-icon`,children:e.kind===`agent-template`?(0,E.jsx)(re,{size:16}):(0,E.jsx)(ae,{size:16})}),(0,E.jsx)(`div`,{className:`dashboard-artefact-body`,children:(0,E.jsx)(`span`,{className:`dashboard-artefact-name`,children:e.name})}),(0,E.jsx)(`span`,{className:`dashboard-artefact-time`,children:L(Date.parse(e.updatedAt),H,r)})]},e.id)):(0,E.jsx)(R,{count:3})}),(0,E.jsx)(`a`,{className:`admin-section-label dashboard-col-label dashboard-skills-label`,href:`/skills`,children:`Skills`}),(0,E.jsx)(`div`,{className:`admin-card dashboard-skills`,children:P.has(`skills`)?(C??[]).length===0?(0,E.jsx)(`div`,{className:`dashboard-empty`,children:`No skills yet.`}):(C??[]).map(e=>(0,E.jsxs)(`a`,{className:`admin-row dashboard-skill-row`,href:`/skills`,children:[(0,E.jsx)(`span`,{className:`dashboard-skill-icon`,children:(0,E.jsx)(ne,{size:16})}),(0,E.jsxs)(`div`,{className:`dashboard-skill-body`,children:[(0,E.jsx)(`span`,{className:`dashboard-skill-name`,children:e.skill}),(0,E.jsx)(`span`,{className:`dashboard-skill-plugin`,children:e.plugin})]})]},`${e.plugin}/${e.skill}`)):(0,E.jsx)(R,{count:2})})]}),(0,E.jsxs)(`div`,{className:`dashboard-col`,children:[(0,E.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Channels`}),P.has(`conversations`)?Y.length===0?(0,E.jsx)(`div`,{className:`admin-card dashboard-empty`,children:`No channel activity.`}):(0,E.jsxs)(`div`,{className:`admin-card dashboard-channel-card`,children:[(0,E.jsx)(`div`,{className:`dashboard-channel-convs`,children:Z.map(t=>(0,E.jsxs)(`button`,{type:`button`,className:`admin-row dashboard-channel-conv-row`,onClick:()=>n(t),title:t.title,children:[(0,E.jsxs)(`span`,{className:`dashboard-channel-conv-line`,children:[(0,E.jsx)(`span`,{className:`dashboard-channel-conv-glyph`,children:(0,E.jsx)(ee,{channel:t.channel,size:13})}),(0,E.jsx)(te,{accountId:t.accountId??``,jid:t.remoteJid,sessionKey:e??``,className:`dashboard-channel-conv-avatar`,size:16}),(0,E.jsx)(`span`,{className:`dashboard-channel-conv-name`,children:p(t)}),t.isGroup===!0&&(0,E.jsx)(`span`,{className:`dashboard-channel-conv-tag is-group`,children:`Group`}),t.role===`public`&&(0,E.jsx)(`span`,{className:`dashboard-channel-conv-tag is-public`,children:`Public`}),(0,E.jsx)(`span`,{className:`dashboard-channel-conv-tag`,children:t.isHouse?`House`:`Client`}),!t.preview&&t.lastMessageAt&&(0,E.jsx)(`span`,{className:`dashboard-channel-conv-time`,children:L(Date.parse(t.lastMessageAt),H,r)})]}),t.preview?(0,E.jsxs)(`span`,{className:`dashboard-channel-conv-sub`,children:[(0,E.jsx)(`span`,{className:`dashboard-channel-conv-preview`,children:t.preview}),t.lastMessageAt&&(0,E.jsx)(`span`,{className:`dashboard-channel-conv-time`,children:L(Date.parse(t.lastMessageAt),H,r)})]}):null]},u(t)))}),ve>0&&(0,E.jsxs)(`button`,{type:`button`,className:`dashboard-channel-more`,onClick:()=>_e(!0),children:[`Show `,ve,` more`]})]}):(0,E.jsx)(R,{variant:`card`,count:2})]})]})]})}function G(){let e=m(),[t,n]=(0,T.useState)(!1);(0,T.useEffect)(()=>{if(!t)return;let e=e=>{e.key===`Escape`&&n(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let r=(0,T.useCallback)(async()=>{let t=e.claudeInfo!=null;if(n(!0),t)return;let r=Date.now();if(!e.cacheKey){console.error(`[admin-ui] claude-info-fetch-skipped reason=no-session-key`);return}try{let t=await fetch(`/api/admin/claude-info?session_key=${encodeURIComponent(e.cacheKey)}`);if(t.ok){let n=await t.json();e.setClaudeInfo(n)}}catch(e){console.error(`[admin-ui] claude-info-fetch-failed ms=${Date.now()-r} error="${e instanceof Error?e.message:String(e)}"`)}},[e]),i=(0,T.useCallback)(({code:t,path:n})=>{console.warn(`[admin-auth] outcome=chat-tab-logout-on-401 code=${t} path=${n}`),e.handleLogout()},[e]);return e.appState===`chat`?(0,E.jsx)(s,{cacheKey:e.cacheKey,onSessionExpired:i,surface:`chat`,children:(0,E.jsx)(y,{cacheKey:e.cacheKey,businessName:e.businessName,sessionId:e.sessionId,onLogout:e.handleLogout,onDisconnect:e.handleDisconnect,disconnecting:e.disconnecting,claudeConnected:e.claudeConnected,onConnectClaude:()=>e.setAppState(`connect-claude`),userName:e.userName,userAvatar:e.userAvatar,role:e.role,footer:(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(D,{onOpen:r}),(0,E.jsx)(v,{show:t,onClose:()=>n(!1),claudeInfo:e.claudeInfo,messages:[],sessionElapsed:0,sessionId:e.sessionId,cacheKey:e.cacheKey})]}),children:t=>(0,E.jsx)(E.Fragment,{children:t.dataOpen&&e.cacheKey?(0,E.jsx)(C,{cacheKey:e.cacheKey}):t.selectedWhatsapp&&e.cacheKey?t.selectedWhatsapp.source===`store`&&t.selectedWhatsapp.channel===`telegram`&&t.selectedWhatsapp.channelKey&&t.selectedWhatsapp.accountId?(0,E.jsx)(S,{accountId:t.selectedWhatsapp.accountId,channelKey:t.selectedWhatsapp.channelKey,contactName:p(t.selectedWhatsapp),sessionKey:e.cacheKey,onBack:t.onClearWhatsapp},u(t.selectedWhatsapp)):t.selectedWhatsapp.source===`store`&&t.selectedWhatsapp.remoteJid&&t.selectedWhatsapp.accountId?(0,E.jsx)(ie,{accountId:t.selectedWhatsapp.accountId,remoteJid:t.selectedWhatsapp.remoteJid,contactName:p(t.selectedWhatsapp),sessionKey:e.cacheKey,onBack:t.onClearWhatsapp},u(t.selectedWhatsapp)):(0,E.jsx)(O,{sessionId:t.selectedWhatsapp.sessionId,projectDir:t.selectedWhatsapp.projectDir,sessionKey:e.cacheKey,contactName:p(t.selectedWhatsapp),onBack:t.onClearWhatsapp},u(t.selectedWhatsapp)):(0,E.jsx)(W,{cacheKey:e.cacheKey,userName:e.userName,onSelectWhatsappConversation:t.onSelectWhatsappConversation})})})}):(0,E.jsx)(h,{auth:e})}(0,w.createRoot)(document.getElementById(`root`)).render((0,E.jsx)(G,{}));