@rubytech/create-maxy-code 0.1.539 → 0.1.540

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 (261) hide show
  1. package/package.json +1 -1
  2. package/payload/platform/lib/agent-slug/dist/index.d.ts +31 -0
  3. package/payload/platform/lib/agent-slug/dist/index.d.ts.map +1 -0
  4. package/payload/platform/lib/agent-slug/dist/index.js +53 -0
  5. package/payload/platform/lib/agent-slug/dist/index.js.map +1 -0
  6. package/payload/platform/lib/agent-slug/src/index.ts +53 -0
  7. package/payload/platform/lib/agent-slug/tsconfig.json +8 -0
  8. package/payload/platform/package.json +2 -2
  9. package/payload/platform/plugins/admin/.claude-plugin/plugin.json +1 -1
  10. package/payload/platform/plugins/admin/PLUGIN.md +33 -1
  11. package/payload/platform/plugins/admin/mcp/dist/index.js +136 -0
  12. package/payload/platform/plugins/admin/mcp/dist/index.js.map +1 -1
  13. package/payload/platform/plugins/admin/mcp/dist/tools/agent-config-schema.d.ts +9 -0
  14. package/payload/platform/plugins/admin/mcp/dist/tools/agent-config-schema.d.ts.map +1 -0
  15. package/payload/platform/plugins/admin/mcp/dist/tools/agent-config-schema.js +49 -0
  16. package/payload/platform/plugins/admin/mcp/dist/tools/agent-config-schema.js.map +1 -0
  17. package/payload/platform/plugins/admin/mcp/dist/tools/agent-write.d.ts +64 -0
  18. package/payload/platform/plugins/admin/mcp/dist/tools/agent-write.d.ts.map +1 -0
  19. package/payload/platform/plugins/admin/mcp/dist/tools/agent-write.js +151 -0
  20. package/payload/platform/plugins/admin/mcp/dist/tools/agent-write.js.map +1 -0
  21. package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +81 -13
  22. package/payload/platform/plugins/admin/skills/public-agent-manager/SKILL.md +36 -20
  23. package/payload/platform/plugins/admin/skills/update-knowledge/SKILL.md +4 -3
  24. package/payload/platform/plugins/admin/skills/whats-new/SKILL.md +7 -0
  25. package/payload/platform/plugins/docs/references/admin-ui.md +47 -0
  26. package/payload/platform/plugins/docs/references/channel-wake-and-prompt.md +31 -10
  27. package/payload/platform/plugins/docs/references/internals.md +2 -2
  28. package/payload/platform/plugins/whatsapp/PLUGIN.md +2 -2
  29. package/payload/platform/plugins/whatsapp/mcp/dist/index.js +6 -1
  30. package/payload/platform/plugins/whatsapp/mcp/dist/index.js.map +1 -1
  31. package/payload/platform/plugins/whatsapp/skills/manage-whatsapp-config/SKILL.md +3 -1
  32. package/payload/platform/scripts/__tests__/check-plugin-tool-declarations.test.ts +51 -0
  33. package/payload/platform/scripts/check-plugin-tool-declarations.mjs +97 -0
  34. package/payload/platform/scripts/check-risk-class.mjs +5 -0
  35. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.d.ts.map +1 -1
  36. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js +8 -0
  37. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js.map +1 -1
  38. package/payload/platform/services/claude-session-manager/dist/channel-targets.d.ts +3 -0
  39. package/payload/platform/services/claude-session-manager/dist/channel-targets.d.ts.map +1 -1
  40. package/payload/platform/services/claude-session-manager/dist/channel-targets.js.map +1 -1
  41. package/payload/platform/services/claude-session-manager/dist/http-server.d.ts.map +1 -1
  42. package/payload/platform/services/claude-session-manager/dist/http-server.js +20 -1
  43. package/payload/platform/services/claude-session-manager/dist/http-server.js.map +1 -1
  44. package/payload/platform/services/claude-session-manager/dist/index.js +35 -18
  45. package/payload/platform/services/claude-session-manager/dist/index.js.map +1 -1
  46. package/payload/platform/services/claude-session-manager/dist/pty-spawner.d.ts.map +1 -1
  47. package/payload/platform/services/claude-session-manager/dist/pty-spawner.js +57 -8
  48. package/payload/platform/services/claude-session-manager/dist/pty-spawner.js.map +1 -1
  49. package/payload/platform/services/claude-session-manager/dist/public-knowledge-audit.d.ts +58 -0
  50. package/payload/platform/services/claude-session-manager/dist/public-knowledge-audit.d.ts.map +1 -0
  51. package/payload/platform/services/claude-session-manager/dist/public-knowledge-audit.js +152 -0
  52. package/payload/platform/services/claude-session-manager/dist/public-knowledge-audit.js.map +1 -0
  53. package/payload/platform/services/claude-session-manager/dist/wa-channel-mcp.d.ts +4 -0
  54. package/payload/platform/services/claude-session-manager/dist/wa-channel-mcp.d.ts.map +1 -1
  55. package/payload/platform/services/claude-session-manager/dist/wa-channel-mcp.js +3 -0
  56. package/payload/platform/services/claude-session-manager/dist/wa-channel-mcp.js.map +1 -1
  57. package/payload/platform/services/whatsapp-channel/dist/notification.d.ts +40 -3
  58. package/payload/platform/services/whatsapp-channel/dist/notification.d.ts.map +1 -1
  59. package/payload/platform/services/whatsapp-channel/dist/notification.js +43 -4
  60. package/payload/platform/services/whatsapp-channel/dist/notification.js.map +1 -1
  61. package/payload/platform/services/whatsapp-channel/dist/server.d.ts.map +1 -1
  62. package/payload/platform/services/whatsapp-channel/dist/server.js +41 -25
  63. package/payload/platform/services/whatsapp-channel/dist/server.js.map +1 -1
  64. package/payload/platform/services/whatsapp-channel/dist/targets.d.ts +1 -0
  65. package/payload/platform/services/whatsapp-channel/dist/targets.d.ts.map +1 -1
  66. package/payload/platform/services/whatsapp-channel/dist/targets.js +9 -5
  67. package/payload/platform/services/whatsapp-channel/dist/targets.js.map +1 -1
  68. package/payload/server/{chunk-BP7LH7MC.js → chunk-CKTHAHL4.js} +26 -16
  69. package/payload/server/{chunk-IALJPXIO.js → chunk-ERIM3EFB.js} +1 -1
  70. package/payload/server/{chunk-S4FIEM3L.js → chunk-TQTZXAK3.js} +64 -7
  71. package/payload/server/{manager-5QV2EAZ2.js → manager-F6NXSOJW.js} +2 -2
  72. package/payload/server/maxy-edge.js +2 -2
  73. package/payload/server/public/activity.html +5 -5
  74. package/payload/server/public/agents.html +4 -4
  75. package/payload/server/public/assets/AdminLoginScreens-DuFCjbz2.js +1 -0
  76. package/payload/server/public/assets/AdminLoginScreens-DuFCjbz2.js.br +0 -0
  77. package/payload/server/public/assets/AdminLoginScreens-DuFCjbz2.js.gz +0 -0
  78. package/payload/server/public/assets/AdminShell-DJL5DzRX.js +2 -0
  79. package/payload/server/public/assets/AdminShell-DJL5DzRX.js.br +0 -0
  80. package/payload/server/public/assets/AdminShell-DJL5DzRX.js.gz +0 -0
  81. package/payload/server/public/assets/activity-CpMnNr5c.js +1 -0
  82. package/payload/server/public/assets/activity-CpMnNr5c.js.br +0 -0
  83. package/payload/server/public/assets/activity-CpMnNr5c.js.gz +0 -0
  84. package/payload/server/public/assets/admin-CBwKIfaI.js +1 -0
  85. package/payload/server/public/assets/admin-CBwKIfaI.js.br +0 -0
  86. package/payload/server/public/assets/admin-CBwKIfaI.js.gz +0 -0
  87. package/payload/server/public/assets/agents-C4LmSKjb.js +1 -0
  88. package/payload/server/public/assets/agents-C4LmSKjb.js.br +0 -0
  89. package/payload/server/public/assets/agents-C4LmSKjb.js.gz +0 -0
  90. package/payload/server/public/assets/browser-Bm9xm_yc.js +1 -0
  91. package/payload/server/public/assets/browser-Bm9xm_yc.js.br +0 -0
  92. package/payload/server/public/assets/browser-Bm9xm_yc.js.gz +0 -0
  93. package/payload/server/public/assets/calendar-CNY9FTWe.js +1 -0
  94. package/payload/server/public/assets/calendar-CNY9FTWe.js.br +0 -0
  95. package/payload/server/public/assets/calendar-CNY9FTWe.js.gz +0 -0
  96. package/payload/server/public/assets/chat-3WoUGCTd.js +1 -0
  97. package/payload/server/public/assets/chat-3WoUGCTd.js.br +0 -0
  98. package/payload/server/public/assets/chat-3WoUGCTd.js.gz +0 -0
  99. package/payload/server/public/assets/chevron-left-BE16BJnw.js +1 -0
  100. package/payload/server/public/assets/chevron-left-BE16BJnw.js.br +0 -0
  101. package/payload/server/public/assets/chevron-right-Bu2VKpeU.js +1 -0
  102. package/payload/server/public/assets/chevron-right-Bu2VKpeU.js.br +0 -0
  103. package/payload/server/public/assets/clock-C4Nu2aRV.js +1 -0
  104. package/payload/server/public/assets/clock-C4Nu2aRV.js.br +0 -0
  105. package/payload/server/public/assets/copy-3kj9Oaoc.js +1 -0
  106. package/payload/server/public/assets/copy-3kj9Oaoc.js.br +0 -0
  107. package/payload/server/public/assets/copy-3kj9Oaoc.js.gz +0 -0
  108. package/payload/server/public/assets/data-C-x5EHyi.js +1 -0
  109. package/payload/server/public/assets/data-C-x5EHyi.js.br +1 -0
  110. package/payload/server/public/assets/data-C-x5EHyi.js.gz +0 -0
  111. package/payload/server/public/assets/file-text-CBaewT76.js +1 -0
  112. package/payload/server/public/assets/file-text-CBaewT76.js.br +0 -0
  113. package/payload/server/public/assets/file-text-CBaewT76.js.gz +0 -0
  114. package/payload/server/public/assets/{graph-C8cQ6Nqf.js → graph-B8-e2_Z-.js} +3 -3
  115. package/payload/server/public/assets/graph-B8-e2_Z-.js.br +0 -0
  116. package/payload/server/public/assets/graph-B8-e2_Z-.js.gz +0 -0
  117. package/payload/server/public/assets/graph-labels-Bsc23eZU.js +1 -0
  118. package/payload/server/public/assets/graph-labels-Bsc23eZU.js.br +0 -0
  119. package/payload/server/public/assets/graph-labels-Bsc23eZU.js.gz +0 -0
  120. package/payload/server/public/assets/operator-Cve0-qfO.js +1 -0
  121. package/payload/server/public/assets/operator-Cve0-qfO.js.br +0 -0
  122. package/payload/server/public/assets/operator-Cve0-qfO.js.gz +0 -0
  123. package/payload/server/public/assets/page-BgVMs6Vf.js +1 -0
  124. package/payload/server/public/assets/page-BgVMs6Vf.js.br +0 -0
  125. package/payload/server/public/assets/page-BgVMs6Vf.js.gz +0 -0
  126. package/payload/server/public/assets/page-fABub-w8.js +32 -0
  127. package/payload/server/public/assets/page-fABub-w8.js.br +0 -0
  128. package/payload/server/public/assets/page-fABub-w8.js.gz +0 -0
  129. package/payload/server/public/assets/play-B6zXB9K7.js +1 -0
  130. package/payload/server/public/assets/play-B6zXB9K7.js.br +0 -0
  131. package/payload/server/public/assets/play-B6zXB9K7.js.gz +0 -0
  132. package/payload/server/public/assets/public--R2DbdWs.js +1 -0
  133. package/payload/server/public/assets/public--R2DbdWs.js.br +0 -0
  134. package/payload/server/public/assets/public--R2DbdWs.js.gz +0 -0
  135. package/payload/server/public/assets/rotate-ccw-FZW7c8p8.js +1 -0
  136. package/payload/server/public/assets/rotate-ccw-FZW7c8p8.js.br +0 -0
  137. package/payload/server/public/assets/rotate-ccw-FZW7c8p8.js.gz +0 -0
  138. package/payload/server/public/assets/routines-BpZs2SaT.js +2 -0
  139. package/payload/server/public/assets/routines-BpZs2SaT.js.br +0 -0
  140. package/payload/server/public/assets/routines-BpZs2SaT.js.gz +0 -0
  141. package/payload/server/public/assets/skills-DF7uyEEz.js +1 -0
  142. package/payload/server/public/assets/skills-DF7uyEEz.js.br +0 -0
  143. package/payload/server/public/assets/skills-DF7uyEEz.js.gz +0 -0
  144. package/payload/server/public/assets/tasks-BfJJmoWO.js +3 -0
  145. package/payload/server/public/assets/tasks-BfJJmoWO.js.br +0 -0
  146. package/payload/server/public/assets/tasks-BfJJmoWO.js.gz +0 -0
  147. package/payload/server/public/assets/triangle-alert-CR-jRJdI.js +1 -0
  148. package/payload/server/public/assets/triangle-alert-CR-jRJdI.js.br +0 -0
  149. package/payload/server/public/assets/triangle-alert-CR-jRJdI.js.gz +0 -0
  150. package/payload/server/public/assets/useCopyFeedback-IOuPUAHY.js +1 -0
  151. package/payload/server/public/assets/useCopyFeedback-IOuPUAHY.js.br +0 -0
  152. package/payload/server/public/assets/useCopyFeedback-IOuPUAHY.js.gz +0 -0
  153. package/payload/server/public/assets/{useSubAccountSwitcher-C7TtIbR3.js → useMediaQuery-CA6dR5iz.js} +1 -1
  154. package/payload/server/public/assets/useMediaQuery-CA6dR5iz.js.br +0 -0
  155. package/payload/server/public/assets/{useSubAccountSwitcher-C7TtIbR3.js.gz → useMediaQuery-CA6dR5iz.js.gz} +0 -0
  156. package/payload/server/public/assets/{useSubAccountSwitcher-DCkivCBS.css → useMediaQuery-DpwgV1Da.css} +1 -1
  157. package/payload/server/public/assets/useMediaQuery-DpwgV1Da.css.br +0 -0
  158. package/payload/server/public/assets/{useSubAccountSwitcher-DCkivCBS.css.gz → useMediaQuery-DpwgV1Da.css.gz} +0 -0
  159. package/payload/server/public/assets/useVoiceRecorder-DGhsN7nV.js +2 -0
  160. package/payload/server/public/assets/useVoiceRecorder-DGhsN7nV.js.br +0 -0
  161. package/payload/server/public/assets/useVoiceRecorder-DGhsN7nV.js.gz +0 -0
  162. package/payload/server/public/assets/wrench-CpCOYUBc.js +1 -0
  163. package/payload/server/public/assets/wrench-CpCOYUBc.js.br +0 -0
  164. package/payload/server/public/assets/wrench-CpCOYUBc.js.gz +0 -0
  165. package/payload/server/public/browser.html +4 -4
  166. package/payload/server/public/calendar.html +8 -8
  167. package/payload/server/public/chat.html +13 -13
  168. package/payload/server/public/data.html +11 -11
  169. package/payload/server/public/graph.html +9 -9
  170. package/payload/server/public/index.html +14 -14
  171. package/payload/server/public/operator.html +14 -14
  172. package/payload/server/public/public.html +13 -13
  173. package/payload/server/public/routines.html +6 -6
  174. package/payload/server/public/skills.html +5 -5
  175. package/payload/server/public/tasks.html +6 -6
  176. package/payload/server/server.js +329 -104
  177. package/payload/server/public/assets/AdminLoginScreens-BpHnjHp_.js +0 -1
  178. package/payload/server/public/assets/AdminLoginScreens-BpHnjHp_.js.br +0 -0
  179. package/payload/server/public/assets/AdminLoginScreens-BpHnjHp_.js.gz +0 -0
  180. package/payload/server/public/assets/AdminShell-D24evn4t.js +0 -2
  181. package/payload/server/public/assets/AdminShell-D24evn4t.js.br +0 -0
  182. package/payload/server/public/assets/AdminShell-D24evn4t.js.gz +0 -0
  183. package/payload/server/public/assets/activity-ZVUTB5uZ.js +0 -1
  184. package/payload/server/public/assets/activity-ZVUTB5uZ.js.br +0 -0
  185. package/payload/server/public/assets/activity-ZVUTB5uZ.js.gz +0 -0
  186. package/payload/server/public/assets/admin-XJqQz3QJ.js +0 -1
  187. package/payload/server/public/assets/admin-XJqQz3QJ.js.br +0 -0
  188. package/payload/server/public/assets/admin-XJqQz3QJ.js.gz +0 -0
  189. package/payload/server/public/assets/agents-Dc9SNC9N.js +0 -1
  190. package/payload/server/public/assets/agents-Dc9SNC9N.js.br +0 -0
  191. package/payload/server/public/assets/agents-Dc9SNC9N.js.gz +0 -0
  192. package/payload/server/public/assets/browser-CCedMIga.js +0 -1
  193. package/payload/server/public/assets/browser-CCedMIga.js.br +0 -0
  194. package/payload/server/public/assets/browser-CCedMIga.js.gz +0 -0
  195. package/payload/server/public/assets/calendar-BDoMLP2j.js +0 -1
  196. package/payload/server/public/assets/calendar-BDoMLP2j.js.br +0 -0
  197. package/payload/server/public/assets/calendar-BDoMLP2j.js.gz +0 -0
  198. package/payload/server/public/assets/chat-BAhoqTY9.js +0 -1
  199. package/payload/server/public/assets/chat-BAhoqTY9.js.br +0 -0
  200. package/payload/server/public/assets/chat-BAhoqTY9.js.gz +0 -0
  201. package/payload/server/public/assets/chevron-left-NGLHgPjF.js +0 -1
  202. package/payload/server/public/assets/chevron-right-B4B7OkG8.js +0 -1
  203. package/payload/server/public/assets/chevron-right-B4B7OkG8.js.br +0 -0
  204. package/payload/server/public/assets/clock-7IMwxJdH.js +0 -1
  205. package/payload/server/public/assets/clock-7IMwxJdH.js.br +0 -0
  206. package/payload/server/public/assets/clock-7IMwxJdH.js.gz +0 -0
  207. package/payload/server/public/assets/copy-PkR4EFD6.js +0 -1
  208. package/payload/server/public/assets/copy-PkR4EFD6.js.br +0 -0
  209. package/payload/server/public/assets/copy-PkR4EFD6.js.gz +0 -0
  210. package/payload/server/public/assets/data-yQYhw2IR.js +0 -1
  211. package/payload/server/public/assets/data-yQYhw2IR.js.br +0 -1
  212. package/payload/server/public/assets/data-yQYhw2IR.js.gz +0 -0
  213. package/payload/server/public/assets/file-text-BA9p7TLU.js +0 -1
  214. package/payload/server/public/assets/file-text-BA9p7TLU.js.br +0 -0
  215. package/payload/server/public/assets/file-text-BA9p7TLU.js.gz +0 -0
  216. package/payload/server/public/assets/graph-C8cQ6Nqf.js.br +0 -0
  217. package/payload/server/public/assets/graph-C8cQ6Nqf.js.gz +0 -0
  218. package/payload/server/public/assets/graph-labels-CiK412vE.js +0 -1
  219. package/payload/server/public/assets/graph-labels-CiK412vE.js.br +0 -0
  220. package/payload/server/public/assets/graph-labels-CiK412vE.js.gz +0 -0
  221. package/payload/server/public/assets/operator-CaQAEUBu.js +0 -1
  222. package/payload/server/public/assets/operator-CaQAEUBu.js.br +0 -0
  223. package/payload/server/public/assets/operator-CaQAEUBu.js.gz +0 -0
  224. package/payload/server/public/assets/page-CpJpyoPS.js +0 -32
  225. package/payload/server/public/assets/page-CpJpyoPS.js.br +0 -0
  226. package/payload/server/public/assets/page-CpJpyoPS.js.gz +0 -0
  227. package/payload/server/public/assets/page-D0ShNyGE.js +0 -1
  228. package/payload/server/public/assets/page-D0ShNyGE.js.br +0 -0
  229. package/payload/server/public/assets/page-D0ShNyGE.js.gz +0 -0
  230. package/payload/server/public/assets/play-huZpq9ra.js +0 -1
  231. package/payload/server/public/assets/play-huZpq9ra.js.br +0 -0
  232. package/payload/server/public/assets/play-huZpq9ra.js.gz +0 -0
  233. package/payload/server/public/assets/public--8RWWGjF.js +0 -1
  234. package/payload/server/public/assets/public--8RWWGjF.js.br +0 -0
  235. package/payload/server/public/assets/public--8RWWGjF.js.gz +0 -0
  236. package/payload/server/public/assets/rotate-ccw-g7l4ZSR3.js +0 -1
  237. package/payload/server/public/assets/rotate-ccw-g7l4ZSR3.js.br +0 -0
  238. package/payload/server/public/assets/rotate-ccw-g7l4ZSR3.js.gz +0 -0
  239. package/payload/server/public/assets/routines-DzFcPNMb.js +0 -2
  240. package/payload/server/public/assets/routines-DzFcPNMb.js.br +0 -0
  241. package/payload/server/public/assets/routines-DzFcPNMb.js.gz +0 -0
  242. package/payload/server/public/assets/skills-5vl_Bt9U.js +0 -1
  243. package/payload/server/public/assets/skills-5vl_Bt9U.js.br +0 -0
  244. package/payload/server/public/assets/skills-5vl_Bt9U.js.gz +0 -0
  245. package/payload/server/public/assets/tasks-DQHtJ8Pq.js +0 -3
  246. package/payload/server/public/assets/tasks-DQHtJ8Pq.js.br +0 -0
  247. package/payload/server/public/assets/tasks-DQHtJ8Pq.js.gz +0 -0
  248. package/payload/server/public/assets/triangle-alert-Cy4Z0uFv.js +0 -1
  249. package/payload/server/public/assets/triangle-alert-Cy4Z0uFv.js.br +0 -0
  250. package/payload/server/public/assets/triangle-alert-Cy4Z0uFv.js.gz +0 -0
  251. package/payload/server/public/assets/useCopyFeedback-BwK1RhmF.js +0 -1
  252. package/payload/server/public/assets/useCopyFeedback-BwK1RhmF.js.br +0 -0
  253. package/payload/server/public/assets/useCopyFeedback-BwK1RhmF.js.gz +0 -0
  254. package/payload/server/public/assets/useSubAccountSwitcher-C7TtIbR3.js.br +0 -0
  255. package/payload/server/public/assets/useSubAccountSwitcher-DCkivCBS.css.br +0 -0
  256. package/payload/server/public/assets/useVoiceRecorder-DgyAGgmF.js +0 -2
  257. package/payload/server/public/assets/useVoiceRecorder-DgyAGgmF.js.br +0 -0
  258. package/payload/server/public/assets/useVoiceRecorder-DgyAGgmF.js.gz +0 -0
  259. package/payload/server/public/assets/wrench-CICORrSc.js +0 -1
  260. package/payload/server/public/assets/wrench-CICORrSc.js.br +0 -0
  261. package/payload/server/public/assets/wrench-CICORrSc.js.gz +0 -0
