@rubytech/create-maxy-code 0.1.539 → 0.1.541

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 (269) hide show
  1. package/package.json +1 -1
  2. package/payload/platform/lib/agent-slug/dist/index.d.ts +31 -0
  3. package/payload/platform/lib/agent-slug/dist/index.d.ts.map +1 -0
  4. package/payload/platform/lib/agent-slug/dist/index.js +53 -0
  5. package/payload/platform/lib/agent-slug/dist/index.js.map +1 -0
  6. package/payload/platform/lib/agent-slug/src/index.ts +53 -0
  7. package/payload/platform/lib/agent-slug/tsconfig.json +8 -0
  8. package/payload/platform/package.json +2 -2
  9. package/payload/platform/plugins/admin/.claude-plugin/plugin.json +1 -1
  10. package/payload/platform/plugins/admin/PLUGIN.md +33 -1
  11. package/payload/platform/plugins/admin/mcp/dist/index.js +136 -0
  12. package/payload/platform/plugins/admin/mcp/dist/index.js.map +1 -1
  13. package/payload/platform/plugins/admin/mcp/dist/tools/agent-config-schema.d.ts +9 -0
  14. package/payload/platform/plugins/admin/mcp/dist/tools/agent-config-schema.d.ts.map +1 -0
  15. package/payload/platform/plugins/admin/mcp/dist/tools/agent-config-schema.js +49 -0
  16. package/payload/platform/plugins/admin/mcp/dist/tools/agent-config-schema.js.map +1 -0
  17. package/payload/platform/plugins/admin/mcp/dist/tools/agent-write.d.ts +64 -0
  18. package/payload/platform/plugins/admin/mcp/dist/tools/agent-write.d.ts.map +1 -0
  19. package/payload/platform/plugins/admin/mcp/dist/tools/agent-write.js +151 -0
  20. package/payload/platform/plugins/admin/mcp/dist/tools/agent-write.js.map +1 -0
  21. package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +81 -13
  22. package/payload/platform/plugins/admin/skills/public-agent-manager/SKILL.md +36 -20
  23. package/payload/platform/plugins/admin/skills/update-knowledge/SKILL.md +4 -3
  24. package/payload/platform/plugins/admin/skills/whats-new/SKILL.md +12 -0
  25. package/payload/platform/plugins/docs/references/admin-ui.md +47 -0
  26. package/payload/platform/plugins/docs/references/channel-wake-and-prompt.md +31 -10
  27. package/payload/platform/plugins/docs/references/internals.md +2 -2
  28. package/payload/platform/plugins/whatsapp/PLUGIN.md +2 -2
  29. package/payload/platform/plugins/whatsapp/mcp/dist/__tests__/config-forwards-every-declared-field.test.d.ts +2 -0
  30. package/payload/platform/plugins/whatsapp/mcp/dist/__tests__/config-forwards-every-declared-field.test.d.ts.map +1 -0
  31. package/payload/platform/plugins/whatsapp/mcp/dist/__tests__/config-forwards-every-declared-field.test.js +57 -0
  32. package/payload/platform/plugins/whatsapp/mcp/dist/__tests__/config-forwards-every-declared-field.test.js.map +1 -0
  33. package/payload/platform/plugins/whatsapp/mcp/dist/__tests__/deliverability-grounding.test.js +9 -2
  34. package/payload/platform/plugins/whatsapp/mcp/dist/__tests__/deliverability-grounding.test.js.map +1 -1
  35. package/payload/platform/plugins/whatsapp/mcp/dist/index.js +8 -3
  36. package/payload/platform/plugins/whatsapp/mcp/dist/index.js.map +1 -1
  37. package/payload/platform/plugins/whatsapp/references/channels-whatsapp.md +3 -3
  38. package/payload/platform/plugins/whatsapp/skills/manage-whatsapp-config/SKILL.md +3 -1
  39. package/payload/platform/scripts/__tests__/check-plugin-tool-declarations.test.ts +51 -0
  40. package/payload/platform/scripts/check-no-live-location-claims.mjs +73 -0
  41. package/payload/platform/scripts/check-plugin-tool-declarations.mjs +97 -0
  42. package/payload/platform/scripts/check-risk-class.mjs +5 -0
  43. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.d.ts.map +1 -1
  44. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js +8 -0
  45. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js.map +1 -1
  46. package/payload/platform/services/claude-session-manager/dist/channel-targets.d.ts +3 -0
  47. package/payload/platform/services/claude-session-manager/dist/channel-targets.d.ts.map +1 -1
  48. package/payload/platform/services/claude-session-manager/dist/channel-targets.js.map +1 -1
  49. package/payload/platform/services/claude-session-manager/dist/http-server.d.ts.map +1 -1
  50. package/payload/platform/services/claude-session-manager/dist/http-server.js +20 -1
  51. package/payload/platform/services/claude-session-manager/dist/http-server.js.map +1 -1
  52. package/payload/platform/services/claude-session-manager/dist/index.js +76 -46
  53. package/payload/platform/services/claude-session-manager/dist/index.js.map +1 -1
  54. package/payload/platform/services/claude-session-manager/dist/pty-spawner.d.ts.map +1 -1
  55. package/payload/platform/services/claude-session-manager/dist/pty-spawner.js +57 -8
  56. package/payload/platform/services/claude-session-manager/dist/pty-spawner.js.map +1 -1
  57. package/payload/platform/services/claude-session-manager/dist/public-knowledge-audit.d.ts +58 -0
  58. package/payload/platform/services/claude-session-manager/dist/public-knowledge-audit.d.ts.map +1 -0
  59. package/payload/platform/services/claude-session-manager/dist/public-knowledge-audit.js +152 -0
  60. package/payload/platform/services/claude-session-manager/dist/public-knowledge-audit.js.map +1 -0
  61. package/payload/platform/services/claude-session-manager/dist/wa-channel-mcp.d.ts +4 -0
  62. package/payload/platform/services/claude-session-manager/dist/wa-channel-mcp.d.ts.map +1 -1
  63. package/payload/platform/services/claude-session-manager/dist/wa-channel-mcp.js +3 -0
  64. package/payload/platform/services/claude-session-manager/dist/wa-channel-mcp.js.map +1 -1
  65. package/payload/platform/services/whatsapp-channel/dist/notification.d.ts +40 -3
  66. package/payload/platform/services/whatsapp-channel/dist/notification.d.ts.map +1 -1
  67. package/payload/platform/services/whatsapp-channel/dist/notification.js +43 -4
  68. package/payload/platform/services/whatsapp-channel/dist/notification.js.map +1 -1
  69. package/payload/platform/services/whatsapp-channel/dist/server.d.ts.map +1 -1
  70. package/payload/platform/services/whatsapp-channel/dist/server.js +41 -25
  71. package/payload/platform/services/whatsapp-channel/dist/server.js.map +1 -1
  72. package/payload/platform/services/whatsapp-channel/dist/targets.d.ts +1 -0
  73. package/payload/platform/services/whatsapp-channel/dist/targets.d.ts.map +1 -1
  74. package/payload/platform/services/whatsapp-channel/dist/targets.js +9 -5
  75. package/payload/platform/services/whatsapp-channel/dist/targets.js.map +1 -1
  76. package/payload/server/{chunk-BP7LH7MC.js → chunk-CKTHAHL4.js} +26 -16
  77. package/payload/server/{chunk-IALJPXIO.js → chunk-ERIM3EFB.js} +1 -1
  78. package/payload/server/{chunk-S4FIEM3L.js → chunk-HZP7BKBF.js} +64 -98
  79. package/payload/server/{manager-5QV2EAZ2.js → manager-CM55K4J2.js} +2 -2
  80. package/payload/server/maxy-edge.js +2 -2
  81. package/payload/server/public/activity.html +5 -5
  82. package/payload/server/public/agents.html +4 -4
  83. package/payload/server/public/assets/AdminLoginScreens-DuFCjbz2.js +1 -0
  84. package/payload/server/public/assets/AdminLoginScreens-DuFCjbz2.js.br +0 -0
  85. package/payload/server/public/assets/AdminLoginScreens-DuFCjbz2.js.gz +0 -0
  86. package/payload/server/public/assets/AdminShell-DJL5DzRX.js +2 -0
  87. package/payload/server/public/assets/AdminShell-DJL5DzRX.js.br +0 -0
  88. package/payload/server/public/assets/AdminShell-DJL5DzRX.js.gz +0 -0
  89. package/payload/server/public/assets/activity-CpMnNr5c.js +1 -0
  90. package/payload/server/public/assets/activity-CpMnNr5c.js.br +0 -0
  91. package/payload/server/public/assets/activity-CpMnNr5c.js.gz +0 -0
  92. package/payload/server/public/assets/admin-CBwKIfaI.js +1 -0
  93. package/payload/server/public/assets/admin-CBwKIfaI.js.br +0 -0
  94. package/payload/server/public/assets/admin-CBwKIfaI.js.gz +0 -0
  95. package/payload/server/public/assets/agents-C4LmSKjb.js +1 -0
  96. package/payload/server/public/assets/agents-C4LmSKjb.js.br +0 -0
  97. package/payload/server/public/assets/agents-C4LmSKjb.js.gz +0 -0
  98. package/payload/server/public/assets/browser-Bm9xm_yc.js +1 -0
  99. package/payload/server/public/assets/browser-Bm9xm_yc.js.br +0 -0
  100. package/payload/server/public/assets/browser-Bm9xm_yc.js.gz +0 -0
  101. package/payload/server/public/assets/calendar-CNY9FTWe.js +1 -0
  102. package/payload/server/public/assets/calendar-CNY9FTWe.js.br +0 -0
  103. package/payload/server/public/assets/calendar-CNY9FTWe.js.gz +0 -0
  104. package/payload/server/public/assets/chat-3WoUGCTd.js +1 -0
  105. package/payload/server/public/assets/chat-3WoUGCTd.js.br +0 -0
  106. package/payload/server/public/assets/chat-3WoUGCTd.js.gz +0 -0
  107. package/payload/server/public/assets/chevron-left-BE16BJnw.js +1 -0
  108. package/payload/server/public/assets/chevron-left-BE16BJnw.js.br +0 -0
  109. package/payload/server/public/assets/chevron-right-Bu2VKpeU.js +1 -0
  110. package/payload/server/public/assets/chevron-right-Bu2VKpeU.js.br +0 -0
  111. package/payload/server/public/assets/clock-C4Nu2aRV.js +1 -0
  112. package/payload/server/public/assets/clock-C4Nu2aRV.js.br +0 -0
  113. package/payload/server/public/assets/copy-3kj9Oaoc.js +1 -0
  114. package/payload/server/public/assets/copy-3kj9Oaoc.js.br +0 -0
  115. package/payload/server/public/assets/copy-3kj9Oaoc.js.gz +0 -0
  116. package/payload/server/public/assets/data-C-x5EHyi.js +1 -0
  117. package/payload/server/public/assets/data-C-x5EHyi.js.br +1 -0
  118. package/payload/server/public/assets/data-C-x5EHyi.js.gz +0 -0
  119. package/payload/server/public/assets/file-text-CBaewT76.js +1 -0
  120. package/payload/server/public/assets/file-text-CBaewT76.js.br +0 -0
  121. package/payload/server/public/assets/file-text-CBaewT76.js.gz +0 -0
  122. package/payload/server/public/assets/{graph-C8cQ6Nqf.js → graph-B8-e2_Z-.js} +3 -3
  123. package/payload/server/public/assets/graph-B8-e2_Z-.js.br +0 -0
  124. package/payload/server/public/assets/graph-B8-e2_Z-.js.gz +0 -0
  125. package/payload/server/public/assets/graph-labels-Bsc23eZU.js +1 -0
  126. package/payload/server/public/assets/graph-labels-Bsc23eZU.js.br +0 -0
  127. package/payload/server/public/assets/graph-labels-Bsc23eZU.js.gz +0 -0
  128. package/payload/server/public/assets/operator-Cve0-qfO.js +1 -0
  129. package/payload/server/public/assets/operator-Cve0-qfO.js.br +0 -0
  130. package/payload/server/public/assets/operator-Cve0-qfO.js.gz +0 -0
  131. package/payload/server/public/assets/page-BgVMs6Vf.js +1 -0
  132. package/payload/server/public/assets/page-BgVMs6Vf.js.br +0 -0
  133. package/payload/server/public/assets/page-BgVMs6Vf.js.gz +0 -0
  134. package/payload/server/public/assets/page-fABub-w8.js +32 -0
  135. package/payload/server/public/assets/page-fABub-w8.js.br +0 -0
  136. package/payload/server/public/assets/page-fABub-w8.js.gz +0 -0
  137. package/payload/server/public/assets/play-B6zXB9K7.js +1 -0
  138. package/payload/server/public/assets/play-B6zXB9K7.js.br +0 -0
  139. package/payload/server/public/assets/play-B6zXB9K7.js.gz +0 -0
  140. package/payload/server/public/assets/public--R2DbdWs.js +1 -0
  141. package/payload/server/public/assets/public--R2DbdWs.js.br +0 -0
  142. package/payload/server/public/assets/public--R2DbdWs.js.gz +0 -0
  143. package/payload/server/public/assets/rotate-ccw-FZW7c8p8.js +1 -0
  144. package/payload/server/public/assets/rotate-ccw-FZW7c8p8.js.br +0 -0
  145. package/payload/server/public/assets/rotate-ccw-FZW7c8p8.js.gz +0 -0
  146. package/payload/server/public/assets/routines-BpZs2SaT.js +2 -0
  147. package/payload/server/public/assets/routines-BpZs2SaT.js.br +0 -0
  148. package/payload/server/public/assets/routines-BpZs2SaT.js.gz +0 -0
  149. package/payload/server/public/assets/skills-DF7uyEEz.js +1 -0
  150. package/payload/server/public/assets/skills-DF7uyEEz.js.br +0 -0
  151. package/payload/server/public/assets/skills-DF7uyEEz.js.gz +0 -0
  152. package/payload/server/public/assets/tasks-BfJJmoWO.js +3 -0
  153. package/payload/server/public/assets/tasks-BfJJmoWO.js.br +0 -0
  154. package/payload/server/public/assets/tasks-BfJJmoWO.js.gz +0 -0
  155. package/payload/server/public/assets/triangle-alert-CR-jRJdI.js +1 -0
  156. package/payload/server/public/assets/triangle-alert-CR-jRJdI.js.br +0 -0
  157. package/payload/server/public/assets/triangle-alert-CR-jRJdI.js.gz +0 -0
  158. package/payload/server/public/assets/useCopyFeedback-IOuPUAHY.js +1 -0
  159. package/payload/server/public/assets/useCopyFeedback-IOuPUAHY.js.br +0 -0
  160. package/payload/server/public/assets/useCopyFeedback-IOuPUAHY.js.gz +0 -0
  161. package/payload/server/public/assets/{useSubAccountSwitcher-C7TtIbR3.js → useMediaQuery-CA6dR5iz.js} +1 -1
  162. package/payload/server/public/assets/useMediaQuery-CA6dR5iz.js.br +0 -0
  163. package/payload/server/public/assets/{useSubAccountSwitcher-C7TtIbR3.js.gz → useMediaQuery-CA6dR5iz.js.gz} +0 -0
  164. package/payload/server/public/assets/{useSubAccountSwitcher-DCkivCBS.css → useMediaQuery-DpwgV1Da.css} +1 -1
  165. package/payload/server/public/assets/useMediaQuery-DpwgV1Da.css.br +0 -0
  166. package/payload/server/public/assets/{useSubAccountSwitcher-DCkivCBS.css.gz → useMediaQuery-DpwgV1Da.css.gz} +0 -0
  167. package/payload/server/public/assets/useVoiceRecorder-DGhsN7nV.js +2 -0
  168. package/payload/server/public/assets/useVoiceRecorder-DGhsN7nV.js.br +0 -0
  169. package/payload/server/public/assets/useVoiceRecorder-DGhsN7nV.js.gz +0 -0
  170. package/payload/server/public/assets/wrench-CpCOYUBc.js +1 -0
  171. package/payload/server/public/assets/wrench-CpCOYUBc.js.br +0 -0
  172. package/payload/server/public/assets/wrench-CpCOYUBc.js.gz +0 -0
  173. package/payload/server/public/browser.html +4 -4
  174. package/payload/server/public/calendar.html +8 -8
  175. package/payload/server/public/chat.html +13 -13
  176. package/payload/server/public/data.html +11 -11
  177. package/payload/server/public/graph.html +9 -9
  178. package/payload/server/public/index.html +14 -14
  179. package/payload/server/public/operator.html +14 -14
  180. package/payload/server/public/public.html +13 -13
  181. package/payload/server/public/routines.html +6 -6
  182. package/payload/server/public/skills.html +5 -5
  183. package/payload/server/public/tasks.html +6 -6
  184. package/payload/server/server.js +329 -104
  185. package/payload/server/public/assets/AdminLoginScreens-BpHnjHp_.js +0 -1
  186. package/payload/server/public/assets/AdminLoginScreens-BpHnjHp_.js.br +0 -0
  187. package/payload/server/public/assets/AdminLoginScreens-BpHnjHp_.js.gz +0 -0
  188. package/payload/server/public/assets/AdminShell-D24evn4t.js +0 -2
  189. package/payload/server/public/assets/AdminShell-D24evn4t.js.br +0 -0
  190. package/payload/server/public/assets/AdminShell-D24evn4t.js.gz +0 -0
  191. package/payload/server/public/assets/activity-ZVUTB5uZ.js +0 -1
  192. package/payload/server/public/assets/activity-ZVUTB5uZ.js.br +0 -0
  193. package/payload/server/public/assets/activity-ZVUTB5uZ.js.gz +0 -0
  194. package/payload/server/public/assets/admin-XJqQz3QJ.js +0 -1
  195. package/payload/server/public/assets/admin-XJqQz3QJ.js.br +0 -0
  196. package/payload/server/public/assets/admin-XJqQz3QJ.js.gz +0 -0
  197. package/payload/server/public/assets/agents-Dc9SNC9N.js +0 -1
  198. package/payload/server/public/assets/agents-Dc9SNC9N.js.br +0 -0
  199. package/payload/server/public/assets/agents-Dc9SNC9N.js.gz +0 -0
  200. package/payload/server/public/assets/browser-CCedMIga.js +0 -1
  201. package/payload/server/public/assets/browser-CCedMIga.js.br +0 -0
  202. package/payload/server/public/assets/browser-CCedMIga.js.gz +0 -0
  203. package/payload/server/public/assets/calendar-BDoMLP2j.js +0 -1
  204. package/payload/server/public/assets/calendar-BDoMLP2j.js.br +0 -0
  205. package/payload/server/public/assets/calendar-BDoMLP2j.js.gz +0 -0
  206. package/payload/server/public/assets/chat-BAhoqTY9.js +0 -1
  207. package/payload/server/public/assets/chat-BAhoqTY9.js.br +0 -0
  208. package/payload/server/public/assets/chat-BAhoqTY9.js.gz +0 -0
  209. package/payload/server/public/assets/chevron-left-NGLHgPjF.js +0 -1
  210. package/payload/server/public/assets/chevron-right-B4B7OkG8.js +0 -1
  211. package/payload/server/public/assets/chevron-right-B4B7OkG8.js.br +0 -0
  212. package/payload/server/public/assets/clock-7IMwxJdH.js +0 -1
  213. package/payload/server/public/assets/clock-7IMwxJdH.js.br +0 -0
  214. package/payload/server/public/assets/clock-7IMwxJdH.js.gz +0 -0
  215. package/payload/server/public/assets/copy-PkR4EFD6.js +0 -1
  216. package/payload/server/public/assets/copy-PkR4EFD6.js.br +0 -0
  217. package/payload/server/public/assets/copy-PkR4EFD6.js.gz +0 -0
  218. package/payload/server/public/assets/data-yQYhw2IR.js +0 -1
  219. package/payload/server/public/assets/data-yQYhw2IR.js.br +0 -1
  220. package/payload/server/public/assets/data-yQYhw2IR.js.gz +0 -0
  221. package/payload/server/public/assets/file-text-BA9p7TLU.js +0 -1
  222. package/payload/server/public/assets/file-text-BA9p7TLU.js.br +0 -0
  223. package/payload/server/public/assets/file-text-BA9p7TLU.js.gz +0 -0
  224. package/payload/server/public/assets/graph-C8cQ6Nqf.js.br +0 -0
  225. package/payload/server/public/assets/graph-C8cQ6Nqf.js.gz +0 -0
  226. package/payload/server/public/assets/graph-labels-CiK412vE.js +0 -1
  227. package/payload/server/public/assets/graph-labels-CiK412vE.js.br +0 -0
  228. package/payload/server/public/assets/graph-labels-CiK412vE.js.gz +0 -0
  229. package/payload/server/public/assets/operator-CaQAEUBu.js +0 -1
  230. package/payload/server/public/assets/operator-CaQAEUBu.js.br +0 -0
  231. package/payload/server/public/assets/operator-CaQAEUBu.js.gz +0 -0
  232. package/payload/server/public/assets/page-CpJpyoPS.js +0 -32
  233. package/payload/server/public/assets/page-CpJpyoPS.js.br +0 -0
  234. package/payload/server/public/assets/page-CpJpyoPS.js.gz +0 -0
  235. package/payload/server/public/assets/page-D0ShNyGE.js +0 -1
  236. package/payload/server/public/assets/page-D0ShNyGE.js.br +0 -0
  237. package/payload/server/public/assets/page-D0ShNyGE.js.gz +0 -0
  238. package/payload/server/public/assets/play-huZpq9ra.js +0 -1
  239. package/payload/server/public/assets/play-huZpq9ra.js.br +0 -0
  240. package/payload/server/public/assets/play-huZpq9ra.js.gz +0 -0
  241. package/payload/server/public/assets/public--8RWWGjF.js +0 -1
  242. package/payload/server/public/assets/public--8RWWGjF.js.br +0 -0
  243. package/payload/server/public/assets/public--8RWWGjF.js.gz +0 -0
  244. package/payload/server/public/assets/rotate-ccw-g7l4ZSR3.js +0 -1
  245. package/payload/server/public/assets/rotate-ccw-g7l4ZSR3.js.br +0 -0
  246. package/payload/server/public/assets/rotate-ccw-g7l4ZSR3.js.gz +0 -0
  247. package/payload/server/public/assets/routines-DzFcPNMb.js +0 -2
  248. package/payload/server/public/assets/routines-DzFcPNMb.js.br +0 -0
  249. package/payload/server/public/assets/routines-DzFcPNMb.js.gz +0 -0
  250. package/payload/server/public/assets/skills-5vl_Bt9U.js +0 -1
  251. package/payload/server/public/assets/skills-5vl_Bt9U.js.br +0 -0
  252. package/payload/server/public/assets/skills-5vl_Bt9U.js.gz +0 -0
  253. package/payload/server/public/assets/tasks-DQHtJ8Pq.js +0 -3
  254. package/payload/server/public/assets/tasks-DQHtJ8Pq.js.br +0 -0
  255. package/payload/server/public/assets/tasks-DQHtJ8Pq.js.gz +0 -0
  256. package/payload/server/public/assets/triangle-alert-Cy4Z0uFv.js +0 -1
  257. package/payload/server/public/assets/triangle-alert-Cy4Z0uFv.js.br +0 -0
  258. package/payload/server/public/assets/triangle-alert-Cy4Z0uFv.js.gz +0 -0
  259. package/payload/server/public/assets/useCopyFeedback-BwK1RhmF.js +0 -1
  260. package/payload/server/public/assets/useCopyFeedback-BwK1RhmF.js.br +0 -0
  261. package/payload/server/public/assets/useCopyFeedback-BwK1RhmF.js.gz +0 -0
  262. package/payload/server/public/assets/useSubAccountSwitcher-C7TtIbR3.js.br +0 -0
  263. package/payload/server/public/assets/useSubAccountSwitcher-DCkivCBS.css.br +0 -0
  264. package/payload/server/public/assets/useVoiceRecorder-DgyAGgmF.js +0 -2
  265. package/payload/server/public/assets/useVoiceRecorder-DgyAGgmF.js.br +0 -0
  266. package/payload/server/public/assets/useVoiceRecorder-DgyAGgmF.js.gz +0 -0
  267. package/payload/server/public/assets/wrench-CICORrSc.js +0 -1
  268. package/payload/server/public/assets/wrench-CICORrSc.js.br +0 -0
  269. package/payload/server/public/assets/wrench-CICORrSc.js.gz +0 -0
