@rubytech/create-maxy-code 0.1.312 → 0.1.313

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/package.json +1 -1
  2. package/payload/platform/plugins/.claude-plugin/marketplace.json +5 -0
  3. package/payload/platform/plugins/admin/hooks/lib/maxy-mcp-plugins.txt +1 -0
  4. package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +37 -3
  5. package/payload/platform/plugins/docs/references/admin-ui.md +2 -2
  6. package/payload/platform/plugins/docs/references/quickbooks.md +29 -0
  7. package/payload/platform/plugins/quickbooks/.claude-plugin/plugin.json +21 -0
  8. package/payload/platform/plugins/quickbooks/PLUGIN.md +91 -0
  9. package/payload/platform/plugins/quickbooks/lib/mcp-spawn-tee/index.js +159 -0
  10. package/payload/platform/plugins/quickbooks/lib/mcp-spawn-tee/package.json +3 -0
  11. package/payload/platform/plugins/quickbooks/mcp/dist/index.d.ts +2 -0
  12. package/payload/platform/plugins/quickbooks/mcp/dist/index.d.ts.map +1 -0
  13. package/payload/platform/plugins/quickbooks/mcp/dist/index.js +218 -0
  14. package/payload/platform/plugins/quickbooks/mcp/dist/index.js.map +1 -0
  15. package/payload/platform/plugins/quickbooks/mcp/dist/lib/oauth.d.ts +37 -0
  16. package/payload/platform/plugins/quickbooks/mcp/dist/lib/oauth.d.ts.map +1 -0
  17. package/payload/platform/plugins/quickbooks/mcp/dist/lib/oauth.js +75 -0
  18. package/payload/platform/plugins/quickbooks/mcp/dist/lib/oauth.js.map +1 -0
  19. package/payload/platform/plugins/quickbooks/mcp/dist/lib/qbo-client.d.ts +39 -0
  20. package/payload/platform/plugins/quickbooks/mcp/dist/lib/qbo-client.d.ts.map +1 -0
  21. package/payload/platform/plugins/quickbooks/mcp/dist/lib/qbo-client.js +178 -0
  22. package/payload/platform/plugins/quickbooks/mcp/dist/lib/qbo-client.js.map +1 -0
  23. package/payload/platform/plugins/quickbooks/mcp/dist/lib/secrets.d.ts +36 -0
  24. package/payload/platform/plugins/quickbooks/mcp/dist/lib/secrets.d.ts.map +1 -0
  25. package/payload/platform/plugins/quickbooks/mcp/dist/lib/secrets.js +107 -0
  26. package/payload/platform/plugins/quickbooks/mcp/dist/lib/secrets.js.map +1 -0
  27. package/payload/platform/plugins/quickbooks/mcp/package.json +19 -0
  28. package/payload/platform/plugins/quickbooks/skills/quickbooks/SKILL.md +37 -0
  29. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.d.ts.map +1 -1
  30. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js +16 -0
  31. package/payload/platform/services/claude-session-manager/dist/canonical-tool-names.generated.js.map +1 -1
  32. package/payload/server/{chunk-J6WDAWFJ.js → chunk-Q7EWROVN.js} +4 -0
  33. package/payload/server/maxy-edge.js +1 -1
  34. package/payload/server/public/assets/{AccessGate-Dh5A79FU.js → AccessGate-Byskkf47.js} +1 -1
  35. package/payload/server/public/assets/{AdminLoginScreens-B8s2TbT7.js → AdminLoginScreens-DgwQi3HN.js} +1 -1
  36. package/payload/server/public/assets/AdminShell-DQfL2c_L.js +1 -0
  37. package/payload/server/public/assets/{Checkbox-B_sOAyv1.js → Checkbox-C54JSreC.js} +1 -1
  38. package/payload/server/public/assets/OperatorConversations-DulQyF8c.js +1 -0
  39. package/payload/server/public/assets/{admin-gZEndvJT.js → admin-B25rkI9Q.js} +1 -1
  40. package/payload/server/public/assets/{audio-attachment-mime-B0b89VnH.js → audio-attachment-mime-BlwrgPQa.js} +1 -1
  41. package/payload/server/public/assets/{brand-BcNavK6q.css → brand-TWflEl22.css} +1 -1
  42. package/payload/server/public/assets/{browser-BUlB5_MD.js → browser-C9Z5dLlN.js} +1 -1
  43. package/payload/server/public/assets/chat-CGNWDmid.js +1 -0
  44. package/payload/server/public/assets/data-DCQDh0-Y.js +1 -0
  45. package/payload/server/public/assets/{graph-labels-AZLGoVy8.js → graph-labels-BBtL--_M.js} +1 -1
  46. package/payload/server/public/assets/{graph-DMCKpW6P.js → graph-sMzOI71g.js} +2 -2
  47. package/payload/server/public/assets/operator-hI6kJi0I.js +1 -0
  48. package/payload/server/public/assets/page-DbsqlpuX.js +1 -0
  49. package/payload/server/public/assets/{public-G_-UI9nB.js → public-Cs5N4-Az.js} +1 -1
  50. package/payload/server/public/assets/{public-next-C8_nExQB.js → public-next-DoGPYX6T.js} +1 -1
  51. package/payload/server/public/assets/{useSelectionMode-Bf6Rt-sl.js → useSelectionMode-Cs-vtuKI.js} +1 -1
  52. package/payload/server/public/browser.html +6 -6
  53. package/payload/server/public/chat.html +8 -8
  54. package/payload/server/public/data.html +5 -5
  55. package/payload/server/public/graph.html +8 -8
  56. package/payload/server/public/index.html +8 -8
  57. package/payload/server/public/operator.html +10 -10
  58. package/payload/server/public/public-next.html +9 -9
  59. package/payload/server/public/public.html +7 -7
  60. package/payload/server/server.js +600 -491
  61. package/payload/server/public/assets/AdminShell-Cu1zlb6L.js +0 -1
  62. package/payload/server/public/assets/OperatorConversations-hm0Gpu_Q.js +0 -1
  63. package/payload/server/public/assets/chat-BnceaVl7.js +0 -1
  64. package/payload/server/public/assets/data-3Nl3P5wt.js +0 -1
  65. package/payload/server/public/assets/operator-BF4F7k23.js +0 -1
  66. package/payload/server/public/assets/page-DQUEst1o.js +0 -1
  67. /package/payload/server/public/assets/{brand-BQ_u9UdS.js → brand-CYjs10m-.js} +0 -0