@@ -1 +0,0 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{A as t,B as n,C as r,E as i,G as a,J as o,N as s,P as c,R as l,S as u,T as d,Z as f,_ as p,a as m,b as h,c as g,l as _,m as ee,o as v,p as y,t as b,v as x,w as S,x as te}from"./useSubAccountSwitcher-C7TtIbR3.js";import{E as ne,O as C,T as re,f as w,k as ie,n as ae,r as T,s as E}from"./useVoiceRecorder-DgyAGgmF.js";import{t as D}from"./chevron-left-NGLHgPjF.js";import{t as O}from"./file-text-BA9p7TLU.js";import{i as oe,t as k}from"./graph-labels-CiK412vE.js";import{t as se}from"./triangle-alert-Cy4Z0uFv.js";import{i as ce,n as le,t as ue}from"./file-download-DbNIjWiK.js";var de=n(`ellipsis`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`19`,cy:`12`,r:`1`,key:`1wjl8i`}],[`circle`,{cx:`5`,cy:`12`,r:`1`,key:`1pcz8c`}]]),fe=n(`folder-plus`,[[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`M9 13h6`,key:`1uhe8q`}],[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]),A=n(`image`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]),pe=n(`layout-grid`,[[`rect`,{width:`7`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`1g98yp`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`3`,rx:`1`,key:`6d4xhi`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`14`,rx:`1`,key:`nxv5o0`}],[`rect`,{width:`7`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`1bb6yr`}]]),me=n(`list`,[[`path`,{d:`M3 5h.01`,key:`18ugdj`}],[`path`,{d:`M3 12h.01`,key:`nlz23k`}],[`path`,{d:`M3 19h.01`,key:`noohij`}],[`path`,{d:`M8 5h13`,key:`1pao27`}],[`path`,{d:`M8 12h13`,key:`1za7za`}],[`path`,{d:`M8 19h13`,key:`m83p4d`}]]),he=n(`mouse-pointer-click`,[[`path`,{d:`M14 4.1 12 6`,key:`ita8i4`}],[`path`,{d:`m5.1 8-2.9-.8`,key:`1go3kf`}],[`path`,{d:`m6 12-1.9 2`,key:`mnht97`}],[`path`,{d:`M7.2 2.2 8 5.1`,key:`1cfko1`}],[`path`,{d:`M9.037 9.69a.498.498 0 0 1 .653-.653l11 4.5a.5.5 0 0 1-.074.949l-4.349 1.041a1 1 0 0 0-.74.739l-1.04 4.35a.5.5 0 0 1-.95.074z`,key:`s0h3yz`}]]),ge=n(`send-horizontal`,[[`path`,{d:`M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z`,key:`117uat`}],[`path`,{d:`M6 12h16`,key:`s4cdu5`}]]),_e=n(`smile`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M8 14s1.5 2 4 2 4-2 4-2`,key:`1y1vjs`}],[`line`,{x1:`9`,x2:`9.01`,y1:`9`,y2:`9`,key:`yxxnd0`}],[`line`,{x1:`15`,x2:`15.01`,y1:`9`,y2:`9`,key:`1p4y9e`}]]),ve=n(`upload`,[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]),j=e(f(),1);function ye(){let[e,t]=(0,j.useState)([]),[n,r]=(0,j.useState)(!1),[i,a]=(0,j.useState)(null),o=(0,j.useRef)(null),s=(0,j.useCallback)(e=>{a(null);let n=e.find(e=>!T(e.type,ie));if(n){a(`Unsupported file type: "${n.type}". Supported: images, PDF, plain text, markdown, CSV, calendar, zip, voice notes.`);return}let r=e.find(e=>e.size>C);if(r){a(`"${r.name}" exceeds the 50 MB limit.`);return}t(t=>[...t,...e].slice(0,5))},[]);return{pendingFiles:e,setPendingFiles:t,isDragOver:n,attachError:i,setAttachError:a,fileInputRef:o,addFiles:s,clearFiles:(0,j.useCallback)(()=>{t([]),a(null)},[]),removeFile:(0,j.useCallback)(e=>{t(t=>t.filter((t,n)=>n!==e))},[]),onDragOver:(0,j.useCallback)(e=>{e.preventDefault(),r(!0)},[]),onDragLeave:(0,j.useCallback)(()=>{r(!1)},[]),onDrop:(0,j.useCallback)(e=>{e.preventDefault(),r(!1),s([...e.dataTransfer.files])},[s])}}var M=[[128512],[128515],[128516],[128513],[128518],[128517],[128514],[129315],[128578],[128579],[128521],[128522],[128519],[128525],[128536],[128535],[128540],[128541],[129303],[129300],[128528],[128566],[128564],[128526],[129395],[128546],[128557],[128548],[128544],[128533],[128556],[129393],[128077],[128078],[128076],[128591],[128079],[128588],[128170],[128075],[129309],[10084,65039],[128293],[11088],[127881],[10024],[128175],[128064]].map(e=>String.fromCodePoint(...e));function be(e,t,n,r){let i=e.length,a=Math.max(0,Math.min(n??i,i)),o=Math.max(a,Math.min(r??a,i));return{value:e.slice(0,a)+t+e.slice(o),caret:a+t.length}}var N=a();function P({onSelect:e}){return(0,N.jsx)(`div`,{className:`wa-emoji-popover`,role:`menu`,"aria-label":`Emoji picker`,children:M.map((t,n)=>(0,N.jsx)(`button`,{type:`button`,role:`menuitem`,className:`wa-emoji-item`,onClick:()=>e(t),children:t},n))})}function xe({sessionKey:e,onPick:t,onClose:n}){let[r,i]=(0,j.useState)(``),[a,o]=(0,j.useState)(null),[c,l]=(0,j.useState)(null),[u,d]=(0,j.useState)(!1),f=(0,j.useCallback)(t=>{d(!0),l(null),fetch(`/api/admin/files?path=${encodeURIComponent(t)}&session_key=${encodeURIComponent(e)}`).then(async e=>{let t=await e.json().catch(()=>({}));if(!e.ok)throw Error(t.error??`Could not list files`);return t}).then(e=>{o(e),i(e.path===`.`?``:e.path)}).catch(e=>l(e instanceof Error?e.message:String(e))).finally(()=>d(!1))},[e]);(0,j.useEffect)(()=>{f(``)},[f]);let p=e=>f(r?`${r}/${e}`:e),m=()=>{let e=r.split(`/`).filter(Boolean);e.pop(),f(e.join(`/`))},g=e=>{let n=e.entryPath??e.name;t({path:r?`${r}/${n}`:n,name:e.displayName??e.name})};return(0,N.jsx)(`div`,{className:`wa-picker-backdrop`,role:`dialog`,"aria-label":`Choose a device file`,onClick:n,children:(0,N.jsxs)(`div`,{className:`wa-picker`,onClick:e=>e.stopPropagation(),children:[(0,N.jsxs)(`div`,{className:`wa-picker-head`,children:[r&&(0,N.jsx)(`button`,{type:`button`,className:`wa-picker-icon-btn`,onClick:m,"aria-label":`Up one folder`,children:(0,N.jsx)(D,{size:18})}),(0,N.jsx)(`span`,{className:`wa-picker-title`,children:r||`Device storage`}),(0,N.jsx)(`button`,{type:`button`,className:`wa-picker-icon-btn`,onClick:n,"aria-label":`Close file picker`,children:(0,N.jsx)(h,{size:18})})]}),c&&(0,N.jsx)(`p`,{className:`wa-picker-error`,role:`alert`,children:c}),u&&(0,N.jsx)(`p`,{className:`wa-picker-empty`,children:`Loading…`}),a&&!u&&(0,N.jsxs)(`ul`,{className:`wa-picker-list`,children:[a.entries.length===0&&(0,N.jsx)(`li`,{className:`wa-picker-empty`,children:`This folder is empty.`}),a.entries.map(e=>(0,N.jsx)(`li`,{children:e.kind===`directory`?(0,N.jsxs)(`button`,{type:`button`,className:`wa-picker-row`,onClick:()=>p(e.name),children:[(0,N.jsx)(s,{size:16,"aria-hidden":!0}),(0,N.jsx)(`span`,{className:`wa-picker-name`,children:e.displayName??e.name})]}):e.kind===`file`?(0,N.jsxs)(`button`,{type:`button`,className:`wa-picker-row`,onClick:()=>g(e),children:[(0,N.jsx)(O,{size:16,"aria-hidden":!0}),(0,N.jsx)(`span`,{className:`wa-picker-name`,children:e.displayName??e.name})]}):null},e.name))]})]})})}function Se(e){return`${Math.floor(e/60)}:${String(e%60).padStart(2,`0`)}`}function Ce({accountId:e,remoteJid:t,sessionKey:n,replyTo:r,onClearReply:i}){let[a,o]=(0,j.useState)(``),[s,c]=(0,j.useState)(!1),[l,f]=(0,j.useState)(null),[p,m]=(0,j.useState)(!1),[g,_]=(0,j.useState)(!1),[ee,v]=(0,j.useState)(!1),[y,b]=(0,j.useState)([]),x=(0,j.useRef)(null),{pendingFiles:S,attachError:C,addFiles:w,removeFile:ie,clearFiles:T}=ye(),{state:E,elapsedSeconds:D,errorMessage:oe,start:k,send:se,discard:ce}=ae(),le=E===`recording`||E===`paused`,ue=(0,j.useCallback)(()=>{k()},[k]),de=(0,j.useCallback)(async()=>{let e=await se();if(e){let t=e.type===`audio/ogg`?`.ogg`:e.type===`audio/mp4`?`.m4a`:`.webm`;w([new File([e],`voice-note${t}`,{type:e.type})])}},[D,se,w]),fe=(0,j.useCallback)(()=>{ce()},[D,ce]),pe=(0,j.useRef)(!1),me=()=>Math.round((typeof window>`u`?900:window.innerHeight)/3),[he,ve]=(0,j.useState)(null),[M,Ce]=(0,j.useState)(null),F=(0,j.useRef)(null),we=(0,j.useCallback)(e=>{let t=F.current;t&&ve(Math.min(me(),Math.max(44,t.startH+(t.startY-e.clientY))))},[]),Te=(0,j.useCallback)(()=>{F.current=null,window.removeEventListener(`pointermove`,we),window.removeEventListener(`pointerup`,Te)},[we]),Ee=(0,j.useCallback)(e=>{F.current={startY:e.clientY,startH:x.current?.offsetHeight??44},window.addEventListener(`pointermove`,we),window.addEventListener(`pointerup`,Te),e.preventDefault()},[we,Te]),De=(0,j.useCallback)(e=>{let t=he??x.current?.offsetHeight??44,n=null;e.key===`ArrowUp`?(e.preventDefault(),n=Math.min(me(),t+24)):e.key===`ArrowDown`&&(e.preventDefault(),n=Math.max(44,t-24)),n!==null&&ve(n)},[he]),Oe=(0,j.useRef)(``);(0,j.useEffect)(()=>{let e=x.current;if(!e)return;let t=Oe.current!==``&&a===``;if(Oe.current=a,he!==null){t&&ve(null);return}let n=e.style.height;e.style.height=`auto`;let r=Math.min(me(),Math.max(44,e.scrollHeight));e.style.height=n,Ce(r)},[a,he]);let I=(a.trim().length>0||S.length>0||y.length>0)&&!s,ke=(0,j.useCallback)(async()=>{if(!pe.current&&!(a.trim().length===0&&S.length===0&&y.length===0)){pe.current=!0,c(!0),f(null);try{let s=`/api/whatsapp-reader/reply?session_key=${encodeURIComponent(n)}`,c;if(S.length>0||y.length>0){let n=new FormData;n.append(`accountId`,e),n.append(`remoteJid`,t),a.trim()&&n.append(`text`,a);for(let e of S)n.append(`files`,e);for(let e of y)n.append(`fileRefs`,e.path);r&&n.append(`quotedId`,r.msgKeyId),c=await fetch(s,{method:`POST`,body:n})}else c=await fetch(s,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({accountId:e,remoteJid:t,text:a,...r?{quotedId:r.msgKeyId}:{}})});let l=await c.json().catch(()=>({}));if(!c.ok){f(l.error??`Send failed.`),console.warn(`[operator-ui] op=reply-fail remoteJid=${t} error=${l.error??`unknown`}`);return}o(``),T(),b([]),i?.()}catch(e){f(`Could not reach the server. Try again.`),console.warn(`[operator-ui] op=reply-fail remoteJid=${t} error=${String(e)}`)}finally{pe.current=!1,c(!1)}}},[a,S,y,r,i,e,t,n,T]),Ae=(0,j.useCallback)(e=>{let t=x.current,{value:n,caret:r}=be(a,e,t?t.selectionStart:null,t?t.selectionEnd:null);o(n),m(!1),requestAnimationFrame(()=>{let e=x.current;e&&(e.focus(),e.setSelectionRange(r,r))})},[a]),je=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),I&&ke())},Me=e=>e.dataTransfer.types.includes(`Files`),L=(0,j.useCallback)(e=>{Me(e)&&(e.preventDefault(),v(!0))},[]),R=(0,j.useCallback)(()=>v(!1),[]),Ne=(0,j.useCallback)(e=>{if(!Me(e))return;e.preventDefault(),v(!1);let t=[...e.dataTransfer.files];t.length!==0&&(Math.max(0,S.length+t.length-5),w(t))},[S.length,w]),Pe=e=>e.startsWith(`image/`)?(0,N.jsx)(A,{size:14}):e===`application/pdf`?(0,N.jsx)(O,{size:14}):(0,N.jsx)(ne,{size:14});return(0,N.jsxs)(`div`,{className:`wa-reply${ee?` wa-reply-drag-over`:``}`,onDragOver:L,onDragLeave:R,onDrop:Ne,children:[g&&(0,N.jsx)(xe,{sessionKey:n,onPick:e=>{b(t=>[...t,e].slice(0,5)),_(!1)},onClose:()=>_(!1)}),p&&(0,N.jsx)(P,{onSelect:Ae}),l&&(0,N.jsx)(`p`,{className:`wa-reply-error`,role:`alert`,children:l}),C&&(0,N.jsx)(`p`,{className:`wa-reply-error`,role:`alert`,children:C}),E===`error`&&oe&&(0,N.jsx)(`p`,{className:`wa-reply-error`,role:`alert`,children:oe}),(S.length>0||y.length>0)&&(0,N.jsxs)(`div`,{className:`wa-reply-attachments`,children:[S.map((e,t)=>(0,N.jsxs)(`div`,{className:`wa-reply-chip`,children:[Pe(e.type),(0,N.jsx)(`span`,{className:`wa-reply-chip-name`,children:e.name}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>ie(t),"aria-label":`Remove ${e.name}`,children:(0,N.jsx)(h,{size:12})})]},`f-${t}`)),y.map((e,t)=>(0,N.jsxs)(`div`,{className:`wa-reply-chip wa-reply-chip-ref`,children:[(0,N.jsx)(O,{size:14}),(0,N.jsx)(`span`,{className:`wa-reply-chip-name`,children:e.name}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>b(e=>e.filter((e,n)=>n!==t)),"aria-label":`Remove ${e.name}`,children:(0,N.jsx)(h,{size:12})})]},`r-${t}`))]}),r&&(0,N.jsxs)(`div`,{className:`wa-reply-quote`,children:[(0,N.jsxs)(`div`,{className:`wa-reply-quote-body`,children:[(0,N.jsx)(`span`,{className:`wa-reply-quote-who`,children:r.fromMe?`You`:r.senderName??`Contact`}),(0,N.jsx)(`span`,{className:`wa-reply-quote-text`,children:r.body||`Message`})]}),(0,N.jsx)(`button`,{type:`button`,className:`wa-reply-quote-cancel`,onClick:()=>i?.(),"aria-label":`Cancel reply`,children:(0,N.jsx)(h,{size:14})})]}),!le&&(0,N.jsx)(`div`,{className:`wa-reply-resize-handle`,role:`separator`,"aria-orientation":`horizontal`,"aria-label":`Resize input — drag up to enlarge`,tabIndex:0,onPointerDown:Ee,onKeyDown:De}),(0,N.jsx)(`div`,{className:`wa-reply-row`,children:le?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`button`,{type:`button`,className:`wa-reply-attach`,onClick:fe,"aria-label":`Cancel recording`,children:(0,N.jsx)(te,{size:20})}),(0,N.jsxs)(`span`,{className:`wa-rec-live`,role:`status`,children:[(0,N.jsx)(`span`,{className:`wa-rec-dot`,"aria-hidden":!0}),Se(D)]}),(0,N.jsx)(`button`,{type:`button`,className:`wa-reply-send`,onClick:()=>void de(),"aria-label":`Stop recording`,children:(0,N.jsx)(u,{size:20})})]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`button`,{type:`button`,className:`wa-reply-emoji`,onClick:()=>m(e=>!e),disabled:s,"aria-label":`Emoji`,"aria-expanded":p,children:(0,N.jsx)(_e,{size:22})}),(0,N.jsx)(`button`,{type:`button`,className:`wa-reply-attach`,onClick:()=>_(!0),disabled:s,"aria-label":`Attach files`,children:(0,N.jsx)(d,{size:22})}),(0,N.jsx)(`textarea`,{ref:x,className:`wa-reply-input`,value:a,rows:1,style:{height:`${he??M??44}px`},placeholder:`Type a message`,disabled:s,onChange:e=>o(e.target.value),onKeyDown:je}),(0,N.jsx)(`button`,{type:`button`,className:`wa-reply-mic`,onClick:()=>void ue(),disabled:s,"aria-label":`Record voice note`,children:(0,N.jsx)(re,{size:22})}),(0,N.jsx)(`button`,{type:`button`,className:`wa-reply-send`,onClick:()=>void ke(),disabled:!I,"aria-label":`Send`,children:(0,N.jsx)(ge,{size:20})})]})})]})}function F({accountId:e,remoteJid:t,contactName:n,sessionKey:r,onBack:i}){let a=_(t),o=t.split(`@`)[0],s=a?`Group`:n===`+${o}`?void 0:`+${o}`,[c,l]=(0,j.useState)(!1),[u,d]=(0,j.useState)(``),f=()=>{l(!1),d(``)},[p,m]=(0,j.useState)(null);return(0,N.jsxs)(`div`,{className:`wa-web`,children:[(0,N.jsxs)(`header`,{className:`wa-web-header`,children:[i&&(0,N.jsx)(`button`,{type:`button`,className:`wa-web-back`,onClick:i,"aria-label":`Back`,children:(0,N.jsx)(D,{size:20})}),(0,N.jsx)(w,{accountId:e,jid:t,sessionKey:r}),c?(0,N.jsxs)(`div`,{className:`wa-web-search`,children:[(0,N.jsx)(oe,{size:18,"aria-hidden":!0}),(0,N.jsx)(`input`,{className:`wa-web-search-input`,type:`text`,autoFocus:!0,placeholder:`Search messages`,"aria-label":`Search messages`,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Escape`&&f()}}),(0,N.jsx)(`button`,{type:`button`,className:`wa-web-search-close`,onClick:f,"aria-label":`Close search`,children:(0,N.jsx)(h,{size:18})})]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`wa-web-titles`,children:[(0,N.jsx)(`span`,{className:`wa-web-name`,children:n}),s&&(0,N.jsx)(`span`,{className:`wa-web-subtitle`,children:s})]}),(0,N.jsx)(`button`,{type:`button`,className:`wa-web-search-toggle`,onClick:()=>l(!0),"aria-label":`Search messages`,children:(0,N.jsx)(oe,{size:20})})]})]}),(0,N.jsx)(`div`,{className:`wa-web-body`,children:(0,N.jsx)(E,{sessionId:``,projectDir:``,sessionKey:r,forceDeliveredOnly:!0,suppressDirectives:!0,store:{accountId:e,remoteJid:t},search:c?u:void 0,onReplyTo:m,groupThread:a})}),(0,N.jsx)(Ce,{accountId:e,remoteJid:t,sessionKey:r,replyTo:p,onClearReply:()=>m(null)})]})}function we(e){let t=new Set,n=[];for(let r of e)for(let e of r.labels)e&&(t.has(e)||k.has(e)&&(t.add(e),n.push(e)));return n}function Te(e){if(!e)return``;let t=new Date(e).getTime();return Number.isFinite(t)?new Date(t).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``}function Ee({conversations:e,sessionKey:t,onBack:n}){let[r,i]=(0,j.useState)(null),a=m(e);return r?r.source===`store`&&r.accountId&&r.remoteJid?(0,N.jsx)(F,{accountId:r.accountId,remoteJid:r.remoteJid,contactName:v(r),sessionKey:t,onBack:()=>i(null)},g(r)):(0,N.jsxs)(`div`,{className:`op-conv op-conv-reader`,children:[(0,N.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,N.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:()=>i(null),"aria-label":`Back to conversations`,children:[(0,N.jsx)(D,{size:16}),` Back`]}),(0,N.jsx)(`span`,{className:`op-conv-title`,children:v(r)})]}),(0,N.jsx)(E,{sessionId:r.sessionId,projectDir:r.projectDir,sessionKey:t,forceDeliveredOnly:!0,suppressDirectives:r.source===`store`,store:r.source===`store`?{accountId:r.accountId,remoteJid:r.remoteJid}:void 0},g(r))]}):(0,N.jsxs)(`div`,{className:`op-conv op-conv-list`,children:[(0,N.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,N.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:n,"aria-label":`Back to chat`,children:[(0,N.jsx)(D,{size:16}),` Chat`]}),(0,N.jsx)(`span`,{className:`op-conv-title`,children:`Conversations`})]}),a.map(e=>(0,N.jsxs)(`div`,{className:`op-conv-group`,children:[(0,N.jsxs)(`div`,{className:`op-conv-group-head`,children:[(0,N.jsx)(y,{channel:e.channel,size:14}),e.label]}),e.rows.map(e=>(0,N.jsxs)(`button`,{type:`button`,className:`op-conv-row`,onClick:()=>{i(e)},children:[e.source===`store`&&e.accountId&&e.remoteJid&&(0,N.jsx)(w,{accountId:e.accountId,jid:e.remoteJid,sessionKey:t,className:`op-conv-avatar`,size:16}),(0,N.jsx)(`span`,{className:`op-conv-name`,children:v(e)}),e.modelGated&&(0,N.jsx)(`span`,{className:`op-conv-gated`,role:`img`,"aria-label":`Model unavailable`,children:(0,N.jsx)(se,{size:13})}),(0,N.jsx)(`span`,{className:`op-conv-when`,children:Te(e.lastMessageAt)})]},g(e)))]},e.channel))]})}var De=/\.(png|jpe?g|gif|webp|svg)$/i;function Oe(e){return De.test(e)}function I(e){return e.entryPath??e.name}var ke=`maxy-data-view`,Ae=95*1024*1024,je=48*1024*1024;function Me(){return typeof window>`u`?`list`:window.localStorage.getItem(ke)===`grid`?`grid`:`list`}function L(){let[e,t]=(0,j.useState)(null),[n,r]=(0,j.useState)(!1);return(0,j.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!n){t(null),r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]),n?e?(0,N.jsx)(x,{cacheKey:e,surface:`data`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=data`);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},children:(0,N.jsx)(`div`,{className:`data-page data-page-full`,children:(0,N.jsx)(R,{cacheKey:e})})}):(0,N.jsx)(`div`,{className:`data-page`,children:(0,N.jsxs)(`div`,{className:`data-empty`,children:[(0,N.jsx)(`p`,{children:`You are not signed in.`}),(0,N.jsxs)(`p`,{children:[`Open the `,(0,N.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,N.jsx)(p,{surface:`gate`})}function R({cacheKey:e}){let{adminFetch:t,cacheKey:n,sessionRefetchNonce:r}=o({initialCacheKey:e,surface:`data`});return(0,N.jsx)(Re,{adminFetch:t,cacheKey:n,sessionRefetchNonce:r})}function Ne(){if(typeof window>`u`)return`@home`;let e=new URLSearchParams(window.location.hash.replace(/^#/,``)).get(`path`);return e&&e.length>0?e:`@home`}function Pe(e){if(typeof window>`u`)return;let t=new URL(window.location.href);t.hash=e===`.`||e===`@home`?``:`path=${encodeURIComponent(e)}`,window.history.replaceState(window.history.state,``,t.toString())}function z(e){return new Promise((t,n)=>{let r=[],i=()=>e.readEntries(e=>{e.length===0?t(r):(r.push(...e),i())},n);i()})}function B(e){return new Promise((t,n)=>e.file(t,n))}async function Fe(e,t=``){let n=[];for(let r of e){if(!r)continue;let e=t?`${t}/${r.name}`:r.name;if(r.isFile)n.push({file:await B(r),relpath:e});else if(r.isDirectory){let t=await z(r.createReader());n.push(...await Fe(t,e))}}return n}function Ie(e,t){if(e===422&&typeof t==`string`){if(/exceeds the .* limit/i.test(t))return`size`;if(/unsupported file type/i.test(t))return`mime`}return`http=${e}`}function Le({adminFetch:e,cacheKey:n,sessionRefetchNonce:a}){let[o,u]=(0,j.useState)(``),d=(0,j.useRef)(null),[f,m]=(0,j.useState)(``),[g,_]=(0,j.useState)(null),[ee,v]=(0,j.useState)(`hybrid`),[y,b]=(0,j.useState)(!1),[x,ne]=(0,j.useState)(null),[C,re]=(0,j.useState)(null),[w,ie]=(0,j.useState)(0),[ae,T]=(0,j.useState)(!1),[E,D]=(0,j.useState)(()=>Ne()),[k,se]=(0,j.useState)(null),[A,ge]=(0,j.useState)(()=>Me()),[_e,ye]=(0,j.useState)(null),[M,be]=(0,j.useState)([]),[P,xe]=(0,j.useState)(null),[Se,Ce]=(0,j.useState)(0),[F,Te]=(0,j.useState)(null),Ee=(0,j.useRef)(null),De=M.slice(0,-1).map(e=>e.name).join(`/`),L=(()=>{let e=M.map(e=>e.name);return e.length>=2&&e[0]===`accounts`?`${e[0]}/${e[1]}`:null})(),R=P?De:E,z=(0,j.useCallback)(e=>R===`.`||R===``?e:`${R}/${e}`,[R]),[B,Le]=(0,j.useState)(!1),[Re,ze]=(0,j.useState)(!1),[He,Ue]=(0,j.useState)(null),[We,qe]=(0,j.useState)(!1),[V,H]=(0,j.useState)(null),[Je,Ye]=(0,j.useState)(null),[Xe,Ze]=(0,j.useState)(null),[Qe,$e]=(0,j.useState)(!1),[et,tt]=(0,j.useState)(null),nt=(0,j.useRef)(null),[rt,U]=(0,j.useState)(0),[it,at]=(0,j.useState)(!1),[ot,st]=(0,j.useState)(``),[ct,lt]=(0,j.useState)(null),[ut,dt]=(0,j.useState)(``),[ft,pt]=(0,j.useState)(null),W=(()=>{let e=E===`.`?[]:E.split(`/`).filter(Boolean);return e.some(e=>e.startsWith(`@`))?!1:e.length>=2&&e[0]===`accounts`})(),[mt,ht]=(0,j.useState)(!1),gt=(0,j.useRef)(null),[_t,G]=(0,j.useState)(!1),vt=(0,j.useRef)(null);(0,j.useEffect)(()=>{let e=o.trim();if(!e){m(``),_(null),ne(null);return}T(!1);let t=setTimeout(()=>m(e),300);return()=>clearTimeout(t)},[o]),(0,j.useEffect)(()=>{if(!f){b(!1);return}let t=!1;return b(!0),ne(null),e(`/api/admin/graph-search?q=${encodeURIComponent(f)}&labels=FileArtifact&limit=20${ae?`&threshold=0`:``}`).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);return t}).then(e=>{t||(_(e.results),v(e.mode??`hybrid`),ie(typeof e.suppressed==`number`?e.suppressed:0))}).catch(e=>{t||ne(e instanceof Error?e.message:String(e))}).finally(()=>{t||b(!1)}),()=>{t=!0}},[f,e,a,ae]);let yt=(0,j.useMemo)(()=>g?we(g):[],[g]),K=C&&yt.includes(C)?C:null,bt=(0,j.useMemo)(()=>g?K?g.filter(e=>e.labels.includes(K)):g:null,[g,K]),xt=(0,j.useCallback)(e=>{let t=e.properties.relativePath;if(typeof t!=`string`||t.length===0)return;let r=`/api/admin/files/download?session_key=${encodeURIComponent(n)}&path=${encodeURIComponent(t)}`,i=document.createElement(`a`);i.href=r,i.rel=`noopener noreferrer`,document.body.appendChild(i),i.click(),i.remove()},[n]);(0,j.useEffect)(()=>{if(!g)return;let e=g.filter(e=>{let t=e.properties.relativePath;return typeof t!=`string`||t.length===0});e.length>0&&console.warn(`[data-search] op=locate-link-missing nodeId=${e.map(e=>e.nodeId).join(`,`)}`)},[g]),(0,j.useEffect)(()=>{let t=!1;return Le(!0),Ue(null),e(`/api/admin/files?path=${encodeURIComponent(E===`.`?``:E)}`).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);return t}).then(e=>{t||(se(e.entries),be(e.displayPath??[]),xe(e.view??null),Ce(typeof e.systemCount==`number`?e.systemCount:0))}).catch(e=>{t||(se([]),be([]),xe(null),Ce(0),Ue(e instanceof Error?e.message:String(e)))}).finally(()=>{t||(Le(!1),ze(!0))}),()=>{t=!0}},[e,E,rt,a]),(0,j.useEffect)(()=>{if(P!==null||!L||Ee.current===L)return;Ee.current=L;let t=!1;return e(`/api/admin/files?path=${encodeURIComponent(`${L}/@home`)}`).then(e=>e.ok?e.json():null).then(e=>{t||!e||Te((e.entries??[]).map(e=>e.name))}).catch(e=>{console.warn(`[data-ui] op=rail-buckets status=error reason="${e instanceof Error?e.message:String(e)}"`)}),()=>{t=!0}},[e,P,L]),(0,j.useEffect)(()=>{Pe(E)},[E]);let St=(0,j.useCallback)(()=>{U(e=>e+1)},[]),q=(0,j.useCallback)(e=>{ht(!1),D(e)},[]),Ct=(0,j.useCallback)(e=>{let t=e.properties.relativePath;if(typeof t!=`string`||t.length===0)return;let n=t.lastIndexOf(`/`),r=n===-1?`.`:t.slice(0,n);u(``),ne(null),re(null),q(r)},[q]),wt=(0,j.useCallback)(()=>{if(!E.split(`/`).some(e=>e.startsWith(`@`))){if(E===`.`||E===``)return;let e=E.split(`/`).filter(Boolean);e.pop(),D(e.length===0?`.`:e.join(`/`));return}M.length!==0&&D(M.length>=2?M.slice(0,M.length-1).map(e=>e.name).join(`/`):`.`)},[E,M]),Tt=(0,j.useCallback)(e=>{le(n,z(I(e)))},[z,n]),[J,Et]=(0,j.useState)(!1),[Y,Dt]=(0,j.useState)(new Set),Ot=(0,j.useRef)(null),X=(0,j.useRef)(!1),kt=typeof navigator<`u`&&typeof navigator.share==`function`&&typeof navigator.canShare==`function`,At=(0,j.useCallback)(e=>{Et(!0),Dt(new Set([e]))},[]),Z=(0,j.useCallback)(e=>{Et(!1),Dt(new Set)},[]),Q=(0,j.useCallback)(e=>{Dt(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),jt=(0,j.useCallback)(e=>{X.current=!1,Ot.current=setTimeout(()=>{X.current=!0,At(e)},500)},[At]),$=(0,j.useCallback)(()=>{Ot.current&&=(clearTimeout(Ot.current),null)},[]),Mt=(0,j.useCallback)(e=>{if(X.current){X.current=!1;return}if(J){Q(e.name);return}Tt(e)},[J,Q,Tt]),Nt=(0,j.useCallback)(e=>{ge(e),typeof window<`u`&&window.localStorage.setItem(ke,e)},[]),Pt=(0,j.useCallback)(e=>{if(X.current){X.current=!1;return}if(J){Q(e.name);return}ye({src:ue(n,z(I(e))),alt:e.displayName??e.name})},[J,Q,z,n]),Ft=(0,j.useCallback)(()=>(k??[]).filter(e=>e.kind===`file`&&Y.has(e.name)),[k,Y]),It=(0,j.useCallback)(()=>{if(Y.size!==1)return null;let e=(k??[]).find(e=>Y.has(e.name));return e&&!e.entryPath?e:null},[k,Y]),Lt=(0,j.useCallback)(()=>(k??[]).filter(e=>(e.kind===`file`||e.kind===`directory`)&&Y.has(e.name)),[k,Y]),Rt=(0,j.useCallback)(()=>{let e=Lt(),t=e.some(e=>e.kind===`directory`);e.length===1&&!t?Tt(e[0]):e.length>=1&&ce(n,e.map(e=>z(I(e)))),Z(`action`)},[Lt,Tt,z,n,Z]),zt=(0,j.useCallback)(async()=>{let t=Ft(),n=t.filter(e=>!e.protected),r=t.length-n.length;tt(r>0?`${r} protected file(s) kept`:null);for(let t of n){let n=z(I(t));try{let t=await e(`/api/admin/files?path=${encodeURIComponent(n)}`,{method:`DELETE`}),r=await t.json().catch(()=>({error:`HTTP ${t.status}`}));if(!t.ok)throw Error(r.error??`HTTP ${t.status}`)}catch(e){tt(e instanceof Error?e.message:String(e))}}U(e=>e+1),Z(`action`)},[Ft,z,e,Z]),Bt=(0,j.useCallback)(async()=>{let e=Ft();if(kt)try{let t=await Promise.all(e.map(async e=>{let t=z(I(e)),r=`/api/admin/files/download?session_key=${encodeURIComponent(n)}&path=${encodeURIComponent(t)}`,i=await(await fetch(r)).blob();return new File([i],e.displayName??e.name,{type:i.type||`application/octet-stream`})}));navigator.canShare({files:t})&&await navigator.share({files:t})}catch(e){console.warn(`[data-ui] op=share-failed err=${e instanceof Error?e.message:String(e)}`)}},[Ft,kt,z,n]),Vt=(0,j.useCallback)(()=>{nt.current?.click()},[]),Ht=(0,j.useCallback)((e,t={})=>{let r=(r,i,a)=>{let o=new URLSearchParams({session_key:n,path:E===`.`?``:E,filename:e.name});t.relpath&&o.set(`relpath`,t.relpath),t.token&&o.set(`token`,t.token);for(let[e,t]of Object.entries(i))o.set(e,t);return new Promise(t=>{let n=new XMLHttpRequest;n.open(`POST`,`/api/admin/files/upload?${o.toString()}`),n.setRequestHeader(`Content-Type`,e.type||`application/octet-stream`),a&&(n.upload.onprogress=e=>{e.lengthComputable&&a(e.loaded)}),n.onload=()=>{let e={};try{e=JSON.parse(n.responseText)}catch{}t({status:n.status,data:e})},n.onerror=()=>t({status:0,data:{}}),n.onabort=()=>t({status:0,data:{error:`aborted`}}),n.send(r)})};if(e.size<=Ae)return r(e,{},n=>t.onProgress?.(n,e.size));let i=`${Date.now().toString(36)}-${Math.random().toString(16).slice(2,10)}`,a=Math.ceil(e.size/je);return(async()=>{let n={status:0,data:{}};for(let o=0;o<a;o++){let s=o*je;if(n=await r(e.slice(s,Math.min(s+je,e.size)),{uploadId:i,seq:String(o),total:String(a)},n=>t.onProgress?.(s+n,e.size)),!(n.status>=200&&n.status<300))return n}return n})()},[n,E]),Ut=(0,j.useCallback)(async e=>{Ye(null),qe(!0),H({loaded:0,total:e.size});try{let{status:t,data:n}=await Ht(e,{onProgress:(e,t)=>H({loaded:e,total:t})});t>=200&&t<300&&n.path?(D(n.path.split(`/`).slice(0,-1).join(`/`)||`.`),U(e=>e+1)):Ye(t===0?`Network error during upload — the connection failed before the server responded.`:n.error??`Upload failed (HTTP ${t}).`)}finally{qe(!1),H(null),nt.current&&(nt.current.value=``)}},[Ht]),Wt=(0,j.useCallback)(e=>{W&&Array.from(e.dataTransfer.types).includes(`Files`)&&(e.preventDefault(),$e(!0))},[W]),Gt=(0,j.useCallback)(e=>{e.currentTarget.contains(e.relatedTarget)||$e(!1)},[]),Kt=(0,j.useCallback)(async e=>{e.preventDefault(),$e(!1);let t=Math.random().toString(16).slice(2,10),n=Array.from(e.dataTransfer.items);if(n.length===0)return;if(!W){Ye(`Open a folder inside your account to upload`);return}let r=n.map(e=>e.webkitGetAsEntry?.()).filter(e=>!!e);qe(!0),Ye(null),Ze(null);try{let e=await Fe(r),n=0,i=[];for(let r=0;r<e.length;r++){let{file:a,relpath:o}=e[r];H({loaded:0,total:a.size});let{status:s,data:c}=await Ht(a,{relpath:o,token:t,onProgress:(e,t)=>H({loaded:e,total:t})});if(s>=200&&s<300)n++;else{let e=s===0?`http=0`:Ie(s,c.error);i.push(`${o} (${e})`)}}Ze(`Uploaded ${n}, skipped ${i.length}${i.length?`: ${i.join(`, `)}`:``}`),U(e=>e+1)}catch(e){Ye(e instanceof Error?e.message:String(e))}finally{qe(!1),H(null)}},[W,Ht]),qt=(0,j.useCallback)(async()=>{let t=ot.trim();if(t){pt(null);try{let n=await e(`/api/admin/files/folder`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:E===`.`?``:E,name:t})}),r=await n.json().catch(()=>({error:`HTTP ${n.status}`}));if(!n.ok)throw Error(r.error??`HTTP ${n.status}`);at(!1),st(``),U(e=>e+1)}catch(e){pt(e instanceof Error?e.message:String(e))}}},[e,ot,E]),Jt=(0,j.useCallback)(async()=>{if(!ct)return;let t=ut.trim();if(!t)return;pt(null);let n=z(ct);try{let r=await e(`/api/admin/files/rename`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:n,newName:t})}),i=await r.json().catch(()=>({error:`HTTP ${r.status}`}));if(!r.ok)throw Error(i.error??`HTTP ${r.status}`);lt(null),dt(``),Z(`action`),U(e=>e+1)}catch(e){pt(e instanceof Error?e.message:String(e))}},[e,ut,ct,z,Z]);(0,j.useEffect)(()=>{if(!mt)return;let e=e=>{gt.current&&!gt.current.contains(e.target)&&ht(!1)},t=e=>{e.key===`Escape`&&ht(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[mt]),(0,j.useEffect)(()=>{if(!_t)return;let e=e=>{vt.current&&!vt.current.contains(e.target)&&G(!1)},t=e=>{e.key===`Escape`&&G(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[_t]);let Yt=(0,j.useCallback)(e=>M.slice(0,e+1).map(e=>e.name).join(`/`),[M]),Xt=M.length>=2,Zt=Xt?[{name:`.`,label:`data`},...M.slice(0,M.length-2).map((e,t)=>({name:Yt(t),label:e.displayName??e.name}))]:[];return Re?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`data-toolbar`,children:[J?(0,N.jsxs)(`button`,{type:`button`,className:`data-select-cancel`,onClick:()=>Z(`cancel`),"aria-label":`Cancel selection`,children:[(0,N.jsx)(h,{size:14}),` Cancel`]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`data-search-input`,children:[o===``&&(0,N.jsx)(oe,{size:14}),(0,N.jsx)(`input`,{ref:d,type:`text`,value:o,onChange:e=>u(e.target.value),autoFocus:!0,autoComplete:`off`,spellCheck:!1}),y&&(0,N.jsx)(t,{size:14,className:`spin`}),o!==``&&(0,N.jsx)(`button`,{type:`button`,className:`data-search-inline-btn`,onClick:()=>{u(``),d.current?.focus()},title:`Clear search`,"aria-label":`Clear search`,children:(0,N.jsx)(h,{size:14})})]}),(0,N.jsxs)(`div`,{className:`data-toolbar-actions`,ref:vt,children:[(0,N.jsx)(`button`,{type:`button`,className:`data-action-overflow`,onClick:()=>G(e=>!e),"aria-haspopup":`menu`,"aria-expanded":_t,"aria-label":`File actions`,title:`File actions`,children:(0,N.jsx)(de,{size:16})}),(0,N.jsxs)(`div`,{className:`data-action-group`,role:`group`,"aria-label":`File actions`,"data-open":_t?`true`:void 0,children:[(0,N.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{St(),G(!1)},disabled:B,title:`Refresh this folder`,"aria-label":`Refresh this folder`,children:[B?(0,N.jsx)(t,{size:16,className:`spin`}):(0,N.jsx)(S,{size:16}),(0,N.jsx)(`span`,{className:`data-action-label`,children:`Refresh`})]}),(0,N.jsxs)(`button`,{type:`button`,className:`data-action-btn admin-btn-cta`,onClick:()=>{Vt(),G(!1)},disabled:We||!W,title:W?`Upload a file`:`Open a folder inside your account to upload`,"aria-label":`Upload a file`,children:[We?V&&V.total>0?(0,N.jsxs)(`span`,{className:`data-upload-pct`,children:[Math.round(V.loaded/V.total*100),`%`]}):(0,N.jsx)(t,{size:16,className:`spin`}):(0,N.jsx)(ve,{size:16}),(0,N.jsx)(`span`,{className:`data-action-label`,children:`Upload`})]}),(0,N.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{at(e=>!e),st(``),pt(null),G(!1)},disabled:We||!W,title:W?`New folder`:`Open a folder inside your account to create one`,"aria-label":`New folder`,children:[(0,N.jsx)(fe,{size:16}),(0,N.jsx)(`span`,{className:`data-action-label`,children:`New folder`})]}),(0,N.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{Nt(A===`grid`?`list`:`grid`),G(!1)},title:A===`grid`?`List view`:`Grid view`,"aria-label":A===`grid`?`Switch to list view`:`Switch to grid view`,"aria-pressed":A===`grid`,children:[A===`grid`?(0,N.jsx)(me,{size:16}):(0,N.jsx)(pe,{size:16}),(0,N.jsx)(`span`,{className:`data-action-label`,children:A===`grid`?`List view`:`Grid view`})]})]})]})]}),(0,N.jsxs)(`div`,{className:`data-breadcrumbs`,children:[E!==`.`&&(0,N.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost data-back-btn`,onClick:wt,title:`Up one level`,"aria-label":`Up one level`,children:(0,N.jsx)(l,{size:14})}),Xt?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`span`,{className:`data-crumb-wrap`,ref:gt,children:[(0,N.jsx)(`button`,{type:`button`,className:`data-crumb data-crumb-ellipsis`,onClick:()=>ht(e=>!e),"aria-haspopup":`menu`,"aria-expanded":mt,"aria-label":`Show parent folders`,title:`Show parent folders`,children:`…`}),mt&&(0,N.jsx)(`div`,{className:`data-crumb-menu`,role:`menu`,children:Zt.map(e=>(0,N.jsx)(`button`,{type:`button`,role:`menuitem`,className:`data-crumb-menu-item`,onClick:()=>q(e.name),title:e.label,children:e.label},e.name))})]}),[M.length-2,M.length-1].map(e=>{let t=M[e];return(0,N.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,N.jsx)(`span`,{className:`data-crumb-sep`,children:`›`}),(0,N.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>q(Yt(e)),title:t.name,children:t.displayName??t.name})]},Yt(e))})]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>q(`.`),children:`data`}),M.map((e,t)=>(0,N.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,N.jsx)(`span`,{className:`data-crumb-sep`,children:`›`}),(0,N.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>q(Yt(t)),title:e.name,children:e.displayName??e.name})]},Yt(t)))]})]}),it&&(0,N.jsxs)(`div`,{className:`data-inline-form`,children:[(0,N.jsx)(`input`,{type:`text`,className:`data-inline-input`,placeholder:`Folder name`,value:ot,autoFocus:!0,onChange:e=>st(e.target.value),onKeyDown:e=>{e.key===`Enter`&&qt(),e.key===`Escape`&&at(!1)}}),(0,N.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:qt,children:`Create`}),(0,N.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost`,onClick:()=>at(!1),children:`Cancel`})]}),ct&&(0,N.jsxs)(`div`,{className:`data-inline-form`,children:[(0,N.jsx)(`input`,{type:`text`,className:`data-inline-input`,placeholder:`New name`,value:ut,autoFocus:!0,onChange:e=>dt(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Jt(),e.key===`Escape`&&lt(null)}}),(0,N.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:Jt,children:`Rename`}),(0,N.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost`,onClick:()=>lt(null),children:`Cancel`})]}),ft&&(0,N.jsx)(`div`,{className:`data-error`,children:ft}),(0,N.jsx)(`input`,{type:`file`,ref:nt,hidden:!0,onChange:e=>{let t=e.target.files?.[0];t&&Ut(t)}})]}),(0,N.jsxs)(`div`,{className:`data-body`,"data-drag-active":Qe?`true`:void 0,onDragEnter:Wt,onDragOver:Wt,onDragLeave:Gt,onDrop:Kt,children:[P===null&&L&&F&&F.length>0&&(0,N.jsxs)(`aside`,{className:`data-rail`,"aria-label":`Folders`,children:[(0,N.jsx)(`span`,{className:`data-rail-label`,children:`Folders`}),(0,N.jsx)(`ul`,{className:`data-rail-list`,children:F.map(e=>{let t=`${L}/${e}`,n=E===t||E.startsWith(`${t}/`);return(0,N.jsx)(`li`,{children:(0,N.jsxs)(`button`,{type:`button`,className:`data-rail-item`,"aria-current":n?`true`:void 0,onClick:()=>q(t),children:[(0,N.jsx)(s,{size:13}),(0,N.jsx)(`span`,{className:`data-rail-item-name`,children:e})]})},e)})})]}),(0,N.jsxs)(`div`,{className:`data-content`,children:[(x!==null||g!==null)&&(0,N.jsxs)(`section`,{className:`data-panel admin-card`,children:[x&&(0,N.jsxs)(`div`,{className:`data-error`,children:[`Search failed: `,x]}),yt.length>0&&(0,N.jsx)(`div`,{className:`data-chip-row`,role:`group`,"aria-label":`Filter by type`,children:yt.map(e=>{let t=e===K;return(0,N.jsx)(`button`,{type:`button`,className:`data-chip`,"data-active":t,onClick:()=>re(t?null:e),children:Ve([e])??e},e)})}),g&&!y&&(0,N.jsxs)(`div`,{className:`data-results-meta`,children:[bt.length,` of `,g.length,` result`,g.length===1?``:`s`]}),g&&!y&&!K&&w>0&&!ae&&(0,N.jsxs)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>T(!0),children:[w,` low-confidence result`,w===1?``:`s`,` hidden — show all`]}),g&&!y&&!K&&ae&&(0,N.jsx)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>T(!1),children:`Showing all results — hide low-confidence`}),g&&g.length===0&&!y&&(0,N.jsx)(`div`,{className:`data-empty-results`,children:`No matches. Try a different keyword.`}),bt&&bt.length>0&&(0,N.jsx)(`ul`,{className:`data-results`,children:bt.map(e=>(0,N.jsx)(Be,{hit:e,mode:ee,onDownload:xt,onLocate:Ct},e.nodeId))})]}),(0,N.jsxs)(`section`,{className:`data-panel data-panel--wide admin-card`,children:[V&&(0,N.jsxs)(`div`,{className:`data-upload-progress`,role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":V.total>0?Math.round(V.loaded/V.total*100):void 0,children:[(0,N.jsx)(`div`,{className:`data-upload-progress-track`,children:(0,N.jsx)(`div`,{className:`data-upload-progress-fill`,style:{width:`${V.total>0?Math.round(V.loaded/V.total*100):0}%`}})}),(0,N.jsxs)(`span`,{className:`data-upload-progress-label`,children:[`Uploading… `,V.total>0?`${Math.round(V.loaded/V.total*100)}%`:``]})]}),Je&&(0,N.jsxs)(`div`,{className:`data-error`,children:[`Upload failed: `,Je]}),Xe&&(0,N.jsx)(`div`,{className:`data-status`,children:Xe}),et&&(0,N.jsxs)(`div`,{className:`data-error`,children:[`Delete failed: `,et]}),He&&(0,N.jsx)(`div`,{className:`data-error`,children:He}),B&&(0,N.jsxs)(`div`,{className:`data-loading`,children:[(0,N.jsx)(t,{size:14,className:`spin`}),` Loading…`]}),!J&&!B&&P!==`home`&&k&&k.length>0&&(0,N.jsxs)(`div`,{className:`data-select-hint`,children:[(0,N.jsx)(he,{size:13}),(0,N.jsx)(`span`,{children:`Press and hold a file to select, rename, or delete it.`})]}),!B&&P!==`home`&&k&&k.length===0&&!He&&(0,N.jsx)(`div`,{className:`data-empty-results`,children:`Empty directory.`}),!B&&P===`home`&&k&&(0,N.jsxs)(`ul`,{className:`routine-list data-home-list`,children:[k.map(e=>(0,N.jsxs)(`li`,{className:`data-home-card`,children:[(0,N.jsxs)(`button`,{type:`button`,className:`data-home-card-head`,onClick:()=>q(z(e.name)),children:[(0,N.jsx)(`span`,{className:`data-home-card-title`,children:e.name}),(0,N.jsx)(`span`,{className:`data-home-card-count`,children:e.childCount===null||e.childCount===void 0?`—`:`${e.childCount} ${e.childCount===1?`item`:`items`}`})]}),(0,N.jsxs)(`ul`,{className:`data-home-card-children`,children:[e.childCount===null&&(0,N.jsx)(`li`,{className:`data-home-card-error`,children:`Could not read this folder.`}),e.childCount===0&&(0,N.jsx)(`li`,{className:`data-home-card-empty`,children:`Empty.`}),(e.children??[]).map(e=>(0,N.jsxs)(`li`,{className:`data-home-card-child`,children:[e.kind===`directory`?(0,N.jsx)(s,{size:12}):(0,N.jsx)(O,{size:12}),(0,N.jsx)(`span`,{className:`data-home-card-child-name`,children:e.name})]},e.name)),typeof e.childCount==`number`&&e.childCount>(e.children?.length??0)&&(0,N.jsxs)(`li`,{className:`data-home-card-more`,children:[`+`,e.childCount-(e.children?.length??0),` more`]})]})]},e.name)),(0,N.jsxs)(`li`,{className:`data-home-card`,children:[(0,N.jsxs)(`button`,{type:`button`,className:`data-home-card-head`,onClick:()=>q(z(`@system`)),children:[(0,N.jsx)(`span`,{className:`data-home-card-title`,children:`system`}),(0,N.jsxs)(`span`,{className:`data-home-card-count`,children:[Se,` `,Se===1?`item`:`items`]})]}),(0,N.jsx)(`ul`,{className:`data-home-card-children`,children:(0,N.jsx)(`li`,{className:`data-home-card-empty`,children:`Platform and plugin folders.`})})]})]}),!B&&P!==`home`&&k&&k.length>0&&A===`grid`&&(0,N.jsx)(`ul`,{className:`data-grid`,children:k.map(e=>{let t=e.displayName??e.name,r=J&&Y.has(e.name);if(e.kind===`directory`)return(0,N.jsx)(`li`,{className:`data-grid-cell`,"data-selected":r?`true`:void 0,children:(0,N.jsxs)(`button`,{type:`button`,className:`data-grid-tile`,onPointerDown:()=>jt(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>{if(X.current){X.current=!1;return}if(J){Q(e.name);return}q(z(e.name))},children:[J&&(0,N.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,N.jsx)(s,{size:28,className:`data-grid-glyph`}),(0,N.jsx)(`span`,{className:`data-grid-label`,title:e.name,children:t})]})},e.name);if(e.kind===`file`){let i=Oe(I(e)),a=z(I(e));return(0,N.jsx)(`li`,{className:`data-grid-cell`,"data-selected":r?`true`:void 0,children:(0,N.jsxs)(`button`,{type:`button`,className:`data-grid-tile${i?` data-grid-tile-image`:``}`,onPointerDown:()=>jt(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>i?Pt(e):Mt(e),title:J?void 0:i?`Preview ${t}`:`Download ${t}`,children:[J&&(0,N.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),i?(0,N.jsx)(`img`,{className:`data-grid-thumb`,src:ue(n,a),alt:t,loading:`lazy`,onError:()=>console.warn(`[data] op=thumb-error path=${a}`)}):(0,N.jsx)(O,{size:28,className:`data-grid-glyph`}),(0,N.jsx)(`span`,{className:`data-grid-label`,title:e.name,children:t}),!i&&(0,N.jsx)(`span`,{className:`data-grid-sub`,children:Ge(e.sizeBytes)})]})},e.name)}return(0,N.jsx)(`li`,{className:`data-grid-cell`,children:(0,N.jsxs)(`div`,{className:`data-grid-tile data-entry-disabled`,children:[(0,N.jsx)(O,{size:28,className:`data-grid-glyph`}),(0,N.jsx)(`span`,{className:`data-grid-label`,children:t}),(0,N.jsx)(`span`,{className:`data-grid-sub`,children:`special`})]})},e.name)})}),!B&&P!==`home`&&k&&k.length>0&&A===`list`&&(0,N.jsx)(`ul`,{className:`data-entries`,children:k.map(e=>{let t=e.displayName??e.name;if(e.kind===`directory`){let n=J&&Y.has(e.name);return(0,N.jsx)(`li`,{className:`data-entry`,"data-selected":n?`true`:void 0,children:(0,N.jsxs)(`button`,{type:`button`,className:`data-entry-btn`,onPointerDown:()=>jt(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>{if(X.current){X.current=!1;return}if(J){Q(e.name);return}q(z(e.name))},children:[J&&(0,N.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,N.jsx)(s,{size:14}),(0,N.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t})]})},e.name)}if(e.kind===`file`){let n=J&&Y.has(e.name);return(0,N.jsx)(`li`,{className:`data-entry`,"data-selected":n?`true`:void 0,children:(0,N.jsxs)(`button`,{type:`button`,className:`data-entry-btn data-entry-file`,onPointerDown:()=>jt(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>Mt(e),title:J?void 0:`Download ${t}`,children:[J&&(0,N.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,N.jsxs)(`span`,{className:`data-entry-text`,children:[(0,N.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t}),(0,N.jsxs)(`span`,{className:`data-entry-meta`,title:`Modified ${Ke(e.modifiedAt)}`,children:[Ge(e.sizeBytes),` · `,Ke(e.modifiedAt)]})]})]})},e.name)}return(0,N.jsx)(`li`,{className:`data-entry`,children:(0,N.jsx)(`div`,{className:`data-entry-btn data-entry-file data-entry-disabled`,children:(0,N.jsxs)(`span`,{className:`data-entry-text`,children:[(0,N.jsx)(`span`,{className:`data-entry-name`,children:t}),(0,N.jsx)(`span`,{className:`data-entry-meta`,children:`special`})]})})},e.name)})})]})]})]}),J&&(0,N.jsx)(`div`,{className:`data-select-bar`,role:`toolbar`,"aria-label":`Selection actions`,children:(0,N.jsxs)(`div`,{className:`data-select-bar-inner`,children:[(0,N.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:Bt,disabled:!kt||Y.size===0,title:kt?`Share selected files`:`Sharing is not supported on this device`,children:[(0,N.jsx)(r,{size:16}),` Share`]}),(0,N.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:Rt,disabled:Y.size===0,children:[(0,N.jsx)(c,{size:16}),` Download`]}),(0,N.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:()=>{let e=It();e&&(lt(e.name),dt(e.name))},disabled:!It(),children:[(0,N.jsx)(i,{size:16}),` Rename`]}),(0,N.jsxs)(`button`,{type:`button`,className:`data-select-action data-select-delete`,onClick:zt,disabled:Y.size===0,children:[(0,N.jsx)(te,{size:16}),` Delete`]})]})}),_e&&(0,N.jsx)(`div`,{className:`chat-attachment-overlay`,role:`dialog`,"aria-label":_e.alt,onClick:()=>ye(null),children:(0,N.jsx)(`img`,{className:`chat-attachment-overlay-image`,src:_e.src,alt:_e.alt})})]}):(0,N.jsx)(p,{surface:`gate`})}function Re({adminFetch:e,cacheKey:t,sessionRefetchNonce:n}){let r=(0,j.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]),i=(0,j.useCallback)(e=>{e===`chat`&&(window.location.href=`/`)},[]),[a,o]=(0,j.useState)([]),[s,c]=(0,j.useState)(`files`),{subAccounts:l,activeAccountId:u,switching:d,switchAccount:f}=b(t);return(0,j.useEffect)(()=>{if(!t)return;let e=!1;return fetch(`/api/operator-conversations/conversations?session_key=${encodeURIComponent(t)}`).then(e=>e.ok?e.json():{conversations:[]}).then(t=>{e||o(t.conversations??[])}).catch(()=>{}),()=>{e=!0}},[t]),(0,N.jsxs)(`main`,{className:`data-main`,children:[(0,N.jsx)(ee,{variant:`operator`,onNavigate:i,onOpenConversations:a.length>0?()=>c(`conversations`):void 0,onToggleSidebar:()=>{},sidebarOpen:!1,onLogout:r,onDisconnect:async()=>!0,disconnecting:!1,subAccounts:l,activeAccountId:u,switchingAccount:d,onSwitchAccount:f}),s===`conversations`?(0,N.jsx)(Ee,{conversations:a,sessionKey:t,onBack:()=>c(`files`)}):(0,N.jsx)(Le,{adminFetch:e,cacheKey:t,sessionRefetchNonce:n})]})}function ze({cacheKey:e}){let{adminFetch:t,cacheKey:n,sessionRefetchNonce:r}=o({initialCacheKey:e,surface:`data`});return(0,N.jsx)(`div`,{className:`data-page`,children:(0,N.jsx)(`main`,{className:`data-main`,children:(0,N.jsx)(Le,{adminFetch:t,cacheKey:n,sessionRefetchNonce:r})})})}function Be({hit:e,mode:t,onDownload:n,onLocate:r}){let i=He(e.properties),a=Ue(e.properties),o=Ve(e.labels),c=We(e.properties),[l,u]=(0,j.useState)(!1),d=a&&a.length>280,f=l||!d?a:a?.slice(0,280)+`…`,p=t===`bm25`?`bm25 ${e.bm25Score.toFixed(2)}`:`vector ${e.vectorScore.toFixed(2)} · bm25 ${e.bm25Score.toFixed(2)} · combined ${e.score.toFixed(2)}`,m=e.properties.relativePath,h=typeof m==`string`&&m.length>0,g=h?m.lastIndexOf(`/`):-1,_=h?g===-1?`data`:m.slice(0,g):null;return(0,N.jsxs)(`li`,{className:`data-result`,children:[(0,N.jsxs)(`div`,{role:`button`,tabIndex:0,className:`data-result-open`,onClick:()=>n(e),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),n(e))},"aria-label":`Download ${i??o??`file`}`,children:[o&&(0,N.jsx)(`div`,{className:`data-result-header`,children:(0,N.jsx)(`span`,{className:`data-result-labels`,children:o})}),i&&(0,N.jsx)(`div`,{className:`data-result-title`,children:i}),a&&(0,N.jsx)(`pre`,{className:`data-result-body`,children:f}),(0,N.jsxs)(`div`,{className:`data-result-scores`,children:[c&&(0,N.jsxs)(`span`,{className:`data-result-updated`,children:[`Updated `,Ke(c),` · `]}),p]})]}),h&&(0,N.jsxs)(`button`,{type:`button`,className:`data-result-locate`,onClick:()=>r(e),title:`Locate in ${_}`,"aria-label":`Locate in ${_}`,children:[(0,N.jsx)(s,{size:12}),_]}),d&&(0,N.jsx)(`button`,{type:`button`,className:`data-result-toggle`,onClick:()=>u(e=>!e),children:l?`Show less`:`Show more`})]})}function Ve(e){if(e.length===0)return null;let t=e[0].replace(/([a-z])([A-Z])/g,`$1 $2`);return t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()}function He(e){for(let t of[`title`,`name`,`summary`,`headline`]){let n=e[t];if(typeof n==`string`&&n.length>0)return n.length>140?n.slice(0,140)+`…`:n}return null}function Ue(e){for(let t of[`content`,`summary`,`body`,`description`,`text`]){let n=e[t];if(typeof n==`string`&&n.length>0)return n}return null}function We(e){for(let t of[`updatedAt`,`modifiedAt`,`fetchedAt`,`createdAt`,`lastModified`]){let n=e[t];if(typeof n==`string`&&n.length>0)return n}return null}function Ge(e){return e==null?``:e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)} MB`:`${(e/1024/1024/1024).toFixed(1)} GB`}function Ke(e){try{let t=new Date(e);if(isNaN(t.getTime()))return`—`;let n=typeof navigator<`u`?navigator.languages&&navigator.languages.length>0?[...navigator.languages]:[navigator.language]:void 0;return t.toLocaleString(n,{dateStyle:`medium`,timeStyle:`short`})}catch{return`—`}}export{ze as n,F as r,L as t};
@@ -1 +0,0 @@
1
- import{B as e}from"./useSubAccountSwitcher-C7TtIbR3.js";var t=e(`play`,[[`path`,{d:`M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z`,key:`10ikf1`}]]);export{t};
@@ -1 +0,0 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{G as t,Y as n,Z as r}from"./useSubAccountSwitcher-C7TtIbR3.js";import"./useVoiceRecorder-DgyAGgmF.js";import{O as i}from"./AdminShell-D24evn4t.js";import{a,c as o,i as s,o as c,r as l,s as u}from"./page-CpJpyoPS.js";import"./useCopyFeedback-BwK1RhmF.js";var d=n(),f=e(r(),1),p=t();function m({gateState:e,setGateState:t,grantInfo:n,resolvedSlugRef:r}){let[a,o]=(0,f.useState)(``),[s,c]=(0,f.useState)(!1),[l,u]=(0,f.useState)(null);async function d(e){e.preventDefault();let n=a.trim().toLowerCase();if(!n){u(`Enter the email you were invited on.`);return}c(!0),u(null);try{let e=await fetch(`/api/access/request-magic-link`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({contactValue:n,agentSlug:r.current})});if(e.status===429){u((await e.json().catch(()=>({})))?.error||`Too many requests. Try again later.`);return}t(`request-sent`)}catch{u(`Could not reach the server. Check your connection and try again.`)}finally{c(!1)}}return(0,p.jsxs)(`div`,{className:`access-gate`,children:[e===`verifying`&&(0,p.jsxs)(`div`,{className:`access-gate-message`,children:[(0,p.jsx)(`h2`,{children:`Verifying your link…`}),(0,p.jsx)(`p`,{children:`This takes a moment.`})]}),e===`verify-failed`&&(0,p.jsxs)(`div`,{className:`access-gate-message`,children:[(0,p.jsx)(`h2`,{children:`That link did not work`}),(0,p.jsx)(`p`,{children:`It may have expired, already been used, or been for a different agent. You can request a fresh one below.`}),(0,p.jsx)(i,{onClick:()=>{t(`request-link`),u(null)},children:`Request a new link`})]}),e===`request-link`&&(0,p.jsxs)(`form`,{className:`access-gate-form`,onSubmit:d,children:[(0,p.jsx)(`h2`,{children:n?.displayName?`Welcome back, ${n.displayName}`:`Sign in`}),(0,p.jsx)(`p`,{children:`Enter the email you were invited on and we will send you a fresh link.`}),(0,p.jsx)(`label`,{htmlFor:`access-email`,children:`Email`}),(0,p.jsx)(`input`,{id:`access-email`,type:`email`,inputMode:`email`,autoComplete:`email`,value:a,onChange:e=>o(e.target.value),disabled:s}),l&&(0,p.jsx)(`p`,{className:`access-gate-error`,children:l}),(0,p.jsx)(i,{type:`submit`,disabled:s||!a.trim(),children:s?`Sending…`:`Send me a link`})]}),e===`request-sent`&&(0,p.jsxs)(`div`,{className:`access-gate-message`,children:[(0,p.jsx)(`h2`,{children:`Check your email`}),(0,p.jsx)(`p`,{children:`If that address is on the invite list, a fresh link is on the way. It expires in 15 minutes.`}),(0,p.jsx)(i,{onClick:()=>{t(`request-link`),o(``),u(null)},children:`Try a different email`})]})]})}function h(){let[e,t]=(0,f.useState)(null),[n,r]=(0,f.useState)(null),[i,l]=(0,f.useState)(`loading`),[d,p]=(0,f.useState)(``),[m,h]=(0,f.useState)(null),[g,_]=(0,f.useState)(null),[v,y]=(0,f.useState)(!1),[b,x]=(0,f.useState)(null),S=(0,f.useMemo)(()=>a(),[]),C=(0,f.useRef)(S||``),w=(0,f.useRef)(null),T=(0,f.useRef)(null),E=(0,f.useRef)(!1),D=(0,f.useRef)(null),[O,k]=(0,f.useState)(`request-link`),[A,j]=(0,f.useState)(null),M=(0,f.useRef)(null),N=(0,f.useRef)(null);(0,f.useEffect)(()=>{try{let e=sessionStorage.getItem(`maxy_session`);e&&(N.current=e)}catch{}},[]),(0,f.useEffect)(()=>{try{let e=c();e&&sessionStorage.setItem(s,e)}catch{}},[]);let P=(0,f.useCallback)(e=>{w.current=e,t(e);try{sessionStorage.setItem(`maxy_session`,e)}catch{}l(`chat`)},[]),F=(0,f.useCallback)(()=>{w.current=null;try{sessionStorage.removeItem(`maxy_session`)}catch{}t(null),l(`auth-required`),k(`request-link`)},[]),I=(0,f.useCallback)(async e=>{k(`verifying`);try{let t=C.current,n=await fetch(`/api/access/verify-token`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({token:e,agentSlug:t})});if(window.history.replaceState({},``,window.location.pathname),n.ok){let e=await n.json().catch(()=>({}));return e?.displayName&&j({displayName:e.displayName,contactValue:``,expiresAt:null,status:`active`}),!0}return k(`verify-failed`),!1}catch{return k(`verify-failed`),!1}},[]),L=(0,f.useCallback)(async()=>{if(w.current)return w.current;if(T.current)return T.current;let e=(async()=>{try{let e=N.current,n=await fetch(`/api/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({session_id:u(),...S?{agent:S}:{},...e?{session_key:e}:{}})});if(!n.ok){let e=await n.json().catch(()=>({error:``}));return o&&console.error(`[session] POST /api/session failed: ${n.status} ${n.statusText}`,e),n.status===404?r(e.error||`Agent not found`):n.status===503&&r(e.error||`Service unavailable`),null}let i=await n.json();if(i.auth_required){i.agent_id&&(C.current=i.agent_id),p(i.displayName||``),i.agentImage&&h(i.agentImage),i.agentImageShape&&_(i.agentImageShape),i.showAgentName&&y(i.showAgentName),i.branding&&x(i.branding),l(`auth-required`);let e=new URLSearchParams(window.location.search).get(`token`);return e?await I(e)&&window.location.reload():k(`request-link`),null}w.current=i.session_key,t(i.session_key),i.displayName&&p(i.displayName),i.agentImage&&h(i.agentImage),i.agentImageShape&&_(i.agentImageShape),i.showAgentName&&y(i.showAgentName),i.branding&&x(i.branding),l(`chat`),i.resumed&&i.messages&&(E.current=!0,D.current=i.messages);try{sessionStorage.setItem(`maxy_session`,i.session_key)}catch{}return i.session_key}catch(e){return o&&console.error(`[session] fetch /api/session threw:`,e),r(`Unable to connect. Please check your connection and try again.`),null}finally{T.current=null}})();return T.current=e,e},[S,I]);return{sessionId:e,cacheKeyRef:w,sessionError:n,pageState:i,setPageState:l,agentDisplayName:d,agentImage:m,agentImageShape:g,showAgentName:v,agentSlug:S,branding:b,resolvedSlugRef:C,ensureSession:L,startNewSession:(0,f.useCallback)(async()=>{w.current=null,T.current=null,N.current=null,E.current=!1,D.current=null,t(null),r(null);try{sessionStorage.removeItem(`maxy_session`)}catch{}await L()},[L]),enterChat:P,enterGate:F,resumedRef:E,resumeMessagesRef:D,gateState:O,setGateState:k,grantInfo:A,setGrantInfo:j,gateCacheKeyRef:M}}function g(){let{ensureSession:e,pageState:t,gateState:n,setGateState:r,grantInfo:i,resolvedSlugRef:a}=h();return(0,f.useEffect)(()=>{e()},[e]),t===`loading`?(0,p.jsx)(`div`,{className:`public-loading`,children:`Loading…`}):t===`auth-required`?(0,p.jsx)(m,{gateState:n,setGateState:r,grantInfo:i,resolvedSlugRef:a}):(0,p.jsx)(`div`,{className:`public-shell`,children:(0,p.jsx)(l,{cacheKey:``,variant:`public`})})}(0,d.createRoot)(document.getElementById(`root`)).render((0,p.jsx)(g,{}));
@@ -1 +0,0 @@
1
- import{B as e}from"./useSubAccountSwitcher-C7TtIbR3.js";var t=e(`rotate-ccw`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}]]);export{t};
@@ -1,2 +0,0 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{A as t,B as n,E as r,G as i,J as a,P as o,R as s,Y as c,Z as l,_ as u,b as d,d as f,p,v as m,x as h}from"./useSubAccountSwitcher-C7TtIbR3.js";import{A as g,h as _,t as v}from"./AdminShell-D24evn4t.js";import{t as y}from"./clock-7IMwxJdH.js";import{t as b}from"./wrench-CICORrSc.js";import{r as x}from"./file-download-DbNIjWiK.js";var ee=n(`circle-pause`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`10`,x2:`10`,y1:`15`,y2:`9`,key:`c1nkhi`}],[`line`,{x1:`14`,x2:`14`,y1:`15`,y2:`9`,key:`h65svq`}]]),S=n(`circle-play`,[[`path`,{d:`M9 9.003a1 1 0 0 1 1.517-.859l4.997 2.997a1 1 0 0 1 0 1.718l-4.997 2.997A1 1 0 0 1 9 14.996z`,key:`kmsa83`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),C=n(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),w=c(),T=e(l(),1),E=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function D(e,t){if(e===`*`)return{kind:`any`,value:0,rangeStart:null,rangeEnd:null,step:1};let n=e.match(/^(\*|\d+-\d+)\/(\d+)$/);if(n){let e=Number(n[2]);if(e<1)return null;if(n[1]===`*`)return{kind:`step`,value:0,rangeStart:null,rangeEnd:null,step:e};let[r,i]=n[1].split(`-`).map(Number);return r>t||i>t||r>i?null:{kind:`step`,value:0,rangeStart:r,rangeEnd:i,step:e}}let r=e.match(/^(\d+)-(\d+)$/);if(r){let e=Number(r[1]),n=Number(r[2]);return e>t||n>t||e>n?null:{kind:`step`,value:0,rangeStart:e,rangeEnd:n,step:1}}if(/^\d+$/.test(e)){let n=Number(e);return n>t?null:{kind:`fixed`,value:n,rangeStart:null,rangeEnd:null,step:1}}return null}function O(e){return String(e).padStart(2,`0`)}function k(e){if(e===`*`)return null;let t=e.match(/^(\d+)-(\d+)$/);if(t){let e=Number(t[1]),n=Number(t[2]);return e>7||n>7||e>n?`invalid`:`${E[e%7]} to ${E[n%7]}`}let n=e.split(`,`);return n.length>0&&n.every(e=>/^\d+$/.test(e)&&Number(e)<=7)?n.map(e=>E[Number(e)%7]).join(`, `):`invalid`}function A(e){let t=e.trim().split(/\s+/);if(t.length!==5)return e;let[n,r,i,a,o]=t;if(a!==`*`||i!==`*`&&!/^\d+$/.test(i)||i!==`*`&&(Number(i)<1||Number(i)>31))return e;let s=D(n,59),c=D(r,23);if(!s||!c)return e;let l=k(o);if(l===`invalid`||s.kind===`step`&&s.rangeStart!==null||(s.kind===`any`&&(s={kind:`step`,value:0,rangeStart:null,rangeEnd:null,step:1}),c.kind===`step`&&c.step===1&&c.rangeStart===null&&(c={kind:`any`,value:0,rangeStart:null,rangeEnd:null,step:1}),i!==`*`&&!(s.kind===`fixed`&&c.kind===`fixed`&&o===`*`))||s.kind===`step`&&c.kind===`step`&&c.step>1)return e;let u=l?`, ${l}`:``,d=e=>e.rangeStart+Math.floor((e.rangeEnd-e.rangeStart)/e.step)*e.step;if(s.kind===`step`){let e=s.step===1?`Every minute`:`Every ${s.step} minutes`;return c.kind===`any`?`${e}${u}`:c.kind===`fixed`?`${e}, ${O(c.value)}:00 to ${O(c.value)}:59${u}`:`${e}, ${O(c.rangeStart)}:00 to ${O(d(c))}:00${u}`}if(c.kind===`step`){let e=O(s.value),t=s.value===0?``:` at :${e}`;return c.rangeStart===null?`Every ${c.step} hours${t}${u}`:c.step===1?`Hourly, ${O(c.rangeStart)}:${e} to ${O(c.rangeEnd)}:${e}${u}`:`Every ${c.step} hours, ${O(c.rangeStart)}:${e} to ${O(d(c))}:${e}${u}`}if(c.kind===`any`)return`${s.value===0?`Every hour`:`Every hour at :${O(s.value)}`}${u}`;let f=`${O(c.value)}:${O(s.value)}`;return i===`*`?l?`${l} at ${f}`:`Daily at ${f}`:`Monthly on day ${Number(i)} at ${f}`}var j={timeMode:`at`,minute:0,hour:9,interval:1,window:null,dayMode:`every`,weekdays:[],dayOfMonth:1};function M(e){let t=e.match(/^(\d+)-(\d+)$/);if(t){let e=Number(t[1]),n=Number(t[2]);if(e>7||n>7||e>n)return null;let r=[];for(let t=e;t<=n;t+=1)r.push(t%7);return[...new Set(r)].sort((e,t)=>e-t)}let n=e.split(`,`);return n.every(e=>/^\d+$/.test(e)&&Number(e)<=7)?[...new Set(n.map(e=>Number(e)%7))].sort((e,t)=>e-t):null}function N(e){let t=e.trim().split(/\s+/);if(t.length!==5)return null;let[n,r,i,a,o]=t;if(a!==`*`||i!==`*`&&!/^\d+$/.test(i))return null;let s=D(n,59),c=D(r,23);if(!s||!c||s.kind===`step`&&s.rangeStart!==null)return null;let l=`every`,u=[],d=1;if(i!==`*`){if(o!==`*`)return null;let e=Number(i);if(e<1||e>31||s.kind!==`fixed`||c.kind!==`fixed`)return null;l=`dayOfMonth`,d=e}else if(o!==`*`){let e=M(o);if(e===null)return null;l=`weekdays`,u=e}let f={dayMode:l,weekdays:u,dayOfMonth:d};if(s.kind===`any`||s.kind===`step`){if(c.kind===`step`&&c.step>1)return null;let e=s.kind===`any`?1:s.step,t=c.kind===`any`?null:c.kind===`fixed`?{start:c.value,end:c.value}:{start:c.rangeStart,end:c.rangeEnd};return{...j,...f,timeMode:`everyMinutes`,minute:0,interval:e,window:t}}return c.kind===`fixed`?{...j,...f,timeMode:`at`,minute:s.value,hour:c.value}:c.kind===`any`?{...j,...f,timeMode:`everyHours`,minute:s.value,interval:1,window:null}:{...j,...f,timeMode:`everyHours`,minute:s.value,interval:c.step,window:c.rangeStart===null?null:{start:c.rangeStart,end:c.rangeEnd}}}function P(e){return e.dayMode===`dayOfMonth`?[String(e.dayOfMonth),`*`]:e.dayMode===`weekdays`&&e.weekdays.length>0?[`*`,[...e.weekdays].sort((e,t)=>e-t).join(`,`)]:[`*`,`*`]}function F(e){let[t,n]=P(e);if(e.timeMode===`everyMinutes`){let r=e.window===null?`*`:e.window.start===e.window.end?String(e.window.start):`${e.window.start}-${e.window.end}`;return`*/${e.interval} ${r} ${t} * ${n}`}if(e.timeMode===`everyHours`){let r=e.window===null?e.interval===1?`*`:`*/${e.interval}`:e.interval===1?`${e.window.start}-${e.window.end}`:`${e.window.start}-${e.window.end}/${e.interval}`;return`${e.minute} ${r} ${t} * ${n}`}return`${e.minute} ${e.hour} ${t} * ${n}`}var I=i(),L=[{value:1,label:`Mon`},{value:2,label:`Tue`},{value:3,label:`Wed`},{value:4,label:`Thu`},{value:5,label:`Fri`},{value:6,label:`Sat`},{value:0,label:`Sun`}],R=Array.from({length:24},(e,t)=>t),z=e=>String(e).padStart(2,`0`),B={timeMode:`at`,minute:0,hour:9,interval:1,window:null,dayMode:`every`,weekdays:[],dayOfMonth:1};function te({recurrence:e,onChange:t,disabled:n}){let r=e?N(e):B,[i,a]=(0,T.useState)(r??B),[o]=(0,T.useState)(e!=null&&r==null),[s,c]=(0,T.useState)(e??``);if((0,T.useEffect)(()=>{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`event`,source:`routines`,op:`schedule-editor`,mode:o?`raw`:`builder`}),keepalive:!0}).catch(()=>{})},[o]),o)return(0,I.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,I.jsx)(`span`,{children:`Schedule (advanced)`}),(0,I.jsx)(`input`,{type:`text`,className:`routine-raw-cron`,value:s,disabled:n,onChange:e=>{c(e.target.value),t(e.target.value)},"aria-label":`Cron expression`}),(0,I.jsx)(`span`,{className:`routine-raw-note`,children:`This routine uses an advanced schedule, edited as a raw cron expression.`})]});let l=e=>{a(e),t(F(e))},u=e=>{let t=e!==`at`&&i.dayMode===`dayOfMonth`?`every`:i.dayMode;l({...i,timeMode:e,dayMode:t})},d=e=>{let t=e===`weekdays`&&i.weekdays.length===0?[1]:i.weekdays;l({...i,dayMode:e,weekdays:t})},f=e=>{let[t,n]=e.split(`:`);l({...i,hour:Number(t)||0,minute:Number(n)||0})},p=e=>{let t=i.weekdays.includes(e);if(t&&i.weekdays.length===1)return;let n=t?i.weekdays.filter(t=>t!==e):[...i.weekdays,e];l({...i,weekdays:n})},m=e=>l({...i,window:e?{start:0,end:23}:null}),h=(e,t)=>{let n={...i.window??{start:0,end:23},[e]:Number(t)};n.start>n.end&&(e===`start`?n.end=n.start:n.start=n.end),l({...i,window:n})},g=(e,t,n)=>Math.min(n,Math.max(t,Number(e)||t));return(0,I.jsxs)(`div`,{className:`routine-sched`,children:[(0,I.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,I.jsx)(`span`,{children:`How often`}),(0,I.jsxs)(`select`,{"aria-label":`How often`,value:i.timeMode,disabled:n,onChange:e=>u(e.target.value),children:[(0,I.jsx)(`option`,{value:`at`,children:`At a time of day`}),(0,I.jsx)(`option`,{value:`everyMinutes`,children:`Every few minutes`}),(0,I.jsx)(`option`,{value:`everyHours`,children:`Every few hours`})]})]}),i.timeMode===`at`&&(0,I.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,I.jsx)(`span`,{children:`Time of day`}),(0,I.jsx)(`input`,{type:`time`,"aria-label":`Time of day`,value:`${z(i.hour)}:${z(i.minute)}`,disabled:n,onChange:e=>f(e.target.value)})]}),i.timeMode===`everyMinutes`&&(0,I.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,I.jsx)(`span`,{children:`Minutes between runs`}),(0,I.jsx)(`input`,{type:`number`,min:1,max:59,"aria-label":`Minutes between runs`,value:i.interval,disabled:n,onChange:e=>l({...i,interval:g(e.target.value,1,59)})})]}),i.timeMode===`everyHours`&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,I.jsx)(`span`,{children:`Hours between runs`}),(0,I.jsx)(`input`,{type:`number`,min:1,max:23,"aria-label":`Hours between runs`,value:i.interval,disabled:n,onChange:e=>l({...i,interval:g(e.target.value,1,23)})})]}),(0,I.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,I.jsx)(`span`,{children:`Minute of the hour`}),(0,I.jsx)(`input`,{type:`number`,min:0,max:59,"aria-label":`Minute of the hour`,value:i.minute,disabled:n,onChange:e=>l({...i,minute:g(e.target.value,0,59)})})]})]}),i.timeMode!==`at`&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`label`,{className:`cal-modal-field routine-sched-check`,children:[(0,I.jsx)(`input`,{type:`checkbox`,"aria-label":`Only between certain hours`,checked:i.window!==null,disabled:n,onChange:e=>m(e.target.checked)}),(0,I.jsx)(`span`,{children:`Only between certain hours`})]}),i.window!==null&&(0,I.jsxs)(`div`,{className:`routine-sched-row`,children:[(0,I.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,I.jsx)(`span`,{children:`From hour`}),(0,I.jsx)(`select`,{"aria-label":`From hour`,value:i.window.start,disabled:n,onChange:e=>h(`start`,e.target.value),children:R.map(e=>(0,I.jsxs)(`option`,{value:e,children:[z(e),`:00`]},e))})]}),(0,I.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,I.jsx)(`span`,{children:`To hour`}),(0,I.jsx)(`select`,{"aria-label":`To hour`,value:i.window.end,disabled:n,onChange:e=>h(`end`,e.target.value),children:R.map(e=>(0,I.jsxs)(`option`,{value:e,children:[z(e),`:00`]},e))})]})]})]}),(0,I.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,I.jsx)(`span`,{children:`Which days`}),(0,I.jsxs)(`select`,{"aria-label":`Which days`,value:i.dayMode,disabled:n,onChange:e=>d(e.target.value),children:[(0,I.jsx)(`option`,{value:`every`,children:`Every day`}),(0,I.jsx)(`option`,{value:`weekdays`,children:`Specific days`}),i.timeMode===`at`&&(0,I.jsx)(`option`,{value:`dayOfMonth`,children:`A day of the month`})]})]}),i.dayMode===`weekdays`&&(0,I.jsxs)(`div`,{className:`cal-modal-field`,children:[(0,I.jsx)(`span`,{children:`Days`}),(0,I.jsx)(`div`,{className:`routine-weekdays`,children:L.map(e=>(0,I.jsx)(`button`,{type:`button`,className:`routine-weekday${i.weekdays.includes(e.value)?` routine-weekday-on`:``}`,"aria-pressed":i.weekdays.includes(e.value),disabled:n,onClick:()=>p(e.value),children:e.label},e.value))})]}),i.dayMode===`dayOfMonth`&&(0,I.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,I.jsx)(`span`,{children:`Day of month`}),(0,I.jsx)(`select`,{"aria-label":`Day of month`,value:i.dayOfMonth,disabled:n,onChange:e=>l({...i,dayOfMonth:Number(e.target.value)||1}),children:Array.from({length:31},(e,t)=>t+1).map(e=>(0,I.jsx)(`option`,{value:e,children:e},e))})]})]})}function V(e){let t=e.trim().replace(/[\s\-().]/g,``).replace(/^\+/,``);return/^\d{11,15}$/.test(t)?`+${t.slice(0,2)} ${t.slice(2,6)} ${t.slice(6)}`:e}function ne(e){if(e.name)return`${e.name} · ${e.label}`;let t=e.channel===`whatsapp`?V(e.destination):e.destination;return`${e.label} · ${t}`}var H={scheduled:`live`,due:`live`,suspended:`stood-down`,cancelled:`inert`,completed:`inert`};function U(e){return e==null||!Object.hasOwn(H,e)?`unknown`:H[e]}function W({eventStatus:e}){let t=U(e);return(0,I.jsx)(`span`,{className:`routine-status-dot is-${t}`,"data-state":t,"aria-hidden":`true`})}function G(e){if(!e)return`—`;let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString():e}function re(e){return e?e.split(`
2
- `).filter(e=>e.trim()!==``).reverse():[]}function K({routine:e,adminFetch:n,onClose:i,onSaved:a,onDeleted:o,onViewRuns:s}){let[c,l]=(0,T.useState)(!1),[u,m]=(0,T.useState)(!1),[g,v]=(0,T.useState)(null),[x,w]=(0,T.useState)(e),[E,D]=(0,T.useState)(!1),O=x.agentChannel!=null,k=x.eventStatus===`suspended`,[j,M]=(0,T.useState)(!1),[N,P]=(0,T.useState)(e.agentPrompt??``),[F,L]=(0,T.useState)(e.recurrence),[R,z]=(0,T.useState)(e.agentChannel??``),[B,V]=(0,T.useState)(e.agentDestination??``),[H,U]=(0,T.useState)(null),[K,q]=(0,T.useState)(null),J=O||x.actionPlugin==null,Y=re(x.notes);(0,T.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!u&&i()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[u,i]),(0,T.useEffect)(()=>{if(!c||!J||H!==null)return;let e=!1;return n(`/api/admin/dispatch-destinations`).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return await e.json()}).then(t=>{e||U(t.destinations)}).catch(t=>{e||(U([]),q(t instanceof Error?t.message:`Could not load destinations`))}),()=>{e=!0}},[c,J,H,n]);let X=(H??[]).filter(e=>e.channel===R),Z=R.length>0&&B.length>0,ie=R.length>0&&B.length===0||Z&&N.trim().length===0,Q=(0,T.useCallback)(()=>{let e={},t=R.length>0&&B.length>0;return(O||t)&&N!==(x.agentPrompt??``)&&(e.agentPrompt=N),F!=null&&F!==(x.recurrence??null)&&(e.recurrence=F),t&&(R!==(x.agentChannel??``)||B!==(x.agentDestination??``))?(e.agentChannel=R,e.agentDestination=B):!t&&R===``&&(x.agentChannel??``)!==``&&(e.agentChannel=null,e.agentDestination=null),e},[O,N,F,R,B,x]),ae=(0,T.useCallback)(async()=>{let t=Q();if(Object.keys(t).length===0){l(!1);return}m(!0),v(null);try{let r=await n(`/api/admin/routines/${encodeURIComponent(e.eventId)}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(t)});if(!r.ok){let e=await r.json().catch(()=>({}));throw Error(e.error??`HTTP ${r.status}`)}let i=await r.json();w(i.routine),P(i.routine.agentPrompt??``),L(i.routine.recurrence),z(i.routine.agentChannel??``),V(i.routine.agentDestination??``),a(i.routine),l(!1)}catch(e){v(e instanceof Error?e.message:`Save failed`)}finally{m(!1)}},[n,Q,e.eventId,a]),oe=(0,T.useCallback)(async()=>{if(u)return;if(!j){D(!1),M(!0);return}let t=k?`resume`:`suspend`;m(!0),v(null);try{let r=await n(`/api/admin/routines/${encodeURIComponent(e.eventId)}/${t}`,{method:`POST`});if(!r.ok){let e=await r.json().catch(()=>({}));throw Error(e.error??`HTTP ${r.status}`)}let i=await r.json();w(i.routine),a(i.routine),M(!1)}catch(e){v(e instanceof Error?e.message:`${t} failed`),M(!1)}finally{m(!1)}},[n,u,j,k,e.eventId,a]),se=(0,T.useCallback)(async()=>{if(!u){if(!E){M(!1),D(!0);return}m(!0),v(null);try{let t=await n(`/api/admin/routines/${encodeURIComponent(e.eventId)}`,{method:`DELETE`});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??`HTTP ${t.status}`)}o(e.eventId)}catch(e){v(e instanceof Error?e.message:`Delete failed`),D(!1)}finally{m(!1)}}},[n,u,E,e.eventId,o]);return(0,I.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{u||i()},children:(0,I.jsxs)(`div`,{className:`cal-modal ${!c||O||Z?`cal-modal-wide`:`cal-modal-dispatch`}`,role:`dialog`,"aria-modal":`true`,"aria-label":c?`Edit routine`:`Routine detail`,onClick:e=>e.stopPropagation(),children:[(0,I.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,I.jsxs)(`span`,{className:`cal-modal-kind`,children:[(0,I.jsx)(_,{size:13}),` Routine`]}),(0,I.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:i,"aria-label":`Close`,autoFocus:!0,disabled:u,children:(0,I.jsx)(d,{size:16})})]}),!c&&(0,I.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,I.jsx)(`div`,{className:`cal-modal-title`,children:x.name??`Untitled routine`}),(0,I.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,I.jsx)(y,{size:14}),(0,I.jsx)(`span`,{children:x.recurrence?A(x.recurrence):`One-time`})]}),(0,I.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,I.jsx)(W,{eventStatus:x.eventStatus}),(0,I.jsxs)(`span`,{children:[`Status: `,x.eventStatus??`unknown`]})]}),(0,I.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,I.jsxs)(`span`,{children:[`Next run: `,G(x.nextRun)]})}),(0,I.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,I.jsx)(C,{size:14}),(0,I.jsxs)(`span`,{children:[`Last run: `,G(x.lastTriggered),x.lastDispatchResult?` (${x.lastDispatchResult})`:``]})]}),O?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,I.jsx)(p,{channel:x.agentChannel,size:14}),(0,I.jsxs)(`span`,{children:[f[x.agentChannel]??x.agentChannel,` to `,x.agentDestination??`—`]})]}),(0,I.jsx)(`div`,{className:`cal-modal-row cal-modal-row-top routine-prose`,children:(0,I.jsx)(`span`,{children:x.agentPrompt??`No instruction set.`})})]}):x.actionPlugin?(0,I.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,I.jsx)(b,{size:14}),(0,I.jsxs)(`span`,{children:[x.actionPlugin,`.`,x.actionTool,x.actionArgs?` ${x.actionArgs}`:``]})]}):(0,I.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,I.jsx)(y,{size:14}),(0,I.jsx)(`span`,{children:`Scheduled trigger (no dispatch)`})]}),Y.length===0?(0,I.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,I.jsx)(C,{size:14}),(0,I.jsx)(`span`,{children:`No history recorded.`})]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,I.jsx)(C,{size:14}),(0,I.jsxs)(`span`,{children:[`History (`,Y.length,` `,Y.length===1?`entry`:`entries`,`)`]})]}),(0,I.jsx)(`div`,{className:`routine-history`,children:Y.map((e,t)=>(0,I.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:e},t))})]})]}),c&&(0,I.jsxs)(`div`,{className:`cal-modal-body`,children:[J&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,I.jsx)(`span`,{children:`Send to`}),(0,I.jsxs)(`div`,{className:`cal-modal-field-inline`,children:[(0,I.jsxs)(`select`,{value:R,disabled:u,onChange:e=>{z(e.target.value),V(``)},children:[(0,I.jsx)(`option`,{value:``,children:`None (no dispatch)`}),(0,I.jsx)(`option`,{value:`whatsapp`,children:`WhatsApp`}),(0,I.jsx)(`option`,{value:`telegram`,children:`Telegram`})]}),R!==``&&(0,I.jsx)(p,{channel:R,size:16})]})]}),R!==``&&(0,I.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,I.jsx)(`span`,{children:`Destination`}),(0,I.jsxs)(`select`,{value:B,disabled:u||H===null,onChange:e=>V(e.target.value),children:[(0,I.jsx)(`option`,{value:``,children:H===null?`Loading destinations`:X.length===0?`No registered destinations`:`Choose a destination`}),B!==``&&!X.some(e=>e.destination===B)&&(0,I.jsxs)(`option`,{value:B,children:[B,` (not in the current list)`]}),X.map(e=>(0,I.jsx)(`option`,{value:e.destination,children:ne(e)},e.destination))]})]}),K&&(0,I.jsxs)(`div`,{className:`cal-modal-error`,children:[`Could not load destinations: `,K]})]}),(O||Z)&&(0,I.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,I.jsx)(`span`,{children:`Instruction`}),(0,I.jsx)(`textarea`,{className:`cal-modal-textarea`,value:N,onChange:e=>P(e.target.value),disabled:u,rows:16,placeholder:`What should the agent do when this routine fires?`})]}),(0,I.jsx)(te,{recurrence:x.recurrence,onChange:L,disabled:u})]}),g&&(0,I.jsx)(`div`,{className:`cal-modal-error`,children:g}),(0,I.jsxs)(`div`,{className:`cal-modal-actions`,children:[!c&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>{D(!1),M(!1),l(!0)},disabled:u,children:[(0,I.jsx)(r,{size:14}),` Edit`]}),(0,I.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>s(x),disabled:u,children:[(0,I.jsx)(C,{size:14}),` Runs`]}),(0,I.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:oe,disabled:u,children:[u&&j?(0,I.jsx)(t,{size:14,className:`spin`}):k?(0,I.jsx)(S,{size:14}):(0,I.jsx)(ee,{size:14}),j?k?`Confirm resume`:`Confirm suspend`:k?`Resume`:`Suspend`]}),j&&(0,I.jsx)(`span`,{className:`cal-modal-confirm-text`,children:k?`This routine will run at its next scheduled time. It will not run for the times it missed.`:`This routine stops running until you resume it. Nothing is deleted.`}),(0,I.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:se,disabled:u,children:[u&&E?(0,I.jsx)(t,{size:14,className:`spin`}):(0,I.jsx)(h,{size:14}),E?`Confirm delete`:`Delete`]})]}),c&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-primary`,onClick:ae,disabled:u||ie,children:[u?(0,I.jsx)(t,{size:14,className:`spin`}):null,` Save`]}),(0,I.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>{l(!1),v(null)},disabled:u,children:`Cancel`})]})]})]})})}function q(e){if(!e)return`—`;let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString():e}function J(e){return e===null?`—`:e<1e3?`${e} ms`:`${(e/1e3).toFixed(1)} s`}function Y({run:e,routineName:t,onClose:n}){return(0,T.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,I.jsx)(`div`,{className:`cal-modal-overlay`,onClick:n,children:(0,I.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":`Run detail`,onClick:e=>e.stopPropagation(),children:[(0,I.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,I.jsxs)(`span`,{className:`cal-modal-kind`,children:[(0,I.jsx)(C,{size:13}),` Run`]}),(0,I.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:n,"aria-label":`Close`,autoFocus:!0,children:(0,I.jsx)(d,{size:16})})]}),(0,I.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,I.jsx)(`div`,{className:`cal-modal-title`,children:t??`Untitled routine`}),(0,I.jsx)(`div`,{className:`cal-modal-row`,children:(0,I.jsx)(`span`,{children:e.status})}),(0,I.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,I.jsxs)(`span`,{children:[`Due: `,q(e.scheduledFor)]})}),(0,I.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,I.jsxs)(`span`,{children:[`Started: `,q(e.startedAt)]})}),(0,I.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,I.jsxs)(`span`,{children:[`Dispatch ended: `,q(e.endedAt),` (`,J(e.ranMs),`)`]})}),(0,I.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,I.jsxs)(`span`,{children:[`Output seen: `,q(e.finishedAt)]})}),(0,I.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,I.jsxs)(`span`,{children:[`Sent to: `,e.target,` · `,e.mode,` · `,e.kind]})}),(0,I.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,I.jsxs)(`span`,{children:[`Transport: `,e.dispatchResult??`—`,e.httpStatus===null?``:` (HTTP ${e.httpStatus})`]})}),e.error&&(0,I.jsx)(`div`,{className:`cal-modal-row cal-modal-row-top routine-prose`,children:(0,I.jsx)(`span`,{children:e.error})}),(0,I.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,I.jsxs)(`span`,{children:[`Conversation: `,e.sessionKey??`—`,e.transcriptOffset===null?``:` at byte ${e.transcriptOffset}`]})}),!e.bounded&&(0,I.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,I.jsx)(`span`,{children:`This run shares its conversation with other traffic, so what it produced cannot be separated out. Its status stays at whatever the dispatch reported.`})}),(0,I.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,I.jsxs)(`span`,{children:[`Run `,e.runId]})})]})]})})}var X=500;function Z(e){if(!e)return`—`;let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString():e}function ie(e){return e===null?`—`:e<1e3?`${e} ms`:`${(e/1e3).toFixed(1)} s`}var Q={channel:`a channel`,destination:`a destination`,prompt:`an instruction`};function ae(e){if(e===`no-dispatch-configured`)return`This routine has no dispatch set up, so there was nothing to do.`;if(e===`no-action-plugin`)return`The tool action names no plugin, so nothing ran.`;if(e===`no-action-tool`)return`The tool action names no tool, so nothing ran.`;let t=e.startsWith(`no-`)?e.slice(3).split(`+`):[];if(t.length>0&&t.every(e=>e in Q)){let e=t.map(e=>Q[e]);return`This routine has no ${(e.length===1?e[0]:`${e.slice(0,-1).join(`, `)} and ${e[e.length-1]}`).replace(/^an? /,``)} set, so nothing was sent.`}return e}function oe(e){return e.status===`no-destination`?e.error?ae(e.error):`Nothing was dispatched, and no reason was recorded.`:e.status===`failed`?e.error??e.dispatchResult??`The dispatch failed.`:e.status===`open`?`Opened and never closed. The dispatch did not report back.`:null}function se({routine:e,adminFetch:n,cacheKey:r,onBack:i}){let[a,c]=(0,T.useState)([]),[l,u]=(0,T.useState)(!0),[d,f]=(0,T.useState)(null),[p,m]=(0,T.useState)(null);(0,T.useEffect)(()=>{let t=!1;return u(!0),f(null),n(`/api/admin/routines/${encodeURIComponent(e.eventId)}/runs?limit=${X}`).then(async e=>{if(t)return;if(!e.ok)throw Error(`HTTP ${e.status}`);let n=await e.json();c(Array.isArray(n.runs)?n.runs:[])}).catch(e=>{t||(f(e instanceof Error?e.message:`Failed to load`),c([]))}).finally(()=>{t||u(!1)}),()=>{t=!0}},[n,e.eventId]);let h=(0,T.useCallback)(()=>{x(r,e.eventId)},[r,e.eventId]);return(0,I.jsxs)(`div`,{className:`cal-page`,children:[(0,I.jsx)(`header`,{className:`cal-header`,children:(0,I.jsxs)(`div`,{className:`cal-nav`,children:[(0,I.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:i,children:[(0,I.jsx)(s,{size:14}),` Routines`]}),(0,I.jsxs)(`span`,{className:`cal-range-label`,children:[(0,I.jsx)(C,{size:16}),` `,e.name??`Untitled routine`]}),l&&(0,I.jsx)(t,{size:16,className:`spin`}),a.length>0&&(0,I.jsx)(`div`,{className:`routine-bulk-actions`,children:(0,I.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:h,children:[(0,I.jsx)(o,{size:14}),` Download all runs`]})})]})}),(0,I.jsxs)(`div`,{className:`cal-body`,children:[d&&(0,I.jsxs)(`div`,{className:`cal-error`,children:[`Could not load runs: `,d]}),!d&&!l&&a.length===0&&(0,I.jsxs)(`div`,{className:`cal-empty`,"data-testid":`runs-empty`,children:[(0,I.jsx)(`p`,{children:`Nothing to show for this routine.`}),(0,I.jsx)(`p`,{children:`That means one of three things, and this page cannot tell them apart: it has never run, it ran but no record was written, or every run it did have is older than the 30 days records are kept for.`}),(0,I.jsxs)(`p`,{children:[`For a repeating routine, the server log settles the middle one: a`,(0,I.jsx)(`code`,{children:` fires-without-records `}),` count above zero names a routine that fired and left no record. It does not distinguish the other two, and it does not cover a one-time routine.`]})]}),a.length>=X&&(0,I.jsxs)(`div`,{className:`cal-modal-confirm-text`,"data-testid":`runs-capped`,children:[`Showing the most recent `,X,` runs. There may be more; the download has everything still on record.`]}),(0,I.jsx)(`div`,{className:`routine-list`,children:a.map(e=>{let t=oe(e);return(0,I.jsxs)(`button`,{type:`button`,className:`routine-card`,"data-testid":`run-row-${e.runId}`,onClick:()=>m(e),children:[(0,I.jsx)(`span`,{className:`routine-card-title`,children:e.status}),(0,I.jsx)(`span`,{className:`routine-card-sched`,children:ie(e.ranMs)}),(0,I.jsx)(`span`,{className:`routine-card-target`,children:e.target}),(0,I.jsxs)(`span`,{className:`routine-card-meta`,children:[`Due `,Z(e.scheduledFor)]}),t&&(0,I.jsx)(`span`,{className:`routine-card-meta run-card-detail`,children:t})]},e.runId)})})]}),p&&(0,I.jsx)(Y,{run:p,routineName:e.name,onClose:()=>m(null)})]})}var $=`maxy-admin-session-key`;function ce(e){return e?A(e):`One-time`}function le(e){if(!e)return`—`;let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString():e}function ue(){let[e,t]=(0,T.useState)(null),[n,r]=(0,T.useState)(!1),[i,a]=(0,T.useState)(void 0),[o,s]=(0,T.useState)(null),[c,l]=(0,T.useState)(void 0),[d,f]=(0,T.useState)(null),[p,h]=(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&&s(e.sessionId??null),h(e.role??null),l(e.userName===void 0?null:e.userName),f(e.avatar??null)}catch{}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]);let _=(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 g();if(e){try{sessionStorage.removeItem($)}catch{}window.location.href=`/`}return e}finally{b(!1)}},[]);return n?e?(0,I.jsx)(m,{cacheKey:e,surface:`routines`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=routines`);try{sessionStorage.removeItem($)}catch{}window.location.href=`/`},children:(0,I.jsx)(v,{cacheKey:e,businessName:i,sessionId:o,onLogout:_,onDisconnect:x,disconnecting:y,userName:c,userAvatar:d,role:p,children:(0,I.jsx)(de,{cacheKey:e})})}):(0,I.jsx)(`div`,{className:`cal-page`,children:(0,I.jsxs)(`div`,{className:`cal-empty`,children:[(0,I.jsx)(`p`,{children:`You are not signed in.`}),(0,I.jsxs)(`p`,{children:[`Open the `,(0,I.jsx)(`a`,{href:`/`,className:`cal-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,I.jsx)(u,{surface:`gate`})}function de({cacheKey:e}){let{adminFetch:n,cacheKey:r,sessionRefetchNonce:i}=a({initialCacheKey:e,surface:`routines`}),[o,s]=(0,T.useState)([]),[c,l]=(0,T.useState)(!1),[d,m]=(0,T.useState)(!1),[h,g]=(0,T.useState)(null),[v,x]=(0,T.useState)(null),[C,w]=(0,T.useState)(null),E=(0,T.useCallback)(()=>{let e=!1;return l(!0),g(null),n(`/api/admin/routines`).then(async t=>{if(e)return;if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();s(Array.isArray(n.routines)?n.routines:[])}).catch(t=>{e||(g(t instanceof Error?t.message:`Failed to load`),s([]))}).finally(()=>{e||(l(!1),m(!0))}),()=>{e=!0}},[n]);(0,T.useEffect)(()=>E(),[E,i]);let D=(0,T.useCallback)(e=>{s(t=>t.map(t=>t.eventId===e.eventId?e:t)),x(e)},[]),O=(0,T.useCallback)(e=>{s(t=>t.filter(t=>t.eventId!==e)),x(null)},[]),[k,A]=(0,T.useState)(!1),[j,M]=(0,T.useState)(null),N=o.filter(e=>e.eventStatus===`scheduled`).length,P=o.filter(e=>e.suspendedInBulk).length,F=(0,T.useCallback)(async e=>{A(!0),M(null);try{let t=await n(`/api/admin/routines/${e}`,{method:`POST`});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??`HTTP ${t.status}`)}let r=await t.json(),i=r.refused?.length??0;M(e===`suspend-all`?`Suspended ${r.suspended??0}. Nothing runs on its own until you resume it.`:`Resumed ${r.restored??0}${i>0?`. ${i} could not be resumed and stayed suspended`:``}. Routines you suspended one at a time are still suspended.`),E()}catch(e){M(e instanceof Error?e.message:`Failed`)}finally{A(!1)}},[n,E]);return d?C?(0,I.jsx)(se,{routine:C,adminFetch:n,cacheKey:r,onBack:()=>w(null)}):(0,I.jsxs)(`div`,{className:`cal-page`,children:[(0,I.jsx)(`header`,{className:`cal-header`,children:(0,I.jsxs)(`div`,{className:`cal-nav`,children:[(0,I.jsxs)(`span`,{className:`cal-range-label`,children:[(0,I.jsx)(_,{size:16}),` Routines`]}),c&&(0,I.jsx)(t,{size:16,className:`spin`}),(0,I.jsxs)(`div`,{className:`routine-bulk-actions`,children:[(0,I.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>F(`suspend-all`),disabled:k||N===0,children:[(0,I.jsx)(ee,{size:14}),` Suspend all (`,N,`)`]}),(0,I.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>F(`resume-all`),disabled:k||P===0,children:[(0,I.jsx)(S,{size:14}),` Resume all (`,P,`)`]})]})]})}),(0,I.jsxs)(`div`,{className:`cal-body`,children:[j&&(0,I.jsx)(`div`,{className:`cal-modal-confirm-text`,children:j}),h&&(0,I.jsxs)(`div`,{className:`cal-error`,children:[`Could not load routines: `,h]}),!h&&!c&&o.length===0&&(0,I.jsx)(`div`,{className:`cal-empty`,children:(0,I.jsx)(`p`,{children:`No routines yet.`})}),(0,I.jsx)(`div`,{className:`routine-list`,children:o.map(e=>(0,I.jsxs)(`button`,{type:`button`,className:`admin-card admin-card--padded routine-card`,onClick:()=>x(e),children:[(0,I.jsx)(`span`,{className:`admin-card-title routine-card-title`,children:e.name??`Untitled routine`}),e.routineDescription&&(0,I.jsx)(`span`,{className:`routine-card-desc`,children:e.routineDescription}),(0,I.jsxs)(`span`,{className:`routine-card-sched`,children:[(0,I.jsx)(y,{size:13}),` `,ce(e.recurrence)]}),(0,I.jsx)(`span`,{className:`routine-card-target`,children:e.agentChannel?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(p,{channel:e.agentChannel,size:13}),` `,f[e.agentChannel]??e.agentChannel,` to `,e.agentDestination??`—`]}):e.actionPlugin?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(b,{size:13}),` `,e.actionPlugin,`.`,e.actionTool]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(y,{size:13}),` Scheduled trigger`]})}),(0,I.jsxs)(`span`,{className:`routine-card-meta`,children:[(0,I.jsx)(W,{eventStatus:e.eventStatus}),`Next: `,le(e.nextRun),` · `,e.eventStatus??`unknown`]})]},e.eventId))})]}),v&&(0,I.jsx)(K,{routine:v,adminFetch:n,onClose:()=>x(null),onSaved:D,onDeleted:O,onViewRuns:e=>{x(null),w(e)}})]}):(0,I.jsx)(u,{surface:`gate`})}(0,w.createRoot)(document.getElementById(`root`)).render((0,I.jsx)(ue,{}));
@@ -1 +0,0 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{A as t,G as n,J as r,M as i,Y as a,Z as o,_ as s,b as c,v as l,x as u}from"./useSubAccountSwitcher-C7TtIbR3.js";import{A as d,g as f,t as p}from"./AdminShell-D24evn4t.js";import{t as m}from"./file-text-BA9p7TLU.js";var h=a(),g=e(o(),1),_=n();function v({summary:e,adminFetch:n,onClose:r,onDeleted:a}){let[o,s]=(0,g.useState)(null),[l,d]=(0,g.useState)(!0),[p,h]=(0,g.useState)(null),[v,y]=(0,g.useState)(!1),[b,x]=(0,g.useState)(!1);(0,g.useEffect)(()=>{let t=!1;return d(!0),h(null),n(`/api/admin/skills/${encodeURIComponent(e.plugin)}/${encodeURIComponent(e.skill)}`).then(async e=>{if(!t){if(!e.ok)throw Error(`HTTP ${e.status}`);s((await e.json()).skill)}}).catch(e=>{t||h(e instanceof Error?e.message:`Failed to load`)}).finally(()=>{t||d(!1)}),()=>{t=!0}},[n,e.plugin,e.skill]),(0,g.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!b&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[b,r]);let S=(0,g.useCallback)(async()=>{x(!0),h(null);try{let t=await n(`/api/admin/skills/${encodeURIComponent(e.plugin)}/${encodeURIComponent(e.skill)}`,{method:`DELETE`,headers:{"content-type":`application/json`}});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??`HTTP ${t.status}`)}a(e)}catch(e){h(e instanceof Error?e.message:`Delete failed`),x(!1),y(!1)}},[n,e,a]);return(0,_.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{b||r()},children:(0,_.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":`Skill detail`,onClick:e=>e.stopPropagation(),children:[(0,_.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,_.jsxs)(`span`,{className:`cal-modal-kind`,children:[(0,_.jsx)(f,{size:13}),` Skill`]}),(0,_.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:r,"aria-label":`Close`,autoFocus:!0,disabled:b,children:(0,_.jsx)(c,{size:16})})]}),(0,_.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,_.jsx)(`div`,{className:`cal-modal-title`,children:e.skill}),(0,_.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,_.jsx)(m,{size:14}),(0,_.jsx)(`span`,{children:e.plugin})]}),l&&(0,_.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,_.jsx)(t,{size:14,className:`spin`}),(0,_.jsx)(`span`,{children:`Loading…`})]}),o&&(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,_.jsx)(`span`,{children:o.frontmatter.description||`No description.`})}),o.frontmatter.publicEmbed&&(0,_.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,_.jsx)(i,{size:14}),(0,_.jsx)(`span`,{children:`Public embed`})]}),(0,_.jsx)(`pre`,{className:`skill-body`,children:o.body.trim()||`No body content.`}),o.references.length>0&&(0,_.jsxs)(`div`,{className:`skill-refs`,children:[(0,_.jsx)(`span`,{className:`skill-refs-label`,children:`References`}),o.references.map(e=>(0,_.jsxs)(`span`,{className:`skill-ref`,children:[(0,_.jsx)(m,{size:13}),` `,e]},e))]})]})]}),p&&(0,_.jsx)(`div`,{className:`cal-modal-error`,children:p}),(0,_.jsxs)(`div`,{className:`cal-modal-actions`,children:[!v&&(0,_.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:()=>y(!0),disabled:b||l,children:[(0,_.jsx)(u,{size:14}),` Delete`]}),v&&(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Delete this skill?`}),(0,_.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:S,disabled:b,children:[b?(0,_.jsx)(t,{size:14,className:`spin`}):(0,_.jsx)(u,{size:14}),` Delete`]}),(0,_.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>y(!1),disabled:b,children:`Cancel`})]})]})]})})}var y=`maxy-admin-session-key`;function b(){let[e,t]=(0,g.useState)(null),[n,r]=(0,g.useState)(!1),[i,a]=(0,g.useState)(void 0),[o,c]=(0,g.useState)(null),[u,f]=(0,g.useState)(void 0),[m,h]=(0,g.useState)(null),[v,b]=(0,g.useState)(null);(0,g.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(y)}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(y)}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),b(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 S=(0,g.useCallback)(()=>{try{sessionStorage.removeItem(y)}catch{}window.location.href=`/`},[]),[C,w]=(0,g.useState)(!1),T=(0,g.useCallback)(async()=>{w(!0);try{let e=await d();if(e){try{sessionStorage.removeItem(y)}catch{}window.location.href=`/`}return e}finally{w(!1)}},[]);return n?e?(0,_.jsx)(l,{cacheKey:e,surface:`skills`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=skills`);try{sessionStorage.removeItem(y)}catch{}window.location.href=`/`},children:(0,_.jsx)(p,{cacheKey:e,businessName:i,sessionId:o,onLogout:S,onDisconnect:T,disconnecting:C,userName:u,userAvatar:m,role:v,children:(0,_.jsx)(x,{cacheKey:e})})}):(0,_.jsx)(`div`,{className:`cal-page`,children:(0,_.jsxs)(`div`,{className:`cal-empty`,children:[(0,_.jsx)(`p`,{children:`You are not signed in.`}),(0,_.jsxs)(`p`,{children:[`Open the `,(0,_.jsx)(`a`,{href:`/`,className:`cal-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,_.jsx)(s,{surface:`gate`})}function x({cacheKey:e}){let{adminFetch:n,sessionRefetchNonce:i}=r({initialCacheKey:e,surface:`skills`}),[a,o]=(0,g.useState)([]),[c,l]=(0,g.useState)(!1),[u,d]=(0,g.useState)(!1),[p,h]=(0,g.useState)(null),[y,b]=(0,g.useState)(null),x=(0,g.useCallback)(()=>{let e=!1;return l(!0),h(null),n(`/api/admin/skills`).then(async t=>{if(e)return;if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();o(Array.isArray(n.skills)?n.skills:[])}).catch(t=>{e||(h(t instanceof Error?t.message:`Failed to load`),o([]))}).finally(()=>{e||(l(!1),d(!0))}),()=>{e=!0}},[n]);(0,g.useEffect)(()=>x(),[x,i]);let S=(0,g.useCallback)(e=>{o(t=>t.filter(t=>!(t.plugin===e.plugin&&t.skill===e.skill))),b(null),x()},[x]);return u?(0,_.jsxs)(`div`,{className:`cal-page`,children:[(0,_.jsx)(`header`,{className:`cal-header`,children:(0,_.jsxs)(`div`,{className:`cal-nav`,children:[(0,_.jsxs)(`span`,{className:`cal-range-label`,children:[(0,_.jsx)(f,{size:16}),` Skills`]}),c&&(0,_.jsx)(t,{size:16,className:`spin`})]})}),(0,_.jsxs)(`div`,{className:`cal-body`,children:[p&&(0,_.jsxs)(`div`,{className:`cal-error`,children:[`Could not load skills: `,p]}),!p&&!c&&a.length===0&&(0,_.jsx)(`div`,{className:`cal-empty`,children:(0,_.jsx)(`p`,{children:`No skills yet. Ask in chat to create one.`})}),a.length>0&&(0,_.jsx)(`div`,{className:`routine-list`,children:a.map(e=>(0,_.jsxs)(`button`,{type:`button`,className:`admin-card admin-card--padded routine-card`,onClick:()=>b(e),children:[(0,_.jsx)(`span`,{className:`admin-card-title routine-card-title`,children:e.skill}),(0,_.jsxs)(`span`,{className:`routine-card-sched`,children:[(0,_.jsx)(m,{size:13}),` `,e.plugin]}),(0,_.jsx)(`span`,{className:`skill-card-desc`,children:e.description||`No description.`}),(0,_.jsx)(`span`,{className:`routine-card-meta`,children:e.refCount===0?`No references`:`${e.refCount} reference${e.refCount===1?``:`s`}`})]},`${e.plugin}/${e.skill}`))})]}),y&&(0,_.jsx)(v,{summary:y,adminFetch:n,onClose:()=>b(null),onDeleted:S})]}):(0,_.jsx)(s,{surface:`gate`})}(0,h.createRoot)(document.getElementById(`root`)).render((0,_.jsx)(b,{}));
@@ -1,3 +0,0 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{E as t,G as n,I as r,J as i,S as a,Y as o,Z as s,_ as c,b as l,i as u,v as d,x as f}from"./useSubAccountSwitcher-C7TtIbR3.js";import{A as p,o as ee,p as m,r as h,t as g,y as _}from"./AdminShell-D24evn4t.js";import{t as v}from"./play-huZpq9ra.js";import{t as y}from"./rotate-ccw-g7l4ZSR3.js";var b=o(),x=e(s(),1);function te(e=3e4){let[t,n]=(0,x.useState)(()=>Date.now());return(0,x.useEffect)(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}function ne(e,t){let n=new Map,r=(e,t,r)=>{let i=n.get(e)??{openCount:0,totalSeconds:0};i.totalSeconds+=t,r&&(i.openCount+=1),n.set(e,i)};for(let t of e)t.clientName&&r(t.clientName,t.secondsLogged,!0);for(let e of t)e.clientName&&r(e.clientName,e.secondsLogged,!1);let i=[...n.entries()].map(([e,t])=>({name:e,openCount:t.openCount,totalSeconds:t.totalSeconds}));return i.sort((e,t)=>t.openCount-e.openCount||e.name.localeCompare(t.name)),S(e,i),i}function S(e,t){let n=t.reduce((e,t)=>e+t.openCount,0),r=e.filter(e=>!e.clientName).length,i=n+r===e.length;return i||console.warn(`[tasks-clients] reconcile-mismatch assigned=${n} unassigned=${r} openTotal=${e.length}`),i}var C=`__unassigned__`;function w(e,t){return e===`__unassigned__`?`Unassigned`:t||e.slice(0,8)}function T(e){return e===null||e===``?C:e}function re(e,t){let n=new Map,r=(e,t)=>{let r=T(e.assigneeUserId),i=n.get(r)??{name:null,openCount:0,totalCount:0};i.name===null&&e.assigneeName&&(i.name=e.assigneeName),i.totalCount+=1,t&&(i.openCount+=1),n.set(r,i)};for(let t of e)r(t,!0);for(let e of t)r(e,!1);let i=[...n.entries()].map(([e,t])=>({userId:e,label:w(e,t.name),openCount:t.openCount,totalCount:t.totalCount}));return i.sort((e,t)=>t.openCount-e.openCount||e.label.localeCompare(t.label)),i}function E(e,t){return t===null?!0:T(e.assigneeUserId)===t}var D=n();function O(e){let t=e.name??e.userId.slice(0,8);return e.kind===`owner`?`${t} (owner)`:t}var k=`maxy-admin-session-key`;function ie(e){let t=[];return e.clientName&&t.push(e.clientName),e.propertyAddress&&t.push(e.propertyAddress),e.fee!=null&&t.push(`£${e.fee}`),t.join(` · `)}function A(e){if(!e)return``;let t=Date.parse(e);if(!Number.isFinite(t))return``;let n=new Date(t);return`${n.getUTCDate()} ${[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`][n.getUTCMonth()]} ${n.getUTCFullYear()}`}function j(e){return e.assigneeName?e.assigneeName:e.assigneeUserId?e.assigneeUserId.slice(0,8):`Unassigned`}function M(e,t){return[t,A(e.createdAt),j(e)].filter(Boolean).join(` · `)}function ae(e,t){if(e.running&&e.runningStartedAt){let n=Date.parse(e.runningStartedAt);if(Number.isFinite(n))return e.secondsLogged+Math.max(0,(t-n)/1e3)}return e.secondsLogged}function oe(e){let t=[`Task: ${e.title}\nTask id: ${e.taskId}`],n=e.description.trim();n.length>0&&t.push(n);let r=e.notes.trim();return r.length>0&&t.push(`Notes:\n${r}`),t.join(`
2
-
3
- `).slice(0,2e3)}function se({clients:e,onSelect:t}){return(0,D.jsxs)(`section`,{className:`admin-card tasks-card`,children:[(0,D.jsxs)(`div`,{className:`tasks-card-head`,children:[(0,D.jsx)(`span`,{className:`tasks-card-title`,children:`Clients`}),(0,D.jsxs)(`span`,{className:`tasks-card-count`,children:[e.length,` total`]})]}),e.length===0&&(0,D.jsx)(`div`,{className:`tasks-empty`,children:`No clients yet.`}),e.map(e=>(0,D.jsx)(`button`,{className:`tasks-row tasks-client-row`,onClick:()=>t(e.name),children:(0,D.jsxs)(`div`,{className:`tasks-row-main`,children:[(0,D.jsx)(`div`,{className:`tasks-row-name`,children:e.name}),(0,D.jsxs)(`div`,{className:`tasks-row-sub`,children:[e.openCount,` open · `,u(e.totalSeconds),` logged`]})]})},e.name))]})}function ce({task:e,roster:t,busy:n,onAssign:r,onClose:i}){return(0,x.useEffect)(()=>{let e=e=>{e.key===`Escape`&&i()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i]),(0,D.jsx)(`div`,{className:`tasks-detail-backdrop`,onClick:i,children:(0,D.jsxs)(`div`,{className:`tasks-detail`,role:`dialog`,"aria-modal":`true`,"aria-label":`Task detail`,onClick:e=>e.stopPropagation(),children:[(0,D.jsxs)(`div`,{className:`tasks-detail-head`,children:[(0,D.jsx)(`h2`,{className:`tasks-detail-title`,children:e?e.name:`Task no longer available`}),(0,D.jsx)(`button`,{className:`tasks-detail-close`,"aria-label":`Close`,onClick:i,children:(0,D.jsx)(l,{size:16})})]}),e===null?(0,D.jsx)(`p`,{className:`tasks-detail-gone`,children:`This task is no longer in the list. It may have been completed, cancelled or removed. Close this and reload to see the current list.`}):(0,D.jsxs)(`dl`,{className:`tasks-detail-fields`,children:[(0,D.jsx)(`dt`,{children:`Status`}),(0,D.jsx)(`dd`,{children:e.status}),(0,D.jsx)(`dt`,{children:`Logged`}),(0,D.jsx)(`dd`,{children:u(e.secondsLogged)}),(0,D.jsx)(`dt`,{children:`Created`}),(0,D.jsx)(`dd`,{children:A(e.createdAt)||`Not recorded`}),(0,D.jsx)(`dt`,{children:`Assignee`}),(0,D.jsx)(`dd`,{children:e.taskId===null?j(e):(0,D.jsxs)(`select`,{className:`tasks-assign-select`,"aria-label":`Assignee`,disabled:n,value:e.assigneeUserId??``,onChange:t=>r(e.taskId,t.target.value===``?null:t.target.value),children:[(0,D.jsx)(`option`,{value:``,children:`Unassigned`}),e.assigneeUserId&&!t.some(t=>t.userId===e.assigneeUserId)&&(0,D.jsxs)(`option`,{value:e.assigneeUserId,children:[j(e),` (not in roster)`]}),t.map(e=>(0,D.jsx)(`option`,{value:e.userId,children:O(e)},e.userId))]})}),e.clientName&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`dt`,{children:`Client`}),(0,D.jsx)(`dd`,{children:e.clientName})]}),e.propertyAddress&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`dt`,{children:`Property`}),(0,D.jsx)(`dd`,{children:e.propertyAddress})]}),e.fee!=null&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`dt`,{children:`Fee`}),(0,D.jsxs)(`dd`,{children:[`£`,e.fee]})]})]})]})})}function N({adminFetch:e}){let[n,i]=(0,x.useState)({open:[],completed:[]}),[o,s]=(0,x.useState)(!1),[d,p]=(0,x.useState)(!1),g=(0,x.useRef)(!1),b=(0,x.useRef)(``),S=te(1e3),[C,w]=(0,x.useState)(`open`),[T,O]=(0,x.useState)(null),[k,A]=(0,x.useState)(null),[j,N]=(0,x.useState)(null),[P,F]=(0,x.useState)(``),[I,L]=(0,x.useState)(null),[le,R]=(0,x.useState)(null),[z,B]=(0,x.useState)(null),V=(0,x.useRef)(new Map),H=(0,x.useRef)(new Set),[ue,de]=(0,x.useState)(new Set),U=(0,x.useMemo)(()=>{if(I!==null)return[...n.open,...n.completed].find(e=>e.rowKey===I)??null},[n,I]),W=(0,x.useMemo)(()=>z===null?null:[...n.open,...n.completed].find(e=>e.rowKey===z)??null,[n,z]);(0,x.useEffect)(()=>{I!==null&&U===null&&console.error(`[tasks-ui] op=detail-failed rowKey=${I} reason=not-in-list`)},[I,U]);let G=(0,x.useMemo)(()=>ne(n.open,n.completed),[n]),K=(0,x.useMemo)(()=>T===null?{open:n.open,completed:n.completed}:{open:n.open.filter(e=>e.clientName===T),completed:n.completed.filter(e=>e.clientName===T)},[n,T]),q=(0,x.useMemo)(()=>re(K.open,K.completed),[K]),fe=(0,x.useCallback)(e=>{O(e),w(`open`)},[]);(0,x.useEffect)(()=>{T&&!G.some(e=>e.name===T)&&O(null)},[G,T]),(0,x.useEffect)(()=>{k&&!q.some(e=>e.userId===k)&&A(null)},[q,k]),(0,x.useEffect)(()=>{R(null),B(null)},[C,T,k]);let J=n.open.filter(e=>e.running||(T===null||e.clientName===T)&&E(e,k)),Y=(T?n.completed.filter(e=>e.clientName===T):n.completed).filter(e=>E(e,k)),[pe,me]=(0,x.useState)([]),X=(0,x.useCallback)(async()=>{let t=await e(`/api/admin/tasks-list`);t.ok&&i(await t.json()),s(!0)},[e]);(0,x.useEffect)(()=>{X()},[X]),(0,x.useEffect)(()=>{(async()=>{let t=await e(`/api/admin/admin-users-list`);if(t.ok){let e=await t.json();e.ok&&Array.isArray(e.users)&&me(e.users)}})()},[e]);let Z=(0,x.useCallback)(async(t,n,r)=>{if(g.current)return!1;g.current=!0,p(!0);try{return await e(t,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({taskId:n,...r})}),await X(),!0}finally{g.current=!1,p(!1)}},[e,X]),he=(0,x.useCallback)(async e=>{await Z(`/api/admin/task-complete`,e)},[Z]),ge=(0,x.useCallback)(async e=>{await Z(`/api/admin/task-delete`,e,{confirmed:!0})},[Z]),_e=(0,x.useCallback)((e,t)=>{let n=String(Math.round(e.secondsLogged/60));b.current=n,N(t),F(n)},[]),Q=(0,x.useCallback)(()=>{N(null),F(``)},[]),ve=(0,x.useCallback)(async e=>{let t=P.trim(),n=Number(t);if(!(t===``||!Number.isInteger(n)||n<0)){if(t===b.current){Q();return}N(null),F(``),await Z(`/api/admin/task-time-adjust`,e,{newSeconds:n*60})}},[P,Z,Q]),ye=(0,x.useCallback)(e=>{Z(`/api/admin/task-time-adjust`,e,{newSeconds:0})},[Z]),be=(0,x.useCallback)((e,t)=>{Z(`/api/admin/task-assign`,e,{assigneeUserId:t})},[Z]),xe=(0,x.useCallback)(async t=>{if(!H.current.has(t)){H.current.add(t),de(new Set(H.current));try{let n=await e(`/api/admin/task-session-open`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({taskId:t})});if(!n.ok){console.error(`[admin-ui] task-session op=open-failed taskId=${t} status=${n.status}`);return}let{sessionId:r,title:i,description:a,notes:o}=await n.json();if(r!==null){let e=`/chat?session=${r}`;window.location.assign(e);return}let s=oe({title:i,taskId:t,description:a??``,notes:o??``}),c=await e(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({title:i,initialMessage:s})}),l=await c.json().catch(()=>({})),u=h(c.ok,c.status,l),d=l.sessionId??null;if(u.kind!==`navigate`){console.error(`[admin-ui] task-session op=spawn-failed taskId=${t} reason=${u.reason}`);return}if(d!==null){let n=await e(`/api/admin/task-session-link`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({taskId:t,sessionId:d})});n.ok&&(await n.json().catch(()=>({}))).linked}else console.error(`[admin-ui] task-session op=link-skipped taskId=${t} reason=no-landed-session-id`);window.location.assign(u.url)}catch(e){console.error(`[admin-ui] task-session op=failed taskId=${t} error=${e instanceof Error?e.message:String(e)}`)}finally{H.current.delete(t),de(new Set(H.current))}}},[e]);if(!o)return(0,D.jsx)(c,{surface:`gate`});let Se=e=>e.taskId!==null&&j===e.taskId,Ce=e=>(0,D.jsxs)(`div`,{className:`tasks-edit`,children:[(0,D.jsx)(`input`,{className:`tasks-edit-input`,type:`number`,min:0,step:1,"aria-label":`Logged minutes`,value:P,onChange:e=>F(e.target.value)}),(0,D.jsx)(`span`,{className:`tasks-edit-unit`,children:`min`}),(0,D.jsxs)(`button`,{className:`admin-btn-cta tasks-btn-action`,disabled:d,onClick:()=>void ve(e),children:[(0,D.jsx)(r,{size:14}),` Save`]}),(0,D.jsxs)(`button`,{className:`tasks-btn-secondary tasks-btn-action`,onClick:Q,children:[(0,D.jsx)(l,{size:14}),` Cancel`]})]}),$=(e,n)=>[{key:`edit-time`,label:`Edit logged time for task: ${e.name}`,menuLabel:`Edit time`,title:e.running?`Stop the timer before editing time`:`Set the logged time for this task`,icon:(0,D.jsx)(t,{size:12}),disabled:d||e.running,onClick:()=>_e(e,n)},{key:`reset-time`,label:`Reset logged time for task: ${e.name}`,menuLabel:`Reset logged time to 0:00`,title:e.running?`Stop the timer before resetting time`:`Set the logged time back to zero`,icon:(0,D.jsx)(y,{size:12}),disabled:d||e.running,onClick:()=>ye(n)},{key:`session`,label:`Open session for task: ${e.name}`,menuLabel:`Session`,title:e.sessionId?`Resume this task’s session`:`Start a session for this task`,icon:(0,D.jsx)(_,{size:12}),disabled:ue.has(n),onClick:()=>{xe(n)}},{key:`delete`,label:`Delete task: ${e.name}`,menuLabel:`Delete`,title:e.running?`Stop the timer before deleting`:`Delete this task and its time records`,icon:(0,D.jsx)(f,{size:12}),danger:!0,disabled:d||e.running,onClick:()=>B(e.rowKey)}];return(0,D.jsxs)(`div`,{className:`ui-page ui-page--full tasks-body`,children:[I!==null&&(0,D.jsx)(ce,{task:U??null,roster:pe,busy:d,onAssign:be,onClose:()=>L(null)}),(0,D.jsx)(ee,{target:W?{name:W.name,secondsLogged:W.secondsLogged}:null,anchorEl:z?V.current.get(z)??null:null,onCancel:()=>B(null),onConfirm:()=>{let e=W;B(null),e?.taskId&&ge(e.taskId)}},z??`none`),(0,D.jsxs)(`div`,{className:`tasks-tabs`,children:[(0,D.jsxs)(`button`,{className:`admin-chip ${C===`open`?`is-active`:``}`,onClick:()=>w(`open`),children:[`Open `,(0,D.jsx)(`span`,{className:`tasks-tab-badge`,children:n.open.length})]}),(0,D.jsxs)(`button`,{className:`admin-chip ${C===`completed`?`is-active`:``}`,onClick:()=>w(`completed`),children:[`Completed `,(0,D.jsx)(`span`,{className:`tasks-tab-badge`,children:n.completed.length})]}),(0,D.jsxs)(`button`,{className:`admin-chip ${C===`clients`?`is-active`:``}`,onClick:()=>w(`clients`),children:[`Clients `,(0,D.jsx)(`span`,{className:`tasks-tab-badge`,children:G.length})]})]}),C===`clients`?(0,D.jsx)(se,{clients:G,onSelect:fe}):(0,D.jsxs)(D.Fragment,{children:[T&&(0,D.jsxs)(`div`,{className:`tasks-filter-banner`,children:[(0,D.jsxs)(`span`,{children:[`Showing `,T]}),(0,D.jsx)(`button`,{className:`tasks-filter-clear`,onClick:()=>O(null),children:`Clear`})]}),q.length>0&&(0,D.jsxs)(`div`,{className:`tasks-assignee-bar`,children:[(0,D.jsxs)(`button`,{className:`admin-chip ${k===null?`is-active`:``}`,"aria-pressed":k===null,onClick:()=>A(null),children:[`All `,(0,D.jsx)(`span`,{className:`tasks-assignee-count`,children:K.open.length})]}),q.map(e=>(0,D.jsxs)(`button`,{className:`admin-chip ${k===e.userId?`is-active`:``}`,"aria-pressed":k===e.userId,"aria-label":`Assignee ${e.label}`,title:e.userId===`__unassigned__`?`Tasks with no assigned admin`:`AdminUser ${e.userId}`,onClick:()=>A(k===e.userId?null:e.userId),children:[e.label,` `,(0,D.jsx)(`span`,{className:`tasks-assignee-count`,children:e.openCount})]},e.userId))]}),C===`open`?(0,D.jsxs)(`section`,{className:`admin-card tasks-card`,children:[(0,D.jsxs)(`div`,{className:`tasks-card-head`,children:[(0,D.jsx)(`span`,{className:`tasks-card-title`,children:`Open tasks`}),(0,D.jsxs)(`span`,{className:`tasks-card-count`,children:[J.length,` to do`]})]}),J.length===0&&(0,D.jsx)(`div`,{className:`tasks-empty`,children:`No open tasks.`}),J.map(e=>(0,D.jsxs)(`div`,{className:`tasks-row`,ref:t=>{t?V.current.set(e.rowKey,t):V.current.delete(e.rowKey)},children:[(0,D.jsx)(`button`,{className:`tasks-row-open`,"aria-label":`Open task detail: ${e.name}`,onClick:()=>L(e.rowKey),children:(0,D.jsxs)(`div`,{className:`tasks-row-main`,children:[(0,D.jsx)(`div`,{className:`tasks-row-name`,children:e.name}),(0,D.jsx)(`div`,{className:`tasks-row-sub`,children:M(e,ie(e))})]})}),(0,D.jsx)(`div`,{className:`tasks-row-elapsed ${e.running?`tasks-row-elapsed-running`:``}`,children:u(ae(e,S))}),(0,D.jsx)(`div`,{className:`tasks-row-controls`,children:e.taskId!==null&&le===e.taskId?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`span`,{className:`tasks-confirm-label`,children:`Complete?`}),(0,D.jsxs)(`button`,{className:`admin-btn-cta tasks-btn-action`,disabled:d,onClick:()=>{R(null),he(e.taskId)},children:[(0,D.jsx)(r,{size:14}),` Confirm complete`]}),(0,D.jsxs)(`button`,{className:`tasks-btn-secondary tasks-btn-action`,onClick:()=>R(null),children:[(0,D.jsx)(l,{size:14}),` Keep open`]})]}):e.taskId===null?(0,D.jsx)(`span`,{className:`tasks-row-broken`,title:`This task has no id, so it cannot be started, edited or completed. Repair it by running platform/scripts/backfill-task-ids.sh on this install.`,children:`Needs repair`}):Se(e)?Ce(e.taskId):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(m,{actions:$(e,e.taskId),disabled:!1,label:`Task actions`}),(0,D.jsx)(`button`,{className:`tasks-btn-secondary tasks-btn-action tasks-btn-icon`,"aria-label":`Complete task: ${e.name}`,disabled:d||e.running,title:e.running?`Stop the timer before completing`:`Complete task`,onClick:()=>R(e.taskId),children:(0,D.jsx)(r,{size:14})}),e.running?(0,D.jsxs)(`button`,{className:`admin-btn-danger tasks-btn-action`,disabled:d,title:`Stop the timer`,onClick:()=>void Z(`/api/admin/task-timer-stop`,e.taskId),children:[(0,D.jsx)(a,{size:14}),` Stop`]}):(0,D.jsxs)(`button`,{className:`admin-btn-cta tasks-btn-action`,disabled:d,title:`Start the timer`,onClick:()=>void Z(`/api/admin/task-timer-start`,e.taskId),children:[(0,D.jsx)(v,{size:14}),` Start`]})]})})]},e.rowKey))]}):(0,D.jsxs)(`section`,{className:`admin-card tasks-card`,children:[(0,D.jsxs)(`div`,{className:`tasks-card-head`,children:[(0,D.jsx)(`span`,{className:`tasks-card-title`,children:`Completed`}),(0,D.jsxs)(`span`,{className:`tasks-card-count`,children:[Y.length,` done`]})]}),Y.length===0&&(0,D.jsx)(`div`,{className:`tasks-empty`,children:`Nothing completed yet.`}),Y.map(e=>(0,D.jsxs)(`div`,{className:`tasks-row tasks-row-done`,ref:t=>{t?V.current.set(e.rowKey,t):V.current.delete(e.rowKey)},children:[(0,D.jsx)(`button`,{className:`tasks-row-open`,"aria-label":`Open task detail: ${e.name}`,onClick:()=>L(e.rowKey),children:(0,D.jsxs)(`div`,{className:`tasks-row-main`,children:[(0,D.jsx)(`div`,{className:`tasks-row-name`,children:e.name}),(0,D.jsx)(`div`,{className:`tasks-row-sub`,children:M(e,ie(e))})]})}),(0,D.jsx)(`div`,{className:`tasks-row-elapsed`,children:u(e.secondsLogged)}),(0,D.jsx)(`div`,{className:`tasks-row-controls`,children:e.taskId===null?(0,D.jsx)(`span`,{className:`tasks-row-broken`,title:`This task has no id, so its logged time cannot be edited. Repair it by running platform/scripts/backfill-task-ids.sh on this install.`,children:`Needs repair`}):Se(e)?Ce(e.taskId):(0,D.jsx)(m,{actions:$(e,e.taskId),disabled:!1,label:`Task actions`})})]},e.rowKey))]})]})]})}function P({cacheKey:e}){let{adminFetch:t}=i({initialCacheKey:e,surface:`tasks`});return(0,D.jsx)(N,{adminFetch:t})}function F(){let[e,t]=(0,x.useState)(null),[n,r]=(0,x.useState)(!1),[i,a]=(0,x.useState)(void 0),[o,s]=(0,x.useState)(null),[l,u]=(0,x.useState)(null),[f,ee]=(0,x.useState)(null),[m,h]=(0,x.useState)(null);(0,x.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(k)}catch{}if(!n){t(null),r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(k)}catch{}window.location.href=`/`;return}if(i.ok)try{let e=await i.json();typeof e.businessName==`string`&&a(e.businessName),e.sessionId!==void 0&&s(e.sessionId??null),u(e.role??null),ee(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 _=(0,x.useCallback)(()=>{try{sessionStorage.removeItem(k)}catch{}window.location.href=`/`},[]),[v,y]=(0,x.useState)(!1),b=(0,x.useCallback)(async()=>{y(!0);try{let e=await p();if(e){try{sessionStorage.removeItem(k)}catch{}window.location.href=`/`}return e}finally{y(!1)}},[]);return n?e?(0,D.jsx)(d,{cacheKey:e,surface:`tasks`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=tasks`);try{sessionStorage.removeItem(k)}catch{}window.location.href=`/`},children:(0,D.jsx)(g,{cacheKey:e,businessName:i,sessionId:o,onLogout:_,onDisconnect:b,disconnecting:v,userName:f,userAvatar:m,role:l,children:(0,D.jsx)(P,{cacheKey:e})})}):(0,D.jsx)(`div`,{className:`tasks-page`,children:(0,D.jsxs)(`div`,{className:`tasks-empty`,children:[(0,D.jsx)(`p`,{children:`You are not signed in.`}),(0,D.jsxs)(`p`,{children:[`Open the `,(0,D.jsx)(`a`,{href:`/`,className:`tasks-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,D.jsx)(c,{surface:`gate`})}(0,b.createRoot)(document.getElementById(`root`)).render((0,D.jsx)(F,{}));
@@ -1 +0,0 @@
1
- import{B as e}from"./useSubAccountSwitcher-C7TtIbR3.js";var t=e(`triangle-alert`,[[`path`,{d:`m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3`,key:`wmoenq`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]);export{t};
@@ -1 +0,0 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{Z as t,r as n}from"./useSubAccountSwitcher-C7TtIbR3.js";var r=e(t(),1);function i(e){let[t,i]=(0,r.useState)(`idle`),a=(0,r.useRef)(null),o=(0,r.useRef)(e?.onResult);return o.current=e?.onResult,(0,r.useEffect)(()=>()=>{a.current&&clearTimeout(a.current)},[]),{status:t,copy:(0,r.useCallback)(async e=>{let t=await n(e);i(t?`ok`:`fail`),o.current?.(t),a.current&&clearTimeout(a.current),a.current=setTimeout(()=>i(`idle`),1500)},[])}}export{i as t};
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/pdf-render-DanMu_cf.js","assets/preload-helper-BQrMkyGX.js"])))=>i.map(i=>d[i]);
2
- import{o as e}from"./chunk-CltuBf4Z.js";import{B as t,G as n,P as r,Z as i,b as a,i as o,k as s,r as c,u as l}from"./useSubAccountSwitcher-C7TtIbR3.js";import{t as u}from"./copy-PkR4EFD6.js";import{t as d}from"./play-huZpq9ra.js";import{t as f}from"./preload-helper-BQrMkyGX.js";var p=`image/jpeg,image/png,image/gif,image/webp,application/pdf,text/plain,text/markdown,text/csv,text/html,text/calendar,application/zip,application/x-zip-compressed,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.oasis.opendocument.text,text/rtf,application/rtf,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,application/vnd.oasis.opendocument.spreadsheet,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.ms-powerpoint,application/vnd.oasis.opendocument.presentation,audio/ogg,audio/opus,audio/mp4,audio/x-m4a,audio/mpeg,audio/webm,audio/wav,video/mp4,.docx,.odt,.rtf,.xlsx,.xls,.ods,.pptx,.ppt,.odp,.opus,.ogg,.m4a,.mp4,.mp3,.wav,.webm`,m=new Set(p.split(`,`).filter(e=>!e.startsWith(`.`))),h=50*1024*1024;function g(e){switch(e){case`expanded`:return!0;case`collapsed`:return!1;default:return}}var _=t(`check-check`,[[`path`,{d:`M18 6 7 17l-5-5`,key:`116fxf`}],[`path`,{d:`m22 10-7.5 7.5L13 16`,key:`ke71qq`}]]),v=t(`file-code`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 12.5 8 15l2 2.5`,key:`1tg20x`}],[`path`,{d:`m14 12.5 2 2.5-2 2.5`,key:`yinavb`}]]),y=t(`mic`,[[`path`,{d:`M12 19v3`,key:`npa21l`}],[`path`,{d:`M19 10v2a7 7 0 0 1-14 0v-2`,key:`1vc78b`}],[`rect`,{x:`9`,y:`2`,width:`6`,height:`13`,rx:`3`,key:`s6n7sd`}]]),b=t(`paperclip`,[[`path`,{d:`m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551`,key:`1miecu`}]]),x=t(`pause`,[[`rect`,{x:`14`,y:`3`,width:`5`,height:`18`,rx:`1`,key:`kaeet6`}],[`rect`,{x:`5`,y:`3`,width:`5`,height:`18`,rx:`1`,key:`1wsw3u`}]]),S=t(`reply`,[[`path`,{d:`M20 18v-2a4 4 0 0 0-4-4H4`,key:`5vmcpk`}],[`path`,{d:`m9 17-5-5 5-5`,key:`nvlc11`}]]),C=t(`user`,[[`path`,{d:`M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2`,key:`975kel`}],[`circle`,{cx:`12`,cy:`7`,r:`4`,key:`17ys0d`}]]),w=e(i(),1),T=n();function E({children:e,tail:t=null,repinSignals:n}){let r=(0,w.useRef)(null),i=(0,w.useRef)(null),a=(0,w.useRef)(!0),[o,s]=(0,w.useState)(!0),c=(0,w.useRef)(0),l=(0,w.useRef)(0),u=()=>{let e=r.current;if(!e)return;let t=e.clientHeight,n=e.scrollHeight,i=t!==c.current||n!==l.current;if(c.current=t,l.current=n,i){a.current&&(e.scrollTop=e.scrollHeight);return}let o=n-e.scrollTop-t<=32;a.current=o,s(e=>e===o?e:o)},d=()=>{let e=r.current;e&&(e.scrollTop=e.scrollHeight,l.current=e.scrollHeight,c.current=e.clientHeight,a.current=!0,s(!0))},f=t!=null;return(0,w.useLayoutEffect)(()=>{let e=r.current;e&&a.current&&(e.scrollTop=e.scrollHeight),e&&(l.current=e.scrollHeight,c.current=e.clientHeight)},[...n,f]),(0,w.useLayoutEffect)(()=>{if(typeof ResizeObserver>`u`)return;let e=new ResizeObserver(()=>u());return r.current&&e.observe(r.current),i.current&&e.observe(i.current),()=>e.disconnect()},[]),(0,T.jsxs)(`div`,{className:`wa-reader`,children:[(0,T.jsx)(`div`,{className:`wa-reader-thread`,ref:r,onScroll:u,children:(0,T.jsxs)(`div`,{className:`wa-thread-scroll`,ref:i,children:[e,t]})}),!o&&(0,T.jsx)(`button`,{type:`button`,className:`wa-jump`,onClick:d,"aria-label":`Jump to latest message`,title:`Jump to latest message`,children:`↓`})]})}var D={auth_expired:`Your session has expired. Please sign in again.`,claude_down:`Claude is currently experiencing an outage. Please try again in a few minutes.`,claude_overloaded:`Claude is overloaded right now. Please try again shortly.`,model_unavailable:`The selected model is currently unavailable. Switch to a different model from the model picker to continue.`,agent_error:`Something went wrong. Please try again.`},O={auth_expired:`I'm not available right now. Please try again later.`,claude_down:`I'm not available right now. Please try again later.`,claude_overloaded:`I'm not available right now. Please try again shortly.`,model_unavailable:`I'm not available right now. Please try again later.`,agent_error:`I'm not available right now. Please try again later.`};function k(e,t=`admin`){return t===`public`?O[e]:D[e]}function A(e){return e===`whatsapp`?` · via WhatsApp`:e===`webchat`?` · via web`:``}var j=56,M=5;function ee(e,t){let n=Math.max(1,Math.floor(e.length/t)),r=[],i=0;for(let a=0;a<t;a++){let t=a*n,o=0,s=0;for(let r=t;r<t+n&&r<e.length;r++)o+=e[r]*e[r],s++;let c=s>0?Math.sqrt(o/s):0;r.push(c),c>i&&(i=c)}return i>0?r.map(e=>e/i):r}function te({src:e,filename:t,onDecodeFail:n,onMediaError:r}){let i=(0,w.useRef)(null),a=(0,w.useRef)(null),s=(0,w.useRef)(!1),[c,l]=(0,w.useState)([]),[u,f]=(0,w.useState)(void 0),[p,m]=(0,w.useState)(!1),[h,g]=(0,w.useState)(0),[_,v]=(0,w.useState)(0);(0,w.useEffect)(()=>{let t=!1,r=null,i=window.AudioContext??window.webkitAudioContext,a=()=>{t||s.current||(s.current=!0,n())};if(!i){a();return}let o=new i;return(async()=>{try{let n=await fetch(e);if(!n.ok)throw Error(`audio fetch ${n.status}`);let i=await n.blob();if(t)return;r=URL.createObjectURL(i),f(r);let a=await o.decodeAudioData(await i.arrayBuffer());if(t)return;l(ee(a.getChannelData(0),j)),Number.isFinite(a.duration)&&a.duration>0&&v(a.duration)}catch{a()}finally{try{o.close()}catch{}}})(),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]);let y=()=>{let e=i.current;e&&(p?e.pause():Promise.resolve(e.play()).catch(()=>{}))},b=e=>{let t=i.current;if(!t||!(_>0))return;let n=Math.min(_,Math.max(0,e));t.currentTime=n,g(n)},S=e=>{let t=a.current;if(!t||!(_>0))return;let n=t.getBoundingClientRect();b(Math.min(1,Math.max(0,(e-n.left)/n.width))*_)},C=e=>{S(e.clientX);let t=e=>S(e.clientX),n=()=>{window.removeEventListener(`mousemove`,t),window.removeEventListener(`mouseup`,n)};window.addEventListener(`mousemove`,t),window.addEventListener(`mouseup`,n)},E=e=>{if(!(_>0))return;let t=i.current?.currentTime??0;switch(e.key){case`ArrowRight`:case`ArrowUp`:b(t+M),e.preventDefault();break;case`ArrowLeft`:case`ArrowDown`:b(t-M),e.preventDefault();break;case`Home`:b(0),e.preventDefault();break;case`End`:b(_),e.preventDefault();break;default:break}},D=_>0?Math.min(1,h/_):0,O=Math.round(D*j),k=o(h>0?h:_);return(0,T.jsxs)(`div`,{className:`voice-note`,children:[(0,T.jsx)(`button`,{type:`button`,className:`voice-note-play`,"aria-label":`${p?`Pause`:`Play`} ${t}`,onClick:y,children:p?(0,T.jsx)(x,{size:16,"aria-hidden":!0}):(0,T.jsx)(d,{size:16,"aria-hidden":!0})}),(0,T.jsx)(`div`,{ref:a,className:`voice-note-bars`,role:`slider`,tabIndex:0,"aria-label":`Seek ${t}`,"aria-valuemin":0,"aria-valuemax":Math.round(_),"aria-valuenow":Math.round(h),onMouseDown:C,onKeyDown:E,children:(c.length?c:Array.from({length:j},()=>0)).map((e,t)=>(0,T.jsx)(`span`,{className:`voice-note-bar${t<O?` is-played`:``}`,style:{height:`${Math.max(10,Math.round(e*100))}%`}},t))}),(0,T.jsx)(`span`,{className:`voice-note-time`,children:k}),(0,T.jsx)(`audio`,{ref:i,className:`voice-note-audio`,preload:`metadata`,src:u,"aria-label":t,onPlay:()=>m(!0),onPause:()=>m(!1),onEnded:()=>m(!1),onError:()=>r?.(),onLoadedMetadata:e=>{let t=e.currentTarget.duration;Number.isFinite(t)&&t>0&&v(t)},onTimeUpdate:e=>g(e.currentTarget.currentTime)})]})}var N=/\.(png|jpe?g|gif|webp|svg|bmp)$/i,P=/\.pdf$/i;function ne(e,t){return(t?t.startsWith(`image/`):N.test(e))?`image`:t&&t.startsWith(`audio/`)?`audio`:(t?t===`application/pdf`:P.test(e))?`pdf`:`file`}function F(e,t,n,r){let i=encodeURIComponent(e.path),a=encodeURIComponent(n),o=r?`&disposition=${r}`:``;return e.root===`scratchpad`?`/api/admin/files/download?path=${i}&root=scratchpad&sessionId=${encodeURIComponent(t)}&session_key=${a}${o}`:`/api/admin/files/download?path=${i}&root=data&session_key=${a}${o}`}function I(e,t,n,r){return t===`public`?`/api/public-reader/attachment/${e}?sessionId=${encodeURIComponent(n)}`:`/api/admin/attachment/${e}?session_key=${encodeURIComponent(r)}`}function re(e,t,n){return`/api/admin/session-upload?session_key=${encodeURIComponent(n)}&session_id=${encodeURIComponent(e)}&file=${encodeURIComponent(t)}`}function L(e){if(e<1024)return`${e} B`;let t=e/1024;if(t<1024)return`${t<10?t.toFixed(1):Math.round(t)} KB`;let n=t/1024;return`${n<10?n.toFixed(1):Math.round(n)} MB`}function R({href:e,filename:t,label:n}){return(0,T.jsxs)(`a`,{className:`chat-attachment-chip`,href:e,download:t,children:[(0,T.jsx)(b,{size:14,"aria-hidden":!0}),n]})}function z({href:e,filename:t,className:n,size:i=14,onClick:a}){return(0,T.jsx)(`a`,{className:n,href:e,download:t,"aria-label":`Download ${t}`,onClick:a,children:(0,T.jsx)(r,{size:i,"aria-hidden":!0})})}function ie({src:e,filename:t,sizeBytes:n,expandable:r,onFail:i}){let[a,o]=(0,w.useState)(!1),[s,c]=(0,w.useState)(!1),l=n==null?t:`${t} · ${L(n)}`;return s?(0,T.jsx)(R,{href:e,filename:t,label:l}):(0,T.jsxs)(T.Fragment,{children:[(0,T.jsxs)(`span`,{className:`chat-attachment-image-wrap`,children:[(0,T.jsx)(`img`,{className:`chat-attachment-image`,src:e,alt:t,onClick:r?()=>o(!0):void 0,onError:()=>{c(!0),i?.(`fetch`)}}),(0,T.jsx)(z,{href:e,filename:t,className:`chat-attachment-download`})]}),r&&a&&(0,T.jsx)(`div`,{className:`chat-attachment-overlay`,role:`dialog`,"aria-label":t,onClick:()=>o(!1),children:(0,T.jsx)(`img`,{className:`chat-attachment-overlay-image`,src:e,alt:t})})]})}var ae=280,oe=360,se=16;function B({src:e,filename:t,sizeBytes:n,onFail:r}){let[i,a]=(0,w.useState)(!1),[o,c]=(0,w.useState)(!1),l=(0,w.useRef)(null),u=n==null?t:`${t} · ${L(n)}`;return(0,w.useEffect)(()=>{let t=!1,n=null;return(async()=>{try{let{loadPdf:r,renderPageToFit:i}=await f(async()=>{let{loadPdf:e,renderPageToFit:t}=await import(`./pdf-render-DanMu_cf.js`);return{loadPdf:e,renderPageToFit:t}},__vite__mapDeps([0,1])),a=await r(e);n=a;let o=l.current;if(t||!o)return;await i(a,1,o,ae,oe)}catch{t||(c(!0),r?.(`render`))}})(),()=>{t=!0;try{n?.destroy()}catch{}}},[e]),o?(0,T.jsx)(R,{href:e,filename:t,label:u}):(0,T.jsxs)(T.Fragment,{children:[(0,T.jsxs)(`div`,{className:`chat-attachment-pdf`,children:[(0,T.jsx)(`canvas`,{ref:l,className:`chat-attachment-pdf-canvas`,"aria-label":t}),(0,T.jsx)(z,{href:e,filename:t,className:`chat-attachment-download`}),(0,T.jsx)(`button`,{type:`button`,className:`chat-attachment-pdf-expand`,"aria-label":`Expand ${t}`,onClick:()=>a(!0),children:(0,T.jsx)(s,{size:14,"aria-hidden":!0})})]}),i&&(0,T.jsx)(ce,{src:e,filename:t,label:u,onClose:()=>a(!1),onFail:r})]})}function ce({src:e,filename:t,label:n,onClose:r,onFail:i}){let o=(0,w.useRef)(null),s=(0,w.useRef)(null),[c,l]=(0,w.useState)(null),[u,d]=(0,w.useState)(!1);return(0,w.useEffect)(()=>{let t=!1;return(async()=>{try{let{loadPdf:n}=await f(async()=>{let{loadPdf:e}=await import(`./pdf-render-DanMu_cf.js`);return{loadPdf:e}},__vite__mapDeps([0,1])),r=await n(e);if(t){try{r.destroy()}catch{}return}s.current=r,l(r.numPages)}catch{t||(d(!0),i?.(`render`))}})(),()=>{t=!0;try{s.current?.destroy()}catch{}}},[e]),(0,w.useEffect)(()=>{if(c==null)return;let e=o.current,t=s.current;if(!e||!t)return;let n=!1;return(async()=>{try{let{renderPageToWidth:r}=await f(async()=>{let{renderPageToWidth:e}=await import(`./pdf-render-DanMu_cf.js`);return{renderPageToWidth:e}},__vite__mapDeps([0,1])),i=Array.from(e.querySelectorAll(`canvas.chat-attachment-overlay-page`)),a=Math.max(e.clientWidth-se*2,1);for(let e=0;e<i.length;e++){if(n)return;await r(t,e+1,i[e],a)}}catch{n||(d(!0),i?.(`render`))}})(),()=>{n=!0}},[c]),(0,T.jsxs)(`div`,{className:`chat-attachment-overlay`,role:`dialog`,"aria-label":t,onClick:r,children:[(0,T.jsx)(`div`,{ref:o,className:`chat-attachment-overlay-pdf`,onClick:e=>e.stopPropagation(),children:u?(0,T.jsx)(R,{href:e,filename:t,label:n}):Array.from({length:c??0},(e,n)=>(0,T.jsx)(`canvas`,{className:`chat-attachment-overlay-page`,"aria-label":`${t} page ${n+1}`},n))}),(0,T.jsx)(z,{href:e,filename:t,className:`chat-attachment-overlay-download`,size:20,onClick:e=>e.stopPropagation()}),(0,T.jsx)(`button`,{type:`button`,className:`chat-attachment-overlay-close`,"aria-label":`Close`,onClick:r,children:(0,T.jsx)(a,{size:20,"aria-hidden":!0})})]})}function le({src:e,filename:t,onFail:n}){let[r,i]=(0,w.useState)(!1);return r?(0,T.jsx)(`audio`,{className:`chat-attachment-audio`,controls:!0,preload:`metadata`,src:e,"aria-label":t,onError:()=>n?.(`fetch`)}):(0,T.jsx)(te,{src:e,filename:t,onDecodeFail:()=>{i(!0),n?.(`render`)},onMediaError:()=>{i(!0),n?.(`fetch`)}})}function V({filename:e,href:t,mimeType:n,sizeBytes:r,expandable:i,telemetry:a}){let o=ne(e,n);(0,w.useEffect)(()=>{a?.onRender?.({kind:o,mime:n,served:!!t})},[]);let s=a?.onFail?e=>a.onFail({kind:o===`pdf`?`pdf`:o===`audio`?`audio`:`image`,mime:n,reason:e}):void 0;if(o===`image`&&t)return(0,T.jsx)(ie,{src:t,filename:e,sizeBytes:r,expandable:i,onFail:s});if(o===`audio`&&t)return(0,T.jsx)(le,{src:t,filename:e,onFail:s});if(o===`pdf`&&t)return(0,T.jsx)(B,{src:t,filename:e,sizeBytes:r,onFail:s});let c=r==null?e:`${e} · ${L(r)}`;return t?(0,T.jsx)(R,{href:t,filename:e,label:c}):(0,T.jsxs)(`p`,{className:`chat-doc`,children:[(0,T.jsx)(b,{size:14,"aria-hidden":!0,style:{verticalAlign:`text-bottom`}}),` `,c]})}var ue=/^-?\d+(\.\d+)?,-?\d+(\.\d+)?$/,de=/^\[(?:live )?location: (.+)\]$/;function H(e){let t=de.exec(e.trim());if(!t)return{kind:`none`};let n=t[1].split(` — `),r=n[n.length-1].trim();if(!ue.test(r))return{kind:`label-only`};let[i,a]=r.split(`,`),o=Number(i),s=Number(a);return!Number.isFinite(o)||!Number.isFinite(s)?{kind:`reject`,reason:`nan`,raw:r}:o<-90||o>90||s<-180||s>180?{kind:`reject`,reason:`range`,raw:r}:`${o},${s}`===r?{kind:`point`,lat:o,lon:s}:{kind:`reject`,reason:`roundtrip`,raw:r}}function fe(e,t,n=16){let r=2**n,i=(t+180)/360*r,a=(1-Math.asinh(Math.tan(e*Math.PI/180))/Math.PI)/2*r,o=Math.round(i)-1,s=(o%r+r)%r,c=Math.min(Math.max(Math.round(a)-1,0),r-2);return{tiles:[{x:s,y:c},{x:(s+1)%r,y:c},{x:s,y:c+1},{x:(s+1)%r,y:c+1}].map(e=>({...e,url:`https://tile.openstreetmap.org/${n}/${e.x}/${e.y}.png`})),offsetX:i*256-o*256,offsetY:a*256-c*256}}var U=0,W=0;function pe(){return{maps:U,tileErrors:W}}function me({lat:e,lon:t,msgKeyId:n}){let{tiles:r,offsetX:i,offsetY:a}=fe(e,t);return(0,w.useEffect)(()=>(U+=1,()=>{--U}),[]),(0,T.jsx)(`a`,{className:`wa-map`,href:`https://www.openstreetmap.org/?mlat=${e}&mlon=${t}#map=16/${e}/${t}`,target:`_blank`,rel:`noopener noreferrer`,style:{width:240,height:160},children:(0,T.jsxs)(`span`,{className:`wa-map-viewport`,children:[(0,T.jsx)(`span`,{className:`wa-map-block`,style:{left:`calc(50% - ${i}px)`,top:`calc(50% - ${a}px)`},children:r.map(e=>(0,T.jsx)(`img`,{className:`wa-map-tile`,src:e.url,alt:``,width:256,height:256,loading:`lazy`,onError:()=>{W+=1}},e.url))}),(0,T.jsx)(`span`,{className:`wa-map-pin`,"aria-hidden":!0}),(0,T.jsx)(`span`,{className:`wa-map-credit`,children:`© OpenStreetMap contributors`})]})})}function G({text:e,body:t,msgKeyId:n}){let r=H(e);return(0,T.jsxs)(T.Fragment,{children:[r.kind===`point`&&(0,T.jsx)(me,{lat:r.lat,lon:r.lon,msgKeyId:n}),(0,T.jsx)(`p`,{className:`wa-body`,children:t})]})}function he(e){let t=0,n=0,r=0,i=0;for(let a of e){let e=a.kind===`turn`?a.turn:null,o=e&&`text`in e&&typeof e.text==`string`?e.text:``;if(o===``)continue;t+=1;let s=H(o);s.kind!==`none`&&(n+=1,s.kind===`point`?r+=1:s.kind===`reject`&&(i+=1))}return{bodies:t,withLabel:n,parsed:r,rejected:i}}function ge(e,t,n,r=`/api/session-reader/stream`,i=e,a=!0){let[o,s]=(0,w.useState)([]),[c,l]=(0,w.useState)(`open`),[u,d]=(0,w.useState)(null),f=(0,w.useRef)([]);return(0,w.useEffect)(()=>{f.current=o},[o]),(0,w.useEffect)(()=>{s([]),f.current=[],d(null)},[i,t,n,r]),(0,w.useEffect)(()=>{if(l(`open`),!a)return;let i=f.current.slice(),o=i.map(K),c=0,u=i.length>0,p=`${r}?sessionId=${encodeURIComponent(e)}&projectDir=${encodeURIComponent(t)}&session_key=${encodeURIComponent(n)}`,m=new EventSource(p);return m.onopen=()=>{l(`open`)},m.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(u){if(c<o.length&&K(t)===o[c]){c+=1;return}u=!1}s(e=>[...e,t])},m.addEventListener(`activity`,e=>{try{d(JSON.parse(e.data))}catch{}}),m.addEventListener(`activity-clear`,()=>d(null)),m.onerror=()=>{m.readyState===2&&(console.error(`[admin-ui] wa-stream onerror readyState=${m.readyState}`),l(`error`))},()=>m.close()},[e,t,n,r,i,a]),{turns:o,status:c,subagentActivity:u}}function K(e){return JSON.stringify(e)}function _e(e,t,n,r=!0){let[i,a]=(0,w.useState)([]),[o,s]=(0,w.useState)(`open`);return(0,w.useEffect)(()=>{if(a([]),s(`open`),!r||!e||!t)return;let i=`/api/whatsapp-reader/store-stream?accountId=${encodeURIComponent(e)}&remoteJid=${encodeURIComponent(t)}&session_key=${encodeURIComponent(n)}`,o=new EventSource(i);return o.onopen=()=>s(`open`),o.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch{return}a(e=>[...e,t])},o.addEventListener(`reaction`,e=>{let t;try{t=JSON.parse(e.data)}catch{return}a(e=>e.map(e=>e.kind===`whatsapp-persisted`&&e.msgKeyId===t.targetMsgKeyId?{...e,reactions:t.reactions}:e))}),o.onerror=()=>{o.readyState===2&&s(`error`)},()=>o.close()},[e,t,n,r]),{turns:i,status:o}}var q=e=>{if(!e)return 1/0;let t=new Date(e).getTime();return Number.isNaN(t)?1/0:t};function ve(e,t){let n=[],r=0;return e.forEach((e,t)=>n.push({sort:q(e.ts),sub:1,ins:r++,item:{kind:`turn`,turn:e,idx:t}})),t.forEach(e=>n.push({sort:q(e.ts),sub:0,ins:r++,item:{kind:`directive`,entry:e}})),n.sort((e,t)=>e.sort===t.sort?e.sort===1/0?e.ins-t.ins:e.sub-t.sub||e.ins-t.ins:e.sort<t.sort?-1:1).map(e=>e.item)}function ye(e,t,n=!0){let[r,i]=(0,w.useState)([]);return(0,w.useEffect)(()=>{if(!n||typeof fetch!=`function`)return;let r=!0,a=`/api/session-reader/directives?sessionId=${encodeURIComponent(e)}&session_key=${encodeURIComponent(t)}`;return fetch(a).then(e=>e.ok?e.json():{entries:[]}).then(e=>{r&&i(Array.isArray(e.entries)?e.entries:[])}).catch(()=>{r&&i([])}),()=>{r=!1}},[e,t,n]),r}var be=new Set([`operator-inbound`,`operator-typed`,`agent-reply`,`agent-reply-document`,`agent-file`,`agent-error`,`agent-webchat-final`,`whatsapp-persisted`]),xe=[`#c2185b`,`#7b1fa2`,`#512da8`,`#303f9f`,`#1976d2`,`#0288d1`,`#0097a7`,`#00796b`,`#388e3c`,`#689f38`,`#af6c00`,`#e64a19`,`#5d4037`,`#455a64`,`#d81b60`,`#8e24aa`,`#3949ab`,`#039be5`,`#00897b`,`#6d4c41`];function Se(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619)>>>0;return t>>>0}function Ce(e){return xe[Se(e)%xe.length]}function we({accountId:e,jid:t,sessionKey:n,className:r=`wa-web-avatar`,size:i=20}){let[a,o]=(0,w.useState)(null);if(!t||a===t)return(0,T.jsx)(`span`,{className:r,"aria-hidden":!0,children:(0,T.jsx)(C,{size:i})});let s=`/api/whatsapp-reader/avatar?session_key=${encodeURIComponent(n)}&accountId=${encodeURIComponent(e)}&jid=${encodeURIComponent(t)}`;return(0,T.jsx)(`span`,{className:r,"aria-hidden":!0,children:(0,T.jsx)(`img`,{className:`wa-avatar-img`,src:s,alt:``,onError:()=>o(t)})})}function J(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}function Y(e){let t=e.lastIndexOf(`/`);return t===-1?e:e.slice(t+1)}var Te=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],Ee=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`];function X(e){let t=String(e.getMonth()+1).padStart(2,`0`),n=String(e.getDate()).padStart(2,`0`);return`${e.getFullYear()}-${t}-${n}`}function De(e){if(!e)return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:X(t)}function Oe(e,t=new Date){if(!e)return``;let n=new Date(e);if(Number.isNaN(n.getTime()))return``;let r=X(n);if(r===X(t))return`Today`;let i=new Date(t);return i.setDate(i.getDate()-1),r===X(i)?`Yesterday`:`${Te[n.getDay()]} ${n.getDate()} ${Ee[n.getMonth()]} ${n.getFullYear()}`}function ke(e){return e.kind===`turn`?e.turn.ts:e.entry.ts}function Ae({ts:e}){return(0,T.jsx)(`div`,{className:`day-divider`,role:`separator`,children:(0,T.jsx)(`span`,{className:`day-divider-label`,children:Oe(e)})})}function je(){return(0,T.jsx)(`div`,{className:`session-divider`,role:`separator`,children:(0,T.jsx)(`span`,{className:`session-divider-label`,children:`Conversation continued`})})}function Z({label:e,ts:t,colour:n}){return(0,T.jsxs)(`div`,{className:`wa-turn-head`,children:[(0,T.jsx)(`span`,{className:`wa-who`,style:n?{color:n}:void 0,children:e}),(0,T.jsx)(`time`,{className:`wa-time`,children:J(t)})]})}function Me({turn:e}){let[t,n]=(0,w.useState)(!1),r=e.kind===`tool-result`,i=r?`wa-turn wa-turn-result${e.isError?` is-error`:``}`:`wa-turn wa-turn-tool`,a=r?e.isError?`result (error)`:`result`:`↳ ${e.name}`,o=r?e.text:JSON.stringify(e.input,null,2);return(0,T.jsxs)(`div`,{className:i,children:[(0,T.jsxs)(`button`,{type:`button`,className:`wa-tool-toggle`,"aria-expanded":t,onClick:()=>n(e=>!e),children:[(0,T.jsx)(`span`,{className:`wa-chevron`,children:t?`▾`:`▸`}),(0,T.jsx)(`span`,{className:`wa-who`,children:a}),(0,T.jsx)(`time`,{className:`wa-time`,children:J(e.ts)})]}),t&&(0,T.jsx)(`pre`,{className:`wa-code`,children:o})]})}function Ne({entry:e,sessionId:t,sessionKey:n}){let[r,i]=(0,w.useState)(!1),[a,o]=(0,w.useState)(null),s=()=>{let s=!r;if(i(s),s&&a===null&&typeof fetch==`function`){let r=`/api/session-reader/directive?sessionId=${encodeURIComponent(t)}&name=${encodeURIComponent(e.name)}&session_key=${encodeURIComponent(n)}`;fetch(r).then(e=>e.ok?e.text():`(directive unavailable)`).then(o).catch(()=>o(`(directive unavailable)`))}};return(0,T.jsxs)(`div`,{className:`wa-turn wa-turn-directive`,children:[(0,T.jsxs)(`button`,{type:`button`,className:`wa-tool-toggle`,"aria-expanded":r,onClick:s,children:[(0,T.jsx)(`span`,{className:`wa-chevron`,children:r?`▾`:`▸`}),(0,T.jsxs)(`span`,{className:`wa-who`,children:[`⚙ directive injected (`,e.len,` B)`]}),(0,T.jsx)(`time`,{className:`wa-time`,children:J(e.ts)})]}),r&&(0,T.jsx)(`pre`,{className:`wa-code`,children:a??`Loading…`})]})}function Pe(e){return`text`in e&&typeof e.text==`string`?e.text:``}function Fe(e,t){let n=(t??``).trim();if(!n)return e;let r=e.toLowerCase(),i=n.toLowerCase(),a=[],o=0,s=0;for(;;){let t=r.indexOf(i,o);if(t===-1){a.push(e.slice(o));break}t>o&&a.push(e.slice(o,t)),a.push((0,T.jsx)(`mark`,{className:`wa-search-hit`,children:e.slice(t,t+i.length)},s++)),o=t+i.length}return a.length===1?a[0]:(0,T.jsx)(T.Fragment,{children:a})}var Q={onFail:({kind:e,mime:t,reason:n})=>console.warn(`[operator-ui] op=reader-attachment-fail kind=${e} mime=${t??``} reason=${n}`)};function Ie(e,t,n){switch(e.kind){case`operator-inbound`:return(0,T.jsxs)(`div`,{className:`wa-turn wa-turn-in`,children:[(0,T.jsx)(Z,{label:`Operator${A(e.source)}`,ts:e.ts}),e.text&&(0,T.jsx)(G,{text:e.text,body:e.text}),e.attachments&&e.attachments.length>0&&(0,T.jsx)(`div`,{className:`chat-attachment-list`,children:e.attachments.map((e,t)=>(0,T.jsx)(V,{expandable:!0,filename:e.filename,mimeType:e.mimeType,sizeBytes:e.sizeBytes,href:I(e.attachmentId,n.audience,n.sessionId,n.sessionKey),telemetry:Q},t))})]},t);case`operator-typed`:return(0,T.jsxs)(`div`,{className:`wa-turn wa-turn-in wa-turn-typed`,children:[(0,T.jsx)(Z,{label:`Operator (web)`,ts:e.ts}),(0,T.jsx)(G,{text:e.text,body:e.text})]},t);case`agent-text`:return(0,T.jsxs)(`div`,{className:`wa-turn wa-turn-think`,children:[(0,T.jsx)(Z,{label:`Agent`,ts:e.ts}),(0,T.jsx)(G,{text:e.text,body:e.text})]},t);case`agent-reply`:return(0,T.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,T.jsx)(Z,{label:`Agent`,ts:e.ts}),(0,T.jsx)(G,{text:e.text,body:e.text})]},t);case`agent-reply-document`:return(0,T.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,T.jsx)(Z,{label:`Agent`,ts:e.ts}),(0,T.jsxs)(`p`,{className:`wa-doc`,children:[(0,T.jsx)(b,{size:14,"aria-hidden":!0,style:{verticalAlign:`text-bottom`}}),` `,`sent document(s): `,e.files.map(Y).join(`, `)]}),e.caption&&(0,T.jsx)(`p`,{className:`wa-body`,children:e.caption})]},t);case`agent-file`:return(0,T.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,T.jsx)(Z,{label:`Agent`,ts:e.ts}),e.files.map((t,r)=>{let i=Y(t),a=e.downloads?.[r];return(0,T.jsx)(V,{expandable:!0,filename:i,href:a?F(a,n.sessionId,n.sessionKey,P.test(i)?`inline`:void 0):void 0,telemetry:Q},r)}),e.caption&&(0,T.jsx)(`p`,{className:`wa-body`,children:e.caption})]},t);case`whatsapp-persisted`:{let r=e.origin===`operator-manual`,i=e.fromMe?r?`You`:`Sent`:e.senderName??`Contact`,a=n.groupThread&&!e.fromMe&&n.storeAccountId&&e.senderJid&&l(e.senderJid)?e.senderJid:null;return(0,T.jsxs)(`div`,{className:`wa-turn ${e.fromMe?`wa-turn-out`:`wa-turn-in`}${r?` wa-op-manual`:``}${a?` wa-turn-has-avatar`:``}`,children:[a&&(0,T.jsx)(we,{accountId:n.storeAccountId,jid:a,sessionKey:n.sessionKey,className:`wa-bubble-avatar`,size:14}),n.onReplyTo&&e.msgKeyId&&(0,T.jsx)(`button`,{type:`button`,className:`wa-bubble-reply`,"aria-label":`Reply to this message`,onClick:()=>n.onReplyTo({msgKeyId:e.msgKeyId,body:e.text,senderName:e.senderName,fromMe:e.fromMe}),children:(0,T.jsx)(S,{size:14})}),n.showCopy&&e.text&&(0,T.jsx)(`button`,{type:`button`,className:`wa-bubble-copy`,"aria-label":`Copy this message`,onClick:()=>{let t=e.text;c(t).then(e=>{e||console.warn(`[operator-ui] op=wa-copy-fail reason=clipboard-unavailable`)})},children:(0,T.jsx)(u,{size:14})}),e.quoted&&(0,T.jsxs)(`div`,{className:`wa-quoted`,children:[(0,T.jsx)(`span`,{className:`wa-quoted-who`,children:e.quoted.fromMe?`You`:e.quoted.sender??`Contact`}),(0,T.jsx)(`span`,{className:`wa-quoted-body`,children:e.quoted.body||`Message`})]}),(0,T.jsx)(Z,{label:i,ts:e.ts,colour:n.groupThread&&!e.fromMe?Ce(e.senderTelephone||e.senderName||``):void 0}),e.text&&(0,T.jsx)(G,{text:e.text,body:Fe(e.text,n.highlight),msgKeyId:e.msgKeyId??void 0}),e.attachments&&e.attachments.length>0&&(0,T.jsx)(`div`,{className:`chat-attachment-list`,children:e.attachments.map((e,t)=>(0,T.jsx)(V,{expandable:!0,filename:e.filename,mimeType:e.mimeType,sizeBytes:e.sizeBytes,href:I(e.attachmentId,n.audience,n.sessionId,n.sessionKey),telemetry:Q},t))}),e.reactions&&e.reactions.length>0&&(0,T.jsx)(`div`,{className:`wa-reactions`,children:e.reactions.map((e,t)=>(0,T.jsx)(`span`,{className:`wa-reaction`,title:e.reactorName??void 0,children:e.emoji},t))}),(0,T.jsxs)(`span`,{className:`wa-bubble-meta`,children:[r&&(0,T.jsx)(`span`,{className:`wa-op-tag`,children:`You`}),(0,T.jsx)(`time`,{className:`wa-bubble-time`,children:J(e.ts)}),e.fromMe&&(0,T.jsx)(_,{size:14,className:`wa-bubble-tick`,"aria-hidden":!0})]})]},t)}case`session-continued`:return(0,T.jsx)(je,{},t);case`harness-internal`:return null;case`tool-call`:case`tool-result`:return(0,T.jsx)(Me,{turn:e},t);case`agent-error`:return(0,T.jsxs)(`div`,{className:`wa-turn wa-turn-error`,role:`alert`,children:[(0,T.jsx)(Z,{label:`Agent`,ts:e.ts}),(0,T.jsx)(`p`,{className:`wa-body wa-error-body`,children:k(e.code,`admin`)}),e.code===`agent_error`&&e.raw&&(0,T.jsx)(`pre`,{className:`wa-code`,children:e.raw})]},t)}}function $(e,t,n,r=`admin`,i,a,o,s,c){let l={sessionId:t,sessionKey:n,audience:r,highlight:i,onReplyTo:a,showCopy:o,groupThread:s,storeAccountId:c},u=[],d=null;return e.forEach((e,r)=>{let i=ke(e),a=De(i);a!==null&&a!==d&&(u.push((0,T.jsx)(Ae,{ts:i},`day-${r}`)),d=a),u.push(e.kind===`turn`?Ie(e.turn,r,l):(0,T.jsx)(Ne,{entry:e.entry,sessionId:t,sessionKey:n},r))}),u}function Le(e){return e.filter(e=>e.kind===`turn`&&be.has(e.turn.kind)&&!(e.turn.kind===`operator-inbound`&&e.turn.scheduled))}var Re=(0,w.memo)(function({sessionId:e,projectDir:t,sessionKey:n,renderItems:r=$,clean:i,onToggleClean:a,forceDeliveredOnly:o=!1,streamEndpoint:s=`/api/session-reader/stream`,suppressDirectives:c=!1,tail:l=null,resetKey:u,onTurnsChange:d,onActivityChange:f,store:p,search:m,onReplyTo:h,groupThread:g=!1}){let _=!!p,v=ge(e,t,n,s,u,!_),y=_e(p?.accountId??``,p?.remoteJid??``,n,_),{turns:b,status:x}=_?{turns:y.turns,status:y.status}:{turns:v.turns,status:v.status},S=_?null:v.subagentActivity;(0,w.useEffect)(()=>{f?.(S)},[S,f]),(0,w.useEffect)(()=>{d?.(b.length)},[b.length,d]);let C=ve(b,ye(e,n,!c)),D=a==null?!1:!!i,O=o||D?Le(C):C,k=(m??``).trim().toLowerCase(),A=k.length>0,j=A?O.filter(e=>e.kind===`turn`&&Pe(e.turn).toLowerCase().includes(k)):O;return(0,w.useEffect)(()=>{if(!g||!_)return;let e=b.filter(e=>e.kind===`whatsapp-persisted`&&!e.fromMe);if(e.length===0)return;let t=new Set(e.map(e=>e.senderTelephone||e.senderName||``));new Set(Array.from(t,e=>Ce(e))),new Set(e.filter(e=>!e.senderTelephone).map(e=>e.senderName??``)).size},[g,_,b,p?.remoteJid]),(0,w.useEffect)(()=>{let e=_?j:r===$?O:null;if(!e||he(e).bodies===0)return;let{maps:t,tileErrors:n}=pe()},[_,j,O,r]),(0,T.jsxs)(E,{repinSignals:[b,D,A],tail:l,children:[x===`error`&&(0,T.jsx)(`div`,{className:`wa-reader-error`,children:`Stream disconnected.`}),!A&&b.length===0&&x===`open`&&(0,T.jsx)(`div`,{className:`wa-reader-placeholder`,children:`No messages in this conversation yet.`}),A&&j.length===0&&(0,T.jsxs)(`div`,{className:`wa-reader-placeholder`,children:[`No matches for "`,m,`".`]}),_?$(j,e,n,`admin`,m,h,!0,g,p?.accountId):r(O,e,n)]})});function ze(e,t){let n=e.split(`;`)[0].trim().toLowerCase();return t.has(n)}var Be=[`audio/ogg;codecs=opus`,`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`];function Ve(){for(let e of Be)if(MediaRecorder.isTypeSupported(e))return e;return``}function He(e){return e.split(`;`)[0]}async function Ue(){return typeof navigator>`u`||!navigator.mediaDevices?.enumerateDevices?[]:(await navigator.mediaDevices.enumerateDevices()).filter(e=>e.kind===`audioinput`)}function We(e){let[t,n]=(0,w.useState)(`idle`),[r,i]=(0,w.useState)(0),[a,o]=(0,w.useState)(null),[s,c]=(0,w.useState)(null),l=(0,w.useRef)(null),u=(0,w.useRef)(null),d=(0,w.useRef)([]),f=(0,w.useRef)(``),p=(0,w.useRef)(null),m=(0,w.useRef)(0),h=(0,w.useRef)(0),g=(0,w.useRef)(null),_=(0,w.useRef)(null),v=(0,w.useRef)(0),y=(0,w.useCallback)(()=>{if(p.current&&=(clearInterval(p.current),null),v.current&&=(cancelAnimationFrame(v.current),0),l.current&&l.current.state!==`inactive`)try{l.current.stop()}catch{}l.current=null,d.current=[],u.current&&=(u.current.getTracks().forEach(e=>e.stop()),null),g.current&&(g.current.close().catch(()=>{}),g.current=null,_.current=null),h.current=0,m.current=0},[]);(0,w.useEffect)(()=>y,[y]);let b=(0,w.useCallback)(()=>{m.current=Date.now(),p.current=setInterval(()=>{let e=Date.now()-m.current,t=h.current+e;i(Math.floor(t/1e3))},200)},[]),x=(0,w.useCallback)(()=>{p.current&&=(clearInterval(p.current),null);let e=Date.now()-m.current;h.current+=e},[]),S=(0,w.useCallback)(()=>{let e=_.current;if(!e)return;let t=new Uint8Array(e.frequencyBinCount),n=()=>{e.getByteTimeDomainData(t),o(new Uint8Array(t)),v.current=requestAnimationFrame(n)};n()},[]),C=(0,w.useCallback)(()=>{v.current&&=(cancelAnimationFrame(v.current),0)},[]),T=e?.onResult,E=(0,w.useCallback)(async e=>{if(!(t!==`idle`&&t!==`error`)){if(c(null),typeof window<`u`&&!window.isSecureContext){n(`error`),c(`Voice recording requires a secure connection (HTTPS). Use your tunnel URL for voice notes.`);return}if(typeof navigator>`u`||!navigator.mediaDevices?.getUserMedia){n(`error`),c(`Voice recording is not supported in this browser.`);return}if(typeof MediaRecorder>`u`){n(`error`),c(`Voice recording is not supported in this browser.`);return}try{let t=e?{audio:{deviceId:{exact:e}}}:{audio:!0},r;try{r=await navigator.mediaDevices.getUserMedia(t)}catch(t){let n=t?.name;if(e&&(n===`OverconstrainedError`||n===`NotFoundError`))r=await navigator.mediaDevices.getUserMedia({audio:!0});else throw t}u.current=r;let a=new AudioContext;g.current=a;let s=a.createMediaStreamSource(r),c=a.createAnalyser();c.fftSize=256,s.connect(c),_.current=c;let p=Ve();f.current=p;let m=new MediaRecorder(r,p?{mimeType:p}:void 0);l.current=m,d.current=[],m.ondataavailable=e=>{e.data.size>0&&d.current.push(e.data)},r.getAudioTracks()[0]?.addEventListener(`ended`,()=>{y(),n(`idle`),i(0),o(null)}),m.start(1e3),n(`recording`),i(0),b(),S(),T?.({ok:!0})}catch(e){y(),n(`error`),e instanceof DOMException?(T?.({ok:!1,name:e.name,message:e.message}),e.name===`NotAllowedError`?c(`Microphone access was denied. Check your browser permissions to enable voice recording.`):e.name===`NotFoundError`?c(`No microphone found. Connect a microphone to use voice recording.`):e.name===`NotReadableError`?c(`The microphone could not be started even though access was granted. The browser reported: ${e.message} (${e.name}).`):c(`Microphone error (${e.name}): ${e.message}`)):(T?.({ok:!1}),c(`Could not start recording.`))}}},[t,y,b,S,T]),D=(0,w.useCallback)(()=>{let e=l.current;e&&(t===`recording`&&e.state===`recording`?(e.pause(),x(),C(),n(`paused`)):t===`paused`&&e.state===`paused`&&(e.resume(),b(),S(),n(`recording`)))},[t,x,b,S,C]),O=(0,w.useCallback)(()=>{t!==`recording`&&t!==`paused`||(y(),n(`idle`),i(0),o(null))},[t,y]),k=(0,w.useCallback)(async()=>{if(t!==`recording`&&t!==`paused`)return null;let e=l.current;if(!e)return null;let r=t===`recording`?Date.now()-m.current:0;return h.current+r<1e3?(O(),null):(n(`sending`),x(),C(),new Promise(t=>{e.onstop=()=>{let r=f.current||e.mimeType||`audio/webm`,a=new Blob(d.current,{type:He(r)});y(),n(`idle`),i(0),o(null),t(a.size>0?a:null)},e.stop()}))},[t,O,x,C,y]);return(0,w.useEffect)(()=>{if(t!==`error`)return;let e=setTimeout(()=>{n(`idle`),c(null)},8e3);return()=>clearTimeout(e)},[t]),{state:t,elapsedSeconds:r,waveform:a,errorMessage:s,start:E,togglePause:D,discard:O,send:k}}export{g as A,x as C,p as D,v as E,h as O,S,y as T,I as _,Ne as a,k as b,Y as c,ke as d,we as f,P as g,N as h,Ae as i,m as k,De as l,B as m,We as n,je as o,V as p,ze as r,Re as s,Ue as t,J as u,F as v,b as w,C as x,re as y};
@@ -1 +0,0 @@
1
- import{B as e}from"./useSubAccountSwitcher-C7TtIbR3.js";var t=e(`wrench`,[[`path`,{d:`M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z`,key:`1ngwbx`}]]);export{t};