@rubytech/create-sitedesk-code 0.1.529 → 0.1.530

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 (250) hide show
  1. package/dist/index.js +13 -0
  2. package/package.json +1 -1
  3. package/payload/platform/lib/routine-templates/dist/index.d.ts +19 -3
  4. package/payload/platform/lib/routine-templates/dist/index.d.ts.map +1 -1
  5. package/payload/platform/lib/routine-templates/dist/index.js +22 -4
  6. package/payload/platform/lib/routine-templates/dist/index.js.map +1 -1
  7. package/payload/platform/lib/routine-templates/dist/roster.d.ts +19 -6
  8. package/payload/platform/lib/routine-templates/dist/roster.d.ts.map +1 -1
  9. package/payload/platform/lib/routine-templates/dist/roster.js +127 -17
  10. package/payload/platform/lib/routine-templates/dist/roster.js.map +1 -1
  11. package/payload/platform/lib/routine-templates/src/__tests__/roster.test.ts +46 -3
  12. package/payload/platform/lib/routine-templates/src/__tests__/seed.test.ts +52 -10
  13. package/payload/platform/lib/routine-templates/src/index.ts +30 -4
  14. package/payload/platform/lib/routine-templates/src/roster.ts +147 -17
  15. package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +7 -3
  16. package/payload/platform/plugins/admin/skills/whats-new/SKILL.md +6 -0
  17. package/payload/platform/plugins/docs/references/admin-ui.md +6 -2
  18. package/payload/platform/plugins/scheduling/PLUGIN.md +2 -0
  19. package/payload/platform/plugins/scheduling/mcp/dist/index.js +5 -0
  20. package/payload/platform/plugins/scheduling/mcp/dist/index.js.map +1 -1
  21. package/payload/platform/plugins/scheduling/mcp/dist/lib/__tests__/normalise-start-date.test.d.ts +2 -0
  22. package/payload/platform/plugins/scheduling/mcp/dist/lib/__tests__/normalise-start-date.test.d.ts.map +1 -0
  23. package/payload/platform/plugins/scheduling/mcp/dist/lib/__tests__/normalise-start-date.test.js +100 -0
  24. package/payload/platform/plugins/scheduling/mcp/dist/lib/__tests__/normalise-start-date.test.js.map +1 -0
  25. package/payload/platform/plugins/scheduling/mcp/dist/lib/dispatcher-env.d.ts +36 -0
  26. package/payload/platform/plugins/scheduling/mcp/dist/lib/dispatcher-env.d.ts.map +1 -0
  27. package/payload/platform/plugins/scheduling/mcp/dist/lib/dispatcher-env.js +82 -0
  28. package/payload/platform/plugins/scheduling/mcp/dist/lib/dispatcher-env.js.map +1 -0
  29. package/payload/platform/plugins/scheduling/mcp/dist/lib/time-format.d.ts +31 -0
  30. package/payload/platform/plugins/scheduling/mcp/dist/lib/time-format.d.ts.map +1 -1
  31. package/payload/platform/plugins/scheduling/mcp/dist/lib/time-format.js +99 -0
  32. package/payload/platform/plugins/scheduling/mcp/dist/lib/time-format.js.map +1 -1
  33. package/payload/platform/plugins/scheduling/mcp/dist/scripts/__tests__/agent-turn-dispatch.test.js +12 -12
  34. package/payload/platform/plugins/scheduling/mcp/dist/scripts/__tests__/agent-turn-dispatch.test.js.map +1 -1
  35. package/payload/platform/plugins/scheduling/mcp/dist/scripts/__tests__/converge-startdate-utc.test.d.ts +2 -0
  36. package/payload/platform/plugins/scheduling/mcp/dist/scripts/__tests__/converge-startdate-utc.test.d.ts.map +1 -0
  37. package/payload/platform/plugins/scheduling/mcp/dist/scripts/__tests__/converge-startdate-utc.test.js +79 -0
  38. package/payload/platform/plugins/scheduling/mcp/dist/scripts/__tests__/converge-startdate-utc.test.js.map +1 -0
  39. package/payload/platform/plugins/scheduling/mcp/dist/scripts/__tests__/dispatch-lateness.test.d.ts +2 -0
  40. package/payload/platform/plugins/scheduling/mcp/dist/scripts/__tests__/dispatch-lateness.test.d.ts.map +1 -0
  41. package/payload/platform/plugins/scheduling/mcp/dist/scripts/__tests__/dispatch-lateness.test.js +23 -0
  42. package/payload/platform/plugins/scheduling/mcp/dist/scripts/__tests__/dispatch-lateness.test.js.map +1 -0
  43. package/payload/platform/plugins/scheduling/mcp/dist/scripts/__tests__/routine-roster-audit.test.js +61 -1
  44. package/payload/platform/plugins/scheduling/mcp/dist/scripts/__tests__/routine-roster-audit.test.js.map +1 -1
  45. package/payload/platform/plugins/scheduling/mcp/dist/scripts/agent-turn-dispatch.d.ts +33 -1
  46. package/payload/platform/plugins/scheduling/mcp/dist/scripts/agent-turn-dispatch.d.ts.map +1 -1
  47. package/payload/platform/plugins/scheduling/mcp/dist/scripts/agent-turn-dispatch.js +96 -7
  48. package/payload/platform/plugins/scheduling/mcp/dist/scripts/agent-turn-dispatch.js.map +1 -1
  49. package/payload/platform/plugins/scheduling/mcp/dist/scripts/check-due-events.js +21 -69
  50. package/payload/platform/plugins/scheduling/mcp/dist/scripts/check-due-events.js.map +1 -1
  51. package/payload/platform/plugins/scheduling/mcp/dist/scripts/converge-startdate-utc.d.ts +24 -0
  52. package/payload/platform/plugins/scheduling/mcp/dist/scripts/converge-startdate-utc.d.ts.map +1 -0
  53. package/payload/platform/plugins/scheduling/mcp/dist/scripts/converge-startdate-utc.js +87 -0
  54. package/payload/platform/plugins/scheduling/mcp/dist/scripts/converge-startdate-utc.js.map +1 -0
  55. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-event-startdate.test.d.ts +2 -0
  56. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-event-startdate.test.d.ts.map +1 -0
  57. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-event-startdate.test.js +123 -0
  58. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-event-startdate.test.js.map +1 -0
  59. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-update-startdate.test.d.ts +2 -0
  60. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-update-startdate.test.d.ts.map +1 -0
  61. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-update-startdate.test.js +71 -0
  62. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-update-startdate.test.js.map +1 -0
  63. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-update-status.test.js +14 -3
  64. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-update-status.test.js.map +1 -1
  65. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-event.d.ts +9 -0
  66. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-event.d.ts.map +1 -1
  67. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-event.js +19 -3
  68. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-event.js.map +1 -1
  69. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-update.d.ts.map +1 -1
  70. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-update.js +24 -9
  71. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-update.js.map +1 -1
  72. package/payload/server/{chunk-UTIHI6KV.js → chunk-2YMGNYA3.js} +12 -12
  73. package/payload/server/{manager-B4LRDZKC.js → manager-XPRN5UF5.js} +1 -1
  74. package/payload/server/package.json +1 -1
  75. package/payload/server/public/activity.html +5 -5
  76. package/payload/server/public/agents.html +4 -4
  77. package/payload/server/public/assets/{AdminLoginScreens-zfexKfbT.js → AdminLoginScreens-7Czw3MAC.js} +1 -1
  78. package/payload/server/public/assets/AdminLoginScreens-7Czw3MAC.js.br +0 -0
  79. package/payload/server/public/assets/AdminLoginScreens-7Czw3MAC.js.gz +0 -0
  80. package/payload/server/public/assets/{AdminShell-Cbk0TL1B.js → AdminShell-D5GApZ_n.js} +1 -1
  81. package/payload/server/public/assets/AdminShell-D5GApZ_n.js.br +0 -0
  82. package/payload/server/public/assets/AdminShell-D5GApZ_n.js.gz +0 -0
  83. package/payload/server/public/assets/{CdpScreencastSurface-CLSQHh4e.js → CdpScreencastSurface-BbekDUFw.js} +1 -1
  84. package/payload/server/public/assets/CdpScreencastSurface-BbekDUFw.js.br +0 -0
  85. package/payload/server/public/assets/CdpScreencastSurface-BbekDUFw.js.gz +0 -0
  86. package/payload/server/public/assets/{activity-u275Oc-u.js → activity-ClI-RgJu.js} +1 -1
  87. package/payload/server/public/assets/activity-ClI-RgJu.js.br +0 -0
  88. package/payload/server/public/assets/activity-ClI-RgJu.js.gz +0 -0
  89. package/payload/server/public/assets/{admin-Du1nR_hP.js → admin-svtCmBPk.js} +1 -1
  90. package/payload/server/public/assets/admin-svtCmBPk.js.br +0 -0
  91. package/payload/server/public/assets/admin-svtCmBPk.js.gz +0 -0
  92. package/payload/server/public/assets/{agents-DJTxRLLU.js → agents-BO8YBj8d.js} +1 -1
  93. package/payload/server/public/assets/agents-BO8YBj8d.js.br +0 -0
  94. package/payload/server/public/assets/agents-BO8YBj8d.js.gz +0 -0
  95. package/payload/server/public/assets/{browser-Bft6zVkX.js → browser-Bj8oTG5R.js} +1 -1
  96. package/payload/server/public/assets/browser-Bj8oTG5R.js.br +0 -0
  97. package/payload/server/public/assets/browser-Bj8oTG5R.js.gz +0 -0
  98. package/payload/server/public/assets/{calendar-Ct-DCCqY.js → calendar-CrkSY8U7.js} +1 -1
  99. package/payload/server/public/assets/calendar-CrkSY8U7.js.br +0 -0
  100. package/payload/server/public/assets/calendar-CrkSY8U7.js.gz +0 -0
  101. package/payload/server/public/assets/chat-Bvxoni2e.js +1 -0
  102. package/payload/server/public/assets/chat-Bvxoni2e.js.br +0 -0
  103. package/payload/server/public/assets/chat-Bvxoni2e.js.gz +0 -0
  104. package/payload/server/public/assets/chevron-left-CdUzxzeB.js +1 -0
  105. package/payload/server/public/assets/chevron-left-CdUzxzeB.js.br +0 -0
  106. package/payload/server/public/assets/chevron-right-CKGwd-M0.js +1 -0
  107. package/payload/server/public/assets/chevron-right-CKGwd-M0.js.br +0 -0
  108. package/payload/server/public/assets/clock-Cf8Oe9qi.js +1 -0
  109. package/payload/server/public/assets/clock-Cf8Oe9qi.js.br +0 -0
  110. package/payload/server/public/assets/clock-Cf8Oe9qi.js.gz +0 -0
  111. package/payload/server/public/assets/data-DF0Pstdp.js +1 -0
  112. package/payload/server/public/assets/data-DF0Pstdp.js.br +1 -0
  113. package/payload/server/public/assets/data-DF0Pstdp.js.gz +0 -0
  114. package/payload/server/public/assets/{file-download-C_fSe4dm.js → file-download-Di_s0_4w.js} +1 -1
  115. package/payload/server/public/assets/file-download-Di_s0_4w.js.br +0 -0
  116. package/payload/server/public/assets/file-download-Di_s0_4w.js.gz +0 -0
  117. package/payload/server/public/assets/{file-text-D7GbEcqj.js → file-text-CP1KIrJV.js} +1 -1
  118. package/payload/server/public/assets/file-text-CP1KIrJV.js.br +1 -0
  119. package/payload/server/public/assets/file-text-CP1KIrJV.js.gz +0 -0
  120. package/payload/server/public/assets/{graph-yl5qU1kO.js → graph-BCMscnCV.js} +1 -1
  121. package/payload/server/public/assets/graph-BCMscnCV.js.br +0 -0
  122. package/payload/server/public/assets/graph-BCMscnCV.js.gz +0 -0
  123. package/payload/server/public/assets/{graph-labels-Dlcb6cW7.js → graph-labels-CgP17xHK.js} +1 -1
  124. package/payload/server/public/assets/graph-labels-CgP17xHK.js.br +0 -0
  125. package/payload/server/public/assets/graph-labels-CgP17xHK.js.gz +0 -0
  126. package/payload/server/public/assets/{maximize-2-BS689r4W.js → maximize-2-DkQzDv-g.js} +1 -1
  127. package/payload/server/public/assets/maximize-2-DkQzDv-g.js.br +0 -0
  128. package/payload/server/public/assets/maximize-2-DkQzDv-g.js.gz +0 -0
  129. package/payload/server/public/assets/{operator-CvapnpIW.js → operator-CLbCar9e.js} +1 -1
  130. package/payload/server/public/assets/operator-CLbCar9e.js.br +0 -0
  131. package/payload/server/public/assets/operator-CLbCar9e.js.gz +0 -0
  132. package/payload/server/public/assets/{page-DWkUH4Z_.js → page-CNJl3tWT.js} +1 -1
  133. package/payload/server/public/assets/page-CNJl3tWT.js.br +0 -0
  134. package/payload/server/public/assets/page-CNJl3tWT.js.gz +0 -0
  135. package/payload/server/public/assets/{page-987y4JbQ.js → page-CPVUAwb8.js} +1 -1
  136. package/payload/server/public/assets/page-CPVUAwb8.js.br +0 -0
  137. package/payload/server/public/assets/page-CPVUAwb8.js.gz +0 -0
  138. package/payload/server/public/assets/{public-D5pi-VFn.js → public-DQea3Ybz.js} +1 -1
  139. package/payload/server/public/assets/public-DQea3Ybz.js.br +0 -0
  140. package/payload/server/public/assets/public-DQea3Ybz.js.gz +0 -0
  141. package/payload/server/public/assets/{rotate-ccw-zNxnK36R.js → rotate-ccw-DPw0vXC0.js} +1 -1
  142. package/payload/server/public/assets/rotate-ccw-DPw0vXC0.js.br +0 -0
  143. package/payload/server/public/assets/rotate-ccw-DPw0vXC0.js.gz +0 -0
  144. package/payload/server/public/assets/{routines-mZzrGA5y.js → routines-CwiiYpfK.js} +2 -2
  145. package/payload/server/public/assets/routines-CwiiYpfK.js.br +0 -0
  146. package/payload/server/public/assets/routines-CwiiYpfK.js.gz +0 -0
  147. package/payload/server/public/assets/{skills-5A8PockT.js → skills-0FOjKUM-.js} +1 -1
  148. package/payload/server/public/assets/skills-0FOjKUM-.js.br +0 -0
  149. package/payload/server/public/assets/skills-0FOjKUM-.js.gz +0 -0
  150. package/payload/server/public/assets/{tasks-B1_2wc6L.js → tasks-BUVsPEGm.js} +1 -1
  151. package/payload/server/public/assets/tasks-BUVsPEGm.js.br +0 -0
  152. package/payload/server/public/assets/tasks-BUVsPEGm.js.gz +0 -0
  153. package/payload/server/public/assets/{time-entry-format-CJ2FSSQt.js → time-entry-format-B6fX_19a.js} +1 -1
  154. package/payload/server/public/assets/time-entry-format-B6fX_19a.js.br +0 -0
  155. package/payload/server/public/assets/time-entry-format-B6fX_19a.js.gz +0 -0
  156. package/payload/server/public/assets/{triangle-alert-CedsrgME.js → triangle-alert-vAaSDhVq.js} +1 -1
  157. package/payload/server/public/assets/triangle-alert-vAaSDhVq.js.br +0 -0
  158. package/payload/server/public/assets/triangle-alert-vAaSDhVq.js.gz +0 -0
  159. package/payload/server/public/assets/{useCopyFeedback-zjZZUC2-.js → useCopyFeedback-BvIRgs7W.js} +1 -1
  160. package/payload/server/public/assets/useCopyFeedback-BvIRgs7W.js.br +0 -0
  161. package/payload/server/public/assets/useCopyFeedback-BvIRgs7W.js.gz +0 -0
  162. package/payload/server/public/assets/{useSubAccountSwitcher-72THldvm.css → useSubAccountSwitcher-DM5Y9eio.css} +1 -1
  163. package/payload/server/public/assets/useSubAccountSwitcher-DM5Y9eio.css.br +0 -0
  164. package/payload/server/public/assets/{useSubAccountSwitcher-72THldvm.css.gz → useSubAccountSwitcher-DM5Y9eio.css.gz} +0 -0
  165. package/payload/server/public/assets/{useVoiceRecorder-CJecnefX.js → useVoiceRecorder-CiDOh8PG.js} +1 -1
  166. package/payload/server/public/assets/useVoiceRecorder-CiDOh8PG.js.br +0 -0
  167. package/payload/server/public/assets/useVoiceRecorder-CiDOh8PG.js.gz +0 -0
  168. package/payload/server/public/assets/{wrench-D8BH20W8.js → wrench-BNBtwT2p.js} +1 -1
  169. package/payload/server/public/assets/wrench-BNBtwT2p.js.br +0 -0
  170. package/payload/server/public/assets/wrench-BNBtwT2p.js.gz +0 -0
  171. package/payload/server/public/browser.html +5 -5
  172. package/payload/server/public/calendar.html +7 -7
  173. package/payload/server/public/chat.html +13 -13
  174. package/payload/server/public/data.html +12 -12
  175. package/payload/server/public/graph.html +9 -9
  176. package/payload/server/public/index.html +16 -16
  177. package/payload/server/public/operator.html +15 -15
  178. package/payload/server/public/public.html +13 -13
  179. package/payload/server/public/routines.html +7 -7
  180. package/payload/server/public/skills.html +5 -5
  181. package/payload/server/public/tasks.html +6 -6
  182. package/payload/server/server.js +10 -4
  183. package/payload/server/public/assets/AdminLoginScreens-zfexKfbT.js.br +0 -0
  184. package/payload/server/public/assets/AdminLoginScreens-zfexKfbT.js.gz +0 -0
  185. package/payload/server/public/assets/AdminShell-Cbk0TL1B.js.br +0 -0
  186. package/payload/server/public/assets/AdminShell-Cbk0TL1B.js.gz +0 -0
  187. package/payload/server/public/assets/CdpScreencastSurface-CLSQHh4e.js.br +0 -0
  188. package/payload/server/public/assets/CdpScreencastSurface-CLSQHh4e.js.gz +0 -0
  189. package/payload/server/public/assets/activity-u275Oc-u.js.br +0 -0
  190. package/payload/server/public/assets/activity-u275Oc-u.js.gz +0 -0
  191. package/payload/server/public/assets/admin-Du1nR_hP.js.br +0 -0
  192. package/payload/server/public/assets/admin-Du1nR_hP.js.gz +0 -0
  193. package/payload/server/public/assets/agents-DJTxRLLU.js.br +0 -0
  194. package/payload/server/public/assets/agents-DJTxRLLU.js.gz +0 -0
  195. package/payload/server/public/assets/browser-Bft6zVkX.js.br +0 -0
  196. package/payload/server/public/assets/browser-Bft6zVkX.js.gz +0 -0
  197. package/payload/server/public/assets/calendar-Ct-DCCqY.js.br +0 -0
  198. package/payload/server/public/assets/calendar-Ct-DCCqY.js.gz +0 -0
  199. package/payload/server/public/assets/chat-pqasbAg8.js +0 -1
  200. package/payload/server/public/assets/chat-pqasbAg8.js.br +0 -0
  201. package/payload/server/public/assets/chat-pqasbAg8.js.gz +0 -0
  202. package/payload/server/public/assets/chevron-left-C8LTc7lb.js +0 -1
  203. package/payload/server/public/assets/chevron-right-Lz9t7Hed.js +0 -1
  204. package/payload/server/public/assets/chevron-right-Lz9t7Hed.js.br +0 -0
  205. package/payload/server/public/assets/clock-D6QQFHwJ.js +0 -1
  206. package/payload/server/public/assets/clock-D6QQFHwJ.js.br +0 -0
  207. package/payload/server/public/assets/clock-D6QQFHwJ.js.gz +0 -0
  208. package/payload/server/public/assets/data-B1JJ3Y1T.js +0 -1
  209. package/payload/server/public/assets/data-B1JJ3Y1T.js.br +0 -0
  210. package/payload/server/public/assets/data-B1JJ3Y1T.js.gz +0 -0
  211. package/payload/server/public/assets/file-download-C_fSe4dm.js.br +0 -0
  212. package/payload/server/public/assets/file-download-C_fSe4dm.js.gz +0 -0
  213. package/payload/server/public/assets/file-text-D7GbEcqj.js.br +0 -0
  214. package/payload/server/public/assets/file-text-D7GbEcqj.js.gz +0 -0
  215. package/payload/server/public/assets/graph-labels-Dlcb6cW7.js.br +0 -0
  216. package/payload/server/public/assets/graph-labels-Dlcb6cW7.js.gz +0 -0
  217. package/payload/server/public/assets/graph-yl5qU1kO.js.br +0 -0
  218. package/payload/server/public/assets/graph-yl5qU1kO.js.gz +0 -0
  219. package/payload/server/public/assets/maximize-2-BS689r4W.js.br +0 -0
  220. package/payload/server/public/assets/maximize-2-BS689r4W.js.gz +0 -0
  221. package/payload/server/public/assets/operator-CvapnpIW.js.br +0 -0
  222. package/payload/server/public/assets/operator-CvapnpIW.js.gz +0 -0
  223. package/payload/server/public/assets/page-987y4JbQ.js.br +0 -0
  224. package/payload/server/public/assets/page-987y4JbQ.js.gz +0 -0
  225. package/payload/server/public/assets/page-DWkUH4Z_.js.br +0 -0
  226. package/payload/server/public/assets/page-DWkUH4Z_.js.gz +0 -0
  227. package/payload/server/public/assets/public-D5pi-VFn.js.br +0 -0
  228. package/payload/server/public/assets/public-D5pi-VFn.js.gz +0 -0
  229. package/payload/server/public/assets/rotate-ccw-zNxnK36R.js.br +0 -0
  230. package/payload/server/public/assets/rotate-ccw-zNxnK36R.js.gz +0 -0
  231. package/payload/server/public/assets/routines-mZzrGA5y.js.br +0 -0
  232. package/payload/server/public/assets/routines-mZzrGA5y.js.gz +0 -0
  233. package/payload/server/public/assets/skills-5A8PockT.js.br +0 -0
  234. package/payload/server/public/assets/skills-5A8PockT.js.gz +0 -0
  235. package/payload/server/public/assets/tasks-B1_2wc6L.js.br +0 -0
  236. package/payload/server/public/assets/tasks-B1_2wc6L.js.gz +0 -0
  237. package/payload/server/public/assets/time-entry-format-CJ2FSSQt.js.br +0 -0
  238. package/payload/server/public/assets/time-entry-format-CJ2FSSQt.js.gz +0 -0
  239. package/payload/server/public/assets/triangle-alert-CedsrgME.js.br +0 -0
  240. package/payload/server/public/assets/triangle-alert-CedsrgME.js.gz +0 -0
  241. package/payload/server/public/assets/useCopyFeedback-zjZZUC2-.js.br +0 -0
  242. package/payload/server/public/assets/useCopyFeedback-zjZZUC2-.js.gz +0 -0
  243. package/payload/server/public/assets/useSubAccountSwitcher-72THldvm.css.br +0 -0
  244. package/payload/server/public/assets/useVoiceRecorder-CJecnefX.js.br +0 -0
  245. package/payload/server/public/assets/useVoiceRecorder-CJecnefX.js.gz +0 -0
  246. package/payload/server/public/assets/wrench-D8BH20W8.js.br +0 -0
  247. package/payload/server/public/assets/wrench-D8BH20W8.js.gz +0 -0
  248. /package/payload/server/public/assets/{useSubAccountSwitcher-HjQZjJBr.js → useSubAccountSwitcher-BEwQMRMo.js} +0 -0
  249. /package/payload/server/public/assets/{useSubAccountSwitcher-HjQZjJBr.js.br → useSubAccountSwitcher-BEwQMRMo.js.br} +0 -0
  250. /package/payload/server/public/assets/{useSubAccountSwitcher-HjQZjJBr.js.gz → useSubAccountSwitcher-BEwQMRMo.js.gz} +0 -0