@@ -1 +0,0 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{G as t,U as n,V as r,Z as i,_ as a,q as o}from"./useSubAccountSwitcher-C7TtIbR3.js";import{A as s}from"./useVoiceRecorder-DgyAGgmF.js";import{A as c,O as l,k as u,m as d}from"./AdminShell-D24evn4t.js";var f=e(i(),1);function p(e=`admin`){let[t,n]=(0,f.useState)(`loading`),[r,i]=(0,f.useState)(``),[a,l]=(0,f.useState)(``),[u,d]=(0,f.useState)(``),[p,m]=(0,f.useState)(!1),[h,g]=(0,f.useState)(!1),[_,v]=(0,f.useState)(!1),[y,b]=(0,f.useState)(!1),[x,S]=(0,f.useState)(!1),[C,w]=(0,f.useState)(null),[T,E]=(0,f.useState)(null),[D,O]=(0,f.useState)(void 0),[k,A]=(0,f.useState)(null),[j,M]=(0,f.useState)(void 0),[N,P]=(0,f.useState)(null),[F,I]=(0,f.useState)(null),[L,R]=(0,f.useState)(void 0),z=(0,f.useRef)(void 0),[B,V]=(0,f.useState)(!1),[H,U]=(0,f.useState)(!0);(0,f.useEffect)(()=>{typeof window>`u`||fetch(`/api/remote-auth/status`).then(e=>e.ok?e.json():null).then(e=>{e?.configured&&V(!0)}).catch(()=>{})},[]);let W=(0,f.useRef)(null),G=(0,f.useRef)(null);(0,f.useEffect)(()=>{async function e(){let e=null;try{e=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!e)return!1;try{let t=await fetch(`/api/admin/session?session_key=${encodeURIComponent(e)}`);if(t.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}return!1}if(!t.ok)return!1;let r=await t.json();w(r.session_key),I(r.sessionId??null),O(r.businessName),A(r.role??null),M(r.userName===void 0?null:r.userName),P(r.avatar??null);let i=s(r.thinkingView);return z.current=i,R(i),n(`chat`),!0}catch(e){return console.error(`[admin] session restore failed:`,e),!1}}async function t(r=2){try{let i=await fetch(`/api/health`);if(!i.ok){if(r>0)return await new Promise(e=>setTimeout(e,1500)),t(r-1);console.error(`[admin] health check returned ${i.status} after retries`),n(`set-pin`);return}let a=await i.json();if(!a.pin_configured){n(`set-pin`);return}U(!!a.claude_authenticated);let o=!1;try{o=new URLSearchParams(window.location.search).get(`connect`)===`claude`}catch{}if(o){try{let e=new URL(window.location.href);e.searchParams.delete(`connect`),window.history.replaceState(null,``,e.pathname+e.search+e.hash)}catch{}if(!a.claude_authenticated){n(`connect-claude`);return}}if(await e())return;n(`enter-pin`)}catch(e){if(r>0)return await new Promise(e=>setTimeout(e,1500)),t(r-1);console.error(`[admin] health check failed:`,e),n(`set-pin`)}}t()},[]),(0,f.useEffect)(()=>{t===`chat`&&C&&fetch(`/api/admin/claude-info?session_key=${encodeURIComponent(C)}`).then(e=>{if(e.ok)return e.json()}).then(e=>{e&&E(e)}).catch(()=>{})},[t,C]);let K=(0,f.useRef)(null);(0,f.useEffect)(()=>{if(t!==`chat`)return;let e=setInterval(async()=>{try{let e=await fetch(`/api/health`);if(e.ok){let t=await e.json();U(t.auth_status!==`dead`&&t.auth_status!==`missing`)}}catch{}if(C)try{let e=await fetch(`/api/admin/session?session_key=${encodeURIComponent(C)}`);if(e.status!==401)return;let t=(await e.clone().json().catch(()=>null))?.code??`unknown-401`;if(t===`remote-auth-required`){o(`heartbeat`,`/api/admin/session`);return}console.warn(`[admin-auth] outcome=heartbeat-detected-expiry code=${t}`),K.current?.()}catch{}},300*1e3);return()=>clearInterval(e)},[t,C]),(0,f.useEffect)(()=>{t===`connect-claude`&&fetch(`/api/health`).then(e=>e.ok?e.json():null).then(e=>{e?.claude_authenticated&&(U(!0),n(`enter-pin`))}).catch(()=>{})},[t]);async function q(e,t){g(!0);try{let r=await fetch(`/api/admin/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:e,...t?{accountId:t}:{}})});if(!r.ok){let e=await r.json().catch(()=>({}));if(r.status===401&&e?.code===`remote-auth-required`){o(`enter-pin`,`/api/admin/session`);return}d(e.error||`Invalid PIN`);return}let a=await r.json();w(a.session_key),I(a.sessionId??null),O(a.businessName),A(a.role??null),M(a.userName===void 0?null:a.userName),P(a.avatar??null);let c=s(a.thinkingView);z.current=c,R(c);try{sessionStorage.setItem(`maxy-admin-session-key`,a.session_key)}catch{}i(``),n(`chat`)}catch(e){console.error(`[admin] connection error:`,e),d(`Could not connect.`)}finally{g(!1)}}let J=(0,f.useCallback)(async e=>{if(e.preventDefault(),h)return;d(``);let t=a.trim();if(!t){d(`Please enter your name.`);return}if(r.length<4){d(`PIN must be at least 4 characters.`);return}let s=r;g(!0);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:s,name:t})});if(!e.ok){let t=await e.json().catch(()=>({}));if(e.status===401&&t?.code===`remote-auth-required`){o(`set-pin`,`/api/onboarding/set-pin`);return}if(e.status===409){try{let e=await fetch(`/api/health`);if(e.ok){let r=await e.json();r.pin_configured&&r.claude_authenticated?n(`enter-pin`):r.pin_configured?n(`connect-claude`):d(t.error||`Failed to set PIN.`)}else n(`enter-pin`)}catch{n(`enter-pin`)}return}d(t.error||`Failed to set PIN.`);return}let r=await fetch(`/api/health`);if((r.ok?await r.json():null)?.claude_authenticated){await q(s);return}i(``),n(`connect-claude`)}catch(e){console.error(`[admin] connection error:`,e),d(`Could not connect.`)}finally{g(!1)}},[r,h,a]),Y=(0,f.useCallback)(async e=>{e.preventDefault(),d(``),await q(r)},[r]),X=(0,f.useCallback)(async()=>{S(!0);try{if(!await c())return console.warn(`[admin-ui] claude-disconnect not verified — credentials may persist; staying put`),!1;U(!1),w(null),A(null),M(void 0),P(null);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}return n(`connect-claude`),!0}finally{S(!1)}},[]),Z=(0,f.useCallback)(()=>{w(null),A(null),M(void 0),P(null);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}i(``),d(``),n(`enter-pin`)},[]);return(0,f.useEffect)(()=>{K.current=Z},[Z]),{appState:t,setAppState:n,pin:r,setPin:i,operatorName:a,setOperatorName:l,pinError:u,setPinError:d,showPin:p,setShowPin:m,pinLoading:h,authPolling:_,setAuthPolling:v,authLoading:y,setAuthLoading:b,disconnecting:x,cacheKey:C,setCacheKey:w,claudeInfo:T,setClaudeInfo:E,businessName:D,role:k,userName:j,userAvatar:N,sessionId:F,setSessionId:I,expandAll:L,setExpandAll:R,expandAllDefaultRef:z,remoteAuthEnabled:B,claudeConnected:H,pinInputRef:W,setPinFormRef:G,handleSetPin:J,handleLogin:Y,handleDisconnect:X,handleLogout:Z}}var m=t();function h({inputRef:e,value:t,onChange:n,onComplete:r,showPin:i,autoFocus:a}){let o=(0,f.useRef)([]);function s(e,r){r.key===`Backspace`?(r.preventDefault(),t[e]?n(t.slice(0,e)+t.slice(e+1)):e>0&&(n(t.slice(0,e-1)+t.slice(e)),o.current[e-1]?.focus())):r.key===`ArrowLeft`&&e>0?o.current[e-1]?.focus():r.key===`ArrowRight`&&e<5?o.current[e+1]?.focus():r.key===`Enter`&&(r.preventDefault(),r.currentTarget.form?.requestSubmit())}function c(e,i){let a=i.nativeEvent.data;if(!a||!/^\d$/.test(a))return;let s=t.split(``);for(s[e]=a;s.length<e;)s.push(``);let c=s.join(``).replace(/\D/g,``).slice(0,6);n(c),c.length===6?r?.(c):e<5&&o.current[e+1]?.focus()}function l(e){e.preventDefault();let t=e.clipboardData.getData(`text`).replace(/\D/g,``).slice(0,6);t&&(n(t),t.length===6?r?.(t):o.current[t.length]?.focus())}return(0,m.jsx)(`div`,{className:`pin-field`,children:Array.from({length:6}).map((n,r)=>(0,m.jsx)(`input`,{ref:t=>{o.current[r]=t,r===0&&e&&(e.current=t)},type:`text`,inputMode:`numeric`,className:`pin-box${t[r]?` pin-box-filled`:``}`,value:t[r]?i?t[r]:`•`:``,onKeyDown:e=>s(r,e),onInput:e=>c(r,e),onPaste:l,onFocus:e=>e.target.select(),autoFocus:a&&r===0,autoComplete:`off`,maxLength:1,"aria-label":`PIN digit ${r+1}`},r))})}function g(e){let{pin:t,setPin:i,showPin:a,setShowPin:o,pinLoading:s,pinError:c,pinInputRef:d,setPinFormRef:f,onSubmit:p,operatorName:g,setOperatorName:_}=e;return(0,m.jsx)(`div`,{className:`connect-page`,children:(0,m.jsxs)(`div`,{className:`connect-content`,children:[(0,m.jsx)(`img`,{src:n,alt:r.productName,className:`connect-logo connect-logo--maxy`}),!r.logoContainsName&&(0,m.jsxs)(`h1`,{className:`connect-title`,children:[`Welcome to `,r.productName]}),(0,m.jsxs)(`p`,{className:`connect-subtitle`,children:[`Tell `,r.productName,` who you are, then choose a PIN.`]}),(0,m.jsxs)(`form`,{ref:f,onSubmit:p,className:`connect-pin-form`,children:[(0,m.jsxs)(`div`,{className:`pin-input-row`,children:[(0,m.jsx)(`input`,{type:`text`,className:`connect-name-input`,placeholder:`Your full name`,value:g,onChange:e=>_(e.target.value),autoComplete:`name`,autoFocus:!0,required:!0,"aria-label":`Your full name`}),(0,m.jsx)(`div`,{style:{width:38,flexShrink:0},"aria-hidden":`true`})]}),(0,m.jsxs)(`div`,{className:`pin-input-row`,children:[(0,m.jsx)(h,{inputRef:d,value:t,onChange:i,onComplete:()=>{},showPin:a}),(0,m.jsx)(l,{variant:`send`,type:`submit`,disabled:!t||!g.trim(),loading:s,"aria-label":`Set PIN`,children:(0,m.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,m.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,m.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,m.jsx)(u,{checked:a,onChange:()=>o(e=>!e),label:`Show PIN`})]}),c&&(0,m.jsx)(`p`,{className:`admin-pin-error`,children:c})]})})}function _(e){let{pin:t,setPin:i,showPin:a,setShowPin:o,pinLoading:s,pinError:c,pinInputRef:d,onSubmit:f,remoteAuthEnabled:p,onSignOutRemote:g}=e;return(0,m.jsxs)(`div`,{className:`connect-page`,children:[p&&g&&(0,m.jsx)(`button`,{type:`button`,className:`connect-signout`,onClick:g,children:`Sign out`}),(0,m.jsxs)(`div`,{className:`connect-content`,children:[(0,m.jsx)(`img`,{src:n,alt:r.productName,className:`connect-logo connect-logo--maxy`}),!r.logoContainsName&&(0,m.jsx)(`h1`,{className:`connect-title`,children:r.productName}),(0,m.jsxs)(`form`,{onSubmit:f,className:`connect-pin-form`,children:[(0,m.jsxs)(`div`,{className:`pin-input-row`,children:[(0,m.jsx)(h,{inputRef:d,value:t,onChange:i,onComplete:()=>{},showPin:a,autoFocus:!0}),(0,m.jsx)(l,{variant:`send`,type:`submit`,disabled:!t,loading:s,children:(0,m.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,m.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,m.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,m.jsx)(`div`,{className:`pin-options`,children:(0,m.jsx)(u,{checked:a,onChange:()=>o(e=>!e),label:`Show PIN`})})]}),c&&(0,m.jsx)(`p`,{className:`admin-pin-error`,children:c})]})]})}function v(e){let{authPolling:t,setAuthPolling:i,authLoading:a,setAuthLoading:o,pinError:s,setPinError:c,setAppState:u}=e,[p,h]=(0,f.useState)(!1),[g,_]=(0,f.useState)(!1),[v,y]=(0,f.useState)(``),[b,x]=(0,f.useState)(``),[S,C]=(0,f.useState)(``),[w,T]=(0,f.useState)(null),[E,D]=(0,f.useState)(null),[O,k]=(0,f.useState)(!1);(0,f.useEffect)(()=>{try{D(sessionStorage.getItem(`maxy-admin-session-key`))}catch{}k(!0)},[]);async function A(){C(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`paste-code`,code:b})})).json();e.accepted?(C(`Code submitted. Finishing sign-in…`),x(``)):C(e.error||`Could not submit code.`)}catch(e){console.error(`[admin] paste-code error:`,e),C(`Could not submit code.`)}}async function j(){_(!0),c(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`launch-browser`})})).json();e.launched?h(!0):e.error&&c(e.error)}catch(e){console.error(`[admin] browser launch error:`,e),c(`Could not launch browser.`)}_(!1)}async function M(){o(!0),c(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`})).json();if(e.started){i(!0),h(!0),o(!1),y(e.transport||``);for(let e=0;e<120;e++){await new Promise(e=>setTimeout(e,2e3));let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`wait`})})).json();if(typeof e.authTargetId==`string`&&T(e.authTargetId),e.authenticated){await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),u(`enter-pin`);return}}c(`Timed out waiting for sign-in. Try again.`),i(!1)}else e.error&&c(e.error)}catch(e){console.error(`[admin] auth flow error:`,e),c(`Could not start auth flow.`)}o(!1)}async function N(){await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),i(!1),c(``)}return t||p?(0,m.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100dvh`,overflow:`auto`},children:[(0,m.jsxs)(`header`,{className:`chat-header`,style:{paddingBottom:`12px`,flexShrink:0,position:`relative`,maxWidth:`680px`,width:`100%`,margin:`0 auto`,padding:`24px 20px 12px`},children:[t?(0,m.jsx)(`button`,{onClick:N,style:{position:`absolute`,top:`12px`,right:`12px`,background:`none`,border:`none`,color:`#999`,fontSize:`13px`,cursor:`pointer`,padding:`4px 8px`},"aria-label":`Cancel`,children:`✕`}):(0,m.jsx)(`button`,{onClick:()=>h(!1),style:{position:`absolute`,top:`12px`,right:`12px`,background:`none`,border:`none`,color:`#999`,fontSize:`13px`,cursor:`pointer`,padding:`4px 8px`},"aria-label":`Close browser`,children:`✕`}),(0,m.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`chat-logo`}),(0,m.jsx)(`h1`,{className:`chat-tagline`,children:`Connect Claude`}),(0,m.jsx)(`p`,{className:`chat-intro`,children:t?`Sign in and authorize in the browser below.`:`Open your email or prepare your accounts, then sign in.`}),!t&&(0,m.jsx)(`div`,{style:{marginTop:`12px`},children:(0,m.jsx)(l,{variant:`primary`,onClick:M,disabled:a,children:a?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`})}),t&&v===`native`&&(0,m.jsxs)(`div`,{style:{marginTop:`14px`,maxWidth:`420px`,margin:`14px auto 0`,display:`flex`,flexDirection:`column`,gap:`8px`},children:[(0,m.jsx)(`label`,{style:{fontSize:`12px`,color:`#999`,lineHeight:1.4},children:`If the browser didn't finish sign-in, paste the code or full redirect URL from Claude's page:`}),(0,m.jsxs)(`div`,{style:{display:`flex`,gap:`8px`},children:[(0,m.jsx)(`input`,{type:`text`,value:b,onChange:e=>x(e.target.value),placeholder:`Paste code or redirect URL`,style:{flex:1,padding:`8px 10px`,fontSize:`13px`,border:`1px solid #ccc`,borderRadius:`6px`}}),(0,m.jsx)(l,{variant:`primary`,onClick:A,disabled:!b.trim(),children:`Submit`})]}),S&&(0,m.jsx)(`p`,{style:{fontSize:`12px`,color:`#999`,margin:0},children:S})]})]}),(0,m.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,minHeight:0,gap:`10px`,padding:`0 0 16px`},children:O&&(0,m.jsx)(d,{preferTargetId:w,cacheKey:E,chrome:!1})}),s&&(0,m.jsx)(`p`,{className:`admin-pin-error`,style:{textAlign:`center`,padding:`0 20px 16px`},children:s})]}):(0,m.jsx)(`div`,{className:`connect-page`,children:(0,m.jsxs)(`div`,{className:`connect-content`,children:[(0,m.jsxs)(`div`,{className:`connect-logos`,children:[(0,m.jsx)(`div`,{className:`connect-logo-wrap`,children:(0,m.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`connect-logo`})}),(0,m.jsx)(`svg`,{className:`connect-arrow`,viewBox:`0 0 48 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,m.jsx)(`path`,{d:`M0 12h44m0 0l-8-8m8 8l-8 8`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}),(0,m.jsxs)(`div`,{className:`connect-logo-wrap`,children:[(0,m.jsx)(`img`,{src:n,alt:r.productName,className:`connect-logo connect-logo--maxy`}),!r.logoContainsName&&(0,m.jsx)(`span`,{className:`connect-logo-label`,children:r.productName})]})]}),(0,m.jsxs)(`h1`,{className:`connect-title`,children:[`Connect Claude to power `,r.productName]}),(0,m.jsx)(`p`,{className:`connect-subtitle`,children:`Sign in with your Anthropic account to get started.`}),(0,m.jsx)(l,{variant:`primary`,onClick:M,disabled:a,children:a?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`}),(0,m.jsx)(`p`,{style:{marginTop:`6px`,fontSize:`11px`,color:`#999`,maxWidth:`300px`,textAlign:`center`,lineHeight:`1.4`},children:`First time? You may need to sign into your email and Anthropic account in the browser before connecting.`}),(0,m.jsx)(`button`,{onClick:j,disabled:g,style:{marginTop:`12px`,background:`none`,border:`none`,color:`var(--color-primary, #666)`,fontSize:`13px`,cursor:`pointer`,textDecoration:`underline`,textUnderlineOffset:`3px`},children:g?`Launching…`:`Open browser first`}),s&&(0,m.jsx)(`p`,{className:`admin-pin-error`,children:s})]})})}function y({auth:e}){return e.appState===`loading`?(0,m.jsx)(a,{surface:`gate`}):e.appState===`set-pin`?(0,m.jsx)(g,{pin:e.pin,setPin:e.setPin,showPin:e.showPin,setShowPin:e.setShowPin,pinLoading:e.pinLoading,pinError:e.pinError,pinInputRef:e.pinInputRef,setPinFormRef:e.setPinFormRef,onSubmit:e.handleSetPin,operatorName:e.operatorName,setOperatorName:e.setOperatorName}):e.appState===`connect-claude`?(0,m.jsx)(v,{authPolling:e.authPolling,setAuthPolling:e.setAuthPolling,authLoading:e.authLoading,setAuthLoading:e.setAuthLoading,pinError:e.pinError,setPinError:e.setPinError,setAppState:e.setAppState}):e.appState===`enter-pin`?(0,m.jsx)(_,{pin:e.pin,setPin:e.setPin,showPin:e.showPin,setShowPin:e.setShowPin,pinLoading:e.pinLoading,pinError:e.pinError,pinInputRef:e.pinInputRef,onSubmit:e.handleLogin,remoteAuthEnabled:e.remoteAuthEnabled,onSignOutRemote:()=>{window.location.href=`/__remote-auth/logout`}}):null}export{p as n,y as t};
@@ -1,2 +0,0 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{A as t,B as n,D as r,E as i,F as a,G as o,H as s,K as c,L as l,M as u,N as d,O as f,P as p,R as m,S as h,T as g,V as _,W as v,X as y,Z as b,_ as ee,b as x,g as S,h as C,i as w,j as T,k as te,m as ne,o as E,p as D,r as O,s as re,t as ie,w as ae,x as oe,y as se,z as ce}from"./useSubAccountSwitcher-C7TtIbR3.js";async function k(){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 A=o();function le({checked:e,onChange:t,label:n,disabled:r,ariaLabel:i=n}){return(0,A.jsxs)(`label`,{className:`maxy-checkbox${r?` maxy-checkbox--disabled`:``}`,children:[(0,A.jsx)(`input`,{type:`checkbox`,"aria-label":i,checked:e,onChange:e=>t(e.target.checked),disabled:r}),(0,A.jsx)(`span`,{className:`maxy-checkbox__box`,children:`✱`}),n&&(0,A.jsx)(`span`,{className:`maxy-checkbox__label`,children:n})]})}var j=e(b(),1),ue={sm:14,md:16,lg:18},de={sm:30,md:38,lg:46};function M({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=ue[t],g={...e===`send`?{width:de[t],height:de[t]}:{},...d},_=Object.keys(g).length>0;return(0,A.jsxs)(`button`,{type:s,className:m,disabled:i||o,onClick:c,"aria-label":l,"aria-pressed":u,style:_?g:void 0,children:[(0,A.jsxs)(`span`,{className:`btn__content`,style:{visibility:i?`hidden`:`visible`},children:[n&&r===`leading`&&(0,A.jsx)(n,{size:h}),p,n&&r===`trailing`&&(0,A.jsx)(n,{size:h})]}),i&&(0,A.jsx)(`span`,{className:`btn__spinner`,children:`✱`})]})}var N=n(`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`}]]),fe=n(`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`}]]),pe=n(`arrow-right`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`m12 5 7 7-7 7`,key:`xquz4c`}]]),me=n(`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`}]]),he=n(`chevron-down`,[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]),P=n(`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`}]]),ge=n(`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`}]]),_e=n(`gauge`,[[`path`,{d:`m12 14 4-4`,key:`9kzdfg`}],[`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`,key:`19p75a`}]]),ve=n(`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`}]]),ye=n(`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`}]]),be=n(`minimize-2`,[[`path`,{d:`m14 10 7-7`,key:`oa77jy`}],[`path`,{d:`M20 10h-6V4`,key:`mjg0md`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M4 14h6v6`,key:`rmj7iw`}]]),F=n(`panel-left`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}]]),xe=n(`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=n(`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=n(`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=n(`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=`/cdp-screencast`;function Ee(e){return{format:`jpeg`,quality:60,maxWidth:e?Math.max(320,Math.round(e.width)):1280,maxHeight:e?Math.max(320,Math.round(e.height)):800,everyNthFrame:1}}function I(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 De(e){return e===0?`left`:e===1?`middle`:e===2?`right`:`none`}function Oe(e,t){let n=De(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 ke(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 Ae={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},je={Enter:`\r`,Tab:` `};function Me(e,t){let n=t.key.length===1,r=n&&/[a-z0-9]/i.test(t.key)?t.key.toUpperCase().charCodeAt(0):Ae[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:je[t.key];e!==void 0&&(i.text=e,i.unmodifiedText=e)}return i}function Ne(e){let t=e.trim();return t?/^[a-z][a-z0-9+.-]*:/i.test(t)?t:`https://${t}`:``}function Pe(e){try{return new URL(Ne(e)).host}catch{return``}}function Fe(e,t,n){return`${e.protocol===`https:`?`wss`:`ws`}://${e.host}${Te}?targetId=${encodeURIComponent(t)}&sid=${encodeURIComponent(n)}`}var Ie=class{nextId=1;startId=null;frames=0;stopped=!1;lastMetadata=null;lastInputLogAtMs=null;inputsSinceLog=0;pending=new Map;constructor(e,t){this.ws=e,this.opts=t}frameCount(){return this.frames}start(e){this.send(`Page.enable`,{}),e&&this.setPaneSize(e);let t=Ee(e);this.startId=this.send(`Page.startScreencast`,t)}setPaneSize(e){let t=Math.max(1,Math.round(e.width)),n=Math.max(1,Math.round(e.height));this.send(`Emulation.setDeviceMetricsOverride`,{width:t,height:n,deviceScaleFactor:0,mobile:!1})}stop(){if(this.stopped)return;this.stopped=!0;let e=this.send(`Page.stopScreencast`,{})!==null;this.send(`Emulation.clearDeviceMetricsOverride`,{}),this.opts.onLog(`teardown`,{stopSent:e})}handleMessage(e){let t;try{t=JSON.parse(e)}catch{return}if(typeof t.id==`number`){let e=this.pending.get(t.id);if(e){this.pending.delete(t.id),e(t.error?null:t.result);return}}if(typeof t.id==`number`&&t.id===this.startId){if(t.error)this.opts.onLog(`start-failed`,{err:t.error.message??`unknown`});else{let e=Ee();this.opts.onLog(`screencast-started`,{format:e.format,everyNthFrame:e.everyNthFrame})}return}if(t.method===`Page.frameNavigated`){let e=t.params?.frame;e&&e.parentId===void 0&&typeof e.url==`string`&&this.opts.onUrlChange?.(e.url);return}if(t.method!==`Page.screencastFrame`||this.stopped)return;let n=t.params;if(typeof n?.data!=`string`||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=I(t.canvasX,t.canvasY,t.rendered,n);this.send(`Input.dispatchMouseEvent`,Oe(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=I(e.canvasX,e.canvasY,e.rendered,t);this.send(`Input.dispatchMouseEvent`,ke({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`,Me(e,t)),this.logInput(`key`)}insertText(e){e&&(this.send(`Input.insertText`,{text:e}),this.logInput(`paste`))}navigate(e){let t=Ne(e);t&&(this.send(`Page.navigate`,{url:t}),this.opts.onLog(`navigate`,{host:Pe(t)}))}async goHistory(e){let t=e<0?`back`:`forward`,n=await this.command(`Page.getNavigationHistory`,{});if(!n){this.opts.onLog(`history`,{dir:t,outcome:`no-result`});return}let{currentIndex:r,entries:i}=n,a=typeof r==`number`?i?.[r+e]:void 0;if(!a||typeof a.id!=`number`){this.opts.onLog(`history`,{dir:t,outcome:`no-entry`});return}this.send(`Page.navigateToHistoryEntry`,{entryId:a.id}),this.opts.onLog(`history`,{dir:t})}command(e,t){let n=this.send(e,t);return n===null?Promise.resolve(null):new Promise(e=>this.pending.set(n,e))}logInput(e){this.inputsSinceLog+=1;let t=(this.opts.now??Date.now)();if(this.lastInputLogAtMs!==null&&t-this.lastInputLogAtMs<1e3)return;this.lastInputLogAtMs=t;let n=this.inputsSinceLog;this.inputsSinceLog=0,this.opts.onLog(`input`,{kind:e,count:n})}send(e,t){let n=this.nextId++;try{return this.ws.send(JSON.stringify({id:n,method:e,params:t})),n}catch(t){return this.opts.onLog(`send-failed`,{method:e,err:t instanceof Error?t.message:String(t)}),null}}};function Le(e){let{targets:t,activeId:n,url:r,busy:i}=e,[a,o]=(0,j.useState)(r),s=(0,j.useRef)(null);return(0,j.useEffect)(()=>{s.current&&document.activeElement===s.current||o(r)},[r]),(0,j.useEffect)(()=>{o(e.url)},[n]),(0,A.jsxs)(`div`,{className:`browser-chrome`,children:[(0,A.jsxs)(`div`,{className:`browser-chrome__tabs`,role:`tablist`,children:[t.map(t=>(0,A.jsxs)(`div`,{className:t.id===n?`browser-chrome__tab is-active`:`browser-chrome__tab`,role:`tab`,"aria-selected":t.id===n,children:[(0,A.jsx)(`button`,{type:`button`,className:`browser-chrome__tab-label`,onClick:()=>e.onSelect(t.id),title:t.url,children:t.title}),(0,A.jsx)(`button`,{type:`button`,className:`browser-chrome__tab-close`,"aria-label":`Close ${t.title}`,onClick:()=>e.onClose(t.id),disabled:i,children:(0,A.jsx)(x,{size:12,strokeWidth:2})})]},t.id)),(0,A.jsx)(`button`,{type:`button`,className:`browser-chrome__new`,"aria-label":`New tab`,title:`New tab`,onClick:e.onNew,disabled:i,children:(0,A.jsx)(g,{size:14,strokeWidth:2})}),(e.onToggleFull||e.onClosePane)&&(0,A.jsxs)(`div`,{className:`browser-chrome__window`,children:[e.onToggleFull&&(0,A.jsx)(`button`,{type:`button`,className:`browser-chrome__nav`,"aria-label":e.isFull?`Exit full screen`:`Full screen`,title:e.isFull?`Exit full screen`:`Full screen`,onClick:e.onToggleFull,children:e.isFull?(0,A.jsx)(be,{size:15,strokeWidth:1.75}):(0,A.jsx)(te,{size:15,strokeWidth:1.75})}),e.onClosePane&&(0,A.jsx)(`button`,{type:`button`,className:`browser-chrome__nav`,"aria-label":`Close browser`,title:`Close browser`,onClick:e.onClosePane,children:(0,A.jsx)(x,{size:16,strokeWidth:1.75})})]})]}),(0,A.jsxs)(`form`,{className:`browser-chrome__bar`,onSubmit:t=>{t.preventDefault(),e.onNavigate(a)},children:[(0,A.jsx)(`button`,{type:`button`,className:`browser-chrome__nav`,"aria-label":`Back`,title:`Back`,onClick:e.onBack,children:(0,A.jsx)(m,{size:16,strokeWidth:1.75})}),(0,A.jsx)(`button`,{type:`button`,className:`browser-chrome__nav`,"aria-label":`Forward`,title:`Forward`,onClick:e.onForward,children:(0,A.jsx)(pe,{size:16,strokeWidth:1.75})}),(0,A.jsx)(`input`,{ref:s,className:`browser-chrome__url`,"aria-label":`Address`,placeholder:`Type a URL`,value:a,onChange:e=>o(e.target.value)})]})]})}function L(e){return(e.altKey?1:0)|(e.ctrlKey?2:0)|(e.metaKey?4:0)|(e.shiftKey?8:0)}function R({preferTargetId:e=null,cacheKey:n=null,chrome:r=!0,surface:i=`browser`,onToggleFull:a,onClosePane:o,isFull:s=!1}={}){let[c,l]=(0,j.useState)(`probing`),[d,f]=(0,j.useState)([]),[p,m]=(0,j.useState)(null),[h,g]=(0,j.useState)(!1),[_,v]=(0,j.useState)(null),[y,b]=(0,j.useState)(!1),[ee,x]=(0,j.useState)(``),S=se(n),C=(0,j.useRef)(null),w=(0,j.useRef)(null),T=(0,j.useRef)(null),te=(0,j.useRef)(``),ne=(0,j.useRef)(e);ne.current=e,te.current||=`sc-${Math.random().toString(36).slice(2,10)}`;let E=(0,j.useCallback)((e,t={})=>{S(`/api/admin/browser/screencast-event`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({sid:te.current,op:e,...t})}).catch(()=>{})},[S]),D=(0,j.useCallback)(async()=>{try{let e=await S(`/api/admin/browser/screencast-targets`);if(!e.ok){l(`unavailable`);return}let t=await e.json().catch(()=>({})),n=Array.isArray(t.targets)?t.targets:[];if(f(n),n.length===0){m(null),l(`no-tabs`);return}let r=ne.current;m(e=>r&&n.some(e=>e.id===r)?r:e&&n.some(t=>t.id===e)?e:n[0].id),l(`live`)}catch{l(`unavailable`)}},[S]);(0,j.useEffect)(()=>{E(`request`),D()},[D,E]),(0,j.useEffect)(()=>{r&&E(`chrome-mounted`,{surface:i,chrome:`v1`})},[r,i,E]),(0,j.useEffect)(()=>{x(d.find(e=>e.id===p)?.url??``)},[d,p]);let O=(0,j.useRef)(null);(0,j.useEffect)(()=>{if(e){if(d.some(t=>t.id===e)){m(e);return}O.current!==e&&(O.current=e,D())}},[e,d,D]);let re=(0,j.useCallback)(e=>{let t=C.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}`},[]),ie=(0,j.useCallback)(()=>{let e=w.current;if(!e)return;let t=e.getBoundingClientRect();if(!(t.width<1||t.height<1))return{width:t.width,height:t.height}},[]);(0,j.useEffect)(()=>{let e=w.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{let e=ie();e&&T.current?.setPaneSize(e)});return t.observe(e),()=>t.disconnect()},[c,ie]),(0,j.useEffect)(()=>{if(c!==`live`||!p)return;let e=Fe({protocol:window.location.protocol,host:window.location.host},p,te.current),t=new WebSocket(e),n=new Ie(t,{onFrame:re,onLog:E,onUrlChange:x});return T.current=n,t.addEventListener(`open`,()=>n.start(ie())),t.addEventListener(`message`,e=>{typeof e.data==`string`&&n.handleMessage(e.data)}),()=>{n.stop(),t.close(),T.current=null}},[c,p,re,E]);let ae=(0,j.useCallback)(e=>t=>{let n=C.current;if(!n)return;let r=n.getBoundingClientRect();T.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:L(t)})},[]);(0,j.useEffect)(()=>{let e=C.current;if(!e)return;let t=t=>{t.preventDefault();let n=e.getBoundingClientRect();T.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:L(t)})};return e.addEventListener(`wheel`,t,{passive:!1}),()=>e.removeEventListener(`wheel`,t)},[c]);let oe=(0,j.useCallback)(e=>t=>{t.preventDefault(),T.current?.dispatchKey(e,{key:t.key,code:t.code,modifiers:L(t)})},[]),ce=(0,j.useCallback)(e=>{e.preventDefault();let t=e.clipboardData.getData(`text`);t&&T.current?.insertText(t)},[]),k=(0,j.useCallback)(async()=>{g(!0),v(null);try{let e=await S(`/api/admin/browser/launch`,{method:`POST`});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error||`Launch failed (${e.status})`)}await D()}catch(e){v(e instanceof Error?e.message:String(e))}finally{g(!1)}},[S,D]),le=(0,j.useCallback)(async()=>{b(!0),v(null);try{c===`no-tabs`&&await S(`/api/admin/browser/launch`,{method:`POST`});let e=await S(`/api/admin/browser/tabs`,{method:`POST`});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error||`New tab failed (${e.status})`)}let t=await e.json().catch(()=>({}));await D(),t.id&&m(t.id)}catch(e){v(e instanceof Error?e.message:String(e))}finally{b(!1)}},[S,D,c]),ue=(0,j.useCallback)(async e=>{b(!0),v(null);try{let t=await S(`/api/admin/browser/tabs/${encodeURIComponent(e)}`,{method:`DELETE`});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error||`Close failed (${t.status})`)}await D()}catch(e){v(e instanceof Error?e.message:String(e))}finally{b(!1)}},[S,D]),de=(0,j.useCallback)(e=>{T.current?.navigate(e)},[]),M=(0,j.useCallback)(e=>{T.current?.goHistory(e)},[]);return c===`probing`?(0,A.jsx)(`div`,{className:`cdp-screencast`,children:(0,A.jsxs)(`div`,{className:`data-loading`,children:[(0,A.jsx)(t,{size:18,className:`spin`}),` Connecting to the device browser…`]})}):c===`unavailable`?(0,A.jsx)(`div`,{className:`cdp-screencast`,children:(0,A.jsxs)(`div`,{className:`cdp-screencast__unavailable`,children:[(0,A.jsx)(u,{size:28,strokeWidth:1.75}),(0,A.jsx)(`p`,{children:`The device browser is not reachable.`})]})}):(0,A.jsxs)(`div`,{className:`cdp-screencast`,children:[r&&(0,A.jsx)(Le,{targets:d,activeId:p,url:ee,busy:y,onSelect:m,onClose:ue,onNew:le,onBack:()=>M(-1),onForward:()=>M(1),onNavigate:de,onToggleFull:a,onClosePane:o,isFull:s}),_&&(0,A.jsx)(`div`,{className:`cdp-screencast__toolbar`,children:(0,A.jsx)(`span`,{className:`cdp-screencast__error`,children:_})}),c===`no-tabs`?(0,A.jsxs)(`div`,{className:`cdp-screencast__unavailable`,children:[(0,A.jsx)(u,{size:28,strokeWidth:1.75}),(0,A.jsx)(`p`,{children:`No open tabs on the device browser.`}),(0,A.jsxs)(`button`,{type:`button`,className:`cdp-screencast__btn`,onClick:k,disabled:h,children:[h?(0,A.jsx)(t,{size:14,className:`spin`}):(0,A.jsx)(u,{size:14}),` Launch browser`]})]}):(0,A.jsxs)(A.Fragment,{children:[!r&&(0,A.jsx)(`div`,{className:`cdp-screencast__tabs`,children:d.map(e=>(0,A.jsx)(`button`,{type:`button`,className:e.id===p?`cdp-screencast__tab is-active`:`cdp-screencast__tab`,onClick:()=>m(e.id),title:e.url,children:e.title},e.id))}),(0,A.jsx)(`div`,{className:`cdp-screencast__viewport`,ref:w,children:(0,A.jsx)(`canvas`,{ref:C,className:`cdp-screencast__canvas`,tabIndex:0,onMouseDown:ae(`mousePressed`),onMouseUp:ae(`mouseReleased`),onMouseMove:ae(`mouseMoved`),onKeyDown:oe(`keyDown`),onKeyUp:oe(`keyUp`),onPaste:ce})})]})]})}var Re=5e3,ze=1200;function Be(e){return Math.max(ze,Math.round(Re/(e<1?1:e)))}var Ve=500,z=new Set;function He(e,t,n){let r=n??(typeof globalThis.fetch==`function`?globalThis.fetch:void 0);if(z.has(e)||!r)return!1;if(z.size>=Ve){for(let e of z)if(z.delete(e),z.size<Ve)break}z.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 Ue({type:e}){return e===`admin`?(0,A.jsx)(`svg`,{className:`wa-notify-icon`,viewBox:`0 0 16 16`,"aria-hidden":`true`,children:(0,A.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,A.jsx)(`svg`,{className:`wa-notify-icon`,viewBox:`0 0 16 16`,"aria-hidden":`true`,children:(0,A.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,A.jsx)(`svg`,{className:`wa-notify-icon`,viewBox:`0 0 16 16`,"aria-hidden":`true`,children:(0,A.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,A.jsx)(`svg`,{className:`wa-notify-icon`,viewBox:`0 0 16 16`,"aria-hidden":`true`,children:(0,A.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 We({frames:e,onExpire:t}){let n=(0,j.useRef)(new Map),r=(0,j.useRef)(new Map);return(0,j.useEffect)(()=>{let i=Date.now(),a=Be(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),He(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,A.jsx)(`div`,{className:`wa-notify-host`,children:[...e].reverse().map(e=>(0,A.jsxs)(`div`,{className:`wa-notify-card`,role:`status`,children:[(0,A.jsxs)(`div`,{className:`wa-notify-head`,children:[(0,A.jsx)(`span`,{className:`wa-notify-pill wa-notify-pill-${e.senderType}`,children:(0,A.jsx)(Ue,{type:e.senderType})}),(0,A.jsx)(`span`,{className:`wa-notify-account`,children:e.accountName})]}),(0,A.jsx)(`div`,{className:`wa-notify-sender`,children:e.senderDisplay}),(0,A.jsxs)(`div`,{className:`wa-notify-body`,children:[e.body,e.truncated?`…`:``]})]},e.waMessageId))})}var Ge=`wa-notify`;function Ke({connected:e,onConnectClaude:t}){return e?(0,A.jsxs)(`span`,{className:`claude-status-pill`,"data-connected":`true`,title:`Claude is connected`,children:[(0,A.jsx)(`img`,{src:`/brand/claude.png`,alt:``,className:`claude-status-pill__mark`}),(0,A.jsx)(`span`,{className:`claude-status-pill__label`,children:`Connected`}),(0,A.jsx)(`span`,{className:`claude-status-pill__dot claude-status-pill__dot--live`,"aria-hidden":`true`})]}):(0,A.jsxs)(`button`,{type:`button`,className:`claude-status-pill claude-status-pill--action`,"data-connected":`false`,onClick:t,title:`Connect Claude`,children:[(0,A.jsx)(`img`,{src:`/brand/claude.png`,alt:``,className:`claude-status-pill__mark`}),(0,A.jsx)(`span`,{className:`claude-status-pill__label`,children:`Connect`}),(0,A.jsx)(`span`,{className:`claude-status-pill__dot claude-status-pill__dot--down`,"aria-hidden":`true`})]})}function qe(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 Je({title:e,sidebarOpen:t,onToggleSidebar:n,claudeConnected:r,onConnectClaude:i,onOpenBrowser:a}){let o=e??qe(typeof window<`u`?window.location.pathname:`/`),s=r!==void 0&&i!==void 0,c=a!==void 0;return(0,A.jsxs)(`header`,{className:`admin-page-header`,children:[(0,A.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,A.jsx)(F,{className:`admin-page-header__toggle-desktop`,size:18,strokeWidth:1.75}),(0,A.jsx)(f,{className:`admin-page-header__toggle-mobile`,size:22,strokeWidth:1.75})]}),(0,A.jsx)(`h1`,{className:`admin-page-header__title`,children:o}),(s||c)&&(0,A.jsxs)(`div`,{className:`admin-page-header__right`,children:[s&&(0,A.jsx)(Ke,{connected:r,onConnectClaude:i}),c&&(0,A.jsx)(`button`,{type:`button`,className:`admin-page-header__icon`,"aria-label":`Show browser`,title:`Show browser`,onClick:a,children:(0,A.jsx)(u,{size:18,strokeWidth:1.75})})]})]})}var Ye=[{label:`Home`,href:`/`,Icon:T,match:e=>e===`/`||e===``},{label:`Chat`,href:`/chat`,Icon:r,match:e=>e.startsWith(`/chat`)},{label:`Tasks`,href:`/tasks`,Icon:ve,match:e=>e.startsWith(`/tasks`)},{label:`Data`,href:`/data`,Icon:a,match:e=>e.startsWith(`/data`)},{label:`Calendar`,href:`/calendar`,Icon:l,match:e=>e.startsWith(`/calendar`)}],Xe=[{label:`Chat`,href:`/`,Icon:r,match:e=>e===`/`||e===``||e.startsWith(`/chat`)},{label:`Data`,href:`/data`,Icon:a,match:e=>e.startsWith(`/data`)}];function Ze(e){let t=Ye.find(t=>t.match(e));return t?t.href:`/`}function B({variant:e=`admin`,onOpenConversations:t}={}){let n=typeof window<`u`?window.location.pathname:`/`,i=e===`operator`?Xe:Ye,a=e===`operator`?Xe.find(e=>e.match(n))?.href??`/`:Ze(n),o=e=>{let t=e.href===a,{Icon:n}=e;return(0,A.jsxs)(`a`,{href:e.href,className:`bottom-tab${t?` is-active`:``}`,"aria-current":t?`page`:void 0,children:[(0,A.jsx)(n,{size:19,strokeWidth:1.75}),(0,A.jsx)(`span`,{className:`bottom-tab__label`,children:e.label})]},e.href)};return(0,A.jsxs)(`nav`,{className:`bottom-tab-bar`,"aria-label":`Primary`,children:[i.slice(0,1).map(o),e===`operator`&&t&&(0,A.jsxs)(`button`,{type:`button`,className:`bottom-tab`,onClick:t,children:[(0,A.jsx)(r,{size:19,strokeWidth:1.75}),(0,A.jsx)(`span`,{className:`bottom-tab__label`,children:`Conversations`})]}),i.slice(1).map(o)]})}var Qe=`maxy-shell-side-px`;function $e(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .artefact`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function et(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=Math.max(248,t-480-$e());return Math.min(Math.max(e,248),n)}function tt(){if(typeof window>`u`)return 264;try{let e=window.localStorage.getItem(Qe);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 et(t)}catch{}return 264}function nt({targetSelector:e=`.platform`}){let t=(0,j.useRef)(null),[n,r]=(0,j.useState)(()=>tt()),i=(0,j.useRef)(n);(0,j.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,j.useCallback)(()=>{r(e=>{let t=et(e);return t===e?e:t})},[]);(0,j.useEffect)(()=>{a(),window.addEventListener(`resize`,a);let t=document.querySelector(e),n=null;return t instanceof HTMLElement&&(n=new MutationObserver(a),n.observe(t,{attributes:!0,attributeFilter:[`data-artefact`,`class`]})),()=>{window.removeEventListener(`resize`,a),n?.disconnect()}},[a,e]);let o=e=>{e.preventDefault();let n=t.current;if(!n)return;n.setPointerCapture(e.pointerId),n.classList.add(`dragging`);let a=!1,o=e=>{a=!0,r(et(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(Qe,String(t))}catch{}};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{r(et(264));try{window.localStorage.removeItem(Qe)}catch{}};return(0,A.jsx)(`div`,{ref:t,className:`side-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize sidebar`,onPointerDown:o,onDoubleClick:s})}var rt=y();function V(e){return Math.max(14,e/2-386)}function it(e){return e.left===0&&e.top===0&&e.width===0&&e.height===0}var H={position:`fixed`,visibility:`hidden`};function U({anchorRef:e,onClose:t,className:n,role:r,ariaLabel:i,anchorId:a,children:o}){let s=(0,j.useRef)(null),[c,l]=(0,j.useState)(H),u=(0,j.useCallback)(()=>{let t=s.current;if(!t)return;let r=e.current,i=[n,a].filter(Boolean).join(`:`)||`unknown`,o=t.getBoundingClientRect(),c=window.innerWidth,u=window.innerHeight,d=o.width>0&&o.height>0,f=r?r.getBoundingClientRect():null,p=(e,t)=>console.error(`[anchored-popover] op=offscreen id=${i} left=${e} top=${t} w=${o.width} h=${o.height} viewport=${c},${u}`);if(!f){l({position:`fixed`,left:Math.max(4,c-o.width-V(c)),top:Math.max(4,u-o.height-14),visibility:`visible`});return}if(d&&it(f)){l(H),p(f.left,f.top);return}let m=f.right-o.width,h=c-o.width-4;m>h&&(m=h),m<4&&(m=4);let g=u-f.bottom-4,_=f.top-4,v=o.height+8<=g?!1:o.height+8<=_?!0:_>g,y=Math.max(0,v?_:g),b=v?Math.max(4,f.top-Math.min(o.height,y)):f.bottom;l({position:`fixed`,left:m,top:b,maxHeight:y,visibility:`visible`});let ee=Math.min(o.height,y);d&&(m+o.width<=0||m>=c||b+ee<=0||b>=u)&&p(m,b)},[e,a,n]);return(0,j.useLayoutEffect)(()=>{if(u(),typeof ResizeObserver>`u`)return;let e=new ResizeObserver(()=>u());return s.current&&e.observe(s.current),()=>e.disconnect()},[u]),(0,j.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,rt.createPortal)((0,A.jsx)(`div`,{ref:s,className:n,role:r,"aria-label":i,style:c,children:o}),document.body)}function at({actions:e,disabled:t,label:n=`Session actions`}){let[r,i]=(0,j.useState)(!1),[a,o]=(0,j.useState)(null),s=(0,j.useRef)(null),c=(0,j.useCallback)(()=>{i(!1),o(null)},[]);return(0,A.jsxs)(`div`,{className:`conv-actions`,children:[(0,A.jsx)(`button`,{ref:s,type:`button`,className:`conv-action conv-actions-overflow`,onClick:()=>i(e=>!e),disabled:t,"aria-haspopup":`menu`,"aria-expanded":r,"aria-label":n,title:n,children:(0,A.jsx)(f,{size:12})}),r&&(0,A.jsx)(U,{anchorRef:s,onClose:c,className:`conv-actions-menu`,role:`menu`,children:e.map(e=>e.panel?(0,A.jsxs)(`div`,{className:`conv-actions-menu-disclosure`,children:[(0,A.jsxs)(`button`,{type:`button`,role:`menuitem`,"aria-haspopup":`dialog`,"aria-expanded":a===e.key,title:e.title,disabled:t||e.disabled,onClick:()=>o(t=>t===e.key?null:e.key),children:[e.icon,(0,A.jsx)(`span`,{children:e.menuLabel})]}),a===e.key&&(0,A.jsx)(`div`,{className:`conv-actions-menu-panel`,children:e.panel()})]},e.key):(0,A.jsxs)(`button`,{type:`button`,role:`menuitem`,className:e.danger?`conv-action-danger`:void 0,"aria-busy":e.busy,title:e.title,disabled:t||e.disabled,onClick:t=>{e.onClick?.(t),c()},children:[e.icon,(0,A.jsx)(`span`,{children:e.menuLabel})]},e.key))})]})}var ot=`claude-opus-5[1m]`,W=`claude-sonnet-5`,G=`claude-haiku-4-5`,st={[ot]:`Opus 5 (1M context)`,[W]:`Sonnet 5`,[G]:`Haiku 4.5`};function ct(e){return st[e]??e}var lt=[ot,W,G];function K(e){return e.replace(/\[1m\]$/,``)}function ut(e){return lt.find(t=>K(t)===K(e))??e}var dt=[`default`,`acceptEdits`,`plan`,`auto`,`bypassPermissions`],ft=[`low`,`medium`,`high`,`xhigh`];[...dt],[...ft],[...ft];var q=[ot,W,G],pt={default:`Ask permissions`,acceptEdits:`Accept edits`,plan:`Plan mode`,auto:`Auto mode`,bypassPermissions:`Bypass permissions`},mt=dt.map(e=>({value:e,label:pt[e]??e})),J={low:`Low`,medium:`Medium`,high:`High`,xhigh:`Highest`},ht=ft.map(e=>({value:e,label:J[e]??e}));function gt(e){if(e){let t=q.find(t=>K(t)===K(e));if(t)return t}return ot}function _t({row:e,adminFetch:n,onError:r}){let[i,a]=(0,j.useState)(()=>gt(e.model)),[o,s]=(0,j.useState)(``),[c,l]=(0,j.useState)(``),[u,d]=(0,j.useState)(!1),f=(0,j.useRef)(!1);(0,j.useEffect)(()=>{a(gt(e.model))},[e.model]);let p=async()=>{if(!f.current){f.current=!0,d(!0);try{let t=await n(`/api/admin/session-reseat`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({fromSessionId:e.sessionId,model:i,...o?{permissionMode:o}:{},...c?{effort:c}:{}})});if(!t.ok){r(`Could not reset ${e.title} (status ${t.status})`),console.error(`[admin-ui] dashboard-reseat-failed sessionId=${e.sessionId} status=${t.status}`),f.current=!1,d(!1);return}let a=await t.json().catch(()=>({}));a.target?window.location.assign(a.target):(r(`Reset of ${e.title} returned no target`),f.current=!1,d(!1))}catch(t){r(`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)}`),f.current=!1,d(!1)}}};return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(`label`,{className:`reseat-field`,children:[(0,A.jsx)(`span`,{children:`Model`}),(0,A.jsx)(`select`,{"data-kind":`model`,value:i,disabled:u,onChange:e=>a(e.target.value),children:q.map(e=>(0,A.jsx)(`option`,{value:e,children:ct(e)},e))})]}),(0,A.jsxs)(`label`,{className:`reseat-field`,children:[(0,A.jsx)(`span`,{children:`Mode`}),(0,A.jsxs)(`select`,{"data-kind":`mode`,value:o,disabled:u,onChange:e=>s(e.target.value),children:[(0,A.jsx)(`option`,{value:``,children:`Keep current`}),mt.map(e=>(0,A.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,A.jsxs)(`label`,{className:`reseat-field`,children:[(0,A.jsx)(`span`,{children:`Effort`}),(0,A.jsxs)(`select`,{"data-kind":`effort`,value:c,disabled:u,onChange:e=>l(e.target.value),children:[(0,A.jsx)(`option`,{value:``,children:`Keep current`}),ht.map(e=>(0,A.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,A.jsx)(`button`,{type:`button`,className:`reseat-apply`,disabled:u,"aria-busy":u,onClick:()=>void p(),children:u?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(t,{size:12,className:`spin`,"aria-hidden":`true`}),`Resetting…`]}):`Reset`})]})}function vt(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 yt(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function bt({target:e,anchorEl:t,onConfirm:n,onCancel:r}){let i=(0,j.useRef)(null);return i.current=t,e?(0,A.jsxs)(U,{anchorRef:i,onClose:r,className:`conv-delete-confirm`,role:`alertdialog`,ariaLabel:`Confirm delete session`,children:[(0,A.jsxs)(`div`,{className:`claude-info-header`,children:[(0,A.jsx)(`span`,{children:`Delete this conversation?`}),(0,A.jsx)(`button`,{className:`claude-info-close`,onClick:r,"aria-label":`Close`,children:`✕`})]}),(0,A.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[(0,A.jsxs)(`div`,{className:`conv-delete-target`,children:[(0,A.jsx)(`span`,{className:`conv-delete-label`,title:e.title,children:e.title||`Untitled session`}),(0,A.jsx)(`code`,{className:`conv-delete-id`,title:e.sessionId,children:e.sessionId.slice(0,8)})]}),(0,A.jsx)(`div`,{style:{marginTop:`8px`},children:`This permanently removes the transcript. It is not moved to Archive and cannot be recovered.`}),e.live&&(0,A.jsx)(`div`,{style:{marginTop:`8px`},children:`This session is running; deleting stops it first.`})]}),(0,A.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,A.jsx)(M,{variant:`danger`,size:`sm`,style:{flex:1},onClick:n,children:`Delete`}),(0,A.jsx)(M,{variant:`secondary`,size:`sm`,style:{flex:1},onClick:r,children:`Cancel`})]})]}):null}function xt({target:e,anchorEl:t,onConfirm:n,onCancel:r}){let i=(0,j.useRef)(null);return i.current=t,e?(0,A.jsxs)(U,{anchorRef:i,onClose:r,className:`conv-delete-confirm`,role:`alertdialog`,ariaLabel:`Confirm delete task`,children:[(0,A.jsxs)(`div`,{className:`claude-info-header`,children:[(0,A.jsx)(`span`,{children:`Delete this task?`}),(0,A.jsx)(`button`,{className:`claude-info-close`,onClick:r,"aria-label":`Close`,children:`✕`})]}),(0,A.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[(0,A.jsxs)(`div`,{className:`conv-delete-target`,children:[(0,A.jsx)(`span`,{className:`conv-delete-label`,title:e.name,children:e.name}),(0,A.jsx)(`code`,{className:`conv-delete-id`,children:w(e.secondsLogged)})]}),(0,A.jsx)(`div`,{style:{marginTop:`8px`},children:`This permanently removes the task and every time record on it. It cannot be recovered.`})]}),(0,A.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,A.jsx)(M,{variant:`danger`,size:`sm`,style:{flex:1},onClick:n,children:`Delete`}),(0,A.jsx)(M,{variant:`secondary`,size:`sm`,style:{flex:1},onClick:r,children:`Cancel`})]})]}):null}function St({open:e,count:t,liveCount:n,onConfirm:r,onCancel:i}){if(!e)return null;let a=t===1?``:`s`;return(0,A.jsx)(`div`,{className:`claude-info-overlay`,onClick:i,children:(0,A.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Confirm delete sessions`,children:[(0,A.jsxs)(`div`,{className:`claude-info-header`,children:[(0,A.jsxs)(`span`,{children:[`Delete `,t,` conversation`,a,`?`]}),(0,A.jsx)(`button`,{className:`claude-info-close`,onClick:i,"aria-label":`Close`,children:`✕`})]}),(0,A.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,A.jsxs)(`div`,{style:{marginTop:`8px`},children:[n,` `,n===1?`is`:`are`,` running and will be stopped first.`]})]}),(0,A.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,A.jsxs)(M,{variant:`danger`,size:`sm`,style:{flex:1},onClick:r,children:[`Delete `,t]}),(0,A.jsx)(M,{variant:`secondary`,size:`sm`,style:{flex:1},onClick:i,children:`Cancel`})]})]})})}function Ct(e){return`New session: ${e.toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`})}`}function wt({open:e,pending:t,onConfirm:n,onCancel:r,now:i}){let[a,o]=(0,j.useState)(``),s=(0,j.useRef)(null),c=(0,j.useRef)(null),l=(0,j.useRef)(!1);if((0,j.useEffect)(()=>{if(!e){c.current=null,l.current=!1;return}if(c.current!==null)return;let t=Ct(i?i():new Date);c.current=t,o(t)},[e,i]),(0,j.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,A.jsx)(`div`,{className:`claude-info-overlay`,onClick:()=>p(`backdrop`),children:(0,A.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`dialog`,"aria-label":`Name this session`,children:[(0,A.jsxs)(`div`,{className:`claude-info-header`,children:[(0,A.jsx)(`span`,{children:`Name this session`}),(0,A.jsx)(`button`,{className:`claude-info-close`,onClick:()=>p(`cancel`),"aria-label":`Close`,disabled:t,children:`✕`})]}),(0,A.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`},children:[(0,A.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,A.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,A.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,A.jsx)(M,{variant:`primary`,size:`sm`,style:{flex:1},disabled:!d||t,onClick:f,children:t?`Starting…`:`Start session`}),(0,A.jsx)(M,{variant:`secondary`,size:`sm`,style:{flex:1},disabled:t,onClick:()=>p(`cancel`),children:`Cancel`})]})]})})}var Tt=`auth-refresh-failed`;function Et({error:e,onClose:t}){if(!e)return null;let n=e.reason===Tt,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,A.jsx)(`div`,{className:`claude-info-overlay`,onClick:t,children:(0,A.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Session could not be opened`,children:[(0,A.jsxs)(`div`,{className:`claude-info-header`,children:[(0,A.jsx)(`span`,{children:r}),(0,A.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:`✕`})]}),(0,A.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[i,(0,A.jsxs)(`div`,{className:`claude-info-row`,style:{marginTop:`8px`},children:[(0,A.jsx)(`span`,{className:`claude-info-label`,children:`Reason`}),(0,A.jsx)(`span`,{className:`claude-info-value`,children:e.reason})]}),e.sessionId&&(0,A.jsxs)(`div`,{className:`claude-info-row`,children:[(0,A.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,A.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,j.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,A.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,A.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,A.jsxs)(`div`,{className:`claude-info-header`,children:[(0,A.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`claude-info-icon`}),(0,A.jsx)(`span`,{children:`Claude Code`}),(0,A.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,A.jsxs)(`div`,{className:`claude-info-section`,children:[(0,A.jsxs)(`div`,{className:`claude-info-row`,children:[(0,A.jsx)(`span`,{className:`claude-info-label`,children:`Version`}),(0,A.jsx)(`span`,{className:`claude-info-value`,children:r?r.version:`…`})]}),(0,A.jsxs)(`div`,{className:`claude-info-row`,children:[(0,A.jsx)(`span`,{className:`claude-info-label`,children:`Email`}),(0,A.jsx)(`span`,{className:`claude-info-value`,children:r?.account?.email??`…`})]})]}),(g||m||h>0)&&(0,A.jsxs)(`div`,{className:`claude-info-section`,children:[g&&(0,A.jsxs)(`div`,{className:`claude-info-row`,children:[(0,A.jsx)(`span`,{className:`claude-info-label`,children:`Plan`}),(0,A.jsx)(`span`,{className:`claude-info-value`,style:{textTransform:`capitalize`},children:g})]}),m&&(0,A.jsxs)(A.Fragment,{children:[(0,A.jsxs)(`div`,{className:`claude-info-row`,children:[(0,A.jsx)(`span`,{className:`claude-info-label`,children:`Usage`}),(0,A.jsxs)(`span`,{className:`claude-info-value`,children:[Math.round(m.utilization*100),`%`]})]}),(0,A.jsxs)(`div`,{className:`claude-info-row`,children:[(0,A.jsx)(`span`,{className:`claude-info-label`,children:`Resets in`}),(0,A.jsx)(`span`,{className:`claude-info-value`,children:_(m.resetsAt)})]}),m.isUsingOverage&&(0,A.jsxs)(`div`,{className:`claude-info-row`,children:[(0,A.jsx)(`span`,{className:`claude-info-label`,children:`Overage`}),(0,A.jsx)(`span`,{className:`claude-info-value`,children:`Active`})]})]}),h>0&&(0,A.jsxs)(`div`,{className:`claude-info-row`,children:[(0,A.jsx)(`span`,{className:`claude-info-label`,children:`Session cost`}),(0,A.jsxs)(`span`,{className:`claude-info-value`,children:[`$`,h<.01?h.toFixed(4):h.toFixed(2)]})]})]}),(0,A.jsxs)(`div`,{className:`claude-info-section`,children:[(0,A.jsxs)(`div`,{className:`claude-info-row`,children:[(0,A.jsx)(`span`,{className:`claude-info-label`,children:`Model`}),(0,A.jsx)(`span`,{className:`claude-info-value`,children:r?.model??`…`})]}),(0,A.jsxs)(`div`,{className:`claude-info-row`,children:[(0,A.jsx)(`span`,{className:`claude-info-label`,children:`Context used`}),(0,A.jsx)(`span`,{className:`claude-info-value`,children:f>0?`${f}%`:`—`})]}),(0,A.jsxs)(`div`,{className:`claude-info-row`,children:[(0,A.jsx)(`span`,{className:`claude-info-label`,children:`Tokens`}),(0,A.jsx)(`span`,{className:`claude-info-value`,children:p>0?yt(p):`—`})]}),(0,A.jsxs)(`div`,{className:`claude-info-row`,children:[(0,A.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,A.jsx)(`span`,{className:`claude-info-value`,children:vt(a)})]}),(o||s)&&(()=>{let e=o??s??``;return(0,A.jsxs)(`div`,{className:`claude-info-row`,children:[(0,A.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,A.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 O(e)?`copied`:`failed`),setTimeout(()=>l(null),1200)},children:c===`copied`?`copied ✓`:c===`failed`?`copy failed ✕`:`${e.slice(0,8)}…`})]})})()]})]})})}function Ot({open:e,onConnect:t,onClose:n}){return e?(0,A.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,A.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Claude is not connected`,children:[(0,A.jsxs)(`div`,{className:`claude-info-header`,children:[(0,A.jsx)(`span`,{children:`Claude isn’t connected`}),(0,A.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,A.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`,display:`flex`,flexDirection:`column`,gap:`10px`},children:[(0,A.jsx)(`span`,{children:`This needs Claude, which is currently disconnected. Connect to continue — the rest of the dashboard stays available either way.`}),(0,A.jsxs)(`div`,{style:{display:`flex`,gap:`8px`,alignItems:`center`},children:[(0,A.jsx)(M,{variant:`primary`,size:`sm`,onClick:t,children:`Connect Claude`}),(0,A.jsx)(`button`,{type:`button`,className:`claude-info-close`,style:{fontSize:`11px`},onClick:n,children:`Not now`})]})]})]})}):null}function kt(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 At(e){return e.activeMs.thinking+e.activeMs.messaging+e.activeMs.toolUse}function Y(e){return e.toLocaleString(`en-GB`)}function jt(e){return`£${e.toFixed(2)}`}function Mt(e){let t=[`Day`,`Active`,`Output tokens`,`Input tokens`,`Cache write`,`Cache read`,`Opus 5 (GBP)`,`Sonnet 5 (GBP)`],n=(e,t)=>[e,kt(At(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
- `)}function X({label:e,d:t,bold:n}){let r=n?`th`:`td`;return(0,A.jsxs)(`tr`,{className:n?`usage-total-row`:void 0,children:[(0,A.jsx)(r,{className:`usage-day`,children:e}),(0,A.jsx)(r,{children:kt(At(t))}),(0,A.jsx)(r,{children:Y(t.tokens.output)}),(0,A.jsx)(r,{children:Y(t.tokens.input)}),(0,A.jsx)(r,{children:Y(t.tokens.cacheWrite)}),(0,A.jsx)(r,{children:Y(t.tokens.cacheRead)}),(0,A.jsx)(r,{children:jt(t.costGBP.opus)}),(0,A.jsx)(r,{children:jt(t.costGBP.sonnet)})]})}function Nt({show:e,onClose:t,anchorEl:n,sessionId:r,summary:i,loading:a,error:o}){let s=(0,j.useRef)(null);if(s.current=n,!e)return null;let c=!!i&&i.days.length>0;return(0,A.jsxs)(U,{anchorRef:s,onClose:t,className:`usage-popover`,role:`dialog`,ariaLabel:`Session usage and cost`,anchorId:r??void 0,children:[(0,A.jsxs)(`div`,{className:`claude-info-header`,children:[(0,A.jsxs)(`span`,{children:[`Usage & cost`,r?` · ${r.slice(0,8)}`:``]}),c&&(0,A.jsx)(`button`,{className:`usage-download`,onClick:()=>{if(!i)return;let e=new Blob([Mt(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,A.jsx)(p,{size:14})}),(0,A.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:(0,A.jsx)(x,{size:14})})]}),(0,A.jsxs)(`div`,{className:`claude-info-section usage-body`,children:[a&&(0,A.jsx)(`div`,{className:`usage-note`,children:`Computing usage…`}),!a&&o&&(0,A.jsx)(`div`,{className:`usage-note usage-error`,children:o}),!a&&!o&&i&&i.days.length===0&&(0,A.jsx)(`div`,{className:`usage-note`,children:`No usage recorded for this session yet.`}),!a&&!o&&i&&i.days.length>0&&(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`div`,{className:`usage-table-scroll`,children:(0,A.jsxs)(`table`,{className:`usage-table`,children:[(0,A.jsx)(`thead`,{children:(0,A.jsxs)(`tr`,{children:[(0,A.jsx)(`th`,{className:`usage-day`,children:`Day`}),(0,A.jsx)(`th`,{children:`Active`}),(0,A.jsx)(`th`,{children:`Output tok`}),(0,A.jsx)(`th`,{children:`Input tok`}),(0,A.jsx)(`th`,{children:`Cache write`}),(0,A.jsx)(`th`,{children:`Cache read`}),(0,A.jsx)(`th`,{children:`Opus 5 (£)`}),(0,A.jsx)(`th`,{children:`Sonnet 5 (£)`})]})}),(0,A.jsxs)(`tbody`,{children:[i.days.map(e=>(0,A.jsx)(X,{label:e.date,d:e},e.date)),(0,A.jsx)(X,{label:`TOTAL (${i.days.length} d)`,d:i.totals,bold:!0})]})]})}),(0,A.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 Pt=`https://claude.ai/code`,Ft=200,It=[500,1e3,1500,2e3,2500,3e3,3e3];function Lt(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:`${Pt}/${r}`,sameOrigin:!1};let i=n.reason||n.error||`status ${t}`;return{kind:`error`,sessionId:n.sessionId??null,reason:i}}function Rt(e){if(!e)return``;let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``}function Z(e){let{businessName:n,cacheKey:o,onConnectClaude:c,role:u,userName:f,userAvatar:p,onSelectProjects:m,onSelectTasks:y,onCloseMobileDrawer:b,collapsed:ee,onSelectData:x,initialDataSurface:w=!1,onLogout:te,onDisconnect:ne,disconnecting:O,claudeConnected:ie=!0,subAccounts:k,activeAccountId:ue,switchingAccount:de,onSwitchAccount:M,refreshAccounts:pe,onOpenConversations:be}=e,F=se(o),Te=(0,j.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,A.jsx)(xe,{size:12}),panel:()=>(0,A.jsx)(_t,{row:e,adminFetch:F,onError:e=>R({message:e,failed:!0})})}),[F]),Ee=_.productName,I=n||Ee,De=typeof f==`string`?f:f===null?`name unavailable`:I,Oe=(De.trim().charAt(0)||`?`).toUpperCase(),[ke,Ae]=(0,j.useState)(w?`data`:`sessions`),[je,Me]=(0,j.useState)(!1),[Ne,Pe]=(0,j.useState)(!1),Fe=!ee&&(k?.length??0)>1&&!!M,Ie=k?.find(e=>e.isHouse)??null,Le=(0,j.useCallback)(()=>{Ie&&Ie.accountId!==ue&&(Pe(!1),M?.(Ie.accountId,`/`))},[Ie,ue,M]),[L,R]=(0,j.useState)(null),[Re,ze]=(0,j.useState)(null),[Be,Ve]=(0,j.useState)(!1),[z,He]=(0,j.useState)([]),[Ue]=(0,j.useState)(()=>typeof window>`u`?null:new URLSearchParams(window.location.search).get(`session`)),[We,Ge]=(0,j.useState)(!1),[Ke,qe]=(0,j.useState)(null),[Je,Ye]=(0,j.useState)(!1),[Xe,Ze]=(0,j.useState)(!1),[B,Qe]=(0,j.useState)(!1),[$e,et]=(0,j.useState)(null),[tt,nt]=(0,j.useState)(new Set),rt=(0,j.useRef)(new Map),[V,it]=(0,j.useState)(!1),[H,U]=(0,j.useState)(new Set),[ot,W]=(0,j.useState)(!1),[G,st]=(0,j.useState)(null),[ct,lt]=(0,j.useState)(new Set),[K,ut]=(0,j.useState)(new Set),[dt,ft]=(0,j.useState)(new Set),[q,pt]=(0,j.useState)(null),[mt,J]=(0,j.useState)(``),[ht,gt]=(0,j.useState)(!1),[vt,yt]=(0,j.useState)(null),[xt,Ct]=(0,j.useState)(null),[Tt,Dt]=(0,j.useState)(!1),[kt,At]=(0,j.useState)(null),[Y,jt]=(0,j.useState)(!1),[Mt,X]=(0,j.useState)(!1),Pt=(0,j.useRef)(0);(0,j.useEffect)(()=>{if(!L)return;let e=setTimeout(()=>R(null),2500);return()=>clearTimeout(e)},[L]);let Z=(0,j.useCallback)(async()=>{if(!o)return null;let e=++Pt.current;Ye(!0),qe(null);try{let t=await F(`/api/admin/sidebar-sessions`);if(!t.ok)throw Error(`status ${t.status}`);let n=await t.json(),r=n.sessions??[];return e===Pt.current?(He(r),et(n.accountId??null),Ge(!0),r):r}catch(t){let n=t instanceof Error?t.message:String(t);return e===Pt.current&&qe(`Failed to load sessions: ${n}`),console.error(`[admin-ui] sidebar-sessions fetch failed: ${n}`),null}finally{e===Pt.current&&Ye(!1)}},[o,F]);(0,j.useEffect)(()=>{!o||We||Z()},[o,We,Z]),(0,j.useEffect)(()=>{if(!o)return;let e=null;function t(){Z()}function n(){e===null&&(e=setInterval(t,Bt))}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 zt=()=>{Z()},Ht=()=>{Ae(`data`),x(),b()},Q=typeof window<`u`&&window.location?.pathname||`/`,Ut=ke===`data`,Wt=typeof window<`u`&&window.location?.search||``,Gt=new URLSearchParams(Wt),Kt=Gt.has(`label`)&&!Gt.has(`nodeId`),$=e=>{b(),window.location.href=e},qt=[{key:`dashboard`,label:`Dashboard`,icon:(0,A.jsx)(T,{size:17,strokeWidth:1.75}),active:Q===`/`&&!Ut,onClick:()=>$(`/`)},{key:`chat`,label:`Chat`,icon:(0,A.jsx)(r,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/chat`),onClick:()=>$(`/chat`)},{key:`tasks`,label:`Tasks`,icon:(0,A.jsx)(ve,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/tasks`),onClick:()=>{y(),b()}},{key:`calendar`,label:`Calendar`,icon:(0,A.jsx)(l,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/calendar`),onClick:()=>$(`/calendar`)},{key:`routines`,label:`Routines`,icon:(0,A.jsx)(we,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/routines`),onClick:()=>$(`/routines`)},{key:`skills`,label:`Skills`,icon:(0,A.jsx)(Se,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/skills`),onClick:()=>$(`/skills`)},{key:`agents`,label:`Agents`,icon:(0,A.jsx)(me,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/agents`),onClick:()=>$(`/agents`)},{key:`data`,label:`Data`,icon:(0,A.jsx)(a,{size:17,strokeWidth:1.75}),active:Ut,onClick:Ht},{key:`container`,label:v().term,icon:(0,A.jsx)(d,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/graph`)&&Kt,onClick:()=>{m(),b()}},{key:`graph`,label:`Graph`,icon:(0,A.jsx)(Ce,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/graph`)&&!Kt,onClick:()=>$(`/graph`)},{key:`activity`,label:`Activity`,icon:(0,A.jsx)(ce,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/activity`),onClick:()=>$(`/activity`)}],Jt=(0,j.useCallback)(async e=>{if(ct.has(e.sessionId))return;lt(t=>{let n=new Set(t);return n.add(e.sessionId),n});let t=window.open(``,`_blank`);try{let n=await F(`/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=Lt(n.ok,n.status,{...r,sessionId:r.sessionId??e.sessionId});i.kind===`navigate`?(b(),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}`),ze(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}`),ze({sessionId:e.sessionId,reason:r})}finally{lt(t=>{let n=new Set(t);return n.delete(e.sessionId),n})}},[F,b,ct]),Yt=(0,j.useCallback)(async e=>{let t=e.slice(0,8);for(let t=1;t<=It.length;t++){await new Promise(e=>setTimeout(e,It[t-1]));let n=await Z();if(n&&n.some(t=>t.sessionId===e))return}console.error(`[admin-ui] sidebar-new-session-converge-timeout sessionId=${t}`)},[Z]),Xt=(0,j.useCallback)(async e=>{if(!Y){jt(!0);try{let t=await F(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({title:e})}),n=await t.json().catch(()=>({})),r=Lt(t.ok,t.status,n);r.kind===`navigate`?r.sameOrigin?window.location.assign(r.url):(window.open(r.url,`_blank`),n.sessionId?Yt(n.sessionId):console.error(`[admin-ui] sidebar-new-session-converge-skipped reason=no-session-id`)):t.status===503||r.reason===`claude-auth-dead`?(X(!1),Ve(!0)):(console.error(`[admin-ui] sidebar-new-session-failed status=${t.status} reason=${r.reason}`),X(!1),ze(r))}catch(e){let t=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-new-session-failed error=${t}`),X(!1),ze({sessionId:null,reason:t})}finally{jt(!1)}}},[F,Y,Yt]),Zt=(0,j.useCallback)((e,t)=>{e.stopPropagation(),st(t)},[]),Qt=(0,j.useCallback)(async(e,t)=>{e.stopPropagation(),yt(t),Ct(null),At(null),Dt(!0);try{let e=await F(`/api/admin/session-usage?sessionId=${encodeURIComponent(t.sessionId)}`),n=await e.json().catch(()=>({}));e.ok?Ct(n):At(n.error??`status ${e.status}`)}catch(e){At(e instanceof Error?e.message:String(e))}finally{Dt(!1)}},[F]),$t=(0,j.useCallback)(async(e,t={})=>{let n=t.refresh??!0;if(tt.has(e.sessionId))return!1;nt(t=>{let n=new Set(t);return n.add(e.sessionId),n});try{let t=await F(`/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`}`),R({message:`Delete failed: ${n.error??`status ${t.status}`}`,failed:!0}),!1}return await t.json(),He(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}`),R({message:`Delete failed: ${n}`,failed:!0}),!1}finally{nt(t=>{let n=new Set(t);return n.delete(e.sessionId),n})}},[F,tt,Z]),en=(0,j.useCallback)(e=>{U(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),tn=(0,j.useCallback)(()=>{it(!1),U(new Set)},[]),nn=(0,j.useCallback)(async()=>{let e=[...H].map(e=>z.find(t=>t.sessionId===e)).filter(e=>!!e),t=(await Promise.all(e.map(e=>$t(e,{refresh:!1})))).filter(Boolean).length,n=e.length-t;n>0&&console.warn(`[admin-ui] sidebar-bulk-delete op=done requested=${e.length} ok=${t} failed=${n}`),Z(),tn()},[H,z,$t,Z,tn]),rn=(0,j.useCallback)(async(e,t)=>{if(e.stopPropagation(),!K.has(t.sessionId)){ut(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await F(`/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`}`),R({message:`Stop failed: ${n.error??`status ${e.status}`}`,failed:!0});return}Z()}catch(e){let n=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-session-stop-failed sessionId=${t.sessionId} error=${n}`),R({message:`Stop failed: ${n}`,failed:!0})}finally{ut(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[F,K,Z]),an=(0,j.useCallback)(async(e,t,n)=>{if(e.stopPropagation(),!dt.has(t.sessionId)){ft(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await F(`/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`}`),R({message:`${n===`archive`?`Archive`:`Unarchive`} failed: ${i}`,failed:!0});return}Z()}catch(e){let r=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-session-archive-failed sessionId=${t.sessionId} mode=${n} error=${r}`),R({message:`${n===`archive`?`Archive`:`Unarchive`} failed: ${r}`,failed:!0})}finally{ft(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[F,dt,Z]),on=(0,j.useCallback)(async e=>{let t=mt.trim();if(!t){R({message:`Title can’t be empty`,failed:!0});return}if(t.length>Ft){R({message:`Title too long (max ${Ft})`,failed:!0});return}gt(!0);try{let n=await F(`/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}`),R({message:`Rename failed: ${r}`,failed:!0});return}pt(null),J(``),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}`),R({message:`Rename failed: ${n}`,failed:!0})}finally{gt(!1)}},[F,mt,Z]);return(0,A.jsxs)(`aside`,{className:`side`,children:[(0,A.jsxs)(`div`,{className:`side-brand`,children:[Fe?(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`button`,{type:`button`,className:`side-brand-icon-btn`,"aria-label":`Switch to house account`,disabled:!Ie,onClick:Le,children:(0,A.jsx)(`img`,{className:`side-brand-icon`,src:s,alt:``,"aria-hidden":`true`})}),(0,A.jsxs)(`button`,{type:`button`,className:`side-brand-trigger`,"aria-haspopup":`menu`,"aria-expanded":Ne,"aria-label":`Switch sub-account`,onClick:()=>{let e=!Ne;Pe(e),e&&pe?.()},children:[(0,A.jsxs)(`span`,{className:`side-brand-lockup`,children:[(0,A.jsx)(`span`,{className:`side-brand-business`,children:I}),(0,A.jsx)(`span`,{className:`side-brand-product`,children:_.productName})]}),(0,A.jsx)(he,{size:14,className:`side-brand-caret`,"aria-hidden":`true`})]})]}):(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`img`,{className:`side-brand-icon`,src:s,alt:``,"aria-hidden":`true`}),(0,A.jsxs)(`span`,{className:`side-brand-lockup`,children:[(0,A.jsx)(`span`,{className:`side-brand-business`,children:I}),(0,A.jsx)(`span`,{className:`side-brand-product`,children:_.productName})]})]}),Ne&&(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`div`,{className:`side-brand-scrim`,"aria-hidden":`true`,onClick:()=>Pe(!1)}),(0,A.jsx)(S,{open:Ne,accounts:k??[],activeAccountId:ue??null,switching:de??!1,onSelect:e=>M?.(e),onClose:()=>Pe(!1)})]})]}),(0,A.jsx)(`nav`,{className:`side-nav`,children:qt.map(e=>(0,A.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,A.jsx)(`span`,{className:`label`,children:e.label}),(0,A.jsx)(`span`,{className:`kbd`})]},e.key))}),(()=>{let e=z.filter(e=>Xe?!0:!e.isSubagent).filter(e=>B?!0:!e.archived),n=z.some(e=>e.isSubagent),r=z.some(e=>e.archived);return(0,A.jsx)(`div`,{className:`side-sessions`,children:(0,A.jsxs)(`div`,{className:`side-list`,children:[(0,A.jsxs)(`div`,{className:`group-head`,children:[(0,A.jsx)(`span`,{children:`Sessions`}),(0,A.jsxs)(`span`,{className:`group-head-meta`,children:[(0,A.jsx)(`button`,{type:`button`,className:`group-head-select${V?` active`:``}`,"aria-pressed":V,title:V?`Exit select mode`:`Select multiple sessions to delete`,onClick:()=>{it(e=>!e),U(new Set),pt(null),J(``)},children:`Select`}),(0,A.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh sessions`,"aria-label":`Refresh sessions`,onClick:zt,disabled:Je,children:(0,A.jsx)(ae,{size:12,className:Je?`spinning`:void 0})}),(0,A.jsx)(`span`,{children:Je?`…`:String(e.length)}),(0,A.jsxs)(`button`,{type:`button`,className:`admin-btn-cta side-sessions-new`,onClick:()=>{X(!0)},disabled:Y,"aria-busy":Y,"aria-label":Y?`Spawning session`:`New session`,title:Y?`Spawning session`:`New session`,children:[Y?(0,A.jsx)(t,{size:13,className:`spinning`}):(0,A.jsx)(g,{size:13}),(0,A.jsx)(`span`,{children:Y?`Spawning…`:`New session`})]})]})]}),V&&(0,A.jsxs)(`div`,{className:`session-select-bar`,children:[(0,A.jsxs)(`span`,{className:`session-select-count`,children:[H.size,` selected`]}),(0,A.jsxs)(`button`,{type:`button`,className:`session-select-delete`,disabled:H.size===0,onClick:()=>W(!0),children:[`Delete `,H.size]}),(0,A.jsx)(`button`,{type:`button`,className:`session-select-cancel`,onClick:tn,children:`Cancel`})]}),$e&&(0,A.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,A.jsx)(`code`,{children:$e})}),(n||r)&&(0,A.jsxs)(`div`,{className:`artefact-filter-chips`,children:[n&&(0,A.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${Xe?` active`:``}`,"aria-pressed":Xe,onClick:()=>Ze(e=>!e),title:Xe?`Hide subagent sessions`:`Show subagent sessions`,children:`Subagents`}),r&&(0,A.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${B?` active`:``}`,"aria-pressed":B,onClick:()=>Qe(e=>!e),title:B?`Hide archived sessions`:`Show archived sessions`,children:`Archived`})]}),Ke&&(0,A.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:Ke}),We&&!Ke&&e.length===0&&(0,A.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No sessions yet`}),e.map(e=>{let t=Rt(e.startedAt),n=ct.has(e.sessionId),r=tt.has(e.sessionId),a=K.has(e.sessionId),o=dt.has(e.sessionId),s=n||r||a||o,c=()=>{window.location.assign(`/chat?session=${e.sessionId}`)},l=[{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,A.jsx)(ge,{size:12}),busy:n,onClick:()=>{Jt(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,A.jsx)(ye,{size:12}),onClick:()=>{c()}},{key:`usage`,label:`Usage and cost for session ${e.title}`,menuLabel:`Usage & cost`,title:`Per-day active time, tokens, and estimated GBP cost`,icon:(0,A.jsx)(_e,{size:12}),onClick:t=>{Qt(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,A.jsx)(h,{size:12}),busy:a,onClick:t=>{rn(t,e)}}]:[],e.archived?{key:`unarchive`,label:`Unarchive session ${e.title}`,menuLabel:`Unarchive`,title:`Unarchive (move back to the active list)`,icon:(0,A.jsx)(N,{size:12}),busy:o,onClick:t=>{an(t,e,`unarchive`)}}:{key:`archive`,label:`Archive session ${e.title}`,menuLabel:`Archive`,title:`Archive (hide from the list, keeps the conversation resumable)`,icon:(0,A.jsx)(fe,{size:12}),busy:o,onClick:t=>{an(t,e,`archive`)}},{key:`rename`,label:`Rename session ${e.title}`,menuLabel:`Rename`,title:`Rename this session`,icon:(0,A.jsx)(i,{size:12}),busy:ht&&q===e.sessionId,onClick:t=>{t.stopPropagation(),pt(e.sessionId),J(e.personName??e.title)}},{key:`delete`,label:`Delete session ${e.title}`,menuLabel:`Delete`,title:`Delete session (stops the process, removes the conversation)`,icon:(0,A.jsx)(oe,{size:12}),danger:!0,busy:r,onClick:t=>{Zt(t,e)}},Te({sessionId:e.sessionId,model:e.model??null,title:e.personName??e.title})],u=e.channel===`whatsapp`?` conv-channel-whatsapp`:e.channel===`telegram`?` conv-channel-telegram`:``,d=e.channel===`whatsapp`||e.channel===`telegram`||e.channel===`webchat`,f=re.includes(e.channel??``)&&e.senderId&&e.titleSource===`prefix`?E({operatorName:e.personName??null,whatsappName:e.whatsappName??null,senderId:e.senderId,title:e.title,channel:e.channel}):e.personName??e.title;return(0,A.jsxs)(`div`,{ref:t=>{let n=rt.current;t?n.set(e.sessionId,t):n.delete(e.sessionId)},className:`conv conv-with-actions${u}${e.sessionId===Ue?` active`:``}`,children:[(0,A.jsxs)(`div`,{className:`conv-main-static conv-main-clickable`,role:`button`,tabIndex:0,"aria-label":`Open ${f} in webchat`,onClick:()=>{if(q!==e.sessionId){if(V){en(e.sessionId);return}c()}},onKeyDown:t=>{q!==e.sessionId&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),V?en(e.sessionId):c())},children:[V&&(0,A.jsx)(`span`,{className:`conv-select-check`,onClick:e=>e.stopPropagation(),children:(0,A.jsx)(le,{checked:H.has(e.sessionId),ariaLabel:`Select ${f}`,onChange:()=>en(e.sessionId)})}),(0,A.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,A.jsxs)(`span`,{className:`conv-stack`,children:[(0,A.jsxs)(`span`,{className:`conv-name-line`,children:[d&&(0,A.jsx)(D,{channel:e.channel,size:13}),q===e.sessionId?(0,A.jsx)(`input`,{className:`conv-name conv-name-edit`,autoFocus:!0,onFocus:e=>e.currentTarget.select(),value:mt,disabled:ht,"aria-label":`New title for session ${e.title}`,onChange:e=>J(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),on(e)):t.key===`Escape`&&(t.preventDefault(),pt(null),J(``))},onBlur:()=>{q===e.sessionId&&!ht&&(pt(null),J(``))}}):(0,A.jsx)(`span`,{className:`conv-name`,title:f,children:f})]}),(0,A.jsxs)(`span`,{className:`conv-timestamp`,children:[(0,A.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,A.jsxs)(`span`,{children:[` · `,t]})]})]})]}),!V&&(0,A.jsx)(at,{actions:l,disabled:s})]},e.sessionId)})]})})})(),(0,A.jsxs)(`div`,{className:`side-foot`,children:[(0,A.jsx)(`div`,{className:`avatar`,children:p?(0,A.jsx)(`img`,{src:p,alt:De}):Oe}),(0,A.jsxs)(`div`,{className:`who`,children:[(0,A.jsx)(`span`,{className:`name`,children:De}),(0,A.jsx)(Vt,{})]}),(0,A.jsx)(`button`,{type:`button`,className:`side-foot-kebab`,"aria-label":`Account menu`,"aria-haspopup":`menu`,"aria-expanded":je,onClick:()=>Me(e=>!e),children:(0,A.jsx)(P,{size:16})}),je&&(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`div`,{className:`side-foot-menu-scrim`,"aria-hidden":`true`,onClick:()=>Me(!1)}),(0,A.jsx)(`div`,{className:`side-foot-menu`,role:`menu`,children:(0,A.jsx)(C,{variant:`admin`,onCloseMenu:()=>Me(!1),onLogout:te??(()=>{}),onDisconnect:ne,disconnecting:O,claudeConnected:ie,onConnectClaude:c,cacheKey:o,onOpenConversations:be})})]})]}),L&&(0,A.jsx)(`div`,{className:`copy-toast${L.failed?` copy-toast-failed`:``}`,role:`status`,children:L.message}),(0,A.jsx)(wt,{open:Mt,pending:Y,onConfirm:e=>{Xt(e)},onCancel:e=>{X(!1)}}),(0,A.jsx)(Et,{error:Re,onClose:()=>ze(null)}),(0,A.jsx)(Ot,{open:Be,onConnect:()=>{Ve(!1),c?.()},onClose:()=>Ve(!1)}),(0,A.jsx)(bt,{target:G,anchorEl:G?rt.current.get(G.sessionId)??null:null,onCancel:()=>st(null),onConfirm:()=>{let e=G;st(null),e&&$t(e)}},G?.sessionId??`none`),(0,A.jsx)(St,{open:ot,count:H.size,liveCount:z.filter(e=>H.has(e.sessionId)&&e.live).length,onConfirm:()=>{W(!1),nn()},onCancel:()=>W(!1)}),(0,A.jsx)(Nt,{show:vt!==null,onClose:()=>{yt(null),Ct(null),At(null)},anchorEl:vt?rt.current.get(vt.sessionId)??null:null,sessionId:vt?.sessionId??null,summary:xt,loading:Tt,error:kt},vt?.sessionId??`none`)]})}var zt=5e3,Bt=3e4;function Vt(){let[e,t]=(0,j.useState)(null);if((0,j.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()},zt))}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,A.jsxs)(`span`,{className:d.join(` `),role:`status`,"aria-label":`host CPU and RAM`,children:[(0,A.jsxs)(`span`,{className:i?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`CPU `,u(n)]}),` · `,(0,A.jsxs)(`span`,{className:o?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`RAM `,u(r)]})]})}var Ht=`maxy-shell-browser-px`;function Q(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .side`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function Ut(){return typeof window>`u`?360:Wt(Math.round((window.innerWidth-Q())/2))}function Wt(e){if(typeof window>`u`)return e;let t=Math.max(360,window.innerWidth-Q()-480);return Math.min(Math.max(e,360),t)}function Gt(){if(typeof window>`u`)return 360;try{let e=window.localStorage.getItem(Ht);if(!e)return Ut();let t=parseInt(e,10);return Number.isFinite(t)?Wt(t):(console.warn(`[admin-ui] browser-width-parse-failed stored=${JSON.stringify(e)}`),Ut())}catch{return Ut()}}function Kt({targetSelector:e=`.platform`}={}){let t=(0,j.useRef)(null),n=(0,j.useRef)(360),[,r]=(0,j.useState)(0),i=(0,j.useCallback)(t=>{n.current=t;let i=document.querySelector(e);i instanceof HTMLElement&&i.style.setProperty(`--artefact-px`,`${t}px`),r(e=>e+1)},[e]);(0,j.useLayoutEffect)(()=>{i(Gt())},[i]),(0,j.useEffect)(()=>{let e=()=>i(Wt(n.current));return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[i]);let a=e=>{e.preventDefault();let r=t.current;if(!r)return;r.setPointerCapture(e.pointerId),r.classList.add(`dragging`);let a=!1,o=e=>{a=!0,i(Wt(Math.round(window.innerWidth-e.clientX)))},s=()=>{if(r.releasePointerCapture(e.pointerId),r.classList.remove(`dragging`),window.removeEventListener(`pointermove`,o),window.removeEventListener(`pointerup`,s),a)try{window.localStorage.setItem(Ht,String(n.current))}catch{}};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},o=()=>{i(Ut());try{window.localStorage.removeItem(Ht)}catch{}};return(0,A.jsx)(`div`,{ref:t,className:`browser-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize browser`,onPointerDown:a,onDoubleClick:o})}var $=1;function qt(e){let t=e.className,n=(typeof t==`string`?t:t?.baseVal??``).trim().split(/\s+/).filter(Boolean);return[e.tagName.toUpperCase(),...n].join(`.`)}function Jt(e,t){let n=t.extent-t.vw;return n<$?null:{op:`layout-overflow`,route:e,vw:t.vw,extent:Math.round(t.extent),delta:Math.round(n),offender:t.offender??``}}function Yt(e,t){if(!e||!t)return null;let n=e.documentElement?.clientWidth??0;if(n<=0)return null;let r=n,i=null;for(let t of Array.from(e.body?.querySelectorAll(`*`)??[])){let e=t.getBoundingClientRect().right;e>=r&&e>n+.5&&(r=e,i=qt(t))}return{vw:n,extent:r,offender:i}}function Xt(e){return e?`${e.route}|${e.delta}|${e.offender}`:null}function Zt(e,t){if(!t)return;let n=Jt(e,t);if(n)try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`event`,source:`layout-overflow`,...n}),keepalive:!0}).catch(()=>{})}catch{}}function Qt(e,t,n=400){let r=0,i,a=0,o=null,s=()=>{if(a>=5)return;let n=t.location.pathname,r=Yt(e,t),i=Xt(r&&Jt(n,r));if(!i){o=null;return}i!==o&&(o=i,a+=1,Zt(n,r))},c=()=>{t.cancelAnimationFrame(r),r=t.requestAnimationFrame(s)},l=()=>{i!==void 0&&clearTimeout(i),i=setTimeout(c,n)};c(),t.addEventListener(`resize`,c);let u=new MutationObserver(l);return e.body&&u.observe(e.body,{childList:!0,subtree:!0}),()=>{t.cancelAnimationFrame(r),i!==void 0&&clearTimeout(i),t.removeEventListener(`resize`,c),u.disconnect()}}function $t(e){return e.supported?e.secureContext?e.permission===`denied`?{show:!1,reason:`permission-denied`}:e.permission===`granted`?e.focused?{show:!1,reason:`focused`}:{show:!0}:{show:!1,reason:`permission-default`}:{show:!1,reason:`insecure-context`}:{show:!1,reason:`unsupported`}}function en(){let e=typeof window<`u`&&`Notification`in window;return{supported:e,secureContext:typeof window<`u`&&window.isSecureContext===!0,permission:e?Notification.permission:`default`,focused:typeof document<`u`&&typeof document.hasFocus==`function`?document.hasFocus():!0}}var tn=500,nn=new Set,rn=new Set;function an(e,t){if(e.size>=tn){for(let t of e)if(e.delete(t),e.size<tn)break}e.add(t)}function on(e){return e??(typeof globalThis.fetch==`function`?globalThis.fetch:void 0)}function sn(e,t,n){try{Promise.resolve(e(`/api/admin/events`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({event:t,fields:n})})).catch(()=>{})}catch{}}function cn(e,t){let n=on(t);return n?(sn(n,`wa-notify:desktop-capability`,{supported:e.supported,secure:e.secureContext,permission:e.permission}),!0):!1}function ln(e,t,n,r){if(nn.has(e))return!1;let i=on(r);return i?(an(nn,e),sn(i,`wa-notify:desktop-outcome`,{msgId:e,senderType:t,reason:n}),!0):!1}function un(e,t,n){try{if(rn.has(e.waMessageId))return;an(rn,e.waMessageId);let r=$t(en());if(!r.show){ln(e.waMessageId,e.senderType,r.reason,n);return}new Notification(`${e.accountName} · ${e.senderDisplay}`,{body:e.body+(e.truncated?`…`:``),icon:t,tag:e.waMessageId}),ln(e.waMessageId,e.senderType,`shown`,n)}catch{ln(e.waMessageId,e.senderType,`construct-failed`,n)}}var dn=`admin-sidebar-collapsed`,fn=`admin-sidebar-drawer-open`,pn=1080;function mn(){if(typeof window>`u`)return!1;let e=null;try{e=window.sessionStorage.getItem(dn)}catch{e=null}return e===null?typeof window.matchMedia==`function`?window.matchMedia(`(min-width: 721px) and (max-width: ${pn}px)`).matches:!1:e===`1`}function hn(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(dn,`1`):window.sessionStorage.removeItem(dn)}catch{}}function gn(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(fn)===`1`}catch{return!1}}function _n(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(fn,`1`):window.sessionStorage.removeItem(fn)}catch{}}function vn(e){let[t,n]=(0,j.useState)(()=>typeof window>`u`||typeof window.matchMedia!=`function`?!1:window.matchMedia(e).matches);return(0,j.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 yn=720;function bn(e,t){return e===`/`?{via:`in-place`}:{via:`navigate`,href:`/?wa=${encodeURIComponent(t.remoteJid??``)}&acct=${encodeURIComponent(t.accountId??``)}`}}function xn(e){return e===`/`?{via:`in-place`}:{via:`navigate`,href:`/?data=1`}}function Sn(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 Cn(e,t){return e===`/`?new URLSearchParams(t).has(`data`):!1}function wn(e,t){return t===`operator`&&e===`chat`||e===`dashboard`?`/`:e===`data`?`/data`:e===`graph`?`/graph`:e===`calendar`?`/calendar`:e===`chat`?`/chat`:e===`activity`?`/activity`:`/browser`}var Tn=`maxy-webchat-browser-pane`;function En(){try{let e=window.localStorage.getItem(Tn);return e===`split`||e===`full`?e:`closed`}catch{return`closed`}}function Dn(){return typeof window<`u`&&window.location.pathname.startsWith(`/chat`)}function On(e){let{cacheKey:t,businessName:n,variant:r=`admin`,onLogout:i,onDisconnect:a,disconnecting:o,claudeConnected:l,onConnectClaude:u,userName:d,userAvatar:f,role:p,onOpenConversations:m,children:h,footer:g}=e,{subAccounts:_,activeAccountId:y,switching:b,switchAccount:x,refreshAccounts:S}=ie(t),[C,w]=(0,j.useState)([]),[T,te]=(0,j.useState)(!1),[E,D]=(0,j.useState)(`closed`);(0,j.useEffect)(()=>{let e=Dn();te(e),e&&D(En())},[]);let O=(0,j.useCallback)(e=>{D(e);try{window.localStorage.setItem(Tn,e)}catch{}},[]),re=(0,j.useCallback)(()=>O(`split`),[O]),ae=(0,j.useCallback)(()=>{O(E===`full`?`split`:`full`)},[E,O]),oe=(0,j.useCallback)(()=>O(`closed`),[O]),se=T?E:`closed`,ce=se!==`closed`,k=(0,j.useCallback)(e=>{w(t=>t.filter(t=>t.waMessageId!==e))},[]);(0,j.useEffect)(()=>{if(!t)return;let e=null;try{e=new EventSource(c(`/api/admin/events`,t)),e.addEventListener(Ge,e=>{try{let t=JSON.parse(e.data);if(!t||typeof t.waMessageId!=`string`)return;w(e=>e.some(e=>e.waMessageId===t.waMessageId)?e:[...e,t]),un(t,s)}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]),(0,j.useEffect)(()=>{cn(en())},[]);let[le,ue]=(0,j.useState)(!0);(0,j.useEffect)(()=>{if(l!==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||ue(n.auth_status!==`dead`&&n.auth_status!==`missing`)}catch{}};t();let n=setInterval(t,6e4);return()=>{e=!0,clearInterval(n)}},[l,r]);let de=l??le,M=u??(()=>{window.location.assign(`/?connect=claude`)}),[N,fe]=(0,j.useState)(()=>mn()),[pe,me]=(0,j.useState)(!1),he=(0,j.useRef)(!0);(0,j.useEffect)(()=>{if(he.current){he.current=!1;return}me(!0);let e=setTimeout(()=>me(!1),260);return()=>clearTimeout(e)},[N]);let[P,ge]=(0,j.useState)(()=>gn()),_e=vn(`(max-width: ${yn}px)`),[ve,ye]=(0,j.useState)(()=>typeof window>`u`||Cn(window.location.pathname,window.location.search)?null:Sn(window.location.pathname,window.location.search)),[be,F]=(0,j.useState)(()=>typeof window>`u`?!1:Cn(window.location.pathname,window.location.search)),[xe]=(0,j.useState)(()=>be),Se=(0,j.useCallback)(e=>{hn(e),fe(e)},[]),Ce=(0,j.useCallback)(e=>{_n(e),ge(e)},[]);(0,j.useEffect)(()=>{typeof window>`u`||window.location?.pathname},[]),(0,j.useEffect)(()=>{typeof window>`u`||!ve||window.history.replaceState(null,``,`/`)},[]),(0,j.useEffect)(()=>{typeof window>`u`||!be||window.history.replaceState(null,``,`/`)},[]);let we=(0,j.useCallback)(e=>{if(F(!1),e===null){ye(null);return}let t=bn(typeof window<`u`?window.location.pathname:`/`,e);t.via===`in-place`?ye(e):window.location.href=t.href},[]),Te=(0,j.useCallback)(()=>{let e=xn(typeof window<`u`?window.location.pathname:`/`);if(e.via===`navigate`){window.location.href=e.href;return}ye(null),F(!0)},[]),Ee=_e?P:!N,I=(0,j.useCallback)(()=>{typeof window>`u`||(window.matchMedia(`(max-width: ${yn}px)`).matches?Ce(!P):Se(!N))},[N,P,Se,Ce]);(0,j.useEffect)(()=>{if(!(typeof window>`u`))return Qt(document,window)},[]);let De=(0,j.useCallback)(e=>{let t=wn(e,r);window.location.href=t},[r]),Oe={collapsed:N,mobileDrawerOpen:P,sidebarOpen:Ee,onToggleSidebar:I,setMobileDrawerOpen:Ce,selectedWhatsapp:ve,onClearWhatsapp:()=>ye(null),onSelectWhatsappConversation:we,dataOpen:be};return r===`operator`?(0,A.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[b&&(0,A.jsx)(ee,{surface:`switch`}),(0,A.jsx)(ne,{businessName:n,variant:r,onNavigate:De,onOpenConversations:m,onToggleSidebar:I,sidebarOpen:Ee,onLogout:i,onDisconnect:a,disconnecting:o,cacheKey:t,subAccounts:_,activeAccountId:y,switchingAccount:b,onSwitchAccount:x,refreshAccounts:S}),(0,A.jsx)(`div`,{className:`platform platform-operator`,children:typeof h==`function`?h(Oe):h}),(0,A.jsx)(B,{variant:`operator`,onOpenConversations:m}),g,(0,A.jsx)(We,{frames:C,onExpire:k})]}):(0,A.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[b&&(0,A.jsx)(ee,{surface:`switch`}),(0,A.jsxs)(`div`,{className:`platform${P?` menu-open`:``}${!_e&&N?` sidebar-collapsed`:``}${pe?` sidebar-animating`:``}`,"data-artefact":ce?`browser`:`closed`,"data-browser-pane":se,children:[(0,A.jsx)(Z,{businessName:n,cacheKey:t,onConnectClaude:M,role:p??null,userName:d,userAvatar:f??null,onSelectProjects:()=>{window.location.href=`/graph?label=${v().label}`},onSelectTasks:()=>{window.location.href=`/tasks`},onCloseMobileDrawer:()=>Ce(!1),collapsed:N,mobileDrawerOpen:P,onSelectData:Te,onCloseData:()=>F(!1),initialDataSurface:xe,onLogout:i,onDisconnect:a,disconnecting:o,claudeConnected:de,subAccounts:_,activeAccountId:y,switchingAccount:b,onSwitchAccount:x,refreshAccounts:S,onOpenConversations:m}),!_e&&(0,A.jsx)(nt,{}),(0,A.jsx)(Je,{sidebarOpen:Ee,onToggleSidebar:I,claudeConnected:de,onConnectClaude:M,onOpenBrowser:T&&!ce?re:void 0}),typeof h==`function`?h(Oe):h,ce&&(0,A.jsxs)(`div`,{className:`webchat-browser-pane`,children:[se===`split`&&(0,A.jsx)(Kt,{}),(0,A.jsx)(R,{cacheKey:e.cacheKey,surface:`webchat`,onToggleFull:ae,onClosePane:oe,isFull:se===`full`})]})]}),P&&(0,A.jsx)(`div`,{className:`sidebar-backdrop menu-open`,"aria-hidden":`true`,onClick:()=>Ce(!1)}),(0,A.jsx)(B,{}),g,(0,A.jsx)(We,{frames:C,onExpire:k})]})}export{k as A,P as C,N as D,fe as E,M as O,ge as S,me as T,xe as _,Dt as a,ve as b,G as c,ut as d,ct as f,Se as g,we as h,Ot as i,le as k,ot as l,R as m,vn as n,xt as o,at as p,Lt as r,wt as s,On as t,W as u,be as v,he as w,_e as x,ye as y};
@@ -1 +0,0 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{G as t,J as n,Y as r,Z as i,_ as a,n as o,v as s,z as c}from"./useSubAccountSwitcher-C7TtIbR3.js";import{A as l,O as u,k as d,t as f}from"./AdminShell-D24evn4t.js";import{t as p}from"./triangle-alert-Cy4Z0uFv.js";var m=r(),h=e(i(),1),g=t(),_=`—`;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,r]=(0,h.useState)(null),[i,s]=(0,h.useState)(null),[l,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 o(t,e)&&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){s(`This view is available to the house account only.`),f(!0);return}if(!n.ok){s(`The session manager did not answer (status ${n.status}).`),f(!0);return}r(await n.json()),s(null)}catch(e){s(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(!l)return(0,g.jsx)(a,{surface:`gate`});if(i)return(0,g.jsx)(`div`,{className:`activity-empty`,children:i});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)(c,{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)(d,{checked:S,onChange:C,label:`Busy`}),(0,g.jsx)(d,{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:t}=n({initialCacheKey:e,surface:`activity`});return(0,g.jsx)(Y,{adminFetch:t,cacheKey:e})}function Z(){let[e,t]=(0,h.useState)(null),[n,r]=(0,h.useState)(!1),[i,o]=(0,h.useState)(void 0),[c,u]=(0,h.useState)(null),[d,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`&&o(e.businessName),e.sessionId!==void 0&&u(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 l();if(e){try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`}return e}finally{S(!1)}},[]);return n?e?(0,g.jsx)(s,{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:d,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)(a,{surface:`gate`})}(0,m.createRoot)(document.getElementById(`root`)).render((0,g.jsx)(Z,{}));
@@ -1 +0,0 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{G as t,K as n,M as r,S as i,Y as a,Z as o,c as s,d as c,f as l,o as u,v as d,y as ee}from"./useSubAccountSwitcher-C7TtIbR3.js";import{n as f,t as p}from"./AdminLoginScreens-BpHnjHp_.js";import{f as te,s as m,x as h}from"./useVoiceRecorder-DgyAGgmF.js";import{S as g,T as ne,a as _,g as re,t as v,w as ie}from"./AdminShell-D24evn4t.js";import{t as y}from"./chevron-left-NGLHgPjF.js";import{t as ae}from"./chevron-right-B4B7OkG8.js";import{n as b,r as x}from"./page-D0ShNyGE.js";import{t as oe}from"./file-text-BA9p7TLU.js";import"./graph-labels-CiK412vE.js";import{n as se}from"./file-download-DbNIjWiK.js";var S=a(),C=e(o(),1),w=t();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)(h,{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)(m,{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 L=6e4;function ce(e){return e<12?`morning`:e<18?`afternoon`:`evening`}function R(e){return e&&e.trim().split(/\s+/)[0]||`there`}function le(e){if(!e)return`everything is running normally.`;let t=e.cpuPct,n=e.memUsedPct;return t!==null&&t>=.98||n!==null&&n>=.98?`system load is critical.`:t!==null&&t>=.9||n!==null&&n>=.9?`system load is high.`:`everything is running normally.`}function z(e){return e==null?`—`:`${Math.round(e*100)}%`}function ue(e){return e.isGroup===!0?e.chatName??e.title:e.operatorName??e.chatName??e.whatsappName??e.senderId??e.title}function de(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:t,onSelectWhatsappConversation:a}){let o=ee(e),[d,f]=(0,C.useState)(null),[p,m]=(0,C.useState)(null),[h,_]=(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 r(e,n,r,i){let a=Date.now(),s=typeof n==`string`?n:`unresolved`;try{typeof n!=`string`&&(s=await n());let e=await o(s);if(!e.ok)throw Error(`status ${e.status}`);let a=await e.json();t||i(r(a))}catch(t){q.current.add(e),console.error(`[admin-ui] dashboard-fetch-failed slice=${e} url=${s} ms=${Date.now()-a} reason=${t instanceof Error?t.message:String(t)}`)}finally{K.current.set(e,Date.now()-a),U(e)}}async function i(){if(!J.current){let e=await o(`/api/admin/accounts`);if(!e.ok)throw Error(`accounts status ${e.status}`);let t=await e.json(),n=t.accounts??[],r=t.activeAccountId??null,i=n.find(e=>e.accountId===r);if(!i)throw Error(`accounts: active ${r??`none`} absent from list of ${n.length}`);let a=i.isHouse||n.length===1;J.current={accountId:i.accountId,isHouse:a}}let{accountId:e,isHouse:t}=J.current;return t?`/api/operator-conversations/conversations-all`:`/api/operator-conversations/conversations`}let a={"sidebar-sessions":()=>r(`sessions`,`/api/admin/sidebar-sessions`,e=>e.sessions??[],f),"conversations-all":()=>r(`conversations`,i,e=>e.conversations??[],m),"tasks-list":()=>r(`tasks`,`/api/admin/tasks-list`,e=>e,S),"sidebar-artefacts":()=>r(`artefacts`,`/api/admin/sidebar-artefacts`,e=>e.artefacts??[],E),skills:()=>r(`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(a).map(e=>e()),r(`stats`,`/api/admin/system-stats`,e=>e,b),r(`bookingLink`,`/api/admin/calendar/booking-link`,e=>e.bookingDomain??null,A),r(`portalLink`,`/api/admin/data-portal/portal-link`,e=>e.portalDomain??null,M)])}finally{G.current=!1;let t=Date.now()-e;if(!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(n(`/api/admin/events`,e)),c.onmessage=e=>{if(document.visibilityState===`visible`)try{let{resource:t}=JSON.parse(e.data),n=t?a[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()},L),u=()=>{document.visibilityState===`visible`&&s()};return document.addEventListener(`visibilitychange`,u),()=>{t=!0,G.current=!1,clearInterval(l),c?.close(),document.removeEventListener(`visibilitychange`,u)}},[e,o]);let Y=(0,C.useMemo)(()=>(d??[]).filter(e=>!e.isSubagent),[d]),X=(0,C.useMemo)(()=>Y.filter(e=>e.live),[Y]),me=(0,C.useMemo)(()=>(p??[]).filter(e=>de(e.lastMessageAt,W)).length,[p,W]),he=x?.open.length??0,Z=(0,C.useMemo)(()=>{let e=new Map;for(let t of p??[]){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?ue(n):``,rows:t}})},[p]);(0,C.useEffect)(()=>{v.current||Z.length!==0&&(v.current=!0,_(Z[0].channel))},[Z]);let Q=(0,C.useRef)(!1);(0,C.useEffect)(()=>{Q.current||!B.has(`bookingLink`)||!B.has(`portalLink`)||(Q.current=!0)},[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 o(`/api/admin/session-stop`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e})});if(!t.ok){console.error(`[admin-ui] dashboard-session-stop-failed sessionId=${e} status=${t.status}`);return}f(t=>(t??[]).map(t=>t.sessionId===e?{...t,live:!1}:t))}catch(t){console.error(`[admin-ui] dashboard-session-stop-failed sessionId=${e} reason=${t instanceof Error?t.message:String(t)}`)}finally{P(t=>{let n=new Set(t);return n.delete(e),n})}}},[o,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}se(e,t.downloadPath,t.downloadRoot??`data`)},[e]),$=ce(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 ${$}, ${R(t)} — ${le(y)}`:`Good ${$}, ${R(t)}`}),(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:z(y?.cpuPct??null)}),(0,w.jsxs)(`span`,{className:`dashboard-stat-delta`,children:[`RAM `,z(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)(g,{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)(g,{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)(i,{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)(ne,{size:16}):(0,w.jsx)(oe,{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)(re,{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(t=>{let n=h===t.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":n,onClick:()=>_(e=>e===t.channel?null:t.channel),children:[(0,w.jsx)(`span`,{className:`dashboard-channel-glyph`,children:t.channel===`whatsapp`||t.channel===`telegram`?(0,w.jsx)(l,{channel:t.channel,size:16}):(0,w.jsx)(r,{size:16})}),(0,w.jsx)(`span`,{className:`dashboard-channel-name`,children:c[t.channel]??t.channel}),(0,w.jsx)(`span`,{className:`dashboard-channel-badge`,children:t.count}),(0,w.jsx)(`span`,{className:`dashboard-channel-chevron`,children:n?(0,w.jsx)(ie,{size:14}):(0,w.jsx)(ae,{size:14})})]}),n?(0,w.jsx)(`div`,{className:`dashboard-channel-convs`,children:t.rows.map(t=>(0,w.jsxs)(`button`,{type:`button`,className:`admin-row dashboard-channel-conv-row`,onClick:()=>a(t),title:t.title,children:[(0,w.jsxs)(`span`,{className:`dashboard-channel-conv-line`,children:[(0,w.jsx)(te,{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:u(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]},s(t)))}):t.preview&&(0,w.jsx)(`span`,{className:`dashboard-channel-preview`,children:t.preview})]},t.channel)}):(0,w.jsx)(I,{variant:`card`,count:2})]})]})]})}function U(){let e=f(),[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)return;let r=Date.now();if(!e.cacheKey){console.error(`[admin-ui] claude-info-fetch-skipped reason=no-session-key`);return}try{let t=await fetch(`/api/admin/claude-info?session_key=${encodeURIComponent(e.cacheKey)}`);if(t.ok){let n=await t.json();e.setClaudeInfo(n)}}catch(e){console.error(`[admin-ui] claude-info-fetch-failed ms=${Date.now()-r} error="${e instanceof Error?e.message:String(e)}"`)}},[e]),i=(0,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)(d,{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)(_,{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:u(t.selectedWhatsapp),sessionKey:e.cacheKey,onBack:t.onClearWhatsapp},s(t.selectedWhatsapp)):(0,w.jsx)(E,{sessionId:t.selectedWhatsapp.sessionId,projectDir:t.selectedWhatsapp.projectDir,sessionKey:e.cacheKey,contactName:u(t.selectedWhatsapp),onBack:t.onClearWhatsapp},s(t.selectedWhatsapp)):(0,w.jsx)(H,{cacheKey:e.cacheKey,userName:e.userName,onSelectWhatsappConversation:t.onSelectWhatsappConversation})})})}):(0,w.jsx)(p,{auth:e})}(0,S.createRoot)(document.getElementById(`root`)).render((0,w.jsx)(U,{}));
@@ -1 +0,0 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{A as t,B as n,G as r,J as i,Y as a,Z as o,_ as s,b as c,v as l,x as u}from"./useSubAccountSwitcher-C7TtIbR3.js";import{A as d,S as f,T as p,t as m}from"./AdminShell-D24evn4t.js";var h=n(`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=n(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),_=a(),v=e(o(),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=r(),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:n,accountId:r,adminFetch:i,onClose:a,onDeleted:o,onToggled:s}){let l=e.kind===`specialist`,d=e.origin===`specialist`,m=e.origin===`shipped`&&e.disabled,_=d||m,[E]=(0,v.useState)(r),[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 i(`/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}},[i,e.slug]),(0,v.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!F&&a()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[F,a]);let V=(0,v.useCallback)(async()=>{I(!0),M(null);try{let t=await i(`/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}`)}o(e)}catch(e){M(e instanceof Error?e.message:`Delete failed`),I(!1),P(!1)}},[i,e,E,o]),H=(0,v.useCallback)(async()=>{let t=e.disabled?`enable`:`disable`;B(!0),M(null);try{let n=await i(`/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(),a()}catch(e){M(e instanceof Error?e.message:`${t} failed`),B(!1),R(!1)}},[i,e,E,s,a]),U=l?null:D,W=l?D:null;return(0,S.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{F||a()},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)(p,{size:13}),` `,l?`Specialist`:`Agent`]}),(0,S.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:a,"aria-label":`Close`,autoFocus:!0,disabled:F,children:(0,S.jsx)(c,{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)(t,{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:`${n}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`cal-link`,children:[(0,S.jsx)(f,{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)(t,{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)(u,{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)(t,{size:14,className:`spin`}):(0,S.jsx)(u,{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,f]=(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),f(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 d();if(e){try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`}return e}finally{x(!1)}},[]);return n?e?(0,S.jsx)(l,{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)(s,{surface:`gate`})}function j({cacheKey:e}){let{adminFetch:n,sessionRefetchNonce:r}=i({initialCacheKey:e,surface:`agents`}),[a,o]=(0,v.useState)([]),[c,l]=(0,v.useState)(0),[u,d]=(0,v.useState)(0),[f,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();o(Array.isArray(n.agents)?n.agents:[]),l(typeof n.skipped==`number`?n.skipped:0),d(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`),o([]))}).finally(()=>{e||(b(!1),C(!0))}),()=>{e=!0}},[n]);(0,v.useEffect)(()=>N(),[N,r]);let P=(0,v.useCallback)(e=>{o(t=>t.filter(t=>t.slug!==e.slug)),A(null),N()},[N]);if(!x)return(0,S.jsx)(s,{surface:`gate`});let F=a.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)(p,{size:16}),` `,a.length,` agent`,a.length===1?``:`s`,` · `,F,` stood down`]}),_&&(0,S.jsx)(t,{size:16,className:`spin`})]})}),(0,S.jsxs)(`div`,{className:`cal-body agents-body`,children:[w&&(0,S.jsxs)(`div`,{className:`cal-error`,children:[`Could not load agents: `,w]}),f&&(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.`}),c+u>0&&(0,S.jsxs)(`div`,{className:`cal-error`,children:[c+u,` agent`,c+u===1?``:`s`,` could not be read (malformed config or frontmatter).`]}),!w&&!_&&a.length===0&&(0,S.jsx)(`div`,{className:`cal-empty`,children:(0,S.jsx)(`p`,{children:`No agents yet. Ask in chat to create one.`})}),a.length>0&&(0,S.jsx)(`div`,{className:`routine-list agents-list`,children:a.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 +0,0 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{A as t,G as n,M as r,Y as i,Z as a,v as o}from"./useSubAccountSwitcher-C7TtIbR3.js";import{A as s,m as c,t as l}from"./AdminShell-D24evn4t.js";var u=i(),d=e(a(),1),f=n();function p(){let[e,n]=(0,d.useState)(null),[i,a]=(0,d.useState)(!1),[u,p]=(0,d.useState)(void 0),[m,h]=(0,d.useState)(null),[g,_]=(0,d.useState)(void 0),[v,y]=(0,d.useState)(null),[b,x]=(0,d.useState)(null);(0,d.useEffect)(()=>{let e=!1,t=null;try{t=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!t){n(null),a(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(t)}`).then(async r=>{if(!e){if(r.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}if(r.ok)try{let e=await r.json();typeof e.businessName==`string`&&p(e.businessName),e.sessionId!==void 0&&h(e.sessionId??null),x(e.role??null),_(e.userName===void 0?null:e.userName),y(e.avatar??null)}catch{}n(t),a(!0)}}).catch(()=>{e||(n(t),a(!0))}),()=>{e=!0}},[]);let S=(0,d.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]),[C,w]=(0,d.useState)(!1),T=(0,d.useCallback)(async()=>{w(!0);try{let e=await s();if(e){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`}return e}finally{w(!1)}},[]);return i?e?(0,f.jsx)(o,{cacheKey:e,surface:`browser`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=browser`);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},children:(0,f.jsx)(l,{cacheKey:e,businessName:u,sessionId:m,onLogout:S,onDisconnect:T,disconnecting:C,userName:g,userAvatar:v,role:b,children:(0,f.jsxs)(`div`,{className:`data-page`,children:[(0,f.jsx)(`header`,{className:`data-header`,children:(0,f.jsxs)(`h1`,{className:`data-title`,children:[(0,f.jsx)(r,{size:18}),` Browser`]})}),(0,f.jsx)(c,{})]})})}):(0,f.jsxs)(`div`,{className:`data-page`,children:[(0,f.jsx)(`header`,{className:`data-header`,children:(0,f.jsxs)(`h1`,{className:`data-title`,children:[(0,f.jsx)(r,{size:18}),` Browser`]})}),(0,f.jsxs)(`div`,{className:`data-empty`,children:[(0,f.jsx)(`p`,{children:`You are not signed in.`}),(0,f.jsxs)(`p`,{children:[`Open the `,(0,f.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})]}):(0,f.jsx)(`div`,{className:`data-page`,children:(0,f.jsxs)(`div`,{className:`data-loading`,children:[(0,f.jsx)(t,{size:18,className:`spin`}),` Loading…`]})})}(0,u.createRoot)(document.getElementById(`root`)).render((0,f.jsx)(p,{}));
@@ -1 +0,0 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{A as t,B as n,E as r,G as i,J as a,M as o,P as s,T as c,Y as l,Z as u,_ as d,b as f,v as p,x as m}from"./useSubAccountSwitcher-C7TtIbR3.js";import{A as h,S as g,t as _}from"./AdminShell-D24evn4t.js";import{t as v}from"./chevron-left-NGLHgPjF.js";import{t as y}from"./chevron-right-B4B7OkG8.js";import{t as b}from"./clock-7IMwxJdH.js";import{t as x}from"./file-text-BA9p7TLU.js";var S=n(`calendar`,[[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`rect`,{width:`18`,height:`18`,x:`3`,y:`4`,rx:`2`,key:`1hopcy`}],[`path`,{d:`M3 10h18`,key:`8toen8`}]]),C=n(`map-pin`,[[`path`,{d:`M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0`,key:`1r0f0z`}],[`circle`,{cx:`12`,cy:`10`,r:`3`,key:`ilqhr7`}]]),w=n(`sticky-note`,[[`path`,{d:`M21 9a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 15 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2z`,key:`1dfntj`}],[`path`,{d:`M15 3v5a1 1 0 0 0 1 1h5`,key:`6s6qgf`}]]),T=n(`user-plus`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`19`,x2:`19`,y1:`8`,y2:`14`,key:`1bvyxn`}],[`line`,{x1:`22`,x2:`16`,y1:`11`,y2:`11`,key:`1shjgl`}]]),E=n(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),D=l(),O=e(u(),1),k=new Map;function A(e){let t=k.get(e);return t||(t=new Intl.DateTimeFormat(`en-CA`,{timeZone:e,hourCycle:`h23`,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`}),k.set(e,t)),t}function j(e,t){let n=A(t).formatToParts(e),r=e=>Number(n.find(t=>t.type===e)?.value??`0`);return{y:r(`year`),m:r(`month`),d:r(`day`),hh:r(`hour`),mm:r(`minute`),ss:r(`second`)}}var M=e=>String(e).padStart(2,`0`);function N(e,t){let n=j(e,t);return`${n.y}-${M(n.m)}-${M(n.d)}`}function P(e,t){let n=j(e,t);return Date.UTC(n.y,n.m-1,n.d,n.hh,n.mm,n.ss)-e.getTime()}function F(e,t,n,r){let i=Date.UTC(e,t-1,n),a=i-P(new Date(i),r);return new Date(i-P(new Date(a),r))}function ee(e,t,n,r,i,a){let o=Date.UTC(e,t-1,n,r,i),s=o-P(new Date(o),a);return new Date(o-P(new Date(s),a))}var I=new Map;function L(e,t){let n=I.get(e);if(!n){try{n=new Intl.DateTimeFormat(`en-GB`,{timeZone:e,timeZoneName:`long`})}catch{return e}I.set(e,n)}return n.formatToParts(t).find(e=>e.type===`timeZoneName`)?.value??e}function R(){return Intl.DateTimeFormat().resolvedOptions().timeZone}var z=1440*60*1e3;function B(e,t){let n=j(e,t);return F(n.y,n.m,n.d,t)}function V(e,t,n){let r=j(e,n),i=new Date(Date.UTC(r.y,r.m-1,r.d)+t*z);return F(i.getUTCFullYear(),i.getUTCMonth()+1,i.getUTCDate(),n)}function H(e,t){let n=B(e,t),r=j(n,t),i=new Date(Date.UTC(r.y,r.m-1,r.d)).getUTCDay();return V(n,i===0?-6:1-i,t)}function U(e,t,n){let r=j(t,n);switch(e){case`day`:{let e=B(t,n);return{from:e,to:V(e,1,n)}}case`week`:{let e=H(t,n);return{from:e,to:V(e,7,n)}}case`month`:return{from:F(r.y,r.m,1,n),to:r.m===12?F(r.y+1,1,1,n):F(r.y,r.m+1,1,n)};case`year`:return{from:F(r.y,1,1,n),to:F(r.y+1,1,1,n)}}}function W(e,t,n,r){let i=j(t,r);switch(e){case`day`:return V(t,n,r);case`week`:return V(t,n*7,r);case`month`:{let e=i.y*12+(i.m-1)+n;return F(Math.floor(e/12),e%12+1,1,r)}case`year`:return F(i.y+n,i.m,1,r)}}function G(e,t,n){return N(e,n)===N(t,n)}var K=[`day`,`week`,`month`,`year`],te=`month`;function q(e,t){return e.toLocaleDateString([],{day:`numeric`,month:`short`,timeZone:t})}function ne(e,t){return e.toLocaleDateString([],{day:`numeric`,month:`short`,year:`numeric`,timeZone:t})}function re(e,t,n){switch(e){case`day`:return t.toLocaleDateString([],{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`,timeZone:n});case`week`:{let{from:e,to:r}=U(`week`,t,n);return`${q(e,n)} – ${ne(new Date(r.getTime()-1),n)}`}case`month`:return t.toLocaleDateString([],{month:`long`,year:`numeric`,timeZone:n});case`year`:return String(j(t,n).y)}}function ie(e,t){return{role:`button`,tabIndex:0,onClick:()=>t(e),onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),t(e))}}}var J=i(),ae={meeting:`Meeting`,event:`Event`,task:`Task`};function oe(e){return ae[e.kind??`meeting`]}function Y(e,t){return e.toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`,timeZone:t})}function se(e,t){if(e.isAllDay)return`All day`;let n=Y(new Date(e.startsAt),t);return e.endsAt?`${n} – ${Y(new Date(e.endsAt),t)}`:n}function X(e,t){if(!e)return``;let n=new Date(e);if(Number.isNaN(n.getTime()))return``;let r=j(n,t),i=e=>String(e).padStart(2,`0`);return`${r.y}-${i(r.m)}-${i(r.d)}T${i(r.hh)}:${i(r.mm)}`}function Z(e,t){let n=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/.exec(e);if(!n)return``;let[,r,i,a,o,s]=n;return ee(Number(r),Number(i),Number(a),Number(o),Number(s),t).toISOString()}function ce(e,t){let n=new Date(e.startsAt),r={weekday:`long`,day:`numeric`,month:`long`,year:`numeric`,timeZone:t};if(e.isAllDay)return n.toLocaleDateString([],r);let i=n.toLocaleDateString([],r),a=Y(n,t);return e.endsAt?`${i} · ${a} – ${Y(new Date(e.endsAt),t)}`:`${i} · ${a}`}function le(e,t){return e.email??`${e.name??`unknown`}-${t}`}function ue(e){return e.map(e=>e.name||e.email||`Unknown`).join(`, `)}function de({a:e}){let t=e.name||e.email||`Unknown`,n=e.name&&e.email?e.email:null;return(0,J.jsxs)(`span`,{className:`cal-attendee-lines`,children:[(0,J.jsx)(`span`,{className:`cal-attendee-name`,children:t}),n&&(0,J.jsx)(`span`,{className:`cal-attendee-email`,children:n})]})}function fe(e){let t=[...e].sort((e,t)=>e.start.localeCompare(t.start)),n=[];for(let e of t){let t=n[n.length-1];t&&t.end===e.start?(t.end=e.end,t.slots+=1):n.push({start:e.start,end:e.end,slots:1})}return n}function pe(e,t){let n=e.slots===1?`slot`:`slots`;return`free ${Y(new Date(e.start),t)} – ${Y(new Date(e.end),t)} · ${e.slots} ${n}`}function me(e,t,n,r=[],i){let a=B(t,i),o=[];for(let t=0;t<n;t++){let n=V(a,t,i),s=e.filter(e=>G(new Date(e.startsAt),n,i)).sort((e,t)=>e.startsAt.localeCompare(t.startsAt)),c=r.some(e=>G(new Date(e.start),n,i));(s.length>0||c)&&o.push({day:n,meetings:s})}return o}function he(e,t,n){return Math.round((B(t,n).getTime()-B(e,n).getTime())/864e5)}function ge(e,t,n){let r=e.toLocaleDateString([],{weekday:`long`,day:`numeric`,month:`long`,timeZone:n});return G(e,t,n)?`${r} · today`:r}function _e({from:e,to:t,meetings:n,stretches:r,gapSource:i,showAllKinds:a,onToggleKinds:o,onSelect:s,onAddAt:c,zone:l,zoneSource:u}){let d=a?n:n.filter(e=>(e.kind??`meeting`)===`meeting`),f=n.length-d.length,p=new Date,m=me(d,e,he(e,t,l),r,l),h=(0,J.jsxs)(`div`,{className:`cal-list-controls`,children:[(0,J.jsx)(`button`,{type:`button`,className:`cal-kind-toggle${a?` cal-kind-toggle-on`:``}`,onClick:o,"aria-pressed":a,children:a?`Meetings only`:`Show reminders and tasks`}),f>0&&(0,J.jsxs)(`span`,{className:`cal-hidden-count`,children:[f,` hidden`]}),(0,J.jsxs)(`span`,{className:`cal-zone-label`,"data-zone":l,"data-zone-source":u,children:[`Times in `,L(l,p)]}),i===`none`&&(0,J.jsx)(`span`,{className:`cal-no-hours`,children:`Free time is not shown: working hours are not set.`})]});return m.length===0?(0,J.jsxs)(`div`,{className:`cal-schedule`,children:[h,(0,J.jsx)(`div`,{className:`cal-schedule-empty`,children:`No events in this period.`})]}):(0,J.jsxs)(`div`,{className:`cal-schedule`,children:[h,m.map(e=>{let t=r.filter(t=>G(new Date(t.start),e.day,l));return(0,J.jsxs)(`section`,{className:`cal-sched-group`,children:[(0,J.jsx)(`h3`,{className:`cal-sched-day${G(e.day,p,l)?` cal-sched-day-today`:``}`,children:ge(e.day,p,l)}),e.meetings.map(e=>{let t=[e.location,ue(e.attendees)||null,oe(e)].filter(Boolean);return(0,J.jsxs)(`div`,{className:`cal-sched-row`,"data-testid":`row-${e.meetingId}`,"data-meeting-id":e.meetingId,"data-kind":e.kind??`meeting`,...ie(e,s),children:[(0,J.jsx)(`span`,{className:`cal-sched-time`,children:se(e,l)}),(0,J.jsxs)(`span`,{className:`cal-sched-detail`,children:[(0,J.jsx)(`span`,{className:`cal-sched-title`,children:e.title??`Untitled`}),(0,J.jsx)(`span`,{className:`cal-sched-meta`,children:t.join(` · `)})]})]},e.meetingId)}),t.map(e=>(0,J.jsx)(`button`,{type:`button`,className:`cal-gap`,"data-gap-start":e.start,onClick:()=>c(e.start,e.end),children:pe(e,l)},e.start))]},e.day.toISOString())})]})}function ve({initialStart:e,initialEnd:n,zone:r,adminFetch:i,onClose:a,onCreated:o}){let[s,c]=(0,O.useState)(``),[l,u]=(0,O.useState)(e),[d,p]=(0,O.useState)(n),[m,h]=(0,O.useState)(``),[g,_]=(0,O.useState)(``),[v,y]=(0,O.useState)(``),[b,x]=(0,O.useState)(!1),[S,C]=(0,O.useState)(null),w=(0,O.useCallback)(async()=>{if(!s.trim()){C(`Title is required`);return}if(!l){C(`Start time is required`);return}x(!0),C(null);try{let e=await i(`/api/admin/calendar/meetings`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({title:s.trim(),startsAt:Z(l,r),endsAt:d?Z(d,r):null,location:m.trim()||null,description:g.trim()||null,privateNote:v.trim()||null})}),t=await e.json();if(!e.ok){C(t.error??`Create failed (HTTP ${e.status})`);return}t.meeting&&o(t.meeting)}catch(e){C(e instanceof Error?e.message:`Create failed`)}finally{x(!1)}},[s,l,d,m,g,v,r,i,o]);return(0,J.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{b||a()},children:(0,J.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":`Add meeting`,onClick:e=>e.stopPropagation(),children:[(0,J.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,J.jsx)(`span`,{className:`cal-modal-kind`,children:`New meeting`}),(0,J.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:a,"aria-label":`Close`,disabled:b,children:(0,J.jsx)(f,{size:16})})]}),(0,J.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,J.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,J.jsx)(`span`,{children:`Title`}),(0,J.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(e.target.value),disabled:b,autoFocus:!0})]}),(0,J.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,J.jsx)(`span`,{children:`Starts`}),(0,J.jsx)(`input`,{type:`datetime-local`,value:l,onChange:e=>u(e.target.value),disabled:b})]}),(0,J.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,J.jsx)(`span`,{children:`Ends`}),(0,J.jsx)(`input`,{type:`datetime-local`,value:d,onChange:e=>p(e.target.value),disabled:b})]}),(0,J.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,J.jsx)(`span`,{children:`Location`}),(0,J.jsx)(`input`,{type:`text`,value:m,onChange:e=>h(e.target.value),disabled:b})]}),(0,J.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,J.jsx)(`span`,{children:`Description`}),(0,J.jsx)(`textarea`,{value:g,onChange:e=>_(e.target.value),disabled:b,rows:3})]}),(0,J.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,J.jsx)(`span`,{children:`Private note`}),(0,J.jsx)(`textarea`,{value:v,onChange:e=>y(e.target.value),disabled:b,rows:2})]}),S&&(0,J.jsx)(`div`,{className:`cal-modal-error`,children:S})]}),(0,J.jsxs)(`div`,{className:`cal-modal-actions`,children:[(0,J.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:a,disabled:b,children:`Cancel`}),(0,J.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-primary`,onClick:w,disabled:b,children:[b?(0,J.jsx)(t,{size:14,className:`spin`}):null,` Create`]})]})]})})}var ye=8;function be(e,t){return t?{op:`view-census`,range:e,nodes:t.nodes.length,clippedV:t.nodes.filter(e=>e.clippedV).length,clippedH:t.nodes.filter(e=>e.clippedH).length,hidden:t.hidden,fields:t.fields.length>0?t.fields.join(`,`):`-`,minBlockPx:t.minBlockPx??`-`,lineBoxPx:t.lineBoxPx??`-`,gapSource:t.gapSource??`-`,gaps:t.gaps??`-`,shownKinds:t.shownKinds??`-`,hiddenKinds:t.hiddenKinds??`-`,zone:t.zone??`-`,zoneSource:t.zoneSource??`-`,descrRows:t.descrRows??`-`,source:`measured`}:{op:`view-census`,range:e,nodes:`-`,clippedV:`-`,clippedH:`-`,hidden:`-`,fields:`-`,minBlockPx:`-`,lineBoxPx:`-`,gapSource:`-`,gaps:`-`,shownKinds:`-`,hiddenKinds:`-`,zone:`-`,zoneSource:`-`,descrRows:`-`,source:`unavailable`}}var xe=5;function Se(e,t){if(!t)return[];let n=[];for(let r of t.nodes)for(let t of[`v`,`h`])(t===`v`?r.clippedV:r.clippedH)&&n.push({op:`node-clipped`,view:e,meetingId:r.meetingId,axis:t,renderedPx:r.renderedPx,neededPx:r.neededPx,durationMin:r.durationMin??`-`});if(n.length<=xe)return n;let r=n.slice(0,xe);return r[r.length-1]={...r[r.length-1],truncated:n.length-xe},r}function Ce(e){let t=(e.textContent??``).length;if(t===0||e.scrollWidth===0||e.clientWidth>=e.scrollWidth-1)return!0;let n=e.scrollWidth/t;return e.clientWidth/n>=ye}function we(e){if(!e||typeof window>`u`||typeof window.getComputedStyle!=`function`)return null;let t=Array.from(e.querySelectorAll(`[data-meeting-id]`)),n=t.map(e=>e.getBoundingClientRect());if(t.length>0&&n.every(e=>e.height===0&&e.width===0))return null;let r=t.length>0?parseFloat(window.getComputedStyle(t[0]).lineHeight):null,i=t.map((e,t)=>{let r=e.querySelector(`.cal-sched-title`),i=e.querySelector(`.cal-event-title`)??r??e,a=i.scrollWidth>i.clientWidth+1,o=e.getAttribute(`data-duration-min`);return{meetingId:e.getAttribute(`data-meeting-id`)??`unknown`,clippedV:e.scrollHeight>e.clientHeight+1,clippedH:r?a:a&&!Ce(i),durationMin:o?Number(o):null,renderedPx:Math.round(n[t].height*10)/10,neededPx:Math.round(e.scrollHeight*10)/10}}),a=[];e.querySelector(`.cal-event-title, .cal-chip, .cal-sched-title`)&&a.push(`title`),e.querySelector(`.cal-event-time, .cal-sched-time`)&&a.push(`time`),e.querySelector(`.cal-sched-meta`)&&a.push(`meta`);let o=0;for(let t of Array.from(e.querySelectorAll(`.cal-more`)))o+=Number(t.getAttribute(`data-hidden-count`)??0);return{nodes:i,hidden:o,fields:a,minBlockPx:i.length>0?Math.min(...i.map(e=>e.renderedPx)):null,lineBoxPx:Number.isFinite(r)?r:null}}function Te(e,t){return{op:`detail-open`,descrPayload:e?1:0,descrShown:t?1:0}}function Ee(e){try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`event`,source:`calendar-legibility`,...e}),keepalive:!0}).catch(()=>{})}catch{}}function De(e,t){for(let n of[be(e,t),...Se(e,t)])Ee(n)}function Q(e){return Math.floor(new Date(e).getTime()/6e4)}function Oe(e){if(!e)return null;let t=e.match(/filename="([^"]+)"/);return t?t[1]:null}function ke({meeting:e,zone:n,adminFetch:i,onClose:a,onSaved:c,onDeleted:l}){let u=e.kind===`meeting`,[d,p]=(0,O.useState)(!1),[h,g]=(0,O.useState)(!1),[_,v]=(0,O.useState)(!1),[y,D]=(0,O.useState)(!1),[k,A]=(0,O.useState)(null),[j,M]=(0,O.useState)(e),[N,P]=(0,O.useState)(e.title??``),[F,ee]=(0,O.useState)(X(e.startsAt,n)),[I,L]=(0,O.useState)(e.endsAt?X(e.endsAt,n):``),[R,z]=(0,O.useState)(e.location??``),[B,V]=(0,O.useState)(e.description??``),[H,U]=(0,O.useState)(e.privateNote??``),[W,G]=(0,O.useState)(``),[K,te]=(0,O.useState)(``);(0,O.useLayoutEffect)(()=>{Ee(Te((j.description??``).trim().length>0,document.querySelector(`[data-testid="cal-descr"]`)!==null))},[j.meetingId,j.description]),(0,O.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!y&&a()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[y,a]);let q=(0,O.useCallback)(()=>{let e={},t=N.trim();t!==(j.title??``)&&(e.title=t);let r=Z(F,n);Q(r)!==Q(j.startsAt)&&(e.startsAt=r);let i=I?Z(I,n):null;(i===null?j.endsAt!==null:j.endsAt===null||Q(i)!==Q(j.endsAt))&&(e.endsAt=i);let a=R.trim()||null;a!==(j.location??null)&&(e.location=a);let o=B.trim()||null;o!==(j.description??null)&&(e.description=o);let s=H.trim()||null;return s!==(j.privateNote??null)&&(e.privateNote=s),e},[N,F,I,R,B,H,j,n]),ne=(0,O.useCallback)(async()=>{let t=q();if(Object.keys(t).length===0){p(!1);return}D(!0),A(null);try{let n=await i(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(t)});if(!n.ok)throw Error(`HTTP ${n.status}`);let r=await n.json();M(r.meeting),c(r.meeting),p(!1)}catch(e){A(e instanceof Error?e.message:`Save failed`)}finally{D(!1)}},[i,q,e.meetingId,c]),re=(0,O.useCallback)(async()=>{let t=W.trim(),n=K.trim();if(!(!t&&!n)){D(!0),A(null);try{let r=await i(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}/attendees`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:t||void 0,email:n||void 0})});if(!r.ok)throw Error(`HTTP ${r.status}`);let a=await r.json();M(a.meeting),c(a.meeting),G(``),te(``)}catch(e){A(e instanceof Error?e.message:`Add failed`)}finally{D(!1)}}},[i,W,K,e.meetingId,c]),ie=(0,O.useCallback)(async t=>{let n=t.email?{email:t.email}:{name:t.name};D(!0),A(null);try{let t=await i(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}/attendees`,{method:`DELETE`,headers:{"content-type":`application/json`},body:JSON.stringify(n)});if(!t.ok)throw Error(`HTTP ${t.status}`);let r=await t.json();M(r.meeting),c(r.meeting)}catch(e){A(e instanceof Error?e.message:`Remove failed`)}finally{D(!1)}},[i,e.meetingId,c]),oe=(0,O.useCallback)(async()=>{D(!0),A(null);try{let t=await i(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}`,{method:`DELETE`});if(!t.ok)throw Error(`HTTP ${t.status}`);l(e.meetingId)}catch(e){A(e instanceof Error?e.message:`Delete failed`),D(!1)}},[i,e.meetingId,l]),Y=(0,O.useCallback)(async t=>{v(!1),D(!0),A(null);try{let n=await i(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}/ics?attendees=${t?`1`:`0`}`);if(!n.ok)throw Error(`HTTP ${n.status}`);let r=await n.blob(),a=Oe(n.headers.get(`content-disposition`))??`meeting.ics`,o=URL.createObjectURL(r),s=document.createElement(`a`);s.href=o,s.download=a,document.body.appendChild(s),s.click(),s.remove(),URL.revokeObjectURL(o)}catch(e){A(e instanceof Error?e.message:`Download failed`)}finally{D(!1)}},[i,e.meetingId]),se=ae[e.kind??`meeting`],ue=W.trim().length>0||K.trim().length>0;return(0,J.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{y||a()},children:(0,J.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":d?`Edit meeting`:`Meeting detail`,onClick:e=>e.stopPropagation(),children:[(0,J.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,J.jsx)(`span`,{className:`cal-modal-kind`,children:se}),(0,J.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:a,"aria-label":`Close`,autoFocus:!0,disabled:y,children:(0,J.jsx)(f,{size:16})})]}),!d&&(0,J.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,J.jsx)(`div`,{className:`cal-modal-title`,children:j.title??`Untitled`}),(0,J.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,J.jsx)(b,{size:14}),(0,J.jsx)(`span`,{children:ce(j,n)})]}),j.timezone&&j.timezone!==n&&(0,J.jsxs)(`div`,{className:`cal-modal-row cal-modal-zone`,"data-testid":`cal-row-zone`,children:[(0,J.jsx)(o,{size:14}),(0,J.jsxs)(`span`,{children:[`Created in `,j.timezone]})]}),j.description&&(0,J.jsxs)(`div`,{className:`cal-modal-row cal-modal-row-top`,"data-testid":`cal-descr`,children:[(0,J.jsx)(x,{size:14}),(0,J.jsx)(`span`,{className:`cal-modal-descr`,children:j.description})]}),j.location&&(0,J.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,J.jsx)(C,{size:14}),(0,J.jsx)(`span`,{children:j.location})]}),j.attendees.length>0&&(0,J.jsxs)(`div`,{className:`cal-modal-row cal-modal-row-top`,children:[(0,J.jsx)(E,{size:14}),(0,J.jsx)(`div`,{className:`cal-modal-attendees`,children:j.attendees.map((e,t)=>(0,J.jsx)(`div`,{className:`cal-attendee-row`,children:(0,J.jsx)(de,{a:e})},le(e,t)))})]}),j.privateNote&&(0,J.jsxs)(`div`,{className:`cal-modal-row cal-modal-row-top`,children:[(0,J.jsx)(w,{size:14}),(0,J.jsx)(`span`,{className:`cal-modal-note`,children:j.privateNote})]}),(0,J.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,J.jsx)(S,{size:14}),(0,J.jsx)(`span`,{children:se})]})]}),d&&(0,J.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,J.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,J.jsx)(`span`,{children:`Title`}),(0,J.jsx)(`input`,{type:`text`,value:N,onChange:e=>P(e.target.value),disabled:y})]}),(0,J.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,J.jsx)(`span`,{children:`Start`}),(0,J.jsx)(`input`,{type:`datetime-local`,value:F,onChange:e=>ee(e.target.value),disabled:y})]}),(0,J.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,J.jsx)(`span`,{children:`End`}),(0,J.jsx)(`input`,{type:`datetime-local`,value:I,onChange:e=>L(e.target.value),disabled:y})]}),(0,J.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,J.jsx)(`span`,{children:`Location`}),(0,J.jsx)(`input`,{type:`text`,value:R,onChange:e=>z(e.target.value),disabled:y})]}),(0,J.jsxs)(`div`,{className:`cal-modal-field`,children:[(0,J.jsx)(`span`,{children:`Attendees`}),(0,J.jsxs)(`div`,{className:`cal-modal-attendees cal-modal-attendees-edit`,children:[j.attendees.length===0&&(0,J.jsx)(`div`,{className:`cal-attendee-empty`,children:`No attendees yet.`}),j.attendees.map((e,t)=>(0,J.jsxs)(`div`,{className:`cal-attendee-row cal-attendee-row-edit`,children:[(0,J.jsx)(de,{a:e}),(0,J.jsx)(`button`,{type:`button`,className:`cal-attendee-remove`,onClick:()=>ie(e),disabled:y,"aria-label":`Remove ${e.name||e.email||`attendee`}`,children:(0,J.jsx)(f,{size:13})})]},le(e,t)))]}),(0,J.jsxs)(`div`,{className:`cal-attendee-add`,children:[(0,J.jsx)(`input`,{type:`text`,placeholder:`Name`,value:W,onChange:e=>G(e.target.value),disabled:y,"aria-label":`Attendee name`}),(0,J.jsx)(`input`,{type:`email`,placeholder:`Email`,value:K,onChange:e=>te(e.target.value),disabled:y,"aria-label":`Attendee email`}),(0,J.jsx)(`button`,{type:`button`,className:`cal-modal-btn cal-attendee-add-btn`,onClick:re,disabled:y||!ue,"aria-label":`Add attendee`,children:y?(0,J.jsx)(t,{size:13,className:`spin`}):(0,J.jsx)(T,{size:13})})]})]}),(0,J.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,J.jsx)(`span`,{children:`Description`}),(0,J.jsx)(`textarea`,{className:`cal-modal-textarea`,value:B,onChange:e=>V(e.target.value),disabled:y,rows:3,placeholder:`The booking detail: who, what, how much.`})]}),(0,J.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,J.jsx)(`span`,{children:`Private note`}),(0,J.jsx)(`textarea`,{className:`cal-modal-textarea`,value:H,onChange:e=>U(e.target.value),disabled:y,rows:3,placeholder:`Only you and your team can see this.`})]})]}),k&&(0,J.jsx)(`div`,{className:`cal-modal-error`,children:k}),u&&(0,J.jsxs)(`div`,{className:`cal-modal-actions`,children:[!d&&!h&&!_&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>p(!0),disabled:y,children:[(0,J.jsx)(r,{size:14}),` Edit`]}),(0,J.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:()=>g(!0),disabled:y,children:[(0,J.jsx)(m,{size:14}),` Delete`]}),(0,J.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-download`,onClick:()=>{j.attendees.length>0?v(!0):Y(!1)},disabled:y,children:[y?(0,J.jsx)(t,{size:14,className:`spin`}):(0,J.jsx)(s,{size:14}),` Download`]})]}),_&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Include attendees in the file?`}),(0,J.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-primary`,onClick:()=>Y(!0),disabled:y,children:[y?(0,J.jsx)(t,{size:14,className:`spin`}):null,` Yes`]}),(0,J.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>Y(!1),disabled:y,children:`No`}),(0,J.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>v(!1),disabled:y,children:`Cancel`})]}),d&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-primary`,onClick:ne,disabled:y,children:[y?(0,J.jsx)(t,{size:14,className:`spin`}):null,` Save`]}),(0,J.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>{p(!1),A(null)},disabled:y,children:`Cancel`})]}),h&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Delete this meeting?`}),(0,J.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:oe,disabled:y,children:[y?(0,J.jsx)(t,{size:14,className:`spin`}):null,` Delete`]}),(0,J.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>g(!1),disabled:y,children:`Cancel`})]})]})]})})}var $=`maxy-admin-session-key`,Ae=`maxy-calendar-show-all-kinds`;function je(){let[e,t]=(0,O.useState)(null),[n,r]=(0,O.useState)(!1),[i,a]=(0,O.useState)(void 0),[o,s]=(0,O.useState)(null),[c,l]=(0,O.useState)(void 0),[u,f]=(0,O.useState)(null),[m,g]=(0,O.useState)(null),[v,y]=(0,O.useState)(null),[b,x]=(0,O.useState)(`browser`);(0,O.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem($)}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($)}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&&s(e.sessionId??null),g(e.role??null),l(e.userName===void 0?null:e.userName),f(e.avatar??null),typeof e.timezone==`string`&&e.timezone&&y(e.timezone),(e.timezoneSource===`account`||e.timezoneSource===`browser`)&&x(e.timezoneSource)}catch{}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]);let S=(0,O.useCallback)(()=>{try{sessionStorage.removeItem($)}catch{}window.location.href=`/`},[]),[C,w]=(0,O.useState)(!1),T=(0,O.useCallback)(async()=>{w(!0);try{let e=await h();if(e){try{sessionStorage.removeItem($)}catch{}window.location.href=`/`}return e}finally{w(!1)}},[]);return n?e?(0,J.jsx)(p,{cacheKey:e,surface:`calendar`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=calendar`);try{sessionStorage.removeItem($)}catch{}window.location.href=`/`},children:(0,J.jsx)(_,{cacheKey:e,businessName:i,sessionId:o,onLogout:S,onDisconnect:T,disconnecting:C,userName:c,userAvatar:u,role:m,children:(0,J.jsx)(Me,{cacheKey:e,zone:v??R(),zoneSource:b})})}):(0,J.jsx)(`div`,{className:`cal-page`,children:(0,J.jsxs)(`div`,{className:`cal-empty`,children:[(0,J.jsx)(`p`,{children:`You are not signed in.`}),(0,J.jsxs)(`p`,{children:[`Open the `,(0,J.jsx)(`a`,{href:`/`,className:`cal-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,J.jsx)(d,{surface:`gate`})}function Me({cacheKey:e,zone:n,zoneSource:r}){let{adminFetch:i,sessionRefetchNonce:o}=a({initialCacheKey:e,surface:`calendar`}),[s,l]=(0,O.useState)(te),[u,f]=(0,O.useState)(()=>new Date),[p,m]=(0,O.useState)([]),[h,_]=(0,O.useState)(!1),[b,x]=(0,O.useState)(!1),[S,C]=(0,O.useState)(null),[w,T]=(0,O.useState)(null),[E,D]=(0,O.useState)([]),[k,A]=(0,O.useState)(`none`),[j,M]=(0,O.useState)(()=>{try{return sessionStorage.getItem(Ae)===`1`}catch{return!1}}),[N,P]=(0,O.useState)(null),[F,ee]=(0,O.useState)(0),[I,L]=(0,O.useState)(null);(0,O.useEffect)(()=>{let e=!1;return i(`/api/admin/calendar/booking-link`).then(async t=>{if(e||!t.ok)return;let n=await t.json();typeof n.bookingDomain==`string`&&n.bookingDomain&&L(n.bookingDomain)}).catch(()=>{}),()=>{e=!0}},[i]),(0,O.useEffect)(()=>{let e=!1,{from:t,to:r}=U(s,u,n);return _(!0),C(null),i(`/api/admin/calendar/meetings?from=${encodeURIComponent(t.toISOString())}&to=${encodeURIComponent(r.toISOString())}`).then(async t=>{if(e)return;if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();m(Array.isArray(n.meetings)?n.meetings:[])}).catch(t=>{e||(C(t instanceof Error?t.message:`Failed to load`),m([]))}).finally(()=>{e||(_(!1),x(!0))}),()=>{e=!0}},[s,u,n,o,i]),(0,O.useEffect)(()=>{let e=!1,{from:t,to:r}=U(s,u,n);return i(`/api/admin/calendar/free-busy?from=${encodeURIComponent(t.toISOString())}&to=${encodeURIComponent(r.toISOString())}`).then(async t=>{if(e)return;if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();D(fe(Array.isArray(n.slots)?n.slots:[])),A(n.gapSource===`config`?`config`:`none`)}).catch(()=>{e||(D([]),A(`none`))}),()=>{e=!0}},[s,u,n,o,i,F]);let R=(0,O.useCallback)(()=>f(new Date),[]),z=(0,O.useCallback)(()=>f(e=>W(s,e,-1,n)),[s,n]),B=(0,O.useCallback)(()=>f(e=>W(s,e,1,n)),[s,n]),V=(0,O.useCallback)(()=>{M(e=>{let t=!e;try{sessionStorage.setItem(Ae,t?`1`:`0`)}catch{}return t})},[]),H=(0,O.useCallback)((e,t)=>P({startsAt:X(e,n),endsAt:X(t,n)}),[n]),G=(0,O.useCallback)(e=>{m(t=>[...t,e]),ee(e=>e+1),P(null)},[]);(0,O.useEffect)(()=>{T(null)},[s,u]);let q=(0,O.useRef)(null);(0,O.useEffect)(()=>{if(h)return;let e=requestAnimationFrame(()=>{let e=we(q.current);De(s,e&&{...e,zone:n,zoneSource:r,descrRows:p.filter(e=>(e.description??``).trim().length>0).length,gapSource:k,gaps:E.length,shownKinds:j?`meeting,event,task`:`meeting`,hiddenKinds:j?0:p.filter(e=>(e.kind??`meeting`)!==`meeting`).length})});return()=>cancelAnimationFrame(e)},[s,p,h,k,E,j,n,r]);let ne=(0,O.useCallback)(e=>{m(t=>t.map(t=>t.meetingId===e.meetingId?e:t)),T(e)},[]),ie=(0,O.useCallback)(e=>{m(t=>t.filter(t=>t.meetingId!==e)),T(null)},[]);return b?(0,J.jsxs)(`div`,{className:`cal-page`,children:[(0,J.jsxs)(`header`,{className:`cal-header`,children:[(0,J.jsxs)(`div`,{className:`cal-nav`,children:[(0,J.jsx)(`span`,{className:`cal-range-label`,children:re(s,u,n)}),(0,J.jsx)(`button`,{type:`button`,className:`cal-nav-btn`,onClick:z,"aria-label":`Previous`,children:(0,J.jsx)(v,{size:18})}),(0,J.jsx)(`button`,{type:`button`,className:`cal-nav-btn`,onClick:B,"aria-label":`Next`,children:(0,J.jsx)(y,{size:18})}),(0,J.jsx)(`button`,{type:`button`,className:`cal-today-btn`,onClick:R,children:`Today`}),h&&(0,J.jsx)(t,{size:16,className:`spin`})]}),(0,J.jsxs)(`button`,{type:`button`,className:`cal-add-btn`,onClick:()=>P({startsAt:``,endsAt:``}),children:[(0,J.jsx)(c,{size:14}),` Add`]}),(0,J.jsx)(`div`,{className:`cal-views`,children:K.map(e=>(0,J.jsx)(`button`,{type:`button`,className:`cal-view-btn${e===s?` cal-view-btn-active`:``}`,onClick:()=>l(e),children:e.charAt(0).toUpperCase()+e.slice(1)},e))}),I&&(0,J.jsxs)(`a`,{className:`cal-booking-link`,href:`https://${I}`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,J.jsx)(g,{size:14}),` Booking page`]})]}),(0,J.jsxs)(`div`,{className:`cal-body`,ref:q,children:[S&&(0,J.jsxs)(`div`,{className:`cal-error`,children:[`Could not load the calendar: `,S]}),(0,J.jsx)(_e,{zone:n,zoneSource:r,from:U(s,u,n).from,to:U(s,u,n).to,meetings:p,stretches:E,gapSource:k,showAllKinds:j,onToggleKinds:V,onSelect:T,onAddAt:H})]}),N&&(0,J.jsx)(ve,{zone:n,initialStart:N.startsAt,initialEnd:N.endsAt,adminFetch:i,onClose:()=>P(null),onCreated:G}),w&&(0,J.jsx)(ke,{zone:n,meeting:w,adminFetch:i,onClose:()=>T(null),onSaved:ne,onDeleted:ie})]}):(0,J.jsx)(d,{surface:`gate`})}(0,D.createRoot)(document.getElementById(`root`)).render((0,J.jsx)(je,{}));
@@ -1 +0,0 @@
1
- import{G as e,Y as t}from"./useSubAccountSwitcher-C7TtIbR3.js";import"./useVoiceRecorder-DgyAGgmF.js";import"./AdminShell-D24evn4t.js";import{n}from"./page-CpJpyoPS.js";import"./useCopyFeedback-BwK1RhmF.js";var r=t(),i=e();(0,r.createRoot)(document.getElementById(`root`)).render((0,i.jsx)(n,{}));
@@ -1 +0,0 @@
1
- import{B as e}from"./useSubAccountSwitcher-C7TtIbR3.js";var t=e(`chevron-left`,[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]);export{t};
@@ -1 +0,0 @@
1
- import{B as e}from"./useSubAccountSwitcher-C7TtIbR3.js";var t=e(`chevron-right`,[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]);export{t};
@@ -1 +0,0 @@
1
- import{B as e}from"./useSubAccountSwitcher-C7TtIbR3.js";var t=e(`clock`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6l4 2`,key:`mmk7yg`}]]);export{t};
@@ -1 +0,0 @@
1
- import{B as e}from"./useSubAccountSwitcher-C7TtIbR3.js";var t=e(`copy`,[[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]);export{t};
@@ -1 +0,0 @@
1
- import{G as e,Y as t}from"./useSubAccountSwitcher-C7TtIbR3.js";import"./useVoiceRecorder-DgyAGgmF.js";import{t as n}from"./page-D0ShNyGE.js";import"./graph-labels-CiK412vE.js";var r=t(),i=e();(0,r.createRoot)(document.getElementById(`root`)).render((0,i.jsx)(n,{}));
@@ -1 +0,0 @@
1
-  `�v��Kc�]����P(YW��KT�.?��ZlB��,� DH�s(��SX\v��|�sٶ_�]�PvK�Kpn��f���׏tl��:�
@@ -1 +0,0 @@
1
- import{B as e}from"./useSubAccountSwitcher-C7TtIbR3.js";var t=e(`file-text`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]);export{t};