@rubytech/create-maxy-code 0.1.99 → 0.1.101

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 (24) hide show
  1. package/package.json +1 -1
  2. package/payload/platform/plugins/founder-pack/skills/investor-data-room/SKILL.md +5 -3
  3. package/payload/platform/plugins/founder-pack/skills/investor-data-room/references/termsheet-template.md +24 -2
  4. package/payload/platform/services/claude-session-manager/dist/http-server.d.ts +0 -1
  5. package/payload/platform/services/claude-session-manager/dist/http-server.d.ts.map +1 -1
  6. package/payload/platform/services/claude-session-manager/dist/http-server.js +8 -157
  7. package/payload/platform/services/claude-session-manager/dist/http-server.js.map +1 -1
  8. package/payload/premium-plugins/founder-pack/skills/investor-data-room/SKILL.md +5 -3
  9. package/payload/premium-plugins/founder-pack/skills/investor-data-room/references/termsheet-template.md +24 -2
  10. package/payload/premium-plugins/real-agent/plugins/brochures/skills/make-brochure/SKILL.md +1 -0
  11. package/payload/premium-plugins/real-agent/plugins/brochures/skills/property-brochure/SKILL.md +1 -1
  12. package/payload/premium-plugins/real-agent/plugins/brochures/skills/property-brochure/references/template.html +10 -1
  13. package/payload/server/public/assets/admin-CvfKXjVx.js +217 -0
  14. package/payload/server/public/assets/{data-BFHNkj3Y.js → data-DPx0BO-i.js} +1 -1
  15. package/payload/server/public/assets/{graph-Df2aJN0a.js → graph-FRecl_Yt.js} +1 -1
  16. package/payload/server/public/assets/graph-labels-IY4_aDc-.js +1 -0
  17. package/payload/server/public/assets/{page-BVuuY21i.js → page-CBKMOwaH.js} +1 -1
  18. package/payload/server/public/assets/{page-Dc2CtJkh.js → page-CJOpTjue.js} +2 -2
  19. package/payload/server/public/data.html +3 -3
  20. package/payload/server/public/graph.html +3 -3
  21. package/payload/server/public/index.html +4 -4
  22. package/payload/server/server.js +330 -300
  23. package/payload/server/public/assets/admin-D6VRETeg.js +0 -217
  24. package/payload/server/public/assets/graph-labels-CCTdQ2Vi.js +0 -1
