@rubytech/create-maxy-code 0.1.576 → 0.1.578

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 (259) hide show
  1. package/package.json +1 -1
  2. package/payload/platform/lib/active-rules/dist/index.d.ts.map +1 -1
  3. package/payload/platform/lib/active-rules/dist/index.js +32 -1
  4. package/payload/platform/lib/active-rules/dist/index.js.map +1 -1
  5. package/payload/platform/lib/active-rules/src/index.test.ts +52 -3
  6. package/payload/platform/lib/active-rules/src/index.ts +36 -2
  7. package/payload/platform/lib/dispatch-read/dist/allocate.d.ts +57 -0
  8. package/payload/platform/lib/dispatch-read/dist/allocate.d.ts.map +1 -0
  9. package/payload/platform/lib/dispatch-read/dist/allocate.js +33 -0
  10. package/payload/platform/lib/dispatch-read/dist/allocate.js.map +1 -0
  11. package/payload/platform/lib/dispatch-read/dist/index.d.ts +2 -0
  12. package/payload/platform/lib/dispatch-read/dist/index.d.ts.map +1 -1
  13. package/payload/platform/lib/dispatch-read/dist/index.js +10 -1
  14. package/payload/platform/lib/dispatch-read/dist/index.js.map +1 -1
  15. package/payload/platform/lib/dispatch-read/src/__tests__/allocate.test.ts +41 -0
  16. package/payload/platform/lib/dispatch-read/src/allocate.ts +89 -0
  17. package/payload/platform/lib/dispatch-read/src/index.ts +14 -0
  18. package/payload/platform/lib/routine-templates/dist/index.d.ts +4 -4
  19. package/payload/platform/lib/routine-templates/dist/index.js +4 -4
  20. package/payload/platform/lib/routine-templates/src/index.ts +4 -4
  21. package/payload/platform/plugins/admin/hooks/__tests__/prompt-optimiser-compliance.test.sh +7 -2
  22. package/payload/platform/plugins/admin/hooks/prompt-optimiser-compliance.sh +8 -2
  23. package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +4 -2
  24. package/payload/platform/plugins/admin/skills/whats-new/SKILL.md +17 -0
  25. package/payload/platform/plugins/cloudflare/mcp/__tests__/portal-visit-status-write.test.ts +333 -22
  26. package/payload/platform/plugins/cloudflare/mcp/__tests__/portal-visits-scope.test.ts +262 -0
  27. package/payload/platform/plugins/cloudflare/skills/data-portal/schema.sql +126 -21
  28. package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/visit-status.ts +142 -2
  29. package/payload/platform/plugins/cloudflare/skills/data-portal/template/functions/api/visits.ts +118 -6
  30. package/payload/platform/plugins/dispatch/PLUGIN.md +2 -0
  31. package/payload/platform/plugins/dispatch/mcp/dist/lib/allocate.d.ts +19 -50
  32. package/payload/platform/plugins/dispatch/mcp/dist/lib/allocate.d.ts.map +1 -1
  33. package/payload/platform/plugins/dispatch/mcp/dist/lib/allocate.js +1 -28
  34. package/payload/platform/plugins/dispatch/mcp/dist/lib/allocate.js.map +1 -1
  35. package/payload/platform/plugins/dispatch/skills/dispatch-page/SKILL.md +45 -6
  36. package/payload/platform/plugins/dispatch/skills/dispatch-page/template/planner.css +60 -0
  37. package/payload/platform/plugins/dispatch/skills/dispatch-page/template/planner.html +13 -0
  38. package/payload/platform/plugins/dispatch/skills/dispatch-page/template/planner.js +203 -5
  39. package/payload/platform/plugins/docs/references/internals.md +1 -1
  40. package/payload/platform/plugins/docs/references/platform.md +2 -0
  41. package/payload/platform/plugins/scheduling/mcp/dist/scripts/check-due-events.js +0 -2
  42. package/payload/platform/plugins/scheduling/mcp/dist/scripts/check-due-events.js.map +1 -1
  43. package/payload/platform/plugins/telegram/mcp/dist/__tests__/webhook-path.test.d.ts +2 -0
  44. package/payload/platform/plugins/telegram/mcp/dist/__tests__/webhook-path.test.d.ts.map +1 -0
  45. package/payload/platform/plugins/telegram/mcp/dist/__tests__/webhook-path.test.js +19 -0
  46. package/payload/platform/plugins/telegram/mcp/dist/__tests__/webhook-path.test.js.map +1 -0
  47. package/payload/platform/plugins/telegram/mcp/dist/__tests__/webhook-register.test.d.ts +2 -0
  48. package/payload/platform/plugins/telegram/mcp/dist/__tests__/webhook-register.test.d.ts.map +1 -0
  49. package/payload/platform/plugins/telegram/mcp/dist/__tests__/webhook-register.test.js +110 -0
  50. package/payload/platform/plugins/telegram/mcp/dist/__tests__/webhook-register.test.js.map +1 -0
  51. package/payload/platform/plugins/telegram/mcp/dist/__tests__/webhook-verdict.test.d.ts +2 -0
  52. package/payload/platform/plugins/telegram/mcp/dist/__tests__/webhook-verdict.test.d.ts.map +1 -0
  53. package/payload/platform/plugins/telegram/mcp/dist/__tests__/webhook-verdict.test.js +22 -0
  54. package/payload/platform/plugins/telegram/mcp/dist/__tests__/webhook-verdict.test.js.map +1 -0
  55. package/payload/platform/plugins/telegram/mcp/dist/index.js +19 -163
  56. package/payload/platform/plugins/telegram/mcp/dist/index.js.map +1 -1
  57. package/payload/platform/plugins/telegram/mcp/dist/lib/account-write.d.ts +9 -0
  58. package/payload/platform/plugins/telegram/mcp/dist/lib/account-write.d.ts.map +1 -1
  59. package/payload/platform/plugins/telegram/mcp/dist/lib/account-write.js +11 -0
  60. package/payload/platform/plugins/telegram/mcp/dist/lib/account-write.js.map +1 -1
  61. package/payload/platform/plugins/telegram/mcp/dist/lib/telegram.d.ts +30 -3
  62. package/payload/platform/plugins/telegram/mcp/dist/lib/telegram.d.ts.map +1 -1
  63. package/payload/platform/plugins/telegram/mcp/dist/lib/telegram.js +29 -4
  64. package/payload/platform/plugins/telegram/mcp/dist/lib/telegram.js.map +1 -1
  65. package/payload/platform/plugins/telegram/mcp/dist/tools/webhook-register.d.ts +33 -0
  66. package/payload/platform/plugins/telegram/mcp/dist/tools/webhook-register.d.ts.map +1 -0
  67. package/payload/platform/plugins/telegram/mcp/dist/tools/webhook-register.js +145 -0
  68. package/payload/platform/plugins/telegram/mcp/dist/tools/webhook-register.js.map +1 -0
  69. package/payload/platform/plugins/telegram/skills/configure/SKILL.md +4 -2
  70. package/payload/platform/services/telegram-channel/dist/notification.d.ts +35 -3
  71. package/payload/platform/services/telegram-channel/dist/notification.d.ts.map +1 -1
  72. package/payload/platform/services/telegram-channel/dist/notification.js +38 -5
  73. package/payload/platform/services/telegram-channel/dist/notification.js.map +1 -1
  74. package/payload/platform/services/telegram-channel/dist/server.js +1 -1
  75. package/payload/platform/services/telegram-channel/dist/server.js.map +1 -1
  76. package/payload/platform/services/webchat-channel/dist/notification.d.ts +2 -1
  77. package/payload/platform/services/webchat-channel/dist/notification.d.ts.map +1 -1
  78. package/payload/platform/services/webchat-channel/dist/notification.js.map +1 -1
  79. package/payload/platform/services/whatsapp-channel/dist/notification.d.ts +2 -2
  80. package/payload/platform/templates/agents/admin/IDENTITY.md +1 -1
  81. package/payload/server/public/activity.html +4 -4
  82. package/payload/server/public/agents.html +3 -3
  83. package/payload/server/public/assets/{AdminLoginScreens-BLGZEaKU.js → AdminLoginScreens-CAZ3DSwA.js} +1 -1
  84. package/payload/server/public/assets/AdminLoginScreens-CAZ3DSwA.js.br +0 -0
  85. package/payload/server/public/assets/AdminLoginScreens-CAZ3DSwA.js.gz +0 -0
  86. package/payload/server/public/assets/{AdminShell-C_M7YE5Z.js → AdminShell-BLs5v0qF.js} +1 -1
  87. package/payload/server/public/assets/AdminShell-BLs5v0qF.js.br +0 -0
  88. package/payload/server/public/assets/AdminShell-BLs5v0qF.js.gz +0 -0
  89. package/payload/server/public/assets/{activity-BL6qbB9a.js → activity-BwPck2yT.js} +1 -1
  90. package/payload/server/public/assets/activity-BwPck2yT.js.br +0 -0
  91. package/payload/server/public/assets/activity-BwPck2yT.js.gz +0 -0
  92. package/payload/server/public/assets/{admin-jnJ3P2u4.js → admin-DjtOoabA.js} +1 -1
  93. package/payload/server/public/assets/admin-DjtOoabA.js.br +0 -0
  94. package/payload/server/public/assets/admin-DjtOoabA.js.gz +0 -0
  95. package/payload/server/public/assets/{agents-BzhfKZDN.js → agents-IQYaRvoh.js} +1 -1
  96. package/payload/server/public/assets/agents-IQYaRvoh.js.br +0 -0
  97. package/payload/server/public/assets/agents-IQYaRvoh.js.gz +0 -0
  98. package/payload/server/public/assets/{browser-C-6io2B9.js → browser-CPG8w8rQ.js} +1 -1
  99. package/payload/server/public/assets/browser-CPG8w8rQ.js.br +0 -0
  100. package/payload/server/public/assets/browser-CPG8w8rQ.js.gz +0 -0
  101. package/payload/server/public/assets/{calendar-Dt3gS88s.js → calendar-CRwrgNdq.js} +1 -1
  102. package/payload/server/public/assets/calendar-CRwrgNdq.js.br +0 -0
  103. package/payload/server/public/assets/calendar-CRwrgNdq.js.gz +0 -0
  104. package/payload/server/public/assets/chat-B7yZ4KLl.js +1 -0
  105. package/payload/server/public/assets/chat-B7yZ4KLl.js.br +3 -0
  106. package/payload/server/public/assets/chat-B7yZ4KLl.js.gz +0 -0
  107. package/payload/server/public/assets/chevron-left-BzKUQqLy.js +1 -0
  108. package/payload/server/public/assets/chevron-left-BzKUQqLy.js.br +0 -0
  109. package/payload/server/public/assets/clock-BafWFNGo.js +1 -0
  110. package/payload/server/public/assets/clock-BafWFNGo.js.br +0 -0
  111. package/payload/server/public/assets/{copy-TkPJgllS.js → copy-JyiMTV0k.js} +1 -1
  112. package/payload/server/public/assets/copy-JyiMTV0k.js.br +0 -0
  113. package/payload/server/public/assets/copy-JyiMTV0k.js.gz +0 -0
  114. package/payload/server/public/assets/data-DHtGCVrl.js +1 -0
  115. package/payload/server/public/assets/data-DHtGCVrl.js.br +0 -0
  116. package/payload/server/public/assets/data-DHtGCVrl.js.gz +0 -0
  117. package/payload/server/public/assets/{file-text-DyAL2DCh.js → file-text-cnHv9ZS6.js} +1 -1
  118. package/payload/server/public/assets/file-text-cnHv9ZS6.js.br +0 -0
  119. package/payload/server/public/assets/file-text-cnHv9ZS6.js.gz +0 -0
  120. package/payload/server/public/assets/{graph-PiNIcCfX.js → graph-lFwEUDSH.js} +1 -1
  121. package/payload/server/public/assets/graph-lFwEUDSH.js.br +0 -0
  122. package/payload/server/public/assets/graph-lFwEUDSH.js.gz +0 -0
  123. package/payload/server/public/assets/{graph-labels-8jKFrLHn.js → graph-labels-C6qUA0vO.js} +1 -1
  124. package/payload/server/public/assets/graph-labels-C6qUA0vO.js.br +0 -0
  125. package/payload/server/public/assets/graph-labels-C6qUA0vO.js.gz +0 -0
  126. package/payload/server/public/assets/{operator-DKGKGzrb.js → operator-BdoEy5mh.js} +1 -1
  127. package/payload/server/public/assets/operator-BdoEy5mh.js.br +0 -0
  128. package/payload/server/public/assets/operator-BdoEy5mh.js.gz +0 -0
  129. package/payload/server/public/assets/{page-DXz_K10G.js → page-DMrnnXNA.js} +1 -1
  130. package/payload/server/public/assets/page-DMrnnXNA.js.br +0 -0
  131. package/payload/server/public/assets/page-DMrnnXNA.js.gz +0 -0
  132. package/payload/server/public/assets/{page-BU5vlY9Y.js → page-DeMikGYL.js} +1 -1
  133. package/payload/server/public/assets/page-DeMikGYL.js.br +0 -0
  134. package/payload/server/public/assets/page-DeMikGYL.js.gz +0 -0
  135. package/payload/server/public/assets/play-D6OAQVJ_.js +1 -0
  136. package/payload/server/public/assets/play-D6OAQVJ_.js.br +0 -0
  137. package/payload/server/public/assets/play-D6OAQVJ_.js.gz +0 -0
  138. package/payload/server/public/assets/{public-BmA3-jLj.js → public-B-X1Cxfw.js} +1 -1
  139. package/payload/server/public/assets/public-B-X1Cxfw.js.br +0 -0
  140. package/payload/server/public/assets/public-B-X1Cxfw.js.gz +0 -0
  141. package/payload/server/public/assets/{rotate-ccw-fCH0LSMq.js → rotate-ccw-DVFvQAHG.js} +1 -1
  142. package/payload/server/public/assets/rotate-ccw-DVFvQAHG.js.br +0 -0
  143. package/payload/server/public/assets/rotate-ccw-DVFvQAHG.js.gz +0 -0
  144. package/payload/server/public/assets/{routines-BeFrmkls.js → routines-CgkkGJaS.js} +1 -1
  145. package/payload/server/public/assets/routines-CgkkGJaS.js.br +0 -0
  146. package/payload/server/public/assets/routines-CgkkGJaS.js.gz +0 -0
  147. package/payload/server/public/assets/{skills-mjls5HBa.js → skills-CW7gVcaG.js} +1 -1
  148. package/payload/server/public/assets/skills-CW7gVcaG.js.br +0 -0
  149. package/payload/server/public/assets/skills-CW7gVcaG.js.gz +0 -0
  150. package/payload/server/public/assets/{tasks-p6puHHD0.js → tasks-Ddjp0Rwh.js} +1 -1
  151. package/payload/server/public/assets/tasks-Ddjp0Rwh.js.br +0 -0
  152. package/payload/server/public/assets/tasks-Ddjp0Rwh.js.gz +0 -0
  153. package/payload/server/public/assets/{triangle-alert-CrZ1ewbd.js → triangle-alert-DUrUutX4.js} +1 -1
  154. package/payload/server/public/assets/triangle-alert-DUrUutX4.js.br +0 -0
  155. package/payload/server/public/assets/triangle-alert-DUrUutX4.js.gz +0 -0
  156. package/payload/server/public/assets/{useCopyFeedback-zOQNrIwd.js → useCopyFeedback-ClVINDrQ.js} +1 -1
  157. package/payload/server/public/assets/useCopyFeedback-ClVINDrQ.js.br +0 -0
  158. package/payload/server/public/assets/useCopyFeedback-ClVINDrQ.js.gz +0 -0
  159. package/payload/server/public/assets/{useMediaQuery-BmG090FR.js → useMediaQuery-BUFkZYRs.js} +1 -1
  160. package/payload/server/public/assets/useMediaQuery-BUFkZYRs.js.br +0 -0
  161. package/payload/server/public/assets/{useMediaQuery-BmG090FR.js.gz → useMediaQuery-BUFkZYRs.js.gz} +0 -0
  162. package/payload/server/public/assets/{useVoiceRecorder-9pf6FFJ-.js → useVoiceRecorder-DnyqQFet.js} +1 -1
  163. package/payload/server/public/assets/useVoiceRecorder-DnyqQFet.js.br +0 -0
  164. package/payload/server/public/assets/useVoiceRecorder-DnyqQFet.js.gz +0 -0
  165. package/payload/server/public/assets/{wrench-k4GYG5rc.js → wrench-BW28s_d0.js} +1 -1
  166. package/payload/server/public/assets/wrench-BW28s_d0.js.br +0 -0
  167. package/payload/server/public/assets/wrench-BW28s_d0.js.gz +0 -0
  168. package/payload/server/public/browser.html +3 -3
  169. package/payload/server/public/calendar.html +6 -6
  170. package/payload/server/public/chat.html +12 -12
  171. package/payload/server/public/data.html +10 -10
  172. package/payload/server/public/graph.html +8 -8
  173. package/payload/server/public/index.html +12 -12
  174. package/payload/server/public/operator.html +13 -13
  175. package/payload/server/public/public.html +12 -12
  176. package/payload/server/public/routines.html +6 -6
  177. package/payload/server/public/skills.html +4 -4
  178. package/payload/server/public/tasks.html +5 -5
  179. package/payload/server/server.js +1014 -375
  180. package/payload/platform/plugins/dispatch/mcp/dist/scripts/converge-visit-instants.d.ts +0 -6
  181. package/payload/platform/plugins/dispatch/mcp/dist/scripts/converge-visit-instants.d.ts.map +0 -1
  182. package/payload/platform/plugins/dispatch/mcp/dist/scripts/converge-visit-instants.js +0 -102
  183. package/payload/platform/plugins/dispatch/mcp/dist/scripts/converge-visit-instants.js.map +0 -1
  184. package/payload/platform/plugins/scheduling/mcp/dist/scripts/__tests__/converge-routine-description.test.d.ts +0 -2
  185. package/payload/platform/plugins/scheduling/mcp/dist/scripts/__tests__/converge-routine-description.test.d.ts.map +0 -1
  186. package/payload/platform/plugins/scheduling/mcp/dist/scripts/__tests__/converge-routine-description.test.js +0 -87
  187. package/payload/platform/plugins/scheduling/mcp/dist/scripts/__tests__/converge-routine-description.test.js.map +0 -1
  188. package/payload/platform/plugins/scheduling/mcp/dist/scripts/__tests__/converge-startdate-utc.test.d.ts +0 -2
  189. package/payload/platform/plugins/scheduling/mcp/dist/scripts/__tests__/converge-startdate-utc.test.d.ts.map +0 -1
  190. package/payload/platform/plugins/scheduling/mcp/dist/scripts/__tests__/converge-startdate-utc.test.js +0 -79
  191. package/payload/platform/plugins/scheduling/mcp/dist/scripts/__tests__/converge-startdate-utc.test.js.map +0 -1
  192. package/payload/platform/plugins/scheduling/mcp/dist/scripts/converge-routine-description.d.ts +0 -35
  193. package/payload/platform/plugins/scheduling/mcp/dist/scripts/converge-routine-description.d.ts.map +0 -1
  194. package/payload/platform/plugins/scheduling/mcp/dist/scripts/converge-routine-description.js +0 -56
  195. package/payload/platform/plugins/scheduling/mcp/dist/scripts/converge-routine-description.js.map +0 -1
  196. package/payload/platform/plugins/scheduling/mcp/dist/scripts/converge-startdate-utc.d.ts +0 -24
  197. package/payload/platform/plugins/scheduling/mcp/dist/scripts/converge-startdate-utc.d.ts.map +0 -1
  198. package/payload/platform/plugins/scheduling/mcp/dist/scripts/converge-startdate-utc.js +0 -87
  199. package/payload/platform/plugins/scheduling/mcp/dist/scripts/converge-startdate-utc.js.map +0 -1
  200. package/payload/server/public/assets/AdminLoginScreens-BLGZEaKU.js.br +0 -0
  201. package/payload/server/public/assets/AdminLoginScreens-BLGZEaKU.js.gz +0 -0
  202. package/payload/server/public/assets/AdminShell-C_M7YE5Z.js.br +0 -0
  203. package/payload/server/public/assets/AdminShell-C_M7YE5Z.js.gz +0 -0
  204. package/payload/server/public/assets/activity-BL6qbB9a.js.br +0 -0
  205. package/payload/server/public/assets/activity-BL6qbB9a.js.gz +0 -0
  206. package/payload/server/public/assets/admin-jnJ3P2u4.js.br +0 -0
  207. package/payload/server/public/assets/admin-jnJ3P2u4.js.gz +0 -0
  208. package/payload/server/public/assets/agents-BzhfKZDN.js.br +0 -0
  209. package/payload/server/public/assets/agents-BzhfKZDN.js.gz +0 -0
  210. package/payload/server/public/assets/browser-C-6io2B9.js.br +0 -0
  211. package/payload/server/public/assets/browser-C-6io2B9.js.gz +0 -0
  212. package/payload/server/public/assets/calendar-Dt3gS88s.js.br +0 -0
  213. package/payload/server/public/assets/calendar-Dt3gS88s.js.gz +0 -0
  214. package/payload/server/public/assets/chat-IUOvVkL-.js +0 -1
  215. package/payload/server/public/assets/chat-IUOvVkL-.js.br +0 -1
  216. package/payload/server/public/assets/chat-IUOvVkL-.js.gz +0 -0
  217. package/payload/server/public/assets/chevron-left-DSzR9zR7.js +0 -1
  218. package/payload/server/public/assets/chevron-left-DSzR9zR7.js.br +0 -0
  219. package/payload/server/public/assets/clock-C5xE5p2I.js +0 -1
  220. package/payload/server/public/assets/clock-C5xE5p2I.js.br +0 -0
  221. package/payload/server/public/assets/copy-TkPJgllS.js.br +0 -0
  222. package/payload/server/public/assets/copy-TkPJgllS.js.gz +0 -0
  223. package/payload/server/public/assets/data-Bhv0Pvfl.js +0 -1
  224. package/payload/server/public/assets/data-Bhv0Pvfl.js.br +0 -0
  225. package/payload/server/public/assets/data-Bhv0Pvfl.js.gz +0 -0
  226. package/payload/server/public/assets/file-text-DyAL2DCh.js.br +0 -0
  227. package/payload/server/public/assets/file-text-DyAL2DCh.js.gz +0 -0
  228. package/payload/server/public/assets/graph-PiNIcCfX.js.br +0 -0
  229. package/payload/server/public/assets/graph-PiNIcCfX.js.gz +0 -0
  230. package/payload/server/public/assets/graph-labels-8jKFrLHn.js.br +0 -0
  231. package/payload/server/public/assets/graph-labels-8jKFrLHn.js.gz +0 -0
  232. package/payload/server/public/assets/operator-DKGKGzrb.js.br +0 -0
  233. package/payload/server/public/assets/operator-DKGKGzrb.js.gz +0 -0
  234. package/payload/server/public/assets/page-BU5vlY9Y.js.br +0 -0
  235. package/payload/server/public/assets/page-BU5vlY9Y.js.gz +0 -0
  236. package/payload/server/public/assets/page-DXz_K10G.js.br +0 -0
  237. package/payload/server/public/assets/page-DXz_K10G.js.gz +0 -0
  238. package/payload/server/public/assets/play-CmSyYrB6.js +0 -1
  239. package/payload/server/public/assets/play-CmSyYrB6.js.br +0 -0
  240. package/payload/server/public/assets/play-CmSyYrB6.js.gz +0 -0
  241. package/payload/server/public/assets/public-BmA3-jLj.js.br +0 -0
  242. package/payload/server/public/assets/public-BmA3-jLj.js.gz +0 -0
  243. package/payload/server/public/assets/rotate-ccw-fCH0LSMq.js.br +0 -0
  244. package/payload/server/public/assets/rotate-ccw-fCH0LSMq.js.gz +0 -0
  245. package/payload/server/public/assets/routines-BeFrmkls.js.br +0 -0
  246. package/payload/server/public/assets/routines-BeFrmkls.js.gz +0 -0
  247. package/payload/server/public/assets/skills-mjls5HBa.js.br +0 -0
  248. package/payload/server/public/assets/skills-mjls5HBa.js.gz +0 -0
  249. package/payload/server/public/assets/tasks-p6puHHD0.js.br +0 -0
  250. package/payload/server/public/assets/tasks-p6puHHD0.js.gz +0 -0
  251. package/payload/server/public/assets/triangle-alert-CrZ1ewbd.js.br +0 -0
  252. package/payload/server/public/assets/triangle-alert-CrZ1ewbd.js.gz +0 -0
  253. package/payload/server/public/assets/useCopyFeedback-zOQNrIwd.js.br +0 -0
  254. package/payload/server/public/assets/useCopyFeedback-zOQNrIwd.js.gz +0 -0
  255. package/payload/server/public/assets/useMediaQuery-BmG090FR.js.br +0 -0
  256. package/payload/server/public/assets/useVoiceRecorder-9pf6FFJ-.js.br +0 -0
  257. package/payload/server/public/assets/useVoiceRecorder-9pf6FFJ-.js.gz +0 -0
  258. package/payload/server/public/assets/wrench-k4GYG5rc.js.br +0 -0
  259. package/payload/server/public/assets/wrench-k4GYG5rc.js.gz +0 -0
