@rubytech/create-sitedesk-code 0.1.609 → 0.1.611
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.
- package/package.json +1 -1
- package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +45 -23
- package/payload/platform/plugins/admin/skills/whats-new/SKILL.md +9 -0
- package/payload/platform/plugins/docs/references/telegram-guide.md +44 -22
- package/payload/server/public/activity.html +6 -6
- package/payload/server/public/agents.html +5 -5
- package/payload/server/public/assets/{AdminLoginScreens-BBKEIEjY.js → AdminLoginScreens-Bjsr45ed.js} +1 -1
- package/payload/server/public/assets/AdminLoginScreens-Bjsr45ed.js.br +0 -0
- package/payload/server/public/assets/AdminLoginScreens-Bjsr45ed.js.gz +0 -0
- package/payload/server/public/assets/AdminShell-Dm_nY4jF.js +3 -0
- package/payload/server/public/assets/AdminShell-Dm_nY4jF.js.br +0 -0
- package/payload/server/public/assets/AdminShell-Dm_nY4jF.js.gz +0 -0
- package/payload/server/public/assets/{activity-CbR3vaq1.js → activity-Dz5eWZze.js} +1 -1
- package/payload/server/public/assets/activity-Dz5eWZze.js.br +0 -0
- package/payload/server/public/assets/activity-Dz5eWZze.js.gz +0 -0
- package/payload/server/public/assets/admin-B2IkUoSc.js +1 -0
- package/payload/server/public/assets/admin-B2IkUoSc.js.br +0 -0
- package/payload/server/public/assets/admin-B2IkUoSc.js.gz +0 -0
- package/payload/server/public/assets/{agents-8gAQjRqI.js → agents-DjDwemOg.js} +1 -1
- package/payload/server/public/assets/agents-DjDwemOg.js.br +0 -0
- package/payload/server/public/assets/agents-DjDwemOg.js.gz +0 -0
- package/payload/server/public/assets/{browser-jAje5ILy.js → browser-BDFx14YM.js} +1 -1
- package/payload/server/public/assets/browser-BDFx14YM.js.br +0 -0
- package/payload/server/public/assets/browser-BDFx14YM.js.gz +0 -0
- package/payload/server/public/assets/{calendar-xEmCJif9.js → calendar-BbUsdMKW.js} +1 -1
- package/payload/server/public/assets/calendar-BbUsdMKW.js.br +0 -0
- package/payload/server/public/assets/calendar-BbUsdMKW.js.gz +0 -0
- package/payload/server/public/assets/chat-fP4sE4pU.js +1 -0
- package/payload/server/public/assets/chat-fP4sE4pU.js.br +2 -0
- package/payload/server/public/assets/chat-fP4sE4pU.js.gz +0 -0
- package/payload/server/public/assets/{chevron-left-DV8gIVC9.js → chevron-left-D3_hiHLC.js} +1 -1
- package/payload/server/public/assets/chevron-left-D3_hiHLC.js.br +0 -0
- package/payload/server/public/assets/clock-kLje910u.js +1 -0
- package/payload/server/public/assets/clock-kLje910u.js.br +0 -0
- package/payload/server/public/assets/clock-kLje910u.js.gz +0 -0
- package/payload/server/public/assets/copy-Dnw0TkVh.js +1 -0
- package/payload/server/public/assets/copy-Dnw0TkVh.js.br +0 -0
- package/payload/server/public/assets/copy-Dnw0TkVh.js.gz +0 -0
- package/payload/server/public/assets/data-DKz9_73S.js +1 -0
- package/payload/server/public/assets/data-DKz9_73S.js.br +1 -0
- package/payload/server/public/assets/data-DKz9_73S.js.gz +0 -0
- package/payload/server/public/assets/{field-CiIsn-47.js → field-mhgbdofr.js} +1 -1
- package/payload/server/public/assets/field-mhgbdofr.js.br +0 -0
- package/payload/server/public/assets/field-mhgbdofr.js.gz +0 -0
- package/payload/server/public/assets/{file-text-Cy-IjCf8.js → file-text-CVZAL3Er.js} +1 -1
- package/payload/server/public/assets/file-text-CVZAL3Er.js.br +0 -0
- package/payload/server/public/assets/file-text-CVZAL3Er.js.gz +0 -0
- package/payload/server/public/assets/graph-NmOxFNdx.js +51 -0
- package/payload/server/public/assets/graph-NmOxFNdx.js.br +0 -0
- package/payload/server/public/assets/graph-NmOxFNdx.js.gz +0 -0
- package/payload/server/public/assets/{graph-labels-3bstML8n.js → graph-labels-BTFUSc63.js} +1 -1
- package/payload/server/public/assets/graph-labels-BTFUSc63.js.br +0 -0
- package/payload/server/public/assets/graph-labels-BTFUSc63.js.gz +0 -0
- package/payload/server/public/assets/{jsx-runtime-JxxB_2S6.css → jsx-runtime-dao9WPN0.css} +1 -1
- package/payload/server/public/assets/jsx-runtime-dao9WPN0.css.br +0 -0
- package/payload/server/public/assets/{jsx-runtime-JxxB_2S6.css.gz → jsx-runtime-dao9WPN0.css.gz} +0 -0
- package/payload/server/public/assets/{operator-D7L2SA16.js → operator-CO5ma-ky.js} +1 -1
- package/payload/server/public/assets/operator-CO5ma-ky.js.br +0 -0
- package/payload/server/public/assets/operator-CO5ma-ky.js.gz +0 -0
- package/payload/server/public/assets/page-BBRWbFzG.js +32 -0
- package/payload/server/public/assets/page-BBRWbFzG.js.br +0 -0
- package/payload/server/public/assets/page-BBRWbFzG.js.gz +0 -0
- package/payload/server/public/assets/page-CdRrpkky.js +1 -0
- package/payload/server/public/assets/page-CdRrpkky.js.br +0 -0
- package/payload/server/public/assets/page-CdRrpkky.js.gz +0 -0
- package/payload/server/public/assets/play-eeQX0FtC.js +1 -0
- package/payload/server/public/assets/play-eeQX0FtC.js.br +0 -0
- package/payload/server/public/assets/play-eeQX0FtC.js.gz +0 -0
- package/payload/server/public/assets/{public-CEXKl8wg.js → public-2mLo4k7L.js} +1 -1
- package/payload/server/public/assets/public-2mLo4k7L.js.br +0 -0
- package/payload/server/public/assets/public-2mLo4k7L.js.gz +0 -0
- package/payload/server/public/assets/{rotate-ccw-ckXDebK2.js → rotate-ccw-D-2d4YGp.js} +1 -1
- package/payload/server/public/assets/rotate-ccw-D-2d4YGp.js.br +0 -0
- package/payload/server/public/assets/rotate-ccw-D-2d4YGp.js.gz +0 -0
- package/payload/server/public/assets/{routines-Dwc2meN2.js → routines-CMW8sm10.js} +2 -2
- package/payload/server/public/assets/routines-CMW8sm10.js.br +0 -0
- package/payload/server/public/assets/routines-CMW8sm10.js.gz +0 -0
- package/payload/server/public/assets/{skills-DdHKHl4Z.js → skills-BQC7SM0J.js} +1 -1
- package/payload/server/public/assets/skills-BQC7SM0J.js.br +0 -0
- package/payload/server/public/assets/skills-BQC7SM0J.js.gz +0 -0
- package/payload/server/public/assets/tasks-CIs0y00-.js +3 -0
- package/payload/server/public/assets/tasks-CIs0y00-.js.br +0 -0
- package/payload/server/public/assets/tasks-CIs0y00-.js.gz +0 -0
- package/payload/server/public/assets/{triangle-alert-C-7A00P0.js → triangle-alert-C_68TrTq.js} +1 -1
- package/payload/server/public/assets/triangle-alert-C_68TrTq.js.br +0 -0
- package/payload/server/public/assets/triangle-alert-C_68TrTq.js.gz +0 -0
- package/payload/server/public/assets/{useCopyFeedback-CWvSi-Qe.js → useCopyFeedback-1MKNUzp3.js} +1 -1
- package/payload/server/public/assets/useCopyFeedback-1MKNUzp3.js.br +0 -0
- package/payload/server/public/assets/useCopyFeedback-1MKNUzp3.js.gz +0 -0
- package/payload/server/public/assets/useMediaQuery-e4ciNiuO.js +6 -0
- package/payload/server/public/assets/useMediaQuery-e4ciNiuO.js.br +0 -0
- package/payload/server/public/assets/useMediaQuery-e4ciNiuO.js.gz +0 -0
- package/payload/server/public/assets/useVoiceRecorder-D7_wLtrS.js +2 -0
- package/payload/server/public/assets/useVoiceRecorder-D7_wLtrS.js.br +0 -0
- package/payload/server/public/assets/useVoiceRecorder-D7_wLtrS.js.gz +0 -0
- package/payload/server/public/assets/{wrench-Cl6TUm2T.js → wrench-BI28h1JF.js} +1 -1
- package/payload/server/public/assets/wrench-BI28h1JF.js.br +0 -0
- package/payload/server/public/assets/wrench-BI28h1JF.js.gz +0 -0
- package/payload/server/public/browser.html +5 -5
- package/payload/server/public/calendar.html +8 -8
- package/payload/server/public/chat.html +14 -14
- package/payload/server/public/data.html +12 -12
- package/payload/server/public/field.html +3 -3
- package/payload/server/public/graph.html +10 -10
- package/payload/server/public/index.html +14 -14
- package/payload/server/public/operator.html +15 -15
- package/payload/server/public/public.html +14 -14
- package/payload/server/public/routines.html +8 -8
- package/payload/server/public/skills.html +6 -6
- package/payload/server/public/tasks.html +7 -7
- package/payload/server/server.js +650 -528
- package/payload/server/public/assets/AdminLoginScreens-BBKEIEjY.js.br +0 -0
- package/payload/server/public/assets/AdminLoginScreens-BBKEIEjY.js.gz +0 -0
- package/payload/server/public/assets/AdminShell-CrCdEMNW.js +0 -3
- package/payload/server/public/assets/AdminShell-CrCdEMNW.js.br +0 -0
- package/payload/server/public/assets/AdminShell-CrCdEMNW.js.gz +0 -0
- package/payload/server/public/assets/activity-CbR3vaq1.js.br +0 -0
- package/payload/server/public/assets/activity-CbR3vaq1.js.gz +0 -0
- package/payload/server/public/assets/admin-D8qKnmhE.js +0 -1
- package/payload/server/public/assets/admin-D8qKnmhE.js.br +0 -0
- package/payload/server/public/assets/admin-D8qKnmhE.js.gz +0 -0
- package/payload/server/public/assets/agents-8gAQjRqI.js.br +0 -0
- package/payload/server/public/assets/agents-8gAQjRqI.js.gz +0 -0
- package/payload/server/public/assets/browser-jAje5ILy.js.br +0 -0
- package/payload/server/public/assets/browser-jAje5ILy.js.gz +0 -0
- package/payload/server/public/assets/calendar-xEmCJif9.js.br +0 -0
- package/payload/server/public/assets/calendar-xEmCJif9.js.gz +0 -0
- package/payload/server/public/assets/chat-Ct5RDmv6.js +0 -1
- package/payload/server/public/assets/chat-Ct5RDmv6.js.br +0 -0
- package/payload/server/public/assets/chat-Ct5RDmv6.js.gz +0 -0
- package/payload/server/public/assets/chevron-left-DV8gIVC9.js.br +0 -0
- package/payload/server/public/assets/clock-PnR4Tlg9.js +0 -1
- package/payload/server/public/assets/clock-PnR4Tlg9.js.br +0 -0
- package/payload/server/public/assets/copy-b6MpzRz9.js +0 -1
- package/payload/server/public/assets/copy-b6MpzRz9.js.br +0 -0
- package/payload/server/public/assets/copy-b6MpzRz9.js.gz +0 -0
- package/payload/server/public/assets/data-BxFc9wPl.js +0 -1
- package/payload/server/public/assets/data-BxFc9wPl.js.br +0 -2
- package/payload/server/public/assets/data-BxFc9wPl.js.gz +0 -0
- package/payload/server/public/assets/field-CiIsn-47.js.br +0 -0
- package/payload/server/public/assets/field-CiIsn-47.js.gz +0 -0
- package/payload/server/public/assets/file-text-Cy-IjCf8.js.br +0 -0
- package/payload/server/public/assets/file-text-Cy-IjCf8.js.gz +0 -0
- package/payload/server/public/assets/graph-BdC2IGOT.js +0 -51
- package/payload/server/public/assets/graph-BdC2IGOT.js.br +0 -0
- package/payload/server/public/assets/graph-BdC2IGOT.js.gz +0 -0
- package/payload/server/public/assets/graph-labels-3bstML8n.js.br +0 -0
- package/payload/server/public/assets/graph-labels-3bstML8n.js.gz +0 -0
- package/payload/server/public/assets/jsx-runtime-JxxB_2S6.css.br +0 -0
- package/payload/server/public/assets/operator-D7L2SA16.js.br +0 -0
- package/payload/server/public/assets/operator-D7L2SA16.js.gz +0 -0
- package/payload/server/public/assets/page-DspGbDgK.js +0 -32
- package/payload/server/public/assets/page-DspGbDgK.js.br +0 -0
- package/payload/server/public/assets/page-DspGbDgK.js.gz +0 -0
- package/payload/server/public/assets/page-ObXxk8ol.js +0 -1
- package/payload/server/public/assets/page-ObXxk8ol.js.br +0 -0
- package/payload/server/public/assets/page-ObXxk8ol.js.gz +0 -0
- package/payload/server/public/assets/play-BL4ztD3m.js +0 -1
- package/payload/server/public/assets/play-BL4ztD3m.js.br +0 -0
- package/payload/server/public/assets/play-BL4ztD3m.js.gz +0 -0
- package/payload/server/public/assets/public-CEXKl8wg.js.br +0 -0
- package/payload/server/public/assets/public-CEXKl8wg.js.gz +0 -0
- package/payload/server/public/assets/rotate-ccw-ckXDebK2.js.br +0 -0
- package/payload/server/public/assets/rotate-ccw-ckXDebK2.js.gz +0 -0
- package/payload/server/public/assets/routines-Dwc2meN2.js.br +0 -0
- package/payload/server/public/assets/routines-Dwc2meN2.js.gz +0 -0
- package/payload/server/public/assets/skills-DdHKHl4Z.js.br +0 -0
- package/payload/server/public/assets/skills-DdHKHl4Z.js.gz +0 -0
- package/payload/server/public/assets/tasks-C_yWRvOG.js +0 -3
- package/payload/server/public/assets/tasks-C_yWRvOG.js.br +0 -0
- package/payload/server/public/assets/tasks-C_yWRvOG.js.gz +0 -0
- package/payload/server/public/assets/triangle-alert-C-7A00P0.js.br +0 -0
- package/payload/server/public/assets/triangle-alert-C-7A00P0.js.gz +0 -0
- package/payload/server/public/assets/useCopyFeedback-CWvSi-Qe.js.br +0 -2
- package/payload/server/public/assets/useCopyFeedback-CWvSi-Qe.js.gz +0 -0
- package/payload/server/public/assets/useMediaQuery-CLVRXJMp.js +0 -6
- package/payload/server/public/assets/useMediaQuery-CLVRXJMp.js.br +0 -0
- package/payload/server/public/assets/useMediaQuery-CLVRXJMp.js.gz +0 -0
- package/payload/server/public/assets/useVoiceRecorder-BbJad9CQ.js +0 -2
- package/payload/server/public/assets/useVoiceRecorder-BbJad9CQ.js.br +0 -0
- package/payload/server/public/assets/useVoiceRecorder-BbJad9CQ.js.gz +0 -0
- package/payload/server/public/assets/wrench-Cl6TUm2T.js.br +0 -0
- package/payload/server/public/assets/wrench-Cl6TUm2T.js.gz +0 -0
- /package/payload/server/public/assets/{jsx-runtime-BCAZhYqz.js → jsx-runtime-BY35JYDT.js} +0 -0
- /package/payload/server/public/assets/{jsx-runtime-BCAZhYqz.js.br → jsx-runtime-BY35JYDT.js.br} +0 -0
- /package/payload/server/public/assets/{jsx-runtime-BCAZhYqz.js.gz → jsx-runtime-BY35JYDT.js.gz} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./chunk-BycB0eMI.js";import{i as t,n,t as r}from"./jsx-runtime-BCAZhYqz.js";import{C as i,N as a,P as o,k as s,lt as c,r as l,tt as u}from"./useMediaQuery-CLVRXJMp.js";import{A as d,O as f,k as p,t as m}from"./AdminShell-CrCdEMNW.js";import{t as h}from"./triangle-alert-C-7A00P0.js";var g=n(),_=e(t(),1),v=r(),y=`—`;function b(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 x={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.`},S=new Set([`never-run`,`never-succeeded`,`failing`,`stalled`]),C=10;function w(e){return e===null||!Number.isFinite(e)?y:`${e.toFixed(1)}%`}function T(e){return e<6e4?`${Math.round(e/1e3)}s`:e<36e5?`${Math.round(e/6e4)}m`:`${Math.round(e/36e5)}h`}function E(e,t){if(e===null)return y;let n=t-e;return n<0?`in ${T(-n)}`:n<6e4?`${Math.round(n/1e3)}s ago`:n<36e5?`${Math.round(n/6e4)}m ago`:`${Math.round(n/36e5)}h ago`}function D(e,t){if(e===null)return y;let n=e-t;return n>=0?`in ${T(n)}`:`overdue by ${T(-n)}`}function ee({loops:e,nowMs:t=Date.now()}){let[n,r]=(0,_.useState)(!1);if(!e)return(0,v.jsxs)(`section`,{className:`activity-loops`,children:[(0,v.jsx)(`h2`,{className:`activity-loops-heading`,children:`Scheduled work`}),(0,v.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=>S.has(e.state)),o=e.rows.filter(e=>!S.has(e.state)&&typeof e.cpuPct==`number`&&e.cpuPct>=C),s=n?e.rows:[...a,...o];return(0,v.jsxs)(`section`,{className:`activity-loops`,children:[(0,v.jsx)(`h2`,{className:`activity-loops-heading`,children:`Scheduled work`}),(0,v.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,v.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,v.jsxs)(`p`,{className:`activity-loops-cpu`,children:[`Server process at `,e.processPct.toFixed(1),`% of one core`,typeof e.attributedPct==`number`&&(0,v.jsxs)(v.Fragment,{children:[` · these loops explain `,e.attributedPct.toFixed(1),`%`]}),typeof e.unattributedPct==`number`&&e.unattributedPct>=1&&(0,v.jsxs)(v.Fragment,{children:[` · `,(0,v.jsxs)(`strong`,{children:[e.unattributedPct.toFixed(1),`% is not from these loops`]})]})]}),i>0&&(0,v.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,v.jsx)(`div`,{className:`activity-table-scroll`,children:(0,v.jsxs)(`table`,{className:`activity-table`,children:[(0,v.jsx)(`thead`,{children:(0,v.jsxs)(`tr`,{children:[(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Loop`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`State`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Every`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Last run`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Last OK`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Took`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`CPU`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Runs`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Produced`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Next due`})]})}),(0,v.jsx)(`tbody`,{children:s.map(e=>(0,v.jsxs)(`tr`,{className:S.has(e.state)?`activity-loop-row activity-loop-unhealthy`:`activity-loop-row`,children:[(0,v.jsx)(`td`,{className:`activity-td`,children:e.name}),(0,v.jsx)(`td`,{className:`activity-td`,title:x[e.state],children:(0,v.jsxs)(`span`,{className:`activity-state`,children:[(0,v.jsx)(`span`,{className:e.state===`ok`?`activity-state-dot is-healthy`:S.has(e.state)?`activity-state-dot is-unhealthy`:`activity-state-dot`,"aria-hidden":`true`}),b(e.state)]})}),(0,v.jsx)(`td`,{className:`activity-td activity-num`,children:T(e.intervalMs)}),(0,v.jsx)(`td`,{className:`activity-td activity-num`,children:E(e.lastStartMs,t)}),(0,v.jsx)(`td`,{className:`activity-td activity-num`,children:E(e.lastSuccessMs,t)}),(0,v.jsx)(`td`,{className:`activity-td activity-num`,children:e.lastDurationMs===null?y:`${e.lastDurationMs} ms`}),(0,v.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:w(e.cpuPct)}),(0,v.jsxs)(`td`,{className:`activity-td activity-num`,children:[e.successCount,`/`,e.runCount]}),(0,v.jsx)(`td`,{className:`activity-td activity-loop-note`,children:(0,v.jsx)(`span`,{className:`activity-loop-note-text`,title:e.lastError??e.lastNote??void 0,children:e.lastError??e.lastNote??y})}),(0,v.jsx)(`td`,{className:`activity-td activity-num`,children:D(e.nextDueMs,t)})]},e.name))})]})}),(0,v.jsxs)(`dl`,{className:`activity-legend`,children:[(0,v.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,v.jsx)(`dt`,{className:`activity-legend-term`,children:`Runs`}),(0,v.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,v.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,v.jsx)(`dt`,{className:`activity-legend-term`,children:`CPU`}),(0,v.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,v.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,v.jsx)(`dt`,{className:`activity-legend-term`,children:y}),(0,v.jsx)(`dd`,{className:`activity-legend-def`,children:`Not measured. It does not mean zero.`})]})]})]})}var O=`maxy-admin-session-key`;function te(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 ne(e,t){let n=t?.[e];return n&&n.trim()!==``?n:e.slice(0,8)}var N=`—`;function P(e){if(e===null||!Number.isFinite(e)||e<0)return N;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 F(e){return e===null||!Number.isFinite(e)?N:`${(e/1024/1024).toFixed(1)} GB`}function I(e,t,n){if(!e)return N;let r=Date.parse(e);if(!Number.isFinite(r))return N;let i=s(new Date(r),n),a=s(new Date(t),n),o=`${String(i.hh).padStart(2,`0`)}:${String(i.mm).padStart(2,`0`)}`;return i.y===a.y&&i.m===a.m&&i.d===a.d?o:`${i.d} ${L[i.m-1]} ${o}`}var L=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`];function R(e){return e===null||!Number.isFinite(e)?N:`${e.toFixed(1)}%`}function z(e){return e===null||!Number.isFinite(e)?N: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)?N:`£${e.toFixed(2)}`}function V(e){if(e===null||!Number.isFinite(e)||e<0)return N;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 K(e,t){return{from:U(new Date(t-(e-1)*864e5)),to:U(new Date(t))}}function q(e){return new Date(`${e}T00:00:00.000Z`).toLocaleString(`en-GB`,{month:`long`,year:`numeric`,timeZone:`UTC`})}function J(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 Y(e,t,n,r){switch(e){case`title`:return t.title??t.sessionId.slice(0,8);case`model`:return t.model??N;case`status`:return t.status??N;case`activeMsInRange`:return V(t.activeMsInRange);case`ageMs`:return P(t.ageMs);case`lastMessageAt`:return I(t.lastMessageAt,n,r);case`turnCount`:return t.turnCount===null?N:`${t.turnCount}${t.turnCountCapped?`+`:``}`;case`rssKb`:return F(t.rssKb);case`cpuPct`:return R(t.cpuPct);case`tokensInRange`:return z(t.tokensInRange);case`costGbp`:return B(t.costGbp);default:return N}}function X({adminFetch:e,cacheKey:t}){let{zone:n}=i(),[r,o]=(0,_.useState)(null),[s,c]=(0,_.useState)(null),[d,m]=(0,_.useState)(!1),[g,y]=(0,_.useState)(`lastMessageAt`),[b,x]=(0,_.useState)(-1),[S,C]=(0,_.useState)(()=>W(new Date)),[w,T]=(0,_.useState)(!0),[E,D]=(0,_.useState)(!0),[O,F]=(0,_.useState)(!1),I=(0,_.useCallback)(async(e,n)=>{t&&await l(t,e)&&window.location.assign(`/chat?session=${encodeURIComponent(n)}`)},[t]),L=(0,_.useRef)(!1),R=(0,_.useRef)(void 0),z=(0,_.useCallback)(async t=>{if(L.current){R.current=t;return}L.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.`),m(!0);return}if(!n.ok){c(`The session manager did not answer (status ${n.status}).`),m(!0);return}o(await n.json()),c(null)}catch(e){c(e instanceof Error?e.message:String(e))}finally{m(!0),L.current=!1;let e=R.current;R.current=void 0,e!==void 0&&z(e)}},[e]);(0,_.useEffect)(()=>{z(S);let e=setInterval(()=>void z(S),15e3);return()=>clearInterval(e)},[z,S]);let B=(0,_.useMemo)(()=>r?[...r.rows].sort((e,t)=>H(e,t,g,b)):[],[r,g,b]),V=(0,_.useMemo)(()=>B.filter(e=>e.status===`busy`?w:e.status===`idle`?E:!0),[B,w,E]),U=B.length-V.length;if(!d)return(0,v.jsx)(a,{surface:`gate`});if(s)return(0,v.jsx)(`div`,{className:`activity-empty`,children:s});if(!r)return(0,v.jsx)(`div`,{className:`activity-empty`,children:`No response.`});let{accounts:X,census:Z,censusAgeMs:Q}=r,re=Date.now(),ie=X.onDisk!==null&&X.onDisk>X.valid,$=r.range===void 0?S:r.range;return(0,v.jsxs)(`div`,{className:`ui-page ui-page--full activity-body`,children:[(0,v.jsxs)(`div`,{className:`activity-head`,children:[(0,v.jsxs)(`span`,{className:`activity-title`,children:[(0,v.jsx)(u,{size:16}),` Live sessions`]}),(0,v.jsxs)(`span`,{className:`activity-meta`,children:[U>0?`${V.length} of ${B.length} live · ${U} hidden`:`${B.length} live`,` · `,X.valid,` accounts`,X.untaggedCount>0?` · ${X.untaggedCount} untagged`:``]})]}),(0,v.jsxs)(`div`,{className:`activity-controls`,children:[(0,v.jsxs)(`div`,{className:`activity-control activity-range`,children:[(0,v.jsx)(f,{variant:`secondary`,size:`sm`,"aria-label":`Previous month`,disabled:!J(S),onClick:()=>C(e=>e&&G(e.from,-1)),children:`‹`}),(0,v.jsx)(`span`,{className:`activity-range-label`,children:S===null?`All time`:J(S)?q(S.from):`${S.from} → ${S.to}`}),(0,v.jsx)(f,{variant:`secondary`,size:`sm`,"aria-label":`Next month`,disabled:!J(S),onClick:()=>C(e=>e&&G(e.from,1)),children:`›`})]}),(0,v.jsxs)(`div`,{className:`activity-control activity-presets`,children:[(0,v.jsx)(f,{variant:`secondary`,size:`sm`,"aria-pressed":S!==null&&J(S)&&S.from===W(new Date).from,onClick:()=>C(W(new Date)),children:`This month`}),(0,v.jsx)(f,{variant:`secondary`,size:`sm`,"aria-pressed":S!==null&&!J(S),onClick:()=>C(K(7,Date.now())),children:`Last 7 days`}),(0,v.jsx)(f,{variant:`secondary`,size:`sm`,"aria-pressed":S===null,onClick:()=>C(null),children:`All time`})]}),(0,v.jsxs)(`div`,{className:`activity-control`,children:[(0,v.jsx)(`label`,{className:`activity-control-label`,htmlFor:`activity-sort`,children:`Sort by`}),(0,v.jsx)(`span`,{className:`activity-select-wrap`,children:(0,v.jsx)(`select`,{id:`activity-sort`,className:`activity-select`,value:g,onChange:e=>{let t=k.find(t=>t.key===e.target.value);t&&(y(t.key),x(t.dir))},children:k.map(e=>(0,v.jsx)(`option`,{value:e.key,children:e.label},e.key))})})]}),(0,v.jsxs)(`div`,{className:`activity-control activity-visibility`,children:[(0,v.jsx)(p,{checked:w,onChange:T,label:`Busy`}),(0,v.jsx)(p,{checked:E,onChange:D,label:`Idle`})]})]}),(0,v.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,v.jsxs)(`strong`,{className:`activity-range-rejected`,children:[` `,`The range was not accepted, so these are all-time figures.`]})]}),(0,v.jsx)(`div`,{className:`activity-census`,children:Z===null?`No census collected yet, so memory and CPU are unavailable.`:`Memory and CPU measured ${P(Q)} ago, averaged over the minute before that · ${Z.cpuNull} of ${Z.live} without a CPU reading`}),ie&&(0,v.jsxs)(`div`,{className:`activity-warning`,children:[(0,v.jsx)(h,{size:14}),` `,X.onDisk,` account folders on disk but only`,` `,X.valid,` are readable. Sessions belonging to the rest cannot be attributed.`]}),B.length===0?(0,v.jsx)(`div`,{className:`activity-empty`,children:`No sessions are running.`}):V.length===0?(0,v.jsxs)(`div`,{className:`activity-empty`,children:[`All `,B.length,` running sessions are hidden by the Busy and Idle filters.`]}):(0,v.jsx)(`div`,{className:`activity-grid`,children:V.map(e=>{let r=e.accountId!==null&&!!t,i=r?()=>void I(e.accountId,e.sessionId):void 0;return(0,v.jsxs)(`article`,{className:`activity-card${r?` activity-card-clickable`:``}`,"data-testid":`activity-card`,"data-session-id":e.sessionId,role:r?`button`:void 0,tabIndex:r?0:void 0,onClick:i,onKeyDown:r?e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),i())}:void 0,children:[(0,v.jsx)(`h3`,{className:`activity-card-heading`,title:e.accountId??void 0,children:e.accountId===null?(0,v.jsx)(`span`,{className:`activity-untagged`,title:`This session records no account, so it cannot be attributed to a business.`,children:`untagged`}):ne(e.accountId,X.names)}),(0,v.jsx)(`dl`,{className:`activity-card-rows`,children:A.map(t=>(0,v.jsxs)(`div`,{className:`activity-card-row`,children:[(0,v.jsx)(`dt`,{className:`activity-card-label`,"data-testid":`activity-card-label`,title:t.help,children:t.label}),(0,v.jsx)(`dd`,{className:`activity-card-value`,title:t.key===`costGbp`?te(e):void 0,children:Y(t.key,e,re,n)})]},t.key))})]},e.sessionId)})}),B.length>0&&(0,v.jsxs)(`div`,{className:`activity-glossary`,children:[(0,v.jsxs)(`dl`,{className:`activity-legend`,children:[O&&(0,v.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,v.jsx)(`dt`,{className:`activity-legend-term`,"data-testid":`activity-glossary-term`,children:M.label}),(0,v.jsx)(`dd`,{className:`activity-legend-def`,children:M.help})]},`heading`),(O?A:A.filter(e=>j.includes(e.key))).map(e=>(0,v.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,v.jsx)(`dt`,{className:`activity-legend-term`,"data-testid":`activity-glossary-term`,children:e.label}),(0,v.jsx)(`dd`,{className:`activity-legend-def`,children:e.help})]},e.key)),(0,v.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,v.jsx)(`dt`,{className:`activity-legend-term`,children:N}),(0,v.jsxs)(`dd`,{className:`activity-legend-def`,children:[`Not measured. It does not mean zero — a measured zero is written as a figure, so `,(0,v.jsx)(`em`,{children:`0h 0m`}),` and `,(0,v.jsx)(`em`,{children:`£0.00`}),` are real readings. Hover a dashed value for the reason where one exists.`]})]})]}),(0,v.jsx)(f,{variant:`secondary`,size:`sm`,className:`activity-glossary-toggle`,onClick:()=>F(e=>!e),children:O?`Show fewer`:`Explain every figure`})]}),(0,v.jsx)(ee,{loops:r?.loops})]})}function Z({cacheKey:e}){let{adminFetch:t}=c({initialCacheKey:e,surface:`activity`});return(0,v.jsx)(X,{adminFetch:t,cacheKey:e})}function Q(){let[e,t]=(0,_.useState)(null),[n,r]=(0,_.useState)(!1),[i,s]=(0,_.useState)(void 0),[c,l]=(0,_.useState)(null),[u,f]=(0,_.useState)(null),[p,h]=(0,_.useState)(null),[g,y]=(0,_.useState)(null);(0,_.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(O)}catch{}if(!n){t(null),r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(O)}catch{}window.location.href=`/`;return}if(i.ok)try{let e=await i.json();typeof e.businessName==`string`&&s(e.businessName),e.sessionId!==void 0&&l(e.sessionId??null),f(e.role??null),h(e.userName===void 0?null:e.userName),y(e.avatar??null)}catch{}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]);let b=(0,_.useCallback)(()=>{try{sessionStorage.removeItem(O)}catch{}window.location.href=`/`},[]),[x,S]=(0,_.useState)(!1),C=(0,_.useCallback)(async()=>{S(!0);try{let e=await d();if(e){try{sessionStorage.removeItem(O)}catch{}window.location.href=`/`}return e}finally{S(!1)}},[]);return n?e?(0,v.jsx)(o,{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(O)}catch{}window.location.href=`/`},children:(0,v.jsx)(m,{cacheKey:e,businessName:i,sessionId:c,onLogout:b,onDisconnect:C,disconnecting:x,userName:p,userAvatar:g,role:u,children:(0,v.jsx)(Z,{cacheKey:e})})}):(0,v.jsx)(`div`,{className:`activity-page`,children:(0,v.jsxs)(`div`,{className:`activity-empty`,children:[(0,v.jsx)(`p`,{children:`You are not signed in.`}),(0,v.jsxs)(`p`,{children:[`Open the `,(0,v.jsx)(`a`,{href:`/`,className:`activity-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,v.jsx)(a,{surface:`gate`})}(0,g.createRoot)(document.getElementById(`root`)).render((0,v.jsx)(Q,{}));
|
|
1
|
+
import{o as e}from"./chunk-BycB0eMI.js";import{i as t,n,t as r}from"./jsx-runtime-BY35JYDT.js";import{C as i,N as a,P as o,k as s,nt as c,r as l,ut as u}from"./useMediaQuery-e4ciNiuO.js";import{D as d,O as f,k as p,t as m}from"./AdminShell-Dm_nY4jF.js";import{t as h}from"./triangle-alert-C_68TrTq.js";var g=n(),_=e(t(),1),v=r(),y=`—`;function b(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 x={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.`},S=new Set([`never-run`,`never-succeeded`,`failing`,`stalled`]),C=10;function w(e){return e===null||!Number.isFinite(e)?y:`${e.toFixed(1)}%`}function T(e){return e<6e4?`${Math.round(e/1e3)}s`:e<36e5?`${Math.round(e/6e4)}m`:`${Math.round(e/36e5)}h`}function E(e,t){if(e===null)return y;let n=t-e;return n<0?`in ${T(-n)}`:n<6e4?`${Math.round(n/1e3)}s ago`:n<36e5?`${Math.round(n/6e4)}m ago`:`${Math.round(n/36e5)}h ago`}function D(e,t){if(e===null)return y;let n=e-t;return n>=0?`in ${T(n)}`:`overdue by ${T(-n)}`}function ee({loops:e,nowMs:t=Date.now()}){let[n,r]=(0,_.useState)(!1);if(!e)return(0,v.jsxs)(`section`,{className:`activity-loops`,children:[(0,v.jsx)(`h2`,{className:`activity-loops-heading`,children:`Scheduled work`}),(0,v.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=>S.has(e.state)),o=e.rows.filter(e=>!S.has(e.state)&&typeof e.cpuPct==`number`&&e.cpuPct>=C),s=n?e.rows:[...a,...o];return(0,v.jsxs)(`section`,{className:`activity-loops`,children:[(0,v.jsx)(`h2`,{className:`activity-loops-heading`,children:`Scheduled work`}),(0,v.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,v.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,v.jsxs)(`p`,{className:`activity-loops-cpu`,children:[`Server process at `,e.processPct.toFixed(1),`% of one core`,typeof e.attributedPct==`number`&&(0,v.jsxs)(v.Fragment,{children:[` · these loops explain `,e.attributedPct.toFixed(1),`%`]}),typeof e.unattributedPct==`number`&&e.unattributedPct>=1&&(0,v.jsxs)(v.Fragment,{children:[` · `,(0,v.jsxs)(`strong`,{children:[e.unattributedPct.toFixed(1),`% is not from these loops`]})]})]}),i>0&&(0,v.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,v.jsx)(`div`,{className:`activity-table-scroll`,children:(0,v.jsxs)(`table`,{className:`activity-table`,children:[(0,v.jsx)(`thead`,{children:(0,v.jsxs)(`tr`,{children:[(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Loop`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`State`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Every`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Last run`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Last OK`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Took`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`CPU`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Runs`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Produced`}),(0,v.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Next due`})]})}),(0,v.jsx)(`tbody`,{children:s.map(e=>(0,v.jsxs)(`tr`,{className:S.has(e.state)?`activity-loop-row activity-loop-unhealthy`:`activity-loop-row`,children:[(0,v.jsx)(`td`,{className:`activity-td`,children:e.name}),(0,v.jsx)(`td`,{className:`activity-td`,title:x[e.state],children:(0,v.jsxs)(`span`,{className:`activity-state`,children:[(0,v.jsx)(`span`,{className:e.state===`ok`?`activity-state-dot is-healthy`:S.has(e.state)?`activity-state-dot is-unhealthy`:`activity-state-dot`,"aria-hidden":`true`}),b(e.state)]})}),(0,v.jsx)(`td`,{className:`activity-td activity-num`,children:T(e.intervalMs)}),(0,v.jsx)(`td`,{className:`activity-td activity-num`,children:E(e.lastStartMs,t)}),(0,v.jsx)(`td`,{className:`activity-td activity-num`,children:E(e.lastSuccessMs,t)}),(0,v.jsx)(`td`,{className:`activity-td activity-num`,children:e.lastDurationMs===null?y:`${e.lastDurationMs} ms`}),(0,v.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:w(e.cpuPct)}),(0,v.jsxs)(`td`,{className:`activity-td activity-num`,children:[e.successCount,`/`,e.runCount]}),(0,v.jsx)(`td`,{className:`activity-td activity-loop-note`,children:(0,v.jsx)(`span`,{className:`activity-loop-note-text`,title:e.lastError??e.lastNote??void 0,children:e.lastError??e.lastNote??y})}),(0,v.jsx)(`td`,{className:`activity-td activity-num`,children:D(e.nextDueMs,t)})]},e.name))})]})}),(0,v.jsxs)(`dl`,{className:`activity-legend`,children:[(0,v.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,v.jsx)(`dt`,{className:`activity-legend-term`,children:`Runs`}),(0,v.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,v.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,v.jsx)(`dt`,{className:`activity-legend-term`,children:`CPU`}),(0,v.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,v.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,v.jsx)(`dt`,{className:`activity-legend-term`,children:y}),(0,v.jsx)(`dd`,{className:`activity-legend-def`,children:`Not measured. It does not mean zero.`})]})]})]})}var O=`maxy-admin-session-key`;function te(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 ne(e,t){let n=t?.[e];return n&&n.trim()!==``?n:e.slice(0,8)}var N=`—`;function P(e){if(e===null||!Number.isFinite(e)||e<0)return N;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 F(e){return e===null||!Number.isFinite(e)?N:`${(e/1024/1024).toFixed(1)} GB`}function I(e,t,n){if(!e)return N;let r=Date.parse(e);if(!Number.isFinite(r))return N;let i=s(new Date(r),n),a=s(new Date(t),n),o=`${String(i.hh).padStart(2,`0`)}:${String(i.mm).padStart(2,`0`)}`;return i.y===a.y&&i.m===a.m&&i.d===a.d?o:`${i.d} ${L[i.m-1]} ${o}`}var L=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`];function R(e){return e===null||!Number.isFinite(e)?N:`${e.toFixed(1)}%`}function z(e){return e===null||!Number.isFinite(e)?N: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)?N:`£${e.toFixed(2)}`}function V(e){if(e===null||!Number.isFinite(e)||e<0)return N;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 K(e,t){return{from:U(new Date(t-(e-1)*864e5)),to:U(new Date(t))}}function q(e){return new Date(`${e}T00:00:00.000Z`).toLocaleString(`en-GB`,{month:`long`,year:`numeric`,timeZone:`UTC`})}function J(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 Y(e,t,n,r){switch(e){case`title`:return t.title??t.sessionId.slice(0,8);case`model`:return t.model??N;case`status`:return t.status??N;case`activeMsInRange`:return V(t.activeMsInRange);case`ageMs`:return P(t.ageMs);case`lastMessageAt`:return I(t.lastMessageAt,n,r);case`turnCount`:return t.turnCount===null?N:`${t.turnCount}${t.turnCountCapped?`+`:``}`;case`rssKb`:return F(t.rssKb);case`cpuPct`:return R(t.cpuPct);case`tokensInRange`:return z(t.tokensInRange);case`costGbp`:return B(t.costGbp);default:return N}}function X({adminFetch:e,cacheKey:t}){let{zone:n}=i(),[r,o]=(0,_.useState)(null),[s,u]=(0,_.useState)(null),[p,m]=(0,_.useState)(!1),[g,y]=(0,_.useState)(`lastMessageAt`),[b,x]=(0,_.useState)(-1),[S,C]=(0,_.useState)(()=>W(new Date)),[w,T]=(0,_.useState)(!0),[E,D]=(0,_.useState)(!0),[O,F]=(0,_.useState)(!1),I=(0,_.useCallback)(async(e,n)=>{t&&await l(t,e)&&window.location.assign(`/chat?session=${encodeURIComponent(n)}`)},[t]),L=(0,_.useRef)(!1),R=(0,_.useRef)(void 0),z=(0,_.useCallback)(async t=>{if(L.current){R.current=t;return}L.current=!0;try{let n=await e(`/api/admin/activity${t?`?from=${t.from}&to=${t.to}`:``}`);if(n.status===403){u(`This view is available to the house account only.`),m(!0);return}if(!n.ok){u(`The session manager did not answer (status ${n.status}).`),m(!0);return}o(await n.json()),u(null)}catch(e){u(e instanceof Error?e.message:String(e))}finally{m(!0),L.current=!1;let e=R.current;R.current=void 0,e!==void 0&&z(e)}},[e]);(0,_.useEffect)(()=>{z(S);let e=setInterval(()=>void z(S),15e3);return()=>clearInterval(e)},[z,S]);let B=(0,_.useMemo)(()=>r?[...r.rows].sort((e,t)=>H(e,t,g,b)):[],[r,g,b]),V=(0,_.useMemo)(()=>B.filter(e=>e.status===`busy`?w:e.status===`idle`?E:!0),[B,w,E]),U=B.length-V.length;if(!p)return(0,v.jsx)(a,{surface:`gate`});if(s)return(0,v.jsx)(`div`,{className:`activity-empty`,children:s});if(!r)return(0,v.jsx)(`div`,{className:`activity-empty`,children:`No response.`});let{accounts:X,census:Z,censusAgeMs:Q}=r,re=Date.now(),ie=X.onDisk!==null&&X.onDisk>X.valid,$=r.range===void 0?S:r.range;return(0,v.jsxs)(`div`,{className:`ui-page ui-page--full activity-body`,children:[(0,v.jsxs)(`div`,{className:`activity-head`,children:[(0,v.jsxs)(`span`,{className:`activity-title`,children:[(0,v.jsx)(c,{size:16}),` Live sessions`]}),(0,v.jsxs)(`span`,{className:`activity-meta`,children:[U>0?`${V.length} of ${B.length} live · ${U} hidden`:`${B.length} live`,` · `,X.valid,` accounts`,X.untaggedCount>0?` · ${X.untaggedCount} untagged`:``]})]}),(0,v.jsxs)(`div`,{className:`activity-controls`,children:[(0,v.jsxs)(`div`,{className:`activity-control activity-range`,children:[(0,v.jsx)(d,{variant:`secondary`,size:`sm`,"aria-label":`Previous month`,disabled:!J(S),onClick:()=>C(e=>e&&G(e.from,-1)),children:`‹`}),(0,v.jsx)(`span`,{className:`activity-range-label`,children:S===null?`All time`:J(S)?q(S.from):`${S.from} → ${S.to}`}),(0,v.jsx)(d,{variant:`secondary`,size:`sm`,"aria-label":`Next month`,disabled:!J(S),onClick:()=>C(e=>e&&G(e.from,1)),children:`›`})]}),(0,v.jsxs)(`div`,{className:`activity-control activity-presets`,children:[(0,v.jsx)(d,{variant:`secondary`,size:`sm`,"aria-pressed":S!==null&&J(S)&&S.from===W(new Date).from,onClick:()=>C(W(new Date)),children:`This month`}),(0,v.jsx)(d,{variant:`secondary`,size:`sm`,"aria-pressed":S!==null&&!J(S),onClick:()=>C(K(7,Date.now())),children:`Last 7 days`}),(0,v.jsx)(d,{variant:`secondary`,size:`sm`,"aria-pressed":S===null,onClick:()=>C(null),children:`All time`})]}),(0,v.jsxs)(`div`,{className:`activity-control`,children:[(0,v.jsx)(`label`,{className:`activity-control-label`,htmlFor:`activity-sort`,children:`Sort by`}),(0,v.jsx)(`span`,{className:`activity-select-wrap`,children:(0,v.jsx)(`select`,{id:`activity-sort`,className:`activity-select`,value:g,onChange:e=>{let t=k.find(t=>t.key===e.target.value);t&&(y(t.key),x(t.dir))},children:k.map(e=>(0,v.jsx)(`option`,{value:e.key,children:e.label},e.key))})})]}),(0,v.jsxs)(`div`,{className:`activity-control activity-visibility`,children:[(0,v.jsx)(f,{checked:w,onChange:T,label:`Busy`}),(0,v.jsx)(f,{checked:E,onChange:D,label:`Idle`})]})]}),(0,v.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,v.jsxs)(`strong`,{className:`activity-range-rejected`,children:[` `,`The range was not accepted, so these are all-time figures.`]})]}),(0,v.jsx)(`div`,{className:`activity-census`,children:Z===null?`No census collected yet, so memory and CPU are unavailable.`:`Memory and CPU measured ${P(Q)} ago, averaged over the minute before that · ${Z.cpuNull} of ${Z.live} without a CPU reading`}),ie&&(0,v.jsxs)(`div`,{className:`activity-warning`,children:[(0,v.jsx)(h,{size:14}),` `,X.onDisk,` account folders on disk but only`,` `,X.valid,` are readable. Sessions belonging to the rest cannot be attributed.`]}),B.length===0?(0,v.jsx)(`div`,{className:`activity-empty`,children:`No sessions are running.`}):V.length===0?(0,v.jsxs)(`div`,{className:`activity-empty`,children:[`All `,B.length,` running sessions are hidden by the Busy and Idle filters.`]}):(0,v.jsx)(`div`,{className:`activity-grid`,children:V.map(e=>{let r=e.accountId!==null&&!!t,i=r?()=>void I(e.accountId,e.sessionId):void 0;return(0,v.jsxs)(`article`,{className:`activity-card${r?` activity-card-clickable`:``}`,"data-testid":`activity-card`,"data-session-id":e.sessionId,role:r?`button`:void 0,tabIndex:r?0:void 0,onClick:i,onKeyDown:r?e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),i())}:void 0,children:[(0,v.jsx)(`h3`,{className:`activity-card-heading`,title:e.accountId??void 0,children:e.accountId===null?(0,v.jsx)(`span`,{className:`activity-untagged`,title:`This session records no account, so it cannot be attributed to a business.`,children:`untagged`}):ne(e.accountId,X.names)}),(0,v.jsx)(`dl`,{className:`activity-card-rows`,children:A.map(t=>(0,v.jsxs)(`div`,{className:`activity-card-row`,children:[(0,v.jsx)(`dt`,{className:`activity-card-label`,"data-testid":`activity-card-label`,title:t.help,children:t.label}),(0,v.jsx)(`dd`,{className:`activity-card-value`,title:t.key===`costGbp`?te(e):void 0,children:Y(t.key,e,re,n)})]},t.key))})]},e.sessionId)})}),B.length>0&&(0,v.jsxs)(`div`,{className:`activity-glossary`,children:[(0,v.jsxs)(`dl`,{className:`activity-legend`,children:[O&&(0,v.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,v.jsx)(`dt`,{className:`activity-legend-term`,"data-testid":`activity-glossary-term`,children:M.label}),(0,v.jsx)(`dd`,{className:`activity-legend-def`,children:M.help})]},`heading`),(O?A:A.filter(e=>j.includes(e.key))).map(e=>(0,v.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,v.jsx)(`dt`,{className:`activity-legend-term`,"data-testid":`activity-glossary-term`,children:e.label}),(0,v.jsx)(`dd`,{className:`activity-legend-def`,children:e.help})]},e.key)),(0,v.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,v.jsx)(`dt`,{className:`activity-legend-term`,children:N}),(0,v.jsxs)(`dd`,{className:`activity-legend-def`,children:[`Not measured. It does not mean zero — a measured zero is written as a figure, so `,(0,v.jsx)(`em`,{children:`0h 0m`}),` and `,(0,v.jsx)(`em`,{children:`£0.00`}),` are real readings. Hover a dashed value for the reason where one exists.`]})]})]}),(0,v.jsx)(d,{variant:`secondary`,size:`sm`,className:`activity-glossary-toggle`,onClick:()=>F(e=>!e),children:O?`Show fewer`:`Explain every figure`})]}),(0,v.jsx)(ee,{loops:r?.loops})]})}function Z({cacheKey:e}){let{adminFetch:t}=u({initialCacheKey:e,surface:`activity`});return(0,v.jsx)(X,{adminFetch:t,cacheKey:e})}function Q(){let[e,t]=(0,_.useState)(null),[n,r]=(0,_.useState)(!1),[i,s]=(0,_.useState)(void 0),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)(null),[f,h]=(0,_.useState)(null),[g,y]=(0,_.useState)(null);(0,_.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(O)}catch{}if(!n){t(null),r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(O)}catch{}window.location.href=`/`;return}if(i.ok)try{let e=await i.json();typeof e.businessName==`string`&&s(e.businessName),e.sessionId!==void 0&&l(e.sessionId??null),d(e.role??null),h(e.userName===void 0?null:e.userName),y(e.avatar??null)}catch{}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]);let b=(0,_.useCallback)(()=>{try{sessionStorage.removeItem(O)}catch{}window.location.href=`/`},[]),[x,S]=(0,_.useState)(!1),C=(0,_.useCallback)(async()=>{S(!0);try{let e=await p();if(e){try{sessionStorage.removeItem(O)}catch{}window.location.href=`/`}return e}finally{S(!1)}},[]);return n?e?(0,v.jsx)(o,{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(O)}catch{}window.location.href=`/`},children:(0,v.jsx)(m,{cacheKey:e,businessName:i,sessionId:c,onLogout:b,onDisconnect:C,disconnecting:x,userName:f,userAvatar:g,role:u,children:(0,v.jsx)(Z,{cacheKey:e})})}):(0,v.jsx)(`div`,{className:`activity-page`,children:(0,v.jsxs)(`div`,{className:`activity-empty`,children:[(0,v.jsx)(`p`,{children:`You are not signed in.`}),(0,v.jsxs)(`p`,{children:[`Open the `,(0,v.jsx)(`a`,{href:`/`,className:`activity-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,v.jsx)(a,{surface:`gate`})}(0,g.createRoot)(document.getElementById(`root`)).render((0,v.jsx)(Q,{}));
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{o as e}from"./chunk-BycB0eMI.js";import{i as t,n,t as r}from"./jsx-runtime-BY35JYDT.js";import{C as i,E as a,F as o,P as s,R as c,ct as l,h as u,i as d,k as f,p,y as ee}from"./useMediaQuery-e4ciNiuO.js";import{n as m,t as h}from"./AdminLoginScreens-Bjsr45ed.js";import{T as g,c as _,p as te}from"./useVoiceRecorder-D7_wLtrS.js";import{h as ne,i as v,t as y,w as re,x as b}from"./AdminShell-Dm_nY4jF.js";import{t as x}from"./chevron-left-D3_hiHLC.js";import{i as S,n as C,r as ie}from"./page-CdRrpkky.js";import{t as ae}from"./file-text-CVZAL3Er.js";import"./graph-labels-BTFUSc63.js";import{n as oe}from"./file-download-B7zwa78w.js";var w=n(),T=e(t(),1),E=r();function D({onOpen:e}){return(0,E.jsx)(`footer`,{className:`admin-footer`,children:(0,E.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,E.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`powered-by-icon`}),(0,E.jsx)(`span`,{children:`Powered by Claude Code`})]})})}function O({sessionId:e,projectDir:t,sessionKey:n,contactName:r,onBack:i}){return(0,E.jsxs)(`div`,{className:`wa-web`,children:[(0,E.jsxs)(`header`,{className:`wa-web-header`,children:[i&&(0,E.jsx)(`button`,{type:`button`,className:`wa-web-back`,onClick:i,"aria-label":`Back`,children:(0,E.jsx)(x,{size:20})}),(0,E.jsx)(`span`,{className:`wa-web-avatar`,"aria-hidden":!0,children:(0,E.jsx)(g,{size:20})}),(0,E.jsx)(`div`,{className:`wa-web-titles`,children:(0,E.jsx)(`span`,{className:`wa-web-name`,children:r})})]}),(0,E.jsx)(`div`,{className:`wa-web-body`,children:(0,E.jsx)(_,{sessionId:e,projectDir:t,sessionKey:n,forceDeliveredOnly:!0})})]})}var k=6e4,A=60*k,j=24*A,M=k,N=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],P=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function F(e){return e<10?`0${e}`:String(e)}function I(e,t){let n=f(e,t);return Date.UTC(n.y,n.m-1,n.d)}function L(e,t,n){if(!Number.isFinite(e)||e<=0||!Number.isFinite(t))return`—`;let r=t-e;if(r<-M)return`—`;let i=r<0?0:r;if(i<k)return`just now`;if(i<A)return`${Math.floor(i/k)}m`;if(i<j)return`${Math.floor(i/A)}h`;let a=I(new Date(t),n),o=I(new Date(e),n),s=Math.round((a-o)/j);if(s===1)return`yesterday`;let c=f(new Date(e),n);if(s>=2&&s<=6)return P[new Date(o).getUTCDay()];let l=F(c.d),u=N[c.m-1],d=f(new Date(t),n).y;return c.y===d?`${l} ${u}`:`${l} ${u} ${c.y}`}function R({variant:e=`row`,count:t=1}){return(0,E.jsx)(E.Fragment,{children:Array.from({length:t},(t,n)=>(0,E.jsx)(`span`,{className:`dashboard-skeleton dashboard-skeleton--${e}`,"data-testid":`dashboard-skeleton`,"aria-hidden":`true`},n))})}var se=6e4;function ce(e){return e<12?`morning`:e<18?`afternoon`:`evening`}function z(e){return e&&e.trim().split(/\s+/)[0]||`there`}function le(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 B(e){return e==null?`—`:`${Math.round(e*100)}%`}function V(e){let t=Date.parse(e.lastMessageAt??``);return Number.isFinite(t)?t:-1/0}function ue(e,t,n){if(!e)return!1;let r=Date.parse(e);return Number.isFinite(r)?a(new Date(r),n)===a(new Date(t),n):!1}function de(e){return e?e.replace(/^claude-/,``):null}function fe(e,t,n,r,i){let a=0;for(let e=1;e<n.length;e+=1)V(n[e-1])<V(n[e])&&(a+=1);let o=!1;for(let e=1;e<t.length;e+=1)if(t[e-1].channel!==t[e].channel){o=!0;break}let s=new Map;for(let t of e)s.set(t.channel,(s.get(t.channel)??0)+1);return{feedRows:e.length,renderedRows:n.length,cap:r,hidden:e.length-n.length,expanded:i,outOfOrder:a,undated:e.filter(e=>V(e)===-1/0).length,channels:[...s.entries()].map(([e,t])=>`${e}:${t}`).join(`,`),interleaved:o}}var H=new Set([`sessions`,`conversations`,`tasks`,`artefacts`,`skills`,`stats`]),U=!1;function pe(e,t,n,r){let i=e=>t.get(e)??null,a=r?r.getEntriesByType(`navigation`)[0]:void 0,o=r?r.getEntriesByType(`resource`).filter(e=>new URL(e.name,`http://x`).pathname.startsWith(`/assets/`)):[],s=e=>e===void 0||!Number.isFinite(e)?null:Math.round(e),c=e=>e?s(e):null;return{batchMs:e,sessionsMs:i(`sessions`),conversationsMs:i(`conversations`),tasksMs:i(`tasks`),artefactsMs:i(`artefacts`),skillsMs:i(`skills`),statsMs:i(`stats`),failed:[...H].filter(e=>n.has(e)).join(`,`)||`none`,ttfbMs:s(a?.responseStart),domContentLoadedMs:c(a?.domContentLoadedEventEnd),loadMs:c(a?.loadEventEnd),assetCount:o.length,assetBytes:o.reduce((e,t)=>e+(t.transferSize||0),0),assetMs:o.length?s(Math.max(...o.map(e=>e.responseEnd))):null}}function W({cacheKey:e,userName:t,onSelectWhatsappConversation:n}){let{zone:r}=i(),a=o(e),[s,f]=(0,T.useState)(null),[m,h]=(0,T.useState)(null),[g,_]=(0,T.useState)(null),[v,y]=(0,T.useState)(null),[x,S]=(0,T.useState)(null),[C,ie]=(0,T.useState)(null),[w,D]=(0,T.useState)(null),[O,k]=(0,T.useState)(null),[A,j]=(0,T.useState)(null),[M,N]=(0,T.useState)(new Set),[P,F]=(0,T.useState)(()=>new Set),I=(0,T.useCallback)(e=>{F(t=>t.has(e)?t:new Set(t).add(e))},[]),H=Date.now(),W=(0,T.useRef)(!1),G=(0,T.useRef)(new Map),me=(0,T.useRef)(new Set),K=(0,T.useRef)(null);(0,T.useEffect)(()=>{if(!e)return;let t=!1;async function n(e,n,r,i){let o=Date.now(),s=typeof n==`string`?n:`unresolved`;try{typeof n!=`string`&&(s=await n());let e=await a(s);if(!e.ok)throw Error(`status ${e.status}`);let o=await e.json();t||i(r(o))}catch(t){me.current.add(e),console.error(`[admin-ui] dashboard-fetch-failed slice=${e} url=${s} ms=${Date.now()-o} reason=${t instanceof Error?t.message:String(t)}`)}finally{G.current.set(e,Date.now()-o),I(e)}}async function r(){if(!K.current){let e=await a(`/api/admin/accounts`);if(!e.ok)throw Error(`accounts status ${e.status}`);let t=await e.json(),n=t.accounts??[],r=t.activeAccountId??null,i=n.find(e=>e.accountId===r);if(!i)throw Error(`accounts: active ${r??`none`} absent from list of ${n.length}`);let o=i.isHouse||n.length===1;K.current={accountId:i.accountId,isHouse:o}}let{accountId:e,isHouse:t}=K.current;return t?`/api/operator-conversations/conversations-all`:`/api/operator-conversations/conversations`}let i={"sidebar-sessions":()=>n(`sessions`,`/api/admin/sidebar-sessions`,e=>e.sessions??[],f),"conversations-all":()=>n(`conversations`,r,e=>e.conversations??[],h),"tasks-list":()=>n(`tasks`,`/api/admin/tasks-list`,e=>e,y),"sidebar-artefacts":()=>n(`artefacts`,`/api/admin/sidebar-artefacts`,e=>e.artefacts??[],S),skills:()=>n(`skills`,`/api/admin/skills`,e=>e.skills??[],ie)};async function o(){if(W.current)return;W.current=!0;let e=Date.now();try{await Promise.all([...Object.values(i).map(e=>e()),n(`stats`,`/api/admin/system-stats`,e=>e,_),n(`bookingLink`,`/api/admin/calendar/booking-link`,e=>e.bookingDomain??null,D),n(`portalLink`,`/api/admin/data-portal/portal-link`,e=>e.portalDomain??null,k),n(`plannerLink`,`/api/admin/dispatch-planner/planner-link`,e=>e.plannerUrl??null,j)])}finally{W.current=!1;let t=Date.now()-e;if(!U){U=!0;try{let e=pe(t,G.current,me.current,typeof performance>`u`?null:performance);fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`event`,source:`dashboard-load`,...e}),keepalive:!0}).catch(()=>{})}catch{}}}}o();let s=null;try{s=new EventSource(l(`/api/admin/events`,e)),s.onmessage=e=>{if(document.visibilityState===`visible`)try{let{resource:t}=JSON.parse(e.data),n=t?i[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`&&o()},se),u=()=>{document.visibilityState===`visible`&&o()};return document.addEventListener(`visibilitychange`,u),()=>{t=!0,W.current=!1,clearInterval(c),s?.close(),document.removeEventListener(`visibilitychange`,u)}},[e,a]);let q=(0,T.useMemo)(()=>(s??[]).filter(e=>!e.isSubagent),[s]),J=(0,T.useMemo)(()=>q.filter(e=>e.live),[q]),he=(0,T.useMemo)(()=>(m??[]).filter(e=>ue(e.lastMessageAt,H,r)).length,[m,H]),ge=v?.open.length??0,Y=(0,T.useMemo)(()=>[...m??[]].sort((e,t)=>{let n=V(e),r=V(t);return n===r?0:r>n?1:-1}),[m]),[X,_e]=(0,T.useState)(!1),Z=X?Y:Y.slice(0,8),ve=Y.length-Z.length,ye=(0,T.useRef)(null),Q=(0,T.useRef)(null);(0,T.useEffect)(()=>{if(!P.has(`conversations`))return;let e=fe(m??[],Y,Z,8,X),t=JSON.stringify(e);ye.current!==t&&(ye.current=t,Q.current===null&&(Q.current=d()),fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`event`,source:`channels-card`,renderId:Q.current,...e})}).catch(()=>{}))},[P,m,Y,Z,X]);let be=(0,T.useRef)(!1);(0,T.useEffect)(()=>{be.current||!P.has(`bookingLink`)||!P.has(`portalLink`)||!P.has(`plannerLink`)||(be.current=!0)},[P,w,O,A]);let xe=(0,T.useCallback)(async e=>{if(!M.has(e)){N(t=>new Set(t).add(e));try{let t=await a(`/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}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{N(t=>{let n=new Set(t);return n.delete(e),n})}}},[a,M]),Se=(0,T.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}oe(e,t.downloadPath,t.downloadRoot??`data`)},[e]),$=ce(new Date(H).getHours());return(0,E.jsxs)(`div`,{className:`ui-page ui-page--full dashboard-home`,children:[(0,E.jsx)(`p`,{className:`dashboard-greeting`,children:P.has(`stats`)?`Good ${$}, ${z(t)} — ${le(g)}`:`Good ${$}, ${z(t)}`}),(0,E.jsxs)(`div`,{className:`dashboard-stats`,children:[(0,E.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,E.jsx)(`span`,{className:`dashboard-stat-label`,children:`Live sessions`}),P.has(`sessions`)?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`span`,{className:`dashboard-stat-value`,children:J.length}),(0,E.jsxs)(`span`,{className:`dashboard-stat-delta`,children:[`of `,q.length,` total`]})]}):(0,E.jsx)(R,{variant:`value`})]}),(0,E.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,E.jsx)(`span`,{className:`dashboard-stat-label`,children:`Messages today`}),P.has(`conversations`)?(0,E.jsx)(`span`,{className:`dashboard-stat-value`,children:he}):(0,E.jsx)(R,{variant:`value`})]}),(0,E.jsxs)(`a`,{className:`admin-stat-card dashboard-stat-card dashboard-stat-card--link`,href:`/tasks`,children:[(0,E.jsx)(`span`,{className:`dashboard-stat-label`,children:`Open tasks`}),P.has(`tasks`)?(0,E.jsx)(`span`,{className:`dashboard-stat-value`,children:ge}):(0,E.jsx)(R,{variant:`value`})]}),(0,E.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,E.jsx)(`span`,{className:`dashboard-stat-label`,children:`Host CPU`}),P.has(`stats`)?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`span`,{className:`dashboard-stat-value`,children:B(g?.cpuPct??null)}),(0,E.jsxs)(`span`,{className:`dashboard-stat-delta`,children:[`RAM `,B(g?.memUsedPct??null)]})]}):(0,E.jsx)(R,{variant:`value`})]})]}),(0,E.jsxs)(`div`,{className:`dashboard-columns`,children:[(0,E.jsxs)(`div`,{className:`dashboard-col`,children:[(w||O||A)&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Public pages`}),(0,E.jsxs)(`div`,{className:`admin-card dashboard-public-pages`,children:[w&&(0,E.jsxs)(`a`,{className:`admin-row dashboard-public-row`,href:`https://${w}`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,E.jsx)(`span`,{className:`dashboard-public-icon`,children:(0,E.jsx)(b,{size:16})}),(0,E.jsx)(`span`,{className:`dashboard-public-name`,children:`Booking page`})]}),O&&(0,E.jsxs)(`a`,{className:`admin-row dashboard-public-row`,href:`https://${O}`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,E.jsx)(`span`,{className:`dashboard-public-icon`,children:(0,E.jsx)(b,{size:16})}),(0,E.jsx)(`span`,{className:`dashboard-public-name`,children:`File drop`})]}),A&&(0,E.jsxs)(`a`,{className:`admin-row dashboard-public-row`,href:A,target:`_blank`,rel:`noopener noreferrer`,children:[(0,E.jsx)(`span`,{className:`dashboard-public-icon`,children:(0,E.jsx)(b,{size:16})}),(0,E.jsx)(`span`,{className:`dashboard-public-name`,children:`Planner`})]})]})]}),(0,E.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Live now`}),P.has(`sessions`)?J.length===0?(0,E.jsx)(`div`,{className:`admin-card dashboard-empty`,children:`No live sessions right now.`}):J.map(e=>{let t=[e.sessionId.slice(0,8),de(e.model),L(Date.parse(e.startedAt),H,r)].filter(Boolean).join(` · `);return(0,E.jsxs)(`div`,{className:`admin-card dashboard-live-card`,children:[(0,E.jsx)(`span`,{className:`admin-status-dot is-live`}),(0,E.jsxs)(`div`,{className:`dashboard-live-main`,children:[(0,E.jsx)(`span`,{className:`dashboard-live-name`,children:e.title}),(0,E.jsx)(`span`,{className:`dashboard-live-meta`,children:t})]}),(0,E.jsx)(`a`,{className:`admin-btn-cta dashboard-open-btn`,href:`/chat?session=${encodeURIComponent(e.sessionId)}`,children:`Open`}),(0,E.jsx)(`button`,{type:`button`,className:`dashboard-stop-btn`,"aria-label":`Stop ${e.title}`,disabled:M.has(e.sessionId),onClick:()=>void xe(e.sessionId),children:(0,E.jsx)(c,{size:12})})]},e.sessionId)}):(0,E.jsx)(R,{variant:`card`,count:2}),(0,E.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Recent artefacts`}),(0,E.jsx)(`div`,{className:`admin-card dashboard-artefacts`,children:P.has(`artefacts`)?(x??[]).length===0?(0,E.jsx)(`div`,{className:`dashboard-empty`,children:`No recent artefacts.`}):(x??[]).slice(0,6).map(e=>(0,E.jsxs)(`button`,{type:`button`,className:`admin-row dashboard-artefact-row`,onClick:()=>Se(e),children:[(0,E.jsx)(`span`,{className:`dashboard-artefact-icon`,children:e.kind===`agent-template`?(0,E.jsx)(re,{size:16}):(0,E.jsx)(ae,{size:16})}),(0,E.jsx)(`div`,{className:`dashboard-artefact-body`,children:(0,E.jsx)(`span`,{className:`dashboard-artefact-name`,children:e.name})}),(0,E.jsx)(`span`,{className:`dashboard-artefact-time`,children:L(Date.parse(e.updatedAt),H,r)})]},e.id)):(0,E.jsx)(R,{count:3})}),(0,E.jsx)(`a`,{className:`admin-section-label dashboard-col-label dashboard-skills-label`,href:`/skills`,children:`Skills`}),(0,E.jsx)(`div`,{className:`admin-card dashboard-skills`,children:P.has(`skills`)?(C??[]).length===0?(0,E.jsx)(`div`,{className:`dashboard-empty`,children:`No skills yet.`}):(C??[]).map(e=>(0,E.jsxs)(`a`,{className:`admin-row dashboard-skill-row`,href:`/skills`,children:[(0,E.jsx)(`span`,{className:`dashboard-skill-icon`,children:(0,E.jsx)(ne,{size:16})}),(0,E.jsxs)(`div`,{className:`dashboard-skill-body`,children:[(0,E.jsx)(`span`,{className:`dashboard-skill-name`,children:e.skill}),(0,E.jsx)(`span`,{className:`dashboard-skill-plugin`,children:e.plugin})]})]},`${e.plugin}/${e.skill}`)):(0,E.jsx)(R,{count:2})})]}),(0,E.jsxs)(`div`,{className:`dashboard-col`,children:[(0,E.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Channels`}),P.has(`conversations`)?Y.length===0?(0,E.jsx)(`div`,{className:`admin-card dashboard-empty`,children:`No channel activity.`}):(0,E.jsxs)(`div`,{className:`admin-card dashboard-channel-card`,children:[(0,E.jsx)(`div`,{className:`dashboard-channel-convs`,children:Z.map(t=>(0,E.jsxs)(`button`,{type:`button`,className:`admin-row dashboard-channel-conv-row`,onClick:()=>n(t),title:t.title,children:[(0,E.jsxs)(`span`,{className:`dashboard-channel-conv-line`,children:[(0,E.jsx)(`span`,{className:`dashboard-channel-conv-glyph`,children:(0,E.jsx)(ee,{channel:t.channel,size:13})}),(0,E.jsx)(te,{accountId:t.accountId??``,jid:t.remoteJid,sessionKey:e??``,className:`dashboard-channel-conv-avatar`,size:16}),(0,E.jsx)(`span`,{className:`dashboard-channel-conv-name`,children:p(t)}),t.isGroup===!0&&(0,E.jsx)(`span`,{className:`dashboard-channel-conv-tag is-group`,children:`Group`}),t.role===`public`&&(0,E.jsx)(`span`,{className:`dashboard-channel-conv-tag is-public`,children:`Public`}),(0,E.jsx)(`span`,{className:`dashboard-channel-conv-tag`,children:t.isHouse?`House`:`Client`}),!t.preview&&t.lastMessageAt&&(0,E.jsx)(`span`,{className:`dashboard-channel-conv-time`,children:L(Date.parse(t.lastMessageAt),H,r)})]}),t.preview?(0,E.jsxs)(`span`,{className:`dashboard-channel-conv-sub`,children:[(0,E.jsx)(`span`,{className:`dashboard-channel-conv-preview`,children:t.preview}),t.lastMessageAt&&(0,E.jsx)(`span`,{className:`dashboard-channel-conv-time`,children:L(Date.parse(t.lastMessageAt),H,r)})]}):null]},u(t)))}),ve>0&&(0,E.jsxs)(`button`,{type:`button`,className:`dashboard-channel-more`,onClick:()=>_e(!0),children:[`Show `,ve,` more`]})]}):(0,E.jsx)(R,{variant:`card`,count:2})]})]})]})}function G(){let e=m(),[t,n]=(0,T.useState)(!1);(0,T.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,T.useCallback)(async()=>{let t=e.claudeInfo!=null;if(n(!0),t)return;let r=Date.now();if(!e.cacheKey){console.error(`[admin-ui] claude-info-fetch-skipped reason=no-session-key`);return}try{let t=await fetch(`/api/admin/claude-info?session_key=${encodeURIComponent(e.cacheKey)}`);if(t.ok){let n=await t.json();e.setClaudeInfo(n)}}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,T.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,E.jsx)(s,{cacheKey:e.cacheKey,onSessionExpired:i,surface:`chat`,children:(0,E.jsx)(y,{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,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(D,{onOpen:r}),(0,E.jsx)(v,{show:t,onClose:()=>n(!1),claudeInfo:e.claudeInfo,messages:[],sessionElapsed:0,sessionId:e.sessionId,cacheKey:e.cacheKey})]}),children:t=>(0,E.jsx)(E.Fragment,{children:t.dataOpen&&e.cacheKey?(0,E.jsx)(C,{cacheKey:e.cacheKey}):t.selectedWhatsapp&&e.cacheKey?t.selectedWhatsapp.source===`store`&&t.selectedWhatsapp.channel===`telegram`&&t.selectedWhatsapp.channelKey&&t.selectedWhatsapp.accountId?(0,E.jsx)(S,{accountId:t.selectedWhatsapp.accountId,channelKey:t.selectedWhatsapp.channelKey,contactName:p(t.selectedWhatsapp),sessionKey:e.cacheKey,onBack:t.onClearWhatsapp},u(t.selectedWhatsapp)):t.selectedWhatsapp.source===`store`&&t.selectedWhatsapp.remoteJid&&t.selectedWhatsapp.accountId?(0,E.jsx)(ie,{accountId:t.selectedWhatsapp.accountId,remoteJid:t.selectedWhatsapp.remoteJid,contactName:p(t.selectedWhatsapp),sessionKey:e.cacheKey,onBack:t.onClearWhatsapp},u(t.selectedWhatsapp)):(0,E.jsx)(O,{sessionId:t.selectedWhatsapp.sessionId,projectDir:t.selectedWhatsapp.projectDir,sessionKey:e.cacheKey,contactName:p(t.selectedWhatsapp),onBack:t.onClearWhatsapp},u(t.selectedWhatsapp)):(0,E.jsx)(W,{cacheKey:e.cacheKey,userName:e.userName,onSelectWhatsappConversation:t.onSelectWhatsappConversation})})})}):(0,E.jsx)(h,{auth:e})}(0,w.createRoot)(document.getElementById(`root`)).render((0,E.jsx)(G,{}));
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./chunk-BycB0eMI.js";import{i as t,n,t as r}from"./jsx-runtime-BCAZhYqz.js";import{I as i,K as a,L as o,N as s,P as c,lt as l,nt as u}from"./useMediaQuery-CLVRXJMp.js";import{A as d,T as f,t as p,x as m}from"./AdminShell-CrCdEMNW.js";var h=u(`power-off`,[[`path`,{d:`M18.36 6.64A9 9 0 0 1 20.77 15`,key:`dxknvb`}],[`path`,{d:`M6.16 6.16a9 9 0 1 0 12.68 12.68`,key:`1x7qb5`}],[`path`,{d:`M12 2v4`,key:`3427ic`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),g=u(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),_=n(),v=e(t(),1),y={green:`success`,amber:`warning`,red:`error`};function b(e){if(!e.startsWith(`mcp__`))return e;let t=e.slice(5),n=t.indexOf(`__`);if(n<0)return e;let r=t.slice(n+2);return r.length>0?r:e}function x(e){let t=` Nothing will be able to hand work to it until it is switched back on.`;if(e.length===0)return t;let n=e.length===1?`skill runs`:`skills run`;return` ${e.length} ${n} through it: ${e.join(`, `)}.${t}`}var S=r(),C={read:`read`,write_local:`writes`,exec:`runs`,external:`sends`},w={read:`tool-chip-read`,write_local:`tool-chip-write_local`,exec:`tool-chip-exec`,external:`tool-chip-external`,unresolved:`tool-chip-unresolved`};function T({label:e,body:t}){return(0,S.jsxs)(`div`,{className:`agent-doc`,children:[(0,S.jsx)(`span`,{className:`agent-doc-label`,children:e}),(0,S.jsx)(`pre`,{className:`skill-body`,children:t.trim()||`Empty.`})]})}function E({summary:e,publicBaseUrl:t,accountId:n,adminFetch:r,onClose:s,onDeleted:c,onToggled:l}){let u=e.kind===`specialist`,d=e.origin===`specialist`,p=e.origin===`shipped`&&e.disabled,_=d||p,[E]=(0,v.useState)(n),[D,O]=(0,v.useState)(null),[k,A]=(0,v.useState)(!0),[j,M]=(0,v.useState)(null),[N,P]=(0,v.useState)(!1),[F,I]=(0,v.useState)(!1),[L,R]=(0,v.useState)(!1),[z,B]=(0,v.useState)(!1);(0,v.useEffect)(()=>{let t=!1;A(!0),M(null);let n=e.origin===`shipped`?`?origin=shipped`: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}`);O((await e.json()).agent)}}).catch(e=>{t||M(e instanceof Error?e.message:`Failed to load`)}).finally(()=>{t||A(!1)}),()=>{t=!0}},[r,e.slug]),(0,v.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!F&&s()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[F,s]);let V=(0,v.useCallback)(async()=>{I(!0),M(null);try{let t=await r(`/api/admin/agents/${encodeURIComponent(e.slug)}?accountId=${encodeURIComponent(E??``)}`,{method:`DELETE`,headers:{"content-type":`application/json`}});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??`HTTP ${t.status}`)}c(e)}catch(e){M(e instanceof Error?e.message:`Delete failed`),I(!1),P(!1)}},[r,e,E,c]),H=(0,v.useCallback)(async()=>{let t=e.disabled?`enable`:`disable`;B(!0),M(null);try{let n=await r(`/api/admin/agents/${encodeURIComponent(e.slug)}/${t}?accountId=${encodeURIComponent(E??``)}`,{method:`POST`,headers:{"content-type":`application/json`}});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??`HTTP ${n.status}`)}l(),s()}catch(e){M(e instanceof Error?e.message:`${t} failed`),B(!1),R(!1)}},[r,e,E,l,s]),U=u?null:D,W=u?D:null;return(0,S.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{F||s()},children:(0,S.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":`Agent detail`,onClick:e=>e.stopPropagation(),children:[(0,S.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,S.jsxs)(`span`,{className:`cal-modal-kind`,children:[(0,S.jsx)(f,{size:13}),` `,u?`Specialist`:`Agent`]}),(0,S.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:s,"aria-label":`Close`,autoFocus:!0,disabled:F,children:(0,S.jsx)(i,{size:16})})]}),(0,S.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,S.jsx)(`div`,{className:`cal-modal-title`,children:e.displayName}),(0,S.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[!u&&(0,S.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),(0,S.jsxs)(`span`,{children:[`/`,e.slug]}),e.risk&&(0,S.jsx)(`span`,{className:`ui-pill ui-pill--solid-${y[e.risk]}`,children:e.risk===`green`?`Read only`:e.risk===`amber`?`Writes`:`Runs`}),e.disabled&&(0,S.jsx)(`span`,{className:`ui-pill ui-pill--tint-error`,children:`Disabled`})]}),e.risk&&e.riskReason&&(0,S.jsx)(`div`,{className:`cal-modal-row agent-risk-reason`,children:(0,S.jsx)(`span`,{children:e.riskReason})}),e.unresolved.length>0&&(0,S.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,S.jsxs)(`span`,{children:[`Forced to Runs: no declared risk class for `,e.unresolved.join(`, `),`.`]})}),k&&(0,S.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,S.jsx)(a,{size:14,className:`spin`}),(0,S.jsx)(`span`,{children:`Loading…`})]}),U&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,S.jsxs)(`span`,{children:[U.status,U.model?` · ${U.model}`:``]})}),(0,S.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,S.jsxs)(`a`,{href:`${t}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`cal-link`,children:[(0,S.jsx)(m,{size:13}),` Open agent`]})}),U.present.identity&&(0,S.jsx)(T,{label:`Identity`,body:U.identity}),U.present.soul&&(0,S.jsx)(T,{label:`Soul`,body:U.soul}),U.present.knowledge&&(0,S.jsx)(T,{label:`Knowledge`,body:U.knowledge}),U.present.knowledgeSummary&&(0,S.jsx)(T,{label:`Knowledge summary`,body:U.knowledgeSummary}),U.knowledgeKeywords.length>0&&(0,S.jsxs)(`div`,{className:`skill-refs`,children:[(0,S.jsx)(`span`,{className:`skill-refs-label`,children:`Knowledge keywords`}),U.knowledgeKeywords.map(e=>(0,S.jsx)(`span`,{className:`skill-ref`,children:e},e))]})]}),W&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,S.jsxs)(`span`,{children:[e.plugin,W.model?` · ${W.model}`:``]})}),W.description&&(0,S.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,S.jsx)(`span`,{children:W.description})}),W.byTool.length>0&&(0,S.jsxs)(`div`,{className:`chip-refs`,children:[(0,S.jsxs)(`span`,{className:`skill-refs-label`,children:[`Tools (`,W.byTool.length,`)`]}),(0,S.jsx)(`div`,{className:`chip-row`,children:W.byTool.map(({tool:e,risk:t})=>(0,S.jsx)(`span`,{"data-testid":`tool-chip-${e}`,className:`tool-chip ${w[t??`unresolved`]}`,title:t?`${e} — ${C[t]}`:`${e} — no declared risk class`,children:b(e)},e))})]}),W.skills.length>0&&(0,S.jsxs)(`div`,{className:`chip-refs`,children:[(0,S.jsx)(`span`,{className:`skill-refs-label`,children:`Skills`}),(0,S.jsx)(`div`,{className:`chip-row`,children:W.skills.map(e=>(0,S.jsx)(`span`,{className:`tool-chip tool-chip-skill`,children:e},e))})]}),(0,S.jsx)(T,{label:`System prompt`,body:W.systemPrompt})]})]}),j&&(0,S.jsx)(`div`,{className:`cal-modal-error`,children:j}),(0,S.jsx)(`div`,{className:`cal-modal-actions`,children:_?L?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`span`,{className:`cal-modal-confirm-text`,children:e.disabled?`Put this agent back in the dispatchable set?`:`Stop this agent being dispatched?${x(W?.skills??[])}`}),(0,S.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:H,disabled:z,children:[z?(0,S.jsx)(a,{size:14,className:`spin`}):e.disabled?(0,S.jsx)(g,{size:14}):(0,S.jsx)(h,{size:14}),e.disabled?` Enable`:` Disable`]}),(0,S.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>R(!1),disabled:z,children:`Cancel`})]}):(0,S.jsx)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:()=>R(!0),disabled:z||k||!E,children:e.disabled?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(g,{size:14}),` Enable`]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(h,{size:14}),` Disable`]})}):u?(0,S.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`This agent is part of the product. To stop it running on its own, suspend the routines that dispatch it.`}):(0,S.jsxs)(S.Fragment,{children:[!N&&(0,S.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:()=>P(!0),disabled:F||k||!E,children:[(0,S.jsx)(o,{size:14}),` Delete`]}),N&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Delete this agent?`}),(0,S.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:V,disabled:F,children:[F?(0,S.jsx)(a,{size:14,className:`spin`}):(0,S.jsx)(o,{size:14}),` Delete`]}),(0,S.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>P(!1),disabled:F,children:`Cancel`})]})]})})]})})}var D=`maxy-admin-session-key`,O={green:`Read only`,amber:`Writes`,red:`Runs`},k={shipped:`Shipped`,specialist:`Specialist`,public:`Public`};function A(){let[e,t]=(0,v.useState)(null),[n,r]=(0,v.useState)(!1),[i,a]=(0,v.useState)(void 0),[o,l]=(0,v.useState)(null),[u,f]=(0,v.useState)(void 0),[m,h]=(0,v.useState)(null),[g,_]=(0,v.useState)(null);(0,v.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(D)}catch{}if(!n){r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`;return}if(i.ok)try{let e=await i.json();typeof e.businessName==`string`&&a(e.businessName),e.sessionId!==void 0&&l(e.sessionId??null),_(e.role??null),f(e.userName===void 0?null:e.userName),h(e.avatar??null)}catch{}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]);let y=(0,v.useCallback)(()=>{try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`},[]),[b,x]=(0,v.useState)(!1),C=(0,v.useCallback)(async()=>{x(!0);try{let e=await d();if(e){try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`}return e}finally{x(!1)}},[]);return n?e?(0,S.jsx)(c,{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(D)}catch{}window.location.href=`/`},children:(0,S.jsx)(p,{cacheKey:e,businessName:i,sessionId:o,onLogout:y,onDisconnect:C,disconnecting:b,userName:u,userAvatar:m,role:g,children:(0,S.jsx)(j,{cacheKey:e})})}):(0,S.jsx)(`div`,{className:`cal-page`,children:(0,S.jsxs)(`div`,{className:`cal-empty`,children:[(0,S.jsx)(`p`,{children:`You are not signed in.`}),(0,S.jsxs)(`p`,{children:[`Open the `,(0,S.jsx)(`a`,{href:`/`,className:`cal-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,S.jsx)(s,{surface:`gate`})}function j({cacheKey:e}){let{adminFetch:t,sessionRefetchNonce:n}=l({initialCacheKey:e,surface:`agents`}),[r,i]=(0,v.useState)([]),[o,c]=(0,v.useState)(0),[u,d]=(0,v.useState)(0),[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(null),[_,b]=(0,v.useState)(!1),[x,C]=(0,v.useState)(!1),[w,T]=(0,v.useState)(null),[D,A]=(0,v.useState)(null),[j,M]=(0,v.useState)(``);(0,v.useEffect)(()=>{M(window.location.hostname.startsWith(`admin.`)?window.location.origin.replace(`admin.`,`public.`):window.location.origin)},[]);let N=(0,v.useCallback)(()=>{let e=!1;return b(!0),T(null),t(`/api/admin/agents`).then(async t=>{if(e)return;if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();i(Array.isArray(n.agents)?n.agents:[]),c(typeof n.skipped==`number`?n.skipped:0),d(typeof n.specialistsSkipped==`number`?n.specialistsSkipped:0),g(typeof n.accountId==`string`?n.accountId:null),m(n.riskSurfaceFailed===!0)}).catch(t=>{e||(T(t instanceof Error?t.message:`Failed to load`),i([]))}).finally(()=>{e||(b(!1),C(!0))}),()=>{e=!0}},[t]);(0,v.useEffect)(()=>N(),[N,n]);let P=(0,v.useCallback)(e=>{i(t=>t.filter(t=>t.slug!==e.slug)),A(null),N()},[N]);if(!x)return(0,S.jsx)(s,{surface:`gate`});let F=r.filter(e=>e.disabled).length;return(0,S.jsxs)(`div`,{className:`cal-page`,children:[(0,S.jsx)(`header`,{className:`cal-header`,children:(0,S.jsxs)(`div`,{className:`cal-nav`,children:[(0,S.jsxs)(`span`,{className:`cal-range-label`,children:[(0,S.jsx)(f,{size:16}),` `,r.length,` agent`,r.length===1?``:`s`,` · `,F,` stood down`]}),_&&(0,S.jsx)(a,{size:16,className:`spin`})]})}),(0,S.jsxs)(`div`,{className:`cal-body agents-body`,children:[w&&(0,S.jsxs)(`div`,{className:`cal-error`,children:[`Could not load agents: `,w]}),p&&(0,S.jsx)(`div`,{className:`cal-error`,children:`The plugin registry could not be read, so every agent below is shown at the highest risk regardless of the tools it declares. These badges are not derived.`}),o+u>0&&(0,S.jsxs)(`div`,{className:`cal-error`,children:[o+u,` agent`,o+u===1?``:`s`,` could not be read (malformed config or frontmatter).`]}),!w&&!_&&r.length===0&&(0,S.jsx)(`div`,{className:`cal-empty`,children:(0,S.jsx)(`p`,{children:`No agents yet. Ask in chat to create one.`})}),r.length>0&&(0,S.jsx)(`div`,{className:`routine-list agents-list`,children:r.map(e=>(0,S.jsxs)(`button`,{type:`button`,className:`admin-card admin-card--padded routine-card`,onClick:()=>A(e),children:[(0,S.jsxs)(`span`,{className:`admin-card-title routine-card-title`,children:[e.displayName,e.risk&&(0,S.jsx)(`span`,{className:`ui-pill ui-pill--solid-${y[e.risk]}`,"data-testid":`agent-risk-badge`,children:O[e.risk]}),(0,S.jsx)(`span`,{className:`ui-pill agent-origin-${e.origin}`,children:k[e.origin]}),e.kind===`specialist`&&(0,S.jsx)(`span`,{className:`ui-pill ${e.disabled?`ui-pill--tint-error`:`ui-pill--tint-success`}`,children:e.disabled?`Stood down`:`Live`})]}),e.kind===`specialist`?(0,S.jsxs)(`span`,{className:`routine-card-sched`,children:[`/`,e.slug]}):(0,S.jsxs)(`span`,{className:`routine-card-sched`,children:[(0,S.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),` /`,e.slug]}),(0,S.jsx)(`span`,{className:`routine-card-meta`,children:e.origin===`public`?e.status:e.plugin})]},`${e.origin}:${e.slug}`))})]}),D&&(0,S.jsx)(E,{summary:D,publicBaseUrl:j,accountId:h,adminFetch:t,onClose:()=>A(null),onDeleted:P,onToggled:N})]})}(0,_.createRoot)(document.getElementById(`root`)).render((0,S.jsx)(A,{}));
|
|
1
|
+
import{o as e}from"./chunk-BycB0eMI.js";import{i as t,n,t as r}from"./jsx-runtime-BY35JYDT.js";import{I as i,K as a,L as o,N as s,P as c,rt as l,ut as u}from"./useMediaQuery-e4ciNiuO.js";import{k as d,t as f,w as p,x as m}from"./AdminShell-Dm_nY4jF.js";var h=l(`power-off`,[[`path`,{d:`M18.36 6.64A9 9 0 0 1 20.77 15`,key:`dxknvb`}],[`path`,{d:`M6.16 6.16a9 9 0 1 0 12.68 12.68`,key:`1x7qb5`}],[`path`,{d:`M12 2v4`,key:`3427ic`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),g=l(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),_=n(),v=e(t(),1),y={green:`success`,amber:`warning`,red:`error`};function b(e){if(!e.startsWith(`mcp__`))return e;let t=e.slice(5),n=t.indexOf(`__`);if(n<0)return e;let r=t.slice(n+2);return r.length>0?r:e}function x(e){let t=` Nothing will be able to hand work to it until it is switched back on.`;if(e.length===0)return t;let n=e.length===1?`skill runs`:`skills run`;return` ${e.length} ${n} through it: ${e.join(`, `)}.${t}`}var S=r(),C={read:`read`,write_local:`writes`,exec:`runs`,external:`sends`},w={read:`tool-chip-read`,write_local:`tool-chip-write_local`,exec:`tool-chip-exec`,external:`tool-chip-external`,unresolved:`tool-chip-unresolved`};function T({label:e,body:t}){return(0,S.jsxs)(`div`,{className:`agent-doc`,children:[(0,S.jsx)(`span`,{className:`agent-doc-label`,children:e}),(0,S.jsx)(`pre`,{className:`skill-body`,children:t.trim()||`Empty.`})]})}function E({summary:e,publicBaseUrl:t,accountId:n,adminFetch:r,onClose:s,onDeleted:c,onToggled:l}){let u=e.kind===`specialist`,d=e.origin===`specialist`,f=e.origin===`shipped`&&e.disabled,_=d||f,[E]=(0,v.useState)(n),[D,O]=(0,v.useState)(null),[k,A]=(0,v.useState)(!0),[j,M]=(0,v.useState)(null),[N,P]=(0,v.useState)(!1),[F,I]=(0,v.useState)(!1),[L,R]=(0,v.useState)(!1),[z,B]=(0,v.useState)(!1);(0,v.useEffect)(()=>{let t=!1;A(!0),M(null);let n=e.origin===`shipped`?`?origin=shipped`: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}`);O((await e.json()).agent)}}).catch(e=>{t||M(e instanceof Error?e.message:`Failed to load`)}).finally(()=>{t||A(!1)}),()=>{t=!0}},[r,e.slug]),(0,v.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!F&&s()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[F,s]);let V=(0,v.useCallback)(async()=>{I(!0),M(null);try{let t=await r(`/api/admin/agents/${encodeURIComponent(e.slug)}?accountId=${encodeURIComponent(E??``)}`,{method:`DELETE`,headers:{"content-type":`application/json`}});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??`HTTP ${t.status}`)}c(e)}catch(e){M(e instanceof Error?e.message:`Delete failed`),I(!1),P(!1)}},[r,e,E,c]),H=(0,v.useCallback)(async()=>{let t=e.disabled?`enable`:`disable`;B(!0),M(null);try{let n=await r(`/api/admin/agents/${encodeURIComponent(e.slug)}/${t}?accountId=${encodeURIComponent(E??``)}`,{method:`POST`,headers:{"content-type":`application/json`}});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error??`HTTP ${n.status}`)}l(),s()}catch(e){M(e instanceof Error?e.message:`${t} failed`),B(!1),R(!1)}},[r,e,E,l,s]),U=u?null:D,W=u?D:null;return(0,S.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{F||s()},children:(0,S.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":`Agent detail`,onClick:e=>e.stopPropagation(),children:[(0,S.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,S.jsxs)(`span`,{className:`cal-modal-kind`,children:[(0,S.jsx)(p,{size:13}),` `,u?`Specialist`:`Agent`]}),(0,S.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:s,"aria-label":`Close`,autoFocus:!0,disabled:F,children:(0,S.jsx)(i,{size:16})})]}),(0,S.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,S.jsx)(`div`,{className:`cal-modal-title`,children:e.displayName}),(0,S.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[!u&&(0,S.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),(0,S.jsxs)(`span`,{children:[`/`,e.slug]}),e.risk&&(0,S.jsx)(`span`,{className:`ui-pill ui-pill--solid-${y[e.risk]}`,children:e.risk===`green`?`Read only`:e.risk===`amber`?`Writes`:`Runs`}),e.disabled&&(0,S.jsx)(`span`,{className:`ui-pill ui-pill--tint-error`,children:`Disabled`})]}),e.risk&&e.riskReason&&(0,S.jsx)(`div`,{className:`cal-modal-row agent-risk-reason`,children:(0,S.jsx)(`span`,{children:e.riskReason})}),e.unresolved.length>0&&(0,S.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,S.jsxs)(`span`,{children:[`Forced to Runs: no declared risk class for `,e.unresolved.join(`, `),`.`]})}),k&&(0,S.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,S.jsx)(a,{size:14,className:`spin`}),(0,S.jsx)(`span`,{children:`Loading…`})]}),U&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,S.jsxs)(`span`,{children:[U.status,U.model?` · ${U.model}`:``]})}),(0,S.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,S.jsxs)(`a`,{href:`${t}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`cal-link`,children:[(0,S.jsx)(m,{size:13}),` Open agent`]})}),U.present.identity&&(0,S.jsx)(T,{label:`Identity`,body:U.identity}),U.present.soul&&(0,S.jsx)(T,{label:`Soul`,body:U.soul}),U.present.knowledge&&(0,S.jsx)(T,{label:`Knowledge`,body:U.knowledge}),U.present.knowledgeSummary&&(0,S.jsx)(T,{label:`Knowledge summary`,body:U.knowledgeSummary}),U.knowledgeKeywords.length>0&&(0,S.jsxs)(`div`,{className:`skill-refs`,children:[(0,S.jsx)(`span`,{className:`skill-refs-label`,children:`Knowledge keywords`}),U.knowledgeKeywords.map(e=>(0,S.jsx)(`span`,{className:`skill-ref`,children:e},e))]})]}),W&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,S.jsxs)(`span`,{children:[e.plugin,W.model?` · ${W.model}`:``]})}),W.description&&(0,S.jsx)(`div`,{className:`cal-modal-row cal-modal-meta`,children:(0,S.jsx)(`span`,{children:W.description})}),W.byTool.length>0&&(0,S.jsxs)(`div`,{className:`chip-refs`,children:[(0,S.jsxs)(`span`,{className:`skill-refs-label`,children:[`Tools (`,W.byTool.length,`)`]}),(0,S.jsx)(`div`,{className:`chip-row`,children:W.byTool.map(({tool:e,risk:t})=>(0,S.jsx)(`span`,{"data-testid":`tool-chip-${e}`,className:`tool-chip ${w[t??`unresolved`]}`,title:t?`${e} — ${C[t]}`:`${e} — no declared risk class`,children:b(e)},e))})]}),W.skills.length>0&&(0,S.jsxs)(`div`,{className:`chip-refs`,children:[(0,S.jsx)(`span`,{className:`skill-refs-label`,children:`Skills`}),(0,S.jsx)(`div`,{className:`chip-row`,children:W.skills.map(e=>(0,S.jsx)(`span`,{className:`tool-chip tool-chip-skill`,children:e},e))})]}),(0,S.jsx)(T,{label:`System prompt`,body:W.systemPrompt})]})]}),j&&(0,S.jsx)(`div`,{className:`cal-modal-error`,children:j}),(0,S.jsx)(`div`,{className:`cal-modal-actions`,children:_?L?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`span`,{className:`cal-modal-confirm-text`,children:e.disabled?`Put this agent back in the dispatchable set?`:`Stop this agent being dispatched?${x(W?.skills??[])}`}),(0,S.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:H,disabled:z,children:[z?(0,S.jsx)(a,{size:14,className:`spin`}):e.disabled?(0,S.jsx)(g,{size:14}):(0,S.jsx)(h,{size:14}),e.disabled?` Enable`:` Disable`]}),(0,S.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>R(!1),disabled:z,children:`Cancel`})]}):(0,S.jsx)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:()=>R(!0),disabled:z||k||!E,children:e.disabled?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(g,{size:14}),` Enable`]}):(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(h,{size:14}),` Disable`]})}):u?(0,S.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`This agent is part of the product. To stop it running on its own, suspend the routines that dispatch it.`}):(0,S.jsxs)(S.Fragment,{children:[!N&&(0,S.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:()=>P(!0),disabled:F||k||!E,children:[(0,S.jsx)(o,{size:14}),` Delete`]}),N&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Delete this agent?`}),(0,S.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:V,disabled:F,children:[F?(0,S.jsx)(a,{size:14,className:`spin`}):(0,S.jsx)(o,{size:14}),` Delete`]}),(0,S.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>P(!1),disabled:F,children:`Cancel`})]})]})})]})})}var D=`maxy-admin-session-key`,O={green:`Read only`,amber:`Writes`,red:`Runs`},k={shipped:`Shipped`,specialist:`Specialist`,public:`Public`};function A(){let[e,t]=(0,v.useState)(null),[n,r]=(0,v.useState)(!1),[i,a]=(0,v.useState)(void 0),[o,l]=(0,v.useState)(null),[u,p]=(0,v.useState)(void 0),[m,h]=(0,v.useState)(null),[g,_]=(0,v.useState)(null);(0,v.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(D)}catch{}if(!n){r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`;return}if(i.ok)try{let e=await i.json();typeof e.businessName==`string`&&a(e.businessName),e.sessionId!==void 0&&l(e.sessionId??null),_(e.role??null),p(e.userName===void 0?null:e.userName),h(e.avatar??null)}catch{}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]);let y=(0,v.useCallback)(()=>{try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`},[]),[b,x]=(0,v.useState)(!1),C=(0,v.useCallback)(async()=>{x(!0);try{let e=await d();if(e){try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`}return e}finally{x(!1)}},[]);return n?e?(0,S.jsx)(c,{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(D)}catch{}window.location.href=`/`},children:(0,S.jsx)(f,{cacheKey:e,businessName:i,sessionId:o,onLogout:y,onDisconnect:C,disconnecting:b,userName:u,userAvatar:m,role:g,children:(0,S.jsx)(j,{cacheKey:e})})}):(0,S.jsx)(`div`,{className:`cal-page`,children:(0,S.jsxs)(`div`,{className:`cal-empty`,children:[(0,S.jsx)(`p`,{children:`You are not signed in.`}),(0,S.jsxs)(`p`,{children:[`Open the `,(0,S.jsx)(`a`,{href:`/`,className:`cal-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,S.jsx)(s,{surface:`gate`})}function j({cacheKey:e}){let{adminFetch:t,sessionRefetchNonce:n}=u({initialCacheKey:e,surface:`agents`}),[r,i]=(0,v.useState)([]),[o,c]=(0,v.useState)(0),[l,d]=(0,v.useState)(0),[f,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(null),[_,b]=(0,v.useState)(!1),[x,C]=(0,v.useState)(!1),[w,T]=(0,v.useState)(null),[D,A]=(0,v.useState)(null),[j,M]=(0,v.useState)(``);(0,v.useEffect)(()=>{M(window.location.hostname.startsWith(`admin.`)?window.location.origin.replace(`admin.`,`public.`):window.location.origin)},[]);let N=(0,v.useCallback)(()=>{let e=!1;return b(!0),T(null),t(`/api/admin/agents`).then(async t=>{if(e)return;if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();i(Array.isArray(n.agents)?n.agents:[]),c(typeof n.skipped==`number`?n.skipped:0),d(typeof n.specialistsSkipped==`number`?n.specialistsSkipped:0),g(typeof n.accountId==`string`?n.accountId:null),m(n.riskSurfaceFailed===!0)}).catch(t=>{e||(T(t instanceof Error?t.message:`Failed to load`),i([]))}).finally(()=>{e||(b(!1),C(!0))}),()=>{e=!0}},[t]);(0,v.useEffect)(()=>N(),[N,n]);let P=(0,v.useCallback)(e=>{i(t=>t.filter(t=>t.slug!==e.slug)),A(null),N()},[N]);if(!x)return(0,S.jsx)(s,{surface:`gate`});let F=r.filter(e=>e.disabled).length;return(0,S.jsxs)(`div`,{className:`cal-page`,children:[(0,S.jsx)(`header`,{className:`cal-header`,children:(0,S.jsxs)(`div`,{className:`cal-nav`,children:[(0,S.jsxs)(`span`,{className:`cal-range-label`,children:[(0,S.jsx)(p,{size:16}),` `,r.length,` agent`,r.length===1?``:`s`,` · `,F,` stood down`]}),_&&(0,S.jsx)(a,{size:16,className:`spin`})]})}),(0,S.jsxs)(`div`,{className:`cal-body agents-body`,children:[w&&(0,S.jsxs)(`div`,{className:`cal-error`,children:[`Could not load agents: `,w]}),f&&(0,S.jsx)(`div`,{className:`cal-error`,children:`The plugin registry could not be read, so every agent below is shown at the highest risk regardless of the tools it declares. These badges are not derived.`}),o+l>0&&(0,S.jsxs)(`div`,{className:`cal-error`,children:[o+l,` agent`,o+l===1?``:`s`,` could not be read (malformed config or frontmatter).`]}),!w&&!_&&r.length===0&&(0,S.jsx)(`div`,{className:`cal-empty`,children:(0,S.jsx)(`p`,{children:`No agents yet. Ask in chat to create one.`})}),r.length>0&&(0,S.jsx)(`div`,{className:`routine-list agents-list`,children:r.map(e=>(0,S.jsxs)(`button`,{type:`button`,className:`admin-card admin-card--padded routine-card`,onClick:()=>A(e),children:[(0,S.jsxs)(`span`,{className:`admin-card-title routine-card-title`,children:[e.displayName,e.risk&&(0,S.jsx)(`span`,{className:`ui-pill ui-pill--solid-${y[e.risk]}`,"data-testid":`agent-risk-badge`,children:O[e.risk]}),(0,S.jsx)(`span`,{className:`ui-pill agent-origin-${e.origin}`,children:k[e.origin]}),e.kind===`specialist`&&(0,S.jsx)(`span`,{className:`ui-pill ${e.disabled?`ui-pill--tint-error`:`ui-pill--tint-success`}`,children:e.disabled?`Stood down`:`Live`})]}),e.kind===`specialist`?(0,S.jsxs)(`span`,{className:`routine-card-sched`,children:[`/`,e.slug]}):(0,S.jsxs)(`span`,{className:`routine-card-sched`,children:[(0,S.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),` /`,e.slug]}),(0,S.jsx)(`span`,{className:`routine-card-meta`,children:e.origin===`public`?e.status:e.plugin})]},`${e.origin}:${e.slug}`))})]}),D&&(0,S.jsx)(E,{summary:D,publicBaseUrl:j,accountId:h,adminFetch:t,onClose:()=>A(null),onDeleted:P,onToggled:N})]})}(0,_.createRoot)(document.getElementById(`root`)).render((0,S.jsx)(A,{}));
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./chunk-BycB0eMI.js";import{i as t,n,t as r}from"./jsx-runtime-
|
|
1
|
+
import{o as e}from"./chunk-BycB0eMI.js";import{i as t,n,t as r}from"./jsx-runtime-BY35JYDT.js";import{J as i,K as a,P as o}from"./useMediaQuery-e4ciNiuO.js";import{k as s,p as c,t as l}from"./AdminShell-Dm_nY4jF.js";var u=n(),d=e(t(),1),f=r();function p(){let[e,t]=(0,d.useState)(null),[n,r]=(0,d.useState)(!1),[u,p]=(0,d.useState)(void 0),[m,h]=(0,d.useState)(null),[g,_]=(0,d.useState)(void 0),[v,y]=(0,d.useState)(null),[b,x]=(0,d.useState)(null);(0,d.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!n){t(null),r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}if(i.ok)try{let e=await i.json();typeof e.businessName==`string`&&p(e.businessName),e.sessionId!==void 0&&h(e.sessionId??null),x(e.role??null),_(e.userName===void 0?null:e.userName),y(e.avatar??null)}catch{}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]);let S=(0,d.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]),[C,w]=(0,d.useState)(!1),T=(0,d.useCallback)(async()=>{w(!0);try{let e=await s();if(e){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`}return e}finally{w(!1)}},[]);return n?e?(0,f.jsx)(o,{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,f.jsx)(l,{cacheKey:e,businessName:u,sessionId:m,onLogout:S,onDisconnect:T,disconnecting:C,userName:g,userAvatar:v,role:b,children:(0,f.jsxs)(`div`,{className:`data-page`,children:[(0,f.jsx)(`header`,{className:`data-header`,children:(0,f.jsxs)(`h1`,{className:`data-title`,children:[(0,f.jsx)(i,{size:18}),` Browser`]})}),(0,f.jsx)(c,{})]})})}):(0,f.jsxs)(`div`,{className:`data-page`,children:[(0,f.jsx)(`header`,{className:`data-header`,children:(0,f.jsxs)(`h1`,{className:`data-title`,children:[(0,f.jsx)(i,{size:18}),` Browser`]})}),(0,f.jsxs)(`div`,{className:`data-empty`,children:[(0,f.jsx)(`p`,{children:`You are not signed in.`}),(0,f.jsxs)(`p`,{children:[`Open the `,(0,f.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})]}):(0,f.jsx)(`div`,{className:`data-page`,children:(0,f.jsxs)(`div`,{className:`data-loading`,children:[(0,f.jsx)(a,{size:18,className:`spin`}),` Loading…`]})})}(0,u.createRoot)(document.getElementById(`root`)).render((0,f.jsx)(p,{}));
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./chunk-BycB0eMI.js";import{i as t,n,t as r}from"./jsx-runtime-BCAZhYqz.js";import{C as i,D as a,E as o,H as s,I as c,J as l,K as u,L as d,N as f,O as p,P as m,T as h,V as g,X as _,k as v,lt as y,nt as b}from"./useMediaQuery-CLVRXJMp.js";import{A as x,C as S,t as C,x as w}from"./AdminShell-CrCdEMNW.js";import{t as T}from"./chevron-left-DV8gIVC9.js";import{t as E}from"./clock-PnR4Tlg9.js";import{t as D}from"./file-text-Cy-IjCf8.js";var ee=b(`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`}]]),O=b(`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`}]]),k=b(`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`}]]),A=b(`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`}]]),te=b(`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`}]]),j=n(),M=e(t(),1),N=1440*60*1e3;function P(e,t){let n=v(e,t);return p(n.y,n.m,n.d,t)}function F(e,t,n){let r=v(e,n),i=new Date(Date.UTC(r.y,r.m-1,r.d)+t*N);return p(i.getUTCFullYear(),i.getUTCMonth()+1,i.getUTCDate(),n)}function I(e,t){let n=P(e,t),r=v(n,t),i=new Date(Date.UTC(r.y,r.m-1,r.d)).getUTCDay();return F(n,i===0?-6:1-i,t)}function L(e,t,n){let r=v(t,n);switch(e){case`day`:{let e=P(t,n);return{from:e,to:F(e,1,n)}}case`week`:{let e=I(t,n);return{from:e,to:F(e,7,n)}}case`month`:return{from:p(r.y,r.m,1,n),to:r.m===12?p(r.y+1,1,1,n):p(r.y,r.m+1,1,n)};case`year`:return{from:p(r.y,1,1,n),to:p(r.y+1,1,1,n)}}}function R(e,t,n,r){let i=v(t,r);switch(e){case`day`:return F(t,n,r);case`week`:return F(t,n*7,r);case`month`:{let e=i.y*12+(i.m-1)+n;return p(Math.floor(e/12),e%12+1,1,r)}case`year`:return p(i.y+n,i.m,1,r)}}function z(e,t,n){return o(e,n)===o(t,n)}var ne=[`day`,`week`,`month`,`year`],B=`month`;function V(e,t){return e.toLocaleDateString([],{day:`numeric`,month:`short`,timeZone:t})}function H(e,t){return e.toLocaleDateString([],{day:`numeric`,month:`short`,year:`numeric`,timeZone:t})}function U(e,t,n){switch(e){case`day`:return t.toLocaleDateString([],{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`,timeZone:n});case`week`:{let{from:e,to:r}=L(`week`,t,n);return`${V(e,n)} – ${H(new Date(r.getTime()-1),n)}`}case`month`:return t.toLocaleDateString([],{month:`long`,year:`numeric`,timeZone:n});case`year`:return String(v(t,n).y)}}function W(e,t){return{role:`button`,tabIndex:0,onClick:()=>t(e),onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),t(e))}}}var G=r(),re={meeting:`Meeting`,event:`Event`,task:`Task`};function K(e){return re[e.kind??`meeting`]}function q(e,t){return e.toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`,timeZone:t})}function J(e,t){if(e.isAllDay)return`All day`;let n=q(new Date(e.startsAt),t);return e.endsAt?`${n} – ${q(new Date(e.endsAt),t)}`:n}function Y(e,t){if(!e)return``;let n=new Date(e);if(Number.isNaN(n.getTime()))return``;let r=v(n,t),i=e=>String(e).padStart(2,`0`);return`${r.y}-${i(r.m)}-${i(r.d)}T${i(r.hh)}:${i(r.mm)}`}function X(e,t){let n=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/.exec(e);if(!n)return``;let[,r,i,o,s,c]=n;return a(Number(r),Number(i),Number(o),Number(s),Number(c),t).toISOString()}function ie(e,t){let n=new Date(e.startsAt),r={weekday:`long`,day:`numeric`,month:`long`,year:`numeric`,timeZone:t};if(e.isAllDay)return n.toLocaleDateString([],r);let i=n.toLocaleDateString([],r),a=q(n,t);return e.endsAt?`${i} · ${a} – ${q(new Date(e.endsAt),t)}`:`${i} · ${a}`}function ae(e,t){return e.email??`${e.name??`unknown`}-${t}`}function oe(e){return e.map(e=>e.name||e.email||`Unknown`).join(`, `)}function se({a:e}){let t=e.name||e.email||`Unknown`,n=e.name&&e.email?e.email:null;return(0,G.jsxs)(`span`,{className:`cal-attendee-lines`,children:[(0,G.jsx)(`span`,{className:`cal-attendee-name`,children:t}),n&&(0,G.jsx)(`span`,{className:`cal-attendee-email`,children:n})]})}function ce(e){let t=[...e].sort((e,t)=>e.start.localeCompare(t.start)),n=[];for(let e of t){let t=n[n.length-1];t&&t.end===e.start?(t.end=e.end,t.slots+=1):n.push({start:e.start,end:e.end,slots:1})}return n}function le(e,t){let n=e.slots===1?`slot`:`slots`;return`free ${q(new Date(e.start),t)} – ${q(new Date(e.end),t)} · ${e.slots} ${n}`}function Z(e,t,n,r=[],i){let a=P(t,i),o=[];for(let t=0;t<n;t++){let n=F(a,t,i),s=e.filter(e=>z(new Date(e.startsAt),n,i)).sort((e,t)=>e.startsAt.localeCompare(t.startsAt)),c=r.some(e=>z(new Date(e.start),n,i));(s.length>0||c)&&o.push({day:n,meetings:s})}return o}function ue(e,t,n){return Math.round((P(t,n).getTime()-P(e,n).getTime())/864e5)}function de(e,t,n){let r=e.toLocaleDateString([],{weekday:`long`,day:`numeric`,month:`long`,timeZone:n});return z(e,t,n)?`${r} · today`:r}function fe({from:e,to:t,meetings:n,stretches:r,gapSource:i,showAllKinds:a,onToggleKinds:o,onSelect:s,onAddAt:c,zone:l,zoneSource:u}){let d=a?n:n.filter(e=>(e.kind??`meeting`)===`meeting`),f=n.length-d.length,p=new Date,m=Z(d,e,ue(e,t,l),r,l),g=(0,G.jsxs)(`div`,{className:`cal-list-controls`,children:[(0,G.jsx)(`button`,{type:`button`,className:`cal-kind-toggle${a?` cal-kind-toggle-on`:``}`,onClick:o,"aria-pressed":a,children:a?`Meetings only`:`Show reminders and tasks`}),f>0&&(0,G.jsxs)(`span`,{className:`cal-hidden-count`,children:[f,` hidden`]}),(0,G.jsxs)(`span`,{className:`cal-zone-label`,"data-zone":l,"data-zone-source":u,children:[`Times in `,h(l,p)]}),i===`none`&&(0,G.jsx)(`span`,{className:`cal-no-hours`,children:`Free time is not shown: working hours are not set.`})]});return m.length===0?(0,G.jsxs)(`div`,{className:`cal-schedule`,children:[g,(0,G.jsx)(`div`,{className:`cal-schedule-empty`,children:`No events in this period.`})]}):(0,G.jsxs)(`div`,{className:`cal-schedule`,children:[g,m.map(e=>{let t=r.filter(t=>z(new Date(t.start),e.day,l));return(0,G.jsxs)(`section`,{className:`cal-sched-group`,children:[(0,G.jsx)(`h3`,{className:`cal-sched-day${z(e.day,p,l)?` cal-sched-day-today`:``}`,children:de(e.day,p,l)}),e.meetings.map(e=>{let t=[e.location,oe(e.attendees)||null,K(e)].filter(Boolean);return(0,G.jsxs)(`div`,{className:`cal-sched-row`,"data-testid":`row-${e.meetingId}`,"data-meeting-id":e.meetingId,"data-kind":e.kind??`meeting`,...W(e,s),children:[(0,G.jsx)(`span`,{className:`cal-sched-time`,children:J(e,l)}),(0,G.jsxs)(`span`,{className:`cal-sched-detail`,children:[(0,G.jsx)(`span`,{className:`cal-sched-title`,children:e.title??`Untitled`}),(0,G.jsx)(`span`,{className:`cal-sched-meta`,children:t.join(` · `)})]})]},e.meetingId)}),t.map(e=>(0,G.jsx)(`button`,{type:`button`,className:`cal-gap`,"data-gap-start":e.start,onClick:()=>c(e.start,e.end),children:le(e,l)},e.start))]},e.day.toISOString())})]})}function pe({initialStart:e,initialEnd:t,zone:n,adminFetch:r,onClose:i,onCreated:a}){let[o,s]=(0,M.useState)(``),[l,d]=(0,M.useState)(e),[f,p]=(0,M.useState)(t),[m,h]=(0,M.useState)(``),[g,_]=(0,M.useState)(``),[v,y]=(0,M.useState)(``),[b,x]=(0,M.useState)(!1),[S,C]=(0,M.useState)(null),w=(0,M.useCallback)(async()=>{if(!o.trim()){C(`Title is required`);return}if(!l){C(`Start time is required`);return}x(!0),C(null);try{let e=await r(`/api/admin/calendar/meetings`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({title:o.trim(),startsAt:X(l,n),endsAt:f?X(f,n):null,location:m.trim()||null,description:g.trim()||null,privateNote:v.trim()||null})}),t=await e.json();if(!e.ok){C(t.error??`Create failed (HTTP ${e.status})`);return}t.meeting&&a(t.meeting)}catch(e){C(e instanceof Error?e.message:`Create failed`)}finally{x(!1)}},[o,l,f,m,g,v,n,r,a]);return(0,G.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{b||i()},children:(0,G.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":`Add meeting`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,G.jsx)(`span`,{className:`cal-modal-kind`,children:`New meeting`}),(0,G.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:i,"aria-label":`Close`,disabled:b,children:(0,G.jsx)(c,{size:16})})]}),(0,G.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,G.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,G.jsx)(`span`,{children:`Title`}),(0,G.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),disabled:b,autoFocus:!0})]}),(0,G.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,G.jsx)(`span`,{children:`Starts`}),(0,G.jsx)(`input`,{type:`datetime-local`,value:l,onChange:e=>d(e.target.value),disabled:b})]}),(0,G.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,G.jsx)(`span`,{children:`Ends`}),(0,G.jsx)(`input`,{type:`datetime-local`,value:f,onChange:e=>p(e.target.value),disabled:b})]}),(0,G.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,G.jsx)(`span`,{children:`Location`}),(0,G.jsx)(`input`,{type:`text`,value:m,onChange:e=>h(e.target.value),disabled:b})]}),(0,G.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,G.jsx)(`span`,{children:`Description`}),(0,G.jsx)(`textarea`,{value:g,onChange:e=>_(e.target.value),disabled:b,rows:3})]}),(0,G.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,G.jsx)(`span`,{children:`Private note`}),(0,G.jsx)(`textarea`,{value:v,onChange:e=>y(e.target.value),disabled:b,rows:2})]}),S&&(0,G.jsx)(`div`,{className:`cal-modal-error`,children:S})]}),(0,G.jsxs)(`div`,{className:`cal-modal-actions`,children:[(0,G.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:i,disabled:b,children:`Cancel`}),(0,G.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-primary`,onClick:w,disabled:b,children:[b?(0,G.jsx)(u,{size:14,className:`spin`}):null,` Create`]})]})]})})}var me=8;function he(e,t){return t?{op:`view-census`,range:e,nodes:t.nodes.length,clippedV:t.nodes.filter(e=>e.clippedV).length,clippedH:t.nodes.filter(e=>e.clippedH).length,hidden:t.hidden,fields:t.fields.length>0?t.fields.join(`,`):`-`,minBlockPx:t.minBlockPx??`-`,lineBoxPx:t.lineBoxPx??`-`,gapSource:t.gapSource??`-`,gaps:t.gaps??`-`,shownKinds:t.shownKinds??`-`,hiddenKinds:t.hiddenKinds??`-`,zone:t.zone??`-`,zoneSource:t.zoneSource??`-`,descrRows:t.descrRows??`-`,source:`measured`}:{op:`view-census`,range:e,nodes:`-`,clippedV:`-`,clippedH:`-`,hidden:`-`,fields:`-`,minBlockPx:`-`,lineBoxPx:`-`,gapSource:`-`,gaps:`-`,shownKinds:`-`,hiddenKinds:`-`,zone:`-`,zoneSource:`-`,descrRows:`-`,source:`unavailable`}}var ge=5;function _e(e,t){if(!t)return[];let n=[];for(let r of t.nodes)for(let t of[`v`,`h`])(t===`v`?r.clippedV:r.clippedH)&&n.push({op:`node-clipped`,view:e,meetingId:r.meetingId,axis:t,renderedPx:r.renderedPx,neededPx:r.neededPx,durationMin:r.durationMin??`-`});if(n.length<=ge)return n;let r=n.slice(0,ge);return r[r.length-1]={...r[r.length-1],truncated:n.length-ge},r}function ve(e){let t=(e.textContent??``).length;if(t===0||e.scrollWidth===0||e.clientWidth>=e.scrollWidth-1)return!0;let n=e.scrollWidth/t;return e.clientWidth/n>=me}function ye(e){if(!e||typeof window>`u`||typeof window.getComputedStyle!=`function`)return null;let t=Array.from(e.querySelectorAll(`[data-meeting-id]`)),n=t.map(e=>e.getBoundingClientRect());if(t.length>0&&n.every(e=>e.height===0&&e.width===0))return null;let r=t.length>0?parseFloat(window.getComputedStyle(t[0]).lineHeight):null,i=t.map((e,t)=>{let r=e.querySelector(`.cal-sched-title`),i=e.querySelector(`.cal-event-title`)??r??e,a=i.scrollWidth>i.clientWidth+1,o=e.getAttribute(`data-duration-min`);return{meetingId:e.getAttribute(`data-meeting-id`)??`unknown`,clippedV:e.scrollHeight>e.clientHeight+1,clippedH:r?a:a&&!ve(i),durationMin:o?Number(o):null,renderedPx:Math.round(n[t].height*10)/10,neededPx:Math.round(e.scrollHeight*10)/10}}),a=[];e.querySelector(`.cal-event-title, .cal-chip, .cal-sched-title`)&&a.push(`title`),e.querySelector(`.cal-event-time, .cal-sched-time`)&&a.push(`time`),e.querySelector(`.cal-sched-meta`)&&a.push(`meta`);let o=0;for(let t of Array.from(e.querySelectorAll(`.cal-more`)))o+=Number(t.getAttribute(`data-hidden-count`)??0);return{nodes:i,hidden:o,fields:a,minBlockPx:i.length>0?Math.min(...i.map(e=>e.renderedPx)):null,lineBoxPx:Number.isFinite(r)?r:null}}function be(e,t){return{op:`detail-open`,descrPayload:e?1:0,descrShown:t?1:0}}function xe(e){try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`event`,source:`calendar-legibility`,...e}),keepalive:!0}).catch(()=>{})}catch{}}function Se(e,t){for(let n of[he(e,t),..._e(e,t)])xe(n)}function Q(e){return Math.floor(new Date(e).getTime()/6e4)}function Ce(e){if(!e)return null;let t=e.match(/filename="([^"]+)"/);return t?t[1]:null}function we({meeting:e,zone:t,adminFetch:n,onClose:r,onSaved:i,onDeleted:a}){let o=e.kind===`meeting`,[f,p]=(0,M.useState)(!1),[m,h]=(0,M.useState)(!1),[g,v]=(0,M.useState)(!1),[y,b]=(0,M.useState)(!1),[x,S]=(0,M.useState)(null),[C,w]=(0,M.useState)(e),[T,j]=(0,M.useState)(e.title??``),[N,P]=(0,M.useState)(Y(e.startsAt,t)),[F,I]=(0,M.useState)(e.endsAt?Y(e.endsAt,t):``),[L,R]=(0,M.useState)(e.location??``),[z,ne]=(0,M.useState)(e.description??``),[B,V]=(0,M.useState)(e.privateNote??``),[H,U]=(0,M.useState)(``),[W,K]=(0,M.useState)(``);(0,M.useLayoutEffect)(()=>{xe(be((C.description??``).trim().length>0,document.querySelector(`[data-testid="cal-descr"]`)!==null))},[C.meetingId,C.description]),(0,M.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!y&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[y,r]);let q=(0,M.useCallback)(()=>{let e={},n=T.trim();n!==(C.title??``)&&(e.title=n);let r=X(N,t);Q(r)!==Q(C.startsAt)&&(e.startsAt=r);let i=F?X(F,t):null;(i===null?C.endsAt!==null:C.endsAt===null||Q(i)!==Q(C.endsAt))&&(e.endsAt=i);let a=L.trim()||null;a!==(C.location??null)&&(e.location=a);let o=z.trim()||null;o!==(C.description??null)&&(e.description=o);let s=B.trim()||null;return s!==(C.privateNote??null)&&(e.privateNote=s),e},[T,N,F,L,z,B,C,t]),J=(0,M.useCallback)(async()=>{let t=q();if(Object.keys(t).length===0){p(!1);return}b(!0),S(null);try{let r=await n(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(t)});if(!r.ok)throw Error(`HTTP ${r.status}`);let a=await r.json();w(a.meeting),i(a.meeting),p(!1)}catch(e){S(e instanceof Error?e.message:`Save failed`)}finally{b(!1)}},[n,q,e.meetingId,i]),oe=(0,M.useCallback)(async()=>{let t=H.trim(),r=W.trim();if(!(!t&&!r)){b(!0),S(null);try{let a=await n(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}/attendees`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:t||void 0,email:r||void 0})});if(!a.ok)throw Error(`HTTP ${a.status}`);let o=await a.json();w(o.meeting),i(o.meeting),U(``),K(``)}catch(e){S(e instanceof Error?e.message:`Add failed`)}finally{b(!1)}}},[n,H,W,e.meetingId,i]),ce=(0,M.useCallback)(async t=>{let r=t.email?{email:t.email}:{name:t.name};b(!0),S(null);try{let t=await n(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}/attendees`,{method:`DELETE`,headers:{"content-type":`application/json`},body:JSON.stringify(r)});if(!t.ok)throw Error(`HTTP ${t.status}`);let a=await t.json();w(a.meeting),i(a.meeting)}catch(e){S(e instanceof Error?e.message:`Remove failed`)}finally{b(!1)}},[n,e.meetingId,i]),le=(0,M.useCallback)(async()=>{b(!0),S(null);try{let t=await n(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}`,{method:`DELETE`});if(!t.ok)throw Error(`HTTP ${t.status}`);a(e.meetingId)}catch(e){S(e instanceof Error?e.message:`Delete failed`),b(!1)}},[n,e.meetingId,a]),Z=(0,M.useCallback)(async t=>{v(!1),b(!0),S(null);try{let r=await n(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}/ics?attendees=${t?`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){S(e instanceof Error?e.message:`Download failed`)}finally{b(!1)}},[n,e.meetingId]),ue=re[e.kind??`meeting`],de=H.trim().length>0||W.trim().length>0;return(0,G.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{y||r()},children:(0,G.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":f?`Edit meeting`:`Meeting detail`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,G.jsx)(`span`,{className:`cal-modal-kind`,children:ue}),(0,G.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:r,"aria-label":`Close`,autoFocus:!0,disabled:y,children:(0,G.jsx)(c,{size:16})})]}),!f&&(0,G.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,G.jsx)(`div`,{className:`cal-modal-title`,children:C.title??`Untitled`}),(0,G.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,G.jsx)(E,{size:14}),(0,G.jsx)(`span`,{children:ie(C,t)})]}),C.timezone&&C.timezone!==t&&(0,G.jsxs)(`div`,{className:`cal-modal-row cal-modal-zone`,"data-testid":`cal-row-zone`,children:[(0,G.jsx)(l,{size:14}),(0,G.jsxs)(`span`,{children:[`Created in `,C.timezone]})]}),C.description&&(0,G.jsxs)(`div`,{className:`cal-modal-row cal-modal-row-top`,"data-testid":`cal-descr`,children:[(0,G.jsx)(D,{size:14}),(0,G.jsx)(`span`,{className:`cal-modal-descr`,children:C.description})]}),C.location&&(0,G.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,G.jsx)(O,{size:14}),(0,G.jsx)(`span`,{children:C.location})]}),C.attendees.length>0&&(0,G.jsxs)(`div`,{className:`cal-modal-row cal-modal-row-top`,children:[(0,G.jsx)(te,{size:14}),(0,G.jsx)(`div`,{className:`cal-modal-attendees`,children:C.attendees.map((e,t)=>(0,G.jsx)(`div`,{className:`cal-attendee-row`,children:(0,G.jsx)(se,{a:e})},ae(e,t)))})]}),C.privateNote&&(0,G.jsxs)(`div`,{className:`cal-modal-row cal-modal-row-top`,children:[(0,G.jsx)(k,{size:14}),(0,G.jsx)(`span`,{className:`cal-modal-note`,children:C.privateNote})]}),(0,G.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,G.jsx)(ee,{size:14}),(0,G.jsx)(`span`,{children:ue})]})]}),f&&(0,G.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,G.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,G.jsx)(`span`,{children:`Title`}),(0,G.jsx)(`input`,{type:`text`,value:T,onChange:e=>j(e.target.value),disabled:y})]}),(0,G.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,G.jsx)(`span`,{children:`Start`}),(0,G.jsx)(`input`,{type:`datetime-local`,value:N,onChange:e=>P(e.target.value),disabled:y})]}),(0,G.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,G.jsx)(`span`,{children:`End`}),(0,G.jsx)(`input`,{type:`datetime-local`,value:F,onChange:e=>I(e.target.value),disabled:y})]}),(0,G.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,G.jsx)(`span`,{children:`Location`}),(0,G.jsx)(`input`,{type:`text`,value:L,onChange:e=>R(e.target.value),disabled:y})]}),(0,G.jsxs)(`div`,{className:`cal-modal-field`,children:[(0,G.jsx)(`span`,{children:`Attendees`}),(0,G.jsxs)(`div`,{className:`cal-modal-attendees cal-modal-attendees-edit`,children:[C.attendees.length===0&&(0,G.jsx)(`div`,{className:`cal-attendee-empty`,children:`No attendees yet.`}),C.attendees.map((e,t)=>(0,G.jsxs)(`div`,{className:`cal-attendee-row cal-attendee-row-edit`,children:[(0,G.jsx)(se,{a:e}),(0,G.jsx)(`button`,{type:`button`,className:`cal-attendee-remove`,onClick:()=>ce(e),disabled:y,"aria-label":`Remove ${e.name||e.email||`attendee`}`,children:(0,G.jsx)(c,{size:13})})]},ae(e,t)))]}),(0,G.jsxs)(`div`,{className:`cal-attendee-add`,children:[(0,G.jsx)(`input`,{type:`text`,placeholder:`Name`,value:H,onChange:e=>U(e.target.value),disabled:y,"aria-label":`Attendee name`}),(0,G.jsx)(`input`,{type:`email`,placeholder:`Email`,value:W,onChange:e=>K(e.target.value),disabled:y,"aria-label":`Attendee email`}),(0,G.jsx)(`button`,{type:`button`,className:`cal-modal-btn cal-attendee-add-btn`,onClick:oe,disabled:y||!de,"aria-label":`Add attendee`,children:y?(0,G.jsx)(u,{size:13,className:`spin`}):(0,G.jsx)(A,{size:13})})]})]}),(0,G.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,G.jsx)(`span`,{children:`Description`}),(0,G.jsx)(`textarea`,{className:`cal-modal-textarea`,value:z,onChange:e=>ne(e.target.value),disabled:y,rows:3,placeholder:`The booking detail: who, what, how much.`})]}),(0,G.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,G.jsx)(`span`,{children:`Private note`}),(0,G.jsx)(`textarea`,{className:`cal-modal-textarea`,value:B,onChange:e=>V(e.target.value),disabled:y,rows:3,placeholder:`Only you and your team can see this.`})]})]}),x&&(0,G.jsx)(`div`,{className:`cal-modal-error`,children:x}),o&&(0,G.jsxs)(`div`,{className:`cal-modal-actions`,children:[!f&&!m&&!g&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>p(!0),disabled:y,children:[(0,G.jsx)(s,{size:14}),` Edit`]}),(0,G.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:()=>h(!0),disabled:y,children:[(0,G.jsx)(d,{size:14}),` Delete`]}),(0,G.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-download`,onClick:()=>{C.attendees.length>0?v(!0):Z(!1)},disabled:y,children:[y?(0,G.jsx)(u,{size:14,className:`spin`}):(0,G.jsx)(_,{size:14}),` Download`]})]}),g&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Include attendees in the file?`}),(0,G.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-primary`,onClick:()=>Z(!0),disabled:y,children:[y?(0,G.jsx)(u,{size:14,className:`spin`}):null,` Yes`]}),(0,G.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>Z(!1),disabled:y,children:`No`}),(0,G.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>v(!1),disabled:y,children:`Cancel`})]}),f&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-primary`,onClick:J,disabled:y,children:[y?(0,G.jsx)(u,{size:14,className:`spin`}):null,` Save`]}),(0,G.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>{p(!1),S(null)},disabled:y,children:`Cancel`})]}),m&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Delete this meeting?`}),(0,G.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:le,disabled:y,children:[y?(0,G.jsx)(u,{size:14,className:`spin`}):null,` Delete`]}),(0,G.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>h(!1),disabled:y,children:`Cancel`})]})]})]})})}var $=`maxy-admin-session-key`,Te=`maxy-calendar-show-all-kinds`;function Ee(){let[e,t]=(0,M.useState)(null),[n,r]=(0,M.useState)(!1),[i,a]=(0,M.useState)(void 0),[o,s]=(0,M.useState)(null),[c,l]=(0,M.useState)(void 0),[u,d]=(0,M.useState)(null),[p,h]=(0,M.useState)(null);(0,M.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem($)}catch{}if(!n){r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem($)}catch{}window.location.href=`/`;return}if(i.ok)try{let e=await i.json();typeof e.businessName==`string`&&a(e.businessName),e.sessionId!==void 0&&s(e.sessionId??null),h(e.role??null),l(e.userName===void 0?null:e.userName),d(e.avatar??null)}catch{}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]);let g=(0,M.useCallback)(()=>{try{sessionStorage.removeItem($)}catch{}window.location.href=`/`},[]),[_,v]=(0,M.useState)(!1),y=(0,M.useCallback)(async()=>{v(!0);try{let e=await x();if(e){try{sessionStorage.removeItem($)}catch{}window.location.href=`/`}return e}finally{v(!1)}},[]);return n?e?(0,G.jsx)(m,{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,G.jsx)(C,{cacheKey:e,businessName:i,sessionId:o,onLogout:g,onDisconnect:y,disconnecting:_,userName:c,userAvatar:u,role:p,children:(0,G.jsx)(De,{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)(f,{surface:`gate`})}function De({cacheKey:e}){let{zone:t,source:n}=i(),{adminFetch:r,sessionRefetchNonce:a}=y({initialCacheKey:e,surface:`calendar`}),[o,s]=(0,M.useState)(B),[c,l]=(0,M.useState)(()=>new Date),[d,p]=(0,M.useState)([]),[m,h]=(0,M.useState)(!1),[_,v]=(0,M.useState)(!1),[b,x]=(0,M.useState)(null),[C,E]=(0,M.useState)(null),[D,ee]=(0,M.useState)([]),[O,k]=(0,M.useState)(`none`),[A,te]=(0,M.useState)(()=>{try{return sessionStorage.getItem(Te)===`1`}catch{return!1}}),[j,N]=(0,M.useState)(null),[P,F]=(0,M.useState)(0),[I,z]=(0,M.useState)(null);(0,M.useEffect)(()=>{let e=!1;return r(`/api/admin/calendar/booking-link`).then(async t=>{if(e||!t.ok)return;let n=await t.json();typeof n.bookingDomain==`string`&&n.bookingDomain&&z(n.bookingDomain)}).catch(()=>{}),()=>{e=!0}},[r]),(0,M.useEffect)(()=>{let e=!1,{from:n,to:i}=L(o,c,t);return h(!0),x(null),r(`/api/admin/calendar/meetings?from=${encodeURIComponent(n.toISOString())}&to=${encodeURIComponent(i.toISOString())}`).then(async t=>{if(e)return;if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();p(Array.isArray(n.meetings)?n.meetings:[])}).catch(t=>{e||(x(t instanceof Error?t.message:`Failed to load`),p([]))}).finally(()=>{e||(h(!1),v(!0))}),()=>{e=!0}},[o,c,t,a,r]),(0,M.useEffect)(()=>{let e=!1,{from:n,to:i}=L(o,c,t);return r(`/api/admin/calendar/free-busy?from=${encodeURIComponent(n.toISOString())}&to=${encodeURIComponent(i.toISOString())}`).then(async t=>{if(e)return;if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();ee(ce(Array.isArray(n.slots)?n.slots:[])),k(n.gapSource===`config`?`config`:`none`)}).catch(()=>{e||(ee([]),k(`none`))}),()=>{e=!0}},[o,c,t,a,r,P]);let V=(0,M.useCallback)(()=>l(new Date),[]),H=(0,M.useCallback)(()=>l(e=>R(o,e,-1,t)),[o,t]),W=(0,M.useCallback)(()=>l(e=>R(o,e,1,t)),[o,t]),re=(0,M.useCallback)(()=>{te(e=>{let t=!e;try{sessionStorage.setItem(Te,t?`1`:`0`)}catch{}return t})},[]),K=(0,M.useCallback)((e,n)=>N({startsAt:Y(e,t),endsAt:Y(n,t)}),[t]),q=(0,M.useCallback)(e=>{p(t=>[...t,e]),F(e=>e+1),N(null)},[]);(0,M.useEffect)(()=>{E(null)},[o,c]);let J=(0,M.useRef)(null);(0,M.useEffect)(()=>{if(m)return;let e=requestAnimationFrame(()=>{let e=ye(J.current);Se(o,e&&{...e,zone:t,zoneSource:n,descrRows:d.filter(e=>(e.description??``).trim().length>0).length,gapSource:O,gaps:D.length,shownKinds:A?`meeting,event,task`:`meeting`,hiddenKinds:A?0:d.filter(e=>(e.kind??`meeting`)!==`meeting`).length})});return()=>cancelAnimationFrame(e)},[o,d,m,O,D,A,t,n]);let X=(0,M.useCallback)(e=>{p(t=>t.map(t=>t.meetingId===e.meetingId?e:t)),E(e)},[]),ie=(0,M.useCallback)(e=>{p(t=>t.filter(t=>t.meetingId!==e)),E(null)},[]);return _?(0,G.jsxs)(`div`,{className:`cal-page`,children:[(0,G.jsxs)(`header`,{className:`cal-header`,children:[(0,G.jsxs)(`div`,{className:`cal-nav`,children:[(0,G.jsx)(`button`,{type:`button`,className:`cal-nav-btn`,onClick:H,"aria-label":`Previous`,children:(0,G.jsx)(T,{size:18})}),(0,G.jsx)(`button`,{type:`button`,className:`cal-nav-btn`,onClick:W,"aria-label":`Next`,children:(0,G.jsx)(S,{size:18})}),(0,G.jsx)(`button`,{type:`button`,className:`cal-today-btn`,onClick:V,children:`Today`}),(0,G.jsxs)(`button`,{type:`button`,className:`cal-add-btn`,onClick:()=>N({startsAt:``,endsAt:``}),children:[(0,G.jsx)(g,{size:14}),` Add`]}),(0,G.jsx)(`span`,{className:`cal-range-label cal-range-label-trailing`,children:U(o,c,t)}),m&&(0,G.jsx)(u,{size:16,className:`spin`})]}),(0,G.jsx)(`div`,{className:`cal-views`,children:ne.map(e=>(0,G.jsx)(`button`,{type:`button`,className:`cal-view-btn${e===o?` cal-view-btn-active`:``}`,onClick:()=>s(e),children:e.charAt(0).toUpperCase()+e.slice(1)},e))}),I&&(0,G.jsxs)(`a`,{className:`cal-booking-link`,href:`https://${I}`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,G.jsx)(w,{size:14}),` Booking page`]})]}),(0,G.jsxs)(`div`,{className:`cal-body`,ref:J,children:[b&&(0,G.jsxs)(`div`,{className:`cal-error`,children:[`Could not load the calendar: `,b]}),(0,G.jsx)(fe,{zone:t,zoneSource:n,from:L(o,c,t).from,to:L(o,c,t).to,meetings:d,stretches:D,gapSource:O,showAllKinds:A,onToggleKinds:re,onSelect:E,onAddAt:K})]}),j&&(0,G.jsx)(pe,{zone:t,initialStart:j.startsAt,initialEnd:j.endsAt,adminFetch:r,onClose:()=>N(null),onCreated:q}),C&&(0,G.jsx)(we,{zone:t,meeting:C,adminFetch:r,onClose:()=>E(null),onSaved:X,onDeleted:ie})]}):(0,G.jsx)(f,{surface:`gate`})}(0,j.createRoot)(document.getElementById(`root`)).render((0,G.jsx)(Ee,{}));
|
|
1
|
+
import{o as e}from"./chunk-BycB0eMI.js";import{i as t,n,t as r}from"./jsx-runtime-BY35JYDT.js";import{C as i,D as a,E as o,H as s,I as c,J as l,K as u,L as d,N as f,O as p,P as m,T as h,V as g,X as _,k as v,rt as y,ut as b}from"./useMediaQuery-e4ciNiuO.js";import{C as x,k as S,t as C,x as w}from"./AdminShell-Dm_nY4jF.js";import{t as T}from"./chevron-left-D3_hiHLC.js";import{t as E}from"./clock-kLje910u.js";import{t as D}from"./file-text-CVZAL3Er.js";var ee=y(`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`}]]),O=y(`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`}]]),k=y(`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`}]]),A=y(`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`}]]),te=y(`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`}]]),j=n(),M=e(t(),1),N=1440*60*1e3;function P(e,t){let n=v(e,t);return p(n.y,n.m,n.d,t)}function F(e,t,n){let r=v(e,n),i=new Date(Date.UTC(r.y,r.m-1,r.d)+t*N);return p(i.getUTCFullYear(),i.getUTCMonth()+1,i.getUTCDate(),n)}function I(e,t){let n=P(e,t),r=v(n,t),i=new Date(Date.UTC(r.y,r.m-1,r.d)).getUTCDay();return F(n,i===0?-6:1-i,t)}function L(e,t,n){let r=v(t,n);switch(e){case`day`:{let e=P(t,n);return{from:e,to:F(e,1,n)}}case`week`:{let e=I(t,n);return{from:e,to:F(e,7,n)}}case`month`:return{from:p(r.y,r.m,1,n),to:r.m===12?p(r.y+1,1,1,n):p(r.y,r.m+1,1,n)};case`year`:return{from:p(r.y,1,1,n),to:p(r.y+1,1,1,n)}}}function R(e,t,n,r){let i=v(t,r);switch(e){case`day`:return F(t,n,r);case`week`:return F(t,n*7,r);case`month`:{let e=i.y*12+(i.m-1)+n;return p(Math.floor(e/12),e%12+1,1,r)}case`year`:return p(i.y+n,i.m,1,r)}}function z(e,t,n){return o(e,n)===o(t,n)}var ne=[`day`,`week`,`month`,`year`],B=`month`;function V(e,t){return e.toLocaleDateString([],{day:`numeric`,month:`short`,timeZone:t})}function H(e,t){return e.toLocaleDateString([],{day:`numeric`,month:`short`,year:`numeric`,timeZone:t})}function U(e,t,n){switch(e){case`day`:return t.toLocaleDateString([],{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`,timeZone:n});case`week`:{let{from:e,to:r}=L(`week`,t,n);return`${V(e,n)} – ${H(new Date(r.getTime()-1),n)}`}case`month`:return t.toLocaleDateString([],{month:`long`,year:`numeric`,timeZone:n});case`year`:return String(v(t,n).y)}}function W(e,t){return{role:`button`,tabIndex:0,onClick:()=>t(e),onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),t(e))}}}var G=r(),re={meeting:`Meeting`,event:`Event`,task:`Task`};function K(e){return re[e.kind??`meeting`]}function q(e,t){return e.toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`,timeZone:t})}function J(e,t){if(e.isAllDay)return`All day`;let n=q(new Date(e.startsAt),t);return e.endsAt?`${n} – ${q(new Date(e.endsAt),t)}`:n}function Y(e,t){if(!e)return``;let n=new Date(e);if(Number.isNaN(n.getTime()))return``;let r=v(n,t),i=e=>String(e).padStart(2,`0`);return`${r.y}-${i(r.m)}-${i(r.d)}T${i(r.hh)}:${i(r.mm)}`}function X(e,t){let n=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/.exec(e);if(!n)return``;let[,r,i,o,s,c]=n;return a(Number(r),Number(i),Number(o),Number(s),Number(c),t).toISOString()}function ie(e,t){let n=new Date(e.startsAt),r={weekday:`long`,day:`numeric`,month:`long`,year:`numeric`,timeZone:t};if(e.isAllDay)return n.toLocaleDateString([],r);let i=n.toLocaleDateString([],r),a=q(n,t);return e.endsAt?`${i} · ${a} – ${q(new Date(e.endsAt),t)}`:`${i} · ${a}`}function ae(e,t){return e.email??`${e.name??`unknown`}-${t}`}function oe(e){return e.map(e=>e.name||e.email||`Unknown`).join(`, `)}function se({a:e}){let t=e.name||e.email||`Unknown`,n=e.name&&e.email?e.email:null;return(0,G.jsxs)(`span`,{className:`cal-attendee-lines`,children:[(0,G.jsx)(`span`,{className:`cal-attendee-name`,children:t}),n&&(0,G.jsx)(`span`,{className:`cal-attendee-email`,children:n})]})}function ce(e){let t=[...e].sort((e,t)=>e.start.localeCompare(t.start)),n=[];for(let e of t){let t=n[n.length-1];t&&t.end===e.start?(t.end=e.end,t.slots+=1):n.push({start:e.start,end:e.end,slots:1})}return n}function le(e,t){let n=e.slots===1?`slot`:`slots`;return`free ${q(new Date(e.start),t)} – ${q(new Date(e.end),t)} · ${e.slots} ${n}`}function Z(e,t,n,r=[],i){let a=P(t,i),o=[];for(let t=0;t<n;t++){let n=F(a,t,i),s=e.filter(e=>z(new Date(e.startsAt),n,i)).sort((e,t)=>e.startsAt.localeCompare(t.startsAt)),c=r.some(e=>z(new Date(e.start),n,i));(s.length>0||c)&&o.push({day:n,meetings:s})}return o}function ue(e,t,n){return Math.round((P(t,n).getTime()-P(e,n).getTime())/864e5)}function de(e,t,n){let r=e.toLocaleDateString([],{weekday:`long`,day:`numeric`,month:`long`,timeZone:n});return z(e,t,n)?`${r} · today`:r}function fe({from:e,to:t,meetings:n,stretches:r,gapSource:i,showAllKinds:a,onToggleKinds:o,onSelect:s,onAddAt:c,zone:l,zoneSource:u}){let d=a?n:n.filter(e=>(e.kind??`meeting`)===`meeting`),f=n.length-d.length,p=new Date,m=Z(d,e,ue(e,t,l),r,l),g=(0,G.jsxs)(`div`,{className:`cal-list-controls`,children:[(0,G.jsx)(`button`,{type:`button`,className:`cal-kind-toggle${a?` cal-kind-toggle-on`:``}`,onClick:o,"aria-pressed":a,children:a?`Meetings only`:`Show reminders and tasks`}),f>0&&(0,G.jsxs)(`span`,{className:`cal-hidden-count`,children:[f,` hidden`]}),(0,G.jsxs)(`span`,{className:`cal-zone-label`,"data-zone":l,"data-zone-source":u,children:[`Times in `,h(l,p)]}),i===`none`&&(0,G.jsx)(`span`,{className:`cal-no-hours`,children:`Free time is not shown: working hours are not set.`})]});return m.length===0?(0,G.jsxs)(`div`,{className:`cal-schedule`,children:[g,(0,G.jsx)(`div`,{className:`cal-schedule-empty`,children:`No events in this period.`})]}):(0,G.jsxs)(`div`,{className:`cal-schedule`,children:[g,m.map(e=>{let t=r.filter(t=>z(new Date(t.start),e.day,l));return(0,G.jsxs)(`section`,{className:`cal-sched-group`,children:[(0,G.jsx)(`h3`,{className:`cal-sched-day${z(e.day,p,l)?` cal-sched-day-today`:``}`,children:de(e.day,p,l)}),e.meetings.map(e=>{let t=[e.location,oe(e.attendees)||null,K(e)].filter(Boolean);return(0,G.jsxs)(`div`,{className:`cal-sched-row`,"data-testid":`row-${e.meetingId}`,"data-meeting-id":e.meetingId,"data-kind":e.kind??`meeting`,...W(e,s),children:[(0,G.jsx)(`span`,{className:`cal-sched-time`,children:J(e,l)}),(0,G.jsxs)(`span`,{className:`cal-sched-detail`,children:[(0,G.jsx)(`span`,{className:`cal-sched-title`,children:e.title??`Untitled`}),(0,G.jsx)(`span`,{className:`cal-sched-meta`,children:t.join(` · `)})]})]},e.meetingId)}),t.map(e=>(0,G.jsx)(`button`,{type:`button`,className:`cal-gap`,"data-gap-start":e.start,onClick:()=>c(e.start,e.end),children:le(e,l)},e.start))]},e.day.toISOString())})]})}function pe({initialStart:e,initialEnd:t,zone:n,adminFetch:r,onClose:i,onCreated:a}){let[o,s]=(0,M.useState)(``),[l,d]=(0,M.useState)(e),[f,p]=(0,M.useState)(t),[m,h]=(0,M.useState)(``),[g,_]=(0,M.useState)(``),[v,y]=(0,M.useState)(``),[b,x]=(0,M.useState)(!1),[S,C]=(0,M.useState)(null),w=(0,M.useCallback)(async()=>{if(!o.trim()){C(`Title is required`);return}if(!l){C(`Start time is required`);return}x(!0),C(null);try{let e=await r(`/api/admin/calendar/meetings`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({title:o.trim(),startsAt:X(l,n),endsAt:f?X(f,n):null,location:m.trim()||null,description:g.trim()||null,privateNote:v.trim()||null})}),t=await e.json();if(!e.ok){C(t.error??`Create failed (HTTP ${e.status})`);return}t.meeting&&a(t.meeting)}catch(e){C(e instanceof Error?e.message:`Create failed`)}finally{x(!1)}},[o,l,f,m,g,v,n,r,a]);return(0,G.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{b||i()},children:(0,G.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":`Add meeting`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,G.jsx)(`span`,{className:`cal-modal-kind`,children:`New meeting`}),(0,G.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:i,"aria-label":`Close`,disabled:b,children:(0,G.jsx)(c,{size:16})})]}),(0,G.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,G.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,G.jsx)(`span`,{children:`Title`}),(0,G.jsx)(`input`,{type:`text`,value:o,onChange:e=>s(e.target.value),disabled:b,autoFocus:!0})]}),(0,G.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,G.jsx)(`span`,{children:`Starts`}),(0,G.jsx)(`input`,{type:`datetime-local`,value:l,onChange:e=>d(e.target.value),disabled:b})]}),(0,G.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,G.jsx)(`span`,{children:`Ends`}),(0,G.jsx)(`input`,{type:`datetime-local`,value:f,onChange:e=>p(e.target.value),disabled:b})]}),(0,G.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,G.jsx)(`span`,{children:`Location`}),(0,G.jsx)(`input`,{type:`text`,value:m,onChange:e=>h(e.target.value),disabled:b})]}),(0,G.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,G.jsx)(`span`,{children:`Description`}),(0,G.jsx)(`textarea`,{value:g,onChange:e=>_(e.target.value),disabled:b,rows:3})]}),(0,G.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,G.jsx)(`span`,{children:`Private note`}),(0,G.jsx)(`textarea`,{value:v,onChange:e=>y(e.target.value),disabled:b,rows:2})]}),S&&(0,G.jsx)(`div`,{className:`cal-modal-error`,children:S})]}),(0,G.jsxs)(`div`,{className:`cal-modal-actions`,children:[(0,G.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:i,disabled:b,children:`Cancel`}),(0,G.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-primary`,onClick:w,disabled:b,children:[b?(0,G.jsx)(u,{size:14,className:`spin`}):null,` Create`]})]})]})})}var me=8;function he(e,t){return t?{op:`view-census`,range:e,nodes:t.nodes.length,clippedV:t.nodes.filter(e=>e.clippedV).length,clippedH:t.nodes.filter(e=>e.clippedH).length,hidden:t.hidden,fields:t.fields.length>0?t.fields.join(`,`):`-`,minBlockPx:t.minBlockPx??`-`,lineBoxPx:t.lineBoxPx??`-`,gapSource:t.gapSource??`-`,gaps:t.gaps??`-`,shownKinds:t.shownKinds??`-`,hiddenKinds:t.hiddenKinds??`-`,zone:t.zone??`-`,zoneSource:t.zoneSource??`-`,descrRows:t.descrRows??`-`,source:`measured`}:{op:`view-census`,range:e,nodes:`-`,clippedV:`-`,clippedH:`-`,hidden:`-`,fields:`-`,minBlockPx:`-`,lineBoxPx:`-`,gapSource:`-`,gaps:`-`,shownKinds:`-`,hiddenKinds:`-`,zone:`-`,zoneSource:`-`,descrRows:`-`,source:`unavailable`}}var ge=5;function _e(e,t){if(!t)return[];let n=[];for(let r of t.nodes)for(let t of[`v`,`h`])(t===`v`?r.clippedV:r.clippedH)&&n.push({op:`node-clipped`,view:e,meetingId:r.meetingId,axis:t,renderedPx:r.renderedPx,neededPx:r.neededPx,durationMin:r.durationMin??`-`});if(n.length<=ge)return n;let r=n.slice(0,ge);return r[r.length-1]={...r[r.length-1],truncated:n.length-ge},r}function ve(e){let t=(e.textContent??``).length;if(t===0||e.scrollWidth===0||e.clientWidth>=e.scrollWidth-1)return!0;let n=e.scrollWidth/t;return e.clientWidth/n>=me}function ye(e){if(!e||typeof window>`u`||typeof window.getComputedStyle!=`function`)return null;let t=Array.from(e.querySelectorAll(`[data-meeting-id]`)),n=t.map(e=>e.getBoundingClientRect());if(t.length>0&&n.every(e=>e.height===0&&e.width===0))return null;let r=t.length>0?parseFloat(window.getComputedStyle(t[0]).lineHeight):null,i=t.map((e,t)=>{let r=e.querySelector(`.cal-sched-title`),i=e.querySelector(`.cal-event-title`)??r??e,a=i.scrollWidth>i.clientWidth+1,o=e.getAttribute(`data-duration-min`);return{meetingId:e.getAttribute(`data-meeting-id`)??`unknown`,clippedV:e.scrollHeight>e.clientHeight+1,clippedH:r?a:a&&!ve(i),durationMin:o?Number(o):null,renderedPx:Math.round(n[t].height*10)/10,neededPx:Math.round(e.scrollHeight*10)/10}}),a=[];e.querySelector(`.cal-event-title, .cal-chip, .cal-sched-title`)&&a.push(`title`),e.querySelector(`.cal-event-time, .cal-sched-time`)&&a.push(`time`),e.querySelector(`.cal-sched-meta`)&&a.push(`meta`);let o=0;for(let t of Array.from(e.querySelectorAll(`.cal-more`)))o+=Number(t.getAttribute(`data-hidden-count`)??0);return{nodes:i,hidden:o,fields:a,minBlockPx:i.length>0?Math.min(...i.map(e=>e.renderedPx)):null,lineBoxPx:Number.isFinite(r)?r:null}}function be(e,t){return{op:`detail-open`,descrPayload:e?1:0,descrShown:t?1:0}}function xe(e){try{fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`event`,source:`calendar-legibility`,...e}),keepalive:!0}).catch(()=>{})}catch{}}function Se(e,t){for(let n of[he(e,t),..._e(e,t)])xe(n)}function Q(e){return Math.floor(new Date(e).getTime()/6e4)}function Ce(e){if(!e)return null;let t=e.match(/filename="([^"]+)"/);return t?t[1]:null}function we({meeting:e,zone:t,adminFetch:n,onClose:r,onSaved:i,onDeleted:a}){let o=e.kind===`meeting`,[f,p]=(0,M.useState)(!1),[m,h]=(0,M.useState)(!1),[g,v]=(0,M.useState)(!1),[y,b]=(0,M.useState)(!1),[x,S]=(0,M.useState)(null),[C,w]=(0,M.useState)(e),[T,j]=(0,M.useState)(e.title??``),[N,P]=(0,M.useState)(Y(e.startsAt,t)),[F,I]=(0,M.useState)(e.endsAt?Y(e.endsAt,t):``),[L,R]=(0,M.useState)(e.location??``),[z,ne]=(0,M.useState)(e.description??``),[B,V]=(0,M.useState)(e.privateNote??``),[H,U]=(0,M.useState)(``),[W,K]=(0,M.useState)(``);(0,M.useLayoutEffect)(()=>{xe(be((C.description??``).trim().length>0,document.querySelector(`[data-testid="cal-descr"]`)!==null))},[C.meetingId,C.description]),(0,M.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!y&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[y,r]);let q=(0,M.useCallback)(()=>{let e={},n=T.trim();n!==(C.title??``)&&(e.title=n);let r=X(N,t);Q(r)!==Q(C.startsAt)&&(e.startsAt=r);let i=F?X(F,t):null;(i===null?C.endsAt!==null:C.endsAt===null||Q(i)!==Q(C.endsAt))&&(e.endsAt=i);let a=L.trim()||null;a!==(C.location??null)&&(e.location=a);let o=z.trim()||null;o!==(C.description??null)&&(e.description=o);let s=B.trim()||null;return s!==(C.privateNote??null)&&(e.privateNote=s),e},[T,N,F,L,z,B,C,t]),J=(0,M.useCallback)(async()=>{let t=q();if(Object.keys(t).length===0){p(!1);return}b(!0),S(null);try{let r=await n(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(t)});if(!r.ok)throw Error(`HTTP ${r.status}`);let a=await r.json();w(a.meeting),i(a.meeting),p(!1)}catch(e){S(e instanceof Error?e.message:`Save failed`)}finally{b(!1)}},[n,q,e.meetingId,i]),oe=(0,M.useCallback)(async()=>{let t=H.trim(),r=W.trim();if(!(!t&&!r)){b(!0),S(null);try{let a=await n(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}/attendees`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:t||void 0,email:r||void 0})});if(!a.ok)throw Error(`HTTP ${a.status}`);let o=await a.json();w(o.meeting),i(o.meeting),U(``),K(``)}catch(e){S(e instanceof Error?e.message:`Add failed`)}finally{b(!1)}}},[n,H,W,e.meetingId,i]),ce=(0,M.useCallback)(async t=>{let r=t.email?{email:t.email}:{name:t.name};b(!0),S(null);try{let t=await n(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}/attendees`,{method:`DELETE`,headers:{"content-type":`application/json`},body:JSON.stringify(r)});if(!t.ok)throw Error(`HTTP ${t.status}`);let a=await t.json();w(a.meeting),i(a.meeting)}catch(e){S(e instanceof Error?e.message:`Remove failed`)}finally{b(!1)}},[n,e.meetingId,i]),le=(0,M.useCallback)(async()=>{b(!0),S(null);try{let t=await n(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}`,{method:`DELETE`});if(!t.ok)throw Error(`HTTP ${t.status}`);a(e.meetingId)}catch(e){S(e instanceof Error?e.message:`Delete failed`),b(!1)}},[n,e.meetingId,a]),Z=(0,M.useCallback)(async t=>{v(!1),b(!0),S(null);try{let r=await n(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}/ics?attendees=${t?`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){S(e instanceof Error?e.message:`Download failed`)}finally{b(!1)}},[n,e.meetingId]),ue=re[e.kind??`meeting`],de=H.trim().length>0||W.trim().length>0;return(0,G.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{y||r()},children:(0,G.jsxs)(`div`,{className:`cal-modal cal-modal-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":f?`Edit meeting`:`Meeting detail`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,G.jsx)(`span`,{className:`cal-modal-kind`,children:ue}),(0,G.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:r,"aria-label":`Close`,autoFocus:!0,disabled:y,children:(0,G.jsx)(c,{size:16})})]}),!f&&(0,G.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,G.jsx)(`div`,{className:`cal-modal-title`,children:C.title??`Untitled`}),(0,G.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,G.jsx)(E,{size:14}),(0,G.jsx)(`span`,{children:ie(C,t)})]}),C.timezone&&C.timezone!==t&&(0,G.jsxs)(`div`,{className:`cal-modal-row cal-modal-zone`,"data-testid":`cal-row-zone`,children:[(0,G.jsx)(l,{size:14}),(0,G.jsxs)(`span`,{children:[`Created in `,C.timezone]})]}),C.description&&(0,G.jsxs)(`div`,{className:`cal-modal-row cal-modal-row-top`,"data-testid":`cal-descr`,children:[(0,G.jsx)(D,{size:14}),(0,G.jsx)(`span`,{className:`cal-modal-descr`,children:C.description})]}),C.location&&(0,G.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,G.jsx)(O,{size:14}),(0,G.jsx)(`span`,{children:C.location})]}),C.attendees.length>0&&(0,G.jsxs)(`div`,{className:`cal-modal-row cal-modal-row-top`,children:[(0,G.jsx)(te,{size:14}),(0,G.jsx)(`div`,{className:`cal-modal-attendees`,children:C.attendees.map((e,t)=>(0,G.jsx)(`div`,{className:`cal-attendee-row`,children:(0,G.jsx)(se,{a:e})},ae(e,t)))})]}),C.privateNote&&(0,G.jsxs)(`div`,{className:`cal-modal-row cal-modal-row-top`,children:[(0,G.jsx)(k,{size:14}),(0,G.jsx)(`span`,{className:`cal-modal-note`,children:C.privateNote})]}),(0,G.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,G.jsx)(ee,{size:14}),(0,G.jsx)(`span`,{children:ue})]})]}),f&&(0,G.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,G.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,G.jsx)(`span`,{children:`Title`}),(0,G.jsx)(`input`,{type:`text`,value:T,onChange:e=>j(e.target.value),disabled:y})]}),(0,G.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,G.jsx)(`span`,{children:`Start`}),(0,G.jsx)(`input`,{type:`datetime-local`,value:N,onChange:e=>P(e.target.value),disabled:y})]}),(0,G.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,G.jsx)(`span`,{children:`End`}),(0,G.jsx)(`input`,{type:`datetime-local`,value:F,onChange:e=>I(e.target.value),disabled:y})]}),(0,G.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,G.jsx)(`span`,{children:`Location`}),(0,G.jsx)(`input`,{type:`text`,value:L,onChange:e=>R(e.target.value),disabled:y})]}),(0,G.jsxs)(`div`,{className:`cal-modal-field`,children:[(0,G.jsx)(`span`,{children:`Attendees`}),(0,G.jsxs)(`div`,{className:`cal-modal-attendees cal-modal-attendees-edit`,children:[C.attendees.length===0&&(0,G.jsx)(`div`,{className:`cal-attendee-empty`,children:`No attendees yet.`}),C.attendees.map((e,t)=>(0,G.jsxs)(`div`,{className:`cal-attendee-row cal-attendee-row-edit`,children:[(0,G.jsx)(se,{a:e}),(0,G.jsx)(`button`,{type:`button`,className:`cal-attendee-remove`,onClick:()=>ce(e),disabled:y,"aria-label":`Remove ${e.name||e.email||`attendee`}`,children:(0,G.jsx)(c,{size:13})})]},ae(e,t)))]}),(0,G.jsxs)(`div`,{className:`cal-attendee-add`,children:[(0,G.jsx)(`input`,{type:`text`,placeholder:`Name`,value:H,onChange:e=>U(e.target.value),disabled:y,"aria-label":`Attendee name`}),(0,G.jsx)(`input`,{type:`email`,placeholder:`Email`,value:W,onChange:e=>K(e.target.value),disabled:y,"aria-label":`Attendee email`}),(0,G.jsx)(`button`,{type:`button`,className:`cal-modal-btn cal-attendee-add-btn`,onClick:oe,disabled:y||!de,"aria-label":`Add attendee`,children:y?(0,G.jsx)(u,{size:13,className:`spin`}):(0,G.jsx)(A,{size:13})})]})]}),(0,G.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,G.jsx)(`span`,{children:`Description`}),(0,G.jsx)(`textarea`,{className:`cal-modal-textarea`,value:z,onChange:e=>ne(e.target.value),disabled:y,rows:3,placeholder:`The booking detail: who, what, how much.`})]}),(0,G.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,G.jsx)(`span`,{children:`Private note`}),(0,G.jsx)(`textarea`,{className:`cal-modal-textarea`,value:B,onChange:e=>V(e.target.value),disabled:y,rows:3,placeholder:`Only you and your team can see this.`})]})]}),x&&(0,G.jsx)(`div`,{className:`cal-modal-error`,children:x}),o&&(0,G.jsxs)(`div`,{className:`cal-modal-actions`,children:[!f&&!m&&!g&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>p(!0),disabled:y,children:[(0,G.jsx)(s,{size:14}),` Edit`]}),(0,G.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:()=>h(!0),disabled:y,children:[(0,G.jsx)(d,{size:14}),` Delete`]}),(0,G.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-download`,onClick:()=>{C.attendees.length>0?v(!0):Z(!1)},disabled:y,children:[y?(0,G.jsx)(u,{size:14,className:`spin`}):(0,G.jsx)(_,{size:14}),` Download`]})]}),g&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Include attendees in the file?`}),(0,G.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-primary`,onClick:()=>Z(!0),disabled:y,children:[y?(0,G.jsx)(u,{size:14,className:`spin`}):null,` Yes`]}),(0,G.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>Z(!1),disabled:y,children:`No`}),(0,G.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>v(!1),disabled:y,children:`Cancel`})]}),f&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-primary`,onClick:J,disabled:y,children:[y?(0,G.jsx)(u,{size:14,className:`spin`}):null,` Save`]}),(0,G.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>{p(!1),S(null)},disabled:y,children:`Cancel`})]}),m&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Delete this meeting?`}),(0,G.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:le,disabled:y,children:[y?(0,G.jsx)(u,{size:14,className:`spin`}):null,` Delete`]}),(0,G.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>h(!1),disabled:y,children:`Cancel`})]})]})]})})}var $=`maxy-admin-session-key`,Te=`maxy-calendar-show-all-kinds`;function Ee(){let[e,t]=(0,M.useState)(null),[n,r]=(0,M.useState)(!1),[i,a]=(0,M.useState)(void 0),[o,s]=(0,M.useState)(null),[c,l]=(0,M.useState)(void 0),[u,d]=(0,M.useState)(null),[p,h]=(0,M.useState)(null);(0,M.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem($)}catch{}if(!n){r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem($)}catch{}window.location.href=`/`;return}if(i.ok)try{let e=await i.json();typeof e.businessName==`string`&&a(e.businessName),e.sessionId!==void 0&&s(e.sessionId??null),h(e.role??null),l(e.userName===void 0?null:e.userName),d(e.avatar??null)}catch{}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]);let g=(0,M.useCallback)(()=>{try{sessionStorage.removeItem($)}catch{}window.location.href=`/`},[]),[_,v]=(0,M.useState)(!1),y=(0,M.useCallback)(async()=>{v(!0);try{let e=await S();if(e){try{sessionStorage.removeItem($)}catch{}window.location.href=`/`}return e}finally{v(!1)}},[]);return n?e?(0,G.jsx)(m,{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,G.jsx)(C,{cacheKey:e,businessName:i,sessionId:o,onLogout:g,onDisconnect:y,disconnecting:_,userName:c,userAvatar:u,role:p,children:(0,G.jsx)(De,{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)(f,{surface:`gate`})}function De({cacheKey:e}){let{zone:t,source:n}=i(),{adminFetch:r,sessionRefetchNonce:a}=b({initialCacheKey:e,surface:`calendar`}),[o,s]=(0,M.useState)(B),[c,l]=(0,M.useState)(()=>new Date),[d,p]=(0,M.useState)([]),[m,h]=(0,M.useState)(!1),[_,v]=(0,M.useState)(!1),[y,S]=(0,M.useState)(null),[C,E]=(0,M.useState)(null),[D,ee]=(0,M.useState)([]),[O,k]=(0,M.useState)(`none`),[A,te]=(0,M.useState)(()=>{try{return sessionStorage.getItem(Te)===`1`}catch{return!1}}),[j,N]=(0,M.useState)(null),[P,F]=(0,M.useState)(0),[I,z]=(0,M.useState)(null);(0,M.useEffect)(()=>{let e=!1;return r(`/api/admin/calendar/booking-link`).then(async t=>{if(e||!t.ok)return;let n=await t.json();typeof n.bookingDomain==`string`&&n.bookingDomain&&z(n.bookingDomain)}).catch(()=>{}),()=>{e=!0}},[r]),(0,M.useEffect)(()=>{let e=!1,{from:n,to:i}=L(o,c,t);return h(!0),S(null),r(`/api/admin/calendar/meetings?from=${encodeURIComponent(n.toISOString())}&to=${encodeURIComponent(i.toISOString())}`).then(async t=>{if(e)return;if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();p(Array.isArray(n.meetings)?n.meetings:[])}).catch(t=>{e||(S(t instanceof Error?t.message:`Failed to load`),p([]))}).finally(()=>{e||(h(!1),v(!0))}),()=>{e=!0}},[o,c,t,a,r]),(0,M.useEffect)(()=>{let e=!1,{from:n,to:i}=L(o,c,t);return r(`/api/admin/calendar/free-busy?from=${encodeURIComponent(n.toISOString())}&to=${encodeURIComponent(i.toISOString())}`).then(async t=>{if(e)return;if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();ee(ce(Array.isArray(n.slots)?n.slots:[])),k(n.gapSource===`config`?`config`:`none`)}).catch(()=>{e||(ee([]),k(`none`))}),()=>{e=!0}},[o,c,t,a,r,P]);let V=(0,M.useCallback)(()=>l(new Date),[]),H=(0,M.useCallback)(()=>l(e=>R(o,e,-1,t)),[o,t]),W=(0,M.useCallback)(()=>l(e=>R(o,e,1,t)),[o,t]),re=(0,M.useCallback)(()=>{te(e=>{let t=!e;try{sessionStorage.setItem(Te,t?`1`:`0`)}catch{}return t})},[]),K=(0,M.useCallback)((e,n)=>N({startsAt:Y(e,t),endsAt:Y(n,t)}),[t]),q=(0,M.useCallback)(e=>{p(t=>[...t,e]),F(e=>e+1),N(null)},[]);(0,M.useEffect)(()=>{E(null)},[o,c]);let J=(0,M.useRef)(null);(0,M.useEffect)(()=>{if(m)return;let e=requestAnimationFrame(()=>{let e=ye(J.current);Se(o,e&&{...e,zone:t,zoneSource:n,descrRows:d.filter(e=>(e.description??``).trim().length>0).length,gapSource:O,gaps:D.length,shownKinds:A?`meeting,event,task`:`meeting`,hiddenKinds:A?0:d.filter(e=>(e.kind??`meeting`)!==`meeting`).length})});return()=>cancelAnimationFrame(e)},[o,d,m,O,D,A,t,n]);let X=(0,M.useCallback)(e=>{p(t=>t.map(t=>t.meetingId===e.meetingId?e:t)),E(e)},[]),ie=(0,M.useCallback)(e=>{p(t=>t.filter(t=>t.meetingId!==e)),E(null)},[]);return _?(0,G.jsxs)(`div`,{className:`cal-page`,children:[(0,G.jsxs)(`header`,{className:`cal-header`,children:[(0,G.jsxs)(`div`,{className:`cal-nav`,children:[(0,G.jsx)(`button`,{type:`button`,className:`cal-nav-btn`,onClick:H,"aria-label":`Previous`,children:(0,G.jsx)(T,{size:18})}),(0,G.jsx)(`button`,{type:`button`,className:`cal-nav-btn`,onClick:W,"aria-label":`Next`,children:(0,G.jsx)(x,{size:18})}),(0,G.jsx)(`button`,{type:`button`,className:`cal-today-btn`,onClick:V,children:`Today`}),(0,G.jsxs)(`button`,{type:`button`,className:`cal-add-btn`,onClick:()=>N({startsAt:``,endsAt:``}),children:[(0,G.jsx)(g,{size:14}),` Add`]}),(0,G.jsx)(`span`,{className:`cal-range-label cal-range-label-trailing`,children:U(o,c,t)}),m&&(0,G.jsx)(u,{size:16,className:`spin`})]}),(0,G.jsx)(`div`,{className:`cal-views`,children:ne.map(e=>(0,G.jsx)(`button`,{type:`button`,className:`cal-view-btn${e===o?` cal-view-btn-active`:``}`,onClick:()=>s(e),children:e.charAt(0).toUpperCase()+e.slice(1)},e))}),I&&(0,G.jsxs)(`a`,{className:`cal-booking-link`,href:`https://${I}`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,G.jsx)(w,{size:14}),` Booking page`]})]}),(0,G.jsxs)(`div`,{className:`cal-body`,ref:J,children:[y&&(0,G.jsxs)(`div`,{className:`cal-error`,children:[`Could not load the calendar: `,y]}),(0,G.jsx)(fe,{zone:t,zoneSource:n,from:L(o,c,t).from,to:L(o,c,t).to,meetings:d,stretches:D,gapSource:O,showAllKinds:A,onToggleKinds:re,onSelect:E,onAddAt:K})]}),j&&(0,G.jsx)(pe,{zone:t,initialStart:j.startsAt,initialEnd:j.endsAt,adminFetch:r,onClose:()=>N(null),onCreated:q}),C&&(0,G.jsx)(we,{zone:t,meeting:C,adminFetch:r,onClose:()=>E(null),onSaved:X,onDeleted:ie})]}):(0,G.jsx)(f,{surface:`gate`})}(0,j.createRoot)(document.getElementById(`root`)).render((0,G.jsx)(Ee,{}));
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,t}from"./jsx-runtime-BY35JYDT.js";import"./useMediaQuery-e4ciNiuO.js";import"./useVoiceRecorder-D7_wLtrS.js";import"./AdminShell-Dm_nY4jF.js";import{n}from"./page-BBRWbFzG.js";import"./useCopyFeedback-1MKNUzp3.js";var r=e(),i=t();(0,r.createRoot)(document.getElementById(`root`)).render((0,i.jsx)(n,{}));
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{rt as e}from"./useMediaQuery-e4ciNiuO.js";var t=e(`chevron-left`,[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]);export{t};
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{rt as e}from"./useMediaQuery-e4ciNiuO.js";var t=e(`clock`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6l4 2`,key:`mmk7yg`}]]);export{t};
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{rt as e}from"./useMediaQuery-e4ciNiuO.js";var t=e(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),n=e(`copy`,[[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]);export{t as n,n as t};
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,t}from"./jsx-runtime-BY35JYDT.js";import"./useMediaQuery-e4ciNiuO.js";import"./useVoiceRecorder-D7_wLtrS.js";import{t as n}from"./page-CdRrpkky.js";import"./graph-labels-BTFUSc63.js";var r=e(),i=t();(0,r.createRoot)(document.getElementById(`root`)).render((0,i.jsx)(n,{}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@�j[�2�[x3M��-���.�.�@��ݔFa��tMgh��W�t���L��0����TU/.�� ʋ�}��^�Ç�d� "1Y��B�S.JpMq8�C���U��N��,'?��֕����%��ev/K��ʋ����:Mnlv���2�Q��V�x��,�Qڵ,��TL]JE�b�n��`
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./chunk-BycB0eMI.js";import{i as t,n,t as r}from"./jsx-runtime-
|
|
1
|
+
import{o as e}from"./chunk-BycB0eMI.js";import{i as t,n,t as r}from"./jsx-runtime-BY35JYDT.js";var i=n(),a=e(t(),1);function o(e){let t=new URLSearchParams(e.replace(/^#/,``));return{initData:t.get(`tgWebAppData`)??``,platform:t.get(`tgWebAppPlatform`),keys:[...t.keys()]}}function s(){return o(typeof window>`u`?``:window.location.hash)}function c(){return typeof window>`u`?``:new URLSearchParams(window.location.search).get(`bot`)??``}var l=class extends Error{constructor(e,t,n,r){super(e),this.reason=e,this.status=t,this.detail=n,this.missing=r}};async function u(e,t={}){let n=e.includes(`?`)?`&`:`?`,r=await fetch(`/api/field${e}${n}bot=${encodeURIComponent(c())}`,{...t,headers:{"x-telegram-init-data":s().initData,...t.body?{"content-type":`application/json`}:{},...t.headers??{}}}),i=await r.json().catch(()=>({reason:`unreadable-response`}));if(!r.ok)throw new l(i.reason??`request-failed`,r.status,i.detail,i.missing);return i}var d=()=>u(`/session`),f=()=>u(`/today`),p=e=>u(`/visit/${encodeURIComponent(e)}`);function m(e,t){let{kind:n,...r}=t;return u(`/visit/${encodeURIComponent(e)}/record`,{method:`POST`,body:JSON.stringify(r)})}var h=(e,t)=>u(`/visit/${encodeURIComponent(e)}/status`,{method:`POST`,body:JSON.stringify({to:t})});function g(e,t){return u(`/probe`,{method:`POST`,body:JSON.stringify({...e,launchKeys:t})})}var _=s;function v(e,t){return t===`ios`||t===`android`?t:/iphone|ipad|ipod/i.test(e)?`ios`:/android/i.test(e)?`android`:`other`}async function y(e,t){let n=!1;try{e.localStorage&&(e.localStorage.setItem(`__maxy_probe`,`1`),e.localStorage.removeItem(`__maxy_probe`),n=!0)}catch{n=!1}let r=!1;try{r=await e.navigator?.storage?.persisted?.()??!1}catch{r=!1}return{platform:v(e.navigator?.userAgent??``,t),indexedDB:!!e.indexedDB,localStorage:n,cacheStorage:!!e.caches,serviceWorker:!!e.navigator?.serviceWorker,persisted:r}}var b=r();function x(e){let[t,n]=(0,a.useState)(``),[r,i]=(0,a.useState)(``),[o,s]=(0,a.useState)(``),c=new Intl.DateTimeFormat(`en-GB`,{timeZone:e.zone,day:`numeric`,month:`short`,year:`numeric`}),{visit:l,history:u,checklist:d,state:f,vocabulary:p}=e.sheet,m=t=>e.missingField===t?` field-missing`:``;return(0,b.jsxs)(`main`,{className:`field-sheet`,children:[(0,b.jsx)(`button`,{type:`button`,className:`field-sheet__back`,onClick:e.onBack,children:`Back to today`}),(0,b.jsx)(`h1`,{children:l.siteName??`Site not named`}),l.address?(0,b.jsx)(`p`,{className:`field-sheet__address`,children:[l.address.streetAddress,l.address.addressLocality,l.address.postalCode].filter(Boolean).join(`, `)}):null,l.contactName?(0,b.jsx)(`p`,{className:`field-sheet__contact`,children:l.contactName}):null,l.contactTelephone?(0,b.jsx)(`p`,{className:`field-sheet__phone`,children:(0,b.jsx)(`a`,{href:`tel:${l.contactTelephone.replace(/\s+/g,``)}`,children:l.contactTelephone})}):null,l.purpose?(0,b.jsx)(`p`,{className:`field-sheet__purpose`,children:l.purpose}):null,(0,b.jsxs)(`section`,{className:`field-sheet__history`,children:[(0,b.jsxs)(`h2`,{children:[`Previous `,p.visit,`s here`]}),u.length===0?(0,b.jsxs)(`p`,{children:[`First `,p.visit,` at this site.`]}):(0,b.jsx)(`ul`,{children:u.map(e=>(0,b.jsxs)(`li`,{children:[(0,b.jsx)(`span`,{className:`field-history__date`,children:e.startDate?c.format(new Date(e.startDate)):`No date`}),(0,b.jsx)(`span`,{className:`field-history__worker`,children:e.workerId??`Nobody recorded`}),e.notes.length>0?(0,b.jsx)(`ul`,{className:`field-history__notes`,children:e.notes.map((e,t)=>(0,b.jsx)(`li`,{children:e},t))}):(0,b.jsx)(`span`,{className:`field-history__notes--none`,children:`No note left`}),(0,b.jsx)(`span`,{className:`field-history__media`,children:e.mediaCount===1?`1 photograph`:`${e.mediaCount} photographs`})]},e.visitId))})]}),(0,b.jsxs)(`section`,{className:`field-sheet__checklist${m(`checklist`)}`,children:[(0,b.jsx)(`h2`,{children:`Checklist`}),d.length===0?(0,b.jsxs)(`p`,{children:[`No checklist for this `,p.job,` type.`]}):(0,b.jsx)(`ul`,{children:d.map(t=>(0,b.jsx)(`li`,{children:(0,b.jsx)(`button`,{type:`button`,disabled:e.busy,onClick:()=>e.onRecord({kind:`checklist`,checklistItem:t}),children:t})},t))}),(0,b.jsxs)(`p`,{className:`field-sheet__count`,children:[f.checklistDone,` of `,f.checklistTotal,` done`]})]}),(0,b.jsxs)(`section`,{className:`field-sheet__parts${m(`parts`)}`,children:[(0,b.jsx)(`h2`,{children:`Parts fitted`}),(0,b.jsx)(`input`,{value:r,placeholder:`Part`,onChange:e=>i(e.target.value)}),(0,b.jsx)(`button`,{type:`button`,disabled:e.busy||r.trim()===``,onClick:()=>{e.onRecord({kind:`part`,partId:r.trim()}),i(``)},children:`Add part`}),(0,b.jsxs)(`p`,{className:`field-sheet__count`,children:[f.parts,` recorded`]})]}),(0,b.jsxs)(`section`,{className:`field-sheet__note${m(`notes`)}`,children:[(0,b.jsx)(`h2`,{children:`Note`}),(0,b.jsx)(`textarea`,{value:t,onChange:e=>n(e.target.value)}),(0,b.jsx)(`button`,{type:`button`,disabled:e.busy||t.trim()===``,onClick:()=>{e.onRecord({kind:`note`,note:t.trim()}),n(``)},children:`Save note`}),(0,b.jsxs)(`p`,{className:`field-sheet__count`,children:[f.notes,` recorded`]})]}),(0,b.jsxs)(`section`,{className:`field-sheet__signature${m(`signature`)}`,children:[(0,b.jsx)(`h2`,{children:`Signatures`}),(0,b.jsx)(`input`,{value:o,placeholder:`Name`,onChange:e=>s(e.target.value)}),(0,b.jsx)(`button`,{type:`button`,disabled:e.busy||o.trim()===``,onClick:()=>{e.onRecord({kind:`signature`,signature:o.trim()}),s(``)},children:`Sign`}),(0,b.jsxs)(`p`,{className:`field-sheet__count`,children:[f.signatures,` recorded`]})]}),e.missingField?(0,b.jsxs)(`p`,{className:`field-sheet__refusal`,role:`alert`,children:[`This `,p.visit,` needs `,e.missingField,` before it can be closed.`]}):null,(0,b.jsx)(`section`,{className:`field-sheet__status`,children:e.sheet.nextStatuses.length===0?(0,b.jsxs)(`p`,{children:[`This `,p.visit,` is finished.`]}):e.sheet.nextStatuses.map(t=>(0,b.jsx)(`button`,{type:`button`,disabled:e.busy,onClick:()=>e.onStatus(t),children:t},t))})]})}function S(e){let t=new Intl.DateTimeFormat(`en-GB`,{timeZone:e.zone,hour:`2-digit`,minute:`2-digit`}),n=new Intl.DateTimeFormat(`en-GB`,{timeZone:e.zone,day:`numeric`,month:`long`,year:`numeric`}).format(new Date(`${e.todayYmd}T12:00:00Z`));return e.visits.length===0?(0,b.jsxs)(`main`,{className:`field-today field-today--empty`,children:[(0,b.jsx)(`h1`,{children:n}),(0,b.jsxs)(`p`,{children:[`No `,e.vocabulary.visit,`s today.`]})]}):(0,b.jsxs)(`main`,{className:`field-today`,children:[(0,b.jsx)(`h1`,{children:n}),(0,b.jsx)(`ol`,{className:`field-today__list`,children:e.visits.map(n=>(0,b.jsx)(`li`,{children:(0,b.jsxs)(`button`,{type:`button`,className:`field-card`,onClick:()=>e.onOpen(n.visitId),children:[(0,b.jsx)(`span`,{className:`field-card__time`,children:n.startDate?t.format(new Date(n.startDate)):`No time set`}),(0,b.jsx)(`span`,{className:`field-card__site`,children:n.siteName??`Site not named`}),n.address?(0,b.jsx)(`span`,{className:`field-card__address`,children:[n.address.streetAddress,n.address.addressLocality,n.address.postalCode].filter(Boolean).join(`, `)}):null,n.customerName?(0,b.jsx)(`span`,{className:`field-card__customer`,children:n.customerName}):null,n.contactName?(0,b.jsx)(`span`,{className:`field-card__contact`,children:n.contactName}):null,n.contactTelephone?(0,b.jsx)(`span`,{className:`field-card__phone`,children:n.contactTelephone}):null,n.purpose?(0,b.jsx)(`span`,{className:`field-card__purpose`,children:n.purpose}):null,(0,b.jsx)(`span`,{className:`field-card__status`,children:n.status})]})},n.visitId))})]})}var C={"no-bot":`This link is missing its bot. Ask the office to send it again.`,"wrong-bot":`This link is for a different account.`,"duplicate-bot":`Two accounts claim this bot. The office needs to fix the configuration.`,"no-config":`This account has not set dispatch up yet.`,"config-invalid":`This account’s dispatch settings need attention from the office.`,malformed:`Open this from the button in your Telegram chat.`,"bad-hash":`Open this from the button in your Telegram chat.`,stale:`This page has expired. Open it again from your Telegram chat.`,"unbound-user":`Ask the office to add you as an engineer.`,"not-assigned":`That job is not yours.`,"not-found":`That job is not on this account.`,"read-failed":`Could not reach the office. Try again in a moment.`,"unreadable-response":`Could not reach the office. Try again in a moment.`},w=`Something went wrong. Show this to the office and try again.`;function T(e){return e instanceof l?C[e.reason]??w:w}function E(){let[e,t]=(0,a.useState)(null),[n,r]=(0,a.useState)(null),[i,o]=(0,a.useState)(null),[s,c]=(0,a.useState)(null),[u,v]=(0,a.useState)(null),[C,w]=(0,a.useState)(!1);(0,a.useEffect)(()=>{let e=_();(async()=>{try{await g(await y(window,e.platform),e.keys)}catch{}})()},[]),(0,a.useEffect)(()=>{(async()=>{try{t(await d()),r(await f())}catch(e){c(T(e))}})()},[]);let E=(0,a.useCallback)(async e=>{c(null),v(null);try{o(await p(e))}catch(e){c(T(e))}},[]),D=(0,a.useCallback)(async e=>{o(await p(e))},[]),O=(0,a.useCallback)(async e=>{if(i){w(!0),c(null);try{await m(i.visit.visitId,e),await D(i.visit.visitId),v(null)}catch(e){c(T(e))}finally{w(!1)}}},[i,D]),k=(0,a.useCallback)(async e=>{if(i){w(!0),c(null);try{await h(i.visit.visitId,e),v(null),o(null),r(await f())}catch(e){e instanceof l&&e.missing?v(e.missing):c(T(e))}finally{w(!1)}}},[i]);return s&&!e?(0,b.jsx)(`main`,{className:`field-error`,role:`alert`,children:(0,b.jsx)(`p`,{children:s})}):!e||!n?(0,b.jsx)(`main`,{className:`field-loading`,children:(0,b.jsx)(`p`,{children:`Loading your day…`})}):(0,b.jsxs)(b.Fragment,{children:[s?(0,b.jsx)(`p`,{className:`field-error`,role:`alert`,children:s}):null,i?(0,b.jsx)(x,{sheet:i,zone:e.zone,missingField:u,busy:C,onRecord:O,onStatus:k,onBack:()=>{o(null),v(null)}}):(0,b.jsx)(S,{zone:n.zone,todayYmd:n.todayYmd,vocabulary:n.vocabulary,visits:n.visits,onOpen:E})]})}(0,i.createRoot)(document.getElementById(`root`)).render((0,b.jsx)(E,{}));
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{rt as e}from"./useMediaQuery-e4ciNiuO.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};
|
|
Binary file
|
|
Binary file
|