@@ -1 +0,0 @@
1
- import{o as e}from"./chunk-CAM3fms7.js";import{c as t,o as n,s as r,t as i,u as a}from"./brand-BQ_u9UdS.js";import{_ as o,b as s,c,d as l,g as u,l as d,p as f,s as p,t as m,u as h,x as g}from"./OperatorConversations-hm0Gpu_Q.js";import{i as _,t as v}from"./useSelectionMode-Bf6Rt-sl.js";async function ee(){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 y=t(`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`}]]),b=t(`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`}]]),x=t(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),te=t(`box`,[[`path`,{d:`M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z`,key:`hh9hay`}],[`path`,{d:`m3.3 7 8.7 5 8.7-5`,key:`g66t2b`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}]]),S=t(`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`}]]),ne=t(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),C=t(`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`}]]),w=t(`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`}]]),T=t(`plus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]),re=t(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),E=t(`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`}]]),D=e(a(),1),O=n(),k=`maxy-shell-side-px`;function A(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .artefact`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function j(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=Math.max(248,t-480-A());return Math.min(Math.max(e,248),n)}function M(){if(typeof window>`u`)return 264;try{let e=window.localStorage.getItem(k);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 j(t)}catch{}return 264}function N({targetSelector:e=`.platform`}){let t=(0,D.useRef)(null),[n,r]=(0,D.useState)(()=>M()),i=(0,D.useRef)(n);(0,D.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,D.useCallback)(()=>{r(e=>{let t=j(e);return t===e?e:t})},[]);(0,D.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(j(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(k,String(t))}catch{}console.info(`[admin-ui] sidebar-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=j(264);r(e);try{window.localStorage.removeItem(k)}catch{}console.info(`[admin-ui] sidebar-resize px=${e}`)};return(0,O.jsx)(`div`,{ref:t,className:`side-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize sidebar`,onPointerDown:o,onDoubleClick:s})}function ie({actions:e,disabled:t,collapsed:n}){let[r,i]=(0,D.useState)(!1),a=(0,D.useRef)(null);return(0,D.useEffect)(()=>{if(!r)return;let e=e=>{e.key===`Escape`&&i(!1)},t=e=>{a.current?.contains(e.target)||i(!1)};return document.addEventListener(`keydown`,e),document.addEventListener(`pointerdown`,t),()=>{document.removeEventListener(`keydown`,e),document.removeEventListener(`pointerdown`,t)}},[r]),(0,D.useEffect)(()=>{n||i(!1)},[n]),n?(0,O.jsxs)(`div`,{className:`conv-actions`,ref:a,children:[(0,O.jsx)(`button`,{type:`button`,className:`conv-action conv-actions-overflow`,onClick:()=>i(e=>!e),disabled:t,"aria-haspopup":`menu`,"aria-expanded":r,"aria-label":`Session actions`,title:`Session actions`,children:(0,O.jsx)(S,{size:12})}),r&&(0,O.jsx)(`div`,{className:`conv-actions-menu`,role:`menu`,children:e.map(e=>(0,O.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),i(!1)},children:[e.icon,(0,O.jsx)(`span`,{children:e.label})]},e.key))})]}):(0,O.jsx)(`div`,{className:`conv-actions`,children:e.map(e=>(0,O.jsx)(`button`,{type:`button`,className:e.danger?`conv-action conv-action-danger`:`conv-action`,onClick:e.onClick,disabled:t,"aria-busy":e.busy,"aria-label":e.label,title:e.title,children:e.icon},e.key))})}var ae=[`whatsapp`,`telegram`];function oe(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 P(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}var se=`auth-refresh-failed`;function ce({error:e,onClose:t}){if(!e)return null;let n=e.reason===se,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,O.jsx)(`div`,{className:`claude-info-overlay`,onClick:t,children:(0,O.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),role:`alertdialog`,"aria-label":`Session could not be opened`,children:[(0,O.jsxs)(`div`,{className:`claude-info-header`,children:[(0,O.jsx)(`span`,{children:r}),(0,O.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:`✕`})]}),(0,O.jsxs)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:[i,(0,O.jsxs)(`div`,{className:`claude-info-row`,style:{marginTop:`8px`},children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Reason`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:e.reason})]}),e.sessionId&&(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,O.jsxs)(`span`,{className:`claude-info-value`,children:[e.sessionId.slice(0,8),`…`]})]})]})]})})}function F(e){let{show:t,onClose:n,claudeInfo:r,messages:i,sessionElapsed:a,sessionId:o,cacheKey:s}=e,[c,l]=(0,D.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,O.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,O.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,O.jsxs)(`div`,{className:`claude-info-header`,children:[(0,O.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`claude-info-icon`}),(0,O.jsx)(`span`,{children:`Claude Code`}),(0,O.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,O.jsxs)(`div`,{className:`claude-info-section`,children:[(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Version`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:r?r.version:`…`})]}),(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Email`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:r?.account?.email??`…`})]})]}),(g||m||h>0)&&(0,O.jsxs)(`div`,{className:`claude-info-section`,children:[g&&(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Plan`}),(0,O.jsx)(`span`,{className:`claude-info-value`,style:{textTransform:`capitalize`},children:g})]}),m&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Usage`}),(0,O.jsxs)(`span`,{className:`claude-info-value`,children:[Math.round(m.utilization*100),`%`]})]}),(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Resets in`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:_(m.resetsAt)})]}),m.isUsingOverage&&(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Overage`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:`Active`})]})]}),h>0&&(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Session cost`}),(0,O.jsxs)(`span`,{className:`claude-info-value`,children:[`$`,h<.01?h.toFixed(4):h.toFixed(2)]})]})]}),(0,O.jsxs)(`div`,{className:`claude-info-section`,children:[(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Model`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:r?.model??`…`})]}),(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Context used`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:f>0?`${f}%`:`—`})]}),(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Tokens`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:p>0?P(p):`—`})]}),(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,O.jsx)(`span`,{className:`claude-info-value`,children:oe(a)})]}),(o||s)&&(()=>{let e=o??s??``;return(0,O.jsxs)(`div`,{className:`claude-info-row`,children:[(0,O.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,O.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 v(e)?`copied`:`failed`),setTimeout(()=>l(null),1200)},children:c===`copied`?`copied ✓`:c===`failed`?`copy failed ✕`:`${e.slice(0,8)}…`})]})})()]})]})})}var le=`https://claude.ai/code`,ue=200,de=[500,1e3,1500,2e3,2500,3e3,3e3];function fe(e,t,n){if(e&&n.target)return{kind:`navigate`,url:n.target};let r=n.slug??n.bridgeSessionId??null;if(e&&r)return{kind:`navigate`,url:`${le}/${r}`};let i=n.reason||n.error||`status ${t}`;return{kind:`error`,sessionId:n.sessionId??null,reason:i}}function pe(e){if(!e)return``;let t=Date.parse(e);return Number.isFinite(t)?new Date(t).toLocaleString(void 0,{dateStyle:`medium`,timeStyle:`short`}):``}function I(e){let{businessName:t,cacheKey:n,role:a,userName:l,userAvatar:m,onSelectProjects:v,onSelectPeople:ee,onSelectTasks:S,onSelectAgents:k,onCloseMobileDrawer:A,collapsed:j,selectedWhatsappId:M,onSelectWhatsappConversation:N,initialWhatsappSurface:oe=!1}=e,P=f(n),se=i.productName,F=typeof l==`string`?l:l===null?`name unavailable`:t||se,le=(F.trim().charAt(0)||`?`).toUpperCase(),[I,L]=(0,D.useState)(oe?`whatsapp`:`sessions`),[R,ge]=(0,D.useState)([]),[z,_e]=(0,D.useState)(!1),[B,ve]=(0,D.useState)(null),[V,ye]=(0,D.useState)(!1),[H,be]=(0,D.useState)(`file`),[U,W]=(0,D.useState)(null),[xe,G]=(0,D.useState)(null),[K,Se]=(0,D.useState)([]),[q,Ce]=(0,D.useState)(!1),[we,Te]=(0,D.useState)(null),[Ee,De]=(0,D.useState)(!1),[Oe,ke]=(0,D.useState)(!1),[Ae,je]=(0,D.useState)(!1),[Me,Ne]=(0,D.useState)(null),[Pe,Fe]=(0,D.useState)(new Set),[Ie,Le]=(0,D.useState)(new Set),[Re,ze]=(0,D.useState)(new Set),[Be,Ve]=(0,D.useState)(new Set),[He,J]=(0,D.useState)(null),[Ue,Y]=(0,D.useState)(``),[We,Ge]=(0,D.useState)(!1),[X,Ke]=(0,D.useState)(!1),qe=(0,D.useRef)(null),[Je,Ye]=(0,D.useState)(0);(0,D.useEffect)(()=>{let e=qe.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(e=>{let t=e[0]?.contentRect.width??0;Ye(e=>Math.abs(e-t)<1?e:t)});return t.observe(e),()=>t.disconnect()},[I]);let Xe=Je>0&&Je<280,[Ze,Qe]=(0,D.useState)([]),[$e,et]=(0,D.useState)(!1),[tt,nt]=(0,D.useState)(null),[Z,rt]=(0,D.useState)(`whatsapp`),it=(0,D.useCallback)(e=>{if(A(),!n){console.error(`[admin-ui] artefact-download-blocked id=${e.id} reason=no-cache-key`),W({message:`Session not ready — try again`,failed:!0});return}if(!e.downloadPath){console.error(`[admin-ui] artefact-download-blocked id=${e.id} reason=not-downloadable`),W({message:`${e.name} can’t be downloaded`,failed:!0});return}console.info(`[admin-ui] artefact-download id=${e.id} root=${e.downloadRoot??`data`} path=${e.downloadPath}`),p(n,e.downloadPath,e.downloadRoot??`data`),W({message:`Downloading ${e.name}`,failed:!1})},[n,A]);(0,D.useEffect)(()=>{if(!U)return;let e=setTimeout(()=>W(null),2500);return()=>clearTimeout(e)},[U]);let at=(0,D.useCallback)(async()=>{if(n){ye(!0),ve(null);try{let e=await P(`/api/admin/sidebar-artefacts`);if(!e.ok)throw Error(`status ${e.status}`);ge((await e.json()).artefacts??[]),_e(!0)}catch(e){let t=e instanceof Error?e.message:String(e);ve(`Failed to load artefacts: ${t}`),console.error(`[admin-ui] sidebar-artefacts fetch failed: ${t}`)}finally{ye(!1)}}},[n,P]),Q=(0,D.useCallback)(async()=>{if(!n)return null;De(!0),Te(null);try{let e=await P(`/api/admin/sidebar-sessions`);if(!e.ok)throw Error(`status ${e.status}`);let t=await e.json(),n=t.sessions??[];return Se(n),Ne(t.accountId??null),Ce(!0),n}catch(e){let t=e instanceof Error?e.message:String(e);return Te(`Failed to load sessions: ${t}`),console.error(`[admin-ui] sidebar-sessions fetch failed: ${t}`),null}finally{De(!1)}},[n,P]),ot=(0,D.useCallback)(async()=>{if(n){nt(null);try{let e=await P(`/api/whatsapp-reader/conversations`);if(!e.ok)throw Error(`status ${e.status}`);Qe((await e.json()).conversations??[]),et(!0)}catch(e){let t=e instanceof Error?e.message:String(e);nt(`Couldn't load conversations.`),console.error(`[admin-ui] channel-convos fetch failed: ${t}`)}}},[n,P]);(0,D.useEffect)(()=>{!n||q||Q()},[n,q,Q]),(0,D.useEffect)(()=>{if(!n)return;let e=null;return ot(),e=setInterval(()=>{ot()},me),()=>{e!==null&&clearInterval(e)}},[n,ot]);let st=(0,D.useMemo)(()=>{let e=new Map;for(let t of ae)e.set(t,[]);for(let t of Ze)e.get(t.channel)?.push(t);for(let t of ae)console.info(`[admin-ui] sidebar-nav surface=${t} count=${e.get(t).length}`);return e},[Ze]),ct={whatsapp:`WhatsApp`,telegram:`Telegram`,webchat:`Webchat`},lt=()=>{N(null),L(`artefacts`),console.info(`[admin-ui] sidebar-nav surface=artefacts count=${z?R.length:0} collapsed=${j}`),at()},$=1.5,ut=()=>{console.info(`[admin-ui] sidebar-refresh surface=artefacts`),at()},dt=()=>{N(null),L(`sessions`),console.info(`[admin-ui] sidebar-nav surface=sessions count=${q?K.length:0} collapsed=${j}`),q||Q()},ft=()=>{console.info(`[admin-ui] sidebar-refresh surface=sessions`),Q()},pt=e=>{L(`whatsapp`),rt(e),console.info(`[admin-ui] sidebar-nav surface=${e} count=${st.get(e)?.length??0} collapsed=${j}`)},mt=(0,D.useCallback)(async e=>{if(Ie.has(e.sessionId))return;Le(t=>{let n=new Set(t);return n.add(e.sessionId),n});let t=window.open(``,`_blank`);try{let n=await P(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e.sessionId,name:e.title||e.sessionId})}),r=await n.json().catch(()=>({})),i=fe(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`?(A(),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}`),G(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}`),G({sessionId:e.sessionId,reason:r})}finally{Le(t=>{let n=new Set(t);return n.delete(e.sessionId),n})}},[P,A,Ie]),ht=(0,D.useCallback)(async e=>{let t=e.slice(0,8);for(let n=1;n<=de.length;n++){await new Promise(e=>setTimeout(e,de[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]),gt=(0,D.useCallback)(async()=>{if(X)return;Ke(!0);let e=window.open(``,`_blank`);try{let t=await P(`/api/admin/session-rc-spawn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}),n=await t.json().catch(()=>({})),r=fe(t.ok,t.status,n);console.info(`[admin-ui] sidebar-new-session-spawned status=${t.status} outcome=${r.kind} slug=${n.slug??n.bridgeSessionId??`none`}`),r.kind===`navigate`?(e?e.location.href=r.url:window.open(r.url,`_blank`),n.sessionId?ht(n.sessionId):console.error(`[admin-ui] sidebar-new-session-converge-skipped reason=no-session-id`)):(e?.close(),console.error(`[admin-ui] sidebar-new-session-failed status=${t.status} reason=${r.reason}`),G(r))}catch(t){e?.close();let n=t instanceof Error?t.message:String(t);console.error(`[admin-ui] sidebar-new-session-failed error=${n}`),G({sessionId:null,reason:n})}finally{Ke(!1)}},[P,X,ht]),_t=(0,D.useCallback)(async(e,t)=>{if(e.stopPropagation(),!Pe.has(t.sessionId)){Fe(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await P(`/api/admin/session-delete`,{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-delete-failed sessionId=${t.sessionId} status=${e.status} error=${n.error??`unknown`}`),W({message:`Delete failed: ${n.error??`status ${e.status}`}`,failed:!0});return}let n=await e.json();console.info(`[admin-ui] sidebar-session-delete sessionId=${t.sessionId} pidKilled=${n.pidKilled??`?`} deleted=${n.deleted??`?`}`),Se(e=>e.filter(e=>e.sessionId!==t.sessionId)),Q()}catch(e){let n=e instanceof Error?e.message:String(e);console.error(`[admin-ui] sidebar-session-delete-failed sessionId=${t.sessionId} error=${n}`),W({message:`Delete failed: ${n}`,failed:!0})}finally{Fe(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[P,Pe,Q]),vt=(0,D.useCallback)(async(e,t)=>{if(e.stopPropagation(),!Re.has(t.sessionId)){ze(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await P(`/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`}`),W({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}`),W({message:`Stop failed: ${n}`,failed:!0})}finally{ze(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[P,Re,Q]),yt=(0,D.useCallback)(async(e,t,n)=>{if(e.stopPropagation(),!Be.has(t.sessionId)){Ve(e=>{let n=new Set(e);return n.add(t.sessionId),n});try{let e=await P(`/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`}`),W({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}`),W({message:`${n===`archive`?`Archive`:`Unarchive`} failed: ${r}`,failed:!0})}finally{Ve(e=>{let n=new Set(e);return n.delete(t.sessionId),n})}}},[P,Be,Q]),bt=(0,D.useCallback)(async e=>{let t=Ue.trim();if(!t){W({message:`Title can’t be empty`,failed:!0});return}if(t.length>ue){W({message:`Title too long (max ${ue})`,failed:!0});return}Ge(!0);try{let n=await P(`/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}`),W({message:`Rename failed: ${r}`,failed:!0});return}console.info(`[admin-ui] sidebar-session-rename sessionId=${e.sessionId.slice(0,8)} outcome=ok`),J(null),Y(``),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}`),W({message:`Rename failed: ${n}`,failed:!0})}finally{Ge(!1)}},[P,Ue,Q]);return(0,O.jsxs)(`aside`,{className:`side`,children:[(0,O.jsx)(`div`,{className:`side-new-session-row`,children:(0,O.jsxs)(`button`,{type:`button`,className:`side-new-session`,onClick:gt,disabled:X,"aria-busy":X,children:[(0,O.jsx)(T,{size:14}),(0,O.jsx)(`span`,{children:X?`Spawning…`:`New session`})]})}),(0,O.jsxs)(`nav`,{className:`side-nav`,children:[(0,O.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=people`),ee(),A()},children:[(0,O.jsx)(E,{size:20,strokeWidth:$}),(0,O.jsx)(`span`,{className:`label`,children:`People`}),(0,O.jsx)(`span`,{className:`kbd`})]}),(0,O.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=agents`),k(),A()},children:[(0,O.jsx)(x,{size:20,strokeWidth:$}),(0,O.jsx)(`span`,{className:`label`,children:`Agents`}),(0,O.jsx)(`span`,{className:`kbd`})]}),(0,O.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=projects`),v(),A()},children:[(0,O.jsx)(te,{size:20,strokeWidth:$}),(0,O.jsx)(`span`,{className:`label`,children:`Projects`}),(0,O.jsx)(`span`,{className:`kbd`})]}),(0,O.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=tasks`),S(),A()},children:[(0,O.jsx)(C,{size:20,strokeWidth:$}),(0,O.jsx)(`span`,{className:`label`,children:`Tasks`}),(0,O.jsx)(`span`,{className:`kbd`})]}),(0,O.jsxs)(`button`,{type:`button`,className:`nav-row${I===`artefacts`?` active`:``}`,onClick:lt,children:[(0,O.jsx)(_,{size:20,strokeWidth:$}),(0,O.jsx)(`span`,{className:`label`,children:`Artefacts`}),(0,O.jsx)(`span`,{className:`kbd`})]}),(0,O.jsxs)(`button`,{type:`button`,className:`nav-row${I===`sessions`?` active`:``}`,onClick:dt,children:[(0,O.jsx)(ne,{size:20,strokeWidth:$}),(0,O.jsx)(`span`,{className:`label`,children:`Sessions`}),(0,O.jsx)(`span`,{className:`kbd`})]}),$e&&ae.filter(e=>st.get(e).length>0).map(e=>(0,O.jsxs)(`button`,{type:`button`,className:`nav-row${I===`whatsapp`&&Z===e?` active`:``}`,onClick:()=>pt(e),children:[(0,O.jsx)(d,{channel:e,size:16}),(0,O.jsx)(`span`,{className:`label`,children:ct[e]}),(0,O.jsx)(`span`,{className:`kbd`})]},e)),tt&&(0,O.jsx)(`div`,{className:`nav-row`,style:{color:`var(--text-tertiary)`,cursor:`default`},"aria-disabled":`true`,children:(0,O.jsx)(`span`,{className:`label`,children:tt})})]}),I===`artefacts`&&(0,O.jsxs)(`div`,{className:`side-list`,children:[(0,O.jsxs)(`div`,{className:`group-head`,children:[(0,O.jsx)(`span`,{children:`Artefacts`}),(0,O.jsxs)(`span`,{className:`group-head-meta`,children:[(0,O.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh artefacts`,"aria-label":`Refresh artefacts`,onClick:ut,disabled:V,children:(0,O.jsx)(u,{size:12,className:V?`spinning`:void 0})}),(0,O.jsx)(`span`,{children:V?`…`:String(R.length)})]})]}),B&&(0,O.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:B}),z&&!B&&R.length>0&&(()=>{let e=R.filter(e=>e.kind===`agent-template`).length,t=R.length-e;return(0,O.jsx)(`div`,{className:`artefact-filter-chips`,children:[{key:`all`,label:`All`,count:R.length},{key:`agent`,label:`Agents`,count:e},{key:`file`,label:`Files`,count:t}].map(e=>(0,O.jsxs)(`button`,{type:`button`,className:`artefact-filter-chip${H===e.key?` active`:``}`,onClick:()=>be(e.key),disabled:e.count===0&&e.key!==`all`,children:[e.label,(0,O.jsx)(`span`,{className:`artefact-filter-chip-count`,children:e.count})]},e.key))})})(),z&&!B&&R.length===0&&(0,O.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No artefacts yet`}),R.filter(e=>H===`all`?!0:H===`agent`?e.kind===`agent-template`:e.kind!==`agent-template`).map(e=>{let t=e.kind===`agent-template`,n=t?x:_,r=pe(e.updatedAt),i=e.downloadPath!==null;return(0,O.jsxs)(`button`,{type:`button`,className:`conv`,onClick:()=>it(e),disabled:!i,style:i?void 0:{cursor:`default`},title:i?`Download ${e.name}`:`${e.name} can’t be downloaded`,children:[(0,O.jsx)(n,{size:14,className:`conv-icon`,"data-kind":t?`agent`:`file`,"aria-label":t?`agent template`:`file`}),(0,O.jsxs)(`span`,{className:`conv-stack`,children:[(0,O.jsx)(`span`,{className:`conv-name-line`,children:(0,O.jsx)(`span`,{className:`conv-name`,children:e.name})}),r&&(0,O.jsx)(`span`,{className:`conv-timestamp`,children:r})]}),i&&(0,O.jsx)(g,{size:12,className:`conv-rc-icon`,"aria-hidden":`true`})]},e.id)})]}),I===`sessions`&&(()=>{let e=K.filter(e=>Oe?!0:!e.isSubagent).filter(e=>Ae?!0:!e.archived),t=K.some(e=>e.isSubagent),n=K.some(e=>e.archived);return(0,O.jsxs)(`div`,{className:`side-list`,ref:qe,children:[(0,O.jsxs)(`div`,{className:`group-head`,children:[(0,O.jsx)(`span`,{children:`Sessions`}),(0,O.jsxs)(`span`,{className:`group-head-meta`,children:[(0,O.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh sessions`,"aria-label":`Refresh sessions`,onClick:ft,disabled:Ee,children:(0,O.jsx)(u,{size:12,className:Ee?`spinning`:void 0})}),(0,O.jsx)(`span`,{children:Ee?`…`:String(e.length)})]})]}),Me&&(0,O.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,O.jsx)(`code`,{children:Me})}),(t||n)&&(0,O.jsxs)(`div`,{className:`artefact-filter-chips`,children:[t&&(0,O.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${Oe?` active`:``}`,onClick:()=>ke(e=>!e),title:Oe?`Hide subagent sessions`:`Show subagent sessions`,children:`Subagents`}),n&&(0,O.jsx)(`button`,{type:`button`,className:`artefact-filter-chip${Ae?` active`:``}`,onClick:()=>je(e=>!e),title:Ae?`Hide archived sessions`:`Show archived sessions`,children:`Archived`})]}),we&&(0,O.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:we}),q&&!we&&e.length===0&&(0,O.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No sessions yet`}),e.map(e=>{let t=pe(e.startedAt),n=Ie.has(e.sessionId),i=Pe.has(e.sessionId),a=Re.has(e.sessionId),c=Be.has(e.sessionId),l=n||i||a||c,u=[{key:`open`,label:`Resume session ${e.title} in claude.ai/code`,title:`Resume in a fresh local Remote Control PTY`,icon:(0,O.jsx)(s,{size:12}),busy:n,onClick:()=>{mt(e)}},{key:`message`,label:`Open session ${e.title} in admin webchat`,title:`Open in admin webchat (/chat) — sending resumes this session`,icon:(0,O.jsx)(w,{size:12}),onClick:()=>{window.location.assign(`/chat?session=${e.sessionId}`)}},...e.live?[{key:`stop`,label:`Stop session ${e.title}`,title:`Stop session process (keeps the conversation, can resume later)`,icon:(0,O.jsx)(re,{size:12}),busy:a,onClick:t=>{vt(t,e)}}]:[],e.archived?{key:`unarchive`,label:`Unarchive session ${e.title}`,title:`Unarchive (move back to the active list)`,icon:(0,O.jsx)(y,{size:12}),busy:c,onClick:t=>{yt(t,e,`unarchive`)}}:{key:`archive`,label:`Archive session ${e.title}`,title:`Archive (hide from the list, keeps the conversation resumable)`,icon:(0,O.jsx)(b,{size:12}),busy:c,onClick:t=>{yt(t,e,`archive`)}},{key:`rename`,label:`Rename session ${e.title}`,title:`Rename this session`,icon:(0,O.jsx)(o,{size:12}),busy:We&&He===e.sessionId,onClick:t=>{t.stopPropagation(),J(e.sessionId),Y(e.personName??e.title)}},{key:`delete`,label:`Delete session ${e.title}`,title:`Delete session (stops the process, removes the conversation)`,icon:(0,O.jsx)(r,{size:12}),danger:!0,busy:i,onClick:t=>{_t(t,e)}}];return(0,O.jsxs)(`div`,{className:`conv conv-with-actions`,children:[(0,O.jsxs)(`div`,{className:`conv-main-static`,children:[(0,O.jsx)(`span`,{className:`conv-live-dot`,"data-live":e.live?`1`:`0`,"aria-label":e.live?`live session`:`ended session`}),(0,O.jsxs)(`span`,{className:`conv-stack`,children:[(0,O.jsxs)(`span`,{className:`conv-name-line`,children:[e.channel&&(0,O.jsx)(h,{channel:e.channel,size:13}),He===e.sessionId?(0,O.jsx)(`input`,{className:`conv-name conv-name-edit`,autoFocus:!0,value:Ue,disabled:We,"aria-label":`New title for session ${e.title}`,onChange:e=>Y(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),bt(e)):t.key===`Escape`&&(t.preventDefault(),J(null),Y(``))},onBlur:()=>{He===e.sessionId&&!We&&(J(null),Y(``))}}):(0,O.jsx)(`span`,{className:`conv-name`,title:e.personName??e.title,children:e.personName??e.title})]}),(0,O.jsxs)(`span`,{className:`conv-timestamp`,children:[(0,O.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,O.jsxs)(`span`,{children:[` · `,t]})]})]})]}),(0,O.jsx)(ie,{actions:u,disabled:l,collapsed:Xe})]},e.sessionId)})]})})(),I===`whatsapp`&&(0,O.jsxs)(`div`,{className:`side-list`,children:[(0,O.jsxs)(`div`,{className:`group-head`,children:[(0,O.jsx)(`span`,{children:ct[Z]}),(0,O.jsxs)(`span`,{className:`group-head-meta`,children:[(0,O.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh conversations`,"aria-label":`Refresh conversations`,onClick:()=>{ot()},children:(0,O.jsx)(u,{size:12})}),(0,O.jsx)(`span`,{children:String(st.get(Z).length)})]})]}),st.get(Z).map(e=>{let t=pe(e.lastMessageAt);return(0,O.jsxs)(`button`,{type:`button`,className:`conv${M===e.sessionId?` active`:``}`,onClick:()=>{N(e),A()},title:e.title,children:[(0,O.jsx)(d,{channel:e.channel,size:14}),(0,O.jsxs)(`span`,{className:`conv-stack`,children:[(0,O.jsxs)(`span`,{className:`conv-name-line`,children:[(0,O.jsx)(`span`,{className:`conv-name`,children:c(e)}),e.role===`public`&&(0,O.jsx)(`span`,{className:`conv-tag conv-tag-public`,children:`Public`})]}),t&&(0,O.jsx)(`span`,{className:`conv-timestamp`,children:t})]})]},e.sessionId)})]}),(0,O.jsx)(he,{}),(0,O.jsxs)(`div`,{className:`side-foot`,children:[(0,O.jsx)(`div`,{className:`avatar`,children:m?(0,O.jsx)(`img`,{src:m,alt:F}):le}),(0,O.jsxs)(`div`,{className:`who`,children:[(0,O.jsx)(`span`,{className:`name`,children:F}),(0,O.jsx)(`span`,{className:`role`,children:a??`operator`})]})]}),U&&(0,O.jsx)(`div`,{className:`copy-toast${U.failed?` copy-toast-failed`:``}`,role:`status`,children:U.message}),(0,O.jsx)(ce,{error:xe,onClose:()=>G(null)})]})}var L=5e3,me=3e4;function he(){let[e,t]=(0,D.useState)(null);if((0,D.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()},L))}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=e=>{if(e===null)return{width:`0%`,background:`var(--text-tertiary)`};let t=Math.min(1,Math.max(0,e)),n=Math.round(140*(1-t));return{width:`${Math.round(t*100)}%`,background:`hsl(${n}, 65%, 45%)`}},f=[`system-stats`];return c&&f.push(`system-stats--warn`),l&&f.push(`system-stats--crit`),(0,O.jsxs)(`div`,{className:f.join(` `),role:`status`,"aria-label":`host CPU and RAM`,children:[(0,O.jsxs)(`div`,{className:`system-stats__metric`,children:[(0,O.jsxs)(`span`,{className:i?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`CPU `,u(n)]}),(0,O.jsx)(`div`,{className:`system-stats__bar`,children:(0,O.jsx)(`div`,{className:`system-stats__bar-fill`,style:d(n)})})]}),(0,O.jsxs)(`div`,{className:`system-stats__metric`,children:[(0,O.jsxs)(`span`,{className:o?`system-stats__fig system-stats__fig--warn`:`system-stats__fig`,children:[`RAM `,u(r)]}),(0,O.jsx)(`div`,{className:`system-stats__bar`,children:(0,O.jsx)(`div`,{className:`system-stats__bar-fill`,style:d(r)})})]})]})}var R=`admin-sidebar-collapsed`,ge=`admin-sidebar-drawer-open`;function z(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(R)===`1`}catch{return!1}}function _e(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(R,`1`):window.sessionStorage.removeItem(R)}catch{}}function B(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(ge)===`1`}catch{return!1}}function ve(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(ge,`1`):window.sessionStorage.removeItem(ge)}catch{}}var V=720;function ye(e,t){return e===`/`?{via:`in-place`}:{via:`navigate`,href:`/?wa=${encodeURIComponent(t.sessionId)}&projectDir=${encodeURIComponent(t.projectDir)}`}}function H(e,t){if(e!==`/`)return null;let n=new URLSearchParams(t),r=n.get(`wa`),i=n.get(`projectDir`);return!r||!i?null:{sessionId:r,projectDir:i,title:``,senderId:null,startedAt:``,channel:`whatsapp`,role:`admin`,operatorName:null,whatsappName:null,lastMessageAt:null,modelGated:!1}}function be(e,t){return t===`operator`&&e===`chat`||e===`dashboard`?`/`:e===`data`?`/data`:e===`graph`?`/graph`:e===`chat`?`/chat`:`/browser`}function U(e){let{cacheKey:t,businessName:n,variant:r=`admin`,onLogout:i,onDisconnect:a,disconnecting:o,userName:s,userAvatar:c,role:u,children:d,footer:f}=e,[p,h]=(0,D.useState)(()=>z()),[g,_]=(0,D.useState)(()=>B()),[v,ee]=(0,D.useState)(()=>typeof window<`u`&&window.matchMedia(`(max-width: ${V}px)`).matches),[y,b]=(0,D.useState)(()=>typeof window>`u`?null:H(window.location.pathname,window.location.search)),[x]=(0,D.useState)(()=>y!==null);(0,D.useEffect)(()=>{if(typeof window>`u`)return;let e=window.matchMedia(`(max-width: ${V}px)`),t=e=>ee(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let te=(0,D.useCallback)(e=>{_e(e),h(e)},[]),S=(0,D.useCallback)(e=>{ve(e),_(e)},[]);(0,D.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=${p} drawer=${g}`)},[]),(0,D.useEffect)(()=>{typeof window>`u`||!y||(console.info(`[admin-ui] wa-hydrate route=/ sessionId=${y.sessionId.slice(0,8)}`),window.history.replaceState(null,``,`/`))},[]);let ne=(0,D.useCallback)(e=>{if(e===null){b(null);return}let t=typeof window<`u`?window.location.pathname:`/`,n=ye(t,e);console.info(`[admin-ui] wa-open route=${t} via=${n.via} sessionId=${e.sessionId.slice(0,8)}`),n.via===`in-place`?b(e):window.location.href=n.href},[]),C=v?g:!p,w=(0,D.useCallback)(()=>{if(!(typeof window>`u`))if(window.matchMedia(`(max-width: ${V}px)`).matches){let e=g;console.info(`[admin-ui] header-sidebar-toggle from=${e?`open`:`closed`} mode=drawer`),S(!e)}else{let e=p;console.info(`[admin-ui] header-sidebar-toggle from=${e?`closed`:`open`} mode=collapse`),te(!e)}},[p,g,te,S]),T=(0,D.useCallback)(e=>{let t=be(e,r);console.info(`[admin-ui] header-menu-nav target=${e} dest=${t}`),window.location.href=t},[r]),[re,E]=(0,D.useState)(`chat`),[k,A]=(0,D.useState)([]);(0,D.useEffect)(()=>{if(r!==`operator`||!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||A(t.conversations??[])}).catch(()=>{}),()=>{e=!0}},[r,t]);let j=(0,D.useMemo)(()=>[...new Set(k.map(e=>e.channel))],[k]),M={collapsed:p,mobileDrawerOpen:g,sidebarOpen:C,onToggleSidebar:w,setMobileDrawerOpen:S,selectedWhatsapp:y,onClearWhatsapp:()=>b(null)};return r===`operator`?(0,O.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[(0,O.jsx)(l,{businessName:n,variant:r,onNavigate:T,conversationsCount:k.length,conversationsChannels:j,onOpenConversations:()=>E(`conversations`),onToggleSidebar:w,sidebarOpen:C,onLogout:i,onDisconnect:a,disconnecting:o}),(0,O.jsx)(`div`,{className:`platform platform-operator`,children:re===`conversations`?(0,O.jsx)(m,{conversations:k,sessionKey:t??``,onBack:()=>E(`chat`)}):typeof d==`function`?d(M):d}),f]}):(0,O.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[(0,O.jsx)(l,{businessName:n,variant:r,onNavigate:T,onToggleSidebar:w,sidebarOpen:C,onLogout:i,onDisconnect:a,disconnecting:o}),(0,O.jsxs)(`div`,{className:`platform${g?` menu-open`:``}${p?` sidebar-collapsed`:``}`,"data-artefact":`closed`,children:[(0,O.jsx)(I,{businessName:n,cacheKey:t,role:u??null,userName:s,userAvatar:c??null,onSelectProjects:()=>{window.location.href=`/graph?label=Project`},onSelectPeople:()=>{window.location.href=`/graph?label=Person`},onSelectTasks:()=>{window.location.href=`/graph?label=Task`},onSelectAgents:()=>{window.location.href=`/graph?label=Agent`},onCloseMobileDrawer:()=>S(!1),collapsed:p,mobileDrawerOpen:g,selectedWhatsappId:y?.sessionId??null,onSelectWhatsappConversation:ne,initialWhatsappSurface:x}),!v&&(0,O.jsx)(N,{}),typeof d==`function`?d(M):d]}),g&&(0,O.jsx)(`div`,{className:`sidebar-backdrop menu-open`,"aria-hidden":`true`,onClick:()=>S(!1)}),f]})}export{C as a,T as i,F as n,x as o,E as r,ee as s,U as t};
@@ -1 +0,0 @@
1
- import{o as e}from"./chunk-CAM3fms7.js";import{c as t,i as n,o as r,s as i,t as a,u as o}from"./brand-BQ_u9UdS.js";var s=`maxy-admin-session`,c=typeof BroadcastChannel<`u`;function l(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.type===`rotation`&&typeof t.newKey==`string`&&t.newKey.length>0&&(t.surface===`chat`||t.surface===`graph`||t.surface===`data`||t.surface===`sessions`)&&typeof t.ts==`number`}function u(e){if(!c)return()=>{};let t=new BroadcastChannel(s),n=t=>{if(!l(t.data)){console.warn(`[admin-session-broadcast] outcome=received-malformed payload=${JSON.stringify(t.data)}`);return}e(t.data)};return t.addEventListener(`message`,n),()=>{t.removeEventListener(`message`,n),t.close()}}var d=e(o(),1),f=`maxy-admin-session-key`;function p(e,t){return`${e}${e.includes(`?`)?`&`:`?`}session_key=${encodeURIComponent(t)}`}async function m(e){let t;try{t=await e.clone().json()}catch{return`parse-failed`}if(typeof t!=`object`||!t)return`unknown-401`;let n=t.code;return n===`session-missing`||n===`session-not-registered`||n===`session-expired-age`||n===`grant-expired`||n===`remote-auth-required`?n:`unknown-401`}var h=`maxy-remote-auth-reload-at`,g=6e4;function _(e,t){let n=0;try{n=Number(sessionStorage.getItem(h)??`0`)}catch{}let r=Date.now();if(Number.isFinite(n)&&r-n<g){console.warn(`[admin-auth] outcome=remote-auth-reload-suppressed surface=${e} path=${t}`);return}try{sessionStorage.setItem(h,String(r))}catch{}console.warn(`[admin-auth] outcome=remote-auth-expired-reload surface=${e} path=${t}`),window.location.reload()}function v(){try{return sessionStorage.getItem(f)}catch{return null}}function y(e){let{initialCacheKey:t,surface:n}=e,[r,i]=(0,d.useState)(t),a=(0,d.useRef)(t);(0,d.useEffect)(()=>{a.current=r},[r]),(0,d.useEffect)(()=>{t!==a.current&&(i(t),a.current=t,s(e=>e+1))},[t]);let[o,s]=(0,d.useState)(0);(0,d.useEffect)(()=>u(e=>{let t=a.current.slice(0,8),r=e.newKey.slice(0,8);e.newKey!==a.current&&(console.log(`[admin-session-broadcast] outcome=received oldKey=${t} newKey=${r} surface=${n} senderSurface=${e.surface}`),i(e.newKey),s(e=>e+1))}),[n]);let c=(0,d.useCallback)(()=>{try{sessionStorage.removeItem(f)}catch{}window.location.href=`/`},[]);return{adminFetch:(0,d.useCallback)(async(e,t)=>{let r=a.current,o=p(e,r),l=await fetch(o,t);if(l.status!==401)return l;let u=await m(l);if(u===`remote-auth-required`)return _(n,e),l;if(u===`session-missing`||u!==`session-not-registered`)return console.warn(`[useAdminFetch] outcome=session-expired-redirect reason=${u} surface=${n} path=${e}`),c(),l;let d=v();if(!d||d===r)return console.warn(`[useAdminFetch] outcome=session-expired-redirect reason=session-not-registered-no-fresh-key surface=${n} path=${e}`),c(),l;i(d),a.current=d,s(e=>e+1),console.log(`[useAdminFetch] outcome=retry-after-rotation oldKey=${r.slice(0,8)} newKey=${d.slice(0,8)} surface=${n} path=${e}`);let f=p(e,d),h=await fetch(f,t);if(h.status===401){if(await m(h)===`remote-auth-required`)return _(n,e),h;console.warn(`[useAdminFetch] outcome=session-expired-redirect reason=second-401-after-retry surface=${n} path=${e}`),c()}return h},[c,n]),cacheKey:r,sessionRefetchNonce:o}}var b=t(`check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),x=t(`chevron-left`,[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]),ee=t(`database`,[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`,key:`msslwz`}],[`path`,{d:`M3 5V19A9 3 0 0 0 21 19V5`,key:`1wlel7`}],[`path`,{d:`M3 12A9 3 0 0 0 21 12`,key:`mv7ke4`}]]),S=t(`download`,[[`path`,{d:`M12 15V3`,key:`m9g1x1`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}],[`path`,{d:`m7 10 5 5 5-5`,key:`brsn70`}]]),C=t(`external-link`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]),w=t(`globe`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20`,key:`13o1zl`}],[`path`,{d:`M2 12h20`,key:`9i4pu4`}]]),te=t(`info`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 16v-4`,key:`1dtifu`}],[`path`,{d:`M12 8h.01`,key:`e9boi3`}]]),ne=t(`layout-dashboard`,[[`rect`,{width:`7`,height:`9`,x:`3`,y:`3`,rx:`1`,key:`10lvy0`}],[`rect`,{width:`7`,height:`5`,x:`14`,y:`3`,rx:`1`,key:`16une8`}],[`rect`,{width:`7`,height:`9`,x:`14`,y:`12`,rx:`1`,key:`1hutg5`}],[`rect`,{width:`7`,height:`5`,x:`3`,y:`16`,rx:`1`,key:`ldoo1y`}]]),T=t(`loader-circle`,[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]]),re=t(`log-out`,[[`path`,{d:`m16 17 5-5-5-5`,key:`1bji2h`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`,key:`1uf3rs`}]]),ie=t(`menu`,[[`path`,{d:`M4 5h16`,key:`1tepv9`}],[`path`,{d:`M4 12h16`,key:`1lakjw`}],[`path`,{d:`M4 19h16`,key:`1djgab`}]]),E=t(`message-circle`,[[`path`,{d:`M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719`,key:`1sd12s`}]]),ae=t(`messages-square`,[[`path`,{d:`M16 10a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 14.286V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z`,key:`1n2ejm`}],[`path`,{d:`M20 9a2 2 0 0 1 2 2v10.286a.71.71 0 0 1-1.212.502l-2.202-2.202A2 2 0 0 0 17.172 19H10a2 2 0 0 1-2-2v-1`,key:`1qfcsi`}]]),oe=t(`panel-right-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m10 15-3-3 3-3`,key:`1pgupc`}]]),se=t(`panel-right`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]),ce=t(`pencil`,[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}],[`path`,{d:`m15 5 4 4`,key:`1mk7zo`}]]),D=t(`refresh-cw`,[[`path`,{d:`M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8`,key:`v9h5vc`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}],[`path`,{d:`M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16`,key:`3uifl3`}],[`path`,{d:`M8 16H3v5`,key:`1cv678`}]]),O=t(`share-2`,[[`circle`,{cx:`18`,cy:`5`,r:`3`,key:`gq8acd`}],[`circle`,{cx:`6`,cy:`12`,r:`3`,key:`w7nqdw`}],[`circle`,{cx:`18`,cy:`19`,r:`3`,key:`1xt0gg`}],[`line`,{x1:`8.59`,x2:`15.42`,y1:`13.51`,y2:`17.49`,key:`47mynk`}],[`line`,{x1:`15.41`,x2:`8.59`,y1:`6.51`,y2:`10.49`,key:`1n3mei`}]]),k=t(`triangle-alert`,[[`path`,{d:`m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3`,key:`wmoenq`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),le=t(`unplug`,[[`path`,{d:`m19 5 3-3`,key:`yk6iyv`}],[`path`,{d:`m2 22 3-3`,key:`19mgm9`}],[`path`,{d:`M6.3 20.3a2.4 2.4 0 0 0 3.4 0L12 18l-6-6-2.3 2.3a2.4 2.4 0 0 0 0 3.4Z`,key:`goz73y`}],[`path`,{d:`M7.5 13.5 10 11`,key:`7xgeeb`}],[`path`,{d:`M10.5 16.5 13 14`,key:`10btkg`}],[`path`,{d:`m12 6 6 6 2.3-2.3a2.4 2.4 0 0 0 0-3.4l-2.6-2.6a2.4 2.4 0 0 0-3.4 0Z`,key:`1snsnr`}]]),A=t(`x`,[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]),j=r(),M=(0,d.createContext)(null);function N({cacheKey:e,onSessionExpired:t,surface:n,children:r}){let i=(0,d.useCallback)(async(r,i)=>{if(!e)return fetch(r,i);let a=p(r,e),o=await fetch(a,i);if(o.status!==401)return o;let s=await m(o),c=e.slice(-8);if(s===`remote-auth-required`)return _(n,r),o;if(s===`session-not-registered`){let a=v();if(a&&a!==e){let e=p(r,a),o=await fetch(e,i);return o.status===401?await m(o)===`remote-auth-required`?(_(n,r),o):(console.warn(`[admin-auth] outcome=session-expired-redirect code=second-401-after-retry path=${r} cacheKey=${c} surface=${n}`),t({code:`second-401-after-retry`,path:r}),o):o}}return console.warn(`[admin-auth] outcome=session-expired-redirect code=${s} path=${r} cacheKey=${c} surface=${n}`),t({code:s,path:r}),o},[e,t,n]);return(0,j.jsx)(M.Provider,{value:i,children:r})}function P(){return(0,d.useContext)(M)}function F(e){let t=P();return(0,d.useMemo)(()=>t||(async(t,n)=>fetch(e?p(t,e):t,n)),[t,e])}function I(e){let{businessName:t,variant:r=`admin`,onNavigate:o,conversationsCount:s=0,conversationsChannels:c,onOpenConversations:l,onToggleSidebar:u,sidebarOpen:f,onLogout:p,onDisconnect:m,disconnecting:h}=e,[g,_]=(0,d.useState)(!1),v=(0,d.useRef)(null),y=(0,d.useRef)(null),x=F(null),[S,E]=(0,d.useState)(null),[ce,D]=(0,d.useState)(!1),[k,M]=(0,d.useState)(null),[N,P]=(0,d.useState)(null),[I,L]=(0,d.useState)(!1),[R,z]=(0,d.useState)(null),[B,V]=(0,d.useState)(null),[H,U]=(0,d.useState)(``);(0,d.useEffect)(()=>{U(window.location.hostname.startsWith(`admin.`)?window.location.origin.replace(`admin.`,`public.`):window.location.origin)},[]),(0,d.useEffect)(()=>{if(!g)return;let e=e=>{v.current&&!v.current.contains(e.target)&&_(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[g]),(0,d.useEffect)(()=>{if(!g)return;let e=e=>{e.key===`Escape`&&_(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[g]),(0,d.useEffect)(()=>{g&&y.current?.focus()},[g]),(0,d.useEffect)(()=>{if(!g||r!==`admin`)return;let e=!1;return x(`/api/admin/version`).then(e=>e.json()).then(t=>{e||V(t)}).catch(e=>{console.error(`[admin/version] menu-open client fetch failed:`,e)}),()=>{e=!0}},[g,r,x]);let W=(0,d.useCallback)(()=>{_(e=>{let t=!e;return t&&console.info(`[admin-ui] header-menu-open`),t&&r===`operator`&&console.info(`[operator-ui] op=conversations-menu present=${s>0} channels=[${(c??[]).join(`,`)}] count=${s}`),t})},[r,s,c]),G=(0,d.useCallback)(e=>{_(!1),o(e)},[o]),K=(0,d.useCallback)(async()=>{if(S!==null){E(null),P(null);return}D(!0),M(null);try{let e=await x(`/api/admin/agents`);if(!e.ok)throw Error(`Failed to load agents`);E((await e.json()).agents??[])}catch(e){console.error(`[admin/agents] list failed:`,e),M(e instanceof Error?e.message:String(e)),E([])}finally{D(!1)}},[S,x]),q=(0,d.useCallback)(e=>{P(null),E(t=>t?.filter(t=>t.slug!==e)??null),x(`/api/admin/agents/${encodeURIComponent(e)}`,{method:`DELETE`}).catch(e=>console.error(`[admin/agents] delete failed:`,e))},[x]),J=(0,d.useCallback)(()=>{_(!1),p()},[p]),Y=(0,d.useCallback)(async()=>{z(null),await m()?(L(!1),_(!1)):z(`Disconnect failed — credentials still present. Try again.`)},[m]),X=t||a.productName;return(0,j.jsxs)(`header`,{className:`admin-header`,children:[r===`admin`?(0,j.jsx)(`button`,{type:`button`,className:`admin-sidebar-toggle`,"aria-label":f?`Hide sidebar`:`Show sidebar`,title:f?`Hide sidebar`:`Show sidebar`,"aria-expanded":f,onClick:u,children:f?(0,j.jsx)(oe,{size:20,strokeWidth:1.5}):(0,j.jsx)(se,{size:20,strokeWidth:1.5})}):(0,j.jsx)(`span`,{className:`chat-logo-btn`,"aria-hidden":`true`,children:(0,j.jsx)(`img`,{src:n,alt:``,className:`chat-logo`})}),r===`admin`?(0,j.jsxs)(`div`,{className:`chat-header-label`,children:[(0,j.jsx)(`span`,{className:`chat-logo-btn`,"aria-hidden":`true`,children:(0,j.jsx)(`img`,{src:n,alt:``,className:`chat-logo`})}),(0,j.jsx)(`h1`,{className:`chat-tagline`,children:X})]}):(0,j.jsx)(`h1`,{className:`chat-tagline`,children:X}),(0,j.jsxs)(`div`,{className:`chat-burger-wrap`,ref:v,children:[(0,j.jsx)(`button`,{type:`button`,className:`admin-burger`,onClick:W,"aria-label":`Menu`,"aria-haspopup":`true`,"aria-expanded":g,children:(0,j.jsx)(ie,{size:20})}),g&&(0,j.jsxs)(`div`,{className:`admin-menu${r===`operator`?` admin-menu-operator`:``}`,role:`menu`,children:[r===`admin`&&(0,j.jsxs)(`button`,{ref:y,type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>G(`dashboard`),children:[(0,j.jsx)(ne,{size:14}),` Dashboard`]}),r===`operator`&&(0,j.jsxs)(`button`,{ref:y,type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>G(`chat`),children:[(0,j.jsx)(`img`,{src:`/brand/claude.png`,alt:``,className:`chat-menu-claude-icon`}),` Chat`]}),r===`operator`&&s>0&&(0,j.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>{_(!1),l?.()},children:[(0,j.jsx)(ae,{size:14}),` Conversations`]}),(0,j.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>G(`data`),children:[(0,j.jsx)(ee,{size:14}),` Data`]}),r===`admin`&&(0,j.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>G(`graph`),children:[(0,j.jsx)(O,{size:14}),` Graph`]}),r===`admin`&&(0,j.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>G(`browser`),children:[(0,j.jsx)(w,{size:14}),` Browser`]}),r===`admin`&&(0,j.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>G(`chat`),children:[(0,j.jsx)(`img`,{src:`/brand/claude.png`,alt:``,className:`chat-menu-claude-icon`}),` Chat`]}),r===`admin`&&(0,j.jsx)(`div`,{className:`chat-menu-divider`}),r===`admin`&&(0,j.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:K,children:[(0,j.jsx)(C,{size:14}),` Public`,ce&&(0,j.jsx)(T,{size:12,className:`spin`})]}),r===`admin`&&S!==null&&(0,j.jsxs)(`div`,{className:`chat-menu-agents`,children:[k&&(0,j.jsx)(`span`,{className:`chat-menu-agent-error`,children:k}),S.length===0&&!k&&(0,j.jsx)(`span`,{className:`chat-menu-agent-empty`,children:`No public agents configured`}),S.map(e=>(0,j.jsxs)(`div`,{className:`chat-menu-item chat-menu-agent-item`,children:[(0,j.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),(0,j.jsxs)(`span`,{className:`agent-text`,children:[(0,j.jsx)(`span`,{className:`agent-display-name`,children:e.displayName}),(0,j.jsxs)(`span`,{className:`agent-slug`,children:[`/`,e.slug]})]}),N===e.slug?(0,j.jsxs)(`span`,{className:`agent-actions agent-confirm`,children:[(0,j.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-yes`,title:`Confirm delete`,onClick:()=>q(e.slug),children:(0,j.jsx)(b,{size:12})}),(0,j.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-no`,title:`Cancel`,onClick:()=>P(null),children:(0,j.jsx)(A,{size:12})})]}):(0,j.jsxs)(`span`,{className:`agent-actions`,children:[(0,j.jsx)(`a`,{href:`${H}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`agent-action-btn`,title:`Open agent`,onClick:()=>_(!1),children:(0,j.jsx)(C,{size:12})}),(0,j.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-delete-btn`,title:`Delete agent`,onClick:()=>P(e.slug),children:(0,j.jsx)(i,{size:12})})]})]},e.slug))]}),r===`admin`&&(0,j.jsx)(`div`,{className:`chat-menu-divider`}),r===`admin`&&(0,j.jsxs)(`div`,{className:`chat-menu-version chat-menu-version-passive`,children:[(0,j.jsx)(te,{size:14}),(0,j.jsxs)(`span`,{className:`version-installed`,children:[B?`v${B.installed}`:`…`,B&&!B.updateAvailable&&(0,j.jsx)(`span`,{className:`version-uptodate-dot`}),B?.updateAvailable&&(0,j.jsx)(`span`,{className:`version-update-dot`})]})]}),r===`admin`&&(I?(0,j.jsxs)(`div`,{className:`chat-menu-item chat-menu-disconnect`,children:[(0,j.jsx)(`span`,{children:`Disconnect Claude account?`}),(0,j.jsxs)(`span`,{className:`agent-actions agent-confirm`,children:[(0,j.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-yes`,title:`Confirm disconnect`,disabled:h,onClick:Y,children:h?(0,j.jsx)(T,{size:12,className:`spin`}):(0,j.jsx)(b,{size:12})}),(0,j.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-no`,title:`Cancel disconnect`,disabled:h,onClick:()=>{L(!1),z(null)},children:(0,j.jsx)(A,{size:12})})]})]}):(0,j.jsxs)(`button`,{type:`button`,className:`chat-menu-item chat-menu-disconnect`,role:`menuitem`,onClick:()=>{z(null),L(!0)},children:[(0,j.jsx)(le,{size:14}),` Disconnect Claude account`]})),r===`admin`&&R&&(0,j.jsx)(`span`,{className:`chat-menu-agent-error`,children:R}),(0,j.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:J,children:[(0,j.jsx)(re,{size:14}),` Log out`]})]})]})]})}var L={whatsapp:{fill:`#25D366`,label:`WhatsApp`,path:`M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.71.306 1.263.489 1.694.625.712.227 1.36.195 1.872.118.571-.085 1.758-.719 2.006-1.413.247-.694.247-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.885-9.885 9.885M20.52 3.449C18.24 1.245 15.24.044 12.045.044 5.463.044.103 5.404.1 11.99c0 2.096.546 4.142 1.588 5.945L0 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.585 0 11.946-5.36 11.949-11.946 0-3.193-1.24-6.19-3.495-8.445`},telegram:{fill:`#229ED9`,label:`Telegram`,path:`M11.944 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0a12 12 0 0 0-.056 0zm4.962 7.224c.1-.002.321.023.465.14a.506.506 0 0 1 .171.325c.016.093.036.306.02.472-.18 1.898-.962 6.502-1.36 8.627-.168.9-.499 1.201-.82 1.23-.696.065-1.225-.46-1.9-.902-1.056-.693-1.653-1.124-2.678-1.8-1.185-.78-.417-1.21.258-1.91.177-.184 3.247-2.977 3.307-3.23.007-.032.014-.15-.056-.212s-.174-.041-.249-.024c-.106.024-1.793 1.14-5.061 3.345-.48.33-.913.49-1.302.48-.428-.008-1.252-.241-1.865-.44-.752-.245-1.349-.374-1.297-.789.027-.216.325-.437.893-.663 3.498-1.524 5.83-2.529 6.998-3.014 3.332-1.386 4.025-1.627 4.476-1.635z`}};function R({channel:e,size:t=16}){let n=L[e];return(0,j.jsx)(`svg`,{width:t,height:t,viewBox:`0 0 24 24`,fill:n.fill,role:`img`,"aria-label":n.label,className:`channel-icon`,children:(0,j.jsx)(`path`,{d:n.path})})}var z={whatsapp:`whatsapp`,telegram:`telegram`};function B({channel:e,size:t=13}){let n=z[e];return n?(0,j.jsx)(R,{channel:n,size:t}):e===`webchat`?(0,j.jsx)(w,{size:t,className:`channel-icon`,role:`img`,"aria-label":`Web chat`,style:{color:`var(--text-tertiary)`}}):(0,j.jsx)(E,{size:t,className:`channel-icon`,role:`img`,"aria-label":e,style:{color:`var(--text-tertiary)`}})}var V=[`whatsapp`,`telegram`,`webchat`],H={whatsapp:`WhatsApp`,telegram:`Telegram`,webchat:`Webchat`};function U(e){return V.map(t=>({channel:t,label:H[t],rows:e.filter(e=>e.channel===t)})).filter(e=>e.rows.length>0)}function W(e){let t=e.operatorName??e.whatsappName;return t?e.senderId?`${t} ${e.senderId}`:t:e.senderId??e.title}function G(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()}var K={auth_expired:`Your session has expired. Please sign in again.`,claude_down:`Claude is currently experiencing an outage. Please try again in a few minutes.`,claude_overloaded:`Claude is overloaded right now. Please try again shortly.`,model_unavailable:`The selected model is currently unavailable. Switch to a different model from the model picker to continue.`,agent_error:`Something went wrong. Please try again.`},q={auth_expired:`I'm not available right now. Please try again later.`,claude_down:`I'm not available right now. Please try again later.`,claude_overloaded:`I'm not available right now. Please try again shortly.`,model_unavailable:`I'm not available right now. Please try again later.`,agent_error:`I'm not available right now. Please try again later.`};function J(e,t=`admin`){return t===`public`?q[e]:K[e]}function Y(e){return e===`whatsapp`?` · via WhatsApp`:e===`webchat`?` · via web`:``}function X(e,t,n,r=`/api/whatsapp-reader/stream`){let[i,a]=(0,d.useState)([]),[o,s]=(0,d.useState)(`open`);return(0,d.useEffect)(()=>{a([]),s(`open`);let i=`${r}?sessionId=${encodeURIComponent(e)}&projectDir=${encodeURIComponent(t)}&session_key=${encodeURIComponent(n)}`,o=new EventSource(i);return o.onopen=()=>{console.info(`[admin-ui] wa-stream onopen sessionId=${e}`),s(`open`)},o.onmessage=e=>{try{a(t=>[...t,JSON.parse(e.data)])}catch{}},o.onerror=()=>{o.readyState===2&&(console.error(`[admin-ui] wa-stream onerror readyState=${o.readyState}`),s(`error`))},()=>o.close()},[e,t,n,r]),{turns:i,status:o}}var Z=e=>{if(!e)return 1/0;let t=new Date(e).getTime();return Number.isNaN(t)?1/0:t};function ue(e,t){let n=[],r=0;return e.forEach((e,t)=>n.push({sort:Z(e.ts),sub:1,ins:r++,item:{kind:`turn`,turn:e,idx:t}})),t.forEach(e=>n.push({sort:Z(e.ts),sub:0,ins:r++,item:{kind:`directive`,entry:e}})),n.sort((e,t)=>e.sort===t.sort?e.sort===1/0?e.ins-t.ins:e.sub-t.sub||e.ins-t.ins:e.sort<t.sort?-1:1).map(e=>e.item)}function de(e,t,n=!0){let[r,i]=(0,d.useState)([]);return(0,d.useEffect)(()=>{if(!n||typeof fetch!=`function`)return;let r=!0,a=`/api/whatsapp-reader/directives?sessionId=${encodeURIComponent(e)}&session_key=${encodeURIComponent(t)}`;return fetch(a).then(e=>e.ok?e.json():{entries:[]}).then(e=>{r&&i(Array.isArray(e.entries)?e.entries:[])}).catch(()=>{r&&i([])}),()=>{r=!1}},[e,t,n]),r}var fe=new Set([`operator-inbound`,`operator-typed`,`agent-reply`,`agent-reply-document`]);function Q(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}function pe(e){let t=e.lastIndexOf(`/`);return t===-1?e:e.slice(t+1)}function $({label:e,ts:t}){return(0,j.jsxs)(`div`,{className:`wa-turn-head`,children:[(0,j.jsx)(`span`,{className:`wa-who`,children:e}),(0,j.jsx)(`time`,{className:`wa-time`,children:Q(t)})]})}function me({turn:e}){let[t,n]=(0,d.useState)(!1),r=e.kind===`tool-result`,i=r?`wa-turn wa-turn-result${e.isError?` is-error`:``}`:`wa-turn wa-turn-tool`,a=r?e.isError?`result (error)`:`result`:`↳ ${e.name}`,o=r?e.text:JSON.stringify(e.input,null,2);return(0,j.jsxs)(`div`,{className:i,children:[(0,j.jsxs)(`button`,{type:`button`,className:`wa-tool-toggle`,"aria-expanded":t,onClick:()=>n(e=>!e),children:[(0,j.jsx)(`span`,{className:`wa-chevron`,children:t?`▾`:`▸`}),(0,j.jsx)(`span`,{className:`wa-who`,children:a}),(0,j.jsx)(`time`,{className:`wa-time`,children:Q(e.ts)})]}),t&&(0,j.jsx)(`pre`,{className:`wa-code`,children:o})]})}function he({entry:e,sessionId:t,sessionKey:n}){let[r,i]=(0,d.useState)(!1),[a,o]=(0,d.useState)(null),s=()=>{let s=!r;if(i(s),s&&a===null&&typeof fetch==`function`){let r=`/api/whatsapp-reader/directive?sessionId=${encodeURIComponent(t)}&name=${encodeURIComponent(e.name)}&session_key=${encodeURIComponent(n)}`;fetch(r).then(e=>e.ok?e.text():`(directive unavailable)`).then(o).catch(()=>o(`(directive unavailable)`))}};return(0,j.jsxs)(`div`,{className:`wa-turn wa-turn-directive`,children:[(0,j.jsxs)(`button`,{type:`button`,className:`wa-tool-toggle`,"aria-expanded":r,onClick:s,children:[(0,j.jsx)(`span`,{className:`wa-chevron`,children:r?`▾`:`▸`}),(0,j.jsxs)(`span`,{className:`wa-who`,children:[`⚙ directive injected (`,e.len,` B)`]}),(0,j.jsx)(`time`,{className:`wa-time`,children:Q(e.ts)})]}),r&&(0,j.jsx)(`pre`,{className:`wa-code`,children:a??`Loading…`})]})}function ge(e,t){switch(e.kind){case`operator-inbound`:return(0,j.jsxs)(`div`,{className:`wa-turn wa-turn-in`,children:[(0,j.jsx)($,{label:`Operator${Y(e.source)}`,ts:e.ts}),(0,j.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`operator-typed`:return(0,j.jsxs)(`div`,{className:`wa-turn wa-turn-in wa-turn-typed`,children:[(0,j.jsx)($,{label:`Operator (web)`,ts:e.ts}),(0,j.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`agent-text`:return(0,j.jsxs)(`div`,{className:`wa-turn wa-turn-think`,children:[(0,j.jsx)($,{label:`Agent`,ts:e.ts}),(0,j.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`agent-reply`:return(0,j.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,j.jsx)($,{label:`Agent`,ts:e.ts}),(0,j.jsx)(`p`,{className:`wa-body`,children:e.text})]},t);case`agent-reply-document`:return(0,j.jsxs)(`div`,{className:`wa-turn wa-turn-out`,children:[(0,j.jsx)($,{label:`Agent`,ts:e.ts}),(0,j.jsxs)(`p`,{className:`wa-doc`,children:[`📎 sent document(s): `,e.files.map(pe).join(`, `)]}),e.caption&&(0,j.jsx)(`p`,{className:`wa-body`,children:e.caption})]},t);case`tool-call`:case`tool-result`:return(0,j.jsx)(me,{turn:e},t);case`agent-error`:return(0,j.jsxs)(`div`,{className:`wa-turn wa-turn-error`,role:`alert`,children:[(0,j.jsx)($,{label:`Agent`,ts:e.ts}),(0,j.jsx)(`p`,{className:`wa-body wa-error-body`,children:J(e.code,`admin`)}),e.code===`agent_error`&&e.raw&&(0,j.jsx)(`pre`,{className:`wa-code`,children:e.raw})]},t)}}function _e(e,t,n){return e.map((e,r)=>e.kind===`turn`?ge(e.turn,r):(0,j.jsx)(he,{entry:e.entry,sessionId:t,sessionKey:n},r))}var ve=`maxy:whatsapp-reader:clean-view`;function ye(e){return e.filter(e=>e.kind===`turn`&&fe.has(e.turn.kind))}function be({sessionId:e,projectDir:t,sessionKey:n,renderItems:r=_e,cleanViewToggle:i=!1,forceDeliveredOnly:a=!1,streamEndpoint:o=`/api/whatsapp-reader/stream`,suppressDirectives:s=!1,tail:c=null}){let{turns:l,status:u}=X(e,t,n,o),f=ue(l,de(e,n,!s)),[p,m]=(0,d.useState)(()=>{if(typeof window>`u`)return!1;try{return window.localStorage.getItem(ve)===`1`}catch{return!1}}),h=()=>m(e=>{let t=!e;try{window.localStorage.setItem(ve,t?`1`:`0`)}catch{}return t}),g=a||i&&p?ye(f):f,_=(0,d.useRef)(null),v=(0,d.useRef)(!0),[y,b]=(0,d.useState)(!0),x=e=>{let t=e.scrollHeight-e.scrollTop-e.clientHeight<=32;v.current=t,b(e=>e===t?e:t)};return(0,d.useLayoutEffect)(()=>{let e=_.current;e&&v.current&&(e.scrollTop=e.scrollHeight)},[l,p,c!=null]),(0,j.jsxs)(`div`,{className:`wa-reader${i?` wa-reader--clean-toggle`:``}`,children:[(0,j.jsx)(`div`,{className:`wa-reader-thread`,ref:_,onScroll:()=>{let e=_.current;e&&x(e)},children:(0,j.jsxs)(`div`,{className:`wa-thread-scroll`,children:[u===`error`&&(0,j.jsx)(`div`,{className:`wa-reader-error`,children:`Stream disconnected.`}),l.length===0&&u===`open`&&(0,j.jsx)(`div`,{className:`wa-reader-placeholder`,children:`No messages in this conversation yet.`}),r(g,e,n),c]})}),!y&&(0,j.jsx)(`button`,{type:`button`,className:`wa-jump`,onClick:()=>{let e=_.current;e&&(e.scrollTop=e.scrollHeight,v.current=!0,b(!0))},"aria-label":`Jump to latest message`,title:`Jump to latest message`,children:`↓`}),i&&!a&&(0,j.jsxs)(`button`,{type:`button`,className:`wa-clean-toggle${p?` is-active`:``}`,role:`switch`,"aria-checked":p,onClick:h,title:p?`Showing delivered messages only — click to show tool calls, results, and narration`:`Hide tool calls, results, and narration — show delivered messages only`,children:[(0,j.jsx)(`span`,{className:`wa-clean-label`,children:`Messages only`}),(0,j.jsx)(`span`,{className:`wa-switch`,"aria-hidden":`true`,children:(0,j.jsx)(`span`,{className:`wa-switch-thumb`})})]})]})}function xe(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 Se({conversations:e,sessionKey:t,onBack:n}){let[r,i]=(0,d.useState)(null),a=U(e);return r?(0,j.jsxs)(`div`,{className:`op-conv op-conv-reader`,children:[(0,j.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,j.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:()=>i(null),"aria-label":`Back to conversations`,children:[(0,j.jsx)(x,{size:16}),` Back`]}),(0,j.jsx)(`span`,{className:`op-conv-title`,children:W(r)})]}),(0,j.jsx)(be,{sessionId:r.sessionId,projectDir:r.projectDir,sessionKey:t,forceDeliveredOnly:!0},r.sessionId)]}):(0,j.jsxs)(`div`,{className:`op-conv op-conv-list`,children:[(0,j.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,j.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:n,"aria-label":`Back to chat`,children:[(0,j.jsx)(x,{size:16}),` Chat`]}),(0,j.jsx)(`span`,{className:`op-conv-title`,children:`Conversations`})]}),a.map(e=>(0,j.jsxs)(`div`,{className:`op-conv-group`,children:[(0,j.jsxs)(`div`,{className:`op-conv-group-head`,children:[(0,j.jsx)(B,{channel:e.channel,size:14}),e.label]}),e.rows.map(e=>(0,j.jsxs)(`button`,{type:`button`,className:`op-conv-row`,onClick:()=>{console.info(`[operator-ui] op=reader-open channel=${e.channel} session=${e.sessionId.slice(0,8)} readonly=true`),i(e)},children:[(0,j.jsx)(`span`,{className:`op-conv-name`,children:W(e)}),e.modelGated&&(0,j.jsx)(`span`,{className:`op-conv-gated`,role:`img`,"aria-label":`Model unavailable`,children:(0,j.jsx)(k,{size:13})}),(0,j.jsx)(`span`,{className:`op-conv-when`,children:xe(e.lastMessageAt)})]},e.sessionId))]},e.channel))]})}export{b as C,x as S,y as T,ce as _,Y as a,C as b,W as c,I as d,N as f,D as g,O as h,pe as i,R as l,A as m,he as n,J as o,F as p,be as r,G as s,Se as t,B as u,T as v,_ as w,S as x,w as y};
@@ -1 +0,0 @@
1
- import{l as e,o as t}from"./brand-BQ_u9UdS.js";import"./OperatorConversations-hm0Gpu_Q.js";import"./admin-types-D2qTXuCg.js";import"./AdminShell-Cu1zlb6L.js";import{n}from"./page-DQUEst1o.js";import"./audio-attachment-mime-B0b89VnH.js";import"./useSelectionMode-Bf6Rt-sl.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-CAM3fms7.js";import{c as t,l as n,o as r,s as i,u as a}from"./brand-BQ_u9UdS.js";import{T as o,_ as s,d as c,f as l,g as ee,h as te,m as ne,s as u,t as d,v as f,x as p}from"./OperatorConversations-hm0Gpu_Q.js";import{i as re,t as ie}from"./graph-labels-AZLGoVy8.js";var ae=t(`arrow-left`,[[`path`,{d:`m12 19-7-7 7-7`,key:`1l729n`}],[`path`,{d:`M19 12H5`,key:`x3x0zl`}]]),oe=t(`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`}]]),se=t(`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`}]]),ce=t(`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`}]]),m=n(),h=e(a(),1);function le(e){let t=new Set,n=[];for(let r of e)for(let e of r.labels)e&&(t.has(e)||ie.has(e)&&(t.add(e),n.push(e)));return n}var g=r();function ue(){let[e,t]=(0,h.useState)(null),[n,r]=(0,h.useState)(!1);return(0,h.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!n){t(null),r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]),n?e?(0,g.jsx)(l,{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,g.jsx)(`div`,{className:`data-page data-page-full`,children:(0,g.jsx)(de,{cacheKey:e})})}):(0,g.jsx)(`div`,{className:`data-page`,children:(0,g.jsxs)(`div`,{className:`data-empty`,children:[(0,g.jsx)(`p`,{children:`You are not signed in.`}),(0,g.jsxs)(`p`,{children:[`Open the `,(0,g.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,g.jsx)(`div`,{className:`data-page`,children:(0,g.jsxs)(`div`,{className:`data-loading`,children:[(0,g.jsx)(f,{size:18,className:`spin`}),` Loading…`]})})}function de({cacheKey:e}){let{adminFetch:t,cacheKey:n,sessionRefetchNonce:r}=o({initialCacheKey:e,surface:`data`});return(0,g.jsx)(v,{adminFetch:t,cacheKey:n,sessionRefetchNonce:r})}function fe(){if(typeof window>`u`)return`.`;let e=new URLSearchParams(window.location.hash.replace(/^#/,``)).get(`path`);return e&&e.length>0?e:`.`}function pe(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 me(e){return new Promise((t,n)=>{let r=[],i=()=>e.readEntries(e=>{e.length===0?t(r):(r.push(...e),i())},n);i()})}function _(e){return new Promise((t,n)=>e.file(t,n))}async function he(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 _(r),relpath:e});else if(r.isDirectory){let t=await me(r.createReader());n.push(...await he(t,e))}}return n}function ge(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 v({adminFetch:e,cacheKey:t,sessionRefetchNonce:n}){let[r,a]=(0,h.useState)(``),o=(0,h.useRef)(null),[l,ie]=(0,h.useState)(``),[m,ue]=(0,h.useState)(null),[de,me]=(0,h.useState)(`hybrid`),[_,v]=(0,h.useState)(!1),[y,b]=(0,h.useState)(null),[x,xe]=(0,h.useState)(null),[Se,Ce]=(0,h.useState)(0),[S,we]=(0,h.useState)(!1),[C,Te]=(0,h.useState)(()=>fe()),[w,Ee]=(0,h.useState)(null),[T,De]=(0,h.useState)([]),[E,Oe]=(0,h.useState)(!1),[ke,Ae]=(0,h.useState)(null),[je,D]=(0,h.useState)(!1),[O,k]=(0,h.useState)(null),[Me,A]=(0,h.useState)(null),[Ne,Pe]=(0,h.useState)(null),[Fe,Ie]=(0,h.useState)(!1),[Le,Re]=(0,h.useState)(null),j=(0,h.useRef)(null),[ze,M]=(0,h.useState)(0),[Be,N]=(0,h.useState)(!1),[Ve,He]=(0,h.useState)(``),[P,F]=(0,h.useState)(null),[Ue,We]=(0,h.useState)(``),[Ge,I]=(0,h.useState)(null),L=(()=>{let e=C===`.`?[]:C.split(`/`).filter(Boolean);return e.length>=2&&e[0]===`accounts`})();(0,h.useEffect)(()=>{console.info(`[data-ui] op=mount header=operator home=absent`)},[]);let Ke=(0,h.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]),qe=(0,h.useCallback)(e=>{e===`chat`&&(window.location.href=`/`)},[]),[R,Je]=(0,h.useState)([]),[Ye,Xe]=(0,h.useState)(`files`);(0,h.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||Je(t.conversations??[])}).catch(()=>{}),()=>{e=!0}},[t]);let Ze=(0,h.useMemo)(()=>[...new Set(R.map(e=>e.channel))],[R]),[z,B]=(0,h.useState)(!1),Qe=(0,h.useRef)(null);(0,h.useEffect)(()=>{let e=r.trim();if(!e){ie(``),ue(null),b(null);return}we(!1);let t=setTimeout(()=>ie(e),300);return()=>clearTimeout(t)},[r]),(0,h.useEffect)(()=>{if(!l){v(!1);return}let t=!1;return v(!0),b(null),e(`/api/admin/graph-search?q=${encodeURIComponent(l)}&labels=FileArtifact&limit=20${S?`&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||(ue(e.results),me(e.mode??`hybrid`),Ce(typeof e.suppressed==`number`?e.suppressed:0))}).catch(e=>{t||b(e instanceof Error?e.message:String(e))}).finally(()=>{t||v(!1)}),()=>{t=!0}},[l,e,n,S]);let $e=(0,h.useMemo)(()=>m?le(m):[],[m]),V=x&&$e.includes(x)?x:null,H=(0,h.useMemo)(()=>m?V?m.filter(e=>e.labels.includes(V)):m:null,[m,V]),et=(0,h.useCallback)(e=>{let n=e.properties.relativePath;if(typeof n!=`string`||n.length===0)return;let r=`/api/admin/files/download?session_key=${encodeURIComponent(t)}&path=${encodeURIComponent(n)}`,i=document.createElement(`a`);i.href=r,i.rel=`noopener noreferrer`,document.body.appendChild(i),i.click(),i.remove()},[t]);(0,h.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,h.useEffect)(()=>{let t=!1;return Oe(!0),Ae(null),e(`/api/admin/files?path=${encodeURIComponent(C===`.`?``:C)}`).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||(Ee(e.entries),De(e.displayPath??[]))}).catch(e=>{t||(Ee([]),De([]),Ae(e instanceof Error?e.message:String(e)))}).finally(()=>{t||Oe(!1)}),()=>{t=!0}},[e,C,ze,n]),(0,h.useEffect)(()=>{pe(C)},[C]);let tt=(0,h.useCallback)(()=>{M(e=>e+1)},[]),U=(0,h.useCallback)(e=>{B(!1),Te(e)},[]),nt=(0,h.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}`),a(``),b(null),xe(null),U(r)},[U]),rt=(0,h.useCallback)(()=>{if(C===`.`||C===``)return;let e=C.split(`/`).filter(Boolean);e.pop(),Te(e.length===0?`.`:e.join(`/`))},[C]),W=(0,h.useCallback)(e=>{u(t,C===`.`?e.name:`${C}/${e.name}`)},[C,t]),[G,it]=(0,h.useState)(!1),[K,at]=(0,h.useState)(new Set),ot=(0,h.useRef)(null),q=(0,h.useRef)(!1),J=typeof navigator<`u`&&typeof navigator.share==`function`&&typeof navigator.canShare==`function`,st=(0,h.useCallback)(e=>{it(!0),at(new Set([e])),console.info(`[data-ui] op=select-enter count=1`)},[]),Y=(0,h.useCallback)(e=>{it(!1),at(new Set),console.info(`[data-ui] op=select-exit reason=${e}`)},[]),ct=(0,h.useCallback)(e=>{at(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),lt=(0,h.useCallback)(e=>{q.current=!1,ot.current=setTimeout(()=>{q.current=!0,st(e)},500)},[st]),X=(0,h.useCallback)(()=>{ot.current&&=(clearTimeout(ot.current),null)},[]),ut=(0,h.useCallback)(e=>{if(q.current){q.current=!1;return}if(G){ct(e.name);return}W(e)},[G,ct,W]),Z=(0,h.useCallback)(()=>(w??[]).filter(e=>e.kind===`file`&&K.has(e.name)),[w,K]),dt=(0,h.useCallback)(()=>{Z().forEach(W),Y(`action`)},[Z,W,Y]),ft=(0,h.useCallback)(async()=>{let t=Z(),n=t.filter(e=>!e.protected),r=t.length-n.length;Re(r>0?`${r} protected file(s) kept`:null);for(let t of n){let n=C===`.`?t.name:`${C}/${t.name}`;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){Re(e instanceof Error?e.message:String(e))}}M(e=>e+1),Y(`action`)},[Z,C,e,Y]),pt=(0,h.useCallback)(async()=>{let e=Z();if(console.info(`[data-ui] op=share supported=${J} count=${e.length}`),J)try{let n=await Promise.all(e.map(async e=>{let n=C===`.`?e.name:`${C}/${e.name}`,r=`/api/admin/files/download?session_key=${encodeURIComponent(t)}&path=${encodeURIComponent(n)}`,i=await(await fetch(r)).blob();return new File([i],e.name,{type:i.type||`application/octet-stream`})}));navigator.canShare({files:n})&&await navigator.share({files:n})}catch(e){console.warn(`[data-ui] op=share-failed err=${e instanceof Error?e.message:String(e)}`)}},[Z,J,C,t]),mt=(0,h.useCallback)(()=>{j.current?.click()},[]),Q=(0,h.useCallback)((e,n={})=>{let r=new URLSearchParams({session_key:t,path:C===`.`?``:C,filename:e.name});return n.relpath&&r.set(`relpath`,n.relpath),n.token&&r.set(`token`,n.token),new Promise(t=>{let i=new XMLHttpRequest;i.open(`POST`,`/api/admin/files/upload?${r.toString()}`),i.setRequestHeader(`Content-Type`,e.type||`application/octet-stream`),n.onProgress&&(i.upload.onprogress=e=>{e.lengthComputable&&n.onProgress(e.loaded,e.total)}),i.onload=()=>{let e={};try{e=JSON.parse(i.responseText)}catch{}t({status:i.status,data:e})},i.onerror=()=>t({status:0,data:{}}),i.onabort=()=>t({status:0,data:{error:`aborted`}}),i.send(e)})},[t,C]),ht=(0,h.useCallback)(async e=>{A(null),D(!0),k({loaded:0,total:e.size});try{let{status:t,data:n}=await Q(e,{onProgress:(e,t)=>k({loaded:e,total:t})});t>=200&&t<300&&n.path?(Te(n.path.split(`/`).slice(0,-1).join(`/`)||`.`),M(e=>e+1)):A(t===0?`Network error during upload — the connection failed before the server responded.`:n.error??`Upload failed (HTTP ${t}).`)}finally{D(!1),k(null),j.current&&(j.current.value=``)}},[Q]),gt=(0,h.useCallback)(e=>{L&&Array.from(e.dataTransfer.types).includes(`Files`)&&(e.preventDefault(),Ie(!0))},[L]),_t=(0,h.useCallback)(e=>{e.currentTarget.contains(e.relatedTarget)||Ie(!1)},[]),vt=(0,h.useCallback)(async e=>{e.preventDefault(),Ie(!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(!L){console.info(`[data-ui] op=drop-rejected token=${t} reason=no-write`),A(`Open a folder inside your account to upload`);return}let r=n.map(e=>e.webkitGetAsEntry?.()).filter(e=>!!e);D(!0),A(null),Pe(null);let i=performance.now();try{let e=await he(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}`),k({loaded:0,total:r.size});let{status:a,data:c}=await Q(r,{relpath:i,token:t,onProgress:(e,t)=>k({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`:ge(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}`),Pe(`Uploaded ${o}, skipped ${s.length}${s.length?`: ${s.join(`, `)}`:``}`),M(e=>e+1)}catch(e){A(e instanceof Error?e.message:String(e))}finally{D(!1),k(null)}},[L,Q]),yt=(0,h.useCallback)(async()=>{let t=Ve.trim();if(t){I(null);try{let n=await e(`/api/admin/files/folder`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:C===`.`?``:C,name:t})}),r=await n.json().catch(()=>({error:`HTTP ${n.status}`}));if(!n.ok)throw Error(r.error??`HTTP ${n.status}`);N(!1),He(``),M(e=>e+1)}catch(e){I(e instanceof Error?e.message:String(e))}}},[e,Ve,C]),bt=(0,h.useCallback)(async()=>{if(!P)return;let t=Ue.trim();if(!t)return;I(null);let n=C===`.`?P:`${C}/${P}`;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}`);F(null),We(``),Y(`action`),M(e=>e+1)}catch(e){I(e instanceof Error?e.message:String(e))}},[e,Ue,P,C,Y]);(0,h.useEffect)(()=>{if(!z)return;let e=e=>{Qe.current&&!Qe.current.contains(e.target)&&B(!1)},t=e=>{e.key===`Escape`&&B(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[z]);let $=(0,h.useCallback)(e=>T.slice(0,e+1).map(e=>e.name).join(`/`),[T]),xt=T.length>=2,St=xt?[{name:`.`,label:`data`},...T.slice(0,T.length-2).map((e,t)=>({name:$(t),label:e.displayName??e.name}))]:[];return(0,g.jsxs)(`main`,{className:`data-main`,children:[(0,g.jsx)(c,{variant:`operator`,onNavigate:qe,conversationsCount:R.length,conversationsChannels:Ze,onOpenConversations:()=>Xe(`conversations`),onToggleSidebar:()=>{},sidebarOpen:!1,onLogout:Ke,onDisconnect:async()=>!0,disconnecting:!1}),Ye===`conversations`?(0,g.jsx)(d,{conversations:R,sessionKey:t,onBack:()=>Xe(`files`)}):(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(`div`,{className:`data-toolbar`,children:[G?(0,g.jsxs)(`button`,{type:`button`,className:`data-select-cancel`,onClick:()=>Y(`cancel`),"aria-label":`Cancel selection`,children:[(0,g.jsx)(ne,{size:14}),` Cancel`]}):(0,g.jsxs)(`div`,{className:`data-search-input`,children:[r===``&&(0,g.jsx)(re,{size:14}),(0,g.jsx)(`input`,{ref:o,type:`text`,value:r,onChange:e=>a(e.target.value),autoFocus:!0,autoComplete:`off`,spellCheck:!1}),_&&(0,g.jsx)(f,{size:14,className:`spin`}),r!==``&&(0,g.jsx)(`button`,{type:`button`,className:`data-search-inline-btn`,onClick:()=>{a(``),o.current?.focus()},title:`Clear search`,"aria-label":`Clear search`,children:(0,g.jsx)(ne,{size:14})}),r===``&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`button`,{type:`button`,className:`data-search-inline-btn`,onClick:tt,disabled:E,title:`Refresh this folder`,"aria-label":`Refresh this folder`,children:E?(0,g.jsx)(f,{size:14,className:`spin`}):(0,g.jsx)(ee,{size:14})}),(0,g.jsx)(`button`,{type:`button`,className:`data-search-inline-btn`,onClick:mt,disabled:je||!L,title:L?`Upload a file`:`Open a folder inside your account to upload`,"aria-label":`Upload a file`,children:je?O&&O.total>0?(0,g.jsxs)(`span`,{className:`data-upload-pct`,children:[Math.round(O.loaded/O.total*100),`%`]}):(0,g.jsx)(f,{size:14,className:`spin`}):(0,g.jsx)(ce,{size:14})}),(0,g.jsx)(`button`,{type:`button`,className:`data-search-inline-btn`,onClick:()=>{N(e=>!e),He(``),I(null)},disabled:je||!L,title:L?`New folder`:`Open a folder inside your account to create one`,"aria-label":`New folder`,children:(0,g.jsx)(oe,{size:14})})]})]}),(0,g.jsxs)(`div`,{className:`data-breadcrumbs`,children:[C!==`.`&&(0,g.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost data-back-btn`,onClick:rt,title:`Up one level`,"aria-label":`Up one level`,children:(0,g.jsx)(ae,{size:14})}),xt?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsxs)(`span`,{className:`data-crumb-wrap`,ref:Qe,children:[(0,g.jsx)(`button`,{type:`button`,className:`data-crumb data-crumb-ellipsis`,onClick:()=>B(e=>!e),"aria-haspopup":`menu`,"aria-expanded":z,"aria-label":`Show parent folders`,title:`Show parent folders`,children:`…`}),z&&(0,g.jsx)(`div`,{className:`data-crumb-menu`,role:`menu`,children:St.map(e=>(0,g.jsx)(`button`,{type:`button`,role:`menuitem`,className:`data-crumb-menu-item`,onClick:()=>U(e.name),title:e.label,children:e.label},e.name))})]}),[T.length-2,T.length-1].map(e=>{let t=T[e];return(0,g.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,g.jsx)(`span`,{className:`data-crumb-sep`,children:`/`}),(0,g.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>U($(e)),title:t.name,children:t.displayName??t.name})]},$(e))})]}):(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>U(`.`),children:`data`}),T.map((e,t)=>(0,g.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,g.jsx)(`span`,{className:`data-crumb-sep`,children:`/`}),(0,g.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>U($(t)),title:e.name,children:e.displayName??e.name})]},$(t)))]})]}),Be&&(0,g.jsxs)(`div`,{className:`data-inline-form`,children:[(0,g.jsx)(`input`,{type:`text`,className:`data-inline-input`,placeholder:`Folder name`,value:Ve,autoFocus:!0,onChange:e=>He(e.target.value),onKeyDown:e=>{e.key===`Enter`&&yt(),e.key===`Escape`&&N(!1)}}),(0,g.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:yt,children:`Create`}),(0,g.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost`,onClick:()=>N(!1),children:`Cancel`})]}),P&&(0,g.jsxs)(`div`,{className:`data-inline-form`,children:[(0,g.jsx)(`input`,{type:`text`,className:`data-inline-input`,placeholder:`New name`,value:Ue,autoFocus:!0,onChange:e=>We(e.target.value),onKeyDown:e=>{e.key===`Enter`&&bt(),e.key===`Escape`&&F(null)}}),(0,g.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:bt,children:`Rename`}),(0,g.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost`,onClick:()=>F(null),children:`Cancel`})]}),Ge&&(0,g.jsx)(`div`,{className:`data-error`,children:Ge}),(0,g.jsx)(`input`,{type:`file`,ref:j,hidden:!0,onChange:e=>{let t=e.target.files?.[0];t&&ht(t)}})]}),(0,g.jsxs)(`div`,{className:`data-body`,"data-drag-active":Fe?`true`:void 0,onDragEnter:gt,onDragOver:gt,onDragLeave:_t,onDrop:vt,children:[(y!==null||m!==null)&&(0,g.jsxs)(`section`,{className:`data-panel`,children:[y&&(0,g.jsxs)(`div`,{className:`data-error`,children:[`Search failed: `,y]}),$e.length>0&&(0,g.jsx)(`div`,{className:`data-chip-row`,role:`group`,"aria-label":`Filter by type`,children:$e.map(e=>{let t=e===V;return(0,g.jsx)(`button`,{type:`button`,className:`data-chip`,"data-active":t,onClick:()=>xe(t?null:e),children:ve([e])??e},e)})}),m&&!_&&(0,g.jsxs)(`div`,{className:`data-results-meta`,children:[H.length,` of `,m.length,` result`,m.length===1?``:`s`]}),m&&!_&&!V&&Se>0&&!S&&(0,g.jsxs)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>we(!0),children:[Se,` low-confidence result`,Se===1?``:`s`,` hidden — show all`]}),m&&!_&&!V&&S&&(0,g.jsx)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>we(!1),children:`Showing all results — hide low-confidence`}),m&&m.length===0&&!_&&(0,g.jsx)(`div`,{className:`data-empty-results`,children:`No matches. Try a different keyword.`}),H&&H.length>0&&(0,g.jsx)(`ul`,{className:`data-results`,children:H.map(e=>(0,g.jsx)(_e,{hit:e,mode:de,onDownload:et,onLocate:nt},e.nodeId))})]}),(0,g.jsxs)(`section`,{className:`data-panel`,children:[O&&(0,g.jsxs)(`div`,{className:`data-upload-progress`,role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":O.total>0?Math.round(O.loaded/O.total*100):void 0,children:[(0,g.jsx)(`div`,{className:`data-upload-progress-track`,children:(0,g.jsx)(`div`,{className:`data-upload-progress-fill`,style:{width:`${O.total>0?Math.round(O.loaded/O.total*100):0}%`}})}),(0,g.jsxs)(`span`,{className:`data-upload-progress-label`,children:[`Uploading… `,O.total>0?`${Math.round(O.loaded/O.total*100)}%`:``]})]}),Me&&(0,g.jsxs)(`div`,{className:`data-error`,children:[`Upload failed: `,Me]}),Ne&&(0,g.jsx)(`div`,{className:`data-status`,children:Ne}),Le&&(0,g.jsxs)(`div`,{className:`data-error`,children:[`Delete failed: `,Le]}),ke&&(0,g.jsx)(`div`,{className:`data-error`,children:ke}),E&&(0,g.jsxs)(`div`,{className:`data-loading`,children:[(0,g.jsx)(f,{size:14,className:`spin`}),` Loading…`]}),!E&&w&&w.length===0&&!ke&&(0,g.jsx)(`div`,{className:`data-empty-results`,children:`Empty directory.`}),!E&&w&&w.length>0&&(0,g.jsx)(`ul`,{className:`data-entries`,children:w.map(e=>{let t=e.displayName??e.name;if(e.kind===`directory`){let n=G&&K.has(e.name);return(0,g.jsx)(`li`,{className:`data-entry`,"data-selected":n?`true`:void 0,children:(0,g.jsxs)(`button`,{type:`button`,className:`data-entry-btn`,onPointerDown:()=>lt(e.name),onPointerUp:X,onPointerMove:X,onPointerLeave:X,onPointerCancel:X,onClick:()=>{if(q.current){q.current=!1;return}if(G){ct(e.name);return}U(C===`.`?e.name:`${C}/${e.name}`)},children:[G&&(0,g.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,g.jsx)(se,{size:14}),(0,g.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t})]})},e.name)}if(e.kind===`file`){let n=G&&K.has(e.name);return(0,g.jsx)(`li`,{className:`data-entry`,"data-selected":n?`true`:void 0,children:(0,g.jsxs)(`button`,{type:`button`,className:`data-entry-btn data-entry-file`,onPointerDown:()=>lt(e.name),onPointerUp:X,onPointerMove:X,onPointerLeave:X,onPointerCancel:X,onClick:()=>ut(e),title:G?void 0:`Download ${t}`,children:[G&&(0,g.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,g.jsxs)(`span`,{className:`data-entry-text`,children:[(0,g.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t}),(0,g.jsxs)(`span`,{className:`data-entry-meta`,title:`Modified ${be(e.modifiedAt)}`,children:[ye(e.sizeBytes),` · `,be(e.modifiedAt)]})]})]})},e.name)}return(0,g.jsx)(`li`,{className:`data-entry`,children:(0,g.jsx)(`div`,{className:`data-entry-btn data-entry-file data-entry-disabled`,children:(0,g.jsxs)(`span`,{className:`data-entry-text`,children:[(0,g.jsx)(`span`,{className:`data-entry-name`,children:t}),(0,g.jsx)(`span`,{className:`data-entry-meta`,children:`special`})]})})},e.name)})})]})]}),G&&(0,g.jsxs)(`div`,{className:`data-select-bar`,role:`toolbar`,"aria-label":`Selection actions`,children:[(0,g.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:pt,disabled:!J||K.size===0,title:J?`Share selected files`:`Sharing is not supported on this device`,children:[(0,g.jsx)(te,{size:16}),` Share`]}),(0,g.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:dt,disabled:K.size===0,children:[(0,g.jsx)(p,{size:16}),` Download`]}),(0,g.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:()=>{let e=[...K][0];e&&(F(e),We(e))},disabled:K.size!==1,children:[(0,g.jsx)(s,{size:16}),` Rename`]}),(0,g.jsxs)(`button`,{type:`button`,className:`data-select-action data-select-delete`,onClick:ft,disabled:K.size===0,children:[(0,g.jsx)(i,{size:16}),` Delete`]})]})]})]})}function _e({hit:e,mode:t,onDownload:n,onLocate:r}){let i=y(e.properties),a=b(e.properties),o=ve(e.labels),s=x(e.properties),[c,l]=(0,h.useState)(!1),ee=a&&a.length>280,te=c||!ee?a:a?.slice(0,280)+`…`,ne=t===`bm25`?`bm25 ${e.bm25Score.toFixed(2)}`:`vector ${e.vectorScore.toFixed(2)} · bm25 ${e.bm25Score.toFixed(2)} · combined ${e.score.toFixed(2)}`,u=e.properties.relativePath,d=typeof u==`string`&&u.length>0,f=d?u.lastIndexOf(`/`):-1,p=d?f===-1?`data`:u.slice(0,f):null;return(0,g.jsxs)(`li`,{className:`data-result`,children:[(0,g.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,g.jsx)(`div`,{className:`data-result-header`,children:(0,g.jsx)(`span`,{className:`data-result-labels`,children:o})}),i&&(0,g.jsx)(`div`,{className:`data-result-title`,children:i}),a&&(0,g.jsx)(`pre`,{className:`data-result-body`,children:te}),(0,g.jsxs)(`div`,{className:`data-result-scores`,children:[s&&(0,g.jsxs)(`span`,{className:`data-result-updated`,children:[`Updated `,be(s),` · `]}),ne]})]}),d&&(0,g.jsxs)(`button`,{type:`button`,className:`data-result-locate`,onClick:()=>r(e),title:`Locate in ${p}`,"aria-label":`Locate in ${p}`,children:[(0,g.jsx)(se,{size:12}),p]}),ee&&(0,g.jsx)(`button`,{type:`button`,className:`data-result-toggle`,onClick:()=>l(e=>!e),children:c?`Show less`:`Show more`})]})}function ve(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 y(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 b(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 x(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 ye(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 be(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`—`}}(0,m.createRoot)(document.getElementById(`root`)).render((0,g.jsx)(ue,{}));
@@ -1 +0,0 @@
1
- import{o as e}from"./chunk-CAM3fms7.js";import{l as t,o as n,u as r}from"./brand-BQ_u9UdS.js";import"./OperatorConversations-hm0Gpu_Q.js";import{n as i,t as a}from"./AdminLoginScreens-B8s2TbT7.js";import"./admin-types-D2qTXuCg.js";import"./AdminShell-Cu1zlb6L.js";import{t as o}from"./page-DQUEst1o.js";import"./audio-attachment-mime-B0b89VnH.js";import"./useSelectionMode-Bf6Rt-sl.js";import"./Checkbox-B_sOAyv1.js";var s=t(),c=e(r(),1),l=n();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`}):(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-CAM3fms7.js";import{c as t,o as n,u as r}from"./brand-BQ_u9UdS.js";import{C as i,a,f as o,i as s,n as c,o as l,r as u,v as d}from"./OperatorConversations-hm0Gpu_Q.js";import{n as f,r as ee,t as te}from"./admin-types-D2qTXuCg.js";import{a as p,i as ne,o as re,r as m,s as h,t as g}from"./AdminShell-Cu1zlb6L.js";import{a as _,i as v,n as y,o as ie,r as ae,t as oe}from"./audio-attachment-mime-B0b89VnH.js";import{i as se}from"./useSelectionMode-Bf6Rt-sl.js";var b=t(`calendar-clock`,[[`path`,{d:`M16 14v2.2l1.6 1`,key:`fo4ql5`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5`,key:`1osxxc`}],[`path`,{d:`M3 10h5`,key:`r794hk`}],[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]),x=t(`circle-question-mark`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),ce=t(`corner-down-left`,[[`path`,{d:`M20 4v7a4 4 0 0 1-4 4H4`,key:`6o5b7l`}],[`path`,{d:`m9 10-5 5 5 5`,key:`1kshq7`}]]),le=t(`graduation-cap`,[[`path`,{d:`M21.42 10.922a1 1 0 0 0-.019-1.838L12.83 5.18a2 2 0 0 0-1.66 0L2.6 9.08a1 1 0 0 0 0 1.832l8.57 3.908a2 2 0 0 0 1.66 0z`,key:`j76jl0`}],[`path`,{d:`M22 10v6`,key:`1lu8f3`}],[`path`,{d:`M6 12.5V16a6 3 0 0 0 12 0v-3.5`,key:`1r8lef`}]]),ue=t(`shield`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}]]),S=`claude-opus-4-8[1m]`,C=`claude-sonnet-4-6`,w=`claude-haiku-4-5`,T={[S]:`Opus 4.8 (1M context)`,[C]:`Sonnet 4.6`,[w]:`Haiku 4.5`};function de(e){return T[e]??e}function fe(e){return e.replace(/\[1m\]$/,``)}var E=`Accomplishing.Actioning.Actualizing.Architecting.Baking.Beaming.Befuddling.Billowing.Blanching.Bloviating.Boogieing.Boondoggling.Booping.Bootstrapping.Brewing.Bunning.Burrowing.Calculating.Canoodling.Caramelizing.Cascading.Catapulting.Cerebrating.Channeling.Channelling.Choreographing.Churning.Clauding.Coalescing.Cogitating.Combobulating.Composing.Computing.Concocting.Considering.Contemplating.Cooking.Crafting.Creating.Crunching.Crystallizing.Cultivating.Deciphering.Deliberating.Determining.Discombobulating.Doing.Doodling.Drizzling.Ebbing.Effecting.Elucidating.Embellishing.Enchanting.Envisioning.Evaporating.Fermenting.Finagling.Flibbertigibbeting.Flowing.Flummoxing.Fluttering.Forging.Forming.Frolicking.Frosting.Gallivanting.Galloping.Garnishing.Generating.Germinating.Gesticulating.Gitifying.Grooving.Gusting.Harmonizing.Hashing.Hatching.Herding.Honking.Hullaballooing.Hyperspacing.Ideating.Imagining.Improvising.Incubating.Inferring.Infusing.Ionizing.Jitterbugging.Julienning.Kneading.Leavening.Levitating.Lollygagging.Manifesting.Marinating.Meandering.Metamorphosing.Misting.Moonwalking.Moseying.Mulling.Musing.Mustering.Nebulizing.Nesting.Newspapering.Noodling.Nucleating.Orbiting.Orchestrating.Osmosing.Perambulating.Percolating.Perusing.Philosophising.Photosynthesizing.Pollinating.Pondering.Pontificating.Pouncing.Precipitating.Prestidigitating.Processing.Proofing.Propagating.Puttering.Puzzling.Quantumizing.Razzmatazzing.Recombobulating.Reticulating.Roosting.Ruminating.Scampering.Schlepping.Scurrying.Seasoning.Shenaniganing.Shimmying.Simmering.Skedaddling.Sketching.Slithering.Smooshing.Spelunking.Spinning.Sprouting.Stewing.Sublimating.Swirling.Swooping.Symbioting.Synthesizing.Tempering.Thinking.Thundering.Tinkering.Tomfoolering.Transfiguring.Transmuting.Twisting.Undulating.Unfurling.Unravelling.Vibing.Waddling.Wandering.Warping.Whatchamacalliting.Whirlpooling.Whirring.Whisking.Wibbling.Working.Wrangling.Zesting.Zigzagging`.split(`.`),D=e(r(),1),O=n(),k=1800;function pe(){let[e,t]=(0,D.useState)(()=>Math.floor(Math.random()*E.length));return(0,D.useEffect)(()=>{let e=setInterval(()=>t(e=>(e+1)%E.length),k);return()=>clearInterval(e)},[]),(0,O.jsxs)(`div`,{className:`chat-activity`,"aria-live":`polite`,"aria-label":`Agent is working`,children:[(0,O.jsx)(`img`,{src:`/brand/claude.png`,alt:``,className:`chat-activity-icon`}),(0,O.jsxs)(`span`,{className:`chat-activity-word`,children:[E[e],`…`]})]})}function A({variant:e,label:t,children:n}){let[r,i]=(0,D.useState)(!1);return(0,O.jsxs)(`div`,{className:`chat-${e}`,children:[(0,O.jsxs)(`button`,{type:`button`,className:`chat-${e}-toggle`,"aria-expanded":r,onClick:()=>i(e=>!e),children:[(0,O.jsx)(`span`,{className:`wa-chevron`,children:r?`▾`:`▸`}),(0,O.jsx)(`span`,{className:`chat-${e}-label`,children:t})]}),r&&n]})}function j({turns:e}){let t=e.filter(e=>e.kind===`tool-call`).length;return(0,O.jsx)(A,{variant:`toolrun`,label:t>0?`Used ${t} tool${t===1?``:`s`}`:`${e.length} tool result${e.length===1?``:`s`}`,children:e.map((e,t)=>(0,O.jsxs)(`div`,{className:`chat-toolrun-item`,children:[(0,O.jsx)(`span`,{className:`chat-toolrun-name`,children:e.kind===`tool-call`?`↳ ${e.name}`:e.isError?`result (error)`:`result`}),(0,O.jsx)(`pre`,{className:`wa-code`,children:e.kind===`tool-call`?JSON.stringify(e.input,null,2):e.text})]},t))})}function M({turns:e}){return(0,O.jsx)(A,{variant:`thinking`,label:`Thinking`,children:e.map((e,t)=>(0,O.jsx)(`div`,{className:`chat-thinking-item`,children:(0,O.jsx)(v,{content:e.text})},t))})}function N({composed:e}){return(0,O.jsx)(A,{variant:`composed`,label:`What the agent received`,children:(0,O.jsx)(`pre`,{className:`wa-code chat-composed-body`,children:e})})}function P(e,t,n){switch(e.kind){case`operator-inbound`:case`operator-typed`:{let r=e.kind===`operator-inbound`?e.rawBody:void 0,i=r??e.text;return(0,O.jsxs)(`div`,{className:`chat-turn-op`,children:[e.kind===`operator-inbound`&&e.source&&(0,O.jsx)(`span`,{className:`chat-via`,children:a(e.source).replace(` · `,``)}),(0,O.jsx)(`p`,{className:`chat-op-body`,children:i}),r!==void 0&&n===`admin`&&(0,O.jsx)(N,{composed:e.text})]},t)}case`agent-reply`:return(0,O.jsx)(`div`,{className:`chat-prose`,children:(0,O.jsx)(v,{content:e.text})},t);case`agent-reply-document`:return(0,O.jsxs)(`div`,{className:`chat-prose`,children:[(0,O.jsxs)(`p`,{className:`chat-doc`,children:[`📎 sent document(s): `,e.files.map(s).join(`, `)]}),e.caption&&(0,O.jsx)(v,{content:e.caption})]},t);case`agent-error`:return(0,O.jsxs)(`div`,{className:`chat-agent-error`,role:`alert`,children:[(0,O.jsx)(`span`,{className:`chat-agent-error-msg`,children:l(e.code,n)}),n===`admin`&&e.code===`agent_error`&&e.raw&&(0,O.jsx)(`pre`,{className:`chat-agent-error-raw`,children:e.raw})]},t)}}function me(e,t,n,r=`admin`){let i=[],a=[],o=[],s=()=>{a.length!==0&&(i.push((0,O.jsx)(j,{turns:a},`tools-${i.length}`)),a=[])},l=()=>{o.length!==0&&(i.push((0,O.jsx)(M,{turns:o},`think-${i.length}`)),o=[])};return e.forEach((e,u)=>{if(e.kind===`turn`&&(e.turn.kind===`tool-call`||e.turn.kind===`tool-result`)){l(),a.push(e.turn);return}if(e.kind===`turn`&&e.turn.kind===`agent-text`){s(),o.push(e.turn);return}s(),l(),e.kind===`directive`?i.push((0,O.jsx)(c,{entry:e.entry,sessionId:t,sessionKey:n},u)):i.push(P(e.turn,u,r))}),s(),l(),i}var F=[S,C,w],I=[`low`,`medium`,`high`,`xhigh`],L={low:`Low`,medium:`Medium`,high:`High`,xhigh:`Highest`},he=[{value:`default`,label:`Ask permissions`},{value:`acceptEdits`,label:`Accept edits`},{value:`plan`,label:`Plan mode`},{value:`auto`,label:`Auto mode`},{value:`bypassPermissions`,label:`Bypass permissions`}],ge=Object.fromEntries(he.map(e=>[e.value,e.label])),_e=2500,ve=15e3;function R(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString(void 0,{weekday:`short`,day:`numeric`,month:`short`,hour:`2-digit`,minute:`2-digit`})}function ye({cacheKey:e,userName:t}){let[n,r]=(0,D.useState)(null);(0,D.useEffect)(()=>{let t=!1;return fetch(`/api/webchat/greeting?session_key=${encodeURIComponent(e)}`).then(async e=>{let n=await e.json();if(!t){if(!e.ok||n.ok!==!0){console.warn(`[admin-ui] greeting-unavailable status=${e.status} ok=${String(n.ok)}`);return}r({events:n.events,tasks:n.tasks,specialists:n.specialists??[]})}}).catch(e=>{t||console.warn(`[admin-ui] greeting-unavailable error=${e instanceof Error?e.message:String(e)}`)}),()=>{t=!0}},[e]);let i=t?.trim().split(/\s+/)[0],a=n?n.tasks.total-n.tasks.items.length:0;return(0,O.jsxs)(`div`,{className:`webchat-greeting`,children:[(0,O.jsx)(`h2`,{className:`webchat-greeting-head`,children:i?`What's up next, ${i}?`:`What's up next?`}),n&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(`section`,{className:`webchat-greeting-section`,"data-kind":`events`,children:[(0,O.jsxs)(`h3`,{className:`webchat-greeting-label`,children:[(0,O.jsx)(b,{size:14}),` Upcoming schedule`]}),n.events.length===0?(0,O.jsx)(`p`,{className:`webchat-greeting-none`,children:`Nothing scheduled`}):n.events.map(e=>(0,O.jsxs)(`div`,{className:`webchat-greeting-row`,children:[(0,O.jsx)(`span`,{className:`webchat-greeting-name`,children:e.name}),(0,O.jsx)(`span`,{className:`webchat-greeting-when`,children:R(e.at)})]},e.eventId))]}),(0,O.jsxs)(`section`,{className:`webchat-greeting-section`,"data-kind":`tasks`,children:[(0,O.jsxs)(`h3`,{className:`webchat-greeting-label`,children:[(0,O.jsx)(p,{size:14}),` Outstanding tasks`]}),n.tasks.items.length===0?(0,O.jsx)(`p`,{className:`webchat-greeting-none`,children:`No open tasks`}):(0,O.jsxs)(O.Fragment,{children:[n.tasks.items.map(e=>(0,O.jsxs)(`div`,{className:`webchat-greeting-row`,children:[(0,O.jsx)(`span`,{className:`webchat-greeting-name`,children:e.name}),(0,O.jsx)(`span`,{className:`webchat-greeting-status`,children:e.status})]},e.taskId)),a>0&&(0,O.jsxs)(`p`,{className:`webchat-greeting-more`,children:[`+`,a,` more`]})]})]}),(0,O.jsxs)(`section`,{className:`webchat-greeting-section`,"data-kind":`specialists`,children:[(0,O.jsxs)(`h3`,{className:`webchat-greeting-label`,children:[(0,O.jsx)(m,{size:14}),` Your specialists`]}),n.specialists.length===0?(0,O.jsx)(`p`,{className:`webchat-greeting-none`,children:`No specialists installed`}):n.specialists.map((e,t)=>(0,O.jsxs)(`div`,{className:`webchat-greeting-row webchat-greeting-row-stacked`,children:[(0,O.jsx)(`span`,{className:`webchat-greeting-name`,children:e.name}),e.summary&&(0,O.jsx)(`span`,{className:`webchat-greeting-summary`,children:e.summary})]},`${t}-${e.name}`))]})]})]})}function z(e,t){let n=(0,D.useRef)(null);return(0,D.useEffect)(()=>{if(!e)return;let r=e=>{n.current&&!n.current.contains(e.target)&&t(!1)},i=e=>{e.key===`Escape`&&t(!1)};return document.addEventListener(`mousedown`,r),window.addEventListener(`keydown`,i),()=>{document.removeEventListener(`mousedown`,r),window.removeEventListener(`keydown`,i)}},[e,t]),n}function be({kind:e,label:t,icon:n,options:r,selected:a,disabled:o,onPick:s}){let[c,l]=(0,D.useState)(!1);return(0,O.jsxs)(`div`,{className:`webchat-picker`,ref:z(c,l),children:[(0,O.jsx)(`button`,{type:`button`,className:`webchat-control webchat-picker-trigger`,"data-kind":e,disabled:o,"aria-haspopup":`listbox`,"aria-expanded":c,"aria-label":a?`${t}: ${a}`:t,title:`${t} — ${a??t} (applies to new sessions)`,onClick:()=>l(e=>!e),children:n}),c&&(0,O.jsx)(`div`,{className:`webchat-picker-panel`,role:`listbox`,children:r.map(t=>(0,O.jsxs)(`button`,{type:`button`,className:`webchat-picker-option`,"data-kind":e,"data-value":t.value,role:`option`,"aria-checked":t.value===a||t.label===a,onClick:()=>{s(t.value),l(!1)},children:[(0,O.jsx)(i,{size:12,className:`webchat-picker-check`}),t.label]},t.value))})]})}function xe({icon:e,value:t,index:n,disabled:r,onPick:i}){let[a,o]=(0,D.useState)(!1),s=z(a,o),c=L[t]??`Medium`;return(0,O.jsxs)(`div`,{className:`webchat-picker`,ref:s,children:[(0,O.jsx)(`button`,{type:`button`,className:`webchat-control webchat-picker-trigger`,"data-kind":`effort`,disabled:r,"aria-haspopup":`dialog`,"aria-expanded":a,"aria-label":`Thinking effort: ${c}`,title:`Thinking — ${c} (Faster ↔ Smarter, applies to new sessions)`,onClick:()=>o(e=>!e),children:e}),a&&(0,O.jsxs)(`div`,{className:`webchat-picker-panel webchat-effort-panel`,role:`dialog`,"aria-label":`Effort for new sessions`,children:[(0,O.jsxs)(`div`,{className:`webchat-effort-head`,children:[(0,O.jsxs)(`span`,{className:`webchat-effort-title`,children:[`Effort `,(0,O.jsx)(`strong`,{children:c})]}),(0,O.jsx)(`span`,{className:`webchat-effort-help`,title:`Higher effort spends more time reasoning before each reply.`,children:(0,O.jsx)(x,{size:13})})]}),(0,O.jsxs)(`div`,{className:`webchat-effort-ends`,children:[(0,O.jsx)(`span`,{children:`Faster`}),(0,O.jsx)(`span`,{children:`Smarter`})]}),(0,O.jsxs)(`div`,{className:`webchat-effort-track`,children:[(0,O.jsx)(`span`,{className:`webchat-effort-dots`,"aria-hidden":`true`,children:I.map((e,t)=>(0,O.jsx)(`span`,{className:`webchat-effort-dot`,"data-max":t===I.length-1},e))}),(0,O.jsx)(`input`,{type:`range`,className:`webchat-effort-slider`,"data-kind":`effort`,min:0,max:I.length-1,step:1,value:n,disabled:r,"aria-label":`Effort for new sessions`,onChange:e=>i(I[Number(e.target.value)])})]})]})]})}function B({cacheKey:e,userName:t,targetSessionId:n,variant:r=`admin`}){let i=r===`public`,[a,o]=(0,D.useState)(null),[s,c]=(0,D.useState)(null),[l,d]=(0,D.useState)(``),[p,m]=(0,D.useState)(!1),[h,g]=(0,D.useState)(null),[v,b]=(0,D.useState)(null),x=(0,D.useRef)(!1),[S,C]=(0,D.useState)([]),[w,T]=(0,D.useState)(null),[E,k]=(0,D.useState)(!1),A=(0,D.useRef)(null),j=()=>Math.round((typeof window>`u`?900:window.innerHeight)/3),[M,N]=(0,D.useState)(null),P=(0,D.useRef)(null),L=(0,D.useRef)(null),R=(0,D.useCallback)(e=>{let t=L.current;t&&N(Math.min(j(),Math.max(44,t.startH+(t.startY-e.clientY))))},[]),z=(0,D.useCallback)(()=>{L.current=null,window.removeEventListener(`pointermove`,R),window.removeEventListener(`pointerup`,z)},[R]),B=(0,D.useCallback)(e=>{L.current={startY:e.clientY,startH:P.current?.offsetHeight??44},window.addEventListener(`pointermove`,R),window.addEventListener(`pointerup`,z),e.preventDefault()},[R,z]),V=(0,D.useCallback)(e=>{let t=M??P.current?.offsetHeight??44;e.key===`ArrowUp`?(e.preventDefault(),N(Math.min(j(),t+24))):e.key===`ArrowDown`&&(e.preventDefault(),N(Math.max(44,t-24)))},[M]),H=(0,D.useCallback)(e=>{T(null);let t=e.find(e=>!oe(e.type,ee));if(t){T(`Unsupported file type: "${t.type}". Supported: images, PDF, plain text, markdown, CSV, calendar, zip, voice notes.`);return}let n=e.find(e=>e.size>f);if(n){T(`"${n.name}" exceeds the 50 MB limit.`);return}C(t=>[...t,...e].slice(0,5))},[]),U=(0,D.useMemo)(()=>S.map(e=>e.type.startsWith(`image/`)?URL.createObjectURL(e):null),[S]);(0,D.useEffect)(()=>()=>{for(let e of U)e&&URL.revokeObjectURL(e)},[U]);let W=y(),Se=W.state===`recording`||W.state===`paused`||W.state===`sending`,Ce=(0,D.useCallback)(async()=>{let t=await W.send();if(!t)return;let r=t.type===`audio/ogg`?`.ogg`:t.type===`audio/mp4`?`.m4a`:`.webm`,a=new File([t],`voice-note${r}`,{type:t.type});if(p){C(e=>[...e,a].slice(0,5));return}m(!0);let o=new FormData;i?(o.append(`message`,``),o.append(`session_key`,s??``)):o.append(`text`,``),o.append(`attachments`,a),!i&&n&&o.append(`session`,n);try{let t=i?await fetch(`/api/chat`,{method:`POST`,body:o}):await fetch(`/api/webchat/send?session_key=${encodeURIComponent(e)}`,{method:`POST`,body:o});t.ok||(console.error(`[admin-ui] webchat-send-failed kind=voice status=${t.status}`),C(e=>[...e,a].slice(0,5)),T(`Voice note failed to send. The recording is attached — press send to retry.`))}catch(e){console.error(`[admin-ui] webchat-send-failed kind=voice error=${e instanceof Error?e.message:String(e)}`),C(e=>[...e,a].slice(0,5)),T(`Voice note failed to send. The recording is attached — press send to retry.`)}finally{m(!1)}},[W,e,n,p,i,s]),G=(0,D.useRef)(!1);(0,D.useEffect)(()=>(G.current=!1,()=>{G.current=!0}),[]);let we=(0,D.useRef)(!1),Te=(0,D.useCallback)(async()=>{if(we.current)return null;we.current=!0;try{if(i){let e=await fetch(`/api/public-reader/session`);if(!e.ok)return null;let t=await e.json();if(G.current)return null;c(t.sessionKey);let n={sessionId:t.sessionId??``,projectDir:t.projectDir};return o(n),n}let t=`session_key=${encodeURIComponent(e)}${n?`&session=${encodeURIComponent(n)}`:``}`,r=await fetch(`/api/webchat/session?${t}`);if(!r.ok)return null;let a=await r.json();return G.current||o(a),a}catch{return null}finally{we.current=!1}},[e,n,i]);(0,D.useEffect)(()=>{Te();let e=setInterval(()=>{Te()},_e);return()=>clearInterval(e)},[Te]);let Ee=(0,D.useCallback)(async()=>{let t=l.trim();if(!(!t&&S.length===0||p)){m(!0),x.current=!1;try{if(i){let e=s;if(!e){console.error(`[public-webchat] op=send-skip reason=no-key`);return}let n;if(S.length>0){let r=new FormData;r.append(`message`,t),r.append(`session_key`,e);for(let e of S)r.append(`attachments`,e);n=await fetch(`/api/chat`,{method:`POST`,body:r})}else n=await fetch(`/api/chat`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({message:t,session_key:e})});n.ok?(d(``),C([]),T(null)):console.error(`[public-webchat] op=send-failed status=${n.status}`);return}let r;if(S.length>0){let i=new FormData;i.append(`text`,t);for(let e of S)i.append(`attachments`,e);n&&i.append(`session`,n),r=await fetch(`/api/webchat/send?session_key=${encodeURIComponent(e)}`,{method:`POST`,body:i})}else r=await fetch(`/api/webchat/send?session_key=${encodeURIComponent(e)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(n?{text:t,session:n}:{text:t})});if(r.ok){T(null),b(null),x.current=!0,g({baselineSize:a?.sizeBytes??null});return}else r.status===409?console.error(`[admin-ui] webchat-send-refused reason=channel-conflict`):console.error(`[admin-ui] webchat-send-failed status=${r.status}`)}catch(e){console.error(`[admin-ui] webchat-send-failed error=${e instanceof Error?e.message:String(e)}`)}finally{x.current||m(!1)}}},[l,p,e,S,n,i,s,a?.sizeBytes]),De=(0,D.useCallback)(e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Ee())},[Ee]);(0,D.useEffect)(()=>{if(!h)return;let e=a?.sizeBytes;e!=null&&(h.baselineSize==null||e>h.baselineSize)&&(d(``),C([]),b(null),g(null),x.current=!1,m(!1))},[a,h]),(0,D.useEffect)(()=>{if(!h)return;let e=setTimeout(()=>{g(null),x.current=!1,m(!1),b(`Couldn't be delivered — press send to retry.`)},ve);return()=>clearTimeout(e)},[h]);let K=n?a?.channelBinding??null:null,Oe=(0,D.useRef)(!1);(0,D.useEffect)(()=>{!n||Oe.current||!a||(Oe.current=!0,console.warn(`[admin-ui] chat-session-target sessionId=${n} jsonl=${a.projectDir?`found`:`missing`} known=${a.known===!0}`))},[a,n]);let ke=(0,D.useRef)(!1);(0,D.useEffect)(()=>{n||ke.current||!a?.sessionId||(ke.current=!0,console.info(`[admin-ui] chat-session-resolve sessionId=${a.sessionId.slice(0,8)} source=canonical`))},[a,n]);let Ae=a?a.effectivePermissionMode??a.permissionMode??null:null,q=a?.model??null,je=a?.activity===`busy`,[J,Me]=(0,D.useState)(null),[Y,Ne]=(0,D.useState)(null),[X,Pe]=(0,D.useState)(null),[Fe,Z]=(0,D.useState)(null),Ie=(0,D.useCallback)(async(t,n)=>{let r=t===`model`?Me:t===`effort`?Ne:Pe;r(n),Z(null);try{let i=await fetch(`/api/webchat/settings?session_key=${encodeURIComponent(e)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({op:t,value:n})});i.ok||(r(null),Z(`Could not save ${t} (status ${i.status})`),console.error(`[admin-ui] webchat-settings-failed op=${t} status=${i.status}`))}catch(e){r(null),Z(`Could not save ${t} (network error)`),console.error(`[admin-ui] webchat-settings-failed op=${t} error=${e instanceof Error?e.message:String(e)}`)}},[e]),Q=(0,D.useRef)(!1),Le=(0,D.useCallback)(async t=>{if(a?.sessionId&&!Q.current){Q.current=!0,Z(null);try{let n=await fetch(`/api/admin/session-reseat?session_key=${encodeURIComponent(e)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({fromSessionId:a.sessionId,model:t})});if(!n.ok){Z(`Could not move this chat (status ${n.status})`),console.error(`[admin-ui] reseat-failed status=${n.status}`),Q.current=!1;return}let r=await n.json();r.target?window.location.href=r.target:Q.current=!1}catch(e){Z(`Could not move this chat (network error)`),console.error(`[admin-ui] reseat-failed error=${e instanceof Error?e.message:String(e)}`),Q.current=!1}}},[e,a?.sessionId]);(0,D.useEffect)(()=>{J!==null&&a?.leverModel===J&&Me(null),Y!==null&&a?.leverEffort===Y&&Ne(null),X!==null&&a?.leverMode===X&&Pe(null)},[a,J,Y,X]);let $=J??a?.leverModel??q??``,Re=Y??a?.leverEffort??``,ze=X??a?.leverMode??Ae??null,Be=Math.max(0,I.indexOf(Re||`medium`)),Ve=$&&!F.includes($)?[...F,$]:F,He=(0,D.useRef)(!1);return(0,D.useEffect)(()=>{He.current||a?.projectDir&&a.activity==null&&Ae==null&&q==null&&(He.current=!0,console.warn(`[admin-ui] composer-indicators-unavailable sessionId=${a.sessionId} (manager meta unreadable or pre-activity)`))},[a,Ae,q]),(0,O.jsxs)(`div`,{className:`webchat-page`,children:[a?.projectDir?(0,O.jsx)(u,{sessionId:a.transcriptSessionId??a.sessionId,projectDir:a.projectDir,sessionKey:i?s??``:e,renderItems:i?(e,t,n)=>me(e,t,n,`public`):me,cleanViewToggle:r===`admin`,forceDeliveredOnly:r===`operator`||i,streamEndpoint:i?`/api/public-reader/stream`:`/api/whatsapp-reader/stream`,suppressDirectives:i,tail:!i&&je?(0,O.jsx)(pe,{}):null},a.sessionId):a&&!i?!n||a.known?(0,O.jsx)(ye,{cacheKey:e,userName:t}):(0,O.jsx)(`div`,{className:`webchat-greeting`,children:(0,O.jsx)(`p`,{className:`webchat-greeting-none`,children:`No transcript found for this session.`})}):null,(0,O.jsx)(`div`,{className:`webchat-composer`,children:(0,O.jsxs)(`div`,{className:`webchat-composer-box${E?` drag-over`:``}`,onDragOver:e=>{e.preventDefault(),k(!0)},onDragLeave:()=>k(!1),onDrop:e=>{e.preventDefault(),k(!1),H([...e.dataTransfer.files])},children:[(0,O.jsx)(`input`,{ref:A,type:`file`,multiple:!0,accept:te,style:{display:`none`},onChange:e=>{e.target.files&&H([...e.target.files]),e.target.value=``}}),!Se&&(0,O.jsx)(`div`,{className:`webchat-resize-handle`,role:`separator`,"aria-orientation":`horizontal`,"aria-label":`Resize input — drag up to enlarge`,tabIndex:0,onPointerDown:B,onKeyDown:V}),S.length>0&&(0,O.jsx)(`div`,{className:`attachment-strip`,children:S.map((e,t)=>(0,O.jsxs)(`div`,{className:`attachment-chip`,children:[U[t]?(0,O.jsx)(`img`,{src:U[t],alt:e.name,className:`attachment-chip-thumb`}):e.type.startsWith(`audio/`)?(0,O.jsx)(_,{size:14}):e.type===`application/pdf`?(0,O.jsx)(se,{size:14}):(0,O.jsx)(ie,{size:14}),(0,O.jsx)(`span`,{className:`attachment-chip-name`,children:e.name}),(0,O.jsx)(`button`,{type:`button`,className:`attachment-chip-remove`,onClick:()=>C(e=>e.filter((e,n)=>n!==t)),"aria-label":`Remove ${e.name}`,children:`×`})]},t))}),w&&(0,O.jsx)(`p`,{className:`attach-error`,children:w}),v&&(0,O.jsx)(`p`,{className:`webchat-send-error`,role:`alert`,children:v}),W.state===`error`&&W.errorMessage&&(0,O.jsxs)(`p`,{className:`voice-error`,role:`alert`,children:[(0,O.jsx)(_,{size:14}),W.errorMessage]}),Se?(0,O.jsx)(`div`,{className:`webchat-input-row voice-active`,children:(0,O.jsx)(ae,{state:W.state,elapsedSeconds:W.elapsedSeconds,waveform:W.waveform,onTogglePause:W.togglePause,onDiscard:W.discard,onSend:()=>void Ce()})}):(0,O.jsxs)(`div`,{className:`webchat-input-row`,children:[(0,O.jsx)(`textarea`,{ref:P,className:`webchat-input`,value:l,placeholder:`Message your agent…`,rows:2,style:M==null?void 0:{height:`${M}px`},disabled:K!==null,onChange:e=>d(e.target.value),onKeyDown:De,onPaste:e=>{let t=e.clipboardData?.items;if(!t)return;let n=[];for(let e of t){if(e.kind!==`file`)continue;let t=e.getAsFile();if(!t)continue;let r=t.type.split(`/`)[1]?.replace(`jpeg`,`jpg`)||`png`;n.push(new File([t],`pasted-image-${Date.now()}.${r}`,{type:t.type}))}n.length>0&&H(n)}}),(0,O.jsx)(`button`,{type:`button`,className:`webchat-send`,onClick:()=>void Ee(),disabled:p||l.trim().length===0&&S.length===0||K!==null,"aria-label":`Send`,title:`Send`,children:(0,O.jsx)(ce,{size:16})})]}),K!==null&&(0,O.jsxs)(`p`,{className:`webchat-conflict-hint`,children:[`This session is bound to the `,K,` channel — message it there. The transcript stays readable here.`]}),(0,O.jsxs)(`div`,{className:`webchat-controls`,children:[(0,O.jsxs)(`div`,{className:`webchat-controls-left`,children:[(0,O.jsx)(`button`,{type:`button`,className:`webchat-control`,onClick:()=>A.current?.click(),disabled:K!==null,title:`Attach files`,"aria-label":`Attach`,children:(0,O.jsx)(ne,{size:14})}),(0,O.jsx)(`button`,{type:`button`,className:`webchat-control`,onClick:W.start,disabled:Se||K!==null,title:`Record voice note`,"aria-label":`Voice input`,children:(0,O.jsx)(_,{size:14})})]}),!i&&(0,O.jsxs)(`div`,{className:`webchat-controls-right`,children:[a?.sessionId&&(0,O.jsx)(`code`,{className:`webchat-session-id`,title:`First 8 characters of this session's id — matches the Sessions list.`,children:a.sessionId.slice(0,8)}),Fe&&(0,O.jsx)(`span`,{className:`webchat-settings-error`,role:`alert`,children:Fe}),ze&&(0,O.jsx)(be,{kind:`mode`,label:`Permission mode`,icon:(0,O.jsx)(ue,{size:14}),options:he,selected:ge[ze]??ze,disabled:K!==null,onPick:e=>void Ie(`mode`,e)}),(0,O.jsx)(be,{kind:`model`,label:`Model`,icon:(0,O.jsx)(re,{size:14}),options:Ve.map(e=>({value:e,label:de(e)})),selected:$?de($):null,disabled:K!==null,onPick:e=>{a?.projectDir?(!q||fe(e)!==fe(q))&&Le(e):Ie(`model`,e)}}),(0,O.jsx)(xe,{icon:(0,O.jsx)(le,{size:14}),value:Re,index:Be,disabled:K!==null,onPick:e=>void Ie(`effort`,e)})]})]})]})})]})}function V({variant:e=`admin`}){let[t,n]=(0,D.useState)(null),[r]=(0,D.useState)(()=>{if(e===`operator`)return null;try{return new URLSearchParams(window.location.search).get(`session`)}catch{return null}}),[i,a]=(0,D.useState)(!1),[s,c]=(0,D.useState)(void 0),[l,u]=(0,D.useState)(null),[f,ee]=(0,D.useState)(void 0),[te,p]=(0,D.useState)(null),[ne,re]=(0,D.useState)(null);(0,D.useEffect)(()=>{let e=!1,t=null;try{t=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!t){n(null),a(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(t)}`).then(async r=>{if(!e){if(r.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}if(r.ok)try{let e=await r.json();typeof e.businessName==`string`&&c(e.businessName),e.sessionId!==void 0&&u(e.sessionId??null),re(e.role??null),ee(e.userName===void 0?null:e.userName),p(e.avatar??null)}catch{}n(t),a(!0)}}).catch(()=>{e||(n(t),a(!0))}),()=>{e=!0}},[]);let m=(0,D.useRef)(!1);(0,D.useEffect)(()=>{e!==`operator`||!i||!t||m.current||(m.current=!0,console.info(`[operator-ui] op=mount surface=chat sessionId=${(l??``).slice(0,8)}`))},[e,i,t,l]);let _=(0,D.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]),[v,y]=(0,D.useState)(!1),ie=(0,D.useCallback)(async()=>{y(!0);try{let e=await h();if(e){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`}return e}finally{y(!1)}},[]);return i?t?(0,O.jsx)(o,{cacheKey:t,surface:`chat`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=chat`);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},children:(0,O.jsx)(g,{cacheKey:t,businessName:s,variant:e,sessionId:l,onLogout:_,onDisconnect:ie,disconnecting:v,userName:f,userAvatar:te,role:ne,children:(0,O.jsx)(B,{cacheKey:t,userName:f??null,targetSessionId:r,variant:e})})}):(0,O.jsx)(`div`,{className:`data-page`,children:(0,O.jsxs)(`div`,{className:`data-empty`,children:[(0,O.jsx)(`p`,{children:`You are not signed in.`}),(0,O.jsxs)(`p`,{children:[`Open the `,(0,O.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,O.jsx)(`div`,{className:`data-page`,children:(0,O.jsxs)(`div`,{className:`data-loading`,children:[(0,O.jsx)(d,{size:18,className:`spin`}),` Loading…`]})})}function H(){return(0,O.jsx)(V,{})}export{H as n,B as r,V as t};