@@ -1 +1 @@
1
- import{d as e,y as t}from"./ChatInput-BmmxQOhM.js";import"./graph-labels-CCTdQ2Vi.js";import{t as n}from"./page-BVuuY21i.js";var r=t(),i=e();(0,r.createRoot)(document.getElementById(`root`)).render((0,i.jsx)(n,{}));
1
+ import{d as e,y as t}from"./ChatInput-BmmxQOhM.js";import"./graph-labels-IY4_aDc-.js";import{t as n}from"./page-CBKMOwaH.js";var r=t(),i=e();(0,r.createRoot)(document.getElementById(`root`)).render((0,i.jsx)(n,{}));
@@ -1 +1 @@
1
- import{d as e,y as t}from"./ChatInput-BmmxQOhM.js";import"./graph-labels-CCTdQ2Vi.js";import{n}from"./page-Dc2CtJkh.js";import"./Checkbox-CfiWjuMH.js";var r=t(),i=e();(0,r.createRoot)(document.getElementById(`root`)).render((0,i.jsx)(n,{}));
1
+ import{d as e,y as t}from"./ChatInput-BmmxQOhM.js";import"./graph-labels-IY4_aDc-.js";import{n}from"./page-CJOpTjue.js";import"./Checkbox-CfiWjuMH.js";var r=t(),i=e();(0,r.createRoot)(document.getElementById(`root`)).render((0,i.jsx)(n,{}));
@@ -0,0 +1 @@
1
+ import{o as e}from"./chunk-DD-I1_y5.js";import{_ as t,a as n,c as r,d as i,f as a,g as o,h as s,m as c,p as l,r as u,t as d,u as f,v as p,x as m}from"./ChatInput-BmmxQOhM.js";var h=p(`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`}]]),g=p(`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`}]]),_=p(`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`}]]),v=p(`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`}]]),y=p(`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`}]]),b=p(`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`}]]),x=p(`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`}]]),S=p(`info`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 16v-4`,key:`1dtifu`}],[`path`,{d:`M12 8h.01`,key:`e9boi3`}]]),C=p(`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=p(`loader-circle`,[[`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`,key:`13zald`}]]),T=p(`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`}]]),E=p(`menu`,[[`path`,{d:`M4 5h16`,key:`1tepv9`}],[`path`,{d:`M4 12h16`,key:`1lakjw`}],[`path`,{d:`M4 19h16`,key:`1djgab`}]]),D=p(`minimize-2`,[[`path`,{d:`m14 10 7-7`,key:`oa77jy`}],[`path`,{d:`M20 10h-6V4`,key:`mjg0md`}],[`path`,{d:`m3 21 7-7`,key:`tjx5ai`}],[`path`,{d:`M4 14h6v6`,key:`rmj7iw`}]]),O=p(`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`}]]),ee=p(`panel-right`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]),k=p(`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`}]]),te=p(`plus`,[[`path`,{d:`M5 12h14`,key:`1ays0h`}],[`path`,{d:`M12 5v14`,key:`s699le`}]]),A=p(`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`}]]),j=p(`search`,[[`path`,{d:`m21 21-4.34-4.34`,key:`14j7rj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}]]),ne=p(`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`}]]),re=p(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),ie=p(`terminal`,[[`path`,{d:`M12 19h8`,key:`baeox8`}],[`path`,{d:`m4 17 6-6-6-6`,key:`1yngyt`}]]),ae=p(`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`}]]),M=p(`x`,[[`path`,{d:`M18 6 6 18`,key:`1bl5f8`}],[`path`,{d:`m6 6 12 12`,key:`d8bk6v`}]]),N=e(m(),1),P=i(),oe=`maxy-shell-side-px`;function se(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .artefact`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function F(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=Math.max(248,t-480-se());return Math.min(Math.max(e,248),n)}function I(){if(typeof window>`u`)return 264;try{let e=window.localStorage.getItem(oe);if(!e)return 264;let t=parseInt(e,10);if(Number.isFinite(t)&&t>=248)return F(t)}catch{}return 264}function L({targetSelector:e=`.platform`}){let t=(0,N.useRef)(null),[n,r]=(0,N.useState)(()=>I()),i=(0,N.useRef)(n);(0,N.useEffect)(()=>{let t=document.querySelector(e);!t||!(t instanceof HTMLElement)||(t.style.setProperty(`--side-px`,`${n}px`),i.current=n)},[n,e]);let a=(0,N.useCallback)(()=>{r(e=>{let t=F(e);return t===e?e:t})},[]);(0,N.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(F(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(oe,String(t))}catch{}console.info(`[admin-ui] sidebar-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=F(264);r(e);try{window.localStorage.removeItem(oe)}catch{}console.info(`[admin-ui] sidebar-resize px=${e}`)};return(0,P.jsx)(`div`,{ref:t,className:`side-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize sidebar`,onPointerDown:o,onDoubleClick:s})}var ce=!1;function R(){let e=crypto.getRandomValues(new Uint8Array(16));e[6]=e[6]&15|64,e[8]=e[8]&63|128;let t=Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}function le(){let e=typeof crypto<`u`&&typeof crypto.randomUUID==`function`;if(!ce){ce=!0;let t=typeof window<`u`&&`isSecureContext`in window?window.isSecureContext:!1;console.info(`[idempotency] uuid-source=${e?`native`:`getRandomValues`} secureContext=${t}`)}return e?crypto.randomUUID():R()}function ue(e){let t=e.trim();return t.length>=1&&t.length<=200}function z(e,t,n,r){let i=e===`pane`?`pane-action`:`sidebar-${t}`;console.info(`[admin-ui] ${i} sessionId=${n.slice(0,8)} action=${t} outcome=${r}`)}var de=/session_([A-Za-z0-9_-]+)/;function B(e){if(!e)return null;let t=e.match(de);return t?t[1]:null}async function fe(e,t,n,r,i){let a=B(r)??`unknown`,o=e=>e.slice(0,8),s=t===`pane`?`pane-action action=resume-archive`:`sidebar-resume-archive`,c;try{let t=await fetch(`/api/admin/claude-sessions/${encodeURIComponent(n)}/archive?session_key=${encodeURIComponent(e)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({mode:`archive`})});c=t.ok?`ok`:t.status===409?`409`:`error`;let r=`[admin-ui] ${s} sourceSessionId=${o(n)} newSessionId=${o(a)} result=${c}`;c===`error`?console.error(r):console.info(r)}catch(e){let t=e instanceof Error?e.message:String(e);console.error(`[admin-ui] ${s} sourceSessionId=${o(n)} newSessionId=${o(a)} result=error detail=${t}`)}finally{i.refetch()}}function pe(e,t,n=`pane`){let[r,i]=(0,N.useState)(null),a=(0,N.useRef)(!1),o=(0,N.useCallback)(async r=>{if(!e)return{ok:!1,error:`no-cache-key`};if(a.current)return z(n,`resume`,r,`skipped-in-flight`),{ok:!1,error:`in-flight`};a.current=!0,i(`resume`);let o=le();try{let i=await fetch(`/api/admin/claude-sessions/resume?session_key=${encodeURIComponent(e)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({sessionId:r,channel:`browser`,idempotencyKey:o})}),a=await i.json();if(!i.ok||!(`sessionId`in a)){let e=a.error??`POST returned ${i.status}`;return z(n,`resume`,r,String(i.status)),{ok:!1,error:e}}return t.setSessions(e=>[a,...e.filter(e=>e.sessionId!==r)]),z(n,`resume`,r,`200`),fe(e,n,r,a.url,t),{ok:!0}}catch(e){let i=e instanceof Error?e.message:String(e);return z(n,`resume`,r,`threw`),t.refetch(),{ok:!1,error:i}}finally{a.current=!1,i(null)}},[e,t,n]),s=(0,N.useCallback)(async r=>{if(!e)return{ok:!1,error:`no-cache-key`};i(`end`);try{let i=await fetch(`/api/admin/claude-sessions/${encodeURIComponent(r)}/stop?session_key=${encodeURIComponent(e)}`,{method:`POST`});if(!i.ok){let e=await i.text().catch(()=>``);return z(n,`end`,r,String(i.status)),t.refetch(),{ok:!1,error:`POST /stop ${i.status} ${e.slice(0,200)}`}}return z(n,`end`,r,`204`),t.refetch(),{ok:!0}}catch(e){let i=e instanceof Error?e.message:String(e);return z(n,`end`,r,`threw`),t.refetch(),{ok:!1,error:i}}finally{i(null)}},[e,t,n]),c=(0,N.useCallback)(async r=>{if(!e)return{ok:!1,error:`no-cache-key`};i(`purge`);try{let i=await fetch(`/api/admin/claude-sessions/${encodeURIComponent(r)}?purge=1&session_key=${encodeURIComponent(e)}`,{method:`DELETE`});if(!i.ok){let e=await i.json().catch(()=>({})),t=e.detail||e.error||`DELETE ?purge=1 ${i.status}`;return z(n,`purge`,r,String(i.status)),{ok:!1,error:t}}return t.setSessions(e=>e.filter(e=>e.sessionId!==r)),z(n,`purge`,r,`200`),t.refetch(),{ok:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return z(n,`purge`,r,`threw`),{ok:!1,error:t}}finally{i(null)}},[e,t,n]),l=(0,N.useCallback)(async(r,a)=>{if(!e)return{ok:!1,error:`no-cache-key`};i(a);try{let i=await fetch(`/api/admin/claude-sessions/${encodeURIComponent(r)}/archive?session_key=${encodeURIComponent(e)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({mode:a})});if(!i.ok){let e=await i.json().catch(()=>({})),t=e.detail||e.error||`POST /archive ${i.status}`;return z(n,a,r,String(i.status)),{ok:!1,error:t}}return a===`archive`&&t.setSessions(e=>e.filter(e=>e.sessionId!==r)),t.refetch(),z(n,a,r,`200`),{ok:!0}}catch(e){let t=e instanceof Error?e.message:String(e);return z(n,a,r,`threw`),{ok:!1,error:t}}finally{i(null)}},[e,t,n]);return{inFlight:r,resume:o,end:s,purge:c,archive:(0,N.useCallback)(e=>l(e,`archive`),[l]),unarchive:(0,N.useCallback)(e=>l(e,`unarchive`),[l]),rename:(0,N.useCallback)(async(t,r)=>{if(!e)return{ok:!1,error:`no-cache-key`};i(`rename`);try{let i=await fetch(`/api/admin/claude-sessions/${encodeURIComponent(t)}/rename?session_key=${encodeURIComponent(e)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({title:r})});if(!i.ok){let e=await i.json().catch(()=>({})),r=e.detail||e.error||`POST /rename ${i.status}`;return z(n,`rename`,t,String(i.status)),{ok:!1,error:r,reason:e.reason}}return z(n,`rename`,t,`200`),{ok:!0}}catch(e){let r=e instanceof Error?e.message:String(e);return z(n,`rename`,t,`threw`),{ok:!1,error:r}}finally{i(null)}},[e,n])}}function V(e){return`code.session.pinned.${e}`}function H(e){if(typeof window>`u`)return new Set;try{let t=window.localStorage.getItem(V(e));if(!t)return new Set;let n=JSON.parse(t);return Array.isArray(n)?new Set(n.filter(e=>typeof e==`string`)):new Set}catch{return new Set}}function me(e,t){if(!(typeof window>`u`))try{window.localStorage.setItem(V(e),JSON.stringify([...t]))}catch{}}function he(e){let[t,n]=(0,N.useState)(()=>H(e));(0,N.useEffect)(()=>{n(H(e))},[e]);let r=(0,N.useCallback)(t=>{n(n=>{let r=new Set(n);return r.has(t)?r.delete(t):r.add(t),me(e,r),r})},[e]);return{pinned:t,isPinned:(0,N.useCallback)(e=>t.has(e),[t]),togglePin:r}}function ge(e){let{businessName:i,onLaunchBrowser:o,onNavigate:s,onToggleSidebar:l,sidebarOpen:u,onLogout:d,browserLaunching:f}=e,[p,m]=(0,N.useState)(!1),h=(0,N.useRef)(null),g=(0,N.useRef)(null),[_,v]=(0,N.useState)(null),[y,C]=(0,N.useState)(!1),[D,k]=(0,N.useState)(null),[te,A]=(0,N.useState)(null),[j,re]=(0,N.useState)(null),[ie,ae]=(0,N.useState)(``);(0,N.useEffect)(()=>{ae(window.location.hostname.startsWith(`admin.`)?window.location.origin.replace(`admin.`,`public.`):window.location.origin)},[]),(0,N.useEffect)(()=>{if(!p)return;let e=e=>{h.current&&!h.current.contains(e.target)&&m(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[p]),(0,N.useEffect)(()=>{if(!p)return;let e=e=>{e.key===`Escape`&&m(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[p]),(0,N.useEffect)(()=>{p&&g.current?.focus()},[p]),(0,N.useEffect)(()=>{if(!p)return;let e=!1;return fetch(`/api/admin/version`).then(e=>e.json()).then(t=>{e||re(t)}).catch(e=>{console.error(`[admin/version] menu-open client fetch failed:`,e)}),()=>{e=!0}},[p]);let oe=(0,N.useCallback)(()=>{m(e=>{let t=!e;return t&&console.info(`[admin-ui] header-menu-open`),t})},[]),se=(0,N.useCallback)(()=>{m(!1),o()},[o]),F=(0,N.useCallback)(e=>{m(!1),s(e)},[s]),I=(0,N.useCallback)(async()=>{if(_!==null){v(null),A(null);return}C(!0),k(null);try{let e=await fetch(`/api/admin/agents`);if(!e.ok)throw Error(`Failed to load agents`);v((await e.json()).agents??[])}catch(e){console.error(`[admin/agents] list failed:`,e),k(e instanceof Error?e.message:String(e)),v([])}finally{C(!1)}},[_]),L=(0,N.useCallback)(e=>{A(null),v(t=>t?.filter(t=>t.slug!==e)??null),fetch(`/api/admin/agents/${encodeURIComponent(e)}`,{method:`DELETE`}).catch(e=>console.error(`[admin/agents] delete failed:`,e))},[]),ce=(0,N.useCallback)(()=>{m(!1),d()},[d]),R=i||n.productName;return(0,P.jsxs)(`header`,{className:`admin-header`,children:[(0,P.jsx)(`button`,{type:`button`,className:`admin-sidebar-toggle`,"aria-label":u?`Hide sidebar`:`Show sidebar`,title:u?`Hide sidebar`:`Show sidebar`,"aria-expanded":u,onClick:l,children:u?(0,P.jsx)(O,{size:20,strokeWidth:1.5}):(0,P.jsx)(ee,{size:20,strokeWidth:1.5})}),(0,P.jsxs)(`div`,{className:`chat-header-label`,children:[(0,P.jsx)(`span`,{className:`chat-logo-btn`,"aria-hidden":`true`,children:(0,P.jsx)(`img`,{src:r,alt:``,className:`chat-logo`})}),(0,P.jsx)(`h1`,{className:`chat-tagline`,children:R})]}),(0,P.jsxs)(`div`,{className:`chat-burger-wrap`,ref:h,children:[(0,P.jsx)(`button`,{type:`button`,className:`admin-burger`,onClick:oe,"aria-label":`Menu`,"aria-haspopup":`true`,"aria-expanded":p,children:(0,P.jsx)(E,{size:20})}),p&&(0,P.jsxs)(`div`,{className:`admin-menu`,role:`menu`,children:[(0,P.jsxs)(`button`,{ref:g,type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:se,disabled:f,children:[(0,P.jsx)(c,{size:14}),` Browser`,f&&(0,P.jsx)(w,{size:12,className:`spin`})]}),(0,P.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>F(`data`),children:[(0,P.jsx)(b,{size:14}),` Data`]}),(0,P.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:()=>F(`graph`),children:[(0,P.jsx)(ne,{size:14}),` Graph`]}),(0,P.jsx)(`div`,{className:`chat-menu-divider`}),(0,P.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:I,children:[(0,P.jsx)(x,{size:14}),` Public`,y&&(0,P.jsx)(w,{size:12,className:`spin`})]}),_!==null&&(0,P.jsxs)(`div`,{className:`chat-menu-agents`,children:[D&&(0,P.jsx)(`span`,{className:`chat-menu-agent-error`,children:D}),_.length===0&&!D&&(0,P.jsx)(`span`,{className:`chat-menu-agent-empty`,children:`No public agents configured`}),_.map(e=>(0,P.jsxs)(`div`,{className:`chat-menu-item chat-menu-agent-item`,children:[(0,P.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),(0,P.jsxs)(`span`,{className:`agent-text`,children:[(0,P.jsx)(`span`,{className:`agent-display-name`,children:e.displayName}),(0,P.jsxs)(`span`,{className:`agent-slug`,children:[`/`,e.slug]})]}),te===e.slug?(0,P.jsxs)(`span`,{className:`agent-actions agent-confirm`,children:[(0,P.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-yes`,title:`Confirm delete`,onClick:()=>L(e.slug),children:(0,P.jsx)(t,{size:12})}),(0,P.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-no`,title:`Cancel`,onClick:()=>A(null),children:(0,P.jsx)(M,{size:12})})]}):(0,P.jsxs)(`span`,{className:`agent-actions`,children:[(0,P.jsx)(`a`,{href:`${ie}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`agent-action-btn`,title:`Open agent`,onClick:()=>m(!1),children:(0,P.jsx)(x,{size:12})}),(0,P.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-delete-btn`,title:`Delete agent`,onClick:()=>A(e.slug),children:(0,P.jsx)(a,{size:12})})]})]},e.slug))]}),(0,P.jsx)(`div`,{className:`chat-menu-divider`}),(0,P.jsxs)(`div`,{className:`chat-menu-version chat-menu-version-passive`,children:[(0,P.jsx)(S,{size:14}),(0,P.jsxs)(`span`,{className:`version-installed`,children:[j?`v${j.installed}`:`…`,j&&!j.updateAvailable&&(0,P.jsx)(`span`,{className:`version-uptodate-dot`}),j?.updateAvailable&&(0,P.jsx)(`span`,{className:`version-update-dot`})]})]}),(0,P.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,role:`menuitem`,onClick:ce,children:[(0,P.jsx)(T,{size:14}),` Log out`]})]})]})]})}var _e=`maxy-admin-session`,ve=typeof BroadcastChannel<`u`;function U(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 ye(e){if(!ve)return()=>{};let t=new BroadcastChannel(_e),n=t=>{if(!U(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 be=`maxy-admin-session-key`;function W(e,t){return`${e}${e.includes(`?`)?`&`:`?`}session_key=${encodeURIComponent(t)}`}async function G(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:`unknown-401`}function xe(){try{return sessionStorage.getItem(be)}catch{return null}}function Se(e){let{initialCacheKey:t,surface:n}=e,[r,i]=(0,N.useState)(t),a=(0,N.useRef)(t);(0,N.useEffect)(()=>{a.current=r},[r]),(0,N.useEffect)(()=>{t!==a.current&&(i(t),a.current=t,s(e=>e+1))},[t]);let[o,s]=(0,N.useState)(0),[c,l]=(0,N.useState)(null);(0,N.useEffect)(()=>ye(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),l(null))}),[n]);let u=(0,N.useCallback)(()=>{try{sessionStorage.removeItem(be)}catch{}window.location.href=`/`},[]);return{adminFetch:(0,N.useCallback)(async(e,t)=>{let r=a.current,o=W(e,r),c=await fetch(o,t);if(c.status!==401)return c;let d=await G(c);if(d===`session-missing`)return console.warn(`[useAdminFetch] outcome=redirect-to-login reason=${d} surface=${n} path=${e}`),u(),c;if(d!==`session-not-registered`)return console.warn(`[useAdminFetch] outcome=redirect-to-login reason=${d} surface=${n} path=${e}`),l({message:`Your admin session has expired. Click to reload and sign in.`,reason:d}),c;let f=xe();if(!f||f===r)return console.warn(`[useAdminFetch] outcome=redirect-to-login reason=session-not-registered-no-fresh-key surface=${n} path=${e}`),l({message:`Your admin session was renewed in another tab. Click to reload.`,reason:`session-not-registered`}),c;i(f),a.current=f,s(e=>e+1),console.log(`[useAdminFetch] outcome=retry-after-rotation oldKey=${r.slice(0,8)} newKey=${f.slice(0,8)} surface=${n} path=${e}`);let p=W(e,f),m=await fetch(p,t);return m.status===401&&(console.warn(`[useAdminFetch] outcome=redirect-to-login reason=second-401-after-retry surface=${n} path=${e}`),l({message:`Your admin session has expired. Click to reload and sign in.`,reason:`session-not-registered`})),m},[u,n]),cacheKey:r,sessionRefetchNonce:o,banner:c,reloadToLogin:u}}var Ce=`/api/admin/claude-sessions/events`,we=`admin-session-list-view`,K=`admin-session-list-include-subagents`,Te=`admin-session-list-include-background`;function Ee(e){return e===`active`||e===`archived`||e===`all`}function De(){let e={rows:[],view:`active`,includeBackground:!1,connected:!1},t=new Map,n=new Set,r=null,i=null,a=0,o=0,s=null,c=!1,l=!1;function u(){let n=[...t.values()].sort((e,t)=>t.updatedAt===e.updatedAt?e.sessionId<t.sessionId?-1:1:t.updatedAt-e.updatedAt);e={...e,rows:n}}function d(){for(let e of n)e()}function f(e,n){if(e===`row-removed`){let e=n?.sessionId;if(typeof e!=`string`||!t.delete(e))return;u(),d();return}let r=n;if(typeof r.sessionId!=`string`)return;let i={sessionId:r.sessionId,live:r.live===!0,status:r.status===`busy`?`busy`:r.status===`idle`?`idle`:r.status===`detached`?`detached`:`gone`,agentLabel:typeof r.agentLabel==`string`&&r.agentLabel.length>0?r.agentLabel:null,cwd:typeof r.cwd==`string`?r.cwd:null,firstPrompt:typeof r.firstPrompt==`string`&&r.firstPrompt.length>0?r.firstPrompt:null,titleSource:r.titleSource===`user`||r.titleSource===`ai`?r.titleSource:null,updatedAt:typeof r.updatedAt==`number`?r.updatedAt:0,url:typeof r.url==`string`&&r.url.length>0?r.url:null,archived:r.archived===!0};t.set(i.sessionId,i),u(),d()}function p(t){if(r&&s===t||(r&&=(r.close(),null),!t))return;s=t,c=!1,l=!1;let n=W(Ce,t);try{r=new EventSource(n)}catch(e){console.error(`[admin-ui] session-row-store EventSource construct failed:`,e),h(`auto`);return}r.addEventListener(`open`,()=>{c=!0,a=0,e={...e,connected:!0},d(),console.info(`[admin-ui] session-row-store connected events-received=${o}`)});for(let e of[`row-created`,`row-updated`,`row-archived`,`row-removed`])r.addEventListener(e,t=>{o+=1;try{f(e,JSON.parse(t.data))}catch(t){console.error(`[admin-ui] session-row-store parse failed kind=${e}:`,t)}});r.addEventListener(`error`,()=>{r&&=(r.close(),null),e={...e,connected:!1},d(),!c&&!l&&(l=!0,m(n)),h(`auto`)})}async function m(e){let t=a+1,n=0,r=`unknown`;try{let t=await fetch(e,{method:`GET`});n=t.status,r=t.status>=400&&t.status<500?await G(t):`unknown`}catch(e){console.error(`[admin-ui] session-row-store sse-error-probe-failed:`,e);return}console.error(`[admin-ui] session-row-store sse-error status=${n} code=${r} attempt=${t}`)}function h(e){if(i)return;a+=1;let t=Math.min(1e3*2**Math.min(a,5),3e4);console.info(`[admin-ui] session-row-store reconnect trigger=${e} attempt=${a} delay-ms=${t}`),i=setTimeout(()=>{i=null,s&&p(s)},t)}function g(){i&&=(clearTimeout(i),null),a=0,r&&=(r.close(),null),console.info(`[admin-ui] session-row-store reconnect trigger=manual attempt=0 delay-ms=0`),s&&p(s)}function _(){if(!(typeof window>`u`))try{let t=window.localStorage.getItem(we);Ee(t)&&(e={...e,view:t});let n=window.localStorage.getItem(K);if(n===null){let e=window.localStorage.getItem(Te);e!==null&&(window.localStorage.setItem(K,e),window.localStorage.removeItem(Te),n=e,console.info(`[admin-ui] session-list-storage-migrated from=${Te} to=${K} value=${e}`))}n===`1`&&(e={...e,includeBackground:!0})}catch{}}function v(t){e={...e,view:t};try{window.localStorage.setItem(we,t)}catch{}d()}function y(t){e={...e,includeBackground:t};try{window.localStorage.setItem(K,t?`1`:`0`)}catch{}d()}function b(e){return n.add(e),()=>{n.delete(e)}}function x(){return e}function S(){r&&=(r.close(),null),i&&=(clearTimeout(i),null),s=null,e={...e,connected:!1}}function C(e,t){f(e,t)}function w(t){e={...e,connected:t},d()}function T(){t.clear(),u(),d()}function E(e){let n=new Set(e),r=0;for(let e of[...t.keys()])n.has(e)||(t.delete(e),r+=1);r!==0&&(console.info(`[admin-ui] session-row-store reconcile evicted=${r} kept=${t.size}`),u(),d())}return _(),{subscribe:b,getSnapshot:x,connect:p,disconnect:S,setView:v,setIncludeBackground:y,reconnectNow:g,reconcileFromList:E,_injectEventForTesting:C,_setConnectedForTesting:w,_clearRowsForTesting:T}}var q=De();q._injectEventForTesting,q.connect,q._setConnectedForTesting,q.getSnapshot,q.reconcileFromList;function Oe(e){let t=(0,N.useSyncExternalStore)(q.subscribe,q.getSnapshot,q.getSnapshot);(0,N.useEffect)(()=>{e&&q.connect(e)},[e]);let n=(0,N.useCallback)(e=>q.setView(e),[]),r=(0,N.useCallback)(e=>q.setIncludeBackground(e),[]),i=(0,N.useCallback)(()=>q.reconnectNow(),[]),a=(0,N.useCallback)(e=>q.reconcileFromList(e),[]);return{rows:t.rows,view:t.view,includeBackground:t.includeBackground,connected:t.connected,setView:n,setIncludeBackground:r,reconnectNow:i,reconcileFromList:a}}function ke(e,t,n){return e.filter(e=>!(t===`active`&&e.archived||t===`archived`&&!e.archived||!n&&e.agentLabel!==null&&e.agentLabel!==`admin`))}var J=6e4,Y=60*J,Ae=24*Y,je=J,Me=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],Ne=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function Pe(e){return e<10?`0${e}`:String(e)}function Fe(e){return new Date(e.getFullYear(),e.getMonth(),e.getDate()).getTime()}function Ie(e,t){if(!Number.isFinite(e)||e<=0||!Number.isFinite(t))return`—`;let n=t-e;if(n<-je)return`—`;let r=n<0?0:n;if(r<J)return`just now`;if(r<Y)return`${Math.floor(r/J)}m`;if(r<Ae)return`${Math.floor(r/Y)}h`;let i=new Date(t),a=new Date(e),o=Math.round((Fe(i)-Fe(a))/Ae);if(o===1)return`yesterday`;if(o>=2&&o<=6)return Ne[a.getDay()];let s=Pe(a.getDate()),c=Me[a.getMonth()];return a.getFullYear()===i.getFullYear()?`${s} ${c}`:`${s} ${c} ${a.getFullYear()}`}function Le(e=3e4){let[t,n]=(0,N.useState)(()=>Date.now());return(0,N.useEffect)(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}var Re={default:`Ask`,acceptEdits:`Accept edits`,plan:`Plan`,auto:`Auto`,bypassPermissions:`Bypass permissions`},X=[`default`,`acceptEdits`,`plan`,`auto`,`bypassPermissions`],Z=`Plan does not include auto mode`,ze=[{value:void 0,label:`Default`},{value:`claude-opus-4-7`,label:`Opus 4.7`},{value:`claude-sonnet-4-6`,label:`Sonnet 4.6`},{value:`claude-haiku-4-5`,label:`Haiku 4.5`}];function Be({seedMode:e,seedModel:n,submitting:r,error:i,onSubmit:a,onCancel:s,onErrorClear:c}){let[l,u]=(0,N.useState)(``),[f,p]=(0,N.useState)(e),[m,h]=(0,N.useState)(n),[g,_]=(0,N.useState)(!1),[v,b]=(0,N.useState)(!1),[x,S]=(0,N.useState)(null),C=(0,N.useRef)(null),T=(0,N.useRef)(null),E=(0,N.useRef)(null);(0,N.useEffect)(()=>{C.current?.focus()},[]),(0,N.useEffect)(()=>{let e=!1,t=Date.now();return(async()=>{try{let n=await fetch(`/api/admin/claude-capabilities`);if(!n.ok)throw Error(`status ${n.status}`);let r=await n.json();if(e)return;S(r.autoModeAvailable),console.info(`[admin-ui] capability-fetch ok=true autoModeAvailable=${r.autoModeAvailable} seatTier=${r.seatTier??`null`} ms=${Date.now()-t}`)}catch(n){if(e)return;let r=n instanceof Error?n.message:String(n);console.error(`[admin-ui] capability-fetch ok=false reason="${r}" ms=${Date.now()-t}`)}})(),()=>{e=!0}},[]);let D=(0,N.useMemo)(()=>e=>e===`auto`&&x===!1,[x]);(0,N.useEffect)(()=>{function e(e){if(e.key===`Escape`){if(g){_(!1),e.stopPropagation();return}if(v){b(!1),e.stopPropagation();return}s(`esc`)}}return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[g,v,s]),(0,N.useEffect)(()=>{if(!g&&!v)return;function e(e){g&&T.current&&!T.current.contains(e.target)&&_(!1),v&&E.current&&!E.current.contains(e.target)&&b(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[g,v]);let O=l.trim(),ee=O.length>0&&!r,k=(0,N.useCallback)(()=>{if(O.length===0||r)return;let e=window.open(`about:blank`,`_blank`);console.info(`[admin-ui] new-session-modal-placeholder-open outcome=${e===null?`blocked`:`ok`}`),a({message:l,permissionMode:f,model:m,placeholder:e})},[l,f,m,O,r,a]);function te(e){e.preventDefault(),k()}let A=ze.find(e=>e.value===m)?.label??`Default`;return(0,P.jsx)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":`new-session-modal-title`,className:`new-session-modal-overlay`,onClick:e=>{e.target===e.currentTarget&&s(`backdrop`)},children:(0,P.jsxs)(`div`,{className:`new-session-modal`,children:[(0,P.jsx)(`h2`,{id:`new-session-modal-title`,className:`new-session-modal-title`,children:`New session`}),(0,P.jsxs)(`form`,{className:`new-session-modal-form`,onSubmit:te,children:[(0,P.jsx)(`div`,{className:`chat-form`,children:(0,P.jsx)(d,{ref:C,value:l,onChange:e=>{u(e),i&&c()},placeholder:`What should this session do?`,disabled:r})}),i&&(0,P.jsx)(`div`,{className:`tunnel-route__error`,role:`alert`,children:i}),(0,P.jsxs)(`div`,{className:`new-session-modal-actions`,children:[(0,P.jsxs)(`div`,{className:`new-session-modal-pickers`,children:[(0,P.jsxs)(`div`,{className:`new-session-modal-picker-wrap`,ref:T,children:[(0,P.jsxs)(`button`,{type:`button`,className:`side-mode-trigger`,onClick:()=>{let e=!g;console.info(`[admin-ui] new-session-modal-mode-picker action=${e?`open`:`close`} current=${f}`),_(e)},disabled:r,"aria-haspopup":`menu`,"aria-expanded":g,"aria-label":`Permission mode for this session`,children:[Re[f],(0,P.jsx)(o,{size:12,"aria-hidden":`true`})]}),g&&(0,P.jsxs)(`div`,{className:`side-mode-popover`,role:`menu`,"aria-label":`Mode`,children:[(0,P.jsx)(`div`,{className:`side-mode-popover-head`,children:(0,P.jsx)(`span`,{children:`Mode`})}),X.map((e,n)=>{let r=D(e);return(0,P.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`side-mode-popover-item`,disabled:r,title:r?Z:void 0,"aria-disabled":r||void 0,onClick:()=>{r||(console.info(`[admin-ui] new-session-modal-mode-change from=${f} to=${e} trigger=click`),p(e),_(!1))},children:[(0,P.jsx)(`span`,{children:Re[e]}),(0,P.jsxs)(`span`,{className:`side-mode-popover-shortcut`,children:[e===f&&(0,P.jsx)(t,{size:12}),(0,P.jsx)(`span`,{children:n+1})]})]},e)})]})]}),(0,P.jsxs)(`div`,{className:`new-session-modal-picker-wrap`,ref:E,children:[(0,P.jsxs)(`button`,{type:`button`,className:`side-mode-trigger`,onClick:()=>{let e=!v;console.info(`[admin-ui] new-session-modal-model-picker action=${e?`open`:`close`} current=${m??`default`}`),b(e)},disabled:r,"aria-haspopup":`menu`,"aria-expanded":v,"aria-label":`Model for this session`,children:[A,(0,P.jsx)(o,{size:12,"aria-hidden":`true`})]}),v&&(0,P.jsxs)(`div`,{className:`side-mode-popover`,role:`menu`,"aria-label":`Model`,children:[(0,P.jsx)(`div`,{className:`side-mode-popover-head`,children:(0,P.jsx)(`span`,{children:`Model`})}),ze.map(e=>(0,P.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`side-mode-popover-item`,onClick:()=>{console.info(`[admin-ui] new-session-modal-model-change from=${m??`default`} to=${e.value??`default`} trigger=click`),h(e.value),b(!1)},children:[(0,P.jsx)(`span`,{children:e.label}),(0,P.jsx)(`span`,{className:`side-mode-popover-shortcut`,children:e.value===m&&(0,P.jsx)(t,{size:12})})]},e.label))]})]})]}),(0,P.jsxs)(`div`,{className:`new-session-modal-buttons`,children:[(0,P.jsx)(`button`,{type:`button`,className:`modal-action-btn`,onClick:()=>s(`button`),disabled:r,children:`Cancel`}),(0,P.jsx)(`button`,{type:`submit`,className:`new-session-modal-submit`,disabled:!ee,"aria-label":`Send`,children:r?(0,P.jsx)(w,{size:14,className:`spinning`}):(0,P.jsx)(y,{size:14})})]})]})]})]})})}var Ve=1e4,He=(0,N.forwardRef)(function(e,r){let{businessName:i,cacheKey:c,role:u,userName:d,userAvatar:f,sessions:p,sessionsLoading:m,sessionsError:y,ensureSessionsLoaded:b,refetchSessions:S,onSelectArtefact:T,onSelectProjects:E,onSelectPeople:D,onSelectTasks:O,onSelectAgents:ee,onCloseMobileDrawer:j,onSelectSession:ne,selectedSessionId:M,collapsed:oe,mobileDrawerOpen:se,recentsActions:F}=e,[I,L]=(0,N.useState)(null),[ce,R]=(0,N.useState)(null),[le,z]=(0,N.useState)(!1);(0,N.useEffect)(()=>{b()},[b]);let de=(0,N.useRef)(null),[B,fe]=(0,N.useState)(!1),[V,H]=(0,N.useState)(`default`),[me,ge]=(0,N.useState)(void 0),_e=(0,N.useRef)(null),[ve,U]=(0,N.useState)(null),[ye,be]=(0,N.useState)(!1),W=(0,N.useRef)(0),G=(0,N.useRef)(new Map),xe=n.productName,Se=typeof d==`string`?d:d===null?`name unavailable`:i||xe,Ce=(Se.trim().charAt(0)||`?`).toUpperCase(),we=he(n.hostname),K=Oe(c),Te=(0,N.useMemo)(()=>{let e=ke(K.rows,K.view,K.includeBackground);if(we.pinned.size===0)return e;let t=[],n=[];for(let r of e)(we.pinned.has(r.sessionId)?t:n).push(r);return[...t,...n]},[K.rows,K.view,K.includeBackground,we.pinned]),Ee=Te.length,De=Le(3e4);(0,N.useEffect)(()=>{if(G.current.size!==0)for(let e of K.rows){let t=G.current.get(e.sessionId);if(!t||e.url===null)continue;G.current.delete(e.sessionId),clearTimeout(t.timeoutId);let n=e.sessionId.slice(0,8);if(t.placeholder.closed){console.info(`[admin-ui] new-session-auto-open outcome=timeout sessionId=${n}`);continue}t.placeholder.location.href=e.url,console.info(`[admin-ui] new-session-auto-open outcome=ok sessionId=${n}`)}},[K.rows]),(0,N.useEffect)(()=>{let e=G.current;return()=>{for(let{timeoutId:t}of e.values())clearTimeout(t);e.clear()}},[]);let[q,J]=(0,N.useState)(`chat`),[Y,Ae]=(0,N.useState)([]),[je,Me]=(0,N.useState)(!1),[Ne,Pe]=(0,N.useState)(null),[Fe,Re]=(0,N.useState)(!1);(0,N.useImperativeHandle)(r,()=>({patchArtefact(e,t){Ae(n=>n.map(n=>n.id===e?{...n,...t}:n))}}),[]);let[X,Z]=(0,N.useState)(!1),ze=(0,N.useRef)(null),He={default:`Ask`,acceptEdits:`Accept edits`,plan:`Plan`,auto:`Auto`,bypassPermissions:`Bypass permissions`},Ue=[`default`,`acceptEdits`,`plan`,`auto`,`bypassPermissions`];(0,N.useEffect)(()=>{if(!c)return;let e=!1,t=Date.now();return(async()=>{try{let n=await fetch(`/api/admin/session-defaults?session_key=${encodeURIComponent(c)}`);if(!n.ok)throw Error(`status ${n.status}`);let r=await n.json();if(e)return;let i=r.permissionMode,a=r.model??void 0;H(i),ge(a),_e.current={permissionMode:i,model:a},console.info(`[admin-ui] session-defaults-hydrate permissionMode=${i} model=${a??`default`} ms=${Date.now()-t}`)}catch(n){if(e)return;let r=n instanceof Error?n.message:String(n);console.error(`[admin-ui] session-defaults-hydrate-failed reason="${r}" ms=${Date.now()-t}`)}})(),()=>{e=!0}},[c]);let qe=(0,N.useCallback)(async(e,t)=>{if(!c||!_e.current)return;let n=_e.current,r=Date.now();console.info(`[admin-ui] session-defaults-put from={mode:${n.permissionMode},model:${n.model??`default`}} to={mode:${e.permissionMode},model:${e.model??`default`}} trigger=${t}`);try{let t=await fetch(`/api/admin/session-defaults?session_key=${encodeURIComponent(c)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({permissionMode:e.permissionMode,model:e.model??null})});if(!t.ok)throw Error(`status ${t.status}`);_e.current=e,console.info(`[admin-ui] session-defaults-put-ok ms=${Date.now()-r}`)}catch(e){let t=e instanceof Error?e.message:String(e);console.error(`[admin-ui] session-defaults-put-failed reason="${t}" ms=${Date.now()-r}`),H(n.permissionMode),ge(n.model)}},[c]);(0,N.useEffect)(()=>{if(!X)return;function e(e){ze.current&&!ze.current.contains(e.target)&&(console.info(`[admin-ui] sidebar-mode-picker action=close mode=${V}`),Z(!1))}function t(e){if(e.key===`Escape`){console.info(`[admin-ui] sidebar-mode-picker action=close mode=${V}`),Z(!1);return}let t=[`1`,`2`,`3`,`4`,`5`].indexOf(e.key);if(t>=0&&!e.metaKey&&!e.ctrlKey&&!e.altKey){let n=Ue[t];n&&(e.preventDefault(),console.info(`[admin-ui] sidebar-mode-picker action=select mode=${n} via=shortcut`),H(n),Z(!1),qe({permissionMode:n,model:me},`sidebar`))}}return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[X,V,me,qe]),(0,N.useEffect)(()=>{function e(e){e.shiftKey&&(e.metaKey||e.ctrlKey)&&(e.key===`m`||e.key===`M`)&&(e.preventDefault(),Z(e=>{let t=!e;return console.info(`[admin-ui] sidebar-mode-picker action=${t?`open`:`close`} mode=${V} via=shortcut`),t}))}return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[V]);let Je=(0,N.useCallback)(async()=>{if(c){Re(!0),Pe(null);try{let e=await fetch(`/api/admin/sidebar-artefacts?session_key=${encodeURIComponent(c)}`);if(!e.ok)throw Error(`status ${e.status}`);Ae((await e.json()).artefacts??[]),Me(!0)}catch(e){let t=e instanceof Error?e.message:String(e);Pe(`Failed to load artefacts: ${t}`),console.error(`[admin-ui] sidebar-artefacts fetch failed: ${t}`)}finally{Re(!1)}}},[c]),Ye=()=>{J(`chat`),console.info(`[admin-ui] sidebar-nav surface=sessions count=${Ee}`)},Xe=()=>{J(`artefacts`),console.info(`[admin-ui] sidebar-nav surface=artefacts count=${je?Y.length:0} collapsed=${oe}`),je||Je()},Q=1.5,Ze=q===`chat`?`Sessions`:`Artefacts`,Qe=q===`chat`?m?`…`:String(Ee):Fe?`…`:String(Y.length),$e=q===`chat`?m:Fe,et=()=>{console.info(`[admin-ui] sidebar-refresh surface=${q}`),q===`chat`?S().then(e=>{e!==null&&K.reconcileFromList(e.map(e=>e.sessionId))}):Je()},tt=(0,N.useCallback)(()=>{if(B||!c){console.info(`[admin-ui] sidebar-new-session-click-ignored startingSession=${B} cacheKey=${c?`set`:`missing`}`);return}U(null),W.current=Date.now(),console.info(`[admin-ui] sidebar-new-session-modal-open seedMode=${V} cacheKey-prefix=${c.slice(0,8)}`),be(!0)},[c,B,V]),nt=(0,N.useCallback)(e=>{let t=W.current?Date.now()-W.current:0;console.info(`[admin-ui] sidebar-new-session-modal-cancel reason=${e} dwell-ms=${t}`),U(null),be(!1)},[]),rt=(0,N.useCallback)(async e=>{if(B||!c)return;let t=W.current?Date.now()-W.current:0,n=Date.now();console.info(`[admin-ui] sidebar-new-session-modal-submit permissionMode=${e.permissionMode} model=${e.model??`default`} messageChars=${e.message.length} dwell-ms=${t}`),fe(!0),U(null);try{console.info(`[admin-ui] sidebar-new-session-fetch-start permissionMode=${e.permissionMode} model=${e.model??`default`} messageChars=${e.message.length}`);let t={channel:`browser`,permissionMode:e.permissionMode,initialMessage:e.message};e.model!==void 0&&(t.model=e.model);let r=await fetch(`/api/admin/claude-sessions?session_key=${encodeURIComponent(c)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)}),i=Date.now()-n;console.info(`[admin-ui] sidebar-new-session-fetch-done status=${r.status} ok=${r.ok} ms=${i}`);let a=await r.json();if(!r.ok||!(`sessionId`in a)){let e=a,t=e.error??`POST returned ${r.status}`,i=e.reason?`${t}: ${e.reason}`:t;console.error(`[admin-ui] sidebar-new-session-failed status=${r.status} ms=${Date.now()-n} error=${t} reason=${e.reason??`none`} tail=${JSON.stringify(e.stderrTail??``)}`),U(i);return}console.info(`[admin-ui] sidebar-new-session-ok pid=${a.pid} sessionId=${a.sessionId.slice(0,8)} permissionMode=${e.permissionMode} model=${e.model??`default`} ms=${Date.now()-n}`),F.setSessions(e=>[a,...e]),be(!1);let o=a.sessionId,s=o.slice(0,8);if(e.placeholder===null)console.info(`[admin-ui] new-session-auto-open outcome=fallback sessionId=${s}`),ne(o);else{let t=setTimeout(()=>{let e=G.current.get(o);e&&(G.current.delete(o),e.placeholder.closed||e.placeholder.close(),console.info(`[admin-ui] new-session-auto-open outcome=timeout sessionId=${s}`))},Ve);G.current.set(o,{placeholder:e.placeholder,timeoutId:t})}}catch(e){let t=e instanceof Error?e.message:String(e);U(t),console.error(`[admin-ui] sidebar-new-session-threw ms=${Date.now()-n} message=${t}`)}finally{fe(!1)}},[c,B,F,ne]),$=pe(c,F,`sidebar`),it=(0,N.useCallback)(async e=>{let t=await $.resume(e);t.ok||console.error(`[admin-ui] sidebar-resume failed: ${t.error}`)},[$]),at=(0,N.useCallback)(async e=>{z(!0),R(null);let t=await $.purge(e);t.ok?L(null):R(t.error??`purge failed`),z(!1)},[$]),ot=(0,N.useCallback)(async e=>{let t=await $.end(e);t.ok||console.error(`[admin-ui] sidebar-end-session failed: ${t.error}`)},[$]),st=(0,N.useCallback)(async e=>{let t=await $.archive(e);t.ok||console.error(`[admin-ui] sidebar-archive failed: ${t.error}`)},[$]),ct=(0,N.useCallback)(async e=>{let t=await $.unarchive(e);t.ok||console.error(`[admin-ui] sidebar-unarchive failed: ${t.error}`)},[$]),[lt,ut]=(0,N.useState)(null),[dt,ft]=(0,N.useState)(``),pt=(0,N.useCallback)(async(e,t)=>{let n=dt.trim();if(n.length===0||!ue(n)){ut(null);return}if(n===(t??``)){ut(null);return}let r=await $.rename(e,n);r.ok||console.error(`[admin-ui] sidebar-rename failed: ${r.error}`),ut(null)},[dt,$]),mt=(0,N.useCallback)(()=>{ut(null)},[]);return(0,P.jsxs)(`aside`,{className:`side`,children:[q===`chat`&&(0,P.jsxs)(`div`,{className:`side-new-session-row`,ref:ze,children:[(0,P.jsxs)(`button`,{type:`button`,className:`side-new-session`,onClick:tt,disabled:B||!c,children:[B?(0,P.jsx)(w,{size:14,className:`spinning`}):(0,P.jsx)(te,{size:14}),(0,P.jsx)(`span`,{children:`New session`})]}),(0,P.jsxs)(`button`,{type:`button`,className:`side-mode-trigger`,onClick:()=>{let e=!X;console.info(`[admin-ui] sidebar-mode-picker action=${e?`open`:`close`} mode=${V}`),Z(e)},disabled:B,"aria-haspopup":`menu`,"aria-expanded":X,"aria-label":`Permission mode for the next session`,title:`Shift+Cmd+M`,children:[He[V],(0,P.jsx)(o,{size:12,"aria-hidden":`true`})]}),X&&(0,P.jsxs)(`div`,{className:`side-mode-popover`,role:`menu`,"aria-label":`Mode`,children:[(0,P.jsxs)(`div`,{className:`side-mode-popover-head`,children:[(0,P.jsx)(`span`,{children:`Mode`}),(0,P.jsx)(`span`,{className:`side-mode-popover-shortcut`,"aria-hidden":`true`,children:`⇧⌘M`})]}),Ue.map((e,n)=>(0,P.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`side-mode-popover-item`,onClick:()=>{console.info(`[admin-ui] sidebar-mode-picker action=select mode=${e}`),H(e),Z(!1),qe({permissionMode:e,model:me},`sidebar`)},children:[(0,P.jsx)(`span`,{children:He[e]}),(0,P.jsxs)(`span`,{className:`side-mode-popover-shortcut`,children:[e===V&&(0,P.jsx)(t,{size:12}),(0,P.jsx)(`span`,{children:n+1})]})]},e))]})]}),(0,P.jsxs)(`nav`,{className:`side-nav`,children:[(0,P.jsxs)(`button`,{type:`button`,className:`nav-row${q===`chat`?` active`:``}`,onClick:Ye,children:[(0,P.jsx)(ie,{size:20,strokeWidth:Q}),(0,P.jsx)(`span`,{className:`label`,children:`Sessions`}),(0,P.jsx)(`span`,{className:`kbd`})]}),(0,P.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=people`),D(),j()},children:[(0,P.jsx)(ae,{size:20,strokeWidth:Q}),(0,P.jsx)(`span`,{className:`label`,children:`People`}),(0,P.jsx)(`span`,{className:`kbd`})]}),(0,P.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=agents`),ee(),j()},children:[(0,P.jsx)(_,{size:20,strokeWidth:Q}),(0,P.jsx)(`span`,{className:`label`,children:`Agents`}),(0,P.jsx)(`span`,{className:`kbd`})]}),(0,P.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=projects`),E(),j()},children:[(0,P.jsx)(v,{size:20,strokeWidth:Q}),(0,P.jsx)(`span`,{className:`label`,children:`Projects`}),(0,P.jsx)(`span`,{className:`kbd`})]}),(0,P.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=tasks`),O(),j()},children:[(0,P.jsx)(C,{size:20,strokeWidth:Q}),(0,P.jsx)(`span`,{className:`label`,children:`Tasks`}),(0,P.jsx)(`span`,{className:`kbd`})]}),(0,P.jsxs)(`button`,{type:`button`,className:`nav-row${q===`artefacts`?` active`:``}`,onClick:Xe,children:[(0,P.jsx)(s,{size:20,strokeWidth:Q}),(0,P.jsx)(`span`,{className:`label`,children:`Artefacts`}),(0,P.jsx)(`span`,{className:`kbd`})]})]}),(0,P.jsxs)(`div`,{className:`side-list`,ref:de,children:[(0,P.jsxs)(`div`,{className:`group-head`,children:[(0,P.jsx)(`span`,{children:Ze}),(0,P.jsxs)(`span`,{className:`group-head-meta`,children:[(0,P.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh ${Ze.toLowerCase()}`,"aria-label":`Refresh ${Ze.toLowerCase()}`,onClick:et,disabled:$e,children:(0,P.jsx)(A,{size:12,className:$e?`spinning`:void 0})}),(0,P.jsx)(`span`,{children:Qe})]})]}),q===`chat`&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(We,{view:K.view,setView:e=>{console.info(`[admin-ui] sidebar-view-change view=${e}`),K.setView(e)},connected:K.connected,reconnectNow:K.reconnectNow}),y&&(0,P.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:y}),Te.map(e=>{let t=M===e.sessionId,n=lt===e.sessionId;return(0,P.jsxs)(`div`,{className:`conv${t?` active`:``}`,children:[n?(0,P.jsxs)(`span`,{className:`conv-name-line`,style:{flex:1,minWidth:0},children:[(0,P.jsx)(ie,{size:12,className:`conv-channel-icon`,"aria-label":`claude session`}),(0,P.jsx)(Ge,{live:e.live,status:e.status}),(0,P.jsx)(`input`,{type:`text`,value:dt,autoFocus:!0,maxLength:200,onChange:e=>ft(e.target.value),onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),pt(e.sessionId,e.firstPrompt)):t.key===`Escape`&&(t.preventDefault(),mt())},onBlur:()=>{pt(e.sessionId,e.firstPrompt)},className:`conv-name`,"aria-label":`Rename session`,style:{flex:1,minWidth:0,background:`transparent`,border:`none`,outline:`none`,color:`inherit`,font:`inherit`}})]}):(0,P.jsxs)(`button`,{type:`button`,className:`conv-name-button`,onClick:()=>{ne(e.sessionId),j()},title:`Show metadata`,children:[(0,P.jsxs)(`span`,{className:`conv-name-line`,children:[(0,P.jsx)(ie,{size:12,className:`conv-channel-icon`,"aria-label":`claude session`}),(0,P.jsx)(Ge,{live:e.live,status:e.status}),e.firstPrompt?(0,P.jsx)(`span`,{className:`conv-name`,children:e.firstPrompt}):(0,P.jsxs)(`span`,{className:`conv-name`,style:{fontStyle:`italic`,opacity:.6},children:[`(unnamed · `,e.sessionId.slice(0,8),`)`]})]}),(0,P.jsx)(`span`,{className:`conv-timestamp`,children:Ie(e.updatedAt,De)})]}),!n&&(0,P.jsx)(`button`,{type:`button`,className:`conversations-action`,title:`Rename`,"aria-label":`Rename session`,onClick:()=>{ft(e.firstPrompt??``),ut(e.sessionId)},children:(0,P.jsx)(k,{size:13})}),e.url!==null&&(0,P.jsx)(`button`,{type:`button`,className:`conversations-action`,title:`Open in new tab`,"aria-label":`Open in new tab`,onClick:()=>Ke(e.url,e.sessionId),children:(0,P.jsx)(x,{size:13})}),e.live?(0,P.jsx)(`button`,{type:`button`,className:`conversations-action`,title:`End session`,"aria-label":`End session`,onClick:()=>void ot(e.sessionId),disabled:$.inFlight===`end`,children:$.inFlight===`end`?(0,P.jsx)(w,{size:13,className:`spinning`}):(0,P.jsx)(re,{size:13})}):e.archived?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`button`,{type:`button`,className:`conversations-action`,title:`Unarchive session`,"aria-label":`Unarchive session`,onClick:()=>void ct(e.sessionId),disabled:$.inFlight===`unarchive`,children:$.inFlight===`unarchive`?(0,P.jsx)(w,{size:13,className:`spinning`}):(0,P.jsx)(h,{size:13})}),(0,P.jsx)(`button`,{type:`button`,className:`conversations-action`,title:`Purge JSONL`,"aria-label":`Purge JSONL`,onClick:()=>{R(null),L({sessionId:e.sessionId,displayName:e.firstPrompt})},children:(0,P.jsx)(a,{size:13})})]}):(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`button`,{type:`button`,className:`conversations-action`,title:`Resume session`,"aria-label":`Resume session`,onClick:()=>void it(e.sessionId),disabled:$.inFlight===`resume`,children:$.inFlight===`resume`?(0,P.jsx)(w,{size:13,className:`spinning`}):(0,P.jsx)(l,{size:13})}),(0,P.jsx)(`button`,{type:`button`,className:`conversations-action`,title:`Archive session`,"aria-label":`Archive session`,onClick:()=>void st(e.sessionId),disabled:$.inFlight===`archive`,children:$.inFlight===`archive`?(0,P.jsx)(w,{size:13,className:`spinning`}):(0,P.jsx)(g,{size:13})}),(0,P.jsx)(`button`,{type:`button`,className:`conversations-action`,title:`Purge JSONL`,"aria-label":`Purge JSONL`,onClick:()=>{R(null),L({sessionId:e.sessionId,displayName:e.firstPrompt})},children:(0,P.jsx)(a,{size:13})})]})]},e.sessionId)})]}),q===`artefacts`&&(0,P.jsxs)(P.Fragment,{children:[Ne&&(0,P.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:Ne}),je&&!Ne&&Y.length===0&&(0,P.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No artefacts yet`}),Y.map(e=>(0,P.jsxs)(`button`,{type:`button`,className:`conv`,onClick:()=>{T({docId:e.id,name:e.name,content:e.content,editable:e.editable,mimeType:e.mimeType,skipReason:e.skipReason},`sidebar-artefacts`),j()},children:[(0,P.jsx)(`span`,{className:`conv-name`,children:e.name}),(0,P.jsx)(`span`,{className:`conv-kind`,"data-kind":e.kind===`agent-template`?`agent`:`doc`,children:e.kind===`agent-template`?`agent`:`doc`})]},e.id))]})]}),(0,P.jsxs)(`div`,{className:`side-foot`,children:[(0,P.jsx)(`div`,{className:`avatar`,children:f?(0,P.jsx)(`img`,{src:f,alt:Se}):Ce}),(0,P.jsxs)(`div`,{className:`who`,children:[(0,P.jsx)(`span`,{className:`name`,children:Se}),(0,P.jsx)(`span`,{className:`role`,children:u??`operator`})]})]}),ye&&(0,P.jsx)(Be,{seedMode:V,seedModel:me,submitting:B,error:ve,onSubmit:e=>void rt(e),onCancel:nt,onErrorClear:()=>U(null)}),I&&(0,P.jsx)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":`purge-confirm-title`,className:`modal-overlay`,onClick:e=>{e.target===e.currentTarget&&!le&&L(null)},children:(0,P.jsxs)(`div`,{className:`modal-card`,children:[(0,P.jsx)(`h3`,{id:`purge-confirm-title`,style:{margin:0,marginBottom:8,fontSize:16,fontWeight:600},children:`Purge session JSONL?`}),(0,P.jsxs)(`p`,{style:{margin:0,marginBottom:8,fontSize:13},children:[`This hard-deletes the transcript for `,(0,P.jsx)(`strong`,{children:I.displayName??I.sessionId.slice(0,8)}),`. The action cannot be undone.`]}),ce&&(0,P.jsx)(`p`,{style:{margin:0,marginBottom:8,fontSize:12,color:`var(--text-tertiary)`},children:ce}),(0,P.jsxs)(`div`,{className:`modal-action-row`,children:[(0,P.jsx)(`button`,{type:`button`,className:`modal-action-btn`,disabled:le,onClick:()=>L(null),children:`Cancel`}),(0,P.jsx)(`button`,{type:`button`,className:`modal-action-btn`,"data-variant":`danger`,disabled:le,onClick:()=>void at(I.sessionId),children:le?(0,P.jsx)(w,{size:13,className:`spinning`}):`Purge`})]})]})})]})}),Ue=[{value:`active`,label:`Active`},{value:`archived`,label:`Archived`},{value:`all`,label:`All`}];function We(e){let{view:t,setView:n,connected:r,reconnectNow:i}=e;return(0,P.jsx)(`div`,{className:`session-view-controls`,children:(0,P.jsxs)(`div`,{className:`session-view-segmented`,role:`tablist`,"aria-label":`Session view`,children:[Ue.map(e=>(0,P.jsx)(`button`,{type:`button`,role:`tab`,className:`session-view-tab${t===e.value?` active`:``}`,"aria-selected":t===e.value,onClick:()=>n(e.value),children:e.label},e.value)),r?(0,P.jsx)(`span`,{className:`session-view-connection connected`,"aria-label":`Live updates connected.`,title:`Live updates connected.`}):(0,P.jsx)(`button`,{type:`button`,className:`session-view-connection disconnected`,"aria-label":`Live updates paused. Click to retry.`,title:`Live updates paused. Click to retry.`,onClick:i})]})})}function Ge({live:e,status:t}){return e?t===`busy`?(0,P.jsxs)(`span`,{className:`session-status session-status-busy`,"aria-label":`session busy`,children:[(0,P.jsx)(`span`,{className:`session-status-dot`}),(0,P.jsx)(`span`,{className:`session-status-dot`}),(0,P.jsx)(`span`,{className:`session-status-dot`})]}):t===`detached`?(0,P.jsx)(`span`,{className:`session-status session-status-detached`,"aria-label":`session detached — manager restart survivor`}):(0,P.jsx)(`span`,{className:`session-status session-status-idle`,"aria-label":`session idle`}):(0,P.jsx)(`span`,{className:`session-status session-status-archived`,"aria-label":`session archived`})}function Ke(e,t){let n=t.slice(0,8),r=window.open(e,`_blank`,`noopener,noreferrer`)===null?`blocked`:`ok`;console.info(`[admin-ui] sidebar-open-in-new-tab outcome=${r} sessionId=${n}`)}function qe(){(0,N.useEffect)(()=>{function e(e){e.data?.type===`vnc-clipboard`&&typeof e.data.text==`string`&&u(e.data.text)}window.addEventListener(`message`,e);let t=null;return typeof BroadcastChannel<`u`&&(t=new BroadcastChannel(`maxy-vnc-clipboard`),t.onmessage=e=>{typeof e.data==`string`&&u(e.data)}),()=>{window.removeEventListener(`message`,e),t?.close()}},[])}function Je({handlePopout:e,disabled:t=!1}){let n=(0,N.useCallback)(()=>{delete document.body.dataset.dragPopoutActive},[]);(0,N.useEffect)(()=>()=>n(),[n]);let r=(0,N.useCallback)(e=>{if(t){e.preventDefault();return}let n=e.target;if(n.closest(`.editor-base__actions`)||n.closest(`.browser-viewer__actions`)){e.preventDefault();return}if(!document.querySelector(`.chat-messages`)){e.preventDefault();return}e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,``),document.body.dataset.dragPopoutActive=`true`},[t,n]),i=(0,N.useCallback)(t=>{if(n(),t.clientX===0&&t.clientY===0)return;let r=document.querySelector(`.chat-messages`);if(!r)return;let i=r.getBoundingClientRect();(t.clientX<i.left||t.clientX>i.right||t.clientY<i.top||t.clientY>i.bottom)&&e()},[e,n]);return t?{draggable:!1,onDragStart:()=>{},onDragEnd:()=>{}}:{draggable:!0,onDragStart:r,onDragEnd:i}}function Ye(e){(0,N.useEffect)(()=>{let t=Date.now(),r=`/api/admin/browser-iframe/event`,i={brand:n.productName,surface:e};return fetch(r,{method:`POST`,credentials:`same-origin`,headers:{"Content-Type":`application/json`},body:JSON.stringify({event:`mount`,...i}),keepalive:!0}).catch(()=>{}),()=>{let e=JSON.stringify({event:`unmount`,durationMs:Date.now()-t,...i});try{let t=new Blob([e],{type:`application/json`});navigator.sendBeacon(r,t)||fetch(r,{method:`POST`,credentials:`same-origin`,headers:{"Content-Type":`application/json`},body:e,keepalive:!0}).catch(()=>{})}catch{}}},[e])}var Xe=`maxy-vnc-overlay-popout`;function Q(e){let[t,r]=(0,N.useState)(!1),i=(0,N.useRef)(null),a=(0,N.useRef)(null),o=(0,N.useCallback)(()=>{a.current&&=(clearInterval(a.current),null),i.current&&!i.current.closed&&i.current.close(),i.current=null,r(!1)},[]),s=(0,N.useCallback)(()=>{let t=`/vnc-popout.html?title=${encodeURIComponent(n.productName)}`,s=window.open(t,Xe,`width=1024,height=768`);s&&(i.current=s,r(!0),a.current=setInterval(()=>{i.current?.closed&&(o(),e?.())},500))},[o,e]);return(0,N.useEffect)(()=>()=>o(),[o]),{poppedOut:t,popout:s,cleanupPopout:o}}var Ze=(0,N.forwardRef)(function({onClose:e},t){qe(),Ye(`overlay`);let{poppedOut:r,popout:i,cleanupPopout:a}=Q(e);return(0,N.useImperativeHandle)(t,()=>({popout:i}),[i]),r?(0,P.jsxs)(`div`,{className:`browser-overlay-popout`,children:[(0,P.jsx)(c,{className:`browser-viewer__icon`}),(0,P.jsx)(`span`,{className:`browser-viewer__title`,children:n.productName}),(0,P.jsx)(`span`,{className:`browser-viewer__popout-label`,children:`Popped out`}),(0,P.jsx)(f,{variant:`ghost`,size:`sm`,icon:D,onClick:()=>a(),"aria-label":`Pop back in`}),e&&(0,P.jsx)(f,{variant:`ghost`,size:`sm`,icon:M,onClick:()=>{a(),e()},"aria-label":`Close`})]}):(0,P.jsx)(`iframe`,{src:`/vnc-viewer.html`,className:`browser-surface__iframe`,title:n.productName})});function Qe({onClose:e}){qe(),Ye(`overlay`);let{poppedOut:t,popout:r,cleanupPopout:i}=Q(e),a=(0,N.useCallback)(()=>{i(),e()},[i,e]);(0,N.useEffect)(()=>{if(t)return;let e=e=>{e.key===`Escape`&&a()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,a]);let o=Je({handlePopout:r,disabled:t});return t?(0,P.jsxs)(`div`,{className:`browser-overlay-popout`,children:[(0,P.jsx)(c,{className:`browser-viewer__icon`}),(0,P.jsx)(`span`,{className:`browser-viewer__title`,children:n.productName}),(0,P.jsx)(`span`,{className:`browser-viewer__popout-label`,children:`Popped out`}),(0,P.jsx)(f,{variant:`ghost`,size:`sm`,icon:D,onClick:()=>{i()},"aria-label":`Pop back in`}),(0,P.jsx)(f,{variant:`ghost`,size:`sm`,icon:M,onClick:a,"aria-label":`Close`})]}):(0,P.jsxs)(`div`,{className:`browser-viewer-fullscreen`,children:[(0,P.jsxs)(`div`,{className:`browser-viewer-fullscreen__bar`,...o,children:[(0,P.jsx)(c,{className:`browser-viewer__icon`}),(0,P.jsx)(`span`,{className:`browser-viewer-fullscreen__title`,children:n.productName}),(0,P.jsxs)(`div`,{className:`browser-viewer-fullscreen__actions`,children:[(0,P.jsx)(f,{variant:`ghost`,size:`sm`,icon:x,onClick:r,"aria-label":`Pop out`}),(0,P.jsx)(f,{variant:`ghost`,size:`sm`,icon:M,onClick:a,"aria-label":`Close`})]})]}),(0,P.jsx)(`iframe`,{src:`/vnc-viewer.html`,className:`browser-viewer-fullscreen__iframe`,title:n.productName})]})}function $e(e){return e.map(e=>[e.sessionId,e.displayName,e.lastMessageAt,e.status])}function et(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++){let r=e[n],i=t[n];if(r[0]!==i[0]||r[1]!==i[1]||r[2]!==i[2]||r[3]!==i[3])return!1}return!0}function tt(e){let[t,n]=(0,N.useState)([]),[r,i]=(0,N.useState)(!1),[a,o]=(0,N.useState)(null),[s,c]=(0,N.useState)(null),l=(0,N.useRef)([]),u=(0,N.useCallback)(async t=>{if(!e||!t&&s===e)return null;i(!0),o(null);try{let t=await fetch(`/api/admin/claude-sessions?session_key=${encodeURIComponent(e)}`);if(!t.ok)throw Error(`claude-sessions fetch returned ${t.status}`);let r=await t.json(),i=Array.isArray(r)?r:r.sessions??[],a=$e(i),o=et(l.current,a);return o||(n(i),l.current=a),c(e),console.info(`[admin-ui] sessions-poll outcome=${o?`unchanged`:`changed`} count=${i.length} cacheKey=${e.slice(0,8)}`),i}catch(t){return console.info(`[admin-ui] sessions-poll outcome=error count=0 cacheKey=${e.slice(0,8)}`),console.error(`[admin/claude-sessions] fetch failed:`,t),o(t instanceof Error?t.message:String(t)),null}finally{i(!1)}},[e,s]);(0,N.useEffect)(()=>{e||(c(null),n([]),o(null),l.current=[])},[e]);let d=(0,N.useCallback)(()=>u(!1),[u]),f=(0,N.useCallback)(()=>u(!0),[u]);return{sessions:t,setSessions:n,loading:r,loaded:s!==null&&s===e,error:a,ensureLoaded:d,refetch:f}}var nt=`admin-sidebar-collapsed`,rt=`admin-sidebar-drawer-open`;function $(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(nt)===`1`}catch{return!1}}function it(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(nt,`1`):window.sessionStorage.removeItem(nt)}catch{}}function at(){if(typeof window>`u`)return!1;try{return window.sessionStorage.getItem(rt)===`1`}catch{return!1}}function ot(e){if(!(typeof window>`u`))try{e?window.sessionStorage.setItem(rt,`1`):window.sessionStorage.removeItem(rt)}catch{}}var st=720;function ct(e){let{cacheKey:t,businessName:n,onLaunchBrowser:r,onLogout:i,browserLaunching:a,userName:o,userAvatar:s,role:c,selectedSessionId:l,onSelectSession:u,onSelectArtefact:d,dataArtefact:f=`closed`,children:p,footer:m}=e,[h,g]=(0,N.useState)(()=>$()),[_,v]=(0,N.useState)(()=>at()),[y,b]=(0,N.useState)(()=>typeof window<`u`&&window.matchMedia(`(max-width: ${st}px)`).matches);(0,N.useEffect)(()=>{if(typeof window>`u`)return;let e=window.matchMedia(`(max-width: ${st}px)`),t=e=>b(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let x=(0,N.useCallback)(e=>{it(e),g(e)},[]),S=(0,N.useCallback)(e=>{ot(e),v(e)},[]);(0,N.useEffect)(()=>{if(typeof window>`u`)return;let e=window.location?.pathname??``;console.info(`[admin-ui] shell-mount route=${e} collapsed=${h} drawer=${_}`)},[]);let C=y?_:!h,w=(0,N.useCallback)(()=>{if(!(typeof window>`u`))if(window.matchMedia(`(max-width: ${st}px)`).matches){let e=_;console.info(`[admin-ui] header-sidebar-toggle from=${e?`open`:`closed`} mode=drawer`),S(!e)}else{let e=h;console.info(`[admin-ui] header-sidebar-toggle from=${e?`closed`:`open`} mode=collapse`),x(!e)}},[h,_,x,S]),T=(0,N.useCallback)(e=>{console.info(`[admin-ui] header-menu-nav target=${e}`),window.location.href=e===`data`?`/data`:`/graph`},[]),[E,D]=(0,N.useState)(!1),[O,ee]=(0,N.useState)(!1),k=(0,N.useCallback)(async()=>{if(E)return;D(!0);let e=typeof window<`u`?window.location?.pathname??``:``,t=`n/a`;try{let n=await fetch(`/api/admin/browser/launch`,{method:`POST`});t=n.status;let r=await n.json().catch(()=>({ok:!1,error:`Invalid response`}));if(!r.ok)throw Error(r.error??`Failed to launch browser`);ee(!0),console.info(`[admin-ui] header-menu-browser-launch outcome=ok source=shell-overlay route=${e} httpStatus=${t}`)}catch(n){console.error(`[admin-ui] header-menu-browser-launch outcome=error source=shell-overlay route=${e} httpStatus=${t} error="${n instanceof Error?n.message:String(n)}"`),window.alert(n instanceof Error?n.message:`Failed to launch browser`)}finally{D(!1)}},[E]),te=a??E,A=tt(t),j=Oe(t),ne=(0,N.useMemo)(()=>j.rows.map(e=>e.sessionId),[j.rows]),re=(0,N.useCallback)(e=>{if(u){u(e);return}window.location.assign(`/?sessionId=${encodeURIComponent(e)}`)},[u]),ie=(0,N.useCallback)(e=>{d&&d(e)},[d]),ae={collapsed:h,mobileDrawerOpen:_,sidebarOpen:C,onToggleSidebar:w,setMobileDrawerOpen:S,sessionsState:A,sessionRowIds:ne,sessionRowsConnected:j.connected};return(0,P.jsxs)(`div`,{className:`admin-shell admin-page admin-shell-root`,children:[(0,P.jsx)(ge,{businessName:n,onLaunchBrowser:r??k,onNavigate:T,onToggleSidebar:w,sidebarOpen:C,onLogout:i,browserLaunching:te}),(0,P.jsxs)(`div`,{className:`platform${_?` menu-open`:``}${h?` sidebar-collapsed`:``}`,"data-artefact":f,children:[(0,P.jsx)(He,{businessName:n,cacheKey:t,role:c??null,userName:o,userAvatar:s??null,sessions:A.sessions,sessionsLoading:A.loading,sessionsError:A.error,ensureSessionsLoaded:A.ensureLoaded,refetchSessions:A.refetch,onSelectArtefact:ie,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),onSelectSession:re,selectedSessionId:l??null,collapsed:h,mobileDrawerOpen:_,recentsActions:{setSessions:A.setSessions,refetch:A.refetch}}),typeof p==`function`?p(ae):p]}),_&&(0,P.jsx)(`div`,{className:`sidebar-backdrop menu-open`,"aria-hidden":`true`,onClick:()=>S(!1)}),O&&(0,P.jsx)(Qe,{onClose:()=>ee(!1)}),m]})}var lt={LocalBusiness:`#4F6B8A`,Service:`#6B85A0`,PriceSpecification:`#8AA0B8`,OpeningHoursSpecification:`#A8BACE`,Organization:`#8A6B47`,Person:`#B86E4A`,UserProfile:`#D08960`,Preference:`#DFA67A`,AdminUser:`#8C5230`,AccessGrant:`#66381F`,KnowledgeDocument:`#6E8A5A`,ConversationArchive:`#82A06A`,Section:`#8AA876`,Chunk:`#A6C194`,DigitalDocument:`#5A7548`,CreativeWork:`#B5C9A2`,Question:`#C7D6B5`,FAQPage:`#95B385`,DefinedTerm:`#76906A`,Review:`#3F5A2E`,ImageObject:`#A0BB8C`,Conversation:`#6B5A85`,AdminConversation:`#4F4070`,PublicConversation:`#8A75A8`,Message:`#6B7280`,UserMessage:`#DFA67A`,AssistantMessage:`#C9A876`,ToolCall:`#B5ABCB`,Task:`#B0617A`,Project:`#8E4A60`,Event:`#C68095`,Workflow:`#3A6F77`,WorkflowStep:`#5A8E96`,WorkflowRun:`#7AAAB2`,StepResult:`#9CC4CB`,Email:`#6F7F4A`,EmailAccount:`#91A063`,Agent:`#B8893D`},ut=`#94A3B8`;Object.freeze(Object.keys(lt)),Object.freeze(new Set([`Chunk`,`GraphPreference`]));var dt=Object.freeze(new Set(`LocalBusiness.Service.PriceSpecification.OpeningHoursSpecification.Organization.Person.UserProfile.Preference.AdminUser.AccessGrant.KnowledgeDocument.DigitalDocument.CreativeWork.Question.FAQPage.DefinedTerm.Review.ImageObject.AdminConversation.PublicConversation.Task.Project.Event.Workflow.Email.EmailAccount.Agent`.split(`.`)));Object.freeze(new Set([`ToolCall`,`StepResult`,`WorkflowStep`,`WorkflowRun`])),Object.freeze(new Set([`HAS_TOOL_CALL`,`RUN_OF`,`HAS_STEP`,`HAS_RESULT`]));function ft(e){for(let t=1;t<e.length;t++)if(Object.prototype.hasOwnProperty.call(lt,e[t]))return e[t];return e[0]??null}function pt(e){return lt[e]??`#94A3B8`}function mt(e){let t=ft(e),n=t?pt(t):ut,r=0;for(let t=1;t<e.length;t++)Object.prototype.hasOwnProperty.call(lt,e[t])&&r++;return{displayLabel:t,colour:n,driftCandidates:r}}export{x as C,h as E,w as S,g as T,j as _,ct as a,k as b,Je as c,ue as d,pe as f,ne as g,re as h,mt as i,Se as l,M as m,pt as n,Qe as o,L as p,ft as r,Ze as s,dt as t,he as u,A as v,b as w,D as x,te as y};
@@ -1 +1 @@
1
- import{o as e}from"./chunk-DD-I1_y5.js";import{d as t,f as n,v as r,x as i}from"./ChatInput-BmmxQOhM.js";import{C as a,T as o,a as s,l as c,m as l,t as u,v as d}from"./graph-labels-CCTdQ2Vi.js";var f=r(`circle-arrow-up`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m16 12-4-4-4 4`,key:`177agl`}],[`path`,{d:`M12 16V8`,key:`1sbj14`}]]),p=r(`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`}]]),m=r(`file`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}]]),h=r(`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`}]]),g=r(`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`}]]);function _(e){let t=new Set,n=[];for(let r of e)for(let e of r.labels)e&&(t.has(e)||u.has(e)&&(t.add(e),n.push(e)));return n}var v=80;function y(e){let t=b(e.properties)??e.labels[0]??``,n=t.length>v?t.slice(0,v):t;return`/graph?${new URLSearchParams({nodeId:e.nodeId,label:n}).toString()}`}function b(e){for(let t of[`title`,`name`,`summary`,`headline`]){let n=e[t];if(typeof n==`string`&&n.length>0)return n}return null}var x=e(i(),1),S=t();function C(){let[e,t]=(0,x.useState)(null),[n,r]=(0,x.useState)(!1),[i,c]=(0,x.useState)(void 0),[u,d]=(0,x.useState)(null),[f,p]=(0,x.useState)(void 0),[m,h]=(0,x.useState)(null),[g,_]=(0,x.useState)(null);(0,x.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!n){t(null),r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}if(i.ok)try{let e=await i.json();typeof e.businessName==`string`&&c(e.businessName),e.conversationId!==void 0&&d(e.conversationId??null),_(e.role??null),p(e.userName===void 0?null:e.userName),h(e.avatar??null)}catch{}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]);let v=(0,x.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]);return n?e?(0,S.jsxs)(s,{cacheKey:e,businessName:i,conversationId:u,onLogout:v,userName:f,userAvatar:m,role:g,children:[(0,S.jsx)(l,{}),(0,S.jsxs)(`div`,{className:`data-page`,children:[(0,S.jsx)(`header`,{className:`data-header`,children:(0,S.jsxs)(`h1`,{className:`data-title`,children:[(0,S.jsx)(o,{size:18}),` Data`]})}),(0,S.jsx)(w,{cacheKey:e})]})]}):(0,S.jsxs)(`div`,{className:`data-page`,children:[(0,S.jsx)(`header`,{className:`data-header`,children:(0,S.jsxs)(`h1`,{className:`data-title`,children:[(0,S.jsx)(o,{size:18}),` Data`]})}),(0,S.jsxs)(`div`,{className:`data-empty`,children:[(0,S.jsx)(`p`,{children:`You are not signed in.`}),(0,S.jsxs)(`p`,{children:[`Open the `,(0,S.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})]}):(0,S.jsx)(`div`,{className:`data-page`,children:(0,S.jsxs)(`div`,{className:`data-loading`,children:[(0,S.jsx)(a,{size:18,className:`spin`}),` Loading…`]})})}function w({cacheKey:e,onOpenInGraph:t}){let{adminFetch:n,cacheKey:r,sessionRefetchNonce:i,banner:a,reloadToLogin:o}=c({initialCacheKey:e,surface:`data`});return(0,S.jsxs)(`main`,{className:`data-main`,children:[a&&(0,S.jsx)(`button`,{type:`button`,className:`data-session-banner`,onClick:o,"data-reason":a.reason,children:a.message}),(0,S.jsx)(T,{adminFetch:n,sessionRefetchNonce:i,onOpenInGraph:t}),(0,S.jsx)(A,{adminFetch:n,cacheKey:r,sessionRefetchNonce:i})]})}function T({adminFetch:e,sessionRefetchNonce:t,onOpenInGraph:n}){let[r,i]=(0,x.useState)(``),[o,s]=(0,x.useState)(``),[c,l]=(0,x.useState)(null),[u,f]=(0,x.useState)(`hybrid`),[p,m]=(0,x.useState)(!1),[h,g]=(0,x.useState)(null),[v,b]=(0,x.useState)(null),[C,w]=(0,x.useState)(0),[T,O]=(0,x.useState)(!1);(0,x.useEffect)(()=>{let e=r.trim();if(!e){s(``),l(null);return}O(!1);let t=setTimeout(()=>s(e),300);return()=>clearTimeout(t)},[r]),(0,x.useEffect)(()=>{if(!o)return;let t=!1;return m(!0),g(null),e(`/api/admin/graph-search?q=${encodeURIComponent(o)}&labels=*&limit=20${T?`&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||(l(e.results),f(e.mode??`hybrid`),w(typeof e.suppressed==`number`?e.suppressed:0))}).catch(e=>{t||g(e instanceof Error?e.message:String(e))}).finally(()=>{t||m(!1)}),()=>{t=!0}},[o,e,t,T]);let k=(0,x.useMemo)(()=>c?_(c):[],[c]),A=v&&k.includes(v)?v:null,j=(0,x.useMemo)(()=>c?A?c.filter(e=>e.labels.includes(A)):c:null,[c,A]),M=(0,x.useCallback)(e=>{if(n){n(e);return}window.location.href=y(e)},[n]);return(0,S.jsxs)(`section`,{className:`data-panel`,children:[(0,S.jsx)(`h2`,{className:`data-panel-title`,children:`Search`}),(0,S.jsx)(`p`,{className:`data-panel-subtitle`,children:`Find anything in your knowledge base by keyword.`}),(0,S.jsxs)(`div`,{className:`data-search-input`,children:[(0,S.jsx)(d,{size:14}),(0,S.jsx)(`input`,{type:`text`,placeholder:`Search your knowledge…`,value:r,onChange:e=>i(e.target.value),autoFocus:!0,autoComplete:`off`,spellCheck:!1}),p&&(0,S.jsx)(a,{size:14,className:`spin`})]}),h&&(0,S.jsxs)(`div`,{className:`data-error`,children:[`Search failed: `,h]}),k.length>0&&(0,S.jsx)(`div`,{className:`data-chip-row`,role:`group`,"aria-label":`Filter by type`,children:k.map(e=>{let t=e===A;return(0,S.jsx)(`button`,{type:`button`,className:`data-chip`,"data-active":t,onClick:()=>b(t?null:e),children:D([e])??e},e)})}),c&&!p&&(0,S.jsxs)(`div`,{className:`data-results-meta`,children:[j.length,` of `,c.length,` result`,c.length===1?``:`s`]}),c&&!p&&!A&&C>0&&!T&&(0,S.jsxs)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>O(!0),children:[C,` low-confidence result`,C===1?``:`s`,` hidden — show all`]}),c&&!p&&!A&&T&&(0,S.jsx)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>O(!1),children:`Showing all results — hide low-confidence`}),c&&c.length===0&&!p&&(0,S.jsx)(`div`,{className:`data-empty-results`,children:`No matches. Try a different keyword.`}),j&&j.length>0&&(0,S.jsx)(`ul`,{className:`data-results`,children:j.map(e=>(0,S.jsx)(E,{hit:e,mode:u,onOpenInGraph:M},e.nodeId))})]})}function E({hit:e,mode:t,onOpenInGraph:n}){let r=O(e.properties),i=k(e.properties),a=D(e.labels),[o,s]=(0,x.useState)(!1),c=i&&i.length>280,l=o||!c?i:i?.slice(0,280)+`…`,u=t===`bm25`?`bm25 ${e.bm25Score.toFixed(2)}`:`vector ${e.vectorScore.toFixed(2)} · bm25 ${e.bm25Score.toFixed(2)} · combined ${e.score.toFixed(2)}`;return(0,S.jsxs)(`li`,{className:`data-result`,children:[(0,S.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":`Open ${r??a??`node`} in graph`,children:[a&&(0,S.jsx)(`div`,{className:`data-result-header`,children:(0,S.jsx)(`span`,{className:`data-result-labels`,children:a})}),r&&(0,S.jsx)(`div`,{className:`data-result-title`,children:r}),i&&(0,S.jsx)(`pre`,{className:`data-result-body`,children:l}),(0,S.jsx)(`div`,{className:`data-result-scores`,children:u})]}),c&&(0,S.jsx)(`button`,{type:`button`,className:`data-result-toggle`,onClick:()=>s(e=>!e),children:o?`Show less`:`Show more`})]})}function D(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 O(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 k(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 A({adminFetch:e,cacheKey:t,sessionRefetchNonce:r}){let[i,o]=(0,x.useState)(`.`),[s,c]=(0,x.useState)(null),[l,u]=(0,x.useState)([]),[d,_]=(0,x.useState)(!1),[v,y]=(0,x.useState)(null),[b,C]=(0,x.useState)(!1),[w,T]=(0,x.useState)(null),[E,D]=(0,x.useState)(null),[O,k]=(0,x.useState)(null),[A,N]=(0,x.useState)(null),P=(0,x.useRef)(null),[F,I]=(0,x.useState)(0);(0,x.useEffect)(()=>{let t=!1;return _(!0),y(null),e(`/api/admin/files?path=${encodeURIComponent(i===`.`?``:i)}`).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||(c(e.entries),u(e.displayPath??[]))}).catch(e=>{t||(c([]),u([]),y(e instanceof Error?e.message:String(e)))}).finally(()=>{t||_(!1)}),()=>{t=!0}},[e,i,F,r]);let L=(0,x.useCallback)(e=>{o(e)},[]),R=(0,x.useCallback)(()=>{if(i===`.`||i===``)return;let e=i.split(`/`).filter(Boolean);e.pop(),o(e.length===0?`.`:e.join(`/`))},[i]),z=(0,x.useCallback)(e=>{let n=i===`.`?e.name:`${i}/${e.name}`,r=`/api/admin/files/download?session_key=${encodeURIComponent(t)}&path=${encodeURIComponent(n)}`,a=document.createElement(`a`);a.href=r,a.rel=`noopener noreferrer`,document.body.appendChild(a),a.click(),a.remove()},[i,t]),B=(0,x.useCallback)(()=>{P.current?.click()},[]),V=(0,x.useCallback)(e=>{D(null),N(e.name)},[]),H=(0,x.useCallback)(()=>{N(null)},[]),U=(0,x.useCallback)(async t=>{let n=i===`.`?t.name:`${i}/${t.name}`;D(null),N(null),k(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}`);I(e=>e+1)}catch(e){D(e instanceof Error?e.message:String(e))}finally{k(null)}},[i,e]);(0,x.useEffect)(()=>{if(!A)return;let e=e=>{e.key===`Escape`&&N(null)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[A]);let W=(0,x.useCallback)(async e=>{T(null),C(!0);try{let n=new FormData;n.append(`session_key`,t),n.append(`file`,e);let r=await fetch(`/api/admin/files/upload`,{method:`POST`,body:n}),i=await r.json().catch(()=>({error:`HTTP ${r.status}`}));if(!r.ok)throw Error(i.error??`HTTP ${r.status}`);o(i.path.split(`/`).slice(0,-1).join(`/`)||`.`),I(e=>e+1)}catch(e){T(e instanceof Error?e.message:String(e))}finally{C(!1),P.current&&(P.current.value=``)}},[t]);return(0,S.jsxs)(`section`,{className:`data-panel`,children:[(0,S.jsxs)(`div`,{className:`data-panel-heading`,children:[(0,S.jsx)(`h2`,{className:`data-panel-title`,children:`Files`}),(0,S.jsxs)(`div`,{className:`data-file-actions`,children:[(0,S.jsxs)(`button`,{type:`button`,className:`data-btn`,onClick:B,disabled:b,children:[b?(0,S.jsx)(a,{size:14,className:`spin`}):(0,S.jsx)(g,{size:14}),` Upload`]}),(0,S.jsx)(`input`,{type:`file`,ref:P,hidden:!0,onChange:e=>{let t=e.target.files?.[0];t&&W(t)}})]})]}),(0,S.jsxs)(`p`,{className:`data-panel-subtitle`,children:[`Everything under your install's `,(0,S.jsx)(`code`,{children:`data/`}),` directory. Click a folder to open it, a file to download it. Uploads go to `,(0,S.jsx)(`code`,{children:`data/uploads/`}),`.`]}),(0,S.jsxs)(`div`,{className:`data-breadcrumbs`,children:[(0,S.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>L(`.`),children:`data`}),l.map((e,t)=>{let n=l.slice(0,t+1).map(e=>e.name).join(`/`);return(0,S.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,S.jsx)(`span`,{className:`data-crumb-sep`,children:`/`}),(0,S.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>L(n),title:e.name,children:e.displayName??e.name})]},n)}),i!==`.`&&(0,S.jsxs)(`button`,{type:`button`,className:`data-btn data-btn-ghost data-up-btn`,onClick:R,children:[(0,S.jsx)(f,{size:14}),` Up`]})]}),w&&(0,S.jsxs)(`div`,{className:`data-error`,children:[`Upload failed: `,w]}),E&&(0,S.jsxs)(`div`,{className:`data-error`,children:[`Delete failed: `,E]}),v&&(0,S.jsx)(`div`,{className:`data-error`,children:v}),d&&(0,S.jsxs)(`div`,{className:`data-loading`,children:[(0,S.jsx)(a,{size:14,className:`spin`}),` Loading…`]}),!d&&s&&s.length===0&&!v&&(0,S.jsx)(`div`,{className:`data-empty-results`,children:`Empty directory.`}),!d&&s&&s.length>0&&(0,S.jsx)(`ul`,{className:`data-entries`,children:s.map(e=>{let t=e.displayName??e.name,r=O===e.name,o=A===e.name;return(0,S.jsx)(`li`,{className:`data-entry`,children:e.kind===`directory`?(0,S.jsxs)(`button`,{type:`button`,className:`data-entry-btn`,onClick:()=>L(i===`.`?e.name:`${i}/${e.name}`),children:[(0,S.jsx)(h,{size:14}),(0,S.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t})]}):e.kind===`file`?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`button`,{type:`button`,className:`data-entry-btn`,onClick:()=>z(e),title:`Download ${t}`,disabled:o,children:[(0,S.jsx)(m,{size:14}),(0,S.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t}),(0,S.jsxs)(`span`,{className:`data-entry-meta`,title:`Modified ${M(e.modifiedAt)}`,children:[j(e.sizeBytes),` · `,M(e.modifiedAt)]}),(0,S.jsx)(p,{size:12,className:`data-entry-download-icon`})]}),o?(0,S.jsxs)(`div`,{className:`data-entry-confirm`,role:`group`,"aria-label":`Confirm delete ${t}`,children:[(0,S.jsx)(`span`,{className:`data-entry-confirm-label`,children:`Delete?`}),(0,S.jsx)(`button`,{type:`button`,className:`data-entry-confirm-yes`,onClick:()=>U(e),autoFocus:!0,children:`Yes`}),(0,S.jsx)(`button`,{type:`button`,className:`data-entry-confirm-no`,onClick:H,children:`No`})]}):(0,S.jsx)(`button`,{type:`button`,className:`data-entry-delete`,onClick:()=>V(e),disabled:r,title:`Delete ${t}`,"aria-label":`Delete ${t}`,children:r?(0,S.jsx)(a,{size:14,className:`spin`}):(0,S.jsx)(n,{size:14})})]}):(0,S.jsxs)(`div`,{className:`data-entry-btn data-entry-disabled`,children:[(0,S.jsx)(m,{size:14}),(0,S.jsx)(`span`,{className:`data-entry-name`,children:t}),(0,S.jsx)(`span`,{className:`data-entry-meta`,children:`special`})]})},e.name)})})]})}function j(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 M(e){try{let t=new Date(e);if(isNaN(t.getTime()))return`—`;let n=typeof navigator<`u`?navigator.languages&&navigator.languages.length>0?[...navigator.languages]:[navigator.language]:void 0;return t.toLocaleString(n,{dateStyle:`medium`,timeStyle:`short`})}catch{return`—`}}export{p as i,w as n,b as r,C as t};
1
+ import{o as e}from"./chunk-DD-I1_y5.js";import{d as t,f as n,v as r,x as i}from"./ChatInput-BmmxQOhM.js";import{S as a,_ as o,a as s,l as c,p as l,t as u,w as d}from"./graph-labels-IY4_aDc-.js";var f=r(`circle-arrow-up`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m16 12-4-4-4 4`,key:`177agl`}],[`path`,{d:`M12 16V8`,key:`1sbj14`}]]),p=r(`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`}]]),m=r(`file`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}]]),h=r(`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`}]]),g=r(`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`}]]);function _(e){let t=new Set,n=[];for(let r of e)for(let e of r.labels)e&&(t.has(e)||u.has(e)&&(t.add(e),n.push(e)));return n}var v=80;function y(e){let t=b(e.properties)??e.labels[0]??``,n=t.length>v?t.slice(0,v):t;return`/graph?${new URLSearchParams({nodeId:e.nodeId,label:n}).toString()}`}function b(e){for(let t of[`title`,`name`,`summary`,`headline`]){let n=e[t];if(typeof n==`string`&&n.length>0)return n}return null}var x=e(i(),1),S=t();function C(){let[e,t]=(0,x.useState)(null),[n,r]=(0,x.useState)(!1),[i,o]=(0,x.useState)(void 0),[c,u]=(0,x.useState)(null),[f,p]=(0,x.useState)(void 0),[m,h]=(0,x.useState)(null),[g,_]=(0,x.useState)(null);(0,x.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!n){t(null),r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}if(i.ok)try{let e=await i.json();typeof e.businessName==`string`&&o(e.businessName),e.conversationId!==void 0&&u(e.conversationId??null),_(e.role??null),p(e.userName===void 0?null:e.userName),h(e.avatar??null)}catch{}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]);let v=(0,x.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]);return n?e?(0,S.jsxs)(s,{cacheKey:e,businessName:i,conversationId:c,onLogout:v,userName:f,userAvatar:m,role:g,children:[(0,S.jsx)(l,{}),(0,S.jsxs)(`div`,{className:`data-page`,children:[(0,S.jsx)(`header`,{className:`data-header`,children:(0,S.jsxs)(`h1`,{className:`data-title`,children:[(0,S.jsx)(d,{size:18}),` Data`]})}),(0,S.jsx)(w,{cacheKey:e})]})]}):(0,S.jsxs)(`div`,{className:`data-page`,children:[(0,S.jsx)(`header`,{className:`data-header`,children:(0,S.jsxs)(`h1`,{className:`data-title`,children:[(0,S.jsx)(d,{size:18}),` Data`]})}),(0,S.jsxs)(`div`,{className:`data-empty`,children:[(0,S.jsx)(`p`,{children:`You are not signed in.`}),(0,S.jsxs)(`p`,{children:[`Open the `,(0,S.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})]}):(0,S.jsx)(`div`,{className:`data-page`,children:(0,S.jsxs)(`div`,{className:`data-loading`,children:[(0,S.jsx)(a,{size:18,className:`spin`}),` Loading…`]})})}function w({cacheKey:e,onOpenInGraph:t}){let{adminFetch:n,cacheKey:r,sessionRefetchNonce:i,banner:a,reloadToLogin:o}=c({initialCacheKey:e,surface:`data`});return(0,S.jsxs)(`main`,{className:`data-main`,children:[a&&(0,S.jsx)(`button`,{type:`button`,className:`data-session-banner`,onClick:o,"data-reason":a.reason,children:a.message}),(0,S.jsx)(T,{adminFetch:n,sessionRefetchNonce:i,onOpenInGraph:t}),(0,S.jsx)(A,{adminFetch:n,cacheKey:r,sessionRefetchNonce:i})]})}function T({adminFetch:e,sessionRefetchNonce:t,onOpenInGraph:n}){let[r,i]=(0,x.useState)(``),[s,c]=(0,x.useState)(``),[l,u]=(0,x.useState)(null),[d,f]=(0,x.useState)(`hybrid`),[p,m]=(0,x.useState)(!1),[h,g]=(0,x.useState)(null),[v,b]=(0,x.useState)(null),[C,w]=(0,x.useState)(0),[T,O]=(0,x.useState)(!1);(0,x.useEffect)(()=>{let e=r.trim();if(!e){c(``),u(null);return}O(!1);let t=setTimeout(()=>c(e),300);return()=>clearTimeout(t)},[r]),(0,x.useEffect)(()=>{if(!s)return;let t=!1;return m(!0),g(null),e(`/api/admin/graph-search?q=${encodeURIComponent(s)}&labels=*&limit=20${T?`&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||(u(e.results),f(e.mode??`hybrid`),w(typeof e.suppressed==`number`?e.suppressed:0))}).catch(e=>{t||g(e instanceof Error?e.message:String(e))}).finally(()=>{t||m(!1)}),()=>{t=!0}},[s,e,t,T]);let k=(0,x.useMemo)(()=>l?_(l):[],[l]),A=v&&k.includes(v)?v:null,j=(0,x.useMemo)(()=>l?A?l.filter(e=>e.labels.includes(A)):l:null,[l,A]),M=(0,x.useCallback)(e=>{if(n){n(e);return}window.location.href=y(e)},[n]);return(0,S.jsxs)(`section`,{className:`data-panel`,children:[(0,S.jsx)(`h2`,{className:`data-panel-title`,children:`Search`}),(0,S.jsx)(`p`,{className:`data-panel-subtitle`,children:`Find anything in your knowledge base by keyword.`}),(0,S.jsxs)(`div`,{className:`data-search-input`,children:[(0,S.jsx)(o,{size:14}),(0,S.jsx)(`input`,{type:`text`,placeholder:`Search your knowledge…`,value:r,onChange:e=>i(e.target.value),autoFocus:!0,autoComplete:`off`,spellCheck:!1}),p&&(0,S.jsx)(a,{size:14,className:`spin`})]}),h&&(0,S.jsxs)(`div`,{className:`data-error`,children:[`Search failed: `,h]}),k.length>0&&(0,S.jsx)(`div`,{className:`data-chip-row`,role:`group`,"aria-label":`Filter by type`,children:k.map(e=>{let t=e===A;return(0,S.jsx)(`button`,{type:`button`,className:`data-chip`,"data-active":t,onClick:()=>b(t?null:e),children:D([e])??e},e)})}),l&&!p&&(0,S.jsxs)(`div`,{className:`data-results-meta`,children:[j.length,` of `,l.length,` result`,l.length===1?``:`s`]}),l&&!p&&!A&&C>0&&!T&&(0,S.jsxs)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>O(!0),children:[C,` low-confidence result`,C===1?``:`s`,` hidden — show all`]}),l&&!p&&!A&&T&&(0,S.jsx)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>O(!1),children:`Showing all results — hide low-confidence`}),l&&l.length===0&&!p&&(0,S.jsx)(`div`,{className:`data-empty-results`,children:`No matches. Try a different keyword.`}),j&&j.length>0&&(0,S.jsx)(`ul`,{className:`data-results`,children:j.map(e=>(0,S.jsx)(E,{hit:e,mode:d,onOpenInGraph:M},e.nodeId))})]})}function E({hit:e,mode:t,onOpenInGraph:n}){let r=O(e.properties),i=k(e.properties),a=D(e.labels),[o,s]=(0,x.useState)(!1),c=i&&i.length>280,l=o||!c?i:i?.slice(0,280)+`…`,u=t===`bm25`?`bm25 ${e.bm25Score.toFixed(2)}`:`vector ${e.vectorScore.toFixed(2)} · bm25 ${e.bm25Score.toFixed(2)} · combined ${e.score.toFixed(2)}`;return(0,S.jsxs)(`li`,{className:`data-result`,children:[(0,S.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":`Open ${r??a??`node`} in graph`,children:[a&&(0,S.jsx)(`div`,{className:`data-result-header`,children:(0,S.jsx)(`span`,{className:`data-result-labels`,children:a})}),r&&(0,S.jsx)(`div`,{className:`data-result-title`,children:r}),i&&(0,S.jsx)(`pre`,{className:`data-result-body`,children:l}),(0,S.jsx)(`div`,{className:`data-result-scores`,children:u})]}),c&&(0,S.jsx)(`button`,{type:`button`,className:`data-result-toggle`,onClick:()=>s(e=>!e),children:o?`Show less`:`Show more`})]})}function D(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 O(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 k(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 A({adminFetch:e,cacheKey:t,sessionRefetchNonce:r}){let[i,o]=(0,x.useState)(`.`),[s,c]=(0,x.useState)(null),[l,u]=(0,x.useState)([]),[d,_]=(0,x.useState)(!1),[v,y]=(0,x.useState)(null),[b,C]=(0,x.useState)(!1),[w,T]=(0,x.useState)(null),[E,D]=(0,x.useState)(null),[O,k]=(0,x.useState)(null),[A,N]=(0,x.useState)(null),P=(0,x.useRef)(null),[F,I]=(0,x.useState)(0);(0,x.useEffect)(()=>{let t=!1;return _(!0),y(null),e(`/api/admin/files?path=${encodeURIComponent(i===`.`?``:i)}`).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||(c(e.entries),u(e.displayPath??[]))}).catch(e=>{t||(c([]),u([]),y(e instanceof Error?e.message:String(e)))}).finally(()=>{t||_(!1)}),()=>{t=!0}},[e,i,F,r]);let L=(0,x.useCallback)(e=>{o(e)},[]),R=(0,x.useCallback)(()=>{if(i===`.`||i===``)return;let e=i.split(`/`).filter(Boolean);e.pop(),o(e.length===0?`.`:e.join(`/`))},[i]),z=(0,x.useCallback)(e=>{let n=i===`.`?e.name:`${i}/${e.name}`,r=`/api/admin/files/download?session_key=${encodeURIComponent(t)}&path=${encodeURIComponent(n)}`,a=document.createElement(`a`);a.href=r,a.rel=`noopener noreferrer`,document.body.appendChild(a),a.click(),a.remove()},[i,t]),B=(0,x.useCallback)(()=>{P.current?.click()},[]),V=(0,x.useCallback)(e=>{D(null),N(e.name)},[]),H=(0,x.useCallback)(()=>{N(null)},[]),U=(0,x.useCallback)(async t=>{let n=i===`.`?t.name:`${i}/${t.name}`;D(null),N(null),k(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}`);I(e=>e+1)}catch(e){D(e instanceof Error?e.message:String(e))}finally{k(null)}},[i,e]);(0,x.useEffect)(()=>{if(!A)return;let e=e=>{e.key===`Escape`&&N(null)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[A]);let W=(0,x.useCallback)(async e=>{T(null),C(!0);try{let n=new FormData;n.append(`session_key`,t),n.append(`file`,e);let r=await fetch(`/api/admin/files/upload`,{method:`POST`,body:n}),i=await r.json().catch(()=>({error:`HTTP ${r.status}`}));if(!r.ok)throw Error(i.error??`HTTP ${r.status}`);o(i.path.split(`/`).slice(0,-1).join(`/`)||`.`),I(e=>e+1)}catch(e){T(e instanceof Error?e.message:String(e))}finally{C(!1),P.current&&(P.current.value=``)}},[t]);return(0,S.jsxs)(`section`,{className:`data-panel`,children:[(0,S.jsxs)(`div`,{className:`data-panel-heading`,children:[(0,S.jsx)(`h2`,{className:`data-panel-title`,children:`Files`}),(0,S.jsxs)(`div`,{className:`data-file-actions`,children:[(0,S.jsxs)(`button`,{type:`button`,className:`data-btn`,onClick:B,disabled:b,children:[b?(0,S.jsx)(a,{size:14,className:`spin`}):(0,S.jsx)(g,{size:14}),` Upload`]}),(0,S.jsx)(`input`,{type:`file`,ref:P,hidden:!0,onChange:e=>{let t=e.target.files?.[0];t&&W(t)}})]})]}),(0,S.jsxs)(`p`,{className:`data-panel-subtitle`,children:[`Everything under your install's `,(0,S.jsx)(`code`,{children:`data/`}),` directory. Click a folder to open it, a file to download it. Uploads go to `,(0,S.jsx)(`code`,{children:`data/uploads/`}),`.`]}),(0,S.jsxs)(`div`,{className:`data-breadcrumbs`,children:[(0,S.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>L(`.`),children:`data`}),l.map((e,t)=>{let n=l.slice(0,t+1).map(e=>e.name).join(`/`);return(0,S.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,S.jsx)(`span`,{className:`data-crumb-sep`,children:`/`}),(0,S.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>L(n),title:e.name,children:e.displayName??e.name})]},n)}),i!==`.`&&(0,S.jsxs)(`button`,{type:`button`,className:`data-btn data-btn-ghost data-up-btn`,onClick:R,children:[(0,S.jsx)(f,{size:14}),` Up`]})]}),w&&(0,S.jsxs)(`div`,{className:`data-error`,children:[`Upload failed: `,w]}),E&&(0,S.jsxs)(`div`,{className:`data-error`,children:[`Delete failed: `,E]}),v&&(0,S.jsx)(`div`,{className:`data-error`,children:v}),d&&(0,S.jsxs)(`div`,{className:`data-loading`,children:[(0,S.jsx)(a,{size:14,className:`spin`}),` Loading…`]}),!d&&s&&s.length===0&&!v&&(0,S.jsx)(`div`,{className:`data-empty-results`,children:`Empty directory.`}),!d&&s&&s.length>0&&(0,S.jsx)(`ul`,{className:`data-entries`,children:s.map(e=>{let t=e.displayName??e.name,r=O===e.name,o=A===e.name;return(0,S.jsx)(`li`,{className:`data-entry`,children:e.kind===`directory`?(0,S.jsxs)(`button`,{type:`button`,className:`data-entry-btn`,onClick:()=>L(i===`.`?e.name:`${i}/${e.name}`),children:[(0,S.jsx)(h,{size:14}),(0,S.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t})]}):e.kind===`file`?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`button`,{type:`button`,className:`data-entry-btn`,onClick:()=>z(e),title:`Download ${t}`,disabled:o,children:[(0,S.jsx)(m,{size:14}),(0,S.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t}),(0,S.jsxs)(`span`,{className:`data-entry-meta`,title:`Modified ${M(e.modifiedAt)}`,children:[j(e.sizeBytes),` · `,M(e.modifiedAt)]}),(0,S.jsx)(p,{size:12,className:`data-entry-download-icon`})]}),o?(0,S.jsxs)(`div`,{className:`data-entry-confirm`,role:`group`,"aria-label":`Confirm delete ${t}`,children:[(0,S.jsx)(`span`,{className:`data-entry-confirm-label`,children:`Delete?`}),(0,S.jsx)(`button`,{type:`button`,className:`data-entry-confirm-yes`,onClick:()=>U(e),autoFocus:!0,children:`Yes`}),(0,S.jsx)(`button`,{type:`button`,className:`data-entry-confirm-no`,onClick:H,children:`No`})]}):(0,S.jsx)(`button`,{type:`button`,className:`data-entry-delete`,onClick:()=>V(e),disabled:r,title:`Delete ${t}`,"aria-label":`Delete ${t}`,children:r?(0,S.jsx)(a,{size:14,className:`spin`}):(0,S.jsx)(n,{size:14})})]}):(0,S.jsxs)(`div`,{className:`data-entry-btn data-entry-disabled`,children:[(0,S.jsx)(m,{size:14}),(0,S.jsx)(`span`,{className:`data-entry-name`,children:t}),(0,S.jsx)(`span`,{className:`data-entry-meta`,children:`special`})]})},e.name)})})]})}function j(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 M(e){try{let t=new Date(e);if(isNaN(t.getTime()))return`—`;let n=typeof navigator<`u`?navigator.languages&&navigator.languages.length>0?[...navigator.languages]:[navigator.language]:void 0;return t.toLocaleString(n,{dateStyle:`medium`,timeStyle:`short`})}catch{return`—`}}export{p as i,w as n,b as r,C as t};