@rubytech/create-sitedesk-code 0.1.519 → 0.1.521

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 (317) hide show
  1. package/package.json +1 -1
  2. package/payload/platform/docs/superpowers/plans/2026-07-28-task-2097-email-signature-set.md +65 -0
  3. package/payload/platform/docs/superpowers/specs/2026-07-28-task-2097-email-signature-set-design.md +155 -0
  4. package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +4 -2
  5. package/payload/platform/plugins/admin/skills/whats-new/SKILL.md +12 -0
  6. package/payload/platform/plugins/cloudflare/bin/portal-assemble.mjs +187 -0
  7. package/payload/platform/plugins/cloudflare/bin/portal-enrol.mjs +46 -5
  8. package/payload/platform/plugins/cloudflare/mcp/__tests__/auth-route.test.ts +19 -7
  9. package/payload/platform/plugins/cloudflare/mcp/__tests__/authorize.test.ts +154 -38
  10. package/payload/platform/plugins/cloudflare/mcp/__tests__/file-routes.test.ts +100 -29
  11. package/payload/platform/plugins/cloudflare/mcp/__tests__/portal-assemble.test.ts +143 -0
  12. package/payload/platform/plugins/cloudflare/mcp/__tests__/portal-delete-withdraw.test.ts +12 -5
  13. package/payload/platform/plugins/cloudflare/mcp/__tests__/portal-directory-listing.test.ts +15 -3
  14. package/payload/platform/plugins/cloudflare/mcp/__tests__/portal-enrol.test.ts +105 -11
  15. package/payload/platform/plugins/cloudflare/mcp/__tests__/portal-indexed-download.test.ts +15 -2
  16. package/payload/platform/plugins/cloudflare/mcp/__tests__/portal-moved-download.test.ts +9 -5
  17. package/payload/platform/plugins/cloudflare/mcp/__tests__/portal-schema-shape.test.ts +47 -5
  18. package/payload/platform/plugins/cloudflare/mcp/__tests__/portal-session-grant.test.ts +26 -2
  19. package/payload/platform/plugins/cloudflare/mcp/__tests__/portal-target.test.ts +12 -4
  20. package/payload/platform/plugins/cloudflare/mcp/__tests__/portal-upload-multipart.test.ts +23 -15
  21. package/payload/platform/plugins/cloudflare/mcp/__tests__/portal-upload-target.test.ts +23 -15
  22. package/payload/platform/plugins/cloudflare/mcp/__tests__/portal-uploads-listing.test.ts +8 -0
  23. package/payload/platform/plugins/cloudflare/mcp/__tests__/skill-contract.test.ts +23 -6
  24. package/payload/platform/plugins/cloudflare/mcp/__tests__/upload-route.test.ts +36 -20
  25. package/payload/platform/plugins/cloudflare/skills/data-portal/SKILL.md +85 -22
  26. package/payload/platform/plugins/cloudflare/skills/data-portal/schema.sql +47 -7
  27. package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/_lib/authorize.ts +27 -18
  28. package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/_lib/ratelimit.ts +10 -3
  29. package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/_lib/session.ts +27 -11
  30. package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/_lib/target.ts +18 -9
  31. package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/_lib/types.ts +16 -0
  32. package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/auth.ts +16 -4
  33. package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/delete.ts +26 -11
  34. package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/download.ts +14 -10
  35. package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/files.ts +13 -9
  36. package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/upload.ts +42 -22
  37. package/payload/platform/plugins/cloudflare/skills/data-portal/template/wrangler.toml +17 -4
  38. package/payload/platform/plugins/docs/references/admin-ui.md +1 -1
  39. package/payload/platform/plugins/email/.claude-plugin/plugin.json +1 -1
  40. package/payload/platform/plugins/email/PLUGIN.md +20 -1
  41. package/payload/platform/plugins/email/mcp/dist/__tests__/attachment-metadata-calendar.test.js +46 -1
  42. package/payload/platform/plugins/email/mcp/dist/__tests__/attachment-metadata-calendar.test.js.map +1 -1
  43. package/payload/platform/plugins/email/mcp/dist/__tests__/email-draft-list-tool.test.d.ts +2 -0
  44. package/payload/platform/plugins/email/mcp/dist/__tests__/email-draft-list-tool.test.d.ts.map +1 -0
  45. package/payload/platform/plugins/email/mcp/dist/__tests__/email-draft-list-tool.test.js +142 -0
  46. package/payload/platform/plugins/email/mcp/dist/__tests__/email-draft-list-tool.test.js.map +1 -0
  47. package/payload/platform/plugins/email/mcp/dist/__tests__/email-draft-list.test.d.ts +2 -0
  48. package/payload/platform/plugins/email/mcp/dist/__tests__/email-draft-list.test.d.ts.map +1 -0
  49. package/payload/platform/plugins/email/mcp/dist/__tests__/email-draft-list.test.js +153 -0
  50. package/payload/platform/plugins/email/mcp/dist/__tests__/email-draft-list.test.js.map +1 -0
  51. package/payload/platform/plugins/email/mcp/dist/__tests__/email-signature-set.test.d.ts +2 -0
  52. package/payload/platform/plugins/email/mcp/dist/__tests__/email-signature-set.test.d.ts.map +1 -0
  53. package/payload/platform/plugins/email/mcp/dist/__tests__/email-signature-set.test.js +203 -0
  54. package/payload/platform/plugins/email/mcp/dist/__tests__/email-signature-set.test.js.map +1 -0
  55. package/payload/platform/plugins/email/mcp/dist/index.js +69 -0
  56. package/payload/platform/plugins/email/mcp/dist/index.js.map +1 -1
  57. package/payload/platform/plugins/email/mcp/dist/lib/compose.d.ts.map +1 -1
  58. package/payload/platform/plugins/email/mcp/dist/lib/compose.js +5 -7
  59. package/payload/platform/plugins/email/mcp/dist/lib/compose.js.map +1 -1
  60. package/payload/platform/plugins/email/mcp/dist/lib/imap.d.ts +56 -0
  61. package/payload/platform/plugins/email/mcp/dist/lib/imap.d.ts.map +1 -1
  62. package/payload/platform/plugins/email/mcp/dist/lib/imap.js +111 -4
  63. package/payload/platform/plugins/email/mcp/dist/lib/imap.js.map +1 -1
  64. package/payload/platform/plugins/email/mcp/dist/lib/signature.d.ts +38 -0
  65. package/payload/platform/plugins/email/mcp/dist/lib/signature.d.ts.map +1 -1
  66. package/payload/platform/plugins/email/mcp/dist/lib/signature.js +67 -2
  67. package/payload/platform/plugins/email/mcp/dist/lib/signature.js.map +1 -1
  68. package/payload/platform/plugins/email/mcp/dist/tools/email-draft-list.d.ts +10 -0
  69. package/payload/platform/plugins/email/mcp/dist/tools/email-draft-list.d.ts.map +1 -0
  70. package/payload/platform/plugins/email/mcp/dist/tools/email-draft-list.js +73 -0
  71. package/payload/platform/plugins/email/mcp/dist/tools/email-draft-list.js.map +1 -0
  72. package/payload/platform/plugins/email/mcp/dist/tools/email-signature-set.d.ts +18 -0
  73. package/payload/platform/plugins/email/mcp/dist/tools/email-signature-set.d.ts.map +1 -0
  74. package/payload/platform/plugins/email/mcp/dist/tools/email-signature-set.js +38 -0
  75. package/payload/platform/plugins/email/mcp/dist/tools/email-signature-set.js.map +1 -0
  76. package/payload/platform/plugins/email/references/email-reference.md +15 -3
  77. package/payload/platform/plugins/email/skills/email-composition/SKILL.md +10 -0
  78. package/payload/platform/plugins/email/skills/email-signature/SKILL.md +61 -0
  79. package/payload/platform/plugins/scheduling/PLUGIN.md +8 -0
  80. package/payload/platform/plugins/scheduling/mcp/dist/index.js +26 -15
  81. package/payload/platform/plugins/scheduling/mcp/dist/index.js.map +1 -1
  82. package/payload/platform/plugins/scheduling/mcp/dist/lib/__tests__/schedule-audit.test.d.ts +2 -0
  83. package/payload/platform/plugins/scheduling/mcp/dist/lib/__tests__/schedule-audit.test.d.ts.map +1 -0
  84. package/payload/platform/plugins/scheduling/mcp/dist/lib/__tests__/schedule-audit.test.js +48 -0
  85. package/payload/platform/plugins/scheduling/mcp/dist/lib/__tests__/schedule-audit.test.js.map +1 -0
  86. package/payload/platform/plugins/scheduling/mcp/dist/lib/schedule-audit.d.ts +24 -0
  87. package/payload/platform/plugins/scheduling/mcp/dist/lib/schedule-audit.d.ts.map +1 -0
  88. package/payload/platform/plugins/scheduling/mcp/dist/lib/schedule-audit.js +33 -0
  89. package/payload/platform/plugins/scheduling/mcp/dist/lib/schedule-audit.js.map +1 -0
  90. package/payload/platform/plugins/scheduling/mcp/dist/scripts/reconcile-bookings.js +22 -1
  91. package/payload/platform/plugins/scheduling/mcp/dist/scripts/reconcile-bookings.js.map +1 -1
  92. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-cancel-meeting.test.d.ts +2 -0
  93. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-cancel-meeting.test.d.ts.map +1 -0
  94. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-cancel-meeting.test.js +30 -0
  95. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-cancel-meeting.test.js.map +1 -0
  96. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-get-meeting.test.d.ts +2 -0
  97. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-get-meeting.test.d.ts.map +1 -0
  98. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-get-meeting.test.js +43 -0
  99. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-get-meeting.test.js.map +1 -0
  100. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-list.test.d.ts +2 -0
  101. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-list.test.d.ts.map +1 -0
  102. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-list.test.js +87 -0
  103. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-list.test.js.map +1 -0
  104. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-update-meeting.test.d.ts +2 -0
  105. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-update-meeting.test.d.ts.map +1 -0
  106. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-update-meeting.test.js +48 -0
  107. package/payload/platform/plugins/scheduling/mcp/dist/tools/__tests__/schedule-update-meeting.test.js.map +1 -0
  108. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-cancel.d.ts.map +1 -1
  109. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-cancel.js +14 -1
  110. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-cancel.js.map +1 -1
  111. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-get.d.ts +4 -1
  112. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-get.d.ts.map +1 -1
  113. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-get.js +39 -2
  114. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-get.js.map +1 -1
  115. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-list.d.ts +4 -1
  116. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-list.d.ts.map +1 -1
  117. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-list.js +50 -1
  118. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-list.js.map +1 -1
  119. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-update.d.ts.map +1 -1
  120. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-update.js +43 -1
  121. package/payload/platform/plugins/scheduling/mcp/dist/tools/schedule-update.js.map +1 -1
  122. package/payload/platform/plugins/whatsapp/references/channels-whatsapp.md +3 -1
  123. package/payload/platform/scripts/check-architecture-skill-no-drift.mjs +20 -6
  124. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.d.ts.map +1 -1
  125. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js +2 -0
  126. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js.map +1 -1
  127. package/payload/platform/services/whatsapp-channel/dist/notification.d.ts +17 -5
  128. package/payload/platform/services/whatsapp-channel/dist/notification.d.ts.map +1 -1
  129. package/payload/platform/services/whatsapp-channel/dist/notification.js +30 -6
  130. package/payload/platform/services/whatsapp-channel/dist/notification.js.map +1 -1
  131. package/payload/platform/services/whatsapp-channel/dist/server.d.ts.map +1 -1
  132. package/payload/platform/services/whatsapp-channel/dist/server.js +53 -21
  133. package/payload/platform/services/whatsapp-channel/dist/server.js.map +1 -1
  134. package/payload/platform/services/whatsapp-channel/dist/turn-follow.d.ts +16 -0
  135. package/payload/platform/services/whatsapp-channel/dist/turn-follow.d.ts.map +1 -1
  136. package/payload/platform/services/whatsapp-channel/dist/turn-follow.js +41 -2
  137. package/payload/platform/services/whatsapp-channel/dist/turn-follow.js.map +1 -1
  138. package/payload/platform/templates/specialists/agents/personal-assistant.md +1 -1
  139. package/payload/server/{chunk-TIIWMF5G.js → chunk-AZLT4LVO.js} +40 -7
  140. package/payload/server/{manager-B6OFOXSW.js → manager-CQBSUJXR.js} +1 -1
  141. package/payload/server/public/activity.html +5 -5
  142. package/payload/server/public/agents.html +4 -4
  143. package/payload/server/public/assets/AdminLoginScreens-Dar_MMJm.js +1 -0
  144. package/payload/server/public/assets/AdminLoginScreens-Dar_MMJm.js.br +0 -0
  145. package/payload/server/public/assets/AdminLoginScreens-Dar_MMJm.js.gz +0 -0
  146. package/payload/server/public/assets/AdminShell-CpaI2F_p.js +2 -0
  147. package/payload/server/public/assets/AdminShell-CpaI2F_p.js.br +0 -0
  148. package/payload/server/public/assets/AdminShell-CpaI2F_p.js.gz +0 -0
  149. package/payload/server/public/assets/{activity-DOsfKzT3.js → activity-B1rt4GIy.js} +1 -1
  150. package/payload/server/public/assets/activity-B1rt4GIy.js.br +0 -0
  151. package/payload/server/public/assets/activity-B1rt4GIy.js.gz +0 -0
  152. package/payload/server/public/assets/admin-DE3lLNje.js +1 -0
  153. package/payload/server/public/assets/admin-DE3lLNje.js.br +0 -0
  154. package/payload/server/public/assets/admin-DE3lLNje.js.gz +0 -0
  155. package/payload/server/public/assets/{agents-DqDnZTH_.js → agents-BXq8woVf.js} +1 -1
  156. package/payload/server/public/assets/agents-BXq8woVf.js.br +0 -0
  157. package/payload/server/public/assets/agents-BXq8woVf.js.gz +0 -0
  158. package/payload/server/public/assets/{browser-FL17Dfp0.js → browser-1QSCPl3X.js} +1 -1
  159. package/payload/server/public/assets/browser-1QSCPl3X.js.br +0 -0
  160. package/payload/server/public/assets/browser-1QSCPl3X.js.gz +0 -0
  161. package/payload/server/public/assets/{calendar-CLfLvsnV.js → calendar-D009qWVV.js} +1 -1
  162. package/payload/server/public/assets/calendar-D009qWVV.js.br +0 -0
  163. package/payload/server/public/assets/calendar-D009qWVV.js.gz +0 -0
  164. package/payload/server/public/assets/chat-CUg1fTqJ.js +1 -0
  165. package/payload/server/public/assets/chat-CUg1fTqJ.js.br +1 -0
  166. package/payload/server/public/assets/chat-CUg1fTqJ.js.gz +0 -0
  167. package/payload/server/public/assets/chevron-left-C2JEy7uU.js +1 -0
  168. package/payload/server/public/assets/chevron-left-C2JEy7uU.js.br +0 -0
  169. package/payload/server/public/assets/chevron-right-DWa047Ys.js +1 -0
  170. package/payload/server/public/assets/chevron-right-DWa047Ys.js.br +0 -0
  171. package/payload/server/public/assets/clock-C3OqfCnn.js +1 -0
  172. package/payload/server/public/assets/clock-C3OqfCnn.js.br +0 -0
  173. package/payload/server/public/assets/clock-C3OqfCnn.js.gz +0 -0
  174. package/payload/server/public/assets/data-Bu_yCScC.js +1 -0
  175. package/payload/server/public/assets/data-Bu_yCScC.js.br +0 -0
  176. package/payload/server/public/assets/data-Bu_yCScC.js.gz +0 -0
  177. package/payload/server/public/assets/{file-text-DNm0AzUz.js → file-text-DwGAfCsd.js} +1 -1
  178. package/payload/server/public/assets/file-text-DwGAfCsd.js.br +0 -0
  179. package/payload/server/public/assets/file-text-DwGAfCsd.js.gz +0 -0
  180. package/payload/server/public/assets/{graph-fAvmlVzh.js → graph-D-DGlfhW.js} +2 -2
  181. package/payload/server/public/assets/graph-D-DGlfhW.js.br +0 -0
  182. package/payload/server/public/assets/graph-D-DGlfhW.js.gz +0 -0
  183. package/payload/server/public/assets/{graph-labels-CwdkCxfs.js → graph-labels-BbX3fXzl.js} +1 -1
  184. package/payload/server/public/assets/graph-labels-BbX3fXzl.js.br +0 -0
  185. package/payload/server/public/assets/graph-labels-BbX3fXzl.js.gz +0 -0
  186. package/payload/server/public/assets/{maximize-2-B6tAPhC2.js → maximize-2-C_-KapxH.js} +1 -1
  187. package/payload/server/public/assets/maximize-2-C_-KapxH.js.br +0 -0
  188. package/payload/server/public/assets/maximize-2-C_-KapxH.js.gz +0 -0
  189. package/payload/server/public/assets/{operator-CTKvBVjk.js → operator-CFrZVcv6.js} +1 -1
  190. package/payload/server/public/assets/operator-CFrZVcv6.js.br +0 -0
  191. package/payload/server/public/assets/operator-CFrZVcv6.js.gz +0 -0
  192. package/payload/server/public/assets/{page-O5HkHQw4.js → page-CHt62f1_.js} +1 -1
  193. package/payload/server/public/assets/page-CHt62f1_.js.br +0 -0
  194. package/payload/server/public/assets/page-CHt62f1_.js.gz +0 -0
  195. package/payload/server/public/assets/page-E74MYB18.js +32 -0
  196. package/payload/server/public/assets/page-E74MYB18.js.br +0 -0
  197. package/payload/server/public/assets/page-E74MYB18.js.gz +0 -0
  198. package/payload/server/public/assets/{public-BF1rnVPa.js → public-CI6K1sNW.js} +1 -1
  199. package/payload/server/public/assets/public-CI6K1sNW.js.br +0 -0
  200. package/payload/server/public/assets/public-CI6K1sNW.js.gz +0 -0
  201. package/payload/server/public/assets/{rotate-ccw-B8TqfCy4.js → rotate-ccw-PWu_QGrD.js} +1 -1
  202. package/payload/server/public/assets/rotate-ccw-PWu_QGrD.js.br +0 -0
  203. package/payload/server/public/assets/rotate-ccw-PWu_QGrD.js.gz +0 -0
  204. package/payload/server/public/assets/routines-Cp3_XS7S.js +1 -0
  205. package/payload/server/public/assets/routines-Cp3_XS7S.js.br +0 -0
  206. package/payload/server/public/assets/routines-Cp3_XS7S.js.gz +0 -0
  207. package/payload/server/public/assets/skills-g8HvunPA.js +1 -0
  208. package/payload/server/public/assets/skills-g8HvunPA.js.br +0 -0
  209. package/payload/server/public/assets/skills-g8HvunPA.js.gz +0 -0
  210. package/payload/server/public/assets/{tasks-DePyOrRk.js → tasks-CMC_jDVm.js} +1 -1
  211. package/payload/server/public/assets/tasks-CMC_jDVm.js.br +0 -0
  212. package/payload/server/public/assets/tasks-CMC_jDVm.js.gz +0 -0
  213. package/payload/server/public/assets/{time-entry-format-D9gtnG01.js → time-entry-format-BXWuQ6Sw.js} +1 -1
  214. package/payload/server/public/assets/time-entry-format-BXWuQ6Sw.js.br +2 -0
  215. package/payload/server/public/assets/time-entry-format-BXWuQ6Sw.js.gz +0 -0
  216. package/payload/server/public/assets/{triangle-alert-DAtm2mLL.js → triangle-alert-BNshRC13.js} +1 -1
  217. package/payload/server/public/assets/triangle-alert-BNshRC13.js.br +0 -0
  218. package/payload/server/public/assets/triangle-alert-BNshRC13.js.gz +0 -0
  219. package/payload/server/public/assets/{useCopyFeedback-uMJT-p6i.js → useCopyFeedback-CwTZ9DqH.js} +1 -1
  220. package/payload/server/public/assets/useCopyFeedback-CwTZ9DqH.js.br +0 -0
  221. package/payload/server/public/assets/useCopyFeedback-CwTZ9DqH.js.gz +0 -0
  222. package/payload/server/public/assets/useSubAccountSwitcher-BuUYMDWl.js +14 -0
  223. package/payload/server/public/assets/useSubAccountSwitcher-BuUYMDWl.js.br +0 -0
  224. package/payload/server/public/assets/useSubAccountSwitcher-BuUYMDWl.js.gz +0 -0
  225. package/payload/server/public/assets/useSubAccountSwitcher-dzDnmWq9.css +1 -0
  226. package/payload/server/public/assets/useSubAccountSwitcher-dzDnmWq9.css.br +0 -0
  227. package/payload/server/public/assets/useSubAccountSwitcher-dzDnmWq9.css.gz +0 -0
  228. package/payload/server/public/assets/{useVoiceRecorder-BFrPC-s7.js → useVoiceRecorder-BGqV5R6u.js} +1 -1
  229. package/payload/server/public/assets/useVoiceRecorder-BGqV5R6u.js.br +0 -0
  230. package/payload/server/public/assets/useVoiceRecorder-BGqV5R6u.js.gz +0 -0
  231. package/payload/server/public/assets/{wrench-CYgaN7K9.js → wrench-DQ045Pyk.js} +1 -1
  232. package/payload/server/public/assets/wrench-DQ045Pyk.js.br +0 -0
  233. package/payload/server/public/assets/wrench-DQ045Pyk.js.gz +0 -0
  234. package/payload/server/public/browser.html +4 -4
  235. package/payload/server/public/calendar.html +7 -7
  236. package/payload/server/public/chat.html +13 -13
  237. package/payload/server/public/data.html +11 -11
  238. package/payload/server/public/graph.html +9 -9
  239. package/payload/server/public/index.html +14 -14
  240. package/payload/server/public/operator.html +14 -14
  241. package/payload/server/public/public.html +13 -13
  242. package/payload/server/public/routines.html +6 -6
  243. package/payload/server/public/skills.html +5 -5
  244. package/payload/server/public/tasks.html +6 -6
  245. package/payload/server/server.js +687 -400
  246. package/payload/server/public/assets/AdminLoginScreens-BZPbCk8g.js +0 -1
  247. package/payload/server/public/assets/AdminLoginScreens-BZPbCk8g.js.br +0 -0
  248. package/payload/server/public/assets/AdminLoginScreens-BZPbCk8g.js.gz +0 -0
  249. package/payload/server/public/assets/AdminShell-Bpo_wgxm.js +0 -2
  250. package/payload/server/public/assets/AdminShell-Bpo_wgxm.js.br +0 -0
  251. package/payload/server/public/assets/AdminShell-Bpo_wgxm.js.gz +0 -0
  252. package/payload/server/public/assets/activity-DOsfKzT3.js.br +0 -0
  253. package/payload/server/public/assets/activity-DOsfKzT3.js.gz +0 -0
  254. package/payload/server/public/assets/admin-COgD1z5a.js +0 -1
  255. package/payload/server/public/assets/admin-COgD1z5a.js.br +0 -0
  256. package/payload/server/public/assets/admin-COgD1z5a.js.gz +0 -0
  257. package/payload/server/public/assets/agents-DqDnZTH_.js.br +0 -0
  258. package/payload/server/public/assets/agents-DqDnZTH_.js.gz +0 -0
  259. package/payload/server/public/assets/browser-FL17Dfp0.js.br +0 -0
  260. package/payload/server/public/assets/browser-FL17Dfp0.js.gz +0 -0
  261. package/payload/server/public/assets/calendar-CLfLvsnV.js.br +0 -0
  262. package/payload/server/public/assets/calendar-CLfLvsnV.js.gz +0 -0
  263. package/payload/server/public/assets/chat-DYq4FxMG.js +0 -1
  264. package/payload/server/public/assets/chat-DYq4FxMG.js.br +0 -0
  265. package/payload/server/public/assets/chat-DYq4FxMG.js.gz +0 -0
  266. package/payload/server/public/assets/chevron-left-DWt5cdUo.js +0 -1
  267. package/payload/server/public/assets/chevron-right-B9suVrYy.js +0 -1
  268. package/payload/server/public/assets/chevron-right-B9suVrYy.js.br +0 -0
  269. package/payload/server/public/assets/clock-DW6qVXtv.js +0 -1
  270. package/payload/server/public/assets/clock-DW6qVXtv.js.br +0 -0
  271. package/payload/server/public/assets/clock-DW6qVXtv.js.gz +0 -0
  272. package/payload/server/public/assets/data-C8rbOgds.js +0 -1
  273. package/payload/server/public/assets/data-C8rbOgds.js.br +0 -0
  274. package/payload/server/public/assets/data-C8rbOgds.js.gz +0 -0
  275. package/payload/server/public/assets/file-text-DNm0AzUz.js.br +0 -0
  276. package/payload/server/public/assets/file-text-DNm0AzUz.js.gz +0 -0
  277. package/payload/server/public/assets/graph-fAvmlVzh.js.br +0 -0
  278. package/payload/server/public/assets/graph-fAvmlVzh.js.gz +0 -0
  279. package/payload/server/public/assets/graph-labels-CwdkCxfs.js.br +0 -0
  280. package/payload/server/public/assets/graph-labels-CwdkCxfs.js.gz +0 -0
  281. package/payload/server/public/assets/maximize-2-B6tAPhC2.js.br +0 -0
  282. package/payload/server/public/assets/maximize-2-B6tAPhC2.js.gz +0 -0
  283. package/payload/server/public/assets/operator-CTKvBVjk.js.br +0 -0
  284. package/payload/server/public/assets/operator-CTKvBVjk.js.gz +0 -0
  285. package/payload/server/public/assets/page-BWoNW3sa.js +0 -32
  286. package/payload/server/public/assets/page-BWoNW3sa.js.br +0 -0
  287. package/payload/server/public/assets/page-BWoNW3sa.js.gz +0 -0
  288. package/payload/server/public/assets/page-O5HkHQw4.js.br +0 -0
  289. package/payload/server/public/assets/page-O5HkHQw4.js.gz +0 -0
  290. package/payload/server/public/assets/public-BF1rnVPa.js.br +0 -0
  291. package/payload/server/public/assets/public-BF1rnVPa.js.gz +0 -0
  292. package/payload/server/public/assets/rotate-ccw-B8TqfCy4.js.br +0 -0
  293. package/payload/server/public/assets/rotate-ccw-B8TqfCy4.js.gz +0 -0
  294. package/payload/server/public/assets/routines-4R7BLZyH.js +0 -1
  295. package/payload/server/public/assets/routines-4R7BLZyH.js.br +0 -0
  296. package/payload/server/public/assets/routines-4R7BLZyH.js.gz +0 -0
  297. package/payload/server/public/assets/skills-CQ9Qs2tg.js +0 -1
  298. package/payload/server/public/assets/skills-CQ9Qs2tg.js.br +0 -0
  299. package/payload/server/public/assets/skills-CQ9Qs2tg.js.gz +0 -0
  300. package/payload/server/public/assets/tasks-DePyOrRk.js.br +0 -0
  301. package/payload/server/public/assets/tasks-DePyOrRk.js.gz +0 -0
  302. package/payload/server/public/assets/time-entry-format-D9gtnG01.js.br +0 -0
  303. package/payload/server/public/assets/time-entry-format-D9gtnG01.js.gz +0 -0
  304. package/payload/server/public/assets/triangle-alert-DAtm2mLL.js.br +0 -0
  305. package/payload/server/public/assets/triangle-alert-DAtm2mLL.js.gz +0 -0
  306. package/payload/server/public/assets/useCopyFeedback-uMJT-p6i.js.br +0 -0
  307. package/payload/server/public/assets/useCopyFeedback-uMJT-p6i.js.gz +0 -0
  308. package/payload/server/public/assets/useSubAccountSwitcher-BufCPDDH.js +0 -14
  309. package/payload/server/public/assets/useSubAccountSwitcher-BufCPDDH.js.br +0 -0
  310. package/payload/server/public/assets/useSubAccountSwitcher-BufCPDDH.js.gz +0 -0
  311. package/payload/server/public/assets/useSubAccountSwitcher-iCzsV96x.css +0 -1
  312. package/payload/server/public/assets/useSubAccountSwitcher-iCzsV96x.css.br +0 -0
  313. package/payload/server/public/assets/useSubAccountSwitcher-iCzsV96x.css.gz +0 -0
  314. package/payload/server/public/assets/useVoiceRecorder-BFrPC-s7.js.br +0 -0
  315. package/payload/server/public/assets/useVoiceRecorder-BFrPC-s7.js.gz +0 -0
  316. package/payload/server/public/assets/wrench-CYgaN7K9.js.br +0 -1
  317. package/payload/server/public/assets/wrench-CYgaN7K9.js.gz +0 -0
