@rubytech/create-maxy-code 0.1.504 → 0.1.505

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 (87) hide show
  1. package/package.json +1 -1
  2. package/payload/platform/lib/models/dist/index.d.ts +5 -5
  3. package/payload/platform/lib/models/dist/index.d.ts.map +1 -1
  4. package/payload/platform/lib/models/dist/index.js +7 -7
  5. package/payload/platform/lib/models/dist/index.js.map +1 -1
  6. package/payload/platform/lib/models/src/index.ts +7 -7
  7. package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +39 -26
  8. package/payload/platform/plugins/admin/skills/public-agent-manager/SKILL.md +2 -2
  9. package/payload/platform/plugins/admin/skills/whats-new/SKILL.md +6 -0
  10. package/payload/platform/plugins/docs/references/admin-session.md +1 -1
  11. package/payload/platform/plugins/docs/references/admin-ui.md +38 -25
  12. package/payload/platform/plugins/work/mcp/dist/__tests__/session-metering.test.js +2 -2
  13. package/payload/platform/plugins/work/mcp/dist/__tests__/session-metering.test.js.map +1 -1
  14. package/payload/platform/plugins/work/mcp/dist/index.js +1 -1
  15. package/payload/platform/plugins/work/mcp/dist/index.js.map +1 -1
  16. package/payload/platform/plugins/work/mcp/dist/tools/session-metering.js +2 -2
  17. package/payload/platform/plugins/work/mcp/dist/tools/session-metering.js.map +1 -1
  18. package/payload/platform/scripts/logs-read-jsonl.test.sh +1 -1
  19. package/payload/platform/services/claude-session-manager/dist/http-server.js +2 -2
  20. package/payload/platform/services/claude-session-manager/dist/http-server.js.map +1 -1
  21. package/payload/platform/services/claude-session-manager/dist/pricing.d.ts +19 -11
  22. package/payload/platform/services/claude-session-manager/dist/pricing.d.ts.map +1 -1
  23. package/payload/platform/services/claude-session-manager/dist/pricing.js +18 -15
  24. package/payload/platform/services/claude-session-manager/dist/pricing.js.map +1 -1
  25. package/payload/platform/services/claude-session-manager/dist/rc-daemon.js +1 -1
  26. package/payload/platform/services/claude-session-manager/dist/rc-daemon.js.map +1 -1
  27. package/payload/platform/services/claude-session-manager/dist/session-metering.js +3 -3
  28. package/payload/platform/services/claude-session-manager/dist/session-metering.js.map +1 -1
  29. package/payload/platform/templates/account.json +1 -1
  30. package/payload/platform/templates/specialists/agents/coding-assistant.md +1 -1
  31. package/payload/platform/templates/specialists/agents/content-producer.md +1 -1
  32. package/payload/platform/templates/specialists/agents/librarian.md +1 -1
  33. package/payload/platform/templates/specialists/agents/research-assistant.md +1 -1
  34. package/payload/server/public/activity.html +5 -5
  35. package/payload/server/public/agents.html +4 -4
  36. package/payload/server/public/assets/{AdminLoginScreens-DWMR4KtI.js → AdminLoginScreens-DeWt3H7l.js} +1 -1
  37. package/payload/server/public/assets/AdminShell-u32d8puE.js +2 -0
  38. package/payload/server/public/assets/{activity-DH3z4cv3.js → activity-DjP45-DD.js} +1 -1
  39. package/payload/server/public/assets/{admin-aaGhd2Yh.js → admin-Bo-Y6Vjx.js} +1 -1
  40. package/payload/server/public/assets/agents-C80aCXd8.js +1 -0
  41. package/payload/server/public/assets/{browser-C_MJYN5k.js → browser-ULvl_K5x.js} +1 -1
  42. package/payload/server/public/assets/{calendar-DA0h7dqW.js → calendar-CGMrT6WZ.js} +1 -1
  43. package/payload/server/public/assets/chat-DnWXaWD4.js +1 -0
  44. package/payload/server/public/assets/chevron-left-BB5Iljw-.js +1 -0
  45. package/payload/server/public/assets/chevron-right-DijU96_j.js +1 -0
  46. package/payload/server/public/assets/clock-DsmnhhJh.js +1 -0
  47. package/payload/server/public/assets/data-JPlhOLGC.js +1 -0
  48. package/payload/server/public/assets/{file-text-RCoSeOpD.js → file-text-C5K6DMcK.js} +1 -1
  49. package/payload/server/public/assets/graph-CO6e1bgD.js +51 -0
  50. package/payload/server/public/assets/{graph-labels-DJV0aIG5.js → graph-labels-iliQjlfE.js} +1 -1
  51. package/payload/server/public/assets/{maximize-2-DcESsKbu.js → maximize-2-D-64XK6V.js} +1 -1
  52. package/payload/server/public/assets/{operator-Dlkw1sXJ.js → operator-DyXgogJ1.js} +1 -1
  53. package/payload/server/public/assets/{page-Dl-mgQUu.js → page-DrbiAFS-.js} +1 -1
  54. package/payload/server/public/assets/page-WeM2ry61.js +1 -0
  55. package/payload/server/public/assets/{public-C-UHWk_S.js → public-B9NVDBxW.js} +1 -1
  56. package/payload/server/public/assets/{rotate-ccw-C1nRSAzP.js → rotate-ccw-P35h7ogS.js} +1 -1
  57. package/payload/server/public/assets/{routines-qdAZ0sA4.js → routines-BeiynLF7.js} +1 -1
  58. package/payload/server/public/assets/{skills-B78wr822.js → skills-C5H7ohLp.js} +1 -1
  59. package/payload/server/public/assets/{tasks-DbIsS-vW.js → tasks-CI74_b6H.js} +1 -1
  60. package/payload/server/public/assets/{time-entry-format-BhlltPP8.js → time-entry-format-CDhHCMrW.js} +1 -1
  61. package/payload/server/public/assets/{triangle-alert-rEVGyIhi.js → triangle-alert-OgY71rDV.js} +1 -1
  62. package/payload/server/public/assets/{useCopyFeedback-DzpXjm9d.js → useCopyFeedback-jOGmWwa3.js} +1 -1
  63. package/payload/server/public/assets/{useSubAccountSwitcher-wP8cOzPj.css → useSubAccountSwitcher-AFSwtthL.css} +1 -1
  64. package/payload/server/public/assets/{useVoiceRecorder-CRRmPjYr.js → useVoiceRecorder-CnE3fhfV.js} +1 -1
  65. package/payload/server/public/assets/{wrench-oeLti270.js → wrench-B1hsCj0R.js} +1 -1
  66. package/payload/server/public/browser.html +4 -4
  67. package/payload/server/public/calendar.html +7 -7
  68. package/payload/server/public/chat.html +13 -13
  69. package/payload/server/public/data.html +11 -11
  70. package/payload/server/public/graph.html +9 -9
  71. package/payload/server/public/index.html +14 -14
  72. package/payload/server/public/operator.html +14 -14
  73. package/payload/server/public/public.html +13 -13
  74. package/payload/server/public/routines.html +6 -6
  75. package/payload/server/public/skills.html +5 -5
  76. package/payload/server/public/tasks.html +6 -6
  77. package/payload/server/server.js +111 -31
  78. package/payload/server/public/assets/AdminShell-C8hBpL9K.js +0 -2
  79. package/payload/server/public/assets/agents-SPu-clsf.js +0 -1
  80. package/payload/server/public/assets/chat-Bg7dlM0I.js +0 -1
  81. package/payload/server/public/assets/chevron-left-BoDA12H8.js +0 -1
  82. package/payload/server/public/assets/chevron-right-DXjrO6qA.js +0 -1
  83. package/payload/server/public/assets/clock-BceBgZP1.js +0 -1
  84. package/payload/server/public/assets/data-rNLaurgY.js +0 -1
  85. package/payload/server/public/assets/graph-Dm-YZeNP.js +0 -51
  86. package/payload/server/public/assets/page-DoyJrk8E.js +0 -1
  87. /package/payload/server/public/assets/{useSubAccountSwitcher-DVmWZxar.js → useSubAccountSwitcher-6AFuRawP.js} +0 -0
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{B as t,G as n,U as r}from"./useSubAccountSwitcher-DVmWZxar.js";import"./useVoiceRecorder-CRRmPjYr.js";import{C as i}from"./AdminShell-C8hBpL9K.js";import{a,c as o,i as s,o as c,r as l,s as u}from"./page-Dl-mgQUu.js";import"./useCopyFeedback-DzpXjm9d.js";var d=r(),f=e(n(),1),p=t();function m({gateState:e,setGateState:t,grantInfo:n,resolvedSlugRef:r}){let[a,o]=(0,f.useState)(``),[s,c]=(0,f.useState)(!1),[l,u]=(0,f.useState)(null);async function d(e){e.preventDefault();let n=a.trim().toLowerCase();if(!n){u(`Enter the email you were invited on.`);return}c(!0),u(null);try{let e=await fetch(`/api/access/request-magic-link`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({contactValue:n,agentSlug:r.current})});if(e.status===429){u((await e.json().catch(()=>({})))?.error||`Too many requests. Try again later.`);return}t(`request-sent`)}catch{u(`Could not reach the server. Check your connection and try again.`)}finally{c(!1)}}return(0,p.jsxs)(`div`,{className:`access-gate`,children:[e===`verifying`&&(0,p.jsxs)(`div`,{className:`access-gate-message`,children:[(0,p.jsx)(`h2`,{children:`Verifying your link…`}),(0,p.jsx)(`p`,{children:`This takes a moment.`})]}),e===`verify-failed`&&(0,p.jsxs)(`div`,{className:`access-gate-message`,children:[(0,p.jsx)(`h2`,{children:`That link did not work`}),(0,p.jsx)(`p`,{children:`It may have expired, already been used, or been for a different agent. You can request a fresh one below.`}),(0,p.jsx)(i,{onClick:()=>{t(`request-link`),u(null)},children:`Request a new link`})]}),e===`request-link`&&(0,p.jsxs)(`form`,{className:`access-gate-form`,onSubmit:d,children:[(0,p.jsx)(`h2`,{children:n?.displayName?`Welcome back, ${n.displayName}`:`Sign in`}),(0,p.jsx)(`p`,{children:`Enter the email you were invited on and we will send you a fresh link.`}),(0,p.jsx)(`label`,{htmlFor:`access-email`,children:`Email`}),(0,p.jsx)(`input`,{id:`access-email`,type:`email`,inputMode:`email`,autoComplete:`email`,value:a,onChange:e=>o(e.target.value),disabled:s}),l&&(0,p.jsx)(`p`,{className:`access-gate-error`,children:l}),(0,p.jsx)(i,{type:`submit`,disabled:s||!a.trim(),children:s?`Sending…`:`Send me a link`})]}),e===`request-sent`&&(0,p.jsxs)(`div`,{className:`access-gate-message`,children:[(0,p.jsx)(`h2`,{children:`Check your email`}),(0,p.jsx)(`p`,{children:`If that address is on the invite list, a fresh link is on the way. It expires in 15 minutes.`}),(0,p.jsx)(i,{onClick:()=>{t(`request-link`),o(``),u(null)},children:`Try a different email`})]})]})}function h(){let[e,t]=(0,f.useState)(null),[n,r]=(0,f.useState)(null),[i,l]=(0,f.useState)(`loading`),[d,p]=(0,f.useState)(``),[m,h]=(0,f.useState)(null),[g,_]=(0,f.useState)(null),[v,y]=(0,f.useState)(!1),[b,x]=(0,f.useState)(null),S=(0,f.useMemo)(()=>a(),[]),C=(0,f.useRef)(S||``),w=(0,f.useRef)(null),T=(0,f.useRef)(null),E=(0,f.useRef)(!1),D=(0,f.useRef)(null),[O,k]=(0,f.useState)(`request-link`),[A,j]=(0,f.useState)(null),M=(0,f.useRef)(null),N=(0,f.useRef)(null);(0,f.useEffect)(()=>{try{let e=sessionStorage.getItem(`maxy_session`);e&&(N.current=e)}catch{}},[]),(0,f.useEffect)(()=>{try{let e=c();e&&(sessionStorage.setItem(s,e),o&&console.info(`[public-webchat] op=seed-persisted len=${e.length} head=${e.slice(0,40)}`))}catch{}},[]);let P=(0,f.useCallback)(e=>{w.current=e,t(e);try{sessionStorage.setItem(`maxy_session`,e)}catch{}l(`chat`)},[]),F=(0,f.useCallback)(()=>{w.current=null;try{sessionStorage.removeItem(`maxy_session`)}catch{}t(null),l(`auth-required`),k(`request-link`)},[]),I=(0,f.useCallback)(async e=>{k(`verifying`);try{let t=C.current,n=await fetch(`/api/access/verify-token`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({token:e,agentSlug:t})});if(window.history.replaceState({},``,window.location.pathname),n.ok){let e=await n.json().catch(()=>({}));return e?.displayName&&j({displayName:e.displayName,contactValue:``,expiresAt:null,status:`active`}),!0}return k(`verify-failed`),!1}catch{return k(`verify-failed`),!1}},[]),L=(0,f.useCallback)(async()=>{if(w.current)return w.current;if(T.current)return T.current;let e=(async()=>{try{let e=N.current,n=await fetch(`/api/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({session_id:u(),...S?{agent:S}:{},...e?{session_key:e}:{}})});if(!n.ok){let e=await n.json().catch(()=>({error:``}));return o&&console.error(`[session] POST /api/session failed: ${n.status} ${n.statusText}`,e),n.status===404?r(e.error||`Agent not found`):n.status===503&&r(e.error||`Service unavailable`),null}let i=await n.json();if(i.auth_required){i.agent_id&&(C.current=i.agent_id),p(i.displayName||``),i.agentImage&&h(i.agentImage),i.agentImageShape&&_(i.agentImageShape),i.showAgentName&&y(i.showAgentName),i.branding&&x(i.branding),l(`auth-required`);let e=new URLSearchParams(window.location.search).get(`token`);return e?await I(e)&&window.location.reload():k(`request-link`),null}w.current=i.session_key,t(i.session_key),i.displayName&&p(i.displayName),i.agentImage&&h(i.agentImage),i.agentImageShape&&_(i.agentImageShape),i.showAgentName&&y(i.showAgentName),i.branding&&x(i.branding),l(`chat`),i.resumed&&i.messages&&(E.current=!0,D.current=i.messages);try{sessionStorage.setItem(`maxy_session`,i.session_key)}catch{}return i.session_key}catch(e){return o&&console.error(`[session] fetch /api/session threw:`,e),r(`Unable to connect. Please check your connection and try again.`),null}finally{T.current=null}})();return T.current=e,e},[S,I]);return{sessionId:e,cacheKeyRef:w,sessionError:n,pageState:i,setPageState:l,agentDisplayName:d,agentImage:m,agentImageShape:g,showAgentName:v,agentSlug:S,branding:b,resolvedSlugRef:C,ensureSession:L,startNewSession:(0,f.useCallback)(async()=>{w.current=null,T.current=null,N.current=null,E.current=!1,D.current=null,t(null),r(null);try{sessionStorage.removeItem(`maxy_session`)}catch{}await L()},[L]),enterChat:P,enterGate:F,resumedRef:E,resumeMessagesRef:D,gateState:O,setGateState:k,grantInfo:A,setGrantInfo:j,gateCacheKeyRef:M}}function g(){let{ensureSession:e,pageState:t,gateState:n,setGateState:r,grantInfo:i,resolvedSlugRef:a}=h();return(0,f.useEffect)(()=>{e()},[e]),t===`loading`?(0,p.jsx)(`div`,{className:`public-loading`,children:`Loading…`}):t===`auth-required`?(0,p.jsx)(m,{gateState:n,setGateState:r,grantInfo:i,resolvedSlugRef:a}):(0,p.jsx)(`div`,{className:`public-shell`,children:(0,p.jsx)(l,{cacheKey:``,variant:`public`})})}(0,d.createRoot)(document.getElementById(`root`)).render((0,p.jsx)(g,{}));
1
+ import{o as e}from"./chunk-CltuBf4Z.js";import{B as t,G as n,U as r}from"./useSubAccountSwitcher-6AFuRawP.js";import"./useVoiceRecorder-CnE3fhfV.js";import{C as i}from"./AdminShell-u32d8puE.js";import{a,c as o,i as s,o as c,r as l,s as u}from"./page-DrbiAFS-.js";import"./useCopyFeedback-jOGmWwa3.js";var d=r(),f=e(n(),1),p=t();function m({gateState:e,setGateState:t,grantInfo:n,resolvedSlugRef:r}){let[a,o]=(0,f.useState)(``),[s,c]=(0,f.useState)(!1),[l,u]=(0,f.useState)(null);async function d(e){e.preventDefault();let n=a.trim().toLowerCase();if(!n){u(`Enter the email you were invited on.`);return}c(!0),u(null);try{let e=await fetch(`/api/access/request-magic-link`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({contactValue:n,agentSlug:r.current})});if(e.status===429){u((await e.json().catch(()=>({})))?.error||`Too many requests. Try again later.`);return}t(`request-sent`)}catch{u(`Could not reach the server. Check your connection and try again.`)}finally{c(!1)}}return(0,p.jsxs)(`div`,{className:`access-gate`,children:[e===`verifying`&&(0,p.jsxs)(`div`,{className:`access-gate-message`,children:[(0,p.jsx)(`h2`,{children:`Verifying your link…`}),(0,p.jsx)(`p`,{children:`This takes a moment.`})]}),e===`verify-failed`&&(0,p.jsxs)(`div`,{className:`access-gate-message`,children:[(0,p.jsx)(`h2`,{children:`That link did not work`}),(0,p.jsx)(`p`,{children:`It may have expired, already been used, or been for a different agent. You can request a fresh one below.`}),(0,p.jsx)(i,{onClick:()=>{t(`request-link`),u(null)},children:`Request a new link`})]}),e===`request-link`&&(0,p.jsxs)(`form`,{className:`access-gate-form`,onSubmit:d,children:[(0,p.jsx)(`h2`,{children:n?.displayName?`Welcome back, ${n.displayName}`:`Sign in`}),(0,p.jsx)(`p`,{children:`Enter the email you were invited on and we will send you a fresh link.`}),(0,p.jsx)(`label`,{htmlFor:`access-email`,children:`Email`}),(0,p.jsx)(`input`,{id:`access-email`,type:`email`,inputMode:`email`,autoComplete:`email`,value:a,onChange:e=>o(e.target.value),disabled:s}),l&&(0,p.jsx)(`p`,{className:`access-gate-error`,children:l}),(0,p.jsx)(i,{type:`submit`,disabled:s||!a.trim(),children:s?`Sending…`:`Send me a link`})]}),e===`request-sent`&&(0,p.jsxs)(`div`,{className:`access-gate-message`,children:[(0,p.jsx)(`h2`,{children:`Check your email`}),(0,p.jsx)(`p`,{children:`If that address is on the invite list, a fresh link is on the way. It expires in 15 minutes.`}),(0,p.jsx)(i,{onClick:()=>{t(`request-link`),o(``),u(null)},children:`Try a different email`})]})]})}function h(){let[e,t]=(0,f.useState)(null),[n,r]=(0,f.useState)(null),[i,l]=(0,f.useState)(`loading`),[d,p]=(0,f.useState)(``),[m,h]=(0,f.useState)(null),[g,_]=(0,f.useState)(null),[v,y]=(0,f.useState)(!1),[b,x]=(0,f.useState)(null),S=(0,f.useMemo)(()=>a(),[]),C=(0,f.useRef)(S||``),w=(0,f.useRef)(null),T=(0,f.useRef)(null),E=(0,f.useRef)(!1),D=(0,f.useRef)(null),[O,k]=(0,f.useState)(`request-link`),[A,j]=(0,f.useState)(null),M=(0,f.useRef)(null),N=(0,f.useRef)(null);(0,f.useEffect)(()=>{try{let e=sessionStorage.getItem(`maxy_session`);e&&(N.current=e)}catch{}},[]),(0,f.useEffect)(()=>{try{let e=c();e&&(sessionStorage.setItem(s,e),o&&console.info(`[public-webchat] op=seed-persisted len=${e.length} head=${e.slice(0,40)}`))}catch{}},[]);let P=(0,f.useCallback)(e=>{w.current=e,t(e);try{sessionStorage.setItem(`maxy_session`,e)}catch{}l(`chat`)},[]),F=(0,f.useCallback)(()=>{w.current=null;try{sessionStorage.removeItem(`maxy_session`)}catch{}t(null),l(`auth-required`),k(`request-link`)},[]),I=(0,f.useCallback)(async e=>{k(`verifying`);try{let t=C.current,n=await fetch(`/api/access/verify-token`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({token:e,agentSlug:t})});if(window.history.replaceState({},``,window.location.pathname),n.ok){let e=await n.json().catch(()=>({}));return e?.displayName&&j({displayName:e.displayName,contactValue:``,expiresAt:null,status:`active`}),!0}return k(`verify-failed`),!1}catch{return k(`verify-failed`),!1}},[]),L=(0,f.useCallback)(async()=>{if(w.current)return w.current;if(T.current)return T.current;let e=(async()=>{try{let e=N.current,n=await fetch(`/api/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({session_id:u(),...S?{agent:S}:{},...e?{session_key:e}:{}})});if(!n.ok){let e=await n.json().catch(()=>({error:``}));return o&&console.error(`[session] POST /api/session failed: ${n.status} ${n.statusText}`,e),n.status===404?r(e.error||`Agent not found`):n.status===503&&r(e.error||`Service unavailable`),null}let i=await n.json();if(i.auth_required){i.agent_id&&(C.current=i.agent_id),p(i.displayName||``),i.agentImage&&h(i.agentImage),i.agentImageShape&&_(i.agentImageShape),i.showAgentName&&y(i.showAgentName),i.branding&&x(i.branding),l(`auth-required`);let e=new URLSearchParams(window.location.search).get(`token`);return e?await I(e)&&window.location.reload():k(`request-link`),null}w.current=i.session_key,t(i.session_key),i.displayName&&p(i.displayName),i.agentImage&&h(i.agentImage),i.agentImageShape&&_(i.agentImageShape),i.showAgentName&&y(i.showAgentName),i.branding&&x(i.branding),l(`chat`),i.resumed&&i.messages&&(E.current=!0,D.current=i.messages);try{sessionStorage.setItem(`maxy_session`,i.session_key)}catch{}return i.session_key}catch(e){return o&&console.error(`[session] fetch /api/session threw:`,e),r(`Unable to connect. Please check your connection and try again.`),null}finally{T.current=null}})();return T.current=e,e},[S,I]);return{sessionId:e,cacheKeyRef:w,sessionError:n,pageState:i,setPageState:l,agentDisplayName:d,agentImage:m,agentImageShape:g,showAgentName:v,agentSlug:S,branding:b,resolvedSlugRef:C,ensureSession:L,startNewSession:(0,f.useCallback)(async()=>{w.current=null,T.current=null,N.current=null,E.current=!1,D.current=null,t(null),r(null);try{sessionStorage.removeItem(`maxy_session`)}catch{}await L()},[L]),enterChat:P,enterGate:F,resumedRef:E,resumeMessagesRef:D,gateState:O,setGateState:k,grantInfo:A,setGrantInfo:j,gateCacheKeyRef:M}}function g(){let{ensureSession:e,pageState:t,gateState:n,setGateState:r,grantInfo:i,resolvedSlugRef:a}=h();return(0,f.useEffect)(()=>{e()},[e]),t===`loading`?(0,p.jsx)(`div`,{className:`public-loading`,children:`Loading…`}):t===`auth-required`?(0,p.jsx)(m,{gateState:n,setGateState:r,grantInfo:i,resolvedSlugRef:a}):(0,p.jsx)(`div`,{className:`public-shell`,children:(0,p.jsx)(l,{cacheKey:``,variant:`public`})})}(0,d.createRoot)(document.getElementById(`root`)).render((0,p.jsx)(g,{}));
@@ -1 +1 @@
1
- import{P as e}from"./useSubAccountSwitcher-DVmWZxar.js";var t=e(`rotate-ccw`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}]]);export{t};
1
+ import{P as e}from"./useSubAccountSwitcher-6AFuRawP.js";var t=e(`rotate-ccw`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}]]);export{t};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{B as t,F as n,G as r,H as i,P as a,S as o,T as s,U as c,_ as l,g as u,p as d}from"./useSubAccountSwitcher-DVmWZxar.js";import{T as f,d as p,m,t as h}from"./AdminShell-C8hBpL9K.js";import{t as g}from"./clock-BceBgZP1.js";import{t as _}from"./wrench-oeLti270.js";var v=a(`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`}]]),y=c(),b=e(r(),1);function x(e){return/^\d+$/.test(e)?Number(e):null}function S(e){let t=e.trim().split(/\s+/);if(t.length!==5)return null;let[n,r,i,a,o]=t,s=x(n),c=x(r);if(s===null||c===null||s>59||c>23||a!==`*`)return null;if(i===`*`&&o===`*`)return{frequency:`daily`,minute:s,hour:c,weekdays:[],dayOfMonth:1};if(i===`*`&&o!==`*`){let e=o.split(`,`).map(x);return e.some(e=>e===null||e>6)?null:{frequency:`weekly`,minute:s,hour:c,weekdays:e,dayOfMonth:1}}if(o===`*`&&i!==`*`){let e=x(i);return e===null||e<1||e>31?null:{frequency:`monthly`,minute:s,hour:c,weekdays:[],dayOfMonth:e}}return null}function C(e){let t=String(e.minute),n=String(e.hour);return e.frequency===`daily`?`${t} ${n} * * *`:e.frequency===`weekly`?`${t} ${n} * * ${e.weekdays.length?[...e.weekdays].sort((e,t)=>e-t).join(`,`):`*`}`:`${t} ${n} ${e.dayOfMonth} * *`}var w=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function T(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 E(e){return String(e).padStart(2,`0`)}function D(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`:`${w[e%7]} to ${w[n%7]}`}let n=e.split(`,`);return n.length>0&&n.every(e=>/^\d+$/.test(e)&&Number(e)<=7)?n.map(e=>w[Number(e)%7]).join(`, `):`invalid`}function O(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))return e;let s=T(n,59),c=T(r,23);if(!s||!c)return e;let l=D(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}, ${E(c.value)}:00 to ${E(c.value)}:59${u}`:`${e}, ${E(c.rangeStart)}:00 to ${E(d(c))}:00${u}`}if(c.kind===`step`){let e=E(s.value),t=s.value===0?``:` at :${e}`;return c.rangeStart===null?`Every ${c.step} hours${t}${u}`:c.step===1?`Hourly, ${E(c.rangeStart)}:${e} to ${E(c.rangeEnd)}:${e}${u}`:`Every ${c.step} hours, ${E(c.rangeStart)}:${e} to ${E(d(c))}:${e}${u}`}if(c.kind===`any`)return`${s.value===0?`Every hour`:`Every hour at :${E(s.value)}`}${u}`;let f=`${E(c.value)}:${E(s.value)}`;return i===`*`?l?`${l} at ${f}`:`Daily at ${f}`:`Monthly on day ${Number(i)} at ${f}`}var k=t(),A=[{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`}];function j(e){return`${String(e.hour).padStart(2,`0`)}:${String(e.minute).padStart(2,`0`)}`}var M={frequency:`daily`,minute:0,hour:9,weekdays:[1],dayOfMonth:1};function N({recurrence:e,onChange:t,disabled:n}){let r=e?S(e):M,[i,a]=(0,b.useState)(r??M),[o]=(0,b.useState)(e!=null&&r==null),[s,c]=(0,b.useState)(e??``);if(o)return(0,k.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,k.jsx)(`span`,{children:`Schedule (advanced)`}),(0,k.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,k.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(C(e))},u=e=>{let t=e===`weekly`&&i.weekdays.length===0?[1]:i.weekdays;l({...i,frequency:e,weekdays:t})},d=e=>{let[t,n]=e.split(`:`);l({...i,hour:Number(t)||0,minute:Number(n)||0})},f=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})},p=e=>l({...i,dayOfMonth:Number(e)||1});return(0,k.jsxs)(`div`,{className:`routine-sched`,children:[(0,k.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,k.jsx)(`span`,{children:`Frequency`}),(0,k.jsxs)(`select`,{value:i.frequency,disabled:n,onChange:e=>u(e.target.value),children:[(0,k.jsx)(`option`,{value:`daily`,children:`Daily`}),(0,k.jsx)(`option`,{value:`weekly`,children:`Weekly`}),(0,k.jsx)(`option`,{value:`monthly`,children:`Monthly`})]})]}),(0,k.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,k.jsx)(`span`,{children:`Time of day`}),(0,k.jsx)(`input`,{type:`time`,value:j(i),disabled:n,onChange:e=>d(e.target.value)})]}),i.frequency===`weekly`&&(0,k.jsxs)(`div`,{className:`cal-modal-field`,children:[(0,k.jsx)(`span`,{children:`Days`}),(0,k.jsx)(`div`,{className:`routine-weekdays`,children:A.map(e=>(0,k.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:()=>f(e.value),children:e.label},e.value))})]}),i.frequency===`monthly`&&(0,k.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,k.jsx)(`span`,{children:`Day of month`}),(0,k.jsx)(`select`,{value:i.dayOfMonth,disabled:n,onChange:e=>p(e.target.value),children:Array.from({length:31},(e,t)=>t+1).map(e=>(0,k.jsx)(`option`,{value:e,children:e},e))})]})]})}function P(e){if(!e)return`—`;let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString():e}function F({routine:e,adminFetch:t,onClose:n,onSaved:r,onDeleted:i}){let[a,c]=(0,b.useState)(!1),[d,f]=(0,b.useState)(!1),[h,y]=(0,b.useState)(null),[x,S]=(0,b.useState)(e),[C,w]=(0,b.useState)(!1),T=x.agentChannel!=null,[E,D]=(0,b.useState)(e.agentPrompt??``),[A,j]=(0,b.useState)(e.recurrence);(0,b.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!d&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[d,n]);let M=(0,b.useCallback)(()=>{let e={};return T&&E!==(x.agentPrompt??``)&&(e.agentPrompt=E),A!=null&&A!==(x.recurrence??null)&&(e.recurrence=A),e},[T,E,A,x]),F=(0,b.useCallback)(async()=>{let n=M();if(Object.keys(n).length===0){c(!1);return}f(!0),y(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),D(a.routine.agentPrompt??``),j(a.routine.recurrence),r(a.routine),c(!1)}catch(e){y(e instanceof Error?e.message:`Save failed`)}finally{f(!1)}},[t,M,e.eventId,r]),I=(0,b.useCallback)(async()=>{if(!d){if(!C){w(!0);return}f(!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}`)}i(e.eventId)}catch(e){y(e instanceof Error?e.message:`Delete failed`),w(!1)}finally{f(!1)}}},[t,d,C,e.eventId,i]);return(0,k.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{d||n()},children:(0,k.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":a?`Edit routine`:`Routine detail`,onClick:e=>e.stopPropagation(),children:[(0,k.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,k.jsxs)(`span`,{className:`cal-modal-kind`,children:[(0,k.jsx)(p,{size:13}),` Routine`]}),(0,k.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:n,"aria-label":`Close`,autoFocus:!0,disabled:d,children:(0,k.jsx)(u,{size:16})})]}),!a&&(0,k.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,k.jsx)(`div`,{className:`cal-modal-title`,children:x.name??`Untitled routine`}),(0,k.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,k.jsx)(g,{size:14}),(0,k.jsx)(`span`,{children:x.recurrence?O(x.recurrence):`One-time`})]}),(0,k.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,k.jsxs)(`span`,{children:[`Status: `,x.eventStatus??`unknown`]})}),(0,k.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,k.jsxs)(`span`,{children:[`Next run: `,P(x.nextRun)]})}),(0,k.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,k.jsx)(v,{size:14}),(0,k.jsxs)(`span`,{children:[`Last run: `,P(x.lastTriggered),x.lastDispatchResult?` (${x.lastDispatchResult})`:``]})]}),T?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,k.jsx)(m,{size:14}),(0,k.jsxs)(`span`,{children:[x.agentChannel,` to `,x.agentDestination??`—`]})]}),(0,k.jsx)(`div`,{className:`cal-modal-row cal-modal-row-top routine-prose`,children:(0,k.jsx)(`span`,{children:x.agentPrompt??`No instruction set.`})})]}):x.actionPlugin?(0,k.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,k.jsx)(_,{size:14}),(0,k.jsxs)(`span`,{children:[x.actionPlugin,`.`,x.actionTool,x.actionArgs?` ${x.actionArgs}`:``]})]}):(0,k.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,k.jsx)(g,{size:14}),(0,k.jsx)(`span`,{children:`Scheduled trigger (no dispatch)`})]})]}),a&&(0,k.jsxs)(`div`,{className:`cal-modal-body`,children:[T&&(0,k.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,k.jsx)(`span`,{children:`Instruction`}),(0,k.jsx)(`textarea`,{className:`cal-modal-textarea`,value:E,onChange:e=>D(e.target.value),disabled:d,rows:16,placeholder:`What should the agent do when this routine fires?`})]}),(0,k.jsx)(N,{recurrence:x.recurrence,onChange:j,disabled:d})]}),h&&(0,k.jsx)(`div`,{className:`cal-modal-error`,children:h}),(0,k.jsxs)(`div`,{className:`cal-modal-actions`,children:[!a&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>{w(!1),c(!0)},disabled:d,children:[(0,k.jsx)(o,{size:14}),` Edit`]}),(0,k.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:I,disabled:d,children:[d&&C?(0,k.jsx)(s,{size:14,className:`spin`}):(0,k.jsx)(l,{size:14}),C?`Confirm delete`:`Delete`]})]}),a&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-primary`,onClick:F,disabled:d,children:[d?(0,k.jsx)(s,{size:14,className:`spin`}):null,` Save`]}),(0,k.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>{c(!1),y(null)},disabled:d,children:`Cancel`})]})]})]})})}var I=`maxy-admin-session-key`;function L(e){return e?O(e):`One-time`}function R(e){if(!e)return`—`;let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString():e}function z(){let[e,t]=(0,b.useState)(null),[r,i]=(0,b.useState)(!1),[a,o]=(0,b.useState)(void 0),[s,c]=(0,b.useState)(null),[l,u]=(0,b.useState)(void 0),[p,m]=(0,b.useState)(null),[g,_]=(0,b.useState)(null);(0,b.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(I)}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(I)}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&&c(e.sessionId??null),_(e.role??null),u(e.userName===void 0?null:e.userName),m(e.avatar??null)}catch{}t(n),i(!0)}}).catch(()=>{e||(t(n),i(!0))}),()=>{e=!0}},[]);let v=(0,b.useCallback)(()=>{try{sessionStorage.removeItem(I)}catch{}window.location.href=`/`},[]),[y,x]=(0,b.useState)(!1),S=(0,b.useCallback)(async()=>{x(!0);try{let e=await f();if(e){try{sessionStorage.removeItem(I)}catch{}window.location.href=`/`}return e}finally{x(!1)}},[]);return r?e?(0,k.jsx)(d,{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(I)}catch{}window.location.href=`/`},children:(0,k.jsx)(h,{cacheKey:e,businessName:a,sessionId:s,onLogout:v,onDisconnect:S,disconnecting:y,userName:l,userAvatar:p,role:g,children:(0,k.jsx)(B,{cacheKey:e})})}):(0,k.jsx)(`div`,{className:`cal-page`,children:(0,k.jsxs)(`div`,{className:`cal-empty`,children:[(0,k.jsx)(`p`,{children:`You are not signed in.`}),(0,k.jsxs)(`p`,{children:[`Open the `,(0,k.jsx)(`a`,{href:`/`,className:`cal-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,k.jsx)(n,{surface:`gate`})}function B({cacheKey:e}){let{adminFetch:t,sessionRefetchNonce:r}=i({initialCacheKey:e,surface:`routines`}),[a,o]=(0,b.useState)([]),[c,l]=(0,b.useState)(!1),[u,d]=(0,b.useState)(!1),[f,h]=(0,b.useState)(null),[v,y]=(0,b.useState)(null),x=(0,b.useCallback)(()=>{let e=!1;return l(!0),h(null),t(`/api/admin/routines`).then(async t=>{if(e)return;if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();o(Array.isArray(n.routines)?n.routines:[])}).catch(t=>{e||(h(t instanceof Error?t.message:`Failed to load`),o([]))}).finally(()=>{e||(l(!1),d(!0))}),()=>{e=!0}},[t]);(0,b.useEffect)(()=>x(),[x,r]);let S=(0,b.useCallback)(e=>{o(t=>t.map(t=>t.eventId===e.eventId?e:t)),y(e)},[]),C=(0,b.useCallback)(e=>{o(t=>t.filter(t=>t.eventId!==e)),y(null)},[]);return u?(0,k.jsxs)(`div`,{className:`cal-page`,children:[(0,k.jsx)(`header`,{className:`cal-header`,children:(0,k.jsxs)(`div`,{className:`cal-nav`,children:[(0,k.jsxs)(`span`,{className:`cal-range-label`,children:[(0,k.jsx)(p,{size:16}),` Routines`]}),c&&(0,k.jsx)(s,{size:16,className:`spin`})]})}),(0,k.jsxs)(`div`,{className:`cal-body`,children:[f&&(0,k.jsxs)(`div`,{className:`cal-error`,children:[`Could not load routines: `,f]}),!f&&!c&&a.length===0&&(0,k.jsx)(`div`,{className:`cal-empty`,children:(0,k.jsx)(`p`,{children:`No routines yet.`})}),(0,k.jsx)(`div`,{className:`routine-list`,children:a.map(e=>(0,k.jsxs)(`button`,{type:`button`,className:`routine-card`,onClick:()=>y(e),children:[(0,k.jsx)(`span`,{className:`routine-card-title`,children:e.name??`Untitled routine`}),(0,k.jsxs)(`span`,{className:`routine-card-sched`,children:[(0,k.jsx)(g,{size:13}),` `,L(e.recurrence)]}),(0,k.jsx)(`span`,{className:`routine-card-target`,children:e.agentChannel?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(m,{size:13}),` `,e.agentChannel,` to `,e.agentDestination??`—`]}):e.actionPlugin?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(_,{size:13}),` `,e.actionPlugin,`.`,e.actionTool]}):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(g,{size:13}),` Scheduled trigger`]})}),(0,k.jsxs)(`span`,{className:`routine-card-meta`,children:[`Next: `,R(e.nextRun),` · `,e.eventStatus??`unknown`]})]},e.eventId))})]}),v&&(0,k.jsx)(F,{routine:v,adminFetch:t,onClose:()=>y(null),onSaved:S,onDeleted:C})]}):(0,k.jsx)(n,{surface:`gate`})}(0,y.createRoot)(document.getElementById(`root`)).render((0,k.jsx)(z,{}));
1
+ import{o as e}from"./chunk-CltuBf4Z.js";import{B as t,F as n,G as r,H as i,P as a,S as o,T as s,U as c,_ as l,g as u,p as d}from"./useSubAccountSwitcher-6AFuRawP.js";import{T as f,d as p,m,t as h}from"./AdminShell-u32d8puE.js";import{t as g}from"./clock-DsmnhhJh.js";import{t as _}from"./wrench-B1hsCj0R.js";var v=a(`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`}]]),y=c(),b=e(r(),1);function x(e){return/^\d+$/.test(e)?Number(e):null}function S(e){let t=e.trim().split(/\s+/);if(t.length!==5)return null;let[n,r,i,a,o]=t,s=x(n),c=x(r);if(s===null||c===null||s>59||c>23||a!==`*`)return null;if(i===`*`&&o===`*`)return{frequency:`daily`,minute:s,hour:c,weekdays:[],dayOfMonth:1};if(i===`*`&&o!==`*`){let e=o.split(`,`).map(x);return e.some(e=>e===null||e>6)?null:{frequency:`weekly`,minute:s,hour:c,weekdays:e,dayOfMonth:1}}if(o===`*`&&i!==`*`){let e=x(i);return e===null||e<1||e>31?null:{frequency:`monthly`,minute:s,hour:c,weekdays:[],dayOfMonth:e}}return null}function C(e){let t=String(e.minute),n=String(e.hour);return e.frequency===`daily`?`${t} ${n} * * *`:e.frequency===`weekly`?`${t} ${n} * * ${e.weekdays.length?[...e.weekdays].sort((e,t)=>e-t).join(`,`):`*`}`:`${t} ${n} ${e.dayOfMonth} * *`}var w=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function T(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 E(e){return String(e).padStart(2,`0`)}function D(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`:`${w[e%7]} to ${w[n%7]}`}let n=e.split(`,`);return n.length>0&&n.every(e=>/^\d+$/.test(e)&&Number(e)<=7)?n.map(e=>w[Number(e)%7]).join(`, `):`invalid`}function O(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))return e;let s=T(n,59),c=T(r,23);if(!s||!c)return e;let l=D(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}, ${E(c.value)}:00 to ${E(c.value)}:59${u}`:`${e}, ${E(c.rangeStart)}:00 to ${E(d(c))}:00${u}`}if(c.kind===`step`){let e=E(s.value),t=s.value===0?``:` at :${e}`;return c.rangeStart===null?`Every ${c.step} hours${t}${u}`:c.step===1?`Hourly, ${E(c.rangeStart)}:${e} to ${E(c.rangeEnd)}:${e}${u}`:`Every ${c.step} hours, ${E(c.rangeStart)}:${e} to ${E(d(c))}:${e}${u}`}if(c.kind===`any`)return`${s.value===0?`Every hour`:`Every hour at :${E(s.value)}`}${u}`;let f=`${E(c.value)}:${E(s.value)}`;return i===`*`?l?`${l} at ${f}`:`Daily at ${f}`:`Monthly on day ${Number(i)} at ${f}`}var k=t(),A=[{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`}];function j(e){return`${String(e.hour).padStart(2,`0`)}:${String(e.minute).padStart(2,`0`)}`}var M={frequency:`daily`,minute:0,hour:9,weekdays:[1],dayOfMonth:1};function N({recurrence:e,onChange:t,disabled:n}){let r=e?S(e):M,[i,a]=(0,b.useState)(r??M),[o]=(0,b.useState)(e!=null&&r==null),[s,c]=(0,b.useState)(e??``);if(o)return(0,k.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,k.jsx)(`span`,{children:`Schedule (advanced)`}),(0,k.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,k.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(C(e))},u=e=>{let t=e===`weekly`&&i.weekdays.length===0?[1]:i.weekdays;l({...i,frequency:e,weekdays:t})},d=e=>{let[t,n]=e.split(`:`);l({...i,hour:Number(t)||0,minute:Number(n)||0})},f=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})},p=e=>l({...i,dayOfMonth:Number(e)||1});return(0,k.jsxs)(`div`,{className:`routine-sched`,children:[(0,k.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,k.jsx)(`span`,{children:`Frequency`}),(0,k.jsxs)(`select`,{value:i.frequency,disabled:n,onChange:e=>u(e.target.value),children:[(0,k.jsx)(`option`,{value:`daily`,children:`Daily`}),(0,k.jsx)(`option`,{value:`weekly`,children:`Weekly`}),(0,k.jsx)(`option`,{value:`monthly`,children:`Monthly`})]})]}),(0,k.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,k.jsx)(`span`,{children:`Time of day`}),(0,k.jsx)(`input`,{type:`time`,value:j(i),disabled:n,onChange:e=>d(e.target.value)})]}),i.frequency===`weekly`&&(0,k.jsxs)(`div`,{className:`cal-modal-field`,children:[(0,k.jsx)(`span`,{children:`Days`}),(0,k.jsx)(`div`,{className:`routine-weekdays`,children:A.map(e=>(0,k.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:()=>f(e.value),children:e.label},e.value))})]}),i.frequency===`monthly`&&(0,k.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,k.jsx)(`span`,{children:`Day of month`}),(0,k.jsx)(`select`,{value:i.dayOfMonth,disabled:n,onChange:e=>p(e.target.value),children:Array.from({length:31},(e,t)=>t+1).map(e=>(0,k.jsx)(`option`,{value:e,children:e},e))})]})]})}function P(e){if(!e)return`—`;let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString():e}function F({routine:e,adminFetch:t,onClose:n,onSaved:r,onDeleted:i}){let[a,c]=(0,b.useState)(!1),[d,f]=(0,b.useState)(!1),[h,y]=(0,b.useState)(null),[x,S]=(0,b.useState)(e),[C,w]=(0,b.useState)(!1),T=x.agentChannel!=null,[E,D]=(0,b.useState)(e.agentPrompt??``),[A,j]=(0,b.useState)(e.recurrence);(0,b.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!d&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[d,n]);let M=(0,b.useCallback)(()=>{let e={};return T&&E!==(x.agentPrompt??``)&&(e.agentPrompt=E),A!=null&&A!==(x.recurrence??null)&&(e.recurrence=A),e},[T,E,A,x]),F=(0,b.useCallback)(async()=>{let n=M();if(Object.keys(n).length===0){c(!1);return}f(!0),y(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),D(a.routine.agentPrompt??``),j(a.routine.recurrence),r(a.routine),c(!1)}catch(e){y(e instanceof Error?e.message:`Save failed`)}finally{f(!1)}},[t,M,e.eventId,r]),I=(0,b.useCallback)(async()=>{if(!d){if(!C){w(!0);return}f(!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}`)}i(e.eventId)}catch(e){y(e instanceof Error?e.message:`Delete failed`),w(!1)}finally{f(!1)}}},[t,d,C,e.eventId,i]);return(0,k.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{d||n()},children:(0,k.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":a?`Edit routine`:`Routine detail`,onClick:e=>e.stopPropagation(),children:[(0,k.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,k.jsxs)(`span`,{className:`cal-modal-kind`,children:[(0,k.jsx)(p,{size:13}),` Routine`]}),(0,k.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:n,"aria-label":`Close`,autoFocus:!0,disabled:d,children:(0,k.jsx)(u,{size:16})})]}),!a&&(0,k.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,k.jsx)(`div`,{className:`cal-modal-title`,children:x.name??`Untitled routine`}),(0,k.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,k.jsx)(g,{size:14}),(0,k.jsx)(`span`,{children:x.recurrence?O(x.recurrence):`One-time`})]}),(0,k.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,k.jsxs)(`span`,{children:[`Status: `,x.eventStatus??`unknown`]})}),(0,k.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,k.jsxs)(`span`,{children:[`Next run: `,P(x.nextRun)]})}),(0,k.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,k.jsx)(v,{size:14}),(0,k.jsxs)(`span`,{children:[`Last run: `,P(x.lastTriggered),x.lastDispatchResult?` (${x.lastDispatchResult})`:``]})]}),T?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,k.jsx)(m,{size:14}),(0,k.jsxs)(`span`,{children:[x.agentChannel,` to `,x.agentDestination??`—`]})]}),(0,k.jsx)(`div`,{className:`cal-modal-row cal-modal-row-top routine-prose`,children:(0,k.jsx)(`span`,{children:x.agentPrompt??`No instruction set.`})})]}):x.actionPlugin?(0,k.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,k.jsx)(_,{size:14}),(0,k.jsxs)(`span`,{children:[x.actionPlugin,`.`,x.actionTool,x.actionArgs?` ${x.actionArgs}`:``]})]}):(0,k.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,k.jsx)(g,{size:14}),(0,k.jsx)(`span`,{children:`Scheduled trigger (no dispatch)`})]})]}),a&&(0,k.jsxs)(`div`,{className:`cal-modal-body`,children:[T&&(0,k.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,k.jsx)(`span`,{children:`Instruction`}),(0,k.jsx)(`textarea`,{className:`cal-modal-textarea`,value:E,onChange:e=>D(e.target.value),disabled:d,rows:16,placeholder:`What should the agent do when this routine fires?`})]}),(0,k.jsx)(N,{recurrence:x.recurrence,onChange:j,disabled:d})]}),h&&(0,k.jsx)(`div`,{className:`cal-modal-error`,children:h}),(0,k.jsxs)(`div`,{className:`cal-modal-actions`,children:[!a&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>{w(!1),c(!0)},disabled:d,children:[(0,k.jsx)(o,{size:14}),` Edit`]}),(0,k.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:I,disabled:d,children:[d&&C?(0,k.jsx)(s,{size:14,className:`spin`}):(0,k.jsx)(l,{size:14}),C?`Confirm delete`:`Delete`]})]}),a&&(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-primary`,onClick:F,disabled:d,children:[d?(0,k.jsx)(s,{size:14,className:`spin`}):null,` Save`]}),(0,k.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>{c(!1),y(null)},disabled:d,children:`Cancel`})]})]})]})})}var I=`maxy-admin-session-key`;function L(e){return e?O(e):`One-time`}function R(e){if(!e)return`—`;let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString():e}function z(){let[e,t]=(0,b.useState)(null),[r,i]=(0,b.useState)(!1),[a,o]=(0,b.useState)(void 0),[s,c]=(0,b.useState)(null),[l,u]=(0,b.useState)(void 0),[p,m]=(0,b.useState)(null),[g,_]=(0,b.useState)(null);(0,b.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(I)}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(I)}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&&c(e.sessionId??null),_(e.role??null),u(e.userName===void 0?null:e.userName),m(e.avatar??null)}catch{}t(n),i(!0)}}).catch(()=>{e||(t(n),i(!0))}),()=>{e=!0}},[]);let v=(0,b.useCallback)(()=>{try{sessionStorage.removeItem(I)}catch{}window.location.href=`/`},[]),[y,x]=(0,b.useState)(!1),S=(0,b.useCallback)(async()=>{x(!0);try{let e=await f();if(e){try{sessionStorage.removeItem(I)}catch{}window.location.href=`/`}return e}finally{x(!1)}},[]);return r?e?(0,k.jsx)(d,{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(I)}catch{}window.location.href=`/`},children:(0,k.jsx)(h,{cacheKey:e,businessName:a,sessionId:s,onLogout:v,onDisconnect:S,disconnecting:y,userName:l,userAvatar:p,role:g,children:(0,k.jsx)(B,{cacheKey:e})})}):(0,k.jsx)(`div`,{className:`cal-page`,children:(0,k.jsxs)(`div`,{className:`cal-empty`,children:[(0,k.jsx)(`p`,{children:`You are not signed in.`}),(0,k.jsxs)(`p`,{children:[`Open the `,(0,k.jsx)(`a`,{href:`/`,className:`cal-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,k.jsx)(n,{surface:`gate`})}function B({cacheKey:e}){let{adminFetch:t,sessionRefetchNonce:r}=i({initialCacheKey:e,surface:`routines`}),[a,o]=(0,b.useState)([]),[c,l]=(0,b.useState)(!1),[u,d]=(0,b.useState)(!1),[f,h]=(0,b.useState)(null),[v,y]=(0,b.useState)(null),x=(0,b.useCallback)(()=>{let e=!1;return l(!0),h(null),t(`/api/admin/routines`).then(async t=>{if(e)return;if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();o(Array.isArray(n.routines)?n.routines:[])}).catch(t=>{e||(h(t instanceof Error?t.message:`Failed to load`),o([]))}).finally(()=>{e||(l(!1),d(!0))}),()=>{e=!0}},[t]);(0,b.useEffect)(()=>x(),[x,r]);let S=(0,b.useCallback)(e=>{o(t=>t.map(t=>t.eventId===e.eventId?e:t)),y(e)},[]),C=(0,b.useCallback)(e=>{o(t=>t.filter(t=>t.eventId!==e)),y(null)},[]);return u?(0,k.jsxs)(`div`,{className:`cal-page`,children:[(0,k.jsx)(`header`,{className:`cal-header`,children:(0,k.jsxs)(`div`,{className:`cal-nav`,children:[(0,k.jsxs)(`span`,{className:`cal-range-label`,children:[(0,k.jsx)(p,{size:16}),` Routines`]}),c&&(0,k.jsx)(s,{size:16,className:`spin`})]})}),(0,k.jsxs)(`div`,{className:`cal-body`,children:[f&&(0,k.jsxs)(`div`,{className:`cal-error`,children:[`Could not load routines: `,f]}),!f&&!c&&a.length===0&&(0,k.jsx)(`div`,{className:`cal-empty`,children:(0,k.jsx)(`p`,{children:`No routines yet.`})}),(0,k.jsx)(`div`,{className:`routine-list`,children:a.map(e=>(0,k.jsxs)(`button`,{type:`button`,className:`routine-card`,onClick:()=>y(e),children:[(0,k.jsx)(`span`,{className:`routine-card-title`,children:e.name??`Untitled routine`}),(0,k.jsxs)(`span`,{className:`routine-card-sched`,children:[(0,k.jsx)(g,{size:13}),` `,L(e.recurrence)]}),(0,k.jsx)(`span`,{className:`routine-card-target`,children:e.agentChannel?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(m,{size:13}),` `,e.agentChannel,` to `,e.agentDestination??`—`]}):e.actionPlugin?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(_,{size:13}),` `,e.actionPlugin,`.`,e.actionTool]}):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(g,{size:13}),` Scheduled trigger`]})}),(0,k.jsxs)(`span`,{className:`routine-card-meta`,children:[`Next: `,R(e.nextRun),` · `,e.eventStatus??`unknown`]})]},e.eventId))})]}),v&&(0,k.jsx)(F,{routine:v,adminFetch:t,onClose:()=>y(null),onSaved:S,onDeleted:C})]}):(0,k.jsx)(n,{surface:`gate`})}(0,y.createRoot)(document.getElementById(`root`)).render((0,k.jsx)(z,{}));
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{B as t,D as n,F as r,G as i,H as a,T as o,U as s,_ as c,g as l,p as u}from"./useSubAccountSwitcher-DVmWZxar.js";import{T as d,f,t as p}from"./AdminShell-C8hBpL9K.js";import{t as m}from"./file-text-RCoSeOpD.js";var h=s(),g=e(i(),1),_=t();function v({summary:e,adminFetch:t,onClose:r,onDeleted:i}){let[a,s]=(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}`);s((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&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[b,r]);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}`)}i(e)}catch(e){h(e instanceof Error?e.message:`Delete failed`),x(!1),y(!1)}},[t,e,i]);return(0,_.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{b||r()},children:(0,_.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":`Skill detail`,onClick:e=>e.stopPropagation(),children:[(0,_.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,_.jsxs)(`span`,{className:`cal-modal-kind`,children:[(0,_.jsx)(f,{size:13}),` Skill`]}),(0,_.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:r,"aria-label":`Close`,autoFocus:!0,disabled:b,children:(0,_.jsx)(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)(o,{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)(n,{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)(c,{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)(o,{size:14,className:`spin`}):(0,_.jsx)(c,{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,i]=(0,g.useState)(!1),[a,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){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&&c(e.sessionId??null),b(e.role??null),f(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 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:a,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)(r,{surface:`gate`})}function x({cacheKey:e}){let{adminFetch:t,sessionRefetchNonce:n}=a({initialCacheKey:e,surface:`skills`}),[i,s]=(0,g.useState)([]),[c,l]=(0,g.useState)(!1),[u,d]=(0,g.useState)(!1),[p,h]=(0,g.useState)(null),[y,b]=(0,g.useState)(null),x=(0,g.useCallback)(()=>{let e=!1;return l(!0),h(null),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),d(!0))}),()=>{e=!0}},[t]);(0,g.useEffect)(()=>x(),[x,n]);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)(f,{size:16}),` Skills`]}),c&&(0,_.jsx)(o,{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&&i.length===0&&(0,_.jsx)(`div`,{className:`cal-empty`,children:(0,_.jsx)(`p`,{children:`No skills yet. Ask in chat to create one.`})}),i.length>0&&(0,_.jsx)(`div`,{className:`routine-list`,children:i.map(e=>(0,_.jsxs)(`button`,{type:`button`,className:`routine-card`,onClick:()=>b(e),children:[(0,_.jsx)(`span`,{className:`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)(r,{surface:`gate`})}(0,h.createRoot)(document.getElementById(`root`)).render((0,_.jsx)(b,{}));
1
+ import{o as e}from"./chunk-CltuBf4Z.js";import{B as t,D as n,F as r,G as i,H as a,T as o,U as s,_ as c,g as l,p as u}from"./useSubAccountSwitcher-6AFuRawP.js";import{T as d,f,t as p}from"./AdminShell-u32d8puE.js";import{t as m}from"./file-text-C5K6DMcK.js";var h=s(),g=e(i(),1),_=t();function v({summary:e,adminFetch:t,onClose:r,onDeleted:i}){let[a,s]=(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}`);s((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&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[b,r]);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}`)}i(e)}catch(e){h(e instanceof Error?e.message:`Delete failed`),x(!1),y(!1)}},[t,e,i]);return(0,_.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{b||r()},children:(0,_.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":`Skill detail`,onClick:e=>e.stopPropagation(),children:[(0,_.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,_.jsxs)(`span`,{className:`cal-modal-kind`,children:[(0,_.jsx)(f,{size:13}),` Skill`]}),(0,_.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:r,"aria-label":`Close`,autoFocus:!0,disabled:b,children:(0,_.jsx)(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)(o,{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)(n,{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)(c,{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)(o,{size:14,className:`spin`}):(0,_.jsx)(c,{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,i]=(0,g.useState)(!1),[a,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){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&&c(e.sessionId??null),b(e.role??null),f(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 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:a,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)(r,{surface:`gate`})}function x({cacheKey:e}){let{adminFetch:t,sessionRefetchNonce:n}=a({initialCacheKey:e,surface:`skills`}),[i,s]=(0,g.useState)([]),[c,l]=(0,g.useState)(!1),[u,d]=(0,g.useState)(!1),[p,h]=(0,g.useState)(null),[y,b]=(0,g.useState)(null),x=(0,g.useCallback)(()=>{let e=!1;return l(!0),h(null),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),d(!0))}),()=>{e=!0}},[t]);(0,g.useEffect)(()=>x(),[x,n]);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)(f,{size:16}),` Skills`]}),c&&(0,_.jsx)(o,{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&&i.length===0&&(0,_.jsx)(`div`,{className:`cal-empty`,children:(0,_.jsx)(`p`,{children:`No skills yet. Ask in chat to create one.`})}),i.length>0&&(0,_.jsx)(`div`,{className:`routine-list`,children:i.map(e=>(0,_.jsxs)(`button`,{type:`button`,className:`routine-card`,onClick:()=>b(e),children:[(0,_.jsx)(`span`,{className:`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)(r,{surface:`gate`})}(0,h.createRoot)(document.getElementById(`root`)).render((0,_.jsx)(b,{}));
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{B as t,F as n,G as r,H as i,S as a,U as o,g as s,j as c,p as l,v as u}from"./useSubAccountSwitcher-DVmWZxar.js";import{T as d,t as f}from"./AdminShell-C8hBpL9K.js";import{n as p,t as m}from"./time-entry-format-BhlltPP8.js";import{t as h}from"./rotate-ccw-C1nRSAzP.js";var g=o(),_=e(r(),1);function v(e=3e4){let[t,n]=(0,_.useState)(()=>Date.now());return(0,_.useEffect)(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}function y(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)),b(e,i),i}function b(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 x=`__unassigned__`;function S(e,t){return e===`__unassigned__`?`Unassigned`:t||e.slice(0,8)}function C(e){return e===null||e===``?x:e}function ee(e,t){let n=new Map,r=(e,t)=>{let r=C(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:S(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 w(e,t){return t===null?!0:C(e.assigneeUserId)===t}var T=t();function E(e){let t=e.name??e.userId.slice(0,8);return e.kind===`owner`?`${t} (owner)`:t}var D=`maxy-admin-session-key`;function O(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 k(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 A(e){return e.assigneeName?e.assigneeName:e.assigneeUserId?e.assigneeUserId.slice(0,8):`Unassigned`}function j(e,t){return[t,k(e.createdAt),A(e)].filter(Boolean).join(` · `)}function M(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 N({clients:e,onSelect:t}){return(0,T.jsxs)(`section`,{className:`admin-card tasks-card`,children:[(0,T.jsxs)(`div`,{className:`tasks-card-head`,children:[(0,T.jsx)(`span`,{className:`tasks-card-title`,children:`Clients`}),(0,T.jsxs)(`span`,{className:`tasks-card-count`,children:[e.length,` total`]})]}),e.length===0&&(0,T.jsx)(`div`,{className:`tasks-empty`,children:`No clients yet.`}),e.map(e=>(0,T.jsx)(`button`,{className:`tasks-row tasks-client-row`,onClick:()=>t(e.name),children:(0,T.jsxs)(`div`,{className:`tasks-row-main`,children:[(0,T.jsx)(`div`,{className:`tasks-row-name`,children:e.name}),(0,T.jsxs)(`div`,{className:`tasks-row-sub`,children:[e.openCount,` open · `,m(e.totalSeconds),` logged`]})]})},e.name))]})}function P({task:e,roster:t,busy:n,onAssign:r,onClose:i}){return(0,_.useEffect)(()=>{let e=e=>{e.key===`Escape`&&i()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i]),(0,T.jsx)(`div`,{className:`tasks-detail-backdrop`,onClick:i,children:(0,T.jsxs)(`div`,{className:`tasks-detail`,role:`dialog`,"aria-modal":`true`,"aria-label":`Task detail`,onClick:e=>e.stopPropagation(),children:[(0,T.jsxs)(`div`,{className:`tasks-detail-head`,children:[(0,T.jsx)(`h2`,{className:`tasks-detail-title`,children:e?e.name:`Task no longer available`}),(0,T.jsx)(`button`,{className:`tasks-detail-close`,"aria-label":`Close`,onClick:i,children:(0,T.jsx)(s,{size:16})})]}),e===null?(0,T.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,T.jsxs)(`dl`,{className:`tasks-detail-fields`,children:[(0,T.jsx)(`dt`,{children:`Status`}),(0,T.jsx)(`dd`,{children:e.status}),(0,T.jsx)(`dt`,{children:`Logged`}),(0,T.jsx)(`dd`,{children:m(e.secondsLogged)}),(0,T.jsx)(`dt`,{children:`Created`}),(0,T.jsx)(`dd`,{children:k(e.createdAt)||`Not recorded`}),(0,T.jsx)(`dt`,{children:`Assignee`}),(0,T.jsx)(`dd`,{children:e.taskId===null?A(e):(0,T.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,T.jsx)(`option`,{value:``,children:`Unassigned`}),e.assigneeUserId&&!t.some(t=>t.userId===e.assigneeUserId)&&(0,T.jsxs)(`option`,{value:e.assigneeUserId,children:[A(e),` (not in roster)`]}),t.map(e=>(0,T.jsx)(`option`,{value:e.userId,children:E(e)},e.userId))]})}),e.clientName&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`dt`,{children:`Client`}),(0,T.jsx)(`dd`,{children:e.clientName})]}),e.propertyAddress&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`dt`,{children:`Property`}),(0,T.jsx)(`dd`,{children:e.propertyAddress})]}),e.fee!=null&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`dt`,{children:`Fee`}),(0,T.jsxs)(`dd`,{children:[`£`,e.fee]})]})]})]})})}function F({adminFetch:e}){let[t,r]=(0,_.useState)({open:[],completed:[]}),[i,o]=(0,_.useState)(!1),[l,d]=(0,_.useState)(!1),f=(0,_.useRef)(!1),g=(0,_.useRef)(``),b=v(1e3),[x,S]=(0,_.useState)(`open`),[C,E]=(0,_.useState)(null),[D,k]=(0,_.useState)(null),[A,F]=(0,_.useState)(null),[I,L]=(0,_.useState)(``),[R,z]=(0,_.useState)(null),[B,V]=(0,_.useState)(null),H=(0,_.useMemo)(()=>{if(R!==null)return[...t.open,...t.completed].find(e=>e.rowKey===R)??null},[t,R]);(0,_.useEffect)(()=>{R!==null&&H===null&&console.error(`[tasks-ui] op=detail-failed rowKey=${R} reason=not-in-list`)},[R,H]);let U=(0,_.useMemo)(()=>y(t.open,t.completed),[t]),W=(0,_.useMemo)(()=>C===null?{open:t.open,completed:t.completed}:{open:t.open.filter(e=>e.clientName===C),completed:t.completed.filter(e=>e.clientName===C)},[t,C]),G=(0,_.useMemo)(()=>ee(W.open,W.completed),[W]),K=(0,_.useCallback)(e=>{E(e),S(`open`)},[]);(0,_.useEffect)(()=>{C&&!U.some(e=>e.name===C)&&E(null)},[U,C]),(0,_.useEffect)(()=>{D&&!G.some(e=>e.userId===D)&&k(null)},[G,D]),(0,_.useEffect)(()=>{V(null)},[x,C,D]);let q=t.open.filter(e=>e.running||(C===null||e.clientName===C)&&w(e,D)),J=(C?t.completed.filter(e=>e.clientName===C):t.completed).filter(e=>w(e,D)),[te,ne]=(0,_.useState)([]),Y=(0,_.useCallback)(async()=>{let t=await e(`/api/admin/tasks-list`);t.ok&&r(await t.json()),o(!0)},[e]);(0,_.useEffect)(()=>{Y()},[Y]),(0,_.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)&&ne(e.users)}})()},[e]);let X=(0,_.useCallback)(async(t,n,r)=>{if(f.current)return!1;f.current=!0,d(!0);try{return await e(t,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({taskId:n,...r})}),await Y(),!0}finally{f.current=!1,d(!1)}},[e,Y]),re=(0,_.useCallback)(async e=>{await X(`/api/admin/task-complete`,e)&&console.log(`[tasks-ui] op=complete taskId=${e.slice(0,8)} confirmed=true`)},[X]),ie=(0,_.useCallback)((e,t)=>{let n=String(Math.round(e.secondsLogged/60));g.current=n,F(t),L(n)},[]),Z=(0,_.useCallback)(()=>{F(null),L(``)},[]),ae=(0,_.useCallback)(async e=>{let t=I.trim(),n=Number(t);if(!(t===``||!Number.isInteger(n)||n<0)){if(t===g.current){Z();return}F(null),L(``),await X(`/api/admin/task-time-adjust`,e,{newSeconds:n*60})}},[I,X,Z]),oe=(0,_.useCallback)(e=>{X(`/api/admin/task-time-adjust`,e,{newSeconds:0})},[X]),se=(0,_.useCallback)((e,t)=>{X(`/api/admin/task-assign`,e,{assigneeUserId:t})},[X]);if(!i)return(0,T.jsx)(n,{surface:`gate`});let Q=e=>e.taskId!==null&&A===e.taskId,$=(e,t)=>Q(e)?(0,T.jsxs)(`div`,{className:`tasks-edit`,children:[(0,T.jsx)(`input`,{className:`tasks-edit-input`,type:`number`,min:0,step:1,"aria-label":`Logged minutes`,value:I,onChange:e=>L(e.target.value)}),(0,T.jsx)(`span`,{className:`tasks-edit-unit`,children:`min`}),(0,T.jsxs)(`button`,{className:`admin-btn-cta tasks-btn-action`,disabled:l,onClick:()=>void ae(t),children:[(0,T.jsx)(c,{size:14}),` Save`]}),(0,T.jsxs)(`button`,{className:`tasks-btn-secondary tasks-btn-action`,onClick:Z,children:[(0,T.jsx)(s,{size:14}),` Cancel`]})]}):(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`button`,{className:`tasks-time-btn`,"aria-label":`Edit time`,disabled:l||e.running,title:e.running?`Stop the timer before editing time`:void 0,onClick:()=>ie(e,t),children:(0,T.jsx)(a,{size:14})}),(0,T.jsx)(`button`,{className:`tasks-time-btn`,"aria-label":`Reset time`,disabled:l||e.running,title:e.running?`Stop the timer before resetting time`:void 0,onClick:()=>oe(t),children:(0,T.jsx)(h,{size:14})})]});return(0,T.jsxs)(`div`,{className:`tasks-body`,children:[R!==null&&(0,T.jsx)(P,{task:H??null,roster:te,busy:l,onAssign:se,onClose:()=>z(null)}),(0,T.jsxs)(`div`,{className:`tasks-tabs`,children:[(0,T.jsxs)(`button`,{className:`admin-chip ${x===`open`?`is-active`:``}`,onClick:()=>S(`open`),children:[`Open `,(0,T.jsx)(`span`,{className:`tasks-tab-badge`,children:t.open.length})]}),(0,T.jsxs)(`button`,{className:`admin-chip ${x===`completed`?`is-active`:``}`,onClick:()=>S(`completed`),children:[`Completed `,(0,T.jsx)(`span`,{className:`tasks-tab-badge`,children:t.completed.length})]}),(0,T.jsxs)(`button`,{className:`admin-chip ${x===`clients`?`is-active`:``}`,onClick:()=>S(`clients`),children:[`Clients `,(0,T.jsx)(`span`,{className:`tasks-tab-badge`,children:U.length})]})]}),x===`clients`?(0,T.jsx)(N,{clients:U,onSelect:K}):(0,T.jsxs)(T.Fragment,{children:[C&&(0,T.jsxs)(`div`,{className:`tasks-filter-banner`,children:[(0,T.jsxs)(`span`,{children:[`Showing `,C]}),(0,T.jsx)(`button`,{className:`tasks-filter-clear`,onClick:()=>E(null),children:`Clear`})]}),G.length>0&&(0,T.jsxs)(`div`,{className:`tasks-assignee-bar`,children:[(0,T.jsxs)(`button`,{className:`admin-chip ${D===null?`is-active`:``}`,"aria-pressed":D===null,onClick:()=>k(null),children:[`All `,(0,T.jsx)(`span`,{className:`tasks-assignee-count`,children:W.open.length})]}),G.map(e=>(0,T.jsxs)(`button`,{className:`admin-chip ${D===e.userId?`is-active`:``}`,"aria-pressed":D===e.userId,"aria-label":`Assignee ${e.label}`,title:e.userId===`__unassigned__`?`Tasks with no assigned admin`:`AdminUser ${e.userId}`,onClick:()=>k(D===e.userId?null:e.userId),children:[e.label,` `,(0,T.jsx)(`span`,{className:`tasks-assignee-count`,children:e.openCount})]},e.userId))]}),x===`open`?(0,T.jsxs)(`section`,{className:`admin-card tasks-card`,children:[(0,T.jsxs)(`div`,{className:`tasks-card-head`,children:[(0,T.jsx)(`span`,{className:`tasks-card-title`,children:`Open tasks`}),(0,T.jsxs)(`span`,{className:`tasks-card-count`,children:[q.length,` to do`]})]}),q.length===0&&(0,T.jsx)(`div`,{className:`tasks-empty`,children:`No open tasks.`}),q.map(e=>(0,T.jsxs)(`div`,{className:`tasks-row`,children:[(0,T.jsx)(`button`,{className:`tasks-row-open`,"aria-label":`Open task detail: ${e.name}`,onClick:()=>z(e.rowKey),children:(0,T.jsxs)(`div`,{className:`tasks-row-main`,children:[(0,T.jsx)(`div`,{className:`tasks-row-name`,children:e.name}),(0,T.jsx)(`div`,{className:`tasks-row-sub`,children:j(e,O(e))})]})}),(0,T.jsx)(`div`,{className:`tasks-row-elapsed ${e.running?`tasks-row-elapsed-running`:``}`,children:m(M(e,b))}),(0,T.jsx)(`div`,{className:`tasks-row-controls ${e.taskId!==null&&B===e.taskId?`is-confirming`:``}`,children:e.taskId!==null&&B===e.taskId?(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`span`,{className:`tasks-confirm-label`,children:`Complete?`}),(0,T.jsxs)(`button`,{className:`admin-btn-cta tasks-btn-action`,disabled:l,onClick:()=>{V(null),re(e.taskId)},children:[(0,T.jsx)(c,{size:14}),` Confirm complete`]}),(0,T.jsxs)(`button`,{className:`tasks-btn-secondary tasks-btn-action`,onClick:()=>V(null),children:[(0,T.jsx)(s,{size:14}),` Keep open`]})]}):e.taskId===null?(0,T.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`}):(0,T.jsxs)(T.Fragment,{children:[$(e,e.taskId),Q(e)?null:(0,T.jsxs)(`button`,{className:`tasks-btn-secondary tasks-btn-action`,"aria-label":`Complete task: ${e.name}`,disabled:l||e.running,title:e.running?`Stop the timer before completing`:void 0,onClick:()=>V(e.taskId),children:[(0,T.jsx)(c,{size:14}),` Complete`]}),Q(e)?null:e.running?(0,T.jsxs)(`button`,{className:`admin-btn-danger tasks-btn-action`,disabled:l,onClick:()=>void X(`/api/admin/task-timer-stop`,e.taskId),children:[(0,T.jsx)(u,{size:14}),` Stop`]}):(0,T.jsxs)(`button`,{className:`admin-btn-cta tasks-btn-action`,disabled:l,onClick:()=>void X(`/api/admin/task-timer-start`,e.taskId),children:[(0,T.jsx)(p,{size:14}),` Start`]})]})})]},e.rowKey))]}):(0,T.jsxs)(`section`,{className:`admin-card tasks-card`,children:[(0,T.jsxs)(`div`,{className:`tasks-card-head`,children:[(0,T.jsx)(`span`,{className:`tasks-card-title`,children:`Completed`}),(0,T.jsxs)(`span`,{className:`tasks-card-count`,children:[J.length,` done`]})]}),J.length===0&&(0,T.jsx)(`div`,{className:`tasks-empty`,children:`Nothing completed yet.`}),J.map(e=>(0,T.jsxs)(`div`,{className:`tasks-row tasks-row-done`,children:[(0,T.jsx)(`button`,{className:`tasks-row-open`,"aria-label":`Open task detail: ${e.name}`,onClick:()=>z(e.rowKey),children:(0,T.jsxs)(`div`,{className:`tasks-row-main`,children:[(0,T.jsx)(`div`,{className:`tasks-row-name`,children:e.name}),(0,T.jsx)(`div`,{className:`tasks-row-sub`,children:j(e,O(e))})]})}),(0,T.jsx)(`div`,{className:`tasks-row-elapsed`,children:m(e.secondsLogged)}),(0,T.jsx)(`div`,{className:`tasks-row-controls`,children:e.taskId===null?(0,T.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`}):$(e,e.taskId)})]},e.rowKey))]})]})]})}function I({cacheKey:e}){let{adminFetch:t}=i({initialCacheKey:e,surface:`tasks`});return(0,T.jsx)(F,{adminFetch:t})}function L(){let[e,t]=(0,_.useState)(null),[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(void 0),[s,c]=(0,_.useState)(null),[u,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(null),[g,v]=(0,_.useState)(null);(0,_.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(D)}catch{}if(!n){t(null),i(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async r=>{if(!e){if(r.status===401){try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`;return}if(r.ok)try{let e=await r.json();typeof e.businessName==`string`&&o(e.businessName),e.sessionId!==void 0&&c(e.sessionId??null),p(e.role??null),h(e.userName===void 0?null:e.userName),v(e.avatar??null)}catch{}t(n),i(!0)}}).catch(()=>{e||(t(n),i(!0))}),()=>{e=!0}},[]);let y=(0,_.useCallback)(()=>{try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`},[]),[b,x]=(0,_.useState)(!1),S=(0,_.useCallback)(async()=>{x(!0);try{let e=await d();if(e){try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`}return e}finally{x(!1)}},[]);return r?e?(0,T.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(D)}catch{}window.location.href=`/`},children:(0,T.jsx)(f,{cacheKey:e,businessName:a,sessionId:s,onLogout:y,onDisconnect:S,disconnecting:b,userName:m,userAvatar:g,role:u,children:(0,T.jsx)(I,{cacheKey:e})})}):(0,T.jsx)(`div`,{className:`tasks-page`,children:(0,T.jsxs)(`div`,{className:`tasks-empty`,children:[(0,T.jsx)(`p`,{children:`You are not signed in.`}),(0,T.jsxs)(`p`,{children:[`Open the `,(0,T.jsx)(`a`,{href:`/`,className:`tasks-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,T.jsx)(n,{surface:`gate`})}(0,g.createRoot)(document.getElementById(`root`)).render((0,T.jsx)(L,{}));
1
+ import{o as e}from"./chunk-CltuBf4Z.js";import{B as t,F as n,G as r,H as i,S as a,U as o,g as s,j as c,p as l,v as u}from"./useSubAccountSwitcher-6AFuRawP.js";import{T as d,t as f}from"./AdminShell-u32d8puE.js";import{n as p,t as m}from"./time-entry-format-CDhHCMrW.js";import{t as h}from"./rotate-ccw-P35h7ogS.js";var g=o(),_=e(r(),1);function v(e=3e4){let[t,n]=(0,_.useState)(()=>Date.now());return(0,_.useEffect)(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}function y(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)),b(e,i),i}function b(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 x=`__unassigned__`;function S(e,t){return e===`__unassigned__`?`Unassigned`:t||e.slice(0,8)}function C(e){return e===null||e===``?x:e}function ee(e,t){let n=new Map,r=(e,t)=>{let r=C(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:S(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 w(e,t){return t===null?!0:C(e.assigneeUserId)===t}var T=t();function E(e){let t=e.name??e.userId.slice(0,8);return e.kind===`owner`?`${t} (owner)`:t}var D=`maxy-admin-session-key`;function O(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 k(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 A(e){return e.assigneeName?e.assigneeName:e.assigneeUserId?e.assigneeUserId.slice(0,8):`Unassigned`}function j(e,t){return[t,k(e.createdAt),A(e)].filter(Boolean).join(` · `)}function M(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 N({clients:e,onSelect:t}){return(0,T.jsxs)(`section`,{className:`admin-card tasks-card`,children:[(0,T.jsxs)(`div`,{className:`tasks-card-head`,children:[(0,T.jsx)(`span`,{className:`tasks-card-title`,children:`Clients`}),(0,T.jsxs)(`span`,{className:`tasks-card-count`,children:[e.length,` total`]})]}),e.length===0&&(0,T.jsx)(`div`,{className:`tasks-empty`,children:`No clients yet.`}),e.map(e=>(0,T.jsx)(`button`,{className:`tasks-row tasks-client-row`,onClick:()=>t(e.name),children:(0,T.jsxs)(`div`,{className:`tasks-row-main`,children:[(0,T.jsx)(`div`,{className:`tasks-row-name`,children:e.name}),(0,T.jsxs)(`div`,{className:`tasks-row-sub`,children:[e.openCount,` open · `,m(e.totalSeconds),` logged`]})]})},e.name))]})}function P({task:e,roster:t,busy:n,onAssign:r,onClose:i}){return(0,_.useEffect)(()=>{let e=e=>{e.key===`Escape`&&i()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i]),(0,T.jsx)(`div`,{className:`tasks-detail-backdrop`,onClick:i,children:(0,T.jsxs)(`div`,{className:`tasks-detail`,role:`dialog`,"aria-modal":`true`,"aria-label":`Task detail`,onClick:e=>e.stopPropagation(),children:[(0,T.jsxs)(`div`,{className:`tasks-detail-head`,children:[(0,T.jsx)(`h2`,{className:`tasks-detail-title`,children:e?e.name:`Task no longer available`}),(0,T.jsx)(`button`,{className:`tasks-detail-close`,"aria-label":`Close`,onClick:i,children:(0,T.jsx)(s,{size:16})})]}),e===null?(0,T.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,T.jsxs)(`dl`,{className:`tasks-detail-fields`,children:[(0,T.jsx)(`dt`,{children:`Status`}),(0,T.jsx)(`dd`,{children:e.status}),(0,T.jsx)(`dt`,{children:`Logged`}),(0,T.jsx)(`dd`,{children:m(e.secondsLogged)}),(0,T.jsx)(`dt`,{children:`Created`}),(0,T.jsx)(`dd`,{children:k(e.createdAt)||`Not recorded`}),(0,T.jsx)(`dt`,{children:`Assignee`}),(0,T.jsx)(`dd`,{children:e.taskId===null?A(e):(0,T.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,T.jsx)(`option`,{value:``,children:`Unassigned`}),e.assigneeUserId&&!t.some(t=>t.userId===e.assigneeUserId)&&(0,T.jsxs)(`option`,{value:e.assigneeUserId,children:[A(e),` (not in roster)`]}),t.map(e=>(0,T.jsx)(`option`,{value:e.userId,children:E(e)},e.userId))]})}),e.clientName&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`dt`,{children:`Client`}),(0,T.jsx)(`dd`,{children:e.clientName})]}),e.propertyAddress&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`dt`,{children:`Property`}),(0,T.jsx)(`dd`,{children:e.propertyAddress})]}),e.fee!=null&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`dt`,{children:`Fee`}),(0,T.jsxs)(`dd`,{children:[`£`,e.fee]})]})]})]})})}function F({adminFetch:e}){let[t,r]=(0,_.useState)({open:[],completed:[]}),[i,o]=(0,_.useState)(!1),[l,d]=(0,_.useState)(!1),f=(0,_.useRef)(!1),g=(0,_.useRef)(``),b=v(1e3),[x,S]=(0,_.useState)(`open`),[C,E]=(0,_.useState)(null),[D,k]=(0,_.useState)(null),[A,F]=(0,_.useState)(null),[I,L]=(0,_.useState)(``),[R,z]=(0,_.useState)(null),[B,V]=(0,_.useState)(null),H=(0,_.useMemo)(()=>{if(R!==null)return[...t.open,...t.completed].find(e=>e.rowKey===R)??null},[t,R]);(0,_.useEffect)(()=>{R!==null&&H===null&&console.error(`[tasks-ui] op=detail-failed rowKey=${R} reason=not-in-list`)},[R,H]);let U=(0,_.useMemo)(()=>y(t.open,t.completed),[t]),W=(0,_.useMemo)(()=>C===null?{open:t.open,completed:t.completed}:{open:t.open.filter(e=>e.clientName===C),completed:t.completed.filter(e=>e.clientName===C)},[t,C]),G=(0,_.useMemo)(()=>ee(W.open,W.completed),[W]),K=(0,_.useCallback)(e=>{E(e),S(`open`)},[]);(0,_.useEffect)(()=>{C&&!U.some(e=>e.name===C)&&E(null)},[U,C]),(0,_.useEffect)(()=>{D&&!G.some(e=>e.userId===D)&&k(null)},[G,D]),(0,_.useEffect)(()=>{V(null)},[x,C,D]);let q=t.open.filter(e=>e.running||(C===null||e.clientName===C)&&w(e,D)),J=(C?t.completed.filter(e=>e.clientName===C):t.completed).filter(e=>w(e,D)),[te,ne]=(0,_.useState)([]),Y=(0,_.useCallback)(async()=>{let t=await e(`/api/admin/tasks-list`);t.ok&&r(await t.json()),o(!0)},[e]);(0,_.useEffect)(()=>{Y()},[Y]),(0,_.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)&&ne(e.users)}})()},[e]);let X=(0,_.useCallback)(async(t,n,r)=>{if(f.current)return!1;f.current=!0,d(!0);try{return await e(t,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({taskId:n,...r})}),await Y(),!0}finally{f.current=!1,d(!1)}},[e,Y]),re=(0,_.useCallback)(async e=>{await X(`/api/admin/task-complete`,e)&&console.log(`[tasks-ui] op=complete taskId=${e.slice(0,8)} confirmed=true`)},[X]),ie=(0,_.useCallback)((e,t)=>{let n=String(Math.round(e.secondsLogged/60));g.current=n,F(t),L(n)},[]),Z=(0,_.useCallback)(()=>{F(null),L(``)},[]),ae=(0,_.useCallback)(async e=>{let t=I.trim(),n=Number(t);if(!(t===``||!Number.isInteger(n)||n<0)){if(t===g.current){Z();return}F(null),L(``),await X(`/api/admin/task-time-adjust`,e,{newSeconds:n*60})}},[I,X,Z]),oe=(0,_.useCallback)(e=>{X(`/api/admin/task-time-adjust`,e,{newSeconds:0})},[X]),se=(0,_.useCallback)((e,t)=>{X(`/api/admin/task-assign`,e,{assigneeUserId:t})},[X]);if(!i)return(0,T.jsx)(n,{surface:`gate`});let Q=e=>e.taskId!==null&&A===e.taskId,$=(e,t)=>Q(e)?(0,T.jsxs)(`div`,{className:`tasks-edit`,children:[(0,T.jsx)(`input`,{className:`tasks-edit-input`,type:`number`,min:0,step:1,"aria-label":`Logged minutes`,value:I,onChange:e=>L(e.target.value)}),(0,T.jsx)(`span`,{className:`tasks-edit-unit`,children:`min`}),(0,T.jsxs)(`button`,{className:`admin-btn-cta tasks-btn-action`,disabled:l,onClick:()=>void ae(t),children:[(0,T.jsx)(c,{size:14}),` Save`]}),(0,T.jsxs)(`button`,{className:`tasks-btn-secondary tasks-btn-action`,onClick:Z,children:[(0,T.jsx)(s,{size:14}),` Cancel`]})]}):(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`button`,{className:`tasks-time-btn`,"aria-label":`Edit time`,disabled:l||e.running,title:e.running?`Stop the timer before editing time`:void 0,onClick:()=>ie(e,t),children:(0,T.jsx)(a,{size:14})}),(0,T.jsx)(`button`,{className:`tasks-time-btn`,"aria-label":`Reset time`,disabled:l||e.running,title:e.running?`Stop the timer before resetting time`:void 0,onClick:()=>oe(t),children:(0,T.jsx)(h,{size:14})})]});return(0,T.jsxs)(`div`,{className:`tasks-body`,children:[R!==null&&(0,T.jsx)(P,{task:H??null,roster:te,busy:l,onAssign:se,onClose:()=>z(null)}),(0,T.jsxs)(`div`,{className:`tasks-tabs`,children:[(0,T.jsxs)(`button`,{className:`admin-chip ${x===`open`?`is-active`:``}`,onClick:()=>S(`open`),children:[`Open `,(0,T.jsx)(`span`,{className:`tasks-tab-badge`,children:t.open.length})]}),(0,T.jsxs)(`button`,{className:`admin-chip ${x===`completed`?`is-active`:``}`,onClick:()=>S(`completed`),children:[`Completed `,(0,T.jsx)(`span`,{className:`tasks-tab-badge`,children:t.completed.length})]}),(0,T.jsxs)(`button`,{className:`admin-chip ${x===`clients`?`is-active`:``}`,onClick:()=>S(`clients`),children:[`Clients `,(0,T.jsx)(`span`,{className:`tasks-tab-badge`,children:U.length})]})]}),x===`clients`?(0,T.jsx)(N,{clients:U,onSelect:K}):(0,T.jsxs)(T.Fragment,{children:[C&&(0,T.jsxs)(`div`,{className:`tasks-filter-banner`,children:[(0,T.jsxs)(`span`,{children:[`Showing `,C]}),(0,T.jsx)(`button`,{className:`tasks-filter-clear`,onClick:()=>E(null),children:`Clear`})]}),G.length>0&&(0,T.jsxs)(`div`,{className:`tasks-assignee-bar`,children:[(0,T.jsxs)(`button`,{className:`admin-chip ${D===null?`is-active`:``}`,"aria-pressed":D===null,onClick:()=>k(null),children:[`All `,(0,T.jsx)(`span`,{className:`tasks-assignee-count`,children:W.open.length})]}),G.map(e=>(0,T.jsxs)(`button`,{className:`admin-chip ${D===e.userId?`is-active`:``}`,"aria-pressed":D===e.userId,"aria-label":`Assignee ${e.label}`,title:e.userId===`__unassigned__`?`Tasks with no assigned admin`:`AdminUser ${e.userId}`,onClick:()=>k(D===e.userId?null:e.userId),children:[e.label,` `,(0,T.jsx)(`span`,{className:`tasks-assignee-count`,children:e.openCount})]},e.userId))]}),x===`open`?(0,T.jsxs)(`section`,{className:`admin-card tasks-card`,children:[(0,T.jsxs)(`div`,{className:`tasks-card-head`,children:[(0,T.jsx)(`span`,{className:`tasks-card-title`,children:`Open tasks`}),(0,T.jsxs)(`span`,{className:`tasks-card-count`,children:[q.length,` to do`]})]}),q.length===0&&(0,T.jsx)(`div`,{className:`tasks-empty`,children:`No open tasks.`}),q.map(e=>(0,T.jsxs)(`div`,{className:`tasks-row`,children:[(0,T.jsx)(`button`,{className:`tasks-row-open`,"aria-label":`Open task detail: ${e.name}`,onClick:()=>z(e.rowKey),children:(0,T.jsxs)(`div`,{className:`tasks-row-main`,children:[(0,T.jsx)(`div`,{className:`tasks-row-name`,children:e.name}),(0,T.jsx)(`div`,{className:`tasks-row-sub`,children:j(e,O(e))})]})}),(0,T.jsx)(`div`,{className:`tasks-row-elapsed ${e.running?`tasks-row-elapsed-running`:``}`,children:m(M(e,b))}),(0,T.jsx)(`div`,{className:`tasks-row-controls ${e.taskId!==null&&B===e.taskId?`is-confirming`:``}`,children:e.taskId!==null&&B===e.taskId?(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`span`,{className:`tasks-confirm-label`,children:`Complete?`}),(0,T.jsxs)(`button`,{className:`admin-btn-cta tasks-btn-action`,disabled:l,onClick:()=>{V(null),re(e.taskId)},children:[(0,T.jsx)(c,{size:14}),` Confirm complete`]}),(0,T.jsxs)(`button`,{className:`tasks-btn-secondary tasks-btn-action`,onClick:()=>V(null),children:[(0,T.jsx)(s,{size:14}),` Keep open`]})]}):e.taskId===null?(0,T.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`}):(0,T.jsxs)(T.Fragment,{children:[$(e,e.taskId),Q(e)?null:(0,T.jsxs)(`button`,{className:`tasks-btn-secondary tasks-btn-action`,"aria-label":`Complete task: ${e.name}`,disabled:l||e.running,title:e.running?`Stop the timer before completing`:void 0,onClick:()=>V(e.taskId),children:[(0,T.jsx)(c,{size:14}),` Complete`]}),Q(e)?null:e.running?(0,T.jsxs)(`button`,{className:`admin-btn-danger tasks-btn-action`,disabled:l,onClick:()=>void X(`/api/admin/task-timer-stop`,e.taskId),children:[(0,T.jsx)(u,{size:14}),` Stop`]}):(0,T.jsxs)(`button`,{className:`admin-btn-cta tasks-btn-action`,disabled:l,onClick:()=>void X(`/api/admin/task-timer-start`,e.taskId),children:[(0,T.jsx)(p,{size:14}),` Start`]})]})})]},e.rowKey))]}):(0,T.jsxs)(`section`,{className:`admin-card tasks-card`,children:[(0,T.jsxs)(`div`,{className:`tasks-card-head`,children:[(0,T.jsx)(`span`,{className:`tasks-card-title`,children:`Completed`}),(0,T.jsxs)(`span`,{className:`tasks-card-count`,children:[J.length,` done`]})]}),J.length===0&&(0,T.jsx)(`div`,{className:`tasks-empty`,children:`Nothing completed yet.`}),J.map(e=>(0,T.jsxs)(`div`,{className:`tasks-row tasks-row-done`,children:[(0,T.jsx)(`button`,{className:`tasks-row-open`,"aria-label":`Open task detail: ${e.name}`,onClick:()=>z(e.rowKey),children:(0,T.jsxs)(`div`,{className:`tasks-row-main`,children:[(0,T.jsx)(`div`,{className:`tasks-row-name`,children:e.name}),(0,T.jsx)(`div`,{className:`tasks-row-sub`,children:j(e,O(e))})]})}),(0,T.jsx)(`div`,{className:`tasks-row-elapsed`,children:m(e.secondsLogged)}),(0,T.jsx)(`div`,{className:`tasks-row-controls`,children:e.taskId===null?(0,T.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`}):$(e,e.taskId)})]},e.rowKey))]})]})]})}function I({cacheKey:e}){let{adminFetch:t}=i({initialCacheKey:e,surface:`tasks`});return(0,T.jsx)(F,{adminFetch:t})}function L(){let[e,t]=(0,_.useState)(null),[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(void 0),[s,c]=(0,_.useState)(null),[u,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(null),[g,v]=(0,_.useState)(null);(0,_.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(D)}catch{}if(!n){t(null),i(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async r=>{if(!e){if(r.status===401){try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`;return}if(r.ok)try{let e=await r.json();typeof e.businessName==`string`&&o(e.businessName),e.sessionId!==void 0&&c(e.sessionId??null),p(e.role??null),h(e.userName===void 0?null:e.userName),v(e.avatar??null)}catch{}t(n),i(!0)}}).catch(()=>{e||(t(n),i(!0))}),()=>{e=!0}},[]);let y=(0,_.useCallback)(()=>{try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`},[]),[b,x]=(0,_.useState)(!1),S=(0,_.useCallback)(async()=>{x(!0);try{let e=await d();if(e){try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`}return e}finally{x(!1)}},[]);return r?e?(0,T.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(D)}catch{}window.location.href=`/`},children:(0,T.jsx)(f,{cacheKey:e,businessName:a,sessionId:s,onLogout:y,onDisconnect:S,disconnecting:b,userName:m,userAvatar:g,role:u,children:(0,T.jsx)(I,{cacheKey:e})})}):(0,T.jsx)(`div`,{className:`tasks-page`,children:(0,T.jsxs)(`div`,{className:`tasks-empty`,children:[(0,T.jsx)(`p`,{children:`You are not signed in.`}),(0,T.jsxs)(`p`,{children:[`Open the `,(0,T.jsx)(`a`,{href:`/`,className:`tasks-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,T.jsx)(n,{surface:`gate`})}(0,g.createRoot)(document.getElementById(`root`)).render((0,T.jsx)(L,{}));
@@ -1 +1 @@
1
- import{P as e}from"./useSubAccountSwitcher-DVmWZxar.js";var t=e(`play`,[[`path`,{d:`M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z`,key:`10ikf1`}]]);function n(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`)}`}export{t as n,n as t};
1
+ import{P as e}from"./useSubAccountSwitcher-6AFuRawP.js";var t=e(`play`,[[`path`,{d:`M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z`,key:`10ikf1`}]]);function n(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`)}`}export{t as n,n as t};
@@ -1 +1 @@
1
- import{P as e}from"./useSubAccountSwitcher-DVmWZxar.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{P as e}from"./useSubAccountSwitcher-6AFuRawP.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{G as t,r as n}from"./useSubAccountSwitcher-DVmWZxar.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{G as t,r as n}from"./useSubAccountSwitcher-6AFuRawP.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};