@rubytech/create-maxy-code 0.1.546 → 0.1.547

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 (205) hide show
  1. package/package.json +1 -1
  2. package/payload/platform/plugins/admin/mcp/dist/index.js +32 -16
  3. package/payload/platform/plugins/admin/mcp/dist/index.js.map +1 -1
  4. package/payload/platform/plugins/admin/mcp/dist/tools/account-default-agent.d.ts +16 -0
  5. package/payload/platform/plugins/admin/mcp/dist/tools/account-default-agent.d.ts.map +1 -0
  6. package/payload/platform/plugins/admin/mcp/dist/tools/account-default-agent.js +21 -0
  7. package/payload/platform/plugins/admin/mcp/dist/tools/account-default-agent.js.map +1 -0
  8. package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +38 -25
  9. package/payload/platform/plugins/admin/skills/whats-new/SKILL.md +5 -0
  10. package/payload/platform/plugins/docs/references/admin-ui.md +23 -0
  11. package/payload/platform/plugins/docs/references/channel-wake-and-prompt.md +14 -24
  12. package/payload/platform/plugins/scheduling/mcp/dist/lib/__tests__/routine-run.test.js +109 -1
  13. package/payload/platform/plugins/scheduling/mcp/dist/lib/__tests__/routine-run.test.js.map +1 -1
  14. package/payload/platform/plugins/scheduling/mcp/dist/lib/routine-run.d.ts +31 -0
  15. package/payload/platform/plugins/scheduling/mcp/dist/lib/routine-run.d.ts.map +1 -1
  16. package/payload/platform/plugins/scheduling/mcp/dist/lib/routine-run.js +116 -2
  17. package/payload/platform/plugins/scheduling/mcp/dist/lib/routine-run.js.map +1 -1
  18. package/payload/platform/plugins/scheduling/mcp/dist/scripts/reconcile-bookings.js +3 -2
  19. package/payload/platform/plugins/scheduling/mcp/dist/scripts/reconcile-bookings.js.map +1 -1
  20. package/payload/platform/plugins/whatsapp/PLUGIN.md +0 -6
  21. package/payload/platform/plugins/whatsapp/mcp/dist/index.js +2 -34
  22. package/payload/platform/plugins/whatsapp/mcp/dist/index.js.map +1 -1
  23. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.d.ts.map +1 -1
  24. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js +0 -1
  25. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js.map +1 -1
  26. package/payload/platform/services/whatsapp-channel/dist/notification.d.ts +14 -16
  27. package/payload/platform/services/whatsapp-channel/dist/notification.d.ts.map +1 -1
  28. package/payload/platform/services/whatsapp-channel/dist/notification.js +14 -20
  29. package/payload/platform/services/whatsapp-channel/dist/notification.js.map +1 -1
  30. package/payload/platform/services/whatsapp-channel/dist/targets.d.ts +4 -4
  31. package/payload/platform/services/whatsapp-channel/dist/targets.d.ts.map +1 -1
  32. package/payload/platform/services/whatsapp-channel/dist/targets.js +3 -5
  33. package/payload/platform/services/whatsapp-channel/dist/targets.js.map +1 -1
  34. package/payload/server/{chunk-CVUSUNXM.js → chunk-MHNHG3GL.js} +2 -4
  35. package/payload/server/{chunk-X2RRMHVV.js → chunk-Q33KT7YJ.js} +1 -1
  36. package/payload/server/{chunk-DU7GPDJJ.js → chunk-WGMIUXXG.js} +4 -0
  37. package/payload/server/{manager-TI2YJQVZ.js → manager-W32LVPCT.js} +2 -2
  38. package/payload/server/maxy-edge.js +2 -2
  39. package/payload/server/public/activity.html +5 -5
  40. package/payload/server/public/agents.html +4 -4
  41. package/payload/server/public/assets/{AdminLoginScreens-BGKtDqAk.js → AdminLoginScreens-Bjcs9ta9.js} +1 -1
  42. package/payload/server/public/assets/AdminLoginScreens-Bjcs9ta9.js.br +0 -0
  43. package/payload/server/public/assets/AdminLoginScreens-Bjcs9ta9.js.gz +0 -0
  44. package/payload/server/public/assets/{AdminShell-DnfgsAQl.js → AdminShell-DVBAMUCy.js} +1 -1
  45. package/payload/server/public/assets/AdminShell-DVBAMUCy.js.br +0 -0
  46. package/payload/server/public/assets/{AdminShell-DnfgsAQl.js.gz → AdminShell-DVBAMUCy.js.gz} +0 -0
  47. package/payload/server/public/assets/{activity-ByJSut0Q.js → activity-C8E8-EwQ.js} +1 -1
  48. package/payload/server/public/assets/activity-C8E8-EwQ.js.br +0 -0
  49. package/payload/server/public/assets/activity-C8E8-EwQ.js.gz +0 -0
  50. package/payload/server/public/assets/{admin-CkeJO6kA.js → admin-CeWAlpRS.js} +1 -1
  51. package/payload/server/public/assets/admin-CeWAlpRS.js.br +0 -0
  52. package/payload/server/public/assets/admin-CeWAlpRS.js.gz +0 -0
  53. package/payload/server/public/assets/{agents-D8phtRX5.js → agents-DuN92iFb.js} +1 -1
  54. package/payload/server/public/assets/agents-DuN92iFb.js.br +0 -0
  55. package/payload/server/public/assets/agents-DuN92iFb.js.gz +0 -0
  56. package/payload/server/public/assets/{browser-DQSTjdom.js → browser-BxebdKbh.js} +1 -1
  57. package/payload/server/public/assets/browser-BxebdKbh.js.br +0 -0
  58. package/payload/server/public/assets/browser-BxebdKbh.js.gz +0 -0
  59. package/payload/server/public/assets/{calendar-DFJu1XjP.js → calendar-BtFZQ5Np.js} +1 -1
  60. package/payload/server/public/assets/calendar-BtFZQ5Np.js.br +0 -0
  61. package/payload/server/public/assets/calendar-BtFZQ5Np.js.gz +0 -0
  62. package/payload/server/public/assets/chat-CGIwynaH.js +1 -0
  63. package/payload/server/public/assets/chat-CGIwynaH.js.br +3 -0
  64. package/payload/server/public/assets/chat-CGIwynaH.js.gz +0 -0
  65. package/payload/server/public/assets/chevron-left-DaNP1zDb.js +1 -0
  66. package/payload/server/public/assets/chevron-left-DaNP1zDb.js.br +0 -0
  67. package/payload/server/public/assets/chevron-right-BbbuTUnt.js +1 -0
  68. package/payload/server/public/assets/chevron-right-BbbuTUnt.js.br +0 -0
  69. package/payload/server/public/assets/clock-CfDdatjp.js +1 -0
  70. package/payload/server/public/assets/clock-CfDdatjp.js.br +0 -0
  71. package/payload/server/public/assets/clock-CfDdatjp.js.gz +0 -0
  72. package/payload/server/public/assets/{copy-lFFhXRGk.js → copy-DCDHXq3O.js} +1 -1
  73. package/payload/server/public/assets/copy-DCDHXq3O.js.br +0 -0
  74. package/payload/server/public/assets/copy-DCDHXq3O.js.gz +0 -0
  75. package/payload/server/public/assets/data-BchSWOju.js +1 -0
  76. package/payload/server/public/assets/data-BchSWOju.js.br +1 -0
  77. package/payload/server/public/assets/data-BchSWOju.js.gz +0 -0
  78. package/payload/server/public/assets/{file-text-D2Y-bkNy.js → file-text-zQgEQWCF.js} +1 -1
  79. package/payload/server/public/assets/file-text-zQgEQWCF.js.br +0 -0
  80. package/payload/server/public/assets/file-text-zQgEQWCF.js.gz +0 -0
  81. package/payload/server/public/assets/{graph-C-3yN6JD.js → graph-CFCEh_YI.js} +1 -1
  82. package/payload/server/public/assets/graph-CFCEh_YI.js.br +0 -0
  83. package/payload/server/public/assets/graph-CFCEh_YI.js.gz +0 -0
  84. package/payload/server/public/assets/{graph-labels-DiaPLP27.js → graph-labels-CA1UcDuS.js} +1 -1
  85. package/payload/server/public/assets/graph-labels-CA1UcDuS.js.br +0 -0
  86. package/payload/server/public/assets/graph-labels-CA1UcDuS.js.gz +0 -0
  87. package/payload/server/public/assets/{operator-KuGPvSa9.js → operator-hFXPDc2X.js} +1 -1
  88. package/payload/server/public/assets/operator-hFXPDc2X.js.br +0 -0
  89. package/payload/server/public/assets/operator-hFXPDc2X.js.gz +0 -0
  90. package/payload/server/public/assets/{page-BhGeFXWA.js → page-C8jyPH_3.js} +1 -1
  91. package/payload/server/public/assets/page-C8jyPH_3.js.br +0 -0
  92. package/payload/server/public/assets/page-C8jyPH_3.js.gz +0 -0
  93. package/payload/server/public/assets/{page-EnbVC-yM.js → page-ne7I_r9L.js} +1 -1
  94. package/payload/server/public/assets/page-ne7I_r9L.js.br +0 -0
  95. package/payload/server/public/assets/page-ne7I_r9L.js.gz +0 -0
  96. package/payload/server/public/assets/play-Ep0SZTbr.js +1 -0
  97. package/payload/server/public/assets/play-Ep0SZTbr.js.br +0 -0
  98. package/payload/server/public/assets/play-Ep0SZTbr.js.gz +0 -0
  99. package/payload/server/public/assets/{public-CdSgMNC7.js → public-BgnqjAal.js} +1 -1
  100. package/payload/server/public/assets/public-BgnqjAal.js.br +0 -0
  101. package/payload/server/public/assets/public-BgnqjAal.js.gz +0 -0
  102. package/payload/server/public/assets/{rotate-ccw-rTRuTqei.js → rotate-ccw-DfJWjXAg.js} +1 -1
  103. package/payload/server/public/assets/rotate-ccw-DfJWjXAg.js.br +0 -0
  104. package/payload/server/public/assets/rotate-ccw-DfJWjXAg.js.gz +0 -0
  105. package/payload/server/public/assets/routines-Ds0yz7_C.js +2 -0
  106. package/payload/server/public/assets/routines-Ds0yz7_C.js.br +0 -0
  107. package/payload/server/public/assets/routines-Ds0yz7_C.js.gz +0 -0
  108. package/payload/server/public/assets/{skills-DFWtZNkW.js → skills-D-6EbgfP.js} +1 -1
  109. package/payload/server/public/assets/skills-D-6EbgfP.js.br +0 -0
  110. package/payload/server/public/assets/skills-D-6EbgfP.js.gz +0 -0
  111. package/payload/server/public/assets/{tasks-B94AuKSy.js → tasks-DnN5Fyds.js} +1 -1
  112. package/payload/server/public/assets/tasks-DnN5Fyds.js.br +0 -0
  113. package/payload/server/public/assets/tasks-DnN5Fyds.js.gz +0 -0
  114. package/payload/server/public/assets/{triangle-alert-DtWUg6jR.js → triangle-alert-eh9UOKDT.js} +1 -1
  115. package/payload/server/public/assets/triangle-alert-eh9UOKDT.js.br +0 -0
  116. package/payload/server/public/assets/triangle-alert-eh9UOKDT.js.gz +0 -0
  117. package/payload/server/public/assets/{useCopyFeedback-CjKYO-Qf.js → useCopyFeedback-Bz9OJHBb.js} +1 -1
  118. package/payload/server/public/assets/useCopyFeedback-Bz9OJHBb.js.br +0 -0
  119. package/payload/server/public/assets/useCopyFeedback-Bz9OJHBb.js.gz +0 -0
  120. package/payload/server/public/assets/{useMediaQuery-DlOWP56H.css → useMediaQuery-CNxsjKZp.css} +1 -1
  121. package/payload/server/public/assets/useMediaQuery-CNxsjKZp.css.br +0 -0
  122. package/payload/server/public/assets/{useMediaQuery-DlOWP56H.css.gz → useMediaQuery-CNxsjKZp.css.gz} +0 -0
  123. package/payload/server/public/assets/{useVoiceRecorder-BKFAYuzz.js → useVoiceRecorder-BaDpMYxX.js} +1 -1
  124. package/payload/server/public/assets/useVoiceRecorder-BaDpMYxX.js.br +0 -0
  125. package/payload/server/public/assets/useVoiceRecorder-BaDpMYxX.js.gz +0 -0
  126. package/payload/server/public/assets/{wrench-Ct4kf-uv.js → wrench-BO-l46rF.js} +1 -1
  127. package/payload/server/public/assets/wrench-BO-l46rF.js.br +0 -0
  128. package/payload/server/public/assets/wrench-BO-l46rF.js.gz +0 -0
  129. package/payload/server/public/browser.html +4 -4
  130. package/payload/server/public/calendar.html +8 -8
  131. package/payload/server/public/chat.html +13 -13
  132. package/payload/server/public/data.html +11 -11
  133. package/payload/server/public/graph.html +9 -9
  134. package/payload/server/public/index.html +14 -14
  135. package/payload/server/public/operator.html +14 -14
  136. package/payload/server/public/public.html +13 -13
  137. package/payload/server/public/routines.html +6 -6
  138. package/payload/server/public/skills.html +5 -5
  139. package/payload/server/public/tasks.html +6 -6
  140. package/payload/server/server.js +56 -355
  141. package/payload/server/public/assets/AdminLoginScreens-BGKtDqAk.js.br +0 -0
  142. package/payload/server/public/assets/AdminLoginScreens-BGKtDqAk.js.gz +0 -0
  143. package/payload/server/public/assets/AdminShell-DnfgsAQl.js.br +0 -0
  144. package/payload/server/public/assets/activity-ByJSut0Q.js.br +0 -0
  145. package/payload/server/public/assets/activity-ByJSut0Q.js.gz +0 -0
  146. package/payload/server/public/assets/admin-CkeJO6kA.js.br +0 -0
  147. package/payload/server/public/assets/admin-CkeJO6kA.js.gz +0 -0
  148. package/payload/server/public/assets/agents-D8phtRX5.js.br +0 -0
  149. package/payload/server/public/assets/agents-D8phtRX5.js.gz +0 -0
  150. package/payload/server/public/assets/browser-DQSTjdom.js.br +0 -0
  151. package/payload/server/public/assets/browser-DQSTjdom.js.gz +0 -0
  152. package/payload/server/public/assets/calendar-DFJu1XjP.js.br +0 -0
  153. package/payload/server/public/assets/calendar-DFJu1XjP.js.gz +0 -0
  154. package/payload/server/public/assets/chat-DUqtIsOt.js +0 -1
  155. package/payload/server/public/assets/chat-DUqtIsOt.js.br +0 -0
  156. package/payload/server/public/assets/chat-DUqtIsOt.js.gz +0 -0
  157. package/payload/server/public/assets/chevron-left-DFK18xVX.js +0 -1
  158. package/payload/server/public/assets/chevron-left-DFK18xVX.js.br +0 -0
  159. package/payload/server/public/assets/chevron-right-DJ4oaHoN.js +0 -1
  160. package/payload/server/public/assets/chevron-right-DJ4oaHoN.js.br +0 -0
  161. package/payload/server/public/assets/clock-wHIan2DW.js +0 -1
  162. package/payload/server/public/assets/clock-wHIan2DW.js.br +0 -0
  163. package/payload/server/public/assets/copy-lFFhXRGk.js.br +0 -0
  164. package/payload/server/public/assets/copy-lFFhXRGk.js.gz +0 -0
  165. package/payload/server/public/assets/data-Cxv97ARy.js +0 -1
  166. package/payload/server/public/assets/data-Cxv97ARy.js.br +0 -0
  167. package/payload/server/public/assets/data-Cxv97ARy.js.gz +0 -0
  168. package/payload/server/public/assets/file-text-D2Y-bkNy.js.br +0 -0
  169. package/payload/server/public/assets/file-text-D2Y-bkNy.js.gz +0 -0
  170. package/payload/server/public/assets/graph-C-3yN6JD.js.br +0 -0
  171. package/payload/server/public/assets/graph-C-3yN6JD.js.gz +0 -0
  172. package/payload/server/public/assets/graph-labels-DiaPLP27.js.br +0 -0
  173. package/payload/server/public/assets/graph-labels-DiaPLP27.js.gz +0 -0
  174. package/payload/server/public/assets/operator-KuGPvSa9.js.br +0 -0
  175. package/payload/server/public/assets/operator-KuGPvSa9.js.gz +0 -0
  176. package/payload/server/public/assets/page-BhGeFXWA.js.br +0 -0
  177. package/payload/server/public/assets/page-BhGeFXWA.js.gz +0 -0
  178. package/payload/server/public/assets/page-EnbVC-yM.js.br +0 -0
  179. package/payload/server/public/assets/page-EnbVC-yM.js.gz +0 -0
  180. package/payload/server/public/assets/play-jZFZAG-t.js +0 -1
  181. package/payload/server/public/assets/play-jZFZAG-t.js.br +0 -0
  182. package/payload/server/public/assets/play-jZFZAG-t.js.gz +0 -0
  183. package/payload/server/public/assets/public-CdSgMNC7.js.br +0 -0
  184. package/payload/server/public/assets/public-CdSgMNC7.js.gz +0 -0
  185. package/payload/server/public/assets/rotate-ccw-rTRuTqei.js.br +0 -0
  186. package/payload/server/public/assets/rotate-ccw-rTRuTqei.js.gz +0 -0
  187. package/payload/server/public/assets/routines-DNRxNRSQ.js +0 -2
  188. package/payload/server/public/assets/routines-DNRxNRSQ.js.br +0 -0
  189. package/payload/server/public/assets/routines-DNRxNRSQ.js.gz +0 -0
  190. package/payload/server/public/assets/skills-DFWtZNkW.js.br +0 -0
  191. package/payload/server/public/assets/skills-DFWtZNkW.js.gz +0 -0
  192. package/payload/server/public/assets/tasks-B94AuKSy.js.br +0 -0
  193. package/payload/server/public/assets/tasks-B94AuKSy.js.gz +0 -0
  194. package/payload/server/public/assets/triangle-alert-DtWUg6jR.js.br +0 -0
  195. package/payload/server/public/assets/triangle-alert-DtWUg6jR.js.gz +0 -0
  196. package/payload/server/public/assets/useCopyFeedback-CjKYO-Qf.js.br +0 -0
  197. package/payload/server/public/assets/useCopyFeedback-CjKYO-Qf.js.gz +0 -0
  198. package/payload/server/public/assets/useMediaQuery-DlOWP56H.css.br +0 -0
  199. package/payload/server/public/assets/useVoiceRecorder-BKFAYuzz.js.br +0 -0
  200. package/payload/server/public/assets/useVoiceRecorder-BKFAYuzz.js.gz +0 -0
  201. package/payload/server/public/assets/wrench-Ct4kf-uv.js.br +0 -0
  202. package/payload/server/public/assets/wrench-Ct4kf-uv.js.gz +0 -0
  203. /package/payload/server/public/assets/{useMediaQuery-BYIHo-xL.js → useMediaQuery-_mMln3Fu.js} +0 -0
  204. /package/payload/server/public/assets/{useMediaQuery-BYIHo-xL.js.br → useMediaQuery-_mMln3Fu.js.br} +0 -0
  205. /package/payload/server/public/assets/{useMediaQuery-BYIHo-xL.js.gz → useMediaQuery-_mMln3Fu.js.gz} +0 -0
