@rubytech/create-maxy 1.0.797 → 1.0.799
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/payload/platform/neo4j/schema.cypher +34 -0
- package/payload/platform/plugins/docs/references/internals.md +4 -0
- package/payload/platform/plugins/whatsapp/mcp/dist/call-api.d.ts +14 -0
- package/payload/platform/plugins/whatsapp/mcp/dist/call-api.d.ts.map +1 -0
- package/payload/platform/plugins/whatsapp/mcp/dist/call-api.js +42 -0
- package/payload/platform/plugins/whatsapp/mcp/dist/call-api.js.map +1 -0
- package/payload/platform/plugins/whatsapp/mcp/dist/index.js +50 -19
- package/payload/platform/plugins/whatsapp/mcp/dist/index.js.map +1 -1
- package/payload/server/chunk-SBHI2NMF.js +9910 -0
- package/payload/server/chunk-WHF6YXJ5.js +3456 -0
- package/payload/server/client-pool-4YDRTKAT.js +29 -0
- package/payload/server/maxy-edge.js +2 -2
- package/payload/server/public/assets/{admin-Cz8hUAqx.js → admin-C0lKk6WM.js} +1 -1
- package/payload/server/public/index.html +1 -1
- package/payload/server/server.js +434 -122
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
_evictAllForTest,
|
|
3
|
+
_poolSnapshotForTest,
|
|
4
|
+
acquireClient,
|
|
5
|
+
evictClient,
|
|
6
|
+
getActiveClient,
|
|
7
|
+
interruptClient,
|
|
8
|
+
pushUserMessage,
|
|
9
|
+
recordCachedTokens,
|
|
10
|
+
recordCrash,
|
|
11
|
+
setInflight,
|
|
12
|
+
startIdleEvictTick,
|
|
13
|
+
stopIdleEvictTick
|
|
14
|
+
} from "./chunk-WHF6YXJ5.js";
|
|
15
|
+
import "./chunk-JSBRDJBE.js";
|
|
16
|
+
export {
|
|
17
|
+
_evictAllForTest,
|
|
18
|
+
_poolSnapshotForTest,
|
|
19
|
+
acquireClient,
|
|
20
|
+
evictClient,
|
|
21
|
+
getActiveClient,
|
|
22
|
+
interruptClient,
|
|
23
|
+
pushUserMessage,
|
|
24
|
+
recordCachedTokens,
|
|
25
|
+
recordCrash,
|
|
26
|
+
setInflight,
|
|
27
|
+
startIdleEvictTick,
|
|
28
|
+
stopIdleEvictTick
|
|
29
|
+
};
|
|
@@ -349,4 +349,4 @@ ${JSON.stringify(u.input,null,2)}`,f=se.get(r),p=o?void 0:f??t;return(0,V.jsx)(j
|
|
|
349
349
|
|
|
350
350
|
---
|
|
351
351
|
|
|
352
|
-
`)}var LE=[{type:`stream`,label:`Stream`},{type:`error`,label:`Errors`},{type:`sse`,label:`SSE`}];function RE(e,t){return e.conversationId?`/api/admin/logs?type=${t}&conversationId=${encodeURIComponent(e.conversationId)}`:e.sessionKey?`/api/admin/logs?type=${t}&sessionKey=${encodeURIComponent(e.sessionKey)}`:`/api/admin/logs?type=${t}`}function zE(e){let{show:t,onClose:n,conversationsLoading:r,conversationsError:a,conversationsList:o,setConversationsList:s,sessionKey:l,isStreaming:u,resetConversation:d,setMessages:f,setConversationId:p}=e,[m,g]=(0,B.useState)(null),[v,y]=(0,B.useState)(null),[b,x]=(0,B.useState)(``),[S,C]=(0,B.useState)(!1),w=(0,B.useRef)(null),[T,E]=(0,B.useState)(null),[D,O]=(0,B.useState)(null),[k,A]=(0,B.useState)(null),j=(0,B.useRef)(null),M=(0,B.useRef)(null),N=(0,B.useRef)(null);(0,B.useEffect)(()=>{t||(g(null),y(null),x(``),C(!1),E(null),O(null),A(null),j.current&&=(clearTimeout(j.current),null),M.current&&=(clearTimeout(M.current),null))},[t]),(0,B.useEffect)(()=>{if(!T)return;function e(e){let t=e.target;t&&N.current?.contains(t)||t&&t.closest?.(`.conversations-logs`)||E(null)}function t(e){e.key===`Escape`&&E(null)}return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[T]),(0,B.useEffect)(()=>{v?.phase===`editing`&&(w.current?.focus(),w.current?.select())},[v]);function P(){g(null),y(null),x(``),C(!1)}async function ee(e){if(l){P(),g(e),y({phase:`loading`});try{let t=await fetch(`/api/admin/sessions/${encodeURIComponent(e)}/label?session_key=${encodeURIComponent(l)}`,{method:`POST`});if(!t.ok){y({phase:`error`,reason:(await t.json().catch(()=>({}))).error||`Request failed`});return}let n=await t.json();n.label?(y({phase:`editing`}),x(n.label)):y({phase:`error`,reason:`Not enough message content to suggest a name`})}catch(e){console.error(`[admin-modal] label suggestion failed:`,e),y({phase:`error`,reason:e instanceof Error?e.message:String(e)})}}}async function te(e){if(!(!l||!b.trim()||S)){C(!0);try{let t=await fetch(`/api/admin/sessions/${encodeURIComponent(e)}/label`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({label:b.trim(),session_key:l})});if(!t.ok){y({phase:`error`,reason:(await t.json().catch(()=>({}))).error||`Rename failed`}),C(!1);return}s(t=>t.map(t=>t.conversationId===e?{...t,name:b.trim()}:t)),P()}catch(e){console.error(`[admin-modal] label rename failed:`,e),y({phase:`error`,reason:e instanceof Error?e.message:String(e)}),C(!1)}}}function F(e,t,n){if(T?.rowId===e){E(null);return}let r=n.getBoundingClientRect();E({rowId:e,conversationId:t.conversationId,sessionKey:t.sessionKey,top:r.bottom+4,right:Math.max(8,window.innerWidth-r.right)})}async function I(e){await ne(e)?(O(e),A(null),j.current&&clearTimeout(j.current),j.current=setTimeout(()=>O(null),1500)):(A(e),O(null),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>A(null),1500))}return t?(0,V.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,V.jsxs)(`div`,{className:`claude-info-modal conversations-modal`,onClick:e=>e.stopPropagation(),children:[(0,V.jsxs)(`div`,{className:`claude-info-header`,children:[(0,V.jsx)(Xe,{size:12}),`Conversations`,(0,V.jsx)(`button`,{className:`claude-info-close`,onClick:n,children:`✕`})]}),(0,V.jsxs)(`div`,{className:`conversations-list`,children:[r&&(0,V.jsxs)(`div`,{className:`conversations-empty`,children:[(0,V.jsx)(ge,{size:14,className:`spin`}),` Loading…`]}),a&&(0,V.jsx)(`div`,{className:`conversations-empty conversations-error`,children:a}),!r&&!a&&o.length===0&&(0,V.jsx)(`div`,{className:`conversations-empty`,children:`No recent conversations`}),!r&&!a&&o.map(e=>{let t=e.conversationId??e.sessionKey??``,r=e.phase===`pre-flush`,a=!r&&m===e.conversationId,o=a&&v?.phase===`loading`,g=a&&v?.phase===`editing`,y=a&&v?.phase===`error`,C=e.conversationId??e.sessionKey??``;return(0,V.jsxs)(`div`,{className:`conversations-row${r?` conversations-row-pre-flush`:``}`,children:[(0,V.jsxs)(`div`,{className:`conversations-row-info`,children:[o&&(0,V.jsxs)(`span`,{className:`conversations-row-name conversations-edit-loading`,children:[(0,V.jsx)(ge,{size:12,className:`spin`}),` Generating suggestion…`]}),g&&(0,V.jsxs)(`div`,{className:`conversations-edit-inline`,children:[(0,V.jsx)(`input`,{ref:w,type:`text`,className:`conversations-edit-input`,value:b,onChange:e=>x(e.target.value),onKeyDown:t=>{t.key===`Enter`&&b.trim()&&te(e.conversationId),t.key===`Escape`&&P()},maxLength:200}),(0,V.jsx)(`button`,{type:`button`,className:`conversations-action conversations-confirm`,title:`Confirm rename`,disabled:!b.trim()||S,onClick:()=>te(e.conversationId),children:S?(0,V.jsx)(ge,{size:13,className:`spin`}):(0,V.jsx)(h,{size:13})}),(0,V.jsx)(`button`,{type:`button`,className:`conversations-action conversations-cancel`,title:`Cancel`,onClick:P,children:(0,V.jsx)(oe,{size:13})})]}),y&&(0,V.jsxs)(`div`,{className:`conversations-edit-inline`,children:[(0,V.jsx)(`span`,{className:`conversations-edit-error`,children:v.reason}),(0,V.jsx)(`button`,{type:`button`,className:`conversations-action conversations-retry`,title:`Retry`,onClick:()=>ee(e.conversationId),children:(0,V.jsx)(ae,{size:13})}),(0,V.jsx)(`button`,{type:`button`,className:`conversations-action conversations-cancel`,title:`Cancel`,onClick:P,children:(0,V.jsx)(oe,{size:13})})]}),!a&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`span`,{className:`conversations-row-name`,children:[e.name||(r?`session ${C}`:C),r&&(0,V.jsx)(`span`,{className:`conversations-row-phase-badge`,title:`Pre-flush — conversation not yet persisted`,children:`pre-flush`})]}),(0,V.jsxs)(`span`,{className:`conversations-row-meta`,children:[(0,V.jsx)(`button`,{type:`button`,className:`conversations-row-id${D===t?` copied`:``}${k===t?` copy-failed`:``}`,title:C,"aria-label":r?`Copy session key ${C}`:`Copy conversation id ${C}`,onClick:e=>{e.stopPropagation(),I(t)},children:D===t?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(h,{size:10}),` copied`]}):k===t?`copy failed`:C.slice(0,8)}),(0,V.jsxs)(`span`,{className:`conversations-row-time`,children:[(0,V.jsx)(Ae,{size:10}),(()=>{try{let t=new Date(e.updatedAt),n=Date.now()-t.getTime();return n<6e4?`just now`:n<36e5?`${Math.floor(n/6e4)}m ago`:n<864e5?`${Math.floor(n/36e5)}h ago`:`${Math.floor(n/864e5)}d ago`}catch{return``}})()]})]})]})]}),(0,V.jsx)(`div`,{className:`conversations-row-actions`,children:!a&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`button`,{type:`button`,className:`conversations-action conversations-logs`,title:r?`View pre-flush logs`:`View logs`,"aria-haspopup":`menu`,"aria-expanded":T?.rowId===t,onClick:n=>{n.stopPropagation(),F(t,{conversationId:e.conversationId,sessionKey:e.sessionKey},n.currentTarget)},children:(0,V.jsx)(c,{size:13})}),!r&&e.conversationId&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`button`,{type:`button`,className:`conversations-action conversations-rename`,title:`Rename conversation`,onClick:()=>ee(e.conversationId),children:(0,V.jsx)(st,{size:13})}),(0,V.jsx)(`button`,{type:`button`,className:`conversations-action conversations-play`,title:`Resume conversation`,disabled:u,onClick:()=>{u||!l||(n(),d(),fetch(`/api/admin/sessions/${encodeURIComponent(e.conversationId)}/resume?session_key=${encodeURIComponent(l)}`,{method:`POST`}).then(e=>e.ok?e.json():Promise.reject(Error(`Failed to resume conversation`))).then(e=>{e.conversationId&&p(e.conversationId);let t=(e.messages??[]).map(e=>({role:e.role===`user`?`admin`:`maxy`,content:e.role===`user`?e.content:void 0,events:e.role===`assistant`?[{type:`text`,content:e.content}]:void 0,timestamp:new Date(e.createdAt).getTime()||0,historical:!0}));t.length>0&&f(t)}).catch(e=>{console.error(`[chat] conversation resume failed:`,e),f([{role:`maxy`,events:[{type:`text`,content:`Could not load conversation history.`}],timestamp:Date.now()-1,historical:!0}])}))},children:(0,V.jsx)(_,{size:13})}),(0,V.jsx)(`button`,{type:`button`,className:`conversations-action conversations-delete`,title:`Delete conversation`,onClick:()=>{s(t=>t.filter(t=>t.conversationId!==e.conversationId)),l&&fetch(`/api/admin/sessions/${encodeURIComponent(e.conversationId)}?session_key=${encodeURIComponent(l)}`,{method:`DELETE`}).catch(e=>console.error(`[chat] conversation delete failed:`,e))},children:(0,V.jsx)(i,{size:13})})]})]})})]},t)})]}),T&&(0,V.jsx)(`div`,{ref:N,className:`conversations-logs-popover`,role:`menu`,style:{top:T.top,right:T.right},children:LE.map(({type:e,label:t})=>(0,V.jsxs)(`a`,{role:`menuitem`,className:`conversations-logs-popover-item`,href:RE({conversationId:T.conversationId,sessionKey:T.sessionKey},e),target:`_blank`,rel:`noopener noreferrer`,onClick:()=>{console.debug(`[admin-modal] open-log`,{conversationId:T.conversationId,sessionKey:T.sessionKey,type:e}),E(null)},children:[(0,V.jsx)(c,{size:12}),(0,V.jsx)(`span`,{children:t})]},e))})]})}):null}function BE({src:e,onClose:t}){return e?(0,V.jsxs)(`div`,{className:`attachment-lightbox`,onClick:t,children:[(0,V.jsx)(`button`,{className:`attachment-lightbox-close`,onClick:t,"aria-label":`Close`,children:`×`}),(0,V.jsx)(`img`,{src:e,alt:`Attachment`,onClick:e=>e.stopPropagation()})]}):null}function VE({show:e,onClose:t,onConfirm:n}){return e?(0,V.jsx)(`div`,{className:`claude-info-overlay`,onClick:t,children:(0,V.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,V.jsxs)(`div`,{className:`claude-info-header`,children:[(0,V.jsx)(`span`,{children:`Compact conversation?`}),(0,V.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:`✕`})]}),(0,V.jsx)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:`Summarises the conversation history to free up context window space. The session continues with a compressed summary.`}),(0,V.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,V.jsx)(w,{variant:`secondary`,size:`sm`,style:{background:`var(--accent)`,flex:1},onClick:()=>{t(),n()},children:`Yes, compact`}),(0,V.jsx)(w,{variant:`secondary`,size:`sm`,style:{flex:1},onClick:t,children:`No`})]})]})}):null}function HE(e){let{show:t,onClose:n,claudeInfo:r,messages:i,sessionElapsed:a,conversationId:o}=e;if(!t)return null;let s=i.flatMap(e=>e.events?.filter(e=>e.type===`usage`)??[]),c=s.at(-1),l=c?.peak_request_pct==null?c?.context_window?Math.round((c.input_tokens+c.cache_creation_tokens+c.cache_read_tokens)/c.context_window*100):0:Math.round(c.peak_request_pct*100),u=s.reduce((e,t)=>e+t.input_tokens+t.cache_creation_tokens+t.cache_read_tokens+t.output_tokens,0),d=i.flatMap(e=>e.events?.filter(e=>e.type===`rate_limit`)??[]).at(-1),f=s.reduce((e,t)=>e+(t.total_cost_usd??0),0),p=r?.account?.subscriptionType,m=e=>{let t=e*1e3-Date.now();if(t<=0)return`now`;let n=Math.floor(t/36e5),r=Math.floor(t%36e5/6e4);return n>0?`${n}h ${r}m`:`${r}m`};return(0,V.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,V.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,V.jsxs)(`div`,{className:`claude-info-header`,children:[(0,V.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`claude-info-icon`}),(0,V.jsx)(`span`,{children:`Claude Code`}),(0,V.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,V.jsxs)(`div`,{className:`claude-info-section`,children:[(0,V.jsxs)(`div`,{className:`claude-info-row`,children:[(0,V.jsx)(`span`,{className:`claude-info-label`,children:`Version`}),(0,V.jsx)(`span`,{className:`claude-info-value`,children:r?r.version:`…`})]}),(0,V.jsxs)(`div`,{className:`claude-info-row`,children:[(0,V.jsx)(`span`,{className:`claude-info-label`,children:`Email`}),(0,V.jsx)(`span`,{className:`claude-info-value`,children:r?.account?.email??`…`})]})]}),(p||d||f>0)&&(0,V.jsxs)(`div`,{className:`claude-info-section`,children:[p&&(0,V.jsxs)(`div`,{className:`claude-info-row`,children:[(0,V.jsx)(`span`,{className:`claude-info-label`,children:`Plan`}),(0,V.jsx)(`span`,{className:`claude-info-value`,style:{textTransform:`capitalize`},children:p})]}),d&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`claude-info-row`,children:[(0,V.jsx)(`span`,{className:`claude-info-label`,children:`Usage`}),(0,V.jsxs)(`span`,{className:`claude-info-value`,children:[Math.round(d.utilization*100),`%`]})]}),(0,V.jsxs)(`div`,{className:`claude-info-row`,children:[(0,V.jsx)(`span`,{className:`claude-info-label`,children:`Resets in`}),(0,V.jsx)(`span`,{className:`claude-info-value`,children:m(d.resetsAt)})]}),d.isUsingOverage&&(0,V.jsxs)(`div`,{className:`claude-info-row`,children:[(0,V.jsx)(`span`,{className:`claude-info-label`,children:`Overage`}),(0,V.jsx)(`span`,{className:`claude-info-value`,children:`Active`})]})]}),f>0&&(0,V.jsxs)(`div`,{className:`claude-info-row`,children:[(0,V.jsx)(`span`,{className:`claude-info-label`,children:`Session cost`}),(0,V.jsxs)(`span`,{className:`claude-info-value`,children:[`$`,f<.01?f.toFixed(4):f.toFixed(2)]})]})]}),(0,V.jsxs)(`div`,{className:`claude-info-section`,children:[(0,V.jsxs)(`div`,{className:`claude-info-row`,children:[(0,V.jsx)(`span`,{className:`claude-info-label`,children:`Model`}),(0,V.jsx)(`span`,{className:`claude-info-value`,children:r?.model??`…`})]}),(0,V.jsxs)(`div`,{className:`claude-info-row`,children:[(0,V.jsx)(`span`,{className:`claude-info-label`,children:`Context used`}),(0,V.jsx)(`span`,{className:`claude-info-value`,children:l>0?`${l}%`:`—`})]}),(0,V.jsxs)(`div`,{className:`claude-info-row`,children:[(0,V.jsx)(`span`,{className:`claude-info-label`,children:`Tokens`}),(0,V.jsx)(`span`,{className:`claude-info-value`,children:u>0?xt(u):`—`})]}),(0,V.jsxs)(`div`,{className:`claude-info-row`,children:[(0,V.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,V.jsx)(`span`,{className:`claude-info-value`,children:bt(a)})]}),o&&(0,V.jsxs)(`div`,{className:`claude-info-row`,children:[(0,V.jsx)(`span`,{className:`claude-info-label`,children:`Conversation`}),(0,V.jsx)(`span`,{className:`claude-info-value`,style:{fontFamily:`monospace`,fontSize:10},children:o.slice(0,8)})]})]})]})})}var UE=5e3,WE={atPhase:8};function GE({show:e,onClose:t,versionInfo:n,sessionKey:r,onUpgradeComplete:i}){let[a,o]=(0,B.useState)(`prompt`),[s,c]=(0,B.useState)(``),[l,u]=(0,B.useState)(!1),[d,f]=(0,B.useState)(null),[p,m]=(0,B.useState)(null),[h,g]=(0,B.useState)(null),_=(0,B.useRef)(null),v=n?.latest??null,y=(0,B.useCallback)(()=>{_.current&&=(clearInterval(_.current),null)},[]);(0,B.useEffect)(()=>{e||(y(),o(`prompt`),c(``),u(!1),f(null),m(null),g(null))},[e,y]),(0,B.useEffect)(()=>y,[y]),(0,B.useEffect)(()=>{if(!(!e||a!==`running`||!v))return _.current=setInterval(async()=>{try{let e=await fetch(`/api/admin/version`,{cache:`no-store`});if(!e.ok)return;(await e.json()).installed===v&&(y(),o(`succeeded`),i(),setTimeout(()=>window.location.reload(),2e3))}catch{}},UE),y},[e,a,v,i,y]);let b=(0,B.useCallback)(async()=>{if(!(!v||!r||a!==`prompt`)){if(!s){f(`Enter your device password first.`);return}f(null),m(null),o(`priming`);try{let e=await fetch(`/api/admin/actions/sudo-prime?session_key=${encodeURIComponent(r)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({password:s,session_key:r})});if(e.status!==204){f((await e.json().catch(()=>({}))).error??`Password check failed (status ${e.status})`),o(`prompt`);return}}catch(e){f(e instanceof Error?e.message:`Password check network error`),o(`prompt`);return}try{let e=await fetch(`/api/admin/actions/upgrade?session_key=${encodeURIComponent(r)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sudoPassword:s,session_key:r})}),t=await e.json().catch(()=>({}));if(!e.ok||!t.actionId){m(t.error??`launch failed (status ${e.status})`),o(`launch-failed`);return}g(t.actionId),o(`running`)}catch(e){m(e instanceof Error?e.message:`launch network error`),o(`launch-failed`)}finally{c(``)}}},[s,v,r,a]);return e?(0,V.jsx)(`div`,{className:`claude-info-overlay`,onClick:()=>{(a===`prompt`||a===`succeeded`||a===`launch-failed`)&&t()},children:(0,V.jsxs)(`div`,{className:`claude-info-modal update-modal`,onClick:e=>e.stopPropagation(),children:[(0,V.jsxs)(`div`,{className:`claude-info-header`,children:[(0,V.jsx)(L,{size:12}),`Software Update`,(0,V.jsx)(`button`,{className:`claude-info-close`,onClick:t,children:`✕`})]}),(0,V.jsxs)(`div`,{className:`update-modal-body`,children:[(0,V.jsxs)(`div`,{className:`update-modal-versions`,children:[(0,V.jsxs)(`div`,{className:`claude-info-row`,children:[(0,V.jsx)(`span`,{className:`claude-info-label`,children:`Installed`}),(0,V.jsxs)(`span`,{className:`claude-info-value`,children:[`v`,n?.installed??`…`]})]}),(0,V.jsxs)(`div`,{className:`claude-info-row`,children:[(0,V.jsx)(`span`,{className:`claude-info-label`,children:`Available`}),(0,V.jsxs)(`span`,{className:`claude-info-value update-version-new`,children:[`v`,v??`…`]})]})]}),(a===`prompt`||a===`priming`||a===`launch-failed`)&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`form-input__field`,style:{marginTop:12},children:[(0,V.jsx)(`label`,{className:`form-input__label`,htmlFor:`upgrade-sudo`,children:`Device password`}),(0,V.jsxs)(`div`,{className:`tunnel-route__row`,children:[(0,V.jsx)(`input`,{id:`upgrade-sudo`,className:`form-input__input tunnel-route__input`,type:l?`text`:`password`,autoComplete:`current-password`,value:s,onChange:e=>{c(e.target.value),f(null)},disabled:a===`priming`,onKeyDown:e=>{e.key===`Enter`&&s&&b()}}),(0,V.jsx)(`button`,{type:`button`,className:`tunnel-route__suffix`,onClick:()=>u(e=>!e),disabled:a===`priming`,style:{cursor:`pointer`,border:`none`,background:`inherit`},"aria-label":l?`Hide password`:`Show password`,children:l?`Hide`:`Show`})]}),(0,V.jsx)(`div`,{className:`form-input__field-desc`,children:`Needed once. The installer uses it to run the privileged steps; it is never saved.`}),d&&(0,V.jsx)(`div`,{className:`tunnel-route__error`,children:d}),p&&(0,V.jsx)(`div`,{className:`tunnel-route__error`,role:`alert`,children:p})]}),(0,V.jsx)(`button`,{type:`button`,className:`update-modal-btn`,onClick:b,disabled:!v||!s||a===`priming`,children:a===`priming`?`Checking password…`:a===`launch-failed`?`Try again`:`Upgrade`})]}),a===`running`&&h&&r&&(0,V.jsx)(`div`,{className:`update-modal-terminal`,style:{height:360,marginTop:10},children:(0,V.jsx)(sE,{actionId:h,sessionKey:r,selfRestart:WE})}),a===`succeeded`&&(0,V.jsxs)(`div`,{className:`update-modal-result`,children:[(0,V.jsx)(De,{size:14,className:`update-success-icon`}),(0,V.jsxs)(`span`,{children:[`Upgraded to v`,v,` — reloading…`]})]})]})]})}):null}function KE(e){let{conversationId:t,sessionKey:n,disconnecting:r,onOpenConversations:i,handleDisconnect:a,onAfterAction:o}=e,s=!t&&!n;return(0,V.jsxs)(`div`,{className:`chat-actions-menu`,children:[(0,V.jsxs)(`button`,{type:`button`,className:`chat-action`,onClick:()=>{o(),i()},children:[(0,V.jsx)(Xe,{size:14}),(0,V.jsx)(`span`,{className:`action-label`,children:`Conversations`})]}),(0,V.jsxs)(`button`,{type:`button`,className:`chat-action`,disabled:r,onClick:async()=>{o(),await a()},children:[r?(0,V.jsx)(ge,{size:14,className:`animate-spin`}):(0,V.jsx)(Se,{size:14}),(0,V.jsx)(`span`,{className:`action-label`,children:r?`Disconnecting...`:`Disconnect Claude`})]}),(0,V.jsxs)(`button`,{type:`button`,className:`chat-action`,disabled:s,title:t?`Download stream log`:n?`Download stream log (pre-flush)`:`No session active — reload the page to start one`,onClick:()=>{if(o(),s){console.debug(`[stream-log-button] no-identity sessionKey=null conversationId=null`);return}let e=document.createElement(`a`);e.href=`${RE({conversationId:t,sessionKey:n},`stream`)}&download=1`,e.click()},children:[(0,V.jsx)(lt,{size:14}),(0,V.jsx)(`span`,{className:`action-label`,children:`Stream log`})]})]})}function qE(e){let{selectionMode:t,selectedItems:n,copyToast:r,exitSelection:i,enterSelection:a,copySelected:o,showCopyToast:s,input:l,setInput:p,inputRef:h,pendingFiles:g,setPendingFiles:v,isDragOver:y,attachError:b,fileInputRef:x,addFiles:S,removeFile:C,onDragOver:D,onDragLeave:O,onDrop:k,isStreaming:j,wasPaused:M,messages:P,messageQueueRef:te,setQueue:F,sendMessage:re,stopStreaming:ie,disconnecting:ae,handleDisconnect:oe,claudeInfo:se,setClaudeInfo:L,setShowClaudeInfo:ce,conversationId:le,sessionKey:ue,onNewConversation:de,newConversationDisabled:fe,onOpenConversations:pe,sidebarVisible:me}=e,[he,ge]=(0,B.useState)(!1),_e=(0,B.useRef)(null),[ve,ye]=(0,B.useState)(!1),be=(0,B.useRef)(null),xe=(0,B.useRef)(!1),Se=ee(),Ce=Se.state===`recording`||Se.state===`paused`||Se.state===`sending`,we=!Ce&&!M&&!l.trim()&&g.length===0;async function Te(){let e=await Se.send();if(!e)return;let t=e.type===`audio/ogg`?`.ogg`:e.type===`audio/mp4`?`.m4a`:`.webm`,n=new File([e],`voice-note${t}`,{type:e.type});if(j){F([...te.current,{text:`[Voice note]`,files:[n],timestamp:Date.now()}]);return}re(`[Voice note]`,[n])}return(0,B.useEffect)(()=>{t||ye(!1)},[t]),(0,B.useEffect)(()=>{if(!ve)return;let e=e=>{e.target.closest(`.selection-copy-wrap`)||ye(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[ve]),(0,B.useEffect)(()=>{if(!he)return;let e=e=>{if(e.key===`Escape`){ge(!1);return}if(e.key===`Tab`&&_e.current){let t=_e.current.querySelectorAll(`.actions-menu-items button:not([disabled])`);if(t.length===0)return;let n=t[0],r=t[t.length-1];e.shiftKey&&document.activeElement===n?(e.preventDefault(),r.focus()):!e.shiftKey&&document.activeElement===r&&(e.preventDefault(),n.focus())}},t=e=>{_e.current&&!_e.current.contains(e.target)&&ge(!1)};return document.addEventListener(`keydown`,e),document.addEventListener(`mousedown`,t),()=>{document.removeEventListener(`keydown`,e),document.removeEventListener(`mousedown`,t)}},[he]),t?(0,V.jsx)(`div`,{className:`chat-input-area`,children:(0,V.jsxs)(`div`,{className:`selection-bar`,children:[(0,V.jsxs)(`span`,{className:`selection-count`,children:[n.size,` Selected`]}),(0,V.jsxs)(`div`,{className:`selection-copy-wrap`,children:[(0,V.jsxs)(`button`,{type:`button`,className:`selection-copy`,onPointerDown:()=>{if(ve){ye(!1);return}xe.current=!1,be.current=setTimeout(()=>{xe.current=!0,ye(!0),be.current=null},500)},onPointerUp:()=>{be.current!==null&&(clearTimeout(be.current),be.current=null)},onPointerLeave:()=>{be.current!==null&&(clearTimeout(be.current),be.current=null)},onPointerCancel:()=>{be.current!==null&&(clearTimeout(be.current),be.current=null)},onClick:async()=>{xe.current||await o(e=>FE(P,e),(e,t)=>{let[n,r]=[e.slice(0,e.lastIndexOf(`_`)),e.slice(e.lastIndexOf(`_`)+1)],[i,a]=[t.slice(0,t.lastIndexOf(`_`)),t.slice(t.lastIndexOf(`_`)+1)],o=parseInt(n,10)-parseInt(i,10);return o===0?r===`admin`?-1:a===`admin`?1:parseInt(r,10)-parseInt(a,10):o})},children:[(0,V.jsx)(f,{size:18}),(0,V.jsx)(`span`,{children:`Copy`})]}),ve&&(0,V.jsx)(`div`,{className:`copy-menu`,children:[[`all`,`All events`],[`text`,`Text messages only`],[`non-text`,`Non-text only`]].map(([e,t])=>(0,V.jsx)(`button`,{type:`button`,className:`copy-menu-item`,onClick:async()=>{let t=IE(P,e);t&&s(await ne(t)),i()},children:t},e))})]}),(0,V.jsx)(`button`,{type:`button`,className:`selection-cancel`,onClick:i,children:`Cancel`})]})}):(0,V.jsxs)(`div`,{className:`chat-input-area`,children:[(0,V.jsx)(`input`,{ref:x,type:`file`,multiple:!0,accept:Ct,style:{display:`none`},onChange:e=>{e.target.files&&S([...e.target.files]),e.target.value=``}}),g.length>0&&(0,V.jsx)(`div`,{className:`attachment-strip`,children:g.map((e,t)=>(0,V.jsxs)(`div`,{className:`attachment-chip`,children:[e.type.startsWith(`image/`)?(0,V.jsx)(`img`,{src:URL.createObjectURL(e),alt:e.name,className:`attachment-chip-thumb`}):e.type===`application/pdf`?(0,V.jsx)(c,{size:14}):(0,V.jsx)(E,{size:14}),(0,V.jsx)(`span`,{className:`attachment-chip-name`,children:e.name}),(0,V.jsx)(`button`,{type:`button`,className:`attachment-chip-remove`,onClick:()=>C(t),"aria-label":`Remove ${e.name}`,children:`×`})]},t))}),b&&(0,V.jsx)(`p`,{className:`attach-error`,children:b}),Se.state===`error`&&Se.errorMessage&&(0,V.jsxs)(`p`,{className:`voice-error`,role:`alert`,children:[(0,V.jsx)(m,{size:14}),Se.errorMessage]}),(0,V.jsx)(T,{inputRef:h}),Ce?(0,V.jsx)(`div`,{className:`chat-form voice-active`,children:(0,V.jsx)(A,{state:Se.state,elapsedSeconds:Se.elapsedSeconds,waveform:Se.waveform,onTogglePause:Se.togglePause,onDiscard:Se.discard,onSend:Te})}):(0,V.jsxs)(`form`,{className:`chat-form${y?` drag-over`:``}`,onSubmit:e=>{e.preventDefault();let t=l.trim()||(M?`continue`:``);if(!(!t&&g.length===0)){if(j){F([...te.current,{text:t,files:[...g],timestamp:Date.now()}]),p(``),v([]),h.current?.resetHeight();return}re(t),h.current?.resetHeight()}},onDragOver:D,onDragLeave:O,onDrop:k,onPaste:e=>{let t=e.clipboardData?.items;if(!t)return;let n=[];for(let e of t){if(e.kind!==`file`)continue;let t=e.getAsFile();if(!t)continue;let r=t.type.split(`/`)[1]?.replace(`jpeg`,`jpg`)||`png`;n.push(new File([t],`pasted-image-${Date.now()}.${r}`,{type:t.type}))}n.length>0&&S(n)},children:[(0,V.jsx)(w,{variant:`icon`,type:`button`,onClick:()=>x.current?.click(),"aria-label":`Attach file`,children:(0,V.jsx)(u,{size:14})}),(0,V.jsx)(N,{ref:h,value:l,onChange:p}),j?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(w,{variant:`send`,type:`button`,onClick:()=>ie(!0),"aria-label":`Pause`,style:{background:`var(--text-secondary)`},children:(0,V.jsx)(d,{size:14})}),(0,V.jsx)(w,{variant:`send`,type:`button`,onClick:()=>ie(!1),"aria-label":`Stop`,style:{background:`var(--danger)`},children:(0,V.jsx)(ft,{size:14})})]}):we?(0,V.jsx)(w,{variant:`send`,type:`button`,onClick:Se.start,"aria-label":`Record voice note`,children:(0,V.jsx)(m,{size:14})}):(0,V.jsx)(w,{variant:`send`,type:`submit`,disabled:!l.trim()&&g.length===0&&!M,"aria-label":`Send message`,children:M?(0,V.jsx)(_,{size:14}):(0,V.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,V.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,V.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,V.jsxs)(`div`,{className:`chat-actions`,ref:_e,children:[(0,V.jsx)(`button`,{type:`button`,className:`chat-action-icon`,title:`New conversation`,"aria-label":`New conversation`,disabled:fe,onClick:de,children:(0,V.jsx)(Ve,{size:16})}),(0,V.jsx)(`button`,{type:`button`,className:`chat-action-icon`,title:`Select messages`,"aria-label":`Select messages`,onClick:a,children:(0,V.jsx)(I,{size:16})}),!me&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`button`,{className:`burger-trigger`,onClick:()=>ge(e=>!e),"aria-expanded":he,"aria-haspopup":`true`,"aria-label":`Conversation actions`,children:(0,V.jsx)(Pe,{size:16})}),(0,V.jsx)(`div`,{className:`actions-menu-items${he?` actions-menu-open`:``}`,children:(0,V.jsx)(KE,{conversationId:le,sessionKey:ue,disconnecting:ae,onOpenConversations:pe,handleDisconnect:oe,onAfterAction:()=>ge(!1)})})]}),(0,V.jsxs)(`div`,{className:`powered-by`,onClick:async()=>{if(ce(!0),!se){let e=await fetch(`/api/admin/claude-info`);e.ok&&L(await e.json())}},children:[(0,V.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`powered-by-icon`}),(0,V.jsx)(`span`,{children:`Powered by Claude Code`})]})]})]})}var JE=`maxy-vnc-overlay-popout`;function YE(e){let[t,n]=(0,B.useState)(!1),r=(0,B.useRef)(null),i=(0,B.useRef)(null),a=(0,B.useCallback)(()=>{i.current&&=(clearInterval(i.current),null),r.current&&!r.current.closed&&r.current.close(),r.current=null,n(!1)},[]),o=(0,B.useCallback)(()=>{let t=`/vnc-popout.html?title=${encodeURIComponent(C.productName)}`,o=window.open(t,JE,`width=1024,height=768`);o&&(r.current=o,n(!0),i.current=setInterval(()=>{r.current?.closed&&(a(),e?.())},500))},[a,e]);return(0,B.useEffect)(()=>()=>a(),[a]),{poppedOut:t,popout:o,cleanupPopout:a}}var XE=(0,B.forwardRef)(function({onClose:e},t){yt();let{poppedOut:n,popout:r,cleanupPopout:i}=YE(e);return(0,B.useImperativeHandle)(t,()=>({popout:r}),[r]),n?(0,V.jsxs)(`div`,{className:`browser-overlay-popout`,children:[(0,V.jsx)(D,{className:`browser-viewer__icon`}),(0,V.jsx)(`span`,{className:`browser-viewer__title`,children:C.productName}),(0,V.jsx)(`span`,{className:`browser-viewer__popout-label`,children:`Popped out`}),(0,V.jsx)(w,{variant:`ghost`,size:`sm`,icon:nt,onClick:()=>i(),"aria-label":`Pop back in`}),e&&(0,V.jsx)(w,{variant:`ghost`,size:`sm`,icon:oe,onClick:()=>{i(),e()},"aria-label":`Close`})]}):(0,V.jsx)(`iframe`,{src:`/vnc-viewer.html`,className:`browser-surface__iframe`,title:C.productName})});function ZE({onClose:e}){yt();let{poppedOut:t,popout:n,cleanupPopout:r}=YE(e),i=(0,B.useCallback)(()=>{r(),e()},[r,e]);(0,B.useEffect)(()=>{if(t)return;let e=e=>{e.key===`Escape`&&i()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,i]);let a=Zt({handlePopout:n,disabled:t});return t?(0,V.jsxs)(`div`,{className:`browser-overlay-popout`,children:[(0,V.jsx)(D,{className:`browser-viewer__icon`}),(0,V.jsx)(`span`,{className:`browser-viewer__title`,children:C.productName}),(0,V.jsx)(`span`,{className:`browser-viewer__popout-label`,children:`Popped out`}),(0,V.jsx)(w,{variant:`ghost`,size:`sm`,icon:nt,onClick:()=>{r()},"aria-label":`Pop back in`}),(0,V.jsx)(w,{variant:`ghost`,size:`sm`,icon:oe,onClick:i,"aria-label":`Close`})]}):(0,V.jsxs)(`div`,{className:`browser-viewer-fullscreen`,children:[(0,V.jsxs)(`div`,{className:`browser-viewer-fullscreen__bar`,...a,children:[(0,V.jsx)(D,{className:`browser-viewer__icon`}),(0,V.jsx)(`span`,{className:`browser-viewer-fullscreen__title`,children:C.productName}),(0,V.jsxs)(`div`,{className:`browser-viewer-fullscreen__actions`,children:[(0,V.jsx)(w,{variant:`ghost`,size:`sm`,icon:Fe,onClick:n,"aria-label":`Pop out`}),(0,V.jsx)(w,{variant:`ghost`,size:`sm`,icon:oe,onClick:i,"aria-label":`Close`})]})]}),(0,V.jsx)(`iframe`,{src:`/vnc-viewer.html`,className:`browser-viewer-fullscreen__iframe`,title:C.productName})]})}var QE=(0,B.forwardRef)(function(e,t){let{businessName:n,sessionKey:r,conversationId:i,role:a,userName:o,userAvatar:s,sessions:l,sessionsLoading:u,sessionsError:d,ensureSessionsLoaded:f,refetchSessions:p,onSelectSession:m,onSelectArtefact:h,onSelectProjects:g,onSelectPeople:_,onSelectTasks:v,onSelectAgents:y,onCloseMobileDrawer:b,collapsed:x,onToggleCollapsed:S,actions:w}=e;(0,B.useEffect)(()=>{f()},[f]);let T=C.productName,E=typeof o==`string`?o:o===null?`name unavailable`:n||T,D=(E.trim().charAt(0)||`?`).toUpperCase(),O=(0,B.useMemo)(()=>l.filter(e=>e.name),[l]),k=O.length,A=i??r,[j,M]=(0,B.useState)(`chat`),[N,P]=(0,B.useState)([]),[ee,te]=(0,B.useState)(!1),[F,I]=(0,B.useState)(null),[ne,re]=(0,B.useState)(!1);(0,B.useImperativeHandle)(t,()=>({patchArtefact(e,t){P(n=>n.map(n=>n.id===e?{...n,...t}:n))}}),[]);let[ae,oe]=(0,B.useState)(!1),se=(0,B.useRef)(null);(0,B.useEffect)(()=>{if(!ae)return;function e(e){se.current&&!se.current.contains(e.target)&&oe(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[ae]);let L=(0,B.useCallback)(async()=>{if(r){re(!0),I(null);try{let e=await fetch(`/api/admin/sidebar-artefacts?session_key=${encodeURIComponent(r)}`);if(!e.ok)throw Error(`status ${e.status}`);P((await e.json()).artefacts??[]),te(!0)}catch(e){let t=e instanceof Error?e.message:String(e);I(`Failed to load artefacts: ${t}`),console.error(`[admin-ui] sidebar-artefacts fetch failed: ${t}`)}finally{re(!1)}}},[r]),ce=()=>{M(`chat`),console.info(`[admin-ui] sidebar-nav surface=chat count=${k}`)},le=()=>{M(`artefacts`),console.info(`[admin-ui] sidebar-nav surface=artefacts count=${ee?N.length:0}`),ee||L()},ue=x?24:16,de=j===`chat`?`Recents`:`Artefacts`,fe=j===`chat`?u?`…`:String(k):ne?`…`:String(N.length),pe=j===`chat`?u:ne,me=()=>{j===`chat`?p():L(),console.info(`[admin-ui] sidebar-refresh surface=${j}`)};return(0,V.jsxs)(`aside`,{className:`side`,children:[(0,V.jsx)(`div`,{className:`side-head`,children:(0,V.jsx)(`button`,{className:`icon-btn side-head-toggle`,title:x?`Expand sidebar`:`Collapse sidebar`,type:`button`,"aria-label":x?`Expand sidebar`:`Collapse sidebar`,onClick:S,children:x?(0,V.jsx)(ot,{size:28}):(0,V.jsx)(at,{size:28})})}),(0,V.jsxs)(`nav`,{className:`side-nav`,children:[(0,V.jsxs)(`button`,{type:`button`,className:`nav-row${j===`chat`?` active`:``}`,onClick:ce,children:[(0,V.jsx)(tt,{size:ue}),(0,V.jsx)(`span`,{className:`label`,children:`Chat`}),(0,V.jsx)(`span`,{className:`kbd`})]}),(0,V.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=people`),_(),b()},children:[(0,V.jsx)(gt,{size:ue}),(0,V.jsx)(`span`,{className:`label`,children:`People`}),(0,V.jsx)(`span`,{className:`kbd`})]}),(0,V.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=agents`),y(),b()},children:[(0,V.jsx)(Ce,{size:ue}),(0,V.jsx)(`span`,{className:`label`,children:`Agents`}),(0,V.jsx)(`span`,{className:`kbd`})]}),(0,V.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=projects`),g(),b()},children:[(0,V.jsx)(we,{size:ue}),(0,V.jsx)(`span`,{className:`label`,children:`Projects`}),(0,V.jsx)(`span`,{className:`kbd`})]}),(0,V.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=tasks`),v(),b()},children:[(0,V.jsx)(Ye,{size:ue}),(0,V.jsx)(`span`,{className:`label`,children:`Tasks`}),(0,V.jsx)(`span`,{className:`kbd`})]}),(0,V.jsxs)(`button`,{type:`button`,className:`nav-row${j===`artefacts`?` active`:``}`,onClick:le,children:[(0,V.jsx)(c,{size:ue}),(0,V.jsx)(`span`,{className:`label`,children:`Artefacts`}),(0,V.jsx)(`span`,{className:`kbd`})]})]}),(0,V.jsxs)(`div`,{className:`side-list`,children:[(0,V.jsxs)(`div`,{className:`group-head`,children:[(0,V.jsx)(`span`,{children:de}),(0,V.jsxs)(`span`,{className:`group-head-meta`,children:[(0,V.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh ${de.toLowerCase()}`,"aria-label":`Refresh ${de.toLowerCase()}`,onClick:me,disabled:pe,children:(0,V.jsx)(ie,{size:12,className:pe?`spinning`:void 0})}),(0,V.jsx)(`span`,{children:fe})]})]}),j===`chat`&&(0,V.jsxs)(V.Fragment,{children:[d&&(0,V.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:d}),O.map(e=>{let t=e.conversationId??e.sessionKey;return(0,V.jsx)(`button`,{type:`button`,className:`conv${t!==null&&t===A?` active`:``}`,onClick:()=>{let t=e.sessionKey?e.sessionKey.slice(0,8):`null`,n=e.conversationId?e.conversationId.slice(0,8):`null`;console.info(`[admin-session-identity] sessionKey=${t} conversationId=${n} phase=${e.phase} surface=sidebar-recents`),m(e),b()},children:(0,V.jsx)(`span`,{className:`conv-name`,children:e.name??`(untitled)`})},t??e.updatedAt)})]}),j===`artefacts`&&(0,V.jsxs)(V.Fragment,{children:[F&&(0,V.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:F}),ee&&!F&&N.length===0&&(0,V.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No artefacts yet`}),N.map(e=>(0,V.jsxs)(`button`,{type:`button`,className:`conv`,onClick:()=>{h({docId:e.id,name:e.name,content:e.content,editable:e.editable,mimeType:e.mimeType,skipReason:e.skipReason},`sidebar-artefacts`),b()},children:[(0,V.jsx)(`span`,{className:`conv-name`,children:e.name}),(0,V.jsx)(`span`,{className:`conv-kind`,"data-kind":e.kind===`agent-template`?`agent`:`doc`,children:e.kind===`agent-template`?`agent`:`doc`})]},e.id))]})]}),(0,V.jsxs)(`div`,{className:`side-foot`,ref:se,children:[(0,V.jsx)(`div`,{className:`avatar`,children:s?(0,V.jsx)(`img`,{src:s,alt:E}):D}),(0,V.jsxs)(`div`,{className:`who`,children:[(0,V.jsx)(`span`,{className:`name`,children:E}),(0,V.jsx)(`span`,{className:`role`,children:a??`operator`})]}),(0,V.jsx)(`button`,{className:`icon-btn side-foot-actions-trigger`,title:`Conversation actions`,type:`button`,"aria-label":`Conversation actions`,"aria-haspopup":`true`,"aria-expanded":ae,onClick:()=>oe(e=>!e),children:(0,V.jsx)(Pe,{size:ue})}),ae&&(0,V.jsx)(`div`,{className:`side-foot-actions-popover`,children:(0,V.jsx)(KE,{...w,onAfterAction:()=>oe(!1)})})]})]})}),$E=()=>{},eD={"null-attachmentId":`No file backing this artefact.`,"non-text-mime":`Content type cannot be displayed inline.`,"containment-rejected":`File path failed containment check; cannot display.`,"missing-on-disk":`File is missing on disk.`};function tD({reason:e}){return(0,V.jsxs)(`div`,{className:`art-skip-banner`,role:`status`,children:[(0,V.jsx)(Re,{size:14}),(0,V.jsx)(`span`,{children:eD[e]})]})}function nD({src:e,name:t,docId:n}){let[r,i]=(0,B.useState)(!1),a=(0,B.useRef)(null),o=(0,B.useRef)(!1),s=(0,B.useRef)(!1),l=(0,B.useCallback)(e=>{s.current||(s.current=!0,console.info(`[admin-ui] artefact-pdf-fallback id=${n.slice(0,8)} reason=${e}`),i(!0))},[n]);(0,B.useEffect)(()=>{let e=setTimeout(()=>{o.current||l(`onload-timeout`)},3e3);return()=>clearTimeout(e)},[l]);let u=()=>{o.current=!0;try{let e=a.current?.contentDocument?.body;e&&e.children.length===0&&!e.textContent?.trim()&&l(`empty-body`)}catch{}};return r?(0,V.jsxs)(`a`,{className:`art-pdf-fallback`,href:e,download:t,children:[(0,V.jsx)(c,{size:20}),(0,V.jsxs)(`div`,{className:`art-pdf-fallback-text`,children:[(0,V.jsx)(`div`,{className:`art-pdf-fallback-name`,children:t}),(0,V.jsx)(`div`,{className:`art-pdf-fallback-hint`,children:`Your browser can't display this PDF inline. Click to download.`})]}),(0,V.jsx)(L,{size:16})]}):(0,V.jsx)(`iframe`,{ref:a,className:`art-pdf`,src:e,title:t,"aria-label":`PDF preview of ${t}`,onLoad:u,onError:()=>l(`onerror`)})}var rD={browser:`Browser`,data:`Data`,graph:`Graph`};function iD({selection:e,trigger:t,sessionKey:n,onClose:r,onArtefactSaved:i}){let a=e!==null,o=e?.surface??null,s=(0,B.useRef)(null),c=(0,B.useRef)(null),[l,u]=(0,B.useState)(null),d=e?.surface===`doc`?e.docId:null,p=(0,B.useCallback)(e=>{if(!n||!d)return;let t={};try{t=JSON.parse(e)}catch{return}t.action!==`save`||typeof t.content!=`string`||(u(null),fetch(`/api/admin/sidebar-artefact-save?session_key=${encodeURIComponent(n)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({id:d,content:t.content})}).then(async e=>{if(!e.ok){let t=(await e.json().catch(()=>({}))).error??`status ${e.status}`;u(`Save failed: ${t}`),console.error(`[admin-ui] artefact-save-failed docId=${d} status=${e.status} error="${t}"`);return}let n=await e.json();i?.(d,n.updatedAt,t.content)}).catch(e=>{let t=e instanceof Error?e.message:String(e);u(`Save failed: ${t}`),console.error(`[admin-ui] artefact-save-failed docId=${d} error="${t}"`)}))},[n,d,i]);(0,B.useEffect)(()=>{u(null)},[d]),(0,B.useEffect)(()=>{let n=e?.surface===`doc`?e.docId:null,r=e?.surface===`graph`?e.focusNodeId??null:null,i=e?.surface??null,o=i===null?`closed`:`${i}:${n??`none`}:${r??`none`}`;if(o===s.current)return;let c=a?`open`:`closed`,l=a?t??`chat-link`:`toolbar-close`,u=i??s.current?.split(`:`)[0]??`doc`;console.info(`[admin-ui] artefact-pane state=${c} docId=${n??`none`} trigger=${l} surface=${u}`),s.current=o},[e,t,a]);let m=e?.surface===`doc`,h=m?(e.tag||e.name.split(`.`).pop()||`doc`).toUpperCase().slice(0,6):``,g=m?e.revision||`rev 1`:`live`,_=e&&e.surface!==`doc`?rD[e.surface]:``,v=m?e.name:_;return(0,V.jsxs)(`aside`,{className:`artefact`,"data-open":a,"data-surface":o??`none`,children:[(0,V.jsxs)(`div`,{className:`art-head`,children:[(0,V.jsxs)(`div`,{className:`left`,children:[!m&&o===`browser`&&(0,V.jsx)(D,{size:14,className:`art-head-surface-icon`}),!m&&o===`data`&&(0,V.jsx)(fe,{size:14,className:`art-head-surface-icon`}),!m&&o===`graph`&&(0,V.jsx)(he,{size:14,className:`art-head-surface-icon`}),(0,V.jsx)(`span`,{className:`file-name`,children:v}),m&&(0,V.jsx)(`span`,{className:`file-tag`,children:h})]}),(0,V.jsxs)(`div`,{className:`right`,children:[m&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`button`,{className:`icon-btn`,title:`Copy`,type:`button`,"aria-label":`Copy`,onClick:()=>{ne(e.content)},children:(0,V.jsx)(f,{size:14})}),(0,V.jsx)(`button`,{className:`icon-btn`,title:`Refresh`,type:`button`,"aria-label":`Refresh`,children:(0,V.jsx)(ae,{size:14})})]}),o===`browser`&&(0,V.jsx)(`button`,{className:`icon-btn`,title:`Pop out`,type:`button`,"aria-label":`Pop out`,onClick:()=>c.current?.popout(),children:(0,V.jsx)(Fe,{size:14})}),a&&(0,V.jsx)(`button`,{className:`icon-btn`,title:`Close`,type:`button`,"aria-label":`Close`,onClick:r,children:(0,V.jsx)(oe,{size:14})})]})]}),(0,V.jsxs)(`div`,{className:`art-toolbar`,children:[(0,V.jsxs)(`span`,{className:`seg`,children:[(0,V.jsx)(`span`,{className:`bullet`}),(0,V.jsx)(`strong`,{children:m?`Artefact`:_})]}),(0,V.jsx)(`span`,{className:`right-meta`,children:g})]}),(0,V.jsxs)(`div`,{className:`art-body`,"data-surface":o??`none`,children:[m&&(()=>{let t=e.editable!==!1,r=e.skipReason??null,i=(e.mimeType??``).startsWith(`application/pdf`);if(r)return(0,V.jsx)(tD,{reason:r});if(i&&n){let t=`/api/admin/sidebar-artefact-content?id=${encodeURIComponent(e.docId)}&session_key=${encodeURIComponent(n)}`;return(0,V.jsx)(nD,{src:t,name:e.name,docId:e.docId},t)}return(0,V.jsxs)(V.Fragment,{children:[l&&(0,V.jsx)(`div`,{className:`art-save-error`,role:`alert`,children:l}),(0,V.jsx)(Jw,{data:{title:e.name,content:e.content,readOnly:!t},onSubmit:t?p:$E,submitted:!1})]})})(),o===`browser`&&(0,V.jsx)(XE,{ref:c,onClose:r}),o===`data`&&n&&(0,V.jsx)(ce,{sessionKey:n}),e?.surface===`graph`&&n&&(0,V.jsx)(se,{sessionKey:n,initialFocus:e.focusNodeId?{nodeId:e.focusNodeId,nodeLabel:e.focusNodeLabel??null}:null,initialLabels:e.initialLabels??null})]}),(0,V.jsxs)(`div`,{className:`art-foot`,children:[(0,V.jsx)(`span`,{className:`left`,children:g}),(0,V.jsx)(`span`,{className:`right in-sync`,children:`in sync`})]})]})}var aD=`maxy-shell-artefact-px`;function oD(){if(typeof window>`u`)return 320;let e=window.innerWidth,t=document.querySelector(`.platform > .side`)?.getBoundingClientRect(),n=t?t.right:Math.round(e*.3);return cD(Math.round((e-n)*(2/3)))}function sD(){if(typeof window>`u`)return 320;try{let e=window.localStorage.getItem(aD);if(!e)return oD();let t=parseInt(e,10);if(Number.isFinite(t)&&t>=320)return t}catch{}return oD()}function cD(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=document.querySelector(`.platform > .side`)?.getBoundingClientRect(),r=n?n.right:Math.round(t*.3),i=Math.max(320,t-r-480);return Math.min(Math.max(e,320),i)}function lD({targetSelector:e=`.platform`}){let t=(0,B.useRef)(null),[n,r]=(0,B.useState)(()=>sD()),i=(0,B.useRef)(n);(0,B.useEffect)(()=>{let t=document.querySelector(e);!t||!(t instanceof HTMLElement)||(t.style.setProperty(`--artefact-px`,`${n}px`),i.current=n)},[n,e]);let a=(0,B.useCallback)(()=>{r(e=>{let t=cD(e);return t===e?e:t})},[]);(0,B.useEffect)(()=>(a(),window.addEventListener(`resize`,a),()=>window.removeEventListener(`resize`,a)),[a]);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(cD(Math.round(window.innerWidth-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(aD,String(t))}catch{}console.info(`[admin-ui] artefact-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=oD();r(e);try{window.localStorage.removeItem(aD)}catch{}console.info(`[admin-ui] artefact-resize px=${e}`)};return(0,V.jsx)(`div`,{ref:t,className:`art-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize artefact pane`,onPointerDown:o,onDoubleClick:s})}var uD=`maxy-shell-side-px`;function dD(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .artefact`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function fD(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=Math.max(220,t-480-dD());return Math.min(Math.max(e,220),n)}function pD(){if(typeof window>`u`)return 264;try{let e=window.localStorage.getItem(uD);if(!e)return 264;let t=parseInt(e,10);if(Number.isFinite(t)&&t>=220)return fD(t)}catch{}return 264}function mD({targetSelector:e=`.platform`}){let t=(0,B.useRef)(null),[n,r]=(0,B.useState)(()=>pD()),i=(0,B.useRef)(n);(0,B.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,B.useCallback)(()=>{r(e=>{let t=fD(e);return t===e?e:t})},[]);(0,B.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(fD(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(uD,String(t))}catch{}console.info(`[admin-ui] sidebar-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=fD(264);r(e);try{window.localStorage.removeItem(uD)}catch{}console.info(`[admin-ui] sidebar-resize px=${e}`)};return(0,V.jsx)(`div`,{ref:t,className:`side-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize sidebar`,onPointerDown:o,onDoubleClick:s})}function hD(e){let[t,n]=(0,B.useState)([]),[r,i]=(0,B.useState)(!1),[a,o]=(0,B.useState)(null),[s,c]=(0,B.useState)(null),l=(0,B.useCallback)(async t=>{if(e&&!(!t&&s===e)){i(!0),o(null);try{let t=await fetch(`/api/admin/sessions?session_key=${encodeURIComponent(e)}`);if(!t.ok)throw Error(`sessions fetch returned ${t.status}`);n((await t.json()).sessions??[]),c(e)}catch(e){console.error(`[admin/sessions] fetch failed:`,e),o(e instanceof Error?e.message:String(e))}finally{i(!1)}}},[e,s]);(0,B.useEffect)(()=>{e||(c(null),n([]),o(null))},[e]);let u=(0,B.useCallback)(()=>l(!1),[l]),d=(0,B.useCallback)(()=>l(!0),[l]);return{sessions:t,setSessions:n,loading:r,loaded:s!==null&&s===e,error:a,ensureLoaded:u,refetch:d}}function gD(){yt();let e=(0,B.useRef)(null),[t,n]=(0,B.useState)(null),[r,a]=(0,B.useState)(!1),[o,s]=(0,B.useState)(!1),[c,l]=(0,B.useState)(``),[u,d]=(0,B.useState)(!1),[f,p]=(0,B.useState)(null),[m,_]=(0,B.useState)(!1),[v,y]=(0,B.useState)(null),[b,x]=(0,B.useState)(null),[w,T]=(0,B.useState)(!1),[E,O]=(0,B.useState)(null),[k,A]=(0,B.useState)(!1),[j,M]=(0,B.useState)(null),[N,P]=(0,B.useState)(!1),[ee,te]=(0,B.useState)(!1),[I,re]=(0,B.useState)(!1),[ie,ae]=(0,B.useState)(!1),[se,L]=(0,B.useState)(null),[ce,le]=(0,B.useState)(null),de=(0,B.useRef)(null),[pe,_e]=(0,B.useState)(()=>typeof window<`u`&&window.matchMedia(`(min-width: 641px)`).matches);(0,B.useEffect)(()=>{let e=window.matchMedia(`(min-width: 641px)`),t=e=>_e(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let[ve,ye]=(0,B.useState)(()=>typeof window<`u`&&window.matchMedia(`(min-width: 1080px)`).matches);(0,B.useEffect)(()=>{let e=window.matchMedia(`(min-width: 1080px)`),t=e=>ye(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let be=(0,B.useRef)(!1),xe=(0,B.useRef)(!1),Se=(0,B.useRef)(!1),Ce=(0,B.useRef)(!1),we=(0,B.useRef)(null),[Te,Ee]=(0,B.useState)(null),De=g(),Oe=St(),R=Ot(),ke=Rt(),Ae=hD(R.sessionKey),z=Lt({sessionKey:R.sessionKey,setSessionKey:R.setSessionKey,setAppState:R.setAppState,setConversationId:R.setConversationId,startElapsedTimer:Oe.startElapsedTimer,stopElapsedTimer:Oe.stopElapsedTimer,resetTimerState:Oe.resetTimerState,pausedElapsedRef:Oe.pausedElapsedRef,expandAllDefaultRef:R.expandAllDefaultRef,setExpandAll:R.setExpandAll,getPendingFiles:()=>ke.pendingFiles,clearPendingFiles:ke.clearFiles,inputRef:e});(0,B.useEffect)(()=>{l(window.location.hostname.startsWith(`admin.`)?window.location.origin.replace(`admin.`,`public.`):window.location.origin)},[]),(0,B.useEffect)(()=>{function e(e){e.key===`Escape`&&(t?n(null):De.selectionMode&&De.exitSelection())}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,De.selectionMode]),(0,B.useEffect)(()=>{(R.appState===`set-pin`||R.appState===`enter-pin`)&&setTimeout(()=>R.pinInputRef.current?.focus(),100),R.appState===`chat`&&setTimeout(()=>e.current?.focus(),100)},[R.appState,z.greetingGeneration]),(0,B.useEffect)(()=>{if(R.appState!==`chat`)return;history.pushState({maxyChat:!0},``);function e(){console.debug(`[history-guard] popstate absorbed`),history.pushState({maxyChat:!0},``)}return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[R.appState]);let je=(0,B.useRef)(z.greetingGeneration);if((0,B.useEffect)(()=>{z.greetingGeneration!==je.current&&(je.current=z.greetingGeneration,R.onboardingComplete===!1&&(be.current=!1))},[z.greetingGeneration,R.onboardingComplete]),(0,B.useEffect)(()=>{R.appState===`chat`&&R.onboardingComplete===!1&&(be.current||(be.current=!0,z.sendSystemPrompt(`[Begin onboarding.]`)))},[R.appState,R.onboardingComplete,z.greetingGeneration]),(0,B.useEffect)(()=>{if(!u)return;let e=!1;return fetch(`/api/admin/version`).then(e=>e.json()).then(t=>{e||O(t)}).catch(e=>{console.error(`[admin/version] menu-open client fetch failed:`,e)}),()=>{e=!0}},[u]),(0,B.useEffect)(()=>{if(R.appState!==`chat`){Se.current=!1,Ce.current=!1;return}if(Se.current)return;Se.current=!0;let e=!1;return fetch(`/api/admin/version`).then(e=>e.json()).then(t=>{e||(O(t),!(!t.updateAvailable||Ce.current)&&(M(t),A(!0),fetch(`/api/admin/version/alert-surfaced`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({installed:t.installed,latest:t.latest})}).catch(e=>{console.error(`[admin/version] alert-surfaced signal failed:`,e)})))}).catch(e=>{console.error(`[admin/version] session-start client fetch failed:`,e)}),()=>{e=!0}},[R.appState]),(0,B.useEffect)(()=>{if(R.appState!==`chat`||!R.sessionKey)return;let e=R.conversationId?`flushed`:`pre-flush`,t=R.sessionKey.slice(0,8),n=R.conversationId?R.conversationId.slice(0,8):`null`;console.info(`[admin-session-identity] sessionKey=${t} conversationId=${n} phase=${e} surface=chat-header`)},[R.appState,R.sessionKey,R.conversationId]),(0,B.useEffect)(()=>{if(R.appState!==`chat`){xe.current=!1;return}if(xe.current||!Ae.loaded)return;xe.current=!0;let e=Ae.sessions.filter(e=>e.name).length,t=se?`open`:`closed`;console.info(`[admin-ui] platform-shell brand=${C.productName} sidebar=${e} artefact=${t}`)},[R.appState,Ae.loaded,Ae.sessions,se]),(0,B.useEffect)(()=>{if(!u){p(null),y(null),x(null),O(null);return}function e(e){we.current&&!we.current.contains(e.target)&&d(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[u]),(0,B.useEffect)(()=>{if(typeof BroadcastChannel>`u`)return;let e=new BroadcastChannel(`platform-onboarding`);return e.onmessage=e=>{e.data?.type===`remote-password-set`&&z.sendMessageRef.current(`I've set the remote password`)},()=>e.close()},[]),R.appState===`loading`)return(0,V.jsx)(`div`,{className:`chat-page admin-page`,children:(0,V.jsx)(`header`,{className:`chat-header`,children:(0,V.jsx)(`img`,{src:F,alt:C.productName,className:`chat-logo`})})});if(R.appState===`set-pin`)return(0,V.jsx)(Bt,{pin:R.pin,setPin:R.setPin,confirmPin:R.confirmPin,setConfirmPin:R.setConfirmPin,operatorName:R.operatorName,setOperatorName:R.setOperatorName,showPin:R.showPin,setShowPin:R.setShowPin,pinLoading:R.pinLoading,pinError:R.pinError,pinInputRef:R.pinInputRef,confirmPinInputRef:R.confirmPinInputRef,setPinFormRef:R.setPinFormRef,onSubmit:R.handleSetPin});if(R.appState===`onboarding-choice`)return(0,V.jsx)(Wt,{setAppState:R.setAppState,setOnboardingComplete:R.setOnboardingComplete});if(R.appState===`connect-claude`)return(0,V.jsx)(Ut,{authPolling:R.authPolling,setAuthPolling:R.setAuthPolling,authLoading:R.authLoading,setAuthLoading:R.setAuthLoading,pinError:R.pinError,setPinError:R.setPinError,setAppState:R.setAppState});if(R.appState===`enter-pin`)return(0,V.jsx)(Vt,{pin:R.pin,setPin:R.setPin,showPin:R.showPin,setShowPin:R.setShowPin,pinLoading:R.pinLoading,pinError:R.pinError,pinInputRef:R.pinInputRef,onSubmit:R.handleLogin,onChangePin:R.handleChangePin});if(R.appState===`account-picker`)return(0,V.jsx)(Ht,{accounts:R.accounts,loading:R.accountPickerLoading,error:R.pinError,onSelect:R.handleAccountSelect});let Me=se?`open`:`closed`,Ne=ie&&pe,Pe=`platform${I?` menu-open`:``}${Ne?` sidebar-collapsed`:``}`,Ie=e=>{if(!z.isStreaming&&R.sessionKey){if(!e.conversationId){z.resetConversation(),z.setMessages([]),R.setConversationId(null);return}z.resetConversation(),z.setMessages([]),fetch(`/api/admin/sessions/${encodeURIComponent(e.conversationId)}/resume?session_key=${encodeURIComponent(R.sessionKey)}`,{method:`POST`}).then(e=>e.ok?e.json():Promise.reject(Error(`resume returned ${e.status}`))).then(e=>{e.conversationId&&R.setConversationId(e.conversationId);let t=(e.messages??[]).map(e=>({role:e.role===`user`?`admin`:`maxy`,content:e.role===`user`?e.content:void 0,events:e.role===`assistant`?e.events??[]:void 0,timestamp:new Date(e.createdAt).getTime()||0,historical:!0}));t.length>0&&z.setMessages(t);let n=[];for(let t of e.messages??[]){if(t.role!==`assistant`||!t.submittedEventIndices?.length)continue;let e=new Date(t.createdAt).getTime()||0;for(let r of t.submittedEventIndices)n.push(`${e}_${r}`)}n.length>0&&z.seedSubmittedComponents(n)}).catch(e=>{console.error(`[chat] sidebar conversation resume failed:`,e),z.setMessages([{role:`maxy`,events:[{type:`text`,content:`Could not load conversation history.`}],timestamp:Date.now()-1,historical:!0}])})}},Le={conversationId:R.conversationId,sessionKey:R.sessionKey,disconnecting:R.disconnecting,onOpenConversations:()=>{T(!0),Ae.refetch()},handleDisconnect:R.handleDisconnect};return(0,V.jsx)(S,{value:{onShowVnc:()=>P(!0)},children:(0,V.jsxs)(`div`,{className:Pe,"data-artefact":Me,children:[(0,V.jsx)(`div`,{className:`scrim`,onClick:()=>{re(!1),console.info(`[admin-ui] mobile-drawer state=closed`)}}),(0,V.jsx)(QE,{ref:de,businessName:R.businessName??null,sessionKey:R.sessionKey,conversationId:R.conversationId,role:R.role,userName:R.userName,userAvatar:R.userAvatar,sessions:Ae.sessions,sessionsLoading:Ae.loading,sessionsError:Ae.error,ensureSessionsLoaded:Ae.ensureLoaded,refetchSessions:Ae.refetch,onSelectSession:Ie,onSelectArtefact:(e,t)=>{L({surface:`doc`,...e}),le(t)},onSelectProjects:()=>{L({surface:`graph`,initialLabels:[`Project`]}),le(`sidebar-projects`)},onSelectPeople:()=>{L({surface:`graph`,initialLabels:[`Person`]}),le(`sidebar-people`)},onSelectTasks:()=>{L({surface:`graph`,initialLabels:[`Task`]}),le(`sidebar-tasks`)},onSelectAgents:()=>{L({surface:`graph`,initialLabels:[`Agent`]}),le(`sidebar-agents`)},onCloseMobileDrawer:()=>{I&&(re(!1),console.info(`[admin-ui] mobile-drawer state=closed`))},collapsed:Ne,onToggleCollapsed:()=>ae(e=>!e),actions:Le}),(0,V.jsxs)(`div`,{className:`chat-page admin-page`,children:[(0,V.jsxs)(`header`,{className:`chat-header`,children:[(0,V.jsx)(`button`,{type:`button`,className:`icon-btn mobile-menu`,"aria-label":`Show sidebar`,title:`Show sidebar`,onClick:()=>{re(e=>{let t=!e;return console.info(`[admin-ui] mobile-drawer state=${t?`open`:`closed`}`),t})},children:(0,V.jsx)(ot,{size:16})}),(0,V.jsx)(`img`,{src:F,alt:C.productName,className:`chat-logo`}),(!C.logoContainsName||R.businessName)&&(0,V.jsx)(`div`,{children:(0,V.jsx)(`h1`,{className:`chat-tagline`,children:R.businessName||C.productName})}),(R.sessionKey||R.conversationId)&&(0,V.jsxs)(`button`,{type:`button`,className:`chat-session-chip chat-session-chip-${R.conversationId?`flushed`:`pre-flush`}`+(Te===`copied`?` copied`:``)+(Te===`failed`?` copy-failed`:``),title:R.conversationId?`conversation ${R.conversationId} — click to copy`:`session ${R.sessionKey} (pre-flush, first turn pending) — click to copy`,onClick:async()=>{let e=R.conversationId??R.sessionKey;e&&(Ee(await ne(e)?`copied`:`failed`),setTimeout(()=>Ee(null),1200))},children:[(0,V.jsx)(`span`,{className:`chat-session-chip-label`,children:Te===`copied`?`copied`:Te===`failed`?`copy failed`:R.conversationId?`conversation`:`session`}),(0,V.jsx)(`span`,{className:`chat-session-chip-id`,children:Te===`copied`?`✓`:Te===`failed`?`✕`:`${(R.conversationId??R.sessionKey??``).slice(0,8)}…`})]}),(0,V.jsxs)(`div`,{className:`chat-burger-wrap`,ref:we,children:[(0,V.jsx)(`button`,{type:`button`,className:`chat-burger`,onClick:()=>d(e=>!e),"aria-label":`Menu`,"aria-haspopup":`true`,"aria-expanded":u,children:(0,V.jsx)(ue,{size:20})}),u&&(0,V.jsxs)(`div`,{className:`chat-menu`,children:[(0,V.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:async()=>{if(!ee&&!(!ve&&N)){te(!0),d(!1);try{let e=await(await fetch(`/api/admin/browser/launch`,{method:`POST`})).json().catch(()=>({ok:!1,error:`Invalid response`}));if(!e.ok)throw Error(e.error??`Failed to launch browser`);ve?(L({surface:`browser`}),le(`header-menu`)):P(!0)}catch(e){console.error(`[browser] Launch failed:`,e),alert(e instanceof Error?e.message:`Failed to launch browser`)}finally{te(!1)}}},disabled:ee,children:[(0,V.jsx)(D,{size:14}),` Browser`,ee&&(0,V.jsx)(ge,{size:12,className:`spin`})]}),(0,V.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{d(!1),ve?(L({surface:`data`}),le(`header-menu`)):window.location.href=`/data`},children:[(0,V.jsx)(fe,{size:14}),` Data`]}),(0,V.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{d(!1),ve?(L({surface:`graph`}),le(`header-menu`)):window.location.href=`/graph`},children:[(0,V.jsx)(he,{size:14}),` Graph`]}),(0,V.jsx)(`div`,{className:`chat-menu-divider`}),(0,V.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:async()=>{if(f!==null){p(null),x(null);return}_(!0),y(null);try{let e=await fetch(`/api/admin/agents`);if(!e.ok)throw Error(`Failed to load agents`);p((await e.json()).agents??[])}catch(e){console.error(`[admin] agent list failed:`,e),y(e instanceof Error?e.message:String(e))}finally{_(!1)}},children:[(0,V.jsx)(Fe,{size:14}),` Public`,m&&(0,V.jsx)(ge,{size:12,className:`spin`})]}),f!==null&&(0,V.jsxs)(`div`,{className:`chat-menu-agents`,children:[v&&(0,V.jsx)(`span`,{className:`chat-menu-agent-error`,children:v}),f.length===0&&!v&&(0,V.jsx)(`span`,{className:`chat-menu-agent-empty`,children:`No public agents configured`}),f.map(e=>(0,V.jsxs)(`div`,{className:`chat-menu-item chat-menu-agent-item`,children:[(0,V.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),(0,V.jsxs)(`span`,{className:`agent-text`,children:[(0,V.jsx)(`span`,{className:`agent-display-name`,children:e.displayName}),(0,V.jsxs)(`span`,{className:`agent-slug`,children:[`/`,e.slug]})]}),b===e.slug?(0,V.jsxs)(`span`,{className:`agent-actions agent-confirm`,children:[(0,V.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-yes`,title:`Confirm delete`,onClick:()=>{x(null),p(t=>t?.filter(t=>t.slug!==e.slug)??null),fetch(`/api/admin/agents/${encodeURIComponent(e.slug)}`,{method:`DELETE`}).catch(e=>console.error(`[admin/agents] delete failed:`,e))},children:(0,V.jsx)(h,{size:12})}),(0,V.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-no`,title:`Cancel`,onClick:()=>x(null),children:(0,V.jsx)(oe,{size:12})})]}):(0,V.jsxs)(`span`,{className:`agent-actions`,children:[(0,V.jsx)(`a`,{href:`${c}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`agent-action-btn`,title:`Open agent`,onClick:()=>d(!1),children:(0,V.jsx)(Fe,{size:12})}),(0,V.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-delete-btn`,title:`Delete agent`,onClick:()=>x(e.slug),children:(0,V.jsx)(i,{size:12})})]})]},e.slug))]}),(0,V.jsx)(`div`,{className:`chat-menu-divider`}),E?.updateAvailable?(0,V.jsxs)(`button`,{type:`button`,className:`chat-menu-version`,onClick:()=>{E.latest&&(M(E),d(!1),A(!0))},children:[(0,V.jsx)(We,{size:14}),(0,V.jsxs)(`span`,{className:`version-installed`,children:[`v`,E.installed,(0,V.jsx)(`span`,{className:`version-update-dot`})]})]}):(0,V.jsxs)(`div`,{className:`chat-menu-version chat-menu-version-passive`,children:[(0,V.jsx)(We,{size:14}),(0,V.jsxs)(`span`,{className:`version-installed`,children:[E?`v${E.installed}`:`…`,E&&!E.updateAvailable&&(0,V.jsx)(`span`,{className:`version-uptodate-dot`})]})]}),(0,V.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{d(!1),R.handleLogout(),z.setMessages([])},children:[(0,V.jsx)(me,{size:14}),` Log out`]})]})]})]}),(0,V.jsxs)(`div`,{className:`chat-content`,children:[(0,V.jsx)(NE,{messages:z.messages,isStreaming:z.isStreaming,elapsedSeconds:Oe.elapsedSeconds,sessionTurnStart:Oe.sessionTurnStart,expandAll:R.expandAll,setExpandAll:R.setExpandAll,conversationCompacted:z.conversationCompacted,isCompacting:z.isCompacting,setShowCompactConfirm:s,handleComponentSubmit:z.handleComponentSubmit,effectiveSubmitted:z.effectiveSubmitted,selectionMode:De.selectionMode,selectedItems:De.selectedItems,toggleSelectItem:De.toggleSelectItem,sessionKey:R.sessionKey,setLightboxSrc:n,messageQueue:z.messageQueue,messageQueueRef:z.messageQueueRef,setQueue:z.setQueue,sendMessage:z.sendMessage,appState:R.appState,onboardingComplete:R.onboardingComplete,onOpenArtefact:e=>{L({surface:`doc`,...e}),le(`chat-link`)}}),(0,V.jsx)(PE,{offer:z.topicChangeOffer,onFreshStart:z.handleTopicFreshStart,onContinue:z.handleTopicContinue,disabled:z.isStreaming}),(0,V.jsx)(qE,{selectionMode:De.selectionMode,selectedItems:De.selectedItems,copyToast:De.copyToast||null,exitSelection:De.exitSelection,enterSelection:De.enterSelection,copySelected:De.copySelected,showCopyToast:De.showCopyToast,input:z.input,setInput:z.setInput,inputRef:e,pendingFiles:ke.pendingFiles,setPendingFiles:ke.setPendingFiles,isDragOver:ke.isDragOver,attachError:ke.attachError,fileInputRef:ke.fileInputRef,addFiles:ke.addFiles,removeFile:ke.removeFile,onDragOver:ke.onDragOver,onDragLeave:ke.onDragLeave,onDrop:ke.onDrop,isStreaming:z.isStreaming,wasPaused:z.wasPaused,messages:z.messages,messageQueueRef:z.messageQueueRef,setQueue:z.setQueue,sendMessage:z.sendMessage,stopStreaming:z.stopStreaming,disconnecting:R.disconnecting,handleDisconnect:R.handleDisconnect,claudeInfo:R.claudeInfo,setClaudeInfo:R.setClaudeInfo,setShowClaudeInfo:a,conversationId:R.conversationId,sessionKey:R.sessionKey,onNewConversation:z.startNewConversation,newConversationDisabled:z.isStreaming||z.isCompacting,onOpenConversations:()=>{T(!0),Ae.refetch()},sidebarVisible:pe})]}),De.copyToast&&(0,V.jsx)(`span`,{className:`copy-toast${De.copyToast===`failed`?` copy-toast-failed`:``}`,children:De.copyToast===`copied`?`Copied`:`Copy failed`}),(0,V.jsx)(zE,{show:w,onClose:()=>T(!1),conversationsLoading:Ae.loading,conversationsError:Ae.error,conversationsList:Ae.sessions,setConversationsList:Ae.setSessions,sessionKey:R.sessionKey,isStreaming:z.isStreaming,resetConversation:z.resetConversation,setMessages:z.setMessages,setConversationId:R.setConversationId}),(0,V.jsx)(BE,{src:t,onClose:()=>n(null)}),(0,V.jsx)(VE,{show:o,onClose:()=>s(!1),onConfirm:z.handleCompactNow}),(0,V.jsx)(HE,{show:r,onClose:()=>{a(!1),R.setClaudeInfo(null)},claudeInfo:R.claudeInfo,messages:z.messages,sessionElapsed:Oe.sessionElapsed,conversationId:R.conversationId}),(0,V.jsx)(GE,{show:k,onClose:()=>{A(!1),Ce.current=!0},versionInfo:j,sessionKey:R.sessionKey,onUpgradeComplete:()=>O(null)}),N&&(0,V.jsx)(ZE,{onClose:()=>P(!1)})]}),(0,V.jsx)(mD,{}),(0,V.jsx)(lD,{}),(0,V.jsx)(iD,{selection:se,trigger:ce,sessionKey:R.sessionKey,onClose:()=>{L(null),le(null)},onArtefactSaved:(e,t,n)=>{de.current?.patchArtefact(e,{updatedAt:t,content:n})}})]})})}(0,ve.createRoot)(document.getElementById(`root`)).render((0,V.jsx)(gD,{}));
|
|
352
|
+
`)}var LE=[{type:`stream`,label:`Stream`},{type:`error`,label:`Errors`},{type:`sse`,label:`SSE`}];function RE(e,t){return e.conversationId?`/api/admin/logs?type=${t}&conversationId=${encodeURIComponent(e.conversationId)}`:e.sessionKey?`/api/admin/logs?type=${t}&sessionKey=${encodeURIComponent(e.sessionKey)}`:`/api/admin/logs?type=${t}`}function zE(e){let{show:t,onClose:n,conversationsLoading:r,conversationsError:a,conversationsList:o,setConversationsList:s,sessionKey:l,isStreaming:u,resetConversation:d,setMessages:f,setConversationId:p}=e,[m,g]=(0,B.useState)(null),[v,y]=(0,B.useState)(null),[b,x]=(0,B.useState)(``),[S,C]=(0,B.useState)(!1),w=(0,B.useRef)(null),[T,E]=(0,B.useState)(null),[D,O]=(0,B.useState)(null),[k,A]=(0,B.useState)(null),j=(0,B.useRef)(null),M=(0,B.useRef)(null),N=(0,B.useRef)(null);(0,B.useEffect)(()=>{t||(g(null),y(null),x(``),C(!1),E(null),O(null),A(null),j.current&&=(clearTimeout(j.current),null),M.current&&=(clearTimeout(M.current),null))},[t]),(0,B.useEffect)(()=>{if(!T)return;function e(e){let t=e.target;t&&N.current?.contains(t)||t&&t.closest?.(`.conversations-logs`)||E(null)}function t(e){e.key===`Escape`&&E(null)}return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[T]),(0,B.useEffect)(()=>{v?.phase===`editing`&&(w.current?.focus(),w.current?.select())},[v]);function P(){g(null),y(null),x(``),C(!1)}async function ee(e){if(l){P(),g(e),y({phase:`loading`});try{let t=await fetch(`/api/admin/sessions/${encodeURIComponent(e)}/label?session_key=${encodeURIComponent(l)}`,{method:`POST`});if(!t.ok){y({phase:`error`,reason:(await t.json().catch(()=>({}))).error||`Request failed`});return}let n=await t.json();n.label?(y({phase:`editing`}),x(n.label)):y({phase:`error`,reason:`Not enough message content to suggest a name`})}catch(e){console.error(`[admin-modal] label suggestion failed:`,e),y({phase:`error`,reason:e instanceof Error?e.message:String(e)})}}}async function te(e){if(!(!l||!b.trim()||S)){C(!0);try{let t=await fetch(`/api/admin/sessions/${encodeURIComponent(e)}/label`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({label:b.trim(),session_key:l})});if(!t.ok){y({phase:`error`,reason:(await t.json().catch(()=>({}))).error||`Rename failed`}),C(!1);return}s(t=>t.map(t=>t.conversationId===e?{...t,name:b.trim()}:t)),P()}catch(e){console.error(`[admin-modal] label rename failed:`,e),y({phase:`error`,reason:e instanceof Error?e.message:String(e)}),C(!1)}}}function F(e,t,n){if(T?.rowId===e){E(null);return}let r=n.getBoundingClientRect();E({rowId:e,conversationId:t.conversationId,sessionKey:t.sessionKey,top:r.bottom+4,right:Math.max(8,window.innerWidth-r.right)})}async function I(e){await ne(e)?(O(e),A(null),j.current&&clearTimeout(j.current),j.current=setTimeout(()=>O(null),1500)):(A(e),O(null),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>A(null),1500))}return t?(0,V.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,V.jsxs)(`div`,{className:`claude-info-modal conversations-modal`,onClick:e=>e.stopPropagation(),children:[(0,V.jsxs)(`div`,{className:`claude-info-header`,children:[(0,V.jsx)(Xe,{size:12}),`Conversations`,(0,V.jsx)(`button`,{className:`claude-info-close`,onClick:n,children:`✕`})]}),(0,V.jsxs)(`div`,{className:`conversations-list`,children:[r&&(0,V.jsxs)(`div`,{className:`conversations-empty`,children:[(0,V.jsx)(ge,{size:14,className:`spin`}),` Loading…`]}),a&&(0,V.jsx)(`div`,{className:`conversations-empty conversations-error`,children:a}),!r&&!a&&o.length===0&&(0,V.jsx)(`div`,{className:`conversations-empty`,children:`No recent conversations`}),!r&&!a&&o.map(e=>{let t=e.conversationId??e.sessionKey??``,r=e.phase===`pre-flush`,a=!r&&m===e.conversationId,o=a&&v?.phase===`loading`,g=a&&v?.phase===`editing`,y=a&&v?.phase===`error`,C=e.conversationId??e.sessionKey??``;return(0,V.jsxs)(`div`,{className:`conversations-row${r?` conversations-row-pre-flush`:``}`,children:[(0,V.jsxs)(`div`,{className:`conversations-row-info`,children:[o&&(0,V.jsxs)(`span`,{className:`conversations-row-name conversations-edit-loading`,children:[(0,V.jsx)(ge,{size:12,className:`spin`}),` Generating suggestion…`]}),g&&(0,V.jsxs)(`div`,{className:`conversations-edit-inline`,children:[(0,V.jsx)(`input`,{ref:w,type:`text`,className:`conversations-edit-input`,value:b,onChange:e=>x(e.target.value),onKeyDown:t=>{t.key===`Enter`&&b.trim()&&te(e.conversationId),t.key===`Escape`&&P()},maxLength:200}),(0,V.jsx)(`button`,{type:`button`,className:`conversations-action conversations-confirm`,title:`Confirm rename`,disabled:!b.trim()||S,onClick:()=>te(e.conversationId),children:S?(0,V.jsx)(ge,{size:13,className:`spin`}):(0,V.jsx)(h,{size:13})}),(0,V.jsx)(`button`,{type:`button`,className:`conversations-action conversations-cancel`,title:`Cancel`,onClick:P,children:(0,V.jsx)(oe,{size:13})})]}),y&&(0,V.jsxs)(`div`,{className:`conversations-edit-inline`,children:[(0,V.jsx)(`span`,{className:`conversations-edit-error`,children:v.reason}),(0,V.jsx)(`button`,{type:`button`,className:`conversations-action conversations-retry`,title:`Retry`,onClick:()=>ee(e.conversationId),children:(0,V.jsx)(ae,{size:13})}),(0,V.jsx)(`button`,{type:`button`,className:`conversations-action conversations-cancel`,title:`Cancel`,onClick:P,children:(0,V.jsx)(oe,{size:13})})]}),!a&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`span`,{className:`conversations-row-name`,children:[e.name||(r?`session ${C}`:C),r&&(0,V.jsx)(`span`,{className:`conversations-row-phase-badge`,title:`Pre-flush — conversation not yet persisted`,children:`pre-flush`})]}),(0,V.jsxs)(`span`,{className:`conversations-row-meta`,children:[(0,V.jsx)(`button`,{type:`button`,className:`conversations-row-id${D===t?` copied`:``}${k===t?` copy-failed`:``}`,title:C,"aria-label":r?`Copy session key ${C}`:`Copy conversation id ${C}`,onClick:e=>{e.stopPropagation(),I(t)},children:D===t?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(h,{size:10}),` copied`]}):k===t?`copy failed`:C.slice(0,8)}),(0,V.jsxs)(`span`,{className:`conversations-row-time`,children:[(0,V.jsx)(Ae,{size:10}),(()=>{try{let t=new Date(e.updatedAt),n=Date.now()-t.getTime();return n<6e4?`just now`:n<36e5?`${Math.floor(n/6e4)}m ago`:n<864e5?`${Math.floor(n/36e5)}h ago`:`${Math.floor(n/864e5)}d ago`}catch{return``}})()]})]})]})]}),(0,V.jsx)(`div`,{className:`conversations-row-actions`,children:!a&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`button`,{type:`button`,className:`conversations-action conversations-logs`,title:r?`View pre-flush logs`:`View logs`,"aria-haspopup":`menu`,"aria-expanded":T?.rowId===t,onClick:n=>{n.stopPropagation(),F(t,{conversationId:e.conversationId,sessionKey:e.sessionKey},n.currentTarget)},children:(0,V.jsx)(c,{size:13})}),!r&&e.conversationId&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`button`,{type:`button`,className:`conversations-action conversations-rename`,title:`Rename conversation`,onClick:()=>ee(e.conversationId),children:(0,V.jsx)(st,{size:13})}),(0,V.jsx)(`button`,{type:`button`,className:`conversations-action conversations-play`,title:`Resume conversation`,disabled:u,onClick:()=>{u||!l||(n(),d(),fetch(`/api/admin/sessions/${encodeURIComponent(e.conversationId)}/resume?session_key=${encodeURIComponent(l)}`,{method:`POST`}).then(e=>e.ok?e.json():Promise.reject(Error(`Failed to resume conversation`))).then(e=>{e.conversationId&&p(e.conversationId);let t=(e.messages??[]).map(e=>({role:e.role===`user`?`admin`:`maxy`,content:e.role===`user`?e.content:void 0,events:e.role===`assistant`?[{type:`text`,content:e.content}]:void 0,timestamp:new Date(e.createdAt).getTime()||0,historical:!0}));t.length>0&&f(t)}).catch(e=>{console.error(`[chat] conversation resume failed:`,e),f([{role:`maxy`,events:[{type:`text`,content:`Could not load conversation history.`}],timestamp:Date.now()-1,historical:!0}])}))},children:(0,V.jsx)(_,{size:13})}),(0,V.jsx)(`button`,{type:`button`,className:`conversations-action conversations-delete`,title:`Delete conversation`,onClick:()=>{s(t=>t.filter(t=>t.conversationId!==e.conversationId)),l&&fetch(`/api/admin/sessions/${encodeURIComponent(e.conversationId)}?session_key=${encodeURIComponent(l)}`,{method:`DELETE`}).catch(e=>console.error(`[chat] conversation delete failed:`,e))},children:(0,V.jsx)(i,{size:13})})]})]})})]},t)})]}),T&&(0,V.jsx)(`div`,{ref:N,className:`conversations-logs-popover`,role:`menu`,style:{top:T.top,right:T.right},children:LE.map(({type:e,label:t})=>(0,V.jsxs)(`a`,{role:`menuitem`,className:`conversations-logs-popover-item`,href:RE({conversationId:T.conversationId,sessionKey:T.sessionKey},e),target:`_blank`,rel:`noopener noreferrer`,onClick:()=>{console.debug(`[admin-modal] open-log`,{conversationId:T.conversationId,sessionKey:T.sessionKey,type:e}),E(null)},children:[(0,V.jsx)(c,{size:12}),(0,V.jsx)(`span`,{children:t})]},e))})]})}):null}function BE({src:e,onClose:t}){return e?(0,V.jsxs)(`div`,{className:`attachment-lightbox`,onClick:t,children:[(0,V.jsx)(`button`,{className:`attachment-lightbox-close`,onClick:t,"aria-label":`Close`,children:`×`}),(0,V.jsx)(`img`,{src:e,alt:`Attachment`,onClick:e=>e.stopPropagation()})]}):null}function VE({show:e,onClose:t,onConfirm:n}){return e?(0,V.jsx)(`div`,{className:`claude-info-overlay`,onClick:t,children:(0,V.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,V.jsxs)(`div`,{className:`claude-info-header`,children:[(0,V.jsx)(`span`,{children:`Compact conversation?`}),(0,V.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:`✕`})]}),(0,V.jsx)(`div`,{className:`claude-info-section`,style:{padding:`12px 14px`,fontSize:`11px`,color:`var(--text-secondary)`},children:`Summarises the conversation history to free up context window space. The session continues with a compressed summary.`}),(0,V.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,V.jsx)(w,{variant:`secondary`,size:`sm`,style:{background:`var(--accent)`,flex:1},onClick:()=>{t(),n()},children:`Yes, compact`}),(0,V.jsx)(w,{variant:`secondary`,size:`sm`,style:{flex:1},onClick:t,children:`No`})]})]})}):null}function HE(e){let{show:t,onClose:n,claudeInfo:r,messages:i,sessionElapsed:a,conversationId:o}=e;if(!t)return null;let s=i.flatMap(e=>e.events?.filter(e=>e.type===`usage`)??[]),c=s.at(-1),l=c?.peak_request_pct==null?c?.context_window?Math.round((c.input_tokens+c.cache_creation_tokens+c.cache_read_tokens)/c.context_window*100):0:Math.round(c.peak_request_pct*100),u=s.reduce((e,t)=>e+t.input_tokens+t.cache_creation_tokens+t.cache_read_tokens+t.output_tokens,0),d=i.flatMap(e=>e.events?.filter(e=>e.type===`rate_limit`)??[]).at(-1),f=s.reduce((e,t)=>e+(t.total_cost_usd??0),0),p=r?.account?.subscriptionType,m=e=>{let t=e*1e3-Date.now();if(t<=0)return`now`;let n=Math.floor(t/36e5),r=Math.floor(t%36e5/6e4);return n>0?`${n}h ${r}m`:`${r}m`};return(0,V.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,V.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,V.jsxs)(`div`,{className:`claude-info-header`,children:[(0,V.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`claude-info-icon`}),(0,V.jsx)(`span`,{children:`Claude Code`}),(0,V.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,V.jsxs)(`div`,{className:`claude-info-section`,children:[(0,V.jsxs)(`div`,{className:`claude-info-row`,children:[(0,V.jsx)(`span`,{className:`claude-info-label`,children:`Version`}),(0,V.jsx)(`span`,{className:`claude-info-value`,children:r?r.version:`…`})]}),(0,V.jsxs)(`div`,{className:`claude-info-row`,children:[(0,V.jsx)(`span`,{className:`claude-info-label`,children:`Email`}),(0,V.jsx)(`span`,{className:`claude-info-value`,children:r?.account?.email??`…`})]})]}),(p||d||f>0)&&(0,V.jsxs)(`div`,{className:`claude-info-section`,children:[p&&(0,V.jsxs)(`div`,{className:`claude-info-row`,children:[(0,V.jsx)(`span`,{className:`claude-info-label`,children:`Plan`}),(0,V.jsx)(`span`,{className:`claude-info-value`,style:{textTransform:`capitalize`},children:p})]}),d&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`claude-info-row`,children:[(0,V.jsx)(`span`,{className:`claude-info-label`,children:`Usage`}),(0,V.jsxs)(`span`,{className:`claude-info-value`,children:[Math.round(d.utilization*100),`%`]})]}),(0,V.jsxs)(`div`,{className:`claude-info-row`,children:[(0,V.jsx)(`span`,{className:`claude-info-label`,children:`Resets in`}),(0,V.jsx)(`span`,{className:`claude-info-value`,children:m(d.resetsAt)})]}),d.isUsingOverage&&(0,V.jsxs)(`div`,{className:`claude-info-row`,children:[(0,V.jsx)(`span`,{className:`claude-info-label`,children:`Overage`}),(0,V.jsx)(`span`,{className:`claude-info-value`,children:`Active`})]})]}),f>0&&(0,V.jsxs)(`div`,{className:`claude-info-row`,children:[(0,V.jsx)(`span`,{className:`claude-info-label`,children:`Session cost`}),(0,V.jsxs)(`span`,{className:`claude-info-value`,children:[`$`,f<.01?f.toFixed(4):f.toFixed(2)]})]})]}),(0,V.jsxs)(`div`,{className:`claude-info-section`,children:[(0,V.jsxs)(`div`,{className:`claude-info-row`,children:[(0,V.jsx)(`span`,{className:`claude-info-label`,children:`Model`}),(0,V.jsx)(`span`,{className:`claude-info-value`,children:r?.model??`…`})]}),(0,V.jsxs)(`div`,{className:`claude-info-row`,children:[(0,V.jsx)(`span`,{className:`claude-info-label`,children:`Context used`}),(0,V.jsx)(`span`,{className:`claude-info-value`,children:l>0?`${l}%`:`—`})]}),(0,V.jsxs)(`div`,{className:`claude-info-row`,children:[(0,V.jsx)(`span`,{className:`claude-info-label`,children:`Tokens`}),(0,V.jsx)(`span`,{className:`claude-info-value`,children:u>0?xt(u):`—`})]}),(0,V.jsxs)(`div`,{className:`claude-info-row`,children:[(0,V.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,V.jsx)(`span`,{className:`claude-info-value`,children:bt(a)})]}),o&&(0,V.jsxs)(`div`,{className:`claude-info-row`,children:[(0,V.jsx)(`span`,{className:`claude-info-label`,children:`Conversation`}),(0,V.jsx)(`span`,{className:`claude-info-value`,style:{fontFamily:`monospace`,fontSize:10},children:o.slice(0,8)})]})]})]})})}var UE=5e3,WE={atPhase:8};function GE({show:e,onClose:t,versionInfo:n,sessionKey:r,onUpgradeComplete:i}){let[a,o]=(0,B.useState)(`prompt`),[s,c]=(0,B.useState)(``),[l,u]=(0,B.useState)(!1),[d,f]=(0,B.useState)(null),[p,m]=(0,B.useState)(null),[h,g]=(0,B.useState)(null),_=(0,B.useRef)(null),v=n?.latest??null,y=(0,B.useCallback)(()=>{_.current&&=(clearInterval(_.current),null)},[]);(0,B.useEffect)(()=>{e||(y(),o(`prompt`),c(``),u(!1),f(null),m(null),g(null))},[e,y]),(0,B.useEffect)(()=>y,[y]),(0,B.useEffect)(()=>{if(!(!e||a!==`running`||!v))return _.current=setInterval(async()=>{try{let e=await fetch(`/api/admin/version`,{cache:`no-store`});if(!e.ok)return;(await e.json()).installed===v&&(y(),o(`succeeded`),i(),setTimeout(()=>window.location.reload(),2e3))}catch{}},UE),y},[e,a,v,i,y]);let b=(0,B.useCallback)(async()=>{if(!(!v||!r||a!==`prompt`)){if(!s){f(`Enter your device password first.`);return}f(null),m(null),o(`priming`);try{let e=await fetch(`/api/admin/actions/sudo-prime?session_key=${encodeURIComponent(r)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({password:s,session_key:r})});if(e.status!==204){f((await e.json().catch(()=>({}))).error??`Password check failed (status ${e.status})`),o(`prompt`);return}}catch(e){f(e instanceof Error?e.message:`Password check network error`),o(`prompt`);return}try{let e=await fetch(`/api/admin/actions/upgrade?session_key=${encodeURIComponent(r)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sudoPassword:s,session_key:r})}),t=await e.json().catch(()=>({}));if(!e.ok||!t.actionId){m(t.error??`launch failed (status ${e.status})`),o(`launch-failed`);return}g(t.actionId),o(`running`)}catch(e){m(e instanceof Error?e.message:`launch network error`),o(`launch-failed`)}finally{c(``)}}},[s,v,r,a]);return e?(0,V.jsx)(`div`,{className:`claude-info-overlay`,onClick:()=>{(a===`prompt`||a===`succeeded`||a===`launch-failed`)&&t()},children:(0,V.jsxs)(`div`,{className:`claude-info-modal update-modal`,onClick:e=>e.stopPropagation(),children:[(0,V.jsxs)(`div`,{className:`claude-info-header`,children:[(0,V.jsx)(L,{size:12}),`Software Update`,(0,V.jsx)(`button`,{className:`claude-info-close`,onClick:t,children:`✕`})]}),(0,V.jsxs)(`div`,{className:`update-modal-body`,children:[(0,V.jsxs)(`div`,{className:`update-modal-versions`,children:[(0,V.jsxs)(`div`,{className:`claude-info-row`,children:[(0,V.jsx)(`span`,{className:`claude-info-label`,children:`Installed`}),(0,V.jsxs)(`span`,{className:`claude-info-value`,children:[`v`,n?.installed??`…`]})]}),(0,V.jsxs)(`div`,{className:`claude-info-row`,children:[(0,V.jsx)(`span`,{className:`claude-info-label`,children:`Available`}),(0,V.jsxs)(`span`,{className:`claude-info-value update-version-new`,children:[`v`,v??`…`]})]})]}),(a===`prompt`||a===`priming`||a===`launch-failed`)&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`form-input__field`,style:{marginTop:12},children:[(0,V.jsx)(`label`,{className:`form-input__label`,htmlFor:`upgrade-sudo`,children:`Device password`}),(0,V.jsxs)(`div`,{className:`tunnel-route__row`,children:[(0,V.jsx)(`input`,{id:`upgrade-sudo`,className:`form-input__input tunnel-route__input`,type:l?`text`:`password`,autoComplete:`current-password`,value:s,onChange:e=>{c(e.target.value),f(null)},disabled:a===`priming`,onKeyDown:e=>{e.key===`Enter`&&s&&b()}}),(0,V.jsx)(`button`,{type:`button`,className:`tunnel-route__suffix`,onClick:()=>u(e=>!e),disabled:a===`priming`,style:{cursor:`pointer`,border:`none`,background:`inherit`},"aria-label":l?`Hide password`:`Show password`,children:l?`Hide`:`Show`})]}),(0,V.jsx)(`div`,{className:`form-input__field-desc`,children:`Needed once. The installer uses it to run the privileged steps; it is never saved.`}),d&&(0,V.jsx)(`div`,{className:`tunnel-route__error`,children:d}),p&&(0,V.jsx)(`div`,{className:`tunnel-route__error`,role:`alert`,children:p})]}),(0,V.jsx)(`button`,{type:`button`,className:`update-modal-btn`,onClick:b,disabled:!v||!s||a===`priming`,children:a===`priming`?`Checking password…`:a===`launch-failed`?`Try again`:`Upgrade`})]}),a===`running`&&h&&r&&(0,V.jsx)(`div`,{className:`update-modal-terminal`,style:{height:360,marginTop:10},children:(0,V.jsx)(sE,{actionId:h,sessionKey:r,selfRestart:WE})}),a===`succeeded`&&(0,V.jsxs)(`div`,{className:`update-modal-result`,children:[(0,V.jsx)(De,{size:14,className:`update-success-icon`}),(0,V.jsxs)(`span`,{children:[`Upgraded to v`,v,` — reloading…`]})]})]})]})}):null}function KE(e){let{conversationId:t,sessionKey:n,disconnecting:r,onOpenConversations:i,handleDisconnect:a,onAfterAction:o}=e,s=!t&&!n;return(0,V.jsxs)(`div`,{className:`chat-actions-menu`,children:[(0,V.jsxs)(`button`,{type:`button`,className:`chat-action`,onClick:()=>{o(),i()},children:[(0,V.jsx)(Xe,{size:14}),(0,V.jsx)(`span`,{className:`action-label`,children:`Conversations`})]}),(0,V.jsxs)(`button`,{type:`button`,className:`chat-action`,disabled:r,onClick:async()=>{o(),await a()},children:[r?(0,V.jsx)(ge,{size:14,className:`animate-spin`}):(0,V.jsx)(Se,{size:14}),(0,V.jsx)(`span`,{className:`action-label`,children:r?`Disconnecting...`:`Disconnect Claude`})]}),(0,V.jsxs)(`button`,{type:`button`,className:`chat-action`,disabled:s,title:t?`Download stream log`:n?`Download stream log (pre-flush)`:`No session active — reload the page to start one`,onClick:()=>{if(o(),s){console.debug(`[stream-log-button] no-identity sessionKey=null conversationId=null`);return}let e=document.createElement(`a`);e.href=`${RE({conversationId:t,sessionKey:n},`stream`)}&download=1`,e.click()},children:[(0,V.jsx)(lt,{size:14}),(0,V.jsx)(`span`,{className:`action-label`,children:`Stream log`})]})]})}function qE(e){let{selectionMode:t,selectedItems:n,copyToast:r,exitSelection:i,enterSelection:a,copySelected:o,showCopyToast:s,input:l,setInput:p,inputRef:h,pendingFiles:g,setPendingFiles:v,isDragOver:y,attachError:b,fileInputRef:x,addFiles:S,removeFile:C,onDragOver:D,onDragLeave:O,onDrop:k,isStreaming:j,wasPaused:M,messages:P,messageQueueRef:te,setQueue:F,sendMessage:re,stopStreaming:ie,disconnecting:ae,handleDisconnect:oe,claudeInfo:se,setClaudeInfo:L,setShowClaudeInfo:ce,conversationId:le,sessionKey:ue,onNewConversation:de,newConversationDisabled:fe,onOpenConversations:pe,sidebarVisible:me}=e,[he,ge]=(0,B.useState)(!1),_e=(0,B.useRef)(null),[ve,ye]=(0,B.useState)(!1),be=(0,B.useRef)(null),xe=(0,B.useRef)(!1),Se=ee(),Ce=Se.state===`recording`||Se.state===`paused`||Se.state===`sending`,we=!Ce&&!M&&!l.trim()&&g.length===0;async function Te(){let e=await Se.send();if(!e)return;let t=e.type===`audio/ogg`?`.ogg`:e.type===`audio/mp4`?`.m4a`:`.webm`,n=new File([e],`voice-note${t}`,{type:e.type});if(j){F([...te.current,{text:`[Voice note]`,files:[n],timestamp:Date.now()}]);return}re(`[Voice note]`,[n])}return(0,B.useEffect)(()=>{t||ye(!1)},[t]),(0,B.useEffect)(()=>{if(!ve)return;let e=e=>{e.target.closest(`.selection-copy-wrap`)||ye(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[ve]),(0,B.useEffect)(()=>{if(!he)return;let e=e=>{if(e.key===`Escape`){ge(!1);return}if(e.key===`Tab`&&_e.current){let t=_e.current.querySelectorAll(`.actions-menu-items button:not([disabled])`);if(t.length===0)return;let n=t[0],r=t[t.length-1];e.shiftKey&&document.activeElement===n?(e.preventDefault(),r.focus()):!e.shiftKey&&document.activeElement===r&&(e.preventDefault(),n.focus())}},t=e=>{_e.current&&!_e.current.contains(e.target)&&ge(!1)};return document.addEventListener(`keydown`,e),document.addEventListener(`mousedown`,t),()=>{document.removeEventListener(`keydown`,e),document.removeEventListener(`mousedown`,t)}},[he]),t?(0,V.jsx)(`div`,{className:`chat-input-area`,children:(0,V.jsxs)(`div`,{className:`selection-bar`,children:[(0,V.jsxs)(`span`,{className:`selection-count`,children:[n.size,` Selected`]}),(0,V.jsxs)(`div`,{className:`selection-copy-wrap`,children:[(0,V.jsxs)(`button`,{type:`button`,className:`selection-copy`,onPointerDown:()=>{if(ve){ye(!1);return}xe.current=!1,be.current=setTimeout(()=>{xe.current=!0,ye(!0),be.current=null},500)},onPointerUp:()=>{be.current!==null&&(clearTimeout(be.current),be.current=null)},onPointerLeave:()=>{be.current!==null&&(clearTimeout(be.current),be.current=null)},onPointerCancel:()=>{be.current!==null&&(clearTimeout(be.current),be.current=null)},onClick:async()=>{xe.current||await o(e=>FE(P,e),(e,t)=>{let[n,r]=[e.slice(0,e.lastIndexOf(`_`)),e.slice(e.lastIndexOf(`_`)+1)],[i,a]=[t.slice(0,t.lastIndexOf(`_`)),t.slice(t.lastIndexOf(`_`)+1)],o=parseInt(n,10)-parseInt(i,10);return o===0?r===`admin`?-1:a===`admin`?1:parseInt(r,10)-parseInt(a,10):o})},children:[(0,V.jsx)(f,{size:18}),(0,V.jsx)(`span`,{children:`Copy`})]}),ve&&(0,V.jsx)(`div`,{className:`copy-menu`,children:[[`all`,`All events`],[`text`,`Text messages only`],[`non-text`,`Non-text only`]].map(([e,t])=>(0,V.jsx)(`button`,{type:`button`,className:`copy-menu-item`,onClick:async()=>{let t=IE(P,e);t&&s(await ne(t)),i()},children:t},e))})]}),(0,V.jsx)(`button`,{type:`button`,className:`selection-cancel`,onClick:i,children:`Cancel`})]})}):(0,V.jsxs)(`div`,{className:`chat-input-area`,children:[(0,V.jsx)(`input`,{ref:x,type:`file`,multiple:!0,accept:Ct,style:{display:`none`},onChange:e=>{e.target.files&&S([...e.target.files]),e.target.value=``}}),g.length>0&&(0,V.jsx)(`div`,{className:`attachment-strip`,children:g.map((e,t)=>(0,V.jsxs)(`div`,{className:`attachment-chip`,children:[e.type.startsWith(`image/`)?(0,V.jsx)(`img`,{src:URL.createObjectURL(e),alt:e.name,className:`attachment-chip-thumb`}):e.type===`application/pdf`?(0,V.jsx)(c,{size:14}):(0,V.jsx)(E,{size:14}),(0,V.jsx)(`span`,{className:`attachment-chip-name`,children:e.name}),(0,V.jsx)(`button`,{type:`button`,className:`attachment-chip-remove`,onClick:()=>C(t),"aria-label":`Remove ${e.name}`,children:`×`})]},t))}),b&&(0,V.jsx)(`p`,{className:`attach-error`,children:b}),Se.state===`error`&&Se.errorMessage&&(0,V.jsxs)(`p`,{className:`voice-error`,role:`alert`,children:[(0,V.jsx)(m,{size:14}),Se.errorMessage]}),(0,V.jsx)(T,{inputRef:h}),Ce?(0,V.jsx)(`div`,{className:`chat-form voice-active`,children:(0,V.jsx)(A,{state:Se.state,elapsedSeconds:Se.elapsedSeconds,waveform:Se.waveform,onTogglePause:Se.togglePause,onDiscard:Se.discard,onSend:Te})}):(0,V.jsxs)(`form`,{className:`chat-form${y?` drag-over`:``}`,onSubmit:e=>{e.preventDefault();let t=l.trim()||(M?`continue`:``);if(!(!t&&g.length===0)){if(j){F([...te.current,{text:t,files:[...g],timestamp:Date.now()}]),p(``),v([]),h.current?.resetHeight();return}re(t),h.current?.resetHeight()}},onDragOver:D,onDragLeave:O,onDrop:k,onPaste:e=>{let t=e.clipboardData?.items;if(!t)return;let n=[];for(let e of t){if(e.kind!==`file`)continue;let t=e.getAsFile();if(!t)continue;let r=t.type.split(`/`)[1]?.replace(`jpeg`,`jpg`)||`png`;n.push(new File([t],`pasted-image-${Date.now()}.${r}`,{type:t.type}))}n.length>0&&S(n)},children:[(0,V.jsx)(w,{variant:`icon`,type:`button`,onClick:()=>x.current?.click(),"aria-label":`Attach file`,children:(0,V.jsx)(u,{size:14})}),(0,V.jsx)(N,{ref:h,value:l,onChange:p}),j?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(w,{variant:`send`,type:`button`,onClick:()=>ie(!0),"aria-label":`Pause`,style:{background:`var(--text-secondary)`},children:(0,V.jsx)(d,{size:14})}),(0,V.jsx)(w,{variant:`send`,type:`button`,onClick:()=>ie(!1),"aria-label":`Stop`,style:{background:`var(--danger)`},children:(0,V.jsx)(ft,{size:14})})]}):we?(0,V.jsx)(w,{variant:`send`,type:`button`,onClick:Se.start,"aria-label":`Record voice note`,children:(0,V.jsx)(m,{size:14})}):(0,V.jsx)(w,{variant:`send`,type:`submit`,disabled:!l.trim()&&g.length===0&&!M,"aria-label":`Send message`,children:M?(0,V.jsx)(_,{size:14}):(0,V.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,V.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,V.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,V.jsxs)(`div`,{className:`chat-actions`,ref:_e,children:[(0,V.jsx)(`button`,{type:`button`,className:`chat-action-icon`,title:`New conversation`,"aria-label":`New conversation`,disabled:fe,onClick:de,children:(0,V.jsx)(Ve,{size:16})}),(0,V.jsx)(`button`,{type:`button`,className:`chat-action-icon`,title:`Select messages`,"aria-label":`Select messages`,onClick:a,children:(0,V.jsx)(I,{size:16})}),!me&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`button`,{className:`burger-trigger`,onClick:()=>ge(e=>!e),"aria-expanded":he,"aria-haspopup":`true`,"aria-label":`Conversation actions`,children:(0,V.jsx)(Pe,{size:16})}),(0,V.jsx)(`div`,{className:`actions-menu-items${he?` actions-menu-open`:``}`,children:(0,V.jsx)(KE,{conversationId:le,sessionKey:ue,disconnecting:ae,onOpenConversations:pe,handleDisconnect:oe,onAfterAction:()=>ge(!1)})})]}),(0,V.jsxs)(`div`,{className:`powered-by`,onClick:async()=>{if(ce(!0),!se){let e=await fetch(`/api/admin/claude-info`);e.ok&&L(await e.json())}},children:[(0,V.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`powered-by-icon`}),(0,V.jsx)(`span`,{children:`Powered by Claude Code`})]})]})]})}var JE=`maxy-vnc-overlay-popout`;function YE(e){let[t,n]=(0,B.useState)(!1),r=(0,B.useRef)(null),i=(0,B.useRef)(null),a=(0,B.useCallback)(()=>{i.current&&=(clearInterval(i.current),null),r.current&&!r.current.closed&&r.current.close(),r.current=null,n(!1)},[]),o=(0,B.useCallback)(()=>{let t=`/vnc-popout.html?title=${encodeURIComponent(C.productName)}`,o=window.open(t,JE,`width=1024,height=768`);o&&(r.current=o,n(!0),i.current=setInterval(()=>{r.current?.closed&&(a(),e?.())},500))},[a,e]);return(0,B.useEffect)(()=>()=>a(),[a]),{poppedOut:t,popout:o,cleanupPopout:a}}var XE=(0,B.forwardRef)(function({onClose:e},t){yt();let{poppedOut:n,popout:r,cleanupPopout:i}=YE(e);return(0,B.useImperativeHandle)(t,()=>({popout:r}),[r]),n?(0,V.jsxs)(`div`,{className:`browser-overlay-popout`,children:[(0,V.jsx)(D,{className:`browser-viewer__icon`}),(0,V.jsx)(`span`,{className:`browser-viewer__title`,children:C.productName}),(0,V.jsx)(`span`,{className:`browser-viewer__popout-label`,children:`Popped out`}),(0,V.jsx)(w,{variant:`ghost`,size:`sm`,icon:nt,onClick:()=>i(),"aria-label":`Pop back in`}),e&&(0,V.jsx)(w,{variant:`ghost`,size:`sm`,icon:oe,onClick:()=>{i(),e()},"aria-label":`Close`})]}):(0,V.jsx)(`iframe`,{src:`/vnc-viewer.html`,className:`browser-surface__iframe`,title:C.productName})});function ZE({onClose:e}){yt();let{poppedOut:t,popout:n,cleanupPopout:r}=YE(e),i=(0,B.useCallback)(()=>{r(),e()},[r,e]);(0,B.useEffect)(()=>{if(t)return;let e=e=>{e.key===`Escape`&&i()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,i]);let a=Zt({handlePopout:n,disabled:t});return t?(0,V.jsxs)(`div`,{className:`browser-overlay-popout`,children:[(0,V.jsx)(D,{className:`browser-viewer__icon`}),(0,V.jsx)(`span`,{className:`browser-viewer__title`,children:C.productName}),(0,V.jsx)(`span`,{className:`browser-viewer__popout-label`,children:`Popped out`}),(0,V.jsx)(w,{variant:`ghost`,size:`sm`,icon:nt,onClick:()=>{r()},"aria-label":`Pop back in`}),(0,V.jsx)(w,{variant:`ghost`,size:`sm`,icon:oe,onClick:i,"aria-label":`Close`})]}):(0,V.jsxs)(`div`,{className:`browser-viewer-fullscreen`,children:[(0,V.jsxs)(`div`,{className:`browser-viewer-fullscreen__bar`,...a,children:[(0,V.jsx)(D,{className:`browser-viewer__icon`}),(0,V.jsx)(`span`,{className:`browser-viewer-fullscreen__title`,children:C.productName}),(0,V.jsxs)(`div`,{className:`browser-viewer-fullscreen__actions`,children:[(0,V.jsx)(w,{variant:`ghost`,size:`sm`,icon:Fe,onClick:n,"aria-label":`Pop out`}),(0,V.jsx)(w,{variant:`ghost`,size:`sm`,icon:oe,onClick:i,"aria-label":`Close`})]})]}),(0,V.jsx)(`iframe`,{src:`/vnc-viewer.html`,className:`browser-viewer-fullscreen__iframe`,title:C.productName})]})}var QE=(0,B.forwardRef)(function(e,t){let{businessName:n,sessionKey:r,conversationId:i,role:a,userName:o,userAvatar:s,sessions:l,sessionsLoading:u,sessionsError:d,ensureSessionsLoaded:f,refetchSessions:p,onSelectSession:m,onSelectArtefact:h,onSelectProjects:g,onSelectPeople:_,onSelectTasks:v,onSelectAgents:y,onCloseMobileDrawer:b,collapsed:x,onToggleCollapsed:S,actions:w}=e;(0,B.useEffect)(()=>{f()},[f]);let T=C.productName,E=typeof o==`string`?o:o===null?`name unavailable`:n||T,D=(E.trim().charAt(0)||`?`).toUpperCase(),O=(0,B.useMemo)(()=>l.filter(e=>e.name),[l]),k=O.length,A=i??r,[j,M]=(0,B.useState)(`chat`),[N,P]=(0,B.useState)([]),[ee,te]=(0,B.useState)(!1),[F,I]=(0,B.useState)(null),[ne,re]=(0,B.useState)(!1);(0,B.useImperativeHandle)(t,()=>({patchArtefact(e,t){P(n=>n.map(n=>n.id===e?{...n,...t}:n))}}),[]);let[ae,oe]=(0,B.useState)(!1),se=(0,B.useRef)(null);(0,B.useEffect)(()=>{if(!ae)return;function e(e){se.current&&!se.current.contains(e.target)&&oe(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[ae]);let L=(0,B.useCallback)(async()=>{if(r){re(!0),I(null);try{let e=await fetch(`/api/admin/sidebar-artefacts?session_key=${encodeURIComponent(r)}`);if(!e.ok)throw Error(`status ${e.status}`);P((await e.json()).artefacts??[]),te(!0)}catch(e){let t=e instanceof Error?e.message:String(e);I(`Failed to load artefacts: ${t}`),console.error(`[admin-ui] sidebar-artefacts fetch failed: ${t}`)}finally{re(!1)}}},[r]),ce=()=>{M(`chat`),console.info(`[admin-ui] sidebar-nav surface=chat count=${k}`)},le=()=>{M(`artefacts`),console.info(`[admin-ui] sidebar-nav surface=artefacts count=${ee?N.length:0}`),ee||L()},ue=x?24:16,de=j===`chat`?`Recents`:`Artefacts`,fe=j===`chat`?u?`…`:String(k):ne?`…`:String(N.length),pe=j===`chat`?u:ne,me=()=>{j===`chat`?p():L(),console.info(`[admin-ui] sidebar-refresh surface=${j}`)};return(0,V.jsxs)(`aside`,{className:`side`,children:[(0,V.jsx)(`div`,{className:`side-head`,children:(0,V.jsx)(`button`,{className:`icon-btn side-head-toggle`,title:x?`Expand sidebar`:`Collapse sidebar`,type:`button`,"aria-label":x?`Expand sidebar`:`Collapse sidebar`,onClick:S,children:x?(0,V.jsx)(ot,{size:28}):(0,V.jsx)(at,{size:28})})}),(0,V.jsxs)(`nav`,{className:`side-nav`,children:[(0,V.jsxs)(`button`,{type:`button`,className:`nav-row${j===`chat`?` active`:``}`,onClick:ce,children:[(0,V.jsx)(tt,{size:ue}),(0,V.jsx)(`span`,{className:`label`,children:`Chat`}),(0,V.jsx)(`span`,{className:`kbd`})]}),(0,V.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=people`),_(),b()},children:[(0,V.jsx)(gt,{size:ue}),(0,V.jsx)(`span`,{className:`label`,children:`People`}),(0,V.jsx)(`span`,{className:`kbd`})]}),(0,V.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=agents`),y(),b()},children:[(0,V.jsx)(Ce,{size:ue}),(0,V.jsx)(`span`,{className:`label`,children:`Agents`}),(0,V.jsx)(`span`,{className:`kbd`})]}),(0,V.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=projects`),g(),b()},children:[(0,V.jsx)(we,{size:ue}),(0,V.jsx)(`span`,{className:`label`,children:`Projects`}),(0,V.jsx)(`span`,{className:`kbd`})]}),(0,V.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=tasks`),v(),b()},children:[(0,V.jsx)(Ye,{size:ue}),(0,V.jsx)(`span`,{className:`label`,children:`Tasks`}),(0,V.jsx)(`span`,{className:`kbd`})]}),(0,V.jsxs)(`button`,{type:`button`,className:`nav-row${j===`artefacts`?` active`:``}`,onClick:le,children:[(0,V.jsx)(c,{size:ue}),(0,V.jsx)(`span`,{className:`label`,children:`Artefacts`}),(0,V.jsx)(`span`,{className:`kbd`})]})]}),(0,V.jsxs)(`div`,{className:`side-list`,children:[(0,V.jsxs)(`div`,{className:`group-head`,children:[(0,V.jsx)(`span`,{children:de}),(0,V.jsxs)(`span`,{className:`group-head-meta`,children:[(0,V.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh ${de.toLowerCase()}`,"aria-label":`Refresh ${de.toLowerCase()}`,onClick:me,disabled:pe,children:(0,V.jsx)(ie,{size:12,className:pe?`spinning`:void 0})}),(0,V.jsx)(`span`,{children:fe})]})]}),j===`chat`&&(0,V.jsxs)(V.Fragment,{children:[d&&(0,V.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:d}),O.map(e=>{let t=e.conversationId??e.sessionKey;return(0,V.jsx)(`button`,{type:`button`,className:`conv${t!==null&&t===A?` active`:``}`,onClick:()=>{let t=e.sessionKey?e.sessionKey.slice(0,8):`null`,n=e.conversationId?e.conversationId.slice(0,8):`null`;console.info(`[admin-session-identity] sessionKey=${t} conversationId=${n} phase=${e.phase} surface=sidebar-recents`),m(e),b()},children:(0,V.jsx)(`span`,{className:`conv-name`,children:e.name??`(untitled)`})},t??e.updatedAt)})]}),j===`artefacts`&&(0,V.jsxs)(V.Fragment,{children:[F&&(0,V.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:F}),ee&&!F&&N.length===0&&(0,V.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No artefacts yet`}),N.map(e=>(0,V.jsxs)(`button`,{type:`button`,className:`conv`,onClick:()=>{h({docId:e.id,name:e.name,content:e.content,editable:e.editable,mimeType:e.mimeType,skipReason:e.skipReason},`sidebar-artefacts`),b()},children:[(0,V.jsx)(`span`,{className:`conv-name`,children:e.name}),(0,V.jsx)(`span`,{className:`conv-kind`,"data-kind":e.kind===`agent-template`?`agent`:`doc`,children:e.kind===`agent-template`?`agent`:`doc`})]},e.id))]})]}),(0,V.jsxs)(`div`,{className:`side-foot`,ref:se,children:[(0,V.jsx)(`div`,{className:`avatar`,children:s?(0,V.jsx)(`img`,{src:s,alt:E}):D}),(0,V.jsxs)(`div`,{className:`who`,children:[(0,V.jsx)(`span`,{className:`name`,children:E}),(0,V.jsx)(`span`,{className:`role`,children:a??`operator`})]}),(0,V.jsx)(`button`,{className:`icon-btn side-foot-actions-trigger`,title:`Conversation actions`,type:`button`,"aria-label":`Conversation actions`,"aria-haspopup":`true`,"aria-expanded":ae,onClick:()=>oe(e=>!e),children:(0,V.jsx)(Pe,{size:ue})}),ae&&(0,V.jsx)(`div`,{className:`side-foot-actions-popover`,children:(0,V.jsx)(KE,{...w,onAfterAction:()=>oe(!1)})})]})]})}),$E=()=>{},eD={"null-attachmentId":`No file backing this artefact.`,"non-text-mime":`Content type cannot be displayed inline.`,"containment-rejected":`File path failed containment check; cannot display.`,"missing-on-disk":`File is missing on disk.`};function tD({reason:e}){return(0,V.jsxs)(`div`,{className:`art-skip-banner`,role:`status`,children:[(0,V.jsx)(Re,{size:14}),(0,V.jsx)(`span`,{children:eD[e]})]})}function nD({src:e,name:t,docId:n}){let[r,i]=(0,B.useState)(!1),a=(0,B.useRef)(null),o=(0,B.useRef)(!1),s=(0,B.useRef)(!1),l=(0,B.useCallback)(e=>{s.current||(s.current=!0,console.info(`[admin-ui] artefact-pdf-fallback id=${n.slice(0,8)} reason=${e}`),i(!0))},[n]);(0,B.useEffect)(()=>{let e=setTimeout(()=>{o.current||l(`onload-timeout`)},3e3);return()=>clearTimeout(e)},[l]);let u=()=>{o.current=!0;try{let e=a.current?.contentDocument?.body;e&&e.children.length===0&&!e.textContent?.trim()&&l(`empty-body`)}catch{}};return r?(0,V.jsxs)(`a`,{className:`art-pdf-fallback`,href:e,download:t,children:[(0,V.jsx)(c,{size:20}),(0,V.jsxs)(`div`,{className:`art-pdf-fallback-text`,children:[(0,V.jsx)(`div`,{className:`art-pdf-fallback-name`,children:t}),(0,V.jsx)(`div`,{className:`art-pdf-fallback-hint`,children:`Your browser can't display this PDF inline. Click to download.`})]}),(0,V.jsx)(L,{size:16})]}):(0,V.jsx)(`iframe`,{ref:a,className:`art-pdf`,src:e,title:t,"aria-label":`PDF preview of ${t}`,onLoad:u,onError:()=>l(`onerror`)})}var rD={browser:`Browser`,data:`Data`,graph:`Graph`};function iD({selection:e,trigger:t,sessionKey:n,onClose:r,onArtefactSaved:i}){let a=e!==null,o=e?.surface??null,s=(0,B.useRef)(null),c=(0,B.useRef)(null),[l,u]=(0,B.useState)(null),d=e?.surface===`doc`?e.docId:null,p=(0,B.useCallback)(e=>{if(!n||!d)return;let t={};try{t=JSON.parse(e)}catch{return}t.action!==`save`||typeof t.content!=`string`||(u(null),fetch(`/api/admin/sidebar-artefact-save?session_key=${encodeURIComponent(n)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({id:d,content:t.content})}).then(async e=>{if(!e.ok){let t=(await e.json().catch(()=>({}))).error??`status ${e.status}`;u(`Save failed: ${t}`),console.error(`[admin-ui] artefact-save-failed docId=${d} status=${e.status} error="${t}"`);return}let n=await e.json();i?.(d,n.updatedAt,t.content)}).catch(e=>{let t=e instanceof Error?e.message:String(e);u(`Save failed: ${t}`),console.error(`[admin-ui] artefact-save-failed docId=${d} error="${t}"`)}))},[n,d,i]);(0,B.useEffect)(()=>{u(null)},[d]),(0,B.useEffect)(()=>{let n=e?.surface===`doc`?e.docId:null,r=e?.surface===`graph`?e.focusNodeId??null:null,i=e?.surface??null,o=i===null?`closed`:`${i}:${n??`none`}:${r??`none`}`;if(o===s.current)return;let c=a?`open`:`closed`,l=a?t??`chat-link`:`toolbar-close`,u=i??s.current?.split(`:`)[0]??`doc`;console.info(`[admin-ui] artefact-pane state=${c} docId=${n??`none`} trigger=${l} surface=${u}`),s.current=o},[e,t,a]);let m=e?.surface===`doc`,h=m?(e.tag||e.name.split(`.`).pop()||`doc`).toUpperCase().slice(0,6):``,g=m?e.revision||`rev 1`:`live`,_=e&&e.surface!==`doc`?rD[e.surface]:``,v=m?e.name:_;return(0,V.jsxs)(`aside`,{className:`artefact`,"data-open":a,"data-surface":o??`none`,children:[(0,V.jsxs)(`div`,{className:`art-head`,children:[(0,V.jsxs)(`div`,{className:`left`,children:[!m&&o===`browser`&&(0,V.jsx)(D,{size:14,className:`art-head-surface-icon`}),!m&&o===`data`&&(0,V.jsx)(fe,{size:14,className:`art-head-surface-icon`}),!m&&o===`graph`&&(0,V.jsx)(he,{size:14,className:`art-head-surface-icon`}),(0,V.jsx)(`span`,{className:`file-name`,children:v}),m&&(0,V.jsx)(`span`,{className:`file-tag`,children:h})]}),(0,V.jsxs)(`div`,{className:`right`,children:[m&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`button`,{className:`icon-btn`,title:`Copy`,type:`button`,"aria-label":`Copy`,onClick:()=>{ne(e.content)},children:(0,V.jsx)(f,{size:14})}),(0,V.jsx)(`button`,{className:`icon-btn`,title:`Refresh`,type:`button`,"aria-label":`Refresh`,children:(0,V.jsx)(ae,{size:14})})]}),o===`browser`&&(0,V.jsx)(`button`,{className:`icon-btn`,title:`Pop out`,type:`button`,"aria-label":`Pop out`,onClick:()=>c.current?.popout(),children:(0,V.jsx)(Fe,{size:14})}),a&&(0,V.jsx)(`button`,{className:`icon-btn`,title:`Close`,type:`button`,"aria-label":`Close`,onClick:r,children:(0,V.jsx)(oe,{size:14})})]})]}),(0,V.jsxs)(`div`,{className:`art-toolbar`,children:[(0,V.jsxs)(`span`,{className:`seg`,children:[(0,V.jsx)(`span`,{className:`bullet`}),(0,V.jsx)(`strong`,{children:m?`Artefact`:_})]}),(0,V.jsx)(`span`,{className:`right-meta`,children:g})]}),(0,V.jsxs)(`div`,{className:`art-body`,"data-surface":o??`none`,children:[m&&(()=>{let t=e.editable!==!1,r=e.skipReason??null,i=(e.mimeType??``).startsWith(`application/pdf`);if(r)return(0,V.jsx)(tD,{reason:r});if(i&&n){let t=`/api/admin/sidebar-artefact-content?id=${encodeURIComponent(e.docId)}&session_key=${encodeURIComponent(n)}`;return(0,V.jsx)(nD,{src:t,name:e.name,docId:e.docId},t)}return(0,V.jsxs)(V.Fragment,{children:[l&&(0,V.jsx)(`div`,{className:`art-save-error`,role:`alert`,children:l}),(0,V.jsx)(Jw,{data:{title:e.name,content:e.content,readOnly:!t},onSubmit:t?p:$E,submitted:!1})]})})(),o===`browser`&&(0,V.jsx)(XE,{ref:c,onClose:r}),o===`data`&&n&&(0,V.jsx)(ce,{sessionKey:n}),e?.surface===`graph`&&n&&(0,V.jsx)(se,{sessionKey:n,initialFocus:e.focusNodeId?{nodeId:e.focusNodeId,nodeLabel:e.focusNodeLabel??null}:null,initialLabels:e.initialLabels??null})]}),(0,V.jsxs)(`div`,{className:`art-foot`,children:[(0,V.jsx)(`span`,{className:`left`,children:g}),(0,V.jsx)(`span`,{className:`right in-sync`,children:`in sync`})]})]})}var aD=`maxy-shell-artefact-px`;function oD(){if(typeof window>`u`)return 320;let e=window.innerWidth,t=document.querySelector(`.platform > .side`)?.getBoundingClientRect(),n=t?t.right:Math.round(e*.3);return cD(Math.round((e-n)*(2/3)))}function sD(){if(typeof window>`u`)return 320;try{let e=window.localStorage.getItem(aD);if(!e)return oD();let t=parseInt(e,10);if(Number.isFinite(t)&&t>=320)return t}catch{}return oD()}function cD(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=document.querySelector(`.platform > .side`)?.getBoundingClientRect(),r=n?n.right:Math.round(t*.3),i=Math.max(320,t-r-480);return Math.min(Math.max(e,320),i)}function lD({targetSelector:e=`.platform`}){let t=(0,B.useRef)(null),[n,r]=(0,B.useState)(()=>sD()),i=(0,B.useRef)(n);(0,B.useEffect)(()=>{let t=document.querySelector(e);!t||!(t instanceof HTMLElement)||(t.style.setProperty(`--artefact-px`,`${n}px`),i.current=n)},[n,e]);let a=(0,B.useCallback)(()=>{r(e=>{let t=cD(e);return t===e?e:t})},[]);(0,B.useEffect)(()=>(a(),window.addEventListener(`resize`,a),()=>window.removeEventListener(`resize`,a)),[a]);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(cD(Math.round(window.innerWidth-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(aD,String(t))}catch{}console.info(`[admin-ui] artefact-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=oD();r(e);try{window.localStorage.removeItem(aD)}catch{}console.info(`[admin-ui] artefact-resize px=${e}`)};return(0,V.jsx)(`div`,{ref:t,className:`art-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize artefact pane`,onPointerDown:o,onDoubleClick:s})}var uD=`maxy-shell-side-px`;function dD(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .artefact`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function fD(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=Math.max(220,t-480-dD());return Math.min(Math.max(e,220),n)}function pD(){if(typeof window>`u`)return 264;try{let e=window.localStorage.getItem(uD);if(!e)return 264;let t=parseInt(e,10);if(Number.isFinite(t)&&t>=220)return fD(t)}catch{}return 264}function mD({targetSelector:e=`.platform`}){let t=(0,B.useRef)(null),[n,r]=(0,B.useState)(()=>pD()),i=(0,B.useRef)(n);(0,B.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,B.useCallback)(()=>{r(e=>{let t=fD(e);return t===e?e:t})},[]);(0,B.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(fD(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(uD,String(t))}catch{}console.info(`[admin-ui] sidebar-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=fD(264);r(e);try{window.localStorage.removeItem(uD)}catch{}console.info(`[admin-ui] sidebar-resize px=${e}`)};return(0,V.jsx)(`div`,{ref:t,className:`side-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize sidebar`,onPointerDown:o,onDoubleClick:s})}function hD(e){let[t,n]=(0,B.useState)([]),[r,i]=(0,B.useState)(!1),[a,o]=(0,B.useState)(null),[s,c]=(0,B.useState)(null),l=(0,B.useCallback)(async t=>{if(e&&!(!t&&s===e)){i(!0),o(null);try{let t=await fetch(`/api/admin/sessions?session_key=${encodeURIComponent(e)}`);if(!t.ok)throw Error(`sessions fetch returned ${t.status}`);n((await t.json()).sessions??[]),c(e)}catch(e){console.error(`[admin/sessions] fetch failed:`,e),o(e instanceof Error?e.message:String(e))}finally{i(!1)}}},[e,s]);(0,B.useEffect)(()=>{e||(c(null),n([]),o(null))},[e]);let u=(0,B.useCallback)(()=>l(!1),[l]),d=(0,B.useCallback)(()=>l(!0),[l]);return{sessions:t,setSessions:n,loading:r,loaded:s!==null&&s===e,error:a,ensureLoaded:u,refetch:d}}function gD(){yt();let e=(0,B.useRef)(null),[t,n]=(0,B.useState)(null),[r,a]=(0,B.useState)(!1),[o,s]=(0,B.useState)(!1),[c,l]=(0,B.useState)(``),[u,d]=(0,B.useState)(!1),[f,p]=(0,B.useState)(null),[m,_]=(0,B.useState)(!1),[v,y]=(0,B.useState)(null),[b,x]=(0,B.useState)(null),[w,T]=(0,B.useState)(!1),[E,O]=(0,B.useState)(null),[k,A]=(0,B.useState)(!1),[j,M]=(0,B.useState)(null),[N,P]=(0,B.useState)(!1),[ee,te]=(0,B.useState)(!1),[I,re]=(0,B.useState)(!1),[ie,ae]=(0,B.useState)(!1),[se,L]=(0,B.useState)(null),[ce,le]=(0,B.useState)(null),de=(0,B.useRef)(null),[pe,_e]=(0,B.useState)(()=>typeof window<`u`&&window.matchMedia(`(min-width: 641px)`).matches);(0,B.useEffect)(()=>{let e=window.matchMedia(`(min-width: 641px)`),t=e=>_e(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let[ve,ye]=(0,B.useState)(()=>typeof window<`u`&&window.matchMedia(`(min-width: 1080px)`).matches);(0,B.useEffect)(()=>{let e=window.matchMedia(`(min-width: 1080px)`),t=e=>ye(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let be=(0,B.useRef)(!1),xe=(0,B.useRef)(!1),Se=(0,B.useRef)(!1),Ce=(0,B.useRef)(!1),we=(0,B.useRef)(null),[Te,Ee]=(0,B.useState)(null),De=g(),Oe=St(),R=Ot(),ke=Rt(),Ae=hD(R.sessionKey),z=Lt({sessionKey:R.sessionKey,setSessionKey:R.setSessionKey,setAppState:R.setAppState,setConversationId:R.setConversationId,startElapsedTimer:Oe.startElapsedTimer,stopElapsedTimer:Oe.stopElapsedTimer,resetTimerState:Oe.resetTimerState,pausedElapsedRef:Oe.pausedElapsedRef,expandAllDefaultRef:R.expandAllDefaultRef,setExpandAll:R.setExpandAll,getPendingFiles:()=>ke.pendingFiles,clearPendingFiles:ke.clearFiles,inputRef:e});(0,B.useEffect)(()=>{l(window.location.hostname.startsWith(`admin.`)?window.location.origin.replace(`admin.`,`public.`):window.location.origin)},[]),(0,B.useEffect)(()=>{function e(e){e.key===`Escape`&&(t?n(null):De.selectionMode&&De.exitSelection())}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,De.selectionMode]),(0,B.useEffect)(()=>{(R.appState===`set-pin`||R.appState===`enter-pin`)&&setTimeout(()=>R.pinInputRef.current?.focus(),100),R.appState===`chat`&&setTimeout(()=>e.current?.focus(),100)},[R.appState,z.greetingGeneration]),(0,B.useEffect)(()=>{if(R.appState!==`chat`)return;history.pushState({maxyChat:!0},``);function e(){console.debug(`[history-guard] popstate absorbed`),history.pushState({maxyChat:!0},``)}return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[R.appState]);let je=(0,B.useRef)(z.greetingGeneration);if((0,B.useEffect)(()=>{z.greetingGeneration!==je.current&&(je.current=z.greetingGeneration,R.onboardingComplete===!1&&(be.current=!1))},[z.greetingGeneration,R.onboardingComplete]),(0,B.useEffect)(()=>{R.appState===`chat`&&R.onboardingComplete===!1&&(be.current||(be.current=!0,z.sendSystemPrompt(`[Begin onboarding.]`)))},[R.appState,R.onboardingComplete,z.greetingGeneration]),(0,B.useEffect)(()=>{if(!u)return;let e=!1;return fetch(`/api/admin/version`).then(e=>e.json()).then(t=>{e||O(t)}).catch(e=>{console.error(`[admin/version] menu-open client fetch failed:`,e)}),()=>{e=!0}},[u]),(0,B.useEffect)(()=>{if(R.appState!==`chat`){Se.current=!1,Ce.current=!1;return}if(Se.current)return;Se.current=!0;let e=!1;return fetch(`/api/admin/version`).then(e=>e.json()).then(t=>{e||(O(t),!(!t.updateAvailable||Ce.current)&&(M(t),A(!0),fetch(`/api/admin/version/alert-surfaced`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({installed:t.installed,latest:t.latest})}).catch(e=>{console.error(`[admin/version] alert-surfaced signal failed:`,e)})))}).catch(e=>{console.error(`[admin/version] session-start client fetch failed:`,e)}),()=>{e=!0}},[R.appState]),(0,B.useEffect)(()=>{if(R.appState!==`chat`||!R.sessionKey)return;let e=R.conversationId?`flushed`:`pre-flush`,t=R.sessionKey.slice(0,8),n=R.conversationId?R.conversationId.slice(0,8):`null`;console.info(`[admin-session-identity] sessionKey=${t} conversationId=${n} phase=${e} surface=chat-header`)},[R.appState,R.sessionKey,R.conversationId]),(0,B.useEffect)(()=>{if(R.appState!==`chat`){xe.current=!1;return}if(xe.current||!Ae.loaded)return;xe.current=!0;let e=Ae.sessions.filter(e=>e.name).length,t=se?`open`:`closed`;console.info(`[admin-ui] platform-shell brand=${C.productName} sidebar=${e} artefact=${t}`)},[R.appState,Ae.loaded,Ae.sessions,se]),(0,B.useEffect)(()=>{if(!u){p(null),y(null),x(null),O(null);return}function e(e){we.current&&!we.current.contains(e.target)&&d(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[u]),(0,B.useEffect)(()=>{if(typeof BroadcastChannel>`u`)return;let e=new BroadcastChannel(`platform-onboarding`);return e.onmessage=e=>{e.data?.type===`remote-password-set`&&z.sendMessageRef.current(`I've set the remote password`)},()=>e.close()},[]),R.appState===`loading`)return(0,V.jsx)(`div`,{className:`chat-page admin-page`,children:(0,V.jsx)(`header`,{className:`chat-header`,children:(0,V.jsx)(`img`,{src:F,alt:C.productName,className:`chat-logo`})})});if(R.appState===`set-pin`)return(0,V.jsx)(Bt,{pin:R.pin,setPin:R.setPin,confirmPin:R.confirmPin,setConfirmPin:R.setConfirmPin,operatorName:R.operatorName,setOperatorName:R.setOperatorName,showPin:R.showPin,setShowPin:R.setShowPin,pinLoading:R.pinLoading,pinError:R.pinError,pinInputRef:R.pinInputRef,confirmPinInputRef:R.confirmPinInputRef,setPinFormRef:R.setPinFormRef,onSubmit:R.handleSetPin});if(R.appState===`onboarding-choice`)return(0,V.jsx)(Wt,{setAppState:R.setAppState,setOnboardingComplete:R.setOnboardingComplete});if(R.appState===`connect-claude`)return(0,V.jsx)(Ut,{authPolling:R.authPolling,setAuthPolling:R.setAuthPolling,authLoading:R.authLoading,setAuthLoading:R.setAuthLoading,pinError:R.pinError,setPinError:R.setPinError,setAppState:R.setAppState});if(R.appState===`enter-pin`)return(0,V.jsx)(Vt,{pin:R.pin,setPin:R.setPin,showPin:R.showPin,setShowPin:R.setShowPin,pinLoading:R.pinLoading,pinError:R.pinError,pinInputRef:R.pinInputRef,onSubmit:R.handleLogin,onChangePin:R.handleChangePin});if(R.appState===`account-picker`)return(0,V.jsx)(Ht,{accounts:R.accounts,loading:R.accountPickerLoading,error:R.pinError,onSelect:R.handleAccountSelect});let Me=se?`open`:`closed`,Ne=ie&&pe,Pe=`platform${I?` menu-open`:``}${Ne?` sidebar-collapsed`:``}`,Ie=e=>{if(!z.isStreaming&&R.sessionKey){if(!e.conversationId){z.resetConversation(),z.setMessages([]),R.setConversationId(null);return}z.resetConversation(),z.setMessages([]),fetch(`/api/admin/sessions/${encodeURIComponent(e.conversationId)}/resume?session_key=${encodeURIComponent(R.sessionKey)}`,{method:`POST`}).then(e=>e.ok?e.json():Promise.reject(Error(`resume returned ${e.status}`))).then(e=>{e.conversationId&&R.setConversationId(e.conversationId);let t=(e.messages??[]).map(e=>({role:e.role===`user`?`admin`:`maxy`,content:e.role===`user`?e.content:void 0,events:e.role===`assistant`?e.events??[]:void 0,...e.role===`user`&&e.attachments&&e.attachments.length>0?{attachments:e.attachments}:{},timestamp:new Date(e.createdAt).getTime()||0,historical:!0}));t.length>0&&z.setMessages(t);let n=[];for(let t of e.messages??[]){if(t.role!==`assistant`||!t.submittedEventIndices?.length)continue;let e=new Date(t.createdAt).getTime()||0;for(let r of t.submittedEventIndices)n.push(`${e}_${r}`)}n.length>0&&z.seedSubmittedComponents(n)}).catch(e=>{console.error(`[chat] sidebar conversation resume failed:`,e),z.setMessages([{role:`maxy`,events:[{type:`text`,content:`Could not load conversation history.`}],timestamp:Date.now()-1,historical:!0}])})}},Le={conversationId:R.conversationId,sessionKey:R.sessionKey,disconnecting:R.disconnecting,onOpenConversations:()=>{T(!0),Ae.refetch()},handleDisconnect:R.handleDisconnect};return(0,V.jsx)(S,{value:{onShowVnc:()=>P(!0)},children:(0,V.jsxs)(`div`,{className:Pe,"data-artefact":Me,children:[(0,V.jsx)(`div`,{className:`scrim`,onClick:()=>{re(!1),console.info(`[admin-ui] mobile-drawer state=closed`)}}),(0,V.jsx)(QE,{ref:de,businessName:R.businessName??null,sessionKey:R.sessionKey,conversationId:R.conversationId,role:R.role,userName:R.userName,userAvatar:R.userAvatar,sessions:Ae.sessions,sessionsLoading:Ae.loading,sessionsError:Ae.error,ensureSessionsLoaded:Ae.ensureLoaded,refetchSessions:Ae.refetch,onSelectSession:Ie,onSelectArtefact:(e,t)=>{L({surface:`doc`,...e}),le(t)},onSelectProjects:()=>{L({surface:`graph`,initialLabels:[`Project`]}),le(`sidebar-projects`)},onSelectPeople:()=>{L({surface:`graph`,initialLabels:[`Person`]}),le(`sidebar-people`)},onSelectTasks:()=>{L({surface:`graph`,initialLabels:[`Task`]}),le(`sidebar-tasks`)},onSelectAgents:()=>{L({surface:`graph`,initialLabels:[`Agent`]}),le(`sidebar-agents`)},onCloseMobileDrawer:()=>{I&&(re(!1),console.info(`[admin-ui] mobile-drawer state=closed`))},collapsed:Ne,onToggleCollapsed:()=>ae(e=>!e),actions:Le}),(0,V.jsxs)(`div`,{className:`chat-page admin-page`,children:[(0,V.jsxs)(`header`,{className:`chat-header`,children:[(0,V.jsx)(`button`,{type:`button`,className:`icon-btn mobile-menu`,"aria-label":`Show sidebar`,title:`Show sidebar`,onClick:()=>{re(e=>{let t=!e;return console.info(`[admin-ui] mobile-drawer state=${t?`open`:`closed`}`),t})},children:(0,V.jsx)(ot,{size:16})}),(0,V.jsx)(`img`,{src:F,alt:C.productName,className:`chat-logo`}),(!C.logoContainsName||R.businessName)&&(0,V.jsx)(`div`,{children:(0,V.jsx)(`h1`,{className:`chat-tagline`,children:R.businessName||C.productName})}),(R.sessionKey||R.conversationId)&&(0,V.jsxs)(`button`,{type:`button`,className:`chat-session-chip chat-session-chip-${R.conversationId?`flushed`:`pre-flush`}`+(Te===`copied`?` copied`:``)+(Te===`failed`?` copy-failed`:``),title:R.conversationId?`conversation ${R.conversationId} — click to copy`:`session ${R.sessionKey} (pre-flush, first turn pending) — click to copy`,onClick:async()=>{let e=R.conversationId??R.sessionKey;e&&(Ee(await ne(e)?`copied`:`failed`),setTimeout(()=>Ee(null),1200))},children:[(0,V.jsx)(`span`,{className:`chat-session-chip-label`,children:Te===`copied`?`copied`:Te===`failed`?`copy failed`:R.conversationId?`conversation`:`session`}),(0,V.jsx)(`span`,{className:`chat-session-chip-id`,children:Te===`copied`?`✓`:Te===`failed`?`✕`:`${(R.conversationId??R.sessionKey??``).slice(0,8)}…`})]}),(0,V.jsxs)(`div`,{className:`chat-burger-wrap`,ref:we,children:[(0,V.jsx)(`button`,{type:`button`,className:`chat-burger`,onClick:()=>d(e=>!e),"aria-label":`Menu`,"aria-haspopup":`true`,"aria-expanded":u,children:(0,V.jsx)(ue,{size:20})}),u&&(0,V.jsxs)(`div`,{className:`chat-menu`,children:[(0,V.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:async()=>{if(!ee&&!(!ve&&N)){te(!0),d(!1);try{let e=await(await fetch(`/api/admin/browser/launch`,{method:`POST`})).json().catch(()=>({ok:!1,error:`Invalid response`}));if(!e.ok)throw Error(e.error??`Failed to launch browser`);ve?(L({surface:`browser`}),le(`header-menu`)):P(!0)}catch(e){console.error(`[browser] Launch failed:`,e),alert(e instanceof Error?e.message:`Failed to launch browser`)}finally{te(!1)}}},disabled:ee,children:[(0,V.jsx)(D,{size:14}),` Browser`,ee&&(0,V.jsx)(ge,{size:12,className:`spin`})]}),(0,V.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{d(!1),ve?(L({surface:`data`}),le(`header-menu`)):window.location.href=`/data`},children:[(0,V.jsx)(fe,{size:14}),` Data`]}),(0,V.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{d(!1),ve?(L({surface:`graph`}),le(`header-menu`)):window.location.href=`/graph`},children:[(0,V.jsx)(he,{size:14}),` Graph`]}),(0,V.jsx)(`div`,{className:`chat-menu-divider`}),(0,V.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:async()=>{if(f!==null){p(null),x(null);return}_(!0),y(null);try{let e=await fetch(`/api/admin/agents`);if(!e.ok)throw Error(`Failed to load agents`);p((await e.json()).agents??[])}catch(e){console.error(`[admin] agent list failed:`,e),y(e instanceof Error?e.message:String(e))}finally{_(!1)}},children:[(0,V.jsx)(Fe,{size:14}),` Public`,m&&(0,V.jsx)(ge,{size:12,className:`spin`})]}),f!==null&&(0,V.jsxs)(`div`,{className:`chat-menu-agents`,children:[v&&(0,V.jsx)(`span`,{className:`chat-menu-agent-error`,children:v}),f.length===0&&!v&&(0,V.jsx)(`span`,{className:`chat-menu-agent-empty`,children:`No public agents configured`}),f.map(e=>(0,V.jsxs)(`div`,{className:`chat-menu-item chat-menu-agent-item`,children:[(0,V.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),(0,V.jsxs)(`span`,{className:`agent-text`,children:[(0,V.jsx)(`span`,{className:`agent-display-name`,children:e.displayName}),(0,V.jsxs)(`span`,{className:`agent-slug`,children:[`/`,e.slug]})]}),b===e.slug?(0,V.jsxs)(`span`,{className:`agent-actions agent-confirm`,children:[(0,V.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-yes`,title:`Confirm delete`,onClick:()=>{x(null),p(t=>t?.filter(t=>t.slug!==e.slug)??null),fetch(`/api/admin/agents/${encodeURIComponent(e.slug)}`,{method:`DELETE`}).catch(e=>console.error(`[admin/agents] delete failed:`,e))},children:(0,V.jsx)(h,{size:12})}),(0,V.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-no`,title:`Cancel`,onClick:()=>x(null),children:(0,V.jsx)(oe,{size:12})})]}):(0,V.jsxs)(`span`,{className:`agent-actions`,children:[(0,V.jsx)(`a`,{href:`${c}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`agent-action-btn`,title:`Open agent`,onClick:()=>d(!1),children:(0,V.jsx)(Fe,{size:12})}),(0,V.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-delete-btn`,title:`Delete agent`,onClick:()=>x(e.slug),children:(0,V.jsx)(i,{size:12})})]})]},e.slug))]}),(0,V.jsx)(`div`,{className:`chat-menu-divider`}),E?.updateAvailable?(0,V.jsxs)(`button`,{type:`button`,className:`chat-menu-version`,onClick:()=>{E.latest&&(M(E),d(!1),A(!0))},children:[(0,V.jsx)(We,{size:14}),(0,V.jsxs)(`span`,{className:`version-installed`,children:[`v`,E.installed,(0,V.jsx)(`span`,{className:`version-update-dot`})]})]}):(0,V.jsxs)(`div`,{className:`chat-menu-version chat-menu-version-passive`,children:[(0,V.jsx)(We,{size:14}),(0,V.jsxs)(`span`,{className:`version-installed`,children:[E?`v${E.installed}`:`…`,E&&!E.updateAvailable&&(0,V.jsx)(`span`,{className:`version-uptodate-dot`})]})]}),(0,V.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{d(!1),R.handleLogout(),z.setMessages([])},children:[(0,V.jsx)(me,{size:14}),` Log out`]})]})]})]}),(0,V.jsxs)(`div`,{className:`chat-content`,children:[(0,V.jsx)(NE,{messages:z.messages,isStreaming:z.isStreaming,elapsedSeconds:Oe.elapsedSeconds,sessionTurnStart:Oe.sessionTurnStart,expandAll:R.expandAll,setExpandAll:R.setExpandAll,conversationCompacted:z.conversationCompacted,isCompacting:z.isCompacting,setShowCompactConfirm:s,handleComponentSubmit:z.handleComponentSubmit,effectiveSubmitted:z.effectiveSubmitted,selectionMode:De.selectionMode,selectedItems:De.selectedItems,toggleSelectItem:De.toggleSelectItem,sessionKey:R.sessionKey,setLightboxSrc:n,messageQueue:z.messageQueue,messageQueueRef:z.messageQueueRef,setQueue:z.setQueue,sendMessage:z.sendMessage,appState:R.appState,onboardingComplete:R.onboardingComplete,onOpenArtefact:e=>{L({surface:`doc`,...e}),le(`chat-link`)}}),(0,V.jsx)(PE,{offer:z.topicChangeOffer,onFreshStart:z.handleTopicFreshStart,onContinue:z.handleTopicContinue,disabled:z.isStreaming}),(0,V.jsx)(qE,{selectionMode:De.selectionMode,selectedItems:De.selectedItems,copyToast:De.copyToast||null,exitSelection:De.exitSelection,enterSelection:De.enterSelection,copySelected:De.copySelected,showCopyToast:De.showCopyToast,input:z.input,setInput:z.setInput,inputRef:e,pendingFiles:ke.pendingFiles,setPendingFiles:ke.setPendingFiles,isDragOver:ke.isDragOver,attachError:ke.attachError,fileInputRef:ke.fileInputRef,addFiles:ke.addFiles,removeFile:ke.removeFile,onDragOver:ke.onDragOver,onDragLeave:ke.onDragLeave,onDrop:ke.onDrop,isStreaming:z.isStreaming,wasPaused:z.wasPaused,messages:z.messages,messageQueueRef:z.messageQueueRef,setQueue:z.setQueue,sendMessage:z.sendMessage,stopStreaming:z.stopStreaming,disconnecting:R.disconnecting,handleDisconnect:R.handleDisconnect,claudeInfo:R.claudeInfo,setClaudeInfo:R.setClaudeInfo,setShowClaudeInfo:a,conversationId:R.conversationId,sessionKey:R.sessionKey,onNewConversation:z.startNewConversation,newConversationDisabled:z.isStreaming||z.isCompacting,onOpenConversations:()=>{T(!0),Ae.refetch()},sidebarVisible:pe})]}),De.copyToast&&(0,V.jsx)(`span`,{className:`copy-toast${De.copyToast===`failed`?` copy-toast-failed`:``}`,children:De.copyToast===`copied`?`Copied`:`Copy failed`}),(0,V.jsx)(zE,{show:w,onClose:()=>T(!1),conversationsLoading:Ae.loading,conversationsError:Ae.error,conversationsList:Ae.sessions,setConversationsList:Ae.setSessions,sessionKey:R.sessionKey,isStreaming:z.isStreaming,resetConversation:z.resetConversation,setMessages:z.setMessages,setConversationId:R.setConversationId}),(0,V.jsx)(BE,{src:t,onClose:()=>n(null)}),(0,V.jsx)(VE,{show:o,onClose:()=>s(!1),onConfirm:z.handleCompactNow}),(0,V.jsx)(HE,{show:r,onClose:()=>{a(!1),R.setClaudeInfo(null)},claudeInfo:R.claudeInfo,messages:z.messages,sessionElapsed:Oe.sessionElapsed,conversationId:R.conversationId}),(0,V.jsx)(GE,{show:k,onClose:()=>{A(!1),Ce.current=!0},versionInfo:j,sessionKey:R.sessionKey,onUpgradeComplete:()=>O(null)}),N&&(0,V.jsx)(ZE,{onClose:()=>P(!1)})]}),(0,V.jsx)(mD,{}),(0,V.jsx)(lD,{}),(0,V.jsx)(iD,{selection:se,trigger:ce,sessionKey:R.sessionKey,onClose:()=>{L(null),le(null)},onArtefactSaved:(e,t,n)=>{de.current?.patchArtefact(e,{updatedAt:t,content:n})}})]})})}(0,ve.createRoot)(document.getElementById(`root`)).render((0,V.jsx)(gD,{}));
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>Maxy</title>
|
|
7
7
|
<link rel="icon" href="/favicon.ico">
|
|
8
|
-
<script type="module" crossorigin src="/assets/admin-
|
|
8
|
+
<script type="module" crossorigin src="/assets/admin-C0lKk6WM.js"></script>
|
|
9
9
|
<link rel="modulepreload" crossorigin href="/assets/chunk-DD-I1_y5.js">
|
|
10
10
|
<link rel="modulepreload" crossorigin href="/assets/jsx-runtime-DJER3a7U.js">
|
|
11
11
|
<link rel="modulepreload" crossorigin href="/assets/preload-helper-qlgyTAkD.js">
|