@@ -1,2 +1,2 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{A as t,C as n,D as r,E as i,F as a,H as o,I as s,J as c,L as l,M as u,N as d,O as f,R as p,T as m,U as h,V as g,a as _,b as ee,f as v,g as y,h as te,j as b,k as x,m as S,o as ne,p as re,q as C,r as ie,t as ae,v as oe,w as se,x as w,y as ce,z as le}from"./useSubAccountSwitcher-HjQZjJBr.js";async function ue(){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 T=o();function de({checked:e,onChange:t,label:n,disabled:r,ariaLabel:i=n}){return(0,T.jsxs)(`label`,{className:`maxy-checkbox${r?` maxy-checkbox--disabled`:``}`,children:[(0,T.jsx)(`input`,{type:`checkbox`,"aria-label":i,checked:e,onChange:e=>t(e.target.checked),disabled:r}),(0,T.jsx)(`span`,{className:`maxy-checkbox__box`,children:`✱`}),n&&(0,T.jsx)(`span`,{className:`maxy-checkbox__label`,children:n})]})}var E=e(c(),1),D={sm:14,md:16,lg:18},fe={sm:30,md:38,lg:46};function O({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=D[t],g={...e===`send`?{width:fe[t],height:fe[t]}:{},...d},_=Object.keys(g).length>0;return(0,T.jsxs)(`button`,{type:s,className:m,disabled:i||o,onClick:c,"aria-label":l,"aria-pressed":u,style:_?g:void 0,children:[(0,T.jsxs)(`span`,{className:`btn__content`,style:{visibility:i?`hidden`:`visible`},children:[n&&r===`leading`&&(0,T.jsx)(n,{size:h}),p,n&&r===`trailing`&&(0,T.jsx)(n,{size:h})]}),i&&(0,T.jsx)(`span`,{className:`btn__spinner`,children:`✱`})]})}var pe=l(`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`}]]),me=l(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),he=l(`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`}]]),ge=l(`chevron-down`,[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]),_e=l(`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`}]]),ve=l(`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`}]]),k=l(`gauge`,[[`path`,{d:`m12 14 4-4`,key:`9kzdfg`}],[`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`,key:`19p75a`}]]),ye=l(`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`}]]),be=l(`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`}]]),A=l(`panel-left`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}]]),xe=l(`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`}]]),Se=l(`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`}]]),Ce=l(`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`}]]),we=l(`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`}]]),Te=5e3,Ee=1200;function De(e){return Math.max(Ee,Math.round(Te/(e<1?1:e)))}var Oe=500,j=new Set;function M(e,t,n){let r=n??(typeof globalThis.fetch==`function`?globalThis.fetch:void 0);if(j.has(e)||!r)return!1;if(j.size>=Oe){for(let e of j)if(j.delete(e),j.size<Oe)break}j.add(e);try{Promise.resolve(r(`/api/admin/events`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({event:`wa-notify:rendered`,fields:{msgId:e,senderType:t}})})).catch(()=>{})}catch{}return!0}function ke({type:e}){return e===`admin`?(0,T.jsx)(`svg`,{className:`wa-notify-icon`,viewBox:`0 0 16 16`,"aria-hidden":`true`,children:(0,T.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,T.jsx)(`svg`,{className:`wa-notify-icon`,viewBox:`0 0 16 16`,"aria-hidden":`true`,children:(0,T.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,T.jsx)(`svg`,{className:`wa-notify-icon`,viewBox:`0 0 16 16`,"aria-hidden":`true`,children:(0,T.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,T.jsx)(`svg`,{className:`wa-notify-icon`,viewBox:`0 0 16 16`,"aria-hidden":`true`,children:(0,T.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 Ae({frames:e,onExpire:t}){let n=(0,E.useRef)(new Map),r=(0,E.useRef)(new Map);return(0,E.useEffect)(()=>{let i=Date.now(),a=De(e.length),o=new Set(e.map(e=>e.waMessageId));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.waMessageId;n.current.has(e)||(n.current.set(e,i),M(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,T.jsx)(`div`,{className:`wa-notify-host`,children:[...e].reverse().map(e=>(0,T.jsxs)(`div`,{className:`wa-notify-card`,role:`status`,children:[(0,T.jsxs)(`div`,{className:`wa-notify-head`,children:[(0,T.jsx)(`span`,{className:`wa-notify-pill wa-notify-pill-${e.senderType}`,children:(0,T.jsx)(ke,{type:e.senderType})}),(0,T.jsx)(`span`,{className:`wa-notify-account`,children:e.accountName})]}),(0,T.jsx)(`div`,{className:`wa-notify-sender`,children:e.senderDisplay}),(0,T.jsxs)(`div`,{className:`wa-notify-body`,children:[e.body,e.truncated?`…`:``]})]},e.waMessageId))})}var je=`wa-notify`;function Me({connected:e,onConnectClaude:t}){return e?(0,T.jsxs)(`span`,{className:`claude-status-pill`,"data-connected":`true`,title:`Claude is connected`,children:[(0,T.jsx)(`img`,{src:`/brand/claude.png`,alt:``,className:`claude-status-pill__mark`}),(0,T.jsx)(`span`,{className:`claude-status-pill__label`,children:`Connected`}),(0,T.jsx)(`span`,{className:`claude-status-pill__dot claude-status-pill__dot--live`,"aria-hidden":`true`})]}):(0,T.jsxs)(`button`,{type:`button`,className:`claude-status-pill claude-status-pill--action`,"data-connected":`false`,onClick:t,title:`Connect Claude`,children:[(0,T.jsx)(`img`,{src:`/brand/claude.png`,alt:``,className:`claude-status-pill__mark`}),(0,T.jsx)(`span`,{className:`claude-status-pill__label`,children:`Connect`}),(0,T.jsx)(`span`,{className:`claude-status-pill__dot claude-status-pill__dot--down`,"aria-hidden":`true`})]})}function Ne(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 Pe({title:e,sidebarOpen:t,onToggleSidebar:n,claudeConnected:i,onConnectClaude:a}){let o=e??Ne(typeof window<`u`?window.location.pathname:`/`),s=i!==void 0&&a!==void 0;return(0,T.jsxs)(`header`,{className:`admin-page-header`,children:[(0,T.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,T.jsx)(A,{className:`admin-page-header__toggle-desktop`,size:18,strokeWidth:1.75}),(0,T.jsx)(r,{className:`admin-page-header__toggle-mobile`,size:22,strokeWidth:1.75})]}),(0,T.jsx)(`h1`,{className:`admin-page-header__title`,children:o}),s&&(0,T.jsx)(`div`,{className:`admin-page-header__right`,children:(0,T.jsx)(Me,{connected:i,onConnectClaude:a})})]})}var Fe=[{label:`Home`,href:`/`,Icon:x,match:e=>e===`/`||e===``},{label:`Chat`,href:`/chat`,Icon:i,match:e=>e.startsWith(`/chat`)},{label:`Tasks`,href:`/tasks`,Icon:ye,match:e=>e.startsWith(`/tasks`)},{label:`Data`,href:`/data`,Icon:d,match:e=>e.startsWith(`/data`)},{label:`Calendar`,href:`/calendar`,Icon:a,match:e=>e.startsWith(`/calendar`)}],Ie=[{label:`Chat`,href:`/`,Icon:i,match:e=>e===`/`||e===``||e.startsWith(`/chat`)},{label:`Data`,href:`/data`,Icon:d,match:e=>e.startsWith(`/data`)}];function Le(e){let t=Fe.find(t=>t.match(e));return t?t.href:`/`}function N({variant:e=`admin`,onOpenConversations:t}={}){let n=typeof window<`u`?window.location.pathname:`/`,r=e===`operator`?Ie:Fe,a=e===`operator`?Ie.find(e=>e.match(n))?.href??`/`:Le(n),o=e=>{let t=e.href===a,{Icon:n}=e;return(0,T.jsxs)(`a`,{href:e.href,className:`bottom-tab${t?` is-active`:``}`,"aria-current":t?`page`:void 0,children:[(0,T.jsx)(n,{size:19,strokeWidth:1.75}),(0,T.jsx)(`span`,{className:`bottom-tab__label`,children:e.label})]},e.href)};return(0,T.jsxs)(`nav`,{className:`bottom-tab-bar`,"aria-label":`Primary`,children:[r.slice(0,1).map(o),e===`operator`&&t&&(0,T.jsxs)(`button`,{type:`button`,className:`bottom-tab`,onClick:t,children:[(0,T.jsx)(i,{size:19,strokeWidth:1.75}),(0,T.jsx)(`span`,{className:`bottom-tab__label`,children:`Conversations`})]}),r.slice(1).map(o)]})}var P=`thicknessPx=- lengthPx=- color=- opacity=- boxPx=- painted=false source=unavailable`;function Re(e){let t=parseFloat(e);return Number.isFinite(t)?t:null}function F(e,t,n,r){return e<=0||t<=0||r<=0||n===`transparent`?!1:!/rgba\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*,\s*0\s*\)/.test(n)}function ze(e,t){let n=`[admin-ui] op=resize-grip-audit surface=${e}`;if(!t)return`${n} ${P}`;let r=Re(t.width),i=Re(t.height),a=Re(t.hostOpacity),o=Re(t.pillOpacity);if(r===null||i===null||a===null||o===null||!t.backgroundColor)return`${n} ${P}`;let s=Math.round(a*o*1e3)/1e3,c=F(r,i,t.backgroundColor,s);return`${n} thicknessPx=${r} lengthPx=${i} color=${t.backgroundColor} opacity=${s} boxPx=${t.boxPx} painted=${c}`}function I(e){if(typeof window>`u`||typeof window.getComputedStyle!=`function`)return null;let t=window.getComputedStyle(e,`::before`);return!t||!t.width||!t.height?null:{width:t.width,height:t.height,backgroundColor:t.backgroundColor,hostOpacity:window.getComputedStyle(e).opacity,pillOpacity:t.opacity,boxPx:Math.round(e.getBoundingClientRect().width)}}var L=`maxy-shell-side-px`;function Be(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .artefact`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function R(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=Math.max(248,t-480-Be());return Math.min(Math.max(e,248),n)}function Ve(){if(typeof window>`u`)return 264;try{let e=window.localStorage.getItem(L);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 R(t)}catch{}return 264}function He({targetSelector:e=`.platform`}){let t=(0,E.useRef)(null),[n,r]=(0,E.useState)(()=>Ve()),i=(0,E.useRef)(n);(0,E.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,E.useCallback)(()=>{r(e=>{let t=R(e);return t===e?e:t})},[]);(0,E.useEffect)(()=>{a(),t.current&&console.info(ze(`sidebar`,I(t.current))),window.addEventListener(`resize`,a);let n=document.querySelector(e),r=null;return n instanceof HTMLElement&&(r=new MutationObserver(a),r.observe(n,{attributes:!0,attributeFilter:[`data-artefact`,`class`]})),()=>{window.removeEventListener(`resize`,a),r?.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(R(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(L,String(t))}catch{}console.info(`[admin-ui] sidebar-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=R(264);r(e);try{window.localStorage.removeItem(L)}catch{}console.info(`[admin-ui] sidebar-resize px=${e}`)};return(0,T.jsx)(`div`,{ref:t,className:`side-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize sidebar`,onPointerDown:o,onDoubleClick:s})}var z=C();function Ue(e){return Math.max(14,e/2-386)}function B(e){return e.left===0&&e.top===0&&e.width===0&&e.height===0}var V={position:`fixed`,visibility:`hidden`};function We({anchorRef:e,onClose:t,className:n,role:r,ariaLabel:i,anchorId:a,children:o}){let s=(0,E.useRef)(null),[c,l]=(0,E.useState)(V),u=(0,E.useRef)(null),d=(0,E.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,d=window.innerHeight,f=o.width>0&&o.height>0,p=r?r.getBoundingClientRect():null,m=(e,t)=>console.error(`[anchored-popover] op=offscreen id=${i} left=${e} top=${t} w=${o.width} h=${o.height} viewport=${c},${d}`),h=e=>{e!==u.current&&(u.current=e,console.log(e))};if(h(`[anchored-popover] op=anchor id=${i} present=${!!r} rect=${p?`${p.left},${p.top},${p.width},${p.height}`:`none`}`),!p){let e=Math.max(4,c-o.width-Ue(c)),t=Math.max(4,d-o.height-14);l({position:`fixed`,left:e,top:t,visibility:`visible`}),h(`[anchored-popover] op=placed id=${i} left=${e} top=${t} w=${o.width} h=${o.height} flipped=false clampedLeft=false clampedRight=false`);return}if(f&&B(p)){l(V),m(p.left,p.top);return}let g=p.right-o.width,_=c-o.width-4,ee=!1,v=!1;g>_&&(g=_,ee=!0),g<4&&(g=4,v=!0);let y=d-p.bottom-4,te=p.top-4,b=o.height+8<=y?!1:o.height+8<=te?!0:te>y,x=Math.max(0,b?te:y),S=b?Math.max(4,p.top-Math.min(o.height,x)):p.bottom;l({position:`fixed`,left:g,top:S,maxHeight:x,visibility:`visible`}),h(`[anchored-popover] op=placed id=${i} left=${g} top=${S} w=${o.width} h=${o.height} maxH=${x} flipped=${b} clampedLeft=${v} clampedRight=${ee}`);let ne=Math.min(o.height,x);f&&(g+o.width<=0||g>=c||S+ne<=0||S>=d)&&m(g,S)},[e,a,n]);return(0,E.useLayoutEffect)(()=>{if(d(),typeof ResizeObserver>`u`)return;let e=new ResizeObserver(()=>d());return s.current&&e.observe(s.current),()=>e.disconnect()},[d]),(0,E.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,z.createPortal)((0,T.jsx)(`div`,{ref:s,className:n,role:r,"aria-label":i,style:c,children:o}),document.body)}function Ge({actions:e,disabled:t}){let[n,i]=(0,E.useState)(!1),[a,o]=(0,E.useState)(null),s=(0,E.useRef)(null),c=(0,E.useCallback)(()=>{i(!1),o(null)},[]);return(0,T.jsxs)(`div`,{className:`conv-actions`,children:[(0,T.jsx)(`button`,{ref:s,type:`button`,className:`conv-action conv-actions-overflow`,onClick:()=>i(e=>!e),disabled:t,"aria-haspopup":`menu`,"aria-expanded":n,"aria-label":`Session actions`,title:`Session actions`,children:(0,T.jsx)(r,{size:12})}),n&&(0,T.jsx)(We,{anchorRef:s,onClose:c,className:`conv-actions-menu`,role:`menu`,children:e.map(e=>e.panel?(0,T.jsxs)(`div`,{className:`conv-actions-menu-disclosure`,children:[(0,T.jsxs)(`button`,{type:`button`,role:`menuitem`,"aria-haspopup":`dialog`,"aria-expanded":a===e.key,disabled:t,onClick:()=>o(t=>t===e.key?null:e.key),children:[e.icon,(0,T.jsx)(`span`,{children:e.menuLabel})]}),a===e.key&&(0,T.jsx)(`div`,{className:`conv-actions-menu-panel`,children:e.panel()})]},e.key):(0,T.jsxs)(`button`,{type:`button`,role:`menuitem`,className:e.danger?`conv-action-danger`:void 0,"aria-busy":e.busy,disabled:t,onClick:t=>{e.onClick?.(t),c()},children:[e.icon,(0,T.jsx)(`span`,{children:e.menuLabel})]},e.key))})]})}var H=`claude-opus-5[1m]`,Ke=`claude-sonnet-5`,U=`claude-haiku-4-5`,qe={[H]:`Opus 5 (1M context)`,[Ke]:`Sonnet 5`,[U]:`Haiku 4.5`};function W(e){return qe[e]??e}var Je=[H,Ke,U];function G(e){return e.replace(/\[1m\]$/,``)}function Ye(e){return Je.find(t=>G(t)===G(e))??e}var Xe=[`default`,`acceptEdits`,`plan`,`auto`,`bypassPermissions`],Ze=[`low`,`medium`,`high`,`xhigh`];[...Xe],[...Ze],[...Ze];var Qe=[H,Ke,U],$e={default:`Ask permissions`,acceptEdits:`Accept edits`,plan:`Plan mode`,auto:`Auto mode`,bypassPermissions:`Bypass permissions`},et=Xe.map(e=>({value:e,label:$e[e]??e})),K={low:`Low`,medium:`Medium`,high:`High`,xhigh:`Highest`},tt=Ze.map(e=>({value:e,label:K[e]??e}));function q(e){if(e){let t=Qe.find(t=>G(t)===G(e));if(t)return t}return H}function nt({row:e,adminFetch:t,onError:n}){let[r,i]=(0,E.useState)(()=>q(e.model)),[a,o]=(0,E.useState)(``),[s,c]=(0,E.useState)(``),[l,u]=(0,E.useState)(!1),d=(0,E.useRef)(!1);(0,E.useEffect)(()=>{i(q(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,T.jsxs)(T.Fragment,{children:[(0,T.jsxs)(`label`,{className:`reseat-field`,children:[(0,T.jsx)(`span`,{children:`Model`}),(0,T.jsx)(`select`,{"data-kind":`model`,value:r,disabled:l,onChange:e=>i(e.target.value),children:Qe.map(e=>(0,T.jsx)(`option`,{value:e,children:W(e)},e))})]}),(0,T.jsxs)(`label`,{className:`reseat-field`,children:[(0,T.jsx)(`span`,{children:`Mode`}),(0,T.jsxs)(`select`,{"data-kind":`mode`,value:a,disabled:l,onChange:e=>o(e.target.value),children:[(0,T.jsx)(`option`,{value:``,children:`Keep current`}),et.map(e=>(0,T.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,T.jsxs)(`label`,{className:`reseat-field`,children:[(0,T.jsx)(`span`,{children:`Effort`}),(0,T.jsxs)(`select`,{"data-kind":`effort`,value:s,disabled:l,onChange:e=>c(e.target.value),children:[(0,T.jsx)(`option`,{value:``,children:`Keep current`}),tt.map(e=>(0,T.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,T.jsx)(`button`,{type:`button`,className:`reseat-apply`,disabled:l,"aria-busy":l,onClick:()=>void p(),children:l?(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(f,{size:12,className:`spin`,"aria-hidden":`true`}),`Resetting…`]}):`Reset`})]})}function rt(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 it(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function at({target:e,anchorEl:t,onConfirm:n,onCancel:r}){let i=(0,E.useRef)(null);return i.current=t,e?(0,T.jsxs)(We,{anchorRef:i,onClose:r,className:`conv-delete-confirm`,role:`alertdialog`,ariaLabel:`Confirm delete session`,children:[(0,T.jsxs)(`div`,{className:`claude-info-header`,children:[(0,T.jsx)(`span`,{children:`Delete this conversation?`}),(0,T.jsx)(`button`,{className:`claude-info-close`,onClick:r,"aria-label":`Close`,children:`✕`})]}),(0,T.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[(0,T.jsxs)(`div`,{className:`conv-delete-target`,children:[(0,T.jsx)(`span`,{className:`conv-delete-label`,title:e.title,children:e.title||`Untitled session`}),(0,T.jsx)(`code`,{className:`conv-delete-id`,title:e.sessionId,children:e.sessionId.slice(0,8)})]}),(0,T.jsx)(`div`,{style:{marginTop:`8px`},children:`This permanently removes the transcript. It is not moved to Archive and cannot be recovered.`}),e.live&&(0,T.jsx)(`div`,{style:{marginTop:`8px`},children:`This session is running; deleting stops it first.`})]}),(0,T.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,T.jsx)(O,{variant:`danger`,size:`sm`,style:{flex:1},onClick:n,children:`Delete`}),(0,T.jsx)(O,{variant:`secondary`,size:`sm`,style:{flex:1},onClick:r,children:`Cancel`})]})]}):null}function ot({open:e,count:t,liveCount:n,onConfirm:r,onCancel:i}){if(!e)return null;let a=t===1?``:`s`;return(0,T.jsx)(`div`,{className:`claude-info-overlay`,onClick:i,children:(0,T.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Confirm delete sessions`,children:[(0,T.jsxs)(`div`,{className:`claude-info-header`,children:[(0,T.jsxs)(`span`,{children:[`Delete `,t,` conversation`,a,`?`]}),(0,T.jsx)(`button`,{className:`claude-info-close`,onClick:i,"aria-label":`Close`,children:`✕`})]}),(0,T.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,T.jsxs)(`div`,{style:{marginTop:`8px`},children:[n,` `,n===1?`is`:`are`,` running and will be stopped first.`]})]}),(0,T.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,T.jsxs)(O,{variant:`danger`,size:`sm`,style:{flex:1},onClick:r,children:[`Delete `,t]}),(0,T.jsx)(O,{variant:`secondary`,size:`sm`,style:{flex:1},onClick:i,children:`Cancel`})]})]})})}function st(e){return`New session: ${e.toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`})}`}function ct({open:e,pending:t,onConfirm:n,onCancel:r,now:i}){let[a,o]=(0,E.useState)(``),s=(0,E.useRef)(null),c=(0,E.useRef)(null),l=(0,E.useRef)(!1);if((0,E.useEffect)(()=>{if(!e){c.current=null,l.current=!1;return}if(c.current!==null)return;let t=st(i?i():new Date);c.current=t,o(t)},[e,i]),(0,E.useEffect)(()=>{if(!e||l.current||c.current===null||a!==c.current)return;let t=s.current;t&&(l.current=!0,t.focus(),t.setSelectionRange(0,t.value.length))},[e,a]),!e)return null;let u=a.trim(),d=u.length>0&&u.length<=200,f=()=>{d&&!t&&n(u)},p=e=>{t||r(e)};return(0,T.jsx)(`div`,{className:`claude-info-overlay`,onClick:()=>p(`backdrop`),children:(0,T.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`dialog`,"aria-label":`Name this session`,children:[(0,T.jsxs)(`div`,{className:`claude-info-header`,children:[(0,T.jsx)(`span`,{children:`Name this session`}),(0,T.jsx)(`button`,{className:`claude-info-close`,onClick:()=>p(`cancel`),"aria-label":`Close`,disabled:t,children:`✕`})]}),(0,T.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`},children:[(0,T.jsx)(`input`,{ref:s,className:`new-session-name-input`,"aria-label":`Session name`,value:a,disabled:t,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),f()),e.key===`Escape`&&(e.preventDefault(),p(`escape`))}}),(0,T.jsx)(`div`,{className:`new-session-name-hint`,children:u.length>200?`Too long by ${u.length-200}`:`You can rename it later from the session menu.`})]}),(0,T.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,T.jsx)(O,{variant:`primary`,size:`sm`,style:{flex:1},disabled:!d||t,onClick:f,children:t?`Starting…`:`Start session`}),(0,T.jsx)(O,{variant:`secondary`,size:`sm`,style:{flex:1},disabled:t,onClick:()=>p(`cancel`),children:`Cancel`})]})]})})}var lt=`auth-refresh-failed`;function ut({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,T.jsx)(`div`,{className:`claude-info-overlay`,onClick:t,children:(0,T.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Session could not be opened`,children:[(0,T.jsxs)(`div`,{className:`claude-info-header`,children:[(0,T.jsx)(`span`,{children:r}),(0,T.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:`✕`})]}),(0,T.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[i,(0,T.jsxs)(`div`,{className:`claude-info-row`,style:{marginTop:`8px`},children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Reason`}),(0,T.jsx)(`span`,{className:`claude-info-value`,children:e.reason})]}),e.sessionId&&(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,T.jsxs)(`span`,{className:`claude-info-value`,children:[e.sessionId.slice(0,8),`…`]})]})]})]})})}function dt(e){let{show:t,onClose:n,claudeInfo:r,messages:i,sessionElapsed:a,sessionId:o,cacheKey:s}=e,[c,l]=(0,E.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,T.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,T.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,T.jsxs)(`div`,{className:`claude-info-header`,children:[(0,T.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`claude-info-icon`}),(0,T.jsx)(`span`,{children:`Claude Code`}),(0,T.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,T.jsxs)(`div`,{className:`claude-info-section`,children:[(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Version`}),(0,T.jsx)(`span`,{className:`claude-info-value`,children:r?r.version:`…`})]}),(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Email`}),(0,T.jsx)(`span`,{className:`claude-info-value`,children:r?.account?.email??`…`})]})]}),(g||m||h>0)&&(0,T.jsxs)(`div`,{className:`claude-info-section`,children:[g&&(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Plan`}),(0,T.jsx)(`span`,{className:`claude-info-value`,style:{textTransform:`capitalize`},children:g})]}),m&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Usage`}),(0,T.jsxs)(`span`,{className:`claude-info-value`,children:[Math.round(m.utilization*100),`%`]})]}),(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Resets in`}),(0,T.jsx)(`span`,{className:`claude-info-value`,children:_(m.resetsAt)})]}),m.isUsingOverage&&(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Overage`}),(0,T.jsx)(`span`,{className:`claude-info-value`,children:`Active`})]})]}),h>0&&(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Session cost`}),(0,T.jsxs)(`span`,{className:`claude-info-value`,children:[`$`,h<.01?h.toFixed(4):h.toFixed(2)]})]})]}),(0,T.jsxs)(`div`,{className:`claude-info-section`,children:[(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Model`}),(0,T.jsx)(`span`,{className:`claude-info-value`,children:r?.model??`…`})]}),(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Context used`}),(0,T.jsx)(`span`,{className:`claude-info-value`,children:f>0?`${f}%`:`—`})]}),(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Tokens`}),(0,T.jsx)(`span`,{className:`claude-info-value`,children:p>0?it(p):`—`})]}),(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,T.jsx)(`span`,{className:`claude-info-value`,children:rt(a)})]}),(o||s)&&(()=>{let e=o??s??``;return(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,T.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 ie(e)?`copied`:`failed`),setTimeout(()=>l(null),1200)},children:c===`copied`?`copied ✓`:c===`failed`?`copy failed ✕`:`${e.slice(0,8)}…`})]})})()]})]})})}function ft({open:e,onConnect:t,onClose:n}){return e?(0,T.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,T.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Claude is not connected`,children:[(0,T.jsxs)(`div`,{className:`claude-info-header`,children:[(0,T.jsx)(`span`,{children:`Claude isn’t connected`}),(0,T.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,T.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`,display:`flex`,flexDirection:`column`,gap:`10px`},children:[(0,T.jsx)(`span`,{children:`This needs Claude, which is currently disconnected. Connect to continue — the rest of the dashboard stays available either way.`}),(0,T.jsxs)(`div`,{style:{display:`flex`,gap:`8px`,alignItems:`center`},children:[(0,T.jsx)(O,{variant:`primary`,size:`sm`,onClick:t,children:`Connect Claude`}),(0,T.jsx)(`button`,{type:`button`,className:`claude-info-close`,style:{fontSize:`11px`},onClick:n,children:`Not now`})]})]})]})}):null}function pt(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 mt(e){return e.activeMs.thinking+e.activeMs.messaging+e.activeMs.toolUse}function J(e){return e.toLocaleString(`en-GB`)}function ht(e){return`£${e.toFixed(2)}`}function gt(e){let t=[`Day`,`Active`,`Output tokens`,`Input tokens`,`Cache write`,`Cache read`,`Opus 5 (GBP)`,`Sonnet 5 (GBP)`],n=(e,t)=>[e,pt(mt(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(`
1
+ import{o as e}from"./chunk-CltuBf4Z.js";import{A as t,C as n,D as r,E as i,F as a,H as o,I as s,J as c,L as l,M as u,N as d,O as f,R as p,T as m,U as h,V as g,a as _,b as ee,f as v,g as y,h as te,j as b,k as x,m as S,o as ne,p as re,q as C,r as ie,t as ae,v as oe,w as se,x as w,y as ce,z as le}from"./useSubAccountSwitcher-BEwQMRMo.js";async function ue(){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 T=o();function de({checked:e,onChange:t,label:n,disabled:r,ariaLabel:i=n}){return(0,T.jsxs)(`label`,{className:`maxy-checkbox${r?` maxy-checkbox--disabled`:``}`,children:[(0,T.jsx)(`input`,{type:`checkbox`,"aria-label":i,checked:e,onChange:e=>t(e.target.checked),disabled:r}),(0,T.jsx)(`span`,{className:`maxy-checkbox__box`,children:`✱`}),n&&(0,T.jsx)(`span`,{className:`maxy-checkbox__label`,children:n})]})}var E=e(c(),1),D={sm:14,md:16,lg:18},fe={sm:30,md:38,lg:46};function O({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=D[t],g={...e===`send`?{width:fe[t],height:fe[t]}:{},...d},_=Object.keys(g).length>0;return(0,T.jsxs)(`button`,{type:s,className:m,disabled:i||o,onClick:c,"aria-label":l,"aria-pressed":u,style:_?g:void 0,children:[(0,T.jsxs)(`span`,{className:`btn__content`,style:{visibility:i?`hidden`:`visible`},children:[n&&r===`leading`&&(0,T.jsx)(n,{size:h}),p,n&&r===`trailing`&&(0,T.jsx)(n,{size:h})]}),i&&(0,T.jsx)(`span`,{className:`btn__spinner`,children:`✱`})]})}var pe=l(`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`}]]),me=l(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),he=l(`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`}]]),ge=l(`chevron-down`,[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]),_e=l(`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`}]]),ve=l(`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`}]]),k=l(`gauge`,[[`path`,{d:`m12 14 4-4`,key:`9kzdfg`}],[`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`,key:`19p75a`}]]),ye=l(`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`}]]),be=l(`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`}]]),A=l(`panel-left`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}]]),xe=l(`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`}]]),Se=l(`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`}]]),Ce=l(`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`}]]),we=l(`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`}]]),Te=5e3,Ee=1200;function De(e){return Math.max(Ee,Math.round(Te/(e<1?1:e)))}var Oe=500,j=new Set;function M(e,t,n){let r=n??(typeof globalThis.fetch==`function`?globalThis.fetch:void 0);if(j.has(e)||!r)return!1;if(j.size>=Oe){for(let e of j)if(j.delete(e),j.size<Oe)break}j.add(e);try{Promise.resolve(r(`/api/admin/events`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({event:`wa-notify:rendered`,fields:{msgId:e,senderType:t}})})).catch(()=>{})}catch{}return!0}function ke({type:e}){return e===`admin`?(0,T.jsx)(`svg`,{className:`wa-notify-icon`,viewBox:`0 0 16 16`,"aria-hidden":`true`,children:(0,T.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,T.jsx)(`svg`,{className:`wa-notify-icon`,viewBox:`0 0 16 16`,"aria-hidden":`true`,children:(0,T.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,T.jsx)(`svg`,{className:`wa-notify-icon`,viewBox:`0 0 16 16`,"aria-hidden":`true`,children:(0,T.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,T.jsx)(`svg`,{className:`wa-notify-icon`,viewBox:`0 0 16 16`,"aria-hidden":`true`,children:(0,T.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 Ae({frames:e,onExpire:t}){let n=(0,E.useRef)(new Map),r=(0,E.useRef)(new Map);return(0,E.useEffect)(()=>{let i=Date.now(),a=De(e.length),o=new Set(e.map(e=>e.waMessageId));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.waMessageId;n.current.has(e)||(n.current.set(e,i),M(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,T.jsx)(`div`,{className:`wa-notify-host`,children:[...e].reverse().map(e=>(0,T.jsxs)(`div`,{className:`wa-notify-card`,role:`status`,children:[(0,T.jsxs)(`div`,{className:`wa-notify-head`,children:[(0,T.jsx)(`span`,{className:`wa-notify-pill wa-notify-pill-${e.senderType}`,children:(0,T.jsx)(ke,{type:e.senderType})}),(0,T.jsx)(`span`,{className:`wa-notify-account`,children:e.accountName})]}),(0,T.jsx)(`div`,{className:`wa-notify-sender`,children:e.senderDisplay}),(0,T.jsxs)(`div`,{className:`wa-notify-body`,children:[e.body,e.truncated?`…`:``]})]},e.waMessageId))})}var je=`wa-notify`;function Me({connected:e,onConnectClaude:t}){return e?(0,T.jsxs)(`span`,{className:`claude-status-pill`,"data-connected":`true`,title:`Claude is connected`,children:[(0,T.jsx)(`img`,{src:`/brand/claude.png`,alt:``,className:`claude-status-pill__mark`}),(0,T.jsx)(`span`,{className:`claude-status-pill__label`,children:`Connected`}),(0,T.jsx)(`span`,{className:`claude-status-pill__dot claude-status-pill__dot--live`,"aria-hidden":`true`})]}):(0,T.jsxs)(`button`,{type:`button`,className:`claude-status-pill claude-status-pill--action`,"data-connected":`false`,onClick:t,title:`Connect Claude`,children:[(0,T.jsx)(`img`,{src:`/brand/claude.png`,alt:``,className:`claude-status-pill__mark`}),(0,T.jsx)(`span`,{className:`claude-status-pill__label`,children:`Connect`}),(0,T.jsx)(`span`,{className:`claude-status-pill__dot claude-status-pill__dot--down`,"aria-hidden":`true`})]})}function Ne(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 Pe({title:e,sidebarOpen:t,onToggleSidebar:n,claudeConnected:i,onConnectClaude:a}){let o=e??Ne(typeof window<`u`?window.location.pathname:`/`),s=i!==void 0&&a!==void 0;return(0,T.jsxs)(`header`,{className:`admin-page-header`,children:[(0,T.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,T.jsx)(A,{className:`admin-page-header__toggle-desktop`,size:18,strokeWidth:1.75}),(0,T.jsx)(r,{className:`admin-page-header__toggle-mobile`,size:22,strokeWidth:1.75})]}),(0,T.jsx)(`h1`,{className:`admin-page-header__title`,children:o}),s&&(0,T.jsx)(`div`,{className:`admin-page-header__right`,children:(0,T.jsx)(Me,{connected:i,onConnectClaude:a})})]})}var Fe=[{label:`Home`,href:`/`,Icon:x,match:e=>e===`/`||e===``},{label:`Chat`,href:`/chat`,Icon:i,match:e=>e.startsWith(`/chat`)},{label:`Tasks`,href:`/tasks`,Icon:ye,match:e=>e.startsWith(`/tasks`)},{label:`Data`,href:`/data`,Icon:d,match:e=>e.startsWith(`/data`)},{label:`Calendar`,href:`/calendar`,Icon:a,match:e=>e.startsWith(`/calendar`)}],Ie=[{label:`Chat`,href:`/`,Icon:i,match:e=>e===`/`||e===``||e.startsWith(`/chat`)},{label:`Data`,href:`/data`,Icon:d,match:e=>e.startsWith(`/data`)}];function Le(e){let t=Fe.find(t=>t.match(e));return t?t.href:`/`}function N({variant:e=`admin`,onOpenConversations:t}={}){let n=typeof window<`u`?window.location.pathname:`/`,r=e===`operator`?Ie:Fe,a=e===`operator`?Ie.find(e=>e.match(n))?.href??`/`:Le(n),o=e=>{let t=e.href===a,{Icon:n}=e;return(0,T.jsxs)(`a`,{href:e.href,className:`bottom-tab${t?` is-active`:``}`,"aria-current":t?`page`:void 0,children:[(0,T.jsx)(n,{size:19,strokeWidth:1.75}),(0,T.jsx)(`span`,{className:`bottom-tab__label`,children:e.label})]},e.href)};return(0,T.jsxs)(`nav`,{className:`bottom-tab-bar`,"aria-label":`Primary`,children:[r.slice(0,1).map(o),e===`operator`&&t&&(0,T.jsxs)(`button`,{type:`button`,className:`bottom-tab`,onClick:t,children:[(0,T.jsx)(i,{size:19,strokeWidth:1.75}),(0,T.jsx)(`span`,{className:`bottom-tab__label`,children:`Conversations`})]}),r.slice(1).map(o)]})}var P=`thicknessPx=- lengthPx=- color=- opacity=- boxPx=- painted=false source=unavailable`;function Re(e){let t=parseFloat(e);return Number.isFinite(t)?t:null}function F(e,t,n,r){return e<=0||t<=0||r<=0||n===`transparent`?!1:!/rgba\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*,\s*0\s*\)/.test(n)}function ze(e,t){let n=`[admin-ui] op=resize-grip-audit surface=${e}`;if(!t)return`${n} ${P}`;let r=Re(t.width),i=Re(t.height),a=Re(t.hostOpacity),o=Re(t.pillOpacity);if(r===null||i===null||a===null||o===null||!t.backgroundColor)return`${n} ${P}`;let s=Math.round(a*o*1e3)/1e3,c=F(r,i,t.backgroundColor,s);return`${n} thicknessPx=${r} lengthPx=${i} color=${t.backgroundColor} opacity=${s} boxPx=${t.boxPx} painted=${c}`}function I(e){if(typeof window>`u`||typeof window.getComputedStyle!=`function`)return null;let t=window.getComputedStyle(e,`::before`);return!t||!t.width||!t.height?null:{width:t.width,height:t.height,backgroundColor:t.backgroundColor,hostOpacity:window.getComputedStyle(e).opacity,pillOpacity:t.opacity,boxPx:Math.round(e.getBoundingClientRect().width)}}var L=`maxy-shell-side-px`;function Be(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .artefact`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function R(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=Math.max(248,t-480-Be());return Math.min(Math.max(e,248),n)}function Ve(){if(typeof window>`u`)return 264;try{let e=window.localStorage.getItem(L);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 R(t)}catch{}return 264}function He({targetSelector:e=`.platform`}){let t=(0,E.useRef)(null),[n,r]=(0,E.useState)(()=>Ve()),i=(0,E.useRef)(n);(0,E.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,E.useCallback)(()=>{r(e=>{let t=R(e);return t===e?e:t})},[]);(0,E.useEffect)(()=>{a(),t.current&&console.info(ze(`sidebar`,I(t.current))),window.addEventListener(`resize`,a);let n=document.querySelector(e),r=null;return n instanceof HTMLElement&&(r=new MutationObserver(a),r.observe(n,{attributes:!0,attributeFilter:[`data-artefact`,`class`]})),()=>{window.removeEventListener(`resize`,a),r?.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(R(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(L,String(t))}catch{}console.info(`[admin-ui] sidebar-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=R(264);r(e);try{window.localStorage.removeItem(L)}catch{}console.info(`[admin-ui] sidebar-resize px=${e}`)};return(0,T.jsx)(`div`,{ref:t,className:`side-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize sidebar`,onPointerDown:o,onDoubleClick:s})}var z=C();function Ue(e){return Math.max(14,e/2-386)}function B(e){return e.left===0&&e.top===0&&e.width===0&&e.height===0}var V={position:`fixed`,visibility:`hidden`};function We({anchorRef:e,onClose:t,className:n,role:r,ariaLabel:i,anchorId:a,children:o}){let s=(0,E.useRef)(null),[c,l]=(0,E.useState)(V),u=(0,E.useRef)(null),d=(0,E.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,d=window.innerHeight,f=o.width>0&&o.height>0,p=r?r.getBoundingClientRect():null,m=(e,t)=>console.error(`[anchored-popover] op=offscreen id=${i} left=${e} top=${t} w=${o.width} h=${o.height} viewport=${c},${d}`),h=e=>{e!==u.current&&(u.current=e,console.log(e))};if(h(`[anchored-popover] op=anchor id=${i} present=${!!r} rect=${p?`${p.left},${p.top},${p.width},${p.height}`:`none`}`),!p){let e=Math.max(4,c-o.width-Ue(c)),t=Math.max(4,d-o.height-14);l({position:`fixed`,left:e,top:t,visibility:`visible`}),h(`[anchored-popover] op=placed id=${i} left=${e} top=${t} w=${o.width} h=${o.height} flipped=false clampedLeft=false clampedRight=false`);return}if(f&&B(p)){l(V),m(p.left,p.top);return}let g=p.right-o.width,_=c-o.width-4,ee=!1,v=!1;g>_&&(g=_,ee=!0),g<4&&(g=4,v=!0);let y=d-p.bottom-4,te=p.top-4,b=o.height+8<=y?!1:o.height+8<=te?!0:te>y,x=Math.max(0,b?te:y),S=b?Math.max(4,p.top-Math.min(o.height,x)):p.bottom;l({position:`fixed`,left:g,top:S,maxHeight:x,visibility:`visible`}),h(`[anchored-popover] op=placed id=${i} left=${g} top=${S} w=${o.width} h=${o.height} maxH=${x} flipped=${b} clampedLeft=${v} clampedRight=${ee}`);let ne=Math.min(o.height,x);f&&(g+o.width<=0||g>=c||S+ne<=0||S>=d)&&m(g,S)},[e,a,n]);return(0,E.useLayoutEffect)(()=>{if(d(),typeof ResizeObserver>`u`)return;let e=new ResizeObserver(()=>d());return s.current&&e.observe(s.current),()=>e.disconnect()},[d]),(0,E.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,z.createPortal)((0,T.jsx)(`div`,{ref:s,className:n,role:r,"aria-label":i,style:c,children:o}),document.body)}function Ge({actions:e,disabled:t}){let[n,i]=(0,E.useState)(!1),[a,o]=(0,E.useState)(null),s=(0,E.useRef)(null),c=(0,E.useCallback)(()=>{i(!1),o(null)},[]);return(0,T.jsxs)(`div`,{className:`conv-actions`,children:[(0,T.jsx)(`button`,{ref:s,type:`button`,className:`conv-action conv-actions-overflow`,onClick:()=>i(e=>!e),disabled:t,"aria-haspopup":`menu`,"aria-expanded":n,"aria-label":`Session actions`,title:`Session actions`,children:(0,T.jsx)(r,{size:12})}),n&&(0,T.jsx)(We,{anchorRef:s,onClose:c,className:`conv-actions-menu`,role:`menu`,children:e.map(e=>e.panel?(0,T.jsxs)(`div`,{className:`conv-actions-menu-disclosure`,children:[(0,T.jsxs)(`button`,{type:`button`,role:`menuitem`,"aria-haspopup":`dialog`,"aria-expanded":a===e.key,disabled:t,onClick:()=>o(t=>t===e.key?null:e.key),children:[e.icon,(0,T.jsx)(`span`,{children:e.menuLabel})]}),a===e.key&&(0,T.jsx)(`div`,{className:`conv-actions-menu-panel`,children:e.panel()})]},e.key):(0,T.jsxs)(`button`,{type:`button`,role:`menuitem`,className:e.danger?`conv-action-danger`:void 0,"aria-busy":e.busy,disabled:t,onClick:t=>{e.onClick?.(t),c()},children:[e.icon,(0,T.jsx)(`span`,{children:e.menuLabel})]},e.key))})]})}var H=`claude-opus-5[1m]`,Ke=`claude-sonnet-5`,U=`claude-haiku-4-5`,qe={[H]:`Opus 5 (1M context)`,[Ke]:`Sonnet 5`,[U]:`Haiku 4.5`};function W(e){return qe[e]??e}var Je=[H,Ke,U];function G(e){return e.replace(/\[1m\]$/,``)}function Ye(e){return Je.find(t=>G(t)===G(e))??e}var Xe=[`default`,`acceptEdits`,`plan`,`auto`,`bypassPermissions`],Ze=[`low`,`medium`,`high`,`xhigh`];[...Xe],[...Ze],[...Ze];var Qe=[H,Ke,U],$e={default:`Ask permissions`,acceptEdits:`Accept edits`,plan:`Plan mode`,auto:`Auto mode`,bypassPermissions:`Bypass permissions`},et=Xe.map(e=>({value:e,label:$e[e]??e})),K={low:`Low`,medium:`Medium`,high:`High`,xhigh:`Highest`},tt=Ze.map(e=>({value:e,label:K[e]??e}));function q(e){if(e){let t=Qe.find(t=>G(t)===G(e));if(t)return t}return H}function nt({row:e,adminFetch:t,onError:n}){let[r,i]=(0,E.useState)(()=>q(e.model)),[a,o]=(0,E.useState)(``),[s,c]=(0,E.useState)(``),[l,u]=(0,E.useState)(!1),d=(0,E.useRef)(!1);(0,E.useEffect)(()=>{i(q(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,T.jsxs)(T.Fragment,{children:[(0,T.jsxs)(`label`,{className:`reseat-field`,children:[(0,T.jsx)(`span`,{children:`Model`}),(0,T.jsx)(`select`,{"data-kind":`model`,value:r,disabled:l,onChange:e=>i(e.target.value),children:Qe.map(e=>(0,T.jsx)(`option`,{value:e,children:W(e)},e))})]}),(0,T.jsxs)(`label`,{className:`reseat-field`,children:[(0,T.jsx)(`span`,{children:`Mode`}),(0,T.jsxs)(`select`,{"data-kind":`mode`,value:a,disabled:l,onChange:e=>o(e.target.value),children:[(0,T.jsx)(`option`,{value:``,children:`Keep current`}),et.map(e=>(0,T.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,T.jsxs)(`label`,{className:`reseat-field`,children:[(0,T.jsx)(`span`,{children:`Effort`}),(0,T.jsxs)(`select`,{"data-kind":`effort`,value:s,disabled:l,onChange:e=>c(e.target.value),children:[(0,T.jsx)(`option`,{value:``,children:`Keep current`}),tt.map(e=>(0,T.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,T.jsx)(`button`,{type:`button`,className:`reseat-apply`,disabled:l,"aria-busy":l,onClick:()=>void p(),children:l?(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(f,{size:12,className:`spin`,"aria-hidden":`true`}),`Resetting…`]}):`Reset`})]})}function rt(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 it(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function at({target:e,anchorEl:t,onConfirm:n,onCancel:r}){let i=(0,E.useRef)(null);return i.current=t,e?(0,T.jsxs)(We,{anchorRef:i,onClose:r,className:`conv-delete-confirm`,role:`alertdialog`,ariaLabel:`Confirm delete session`,children:[(0,T.jsxs)(`div`,{className:`claude-info-header`,children:[(0,T.jsx)(`span`,{children:`Delete this conversation?`}),(0,T.jsx)(`button`,{className:`claude-info-close`,onClick:r,"aria-label":`Close`,children:`✕`})]}),(0,T.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[(0,T.jsxs)(`div`,{className:`conv-delete-target`,children:[(0,T.jsx)(`span`,{className:`conv-delete-label`,title:e.title,children:e.title||`Untitled session`}),(0,T.jsx)(`code`,{className:`conv-delete-id`,title:e.sessionId,children:e.sessionId.slice(0,8)})]}),(0,T.jsx)(`div`,{style:{marginTop:`8px`},children:`This permanently removes the transcript. It is not moved to Archive and cannot be recovered.`}),e.live&&(0,T.jsx)(`div`,{style:{marginTop:`8px`},children:`This session is running; deleting stops it first.`})]}),(0,T.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,T.jsx)(O,{variant:`danger`,size:`sm`,style:{flex:1},onClick:n,children:`Delete`}),(0,T.jsx)(O,{variant:`secondary`,size:`sm`,style:{flex:1},onClick:r,children:`Cancel`})]})]}):null}function ot({open:e,count:t,liveCount:n,onConfirm:r,onCancel:i}){if(!e)return null;let a=t===1?``:`s`;return(0,T.jsx)(`div`,{className:`claude-info-overlay`,onClick:i,children:(0,T.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Confirm delete sessions`,children:[(0,T.jsxs)(`div`,{className:`claude-info-header`,children:[(0,T.jsxs)(`span`,{children:[`Delete `,t,` conversation`,a,`?`]}),(0,T.jsx)(`button`,{className:`claude-info-close`,onClick:i,"aria-label":`Close`,children:`✕`})]}),(0,T.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,T.jsxs)(`div`,{style:{marginTop:`8px`},children:[n,` `,n===1?`is`:`are`,` running and will be stopped first.`]})]}),(0,T.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,T.jsxs)(O,{variant:`danger`,size:`sm`,style:{flex:1},onClick:r,children:[`Delete `,t]}),(0,T.jsx)(O,{variant:`secondary`,size:`sm`,style:{flex:1},onClick:i,children:`Cancel`})]})]})})}function st(e){return`New session: ${e.toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`})}`}function ct({open:e,pending:t,onConfirm:n,onCancel:r,now:i}){let[a,o]=(0,E.useState)(``),s=(0,E.useRef)(null),c=(0,E.useRef)(null),l=(0,E.useRef)(!1);if((0,E.useEffect)(()=>{if(!e){c.current=null,l.current=!1;return}if(c.current!==null)return;let t=st(i?i():new Date);c.current=t,o(t)},[e,i]),(0,E.useEffect)(()=>{if(!e||l.current||c.current===null||a!==c.current)return;let t=s.current;t&&(l.current=!0,t.focus(),t.setSelectionRange(0,t.value.length))},[e,a]),!e)return null;let u=a.trim(),d=u.length>0&&u.length<=200,f=()=>{d&&!t&&n(u)},p=e=>{t||r(e)};return(0,T.jsx)(`div`,{className:`claude-info-overlay`,onClick:()=>p(`backdrop`),children:(0,T.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`dialog`,"aria-label":`Name this session`,children:[(0,T.jsxs)(`div`,{className:`claude-info-header`,children:[(0,T.jsx)(`span`,{children:`Name this session`}),(0,T.jsx)(`button`,{className:`claude-info-close`,onClick:()=>p(`cancel`),"aria-label":`Close`,disabled:t,children:`✕`})]}),(0,T.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`},children:[(0,T.jsx)(`input`,{ref:s,className:`new-session-name-input`,"aria-label":`Session name`,value:a,disabled:t,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),f()),e.key===`Escape`&&(e.preventDefault(),p(`escape`))}}),(0,T.jsx)(`div`,{className:`new-session-name-hint`,children:u.length>200?`Too long by ${u.length-200}`:`You can rename it later from the session menu.`})]}),(0,T.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,T.jsx)(O,{variant:`primary`,size:`sm`,style:{flex:1},disabled:!d||t,onClick:f,children:t?`Starting…`:`Start session`}),(0,T.jsx)(O,{variant:`secondary`,size:`sm`,style:{flex:1},disabled:t,onClick:()=>p(`cancel`),children:`Cancel`})]})]})})}var lt=`auth-refresh-failed`;function ut({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,T.jsx)(`div`,{className:`claude-info-overlay`,onClick:t,children:(0,T.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Session could not be opened`,children:[(0,T.jsxs)(`div`,{className:`claude-info-header`,children:[(0,T.jsx)(`span`,{children:r}),(0,T.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:`✕`})]}),(0,T.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[i,(0,T.jsxs)(`div`,{className:`claude-info-row`,style:{marginTop:`8px`},children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Reason`}),(0,T.jsx)(`span`,{className:`claude-info-value`,children:e.reason})]}),e.sessionId&&(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,T.jsxs)(`span`,{className:`claude-info-value`,children:[e.sessionId.slice(0,8),`…`]})]})]})]})})}function dt(e){let{show:t,onClose:n,claudeInfo:r,messages:i,sessionElapsed:a,sessionId:o,cacheKey:s}=e,[c,l]=(0,E.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,T.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,T.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,T.jsxs)(`div`,{className:`claude-info-header`,children:[(0,T.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`claude-info-icon`}),(0,T.jsx)(`span`,{children:`Claude Code`}),(0,T.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,T.jsxs)(`div`,{className:`claude-info-section`,children:[(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Version`}),(0,T.jsx)(`span`,{className:`claude-info-value`,children:r?r.version:`…`})]}),(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Email`}),(0,T.jsx)(`span`,{className:`claude-info-value`,children:r?.account?.email??`…`})]})]}),(g||m||h>0)&&(0,T.jsxs)(`div`,{className:`claude-info-section`,children:[g&&(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Plan`}),(0,T.jsx)(`span`,{className:`claude-info-value`,style:{textTransform:`capitalize`},children:g})]}),m&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Usage`}),(0,T.jsxs)(`span`,{className:`claude-info-value`,children:[Math.round(m.utilization*100),`%`]})]}),(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Resets in`}),(0,T.jsx)(`span`,{className:`claude-info-value`,children:_(m.resetsAt)})]}),m.isUsingOverage&&(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Overage`}),(0,T.jsx)(`span`,{className:`claude-info-value`,children:`Active`})]})]}),h>0&&(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Session cost`}),(0,T.jsxs)(`span`,{className:`claude-info-value`,children:[`$`,h<.01?h.toFixed(4):h.toFixed(2)]})]})]}),(0,T.jsxs)(`div`,{className:`claude-info-section`,children:[(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Model`}),(0,T.jsx)(`span`,{className:`claude-info-value`,children:r?.model??`…`})]}),(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Context used`}),(0,T.jsx)(`span`,{className:`claude-info-value`,children:f>0?`${f}%`:`—`})]}),(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Tokens`}),(0,T.jsx)(`span`,{className:`claude-info-value`,children:p>0?it(p):`—`})]}),(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,T.jsx)(`span`,{className:`claude-info-value`,children:rt(a)})]}),(o||s)&&(()=>{let e=o??s??``;return(0,T.jsxs)(`div`,{className:`claude-info-row`,children:[(0,T.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,T.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 ie(e)?`copied`:`failed`),setTimeout(()=>l(null),1200)},children:c===`copied`?`copied ✓`:c===`failed`?`copy failed ✕`:`${e.slice(0,8)}…`})]})})()]})]})})}function ft({open:e,onConnect:t,onClose:n}){return e?(0,T.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,T.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Claude is not connected`,children:[(0,T.jsxs)(`div`,{className:`claude-info-header`,children:[(0,T.jsx)(`span`,{children:`Claude isn’t connected`}),(0,T.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,T.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`,display:`flex`,flexDirection:`column`,gap:`10px`},children:[(0,T.jsx)(`span`,{children:`This needs Claude, which is currently disconnected. Connect to continue — the rest of the dashboard stays available either way.`}),(0,T.jsxs)(`div`,{style:{display:`flex`,gap:`8px`,alignItems:`center`},children:[(0,T.jsx)(O,{variant:`primary`,size:`sm`,onClick:t,children:`Connect Claude`}),(0,T.jsx)(`button`,{type:`button`,className:`claude-info-close`,style:{fontSize:`11px`},onClick:n,children:`Not now`})]})]})]})}):null}function pt(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 mt(e){return e.activeMs.thinking+e.activeMs.messaging+e.activeMs.toolUse}function J(e){return e.toLocaleString(`en-GB`)}function ht(e){return`£${e.toFixed(2)}`}function gt(e){let t=[`Day`,`Active`,`Output tokens`,`Input tokens`,`Cache write`,`Cache read`,`Opus 5 (GBP)`,`Sonnet 5 (GBP)`],n=(e,t)=>[e,pt(mt(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(`
2
2
  `)}function _t({label:e,d:t,bold:n}){let r=n?`th`:`td`;return(0,T.jsxs)(`tr`,{className:n?`usage-total-row`:void 0,children:[(0,T.jsx)(r,{className:`usage-day`,children:e}),(0,T.jsx)(r,{children:pt(mt(t))}),(0,T.jsx)(r,{children:J(t.tokens.output)}),(0,T.jsx)(r,{children:J(t.tokens.input)}),(0,T.jsx)(r,{children:J(t.tokens.cacheWrite)}),(0,T.jsx)(r,{children:J(t.tokens.cacheRead)}),(0,T.jsx)(r,{children:ht(t.costGBP.opus)}),(0,T.jsx)(r,{children:ht(t.costGBP.sonnet)})]})}function vt({show:e,onClose:t,anchorEl:n,sessionId:r,summary:i,loading:a,error:o}){let s=(0,E.useRef)(null);if(s.current=n,!e)return null;let c=!!i&&i.days.length>0;return(0,T.jsxs)(We,{anchorRef:s,onClose:t,className:`usage-popover`,role:`dialog`,ariaLabel:`Session usage and cost`,anchorId:r??void 0,children:[(0,T.jsxs)(`div`,{className:`claude-info-header`,children:[(0,T.jsxs)(`span`,{children:[`Usage & cost`,r?` · ${r.slice(0,8)}`:``]}),c&&(0,T.jsx)(`button`,{className:`usage-download`,onClick:()=>{if(!i)return;let e=new Blob([gt(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,T.jsx)(u,{size:14})}),(0,T.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:(0,T.jsx)(ce,{size:14})})]}),(0,T.jsxs)(`div`,{className:`claude-info-section usage-body`,children:[a&&(0,T.jsx)(`div`,{className:`usage-note`,children:`Computing usage…`}),!a&&o&&(0,T.jsx)(`div`,{className:`usage-note usage-error`,children:o}),!a&&!o&&i&&i.days.length===0&&(0,T.jsx)(`div`,{className:`usage-note`,children:`No usage recorded for this session yet.`}),!a&&!o&&i&&i.days.length>0&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`div`,{className:`usage-table-scroll`,children:(0,T.jsxs)(`table`,{className:`usage-table`,children:[(0,T.jsx)(`thead`,{children:(0,T.jsxs)(`tr`,{children:[(0,T.jsx)(`th`,{className:`usage-day`,children:`Day`}),(0,T.jsx)(`th`,{children:`Active`}),(0,T.jsx)(`th`,{children:`Output tok`}),(0,T.jsx)(`th`,{children:`Input tok`}),(0,T.jsx)(`th`,{children:`Cache write`}),(0,T.jsx)(`th`,{children:`Cache read`}),(0,T.jsx)(`th`,{children:`Opus 5 (£)`}),(0,T.jsx)(`th`,{children:`Sonnet 5 (£)`})]})}),(0,T.jsxs)(`tbody`,{children:[i.days.map(e=>(0,T.jsx)(_t,{label:e.date,d:e},e.date)),(0,T.jsx)(_t,{label:`TOTAL (${i.days.length} d)`,d:i.totals,bold:!0})]})]})}),(0,T.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 yt=`https://claude.ai/code`,bt=200,xt=[500,1e3,1500,2e3,2500,3e3,3e3];function St(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:`${yt}/${r}`,sameOrigin:!1};let i=n.reason||n.error||`status ${t}`;return{kind:`error`,sessionId:n.sessionId??null,reason:i}}function Ct(e){if(!e)return``;let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``}function wt(e){let{businessName:r,cacheKey:o,onConnectClaude:c,role:l,userName:u,userAvatar:h,onSelectProjects:y,onSelectTasks:re,onCloseMobileDrawer:C,collapsed:ie,onSelectData:ae,initialDataSurface:ce=!1,onLogout:ue,onDisconnect:D,disconnecting:fe,claudeConnected:O=!0,subAccounts:A,activeAccountId:Te,switchingAccount:Ee,onSwitchAccount:De,refreshAccounts:Oe,onOpenConversations:j}=e,M=oe(o),ke=(0,E.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,T.jsx)(xe,{size:12}),panel:()=>(0,T.jsx)(nt,{row:e,adminFetch:M,onError:e=>L({message:e,failed:!0})})}),[M]),Ae=p.productName,je=r||Ae,Me=typeof u==`string`?u:u===null?`name unavailable`:je,Ne=(Me.trim().charAt(0)||`?`).toUpperCase(),[Pe,Fe]=(0,E.useState)(ce?`data`:`sessions`),[Ie,Le]=(0,E.useState)(!1),[N,P]=(0,E.useState)(!1),Re=!ie&&(A?.length??0)>1&&!!De,F=A?.find(e=>e.isHouse)??null,ze=(0,E.useCallback)(()=>{if(F){if(F.accountId===Te){console.info(`[admin-ui] op=subaccount-switch-house anchor=brand-icon accountId=${F.accountId.slice(0,8)} switched=false reason=already-house`);return}console.info(`[admin-ui] op=subaccount-switch-house anchor=brand-icon accountId=${F.accountId.slice(0,8)} switched=true`),P(!1),De?.(F.accountId,`/`)}},[F,Te,De]),[I,L]=(0,E.useState)(null),[Be,R]=(0,E.useState)(null),[Ve,He]=(0,E.useState)(!1),[z,Ue]=(0,E.useState)([]),[B]=(0,E.useState)(()=>typeof window>`u`?null:new URLSearchParams(window.location.search).get(`session`)),[V,We]=(0,E.useState)(!1),[H,Ke]=(0,E.useState)(null),[U,qe]=(0,E.useState)(!1),[W,Je]=(0,E.useState)(!1),[G,Ye]=(0,E.useState)(!1),[Xe,Ze]=(0,E.useState)(null),[Qe,$e]=(0,E.useState)(new Set),et=(0,E.useRef)(new Map),[K,tt]=(0,E.useState)(!1),[q,rt]=(0,E.useState)(new Set),[it,st]=(0,E.useState)(!1),[lt,dt]=(0,E.useState)(null),[pt,mt]=(0,E.useState)(new Set),[J,ht]=(0,E.useState)(new Set),[gt,_t]=(0,E.useState)(new Set),[yt,wt]=(0,E.useState)(null),[Tt,Y]=(0,E.useState)(``),[Ot,kt]=(0,E.useState)(!1),[At,jt]=(0,E.useState)(null),[Mt,Nt]=(0,E.useState)(null),[Pt,Ft]=(0,E.useState)(!1),[It,Lt]=(0,E.useState)(null),[X,Rt]=(0,E.useState)(!1),[zt,Bt]=(0,E.useState)(!1),Vt=(0,E.useRef)(0);(0,E.useEffect)(()=>{if(!I)return;let e=setTimeout(()=>L(null),2500);return()=>clearTimeout(e)},[I]);let Ht=B!=null&&z.some(e=>e.sessionId===B);(0,E.useEffect)(()=>{B==null||!V||console.info(`[sidebar-sessions] op=select-highlight session=${B.slice(0,8)} matched=${Ht}`)},[B,Ht,V]);let Z=(0,E.useCallback)(async()=>{if(!o)return null;let e=++Vt.current;qe(!0),Ke(null);try{let t=await M(`/api/admin/sidebar-sessions`);if(!t.ok)throw Error(`status ${t.status}`);let n=await t.json(),r=n.sessions??[];return e===Vt.current?(Ue(r),Ze(n.accountId??null),We(!0),r):(console.info(`[admin-ui] sidebar-sessions-stale-response-dropped token=${e}`),r)}catch(t){let n=t instanceof Error?t.message:String(t);return e===Vt.current&&Ke(`Failed to load sessions: ${n}`),console.error(`[admin-ui] sidebar-sessions fetch failed: ${n}`),null}finally{e===Vt.current&&qe(!1)}},[o,M]);(0,E.useEffect)(()=>{!o||V||Z()},[o,V,Z]),(0,E.useEffect)(()=>{if(!o)return;let e=null;function t(){console.info(`[admin-ui] sidebar-refresh surface=sessions trigger=poll`),Z()}function n(){e===null&&(e=setInterval(t,Et))}function r(){e!==null&&(clearInterval(e),e=null)}function i(){document.hidden?r():(t(),n())}return document.hidden||n(),document.addEventListener(`visibilitychange`,i),()=>{r(),document.removeEventListener(`visibilitychange`,i)}},[o,Z]);let Ut=()=>{console.info(`[admin-ui] sidebar-refresh surface=sessions trigger=manual`),Z()},Wt=()=>{Fe(`data`),console.info(`[admin-ui] sidebar-nav surface=data collapsed=${ie}`),ae(),C()},Q=typeof window<`u`&&window.location?.pathname||`/`,Gt=Pe===`data`,Kt=typeof window<`u`&&window.location?.search||``,qt=new URLSearchParams(Kt),Jt=qt.has(`label`)&&!qt.has(`nodeId`),$=e=>{C(),window.location.href=e},Yt=[{key:`dashboard`,label:`Dashboard`,icon:(0,T.jsx)(x,{size:17,strokeWidth:1.75}),active:Q===`/`&&!Gt,onClick:()=>$(`/`)},{key:`chat`,label:`Chat`,icon:(0,T.jsx)(i,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/chat`),onClick:()=>$(`/chat`)},{key:`tasks`,label:`Tasks`,icon:(0,T.jsx)(ye,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/tasks`),onClick:()=>{re(),C()}},{key:`calendar`,label:`Calendar`,icon:(0,T.jsx)(a,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/calendar`),onClick:()=>$(`/calendar`)},{key:`routines`,label:`Routines`,icon:(0,T.jsx)(we,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/routines`),onClick:()=>$(`/routines`)},{key:`skills`,label:`Skills`,icon:(0,T.jsx)(Se,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/skills`),onClick:()=>$(`/skills`)},{key:`agents`,label:`Agents`,icon:(0,T.jsx)(he,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/agents`),onClick:()=>$(`/agents`)},{key:`data`,label:`Data`,icon:(0,T.jsx)(d,{size:17,strokeWidth:1.75}),active:Gt,onClick:Wt},{key:`container`,label:g().term,icon:(0,T.jsx)(b,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/graph`)&&Jt,onClick:()=>{y(),C()}},{key:`graph`,label:`Graph`,icon:(0,T.jsx)(Ce,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/graph`)&&!Jt,onClick:()=>$(`/graph`)},{key:`activity`,label:`Activity`,icon:(0,T.jsx)(s,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/activity`),onClick:()=>$(`/activity`)},{key:`browser`,label:`Browser`,icon:(0,T.jsx)(t,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/browser`),onClick:()=>$(`/browser`)}],Xt=(0,E.useCallback)(async e=>{if(pt.has(e.sessionId))return;mt(t=>{let n=new Set(t);return n.add(e.sessionId),n});let t=window.open(``,`_blank`);try{let n=await M(`/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=St(n.ok,n.status,{...r,sessionId:r.sessionId??e.sessionId});console.info(`[admin-ui] sidebar-session-resume sessionId=${e.sessionId} status=${n.status} outcome=${i.kind} slug=${r.slug??r.bridgeSessionId??`none`}`),i.kind===`navigate`?(C(),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}`),R(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}`),R({sessionId:e.sessionId,reason:r})}finally{mt(t=>{let n=new Set(t);return n.delete(e.sessionId),n})}},[M,C,pt]),Zt=(0,E.useCallback)(async e=>{let t=e.slice(0,8);for(let n=1;n<=xt.length;n++){await new Promise(e=>setTimeout(e,xt[n-1]));let r=await Z();if(r&&r.some(t=>t.sessionId===e)){console.info(`[admin-ui] sidebar-new-session-converged sessionId=${t} via=retry attempts=${n}`);return}}console.error(`[admin-ui] sidebar-new-session-converge-timeout sessionId=${t}`)},[Z]),Qt=(0,E.useCallback)(async e=>{if(!X){Rt(!0),console.info(`[admin-ui] new-session-modal op=submit surface=sidebar titleLen=${e.length}`);try{let t=await M(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({title:e})}),n=await t.json().catch(()=>({})),r=St(t.ok,t.status,n);console.info(`[admin-ui] sidebar-new-session-spawned status=${t.status} outcome=${r.kind} slug=${n.slug??n.bridgeSessionId??`none`}`),r.kind===`navigate`?r.sameOrigin?(console.info(`[admin-ui] new-session-modal op=navigate surface=sidebar sessionId=${(n.sessionId??``).slice(0,8)} titleSource=${n.titleSource??`none`}`),window.location.assign(r.url)):(window.open(r.url,`_blank`),n.sessionId?Zt(n.sessionId):console.error(`[admin-ui] sidebar-new-session-converge-skipped reason=no-session-id`)):t.status===503||r.reason===`claude-auth-dead`?(console.info(`[admin-ui] op=llm-action-blocked action=spawn reason=claude-disconnected`),Bt(!1),He(!0)):(console.error(`[admin-ui] sidebar-new-session-failed status=${t.status} reason=${r.reason}`),Bt(!1),R(r))}catch(e){let t=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-new-session-failed error=${t}`),Bt(!1),R({sessionId:null,reason:t})}finally{Rt(!1)}}},[M,X,Zt]),$t=(0,E.useCallback)((e,t)=>{e.stopPropagation(),dt(t)},[]),en=(0,E.useCallback)(async(e,t)=>{e.stopPropagation(),jt(t),Nt(null),Lt(null),Ft(!0);try{let e=await M(`/api/admin/session-usage?sessionId=${encodeURIComponent(t.sessionId)}`),n=await e.json().catch(()=>({}));e.ok?Nt(n):Lt(n.error??`status ${e.status}`)}catch(e){Lt(e instanceof Error?e.message:String(e))}finally{Ft(!1)}},[M]),tn=(0,E.useCallback)(async(e,t={})=>{let n=t.refresh??!0;if(Qe.has(e.sessionId))return!1;$e(t=>{let n=new Set(t);return n.add(e.sessionId),n});try{let t=await M(`/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`}`),L({message:`Delete failed: ${n.error??`status ${t.status}`}`,failed:!0}),!1}let r=await t.json();return console.info(`[admin-ui] sidebar-session-delete sessionId=${e.sessionId} live=${e.live} confirmed=true pidKilled=${r.pidKilled??`?`} deleted=${r.deleted??`?`}`),Ue(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}`),L({message:`Delete failed: ${n}`,failed:!0}),!1}finally{$e(t=>{let n=new Set(t);return n.delete(e.sessionId),n})}},[M,Qe,Z]),nn=(0,E.useCallback)(e=>{rt(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),rn=(0,E.useCallback)(()=>{tt(!1),rt(new Set)},[]),an=(0,E.useCallback)(async()=>{let e=[...q].map(e=>z.find(t=>t.sessionId===e)).filter(e=>!!e),t=e.filter(e=>e.live).length;console.info(`[admin-ui] sidebar-bulk-delete op=start count=${e.length} live=${t}`);let n=(await Promise.all(e.map(e=>tn(e,{refresh:!1})))).filter(Boolean).length;console.info(`[admin-ui] sidebar-bulk-delete op=done requested=${e.length} ok=${n} failed=${e.length-n}`),Z(),rn()},[q,z,tn,Z,rn]),on=(0,E.useCallback)(async(e,t)=>{if(e.stopPropagation(),!J.has(t.sessionId)){ht(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await M(`/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`}`),L({message:`Stop failed: ${n.error??`status ${e.status}`}`,failed:!0});return}console.info(`[admin-ui] sidebar-session-stop sessionId=${t.sessionId}`),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}`),L({message:`Stop failed: ${n}`,failed:!0})}finally{ht(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[M,J,Z]),sn=(0,E.useCallback)(async(e,t,n)=>{if(e.stopPropagation(),!gt.has(t.sessionId)){_t(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await M(`/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`}`),L({message:`${n===`archive`?`Archive`:`Unarchive`} failed: ${i}`,failed:!0});return}console.info(`[admin-ui] sidebar-session-archive sessionId=${t.sessionId} mode=${n}`),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}`),L({message:`${n===`archive`?`Archive`:`Unarchive`} failed: ${r}`,failed:!0})}finally{_t(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[M,gt,Z]),cn=(0,E.useCallback)(async e=>{let t=Tt.trim();if(!t){L({message:`Title can’t be empty`,failed:!0});return}if(t.length>bt){L({message:`Title too long (max ${bt})`,failed:!0});return}kt(!0);try{let n=await M(`/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}`),L({message:`Rename failed: ${r}`,failed:!0});return}console.info(`[admin-ui] sidebar-session-rename sessionId=${e.sessionId.slice(0,8)} outcome=ok`),wt(null),Y(``),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}`),L({message:`Rename failed: ${n}`,failed:!0})}finally{kt(!1)}},[M,Tt,Z]);return(0,T.jsxs)(`aside`,{className:`side`,children:[(0,T.jsxs)(`div`,{className:`side-brand`,children:[Re?(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`button`,{type:`button`,className:`side-brand-icon-btn`,"aria-label":`Switch to house account`,disabled:!F,onClick:ze,children:(0,T.jsx)(`img`,{className:`side-brand-icon`,src:le,alt:``,"aria-hidden":`true`})}),(0,T.jsxs)(`button`,{type:`button`,className:`side-brand-trigger`,"aria-haspopup":`menu`,"aria-expanded":N,"aria-label":`Switch sub-account`,onClick:()=>{let e=!N;P(e),e&&Oe?.(),console.info(`[admin-ui] op=subaccount-switcher-toggle anchor=brand-head open=${e} available=true accounts=${A?.length??0}`)},children:[(0,T.jsxs)(`span`,{className:`side-brand-lockup`,children:[(0,T.jsx)(`span`,{className:`side-brand-business`,children:je}),(0,T.jsx)(`span`,{className:`side-brand-product`,children:p.productName})]}),(0,T.jsx)(ge,{size:14,className:`side-brand-caret`,"aria-hidden":`true`})]})]}):(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`img`,{className:`side-brand-icon`,src:le,alt:``,"aria-hidden":`true`}),(0,T.jsxs)(`span`,{className:`side-brand-lockup`,children:[(0,T.jsx)(`span`,{className:`side-brand-business`,children:je}),(0,T.jsx)(`span`,{className:`side-brand-product`,children:p.productName})]})]}),N&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`div`,{className:`side-brand-scrim`,"aria-hidden":`true`,onClick:()=>P(!1)}),(0,T.jsx)(te,{open:N,accounts:A??[],activeAccountId:Te??null,switching:Ee??!1,onSelect:e=>De?.(e),onClose:()=>P(!1)})]})]}),(0,T.jsx)(`nav`,{className:`side-nav`,children:Yt.map(e=>(0,T.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,T.jsx)(`span`,{className:`label`,children:e.label}),(0,T.jsx)(`span`,{className:`kbd`})]},e.key))}),(()=>{let e=z.filter(e=>W?!0:!e.isSubagent).filter(e=>G?!0:!e.archived),t=z.some(e=>e.isSubagent),r=z.some(e=>e.archived);return(0,T.jsx)(`div`,{className:`side-sessions`,children:(0,T.jsxs)(`div`,{className:`side-list`,children:[(0,T.jsxs)(`div`,{className:`group-head`,children:[(0,T.jsx)(`span`,{children:`Sessions`}),(0,T.jsxs)(`span`,{className:`group-head-meta`,children:[(0,T.jsx)(`button`,{type:`button`,className:`group-head-select${K?` active`:``}`,"aria-pressed":K,title:K?`Exit select mode`:`Select multiple sessions to delete`,onClick:()=>{tt(e=>!e),rt(new Set),wt(null),Y(``)},children:`Select`}),(0,T.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh sessions`,"aria-label":`Refresh sessions`,onClick:Ut,disabled:U,children:(0,T.jsx)(n,{size:12,className:U?`spinning`:void 0})}),(0,T.jsx)(`span`,{children:U?`…`:String(e.length)}),(0,T.jsxs)(`button`,{type:`button`,className:`admin-btn-cta side-sessions-new`,onClick:()=>{console.info(`[admin-ui] new-session-modal op=open surface=sidebar default=applied`),Bt(!0)},disabled:X,"aria-busy":X,"aria-label":X?`Spawning session`:`New session`,title:X?`Spawning session`:`New session`,children:[X?(0,T.jsx)(f,{size:13,className:`spinning`}):(0,T.jsx)(se,{size:13}),(0,T.jsx)(`span`,{children:X?`Spawning…`:`New session`})]})]})]}),K&&(0,T.jsxs)(`div`,{className:`session-select-bar`,children:[(0,T.jsxs)(`span`,{className:`session-select-count`,children:[q.size,` selected`]}),(0,T.jsxs)(`button`,{type:`button`,className:`session-select-delete`,disabled:q.size===0,onClick:()=>st(!0),children:[`Delete `,q.size]}),(0,T.jsx)(`button`,{type:`button`,className:`session-select-cancel`,onClick:rn,children:`Cancel`})]}),Xe&&(0,T.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,T.jsx)(`code`,{children:Xe})}),(t||r)&&(0,T.jsxs)(`div`,{className:`artefact-filter-chips`,children:[t&&(0,T.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${W?` active`:``}`,"aria-pressed":W,onClick:()=>Je(e=>!e),title:W?`Hide subagent sessions`:`Show subagent sessions`,children:`Subagents`}),r&&(0,T.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${G?` active`:``}`,"aria-pressed":G,onClick:()=>Ye(e=>!e),title:G?`Hide archived sessions`:`Show archived sessions`,children:`Archived`})]}),H&&(0,T.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:H}),V&&!H&&e.length===0&&(0,T.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No sessions yet`}),e.map(e=>{let t=Ct(e.startedAt),n=pt.has(e.sessionId),r=Qe.has(e.sessionId),i=J.has(e.sessionId),a=gt.has(e.sessionId),o=n||r||i||a,s=()=>{window.location.assign(`/chat?session=${e.sessionId}`)},c=[{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,T.jsx)(ve,{size:12}),busy:n,onClick:()=>{Xt(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,T.jsx)(be,{size:12}),onClick:()=>{s()}},{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,T.jsx)(k,{size:12}),onClick:t=>{en(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,T.jsx)(w,{size:12}),busy:i,onClick:t=>{on(t,e)}}]:[],e.archived?{key:`unarchive`,label:`Unarchive session ${e.title}`,menuLabel:`Unarchive`,title:`Unarchive (move back to the active list)`,icon:(0,T.jsx)(pe,{size:12}),busy:a,onClick:t=>{sn(t,e,`unarchive`)}}:{key:`archive`,label:`Archive session ${e.title}`,menuLabel:`Archive`,title:`Archive (hide from the list, keeps the conversation resumable)`,icon:(0,T.jsx)(me,{size:12}),busy:a,onClick:t=>{sn(t,e,`archive`)}},{key:`rename`,label:`Rename session ${e.title}`,menuLabel:`Rename`,title:`Rename this session`,icon:(0,T.jsx)(m,{size:12}),busy:Ot&&yt===e.sessionId,onClick:t=>{t.stopPropagation(),wt(e.sessionId),Y(e.personName??e.title)}},{key:`delete`,label:`Delete session ${e.title}`,menuLabel:`Delete`,title:`Delete session (stops the process, removes the conversation)`,icon:(0,T.jsx)(ee,{size:12}),danger:!0,busy:r,onClick:t=>{$t(t,e)}},ke({sessionId:e.sessionId,model:e.model??null,title:e.personName??e.title})],l=e.channel===`whatsapp`?` conv-channel-whatsapp`:e.channel===`telegram`?` conv-channel-telegram`:``,u=e.channel===`whatsapp`||e.channel===`telegram`||e.channel===`webchat`,d=ne.includes(e.channel??``)&&e.senderId&&e.titleSource===`prefix`?_({operatorName:e.personName??null,whatsappName:e.whatsappName??null,senderId:e.senderId,title:e.title,channel:e.channel}):e.personName??e.title;return(0,T.jsxs)(`div`,{ref:t=>{let n=et.current;t?n.set(e.sessionId,t):n.delete(e.sessionId)},className:`conv conv-with-actions${l}${e.sessionId===B?` active`:``}`,children:[(0,T.jsxs)(`div`,{className:`conv-main-static conv-main-clickable`,role:`button`,tabIndex:0,"aria-label":`Open ${d} in webchat`,onClick:()=>{if(yt!==e.sessionId){if(K){nn(e.sessionId);return}s()}},onKeyDown:t=>{yt!==e.sessionId&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),K?nn(e.sessionId):s())},children:[K&&(0,T.jsx)(`span`,{className:`conv-select-check`,onClick:e=>e.stopPropagation(),children:(0,T.jsx)(de,{checked:q.has(e.sessionId),ariaLabel:`Select ${d}`,onChange:()=>nn(e.sessionId)})}),(0,T.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,T.jsxs)(`span`,{className:`conv-stack`,children:[(0,T.jsxs)(`span`,{className:`conv-name-line`,children:[u&&(0,T.jsx)(v,{channel:e.channel,size:13}),yt===e.sessionId?(0,T.jsx)(`input`,{className:`conv-name conv-name-edit`,autoFocus:!0,onFocus:e=>e.currentTarget.select(),value:Tt,disabled:Ot,"aria-label":`New title for session ${e.title}`,onChange:e=>Y(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),cn(e)):t.key===`Escape`&&(t.preventDefault(),wt(null),Y(``))},onBlur:()=>{yt===e.sessionId&&!Ot&&(wt(null),Y(``))}}):(0,T.jsx)(`span`,{className:`conv-name`,title:d,children:d})]}),(0,T.jsxs)(`span`,{className:`conv-timestamp`,children:[(0,T.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)}),t&&(0,T.jsxs)(`span`,{children:[` · `,t]})]})]})]}),!K&&(0,T.jsx)(Ge,{actions:c,disabled:o})]},e.sessionId)})]})})})(),(0,T.jsxs)(`div`,{className:`side-foot`,children:[(0,T.jsx)(`div`,{className:`avatar`,children:h?(0,T.jsx)(`img`,{src:h,alt:Me}):Ne}),(0,T.jsxs)(`div`,{className:`who`,children:[(0,T.jsx)(`span`,{className:`name`,children:Me}),(0,T.jsx)(Dt,{})]}),(0,T.jsx)(`button`,{type:`button`,className:`side-foot-kebab`,"aria-label":`Account menu`,"aria-haspopup":`menu`,"aria-expanded":Ie,onClick:()=>Le(e=>!e),children:(0,T.jsx)(_e,{size:16})}),Ie&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`div`,{className:`side-foot-menu-scrim`,"aria-hidden":`true`,onClick:()=>Le(!1)}),(0,T.jsx)(`div`,{className:`side-foot-menu`,role:`menu`,children:(0,T.jsx)(S,{variant:`admin`,onCloseMenu:()=>Le(!1),onLogout:ue??(()=>{}),onDisconnect:D,disconnecting:fe,claudeConnected:O,onConnectClaude:c,cacheKey:o,onOpenConversations:j})})]})]}),I&&(0,T.jsx)(`div`,{className:`copy-toast${I.failed?` copy-toast-failed`:``}`,role:`status`,children:I.message}),(0,T.jsx)(ct,{open:zt,pending:X,onConfirm:e=>{Qt(e)},onCancel:e=>{console.info(`[admin-ui] new-session-modal op=cancel surface=sidebar via=${e}`),Bt(!1)}}),(0,T.jsx)(ut,{error:Be,onClose:()=>R(null)}),(0,T.jsx)(ft,{open:Ve,onConnect:()=>{He(!1),c?.()},onClose:()=>He(!1)}),(0,T.jsx)(at,{target:lt,anchorEl:lt?et.current.get(lt.sessionId)??null:null,onCancel:()=>dt(null),onConfirm:()=>{let e=lt;dt(null),e&&tn(e)}},lt?.sessionId??`none`),(0,T.jsx)(ot,{open:it,count:q.size,liveCount:z.filter(e=>q.has(e.sessionId)&&e.live).length,onConfirm:()=>{st(!1),an()},onCancel:()=>st(!1)}),(0,T.jsx)(vt,{show:At!==null,onClose:()=>{jt(null),Nt(null),Lt(null)},anchorEl:At?et.current.get(At.sessionId)??null:null,sessionId:At?.sessionId??null,summary:Mt,loading:Pt,error:It},At?.sessionId??`none`)]})}var Tt=5e3,Et=3e4;function Dt(){let[e,t]=(0,E.useState)(null);if((0,E.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()},Tt))}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,T.jsxs)(`span`,{className:d.join(` `),role:`status`,"aria-label":`host CPU and RAM`,children:[(0,T.jsxs)(`span`,{className:i?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`CPU `,u(n)]}),` · `,(0,T.jsxs)(`span`,{className:o?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`RAM `,u(r)]})]})}var Y=`admin-sidebar-collapsed`,Ot=`admin-sidebar-drawer-open`,kt=1080;function At(){if(typeof window>`u`)return!1;let e=null;try{e=window.sessionStorage.getItem(Y)}catch{e=null}return e===null?typeof window.matchMedia==`function`?window.matchMedia(`(min-width: 721px) and (max-width: ${kt}px)`).matches:!1:e===`1`}function jt(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(Y,`1`):window.sessionStorage.removeItem(Y)}catch{}}function Mt(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(Ot)===`1`}catch{return!1}}function Nt(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(Ot,`1`):window.sessionStorage.removeItem(Ot)}catch{}}function Pt(e){let[t,n]=(0,E.useState)(()=>typeof window>`u`||typeof window.matchMedia!=`function`?!1:window.matchMedia(e).matches);return(0,E.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let t=window.matchMedia(e),r=()=>n(t.matches);return r(),t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t}var Ft=720;function It(e,t){return e===`/`?{via:`in-place`}:{via:`navigate`,href:`/?wa=${encodeURIComponent(t.remoteJid??``)}&acct=${encodeURIComponent(t.accountId??``)}`}}function Lt(e){return e===`/`?{via:`in-place`}:{via:`navigate`,href:`/?data=1`}}function X(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 Rt(e,t){return e===`/`?new URLSearchParams(t).has(`data`):!1}function zt(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`}function Bt(e){let{cacheKey:t,businessName:n,variant:r=`admin`,onLogout:i,onDisconnect:a,disconnecting:o,claudeConnected:s,onConnectClaude:c,userName:l,userAvatar:u,role:d,onOpenConversations:f,children:p,footer:m}=e,{subAccounts:_,activeAccountId:ee,switching:v,switchAccount:te,refreshAccounts:b}=ae(t),[x,S]=(0,E.useState)([]),ne=(0,E.useCallback)(e=>{S(t=>t.filter(t=>t.waMessageId!==e))},[]);(0,E.useEffect)(()=>{if(!t)return;let e=null;try{e=new EventSource(h(`/api/admin/events`,t)),e.addEventListener(je,e=>{try{let t=JSON.parse(e.data);if(!t||typeof t.waMessageId!=`string`)return;S(e=>e.some(e=>e.waMessageId===t.waMessageId)?e:[...e,t])}catch{}}),e.onerror=()=>{console.error(`[admin-ui] wa-notify stream error`)}}catch(e){console.error(`[admin-ui] wa-notify unavailable reason=${e instanceof Error?e.message:String(e)}`)}return()=>{e?.close()}},[t]);let[C,ie]=(0,E.useState)(!0);(0,E.useEffect)(()=>{if(s!==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||ie(n.auth_status!==`dead`&&n.auth_status!==`missing`)}catch{}};t();let n=setInterval(t,6e4);return()=>{e=!0,clearInterval(n)}},[s,r]);let oe=s??C,se=c??(()=>{window.location.assign(`/?connect=claude`)}),[w,ce]=(0,E.useState)(()=>At()),[le,ue]=(0,E.useState)(!1),de=(0,E.useRef)(!0);(0,E.useEffect)(()=>{if(de.current){de.current=!1;return}ue(!0);let e=setTimeout(()=>ue(!1),260);return()=>clearTimeout(e)},[w]);let[D,fe]=(0,E.useState)(()=>Mt()),O=Pt(`(max-width: ${Ft}px)`),[pe,me]=(0,E.useState)(()=>typeof window>`u`||Rt(window.location.pathname,window.location.search)?null:X(window.location.pathname,window.location.search)),[he,ge]=(0,E.useState)(()=>typeof window>`u`?!1:Rt(window.location.pathname,window.location.search)),[_e]=(0,E.useState)(()=>he),ve=(0,E.useCallback)(e=>{jt(e),ce(e)},[]),k=(0,E.useCallback)(e=>{Nt(e),fe(e)},[]);(0,E.useEffect)(()=>{if(typeof window>`u`)return;let e=window.location?.pathname??``;console.info(`[admin-ui] shell-mount route=${e} variant=${r} sidebar=${r===`operator`?`none`:`present`} collapsed=${w} drawer=${D}`)},[]),(0,E.useEffect)(()=>{typeof window>`u`||!pe||(console.info(`[admin-ui] wa-hydrate route=/ remoteJid=${pe.remoteJid??``}`),window.history.replaceState(null,``,`/`))},[]),(0,E.useEffect)(()=>{typeof window>`u`||!he||(console.info(`[admin-ui] data-hydrate route=/`),window.history.replaceState(null,``,`/`))},[]);let ye=(0,E.useCallback)(e=>{if(ge(!1),e===null){me(null);return}let t=typeof window<`u`?window.location.pathname:`/`,n=It(t,e);console.info(`[admin-ui] wa-open route=${t} via=${n.via} sessionId=${e.sessionId.slice(0,8)}`),n.via===`in-place`?me(e):window.location.href=n.href},[]),be=(0,E.useCallback)(()=>{let e=typeof window<`u`?window.location.pathname:`/`,t=Lt(e);if(console.info(`[admin-ui] data-open route=${e} via=${t.via}`),t.via===`navigate`){window.location.href=t.href;return}me(null),ge(!0)},[]),A=O?D:!w,xe=(0,E.useCallback)(()=>{if(!(typeof window>`u`))if(window.matchMedia(`(max-width: ${Ft}px)`).matches){let e=D;console.info(`[admin-ui] header-sidebar-toggle from=${e?`open`:`closed`} mode=drawer`),k(!e)}else{let e=w;console.info(`[admin-ui] header-sidebar-toggle from=${e?`closed`:`open`} mode=collapse`),ve(!e)}},[w,D,ve,k]),Se=(0,E.useCallback)(e=>{let t=zt(e,r);console.info(`[admin-ui] header-menu-nav target=${e} dest=${t}`),window.location.href=t},[r]),Ce={collapsed:w,mobileDrawerOpen:D,sidebarOpen:A,onToggleSidebar:xe,setMobileDrawerOpen:k,selectedWhatsapp:pe,onClearWhatsapp:()=>me(null),onSelectWhatsappConversation:ye,dataOpen:he};return r===`operator`?(0,T.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[v&&(0,T.jsx)(y,{surface:`switch`}),(0,T.jsx)(re,{businessName:n,variant:r,onNavigate:Se,onOpenConversations:f,onToggleSidebar:xe,sidebarOpen:A,onLogout:i,onDisconnect:a,disconnecting:o,cacheKey:t,subAccounts:_,activeAccountId:ee,switchingAccount:v,onSwitchAccount:te,refreshAccounts:b}),(0,T.jsx)(`div`,{className:`platform platform-operator`,children:typeof p==`function`?p(Ce):p}),(0,T.jsx)(N,{variant:`operator`,onOpenConversations:f}),m,(0,T.jsx)(Ae,{frames:x,onExpire:ne})]}):(0,T.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[v&&(0,T.jsx)(y,{surface:`switch`}),(0,T.jsxs)(`div`,{className:`platform${D?` menu-open`:``}${!O&&w?` sidebar-collapsed`:``}${le?` sidebar-animating`:``}`,"data-artefact":`closed`,children:[(0,T.jsx)(wt,{businessName:n,cacheKey:t,onConnectClaude:se,role:d??null,userName:l,userAvatar:u??null,onSelectProjects:()=>{window.location.href=`/graph?label=${g().label}`},onSelectTasks:()=>{window.location.href=`/tasks`},onCloseMobileDrawer:()=>k(!1),collapsed:w,mobileDrawerOpen:D,onSelectData:be,onCloseData:()=>ge(!1),initialDataSurface:_e,onLogout:i,onDisconnect:a,disconnecting:o,claudeConnected:oe,subAccounts:_,activeAccountId:ee,switchingAccount:v,onSwitchAccount:te,refreshAccounts:b,onOpenConversations:f}),!O&&(0,T.jsx)(He,{}),(0,T.jsx)(Pe,{sidebarOpen:A,onToggleSidebar:xe,claudeConnected:oe,onConnectClaude:se}),typeof p==`function`?p(Ce):p]}),D&&(0,T.jsx)(`div`,{className:`sidebar-backdrop menu-open`,"aria-hidden":`true`,onClick:()=>k(!1)}),(0,T.jsx)(N,{}),m,(0,T.jsx)(Ae,{frames:x,onExpire:ne})]})}export{he as C,de as D,O as E,ue as O,ge as S,pe as T,be as _,dt as a,ve as b,H as c,W as d,I as f,xe as g,Se as h,ft as i,Ke as l,we as m,Pt as n,ct as o,ze as p,St as r,U as s,Bt as t,Ye as u,ye as v,me as w,_e as x,k as y};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{A as t,H as n,J as r,O as i,v as a}from"./useSubAccountSwitcher-HjQZjJBr.js";var o=`/cdp-screencast`;function s(){return{format:`jpeg`,quality:60,maxWidth:1280,maxHeight:800,everyNthFrame:1}}function c(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 l(e){return e===0?`left`:e===1?`middle`:e===2?`right`:`none`}function u(e,t){let n=l(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 d(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 f={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},p={Enter:`\r`,Tab:` `};function m(e,t){let n=t.key.length===1,r=n?t.key.toUpperCase().charCodeAt(0):f[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:p[t.key];e!==void 0&&(i.text=e,i.unmodifiedText=e)}return i}function h(e,t,n){return`${e.protocol===`https:`?`wss`:`ws`}://${e.host}${o}?targetId=${encodeURIComponent(t)}&sid=${encodeURIComponent(n)}`}var g=class{nextId=1;startId=null;frames=0;stopped=!1;lastMetadata=null;lastInputLogAtMs=null;inputsSinceLog=0;constructor(e,t){this.ws=e,this.opts=t}frameCount(){return this.frames}start(){let e=s();this.startId=this.send(`Page.startScreencast`,e)}stop(){if(this.stopped)return;this.stopped=!0;let e=this.send(`Page.stopScreencast`,{})!==null;this.opts.onLog(`teardown`,{stopSent:e})}handleMessage(e){let t;try{t=JSON.parse(e)}catch{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=s();this.opts.onLog(`screencast-started`,{format:e.format,everyNthFrame:e.everyNthFrame})}return}if(t.method!==`Page.screencastFrame`||this.stopped)return;let n=t.params;if(typeof n?.data!=`string`||typeof n?.metadata!=`object`||n.metadata===null)return;let r=n.metadata;typeof n.sessionId==`number`&&this.send(`Page.screencastFrameAck`,{sessionId:n.sessionId}),this.frames+=1,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=c(t.canvasX,t.canvasY,t.rendered,n);this.send(`Input.dispatchMouseEvent`,u(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=c(e.canvasX,e.canvasY,e.rendered,t);this.send(`Input.dispatchMouseEvent`,d({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`,m(e,t)),this.logInput(`key`)}logInput(e){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}}},_=e(r(),1),v=n();function y(e){return(e.altKey?1:0)|(e.ctrlKey?2:0)|(e.metaKey?4:0)|(e.shiftKey?8:0)}function b({preferTargetId:e=null,cacheKey:n=null}={}){let[r,o]=(0,_.useState)(`probing`),[s,c]=(0,_.useState)([]),[l,u]=(0,_.useState)(null),[d,f]=(0,_.useState)(!1),[p,m]=(0,_.useState)(null),b=a(n),x=(0,_.useRef)(null),S=(0,_.useRef)(null),C=(0,_.useRef)(``),w=(0,_.useRef)(e);w.current=e,C.current||=`sc-${Math.random().toString(36).slice(2,10)}`;let T=(0,_.useCallback)((e,t={})=>{b(`/api/admin/browser/screencast-event`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({sid:C.current,op:e,...t})}).catch(()=>{})},[b]),E=(0,_.useCallback)(async()=>{try{let e=await b(`/api/admin/browser/screencast-targets`);if(!e.ok){o(`unavailable`);return}let t=await e.json().catch(()=>({})),n=Array.isArray(t.targets)?t.targets:[];if(c(n),n.length===0){u(null),o(`no-tabs`);return}let r=w.current;u(e=>r&&n.some(e=>e.id===r)?r:e&&n.some(t=>t.id===e)?e:n[0].id),o(`live`)}catch{o(`unavailable`)}},[b]);(0,_.useEffect)(()=>{T(`request`),E()},[E,T]);let D=(0,_.useRef)(null);(0,_.useEffect)(()=>{if(e){if(s.some(t=>t.id===e)){u(e);return}D.current!==e&&(D.current=e,E())}},[e,s,E]);let O=(0,_.useCallback)(e=>{let t=x.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}`},[]);(0,_.useEffect)(()=>{if(r!==`live`||!l)return;let e=h({protocol:window.location.protocol,host:window.location.host},l,C.current),t=new WebSocket(e),n=new g(t,{onFrame:O,onLog:T});return S.current=n,t.addEventListener(`open`,()=>n.start()),t.addEventListener(`message`,e=>{typeof e.data==`string`&&n.handleMessage(e.data)}),()=>{n.stop(),t.close(),S.current=null}},[r,l,O,T]);let k=(0,_.useCallback)(e=>t=>{let n=x.current;if(!n)return;let r=n.getBoundingClientRect();S.current?.dispatchMouse(e,{canvasX:t.clientX-r.left,canvasY:t.clientY-r.top,rendered:{width:r.width,height:r.height},button:e===`mouseMoved`?-1:t.button,buttons:t.buttons,modifiers:y(t)})},[]);(0,_.useEffect)(()=>{let e=x.current;if(!e)return;let t=t=>{t.preventDefault();let n=e.getBoundingClientRect();S.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:y(t)})};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[r]);let A=(0,_.useCallback)(e=>t=>{t.preventDefault(),S.current?.dispatchKey(e,{key:t.key,code:t.code,modifiers:y(t)})},[]),j=(0,_.useCallback)(async()=>{f(!0),m(null);try{let e=await b(`/api/admin/browser/launch`,{method:`POST`});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error||`Launch failed (${e.status})`)}await E()}catch(e){m(e instanceof Error?e.message:String(e))}finally{f(!1)}},[b,E]);return r===`probing`?(0,v.jsx)(`div`,{className:`cdp-screencast`,children:(0,v.jsxs)(`div`,{className:`data-loading`,children:[(0,v.jsx)(i,{size:18,className:`spin`}),` Connecting to the device browser…`]})}):r===`unavailable`?(0,v.jsx)(`div`,{className:`cdp-screencast`,children:(0,v.jsxs)(`div`,{className:`cdp-screencast__unavailable`,children:[(0,v.jsx)(t,{size:28,strokeWidth:1.75}),(0,v.jsx)(`p`,{children:`The device browser is not reachable.`})]})}):(0,v.jsxs)(`div`,{className:`cdp-screencast`,children:[(0,v.jsxs)(`div`,{className:`cdp-screencast__toolbar`,children:[(0,v.jsxs)(`button`,{type:`button`,className:`cdp-screencast__btn`,onClick:j,disabled:d,children:[d?(0,v.jsx)(i,{size:14,className:`spin`}):(0,v.jsx)(t,{size:14}),` Launch browser`]}),p&&(0,v.jsx)(`span`,{className:`cdp-screencast__error`,children:p})]}),r===`no-tabs`?(0,v.jsxs)(`div`,{className:`cdp-screencast__unavailable`,children:[(0,v.jsx)(t,{size:28,strokeWidth:1.75}),(0,v.jsx)(`p`,{children:`No open tabs on the device browser.`})]}):(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(`div`,{className:`cdp-screencast__tabs`,children:s.map(e=>(0,v.jsx)(`button`,{type:`button`,className:e.id===l?`cdp-screencast__tab is-active`:`cdp-screencast__tab`,onClick:()=>u(e.id),title:e.url,children:e.title},e.id))}),(0,v.jsx)(`div`,{className:`cdp-screencast__viewport`,children:(0,v.jsx)(`canvas`,{ref:x,className:`cdp-screencast__canvas`,tabIndex:0,onMouseDown:k(`mousePressed`),onMouseUp:k(`mouseReleased`),onMouseMove:k(`mouseMoved`),onKeyDown:A(`keyDown`),onKeyUp:A(`keyUp`)})})]})]})}export{b as t};
1
+ import{o as e}from"./chunk-CltuBf4Z.js";import{A as t,H as n,J as r,O as i,v as a}from"./useSubAccountSwitcher-BEwQMRMo.js";var o=`/cdp-screencast`;function s(){return{format:`jpeg`,quality:60,maxWidth:1280,maxHeight:800,everyNthFrame:1}}function c(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 l(e){return e===0?`left`:e===1?`middle`:e===2?`right`:`none`}function u(e,t){let n=l(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 d(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 f={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},p={Enter:`\r`,Tab:` `};function m(e,t){let n=t.key.length===1,r=n?t.key.toUpperCase().charCodeAt(0):f[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:p[t.key];e!==void 0&&(i.text=e,i.unmodifiedText=e)}return i}function h(e,t,n){return`${e.protocol===`https:`?`wss`:`ws`}://${e.host}${o}?targetId=${encodeURIComponent(t)}&sid=${encodeURIComponent(n)}`}var g=class{nextId=1;startId=null;frames=0;stopped=!1;lastMetadata=null;lastInputLogAtMs=null;inputsSinceLog=0;constructor(e,t){this.ws=e,this.opts=t}frameCount(){return this.frames}start(){let e=s();this.startId=this.send(`Page.startScreencast`,e)}stop(){if(this.stopped)return;this.stopped=!0;let e=this.send(`Page.stopScreencast`,{})!==null;this.opts.onLog(`teardown`,{stopSent:e})}handleMessage(e){let t;try{t=JSON.parse(e)}catch{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=s();this.opts.onLog(`screencast-started`,{format:e.format,everyNthFrame:e.everyNthFrame})}return}if(t.method!==`Page.screencastFrame`||this.stopped)return;let n=t.params;if(typeof n?.data!=`string`||typeof n?.metadata!=`object`||n.metadata===null)return;let r=n.metadata;typeof n.sessionId==`number`&&this.send(`Page.screencastFrameAck`,{sessionId:n.sessionId}),this.frames+=1,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=c(t.canvasX,t.canvasY,t.rendered,n);this.send(`Input.dispatchMouseEvent`,u(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=c(e.canvasX,e.canvasY,e.rendered,t);this.send(`Input.dispatchMouseEvent`,d({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`,m(e,t)),this.logInput(`key`)}logInput(e){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}}},_=e(r(),1),v=n();function y(e){return(e.altKey?1:0)|(e.ctrlKey?2:0)|(e.metaKey?4:0)|(e.shiftKey?8:0)}function b({preferTargetId:e=null,cacheKey:n=null}={}){let[r,o]=(0,_.useState)(`probing`),[s,c]=(0,_.useState)([]),[l,u]=(0,_.useState)(null),[d,f]=(0,_.useState)(!1),[p,m]=(0,_.useState)(null),b=a(n),x=(0,_.useRef)(null),S=(0,_.useRef)(null),C=(0,_.useRef)(``),w=(0,_.useRef)(e);w.current=e,C.current||=`sc-${Math.random().toString(36).slice(2,10)}`;let T=(0,_.useCallback)((e,t={})=>{b(`/api/admin/browser/screencast-event`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({sid:C.current,op:e,...t})}).catch(()=>{})},[b]),E=(0,_.useCallback)(async()=>{try{let e=await b(`/api/admin/browser/screencast-targets`);if(!e.ok){o(`unavailable`);return}let t=await e.json().catch(()=>({})),n=Array.isArray(t.targets)?t.targets:[];if(c(n),n.length===0){u(null),o(`no-tabs`);return}let r=w.current;u(e=>r&&n.some(e=>e.id===r)?r:e&&n.some(t=>t.id===e)?e:n[0].id),o(`live`)}catch{o(`unavailable`)}},[b]);(0,_.useEffect)(()=>{T(`request`),E()},[E,T]);let D=(0,_.useRef)(null);(0,_.useEffect)(()=>{if(e){if(s.some(t=>t.id===e)){u(e);return}D.current!==e&&(D.current=e,E())}},[e,s,E]);let O=(0,_.useCallback)(e=>{let t=x.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}`},[]);(0,_.useEffect)(()=>{if(r!==`live`||!l)return;let e=h({protocol:window.location.protocol,host:window.location.host},l,C.current),t=new WebSocket(e),n=new g(t,{onFrame:O,onLog:T});return S.current=n,t.addEventListener(`open`,()=>n.start()),t.addEventListener(`message`,e=>{typeof e.data==`string`&&n.handleMessage(e.data)}),()=>{n.stop(),t.close(),S.current=null}},[r,l,O,T]);let k=(0,_.useCallback)(e=>t=>{let n=x.current;if(!n)return;let r=n.getBoundingClientRect();S.current?.dispatchMouse(e,{canvasX:t.clientX-r.left,canvasY:t.clientY-r.top,rendered:{width:r.width,height:r.height},button:e===`mouseMoved`?-1:t.button,buttons:t.buttons,modifiers:y(t)})},[]);(0,_.useEffect)(()=>{let e=x.current;if(!e)return;let t=t=>{t.preventDefault();let n=e.getBoundingClientRect();S.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:y(t)})};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[r]);let A=(0,_.useCallback)(e=>t=>{t.preventDefault(),S.current?.dispatchKey(e,{key:t.key,code:t.code,modifiers:y(t)})},[]),j=(0,_.useCallback)(async()=>{f(!0),m(null);try{let e=await b(`/api/admin/browser/launch`,{method:`POST`});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error||`Launch failed (${e.status})`)}await E()}catch(e){m(e instanceof Error?e.message:String(e))}finally{f(!1)}},[b,E]);return r===`probing`?(0,v.jsx)(`div`,{className:`cdp-screencast`,children:(0,v.jsxs)(`div`,{className:`data-loading`,children:[(0,v.jsx)(i,{size:18,className:`spin`}),` Connecting to the device browser…`]})}):r===`unavailable`?(0,v.jsx)(`div`,{className:`cdp-screencast`,children:(0,v.jsxs)(`div`,{className:`cdp-screencast__unavailable`,children:[(0,v.jsx)(t,{size:28,strokeWidth:1.75}),(0,v.jsx)(`p`,{children:`The device browser is not reachable.`})]})}):(0,v.jsxs)(`div`,{className:`cdp-screencast`,children:[(0,v.jsxs)(`div`,{className:`cdp-screencast__toolbar`,children:[(0,v.jsxs)(`button`,{type:`button`,className:`cdp-screencast__btn`,onClick:j,disabled:d,children:[d?(0,v.jsx)(i,{size:14,className:`spin`}):(0,v.jsx)(t,{size:14}),` Launch browser`]}),p&&(0,v.jsx)(`span`,{className:`cdp-screencast__error`,children:p})]}),r===`no-tabs`?(0,v.jsxs)(`div`,{className:`cdp-screencast__unavailable`,children:[(0,v.jsx)(t,{size:28,strokeWidth:1.75}),(0,v.jsx)(`p`,{children:`No open tabs on the device browser.`})]}):(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(`div`,{className:`cdp-screencast__tabs`,children:s.map(e=>(0,v.jsx)(`button`,{type:`button`,className:e.id===l?`cdp-screencast__tab is-active`:`cdp-screencast__tab`,onClick:()=>u(e.id),title:e.url,children:e.title},e.id))}),(0,v.jsx)(`div`,{className:`cdp-screencast__viewport`,children:(0,v.jsx)(`canvas`,{ref:x,className:`cdp-screencast__canvas`,tabIndex:0,onMouseDown:k(`mousePressed`),onMouseUp:k(`mouseReleased`),onMouseMove:k(`mouseMoved`),onKeyDown:A(`keyDown`),onKeyUp:A(`keyUp`)})})]})]})}export{b as t};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{G as t,H as n,I as r,J as i,K as a,_ as o,g as s,n as c}from"./useSubAccountSwitcher-HjQZjJBr.js";import{D as l,E as u,O as d,t as f}from"./AdminShell-Cbk0TL1B.js";import{t as p}from"./triangle-alert-CedsrgME.js";var m=a(),h=e(i(),1),g=n(),_=`—`;function v(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 y={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.`},b=new Set([`never-run`,`never-succeeded`,`failing`,`stalled`]),x=10;function S(e){return e===null||!Number.isFinite(e)?_:`${e.toFixed(1)}%`}function C(e){return e<6e4?`${Math.round(e/1e3)}s`:e<36e5?`${Math.round(e/6e4)}m`:`${Math.round(e/36e5)}h`}function w(e,t){if(e===null)return _;let n=t-e;return n<0?`in ${C(-n)}`:n<6e4?`${Math.round(n/1e3)}s ago`:n<36e5?`${Math.round(n/6e4)}m ago`:`${Math.round(n/36e5)}h ago`}function T(e,t){if(e===null)return _;let n=e-t;return n>=0?`in ${C(n)}`:`overdue by ${C(-n)}`}function E({loops:e,nowMs:t=Date.now()}){let[n,r]=(0,h.useState)(!1);if(!e)return(0,g.jsxs)(`section`,{className:`activity-loops`,children:[(0,g.jsx)(`h2`,{className:`activity-loops-heading`,children:`Scheduled work`}),(0,g.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=>b.has(e.state)),o=e.rows.filter(e=>!b.has(e.state)&&typeof e.cpuPct==`number`&&e.cpuPct>=x),s=n?e.rows:[...a,...o];return(0,g.jsxs)(`section`,{className:`activity-loops`,children:[(0,g.jsx)(`h2`,{className:`activity-loops-heading`,children:`Scheduled work`}),(0,g.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,g.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,g.jsxs)(`p`,{className:`activity-loops-cpu`,children:[`Server process at `,e.processPct.toFixed(1),`% of one core`,typeof e.attributedPct==`number`&&(0,g.jsxs)(g.Fragment,{children:[` · these loops explain `,e.attributedPct.toFixed(1),`%`]}),typeof e.unattributedPct==`number`&&e.unattributedPct>=1&&(0,g.jsxs)(g.Fragment,{children:[` · `,(0,g.jsxs)(`strong`,{children:[e.unattributedPct.toFixed(1),`% is not from these loops`]})]})]}),i>0&&(0,g.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,g.jsx)(`div`,{className:`activity-table-scroll`,children:(0,g.jsxs)(`table`,{className:`activity-table`,children:[(0,g.jsx)(`thead`,{children:(0,g.jsxs)(`tr`,{children:[(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Loop`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`State`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Every`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Last run`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Last OK`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Took`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`CPU`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Runs`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Produced`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Next due`})]})}),(0,g.jsx)(`tbody`,{children:s.map(e=>(0,g.jsxs)(`tr`,{className:b.has(e.state)?`activity-loop-row activity-loop-unhealthy`:`activity-loop-row`,children:[(0,g.jsx)(`td`,{className:`activity-td`,children:e.name}),(0,g.jsx)(`td`,{className:`activity-td`,title:y[e.state],children:(0,g.jsxs)(`span`,{className:`activity-state`,children:[(0,g.jsx)(`span`,{className:e.state===`ok`?`activity-state-dot is-healthy`:b.has(e.state)?`activity-state-dot is-unhealthy`:`activity-state-dot`,"aria-hidden":`true`}),v(e.state)]})}),(0,g.jsx)(`td`,{className:`activity-td activity-num`,children:C(e.intervalMs)}),(0,g.jsx)(`td`,{className:`activity-td activity-num`,children:w(e.lastStartMs,t)}),(0,g.jsx)(`td`,{className:`activity-td activity-num`,children:w(e.lastSuccessMs,t)}),(0,g.jsx)(`td`,{className:`activity-td activity-num`,children:e.lastDurationMs===null?_:`${e.lastDurationMs} ms`}),(0,g.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:S(e.cpuPct)}),(0,g.jsxs)(`td`,{className:`activity-td activity-num`,children:[e.successCount,`/`,e.runCount]}),(0,g.jsx)(`td`,{className:`activity-td activity-loop-note`,children:(0,g.jsx)(`span`,{className:`activity-loop-note-text`,title:e.lastError??e.lastNote??void 0,children:e.lastError??e.lastNote??_})}),(0,g.jsx)(`td`,{className:`activity-td activity-num`,children:T(e.nextDueMs,t)})]},e.name))})]})}),(0,g.jsxs)(`dl`,{className:`activity-legend`,children:[(0,g.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,g.jsx)(`dt`,{className:`activity-legend-term`,children:`Runs`}),(0,g.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,g.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,g.jsx)(`dt`,{className:`activity-legend-term`,children:`CPU`}),(0,g.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,g.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,g.jsx)(`dt`,{className:`activity-legend-term`,children:_}),(0,g.jsx)(`dd`,{className:`activity-legend-def`,children:`Not measured. It does not mean zero.`})]})]})]})}var D=`maxy-admin-session-key`;function O(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 N(e,t){let n=t?.[e];return n&&n.trim()!==``?n:e.slice(0,8)}var P=`—`;function F(e){if(e===null||!Number.isFinite(e)||e<0)return P;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 I(e){return e===null||!Number.isFinite(e)?P:`${(e/1024/1024).toFixed(1)} GB`}function L(e,t){if(!e)return P;let n=Date.parse(e);if(!Number.isFinite(n))return P;let r=new Date(n),i=new Date(t),a=`${String(r.getHours()).padStart(2,`0`)}:${String(r.getMinutes()).padStart(2,`0`)}`;return r.getFullYear()===i.getFullYear()&&r.getMonth()===i.getMonth()&&r.getDate()===i.getDate()?a:`${r.getDate()} ${r.toLocaleString(`en-GB`,{month:`short`})} ${a}`}function R(e){return e===null||!Number.isFinite(e)?P:`${e.toFixed(1)}%`}function z(e){return e===null||!Number.isFinite(e)?P: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)?P:`£${e.toFixed(2)}`}function V(e){if(e===null||!Number.isFinite(e)||e<0)return P;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 ee(e,t){return{from:U(new Date(t-(e-1)*864e5)),to:U(new Date(t))}}function K(e){return new Date(`${e}T00:00:00.000Z`).toLocaleString(`en-GB`,{month:`long`,year:`numeric`,timeZone:`UTC`})}function q(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 J(e,t,n){switch(e){case`title`:return t.title??t.sessionId.slice(0,8);case`model`:return t.model??P;case`status`:return t.status??P;case`activeMsInRange`:return V(t.activeMsInRange);case`ageMs`:return F(t.ageMs);case`lastMessageAt`:return L(t.lastMessageAt,n);case`turnCount`:return t.turnCount===null?P:`${t.turnCount}${t.turnCountCapped?`+`:``}`;case`rssKb`:return I(t.rssKb);case`cpuPct`:return R(t.cpuPct);case`tokensInRange`:return z(t.tokensInRange);case`costGbp`:return B(t.costGbp);default:return P}}function Y({adminFetch:e,cacheKey:t}){let[n,i]=(0,h.useState)(null),[a,o]=(0,h.useState)(null),[d,f]=(0,h.useState)(!1),[m,_]=(0,h.useState)(`lastMessageAt`),[v,y]=(0,h.useState)(-1),[b,x]=(0,h.useState)(()=>W(new Date)),[S,C]=(0,h.useState)(!0),[w,T]=(0,h.useState)(!0),[D,I]=(0,h.useState)(!1),L=(0,h.useCallback)(async(e,n)=>{t&&await c(t,e)&&(console.info(`[admin-ui] activity-card-open account=${e.slice(0,8)} session=${n.slice(0,8)}`),window.location.assign(`/chat?session=${encodeURIComponent(n)}`))},[t]),R=(0,h.useRef)(!1),z=(0,h.useRef)(void 0),B=(0,h.useCallback)(async t=>{if(R.current){z.current=t;return}R.current=!0;try{let n=await e(`/api/admin/activity${t?`?from=${t.from}&to=${t.to}`:``}`);if(n.status===403){o(`This view is available to the house account only.`),f(!0);return}if(!n.ok){o(`The session manager did not answer (status ${n.status}).`),f(!0);return}i(await n.json()),o(null)}catch(e){o(e instanceof Error?e.message:String(e))}finally{f(!0),R.current=!1;let e=z.current;z.current=void 0,e!==void 0&&B(e)}},[e]);(0,h.useEffect)(()=>{B(b);let e=setInterval(()=>void B(b),15e3);return()=>clearInterval(e)},[B,b]);let V=(0,h.useMemo)(()=>n?[...n.rows].sort((e,t)=>H(e,t,m,v)):[],[n,m,v]),U=(0,h.useMemo)(()=>V.filter(e=>e.status===`busy`?S:e.status===`idle`?w:!0),[V,S,w]),Y=V.length-U.length;if(!d)return(0,g.jsx)(s,{surface:`gate`});if(a)return(0,g.jsx)(`div`,{className:`activity-empty`,children:a});if(!n)return(0,g.jsx)(`div`,{className:`activity-empty`,children:`No response.`});let{accounts:X,census:Z,censusAgeMs:Q}=n,te=Date.now(),ne=X.onDisk!==null&&X.onDisk>X.valid,$=n.range===void 0?b:n.range;return(0,g.jsxs)(`div`,{className:`ui-page ui-page--full activity-body`,children:[(0,g.jsxs)(`div`,{className:`activity-head`,children:[(0,g.jsxs)(`span`,{className:`activity-title`,children:[(0,g.jsx)(r,{size:16}),` Live sessions`]}),(0,g.jsxs)(`span`,{className:`activity-meta`,children:[Y>0?`${U.length} of ${V.length} live · ${Y} hidden`:`${V.length} live`,` · `,X.valid,` accounts`,X.untaggedCount>0?` · ${X.untaggedCount} untagged`:``]})]}),(0,g.jsxs)(`div`,{className:`activity-controls`,children:[(0,g.jsxs)(`div`,{className:`activity-control activity-range`,children:[(0,g.jsx)(u,{variant:`secondary`,size:`sm`,"aria-label":`Previous month`,disabled:!q(b),onClick:()=>x(e=>e&&G(e.from,-1)),children:`‹`}),(0,g.jsx)(`span`,{className:`activity-range-label`,children:b===null?`All time`:q(b)?K(b.from):`${b.from} → ${b.to}`}),(0,g.jsx)(u,{variant:`secondary`,size:`sm`,"aria-label":`Next month`,disabled:!q(b),onClick:()=>x(e=>e&&G(e.from,1)),children:`›`})]}),(0,g.jsxs)(`div`,{className:`activity-control activity-presets`,children:[(0,g.jsx)(u,{variant:`secondary`,size:`sm`,"aria-pressed":b!==null&&q(b)&&b.from===W(new Date).from,onClick:()=>x(W(new Date)),children:`This month`}),(0,g.jsx)(u,{variant:`secondary`,size:`sm`,"aria-pressed":b!==null&&!q(b),onClick:()=>x(ee(7,Date.now())),children:`Last 7 days`}),(0,g.jsx)(u,{variant:`secondary`,size:`sm`,"aria-pressed":b===null,onClick:()=>x(null),children:`All time`})]}),(0,g.jsxs)(`div`,{className:`activity-control`,children:[(0,g.jsx)(`label`,{className:`activity-control-label`,htmlFor:`activity-sort`,children:`Sort by`}),(0,g.jsx)(`span`,{className:`activity-select-wrap`,children:(0,g.jsx)(`select`,{id:`activity-sort`,className:`activity-select`,value:m,onChange:e=>{let t=k.find(t=>t.key===e.target.value);t&&(_(t.key),y(t.dir))},children:k.map(e=>(0,g.jsx)(`option`,{value:e.key,children:e.label},e.key))})})]}),(0,g.jsxs)(`div`,{className:`activity-control activity-visibility`,children:[(0,g.jsx)(l,{checked:S,onChange:C,label:`Busy`}),(0,g.jsx)(l,{checked:w,onChange:T,label:`Idle`})]})]}),(0,g.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.`,n.fullRangeFallback&&(0,g.jsxs)(`strong`,{className:`activity-range-rejected`,children:[` `,`The range was not accepted, so these are all-time figures.`]})]}),(0,g.jsx)(`div`,{className:`activity-census`,children:Z===null?`No census collected yet, so memory and CPU are unavailable.`:`Memory and CPU measured ${F(Q)} ago, averaged over the minute before that · ${Z.cpuNull} of ${Z.live} without a CPU reading`}),ne&&(0,g.jsxs)(`div`,{className:`activity-warning`,children:[(0,g.jsx)(p,{size:14}),` `,X.onDisk,` account folders on disk but only`,` `,X.valid,` are readable. Sessions belonging to the rest cannot be attributed.`]}),V.length===0?(0,g.jsx)(`div`,{className:`activity-empty`,children:`No sessions are running.`}):U.length===0?(0,g.jsxs)(`div`,{className:`activity-empty`,children:[`All `,V.length,` running sessions are hidden by the Busy and Idle filters.`]}):(0,g.jsx)(`div`,{className:`activity-grid`,children:U.map(e=>{let n=e.accountId!==null&&!!t,r=n?()=>void L(e.accountId,e.sessionId):void 0;return(0,g.jsxs)(`article`,{className:`activity-card${n?` activity-card-clickable`:``}`,"data-testid":`activity-card`,"data-session-id":e.sessionId,role:n?`button`:void 0,tabIndex:n?0:void 0,onClick:r,onKeyDown:n?e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),r())}:void 0,children:[(0,g.jsx)(`h3`,{className:`activity-card-heading`,title:e.accountId??void 0,children:e.accountId===null?(0,g.jsx)(`span`,{className:`activity-untagged`,title:`This session records no account, so it cannot be attributed to a business.`,children:`untagged`}):N(e.accountId,X.names)}),(0,g.jsx)(`dl`,{className:`activity-card-rows`,children:A.map(t=>(0,g.jsxs)(`div`,{className:`activity-card-row`,children:[(0,g.jsx)(`dt`,{className:`activity-card-label`,"data-testid":`activity-card-label`,title:t.help,children:t.label}),(0,g.jsx)(`dd`,{className:`activity-card-value`,title:t.key===`costGbp`?O(e):void 0,children:J(t.key,e,te)})]},t.key))})]},e.sessionId)})}),V.length>0&&(0,g.jsxs)(`div`,{className:`activity-glossary`,children:[(0,g.jsxs)(`dl`,{className:`activity-legend`,children:[D&&(0,g.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,g.jsx)(`dt`,{className:`activity-legend-term`,"data-testid":`activity-glossary-term`,children:M.label}),(0,g.jsx)(`dd`,{className:`activity-legend-def`,children:M.help})]},`heading`),(D?A:A.filter(e=>j.includes(e.key))).map(e=>(0,g.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,g.jsx)(`dt`,{className:`activity-legend-term`,"data-testid":`activity-glossary-term`,children:e.label}),(0,g.jsx)(`dd`,{className:`activity-legend-def`,children:e.help})]},e.key)),(0,g.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,g.jsx)(`dt`,{className:`activity-legend-term`,children:P}),(0,g.jsxs)(`dd`,{className:`activity-legend-def`,children:[`Not measured. It does not mean zero — a measured zero is written as a figure, so `,(0,g.jsx)(`em`,{children:`0h 0m`}),` and `,(0,g.jsx)(`em`,{children:`£0.00`}),` are real readings. Hover a dashed value for the reason where one exists.`]})]})]}),(0,g.jsx)(u,{variant:`secondary`,size:`sm`,className:`activity-glossary-toggle`,onClick:()=>I(e=>!e),children:D?`Show fewer`:`Explain every figure`})]}),(0,g.jsx)(E,{loops:n?.loops})]})}function X({cacheKey:e}){let{adminFetch:n}=t({initialCacheKey:e,surface:`activity`});return(0,g.jsx)(Y,{adminFetch:n,cacheKey:e})}function Z(){let[e,t]=(0,h.useState)(null),[n,r]=(0,h.useState)(!1),[i,a]=(0,h.useState)(void 0),[c,l]=(0,h.useState)(null),[u,p]=(0,h.useState)(null),[m,_]=(0,h.useState)(null),[v,y]=(0,h.useState)(null);(0,h.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(D)}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(D)}catch{}window.location.href=`/`;return}if(i.ok)try{let e=await i.json();typeof e.businessName==`string`&&a(e.businessName),e.sessionId!==void 0&&l(e.sessionId??null),p(e.role??null),_(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,h.useCallback)(()=>{try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`},[]),[x,S]=(0,h.useState)(!1),C=(0,h.useCallback)(async()=>{S(!0);try{let e=await d();if(e){try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`}return e}finally{S(!1)}},[]);return n?e?(0,g.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(D)}catch{}window.location.href=`/`},children:(0,g.jsx)(f,{cacheKey:e,businessName:i,sessionId:c,onLogout:b,onDisconnect:C,disconnecting:x,userName:m,userAvatar:v,role:u,children:(0,g.jsx)(X,{cacheKey:e})})}):(0,g.jsx)(`div`,{className:`activity-page`,children:(0,g.jsxs)(`div`,{className:`activity-empty`,children:[(0,g.jsx)(`p`,{children:`You are not signed in.`}),(0,g.jsxs)(`p`,{children:[`Open the `,(0,g.jsx)(`a`,{href:`/`,className:`activity-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,g.jsx)(s,{surface:`gate`})}(0,m.createRoot)(document.getElementById(`root`)).render((0,g.jsx)(Z,{}));
1
+ import{o as e}from"./chunk-CltuBf4Z.js";import{G as t,H as n,I as r,J as i,K as a,_ as o,g as s,n as c}from"./useSubAccountSwitcher-BEwQMRMo.js";import{D as l,E as u,O as d,t as f}from"./AdminShell-D5GApZ_n.js";import{t as p}from"./triangle-alert-vAaSDhVq.js";var m=a(),h=e(i(),1),g=n(),_=`—`;function v(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 y={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.`},b=new Set([`never-run`,`never-succeeded`,`failing`,`stalled`]),x=10;function S(e){return e===null||!Number.isFinite(e)?_:`${e.toFixed(1)}%`}function C(e){return e<6e4?`${Math.round(e/1e3)}s`:e<36e5?`${Math.round(e/6e4)}m`:`${Math.round(e/36e5)}h`}function w(e,t){if(e===null)return _;let n=t-e;return n<0?`in ${C(-n)}`:n<6e4?`${Math.round(n/1e3)}s ago`:n<36e5?`${Math.round(n/6e4)}m ago`:`${Math.round(n/36e5)}h ago`}function T(e,t){if(e===null)return _;let n=e-t;return n>=0?`in ${C(n)}`:`overdue by ${C(-n)}`}function E({loops:e,nowMs:t=Date.now()}){let[n,r]=(0,h.useState)(!1);if(!e)return(0,g.jsxs)(`section`,{className:`activity-loops`,children:[(0,g.jsx)(`h2`,{className:`activity-loops-heading`,children:`Scheduled work`}),(0,g.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=>b.has(e.state)),o=e.rows.filter(e=>!b.has(e.state)&&typeof e.cpuPct==`number`&&e.cpuPct>=x),s=n?e.rows:[...a,...o];return(0,g.jsxs)(`section`,{className:`activity-loops`,children:[(0,g.jsx)(`h2`,{className:`activity-loops-heading`,children:`Scheduled work`}),(0,g.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,g.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,g.jsxs)(`p`,{className:`activity-loops-cpu`,children:[`Server process at `,e.processPct.toFixed(1),`% of one core`,typeof e.attributedPct==`number`&&(0,g.jsxs)(g.Fragment,{children:[` · these loops explain `,e.attributedPct.toFixed(1),`%`]}),typeof e.unattributedPct==`number`&&e.unattributedPct>=1&&(0,g.jsxs)(g.Fragment,{children:[` · `,(0,g.jsxs)(`strong`,{children:[e.unattributedPct.toFixed(1),`% is not from these loops`]})]})]}),i>0&&(0,g.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,g.jsx)(`div`,{className:`activity-table-scroll`,children:(0,g.jsxs)(`table`,{className:`activity-table`,children:[(0,g.jsx)(`thead`,{children:(0,g.jsxs)(`tr`,{children:[(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Loop`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`State`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Every`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Last run`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Last OK`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Took`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`CPU`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Runs`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Produced`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Next due`})]})}),(0,g.jsx)(`tbody`,{children:s.map(e=>(0,g.jsxs)(`tr`,{className:b.has(e.state)?`activity-loop-row activity-loop-unhealthy`:`activity-loop-row`,children:[(0,g.jsx)(`td`,{className:`activity-td`,children:e.name}),(0,g.jsx)(`td`,{className:`activity-td`,title:y[e.state],children:(0,g.jsxs)(`span`,{className:`activity-state`,children:[(0,g.jsx)(`span`,{className:e.state===`ok`?`activity-state-dot is-healthy`:b.has(e.state)?`activity-state-dot is-unhealthy`:`activity-state-dot`,"aria-hidden":`true`}),v(e.state)]})}),(0,g.jsx)(`td`,{className:`activity-td activity-num`,children:C(e.intervalMs)}),(0,g.jsx)(`td`,{className:`activity-td activity-num`,children:w(e.lastStartMs,t)}),(0,g.jsx)(`td`,{className:`activity-td activity-num`,children:w(e.lastSuccessMs,t)}),(0,g.jsx)(`td`,{className:`activity-td activity-num`,children:e.lastDurationMs===null?_:`${e.lastDurationMs} ms`}),(0,g.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:S(e.cpuPct)}),(0,g.jsxs)(`td`,{className:`activity-td activity-num`,children:[e.successCount,`/`,e.runCount]}),(0,g.jsx)(`td`,{className:`activity-td activity-loop-note`,children:(0,g.jsx)(`span`,{className:`activity-loop-note-text`,title:e.lastError??e.lastNote??void 0,children:e.lastError??e.lastNote??_})}),(0,g.jsx)(`td`,{className:`activity-td activity-num`,children:T(e.nextDueMs,t)})]},e.name))})]})}),(0,g.jsxs)(`dl`,{className:`activity-legend`,children:[(0,g.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,g.jsx)(`dt`,{className:`activity-legend-term`,children:`Runs`}),(0,g.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,g.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,g.jsx)(`dt`,{className:`activity-legend-term`,children:`CPU`}),(0,g.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,g.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,g.jsx)(`dt`,{className:`activity-legend-term`,children:_}),(0,g.jsx)(`dd`,{className:`activity-legend-def`,children:`Not measured. It does not mean zero.`})]})]})]})}var D=`maxy-admin-session-key`;function O(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 N(e,t){let n=t?.[e];return n&&n.trim()!==``?n:e.slice(0,8)}var P=`—`;function F(e){if(e===null||!Number.isFinite(e)||e<0)return P;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 I(e){return e===null||!Number.isFinite(e)?P:`${(e/1024/1024).toFixed(1)} GB`}function L(e,t){if(!e)return P;let n=Date.parse(e);if(!Number.isFinite(n))return P;let r=new Date(n),i=new Date(t),a=`${String(r.getHours()).padStart(2,`0`)}:${String(r.getMinutes()).padStart(2,`0`)}`;return r.getFullYear()===i.getFullYear()&&r.getMonth()===i.getMonth()&&r.getDate()===i.getDate()?a:`${r.getDate()} ${r.toLocaleString(`en-GB`,{month:`short`})} ${a}`}function R(e){return e===null||!Number.isFinite(e)?P:`${e.toFixed(1)}%`}function z(e){return e===null||!Number.isFinite(e)?P: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)?P:`£${e.toFixed(2)}`}function V(e){if(e===null||!Number.isFinite(e)||e<0)return P;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 ee(e,t){return{from:U(new Date(t-(e-1)*864e5)),to:U(new Date(t))}}function K(e){return new Date(`${e}T00:00:00.000Z`).toLocaleString(`en-GB`,{month:`long`,year:`numeric`,timeZone:`UTC`})}function q(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 J(e,t,n){switch(e){case`title`:return t.title??t.sessionId.slice(0,8);case`model`:return t.model??P;case`status`:return t.status??P;case`activeMsInRange`:return V(t.activeMsInRange);case`ageMs`:return F(t.ageMs);case`lastMessageAt`:return L(t.lastMessageAt,n);case`turnCount`:return t.turnCount===null?P:`${t.turnCount}${t.turnCountCapped?`+`:``}`;case`rssKb`:return I(t.rssKb);case`cpuPct`:return R(t.cpuPct);case`tokensInRange`:return z(t.tokensInRange);case`costGbp`:return B(t.costGbp);default:return P}}function Y({adminFetch:e,cacheKey:t}){let[n,i]=(0,h.useState)(null),[a,o]=(0,h.useState)(null),[d,f]=(0,h.useState)(!1),[m,_]=(0,h.useState)(`lastMessageAt`),[v,y]=(0,h.useState)(-1),[b,x]=(0,h.useState)(()=>W(new Date)),[S,C]=(0,h.useState)(!0),[w,T]=(0,h.useState)(!0),[D,I]=(0,h.useState)(!1),L=(0,h.useCallback)(async(e,n)=>{t&&await c(t,e)&&(console.info(`[admin-ui] activity-card-open account=${e.slice(0,8)} session=${n.slice(0,8)}`),window.location.assign(`/chat?session=${encodeURIComponent(n)}`))},[t]),R=(0,h.useRef)(!1),z=(0,h.useRef)(void 0),B=(0,h.useCallback)(async t=>{if(R.current){z.current=t;return}R.current=!0;try{let n=await e(`/api/admin/activity${t?`?from=${t.from}&to=${t.to}`:``}`);if(n.status===403){o(`This view is available to the house account only.`),f(!0);return}if(!n.ok){o(`The session manager did not answer (status ${n.status}).`),f(!0);return}i(await n.json()),o(null)}catch(e){o(e instanceof Error?e.message:String(e))}finally{f(!0),R.current=!1;let e=z.current;z.current=void 0,e!==void 0&&B(e)}},[e]);(0,h.useEffect)(()=>{B(b);let e=setInterval(()=>void B(b),15e3);return()=>clearInterval(e)},[B,b]);let V=(0,h.useMemo)(()=>n?[...n.rows].sort((e,t)=>H(e,t,m,v)):[],[n,m,v]),U=(0,h.useMemo)(()=>V.filter(e=>e.status===`busy`?S:e.status===`idle`?w:!0),[V,S,w]),Y=V.length-U.length;if(!d)return(0,g.jsx)(s,{surface:`gate`});if(a)return(0,g.jsx)(`div`,{className:`activity-empty`,children:a});if(!n)return(0,g.jsx)(`div`,{className:`activity-empty`,children:`No response.`});let{accounts:X,census:Z,censusAgeMs:Q}=n,te=Date.now(),ne=X.onDisk!==null&&X.onDisk>X.valid,$=n.range===void 0?b:n.range;return(0,g.jsxs)(`div`,{className:`ui-page ui-page--full activity-body`,children:[(0,g.jsxs)(`div`,{className:`activity-head`,children:[(0,g.jsxs)(`span`,{className:`activity-title`,children:[(0,g.jsx)(r,{size:16}),` Live sessions`]}),(0,g.jsxs)(`span`,{className:`activity-meta`,children:[Y>0?`${U.length} of ${V.length} live · ${Y} hidden`:`${V.length} live`,` · `,X.valid,` accounts`,X.untaggedCount>0?` · ${X.untaggedCount} untagged`:``]})]}),(0,g.jsxs)(`div`,{className:`activity-controls`,children:[(0,g.jsxs)(`div`,{className:`activity-control activity-range`,children:[(0,g.jsx)(u,{variant:`secondary`,size:`sm`,"aria-label":`Previous month`,disabled:!q(b),onClick:()=>x(e=>e&&G(e.from,-1)),children:`‹`}),(0,g.jsx)(`span`,{className:`activity-range-label`,children:b===null?`All time`:q(b)?K(b.from):`${b.from} → ${b.to}`}),(0,g.jsx)(u,{variant:`secondary`,size:`sm`,"aria-label":`Next month`,disabled:!q(b),onClick:()=>x(e=>e&&G(e.from,1)),children:`›`})]}),(0,g.jsxs)(`div`,{className:`activity-control activity-presets`,children:[(0,g.jsx)(u,{variant:`secondary`,size:`sm`,"aria-pressed":b!==null&&q(b)&&b.from===W(new Date).from,onClick:()=>x(W(new Date)),children:`This month`}),(0,g.jsx)(u,{variant:`secondary`,size:`sm`,"aria-pressed":b!==null&&!q(b),onClick:()=>x(ee(7,Date.now())),children:`Last 7 days`}),(0,g.jsx)(u,{variant:`secondary`,size:`sm`,"aria-pressed":b===null,onClick:()=>x(null),children:`All time`})]}),(0,g.jsxs)(`div`,{className:`activity-control`,children:[(0,g.jsx)(`label`,{className:`activity-control-label`,htmlFor:`activity-sort`,children:`Sort by`}),(0,g.jsx)(`span`,{className:`activity-select-wrap`,children:(0,g.jsx)(`select`,{id:`activity-sort`,className:`activity-select`,value:m,onChange:e=>{let t=k.find(t=>t.key===e.target.value);t&&(_(t.key),y(t.dir))},children:k.map(e=>(0,g.jsx)(`option`,{value:e.key,children:e.label},e.key))})})]}),(0,g.jsxs)(`div`,{className:`activity-control activity-visibility`,children:[(0,g.jsx)(l,{checked:S,onChange:C,label:`Busy`}),(0,g.jsx)(l,{checked:w,onChange:T,label:`Idle`})]})]}),(0,g.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.`,n.fullRangeFallback&&(0,g.jsxs)(`strong`,{className:`activity-range-rejected`,children:[` `,`The range was not accepted, so these are all-time figures.`]})]}),(0,g.jsx)(`div`,{className:`activity-census`,children:Z===null?`No census collected yet, so memory and CPU are unavailable.`:`Memory and CPU measured ${F(Q)} ago, averaged over the minute before that · ${Z.cpuNull} of ${Z.live} without a CPU reading`}),ne&&(0,g.jsxs)(`div`,{className:`activity-warning`,children:[(0,g.jsx)(p,{size:14}),` `,X.onDisk,` account folders on disk but only`,` `,X.valid,` are readable. Sessions belonging to the rest cannot be attributed.`]}),V.length===0?(0,g.jsx)(`div`,{className:`activity-empty`,children:`No sessions are running.`}):U.length===0?(0,g.jsxs)(`div`,{className:`activity-empty`,children:[`All `,V.length,` running sessions are hidden by the Busy and Idle filters.`]}):(0,g.jsx)(`div`,{className:`activity-grid`,children:U.map(e=>{let n=e.accountId!==null&&!!t,r=n?()=>void L(e.accountId,e.sessionId):void 0;return(0,g.jsxs)(`article`,{className:`activity-card${n?` activity-card-clickable`:``}`,"data-testid":`activity-card`,"data-session-id":e.sessionId,role:n?`button`:void 0,tabIndex:n?0:void 0,onClick:r,onKeyDown:n?e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),r())}:void 0,children:[(0,g.jsx)(`h3`,{className:`activity-card-heading`,title:e.accountId??void 0,children:e.accountId===null?(0,g.jsx)(`span`,{className:`activity-untagged`,title:`This session records no account, so it cannot be attributed to a business.`,children:`untagged`}):N(e.accountId,X.names)}),(0,g.jsx)(`dl`,{className:`activity-card-rows`,children:A.map(t=>(0,g.jsxs)(`div`,{className:`activity-card-row`,children:[(0,g.jsx)(`dt`,{className:`activity-card-label`,"data-testid":`activity-card-label`,title:t.help,children:t.label}),(0,g.jsx)(`dd`,{className:`activity-card-value`,title:t.key===`costGbp`?O(e):void 0,children:J(t.key,e,te)})]},t.key))})]},e.sessionId)})}),V.length>0&&(0,g.jsxs)(`div`,{className:`activity-glossary`,children:[(0,g.jsxs)(`dl`,{className:`activity-legend`,children:[D&&(0,g.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,g.jsx)(`dt`,{className:`activity-legend-term`,"data-testid":`activity-glossary-term`,children:M.label}),(0,g.jsx)(`dd`,{className:`activity-legend-def`,children:M.help})]},`heading`),(D?A:A.filter(e=>j.includes(e.key))).map(e=>(0,g.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,g.jsx)(`dt`,{className:`activity-legend-term`,"data-testid":`activity-glossary-term`,children:e.label}),(0,g.jsx)(`dd`,{className:`activity-legend-def`,children:e.help})]},e.key)),(0,g.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,g.jsx)(`dt`,{className:`activity-legend-term`,children:P}),(0,g.jsxs)(`dd`,{className:`activity-legend-def`,children:[`Not measured. It does not mean zero — a measured zero is written as a figure, so `,(0,g.jsx)(`em`,{children:`0h 0m`}),` and `,(0,g.jsx)(`em`,{children:`£0.00`}),` are real readings. Hover a dashed value for the reason where one exists.`]})]})]}),(0,g.jsx)(u,{variant:`secondary`,size:`sm`,className:`activity-glossary-toggle`,onClick:()=>I(e=>!e),children:D?`Show fewer`:`Explain every figure`})]}),(0,g.jsx)(E,{loops:n?.loops})]})}function X({cacheKey:e}){let{adminFetch:n}=t({initialCacheKey:e,surface:`activity`});return(0,g.jsx)(Y,{adminFetch:n,cacheKey:e})}function Z(){let[e,t]=(0,h.useState)(null),[n,r]=(0,h.useState)(!1),[i,a]=(0,h.useState)(void 0),[c,l]=(0,h.useState)(null),[u,p]=(0,h.useState)(null),[m,_]=(0,h.useState)(null),[v,y]=(0,h.useState)(null);(0,h.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(D)}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(D)}catch{}window.location.href=`/`;return}if(i.ok)try{let e=await i.json();typeof e.businessName==`string`&&a(e.businessName),e.sessionId!==void 0&&l(e.sessionId??null),p(e.role??null),_(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,h.useCallback)(()=>{try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`},[]),[x,S]=(0,h.useState)(!1),C=(0,h.useCallback)(async()=>{S(!0);try{let e=await d();if(e){try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`}return e}finally{S(!1)}},[]);return n?e?(0,g.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(D)}catch{}window.location.href=`/`},children:(0,g.jsx)(f,{cacheKey:e,businessName:i,sessionId:c,onLogout:b,onDisconnect:C,disconnecting:x,userName:m,userAvatar:v,role:u,children:(0,g.jsx)(X,{cacheKey:e})})}):(0,g.jsx)(`div`,{className:`activity-page`,children:(0,g.jsxs)(`div`,{className:`activity-empty`,children:[(0,g.jsx)(`p`,{children:`You are not signed in.`}),(0,g.jsxs)(`p`,{children:[`Open the `,(0,g.jsx)(`a`,{href:`/`,className:`activity-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,g.jsx)(s,{surface:`gate`})}(0,m.createRoot)(document.getElementById(`root`)).render((0,g.jsx)(Z,{}));
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{A as t,H as n,J as r,K as i,U as a,_ as o,a as s,d as c,s as l,u,v as ee,x as te}from"./useSubAccountSwitcher-HjQZjJBr.js";import{n as d,t as f}from"./AdminLoginScreens-zfexKfbT.js";import{f as ne,s as p,x as m}from"./useVoiceRecorder-CJecnefX.js";import{C as h,S as re,a as g,b as _,h as ie,t as v}from"./AdminShell-Cbk0TL1B.js";import{n as ae}from"./file-download-C_fSe4dm.js";import{t as y}from"./chevron-left-C8LTc7lb.js";import{t as oe}from"./chevron-right-Lz9t7Hed.js";import{n as b,r as x}from"./page-DWkUH4Z_.js";import{t as se}from"./file-text-D7GbEcqj.js";import"./graph-labels-Dlcb6cW7.js";import"./CdpScreencastSurface-CLSQHh4e.js";var S=i(),C=e(r(),1),w=n();function T({onOpen:e}){return(0,w.jsx)(`footer`,{className:`admin-footer`,children:(0,w.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,w.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`powered-by-icon`}),(0,w.jsx)(`span`,{children:`Powered by Claude Code`})]})})}function E({sessionId:e,projectDir:t,sessionKey:n,contactName:r,onBack:i}){return(0,w.jsxs)(`div`,{className:`wa-web`,children:[(0,w.jsxs)(`header`,{className:`wa-web-header`,children:[i&&(0,w.jsx)(`button`,{type:`button`,className:`wa-web-back`,onClick:i,"aria-label":`Back`,children:(0,w.jsx)(y,{size:20})}),(0,w.jsx)(`span`,{className:`wa-web-avatar`,"aria-hidden":!0,children:(0,w.jsx)(m,{size:20})}),(0,w.jsx)(`div`,{className:`wa-web-titles`,children:(0,w.jsx)(`span`,{className:`wa-web-name`,children:r})})]}),(0,w.jsx)(`div`,{className:`wa-web-body`,children:(0,w.jsx)(p,{sessionId:e,projectDir:t,sessionKey:n,forceDeliveredOnly:!0})})]})}var D=6e4,O=60*D,k=24*O,A=D,j=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],M=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function N(e){return e<10?`0${e}`:String(e)}function P(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime()}function F(e,t){if(!Number.isFinite(e)||e<=0||!Number.isFinite(t))return`—`;let n=t-e;if(n<-A)return`—`;let r=n<0?0:n;if(r<D)return`just now`;if(r<O)return`${Math.floor(r/D)}m`;if(r<k)return`${Math.floor(r/O)}h`;let i=new Date(t),a=new Date(e),o=Math.round((P(i)-P(a))/k);if(o===1)return`yesterday`;if(o>=2&&o<=6)return M[a.getDay()];let s=N(a.getDate()),c=j[a.getMonth()];return a.getFullYear()===i.getFullYear()?`${s} ${c}`:`${s} ${c} ${a.getFullYear()}`}function I({variant:e=`row`,count:t=1}){return(0,w.jsx)(w.Fragment,{children:Array.from({length:t},(t,n)=>(0,w.jsx)(`span`,{className:`dashboard-skeleton dashboard-skeleton--${e}`,"data-testid":`dashboard-skeleton`,"aria-hidden":`true`},n))})}var ce=6e4;function le(e){return e<12?`morning`:e<18?`afternoon`:`evening`}function L(e){return e&&e.trim().split(/\s+/)[0]||`there`}function ue(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 R(e){return e==null?`—`:`${Math.round(e*100)}%`}function de(e){return e.isGroup===!0?e.chatName??e.title:e.operatorName??e.chatName??e.whatsappName??e.senderId??e.title}function z(e,t){if(!e)return!1;let n=Date.parse(e);if(!Number.isFinite(n))return!1;let r=new Date(n),i=new Date(t);return r.getFullYear()===i.getFullYear()&&r.getMonth()===i.getMonth()&&r.getDate()===i.getDate()}function fe(e){return e?e.replace(/^claude-/,``):null}var B=new Set([`sessions`,`conversations`,`tasks`,`artefacts`,`skills`,`stats`]),V=!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:[...B].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 H({cacheKey:e,userName:n,onSelectWhatsappConversation:r}){let i=ee(e),[o,d]=(0,C.useState)(null),[f,p]=(0,C.useState)(null),[m,g]=(0,C.useState)(null),v=(0,C.useRef)(!1),[y,b]=(0,C.useState)(null),[x,S]=(0,C.useState)(null),[T,E]=(0,C.useState)(null),[D,O]=(0,C.useState)(null),[k,A]=(0,C.useState)(null),[j,M]=(0,C.useState)(null),[N,P]=(0,C.useState)(new Set),[B,H]=(0,C.useState)(()=>new Set),U=(0,C.useCallback)(e=>{H(t=>t.has(e)?t:new Set(t).add(e))},[]),W=Date.now(),G=(0,C.useRef)(!1),K=(0,C.useRef)(new Map),q=(0,C.useRef)(new Set),J=(0,C.useRef)(null);(0,C.useEffect)(()=>{if(!e)return;let t=!1;async function n(e,n,r,a){let o=Date.now(),s=typeof n==`string`?n:`unresolved`;try{typeof n!=`string`&&(s=await n());let c=await i(s);if(!c.ok)throw Error(`status ${c.status}`);let l=await c.json();t||a(r(l)),console.info(`[admin-ui] op=dashboard-fetch slice=${e} url=${s} outcome=ok ms=${Date.now()-o}`)}catch(t){q.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{K.current.set(e,Date.now()-o),U(e)}}async function r(){if(!J.current){let e=await i(`/api/admin/accounts`);if(!e.ok)throw Error(`accounts status ${e.status}`);let t=await e.json(),n=t.accounts??[],r=t.activeAccountId??null,a=n.find(e=>e.accountId===r);if(!a)throw Error(`accounts: active ${r??`none`} absent from list of ${n.length}`);let o=a.isHouse||n.length===1;J.current={accountId:a.accountId,isHouse:o}}let{accountId:e,isHouse:t}=J.current;return console.info(`[admin-ui] op=dashboard-channels-source source=${t?`all`:`scoped`} account=${e.slice(0,8)}`),t?`/api/operator-conversations/conversations-all`:`/api/operator-conversations/conversations`}let o={"sidebar-sessions":()=>n(`sessions`,`/api/admin/sidebar-sessions`,e=>e.sessions??[],d),"conversations-all":()=>n(`conversations`,r,e=>e.conversations??[],p),"tasks-list":()=>n(`tasks`,`/api/admin/tasks-list`,e=>e,S),"sidebar-artefacts":()=>n(`artefacts`,`/api/admin/sidebar-artefacts`,e=>e.artefacts??[],E),skills:()=>n(`skills`,`/api/admin/skills`,e=>e.skills??[],O)};async function s(){if(G.current)return;G.current=!0;let e=Date.now();try{await Promise.all([...Object.values(o).map(e=>e()),n(`stats`,`/api/admin/system-stats`,e=>e,b),n(`bookingLink`,`/api/admin/calendar/booking-link`,e=>e.bookingDomain??null,A),n(`portalLink`,`/api/admin/data-portal/portal-link`,e=>e.portalDomain??null,M)])}finally{G.current=!1;let t=Date.now()-e;if(console.info(`[admin-ui] op=dashboard-refresh-settled ms=${t}`),!V){V=!0;try{let e=pe(t,K.current,q.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{}}}}s();let c=null;try{c=new EventSource(a(`/api/admin/events`,e)),c.onmessage=e=>{if(document.visibilityState===`visible`)try{let{resource:t}=JSON.parse(e.data),n=t?o[t]:void 0;n&&n()}catch{}},c.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 l=setInterval(()=>{document.visibilityState===`visible`&&s()},ce),u=()=>{document.visibilityState===`visible`&&s()};return document.addEventListener(`visibilitychange`,u),()=>{t=!0,G.current=!1,clearInterval(l),c?.close(),document.removeEventListener(`visibilitychange`,u)}},[e,i]);let Y=(0,C.useMemo)(()=>(o??[]).filter(e=>!e.isSubagent),[o]),X=(0,C.useMemo)(()=>Y.filter(e=>e.live),[Y]),me=(0,C.useMemo)(()=>(f??[]).filter(e=>z(e.lastMessageAt,W)).length,[f,W]),he=x?.open.length??0,Z=(0,C.useMemo)(()=>{let e=new Map;for(let t of f??[]){let n=e.get(t.channel)??[];n.push(t),e.set(t.channel,n)}return[...e.entries()].map(([e,t])=>{let n=t.reduce((e,t)=>t.lastMessageAt&&(!e||Date.parse(t.lastMessageAt)>Date.parse(e.lastMessageAt??``))?t:e,null);return{channel:e,count:t.length,preview:n?de(n):``,rows:t}})},[f]);(0,C.useEffect)(()=>{v.current||Z.length!==0&&(v.current=!0,g(Z[0].channel))},[Z]);let Q=(0,C.useRef)(!1);(0,C.useEffect)(()=>{Q.current||!B.has(`bookingLink`)||!B.has(`portalLink`)||(Q.current=!0,console.info(`[admin-ui] dashboard-public-pages booking=${k!=null} filedrop=${j!=null}`))},[B,k,j]);let ge=(0,C.useCallback)(async e=>{if(!N.has(e)){P(t=>new Set(t).add(e));try{let t=await i(`/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}console.info(`[admin-ui] dashboard-session-stop sessionId=${e}`),d(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{P(t=>{let n=new Set(t);return n.delete(e),n})}}},[i,N]),_e=(0,C.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}ae(e,t.downloadPath,t.downloadRoot??`data`)},[e]),$=le(new Date(W).getHours());return(0,w.jsxs)(`div`,{className:`ui-page ui-page--full dashboard-home`,children:[(0,w.jsx)(`p`,{className:`dashboard-greeting`,children:B.has(`stats`)?`Good ${$}, ${L(n)} — ${ue(y)}`:`Good ${$}, ${L(n)}`}),(0,w.jsxs)(`div`,{className:`dashboard-stats`,children:[(0,w.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,w.jsx)(`span`,{className:`dashboard-stat-label`,children:`Live sessions`}),B.has(`sessions`)?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`span`,{className:`dashboard-stat-value`,children:X.length}),(0,w.jsxs)(`span`,{className:`dashboard-stat-delta`,children:[`of `,Y.length,` total`]})]}):(0,w.jsx)(I,{variant:`value`})]}),(0,w.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,w.jsx)(`span`,{className:`dashboard-stat-label`,children:`Messages today`}),B.has(`conversations`)?(0,w.jsx)(`span`,{className:`dashboard-stat-value`,children:me}):(0,w.jsx)(I,{variant:`value`})]}),(0,w.jsxs)(`a`,{className:`admin-stat-card dashboard-stat-card dashboard-stat-card--link`,href:`/tasks`,children:[(0,w.jsx)(`span`,{className:`dashboard-stat-label`,children:`Open tasks`}),B.has(`tasks`)?(0,w.jsx)(`span`,{className:`dashboard-stat-value`,children:he}):(0,w.jsx)(I,{variant:`value`})]}),(0,w.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,w.jsx)(`span`,{className:`dashboard-stat-label`,children:`Host CPU`}),B.has(`stats`)?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`span`,{className:`dashboard-stat-value`,children:R(y?.cpuPct??null)}),(0,w.jsxs)(`span`,{className:`dashboard-stat-delta`,children:[`RAM `,R(y?.memUsedPct??null)]})]}):(0,w.jsx)(I,{variant:`value`})]})]}),(0,w.jsxs)(`div`,{className:`dashboard-columns`,children:[(0,w.jsxs)(`div`,{className:`dashboard-col`,children:[(k||j)&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Public pages`}),(0,w.jsxs)(`div`,{className:`admin-card dashboard-public-pages`,children:[k&&(0,w.jsxs)(`a`,{className:`admin-row dashboard-public-row`,href:`https://${k}`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,w.jsx)(`span`,{className:`dashboard-public-icon`,children:(0,w.jsx)(_,{size:16})}),(0,w.jsx)(`span`,{className:`dashboard-public-name`,children:`Booking page`})]}),j&&(0,w.jsxs)(`a`,{className:`admin-row dashboard-public-row`,href:`https://${j}`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,w.jsx)(`span`,{className:`dashboard-public-icon`,children:(0,w.jsx)(_,{size:16})}),(0,w.jsx)(`span`,{className:`dashboard-public-name`,children:`File drop`})]})]})]}),(0,w.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Live now`}),B.has(`sessions`)?X.length===0?(0,w.jsx)(`div`,{className:`admin-card dashboard-empty`,children:`No live sessions right now.`}):X.map(e=>{let t=[e.sessionId.slice(0,8),fe(e.model),F(Date.parse(e.startedAt),W)].filter(Boolean).join(` · `);return(0,w.jsxs)(`div`,{className:`admin-card dashboard-live-card`,children:[(0,w.jsx)(`span`,{className:`admin-status-dot is-live`}),(0,w.jsxs)(`div`,{className:`dashboard-live-main`,children:[(0,w.jsx)(`span`,{className:`dashboard-live-name`,children:e.title}),(0,w.jsx)(`span`,{className:`dashboard-live-meta`,children:t})]}),(0,w.jsx)(`a`,{className:`admin-btn-cta dashboard-open-btn`,href:`/chat?session=${encodeURIComponent(e.sessionId)}`,children:`Open`}),(0,w.jsx)(`button`,{type:`button`,className:`dashboard-stop-btn`,"aria-label":`Stop ${e.title}`,disabled:N.has(e.sessionId),onClick:()=>void ge(e.sessionId),children:(0,w.jsx)(te,{size:12})})]},e.sessionId)}):(0,w.jsx)(I,{variant:`card`,count:2}),(0,w.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Recent artefacts`}),(0,w.jsx)(`div`,{className:`admin-card dashboard-artefacts`,children:B.has(`artefacts`)?(T??[]).length===0?(0,w.jsx)(`div`,{className:`dashboard-empty`,children:`No recent artefacts.`}):(T??[]).slice(0,6).map(e=>(0,w.jsxs)(`button`,{type:`button`,className:`admin-row dashboard-artefact-row`,onClick:()=>_e(e),children:[(0,w.jsx)(`span`,{className:`dashboard-artefact-icon`,children:e.kind===`agent-template`?(0,w.jsx)(h,{size:16}):(0,w.jsx)(se,{size:16})}),(0,w.jsx)(`div`,{className:`dashboard-artefact-body`,children:(0,w.jsx)(`span`,{className:`dashboard-artefact-name`,children:e.name})}),(0,w.jsx)(`span`,{className:`dashboard-artefact-time`,children:F(Date.parse(e.updatedAt),W)})]},e.id)):(0,w.jsx)(I,{count:3})}),(0,w.jsx)(`a`,{className:`admin-section-label dashboard-col-label dashboard-skills-label`,href:`/skills`,children:`Skills`}),(0,w.jsx)(`div`,{className:`admin-card dashboard-skills`,children:B.has(`skills`)?(D??[]).length===0?(0,w.jsx)(`div`,{className:`dashboard-empty`,children:`No skills yet.`}):(D??[]).map(e=>(0,w.jsxs)(`a`,{className:`admin-row dashboard-skill-row`,href:`/skills`,children:[(0,w.jsx)(`span`,{className:`dashboard-skill-icon`,children:(0,w.jsx)(ie,{size:16})}),(0,w.jsxs)(`div`,{className:`dashboard-skill-body`,children:[(0,w.jsx)(`span`,{className:`dashboard-skill-name`,children:e.skill}),(0,w.jsx)(`span`,{className:`dashboard-skill-plugin`,children:e.plugin})]})]},`${e.plugin}/${e.skill}`)):(0,w.jsx)(I,{count:2})})]}),(0,w.jsxs)(`div`,{className:`dashboard-col`,children:[(0,w.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Channels`}),B.has(`conversations`)?Z.length===0?(0,w.jsx)(`div`,{className:`admin-card dashboard-empty`,children:`No channel activity.`}):Z.map(n=>{let i=m===n.channel;return(0,w.jsxs)(`div`,{className:`admin-card dashboard-channel-card`,children:[(0,w.jsxs)(`button`,{type:`button`,className:`dashboard-channel-head`,"aria-expanded":i,onClick:()=>g(e=>e===n.channel?null:n.channel),children:[(0,w.jsx)(`span`,{className:`dashboard-channel-glyph`,children:n.channel===`whatsapp`||n.channel===`telegram`?(0,w.jsx)(c,{channel:n.channel,size:16}):(0,w.jsx)(t,{size:16})}),(0,w.jsx)(`span`,{className:`dashboard-channel-name`,children:u[n.channel]??n.channel}),(0,w.jsx)(`span`,{className:`dashboard-channel-badge`,children:n.count}),(0,w.jsx)(`span`,{className:`dashboard-channel-chevron`,children:i?(0,w.jsx)(re,{size:14}):(0,w.jsx)(oe,{size:14})})]}),i?(0,w.jsx)(`div`,{className:`dashboard-channel-convs`,children:n.rows.map(t=>(0,w.jsxs)(`button`,{type:`button`,className:`admin-row dashboard-channel-conv-row`,onClick:()=>r(t),title:t.title,children:[(0,w.jsxs)(`span`,{className:`dashboard-channel-conv-line`,children:[(0,w.jsx)(ne,{accountId:t.accountId??``,jid:t.remoteJid,sessionKey:e??``,className:`dashboard-channel-conv-avatar`,size:16}),(0,w.jsx)(`span`,{className:`dashboard-channel-conv-name`,children:s(t)}),t.isGroup===!0&&(0,w.jsx)(`span`,{className:`dashboard-channel-conv-tag is-group`,children:`Group`}),t.role===`public`&&(0,w.jsx)(`span`,{className:`dashboard-channel-conv-tag is-public`,children:`Public`}),(0,w.jsx)(`span`,{className:`dashboard-channel-conv-tag`,children:t.isHouse?`House`:`Client`}),!t.preview&&t.lastMessageAt&&(0,w.jsx)(`span`,{className:`dashboard-channel-conv-time`,children:F(Date.parse(t.lastMessageAt),W)})]}),t.preview?(0,w.jsxs)(`span`,{className:`dashboard-channel-conv-sub`,children:[(0,w.jsx)(`span`,{className:`dashboard-channel-conv-preview`,children:t.preview}),t.lastMessageAt&&(0,w.jsx)(`span`,{className:`dashboard-channel-conv-time`,children:F(Date.parse(t.lastMessageAt),W)})]}):null]},l(t)))}):n.preview&&(0,w.jsx)(`span`,{className:`dashboard-channel-preview`,children:n.preview})]},n.channel)}):(0,w.jsx)(I,{variant:`card`,count:2})]})]})]})}function U(){let e=d(),[t,n]=(0,C.useState)(!1);(0,C.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,C.useCallback)(async()=>{let t=e.claudeInfo!=null;if(n(!0),t){console.info(`[admin-ui] claude-info-open cached=true ms=0`);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)}console.info(`[admin-ui] claude-info-open cached=false ms=${Date.now()-r}`)}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,C.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,w.jsx)(o,{cacheKey:e.cacheKey,onSessionExpired:i,surface:`chat`,children:(0,w.jsx)(v,{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,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(T,{onOpen:r}),(0,w.jsx)(g,{show:t,onClose:()=>n(!1),claudeInfo:e.claudeInfo,messages:[],sessionElapsed:0,sessionId:e.sessionId,cacheKey:e.cacheKey})]}),children:t=>(0,w.jsx)(w.Fragment,{children:t.dataOpen&&e.cacheKey?(0,w.jsx)(b,{cacheKey:e.cacheKey}):t.selectedWhatsapp&&e.cacheKey?t.selectedWhatsapp.source===`store`&&t.selectedWhatsapp.remoteJid&&t.selectedWhatsapp.accountId?(0,w.jsx)(x,{accountId:t.selectedWhatsapp.accountId,remoteJid:t.selectedWhatsapp.remoteJid,contactName:s(t.selectedWhatsapp),sessionKey:e.cacheKey,onBack:t.onClearWhatsapp},l(t.selectedWhatsapp)):(0,w.jsx)(E,{sessionId:t.selectedWhatsapp.sessionId,projectDir:t.selectedWhatsapp.projectDir,sessionKey:e.cacheKey,contactName:s(t.selectedWhatsapp),onBack:t.onClearWhatsapp},l(t.selectedWhatsapp)):(0,w.jsx)(H,{cacheKey:e.cacheKey,userName:e.userName,onSelectWhatsappConversation:t.onSelectWhatsappConversation})})})}):(0,w.jsx)(f,{auth:e})}(0,S.createRoot)(document.getElementById(`root`)).render((0,w.jsx)(U,{}));
1
+ import{o as e}from"./chunk-CltuBf4Z.js";import{A as t,H as n,J as r,K as i,U as a,_ as o,a as s,d as c,s as l,u,v as ee,x as te}from"./useSubAccountSwitcher-BEwQMRMo.js";import{n as d,t as f}from"./AdminLoginScreens-7Czw3MAC.js";import{f as ne,s as p,x as m}from"./useVoiceRecorder-CiDOh8PG.js";import{C as h,S as re,a as g,b as _,h as ie,t as v}from"./AdminShell-D5GApZ_n.js";import{n as ae}from"./file-download-Di_s0_4w.js";import{t as y}from"./chevron-left-CdUzxzeB.js";import{t as oe}from"./chevron-right-CKGwd-M0.js";import{n as b,r as x}from"./page-CNJl3tWT.js";import{t as se}from"./file-text-CP1KIrJV.js";import"./graph-labels-CgP17xHK.js";import"./CdpScreencastSurface-BbekDUFw.js";var S=i(),C=e(r(),1),w=n();function T({onOpen:e}){return(0,w.jsx)(`footer`,{className:`admin-footer`,children:(0,w.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,w.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`powered-by-icon`}),(0,w.jsx)(`span`,{children:`Powered by Claude Code`})]})})}function E({sessionId:e,projectDir:t,sessionKey:n,contactName:r,onBack:i}){return(0,w.jsxs)(`div`,{className:`wa-web`,children:[(0,w.jsxs)(`header`,{className:`wa-web-header`,children:[i&&(0,w.jsx)(`button`,{type:`button`,className:`wa-web-back`,onClick:i,"aria-label":`Back`,children:(0,w.jsx)(y,{size:20})}),(0,w.jsx)(`span`,{className:`wa-web-avatar`,"aria-hidden":!0,children:(0,w.jsx)(m,{size:20})}),(0,w.jsx)(`div`,{className:`wa-web-titles`,children:(0,w.jsx)(`span`,{className:`wa-web-name`,children:r})})]}),(0,w.jsx)(`div`,{className:`wa-web-body`,children:(0,w.jsx)(p,{sessionId:e,projectDir:t,sessionKey:n,forceDeliveredOnly:!0})})]})}var D=6e4,O=60*D,k=24*O,A=D,j=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],M=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function N(e){return e<10?`0${e}`:String(e)}function P(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime()}function F(e,t){if(!Number.isFinite(e)||e<=0||!Number.isFinite(t))return`—`;let n=t-e;if(n<-A)return`—`;let r=n<0?0:n;if(r<D)return`just now`;if(r<O)return`${Math.floor(r/D)}m`;if(r<k)return`${Math.floor(r/O)}h`;let i=new Date(t),a=new Date(e),o=Math.round((P(i)-P(a))/k);if(o===1)return`yesterday`;if(o>=2&&o<=6)return M[a.getDay()];let s=N(a.getDate()),c=j[a.getMonth()];return a.getFullYear()===i.getFullYear()?`${s} ${c}`:`${s} ${c} ${a.getFullYear()}`}function I({variant:e=`row`,count:t=1}){return(0,w.jsx)(w.Fragment,{children:Array.from({length:t},(t,n)=>(0,w.jsx)(`span`,{className:`dashboard-skeleton dashboard-skeleton--${e}`,"data-testid":`dashboard-skeleton`,"aria-hidden":`true`},n))})}var ce=6e4;function le(e){return e<12?`morning`:e<18?`afternoon`:`evening`}function L(e){return e&&e.trim().split(/\s+/)[0]||`there`}function ue(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 R(e){return e==null?`—`:`${Math.round(e*100)}%`}function de(e){return e.isGroup===!0?e.chatName??e.title:e.operatorName??e.chatName??e.whatsappName??e.senderId??e.title}function z(e,t){if(!e)return!1;let n=Date.parse(e);if(!Number.isFinite(n))return!1;let r=new Date(n),i=new Date(t);return r.getFullYear()===i.getFullYear()&&r.getMonth()===i.getMonth()&&r.getDate()===i.getDate()}function fe(e){return e?e.replace(/^claude-/,``):null}var B=new Set([`sessions`,`conversations`,`tasks`,`artefacts`,`skills`,`stats`]),V=!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:[...B].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 H({cacheKey:e,userName:n,onSelectWhatsappConversation:r}){let i=ee(e),[o,d]=(0,C.useState)(null),[f,p]=(0,C.useState)(null),[m,g]=(0,C.useState)(null),v=(0,C.useRef)(!1),[y,b]=(0,C.useState)(null),[x,S]=(0,C.useState)(null),[T,E]=(0,C.useState)(null),[D,O]=(0,C.useState)(null),[k,A]=(0,C.useState)(null),[j,M]=(0,C.useState)(null),[N,P]=(0,C.useState)(new Set),[B,H]=(0,C.useState)(()=>new Set),U=(0,C.useCallback)(e=>{H(t=>t.has(e)?t:new Set(t).add(e))},[]),W=Date.now(),G=(0,C.useRef)(!1),K=(0,C.useRef)(new Map),q=(0,C.useRef)(new Set),J=(0,C.useRef)(null);(0,C.useEffect)(()=>{if(!e)return;let t=!1;async function n(e,n,r,a){let o=Date.now(),s=typeof n==`string`?n:`unresolved`;try{typeof n!=`string`&&(s=await n());let c=await i(s);if(!c.ok)throw Error(`status ${c.status}`);let l=await c.json();t||a(r(l)),console.info(`[admin-ui] op=dashboard-fetch slice=${e} url=${s} outcome=ok ms=${Date.now()-o}`)}catch(t){q.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{K.current.set(e,Date.now()-o),U(e)}}async function r(){if(!J.current){let e=await i(`/api/admin/accounts`);if(!e.ok)throw Error(`accounts status ${e.status}`);let t=await e.json(),n=t.accounts??[],r=t.activeAccountId??null,a=n.find(e=>e.accountId===r);if(!a)throw Error(`accounts: active ${r??`none`} absent from list of ${n.length}`);let o=a.isHouse||n.length===1;J.current={accountId:a.accountId,isHouse:o}}let{accountId:e,isHouse:t}=J.current;return console.info(`[admin-ui] op=dashboard-channels-source source=${t?`all`:`scoped`} account=${e.slice(0,8)}`),t?`/api/operator-conversations/conversations-all`:`/api/operator-conversations/conversations`}let o={"sidebar-sessions":()=>n(`sessions`,`/api/admin/sidebar-sessions`,e=>e.sessions??[],d),"conversations-all":()=>n(`conversations`,r,e=>e.conversations??[],p),"tasks-list":()=>n(`tasks`,`/api/admin/tasks-list`,e=>e,S),"sidebar-artefacts":()=>n(`artefacts`,`/api/admin/sidebar-artefacts`,e=>e.artefacts??[],E),skills:()=>n(`skills`,`/api/admin/skills`,e=>e.skills??[],O)};async function s(){if(G.current)return;G.current=!0;let e=Date.now();try{await Promise.all([...Object.values(o).map(e=>e()),n(`stats`,`/api/admin/system-stats`,e=>e,b),n(`bookingLink`,`/api/admin/calendar/booking-link`,e=>e.bookingDomain??null,A),n(`portalLink`,`/api/admin/data-portal/portal-link`,e=>e.portalDomain??null,M)])}finally{G.current=!1;let t=Date.now()-e;if(console.info(`[admin-ui] op=dashboard-refresh-settled ms=${t}`),!V){V=!0;try{let e=pe(t,K.current,q.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{}}}}s();let c=null;try{c=new EventSource(a(`/api/admin/events`,e)),c.onmessage=e=>{if(document.visibilityState===`visible`)try{let{resource:t}=JSON.parse(e.data),n=t?o[t]:void 0;n&&n()}catch{}},c.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 l=setInterval(()=>{document.visibilityState===`visible`&&s()},ce),u=()=>{document.visibilityState===`visible`&&s()};return document.addEventListener(`visibilitychange`,u),()=>{t=!0,G.current=!1,clearInterval(l),c?.close(),document.removeEventListener(`visibilitychange`,u)}},[e,i]);let Y=(0,C.useMemo)(()=>(o??[]).filter(e=>!e.isSubagent),[o]),X=(0,C.useMemo)(()=>Y.filter(e=>e.live),[Y]),me=(0,C.useMemo)(()=>(f??[]).filter(e=>z(e.lastMessageAt,W)).length,[f,W]),he=x?.open.length??0,Z=(0,C.useMemo)(()=>{let e=new Map;for(let t of f??[]){let n=e.get(t.channel)??[];n.push(t),e.set(t.channel,n)}return[...e.entries()].map(([e,t])=>{let n=t.reduce((e,t)=>t.lastMessageAt&&(!e||Date.parse(t.lastMessageAt)>Date.parse(e.lastMessageAt??``))?t:e,null);return{channel:e,count:t.length,preview:n?de(n):``,rows:t}})},[f]);(0,C.useEffect)(()=>{v.current||Z.length!==0&&(v.current=!0,g(Z[0].channel))},[Z]);let Q=(0,C.useRef)(!1);(0,C.useEffect)(()=>{Q.current||!B.has(`bookingLink`)||!B.has(`portalLink`)||(Q.current=!0,console.info(`[admin-ui] dashboard-public-pages booking=${k!=null} filedrop=${j!=null}`))},[B,k,j]);let ge=(0,C.useCallback)(async e=>{if(!N.has(e)){P(t=>new Set(t).add(e));try{let t=await i(`/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}console.info(`[admin-ui] dashboard-session-stop sessionId=${e}`),d(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{P(t=>{let n=new Set(t);return n.delete(e),n})}}},[i,N]),_e=(0,C.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}ae(e,t.downloadPath,t.downloadRoot??`data`)},[e]),$=le(new Date(W).getHours());return(0,w.jsxs)(`div`,{className:`ui-page ui-page--full dashboard-home`,children:[(0,w.jsx)(`p`,{className:`dashboard-greeting`,children:B.has(`stats`)?`Good ${$}, ${L(n)} — ${ue(y)}`:`Good ${$}, ${L(n)}`}),(0,w.jsxs)(`div`,{className:`dashboard-stats`,children:[(0,w.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,w.jsx)(`span`,{className:`dashboard-stat-label`,children:`Live sessions`}),B.has(`sessions`)?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`span`,{className:`dashboard-stat-value`,children:X.length}),(0,w.jsxs)(`span`,{className:`dashboard-stat-delta`,children:[`of `,Y.length,` total`]})]}):(0,w.jsx)(I,{variant:`value`})]}),(0,w.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,w.jsx)(`span`,{className:`dashboard-stat-label`,children:`Messages today`}),B.has(`conversations`)?(0,w.jsx)(`span`,{className:`dashboard-stat-value`,children:me}):(0,w.jsx)(I,{variant:`value`})]}),(0,w.jsxs)(`a`,{className:`admin-stat-card dashboard-stat-card dashboard-stat-card--link`,href:`/tasks`,children:[(0,w.jsx)(`span`,{className:`dashboard-stat-label`,children:`Open tasks`}),B.has(`tasks`)?(0,w.jsx)(`span`,{className:`dashboard-stat-value`,children:he}):(0,w.jsx)(I,{variant:`value`})]}),(0,w.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,w.jsx)(`span`,{className:`dashboard-stat-label`,children:`Host CPU`}),B.has(`stats`)?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`span`,{className:`dashboard-stat-value`,children:R(y?.cpuPct??null)}),(0,w.jsxs)(`span`,{className:`dashboard-stat-delta`,children:[`RAM `,R(y?.memUsedPct??null)]})]}):(0,w.jsx)(I,{variant:`value`})]})]}),(0,w.jsxs)(`div`,{className:`dashboard-columns`,children:[(0,w.jsxs)(`div`,{className:`dashboard-col`,children:[(k||j)&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Public pages`}),(0,w.jsxs)(`div`,{className:`admin-card dashboard-public-pages`,children:[k&&(0,w.jsxs)(`a`,{className:`admin-row dashboard-public-row`,href:`https://${k}`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,w.jsx)(`span`,{className:`dashboard-public-icon`,children:(0,w.jsx)(_,{size:16})}),(0,w.jsx)(`span`,{className:`dashboard-public-name`,children:`Booking page`})]}),j&&(0,w.jsxs)(`a`,{className:`admin-row dashboard-public-row`,href:`https://${j}`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,w.jsx)(`span`,{className:`dashboard-public-icon`,children:(0,w.jsx)(_,{size:16})}),(0,w.jsx)(`span`,{className:`dashboard-public-name`,children:`File drop`})]})]})]}),(0,w.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Live now`}),B.has(`sessions`)?X.length===0?(0,w.jsx)(`div`,{className:`admin-card dashboard-empty`,children:`No live sessions right now.`}):X.map(e=>{let t=[e.sessionId.slice(0,8),fe(e.model),F(Date.parse(e.startedAt),W)].filter(Boolean).join(` · `);return(0,w.jsxs)(`div`,{className:`admin-card dashboard-live-card`,children:[(0,w.jsx)(`span`,{className:`admin-status-dot is-live`}),(0,w.jsxs)(`div`,{className:`dashboard-live-main`,children:[(0,w.jsx)(`span`,{className:`dashboard-live-name`,children:e.title}),(0,w.jsx)(`span`,{className:`dashboard-live-meta`,children:t})]}),(0,w.jsx)(`a`,{className:`admin-btn-cta dashboard-open-btn`,href:`/chat?session=${encodeURIComponent(e.sessionId)}`,children:`Open`}),(0,w.jsx)(`button`,{type:`button`,className:`dashboard-stop-btn`,"aria-label":`Stop ${e.title}`,disabled:N.has(e.sessionId),onClick:()=>void ge(e.sessionId),children:(0,w.jsx)(te,{size:12})})]},e.sessionId)}):(0,w.jsx)(I,{variant:`card`,count:2}),(0,w.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Recent artefacts`}),(0,w.jsx)(`div`,{className:`admin-card dashboard-artefacts`,children:B.has(`artefacts`)?(T??[]).length===0?(0,w.jsx)(`div`,{className:`dashboard-empty`,children:`No recent artefacts.`}):(T??[]).slice(0,6).map(e=>(0,w.jsxs)(`button`,{type:`button`,className:`admin-row dashboard-artefact-row`,onClick:()=>_e(e),children:[(0,w.jsx)(`span`,{className:`dashboard-artefact-icon`,children:e.kind===`agent-template`?(0,w.jsx)(h,{size:16}):(0,w.jsx)(se,{size:16})}),(0,w.jsx)(`div`,{className:`dashboard-artefact-body`,children:(0,w.jsx)(`span`,{className:`dashboard-artefact-name`,children:e.name})}),(0,w.jsx)(`span`,{className:`dashboard-artefact-time`,children:F(Date.parse(e.updatedAt),W)})]},e.id)):(0,w.jsx)(I,{count:3})}),(0,w.jsx)(`a`,{className:`admin-section-label dashboard-col-label dashboard-skills-label`,href:`/skills`,children:`Skills`}),(0,w.jsx)(`div`,{className:`admin-card dashboard-skills`,children:B.has(`skills`)?(D??[]).length===0?(0,w.jsx)(`div`,{className:`dashboard-empty`,children:`No skills yet.`}):(D??[]).map(e=>(0,w.jsxs)(`a`,{className:`admin-row dashboard-skill-row`,href:`/skills`,children:[(0,w.jsx)(`span`,{className:`dashboard-skill-icon`,children:(0,w.jsx)(ie,{size:16})}),(0,w.jsxs)(`div`,{className:`dashboard-skill-body`,children:[(0,w.jsx)(`span`,{className:`dashboard-skill-name`,children:e.skill}),(0,w.jsx)(`span`,{className:`dashboard-skill-plugin`,children:e.plugin})]})]},`${e.plugin}/${e.skill}`)):(0,w.jsx)(I,{count:2})})]}),(0,w.jsxs)(`div`,{className:`dashboard-col`,children:[(0,w.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Channels`}),B.has(`conversations`)?Z.length===0?(0,w.jsx)(`div`,{className:`admin-card dashboard-empty`,children:`No channel activity.`}):Z.map(n=>{let i=m===n.channel;return(0,w.jsxs)(`div`,{className:`admin-card dashboard-channel-card`,children:[(0,w.jsxs)(`button`,{type:`button`,className:`dashboard-channel-head`,"aria-expanded":i,onClick:()=>g(e=>e===n.channel?null:n.channel),children:[(0,w.jsx)(`span`,{className:`dashboard-channel-glyph`,children:n.channel===`whatsapp`||n.channel===`telegram`?(0,w.jsx)(c,{channel:n.channel,size:16}):(0,w.jsx)(t,{size:16})}),(0,w.jsx)(`span`,{className:`dashboard-channel-name`,children:u[n.channel]??n.channel}),(0,w.jsx)(`span`,{className:`dashboard-channel-badge`,children:n.count}),(0,w.jsx)(`span`,{className:`dashboard-channel-chevron`,children:i?(0,w.jsx)(re,{size:14}):(0,w.jsx)(oe,{size:14})})]}),i?(0,w.jsx)(`div`,{className:`dashboard-channel-convs`,children:n.rows.map(t=>(0,w.jsxs)(`button`,{type:`button`,className:`admin-row dashboard-channel-conv-row`,onClick:()=>r(t),title:t.title,children:[(0,w.jsxs)(`span`,{className:`dashboard-channel-conv-line`,children:[(0,w.jsx)(ne,{accountId:t.accountId??``,jid:t.remoteJid,sessionKey:e??``,className:`dashboard-channel-conv-avatar`,size:16}),(0,w.jsx)(`span`,{className:`dashboard-channel-conv-name`,children:s(t)}),t.isGroup===!0&&(0,w.jsx)(`span`,{className:`dashboard-channel-conv-tag is-group`,children:`Group`}),t.role===`public`&&(0,w.jsx)(`span`,{className:`dashboard-channel-conv-tag is-public`,children:`Public`}),(0,w.jsx)(`span`,{className:`dashboard-channel-conv-tag`,children:t.isHouse?`House`:`Client`}),!t.preview&&t.lastMessageAt&&(0,w.jsx)(`span`,{className:`dashboard-channel-conv-time`,children:F(Date.parse(t.lastMessageAt),W)})]}),t.preview?(0,w.jsxs)(`span`,{className:`dashboard-channel-conv-sub`,children:[(0,w.jsx)(`span`,{className:`dashboard-channel-conv-preview`,children:t.preview}),t.lastMessageAt&&(0,w.jsx)(`span`,{className:`dashboard-channel-conv-time`,children:F(Date.parse(t.lastMessageAt),W)})]}):null]},l(t)))}):n.preview&&(0,w.jsx)(`span`,{className:`dashboard-channel-preview`,children:n.preview})]},n.channel)}):(0,w.jsx)(I,{variant:`card`,count:2})]})]})]})}function U(){let e=d(),[t,n]=(0,C.useState)(!1);(0,C.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,C.useCallback)(async()=>{let t=e.claudeInfo!=null;if(n(!0),t){console.info(`[admin-ui] claude-info-open cached=true ms=0`);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)}console.info(`[admin-ui] claude-info-open cached=false ms=${Date.now()-r}`)}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,C.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,w.jsx)(o,{cacheKey:e.cacheKey,onSessionExpired:i,surface:`chat`,children:(0,w.jsx)(v,{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,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(T,{onOpen:r}),(0,w.jsx)(g,{show:t,onClose:()=>n(!1),claudeInfo:e.claudeInfo,messages:[],sessionElapsed:0,sessionId:e.sessionId,cacheKey:e.cacheKey})]}),children:t=>(0,w.jsx)(w.Fragment,{children:t.dataOpen&&e.cacheKey?(0,w.jsx)(b,{cacheKey:e.cacheKey}):t.selectedWhatsapp&&e.cacheKey?t.selectedWhatsapp.source===`store`&&t.selectedWhatsapp.remoteJid&&t.selectedWhatsapp.accountId?(0,w.jsx)(x,{accountId:t.selectedWhatsapp.accountId,remoteJid:t.selectedWhatsapp.remoteJid,contactName:s(t.selectedWhatsapp),sessionKey:e.cacheKey,onBack:t.onClearWhatsapp},l(t.selectedWhatsapp)):(0,w.jsx)(E,{sessionId:t.selectedWhatsapp.sessionId,projectDir:t.selectedWhatsapp.projectDir,sessionKey:e.cacheKey,contactName:s(t.selectedWhatsapp),onBack:t.onClearWhatsapp},l(t.selectedWhatsapp)):(0,w.jsx)(H,{cacheKey:e.cacheKey,userName:e.userName,onSelectWhatsappConversation:t.onSelectWhatsappConversation})})})}):(0,w.jsx)(f,{auth:e})}(0,S.createRoot)(document.getElementById(`root`)).render((0,w.jsx)(U,{}));
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{G as t,H as n,J as r,K as i,L as a,O as o,_ as s,b as c,g as l,y as u}from"./useSubAccountSwitcher-HjQZjJBr.js";import{C as d,O as f,b as p,t as m}from"./AdminShell-Cbk0TL1B.js";var h=a(`power-off`,[[`path`,{d:`M18.36 6.64A9 9 0 0 1 20.77 15`,key:`dxknvb`}],[`path`,{d:`M6.16 6.16a9 9 0 1 0 12.68 12.68`,key:`1x7qb5`}],[`path`,{d:`M12 2v4`,key:`3427ic`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),g=a(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),_=i(),v=e(r(),1),y={green:`success`,amber:`warning`,red:`error`};function b(e){if(!e.startsWith(`mcp__`))return e;let t=e.slice(5),n=t.indexOf(`__`);if(n<0)return e;let r=t.slice(n+2);return r.length>0?r:e}function x(e){let t=` Nothing will be able to hand work to it until it is switched back on.`;if(e.length===0)return t;let n=e.length===1?`skill runs`:`skills run`;return` ${e.length} ${n} through it: ${e.join(`, `)}.${t}`}var S=n(),C={read:`read`,write_local:`writes`,exec:`runs`,external:`sends`},w={read:`tool-chip-read`,write_local:`tool-chip-write_local`,exec:`tool-chip-exec`,external:`tool-chip-external`,unresolved:`tool-chip-unresolved`};function T({label:e,body:t}){return(0,S.jsxs)(`div`,{className:`agent-doc`,children:[(0,S.jsx)(`span`,{className:`agent-doc-label`,children:e}),(0,S.jsx)(`pre`,{className:`skill-body`,children:t.trim()||`Empty.`})]})}function E({summary:e,publicBaseUrl:t,accountId:n,adminFetch:r,onClose:i,onDeleted:a,onToggled:s}){let l=e.kind===`specialist`,f=e.origin===`specialist`,m=e.origin===`shipped`&&e.disabled,_=f||m,[E]=(0,v.useState)(n),[D,O]=(0,v.useState)(null),[k,A]=(0,v.useState)(!0),[j,M]=(0,v.useState)(null),[N,P]=(0,v.useState)(!1),[F,I]=(0,v.useState)(!1),[L,R]=(0,v.useState)(!1),[z,B]=(0,v.useState)(!1);(0,v.useEffect)(()=>{let t=!1;A(!0),M(null);let n=e.origin===`shipped`?`?origin=shipped`:e.kind===`specialist`&&e.plugin?`?plugin=${encodeURIComponent(e.plugin)}`:``;return r(`/api/admin/agents/${encodeURIComponent(e.slug)}${n}`).then(async e=>{if(!t){if(!e.ok)throw Error(`HTTP ${e.status}`);O((await e.json()).agent)}}).catch(e=>{t||M(e instanceof Error?e.message:`Failed to load`)}).finally(()=>{t||A(!1)}),()=>{t=!0}},[r,e.slug]),(0,v.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!F&&i()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[F,i]);let V=(0,v.useCallback)(async()=>{I(!0),M(null);try{let t=await r(`/api/admin/agents/${encodeURIComponent(e.slug)}?accountId=${encodeURIComponent(E??``)}`,{method:`DELETE`,headers:{"content-type":`application/json`}});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??`HTTP ${t.status}`)}a(e)}catch(e){M(e instanceof Error?e.message:`Delete failed`),I(!1),P(!1)}},[r,e,E,a]),H=(0,v.useCallback)(async()=>{let t=e.disabled?`enable`:`disable`;B(!0),M(null);try{let n=await r(`/api/admin/agents/${encodeURIComponent(e.slug)}/${t}?accountId=${encodeURIComponent(E??``)}`,{method:`POST`,headers:{"content-type":`application/json`}});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??`HTTP ${n.status}`)}s(),i()}catch(e){M(e instanceof Error?e.message:`${t} failed`),B(!1),R(!1)}},[r,e,E,s,i]),U=l?null:D,W=l?D:null;return(0,S.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{F||i()},children:(0,S.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":`Agent detail`,onClick:e=>e.stopPropagation(),children:[(0,S.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,S.jsxs)(`span`,{className:`cal-modal-kind`,children:[(0,S.jsx)(d,{size:13}),` `,l?`Specialist`:`Agent`]}),(0,S.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:i,"aria-label":`Close`,autoFocus:!0,disabled:F,children:(0,S.jsx)(u,{size:16})})]}),(0,S.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,S.jsx)(`div`,{className:`cal-modal-title`,children:e.displayName}),(0,S.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[!l&&(0,S.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),(0,S.jsxs)(`span`,{children:[`/`,e.slug]}),e.risk&&(0,S.jsx)(`span`,{className:`ui-pill ui-pill--solid-${y[e.risk]}`,children:e.risk===`green`?`Read only`:e.risk===`amber`?`Writes`:`Runs`}),e.disabled&&(0,S.jsx)(`span`,{className:`ui-pill ui-pill--tint-error`,children:`Disabled`})]}),e.risk&&e.riskReason&&(0,S.jsx)(`div`,{className:`cal-modal-row agent-risk-reason`,children:(0,S.jsx)(`span`,{children:e.riskReason})}),e.unresolved.length>0&&(0,S.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,S.jsxs)(`span`,{children:[`Forced to Runs: no declared risk class for `,e.unresolved.join(`, `),`.`]})}),k&&(0,S.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,S.jsx)(o,{size:14,className:`spin`}),(0,S.jsx)(`span`,{children:`Loading…`})]}),U&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,S.jsxs)(`span`,{children:[U.status,U.model?` · ${U.model}`:``]})}),(0,S.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,S.jsxs)(`a`,{href:`${t}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`cal-link`,children:[(0,S.jsx)(p,{size:13}),` Open agent`]})}),U.present.identity&&(0,S.jsx)(T,{label:`Identity`,body:U.identity}),U.present.soul&&(0,S.jsx)(T,{label:`Soul`,body:U.soul}),U.present.knowledge&&(0,S.jsx)(T,{label:`Knowledge`,body:U.knowledge}),U.present.knowledgeSummary&&(0,S.jsx)(T,{label:`Knowledge summary`,body:U.knowledgeSummary}),U.knowledgeKeywords.length>0&&(0,S.jsxs)(`div`,{className:`skill-refs`,children:[(0,S.jsx)(`span`,{className:`skill-refs-label`,children:`Knowledge keywords`}),U.knowledgeKeywords.map(e=>(0,S.jsx)(`span`,{className:`skill-ref`,children:e},e))]})]}),W&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,S.jsxs)(`span`,{children:[e.plugin,W.model?` · ${W.model}`:``]})}),W.description&&(0,S.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,S.jsx)(`span`,{children:W.description})}),W.byTool.length>0&&(0,S.jsxs)(`div`,{className:`chip-refs`,children:[(0,S.jsxs)(`span`,{className:`skill-refs-label`,children:[`Tools (`,W.byTool.length,`)`]}),(0,S.jsx)(`div`,{className:`chip-row`,children:W.byTool.map(({tool:e,risk:t})=>(0,S.jsx)(`span`,{"data-testid":`tool-chip-${e}`,className:`tool-chip ${w[t??`unresolved`]}`,title:t?`${e} — ${C[t]}`:`${e} — no declared risk class`,children:b(e)},e))})]}),W.skills.length>0&&(0,S.jsxs)(`div`,{className:`chip-refs`,children:[(0,S.jsx)(`span`,{className:`skill-refs-label`,children:`Skills`}),(0,S.jsx)(`div`,{className:`chip-row`,children:W.skills.map(e=>(0,S.jsx)(`span`,{className:`tool-chip tool-chip-skill`,children:e},e))})]}),(0,S.jsx)(T,{label:`System prompt`,body:W.systemPrompt})]})]}),j&&(0,S.jsx)(`div`,{className:`cal-modal-error`,children:j}),(0,S.jsx)(`div`,{className:`cal-modal-actions`,children:_?L?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`span`,{className:`cal-modal-confirm-text`,children:e.disabled?`Put this agent back in the dispatchable set?`:`Stop this agent being dispatched?${x(W?.skills??[])}`}),(0,S.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:H,disabled:z,children:[z?(0,S.jsx)(o,{size:14,className:`spin`}):e.disabled?(0,S.jsx)(g,{size:14}):(0,S.jsx)(h,{size:14}),e.disabled?` Enable`:` Disable`]}),(0,S.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>R(!1),disabled:z,children:`Cancel`})]}):(0,S.jsx)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:()=>R(!0),disabled:z||k||!E,children:e.disabled?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(g,{size:14}),` Enable`]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(h,{size:14}),` Disable`]})}):l?(0,S.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`This agent is part of the product. To stop it running on its own, suspend the routines that dispatch it.`}):(0,S.jsxs)(S.Fragment,{children:[!N&&(0,S.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:()=>P(!0),disabled:F||k||!E,children:[(0,S.jsx)(c,{size:14}),` Delete`]}),N&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Delete this agent?`}),(0,S.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:V,disabled:F,children:[F?(0,S.jsx)(o,{size:14,className:`spin`}):(0,S.jsx)(c,{size:14}),` Delete`]}),(0,S.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>P(!1),disabled:F,children:`Cancel`})]})]})})]})})}var D=`maxy-admin-session-key`,O={green:`Read only`,amber:`Writes`,red:`Runs`},k={shipped:`Shipped`,specialist:`Specialist`,public:`Public`};function A(){let[e,t]=(0,v.useState)(null),[n,r]=(0,v.useState)(!1),[i,a]=(0,v.useState)(void 0),[o,c]=(0,v.useState)(null),[u,d]=(0,v.useState)(void 0),[p,h]=(0,v.useState)(null),[g,_]=(0,v.useState)(null);(0,v.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(D)}catch{}if(!n){r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`;return}if(i.ok)try{let e=await i.json();typeof e.businessName==`string`&&a(e.businessName),e.sessionId!==void 0&&c(e.sessionId??null),_(e.role??null),d(e.userName===void 0?null:e.userName),h(e.avatar??null)}catch{}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]);let y=(0,v.useCallback)(()=>{try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`},[]),[b,x]=(0,v.useState)(!1),C=(0,v.useCallback)(async()=>{x(!0);try{let e=await f();if(e){try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`}return e}finally{x(!1)}},[]);return n?e?(0,S.jsx)(s,{cacheKey:e,surface:`agents`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=agents`);try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`},children:(0,S.jsx)(m,{cacheKey:e,businessName:i,sessionId:o,onLogout:y,onDisconnect:C,disconnecting:b,userName:u,userAvatar:p,role:g,children:(0,S.jsx)(j,{cacheKey:e})})}):(0,S.jsx)(`div`,{className:`cal-page`,children:(0,S.jsxs)(`div`,{className:`cal-empty`,children:[(0,S.jsx)(`p`,{children:`You are not signed in.`}),(0,S.jsxs)(`p`,{children:[`Open the `,(0,S.jsx)(`a`,{href:`/`,className:`cal-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,S.jsx)(l,{surface:`gate`})}function j({cacheKey:e}){let{adminFetch:n,sessionRefetchNonce:r}=t({initialCacheKey:e,surface:`agents`}),[i,a]=(0,v.useState)([]),[s,c]=(0,v.useState)(0),[u,f]=(0,v.useState)(0),[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(null),[_,b]=(0,v.useState)(!1),[x,C]=(0,v.useState)(!1),[w,T]=(0,v.useState)(null),[D,A]=(0,v.useState)(null),[j,M]=(0,v.useState)(``);(0,v.useEffect)(()=>{M(window.location.hostname.startsWith(`admin.`)?window.location.origin.replace(`admin.`,`public.`):window.location.origin)},[]);let N=(0,v.useCallback)(()=>{let e=!1;return b(!0),T(null),n(`/api/admin/agents`).then(async t=>{if(e)return;if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();a(Array.isArray(n.agents)?n.agents:[]),c(typeof n.skipped==`number`?n.skipped:0),f(typeof n.specialistsSkipped==`number`?n.specialistsSkipped:0),g(typeof n.accountId==`string`?n.accountId:null),m(n.riskSurfaceFailed===!0)}).catch(t=>{e||(T(t instanceof Error?t.message:`Failed to load`),a([]))}).finally(()=>{e||(b(!1),C(!0))}),()=>{e=!0}},[n]);(0,v.useEffect)(()=>N(),[N,r]);let P=(0,v.useCallback)(e=>{a(t=>t.filter(t=>t.slug!==e.slug)),A(null),N()},[N]);if(!x)return(0,S.jsx)(l,{surface:`gate`});let F=i.filter(e=>e.disabled).length;return(0,S.jsxs)(`div`,{className:`cal-page`,children:[(0,S.jsx)(`header`,{className:`cal-header`,children:(0,S.jsxs)(`div`,{className:`cal-nav`,children:[(0,S.jsxs)(`span`,{className:`cal-range-label`,children:[(0,S.jsx)(d,{size:16}),` `,i.length,` agent`,i.length===1?``:`s`,` · `,F,` stood down`]}),_&&(0,S.jsx)(o,{size:16,className:`spin`})]})}),(0,S.jsxs)(`div`,{className:`cal-body`,children:[w&&(0,S.jsxs)(`div`,{className:`cal-error`,children:[`Could not load agents: `,w]}),p&&(0,S.jsx)(`div`,{className:`cal-error`,children:`The plugin registry could not be read, so every agent below is shown at the highest risk regardless of the tools it declares. These badges are not derived.`}),s+u>0&&(0,S.jsxs)(`div`,{className:`cal-error`,children:[s+u,` agent`,s+u===1?``:`s`,` could not be read (malformed config or frontmatter).`]}),!w&&!_&&i.length===0&&(0,S.jsx)(`div`,{className:`cal-empty`,children:(0,S.jsx)(`p`,{children:`No agents yet. Ask in chat to create one.`})}),i.length>0&&(0,S.jsx)(`div`,{className:`routine-list`,children:i.map(e=>(0,S.jsxs)(`button`,{type:`button`,className:`admin-card admin-card--padded routine-card`,onClick:()=>A(e),children:[(0,S.jsxs)(`span`,{className:`admin-card-title routine-card-title`,children:[e.displayName,e.risk&&(0,S.jsx)(`span`,{className:`ui-pill ui-pill--solid-${y[e.risk]}`,"data-testid":`agent-risk-badge`,children:O[e.risk]}),(0,S.jsx)(`span`,{className:`ui-pill agent-origin-${e.origin}`,children:k[e.origin]}),e.kind===`specialist`&&(0,S.jsx)(`span`,{className:`ui-pill ${e.disabled?`ui-pill--tint-error`:`ui-pill--tint-success`}`,children:e.disabled?`Stood down`:`Live`})]}),e.kind===`specialist`?(0,S.jsxs)(`span`,{className:`routine-card-sched`,children:[`/`,e.slug]}):(0,S.jsxs)(`span`,{className:`routine-card-sched`,children:[(0,S.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),` /`,e.slug]}),(0,S.jsx)(`span`,{className:`routine-card-meta`,children:e.origin===`public`?e.status:e.plugin})]},`${e.origin}:${e.slug}`))})]}),D&&(0,S.jsx)(E,{summary:D,publicBaseUrl:j,accountId:h,adminFetch:n,onClose:()=>A(null),onDeleted:P,onToggled:N})]})}(0,_.createRoot)(document.getElementById(`root`)).render((0,S.jsx)(A,{}));
1
+ import{o as e}from"./chunk-CltuBf4Z.js";import{G as t,H as n,J as r,K as i,L as a,O as o,_ as s,b as c,g as l,y as u}from"./useSubAccountSwitcher-BEwQMRMo.js";import{C as d,O as f,b as p,t as m}from"./AdminShell-D5GApZ_n.js";var h=a(`power-off`,[[`path`,{d:`M18.36 6.64A9 9 0 0 1 20.77 15`,key:`dxknvb`}],[`path`,{d:`M6.16 6.16a9 9 0 1 0 12.68 12.68`,key:`1x7qb5`}],[`path`,{d:`M12 2v4`,key:`3427ic`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),g=a(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),_=i(),v=e(r(),1),y={green:`success`,amber:`warning`,red:`error`};function b(e){if(!e.startsWith(`mcp__`))return e;let t=e.slice(5),n=t.indexOf(`__`);if(n<0)return e;let r=t.slice(n+2);return r.length>0?r:e}function x(e){let t=` Nothing will be able to hand work to it until it is switched back on.`;if(e.length===0)return t;let n=e.length===1?`skill runs`:`skills run`;return` ${e.length} ${n} through it: ${e.join(`, `)}.${t}`}var S=n(),C={read:`read`,write_local:`writes`,exec:`runs`,external:`sends`},w={read:`tool-chip-read`,write_local:`tool-chip-write_local`,exec:`tool-chip-exec`,external:`tool-chip-external`,unresolved:`tool-chip-unresolved`};function T({label:e,body:t}){return(0,S.jsxs)(`div`,{className:`agent-doc`,children:[(0,S.jsx)(`span`,{className:`agent-doc-label`,children:e}),(0,S.jsx)(`pre`,{className:`skill-body`,children:t.trim()||`Empty.`})]})}function E({summary:e,publicBaseUrl:t,accountId:n,adminFetch:r,onClose:i,onDeleted:a,onToggled:s}){let l=e.kind===`specialist`,f=e.origin===`specialist`,m=e.origin===`shipped`&&e.disabled,_=f||m,[E]=(0,v.useState)(n),[D,O]=(0,v.useState)(null),[k,A]=(0,v.useState)(!0),[j,M]=(0,v.useState)(null),[N,P]=(0,v.useState)(!1),[F,I]=(0,v.useState)(!1),[L,R]=(0,v.useState)(!1),[z,B]=(0,v.useState)(!1);(0,v.useEffect)(()=>{let t=!1;A(!0),M(null);let n=e.origin===`shipped`?`?origin=shipped`:e.kind===`specialist`&&e.plugin?`?plugin=${encodeURIComponent(e.plugin)}`:``;return r(`/api/admin/agents/${encodeURIComponent(e.slug)}${n}`).then(async e=>{if(!t){if(!e.ok)throw Error(`HTTP ${e.status}`);O((await e.json()).agent)}}).catch(e=>{t||M(e instanceof Error?e.message:`Failed to load`)}).finally(()=>{t||A(!1)}),()=>{t=!0}},[r,e.slug]),(0,v.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!F&&i()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[F,i]);let V=(0,v.useCallback)(async()=>{I(!0),M(null);try{let t=await r(`/api/admin/agents/${encodeURIComponent(e.slug)}?accountId=${encodeURIComponent(E??``)}`,{method:`DELETE`,headers:{"content-type":`application/json`}});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??`HTTP ${t.status}`)}a(e)}catch(e){M(e instanceof Error?e.message:`Delete failed`),I(!1),P(!1)}},[r,e,E,a]),H=(0,v.useCallback)(async()=>{let t=e.disabled?`enable`:`disable`;B(!0),M(null);try{let n=await r(`/api/admin/agents/${encodeURIComponent(e.slug)}/${t}?accountId=${encodeURIComponent(E??``)}`,{method:`POST`,headers:{"content-type":`application/json`}});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??`HTTP ${n.status}`)}s(),i()}catch(e){M(e instanceof Error?e.message:`${t} failed`),B(!1),R(!1)}},[r,e,E,s,i]),U=l?null:D,W=l?D:null;return(0,S.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{F||i()},children:(0,S.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":`Agent detail`,onClick:e=>e.stopPropagation(),children:[(0,S.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,S.jsxs)(`span`,{className:`cal-modal-kind`,children:[(0,S.jsx)(d,{size:13}),` `,l?`Specialist`:`Agent`]}),(0,S.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:i,"aria-label":`Close`,autoFocus:!0,disabled:F,children:(0,S.jsx)(u,{size:16})})]}),(0,S.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,S.jsx)(`div`,{className:`cal-modal-title`,children:e.displayName}),(0,S.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[!l&&(0,S.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),(0,S.jsxs)(`span`,{children:[`/`,e.slug]}),e.risk&&(0,S.jsx)(`span`,{className:`ui-pill ui-pill--solid-${y[e.risk]}`,children:e.risk===`green`?`Read only`:e.risk===`amber`?`Writes`:`Runs`}),e.disabled&&(0,S.jsx)(`span`,{className:`ui-pill ui-pill--tint-error`,children:`Disabled`})]}),e.risk&&e.riskReason&&(0,S.jsx)(`div`,{className:`cal-modal-row agent-risk-reason`,children:(0,S.jsx)(`span`,{children:e.riskReason})}),e.unresolved.length>0&&(0,S.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,S.jsxs)(`span`,{children:[`Forced to Runs: no declared risk class for `,e.unresolved.join(`, `),`.`]})}),k&&(0,S.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,S.jsx)(o,{size:14,className:`spin`}),(0,S.jsx)(`span`,{children:`Loading…`})]}),U&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,S.jsxs)(`span`,{children:[U.status,U.model?` · ${U.model}`:``]})}),(0,S.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,S.jsxs)(`a`,{href:`${t}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`cal-link`,children:[(0,S.jsx)(p,{size:13}),` Open agent`]})}),U.present.identity&&(0,S.jsx)(T,{label:`Identity`,body:U.identity}),U.present.soul&&(0,S.jsx)(T,{label:`Soul`,body:U.soul}),U.present.knowledge&&(0,S.jsx)(T,{label:`Knowledge`,body:U.knowledge}),U.present.knowledgeSummary&&(0,S.jsx)(T,{label:`Knowledge summary`,body:U.knowledgeSummary}),U.knowledgeKeywords.length>0&&(0,S.jsxs)(`div`,{className:`skill-refs`,children:[(0,S.jsx)(`span`,{className:`skill-refs-label`,children:`Knowledge keywords`}),U.knowledgeKeywords.map(e=>(0,S.jsx)(`span`,{className:`skill-ref`,children:e},e))]})]}),W&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,S.jsxs)(`span`,{children:[e.plugin,W.model?` · ${W.model}`:``]})}),W.description&&(0,S.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,S.jsx)(`span`,{children:W.description})}),W.byTool.length>0&&(0,S.jsxs)(`div`,{className:`chip-refs`,children:[(0,S.jsxs)(`span`,{className:`skill-refs-label`,children:[`Tools (`,W.byTool.length,`)`]}),(0,S.jsx)(`div`,{className:`chip-row`,children:W.byTool.map(({tool:e,risk:t})=>(0,S.jsx)(`span`,{"data-testid":`tool-chip-${e}`,className:`tool-chip ${w[t??`unresolved`]}`,title:t?`${e} — ${C[t]}`:`${e} — no declared risk class`,children:b(e)},e))})]}),W.skills.length>0&&(0,S.jsxs)(`div`,{className:`chip-refs`,children:[(0,S.jsx)(`span`,{className:`skill-refs-label`,children:`Skills`}),(0,S.jsx)(`div`,{className:`chip-row`,children:W.skills.map(e=>(0,S.jsx)(`span`,{className:`tool-chip tool-chip-skill`,children:e},e))})]}),(0,S.jsx)(T,{label:`System prompt`,body:W.systemPrompt})]})]}),j&&(0,S.jsx)(`div`,{className:`cal-modal-error`,children:j}),(0,S.jsx)(`div`,{className:`cal-modal-actions`,children:_?L?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`span`,{className:`cal-modal-confirm-text`,children:e.disabled?`Put this agent back in the dispatchable set?`:`Stop this agent being dispatched?${x(W?.skills??[])}`}),(0,S.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:H,disabled:z,children:[z?(0,S.jsx)(o,{size:14,className:`spin`}):e.disabled?(0,S.jsx)(g,{size:14}):(0,S.jsx)(h,{size:14}),e.disabled?` Enable`:` Disable`]}),(0,S.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>R(!1),disabled:z,children:`Cancel`})]}):(0,S.jsx)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:()=>R(!0),disabled:z||k||!E,children:e.disabled?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(g,{size:14}),` Enable`]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(h,{size:14}),` Disable`]})}):l?(0,S.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`This agent is part of the product. To stop it running on its own, suspend the routines that dispatch it.`}):(0,S.jsxs)(S.Fragment,{children:[!N&&(0,S.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:()=>P(!0),disabled:F||k||!E,children:[(0,S.jsx)(c,{size:14}),` Delete`]}),N&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Delete this agent?`}),(0,S.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:V,disabled:F,children:[F?(0,S.jsx)(o,{size:14,className:`spin`}):(0,S.jsx)(c,{size:14}),` Delete`]}),(0,S.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>P(!1),disabled:F,children:`Cancel`})]})]})})]})})}var D=`maxy-admin-session-key`,O={green:`Read only`,amber:`Writes`,red:`Runs`},k={shipped:`Shipped`,specialist:`Specialist`,public:`Public`};function A(){let[e,t]=(0,v.useState)(null),[n,r]=(0,v.useState)(!1),[i,a]=(0,v.useState)(void 0),[o,c]=(0,v.useState)(null),[u,d]=(0,v.useState)(void 0),[p,h]=(0,v.useState)(null),[g,_]=(0,v.useState)(null);(0,v.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(D)}catch{}if(!n){r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`;return}if(i.ok)try{let e=await i.json();typeof e.businessName==`string`&&a(e.businessName),e.sessionId!==void 0&&c(e.sessionId??null),_(e.role??null),d(e.userName===void 0?null:e.userName),h(e.avatar??null)}catch{}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]);let y=(0,v.useCallback)(()=>{try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`},[]),[b,x]=(0,v.useState)(!1),C=(0,v.useCallback)(async()=>{x(!0);try{let e=await f();if(e){try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`}return e}finally{x(!1)}},[]);return n?e?(0,S.jsx)(s,{cacheKey:e,surface:`agents`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=agents`);try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`},children:(0,S.jsx)(m,{cacheKey:e,businessName:i,sessionId:o,onLogout:y,onDisconnect:C,disconnecting:b,userName:u,userAvatar:p,role:g,children:(0,S.jsx)(j,{cacheKey:e})})}):(0,S.jsx)(`div`,{className:`cal-page`,children:(0,S.jsxs)(`div`,{className:`cal-empty`,children:[(0,S.jsx)(`p`,{children:`You are not signed in.`}),(0,S.jsxs)(`p`,{children:[`Open the `,(0,S.jsx)(`a`,{href:`/`,className:`cal-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,S.jsx)(l,{surface:`gate`})}function j({cacheKey:e}){let{adminFetch:n,sessionRefetchNonce:r}=t({initialCacheKey:e,surface:`agents`}),[i,a]=(0,v.useState)([]),[s,c]=(0,v.useState)(0),[u,f]=(0,v.useState)(0),[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(null),[_,b]=(0,v.useState)(!1),[x,C]=(0,v.useState)(!1),[w,T]=(0,v.useState)(null),[D,A]=(0,v.useState)(null),[j,M]=(0,v.useState)(``);(0,v.useEffect)(()=>{M(window.location.hostname.startsWith(`admin.`)?window.location.origin.replace(`admin.`,`public.`):window.location.origin)},[]);let N=(0,v.useCallback)(()=>{let e=!1;return b(!0),T(null),n(`/api/admin/agents`).then(async t=>{if(e)return;if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();a(Array.isArray(n.agents)?n.agents:[]),c(typeof n.skipped==`number`?n.skipped:0),f(typeof n.specialistsSkipped==`number`?n.specialistsSkipped:0),g(typeof n.accountId==`string`?n.accountId:null),m(n.riskSurfaceFailed===!0)}).catch(t=>{e||(T(t instanceof Error?t.message:`Failed to load`),a([]))}).finally(()=>{e||(b(!1),C(!0))}),()=>{e=!0}},[n]);(0,v.useEffect)(()=>N(),[N,r]);let P=(0,v.useCallback)(e=>{a(t=>t.filter(t=>t.slug!==e.slug)),A(null),N()},[N]);if(!x)return(0,S.jsx)(l,{surface:`gate`});let F=i.filter(e=>e.disabled).length;return(0,S.jsxs)(`div`,{className:`cal-page`,children:[(0,S.jsx)(`header`,{className:`cal-header`,children:(0,S.jsxs)(`div`,{className:`cal-nav`,children:[(0,S.jsxs)(`span`,{className:`cal-range-label`,children:[(0,S.jsx)(d,{size:16}),` `,i.length,` agent`,i.length===1?``:`s`,` · `,F,` stood down`]}),_&&(0,S.jsx)(o,{size:16,className:`spin`})]})}),(0,S.jsxs)(`div`,{className:`cal-body`,children:[w&&(0,S.jsxs)(`div`,{className:`cal-error`,children:[`Could not load agents: `,w]}),p&&(0,S.jsx)(`div`,{className:`cal-error`,children:`The plugin registry could not be read, so every agent below is shown at the highest risk regardless of the tools it declares. These badges are not derived.`}),s+u>0&&(0,S.jsxs)(`div`,{className:`cal-error`,children:[s+u,` agent`,s+u===1?``:`s`,` could not be read (malformed config or frontmatter).`]}),!w&&!_&&i.length===0&&(0,S.jsx)(`div`,{className:`cal-empty`,children:(0,S.jsx)(`p`,{children:`No agents yet. Ask in chat to create one.`})}),i.length>0&&(0,S.jsx)(`div`,{className:`routine-list`,children:i.map(e=>(0,S.jsxs)(`button`,{type:`button`,className:`admin-card admin-card--padded routine-card`,onClick:()=>A(e),children:[(0,S.jsxs)(`span`,{className:`admin-card-title routine-card-title`,children:[e.displayName,e.risk&&(0,S.jsx)(`span`,{className:`ui-pill ui-pill--solid-${y[e.risk]}`,"data-testid":`agent-risk-badge`,children:O[e.risk]}),(0,S.jsx)(`span`,{className:`ui-pill agent-origin-${e.origin}`,children:k[e.origin]}),e.kind===`specialist`&&(0,S.jsx)(`span`,{className:`ui-pill ${e.disabled?`ui-pill--tint-error`:`ui-pill--tint-success`}`,children:e.disabled?`Stood down`:`Live`})]}),e.kind===`specialist`?(0,S.jsxs)(`span`,{className:`routine-card-sched`,children:[`/`,e.slug]}):(0,S.jsxs)(`span`,{className:`routine-card-sched`,children:[(0,S.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),` /`,e.slug]}),(0,S.jsx)(`span`,{className:`routine-card-meta`,children:e.origin===`public`?e.status:e.plugin})]},`${e.origin}:${e.slug}`))})]}),D&&(0,S.jsx)(E,{summary:D,publicBaseUrl:j,accountId:h,adminFetch:n,onClose:()=>A(null),onDeleted:P,onToggled:N})]})}(0,_.createRoot)(document.getElementById(`root`)).render((0,S.jsx)(A,{}));