@@ -0,0 +1,2 @@
1
+ import{o as e}from"./chunk-CltuBf4Z.js";import{A as t,B as n,C as r,D as i,E as a,F as o,H as s,I as c,K as l,L as u,N as d,O as f,P as p,R as m,S as h,T as g,V as _,_ as ee,a as te,d as v,f as y,g as b,h as x,j as S,k as ne,o as re,p as ie,q as ae,r as oe,t as se,v as ce,w as C,x as le,y as ue}from"./useSubAccountSwitcher-BuUYMDWl.js";async function de(){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 w=_();function fe({checked:e,onChange:t,label:n,disabled:r,ariaLabel:i=n}){return(0,w.jsxs)(`label`,{className:`maxy-checkbox${r?` maxy-checkbox--disabled`:``}`,children:[(0,w.jsx)(`input`,{type:`checkbox`,"aria-label":i,checked:e,onChange:e=>t(e.target.checked),disabled:r}),(0,w.jsx)(`span`,{className:`maxy-checkbox__box`,children:`✱`}),n&&(0,w.jsx)(`span`,{className:`maxy-checkbox__label`,children:n})]})}var T=e(ae(),1),E={sm:14,md:16,lg:18},pe={sm:30,md:38,lg:46};function D({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=E[t],g={...e===`send`?{width:pe[t],height:pe[t]}:{},...d},_=Object.keys(g).length>0;return(0,w.jsxs)(`button`,{type:s,className:m,disabled:i||o,onClick:c,"aria-label":l,"aria-pressed":u,style:_?g:void 0,children:[(0,w.jsxs)(`span`,{className:`btn__content`,style:{visibility:i?`hidden`:`visible`},children:[n&&r===`leading`&&(0,w.jsx)(n,{size:h}),p,n&&r===`trailing`&&(0,w.jsx)(n,{size:h})]}),i&&(0,w.jsx)(`span`,{className:`btn__spinner`,children:`✱`})]})}var O=5e3,k=1200;function me(e){return Math.max(k,Math.round(O/(e<1?1:e)))}var A=500,j=new Set;function he(e,t,n){let r=n??(typeof globalThis.fetch==`function`?globalThis.fetch:void 0);if(j.has(e)||!r)return!1;if(j.size>=A){for(let e of j)if(j.delete(e),j.size<A)break}j.add(e);try{Promise.resolve(r(`/api/admin/events`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({event:`wa-notify:rendered`,fields:{msgId:e,senderType:t}})})).catch(()=>{})}catch{}return!0}function M({type:e}){return e===`admin`?(0,w.jsx)(`svg`,{className:`wa-notify-icon`,viewBox:`0 0 16 16`,"aria-hidden":`true`,children:(0,w.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,w.jsx)(`svg`,{className:`wa-notify-icon`,viewBox:`0 0 16 16`,"aria-hidden":`true`,children:(0,w.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,w.jsx)(`svg`,{className:`wa-notify-icon`,viewBox:`0 0 16 16`,"aria-hidden":`true`,children:(0,w.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,w.jsx)(`svg`,{className:`wa-notify-icon`,viewBox:`0 0 16 16`,"aria-hidden":`true`,children:(0,w.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 ge({frames:e,onExpire:t}){let n=(0,T.useRef)(new Map),r=(0,T.useRef)(new Map);return(0,T.useEffect)(()=>{let i=Date.now(),a=me(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,w.jsx)(`div`,{className:`wa-notify-host`,children:[...e].reverse().map(e=>(0,w.jsxs)(`div`,{className:`wa-notify-card`,role:`status`,children:[(0,w.jsxs)(`div`,{className:`wa-notify-head`,children:[(0,w.jsx)(`span`,{className:`wa-notify-pill wa-notify-pill-${e.senderType}`,children:(0,w.jsx)(M,{type:e.senderType})}),(0,w.jsx)(`span`,{className:`wa-notify-account`,children:e.accountName})]}),(0,w.jsx)(`div`,{className:`wa-notify-sender`,children:e.senderDisplay}),(0,w.jsxs)(`div`,{className:`wa-notify-body`,children:[e.body,e.truncated?`…`:``]})]},e.waMessageId))})}var _e=`wa-notify`,ve=o(`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`}]]),ye=o(`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`}]]),be=o(`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`}]]),xe=o(`chevron-down`,[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]),Se=o(`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`}]]),Ce=o(`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`}]]),we=o(`gauge`,[[`path`,{d:`m12 14 4-4`,key:`9kzdfg`}],[`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`,key:`19p75a`}]]),Te=o(`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`}]]),Ee=o(`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`}]]),De=o(`panel-left`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}]]),Oe=o(`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`}]]),ke=o(`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`}]]),Ae=o(`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`}]]),je=o(`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`}]]);function Me({connected:e,onConnectClaude:t}){return e?(0,w.jsxs)(`span`,{className:`claude-status-pill`,"data-connected":`true`,title:`Claude is connected`,children:[(0,w.jsx)(`img`,{src:`/brand/claude.png`,alt:``,className:`claude-status-pill__mark`}),(0,w.jsx)(`span`,{className:`claude-status-pill__label`,children:`Connected`}),(0,w.jsx)(`span`,{className:`claude-status-pill__dot claude-status-pill__dot--live`,"aria-hidden":`true`})]}):(0,w.jsxs)(`button`,{type:`button`,className:`claude-status-pill claude-status-pill--action`,"data-connected":`false`,onClick:t,title:`Connect Claude`,children:[(0,w.jsx)(`img`,{src:`/brand/claude.png`,alt:``,className:`claude-status-pill__mark`}),(0,w.jsx)(`span`,{className:`claude-status-pill__label`,children:`Connect`}),(0,w.jsx)(`span`,{className:`claude-status-pill__dot claude-status-pill__dot--down`,"aria-hidden":`true`})]})}function Ne(e){return e===`/`||e===``?`Dashboard`:e.startsWith(`/chat`)?`Chat`:e.startsWith(`/tasks`)?`Tasks`:e.startsWith(`/data`)?`Data`:e.startsWith(`/calendar`)?`Calendar`:e.startsWith(`/graph`)?`Graph`:e.startsWith(`/activity`)?`Activity`:e.startsWith(`/browser`)?`Browser`:`Dashboard`}function Pe({title:e,sidebarOpen:t,onToggleSidebar:n,claudeConnected:r,onConnectClaude:i}){let a=e??Ne(typeof window<`u`?window.location.pathname:`/`),o=r!==void 0&&i!==void 0;return(0,w.jsxs)(`header`,{className:`admin-page-header`,children:[(0,w.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,w.jsx)(De,{className:`admin-page-header__toggle-desktop`,size:18,strokeWidth:1.75}),(0,w.jsx)(g,{className:`admin-page-header__toggle-mobile`,size:22,strokeWidth:1.75})]}),(0,w.jsx)(`h1`,{className:`admin-page-header__title`,children:a}),o&&(0,w.jsx)(`div`,{className:`admin-page-header__right`,children:(0,w.jsx)(Me,{connected:r,onConnectClaude:i})})]})}var Fe=[{label:`Home`,href:`/`,Icon:i,match:e=>e===`/`||e===``},{label:`Chat`,href:`/chat`,Icon:C,match:e=>e.startsWith(`/chat`)},{label:`Tasks`,href:`/tasks`,Icon:Te,match:e=>e.startsWith(`/tasks`)},{label:`Data`,href:`/data`,Icon:S,match:e=>e.startsWith(`/data`)},{label:`Calendar`,href:`/calendar`,Icon:d,match:e=>e.startsWith(`/calendar`)}],Ie=[{label:`Chat`,href:`/`,Icon:C,match:e=>e===`/`||e===``||e.startsWith(`/chat`)},{label:`Data`,href:`/data`,Icon:S,match:e=>e.startsWith(`/data`)}];function Le(e){let t=Fe.find(t=>t.match(e));return t?t.href:`/`}function N({variant:e=`admin`,onOpenConversations:t}={}){let n=typeof window<`u`?window.location.pathname:`/`,r=e===`operator`?Ie:Fe,i=e===`operator`?Ie.find(e=>e.match(n))?.href??`/`:Le(n),a=e=>{let t=e.href===i,{Icon:n}=e;return(0,w.jsxs)(`a`,{href:e.href,className:`bottom-tab${t?` is-active`:``}`,"aria-current":t?`page`:void 0,children:[(0,w.jsx)(n,{size:19,strokeWidth:1.75}),(0,w.jsx)(`span`,{className:`bottom-tab__label`,children:e.label})]},e.href)};return(0,w.jsxs)(`nav`,{className:`bottom-tab-bar`,"aria-label":`Primary`,children:[r.slice(0,1).map(a),e===`operator`&&t&&(0,w.jsxs)(`button`,{type:`button`,className:`bottom-tab`,onClick:t,children:[(0,w.jsx)(C,{size:19,strokeWidth:1.75}),(0,w.jsx)(`span`,{className:`bottom-tab__label`,children:`Conversations`})]}),r.slice(1).map(a)]})}var P=`maxy-shell-side-px`;function Re(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .artefact`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function F(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=Math.max(248,t-480-Re());return Math.min(Math.max(e,248),n)}function ze(){if(typeof window>`u`)return 264;try{let e=window.localStorage.getItem(P);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 F(t)}catch{}return 264}function I({targetSelector:e=`.platform`}){let t=(0,T.useRef)(null),[n,r]=(0,T.useState)(()=>ze()),i=(0,T.useRef)(n);(0,T.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,T.useCallback)(()=>{r(e=>{let t=F(e);return t===e?e:t})},[]);(0,T.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(F(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(P,String(t))}catch{}console.info(`[admin-ui] sidebar-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=F(264);r(e);try{window.localStorage.removeItem(P)}catch{}console.info(`[admin-ui] sidebar-resize px=${e}`)};return(0,w.jsx)(`div`,{ref:t,className:`side-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize sidebar`,onPointerDown:o,onDoubleClick:s})}var L=l();function Be(e){return Math.max(14,e/2-386)}function R(e){return e.left===0&&e.top===0&&e.width===0&&e.height===0}var Ve={position:`fixed`,visibility:`hidden`};function He({anchorRef:e,onClose:t,className:n,role:r,ariaLabel:i,anchorId:a,children:o}){let s=(0,T.useRef)(null),[c,l]=(0,T.useState)(Ve),u=(0,T.useRef)(null),d=(0,T.useCallback)(()=>{let t=s.current;if(!t)return;let r=e.current,i=[n,a].filter(Boolean).join(`:`)||`unknown`,o=t.getBoundingClientRect(),c=window.innerWidth,d=window.innerHeight,f=o.width>0&&o.height>0,p=r?r.getBoundingClientRect():null,m=(e,t)=>console.error(`[anchored-popover] op=offscreen id=${i} left=${e} top=${t} w=${o.width} h=${o.height} viewport=${c},${d}`),h=e=>{e!==u.current&&(u.current=e,console.log(e))};if(h(`[anchored-popover] op=anchor id=${i} present=${!!r} rect=${p?`${p.left},${p.top},${p.width},${p.height}`:`none`}`),!p){let e=Math.max(4,c-o.width-Be(c)),t=Math.max(4,d-o.height-14);l({position:`fixed`,left:e,top:t,visibility:`visible`}),h(`[anchored-popover] op=placed id=${i} left=${e} top=${t} w=${o.width} h=${o.height} flipped=false clampedLeft=false clampedRight=false`);return}if(f&&R(p)){l(Ve),m(p.left,p.top);return}let g=p.right-o.width,_=c-o.width-4,ee=!1,te=!1;g>_&&(g=_,ee=!0),g<4&&(g=4,te=!0);let v=d-p.bottom-4,y=p.top-4,b=o.height+8<=v?!1:o.height+8<=y?!0:y>v,x=Math.max(0,b?y:v),S=b?Math.max(4,p.top-Math.min(o.height,x)):p.bottom;l({position:`fixed`,left:g,top:S,maxHeight:x,visibility:`visible`}),h(`[anchored-popover] op=placed id=${i} left=${g} top=${S} w=${o.width} h=${o.height} maxH=${x} flipped=${b} clampedLeft=${te} clampedRight=${ee}`);let ne=Math.min(o.height,x);f&&(g+o.width<=0||g>=c||S+ne<=0||S>=d)&&m(g,S)},[e,a,n]);return(0,T.useLayoutEffect)(()=>{if(d(),typeof ResizeObserver>`u`)return;let e=new ResizeObserver(()=>d());return s.current&&e.observe(s.current),()=>e.disconnect()},[d]),(0,T.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,L.createPortal)((0,w.jsx)(`div`,{ref:s,className:n,role:r,"aria-label":i,style:c,children:o}),document.body)}function Ue({actions:e,disabled:t}){let[n,r]=(0,T.useState)(!1),[i,a]=(0,T.useState)(null),o=(0,T.useRef)(null),s=(0,T.useCallback)(()=>{r(!1),a(null)},[]);return(0,w.jsxs)(`div`,{className:`conv-actions`,children:[(0,w.jsx)(`button`,{ref:o,type:`button`,className:`conv-action conv-actions-overflow`,onClick:()=>r(e=>!e),disabled:t,"aria-haspopup":`menu`,"aria-expanded":n,"aria-label":`Session actions`,title:`Session actions`,children:(0,w.jsx)(g,{size:12})}),n&&(0,w.jsx)(He,{anchorRef:o,onClose:s,className:`conv-actions-menu`,role:`menu`,children:e.map(e=>e.panel?(0,w.jsxs)(`div`,{className:`conv-actions-menu-disclosure`,children:[(0,w.jsxs)(`button`,{type:`button`,role:`menuitem`,"aria-haspopup":`dialog`,"aria-expanded":i===e.key,disabled:t,onClick:()=>a(t=>t===e.key?null:e.key),children:[e.icon,(0,w.jsx)(`span`,{children:e.menuLabel})]}),i===e.key&&(0,w.jsx)(`div`,{className:`conv-actions-menu-panel`,children:e.panel()})]},e.key):(0,w.jsxs)(`button`,{type:`button`,role:`menuitem`,className:e.danger?`conv-action-danger`:void 0,"aria-busy":e.busy,disabled:t,onClick:t=>{e.onClick?.(t),s()},children:[e.icon,(0,w.jsx)(`span`,{children:e.menuLabel})]},e.key))})]})}var z=`claude-opus-5[1m]`,B=`claude-sonnet-5`,V=`claude-haiku-4-5`,We={[z]:`Opus 5 (1M context)`,[B]:`Sonnet 5`,[V]:`Haiku 4.5`};function Ge(e){return We[e]??e}var Ke=[z,B,V];function qe(e){return e.replace(/\[1m\]$/,``)}function Je(e){return Ke.find(t=>qe(t)===qe(e))??e}var Ye=[`default`,`acceptEdits`,`plan`,`auto`,`bypassPermissions`],H=[`low`,`medium`,`high`,`xhigh`];[...Ye],[...H],[...H];var Xe=[z,B,V],Ze={default:`Ask permissions`,acceptEdits:`Accept edits`,plan:`Plan mode`,auto:`Auto mode`,bypassPermissions:`Bypass permissions`},Qe=Ye.map(e=>({value:e,label:Ze[e]??e})),$e={low:`Low`,medium:`Medium`,high:`High`,xhigh:`Highest`},et=H.map(e=>({value:e,label:$e[e]??e}));function tt(e){if(e){let t=Xe.find(t=>qe(t)===qe(e));if(t)return t}return z}function nt({row:e,adminFetch:t,onError:n}){let[r,i]=(0,T.useState)(()=>tt(e.model)),[o,s]=(0,T.useState)(``),[c,l]=(0,T.useState)(``),[u,d]=(0,T.useState)(!1),f=(0,T.useRef)(!1);(0,T.useEffect)(()=>{i(tt(e.model))},[e.model]);let p=async()=>{if(!f.current){f.current=!0,d(!0);try{let i=await t(`/api/admin/session-reseat`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({fromSessionId:e.sessionId,model:r,...o?{permissionMode:o}:{},...c?{effort:c}:{}})});if(!i.ok){n(`Could not reset ${e.title} (status ${i.status})`),console.error(`[admin-ui] dashboard-reseat-failed sessionId=${e.sessionId} status=${i.status}`),f.current=!1,d(!1);return}let a=await i.json().catch(()=>({}));a.target?window.location.assign(a.target):(n(`Reset of ${e.title} returned no target`),f.current=!1,d(!1))}catch(t){n(`Could not reset ${e.title} (network error)`),console.error(`[admin-ui] dashboard-reseat-failed sessionId=${e.sessionId} error=${t instanceof Error?t.message:String(t)}`),f.current=!1,d(!1)}}};return(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`label`,{className:`reseat-field`,children:[(0,w.jsx)(`span`,{children:`Model`}),(0,w.jsx)(`select`,{"data-kind":`model`,value:r,disabled:u,onChange:e=>i(e.target.value),children:Xe.map(e=>(0,w.jsx)(`option`,{value:e,children:Ge(e)},e))})]}),(0,w.jsxs)(`label`,{className:`reseat-field`,children:[(0,w.jsx)(`span`,{children:`Mode`}),(0,w.jsxs)(`select`,{"data-kind":`mode`,value:o,disabled:u,onChange:e=>s(e.target.value),children:[(0,w.jsx)(`option`,{value:``,children:`Keep current`}),Qe.map(e=>(0,w.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,w.jsxs)(`label`,{className:`reseat-field`,children:[(0,w.jsx)(`span`,{children:`Effort`}),(0,w.jsxs)(`select`,{"data-kind":`effort`,value:c,disabled:u,onChange:e=>l(e.target.value),children:[(0,w.jsx)(`option`,{value:``,children:`Keep current`}),et.map(e=>(0,w.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,w.jsx)(`button`,{type:`button`,className:`reseat-apply`,disabled:u,"aria-busy":u,onClick:()=>void p(),children:u?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(a,{size:12,className:`spin`,"aria-hidden":`true`}),`Resetting…`]}):`Reset`})]})}function rt(e){if(e<60)return`${e}s`;let t=Math.floor(e/60),n=e%60;return n>0?`${t}m ${n}s`:`${t}m`}function it(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function at({target:e,anchorEl:t,onConfirm:n,onCancel:r}){let i=(0,T.useRef)(null);return i.current=t,e?(0,w.jsxs)(He,{anchorRef:i,onClose:r,className:`conv-delete-confirm`,role:`alertdialog`,ariaLabel:`Confirm delete session`,children:[(0,w.jsxs)(`div`,{className:`claude-info-header`,children:[(0,w.jsx)(`span`,{children:`Delete this conversation?`}),(0,w.jsx)(`button`,{className:`claude-info-close`,onClick:r,"aria-label":`Close`,children:`✕`})]}),(0,w.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[(0,w.jsxs)(`div`,{className:`conv-delete-target`,children:[(0,w.jsx)(`span`,{className:`conv-delete-label`,title:e.title,children:e.title||`Untitled session`}),(0,w.jsx)(`code`,{className:`conv-delete-id`,title:e.sessionId,children:e.sessionId.slice(0,8)})]}),(0,w.jsx)(`div`,{style:{marginTop:`8px`},children:`This permanently removes the transcript. It is not moved to Archive and cannot be recovered.`}),e.live&&(0,w.jsx)(`div`,{style:{marginTop:`8px`},children:`This session is running; deleting stops it first.`})]}),(0,w.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,w.jsx)(D,{variant:`danger`,size:`sm`,style:{flex:1},onClick:n,children:`Delete`}),(0,w.jsx)(D,{variant:`secondary`,size:`sm`,style:{flex:1},onClick:r,children:`Cancel`})]})]}):null}function ot({open:e,count:t,liveCount:n,onConfirm:r,onCancel:i}){if(!e)return null;let a=t===1?``:`s`;return(0,w.jsx)(`div`,{className:`claude-info-overlay`,onClick:i,children:(0,w.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Confirm delete sessions`,children:[(0,w.jsxs)(`div`,{className:`claude-info-header`,children:[(0,w.jsxs)(`span`,{children:[`Delete `,t,` conversation`,a,`?`]}),(0,w.jsx)(`button`,{className:`claude-info-close`,onClick:i,"aria-label":`Close`,children:`✕`})]}),(0,w.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,w.jsxs)(`div`,{style:{marginTop:`8px`},children:[n,` `,n===1?`is`:`are`,` running and will be stopped first.`]})]}),(0,w.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,w.jsxs)(D,{variant:`danger`,size:`sm`,style:{flex:1},onClick:r,children:[`Delete `,t]}),(0,w.jsx)(D,{variant:`secondary`,size:`sm`,style:{flex:1},onClick:i,children:`Cancel`})]})]})})}function U(e){return`New session: ${e.toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`})}`}function st({open:e,pending:t,onConfirm:n,onCancel:r,now:i}){let[a,o]=(0,T.useState)(``),s=(0,T.useRef)(null),c=(0,T.useRef)(null),l=(0,T.useRef)(!1);if((0,T.useEffect)(()=>{if(!e){c.current=null,l.current=!1;return}if(c.current!==null)return;let t=U(i?i():new Date);c.current=t,o(t)},[e,i]),(0,T.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,w.jsx)(`div`,{className:`claude-info-overlay`,onClick:()=>p(`backdrop`),children:(0,w.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`dialog`,"aria-label":`Name this session`,children:[(0,w.jsxs)(`div`,{className:`claude-info-header`,children:[(0,w.jsx)(`span`,{children:`Name this session`}),(0,w.jsx)(`button`,{className:`claude-info-close`,onClick:()=>p(`cancel`),"aria-label":`Close`,disabled:t,children:`✕`})]}),(0,w.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`},children:[(0,w.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,w.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,w.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,w.jsx)(D,{variant:`primary`,size:`sm`,style:{flex:1},disabled:!d||t,onClick:f,children:t?`Starting…`:`Start session`}),(0,w.jsx)(D,{variant:`secondary`,size:`sm`,style:{flex:1},disabled:t,onClick:()=>p(`cancel`),children:`Cancel`})]})]})})}var ct=`auth-refresh-failed`;function lt({error:e,onClose:t}){if(!e)return null;let n=e.reason===ct,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,w.jsx)(`div`,{className:`claude-info-overlay`,onClick:t,children:(0,w.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Session could not be opened`,children:[(0,w.jsxs)(`div`,{className:`claude-info-header`,children:[(0,w.jsx)(`span`,{children:r}),(0,w.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:`✕`})]}),(0,w.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[i,(0,w.jsxs)(`div`,{className:`claude-info-row`,style:{marginTop:`8px`},children:[(0,w.jsx)(`span`,{className:`claude-info-label`,children:`Reason`}),(0,w.jsx)(`span`,{className:`claude-info-value`,children:e.reason})]}),e.sessionId&&(0,w.jsxs)(`div`,{className:`claude-info-row`,children:[(0,w.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,w.jsxs)(`span`,{className:`claude-info-value`,children:[e.sessionId.slice(0,8),`…`]})]})]})]})})}function W(e){let{show:t,onClose:n,claudeInfo:r,messages:i,sessionElapsed:a,sessionId:o,cacheKey:s}=e,[c,l]=(0,T.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,w.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,w.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,w.jsxs)(`div`,{className:`claude-info-header`,children:[(0,w.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`claude-info-icon`}),(0,w.jsx)(`span`,{children:`Claude Code`}),(0,w.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,w.jsxs)(`div`,{className:`claude-info-section`,children:[(0,w.jsxs)(`div`,{className:`claude-info-row`,children:[(0,w.jsx)(`span`,{className:`claude-info-label`,children:`Version`}),(0,w.jsx)(`span`,{className:`claude-info-value`,children:r?r.version:`…`})]}),(0,w.jsxs)(`div`,{className:`claude-info-row`,children:[(0,w.jsx)(`span`,{className:`claude-info-label`,children:`Email`}),(0,w.jsx)(`span`,{className:`claude-info-value`,children:r?.account?.email??`…`})]})]}),(g||m||h>0)&&(0,w.jsxs)(`div`,{className:`claude-info-section`,children:[g&&(0,w.jsxs)(`div`,{className:`claude-info-row`,children:[(0,w.jsx)(`span`,{className:`claude-info-label`,children:`Plan`}),(0,w.jsx)(`span`,{className:`claude-info-value`,style:{textTransform:`capitalize`},children:g})]}),m&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`div`,{className:`claude-info-row`,children:[(0,w.jsx)(`span`,{className:`claude-info-label`,children:`Usage`}),(0,w.jsxs)(`span`,{className:`claude-info-value`,children:[Math.round(m.utilization*100),`%`]})]}),(0,w.jsxs)(`div`,{className:`claude-info-row`,children:[(0,w.jsx)(`span`,{className:`claude-info-label`,children:`Resets in`}),(0,w.jsx)(`span`,{className:`claude-info-value`,children:_(m.resetsAt)})]}),m.isUsingOverage&&(0,w.jsxs)(`div`,{className:`claude-info-row`,children:[(0,w.jsx)(`span`,{className:`claude-info-label`,children:`Overage`}),(0,w.jsx)(`span`,{className:`claude-info-value`,children:`Active`})]})]}),h>0&&(0,w.jsxs)(`div`,{className:`claude-info-row`,children:[(0,w.jsx)(`span`,{className:`claude-info-label`,children:`Session cost`}),(0,w.jsxs)(`span`,{className:`claude-info-value`,children:[`$`,h<.01?h.toFixed(4):h.toFixed(2)]})]})]}),(0,w.jsxs)(`div`,{className:`claude-info-section`,children:[(0,w.jsxs)(`div`,{className:`claude-info-row`,children:[(0,w.jsx)(`span`,{className:`claude-info-label`,children:`Model`}),(0,w.jsx)(`span`,{className:`claude-info-value`,children:r?.model??`…`})]}),(0,w.jsxs)(`div`,{className:`claude-info-row`,children:[(0,w.jsx)(`span`,{className:`claude-info-label`,children:`Context used`}),(0,w.jsx)(`span`,{className:`claude-info-value`,children:f>0?`${f}%`:`—`})]}),(0,w.jsxs)(`div`,{className:`claude-info-row`,children:[(0,w.jsx)(`span`,{className:`claude-info-label`,children:`Tokens`}),(0,w.jsx)(`span`,{className:`claude-info-value`,children:p>0?it(p):`—`})]}),(0,w.jsxs)(`div`,{className:`claude-info-row`,children:[(0,w.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,w.jsx)(`span`,{className:`claude-info-value`,children:rt(a)})]}),(o||s)&&(()=>{let e=o??s??``;return(0,w.jsxs)(`div`,{className:`claude-info-row`,children:[(0,w.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,w.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 oe(e)?`copied`:`failed`),setTimeout(()=>l(null),1200)},children:c===`copied`?`copied ✓`:c===`failed`?`copy failed ✕`:`${e.slice(0,8)}…`})]})})()]})]})})}function ut({open:e,onConnect:t,onClose:n}){return e?(0,w.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,w.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Claude is not connected`,children:[(0,w.jsxs)(`div`,{className:`claude-info-header`,children:[(0,w.jsx)(`span`,{children:`Claude isn’t connected`}),(0,w.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,w.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`,display:`flex`,flexDirection:`column`,gap:`10px`},children:[(0,w.jsx)(`span`,{children:`This needs Claude, which is currently disconnected. Connect to continue — the rest of the dashboard stays available either way.`}),(0,w.jsxs)(`div`,{style:{display:`flex`,gap:`8px`,alignItems:`center`},children:[(0,w.jsx)(D,{variant:`primary`,size:`sm`,onClick:t,children:`Connect Claude`}),(0,w.jsx)(`button`,{type:`button`,className:`claude-info-close`,style:{fontSize:`11px`},onClick:n,children:`Not now`})]})]})]})}):null}function dt(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 ft(e){return e.activeMs.thinking+e.activeMs.messaging+e.activeMs.toolUse}function G(e){return e.toLocaleString(`en-GB`)}function K(e){return`£${e.toFixed(2)}`}function pt(e){let t=[`Day`,`Active`,`Output tokens`,`Input tokens`,`Cache write`,`Cache read`,`Opus 5 (GBP)`,`Sonnet 5 (GBP)`],n=(e,t)=>[e,dt(ft(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 mt({label:e,d:t,bold:n}){let r=n?`th`:`td`;return(0,w.jsxs)(`tr`,{className:n?`usage-total-row`:void 0,children:[(0,w.jsx)(r,{className:`usage-day`,children:e}),(0,w.jsx)(r,{children:dt(ft(t))}),(0,w.jsx)(r,{children:G(t.tokens.output)}),(0,w.jsx)(r,{children:G(t.tokens.input)}),(0,w.jsx)(r,{children:G(t.tokens.cacheWrite)}),(0,w.jsx)(r,{children:G(t.tokens.cacheRead)}),(0,w.jsx)(r,{children:K(t.costGBP.opus)}),(0,w.jsx)(r,{children:K(t.costGBP.sonnet)})]})}function ht({show:e,onClose:n,anchorEl:r,sessionId:i,summary:a,loading:o,error:s}){let c=(0,T.useRef)(null);if(c.current=r,!e)return null;let l=!!a&&a.days.length>0;return(0,w.jsxs)(He,{anchorRef:c,onClose:n,className:`usage-popover`,role:`dialog`,ariaLabel:`Session usage and cost`,anchorId:i??void 0,children:[(0,w.jsxs)(`div`,{className:`claude-info-header`,children:[(0,w.jsxs)(`span`,{children:[`Usage & cost`,i?` · ${i.slice(0,8)}`:``]}),l&&(0,w.jsx)(`button`,{className:`usage-download`,onClick:()=>{if(!a)return;let e=new Blob([pt(a)],{type:`text/csv;charset=utf-8`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`usage-${i?i.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,w.jsx)(t,{size:14})}),(0,w.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:(0,w.jsx)(ee,{size:14})})]}),(0,w.jsxs)(`div`,{className:`claude-info-section usage-body`,children:[o&&(0,w.jsx)(`div`,{className:`usage-note`,children:`Computing usage…`}),!o&&s&&(0,w.jsx)(`div`,{className:`usage-note usage-error`,children:s}),!o&&!s&&a&&a.days.length===0&&(0,w.jsx)(`div`,{className:`usage-note`,children:`No usage recorded for this session yet.`}),!o&&!s&&a&&a.days.length>0&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`usage-table-scroll`,children:(0,w.jsxs)(`table`,{className:`usage-table`,children:[(0,w.jsx)(`thead`,{children:(0,w.jsxs)(`tr`,{children:[(0,w.jsx)(`th`,{className:`usage-day`,children:`Day`}),(0,w.jsx)(`th`,{children:`Active`}),(0,w.jsx)(`th`,{children:`Output tok`}),(0,w.jsx)(`th`,{children:`Input tok`}),(0,w.jsx)(`th`,{children:`Cache write`}),(0,w.jsx)(`th`,{children:`Cache read`}),(0,w.jsx)(`th`,{children:`Opus 5 (£)`}),(0,w.jsx)(`th`,{children:`Sonnet 5 (£)`})]})}),(0,w.jsxs)(`tbody`,{children:[a.days.map(e=>(0,w.jsx)(mt,{label:e.date,d:e},e.date)),(0,w.jsx)(mt,{label:`TOTAL (${a.days.length} d)`,d:a.totals,bold:!0})]})]})}),(0,w.jsxs)(`div`,{className:`usage-note usage-caveats`,children:[`Prices dated `,a.pricing.opusPriceDate,` · £/$ `,a.pricing.usdPerGbp,` · Sonnet tokenizer factor `,a.pricing.tokenizerFactor,`. Idle human-wait dominates the calendar span; cache-read tokens dominate cost.`]})]})]})]})}var gt=`https://claude.ai/code`,_t=200,vt=[500,1e3,1500,2e3,2500,3e3,3e3];function yt(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:`${gt}/${r}`,sameOrigin:!1};let i=n.reason||n.error||`status ${t}`;return{kind:`error`,sessionId:n.sessionId??null,reason:i}}function bt(e){if(!e)return``;let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``}function xt(e){let{businessName:t,cacheKey:o,onConnectClaude:s,role:c,userName:l,userAvatar:g,onSelectProjects:_,onSelectTasks:ee,onCloseMobileDrawer:y,collapsed:ae,onSelectData:oe,initialDataSurface:se=!1,onLogout:de,onDisconnect:E,disconnecting:pe,claudeConnected:D=!0,subAccounts:O,activeAccountId:k,switchingAccount:me,onSwitchAccount:A,refreshAccounts:j,onOpenConversations:he}=e,M=x(o),ge=(0,T.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,w.jsx)(Oe,{size:12}),panel:()=>(0,w.jsx)(nt,{row:e,adminFetch:M,onError:e=>L({message:e,failed:!0})})}),[M]),_e=u.productName,De=t||_e,Me=typeof l==`string`?l:l===null?`name unavailable`:De,Ne=(Me.trim().charAt(0)||`?`).toUpperCase(),[Pe,Fe]=(0,T.useState)(se?`data`:`sessions`),[Ie,Le]=(0,T.useState)(!1),[N,P]=(0,T.useState)(!1),Re=!ae&&(O?.length??0)>1&&!!A,F=O?.find(e=>e.isHouse)??null,ze=(0,T.useCallback)(()=>{if(F){if(F.accountId===k){console.info(`[admin-ui] op=subaccount-switch-house anchor=brand-icon accountId=${F.accountId.slice(0,8)} switched=false reason=already-house`);return}console.info(`[admin-ui] op=subaccount-switch-house anchor=brand-icon accountId=${F.accountId.slice(0,8)} switched=true`),P(!1),A?.(F.accountId,`/`)}},[F,k,A]),[I,L]=(0,T.useState)(null),[Be,R]=(0,T.useState)(null),[Ve,He]=(0,T.useState)(!1),[z,B]=(0,T.useState)([]),[V]=(0,T.useState)(()=>typeof window>`u`?null:new URLSearchParams(window.location.search).get(`session`)),[We,Ge]=(0,T.useState)(!1),[Ke,qe]=(0,T.useState)(null),[Je,Ye]=(0,T.useState)(!1),[H,Xe]=(0,T.useState)(!1),[Ze,Qe]=(0,T.useState)(!1),[$e,et]=(0,T.useState)(null),[tt,rt]=(0,T.useState)(new Set),it=(0,T.useRef)(new Map),[U,ct]=(0,T.useState)(!1),[W,dt]=(0,T.useState)(new Set),[ft,G]=(0,T.useState)(!1),[K,pt]=(0,T.useState)(null),[mt,gt]=(0,T.useState)(new Set),[xt,St]=(0,T.useState)(new Set),[Tt,Et]=(0,T.useState)(new Set),[Dt,q]=(0,T.useState)(null),[Ot,J]=(0,T.useState)(``),[kt,At]=(0,T.useState)(!1),[Y,jt]=(0,T.useState)(null),[Mt,Nt]=(0,T.useState)(null),[Pt,Ft]=(0,T.useState)(!1),[It,Lt]=(0,T.useState)(null),[X,Rt]=(0,T.useState)(!1),[zt,Bt]=(0,T.useState)(!1),Vt=(0,T.useRef)(0);(0,T.useEffect)(()=>{if(!I)return;let e=setTimeout(()=>L(null),2500);return()=>clearTimeout(e)},[I]);let Ht=V!=null&&z.some(e=>e.sessionId===V);(0,T.useEffect)(()=>{V==null||!We||console.info(`[sidebar-sessions] op=select-highlight session=${V.slice(0,8)} matched=${Ht}`)},[V,Ht,We]);let Z=(0,T.useCallback)(async()=>{if(!o)return null;let e=++Vt.current;Ye(!0),qe(null);try{let t=await M(`/api/admin/sidebar-sessions`);if(!t.ok)throw Error(`status ${t.status}`);let n=await t.json(),r=n.sessions??[];return e===Vt.current?(B(r),et(n.accountId??null),Ge(!0),r):(console.info(`[admin-ui] sidebar-sessions-stale-response-dropped token=${e}`),r)}catch(t){let n=t instanceof Error?t.message:String(t);return e===Vt.current&&qe(`Failed to load sessions: ${n}`),console.error(`[admin-ui] sidebar-sessions fetch failed: ${n}`),null}finally{e===Vt.current&&Ye(!1)}},[o,M]);(0,T.useEffect)(()=>{!o||We||Z()},[o,We,Z]),(0,T.useEffect)(()=>{if(!o)return;let e=null;function t(){console.info(`[admin-ui] sidebar-refresh surface=sessions trigger=poll`),Z()}function n(){e===null&&(e=setInterval(t,Ct))}function r(){e!==null&&(clearInterval(e),e=null)}function i(){document.hidden?r():(t(),n())}return document.hidden||n(),document.addEventListener(`visibilitychange`,i),()=>{r(),document.removeEventListener(`visibilitychange`,i)}},[o,Z]);let Ut=()=>{console.info(`[admin-ui] sidebar-refresh surface=sessions trigger=manual`),Z()},Wt=()=>{Fe(`data`),console.info(`[admin-ui] sidebar-nav surface=data collapsed=${ae}`),oe(),y()},Q=typeof window<`u`&&window.location?.pathname||`/`,Gt=Pe===`data`,Kt=typeof window<`u`&&window.location?.search||``,qt=new URLSearchParams(Kt),Jt=qt.has(`label`)&&!qt.has(`nodeId`),$=e=>{y(),window.location.href=e},Yt=[{key:`dashboard`,label:`Dashboard`,icon:(0,w.jsx)(i,{size:17,strokeWidth:1.75}),active:Q===`/`&&!Gt,onClick:()=>$(`/`)},{key:`chat`,label:`Chat`,icon:(0,w.jsx)(C,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/chat`),onClick:()=>$(`/chat`)},{key:`tasks`,label:`Tasks`,icon:(0,w.jsx)(Te,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/tasks`),onClick:()=>{ee(),y()}},{key:`calendar`,label:`Calendar`,icon:(0,w.jsx)(d,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/calendar`),onClick:()=>$(`/calendar`)},{key:`routines`,label:`Routines`,icon:(0,w.jsx)(je,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/routines`),onClick:()=>$(`/routines`)},{key:`skills`,label:`Skills`,icon:(0,w.jsx)(ke,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/skills`),onClick:()=>$(`/skills`)},{key:`agents`,label:`Agents`,icon:(0,w.jsx)(be,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/agents`),onClick:()=>$(`/agents`)},{key:`data`,label:`Data`,icon:(0,w.jsx)(S,{size:17,strokeWidth:1.75}),active:Gt,onClick:Wt},{key:`container`,label:n().term,icon:(0,w.jsx)(ne,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/graph`)&&Jt,onClick:()=>{_(),y()}},{key:`graph`,label:`Graph`,icon:(0,w.jsx)(Ae,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/graph`)&&!Jt,onClick:()=>$(`/graph`)},{key:`activity`,label:`Activity`,icon:(0,w.jsx)(p,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/activity`),onClick:()=>$(`/activity`)},{key:`browser`,label:`Browser`,icon:(0,w.jsx)(f,{size:17,strokeWidth:1.75}),active:Q.startsWith(`/browser`),onClick:()=>$(`/browser`)}],Xt=(0,T.useCallback)(async e=>{if(mt.has(e.sessionId))return;gt(t=>{let n=new Set(t);return n.add(e.sessionId),n});let t=window.open(``,`_blank`);try{let n=await M(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e.sessionId,name:e.title||e.sessionId,...e.accountId?{targetAccountId:e.accountId}:{}})}),r=await n.json().catch(()=>({})),i=yt(n.ok,n.status,{...r,sessionId:r.sessionId??e.sessionId});console.info(`[admin-ui] sidebar-session-resume sessionId=${e.sessionId} status=${n.status} outcome=${i.kind} slug=${r.slug??r.bridgeSessionId??`none`}`),i.kind===`navigate`?(y(),t?t.location.href=i.url:window.open(i.url,`_blank`)):(t?.close(),console.error(`[admin-ui] sidebar-session-resume-failed sessionId=${e.sessionId} status=${n.status} reason=${i.reason}`),R(i))}catch(n){t?.close();let r=n instanceof Error?n.message:String(n);console.error(`[admin-ui] sidebar-session-resume-failed sessionId=${e.sessionId} error=${r}`),R({sessionId:e.sessionId,reason:r})}finally{gt(t=>{let n=new Set(t);return n.delete(e.sessionId),n})}},[M,y,mt]),Zt=(0,T.useCallback)(async e=>{let t=e.slice(0,8);for(let n=1;n<=vt.length;n++){await new Promise(e=>setTimeout(e,vt[n-1]));let r=await Z();if(r&&r.some(t=>t.sessionId===e)){console.info(`[admin-ui] sidebar-new-session-converged sessionId=${t} via=retry attempts=${n}`);return}}console.error(`[admin-ui] sidebar-new-session-converge-timeout sessionId=${t}`)},[Z]),Qt=(0,T.useCallback)(async e=>{if(!X){Rt(!0),console.info(`[admin-ui] new-session-modal op=submit surface=sidebar titleLen=${e.length}`);try{let t=await M(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({title:e})}),n=await t.json().catch(()=>({})),r=yt(t.ok,t.status,n);console.info(`[admin-ui] sidebar-new-session-spawned status=${t.status} outcome=${r.kind} slug=${n.slug??n.bridgeSessionId??`none`}`),r.kind===`navigate`?r.sameOrigin?(console.info(`[admin-ui] new-session-modal op=navigate surface=sidebar sessionId=${(n.sessionId??``).slice(0,8)} titleSource=${n.titleSource??`none`}`),window.location.assign(r.url)):(window.open(r.url,`_blank`),n.sessionId?Zt(n.sessionId):console.error(`[admin-ui] sidebar-new-session-converge-skipped reason=no-session-id`)):t.status===503||r.reason===`claude-auth-dead`?(console.info(`[admin-ui] op=llm-action-blocked action=spawn reason=claude-disconnected`),Bt(!1),He(!0)):(console.error(`[admin-ui] sidebar-new-session-failed status=${t.status} reason=${r.reason}`),Bt(!1),R(r))}catch(e){let t=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-new-session-failed error=${t}`),Bt(!1),R({sessionId:null,reason:t})}finally{Rt(!1)}}},[M,X,Zt]),$t=(0,T.useCallback)((e,t)=>{e.stopPropagation(),pt(t)},[]),en=(0,T.useCallback)(async(e,t)=>{e.stopPropagation(),jt(t),Nt(null),Lt(null),Ft(!0);try{let e=await M(`/api/admin/session-usage?sessionId=${encodeURIComponent(t.sessionId)}`),n=await e.json().catch(()=>({}));e.ok?Nt(n):Lt(n.error??`status ${e.status}`)}catch(e){Lt(e instanceof Error?e.message:String(e))}finally{Ft(!1)}},[M]),tn=(0,T.useCallback)(async(e,t={})=>{let n=t.refresh??!0;if(tt.has(e.sessionId))return!1;rt(t=>{let n=new Set(t);return n.add(e.sessionId),n});try{let t=await M(`/api/admin/session-delete`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e.sessionId})});if(!t.ok){let n=await t.json().catch(()=>({}));return console.error(`[admin-ui] sidebar-session-delete-failed sessionId=${e.sessionId} status=${t.status} error=${n.error??`unknown`}`),L({message:`Delete failed: ${n.error??`status ${t.status}`}`,failed:!0}),!1}let r=await t.json();return console.info(`[admin-ui] sidebar-session-delete sessionId=${e.sessionId} live=${e.live} confirmed=true pidKilled=${r.pidKilled??`?`} deleted=${r.deleted??`?`}`),B(t=>t.filter(t=>t.sessionId!==e.sessionId)),n&&Z(),!0}catch(t){let n=t instanceof Error?t.message:String(t);return console.error(`[admin-ui] sidebar-session-delete-failed sessionId=${e.sessionId} error=${n}`),L({message:`Delete failed: ${n}`,failed:!0}),!1}finally{rt(t=>{let n=new Set(t);return n.delete(e.sessionId),n})}},[M,tt,Z]),nn=(0,T.useCallback)(e=>{dt(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),rn=(0,T.useCallback)(()=>{ct(!1),dt(new Set)},[]),an=(0,T.useCallback)(async()=>{let e=[...W].map(e=>z.find(t=>t.sessionId===e)).filter(e=>!!e),t=e.filter(e=>e.live).length;console.info(`[admin-ui] sidebar-bulk-delete op=start count=${e.length} live=${t}`);let n=(await Promise.all(e.map(e=>tn(e,{refresh:!1})))).filter(Boolean).length;console.info(`[admin-ui] sidebar-bulk-delete op=done requested=${e.length} ok=${n} failed=${e.length-n}`),Z(),rn()},[W,z,tn,Z,rn]),on=(0,T.useCallback)(async(e,t)=>{if(e.stopPropagation(),!xt.has(t.sessionId)){St(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await M(`/api/admin/session-stop`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:t.sessionId})});if(!e.ok){let n=await e.json().catch(()=>({}));console.error(`[admin-ui] sidebar-session-stop-failed sessionId=${t.sessionId} status=${e.status} error=${n.error??`unknown`}`),L({message:`Stop failed: ${n.error??`status ${e.status}`}`,failed:!0});return}console.info(`[admin-ui] sidebar-session-stop sessionId=${t.sessionId}`),Z()}catch(e){let n=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-session-stop-failed sessionId=${t.sessionId} error=${n}`),L({message:`Stop failed: ${n}`,failed:!0})}finally{St(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[M,xt,Z]),sn=(0,T.useCallback)(async(e,t,n)=>{if(e.stopPropagation(),!Tt.has(t.sessionId)){Et(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await M(`/api/admin/session-archive`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:t.sessionId,mode:n})});if(!e.ok){let r=await e.json().catch(()=>({})),i=r.detail??r.error??`status ${e.status}`;console.error(`[admin-ui] sidebar-session-archive-failed sessionId=${t.sessionId} mode=${n} status=${e.status} error=${r.error??`unknown`}`),L({message:`${n===`archive`?`Archive`:`Unarchive`} failed: ${i}`,failed:!0});return}console.info(`[admin-ui] sidebar-session-archive sessionId=${t.sessionId} mode=${n}`),Z()}catch(e){let r=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-session-archive-failed sessionId=${t.sessionId} mode=${n} error=${r}`),L({message:`${n===`archive`?`Archive`:`Unarchive`} failed: ${r}`,failed:!0})}finally{Et(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[M,Tt,Z]),cn=(0,T.useCallback)(async e=>{let t=Ot.trim();if(!t){L({message:`Title can’t be empty`,failed:!0});return}if(t.length>_t){L({message:`Title too long (max ${_t})`,failed:!0});return}At(!0);try{let n=await M(`/api/admin/session-rename`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e.sessionId,title:t})});if(!n.ok){let t=await n.json().catch(()=>({})),r=t.reason??t.error??`status ${n.status}`;console.error(`[admin-ui] sidebar-session-rename sessionId=${e.sessionId.slice(0,8)} outcome=rejected reason=${r}`),L({message:`Rename failed: ${r}`,failed:!0});return}console.info(`[admin-ui] sidebar-session-rename sessionId=${e.sessionId.slice(0,8)} outcome=ok`),q(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}`),L({message:`Rename failed: ${n}`,failed:!0})}finally{At(!1)}},[M,Ot,Z]);return(0,w.jsxs)(`aside`,{className:`side`,children:[(0,w.jsxs)(`div`,{className:`side-brand`,children:[Re?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`button`,{type:`button`,className:`side-brand-icon-btn`,"aria-label":`Switch to house account`,disabled:!F,onClick:ze,children:(0,w.jsx)(`img`,{className:`side-brand-icon`,src:m,alt:``,"aria-hidden":`true`})}),(0,w.jsxs)(`button`,{type:`button`,className:`side-brand-trigger`,"aria-haspopup":`menu`,"aria-expanded":N,"aria-label":`Switch sub-account`,onClick:()=>{let e=!N;P(e),e&&j?.(),console.info(`[admin-ui] op=subaccount-switcher-toggle anchor=brand-head open=${e} available=true accounts=${O?.length??0}`)},children:[(0,w.jsxs)(`span`,{className:`side-brand-lockup`,children:[(0,w.jsx)(`span`,{className:`side-brand-business`,children:De}),(0,w.jsx)(`span`,{className:`side-brand-product`,children:u.productName})]}),(0,w.jsx)(xe,{size:14,className:`side-brand-caret`,"aria-hidden":`true`})]})]}):(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`img`,{className:`side-brand-icon`,src:m,alt:``,"aria-hidden":`true`}),(0,w.jsxs)(`span`,{className:`side-brand-lockup`,children:[(0,w.jsx)(`span`,{className:`side-brand-business`,children:De}),(0,w.jsx)(`span`,{className:`side-brand-product`,children:u.productName})]})]}),N&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`side-brand-scrim`,"aria-hidden":`true`,onClick:()=>P(!1)}),(0,w.jsx)(b,{open:N,accounts:O??[],activeAccountId:k??null,switching:me??!1,onSelect:e=>A?.(e),onClose:()=>P(!1)})]})]}),(0,w.jsx)(`nav`,{className:`side-nav`,children:Yt.map(e=>(0,w.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,w.jsx)(`span`,{className:`label`,children:e.label}),(0,w.jsx)(`span`,{className:`kbd`})]},e.key))}),(()=>{let e=z.filter(e=>H?!0:!e.isSubagent).filter(e=>Ze?!0:!e.archived),t=z.some(e=>e.isSubagent),n=z.some(e=>e.archived);return(0,w.jsx)(`div`,{className:`side-sessions`,children:(0,w.jsxs)(`div`,{className:`side-list`,children:[(0,w.jsxs)(`div`,{className:`group-head`,children:[(0,w.jsx)(`span`,{children:`Sessions`}),(0,w.jsxs)(`span`,{className:`group-head-meta`,children:[(0,w.jsx)(`button`,{type:`button`,className:`group-head-select${U?` active`:``}`,"aria-pressed":U,title:U?`Exit select mode`:`Select multiple sessions to delete`,onClick:()=>{ct(e=>!e),dt(new Set),q(null),J(``)},children:`Select`}),(0,w.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh sessions`,"aria-label":`Refresh sessions`,onClick:Ut,disabled:Je,children:(0,w.jsx)(le,{size:12,className:Je?`spinning`:void 0})}),(0,w.jsx)(`span`,{children:Je?`…`:String(e.length)}),(0,w.jsxs)(`button`,{type:`button`,className:`admin-btn-cta side-sessions-new`,onClick:()=>{console.info(`[admin-ui] new-session-modal op=open surface=sidebar default=applied`),Bt(!0)},disabled:X,"aria-busy":X,"aria-label":X?`Spawning session`:`New session`,title:X?`Spawning session`:`New session`,children:[X?(0,w.jsx)(a,{size:13,className:`spinning`}):(0,w.jsx)(h,{size:13}),(0,w.jsx)(`span`,{children:X?`Spawning…`:`New session`})]})]})]}),U&&(0,w.jsxs)(`div`,{className:`session-select-bar`,children:[(0,w.jsxs)(`span`,{className:`session-select-count`,children:[W.size,` selected`]}),(0,w.jsxs)(`button`,{type:`button`,className:`session-select-delete`,disabled:W.size===0,onClick:()=>G(!0),children:[`Delete `,W.size]}),(0,w.jsx)(`button`,{type:`button`,className:`session-select-cancel`,onClick:rn,children:`Cancel`})]}),$e&&(0,w.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,w.jsx)(`code`,{children:$e})}),(t||n)&&(0,w.jsxs)(`div`,{className:`artefact-filter-chips`,children:[t&&(0,w.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${H?` active`:``}`,"aria-pressed":H,onClick:()=>Xe(e=>!e),title:H?`Hide subagent sessions`:`Show subagent sessions`,children:`Subagents`}),n&&(0,w.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${Ze?` active`:``}`,"aria-pressed":Ze,onClick:()=>Qe(e=>!e),title:Ze?`Hide archived sessions`:`Show archived sessions`,children:`Archived`})]}),Ke&&(0,w.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:Ke}),We&&!Ke&&e.length===0&&(0,w.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No sessions yet`}),e.map(e=>{let t=bt(e.startedAt),n=mt.has(e.sessionId),i=tt.has(e.sessionId),a=xt.has(e.sessionId),o=Tt.has(e.sessionId),s=n||i||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,w.jsx)(Ce,{size:12}),busy:n,onClick:()=>{Xt(e)}},{key:`message`,label:`Open session ${e.title} in admin webchat`,menuLabel:`Open in webchat`,title:`Open in admin webchat (/chat) — sending resumes this session`,icon:(0,w.jsx)(Ee,{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,w.jsx)(we,{size:12}),onClick:t=>{en(t,e)}},...e.live?[{key:`stop`,label:`Stop session ${e.title}`,menuLabel:`Stop`,title:`Stop session process (keeps the conversation, can resume later)`,icon:(0,w.jsx)(ue,{size:12}),busy:a,onClick:t=>{on(t,e)}}]:[],e.archived?{key:`unarchive`,label:`Unarchive session ${e.title}`,menuLabel:`Unarchive`,title:`Unarchive (move back to the active list)`,icon:(0,w.jsx)(ve,{size:12}),busy:o,onClick:t=>{sn(t,e,`unarchive`)}}:{key:`archive`,label:`Archive session ${e.title}`,menuLabel:`Archive`,title:`Archive (hide from the list, keeps the conversation resumable)`,icon:(0,w.jsx)(ye,{size:12}),busy:o,onClick:t=>{sn(t,e,`archive`)}},{key:`rename`,label:`Rename session ${e.title}`,menuLabel:`Rename`,title:`Rename this session`,icon:(0,w.jsx)(r,{size:12}),busy:kt&&Dt===e.sessionId,onClick:t=>{t.stopPropagation(),q(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,w.jsx)(ce,{size:12}),danger:!0,busy:i,onClick:t=>{$t(t,e)}},ge({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`?te({operatorName:e.personName??null,whatsappName:e.whatsappName??null,senderId:e.senderId,title:e.title,channel:e.channel}):e.personName??e.title;return(0,w.jsxs)(`div`,{ref:t=>{let n=it.current;t?n.set(e.sessionId,t):n.delete(e.sessionId)},className:`conv conv-with-actions${u}${e.sessionId===V?` active`:``}`,children:[(0,w.jsxs)(`div`,{className:`conv-main-static conv-main-clickable`,role:`button`,tabIndex:0,"aria-label":`Open ${f} in webchat`,onClick:()=>{if(Dt!==e.sessionId){if(U){nn(e.sessionId);return}c()}},onKeyDown:t=>{Dt!==e.sessionId&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),U?nn(e.sessionId):c())},children:[U&&(0,w.jsx)(`span`,{className:`conv-select-check`,onClick:e=>e.stopPropagation(),children:(0,w.jsx)(fe,{checked:W.has(e.sessionId),ariaLabel:`Select ${f}`,onChange:()=>nn(e.sessionId)})}),(0,w.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,w.jsxs)(`span`,{className:`conv-stack`,children:[(0,w.jsxs)(`span`,{className:`conv-name-line`,children:[d&&(0,w.jsx)(v,{channel:e.channel,size:13}),Dt===e.sessionId?(0,w.jsx)(`input`,{className:`conv-name conv-name-edit`,autoFocus:!0,onFocus:e=>e.currentTarget.select(),value:Ot,disabled:kt,"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(),cn(e)):t.key===`Escape`&&(t.preventDefault(),q(null),J(``))},onBlur:()=>{Dt===e.sessionId&&!kt&&(q(null),J(``))}}):(0,w.jsx)(`span`,{className:`conv-name`,title:f,children:f})]}),(0,w.jsxs)(`span`,{className:`conv-timestamp`,children:[(0,w.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,w.jsxs)(`span`,{children:[` · `,t]})]})]})]}),!U&&(0,w.jsx)(Ue,{actions:l,disabled:s})]},e.sessionId)})]})})})(),(0,w.jsxs)(`div`,{className:`side-foot`,children:[(0,w.jsx)(`div`,{className:`avatar`,children:g?(0,w.jsx)(`img`,{src:g,alt:Me}):Ne}),(0,w.jsxs)(`div`,{className:`who`,children:[(0,w.jsx)(`span`,{className:`name`,children:Me}),(0,w.jsx)(wt,{})]}),(0,w.jsx)(`button`,{type:`button`,className:`side-foot-kebab`,"aria-label":`Account menu`,"aria-haspopup":`menu`,"aria-expanded":Ie,onClick:()=>Le(e=>!e),children:(0,w.jsx)(Se,{size:16})}),Ie&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:`side-foot-menu-scrim`,"aria-hidden":`true`,onClick:()=>Le(!1)}),(0,w.jsx)(`div`,{className:`side-foot-menu`,role:`menu`,children:(0,w.jsx)(ie,{variant:`admin`,onCloseMenu:()=>Le(!1),onLogout:de??(()=>{}),onDisconnect:E,disconnecting:pe,claudeConnected:D,onConnectClaude:s,cacheKey:o,onOpenConversations:he})})]})]}),I&&(0,w.jsx)(`div`,{className:`copy-toast${I.failed?` copy-toast-failed`:``}`,role:`status`,children:I.message}),(0,w.jsx)(st,{open:zt,pending:X,onConfirm:e=>{Qt(e)},onCancel:e=>{console.info(`[admin-ui] new-session-modal op=cancel surface=sidebar via=${e}`),Bt(!1)}}),(0,w.jsx)(lt,{error:Be,onClose:()=>R(null)}),(0,w.jsx)(ut,{open:Ve,onConnect:()=>{He(!1),s?.()},onClose:()=>He(!1)}),(0,w.jsx)(at,{target:K,anchorEl:K?it.current.get(K.sessionId)??null:null,onCancel:()=>pt(null),onConfirm:()=>{let e=K;pt(null),e&&tn(e)}},K?.sessionId??`none`),(0,w.jsx)(ot,{open:ft,count:W.size,liveCount:z.filter(e=>W.has(e.sessionId)&&e.live).length,onConfirm:()=>{G(!1),an()},onCancel:()=>G(!1)}),(0,w.jsx)(ht,{show:Y!==null,onClose:()=>{jt(null),Nt(null),Lt(null)},anchorEl:Y?it.current.get(Y.sessionId)??null:null,sessionId:Y?.sessionId??null,summary:Mt,loading:Pt,error:It},Y?.sessionId??`none`)]})}var St=5e3,Ct=3e4;function wt(){let[e,t]=(0,T.useState)(null);if((0,T.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()},St))}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,w.jsxs)(`span`,{className:d.join(` `),role:`status`,"aria-label":`host CPU and RAM`,children:[(0,w.jsxs)(`span`,{className:i?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`CPU `,u(n)]}),` · `,(0,w.jsxs)(`span`,{className:o?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`RAM `,u(r)]})]})}var Tt=`admin-sidebar-collapsed`,Et=`admin-sidebar-drawer-open`,Dt=1080;function q(){if(typeof window>`u`)return!1;let e=null;try{e=window.sessionStorage.getItem(Tt)}catch{e=null}return e===null?typeof window.matchMedia==`function`?window.matchMedia(`(min-width: 721px) and (max-width: ${Dt}px)`).matches:!1:e===`1`}function Ot(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(Tt,`1`):window.sessionStorage.removeItem(Tt)}catch{}}function J(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(Et)===`1`}catch{return!1}}function kt(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(Et,`1`):window.sessionStorage.removeItem(Et)}catch{}}function At(e){let[t,n]=(0,T.useState)(()=>typeof window>`u`||typeof window.matchMedia!=`function`?!1:window.matchMedia(e).matches);return(0,T.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 Y=720;function jt(e,t){return e===`/`?{via:`in-place`}:{via:`navigate`,href:`/?wa=${encodeURIComponent(t.remoteJid??``)}&acct=${encodeURIComponent(t.accountId??``)}`}}function Mt(e){return e===`/`?{via:`in-place`}:{via:`navigate`,href:`/?data=1`}}function Nt(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 Pt(e,t){return e===`/`?new URLSearchParams(t).has(`data`):!1}function Ft(e,t){return t===`operator`&&e===`chat`||e===`dashboard`?`/`:e===`data`?`/data`:e===`graph`?`/graph`:e===`calendar`?`/calendar`:e===`chat`?`/chat`:e===`activity`?`/activity`:`/browser`}function It(e){let{cacheKey:t,businessName:r,variant:i=`admin`,onLogout:a,onDisconnect:o,disconnecting:l,claudeConnected:u,onConnectClaude:d,userName:f,userAvatar:p,role:m,onOpenConversations:h,children:g,footer:_}=e,{subAccounts:ee,activeAccountId:te,switching:v,switchAccount:b,refreshAccounts:x}=se(t),[S,ne]=(0,T.useState)([]),re=(0,T.useCallback)(e=>{ne(t=>t.filter(t=>t.waMessageId!==e))},[]);(0,T.useEffect)(()=>{if(!t)return;let e=null;try{e=new EventSource(s(`/api/admin/events`,t)),e.addEventListener(_e,e=>{try{let t=JSON.parse(e.data);if(!t||typeof t.waMessageId!=`string`)return;ne(e=>e.some(e=>e.waMessageId===t.waMessageId)?e:[...e,t])}catch{}}),e.onerror=()=>{console.error(`[admin-ui] wa-notify stream error`)}}catch(e){console.error(`[admin-ui] wa-notify unavailable reason=${e instanceof Error?e.message:String(e)}`)}return()=>{e?.close()}},[t]);let[ie,ae]=(0,T.useState)(!0);(0,T.useEffect)(()=>{if(u!==void 0||i!==`admin`)return;let e=!1,t=async()=>{try{let t=await fetch(`/api/health`);if(!t.ok)return;let n=await t.json();e||ae(n.auth_status!==`dead`&&n.auth_status!==`missing`)}catch{}};t();let n=setInterval(t,6e4);return()=>{e=!0,clearInterval(n)}},[u,i]);let oe=u??ie,ce=d??(()=>{window.location.assign(`/?connect=claude`)}),[C,le]=(0,T.useState)(()=>q()),[ue,de]=(0,T.useState)(!1),fe=(0,T.useRef)(!0);(0,T.useEffect)(()=>{if(fe.current){fe.current=!1;return}de(!0);let e=setTimeout(()=>de(!1),260);return()=>clearTimeout(e)},[C]);let[E,pe]=(0,T.useState)(()=>J()),D=At(`(max-width: ${Y}px)`),[O,k]=(0,T.useState)(()=>typeof window>`u`||Pt(window.location.pathname,window.location.search)?null:Nt(window.location.pathname,window.location.search)),[me,A]=(0,T.useState)(()=>typeof window>`u`?!1:Pt(window.location.pathname,window.location.search)),[j]=(0,T.useState)(()=>me),he=(0,T.useCallback)(e=>{Ot(e),le(e)},[]),M=(0,T.useCallback)(e=>{kt(e),pe(e)},[]);(0,T.useEffect)(()=>{if(typeof window>`u`)return;let e=window.location?.pathname??``;console.info(`[admin-ui] shell-mount route=${e} variant=${i} sidebar=${i===`operator`?`none`:`present`} collapsed=${C} drawer=${E}`)},[]),(0,T.useEffect)(()=>{typeof window>`u`||!O||(console.info(`[admin-ui] wa-hydrate route=/ remoteJid=${O.remoteJid??``}`),window.history.replaceState(null,``,`/`))},[]),(0,T.useEffect)(()=>{typeof window>`u`||!me||(console.info(`[admin-ui] data-hydrate route=/`),window.history.replaceState(null,``,`/`))},[]);let ve=(0,T.useCallback)(e=>{if(A(!1),e===null){k(null);return}let t=typeof window<`u`?window.location.pathname:`/`,n=jt(t,e);console.info(`[admin-ui] wa-open route=${t} via=${n.via} sessionId=${e.sessionId.slice(0,8)}`),n.via===`in-place`?k(e):window.location.href=n.href},[]),ye=(0,T.useCallback)(()=>{let e=typeof window<`u`?window.location.pathname:`/`,t=Mt(e);if(console.info(`[admin-ui] data-open route=${e} via=${t.via}`),t.via===`navigate`){window.location.href=t.href;return}k(null),A(!0)},[]),be=D?E:!C,xe=(0,T.useCallback)(()=>{if(!(typeof window>`u`))if(window.matchMedia(`(max-width: ${Y}px)`).matches){let e=E;console.info(`[admin-ui] header-sidebar-toggle from=${e?`open`:`closed`} mode=drawer`),M(!e)}else{let e=C;console.info(`[admin-ui] header-sidebar-toggle from=${e?`closed`:`open`} mode=collapse`),he(!e)}},[C,E,he,M]),Se=(0,T.useCallback)(e=>{let t=Ft(e,i);console.info(`[admin-ui] header-menu-nav target=${e} dest=${t}`),window.location.href=t},[i]),Ce={collapsed:C,mobileDrawerOpen:E,sidebarOpen:be,onToggleSidebar:xe,setMobileDrawerOpen:M,selectedWhatsapp:O,onClearWhatsapp:()=>k(null),onSelectWhatsappConversation:ve,dataOpen:me};return i===`operator`?(0,w.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[v&&(0,w.jsx)(c,{surface:`switch`}),(0,w.jsx)(y,{businessName:r,variant:i,onNavigate:Se,onOpenConversations:h,onToggleSidebar:xe,sidebarOpen:be,onLogout:a,onDisconnect:o,disconnecting:l,cacheKey:t,subAccounts:ee,activeAccountId:te,switchingAccount:v,onSwitchAccount:b,refreshAccounts:x}),(0,w.jsx)(`div`,{className:`platform platform-operator`,children:typeof g==`function`?g(Ce):g}),(0,w.jsx)(N,{variant:`operator`,onOpenConversations:h}),_,(0,w.jsx)(ge,{frames:S,onExpire:re})]}):(0,w.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[v&&(0,w.jsx)(c,{surface:`switch`}),(0,w.jsxs)(`div`,{className:`platform${E?` menu-open`:``}${!D&&C?` sidebar-collapsed`:``}${ue?` sidebar-animating`:``}`,"data-artefact":`closed`,children:[(0,w.jsx)(xt,{businessName:r,cacheKey:t,onConnectClaude:ce,role:m??null,userName:f,userAvatar:p??null,onSelectProjects:()=>{window.location.href=`/graph?label=${n().label}`},onSelectTasks:()=>{window.location.href=`/tasks`},onCloseMobileDrawer:()=>M(!1),collapsed:C,mobileDrawerOpen:E,onSelectData:ye,onCloseData:()=>A(!1),initialDataSurface:j,onLogout:a,onDisconnect:o,disconnecting:l,claudeConnected:oe,subAccounts:ee,activeAccountId:te,switchingAccount:v,onSwitchAccount:b,refreshAccounts:x,onOpenConversations:h}),!D&&(0,w.jsx)(I,{}),(0,w.jsx)(Pe,{sidebarOpen:be,onToggleSidebar:xe,claudeConnected:oe,onConnectClaude:ce}),typeof g==`function`?g(Ce):g]}),E&&(0,w.jsx)(`div`,{className:`sidebar-backdrop menu-open`,"aria-hidden":`true`,onClick:()=>M(!1)}),(0,w.jsx)(N,{}),_,(0,w.jsx)(ge,{frames:S,onExpire:re})]})}export{ve as C,de as E,ye as S,fe as T,we as _,W as a,xe as b,z as c,Ge as d,je as f,Te as g,Ee as h,ut as i,B as l,Oe as m,At as n,st as o,ke as p,yt as r,V as s,It as t,Je as u,Ce as v,D as w,be as x,Se as y};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{G as t,I as n,P as r,V as i,W as a,m as o,n as s,q as c}from"./useSubAccountSwitcher-BufCPDDH.js";import{C as l,T as u,t as d,w as f}from"./AdminShell-Bpo_wgxm.js";import{t as p}from"./triangle-alert-DAtm2mLL.js";var m=t(),h=e(c(),1),g=i(),_=`—`;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[i,a]=(0,h.useState)(null),[o,c]=(0,h.useState)(null),[u,d]=(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 s(t,e)&&(console.info(`[admin-ui] activity-card-open account=${e.slice(0,8)} session=${n.slice(0,8)}`),window.location.assign(`/chat?session=${encodeURIComponent(n)}`))},[t]),R=(0,h.useRef)(!1),z=(0,h.useRef)(void 0),B=(0,h.useCallback)(async t=>{if(R.current){z.current=t;return}R.current=!0;try{let n=await e(`/api/admin/activity${t?`?from=${t.from}&to=${t.to}`:``}`);if(n.status===403){c(`This view is available to the house account only.`),d(!0);return}if(!n.ok){c(`The session manager did not answer (status ${n.status}).`),d(!0);return}a(await n.json()),c(null)}catch(e){c(e instanceof Error?e.message:String(e))}finally{d(!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)(()=>i?[...i.rows].sort((e,t)=>H(e,t,m,v)):[],[i,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(!u)return(0,g.jsx)(n,{surface:`gate`});if(o)return(0,g.jsx)(`div`,{className:`activity-empty`,children:o});if(!i)return(0,g.jsx)(`div`,{className:`activity-empty`,children:`No response.`});let{accounts:X,census:Z,censusAgeMs:Q}=i,te=Date.now(),ne=X.onDisk!==null&&X.onDisk>X.valid,$=i.range===void 0?b:i.range;return(0,g.jsxs)(`div`,{className:`activity-body`,children:[(0,g.jsxs)(`div`,{className:`activity-head`,children:[(0,g.jsxs)(`span`,{className:`activity-title`,children:[(0,g.jsx)(r,{size:16}),` Live sessions`]}),(0,g.jsxs)(`span`,{className:`activity-meta`,children:[Y>0?`${U.length} of ${V.length} live · ${Y} hidden`:`${V.length} live`,` · `,X.valid,` accounts`,X.untaggedCount>0?` · ${X.untaggedCount} untagged`:``]})]}),(0,g.jsxs)(`div`,{className:`activity-controls`,children:[(0,g.jsxs)(`div`,{className:`activity-control activity-range`,children:[(0,g.jsx)(l,{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)(l,{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)(l,{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)(l,{variant:`secondary`,size:`sm`,"aria-pressed":b!==null&&!q(b),onClick:()=>x(ee(7,Date.now())),children:`Last 7 days`}),(0,g.jsx)(l,{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)(f,{checked:S,onChange:C,label:`Busy`}),(0,g.jsx)(f,{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.`,i.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)(l,{variant:`secondary`,size:`sm`,className:`activity-glossary-toggle`,onClick:()=>I(e=>!e),children:D?`Show fewer`:`Explain every figure`})]}),(0,g.jsx)(E,{loops:i?.loops})]})}function X({cacheKey:e}){let{adminFetch:t}=a({initialCacheKey:e,surface:`activity`});return(0,g.jsx)(Y,{adminFetch:t,cacheKey:e})}function Z(){let[e,t]=(0,h.useState)(null),[r,i]=(0,h.useState)(!1),[a,s]=(0,h.useState)(void 0),[c,l]=(0,h.useState)(null),[f,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),i(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async r=>{if(!e){if(r.status===401){try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`;return}if(r.ok)try{let e=await r.json();typeof e.businessName==`string`&&s(e.businessName),e.sessionId!==void 0&&l(e.sessionId??null),p(e.role??null),_(e.userName===void 0?null:e.userName),y(e.avatar??null)}catch{}t(n),i(!0)}}).catch(()=>{e||(t(n),i(!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 u();if(e){try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`}return e}finally{S(!1)}},[]);return r?e?(0,g.jsx)(o,{cacheKey:e,surface:`activity`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=activity`);try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`},children:(0,g.jsx)(d,{cacheKey:e,businessName:a,sessionId:c,onLogout:b,onDisconnect:C,disconnecting:x,userName:m,userAvatar:v,role:f,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)(n,{surface:`gate`})}(0,m.createRoot)(document.getElementById(`root`)).render((0,g.jsx)(Z,{}));
1
+ import{o as e}from"./chunk-CltuBf4Z.js";import{G as t,I as n,P as r,V as i,W as a,m as o,n as s,q as c}from"./useSubAccountSwitcher-BuUYMDWl.js";import{E as l,T as u,t as d,w as f}from"./AdminShell-CpaI2F_p.js";import{t as p}from"./triangle-alert-BNshRC13.js";var m=t(),h=e(c(),1),g=i(),_=`—`;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[i,a]=(0,h.useState)(null),[o,c]=(0,h.useState)(null),[l,d]=(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 s(t,e)&&(console.info(`[admin-ui] activity-card-open account=${e.slice(0,8)} session=${n.slice(0,8)}`),window.location.assign(`/chat?session=${encodeURIComponent(n)}`))},[t]),R=(0,h.useRef)(!1),z=(0,h.useRef)(void 0),B=(0,h.useCallback)(async t=>{if(R.current){z.current=t;return}R.current=!0;try{let n=await e(`/api/admin/activity${t?`?from=${t.from}&to=${t.to}`:``}`);if(n.status===403){c(`This view is available to the house account only.`),d(!0);return}if(!n.ok){c(`The session manager did not answer (status ${n.status}).`),d(!0);return}a(await n.json()),c(null)}catch(e){c(e instanceof Error?e.message:String(e))}finally{d(!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)(()=>i?[...i.rows].sort((e,t)=>H(e,t,m,v)):[],[i,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)(n,{surface:`gate`});if(o)return(0,g.jsx)(`div`,{className:`activity-empty`,children:o});if(!i)return(0,g.jsx)(`div`,{className:`activity-empty`,children:`No response.`});let{accounts:X,census:Z,censusAgeMs:Q}=i,te=Date.now(),ne=X.onDisk!==null&&X.onDisk>X.valid,$=i.range===void 0?b:i.range;return(0,g.jsxs)(`div`,{className:`activity-body`,children:[(0,g.jsxs)(`div`,{className:`activity-head`,children:[(0,g.jsxs)(`span`,{className:`activity-title`,children:[(0,g.jsx)(r,{size:16}),` Live sessions`]}),(0,g.jsxs)(`span`,{className:`activity-meta`,children:[Y>0?`${U.length} of ${V.length} live · ${Y} hidden`:`${V.length} live`,` · `,X.valid,` accounts`,X.untaggedCount>0?` · ${X.untaggedCount} untagged`:``]})]}),(0,g.jsxs)(`div`,{className:`activity-controls`,children:[(0,g.jsxs)(`div`,{className:`activity-control activity-range`,children:[(0,g.jsx)(f,{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)(f,{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)(f,{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)(f,{variant:`secondary`,size:`sm`,"aria-pressed":b!==null&&!q(b),onClick:()=>x(ee(7,Date.now())),children:`Last 7 days`}),(0,g.jsx)(f,{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)(u,{checked:S,onChange:C,label:`Busy`}),(0,g.jsx)(u,{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.`,i.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)(f,{variant:`secondary`,size:`sm`,className:`activity-glossary-toggle`,onClick:()=>I(e=>!e),children:D?`Show fewer`:`Explain every figure`})]}),(0,g.jsx)(E,{loops:i?.loops})]})}function X({cacheKey:e}){let{adminFetch:t}=a({initialCacheKey:e,surface:`activity`});return(0,g.jsx)(Y,{adminFetch:t,cacheKey:e})}function Z(){let[e,t]=(0,h.useState)(null),[r,i]=(0,h.useState)(!1),[a,s]=(0,h.useState)(void 0),[c,u]=(0,h.useState)(null),[f,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),i(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async r=>{if(!e){if(r.status===401){try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`;return}if(r.ok)try{let e=await r.json();typeof e.businessName==`string`&&s(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),i(!0)}}).catch(()=>{e||(t(n),i(!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 r?e?(0,g.jsx)(o,{cacheKey:e,surface:`activity`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=activity`);try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`},children:(0,g.jsx)(d,{cacheKey:e,businessName:a,sessionId:c,onLogout:b,onDisconnect:C,disconnecting:x,userName:m,userAvatar:v,role:f,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)(n,{surface:`gate`})}(0,m.createRoot)(document.getElementById(`root`)).render((0,g.jsx)(Z,{}));
@@ -0,0 +1 @@
1
+ import{o as e}from"./chunk-CltuBf4Z.js";import{G as t,H as n,O as r,V as i,a,h as o,m as s,q as c,s as l,u,y as ee}from"./useSubAccountSwitcher-BuUYMDWl.js";import{n as d,t as f}from"./AdminLoginScreens-Dar_MMJm.js";import{s as p,x as m}from"./useVoiceRecorder-BGqV5R6u.js";import{a as h,b as te,p as ne,t as g,v as _,x as re}from"./AdminShell-CpaI2F_p.js";import{i as v,n as y,r as ie}from"./page-CHt62f1_.js";import{t as b}from"./chevron-left-C2JEy7uU.js";import{t as x}from"./chevron-right-DWa047Ys.js";import{t as ae}from"./file-text-DwGAfCsd.js";import"./graph-labels-BbX3fXzl.js";var S=t(),C=e(c(),1),w=i();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)(b,{size:20})}),(0,w.jsx)(`span`,{className:`wa-web-avatar`,"aria-hidden":!0,children:(0,w.jsx)(m,{size:20})}),(0,w.jsx)(`div`,{className:`wa-web-titles`,children:(0,w.jsx)(`span`,{className:`wa-web-name`,children:r})})]}),(0,w.jsx)(`div`,{className:`wa-web-body`,children:(0,w.jsx)(p,{sessionId:e,projectDir:t,sessionKey:n,forceDeliveredOnly:!0})})]})}var D=6e4,O=60*D,k=24*O,A=D,j=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],M=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function N(e){return e<10?`0${e}`:String(e)}function P(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime()}function F(e,t){if(!Number.isFinite(e)||e<=0||!Number.isFinite(t))return`—`;let n=t-e;if(n<-A)return`—`;let r=n<0?0:n;if(r<D)return`just now`;if(r<O)return`${Math.floor(r/D)}m`;if(r<k)return`${Math.floor(r/O)}h`;let i=new Date(t),a=new Date(e),o=Math.round((P(i)-P(a))/k);if(o===1)return`yesterday`;if(o>=2&&o<=6)return M[a.getDay()];let s=N(a.getDate()),c=j[a.getMonth()];return a.getFullYear()===i.getFullYear()?`${s} ${c}`:`${s} ${c} ${a.getFullYear()}`}var oe={whatsapp:`WhatsApp`,telegram:`Telegram`,webchat:`Web chat`};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 se=6e4;function ce(e){return e<12?`morning`:e<18?`afternoon`:`evening`}function L(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 R(e){return e==null?`—`:`${Math.round(e*100)}%`}function ue(e){return e.operatorName??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 z(e){return e?e.replace(/^claude-/,``):null}var B=new Set([`sessions`,`conversations`,`tasks`,`artefacts`,`skills`,`stats`]),V=!1;function fe(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:i}){let s=o(e),[c,d]=(0,C.useState)(null),[f,p]=(0,C.useState)(null),[m,h]=(0,C.useState)(null),g=(0,C.useRef)(!1),[v,y]=(0,C.useState)(null),[b,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(),o=typeof n==`string`?n:`unresolved`;try{typeof n!=`string`&&(o=await n());let c=await s(o);if(!c.ok)throw Error(`status ${c.status}`);let l=await c.json();t||i(r(l)),console.info(`[admin-ui] op=dashboard-fetch slice=${e} url=${o} outcome=ok ms=${Date.now()-a}`)}catch(t){q.current.add(e),console.error(`[admin-ui] dashboard-fetch-failed slice=${e} url=${o} 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 s(`/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 console.info(`[admin-ui] op=dashboard-channels-source source=${t?`all`:`scoped`} account=${e.slice(0,8)}`),t?`/api/operator-conversations/conversations-all`:`/api/operator-conversations/conversations`}let a={"sidebar-sessions":()=>r(`sessions`,`/api/admin/sidebar-sessions`,e=>e.sessions??[],d),"conversations-all":()=>r(`conversations`,i,e=>e.conversations??[],p),"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 o(){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,y),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(console.info(`[admin-ui] op=dashboard-refresh-settled ms=${t}`),!V){V=!0;try{let e=fe(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{}}}}o();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`&&o()},se),u=()=>{document.visibilityState===`visible`&&o()};return document.addEventListener(`visibilitychange`,u),()=>{t=!0,G.current=!1,clearInterval(l),c?.close(),document.removeEventListener(`visibilitychange`,u)}},[e,s]);let Y=(0,C.useMemo)(()=>(c??[]).filter(e=>!e.isSubagent),[c]),X=(0,C.useMemo)(()=>Y.filter(e=>e.live),[Y]),pe=(0,C.useMemo)(()=>(f??[]).filter(e=>de(e.lastMessageAt,W)).length,[f,W]),me=b?.open.length??0,Z=(0,C.useMemo)(()=>{let e=new Map;for(let t of f??[]){let n=e.get(t.channel)??[];n.push(t),e.set(t.channel,n)}return[...e.entries()].map(([e,t])=>{let n=t.reduce((e,t)=>t.lastMessageAt&&(!e||Date.parse(t.lastMessageAt)>Date.parse(e.lastMessageAt??``))?t:e,null);return{channel:e,count:t.length,preview:n?ue(n):``,rows:t}})},[f]);(0,C.useEffect)(()=>{g.current||Z.length!==0&&(g.current=!0,h(Z[0].channel))},[Z]);let Q=(0,C.useRef)(!1);(0,C.useEffect)(()=>{Q.current||!B.has(`bookingLink`)||!B.has(`portalLink`)||(Q.current=!0,console.info(`[admin-ui] dashboard-public-pages booking=${k!=null} filedrop=${j!=null}`))},[B,k,j]);let he=(0,C.useCallback)(async e=>{if(!N.has(e)){P(t=>new Set(t).add(e));try{let t=await s(`/api/admin/session-stop`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e})});if(!t.ok){console.error(`[admin-ui] dashboard-session-stop-failed sessionId=${e} status=${t.status}`);return}console.info(`[admin-ui] dashboard-session-stop sessionId=${e}`),d(t=>(t??[]).map(t=>t.sessionId===e?{...t,live:!1}:t))}catch(t){console.error(`[admin-ui] dashboard-session-stop-failed sessionId=${e} reason=${t instanceof Error?t.message:String(t)}`)}finally{P(t=>{let n=new Set(t);return n.delete(e),n})}}},[s,N]),ge=(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}ie(e,t.downloadPath,t.downloadRoot??`data`)},[e]),$=ce(new Date(W).getHours());return(0,w.jsxs)(`div`,{className:`dashboard-home`,children:[(0,w.jsx)(`p`,{className:`dashboard-greeting`,children:B.has(`stats`)?`Good ${$}, ${L(t)} — ${le(v)}`:`Good ${$}, ${L(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:pe}):(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:me}):(0,w.jsx)(I,{variant:`value`})]}),(0,w.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,w.jsx)(`span`,{className:`dashboard-stat-label`,children:`Host CPU`}),B.has(`stats`)?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`span`,{className:`dashboard-stat-value`,children:R(v?.cpuPct??null)}),(0,w.jsxs)(`span`,{className:`dashboard-stat-delta`,children:[`RAM `,R(v?.memUsedPct??null)]})]}):(0,w.jsx)(I,{variant:`value`})]})]}),(0,w.jsxs)(`div`,{className:`dashboard-columns`,children:[(0,w.jsxs)(`div`,{className:`dashboard-col`,children:[(k||j)&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Public pages`}),(0,w.jsxs)(`div`,{className:`admin-card dashboard-public-pages`,children:[k&&(0,w.jsxs)(`a`,{className:`admin-row dashboard-public-row`,href:`https://${k}`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,w.jsx)(`span`,{className:`dashboard-public-icon`,children:(0,w.jsx)(_,{size:16})}),(0,w.jsx)(`span`,{className:`dashboard-public-name`,children:`Booking page`})]}),j&&(0,w.jsxs)(`a`,{className:`admin-row dashboard-public-row`,href:`https://${j}`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,w.jsx)(`span`,{className:`dashboard-public-icon`,children:(0,w.jsx)(_,{size:16})}),(0,w.jsx)(`span`,{className:`dashboard-public-name`,children:`File drop`})]})]})]}),(0,w.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Live now`}),B.has(`sessions`)?X.length===0?(0,w.jsx)(`div`,{className:`admin-card dashboard-empty`,children:`No live sessions right now.`}):X.map(e=>{let t=[e.sessionId.slice(0,8),z(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 he(e.sessionId),children:(0,w.jsx)(ee,{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:()=>ge(e),children:[(0,w.jsx)(`span`,{className:`dashboard-artefact-icon`,children:e.kind===`agent-template`?(0,w.jsx)(re,{size:16}):(0,w.jsx)(ae,{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)(ne,{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(e=>{let t=m===e.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":t,onClick:()=>h(t=>t===e.channel?null:e.channel),children:[(0,w.jsx)(`span`,{className:`dashboard-channel-glyph`,children:e.channel===`whatsapp`||e.channel===`telegram`?(0,w.jsx)(u,{channel:e.channel,size:16}):(0,w.jsx)(r,{size:16})}),(0,w.jsx)(`span`,{className:`dashboard-channel-name`,children:oe[e.channel]??e.channel}),(0,w.jsx)(`span`,{className:`dashboard-channel-badge`,children:e.count}),(0,w.jsx)(`span`,{className:`dashboard-channel-chevron`,children:t?(0,w.jsx)(te,{size:14}):(0,w.jsx)(x,{size:14})})]}),t?(0,w.jsx)(`div`,{className:`dashboard-channel-convs`,children:e.rows.map(e=>(0,w.jsxs)(`button`,{type:`button`,className:`admin-row dashboard-channel-conv-row`,onClick:()=>i(e),title:e.title,children:[(0,w.jsx)(`span`,{className:`dashboard-channel-conv-name`,children:a(e)}),e.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:e.isHouse?`House`:`Client`}),e.lastMessageAt&&(0,w.jsx)(`span`,{className:`dashboard-channel-conv-time`,children:F(Date.parse(e.lastMessageAt),W)})]},l(e)))}):e.preview&&(0,w.jsx)(`span`,{className:`dashboard-channel-preview`,children:e.preview})]},e.channel)}):(0,w.jsx)(I,{variant:`card`,count:2})]})]})]})}function U(){let e=d(),[t,n]=(0,C.useState)(!1);(0,C.useEffect)(()=>{if(!t)return;let e=e=>{e.key===`Escape`&&n(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let r=(0,C.useCallback)(async()=>{let t=e.claudeInfo!=null;if(n(!0),t){console.info(`[admin-ui] claude-info-open cached=true ms=0`);return}let r=Date.now();if(!e.cacheKey){console.error(`[admin-ui] claude-info-fetch-skipped reason=no-session-key`);return}try{let t=await fetch(`/api/admin/claude-info?session_key=${encodeURIComponent(e.cacheKey)}`);if(t.ok){let n=await t.json();e.setClaudeInfo(n)}console.info(`[admin-ui] claude-info-open cached=false ms=${Date.now()-r}`)}catch(e){console.error(`[admin-ui] claude-info-fetch-failed ms=${Date.now()-r} error="${e instanceof Error?e.message:String(e)}"`)}},[e]),i=(0,C.useCallback)(({code:t,path:n})=>{console.warn(`[admin-auth] outcome=chat-tab-logout-on-401 code=${t} path=${n}`),e.handleLogout()},[e]);return e.appState===`chat`?(0,w.jsx)(s,{cacheKey:e.cacheKey,onSessionExpired:i,surface:`chat`,children:(0,w.jsx)(g,{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)(h,{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)(y,{cacheKey:e.cacheKey}):t.selectedWhatsapp&&e.cacheKey?t.selectedWhatsapp.source===`store`&&t.selectedWhatsapp.remoteJid&&t.selectedWhatsapp.accountId?(0,w.jsx)(v,{accountId:t.selectedWhatsapp.accountId,remoteJid:t.selectedWhatsapp.remoteJid,contactName:a(t.selectedWhatsapp),sessionKey:e.cacheKey,onBack:t.onClearWhatsapp},l(t.selectedWhatsapp)):(0,w.jsx)(E,{sessionId:t.selectedWhatsapp.sessionId,projectDir:t.selectedWhatsapp.projectDir,sessionKey:e.cacheKey,contactName:a(t.selectedWhatsapp),onBack:t.onClearWhatsapp},l(t.selectedWhatsapp)):(0,w.jsx)(H,{cacheKey:e.cacheKey,userName:e.userName,onSelectWhatsappConversation:t.onSelectWhatsappConversation})})})}):(0,w.jsx)(f,{auth:e})}(0,S.createRoot)(document.getElementById(`root`)).render((0,w.jsx)(U,{}));
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{E as t,F as n,G as r,I as i,V as a,W as o,_ as s,m as c,q as l,v as u}from"./useSubAccountSwitcher-BufCPDDH.js";import{T as d,_ as f,b as p,t as m}from"./AdminShell-Bpo_wgxm.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`}]]),_=r(),v=e(l(),1);function y(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}var b=a(),x={read:`read`,write_local:`writes`,exec:`runs`,external:`sends`},S={read:`tool-chip-read`,write_local:`tool-chip-write_local`,exec:`tool-chip-exec`,external:`tool-chip-external`,unresolved:`tool-chip-unresolved`};function C({label:e,body:t}){return(0,b.jsxs)(`div`,{className:`agent-doc`,children:[(0,b.jsx)(`span`,{className:`agent-doc-label`,children:e}),(0,b.jsx)(`pre`,{className:`skill-body`,children:t.trim()||`Empty.`})]})}function w({summary:e,publicBaseUrl:n,accountId:r,adminFetch:i,onClose:a,onDeleted:o,onToggled:c}){let l=e.kind===`specialist`,d=e.origin===`shipped`,[m]=(0,v.useState)(r),[_,w]=(0,v.useState)(null),[T,E]=(0,v.useState)(!0),[D,O]=(0,v.useState)(null),[k,A]=(0,v.useState)(!1),[j,M]=(0,v.useState)(!1),[N,P]=(0,v.useState)(!1),[F,I]=(0,v.useState)(!1);(0,v.useEffect)(()=>{let t=!1;E(!0),O(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}`);w((await e.json()).agent)}}).catch(e=>{t||O(e instanceof Error?e.message:`Failed to load`)}).finally(()=>{t||E(!1)}),()=>{t=!0}},[i,e.slug]),(0,v.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!j&&a()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[j,a]);let L=(0,v.useCallback)(async()=>{M(!0),O(null);try{let t=await i(`/api/admin/agents/${encodeURIComponent(e.slug)}?accountId=${encodeURIComponent(m??``)}`,{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){O(e instanceof Error?e.message:`Delete failed`),M(!1),A(!1)}},[i,e,m,o]),R=(0,v.useCallback)(async()=>{let t=e.disabled?`enable`:`disable`;I(!0),O(null);try{let n=await i(`/api/admin/agents/${encodeURIComponent(e.slug)}/${t}?accountId=${encodeURIComponent(m??``)}`,{method:`POST`,headers:{"content-type":`application/json`}});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??`HTTP ${n.status}`)}c(),a()}catch(e){O(e instanceof Error?e.message:`${t} failed`),I(!1),P(!1)}},[i,e,m,c,a]),z=l?null:_,B=l?_:null;return(0,b.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{j||a()},children:(0,b.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":`Agent detail`,onClick:e=>e.stopPropagation(),children:[(0,b.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,b.jsxs)(`span`,{className:`cal-modal-kind`,children:[(0,b.jsx)(p,{size:13}),` `,l?`Specialist`:`Agent`]}),(0,b.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:a,"aria-label":`Close`,autoFocus:!0,disabled:j,children:(0,b.jsx)(s,{size:16})})]}),(0,b.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,b.jsx)(`div`,{className:`cal-modal-title`,children:e.displayName}),(0,b.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[!l&&(0,b.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),(0,b.jsxs)(`span`,{children:[`/`,e.slug]}),e.risk&&(0,b.jsx)(`span`,{className:`agent-risk-badge agent-risk-${e.risk}`,children:e.risk===`green`?`Read only`:e.risk===`amber`?`Writes`:`Runs`}),e.disabled&&(0,b.jsx)(`span`,{className:`agent-kind-pill agent-disabled-pill`,children:`Disabled`})]}),e.unresolved.length>0&&(0,b.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,b.jsxs)(`span`,{children:[`Forced to Runs: no declared risk class for `,e.unresolved.join(`, `),`.`]})}),T&&(0,b.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,b.jsx)(t,{size:14,className:`spin`}),(0,b.jsx)(`span`,{children:`Loading…`})]}),z&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,b.jsxs)(`span`,{children:[z.status,z.model?` · ${z.model}`:``]})}),(0,b.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,b.jsxs)(`a`,{href:`${n}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`cal-link`,children:[(0,b.jsx)(f,{size:13}),` Open agent`]})}),z.present.identity&&(0,b.jsx)(C,{label:`Identity`,body:z.identity}),z.present.soul&&(0,b.jsx)(C,{label:`Soul`,body:z.soul}),z.present.knowledge&&(0,b.jsx)(C,{label:`Knowledge`,body:z.knowledge}),z.present.knowledgeSummary&&(0,b.jsx)(C,{label:`Knowledge summary`,body:z.knowledgeSummary}),z.knowledgeKeywords.length>0&&(0,b.jsxs)(`div`,{className:`skill-refs`,children:[(0,b.jsx)(`span`,{className:`skill-refs-label`,children:`Knowledge keywords`}),z.knowledgeKeywords.map(e=>(0,b.jsx)(`span`,{className:`skill-ref`,children:e},e))]})]}),B&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,b.jsxs)(`span`,{children:[e.plugin,B.model?` · ${B.model}`:``]})}),B.description&&(0,b.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,b.jsx)(`span`,{children:B.description})}),B.byTool.length>0&&(0,b.jsxs)(`div`,{className:`chip-refs`,children:[(0,b.jsxs)(`span`,{className:`skill-refs-label`,children:[`Tools (`,B.byTool.length,`)`,B.riskiestTool?` · riskiest: ${y(B.riskiestTool)}`:``]}),(0,b.jsx)(`div`,{className:`chip-row`,children:B.byTool.map(({tool:e,risk:t})=>(0,b.jsx)(`span`,{"data-testid":`tool-chip-${e}`,className:`tool-chip ${S[t??`unresolved`]}`,title:t?`${e} — ${x[t]}`:`${e} — no declared risk class`,children:y(e)},e))})]}),B.skills.length>0&&(0,b.jsxs)(`div`,{className:`chip-refs`,children:[(0,b.jsx)(`span`,{className:`skill-refs-label`,children:`Skills`}),(0,b.jsx)(`div`,{className:`chip-row`,children:B.skills.map(e=>(0,b.jsx)(`span`,{className:`tool-chip tool-chip-skill`,children:e},e))})]}),(0,b.jsx)(C,{label:`System prompt`,body:B.systemPrompt})]})]}),D&&(0,b.jsx)(`div`,{className:`cal-modal-error`,children:D}),(0,b.jsx)(`div`,{className:`cal-modal-actions`,children:d?N?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`span`,{className:`cal-modal-confirm-text`,children:e.disabled?`Put this agent back in the dispatchable set?`:`Stop this agent being dispatched?`}),(0,b.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:R,disabled:F,children:[F?(0,b.jsx)(t,{size:14,className:`spin`}):e.disabled?(0,b.jsx)(g,{size:14}):(0,b.jsx)(h,{size:14}),e.disabled?` Enable`:` Disable`]}),(0,b.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>P(!1),disabled:F,children:`Cancel`})]}):(0,b.jsx)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:()=>P(!0),disabled:F||T||!m,children:e.disabled?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(g,{size:14}),` Enable`]}):(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(h,{size:14}),` Disable`]})}):l?(0,b.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Edit in chat via agent-builder.`}):(0,b.jsxs)(b.Fragment,{children:[!k&&(0,b.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:()=>A(!0),disabled:j||T||!m,children:[(0,b.jsx)(u,{size:14}),` Delete`]}),k&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Delete this agent?`}),(0,b.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:L,disabled:j,children:[j?(0,b.jsx)(t,{size:14,className:`spin`}):(0,b.jsx)(u,{size:14}),` Delete`]}),(0,b.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>A(!1),disabled:j,children:`Cancel`})]})]})})]})})}var T=`maxy-admin-session-key`,E={green:`Read only`,amber:`Writes`,red:`Runs`},D={shipped:`Shipped`,specialist:`Specialist`,public:`Public`};function O(){let[e,t]=(0,v.useState)(null),[n,r]=(0,v.useState)(!1),[a,o]=(0,v.useState)(void 0),[s,l]=(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(T)}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(T)}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&&l(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(T)}catch{}window.location.href=`/`},[]),[x,S]=(0,v.useState)(!1),C=(0,v.useCallback)(async()=>{S(!0);try{let e=await d();if(e){try{sessionStorage.removeItem(T)}catch{}window.location.href=`/`}return e}finally{S(!1)}},[]);return n?e?(0,b.jsx)(c,{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(T)}catch{}window.location.href=`/`},children:(0,b.jsx)(m,{cacheKey:e,businessName:a,sessionId:s,onLogout:y,onDisconnect:C,disconnecting:x,userName:u,userAvatar:p,role:g,children:(0,b.jsx)(k,{cacheKey:e})})}):(0,b.jsx)(`div`,{className:`cal-page`,children:(0,b.jsxs)(`div`,{className:`cal-empty`,children:[(0,b.jsx)(`p`,{children:`You are not signed in.`}),(0,b.jsxs)(`p`,{children:[`Open the `,(0,b.jsx)(`a`,{href:`/`,className:`cal-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,b.jsx)(i,{surface:`gate`})}function k({cacheKey:e}){let{adminFetch:n,sessionRefetchNonce:r}=o({initialCacheKey:e,surface:`agents`}),[a,s]=(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),[_,x]=(0,v.useState)(!1),[S,C]=(0,v.useState)(!1),[T,O]=(0,v.useState)(null),[k,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 x(!0),O(null),n(`/api/admin/agents`).then(async t=>{if(e)return;if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();s(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||(O(t instanceof Error?t.message:`Failed to load`),s([]))}).finally(()=>{e||(x(!1),C(!0))}),()=>{e=!0}},[n]);(0,v.useEffect)(()=>N(),[N,r]);let P=(0,v.useCallback)(e=>{s(t=>t.filter(t=>t.slug!==e.slug)),A(null),N()},[N]);return S?(0,b.jsxs)(`div`,{className:`cal-page`,children:[(0,b.jsx)(`header`,{className:`cal-header`,children:(0,b.jsxs)(`div`,{className:`cal-nav`,children:[(0,b.jsxs)(`span`,{className:`cal-range-label`,children:[(0,b.jsx)(p,{size:16}),` Agents`]}),_&&(0,b.jsx)(t,{size:16,className:`spin`})]})}),(0,b.jsxs)(`div`,{className:`cal-body`,children:[T&&(0,b.jsxs)(`div`,{className:`cal-error`,children:[`Could not load agents: `,T]}),f&&(0,b.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,b.jsxs)(`div`,{className:`cal-error`,children:[c+u,` agent`,c+u===1?``:`s`,` could not be read (malformed config or frontmatter).`]}),!T&&!_&&a.length===0&&(0,b.jsx)(`div`,{className:`cal-empty`,children:(0,b.jsx)(`p`,{children:`No agents yet. Ask in chat to create one.`})}),a.length>0&&(0,b.jsx)(`div`,{className:`routine-list`,children:a.map(e=>(0,b.jsxs)(`button`,{type:`button`,className:`routine-card`,onClick:()=>A(e),children:[(0,b.jsxs)(`span`,{className:`routine-card-title`,children:[e.displayName,e.risk&&(0,b.jsx)(`span`,{className:`agent-risk-badge agent-risk-${e.risk}`,"data-testid":`agent-risk-badge`,children:E[e.risk]}),(0,b.jsx)(`span`,{className:`agent-kind-pill agent-origin-${e.origin}`,children:D[e.origin]}),e.disabled&&(0,b.jsx)(`span`,{className:`agent-kind-pill agent-disabled-pill`,children:`Disabled`})]}),e.kind===`specialist`?(0,b.jsxs)(`span`,{className:`routine-card-sched`,children:[`/`,e.slug]}):(0,b.jsxs)(`span`,{className:`routine-card-sched`,children:[(0,b.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),` /`,e.slug]}),(0,b.jsx)(`span`,{className:`routine-card-meta`,children:e.origin===`public`?e.status:e.riskiestTool?`riskiest tool: ${y(e.riskiestTool)}`:e.plugin})]},`${e.origin}:${e.slug}`))})]}),k&&(0,b.jsx)(w,{summary:k,publicBaseUrl:j,accountId:h,adminFetch:n,onClose:()=>A(null),onDeleted:P,onToggled:N})]}):(0,b.jsx)(i,{surface:`gate`})}(0,_.createRoot)(document.getElementById(`root`)).render((0,b.jsx)(O,{}));
1
+ import{o as e}from"./chunk-CltuBf4Z.js";import{E as t,F as n,G as r,I as i,V as a,W as o,_ as s,m as c,q as l,v as u}from"./useSubAccountSwitcher-BuUYMDWl.js";import{E as d,t as f,v as p,x as m}from"./AdminShell-CpaI2F_p.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`}]]),_=r(),v=e(l(),1);function y(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}var b=a(),x={read:`read`,write_local:`writes`,exec:`runs`,external:`sends`},S={read:`tool-chip-read`,write_local:`tool-chip-write_local`,exec:`tool-chip-exec`,external:`tool-chip-external`,unresolved:`tool-chip-unresolved`};function C({label:e,body:t}){return(0,b.jsxs)(`div`,{className:`agent-doc`,children:[(0,b.jsx)(`span`,{className:`agent-doc-label`,children:e}),(0,b.jsx)(`pre`,{className:`skill-body`,children:t.trim()||`Empty.`})]})}function w({summary:e,publicBaseUrl:n,accountId:r,adminFetch:i,onClose:a,onDeleted:o,onToggled:c}){let l=e.kind===`specialist`,d=e.origin===`shipped`,[f]=(0,v.useState)(r),[_,w]=(0,v.useState)(null),[T,E]=(0,v.useState)(!0),[D,O]=(0,v.useState)(null),[k,A]=(0,v.useState)(!1),[j,M]=(0,v.useState)(!1),[N,P]=(0,v.useState)(!1),[F,I]=(0,v.useState)(!1);(0,v.useEffect)(()=>{let t=!1;E(!0),O(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}`);w((await e.json()).agent)}}).catch(e=>{t||O(e instanceof Error?e.message:`Failed to load`)}).finally(()=>{t||E(!1)}),()=>{t=!0}},[i,e.slug]),(0,v.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!j&&a()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[j,a]);let L=(0,v.useCallback)(async()=>{M(!0),O(null);try{let t=await i(`/api/admin/agents/${encodeURIComponent(e.slug)}?accountId=${encodeURIComponent(f??``)}`,{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){O(e instanceof Error?e.message:`Delete failed`),M(!1),A(!1)}},[i,e,f,o]),R=(0,v.useCallback)(async()=>{let t=e.disabled?`enable`:`disable`;I(!0),O(null);try{let n=await i(`/api/admin/agents/${encodeURIComponent(e.slug)}/${t}?accountId=${encodeURIComponent(f??``)}`,{method:`POST`,headers:{"content-type":`application/json`}});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??`HTTP ${n.status}`)}c(),a()}catch(e){O(e instanceof Error?e.message:`${t} failed`),I(!1),P(!1)}},[i,e,f,c,a]),z=l?null:_,B=l?_:null;return(0,b.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{j||a()},children:(0,b.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":`Agent detail`,onClick:e=>e.stopPropagation(),children:[(0,b.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,b.jsxs)(`span`,{className:`cal-modal-kind`,children:[(0,b.jsx)(m,{size:13}),` `,l?`Specialist`:`Agent`]}),(0,b.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:a,"aria-label":`Close`,autoFocus:!0,disabled:j,children:(0,b.jsx)(s,{size:16})})]}),(0,b.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,b.jsx)(`div`,{className:`cal-modal-title`,children:e.displayName}),(0,b.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[!l&&(0,b.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),(0,b.jsxs)(`span`,{children:[`/`,e.slug]}),e.risk&&(0,b.jsx)(`span`,{className:`agent-risk-badge agent-risk-${e.risk}`,children:e.risk===`green`?`Read only`:e.risk===`amber`?`Writes`:`Runs`}),e.disabled&&(0,b.jsx)(`span`,{className:`agent-kind-pill agent-disabled-pill`,children:`Disabled`})]}),e.unresolved.length>0&&(0,b.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,b.jsxs)(`span`,{children:[`Forced to Runs: no declared risk class for `,e.unresolved.join(`, `),`.`]})}),T&&(0,b.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,b.jsx)(t,{size:14,className:`spin`}),(0,b.jsx)(`span`,{children:`Loading…`})]}),z&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,b.jsxs)(`span`,{children:[z.status,z.model?` · ${z.model}`:``]})}),(0,b.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,b.jsxs)(`a`,{href:`${n}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`cal-link`,children:[(0,b.jsx)(p,{size:13}),` Open agent`]})}),z.present.identity&&(0,b.jsx)(C,{label:`Identity`,body:z.identity}),z.present.soul&&(0,b.jsx)(C,{label:`Soul`,body:z.soul}),z.present.knowledge&&(0,b.jsx)(C,{label:`Knowledge`,body:z.knowledge}),z.present.knowledgeSummary&&(0,b.jsx)(C,{label:`Knowledge summary`,body:z.knowledgeSummary}),z.knowledgeKeywords.length>0&&(0,b.jsxs)(`div`,{className:`skill-refs`,children:[(0,b.jsx)(`span`,{className:`skill-refs-label`,children:`Knowledge keywords`}),z.knowledgeKeywords.map(e=>(0,b.jsx)(`span`,{className:`skill-ref`,children:e},e))]})]}),B&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,b.jsxs)(`span`,{children:[e.plugin,B.model?` · ${B.model}`:``]})}),B.description&&(0,b.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,b.jsx)(`span`,{children:B.description})}),B.byTool.length>0&&(0,b.jsxs)(`div`,{className:`chip-refs`,children:[(0,b.jsxs)(`span`,{className:`skill-refs-label`,children:[`Tools (`,B.byTool.length,`)`,B.riskiestTool?` · riskiest: ${y(B.riskiestTool)}`:``]}),(0,b.jsx)(`div`,{className:`chip-row`,children:B.byTool.map(({tool:e,risk:t})=>(0,b.jsx)(`span`,{"data-testid":`tool-chip-${e}`,className:`tool-chip ${S[t??`unresolved`]}`,title:t?`${e} — ${x[t]}`:`${e} — no declared risk class`,children:y(e)},e))})]}),B.skills.length>0&&(0,b.jsxs)(`div`,{className:`chip-refs`,children:[(0,b.jsx)(`span`,{className:`skill-refs-label`,children:`Skills`}),(0,b.jsx)(`div`,{className:`chip-row`,children:B.skills.map(e=>(0,b.jsx)(`span`,{className:`tool-chip tool-chip-skill`,children:e},e))})]}),(0,b.jsx)(C,{label:`System prompt`,body:B.systemPrompt})]})]}),D&&(0,b.jsx)(`div`,{className:`cal-modal-error`,children:D}),(0,b.jsx)(`div`,{className:`cal-modal-actions`,children:d?N?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`span`,{className:`cal-modal-confirm-text`,children:e.disabled?`Put this agent back in the dispatchable set?`:`Stop this agent being dispatched?`}),(0,b.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:R,disabled:F,children:[F?(0,b.jsx)(t,{size:14,className:`spin`}):e.disabled?(0,b.jsx)(g,{size:14}):(0,b.jsx)(h,{size:14}),e.disabled?` Enable`:` Disable`]}),(0,b.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>P(!1),disabled:F,children:`Cancel`})]}):(0,b.jsx)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:()=>P(!0),disabled:F||T||!f,children:e.disabled?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(g,{size:14}),` Enable`]}):(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(h,{size:14}),` Disable`]})}):l?(0,b.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Edit in chat via agent-builder.`}):(0,b.jsxs)(b.Fragment,{children:[!k&&(0,b.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:()=>A(!0),disabled:j||T||!f,children:[(0,b.jsx)(u,{size:14}),` Delete`]}),k&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Delete this agent?`}),(0,b.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:L,disabled:j,children:[j?(0,b.jsx)(t,{size:14,className:`spin`}):(0,b.jsx)(u,{size:14}),` Delete`]}),(0,b.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>A(!1),disabled:j,children:`Cancel`})]})]})})]})})}var T=`maxy-admin-session-key`,E={green:`Read only`,amber:`Writes`,red:`Runs`},D={shipped:`Shipped`,specialist:`Specialist`,public:`Public`};function O(){let[e,t]=(0,v.useState)(null),[n,r]=(0,v.useState)(!1),[a,o]=(0,v.useState)(void 0),[s,l]=(0,v.useState)(null),[u,p]=(0,v.useState)(void 0),[m,h]=(0,v.useState)(null),[g,_]=(0,v.useState)(null);(0,v.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(T)}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(T)}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&&l(e.sessionId??null),_(e.role??null),p(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(T)}catch{}window.location.href=`/`},[]),[x,S]=(0,v.useState)(!1),C=(0,v.useCallback)(async()=>{S(!0);try{let e=await d();if(e){try{sessionStorage.removeItem(T)}catch{}window.location.href=`/`}return e}finally{S(!1)}},[]);return n?e?(0,b.jsx)(c,{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(T)}catch{}window.location.href=`/`},children:(0,b.jsx)(f,{cacheKey:e,businessName:a,sessionId:s,onLogout:y,onDisconnect:C,disconnecting:x,userName:u,userAvatar:m,role:g,children:(0,b.jsx)(k,{cacheKey:e})})}):(0,b.jsx)(`div`,{className:`cal-page`,children:(0,b.jsxs)(`div`,{className:`cal-empty`,children:[(0,b.jsx)(`p`,{children:`You are not signed in.`}),(0,b.jsxs)(`p`,{children:[`Open the `,(0,b.jsx)(`a`,{href:`/`,className:`cal-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,b.jsx)(i,{surface:`gate`})}function k({cacheKey:e}){let{adminFetch:n,sessionRefetchNonce:r}=o({initialCacheKey:e,surface:`agents`}),[a,s]=(0,v.useState)([]),[c,l]=(0,v.useState)(0),[u,d]=(0,v.useState)(0),[f,p]=(0,v.useState)(!1),[h,g]=(0,v.useState)(null),[_,x]=(0,v.useState)(!1),[S,C]=(0,v.useState)(!1),[T,O]=(0,v.useState)(null),[k,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 x(!0),O(null),n(`/api/admin/agents`).then(async t=>{if(e)return;if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();s(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),p(n.riskSurfaceFailed===!0)}).catch(t=>{e||(O(t instanceof Error?t.message:`Failed to load`),s([]))}).finally(()=>{e||(x(!1),C(!0))}),()=>{e=!0}},[n]);(0,v.useEffect)(()=>N(),[N,r]);let P=(0,v.useCallback)(e=>{s(t=>t.filter(t=>t.slug!==e.slug)),A(null),N()},[N]);return S?(0,b.jsxs)(`div`,{className:`cal-page`,children:[(0,b.jsx)(`header`,{className:`cal-header`,children:(0,b.jsxs)(`div`,{className:`cal-nav`,children:[(0,b.jsxs)(`span`,{className:`cal-range-label`,children:[(0,b.jsx)(m,{size:16}),` Agents`]}),_&&(0,b.jsx)(t,{size:16,className:`spin`})]})}),(0,b.jsxs)(`div`,{className:`cal-body`,children:[T&&(0,b.jsxs)(`div`,{className:`cal-error`,children:[`Could not load agents: `,T]}),f&&(0,b.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,b.jsxs)(`div`,{className:`cal-error`,children:[c+u,` agent`,c+u===1?``:`s`,` could not be read (malformed config or frontmatter).`]}),!T&&!_&&a.length===0&&(0,b.jsx)(`div`,{className:`cal-empty`,children:(0,b.jsx)(`p`,{children:`No agents yet. Ask in chat to create one.`})}),a.length>0&&(0,b.jsx)(`div`,{className:`routine-list`,children:a.map(e=>(0,b.jsxs)(`button`,{type:`button`,className:`routine-card`,onClick:()=>A(e),children:[(0,b.jsxs)(`span`,{className:`routine-card-title`,children:[e.displayName,e.risk&&(0,b.jsx)(`span`,{className:`agent-risk-badge agent-risk-${e.risk}`,"data-testid":`agent-risk-badge`,children:E[e.risk]}),(0,b.jsx)(`span`,{className:`agent-kind-pill agent-origin-${e.origin}`,children:D[e.origin]}),e.disabled&&(0,b.jsx)(`span`,{className:`agent-kind-pill agent-disabled-pill`,children:`Disabled`})]}),e.kind===`specialist`?(0,b.jsxs)(`span`,{className:`routine-card-sched`,children:[`/`,e.slug]}):(0,b.jsxs)(`span`,{className:`routine-card-sched`,children:[(0,b.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),` /`,e.slug]}),(0,b.jsx)(`span`,{className:`routine-card-meta`,children:e.origin===`public`?e.status:e.riskiestTool?`riskiest tool: ${y(e.riskiestTool)}`:e.plugin})]},`${e.origin}:${e.slug}`))})]}),k&&(0,b.jsx)(w,{summary:k,publicBaseUrl:j,accountId:h,adminFetch:n,onClose:()=>A(null),onDeleted:P,onToggled:N})]}):(0,b.jsx)(i,{surface:`gate`})}(0,_.createRoot)(document.getElementById(`root`)).render((0,b.jsx)(O,{}));
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{E as t,G as n,L as r,O as i,V as a,h as o,m as s,q as c}from"./useSubAccountSwitcher-BufCPDDH.js";import{T as l,_ as u,t as d}from"./AdminShell-Bpo_wgxm.js";var f=n(),p=e(c(),1),m=a(),h=`maxy-vnc-popout`;function g(){let[e,n]=(0,p.useState)(null),[a,s]=(0,p.useState)(!1),[c,l]=(0,p.useState)(null),d=o(null);(0,p.useEffect)(()=>{let e=!1;return fetch(`/vnc-viewer.html`,{method:`HEAD`}).then(t=>{e||(console.info(`[browser-page] op=viewer-probe available=${t.ok}`),n(t.ok))}).catch(()=>{e||(console.info(`[browser-page] op=viewer-probe available=false`),n(!1))}),()=>{e=!0}},[]);let f=(0,p.useCallback)(()=>{window.open(`/vnc-popout.html?title=${encodeURIComponent(r.productName)}`,h,`width=1024,height=768`)},[]),g=(0,p.useCallback)(async()=>{s(!0),l(null);try{let e=await d(`/api/admin/browser/launch`,{method:`POST`});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error||`Launch failed (${e.status})`)}}catch(e){l(e instanceof Error?e.message:String(e))}finally{s(!1)}},[d]);return e===null?(0,m.jsx)(`div`,{className:`vnc-surface`,children:(0,m.jsxs)(`div`,{className:`data-loading`,children:[(0,m.jsx)(t,{size:18,className:`spin`}),` Checking viewer…`]})}):e?(0,m.jsxs)(`div`,{className:`vnc-surface`,children:[(0,m.jsxs)(`div`,{className:`vnc-surface__toolbar`,children:[(0,m.jsxs)(`button`,{type:`button`,className:`vnc-surface__btn`,onClick:g,disabled:a,children:[a?(0,m.jsx)(t,{size:14,className:`spin`}):(0,m.jsx)(i,{size:14}),` Launch browser`]}),(0,m.jsxs)(`button`,{type:`button`,className:`vnc-surface__btn`,onClick:f,children:[(0,m.jsx)(u,{size:14}),` Pop out`]}),c&&(0,m.jsx)(`span`,{className:`vnc-surface__error`,children:c})]}),(0,m.jsx)(`div`,{className:`vnc-surface__viewport`,children:(0,m.jsx)(`iframe`,{className:`vnc-surface__iframe`,src:`/vnc-viewer.html`,title:`VNC viewer`})})]}):(0,m.jsx)(`div`,{className:`vnc-surface`,children:(0,m.jsxs)(`div`,{className:`vnc-surface__unavailable`,children:[(0,m.jsx)(i,{size:28,strokeWidth:1.75}),(0,m.jsx)(`p`,{children:`VNC surface not available on this platform.`})]})})}function _(){let[e,n]=(0,p.useState)(null),[r,a]=(0,p.useState)(!1),[o,c]=(0,p.useState)(void 0),[u,f]=(0,p.useState)(null),[h,_]=(0,p.useState)(void 0),[v,y]=(0,p.useState)(null),[b,x]=(0,p.useState)(null);(0,p.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`&&c(e.businessName),e.sessionId!==void 0&&f(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,p.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]),[C,w]=(0,p.useState)(!1),T=(0,p.useCallback)(async()=>{w(!0);try{let e=await l();if(e){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`}return e}finally{w(!1)}},[]);return r?e?(0,m.jsx)(s,{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,m.jsx)(d,{cacheKey:e,businessName:o,sessionId:u,onLogout:S,onDisconnect:T,disconnecting:C,userName:h,userAvatar:v,role:b,children:(0,m.jsxs)(`div`,{className:`data-page`,children:[(0,m.jsx)(`header`,{className:`data-header`,children:(0,m.jsxs)(`h1`,{className:`data-title`,children:[(0,m.jsx)(i,{size:18}),` Browser`]})}),(0,m.jsx)(g,{})]})})}):(0,m.jsxs)(`div`,{className:`data-page`,children:[(0,m.jsx)(`header`,{className:`data-header`,children:(0,m.jsxs)(`h1`,{className:`data-title`,children:[(0,m.jsx)(i,{size:18}),` Browser`]})}),(0,m.jsxs)(`div`,{className:`data-empty`,children:[(0,m.jsx)(`p`,{children:`You are not signed in.`}),(0,m.jsxs)(`p`,{children:[`Open the `,(0,m.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})]}):(0,m.jsx)(`div`,{className:`data-page`,children:(0,m.jsxs)(`div`,{className:`data-loading`,children:[(0,m.jsx)(t,{size:18,className:`spin`}),` Loading…`]})})}(0,f.createRoot)(document.getElementById(`root`)).render((0,m.jsx)(_,{}));
1
+ import{o as e}from"./chunk-CltuBf4Z.js";import{E as t,G as n,L as r,O as i,V as a,h as o,m as s,q as c}from"./useSubAccountSwitcher-BuUYMDWl.js";import{E as l,t as u,v as d}from"./AdminShell-CpaI2F_p.js";var f=n(),p=e(c(),1),m=a(),h=`maxy-vnc-popout`;function g(){let[e,n]=(0,p.useState)(null),[a,s]=(0,p.useState)(!1),[c,l]=(0,p.useState)(null),u=o(null);(0,p.useEffect)(()=>{let e=!1;return fetch(`/vnc-viewer.html`,{method:`HEAD`}).then(t=>{e||(console.info(`[browser-page] op=viewer-probe available=${t.ok}`),n(t.ok))}).catch(()=>{e||(console.info(`[browser-page] op=viewer-probe available=false`),n(!1))}),()=>{e=!0}},[]);let f=(0,p.useCallback)(()=>{window.open(`/vnc-popout.html?title=${encodeURIComponent(r.productName)}`,h,`width=1024,height=768`)},[]),g=(0,p.useCallback)(async()=>{s(!0),l(null);try{let e=await u(`/api/admin/browser/launch`,{method:`POST`});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error||`Launch failed (${e.status})`)}}catch(e){l(e instanceof Error?e.message:String(e))}finally{s(!1)}},[u]);return e===null?(0,m.jsx)(`div`,{className:`vnc-surface`,children:(0,m.jsxs)(`div`,{className:`data-loading`,children:[(0,m.jsx)(t,{size:18,className:`spin`}),` Checking viewer…`]})}):e?(0,m.jsxs)(`div`,{className:`vnc-surface`,children:[(0,m.jsxs)(`div`,{className:`vnc-surface__toolbar`,children:[(0,m.jsxs)(`button`,{type:`button`,className:`vnc-surface__btn`,onClick:g,disabled:a,children:[a?(0,m.jsx)(t,{size:14,className:`spin`}):(0,m.jsx)(i,{size:14}),` Launch browser`]}),(0,m.jsxs)(`button`,{type:`button`,className:`vnc-surface__btn`,onClick:f,children:[(0,m.jsx)(d,{size:14}),` Pop out`]}),c&&(0,m.jsx)(`span`,{className:`vnc-surface__error`,children:c})]}),(0,m.jsx)(`div`,{className:`vnc-surface__viewport`,children:(0,m.jsx)(`iframe`,{className:`vnc-surface__iframe`,src:`/vnc-viewer.html`,title:`VNC viewer`})})]}):(0,m.jsx)(`div`,{className:`vnc-surface`,children:(0,m.jsxs)(`div`,{className:`vnc-surface__unavailable`,children:[(0,m.jsx)(i,{size:28,strokeWidth:1.75}),(0,m.jsx)(`p`,{children:`VNC surface not available on this platform.`})]})})}function _(){let[e,n]=(0,p.useState)(null),[r,a]=(0,p.useState)(!1),[o,c]=(0,p.useState)(void 0),[d,f]=(0,p.useState)(null),[h,_]=(0,p.useState)(void 0),[v,y]=(0,p.useState)(null),[b,x]=(0,p.useState)(null);(0,p.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`&&c(e.businessName),e.sessionId!==void 0&&f(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,p.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]),[C,w]=(0,p.useState)(!1),T=(0,p.useCallback)(async()=>{w(!0);try{let e=await l();if(e){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`}return e}finally{w(!1)}},[]);return r?e?(0,m.jsx)(s,{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,m.jsx)(u,{cacheKey:e,businessName:o,sessionId:d,onLogout:S,onDisconnect:T,disconnecting:C,userName:h,userAvatar:v,role:b,children:(0,m.jsxs)(`div`,{className:`data-page`,children:[(0,m.jsx)(`header`,{className:`data-header`,children:(0,m.jsxs)(`h1`,{className:`data-title`,children:[(0,m.jsx)(i,{size:18}),` Browser`]})}),(0,m.jsx)(g,{})]})})}):(0,m.jsxs)(`div`,{className:`data-page`,children:[(0,m.jsx)(`header`,{className:`data-header`,children:(0,m.jsxs)(`h1`,{className:`data-title`,children:[(0,m.jsx)(i,{size:18}),` Browser`]})}),(0,m.jsxs)(`div`,{className:`data-empty`,children:[(0,m.jsx)(`p`,{children:`You are not signed in.`}),(0,m.jsxs)(`p`,{children:[`Open the `,(0,m.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})]}):(0,m.jsx)(`div`,{className:`data-page`,children:(0,m.jsxs)(`div`,{className:`data-loading`,children:[(0,m.jsx)(t,{size:18,className:`spin`}),` Loading…`]})})}(0,f.createRoot)(document.getElementById(`root`)).render((0,m.jsx)(_,{}));
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{A as t,C as n,E as r,F as i,G as a,I as o,V as s,W as c,_ as l,m as u,q as d,v as f}from"./useSubAccountSwitcher-BufCPDDH.js";import{T as p,_ as m,t as h}from"./AdminShell-Bpo_wgxm.js";import{t as g}from"./chevron-left-DWt5cdUo.js";import{t as _}from"./chevron-right-B9suVrYy.js";import{t as v}from"./clock-DW6qVXtv.js";var y=i(`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`}]]),b=i(`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`}]]),x=i(`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`}]]),S=i(`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`}]]),C=i(`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`}]]),w=a(),T=e(d(),1);function E(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function D(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n}function O(e){let t=E(e),n=t.getDay();return D(t,n===0?-6:1-n)}function k(e){let t=O(e);return Array.from({length:7},(e,n)=>D(t,n))}function A(e){let t=O(new Date(e.getFullYear(),e.getMonth(),1));return Array.from({length:42},(e,n)=>D(t,n))}function j(){return Array.from({length:24},(e,t)=>t)}function M(e){let t=e.getFullYear();return Array.from({length:12},(e,n)=>new Date(t,n,1))}function N(e,t){switch(e){case`day`:{let e=E(t);return{from:e,to:D(e,1)}}case`week`:{let e=O(t);return{from:e,to:D(e,7)}}case`month`:{let e=O(new Date(t.getFullYear(),t.getMonth(),1));return{from:e,to:D(e,42)}}case`year`:return{from:new Date(t.getFullYear(),0,1),to:new Date(t.getFullYear()+1,0,1)}}}function P(e,t,n){switch(e){case`day`:return D(t,n);case`week`:return D(t,n*7);case`month`:return new Date(t.getFullYear(),t.getMonth()+n,1);case`year`:return new Date(t.getFullYear()+n,t.getMonth(),1)}}function F(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function I(e,t){return{role:`button`,tabIndex:0,onClick:()=>t(e),onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),t(e))}}}var L=s(),ee=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],R=3;function z(e){return e.toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`})}function B({anchor:e,meetings:t,onSelect:n}){let r=A(e),i=e.getMonth(),a=new Date;return(0,L.jsxs)(`div`,{className:`cal-month`,children:[(0,L.jsx)(`div`,{className:`cal-weekday-row`,children:ee.map(e=>(0,L.jsx)(`div`,{className:`cal-weekday`,children:e},e))}),(0,L.jsx)(`div`,{className:`cal-month-grid`,children:r.map(e=>{let r=t.filter(t=>F(new Date(t.startsAt),e)).sort((e,t)=>e.startsAt.localeCompare(t.startsAt)),o=e.getMonth()!==i,s=F(e,a);return(0,L.jsxs)(`div`,{className:`cal-cell${o?` cal-cell-out`:``}${s?` cal-cell-today`:``}`,children:[(0,L.jsx)(`div`,{className:`cal-cell-num`,children:e.getDate()}),r.slice(0,R).map(e=>(0,L.jsxs)(`div`,{className:`cal-chip`,title:e.title??`Untitled`,...I(e,n),children:[!e.isAllDay&&(0,L.jsx)(`span`,{className:`cal-chip-time`,children:z(new Date(e.startsAt))}),e.title??`Untitled`]},e.meetingId)),r.length>R&&(0,L.jsxs)(`div`,{className:`cal-more`,children:[`+`,r.length-R,` more`]})]},e.toISOString())})})]})}var V=1440,H=1.8;function U(e){return e.getHours()*60+e.getMinutes()}function W(e){return e.toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`})}function G({day:e,meetings:t,hourHeight:n,onSelect:r}){let i=n*24,a=t.filter(t=>!t.isAllDay&&F(new Date(t.startsAt),e));return(0,L.jsx)(`div`,{className:`cal-day-col`,children:(0,L.jsxs)(`div`,{className:`cal-hours`,style:{height:`${i}px`},children:[Array.from({length:24},(e,t)=>(0,L.jsx)(`div`,{className:`cal-hour-line`,style:{top:`${t*n}px`}},t)),a.map(t=>{let n=new Date(t.startsAt),i=t.endsAt?new Date(t.endsAt):new Date(n.getTime()+30*6e4),a=U(n),o=F(i,e)?U(i):V,s=a/V*100,c=Math.max((o-a)/V*100,H);return(0,L.jsxs)(`div`,{className:`cal-event`,style:{top:`${s}%`,height:`${c}%`},title:t.title??`Untitled`,...I(t,r),children:[(0,L.jsx)(`span`,{className:`cal-event-time`,children:W(n)}),(0,L.jsx)(`span`,{className:`cal-event-title`,children:t.title??`Untitled`})]},t.meetingId)})]})})}var K=44;function q(e){let t=new Date;return t.setHours(e,0,0,0),t.toLocaleTimeString([],{hour:`numeric`})}function J({anchor:e,meetings:t,onSelect:n}){let r=k(e),i=new Date;return(0,L.jsxs)(`div`,{className:`cal-timed`,children:[(0,L.jsxs)(`div`,{className:`cal-day-headrow`,children:[(0,L.jsx)(`div`,{className:`cal-timed-gutter`}),r.map(e=>(0,L.jsxs)(`div`,{className:`cal-day-head${F(e,i)?` cal-day-head-today`:``}`,children:[(0,L.jsx)(`span`,{className:`cal-day-head-name`,children:e.toLocaleDateString([],{weekday:`short`})}),(0,L.jsx)(`span`,{className:`cal-day-head-num`,children:e.getDate()})]},e.toISOString()))]}),(0,L.jsxs)(`div`,{className:`cal-allday-band`,children:[(0,L.jsx)(`div`,{className:`cal-timed-gutter`,children:`All-day`}),r.map(e=>(0,L.jsx)(`div`,{className:`cal-allday-cell`,children:t.filter(t=>t.isAllDay&&F(new Date(t.startsAt),e)).map(e=>(0,L.jsx)(`div`,{className:`cal-allday-chip`,title:e.title??`Untitled`,...I(e,n),children:e.title??`Untitled`},e.meetingId))},e.toISOString()))]}),(0,L.jsxs)(`div`,{className:`cal-timed-cols`,children:[(0,L.jsx)(`div`,{className:`cal-timed-gutter`,children:j().map(e=>(0,L.jsx)(`div`,{className:`cal-hour-label`,style:{height:`${K}px`},children:e===0?``:q(e)},e))}),r.map(e=>(0,L.jsx)(G,{day:e,meetings:t,hourHeight:K,onSelect:n},e.toISOString()))]})]})}var Y=52;function X(e){let t=new Date;return t.setHours(e,0,0,0),t.toLocaleTimeString([],{hour:`numeric`})}function Z({anchor:e,meetings:t,onSelect:n}){let r=t.filter(t=>t.isAllDay&&F(new Date(t.startsAt),e));return(0,L.jsxs)(`div`,{className:`cal-timed cal-timed-single`,children:[(0,L.jsxs)(`div`,{className:`cal-allday-band`,children:[(0,L.jsx)(`div`,{className:`cal-timed-gutter`,children:`All-day`}),(0,L.jsx)(`div`,{className:`cal-allday-cell`,children:r.map(e=>(0,L.jsx)(`div`,{className:`cal-allday-chip`,title:e.title??`Untitled`,...I(e,n),children:e.title??`Untitled`},e.meetingId))})]}),(0,L.jsxs)(`div`,{className:`cal-timed-cols`,children:[(0,L.jsx)(`div`,{className:`cal-timed-gutter`,children:j().map(e=>(0,L.jsx)(`div`,{className:`cal-hour-label`,style:{height:`${Y}px`},children:e===0?``:X(e)},e))}),(0,L.jsx)(G,{day:e,meetings:t,hourHeight:Y,onSelect:n})]})]})}var te=[`M`,`T`,`W`,`T`,`F`,`S`,`S`];function ne(e){return`${e.getFullYear()}-${e.getMonth()}-${e.getDate()}`}function re({anchor:e,meetings:t,onPickMonth:n}){let r=new Date,i=new Set(t.map(e=>ne(new Date(e.startsAt))));return(0,L.jsx)(`div`,{className:`cal-year`,children:(0,L.jsx)(`div`,{className:`cal-year-grid`,children:M(e).map(e=>{let t=A(e),a=e.getMonth();return(0,L.jsxs)(`button`,{type:`button`,className:`cal-mini`,onClick:()=>n(e),title:e.toLocaleDateString([],{month:`long`,year:`numeric`}),children:[(0,L.jsx)(`div`,{className:`cal-mini-title`,children:e.toLocaleDateString([],{month:`long`})}),(0,L.jsx)(`div`,{className:`cal-mini-weekrow`,children:te.map((e,t)=>(0,L.jsx)(`span`,{className:`cal-mini-weekday`,children:e},t))}),(0,L.jsx)(`div`,{className:`cal-mini-grid`,children:t.map(e=>{let t=e.getMonth()!==a,n=F(e,r),o=!t&&i.has(ne(e));return(0,L.jsxs)(`span`,{className:`cal-mini-day${t?` cal-mini-day-out`:``}${n?` cal-mini-day-today`:``}`,children:[e.getDate(),o&&(0,L.jsx)(`span`,{className:`cal-mini-dot`})]},e.toISOString())})})]},a)})})})}var ie={meeting:`Meeting`,event:`Event`,task:`Task`};function ae(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}T${n(t.getHours())}:${n(t.getMinutes())}`}function oe(e){return new Date(e).toISOString()}function Q(e){return Math.floor(new Date(e).getTime()/6e4)}function se(e){let t=new Date(e.startsAt);if(e.isAllDay)return t.toLocaleDateString([],{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`});let n=t.toLocaleDateString([],{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`}),r=t.toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`});return e.endsAt?`${n} · ${r} – ${new Date(e.endsAt).toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`})}`:`${n} · ${r}`}function ce(e){if(!e)return null;let t=e.match(/filename="([^"]+)"/);return t?t[1]:null}function le(e,t){return e.email??`${e.name??`unknown`}-${t}`}function ue({a:e}){let t=e.name||e.email||`Unknown`,n=e.name&&e.email?e.email:null;return(0,L.jsxs)(`span`,{className:`cal-attendee-lines`,children:[(0,L.jsx)(`span`,{className:`cal-attendee-name`,children:t}),n&&(0,L.jsx)(`span`,{className:`cal-attendee-email`,children:n})]})}function de({meeting:e,adminFetch:i,onClose:a,onSaved:o,onDeleted:s}){let c=e.kind===`meeting`,[u,d]=(0,T.useState)(!1),[p,m]=(0,T.useState)(!1),[h,g]=(0,T.useState)(!1),[_,w]=(0,T.useState)(!1),[E,D]=(0,T.useState)(null),[O,k]=(0,T.useState)(e),[A,j]=(0,T.useState)(e.title??``),[M,N]=(0,T.useState)(ae(e.startsAt)),[P,F]=(0,T.useState)(e.endsAt?ae(e.endsAt):``),[I,ee]=(0,T.useState)(e.location??``),[R,z]=(0,T.useState)(e.privateNote??``),[B,V]=(0,T.useState)(``),[H,U]=(0,T.useState)(``);(0,T.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!_&&a()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[_,a]);let W=(0,T.useCallback)(()=>{let e={},t=A.trim();t!==(O.title??``)&&(e.title=t);let n=oe(M);Q(n)!==Q(O.startsAt)&&(e.startsAt=n);let r=P?oe(P):null;(r===null?O.endsAt!==null:O.endsAt===null||Q(r)!==Q(O.endsAt))&&(e.endsAt=r);let i=I.trim()||null;i!==(O.location??null)&&(e.location=i);let a=R.trim()||null;return a!==(O.privateNote??null)&&(e.privateNote=a),e},[A,M,P,I,R,O]),G=(0,T.useCallback)(async()=>{let t=W();if(Object.keys(t).length===0){d(!1);return}w(!0),D(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();k(r.meeting),o(r.meeting),d(!1)}catch(e){D(e instanceof Error?e.message:`Save failed`)}finally{w(!1)}},[i,W,e.meetingId,o]),K=(0,T.useCallback)(async()=>{let t=B.trim(),n=H.trim();if(!(!t&&!n)){w(!0),D(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();k(a.meeting),o(a.meeting),V(``),U(``)}catch(e){D(e instanceof Error?e.message:`Add failed`)}finally{w(!1)}}},[i,B,H,e.meetingId,o]),q=(0,T.useCallback)(async t=>{let n=t.email?{email:t.email}:{name:t.name};w(!0),D(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();k(r.meeting),o(r.meeting)}catch(e){D(e instanceof Error?e.message:`Remove failed`)}finally{w(!1)}},[i,e.meetingId,o]),J=(0,T.useCallback)(async()=>{w(!0),D(null);try{let t=await i(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}`,{method:`DELETE`});if(!t.ok)throw Error(`HTTP ${t.status}`);s(e.meetingId)}catch(e){D(e instanceof Error?e.message:`Delete failed`),w(!1)}},[i,e.meetingId,s]),Y=(0,T.useCallback)(async t=>{g(!1),w(!0),D(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=ce(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){D(e instanceof Error?e.message:`Download failed`)}finally{w(!1)}},[i,e.meetingId]),X=ie[e.kind??`meeting`],Z=B.trim().length>0||H.trim().length>0;return(0,L.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{_||a()},children:(0,L.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":u?`Edit meeting`:`Meeting detail`,onClick:e=>e.stopPropagation(),children:[(0,L.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,L.jsx)(`span`,{className:`cal-modal-kind`,children:X}),(0,L.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:a,"aria-label":`Close`,autoFocus:!0,disabled:_,children:(0,L.jsx)(l,{size:16})})]}),!u&&(0,L.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,L.jsx)(`div`,{className:`cal-modal-title`,children:O.title??`Untitled`}),(0,L.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,L.jsx)(v,{size:14}),(0,L.jsx)(`span`,{children:se(O)})]}),O.location&&(0,L.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,L.jsx)(b,{size:14}),(0,L.jsx)(`span`,{children:O.location})]}),O.attendees.length>0&&(0,L.jsxs)(`div`,{className:`cal-modal-row cal-modal-row-top`,children:[(0,L.jsx)(C,{size:14}),(0,L.jsx)(`div`,{className:`cal-modal-attendees`,children:O.attendees.map((e,t)=>(0,L.jsx)(`div`,{className:`cal-attendee-row`,children:(0,L.jsx)(ue,{a:e})},le(e,t)))})]}),O.privateNote&&(0,L.jsxs)(`div`,{className:`cal-modal-row cal-modal-row-top`,children:[(0,L.jsx)(x,{size:14}),(0,L.jsx)(`span`,{className:`cal-modal-note`,children:O.privateNote})]}),(0,L.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,L.jsx)(y,{size:14}),(0,L.jsx)(`span`,{children:X})]})]}),u&&(0,L.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,L.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,L.jsx)(`span`,{children:`Title`}),(0,L.jsx)(`input`,{type:`text`,value:A,onChange:e=>j(e.target.value),disabled:_})]}),(0,L.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,L.jsx)(`span`,{children:`Start`}),(0,L.jsx)(`input`,{type:`datetime-local`,value:M,onChange:e=>N(e.target.value),disabled:_})]}),(0,L.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,L.jsx)(`span`,{children:`End`}),(0,L.jsx)(`input`,{type:`datetime-local`,value:P,onChange:e=>F(e.target.value),disabled:_})]}),(0,L.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,L.jsx)(`span`,{children:`Location`}),(0,L.jsx)(`input`,{type:`text`,value:I,onChange:e=>ee(e.target.value),disabled:_})]}),(0,L.jsxs)(`div`,{className:`cal-modal-field`,children:[(0,L.jsx)(`span`,{children:`Attendees`}),(0,L.jsxs)(`div`,{className:`cal-modal-attendees cal-modal-attendees-edit`,children:[O.attendees.length===0&&(0,L.jsx)(`div`,{className:`cal-attendee-empty`,children:`No attendees yet.`}),O.attendees.map((e,t)=>(0,L.jsxs)(`div`,{className:`cal-attendee-row cal-attendee-row-edit`,children:[(0,L.jsx)(ue,{a:e}),(0,L.jsx)(`button`,{type:`button`,className:`cal-attendee-remove`,onClick:()=>q(e),disabled:_,"aria-label":`Remove ${e.name||e.email||`attendee`}`,children:(0,L.jsx)(l,{size:13})})]},le(e,t)))]}),(0,L.jsxs)(`div`,{className:`cal-attendee-add`,children:[(0,L.jsx)(`input`,{type:`text`,placeholder:`Name`,value:B,onChange:e=>V(e.target.value),disabled:_,"aria-label":`Attendee name`}),(0,L.jsx)(`input`,{type:`email`,placeholder:`Email`,value:H,onChange:e=>U(e.target.value),disabled:_,"aria-label":`Attendee email`}),(0,L.jsx)(`button`,{type:`button`,className:`cal-modal-btn cal-attendee-add-btn`,onClick:K,disabled:_||!Z,"aria-label":`Add attendee`,children:_?(0,L.jsx)(r,{size:13,className:`spin`}):(0,L.jsx)(S,{size:13})})]})]}),(0,L.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,L.jsx)(`span`,{children:`Private note`}),(0,L.jsx)(`textarea`,{className:`cal-modal-textarea`,value:R,onChange:e=>z(e.target.value),disabled:_,rows:3,placeholder:`Only you and your team can see this.`})]})]}),E&&(0,L.jsx)(`div`,{className:`cal-modal-error`,children:E}),c&&(0,L.jsxs)(`div`,{className:`cal-modal-actions`,children:[!u&&!p&&!h&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>d(!0),disabled:_,children:[(0,L.jsx)(n,{size:14}),` Edit`]}),(0,L.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:()=>m(!0),disabled:_,children:[(0,L.jsx)(f,{size:14}),` Delete`]}),(0,L.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-download`,onClick:()=>{O.attendees.length>0?g(!0):Y(!1)},disabled:_,children:[_?(0,L.jsx)(r,{size:14,className:`spin`}):(0,L.jsx)(t,{size:14}),` Download`]})]}),h&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Include attendees in the file?`}),(0,L.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-primary`,onClick:()=>Y(!0),disabled:_,children:[_?(0,L.jsx)(r,{size:14,className:`spin`}):null,` Yes`]}),(0,L.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>Y(!1),disabled:_,children:`No`}),(0,L.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>g(!1),disabled:_,children:`Cancel`})]}),u&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-primary`,onClick:G,disabled:_,children:[_?(0,L.jsx)(r,{size:14,className:`spin`}):null,` Save`]}),(0,L.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>{d(!1),D(null)},disabled:_,children:`Cancel`})]}),p&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Delete this meeting?`}),(0,L.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:J,disabled:_,children:[_?(0,L.jsx)(r,{size:14,className:`spin`}):null,` Delete`]}),(0,L.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>m(!1),disabled:_,children:`Cancel`})]})]})]})})}var $=`maxy-admin-session-key`,fe=[`day`,`week`,`month`,`year`];function pe(e,t){switch(e){case`day`:return t.toLocaleDateString([],{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`});case`week`:{let{from:e,to:n}=N(`week`,t),r=new Date(n.getTime()-1);return`${e.toLocaleDateString([],{day:`numeric`,month:`short`})} – ${r.toLocaleDateString([],{day:`numeric`,month:`short`,year:`numeric`})}`}case`month`:return t.toLocaleDateString([],{month:`long`,year:`numeric`});case`year`:return String(t.getFullYear())}}function me(){let[e,t]=(0,T.useState)(null),[n,r]=(0,T.useState)(!1),[i,a]=(0,T.useState)(void 0),[s,c]=(0,T.useState)(null),[l,d]=(0,T.useState)(void 0),[f,m]=(0,T.useState)(null),[g,_]=(0,T.useState)(null);(0,T.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&&c(e.sessionId??null),_(e.role??null),d(e.userName===void 0?null:e.userName),m(e.avatar??null)}catch{}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]);let v=(0,T.useCallback)(()=>{try{sessionStorage.removeItem($)}catch{}window.location.href=`/`},[]),[y,b]=(0,T.useState)(!1),x=(0,T.useCallback)(async()=>{b(!0);try{let e=await p();if(e){try{sessionStorage.removeItem($)}catch{}window.location.href=`/`}return e}finally{b(!1)}},[]);return n?e?(0,L.jsx)(u,{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,L.jsx)(h,{cacheKey:e,businessName:i,sessionId:s,onLogout:v,onDisconnect:x,disconnecting:y,userName:l,userAvatar:f,role:g,children:(0,L.jsx)(he,{cacheKey:e})})}):(0,L.jsx)(`div`,{className:`cal-page`,children:(0,L.jsxs)(`div`,{className:`cal-empty`,children:[(0,L.jsx)(`p`,{children:`You are not signed in.`}),(0,L.jsxs)(`p`,{children:[`Open the `,(0,L.jsx)(`a`,{href:`/`,className:`cal-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,L.jsx)(o,{surface:`gate`})}function he({cacheKey:e}){let{adminFetch:t,sessionRefetchNonce:n}=c({initialCacheKey:e,surface:`calendar`}),[i,a]=(0,T.useState)(`month`),[s,l]=(0,T.useState)(()=>new Date),[u,d]=(0,T.useState)([]),[f,p]=(0,T.useState)(!1),[h,v]=(0,T.useState)(!1),[y,b]=(0,T.useState)(null),[x,S]=(0,T.useState)(null),[C,w]=(0,T.useState)(null);(0,T.useEffect)(()=>{let e=!1;return t(`/api/admin/calendar/booking-link`).then(async t=>{if(e||!t.ok)return;let n=await t.json();typeof n.bookingDomain==`string`&&n.bookingDomain&&w(n.bookingDomain)}).catch(()=>{}),()=>{e=!0}},[t]),(0,T.useEffect)(()=>{let e=!1,{from:n,to:r}=N(i,s);return p(!0),b(null),t(`/api/admin/calendar/meetings?from=${encodeURIComponent(n.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(Array.isArray(n.meetings)?n.meetings:[])}).catch(t=>{e||(b(t instanceof Error?t.message:`Failed to load`),d([]))}).finally(()=>{e||(p(!1),v(!0))}),()=>{e=!0}},[i,s,n,t]);let E=(0,T.useCallback)(()=>l(new Date),[]),D=(0,T.useCallback)(()=>l(e=>P(i,e,-1)),[i]),O=(0,T.useCallback)(()=>l(e=>P(i,e,1)),[i]),k=(0,T.useCallback)(e=>{l(e),a(`month`)},[]);(0,T.useEffect)(()=>{S(null)},[i,s]);let A=(0,T.useCallback)(e=>{d(t=>t.map(t=>t.meetingId===e.meetingId?e:t)),S(e)},[]),j=(0,T.useCallback)(e=>{d(t=>t.filter(t=>t.meetingId!==e)),S(null)},[]);return h?(0,L.jsxs)(`div`,{className:`cal-page`,children:[(0,L.jsxs)(`header`,{className:`cal-header`,children:[(0,L.jsxs)(`div`,{className:`cal-nav`,children:[(0,L.jsx)(`span`,{className:`cal-range-label`,children:pe(i,s)}),(0,L.jsx)(`button`,{type:`button`,className:`cal-nav-btn`,onClick:D,"aria-label":`Previous`,children:(0,L.jsx)(g,{size:18})}),(0,L.jsx)(`button`,{type:`button`,className:`cal-nav-btn`,onClick:O,"aria-label":`Next`,children:(0,L.jsx)(_,{size:18})}),(0,L.jsx)(`button`,{type:`button`,className:`cal-today-btn`,onClick:E,children:`Today`}),f&&(0,L.jsx)(r,{size:16,className:`spin`})]}),(0,L.jsx)(`div`,{className:`cal-views`,children:fe.map(e=>(0,L.jsx)(`button`,{type:`button`,className:`cal-view-btn${e===i?` cal-view-btn-active`:``}`,onClick:()=>a(e),children:e.charAt(0).toUpperCase()+e.slice(1)},e))}),C&&(0,L.jsxs)(`a`,{className:`cal-booking-link`,href:`https://${C}`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,L.jsx)(m,{size:14}),` Booking page`]})]}),(0,L.jsxs)(`div`,{className:`cal-body`,children:[y&&(0,L.jsxs)(`div`,{className:`cal-error`,children:[`Could not load the calendar: `,y]}),i===`day`&&(0,L.jsx)(Z,{anchor:s,meetings:u,onSelect:S}),i===`week`&&(0,L.jsx)(J,{anchor:s,meetings:u,onSelect:S}),i===`month`&&(0,L.jsx)(B,{anchor:s,meetings:u,onSelect:S}),i===`year`&&(0,L.jsx)(re,{anchor:s,meetings:u,onPickMonth:k})]}),x&&(0,L.jsx)(de,{meeting:x,adminFetch:t,onClose:()=>S(null),onSaved:A,onDeleted:j})]}):(0,L.jsx)(o,{surface:`gate`})}(0,w.createRoot)(document.getElementById(`root`)).render((0,L.jsx)(me,{}));
1
+ import{o as e}from"./chunk-CltuBf4Z.js";import{A as t,C as n,E as r,F as i,G as a,I as o,V as s,W as c,_ as l,m as u,q as d,v as f}from"./useSubAccountSwitcher-BuUYMDWl.js";import{E as p,t as m,v as h}from"./AdminShell-CpaI2F_p.js";import{t as g}from"./chevron-left-C2JEy7uU.js";import{t as _}from"./chevron-right-DWa047Ys.js";import{t as v}from"./clock-C3OqfCnn.js";var y=i(`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`}]]),b=i(`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`}]]),x=i(`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`}]]),S=i(`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`}]]),C=i(`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`}]]),w=a(),T=e(d(),1);function E(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function D(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n}function O(e){let t=E(e),n=t.getDay();return D(t,n===0?-6:1-n)}function k(e){let t=O(e);return Array.from({length:7},(e,n)=>D(t,n))}function A(e){let t=O(new Date(e.getFullYear(),e.getMonth(),1));return Array.from({length:42},(e,n)=>D(t,n))}function j(){return Array.from({length:24},(e,t)=>t)}function M(e){let t=e.getFullYear();return Array.from({length:12},(e,n)=>new Date(t,n,1))}function N(e,t){switch(e){case`day`:{let e=E(t);return{from:e,to:D(e,1)}}case`week`:{let e=O(t);return{from:e,to:D(e,7)}}case`month`:{let e=O(new Date(t.getFullYear(),t.getMonth(),1));return{from:e,to:D(e,42)}}case`year`:return{from:new Date(t.getFullYear(),0,1),to:new Date(t.getFullYear()+1,0,1)}}}function P(e,t,n){switch(e){case`day`:return D(t,n);case`week`:return D(t,n*7);case`month`:return new Date(t.getFullYear(),t.getMonth()+n,1);case`year`:return new Date(t.getFullYear()+n,t.getMonth(),1)}}function F(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function I(e,t){return{role:`button`,tabIndex:0,onClick:()=>t(e),onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),t(e))}}}var L=s(),ee=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],R=3;function z(e){return e.toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`})}function B({anchor:e,meetings:t,onSelect:n}){let r=A(e),i=e.getMonth(),a=new Date;return(0,L.jsxs)(`div`,{className:`cal-month`,children:[(0,L.jsx)(`div`,{className:`cal-weekday-row`,children:ee.map(e=>(0,L.jsx)(`div`,{className:`cal-weekday`,children:e},e))}),(0,L.jsx)(`div`,{className:`cal-month-grid`,children:r.map(e=>{let r=t.filter(t=>F(new Date(t.startsAt),e)).sort((e,t)=>e.startsAt.localeCompare(t.startsAt)),o=e.getMonth()!==i,s=F(e,a);return(0,L.jsxs)(`div`,{className:`cal-cell${o?` cal-cell-out`:``}${s?` cal-cell-today`:``}`,children:[(0,L.jsx)(`div`,{className:`cal-cell-num`,children:e.getDate()}),r.slice(0,R).map(e=>(0,L.jsxs)(`div`,{className:`cal-chip`,title:e.title??`Untitled`,...I(e,n),children:[!e.isAllDay&&(0,L.jsx)(`span`,{className:`cal-chip-time`,children:z(new Date(e.startsAt))}),e.title??`Untitled`]},e.meetingId)),r.length>R&&(0,L.jsxs)(`div`,{className:`cal-more`,children:[`+`,r.length-R,` more`]})]},e.toISOString())})})]})}var V=1440,H=1.8;function U(e){return e.getHours()*60+e.getMinutes()}function W(e){return e.toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`})}function G({day:e,meetings:t,hourHeight:n,onSelect:r}){let i=n*24,a=t.filter(t=>!t.isAllDay&&F(new Date(t.startsAt),e));return(0,L.jsx)(`div`,{className:`cal-day-col`,children:(0,L.jsxs)(`div`,{className:`cal-hours`,style:{height:`${i}px`},children:[Array.from({length:24},(e,t)=>(0,L.jsx)(`div`,{className:`cal-hour-line`,style:{top:`${t*n}px`}},t)),a.map(t=>{let n=new Date(t.startsAt),i=t.endsAt?new Date(t.endsAt):new Date(n.getTime()+30*6e4),a=U(n),o=F(i,e)?U(i):V,s=a/V*100,c=Math.max((o-a)/V*100,H);return(0,L.jsxs)(`div`,{className:`cal-event`,style:{top:`${s}%`,height:`${c}%`},title:t.title??`Untitled`,...I(t,r),children:[(0,L.jsx)(`span`,{className:`cal-event-time`,children:W(n)}),(0,L.jsx)(`span`,{className:`cal-event-title`,children:t.title??`Untitled`})]},t.meetingId)})]})})}var K=44;function q(e){let t=new Date;return t.setHours(e,0,0,0),t.toLocaleTimeString([],{hour:`numeric`})}function J({anchor:e,meetings:t,onSelect:n}){let r=k(e),i=new Date;return(0,L.jsxs)(`div`,{className:`cal-timed`,children:[(0,L.jsxs)(`div`,{className:`cal-day-headrow`,children:[(0,L.jsx)(`div`,{className:`cal-timed-gutter`}),r.map(e=>(0,L.jsxs)(`div`,{className:`cal-day-head${F(e,i)?` cal-day-head-today`:``}`,children:[(0,L.jsx)(`span`,{className:`cal-day-head-name`,children:e.toLocaleDateString([],{weekday:`short`})}),(0,L.jsx)(`span`,{className:`cal-day-head-num`,children:e.getDate()})]},e.toISOString()))]}),(0,L.jsxs)(`div`,{className:`cal-allday-band`,children:[(0,L.jsx)(`div`,{className:`cal-timed-gutter`,children:`All-day`}),r.map(e=>(0,L.jsx)(`div`,{className:`cal-allday-cell`,children:t.filter(t=>t.isAllDay&&F(new Date(t.startsAt),e)).map(e=>(0,L.jsx)(`div`,{className:`cal-allday-chip`,title:e.title??`Untitled`,...I(e,n),children:e.title??`Untitled`},e.meetingId))},e.toISOString()))]}),(0,L.jsxs)(`div`,{className:`cal-timed-cols`,children:[(0,L.jsx)(`div`,{className:`cal-timed-gutter`,children:j().map(e=>(0,L.jsx)(`div`,{className:`cal-hour-label`,style:{height:`${K}px`},children:e===0?``:q(e)},e))}),r.map(e=>(0,L.jsx)(G,{day:e,meetings:t,hourHeight:K,onSelect:n},e.toISOString()))]})]})}var Y=52;function X(e){let t=new Date;return t.setHours(e,0,0,0),t.toLocaleTimeString([],{hour:`numeric`})}function Z({anchor:e,meetings:t,onSelect:n}){let r=t.filter(t=>t.isAllDay&&F(new Date(t.startsAt),e));return(0,L.jsxs)(`div`,{className:`cal-timed cal-timed-single`,children:[(0,L.jsxs)(`div`,{className:`cal-allday-band`,children:[(0,L.jsx)(`div`,{className:`cal-timed-gutter`,children:`All-day`}),(0,L.jsx)(`div`,{className:`cal-allday-cell`,children:r.map(e=>(0,L.jsx)(`div`,{className:`cal-allday-chip`,title:e.title??`Untitled`,...I(e,n),children:e.title??`Untitled`},e.meetingId))})]}),(0,L.jsxs)(`div`,{className:`cal-timed-cols`,children:[(0,L.jsx)(`div`,{className:`cal-timed-gutter`,children:j().map(e=>(0,L.jsx)(`div`,{className:`cal-hour-label`,style:{height:`${Y}px`},children:e===0?``:X(e)},e))}),(0,L.jsx)(G,{day:e,meetings:t,hourHeight:Y,onSelect:n})]})]})}var te=[`M`,`T`,`W`,`T`,`F`,`S`,`S`];function ne(e){return`${e.getFullYear()}-${e.getMonth()}-${e.getDate()}`}function re({anchor:e,meetings:t,onPickMonth:n}){let r=new Date,i=new Set(t.map(e=>ne(new Date(e.startsAt))));return(0,L.jsx)(`div`,{className:`cal-year`,children:(0,L.jsx)(`div`,{className:`cal-year-grid`,children:M(e).map(e=>{let t=A(e),a=e.getMonth();return(0,L.jsxs)(`button`,{type:`button`,className:`cal-mini`,onClick:()=>n(e),title:e.toLocaleDateString([],{month:`long`,year:`numeric`}),children:[(0,L.jsx)(`div`,{className:`cal-mini-title`,children:e.toLocaleDateString([],{month:`long`})}),(0,L.jsx)(`div`,{className:`cal-mini-weekrow`,children:te.map((e,t)=>(0,L.jsx)(`span`,{className:`cal-mini-weekday`,children:e},t))}),(0,L.jsx)(`div`,{className:`cal-mini-grid`,children:t.map(e=>{let t=e.getMonth()!==a,n=F(e,r),o=!t&&i.has(ne(e));return(0,L.jsxs)(`span`,{className:`cal-mini-day${t?` cal-mini-day-out`:``}${n?` cal-mini-day-today`:``}`,children:[e.getDate(),o&&(0,L.jsx)(`span`,{className:`cal-mini-dot`})]},e.toISOString())})})]},a)})})})}var ie={meeting:`Meeting`,event:`Event`,task:`Task`};function ae(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}T${n(t.getHours())}:${n(t.getMinutes())}`}function oe(e){return new Date(e).toISOString()}function Q(e){return Math.floor(new Date(e).getTime()/6e4)}function se(e){let t=new Date(e.startsAt);if(e.isAllDay)return t.toLocaleDateString([],{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`});let n=t.toLocaleDateString([],{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`}),r=t.toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`});return e.endsAt?`${n} · ${r} – ${new Date(e.endsAt).toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`})}`:`${n} · ${r}`}function ce(e){if(!e)return null;let t=e.match(/filename="([^"]+)"/);return t?t[1]:null}function le(e,t){return e.email??`${e.name??`unknown`}-${t}`}function ue({a:e}){let t=e.name||e.email||`Unknown`,n=e.name&&e.email?e.email:null;return(0,L.jsxs)(`span`,{className:`cal-attendee-lines`,children:[(0,L.jsx)(`span`,{className:`cal-attendee-name`,children:t}),n&&(0,L.jsx)(`span`,{className:`cal-attendee-email`,children:n})]})}function de({meeting:e,adminFetch:i,onClose:a,onSaved:o,onDeleted:s}){let c=e.kind===`meeting`,[u,d]=(0,T.useState)(!1),[p,m]=(0,T.useState)(!1),[h,g]=(0,T.useState)(!1),[_,w]=(0,T.useState)(!1),[E,D]=(0,T.useState)(null),[O,k]=(0,T.useState)(e),[A,j]=(0,T.useState)(e.title??``),[M,N]=(0,T.useState)(ae(e.startsAt)),[P,F]=(0,T.useState)(e.endsAt?ae(e.endsAt):``),[I,ee]=(0,T.useState)(e.location??``),[R,z]=(0,T.useState)(e.privateNote??``),[B,V]=(0,T.useState)(``),[H,U]=(0,T.useState)(``);(0,T.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!_&&a()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[_,a]);let W=(0,T.useCallback)(()=>{let e={},t=A.trim();t!==(O.title??``)&&(e.title=t);let n=oe(M);Q(n)!==Q(O.startsAt)&&(e.startsAt=n);let r=P?oe(P):null;(r===null?O.endsAt!==null:O.endsAt===null||Q(r)!==Q(O.endsAt))&&(e.endsAt=r);let i=I.trim()||null;i!==(O.location??null)&&(e.location=i);let a=R.trim()||null;return a!==(O.privateNote??null)&&(e.privateNote=a),e},[A,M,P,I,R,O]),G=(0,T.useCallback)(async()=>{let t=W();if(Object.keys(t).length===0){d(!1);return}w(!0),D(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();k(r.meeting),o(r.meeting),d(!1)}catch(e){D(e instanceof Error?e.message:`Save failed`)}finally{w(!1)}},[i,W,e.meetingId,o]),K=(0,T.useCallback)(async()=>{let t=B.trim(),n=H.trim();if(!(!t&&!n)){w(!0),D(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();k(a.meeting),o(a.meeting),V(``),U(``)}catch(e){D(e instanceof Error?e.message:`Add failed`)}finally{w(!1)}}},[i,B,H,e.meetingId,o]),q=(0,T.useCallback)(async t=>{let n=t.email?{email:t.email}:{name:t.name};w(!0),D(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();k(r.meeting),o(r.meeting)}catch(e){D(e instanceof Error?e.message:`Remove failed`)}finally{w(!1)}},[i,e.meetingId,o]),J=(0,T.useCallback)(async()=>{w(!0),D(null);try{let t=await i(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}`,{method:`DELETE`});if(!t.ok)throw Error(`HTTP ${t.status}`);s(e.meetingId)}catch(e){D(e instanceof Error?e.message:`Delete failed`),w(!1)}},[i,e.meetingId,s]),Y=(0,T.useCallback)(async t=>{g(!1),w(!0),D(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=ce(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){D(e instanceof Error?e.message:`Download failed`)}finally{w(!1)}},[i,e.meetingId]),X=ie[e.kind??`meeting`],Z=B.trim().length>0||H.trim().length>0;return(0,L.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{_||a()},children:(0,L.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":u?`Edit meeting`:`Meeting detail`,onClick:e=>e.stopPropagation(),children:[(0,L.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,L.jsx)(`span`,{className:`cal-modal-kind`,children:X}),(0,L.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:a,"aria-label":`Close`,autoFocus:!0,disabled:_,children:(0,L.jsx)(l,{size:16})})]}),!u&&(0,L.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,L.jsx)(`div`,{className:`cal-modal-title`,children:O.title??`Untitled`}),(0,L.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,L.jsx)(v,{size:14}),(0,L.jsx)(`span`,{children:se(O)})]}),O.location&&(0,L.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,L.jsx)(b,{size:14}),(0,L.jsx)(`span`,{children:O.location})]}),O.attendees.length>0&&(0,L.jsxs)(`div`,{className:`cal-modal-row cal-modal-row-top`,children:[(0,L.jsx)(C,{size:14}),(0,L.jsx)(`div`,{className:`cal-modal-attendees`,children:O.attendees.map((e,t)=>(0,L.jsx)(`div`,{className:`cal-attendee-row`,children:(0,L.jsx)(ue,{a:e})},le(e,t)))})]}),O.privateNote&&(0,L.jsxs)(`div`,{className:`cal-modal-row cal-modal-row-top`,children:[(0,L.jsx)(x,{size:14}),(0,L.jsx)(`span`,{className:`cal-modal-note`,children:O.privateNote})]}),(0,L.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,L.jsx)(y,{size:14}),(0,L.jsx)(`span`,{children:X})]})]}),u&&(0,L.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,L.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,L.jsx)(`span`,{children:`Title`}),(0,L.jsx)(`input`,{type:`text`,value:A,onChange:e=>j(e.target.value),disabled:_})]}),(0,L.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,L.jsx)(`span`,{children:`Start`}),(0,L.jsx)(`input`,{type:`datetime-local`,value:M,onChange:e=>N(e.target.value),disabled:_})]}),(0,L.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,L.jsx)(`span`,{children:`End`}),(0,L.jsx)(`input`,{type:`datetime-local`,value:P,onChange:e=>F(e.target.value),disabled:_})]}),(0,L.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,L.jsx)(`span`,{children:`Location`}),(0,L.jsx)(`input`,{type:`text`,value:I,onChange:e=>ee(e.target.value),disabled:_})]}),(0,L.jsxs)(`div`,{className:`cal-modal-field`,children:[(0,L.jsx)(`span`,{children:`Attendees`}),(0,L.jsxs)(`div`,{className:`cal-modal-attendees cal-modal-attendees-edit`,children:[O.attendees.length===0&&(0,L.jsx)(`div`,{className:`cal-attendee-empty`,children:`No attendees yet.`}),O.attendees.map((e,t)=>(0,L.jsxs)(`div`,{className:`cal-attendee-row cal-attendee-row-edit`,children:[(0,L.jsx)(ue,{a:e}),(0,L.jsx)(`button`,{type:`button`,className:`cal-attendee-remove`,onClick:()=>q(e),disabled:_,"aria-label":`Remove ${e.name||e.email||`attendee`}`,children:(0,L.jsx)(l,{size:13})})]},le(e,t)))]}),(0,L.jsxs)(`div`,{className:`cal-attendee-add`,children:[(0,L.jsx)(`input`,{type:`text`,placeholder:`Name`,value:B,onChange:e=>V(e.target.value),disabled:_,"aria-label":`Attendee name`}),(0,L.jsx)(`input`,{type:`email`,placeholder:`Email`,value:H,onChange:e=>U(e.target.value),disabled:_,"aria-label":`Attendee email`}),(0,L.jsx)(`button`,{type:`button`,className:`cal-modal-btn cal-attendee-add-btn`,onClick:K,disabled:_||!Z,"aria-label":`Add attendee`,children:_?(0,L.jsx)(r,{size:13,className:`spin`}):(0,L.jsx)(S,{size:13})})]})]}),(0,L.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,L.jsx)(`span`,{children:`Private note`}),(0,L.jsx)(`textarea`,{className:`cal-modal-textarea`,value:R,onChange:e=>z(e.target.value),disabled:_,rows:3,placeholder:`Only you and your team can see this.`})]})]}),E&&(0,L.jsx)(`div`,{className:`cal-modal-error`,children:E}),c&&(0,L.jsxs)(`div`,{className:`cal-modal-actions`,children:[!u&&!p&&!h&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>d(!0),disabled:_,children:[(0,L.jsx)(n,{size:14}),` Edit`]}),(0,L.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:()=>m(!0),disabled:_,children:[(0,L.jsx)(f,{size:14}),` Delete`]}),(0,L.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-download`,onClick:()=>{O.attendees.length>0?g(!0):Y(!1)},disabled:_,children:[_?(0,L.jsx)(r,{size:14,className:`spin`}):(0,L.jsx)(t,{size:14}),` Download`]})]}),h&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Include attendees in the file?`}),(0,L.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-primary`,onClick:()=>Y(!0),disabled:_,children:[_?(0,L.jsx)(r,{size:14,className:`spin`}):null,` Yes`]}),(0,L.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>Y(!1),disabled:_,children:`No`}),(0,L.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>g(!1),disabled:_,children:`Cancel`})]}),u&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-primary`,onClick:G,disabled:_,children:[_?(0,L.jsx)(r,{size:14,className:`spin`}):null,` Save`]}),(0,L.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>{d(!1),D(null)},disabled:_,children:`Cancel`})]}),p&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Delete this meeting?`}),(0,L.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:J,disabled:_,children:[_?(0,L.jsx)(r,{size:14,className:`spin`}):null,` Delete`]}),(0,L.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>m(!1),disabled:_,children:`Cancel`})]})]})]})})}var $=`maxy-admin-session-key`,fe=[`day`,`week`,`month`,`year`];function pe(e,t){switch(e){case`day`:return t.toLocaleDateString([],{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`});case`week`:{let{from:e,to:n}=N(`week`,t),r=new Date(n.getTime()-1);return`${e.toLocaleDateString([],{day:`numeric`,month:`short`})} – ${r.toLocaleDateString([],{day:`numeric`,month:`short`,year:`numeric`})}`}case`month`:return t.toLocaleDateString([],{month:`long`,year:`numeric`});case`year`:return String(t.getFullYear())}}function me(){let[e,t]=(0,T.useState)(null),[n,r]=(0,T.useState)(!1),[i,a]=(0,T.useState)(void 0),[s,c]=(0,T.useState)(null),[l,d]=(0,T.useState)(void 0),[f,h]=(0,T.useState)(null),[g,_]=(0,T.useState)(null);(0,T.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&&c(e.sessionId??null),_(e.role??null),d(e.userName===void 0?null:e.userName),h(e.avatar??null)}catch{}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]);let v=(0,T.useCallback)(()=>{try{sessionStorage.removeItem($)}catch{}window.location.href=`/`},[]),[y,b]=(0,T.useState)(!1),x=(0,T.useCallback)(async()=>{b(!0);try{let e=await p();if(e){try{sessionStorage.removeItem($)}catch{}window.location.href=`/`}return e}finally{b(!1)}},[]);return n?e?(0,L.jsx)(u,{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,L.jsx)(m,{cacheKey:e,businessName:i,sessionId:s,onLogout:v,onDisconnect:x,disconnecting:y,userName:l,userAvatar:f,role:g,children:(0,L.jsx)(he,{cacheKey:e})})}):(0,L.jsx)(`div`,{className:`cal-page`,children:(0,L.jsxs)(`div`,{className:`cal-empty`,children:[(0,L.jsx)(`p`,{children:`You are not signed in.`}),(0,L.jsxs)(`p`,{children:[`Open the `,(0,L.jsx)(`a`,{href:`/`,className:`cal-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,L.jsx)(o,{surface:`gate`})}function he({cacheKey:e}){let{adminFetch:t,sessionRefetchNonce:n}=c({initialCacheKey:e,surface:`calendar`}),[i,a]=(0,T.useState)(`month`),[s,l]=(0,T.useState)(()=>new Date),[u,d]=(0,T.useState)([]),[f,p]=(0,T.useState)(!1),[m,v]=(0,T.useState)(!1),[y,b]=(0,T.useState)(null),[x,S]=(0,T.useState)(null),[C,w]=(0,T.useState)(null);(0,T.useEffect)(()=>{let e=!1;return t(`/api/admin/calendar/booking-link`).then(async t=>{if(e||!t.ok)return;let n=await t.json();typeof n.bookingDomain==`string`&&n.bookingDomain&&w(n.bookingDomain)}).catch(()=>{}),()=>{e=!0}},[t]),(0,T.useEffect)(()=>{let e=!1,{from:n,to:r}=N(i,s);return p(!0),b(null),t(`/api/admin/calendar/meetings?from=${encodeURIComponent(n.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(Array.isArray(n.meetings)?n.meetings:[])}).catch(t=>{e||(b(t instanceof Error?t.message:`Failed to load`),d([]))}).finally(()=>{e||(p(!1),v(!0))}),()=>{e=!0}},[i,s,n,t]);let E=(0,T.useCallback)(()=>l(new Date),[]),D=(0,T.useCallback)(()=>l(e=>P(i,e,-1)),[i]),O=(0,T.useCallback)(()=>l(e=>P(i,e,1)),[i]),k=(0,T.useCallback)(e=>{l(e),a(`month`)},[]);(0,T.useEffect)(()=>{S(null)},[i,s]);let A=(0,T.useCallback)(e=>{d(t=>t.map(t=>t.meetingId===e.meetingId?e:t)),S(e)},[]),j=(0,T.useCallback)(e=>{d(t=>t.filter(t=>t.meetingId!==e)),S(null)},[]);return m?(0,L.jsxs)(`div`,{className:`cal-page`,children:[(0,L.jsxs)(`header`,{className:`cal-header`,children:[(0,L.jsxs)(`div`,{className:`cal-nav`,children:[(0,L.jsx)(`span`,{className:`cal-range-label`,children:pe(i,s)}),(0,L.jsx)(`button`,{type:`button`,className:`cal-nav-btn`,onClick:D,"aria-label":`Previous`,children:(0,L.jsx)(g,{size:18})}),(0,L.jsx)(`button`,{type:`button`,className:`cal-nav-btn`,onClick:O,"aria-label":`Next`,children:(0,L.jsx)(_,{size:18})}),(0,L.jsx)(`button`,{type:`button`,className:`cal-today-btn`,onClick:E,children:`Today`}),f&&(0,L.jsx)(r,{size:16,className:`spin`})]}),(0,L.jsx)(`div`,{className:`cal-views`,children:fe.map(e=>(0,L.jsx)(`button`,{type:`button`,className:`cal-view-btn${e===i?` cal-view-btn-active`:``}`,onClick:()=>a(e),children:e.charAt(0).toUpperCase()+e.slice(1)},e))}),C&&(0,L.jsxs)(`a`,{className:`cal-booking-link`,href:`https://${C}`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,L.jsx)(h,{size:14}),` Booking page`]})]}),(0,L.jsxs)(`div`,{className:`cal-body`,children:[y&&(0,L.jsxs)(`div`,{className:`cal-error`,children:[`Could not load the calendar: `,y]}),i===`day`&&(0,L.jsx)(Z,{anchor:s,meetings:u,onSelect:S}),i===`week`&&(0,L.jsx)(J,{anchor:s,meetings:u,onSelect:S}),i===`month`&&(0,L.jsx)(B,{anchor:s,meetings:u,onSelect:S}),i===`year`&&(0,L.jsx)(re,{anchor:s,meetings:u,onPickMonth:k})]}),x&&(0,L.jsx)(de,{meeting:x,adminFetch:t,onClose:()=>S(null),onSaved:A,onDeleted:j})]}):(0,L.jsx)(o,{surface:`gate`})}(0,w.createRoot)(document.getElementById(`root`)).render((0,L.jsx)(me,{}));
@@ -0,0 +1 @@
1
+ import{G as e,V as t}from"./useSubAccountSwitcher-BuUYMDWl.js";import"./useVoiceRecorder-BGqV5R6u.js";import"./AdminShell-CpaI2F_p.js";import{n}from"./page-E74MYB18.js";import"./useCopyFeedback-CwTZ9DqH.js";var r=e(),i=t();(0,r.createRoot)(document.getElementById(`root`)).render((0,i.jsx)(n,{}));
@@ -0,0 +1 @@
1
+ (��j[�2�[��U�l���o0�UjA��t�b�0��p�&���S��۟� {�Ϋ���<#T�/tp���Qs�l��I'֬L�:�$yn��n��>�7��i!1<��P��ӱ*���U���M+>k=:���/���oL�QF�K���h�mt9o#�ϕ�ľf6�c<P�?�
@@ -0,0 +1 @@
1
+ import{F as e}from"./useSubAccountSwitcher-BuUYMDWl.js";var t=e(`chevron-left`,[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]);export{t};
@@ -0,0 +1 @@
1
+ import{F as e}from"./useSubAccountSwitcher-BuUYMDWl.js";var t=e(`chevron-right`,[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]);export{t};
@@ -0,0 +1 @@
1
+ import{F as e}from"./useSubAccountSwitcher-BuUYMDWl.js";var t=e(`clock`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6l4 2`,key:`mmk7yg`}]]);export{t};