@rubytech/create-maxy-code 0.1.506 → 0.1.507

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 (104) hide show
  1. package/package.json +2 -2
  2. package/payload/platform/config/brand.json +79 -18
  3. package/payload/platform/lib/account-schema-regions/dist/index.d.ts +17 -5
  4. package/payload/platform/lib/account-schema-regions/dist/index.d.ts.map +1 -1
  5. package/payload/platform/lib/account-schema-regions/dist/index.js +20 -6
  6. package/payload/platform/lib/account-schema-regions/dist/index.js.map +1 -1
  7. package/payload/platform/lib/account-schema-regions/src/index.ts +20 -6
  8. package/payload/platform/plugins/admin/PLUGIN.md +36 -0
  9. package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +48 -2
  10. package/payload/platform/plugins/admin/skills/whats-new/SKILL.md +7 -0
  11. package/payload/platform/plugins/aeo/PLUGIN.md +3 -0
  12. package/payload/platform/plugins/browser/PLUGIN.md +18 -0
  13. package/payload/platform/plugins/connector/PLUGIN.md +4 -0
  14. package/payload/platform/plugins/contacts/PLUGIN.md +9 -0
  15. package/payload/platform/plugins/docs/references/admin-ui.md +21 -1
  16. package/payload/platform/plugins/docs/references/plugins-guide.md +26 -0
  17. package/payload/platform/plugins/email/PLUGIN.md +17 -0
  18. package/payload/platform/plugins/filesystem/PLUGIN.md +6 -0
  19. package/payload/platform/plugins/google/PLUGIN.md +12 -0
  20. package/payload/platform/plugins/graph/PLUGIN.md +3 -0
  21. package/payload/platform/plugins/graph-viewer/PLUGIN.md +1 -0
  22. package/payload/platform/plugins/ledger/PLUGIN.md +7 -0
  23. package/payload/platform/plugins/memory/PLUGIN.md +41 -0
  24. package/payload/platform/plugins/outlook/PLUGIN.md +24 -0
  25. package/payload/platform/plugins/quickbooks/PLUGIN.md +15 -0
  26. package/payload/platform/plugins/replicate/PLUGIN.md +3 -0
  27. package/payload/platform/plugins/scheduling/PLUGIN.md +10 -0
  28. package/payload/platform/plugins/storage-broker/PLUGIN.md +12 -0
  29. package/payload/platform/plugins/telegram/PLUGIN.md +3 -0
  30. package/payload/platform/plugins/url-get/PLUGIN.md +1 -0
  31. package/payload/platform/plugins/voice-mirror/PLUGIN.md +5 -0
  32. package/payload/platform/plugins/whatsapp/PLUGIN.md +12 -0
  33. package/payload/platform/plugins/work/PLUGIN.md +15 -0
  34. package/payload/platform/plugins/workflows/PLUGIN.md +8 -0
  35. package/payload/platform/scripts/check-risk-class.mjs +145 -0
  36. package/payload/platform/scripts/lib/__pycache__/account-schema-owned-dirs.cpython-314.pyc +0 -0
  37. package/payload/platform/scripts/lib/provision-account-dir.sh +4 -1
  38. package/payload/platform/services/claude-session-manager/dist/http-server.d.ts.map +1 -1
  39. package/payload/platform/services/claude-session-manager/dist/http-server.js +4 -0
  40. package/payload/platform/services/claude-session-manager/dist/http-server.js.map +1 -1
  41. package/payload/platform/services/claude-session-manager/dist/index.js +8 -0
  42. package/payload/platform/services/claude-session-manager/dist/index.js.map +1 -1
  43. package/payload/platform/services/claude-session-manager/dist/tool-surface.d.ts +13 -0
  44. package/payload/platform/services/claude-session-manager/dist/tool-surface.d.ts.map +1 -1
  45. package/payload/platform/services/claude-session-manager/dist/tool-surface.js +33 -8
  46. package/payload/platform/services/claude-session-manager/dist/tool-surface.js.map +1 -1
  47. package/payload/server/{chunk-5ADBNEJA.js → chunk-2WAXM5N2.js} +111 -111
  48. package/payload/server/maxy-edge.js +1 -1
  49. package/payload/server/public/activity.html +5 -5
  50. package/payload/server/public/agents.html +4 -4
  51. package/payload/server/public/assets/{AdminLoginScreens-D5KOQA8S.js → AdminLoginScreens-YT7jsh_H.js} +1 -1
  52. package/payload/server/public/assets/{AdminShell-C8wazpnz.js → AdminShell-Ckht9hmU.js} +1 -1
  53. package/payload/server/public/assets/{activity-CFqkDhTs.js → activity-DH3Wgc3O.js} +1 -1
  54. package/payload/server/public/assets/admin-DetvulAu.js +1 -0
  55. package/payload/server/public/assets/{agents-DPulfmrd.js → agents-X_IvDHLZ.js} +1 -1
  56. package/payload/server/public/assets/{browser-T_5xbnJh.js → browser-Bym8QhfA.js} +1 -1
  57. package/payload/server/public/assets/{calendar-CKjuiG8c.js → calendar-CFnufJOy.js} +1 -1
  58. package/payload/server/public/assets/chat-wrckyIpw.js +1 -0
  59. package/payload/server/public/assets/chevron-left-Dtk3jEK5.js +1 -0
  60. package/payload/server/public/assets/chevron-right-Dih6IZ8B.js +1 -0
  61. package/payload/server/public/assets/clock-iJCrrmWM.js +1 -0
  62. package/payload/server/public/assets/data-D76--TYs.js +1 -0
  63. package/payload/server/public/assets/{file-text-c6cA4Evd.js → file-text-zch0E1GJ.js} +1 -1
  64. package/payload/server/public/assets/{graph-DIk-o45J.js → graph-BavHLzpV.js} +1 -1
  65. package/payload/server/public/assets/{graph-labels-5bjxhC_p.js → graph-labels-CBwh4g-6.js} +1 -1
  66. package/payload/server/public/assets/{maximize-2-BCQkFb1_.js → maximize-2-bTn_Ozpi.js} +1 -1
  67. package/payload/server/public/assets/{operator-0UnNo2ms.js → operator-a4IOwf62.js} +1 -1
  68. package/payload/server/public/assets/page-3T2mE63b.js +1 -0
  69. package/payload/server/public/assets/{page-HVtUfub2.js → page-D6M1CmPe.js} +4 -4
  70. package/payload/server/public/assets/{public-CKEYyIPn.js → public-B3y_YU1G.js} +1 -1
  71. package/payload/server/public/assets/{rotate-ccw-dTpO5dhL.js → rotate-ccw-BGvzNB1b.js} +1 -1
  72. package/payload/server/public/assets/{routines-C6P1-Dto.js → routines-C7Dr16am.js} +1 -1
  73. package/payload/server/public/assets/{skills-ClrpVqlz.js → skills-DFeb3XO3.js} +1 -1
  74. package/payload/server/public/assets/{tasks-C8SNhSFC.js → tasks-CSfnCKJe.js} +1 -1
  75. package/payload/server/public/assets/{time-entry-format-CCO6N6XZ.js → time-entry-format-BgZqOOqG.js} +1 -1
  76. package/payload/server/public/assets/{triangle-alert-CHjdKpag.js → triangle-alert-DBJ7xz_t.js} +1 -1
  77. package/payload/server/public/assets/{useCopyFeedback-BTUu3-l8.js → useCopyFeedback-BFOujMl-.js} +1 -1
  78. package/payload/server/public/assets/useSubAccountSwitcher-BkQ5tA8A.css +1 -0
  79. package/payload/server/public/assets/{useVoiceRecorder-BeNqxmm2.js → useVoiceRecorder-BP6CpYQD.js} +1 -1
  80. package/payload/server/public/assets/{wrench-CeNnc7oO.js → wrench-DdaRhfzS.js} +1 -1
  81. package/payload/server/public/brand/fonts/inter-400.woff2 +0 -0
  82. package/payload/server/public/brand/fonts/inter-500.woff2 +0 -0
  83. package/payload/server/public/brand-defaults.css +47 -4
  84. package/payload/server/public/browser.html +4 -4
  85. package/payload/server/public/calendar.html +7 -7
  86. package/payload/server/public/chat.html +13 -13
  87. package/payload/server/public/data.html +11 -11
  88. package/payload/server/public/graph.html +9 -9
  89. package/payload/server/public/index.html +14 -14
  90. package/payload/server/public/operator.html +14 -14
  91. package/payload/server/public/public.html +13 -13
  92. package/payload/server/public/routines.html +6 -6
  93. package/payload/server/public/skills.html +5 -5
  94. package/payload/server/public/tasks.html +6 -6
  95. package/payload/server/server.js +702 -586
  96. package/payload/server/public/assets/admin-B-EGUWS4.js +0 -1
  97. package/payload/server/public/assets/chat-DWLYAA70.js +0 -1
  98. package/payload/server/public/assets/chevron-left-DBMCTKlT.js +0 -1
  99. package/payload/server/public/assets/chevron-right-SBAr6zzc.js +0 -1
  100. package/payload/server/public/assets/clock-kkzt7Scf.js +0 -1
  101. package/payload/server/public/assets/data-CV8N9qcy.js +0 -1
  102. package/payload/server/public/assets/page-JJa2xdzf.js +0 -1
  103. package/payload/server/public/assets/useSubAccountSwitcher-DyrH8DA8.css +0 -1
  104. /package/payload/server/public/assets/{useSubAccountSwitcher-DSW9vDi2.js → useSubAccountSwitcher-0PfRrN6i.js} +0 -0
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{B as t,F as n,K as r,N as i,U as a,W as o,n as s,p as c}from"./useSubAccountSwitcher-DSW9vDi2.js";import{C as l,T as u,t as d,w as f}from"./AdminShell-C8wazpnz.js";import{t as p}from"./triangle-alert-CHjdKpag.js";var m=o(),h=e(r(),1),g=t(),_=`—`;function v(e){switch(e){case`waiting`:return`Waiting`;case`never-run`:return`Never run`;case`never-succeeded`:return`Never succeeded`;case`failing`:return`Failing`;case`stalled`:return`Stalled`;case`running`:return`Running`;case`ok`:return`Healthy`}}var y={waiting:`Armed and not due yet. It has no start-up run and its first interval has not elapsed, so it has correctly not fired.`,"never-run":`Its interval has elapsed and it still has not fired once. This is not the same as waiting its turn.`,"never-succeeded":`It has fired, and not one run has finished. The work this loop exists to do has never happened.`,failing:`It worked before and is failing now.`,stalled:`It has not started within three of its own intervals. Something is holding it up.`,running:`A run is in progress right now.`,ok:`The last run finished and the next is due within the interval.`},b=new Set([`never-run`,`never-succeeded`,`failing`,`stalled`]),x=10;function S(e){return e===null||!Number.isFinite(e)?_:`${e.toFixed(1)}%`}function C(e){return e<6e4?`${Math.round(e/1e3)}s`:e<36e5?`${Math.round(e/6e4)}m`:`${Math.round(e/36e5)}h`}function w(e,t){if(e===null)return _;let n=t-e;return n<0?`in ${C(-n)}`:n<6e4?`${Math.round(n/1e3)}s ago`:n<36e5?`${Math.round(n/6e4)}m ago`:`${Math.round(n/36e5)}h ago`}function T(e,t){if(e===null)return _;let n=e-t;return n>=0?`in ${C(n)}`:`overdue by ${C(-n)}`}function E({loops:e,nowMs:t=Date.now()}){let[n,r]=(0,h.useState)(!1);if(!e)return(0,g.jsxs)(`section`,{className:`activity-loops`,children:[(0,g.jsx)(`h2`,{className:`activity-loops-heading`,children:`Scheduled work`}),(0,g.jsx)(`p`,{className:`activity-loops-empty`,children:`Scheduled work could not be read from the server.`})]});let i=e.armed-e.rows.length,a=e.rows.filter(e=>b.has(e.state)),o=e.rows.filter(e=>!b.has(e.state)&&typeof e.cpuPct==`number`&&e.cpuPct>=x),s=n?e.rows:[...a,...o];return(0,g.jsxs)(`section`,{className:`activity-loops`,children:[(0,g.jsx)(`h2`,{className:`activity-loops-heading`,children:`Scheduled work`}),(0,g.jsxs)(`p`,{className:`activity-loops-sub`,children:[e.armed,` `,e.armed===1?`loop`:`loops`,` armed`,a.length>0?` · ${a.length} ${a.length===1?`needs`:`need`} attention`:` · all healthy`,o.length>0&&` · ${o.length} using significant processor`,`. `,(0,g.jsx)(`button`,{type:`button`,className:`activity-loops-toggle`,"aria-expanded":n,onClick:()=>r(e=>!e),children:n?`Show less`:`Show all`})]}),typeof e.processPct==`number`&&(0,g.jsxs)(`p`,{className:`activity-loops-cpu`,children:[`Server process at `,e.processPct.toFixed(1),`% of one core`,typeof e.attributedPct==`number`&&(0,g.jsxs)(g.Fragment,{children:[` · these loops explain `,e.attributedPct.toFixed(1),`%`]}),typeof e.unattributedPct==`number`&&e.unattributedPct>=1&&(0,g.jsxs)(g.Fragment,{children:[` · `,(0,g.jsxs)(`strong`,{children:[e.unattributedPct.toFixed(1),`% is not from these loops`]})]})]}),i>0&&(0,g.jsxs)(`p`,{className:`activity-loops-omission`,role:`status`,children:[i,` armed `,i===1?`loop is`:`loops are`,` missing from this list. The server armed `,e.armed,` but sent `,e.rows.length,`.`]}),s.length===0?null:(0,g.jsx)(`div`,{className:`activity-table-scroll`,children:(0,g.jsxs)(`table`,{className:`activity-table`,children:[(0,g.jsx)(`thead`,{children:(0,g.jsxs)(`tr`,{children:[(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Loop`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`State`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Every`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Last run`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Last OK`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Took`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`CPU`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Runs`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Produced`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Next due`})]})}),(0,g.jsx)(`tbody`,{children:s.map(e=>(0,g.jsxs)(`tr`,{className:b.has(e.state)?`activity-loop-row activity-loop-unhealthy`:`activity-loop-row`,children:[(0,g.jsx)(`td`,{className:`activity-td`,children:e.name}),(0,g.jsx)(`td`,{className:`activity-td`,title:y[e.state],children:(0,g.jsxs)(`span`,{className:`activity-state`,children:[(0,g.jsx)(`span`,{className:e.state===`ok`?`activity-state-dot is-healthy`:b.has(e.state)?`activity-state-dot is-unhealthy`:`activity-state-dot`,"aria-hidden":`true`}),v(e.state)]})}),(0,g.jsx)(`td`,{className:`activity-td activity-num`,children:C(e.intervalMs)}),(0,g.jsx)(`td`,{className:`activity-td activity-num`,children:w(e.lastStartMs,t)}),(0,g.jsx)(`td`,{className:`activity-td activity-num`,children:w(e.lastSuccessMs,t)}),(0,g.jsx)(`td`,{className:`activity-td activity-num`,children:e.lastDurationMs===null?_:`${e.lastDurationMs} ms`}),(0,g.jsx)(`td`,{className:`activity-td activity-num`,title:e.cpuAttributable?e.detached?`Includes the processor time of the separate process this loop starts.`:void 0:`This loop waits on other work while it runs, so the processor time it uses cannot be separated from the rest of the server.`,children:S(e.cpuPct)}),(0,g.jsxs)(`td`,{className:`activity-td activity-num`,children:[e.successCount,`/`,e.runCount]}),(0,g.jsx)(`td`,{className:`activity-td activity-loop-note`,children:(0,g.jsx)(`span`,{className:`activity-loop-note-text`,title:e.lastError??e.lastNote??void 0,children:e.lastError??e.lastNote??_})}),(0,g.jsx)(`td`,{className:`activity-td activity-num`,children:T(e.nextDueMs,t)})]},e.name))})]})}),(0,g.jsxs)(`dl`,{className:`activity-legend`,children:[(0,g.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,g.jsx)(`dt`,{className:`activity-legend-term`,children:`Runs`}),(0,g.jsx)(`dd`,{className:`activity-legend-def`,children:`Finished runs out of attempted runs since the server started. 0 out of a large number means it has tried many times and never once finished.`})]}),(0,g.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,g.jsx)(`dt`,{className:`activity-legend-term`,children:`CPU`}),(0,g.jsx)(`dd`,{className:`activity-legend-def`,children:`Share of one processor core this loop is using, measured between the last two refreshes. It includes any separate process the loop starts, and can pass 100% because those run alongside each other. A dash means it could not be measured: the loop waits on other work while it runs, so its share cannot be separated from the rest of the server.`})]}),(0,g.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,g.jsx)(`dt`,{className:`activity-legend-term`,children:_}),(0,g.jsx)(`dd`,{className:`activity-legend-def`,children:`Not measured. It does not mean zero.`})]})]})]})}var D=`maxy-admin-session-key`;function O(e){switch(e.costUnavailable){case`metering-failed`:return`Cost could not be calculated: ${e.meteringError??`the transcript could not be read`}`;case`model-not-priced`:return`No published price for this model, so cost cannot be estimated.`;case`no-transcript`:return`This session has no transcript yet, so there is nothing to cost.`;default:return}}var k=[{key:`lastMessageAt`,label:`Last activity`,dir:-1},{key:`activeMsInRange`,label:`Active time`,dir:-1},{key:`costGbp`,label:`Cost`,dir:-1},{key:`accountId`,label:`Account name`,dir:1}],A=[{key:`title`,label:`Session`,help:`The conversation name, or its short id when it has none yet.`},{key:`model`,label:`Model`,help:`The model that answered the most recent turn.`},{key:`status`,label:`Status`,help:`What the process is doing right now.`},{key:`activeMsInRange`,label:`Active`,help:`Time this session spent thinking, writing and running tools inside the selected range. This is worked time, not elapsed time.`},{key:`ageMs`,label:`Age`,help:`How long ago this conversation started. Wall-clock, so it counts every hour nobody was working.`},{key:`lastMessageAt`,label:`Last activity`,help:`The clock time of the most recent message, in your timezone. A date appears once it is not today.`},{key:`turnCount`,label:`Turns`,help:`Messages exchanged. A trailing + means the count is a minimum — the conversation is too long to count exactly.`},{key:`rssKb`,label:`RAM`,help:`Memory held by this session and all its helper processes together.`},{key:`cpuPct`,label:`CPU (avg)`,help:`AVERAGE share of one processor core over the last census interval, up to 60 seconds. It is not a reading of this instant, so a session that answered a turn a minute ago still shows a high figure while sitting quiet now. Can exceed 100% because a session runs many processes at once.`},{key:`tokensInRange`,label:`Tokens`,help:`Total tokens billed inside the selected range, added up across every day in it. A cumulative total, not the size of the conversation the model currently reads back.`},{key:`costGbp`,label:`Cost`,help:`Estimated spend inside the selected range, at published prices for this model.`}],j=[`activeMsInRange`,`lastMessageAt`,`cpuPct`,`tokensInRange`],M={label:`Account`,help:`The business this session belongs to. "untagged" means the session records no account.`};function N(e,t){let n=t?.[e];return n&&n.trim()!==``?n:e.slice(0,8)}var P=`—`;function F(e){if(e===null||!Number.isFinite(e)||e<0)return P;let t=Math.floor(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);if(n<60)return`${n}m`;let r=Math.floor(n/60);return r<24?`${r}h ${n%60}m`:`${Math.floor(r/24)}d ${r%24}h`}function I(e){return e===null||!Number.isFinite(e)?P:`${(e/1024/1024).toFixed(1)} GB`}function L(e,t){if(!e)return P;let n=Date.parse(e);if(!Number.isFinite(n))return P;let r=new Date(n),i=new Date(t),a=`${String(r.getHours()).padStart(2,`0`)}:${String(r.getMinutes()).padStart(2,`0`)}`;return r.getFullYear()===i.getFullYear()&&r.getMonth()===i.getMonth()&&r.getDate()===i.getDate()?a:`${r.getDate()} ${r.toLocaleString(`en-GB`,{month:`short`})} ${a}`}function R(e){return e===null||!Number.isFinite(e)?P:`${e.toFixed(1)}%`}function z(e){return e===null||!Number.isFinite(e)?P:e<1e3?String(e):e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(2)}M`}function B(e){return e===null||!Number.isFinite(e)?P:`£${e.toFixed(2)}`}function V(e){if(e===null||!Number.isFinite(e)||e<0)return P;let t=Math.floor(e/6e4);return`${Math.floor(t/60)}h ${t%60}m`}function H(e,t,n,r){let i=e[n],a=t[n];if(i===null&&a===null)return 0;if(i===null)return 1;if(a===null)return-1;if(n===`lastMessageAt`){let e=Date.parse(String(i)),t=Date.parse(String(a));return!Number.isFinite(e)&&!Number.isFinite(t)?0:Number.isFinite(e)?Number.isFinite(t)?(e-t)*r:-1:1}return typeof i==`number`&&typeof a==`number`?(i-a)*r:String(i).localeCompare(String(a))*r}function U(e){return e.toISOString().slice(0,10)}function W(e){let t=e.getUTCFullYear(),n=e.getUTCMonth();return{from:U(new Date(Date.UTC(t,n,1))),to:U(new Date(Date.UTC(t,n+1,0)))}}function G(e,t){let n=new Date(`${e}T00:00:00.000Z`);return W(new Date(Date.UTC(n.getUTCFullYear(),n.getUTCMonth()+t,1)))}function ee(e,t){return{from:U(new Date(t-(e-1)*864e5)),to:U(new Date(t))}}function K(e){return new Date(`${e}T00:00:00.000Z`).toLocaleString(`en-GB`,{month:`long`,year:`numeric`,timeZone:`UTC`})}function q(e){if(e===null)return!1;let t=W(new Date(`${e.from}T00:00:00.000Z`));return t.from===e.from&&t.to===e.to}function J(e,t,n){switch(e){case`title`:return t.title??t.sessionId.slice(0,8);case`model`:return t.model??P;case`status`:return t.status??P;case`activeMsInRange`:return V(t.activeMsInRange);case`ageMs`:return F(t.ageMs);case`lastMessageAt`:return L(t.lastMessageAt,n);case`turnCount`:return t.turnCount===null?P:`${t.turnCount}${t.turnCountCapped?`+`:``}`;case`rssKb`:return I(t.rssKb);case`cpuPct`:return R(t.cpuPct);case`tokensInRange`:return z(t.tokensInRange);case`costGbp`:return B(t.costGbp);default:return P}}function Y({adminFetch:e,cacheKey:t}){let[r,a]=(0,h.useState)(null),[o,c]=(0,h.useState)(null),[u,d]=(0,h.useState)(!1),[m,_]=(0,h.useState)(`lastMessageAt`),[v,y]=(0,h.useState)(-1),[b,x]=(0,h.useState)(()=>W(new Date)),[S,C]=(0,h.useState)(!0),[w,T]=(0,h.useState)(!0),[D,I]=(0,h.useState)(!1),L=(0,h.useCallback)(async(e,n)=>{t&&await s(t,e)&&(console.info(`[admin-ui] activity-card-open account=${e.slice(0,8)} session=${n.slice(0,8)}`),window.location.assign(`/chat?session=${encodeURIComponent(n)}`))},[t]),R=(0,h.useRef)(!1),z=(0,h.useRef)(void 0),B=(0,h.useCallback)(async t=>{if(R.current){z.current=t;return}R.current=!0;try{let n=await e(`/api/admin/activity${t?`?from=${t.from}&to=${t.to}`:``}`);if(n.status===403){c(`This view is available to the house account only.`),d(!0);return}if(!n.ok){c(`The session manager did not answer (status ${n.status}).`),d(!0);return}a(await n.json()),c(null)}catch(e){c(e instanceof Error?e.message:String(e))}finally{d(!0),R.current=!1;let e=z.current;z.current=void 0,e!==void 0&&B(e)}},[e]);(0,h.useEffect)(()=>{B(b);let e=setInterval(()=>void B(b),15e3);return()=>clearInterval(e)},[B,b]);let V=(0,h.useMemo)(()=>r?[...r.rows].sort((e,t)=>H(e,t,m,v)):[],[r,m,v]),U=(0,h.useMemo)(()=>V.filter(e=>e.status===`busy`?S:e.status===`idle`?w:!0),[V,S,w]),Y=V.length-U.length;if(!u)return(0,g.jsx)(n,{surface:`gate`});if(o)return(0,g.jsx)(`div`,{className:`activity-empty`,children:o});if(!r)return(0,g.jsx)(`div`,{className:`activity-empty`,children:`No response.`});let{accounts:X,census:Z,censusAgeMs:Q}=r,te=Date.now(),ne=X.onDisk!==null&&X.onDisk>X.valid,$=r.range===void 0?b:r.range;return(0,g.jsxs)(`div`,{className:`activity-body`,children:[(0,g.jsxs)(`div`,{className:`activity-head`,children:[(0,g.jsxs)(`span`,{className:`activity-title`,children:[(0,g.jsx)(i,{size:16}),` Live sessions`]}),(0,g.jsxs)(`span`,{className:`activity-meta`,children:[Y>0?`${U.length} of ${V.length} live · ${Y} hidden`:`${V.length} live`,` · `,X.valid,` accounts`,X.untaggedCount>0?` · ${X.untaggedCount} untagged`:``]})]}),(0,g.jsxs)(`div`,{className:`activity-controls`,children:[(0,g.jsxs)(`div`,{className:`activity-control activity-range`,children:[(0,g.jsx)(l,{variant:`secondary`,size:`sm`,"aria-label":`Previous month`,disabled:!q(b),onClick:()=>x(e=>e&&G(e.from,-1)),children:`‹`}),(0,g.jsx)(`span`,{className:`activity-range-label`,children:b===null?`All time`:q(b)?K(b.from):`${b.from} → ${b.to}`}),(0,g.jsx)(l,{variant:`secondary`,size:`sm`,"aria-label":`Next month`,disabled:!q(b),onClick:()=>x(e=>e&&G(e.from,1)),children:`›`})]}),(0,g.jsxs)(`div`,{className:`activity-control activity-presets`,children:[(0,g.jsx)(l,{variant:`secondary`,size:`sm`,"aria-pressed":b!==null&&q(b)&&b.from===W(new Date).from,onClick:()=>x(W(new Date)),children:`This month`}),(0,g.jsx)(l,{variant:`secondary`,size:`sm`,"aria-pressed":b!==null&&!q(b),onClick:()=>x(ee(7,Date.now())),children:`Last 7 days`}),(0,g.jsx)(l,{variant:`secondary`,size:`sm`,"aria-pressed":b===null,onClick:()=>x(null),children:`All time`})]}),(0,g.jsxs)(`div`,{className:`activity-control`,children:[(0,g.jsx)(`label`,{className:`activity-control-label`,htmlFor:`activity-sort`,children:`Sort by`}),(0,g.jsx)(`span`,{className:`activity-select-wrap`,children:(0,g.jsx)(`select`,{id:`activity-sort`,className:`activity-select`,value:m,onChange:e=>{let t=k.find(t=>t.key===e.target.value);t&&(_(t.key),y(t.dir))},children:k.map(e=>(0,g.jsx)(`option`,{value:e.key,children:e.label},e.key))})})]}),(0,g.jsxs)(`div`,{className:`activity-control activity-visibility`,children:[(0,g.jsx)(f,{checked:S,onChange:C,label:`Busy`}),(0,g.jsx)(f,{checked:w,onChange:T,label:`Idle`})]})]}),(0,g.jsxs)(`div`,{className:`activity-range-note`,children:[$===null?`Active time, tokens and cost cover each conversation’s whole history.`:`Active time, tokens and cost cover ${$.from} to ${$.to} (UTC), inclusive.`,r.fullRangeFallback&&(0,g.jsxs)(`strong`,{className:`activity-range-rejected`,children:[` `,`The range was not accepted, so these are all-time figures.`]})]}),(0,g.jsx)(`div`,{className:`activity-census`,children:Z===null?`No census collected yet, so memory and CPU are unavailable.`:`Memory and CPU measured ${F(Q)} ago, averaged over the minute before that · ${Z.cpuNull} of ${Z.live} without a CPU reading`}),ne&&(0,g.jsxs)(`div`,{className:`activity-warning`,children:[(0,g.jsx)(p,{size:14}),` `,X.onDisk,` account folders on disk but only`,` `,X.valid,` are readable. Sessions belonging to the rest cannot be attributed.`]}),V.length===0?(0,g.jsx)(`div`,{className:`activity-empty`,children:`No sessions are running.`}):U.length===0?(0,g.jsxs)(`div`,{className:`activity-empty`,children:[`All `,V.length,` running sessions are hidden by the Busy and Idle filters.`]}):(0,g.jsx)(`div`,{className:`activity-grid`,children:U.map(e=>{let n=e.accountId!==null&&!!t,r=n?()=>void L(e.accountId,e.sessionId):void 0;return(0,g.jsxs)(`article`,{className:`activity-card${n?` activity-card-clickable`:``}`,"data-testid":`activity-card`,"data-session-id":e.sessionId,role:n?`button`:void 0,tabIndex:n?0:void 0,onClick:r,onKeyDown:n?e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),r())}:void 0,children:[(0,g.jsx)(`h3`,{className:`activity-card-heading`,title:e.accountId??void 0,children:e.accountId===null?(0,g.jsx)(`span`,{className:`activity-untagged`,title:`This session records no account, so it cannot be attributed to a business.`,children:`untagged`}):N(e.accountId,X.names)}),(0,g.jsx)(`dl`,{className:`activity-card-rows`,children:A.map(t=>(0,g.jsxs)(`div`,{className:`activity-card-row`,children:[(0,g.jsx)(`dt`,{className:`activity-card-label`,"data-testid":`activity-card-label`,title:t.help,children:t.label}),(0,g.jsx)(`dd`,{className:`activity-card-value`,title:t.key===`costGbp`?O(e):void 0,children:J(t.key,e,te)})]},t.key))})]},e.sessionId)})}),V.length>0&&(0,g.jsxs)(`div`,{className:`activity-glossary`,children:[(0,g.jsxs)(`dl`,{className:`activity-legend`,children:[D&&(0,g.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,g.jsx)(`dt`,{className:`activity-legend-term`,"data-testid":`activity-glossary-term`,children:M.label}),(0,g.jsx)(`dd`,{className:`activity-legend-def`,children:M.help})]},`heading`),(D?A:A.filter(e=>j.includes(e.key))).map(e=>(0,g.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,g.jsx)(`dt`,{className:`activity-legend-term`,"data-testid":`activity-glossary-term`,children:e.label}),(0,g.jsx)(`dd`,{className:`activity-legend-def`,children:e.help})]},e.key)),(0,g.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,g.jsx)(`dt`,{className:`activity-legend-term`,children:P}),(0,g.jsxs)(`dd`,{className:`activity-legend-def`,children:[`Not measured. It does not mean zero — a measured zero is written as a figure, so `,(0,g.jsx)(`em`,{children:`0h 0m`}),` and `,(0,g.jsx)(`em`,{children:`£0.00`}),` are real readings. Hover a dashed value for the reason where one exists.`]})]})]}),(0,g.jsx)(l,{variant:`secondary`,size:`sm`,className:`activity-glossary-toggle`,onClick:()=>I(e=>!e),children:D?`Show fewer`:`Explain every figure`})]}),(0,g.jsx)(E,{loops:r?.loops})]})}function X({cacheKey:e}){let{adminFetch:t}=a({initialCacheKey:e,surface:`activity`});return(0,g.jsx)(Y,{adminFetch:t,cacheKey:e})}function Z(){let[e,t]=(0,h.useState)(null),[r,i]=(0,h.useState)(!1),[a,o]=(0,h.useState)(void 0),[s,l]=(0,h.useState)(null),[f,p]=(0,h.useState)(null),[m,_]=(0,h.useState)(null),[v,y]=(0,h.useState)(null);(0,h.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(D)}catch{}if(!n){t(null),i(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async r=>{if(!e){if(r.status===401){try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`;return}if(r.ok)try{let e=await r.json();typeof e.businessName==`string`&&o(e.businessName),e.sessionId!==void 0&&l(e.sessionId??null),p(e.role??null),_(e.userName===void 0?null:e.userName),y(e.avatar??null)}catch{}t(n),i(!0)}}).catch(()=>{e||(t(n),i(!0))}),()=>{e=!0}},[]);let b=(0,h.useCallback)(()=>{try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`},[]),[x,S]=(0,h.useState)(!1),C=(0,h.useCallback)(async()=>{S(!0);try{let e=await u();if(e){try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`}return e}finally{S(!1)}},[]);return r?e?(0,g.jsx)(c,{cacheKey:e,surface:`activity`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=activity`);try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`},children:(0,g.jsx)(d,{cacheKey:e,businessName:a,sessionId:s,onLogout:b,onDisconnect:C,disconnecting:x,userName:m,userAvatar:v,role:f,children:(0,g.jsx)(X,{cacheKey:e})})}):(0,g.jsx)(`div`,{className:`activity-page`,children:(0,g.jsxs)(`div`,{className:`activity-empty`,children:[(0,g.jsx)(`p`,{children:`You are not signed in.`}),(0,g.jsxs)(`p`,{children:[`Open the `,(0,g.jsx)(`a`,{href:`/`,className:`activity-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,g.jsx)(n,{surface:`gate`})}(0,m.createRoot)(document.getElementById(`root`)).render((0,g.jsx)(Z,{}));
1
+ import{o as e}from"./chunk-CltuBf4Z.js";import{B as t,F as n,K as r,N as i,U as a,W as o,n as s,p as c}from"./useSubAccountSwitcher-0PfRrN6i.js";import{C as l,T as u,t as d,w as f}from"./AdminShell-Ckht9hmU.js";import{t as p}from"./triangle-alert-DBJ7xz_t.js";var m=o(),h=e(r(),1),g=t(),_=`—`;function v(e){switch(e){case`waiting`:return`Waiting`;case`never-run`:return`Never run`;case`never-succeeded`:return`Never succeeded`;case`failing`:return`Failing`;case`stalled`:return`Stalled`;case`running`:return`Running`;case`ok`:return`Healthy`}}var y={waiting:`Armed and not due yet. It has no start-up run and its first interval has not elapsed, so it has correctly not fired.`,"never-run":`Its interval has elapsed and it still has not fired once. This is not the same as waiting its turn.`,"never-succeeded":`It has fired, and not one run has finished. The work this loop exists to do has never happened.`,failing:`It worked before and is failing now.`,stalled:`It has not started within three of its own intervals. Something is holding it up.`,running:`A run is in progress right now.`,ok:`The last run finished and the next is due within the interval.`},b=new Set([`never-run`,`never-succeeded`,`failing`,`stalled`]),x=10;function S(e){return e===null||!Number.isFinite(e)?_:`${e.toFixed(1)}%`}function C(e){return e<6e4?`${Math.round(e/1e3)}s`:e<36e5?`${Math.round(e/6e4)}m`:`${Math.round(e/36e5)}h`}function w(e,t){if(e===null)return _;let n=t-e;return n<0?`in ${C(-n)}`:n<6e4?`${Math.round(n/1e3)}s ago`:n<36e5?`${Math.round(n/6e4)}m ago`:`${Math.round(n/36e5)}h ago`}function T(e,t){if(e===null)return _;let n=e-t;return n>=0?`in ${C(n)}`:`overdue by ${C(-n)}`}function E({loops:e,nowMs:t=Date.now()}){let[n,r]=(0,h.useState)(!1);if(!e)return(0,g.jsxs)(`section`,{className:`activity-loops`,children:[(0,g.jsx)(`h2`,{className:`activity-loops-heading`,children:`Scheduled work`}),(0,g.jsx)(`p`,{className:`activity-loops-empty`,children:`Scheduled work could not be read from the server.`})]});let i=e.armed-e.rows.length,a=e.rows.filter(e=>b.has(e.state)),o=e.rows.filter(e=>!b.has(e.state)&&typeof e.cpuPct==`number`&&e.cpuPct>=x),s=n?e.rows:[...a,...o];return(0,g.jsxs)(`section`,{className:`activity-loops`,children:[(0,g.jsx)(`h2`,{className:`activity-loops-heading`,children:`Scheduled work`}),(0,g.jsxs)(`p`,{className:`activity-loops-sub`,children:[e.armed,` `,e.armed===1?`loop`:`loops`,` armed`,a.length>0?` · ${a.length} ${a.length===1?`needs`:`need`} attention`:` · all healthy`,o.length>0&&` · ${o.length} using significant processor`,`. `,(0,g.jsx)(`button`,{type:`button`,className:`activity-loops-toggle`,"aria-expanded":n,onClick:()=>r(e=>!e),children:n?`Show less`:`Show all`})]}),typeof e.processPct==`number`&&(0,g.jsxs)(`p`,{className:`activity-loops-cpu`,children:[`Server process at `,e.processPct.toFixed(1),`% of one core`,typeof e.attributedPct==`number`&&(0,g.jsxs)(g.Fragment,{children:[` · these loops explain `,e.attributedPct.toFixed(1),`%`]}),typeof e.unattributedPct==`number`&&e.unattributedPct>=1&&(0,g.jsxs)(g.Fragment,{children:[` · `,(0,g.jsxs)(`strong`,{children:[e.unattributedPct.toFixed(1),`% is not from these loops`]})]})]}),i>0&&(0,g.jsxs)(`p`,{className:`activity-loops-omission`,role:`status`,children:[i,` armed `,i===1?`loop is`:`loops are`,` missing from this list. The server armed `,e.armed,` but sent `,e.rows.length,`.`]}),s.length===0?null:(0,g.jsx)(`div`,{className:`activity-table-scroll`,children:(0,g.jsxs)(`table`,{className:`activity-table`,children:[(0,g.jsx)(`thead`,{children:(0,g.jsxs)(`tr`,{children:[(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Loop`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`State`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Every`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Last run`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Last OK`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Took`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`CPU`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Runs`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Produced`}),(0,g.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Next due`})]})}),(0,g.jsx)(`tbody`,{children:s.map(e=>(0,g.jsxs)(`tr`,{className:b.has(e.state)?`activity-loop-row activity-loop-unhealthy`:`activity-loop-row`,children:[(0,g.jsx)(`td`,{className:`activity-td`,children:e.name}),(0,g.jsx)(`td`,{className:`activity-td`,title:y[e.state],children:(0,g.jsxs)(`span`,{className:`activity-state`,children:[(0,g.jsx)(`span`,{className:e.state===`ok`?`activity-state-dot is-healthy`:b.has(e.state)?`activity-state-dot is-unhealthy`:`activity-state-dot`,"aria-hidden":`true`}),v(e.state)]})}),(0,g.jsx)(`td`,{className:`activity-td activity-num`,children:C(e.intervalMs)}),(0,g.jsx)(`td`,{className:`activity-td activity-num`,children:w(e.lastStartMs,t)}),(0,g.jsx)(`td`,{className:`activity-td activity-num`,children:w(e.lastSuccessMs,t)}),(0,g.jsx)(`td`,{className:`activity-td activity-num`,children:e.lastDurationMs===null?_:`${e.lastDurationMs} ms`}),(0,g.jsx)(`td`,{className:`activity-td activity-num`,title:e.cpuAttributable?e.detached?`Includes the processor time of the separate process this loop starts.`:void 0:`This loop waits on other work while it runs, so the processor time it uses cannot be separated from the rest of the server.`,children:S(e.cpuPct)}),(0,g.jsxs)(`td`,{className:`activity-td activity-num`,children:[e.successCount,`/`,e.runCount]}),(0,g.jsx)(`td`,{className:`activity-td activity-loop-note`,children:(0,g.jsx)(`span`,{className:`activity-loop-note-text`,title:e.lastError??e.lastNote??void 0,children:e.lastError??e.lastNote??_})}),(0,g.jsx)(`td`,{className:`activity-td activity-num`,children:T(e.nextDueMs,t)})]},e.name))})]})}),(0,g.jsxs)(`dl`,{className:`activity-legend`,children:[(0,g.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,g.jsx)(`dt`,{className:`activity-legend-term`,children:`Runs`}),(0,g.jsx)(`dd`,{className:`activity-legend-def`,children:`Finished runs out of attempted runs since the server started. 0 out of a large number means it has tried many times and never once finished.`})]}),(0,g.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,g.jsx)(`dt`,{className:`activity-legend-term`,children:`CPU`}),(0,g.jsx)(`dd`,{className:`activity-legend-def`,children:`Share of one processor core this loop is using, measured between the last two refreshes. It includes any separate process the loop starts, and can pass 100% because those run alongside each other. A dash means it could not be measured: the loop waits on other work while it runs, so its share cannot be separated from the rest of the server.`})]}),(0,g.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,g.jsx)(`dt`,{className:`activity-legend-term`,children:_}),(0,g.jsx)(`dd`,{className:`activity-legend-def`,children:`Not measured. It does not mean zero.`})]})]})]})}var D=`maxy-admin-session-key`;function O(e){switch(e.costUnavailable){case`metering-failed`:return`Cost could not be calculated: ${e.meteringError??`the transcript could not be read`}`;case`model-not-priced`:return`No published price for this model, so cost cannot be estimated.`;case`no-transcript`:return`This session has no transcript yet, so there is nothing to cost.`;default:return}}var k=[{key:`lastMessageAt`,label:`Last activity`,dir:-1},{key:`activeMsInRange`,label:`Active time`,dir:-1},{key:`costGbp`,label:`Cost`,dir:-1},{key:`accountId`,label:`Account name`,dir:1}],A=[{key:`title`,label:`Session`,help:`The conversation name, or its short id when it has none yet.`},{key:`model`,label:`Model`,help:`The model that answered the most recent turn.`},{key:`status`,label:`Status`,help:`What the process is doing right now.`},{key:`activeMsInRange`,label:`Active`,help:`Time this session spent thinking, writing and running tools inside the selected range. This is worked time, not elapsed time.`},{key:`ageMs`,label:`Age`,help:`How long ago this conversation started. Wall-clock, so it counts every hour nobody was working.`},{key:`lastMessageAt`,label:`Last activity`,help:`The clock time of the most recent message, in your timezone. A date appears once it is not today.`},{key:`turnCount`,label:`Turns`,help:`Messages exchanged. A trailing + means the count is a minimum — the conversation is too long to count exactly.`},{key:`rssKb`,label:`RAM`,help:`Memory held by this session and all its helper processes together.`},{key:`cpuPct`,label:`CPU (avg)`,help:`AVERAGE share of one processor core over the last census interval, up to 60 seconds. It is not a reading of this instant, so a session that answered a turn a minute ago still shows a high figure while sitting quiet now. Can exceed 100% because a session runs many processes at once.`},{key:`tokensInRange`,label:`Tokens`,help:`Total tokens billed inside the selected range, added up across every day in it. A cumulative total, not the size of the conversation the model currently reads back.`},{key:`costGbp`,label:`Cost`,help:`Estimated spend inside the selected range, at published prices for this model.`}],j=[`activeMsInRange`,`lastMessageAt`,`cpuPct`,`tokensInRange`],M={label:`Account`,help:`The business this session belongs to. "untagged" means the session records no account.`};function N(e,t){let n=t?.[e];return n&&n.trim()!==``?n:e.slice(0,8)}var P=`—`;function F(e){if(e===null||!Number.isFinite(e)||e<0)return P;let t=Math.floor(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);if(n<60)return`${n}m`;let r=Math.floor(n/60);return r<24?`${r}h ${n%60}m`:`${Math.floor(r/24)}d ${r%24}h`}function I(e){return e===null||!Number.isFinite(e)?P:`${(e/1024/1024).toFixed(1)} GB`}function L(e,t){if(!e)return P;let n=Date.parse(e);if(!Number.isFinite(n))return P;let r=new Date(n),i=new Date(t),a=`${String(r.getHours()).padStart(2,`0`)}:${String(r.getMinutes()).padStart(2,`0`)}`;return r.getFullYear()===i.getFullYear()&&r.getMonth()===i.getMonth()&&r.getDate()===i.getDate()?a:`${r.getDate()} ${r.toLocaleString(`en-GB`,{month:`short`})} ${a}`}function R(e){return e===null||!Number.isFinite(e)?P:`${e.toFixed(1)}%`}function z(e){return e===null||!Number.isFinite(e)?P:e<1e3?String(e):e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(2)}M`}function B(e){return e===null||!Number.isFinite(e)?P:`£${e.toFixed(2)}`}function V(e){if(e===null||!Number.isFinite(e)||e<0)return P;let t=Math.floor(e/6e4);return`${Math.floor(t/60)}h ${t%60}m`}function H(e,t,n,r){let i=e[n],a=t[n];if(i===null&&a===null)return 0;if(i===null)return 1;if(a===null)return-1;if(n===`lastMessageAt`){let e=Date.parse(String(i)),t=Date.parse(String(a));return!Number.isFinite(e)&&!Number.isFinite(t)?0:Number.isFinite(e)?Number.isFinite(t)?(e-t)*r:-1:1}return typeof i==`number`&&typeof a==`number`?(i-a)*r:String(i).localeCompare(String(a))*r}function U(e){return e.toISOString().slice(0,10)}function W(e){let t=e.getUTCFullYear(),n=e.getUTCMonth();return{from:U(new Date(Date.UTC(t,n,1))),to:U(new Date(Date.UTC(t,n+1,0)))}}function G(e,t){let n=new Date(`${e}T00:00:00.000Z`);return W(new Date(Date.UTC(n.getUTCFullYear(),n.getUTCMonth()+t,1)))}function ee(e,t){return{from:U(new Date(t-(e-1)*864e5)),to:U(new Date(t))}}function K(e){return new Date(`${e}T00:00:00.000Z`).toLocaleString(`en-GB`,{month:`long`,year:`numeric`,timeZone:`UTC`})}function q(e){if(e===null)return!1;let t=W(new Date(`${e.from}T00:00:00.000Z`));return t.from===e.from&&t.to===e.to}function J(e,t,n){switch(e){case`title`:return t.title??t.sessionId.slice(0,8);case`model`:return t.model??P;case`status`:return t.status??P;case`activeMsInRange`:return V(t.activeMsInRange);case`ageMs`:return F(t.ageMs);case`lastMessageAt`:return L(t.lastMessageAt,n);case`turnCount`:return t.turnCount===null?P:`${t.turnCount}${t.turnCountCapped?`+`:``}`;case`rssKb`:return I(t.rssKb);case`cpuPct`:return R(t.cpuPct);case`tokensInRange`:return z(t.tokensInRange);case`costGbp`:return B(t.costGbp);default:return P}}function Y({adminFetch:e,cacheKey:t}){let[r,a]=(0,h.useState)(null),[o,c]=(0,h.useState)(null),[u,d]=(0,h.useState)(!1),[m,_]=(0,h.useState)(`lastMessageAt`),[v,y]=(0,h.useState)(-1),[b,x]=(0,h.useState)(()=>W(new Date)),[S,C]=(0,h.useState)(!0),[w,T]=(0,h.useState)(!0),[D,I]=(0,h.useState)(!1),L=(0,h.useCallback)(async(e,n)=>{t&&await s(t,e)&&(console.info(`[admin-ui] activity-card-open account=${e.slice(0,8)} session=${n.slice(0,8)}`),window.location.assign(`/chat?session=${encodeURIComponent(n)}`))},[t]),R=(0,h.useRef)(!1),z=(0,h.useRef)(void 0),B=(0,h.useCallback)(async t=>{if(R.current){z.current=t;return}R.current=!0;try{let n=await e(`/api/admin/activity${t?`?from=${t.from}&to=${t.to}`:``}`);if(n.status===403){c(`This view is available to the house account only.`),d(!0);return}if(!n.ok){c(`The session manager did not answer (status ${n.status}).`),d(!0);return}a(await n.json()),c(null)}catch(e){c(e instanceof Error?e.message:String(e))}finally{d(!0),R.current=!1;let e=z.current;z.current=void 0,e!==void 0&&B(e)}},[e]);(0,h.useEffect)(()=>{B(b);let e=setInterval(()=>void B(b),15e3);return()=>clearInterval(e)},[B,b]);let V=(0,h.useMemo)(()=>r?[...r.rows].sort((e,t)=>H(e,t,m,v)):[],[r,m,v]),U=(0,h.useMemo)(()=>V.filter(e=>e.status===`busy`?S:e.status===`idle`?w:!0),[V,S,w]),Y=V.length-U.length;if(!u)return(0,g.jsx)(n,{surface:`gate`});if(o)return(0,g.jsx)(`div`,{className:`activity-empty`,children:o});if(!r)return(0,g.jsx)(`div`,{className:`activity-empty`,children:`No response.`});let{accounts:X,census:Z,censusAgeMs:Q}=r,te=Date.now(),ne=X.onDisk!==null&&X.onDisk>X.valid,$=r.range===void 0?b:r.range;return(0,g.jsxs)(`div`,{className:`activity-body`,children:[(0,g.jsxs)(`div`,{className:`activity-head`,children:[(0,g.jsxs)(`span`,{className:`activity-title`,children:[(0,g.jsx)(i,{size:16}),` Live sessions`]}),(0,g.jsxs)(`span`,{className:`activity-meta`,children:[Y>0?`${U.length} of ${V.length} live · ${Y} hidden`:`${V.length} live`,` · `,X.valid,` accounts`,X.untaggedCount>0?` · ${X.untaggedCount} untagged`:``]})]}),(0,g.jsxs)(`div`,{className:`activity-controls`,children:[(0,g.jsxs)(`div`,{className:`activity-control activity-range`,children:[(0,g.jsx)(l,{variant:`secondary`,size:`sm`,"aria-label":`Previous month`,disabled:!q(b),onClick:()=>x(e=>e&&G(e.from,-1)),children:`‹`}),(0,g.jsx)(`span`,{className:`activity-range-label`,children:b===null?`All time`:q(b)?K(b.from):`${b.from} → ${b.to}`}),(0,g.jsx)(l,{variant:`secondary`,size:`sm`,"aria-label":`Next month`,disabled:!q(b),onClick:()=>x(e=>e&&G(e.from,1)),children:`›`})]}),(0,g.jsxs)(`div`,{className:`activity-control activity-presets`,children:[(0,g.jsx)(l,{variant:`secondary`,size:`sm`,"aria-pressed":b!==null&&q(b)&&b.from===W(new Date).from,onClick:()=>x(W(new Date)),children:`This month`}),(0,g.jsx)(l,{variant:`secondary`,size:`sm`,"aria-pressed":b!==null&&!q(b),onClick:()=>x(ee(7,Date.now())),children:`Last 7 days`}),(0,g.jsx)(l,{variant:`secondary`,size:`sm`,"aria-pressed":b===null,onClick:()=>x(null),children:`All time`})]}),(0,g.jsxs)(`div`,{className:`activity-control`,children:[(0,g.jsx)(`label`,{className:`activity-control-label`,htmlFor:`activity-sort`,children:`Sort by`}),(0,g.jsx)(`span`,{className:`activity-select-wrap`,children:(0,g.jsx)(`select`,{id:`activity-sort`,className:`activity-select`,value:m,onChange:e=>{let t=k.find(t=>t.key===e.target.value);t&&(_(t.key),y(t.dir))},children:k.map(e=>(0,g.jsx)(`option`,{value:e.key,children:e.label},e.key))})})]}),(0,g.jsxs)(`div`,{className:`activity-control activity-visibility`,children:[(0,g.jsx)(f,{checked:S,onChange:C,label:`Busy`}),(0,g.jsx)(f,{checked:w,onChange:T,label:`Idle`})]})]}),(0,g.jsxs)(`div`,{className:`activity-range-note`,children:[$===null?`Active time, tokens and cost cover each conversation’s whole history.`:`Active time, tokens and cost cover ${$.from} to ${$.to} (UTC), inclusive.`,r.fullRangeFallback&&(0,g.jsxs)(`strong`,{className:`activity-range-rejected`,children:[` `,`The range was not accepted, so these are all-time figures.`]})]}),(0,g.jsx)(`div`,{className:`activity-census`,children:Z===null?`No census collected yet, so memory and CPU are unavailable.`:`Memory and CPU measured ${F(Q)} ago, averaged over the minute before that · ${Z.cpuNull} of ${Z.live} without a CPU reading`}),ne&&(0,g.jsxs)(`div`,{className:`activity-warning`,children:[(0,g.jsx)(p,{size:14}),` `,X.onDisk,` account folders on disk but only`,` `,X.valid,` are readable. Sessions belonging to the rest cannot be attributed.`]}),V.length===0?(0,g.jsx)(`div`,{className:`activity-empty`,children:`No sessions are running.`}):U.length===0?(0,g.jsxs)(`div`,{className:`activity-empty`,children:[`All `,V.length,` running sessions are hidden by the Busy and Idle filters.`]}):(0,g.jsx)(`div`,{className:`activity-grid`,children:U.map(e=>{let n=e.accountId!==null&&!!t,r=n?()=>void L(e.accountId,e.sessionId):void 0;return(0,g.jsxs)(`article`,{className:`activity-card${n?` activity-card-clickable`:``}`,"data-testid":`activity-card`,"data-session-id":e.sessionId,role:n?`button`:void 0,tabIndex:n?0:void 0,onClick:r,onKeyDown:n?e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),r())}:void 0,children:[(0,g.jsx)(`h3`,{className:`activity-card-heading`,title:e.accountId??void 0,children:e.accountId===null?(0,g.jsx)(`span`,{className:`activity-untagged`,title:`This session records no account, so it cannot be attributed to a business.`,children:`untagged`}):N(e.accountId,X.names)}),(0,g.jsx)(`dl`,{className:`activity-card-rows`,children:A.map(t=>(0,g.jsxs)(`div`,{className:`activity-card-row`,children:[(0,g.jsx)(`dt`,{className:`activity-card-label`,"data-testid":`activity-card-label`,title:t.help,children:t.label}),(0,g.jsx)(`dd`,{className:`activity-card-value`,title:t.key===`costGbp`?O(e):void 0,children:J(t.key,e,te)})]},t.key))})]},e.sessionId)})}),V.length>0&&(0,g.jsxs)(`div`,{className:`activity-glossary`,children:[(0,g.jsxs)(`dl`,{className:`activity-legend`,children:[D&&(0,g.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,g.jsx)(`dt`,{className:`activity-legend-term`,"data-testid":`activity-glossary-term`,children:M.label}),(0,g.jsx)(`dd`,{className:`activity-legend-def`,children:M.help})]},`heading`),(D?A:A.filter(e=>j.includes(e.key))).map(e=>(0,g.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,g.jsx)(`dt`,{className:`activity-legend-term`,"data-testid":`activity-glossary-term`,children:e.label}),(0,g.jsx)(`dd`,{className:`activity-legend-def`,children:e.help})]},e.key)),(0,g.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,g.jsx)(`dt`,{className:`activity-legend-term`,children:P}),(0,g.jsxs)(`dd`,{className:`activity-legend-def`,children:[`Not measured. It does not mean zero — a measured zero is written as a figure, so `,(0,g.jsx)(`em`,{children:`0h 0m`}),` and `,(0,g.jsx)(`em`,{children:`£0.00`}),` are real readings. Hover a dashed value for the reason where one exists.`]})]})]}),(0,g.jsx)(l,{variant:`secondary`,size:`sm`,className:`activity-glossary-toggle`,onClick:()=>I(e=>!e),children:D?`Show fewer`:`Explain every figure`})]}),(0,g.jsx)(E,{loops:r?.loops})]})}function X({cacheKey:e}){let{adminFetch:t}=a({initialCacheKey:e,surface:`activity`});return(0,g.jsx)(Y,{adminFetch:t,cacheKey:e})}function Z(){let[e,t]=(0,h.useState)(null),[r,i]=(0,h.useState)(!1),[a,o]=(0,h.useState)(void 0),[s,l]=(0,h.useState)(null),[f,p]=(0,h.useState)(null),[m,_]=(0,h.useState)(null),[v,y]=(0,h.useState)(null);(0,h.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(D)}catch{}if(!n){t(null),i(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async r=>{if(!e){if(r.status===401){try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`;return}if(r.ok)try{let e=await r.json();typeof e.businessName==`string`&&o(e.businessName),e.sessionId!==void 0&&l(e.sessionId??null),p(e.role??null),_(e.userName===void 0?null:e.userName),y(e.avatar??null)}catch{}t(n),i(!0)}}).catch(()=>{e||(t(n),i(!0))}),()=>{e=!0}},[]);let b=(0,h.useCallback)(()=>{try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`},[]),[x,S]=(0,h.useState)(!1),C=(0,h.useCallback)(async()=>{S(!0);try{let e=await u();if(e){try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`}return e}finally{S(!1)}},[]);return r?e?(0,g.jsx)(c,{cacheKey:e,surface:`activity`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=activity`);try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`},children:(0,g.jsx)(d,{cacheKey:e,businessName:a,sessionId:s,onLogout:b,onDisconnect:C,disconnecting:x,userName:m,userAvatar:v,role:f,children:(0,g.jsx)(X,{cacheKey:e})})}):(0,g.jsx)(`div`,{className:`activity-page`,children:(0,g.jsxs)(`div`,{className:`activity-empty`,children:[(0,g.jsx)(`p`,{children:`You are not signed in.`}),(0,g.jsxs)(`p`,{children:[`Open the `,(0,g.jsx)(`a`,{href:`/`,className:`activity-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,g.jsx)(n,{surface:`gate`})}(0,m.createRoot)(document.getElementById(`root`)).render((0,g.jsx)(Z,{}));
@@ -0,0 +1 @@
1
+ import{o as e}from"./chunk-CltuBf4Z.js";import{B as t,D as n,F as r,K as i,V as a,W as o,a as s,l as c,m as l,p as u,s as d,v as ee}from"./useSubAccountSwitcher-0PfRrN6i.js";import{n as f,t as p}from"./AdminLoginScreens-YT7jsh_H.js";import{s as m}from"./useVoiceRecorder-BP6CpYQD.js";import{a as h,b as g,f as _,t as v,y}from"./AdminShell-Ckht9hmU.js";import{a as b,i as x,n as S,r as C}from"./page-3T2mE63b.js";import{t as w}from"./chevron-left-Dtk3jEK5.js";import{t as T}from"./chevron-right-Dih6IZ8B.js";import{t as E}from"./file-text-zch0E1GJ.js";import"./graph-labels-CBwh4g-6.js";var D=o(),O=e(i(),1),k=t();function A({onOpen:e}){return(0,k.jsx)(`footer`,{className:`admin-footer`,children:(0,k.jsxs)(`div`,{className:`powered-by`,role:`button`,tabIndex:0,onClick:e,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),e())},"aria-label":`Powered by Claude Code — show details`,children:[(0,k.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`powered-by-icon`}),(0,k.jsx)(`span`,{children:`Powered by Claude Code`})]})})}function j({sessionId:e,projectDir:t,sessionKey:n,contactName:r,onBack:i}){return(0,k.jsxs)(`div`,{className:`wa-web`,children:[(0,k.jsxs)(`header`,{className:`wa-web-header`,children:[i&&(0,k.jsx)(`button`,{type:`button`,className:`wa-web-back`,onClick:i,"aria-label":`Back`,children:(0,k.jsx)(w,{size:20})}),(0,k.jsx)(`span`,{className:`wa-web-avatar`,"aria-hidden":!0,children:(0,k.jsx)(b,{size:20})}),(0,k.jsx)(`div`,{className:`wa-web-titles`,children:(0,k.jsx)(`span`,{className:`wa-web-name`,children:r})})]}),(0,k.jsx)(`div`,{className:`wa-web-body`,children:(0,k.jsx)(m,{sessionId:e,projectDir:t,sessionKey:n,forceDeliveredOnly:!0})})]})}var M=6e4,N=60*M,P=24*N,F=M,I=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],L=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function R(e){return e<10?`0${e}`:String(e)}function z(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime()}function B(e,t){if(!Number.isFinite(e)||e<=0||!Number.isFinite(t))return`—`;let n=t-e;if(n<-F)return`—`;let r=n<0?0:n;if(r<M)return`just now`;if(r<N)return`${Math.floor(r/M)}m`;if(r<P)return`${Math.floor(r/N)}h`;let i=new Date(t),a=new Date(e),o=Math.round((z(i)-z(a))/P);if(o===1)return`yesterday`;if(o>=2&&o<=6)return L[a.getDay()];let s=R(a.getDate()),c=I[a.getMonth()];return a.getFullYear()===i.getFullYear()?`${s} ${c}`:`${s} ${c} ${a.getFullYear()}`}var V={whatsapp:`WhatsApp`,telegram:`Telegram`,webchat:`Web chat`},H=6e4;function U(e){return e<12?`morning`:e<18?`afternoon`:`evening`}function W(e){return e&&e.trim().split(/\s+/)[0]||`there`}function G(e){if(!e)return`everything is running normally.`;let t=e.cpuPct,n=e.memUsedPct;return t!==null&&t>=.98||n!==null&&n>=.98?`system load is critical.`:t!==null&&t>=.9||n!==null&&n>=.9?`system load is high.`:`everything is running normally.`}function K(e){return e==null?`—`:`${Math.round(e*100)}%`}function q(e){return e.operatorName??e.whatsappName??e.senderId??e.title}function J(e,t){if(!e)return!1;let n=Date.parse(e);if(!Number.isFinite(n))return!1;let r=new Date(n),i=new Date(t);return r.getFullYear()===i.getFullYear()&&r.getMonth()===i.getMonth()&&r.getDate()===i.getDate()}function Y(e){return e?e.replace(/^claude-/,``):null}function X({cacheKey:e,userName:t,onSelectWhatsappConversation:i}){let o=l(e),[u,f]=(0,O.useState)(null),[p,m]=(0,O.useState)(null),[h,v]=(0,O.useState)(null),b=(0,O.useRef)(!1),[x,S]=(0,O.useState)(null),[w,D]=(0,O.useState)(null),[A,j]=(0,O.useState)(null),[M,N]=(0,O.useState)(null),[P,F]=(0,O.useState)(new Set),[I,L]=(0,O.useState)(!1),R=Date.now(),z=(0,O.useRef)(!1);(0,O.useEffect)(()=>{if(!e)return;let t=!1;async function n(e,n,r){try{let i=await o(e);if(!i.ok)throw Error(`status ${i.status}`);let a=await i.json();t||r(n(a))}catch(t){console.error(`[admin-ui] dashboard-fetch-failed url=${e} reason=${t instanceof Error?t.message:String(t)}`)}}let r={"sidebar-sessions":()=>n(`/api/admin/sidebar-sessions`,e=>e.sessions??[],f),"conversations-all":()=>n(`/api/whatsapp-reader/conversations-all`,e=>e.conversations??[],m),"tasks-list":()=>n(`/api/admin/tasks-list`,e=>e,D),"sidebar-artefacts":()=>n(`/api/admin/sidebar-artefacts`,e=>e.artefacts??[],j),skills:()=>n(`/api/admin/skills`,e=>e.skills??[],N)};async function i(){if(!z.current){z.current=!0;try{await Promise.all([...Object.values(r).map(e=>e()),n(`/api/admin/system-stats`,e=>e,S)])}finally{z.current=!1,t||L(!0)}}}i();let s=null;try{s=new EventSource(a(`/api/admin/events`,e)),s.onmessage=e=>{if(document.visibilityState===`visible`)try{let{resource:t}=JSON.parse(e.data),n=t?r[t]:void 0;n&&n()}catch{}},s.onerror=()=>{console.error(`[admin-ui] dashboard-events stream error`)}}catch(e){console.error(`[admin-ui] dashboard-events unavailable reason=${e instanceof Error?e.message:String(e)}`)}let c=setInterval(()=>{document.visibilityState===`visible`&&i()},H),l=()=>{document.visibilityState===`visible`&&i()};return document.addEventListener(`visibilitychange`,l),()=>{t=!0,clearInterval(c),s?.close(),document.removeEventListener(`visibilitychange`,l)}},[e,o]);let X=(0,O.useMemo)(()=>(u??[]).filter(e=>!e.isSubagent),[u]),Z=(0,O.useMemo)(()=>X.filter(e=>e.live),[X]),Q=(0,O.useMemo)(()=>(p??[]).filter(e=>J(e.lastMessageAt,R)).length,[p,R]),te=w?.open.length??0,$=(0,O.useMemo)(()=>{let e=new Map;for(let t of p??[]){let n=e.get(t.channel)??[];n.push(t),e.set(t.channel,n)}return[...e.entries()].map(([e,t])=>{let n=t.reduce((e,t)=>t.lastMessageAt&&(!e||Date.parse(t.lastMessageAt)>Date.parse(e.lastMessageAt??``))?t:e,null);return{channel:e,count:t.length,preview:n?q(n):``,rows:t}})},[p]);(0,O.useEffect)(()=>{b.current||$.length!==0&&(b.current=!0,v($[0].channel))},[$]);let ne=(0,O.useCallback)(async e=>{if(!P.has(e)){F(t=>new Set(t).add(e));try{let t=await o(`/api/admin/session-stop`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e})});if(!t.ok){console.error(`[admin-ui] dashboard-session-stop-failed sessionId=${e} status=${t.status}`);return}console.info(`[admin-ui] dashboard-session-stop sessionId=${e}`),f(t=>(t??[]).map(t=>t.sessionId===e?{...t,live:!1}:t))}catch(t){console.error(`[admin-ui] dashboard-session-stop-failed sessionId=${e} reason=${t instanceof Error?t.message:String(t)}`)}finally{F(t=>{let n=new Set(t);return n.delete(e),n})}}},[o,P]),re=(0,O.useCallback)(t=>{if(!e||!t.downloadPath){console.error(`[admin-ui] dashboard-artefact-download-blocked id=${t.id} reason=${e?`not-downloadable`:`no-cache-key`}`);return}C(e,t.downloadPath,t.downloadRoot??`data`)},[e]),ie=U(new Date(R).getHours());return I?(0,k.jsxs)(`div`,{className:`dashboard-home`,children:[(0,k.jsx)(`p`,{className:`dashboard-greeting`,children:`Good ${ie}, ${W(t)} — ${G(x)}`}),(0,k.jsxs)(`div`,{className:`dashboard-stats`,children:[(0,k.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,k.jsx)(`span`,{className:`dashboard-stat-label`,children:`Live sessions`}),(0,k.jsx)(`span`,{className:`dashboard-stat-value`,children:Z.length}),(0,k.jsxs)(`span`,{className:`dashboard-stat-delta`,children:[`of `,X.length,` total`]})]}),(0,k.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,k.jsx)(`span`,{className:`dashboard-stat-label`,children:`Messages today`}),(0,k.jsx)(`span`,{className:`dashboard-stat-value`,children:Q})]}),(0,k.jsxs)(`a`,{className:`admin-stat-card dashboard-stat-card dashboard-stat-card--link`,href:`/tasks`,children:[(0,k.jsx)(`span`,{className:`dashboard-stat-label`,children:`Open tasks`}),(0,k.jsx)(`span`,{className:`dashboard-stat-value`,children:te})]}),(0,k.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,k.jsx)(`span`,{className:`dashboard-stat-label`,children:`Host CPU`}),(0,k.jsx)(`span`,{className:`dashboard-stat-value`,children:K(x?.cpuPct??null)}),(0,k.jsxs)(`span`,{className:`dashboard-stat-delta`,children:[`RAM `,K(x?.memUsedPct??null)]})]})]}),(0,k.jsxs)(`div`,{className:`dashboard-columns`,children:[(0,k.jsxs)(`div`,{className:`dashboard-col`,children:[(0,k.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Live now`}),Z.length===0?(0,k.jsx)(`div`,{className:`admin-card dashboard-empty`,children:`No live sessions right now.`}):Z.map(e=>{let t=[e.sessionId.slice(0,8),Y(e.model),B(Date.parse(e.startedAt),R)].filter(Boolean).join(` · `);return(0,k.jsxs)(`div`,{className:`admin-card dashboard-live-card`,children:[(0,k.jsx)(`span`,{className:`admin-status-dot is-live`}),(0,k.jsxs)(`div`,{className:`dashboard-live-main`,children:[(0,k.jsx)(`span`,{className:`dashboard-live-name`,children:e.title}),(0,k.jsx)(`span`,{className:`dashboard-live-meta`,children:t})]}),(0,k.jsx)(`a`,{className:`admin-btn-cta dashboard-open-btn`,href:`/chat?session=${encodeURIComponent(e.sessionId)}`,children:`Open`}),(0,k.jsx)(`button`,{type:`button`,className:`dashboard-stop-btn`,"aria-label":`Stop ${e.title}`,disabled:P.has(e.sessionId),onClick:()=>void ne(e.sessionId),children:(0,k.jsx)(ee,{size:12})})]},e.sessionId)}),(0,k.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Recent artefacts`}),(0,k.jsx)(`div`,{className:`admin-card dashboard-artefacts`,children:(A??[]).length===0?(0,k.jsx)(`div`,{className:`dashboard-empty`,children:`No recent artefacts.`}):(A??[]).slice(0,6).map(e=>(0,k.jsxs)(`button`,{type:`button`,className:`admin-row dashboard-artefact-row`,onClick:()=>re(e),children:[(0,k.jsx)(`span`,{className:`dashboard-artefact-icon`,children:e.kind===`agent-template`?(0,k.jsx)(g,{size:16}):(0,k.jsx)(E,{size:16})}),(0,k.jsx)(`div`,{className:`dashboard-artefact-body`,children:(0,k.jsx)(`span`,{className:`dashboard-artefact-name`,children:e.name})}),(0,k.jsx)(`span`,{className:`dashboard-artefact-time`,children:B(Date.parse(e.updatedAt),R)})]},e.id))}),(0,k.jsx)(`a`,{className:`admin-section-label dashboard-col-label dashboard-skills-label`,href:`/skills`,children:`Skills`}),(0,k.jsx)(`div`,{className:`admin-card dashboard-skills`,children:(M??[]).length===0?(0,k.jsx)(`div`,{className:`dashboard-empty`,children:`No skills yet.`}):(M??[]).map(e=>(0,k.jsxs)(`a`,{className:`admin-row dashboard-skill-row`,href:`/skills`,children:[(0,k.jsx)(`span`,{className:`dashboard-skill-icon`,children:(0,k.jsx)(_,{size:16})}),(0,k.jsxs)(`div`,{className:`dashboard-skill-body`,children:[(0,k.jsx)(`span`,{className:`dashboard-skill-name`,children:e.skill}),(0,k.jsx)(`span`,{className:`dashboard-skill-plugin`,children:e.plugin})]})]},`${e.plugin}/${e.skill}`))})]}),(0,k.jsxs)(`div`,{className:`dashboard-col`,children:[(0,k.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Channels`}),$.length===0?(0,k.jsx)(`div`,{className:`admin-card dashboard-empty`,children:`No channel activity.`}):$.map(e=>{let t=h===e.channel;return(0,k.jsxs)(`div`,{className:`admin-card dashboard-channel-card`,children:[(0,k.jsxs)(`button`,{type:`button`,className:`dashboard-channel-head`,"aria-expanded":t,onClick:()=>v(t=>t===e.channel?null:e.channel),children:[(0,k.jsx)(`span`,{className:`dashboard-channel-glyph`,children:e.channel===`whatsapp`||e.channel===`telegram`?(0,k.jsx)(c,{channel:e.channel,size:16}):(0,k.jsx)(n,{size:16})}),(0,k.jsx)(`span`,{className:`dashboard-channel-name`,children:V[e.channel]??e.channel}),(0,k.jsx)(`span`,{className:`dashboard-channel-badge`,children:e.count}),(0,k.jsx)(`span`,{className:`dashboard-channel-chevron`,children:t?(0,k.jsx)(y,{size:14}):(0,k.jsx)(T,{size:14})})]}),t?(0,k.jsx)(`div`,{className:`dashboard-channel-convs`,children:e.rows.map(e=>(0,k.jsxs)(`button`,{type:`button`,className:`admin-row dashboard-channel-conv-row`,onClick:()=>i(e),title:e.title,children:[(0,k.jsx)(`span`,{className:`dashboard-channel-conv-name`,children:s(e)}),(0,k.jsx)(`span`,{className:`dashboard-channel-conv-tag`,children:e.isHouse?`House`:`Client`}),e.lastMessageAt&&(0,k.jsx)(`span`,{className:`dashboard-channel-conv-time`,children:B(Date.parse(e.lastMessageAt),R)})]},d(e)))}):e.preview&&(0,k.jsx)(`span`,{className:`dashboard-channel-preview`,children:e.preview})]},e.channel)})]})]})]}):(0,k.jsx)(r,{surface:`gate`})}function Z(){let e=f(),[t,n]=(0,O.useState)(!1);(0,O.useEffect)(()=>{if(!t)return;let e=e=>{e.key===`Escape`&&n(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let r=(0,O.useCallback)(async()=>{let t=e.claudeInfo!=null;if(n(!0),t){console.info(`[admin-ui] claude-info-open cached=true ms=0`);return}let r=Date.now();try{let t=await fetch(`/api/admin/claude-info`);if(t.ok){let n=await t.json();e.setClaudeInfo(n)}console.info(`[admin-ui] claude-info-open cached=false ms=${Date.now()-r}`)}catch(e){console.error(`[admin-ui] claude-info-fetch-failed ms=${Date.now()-r} error="${e instanceof Error?e.message:String(e)}"`)}},[e]),i=(0,O.useCallback)(({code:t,path:n})=>{console.warn(`[admin-auth] outcome=chat-tab-logout-on-401 code=${t} path=${n}`),e.handleLogout()},[e]);return e.appState===`chat`?(0,k.jsx)(u,{cacheKey:e.cacheKey,onSessionExpired:i,surface:`chat`,children:(0,k.jsx)(v,{cacheKey:e.cacheKey,businessName:e.businessName,sessionId:e.sessionId,onLogout:e.handleLogout,onDisconnect:e.handleDisconnect,disconnecting:e.disconnecting,claudeConnected:e.claudeConnected,onConnectClaude:()=>e.setAppState(`connect-claude`),userName:e.userName,userAvatar:e.userAvatar,role:e.role,footer:(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(A,{onOpen:r}),(0,k.jsx)(h,{show:t,onClose:()=>n(!1),claudeInfo:e.claudeInfo,messages:[],sessionElapsed:0,sessionId:e.sessionId,cacheKey:e.cacheKey})]}),children:t=>(0,k.jsx)(k.Fragment,{children:t.dataOpen&&e.cacheKey?(0,k.jsx)(S,{cacheKey:e.cacheKey}):t.selectedWhatsapp&&e.cacheKey?t.selectedWhatsapp.source===`store`&&t.selectedWhatsapp.remoteJid&&t.selectedWhatsapp.accountId?(0,k.jsx)(x,{accountId:t.selectedWhatsapp.accountId,remoteJid:t.selectedWhatsapp.remoteJid,contactName:s(t.selectedWhatsapp),sessionKey:e.cacheKey,onBack:t.onClearWhatsapp},d(t.selectedWhatsapp)):(0,k.jsx)(j,{sessionId:t.selectedWhatsapp.sessionId,projectDir:t.selectedWhatsapp.projectDir,sessionKey:e.cacheKey,contactName:s(t.selectedWhatsapp),onBack:t.onClearWhatsapp},d(t.selectedWhatsapp)):(0,k.jsx)(X,{cacheKey:e.cacheKey,userName:e.userName,onSelectWhatsappConversation:t.onSelectWhatsappConversation})})})}):(0,k.jsx)(p,{auth:e})}(0,D.createRoot)(document.getElementById(`root`)).render((0,k.jsx)(Z,{}));
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{B as t,F as n,K as r,T as i,U as a,W as o,_ as s,g as c,p as l}from"./useSubAccountSwitcher-DSW9vDi2.js";import{T as u,_ as d,b as f,t as p}from"./AdminShell-C8wazpnz.js";var m=o(),h=e(r(),1),g=t();function _({label:e,body:t}){return(0,g.jsxs)(`div`,{className:`agent-doc`,children:[(0,g.jsx)(`span`,{className:`agent-doc-label`,children:e}),(0,g.jsx)(`pre`,{className:`skill-body`,children:t.trim()||`Empty.`})]})}function v({summary:e,publicBaseUrl:t,accountId:n,adminFetch:r,onClose:a,onDeleted:o}){let l=e.kind===`specialist`,[u]=(0,h.useState)(n),[p,m]=(0,h.useState)(null),[v,y]=(0,h.useState)(!0),[b,x]=(0,h.useState)(null),[S,C]=(0,h.useState)(!1),[w,T]=(0,h.useState)(!1);(0,h.useEffect)(()=>{let t=!1;y(!0),x(null);let n=e.kind===`specialist`&&e.plugin?`?plugin=${encodeURIComponent(e.plugin)}`:``;return r(`/api/admin/agents/${encodeURIComponent(e.slug)}${n}`).then(async e=>{if(!t){if(!e.ok)throw Error(`HTTP ${e.status}`);m((await e.json()).agent)}}).catch(e=>{t||x(e instanceof Error?e.message:`Failed to load`)}).finally(()=>{t||y(!1)}),()=>{t=!0}},[r,e.slug]),(0,h.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!w&&a()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[w,a]);let E=(0,h.useCallback)(async()=>{T(!0),x(null);try{let t=await r(`/api/admin/agents/${encodeURIComponent(e.slug)}?accountId=${encodeURIComponent(u??``)}`,{method:`DELETE`,headers:{"content-type":`application/json`}});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??`HTTP ${t.status}`)}o(e)}catch(e){x(e instanceof Error?e.message:`Delete failed`),T(!1),C(!1)}},[r,e,u,o]),D=l?null:p,O=l?p:null;return(0,g.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{w||a()},children:(0,g.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":`Agent detail`,onClick:e=>e.stopPropagation(),children:[(0,g.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,g.jsxs)(`span`,{className:`cal-modal-kind`,children:[(0,g.jsx)(f,{size:13}),` `,l?`Specialist`:`Agent`]}),(0,g.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:a,"aria-label":`Close`,autoFocus:!0,disabled:w,children:(0,g.jsx)(c,{size:16})})]}),(0,g.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,g.jsx)(`div`,{className:`cal-modal-title`,children:e.displayName}),(0,g.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[!l&&(0,g.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),(0,g.jsxs)(`span`,{children:[`/`,e.slug]})]}),v&&(0,g.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,g.jsx)(i,{size:14,className:`spin`}),(0,g.jsx)(`span`,{children:`Loading…`})]}),D&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,g.jsxs)(`span`,{children:[D.status,D.model?` · ${D.model}`:``]})}),(0,g.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,g.jsxs)(`a`,{href:`${t}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`cal-link`,children:[(0,g.jsx)(d,{size:13}),` Open agent`]})}),D.present.identity&&(0,g.jsx)(_,{label:`Identity`,body:D.identity}),D.present.soul&&(0,g.jsx)(_,{label:`Soul`,body:D.soul}),D.present.knowledge&&(0,g.jsx)(_,{label:`Knowledge`,body:D.knowledge}),D.present.knowledgeSummary&&(0,g.jsx)(_,{label:`Knowledge summary`,body:D.knowledgeSummary}),D.knowledgeKeywords.length>0&&(0,g.jsxs)(`div`,{className:`skill-refs`,children:[(0,g.jsx)(`span`,{className:`skill-refs-label`,children:`Knowledge keywords`}),D.knowledgeKeywords.map(e=>(0,g.jsx)(`span`,{className:`skill-ref`,children:e},e))]})]}),O&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,g.jsxs)(`span`,{children:[e.plugin,O.model?` · ${O.model}`:``]})}),O.description&&(0,g.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,g.jsx)(`span`,{children:O.description})}),O.tools.length>0&&(0,g.jsxs)(`div`,{className:`skill-refs`,children:[(0,g.jsx)(`span`,{className:`skill-refs-label`,children:`Tools`}),O.tools.map(e=>(0,g.jsx)(`span`,{className:`skill-ref`,children:e},e))]}),O.skills.length>0&&(0,g.jsxs)(`div`,{className:`skill-refs`,children:[(0,g.jsx)(`span`,{className:`skill-refs-label`,children:`Skills`}),O.skills.map(e=>(0,g.jsx)(`span`,{className:`skill-ref`,children:e},e))]}),(0,g.jsx)(_,{label:`System prompt`,body:O.systemPrompt})]})]}),b&&(0,g.jsx)(`div`,{className:`cal-modal-error`,children:b}),(0,g.jsx)(`div`,{className:`cal-modal-actions`,children:l?(0,g.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Edit in chat via agent-builder.`}):(0,g.jsxs)(g.Fragment,{children:[!S&&(0,g.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:()=>C(!0),disabled:w||v||!u,children:[(0,g.jsx)(s,{size:14}),` Delete`]}),S&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Delete this agent?`}),(0,g.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:E,disabled:w,children:[w?(0,g.jsx)(i,{size:14,className:`spin`}):(0,g.jsx)(s,{size:14}),` Delete`]}),(0,g.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>C(!1),disabled:w,children:`Cancel`})]})]})})]})})}var y=`maxy-admin-session-key`;function b(){let[e,t]=(0,h.useState)(null),[r,i]=(0,h.useState)(!1),[a,o]=(0,h.useState)(void 0),[s,c]=(0,h.useState)(null),[d,f]=(0,h.useState)(void 0),[m,_]=(0,h.useState)(null),[v,b]=(0,h.useState)(null);(0,h.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),_(e.avatar??null)}catch{}t(n),i(!0)}}).catch(()=>{e||(t(n),i(!0))}),()=>{e=!0}},[]);let S=(0,h.useCallback)(()=>{try{sessionStorage.removeItem(y)}catch{}window.location.href=`/`},[]),[C,w]=(0,h.useState)(!1),T=(0,h.useCallback)(async()=>{w(!0);try{let e=await u();if(e){try{sessionStorage.removeItem(y)}catch{}window.location.href=`/`}return e}finally{w(!1)}},[]);return r?e?(0,g.jsx)(l,{cacheKey:e,surface:`agents`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=agents`);try{sessionStorage.removeItem(y)}catch{}window.location.href=`/`},children:(0,g.jsx)(p,{cacheKey:e,businessName:a,sessionId:s,onLogout:S,onDisconnect:T,disconnecting:C,userName:d,userAvatar:m,role:v,children:(0,g.jsx)(x,{cacheKey:e})})}):(0,g.jsx)(`div`,{className:`cal-page`,children:(0,g.jsxs)(`div`,{className:`cal-empty`,children:[(0,g.jsx)(`p`,{children:`You are not signed in.`}),(0,g.jsxs)(`p`,{children:[`Open the `,(0,g.jsx)(`a`,{href:`/`,className:`cal-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,g.jsx)(n,{surface:`gate`})}function x({cacheKey:e}){let{adminFetch:t,sessionRefetchNonce:r}=a({initialCacheKey:e,surface:`agents`}),[o,s]=(0,h.useState)([]),[c,l]=(0,h.useState)(0),[u,d]=(0,h.useState)(0),[p,m]=(0,h.useState)(null),[_,y]=(0,h.useState)(!1),[b,x]=(0,h.useState)(!1),[S,C]=(0,h.useState)(null),[w,T]=(0,h.useState)(null),[E,D]=(0,h.useState)(``);(0,h.useEffect)(()=>{D(window.location.hostname.startsWith(`admin.`)?window.location.origin.replace(`admin.`,`public.`):window.location.origin)},[]);let O=(0,h.useCallback)(()=>{let e=!1;return y(!0),C(null),t(`/api/admin/agents`).then(async t=>{if(e)return;if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();s(Array.isArray(n.agents)?n.agents:[]),l(typeof n.skipped==`number`?n.skipped:0),d(typeof n.specialistsSkipped==`number`?n.specialistsSkipped:0),m(typeof n.accountId==`string`?n.accountId:null)}).catch(t=>{e||(C(t instanceof Error?t.message:`Failed to load`),s([]))}).finally(()=>{e||(y(!1),x(!0))}),()=>{e=!0}},[t]);(0,h.useEffect)(()=>O(),[O,r]);let k=(0,h.useCallback)(e=>{s(t=>t.filter(t=>t.slug!==e.slug)),T(null),O()},[O]);return b?(0,g.jsxs)(`div`,{className:`cal-page`,children:[(0,g.jsx)(`header`,{className:`cal-header`,children:(0,g.jsxs)(`div`,{className:`cal-nav`,children:[(0,g.jsxs)(`span`,{className:`cal-range-label`,children:[(0,g.jsx)(f,{size:16}),` Agents`]}),_&&(0,g.jsx)(i,{size:16,className:`spin`})]})}),(0,g.jsxs)(`div`,{className:`cal-body`,children:[S&&(0,g.jsxs)(`div`,{className:`cal-error`,children:[`Could not load agents: `,S]}),c+u>0&&(0,g.jsxs)(`div`,{className:`cal-error`,children:[c+u,` agent`,c+u===1?``:`s`,` could not be read (malformed config or frontmatter).`]}),!S&&!_&&o.length===0&&(0,g.jsx)(`div`,{className:`cal-empty`,children:(0,g.jsx)(`p`,{children:`No agents yet. Ask in chat to create one.`})}),o.length>0&&(0,g.jsx)(`div`,{className:`routine-list`,children:o.map(e=>(0,g.jsxs)(`button`,{type:`button`,className:`routine-card`,onClick:()=>T(e),children:[(0,g.jsxs)(`span`,{className:`routine-card-title`,children:[e.displayName,(0,g.jsx)(`span`,{className:`agent-kind-pill agent-kind-${e.kind}`,children:e.kind===`specialist`?`Specialist`:`Public`})]}),e.kind===`specialist`?(0,g.jsxs)(`span`,{className:`routine-card-sched`,children:[`/`,e.slug]}):(0,g.jsxs)(`span`,{className:`routine-card-sched`,children:[(0,g.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),` /`,e.slug]}),(0,g.jsx)(`span`,{className:`routine-card-meta`,children:e.kind===`specialist`?e.plugin:e.status})]},e.slug))})]}),w&&(0,g.jsx)(v,{summary:w,publicBaseUrl:E,accountId:p,adminFetch:t,onClose:()=>T(null),onDeleted:k})]}):(0,g.jsx)(n,{surface:`gate`})}(0,m.createRoot)(document.getElementById(`root`)).render((0,g.jsx)(b,{}));
1
+ import{o as e}from"./chunk-CltuBf4Z.js";import{B as t,F as n,K as r,T as i,U as a,W as o,_ as s,g as c,p as l}from"./useSubAccountSwitcher-0PfRrN6i.js";import{T as u,_ as d,b as f,t as p}from"./AdminShell-Ckht9hmU.js";var m=o(),h=e(r(),1),g=t();function _({label:e,body:t}){return(0,g.jsxs)(`div`,{className:`agent-doc`,children:[(0,g.jsx)(`span`,{className:`agent-doc-label`,children:e}),(0,g.jsx)(`pre`,{className:`skill-body`,children:t.trim()||`Empty.`})]})}function v({summary:e,publicBaseUrl:t,accountId:n,adminFetch:r,onClose:a,onDeleted:o}){let l=e.kind===`specialist`,[u]=(0,h.useState)(n),[p,m]=(0,h.useState)(null),[v,y]=(0,h.useState)(!0),[b,x]=(0,h.useState)(null),[S,C]=(0,h.useState)(!1),[w,T]=(0,h.useState)(!1);(0,h.useEffect)(()=>{let t=!1;y(!0),x(null);let n=e.kind===`specialist`&&e.plugin?`?plugin=${encodeURIComponent(e.plugin)}`:``;return r(`/api/admin/agents/${encodeURIComponent(e.slug)}${n}`).then(async e=>{if(!t){if(!e.ok)throw Error(`HTTP ${e.status}`);m((await e.json()).agent)}}).catch(e=>{t||x(e instanceof Error?e.message:`Failed to load`)}).finally(()=>{t||y(!1)}),()=>{t=!0}},[r,e.slug]),(0,h.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!w&&a()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[w,a]);let E=(0,h.useCallback)(async()=>{T(!0),x(null);try{let t=await r(`/api/admin/agents/${encodeURIComponent(e.slug)}?accountId=${encodeURIComponent(u??``)}`,{method:`DELETE`,headers:{"content-type":`application/json`}});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??`HTTP ${t.status}`)}o(e)}catch(e){x(e instanceof Error?e.message:`Delete failed`),T(!1),C(!1)}},[r,e,u,o]),D=l?null:p,O=l?p:null;return(0,g.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{w||a()},children:(0,g.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":`Agent detail`,onClick:e=>e.stopPropagation(),children:[(0,g.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,g.jsxs)(`span`,{className:`cal-modal-kind`,children:[(0,g.jsx)(f,{size:13}),` `,l?`Specialist`:`Agent`]}),(0,g.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:a,"aria-label":`Close`,autoFocus:!0,disabled:w,children:(0,g.jsx)(c,{size:16})})]}),(0,g.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,g.jsx)(`div`,{className:`cal-modal-title`,children:e.displayName}),(0,g.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[!l&&(0,g.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),(0,g.jsxs)(`span`,{children:[`/`,e.slug]})]}),v&&(0,g.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,g.jsx)(i,{size:14,className:`spin`}),(0,g.jsx)(`span`,{children:`Loading…`})]}),D&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,g.jsxs)(`span`,{children:[D.status,D.model?` · ${D.model}`:``]})}),(0,g.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,g.jsxs)(`a`,{href:`${t}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`cal-link`,children:[(0,g.jsx)(d,{size:13}),` Open agent`]})}),D.present.identity&&(0,g.jsx)(_,{label:`Identity`,body:D.identity}),D.present.soul&&(0,g.jsx)(_,{label:`Soul`,body:D.soul}),D.present.knowledge&&(0,g.jsx)(_,{label:`Knowledge`,body:D.knowledge}),D.present.knowledgeSummary&&(0,g.jsx)(_,{label:`Knowledge summary`,body:D.knowledgeSummary}),D.knowledgeKeywords.length>0&&(0,g.jsxs)(`div`,{className:`skill-refs`,children:[(0,g.jsx)(`span`,{className:`skill-refs-label`,children:`Knowledge keywords`}),D.knowledgeKeywords.map(e=>(0,g.jsx)(`span`,{className:`skill-ref`,children:e},e))]})]}),O&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,g.jsxs)(`span`,{children:[e.plugin,O.model?` · ${O.model}`:``]})}),O.description&&(0,g.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,g.jsx)(`span`,{children:O.description})}),O.tools.length>0&&(0,g.jsxs)(`div`,{className:`skill-refs`,children:[(0,g.jsx)(`span`,{className:`skill-refs-label`,children:`Tools`}),O.tools.map(e=>(0,g.jsx)(`span`,{className:`skill-ref`,children:e},e))]}),O.skills.length>0&&(0,g.jsxs)(`div`,{className:`skill-refs`,children:[(0,g.jsx)(`span`,{className:`skill-refs-label`,children:`Skills`}),O.skills.map(e=>(0,g.jsx)(`span`,{className:`skill-ref`,children:e},e))]}),(0,g.jsx)(_,{label:`System prompt`,body:O.systemPrompt})]})]}),b&&(0,g.jsx)(`div`,{className:`cal-modal-error`,children:b}),(0,g.jsx)(`div`,{className:`cal-modal-actions`,children:l?(0,g.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Edit in chat via agent-builder.`}):(0,g.jsxs)(g.Fragment,{children:[!S&&(0,g.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:()=>C(!0),disabled:w||v||!u,children:[(0,g.jsx)(s,{size:14}),` Delete`]}),S&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Delete this agent?`}),(0,g.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:E,disabled:w,children:[w?(0,g.jsx)(i,{size:14,className:`spin`}):(0,g.jsx)(s,{size:14}),` Delete`]}),(0,g.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>C(!1),disabled:w,children:`Cancel`})]})]})})]})})}var y=`maxy-admin-session-key`;function b(){let[e,t]=(0,h.useState)(null),[r,i]=(0,h.useState)(!1),[a,o]=(0,h.useState)(void 0),[s,c]=(0,h.useState)(null),[d,f]=(0,h.useState)(void 0),[m,_]=(0,h.useState)(null),[v,b]=(0,h.useState)(null);(0,h.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),_(e.avatar??null)}catch{}t(n),i(!0)}}).catch(()=>{e||(t(n),i(!0))}),()=>{e=!0}},[]);let S=(0,h.useCallback)(()=>{try{sessionStorage.removeItem(y)}catch{}window.location.href=`/`},[]),[C,w]=(0,h.useState)(!1),T=(0,h.useCallback)(async()=>{w(!0);try{let e=await u();if(e){try{sessionStorage.removeItem(y)}catch{}window.location.href=`/`}return e}finally{w(!1)}},[]);return r?e?(0,g.jsx)(l,{cacheKey:e,surface:`agents`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=agents`);try{sessionStorage.removeItem(y)}catch{}window.location.href=`/`},children:(0,g.jsx)(p,{cacheKey:e,businessName:a,sessionId:s,onLogout:S,onDisconnect:T,disconnecting:C,userName:d,userAvatar:m,role:v,children:(0,g.jsx)(x,{cacheKey:e})})}):(0,g.jsx)(`div`,{className:`cal-page`,children:(0,g.jsxs)(`div`,{className:`cal-empty`,children:[(0,g.jsx)(`p`,{children:`You are not signed in.`}),(0,g.jsxs)(`p`,{children:[`Open the `,(0,g.jsx)(`a`,{href:`/`,className:`cal-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,g.jsx)(n,{surface:`gate`})}function x({cacheKey:e}){let{adminFetch:t,sessionRefetchNonce:r}=a({initialCacheKey:e,surface:`agents`}),[o,s]=(0,h.useState)([]),[c,l]=(0,h.useState)(0),[u,d]=(0,h.useState)(0),[p,m]=(0,h.useState)(null),[_,y]=(0,h.useState)(!1),[b,x]=(0,h.useState)(!1),[S,C]=(0,h.useState)(null),[w,T]=(0,h.useState)(null),[E,D]=(0,h.useState)(``);(0,h.useEffect)(()=>{D(window.location.hostname.startsWith(`admin.`)?window.location.origin.replace(`admin.`,`public.`):window.location.origin)},[]);let O=(0,h.useCallback)(()=>{let e=!1;return y(!0),C(null),t(`/api/admin/agents`).then(async t=>{if(e)return;if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();s(Array.isArray(n.agents)?n.agents:[]),l(typeof n.skipped==`number`?n.skipped:0),d(typeof n.specialistsSkipped==`number`?n.specialistsSkipped:0),m(typeof n.accountId==`string`?n.accountId:null)}).catch(t=>{e||(C(t instanceof Error?t.message:`Failed to load`),s([]))}).finally(()=>{e||(y(!1),x(!0))}),()=>{e=!0}},[t]);(0,h.useEffect)(()=>O(),[O,r]);let k=(0,h.useCallback)(e=>{s(t=>t.filter(t=>t.slug!==e.slug)),T(null),O()},[O]);return b?(0,g.jsxs)(`div`,{className:`cal-page`,children:[(0,g.jsx)(`header`,{className:`cal-header`,children:(0,g.jsxs)(`div`,{className:`cal-nav`,children:[(0,g.jsxs)(`span`,{className:`cal-range-label`,children:[(0,g.jsx)(f,{size:16}),` Agents`]}),_&&(0,g.jsx)(i,{size:16,className:`spin`})]})}),(0,g.jsxs)(`div`,{className:`cal-body`,children:[S&&(0,g.jsxs)(`div`,{className:`cal-error`,children:[`Could not load agents: `,S]}),c+u>0&&(0,g.jsxs)(`div`,{className:`cal-error`,children:[c+u,` agent`,c+u===1?``:`s`,` could not be read (malformed config or frontmatter).`]}),!S&&!_&&o.length===0&&(0,g.jsx)(`div`,{className:`cal-empty`,children:(0,g.jsx)(`p`,{children:`No agents yet. Ask in chat to create one.`})}),o.length>0&&(0,g.jsx)(`div`,{className:`routine-list`,children:o.map(e=>(0,g.jsxs)(`button`,{type:`button`,className:`routine-card`,onClick:()=>T(e),children:[(0,g.jsxs)(`span`,{className:`routine-card-title`,children:[e.displayName,(0,g.jsx)(`span`,{className:`agent-kind-pill agent-kind-${e.kind}`,children:e.kind===`specialist`?`Specialist`:`Public`})]}),e.kind===`specialist`?(0,g.jsxs)(`span`,{className:`routine-card-sched`,children:[`/`,e.slug]}):(0,g.jsxs)(`span`,{className:`routine-card-sched`,children:[(0,g.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),` /`,e.slug]}),(0,g.jsx)(`span`,{className:`routine-card-meta`,children:e.kind===`specialist`?e.plugin:e.status})]},e.slug))})]}),w&&(0,g.jsx)(v,{summary:w,publicBaseUrl:E,accountId:p,adminFetch:t,onClose:()=>T(null),onDeleted:k})]}):(0,g.jsx)(n,{surface:`gate`})}(0,m.createRoot)(document.getElementById(`root`)).render((0,g.jsx)(b,{}));
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{B as t,D as n,I as r,K as i,T as a,W as o,m as s,p as c}from"./useSubAccountSwitcher-DSW9vDi2.js";import{T as l,_ as u,t as d}from"./AdminShell-C8wazpnz.js";var f=o(),p=e(i(),1),m=t(),h=`maxy-vnc-popout`;function g(){let[e,t]=(0,p.useState)(null),[i,o]=(0,p.useState)(!1),[c,l]=(0,p.useState)(null),d=s(null);(0,p.useEffect)(()=>{let e=!1;return fetch(`/vnc-viewer.html`,{method:`HEAD`}).then(n=>{e||(console.info(`[browser-page] op=viewer-probe available=${n.ok}`),t(n.ok))}).catch(()=>{e||(console.info(`[browser-page] op=viewer-probe available=false`),t(!1))}),()=>{e=!0}},[]);let f=(0,p.useCallback)(()=>{window.open(`/vnc-popout.html?title=${encodeURIComponent(r.productName)}`,h,`width=1024,height=768`)},[]),g=(0,p.useCallback)(async()=>{o(!0),l(null);try{let e=await d(`/api/admin/browser/launch`,{method:`POST`});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error||`Launch failed (${e.status})`)}}catch(e){l(e instanceof Error?e.message:String(e))}finally{o(!1)}},[d]);return e===null?(0,m.jsx)(`div`,{className:`vnc-surface`,children:(0,m.jsxs)(`div`,{className:`data-loading`,children:[(0,m.jsx)(a,{size:18,className:`spin`}),` Checking viewer…`]})}):e?(0,m.jsxs)(`div`,{className:`vnc-surface`,children:[(0,m.jsxs)(`div`,{className:`vnc-surface__toolbar`,children:[(0,m.jsxs)(`button`,{type:`button`,className:`vnc-surface__btn`,onClick:g,disabled:i,children:[i?(0,m.jsx)(a,{size:14,className:`spin`}):(0,m.jsx)(n,{size:14}),` Launch browser`]}),(0,m.jsxs)(`button`,{type:`button`,className:`vnc-surface__btn`,onClick:f,children:[(0,m.jsx)(u,{size:14}),` Pop out`]}),c&&(0,m.jsx)(`span`,{className:`vnc-surface__error`,children:c})]}),(0,m.jsx)(`div`,{className:`vnc-surface__viewport`,children:(0,m.jsx)(`iframe`,{className:`vnc-surface__iframe`,src:`/vnc-viewer.html`,title:`VNC viewer`})})]}):(0,m.jsx)(`div`,{className:`vnc-surface`,children:(0,m.jsxs)(`div`,{className:`vnc-surface__unavailable`,children:[(0,m.jsx)(n,{size:28,strokeWidth:1.75}),(0,m.jsx)(`p`,{children:`VNC surface not available on this platform.`})]})})}function _(){let[e,t]=(0,p.useState)(null),[r,i]=(0,p.useState)(!1),[o,s]=(0,p.useState)(void 0),[u,f]=(0,p.useState)(null),[h,_]=(0,p.useState)(void 0),[v,y]=(0,p.useState)(null),[b,x]=(0,p.useState)(null);(0,p.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(`maxy-admin-session-key`)}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(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}if(r.ok)try{let e=await r.json();typeof e.businessName==`string`&&s(e.businessName),e.sessionId!==void 0&&f(e.sessionId??null),x(e.role??null),_(e.userName===void 0?null:e.userName),y(e.avatar??null)}catch{}t(n),i(!0)}}).catch(()=>{e||(t(n),i(!0))}),()=>{e=!0}},[]);let S=(0,p.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]),[C,w]=(0,p.useState)(!1),T=(0,p.useCallback)(async()=>{w(!0);try{let e=await l();if(e){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`}return e}finally{w(!1)}},[]);return r?e?(0,m.jsx)(c,{cacheKey:e,surface:`browser`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=browser`);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},children:(0,m.jsx)(d,{cacheKey:e,businessName:o,sessionId:u,onLogout:S,onDisconnect:T,disconnecting:C,userName:h,userAvatar:v,role:b,children:(0,m.jsxs)(`div`,{className:`data-page`,children:[(0,m.jsx)(`header`,{className:`data-header`,children:(0,m.jsxs)(`h1`,{className:`data-title`,children:[(0,m.jsx)(n,{size:18}),` Browser`]})}),(0,m.jsx)(g,{})]})})}):(0,m.jsxs)(`div`,{className:`data-page`,children:[(0,m.jsx)(`header`,{className:`data-header`,children:(0,m.jsxs)(`h1`,{className:`data-title`,children:[(0,m.jsx)(n,{size:18}),` Browser`]})}),(0,m.jsxs)(`div`,{className:`data-empty`,children:[(0,m.jsx)(`p`,{children:`You are not signed in.`}),(0,m.jsxs)(`p`,{children:[`Open the `,(0,m.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})]}):(0,m.jsx)(`div`,{className:`data-page`,children:(0,m.jsxs)(`div`,{className:`data-loading`,children:[(0,m.jsx)(a,{size:18,className:`spin`}),` Loading…`]})})}(0,f.createRoot)(document.getElementById(`root`)).render((0,m.jsx)(_,{}));
1
+ import{o as e}from"./chunk-CltuBf4Z.js";import{B as t,D as n,I as r,K as i,T as a,W as o,m as s,p as c}from"./useSubAccountSwitcher-0PfRrN6i.js";import{T as l,_ as u,t as d}from"./AdminShell-Ckht9hmU.js";var f=o(),p=e(i(),1),m=t(),h=`maxy-vnc-popout`;function g(){let[e,t]=(0,p.useState)(null),[i,o]=(0,p.useState)(!1),[c,l]=(0,p.useState)(null),d=s(null);(0,p.useEffect)(()=>{let e=!1;return fetch(`/vnc-viewer.html`,{method:`HEAD`}).then(n=>{e||(console.info(`[browser-page] op=viewer-probe available=${n.ok}`),t(n.ok))}).catch(()=>{e||(console.info(`[browser-page] op=viewer-probe available=false`),t(!1))}),()=>{e=!0}},[]);let f=(0,p.useCallback)(()=>{window.open(`/vnc-popout.html?title=${encodeURIComponent(r.productName)}`,h,`width=1024,height=768`)},[]),g=(0,p.useCallback)(async()=>{o(!0),l(null);try{let e=await d(`/api/admin/browser/launch`,{method:`POST`});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t.error||`Launch failed (${e.status})`)}}catch(e){l(e instanceof Error?e.message:String(e))}finally{o(!1)}},[d]);return e===null?(0,m.jsx)(`div`,{className:`vnc-surface`,children:(0,m.jsxs)(`div`,{className:`data-loading`,children:[(0,m.jsx)(a,{size:18,className:`spin`}),` Checking viewer…`]})}):e?(0,m.jsxs)(`div`,{className:`vnc-surface`,children:[(0,m.jsxs)(`div`,{className:`vnc-surface__toolbar`,children:[(0,m.jsxs)(`button`,{type:`button`,className:`vnc-surface__btn`,onClick:g,disabled:i,children:[i?(0,m.jsx)(a,{size:14,className:`spin`}):(0,m.jsx)(n,{size:14}),` Launch browser`]}),(0,m.jsxs)(`button`,{type:`button`,className:`vnc-surface__btn`,onClick:f,children:[(0,m.jsx)(u,{size:14}),` Pop out`]}),c&&(0,m.jsx)(`span`,{className:`vnc-surface__error`,children:c})]}),(0,m.jsx)(`div`,{className:`vnc-surface__viewport`,children:(0,m.jsx)(`iframe`,{className:`vnc-surface__iframe`,src:`/vnc-viewer.html`,title:`VNC viewer`})})]}):(0,m.jsx)(`div`,{className:`vnc-surface`,children:(0,m.jsxs)(`div`,{className:`vnc-surface__unavailable`,children:[(0,m.jsx)(n,{size:28,strokeWidth:1.75}),(0,m.jsx)(`p`,{children:`VNC surface not available on this platform.`})]})})}function _(){let[e,t]=(0,p.useState)(null),[r,i]=(0,p.useState)(!1),[o,s]=(0,p.useState)(void 0),[u,f]=(0,p.useState)(null),[h,_]=(0,p.useState)(void 0),[v,y]=(0,p.useState)(null),[b,x]=(0,p.useState)(null);(0,p.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(`maxy-admin-session-key`)}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(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}if(r.ok)try{let e=await r.json();typeof e.businessName==`string`&&s(e.businessName),e.sessionId!==void 0&&f(e.sessionId??null),x(e.role??null),_(e.userName===void 0?null:e.userName),y(e.avatar??null)}catch{}t(n),i(!0)}}).catch(()=>{e||(t(n),i(!0))}),()=>{e=!0}},[]);let S=(0,p.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]),[C,w]=(0,p.useState)(!1),T=(0,p.useCallback)(async()=>{w(!0);try{let e=await l();if(e){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`}return e}finally{w(!1)}},[]);return r?e?(0,m.jsx)(c,{cacheKey:e,surface:`browser`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=browser`);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},children:(0,m.jsx)(d,{cacheKey:e,businessName:o,sessionId:u,onLogout:S,onDisconnect:T,disconnecting:C,userName:h,userAvatar:v,role:b,children:(0,m.jsxs)(`div`,{className:`data-page`,children:[(0,m.jsx)(`header`,{className:`data-header`,children:(0,m.jsxs)(`h1`,{className:`data-title`,children:[(0,m.jsx)(n,{size:18}),` Browser`]})}),(0,m.jsx)(g,{})]})})}):(0,m.jsxs)(`div`,{className:`data-page`,children:[(0,m.jsx)(`header`,{className:`data-header`,children:(0,m.jsxs)(`h1`,{className:`data-title`,children:[(0,m.jsx)(n,{size:18}),` Browser`]})}),(0,m.jsxs)(`div`,{className:`data-empty`,children:[(0,m.jsx)(`p`,{children:`You are not signed in.`}),(0,m.jsxs)(`p`,{children:[`Open the `,(0,m.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})]}):(0,m.jsx)(`div`,{className:`data-page`,children:(0,m.jsxs)(`div`,{className:`data-loading`,children:[(0,m.jsx)(a,{size:18,className:`spin`}),` Loading…`]})})}(0,f.createRoot)(document.getElementById(`root`)).render((0,m.jsx)(_,{}));
@@ -1 +1 @@
1
- import{o as e}from"./chunk-CltuBf4Z.js";import{B as t,F as n,K as r,P as i,S as a,T as o,U as s,W as c,_ as l,g as u,k as d,p as f}from"./useSubAccountSwitcher-DSW9vDi2.js";import{T as p,_ as m,t as h}from"./AdminShell-C8wazpnz.js";import{t as g}from"./chevron-left-DBMCTKlT.js";import{t as _}from"./chevron-right-SBAr6zzc.js";import{t as v}from"./clock-kkzt7Scf.js";var y=i(`calendar`,[[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`rect`,{width:`18`,height:`18`,x:`3`,y:`4`,rx:`2`,key:`1hopcy`}],[`path`,{d:`M3 10h18`,key:`8toen8`}]]),b=i(`map-pin`,[[`path`,{d:`M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0`,key:`1r0f0z`}],[`circle`,{cx:`12`,cy:`10`,r:`3`,key:`ilqhr7`}]]),x=i(`sticky-note`,[[`path`,{d:`M21 9a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 15 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2z`,key:`1dfntj`}],[`path`,{d:`M15 3v5a1 1 0 0 0 1 1h5`,key:`6s6qgf`}]]),S=i(`user-plus`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`19`,x2:`19`,y1:`8`,y2:`14`,key:`1bvyxn`}],[`line`,{x1:`22`,x2:`16`,y1:`11`,y2:`11`,key:`1shjgl`}]]),C=i(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),w=c(),T=e(r(),1);function E(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function D(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n}function O(e){let t=E(e),n=t.getDay();return D(t,n===0?-6:1-n)}function k(e){let t=O(e);return Array.from({length:7},(e,n)=>D(t,n))}function A(e){let t=O(new Date(e.getFullYear(),e.getMonth(),1));return Array.from({length:42},(e,n)=>D(t,n))}function j(){return Array.from({length:24},(e,t)=>t)}function M(e){let t=e.getFullYear();return Array.from({length:12},(e,n)=>new Date(t,n,1))}function N(e,t){switch(e){case`day`:{let e=E(t);return{from:e,to:D(e,1)}}case`week`:{let e=O(t);return{from:e,to:D(e,7)}}case`month`:{let e=O(new Date(t.getFullYear(),t.getMonth(),1));return{from:e,to:D(e,42)}}case`year`:return{from:new Date(t.getFullYear(),0,1),to:new Date(t.getFullYear()+1,0,1)}}}function P(e,t,n){switch(e){case`day`:return D(t,n);case`week`:return D(t,n*7);case`month`:return new Date(t.getFullYear(),t.getMonth()+n,1);case`year`:return new Date(t.getFullYear()+n,t.getMonth(),1)}}function F(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function I(e,t){return{role:`button`,tabIndex:0,onClick:()=>t(e),onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),t(e))}}}var L=t(),R=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],z=3;function ee(e){return e.toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`})}function B({anchor:e,meetings:t,onSelect:n}){let r=A(e),i=e.getMonth(),a=new Date;return(0,L.jsxs)(`div`,{className:`cal-month`,children:[(0,L.jsx)(`div`,{className:`cal-weekday-row`,children:R.map(e=>(0,L.jsx)(`div`,{className:`cal-weekday`,children:e},e))}),(0,L.jsx)(`div`,{className:`cal-month-grid`,children:r.map(e=>{let r=t.filter(t=>F(new Date(t.startsAt),e)).sort((e,t)=>e.startsAt.localeCompare(t.startsAt)),o=e.getMonth()!==i,s=F(e,a);return(0,L.jsxs)(`div`,{className:`cal-cell${o?` cal-cell-out`:``}${s?` cal-cell-today`:``}`,children:[(0,L.jsx)(`div`,{className:`cal-cell-num`,children:e.getDate()}),r.slice(0,z).map(e=>(0,L.jsxs)(`div`,{className:`cal-chip`,title:e.title??`Untitled`,...I(e,n),children:[!e.isAllDay&&(0,L.jsx)(`span`,{className:`cal-chip-time`,children:ee(new Date(e.startsAt))}),e.title??`Untitled`]},e.meetingId)),r.length>z&&(0,L.jsxs)(`div`,{className:`cal-more`,children:[`+`,r.length-z,` more`]})]},e.toISOString())})})]})}var V=1440,H=1.8;function U(e){return e.getHours()*60+e.getMinutes()}function W(e){return e.toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`})}function G({day:e,meetings:t,hourHeight:n,onSelect:r}){let i=n*24,a=t.filter(t=>!t.isAllDay&&F(new Date(t.startsAt),e));return(0,L.jsx)(`div`,{className:`cal-day-col`,children:(0,L.jsxs)(`div`,{className:`cal-hours`,style:{height:`${i}px`},children:[Array.from({length:24},(e,t)=>(0,L.jsx)(`div`,{className:`cal-hour-line`,style:{top:`${t*n}px`}},t)),a.map(t=>{let n=new Date(t.startsAt),i=t.endsAt?new Date(t.endsAt):new Date(n.getTime()+30*6e4),a=U(n),o=F(i,e)?U(i):V,s=a/V*100,c=Math.max((o-a)/V*100,H);return(0,L.jsxs)(`div`,{className:`cal-event`,style:{top:`${s}%`,height:`${c}%`},title:t.title??`Untitled`,...I(t,r),children:[(0,L.jsx)(`span`,{className:`cal-event-time`,children:W(n)}),(0,L.jsx)(`span`,{className:`cal-event-title`,children:t.title??`Untitled`})]},t.meetingId)})]})})}var K=44;function q(e){let t=new Date;return t.setHours(e,0,0,0),t.toLocaleTimeString([],{hour:`numeric`})}function te({anchor:e,meetings:t,onSelect:n}){let r=k(e),i=new Date;return(0,L.jsxs)(`div`,{className:`cal-timed`,children:[(0,L.jsxs)(`div`,{className:`cal-day-headrow`,children:[(0,L.jsx)(`div`,{className:`cal-timed-gutter`}),r.map(e=>(0,L.jsxs)(`div`,{className:`cal-day-head${F(e,i)?` cal-day-head-today`:``}`,children:[(0,L.jsx)(`span`,{className:`cal-day-head-name`,children:e.toLocaleDateString([],{weekday:`short`})}),(0,L.jsx)(`span`,{className:`cal-day-head-num`,children:e.getDate()})]},e.toISOString()))]}),(0,L.jsxs)(`div`,{className:`cal-allday-band`,children:[(0,L.jsx)(`div`,{className:`cal-timed-gutter`,children:`All-day`}),r.map(e=>(0,L.jsx)(`div`,{className:`cal-allday-cell`,children:t.filter(t=>t.isAllDay&&F(new Date(t.startsAt),e)).map(e=>(0,L.jsx)(`div`,{className:`cal-allday-chip`,title:e.title??`Untitled`,...I(e,n),children:e.title??`Untitled`},e.meetingId))},e.toISOString()))]}),(0,L.jsxs)(`div`,{className:`cal-timed-cols`,children:[(0,L.jsx)(`div`,{className:`cal-timed-gutter`,children:j().map(e=>(0,L.jsx)(`div`,{className:`cal-hour-label`,style:{height:`${K}px`},children:e===0?``:q(e)},e))}),r.map(e=>(0,L.jsx)(G,{day:e,meetings:t,hourHeight:K,onSelect:n},e.toISOString()))]})]})}var J=52;function Y(e){let t=new Date;return t.setHours(e,0,0,0),t.toLocaleTimeString([],{hour:`numeric`})}function X({anchor:e,meetings:t,onSelect:n}){let r=t.filter(t=>t.isAllDay&&F(new Date(t.startsAt),e));return(0,L.jsxs)(`div`,{className:`cal-timed cal-timed-single`,children:[(0,L.jsxs)(`div`,{className:`cal-allday-band`,children:[(0,L.jsx)(`div`,{className:`cal-timed-gutter`,children:`All-day`}),(0,L.jsx)(`div`,{className:`cal-allday-cell`,children:r.map(e=>(0,L.jsx)(`div`,{className:`cal-allday-chip`,title:e.title??`Untitled`,...I(e,n),children:e.title??`Untitled`},e.meetingId))})]}),(0,L.jsxs)(`div`,{className:`cal-timed-cols`,children:[(0,L.jsx)(`div`,{className:`cal-timed-gutter`,children:j().map(e=>(0,L.jsx)(`div`,{className:`cal-hour-label`,style:{height:`${J}px`},children:e===0?``:Y(e)},e))}),(0,L.jsx)(G,{day:e,meetings:t,hourHeight:J,onSelect:n})]})]})}var ne=[`M`,`T`,`W`,`T`,`F`,`S`,`S`];function Z(e){return`${e.getFullYear()}-${e.getMonth()}-${e.getDate()}`}function re({anchor:e,meetings:t,onPickMonth:n}){let r=new Date,i=new Set(t.map(e=>Z(new Date(e.startsAt))));return(0,L.jsx)(`div`,{className:`cal-year`,children:(0,L.jsx)(`div`,{className:`cal-year-grid`,children:M(e).map(e=>{let t=A(e),a=e.getMonth();return(0,L.jsxs)(`button`,{type:`button`,className:`cal-mini`,onClick:()=>n(e),title:e.toLocaleDateString([],{month:`long`,year:`numeric`}),children:[(0,L.jsx)(`div`,{className:`cal-mini-title`,children:e.toLocaleDateString([],{month:`long`})}),(0,L.jsx)(`div`,{className:`cal-mini-weekrow`,children:ne.map((e,t)=>(0,L.jsx)(`span`,{className:`cal-mini-weekday`,children:e},t))}),(0,L.jsx)(`div`,{className:`cal-mini-grid`,children:t.map(e=>{let t=e.getMonth()!==a,n=F(e,r),o=!t&&i.has(Z(e));return(0,L.jsxs)(`span`,{className:`cal-mini-day${t?` cal-mini-day-out`:``}${n?` cal-mini-day-today`:``}`,children:[e.getDate(),o&&(0,L.jsx)(`span`,{className:`cal-mini-dot`})]},e.toISOString())})})]},a)})})})}var ie={meeting:`Meeting`,event:`Event`,task:`Task`};function ae(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}T${n(t.getHours())}:${n(t.getMinutes())}`}function oe(e){return new Date(e).toISOString()}function Q(e){return Math.floor(new Date(e).getTime()/6e4)}function se(e){let t=new Date(e.startsAt);if(e.isAllDay)return t.toLocaleDateString([],{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`});let n=t.toLocaleDateString([],{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`}),r=t.toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`});return e.endsAt?`${n} · ${r} – ${new Date(e.endsAt).toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`})}`:`${n} · ${r}`}function ce(e){if(!e)return null;let t=e.match(/filename="([^"]+)"/);return t?t[1]:null}function le(e,t){return e.email??`${e.name??`unknown`}-${t}`}function ue({a:e}){let t=e.name||e.email||`Unknown`,n=e.name&&e.email?e.email:null;return(0,L.jsxs)(`span`,{className:`cal-attendee-lines`,children:[(0,L.jsx)(`span`,{className:`cal-attendee-name`,children:t}),n&&(0,L.jsx)(`span`,{className:`cal-attendee-email`,children:n})]})}function de({meeting:e,adminFetch:t,onClose:n,onSaved:r,onDeleted:i}){let s=e.kind===`meeting`,[c,f]=(0,T.useState)(!1),[p,m]=(0,T.useState)(!1),[h,g]=(0,T.useState)(!1),[_,w]=(0,T.useState)(!1),[E,D]=(0,T.useState)(null),[O,k]=(0,T.useState)(e),[A,j]=(0,T.useState)(e.title??``),[M,N]=(0,T.useState)(ae(e.startsAt)),[P,F]=(0,T.useState)(e.endsAt?ae(e.endsAt):``),[I,R]=(0,T.useState)(e.location??``),[z,ee]=(0,T.useState)(e.privateNote??``),[B,V]=(0,T.useState)(``),[H,U]=(0,T.useState)(``);(0,T.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!_&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[_,n]);let W=(0,T.useCallback)(()=>{let e={},t=A.trim();t!==(O.title??``)&&(e.title=t);let n=oe(M);Q(n)!==Q(O.startsAt)&&(e.startsAt=n);let r=P?oe(P):null;(r===null?O.endsAt!==null:O.endsAt===null||Q(r)!==Q(O.endsAt))&&(e.endsAt=r);let i=I.trim()||null;i!==(O.location??null)&&(e.location=i);let a=z.trim()||null;return a!==(O.privateNote??null)&&(e.privateNote=a),e},[A,M,P,I,z,O]),G=(0,T.useCallback)(async()=>{let n=W();if(Object.keys(n).length===0){f(!1);return}w(!0),D(null);try{let i=await t(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(n)});if(!i.ok)throw Error(`HTTP ${i.status}`);let a=await i.json();k(a.meeting),r(a.meeting),f(!1)}catch(e){D(e instanceof Error?e.message:`Save failed`)}finally{w(!1)}},[t,W,e.meetingId,r]),K=(0,T.useCallback)(async()=>{let n=B.trim(),i=H.trim();if(!(!n&&!i)){w(!0),D(null);try{let a=await t(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}/attendees`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:n||void 0,email:i||void 0})});if(!a.ok)throw Error(`HTTP ${a.status}`);let o=await a.json();k(o.meeting),r(o.meeting),V(``),U(``)}catch(e){D(e instanceof Error?e.message:`Add failed`)}finally{w(!1)}}},[t,B,H,e.meetingId,r]),q=(0,T.useCallback)(async n=>{let i=n.email?{email:n.email}:{name:n.name};w(!0),D(null);try{let n=await t(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}/attendees`,{method:`DELETE`,headers:{"content-type":`application/json`},body:JSON.stringify(i)});if(!n.ok)throw Error(`HTTP ${n.status}`);let a=await n.json();k(a.meeting),r(a.meeting)}catch(e){D(e instanceof Error?e.message:`Remove failed`)}finally{w(!1)}},[t,e.meetingId,r]),te=(0,T.useCallback)(async()=>{w(!0),D(null);try{let n=await t(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}`,{method:`DELETE`});if(!n.ok)throw Error(`HTTP ${n.status}`);i(e.meetingId)}catch(e){D(e instanceof Error?e.message:`Delete failed`),w(!1)}},[t,e.meetingId,i]),J=(0,T.useCallback)(async n=>{g(!1),w(!0),D(null);try{let r=await t(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}/ics?attendees=${n?`1`:`0`}`);if(!r.ok)throw Error(`HTTP ${r.status}`);let i=await r.blob(),a=ce(r.headers.get(`content-disposition`))??`meeting.ics`,o=URL.createObjectURL(i),s=document.createElement(`a`);s.href=o,s.download=a,document.body.appendChild(s),s.click(),s.remove(),URL.revokeObjectURL(o)}catch(e){D(e instanceof Error?e.message:`Download failed`)}finally{w(!1)}},[t,e.meetingId]),Y=ie[e.kind??`meeting`],X=B.trim().length>0||H.trim().length>0;return(0,L.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{_||n()},children:(0,L.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":c?`Edit meeting`:`Meeting detail`,onClick:e=>e.stopPropagation(),children:[(0,L.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,L.jsx)(`span`,{className:`cal-modal-kind`,children:Y}),(0,L.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:n,"aria-label":`Close`,autoFocus:!0,disabled:_,children:(0,L.jsx)(u,{size:16})})]}),!c&&(0,L.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,L.jsx)(`div`,{className:`cal-modal-title`,children:O.title??`Untitled`}),(0,L.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,L.jsx)(v,{size:14}),(0,L.jsx)(`span`,{children:se(O)})]}),O.location&&(0,L.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,L.jsx)(b,{size:14}),(0,L.jsx)(`span`,{children:O.location})]}),O.attendees.length>0&&(0,L.jsxs)(`div`,{className:`cal-modal-row cal-modal-row-top`,children:[(0,L.jsx)(C,{size:14}),(0,L.jsx)(`div`,{className:`cal-modal-attendees`,children:O.attendees.map((e,t)=>(0,L.jsx)(`div`,{className:`cal-attendee-row`,children:(0,L.jsx)(ue,{a:e})},le(e,t)))})]}),O.privateNote&&(0,L.jsxs)(`div`,{className:`cal-modal-row cal-modal-row-top`,children:[(0,L.jsx)(x,{size:14}),(0,L.jsx)(`span`,{className:`cal-modal-note`,children:O.privateNote})]}),(0,L.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,L.jsx)(y,{size:14}),(0,L.jsx)(`span`,{children:Y})]})]}),c&&(0,L.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,L.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,L.jsx)(`span`,{children:`Title`}),(0,L.jsx)(`input`,{type:`text`,value:A,onChange:e=>j(e.target.value),disabled:_})]}),(0,L.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,L.jsx)(`span`,{children:`Start`}),(0,L.jsx)(`input`,{type:`datetime-local`,value:M,onChange:e=>N(e.target.value),disabled:_})]}),(0,L.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,L.jsx)(`span`,{children:`End`}),(0,L.jsx)(`input`,{type:`datetime-local`,value:P,onChange:e=>F(e.target.value),disabled:_})]}),(0,L.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,L.jsx)(`span`,{children:`Location`}),(0,L.jsx)(`input`,{type:`text`,value:I,onChange:e=>R(e.target.value),disabled:_})]}),(0,L.jsxs)(`div`,{className:`cal-modal-field`,children:[(0,L.jsx)(`span`,{children:`Attendees`}),(0,L.jsxs)(`div`,{className:`cal-modal-attendees cal-modal-attendees-edit`,children:[O.attendees.length===0&&(0,L.jsx)(`div`,{className:`cal-attendee-empty`,children:`No attendees yet.`}),O.attendees.map((e,t)=>(0,L.jsxs)(`div`,{className:`cal-attendee-row cal-attendee-row-edit`,children:[(0,L.jsx)(ue,{a:e}),(0,L.jsx)(`button`,{type:`button`,className:`cal-attendee-remove`,onClick:()=>q(e),disabled:_,"aria-label":`Remove ${e.name||e.email||`attendee`}`,children:(0,L.jsx)(u,{size:13})})]},le(e,t)))]}),(0,L.jsxs)(`div`,{className:`cal-attendee-add`,children:[(0,L.jsx)(`input`,{type:`text`,placeholder:`Name`,value:B,onChange:e=>V(e.target.value),disabled:_,"aria-label":`Attendee name`}),(0,L.jsx)(`input`,{type:`email`,placeholder:`Email`,value:H,onChange:e=>U(e.target.value),disabled:_,"aria-label":`Attendee email`}),(0,L.jsx)(`button`,{type:`button`,className:`cal-modal-btn cal-attendee-add-btn`,onClick:K,disabled:_||!X,"aria-label":`Add attendee`,children:_?(0,L.jsx)(o,{size:13,className:`spin`}):(0,L.jsx)(S,{size:13})})]})]}),(0,L.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,L.jsx)(`span`,{children:`Private note`}),(0,L.jsx)(`textarea`,{className:`cal-modal-textarea`,value:z,onChange:e=>ee(e.target.value),disabled:_,rows:3,placeholder:`Only you and your team can see this.`})]})]}),E&&(0,L.jsx)(`div`,{className:`cal-modal-error`,children:E}),s&&(0,L.jsxs)(`div`,{className:`cal-modal-actions`,children:[!c&&!p&&!h&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>f(!0),disabled:_,children:[(0,L.jsx)(a,{size:14}),` Edit`]}),(0,L.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:()=>m(!0),disabled:_,children:[(0,L.jsx)(l,{size:14}),` Delete`]}),(0,L.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-download`,onClick:()=>{O.attendees.length>0?g(!0):J(!1)},disabled:_,children:[_?(0,L.jsx)(o,{size:14,className:`spin`}):(0,L.jsx)(d,{size:14}),` Download`]})]}),h&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Include attendees in the file?`}),(0,L.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-primary`,onClick:()=>J(!0),disabled:_,children:[_?(0,L.jsx)(o,{size:14,className:`spin`}):null,` Yes`]}),(0,L.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>J(!1),disabled:_,children:`No`}),(0,L.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>g(!1),disabled:_,children:`Cancel`})]}),c&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-primary`,onClick:G,disabled:_,children:[_?(0,L.jsx)(o,{size:14,className:`spin`}):null,` Save`]}),(0,L.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>{f(!1),D(null)},disabled:_,children:`Cancel`})]}),p&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Delete this meeting?`}),(0,L.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:te,disabled:_,children:[_?(0,L.jsx)(o,{size:14,className:`spin`}):null,` Delete`]}),(0,L.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>m(!1),disabled:_,children:`Cancel`})]})]})]})})}var $=`maxy-admin-session-key`,fe=[`day`,`week`,`month`,`year`];function pe(e,t){switch(e){case`day`:return t.toLocaleDateString([],{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`});case`week`:{let{from:e,to:n}=N(`week`,t),r=new Date(n.getTime()-1);return`${e.toLocaleDateString([],{day:`numeric`,month:`short`})} – ${r.toLocaleDateString([],{day:`numeric`,month:`short`,year:`numeric`})}`}case`month`:return t.toLocaleDateString([],{month:`long`,year:`numeric`});case`year`:return String(t.getFullYear())}}function me(){let[e,t]=(0,T.useState)(null),[r,i]=(0,T.useState)(!1),[a,o]=(0,T.useState)(void 0),[s,c]=(0,T.useState)(null),[l,u]=(0,T.useState)(void 0),[d,m]=(0,T.useState)(null),[g,_]=(0,T.useState)(null);(0,T.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem($)}catch{}if(!n){i(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async r=>{if(!e){if(r.status===401){try{sessionStorage.removeItem($)}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,T.useCallback)(()=>{try{sessionStorage.removeItem($)}catch{}window.location.href=`/`},[]),[y,b]=(0,T.useState)(!1),x=(0,T.useCallback)(async()=>{b(!0);try{let e=await p();if(e){try{sessionStorage.removeItem($)}catch{}window.location.href=`/`}return e}finally{b(!1)}},[]);return r?e?(0,L.jsx)(f,{cacheKey:e,surface:`calendar`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=calendar`);try{sessionStorage.removeItem($)}catch{}window.location.href=`/`},children:(0,L.jsx)(h,{cacheKey:e,businessName:a,sessionId:s,onLogout:v,onDisconnect:x,disconnecting:y,userName:l,userAvatar:d,role:g,children:(0,L.jsx)(he,{cacheKey:e})})}):(0,L.jsx)(`div`,{className:`cal-page`,children:(0,L.jsxs)(`div`,{className:`cal-empty`,children:[(0,L.jsx)(`p`,{children:`You are not signed in.`}),(0,L.jsxs)(`p`,{children:[`Open the `,(0,L.jsx)(`a`,{href:`/`,className:`cal-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,L.jsx)(n,{surface:`gate`})}function he({cacheKey:e}){let{adminFetch:t,sessionRefetchNonce:r}=s({initialCacheKey:e,surface:`calendar`}),[i,a]=(0,T.useState)(`month`),[c,l]=(0,T.useState)(()=>new Date),[u,d]=(0,T.useState)([]),[f,p]=(0,T.useState)(!1),[h,v]=(0,T.useState)(!1),[y,b]=(0,T.useState)(null),[x,S]=(0,T.useState)(null),[C,w]=(0,T.useState)(null);(0,T.useEffect)(()=>{let e=!1;return t(`/api/admin/calendar/booking-link`).then(async t=>{if(e||!t.ok)return;let n=await t.json();typeof n.bookingDomain==`string`&&n.bookingDomain&&w(n.bookingDomain)}).catch(()=>{}),()=>{e=!0}},[t]),(0,T.useEffect)(()=>{let e=!1,{from:n,to:r}=N(i,c);return p(!0),b(null),t(`/api/admin/calendar/meetings?from=${encodeURIComponent(n.toISOString())}&to=${encodeURIComponent(r.toISOString())}`).then(async t=>{if(e)return;if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();d(Array.isArray(n.meetings)?n.meetings:[])}).catch(t=>{e||(b(t instanceof Error?t.message:`Failed to load`),d([]))}).finally(()=>{e||(p(!1),v(!0))}),()=>{e=!0}},[i,c,r,t]);let E=(0,T.useCallback)(()=>l(new Date),[]),D=(0,T.useCallback)(()=>l(e=>P(i,e,-1)),[i]),O=(0,T.useCallback)(()=>l(e=>P(i,e,1)),[i]),k=(0,T.useCallback)(e=>{l(e),a(`month`)},[]);(0,T.useEffect)(()=>{S(null)},[i,c]);let A=(0,T.useCallback)(e=>{d(t=>t.map(t=>t.meetingId===e.meetingId?e:t)),S(e)},[]),j=(0,T.useCallback)(e=>{d(t=>t.filter(t=>t.meetingId!==e)),S(null)},[]);return h?(0,L.jsxs)(`div`,{className:`cal-page`,children:[(0,L.jsxs)(`header`,{className:`cal-header`,children:[(0,L.jsxs)(`div`,{className:`cal-nav`,children:[(0,L.jsx)(`span`,{className:`cal-range-label`,children:pe(i,c)}),(0,L.jsx)(`button`,{type:`button`,className:`cal-nav-btn`,onClick:D,"aria-label":`Previous`,children:(0,L.jsx)(g,{size:18})}),(0,L.jsx)(`button`,{type:`button`,className:`cal-nav-btn`,onClick:O,"aria-label":`Next`,children:(0,L.jsx)(_,{size:18})}),(0,L.jsx)(`button`,{type:`button`,className:`cal-today-btn`,onClick:E,children:`Today`}),f&&(0,L.jsx)(o,{size:16,className:`spin`})]}),(0,L.jsx)(`div`,{className:`cal-views`,children:fe.map(e=>(0,L.jsx)(`button`,{type:`button`,className:`cal-view-btn${e===i?` cal-view-btn-active`:``}`,onClick:()=>a(e),children:e.charAt(0).toUpperCase()+e.slice(1)},e))}),C&&(0,L.jsxs)(`a`,{className:`cal-booking-link`,href:`https://${C}`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,L.jsx)(m,{size:14}),` Booking page`]})]}),(0,L.jsxs)(`div`,{className:`cal-body`,children:[y&&(0,L.jsxs)(`div`,{className:`cal-error`,children:[`Could not load the calendar: `,y]}),i===`day`&&(0,L.jsx)(X,{anchor:c,meetings:u,onSelect:S}),i===`week`&&(0,L.jsx)(te,{anchor:c,meetings:u,onSelect:S}),i===`month`&&(0,L.jsx)(B,{anchor:c,meetings:u,onSelect:S}),i===`year`&&(0,L.jsx)(re,{anchor:c,meetings:u,onPickMonth:k})]}),x&&(0,L.jsx)(de,{meeting:x,adminFetch:t,onClose:()=>S(null),onSaved:A,onDeleted:j})]}):(0,L.jsx)(n,{surface:`gate`})}(0,w.createRoot)(document.getElementById(`root`)).render((0,L.jsx)(me,{}));
1
+ import{o as e}from"./chunk-CltuBf4Z.js";import{B as t,F as n,K as r,P as i,S as a,T as o,U as s,W as c,_ as l,g as u,k as d,p as f}from"./useSubAccountSwitcher-0PfRrN6i.js";import{T as p,_ as m,t as h}from"./AdminShell-Ckht9hmU.js";import{t as g}from"./chevron-left-Dtk3jEK5.js";import{t as _}from"./chevron-right-Dih6IZ8B.js";import{t as v}from"./clock-iJCrrmWM.js";var y=i(`calendar`,[[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`rect`,{width:`18`,height:`18`,x:`3`,y:`4`,rx:`2`,key:`1hopcy`}],[`path`,{d:`M3 10h18`,key:`8toen8`}]]),b=i(`map-pin`,[[`path`,{d:`M20 10c0 4.993-5.539 10.193-7.399 11.799a1 1 0 0 1-1.202 0C9.539 20.193 4 14.993 4 10a8 8 0 0 1 16 0`,key:`1r0f0z`}],[`circle`,{cx:`12`,cy:`10`,r:`3`,key:`ilqhr7`}]]),x=i(`sticky-note`,[[`path`,{d:`M21 9a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 15 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2z`,key:`1dfntj`}],[`path`,{d:`M15 3v5a1 1 0 0 0 1 1h5`,key:`6s6qgf`}]]),S=i(`user-plus`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`19`,x2:`19`,y1:`8`,y2:`14`,key:`1bvyxn`}],[`line`,{x1:`22`,x2:`16`,y1:`11`,y2:`11`,key:`1shjgl`}]]),C=i(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),w=c(),T=e(r(),1);function E(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function D(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n}function O(e){let t=E(e),n=t.getDay();return D(t,n===0?-6:1-n)}function k(e){let t=O(e);return Array.from({length:7},(e,n)=>D(t,n))}function A(e){let t=O(new Date(e.getFullYear(),e.getMonth(),1));return Array.from({length:42},(e,n)=>D(t,n))}function j(){return Array.from({length:24},(e,t)=>t)}function M(e){let t=e.getFullYear();return Array.from({length:12},(e,n)=>new Date(t,n,1))}function N(e,t){switch(e){case`day`:{let e=E(t);return{from:e,to:D(e,1)}}case`week`:{let e=O(t);return{from:e,to:D(e,7)}}case`month`:{let e=O(new Date(t.getFullYear(),t.getMonth(),1));return{from:e,to:D(e,42)}}case`year`:return{from:new Date(t.getFullYear(),0,1),to:new Date(t.getFullYear()+1,0,1)}}}function P(e,t,n){switch(e){case`day`:return D(t,n);case`week`:return D(t,n*7);case`month`:return new Date(t.getFullYear(),t.getMonth()+n,1);case`year`:return new Date(t.getFullYear()+n,t.getMonth(),1)}}function F(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function I(e,t){return{role:`button`,tabIndex:0,onClick:()=>t(e),onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),t(e))}}}var L=t(),R=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],z=3;function ee(e){return e.toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`})}function B({anchor:e,meetings:t,onSelect:n}){let r=A(e),i=e.getMonth(),a=new Date;return(0,L.jsxs)(`div`,{className:`cal-month`,children:[(0,L.jsx)(`div`,{className:`cal-weekday-row`,children:R.map(e=>(0,L.jsx)(`div`,{className:`cal-weekday`,children:e},e))}),(0,L.jsx)(`div`,{className:`cal-month-grid`,children:r.map(e=>{let r=t.filter(t=>F(new Date(t.startsAt),e)).sort((e,t)=>e.startsAt.localeCompare(t.startsAt)),o=e.getMonth()!==i,s=F(e,a);return(0,L.jsxs)(`div`,{className:`cal-cell${o?` cal-cell-out`:``}${s?` cal-cell-today`:``}`,children:[(0,L.jsx)(`div`,{className:`cal-cell-num`,children:e.getDate()}),r.slice(0,z).map(e=>(0,L.jsxs)(`div`,{className:`cal-chip`,title:e.title??`Untitled`,...I(e,n),children:[!e.isAllDay&&(0,L.jsx)(`span`,{className:`cal-chip-time`,children:ee(new Date(e.startsAt))}),e.title??`Untitled`]},e.meetingId)),r.length>z&&(0,L.jsxs)(`div`,{className:`cal-more`,children:[`+`,r.length-z,` more`]})]},e.toISOString())})})]})}var V=1440,H=1.8;function U(e){return e.getHours()*60+e.getMinutes()}function W(e){return e.toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`})}function G({day:e,meetings:t,hourHeight:n,onSelect:r}){let i=n*24,a=t.filter(t=>!t.isAllDay&&F(new Date(t.startsAt),e));return(0,L.jsx)(`div`,{className:`cal-day-col`,children:(0,L.jsxs)(`div`,{className:`cal-hours`,style:{height:`${i}px`},children:[Array.from({length:24},(e,t)=>(0,L.jsx)(`div`,{className:`cal-hour-line`,style:{top:`${t*n}px`}},t)),a.map(t=>{let n=new Date(t.startsAt),i=t.endsAt?new Date(t.endsAt):new Date(n.getTime()+30*6e4),a=U(n),o=F(i,e)?U(i):V,s=a/V*100,c=Math.max((o-a)/V*100,H);return(0,L.jsxs)(`div`,{className:`cal-event`,style:{top:`${s}%`,height:`${c}%`},title:t.title??`Untitled`,...I(t,r),children:[(0,L.jsx)(`span`,{className:`cal-event-time`,children:W(n)}),(0,L.jsx)(`span`,{className:`cal-event-title`,children:t.title??`Untitled`})]},t.meetingId)})]})})}var K=44;function q(e){let t=new Date;return t.setHours(e,0,0,0),t.toLocaleTimeString([],{hour:`numeric`})}function te({anchor:e,meetings:t,onSelect:n}){let r=k(e),i=new Date;return(0,L.jsxs)(`div`,{className:`cal-timed`,children:[(0,L.jsxs)(`div`,{className:`cal-day-headrow`,children:[(0,L.jsx)(`div`,{className:`cal-timed-gutter`}),r.map(e=>(0,L.jsxs)(`div`,{className:`cal-day-head${F(e,i)?` cal-day-head-today`:``}`,children:[(0,L.jsx)(`span`,{className:`cal-day-head-name`,children:e.toLocaleDateString([],{weekday:`short`})}),(0,L.jsx)(`span`,{className:`cal-day-head-num`,children:e.getDate()})]},e.toISOString()))]}),(0,L.jsxs)(`div`,{className:`cal-allday-band`,children:[(0,L.jsx)(`div`,{className:`cal-timed-gutter`,children:`All-day`}),r.map(e=>(0,L.jsx)(`div`,{className:`cal-allday-cell`,children:t.filter(t=>t.isAllDay&&F(new Date(t.startsAt),e)).map(e=>(0,L.jsx)(`div`,{className:`cal-allday-chip`,title:e.title??`Untitled`,...I(e,n),children:e.title??`Untitled`},e.meetingId))},e.toISOString()))]}),(0,L.jsxs)(`div`,{className:`cal-timed-cols`,children:[(0,L.jsx)(`div`,{className:`cal-timed-gutter`,children:j().map(e=>(0,L.jsx)(`div`,{className:`cal-hour-label`,style:{height:`${K}px`},children:e===0?``:q(e)},e))}),r.map(e=>(0,L.jsx)(G,{day:e,meetings:t,hourHeight:K,onSelect:n},e.toISOString()))]})]})}var J=52;function Y(e){let t=new Date;return t.setHours(e,0,0,0),t.toLocaleTimeString([],{hour:`numeric`})}function X({anchor:e,meetings:t,onSelect:n}){let r=t.filter(t=>t.isAllDay&&F(new Date(t.startsAt),e));return(0,L.jsxs)(`div`,{className:`cal-timed cal-timed-single`,children:[(0,L.jsxs)(`div`,{className:`cal-allday-band`,children:[(0,L.jsx)(`div`,{className:`cal-timed-gutter`,children:`All-day`}),(0,L.jsx)(`div`,{className:`cal-allday-cell`,children:r.map(e=>(0,L.jsx)(`div`,{className:`cal-allday-chip`,title:e.title??`Untitled`,...I(e,n),children:e.title??`Untitled`},e.meetingId))})]}),(0,L.jsxs)(`div`,{className:`cal-timed-cols`,children:[(0,L.jsx)(`div`,{className:`cal-timed-gutter`,children:j().map(e=>(0,L.jsx)(`div`,{className:`cal-hour-label`,style:{height:`${J}px`},children:e===0?``:Y(e)},e))}),(0,L.jsx)(G,{day:e,meetings:t,hourHeight:J,onSelect:n})]})]})}var ne=[`M`,`T`,`W`,`T`,`F`,`S`,`S`];function Z(e){return`${e.getFullYear()}-${e.getMonth()}-${e.getDate()}`}function re({anchor:e,meetings:t,onPickMonth:n}){let r=new Date,i=new Set(t.map(e=>Z(new Date(e.startsAt))));return(0,L.jsx)(`div`,{className:`cal-year`,children:(0,L.jsx)(`div`,{className:`cal-year-grid`,children:M(e).map(e=>{let t=A(e),a=e.getMonth();return(0,L.jsxs)(`button`,{type:`button`,className:`cal-mini`,onClick:()=>n(e),title:e.toLocaleDateString([],{month:`long`,year:`numeric`}),children:[(0,L.jsx)(`div`,{className:`cal-mini-title`,children:e.toLocaleDateString([],{month:`long`})}),(0,L.jsx)(`div`,{className:`cal-mini-weekrow`,children:ne.map((e,t)=>(0,L.jsx)(`span`,{className:`cal-mini-weekday`,children:e},t))}),(0,L.jsx)(`div`,{className:`cal-mini-grid`,children:t.map(e=>{let t=e.getMonth()!==a,n=F(e,r),o=!t&&i.has(Z(e));return(0,L.jsxs)(`span`,{className:`cal-mini-day${t?` cal-mini-day-out`:``}${n?` cal-mini-day-today`:``}`,children:[e.getDate(),o&&(0,L.jsx)(`span`,{className:`cal-mini-dot`})]},e.toISOString())})})]},a)})})})}var ie={meeting:`Meeting`,event:`Event`,task:`Task`};function ae(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}T${n(t.getHours())}:${n(t.getMinutes())}`}function oe(e){return new Date(e).toISOString()}function Q(e){return Math.floor(new Date(e).getTime()/6e4)}function se(e){let t=new Date(e.startsAt);if(e.isAllDay)return t.toLocaleDateString([],{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`});let n=t.toLocaleDateString([],{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`}),r=t.toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`});return e.endsAt?`${n} · ${r} – ${new Date(e.endsAt).toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`})}`:`${n} · ${r}`}function ce(e){if(!e)return null;let t=e.match(/filename="([^"]+)"/);return t?t[1]:null}function le(e,t){return e.email??`${e.name??`unknown`}-${t}`}function ue({a:e}){let t=e.name||e.email||`Unknown`,n=e.name&&e.email?e.email:null;return(0,L.jsxs)(`span`,{className:`cal-attendee-lines`,children:[(0,L.jsx)(`span`,{className:`cal-attendee-name`,children:t}),n&&(0,L.jsx)(`span`,{className:`cal-attendee-email`,children:n})]})}function de({meeting:e,adminFetch:t,onClose:n,onSaved:r,onDeleted:i}){let s=e.kind===`meeting`,[c,f]=(0,T.useState)(!1),[p,m]=(0,T.useState)(!1),[h,g]=(0,T.useState)(!1),[_,w]=(0,T.useState)(!1),[E,D]=(0,T.useState)(null),[O,k]=(0,T.useState)(e),[A,j]=(0,T.useState)(e.title??``),[M,N]=(0,T.useState)(ae(e.startsAt)),[P,F]=(0,T.useState)(e.endsAt?ae(e.endsAt):``),[I,R]=(0,T.useState)(e.location??``),[z,ee]=(0,T.useState)(e.privateNote??``),[B,V]=(0,T.useState)(``),[H,U]=(0,T.useState)(``);(0,T.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!_&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[_,n]);let W=(0,T.useCallback)(()=>{let e={},t=A.trim();t!==(O.title??``)&&(e.title=t);let n=oe(M);Q(n)!==Q(O.startsAt)&&(e.startsAt=n);let r=P?oe(P):null;(r===null?O.endsAt!==null:O.endsAt===null||Q(r)!==Q(O.endsAt))&&(e.endsAt=r);let i=I.trim()||null;i!==(O.location??null)&&(e.location=i);let a=z.trim()||null;return a!==(O.privateNote??null)&&(e.privateNote=a),e},[A,M,P,I,z,O]),G=(0,T.useCallback)(async()=>{let n=W();if(Object.keys(n).length===0){f(!1);return}w(!0),D(null);try{let i=await t(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(n)});if(!i.ok)throw Error(`HTTP ${i.status}`);let a=await i.json();k(a.meeting),r(a.meeting),f(!1)}catch(e){D(e instanceof Error?e.message:`Save failed`)}finally{w(!1)}},[t,W,e.meetingId,r]),K=(0,T.useCallback)(async()=>{let n=B.trim(),i=H.trim();if(!(!n&&!i)){w(!0),D(null);try{let a=await t(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}/attendees`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:n||void 0,email:i||void 0})});if(!a.ok)throw Error(`HTTP ${a.status}`);let o=await a.json();k(o.meeting),r(o.meeting),V(``),U(``)}catch(e){D(e instanceof Error?e.message:`Add failed`)}finally{w(!1)}}},[t,B,H,e.meetingId,r]),q=(0,T.useCallback)(async n=>{let i=n.email?{email:n.email}:{name:n.name};w(!0),D(null);try{let n=await t(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}/attendees`,{method:`DELETE`,headers:{"content-type":`application/json`},body:JSON.stringify(i)});if(!n.ok)throw Error(`HTTP ${n.status}`);let a=await n.json();k(a.meeting),r(a.meeting)}catch(e){D(e instanceof Error?e.message:`Remove failed`)}finally{w(!1)}},[t,e.meetingId,r]),te=(0,T.useCallback)(async()=>{w(!0),D(null);try{let n=await t(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}`,{method:`DELETE`});if(!n.ok)throw Error(`HTTP ${n.status}`);i(e.meetingId)}catch(e){D(e instanceof Error?e.message:`Delete failed`),w(!1)}},[t,e.meetingId,i]),J=(0,T.useCallback)(async n=>{g(!1),w(!0),D(null);try{let r=await t(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}/ics?attendees=${n?`1`:`0`}`);if(!r.ok)throw Error(`HTTP ${r.status}`);let i=await r.blob(),a=ce(r.headers.get(`content-disposition`))??`meeting.ics`,o=URL.createObjectURL(i),s=document.createElement(`a`);s.href=o,s.download=a,document.body.appendChild(s),s.click(),s.remove(),URL.revokeObjectURL(o)}catch(e){D(e instanceof Error?e.message:`Download failed`)}finally{w(!1)}},[t,e.meetingId]),Y=ie[e.kind??`meeting`],X=B.trim().length>0||H.trim().length>0;return(0,L.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{_||n()},children:(0,L.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":c?`Edit meeting`:`Meeting detail`,onClick:e=>e.stopPropagation(),children:[(0,L.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,L.jsx)(`span`,{className:`cal-modal-kind`,children:Y}),(0,L.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:n,"aria-label":`Close`,autoFocus:!0,disabled:_,children:(0,L.jsx)(u,{size:16})})]}),!c&&(0,L.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,L.jsx)(`div`,{className:`cal-modal-title`,children:O.title??`Untitled`}),(0,L.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,L.jsx)(v,{size:14}),(0,L.jsx)(`span`,{children:se(O)})]}),O.location&&(0,L.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,L.jsx)(b,{size:14}),(0,L.jsx)(`span`,{children:O.location})]}),O.attendees.length>0&&(0,L.jsxs)(`div`,{className:`cal-modal-row cal-modal-row-top`,children:[(0,L.jsx)(C,{size:14}),(0,L.jsx)(`div`,{className:`cal-modal-attendees`,children:O.attendees.map((e,t)=>(0,L.jsx)(`div`,{className:`cal-attendee-row`,children:(0,L.jsx)(ue,{a:e})},le(e,t)))})]}),O.privateNote&&(0,L.jsxs)(`div`,{className:`cal-modal-row cal-modal-row-top`,children:[(0,L.jsx)(x,{size:14}),(0,L.jsx)(`span`,{className:`cal-modal-note`,children:O.privateNote})]}),(0,L.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,L.jsx)(y,{size:14}),(0,L.jsx)(`span`,{children:Y})]})]}),c&&(0,L.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,L.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,L.jsx)(`span`,{children:`Title`}),(0,L.jsx)(`input`,{type:`text`,value:A,onChange:e=>j(e.target.value),disabled:_})]}),(0,L.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,L.jsx)(`span`,{children:`Start`}),(0,L.jsx)(`input`,{type:`datetime-local`,value:M,onChange:e=>N(e.target.value),disabled:_})]}),(0,L.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,L.jsx)(`span`,{children:`End`}),(0,L.jsx)(`input`,{type:`datetime-local`,value:P,onChange:e=>F(e.target.value),disabled:_})]}),(0,L.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,L.jsx)(`span`,{children:`Location`}),(0,L.jsx)(`input`,{type:`text`,value:I,onChange:e=>R(e.target.value),disabled:_})]}),(0,L.jsxs)(`div`,{className:`cal-modal-field`,children:[(0,L.jsx)(`span`,{children:`Attendees`}),(0,L.jsxs)(`div`,{className:`cal-modal-attendees cal-modal-attendees-edit`,children:[O.attendees.length===0&&(0,L.jsx)(`div`,{className:`cal-attendee-empty`,children:`No attendees yet.`}),O.attendees.map((e,t)=>(0,L.jsxs)(`div`,{className:`cal-attendee-row cal-attendee-row-edit`,children:[(0,L.jsx)(ue,{a:e}),(0,L.jsx)(`button`,{type:`button`,className:`cal-attendee-remove`,onClick:()=>q(e),disabled:_,"aria-label":`Remove ${e.name||e.email||`attendee`}`,children:(0,L.jsx)(u,{size:13})})]},le(e,t)))]}),(0,L.jsxs)(`div`,{className:`cal-attendee-add`,children:[(0,L.jsx)(`input`,{type:`text`,placeholder:`Name`,value:B,onChange:e=>V(e.target.value),disabled:_,"aria-label":`Attendee name`}),(0,L.jsx)(`input`,{type:`email`,placeholder:`Email`,value:H,onChange:e=>U(e.target.value),disabled:_,"aria-label":`Attendee email`}),(0,L.jsx)(`button`,{type:`button`,className:`cal-modal-btn cal-attendee-add-btn`,onClick:K,disabled:_||!X,"aria-label":`Add attendee`,children:_?(0,L.jsx)(o,{size:13,className:`spin`}):(0,L.jsx)(S,{size:13})})]})]}),(0,L.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,L.jsx)(`span`,{children:`Private note`}),(0,L.jsx)(`textarea`,{className:`cal-modal-textarea`,value:z,onChange:e=>ee(e.target.value),disabled:_,rows:3,placeholder:`Only you and your team can see this.`})]})]}),E&&(0,L.jsx)(`div`,{className:`cal-modal-error`,children:E}),s&&(0,L.jsxs)(`div`,{className:`cal-modal-actions`,children:[!c&&!p&&!h&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>f(!0),disabled:_,children:[(0,L.jsx)(a,{size:14}),` Edit`]}),(0,L.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:()=>m(!0),disabled:_,children:[(0,L.jsx)(l,{size:14}),` Delete`]}),(0,L.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-download`,onClick:()=>{O.attendees.length>0?g(!0):J(!1)},disabled:_,children:[_?(0,L.jsx)(o,{size:14,className:`spin`}):(0,L.jsx)(d,{size:14}),` Download`]})]}),h&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Include attendees in the file?`}),(0,L.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-primary`,onClick:()=>J(!0),disabled:_,children:[_?(0,L.jsx)(o,{size:14,className:`spin`}):null,` Yes`]}),(0,L.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>J(!1),disabled:_,children:`No`}),(0,L.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>g(!1),disabled:_,children:`Cancel`})]}),c&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-primary`,onClick:G,disabled:_,children:[_?(0,L.jsx)(o,{size:14,className:`spin`}):null,` Save`]}),(0,L.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>{f(!1),D(null)},disabled:_,children:`Cancel`})]}),p&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Delete this meeting?`}),(0,L.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:te,disabled:_,children:[_?(0,L.jsx)(o,{size:14,className:`spin`}):null,` Delete`]}),(0,L.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>m(!1),disabled:_,children:`Cancel`})]})]})]})})}var $=`maxy-admin-session-key`,fe=[`day`,`week`,`month`,`year`];function pe(e,t){switch(e){case`day`:return t.toLocaleDateString([],{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`});case`week`:{let{from:e,to:n}=N(`week`,t),r=new Date(n.getTime()-1);return`${e.toLocaleDateString([],{day:`numeric`,month:`short`})} – ${r.toLocaleDateString([],{day:`numeric`,month:`short`,year:`numeric`})}`}case`month`:return t.toLocaleDateString([],{month:`long`,year:`numeric`});case`year`:return String(t.getFullYear())}}function me(){let[e,t]=(0,T.useState)(null),[r,i]=(0,T.useState)(!1),[a,o]=(0,T.useState)(void 0),[s,c]=(0,T.useState)(null),[l,u]=(0,T.useState)(void 0),[d,m]=(0,T.useState)(null),[g,_]=(0,T.useState)(null);(0,T.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem($)}catch{}if(!n){i(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async r=>{if(!e){if(r.status===401){try{sessionStorage.removeItem($)}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,T.useCallback)(()=>{try{sessionStorage.removeItem($)}catch{}window.location.href=`/`},[]),[y,b]=(0,T.useState)(!1),x=(0,T.useCallback)(async()=>{b(!0);try{let e=await p();if(e){try{sessionStorage.removeItem($)}catch{}window.location.href=`/`}return e}finally{b(!1)}},[]);return r?e?(0,L.jsx)(f,{cacheKey:e,surface:`calendar`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=calendar`);try{sessionStorage.removeItem($)}catch{}window.location.href=`/`},children:(0,L.jsx)(h,{cacheKey:e,businessName:a,sessionId:s,onLogout:v,onDisconnect:x,disconnecting:y,userName:l,userAvatar:d,role:g,children:(0,L.jsx)(he,{cacheKey:e})})}):(0,L.jsx)(`div`,{className:`cal-page`,children:(0,L.jsxs)(`div`,{className:`cal-empty`,children:[(0,L.jsx)(`p`,{children:`You are not signed in.`}),(0,L.jsxs)(`p`,{children:[`Open the `,(0,L.jsx)(`a`,{href:`/`,className:`cal-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,L.jsx)(n,{surface:`gate`})}function he({cacheKey:e}){let{adminFetch:t,sessionRefetchNonce:r}=s({initialCacheKey:e,surface:`calendar`}),[i,a]=(0,T.useState)(`month`),[c,l]=(0,T.useState)(()=>new Date),[u,d]=(0,T.useState)([]),[f,p]=(0,T.useState)(!1),[h,v]=(0,T.useState)(!1),[y,b]=(0,T.useState)(null),[x,S]=(0,T.useState)(null),[C,w]=(0,T.useState)(null);(0,T.useEffect)(()=>{let e=!1;return t(`/api/admin/calendar/booking-link`).then(async t=>{if(e||!t.ok)return;let n=await t.json();typeof n.bookingDomain==`string`&&n.bookingDomain&&w(n.bookingDomain)}).catch(()=>{}),()=>{e=!0}},[t]),(0,T.useEffect)(()=>{let e=!1,{from:n,to:r}=N(i,c);return p(!0),b(null),t(`/api/admin/calendar/meetings?from=${encodeURIComponent(n.toISOString())}&to=${encodeURIComponent(r.toISOString())}`).then(async t=>{if(e)return;if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();d(Array.isArray(n.meetings)?n.meetings:[])}).catch(t=>{e||(b(t instanceof Error?t.message:`Failed to load`),d([]))}).finally(()=>{e||(p(!1),v(!0))}),()=>{e=!0}},[i,c,r,t]);let E=(0,T.useCallback)(()=>l(new Date),[]),D=(0,T.useCallback)(()=>l(e=>P(i,e,-1)),[i]),O=(0,T.useCallback)(()=>l(e=>P(i,e,1)),[i]),k=(0,T.useCallback)(e=>{l(e),a(`month`)},[]);(0,T.useEffect)(()=>{S(null)},[i,c]);let A=(0,T.useCallback)(e=>{d(t=>t.map(t=>t.meetingId===e.meetingId?e:t)),S(e)},[]),j=(0,T.useCallback)(e=>{d(t=>t.filter(t=>t.meetingId!==e)),S(null)},[]);return h?(0,L.jsxs)(`div`,{className:`cal-page`,children:[(0,L.jsxs)(`header`,{className:`cal-header`,children:[(0,L.jsxs)(`div`,{className:`cal-nav`,children:[(0,L.jsx)(`span`,{className:`cal-range-label`,children:pe(i,c)}),(0,L.jsx)(`button`,{type:`button`,className:`cal-nav-btn`,onClick:D,"aria-label":`Previous`,children:(0,L.jsx)(g,{size:18})}),(0,L.jsx)(`button`,{type:`button`,className:`cal-nav-btn`,onClick:O,"aria-label":`Next`,children:(0,L.jsx)(_,{size:18})}),(0,L.jsx)(`button`,{type:`button`,className:`cal-today-btn`,onClick:E,children:`Today`}),f&&(0,L.jsx)(o,{size:16,className:`spin`})]}),(0,L.jsx)(`div`,{className:`cal-views`,children:fe.map(e=>(0,L.jsx)(`button`,{type:`button`,className:`cal-view-btn${e===i?` cal-view-btn-active`:``}`,onClick:()=>a(e),children:e.charAt(0).toUpperCase()+e.slice(1)},e))}),C&&(0,L.jsxs)(`a`,{className:`cal-booking-link`,href:`https://${C}`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,L.jsx)(m,{size:14}),` Booking page`]})]}),(0,L.jsxs)(`div`,{className:`cal-body`,children:[y&&(0,L.jsxs)(`div`,{className:`cal-error`,children:[`Could not load the calendar: `,y]}),i===`day`&&(0,L.jsx)(X,{anchor:c,meetings:u,onSelect:S}),i===`week`&&(0,L.jsx)(te,{anchor:c,meetings:u,onSelect:S}),i===`month`&&(0,L.jsx)(B,{anchor:c,meetings:u,onSelect:S}),i===`year`&&(0,L.jsx)(re,{anchor:c,meetings:u,onPickMonth:k})]}),x&&(0,L.jsx)(de,{meeting:x,adminFetch:t,onClose:()=>S(null),onSaved:A,onDeleted:j})]}):(0,L.jsx)(n,{surface:`gate`})}(0,w.createRoot)(document.getElementById(`root`)).render((0,L.jsx)(me,{}));
@@ -0,0 +1 @@
1
+ import{B as e,W as t}from"./useSubAccountSwitcher-0PfRrN6i.js";import"./useVoiceRecorder-BP6CpYQD.js";import"./AdminShell-Ckht9hmU.js";import{n}from"./page-D6M1CmPe.js";import"./useCopyFeedback-BFOujMl-.js";var r=t(),i=e();(0,r.createRoot)(document.getElementById(`root`)).render((0,i.jsx)(n,{}));
@@ -0,0 +1 @@
1
+ import{P as e}from"./useSubAccountSwitcher-0PfRrN6i.js";var t=e(`chevron-left`,[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]);export{t};
@@ -0,0 +1 @@
1
+ import{P as e}from"./useSubAccountSwitcher-0PfRrN6i.js";var t=e(`chevron-right`,[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]);export{t};
@@ -0,0 +1 @@
1
+ import{P as e}from"./useSubAccountSwitcher-0PfRrN6i.js";var t=e(`clock`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6l4 2`,key:`mmk7yg`}]]);export{t};
@@ -0,0 +1 @@
1
+ import{B as e,W as t}from"./useSubAccountSwitcher-0PfRrN6i.js";import"./useVoiceRecorder-BP6CpYQD.js";import{t as n}from"./page-3T2mE63b.js";import"./graph-labels-CBwh4g-6.js";var r=t(),i=e();(0,r.createRoot)(document.getElementById(`root`)).render((0,i.jsx)(n,{}));
@@ -1 +1 @@
1
- import{P as e}from"./useSubAccountSwitcher-DSW9vDi2.js";var t=e(`file-text`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]);export{t};
1
+ import{P as e}from"./useSubAccountSwitcher-0PfRrN6i.js";var t=e(`file-text`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]);export{t};