@@ -1,2 +1,2 @@
1
- import{o as e,t}from"./chunk-BycB0eMI.js";import{i as n,n as r,t as i}from"./jsx-runtime-YcUntiud.js";import{F as a,G as o,L as s,M as c,O as l,V as u,Y as d,Z as f,_ as p,f as m,it as h,j as g,k as _,m as v,v as y}from"./useMediaQuery-BmG090FR.js";import{A as b,m as x,t as S}from"./AdminShell-C_M7YE5Z.js";import{t as C}from"./clock-C5xE5p2I.js";import{t as w}from"./triangle-alert-CrZ1ewbd.js";import{t as ee}from"./wrench-k4GYG5rc.js";import{r as T}from"./file-download-B7zwa78w.js";var te=f(`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`}]]),ne=f(`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`}]]),E=f(`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`}]]),D=r(),O=e(n(),1),k=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function A(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 j(e){return String(e).padStart(2,`0`)}function M(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`:`${k[e%7]} to ${k[n%7]}`}let n=e.split(`,`);return n.length>0&&n.every(e=>/^\d+$/.test(e)&&Number(e)<=7)?n.map(e=>k[Number(e)%7]).join(`, `):`invalid`}function N(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=A(n,59),c=A(r,23);if(!s||!c)return e;let l=M(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}, ${j(c.value)}:00 to ${j(c.value)}:59${u}`:`${e}, ${j(c.rangeStart)}:00 to ${j(d(c))}:00${u}`}if(c.kind===`step`){let e=j(s.value),t=s.value===0?``:` at :${e}`;return c.rangeStart===null?`Every ${c.step} hours${t}${u}`:c.step===1?`Hourly, ${j(c.rangeStart)}:${e} to ${j(c.rangeEnd)}:${e}${u}`:`Every ${c.step} hours, ${j(c.rangeStart)}:${e} to ${j(d(c))}:${e}${u}`}if(c.kind===`any`)return`${s.value===0?`Every hour`:`Every hour at :${j(s.value)}`}${u}`;let f=`${j(c.value)}:${j(s.value)}`;return i===`*`?l?`${l} at ${f}`:`Daily at ${f}`:`Monthly on day ${Number(i)} at ${f}`}var P={timeMode:`at`,minute:0,hour:9,interval:1,window:null,dayMode:`every`,weekdays:[],dayOfMonth:1};function F(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 I(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=A(n,59),c=A(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=F(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{...P,...f,timeMode:`everyMinutes`,minute:0,interval:e,window:t}}return c.kind===`fixed`?{...P,...f,timeMode:`at`,minute:s.value,hour:c.value}:c.kind===`any`?{...P,...f,timeMode:`everyHours`,minute:s.value,interval:1,window:null}:{...P,...f,timeMode:`everyHours`,minute:s.value,interval:c.step,window:c.rangeStart===null?null:{start:c.rangeStart,end:c.rangeEnd}}}function L(e){return e.dayMode===`dayOfMonth`?[String(e.dayOfMonth),`*`]:e.dayMode===`weekdays`&&e.weekdays.length>0?[`*`,[...e.weekdays].sort((e,t)=>e-t).join(`,`)]:[`*`,`*`]}function R(e){let[t,n]=L(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 z={scheduled:`live`,suspended:`stood-down`,due:`inert`,cancelled:`inert`,completed:`inert`};function re(e){return e==null||!Object.hasOwn(z,e)?`unknown`:z[e]}var B={scheduled:{control:`suspend`,note:null},suspended:{control:`resume`,note:null},due:{control:`none`,note:`This one-time routine has already been dispatched. It will not run again.`},cancelled:{control:`none`,note:`This routine was cancelled and cannot be restarted. Delete it, or create a new one.`},completed:{control:`none`,note:`This routine has finished and will not run again.`}},ie={control:`none`,note:`This routine's status is not one this dashboard recognises, so no start or stop is offered.`};function ae(e){return e==null||!Object.hasOwn(B,e)?ie:B[e]}var V={finished:`live`,gated:`live`,started:`in-flight`,accepted:`in-flight`,open:`in-flight`,failed:`error`,"no-destination":`warning`};function oe(e){return e==null||!Object.hasOwn(V,e)?`unknown`:V[e]}function H(e){return e===`gated`?`skipped: no work`:e??`unknown`}var U=i(),se=[{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`}],W=Array.from({length:24},(e,t)=>t),G=e=>String(e).padStart(2,`0`),K={timeMode:`at`,minute:0,hour:9,interval:1,window:null,dayMode:`every`,weekdays:[],dayOfMonth:1};function ce({recurrence:e,onChange:t,disabled:n}){let r=e?I(e):K,[i,a]=(0,O.useState)(r??K),[o]=(0,O.useState)(e!=null&&r==null),[s,c]=(0,O.useState)(e??``);if((0,O.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,U.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,U.jsx)(`span`,{children:`Schedule (advanced)`}),(0,U.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,U.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(R(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,U.jsxs)(`div`,{className:`routine-sched`,children:[(0,U.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,U.jsx)(`span`,{children:`How often`}),(0,U.jsxs)(`select`,{"aria-label":`How often`,value:i.timeMode,disabled:n,onChange:e=>u(e.target.value),children:[(0,U.jsx)(`option`,{value:`at`,children:`At a time of day`}),(0,U.jsx)(`option`,{value:`everyMinutes`,children:`Every few minutes`}),(0,U.jsx)(`option`,{value:`everyHours`,children:`Every few hours`})]})]}),i.timeMode===`at`&&(0,U.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,U.jsx)(`span`,{children:`Time of day`}),(0,U.jsx)(`input`,{type:`time`,"aria-label":`Time of day`,value:`${G(i.hour)}:${G(i.minute)}`,disabled:n,onChange:e=>f(e.target.value)})]}),i.timeMode===`everyMinutes`&&(0,U.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,U.jsx)(`span`,{children:`Minutes between runs`}),(0,U.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,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,U.jsx)(`span`,{children:`Hours between runs`}),(0,U.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,U.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,U.jsx)(`span`,{children:`Minute of the hour`}),(0,U.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,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`label`,{className:`cal-modal-field routine-sched-check`,children:[(0,U.jsx)(`input`,{type:`checkbox`,"aria-label":`Only between certain hours`,checked:i.window!==null,disabled:n,onChange:e=>m(e.target.checked)}),(0,U.jsx)(`span`,{children:`Only between certain hours`})]}),i.window!==null&&(0,U.jsxs)(`div`,{className:`routine-sched-row`,children:[(0,U.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,U.jsx)(`span`,{children:`From hour`}),(0,U.jsx)(`select`,{"aria-label":`From hour`,value:i.window.start,disabled:n,onChange:e=>h(`start`,e.target.value),children:W.map(e=>(0,U.jsxs)(`option`,{value:e,children:[G(e),`:00`]},e))})]}),(0,U.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,U.jsx)(`span`,{children:`To hour`}),(0,U.jsx)(`select`,{"aria-label":`To hour`,value:i.window.end,disabled:n,onChange:e=>h(`end`,e.target.value),children:W.map(e=>(0,U.jsxs)(`option`,{value:e,children:[G(e),`:00`]},e))})]})]})]}),(0,U.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,U.jsx)(`span`,{children:`Which days`}),(0,U.jsxs)(`select`,{"aria-label":`Which days`,value:i.dayMode,disabled:n,onChange:e=>d(e.target.value),children:[(0,U.jsx)(`option`,{value:`every`,children:`Every day`}),(0,U.jsx)(`option`,{value:`weekdays`,children:`Specific days`}),i.timeMode===`at`&&(0,U.jsx)(`option`,{value:`dayOfMonth`,children:`A day of the month`})]})]}),i.dayMode===`weekdays`&&(0,U.jsxs)(`div`,{className:`cal-modal-field`,children:[(0,U.jsx)(`span`,{children:`Days`}),(0,U.jsx)(`div`,{className:`routine-weekdays`,children:se.map(e=>(0,U.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,U.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,U.jsx)(`span`,{children:`Day of month`}),(0,U.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,U.jsx)(`option`,{value:e,children:e},e))})]})]})}function q(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 le(e){if(e.name)return`${e.name} · ${e.label}`;let t=e.channel===`whatsapp`?q(e.destination):e.destination;return`${e.label} · ${t}`}function ue({eventStatus:e}){let t=re(e);return(0,U.jsx)(`span`,{className:`routine-status-dot is-${t}`,"data-state":t,"aria-hidden":`true`})}function de(e){return e.agentChannel==null?e.actionPlugin==null?`trigger`:`deterministic`:e.gateTool==null?`agent-every-fire`:`checked-agent`}var fe={"checked-agent":`checks first, model only when there is work`,"agent-every-fire":`model every fire`,deterministic:`runs a tool, no model`,trigger:null};function pe(e){return e.agentChannel&&e.agentDestination&&e.agentPrompt?`model`:e.actionPlugin&&e.actionTool?`tool`:`none`}function me(e){let t=e.filter(e=>e.eventStatus===`scheduled`&&e.recurrence!=null),n={live:t.length,model:0,tool:0,none:0};for(let e of t)n[pe(e)]++;return n}function he(e){if(!e)return[];let t;try{t=JSON.parse(e)}catch{return[]}let n=t?.checks;return Array.isArray(n)?n.flatMap(e=>{if(typeof e!=`object`||!e)return[];let t=e;return typeof t.type==`string`?[{kind:t.type,target:J(t.type,t)}]:[]}):[]}function J(e,t){let n=e=>typeof t[e]==`string`?t[e]:null;if(e===`mail`){let e=n(`mailbox`);if(e===null)return null;let t=n(`folder`);return t?`${e}/${t}`:e}return e===`d1`?n(`database`):e===`whatsapp`?n(`scope`):e===`calendar`?n(`connector`):null}function ge(e,t){if(!e)return null;let n=Date.parse(e);if(!Number.isFinite(n))return null;let r=Math.max(t-n,0);return r<6e4?`${Math.round(r/1e3)}s ago`:r<36e5?`${Math.round(r/6e4)}m ago`:`${Math.round(r/36e5)}h ago`}function _e(e,t){if(!e)return`—`;let n=Date.parse(e);return Number.isFinite(n)?p(new Date(n).toISOString(),t):e}function ve(e){return e?e.split(`
1
+ import{o as e,t}from"./chunk-BycB0eMI.js";import{i as n,n as r,t as i}from"./jsx-runtime-YcUntiud.js";import{F as a,G as o,L as s,M as c,O as l,V as u,Y as d,Z as f,_ as p,f as m,it as h,j as g,k as _,m as v,v as y}from"./useMediaQuery-BUFkZYRs.js";import{A as b,m as x,t as S}from"./AdminShell-BLs5v0qF.js";import{t as C}from"./clock-BafWFNGo.js";import{t as w}from"./triangle-alert-DUrUutX4.js";import{t as ee}from"./wrench-BW28s_d0.js";import{r as T}from"./file-download-B7zwa78w.js";var te=f(`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`}]]),ne=f(`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`}]]),E=f(`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`}]]),D=r(),O=e(n(),1),k=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function A(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 j(e){return String(e).padStart(2,`0`)}function M(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`:`${k[e%7]} to ${k[n%7]}`}let n=e.split(`,`);return n.length>0&&n.every(e=>/^\d+$/.test(e)&&Number(e)<=7)?n.map(e=>k[Number(e)%7]).join(`, `):`invalid`}function N(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=A(n,59),c=A(r,23);if(!s||!c)return e;let l=M(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}, ${j(c.value)}:00 to ${j(c.value)}:59${u}`:`${e}, ${j(c.rangeStart)}:00 to ${j(d(c))}:00${u}`}if(c.kind===`step`){let e=j(s.value),t=s.value===0?``:` at :${e}`;return c.rangeStart===null?`Every ${c.step} hours${t}${u}`:c.step===1?`Hourly, ${j(c.rangeStart)}:${e} to ${j(c.rangeEnd)}:${e}${u}`:`Every ${c.step} hours, ${j(c.rangeStart)}:${e} to ${j(d(c))}:${e}${u}`}if(c.kind===`any`)return`${s.value===0?`Every hour`:`Every hour at :${j(s.value)}`}${u}`;let f=`${j(c.value)}:${j(s.value)}`;return i===`*`?l?`${l} at ${f}`:`Daily at ${f}`:`Monthly on day ${Number(i)} at ${f}`}var P={timeMode:`at`,minute:0,hour:9,interval:1,window:null,dayMode:`every`,weekdays:[],dayOfMonth:1};function F(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 I(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=A(n,59),c=A(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=F(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{...P,...f,timeMode:`everyMinutes`,minute:0,interval:e,window:t}}return c.kind===`fixed`?{...P,...f,timeMode:`at`,minute:s.value,hour:c.value}:c.kind===`any`?{...P,...f,timeMode:`everyHours`,minute:s.value,interval:1,window:null}:{...P,...f,timeMode:`everyHours`,minute:s.value,interval:c.step,window:c.rangeStart===null?null:{start:c.rangeStart,end:c.rangeEnd}}}function L(e){return e.dayMode===`dayOfMonth`?[String(e.dayOfMonth),`*`]:e.dayMode===`weekdays`&&e.weekdays.length>0?[`*`,[...e.weekdays].sort((e,t)=>e-t).join(`,`)]:[`*`,`*`]}function R(e){let[t,n]=L(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 z={scheduled:`live`,suspended:`stood-down`,due:`inert`,cancelled:`inert`,completed:`inert`};function re(e){return e==null||!Object.hasOwn(z,e)?`unknown`:z[e]}var B={scheduled:{control:`suspend`,note:null},suspended:{control:`resume`,note:null},due:{control:`none`,note:`This one-time routine has already been dispatched. It will not run again.`},cancelled:{control:`none`,note:`This routine was cancelled and cannot be restarted. Delete it, or create a new one.`},completed:{control:`none`,note:`This routine has finished and will not run again.`}},ie={control:`none`,note:`This routine's status is not one this dashboard recognises, so no start or stop is offered.`};function ae(e){return e==null||!Object.hasOwn(B,e)?ie:B[e]}var V={finished:`live`,gated:`live`,started:`in-flight`,accepted:`in-flight`,open:`in-flight`,failed:`error`,"no-destination":`warning`};function oe(e){return e==null||!Object.hasOwn(V,e)?`unknown`:V[e]}function H(e){return e===`gated`?`skipped: no work`:e??`unknown`}var U=i(),se=[{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`}],W=Array.from({length:24},(e,t)=>t),G=e=>String(e).padStart(2,`0`),K={timeMode:`at`,minute:0,hour:9,interval:1,window:null,dayMode:`every`,weekdays:[],dayOfMonth:1};function ce({recurrence:e,onChange:t,disabled:n}){let r=e?I(e):K,[i,a]=(0,O.useState)(r??K),[o]=(0,O.useState)(e!=null&&r==null),[s,c]=(0,O.useState)(e??``);if((0,O.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,U.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,U.jsx)(`span`,{children:`Schedule (advanced)`}),(0,U.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,U.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(R(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,U.jsxs)(`div`,{className:`routine-sched`,children:[(0,U.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,U.jsx)(`span`,{children:`How often`}),(0,U.jsxs)(`select`,{"aria-label":`How often`,value:i.timeMode,disabled:n,onChange:e=>u(e.target.value),children:[(0,U.jsx)(`option`,{value:`at`,children:`At a time of day`}),(0,U.jsx)(`option`,{value:`everyMinutes`,children:`Every few minutes`}),(0,U.jsx)(`option`,{value:`everyHours`,children:`Every few hours`})]})]}),i.timeMode===`at`&&(0,U.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,U.jsx)(`span`,{children:`Time of day`}),(0,U.jsx)(`input`,{type:`time`,"aria-label":`Time of day`,value:`${G(i.hour)}:${G(i.minute)}`,disabled:n,onChange:e=>f(e.target.value)})]}),i.timeMode===`everyMinutes`&&(0,U.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,U.jsx)(`span`,{children:`Minutes between runs`}),(0,U.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,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,U.jsx)(`span`,{children:`Hours between runs`}),(0,U.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,U.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,U.jsx)(`span`,{children:`Minute of the hour`}),(0,U.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,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`label`,{className:`cal-modal-field routine-sched-check`,children:[(0,U.jsx)(`input`,{type:`checkbox`,"aria-label":`Only between certain hours`,checked:i.window!==null,disabled:n,onChange:e=>m(e.target.checked)}),(0,U.jsx)(`span`,{children:`Only between certain hours`})]}),i.window!==null&&(0,U.jsxs)(`div`,{className:`routine-sched-row`,children:[(0,U.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,U.jsx)(`span`,{children:`From hour`}),(0,U.jsx)(`select`,{"aria-label":`From hour`,value:i.window.start,disabled:n,onChange:e=>h(`start`,e.target.value),children:W.map(e=>(0,U.jsxs)(`option`,{value:e,children:[G(e),`:00`]},e))})]}),(0,U.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,U.jsx)(`span`,{children:`To hour`}),(0,U.jsx)(`select`,{"aria-label":`To hour`,value:i.window.end,disabled:n,onChange:e=>h(`end`,e.target.value),children:W.map(e=>(0,U.jsxs)(`option`,{value:e,children:[G(e),`:00`]},e))})]})]})]}),(0,U.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,U.jsx)(`span`,{children:`Which days`}),(0,U.jsxs)(`select`,{"aria-label":`Which days`,value:i.dayMode,disabled:n,onChange:e=>d(e.target.value),children:[(0,U.jsx)(`option`,{value:`every`,children:`Every day`}),(0,U.jsx)(`option`,{value:`weekdays`,children:`Specific days`}),i.timeMode===`at`&&(0,U.jsx)(`option`,{value:`dayOfMonth`,children:`A day of the month`})]})]}),i.dayMode===`weekdays`&&(0,U.jsxs)(`div`,{className:`cal-modal-field`,children:[(0,U.jsx)(`span`,{children:`Days`}),(0,U.jsx)(`div`,{className:`routine-weekdays`,children:se.map(e=>(0,U.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,U.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,U.jsx)(`span`,{children:`Day of month`}),(0,U.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,U.jsx)(`option`,{value:e,children:e},e))})]})]})}function q(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 le(e){if(e.name)return`${e.name} · ${e.label}`;let t=e.channel===`whatsapp`?q(e.destination):e.destination;return`${e.label} · ${t}`}function ue({eventStatus:e}){let t=re(e);return(0,U.jsx)(`span`,{className:`routine-status-dot is-${t}`,"data-state":t,"aria-hidden":`true`})}function de(e){return e.agentChannel==null?e.actionPlugin==null?`trigger`:`deterministic`:e.gateTool==null?`agent-every-fire`:`checked-agent`}var fe={"checked-agent":`checks first, model only when there is work`,"agent-every-fire":`model every fire`,deterministic:`runs a tool, no model`,trigger:null};function pe(e){return e.agentChannel&&e.agentDestination&&e.agentPrompt?`model`:e.actionPlugin&&e.actionTool?`tool`:`none`}function me(e){let t=e.filter(e=>e.eventStatus===`scheduled`&&e.recurrence!=null),n={live:t.length,model:0,tool:0,none:0};for(let e of t)n[pe(e)]++;return n}function he(e){if(!e)return[];let t;try{t=JSON.parse(e)}catch{return[]}let n=t?.checks;return Array.isArray(n)?n.flatMap(e=>{if(typeof e!=`object`||!e)return[];let t=e;return typeof t.type==`string`?[{kind:t.type,target:J(t.type,t)}]:[]}):[]}function J(e,t){let n=e=>typeof t[e]==`string`?t[e]:null;if(e===`mail`){let e=n(`mailbox`);if(e===null)return null;let t=n(`folder`);return t?`${e}/${t}`:e}return e===`d1`?n(`database`):e===`whatsapp`?n(`scope`):e===`calendar`?n(`connector`):null}function ge(e,t){if(!e)return null;let n=Date.parse(e);if(!Number.isFinite(n))return null;let r=Math.max(t-n,0);return r<6e4?`${Math.round(r/1e3)}s ago`:r<36e5?`${Math.round(r/6e4)}m ago`:`${Math.round(r/36e5)}h ago`}function _e(e,t){if(!e)return`—`;let n=Date.parse(e);return Number.isFinite(n)?p(new Date(n).toISOString(),t):e}function ve(e){return e?e.split(`
2
2
  `).filter(e=>e.trim()!==``).reverse():[]}function Y({routine:e,adminFetch:t,onClose:n,onSaved:r,onDeleted:i,onViewRuns:a}){let{zone:o}=y(),[l,d]=(0,O.useState)(!1),[f,p]=(0,O.useState)(!1),[h,_]=(0,O.useState)(null),[b,S]=(0,O.useState)(e),[w,T]=(0,O.useState)(!1),D=b.agentChannel!=null,k=de(b),A=he(b.gateArgs),j=ge(b.gateLastCommitAt,Date.now()),M=ae(b.eventStatus),P=M.control===`resume`,[F,I]=(0,O.useState)(!1),[L,R]=(0,O.useState)(e.agentPrompt??``),[z,re]=(0,O.useState)(e.name??``),[B,ie]=(0,O.useState)(e.description??``),[V,oe]=(0,O.useState)(e.recurrence),[H,se]=(0,O.useState)(e.agentChannel??``),[W,G]=(0,O.useState)(e.agentDestination??``),[K,q]=(0,O.useState)(null),[pe,me]=(0,O.useState)(null),J=D||b.actionPlugin==null,Y=ve(b.notes);(0,O.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!f&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[f,n]),(0,O.useEffect)(()=>{if(!l||!J||K!==null)return;let e=!1;return t(`/api/admin/dispatch-destinations`).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return await e.json()}).then(t=>{e||q(t.destinations)}).catch(t=>{e||(q([]),me(t instanceof Error?t.message:`Could not load destinations`))}),()=>{e=!0}},[l,J,K,t]);let X=(K??[]).filter(e=>e.channel===H),Z=H.length>0&&W.length>0,ye=z.trim().length===0&&(b.name??``).length>0||H.length>0&&W.length===0||Z&&L.trim().length===0,be=(0,O.useCallback)(()=>{let e={},t=H.length>0&&W.length>0,n=z.trim();n!==(b.name??``)&&(e.name=n),(D||t)&&L!==(b.agentPrompt??``)&&(e.agentPrompt=L);let r=B.trim().length>0?B:null;return r!==(b.description??null)&&(e.description=r),V!=null&&V!==(b.recurrence??null)&&(e.recurrence=V),t&&(H!==(b.agentChannel??``)||W!==(b.agentDestination??``))?(e.agentChannel=H,e.agentDestination=W):!t&&H===``&&(b.agentChannel??``)!==``&&(e.agentChannel=null,e.agentDestination=null),e},[D,z,L,B,V,H,W,b]),Q=(0,O.useCallback)(async()=>{let n=be();if(Object.keys(n).length===0){d(!1);return}p(!0),_(null);try{let i=await t(`/api/admin/routines/${encodeURIComponent(e.eventId)}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(n)});if(!i.ok){let e=await i.json().catch(()=>({}));throw Error(e.error??`HTTP ${i.status}`)}let a=await i.json();S(a.routine),re(a.routine.name??``),R(a.routine.agentPrompt??``),ie(a.routine.description??``),oe(a.routine.recurrence),se(a.routine.agentChannel??``),G(a.routine.agentDestination??``),r(a.routine),d(!1)}catch(e){_(e instanceof Error?e.message:`Save failed`)}finally{p(!1)}},[t,be,e.eventId,r]),xe=(0,O.useCallback)(async()=>{if(f)return;if(!F){T(!1),I(!0);return}let n=P?`resume`:`suspend`;p(!0),_(null);try{let i=await t(`/api/admin/routines/${encodeURIComponent(e.eventId)}/${n}`,{method:`POST`});if(!i.ok){let e=await i.json().catch(()=>({}));throw Error(e.error??`HTTP ${i.status}`)}let a=await i.json();S(a.routine),r(a.routine),I(!1)}catch(e){_(e instanceof Error?e.message:`${n} failed`),I(!1)}finally{p(!1)}},[t,f,F,P,e.eventId,r]),Se=(0,O.useCallback)(async()=>{if(!f){if(!w){I(!1),T(!0);return}p(!0),_(null);try{let n=await t(`/api/admin/routines/${encodeURIComponent(e.eventId)}`,{method:`DELETE`});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??`HTTP ${n.status}`)}i(e.eventId)}catch(e){_(e instanceof Error?e.message:`Delete failed`),T(!1)}finally{p(!1)}}},[t,f,w,e.eventId,i]);return(0,U.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{f||n()},children:(0,U.jsxs)(`div`,{className:`cal-modal ${!l||D||Z?`cal-modal-wide`:`cal-modal-dispatch`}`,role:`dialog`,"aria-modal":`true`,"aria-label":l?`Edit routine`:`Routine detail`,onClick:e=>e.stopPropagation(),children:[(0,U.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,U.jsxs)(`span`,{className:`cal-modal-kind`,children:[(0,U.jsx)(x,{size:13}),` Routine`]}),(0,U.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:n,"aria-label":`Close`,autoFocus:!0,disabled:f,children:(0,U.jsx)(g,{size:16})})]}),!l&&(0,U.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,U.jsx)(`div`,{className:`cal-modal-title`,children:b.name??`Untitled routine`}),(0,U.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,U.jsx)(C,{size:14}),(0,U.jsx)(`span`,{children:b.recurrence?N(b.recurrence):`One-time`})]}),(0,U.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,U.jsx)(ue,{eventStatus:b.eventStatus}),(0,U.jsxs)(`span`,{children:[`Status: `,b.eventStatus??`unknown`]})]}),(0,U.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,U.jsxs)(`span`,{children:[`Next run: `,_e(b.nextRun,o)]})}),(0,U.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,U.jsx)(E,{size:14}),(0,U.jsxs)(`span`,{children:[`Last run: `,_e(b.lastTriggered,o),b.lastDispatchResult?` (${b.lastDispatchResult})`:``]})]}),b.description&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,U.jsx)(`span`,{children:`Description`})}),(0,U.jsx)(`div`,{className:`cal-modal-row cal-modal-row-top routine-prose`,children:(0,U.jsx)(`span`,{children:b.description})})]}),fe[k]&&(0,U.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,"data-testid":`routine-mode`,children:[(0,U.jsx)(x,{size:14}),(0,U.jsxs)(`span`,{children:[fe[k],k===`agent-every-fire`&&b.gateWaived?`: ${b.gateWaived}`:``]})]}),b.gateClassified===!1&&b.gateTool==null&&(0,U.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,"data-testid":`gate-unclassified`,children:(0,U.jsx)(`span`,{children:`No check is set and no reason is recorded, so every fire spends a model turn.`})}),D?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,U.jsx)(v,{channel:b.agentChannel,size:14}),(0,U.jsxs)(`span`,{children:[m[b.agentChannel]??b.agentChannel,` to `,b.agentDestination??`—`]})]}),b.gateTool!=null&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,U.jsx)(`span`,{children:`Checks before the agent runs`})}),(0,U.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,U.jsx)(ee,{size:14}),(0,U.jsxs)(`span`,{children:[b.gatePlugin,`.`,b.gateTool]})]}),A.map((e,t)=>(0,U.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,"data-testid":`gate-check`,children:(0,U.jsxs)(`span`,{children:[e.kind,e.target?` · ${e.target}`:``]})},t)),b.lastTriggered!=null&&(0,U.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,"data-testid":`gate-commit-age`,children:(0,U.jsx)(`span`,{children:j===null?`This gate has never committed, so it reports work on every fire.`:`Checks last committed ${j} (${_e(b.gateLastCommitAt,o)})`})})]}),(0,U.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,U.jsx)(`span`,{children:`Instruction sent to the agent`})}),(0,U.jsx)(`div`,{className:`cal-modal-row cal-modal-row-top routine-prose`,children:(0,U.jsx)(`span`,{children:b.agentPrompt??`No instruction sent to the agent.`})})]}):b.actionPlugin?(0,U.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,U.jsx)(ee,{size:14}),(0,U.jsxs)(`span`,{children:[b.actionPlugin,`.`,b.actionTool,b.actionArgs?` ${b.actionArgs}`:``]})]}):(0,U.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,U.jsx)(C,{size:14}),(0,U.jsx)(`span`,{children:`Scheduled trigger (no dispatch)`})]}),Y.length===0?(0,U.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,U.jsx)(E,{size:14}),(0,U.jsx)(`span`,{children:`No history recorded.`})]}):(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,U.jsx)(E,{size:14}),(0,U.jsxs)(`span`,{children:[`History (`,Y.length,` `,Y.length===1?`entry`:`entries`,`)`]})]}),(0,U.jsx)(`div`,{className:`routine-history`,children:Y.map((e,t)=>(0,U.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:e},t))})]})]}),l&&(0,U.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,U.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,U.jsx)(`span`,{children:`Name`}),(0,U.jsx)(`input`,{type:`text`,value:z,onChange:e=>re(e.target.value),disabled:f,maxLength:200,placeholder:`The routine's title, shown on the card`})]}),J&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,U.jsx)(`span`,{children:`Send to`}),(0,U.jsxs)(`div`,{className:`cal-modal-field-inline`,children:[(0,U.jsxs)(`select`,{value:H,disabled:f,onChange:e=>{se(e.target.value),G(``)},children:[(0,U.jsx)(`option`,{value:``,children:`None (no dispatch)`}),(0,U.jsx)(`option`,{value:`whatsapp`,children:`WhatsApp`}),(0,U.jsx)(`option`,{value:`telegram`,children:`Telegram`})]}),H!==``&&(0,U.jsx)(v,{channel:H,size:16})]})]}),H!==``&&(0,U.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,U.jsx)(`span`,{children:`Destination`}),(0,U.jsxs)(`select`,{value:W,disabled:f||K===null,onChange:e=>G(e.target.value),children:[(0,U.jsx)(`option`,{value:``,children:K===null?`Loading destinations`:X.length===0?`No registered destinations`:`Choose a destination`}),W!==``&&!X.some(e=>e.destination===W)&&(0,U.jsxs)(`option`,{value:W,children:[W,` (not in the current list)`]}),X.map(e=>(0,U.jsx)(`option`,{value:e.destination,children:le(e)},e.destination))]})]}),pe&&(0,U.jsxs)(`div`,{className:`cal-modal-error`,children:[`Could not load destinations: `,pe]})]}),(0,U.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,U.jsx)(`span`,{children:`Description`}),(0,U.jsx)(`input`,{type:`text`,value:B,onChange:e=>ie(e.target.value),disabled:f,placeholder:`One line: what this routine is for`})]}),(D||Z)&&(0,U.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,U.jsx)(`span`,{children:`Instruction sent to the agent`}),(0,U.jsx)(`textarea`,{className:`cal-modal-textarea`,value:L,onChange:e=>R(e.target.value),disabled:f,rows:16,placeholder:`What should the agent do when this routine fires?`})]}),(0,U.jsx)(ce,{recurrence:b.recurrence,onChange:oe,disabled:f})]}),h&&(0,U.jsx)(`div`,{className:`cal-modal-error`,children:h}),(0,U.jsxs)(`div`,{className:`cal-modal-actions`,children:[!l&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>{T(!1),I(!1),d(!0)},disabled:f,children:[(0,U.jsx)(s,{size:14}),` Edit`]}),(0,U.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>a(b),disabled:f,children:[(0,U.jsx)(E,{size:14}),` Runs`]}),M.control===`none`?(0,U.jsx)(`span`,{className:`cal-modal-confirm-text`,children:M.note}):(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:xe,disabled:f,children:[f&&F?(0,U.jsx)(u,{size:14,className:`spin`}):P?(0,U.jsx)(ne,{size:14}):(0,U.jsx)(te,{size:14}),F?P?`Confirm resume`:`Confirm suspend`:P?`Resume`:`Suspend`]}),F&&(0,U.jsx)(`span`,{className:`cal-modal-confirm-text`,children:P?`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,U.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:Se,disabled:f,children:[f&&w?(0,U.jsx)(u,{size:14,className:`spin`}):(0,U.jsx)(c,{size:14}),w?`Confirm delete`:`Delete`]})]}),l&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-primary`,onClick:Q,disabled:f||ye,children:[f?(0,U.jsx)(u,{size:14,className:`spin`}):null,` Save`]}),(0,U.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>{d(!1),_(null)},disabled:f,children:`Cancel`})]})]})]})})}function X(e,t){if(!e)return`—`;let n=Date.parse(e);return Number.isFinite(n)?p(new Date(n).toISOString(),t):e}function Z(e){return e===null?`—`:e<1e3?`${e} ms`:`${(e/1e3).toFixed(1)} s`}function ye({run:e,routineName:t,onClose:n}){let{zone:r}=y();return(0,O.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,U.jsx)(`div`,{className:`cal-modal-overlay`,onClick:n,children:(0,U.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":`Run detail`,onClick:e=>e.stopPropagation(),children:[(0,U.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,U.jsx)(`span`,{className:`cal-modal-kind`,children:`Run`}),(0,U.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:n,"aria-label":`Close`,autoFocus:!0,children:(0,U.jsx)(g,{size:16})})]}),(0,U.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,U.jsx)(`div`,{className:`cal-modal-title`,children:t??`Untitled routine`}),e.outputExcerpt!==null&&(0,U.jsx)(`div`,{className:`cal-modal-row cal-modal-row-top routine-prose`,"data-testid":`run-output`,children:(0,U.jsx)(`span`,{children:e.outputExcerpt})}),e.outputExcerpt===null&&e.status===`finished`&&(0,U.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,"data-testid":`run-output-none`,children:(0,U.jsx)(`span`,{children:`This run finished without sending anything.`})}),(0,U.jsx)(`div`,{className:`cal-modal-row`,children:(0,U.jsx)(`span`,{children:H(e.status)})}),(0,U.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,U.jsxs)(`span`,{children:[`Due: `,X(e.scheduledFor,r)]})}),(0,U.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,U.jsxs)(`span`,{children:[`Started: `,X(e.startedAt,r)]})}),(0,U.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,U.jsxs)(`span`,{children:[`Dispatch ended: `,X(e.endedAt,r),` (`,Z(e.ranMs),`)`]})}),(0,U.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,U.jsxs)(`span`,{children:[`Output seen: `,X(e.finishedAt,r)]})}),(0,U.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,U.jsxs)(`span`,{children:[`Sent to: `,e.target,` · `,e.mode,` · `,e.kind]})}),(0,U.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,U.jsxs)(`span`,{children:[`Transport: `,e.dispatchResult??`—`,e.httpStatus===null?``:` (HTTP ${e.httpStatus})`]})}),e.error&&(0,U.jsx)(`div`,{className:`cal-modal-row cal-modal-row-top routine-prose`,children:(0,U.jsx)(`span`,{children:e.error})}),(0,U.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,U.jsxs)(`span`,{children:[`Conversation: `,e.sessionKey??`—`,e.transcriptOffset===null?``:` at byte ${e.transcriptOffset}`]})}),!e.bounded&&e.status!==`gated`&&(0,U.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,U.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,U.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,U.jsxs)(`span`,{children:[`Run `,e.runId]})})]})]})})}function be({status:e}){let t=oe(e);return(0,U.jsx)(`span`,{className:`routine-status-dot is-${t}`,"data-state":t,"aria-hidden":`true`})}var Q=500;function xe(e,t){if(!e)return`—`;let n=Date.parse(e);return Number.isFinite(n)?p(new Date(n).toISOString(),t):e}function Se(e){return e===null?`—`:e<1e3?`${e} ms`:`${(e/1e3).toFixed(1)} s`}var Ce={channel:`a channel`,destination:`a destination`,prompt:`an instruction`};function we(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 Ce)){let e=t.map(e=>Ce[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 Te(e){return e.status===`no-destination`?e.error?we(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 Ee(e){let t=e.indexOf(`:`);return t<=0?{channel:null,destination:e}:{channel:e.slice(0,t),destination:e.slice(t+1)}}function De(e){return e.outputExcerpt===null?e.status===`finished`?`Finished and sent nothing.`:null:e.outputExcerpt}function Oe({routine:e,adminFetch:t,cacheKey:n,from:r=`card`,onBack:i}){let{zone:s}=y(),[c,l]=(0,O.useState)([]),[f,p]=(0,O.useState)(!0),[h,g]=(0,O.useState)(null),[_,b]=(0,O.useState)(null),x=(0,O.useRef)(0),S=(0,O.useCallback)(()=>{let n=!1,i=++x.current,a=()=>n||i!==x.current;return p(!0),g(null),t(`/api/admin/routines/${encodeURIComponent(e.eventId)}/runs?limit=${Q}&from=${r}`).then(async e=>{if(a())return;if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await e.json();a()||l(Array.isArray(t.runs)?t.runs:[])}).catch(e=>{a()||(g(e instanceof Error?e.message:`Failed to load`),l([]))}).finally(()=>{a()||p(!1)}),()=>{n=!0}},[t,e.eventId,r]);(0,O.useEffect)(()=>S(),[S]);let C=(0,O.useCallback)(()=>{T(n,e.eventId)},[n,e.eventId]);return(0,U.jsxs)(`div`,{className:`cal-page`,children:[(0,U.jsx)(`header`,{className:`cal-header`,children:(0,U.jsxs)(`div`,{className:`cal-nav`,children:[(0,U.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:i,children:[(0,U.jsx)(d,{size:14}),` Routines`]}),(0,U.jsx)(`span`,{className:`cal-range-label runs-title`,"data-testid":`runs-title`,title:e.name??`Untitled routine`,children:e.name??`Untitled routine`}),(0,U.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,"data-testid":`runs-refresh`,onClick:S,disabled:f,title:`Refresh runs`,"aria-label":`Refresh runs`,children:[f?(0,U.jsx)(u,{size:14,className:`spin`}):(0,U.jsx)(a,{size:14}),` Refresh`]}),c.length>0&&(0,U.jsx)(`div`,{className:`routine-bulk-actions`,children:(0,U.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:C,children:[(0,U.jsx)(o,{size:14}),` Download all runs`]})})]})}),(0,U.jsxs)(`div`,{className:`cal-body`,children:[h&&(0,U.jsxs)(`div`,{className:`cal-error`,children:[`Could not load runs: `,h]}),!h&&!f&&c.length===0&&(0,U.jsxs)(`div`,{className:`cal-empty`,"data-testid":`runs-empty`,children:[(0,U.jsx)(`p`,{children:`Nothing to show for this routine.`}),(0,U.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,U.jsxs)(`p`,{children:[`For a repeating routine, the server log settles the middle one: a`,(0,U.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.`]})]}),c.length>=Q&&(0,U.jsxs)(`div`,{className:`cal-modal-confirm-text`,"data-testid":`runs-capped`,children:[`Showing the most recent `,Q,` runs. There may be more; the download has everything still on record.`]}),(0,U.jsx)(`div`,{className:`routine-list`,children:c.map(e=>{let t=Te(e),n=De(e),{channel:r,destination:i}=Ee(e.target);return(0,U.jsxs)(`button`,{type:`button`,className:`admin-card admin-card--padded routine-card`,"data-testid":`run-row-${e.runId}`,onClick:()=>b(e),children:[(0,U.jsxs)(`span`,{className:`admin-card-title routine-card-title run-card-title`,children:[(0,U.jsx)(be,{status:e.status}),` `,H(e.status)]}),(0,U.jsx)(`span`,{className:`routine-card-sched`,children:Se(e.ranMs)}),(0,U.jsx)(`span`,{className:`routine-card-target`,children:r?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(v,{channel:r,size:13}),` `,m[r]??r,` to `,r===`whatsapp`?q(i):i]}):i}),(0,U.jsxs)(`span`,{className:`routine-card-meta`,children:[`Due `,xe(e.scheduledFor,s)]}),n&&(0,U.jsx)(`span`,{className:`routine-card-meta run-card-output`,children:n}),t&&(0,U.jsx)(`span`,{className:`routine-card-meta run-card-detail`,children:t})]},e.runId)})})]}),_&&(0,U.jsx)(ye,{run:_,routineName:e.name,onClose:()=>b(null)})]})}t(((e,t)=>{t.exports={}}))();function ke(e){return e.agentChannel&&e.agentDestination&&e.agentPrompt?!0:!!(e.actionPlugin&&e.actionTool)}function Ae(e){if(e.agentChannel||e.agentDestination||e.agentPrompt){let t=[];return e.agentChannel||t.push(`channel`),e.agentDestination||t.push(`destination`),e.agentPrompt||t.push(`prompt`),`no-${t.join(`+`)}`}return e.actionPlugin||e.actionTool?e.actionTool?`no-action-plugin`:`no-action-tool`:`no-dispatch-configured`}var $=`maxy-admin-session-key`;function je(e){return e?N(e):`One-time`}function Me(e,t){if(!e)return`—`;let n=Date.parse(e);return Number.isFinite(n)?p(new Date(n).toISOString(),t):e}function Ne(){let[e,t]=(0,O.useState)(null),[n,r]=(0,O.useState)(!1),[i,a]=(0,O.useState)(void 0),[o,s]=(0,O.useState)(null),[c,u]=(0,O.useState)(void 0),[d,f]=(0,O.useState)(null),[p,m]=(0,O.useState)(null);(0,O.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem($)}catch{}if(!n){r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem($)}catch{}window.location.href=`/`;return}if(i.ok)try{let e=await i.json();typeof e.businessName==`string`&&a(e.businessName),e.sessionId!==void 0&&s(e.sessionId??null),m(e.role??null),u(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 h=(0,O.useCallback)(()=>{try{sessionStorage.removeItem($)}catch{}window.location.href=`/`},[]),[g,v]=(0,O.useState)(!1),y=(0,O.useCallback)(async()=>{v(!0);try{let e=await b();if(e){try{sessionStorage.removeItem($)}catch{}window.location.href=`/`}return e}finally{v(!1)}},[]);return n?e?(0,U.jsx)(_,{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,U.jsx)(S,{cacheKey:e,businessName:i,sessionId:o,onLogout:h,onDisconnect:y,disconnecting:g,userName:c,userAvatar:d,role:p,children:(0,U.jsx)(Pe,{cacheKey:e})})}):(0,U.jsx)(`div`,{className:`cal-page`,children:(0,U.jsxs)(`div`,{className:`cal-empty`,children:[(0,U.jsx)(`p`,{children:`You are not signed in.`}),(0,U.jsxs)(`p`,{children:[`Open the `,(0,U.jsx)(`a`,{href:`/`,className:`cal-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,U.jsx)(l,{surface:`gate`})}function Pe({cacheKey:e}){let{zone:t}=y(),{adminFetch:n,cacheKey:r,sessionRefetchNonce:i}=h({initialCacheKey:e,surface:`routines`}),[o,s]=(0,O.useState)([]),[c,d]=(0,O.useState)(null),[f,p]=(0,O.useState)(!1),[g,_]=(0,O.useState)(!1),[b,S]=(0,O.useState)(null),[T,E]=(0,O.useState)(null),[D,k]=(0,O.useState)(null),A=(0,O.useCallback)(()=>{let e=!1;return p(!0),S(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:[]),d(typeof n.workflowRuns24h==`number`?n.workflowRuns24h:null)}).catch(t=>{e||(S(t instanceof Error?t.message:`Failed to load`),s([]),d(null))}).finally(()=>{e||(p(!1),_(!0))}),()=>{e=!0}},[n]);(0,O.useEffect)(()=>A(),[A,i]);let j=(0,O.useCallback)(e=>{s(t=>t.map(t=>t.eventId===e.eventId?e:t)),E(e)},[]),M=(0,O.useCallback)(e=>{s(t=>t.filter(t=>t.eventId!==e)),E(null)},[]),[N,P]=(0,O.useState)(!1),[F,I]=(0,O.useState)(null),L=o.filter(e=>e.eventStatus===`scheduled`).length,R=o.filter(e=>e.suspendedInBulk).length,z=(0,O.useCallback)(async e=>{P(!0),I(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;I(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.`),A()}catch(e){I(e instanceof Error?e.message:`Failed`)}finally{P(!1)}},[n,A]);return g?D?(0,U.jsx)(Oe,{routine:D,adminFetch:n,cacheKey:r,from:`modal`,onBack:()=>k(null)}):(0,U.jsxs)(`div`,{className:`cal-page`,children:[(0,U.jsx)(`header`,{className:`cal-header`,children:(0,U.jsxs)(`div`,{className:`cal-nav`,children:[(0,U.jsxs)(`span`,{className:`cal-range-label`,children:[(0,U.jsx)(x,{size:16}),` Routines`]}),(0,U.jsxs)(`div`,{className:`routine-bulk-actions`,children:[(0,U.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,"data-testid":`routines-refresh`,onClick:A,disabled:f,title:`Refresh routines`,"aria-label":`Refresh routines`,children:[f?(0,U.jsx)(u,{size:14,className:`spin`}):(0,U.jsx)(a,{size:14}),` Refresh`]}),(0,U.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>z(`suspend-all`),disabled:N||L===0,children:[(0,U.jsx)(te,{size:14}),` Suspend all (`,L,`)`]}),(0,U.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>z(`resume-all`),disabled:N||R===0,children:[(0,U.jsx)(ne,{size:14}),` Resume all (`,R,`)`]})]})]})}),(0,U.jsxs)(`div`,{className:`cal-body`,children:[!b&&(()=>{let e=me(o);return(0,U.jsxs)(`div`,{className:`routine-rail-strip`,"data-testid":`routine-rail-strip`,children:[`Live recurring: `,e.live,` · `,e.model,` model · `,e.tool,` tool · `,e.none,` no dispatch`,` · `,`Workflow runs (24h): `,c===null?`—`:c]})})(),F&&(0,U.jsx)(`div`,{className:`cal-modal-confirm-text`,children:F}),b&&(0,U.jsxs)(`div`,{className:`cal-error`,children:[`Could not load routines: `,b]}),!b&&!f&&o.length===0&&(0,U.jsx)(`div`,{className:`cal-empty`,children:(0,U.jsx)(`p`,{children:`No routines yet.`})}),(0,U.jsx)(`div`,{className:`routine-list`,children:o.map(e=>(0,U.jsxs)(`div`,{role:`button`,tabIndex:0,className:`admin-card admin-card--padded routine-card`,"data-testid":`routine-card-${e.eventId}`,onClick:()=>E(e),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),E(e))},children:[(0,U.jsx)(`span`,{className:`admin-card-title routine-card-title`,title:e.name??`Untitled routine`,children:e.name??`Untitled routine`}),(0,U.jsxs)(`span`,{className:`routine-card-sched`,children:[(0,U.jsx)(C,{size:13}),` `,je(e.recurrence)]}),e.description&&(0,U.jsx)(`span`,{className:`routine-card-desc`,children:e.description}),(()=>{let t=e.eventStatus===`scheduled`&&!ke(e)?Ae(e):null;return t===null?(0,U.jsx)(`span`,{className:`routine-card-target`,children:e.agentChannel?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(v,{channel:e.agentChannel,size:13}),` `,m[e.agentChannel]??e.agentChannel,` to `,e.agentDestination??`—`]}):e.actionPlugin?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(ee,{size:13}),` `,e.actionPlugin,`.`,e.actionTool]}):(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(C,{size:13}),` Scheduled trigger`]})}):(0,U.jsxs)(`span`,{className:`routine-card-target routine-card-target--gap`,children:[(0,U.jsx)(w,{size:13}),` `,we(t)]})})(),(()=>{let t=[],n=fe[de(e)];return n&&t.push(n),e.runs24h>0&&t.push(`24h: ${e.runs24h} ${e.runs24h===1?`fire`:`fires`}, ${e.gated24h} skipped`),t.length===0?null:(0,U.jsx)(`span`,{className:`routine-card-gate`,"data-testid":`routine-gate-${e.eventId}`,children:t.join(` · `)})})(),(0,U.jsxs)(`span`,{className:`routine-card-meta`,children:[(0,U.jsx)(ue,{eventStatus:e.eventStatus}),`Next: `,Me(e.nextRun,t),` · `,e.eventStatus??`unknown`]})]},e.eventId))})]}),T&&(0,U.jsx)(Y,{routine:T,adminFetch:n,onClose:()=>E(null),onSaved:j,onDeleted:M,onViewRuns:e=>{E(null),k(e)}})]}):(0,U.jsx)(l,{surface:`gate`})}(0,D.createRoot)(document.getElementById(`root`)).render((0,U.jsx)(Ne,{}));
@@ -1 +1 @@
1
- import{o as e}from"./chunk-BycB0eMI.js";import{i as t,n,t as r}from"./jsx-runtime-YcUntiud.js";import{M as i,O as a,U as o,V as s,it as c,j as l,k as u}from"./useMediaQuery-BmG090FR.js";import{A as d,h as f,t as p}from"./AdminShell-C_M7YE5Z.js";import{t as m}from"./file-text-DyAL2DCh.js";var h=n(),g=e(t(),1),_=r();function v({summary:e,adminFetch:t,onClose:n,onDeleted:r}){let[a,c]=(0,g.useState)(null),[u,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 n=!1;return d(!0),h(null),t(`/api/admin/skills/${encodeURIComponent(e.plugin)}/${encodeURIComponent(e.skill)}`).then(async e=>{if(!n){if(!e.ok)throw Error(`HTTP ${e.status}`);c((await e.json()).skill)}}).catch(e=>{n||h(e instanceof Error?e.message:`Failed to load`)}).finally(()=>{n||d(!1)}),()=>{n=!0}},[t,e.plugin,e.skill]),(0,g.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!b&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[b,n]);let S=(0,g.useCallback)(async()=>{x(!0),h(null);try{let n=await t(`/api/admin/skills/${encodeURIComponent(e.plugin)}/${encodeURIComponent(e.skill)}`,{method:`DELETE`,headers:{"content-type":`application/json`}});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??`HTTP ${n.status}`)}r(e)}catch(e){h(e instanceof Error?e.message:`Delete failed`),x(!1),y(!1)}},[t,e,r]);return(0,_.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{b||n()},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:n,"aria-label":`Close`,autoFocus:!0,disabled:b,children:(0,_.jsx)(l,{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})]}),u&&(0,_.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,_.jsx)(s,{size:14,className:`spin`}),(0,_.jsx)(`span`,{children:`Loading…`})]}),a&&(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,_.jsx)(`span`,{children:a.frontmatter.description||`No description.`})}),a.frontmatter.publicEmbed&&(0,_.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,_.jsx)(o,{size:14}),(0,_.jsx)(`span`,{children:`Public embed`})]}),(0,_.jsx)(`pre`,{className:`skill-body`,children:a.body.trim()||`No body content.`}),a.references.length>0&&(0,_.jsxs)(`div`,{className:`skill-refs`,children:[(0,_.jsx)(`span`,{className:`skill-refs-label`,children:`References`}),a.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||u,children:[(0,_.jsx)(i,{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)(s,{size:14,className:`spin`}):(0,_.jsx)(i,{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,o]=(0,g.useState)(void 0),[s,c]=(0,g.useState)(null),[l,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`&&o(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)(u,{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:s,onLogout:S,onDisconnect:T,disconnecting:C,userName:l,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)(a,{surface:`gate`})}function x({cacheKey:e}){let{adminFetch:t,sessionRefetchNonce:n}=c({initialCacheKey:e,surface:`skills`}),[r,i]=(0,g.useState)([]),[o,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),t(`/api/admin/skills`).then(async t=>{if(e)return;if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();i(Array.isArray(n.skills)?n.skills:[])}).catch(t=>{e||(h(t instanceof Error?t.message:`Failed to load`),i([]))}).finally(()=>{e||(l(!1),d(!0))}),()=>{e=!0}},[t]);(0,g.useEffect)(()=>x(),[x,n]);let S=(0,g.useCallback)(e=>{i(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`]}),o&&(0,_.jsx)(s,{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&&!o&&r.length===0&&(0,_.jsx)(`div`,{className:`cal-empty`,children:(0,_.jsx)(`p`,{children:`No skills yet. Ask in chat to create one.`})}),r.length>0&&(0,_.jsx)(`div`,{className:`routine-list`,children:r.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:t,onClose:()=>b(null),onDeleted:S})]}):(0,_.jsx)(a,{surface:`gate`})}(0,h.createRoot)(document.getElementById(`root`)).render((0,_.jsx)(b,{}));
1
+ import{o as e}from"./chunk-BycB0eMI.js";import{i as t,n,t as r}from"./jsx-runtime-YcUntiud.js";import{M as i,O as a,U as o,V as s,it as c,j as l,k as u}from"./useMediaQuery-BUFkZYRs.js";import{A as d,h as f,t as p}from"./AdminShell-BLs5v0qF.js";import{t as m}from"./file-text-cnHv9ZS6.js";var h=n(),g=e(t(),1),_=r();function v({summary:e,adminFetch:t,onClose:n,onDeleted:r}){let[a,c]=(0,g.useState)(null),[u,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 n=!1;return d(!0),h(null),t(`/api/admin/skills/${encodeURIComponent(e.plugin)}/${encodeURIComponent(e.skill)}`).then(async e=>{if(!n){if(!e.ok)throw Error(`HTTP ${e.status}`);c((await e.json()).skill)}}).catch(e=>{n||h(e instanceof Error?e.message:`Failed to load`)}).finally(()=>{n||d(!1)}),()=>{n=!0}},[t,e.plugin,e.skill]),(0,g.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!b&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[b,n]);let S=(0,g.useCallback)(async()=>{x(!0),h(null);try{let n=await t(`/api/admin/skills/${encodeURIComponent(e.plugin)}/${encodeURIComponent(e.skill)}`,{method:`DELETE`,headers:{"content-type":`application/json`}});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??`HTTP ${n.status}`)}r(e)}catch(e){h(e instanceof Error?e.message:`Delete failed`),x(!1),y(!1)}},[t,e,r]);return(0,_.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{b||n()},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:n,"aria-label":`Close`,autoFocus:!0,disabled:b,children:(0,_.jsx)(l,{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})]}),u&&(0,_.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,_.jsx)(s,{size:14,className:`spin`}),(0,_.jsx)(`span`,{children:`Loading…`})]}),a&&(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,_.jsx)(`span`,{children:a.frontmatter.description||`No description.`})}),a.frontmatter.publicEmbed&&(0,_.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,_.jsx)(o,{size:14}),(0,_.jsx)(`span`,{children:`Public embed`})]}),(0,_.jsx)(`pre`,{className:`skill-body`,children:a.body.trim()||`No body content.`}),a.references.length>0&&(0,_.jsxs)(`div`,{className:`skill-refs`,children:[(0,_.jsx)(`span`,{className:`skill-refs-label`,children:`References`}),a.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||u,children:[(0,_.jsx)(i,{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)(s,{size:14,className:`spin`}):(0,_.jsx)(i,{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,o]=(0,g.useState)(void 0),[s,c]=(0,g.useState)(null),[l,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`&&o(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)(u,{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:s,onLogout:S,onDisconnect:T,disconnecting:C,userName:l,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)(a,{surface:`gate`})}function x({cacheKey:e}){let{adminFetch:t,sessionRefetchNonce:n}=c({initialCacheKey:e,surface:`skills`}),[r,i]=(0,g.useState)([]),[o,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),t(`/api/admin/skills`).then(async t=>{if(e)return;if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();i(Array.isArray(n.skills)?n.skills:[])}).catch(t=>{e||(h(t instanceof Error?t.message:`Failed to load`),i([]))}).finally(()=>{e||(l(!1),d(!0))}),()=>{e=!0}},[t]);(0,g.useEffect)(()=>x(),[x,n]);let S=(0,g.useCallback)(e=>{i(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`]}),o&&(0,_.jsx)(s,{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&&!o&&r.length===0&&(0,_.jsx)(`div`,{className:`cal-empty`,children:(0,_.jsx)(`p`,{children:`No skills yet. Ask in chat to create one.`})}),r.length>0&&(0,_.jsx)(`div`,{className:`routine-list`,children:r.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:t,onClose:()=>b(null),onDeleted:S})]}):(0,_.jsx)(a,{surface:`gate`})}(0,h.createRoot)(document.getElementById(`root`)).render((0,_.jsx)(b,{}));
@@ -1,3 +1,3 @@
1
- import{o as e}from"./chunk-BycB0eMI.js";import{i as t,n,t as r}from"./jsx-runtime-YcUntiud.js";import{L as i,M as a,N as o,O as s,a as c,it as l,j as u,k as d,q as f}from"./useMediaQuery-BmG090FR.js";import{A as p,a as m,f as h,n as ee,t as g,v as _}from"./AdminShell-C_M7YE5Z.js";import{t as v}from"./play-CmSyYrB6.js";import{t as y}from"./rotate-ccw-fCH0LSMq.js";var b=n(),x=e(t(),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=r();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 A(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 j(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 M(e){return e.assigneeName?e.assigneeName:e.assigneeUserId?e.assigneeUserId.slice(0,8):`Unassigned`}function N(e,t){return[t,j(e.createdAt),M(e)].filter(Boolean).join(` · `)}function ie(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 ae(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(`
1
+ import{o as e}from"./chunk-BycB0eMI.js";import{i as t,n,t as r}from"./jsx-runtime-YcUntiud.js";import{L as i,M as a,N as o,O as s,a as c,it as l,j as u,k as d,q as f}from"./useMediaQuery-BUFkZYRs.js";import{A as p,a as m,f as h,n as ee,t as g,v as _}from"./AdminShell-BLs5v0qF.js";import{t as v}from"./play-D6OAQVJ_.js";import{t as y}from"./rotate-ccw-DVFvQAHG.js";var b=n(),x=e(t(),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=r();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 A(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 j(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 M(e){return e.assigneeName?e.assigneeName:e.assigneeUserId?e.assigneeUserId.slice(0,8):`Unassigned`}function N(e,t){return[t,j(e.createdAt),M(e)].filter(Boolean).join(` · `)}function ie(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 ae(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
2
 
3
3
  `).slice(0,2e3)}function oe({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 · `,c(e.totalSeconds),` logged`]})]})},e.name))]})}function se({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)(u,{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:c(e.secondsLogged)}),(0,D.jsx)(`dt`,{children:`Created`}),(0,D.jsx)(`dd`,{children:j(e.createdAt)||`Not recorded`}),(0,D.jsx)(`dt`,{children:`Assignee`}),(0,D.jsx)(`dd`,{children:e.taskId===null?M(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:[M(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 P({adminFetch:e}){let[t,n]=(0,x.useState)({open:[],completed:[]}),[r,l]=(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,j]=(0,x.useState)(null),[M,P]=(0,x.useState)(null),[F,I]=(0,x.useState)(``),[L,R]=(0,x.useState)(null),[ce,z]=(0,x.useState)(null),[B,V]=(0,x.useState)(null),H=(0,x.useRef)(new Map),U=(0,x.useRef)(new Set),[le,ue]=(0,x.useState)(new Set),W=(0,x.useMemo)(()=>{if(L!==null)return[...t.open,...t.completed].find(e=>e.rowKey===L)??null},[t,L]),G=(0,x.useMemo)(()=>B===null?null:[...t.open,...t.completed].find(e=>e.rowKey===B)??null,[t,B]);(0,x.useEffect)(()=>{L!==null&&W===null&&console.error(`[tasks-ui] op=detail-failed rowKey=${L} reason=not-in-list`)},[L,W]);let K=(0,x.useMemo)(()=>ne(t.open,t.completed),[t]),q=(0,x.useMemo)(()=>T===null?{open:t.open,completed:t.completed}:{open:t.open.filter(e=>e.clientName===T),completed:t.completed.filter(e=>e.clientName===T)},[t,T]),J=(0,x.useMemo)(()=>re(q.open,q.completed),[q]),de=(0,x.useCallback)(e=>{O(e),w(`open`)},[]);(0,x.useEffect)(()=>{T&&!K.some(e=>e.name===T)&&O(null)},[K,T]),(0,x.useEffect)(()=>{k&&!J.some(e=>e.userId===k)&&j(null)},[J,k]),(0,x.useEffect)(()=>{z(null),V(null)},[C,T,k]);let Y=t.open.filter(e=>e.running||(T===null||e.clientName===T)&&E(e,k)),X=(T?t.completed.filter(e=>e.clientName===T):t.completed).filter(e=>E(e,k)),[fe,pe]=(0,x.useState)([]),Z=(0,x.useCallback)(async()=>{let t=await e(`/api/admin/tasks-list`);t.ok&&n(await t.json()),l(!0)},[e]);(0,x.useEffect)(()=>{Z()},[Z]),(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)&&pe(e.users)}})()},[e]);let Q=(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 Z(),!0}finally{g.current=!1,p(!1)}},[e,Z]),me=(0,x.useCallback)(async e=>{await Q(`/api/admin/task-complete`,e)},[Q]),he=(0,x.useCallback)(async e=>{await Q(`/api/admin/task-delete`,e,{confirmed:!0})},[Q]),ge=(0,x.useCallback)((e,t)=>{let n=String(Math.round(e.secondsLogged/60));b.current=n,P(t),I(n)},[]),$=(0,x.useCallback)(()=>{P(null),I(``)},[]),_e=(0,x.useCallback)(async e=>{let t=F.trim(),n=Number(t);if(!(t===``||!Number.isInteger(n)||n<0)){if(t===b.current){$();return}P(null),I(``),await Q(`/api/admin/task-time-adjust`,e,{newSeconds:n*60})}},[F,Q,$]),ve=(0,x.useCallback)(e=>{Q(`/api/admin/task-time-adjust`,e,{newSeconds:0})},[Q]),ye=(0,x.useCallback)((e,t)=>{Q(`/api/admin/task-assign`,e,{assigneeUserId:t})},[Q]),be=(0,x.useCallback)(async t=>{if(!U.current.has(t)){U.current.add(t),ue(new Set(U.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=ae({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=ee(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{U.current.delete(t),ue(new Set(U.current))}}},[e]);if(!r)return(0,D.jsx)(s,{surface:`gate`});let xe=e=>e.taskId!==null&&M===e.taskId,Se=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:F,onChange:e=>I(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 _e(e),children:[(0,D.jsx)(f,{size:14}),` Save`]}),(0,D.jsxs)(`button`,{className:`tasks-btn-secondary tasks-btn-action`,onClick:$,children:[(0,D.jsx)(u,{size:14}),` Cancel`]})]}),Ce=(e,t)=>[{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)(i,{size:12}),disabled:d||e.running,onClick:()=>ge(e,t)},{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:()=>ve(t)},{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:le.has(t),onClick:()=>{be(t)}},{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)(a,{size:12}),danger:!0,disabled:d||e.running,onClick:()=>V(e.rowKey)}];return(0,D.jsxs)(`div`,{className:`ui-page ui-page--full tasks-body`,children:[L!==null&&(0,D.jsx)(se,{task:W??null,roster:fe,busy:d,onAssign:ye,onClose:()=>R(null)}),(0,D.jsx)(m,{target:G?{name:G.name,secondsLogged:G.secondsLogged}:null,anchorEl:B?H.current.get(B)??null:null,onCancel:()=>V(null),onConfirm:()=>{let e=G;V(null),e?.taskId&&he(e.taskId)}},B??`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:t.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:t.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:K.length})]})]}),C===`clients`?(0,D.jsx)(oe,{clients:K,onSelect:de}):(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`})]}),J.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:()=>j(null),children:[`All `,(0,D.jsx)(`span`,{className:`tasks-assignee-count`,children:q.open.length})]}),J.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:()=>j(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:[Y.length,` to do`]})]}),Y.length===0&&(0,D.jsx)(`div`,{className:`tasks-empty`,children:`No open tasks.`}),Y.map(e=>(0,D.jsxs)(`div`,{className:`tasks-row`,ref:t=>{t?H.current.set(e.rowKey,t):H.current.delete(e.rowKey)},children:[(0,D.jsx)(`button`,{className:`tasks-row-open`,"aria-label":`Open task detail: ${e.name}`,onClick:()=>R(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:N(e,A(e))})]})}),(0,D.jsx)(`div`,{className:`tasks-row-elapsed ${e.running?`tasks-row-elapsed-running`:``}`,children:c(ie(e,S))}),(0,D.jsx)(`div`,{className:`tasks-row-controls`,children:e.taskId!==null&&ce===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:()=>{z(null),me(e.taskId)},children:[(0,D.jsx)(f,{size:14}),` Confirm complete`]}),(0,D.jsxs)(`button`,{className:`tasks-btn-secondary tasks-btn-action`,onClick:()=>z(null),children:[(0,D.jsx)(u,{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`}):xe(e)?Se(e.taskId):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(h,{actions:Ce(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:()=>z(e.taskId),children:(0,D.jsx)(f,{size:14})}),e.running?(0,D.jsxs)(`button`,{className:`admin-btn-danger tasks-btn-action`,disabled:d,title:`Stop the timer`,onClick:()=>void Q(`/api/admin/task-timer-stop`,e.taskId),children:[(0,D.jsx)(o,{size:14}),` Stop`]}):(0,D.jsxs)(`button`,{className:`admin-btn-cta tasks-btn-action`,disabled:d,title:`Start the timer`,onClick:()=>void Q(`/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:[X.length,` done`]})]}),X.length===0&&(0,D.jsx)(`div`,{className:`tasks-empty`,children:`Nothing completed yet.`}),X.map(e=>(0,D.jsxs)(`div`,{className:`tasks-row tasks-row-done`,ref:t=>{t?H.current.set(e.rowKey,t):H.current.delete(e.rowKey)},children:[(0,D.jsx)(`button`,{className:`tasks-row-open`,"aria-label":`Open task detail: ${e.name}`,onClick:()=>R(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:N(e,A(e))})]})}),(0,D.jsx)(`div`,{className:`tasks-row-elapsed`,children:c(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`}):xe(e)?Se(e.taskId):(0,D.jsx)(h,{actions:Ce(e,e.taskId),disabled:!1,label:`Task actions`})})]},e.rowKey))]})]})]})}function F({cacheKey:e}){let{adminFetch:t}=l({initialCacheKey:e,surface:`tasks`});return(0,D.jsx)(P,{adminFetch:t})}function I(){let[e,t]=(0,x.useState)(null),[n,r]=(0,x.useState)(!1),[i,a]=(0,x.useState)(void 0),[o,c]=(0,x.useState)(null),[l,u]=(0,x.useState)(null),[f,m]=(0,x.useState)(null),[h,ee]=(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&&c(e.sessionId??null),u(e.role??null),m(e.userName===void 0?null:e.userName),ee(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:h,role:l,children:(0,D.jsx)(F,{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)(s,{surface:`gate`})}(0,b.createRoot)(document.getElementById(`root`)).render((0,D.jsx)(I,{}));
@@ -1 +1 @@
1
- import{Z as e}from"./useMediaQuery-BmG090FR.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
+ import{Z as e}from"./useMediaQuery-BUFkZYRs.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 +1 @@
1
- import{o as e}from"./chunk-BycB0eMI.js";import{i as t}from"./jsx-runtime-YcUntiud.js";import{i as n}from"./useMediaQuery-BmG090FR.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
+ import{o as e}from"./chunk-BycB0eMI.js";import{i as t}from"./jsx-runtime-YcUntiud.js";import{i as n}from"./useMediaQuery-BUFkZYRs.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};
@@ -3,4 +3,4 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
3
3
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Vt(e,t){if(e){if(typeof e==`string`)return Ht(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Ht(e,t):void 0}}function Ht(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}var Ut=[`MOBILE`,`PREMIUM_RATE`,`TOLL_FREE`,`SHARED_COST`,`VOIP`,`PERSONAL_NUMBER`,`PAGER`,`UAN`,`VOICEMAIL`];function Wt(e,t,n){if(t||={},!(!e.country&&!e.countryCallingCode)){var r=new H(n);r.selectNumberingPlan(e.country||e.countryCallingCode);var i=t.v2?e.nationalNumber:e.phone;if(U(i,r.nationalNumberPattern())){if(Gt(i,`FIXED_LINE`,r))return r.type(`MOBILE`)&&r.type(`MOBILE`).pattern()===``||!r.type(`MOBILE`)||Gt(i,`MOBILE`,r)?`FIXED_LINE_OR_MOBILE`:`FIXED_LINE`;for(var a=Bt(Ut),o;!(o=a()).done;){var s=o.value;if(Gt(i,s,r))return s}}}}function Gt(e,t,n){var r=n.type(t);return!r||!r.pattern()||r.possibleLengths()&&r.possibleLengths().indexOf(e.length)<0?!1:U(e,r.pattern())}function Kt(e,t,n){t||={};var r=new H(n);return r.selectNumberingPlan(e.country||e.countryCallingCode),r.hasTypes()?Wt(e,t,r.metadata)!==void 0:U(t.v2?e.nationalNumber:e.phone,r.nationalNumberPattern())}var qt=/^[A-Z]{2}$/;function Jt(e){return qt.test(e)}var Yt=!1;function Xt(e,t){var n,r,i=new H(t);return Jt(e)?(n=e,i.selectNumberingPlan(n),r=i.countryCallingCode()):(r=e,Yt&&i.isNonGeographicCallingCode(r)&&(n=`001`)),{country:n,callingCode:r}}function Zt(e,t,n){var r=new H(n).getCountryCodesForCallingCode(e);return r?r.filter(function(e){return Qt(t,e,n)}):[]}function Qt(e,t,n){var r=new H(n);return r.selectNumberingPlan(t),r.numberingPlan.possibleLengths().indexOf(e.length)>=0}var W=`0-90-9٠-٩۰-۹`,$t=`-‐-―−ー-//.. \xA0­​⁠ ()()[]\\[\\]~⁓∼~`,en=`++`,tn=RegExp(`([`+W+`])`);function nn(e,t,n,r){if(t){var i=new H(r);i.selectNumberingPlan(t||n);var a=new RegExp(i.IDDPrefix());if(e.search(a)===0){e=e.slice(e.match(a)[0].length);var o=e.match(tn);if(!(o&&o[1]!=null&&o[1].length>0&&o[1]===`0`))return e}}}function rn(e,t){if(e&&t.numberingPlan.nationalPrefixForParsing()){var n=RegExp(`^(?:`+t.numberingPlan.nationalPrefixForParsing()+`)`),r=n.exec(e);if(r){var i,a,o=r.length-1,s=o>0&&r[o];if(t.nationalPrefixTransformRule()&&s)i=e.replace(n,t.nationalPrefixTransformRule()),o>1&&(a=r[1]);else{var c=r[0];i=e.slice(c.length),s&&(a=r[1])}var l;if(s){var u=e.indexOf(r[1]);e.slice(0,u)===t.numberingPlan.nationalPrefix()&&(l=t.numberingPlan.nationalPrefix())}else l=r[0];return{nationalNumber:i,nationalPrefix:l,carrierCode:a}}}return{nationalNumber:e}}function an(e,t){var n=typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=on(e))||t&&e&&typeof e.length==`number`){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw TypeError(`Invalid attempt to iterate non-iterable instance.
4
4
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function on(e,t){if(e){if(typeof e==`string`)return sn(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?sn(e,t):void 0}}function sn(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function cn(e,t,n){for(var r=new H(n),i=an(t),a;!(a=i()).done;){var o=a.value;if(r.selectNumberingPlan(o),r.leadingDigits()){if(e&&e.search(r.leadingDigits())===0)return o}else if(Wt({phone:e,country:o},void 0,r.metadata))return o}}var ln=!1;function un(e,t){var n=t.nationalNumber,r=t.metadata;if(ln&&r.isNonGeographicCallingCode(e))return`001`;var i=r.getCountryCodesForCallingCode(e);if(i)return i.length===1?i[0]:cn(n,i,r.metadata)}function dn(e,t,n){var r=rn(e,n),i=r.carrierCode,a=r.nationalNumber;return a!==e&&(!fn(e,a,n)||n.numberingPlan.possibleLengths()&&(t||=un(n.numberingPlan.callingCode(),{nationalNumber:a,metadata:n}),!pn(a,t,n)))?{nationalNumber:e}:{nationalNumber:a,carrierCode:i}}function fn(e,t,n){return!(U(e,n.nationalNumberPattern())&&!U(t,n.nationalNumberPattern()))}function pn(e,t,n){switch(It(e,t,n)){case`TOO_SHORT`:case`INVALID_LENGTH`:return!1;default:return!0}}function mn(e,t,n,r,i){if(!(t||n||r))return{number:e};var a=t||n?kt(t||n,i):r;if(e.indexOf(a)===0){var o=new H(i);o.selectNumberingPlan(t||n||r);var s=e.slice(a.length),c=dn(s,void 0,o).nationalNumber,l=dn(e,void 0,o).nationalNumber;if(!U(l,o.nationalNumberPattern())&&U(c,o.nationalNumberPattern())||It(l,void 0,o)===`TOO_LONG`)return{countryCallingCode:a,number:s}}return{number:e}}function hn(e,t,n,r,i){if(!e)return{};var a;if(e[0]!==`+`){var o=nn(e,t||n,r,i);if(o&&o!==e)a=!0,e=`+`+o;else{if(t||n||r){var s=mn(e,t,n,r,i),c=s.countryCallingCode,l=s.number;if(c)return{countryCallingCodeSource:`FROM_NUMBER_WITHOUT_PLUS_SIGN`,countryCallingCode:c,number:l}}return{number:e}}}if(e[1]===`0`)return{};for(var u=new H(i),d=2;d-1<=3&&d<=e.length;){var f=e.slice(1,d);if(u.hasCallingCode(f))return u.selectNumberingPlan(f),{countryCallingCodeSource:a?`FROM_NUMBER_WITH_IDD`:`FROM_NUMBER_WITH_PLUS_SIGN`,countryCallingCode:f,number:e.slice(d)};d++}return{}}function gn(e){return e.replace(RegExp(`[${$t}]+`,`g`),` `).trim()}var _n=/(\$\d)/;function vn(e,t,n){var r=n.useInternationalFormat,i=n.withNationalPrefix;n.carrierCode,n.metadata;var a=e.replace(new RegExp(t.pattern()),r?t.internationalFormat():i&&t.nationalPrefixFormattingRule()?t.format().replace(_n,t.nationalPrefixFormattingRule()):t.format());return r?gn(a):a}var yn=/^[\d]+(?:[~\u2053\u223C\uFF5E][\d]+)?$/;function bn(e,t,n){var r=new H(n);if(r.selectNumberingPlan(e||t),r.defaultIDDPrefix())return r.defaultIDDPrefix();if(yn.test(r.IDDPrefix()))return r.IDDPrefix()}var xn=`;ext=`,G=function(e){return`([${W}]{1,${e}})`};function Sn(e){var t=`20`,n=`15`,r=`9`,i=`6`,a=`[ \xA0\\t,]*`,o=`[:\\..]?[ \xA0\\t,-]*`,s=`#?`,c=`(?:e?xt(?:ensi(?:ó?|ó))?n?|e?xtn?|доб|anexo)`,l=`(?:[xx##~~]|int|int)`,u=`[- ]+`,d=`[ \xA0\\t]*`,f=`(?:,{2}|;)`,p=xn+G(t),m=a+c+o+G(t)+s,h=a+l+o+G(r)+s,g=u+G(i)+`#`,_=d+f+o+G(n)+s,v=d+`(?:,)+`+o+G(r)+s;return p+`|`+m+`|`+h+`|`+g+`|`+_+`|`+v}var Cn=`[`+W+`]{2}`,wn=`[`+en+`]{0,1}(?:[`+$t+`]*[`+W+`]){3,}[`+$t+W+`]*`,Tn=RegExp(`^[`+en+`]{0,1}(?:[`+$t+`]*[`+W+`]){1,2}$`,`i`),En=wn+`(?:`+Sn()+`)?`,Dn=RegExp(`^`+Cn+`$|^`+En+`$`,`i`);function On(e){return e.length>=2&&Dn.test(e)}function kn(e){return Tn.test(e)}function An(e){var t=e.number,n=e.ext;if(!t)return``;if(t[0]!==`+`)throw Error(`"formatRFC3966()" expects "number" to be in E.164 format.`);return`tel:${t}${n?`;ext=`+n:``}`}var jn={formatExtension:function(e,t,n){return`${e}${n.ext()}${t}`}};function Mn(e,t,n,r){n=n?Ln({},jn,n):jn;var i=new H(r);if(e.country&&e.country!==`001`){if(!i.hasCountry(e.country))throw Error(`Unknown country: ${e.country}`);i.selectNumberingPlan(e.country)}else if(e.countryCallingCode)i.selectNumberingPlan(e.countryCallingCode);else return e.phone||``;var a=i.countryCallingCode(),o=n.v2?e.nationalNumber:e.phone,s;switch(t){case`NATIONAL`:return o?(s=Nn(o,e.carrierCode,`NATIONAL`,i,n),Fn(s,e.ext,i,n.formatExtension)):``;case`INTERNATIONAL`:return o?(s=Nn(o,null,`INTERNATIONAL`,i,n),s=`+${a} ${s}`,Fn(s,e.ext,i,n.formatExtension)):`+${a}`;case`E.164`:return`+${a}${o}`;case`RFC3966`:return An({number:`+${a}${o}`,ext:e.ext});case`IDD`:if(!n.fromCountry)return;var c=In(o,e.carrierCode,a,n.fromCountry,i);return c?Fn(c,e.ext,i,n.formatExtension):void 0;default:throw Error(`Unknown "format" argument passed to "formatNumber()": "${t}"`)}}function Nn(e,t,n,r,i){var a=Pn(r.formats(),e);return a?vn(e,a,{useInternationalFormat:n===`INTERNATIONAL`,withNationalPrefix:!(a.nationalPrefixIsOptionalWhenFormattingInNationalFormat()&&i&&i.nationalPrefix===!1),carrierCode:t,metadata:r}):e}function Pn(e,t){return Rn(e,function(e){if(e.leadingDigitsPatterns().length>0){var n=e.leadingDigitsPatterns()[e.leadingDigitsPatterns().length-1];if(t.search(n)!==0)return!1}return U(t,e.pattern())})}function Fn(e,t,n,r){return t?r(e,t,n):e}function In(e,t,n,r,i){if(kt(r,i.metadata)===n){var a=Nn(e,t,`NATIONAL`,i);return n===`1`?n+` `+a:a}var o=bn(r,void 0,i.metadata);if(o)return`${o} ${n} ${Nn(e,null,`INTERNATIONAL`,i)}`}function Ln(){for(var e=1,t=[...arguments];e<t.length;){if(t[e])for(var n in t[e])t[0][n]=t[e][n];e++}return t[0]}function Rn(e,t){for(var n=0;n<e.length;){if(t(e[n]))return e[n];n++}}function K(e){"@babel/helpers - typeof";return K=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},K(e)}function zn(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function Bn(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?zn(Object(n),!0).forEach(function(t){Vn(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):zn(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Vn(e,t,n){return(t=Gn(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Hn(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function Un(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,Gn(r.key),r)}}function Wn(e,t,n){return t&&Un(e.prototype,t),n&&Un(e,n),Object.defineProperty(e,`prototype`,{writable:!1}),e}function Gn(e){var t=Kn(e,`string`);return K(t)==`symbol`?t:t+``}function Kn(e,t){if(K(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(K(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var qn=function(){function e(t,n,r){if(Hn(this,e),!t)throw TypeError(`First argument is required`);if(typeof t!=`string`)throw TypeError(`First argument must be a string`);if(t[0]===`+`&&!n)throw TypeError("`metadata` argument not passed");if(R(n)&&R(n.countries)){r=n;var i=t;if(!Jn.test(i))throw Error('Invalid `number` argument passed: must consist of a "+" followed by digits');var a=hn(i,void 0,void 0,void 0,r),o=a.countryCallingCode;if(n=a.number,t=o,!n)throw Error("Invalid `number` argument passed: too short")}if(!n)throw TypeError("`nationalNumber` argument is required");if(typeof n!=`string`)throw TypeError("`nationalNumber` argument must be a string");Dt(r);var s=Xt(t,r),c=s.country,l=s.callingCode;this.country=c,this.countryCallingCode=l,this.nationalNumber=n,this.number=`+`+this.countryCallingCode+this.nationalNumber,this.getMetadata=function(){return r}}return Wn(e,[{key:`setExt`,value:function(e){this.ext=e}},{key:`getPossibleCountries`,value:function(){return this.country?[this.country]:Zt(this.countryCallingCode,this.nationalNumber,this.getMetadata())}},{key:`isPossible`,value:function(){return Rt(this,{v2:!0},this.getMetadata())}},{key:`isValid`,value:function(){return Kt(this,{v2:!0},this.getMetadata())}},{key:`isNonGeographic`,value:function(){return new H(this.getMetadata()).isNonGeographicCallingCode(this.countryCallingCode)}},{key:`isEqual`,value:function(e){return this.number===e.number&&this.ext===e.ext}},{key:`getType`,value:function(){return Wt(this,{v2:!0},this.getMetadata())}},{key:`format`,value:function(e,t){return Mn(this,e,t?Bn(Bn({},t),{},{v2:!0}):{v2:!0},this.getMetadata())}},{key:`formatNational`,value:function(e){return this.format(`NATIONAL`,e)}},{key:`formatInternational`,value:function(e){return this.format(`INTERNATIONAL`,e)}},{key:`getURI`,value:function(e){return this.format(`RFC3966`,e)}}])}(),Jn=/^\+\d+$/;function q(e){"@babel/helpers - typeof";return q=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},q(e)}function Yn(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,Zn(r.key),r)}}function Xn(e,t,n){return t&&Yn(e.prototype,t),n&&Yn(e,n),Object.defineProperty(e,`prototype`,{writable:!1}),e}function Zn(e){var t=Qn(e,`string`);return q(t)==`symbol`?t:t+``}function Qn(e,t){if(q(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(q(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function $n(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function er(e,t,n){return t=Y(t),tr(e,or()?Reflect.construct(t,n||[],Y(e).constructor):t.apply(e,n))}function tr(e,t){if(t&&(q(t)==`object`||typeof t==`function`))return t;if(t!==void 0)throw TypeError(`Derived constructors may only return object or undefined`);return nr(e)}function nr(e){if(e===void 0)throw ReferenceError(`this hasn't been initialised - super() hasn't been called`);return e}function rr(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Super expression must either be null or a function`);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,`prototype`,{writable:!1}),t&&J(e,t)}function ir(e){var t=typeof Map==`function`?new Map:void 0;return ir=function(e){if(e===null||!sr(e))return e;if(typeof e!=`function`)throw TypeError(`Super expression must either be null or a function`);if(t!==void 0){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return ar(e,arguments,Y(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),J(n,e)},ir(e)}function ar(e,t,n){if(or())return Reflect.construct.apply(null,arguments);var r=[null];r.push.apply(r,t);var i=new(e.bind.apply(e,r));return n&&J(i,n.prototype),i}function or(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(or=function(){return!!e})()}function sr(e){try{return Function.toString.call(e).indexOf(`[native code]`)!==-1}catch{return typeof e==`function`}}function J(e,t){return J=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},J(e,t)}function Y(e){return Y=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},Y(e)}var X=function(e){function t(e){var n;return $n(this,t),n=er(this,t,[e]),Object.setPrototypeOf(n,t.prototype),n.name=n.constructor.name,n}return rr(t,e),Xn(t)}(ir(Error)),cr=RegExp(`(?:`+Sn()+`)$`,`i`);function lr(e){var t=e.search(cr);if(t<0)return{};for(var n=e.slice(0,t),r=e.match(cr),i=1;i<r.length;){if(r[i])return{number:n,ext:r[i]};i++}}var ur={0:`0`,1:`1`,2:`2`,3:`3`,4:`4`,5:`5`,6:`6`,7:`7`,8:`8`,9:`9`,"0":`0`,"1":`1`,"2":`2`,"3":`3`,"4":`4`,"5":`5`,"6":`6`,"7":`7`,"8":`8`,"9":`9`,"٠":`0`,"١":`1`,"٢":`2`,"٣":`3`,"٤":`4`,"٥":`5`,"٦":`6`,"٧":`7`,"٨":`8`,"٩":`9`,"۰":`0`,"۱":`1`,"۲":`2`,"۳":`3`,"۴":`4`,"۵":`5`,"۶":`6`,"۷":`7`,"۸":`8`,"۹":`9`};function dr(e){return ur[e]}function fr(e,t){var n=typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=pr(e))||t&&e&&typeof e.length==`number`){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw TypeError(`Invalid attempt to iterate non-iterable instance.
5
5
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function pr(e,t){if(e){if(typeof e==`string`)return mr(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?mr(e,t):void 0}}function mr(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function hr(e){for(var t=``,n=fr(e.split(``)),r;!(r=n()).done;){var i=r.value;t+=gr(i,t)||``}return t}function gr(e,t,n){if(e===`+`){if(t){typeof n==`function`&&n(`end`);return}return`+`}return dr(e)}var _r=`([`+W+`]|[\\-\\.\\(\\)]?)`,vr=`^\\+`+_r+`*[`+W+`]`+_r+`*$`,yr=new RegExp(vr,`g`),br=W,xr=`[`+br+`]+((\\-)*[`+br+`])*`,Sr=`[a-zA-Z]+((\\-)*[`+br+`])*`,Cr=`^(`+xr+`\\.)*`+Sr+`\\.?$`,wr=new RegExp(Cr,`g`),Tr=`tel:`,Er=`;phone-context=`,Dr=`;isub=`;function Or(e){var t=e.indexOf(Er);if(t<0)return null;var n=t+Er.length;if(n>=e.length)return``;var r=e.indexOf(`;`,n);return r>=0?e.substring(n,r):e.substring(n)}function kr(e){return e===null?!0:e.length===0?!1:yr.test(e)||wr.test(e)}function Ar(e,t){var n=t.extractFormattedPhoneNumber,r=Or(e);if(!kr(r))throw new X(`NOT_A_NUMBER`);var i;if(r===null)i=n(e)||``;else{i=``,r.charAt(0)===`+`&&(i+=r);var a=e.indexOf(Tr),o=a>=0?a+Tr.length:0,s=e.indexOf(Er);i+=e.substring(o,s)}var c=i.indexOf(Dr);if(c>0&&(i=i.substring(0,c)),i!==``)return i}var jr=250,Mr=RegExp(`[`+en+W+`]`),Nr=RegExp(`[^`+W+`#]+$`),Pr=!1;function Fr(e,t,n){t||={};var r=new H(n);if(t.defaultCountry&&!r.hasCountry(t.defaultCountry))throw t.v2?new X(`INVALID_COUNTRY`):Error(`Unknown country: ${t.defaultCountry}`);var i=Lr(e,t.v2,t.extract),a=i.number,o=i.ext,s=i.error;if(!a){if(t.v2)throw s===`TOO_SHORT`?new X(`TOO_SHORT`):new X(`NOT_A_NUMBER`);return{}}var c=zr(a,t.defaultCountry,t.defaultCallingCode,r),l=c.country,u=c.nationalNumber,d=c.countryCallingCode,f=c.countryCallingCodeSource,p=c.carrierCode;if(!r.hasSelectedNumberingPlan()){if(t.v2)throw new X(`INVALID_COUNTRY`);return{}}if(!u||u.length<2){if(t.v2)throw new X(`TOO_SHORT`);return{}}if(u.length>17){if(t.v2)throw new X(`TOO_LONG`);return{}}if(t.v2){var m=new qn(d,u,r.metadata);return l&&(m.country=l),p&&(m.carrierCode=p),o&&(m.ext=o),m.__countryCallingCodeSource=f,m}var h=(t.extended?r.hasSelectedNumberingPlan():l)?U(u,r.nationalNumberPattern()):!1;return t.extended?{country:l,countryCallingCode:d,carrierCode:p,valid:h,possible:h?!0:!!(t.extended===!0&&r.possibleLengths()&&zt(u,r)),phone:u,ext:o}:h?Rr(l,u,o):{}}function Ir(e,t,n){if(e){if(e.length>jr){if(n)throw new X(`TOO_LONG`);return}if(t===!1)return e;var r=e.search(Mr);if(!(r<0))return e.slice(r).replace(Nr,``)}}function Lr(e,t,n){var r=Ar(e,{extractFormattedPhoneNumber:function(e){return Ir(e,n,t)}});if(!r)return{};if(!On(r))return kn(r)?{error:`TOO_SHORT`}:{};var i=lr(r);return i.ext?i:{number:r}}function Rr(e,t,n){var r={country:e,phone:t};return n&&(r.ext=n),r}function zr(e,t,n,r){var i=hn(hr(e),void 0,t,n,r.metadata),a=i.countryCallingCodeSource,o=i.countryCallingCode,s=i.number,c;if(o)r.selectNumberingPlan(o);else if(s&&(t||n))t?(c=t,r.selectNumberingPlan(t),o=r.numberingPlan.callingCode()):(r.selectNumberingPlan(n),o=n,Pr&&r.isNonGeographicCallingCode(o)&&(c=`001`));else return{};if(!s)return{countryCallingCodeSource:a,countryCallingCode:o};var l=dn(hr(s),void 0,r),u=l.nationalNumber,d=l.carrierCode,f=un(o,{nationalNumber:u,metadata:r});return f&&(c=f,f===`001`||r.selectNumberingPlan(c)),{country:c,countryCallingCode:o,countryCallingCodeSource:a,nationalNumber:u,carrierCode:d}}function Z(e){"@babel/helpers - typeof";return Z=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},Z(e)}function Br(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function Vr(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Br(Object(n),!0).forEach(function(t){Hr(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Br(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Hr(e,t,n){return(t=Ur(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Ur(e){var t=Wr(e,`string`);return Z(t)==`symbol`?t:t+``}function Wr(e,t){if(Z(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(Z(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Gr(e,t,n){return Fr(e,Vr(Vr({},t),{},{v2:!0}),n)}function Q(e){"@babel/helpers - typeof";return Q=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},Q(e)}function Kr(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function qr(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Kr(Object(n),!0).forEach(function(t){Jr(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Kr(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Jr(e,t,n){return(t=Yr(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Yr(e){var t=Xr(e,`string`);return Q(t)==`symbol`?t:t+``}function Xr(e,t){if(Q(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(Q(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Zr(e,t){return ni(e)||ti(e,t)||$r(e,t)||Qr()}function Qr(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
6
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function $r(e,t){if(e){if(typeof e==`string`)return ei(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?ei(e,t):void 0}}function ei(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function ti(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t===0){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function ni(e){if(Array.isArray(e))return e}function ri(e){var t=Zr(Array.prototype.slice.call(e),4),n=t[0],r=t[1],i=t[2],a=t[3],o,s,c;if(typeof n==`string`)o=n;else throw TypeError(`A text for parsing must be a string.`);if(!r||typeof r==`string`)a?(s=i,c=a):(s=void 0,c=i),r&&(s=qr({defaultCountry:r},s));else if(R(r))i?(s=r,c=i):c=r;else throw Error(`Invalid second argument: ${r}`);return{text:o,options:s,metadata:c}}function $(e){"@babel/helpers - typeof";return $=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},$(e)}function ii(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function ai(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?ii(Object(n),!0).forEach(function(t){oi(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ii(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function oi(e,t,n){return(t=si(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function si(e){var t=ci(e,`string`);return $(t)==`symbol`?t:t+``}function ci(e,t){if($(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if($(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function li(e,t,n){t&&t.defaultCountry&&!At(t.defaultCountry,n)&&(t=ai(ai({},t),{},{defaultCountry:void 0}));try{return Gr(e,t,n)}catch(e){if(!(e instanceof X))throw e}}function ui(){var e=ri(arguments),t=e.text,n=e.options,r=e.metadata;return li(t,n,r)}function di(){return dt(ui,arguments)}function fi(e){let t=it(e);if(!t)return e;let n=di(`+${t}`);return n?.isPossible()?n.formatInternational():e}var pi=[`whatsapp`,`telegram`,`webchat`],mi={whatsapp:`WhatsApp`,telegram:`Telegram`,webchat:`Webchat`};function hi(e){return pi.map(t=>({channel:t,label:mi[t],rows:e.filter(e=>e.channel===t)})).filter(e=>e.rows.length>0)}function gi(e){if(e.isGroup===!0)return e.chatName??e.title;let t=e.operatorName??e.chatName??e.whatsappName,n=e.senderId!=null&&e.channel===`whatsapp`?fi(e.senderId):e.senderId;return t?n?`${t} ${n}`:t:n??e.title}function _i(e){let t=Math.max(0,Math.floor(e)),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=t%60;return n>0?`${n}:${String(r).padStart(2,`0`)}`:`${r}:${String(i).padStart(2,`0`)}`}async function vi(e){if(navigator.clipboard)try{return await navigator.clipboard.writeText(e),!0}catch{}try{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),n}catch{return!1}}var yi=!1;function bi(){let e=crypto.getRandomValues(new Uint8Array(16));e[6]=e[6]&15|64,e[8]=e[8]&63|128;let t=Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}function xi(){let e=typeof crypto<`u`&&typeof crypto.randomUUID==`function`;if(!yi){yi=!0;let t=typeof window<`u`&&`isSecureContext`in window?window.isSecureContext:!1;console.info(`[idempotency] uuid-source=${e?`native`:`getRandomValues`} secureContext=${t}`)}return e?crypto.randomUUID():bi()}async function Si(e,t){try{let n=await fetch(`/api/admin/session/switch-account?session_key=${encodeURIComponent(e)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({accountId:t})});if(!n.ok)return console.error(`[sub-account] switch-request-failed status=${n.status}`),null;let r=await n.json();try{sessionStorage.setItem(`maxy-admin-session-key`,r.session_key)}catch{}return r.session_key}catch(e){return console.error(`[sub-account] switch-request-failed reason=${e instanceof Error?e.message:String(e)}`),null}}var Ci=`maxy-subaccount-switch-clear`;function wi(e){let[t,n]=(0,s.useState)([]),[r,i]=(0,s.useState)(null),[a,o]=(0,s.useState)(!1),c=(0,s.useRef)(0),l=(0,s.useCallback)(async()=>{if(!e)return;let t=++c.current;try{let r=await fetch(`/api/admin/accounts?session_key=${encodeURIComponent(e)}`),a=r.ok?await r.json():null,o=a?.accounts??[],s=a?.activeAccountId??null;t===c.current&&a&&(n(o),i(s))}catch{}},[e]);(0,s.useEffect)(()=>{l()},[l]);let u=(0,s.useCallback)(()=>l(),[l]);return{subAccounts:t,activeAccountId:r,switching:a,switchAccount:(0,s.useCallback)(async(t,n)=>{if(e){o(!0);try{if(!await Si(e,t))return;let r=xi().slice(0,8),i=new URL(window.location.href);i.searchParams.delete(`session`);let a=!!(n&&n.length>0),o=a?n:i.pathname;if(o===`/chat`)try{sessionStorage.setItem(Ci,r)}catch{}try{sessionStorage.setItem(Ee,r)}catch{}window.location.assign(a?o:o+i.search+i.hash)}finally{o(!1)}}},[e]),refreshAccounts:u}}function Ti(e){let[t,n]=(0,s.useState)(()=>typeof window>`u`||typeof window.matchMedia!=`function`?!1:window.matchMedia(e).matches);return(0,s.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let t=window.matchMedia(e),r=()=>n(t.matches);return r(),t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t}export{S as $,Te as A,ue as B,Be as C,Me as D,Ne as E,_e as F,ae as G,ce as H,ge as I,re as J,ie as K,he as L,be as M,ye as N,je as O,ve as P,y as Q,P as R,Ve as S,Fe as T,oe as U,N as V,M as W,te as X,A as Y,k as Z,Xe as _,_i as a,Ue as b,ct as c,ot as d,x as et,et as f,Ke as g,Je as h,vi as i,h as it,xe as j,Ce as k,lt as l,tt as m,wi as n,l as nt,hi as o,Qe as p,j as q,Si as r,p as rt,gi as s,Ti as t,b as tt,at as u,qe as v,I as w,ze as x,We as y,de as z};
6
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function $r(e,t){if(e){if(typeof e==`string`)return ei(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?ei(e,t):void 0}}function ei(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function ti(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t===0){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function ni(e){if(Array.isArray(e))return e}function ri(e){var t=Zr(Array.prototype.slice.call(e),4),n=t[0],r=t[1],i=t[2],a=t[3],o,s,c;if(typeof n==`string`)o=n;else throw TypeError(`A text for parsing must be a string.`);if(!r||typeof r==`string`)a?(s=i,c=a):(s=void 0,c=i),r&&(s=qr({defaultCountry:r},s));else if(R(r))i?(s=r,c=i):c=r;else throw Error(`Invalid second argument: ${r}`);return{text:o,options:s,metadata:c}}function $(e){"@babel/helpers - typeof";return $=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},$(e)}function ii(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function ai(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?ii(Object(n),!0).forEach(function(t){oi(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ii(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function oi(e,t,n){return(t=si(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function si(e){var t=ci(e,`string`);return $(t)==`symbol`?t:t+``}function ci(e,t){if($(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if($(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function li(e,t,n){t&&t.defaultCountry&&!At(t.defaultCountry,n)&&(t=ai(ai({},t),{},{defaultCountry:void 0}));try{return Gr(e,t,n)}catch(e){if(!(e instanceof X))throw e}}function ui(){var e=ri(arguments),t=e.text,n=e.options,r=e.metadata;return li(t,n,r)}function di(){return dt(ui,arguments)}function fi(e){let t=it(e);if(!t)return e;let n=di(`+${t}`);return n?.isPossible()?n.formatInternational():e}var pi=[`whatsapp`,`telegram`,`webchat`],mi={whatsapp:`WhatsApp`,telegram:`Telegram`,webchat:`Webchat`};function hi(e){return pi.map(t=>({channel:t,label:mi[t],rows:e.filter(e=>e.channel===t)})).filter(e=>e.rows.length>0)}function gi(e){if(e.isGroup===!0)return e.chatName??e.title;let t=e.operatorName??e.chatName??e.whatsappName??e.telegramName,n=e.senderId!=null&&e.channel===`whatsapp`?fi(e.senderId):e.senderId;return t?n?`${t} ${n}`:t:n??e.title}function _i(e){let t=Math.max(0,Math.floor(e)),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=t%60;return n>0?`${n}:${String(r).padStart(2,`0`)}`:`${r}:${String(i).padStart(2,`0`)}`}async function vi(e){if(navigator.clipboard)try{return await navigator.clipboard.writeText(e),!0}catch{}try{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),n}catch{return!1}}var yi=!1;function bi(){let e=crypto.getRandomValues(new Uint8Array(16));e[6]=e[6]&15|64,e[8]=e[8]&63|128;let t=Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}function xi(){let e=typeof crypto<`u`&&typeof crypto.randomUUID==`function`;if(!yi){yi=!0;let t=typeof window<`u`&&`isSecureContext`in window?window.isSecureContext:!1;console.info(`[idempotency] uuid-source=${e?`native`:`getRandomValues`} secureContext=${t}`)}return e?crypto.randomUUID():bi()}async function Si(e,t){try{let n=await fetch(`/api/admin/session/switch-account?session_key=${encodeURIComponent(e)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({accountId:t})});if(!n.ok)return console.error(`[sub-account] switch-request-failed status=${n.status}`),null;let r=await n.json();try{sessionStorage.setItem(`maxy-admin-session-key`,r.session_key)}catch{}return r.session_key}catch(e){return console.error(`[sub-account] switch-request-failed reason=${e instanceof Error?e.message:String(e)}`),null}}var Ci=`maxy-subaccount-switch-clear`;function wi(e){let[t,n]=(0,s.useState)([]),[r,i]=(0,s.useState)(null),[a,o]=(0,s.useState)(!1),c=(0,s.useRef)(0),l=(0,s.useCallback)(async()=>{if(!e)return;let t=++c.current;try{let r=await fetch(`/api/admin/accounts?session_key=${encodeURIComponent(e)}`),a=r.ok?await r.json():null,o=a?.accounts??[],s=a?.activeAccountId??null;t===c.current&&a&&(n(o),i(s))}catch{}},[e]);(0,s.useEffect)(()=>{l()},[l]);let u=(0,s.useCallback)(()=>l(),[l]);return{subAccounts:t,activeAccountId:r,switching:a,switchAccount:(0,s.useCallback)(async(t,n)=>{if(e){o(!0);try{if(!await Si(e,t))return;let r=xi().slice(0,8),i=new URL(window.location.href);i.searchParams.delete(`session`);let a=!!(n&&n.length>0),o=a?n:i.pathname;if(o===`/chat`)try{sessionStorage.setItem(Ci,r)}catch{}try{sessionStorage.setItem(Ee,r)}catch{}window.location.assign(a?o:o+i.search+i.hash)}finally{o(!1)}}},[e]),refreshAccounts:u}}function Ti(e){let[t,n]=(0,s.useState)(()=>typeof window>`u`||typeof window.matchMedia!=`function`?!1:window.matchMedia(e).matches);return(0,s.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let t=window.matchMedia(e),r=()=>n(t.matches);return r(),t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t}export{S as $,Te as A,ue as B,Be as C,Me as D,Ne as E,_e as F,ae as G,ce as H,ge as I,re as J,ie as K,he as L,be as M,ye as N,je as O,ve as P,y as Q,P as R,Ve as S,Fe as T,oe as U,N as V,M as W,te as X,A as Y,k as Z,Xe as _,_i as a,Ue as b,ct as c,ot as d,x as et,et as f,Ke as g,Je as h,vi as i,h as it,xe as j,Ce as k,lt as l,tt as m,wi as n,l as nt,hi as o,Qe as p,j as q,Si as r,p as rt,gi as s,Ti as t,b as tt,at as u,qe as v,I as w,ze as x,We as y,de as z};
@@ -1,2 +1,2 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/pdf-render-B5af7vu1.js","assets/preload-helper-eAV8hweq.js"])))=>i.map(i=>d[i]);
2
- import{o as e}from"./chunk-BycB0eMI.js";import{i as t,t as n}from"./jsx-runtime-YcUntiud.js";import{B as r,G as i,Z as a,a as o,d as s,i as c,j as l,v as u,w as d,x as f}from"./useMediaQuery-BmG090FR.js";import{t as p}from"./copy-TkPJgllS.js";import{t as m}from"./play-CmSyYrB6.js";import{t as h}from"./preload-helper-eAV8hweq.js";var g=`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`,_=new Set(g.split(`,`).filter(e=>!e.startsWith(`.`))),v=50*1024*1024;function y(e){switch(e){case`expanded`:return!0;case`collapsed`:return!1;default:return}}var b=a(`check-check`,[[`path`,{d:`M18 6 7 17l-5-5`,key:`116fxf`}],[`path`,{d:`m22 10-7.5 7.5L13 16`,key:`ke71qq`}]]),x=a(`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`}]]),S=a(`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`}]]),C=a(`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`}]]),w=a(`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`}]]),T=a(`reply`,[[`path`,{d:`M20 18v-2a4 4 0 0 0-4-4H4`,key:`5vmcpk`}],[`path`,{d:`m9 17-5-5 5-5`,key:`nvlc11`}]]),E=a(`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`}]]),D=e(t(),1),O=n(),k=200;function ee({children:e,tail:t=null,repinSignals:n,onReachTop:r,prependToken:i=0}){let a=(0,D.useRef)(null),o=(0,D.useRef)(null),s=(0,D.useRef)(!0),[c,l]=(0,D.useState)(!0),u=(0,D.useRef)(0),d=(0,D.useRef)(0),f=(0,D.useRef)(!1),p=(0,D.useRef)(r);p.current=r;let m=()=>{let e=a.current;if(!e)return;let t=e.clientHeight,n=e.scrollHeight,r=t!==u.current||n!==d.current;if(u.current=t,d.current=n,r){s.current&&(e.scrollTop=e.scrollHeight);return}let i=n-e.scrollTop-t<=32;s.current=i,l(e=>e===i?e:i);let o=e.scrollTop<=k;o&&!f.current&&p.current?.(),f.current=o},h=()=>{let e=a.current;e&&(e.scrollTop=e.scrollHeight,d.current=e.scrollHeight,u.current=e.clientHeight,s.current=!0,l(!0))},g=t!=null;return(0,D.useLayoutEffect)(()=>{let e=a.current;if(!e||i===0)return;let t=e.scrollHeight-d.current;t>0&&(e.scrollTop+=t),d.current=e.scrollHeight},[i]),(0,D.useLayoutEffect)(()=>{let e=a.current;e&&s.current&&(e.scrollTop=e.scrollHeight),e&&(d.current=e.scrollHeight,u.current=e.clientHeight)},[...n,g]),(0,D.useLayoutEffect)(()=>{if(typeof ResizeObserver>`u`)return;let e=new ResizeObserver(()=>m());return a.current&&e.observe(a.current),o.current&&e.observe(o.current),()=>e.disconnect()},[]),(0,O.jsxs)(`div`,{className:`wa-reader`,children:[(0,O.jsx)(`div`,{className:`wa-reader-thread`,ref:a,onScroll:m,children:(0,O.jsxs)(`div`,{className:`wa-thread-scroll`,ref:o,children:[e,t]})}),!c&&(0,O.jsx)(`button`,{type:`button`,className:`wa-jump`,onClick:h,"aria-label":`Jump to latest message`,title:`Jump to latest message`,children:`↓`})]})}var A={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.`},j={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 M(e,t=`admin`){return t===`public`?j[e]:A[e]}function N(e){return e===`whatsapp`?` · via WhatsApp`:e===`webchat`?` · via web`:``}var P=56,te=5;function ne(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 re({src:e,filename:t,onDecodeFail:n,onMediaError:r}){let i=(0,D.useRef)(null),a=(0,D.useRef)(null),s=(0,D.useRef)(!1),[c,l]=(0,D.useState)([]),[u,d]=(0,D.useState)(void 0),[f,p]=(0,D.useState)(!1),[h,g]=(0,D.useState)(0),[_,v]=(0,D.useState)(0);(0,D.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),d(r);let a=await o.decodeAudioData(await i.arrayBuffer());if(t)return;l(ne(a.getChannelData(0),P)),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&&(f?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)},x=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))*_)},S=e=>{x(e.clientX);let t=e=>x(e.clientX),n=()=>{window.removeEventListener(`mousemove`,t),window.removeEventListener(`mouseup`,n)};window.addEventListener(`mousemove`,t),window.addEventListener(`mouseup`,n)},C=e=>{if(!(_>0))return;let t=i.current?.currentTime??0;switch(e.key){case`ArrowRight`:case`ArrowUp`:b(t+te),e.preventDefault();break;case`ArrowLeft`:case`ArrowDown`:b(t-te),e.preventDefault();break;case`Home`:b(0),e.preventDefault();break;case`End`:b(_),e.preventDefault();break;default:break}},T=_>0?Math.min(1,h/_):0,E=Math.round(T*P),k=o(h>0?h:_);return(0,O.jsxs)(`div`,{className:`voice-note`,children:[(0,O.jsx)(`button`,{type:`button`,className:`voice-note-play`,"aria-label":`${f?`Pause`:`Play`} ${t}`,onClick:y,children:f?(0,O.jsx)(w,{size:16,"aria-hidden":!0}):(0,O.jsx)(m,{size:16,"aria-hidden":!0})}),(0,O.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:S,onKeyDown:C,children:(c.length?c:Array.from({length:P},()=>0)).map((e,t)=>(0,O.jsx)(`span`,{className:`voice-note-bar${t<E?` is-played`:``}`,style:{height:`${Math.max(10,Math.round(e*100))}%`}},t))}),(0,O.jsx)(`span`,{className:`voice-note-time`,children:k}),(0,O.jsx)(`audio`,{ref:i,className:`voice-note-audio`,preload:`metadata`,src:u,"aria-label":t,onPlay:()=>p(!0),onPause:()=>p(!1),onEnded:()=>p(!1),onError:()=>r?.(),onLoadedMetadata:e=>{let t=e.currentTarget.duration;Number.isFinite(t)&&t>0&&v(t)},onTimeUpdate:e=>g(e.currentTarget.currentTime)})]})}var ie=/\.(png|jpe?g|gif|webp|svg|bmp)$/i,F=/\.pdf$/i;function ae(e,t){return(t?t.startsWith(`image/`):ie.test(e))?`image`:t&&t.startsWith(`audio/`)?`audio`:(t?t===`application/pdf`:F.test(e))?`pdf`:`file`}function oe(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 se(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,O.jsxs)(`a`,{className:`chat-attachment-chip`,href:e,download:t,children:[(0,O.jsx)(C,{size:14,"aria-hidden":!0}),n]})}function z({href:e,filename:t,className:n,size:r=14,onClick:a}){return(0,O.jsx)(`a`,{className:n,href:e,download:t,"aria-label":`Download ${t}`,onClick:a,children:(0,O.jsx)(i,{size:r,"aria-hidden":!0})})}function ce({src:e,filename:t,sizeBytes:n,expandable:r,onFail:i}){let[a,o]=(0,D.useState)(!1),[s,c]=(0,D.useState)(!1),l=n==null?t:`${t} · ${L(n)}`;return s?(0,O.jsx)(R,{href:e,filename:t,label:l}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`span`,{className:`chat-attachment-image-wrap`,children:[(0,O.jsx)(`img`,{className:`chat-attachment-image`,src:e,alt:t,onClick:r?()=>o(!0):void 0,onError:()=>{c(!0),i?.(`fetch`)}}),(0,O.jsx)(z,{href:e,filename:t,className:`chat-attachment-download`})]}),r&&a&&(0,O.jsx)(`div`,{className:`chat-attachment-overlay`,role:`dialog`,"aria-label":t,onClick:()=>o(!1),children:(0,O.jsx)(`img`,{className:`chat-attachment-overlay-image`,src:e,alt:t})})]})}var le=280,ue=360,de=16;function fe({src:e,filename:t,sizeBytes:n,onFail:i}){let[a,o]=(0,D.useState)(!1),[s,c]=(0,D.useState)(!1),l=(0,D.useRef)(null),u=n==null?t:`${t} · ${L(n)}`;return(0,D.useEffect)(()=>{let t=!1,n=null;return(async()=>{try{let{loadPdf:r,renderPageToFit:i}=await h(async()=>{let{loadPdf:e,renderPageToFit:t}=await import(`./pdf-render-B5af7vu1.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,le,ue)}catch{t||(c(!0),i?.(`render`))}})(),()=>{t=!0;try{n?.destroy()}catch{}}},[e]),s?(0,O.jsx)(R,{href:e,filename:t,label:u}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`div`,{className:`chat-attachment-pdf`,children:[(0,O.jsx)(`canvas`,{ref:l,className:`chat-attachment-pdf-canvas`,"aria-label":t}),(0,O.jsx)(z,{href:e,filename:t,className:`chat-attachment-download`}),(0,O.jsx)(`button`,{type:`button`,className:`chat-attachment-pdf-expand`,"aria-label":`Expand ${t}`,onClick:()=>o(!0),children:(0,O.jsx)(r,{size:14,"aria-hidden":!0})})]}),a&&(0,O.jsx)(pe,{src:e,filename:t,label:u,onClose:()=>o(!1),onFail:i})]})}function pe({src:e,filename:t,label:n,onClose:r,onFail:i}){let a=(0,D.useRef)(null),o=(0,D.useRef)(null),[s,c]=(0,D.useState)(null),[u,d]=(0,D.useState)(!1);return(0,D.useEffect)(()=>{let t=!1;return(async()=>{try{let{loadPdf:n}=await h(async()=>{let{loadPdf:e}=await import(`./pdf-render-B5af7vu1.js`);return{loadPdf:e}},__vite__mapDeps([0,1])),r=await n(e);if(t){try{r.destroy()}catch{}return}o.current=r,c(r.numPages)}catch{t||(d(!0),i?.(`render`))}})(),()=>{t=!0;try{o.current?.destroy()}catch{}}},[e]),(0,D.useEffect)(()=>{if(s==null)return;let e=a.current,t=o.current;if(!e||!t)return;let n=!1;return(async()=>{try{let{renderPageToWidth:r}=await h(async()=>{let{renderPageToWidth:e}=await import(`./pdf-render-B5af7vu1.js`);return{renderPageToWidth:e}},__vite__mapDeps([0,1])),i=Array.from(e.querySelectorAll(`canvas.chat-attachment-overlay-page`)),a=Math.max(e.clientWidth-de*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}},[s]),(0,O.jsxs)(`div`,{className:`chat-attachment-overlay`,role:`dialog`,"aria-label":t,onClick:r,children:[(0,O.jsx)(`div`,{ref:a,className:`chat-attachment-overlay-pdf`,onClick:e=>e.stopPropagation(),children:u?(0,O.jsx)(R,{href:e,filename:t,label:n}):Array.from({length:s??0},(e,n)=>(0,O.jsx)(`canvas`,{className:`chat-attachment-overlay-page`,"aria-label":`${t} page ${n+1}`},n))}),(0,O.jsx)(z,{href:e,filename:t,className:`chat-attachment-overlay-download`,size:20,onClick:e=>e.stopPropagation()}),(0,O.jsx)(`button`,{type:`button`,className:`chat-attachment-overlay-close`,"aria-label":`Close`,onClick:r,children:(0,O.jsx)(l,{size:20,"aria-hidden":!0})})]})}function me({src:e,filename:t,onFail:n}){let[r,i]=(0,D.useState)(!1);return r?(0,O.jsx)(`audio`,{className:`chat-attachment-audio`,controls:!0,preload:`metadata`,src:e,"aria-label":t,onError:()=>n?.(`fetch`)}):(0,O.jsx)(re,{src:e,filename:t,onDecodeFail:()=>{i(!0),n?.(`render`)},onMediaError:()=>{i(!0),n?.(`fetch`)}})}function B({filename:e,href:t,mimeType:n,sizeBytes:r,expandable:i,telemetry:a}){let o=ae(e,n);(0,D.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,O.jsx)(ce,{src:t,filename:e,sizeBytes:r,expandable:i,onFail:s});if(o===`audio`&&t)return(0,O.jsx)(me,{src:t,filename:e,onFail:s});if(o===`pdf`&&t)return(0,O.jsx)(fe,{src:t,filename:e,sizeBytes:r,onFail:s});let c=r==null?e:`${e} · ${L(r)}`;return t?(0,O.jsx)(R,{href:t,filename:e,label:c}):(0,O.jsxs)(`p`,{className:`chat-doc`,children:[(0,O.jsx)(C,{size:14,"aria-hidden":!0,style:{verticalAlign:`text-bottom`}}),` `,c]})}var he=/^-?\d+(\.\d+)?,-?\d+(\.\d+)?$/,ge=/^\[(?:live )?location: (.+)\]$/;function V(e){let t=ge.exec(e.trim());if(!t)return{kind:`none`};let n=t[1].split(` — `),r=n[n.length-1].trim();if(!he.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}}var _e=/^\[live location: .+\]$/;function ve(e){let t=new Map;e.forEach((e,n)=>{if(e.kind!==`turn`)return;let r=e.turn;if(r.kind!==`telegram-persisted`||!_e.test(r.text.trim()))return;let i=V(r.text);if(i.kind!==`point`)return;let a=r.messageId.replace(/:edit:[^:]*$/,``),o=t.get(a)??[];o.push({index:n,point:{lat:i.lat,lon:i.lon,ts:r.ts}}),t.set(a,o)});let n=new Map;for(let e of t.values())if(!(e.length<2)){n.set(e[0].index,{role:`head`,points:e.map(e=>e.point)});for(let t of e.slice(1))n.set(t.index,{role:`member`})}return n}function H(e,t){return(e+180)/360*2**t}function U(e,t){return(1-Math.asinh(Math.tan(e*Math.PI/180))/Math.PI)/2*2**t}function ye(e,t,n){let r=2**n,i=Math.round(e)-1,a=(i%r+r)%r,o=Math.min(Math.max(Math.round(t)-1,0),r-2);return{tiles:[{x:a,y:o},{x:(a+1)%r,y:o},{x:a,y:o+1},{x:(a+1)%r,y:o+1}].map(e=>({...e,url:`https://tile.openstreetmap.org/${n}/${e.x}/${e.y}.png`})),offsetX:e*256-i*256,offsetY:t*256-o*256}}function be(e,t,n=16){return ye(H(t,n),U(e,n),n)}function xe(e){let t=[];for(let n of e){let e=t[t.length-1],r=e===void 0?0:Math.round((e-n)/360);t.push(r===0?n:n+r*360)}return t}function Se(e){let t=xe(e.map(e=>e.lon)),n=1;for(let r=16;r>=1;r--){let i=t.map(e=>H(e,r)*256),a=e.map(e=>U(e.lat,r)*256);if(Math.max(...i)-Math.min(...i)<=240&&Math.max(...a)-Math.min(...a)<=160){n=r;break}}let r=t.map(e=>H(e,n)),i=e.map(e=>U(e.lat,n)),a=(Math.min(...r)+Math.max(...r))/2,o=(Math.min(...i)+Math.max(...i))/2,s=ye(a,o,n);return{zoom:n,...s,points:r.map((e,t)=>({x:s.offsetX+(e-a)*256,y:s.offsetY+(i[t]-o)*256}))}}var W=0,G=0,K=0,q=0;function Ce(){return{maps:W,tracks:G,trackPoints:K,tileErrors:q}}function we({lat:e,lon:t,msgKeyId:n}){let{tiles:r,offsetX:i,offsetY:a}=be(e,t);return(0,D.useEffect)(()=>(W+=1,()=>{--W}),[]),(0,O.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,O.jsxs)(`span`,{className:`wa-map-viewport`,children:[(0,O.jsx)(`span`,{className:`wa-map-block`,style:{left:`calc(50% - ${i}px)`,top:`calc(50% - ${a}px)`},children:r.map(e=>(0,O.jsx)(`img`,{className:`wa-map-tile`,src:e.url,alt:``,width:256,height:256,loading:`lazy`,onError:()=>{q+=1}},e.url))}),(0,O.jsx)(`span`,{className:`wa-map-pin`,"aria-hidden":!0}),(0,O.jsx)(`span`,{className:`wa-map-credit`,children:`© OpenStreetMap contributors`})]})})}function Te({points:e,formatTime:t,msgKeyId:n}){let{zone:r}=u(),i=Se(e),a=e.length;(0,D.useEffect)(()=>(G+=1,K+=a,()=>{--G,K-=a}),[a]);let o=e[a-1],s=i.points[0],c=i.points[a-1],l=t(e[0].ts,r),d=t(o.ts,r);return(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(`a`,{className:`wa-map`,href:`https://www.openstreetmap.org/?mlat=${o.lat}&mlon=${o.lon}#map=${i.zoom}/${o.lat}/${o.lon}`,target:`_blank`,rel:`noopener noreferrer`,style:{width:240,height:160},children:(0,O.jsxs)(`span`,{className:`wa-map-viewport`,children:[(0,O.jsxs)(`span`,{className:`wa-map-block`,style:{left:`calc(50% - ${i.offsetX}px)`,top:`calc(50% - ${i.offsetY}px)`},children:[i.tiles.map(e=>(0,O.jsx)(`img`,{className:`wa-map-tile`,src:e.url,alt:``,width:256,height:256,loading:`lazy`,onError:()=>{q+=1}},e.url)),(0,O.jsxs)(`svg`,{className:`wa-map-track`,width:256*2,height:256*2,"aria-hidden":!0,children:[(0,O.jsx)(`polyline`,{points:i.points.map(e=>`${e.x},${e.y}`).join(` `)}),(0,O.jsx)(`circle`,{className:`wa-map-track-start`,cx:s.x,cy:s.y,r:4}),(0,O.jsx)(`circle`,{className:`wa-map-track-now`,cx:c.x,cy:c.y,r:5})]})]}),(0,O.jsx)(`span`,{className:`wa-map-credit`,children:`© OpenStreetMap contributors`})]})}),(0,O.jsxs)(`span`,{className:`wa-map-track-caption`,children:[a,` updates · `,l,` to `,d]})]})}function J({text:e,body:t,msgKeyId:n}){let r=V(e);return(0,O.jsxs)(O.Fragment,{children:[r.kind===`point`&&(0,O.jsx)(we,{lat:r.lat,lon:r.lon,msgKeyId:n}),(0,O.jsx)(`p`,{className:`wa-body`,children:t})]})}function Ee(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=V(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 De(e,t){let{maps:n,tracks:r,trackPoints:i,tileErrors:a}=t;return e.rejected>0||e.parsed>n+i||r===0&&i>0?`[operator-ui] op=location-census-alarm bodies=${e.bodies} withLabel=${e.withLabel} parsed=${e.parsed} rejected=${e.rejected} maps=${n} tracks=${r} trackPoints=${i} tileErrors=${a}`:null}var Oe=20;function ke(e){let t=e.replace(/\/(store-)?stream$/,(e,t)=>t?`/store-backfill`:`/backfill`);return t===e?``:t}function Ae(e,...t){let[n,r,i,a,o]=t,[s,c]=(0,D.useState)([]),[l,u]=(0,D.useState)(null),[d,f]=(0,D.useState)(!1),[p,m]=(0,D.useState)(0),h=(0,D.useRef)(!1);(0,D.useEffect)(()=>{c([]),u(null),f(!1),m(0),h.current=!1},[a,n,r,i,e]);let g=(0,D.useCallback)(e=>u(e),[]),_=(0,D.useCallback)(()=>{!e||l===null||l<=0||h.current||(h.current=!0,f(!0),(async()=>{let t=l,a=[],s=0;try{for(;t>0&&a.length===0&&s<Oe;){s+=1;let c=await fetch(`${e}?${Me(e,n,r,i,t,o)}`);if(!c.ok)break;let l=await c.json();if(!Array.isArray(l.turns))break;a.unshift(...l.turns);let u=l.reachedStart?0:l.from;if(!l.reachedStart&&u>=t){je(e,t,l.from);break}t=u}}catch{}finally{a.length>0&&(c(e=>[...a,...e]),m(e=>e+1)),u(t),h.current=!1,f(!1)}})())},[e,n,r,i,l]);return{turns:s,hasOlder:l!==null&&l>0,loadingOlder:d,prependCount:p,loadOlder:_,setTurns:c,onWindow:g}}function je(e,t,n){let r=e.endsWith(`/store-backfill`)?`store`:e.includes(`/public-reader/`)?`public`:`session`;try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`event`,source:`reader-backfill`,op:`backfill-no-advance`,reader:r,before:t,from:n}),keepalive:!0}).catch(()=>{})}catch{}}function Me(e,t,n,r,i,a=`remoteJid`){let o=e.endsWith(`/store-backfill`);return new URLSearchParams(o?{accountId:t,[a]:n,session_key:r,before:String(i)}:{sessionId:t,projectDir:n,session_key:r,before:String(i)}).toString()}function Ne(e,t,n,r=`/api/session-reader/stream`,i=e,a=!0){let[o,s]=(0,D.useState)([]),[c,l]=(0,D.useState)(`open`),[u,d]=(0,D.useState)(null),f=Ae(ke(r),e,t,n,i),{onWindow:p}=f,m=(0,D.useRef)([]);return(0,D.useEffect)(()=>{m.current=o},[o]),(0,D.useEffect)(()=>{s([]),m.current=[],d(null)},[i,t,n,r]),(0,D.useEffect)(()=>{if(l(`open`),!a)return;let i=m.current.slice(),o=i.map(Pe),c=0,u=i.length>0,f=`${r}?sessionId=${encodeURIComponent(e)}&projectDir=${encodeURIComponent(t)}&session_key=${encodeURIComponent(n)}`,h=new EventSource(f);return h.onopen=()=>{l(`open`)},h.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(u){if(c<o.length&&Pe(t)===o[c]){c+=1;return}u=!1}s(e=>[...e,t])},h.addEventListener(`activity`,e=>{try{d(JSON.parse(e.data))}catch{}}),h.addEventListener(`activity-clear`,()=>d(null)),h.addEventListener(`window`,e=>{try{let t=JSON.parse(e.data);typeof t.from==`number`&&p(t.from)}catch{}}),h.onerror=()=>{h.readyState===2&&(console.error(`[admin-ui] wa-stream onerror readyState=${h.readyState}`),l(`error`))},()=>h.close()},[e,t,n,r,i,a,p]),{turns:(0,D.useMemo)(()=>[...f.turns,...o],[f.turns,o]),status:c,subagentActivity:u,hasOlder:f.hasOlder,loadingOlder:f.loadingOlder,prependCount:f.prependCount,loadOlder:f.loadOlder}}function Pe(e){return JSON.stringify(e)}function Fe(e,t,n,r,i,a=!0){let[o,s]=(0,D.useState)([]),[c,l]=(0,D.useState)(`open`),u=Ae(`${e}/store-backfill`,n,r,i,`${n}|${r}`,t),{onWindow:d,setTurns:f}=u;return(0,D.useEffect)(()=>{if(s([]),l(`open`),!a||!n||!r)return;let o=`${e}/store-stream?accountId=${encodeURIComponent(n)}&${t}=${encodeURIComponent(r)}&session_key=${encodeURIComponent(i)}`,c=new EventSource(o);return c.onopen=()=>l(`open`),c.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch{return}s(e=>[...e,t])},c.addEventListener(`window`,e=>{try{let t=JSON.parse(e.data);typeof t.from==`number`&&d(t.from)}catch{}}),c.addEventListener(`reaction`,e=>{let t;try{t=JSON.parse(e.data)}catch{return}let n=e=>e.map(e=>e.kind===`whatsapp-persisted`&&e.msgKeyId===t.targetMsgKeyId?{...e,reactions:t.reactions}:e);s(n),f(n)}),c.onerror=()=>{c.readyState===2&&l(`error`)},()=>c.close()},[e,t,n,r,i,a,d,f]),{turns:(0,D.useMemo)(()=>[...u.turns,...o].sort((e,t)=>String(e.ts??``).localeCompare(String(t.ts??``))),[u.turns,o]),status:c,hasOlder:u.hasOlder,loadingOlder:u.loadingOlder,prependCount:u.prependCount,loadOlder:u.loadOlder}}var Ie=e=>{if(!e)return 1/0;let t=new Date(e).getTime();return Number.isNaN(t)?1/0:t};function Le(e,t){let n=[],r=0;return e.forEach((e,t)=>n.push({sort:Ie(e.ts),sub:1,ins:r++,item:{kind:`turn`,turn:e,idx:t}})),t.forEach(e=>n.push({sort:Ie(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 Re(e,t,n=!0){let[r,i]=(0,D.useState)([]);return(0,D.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 ze=new Set([`operator-inbound`,`operator-typed`,`agent-reply`,`agent-reply-document`,`agent-file`,`agent-error`,`agent-webchat-final`,`agent-send-party`,`whatsapp-persisted`]),Be=[`#c2185b`,`#7b1fa2`,`#512da8`,`#303f9f`,`#1976d2`,`#0288d1`,`#0097a7`,`#00796b`,`#388e3c`,`#689f38`,`#af6c00`,`#e64a19`,`#5d4037`,`#455a64`,`#d81b60`,`#8e24aa`,`#3949ab`,`#039be5`,`#00897b`,`#6d4c41`];function Ve(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 He(e){return Be[Ve(e)%Be.length]}function Ue({accountId:e,jid:t,sessionKey:n,className:r=`wa-web-avatar`,size:i=20}){let[a,o]=(0,D.useState)(null);if(!t||a===t)return(0,O.jsx)(`span`,{className:r,"aria-hidden":!0,children:(0,O.jsx)(E,{size:i})});let s=`/api/whatsapp-reader/avatar?session_key=${encodeURIComponent(n)}&accountId=${encodeURIComponent(e)}&jid=${encodeURIComponent(t)}`;return(0,O.jsx)(`span`,{className:r,"aria-hidden":!0,children:(0,O.jsx)(`img`,{className:`wa-avatar-img`,src:s,alt:``,onError:()=>o(t)})})}function Y(e,t){if(!e)return``;let n=new Date(e);if(Number.isNaN(n.getTime()))return``;let r=d(n,t);return`${String(r.hh).padStart(2,`0`)}:${String(r.mm).padStart(2,`0`)}`}function X(e){let t=e.lastIndexOf(`/`);return t===-1?e:e.slice(t+1)}var We=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],Ge=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`];function Z(e,t){if(!e)return null;let n=new Date(e);return Number.isNaN(n.getTime())?null:f(n,t)}function Ke(e,t,n=new Date){if(!e)return``;let r=new Date(e);if(Number.isNaN(r.getTime()))return``;let i=f(r,t);if(i===f(n,t))return`Today`;let a=d(n,t);if(i===f(new Date(Date.UTC(a.y,a.m-1,a.d)-864e5),`UTC`))return`Yesterday`;let o=d(r,t);return`${We[new Date(Date.UTC(o.y,o.m-1,o.d)).getUTCDay()]} ${o.d} ${Ge[o.m-1]} ${o.y}`}function qe(e){return e.kind===`turn`?e.turn.ts:e.entry.ts}function Je({ts:e,prevTs:t=null}){let{zone:n}=u(),r=Z(e,n);return r===null||t!==null&&Z(t,n)===r?null:(0,O.jsx)(`div`,{className:`day-divider`,role:`separator`,children:(0,O.jsx)(`span`,{className:`day-divider-label`,children:Ke(e,n)})})}function Ye({ts:e,className:t}){let{zone:n}=u();return(0,O.jsx)(`time`,{className:t,children:Y(e,n)})}function Xe(){return(0,O.jsx)(`div`,{className:`session-divider`,role:`separator`,children:(0,O.jsx)(`span`,{className:`session-divider-label`,children:`Conversation continued`})})}function Q({label:e,ts:t,colour:n}){let{zone:r}=u();return(0,O.jsxs)(`div`,{className:`wa-turn-head`,children:[(0,O.jsx)(`span`,{className:`wa-who`,style:n?{color:n}:void 0,children:e}),(0,O.jsx)(`time`,{className:`wa-time`,children:Y(t,r)})]})}function Ze({turn:e}){let[t,n]=(0,D.useState)(!1),{zone:r}=u(),i=e.kind===`tool-result`,a=i?`wa-turn wa-turn-result${e.isError?` is-error`:``}`:`wa-turn wa-turn-tool`,o=i?e.isError?`result (error)`:`result`:`↳ ${e.name}`,s=i?e.text:JSON.stringify(e.input,null,2);return(0,O.jsxs)(`div`,{className:a,children:[(0,O.jsxs)(`button`,{type:`button`,className:`wa-tool-toggle`,"aria-expanded":t,onClick:()=>n(e=>!e),children:[(0,O.jsx)(`span`,{className:`wa-chevron`,children:t?`▾`:`▸`}),(0,O.jsx)(`span`,{className:`wa-who`,children:o}),(0,O.jsx)(`time`,{className:`wa-time`,children:Y(e.ts,r)})]}),t&&(0,O.jsx)(`pre`,{className:`wa-code`,children:s})]})}function Qe({entry:e,sessionId:t,sessionKey:n}){let[r,i]=(0,D.useState)(!1),[a,o]=(0,D.useState)(null),{zone:s}=u(),c=()=>{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,O.jsxs)(`div`,{className:`wa-turn wa-turn-directive`,children:[(0,O.jsxs)(`button`,{type:`button`,className:`wa-tool-toggle`,"aria-expanded":r,onClick:c,children:[(0,O.jsx)(`span`,{className:`wa-chevron`,children:r?`▾`:`▸`}),(0,O.jsxs)(`span`,{className:`wa-who`,children:[`⚙ directive injected (`,e.len,` B)`]}),(0,O.jsx)(`time`,{className:`wa-time`,children:Y(e.ts,s)})]}),r&&(0,O.jsx)(`pre`,{className:`wa-code`,children:a??`Loading…`})]})}function $e(e){return`text`in e&&typeof e.text==`string`?e.text:``}function $(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,O.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,O.jsx)(O.Fragment,{children:a})}var et={onFail:({kind:e,mime:t,reason:n})=>console.warn(`[operator-ui] op=reader-attachment-fail kind=${e} mime=${t??``} reason=${n}`)};function tt(e,t,n,r){switch(e.kind){case`operator-inbound`:return(0,O.jsxs)(`div`,{className:`wa-turn wa-turn-in`,children:[(0,O.jsx)(Q,{label:`Operator${N(e.source)}`,ts:e.ts}),e.text&&(0,O.jsx)(J,{text:e.text,body:e.text}),e.attachments&&e.attachments.length>0&&(0,O.jsx)(`div`,{className:`chat-attachment-list`,children:e.attachments.map((e,t)=>(0,O.jsx)(B,{expandable:!0,filename:e.filename,mimeType:e.mimeType,sizeBytes:e.sizeBytes,href:I(e.attachmentId,n.audience,n.sessionId,n.sessionKey),telemetry:et},t))})]},t);case`operator-typed`:return(0,O.jsxs)(`div`,{className:`wa-turn wa-turn-in wa-turn-typed`,children:[(0,O.jsx)(Q,{label:`Operator (web)`,ts:e.ts}),(0,O.jsx)(J,{text:e.text,body:e.text})]},t);case`agent-text`:return(0,O.jsxs)(`div`,{className:`wa-turn wa-turn-think`,children:[(0,O.jsx)(Q,{label:`Agent`,ts:e.ts}),(0,O.jsx)(J,{text:e.text,body:e.text})]},t);case`agent-reply`:return(0,O.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,O.jsx)(Q,{label:`Agent`,ts:e.ts}),(0,O.jsx)(J,{text:e.text,body:e.text})]},t);case`agent-send-party`:return(0,O.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,O.jsx)(Q,{label:`Agent to ${e.phone}`,ts:e.ts}),(0,O.jsx)(J,{text:e.text,body:e.text})]},t);case`agent-reply-document`:return(0,O.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,O.jsx)(Q,{label:`Agent`,ts:e.ts}),(0,O.jsxs)(`p`,{className:`wa-doc`,children:[(0,O.jsx)(C,{size:14,"aria-hidden":!0,style:{verticalAlign:`text-bottom`}}),` `,`sent document(s): `,e.files.map(X).join(`, `)]}),e.caption&&(0,O.jsx)(`p`,{className:`wa-body`,children:e.caption})]},t);case`agent-file`:return(0,O.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,O.jsx)(Q,{label:`Agent`,ts:e.ts}),e.files.map((t,r)=>{let i=X(t),a=e.downloads?.[r];return(0,O.jsx)(B,{expandable:!0,filename:i,href:a?oe(a,n.sessionId,n.sessionKey,F.test(i)?`inline`:void 0):void 0,telemetry:et},r)}),e.caption&&(0,O.jsx)(`p`,{className:`wa-body`,children:e.caption})]},t);case`telegram-persisted`:{let i=e.origin===`operator-manual`,a=e.fromMe?i?`You`:`Sent`:e.senderName??`Contact`;return(0,O.jsxs)(`div`,{className:`wa-turn ${e.fromMe?`wa-turn-out`:`wa-turn-in`}${i?` wa-op-manual`:``}`,children:[(0,O.jsx)(Q,{label:a,ts:e.ts}),e.text&&r?.role===`head`&&(0,O.jsx)(Te,{points:r.points,formatTime:Y}),e.text&&r&&(0,O.jsx)(`p`,{className:`wa-body`,children:$(e.text,n.highlight)}),e.text&&!r&&(0,O.jsx)(J,{text:e.text,body:$(e.text,n.highlight)})]},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&&s(e.senderJid)?e.senderJid:null;return(0,O.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,O.jsx)(Ue,{accountId:n.storeAccountId,jid:a,sessionKey:n.sessionKey,className:`wa-bubble-avatar`,size:14}),n.onReplyTo&&e.msgKeyId&&(0,O.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,O.jsx)(T,{size:14})}),n.showCopy&&e.text&&(0,O.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,O.jsx)(p,{size:14})}),e.quoted&&(0,O.jsxs)(`div`,{className:`wa-quoted`,children:[(0,O.jsx)(`span`,{className:`wa-quoted-who`,children:e.quoted.fromMe?`You`:e.quoted.sender??`Contact`}),(0,O.jsx)(`span`,{className:`wa-quoted-body`,children:e.quoted.body||`Message`})]}),(0,O.jsx)(Q,{label:i,ts:e.ts,colour:n.groupThread&&!e.fromMe?He(e.senderTelephone||e.senderName||``):void 0}),e.text&&(0,O.jsx)(J,{text:e.text,body:$(e.text,n.highlight),msgKeyId:e.msgKeyId??void 0}),e.attachments&&e.attachments.length>0&&(0,O.jsx)(`div`,{className:`chat-attachment-list`,children:e.attachments.map((e,t)=>(0,O.jsx)(B,{expandable:!0,filename:e.filename,mimeType:e.mimeType,sizeBytes:e.sizeBytes,href:I(e.attachmentId,n.audience,n.sessionId,n.sessionKey),telemetry:et},t))}),e.reactions&&e.reactions.length>0&&(0,O.jsx)(`div`,{className:`wa-reactions`,children:e.reactions.map((e,t)=>(0,O.jsx)(`span`,{className:`wa-reaction`,title:e.reactorName??void 0,children:e.emoji},t))}),(0,O.jsxs)(`span`,{className:`wa-bubble-meta`,children:[r&&(0,O.jsx)(`span`,{className:`wa-op-tag`,children:`You`}),(0,O.jsx)(Ye,{ts:e.ts,className:`wa-bubble-time`}),e.fromMe&&(0,O.jsx)(b,{size:14,className:`wa-bubble-tick`,"aria-hidden":!0})]})]},t)}case`session-continued`:return(0,O.jsx)(Xe,{},t);case`harness-internal`:return null;case`tool-call`:case`tool-result`:return(0,O.jsx)(Ze,{turn:e},t);case`agent-error`:return(0,O.jsxs)(`div`,{className:`wa-turn wa-turn-error`,role:`alert`,children:[(0,O.jsx)(Q,{label:`Agent`,ts:e.ts}),(0,O.jsx)(`p`,{className:`wa-body wa-error-body`,children:M(e.code,`admin`)}),e.code===`agent_error`&&e.raw&&(0,O.jsx)(`pre`,{className:`wa-code`,children:e.raw})]},t)}}function nt(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=ve(e),d=[],f=null;return e.forEach((e,r)=>{let i=qe(e);i!==null&&!Number.isNaN(new Date(i).getTime())&&(d.push((0,O.jsx)(Je,{ts:i,prevTs:f},`day-${r}`)),f=i),d.push(e.kind===`turn`?tt(e.turn,r,l,u.get(r)):(0,O.jsx)(Qe,{entry:e.entry,sessionId:t,sessionKey:n},r))}),d}function rt(e){return e.filter(e=>e.kind===`turn`&&ze.has(e.turn.kind)&&!(e.turn.kind===`operator-inbound`&&e.turn.scheduled))}var it=(0,D.memo)(function({sessionId:e,projectDir:t,sessionKey:n,renderItems:r=nt,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=Ne(e,t,n,s,u,!_),y=p?.channel===`telegram`?`/api/telegram-reader`:`/api/whatsapp-reader`,b=p?.channel===`telegram`?`channelKey`:`remoteJid`,x=p?p.channel===`telegram`?p.channelKey:p.remoteJid:``,S=Fe(y,b,p?.accountId??``,x,n,_),{turns:C,status:w}=_?{turns:S.turns,status:S.status}:{turns:v.turns,status:v.status},T=_?S:v,E=_?null:v.subagentActivity;(0,D.useEffect)(()=>{f?.(E)},[E,f]),(0,D.useEffect)(()=>{d?.(C.length)},[C.length,d]);let k=Le(C,Re(e,n,!c)),A=a==null?!1:!!i,j=o||A?rt(k):k,M=(m??``).trim().toLowerCase(),N=M.length>0,P=N?j.filter(e=>e.kind===`turn`&&$e(e.turn).toLowerCase().includes(M)):j;return(0,D.useEffect)(()=>{if(!g||!_)return;let e=C.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=>He(e))),new Set(e.filter(e=>!e.senderTelephone).map(e=>e.senderName??``)).size},[g,_,C,x]),(0,D.useEffect)(()=>{let e=_?P:r===nt?j:null;if(!e)return;let t=Ee(e);if(t.bodies===0)return;let n=De(t,Ce());n&&console.warn(n)},[_,P,j,r]),(0,O.jsxs)(ee,{repinSignals:[C,A,N],tail:l,onReachTop:T.hasOlder&&!N?T.loadOlder:void 0,prependToken:T.prependCount,children:[w===`error`&&(0,O.jsx)(`div`,{className:`wa-reader-error`,children:`Stream disconnected.`}),T.loadingOlder&&(0,O.jsx)(`div`,{className:`wa-reader-placeholder`,children:`Loading earlier messages…`}),!N&&C.length===0&&w===`open`&&(0,O.jsx)(`div`,{className:`wa-reader-placeholder`,children:`No messages in this conversation yet.`}),N&&P.length===0&&(0,O.jsxs)(`div`,{className:`wa-reader-placeholder`,children:[`No matches for "`,m,`".`]}),_?nt(P,e,n,`admin`,m,h,!0,g,p?.accountId):r(j,e,n)]})});function at(e,t){let n=e.split(`;`)[0].trim().toLowerCase();return t.has(n)}var ot=[`audio/ogg;codecs=opus`,`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`];function st(){for(let e of ot)if(MediaRecorder.isTypeSupported(e))return e;return``}function ct(e){return e.split(`;`)[0]}async function lt(){return typeof navigator>`u`||!navigator.mediaDevices?.enumerateDevices?[]:(await navigator.mediaDevices.enumerateDevices()).filter(e=>e.kind===`audioinput`)}function ut(e){let[t,n]=(0,D.useState)(`idle`),[r,i]=(0,D.useState)(0),[a,o]=(0,D.useState)(null),[s,c]=(0,D.useState)(null),l=(0,D.useRef)(null),u=(0,D.useRef)(null),d=(0,D.useRef)([]),f=(0,D.useRef)(``),p=(0,D.useRef)(null),m=(0,D.useRef)(0),h=(0,D.useRef)(0),g=(0,D.useRef)(null),_=(0,D.useRef)(null),v=(0,D.useRef)(0),y=(0,D.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,D.useEffect)(()=>y,[y]);let b=(0,D.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,D.useCallback)(()=>{p.current&&=(clearInterval(p.current),null);let e=Date.now()-m.current;h.current+=e},[]),S=(0,D.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,D.useCallback)(()=>{v.current&&=(cancelAnimationFrame(v.current),0)},[]),w=e?.onResult,T=(0,D.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=st();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(),w?.({ok:!0})}catch(e){y(),n(`error`),e instanceof DOMException?(w?.({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}`)):(w?.({ok:!1}),c(`Could not start recording.`))}}},[t,y,b,S,w]),E=(0,D.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,D.useCallback)(()=>{t!==`recording`&&t!==`paused`||(y(),n(`idle`),i(0),o(null))},[t,y]),k=(0,D.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:ct(r)});y(),n(`idle`),i(0),o(null),t(a.size>0?a:null)},e.stop()}))},[t,O,x,C,y]);return(0,D.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:T,togglePause:E,discard:O,send:k}}export{y as A,w as C,g as D,x as E,v as O,T as S,S as T,I as _,Qe as a,M as b,X as c,qe as d,Ue as f,F as g,ie as h,Je as i,_ as k,Z as l,fe as m,ut as n,Xe as o,B as p,at as r,it as s,lt as t,Y as u,oe as v,C as w,E as x,se as y};
2
+ import{o as e}from"./chunk-BycB0eMI.js";import{i as t,t as n}from"./jsx-runtime-YcUntiud.js";import{B as r,G as i,Z as a,a as o,d as s,i as c,j as l,v as u,w as d,x as f}from"./useMediaQuery-BUFkZYRs.js";import{t as p}from"./copy-JyiMTV0k.js";import{t as m}from"./play-D6OAQVJ_.js";import{t as h}from"./preload-helper-eAV8hweq.js";var g=`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`,_=new Set(g.split(`,`).filter(e=>!e.startsWith(`.`))),v=50*1024*1024;function y(e){switch(e){case`expanded`:return!0;case`collapsed`:return!1;default:return}}var b=a(`check-check`,[[`path`,{d:`M18 6 7 17l-5-5`,key:`116fxf`}],[`path`,{d:`m22 10-7.5 7.5L13 16`,key:`ke71qq`}]]),x=a(`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`}]]),S=a(`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`}]]),C=a(`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`}]]),w=a(`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`}]]),T=a(`reply`,[[`path`,{d:`M20 18v-2a4 4 0 0 0-4-4H4`,key:`5vmcpk`}],[`path`,{d:`m9 17-5-5 5-5`,key:`nvlc11`}]]),E=a(`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`}]]),D=e(t(),1),O=n(),k=200;function ee({children:e,tail:t=null,repinSignals:n,onReachTop:r,prependToken:i=0}){let a=(0,D.useRef)(null),o=(0,D.useRef)(null),s=(0,D.useRef)(!0),[c,l]=(0,D.useState)(!0),u=(0,D.useRef)(0),d=(0,D.useRef)(0),f=(0,D.useRef)(!1),p=(0,D.useRef)(r);p.current=r;let m=()=>{let e=a.current;if(!e)return;let t=e.clientHeight,n=e.scrollHeight,r=t!==u.current||n!==d.current;if(u.current=t,d.current=n,r){s.current&&(e.scrollTop=e.scrollHeight);return}let i=n-e.scrollTop-t<=32;s.current=i,l(e=>e===i?e:i);let o=e.scrollTop<=k;o&&!f.current&&p.current?.(),f.current=o},h=()=>{let e=a.current;e&&(e.scrollTop=e.scrollHeight,d.current=e.scrollHeight,u.current=e.clientHeight,s.current=!0,l(!0))},g=t!=null;return(0,D.useLayoutEffect)(()=>{let e=a.current;if(!e||i===0)return;let t=e.scrollHeight-d.current;t>0&&(e.scrollTop+=t),d.current=e.scrollHeight},[i]),(0,D.useLayoutEffect)(()=>{let e=a.current;e&&s.current&&(e.scrollTop=e.scrollHeight),e&&(d.current=e.scrollHeight,u.current=e.clientHeight)},[...n,g]),(0,D.useLayoutEffect)(()=>{if(typeof ResizeObserver>`u`)return;let e=new ResizeObserver(()=>m());return a.current&&e.observe(a.current),o.current&&e.observe(o.current),()=>e.disconnect()},[]),(0,O.jsxs)(`div`,{className:`wa-reader`,children:[(0,O.jsx)(`div`,{className:`wa-reader-thread`,ref:a,onScroll:m,children:(0,O.jsxs)(`div`,{className:`wa-thread-scroll`,ref:o,children:[e,t]})}),!c&&(0,O.jsx)(`button`,{type:`button`,className:`wa-jump`,onClick:h,"aria-label":`Jump to latest message`,title:`Jump to latest message`,children:`↓`})]})}var A={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.`},j={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 M(e,t=`admin`){return t===`public`?j[e]:A[e]}function N(e){return e===`whatsapp`?` · via WhatsApp`:e===`webchat`?` · via web`:``}var P=56,te=5;function ne(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 re({src:e,filename:t,onDecodeFail:n,onMediaError:r}){let i=(0,D.useRef)(null),a=(0,D.useRef)(null),s=(0,D.useRef)(!1),[c,l]=(0,D.useState)([]),[u,d]=(0,D.useState)(void 0),[f,p]=(0,D.useState)(!1),[h,g]=(0,D.useState)(0),[_,v]=(0,D.useState)(0);(0,D.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),d(r);let a=await o.decodeAudioData(await i.arrayBuffer());if(t)return;l(ne(a.getChannelData(0),P)),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&&(f?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)},x=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))*_)},S=e=>{x(e.clientX);let t=e=>x(e.clientX),n=()=>{window.removeEventListener(`mousemove`,t),window.removeEventListener(`mouseup`,n)};window.addEventListener(`mousemove`,t),window.addEventListener(`mouseup`,n)},C=e=>{if(!(_>0))return;let t=i.current?.currentTime??0;switch(e.key){case`ArrowRight`:case`ArrowUp`:b(t+te),e.preventDefault();break;case`ArrowLeft`:case`ArrowDown`:b(t-te),e.preventDefault();break;case`Home`:b(0),e.preventDefault();break;case`End`:b(_),e.preventDefault();break;default:break}},T=_>0?Math.min(1,h/_):0,E=Math.round(T*P),k=o(h>0?h:_);return(0,O.jsxs)(`div`,{className:`voice-note`,children:[(0,O.jsx)(`button`,{type:`button`,className:`voice-note-play`,"aria-label":`${f?`Pause`:`Play`} ${t}`,onClick:y,children:f?(0,O.jsx)(w,{size:16,"aria-hidden":!0}):(0,O.jsx)(m,{size:16,"aria-hidden":!0})}),(0,O.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:S,onKeyDown:C,children:(c.length?c:Array.from({length:P},()=>0)).map((e,t)=>(0,O.jsx)(`span`,{className:`voice-note-bar${t<E?` is-played`:``}`,style:{height:`${Math.max(10,Math.round(e*100))}%`}},t))}),(0,O.jsx)(`span`,{className:`voice-note-time`,children:k}),(0,O.jsx)(`audio`,{ref:i,className:`voice-note-audio`,preload:`metadata`,src:u,"aria-label":t,onPlay:()=>p(!0),onPause:()=>p(!1),onEnded:()=>p(!1),onError:()=>r?.(),onLoadedMetadata:e=>{let t=e.currentTarget.duration;Number.isFinite(t)&&t>0&&v(t)},onTimeUpdate:e=>g(e.currentTarget.currentTime)})]})}var ie=/\.(png|jpe?g|gif|webp|svg|bmp)$/i,F=/\.pdf$/i;function ae(e,t){return(t?t.startsWith(`image/`):ie.test(e))?`image`:t&&t.startsWith(`audio/`)?`audio`:(t?t===`application/pdf`:F.test(e))?`pdf`:`file`}function oe(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 se(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,O.jsxs)(`a`,{className:`chat-attachment-chip`,href:e,download:t,children:[(0,O.jsx)(C,{size:14,"aria-hidden":!0}),n]})}function z({href:e,filename:t,className:n,size:r=14,onClick:a}){return(0,O.jsx)(`a`,{className:n,href:e,download:t,"aria-label":`Download ${t}`,onClick:a,children:(0,O.jsx)(i,{size:r,"aria-hidden":!0})})}function ce({src:e,filename:t,sizeBytes:n,expandable:r,onFail:i}){let[a,o]=(0,D.useState)(!1),[s,c]=(0,D.useState)(!1),l=n==null?t:`${t} · ${L(n)}`;return s?(0,O.jsx)(R,{href:e,filename:t,label:l}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`span`,{className:`chat-attachment-image-wrap`,children:[(0,O.jsx)(`img`,{className:`chat-attachment-image`,src:e,alt:t,onClick:r?()=>o(!0):void 0,onError:()=>{c(!0),i?.(`fetch`)}}),(0,O.jsx)(z,{href:e,filename:t,className:`chat-attachment-download`})]}),r&&a&&(0,O.jsx)(`div`,{className:`chat-attachment-overlay`,role:`dialog`,"aria-label":t,onClick:()=>o(!1),children:(0,O.jsx)(`img`,{className:`chat-attachment-overlay-image`,src:e,alt:t})})]})}var le=280,ue=360,de=16;function fe({src:e,filename:t,sizeBytes:n,onFail:i}){let[a,o]=(0,D.useState)(!1),[s,c]=(0,D.useState)(!1),l=(0,D.useRef)(null),u=n==null?t:`${t} · ${L(n)}`;return(0,D.useEffect)(()=>{let t=!1,n=null;return(async()=>{try{let{loadPdf:r,renderPageToFit:i}=await h(async()=>{let{loadPdf:e,renderPageToFit:t}=await import(`./pdf-render-B5af7vu1.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,le,ue)}catch{t||(c(!0),i?.(`render`))}})(),()=>{t=!0;try{n?.destroy()}catch{}}},[e]),s?(0,O.jsx)(R,{href:e,filename:t,label:u}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`div`,{className:`chat-attachment-pdf`,children:[(0,O.jsx)(`canvas`,{ref:l,className:`chat-attachment-pdf-canvas`,"aria-label":t}),(0,O.jsx)(z,{href:e,filename:t,className:`chat-attachment-download`}),(0,O.jsx)(`button`,{type:`button`,className:`chat-attachment-pdf-expand`,"aria-label":`Expand ${t}`,onClick:()=>o(!0),children:(0,O.jsx)(r,{size:14,"aria-hidden":!0})})]}),a&&(0,O.jsx)(pe,{src:e,filename:t,label:u,onClose:()=>o(!1),onFail:i})]})}function pe({src:e,filename:t,label:n,onClose:r,onFail:i}){let a=(0,D.useRef)(null),o=(0,D.useRef)(null),[s,c]=(0,D.useState)(null),[u,d]=(0,D.useState)(!1);return(0,D.useEffect)(()=>{let t=!1;return(async()=>{try{let{loadPdf:n}=await h(async()=>{let{loadPdf:e}=await import(`./pdf-render-B5af7vu1.js`);return{loadPdf:e}},__vite__mapDeps([0,1])),r=await n(e);if(t){try{r.destroy()}catch{}return}o.current=r,c(r.numPages)}catch{t||(d(!0),i?.(`render`))}})(),()=>{t=!0;try{o.current?.destroy()}catch{}}},[e]),(0,D.useEffect)(()=>{if(s==null)return;let e=a.current,t=o.current;if(!e||!t)return;let n=!1;return(async()=>{try{let{renderPageToWidth:r}=await h(async()=>{let{renderPageToWidth:e}=await import(`./pdf-render-B5af7vu1.js`);return{renderPageToWidth:e}},__vite__mapDeps([0,1])),i=Array.from(e.querySelectorAll(`canvas.chat-attachment-overlay-page`)),a=Math.max(e.clientWidth-de*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}},[s]),(0,O.jsxs)(`div`,{className:`chat-attachment-overlay`,role:`dialog`,"aria-label":t,onClick:r,children:[(0,O.jsx)(`div`,{ref:a,className:`chat-attachment-overlay-pdf`,onClick:e=>e.stopPropagation(),children:u?(0,O.jsx)(R,{href:e,filename:t,label:n}):Array.from({length:s??0},(e,n)=>(0,O.jsx)(`canvas`,{className:`chat-attachment-overlay-page`,"aria-label":`${t} page ${n+1}`},n))}),(0,O.jsx)(z,{href:e,filename:t,className:`chat-attachment-overlay-download`,size:20,onClick:e=>e.stopPropagation()}),(0,O.jsx)(`button`,{type:`button`,className:`chat-attachment-overlay-close`,"aria-label":`Close`,onClick:r,children:(0,O.jsx)(l,{size:20,"aria-hidden":!0})})]})}function me({src:e,filename:t,onFail:n}){let[r,i]=(0,D.useState)(!1);return r?(0,O.jsx)(`audio`,{className:`chat-attachment-audio`,controls:!0,preload:`metadata`,src:e,"aria-label":t,onError:()=>n?.(`fetch`)}):(0,O.jsx)(re,{src:e,filename:t,onDecodeFail:()=>{i(!0),n?.(`render`)},onMediaError:()=>{i(!0),n?.(`fetch`)}})}function B({filename:e,href:t,mimeType:n,sizeBytes:r,expandable:i,telemetry:a}){let o=ae(e,n);(0,D.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,O.jsx)(ce,{src:t,filename:e,sizeBytes:r,expandable:i,onFail:s});if(o===`audio`&&t)return(0,O.jsx)(me,{src:t,filename:e,onFail:s});if(o===`pdf`&&t)return(0,O.jsx)(fe,{src:t,filename:e,sizeBytes:r,onFail:s});let c=r==null?e:`${e} · ${L(r)}`;return t?(0,O.jsx)(R,{href:t,filename:e,label:c}):(0,O.jsxs)(`p`,{className:`chat-doc`,children:[(0,O.jsx)(C,{size:14,"aria-hidden":!0,style:{verticalAlign:`text-bottom`}}),` `,c]})}var he=/^-?\d+(\.\d+)?,-?\d+(\.\d+)?$/,ge=/^\[(?:live )?location: (.+)\]$/;function V(e){let t=ge.exec(e.trim());if(!t)return{kind:`none`};let n=t[1].split(` — `),r=n[n.length-1].trim();if(!he.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}}var _e=/^\[live location: .+\]$/;function ve(e){let t=new Map;e.forEach((e,n)=>{if(e.kind!==`turn`)return;let r=e.turn;if(r.kind!==`telegram-persisted`||!_e.test(r.text.trim()))return;let i=V(r.text);if(i.kind!==`point`)return;let a=r.messageId.replace(/:edit:[^:]*$/,``),o=t.get(a)??[];o.push({index:n,point:{lat:i.lat,lon:i.lon,ts:r.ts}}),t.set(a,o)});let n=new Map;for(let e of t.values())if(!(e.length<2)){n.set(e[0].index,{role:`head`,points:e.map(e=>e.point)});for(let t of e.slice(1))n.set(t.index,{role:`member`})}return n}function H(e,t){return(e+180)/360*2**t}function U(e,t){return(1-Math.asinh(Math.tan(e*Math.PI/180))/Math.PI)/2*2**t}function ye(e,t,n){let r=2**n,i=Math.round(e)-1,a=(i%r+r)%r,o=Math.min(Math.max(Math.round(t)-1,0),r-2);return{tiles:[{x:a,y:o},{x:(a+1)%r,y:o},{x:a,y:o+1},{x:(a+1)%r,y:o+1}].map(e=>({...e,url:`https://tile.openstreetmap.org/${n}/${e.x}/${e.y}.png`})),offsetX:e*256-i*256,offsetY:t*256-o*256}}function be(e,t,n=16){return ye(H(t,n),U(e,n),n)}function xe(e){let t=[];for(let n of e){let e=t[t.length-1],r=e===void 0?0:Math.round((e-n)/360);t.push(r===0?n:n+r*360)}return t}function Se(e){let t=xe(e.map(e=>e.lon)),n=1;for(let r=16;r>=1;r--){let i=t.map(e=>H(e,r)*256),a=e.map(e=>U(e.lat,r)*256);if(Math.max(...i)-Math.min(...i)<=240&&Math.max(...a)-Math.min(...a)<=160){n=r;break}}let r=t.map(e=>H(e,n)),i=e.map(e=>U(e.lat,n)),a=(Math.min(...r)+Math.max(...r))/2,o=(Math.min(...i)+Math.max(...i))/2,s=ye(a,o,n);return{zoom:n,...s,points:r.map((e,t)=>({x:s.offsetX+(e-a)*256,y:s.offsetY+(i[t]-o)*256}))}}var W=0,G=0,K=0,q=0;function Ce(){return{maps:W,tracks:G,trackPoints:K,tileErrors:q}}function we({lat:e,lon:t,msgKeyId:n}){let{tiles:r,offsetX:i,offsetY:a}=be(e,t);return(0,D.useEffect)(()=>(W+=1,()=>{--W}),[]),(0,O.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,O.jsxs)(`span`,{className:`wa-map-viewport`,children:[(0,O.jsx)(`span`,{className:`wa-map-block`,style:{left:`calc(50% - ${i}px)`,top:`calc(50% - ${a}px)`},children:r.map(e=>(0,O.jsx)(`img`,{className:`wa-map-tile`,src:e.url,alt:``,width:256,height:256,loading:`lazy`,onError:()=>{q+=1}},e.url))}),(0,O.jsx)(`span`,{className:`wa-map-pin`,"aria-hidden":!0}),(0,O.jsx)(`span`,{className:`wa-map-credit`,children:`© OpenStreetMap contributors`})]})})}function Te({points:e,formatTime:t,msgKeyId:n}){let{zone:r}=u(),i=Se(e),a=e.length;(0,D.useEffect)(()=>(G+=1,K+=a,()=>{--G,K-=a}),[a]);let o=e[a-1],s=i.points[0],c=i.points[a-1],l=t(e[0].ts,r),d=t(o.ts,r);return(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(`a`,{className:`wa-map`,href:`https://www.openstreetmap.org/?mlat=${o.lat}&mlon=${o.lon}#map=${i.zoom}/${o.lat}/${o.lon}`,target:`_blank`,rel:`noopener noreferrer`,style:{width:240,height:160},children:(0,O.jsxs)(`span`,{className:`wa-map-viewport`,children:[(0,O.jsxs)(`span`,{className:`wa-map-block`,style:{left:`calc(50% - ${i.offsetX}px)`,top:`calc(50% - ${i.offsetY}px)`},children:[i.tiles.map(e=>(0,O.jsx)(`img`,{className:`wa-map-tile`,src:e.url,alt:``,width:256,height:256,loading:`lazy`,onError:()=>{q+=1}},e.url)),(0,O.jsxs)(`svg`,{className:`wa-map-track`,width:256*2,height:256*2,"aria-hidden":!0,children:[(0,O.jsx)(`polyline`,{points:i.points.map(e=>`${e.x},${e.y}`).join(` `)}),(0,O.jsx)(`circle`,{className:`wa-map-track-start`,cx:s.x,cy:s.y,r:4}),(0,O.jsx)(`circle`,{className:`wa-map-track-now`,cx:c.x,cy:c.y,r:5})]})]}),(0,O.jsx)(`span`,{className:`wa-map-credit`,children:`© OpenStreetMap contributors`})]})}),(0,O.jsxs)(`span`,{className:`wa-map-track-caption`,children:[a,` updates · `,l,` to `,d]})]})}function J({text:e,body:t,msgKeyId:n}){let r=V(e);return(0,O.jsxs)(O.Fragment,{children:[r.kind===`point`&&(0,O.jsx)(we,{lat:r.lat,lon:r.lon,msgKeyId:n}),(0,O.jsx)(`p`,{className:`wa-body`,children:t})]})}function Ee(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=V(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 De(e,t){let{maps:n,tracks:r,trackPoints:i,tileErrors:a}=t;return e.rejected>0||e.parsed>n+i||r===0&&i>0?`[operator-ui] op=location-census-alarm bodies=${e.bodies} withLabel=${e.withLabel} parsed=${e.parsed} rejected=${e.rejected} maps=${n} tracks=${r} trackPoints=${i} tileErrors=${a}`:null}var Oe=20;function ke(e){let t=e.replace(/\/(store-)?stream$/,(e,t)=>t?`/store-backfill`:`/backfill`);return t===e?``:t}function Ae(e,...t){let[n,r,i,a,o]=t,[s,c]=(0,D.useState)([]),[l,u]=(0,D.useState)(null),[d,f]=(0,D.useState)(!1),[p,m]=(0,D.useState)(0),h=(0,D.useRef)(!1);(0,D.useEffect)(()=>{c([]),u(null),f(!1),m(0),h.current=!1},[a,n,r,i,e]);let g=(0,D.useCallback)(e=>u(e),[]),_=(0,D.useCallback)(()=>{!e||l===null||l<=0||h.current||(h.current=!0,f(!0),(async()=>{let t=l,a=[],s=0;try{for(;t>0&&a.length===0&&s<Oe;){s+=1;let c=await fetch(`${e}?${Me(e,n,r,i,t,o)}`);if(!c.ok)break;let l=await c.json();if(!Array.isArray(l.turns))break;a.unshift(...l.turns);let u=l.reachedStart?0:l.from;if(!l.reachedStart&&u>=t){je(e,t,l.from);break}t=u}}catch{}finally{a.length>0&&(c(e=>[...a,...e]),m(e=>e+1)),u(t),h.current=!1,f(!1)}})())},[e,n,r,i,l]);return{turns:s,hasOlder:l!==null&&l>0,loadingOlder:d,prependCount:p,loadOlder:_,setTurns:c,onWindow:g}}function je(e,t,n){let r=e.endsWith(`/store-backfill`)?`store`:e.includes(`/public-reader/`)?`public`:`session`;try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`event`,source:`reader-backfill`,op:`backfill-no-advance`,reader:r,before:t,from:n}),keepalive:!0}).catch(()=>{})}catch{}}function Me(e,t,n,r,i,a=`remoteJid`){let o=e.endsWith(`/store-backfill`);return new URLSearchParams(o?{accountId:t,[a]:n,session_key:r,before:String(i)}:{sessionId:t,projectDir:n,session_key:r,before:String(i)}).toString()}function Ne(e,t,n,r=`/api/session-reader/stream`,i=e,a=!0){let[o,s]=(0,D.useState)([]),[c,l]=(0,D.useState)(`open`),[u,d]=(0,D.useState)(null),f=Ae(ke(r),e,t,n,i),{onWindow:p}=f,m=(0,D.useRef)([]);return(0,D.useEffect)(()=>{m.current=o},[o]),(0,D.useEffect)(()=>{s([]),m.current=[],d(null)},[i,t,n,r]),(0,D.useEffect)(()=>{if(l(`open`),!a)return;let i=m.current.slice(),o=i.map(Pe),c=0,u=i.length>0,f=`${r}?sessionId=${encodeURIComponent(e)}&projectDir=${encodeURIComponent(t)}&session_key=${encodeURIComponent(n)}`,h=new EventSource(f);return h.onopen=()=>{l(`open`)},h.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(u){if(c<o.length&&Pe(t)===o[c]){c+=1;return}u=!1}s(e=>[...e,t])},h.addEventListener(`activity`,e=>{try{d(JSON.parse(e.data))}catch{}}),h.addEventListener(`activity-clear`,()=>d(null)),h.addEventListener(`window`,e=>{try{let t=JSON.parse(e.data);typeof t.from==`number`&&p(t.from)}catch{}}),h.onerror=()=>{h.readyState===2&&(console.error(`[admin-ui] wa-stream onerror readyState=${h.readyState}`),l(`error`))},()=>h.close()},[e,t,n,r,i,a,p]),{turns:(0,D.useMemo)(()=>[...f.turns,...o],[f.turns,o]),status:c,subagentActivity:u,hasOlder:f.hasOlder,loadingOlder:f.loadingOlder,prependCount:f.prependCount,loadOlder:f.loadOlder}}function Pe(e){return JSON.stringify(e)}function Fe(e,t,n,r,i,a=!0){let[o,s]=(0,D.useState)([]),[c,l]=(0,D.useState)(`open`),u=Ae(`${e}/store-backfill`,n,r,i,`${n}|${r}`,t),{onWindow:d,setTurns:f}=u;return(0,D.useEffect)(()=>{if(s([]),l(`open`),!a||!n||!r)return;let o=`${e}/store-stream?accountId=${encodeURIComponent(n)}&${t}=${encodeURIComponent(r)}&session_key=${encodeURIComponent(i)}`,c=new EventSource(o);return c.onopen=()=>l(`open`),c.onmessage=e=>{let t;try{t=JSON.parse(e.data)}catch{return}s(e=>[...e,t])},c.addEventListener(`window`,e=>{try{let t=JSON.parse(e.data);typeof t.from==`number`&&d(t.from)}catch{}}),c.addEventListener(`reaction`,e=>{let t;try{t=JSON.parse(e.data)}catch{return}let n=e=>e.map(e=>e.kind===`whatsapp-persisted`&&e.msgKeyId===t.targetMsgKeyId?{...e,reactions:t.reactions}:e);s(n),f(n)}),c.onerror=()=>{c.readyState===2&&l(`error`)},()=>c.close()},[e,t,n,r,i,a,d,f]),{turns:(0,D.useMemo)(()=>[...u.turns,...o].sort((e,t)=>String(e.ts??``).localeCompare(String(t.ts??``))),[u.turns,o]),status:c,hasOlder:u.hasOlder,loadingOlder:u.loadingOlder,prependCount:u.prependCount,loadOlder:u.loadOlder}}var Ie=e=>{if(!e)return 1/0;let t=new Date(e).getTime();return Number.isNaN(t)?1/0:t};function Le(e,t){let n=[],r=0;return e.forEach((e,t)=>n.push({sort:Ie(e.ts),sub:1,ins:r++,item:{kind:`turn`,turn:e,idx:t}})),t.forEach(e=>n.push({sort:Ie(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 Re(e,t,n=!0){let[r,i]=(0,D.useState)([]);return(0,D.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 ze=new Set([`operator-inbound`,`operator-typed`,`agent-reply`,`agent-reply-document`,`agent-file`,`agent-error`,`agent-webchat-final`,`agent-send-party`,`whatsapp-persisted`]),Be=[`#c2185b`,`#7b1fa2`,`#512da8`,`#303f9f`,`#1976d2`,`#0288d1`,`#0097a7`,`#00796b`,`#388e3c`,`#689f38`,`#af6c00`,`#e64a19`,`#5d4037`,`#455a64`,`#d81b60`,`#8e24aa`,`#3949ab`,`#039be5`,`#00897b`,`#6d4c41`];function Ve(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 He(e){return Be[Ve(e)%Be.length]}function Ue({accountId:e,jid:t,sessionKey:n,className:r=`wa-web-avatar`,size:i=20}){let[a,o]=(0,D.useState)(null);if(!t||a===t)return(0,O.jsx)(`span`,{className:r,"aria-hidden":!0,children:(0,O.jsx)(E,{size:i})});let s=`/api/whatsapp-reader/avatar?session_key=${encodeURIComponent(n)}&accountId=${encodeURIComponent(e)}&jid=${encodeURIComponent(t)}`;return(0,O.jsx)(`span`,{className:r,"aria-hidden":!0,children:(0,O.jsx)(`img`,{className:`wa-avatar-img`,src:s,alt:``,onError:()=>o(t)})})}function Y(e,t){if(!e)return``;let n=new Date(e);if(Number.isNaN(n.getTime()))return``;let r=d(n,t);return`${String(r.hh).padStart(2,`0`)}:${String(r.mm).padStart(2,`0`)}`}function X(e){let t=e.lastIndexOf(`/`);return t===-1?e:e.slice(t+1)}var We=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`],Ge=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`];function Z(e,t){if(!e)return null;let n=new Date(e);return Number.isNaN(n.getTime())?null:f(n,t)}function Ke(e,t,n=new Date){if(!e)return``;let r=new Date(e);if(Number.isNaN(r.getTime()))return``;let i=f(r,t);if(i===f(n,t))return`Today`;let a=d(n,t);if(i===f(new Date(Date.UTC(a.y,a.m-1,a.d)-864e5),`UTC`))return`Yesterday`;let o=d(r,t);return`${We[new Date(Date.UTC(o.y,o.m-1,o.d)).getUTCDay()]} ${o.d} ${Ge[o.m-1]} ${o.y}`}function qe(e){return e.kind===`turn`?e.turn.ts:e.entry.ts}function Je({ts:e,prevTs:t=null}){let{zone:n}=u(),r=Z(e,n);return r===null||t!==null&&Z(t,n)===r?null:(0,O.jsx)(`div`,{className:`day-divider`,role:`separator`,children:(0,O.jsx)(`span`,{className:`day-divider-label`,children:Ke(e,n)})})}function Ye({ts:e,className:t}){let{zone:n}=u();return(0,O.jsx)(`time`,{className:t,children:Y(e,n)})}function Xe(){return(0,O.jsx)(`div`,{className:`session-divider`,role:`separator`,children:(0,O.jsx)(`span`,{className:`session-divider-label`,children:`Conversation continued`})})}function Q({label:e,ts:t,colour:n}){let{zone:r}=u();return(0,O.jsxs)(`div`,{className:`wa-turn-head`,children:[(0,O.jsx)(`span`,{className:`wa-who`,style:n?{color:n}:void 0,children:e}),(0,O.jsx)(`time`,{className:`wa-time`,children:Y(t,r)})]})}function Ze({turn:e}){let[t,n]=(0,D.useState)(!1),{zone:r}=u(),i=e.kind===`tool-result`,a=i?`wa-turn wa-turn-result${e.isError?` is-error`:``}`:`wa-turn wa-turn-tool`,o=i?e.isError?`result (error)`:`result`:`↳ ${e.name}`,s=i?e.text:JSON.stringify(e.input,null,2);return(0,O.jsxs)(`div`,{className:a,children:[(0,O.jsxs)(`button`,{type:`button`,className:`wa-tool-toggle`,"aria-expanded":t,onClick:()=>n(e=>!e),children:[(0,O.jsx)(`span`,{className:`wa-chevron`,children:t?`▾`:`▸`}),(0,O.jsx)(`span`,{className:`wa-who`,children:o}),(0,O.jsx)(`time`,{className:`wa-time`,children:Y(e.ts,r)})]}),t&&(0,O.jsx)(`pre`,{className:`wa-code`,children:s})]})}function Qe({entry:e,sessionId:t,sessionKey:n}){let[r,i]=(0,D.useState)(!1),[a,o]=(0,D.useState)(null),{zone:s}=u(),c=()=>{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,O.jsxs)(`div`,{className:`wa-turn wa-turn-directive`,children:[(0,O.jsxs)(`button`,{type:`button`,className:`wa-tool-toggle`,"aria-expanded":r,onClick:c,children:[(0,O.jsx)(`span`,{className:`wa-chevron`,children:r?`▾`:`▸`}),(0,O.jsxs)(`span`,{className:`wa-who`,children:[`⚙ directive injected (`,e.len,` B)`]}),(0,O.jsx)(`time`,{className:`wa-time`,children:Y(e.ts,s)})]}),r&&(0,O.jsx)(`pre`,{className:`wa-code`,children:a??`Loading…`})]})}function $e(e){return`text`in e&&typeof e.text==`string`?e.text:``}function $(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,O.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,O.jsx)(O.Fragment,{children:a})}var et={onFail:({kind:e,mime:t,reason:n})=>console.warn(`[operator-ui] op=reader-attachment-fail kind=${e} mime=${t??``} reason=${n}`)};function tt(e,t,n,r){switch(e.kind){case`operator-inbound`:return(0,O.jsxs)(`div`,{className:`wa-turn wa-turn-in`,children:[(0,O.jsx)(Q,{label:`Operator${N(e.source)}`,ts:e.ts}),e.text&&(0,O.jsx)(J,{text:e.text,body:e.text}),e.attachments&&e.attachments.length>0&&(0,O.jsx)(`div`,{className:`chat-attachment-list`,children:e.attachments.map((e,t)=>(0,O.jsx)(B,{expandable:!0,filename:e.filename,mimeType:e.mimeType,sizeBytes:e.sizeBytes,href:I(e.attachmentId,n.audience,n.sessionId,n.sessionKey),telemetry:et},t))})]},t);case`operator-typed`:return(0,O.jsxs)(`div`,{className:`wa-turn wa-turn-in wa-turn-typed`,children:[(0,O.jsx)(Q,{label:`Operator (web)`,ts:e.ts}),(0,O.jsx)(J,{text:e.text,body:e.text})]},t);case`agent-text`:return(0,O.jsxs)(`div`,{className:`wa-turn wa-turn-think`,children:[(0,O.jsx)(Q,{label:`Agent`,ts:e.ts}),(0,O.jsx)(J,{text:e.text,body:e.text})]},t);case`agent-reply`:return(0,O.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,O.jsx)(Q,{label:`Agent`,ts:e.ts}),(0,O.jsx)(J,{text:e.text,body:e.text})]},t);case`agent-send-party`:return(0,O.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,O.jsx)(Q,{label:`Agent to ${e.phone}`,ts:e.ts}),(0,O.jsx)(J,{text:e.text,body:e.text})]},t);case`agent-reply-document`:return(0,O.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,O.jsx)(Q,{label:`Agent`,ts:e.ts}),(0,O.jsxs)(`p`,{className:`wa-doc`,children:[(0,O.jsx)(C,{size:14,"aria-hidden":!0,style:{verticalAlign:`text-bottom`}}),` `,`sent document(s): `,e.files.map(X).join(`, `)]}),e.caption&&(0,O.jsx)(`p`,{className:`wa-body`,children:e.caption})]},t);case`agent-file`:return(0,O.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,O.jsx)(Q,{label:`Agent`,ts:e.ts}),e.files.map((t,r)=>{let i=X(t),a=e.downloads?.[r];return(0,O.jsx)(B,{expandable:!0,filename:i,href:a?oe(a,n.sessionId,n.sessionKey,F.test(i)?`inline`:void 0):void 0,telemetry:et},r)}),e.caption&&(0,O.jsx)(`p`,{className:`wa-body`,children:e.caption})]},t);case`telegram-persisted`:{let i=e.origin===`operator-manual`,a=e.fromMe?i?`You`:`Sent`:e.senderName??`Contact`;return(0,O.jsxs)(`div`,{className:`wa-turn ${e.fromMe?`wa-turn-out`:`wa-turn-in`}${i?` wa-op-manual`:``}`,children:[(0,O.jsx)(Q,{label:a,ts:e.ts}),e.text&&r?.role===`head`&&(0,O.jsx)(Te,{points:r.points,formatTime:Y}),e.text&&r&&(0,O.jsx)(`p`,{className:`wa-body`,children:$(e.text,n.highlight)}),e.text&&!r&&(0,O.jsx)(J,{text:e.text,body:$(e.text,n.highlight)})]},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&&s(e.senderJid)?e.senderJid:null;return(0,O.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,O.jsx)(Ue,{accountId:n.storeAccountId,jid:a,sessionKey:n.sessionKey,className:`wa-bubble-avatar`,size:14}),n.onReplyTo&&e.msgKeyId&&(0,O.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,O.jsx)(T,{size:14})}),n.showCopy&&e.text&&(0,O.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,O.jsx)(p,{size:14})}),e.quoted&&(0,O.jsxs)(`div`,{className:`wa-quoted`,children:[(0,O.jsx)(`span`,{className:`wa-quoted-who`,children:e.quoted.fromMe?`You`:e.quoted.sender??`Contact`}),(0,O.jsx)(`span`,{className:`wa-quoted-body`,children:e.quoted.body||`Message`})]}),(0,O.jsx)(Q,{label:i,ts:e.ts,colour:n.groupThread&&!e.fromMe?He(e.senderTelephone||e.senderName||``):void 0}),e.text&&(0,O.jsx)(J,{text:e.text,body:$(e.text,n.highlight),msgKeyId:e.msgKeyId??void 0}),e.attachments&&e.attachments.length>0&&(0,O.jsx)(`div`,{className:`chat-attachment-list`,children:e.attachments.map((e,t)=>(0,O.jsx)(B,{expandable:!0,filename:e.filename,mimeType:e.mimeType,sizeBytes:e.sizeBytes,href:I(e.attachmentId,n.audience,n.sessionId,n.sessionKey),telemetry:et},t))}),e.reactions&&e.reactions.length>0&&(0,O.jsx)(`div`,{className:`wa-reactions`,children:e.reactions.map((e,t)=>(0,O.jsx)(`span`,{className:`wa-reaction`,title:e.reactorName??void 0,children:e.emoji},t))}),(0,O.jsxs)(`span`,{className:`wa-bubble-meta`,children:[r&&(0,O.jsx)(`span`,{className:`wa-op-tag`,children:`You`}),(0,O.jsx)(Ye,{ts:e.ts,className:`wa-bubble-time`}),e.fromMe&&(0,O.jsx)(b,{size:14,className:`wa-bubble-tick`,"aria-hidden":!0})]})]},t)}case`session-continued`:return(0,O.jsx)(Xe,{},t);case`harness-internal`:return null;case`tool-call`:case`tool-result`:return(0,O.jsx)(Ze,{turn:e},t);case`agent-error`:return(0,O.jsxs)(`div`,{className:`wa-turn wa-turn-error`,role:`alert`,children:[(0,O.jsx)(Q,{label:`Agent`,ts:e.ts}),(0,O.jsx)(`p`,{className:`wa-body wa-error-body`,children:M(e.code,`admin`)}),e.code===`agent_error`&&e.raw&&(0,O.jsx)(`pre`,{className:`wa-code`,children:e.raw})]},t)}}function nt(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=ve(e),d=[],f=null;return e.forEach((e,r)=>{let i=qe(e);i!==null&&!Number.isNaN(new Date(i).getTime())&&(d.push((0,O.jsx)(Je,{ts:i,prevTs:f},`day-${r}`)),f=i),d.push(e.kind===`turn`?tt(e.turn,r,l,u.get(r)):(0,O.jsx)(Qe,{entry:e.entry,sessionId:t,sessionKey:n},r))}),d}function rt(e){return e.filter(e=>e.kind===`turn`&&ze.has(e.turn.kind)&&!(e.turn.kind===`operator-inbound`&&e.turn.scheduled))}var it=(0,D.memo)(function({sessionId:e,projectDir:t,sessionKey:n,renderItems:r=nt,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=Ne(e,t,n,s,u,!_),y=p?.channel===`telegram`?`/api/telegram-reader`:`/api/whatsapp-reader`,b=p?.channel===`telegram`?`channelKey`:`remoteJid`,x=p?p.channel===`telegram`?p.channelKey:p.remoteJid:``,S=Fe(y,b,p?.accountId??``,x,n,_),{turns:C,status:w}=_?{turns:S.turns,status:S.status}:{turns:v.turns,status:v.status},T=_?S:v,E=_?null:v.subagentActivity;(0,D.useEffect)(()=>{f?.(E)},[E,f]),(0,D.useEffect)(()=>{d?.(C.length)},[C.length,d]);let k=Le(C,Re(e,n,!c)),A=a==null?!1:!!i,j=o||A?rt(k):k,M=(m??``).trim().toLowerCase(),N=M.length>0,P=N?j.filter(e=>e.kind===`turn`&&$e(e.turn).toLowerCase().includes(M)):j;return(0,D.useEffect)(()=>{if(!g||!_)return;let e=C.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=>He(e))),new Set(e.filter(e=>!e.senderTelephone).map(e=>e.senderName??``)).size},[g,_,C,x]),(0,D.useEffect)(()=>{let e=_?P:r===nt?j:null;if(!e)return;let t=Ee(e);if(t.bodies===0)return;let n=De(t,Ce());n&&console.warn(n)},[_,P,j,r]),(0,O.jsxs)(ee,{repinSignals:[C,A,N],tail:l,onReachTop:T.hasOlder&&!N?T.loadOlder:void 0,prependToken:T.prependCount,children:[w===`error`&&(0,O.jsx)(`div`,{className:`wa-reader-error`,children:`Stream disconnected.`}),T.loadingOlder&&(0,O.jsx)(`div`,{className:`wa-reader-placeholder`,children:`Loading earlier messages…`}),!N&&C.length===0&&w===`open`&&(0,O.jsx)(`div`,{className:`wa-reader-placeholder`,children:`No messages in this conversation yet.`}),N&&P.length===0&&(0,O.jsxs)(`div`,{className:`wa-reader-placeholder`,children:[`No matches for "`,m,`".`]}),_?nt(P,e,n,`admin`,m,h,!0,g,p?.accountId):r(j,e,n)]})});function at(e,t){let n=e.split(`;`)[0].trim().toLowerCase();return t.has(n)}var ot=[`audio/ogg;codecs=opus`,`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`];function st(){for(let e of ot)if(MediaRecorder.isTypeSupported(e))return e;return``}function ct(e){return e.split(`;`)[0]}async function lt(){return typeof navigator>`u`||!navigator.mediaDevices?.enumerateDevices?[]:(await navigator.mediaDevices.enumerateDevices()).filter(e=>e.kind===`audioinput`)}function ut(e){let[t,n]=(0,D.useState)(`idle`),[r,i]=(0,D.useState)(0),[a,o]=(0,D.useState)(null),[s,c]=(0,D.useState)(null),l=(0,D.useRef)(null),u=(0,D.useRef)(null),d=(0,D.useRef)([]),f=(0,D.useRef)(``),p=(0,D.useRef)(null),m=(0,D.useRef)(0),h=(0,D.useRef)(0),g=(0,D.useRef)(null),_=(0,D.useRef)(null),v=(0,D.useRef)(0),y=(0,D.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,D.useEffect)(()=>y,[y]);let b=(0,D.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,D.useCallback)(()=>{p.current&&=(clearInterval(p.current),null);let e=Date.now()-m.current;h.current+=e},[]),S=(0,D.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,D.useCallback)(()=>{v.current&&=(cancelAnimationFrame(v.current),0)},[]),w=e?.onResult,T=(0,D.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=st();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(),w?.({ok:!0})}catch(e){y(),n(`error`),e instanceof DOMException?(w?.({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}`)):(w?.({ok:!1}),c(`Could not start recording.`))}}},[t,y,b,S,w]),E=(0,D.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,D.useCallback)(()=>{t!==`recording`&&t!==`paused`||(y(),n(`idle`),i(0),o(null))},[t,y]),k=(0,D.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:ct(r)});y(),n(`idle`),i(0),o(null),t(a.size>0?a:null)},e.stop()}))},[t,O,x,C,y]);return(0,D.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:T,togglePause:E,discard:O,send:k}}export{y as A,w as C,g as D,x as E,v as O,T as S,S as T,I as _,Qe as a,M as b,X as c,qe as d,Ue as f,F as g,ie as h,Je as i,_ as k,Z as l,fe as m,ut as n,Xe as o,B as p,at as r,it as s,lt as t,Y as u,oe as v,C as w,E as x,se as y};
@@ -1 +1 @@
1
- import{Z as e}from"./useMediaQuery-BmG090FR.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};
1
+ import{Z as e}from"./useMediaQuery-BUFkZYRs.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};