@rubytech/create-maxy-code 0.1.483 → 0.1.484
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/package-lock.json +271 -1
- package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +28 -21
- package/payload/platform/plugins/docs/references/google-guide.md +27 -20
- package/payload/platform/plugins/email/mcp/dist/__tests__/email-draft-send.test.js +76 -2
- package/payload/platform/plugins/email/mcp/dist/__tests__/email-draft-send.test.js.map +1 -1
- package/payload/platform/plugins/email/mcp/dist/lib/imap.d.ts +1 -0
- package/payload/platform/plugins/email/mcp/dist/lib/imap.d.ts.map +1 -1
- package/payload/platform/plugins/email/mcp/dist/lib/imap.js +1 -0
- package/payload/platform/plugins/email/mcp/dist/lib/imap.js.map +1 -1
- package/payload/platform/plugins/email/mcp/dist/tools/email-draft-send.d.ts.map +1 -1
- package/payload/platform/plugins/email/mcp/dist/tools/email-draft-send.js +87 -6
- package/payload/platform/plugins/email/mcp/dist/tools/email-draft-send.js.map +1 -1
- package/payload/platform/plugins/google/.claude-plugin/plugin.json +1 -1
- package/payload/platform/plugins/google/PLUGIN.md +20 -1
- package/payload/platform/plugins/google/mcp/dist/__tests__/account-register.test.js +29 -1
- package/payload/platform/plugins/google/mcp/dist/__tests__/account-register.test.js.map +1 -1
- package/payload/platform/plugins/google/mcp/dist/__tests__/consent-open.test.d.ts +2 -0
- package/payload/platform/plugins/google/mcp/dist/__tests__/consent-open.test.d.ts.map +1 -0
- package/payload/platform/plugins/google/mcp/dist/__tests__/consent-open.test.js +92 -0
- package/payload/platform/plugins/google/mcp/dist/__tests__/consent-open.test.js.map +1 -0
- package/payload/platform/plugins/google/mcp/dist/auth/consent-open.d.ts +61 -0
- package/payload/platform/plugins/google/mcp/dist/auth/consent-open.d.ts.map +1 -0
- package/payload/platform/plugins/google/mcp/dist/auth/consent-open.js +184 -0
- package/payload/platform/plugins/google/mcp/dist/auth/consent-open.js.map +1 -0
- package/payload/platform/plugins/google/mcp/dist/index.js +65 -2
- package/payload/platform/plugins/google/mcp/dist/index.js.map +1 -1
- package/payload/platform/plugins/google/mcp/dist/tools/account-register.d.ts +14 -0
- package/payload/platform/plugins/google/mcp/dist/tools/account-register.d.ts.map +1 -1
- package/payload/platform/plugins/google/mcp/dist/tools/account-register.js +16 -0
- package/payload/platform/plugins/google/mcp/dist/tools/account-register.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/http-server.d.ts +5 -0
- package/payload/platform/services/claude-session-manager/dist/http-server.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/http-server.js +18 -1
- package/payload/platform/services/claude-session-manager/dist/http-server.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/index.js +8 -0
- package/payload/platform/services/claude-session-manager/dist/index.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/subagent-injection-tail.d.ts +13 -0
- package/payload/platform/services/claude-session-manager/dist/subagent-injection-tail.d.ts.map +1 -0
- package/payload/platform/services/claude-session-manager/dist/subagent-injection-tail.js +149 -0
- package/payload/platform/services/claude-session-manager/dist/subagent-injection-tail.js.map +1 -0
- package/payload/platform/services/telegram-channel/dist/instructions.d.ts.map +1 -1
- package/payload/platform/services/telegram-channel/dist/instructions.js +17 -2
- package/payload/platform/services/telegram-channel/dist/instructions.js.map +1 -1
- package/payload/platform/services/webchat-channel/dist/instructions.d.ts.map +1 -1
- package/payload/platform/services/webchat-channel/dist/instructions.js +17 -2
- package/payload/platform/services/webchat-channel/dist/instructions.js.map +1 -1
- package/payload/platform/services/whatsapp-channel/dist/server.d.ts.map +1 -1
- package/payload/platform/services/whatsapp-channel/dist/server.js +16 -2
- package/payload/platform/services/whatsapp-channel/dist/server.js.map +1 -1
- package/payload/server/public/activity.html +6 -6
- package/payload/server/public/assets/{AdminLoginScreens-Jw45pvb2.js → AdminLoginScreens-DF9S5Rca.js} +1 -1
- package/payload/server/public/assets/AdminShell-B0PNDCAb.js +2 -0
- package/payload/server/public/assets/{Checkbox-D7_S2EUI.js → Checkbox-s5X6dso4.js} +1 -1
- package/payload/server/public/assets/activity-BRBsaalV.js +1 -0
- package/payload/server/public/assets/admin-rScqRq-R.js +1 -0
- package/payload/server/public/assets/{bot-GC7iZjtW.js → bot-BVO9Uqr_.js} +1 -1
- package/payload/server/public/assets/{browser-BI-wi3CM.js → browser-BVW4FFii.js} +1 -1
- package/payload/server/public/assets/calendar-CWsD3uLk.js +1 -0
- package/payload/server/public/assets/chat-DKGREuIO.js +1 -0
- package/payload/server/public/assets/chevron-down-m581tl1J.js +1 -0
- package/payload/server/public/assets/chevron-left-BAY0xfmR.js +1 -0
- package/payload/server/public/assets/chevron-right-Dy_REdYZ.js +1 -0
- package/payload/server/public/assets/data-TOWuhMFb.js +1 -0
- package/payload/server/public/assets/{graph-Cl72j3UC.js → graph-BEGs_P2m.js} +3 -3
- package/payload/server/public/assets/{graph-labels-7p-mVi9M.js → graph-labels-Axa04w8A.js} +1 -1
- package/payload/server/public/assets/{maximize-2-HcfeeOdJ.js → maximize-2-yucCepu_.js} +1 -1
- package/payload/server/public/assets/operator-911z_Fy_.js +1 -0
- package/payload/server/public/assets/page-6CZ8R57f.js +1 -0
- package/payload/server/public/assets/{page-DPQS0X5M.js → page-CgSgj8Cy.js} +3 -3
- package/payload/server/public/assets/{public-DAn13pnw.js → public-BzwveFwz.js} +1 -1
- package/payload/server/public/assets/{rotate-ccw-CCbbX5ef.js → rotate-ccw-BH51cf2Q.js} +1 -1
- package/payload/server/public/assets/tasks-21egY7A6.js +1 -0
- package/payload/server/public/assets/{time-entry-format-C-By1MbO.js → time-entry-format-DPdGkp1C.js} +1 -1
- package/payload/server/public/assets/{triangle-alert-BDtoi5R0.js → triangle-alert-DO2rjjfV.js} +1 -1
- package/payload/server/public/assets/useCopyFeedback-HMSM7-Ir.js +1 -0
- package/payload/server/public/assets/useSubAccountSwitcher-2ojOOYNo.css +1 -0
- package/payload/server/public/assets/{useSubAccountSwitcher-sPN6lobE.js → useSubAccountSwitcher-DLvqvfoc.js} +1 -1
- package/payload/server/public/assets/{useVoiceRecorder-DOFBQ2gP.js → useVoiceRecorder-BcukQIza.js} +1 -1
- package/payload/server/public/browser.html +4 -4
- package/payload/server/public/calendar.html +6 -6
- package/payload/server/public/chat.html +13 -13
- package/payload/server/public/data.html +10 -10
- package/payload/server/public/graph.html +11 -11
- package/payload/server/public/index.html +16 -16
- package/payload/server/public/operator.html +15 -15
- package/payload/server/public/public.html +13 -13
- package/payload/server/public/tasks.html +6 -6
- package/payload/server/server.js +87 -0
- package/payload/server/public/assets/AdminShell-DR6AzflZ.js +0 -2
- package/payload/server/public/assets/activity-CKbv3zFM.js +0 -1
- package/payload/server/public/assets/admin-DXUspIjz.js +0 -1
- package/payload/server/public/assets/calendar-DXnv4F7l.js +0 -1
- package/payload/server/public/assets/chat-CAdgaPW1.js +0 -1
- package/payload/server/public/assets/chevron-down-BCLf1wKu.js +0 -1
- package/payload/server/public/assets/chevron-left-BNtL-CjS.js +0 -1
- package/payload/server/public/assets/chevron-right-Bu5hsjy5.js +0 -1
- package/payload/server/public/assets/data-D7cYlorm.js +0 -1
- package/payload/server/public/assets/operator-C0iaGPNT.js +0 -1
- package/payload/server/public/assets/page-DsV3rID5.js +0 -1
- package/payload/server/public/assets/tasks-_Ij9BdOE.js +0 -1
- package/payload/server/public/assets/useCopyFeedback-CfbJc9iN.js +0 -1
- package/payload/server/public/assets/useSubAccountSwitcher-5jQsc23X.css +0 -1
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./chunk-TPjIAO9U.js";import{A as t,C as n,D as r,E as i,H as a,I as o,L as s,M as c,N as l,O as u,P as d,S as f,T as p,V as m,_ as h,a as g,b as _,d as v,g as ee,h as y,i as b,j as x,l as S,m as C,n as w,p as te,t as ne,u as re,v as ie,w as ae,x as oe,y as T}from"./useSubAccountSwitcher-sPN6lobE.js";async function se(){try{let e=await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`logout`})});return e.ok?(await e.json().catch(()=>({})))?.logged_out===!0:(console.error(`[admin-ui] claude-logout http-status=${e.status}`),!1)}catch(e){return console.error(`[admin-ui] claude-logout fetch failed: ${e instanceof Error?e.message:String(e)}`),!1}}var E=e(a(),1),D=s(),O={sm:14,md:16,lg:18},k={sm:30,md:38,lg:46};function A({variant:e=`primary`,size:t=`md`,icon:n,iconPosition:r=`leading`,loading:i=!1,fullWidth:a=!1,disabled:o=!1,type:s=`button`,onClick:c,"aria-label":l,"aria-pressed":u,style:d,className:f,children:p}){let m=[`btn`,`btn--${e}`,t===`md`?``:`btn--${t}`,a?`btn--full`:``,f].filter(Boolean).join(` `),h=O[t],g={...e===`send`?{width:k[t],height:k[t]}:{},...d},_=Object.keys(g).length>0;return(0,D.jsxs)(`button`,{type:s,className:m,disabled:i||o,onClick:c,"aria-label":l,"aria-pressed":u,style:_?g:void 0,children:[(0,D.jsxs)(`span`,{className:`btn__content`,style:{visibility:i?`hidden`:`visible`},children:[n&&r===`leading`&&(0,D.jsx)(n,{size:h}),p,n&&r===`trailing`&&(0,D.jsx)(n,{size:h})]}),i&&(0,D.jsx)(`span`,{className:`btn__spinner`,children:`✱`})]})}var ce=c(`archive-restore`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h2`,key:`tvwodi`}],[`path`,{d:`M20 8v11a2 2 0 0 1-2 2h-2`,key:`1gkqxj`}],[`path`,{d:`m9 15 3-3 3 3`,key:`1pd0qc`}],[`path`,{d:`M12 12v9`,key:`192myk`}]]),le=c(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),ue=c(`ellipsis-vertical`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]]),de=c(`gauge`,[[`path`,{d:`m12 14 4-4`,key:`9kzdfg`}],[`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`,key:`19p75a`}]]),j=c(`list-todo`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),fe=c(`message-square`,[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}]]),pe=c(`panel-left`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}]]),me=c(`sliders-horizontal`,[[`path`,{d:`M10 5H3`,key:`1qgfaw`}],[`path`,{d:`M12 19H3`,key:`yhmn1j`}],[`path`,{d:`M14 3v4`,key:`1sua03`}],[`path`,{d:`M16 17v4`,key:`1q0r14`}],[`path`,{d:`M21 12h-9`,key:`1o4lsq`}],[`path`,{d:`M21 19h-5`,key:`1rlt1p`}],[`path`,{d:`M21 5h-7`,key:`1oszz2`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M8 12H3`,key:`a7s4jb`}]]);function he({connected:e,onConnectClaude:t}){return e?(0,D.jsxs)(`span`,{className:`claude-status-pill`,"data-connected":`true`,title:`Claude is connected`,children:[(0,D.jsx)(`img`,{src:`/brand/claude.png`,alt:``,className:`claude-status-pill__mark`}),(0,D.jsx)(`span`,{className:`claude-status-pill__label`,children:`Connected`}),(0,D.jsx)(`span`,{className:`claude-status-pill__dot claude-status-pill__dot--live`,"aria-hidden":`true`})]}):(0,D.jsxs)(`button`,{type:`button`,className:`claude-status-pill claude-status-pill--action`,"data-connected":`false`,onClick:t,title:`Connect Claude`,children:[(0,D.jsx)(`img`,{src:`/brand/claude.png`,alt:``,className:`claude-status-pill__mark`}),(0,D.jsx)(`span`,{className:`claude-status-pill__label`,children:`Connect`}),(0,D.jsx)(`span`,{className:`claude-status-pill__dot claude-status-pill__dot--down`,"aria-hidden":`true`})]})}function ge(e){return e===`/`||e===``?`Dashboard`:e.startsWith(`/chat`)?`Chat`:e.startsWith(`/tasks`)?`Tasks`:e.startsWith(`/data`)?`Data`:e.startsWith(`/calendar`)?`Calendar`:e.startsWith(`/graph`)?`Graph`:e.startsWith(`/activity`)?`Activity`:e.startsWith(`/browser`)?`Browser`:`Dashboard`}function _e({title:e,sidebarOpen:t,onToggleSidebar:n,claudeConnected:r,onConnectClaude:i}){let a=e??ge(typeof window<`u`?window.location.pathname:`/`),o=r!==void 0&&i!==void 0;return(0,D.jsxs)(`header`,{className:`admin-page-header`,children:[(0,D.jsxs)(`button`,{type:`button`,className:`admin-page-header__toggle`,"aria-label":t?`Hide sidebar`:`Show sidebar`,title:t?`Hide sidebar`:`Show sidebar`,"aria-expanded":t,onClick:n,children:[(0,D.jsx)(pe,{className:`admin-page-header__toggle-desktop`,size:18,strokeWidth:1.75}),(0,D.jsx)(f,{className:`admin-page-header__toggle-mobile`,size:22,strokeWidth:1.75})]}),(0,D.jsx)(`h1`,{className:`admin-page-header__title`,children:a}),o&&(0,D.jsx)(`div`,{className:`admin-page-header__right`,children:(0,D.jsx)(he,{connected:r,onConnectClaude:i})})]})}var ve=[{label:`Home`,href:`/`,Icon:ae,match:e=>e===`/`||e===``},{label:`Chat`,href:`/chat`,Icon:oe,match:e=>e.startsWith(`/chat`)},{label:`Tasks`,href:`/tasks`,Icon:j,match:e=>e.startsWith(`/tasks`)},{label:`Data`,href:`/data`,Icon:u,match:e=>e.startsWith(`/data`)},{label:`Calendar`,href:`/calendar`,Icon:t,match:e=>e.startsWith(`/calendar`)}];function ye(e){let t=ve.find(t=>t.match(e));return t?t.href:`/`}function be(){let e=ye(typeof window<`u`?window.location.pathname:`/`);return(0,D.jsx)(`nav`,{className:`bottom-tab-bar`,"aria-label":`Primary`,children:ve.map(t=>{let n=t.href===e,{Icon:r}=t;return(0,D.jsxs)(`a`,{href:t.href,className:`bottom-tab${n?` is-active`:``}`,"aria-current":n?`page`:void 0,children:[(0,D.jsx)(r,{size:19,strokeWidth:1.75}),(0,D.jsx)(`span`,{className:`bottom-tab__label`,children:t.label})]},t.href)})})}var M=`maxy-shell-side-px`;function xe(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .artefact`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function N(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=Math.max(248,t-480-xe());return Math.min(Math.max(e,248),n)}function Se(){if(typeof window>`u`)return 264;try{let e=window.localStorage.getItem(M);if(!e)return 264;let t=parseInt(e,10);if(!Number.isFinite(t))return console.warn(`[admin-ui] sidebar-width-parse-failed stored=${JSON.stringify(e)} fallback=264`),264;if(t>=248)return N(t)}catch{}return 264}function Ce({targetSelector:e=`.platform`}){let t=(0,E.useRef)(null),[n,r]=(0,E.useState)(()=>Se()),i=(0,E.useRef)(n);(0,E.useLayoutEffect)(()=>{let t=document.querySelector(e);!t||!(t instanceof HTMLElement)||(t.style.setProperty(`--side-px`,`${n}px`),i.current=n)},[n,e]);let a=(0,E.useCallback)(()=>{r(e=>{let t=N(e);return t===e?e:t})},[]);(0,E.useEffect)(()=>{a(),window.addEventListener(`resize`,a);let t=document.querySelector(e),n=null;return t instanceof HTMLElement&&(n=new MutationObserver(a),n.observe(t,{attributes:!0,attributeFilter:[`data-artefact`,`class`]})),()=>{window.removeEventListener(`resize`,a),n?.disconnect()}},[a,e]);let o=e=>{e.preventDefault();let n=t.current;if(!n)return;n.setPointerCapture(e.pointerId),n.classList.add(`dragging`);let a=!1,o=e=>{a=!0,r(N(Math.round(e.clientX)))},s=()=>{if(n.releasePointerCapture(e.pointerId),n.classList.remove(`dragging`),window.removeEventListener(`pointermove`,o),window.removeEventListener(`pointerup`,s),!a)return;let t=i.current;try{window.localStorage.setItem(M,String(t))}catch{}console.info(`[admin-ui] sidebar-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=N(264);r(e);try{window.localStorage.removeItem(M)}catch{}console.info(`[admin-ui] sidebar-resize px=${e}`)};return(0,D.jsx)(`div`,{ref:t,className:`side-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize sidebar`,onPointerDown:o,onDoubleClick:s})}var we=m();function Te(e){return Math.max(14,e/2-386)}function Ee(e){return e.left===0&&e.top===0&&e.width===0&&e.height===0}var De={position:`fixed`,visibility:`hidden`};function P({anchorRef:e,onClose:t,className:n,role:r,ariaLabel:i,anchorId:a,children:o}){let s=(0,E.useRef)(null),[c,l]=(0,E.useState)(De),u=(0,E.useRef)(null),d=(0,E.useCallback)(()=>{let t=s.current;if(!t)return;let r=e.current,i=[n,a].filter(Boolean).join(`:`)||`unknown`,o=t.getBoundingClientRect(),c=window.innerWidth,d=window.innerHeight,f=o.width>0&&o.height>0,p=r?r.getBoundingClientRect():null,m=(e,t)=>console.error(`[anchored-popover] op=offscreen id=${i} left=${e} top=${t} w=${o.width} h=${o.height} viewport=${c},${d}`),h=e=>{e!==u.current&&(u.current=e,console.log(e))};if(h(`[anchored-popover] op=anchor id=${i} present=${!!r} rect=${p?`${p.left},${p.top},${p.width},${p.height}`:`none`}`),!p){let e=Math.max(4,c-o.width-Te(c)),t=Math.max(4,d-o.height-14);l({position:`fixed`,left:e,top:t,visibility:`visible`}),h(`[anchored-popover] op=placed id=${i} left=${e} top=${t} w=${o.width} h=${o.height} flipped=false clampedLeft=false clampedRight=false`);return}if(f&&Ee(p)){l(De),m(p.left,p.top);return}let g=p.right-o.width,_=c-o.width-4,v=!1,ee=!1;g>_&&(g=_,v=!0),g<4&&(g=4,ee=!0);let y=d-p.bottom-4,b=p.top-4,x=o.height+8<=y?!1:o.height+8<=b?!0:b>y,S=Math.max(0,x?b:y),C=x?Math.max(4,p.top-Math.min(o.height,S)):p.bottom;l({position:`fixed`,left:g,top:C,maxHeight:S,visibility:`visible`}),h(`[anchored-popover] op=placed id=${i} left=${g} top=${C} w=${o.width} h=${o.height} maxH=${S} flipped=${x} clampedLeft=${ee} clampedRight=${v}`);let w=Math.min(o.height,S);f&&(g+o.width<=0||g>=c||C+w<=0||C>=d)&&m(g,C)},[e,a,n]);return(0,E.useLayoutEffect)(()=>{if(d(),typeof ResizeObserver>`u`)return;let e=new ResizeObserver(()=>d());return s.current&&e.observe(s.current),()=>e.disconnect()},[d]),(0,E.useEffect)(()=>{let n=e=>{e.key===`Escape`&&t()},r=n=>{let r=n.target;e.current?.contains(r)||s.current?.contains(r)||t()},i=n=>{let r=e.current;r&&n.target instanceof Node&&n.target.contains(r)&&t()},a=()=>t();return document.addEventListener(`keydown`,n),document.addEventListener(`pointerdown`,r),window.addEventListener(`scroll`,i,!0),window.addEventListener(`resize`,a),()=>{document.removeEventListener(`keydown`,n),document.removeEventListener(`pointerdown`,r),window.removeEventListener(`scroll`,i,!0),window.removeEventListener(`resize`,a)}},[e,t]),(0,we.createPortal)((0,D.jsx)(`div`,{ref:s,className:n,role:r,"aria-label":i,style:c,children:o}),document.body)}function Oe({actions:e,disabled:t}){let[n,r]=(0,E.useState)(!1),[i,a]=(0,E.useState)(null),o=(0,E.useRef)(null),s=(0,E.useCallback)(()=>{r(!1),a(null)},[]);return(0,D.jsxs)(`div`,{className:`conv-actions`,children:[(0,D.jsx)(`button`,{ref:o,type:`button`,className:`conv-action conv-actions-overflow`,onClick:()=>r(e=>!e),disabled:t,"aria-haspopup":`menu`,"aria-expanded":n,"aria-label":`Session actions`,title:`Session actions`,children:(0,D.jsx)(f,{size:12})}),n&&(0,D.jsx)(P,{anchorRef:o,onClose:s,className:`conv-actions-menu`,role:`menu`,children:e.map(e=>e.panel?(0,D.jsxs)(`div`,{className:`conv-actions-menu-disclosure`,children:[(0,D.jsxs)(`button`,{type:`button`,role:`menuitem`,"aria-haspopup":`dialog`,"aria-expanded":i===e.key,disabled:t,onClick:()=>a(t=>t===e.key?null:e.key),children:[e.icon,(0,D.jsx)(`span`,{children:e.menuLabel})]}),i===e.key&&(0,D.jsx)(`div`,{className:`conv-actions-menu-panel`,children:e.panel()})]},e.key):(0,D.jsxs)(`button`,{type:`button`,role:`menuitem`,className:e.danger?`conv-action-danger`:void 0,"aria-busy":e.busy,disabled:t,onClick:t=>{e.onClick?.(t),s()},children:[e.icon,(0,D.jsx)(`span`,{children:e.menuLabel})]},e.key))})]})}var F=`claude-opus-4-8[1m]`,I=`claude-sonnet-5`,L=`claude-haiku-4-5`,R={[F]:`Opus 4.8 (1M context)`,[I]:`Sonnet 5`,[L]:`Haiku 4.5`};function ke(e){return R[e]??e}var Ae=[F,I,L];function z(e){return e.replace(/\[1m\]$/,``)}function je(e){return Ae.find(t=>z(t)===z(e))??e}var B=[`default`,`acceptEdits`,`plan`,`auto`,`bypassPermissions`],V=[`low`,`medium`,`high`,`xhigh`];[...B],[...V],[...V];var Me=[F,I,L],Ne={default:`Ask permissions`,acceptEdits:`Accept edits`,plan:`Plan mode`,auto:`Auto mode`,bypassPermissions:`Bypass permissions`},Pe=B.map(e=>({value:e,label:Ne[e]??e})),Fe={low:`Low`,medium:`Medium`,high:`High`,xhigh:`Highest`},Ie=V.map(e=>({value:e,label:Fe[e]??e}));function H(e){if(e){let t=Me.find(t=>z(t)===z(e));if(t)return t}return F}function Le({row:e,adminFetch:t,onError:r}){let[i,a]=(0,E.useState)(()=>H(e.model)),[o,s]=(0,E.useState)(``),[c,l]=(0,E.useState)(``),[u,d]=(0,E.useState)(!1),f=(0,E.useRef)(!1);(0,E.useEffect)(()=>{a(H(e.model))},[e.model]);let p=async()=>{if(!f.current){f.current=!0,d(!0);try{let n=await t(`/api/admin/session-reseat`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({fromSessionId:e.sessionId,model:i,...o?{permissionMode:o}:{},...c?{effort:c}:{}})});if(!n.ok){r(`Could not reset ${e.title} (status ${n.status})`),console.error(`[admin-ui] dashboard-reseat-failed sessionId=${e.sessionId} status=${n.status}`),f.current=!1,d(!1);return}let a=await n.json().catch(()=>({}));a.target?window.location.assign(a.target):(r(`Reset of ${e.title} returned no target`),f.current=!1,d(!1))}catch(t){r(`Could not reset ${e.title} (network error)`),console.error(`[admin-ui] dashboard-reseat-failed sessionId=${e.sessionId} error=${t instanceof Error?t.message:String(t)}`),f.current=!1,d(!1)}}};return(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`label`,{className:`reseat-field`,children:[(0,D.jsx)(`span`,{children:`Model`}),(0,D.jsx)(`select`,{"data-kind":`model`,value:i,disabled:u,onChange:e=>a(e.target.value),children:Me.map(e=>(0,D.jsx)(`option`,{value:e,children:ke(e)},e))})]}),(0,D.jsxs)(`label`,{className:`reseat-field`,children:[(0,D.jsx)(`span`,{children:`Mode`}),(0,D.jsxs)(`select`,{"data-kind":`mode`,value:o,disabled:u,onChange:e=>s(e.target.value),children:[(0,D.jsx)(`option`,{value:``,children:`Keep current`}),Pe.map(e=>(0,D.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,D.jsxs)(`label`,{className:`reseat-field`,children:[(0,D.jsx)(`span`,{children:`Effort`}),(0,D.jsxs)(`select`,{"data-kind":`effort`,value:c,disabled:u,onChange:e=>l(e.target.value),children:[(0,D.jsx)(`option`,{value:``,children:`Keep current`}),Ie.map(e=>(0,D.jsx)(`option`,{value:e.value,children:e.label},e.value))]})]}),(0,D.jsx)(`button`,{type:`button`,className:`reseat-apply`,disabled:u,"aria-busy":u,onClick:()=>void p(),children:u?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(n,{size:12,className:`spin`,"aria-hidden":`true`}),`Resetting…`]}):`Reset`})]})}function Re(e){if(e<60)return`${e}s`;let t=Math.floor(e/60),n=e%60;return n>0?`${t}m ${n}s`:`${t}m`}function U(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function ze({target:e,anchorEl:t,onConfirm:n,onCancel:r}){let i=(0,E.useRef)(null);return i.current=t,e?(0,D.jsxs)(P,{anchorRef:i,onClose:r,className:`conv-delete-confirm`,role:`alertdialog`,ariaLabel:`Confirm delete session`,children:[(0,D.jsxs)(`div`,{className:`claude-info-header`,children:[(0,D.jsx)(`span`,{children:`Delete this conversation?`}),(0,D.jsx)(`button`,{className:`claude-info-close`,onClick:r,"aria-label":`Close`,children:`✕`})]}),(0,D.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[(0,D.jsxs)(`div`,{className:`conv-delete-target`,children:[(0,D.jsx)(`span`,{className:`conv-delete-label`,title:e.title,children:e.title||`Untitled session`}),(0,D.jsx)(`code`,{className:`conv-delete-id`,title:e.sessionId,children:e.sessionId.slice(0,8)})]}),(0,D.jsx)(`div`,{style:{marginTop:`8px`},children:`This permanently removes the transcript. It is not moved to Archive and cannot be recovered.`}),e.live&&(0,D.jsx)(`div`,{style:{marginTop:`8px`},children:`This session is running; deleting stops it first.`})]}),(0,D.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,D.jsx)(A,{variant:`danger`,size:`sm`,style:{flex:1},onClick:n,children:`Delete`}),(0,D.jsx)(A,{variant:`secondary`,size:`sm`,style:{flex:1},onClick:r,children:`Cancel`})]})]}):null}function Be({open:e,count:t,liveCount:n,onConfirm:r,onCancel:i}){if(!e)return null;let a=t===1?``:`s`;return(0,D.jsx)(`div`,{className:`claude-info-overlay`,onClick:i,children:(0,D.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Confirm delete sessions`,children:[(0,D.jsxs)(`div`,{className:`claude-info-header`,children:[(0,D.jsxs)(`span`,{children:[`Delete `,t,` conversation`,a,`?`]}),(0,D.jsx)(`button`,{className:`claude-info-close`,onClick:i,"aria-label":`Close`,children:`✕`})]}),(0,D.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[`This permanently removes `,t,` transcript`,a,`. `,t===1?`It is`:`They are`,` not moved to Archive and cannot be recovered.`,n>0&&(0,D.jsxs)(`div`,{style:{marginTop:`8px`},children:[n,` `,n===1?`is`:`are`,` running and will be stopped first.`]})]}),(0,D.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,D.jsxs)(A,{variant:`danger`,size:`sm`,style:{flex:1},onClick:r,children:[`Delete `,t]}),(0,D.jsx)(A,{variant:`secondary`,size:`sm`,style:{flex:1},onClick:i,children:`Cancel`})]})]})})}var Ve=`auth-refresh-failed`;function He({error:e,onClose:t}){if(!e)return null;let n=e.reason===Ve,r=n?`Claude sign-in expired`:`Session didn’t open`,i=n?`Your claude.ai login has expired. Re-authenticate to resume sessions.`:`The session did not bind within 60 seconds, so there is no live conversation to open.`;return(0,D.jsx)(`div`,{className:`claude-info-overlay`,onClick:t,children:(0,D.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Session could not be opened`,children:[(0,D.jsxs)(`div`,{className:`claude-info-header`,children:[(0,D.jsx)(`span`,{children:r}),(0,D.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:`✕`})]}),(0,D.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[i,(0,D.jsxs)(`div`,{className:`claude-info-row`,style:{marginTop:`8px`},children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Reason`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:e.reason})]}),e.sessionId&&(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,D.jsxs)(`span`,{className:`claude-info-value`,children:[e.sessionId.slice(0,8),`…`]})]})]})]})})}function Ue(e){let{show:t,onClose:n,claudeInfo:r,messages:i,sessionElapsed:a,sessionId:o,cacheKey:s}=e,[c,l]=(0,E.useState)(null);if(!t)return null;let u=i.flatMap(e=>e.events?.filter(e=>e.type===`usage`)??[]),d=u.at(-1),f=d?.peak_request_pct==null?d?.context_window?Math.round((d.input_tokens+d.cache_creation_tokens+d.cache_read_tokens)/d.context_window*100):0:Math.round(d.peak_request_pct*100),p=u.reduce((e,t)=>e+t.input_tokens+t.cache_creation_tokens+t.cache_read_tokens+t.output_tokens,0),m=i.flatMap(e=>e.events?.filter(e=>e.type===`rate_limit`)??[]).at(-1),h=u.reduce((e,t)=>e+(t.total_cost_usd??0),0),g=r?.account?.subscriptionType,_=e=>{let t=e*1e3-Date.now();if(t<=0)return`now`;let n=Math.floor(t/36e5),r=Math.floor(t%36e5/6e4);return n>0?`${n}h ${r}m`:`${r}m`};return(0,D.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,D.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,D.jsxs)(`div`,{className:`claude-info-header`,children:[(0,D.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`claude-info-icon`}),(0,D.jsx)(`span`,{children:`Claude Code`}),(0,D.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,D.jsxs)(`div`,{className:`claude-info-section`,children:[(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Version`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:r?r.version:`…`})]}),(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Email`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:r?.account?.email??`…`})]})]}),(g||m||h>0)&&(0,D.jsxs)(`div`,{className:`claude-info-section`,children:[g&&(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Plan`}),(0,D.jsx)(`span`,{className:`claude-info-value`,style:{textTransform:`capitalize`},children:g})]}),m&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Usage`}),(0,D.jsxs)(`span`,{className:`claude-info-value`,children:[Math.round(m.utilization*100),`%`]})]}),(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Resets in`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:_(m.resetsAt)})]}),m.isUsingOverage&&(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Overage`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:`Active`})]})]}),h>0&&(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Session cost`}),(0,D.jsxs)(`span`,{className:`claude-info-value`,children:[`$`,h<.01?h.toFixed(4):h.toFixed(2)]})]})]}),(0,D.jsxs)(`div`,{className:`claude-info-section`,children:[(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Model`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:r?.model??`…`})]}),(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Context used`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:f>0?`${f}%`:`—`})]}),(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Tokens`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:p>0?U(p):`—`})]}),(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,D.jsx)(`span`,{className:`claude-info-value`,children:Re(a)})]}),(o||s)&&(()=>{let e=o??s??``;return(0,D.jsxs)(`div`,{className:`claude-info-row`,children:[(0,D.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,D.jsx)(`button`,{type:`button`,className:`claude-info-value claude-info-id-copy`,title:`${e} (${o?`flushed`:`pre-flush`}) — click to copy`,onClick:async()=>{l(await w(e)?`copied`:`failed`),setTimeout(()=>l(null),1200)},children:c===`copied`?`copied ✓`:c===`failed`?`copy failed ✕`:`${e.slice(0,8)}…`})]})})()]})]})})}function We({open:e,onConnect:t,onClose:n}){return e?(0,D.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,D.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Claude is not connected`,children:[(0,D.jsxs)(`div`,{className:`claude-info-header`,children:[(0,D.jsx)(`span`,{children:`Claude isn’t connected`}),(0,D.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,D.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`,display:`flex`,flexDirection:`column`,gap:`10px`},children:[(0,D.jsx)(`span`,{children:`This needs Claude, which is currently disconnected. Connect to continue — the rest of the dashboard stays available either way.`}),(0,D.jsxs)(`div`,{style:{display:`flex`,gap:`8px`,alignItems:`center`},children:[(0,D.jsx)(A,{variant:`primary`,size:`sm`,onClick:t,children:`Connect Claude`}),(0,D.jsx)(`button`,{type:`button`,className:`claude-info-close`,style:{fontSize:`11px`},onClick:n,children:`Not now`})]})]})]})}):null}function Ge(e){let t=Math.round(e/6e4),n=Math.floor(t/60),r=t%60;return`${n}h ${String(r).padStart(2,`0`)}m`}function Ke(e){return e.activeMs.thinking+e.activeMs.messaging+e.activeMs.toolUse}function W(e){return e.toLocaleString(`en-GB`)}function qe(e){return`£${e.toFixed(2)}`}function G(e){let t=[`Day`,`Active`,`Output tokens`,`Input tokens`,`Cache write`,`Cache read`,`Opus 4.8 (GBP)`,`Sonnet 4.6 (GBP)`],n=(e,t)=>[e,Ge(Ke(t)),String(t.tokens.output),String(t.tokens.input),String(t.tokens.cacheWrite),String(t.tokens.cacheRead),t.costGBP.opus.toFixed(2),t.costGBP.sonnet.toFixed(2)];return[t,...e.days.map(e=>n(e.date,e)),n(`TOTAL (${e.days.length} d)`,e.totals)].map(e=>e.join(`,`)).join(`
|
|
2
|
-
`)}function Je({label:e,d:t,bold:n}){let r=n?`th`:`td`;return(0,D.jsxs)(`tr`,{className:n?`usage-total-row`:void 0,children:[(0,D.jsx)(r,{className:`usage-day`,children:e}),(0,D.jsx)(r,{children:Ge(Ke(t))}),(0,D.jsx)(r,{children:W(t.tokens.output)}),(0,D.jsx)(r,{children:W(t.tokens.input)}),(0,D.jsx)(r,{children:W(t.tokens.cacheWrite)}),(0,D.jsx)(r,{children:W(t.tokens.cacheRead)}),(0,D.jsx)(r,{children:qe(t.costGBP.opus)}),(0,D.jsx)(r,{children:qe(t.costGBP.sonnet)})]})}function Ye({show:e,onClose:t,anchorEl:n,sessionId:i,summary:a,loading:o,error:s}){let c=(0,E.useRef)(null);if(c.current=n,!e)return null;let l=!!a&&a.days.length>0;return(0,D.jsxs)(P,{anchorRef:c,onClose:t,className:`usage-popover`,role:`dialog`,ariaLabel:`Session usage and cost`,anchorId:i??void 0,children:[(0,D.jsxs)(`div`,{className:`claude-info-header`,children:[(0,D.jsxs)(`span`,{children:[`Usage & cost`,i?` · ${i.slice(0,8)}`:``]}),l&&(0,D.jsx)(`button`,{className:`usage-download`,onClick:()=>{if(!a)return;let e=new Blob([G(a)],{type:`text/csv;charset=utf-8`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`usage-${i?i.slice(0,8):`session`}.csv`,document.body.appendChild(n),n.click(),n.remove(),URL.revokeObjectURL(t)},"aria-label":`Download as CSV`,title:`Download as CSV`,children:(0,D.jsx)(r,{size:14})}),(0,D.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:(0,D.jsx)(C,{size:14})})]}),(0,D.jsxs)(`div`,{className:`claude-info-section usage-body`,children:[o&&(0,D.jsx)(`div`,{className:`usage-note`,children:`Computing usage…`}),!o&&s&&(0,D.jsx)(`div`,{className:`usage-note usage-error`,children:s}),!o&&!s&&a&&a.days.length===0&&(0,D.jsx)(`div`,{className:`usage-note`,children:`No usage recorded for this session yet.`}),!o&&!s&&a&&a.days.length>0&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`div`,{className:`usage-table-scroll`,children:(0,D.jsxs)(`table`,{className:`usage-table`,children:[(0,D.jsx)(`thead`,{children:(0,D.jsxs)(`tr`,{children:[(0,D.jsx)(`th`,{className:`usage-day`,children:`Day`}),(0,D.jsx)(`th`,{children:`Active`}),(0,D.jsx)(`th`,{children:`Output tok`}),(0,D.jsx)(`th`,{children:`Input tok`}),(0,D.jsx)(`th`,{children:`Cache write`}),(0,D.jsx)(`th`,{children:`Cache read`}),(0,D.jsx)(`th`,{children:`Opus 4.8 (£)`}),(0,D.jsx)(`th`,{children:`Sonnet 4.6 (£)`})]})}),(0,D.jsxs)(`tbody`,{children:[a.days.map(e=>(0,D.jsx)(Je,{label:e.date,d:e},e.date)),(0,D.jsx)(Je,{label:`TOTAL (${a.days.length} d)`,d:a.totals,bold:!0})]})]})}),(0,D.jsxs)(`div`,{className:`usage-note usage-caveats`,children:[`Prices dated `,a.pricing.opusPriceDate,` · £/$ `,a.pricing.usdPerGbp,` · Sonnet tokenizer factor `,a.pricing.tokenizerFactor,`. Idle human-wait dominates the calendar span; cache-read tokens dominate cost; Sonnet is a tokenizer-adjusted estimate.`]})]})]})]})}var K=`https://claude.ai/code`,Xe=200,Ze=[500,1e3,1500,2e3,2500,3e3,3e3];function Qe(e,t,n){if(e&&n.target)return{kind:`navigate`,url:n.target,sameOrigin:!0};let r=n.slug??n.bridgeSessionId??null;if(e&&r)return{kind:`navigate`,url:`${K}/${r}`,sameOrigin:!1};let i=n.reason||n.error||`status ${t}`;return{kind:`error`,sessionId:n.sessionId??null,reason:i}}function $e(e){if(!e)return``;let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``}function et(e){let{businessName:n,cacheKey:r,onConnectClaude:a,role:s,userName:c,userAvatar:f,onSelectProjects:m,onSelectTasks:C,onCloseMobileDrawer:w,collapsed:ne,onSelectData:re,initialDataSurface:se=!1,onLogout:O,onDisconnect:k,disconnecting:A,claudeConnected:pe=!0,subAccounts:he,activeAccountId:ge,switchingAccount:_e,onSwitchAccount:ve,refreshAccounts:ye,onOpenConversations:be}=e,M=te(r),xe=(0,E.useCallback)(e=>({key:`reseat`,label:`Reset session ${e.title} (model, mode, effort)`,menuLabel:`Reset`,title:`Reset — move this session onto a chosen model, mode, and effort`,icon:(0,D.jsx)(me,{size:12}),panel:()=>(0,D.jsx)(Le,{row:e,adminFetch:M,onError:e=>I({message:e,failed:!0})})}),[M]),N=l.productName,Se=n||N,Ce=typeof c==`string`?c:c===null?`name unavailable`:Se,we=(Ce.trim().charAt(0)||`?`).toUpperCase(),[Te,Ee]=(0,E.useState)(se?`data`:`sessions`),[De,P]=(0,E.useState)(!1),[F,I]=(0,E.useState)(null),[L,R]=(0,E.useState)(null),[ke,Ae]=(0,E.useState)(!1),[z,je]=(0,E.useState)([]),[B]=(0,E.useState)(()=>typeof window>`u`?null:new URLSearchParams(window.location.search).get(`session`)),[V,Me]=(0,E.useState)(!1),[Ne,Pe]=(0,E.useState)(null),[Fe,Ie]=(0,E.useState)(!1),[H,Re]=(0,E.useState)(!1),[U,Ve]=(0,E.useState)(!1),[Ue,Ge]=(0,E.useState)(null),[Ke,W]=(0,E.useState)(new Set),qe=(0,E.useRef)(new Map),[G,Je]=(0,E.useState)(!1),[K,et]=(0,E.useState)(new Set),[tt,q]=(0,E.useState)(!1),[J,it]=(0,E.useState)(null),[at,ot]=(0,E.useState)(new Set),[st,ct]=(0,E.useState)(new Set),[lt,ut]=(0,E.useState)(new Set),[Y,X]=(0,E.useState)(null),[dt,Z]=(0,E.useState)(``),[ft,pt]=(0,E.useState)(!1),[mt,ht]=(0,E.useState)(null),[gt,_t]=(0,E.useState)(null),[vt,yt]=(0,E.useState)(!1),[bt,xt]=(0,E.useState)(null),[St,Ct]=(0,E.useState)(!1),wt=(0,E.useRef)(0);(0,E.useEffect)(()=>{if(!F)return;let e=setTimeout(()=>I(null),2500);return()=>clearTimeout(e)},[F]);let Tt=B!=null&&z.some(e=>e.sessionId===B);(0,E.useEffect)(()=>{B==null||!V||console.info(`[sidebar-sessions] op=select-highlight session=${B.slice(0,8)} matched=${Tt}`)},[B,Tt,V]);let Q=(0,E.useCallback)(async()=>{if(!r)return null;let e=++wt.current;Ie(!0),Pe(null);try{let t=await M(`/api/admin/sidebar-sessions`);if(!t.ok)throw Error(`status ${t.status}`);let n=await t.json(),r=n.sessions??[];return e===wt.current?(je(r),Ge(n.accountId??null),Me(!0),r):(console.info(`[admin-ui] sidebar-sessions-stale-response-dropped token=${e}`),r)}catch(t){let n=t instanceof Error?t.message:String(t);return e===wt.current&&Pe(`Failed to load sessions: ${n}`),console.error(`[admin-ui] sidebar-sessions fetch failed: ${n}`),null}finally{e===wt.current&&Ie(!1)}},[r,M]);(0,E.useEffect)(()=>{!r||V||Q()},[r,V,Q]),(0,E.useEffect)(()=>{if(!r)return;let e=null;function t(){console.info(`[admin-ui] sidebar-refresh surface=sessions trigger=poll`),Q()}function n(){e===null&&(e=setInterval(t,nt))}function i(){e!==null&&(clearInterval(e),e=null)}function a(){document.hidden?i():(t(),n())}return document.hidden||n(),document.addEventListener(`visibilitychange`,a),()=>{i(),document.removeEventListener(`visibilitychange`,a)}},[r,Q]);let Et=()=>{console.info(`[admin-ui] sidebar-refresh surface=sessions trigger=manual`),Q()},Dt=()=>{Ee(`data`),console.info(`[admin-ui] sidebar-nav surface=data collapsed=${ne}`),re(),w()},$=typeof window<`u`&&window.location?.pathname||`/`,Ot=Te===`data`,kt=e=>{w(),window.location.href=e},At=[{key:`dashboard`,label:`Dashboard`,icon:(0,D.jsx)(ae,{size:17,strokeWidth:1.75}),active:$===`/`&&!Ot,onClick:()=>kt(`/`)},{key:`chat`,label:`Chat`,icon:(0,D.jsx)(oe,{size:17,strokeWidth:1.75}),active:$.startsWith(`/chat`),onClick:()=>kt(`/chat`)},{key:`tasks`,label:`Tasks`,icon:(0,D.jsx)(j,{size:17,strokeWidth:1.75}),active:$.startsWith(`/tasks`),onClick:()=>{C(),w()}},{key:`calendar`,label:`Calendar`,icon:(0,D.jsx)(t,{size:17,strokeWidth:1.75}),active:$.startsWith(`/calendar`),onClick:()=>kt(`/calendar`)},{key:`data`,label:`Data`,icon:(0,D.jsx)(u,{size:17,strokeWidth:1.75}),active:Ot,onClick:Dt},{key:`container`,label:o().term,icon:(0,D.jsx)(h,{size:17,strokeWidth:1.75}),active:$.startsWith(`/graph`),onClick:()=>{m(),w()}},{key:`activity`,label:`Activity`,icon:(0,D.jsx)(x,{size:17,strokeWidth:1.75}),active:$.startsWith(`/activity`),onClick:()=>kt(`/activity`)},{key:`browser`,label:`Browser`,icon:(0,D.jsx)(p,{size:17,strokeWidth:1.75}),active:$.startsWith(`/browser`),onClick:()=>kt(`/browser`)}],jt=(0,E.useCallback)(async e=>{if(at.has(e.sessionId))return;ot(t=>{let n=new Set(t);return n.add(e.sessionId),n});let t=window.open(``,`_blank`);try{let n=await M(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e.sessionId,name:e.title||e.sessionId,...e.accountId?{targetAccountId:e.accountId}:{}})}),r=await n.json().catch(()=>({})),i=Qe(n.ok,n.status,{...r,sessionId:r.sessionId??e.sessionId});console.info(`[admin-ui] sidebar-session-resume sessionId=${e.sessionId} status=${n.status} outcome=${i.kind} slug=${r.slug??r.bridgeSessionId??`none`}`),i.kind===`navigate`?(w(),t?t.location.href=i.url:window.open(i.url,`_blank`)):(t?.close(),console.error(`[admin-ui] sidebar-session-resume-failed sessionId=${e.sessionId} status=${n.status} reason=${i.reason}`),R(i))}catch(n){t?.close();let r=n instanceof Error?n.message:String(n);console.error(`[admin-ui] sidebar-session-resume-failed sessionId=${e.sessionId} error=${r}`),R({sessionId:e.sessionId,reason:r})}finally{ot(t=>{let n=new Set(t);return n.delete(e.sessionId),n})}},[M,w,at]),Mt=(0,E.useCallback)(async e=>{let t=e.slice(0,8);for(let n=1;n<=Ze.length;n++){await new Promise(e=>setTimeout(e,Ze[n-1]));let r=await Q();if(r&&r.some(t=>t.sessionId===e)){console.info(`[admin-ui] sidebar-new-session-converged sessionId=${t} via=retry attempts=${n}`);return}}console.error(`[admin-ui] sidebar-new-session-converge-timeout sessionId=${t}`)},[Q]),Nt=(0,E.useCallback)(async()=>{if(!St){Ct(!0);try{let e=await M(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}),t=await e.json().catch(()=>({})),n=Qe(e.ok,e.status,t);console.info(`[admin-ui] sidebar-new-session-spawned status=${e.status} outcome=${n.kind} slug=${t.slug??t.bridgeSessionId??`none`}`),n.kind===`navigate`?n.sameOrigin?window.location.assign(n.url):(window.open(n.url,`_blank`),t.sessionId?Mt(t.sessionId):console.error(`[admin-ui] sidebar-new-session-converge-skipped reason=no-session-id`)):e.status===503||n.reason===`claude-auth-dead`?(console.info(`[admin-ui] op=llm-action-blocked action=spawn reason=claude-disconnected`),Ae(!0)):(console.error(`[admin-ui] sidebar-new-session-failed status=${e.status} reason=${n.reason}`),R(n))}catch(e){let t=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-new-session-failed error=${t}`),R({sessionId:null,reason:t})}finally{Ct(!1)}}},[M,St,Mt]),Pt=(0,E.useCallback)((e,t)=>{e.stopPropagation(),it(t)},[]),Ft=(0,E.useCallback)(async(e,t)=>{e.stopPropagation(),ht(t),_t(null),xt(null),yt(!0);try{let e=await M(`/api/admin/session-usage?sessionId=${encodeURIComponent(t.sessionId)}`),n=await e.json().catch(()=>({}));e.ok?_t(n):xt(n.error??`status ${e.status}`)}catch(e){xt(e instanceof Error?e.message:String(e))}finally{yt(!1)}},[M]),It=(0,E.useCallback)(async(e,t={})=>{let n=t.refresh??!0;if(Ke.has(e.sessionId))return!1;W(t=>{let n=new Set(t);return n.add(e.sessionId),n});try{let t=await M(`/api/admin/session-delete`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e.sessionId})});if(!t.ok){let n=await t.json().catch(()=>({}));return console.error(`[admin-ui] sidebar-session-delete-failed sessionId=${e.sessionId} status=${t.status} error=${n.error??`unknown`}`),I({message:`Delete failed: ${n.error??`status ${t.status}`}`,failed:!0}),!1}let r=await t.json();return console.info(`[admin-ui] sidebar-session-delete sessionId=${e.sessionId} live=${e.live} confirmed=true pidKilled=${r.pidKilled??`?`} deleted=${r.deleted??`?`}`),je(t=>t.filter(t=>t.sessionId!==e.sessionId)),n&&Q(),!0}catch(t){let n=t instanceof Error?t.message:String(t);return console.error(`[admin-ui] sidebar-session-delete-failed sessionId=${e.sessionId} error=${n}`),I({message:`Delete failed: ${n}`,failed:!0}),!1}finally{W(t=>{let n=new Set(t);return n.delete(e.sessionId),n})}},[M,Ke,Q]),Lt=(0,E.useCallback)(e=>{et(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Rt=(0,E.useCallback)(()=>{Je(!1),et(new Set)},[]),zt=(0,E.useCallback)(async()=>{let e=[...K].map(e=>z.find(t=>t.sessionId===e)).filter(e=>!!e),t=e.filter(e=>e.live).length;console.info(`[admin-ui] sidebar-bulk-delete op=start count=${e.length} live=${t}`);let n=(await Promise.all(e.map(e=>It(e,{refresh:!1})))).filter(Boolean).length;console.info(`[admin-ui] sidebar-bulk-delete op=done requested=${e.length} ok=${n} failed=${e.length-n}`),Q(),Rt()},[K,z,It,Q,Rt]),Bt=(0,E.useCallback)(async(e,t)=>{if(e.stopPropagation(),!st.has(t.sessionId)){ct(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await M(`/api/admin/session-stop`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:t.sessionId})});if(!e.ok){let n=await e.json().catch(()=>({}));console.error(`[admin-ui] sidebar-session-stop-failed sessionId=${t.sessionId} status=${e.status} error=${n.error??`unknown`}`),I({message:`Stop failed: ${n.error??`status ${e.status}`}`,failed:!0});return}console.info(`[admin-ui] sidebar-session-stop sessionId=${t.sessionId}`),Q()}catch(e){let n=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-session-stop-failed sessionId=${t.sessionId} error=${n}`),I({message:`Stop failed: ${n}`,failed:!0})}finally{ct(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[M,st,Q]),Vt=(0,E.useCallback)(async(e,t,n)=>{if(e.stopPropagation(),!lt.has(t.sessionId)){ut(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await M(`/api/admin/session-archive`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:t.sessionId,mode:n})});if(!e.ok){let r=await e.json().catch(()=>({})),i=r.detail??r.error??`status ${e.status}`;console.error(`[admin-ui] sidebar-session-archive-failed sessionId=${t.sessionId} mode=${n} status=${e.status} error=${r.error??`unknown`}`),I({message:`${n===`archive`?`Archive`:`Unarchive`} failed: ${i}`,failed:!0});return}console.info(`[admin-ui] sidebar-session-archive sessionId=${t.sessionId} mode=${n}`),Q()}catch(e){let r=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-session-archive-failed sessionId=${t.sessionId} mode=${n} error=${r}`),I({message:`${n===`archive`?`Archive`:`Unarchive`} failed: ${r}`,failed:!0})}finally{ut(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[M,lt,Q]),Ht=(0,E.useCallback)(async e=>{let t=dt.trim();if(!t){I({message:`Title can’t be empty`,failed:!0});return}if(t.length>Xe){I({message:`Title too long (max ${Xe})`,failed:!0});return}pt(!0);try{let n=await M(`/api/admin/session-rename`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e.sessionId,title:t})});if(!n.ok){let t=await n.json().catch(()=>({})),r=t.reason??t.error??`status ${n.status}`;console.error(`[admin-ui] sidebar-session-rename sessionId=${e.sessionId.slice(0,8)} outcome=rejected reason=${r}`),I({message:`Rename failed: ${r}`,failed:!0});return}console.info(`[admin-ui] sidebar-session-rename sessionId=${e.sessionId.slice(0,8)} outcome=ok`),X(null),Z(``),Q()}catch(t){let n=t instanceof Error?t.message:String(t);console.error(`[admin-ui] sidebar-session-rename sessionId=${e.sessionId.slice(0,8)} outcome=rejected reason=${n}`),I({message:`Rename failed: ${n}`,failed:!0})}finally{pt(!1)}},[M,dt,Q]);return(0,D.jsxs)(`aside`,{className:`side`,children:[(0,D.jsxs)(`div`,{className:`side-brand`,children:[(0,D.jsx)(`img`,{className:`side-brand-icon`,src:d,alt:``,"aria-hidden":`true`}),(0,D.jsxs)(`span`,{className:`side-brand-lockup`,children:[(0,D.jsx)(`span`,{className:`side-brand-business`,children:Se}),(0,D.jsx)(`span`,{className:`side-brand-product`,children:l.productName})]})]}),(0,D.jsx)(`nav`,{className:`side-nav`,children:At.map(e=>(0,D.jsxs)(`button`,{type:`button`,className:`admin-row nav-row${e.active?` active`:``}`,"aria-current":e.active?`page`:void 0,onClick:e.onClick,children:[e.icon,(0,D.jsx)(`span`,{className:`label`,children:e.label}),(0,D.jsx)(`span`,{className:`kbd`})]},e.key))}),(()=>{let e=z.filter(e=>H?!0:!e.isSubagent).filter(e=>U?!0:!e.archived),t=z.some(e=>e.isSubagent),n=z.some(e=>e.archived);return(0,D.jsx)(`div`,{className:`side-sessions`,children:(0,D.jsxs)(`div`,{className:`side-list`,children:[(0,D.jsxs)(`div`,{className:`group-head`,children:[(0,D.jsx)(`span`,{children:`Sessions`}),(0,D.jsxs)(`span`,{className:`group-head-meta`,children:[(0,D.jsx)(`button`,{type:`button`,className:`group-head-select${G?` active`:``}`,"aria-pressed":G,title:G?`Exit select mode`:`Select multiple sessions to delete`,onClick:()=>{Je(e=>!e),et(new Set),X(null),Z(``)},children:`Select`}),(0,D.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh sessions`,"aria-label":`Refresh sessions`,onClick:Et,disabled:Fe,children:(0,D.jsx)(ie,{size:12,className:Fe?`spinning`:void 0})}),(0,D.jsx)(`span`,{children:Fe?`…`:String(e.length)}),(0,D.jsxs)(`button`,{type:`button`,className:`admin-btn-cta side-sessions-new`,onClick:Nt,disabled:St,"aria-busy":St,children:[(0,D.jsx)(T,{size:13}),(0,D.jsx)(`span`,{children:St?`Spawning…`:`New session`})]})]})]}),G&&(0,D.jsxs)(`div`,{className:`session-select-bar`,children:[(0,D.jsxs)(`span`,{className:`session-select-count`,children:[K.size,` selected`]}),(0,D.jsxs)(`button`,{type:`button`,className:`session-select-delete`,disabled:K.size===0,onClick:()=>q(!0),children:[`Delete `,K.size]}),(0,D.jsx)(`button`,{type:`button`,className:`session-select-cancel`,onClick:Rt,children:`Cancel`})]}),Ue&&(0,D.jsx)(`div`,{className:`side-account-id`,title:`This install's accountId. The first 8 characters match the truncated UUID label on the live Remote Control daemon entry in claude.ai/code.`,children:(0,D.jsx)(`code`,{children:Ue})}),(t||n)&&(0,D.jsxs)(`div`,{className:`artefact-filter-chips`,children:[t&&(0,D.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${H?` active`:``}`,"aria-pressed":H,onClick:()=>Re(e=>!e),title:H?`Hide subagent sessions`:`Show subagent sessions`,children:`Subagents`}),n&&(0,D.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${U?` active`:``}`,"aria-pressed":U,onClick:()=>Ve(e=>!e),title:U?`Hide archived sessions`:`Show archived sessions`,children:`Archived`})]}),Ne&&(0,D.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:Ne}),V&&!Ne&&e.length===0&&(0,D.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No sessions yet`}),e.map(e=>{let t=$e(e.startedAt),n=at.has(e.sessionId),r=Ke.has(e.sessionId),a=st.has(e.sessionId),o=lt.has(e.sessionId),s=n||r||a||o,c=()=>{window.location.assign(`/chat?session=${e.sessionId}`)},l=[{key:`open`,label:`Resume session ${e.title} in claude.ai/code`,menuLabel:`Resume in claude.ai/code`,title:`Resume in a fresh local Remote Control PTY`,icon:(0,D.jsx)(i,{size:12}),busy:n,onClick:()=>{jt(e)}},{key:`message`,label:`Open session ${e.title} in admin webchat`,menuLabel:`Open in webchat`,title:`Open in admin webchat (/chat) — sending resumes this session`,icon:(0,D.jsx)(fe,{size:12}),onClick:()=>{c()}},{key:`usage`,label:`Usage and cost for session ${e.title}`,menuLabel:`Usage & cost`,title:`Per-day active time, tokens, and estimated GBP cost`,icon:(0,D.jsx)(de,{size:12}),onClick:t=>{Ft(t,e)}},...e.live?[{key:`stop`,label:`Stop session ${e.title}`,menuLabel:`Stop`,title:`Stop session process (keeps the conversation, can resume later)`,icon:(0,D.jsx)(ee,{size:12}),busy:a,onClick:t=>{Bt(t,e)}}]:[],e.archived?{key:`unarchive`,label:`Unarchive session ${e.title}`,menuLabel:`Unarchive`,title:`Unarchive (move back to the active list)`,icon:(0,D.jsx)(ce,{size:12}),busy:o,onClick:t=>{Vt(t,e,`unarchive`)}}:{key:`archive`,label:`Archive session ${e.title}`,menuLabel:`Archive`,title:`Archive (hide from the list, keeps the conversation resumable)`,icon:(0,D.jsx)(le,{size:12}),busy:o,onClick:t=>{Vt(t,e,`archive`)}},{key:`rename`,label:`Rename session ${e.title}`,menuLabel:`Rename`,title:`Rename this session`,icon:(0,D.jsx)(_,{size:12}),busy:ft&&Y===e.sessionId,onClick:t=>{t.stopPropagation(),X(e.sessionId),Z(e.personName??e.title)}},{key:`delete`,label:`Delete session ${e.title}`,menuLabel:`Delete`,title:`Delete session (stops the process, removes the conversation)`,icon:(0,D.jsx)(y,{size:12}),danger:!0,busy:r,onClick:t=>{Pt(t,e)}},xe({sessionId:e.sessionId,model:e.model??null,title:e.personName??e.title})],u=e.channel===`whatsapp`?` conv-channel-whatsapp`:e.channel===`telegram`?` conv-channel-telegram`:``,d=e.channel===`whatsapp`||e.channel===`telegram`||e.channel===`webchat`,f=g.includes(e.channel??``)&&e.senderId&&e.titleSource===`prefix`?b({operatorName:e.personName??null,whatsappName:e.whatsappName??null,senderId:e.senderId,title:e.title}):e.personName??e.title;return(0,D.jsxs)(`div`,{ref:t=>{let n=qe.current;t?n.set(e.sessionId,t):n.delete(e.sessionId)},className:`conv conv-with-actions${u}${e.sessionId===B?` active`:``}`,children:[(0,D.jsxs)(`div`,{className:`conv-main-static conv-main-clickable`,role:`button`,tabIndex:0,"aria-label":`Open ${f} in webchat`,onClick:()=>{if(Y!==e.sessionId){if(G){Lt(e.sessionId);return}c()}},onKeyDown:t=>{Y!==e.sessionId&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),G?Lt(e.sessionId):c())},children:[G&&(0,D.jsx)(`input`,{type:`checkbox`,className:`conv-select-check`,checked:K.has(e.sessionId),"aria-label":`Select ${f}`,onChange:()=>Lt(e.sessionId),onClick:e=>e.stopPropagation()}),(0,D.jsx)(`span`,{className:`conv-live-dot`,"data-live":e.live?`1`:`0`,"aria-label":e.live?`live session`:`ended session`}),(0,D.jsxs)(`span`,{className:`conv-stack`,children:[(0,D.jsxs)(`span`,{className:`conv-name-line`,children:[d&&(0,D.jsx)(S,{channel:e.channel,size:13}),Y===e.sessionId?(0,D.jsx)(`input`,{className:`conv-name conv-name-edit`,autoFocus:!0,onFocus:e=>e.currentTarget.select(),value:dt,disabled:ft,"aria-label":`New title for session ${e.title}`,onChange:e=>Z(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),Ht(e)):t.key===`Escape`&&(t.preventDefault(),X(null),Z(``))},onBlur:()=>{Y===e.sessionId&&!ft&&(X(null),Z(``))}}):(0,D.jsx)(`span`,{className:`conv-name`,title:f,children:f})]}),(0,D.jsxs)(`span`,{className:`conv-timestamp`,children:[(0,D.jsx)(`code`,{className:`conv-session-id`,title:`First 8 characters of this session's id — distinguishes rows with identical auto-titles. The resume/delete buttons act on the full id.`,children:e.sessionId.slice(0,8)}),t&&(0,D.jsxs)(`span`,{children:[` · `,t]})]})]})]}),!G&&(0,D.jsx)(Oe,{actions:l,disabled:s})]},e.sessionId)})]})})})(),(0,D.jsxs)(`div`,{className:`side-foot`,children:[(0,D.jsx)(`div`,{className:`avatar`,children:f?(0,D.jsx)(`img`,{src:f,alt:Ce}):we}),(0,D.jsxs)(`div`,{className:`who`,children:[(0,D.jsx)(`span`,{className:`name`,children:Ce}),(0,D.jsx)(rt,{})]}),(0,D.jsx)(`button`,{type:`button`,className:`side-foot-kebab`,"aria-label":`Account menu`,"aria-haspopup":`menu`,"aria-expanded":De,onClick:()=>P(e=>!e),children:(0,D.jsx)(ue,{size:16})}),De&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`div`,{className:`side-foot-menu-scrim`,"aria-hidden":`true`,onClick:()=>P(!1)}),(0,D.jsx)(`div`,{className:`side-foot-menu`,role:`menu`,children:(0,D.jsx)(v,{variant:`admin`,onCloseMenu:()=>P(!1),onLogout:O??(()=>{}),onDisconnect:k,disconnecting:A,claudeConnected:pe,onConnectClaude:a,cacheKey:r,subAccounts:he,activeAccountId:ge,switchingAccount:_e,onSwitchAccount:ve,refreshAccounts:ye,onOpenConversations:be})})]})]}),F&&(0,D.jsx)(`div`,{className:`copy-toast${F.failed?` copy-toast-failed`:``}`,role:`status`,children:F.message}),(0,D.jsx)(He,{error:L,onClose:()=>R(null)}),(0,D.jsx)(We,{open:ke,onConnect:()=>{Ae(!1),a?.()},onClose:()=>Ae(!1)}),(0,D.jsx)(ze,{target:J,anchorEl:J?qe.current.get(J.sessionId)??null:null,onCancel:()=>it(null),onConfirm:()=>{let e=J;it(null),e&&It(e)}},J?.sessionId??`none`),(0,D.jsx)(Be,{open:tt,count:K.size,liveCount:z.filter(e=>K.has(e.sessionId)&&e.live).length,onConfirm:()=>{q(!1),zt()},onCancel:()=>q(!1)}),(0,D.jsx)(Ye,{show:mt!==null,onClose:()=>{ht(null),_t(null),xt(null)},anchorEl:mt?qe.current.get(mt.sessionId)??null:null,sessionId:mt?.sessionId??null,summary:gt,loading:vt,error:bt},mt?.sessionId??`none`)]})}var tt=5e3,nt=3e4;function rt(){let[e,t]=(0,E.useState)(null);if((0,E.useEffect)(()=>{let e=!1,n=null;async function r(){try{let n=await fetch(`/api/admin/system-stats`);if(!n.ok){console.error(`[admin-ui] system-stats-fetch-failed status=${n.status}`);return}let r=await n.json();e||t(r)}catch(e){console.error(`[admin-ui] system-stats-fetch-failed reason=${e instanceof Error?e.message:String(e)}`)}}function i(){n===null&&(r(),n=setInterval(()=>{r()},tt))}function a(){n!==null&&(clearInterval(n),n=null)}function o(){document.hidden?a():i()}return document.hidden||i(),document.addEventListener(`visibilitychange`,o),()=>{e=!0,a(),document.removeEventListener(`visibilitychange`,o)}},[]),!e||e.platform===`darwin`)return null;let n=e.cpuPct,r=e.memUsedPct,i=n!==null&&n>=.9,a=n!==null&&n>=.98,o=r!==null&&r>=.9,s=r!==null&&r>=.98,c=i||o,l=a||s,u=e=>e===null?`—`:`${Math.round(e*100)}%`,d=[`system-stats`];return c&&d.push(`system-stats--warn`),l&&d.push(`system-stats--crit`),(0,D.jsxs)(`span`,{className:d.join(` `),role:`status`,"aria-label":`host CPU and RAM`,children:[(0,D.jsxs)(`span`,{className:i?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`CPU `,u(n)]}),` · `,(0,D.jsxs)(`span`,{className:o?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`RAM `,u(r)]})]})}var q=`admin-sidebar-collapsed`,J=`admin-sidebar-drawer-open`,it=1080;function at(){if(typeof window>`u`)return!1;let e=null;try{e=window.sessionStorage.getItem(q)}catch{e=null}return e===null?typeof window.matchMedia==`function`?window.matchMedia(`(min-width: 721px) and (max-width: ${it}px)`).matches:!1:e===`1`}function ot(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(q,`1`):window.sessionStorage.removeItem(q)}catch{}}function st(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(J)===`1`}catch{return!1}}function ct(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(J,`1`):window.sessionStorage.removeItem(J)}catch{}}function lt(e){let[t,n]=(0,E.useState)(()=>typeof window>`u`||typeof window.matchMedia!=`function`?!1:window.matchMedia(e).matches);return(0,E.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let t=window.matchMedia(e),r=()=>n(t.matches);return r(),t.addEventListener(`change`,r),()=>t.removeEventListener(`change`,r)},[e]),t}var ut=720;function Y(e,t){return e===`/`?{via:`in-place`}:{via:`navigate`,href:`/?wa=${encodeURIComponent(t.remoteJid??``)}&acct=${encodeURIComponent(t.accountId??``)}`}}function X(e){return e===`/`?{via:`in-place`}:{via:`navigate`,href:`/?data=1`}}function dt(e,t){if(e!==`/`)return null;let n=new URLSearchParams(t),r=n.get(`wa`),i=n.get(`acct`);return!r||!i?null:{sessionId:``,projectDir:``,title:``,senderId:null,startedAt:``,channel:`whatsapp`,role:`public`,operatorName:null,whatsappName:null,lastMessageAt:null,modelGated:!1,model:null,source:`store`,accountId:i,remoteJid:r}}function Z(e,t){return e===`/`?new URLSearchParams(t).has(`data`):!1}function ft(e,t){return t===`operator`&&e===`chat`||e===`dashboard`?`/`:e===`data`?`/data`:e===`graph`?`/graph`:e===`calendar`?`/calendar`:e===`chat`?`/chat`:e===`activity`?`/activity`:`/browser`}function pt(e){let{cacheKey:t,businessName:n,variant:r=`admin`,onLogout:i,onDisconnect:a,disconnecting:s,claudeConnected:c,onConnectClaude:l,userName:u,userAvatar:d,role:f,onOpenConversations:p,children:m,footer:h}=e,{subAccounts:g,activeAccountId:_,switching:v,switchAccount:ee,refreshAccounts:y}=ne(t),[b,x]=(0,E.useState)(!0);(0,E.useEffect)(()=>{if(c!==void 0||r!==`admin`)return;let e=!1,t=async()=>{try{let t=await fetch(`/api/health`);if(!t.ok)return;let n=await t.json();e||x(n.auth_status!==`dead`&&n.auth_status!==`missing`)}catch{}};t();let n=setInterval(t,6e4);return()=>{e=!0,clearInterval(n)}},[c,r]);let S=c??b,C=l??(()=>{window.location.assign(`/?connect=claude`)}),[w,te]=(0,E.useState)(()=>at()),[ie,ae]=(0,E.useState)(!1),oe=(0,E.useRef)(!0);(0,E.useEffect)(()=>{if(oe.current){oe.current=!1;return}ae(!0);let e=setTimeout(()=>ae(!1),260);return()=>clearTimeout(e)},[w]);let[T,se]=(0,E.useState)(()=>st()),O=lt(`(max-width: ${ut}px)`),[k,A]=(0,E.useState)(()=>typeof window>`u`||Z(window.location.pathname,window.location.search)?null:dt(window.location.pathname,window.location.search)),[ce,le]=(0,E.useState)(()=>typeof window>`u`?!1:Z(window.location.pathname,window.location.search)),[ue]=(0,E.useState)(()=>ce),de=(0,E.useCallback)(e=>{ot(e),te(e)},[]),j=(0,E.useCallback)(e=>{ct(e),se(e)},[]);(0,E.useEffect)(()=>{if(typeof window>`u`)return;let e=window.location?.pathname??``;console.info(`[admin-ui] shell-mount route=${e} variant=${r} sidebar=${r===`operator`?`none`:`present`} collapsed=${w} drawer=${T}`)},[]),(0,E.useEffect)(()=>{typeof window>`u`||!k||(console.info(`[admin-ui] wa-hydrate route=/ remoteJid=${k.remoteJid??``}`),window.history.replaceState(null,``,`/`))},[]),(0,E.useEffect)(()=>{typeof window>`u`||!ce||(console.info(`[admin-ui] data-hydrate route=/`),window.history.replaceState(null,``,`/`))},[]);let fe=(0,E.useCallback)(e=>{if(le(!1),e===null){A(null);return}let t=typeof window<`u`?window.location.pathname:`/`,n=Y(t,e);console.info(`[admin-ui] wa-open route=${t} via=${n.via} sessionId=${e.sessionId.slice(0,8)}`),n.via===`in-place`?A(e):window.location.href=n.href},[]),pe=(0,E.useCallback)(()=>{let e=typeof window<`u`?window.location.pathname:`/`,t=X(e);if(console.info(`[admin-ui] data-open route=${e} via=${t.via}`),t.via===`navigate`){window.location.href=t.href;return}A(null),le(!0)},[]),me=O?T:!w,he=(0,E.useCallback)(()=>{if(!(typeof window>`u`))if(window.matchMedia(`(max-width: ${ut}px)`).matches){let e=T;console.info(`[admin-ui] header-sidebar-toggle from=${e?`open`:`closed`} mode=drawer`),j(!e)}else{let e=w;console.info(`[admin-ui] header-sidebar-toggle from=${e?`closed`:`open`} mode=collapse`),de(!e)}},[w,T,de,j]),ge=(0,E.useCallback)(e=>{let t=ft(e,r);console.info(`[admin-ui] header-menu-nav target=${e} dest=${t}`),window.location.href=t},[r]),ve={collapsed:w,mobileDrawerOpen:T,sidebarOpen:me,onToggleSidebar:he,setMobileDrawerOpen:j,selectedWhatsapp:k,onClearWhatsapp:()=>A(null),onSelectWhatsappConversation:fe,dataOpen:ce};return r===`operator`?(0,D.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[(0,D.jsx)(re,{businessName:n,variant:r,onNavigate:ge,onOpenConversations:p,onToggleSidebar:he,sidebarOpen:me,onLogout:i,onDisconnect:a,disconnecting:s,cacheKey:t,subAccounts:g,activeAccountId:_,switchingAccount:v,onSwitchAccount:ee,refreshAccounts:y}),(0,D.jsx)(`div`,{className:`platform platform-operator`,children:typeof m==`function`?m(ve):m}),h]}):(0,D.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[(0,D.jsxs)(`div`,{className:`platform${T?` menu-open`:``}${!O&&w?` sidebar-collapsed`:``}${ie?` sidebar-animating`:``}`,"data-artefact":`closed`,children:[(0,D.jsx)(et,{businessName:n,cacheKey:t,onConnectClaude:C,role:f??null,userName:u,userAvatar:d??null,onSelectProjects:()=>{window.location.href=`/graph?label=${o().label}`},onSelectTasks:()=>{window.location.href=`/tasks`},onCloseMobileDrawer:()=>j(!1),collapsed:w,mobileDrawerOpen:T,onSelectData:pe,onCloseData:()=>le(!1),initialDataSurface:ue,onLogout:i,onDisconnect:a,disconnecting:s,claudeConnected:S,subAccounts:g,activeAccountId:_,switchingAccount:v,onSwitchAccount:ee,refreshAccounts:y,onOpenConversations:p}),!O&&(0,D.jsx)(Ce,{}),(0,D.jsx)(_e,{sidebarOpen:me,onToggleSidebar:he,claudeConnected:S,onConnectClaude:C}),typeof m==`function`?m(ve):m]}),T&&(0,D.jsx)(`div`,{className:`sidebar-backdrop menu-open`,"aria-hidden":`true`,onClick:()=>j(!1)}),(0,D.jsx)(be,{}),h]})}export{A as _,Ue as a,I as c,me as d,j as f,ce as g,le as h,We as i,je as l,ue as m,lt as n,L as o,de as p,Qe as r,F as s,pt as t,ke as u,se as v};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./chunk-TPjIAO9U.js";import{B as t,C as n,H as r,L as i,f as a,j as o,z as s}from"./useSubAccountSwitcher-sPN6lobE.js";import{_ as c,t as l,v as u}from"./AdminShell-DR6AzflZ.js";import{t as d}from"./Checkbox-D7_S2EUI.js";import{t as f}from"./triangle-alert-BDtoi5R0.js";var p=t(),m=e(r(),1),h=i(),g=`—`;function _(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 v={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.`},y=new Set([`never-run`,`never-succeeded`,`failing`,`stalled`]),b=10;function x(e){return e===null||!Number.isFinite(e)?g:`${e.toFixed(1)}%`}function S(e){return e<6e4?`${Math.round(e/1e3)}s`:e<36e5?`${Math.round(e/6e4)}m`:`${Math.round(e/36e5)}h`}function C(e,t){if(e===null)return g;let n=t-e;return n<0?`in ${S(-n)}`:n<6e4?`${Math.round(n/1e3)}s ago`:n<36e5?`${Math.round(n/6e4)}m ago`:`${Math.round(n/36e5)}h ago`}function w(e,t){if(e===null)return g;let n=e-t;return n>=0?`in ${S(n)}`:`overdue by ${S(-n)}`}function T({loops:e,nowMs:t=Date.now()}){let[n,r]=(0,m.useState)(!1);if(!e)return(0,h.jsxs)(`section`,{className:`activity-loops`,children:[(0,h.jsx)(`h2`,{className:`activity-loops-heading`,children:`Scheduled work`}),(0,h.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=>y.has(e.state)),o=e.rows.filter(e=>!y.has(e.state)&&typeof e.cpuPct==`number`&&e.cpuPct>=b),s=n?e.rows:[...a,...o];return(0,h.jsxs)(`section`,{className:`activity-loops`,children:[(0,h.jsx)(`h2`,{className:`activity-loops-heading`,children:`Scheduled work`}),(0,h.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,h.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,h.jsxs)(`p`,{className:`activity-loops-cpu`,children:[`Server process at `,e.processPct.toFixed(1),`% of one core`,typeof e.attributedPct==`number`&&(0,h.jsxs)(h.Fragment,{children:[` · these loops explain `,e.attributedPct.toFixed(1),`%`]}),typeof e.unattributedPct==`number`&&e.unattributedPct>=1&&(0,h.jsxs)(h.Fragment,{children:[` · `,(0,h.jsxs)(`strong`,{children:[e.unattributedPct.toFixed(1),`% is not from these loops`]})]})]}),i>0&&(0,h.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,h.jsx)(`div`,{className:`activity-table-scroll`,children:(0,h.jsxs)(`table`,{className:`activity-table`,children:[(0,h.jsx)(`thead`,{children:(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Loop`}),(0,h.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`State`}),(0,h.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Every`}),(0,h.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Last run`}),(0,h.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Last OK`}),(0,h.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Took`}),(0,h.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`CPU`}),(0,h.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Runs`}),(0,h.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Produced`}),(0,h.jsx)(`th`,{scope:`col`,className:`activity-th`,children:`Next due`})]})}),(0,h.jsx)(`tbody`,{children:s.map(e=>(0,h.jsxs)(`tr`,{className:y.has(e.state)?`activity-loop-row activity-loop-unhealthy`:`activity-loop-row`,children:[(0,h.jsx)(`td`,{className:`activity-td`,children:e.name}),(0,h.jsx)(`td`,{className:`activity-td`,title:v[e.state],children:(0,h.jsxs)(`span`,{className:`activity-state`,children:[(0,h.jsx)(`span`,{className:e.state===`ok`?`activity-state-dot is-healthy`:y.has(e.state)?`activity-state-dot is-unhealthy`:`activity-state-dot`,"aria-hidden":`true`}),_(e.state)]})}),(0,h.jsx)(`td`,{className:`activity-td activity-num`,children:S(e.intervalMs)}),(0,h.jsx)(`td`,{className:`activity-td activity-num`,children:C(e.lastStartMs,t)}),(0,h.jsx)(`td`,{className:`activity-td activity-num`,children:C(e.lastSuccessMs,t)}),(0,h.jsx)(`td`,{className:`activity-td activity-num`,children:e.lastDurationMs===null?g:`${e.lastDurationMs} ms`}),(0,h.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:x(e.cpuPct)}),(0,h.jsxs)(`td`,{className:`activity-td activity-num`,children:[e.successCount,`/`,e.runCount]}),(0,h.jsx)(`td`,{className:`activity-td activity-loop-note`,children:(0,h.jsx)(`span`,{className:`activity-loop-note-text`,title:e.lastError??e.lastNote??void 0,children:e.lastError??e.lastNote??g})}),(0,h.jsx)(`td`,{className:`activity-td activity-num`,children:w(e.nextDueMs,t)})]},e.name))})]})}),(0,h.jsxs)(`dl`,{className:`activity-legend`,children:[(0,h.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,h.jsx)(`dt`,{className:`activity-legend-term`,children:`Runs`}),(0,h.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,h.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,h.jsx)(`dt`,{className:`activity-legend-term`,children:`CPU`}),(0,h.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,h.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,h.jsx)(`dt`,{className:`activity-legend-term`,children:g}),(0,h.jsx)(`dd`,{className:`activity-legend-def`,children:`Not measured. It does not mean zero.`})]})]})]})}var E=`maxy-admin-session-key`;function D(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 O=[{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}],k=[{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.`}],A=[`activeMsInRange`,`lastMessageAt`,`cpuPct`,`tokensInRange`],j={label:`Account`,help:`The business this session belongs to. "untagged" means the session records no account.`};function M(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){if(!e)return N;let n=Date.parse(e);if(!Number.isFinite(n))return N;let r=new Date(n),i=new Date(t),a=`${String(r.getHours()).padStart(2,`0`)}:${String(r.getMinutes()).padStart(2,`0`)}`;return r.getFullYear()===i.getFullYear()&&r.getMonth()===i.getMonth()&&r.getDate()===i.getDate()?a:`${r.getDate()} ${r.toLocaleString(`en-GB`,{month:`short`})} ${a}`}function L(e){return e===null||!Number.isFinite(e)?N:`${e.toFixed(1)}%`}function R(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 z(e){return e===null||!Number.isFinite(e)?N:`£${e.toFixed(2)}`}function B(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 V(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 H(e){return e.toISOString().slice(0,10)}function U(e){let t=e.getUTCFullYear(),n=e.getUTCMonth();return{from:H(new Date(Date.UTC(t,n,1))),to:H(new Date(Date.UTC(t,n+1,0)))}}function W(e,t){let n=new Date(`${e}T00:00:00.000Z`);return U(new Date(Date.UTC(n.getUTCFullYear(),n.getUTCMonth()+t,1)))}function G(e,t){return{from:H(new Date(t-(e-1)*864e5)),to:H(new Date(t))}}function K(e){return new Date(`${e}T00:00:00.000Z`).toLocaleString(`en-GB`,{month:`long`,year:`numeric`,timeZone:`UTC`})}function q(e){if(e===null)return!1;let t=U(new Date(`${e.from}T00:00:00.000Z`));return t.from===e.from&&t.to===e.to}function J(e,t,n){switch(e){case`title`:return t.title??t.sessionId.slice(0,8);case`model`:return t.model??N;case`status`:return t.status??N;case`activeMsInRange`:return B(t.activeMsInRange);case`ageMs`:return P(t.ageMs);case`lastMessageAt`:return I(t.lastMessageAt,n);case`turnCount`:return t.turnCount===null?N:`${t.turnCount}${t.turnCountCapped?`+`:``}`;case`rssKb`:return F(t.rssKb);case`cpuPct`:return L(t.cpuPct);case`tokensInRange`:return R(t.tokensInRange);case`costGbp`:return z(t.costGbp);default:return N}}function Y({adminFetch:e}){let[t,r]=(0,m.useState)(null),[i,a]=(0,m.useState)(null),[s,l]=(0,m.useState)(!1),[u,p]=(0,m.useState)(`lastMessageAt`),[g,_]=(0,m.useState)(-1),[v,y]=(0,m.useState)(()=>U(new Date)),[b,x]=(0,m.useState)(!0),[S,C]=(0,m.useState)(!0),[w,E]=(0,m.useState)(!1),F=(0,m.useRef)(!1),I=(0,m.useRef)(void 0),L=(0,m.useCallback)(async t=>{if(F.current){I.current=t;return}F.current=!0;try{let n=await e(`/api/admin/activity${t?`?from=${t.from}&to=${t.to}`:``}`);if(n.status===403){a(`This view is available to the house account only.`),l(!0);return}if(!n.ok){a(`The session manager did not answer (status ${n.status}).`),l(!0);return}r(await n.json()),a(null)}catch(e){a(e instanceof Error?e.message:String(e))}finally{l(!0),F.current=!1;let e=I.current;I.current=void 0,e!==void 0&&L(e)}},[e]);(0,m.useEffect)(()=>{L(v);let e=setInterval(()=>void L(v),15e3);return()=>clearInterval(e)},[L,v]);let R=(0,m.useMemo)(()=>t?[...t.rows].sort((e,t)=>V(e,t,u,g)):[],[t,u,g]),z=(0,m.useMemo)(()=>R.filter(e=>e.status===`busy`?b:e.status===`idle`?S:!0),[R,b,S]),B=R.length-z.length;if(!s)return(0,h.jsxs)(`div`,{className:`activity-loading`,children:[(0,h.jsx)(n,{size:18,className:`spin`}),` Loading…`]});if(i)return(0,h.jsx)(`div`,{className:`activity-empty`,children:i});if(!t)return(0,h.jsx)(`div`,{className:`activity-empty`,children:`No response.`});let{accounts:H,census:Y,censusAgeMs:X}=t,Z=Date.now(),Q=H.onDisk!==null&&H.onDisk>H.valid,$=t.range===void 0?v:t.range;return(0,h.jsxs)(`div`,{className:`activity-body`,children:[(0,h.jsxs)(`div`,{className:`activity-head`,children:[(0,h.jsxs)(`span`,{className:`activity-title`,children:[(0,h.jsx)(o,{size:16}),` Live sessions`]}),(0,h.jsxs)(`span`,{className:`activity-meta`,children:[B>0?`${z.length} of ${R.length} live · ${B} hidden`:`${R.length} live`,` · `,H.valid,` accounts`,H.untaggedCount>0?` · ${H.untaggedCount} untagged`:``]})]}),(0,h.jsxs)(`div`,{className:`activity-controls`,children:[(0,h.jsxs)(`div`,{className:`activity-control activity-range`,children:[(0,h.jsx)(c,{variant:`secondary`,size:`sm`,"aria-label":`Previous month`,disabled:!q(v),onClick:()=>y(e=>e&&W(e.from,-1)),children:`‹`}),(0,h.jsx)(`span`,{className:`activity-range-label`,children:v===null?`All time`:q(v)?K(v.from):`${v.from} → ${v.to}`}),(0,h.jsx)(c,{variant:`secondary`,size:`sm`,"aria-label":`Next month`,disabled:!q(v),onClick:()=>y(e=>e&&W(e.from,1)),children:`›`})]}),(0,h.jsxs)(`div`,{className:`activity-control activity-presets`,children:[(0,h.jsx)(c,{variant:`secondary`,size:`sm`,"aria-pressed":v!==null&&q(v)&&v.from===U(new Date).from,onClick:()=>y(U(new Date)),children:`This month`}),(0,h.jsx)(c,{variant:`secondary`,size:`sm`,"aria-pressed":v!==null&&!q(v),onClick:()=>y(G(7,Date.now())),children:`Last 7 days`}),(0,h.jsx)(c,{variant:`secondary`,size:`sm`,"aria-pressed":v===null,onClick:()=>y(null),children:`All time`})]}),(0,h.jsxs)(`div`,{className:`activity-control`,children:[(0,h.jsx)(`label`,{className:`activity-control-label`,htmlFor:`activity-sort`,children:`Sort by`}),(0,h.jsx)(`span`,{className:`activity-select-wrap`,children:(0,h.jsx)(`select`,{id:`activity-sort`,className:`activity-select`,value:u,onChange:e=>{let t=O.find(t=>t.key===e.target.value);t&&(p(t.key),_(t.dir))},children:O.map(e=>(0,h.jsx)(`option`,{value:e.key,children:e.label},e.key))})})]}),(0,h.jsxs)(`div`,{className:`activity-control activity-visibility`,children:[(0,h.jsx)(d,{checked:b,onChange:x,label:`Busy`}),(0,h.jsx)(d,{checked:S,onChange:C,label:`Idle`})]})]}),(0,h.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.`,t.fullRangeFallback&&(0,h.jsxs)(`strong`,{className:`activity-range-rejected`,children:[` `,`The range was not accepted, so these are all-time figures.`]})]}),(0,h.jsx)(`div`,{className:`activity-census`,children:Y===null?`No census collected yet, so memory and CPU are unavailable.`:`Memory and CPU measured ${P(X)} ago, averaged over the minute before that · ${Y.cpuNull} of ${Y.live} without a CPU reading`}),Q&&(0,h.jsxs)(`div`,{className:`activity-warning`,children:[(0,h.jsx)(f,{size:14}),` `,H.onDisk,` account folders on disk but only`,` `,H.valid,` are readable. Sessions belonging to the rest cannot be attributed.`]}),R.length===0?(0,h.jsx)(`div`,{className:`activity-empty`,children:`No sessions are running.`}):z.length===0?(0,h.jsxs)(`div`,{className:`activity-empty`,children:[`All `,R.length,` running sessions are hidden by the Busy and Idle filters.`]}):(0,h.jsx)(`div`,{className:`activity-grid`,children:z.map(e=>(0,h.jsxs)(`article`,{className:`activity-card`,"data-testid":`activity-card`,"data-session-id":e.sessionId,children:[(0,h.jsx)(`h3`,{className:`activity-card-heading`,title:e.accountId??void 0,children:e.accountId===null?(0,h.jsx)(`span`,{className:`activity-untagged`,title:`This session records no account, so it cannot be attributed to a business.`,children:`untagged`}):M(e.accountId,H.names)}),(0,h.jsx)(`dl`,{className:`activity-card-rows`,children:k.map(t=>(0,h.jsxs)(`div`,{className:`activity-card-row`,children:[(0,h.jsx)(`dt`,{className:`activity-card-label`,"data-testid":`activity-card-label`,title:t.help,children:t.label}),(0,h.jsx)(`dd`,{className:`activity-card-value`,title:t.key===`costGbp`?D(e):void 0,children:J(t.key,e,Z)})]},t.key))})]},e.sessionId))}),R.length>0&&(0,h.jsxs)(`div`,{className:`activity-glossary`,children:[(0,h.jsxs)(`dl`,{className:`activity-legend`,children:[w&&(0,h.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,h.jsx)(`dt`,{className:`activity-legend-term`,"data-testid":`activity-glossary-term`,children:j.label}),(0,h.jsx)(`dd`,{className:`activity-legend-def`,children:j.help})]},`heading`),(w?k:k.filter(e=>A.includes(e.key))).map(e=>(0,h.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,h.jsx)(`dt`,{className:`activity-legend-term`,"data-testid":`activity-glossary-term`,children:e.label}),(0,h.jsx)(`dd`,{className:`activity-legend-def`,children:e.help})]},e.key)),(0,h.jsxs)(`div`,{className:`activity-legend-item`,children:[(0,h.jsx)(`dt`,{className:`activity-legend-term`,children:N}),(0,h.jsxs)(`dd`,{className:`activity-legend-def`,children:[`Not measured. It does not mean zero — a measured zero is written as a figure, so `,(0,h.jsx)(`em`,{children:`0h 0m`}),` and `,(0,h.jsx)(`em`,{children:`£0.00`}),` are real readings. Hover a dashed value for the reason where one exists.`]})]})]}),(0,h.jsx)(c,{variant:`secondary`,size:`sm`,className:`activity-glossary-toggle`,onClick:()=>E(e=>!e),children:w?`Show fewer`:`Explain every figure`})]}),(0,h.jsx)(T,{loops:t?.loops})]})}function X({cacheKey:e}){let{adminFetch:t}=s({initialCacheKey:e,surface:`activity`});return(0,h.jsx)(Y,{adminFetch:t})}function Z(){let[e,t]=(0,m.useState)(null),[r,i]=(0,m.useState)(!1),[o,s]=(0,m.useState)(void 0),[c,d]=(0,m.useState)(null),[f,p]=(0,m.useState)(null),[g,_]=(0,m.useState)(null),[v,y]=(0,m.useState)(null);(0,m.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(E)}catch{}if(!n){t(null),i(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async r=>{if(!e){if(r.status===401){try{sessionStorage.removeItem(E)}catch{}window.location.href=`/`;return}if(r.ok)try{let e=await r.json();typeof e.businessName==`string`&&s(e.businessName),e.sessionId!==void 0&&d(e.sessionId??null),p(e.role??null),_(e.userName===void 0?null:e.userName),y(e.avatar??null)}catch{}t(n),i(!0)}}).catch(()=>{e||(t(n),i(!0))}),()=>{e=!0}},[]);let b=(0,m.useCallback)(()=>{try{sessionStorage.removeItem(E)}catch{}window.location.href=`/`},[]),[x,S]=(0,m.useState)(!1),C=(0,m.useCallback)(async()=>{S(!0);try{let e=await u();if(e){try{sessionStorage.removeItem(E)}catch{}window.location.href=`/`}return e}finally{S(!1)}},[]);return r?e?(0,h.jsx)(a,{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(E)}catch{}window.location.href=`/`},children:(0,h.jsx)(l,{cacheKey:e,businessName:o,sessionId:c,onLogout:b,onDisconnect:C,disconnecting:x,userName:g,userAvatar:v,role:f,children:(0,h.jsx)(X,{cacheKey:e})})}):(0,h.jsx)(`div`,{className:`activity-page`,children:(0,h.jsxs)(`div`,{className:`activity-empty`,children:[(0,h.jsx)(`p`,{children:`You are not signed in.`}),(0,h.jsxs)(`p`,{children:[`Open the `,(0,h.jsx)(`a`,{href:`/`,className:`activity-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,h.jsx)(`div`,{className:`activity-page`,children:(0,h.jsxs)(`div`,{className:`activity-loading`,children:[(0,h.jsx)(n,{size:18,className:`spin`}),` Loading…`]})})}(0,p.createRoot)(document.getElementById(`root`)).render((0,h.jsx)(Z,{}));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./chunk-TPjIAO9U.js";import{B as t,H as n,L as r,T as i,c as a,f as o,g as s,i as c,o as l,p as u}from"./useSubAccountSwitcher-sPN6lobE.js";import{n as d,t as f}from"./AdminLoginScreens-Jw45pvb2.js";import{S as p,s as m}from"./useVoiceRecorder-DOFBQ2gP.js";import{a as h,t as g}from"./AdminShell-DR6AzflZ.js";import"./Checkbox-D7_S2EUI.js";import{i as _,n as v,r as y}from"./page-DsV3rID5.js";import{t as b}from"./bot-GC7iZjtW.js";import{t as x}from"./chevron-down-BCLf1wKu.js";import{t as S}from"./chevron-right-Bu5hsjy5.js";import"./graph-labels-7p-mVi9M.js";var C=t(),w=e(n(),1),T=r();function E({onOpen:e}){return(0,T.jsx)(`footer`,{className:`admin-footer`,children:(0,T.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,T.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`powered-by-icon`}),(0,T.jsx)(`span`,{children:`Powered by Claude Code`})]})})}var D=6e4,O=60*D,k=24*O,A=D,j=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],M=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function N(e){return e<10?`0${e}`:String(e)}function P(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime()}function F(e,t){if(!Number.isFinite(e)||e<=0||!Number.isFinite(t))return`—`;let n=t-e;if(n<-A)return`—`;let r=n<0?0:n;if(r<D)return`just now`;if(r<O)return`${Math.floor(r/D)}m`;if(r<k)return`${Math.floor(r/O)}h`;let i=new Date(t),a=new Date(e),o=Math.round((P(i)-P(a))/k);if(o===1)return`yesterday`;if(o>=2&&o<=6)return M[a.getDay()];let s=N(a.getDate()),c=j[a.getMonth()];return a.getFullYear()===i.getFullYear()?`${s} ${c}`:`${s} ${c} ${a.getFullYear()}`}var I={whatsapp:`WhatsApp`,telegram:`Telegram`,webchat:`Web chat`};function L(e){return e<12?`morning`:e<18?`afternoon`:`evening`}function R(e){return e&&e.trim().split(/\s+/)[0]||`there`}function z(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){return e.operatorName??e.whatsappName??e.senderId??e.title}function H(e,t){if(!e)return!1;let n=Date.parse(e);if(!Number.isFinite(n))return!1;let r=new Date(n),i=new Date(t);return r.getFullYear()===i.getFullYear()&&r.getMonth()===i.getMonth()&&r.getDate()===i.getDate()}function U(e){return e?e.replace(/^claude-/,``):null}function W({cacheKey:e,userName:t,onSelectWhatsappConversation:n}){let r=u(e),[o,d]=(0,w.useState)(null),[f,m]=(0,w.useState)(null),[h,g]=(0,w.useState)(null),[_,v]=(0,w.useState)(null),[C,E]=(0,w.useState)(null),[D,O]=(0,w.useState)(null),[k,A]=(0,w.useState)(new Set),j=Date.now();(0,w.useEffect)(()=>{if(!e)return;let t=!1;async function n(e,n,i){try{let a=await r(e);if(!a.ok)throw Error(`status ${a.status}`);let o=await a.json();t||i(n(o))}catch(t){console.error(`[admin-ui] dashboard-fetch-failed url=${e} reason=${t instanceof Error?t.message:String(t)}`)}}return n(`/api/admin/sidebar-sessions`,e=>e.sessions??[],d),n(`/api/whatsapp-reader/conversations`,e=>e.conversations??[],m),n(`/api/admin/system-stats`,e=>e,v),n(`/api/admin/tasks-list`,e=>e,E),n(`/api/admin/sidebar-artefacts`,e=>e.artefacts??[],O),()=>{t=!0}},[e,r]);let M=(0,w.useMemo)(()=>(o??[]).filter(e=>!e.isSubagent),[o]),N=(0,w.useMemo)(()=>M.filter(e=>e.live),[M]),P=(0,w.useMemo)(()=>(f??[]).filter(e=>H(e.lastMessageAt,j)).length,[f,j]),W=C?.open.length??0,G=(0,w.useMemo)(()=>{let e=new Map;for(let t of f??[]){let n=e.get(t.channel)??[];n.push(t),e.set(t.channel,n)}return[...e.entries()].map(([e,t])=>{let n=t.reduce((e,t)=>t.lastMessageAt&&(!e||Date.parse(t.lastMessageAt)>Date.parse(e.lastMessageAt??``))?t:e,null);return{channel:e,count:t.length,preview:n?V(n):``,rows:t}})},[f]),K=(0,w.useCallback)(async e=>{if(!k.has(e)){A(t=>new Set(t).add(e));try{let t=await r(`/api/admin/session-stop`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e})});if(!t.ok){console.error(`[admin-ui] dashboard-session-stop-failed sessionId=${e} status=${t.status}`);return}console.info(`[admin-ui] dashboard-session-stop sessionId=${e}`),d(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{A(t=>{let n=new Set(t);return n.delete(e),n})}}},[r,k]),q=(0,w.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}y(e,t.downloadPath,t.downloadRoot??`data`)},[e]);return(0,T.jsxs)(`div`,{className:`dashboard-home`,children:[(0,T.jsx)(`p`,{className:`dashboard-greeting`,children:`Good ${L(new Date(j).getHours())}, ${R(t)} — ${z(_)}`}),(0,T.jsxs)(`div`,{className:`dashboard-stats`,children:[(0,T.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,T.jsx)(`span`,{className:`dashboard-stat-label`,children:`Live sessions`}),(0,T.jsx)(`span`,{className:`dashboard-stat-value`,children:N.length}),(0,T.jsxs)(`span`,{className:`dashboard-stat-delta`,children:[`of `,M.length,` total`]})]}),(0,T.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,T.jsx)(`span`,{className:`dashboard-stat-label`,children:`Messages today`}),(0,T.jsx)(`span`,{className:`dashboard-stat-value`,children:P})]}),(0,T.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,T.jsx)(`span`,{className:`dashboard-stat-label`,children:`Open tasks`}),(0,T.jsx)(`span`,{className:`dashboard-stat-value`,children:W})]}),(0,T.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,T.jsx)(`span`,{className:`dashboard-stat-label`,children:`Host CPU`}),(0,T.jsx)(`span`,{className:`dashboard-stat-value`,children:B(_?.cpuPct??null)}),(0,T.jsxs)(`span`,{className:`dashboard-stat-delta`,children:[`RAM `,B(_?.memUsedPct??null)]})]})]}),(0,T.jsxs)(`div`,{className:`dashboard-columns`,children:[(0,T.jsxs)(`div`,{className:`dashboard-col`,children:[(0,T.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Live now`}),N.length===0?(0,T.jsx)(`div`,{className:`admin-card dashboard-empty`,children:`No live sessions right now.`}):N.map(e=>{let t=[e.sessionId.slice(0,8),U(e.model),F(Date.parse(e.startedAt),j)].filter(Boolean).join(` · `);return(0,T.jsxs)(`div`,{className:`admin-card dashboard-live-card`,children:[(0,T.jsx)(`span`,{className:`admin-status-dot is-live`}),(0,T.jsxs)(`div`,{className:`dashboard-live-main`,children:[(0,T.jsx)(`span`,{className:`dashboard-live-name`,children:e.title}),(0,T.jsx)(`span`,{className:`dashboard-live-meta`,children:t})]}),(0,T.jsx)(`a`,{className:`admin-btn-cta dashboard-open-btn`,href:`/chat?session=${encodeURIComponent(e.sessionId)}`,children:`Open`}),(0,T.jsx)(`button`,{type:`button`,className:`dashboard-stop-btn`,"aria-label":`Stop ${e.title}`,disabled:k.has(e.sessionId),onClick:()=>void K(e.sessionId),children:(0,T.jsx)(s,{size:12})})]},e.sessionId)}),(0,T.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Recent artefacts`}),(0,T.jsx)(`div`,{className:`admin-card dashboard-artefacts`,children:(D??[]).length===0?(0,T.jsx)(`div`,{className:`dashboard-empty`,children:`No recent artefacts.`}):(D??[]).slice(0,6).map(e=>(0,T.jsxs)(`button`,{type:`button`,className:`admin-row dashboard-artefact-row`,onClick:()=>q(e),children:[(0,T.jsx)(`span`,{className:`dashboard-artefact-icon`,children:e.kind===`agent-template`?(0,T.jsx)(b,{size:16}):(0,T.jsx)(p,{size:16})}),(0,T.jsx)(`div`,{className:`dashboard-artefact-body`,children:(0,T.jsx)(`span`,{className:`dashboard-artefact-name`,children:e.name})}),(0,T.jsx)(`span`,{className:`dashboard-artefact-time`,children:F(Date.parse(e.updatedAt),j)})]},e.id))})]}),(0,T.jsxs)(`div`,{className:`dashboard-col`,children:[(0,T.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Channels`}),G.length===0?(0,T.jsx)(`div`,{className:`admin-card dashboard-empty`,children:`No channel activity.`}):G.map(e=>{let t=h===e.channel;return(0,T.jsxs)(`div`,{className:`admin-card dashboard-channel-card`,children:[(0,T.jsxs)(`button`,{type:`button`,className:`dashboard-channel-head`,"aria-expanded":t,onClick:()=>g(t=>t===e.channel?null:e.channel),children:[(0,T.jsx)(`span`,{className:`dashboard-channel-glyph`,children:e.channel===`whatsapp`||e.channel===`telegram`?(0,T.jsx)(a,{channel:e.channel,size:16}):(0,T.jsx)(i,{size:16})}),(0,T.jsx)(`span`,{className:`dashboard-channel-name`,children:I[e.channel]??e.channel}),(0,T.jsx)(`span`,{className:`dashboard-channel-badge`,children:e.count}),(0,T.jsx)(`span`,{className:`dashboard-channel-chevron`,children:t?(0,T.jsx)(x,{size:14}):(0,T.jsx)(S,{size:14})})]}),t?(0,T.jsx)(`div`,{className:`dashboard-channel-convs`,children:e.rows.map(e=>(0,T.jsxs)(`button`,{type:`button`,className:`admin-row dashboard-channel-conv-row`,onClick:()=>n(e),title:e.title,children:[(0,T.jsx)(`span`,{className:`dashboard-channel-conv-name`,children:c(e)}),e.lastMessageAt&&(0,T.jsx)(`span`,{className:`dashboard-channel-conv-time`,children:F(Date.parse(e.lastMessageAt),j)})]},l(e)))}):e.preview&&(0,T.jsx)(`span`,{className:`dashboard-channel-preview`,children:e.preview})]},e.channel)})]})]})]})}function G(){let e=d(),[t,n]=(0,w.useState)(!1);(0,w.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,w.useCallback)(async()=>{let t=e.claudeInfo!=null;if(n(!0),t){console.info(`[admin-ui] claude-info-open cached=true ms=0`);return}let r=Date.now();try{let t=await fetch(`/api/admin/claude-info`);if(t.ok){let n=await t.json();e.setClaudeInfo(n)}console.info(`[admin-ui] claude-info-open cached=false ms=${Date.now()-r}`)}catch(e){console.error(`[admin-ui] claude-info-fetch-failed ms=${Date.now()-r} error="${e instanceof Error?e.message:String(e)}"`)}},[e]),i=(0,w.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,T.jsx)(o,{cacheKey:e.cacheKey,onSessionExpired:i,surface:`chat`,children:(0,T.jsx)(g,{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,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(E,{onOpen:r}),(0,T.jsx)(h,{show:t,onClose:()=>n(!1),claudeInfo:e.claudeInfo,messages:[],sessionElapsed:0,sessionId:e.sessionId,cacheKey:e.cacheKey})]}),children:t=>(0,T.jsx)(T.Fragment,{children:t.dataOpen&&e.cacheKey?(0,T.jsx)(v,{cacheKey:e.cacheKey}):t.selectedWhatsapp&&e.cacheKey?t.selectedWhatsapp.source===`store`&&t.selectedWhatsapp.remoteJid&&t.selectedWhatsapp.accountId?(0,T.jsx)(_,{accountId:t.selectedWhatsapp.accountId,remoteJid:t.selectedWhatsapp.remoteJid,contactName:c(t.selectedWhatsapp),sessionKey:e.cacheKey},l(t.selectedWhatsapp)):(0,T.jsx)(m,{sessionId:t.selectedWhatsapp.sessionId,projectDir:t.selectedWhatsapp.projectDir,sessionKey:e.cacheKey,forceDeliveredOnly:!0},l(t.selectedWhatsapp)):(0,T.jsx)(W,{cacheKey:e.cacheKey,userName:e.userName,onSelectWhatsappConversation:t.onSelectWhatsappConversation})})})}):(0,T.jsx)(f,{auth:e})}(0,C.createRoot)(document.getElementById(`root`)).render((0,T.jsx)(G,{}));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./chunk-TPjIAO9U.js";import{B as t,C as n,D as r,E as i,H as a,L as o,M as s,b as c,f as l,h as u,m as d,z as f}from"./useSubAccountSwitcher-sPN6lobE.js";import{t as p,v as m}from"./AdminShell-DR6AzflZ.js";import{t as h}from"./chevron-left-BNtL-CjS.js";import{t as g}from"./chevron-right-Bu5hsjy5.js";var _=s(`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`}]]),v=s(`clock`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6l4 2`,key:`mmk7yg`}]]),y=s(`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`}]]),b=s(`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`}]]),x=s(`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`}]]),ee=s(`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`}]]),S=t(),C=e(a(),1);function w(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate())}function T(e,t){let n=new Date(e);return n.setDate(n.getDate()+t),n}function E(e){let t=w(e),n=t.getDay();return T(t,n===0?-6:1-n)}function D(e){let t=E(e);return Array.from({length:7},(e,n)=>T(t,n))}function O(e){let t=E(new Date(e.getFullYear(),e.getMonth(),1));return Array.from({length:42},(e,n)=>T(t,n))}function k(){return Array.from({length:24},(e,t)=>t)}function A(e){let t=e.getFullYear();return Array.from({length:12},(e,n)=>new Date(t,n,1))}function j(e,t){switch(e){case`day`:{let e=w(t);return{from:e,to:T(e,1)}}case`week`:{let e=E(t);return{from:e,to:T(e,7)}}case`month`:{let e=E(new Date(t.getFullYear(),t.getMonth(),1));return{from:e,to:T(e,42)}}case`year`:return{from:new Date(t.getFullYear(),0,1),to:new Date(t.getFullYear()+1,0,1)}}}function M(e,t,n){switch(e){case`day`:return T(t,n);case`week`:return T(t,n*7);case`month`:return new Date(t.getFullYear(),t.getMonth()+n,1);case`year`:return new Date(t.getFullYear()+n,t.getMonth(),1)}}function N(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function P(e,t){return{role:`button`,tabIndex:0,onClick:()=>t(e),onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),t(e))}}}var F=o(),I=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],L=3;function R(e){return e.toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`})}function z({anchor:e,meetings:t,onSelect:n}){let r=O(e),i=e.getMonth(),a=new Date;return(0,F.jsxs)(`div`,{className:`cal-month`,children:[(0,F.jsx)(`div`,{className:`cal-weekday-row`,children:I.map(e=>(0,F.jsx)(`div`,{className:`cal-weekday`,children:e},e))}),(0,F.jsx)(`div`,{className:`cal-month-grid`,children:r.map(e=>{let r=t.filter(t=>N(new Date(t.startsAt),e)).sort((e,t)=>e.startsAt.localeCompare(t.startsAt)),o=e.getMonth()!==i,s=N(e,a);return(0,F.jsxs)(`div`,{className:`cal-cell${o?` cal-cell-out`:``}${s?` cal-cell-today`:``}`,children:[(0,F.jsx)(`div`,{className:`cal-cell-num`,children:e.getDate()}),r.slice(0,L).map(e=>(0,F.jsxs)(`div`,{className:`cal-chip`,title:e.title??`Untitled`,...P(e,n),children:[!e.isAllDay&&(0,F.jsx)(`span`,{className:`cal-chip-time`,children:R(new Date(e.startsAt))}),e.title??`Untitled`]},e.meetingId)),r.length>L&&(0,F.jsxs)(`div`,{className:`cal-more`,children:[`+`,r.length-L,` more`]})]},e.toISOString())})})]})}var B=1440,V=1.8;function H(e){return e.getHours()*60+e.getMinutes()}function U(e){return e.toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`})}function W({day:e,meetings:t,hourHeight:n,onSelect:r}){let i=n*24,a=t.filter(t=>!t.isAllDay&&N(new Date(t.startsAt),e));return(0,F.jsx)(`div`,{className:`cal-day-col`,children:(0,F.jsxs)(`div`,{className:`cal-hours`,style:{height:`${i}px`},children:[Array.from({length:24},(e,t)=>(0,F.jsx)(`div`,{className:`cal-hour-line`,style:{top:`${t*n}px`}},t)),a.map(t=>{let n=new Date(t.startsAt),i=t.endsAt?new Date(t.endsAt):new Date(n.getTime()+30*6e4),a=H(n),o=N(i,e)?H(i):B,s=a/B*100,c=Math.max((o-a)/B*100,V);return(0,F.jsxs)(`div`,{className:`cal-event`,style:{top:`${s}%`,height:`${c}%`},title:t.title??`Untitled`,...P(t,r),children:[(0,F.jsx)(`span`,{className:`cal-event-time`,children:U(n)}),(0,F.jsx)(`span`,{className:`cal-event-title`,children:t.title??`Untitled`})]},t.meetingId)})]})})}var G=44;function K(e){let t=new Date;return t.setHours(e,0,0,0),t.toLocaleTimeString([],{hour:`numeric`})}function q({anchor:e,meetings:t,onSelect:n}){let r=D(e),i=new Date;return(0,F.jsxs)(`div`,{className:`cal-timed`,children:[(0,F.jsxs)(`div`,{className:`cal-day-headrow`,children:[(0,F.jsx)(`div`,{className:`cal-timed-gutter`}),r.map(e=>(0,F.jsxs)(`div`,{className:`cal-day-head${N(e,i)?` cal-day-head-today`:``}`,children:[(0,F.jsx)(`span`,{className:`cal-day-head-name`,children:e.toLocaleDateString([],{weekday:`short`})}),(0,F.jsx)(`span`,{className:`cal-day-head-num`,children:e.getDate()})]},e.toISOString()))]}),(0,F.jsxs)(`div`,{className:`cal-allday-band`,children:[(0,F.jsx)(`div`,{className:`cal-timed-gutter`,children:`All-day`}),r.map(e=>(0,F.jsx)(`div`,{className:`cal-allday-cell`,children:t.filter(t=>t.isAllDay&&N(new Date(t.startsAt),e)).map(e=>(0,F.jsx)(`div`,{className:`cal-allday-chip`,title:e.title??`Untitled`,...P(e,n),children:e.title??`Untitled`},e.meetingId))},e.toISOString()))]}),(0,F.jsxs)(`div`,{className:`cal-timed-cols`,children:[(0,F.jsx)(`div`,{className:`cal-timed-gutter`,children:k().map(e=>(0,F.jsx)(`div`,{className:`cal-hour-label`,style:{height:`${G}px`},children:e===0?``:K(e)},e))}),r.map(e=>(0,F.jsx)(W,{day:e,meetings:t,hourHeight:G,onSelect:n},e.toISOString()))]})]})}var J=52;function Y(e){let t=new Date;return t.setHours(e,0,0,0),t.toLocaleTimeString([],{hour:`numeric`})}function X({anchor:e,meetings:t,onSelect:n}){let r=t.filter(t=>t.isAllDay&&N(new Date(t.startsAt),e));return(0,F.jsxs)(`div`,{className:`cal-timed cal-timed-single`,children:[(0,F.jsxs)(`div`,{className:`cal-allday-band`,children:[(0,F.jsx)(`div`,{className:`cal-timed-gutter`,children:`All-day`}),(0,F.jsx)(`div`,{className:`cal-allday-cell`,children:r.map(e=>(0,F.jsx)(`div`,{className:`cal-allday-chip`,title:e.title??`Untitled`,...P(e,n),children:e.title??`Untitled`},e.meetingId))})]}),(0,F.jsxs)(`div`,{className:`cal-timed-cols`,children:[(0,F.jsx)(`div`,{className:`cal-timed-gutter`,children:k().map(e=>(0,F.jsx)(`div`,{className:`cal-hour-label`,style:{height:`${J}px`},children:e===0?``:Y(e)},e))}),(0,F.jsx)(W,{day:e,meetings:t,hourHeight:J,onSelect:n})]})]})}var Z=[`M`,`T`,`W`,`T`,`F`,`S`,`S`];function te(e){return`${e.getFullYear()}-${e.getMonth()}-${e.getDate()}`}function ne({anchor:e,meetings:t,onPickMonth:n}){let r=new Date,i=new Set(t.map(e=>te(new Date(e.startsAt))));return(0,F.jsx)(`div`,{className:`cal-year`,children:(0,F.jsx)(`div`,{className:`cal-year-grid`,children:A(e).map(e=>{let t=O(e),a=e.getMonth();return(0,F.jsxs)(`button`,{type:`button`,className:`cal-mini`,onClick:()=>n(e),title:e.toLocaleDateString([],{month:`long`,year:`numeric`}),children:[(0,F.jsx)(`div`,{className:`cal-mini-title`,children:e.toLocaleDateString([],{month:`long`})}),(0,F.jsx)(`div`,{className:`cal-mini-weekrow`,children:Z.map((e,t)=>(0,F.jsx)(`span`,{className:`cal-mini-weekday`,children:e},t))}),(0,F.jsx)(`div`,{className:`cal-mini-grid`,children:t.map(e=>{let t=e.getMonth()!==a,n=N(e,r),o=!t&&i.has(te(e));return(0,F.jsxs)(`span`,{className:`cal-mini-day${t?` cal-mini-day-out`:``}${n?` cal-mini-day-today`:``}`,children:[e.getDate(),o&&(0,F.jsx)(`span`,{className:`cal-mini-dot`})]},e.toISOString())})})]},a)})})})}var re={meeting:`Meeting`,event:`Event`,task:`Task`};function ie(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}T${n(t.getHours())}:${n(t.getMinutes())}`}function ae(e){return new Date(e).toISOString()}function Q(e){return Math.floor(new Date(e).getTime()/6e4)}function oe(e){let t=new Date(e.startsAt);if(e.isAllDay)return t.toLocaleDateString([],{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`});let n=t.toLocaleDateString([],{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`}),r=t.toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`});return e.endsAt?`${n} · ${r} – ${new Date(e.endsAt).toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`})}`:`${n} · ${r}`}function se(e){if(!e)return null;let t=e.match(/filename="([^"]+)"/);return t?t[1]:null}function ce(e,t){return e.email??`${e.name??`unknown`}-${t}`}function le({a:e}){let t=e.name||e.email||`Unknown`,n=e.name&&e.email?e.email:null;return(0,F.jsxs)(`span`,{className:`cal-attendee-lines`,children:[(0,F.jsx)(`span`,{className:`cal-attendee-name`,children:t}),n&&(0,F.jsx)(`span`,{className:`cal-attendee-email`,children:n})]})}function ue({meeting:e,adminFetch:t,onClose:i,onSaved:a,onDeleted:o}){let s=e.kind===`meeting`,[l,f]=(0,C.useState)(!1),[p,m]=(0,C.useState)(!1),[h,g]=(0,C.useState)(!1),[S,w]=(0,C.useState)(!1),[T,E]=(0,C.useState)(null),[D,O]=(0,C.useState)(e),[k,A]=(0,C.useState)(e.title??``),[j,M]=(0,C.useState)(ie(e.startsAt)),[N,P]=(0,C.useState)(e.endsAt?ie(e.endsAt):``),[I,L]=(0,C.useState)(e.location??``),[R,z]=(0,C.useState)(e.privateNote??``),[B,V]=(0,C.useState)(``),[H,U]=(0,C.useState)(``);(0,C.useEffect)(()=>{let e=e=>{e.key===`Escape`&&!S&&i()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[S,i]);let W=(0,C.useCallback)(()=>{let e={},t=k.trim();t!==(D.title??``)&&(e.title=t);let n=ae(j);Q(n)!==Q(D.startsAt)&&(e.startsAt=n);let r=N?ae(N):null;(r===null?D.endsAt!==null:D.endsAt===null||Q(r)!==Q(D.endsAt))&&(e.endsAt=r);let i=I.trim()||null;i!==(D.location??null)&&(e.location=i);let a=R.trim()||null;return a!==(D.privateNote??null)&&(e.privateNote=a),e},[k,j,N,I,R,D]),G=(0,C.useCallback)(async()=>{let n=W();if(Object.keys(n).length===0){f(!1);return}w(!0),E(null);try{let r=await t(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify(n)});if(!r.ok)throw Error(`HTTP ${r.status}`);let i=await r.json();O(i.meeting),a(i.meeting),f(!1)}catch(e){E(e instanceof Error?e.message:`Save failed`)}finally{w(!1)}},[t,W,e.meetingId,a]),K=(0,C.useCallback)(async()=>{let n=B.trim(),r=H.trim();if(!(!n&&!r)){w(!0),E(null);try{let i=await t(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}/attendees`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:n||void 0,email:r||void 0})});if(!i.ok)throw Error(`HTTP ${i.status}`);let o=await i.json();O(o.meeting),a(o.meeting),V(``),U(``)}catch(e){E(e instanceof Error?e.message:`Add failed`)}finally{w(!1)}}},[t,B,H,e.meetingId,a]),q=(0,C.useCallback)(async n=>{let r=n.email?{email:n.email}:{name:n.name};w(!0),E(null);try{let n=await t(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}/attendees`,{method:`DELETE`,headers:{"content-type":`application/json`},body:JSON.stringify(r)});if(!n.ok)throw Error(`HTTP ${n.status}`);let i=await n.json();O(i.meeting),a(i.meeting)}catch(e){E(e instanceof Error?e.message:`Remove failed`)}finally{w(!1)}},[t,e.meetingId,a]),J=(0,C.useCallback)(async()=>{w(!0),E(null);try{let n=await t(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}`,{method:`DELETE`});if(!n.ok)throw Error(`HTTP ${n.status}`);o(e.meetingId)}catch(e){E(e instanceof Error?e.message:`Delete failed`),w(!1)}},[t,e.meetingId,o]),Y=(0,C.useCallback)(async n=>{g(!1),w(!0),E(null);try{let r=await t(`/api/admin/calendar/meetings/${encodeURIComponent(e.meetingId)}/ics?attendees=${n?`1`:`0`}`);if(!r.ok)throw Error(`HTTP ${r.status}`);let i=await r.blob(),a=se(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){E(e instanceof Error?e.message:`Download failed`)}finally{w(!1)}},[t,e.meetingId]),X=re[e.kind??`meeting`],Z=B.trim().length>0||H.trim().length>0;return(0,F.jsx)(`div`,{className:`cal-modal-overlay`,onClick:()=>{S||i()},children:(0,F.jsxs)(`div`,{className:`cal-modal`,role:`dialog`,"aria-modal":`true`,"aria-label":l?`Edit meeting`:`Meeting detail`,onClick:e=>e.stopPropagation(),children:[(0,F.jsxs)(`div`,{className:`cal-modal-header`,children:[(0,F.jsx)(`span`,{className:`cal-modal-kind`,children:X}),(0,F.jsx)(`button`,{type:`button`,className:`cal-modal-close`,onClick:i,"aria-label":`Close`,autoFocus:!0,disabled:S,children:(0,F.jsx)(d,{size:16})})]}),!l&&(0,F.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,F.jsx)(`div`,{className:`cal-modal-title`,children:D.title??`Untitled`}),(0,F.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,F.jsx)(v,{size:14}),(0,F.jsx)(`span`,{children:oe(D)})]}),D.location&&(0,F.jsxs)(`div`,{className:`cal-modal-row`,children:[(0,F.jsx)(y,{size:14}),(0,F.jsx)(`span`,{children:D.location})]}),D.attendees.length>0&&(0,F.jsxs)(`div`,{className:`cal-modal-row cal-modal-row-top`,children:[(0,F.jsx)(ee,{size:14}),(0,F.jsx)(`div`,{className:`cal-modal-attendees`,children:D.attendees.map((e,t)=>(0,F.jsx)(`div`,{className:`cal-attendee-row`,children:(0,F.jsx)(le,{a:e})},ce(e,t)))})]}),D.privateNote&&(0,F.jsxs)(`div`,{className:`cal-modal-row cal-modal-row-top`,children:[(0,F.jsx)(b,{size:14}),(0,F.jsx)(`span`,{className:`cal-modal-note`,children:D.privateNote})]}),(0,F.jsxs)(`div`,{className:`cal-modal-row cal-modal-meta`,children:[(0,F.jsx)(_,{size:14}),(0,F.jsx)(`span`,{children:X})]})]}),l&&(0,F.jsxs)(`div`,{className:`cal-modal-body`,children:[(0,F.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,F.jsx)(`span`,{children:`Title`}),(0,F.jsx)(`input`,{type:`text`,value:k,onChange:e=>A(e.target.value),disabled:S})]}),(0,F.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,F.jsx)(`span`,{children:`Start`}),(0,F.jsx)(`input`,{type:`datetime-local`,value:j,onChange:e=>M(e.target.value),disabled:S})]}),(0,F.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,F.jsx)(`span`,{children:`End`}),(0,F.jsx)(`input`,{type:`datetime-local`,value:N,onChange:e=>P(e.target.value),disabled:S})]}),(0,F.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,F.jsx)(`span`,{children:`Location`}),(0,F.jsx)(`input`,{type:`text`,value:I,onChange:e=>L(e.target.value),disabled:S})]}),(0,F.jsxs)(`div`,{className:`cal-modal-field`,children:[(0,F.jsx)(`span`,{children:`Attendees`}),(0,F.jsxs)(`div`,{className:`cal-modal-attendees cal-modal-attendees-edit`,children:[D.attendees.length===0&&(0,F.jsx)(`div`,{className:`cal-attendee-empty`,children:`No attendees yet.`}),D.attendees.map((e,t)=>(0,F.jsxs)(`div`,{className:`cal-attendee-row cal-attendee-row-edit`,children:[(0,F.jsx)(le,{a:e}),(0,F.jsx)(`button`,{type:`button`,className:`cal-attendee-remove`,onClick:()=>q(e),disabled:S,"aria-label":`Remove ${e.name||e.email||`attendee`}`,children:(0,F.jsx)(d,{size:13})})]},ce(e,t)))]}),(0,F.jsxs)(`div`,{className:`cal-attendee-add`,children:[(0,F.jsx)(`input`,{type:`text`,placeholder:`Name`,value:B,onChange:e=>V(e.target.value),disabled:S,"aria-label":`Attendee name`}),(0,F.jsx)(`input`,{type:`email`,placeholder:`Email`,value:H,onChange:e=>U(e.target.value),disabled:S,"aria-label":`Attendee email`}),(0,F.jsx)(`button`,{type:`button`,className:`cal-modal-btn cal-attendee-add-btn`,onClick:K,disabled:S||!Z,"aria-label":`Add attendee`,children:S?(0,F.jsx)(n,{size:13,className:`spin`}):(0,F.jsx)(x,{size:13})})]})]}),(0,F.jsxs)(`label`,{className:`cal-modal-field`,children:[(0,F.jsx)(`span`,{children:`Private note`}),(0,F.jsx)(`textarea`,{className:`cal-modal-textarea`,value:R,onChange:e=>z(e.target.value),disabled:S,rows:3,placeholder:`Only you and your team can see this.`})]})]}),T&&(0,F.jsx)(`div`,{className:`cal-modal-error`,children:T}),s&&(0,F.jsxs)(`div`,{className:`cal-modal-actions`,children:[!l&&!p&&!h&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>f(!0),disabled:S,children:[(0,F.jsx)(c,{size:14}),` Edit`]}),(0,F.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:()=>m(!0),disabled:S,children:[(0,F.jsx)(u,{size:14}),` Delete`]}),(0,F.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-download`,onClick:()=>{D.attendees.length>0?g(!0):Y(!1)},disabled:S,children:[S?(0,F.jsx)(n,{size:14,className:`spin`}):(0,F.jsx)(r,{size:14}),` Download`]})]}),h&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Include attendees in the file?`}),(0,F.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-primary`,onClick:()=>Y(!0),disabled:S,children:[S?(0,F.jsx)(n,{size:14,className:`spin`}):null,` Yes`]}),(0,F.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>Y(!1),disabled:S,children:`No`}),(0,F.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>g(!1),disabled:S,children:`Cancel`})]}),l&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-primary`,onClick:G,disabled:S,children:[S?(0,F.jsx)(n,{size:14,className:`spin`}):null,` Save`]}),(0,F.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>{f(!1),E(null)},disabled:S,children:`Cancel`})]}),p&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`span`,{className:`cal-modal-confirm-text`,children:`Delete this meeting?`}),(0,F.jsxs)(`button`,{type:`button`,className:`cal-modal-btn cal-modal-btn-danger`,onClick:J,disabled:S,children:[S?(0,F.jsx)(n,{size:14,className:`spin`}):null,` Delete`]}),(0,F.jsx)(`button`,{type:`button`,className:`cal-modal-btn`,onClick:()=>m(!1),disabled:S,children:`Cancel`})]})]})]})})}var $=`maxy-admin-session-key`,de=[`day`,`week`,`month`,`year`];function fe(e,t){switch(e){case`day`:return t.toLocaleDateString([],{weekday:`long`,day:`numeric`,month:`long`,year:`numeric`});case`week`:{let{from:e,to:n}=j(`week`,t),r=new Date(n.getTime()-1);return`${e.toLocaleDateString([],{day:`numeric`,month:`short`})} – ${r.toLocaleDateString([],{day:`numeric`,month:`short`,year:`numeric`})}`}case`month`:return t.toLocaleDateString([],{month:`long`,year:`numeric`});case`year`:return String(t.getFullYear())}}function pe(){let[e,t]=(0,C.useState)(null),[r,i]=(0,C.useState)(!1),[a,o]=(0,C.useState)(void 0),[s,c]=(0,C.useState)(null),[u,d]=(0,C.useState)(void 0),[f,h]=(0,C.useState)(null),[g,_]=(0,C.useState)(null);(0,C.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem($)}catch{}if(!n){i(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async r=>{if(!e){if(r.status===401){try{sessionStorage.removeItem($)}catch{}window.location.href=`/`;return}if(r.ok)try{let e=await r.json();typeof e.businessName==`string`&&o(e.businessName),e.sessionId!==void 0&&c(e.sessionId??null),_(e.role??null),d(e.userName===void 0?null:e.userName),h(e.avatar??null)}catch{}t(n),i(!0)}}).catch(()=>{e||(t(n),i(!0))}),()=>{e=!0}},[]);let v=(0,C.useCallback)(()=>{try{sessionStorage.removeItem($)}catch{}window.location.href=`/`},[]),[y,b]=(0,C.useState)(!1),x=(0,C.useCallback)(async()=>{b(!0);try{let e=await m();if(e){try{sessionStorage.removeItem($)}catch{}window.location.href=`/`}return e}finally{b(!1)}},[]);return r?e?(0,F.jsx)(l,{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,F.jsx)(p,{cacheKey:e,businessName:a,sessionId:s,onLogout:v,onDisconnect:x,disconnecting:y,userName:u,userAvatar:f,role:g,children:(0,F.jsx)(me,{cacheKey:e})})}):(0,F.jsx)(`div`,{className:`cal-page`,children:(0,F.jsxs)(`div`,{className:`cal-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:`cal-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,F.jsx)(`div`,{className:`cal-page`,children:(0,F.jsxs)(`div`,{className:`cal-loading`,children:[(0,F.jsx)(n,{size:18,className:`spin`}),` Loading…`]})})}function me({cacheKey:e}){let{adminFetch:t,sessionRefetchNonce:r}=f({initialCacheKey:e,surface:`calendar`}),[a,o]=(0,C.useState)(`month`),[s,c]=(0,C.useState)(()=>new Date),[l,u]=(0,C.useState)([]),[d,p]=(0,C.useState)(!1),[m,_]=(0,C.useState)(null),[v,y]=(0,C.useState)(null),[b,x]=(0,C.useState)(null);(0,C.useEffect)(()=>{let e=!1;return t(`/api/admin/calendar/booking-link`).then(async t=>{if(e||!t.ok)return;let n=await t.json();typeof n.bookingDomain==`string`&&n.bookingDomain&&x(n.bookingDomain)}).catch(()=>{}),()=>{e=!0}},[t]),(0,C.useEffect)(()=>{let e=!1,{from:n,to:r}=j(a,s);return p(!0),_(null),t(`/api/admin/calendar/meetings?from=${encodeURIComponent(n.toISOString())}&to=${encodeURIComponent(r.toISOString())}`).then(async t=>{if(e)return;if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();u(Array.isArray(n.meetings)?n.meetings:[])}).catch(t=>{e||(_(t instanceof Error?t.message:`Failed to load`),u([]))}).finally(()=>{e||p(!1)}),()=>{e=!0}},[a,s,r,t]);let ee=(0,C.useCallback)(()=>c(new Date),[]),S=(0,C.useCallback)(()=>c(e=>M(a,e,-1)),[a]),w=(0,C.useCallback)(()=>c(e=>M(a,e,1)),[a]),T=(0,C.useCallback)(e=>{c(e),o(`month`)},[]);(0,C.useEffect)(()=>{y(null)},[a,s]);let E=(0,C.useCallback)(e=>{u(t=>t.map(t=>t.meetingId===e.meetingId?e:t)),y(e)},[]),D=(0,C.useCallback)(e=>{u(t=>t.filter(t=>t.meetingId!==e)),y(null)},[]);return(0,F.jsxs)(`div`,{className:`cal-page`,children:[(0,F.jsxs)(`header`,{className:`cal-header`,children:[(0,F.jsxs)(`div`,{className:`cal-nav`,children:[(0,F.jsx)(`span`,{className:`cal-range-label`,children:fe(a,s)}),(0,F.jsx)(`button`,{type:`button`,className:`cal-nav-btn`,onClick:S,"aria-label":`Previous`,children:(0,F.jsx)(h,{size:18})}),(0,F.jsx)(`button`,{type:`button`,className:`cal-nav-btn`,onClick:w,"aria-label":`Next`,children:(0,F.jsx)(g,{size:18})}),(0,F.jsx)(`button`,{type:`button`,className:`cal-today-btn`,onClick:ee,children:`Today`}),d&&(0,F.jsx)(n,{size:16,className:`spin`})]}),(0,F.jsx)(`div`,{className:`cal-views`,children:de.map(e=>(0,F.jsx)(`button`,{type:`button`,className:`cal-view-btn${e===a?` cal-view-btn-active`:``}`,onClick:()=>o(e),children:e.charAt(0).toUpperCase()+e.slice(1)},e))}),b&&(0,F.jsxs)(`a`,{className:`cal-booking-link`,href:`https://${b}`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,F.jsx)(i,{size:14}),` Booking page`]})]}),(0,F.jsxs)(`div`,{className:`cal-body`,children:[m&&(0,F.jsxs)(`div`,{className:`cal-error`,children:[`Could not load the calendar: `,m]}),a===`day`&&(0,F.jsx)(X,{anchor:s,meetings:l,onSelect:y}),a===`week`&&(0,F.jsx)(q,{anchor:s,meetings:l,onSelect:y}),a===`month`&&(0,F.jsx)(z,{anchor:s,meetings:l,onSelect:y}),a===`year`&&(0,F.jsx)(ne,{anchor:s,meetings:l,onPickMonth:T})]}),v&&(0,F.jsx)(ue,{meeting:v,adminFetch:t,onClose:()=>y(null),onSaved:E,onDeleted:D})]})}(0,S.createRoot)(document.getElementById(`root`)).render((0,F.jsx)(pe,{}));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{B as e,L as t}from"./useSubAccountSwitcher-sPN6lobE.js";import"./useVoiceRecorder-DOFBQ2gP.js";import"./AdminShell-DR6AzflZ.js";import{n}from"./page-DPQS0X5M.js";import"./useCopyFeedback-CfbJc9iN.js";var r=e(),i=t();(0,r.createRoot)(document.getElementById(`root`)).render((0,i.jsx)(n,{}));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{M as e}from"./useSubAccountSwitcher-sPN6lobE.js";var t=e(`chevron-down`,[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]);export{t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{M as e}from"./useSubAccountSwitcher-sPN6lobE.js";var t=e(`chevron-left`,[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]);export{t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{M as e}from"./useSubAccountSwitcher-sPN6lobE.js";var t=e(`chevron-right`,[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]);export{t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{B as e,L as t}from"./useSubAccountSwitcher-sPN6lobE.js";import"./useVoiceRecorder-DOFBQ2gP.js";import{t as n}from"./page-DsV3rID5.js";import"./graph-labels-7p-mVi9M.js";var r=e(),i=t();(0,r.createRoot)(document.getElementById(`root`)).render((0,i.jsx)(n,{}));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./chunk-TPjIAO9U.js";import{B as t,H as n,L as r}from"./useSubAccountSwitcher-sPN6lobE.js";import{n as i,t as a}from"./AdminLoginScreens-Jw45pvb2.js";import"./useVoiceRecorder-DOFBQ2gP.js";import"./AdminShell-DR6AzflZ.js";import"./Checkbox-D7_S2EUI.js";import{t as o}from"./page-DPQS0X5M.js";import"./useCopyFeedback-CfbJc9iN.js";var s=t(),c=e(n(),1),l=r();function u(){let e=i(`operator`),t=(0,c.useRef)(null);return(0,c.useEffect)(()=>{e.appState!==`chat`&&t.current!==e.appState&&(t.current=e.appState,console.info(`[operator-ui] op=auth-gate state=${e.appState}`))},[e.appState]),e.appState===`chat`?(0,l.jsx)(o,{variant:`operator`,forceCanonicalSession:window.location.pathname!==`/chat`}):(0,l.jsx)(a,{auth:e})}(0,s.createRoot)(document.getElementById(`root`)).render((0,l.jsx)(u,{}));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./chunk-TPjIAO9U.js";import{C as t,D as n,H as r,L as i,M as a,_ as o,b as s,f as c,g as l,h as u,i as d,l as f,m as p,o as m,r as h,s as g,t as ee,u as _,v as te,y as ne,z as v}from"./useSubAccountSwitcher-sPN6lobE.js";import{C as y,E as b,S as re,T as x,n as ie,r as S,s as C,x as ae}from"./useVoiceRecorder-DOFBQ2gP.js";import{t as w}from"./chevron-left-BNtL-CjS.js";import{i as oe,t as T}from"./graph-labels-7p-mVi9M.js";import{t as E}from"./triangle-alert-BDtoi5R0.js";var D=a(`arrow-left`,[[`path`,{d:`m12 19-7-7 7-7`,key:`1l729n`}],[`path`,{d:`M19 12H5`,key:`x3x0zl`}]]),se=a(`ellipsis`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`19`,cy:`12`,r:`1`,key:`1wjl8i`}],[`circle`,{cx:`5`,cy:`12`,r:`1`,key:`1pcz8c`}]]),ce=a(`folder-plus`,[[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`M9 13h6`,key:`1uhe8q`}],[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]),O=a(`folder`,[[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]),le=a(`image`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]),ue=a(`layout-grid`,[[`rect`,{width:`7`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`1g98yp`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`3`,rx:`1`,key:`6d4xhi`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`14`,rx:`1`,key:`nxv5o0`}],[`rect`,{width:`7`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`1bb6yr`}]]),de=a(`list`,[[`path`,{d:`M3 5h.01`,key:`18ugdj`}],[`path`,{d:`M3 12h.01`,key:`nlz23k`}],[`path`,{d:`M3 19h.01`,key:`noohij`}],[`path`,{d:`M8 5h13`,key:`1pao27`}],[`path`,{d:`M8 12h13`,key:`1za7za`}],[`path`,{d:`M8 19h13`,key:`m83p4d`}]]),fe=a(`mouse-pointer-click`,[[`path`,{d:`M14 4.1 12 6`,key:`ita8i4`}],[`path`,{d:`m5.1 8-2.9-.8`,key:`1go3kf`}],[`path`,{d:`m6 12-1.9 2`,key:`mnht97`}],[`path`,{d:`M7.2 2.2 8 5.1`,key:`1cfko1`}],[`path`,{d:`M9.037 9.69a.498.498 0 0 1 .653-.653l11 4.5a.5.5 0 0 1-.074.949l-4.349 1.041a1 1 0 0 0-.74.739l-1.04 4.35a.5.5 0 0 1-.95.074z`,key:`s0h3yz`}]]),k=a(`send-horizontal`,[[`path`,{d:`M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z`,key:`117uat`}],[`path`,{d:`M6 12h16`,key:`s4cdu5`}]]),pe=a(`smile`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M8 14s1.5 2 4 2 4-2 4-2`,key:`1y1vjs`}],[`line`,{x1:`9`,x2:`9.01`,y1:`9`,y2:`9`,key:`yxxnd0`}],[`line`,{x1:`15`,x2:`15.01`,y1:`9`,y2:`9`,key:`1p4y9e`}]]),me=a(`upload`,[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]),A=a(`user`,[[`path`,{d:`M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2`,key:`975kel`}],[`circle`,{cx:`12`,cy:`7`,r:`4`,key:`17ys0d`}]]),j=e(r(),1);function he(){let[e,t]=(0,j.useState)([]),[n,r]=(0,j.useState)(!1),[i,a]=(0,j.useState)(null),o=(0,j.useRef)(null),s=(0,j.useCallback)(e=>{a(null);let n=e.find(e=>!S(e.type,b));if(n){a(`Unsupported file type: "${n.type}". Supported: images, PDF, plain text, markdown, CSV, calendar, zip, voice notes.`);return}let r=e.find(e=>e.size>x);if(r){a(`"${r.name}" exceeds the 50 MB limit.`);return}t(t=>[...t,...e].slice(0,5))},[]);return{pendingFiles:e,setPendingFiles:t,isDragOver:n,attachError:i,setAttachError:a,fileInputRef:o,addFiles:s,clearFiles:(0,j.useCallback)(()=>{t([]),a(null)},[]),removeFile:(0,j.useCallback)(e=>{t(t=>t.filter((t,n)=>n!==e))},[]),onDragOver:(0,j.useCallback)(e=>{e.preventDefault(),r(!0)},[]),onDragLeave:(0,j.useCallback)(()=>{r(!1)},[]),onDrop:(0,j.useCallback)(e=>{e.preventDefault(),r(!1),s([...e.dataTransfer.files])},[s])}}var M=[[128512],[128515],[128516],[128513],[128518],[128517],[128514],[129315],[128578],[128579],[128521],[128522],[128519],[128525],[128536],[128535],[128540],[128541],[129303],[129300],[128528],[128566],[128564],[128526],[129395],[128546],[128557],[128548],[128544],[128533],[128556],[129393],[128077],[128078],[128076],[128591],[128079],[128588],[128170],[128075],[129309],[10084,65039],[128293],[11088],[127881],[10024],[128175],[128064]].map(e=>String.fromCodePoint(...e));function ge(e,t,n,r){let i=e.length,a=Math.max(0,Math.min(n??i,i)),o=Math.max(a,Math.min(r??a,i));return{value:e.slice(0,a)+t+e.slice(o),caret:a+t.length}}var N=i();function P({onSelect:e}){return(0,N.jsx)(`div`,{className:`wa-emoji-popover`,role:`menu`,"aria-label":`Emoji picker`,children:M.map((t,n)=>(0,N.jsx)(`button`,{type:`button`,role:`menuitem`,className:`wa-emoji-item`,onClick:()=>e(t),children:t},n))})}function _e({sessionKey:e,onPick:t,onClose:n}){let[r,i]=(0,j.useState)(``),[a,o]=(0,j.useState)(null),[s,c]=(0,j.useState)(null),[l,u]=(0,j.useState)(!1),d=(0,j.useCallback)(t=>{u(!0),c(null),fetch(`/api/admin/files?path=${encodeURIComponent(t)}&session_key=${encodeURIComponent(e)}`).then(async e=>{let t=await e.json().catch(()=>({}));if(!e.ok)throw Error(t.error??`Could not list files`);return t}).then(e=>{o(e),i(e.path===`.`?``:e.path)}).catch(e=>c(e instanceof Error?e.message:String(e))).finally(()=>u(!1))},[e]);(0,j.useEffect)(()=>{d(``)},[d]);let f=e=>d(r?`${r}/${e}`:e),m=()=>{let e=r.split(`/`).filter(Boolean);e.pop(),d(e.join(`/`))},h=e=>{let n=e.entryPath??e.name;t({path:r?`${r}/${n}`:n,name:e.displayName??e.name})};return(0,N.jsx)(`div`,{className:`wa-picker-backdrop`,role:`dialog`,"aria-label":`Choose a device file`,onClick:n,children:(0,N.jsxs)(`div`,{className:`wa-picker`,onClick:e=>e.stopPropagation(),children:[(0,N.jsxs)(`div`,{className:`wa-picker-head`,children:[r&&(0,N.jsx)(`button`,{type:`button`,className:`wa-picker-icon-btn`,onClick:m,"aria-label":`Up one folder`,children:(0,N.jsx)(w,{size:18})}),(0,N.jsx)(`span`,{className:`wa-picker-title`,children:r||`Device storage`}),(0,N.jsx)(`button`,{type:`button`,className:`wa-picker-icon-btn`,onClick:n,"aria-label":`Close file picker`,children:(0,N.jsx)(p,{size:18})})]}),s&&(0,N.jsx)(`p`,{className:`wa-picker-error`,role:`alert`,children:s}),l&&(0,N.jsx)(`p`,{className:`wa-picker-empty`,children:`Loading…`}),a&&!l&&(0,N.jsxs)(`ul`,{className:`wa-picker-list`,children:[a.entries.length===0&&(0,N.jsx)(`li`,{className:`wa-picker-empty`,children:`This folder is empty.`}),a.entries.map(e=>(0,N.jsx)(`li`,{children:e.kind===`directory`?(0,N.jsxs)(`button`,{type:`button`,className:`wa-picker-row`,onClick:()=>f(e.name),children:[(0,N.jsx)(O,{size:16,"aria-hidden":!0}),(0,N.jsx)(`span`,{className:`wa-picker-name`,children:e.displayName??e.name})]}):e.kind===`file`?(0,N.jsxs)(`button`,{type:`button`,className:`wa-picker-row`,onClick:()=>h(e),children:[(0,N.jsx)(re,{size:16,"aria-hidden":!0}),(0,N.jsx)(`span`,{className:`wa-picker-name`,children:e.displayName??e.name})]}):null},e.name))]})]})})}function ve(e){return`${Math.floor(e/60)}:${String(e%60).padStart(2,`0`)}`}function F({accountId:e,remoteJid:t,sessionKey:n,replyTo:r,onClearReply:i}){let[a,o]=(0,j.useState)(``),[s,c]=(0,j.useState)(!1),[d,f]=(0,j.useState)(null),[m,h]=(0,j.useState)(!1),[g,ee]=(0,j.useState)(!1),[_,te]=(0,j.useState)(!1),[v,b]=(0,j.useState)([]),x=(0,j.useRef)(null),{pendingFiles:S,attachError:C,addFiles:w,removeFile:oe,clearFiles:T}=he(),{state:E,elapsedSeconds:D,errorMessage:se,start:ce,send:O,discard:ue}=ie(),de=E===`recording`||E===`paused`,fe=(0,j.useCallback)(()=>{console.info(`[operator-ui] op=voice-record state=start ms=0`),ce()},[ce]),me=(0,j.useCallback)(async()=>{let e=D*1e3,t=await O();if(console.info(`[operator-ui] op=voice-record state=stop ms=${e}`),t){let e=t.type===`audio/ogg`?`.ogg`:t.type===`audio/mp4`?`.m4a`:`.webm`;w([new File([t],`voice-note${e}`,{type:t.type})])}},[D,O,w]),A=(0,j.useCallback)(()=>{console.info(`[operator-ui] op=voice-record state=cancel ms=${D*1e3}`),ue()},[D,ue]),M=(0,j.useRef)(!1),F=()=>Math.round((typeof window>`u`?900:window.innerHeight)/3),[I,ye]=(0,j.useState)(null),[be,xe]=(0,j.useState)(null),L=(0,j.useRef)(null),R=(0,j.useRef)(44),z=(0,j.useCallback)(e=>{let t=L.current;if(!t)return;t.moved=!0;let n=Math.min(F(),Math.max(44,t.startH+(t.startY-e.clientY)));R.current=n,ye(n)},[]),B=(0,j.useCallback)(()=>{let e=L.current?.moved??!1;L.current=null,window.removeEventListener(`pointermove`,z),window.removeEventListener(`pointerup`,B),e&&console.info(`[operator-ui] op=wa-composer-resize mode=drag h=${R.current}`)},[z]),Se=(0,j.useCallback)(e=>{L.current={startY:e.clientY,startH:x.current?.offsetHeight??44,moved:!1},window.addEventListener(`pointermove`,z),window.addEventListener(`pointerup`,B),e.preventDefault()},[z,B]),V=(0,j.useCallback)(e=>{let t=I??x.current?.offsetHeight??44,n=null;e.key===`ArrowUp`?(e.preventDefault(),n=Math.min(F(),t+24)):e.key===`ArrowDown`&&(e.preventDefault(),n=Math.max(44,t-24)),n!==null&&(ye(n),console.info(`[operator-ui] op=wa-composer-resize mode=key h=${n}`))},[I]),Ce=(0,j.useRef)(``);(0,j.useEffect)(()=>{let e=x.current;if(!e)return;let t=Ce.current!==``&&a===``;if(Ce.current=a,I!==null){t&&ye(null);return}let n=e.style.height;e.style.height=`auto`;let r=Math.min(F(),Math.max(44,e.scrollHeight));e.style.height=n,xe(r)},[a,I]);let we=(a.trim().length>0||S.length>0||v.length>0)&&!s,Te=(0,j.useCallback)(async()=>{if(!M.current&&!(a.trim().length===0&&S.length===0&&v.length===0)){M.current=!0,c(!0),f(null);try{let s=`/api/whatsapp-reader/reply?session_key=${encodeURIComponent(n)}`,c;if(S.length>0||v.length>0){let n=new FormData;n.append(`accountId`,e),n.append(`remoteJid`,t),a.trim()&&n.append(`text`,a);for(let e of S)n.append(`files`,e);for(let e of v)n.append(`fileRefs`,e.path);r&&n.append(`quotedId`,r.msgKeyId),c=await fetch(s,{method:`POST`,body:n})}else c=await fetch(s,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({accountId:e,remoteJid:t,text:a,...r?{quotedId:r.msgKeyId}:{}})});let l=await c.json().catch(()=>({}));if(!c.ok){f(l.error??`Send failed.`),console.info(`[operator-ui] op=reply-fail remoteJid=${t} error=${l.error??`unknown`}`);return}o(``),T(),b([]),i?.(),console.info(`[operator-ui] op=reply-sent remoteJid=${t} sent=${l.sent??0}`)}catch(e){f(`Could not reach the server. Try again.`),console.info(`[operator-ui] op=reply-fail remoteJid=${t} error=${String(e)}`)}finally{M.current=!1,c(!1)}}},[a,S,v,r,i,e,t,n,T]),Ee=(0,j.useCallback)(e=>{let t=x.current,{value:n,caret:r}=ge(a,e,t?t.selectionStart:null,t?t.selectionEnd:null);o(n),h(!1),requestAnimationFrame(()=>{let e=x.current;e&&(e.focus(),e.setSelectionRange(r,r))})},[a]),De=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),we&&Te())},H=e=>e.dataTransfer.types.includes(`Files`),Oe=(0,j.useCallback)(e=>{H(e)&&(e.preventDefault(),te(!0))},[]),ke=(0,j.useCallback)(()=>te(!1),[]),Ae=(0,j.useCallback)(e=>{if(!H(e))return;e.preventDefault(),te(!1);let t=[...e.dataTransfer.files];if(t.length===0)return;let n=Math.max(0,S.length+t.length-5);console.info(`[operator-ui] op=composer-drop count=${t.length} rejected=${n}`),w(t)},[S.length,w]),je=e=>e.startsWith(`image/`)?(0,N.jsx)(le,{size:14}):e===`application/pdf`?(0,N.jsx)(re,{size:14}):(0,N.jsx)(y,{size:14});return(0,N.jsxs)(`div`,{className:`wa-reply${_?` wa-reply-drag-over`:``}`,onDragOver:Oe,onDragLeave:ke,onDrop:Ae,children:[g&&(0,N.jsx)(_e,{sessionKey:n,onPick:e=>{b(t=>[...t,e].slice(0,5)),ee(!1)},onClose:()=>ee(!1)}),m&&(0,N.jsx)(P,{onSelect:Ee}),d&&(0,N.jsx)(`p`,{className:`wa-reply-error`,role:`alert`,children:d}),C&&(0,N.jsx)(`p`,{className:`wa-reply-error`,role:`alert`,children:C}),E===`error`&&se&&(0,N.jsx)(`p`,{className:`wa-reply-error`,role:`alert`,children:se}),(S.length>0||v.length>0)&&(0,N.jsxs)(`div`,{className:`wa-reply-attachments`,children:[S.map((e,t)=>(0,N.jsxs)(`div`,{className:`wa-reply-chip`,children:[je(e.type),(0,N.jsx)(`span`,{className:`wa-reply-chip-name`,children:e.name}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>oe(t),"aria-label":`Remove ${e.name}`,children:(0,N.jsx)(p,{size:12})})]},`f-${t}`)),v.map((e,t)=>(0,N.jsxs)(`div`,{className:`wa-reply-chip wa-reply-chip-ref`,children:[(0,N.jsx)(re,{size:14}),(0,N.jsx)(`span`,{className:`wa-reply-chip-name`,children:e.name}),(0,N.jsx)(`button`,{type:`button`,onClick:()=>b(e=>e.filter((e,n)=>n!==t)),"aria-label":`Remove ${e.name}`,children:(0,N.jsx)(p,{size:12})})]},`r-${t}`))]}),r&&(0,N.jsxs)(`div`,{className:`wa-reply-quote`,children:[(0,N.jsxs)(`div`,{className:`wa-reply-quote-body`,children:[(0,N.jsx)(`span`,{className:`wa-reply-quote-who`,children:r.fromMe?`You`:r.senderName??`Contact`}),(0,N.jsx)(`span`,{className:`wa-reply-quote-text`,children:r.body||`Message`})]}),(0,N.jsx)(`button`,{type:`button`,className:`wa-reply-quote-cancel`,onClick:()=>i?.(),"aria-label":`Cancel reply`,children:(0,N.jsx)(p,{size:14})})]}),!de&&(0,N.jsx)(`div`,{className:`wa-reply-resize-handle`,role:`separator`,"aria-orientation":`horizontal`,"aria-label":`Resize input — drag up to enlarge`,tabIndex:0,onPointerDown:Se,onKeyDown:V}),(0,N.jsx)(`div`,{className:`wa-reply-row`,children:de?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`button`,{type:`button`,className:`wa-reply-attach`,onClick:A,"aria-label":`Cancel recording`,children:(0,N.jsx)(u,{size:20})}),(0,N.jsxs)(`span`,{className:`wa-rec-live`,role:`status`,children:[(0,N.jsx)(`span`,{className:`wa-rec-dot`,"aria-hidden":!0}),ve(D)]}),(0,N.jsx)(`button`,{type:`button`,className:`wa-reply-send`,onClick:()=>void me(),"aria-label":`Stop recording`,children:(0,N.jsx)(l,{size:20})})]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`button`,{type:`button`,className:`wa-reply-emoji`,onClick:()=>h(e=>!e),disabled:s,"aria-label":`Emoji`,"aria-expanded":m,children:(0,N.jsx)(pe,{size:22})}),(0,N.jsx)(`button`,{type:`button`,className:`wa-reply-attach`,onClick:()=>ee(!0),disabled:s,"aria-label":`Attach files`,children:(0,N.jsx)(ne,{size:22})}),(0,N.jsx)(`textarea`,{ref:x,className:`wa-reply-input`,value:a,rows:1,style:{height:`${I??be??44}px`},placeholder:`Type a message`,disabled:s,onChange:e=>o(e.target.value),onKeyDown:De}),(0,N.jsx)(`button`,{type:`button`,className:`wa-reply-mic`,onClick:()=>void fe(),disabled:s,"aria-label":`Record voice note`,children:(0,N.jsx)(ae,{size:22})}),(0,N.jsx)(`button`,{type:`button`,className:`wa-reply-send`,onClick:()=>void Te(),disabled:!we,"aria-label":`Send`,children:(0,N.jsx)(k,{size:20})})]})})]})}function I({accountId:e,remoteJid:t,contactName:n,sessionKey:r,onBack:i}){let a=g(t),o=t.split(`@`)[0],s=a?`Group`:n===`+${o}`?void 0:`+${o}`,[c,l]=(0,j.useState)(!1),[u,d]=(0,j.useState)(``),f=()=>{l(!1),d(``)},[m,h]=(0,j.useState)(null);return(0,N.jsxs)(`div`,{className:`wa-web`,children:[(0,N.jsxs)(`header`,{className:`wa-web-header`,children:[i&&(0,N.jsx)(`button`,{type:`button`,className:`wa-web-back`,onClick:i,"aria-label":`Back`,children:(0,N.jsx)(w,{size:20})}),(0,N.jsx)(`span`,{className:`wa-web-avatar`,"aria-hidden":!0,children:(0,N.jsx)(A,{size:20})}),c?(0,N.jsxs)(`div`,{className:`wa-web-search`,children:[(0,N.jsx)(oe,{size:18,"aria-hidden":!0}),(0,N.jsx)(`input`,{className:`wa-web-search-input`,type:`text`,autoFocus:!0,placeholder:`Search messages`,"aria-label":`Search messages`,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Escape`&&f()}}),(0,N.jsx)(`button`,{type:`button`,className:`wa-web-search-close`,onClick:f,"aria-label":`Close search`,children:(0,N.jsx)(p,{size:18})})]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`wa-web-titles`,children:[(0,N.jsx)(`span`,{className:`wa-web-name`,children:n}),s&&(0,N.jsx)(`span`,{className:`wa-web-subtitle`,children:s})]}),(0,N.jsx)(`button`,{type:`button`,className:`wa-web-search-toggle`,onClick:()=>l(!0),"aria-label":`Search messages`,children:(0,N.jsx)(oe,{size:20})})]})]}),(0,N.jsx)(`div`,{className:`wa-web-body`,children:(0,N.jsx)(C,{sessionId:``,projectDir:``,sessionKey:r,forceDeliveredOnly:!0,suppressDirectives:!0,store:{accountId:e,remoteJid:t},search:c?u:void 0,onReplyTo:a?void 0:h})}),a?(0,N.jsx)(`p`,{className:`wa-reply wa-reply-readonly`,children:`Group messages are read-only.`}):(0,N.jsx)(F,{accountId:e,remoteJid:t,sessionKey:r,replyTo:m,onClearReply:()=>h(null)})]})}function ye(e){let t=new Set,n=[];for(let r of e)for(let e of r.labels)e&&(t.has(e)||T.has(e)&&(t.add(e),n.push(e)));return n}function be(e,t,n=`data`){let r=`/api/admin/files/download?session_key=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}`+(n===`data`?``:`&root=${encodeURIComponent(n)}`),i=document.createElement(`a`);i.href=r,i.rel=`noopener noreferrer`,document.body.appendChild(i),i.click(),i.remove()}function xe(e,t){let n=new URLSearchParams;n.set(`session_key`,e);for(let e of t)n.append(`path`,e);let r=document.createElement(`a`);r.href=`/api/admin/files/download-zip?${n.toString()}`,r.rel=`noopener noreferrer`,document.body.appendChild(r),r.click(),r.remove()}function L(e,t,n=`data`){return`/api/admin/files/download?session_key=${encodeURIComponent(e)}&path=${encodeURIComponent(t)}&disposition=inline`+(n===`data`?``:`&root=${encodeURIComponent(n)}`)}function R(e){if(!e)return``;let t=new Date(e).getTime();return Number.isFinite(t)?new Date(t).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``}function z({conversations:e,sessionKey:t,onBack:n}){let[r,i]=(0,j.useState)(null),a=h(e);return r?r.source===`store`&&r.accountId&&r.remoteJid?(0,N.jsx)(I,{accountId:r.accountId,remoteJid:r.remoteJid,contactName:d(r),sessionKey:t,onBack:()=>i(null)},m(r)):(0,N.jsxs)(`div`,{className:`op-conv op-conv-reader`,children:[(0,N.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,N.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:()=>i(null),"aria-label":`Back to conversations`,children:[(0,N.jsx)(w,{size:16}),` Back`]}),(0,N.jsx)(`span`,{className:`op-conv-title`,children:d(r)})]}),(0,N.jsx)(C,{sessionId:r.sessionId,projectDir:r.projectDir,sessionKey:t,forceDeliveredOnly:!0,suppressDirectives:r.source===`store`,store:r.source===`store`?{accountId:r.accountId,remoteJid:r.remoteJid}:void 0},m(r))]}):(0,N.jsxs)(`div`,{className:`op-conv op-conv-list`,children:[(0,N.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,N.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:n,"aria-label":`Back to chat`,children:[(0,N.jsx)(w,{size:16}),` Chat`]}),(0,N.jsx)(`span`,{className:`op-conv-title`,children:`Conversations`})]}),a.map(e=>(0,N.jsxs)(`div`,{className:`op-conv-group`,children:[(0,N.jsxs)(`div`,{className:`op-conv-group-head`,children:[(0,N.jsx)(f,{channel:e.channel,size:14}),e.label]}),e.rows.map(e=>(0,N.jsxs)(`button`,{type:`button`,className:`op-conv-row`,onClick:()=>{console.info(`[operator-ui] op=reader-open channel=${e.channel} key=${m(e)} readonly=true source=${e.source}`),i(e)},children:[(0,N.jsx)(`span`,{className:`op-conv-name`,children:d(e)}),e.modelGated&&(0,N.jsx)(`span`,{className:`op-conv-gated`,role:`img`,"aria-label":`Model unavailable`,children:(0,N.jsx)(E,{size:13})}),(0,N.jsx)(`span`,{className:`op-conv-when`,children:R(e.lastMessageAt)})]},m(e)))]},e.channel))]})}var B=/\.(png|jpe?g|gif|webp|svg)$/i;function Se(e){return B.test(e)}function V(e){return e.entryPath??e.name}var Ce=`maxy-data-view`,we=95*1024*1024,Te=48*1024*1024;function Ee(){return typeof window>`u`?`list`:window.localStorage.getItem(Ce)===`grid`?`grid`:`list`}function De(){let[e,n]=(0,j.useState)(null),[r,i]=(0,j.useState)(!1);return(0,j.useEffect)(()=>{let e=!1,t=null;try{t=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!t){n(null),i(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(t)}`).then(r=>{if(!e){if(r.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}n(t),i(!0)}}).catch(()=>{e||(n(t),i(!0))}),()=>{e=!0}},[]),r?e?(0,N.jsx)(c,{cacheKey:e,surface:`data`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=data`);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},children:(0,N.jsx)(`div`,{className:`data-page data-page-full`,children:(0,N.jsx)(H,{cacheKey:e})})}):(0,N.jsx)(`div`,{className:`data-page`,children:(0,N.jsxs)(`div`,{className:`data-empty`,children:[(0,N.jsx)(`p`,{children:`You are not signed in.`}),(0,N.jsxs)(`p`,{children:[`Open the `,(0,N.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,N.jsx)(`div`,{className:`data-page`,children:(0,N.jsxs)(`div`,{className:`data-loading`,children:[(0,N.jsx)(t,{size:18,className:`spin`}),` Loading…`]})})}function H({cacheKey:e}){let{adminFetch:t,cacheKey:n,sessionRefetchNonce:r}=v({initialCacheKey:e,surface:`data`});return(0,N.jsx)(Fe,{adminFetch:t,cacheKey:n,sessionRefetchNonce:r})}function Oe(){if(typeof window>`u`)return`.`;let e=new URLSearchParams(window.location.hash.replace(/^#/,``)).get(`path`);return e&&e.length>0?e:`.`}function ke(e){if(typeof window>`u`)return;let t=new URL(window.location.href);t.hash=e===`.`?``:`path=${encodeURIComponent(e)}`,window.history.replaceState(window.history.state,``,t.toString())}function Ae(e){return new Promise((t,n)=>{let r=[],i=()=>e.readEntries(e=>{e.length===0?t(r):(r.push(...e),i())},n);i()})}function je(e){return new Promise((t,n)=>e.file(t,n))}async function Me(e,t=``){let n=[];for(let r of e){if(!r)continue;let e=t?`${t}/${r.name}`:r.name;if(r.isFile)n.push({file:await je(r),relpath:e});else if(r.isDirectory){let t=await Ae(r.createReader());n.push(...await Me(t,e))}}return n}function Ne(e,t){if(e===422&&typeof t==`string`){if(/exceeds the .* limit/i.test(t))return`size`;if(/unsupported file type/i.test(t))return`mime`}return`http=${e}`}function Pe({adminFetch:e,cacheKey:r,sessionRefetchNonce:i}){let[a,c]=(0,j.useState)(``),l=(0,j.useRef)(null),[d,f]=(0,j.useState)(``),[m,h]=(0,j.useState)(null),[g,ee]=(0,j.useState)(`hybrid`),[_,ne]=(0,j.useState)(!1),[v,y]=(0,j.useState)(null),[b,x]=(0,j.useState)(null),[ie,S]=(0,j.useState)(0),[C,ae]=(0,j.useState)(!1),[w,T]=(0,j.useState)(()=>Oe()),[E,le]=(0,j.useState)(null),[k,pe]=(0,j.useState)(()=>Ee()),[A,he]=(0,j.useState)(null),[M,ge]=(0,j.useState)([]),[P,_e]=(0,j.useState)(!1),[ve,F]=(0,j.useState)(null),[I,R]=(0,j.useState)(!1),[z,B]=(0,j.useState)(null),[De,H]=(0,j.useState)(null),[Ae,je]=(0,j.useState)(null),[Pe,Fe]=(0,j.useState)(!1),[Ie,ze]=(0,j.useState)(null),Be=(0,j.useRef)(null),[Ve,U]=(0,j.useState)(0),[We,Ge]=(0,j.useState)(!1),[Ke,qe]=(0,j.useState)(``),[Je,Ye]=(0,j.useState)(null),[Xe,Ze]=(0,j.useState)(``),[Qe,$e]=(0,j.useState)(null),W=(()=>{let e=w===`.`?[]:w.split(`/`).filter(Boolean);return e.length>=2&&e[0]===`accounts`})(),[et,tt]=(0,j.useState)(!1),nt=(0,j.useRef)(null),[rt,G]=(0,j.useState)(!1),it=(0,j.useRef)(null);(0,j.useEffect)(()=>{let e=a.trim();if(!e){f(``),h(null),y(null);return}ae(!1);let t=setTimeout(()=>f(e),300);return()=>clearTimeout(t)},[a]),(0,j.useEffect)(()=>{if(!d){ne(!1);return}let t=!1;return ne(!0),y(null),e(`/api/admin/graph-search?q=${encodeURIComponent(d)}&labels=FileArtifact&limit=20${C?`&threshold=0`:``}`).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);return t}).then(e=>{t||(h(e.results),ee(e.mode??`hybrid`),S(typeof e.suppressed==`number`?e.suppressed:0))}).catch(e=>{t||y(e instanceof Error?e.message:String(e))}).finally(()=>{t||ne(!1)}),()=>{t=!0}},[d,e,i,C]);let at=(0,j.useMemo)(()=>m?ye(m):[],[m]),K=b&&at.includes(b)?b:null,ot=(0,j.useMemo)(()=>m?K?m.filter(e=>e.labels.includes(K)):m:null,[m,K]),st=(0,j.useCallback)(e=>{let t=e.properties.relativePath;if(typeof t!=`string`||t.length===0)return;let n=`/api/admin/files/download?session_key=${encodeURIComponent(r)}&path=${encodeURIComponent(t)}`,i=document.createElement(`a`);i.href=n,i.rel=`noopener noreferrer`,document.body.appendChild(i),i.click(),i.remove()},[r]);(0,j.useEffect)(()=>{if(!m)return;let e=m.filter(e=>{let t=e.properties.relativePath;return typeof t!=`string`||t.length===0});e.length>0&&console.warn(`[data-search] op=locate-link-missing nodeId=${e.map(e=>e.nodeId).join(`,`)}`)},[m]),(0,j.useEffect)(()=>{let t=!1;return _e(!0),F(null),e(`/api/admin/files?path=${encodeURIComponent(w===`.`?``:w)}`).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);return t}).then(e=>{t||(le(e.entries),ge(e.displayPath??[]))}).catch(e=>{t||(le([]),ge([]),F(e instanceof Error?e.message:String(e)))}).finally(()=>{t||_e(!1)}),()=>{t=!0}},[e,w,Ve,i]),(0,j.useEffect)(()=>{ke(w)},[w]);let ct=(0,j.useCallback)(()=>{U(e=>e+1)},[]),q=(0,j.useCallback)(e=>{tt(!1),T(e)},[]),lt=(0,j.useCallback)(e=>{let t=e.properties.relativePath;if(typeof t!=`string`||t.length===0)return;let n=t.lastIndexOf(`/`),r=n===-1?`.`:t.slice(0,n);console.log(`[data-search] op=locate nodeId=${e.nodeId} folder=${r}`),c(``),y(null),x(null),q(r)},[q]),ut=(0,j.useCallback)(()=>{if(w===`.`||w===``)return;let e=w.split(`/`).filter(Boolean);e.pop(),T(e.length===0?`.`:e.join(`/`))},[w]),dt=(0,j.useCallback)(e=>{be(r,w===`.`?V(e):`${w}/${V(e)}`)},[w,r]),[J,ft]=(0,j.useState)(!1),[Y,pt]=(0,j.useState)(new Set),mt=(0,j.useRef)(null),X=(0,j.useRef)(!1),ht=typeof navigator<`u`&&typeof navigator.share==`function`&&typeof navigator.canShare==`function`,gt=(0,j.useCallback)(e=>{ft(!0),pt(new Set([e])),console.info(`[data-ui] op=select-enter count=1`)},[]),Z=(0,j.useCallback)(e=>{ft(!1),pt(new Set),console.info(`[data-ui] op=select-exit reason=${e}`)},[]),Q=(0,j.useCallback)(e=>{pt(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),_t=(0,j.useCallback)(e=>{X.current=!1,mt.current=setTimeout(()=>{X.current=!0,gt(e)},500)},[gt]),$=(0,j.useCallback)(()=>{mt.current&&=(clearTimeout(mt.current),null)},[]),vt=(0,j.useCallback)(e=>{if(X.current){X.current=!1;return}if(J){Q(e.name);return}dt(e)},[J,Q,dt]),yt=(0,j.useCallback)(e=>{pe(e),typeof window<`u`&&window.localStorage.setItem(Ce,e),console.info(`[data] op=view-mode mode=${e}`)},[]),bt=(0,j.useCallback)(e=>{if(X.current){X.current=!1;return}if(J){Q(e.name);return}he({src:L(r,w===`.`?V(e):`${w}/${V(e)}`),alt:e.displayName??e.name})},[J,Q,w,r]),xt=(0,j.useCallback)(()=>(E??[]).filter(e=>e.kind===`file`&&Y.has(e.name)),[E,Y]),St=(0,j.useCallback)(()=>{if(Y.size!==1)return null;let e=(E??[]).find(e=>Y.has(e.name));return e&&!e.entryPath?e:null},[E,Y]),Ct=(0,j.useCallback)(()=>(E??[]).filter(e=>(e.kind===`file`||e.kind===`directory`)&&Y.has(e.name)),[E,Y]),wt=(0,j.useCallback)(()=>{let e=Ct(),t=e.some(e=>e.kind===`directory`);e.length===1&&!t?dt(e[0]):e.length>=1&&xe(r,e.map(e=>w===`.`?V(e):`${w}/${V(e)}`)),Z(`action`)},[Ct,dt,w,r,Z]),Tt=(0,j.useCallback)(async()=>{let t=xt(),n=t.filter(e=>!e.protected),r=t.length-n.length;ze(r>0?`${r} protected file(s) kept`:null);for(let t of n){let n=w===`.`?V(t):`${w}/${V(t)}`;try{let t=await e(`/api/admin/files?path=${encodeURIComponent(n)}`,{method:`DELETE`}),r=await t.json().catch(()=>({error:`HTTP ${t.status}`}));if(!t.ok)throw Error(r.error??`HTTP ${t.status}`)}catch(e){ze(e instanceof Error?e.message:String(e))}}U(e=>e+1),Z(`action`)},[xt,w,e,Z]),Et=(0,j.useCallback)(async()=>{let e=xt();if(console.info(`[data-ui] op=share supported=${ht} count=${e.length}`),ht)try{let t=await Promise.all(e.map(async e=>{let t=w===`.`?V(e):`${w}/${V(e)}`,n=`/api/admin/files/download?session_key=${encodeURIComponent(r)}&path=${encodeURIComponent(t)}`,i=await(await fetch(n)).blob();return new File([i],e.displayName??e.name,{type:i.type||`application/octet-stream`})}));navigator.canShare({files:t})&&await navigator.share({files:t})}catch(e){console.warn(`[data-ui] op=share-failed err=${e instanceof Error?e.message:String(e)}`)}},[xt,ht,w,r]),Dt=(0,j.useCallback)(()=>{Be.current?.click()},[]),Ot=(0,j.useCallback)((e,t={})=>{let n=(n,i,a)=>{let o=new URLSearchParams({session_key:r,path:w===`.`?``:w,filename:e.name});t.relpath&&o.set(`relpath`,t.relpath),t.token&&o.set(`token`,t.token);for(let[e,t]of Object.entries(i))o.set(e,t);return new Promise(t=>{let r=new XMLHttpRequest;r.open(`POST`,`/api/admin/files/upload?${o.toString()}`),r.setRequestHeader(`Content-Type`,e.type||`application/octet-stream`),a&&(r.upload.onprogress=e=>{e.lengthComputable&&a(e.loaded)}),r.onload=()=>{let e={};try{e=JSON.parse(r.responseText)}catch{}t({status:r.status,data:e})},r.onerror=()=>t({status:0,data:{}}),r.onabort=()=>t({status:0,data:{error:`aborted`}}),r.send(n)})};if(e.size<=we)return n(e,{},n=>t.onProgress?.(n,e.size));let i=`${Date.now().toString(36)}-${Math.random().toString(16).slice(2,10)}`,a=Math.ceil(e.size/Te);return(async()=>{let r={status:0,data:{}};for(let o=0;o<a;o++){let s=o*Te;if(r=await n(e.slice(s,Math.min(s+Te,e.size)),{uploadId:i,seq:String(o),total:String(a)},n=>t.onProgress?.(s+n,e.size)),!(r.status>=200&&r.status<300))return r}return r})()},[r,w]),kt=(0,j.useCallback)(async e=>{H(null),R(!0),B({loaded:0,total:e.size});try{let{status:t,data:n}=await Ot(e,{onProgress:(e,t)=>B({loaded:e,total:t})});t>=200&&t<300&&n.path?(T(n.path.split(`/`).slice(0,-1).join(`/`)||`.`),U(e=>e+1)):H(t===0?`Network error during upload — the connection failed before the server responded.`:n.error??`Upload failed (HTTP ${t}).`)}finally{R(!1),B(null),Be.current&&(Be.current.value=``)}},[Ot]),At=(0,j.useCallback)(e=>{W&&Array.from(e.dataTransfer.types).includes(`Files`)&&(e.preventDefault(),Fe(!0))},[W]),jt=(0,j.useCallback)(e=>{e.currentTarget.contains(e.relatedTarget)||Fe(!1)},[]),Mt=(0,j.useCallback)(async e=>{e.preventDefault(),Fe(!1);let t=Math.random().toString(16).slice(2,10),n=Array.from(e.dataTransfer.items);if(console.info(`[data-ui] op=drop-received token=${t} items=${n.length}`),n.length===0)return;if(!W){console.info(`[data-ui] op=drop-rejected token=${t} reason=no-write`),H(`Open a folder inside your account to upload`);return}let r=n.map(e=>e.webkitGetAsEntry?.()).filter(e=>!!e);R(!0),H(null),je(null);let i=performance.now();try{let e=await Me(r),n=e.reduce((e,t)=>e+t.file.size,0),a=new Set(e.map(e=>e.relpath.split(`/`).slice(0,-1).join(`/`)).filter(Boolean)).size;console.info(`[data-ui] op=drop-walk token=${t} files=${e.length} dirs=${a} bytes=${n}`);let o=0,s=[];for(let n=0;n<e.length;n++){let{file:r,relpath:i}=e[n];console.info(`[data-ui] op=drop-file token=${t} rel="${i}" i=${n+1}/${e.length}`),B({loaded:0,total:r.size});let{status:a,data:c}=await Ot(r,{relpath:i,token:t,onProgress:(e,t)=>B({loaded:e,total:t})});if(a>=200&&a<300)o++,console.info(`[data-ui] op=drop-file-ok token=${t} rel="${i}"`);else{let e=a===0?`http=0`:Ne(a,c.error);s.push(`${i} (${e})`),console.info(`[data-ui] op=drop-file-skip token=${t} rel="${i}" reason=${e}`)}}let c=Math.round(performance.now()-i);console.info(`[data-ui] op=drop-done token=${t} uploaded=${o} skipped=${s.length} ms=${c}`),je(`Uploaded ${o}, skipped ${s.length}${s.length?`: ${s.join(`, `)}`:``}`),U(e=>e+1)}catch(e){H(e instanceof Error?e.message:String(e))}finally{R(!1),B(null)}},[W,Ot]),Nt=(0,j.useCallback)(async()=>{let t=Ke.trim();if(t){$e(null);try{let n=await e(`/api/admin/files/folder`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:w===`.`?``:w,name:t})}),r=await n.json().catch(()=>({error:`HTTP ${n.status}`}));if(!n.ok)throw Error(r.error??`HTTP ${n.status}`);Ge(!1),qe(``),U(e=>e+1)}catch(e){$e(e instanceof Error?e.message:String(e))}}},[e,Ke,w]),Pt=(0,j.useCallback)(async()=>{if(!Je)return;let t=Xe.trim();if(!t)return;$e(null);let n=w===`.`?Je:`${w}/${Je}`;try{let r=await e(`/api/admin/files/rename`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:n,newName:t})}),i=await r.json().catch(()=>({error:`HTTP ${r.status}`}));if(!r.ok)throw Error(i.error??`HTTP ${r.status}`);Ye(null),Ze(``),Z(`action`),U(e=>e+1)}catch(e){$e(e instanceof Error?e.message:String(e))}},[e,Xe,Je,w,Z]);(0,j.useEffect)(()=>{if(!et)return;let e=e=>{nt.current&&!nt.current.contains(e.target)&&tt(!1)},t=e=>{e.key===`Escape`&&tt(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[et]),(0,j.useEffect)(()=>{if(!rt)return;let e=e=>{it.current&&!it.current.contains(e.target)&&G(!1)},t=e=>{e.key===`Escape`&&G(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[rt]);let Ft=(0,j.useCallback)(e=>M.slice(0,e+1).map(e=>e.name).join(`/`),[M]),It=M.length>=2,Lt=It?[{name:`.`,label:`data`},...M.slice(0,M.length-2).map((e,t)=>({name:Ft(t),label:e.displayName??e.name}))]:[];return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`data-toolbar`,children:[J?(0,N.jsxs)(`button`,{type:`button`,className:`data-select-cancel`,onClick:()=>Z(`cancel`),"aria-label":`Cancel selection`,children:[(0,N.jsx)(p,{size:14}),` Cancel`]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`div`,{className:`data-search-input`,children:[a===``&&(0,N.jsx)(oe,{size:14}),(0,N.jsx)(`input`,{ref:l,type:`text`,value:a,onChange:e=>c(e.target.value),autoFocus:!0,autoComplete:`off`,spellCheck:!1}),_&&(0,N.jsx)(t,{size:14,className:`spin`}),a!==``&&(0,N.jsx)(`button`,{type:`button`,className:`data-search-inline-btn`,onClick:()=>{c(``),l.current?.focus()},title:`Clear search`,"aria-label":`Clear search`,children:(0,N.jsx)(p,{size:14})})]}),(0,N.jsxs)(`div`,{className:`data-toolbar-actions`,ref:it,children:[(0,N.jsx)(`button`,{type:`button`,className:`data-action-overflow`,onClick:()=>G(e=>!e),"aria-haspopup":`menu`,"aria-expanded":rt,"aria-label":`File actions`,title:`File actions`,children:(0,N.jsx)(se,{size:16})}),(0,N.jsxs)(`div`,{className:`data-action-group`,role:`group`,"aria-label":`File actions`,"data-open":rt?`true`:void 0,children:[(0,N.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{ct(),G(!1)},disabled:P,title:`Refresh this folder`,"aria-label":`Refresh this folder`,children:[P?(0,N.jsx)(t,{size:16,className:`spin`}):(0,N.jsx)(te,{size:16}),(0,N.jsx)(`span`,{className:`data-action-label`,children:`Refresh`})]}),(0,N.jsxs)(`button`,{type:`button`,className:`data-action-btn admin-btn-cta`,onClick:()=>{Dt(),G(!1)},disabled:I||!W,title:W?`Upload a file`:`Open a folder inside your account to upload`,"aria-label":`Upload a file`,children:[I?z&&z.total>0?(0,N.jsxs)(`span`,{className:`data-upload-pct`,children:[Math.round(z.loaded/z.total*100),`%`]}):(0,N.jsx)(t,{size:16,className:`spin`}):(0,N.jsx)(me,{size:16}),(0,N.jsx)(`span`,{className:`data-action-label`,children:`Upload`})]}),(0,N.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{Ge(e=>!e),qe(``),$e(null),G(!1)},disabled:I||!W,title:W?`New folder`:`Open a folder inside your account to create one`,"aria-label":`New folder`,children:[(0,N.jsx)(ce,{size:16}),(0,N.jsx)(`span`,{className:`data-action-label`,children:`New folder`})]}),(0,N.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{yt(k===`grid`?`list`:`grid`),G(!1)},title:k===`grid`?`List view`:`Grid view`,"aria-label":k===`grid`?`Switch to list view`:`Switch to grid view`,"aria-pressed":k===`grid`,children:[k===`grid`?(0,N.jsx)(de,{size:16}):(0,N.jsx)(ue,{size:16}),(0,N.jsx)(`span`,{className:`data-action-label`,children:k===`grid`?`List view`:`Grid view`})]})]})]})]}),(0,N.jsxs)(`div`,{className:`data-breadcrumbs`,children:[w!==`.`&&(0,N.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost data-back-btn`,onClick:ut,title:`Up one level`,"aria-label":`Up one level`,children:(0,N.jsx)(D,{size:14})}),It?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(`span`,{className:`data-crumb-wrap`,ref:nt,children:[(0,N.jsx)(`button`,{type:`button`,className:`data-crumb data-crumb-ellipsis`,onClick:()=>tt(e=>!e),"aria-haspopup":`menu`,"aria-expanded":et,"aria-label":`Show parent folders`,title:`Show parent folders`,children:`…`}),et&&(0,N.jsx)(`div`,{className:`data-crumb-menu`,role:`menu`,children:Lt.map(e=>(0,N.jsx)(`button`,{type:`button`,role:`menuitem`,className:`data-crumb-menu-item`,onClick:()=>q(e.name),title:e.label,children:e.label},e.name))})]}),[M.length-2,M.length-1].map(e=>{let t=M[e];return(0,N.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,N.jsx)(`span`,{className:`data-crumb-sep`,children:`›`}),(0,N.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>q(Ft(e)),title:t.name,children:t.displayName??t.name})]},Ft(e))})]}):(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>q(`.`),children:`data`}),M.map((e,t)=>(0,N.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,N.jsx)(`span`,{className:`data-crumb-sep`,children:`›`}),(0,N.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>q(Ft(t)),title:e.name,children:e.displayName??e.name})]},Ft(t)))]})]}),We&&(0,N.jsxs)(`div`,{className:`data-inline-form`,children:[(0,N.jsx)(`input`,{type:`text`,className:`data-inline-input`,placeholder:`Folder name`,value:Ke,autoFocus:!0,onChange:e=>qe(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Nt(),e.key===`Escape`&&Ge(!1)}}),(0,N.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:Nt,children:`Create`}),(0,N.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost`,onClick:()=>Ge(!1),children:`Cancel`})]}),Je&&(0,N.jsxs)(`div`,{className:`data-inline-form`,children:[(0,N.jsx)(`input`,{type:`text`,className:`data-inline-input`,placeholder:`New name`,value:Xe,autoFocus:!0,onChange:e=>Ze(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Pt(),e.key===`Escape`&&Ye(null)}}),(0,N.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:Pt,children:`Rename`}),(0,N.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost`,onClick:()=>Ye(null),children:`Cancel`})]}),Qe&&(0,N.jsx)(`div`,{className:`data-error`,children:Qe}),(0,N.jsx)(`input`,{type:`file`,ref:Be,hidden:!0,onChange:e=>{let t=e.target.files?.[0];t&&kt(t)}})]}),(0,N.jsxs)(`div`,{className:`data-body`,"data-drag-active":Pe?`true`:void 0,onDragEnter:At,onDragOver:At,onDragLeave:jt,onDrop:Mt,children:[(v!==null||m!==null)&&(0,N.jsxs)(`section`,{className:`data-panel admin-card`,children:[v&&(0,N.jsxs)(`div`,{className:`data-error`,children:[`Search failed: `,v]}),at.length>0&&(0,N.jsx)(`div`,{className:`data-chip-row`,role:`group`,"aria-label":`Filter by type`,children:at.map(e=>{let t=e===K;return(0,N.jsx)(`button`,{type:`button`,className:`data-chip`,"data-active":t,onClick:()=>x(t?null:e),children:Re([e])??e},e)})}),m&&!_&&(0,N.jsxs)(`div`,{className:`data-results-meta`,children:[ot.length,` of `,m.length,` result`,m.length===1?``:`s`]}),m&&!_&&!K&&ie>0&&!C&&(0,N.jsxs)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>ae(!0),children:[ie,` low-confidence result`,ie===1?``:`s`,` hidden — show all`]}),m&&!_&&!K&&C&&(0,N.jsx)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>ae(!1),children:`Showing all results — hide low-confidence`}),m&&m.length===0&&!_&&(0,N.jsx)(`div`,{className:`data-empty-results`,children:`No matches. Try a different keyword.`}),ot&&ot.length>0&&(0,N.jsx)(`ul`,{className:`data-results`,children:ot.map(e=>(0,N.jsx)(Le,{hit:e,mode:g,onDownload:st,onLocate:lt},e.nodeId))})]}),(0,N.jsxs)(`section`,{className:`data-panel admin-card`,children:[z&&(0,N.jsxs)(`div`,{className:`data-upload-progress`,role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":z.total>0?Math.round(z.loaded/z.total*100):void 0,children:[(0,N.jsx)(`div`,{className:`data-upload-progress-track`,children:(0,N.jsx)(`div`,{className:`data-upload-progress-fill`,style:{width:`${z.total>0?Math.round(z.loaded/z.total*100):0}%`}})}),(0,N.jsxs)(`span`,{className:`data-upload-progress-label`,children:[`Uploading… `,z.total>0?`${Math.round(z.loaded/z.total*100)}%`:``]})]}),De&&(0,N.jsxs)(`div`,{className:`data-error`,children:[`Upload failed: `,De]}),Ae&&(0,N.jsx)(`div`,{className:`data-status`,children:Ae}),Ie&&(0,N.jsxs)(`div`,{className:`data-error`,children:[`Delete failed: `,Ie]}),ve&&(0,N.jsx)(`div`,{className:`data-error`,children:ve}),P&&(0,N.jsxs)(`div`,{className:`data-loading`,children:[(0,N.jsx)(t,{size:14,className:`spin`}),` Loading…`]}),!J&&!P&&E&&E.length>0&&(0,N.jsxs)(`div`,{className:`data-select-hint`,children:[(0,N.jsx)(fe,{size:13}),(0,N.jsx)(`span`,{children:`Press and hold a file to select, rename, or delete it.`})]}),!P&&E&&E.length===0&&!ve&&(0,N.jsx)(`div`,{className:`data-empty-results`,children:`Empty directory.`}),!P&&E&&E.length>0&&k===`grid`&&(0,N.jsx)(`ul`,{className:`data-grid`,children:E.map(e=>{let t=e.displayName??e.name,n=J&&Y.has(e.name);if(e.kind===`directory`)return(0,N.jsx)(`li`,{className:`data-grid-cell`,"data-selected":n?`true`:void 0,children:(0,N.jsxs)(`button`,{type:`button`,className:`data-grid-tile`,onPointerDown:()=>_t(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>{if(X.current){X.current=!1;return}if(J){Q(e.name);return}q(w===`.`?e.name:`${w}/${e.name}`)},children:[J&&(0,N.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,N.jsx)(O,{size:28,className:`data-grid-glyph`}),(0,N.jsx)(`span`,{className:`data-grid-label`,title:e.name,children:t})]})},e.name);if(e.kind===`file`){let i=Se(V(e)),a=w===`.`?V(e):`${w}/${V(e)}`;return(0,N.jsx)(`li`,{className:`data-grid-cell`,"data-selected":n?`true`:void 0,children:(0,N.jsxs)(`button`,{type:`button`,className:`data-grid-tile${i?` data-grid-tile-image`:``}`,onPointerDown:()=>_t(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>i?bt(e):vt(e),title:J?void 0:i?`Preview ${t}`:`Download ${t}`,children:[J&&(0,N.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),i?(0,N.jsx)(`img`,{className:`data-grid-thumb`,src:L(r,a),alt:t,loading:`lazy`,onError:()=>console.warn(`[data] op=thumb-error path=${a}`)}):(0,N.jsx)(re,{size:28,className:`data-grid-glyph`}),(0,N.jsx)(`span`,{className:`data-grid-label`,title:e.name,children:t}),!i&&(0,N.jsx)(`span`,{className:`data-grid-sub`,children:He(e.sizeBytes)})]})},e.name)}return(0,N.jsx)(`li`,{className:`data-grid-cell`,children:(0,N.jsxs)(`div`,{className:`data-grid-tile data-entry-disabled`,children:[(0,N.jsx)(re,{size:28,className:`data-grid-glyph`}),(0,N.jsx)(`span`,{className:`data-grid-label`,children:t}),(0,N.jsx)(`span`,{className:`data-grid-sub`,children:`special`})]})},e.name)})}),!P&&E&&E.length>0&&k===`list`&&(0,N.jsx)(`ul`,{className:`data-entries`,children:E.map(e=>{let t=e.displayName??e.name;if(e.kind===`directory`){let n=J&&Y.has(e.name);return(0,N.jsx)(`li`,{className:`data-entry`,"data-selected":n?`true`:void 0,children:(0,N.jsxs)(`button`,{type:`button`,className:`data-entry-btn`,onPointerDown:()=>_t(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>{if(X.current){X.current=!1;return}if(J){Q(e.name);return}q(w===`.`?e.name:`${w}/${e.name}`)},children:[J&&(0,N.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,N.jsx)(O,{size:14}),(0,N.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t})]})},e.name)}if(e.kind===`file`){let n=J&&Y.has(e.name);return(0,N.jsx)(`li`,{className:`data-entry`,"data-selected":n?`true`:void 0,children:(0,N.jsxs)(`button`,{type:`button`,className:`data-entry-btn data-entry-file`,onPointerDown:()=>_t(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>vt(e),title:J?void 0:`Download ${t}`,children:[J&&(0,N.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,N.jsxs)(`span`,{className:`data-entry-text`,children:[(0,N.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t}),(0,N.jsxs)(`span`,{className:`data-entry-meta`,title:`Modified ${Ue(e.modifiedAt)}`,children:[He(e.sizeBytes),` · `,Ue(e.modifiedAt)]})]})]})},e.name)}return(0,N.jsx)(`li`,{className:`data-entry`,children:(0,N.jsx)(`div`,{className:`data-entry-btn data-entry-file data-entry-disabled`,children:(0,N.jsxs)(`span`,{className:`data-entry-text`,children:[(0,N.jsx)(`span`,{className:`data-entry-name`,children:t}),(0,N.jsx)(`span`,{className:`data-entry-meta`,children:`special`})]})})},e.name)})})]})]}),J&&(0,N.jsx)(`div`,{className:`data-select-bar`,role:`toolbar`,"aria-label":`Selection actions`,children:(0,N.jsxs)(`div`,{className:`data-select-bar-inner`,children:[(0,N.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:Et,disabled:!ht||Y.size===0,title:ht?`Share selected files`:`Sharing is not supported on this device`,children:[(0,N.jsx)(o,{size:16}),` Share`]}),(0,N.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:wt,disabled:Y.size===0,children:[(0,N.jsx)(n,{size:16}),` Download`]}),(0,N.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:()=>{let e=St();e&&(Ye(e.name),Ze(e.name))},disabled:!St(),children:[(0,N.jsx)(s,{size:16}),` Rename`]}),(0,N.jsxs)(`button`,{type:`button`,className:`data-select-action data-select-delete`,onClick:Tt,disabled:Y.size===0,children:[(0,N.jsx)(u,{size:16}),` Delete`]})]})}),A&&(0,N.jsx)(`div`,{className:`chat-attachment-overlay`,role:`dialog`,"aria-label":A.alt,onClick:()=>he(null),children:(0,N.jsx)(`img`,{className:`chat-attachment-overlay-image`,src:A.src,alt:A.alt})})]})}function Fe({adminFetch:e,cacheKey:t,sessionRefetchNonce:n}){(0,j.useEffect)(()=>{console.info(`[data-ui] op=mount header=operator home=absent`)},[]);let r=(0,j.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]),i=(0,j.useCallback)(e=>{e===`chat`&&(window.location.href=`/`)},[]),[a,o]=(0,j.useState)([]),[s,c]=(0,j.useState)(`files`),{subAccounts:l,activeAccountId:u,switching:d,switchAccount:f}=ee(t);return(0,j.useEffect)(()=>{if(!t)return;let e=!1;return fetch(`/api/whatsapp-reader/conversations?session_key=${encodeURIComponent(t)}`).then(e=>e.ok?e.json():{conversations:[]}).then(t=>{e||o(t.conversations??[])}).catch(()=>{}),()=>{e=!0}},[t]),(0,N.jsxs)(`main`,{className:`data-main`,children:[(0,N.jsx)(_,{variant:`operator`,onNavigate:i,onOpenConversations:a.length>0?()=>c(`conversations`):void 0,onToggleSidebar:()=>{},sidebarOpen:!1,onLogout:r,onDisconnect:async()=>!0,disconnecting:!1,subAccounts:l,activeAccountId:u,switchingAccount:d,onSwitchAccount:f}),s===`conversations`?(0,N.jsx)(z,{conversations:a,sessionKey:t,onBack:()=>c(`files`)}):(0,N.jsx)(Pe,{adminFetch:e,cacheKey:t,sessionRefetchNonce:n})]})}function Ie({cacheKey:e}){let{adminFetch:t,cacheKey:n,sessionRefetchNonce:r}=v({initialCacheKey:e,surface:`data`});return(0,N.jsx)(`div`,{className:`data-page`,children:(0,N.jsx)(`main`,{className:`data-main`,children:(0,N.jsx)(Pe,{adminFetch:t,cacheKey:n,sessionRefetchNonce:r})})})}function Le({hit:e,mode:t,onDownload:n,onLocate:r}){let i=ze(e.properties),a=Be(e.properties),o=Re(e.labels),s=Ve(e.properties),[c,l]=(0,j.useState)(!1),u=a&&a.length>280,d=c||!u?a:a?.slice(0,280)+`…`,f=t===`bm25`?`bm25 ${e.bm25Score.toFixed(2)}`:`vector ${e.vectorScore.toFixed(2)} · bm25 ${e.bm25Score.toFixed(2)} · combined ${e.score.toFixed(2)}`,p=e.properties.relativePath,m=typeof p==`string`&&p.length>0,h=m?p.lastIndexOf(`/`):-1,g=m?h===-1?`data`:p.slice(0,h):null;return(0,N.jsxs)(`li`,{className:`data-result`,children:[(0,N.jsxs)(`div`,{role:`button`,tabIndex:0,className:`data-result-open`,onClick:()=>n(e),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),n(e))},"aria-label":`Download ${i??o??`file`}`,children:[o&&(0,N.jsx)(`div`,{className:`data-result-header`,children:(0,N.jsx)(`span`,{className:`data-result-labels`,children:o})}),i&&(0,N.jsx)(`div`,{className:`data-result-title`,children:i}),a&&(0,N.jsx)(`pre`,{className:`data-result-body`,children:d}),(0,N.jsxs)(`div`,{className:`data-result-scores`,children:[s&&(0,N.jsxs)(`span`,{className:`data-result-updated`,children:[`Updated `,Ue(s),` · `]}),f]})]}),m&&(0,N.jsxs)(`button`,{type:`button`,className:`data-result-locate`,onClick:()=>r(e),title:`Locate in ${g}`,"aria-label":`Locate in ${g}`,children:[(0,N.jsx)(O,{size:12}),g]}),u&&(0,N.jsx)(`button`,{type:`button`,className:`data-result-toggle`,onClick:()=>l(e=>!e),children:c?`Show less`:`Show more`})]})}function Re(e){if(e.length===0)return null;let t=e[0].replace(/([a-z])([A-Z])/g,`$1 $2`);return t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()}function ze(e){for(let t of[`title`,`name`,`summary`,`headline`]){let n=e[t];if(typeof n==`string`&&n.length>0)return n.length>140?n.slice(0,140)+`…`:n}return null}function Be(e){for(let t of[`content`,`summary`,`body`,`description`,`text`]){let n=e[t];if(typeof n==`string`&&n.length>0)return n}return null}function Ve(e){for(let t of[`updatedAt`,`modifiedAt`,`fetchedAt`,`createdAt`,`lastModified`]){let n=e[t];if(typeof n==`string`&&n.length>0)return n}return null}function He(e){return e==null?``:e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)} MB`:`${(e/1024/1024/1024).toFixed(1)} GB`}function Ue(e){try{let t=new Date(e);if(isNaN(t.getTime()))return`—`;let n=typeof navigator<`u`?navigator.languages&&navigator.languages.length>0?[...navigator.languages]:[navigator.language]:void 0;return t.toLocaleString(n,{dateStyle:`medium`,timeStyle:`short`})}catch{return`—`}}export{I as i,Ie as n,be as r,De as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./chunk-TPjIAO9U.js";import{B as t,C as n,H as r,L as i,b as a,f as o,g as s,k as c,m as l,z as u}from"./useSubAccountSwitcher-sPN6lobE.js";import{t as d,v as f}from"./AdminShell-DR6AzflZ.js";import{n as p,t as m}from"./time-entry-format-C-By1MbO.js";import{t as h}from"./rotate-ccw-CCbbX5ef.js";var g=t(),_=e(r(),1);function v(e=3e4){let[t,n]=(0,_.useState)(()=>Date.now());return(0,_.useEffect)(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}function y(e,t){let n=new Map,r=(e,t,r)=>{let i=n.get(e)??{openCount:0,totalSeconds:0};i.totalSeconds+=t,r&&(i.openCount+=1),n.set(e,i)};for(let t of e)t.clientName&&r(t.clientName,t.secondsLogged,!0);for(let e of t)e.clientName&&r(e.clientName,e.secondsLogged,!1);let i=[...n.entries()].map(([e,t])=>({name:e,openCount:t.openCount,totalSeconds:t.totalSeconds}));return i.sort((e,t)=>t.openCount-e.openCount||e.name.localeCompare(t.name)),b(e,i),i}function b(e,t){let n=t.reduce((e,t)=>e+t.openCount,0),r=e.filter(e=>!e.clientName).length,i=n+r===e.length;return i||console.warn(`[tasks-clients] reconcile-mismatch assigned=${n} unassigned=${r} openTotal=${e.length}`),i}var x=`__unassigned__`;function S(e,t){return e===`__unassigned__`?`Unassigned`:t||e.slice(0,8)}function C(e){return e===null||e===``?x:e}function w(e,t){let n=new Map,r=(e,t)=>{let r=C(e.assigneeUserId),i=n.get(r)??{name:null,openCount:0,totalCount:0};i.name===null&&e.assigneeName&&(i.name=e.assigneeName),i.totalCount+=1,t&&(i.openCount+=1),n.set(r,i)};for(let t of e)r(t,!0);for(let e of t)r(e,!1);let i=[...n.entries()].map(([e,t])=>({userId:e,label:S(e,t.name),openCount:t.openCount,totalCount:t.totalCount}));return i.sort((e,t)=>t.openCount-e.openCount||e.label.localeCompare(t.label)),i}function T(e,t){return t===null?!0:C(e.assigneeUserId)===t}var E=i(),D=`maxy-admin-session-key`;function ee(e){let t=[];return e.clientName&&t.push(e.clientName),e.propertyAddress&&t.push(e.propertyAddress),e.fee!=null&&t.push(`£${e.fee}`),t.join(` · `)}function te(e){return[e.clientName,e.propertyAddress].filter(Boolean).join(` · `)}function O(e){if(!e)return``;let t=Date.parse(e);if(!Number.isFinite(t))return``;let n=new Date(t);return`${n.getUTCDate()} ${[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`][n.getUTCMonth()]} ${n.getUTCFullYear()}`}function k(e){return e.assigneeName?e.assigneeName:e.assigneeUserId?e.assigneeUserId.slice(0,8):`Unassigned`}function A(e,t){return[t,O(e.createdAt),k(e)].filter(Boolean).join(` · `)}function j(e,t){if(e.running&&e.runningStartedAt){let n=Date.parse(e.runningStartedAt);if(Number.isFinite(n))return e.secondsLogged+Math.max(0,(t-n)/1e3)}return e.secondsLogged}function M({clients:e,onSelect:t}){return(0,E.jsxs)(`section`,{className:`admin-card tasks-card`,children:[(0,E.jsxs)(`div`,{className:`tasks-card-head`,children:[(0,E.jsx)(`span`,{className:`tasks-card-title`,children:`Clients`}),(0,E.jsxs)(`span`,{className:`tasks-card-count`,children:[e.length,` total`]})]}),e.length===0&&(0,E.jsx)(`div`,{className:`tasks-empty`,children:`No clients yet.`}),e.map(e=>(0,E.jsx)(`button`,{className:`tasks-row tasks-client-row`,onClick:()=>t(e.name),children:(0,E.jsxs)(`div`,{className:`tasks-row-main`,children:[(0,E.jsx)(`div`,{className:`tasks-row-name`,children:e.name}),(0,E.jsxs)(`div`,{className:`tasks-row-sub`,children:[e.openCount,` open · `,m(e.totalSeconds),` logged`]})]})},e.name))]})}function N({task:e,onClose:t}){return(0,_.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),(0,E.jsx)(`div`,{className:`tasks-detail-backdrop`,onClick:t,children:(0,E.jsxs)(`div`,{className:`tasks-detail`,role:`dialog`,"aria-modal":`true`,"aria-label":`Task detail`,onClick:e=>e.stopPropagation(),children:[(0,E.jsxs)(`div`,{className:`tasks-detail-head`,children:[(0,E.jsx)(`h2`,{className:`tasks-detail-title`,children:e?e.name:`Task no longer available`}),(0,E.jsx)(`button`,{className:`tasks-detail-close`,"aria-label":`Close`,onClick:t,children:(0,E.jsx)(l,{size:16})})]}),e===null?(0,E.jsx)(`p`,{className:`tasks-detail-gone`,children:`This task is no longer in the list. It may have been completed, cancelled or removed. Close this and reload to see the current list.`}):(0,E.jsxs)(`dl`,{className:`tasks-detail-fields`,children:[(0,E.jsx)(`dt`,{children:`Status`}),(0,E.jsx)(`dd`,{children:e.status}),(0,E.jsx)(`dt`,{children:`Logged`}),(0,E.jsx)(`dd`,{children:m(e.secondsLogged)}),(0,E.jsx)(`dt`,{children:`Created`}),(0,E.jsx)(`dd`,{children:O(e.createdAt)||`Not recorded`}),(0,E.jsx)(`dt`,{children:`Assignee`}),(0,E.jsx)(`dd`,{children:k(e)}),e.clientName&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`dt`,{children:`Client`}),(0,E.jsx)(`dd`,{children:e.clientName})]}),e.propertyAddress&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`dt`,{children:`Property`}),(0,E.jsx)(`dd`,{children:e.propertyAddress})]}),e.fee!=null&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`dt`,{children:`Fee`}),(0,E.jsxs)(`dd`,{children:[`£`,e.fee]})]})]})]})})}function P({adminFetch:e}){let[t,r]=(0,_.useState)({open:[],completed:[]}),[i,o]=(0,_.useState)(!1),[u,d]=(0,_.useState)(!1),f=(0,_.useRef)(!1),g=(0,_.useRef)(``),b=v(1e3),[x,S]=(0,_.useState)(`open`),[C,D]=(0,_.useState)(null),[O,k]=(0,_.useState)(null),[P,F]=(0,_.useState)(null),[I,L]=(0,_.useState)(``),[R,z]=(0,_.useState)(null),[B,V]=(0,_.useState)(null),H=(0,_.useMemo)(()=>{if(R!==null)return[...t.open,...t.completed].find(e=>e.rowKey===R)??null},[t,R]);(0,_.useEffect)(()=>{R!==null&&H===null&&console.error(`[tasks-ui] op=detail-failed rowKey=${R} reason=not-in-list`)},[R,H]);let U=(0,_.useMemo)(()=>y(t.open,t.completed),[t]),W=(0,_.useMemo)(()=>C===null?{open:t.open,completed:t.completed}:{open:t.open.filter(e=>e.clientName===C),completed:t.completed.filter(e=>e.clientName===C)},[t,C]),G=(0,_.useMemo)(()=>w(W.open,W.completed),[W]),K=(0,_.useCallback)(e=>{D(e),S(`open`)},[]);(0,_.useEffect)(()=>{C&&!U.some(e=>e.name===C)&&D(null)},[U,C]),(0,_.useEffect)(()=>{O&&!G.some(e=>e.userId===O)&&k(null)},[G,O]),(0,_.useEffect)(()=>{V(null)},[x,C,O]);let q=t.open.filter(e=>e.running||(C===null||e.clientName===C)&&T(e,O)),J=(C?t.completed.filter(e=>e.clientName===C):t.completed).filter(e=>T(e,O)),Y=(0,_.useCallback)(async()=>{let t=await e(`/api/admin/tasks-list`);t.ok&&r(await t.json()),o(!0)},[e]);(0,_.useEffect)(()=>{Y()},[Y]);let X=(0,_.useCallback)(async(t,n,r)=>{if(f.current)return!1;f.current=!0,d(!0);try{return await e(t,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({taskId:n,...r})}),await Y(),!0}finally{f.current=!1,d(!1)}},[e,Y]),ne=(0,_.useCallback)(async e=>{await X(`/api/admin/task-complete`,e)&&console.log(`[tasks-ui] op=complete taskId=${e.slice(0,8)} confirmed=true`)},[X]),re=(0,_.useCallback)((e,t)=>{let n=String(Math.round(e.secondsLogged/60));g.current=n,F(t),L(n)},[]),Z=(0,_.useCallback)(()=>{F(null),L(``)},[]),ie=(0,_.useCallback)(async e=>{let t=I.trim(),n=Number(t);if(!(t===``||!Number.isInteger(n)||n<0)){if(t===g.current){Z();return}F(null),L(``),await X(`/api/admin/task-time-adjust`,e,{newSeconds:n*60})}},[I,X,Z]),ae=(0,_.useCallback)(e=>{X(`/api/admin/task-time-adjust`,e,{newSeconds:0})},[X]);if(!i)return(0,E.jsxs)(`div`,{className:`tasks-loading`,children:[(0,E.jsx)(n,{size:18,className:`spin`}),` Loading…`]});let Q=e=>e.taskId!==null&&P===e.taskId,$=(e,t)=>Q(e)?(0,E.jsxs)(`div`,{className:`tasks-edit`,children:[(0,E.jsx)(`input`,{className:`tasks-edit-input`,type:`number`,min:0,step:1,"aria-label":`Logged minutes`,value:I,onChange:e=>L(e.target.value)}),(0,E.jsx)(`span`,{className:`tasks-edit-unit`,children:`min`}),(0,E.jsxs)(`button`,{className:`admin-btn-cta tasks-btn-action`,disabled:u,onClick:()=>void ie(t),children:[(0,E.jsx)(c,{size:14}),` Save`]}),(0,E.jsxs)(`button`,{className:`tasks-btn-secondary tasks-btn-action`,onClick:Z,children:[(0,E.jsx)(l,{size:14}),` Cancel`]})]}):(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`button`,{className:`tasks-time-btn`,"aria-label":`Edit time`,disabled:u||e.running,title:e.running?`Stop the timer before editing time`:void 0,onClick:()=>re(e,t),children:(0,E.jsx)(a,{size:14})}),(0,E.jsx)(`button`,{className:`tasks-time-btn`,"aria-label":`Reset time`,disabled:u||e.running,title:e.running?`Stop the timer before resetting time`:void 0,onClick:()=>ae(t),children:(0,E.jsx)(h,{size:14})})]});return(0,E.jsxs)(`div`,{className:`tasks-body`,children:[R!==null&&(0,E.jsx)(N,{task:H??null,onClose:()=>z(null)}),(0,E.jsxs)(`div`,{className:`tasks-tabs`,children:[(0,E.jsxs)(`button`,{className:`admin-chip ${x===`open`?`is-active`:``}`,onClick:()=>S(`open`),children:[`Open `,(0,E.jsx)(`span`,{className:`tasks-tab-badge`,children:t.open.length})]}),(0,E.jsxs)(`button`,{className:`admin-chip ${x===`completed`?`is-active`:``}`,onClick:()=>S(`completed`),children:[`Completed `,(0,E.jsx)(`span`,{className:`tasks-tab-badge`,children:t.completed.length})]}),(0,E.jsxs)(`button`,{className:`admin-chip ${x===`clients`?`is-active`:``}`,onClick:()=>S(`clients`),children:[`Clients `,(0,E.jsx)(`span`,{className:`tasks-tab-badge`,children:U.length})]})]}),x===`clients`?(0,E.jsx)(M,{clients:U,onSelect:K}):(0,E.jsxs)(E.Fragment,{children:[C&&(0,E.jsxs)(`div`,{className:`tasks-filter-banner`,children:[(0,E.jsxs)(`span`,{children:[`Showing `,C]}),(0,E.jsx)(`button`,{className:`tasks-filter-clear`,onClick:()=>D(null),children:`Clear`})]}),G.length>0&&(0,E.jsxs)(`div`,{className:`tasks-assignee-bar`,children:[(0,E.jsxs)(`button`,{className:`admin-chip ${O===null?`is-active`:``}`,"aria-pressed":O===null,onClick:()=>k(null),children:[`All `,(0,E.jsx)(`span`,{className:`tasks-assignee-count`,children:W.open.length})]}),G.map(e=>(0,E.jsxs)(`button`,{className:`admin-chip ${O===e.userId?`is-active`:``}`,"aria-pressed":O===e.userId,"aria-label":`Assignee ${e.label}`,title:e.userId===`__unassigned__`?`Tasks with no assigned admin`:`AdminUser ${e.userId}`,onClick:()=>k(O===e.userId?null:e.userId),children:[e.label,` `,(0,E.jsx)(`span`,{className:`tasks-assignee-count`,children:e.openCount})]},e.userId))]}),x===`open`?(0,E.jsxs)(`section`,{className:`admin-card tasks-card`,children:[(0,E.jsxs)(`div`,{className:`tasks-card-head`,children:[(0,E.jsx)(`span`,{className:`tasks-card-title`,children:`Open tasks`}),(0,E.jsxs)(`span`,{className:`tasks-card-count`,children:[q.length,` to do`]})]}),q.length===0&&(0,E.jsx)(`div`,{className:`tasks-empty`,children:`No open tasks.`}),q.map(e=>(0,E.jsxs)(`div`,{className:`tasks-row`,children:[(0,E.jsx)(`button`,{className:`tasks-row-open`,"aria-label":`Open task detail: ${e.name}`,onClick:()=>z(e.rowKey),children:(0,E.jsxs)(`div`,{className:`tasks-row-main`,children:[(0,E.jsx)(`div`,{className:`tasks-row-name`,children:e.name}),(0,E.jsx)(`div`,{className:`tasks-row-sub`,children:A(e,ee(e))})]})}),(0,E.jsx)(`div`,{className:`tasks-row-elapsed ${e.running?`tasks-row-elapsed-running`:``}`,children:m(j(e,b))}),(0,E.jsx)(`div`,{className:`tasks-row-controls`,children:e.taskId!==null&&B===e.taskId?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`span`,{className:`tasks-confirm-label`,children:`Complete?`}),(0,E.jsxs)(`button`,{className:`admin-btn-cta tasks-btn-action`,disabled:u,onClick:()=>{V(null),ne(e.taskId)},children:[(0,E.jsx)(c,{size:14}),` Confirm complete`]}),(0,E.jsxs)(`button`,{className:`tasks-btn-secondary tasks-btn-action`,onClick:()=>V(null),children:[(0,E.jsx)(l,{size:14}),` Keep open`]})]}):e.taskId===null?(0,E.jsx)(`span`,{className:`tasks-row-broken`,title:`This task has no id, so it cannot be started, edited or completed. Repair it by running platform/scripts/backfill-task-ids.sh on this install.`,children:`Needs repair`}):(0,E.jsxs)(E.Fragment,{children:[$(e,e.taskId),Q(e)?null:(0,E.jsxs)(`button`,{className:`tasks-btn-secondary tasks-btn-action`,"aria-label":`Complete task: ${e.name}`,disabled:u||e.running,title:e.running?`Stop the timer before completing`:void 0,onClick:()=>V(e.taskId),children:[(0,E.jsx)(c,{size:14}),` Complete`]}),Q(e)?null:e.running?(0,E.jsxs)(`button`,{className:`admin-btn-danger tasks-btn-action`,disabled:u,onClick:()=>void X(`/api/admin/task-timer-stop`,e.taskId),children:[(0,E.jsx)(s,{size:14}),` Stop`]}):(0,E.jsxs)(`button`,{className:`admin-btn-cta tasks-btn-action`,disabled:u,onClick:()=>void X(`/api/admin/task-timer-start`,e.taskId),children:[(0,E.jsx)(p,{size:14}),` Start`]})]})})]},e.rowKey))]}):(0,E.jsxs)(`section`,{className:`admin-card tasks-card`,children:[(0,E.jsxs)(`div`,{className:`tasks-card-head`,children:[(0,E.jsx)(`span`,{className:`tasks-card-title`,children:`Completed`}),(0,E.jsxs)(`span`,{className:`tasks-card-count`,children:[J.length,` done`]})]}),J.length===0&&(0,E.jsx)(`div`,{className:`tasks-empty`,children:`Nothing completed yet.`}),J.map(e=>(0,E.jsxs)(`div`,{className:`tasks-row tasks-row-done`,children:[(0,E.jsx)(`button`,{className:`tasks-row-open`,"aria-label":`Open task detail: ${e.name}`,onClick:()=>z(e.rowKey),children:(0,E.jsxs)(`div`,{className:`tasks-row-main`,children:[(0,E.jsx)(`div`,{className:`tasks-row-name`,children:e.name}),(0,E.jsx)(`div`,{className:`tasks-row-sub`,children:A(e,te(e))})]})}),(0,E.jsxs)(`div`,{className:`tasks-row-elapsed`,children:[m(e.secondsLogged),e.fee==null?``:` · £${e.fee}`]}),(0,E.jsx)(`div`,{className:`tasks-row-controls`,children:e.taskId===null?(0,E.jsx)(`span`,{className:`tasks-row-broken`,title:`This task has no id, so its logged time cannot be edited. Repair it by running platform/scripts/backfill-task-ids.sh on this install.`,children:`Needs repair`}):$(e,e.taskId)})]},e.rowKey))]})]})]})}function F({cacheKey:e}){let{adminFetch:t}=u({initialCacheKey:e,surface:`tasks`});return(0,E.jsx)(P,{adminFetch:t})}function I(){let[e,t]=(0,_.useState)(null),[r,i]=(0,_.useState)(!1),[a,s]=(0,_.useState)(void 0),[c,l]=(0,_.useState)(null),[u,p]=(0,_.useState)(null),[m,h]=(0,_.useState)(null),[g,v]=(0,_.useState)(null);(0,_.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(D)}catch{}if(!n){t(null),i(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async r=>{if(!e){if(r.status===401){try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`;return}if(r.ok)try{let e=await r.json();typeof e.businessName==`string`&&s(e.businessName),e.sessionId!==void 0&&l(e.sessionId??null),p(e.role??null),h(e.userName===void 0?null:e.userName),v(e.avatar??null)}catch{}t(n),i(!0)}}).catch(()=>{e||(t(n),i(!0))}),()=>{e=!0}},[]);let y=(0,_.useCallback)(()=>{try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`},[]),[b,x]=(0,_.useState)(!1),S=(0,_.useCallback)(async()=>{x(!0);try{let e=await f();if(e){try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`}return e}finally{x(!1)}},[]);return r?e?(0,E.jsx)(o,{cacheKey:e,surface:`tasks`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=tasks`);try{sessionStorage.removeItem(D)}catch{}window.location.href=`/`},children:(0,E.jsx)(d,{cacheKey:e,businessName:a,sessionId:c,onLogout:y,onDisconnect:S,disconnecting:b,userName:m,userAvatar:g,role:u,children:(0,E.jsx)(F,{cacheKey:e})})}):(0,E.jsx)(`div`,{className:`tasks-page`,children:(0,E.jsxs)(`div`,{className:`tasks-empty`,children:[(0,E.jsx)(`p`,{children:`You are not signed in.`}),(0,E.jsxs)(`p`,{children:[`Open the `,(0,E.jsx)(`a`,{href:`/`,className:`tasks-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,E.jsx)(`div`,{className:`tasks-page`,children:(0,E.jsxs)(`div`,{className:`tasks-loading`,children:[(0,E.jsx)(n,{size:18,className:`spin`}),` Loading…`]})})}(0,g.createRoot)(document.getElementById(`root`)).render((0,E.jsx)(I,{}));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./chunk-TPjIAO9U.js";import{H as t,n}from"./useSubAccountSwitcher-sPN6lobE.js";var r=e(t(),1);function i(e){let[t,i]=(0,r.useState)(`idle`),a=(0,r.useRef)(null),o=(0,r.useRef)(e?.onResult);return o.current=e?.onResult,(0,r.useEffect)(()=>()=>{a.current&&clearTimeout(a.current)},[]),{status:t,copy:(0,r.useCallback)(async e=>{let t=await n(e);i(t?`ok`:`fail`),o.current?.(t),a.current&&clearTimeout(a.current),a.current=setTimeout(()=>i(`idle`),1500)},[])}}export{i as t};
|