@@ -0,0 +1,2 @@
1
+ import{o as e}from"./chunk-CltuBf4Z.js";import{F as t,G as n,L as r,M as i,O as a,V as o,Y as s,Z as c,_ as l,at as u,ct as d,f,j as p,k as m,m as h,nt as g,ot as _,v}from"./useMediaQuery-_mMln3Fu.js";import{k as y,m as b,t as x}from"./AdminShell-DVBAMUCy.js";import{t as S}from"./clock-CfDdatjp.js";import{t as C}from"./wrench-BO-l46rF.js";import{r as w}from"./file-download-DbNIjWiK.js";var ee=c(`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`}]]),te=c(`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`}]]),T=c(`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`}]]),E=_(),D=e(d(),1),O=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function k(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 A(e){return String(e).padStart(2,`0`)}function j(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`:`${O[e%7]} to ${O[n%7]}`}let n=e.split(`,`);return n.length>0&&n.every(e=>/^\d+$/.test(e)&&Number(e)<=7)?n.map(e=>O[Number(e)%7]).join(`, `):`invalid`}function M(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=k(n,59),c=k(r,23);if(!s||!c)return e;let l=j(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}, ${A(c.value)}:00 to ${A(c.value)}:59${u}`:`${e}, ${A(c.rangeStart)}:00 to ${A(d(c))}:00${u}`}if(c.kind===`step`){let e=A(s.value),t=s.value===0?``:` at :${e}`;return c.rangeStart===null?`Every ${c.step} hours${t}${u}`:c.step===1?`Hourly, ${A(c.rangeStart)}:${e} to ${A(c.rangeEnd)}:${e}${u}`:`Every ${c.step} hours, ${A(c.rangeStart)}:${e} to ${A(d(c))}:${e}${u}`}if(c.kind===`any`)return`${s.value===0?`Every hour`:`Every hour at :${A(s.value)}`}${u}`;let f=`${A(c.value)}:${A(s.value)}`;return i===`*`?l?`${l} at ${f}`:`Daily at ${f}`:`Monthly on day ${Number(i)} at ${f}`}var N={timeMode:`at`,minute:0,hour:9,interval:1,window:null,dayMode:`every`,weekdays:[],dayOfMonth:1};function P(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 F(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=k(n,59),c=k(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=P(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{...N,...f,timeMode:`everyMinutes`,minute:0,interval:e,window:t}}return c.kind===`fixed`?{...N,...f,timeMode:`at`,minute:s.value,hour:c.value}:c.kind===`any`?{...N,...f,timeMode:`everyHours`,minute:s.value,interval:1,window:null}:{...N,...f,timeMode:`everyHours`,minute:s.value,interval:c.step,window:c.rangeStart===null?null:{start:c.rangeStart,end:c.rangeEnd}}}function I(e){return e.dayMode===`dayOfMonth`?[String(e.dayOfMonth),`*`]:e.dayMode===`weekdays`&&e.weekdays.length>0?[`*`,[...e.weekdays].sort((e,t)=>e-t).join(`,`)]:[`*`,`*`]}function L(e){let[t,n]=I(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 R=g(),z=[{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`}],B=Array.from({length:24},(e,t)=>t),V=e=>String(e).padStart(2,`0`),H={timeMode:`at`,minute:0,hour:9,interval:1,window:null,dayMode:`every`,weekdays:[],dayOfMonth:1};function ne({recurrence:e,onChange:t,disabled:n}){let r=e?F(e):H,[i,a]=(0,D.useState)(r??H),[o]=(0,D.useState)(e!=null&&r==null),[s,c]=(0,D.useState)(e??``);if((0,D.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,R.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,R.jsx)(`span`,{children:`Schedule (advanced)`}),(0,R.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,R.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(L(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,R.jsxs)(`div`,{className:`routine-sched`,children:[(0,R.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,R.jsx)(`span`,{children:`How often`}),(0,R.jsxs)(`select`,{"aria-label":`How often`,value:i.timeMode,disabled:n,onChange:e=>u(e.target.value),children:[(0,R.jsx)(`option`,{value:`at`,children:`At a time of day`}),(0,R.jsx)(`option`,{value:`everyMinutes`,children:`Every few minutes`}),(0,R.jsx)(`option`,{value:`everyHours`,children:`Every few hours`})]})]}),i.timeMode===`at`&&(0,R.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,R.jsx)(`span`,{children:`Time of day`}),(0,R.jsx)(`input`,{type:`time`,"aria-label":`Time of day`,value:`${V(i.hour)}:${V(i.minute)}`,disabled:n,onChange:e=>f(e.target.value)})]}),i.timeMode===`everyMinutes`&&(0,R.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,R.jsx)(`span`,{children:`Minutes between runs`}),(0,R.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,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,R.jsx)(`span`,{children:`Hours between runs`}),(0,R.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,R.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,R.jsx)(`span`,{children:`Minute of the hour`}),(0,R.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,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`label`,{className:`cal-modal-field routine-sched-check`,children:[(0,R.jsx)(`input`,{type:`checkbox`,"aria-label":`Only between certain hours`,checked:i.window!==null,disabled:n,onChange:e=>m(e.target.checked)}),(0,R.jsx)(`span`,{children:`Only between certain hours`})]}),i.window!==null&&(0,R.jsxs)(`div`,{className:`routine-sched-row`,children:[(0,R.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,R.jsx)(`span`,{children:`From hour`}),(0,R.jsx)(`select`,{"aria-label":`From hour`,value:i.window.start,disabled:n,onChange:e=>h(`start`,e.target.value),children:B.map(e=>(0,R.jsxs)(`option`,{value:e,children:[V(e),`:00`]},e))})]}),(0,R.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,R.jsx)(`span`,{children:`To hour`}),(0,R.jsx)(`select`,{"aria-label":`To hour`,value:i.window.end,disabled:n,onChange:e=>h(`end`,e.target.value),children:B.map(e=>(0,R.jsxs)(`option`,{value:e,children:[V(e),`:00`]},e))})]})]})]}),(0,R.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,R.jsx)(`span`,{children:`Which days`}),(0,R.jsxs)(`select`,{"aria-label":`Which days`,value:i.dayMode,disabled:n,onChange:e=>d(e.target.value),children:[(0,R.jsx)(`option`,{value:`every`,children:`Every day`}),(0,R.jsx)(`option`,{value:`weekdays`,children:`Specific days`}),i.timeMode===`at`&&(0,R.jsx)(`option`,{value:`dayOfMonth`,children:`A day of the month`})]})]}),i.dayMode===`weekdays`&&(0,R.jsxs)(`div`,{className:`cal-modal-field`,children:[(0,R.jsx)(`span`,{children:`Days`}),(0,R.jsx)(`div`,{className:`routine-weekdays`,children:z.map(e=>(0,R.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,R.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,R.jsx)(`span`,{children:`Day of month`}),(0,R.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,R.jsx)(`option`,{value:e,children:e},e))})]})]})}function U(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 re(e){if(e.name)return`${e.name} · ${e.label}`;let t=e.channel===`whatsapp`?U(e.destination):e.destination;return`${e.label} · ${t}`}var W={scheduled:`live`,due:`live`,suspended:`stood-down`,cancelled:`inert`,completed:`inert`};function G(e){return e==null||!Object.hasOwn(W,e)?`unknown`:W[e]}var K={finished:`live`,started:`in-flight`,accepted:`in-flight`,open:`in-flight`,failed:`error`,"no-destination":`warning`};function q(e){return e==null||!Object.hasOwn(K,e)?`unknown`:K[e]}function ie({eventStatus:e}){let t=G(e);return(0,R.jsx)(`span`,{className:`routine-status-dot is-${t}`,"data-state":t,"aria-hidden":`true`})}function ae(e,t){if(!e)return`—`;let n=Date.parse(e);return Number.isFinite(n)?l(new Date(n).toISOString(),t):e}function oe(e){return e?e.split(`
2
+ `).filter(e=>e.trim()!==``).reverse():[]}function J({routine:e,adminFetch:t,onClose:n,onSaved:a,onDeleted:s,onViewRuns:c}){let{zone:l}=v(),[u,d]=(0,D.useState)(!1),[m,g]=(0,D.useState)(!1),[_,y]=(0,D.useState)(null),[x,w]=(0,D.useState)(e),[E,O]=(0,D.useState)(!1),k=x.agentChannel!=null,A=x.eventStatus===`suspended`,[j,N]=(0,D.useState)(!1),[P,F]=(0,D.useState)(e.agentPrompt??``),[I,L]=(0,D.useState)(e.recurrence),[z,B]=(0,D.useState)(e.agentChannel??``),[V,H]=(0,D.useState)(e.agentDestination??``),[U,W]=(0,D.useState)(null),[G,K]=(0,D.useState)(null),q=k||x.actionPlugin==null,J=oe(x.notes);(0,D.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!m&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[m,n]),(0,D.useEffect)(()=>{if(!u||!q||U!==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||W(t.destinations)}).catch(t=>{e||(W([]),K(t instanceof Error?t.message:`Could not load destinations`))}),()=>{e=!0}},[u,q,U,t]);let Y=(U??[]).filter(e=>e.channel===z),X=z.length>0&&V.length>0,se=z.length>0&&V.length===0||X&&P.trim().length===0,Z=(0,D.useCallback)(()=>{let e={},t=z.length>0&&V.length>0;return(k||t)&&P!==(x.agentPrompt??``)&&(e.agentPrompt=P),I!=null&&I!==(x.recurrence??null)&&(e.recurrence=I),t&&(z!==(x.agentChannel??``)||V!==(x.agentDestination??``))?(e.agentChannel=z,e.agentDestination=V):!t&&z===``&&(x.agentChannel??``)!==``&&(e.agentChannel=null,e.agentDestination=null),e},[k,P,I,z,V,x]),Q=(0,D.useCallback)(async()=>{let n=Z();if(Object.keys(n).length===0){d(!1);return}g(!0),y(null);try{let r=await t(`/api/admin/routines/${encodeURIComponent(e.eventId)}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(n)});if(!r.ok){let e=await r.json().catch(()=>({}));throw Error(e.error??`HTTP ${r.status}`)}let i=await r.json();w(i.routine),F(i.routine.agentPrompt??``),L(i.routine.recurrence),B(i.routine.agentChannel??``),H(i.routine.agentDestination??``),a(i.routine),d(!1)}catch(e){y(e instanceof Error?e.message:`Save failed`)}finally{g(!1)}},[t,Z,e.eventId,a]),ce=(0,D.useCallback)(async()=>{if(m)return;if(!j){O(!1),N(!0);return}let n=A?`resume`:`suspend`;g(!0),y(null);try{let r=await t(`/api/admin/routines/${encodeURIComponent(e.eventId)}/${n}`,{method:`POST`});if(!r.ok){let e=await r.json().catch(()=>({}));throw Error(e.error??`HTTP ${r.status}`)}let i=await r.json();w(i.routine),a(i.routine),N(!1)}catch(e){y(e instanceof Error?e.message:`${n} failed`),N(!1)}finally{g(!1)}},[t,m,j,A,e.eventId,a]),le=(0,D.useCallback)(async()=>{if(!m){if(!E){N(!1),O(!0);return}g(!0),y(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}`)}s(e.eventId)}catch(e){y(e instanceof Error?e.message:`Delete failed`),O(!1)}finally{g(!1)}}},[t,m,E,e.eventId,s]);return(0,R.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{m||n()},children:(0,R.jsxs)(`div`,{className:`cal-modal ${!u||k||X?`cal-modal-wide`:`cal-modal-dispatch`}`,role:`dialog`,"aria-modal":`true`,"aria-label":u?`Edit routine`:`Routine detail`,onClick:e=>e.stopPropagation(),children:[(0,R.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,R.jsxs)(`span`,{className:`cal-modal-kind`,children:[(0,R.jsx)(b,{size:13}),` Routine`]}),(0,R.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:n,"aria-label":`Close`,autoFocus:!0,disabled:m,children:(0,R.jsx)(p,{size:16})})]}),!u&&(0,R.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,R.jsx)(`div`,{className:`cal-modal-title`,children:x.name??`Untitled routine`}),(0,R.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,R.jsx)(S,{size:14}),(0,R.jsx)(`span`,{children:x.recurrence?M(x.recurrence):`One-time`})]}),(0,R.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,R.jsx)(ie,{eventStatus:x.eventStatus}),(0,R.jsxs)(`span`,{children:[`Status: `,x.eventStatus??`unknown`]})]}),(0,R.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,R.jsxs)(`span`,{children:[`Next run: `,ae(x.nextRun,l)]})}),(0,R.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,R.jsx)(T,{size:14}),(0,R.jsxs)(`span`,{children:[`Last run: `,ae(x.lastTriggered,l),x.lastDispatchResult?` (${x.lastDispatchResult})`:``]})]}),k?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,R.jsx)(h,{channel:x.agentChannel,size:14}),(0,R.jsxs)(`span`,{children:[f[x.agentChannel]??x.agentChannel,` to `,x.agentDestination??`—`]})]}),(0,R.jsx)(`div`,{className:`cal-modal-row cal-modal-row-top routine-prose`,children:(0,R.jsx)(`span`,{children:x.agentPrompt??`No instruction set.`})})]}):x.actionPlugin?(0,R.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,R.jsx)(C,{size:14}),(0,R.jsxs)(`span`,{children:[x.actionPlugin,`.`,x.actionTool,x.actionArgs?` ${x.actionArgs}`:``]})]}):(0,R.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,R.jsx)(S,{size:14}),(0,R.jsx)(`span`,{children:`Scheduled trigger (no dispatch)`})]}),J.length===0?(0,R.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,R.jsx)(T,{size:14}),(0,R.jsx)(`span`,{children:`No history recorded.`})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,R.jsx)(T,{size:14}),(0,R.jsxs)(`span`,{children:[`History (`,J.length,` `,J.length===1?`entry`:`entries`,`)`]})]}),(0,R.jsx)(`div`,{className:`routine-history`,children:J.map((e,t)=>(0,R.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:e},t))})]})]}),u&&(0,R.jsxs)(`div`,{className:`cal-modal-body`,children:[q&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,R.jsx)(`span`,{children:`Send to`}),(0,R.jsxs)(`div`,{className:`cal-modal-field-inline`,children:[(0,R.jsxs)(`select`,{value:z,disabled:m,onChange:e=>{B(e.target.value),H(``)},children:[(0,R.jsx)(`option`,{value:``,children:`None (no dispatch)`}),(0,R.jsx)(`option`,{value:`whatsapp`,children:`WhatsApp`}),(0,R.jsx)(`option`,{value:`telegram`,children:`Telegram`})]}),z!==``&&(0,R.jsx)(h,{channel:z,size:16})]})]}),z!==``&&(0,R.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,R.jsx)(`span`,{children:`Destination`}),(0,R.jsxs)(`select`,{value:V,disabled:m||U===null,onChange:e=>H(e.target.value),children:[(0,R.jsx)(`option`,{value:``,children:U===null?`Loading destinations`:Y.length===0?`No registered destinations`:`Choose a destination`}),V!==``&&!Y.some(e=>e.destination===V)&&(0,R.jsxs)(`option`,{value:V,children:[V,` (not in the current list)`]}),Y.map(e=>(0,R.jsx)(`option`,{value:e.destination,children:re(e)},e.destination))]})]}),G&&(0,R.jsxs)(`div`,{className:`cal-modal-error`,children:[`Could not load destinations: `,G]})]}),(k||X)&&(0,R.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,R.jsx)(`span`,{children:`Instruction`}),(0,R.jsx)(`textarea`,{className:`cal-modal-textarea`,value:P,onChange:e=>F(e.target.value),disabled:m,rows:16,placeholder:`What should the agent do when this routine fires?`})]}),(0,R.jsx)(ne,{recurrence:x.recurrence,onChange:L,disabled:m})]}),_&&(0,R.jsx)(`div`,{className:`cal-modal-error`,children:_}),(0,R.jsxs)(`div`,{className:`cal-modal-actions`,children:[!u&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>{O(!1),N(!1),d(!0)},disabled:m,children:[(0,R.jsx)(r,{size:14}),` Edit`]}),(0,R.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>c(x),disabled:m,children:[(0,R.jsx)(T,{size:14}),` Runs`]}),(0,R.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:ce,disabled:m,children:[m&&j?(0,R.jsx)(o,{size:14,className:`spin`}):A?(0,R.jsx)(te,{size:14}):(0,R.jsx)(ee,{size:14}),j?A?`Confirm resume`:`Confirm suspend`:A?`Resume`:`Suspend`]}),j&&(0,R.jsx)(`span`,{className:`cal-modal-confirm-text`,children:A?`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,R.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:le,disabled:m,children:[m&&E?(0,R.jsx)(o,{size:14,className:`spin`}):(0,R.jsx)(i,{size:14}),E?`Confirm delete`:`Delete`]})]}),u&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-primary`,onClick:Q,disabled:m||se,children:[m?(0,R.jsx)(o,{size:14,className:`spin`}):null,` Save`]}),(0,R.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>{d(!1),y(null)},disabled:m,children:`Cancel`})]})]})]})})}function Y(e,t){if(!e)return`—`;let n=Date.parse(e);return Number.isFinite(n)?l(new Date(n).toISOString(),t):e}function X(e){return e===null?`—`:e<1e3?`${e} ms`:`${(e/1e3).toFixed(1)} s`}function se({run:e,routineName:t,onClose:n}){let{zone:r}=v();return(0,D.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,R.jsx)(`div`,{className:`cal-modal-overlay`,onClick:n,children:(0,R.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":`Run detail`,onClick:e=>e.stopPropagation(),children:[(0,R.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,R.jsx)(`span`,{className:`cal-modal-kind`,children:`Run`}),(0,R.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:n,"aria-label":`Close`,autoFocus:!0,children:(0,R.jsx)(p,{size:16})})]}),(0,R.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,R.jsx)(`div`,{className:`cal-modal-title`,children:t??`Untitled routine`}),e.outputExcerpt!==null&&(0,R.jsx)(`div`,{className:`cal-modal-row cal-modal-row-top routine-prose`,"data-testid":`run-output`,children:(0,R.jsx)(`span`,{children:e.outputExcerpt})}),e.outputExcerpt===null&&e.status===`finished`&&(0,R.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,"data-testid":`run-output-none`,children:(0,R.jsx)(`span`,{children:`This run finished without sending anything.`})}),(0,R.jsx)(`div`,{className:`cal-modal-row`,children:(0,R.jsx)(`span`,{children:e.status})}),(0,R.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,R.jsxs)(`span`,{children:[`Due: `,Y(e.scheduledFor,r)]})}),(0,R.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,R.jsxs)(`span`,{children:[`Started: `,Y(e.startedAt,r)]})}),(0,R.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,R.jsxs)(`span`,{children:[`Dispatch ended: `,Y(e.endedAt,r),` (`,X(e.ranMs),`)`]})}),(0,R.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,R.jsxs)(`span`,{children:[`Output seen: `,Y(e.finishedAt,r)]})}),(0,R.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,R.jsxs)(`span`,{children:[`Sent to: `,e.target,` · `,e.mode,` · `,e.kind]})}),(0,R.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,R.jsxs)(`span`,{children:[`Transport: `,e.dispatchResult??`—`,e.httpStatus===null?``:` (HTTP ${e.httpStatus})`]})}),e.error&&(0,R.jsx)(`div`,{className:`cal-modal-row cal-modal-row-top routine-prose`,children:(0,R.jsx)(`span`,{children:e.error})}),(0,R.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,R.jsxs)(`span`,{children:[`Conversation: `,e.sessionKey??`—`,e.transcriptOffset===null?``:` at byte ${e.transcriptOffset}`]})}),!e.bounded&&(0,R.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,R.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,R.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,R.jsxs)(`span`,{children:[`Run `,e.runId]})})]})]})})}function Z({status:e}){let t=q(e);return(0,R.jsx)(`span`,{className:`routine-status-dot is-${t}`,"data-state":t,"aria-hidden":`true`})}var Q=500;function ce(e,t){if(!e)return`—`;let n=Date.parse(e);return Number.isFinite(n)?l(new Date(n).toISOString(),t):e}function le(e){return e===null?`—`:e<1e3?`${e} ms`:`${(e/1e3).toFixed(1)} s`}var ue={channel:`a channel`,destination:`a destination`,prompt:`an instruction`};function de(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 ue)){let e=t.map(e=>ue[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 fe(e){return e.status===`no-destination`?e.error?de(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 pe(e){let t=e.indexOf(`:`);return t<=0?{channel:null,destination:e}:{channel:e.slice(0,t),destination:e.slice(t+1)}}function me(e){return e.outputExcerpt===null?e.status===`finished`?`Finished and sent nothing.`:null:e.outputExcerpt}function he({routine:e,adminFetch:r,cacheKey:i,from:a=`card`,onBack:c}){let{zone:l}=v(),[u,d]=(0,D.useState)([]),[p,m]=(0,D.useState)(!0),[g,_]=(0,D.useState)(null),[y,b]=(0,D.useState)(null),x=(0,D.useRef)(0),S=(0,D.useCallback)(()=>{let t=!1,n=++x.current,i=()=>t||n!==x.current;return m(!0),_(null),r(`/api/admin/routines/${encodeURIComponent(e.eventId)}/runs?limit=${Q}&from=${a}`).then(async e=>{if(i())return;if(!e.ok)throw Error(`HTTP ${e.status}`);let t=await e.json();i()||d(Array.isArray(t.runs)?t.runs:[])}).catch(e=>{i()||(_(e instanceof Error?e.message:`Failed to load`),d([]))}).finally(()=>{i()||m(!1)}),()=>{t=!0}},[r,e.eventId,a]);(0,D.useEffect)(()=>S(),[S]);let C=(0,D.useCallback)(()=>{w(i,e.eventId)},[i,e.eventId]);return(0,R.jsxs)(`div`,{className:`cal-page`,children:[(0,R.jsx)(`header`,{className:`cal-header`,children:(0,R.jsxs)(`div`,{className:`cal-nav`,children:[(0,R.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:c,children:[(0,R.jsx)(s,{size:14}),` Routines`]}),(0,R.jsx)(`span`,{className:`cal-range-label runs-title`,"data-testid":`runs-title`,title:e.name??`Untitled routine`,children:e.name??`Untitled routine`}),(0,R.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,"data-testid":`runs-refresh`,onClick:S,disabled:p,title:`Refresh runs`,"aria-label":`Refresh runs`,children:[p?(0,R.jsx)(o,{size:14,className:`spin`}):(0,R.jsx)(t,{size:14}),` Refresh`]}),u.length>0&&(0,R.jsx)(`div`,{className:`routine-bulk-actions`,children:(0,R.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:C,children:[(0,R.jsx)(n,{size:14}),` Download all runs`]})})]})}),(0,R.jsxs)(`div`,{className:`cal-body`,children:[g&&(0,R.jsxs)(`div`,{className:`cal-error`,children:[`Could not load runs: `,g]}),!g&&!p&&u.length===0&&(0,R.jsxs)(`div`,{className:`cal-empty`,"data-testid":`runs-empty`,children:[(0,R.jsx)(`p`,{children:`Nothing to show for this routine.`}),(0,R.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,R.jsxs)(`p`,{children:[`For a repeating routine, the server log settles the middle one: a`,(0,R.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.`]})]}),u.length>=Q&&(0,R.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,R.jsx)(`div`,{className:`routine-list`,children:u.map(e=>{let t=fe(e),n=me(e),{channel:r,destination:i}=pe(e.target);return(0,R.jsxs)(`button`,{type:`button`,className:`admin-card admin-card--padded routine-card`,"data-testid":`run-row-${e.runId}`,onClick:()=>b(e),children:[(0,R.jsxs)(`span`,{className:`admin-card-title routine-card-title run-card-title`,children:[(0,R.jsx)(Z,{status:e.status}),` `,e.status]}),(0,R.jsx)(`span`,{className:`routine-card-sched`,children:le(e.ranMs)}),(0,R.jsx)(`span`,{className:`routine-card-target`,children:r?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(h,{channel:r,size:13}),` `,f[r]??r,` to `,r===`whatsapp`?U(i):i]}):i}),(0,R.jsxs)(`span`,{className:`routine-card-meta`,children:[`Due `,ce(e.scheduledFor,l)]}),n&&(0,R.jsx)(`span`,{className:`routine-card-meta run-card-output`,children:n}),t&&(0,R.jsx)(`span`,{className:`routine-card-meta run-card-detail`,children:t})]},e.runId)})})]}),y&&(0,R.jsx)(se,{run:y,routineName:e.name,onClose:()=>b(null)})]})}var $=`maxy-admin-session-key`;function ge(e){return e?M(e):`One-time`}function _e(e,t){if(!e)return`—`;let n=Date.parse(e);return Number.isFinite(n)?l(new Date(n).toISOString(),t):e}function ve(){let[e,t]=(0,D.useState)(null),[n,r]=(0,D.useState)(!1),[i,o]=(0,D.useState)(void 0),[s,c]=(0,D.useState)(null),[l,u]=(0,D.useState)(void 0),[d,f]=(0,D.useState)(null),[p,h]=(0,D.useState)(null);(0,D.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`&&o(e.businessName),e.sessionId!==void 0&&c(e.sessionId??null),h(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 g=(0,D.useCallback)(()=>{try{sessionStorage.removeItem($)}catch{}window.location.href=`/`},[]),[_,v]=(0,D.useState)(!1),b=(0,D.useCallback)(async()=>{v(!0);try{let e=await y();if(e){try{sessionStorage.removeItem($)}catch{}window.location.href=`/`}return e}finally{v(!1)}},[]);return n?e?(0,R.jsx)(m,{cacheKey:e,surface:`routines`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=routines`);try{sessionStorage.removeItem($)}catch{}window.location.href=`/`},children:(0,R.jsx)(x,{cacheKey:e,businessName:i,sessionId:s,onLogout:g,onDisconnect:b,disconnecting:_,userName:l,userAvatar:d,role:p,children:(0,R.jsx)(ye,{cacheKey:e})})}):(0,R.jsx)(`div`,{className:`cal-page`,children:(0,R.jsxs)(`div`,{className:`cal-empty`,children:[(0,R.jsx)(`p`,{children:`You are not signed in.`}),(0,R.jsxs)(`p`,{children:[`Open the `,(0,R.jsx)(`a`,{href:`/`,className:`cal-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,R.jsx)(a,{surface:`gate`})}function ye({cacheKey:e}){let{zone:n}=v(),{adminFetch:r,cacheKey:i,sessionRefetchNonce:s}=u({initialCacheKey:e,surface:`routines`}),[c,l]=(0,D.useState)([]),[d,p]=(0,D.useState)(!1),[m,g]=(0,D.useState)(!1),[_,y]=(0,D.useState)(null),[x,w]=(0,D.useState)(null),[E,O]=(0,D.useState)(null),[k,A]=(0,D.useState)(`card`),j=(0,D.useCallback)(()=>{let e=!1;return p(!0),y(null),r(`/api/admin/routines`).then(async t=>{if(e)return;if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();l(Array.isArray(n.routines)?n.routines:[])}).catch(t=>{e||(y(t instanceof Error?t.message:`Failed to load`),l([]))}).finally(()=>{e||(p(!1),g(!0))}),()=>{e=!0}},[r]);(0,D.useEffect)(()=>j(),[j,s]);let M=(0,D.useCallback)(e=>{l(t=>t.map(t=>t.eventId===e.eventId?e:t)),w(e)},[]),N=(0,D.useCallback)(e=>{l(t=>t.filter(t=>t.eventId!==e)),w(null)},[]),[P,F]=(0,D.useState)(!1),[I,L]=(0,D.useState)(null),z=c.filter(e=>e.eventStatus===`scheduled`).length,B=c.filter(e=>e.suspendedInBulk).length,V=(0,D.useCallback)(async e=>{F(!0),L(null);try{let t=await r(`/api/admin/routines/${e}`,{method:`POST`});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??`HTTP ${t.status}`)}let n=await t.json(),i=n.refused?.length??0;L(e===`suspend-all`?`Suspended ${n.suspended??0}. Nothing runs on its own until you resume it.`:`Resumed ${n.restored??0}${i>0?`. ${i} could not be resumed and stayed suspended`:``}. Routines you suspended one at a time are still suspended.`),j()}catch(e){L(e instanceof Error?e.message:`Failed`)}finally{F(!1)}},[r,j]);return m?E?(0,R.jsx)(he,{routine:E,adminFetch:r,cacheKey:i,from:k,onBack:()=>O(null)}):(0,R.jsxs)(`div`,{className:`cal-page`,children:[(0,R.jsx)(`header`,{className:`cal-header`,children:(0,R.jsxs)(`div`,{className:`cal-nav`,children:[(0,R.jsxs)(`span`,{className:`cal-range-label`,children:[(0,R.jsx)(b,{size:16}),` Routines`]}),(0,R.jsxs)(`div`,{className:`routine-bulk-actions`,children:[(0,R.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,"data-testid":`routines-refresh`,onClick:j,disabled:d,title:`Refresh routines`,"aria-label":`Refresh routines`,children:[d?(0,R.jsx)(o,{size:14,className:`spin`}):(0,R.jsx)(t,{size:14}),` Refresh`]}),(0,R.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>V(`suspend-all`),disabled:P||z===0,children:[(0,R.jsx)(ee,{size:14}),` Suspend all (`,z,`)`]}),(0,R.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>V(`resume-all`),disabled:P||B===0,children:[(0,R.jsx)(te,{size:14}),` Resume all (`,B,`)`]})]})]})}),(0,R.jsxs)(`div`,{className:`cal-body`,children:[I&&(0,R.jsx)(`div`,{className:`cal-modal-confirm-text`,children:I}),_&&(0,R.jsxs)(`div`,{className:`cal-error`,children:[`Could not load routines: `,_]}),!_&&!d&&c.length===0&&(0,R.jsx)(`div`,{className:`cal-empty`,children:(0,R.jsx)(`p`,{children:`No routines yet.`})}),(0,R.jsx)(`div`,{className:`routine-list`,children:c.map(e=>(0,R.jsxs)(`div`,{className:`admin-card admin-card--padded routine-card-shell`,children:[(0,R.jsxs)(`div`,{role:`button`,tabIndex:0,className:`routine-card`,"data-testid":`routine-card-${e.eventId}`,onClick:()=>w(e),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),w(e))},children:[(0,R.jsx)(`span`,{className:`admin-card-title routine-card-title`,children:e.name??`Untitled routine`}),e.routineDescription&&(0,R.jsx)(`span`,{className:`routine-card-desc`,children:e.routineDescription}),(0,R.jsxs)(`span`,{className:`routine-card-sched`,children:[(0,R.jsx)(S,{size:13}),` `,ge(e.recurrence)]}),(0,R.jsx)(`span`,{className:`routine-card-target`,children:e.agentChannel?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(h,{channel:e.agentChannel,size:13}),` `,f[e.agentChannel]??e.agentChannel,` to `,e.agentDestination??`—`]}):e.actionPlugin?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(C,{size:13}),` `,e.actionPlugin,`.`,e.actionTool]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(S,{size:13}),` Scheduled trigger`]})}),(0,R.jsxs)(`span`,{className:`routine-card-meta`,children:[(0,R.jsx)(ie,{eventStatus:e.eventStatus}),`Next: `,_e(e.nextRun,n),` · `,e.eventStatus??`unknown`]})]}),(0,R.jsx)(`button`,{type:`button`,className:`routine-card-runs`,"data-testid":`routine-runs-${e.eventId}`,title:`View runs`,"aria-label":`View runs for ${e.name??`this routine`}`,onClick:()=>{A(`card`),O(e)},children:(0,R.jsx)(T,{size:14})})]},e.eventId))})]}),x&&(0,R.jsx)(J,{routine:x,adminFetch:r,onClose:()=>w(null),onSaved:M,onDeleted:N,onViewRuns:e=>{A(`modal`),w(null),O(e)}})]}):(0,R.jsx)(a,{surface:`gate`})}(0,E.createRoot)(document.getElementById(`root`)).render((0,R.jsx)(ve,{}));
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{M as t,O as n,U as r,V as i,at as a,ct as o,j as s,k as c,nt as l,ot as u}from"./useMediaQuery-BYIHo-xL.js";import{h as d,k as f,t as p}from"./AdminShell-DnfgsAQl.js";import{t as m}from"./file-text-D2Y-bkNy.js";var h=u(),g=e(o(),1),_=l();function v({summary:e,adminFetch:n,onClose:a,onDeleted:o}){let[c,l]=(0,g.useState)(null),[u,f]=(0,g.useState)(!0),[p,h]=(0,g.useState)(null),[v,y]=(0,g.useState)(!1),[b,x]=(0,g.useState)(!1);(0,g.useEffect)(()=>{let t=!1;return f(!0),h(null),n(`/api/admin/skills/${encodeURIComponent(e.plugin)}/${encodeURIComponent(e.skill)}`).then(async e=>{if(!t){if(!e.ok)throw Error(`HTTP ${e.status}`);l((await e.json()).skill)}}).catch(e=>{t||h(e instanceof Error?e.message:`Failed to load`)}).finally(()=>{t||f(!1)}),()=>{t=!0}},[n,e.plugin,e.skill]),(0,g.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!b&&a()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[b,a]);let S=(0,g.useCallback)(async()=>{x(!0),h(null);try{let t=await n(`/api/admin/skills/${encodeURIComponent(e.plugin)}/${encodeURIComponent(e.skill)}`,{method:`DELETE`,headers:{"content-type":`application/json`}});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??`HTTP ${t.status}`)}o(e)}catch(e){h(e instanceof Error?e.message:`Delete failed`),x(!1),y(!1)}},[n,e,o]);return(0,_.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{b||a()},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)(d,{size:13}),` Skill`]}),(0,_.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:a,"aria-label":`Close`,autoFocus:!0,disabled:b,children:(0,_.jsx)(s,{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)(i,{size:14,className:`spin`}),(0,_.jsx)(`span`,{children:`Loading…`})]}),c&&(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,_.jsx)(`span`,{children:c.frontmatter.description||`No description.`})}),c.frontmatter.publicEmbed&&(0,_.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,_.jsx)(r,{size:14}),(0,_.jsx)(`span`,{children:`Public embed`})]}),(0,_.jsx)(`pre`,{className:`skill-body`,children:c.body.trim()||`No body content.`}),c.references.length>0&&(0,_.jsxs)(`div`,{className:`skill-refs`,children:[(0,_.jsx)(`span`,{className:`skill-refs-label`,children:`References`}),c.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)(t,{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)(i,{size:14,className:`spin`}):(0,_.jsx)(t,{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),[r,i]=(0,g.useState)(!1),[a,o]=(0,g.useState)(void 0),[s,l]=(0,g.useState)(null),[u,d]=(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){i(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async r=>{if(!e){if(r.status===401){try{sessionStorage.removeItem(y)}catch{}window.location.href=`/`;return}if(r.ok)try{let e=await r.json();typeof e.businessName==`string`&&o(e.businessName),e.sessionId!==void 0&&l(e.sessionId??null),b(e.role??null),d(e.userName===void 0?null:e.userName),h(e.avatar??null)}catch{}t(n),i(!0)}}).catch(()=>{e||(t(n),i(!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 f();if(e){try{sessionStorage.removeItem(y)}catch{}window.location.href=`/`}return e}finally{w(!1)}},[]);return r?e?(0,_.jsx)(c,{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:a,sessionId:s,onLogout:S,onDisconnect:T,disconnecting:C,userName:u,userAvatar:m,role:v,children:(0,_.jsx)(x,{cacheKey:e})})}):(0,_.jsx)(`div`,{className:`cal-page`,children:(0,_.jsxs)(`div`,{className:`cal-empty`,children:[(0,_.jsx)(`p`,{children:`You are not signed in.`}),(0,_.jsxs)(`p`,{children:[`Open the `,(0,_.jsx)(`a`,{href:`/`,className:`cal-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,_.jsx)(n,{surface:`gate`})}function x({cacheKey:e}){let{adminFetch:t,sessionRefetchNonce:r}=a({initialCacheKey:e,surface:`skills`}),[o,s]=(0,g.useState)([]),[c,l]=(0,g.useState)(!1),[u,f]=(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();s(Array.isArray(n.skills)?n.skills:[])}).catch(t=>{e||(h(t instanceof Error?t.message:`Failed to load`),s([]))}).finally(()=>{e||(l(!1),f(!0))}),()=>{e=!0}},[t]);(0,g.useEffect)(()=>x(),[x,r]);let S=(0,g.useCallback)(e=>{s(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)(d,{size:16}),` Skills`]}),c&&(0,_.jsx)(i,{size:16,className:`spin`})]})}),(0,_.jsxs)(`div`,{className:`cal-body`,children:[p&&(0,_.jsxs)(`div`,{className:`cal-error`,children:[`Could not load skills: `,p]}),!p&&!c&&o.length===0&&(0,_.jsx)(`div`,{className:`cal-empty`,children:(0,_.jsx)(`p`,{children:`No skills yet. Ask in chat to create one.`})}),o.length>0&&(0,_.jsx)(`div`,{className:`routine-list`,children:o.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)(n,{surface:`gate`})}(0,h.createRoot)(document.getElementById(`root`)).render((0,_.jsx)(b,{}));
1
+ import{o as e}from"./chunk-CltuBf4Z.js";import{M as t,O as n,U as r,V as i,at as a,ct as o,j as s,k as c,nt as l,ot as u}from"./useMediaQuery-_mMln3Fu.js";import{h as d,k as f,t as p}from"./AdminShell-DVBAMUCy.js";import{t as m}from"./file-text-zQgEQWCF.js";var h=u(),g=e(o(),1),_=l();function v({summary:e,adminFetch:n,onClose:a,onDeleted:o}){let[c,l]=(0,g.useState)(null),[u,f]=(0,g.useState)(!0),[p,h]=(0,g.useState)(null),[v,y]=(0,g.useState)(!1),[b,x]=(0,g.useState)(!1);(0,g.useEffect)(()=>{let t=!1;return f(!0),h(null),n(`/api/admin/skills/${encodeURIComponent(e.plugin)}/${encodeURIComponent(e.skill)}`).then(async e=>{if(!t){if(!e.ok)throw Error(`HTTP ${e.status}`);l((await e.json()).skill)}}).catch(e=>{t||h(e instanceof Error?e.message:`Failed to load`)}).finally(()=>{t||f(!1)}),()=>{t=!0}},[n,e.plugin,e.skill]),(0,g.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!b&&a()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[b,a]);let S=(0,g.useCallback)(async()=>{x(!0),h(null);try{let t=await n(`/api/admin/skills/${encodeURIComponent(e.plugin)}/${encodeURIComponent(e.skill)}`,{method:`DELETE`,headers:{"content-type":`application/json`}});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??`HTTP ${t.status}`)}o(e)}catch(e){h(e instanceof Error?e.message:`Delete failed`),x(!1),y(!1)}},[n,e,o]);return(0,_.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{b||a()},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)(d,{size:13}),` Skill`]}),(0,_.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:a,"aria-label":`Close`,autoFocus:!0,disabled:b,children:(0,_.jsx)(s,{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)(i,{size:14,className:`spin`}),(0,_.jsx)(`span`,{children:`Loading…`})]}),c&&(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,_.jsx)(`span`,{children:c.frontmatter.description||`No description.`})}),c.frontmatter.publicEmbed&&(0,_.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,_.jsx)(r,{size:14}),(0,_.jsx)(`span`,{children:`Public embed`})]}),(0,_.jsx)(`pre`,{className:`skill-body`,children:c.body.trim()||`No body content.`}),c.references.length>0&&(0,_.jsxs)(`div`,{className:`skill-refs`,children:[(0,_.jsx)(`span`,{className:`skill-refs-label`,children:`References`}),c.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)(t,{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)(i,{size:14,className:`spin`}):(0,_.jsx)(t,{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),[r,i]=(0,g.useState)(!1),[a,o]=(0,g.useState)(void 0),[s,l]=(0,g.useState)(null),[u,d]=(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){i(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async r=>{if(!e){if(r.status===401){try{sessionStorage.removeItem(y)}catch{}window.location.href=`/`;return}if(r.ok)try{let e=await r.json();typeof e.businessName==`string`&&o(e.businessName),e.sessionId!==void 0&&l(e.sessionId??null),b(e.role??null),d(e.userName===void 0?null:e.userName),h(e.avatar??null)}catch{}t(n),i(!0)}}).catch(()=>{e||(t(n),i(!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 f();if(e){try{sessionStorage.removeItem(y)}catch{}window.location.href=`/`}return e}finally{w(!1)}},[]);return r?e?(0,_.jsx)(c,{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:a,sessionId:s,onLogout:S,onDisconnect:T,disconnecting:C,userName:u,userAvatar:m,role:v,children:(0,_.jsx)(x,{cacheKey:e})})}):(0,_.jsx)(`div`,{className:`cal-page`,children:(0,_.jsxs)(`div`,{className:`cal-empty`,children:[(0,_.jsx)(`p`,{children:`You are not signed in.`}),(0,_.jsxs)(`p`,{children:[`Open the `,(0,_.jsx)(`a`,{href:`/`,className:`cal-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,_.jsx)(n,{surface:`gate`})}function x({cacheKey:e}){let{adminFetch:t,sessionRefetchNonce:r}=a({initialCacheKey:e,surface:`skills`}),[o,s]=(0,g.useState)([]),[c,l]=(0,g.useState)(!1),[u,f]=(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();s(Array.isArray(n.skills)?n.skills:[])}).catch(t=>{e||(h(t instanceof Error?t.message:`Failed to load`),s([]))}).finally(()=>{e||(l(!1),f(!0))}),()=>{e=!0}},[t]);(0,g.useEffect)(()=>x(),[x,r]);let S=(0,g.useCallback)(e=>{s(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)(d,{size:16}),` Skills`]}),c&&(0,_.jsx)(i,{size:16,className:`spin`})]})}),(0,_.jsxs)(`div`,{className:`cal-body`,children:[p&&(0,_.jsxs)(`div`,{className:`cal-error`,children:[`Could not load skills: `,p]}),!p&&!c&&o.length===0&&(0,_.jsx)(`div`,{className:`cal-empty`,children:(0,_.jsx)(`p`,{children:`No skills yet. Ask in chat to create one.`})}),o.length>0&&(0,_.jsx)(`div`,{className:`routine-list`,children:o.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)(n,{surface:`gate`})}(0,h.createRoot)(document.getElementById(`root`)).render((0,_.jsx)(b,{}));
@@ -1,3 +1,3 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{L as t,M as n,N as r,O as i,a,at as o,ct as s,j as c,k as l,nt as u,ot as d,q as f}from"./useMediaQuery-BYIHo-xL.js";import{a as p,f as m,k as h,n as g,t as _,v as ee}from"./AdminShell-DnfgsAQl.js";import{t as te}from"./play-jZFZAG-t.js";import{t as v}from"./rotate-ccw-rTRuTqei.js";var y=d(),b=e(s(),1);function ne(e=3e4){let[t,n]=(0,b.useState)(()=>Date.now());return(0,b.useEffect)(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}function re(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)),x(e,i),i}function x(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 S=`__unassigned__`;function C(e,t){return e===`__unassigned__`?`Unassigned`:t||e.slice(0,8)}function w(e){return e===null||e===``?S:e}function ie(e,t){let n=new Map,r=(e,t)=>{let r=w(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:C(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 T(e,t){return t===null?!0:w(e.assigneeUserId)===t}var E=u();function D(e){let t=e.name??e.userId.slice(0,8);return e.kind===`owner`?`${t} (owner)`:t}var O=`maxy-admin-session-key`;function k(e){let t=[];return e.clientName&&t.push(e.clientName),e.propertyAddress&&t.push(e.propertyAddress),e.fee!=null&&t.push(`£${e.fee}`),t.join(` · `)}function A(e){if(!e)return``;let t=Date.parse(e);if(!Number.isFinite(t))return``;let n=new Date(t);return`${n.getUTCDate()} ${[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`][n.getUTCMonth()]} ${n.getUTCFullYear()}`}function j(e){return e.assigneeName?e.assigneeName:e.assigneeUserId?e.assigneeUserId.slice(0,8):`Unassigned`}function M(e,t){return[t,A(e.createdAt),j(e)].filter(Boolean).join(` · `)}function ae(e,t){if(e.running&&e.runningStartedAt){let n=Date.parse(e.runningStartedAt);if(Number.isFinite(n))return e.secondsLogged+Math.max(0,(t-n)/1e3)}return e.secondsLogged}function oe(e){let t=[`Task: ${e.title}\nTask id: ${e.taskId}`],n=e.description.trim();n.length>0&&t.push(n);let r=e.notes.trim();return r.length>0&&t.push(`Notes:\n${r}`),t.join(`
1
+ import{o as e}from"./chunk-CltuBf4Z.js";import{L as t,M as n,N as r,O as i,a,at as o,ct as s,j as c,k as l,nt as u,ot as d,q as f}from"./useMediaQuery-_mMln3Fu.js";import{a as p,f as m,k as h,n as g,t as _,v as ee}from"./AdminShell-DVBAMUCy.js";import{t as te}from"./play-Ep0SZTbr.js";import{t as v}from"./rotate-ccw-DfJWjXAg.js";var y=d(),b=e(s(),1);function ne(e=3e4){let[t,n]=(0,b.useState)(()=>Date.now());return(0,b.useEffect)(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}function re(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)),x(e,i),i}function x(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 S=`__unassigned__`;function C(e,t){return e===`__unassigned__`?`Unassigned`:t||e.slice(0,8)}function w(e){return e===null||e===``?S:e}function ie(e,t){let n=new Map,r=(e,t)=>{let r=w(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:C(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 T(e,t){return t===null?!0:w(e.assigneeUserId)===t}var E=u();function D(e){let t=e.name??e.userId.slice(0,8);return e.kind===`owner`?`${t} (owner)`:t}var O=`maxy-admin-session-key`;function k(e){let t=[];return e.clientName&&t.push(e.clientName),e.propertyAddress&&t.push(e.propertyAddress),e.fee!=null&&t.push(`£${e.fee}`),t.join(` · `)}function A(e){if(!e)return``;let t=Date.parse(e);if(!Number.isFinite(t))return``;let n=new Date(t);return`${n.getUTCDate()} ${[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`][n.getUTCMonth()]} ${n.getUTCFullYear()}`}function j(e){return e.assigneeName?e.assigneeName:e.assigneeUserId?e.assigneeUserId.slice(0,8):`Unassigned`}function M(e,t){return[t,A(e.createdAt),j(e)].filter(Boolean).join(` · `)}function ae(e,t){if(e.running&&e.runningStartedAt){let n=Date.parse(e.runningStartedAt);if(Number.isFinite(n))return e.secondsLogged+Math.max(0,(t-n)/1e3)}return e.secondsLogged}function oe(e){let t=[`Task: ${e.title}\nTask id: ${e.taskId}`],n=e.description.trim();n.length>0&&t.push(n);let r=e.notes.trim();return r.length>0&&t.push(`Notes:\n${r}`),t.join(`
2
2
 
3
3
  `).slice(0,2e3)}function se({clients:e,onSelect:t}){return(0,E.jsxs)(`section`,{className:`admin-card tasks-card`,children:[(0,E.jsxs)(`div`,{className:`tasks-card-head`,children:[(0,E.jsx)(`span`,{className:`tasks-card-title`,children:`Clients`}),(0,E.jsxs)(`span`,{className:`tasks-card-count`,children:[e.length,` total`]})]}),e.length===0&&(0,E.jsx)(`div`,{className:`tasks-empty`,children:`No clients yet.`}),e.map(e=>(0,E.jsx)(`button`,{className:`tasks-row tasks-client-row`,onClick:()=>t(e.name),children:(0,E.jsxs)(`div`,{className:`tasks-row-main`,children:[(0,E.jsx)(`div`,{className:`tasks-row-name`,children:e.name}),(0,E.jsxs)(`div`,{className:`tasks-row-sub`,children:[e.openCount,` open · `,a(e.totalSeconds),` logged`]})]})},e.name))]})}function ce({task:e,roster:t,busy:n,onAssign:r,onClose:i}){return(0,b.useEffect)(()=>{let e=e=>{e.key===`Escape`&&i()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i]),(0,E.jsx)(`div`,{className:`tasks-detail-backdrop`,onClick:i,children:(0,E.jsxs)(`div`,{className:`tasks-detail`,role:`dialog`,"aria-modal":`true`,"aria-label":`Task detail`,onClick:e=>e.stopPropagation(),children:[(0,E.jsxs)(`div`,{className:`tasks-detail-head`,children:[(0,E.jsx)(`h2`,{className:`tasks-detail-title`,children:e?e.name:`Task no longer available`}),(0,E.jsx)(`button`,{className:`tasks-detail-close`,"aria-label":`Close`,onClick:i,children:(0,E.jsx)(c,{size:16})})]}),e===null?(0,E.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,E.jsxs)(`dl`,{className:`tasks-detail-fields`,children:[(0,E.jsx)(`dt`,{children:`Status`}),(0,E.jsx)(`dd`,{children:e.status}),(0,E.jsx)(`dt`,{children:`Logged`}),(0,E.jsx)(`dd`,{children:a(e.secondsLogged)}),(0,E.jsx)(`dt`,{children:`Created`}),(0,E.jsx)(`dd`,{children:A(e.createdAt)||`Not recorded`}),(0,E.jsx)(`dt`,{children:`Assignee`}),(0,E.jsx)(`dd`,{children:e.taskId===null?j(e):(0,E.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,E.jsx)(`option`,{value:``,children:`Unassigned`}),e.assigneeUserId&&!t.some(t=>t.userId===e.assigneeUserId)&&(0,E.jsxs)(`option`,{value:e.assigneeUserId,children:[j(e),` (not in roster)`]}),t.map(e=>(0,E.jsx)(`option`,{value:e.userId,children:D(e)},e.userId))]})}),e.clientName&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`dt`,{children:`Client`}),(0,E.jsx)(`dd`,{children:e.clientName})]}),e.propertyAddress&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`dt`,{children:`Property`}),(0,E.jsx)(`dd`,{children:e.propertyAddress})]}),e.fee!=null&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`dt`,{children:`Fee`}),(0,E.jsxs)(`dd`,{children:[`£`,e.fee]})]})]})]})})}function N({adminFetch:e}){let[o,s]=(0,b.useState)({open:[],completed:[]}),[l,u]=(0,b.useState)(!1),[d,h]=(0,b.useState)(!1),_=(0,b.useRef)(!1),y=(0,b.useRef)(``),x=ne(1e3),[S,C]=(0,b.useState)(`open`),[w,D]=(0,b.useState)(null),[O,A]=(0,b.useState)(null),[j,N]=(0,b.useState)(null),[P,F]=(0,b.useState)(``),[I,L]=(0,b.useState)(null),[le,R]=(0,b.useState)(null),[z,B]=(0,b.useState)(null),V=(0,b.useRef)(new Map),H=(0,b.useRef)(new Set),[ue,U]=(0,b.useState)(new Set),W=(0,b.useMemo)(()=>{if(I!==null)return[...o.open,...o.completed].find(e=>e.rowKey===I)??null},[o,I]),G=(0,b.useMemo)(()=>z===null?null:[...o.open,...o.completed].find(e=>e.rowKey===z)??null,[o,z]);(0,b.useEffect)(()=>{I!==null&&W===null&&console.error(`[tasks-ui] op=detail-failed rowKey=${I} reason=not-in-list`)},[I,W]);let K=(0,b.useMemo)(()=>re(o.open,o.completed),[o]),q=(0,b.useMemo)(()=>w===null?{open:o.open,completed:o.completed}:{open:o.open.filter(e=>e.clientName===w),completed:o.completed.filter(e=>e.clientName===w)},[o,w]),J=(0,b.useMemo)(()=>ie(q.open,q.completed),[q]),de=(0,b.useCallback)(e=>{D(e),C(`open`)},[]);(0,b.useEffect)(()=>{w&&!K.some(e=>e.name===w)&&D(null)},[K,w]),(0,b.useEffect)(()=>{O&&!J.some(e=>e.userId===O)&&A(null)},[J,O]),(0,b.useEffect)(()=>{R(null),B(null)},[S,w,O]);let Y=o.open.filter(e=>e.running||(w===null||e.clientName===w)&&T(e,O)),X=(w?o.completed.filter(e=>e.clientName===w):o.completed).filter(e=>T(e,O)),[fe,pe]=(0,b.useState)([]),Z=(0,b.useCallback)(async()=>{let t=await e(`/api/admin/tasks-list`);t.ok&&s(await t.json()),u(!0)},[e]);(0,b.useEffect)(()=>{Z()},[Z]),(0,b.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,b.useCallback)(async(t,n,r)=>{if(_.current)return!1;_.current=!0,h(!0);try{return await e(t,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({taskId:n,...r})}),await Z(),!0}finally{_.current=!1,h(!1)}},[e,Z]),me=(0,b.useCallback)(async e=>{await Q(`/api/admin/task-complete`,e)},[Q]),he=(0,b.useCallback)(async e=>{await Q(`/api/admin/task-delete`,e,{confirmed:!0})},[Q]),ge=(0,b.useCallback)((e,t)=>{let n=String(Math.round(e.secondsLogged/60));y.current=n,N(t),F(n)},[]),$=(0,b.useCallback)(()=>{N(null),F(``)},[]),_e=(0,b.useCallback)(async e=>{let t=P.trim(),n=Number(t);if(!(t===``||!Number.isInteger(n)||n<0)){if(t===y.current){$();return}N(null),F(``),await Q(`/api/admin/task-time-adjust`,e,{newSeconds:n*60})}},[P,Q,$]),ve=(0,b.useCallback)(e=>{Q(`/api/admin/task-time-adjust`,e,{newSeconds:0})},[Q]),ye=(0,b.useCallback)((e,t)=>{Q(`/api/admin/task-assign`,e,{assigneeUserId:t})},[Q]),be=(0,b.useCallback)(async t=>{if(!H.current.has(t)){H.current.add(t),U(new Set(H.current));try{let n=await e(`/api/admin/task-session-open`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({taskId:t})});if(!n.ok){console.error(`[admin-ui] task-session op=open-failed taskId=${t} status=${n.status}`);return}let{sessionId:r,title:i,description:a,notes:o}=await n.json();if(r!==null){let e=`/chat?session=${r}`;window.location.assign(e);return}let s=oe({title:i,taskId:t,description:a??``,notes:o??``}),c=await e(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({title:i,initialMessage:s})}),l=await c.json().catch(()=>({})),u=g(c.ok,c.status,l),d=l.sessionId??null;if(u.kind!==`navigate`){console.error(`[admin-ui] task-session op=spawn-failed taskId=${t} reason=${u.reason}`);return}if(d!==null){let n=await e(`/api/admin/task-session-link`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({taskId:t,sessionId:d})});n.ok&&(await n.json().catch(()=>({}))).linked}else console.error(`[admin-ui] task-session op=link-skipped taskId=${t} reason=no-landed-session-id`);window.location.assign(u.url)}catch(e){console.error(`[admin-ui] task-session op=failed taskId=${t} error=${e instanceof Error?e.message:String(e)}`)}finally{H.current.delete(t),U(new Set(H.current))}}},[e]);if(!l)return(0,E.jsx)(i,{surface:`gate`});let xe=e=>e.taskId!==null&&j===e.taskId,Se=e=>(0,E.jsxs)(`div`,{className:`tasks-edit`,children:[(0,E.jsx)(`input`,{className:`tasks-edit-input`,type:`number`,min:0,step:1,"aria-label":`Logged minutes`,value:P,onChange:e=>F(e.target.value)}),(0,E.jsx)(`span`,{className:`tasks-edit-unit`,children:`min`}),(0,E.jsxs)(`button`,{className:`admin-btn-cta tasks-btn-action`,disabled:d,onClick:()=>void _e(e),children:[(0,E.jsx)(f,{size:14}),` Save`]}),(0,E.jsxs)(`button`,{className:`tasks-btn-secondary tasks-btn-action`,onClick:$,children:[(0,E.jsx)(c,{size:14}),` Cancel`]})]}),Ce=(e,r)=>[{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,E.jsx)(t,{size:12}),disabled:d||e.running,onClick:()=>ge(e,r)},{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,E.jsx)(v,{size:12}),disabled:d||e.running,onClick:()=>ve(r)},{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,E.jsx)(ee,{size:12}),disabled:ue.has(r),onClick:()=>{be(r)}},{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,E.jsx)(n,{size:12}),danger:!0,disabled:d||e.running,onClick:()=>B(e.rowKey)}];return(0,E.jsxs)(`div`,{className:`ui-page ui-page--full tasks-body`,children:[I!==null&&(0,E.jsx)(ce,{task:W??null,roster:fe,busy:d,onAssign:ye,onClose:()=>L(null)}),(0,E.jsx)(p,{target:G?{name:G.name,secondsLogged:G.secondsLogged}:null,anchorEl:z?V.current.get(z)??null:null,onCancel:()=>B(null),onConfirm:()=>{let e=G;B(null),e?.taskId&&he(e.taskId)}},z??`none`),(0,E.jsxs)(`div`,{className:`tasks-tabs`,children:[(0,E.jsxs)(`button`,{className:`admin-chip ${S===`open`?`is-active`:``}`,onClick:()=>C(`open`),children:[`Open `,(0,E.jsx)(`span`,{className:`tasks-tab-badge`,children:o.open.length})]}),(0,E.jsxs)(`button`,{className:`admin-chip ${S===`completed`?`is-active`:``}`,onClick:()=>C(`completed`),children:[`Completed `,(0,E.jsx)(`span`,{className:`tasks-tab-badge`,children:o.completed.length})]}),(0,E.jsxs)(`button`,{className:`admin-chip ${S===`clients`?`is-active`:``}`,onClick:()=>C(`clients`),children:[`Clients `,(0,E.jsx)(`span`,{className:`tasks-tab-badge`,children:K.length})]})]}),S===`clients`?(0,E.jsx)(se,{clients:K,onSelect:de}):(0,E.jsxs)(E.Fragment,{children:[w&&(0,E.jsxs)(`div`,{className:`tasks-filter-banner`,children:[(0,E.jsxs)(`span`,{children:[`Showing `,w]}),(0,E.jsx)(`button`,{className:`tasks-filter-clear`,onClick:()=>D(null),children:`Clear`})]}),J.length>0&&(0,E.jsxs)(`div`,{className:`tasks-assignee-bar`,children:[(0,E.jsxs)(`button`,{className:`admin-chip ${O===null?`is-active`:``}`,"aria-pressed":O===null,onClick:()=>A(null),children:[`All `,(0,E.jsx)(`span`,{className:`tasks-assignee-count`,children:q.open.length})]}),J.map(e=>(0,E.jsxs)(`button`,{className:`admin-chip ${O===e.userId?`is-active`:``}`,"aria-pressed":O===e.userId,"aria-label":`Assignee ${e.label}`,title:e.userId===`__unassigned__`?`Tasks with no assigned admin`:`AdminUser ${e.userId}`,onClick:()=>A(O===e.userId?null:e.userId),children:[e.label,` `,(0,E.jsx)(`span`,{className:`tasks-assignee-count`,children:e.openCount})]},e.userId))]}),S===`open`?(0,E.jsxs)(`section`,{className:`admin-card tasks-card`,children:[(0,E.jsxs)(`div`,{className:`tasks-card-head`,children:[(0,E.jsx)(`span`,{className:`tasks-card-title`,children:`Open tasks`}),(0,E.jsxs)(`span`,{className:`tasks-card-count`,children:[Y.length,` to do`]})]}),Y.length===0&&(0,E.jsx)(`div`,{className:`tasks-empty`,children:`No open tasks.`}),Y.map(e=>(0,E.jsxs)(`div`,{className:`tasks-row`,ref:t=>{t?V.current.set(e.rowKey,t):V.current.delete(e.rowKey)},children:[(0,E.jsx)(`button`,{className:`tasks-row-open`,"aria-label":`Open task detail: ${e.name}`,onClick:()=>L(e.rowKey),children:(0,E.jsxs)(`div`,{className:`tasks-row-main`,children:[(0,E.jsx)(`div`,{className:`tasks-row-name`,children:e.name}),(0,E.jsx)(`div`,{className:`tasks-row-sub`,children:M(e,k(e))})]})}),(0,E.jsx)(`div`,{className:`tasks-row-elapsed ${e.running?`tasks-row-elapsed-running`:``}`,children:a(ae(e,x))}),(0,E.jsx)(`div`,{className:`tasks-row-controls`,children:e.taskId!==null&&le===e.taskId?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`span`,{className:`tasks-confirm-label`,children:`Complete?`}),(0,E.jsxs)(`button`,{className:`admin-btn-cta tasks-btn-action`,disabled:d,onClick:()=>{R(null),me(e.taskId)},children:[(0,E.jsx)(f,{size:14}),` Confirm complete`]}),(0,E.jsxs)(`button`,{className:`tasks-btn-secondary tasks-btn-action`,onClick:()=>R(null),children:[(0,E.jsx)(c,{size:14}),` Keep open`]})]}):e.taskId===null?(0,E.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,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(m,{actions:Ce(e,e.taskId),disabled:!1,label:`Task actions`}),(0,E.jsx)(`button`,{className:`tasks-btn-secondary tasks-btn-action tasks-btn-icon`,"aria-label":`Complete task: ${e.name}`,disabled:d||e.running,title:e.running?`Stop the timer before completing`:`Complete task`,onClick:()=>R(e.taskId),children:(0,E.jsx)(f,{size:14})}),e.running?(0,E.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,E.jsx)(r,{size:14}),` Stop`]}):(0,E.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,E.jsx)(te,{size:14}),` Start`]})]})})]},e.rowKey))]}):(0,E.jsxs)(`section`,{className:`admin-card tasks-card`,children:[(0,E.jsxs)(`div`,{className:`tasks-card-head`,children:[(0,E.jsx)(`span`,{className:`tasks-card-title`,children:`Completed`}),(0,E.jsxs)(`span`,{className:`tasks-card-count`,children:[X.length,` done`]})]}),X.length===0&&(0,E.jsx)(`div`,{className:`tasks-empty`,children:`Nothing completed yet.`}),X.map(e=>(0,E.jsxs)(`div`,{className:`tasks-row tasks-row-done`,ref:t=>{t?V.current.set(e.rowKey,t):V.current.delete(e.rowKey)},children:[(0,E.jsx)(`button`,{className:`tasks-row-open`,"aria-label":`Open task detail: ${e.name}`,onClick:()=>L(e.rowKey),children:(0,E.jsxs)(`div`,{className:`tasks-row-main`,children:[(0,E.jsx)(`div`,{className:`tasks-row-name`,children:e.name}),(0,E.jsx)(`div`,{className:`tasks-row-sub`,children:M(e,k(e))})]})}),(0,E.jsx)(`div`,{className:`tasks-row-elapsed`,children:a(e.secondsLogged)}),(0,E.jsx)(`div`,{className:`tasks-row-controls`,children:e.taskId===null?(0,E.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,E.jsx)(m,{actions:Ce(e,e.taskId),disabled:!1,label:`Task actions`})})]},e.rowKey))]})]})]})}function P({cacheKey:e}){let{adminFetch:t}=o({initialCacheKey:e,surface:`tasks`});return(0,E.jsx)(N,{adminFetch:t})}function F(){let[e,t]=(0,b.useState)(null),[n,r]=(0,b.useState)(!1),[a,o]=(0,b.useState)(void 0),[s,c]=(0,b.useState)(null),[u,d]=(0,b.useState)(null),[f,p]=(0,b.useState)(null),[m,g]=(0,b.useState)(null);(0,b.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(O)}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(O)}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),d(e.role??null),p(e.userName===void 0?null:e.userName),g(e.avatar??null)}catch{}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]);let ee=(0,b.useCallback)(()=>{try{sessionStorage.removeItem(O)}catch{}window.location.href=`/`},[]),[te,v]=(0,b.useState)(!1),y=(0,b.useCallback)(async()=>{v(!0);try{let e=await h();if(e){try{sessionStorage.removeItem(O)}catch{}window.location.href=`/`}return e}finally{v(!1)}},[]);return n?e?(0,E.jsx)(l,{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(O)}catch{}window.location.href=`/`},children:(0,E.jsx)(_,{cacheKey:e,businessName:a,sessionId:s,onLogout:ee,onDisconnect:y,disconnecting:te,userName:f,userAvatar:m,role:u,children:(0,E.jsx)(P,{cacheKey:e})})}):(0,E.jsx)(`div`,{className:`tasks-page`,children:(0,E.jsxs)(`div`,{className:`tasks-empty`,children:[(0,E.jsx)(`p`,{children:`You are not signed in.`}),(0,E.jsxs)(`p`,{children:[`Open the `,(0,E.jsx)(`a`,{href:`/`,className:`tasks-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,E.jsx)(i,{surface:`gate`})}(0,y.createRoot)(document.getElementById(`root`)).render((0,E.jsx)(F,{}));
@@ -1 +1 @@
1
- import{Z as e}from"./useMediaQuery-BYIHo-xL.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-_mMln3Fu.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-CltuBf4Z.js";import{ct as t,i as n}from"./useMediaQuery-BYIHo-xL.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-CltuBf4Z.js";import{ct as t,i as n}from"./useMediaQuery-_mMln3Fu.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};