@rubytech/create-realagent 1.0.844 → 1.0.845

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.
@@ -15,7 +15,7 @@ import {
15
15
  sanitizeClientCorrId,
16
16
  streamActionEvents,
17
17
  vncLog
18
- } from "./chunk-LU2UG7KB.js";
18
+ } from "./chunk-NYGJNXX2.js";
19
19
  import {
20
20
  LOG_DIR
21
21
  } from "./chunk-H7AEWSE6.js";
@@ -349,4 +349,4 @@ ${JSON.stringify(u.input,null,2)}`,f=z.get(r),p=o?void 0:f??t;return(0,U.jsx)(GE
349
349
 
350
350
  ---
351
351
 
352
- `)}var ZE=`Cloudflare setup completed (actionId: `,QE=`{"_componentDone"`,$E=`{"_lifecycle"`;function eD(e){return typeof e!=`string`||e.length===0?!1:e.startsWith(QE)||e.startsWith($E)||e.startsWith(ZE)}function tD(e){let{row:t,surface:n,isStreaming:r,activeSessionKey:a,isLogsOpen:o,onLogsToggle:s,onRequestRename:l,onResume:u,onDelete:d,onSwitchPreFlush:f}=e,p=t.phase===`pre-flush`,m=p&&t.sessionKey!==null&&t.sessionKey!==a;return(0,U.jsxs)(`div`,{className:`conversations-row-actions`,"data-surface":n,children:[(0,U.jsx)(`button`,{type:`button`,className:`conversations-action conversations-logs`,title:p?`View pre-flush logs`:`View logs`,"aria-haspopup":`menu`,"aria-expanded":o,onClick:e=>{e.stopPropagation(),s(e.currentTarget)},children:(0,U.jsx)(c,{size:13})}),m&&f&&(0,U.jsx)(`button`,{type:`button`,className:`conversations-action conversations-play`,title:`Switch into this in-memory session`,disabled:r||!a,onClick:e=>{e.stopPropagation(),!(r||!a)&&f()},children:(0,U.jsx)(_,{size:13})}),!p&&t.conversationId&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`button`,{type:`button`,className:`conversations-action conversations-rename`,title:`Rename conversation`,onClick:e=>{e.stopPropagation(),l()},children:(0,U.jsx)(ct,{size:13})}),(0,U.jsx)(`button`,{type:`button`,className:`conversations-action conversations-play`,title:`Resume conversation`,disabled:r,onClick:e=>{e.stopPropagation(),!(r||!a)&&u()},children:(0,U.jsx)(_,{size:13})}),(0,U.jsx)(`button`,{type:`button`,className:`conversations-action conversations-delete`,title:`Delete conversation`,onClick:e=>{e.stopPropagation(),d()},children:(0,U.jsx)(i,{size:13})})]})]})}var nD=[{type:`stream`,label:`Stream`},{type:`error`,label:`Errors`},{type:`sse`,label:`SSE`}];function rD(e){let{state:t,popoverRef:n,surface:r,buildLogsUrl:i,onClose:a}=e;return t?(0,U.jsx)(`div`,{ref:n,className:`conversations-logs-popover`,role:`menu`,style:{top:t.top,right:t.right},"data-surface":r,children:nD.map(({type:e,label:n})=>(0,U.jsxs)(`a`,{role:`menuitem`,className:`conversations-logs-popover-item`,href:i({conversationId:t.conversationId,sessionKey:t.sessionKey},e),target:`_blank`,rel:`noopener noreferrer`,onClick:()=>{console.debug(`[admin-logs-popover] open-log`,{surface:r,conversationId:t.conversationId,sessionKey:t.sessionKey,type:e}),a()},children:[(0,U.jsx)(c,{size:12}),(0,U.jsx)(`span`,{children:n})]},e))}):null}function iD(e){let[t,n]=(0,H.useState)(null),r=(0,H.useRef)(null),i=(0,H.useCallback)(()=>n(null),[]),a=(0,H.useCallback)((e,t,r)=>{n(n=>{if(n?.rowId===e)return null;let i=r.getBoundingClientRect();return{rowId:e,conversationId:t.conversationId,sessionKey:t.sessionKey,top:i.bottom+4,right:Math.max(8,window.innerWidth-i.right)}})},[]);return(0,H.useEffect)(()=>{if(!t)return;function e(e){let t=e.target;t&&r.current?.contains(t)||t&&t.closest?.(`.conversations-logs`)||n(null)}function i(e){e.key===`Escape`&&n(null)}return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,i),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,i)}},[t]),(0,H.useEffect)(()=>{if(!t||!e?.current)return;let r=e.current,i=()=>n(null);return r.addEventListener(`scroll`,i,{passive:!0}),()=>r.removeEventListener(`scroll`,i)},[t,e]),{popover:t,popoverRef:r,toggle:a,close:i}}function aD(e,t){let[n,r]=(0,H.useState)(null),[i,a]=(0,H.useState)(null),[o,s]=(0,H.useState)(``),[c,l]=(0,H.useState)(!1),u=(0,H.useRef)(null);(0,H.useEffect)(()=>{i?.phase===`editing`&&(u.current?.focus(),u.current?.select())},[i]);let d=(0,H.useCallback)(()=>{r(null),a(null),s(``),l(!1)},[]);return{editingId:n,editState:i,editValue:o,setEditValue:s,confirming:c,editInputRef:u,requestSuggestion:(0,H.useCallback)(async t=>{if(e){d(),r(t),a({phase:`loading`});try{let n=await fetch(`/api/admin/sessions/${encodeURIComponent(t)}/label?session_key=${encodeURIComponent(e)}`,{method:`POST`});if(!n.ok){a({phase:`error`,reason:(await n.json().catch(()=>({}))).error||`Request failed`});return}let r=await n.json();r.label?(a({phase:`editing`}),s(r.label)):a({phase:`error`,reason:`Not enough message content to suggest a name`})}catch(e){console.error(`[admin-rename] label suggestion failed:`,e),a({phase:`error`,reason:e instanceof Error?e.message:String(e)})}}},[e,d]),confirmRename:(0,H.useCallback)(async n=>{let r=o.trim();if(!(!e||!r||c)){l(!0);try{let i=await fetch(`/api/admin/sessions/${encodeURIComponent(n)}/label`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({label:r,session_key:e})});if(!i.ok){a({phase:`error`,reason:(await i.json().catch(()=>({}))).error||`Rename failed`}),l(!1);return}t(e=>e.map(e=>e.conversationId===n?{...e,name:r}:e)),d()}catch(e){console.error(`[admin-rename] label rename failed:`,e),a({phase:`error`,reason:e instanceof Error?e.message:String(e)}),l(!1)}}},[e,o,c,t,d]),cancelEdit:d,isEditingRow:(0,H.useCallback)(e=>e!==null&&n===e,[n])}}var oD=`maxy-admin-session-key`;function sD(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 cD(e){let{show:t,onClose:n,conversationsLoading:r,conversationsError:i,conversationsList:a,setConversationsList:o,sessionKey:s,setSessionKey:c,isStreaming:l,resetConversation:u,setMessages:d,setConversationId:f}=e,[p,m]=(0,H.useState)(null),[g,_]=(0,H.useState)(null),v=(0,H.useRef)(null),y=(0,H.useRef)(null),b=(0,H.useRef)(null),{popover:x,popoverRef:S,toggle:C,close:w}=iD(b),T=aD(s,o);(0,H.useEffect)(()=>{t||(T.cancelEdit(),w(),m(null),_(null),v.current&&=(clearTimeout(v.current),null),y.current&&=(clearTimeout(y.current),null))},[t,T,w]);async function E(e){await I(e)?(m(e),_(null),v.current&&clearTimeout(v.current),v.current=setTimeout(()=>m(null),1500)):(_(e),m(null),y.current&&clearTimeout(y.current),y.current=setTimeout(()=>_(null),1500))}return t?(0,U.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,U.jsxs)(`div`,{className:`claude-info-modal conversations-modal`,onClick:e=>e.stopPropagation(),children:[(0,U.jsxs)(`div`,{className:`claude-info-header`,children:[(0,U.jsx)(Xe,{size:12}),`Conversations`,(0,U.jsx)(`button`,{className:`claude-info-close`,onClick:n,children:`✕`})]}),(0,U.jsxs)(`div`,{className:`conversations-list`,ref:b,children:[r&&(0,U.jsxs)(`div`,{className:`conversations-empty`,children:[(0,U.jsx)(ge,{size:14,className:`spin`}),` Loading…`]}),i&&(0,U.jsx)(`div`,{className:`conversations-empty conversations-error`,children:i}),!r&&!i&&a.length===0&&(0,U.jsx)(`div`,{className:`conversations-empty`,children:`No recent conversations`}),!r&&!i&&a.map(e=>{let t=e.conversationId??e.sessionKey??``,r=e.phase===`pre-flush`,i=T.isEditingRow(e.conversationId),a=i&&T.editState?.phase===`loading`,m=i&&T.editState?.phase===`editing`,_=i&&T.editState?.phase===`error`,v=e.conversationId??e.sessionKey??``;return(0,U.jsxs)(`div`,{className:`conversations-row${r?` conversations-row-pre-flush`:``}`,children:[(0,U.jsxs)(`div`,{className:`conversations-row-info`,children:[a&&(0,U.jsxs)(`span`,{className:`conversations-row-name conversations-edit-loading`,children:[(0,U.jsx)(ge,{size:12,className:`spin`}),` Generating suggestion…`]}),m&&(0,U.jsxs)(`div`,{className:`conversations-edit-inline`,children:[(0,U.jsx)(`input`,{ref:T.editInputRef,type:`text`,className:`conversations-edit-input`,value:T.editValue,onChange:e=>T.setEditValue(e.target.value),onKeyDown:t=>{t.key===`Enter`&&T.editValue.trim()&&T.confirmRename(e.conversationId),t.key===`Escape`&&T.cancelEdit()},maxLength:200}),(0,U.jsx)(`button`,{type:`button`,className:`conversations-action conversations-confirm`,title:`Confirm rename`,disabled:!T.editValue.trim()||T.confirming,onClick:()=>T.confirmRename(e.conversationId),children:T.confirming?(0,U.jsx)(ge,{size:13,className:`spin`}):(0,U.jsx)(h,{size:13})}),(0,U.jsx)(`button`,{type:`button`,className:`conversations-action conversations-cancel`,title:`Cancel`,onClick:T.cancelEdit,children:(0,U.jsx)(ie,{size:13})})]}),_&&(0,U.jsxs)(`div`,{className:`conversations-edit-inline`,children:[(0,U.jsx)(`span`,{className:`conversations-edit-error`,children:T.editState.reason}),(0,U.jsx)(`button`,{type:`button`,className:`conversations-action conversations-retry`,title:`Retry`,onClick:()=>T.requestSuggestion(e.conversationId),children:(0,U.jsx)(re,{size:13})}),(0,U.jsx)(`button`,{type:`button`,className:`conversations-action conversations-cancel`,title:`Cancel`,onClick:T.cancelEdit,children:(0,U.jsx)(ie,{size:13})})]}),!i&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`span`,{className:`conversations-row-name`,children:[e.name||(r?`session ${v}`:v),r&&(0,U.jsx)(`span`,{className:`conversations-row-phase-badge`,title:`Pre-flush — conversation not yet persisted`,children:`pre-flush`})]}),(0,U.jsxs)(`span`,{className:`conversations-row-meta`,children:[(0,U.jsx)(`button`,{type:`button`,className:`conversations-row-id${p===t?` copied`:``}${g===t?` copy-failed`:``}`,title:v,"aria-label":r?`Copy session key ${v}`:`Copy conversation id ${v}`,onClick:e=>{e.stopPropagation(),E(t)},children:p===t?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(h,{size:10}),` copied`]}):g===t?`copy failed`:v.slice(0,8)}),(0,U.jsxs)(`span`,{className:`conversations-row-time`,children:[(0,U.jsx)(ke,{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``}})()]})]})]})]}),!i&&(0,U.jsx)(tD,{row:e,surface:`conversations-modal`,rowId:t,isStreaming:l,activeSessionKey:s,isLogsOpen:x?.rowId===t,onLogsToggle:n=>{console.info(`[admin-session-identity] sessionKey=${(e.sessionKey??`null`).slice(0,8)} conversationId=${(e.conversationId??`null`).slice(0,8)} phase=${e.phase} surface=conversations-modal action=logs`),C(t,{conversationId:e.conversationId,sessionKey:e.sessionKey},n)},onRequestRename:()=>{e.conversationId&&(console.info(`[admin-session-identity] sessionKey=${(e.sessionKey??`null`).slice(0,8)} conversationId=${e.conversationId.slice(0,8)} phase=${e.phase} surface=conversations-modal action=rename`),T.requestSuggestion(e.conversationId))},onResume:()=>{!e.conversationId||!s||(console.info(`[admin-session-identity] sessionKey=${s.slice(0,8)} conversationId=${e.conversationId.slice(0,8)} phase=${e.phase} surface=conversations-modal action=resume`),n(),u(),fetch(`/api/admin/sessions/${encodeURIComponent(e.conversationId)}/resume?session_key=${encodeURIComponent(s)}`,{method:`POST`}).then(e=>e.ok?e.json():Promise.reject(Error(`Failed to resume conversation`))).then(e=>{e.conversationId&&f(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??(e.content?[{type:`text`,content:e.content}]:[]):void 0,...e.role===`user`&&e.attachments&&e.attachments.length>0?{attachments:e.attachments}:{},...e.role===`user`&&eD(e.content)?{hidden:!0}:{},timestamp:new Date(e.createdAt).getTime()||0,historical:!0,...e.messageId?{messageId:e.messageId}:{}}));t.length>0&&d(t)}).catch(e=>{console.error(`[chat] conversation resume failed:`,e),d([{role:`maxy`,events:[{type:`text`,content:`Could not load conversation history.`}],timestamp:Date.now()-1,historical:!0}])}))},onDelete:()=>{e.conversationId&&(console.info(`[admin-session-identity] sessionKey=${(e.sessionKey??`null`).slice(0,8)} conversationId=${e.conversationId.slice(0,8)} phase=${e.phase} surface=conversations-modal action=delete`),o(t=>t.filter(t=>t.conversationId!==e.conversationId)),s&&fetch(`/api/admin/sessions/${encodeURIComponent(e.conversationId)}?session_key=${encodeURIComponent(s)}`,{method:`DELETE`}).catch(e=>console.error(`[chat] conversation delete failed:`,e)))},onSwitchPreFlush:()=>{if(l||!s||!e.sessionKey)return;let t=e.sessionKey;console.info(`[admin-session-identity] sessionKey=${s.slice(0,8)} conversationId=null phase=${e.phase} surface=conversations-modal action=switch-pre-flush target=${t.slice(0,8)}`),n(),u(),d([]),fetch(`/api/admin/sessions/switch?session_key=${encodeURIComponent(s)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({target_session_key:t})}).then(e=>e.ok?e.json():Promise.reject(Error(`switch returned ${e.status}`))).then(e=>{try{sessionStorage.setItem(oD,e.session_key)}catch{}pe(e.session_key,`chat`),c(e.session_key),f(e.conversationId)}).catch(e=>{console.error(`[chat] pre-flush session switch failed:`,e),d([{role:`maxy`,events:[{type:`text`,content:`Could not switch into that session.`}],timestamp:Date.now()-1,historical:!0}])})}})]},t)})]}),(0,U.jsx)(rD,{state:x,popoverRef:S,surface:`conversations-modal`,buildLogsUrl:sD,onClose:w})]})}):null}function lD({src:e,onClose:t}){return e?(0,U.jsxs)(`div`,{className:`attachment-lightbox`,onClick:t,children:[(0,U.jsx)(`button`,{className:`attachment-lightbox-close`,onClick:t,"aria-label":`Close`,children:`×`}),(0,U.jsx)(`img`,{src:e,alt:`Attachment`,onClick:e=>e.stopPropagation()})]}):null}function uD({show:e,onClose:t,onConfirm:n}){return e?(0,U.jsx)(`div`,{className:`claude-info-overlay`,onClick:t,children:(0,U.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,U.jsxs)(`div`,{className:`claude-info-header`,children:[(0,U.jsx)(`span`,{children:`Compact conversation?`}),(0,U.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:`✕`})]}),(0,U.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,U.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,U.jsx)(w,{variant:`secondary`,size:`sm`,style:{background:`var(--accent)`,flex:1},onClick:()=>{t(),n()},children:`Yes, compact`}),(0,U.jsx)(w,{variant:`secondary`,size:`sm`,style:{flex:1},onClick:t,children:`No`})]})]})}):null}function dD(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,U.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,U.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,U.jsxs)(`div`,{className:`claude-info-header`,children:[(0,U.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`claude-info-icon`}),(0,U.jsx)(`span`,{children:`Claude Code`}),(0,U.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,U.jsxs)(`div`,{className:`claude-info-section`,children:[(0,U.jsxs)(`div`,{className:`claude-info-row`,children:[(0,U.jsx)(`span`,{className:`claude-info-label`,children:`Version`}),(0,U.jsx)(`span`,{className:`claude-info-value`,children:r?r.version:`…`})]}),(0,U.jsxs)(`div`,{className:`claude-info-row`,children:[(0,U.jsx)(`span`,{className:`claude-info-label`,children:`Email`}),(0,U.jsx)(`span`,{className:`claude-info-value`,children:r?.account?.email??`…`})]})]}),(p||d||f>0)&&(0,U.jsxs)(`div`,{className:`claude-info-section`,children:[p&&(0,U.jsxs)(`div`,{className:`claude-info-row`,children:[(0,U.jsx)(`span`,{className:`claude-info-label`,children:`Plan`}),(0,U.jsx)(`span`,{className:`claude-info-value`,style:{textTransform:`capitalize`},children:p})]}),d&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`div`,{className:`claude-info-row`,children:[(0,U.jsx)(`span`,{className:`claude-info-label`,children:`Usage`}),(0,U.jsxs)(`span`,{className:`claude-info-value`,children:[Math.round(d.utilization*100),`%`]})]}),(0,U.jsxs)(`div`,{className:`claude-info-row`,children:[(0,U.jsx)(`span`,{className:`claude-info-label`,children:`Resets in`}),(0,U.jsx)(`span`,{className:`claude-info-value`,children:m(d.resetsAt)})]}),d.isUsingOverage&&(0,U.jsxs)(`div`,{className:`claude-info-row`,children:[(0,U.jsx)(`span`,{className:`claude-info-label`,children:`Overage`}),(0,U.jsx)(`span`,{className:`claude-info-value`,children:`Active`})]})]}),f>0&&(0,U.jsxs)(`div`,{className:`claude-info-row`,children:[(0,U.jsx)(`span`,{className:`claude-info-label`,children:`Session cost`}),(0,U.jsxs)(`span`,{className:`claude-info-value`,children:[`$`,f<.01?f.toFixed(4):f.toFixed(2)]})]})]}),(0,U.jsxs)(`div`,{className:`claude-info-section`,children:[(0,U.jsxs)(`div`,{className:`claude-info-row`,children:[(0,U.jsx)(`span`,{className:`claude-info-label`,children:`Model`}),(0,U.jsx)(`span`,{className:`claude-info-value`,children:r?.model??`…`})]}),(0,U.jsxs)(`div`,{className:`claude-info-row`,children:[(0,U.jsx)(`span`,{className:`claude-info-label`,children:`Context used`}),(0,U.jsx)(`span`,{className:`claude-info-value`,children:l>0?`${l}%`:`—`})]}),(0,U.jsxs)(`div`,{className:`claude-info-row`,children:[(0,U.jsx)(`span`,{className:`claude-info-label`,children:`Tokens`}),(0,U.jsx)(`span`,{className:`claude-info-value`,children:u>0?St(u):`—`})]}),(0,U.jsxs)(`div`,{className:`claude-info-row`,children:[(0,U.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,U.jsx)(`span`,{className:`claude-info-value`,children:xt(a)})]}),o&&(0,U.jsxs)(`div`,{className:`claude-info-row`,children:[(0,U.jsx)(`span`,{className:`claude-info-label`,children:`Conversation`}),(0,U.jsx)(`span`,{className:`claude-info-value`,style:{fontFamily:`monospace`,fontSize:10},children:o.slice(0,8)})]})]})]})})}var fD=5e3,pD={atPhase:8};function mD({show:e,onClose:t,versionInfo:n,sessionKey:r,onUpgradeComplete:i}){let[a,o]=(0,H.useState)(`prompt`),[s,c]=(0,H.useState)(``),[l,u]=(0,H.useState)(!1),[d,f]=(0,H.useState)(null),[p,m]=(0,H.useState)(null),[h,g]=(0,H.useState)(null),_=(0,H.useRef)(null),v=n?.latest??null,y=(0,H.useCallback)(()=>{_.current&&=(clearInterval(_.current),null)},[]);(0,H.useEffect)(()=>{e||(y(),o(`prompt`),c(``),u(!1),f(null),m(null),g(null))},[e,y]),(0,H.useEffect)(()=>y,[y]),(0,H.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{}},fD),y},[e,a,v,i,y]);let b=(0,H.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,U.jsx)(`div`,{className:`claude-info-overlay`,onClick:()=>{(a===`prompt`||a===`succeeded`||a===`launch-failed`)&&t()},children:(0,U.jsxs)(`div`,{className:`claude-info-modal update-modal`,onClick:e=>e.stopPropagation(),children:[(0,U.jsxs)(`div`,{className:`claude-info-header`,children:[(0,U.jsx)(oe,{size:12}),`Software Update`,(0,U.jsx)(`button`,{className:`claude-info-close`,onClick:t,children:`✕`})]}),(0,U.jsxs)(`div`,{className:`update-modal-body`,children:[(0,U.jsxs)(`div`,{className:`update-modal-versions`,children:[(0,U.jsxs)(`div`,{className:`claude-info-row`,children:[(0,U.jsx)(`span`,{className:`claude-info-label`,children:`Installed`}),(0,U.jsxs)(`span`,{className:`claude-info-value`,children:[`v`,n?.installed??`…`]})]}),(0,U.jsxs)(`div`,{className:`claude-info-row`,children:[(0,U.jsx)(`span`,{className:`claude-info-label`,children:`Available`}),(0,U.jsxs)(`span`,{className:`claude-info-value update-version-new`,children:[`v`,v??`…`]})]})]}),(a===`prompt`||a===`priming`||a===`launch-failed`)&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`div`,{className:`form-input__field`,style:{marginTop:12},children:[(0,U.jsx)(`label`,{className:`form-input__label`,htmlFor:`upgrade-sudo`,children:`Device password`}),(0,U.jsxs)(`div`,{className:`tunnel-route__row`,children:[(0,U.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,U.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,U.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,U.jsx)(`div`,{className:`tunnel-route__error`,children:d}),p&&(0,U.jsx)(`div`,{className:`tunnel-route__error`,role:`alert`,children:p})]}),(0,U.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,U.jsx)(`div`,{className:`update-modal-terminal`,style:{height:360,marginTop:10},children:(0,U.jsx)(yE,{actionId:h,sessionKey:r,selfRestart:pD})}),a===`succeeded`&&(0,U.jsxs)(`div`,{className:`update-modal-result`,children:[(0,U.jsx)(B,{size:14,className:`update-success-icon`}),(0,U.jsxs)(`span`,{children:[`Upgraded to v`,v,` — reloading…`]})]})]})]})}):null}function hD(e){let{conversationId:t,sessionKey:n,disconnecting:r,onOpenConversations:i,handleDisconnect:a,onAfterAction:o}=e,s=!t&&!n;return(0,U.jsxs)(`div`,{className:`chat-actions-menu`,children:[(0,U.jsxs)(`button`,{type:`button`,className:`chat-action`,onClick:()=>{o(),i()},children:[(0,U.jsx)(Xe,{size:14}),(0,U.jsx)(`span`,{className:`action-label`,children:`Conversations`})]}),(0,U.jsxs)(`button`,{type:`button`,className:`chat-action`,disabled:r,onClick:async()=>{o(),await a()},children:[r?(0,U.jsx)(ge,{size:14,className:`animate-spin`}):(0,U.jsx)(Se,{size:14}),(0,U.jsx)(`span`,{className:`action-label`,children:r?`Disconnecting...`:`Disconnect Claude`})]}),(0,U.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=`${sD({conversationId:t,sessionKey:n},`stream`)}&download=1`,e.click()},children:[(0,U.jsx)(ut,{size:14}),(0,U.jsx)(`span`,{className:`action-label`,children:`Stream log`})]})]})}function gD(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:L,stopStreaming:re,disconnecting:ie,handleDisconnect:ae,claudeInfo:R,setClaudeInfo:z,setShowClaudeInfo:oe,conversationId:se,sessionKey:ce,onNewConversation:le,newConversationDisabled:ue,onOpenConversations:de,sidebarVisible:fe}=e,[pe,me]=(0,H.useState)(!1),he=(0,H.useRef)(null),[ge,_e]=(0,H.useState)(!1),ve=(0,H.useRef)(null),ye=(0,H.useRef)(!1),be=ee(),xe=be.state===`recording`||be.state===`paused`||be.state===`sending`,Se=!xe&&!M&&!l.trim()&&g.length===0;async function Ce(){let e=await be.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}L(`[Voice note]`,[n])}return(0,H.useEffect)(()=>{t||_e(!1)},[t]),(0,H.useEffect)(()=>{if(!ge)return;let e=e=>{e.target.closest(`.selection-copy-wrap`)||_e(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[ge]),(0,H.useEffect)(()=>{if(!pe)return;let e=e=>{if(e.key===`Escape`){me(!1);return}if(e.key===`Tab`&&he.current){let t=he.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=>{he.current&&!he.current.contains(e.target)&&me(!1)};return document.addEventListener(`keydown`,e),document.addEventListener(`mousedown`,t),()=>{document.removeEventListener(`keydown`,e),document.removeEventListener(`mousedown`,t)}},[pe]),t?(0,U.jsx)(`div`,{className:`chat-input-area`,children:(0,U.jsxs)(`div`,{className:`selection-bar`,children:[(0,U.jsxs)(`span`,{className:`selection-count`,children:[n.size,` Selected`]}),(0,U.jsxs)(`div`,{className:`selection-copy-wrap`,children:[(0,U.jsxs)(`button`,{type:`button`,className:`selection-copy`,onPointerDown:()=>{if(ge){_e(!1);return}ye.current=!1,ve.current=setTimeout(()=>{ye.current=!0,_e(!0),ve.current=null},500)},onPointerUp:()=>{ve.current!==null&&(clearTimeout(ve.current),ve.current=null)},onPointerLeave:()=>{ve.current!==null&&(clearTimeout(ve.current),ve.current=null)},onPointerCancel:()=>{ve.current!==null&&(clearTimeout(ve.current),ve.current=null)},onClick:async()=>{ye.current||await o(e=>YE(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,U.jsx)(f,{size:18}),(0,U.jsx)(`span`,{children:`Copy`})]}),ge&&(0,U.jsx)(`div`,{className:`copy-menu`,children:[[`all`,`All events`],[`text`,`Text messages only`],[`non-text`,`Non-text only`]].map(([e,t])=>(0,U.jsx)(`button`,{type:`button`,className:`copy-menu-item`,onClick:async()=>{let t=XE(P,e);t&&s(await I(t)),i()},children:t},e))})]}),(0,U.jsx)(`button`,{type:`button`,className:`selection-cancel`,onClick:i,children:`Cancel`})]})}):(0,U.jsxs)(`div`,{className:`chat-input-area`,children:[(0,U.jsx)(`input`,{ref:x,type:`file`,multiple:!0,accept:wt,style:{display:`none`},onChange:e=>{e.target.files&&S([...e.target.files]),e.target.value=``}}),g.length>0&&(0,U.jsx)(`div`,{className:`attachment-strip`,children:g.map((e,t)=>(0,U.jsxs)(`div`,{className:`attachment-chip`,children:[e.type.startsWith(`image/`)?(0,U.jsx)(`img`,{src:URL.createObjectURL(e),alt:e.name,className:`attachment-chip-thumb`}):e.type===`application/pdf`?(0,U.jsx)(c,{size:14}):(0,U.jsx)(E,{size:14}),(0,U.jsx)(`span`,{className:`attachment-chip-name`,children:e.name}),(0,U.jsx)(`button`,{type:`button`,className:`attachment-chip-remove`,onClick:()=>C(t),"aria-label":`Remove ${e.name}`,children:`×`})]},t))}),b&&(0,U.jsx)(`p`,{className:`attach-error`,children:b}),be.state===`error`&&be.errorMessage&&(0,U.jsxs)(`p`,{className:`voice-error`,role:`alert`,children:[(0,U.jsx)(m,{size:14}),be.errorMessage]}),(0,U.jsx)(T,{inputRef:h}),xe?(0,U.jsx)(`div`,{className:`chat-form voice-active`,children:(0,U.jsx)(A,{state:be.state,elapsedSeconds:be.elapsedSeconds,waveform:be.waveform,onTogglePause:be.togglePause,onDiscard:be.discard,onSend:Ce})}):(0,U.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}L(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,U.jsx)(w,{variant:`icon`,type:`button`,onClick:()=>x.current?.click(),"aria-label":`Attach file`,children:(0,U.jsx)(u,{size:14})}),(0,U.jsx)(N,{ref:h,value:l,onChange:p}),j?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(w,{variant:`send`,type:`button`,onClick:()=>re(!0),"aria-label":`Pause`,style:{background:`var(--text-secondary)`},children:(0,U.jsx)(d,{size:14})}),(0,U.jsx)(w,{variant:`send`,type:`button`,onClick:()=>re(!1),"aria-label":`Stop`,style:{background:`var(--danger)`},children:(0,U.jsx)(pt,{size:14})})]}):Se?(0,U.jsx)(w,{variant:`send`,type:`button`,onClick:be.start,"aria-label":`Record voice note`,children:(0,U.jsx)(m,{size:14})}):(0,U.jsx)(w,{variant:`send`,type:`submit`,disabled:!l.trim()&&g.length===0&&!M,"aria-label":`Send message`,children:M?(0,U.jsx)(_,{size:14}):(0,U.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,U.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,U.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,U.jsxs)(`div`,{className:`chat-actions`,ref:he,children:[(0,U.jsx)(`button`,{type:`button`,className:`chat-action-icon`,title:`New conversation`,"aria-label":`New conversation`,disabled:ue,onClick:le,children:(0,U.jsx)(Ve,{size:16})}),(0,U.jsx)(`button`,{type:`button`,className:`chat-action-icon`,title:`Select messages`,"aria-label":`Select messages`,onClick:a,children:(0,U.jsx)(ne,{size:16})}),!fe&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`button`,{className:`burger-trigger`,onClick:()=>me(e=>!e),"aria-expanded":pe,"aria-haspopup":`true`,"aria-label":`Conversation actions`,children:(0,U.jsx)(Pe,{size:16})}),(0,U.jsx)(`div`,{className:`actions-menu-items${pe?` actions-menu-open`:``}`,children:(0,U.jsx)(hD,{conversationId:se,sessionKey:ce,disconnecting:ie,onOpenConversations:de,handleDisconnect:ae,onAfterAction:()=>me(!1)})})]}),(0,U.jsxs)(`div`,{className:`powered-by`,onClick:async()=>{if(oe(!0),!R){let e=await fetch(`/api/admin/claude-info`);e.ok&&z(await e.json())}},children:[(0,U.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`powered-by-icon`}),(0,U.jsx)(`span`,{children:`Powered by Claude Code`})]})]})]})}var _D=`maxy-vnc-overlay-popout`;function vD(e){let[t,n]=(0,H.useState)(!1),r=(0,H.useRef)(null),i=(0,H.useRef)(null),a=(0,H.useCallback)(()=>{i.current&&=(clearInterval(i.current),null),r.current&&!r.current.closed&&r.current.close(),r.current=null,n(!1)},[]),o=(0,H.useCallback)(()=>{let t=`/vnc-popout.html?title=${encodeURIComponent(C.productName)}`,o=window.open(t,_D,`width=1024,height=768`);o&&(r.current=o,n(!0),i.current=setInterval(()=>{r.current?.closed&&(a(),e?.())},500))},[a,e]);return(0,H.useEffect)(()=>()=>a(),[a]),{poppedOut:t,popout:o,cleanupPopout:a}}var yD=(0,H.forwardRef)(function({onClose:e},t){bt();let{poppedOut:n,popout:r,cleanupPopout:i}=vD(e);return(0,H.useImperativeHandle)(t,()=>({popout:r}),[r]),n?(0,U.jsxs)(`div`,{className:`browser-overlay-popout`,children:[(0,U.jsx)(D,{className:`browser-viewer__icon`}),(0,U.jsx)(`span`,{className:`browser-viewer__title`,children:C.productName}),(0,U.jsx)(`span`,{className:`browser-viewer__popout-label`,children:`Popped out`}),(0,U.jsx)(w,{variant:`ghost`,size:`sm`,icon:rt,onClick:()=>i(),"aria-label":`Pop back in`}),e&&(0,U.jsx)(w,{variant:`ghost`,size:`sm`,icon:ie,onClick:()=>{i(),e()},"aria-label":`Close`})]}):(0,U.jsx)(`iframe`,{src:`/vnc-viewer.html`,className:`browser-surface__iframe`,title:C.productName})});function bD({onClose:e}){bt();let{poppedOut:t,popout:n,cleanupPopout:r}=vD(e),i=(0,H.useCallback)(()=>{r(),e()},[r,e]);(0,H.useEffect)(()=>{if(t)return;let e=e=>{e.key===`Escape`&&i()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,i]);let a=an({handlePopout:n,disabled:t});return t?(0,U.jsxs)(`div`,{className:`browser-overlay-popout`,children:[(0,U.jsx)(D,{className:`browser-viewer__icon`}),(0,U.jsx)(`span`,{className:`browser-viewer__title`,children:C.productName}),(0,U.jsx)(`span`,{className:`browser-viewer__popout-label`,children:`Popped out`}),(0,U.jsx)(w,{variant:`ghost`,size:`sm`,icon:rt,onClick:()=>{r()},"aria-label":`Pop back in`}),(0,U.jsx)(w,{variant:`ghost`,size:`sm`,icon:ie,onClick:i,"aria-label":`Close`})]}):(0,U.jsxs)(`div`,{className:`browser-viewer-fullscreen`,children:[(0,U.jsxs)(`div`,{className:`browser-viewer-fullscreen__bar`,...a,children:[(0,U.jsx)(D,{className:`browser-viewer__icon`}),(0,U.jsx)(`span`,{className:`browser-viewer-fullscreen__title`,children:C.productName}),(0,U.jsxs)(`div`,{className:`browser-viewer-fullscreen__actions`,children:[(0,U.jsx)(w,{variant:`ghost`,size:`sm`,icon:Fe,onClick:n,"aria-label":`Pop out`}),(0,U.jsx)(w,{variant:`ghost`,size:`sm`,icon:ie,onClick:i,"aria-label":`Close`})]})]}),(0,U.jsx)(`iframe`,{src:`/vnc-viewer.html`,className:`browser-viewer-fullscreen__iframe`,title:C.productName})]})}var xD=`maxy-admin-session-key`,SD=(0,H.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:g,onSelectProjects:_,onSelectPeople:v,onSelectTasks:y,onSelectAgents:b,onCloseMobileDrawer:x,collapsed:S,onToggleCollapsed:w,actions:T,recentsActions:E}=e;(0,H.useEffect)(()=>{f()},[f]);let D=(0,H.useRef)(null),{popover:O,popoverRef:k,toggle:A,close:j}=iD(D),M=aD(r,E.setSessions),N=C.productName,P=typeof o==`string`?o:o===null?`name unavailable`:n||N,ee=(P.trim().charAt(0)||`?`).toUpperCase(),[te,F]=(0,H.useState)(`all`),ne=(0,H.useMemo)(()=>l.filter(e=>e.name).filter(e=>te===`all`?!0:(e.channel??`webchat`)===te),[l,te]),I=ne.length,L=i??r,[R,z]=(0,H.useState)(`chat`),[oe,se]=(0,H.useState)([]),[ce,le]=(0,H.useState)(!1),[ue,de]=(0,H.useState)(null),[fe,me]=(0,H.useState)(!1);(0,H.useImperativeHandle)(t,()=>({patchArtefact(e,t){se(n=>n.map(n=>n.id===e?{...n,...t}:n))}}),[]);let[he,_e]=(0,H.useState)(!1),ve=(0,H.useRef)(null);(0,H.useEffect)(()=>{if(!he)return;function e(e){ve.current&&!ve.current.contains(e.target)&&_e(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[he]);let ye=(0,H.useCallback)(async()=>{if(r){me(!0),de(null);try{let e=await fetch(`/api/admin/sidebar-artefacts?session_key=${encodeURIComponent(r)}`);if(!e.ok)throw Error(`status ${e.status}`);se((await e.json()).artefacts??[]),le(!0)}catch(e){let t=e instanceof Error?e.message:String(e);de(`Failed to load artefacts: ${t}`),console.error(`[admin-ui] sidebar-artefacts fetch failed: ${t}`)}finally{me(!1)}}},[r]),be=()=>{z(`chat`),console.info(`[admin-ui] sidebar-nav surface=chat count=${I}`)},xe=()=>{z(`artefacts`),console.info(`[admin-ui] sidebar-nav surface=artefacts count=${ce?oe.length:0}`),ce||ye()},Se=S?24:16,Te=R===`chat`?`Recents`:`Artefacts`,Ee=R===`chat`?u?`…`:String(I):fe?`…`:String(oe.length),B=R===`chat`?u:fe,De=()=>{R===`chat`?p():ye(),console.info(`[admin-ui] sidebar-refresh surface=${R}`)};return(0,U.jsxs)(`aside`,{className:`side`,children:[(0,U.jsx)(`div`,{className:`side-head`,children:(0,U.jsx)(`button`,{className:`icon-btn side-head-toggle`,title:S?`Expand sidebar`:`Collapse sidebar`,type:`button`,"aria-label":S?`Expand sidebar`:`Collapse sidebar`,onClick:w,children:S?(0,U.jsx)(st,{size:28}):(0,U.jsx)(ot,{size:28})})}),(0,U.jsxs)(`nav`,{className:`side-nav`,children:[(0,U.jsxs)(`button`,{type:`button`,className:`nav-row${R===`chat`?` active`:``}`,onClick:be,children:[(0,U.jsx)(nt,{size:Se}),(0,U.jsx)(`span`,{className:`label`,children:`Chat`}),(0,U.jsx)(`span`,{className:`kbd`})]}),(0,U.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=people`),v(),x()},children:[(0,U.jsx)(_t,{size:Se}),(0,U.jsx)(`span`,{className:`label`,children:`People`}),(0,U.jsx)(`span`,{className:`kbd`})]}),(0,U.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=agents`),b(),x()},children:[(0,U.jsx)(Ce,{size:Se}),(0,U.jsx)(`span`,{className:`label`,children:`Agents`}),(0,U.jsx)(`span`,{className:`kbd`})]}),(0,U.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=projects`),_(),x()},children:[(0,U.jsx)(we,{size:Se}),(0,U.jsx)(`span`,{className:`label`,children:`Projects`}),(0,U.jsx)(`span`,{className:`kbd`})]}),(0,U.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=tasks`),y(),x()},children:[(0,U.jsx)(Ye,{size:Se}),(0,U.jsx)(`span`,{className:`label`,children:`Tasks`}),(0,U.jsx)(`span`,{className:`kbd`})]}),(0,U.jsxs)(`button`,{type:`button`,className:`nav-row${R===`artefacts`?` active`:``}`,onClick:xe,children:[(0,U.jsx)(c,{size:Se}),(0,U.jsx)(`span`,{className:`label`,children:`Artefacts`}),(0,U.jsx)(`span`,{className:`kbd`})]})]}),(0,U.jsxs)(`div`,{className:`side-list`,ref:D,children:[(0,U.jsxs)(`div`,{className:`group-head`,children:[(0,U.jsx)(`span`,{children:Te}),(0,U.jsxs)(`span`,{className:`group-head-meta`,children:[(0,U.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh ${Te.toLowerCase()}`,"aria-label":`Refresh ${Te.toLowerCase()}`,onClick:De,disabled:B,children:(0,U.jsx)(ae,{size:12,className:B?`spinning`:void 0})}),(0,U.jsx)(`span`,{children:Ee})]})]}),R===`chat`&&(0,U.jsxs)(U.Fragment,{children:[d&&(0,U.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:d}),(0,U.jsxs)(en,{className:`conv-channel-filter`,value:te,onChange:e=>{let t=e.target.value;F(t),console.info(`[admin-ui] sidebar-channel-filter set value=${t}`)},"aria-label":`Filter conversations by channel`,children:[(0,U.jsx)(`option`,{value:`all`,children:`All channels`}),(0,U.jsx)(`option`,{value:`webchat`,children:`Web`})]}),ne.map(e=>{let t=e.conversationId??e.sessionKey??``,n=t!==``&&t===L,i=e.channel??`webchat`,a=e.phase===`pre-flush`,o=M.isEditingRow(e.conversationId),s=o&&M.editState?.phase===`loading`,c=o&&M.editState?.phase===`editing`,l=o&&M.editState?.phase===`error`,u=t=>{let n=e.sessionKey?e.sessionKey.slice(0,8):`null`,r=e.conversationId?e.conversationId.slice(0,8):`null`;console.info(`[admin-session-identity] sessionKey=${n} conversationId=${r} phase=${e.phase} surface=sidebar-recents action=${t}`)};return(0,U.jsxs)(`div`,{className:`conv${n?` active`:``}${a?` conv-pre-flush`:``}${o?` conv-editing`:``}`,children:[!o&&(0,U.jsxs)(`button`,{type:`button`,className:`conv-name-button`,onClick:()=>{u(`select`),m(e),x()},children:[i===`whatsapp`&&(0,U.jsx)($e,{size:12,className:`conv-channel-icon`,"aria-label":`WhatsApp`}),(0,U.jsx)(`span`,{className:`conv-name`,children:e.name??`(untitled)`})]}),s&&(0,U.jsxs)(`span`,{className:`conversations-row-name conversations-edit-loading conv-edit-loading`,children:[(0,U.jsx)(ge,{size:12,className:`spin`}),` Generating suggestion…`]}),c&&(0,U.jsxs)(`div`,{className:`conversations-edit-inline conv-edit-inline`,children:[(0,U.jsx)(`input`,{ref:M.editInputRef,type:`text`,className:`conversations-edit-input`,value:M.editValue,onChange:e=>M.setEditValue(e.target.value),onKeyDown:t=>{t.key===`Enter`&&M.editValue.trim()&&e.conversationId&&M.confirmRename(e.conversationId),t.key===`Escape`&&M.cancelEdit()},maxLength:200}),(0,U.jsx)(`button`,{type:`button`,className:`conversations-action conversations-confirm`,title:`Confirm rename`,disabled:!M.editValue.trim()||M.confirming,onClick:()=>e.conversationId&&M.confirmRename(e.conversationId),children:M.confirming?(0,U.jsx)(ge,{size:13,className:`spin`}):(0,U.jsx)(h,{size:13})}),(0,U.jsx)(`button`,{type:`button`,className:`conversations-action conversations-cancel`,title:`Cancel`,onClick:M.cancelEdit,children:(0,U.jsx)(ie,{size:13})})]}),l&&(0,U.jsxs)(`div`,{className:`conversations-edit-inline conv-edit-inline`,children:[(0,U.jsx)(`span`,{className:`conversations-edit-error`,children:M.editState.reason}),(0,U.jsx)(`button`,{type:`button`,className:`conversations-action conversations-retry`,title:`Retry`,onClick:()=>e.conversationId&&M.requestSuggestion(e.conversationId),children:(0,U.jsx)(re,{size:13})}),(0,U.jsx)(`button`,{type:`button`,className:`conversations-action conversations-cancel`,title:`Cancel`,onClick:M.cancelEdit,children:(0,U.jsx)(ie,{size:13})})]}),!o&&(0,U.jsx)(tD,{row:e,surface:`sidebar-recents`,rowId:t,isStreaming:E.isStreaming,activeSessionKey:r,isLogsOpen:O?.rowId===t,onLogsToggle:n=>{u(`logs`),A(t,{conversationId:e.conversationId,sessionKey:e.sessionKey},n)},onRequestRename:()=>{e.conversationId&&(u(`rename`),M.requestSuggestion(e.conversationId))},onResume:()=>{!e.conversationId||E.isStreaming||(u(`resume`),m(e),x())},onDelete:()=>{if(!e.conversationId)return;u(`delete`);let t=e.conversationId;E.setSessions(e=>e.filter(e=>e.conversationId!==t)),r&&fetch(`/api/admin/sessions/${encodeURIComponent(t)}?session_key=${encodeURIComponent(r)}`,{method:`DELETE`}).catch(e=>console.error(`[chat] conversation delete failed:`,e))},onSwitchPreFlush:()=>{if(E.isStreaming||!r||!e.sessionKey)return;let t=e.sessionKey;u(`switch-pre-flush target=${t.slice(0,8)}`),E.resetConversation(),E.setMessages([]),fetch(`/api/admin/sessions/switch?session_key=${encodeURIComponent(r)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({target_session_key:t})}).then(e=>e.ok?e.json():Promise.reject(Error(`switch returned ${e.status}`))).then(e=>{try{sessionStorage.setItem(xD,e.session_key)}catch{}pe(e.session_key,`chat`),E.setSessionKey(e.session_key),E.setConversationId(e.conversationId)}).catch(e=>{console.error(`[chat] pre-flush session switch failed:`,e),E.setMessages([{role:`maxy`,events:[{type:`text`,content:`Could not switch into that session.`}],timestamp:Date.now()-1,historical:!0}])})}})]},t===``?e.updatedAt:t)})]}),R===`artefacts`&&(0,U.jsxs)(U.Fragment,{children:[ue&&(0,U.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:ue}),ce&&!ue&&oe.length===0&&(0,U.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No artefacts yet`}),oe.map(e=>(0,U.jsxs)(`button`,{type:`button`,className:`conv`,onClick:()=>{g({docId:e.id,name:e.name,content:e.content,editable:e.editable,mimeType:e.mimeType,skipReason:e.skipReason},`sidebar-artefacts`),x()},children:[(0,U.jsx)(`span`,{className:`conv-name`,children:e.name}),(0,U.jsx)(`span`,{className:`conv-kind`,"data-kind":e.kind===`agent-template`?`agent`:`doc`,children:e.kind===`agent-template`?`agent`:`doc`})]},e.id))]}),(0,U.jsx)(rD,{state:O,popoverRef:k,surface:`sidebar-recents`,buildLogsUrl:sD,onClose:j})]}),(0,U.jsxs)(`div`,{className:`side-foot`,ref:ve,children:[(0,U.jsx)(`div`,{className:`avatar`,children:s?(0,U.jsx)(`img`,{src:s,alt:P}):ee}),(0,U.jsxs)(`div`,{className:`who`,children:[(0,U.jsx)(`span`,{className:`name`,children:P}),(0,U.jsx)(`span`,{className:`role`,children:a??`operator`})]}),(0,U.jsx)(`button`,{className:`icon-btn side-foot-actions-trigger`,title:`Conversation actions`,type:`button`,"aria-label":`Conversation actions`,"aria-haspopup":`true`,"aria-expanded":he,onClick:()=>_e(e=>!e),children:(0,U.jsx)(Pe,{size:Se})}),he&&(0,U.jsx)(`div`,{className:`side-foot-actions-popover`,children:(0,U.jsx)(hD,{...T,onAfterAction:()=>_e(!1)})})]})]})}),CD=()=>{},wD={"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,U.jsxs)(`div`,{className:`art-skip-banner`,role:`status`,children:[(0,U.jsx)(Re,{size:14}),(0,U.jsx)(`span`,{children:wD[e]})]})}function ED({src:e,name:t,docId:n}){let[r,i]=(0,H.useState)(!1),a=(0,H.useRef)(null),o=(0,H.useRef)(!1),s=(0,H.useRef)(!1),l=(0,H.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,H.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,U.jsxs)(`a`,{className:`art-pdf-fallback`,href:e,download:t,children:[(0,U.jsx)(c,{size:20}),(0,U.jsxs)(`div`,{className:`art-pdf-fallback-text`,children:[(0,U.jsx)(`div`,{className:`art-pdf-fallback-name`,children:t}),(0,U.jsx)(`div`,{className:`art-pdf-fallback-hint`,children:`Your browser can't display this PDF inline. Click to download.`})]}),(0,U.jsx)(oe,{size:16})]}):(0,U.jsx)(`iframe`,{ref:a,className:`art-pdf`,src:e,title:t,"aria-label":`PDF preview of ${t}`,onLoad:u,onError:()=>l(`onerror`)})}var DD={browser:`Browser`,data:`Data`,graph:`Graph`};function OD({selection:e,trigger:t,sessionKey:n,onClose:r,onArtefactSaved:i,onSwapToGraph:a}){let o=e!==null,s=e?.surface??null,c=(0,H.useRef)(null),l=(0,H.useRef)(null),[u,d]=(0,H.useState)(null),p=e?.surface===`doc`?e.docId:null,m=(0,H.useCallback)(e=>{if(!n||!p)return;let t={};try{t=JSON.parse(e)}catch{return}t.action!==`save`||typeof t.content!=`string`||(d(null),fetch(`/api/admin/sidebar-artefact-save?session_key=${encodeURIComponent(n)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({id:p,content:t.content})}).then(async e=>{if(!e.ok){let t=(await e.json().catch(()=>({}))).error??`status ${e.status}`;d(`Save failed: ${t}`),console.error(`[admin-ui] artefact-save-failed docId=${p} status=${e.status} error="${t}"`);return}let n=await e.json();i?.(p,n.updatedAt,t.content)}).catch(e=>{let t=e instanceof Error?e.message:String(e);d(`Save failed: ${t}`),console.error(`[admin-ui] artefact-save-failed docId=${p} error="${t}"`)}))},[n,p,i]);(0,H.useEffect)(()=>{d(null)},[p]),(0,H.useEffect)(()=>{let n=e?.surface===`doc`?e.docId:null,r=e?.surface===`graph`?e.focusNodeId??null:null,i=e?.surface??null,a=i===null?`closed`:`${i}:${n??`none`}:${r??`none`}`;if(a===c.current)return;let s=o?`open`:`closed`,l=o?t??`chat-link`:`toolbar-close`,u=i??c.current?.split(`:`)[0]??`doc`;console.info(`[admin-ui] artefact-pane state=${s} docId=${n??`none`} trigger=${l} surface=${u}`),c.current=a},[e,t,o]);let h=e?.surface===`doc`,g=h?(e.tag||e.name.split(`.`).pop()||`doc`).toUpperCase().slice(0,6):``,_=h?e.revision||`rev 1`:`live`,v=e&&e.surface!==`doc`?DD[e.surface]:``,y=h?e.name:v;return(0,U.jsxs)(`aside`,{className:`artefact`,"data-open":o,"data-surface":s??`none`,children:[(0,U.jsxs)(`div`,{className:`art-head`,children:[(0,U.jsxs)(`div`,{className:`left`,children:[!h&&s===`browser`&&(0,U.jsx)(D,{size:14,className:`art-head-surface-icon`}),!h&&s===`data`&&(0,U.jsx)(fe,{size:14,className:`art-head-surface-icon`}),!h&&s===`graph`&&(0,U.jsx)(he,{size:14,className:`art-head-surface-icon`}),(0,U.jsx)(`span`,{className:`file-name`,children:y}),h&&(0,U.jsx)(`span`,{className:`file-tag`,children:g})]}),(0,U.jsxs)(`div`,{className:`right`,children:[h&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`button`,{className:`icon-btn`,title:`Copy`,type:`button`,"aria-label":`Copy`,onClick:()=>{I(e.content)},children:(0,U.jsx)(f,{size:14})}),(0,U.jsx)(`button`,{className:`icon-btn`,title:`Refresh`,type:`button`,"aria-label":`Refresh`,children:(0,U.jsx)(re,{size:14})})]}),s===`browser`&&(0,U.jsx)(`button`,{className:`icon-btn`,title:`Pop out`,type:`button`,"aria-label":`Pop out`,onClick:()=>l.current?.popout(),children:(0,U.jsx)(Fe,{size:14})}),o&&(0,U.jsx)(`button`,{className:`icon-btn`,title:`Close`,type:`button`,"aria-label":`Close`,onClick:r,children:(0,U.jsx)(ie,{size:14})})]})]}),(0,U.jsxs)(`div`,{className:`art-toolbar`,children:[(0,U.jsxs)(`span`,{className:`seg`,children:[(0,U.jsx)(`span`,{className:`bullet`}),(0,U.jsx)(`strong`,{children:h?`Artefact`:v})]}),(0,U.jsx)(`span`,{className:`right-meta`,children:_})]}),(0,U.jsxs)(`div`,{className:`art-body`,"data-surface":s??`none`,children:[h&&(()=>{let t=e.editable!==!1,r=e.skipReason??null,i=(e.mimeType??``).startsWith(`application/pdf`);if(r)return(0,U.jsx)(TD,{reason:r});if(i&&n){let t=`/api/admin/sidebar-artefact-content?id=${encodeURIComponent(e.docId)}&session_key=${encodeURIComponent(n)}`;return(0,U.jsx)(ED,{src:t,name:e.name,docId:e.docId},t)}return(0,U.jsxs)(U.Fragment,{children:[u&&(0,U.jsx)(`div`,{className:`art-save-error`,role:`alert`,children:u}),(0,U.jsx)(rT,{data:{title:e.name,content:e.content,readOnly:!t},onSubmit:t?m:CD,submitted:!1})]})})(),s===`browser`&&(0,U.jsx)(yD,{ref:l,onClose:r}),s===`data`&&n&&(0,U.jsx)(ce,{sessionKey:n,onOpenInGraph:a?e=>{let t=le(e.properties);a(e.nodeId,t??e.labels[0]??null)}:void 0}),e?.surface===`graph`&&n&&(0,U.jsx)(z,{sessionKey:n,initialFocus:e.focusNodeId?{nodeId:e.focusNodeId,nodeLabel:e.focusNodeLabel??null}:null,initialLabels:e.initialLabels??null})]}),(0,U.jsxs)(`div`,{className:`art-foot`,children:[(0,U.jsx)(`span`,{className:`left`,children:_}),(0,U.jsx)(`span`,{className:`right in-sync`,children:`in sync`})]})]})}var kD=`maxy-shell-artefact-px`;function AD(){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 MD(Math.round((e-n)*(2/3)))}function jD(){if(typeof window>`u`)return 320;try{let e=window.localStorage.getItem(kD);if(!e)return AD();let t=parseInt(e,10);if(Number.isFinite(t)&&t>=320)return t}catch{}return AD()}function MD(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 ND({targetSelector:e=`.platform`}){let t=(0,H.useRef)(null),[n,r]=(0,H.useState)(()=>jD()),i=(0,H.useRef)(n);(0,H.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,H.useCallback)(()=>{r(e=>{let t=MD(e);return t===e?e:t})},[]);(0,H.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(MD(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(kD,String(t))}catch{}console.info(`[admin-ui] artefact-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=AD();r(e);try{window.localStorage.removeItem(kD)}catch{}console.info(`[admin-ui] artefact-resize px=${e}`)};return(0,U.jsx)(`div`,{ref:t,className:`art-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize artefact pane`,onPointerDown:o,onDoubleClick:s})}var PD=`maxy-shell-side-px`;function FD(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .artefact`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function ID(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=Math.max(248,t-480-FD());return Math.min(Math.max(e,248),n)}function LD(){if(typeof window>`u`)return 264;try{let e=window.localStorage.getItem(PD);if(!e)return 264;let t=parseInt(e,10);if(Number.isFinite(t)&&t>=248)return ID(t)}catch{}return 264}function RD({targetSelector:e=`.platform`}){let t=(0,H.useRef)(null),[n,r]=(0,H.useState)(()=>LD()),i=(0,H.useRef)(n);(0,H.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,H.useCallback)(()=>{r(e=>{let t=ID(e);return t===e?e:t})},[]);(0,H.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(ID(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(PD,String(t))}catch{}console.info(`[admin-ui] sidebar-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=ID(264);r(e);try{window.localStorage.removeItem(PD)}catch{}console.info(`[admin-ui] sidebar-resize px=${e}`)};return(0,U.jsx)(`div`,{ref:t,className:`side-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize sidebar`,onPointerDown:o,onDoubleClick:s})}var zD=50;function BD(e){let[t,n]=(0,H.useState)([]),[r,i]=(0,H.useState)(!1),[a,o]=(0,H.useState)(null),[s,c]=(0,H.useState)(null),l=(0,H.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,H.useEffect)(()=>{e||(c(null),n([]),o(null))},[e]);let u=(0,H.useCallback)(()=>l(!1),[l]),d=(0,H.useCallback)(()=>l(!0),[l]),f=(0,H.useRef)(d);return(0,H.useEffect)(()=>{f.current=d},[d]),(0,H.useEffect)(()=>{if(!e)return;let t=null,n=R(()=>{t&&clearTimeout(t),t=setTimeout(()=>{t=null,f.current()},zD)});return()=>{t&&clearTimeout(t),n()}},[e]),{sessions:t,setSessions:n,loading:r,loaded:s!==null&&s===e,error:a,ensureLoaded:u,refetch:d}}function VD(){bt();let e=(0,H.useRef)(null),[t,n]=(0,H.useState)(null),[r,a]=(0,H.useState)(!1),[o,s]=(0,H.useState)(!1),[c,l]=(0,H.useState)(``),[u,d]=(0,H.useState)(!1),[f,p]=(0,H.useState)(null),[m,_]=(0,H.useState)(!1),[v,y]=(0,H.useState)(null),[b,x]=(0,H.useState)(null),[w,T]=(0,H.useState)(!1),[E,O]=(0,H.useState)(null),[k,A]=(0,H.useState)(!1),[j,M]=(0,H.useState)(null),[N,P]=(0,H.useState)(!1),[ee,te]=(0,H.useState)(!1),[ne,L]=(0,H.useState)(!1),[re,ae]=(0,H.useState)(!1),[R,z]=(0,H.useState)(null),[oe,se]=(0,H.useState)(null),ce=(0,H.useRef)(null),[le,de]=(0,H.useState)(()=>typeof window<`u`&&window.matchMedia(`(min-width: 721px)`).matches);(0,H.useEffect)(()=>{let e=window.matchMedia(`(min-width: 721px)`),t=e=>de(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let[pe,_e]=(0,H.useState)(()=>typeof window<`u`&&window.matchMedia(`(min-width: 1080px)`).matches);(0,H.useEffect)(()=>{let e=window.matchMedia(`(min-width: 1080px)`),t=e=>_e(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let ve=(0,H.useRef)(!1),ye=(0,H.useRef)(!1),be=(0,H.useRef)(!1),xe=(0,H.useRef)(!1),Se=(0,H.useRef)(null),[Ce,we]=(0,H.useState)(null),Te=g(),Ee=Ct(),B=kt(),De=Wt(),Oe=BD(B.sessionKey),V=Ut({sessionKey:B.sessionKey,setSessionKey:B.setSessionKey,setAppState:B.setAppState,conversationId:B.conversationId,setConversationId:B.setConversationId,startElapsedTimer:Ee.startElapsedTimer,stopElapsedTimer:Ee.stopElapsedTimer,resetTimerState:Ee.resetTimerState,pausedElapsedRef:Ee.pausedElapsedRef,expandAllDefaultRef:B.expandAllDefaultRef,setExpandAll:B.setExpandAll,getPendingFiles:()=>De.pendingFiles,clearPendingFiles:De.clearFiles,inputRef:e});(0,H.useEffect)(()=>{l(window.location.hostname.startsWith(`admin.`)?window.location.origin.replace(`admin.`,`public.`):window.location.origin)},[]),(0,H.useEffect)(()=>{function e(e){e.key===`Escape`&&(t?n(null):Te.selectionMode&&Te.exitSelection())}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,Te.selectionMode]),(0,H.useEffect)(()=>{(B.appState===`set-pin`||B.appState===`enter-pin`)&&setTimeout(()=>B.pinInputRef.current?.focus(),100),B.appState===`chat`&&setTimeout(()=>e.current?.focus(),100)},[B.appState,V.greetingGeneration]),(0,H.useEffect)(()=>{if(B.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)},[B.appState]);let ke=(0,H.useRef)(V.greetingGeneration);if((0,H.useEffect)(()=>{V.greetingGeneration!==ke.current&&(ke.current=V.greetingGeneration,B.onboardingComplete===!1&&(ve.current=!1))},[V.greetingGeneration,B.onboardingComplete]),(0,H.useEffect)(()=>{B.appState===`chat`&&B.onboardingComplete===!1&&(ve.current||(ve.current=!0,V.sendSystemPrompt(`[Begin onboarding.]`)))},[B.appState,B.onboardingComplete,V.greetingGeneration]),(0,H.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,H.useEffect)(()=>{if(B.appState!==`chat`){be.current=!1,xe.current=!1;return}if(be.current)return;be.current=!0;let e=!1;return fetch(`/api/admin/version`).then(e=>e.json()).then(t=>{e||(O(t),!(!t.updateAvailable||xe.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}},[B.appState]),(0,H.useEffect)(()=>{if(B.appState!==`chat`||!B.sessionKey)return;let e=B.conversationId?`flushed`:`pre-flush`,t=B.sessionKey.slice(0,8),n=B.conversationId?B.conversationId.slice(0,8):`null`;console.info(`[admin-session-identity] sessionKey=${t} conversationId=${n} phase=${e} surface=chat-header`)},[B.appState,B.sessionKey,B.conversationId]),(0,H.useEffect)(()=>{if(B.appState!==`chat`){ye.current=!1;return}if(ye.current||!Oe.loaded)return;ye.current=!0;let e=Oe.sessions.filter(e=>e.name).length,t=R?`open`:`closed`;console.info(`[admin-ui] platform-shell brand=${C.productName} sidebar=${e} artefact=${t}`)},[B.appState,Oe.loaded,Oe.sessions,R]),(0,H.useEffect)(()=>{if(!u){p(null),y(null),x(null),O(null);return}function e(e){Se.current&&!Se.current.contains(e.target)&&d(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[u]),(0,H.useEffect)(()=>{if(typeof BroadcastChannel>`u`)return;let e=new BroadcastChannel(`platform-onboarding`);return e.onmessage=e=>{e.data?.type===`remote-password-set`&&V.sendMessageRef.current(`I've set the remote password`)},()=>e.close()},[]),B.appState===`loading`)return(0,U.jsx)(`div`,{className:`chat-page admin-page`,children:(0,U.jsx)(`header`,{className:`chat-header`,children:(0,U.jsx)(`img`,{src:F,alt:C.productName,className:`chat-logo`})})});if(B.appState===`set-pin`)return(0,U.jsx)(Kt,{pin:B.pin,setPin:B.setPin,confirmPin:B.confirmPin,setConfirmPin:B.setConfirmPin,operatorName:B.operatorName,setOperatorName:B.setOperatorName,showPin:B.showPin,setShowPin:B.setShowPin,pinLoading:B.pinLoading,pinError:B.pinError,pinInputRef:B.pinInputRef,confirmPinInputRef:B.confirmPinInputRef,setPinFormRef:B.setPinFormRef,onSubmit:B.handleSetPin});if(B.appState===`onboarding-choice`)return(0,U.jsx)(Xt,{setAppState:B.setAppState,setOnboardingComplete:B.setOnboardingComplete});if(B.appState===`connect-claude`)return(0,U.jsx)(Yt,{authPolling:B.authPolling,setAuthPolling:B.setAuthPolling,authLoading:B.authLoading,setAuthLoading:B.setAuthLoading,pinError:B.pinError,setPinError:B.setPinError,setAppState:B.setAppState});if(B.appState===`enter-pin`)return(0,U.jsx)(qt,{pin:B.pin,setPin:B.setPin,showPin:B.showPin,setShowPin:B.setShowPin,pinLoading:B.pinLoading,pinError:B.pinError,pinInputRef:B.pinInputRef,onSubmit:B.handleLogin,onChangePin:B.handleChangePin});if(B.appState===`account-picker`)return(0,U.jsx)(Jt,{accounts:B.accounts,loading:B.accountPickerLoading,error:B.pinError,onSelect:B.handleAccountSelect});let Ae=R?`open`:`closed`,je=re&&le,Me=`platform${ne?` menu-open`:``}${je?` sidebar-collapsed`:``}`,Ne=e=>{if(!V.isStreaming&&B.sessionKey){if(!e.conversationId){V.resetConversation(),V.setMessages([]),B.setConversationId(null);return}V.resetConversation(),V.setMessages([]),fetch(`/api/admin/sessions/${encodeURIComponent(e.conversationId)}/resume?session_key=${encodeURIComponent(B.sessionKey)}`,{method:`POST`}).then(e=>e.ok?e.json():Promise.reject(Error(`resume returned ${e.status}`))).then(e=>{e.conversationId&&B.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}:{},...e.role===`user`&&eD(e.content)?{hidden:!0}:{},timestamp:new Date(e.createdAt).getTime()||0,historical:!0,...e.messageId?{messageId:e.messageId}:{}}));t.length>0&&V.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&&V.seedSubmittedComponents(n)}).catch(e=>{console.error(`[chat] sidebar conversation resume failed:`,e),V.setMessages([{role:`maxy`,events:[{type:`text`,content:`Could not load conversation history.`}],timestamp:Date.now()-1,historical:!0}])})}},Pe={conversationId:B.conversationId,sessionKey:B.sessionKey,disconnecting:B.disconnecting,onOpenConversations:()=>{T(!0),Oe.refetch()},handleDisconnect:B.handleDisconnect};return(0,U.jsx)(S,{value:{onShowVnc:()=>P(!0)},children:(0,U.jsxs)(`div`,{className:Me,"data-artefact":Ae,children:[(0,U.jsx)(`div`,{className:`scrim`,onClick:()=>{L(!1),console.info(`[admin-ui] mobile-drawer state=closed`)}}),(0,U.jsx)(SD,{ref:ce,businessName:B.businessName??null,sessionKey:B.sessionKey,conversationId:B.conversationId,role:B.role,userName:B.userName,userAvatar:B.userAvatar,sessions:Oe.sessions,sessionsLoading:Oe.loading,sessionsError:Oe.error,ensureSessionsLoaded:Oe.ensureLoaded,refetchSessions:Oe.refetch,recentsActions:{setSessions:Oe.setSessions,isStreaming:V.isStreaming,resetConversation:V.resetConversation,setMessages:V.setMessages,setConversationId:B.setConversationId,setSessionKey:B.setSessionKey},onSelectSession:Ne,onSelectArtefact:(e,t)=>{z({surface:`doc`,...e}),se(t)},onSelectProjects:()=>{z({surface:`graph`,initialLabels:[`Project`]}),se(`sidebar-projects`)},onSelectPeople:()=>{z({surface:`graph`,initialLabels:[`Person`]}),se(`sidebar-people`)},onSelectTasks:()=>{z({surface:`graph`,initialLabels:[`Task`]}),se(`sidebar-tasks`)},onSelectAgents:()=>{z({surface:`graph`,initialLabels:[`Agent`]}),se(`sidebar-agents`)},onCloseMobileDrawer:()=>{ne&&(L(!1),console.info(`[admin-ui] mobile-drawer state=closed`))},collapsed:je,onToggleCollapsed:()=>ae(e=>!e),actions:Pe}),(0,U.jsxs)(`div`,{className:`chat-page admin-page`,children:[(0,U.jsxs)(`header`,{className:`chat-header`,children:[(0,U.jsx)(`button`,{type:`button`,className:`icon-btn mobile-menu`,"aria-label":`Show sidebar`,title:`Show sidebar`,onClick:()=>{L(e=>{let t=!e;return console.info(`[admin-ui] mobile-drawer state=${t?`open`:`closed`}`),t})},children:(0,U.jsx)(st,{size:16})}),(0,U.jsx)(`img`,{src:F,alt:C.productName,className:`chat-logo`}),(!C.logoContainsName||B.businessName)&&(0,U.jsx)(`div`,{children:(0,U.jsx)(`h1`,{className:`chat-tagline`,children:B.businessName||C.productName})}),(B.sessionKey||B.conversationId)&&(0,U.jsxs)(`button`,{type:`button`,className:`chat-session-chip chat-session-chip-${B.conversationId?`flushed`:`pre-flush`}`+(Ce===`copied`?` copied`:``)+(Ce===`failed`?` copy-failed`:``),title:B.conversationId?`conversation ${B.conversationId} — click to copy`:`session ${B.sessionKey} (pre-flush, first turn pending) — click to copy`,onClick:async()=>{let e=B.conversationId??B.sessionKey;e&&(we(await I(e)?`copied`:`failed`),setTimeout(()=>we(null),1200))},children:[(0,U.jsx)(`span`,{className:`chat-session-chip-label`,children:Ce===`copied`?`copied`:Ce===`failed`?`copy failed`:B.conversationId?`conversation`:`session`}),(0,U.jsx)(`span`,{className:`chat-session-chip-id`,children:Ce===`copied`?`✓`:Ce===`failed`?`✕`:`${(B.conversationId??B.sessionKey??``).slice(0,8)}…`})]}),(0,U.jsxs)(`div`,{className:`chat-burger-wrap`,ref:Se,children:[(0,U.jsx)(`button`,{type:`button`,className:`chat-burger`,onClick:()=>d(e=>!e),"aria-label":`Menu`,"aria-haspopup":`true`,"aria-expanded":u,children:(0,U.jsx)(ue,{size:20})}),u&&(0,U.jsxs)(`div`,{className:`chat-menu`,children:[(0,U.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:async()=>{if(!ee&&!(!pe&&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`);pe?(z({surface:`browser`}),se(`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,U.jsx)(D,{size:14}),` Browser`,ee&&(0,U.jsx)(ge,{size:12,className:`spin`})]}),(0,U.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{d(!1),pe?(z({surface:`data`}),se(`header-menu`)):window.location.href=`/data`},children:[(0,U.jsx)(fe,{size:14}),` Data`]}),(0,U.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{d(!1),pe?(z({surface:`graph`}),se(`header-menu`)):window.location.href=`/graph`},children:[(0,U.jsx)(he,{size:14}),` Graph`]}),(0,U.jsx)(`div`,{className:`chat-menu-divider`}),(0,U.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,U.jsx)(Fe,{size:14}),` Public`,m&&(0,U.jsx)(ge,{size:12,className:`spin`})]}),f!==null&&(0,U.jsxs)(`div`,{className:`chat-menu-agents`,children:[v&&(0,U.jsx)(`span`,{className:`chat-menu-agent-error`,children:v}),f.length===0&&!v&&(0,U.jsx)(`span`,{className:`chat-menu-agent-empty`,children:`No public agents configured`}),f.map(e=>(0,U.jsxs)(`div`,{className:`chat-menu-item chat-menu-agent-item`,children:[(0,U.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),(0,U.jsxs)(`span`,{className:`agent-text`,children:[(0,U.jsx)(`span`,{className:`agent-display-name`,children:e.displayName}),(0,U.jsxs)(`span`,{className:`agent-slug`,children:[`/`,e.slug]})]}),b===e.slug?(0,U.jsxs)(`span`,{className:`agent-actions agent-confirm`,children:[(0,U.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,U.jsx)(h,{size:12})}),(0,U.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-no`,title:`Cancel`,onClick:()=>x(null),children:(0,U.jsx)(ie,{size:12})})]}):(0,U.jsxs)(`span`,{className:`agent-actions`,children:[(0,U.jsx)(`a`,{href:`${c}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`agent-action-btn`,title:`Open agent`,onClick:()=>d(!1),children:(0,U.jsx)(Fe,{size:12})}),(0,U.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-delete-btn`,title:`Delete agent`,onClick:()=>x(e.slug),children:(0,U.jsx)(i,{size:12})})]})]},e.slug))]}),(0,U.jsx)(`div`,{className:`chat-menu-divider`}),E?.updateAvailable?(0,U.jsxs)(`button`,{type:`button`,className:`chat-menu-version`,onClick:()=>{E.latest&&(M(E),d(!1),A(!0))},children:[(0,U.jsx)(We,{size:14}),(0,U.jsxs)(`span`,{className:`version-installed`,children:[`v`,E.installed,(0,U.jsx)(`span`,{className:`version-update-dot`})]})]}):(0,U.jsxs)(`div`,{className:`chat-menu-version chat-menu-version-passive`,children:[(0,U.jsx)(We,{size:14}),(0,U.jsxs)(`span`,{className:`version-installed`,children:[E?`v${E.installed}`:`…`,E&&!E.updateAvailable&&(0,U.jsx)(`span`,{className:`version-uptodate-dot`})]})]}),(0,U.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{d(!1),B.handleLogout(),V.setMessages([])},children:[(0,U.jsx)(me,{size:14}),` Log out`]})]})]})]}),(0,U.jsxs)(`div`,{className:`chat-content`,children:[(0,U.jsx)(qE,{messages:V.messages,isStreaming:V.isStreaming,elapsedSeconds:Ee.elapsedSeconds,sessionTurnStart:Ee.sessionTurnStart,expandAll:B.expandAll,setExpandAll:B.setExpandAll,conversationCompacted:V.conversationCompacted,isCompacting:V.isCompacting,setShowCompactConfirm:s,handleComponentSubmit:V.handleComponentSubmit,effectiveSubmitted:V.effectiveSubmitted,selectionMode:Te.selectionMode,selectedItems:Te.selectedItems,toggleSelectItem:Te.toggleSelectItem,sessionKey:B.sessionKey,setLightboxSrc:n,messageQueue:V.messageQueue,messageQueueRef:V.messageQueueRef,setQueue:V.setQueue,sendMessage:V.sendMessage,appState:B.appState,onboardingComplete:B.onboardingComplete,onOpenArtefact:e=>{z({surface:`doc`,...e}),se(`chat-link`)}}),(0,U.jsx)(JE,{offer:V.topicChangeOffer,onFreshStart:V.handleTopicFreshStart,onContinue:V.handleTopicContinue,disabled:V.isStreaming}),(0,U.jsx)(gD,{selectionMode:Te.selectionMode,selectedItems:Te.selectedItems,copyToast:Te.copyToast||null,exitSelection:Te.exitSelection,enterSelection:Te.enterSelection,copySelected:Te.copySelected,showCopyToast:Te.showCopyToast,input:V.input,setInput:V.setInput,inputRef:e,pendingFiles:De.pendingFiles,setPendingFiles:De.setPendingFiles,isDragOver:De.isDragOver,attachError:De.attachError,fileInputRef:De.fileInputRef,addFiles:De.addFiles,removeFile:De.removeFile,onDragOver:De.onDragOver,onDragLeave:De.onDragLeave,onDrop:De.onDrop,isStreaming:V.isStreaming,wasPaused:V.wasPaused,messages:V.messages,messageQueueRef:V.messageQueueRef,setQueue:V.setQueue,sendMessage:V.sendMessage,stopStreaming:V.stopStreaming,disconnecting:B.disconnecting,handleDisconnect:B.handleDisconnect,claudeInfo:B.claudeInfo,setClaudeInfo:B.setClaudeInfo,setShowClaudeInfo:a,conversationId:B.conversationId,sessionKey:B.sessionKey,onNewConversation:V.startNewConversation,newConversationDisabled:V.isStreaming||V.isCompacting,onOpenConversations:()=>{T(!0),Oe.refetch()},sidebarVisible:le})]}),Te.copyToast&&(0,U.jsx)(`span`,{className:`copy-toast${Te.copyToast===`failed`?` copy-toast-failed`:``}`,children:Te.copyToast===`copied`?`Copied`:`Copy failed`}),(0,U.jsx)(cD,{show:w,onClose:()=>T(!1),conversationsLoading:Oe.loading,conversationsError:Oe.error,conversationsList:Oe.sessions,setConversationsList:Oe.setSessions,sessionKey:B.sessionKey,setSessionKey:B.setSessionKey,isStreaming:V.isStreaming,resetConversation:V.resetConversation,setMessages:V.setMessages,setConversationId:B.setConversationId}),(0,U.jsx)(lD,{src:t,onClose:()=>n(null)}),(0,U.jsx)(uD,{show:o,onClose:()=>s(!1),onConfirm:V.handleCompactNow}),(0,U.jsx)(dD,{show:r,onClose:()=>{a(!1),B.setClaudeInfo(null)},claudeInfo:B.claudeInfo,messages:V.messages,sessionElapsed:Ee.sessionElapsed,conversationId:B.conversationId}),(0,U.jsx)(mD,{show:k,onClose:()=>{A(!1),xe.current=!0},versionInfo:j,sessionKey:B.sessionKey,onUpgradeComplete:()=>O(null)}),N&&(0,U.jsx)(bD,{onClose:()=>P(!1)})]}),(0,U.jsx)(RD,{}),(0,U.jsx)(ND,{}),(0,U.jsx)(OD,{selection:R,trigger:oe,sessionKey:B.sessionKey,onClose:()=>{z(null),se(null)},onArtefactSaved:(e,t,n)=>{ce.current?.patchArtefact(e,{updatedAt:t,content:n})},onSwapToGraph:(e,t)=>{z({surface:`graph`,focusNodeId:e,focusNodeLabel:t}),se(`chat-link`)}})]})})}(0,ve.createRoot)(document.getElementById(`root`)).render((0,U.jsx)(VD,{}));
352
+ `)}var ZE=`Cloudflare setup completed (actionId: `,QE=`{"_componentDone"`,$E=`{"_lifecycle"`;function eD(e){return typeof e!=`string`||e.length===0?!1:e.startsWith(QE)||e.startsWith($E)||e.startsWith(ZE)}function tD(e){let{row:t,surface:n,isStreaming:r,activeSessionKey:a,isLogsOpen:o,onLogsToggle:s,onRequestRename:l,onResume:u,onDelete:d,onSwitchPreFlush:f}=e,p=t.phase===`pre-flush`,m=p&&t.sessionKey!==null&&t.sessionKey!==a;return(0,U.jsxs)(`div`,{className:`conversations-row-actions`,"data-surface":n,children:[(0,U.jsx)(`button`,{type:`button`,className:`conversations-action conversations-logs`,title:p?`View pre-flush logs`:`View logs`,"aria-haspopup":`menu`,"aria-expanded":o,onClick:e=>{e.stopPropagation(),s(e.currentTarget)},children:(0,U.jsx)(c,{size:13})}),m&&f&&(0,U.jsx)(`button`,{type:`button`,className:`conversations-action conversations-play`,title:`Switch into this in-memory session`,disabled:r||!a,onClick:e=>{e.stopPropagation(),!(r||!a)&&f()},children:(0,U.jsx)(_,{size:13})}),!p&&t.conversationId&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`button`,{type:`button`,className:`conversations-action conversations-rename`,title:`Rename conversation`,onClick:e=>{e.stopPropagation(),l()},children:(0,U.jsx)(ct,{size:13})}),(0,U.jsx)(`button`,{type:`button`,className:`conversations-action conversations-play`,title:`Resume conversation`,disabled:r,onClick:e=>{e.stopPropagation(),!(r||!a)&&u()},children:(0,U.jsx)(_,{size:13})}),(0,U.jsx)(`button`,{type:`button`,className:`conversations-action conversations-delete`,title:`Delete conversation`,onClick:e=>{e.stopPropagation(),d()},children:(0,U.jsx)(i,{size:13})})]})]})}var nD=[{type:`stream`,label:`Stream`},{type:`error`,label:`Errors`},{type:`sse`,label:`SSE`}];function rD(e){let{state:t,popoverRef:n,surface:r,buildLogsUrl:i,onClose:a}=e;return t?(0,U.jsx)(`div`,{ref:n,className:`conversations-logs-popover`,role:`menu`,style:{top:t.top,right:t.right},"data-surface":r,children:nD.map(({type:e,label:n})=>(0,U.jsxs)(`a`,{role:`menuitem`,className:`conversations-logs-popover-item`,href:i({conversationId:t.conversationId,sessionKey:t.sessionKey},e),target:`_blank`,rel:`noopener noreferrer`,onClick:()=>{console.debug(`[admin-logs-popover] open-log`,{surface:r,conversationId:t.conversationId,sessionKey:t.sessionKey,type:e}),a()},children:[(0,U.jsx)(c,{size:12}),(0,U.jsx)(`span`,{children:n})]},e))}):null}function iD(e){let[t,n]=(0,H.useState)(null),r=(0,H.useRef)(null),i=(0,H.useCallback)(()=>n(null),[]),a=(0,H.useCallback)((e,t,r)=>{n(n=>{if(n?.rowId===e)return null;let i=r.getBoundingClientRect();return{rowId:e,conversationId:t.conversationId,sessionKey:t.sessionKey,top:i.bottom+4,right:Math.max(8,window.innerWidth-i.right)}})},[]);return(0,H.useEffect)(()=>{if(!t)return;function e(e){let t=e.target;t&&r.current?.contains(t)||t&&t.closest?.(`.conversations-logs`)||n(null)}function i(e){e.key===`Escape`&&n(null)}return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,i),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,i)}},[t]),(0,H.useEffect)(()=>{if(!t||!e?.current)return;let r=e.current,i=()=>n(null);return r.addEventListener(`scroll`,i,{passive:!0}),()=>r.removeEventListener(`scroll`,i)},[t,e]),{popover:t,popoverRef:r,toggle:a,close:i}}function aD(e,t){let[n,r]=(0,H.useState)(null),[i,a]=(0,H.useState)(null),[o,s]=(0,H.useState)(``),[c,l]=(0,H.useState)(!1),u=(0,H.useRef)(null);(0,H.useEffect)(()=>{i?.phase===`editing`&&(u.current?.focus(),u.current?.select())},[i]);let d=(0,H.useCallback)(()=>{r(null),a(null),s(``),l(!1)},[]);return{editingId:n,editState:i,editValue:o,setEditValue:s,confirming:c,editInputRef:u,requestSuggestion:(0,H.useCallback)(async t=>{if(e){d(),r(t),a({phase:`loading`});try{let n=await fetch(`/api/admin/sessions/${encodeURIComponent(t)}/label?session_key=${encodeURIComponent(e)}`,{method:`POST`});if(!n.ok){a({phase:`error`,reason:(await n.json().catch(()=>({}))).error||`Request failed`});return}let r=await n.json();r.label?(a({phase:`editing`}),s(r.label)):a({phase:`error`,reason:`Not enough message content to suggest a name`})}catch(e){console.error(`[admin-rename] label suggestion failed:`,e),a({phase:`error`,reason:e instanceof Error?e.message:String(e)})}}},[e,d]),confirmRename:(0,H.useCallback)(async n=>{let r=o.trim();if(!(!e||!r||c)){l(!0);try{let i=await fetch(`/api/admin/sessions/${encodeURIComponent(n)}/label`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({label:r,session_key:e})});if(!i.ok){a({phase:`error`,reason:(await i.json().catch(()=>({}))).error||`Rename failed`}),l(!1);return}t(e=>e.map(e=>e.conversationId===n?{...e,name:r}:e)),d()}catch(e){console.error(`[admin-rename] label rename failed:`,e),a({phase:`error`,reason:e instanceof Error?e.message:String(e)}),l(!1)}}},[e,o,c,t,d]),cancelEdit:d,isEditingRow:(0,H.useCallback)(e=>e!==null&&n===e,[n])}}var oD=`maxy-admin-session-key`;function sD(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 cD(e){let{show:t,onClose:n,conversationsLoading:r,conversationsError:i,conversationsList:a,setConversationsList:o,sessionKey:s,setSessionKey:c,isStreaming:l,resetConversation:u,setMessages:d,setConversationId:f}=e,[p,m]=(0,H.useState)(null),[g,_]=(0,H.useState)(null),v=(0,H.useRef)(null),y=(0,H.useRef)(null),b=(0,H.useRef)(null),{popover:x,popoverRef:S,toggle:C,close:w}=iD(b),T=aD(s,o);(0,H.useEffect)(()=>{t||(T.cancelEdit(),w(),m(null),_(null),v.current&&=(clearTimeout(v.current),null),y.current&&=(clearTimeout(y.current),null))},[t,T,w]);async function E(e){await I(e)?(m(e),_(null),v.current&&clearTimeout(v.current),v.current=setTimeout(()=>m(null),1500)):(_(e),m(null),y.current&&clearTimeout(y.current),y.current=setTimeout(()=>_(null),1500))}return t?(0,U.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,U.jsxs)(`div`,{className:`claude-info-modal conversations-modal`,onClick:e=>e.stopPropagation(),children:[(0,U.jsxs)(`div`,{className:`claude-info-header`,children:[(0,U.jsx)(Xe,{size:12}),`Conversations`,(0,U.jsx)(`button`,{className:`claude-info-close`,onClick:n,children:`✕`})]}),(0,U.jsxs)(`div`,{className:`conversations-list`,ref:b,children:[r&&(0,U.jsxs)(`div`,{className:`conversations-empty`,children:[(0,U.jsx)(ge,{size:14,className:`spin`}),` Loading…`]}),i&&(0,U.jsx)(`div`,{className:`conversations-empty conversations-error`,children:i}),!r&&!i&&a.length===0&&(0,U.jsx)(`div`,{className:`conversations-empty`,children:`No recent conversations`}),!r&&!i&&a.map(e=>{let t=e.conversationId??e.sessionKey??``,r=e.phase===`pre-flush`,i=T.isEditingRow(e.conversationId),a=i&&T.editState?.phase===`loading`,m=i&&T.editState?.phase===`editing`,_=i&&T.editState?.phase===`error`,v=e.conversationId??e.sessionKey??``;return(0,U.jsxs)(`div`,{className:`conversations-row${r?` conversations-row-pre-flush`:``}`,children:[(0,U.jsxs)(`div`,{className:`conversations-row-info`,children:[a&&(0,U.jsxs)(`span`,{className:`conversations-row-name conversations-edit-loading`,children:[(0,U.jsx)(ge,{size:12,className:`spin`}),` Generating suggestion…`]}),m&&(0,U.jsxs)(`div`,{className:`conversations-edit-inline`,children:[(0,U.jsx)(`input`,{ref:T.editInputRef,type:`text`,className:`conversations-edit-input`,value:T.editValue,onChange:e=>T.setEditValue(e.target.value),onKeyDown:t=>{t.key===`Enter`&&T.editValue.trim()&&T.confirmRename(e.conversationId),t.key===`Escape`&&T.cancelEdit()},maxLength:200}),(0,U.jsx)(`button`,{type:`button`,className:`conversations-action conversations-confirm`,title:`Confirm rename`,disabled:!T.editValue.trim()||T.confirming,onClick:()=>T.confirmRename(e.conversationId),children:T.confirming?(0,U.jsx)(ge,{size:13,className:`spin`}):(0,U.jsx)(h,{size:13})}),(0,U.jsx)(`button`,{type:`button`,className:`conversations-action conversations-cancel`,title:`Cancel`,onClick:T.cancelEdit,children:(0,U.jsx)(ie,{size:13})})]}),_&&(0,U.jsxs)(`div`,{className:`conversations-edit-inline`,children:[(0,U.jsx)(`span`,{className:`conversations-edit-error`,children:T.editState.reason}),(0,U.jsx)(`button`,{type:`button`,className:`conversations-action conversations-retry`,title:`Retry`,onClick:()=>T.requestSuggestion(e.conversationId),children:(0,U.jsx)(re,{size:13})}),(0,U.jsx)(`button`,{type:`button`,className:`conversations-action conversations-cancel`,title:`Cancel`,onClick:T.cancelEdit,children:(0,U.jsx)(ie,{size:13})})]}),!i&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`span`,{className:`conversations-row-name`,children:[e.name||(r?`session ${v}`:v),r&&(0,U.jsx)(`span`,{className:`conversations-row-phase-badge`,title:`Pre-flush — conversation not yet persisted`,children:`pre-flush`})]}),(0,U.jsxs)(`span`,{className:`conversations-row-meta`,children:[(0,U.jsx)(`button`,{type:`button`,className:`conversations-row-id${p===t?` copied`:``}${g===t?` copy-failed`:``}`,title:v,"aria-label":r?`Copy session key ${v}`:`Copy conversation id ${v}`,onClick:e=>{e.stopPropagation(),E(t)},children:p===t?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(h,{size:10}),` copied`]}):g===t?`copy failed`:v.slice(0,8)}),(0,U.jsxs)(`span`,{className:`conversations-row-time`,children:[(0,U.jsx)(ke,{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``}})()]})]})]})]}),!i&&(0,U.jsx)(tD,{row:e,surface:`conversations-modal`,rowId:t,isStreaming:l,activeSessionKey:s,isLogsOpen:x?.rowId===t,onLogsToggle:n=>{console.info(`[admin-session-identity] sessionKey=${(e.sessionKey??`null`).slice(0,8)} conversationId=${(e.conversationId??`null`).slice(0,8)} phase=${e.phase} surface=conversations-modal action=logs`),C(t,{conversationId:e.conversationId,sessionKey:e.sessionKey},n)},onRequestRename:()=>{e.conversationId&&(console.info(`[admin-session-identity] sessionKey=${(e.sessionKey??`null`).slice(0,8)} conversationId=${e.conversationId.slice(0,8)} phase=${e.phase} surface=conversations-modal action=rename`),T.requestSuggestion(e.conversationId))},onResume:()=>{!e.conversationId||!s||(console.info(`[admin-session-identity] sessionKey=${s.slice(0,8)} conversationId=${e.conversationId.slice(0,8)} phase=${e.phase} surface=conversations-modal action=resume`),n(),u(),fetch(`/api/admin/sessions/${encodeURIComponent(e.conversationId)}/resume?session_key=${encodeURIComponent(s)}`,{method:`POST`}).then(e=>e.ok?e.json():Promise.reject(Error(`Failed to resume conversation`))).then(e=>{e.conversationId&&f(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??(e.content?[{type:`text`,content:e.content}]:[]):void 0,...e.role===`user`&&e.attachments&&e.attachments.length>0?{attachments:e.attachments}:{},...e.role===`user`&&eD(e.content)?{hidden:!0}:{},timestamp:new Date(e.createdAt).getTime()||0,historical:!0,...e.messageId?{messageId:e.messageId}:{}}));t.length>0&&d(t)}).catch(e=>{console.error(`[chat] conversation resume failed:`,e),d([{role:`maxy`,events:[{type:`text`,content:`Could not load conversation history.`}],timestamp:Date.now()-1,historical:!0}])}))},onDelete:()=>{e.conversationId&&(console.info(`[admin-session-identity] sessionKey=${(e.sessionKey??`null`).slice(0,8)} conversationId=${e.conversationId.slice(0,8)} phase=${e.phase} surface=conversations-modal action=delete`),o(t=>t.filter(t=>t.conversationId!==e.conversationId)),s&&fetch(`/api/admin/sessions/${encodeURIComponent(e.conversationId)}?session_key=${encodeURIComponent(s)}`,{method:`DELETE`}).catch(e=>console.error(`[chat] conversation delete failed:`,e)))},onSwitchPreFlush:()=>{if(l||!s||!e.sessionKey)return;let t=e.sessionKey;console.info(`[admin-session-identity] sessionKey=${s.slice(0,8)} conversationId=null phase=${e.phase} surface=conversations-modal action=switch-pre-flush target=${t.slice(0,8)}`),n(),u(),d([]),fetch(`/api/admin/sessions/switch?session_key=${encodeURIComponent(s)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({target_session_key:t})}).then(e=>e.ok?e.json():Promise.reject(Error(`switch returned ${e.status}`))).then(e=>{try{sessionStorage.setItem(oD,e.session_key)}catch{}pe(e.session_key,`chat`),c(e.session_key),f(e.conversationId)}).catch(e=>{console.error(`[chat] pre-flush session switch failed:`,e),d([{role:`maxy`,events:[{type:`text`,content:`Could not switch into that session.`}],timestamp:Date.now()-1,historical:!0}])})}})]},t)})]}),(0,U.jsx)(rD,{state:x,popoverRef:S,surface:`conversations-modal`,buildLogsUrl:sD,onClose:w})]})}):null}function lD({src:e,onClose:t}){return e?(0,U.jsxs)(`div`,{className:`attachment-lightbox`,onClick:t,children:[(0,U.jsx)(`button`,{className:`attachment-lightbox-close`,onClick:t,"aria-label":`Close`,children:`×`}),(0,U.jsx)(`img`,{src:e,alt:`Attachment`,onClick:e=>e.stopPropagation()})]}):null}function uD({show:e,onClose:t,onConfirm:n}){return e?(0,U.jsx)(`div`,{className:`claude-info-overlay`,onClick:t,children:(0,U.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,U.jsxs)(`div`,{className:`claude-info-header`,children:[(0,U.jsx)(`span`,{children:`Compact conversation?`}),(0,U.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:`✕`})]}),(0,U.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,U.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,U.jsx)(w,{variant:`secondary`,size:`sm`,style:{background:`var(--accent)`,flex:1},onClick:()=>{t(),n()},children:`Yes, compact`}),(0,U.jsx)(w,{variant:`secondary`,size:`sm`,style:{flex:1},onClick:t,children:`No`})]})]})}):null}function dD(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,U.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,U.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,U.jsxs)(`div`,{className:`claude-info-header`,children:[(0,U.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`claude-info-icon`}),(0,U.jsx)(`span`,{children:`Claude Code`}),(0,U.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,U.jsxs)(`div`,{className:`claude-info-section`,children:[(0,U.jsxs)(`div`,{className:`claude-info-row`,children:[(0,U.jsx)(`span`,{className:`claude-info-label`,children:`Version`}),(0,U.jsx)(`span`,{className:`claude-info-value`,children:r?r.version:`…`})]}),(0,U.jsxs)(`div`,{className:`claude-info-row`,children:[(0,U.jsx)(`span`,{className:`claude-info-label`,children:`Email`}),(0,U.jsx)(`span`,{className:`claude-info-value`,children:r?.account?.email??`…`})]})]}),(p||d||f>0)&&(0,U.jsxs)(`div`,{className:`claude-info-section`,children:[p&&(0,U.jsxs)(`div`,{className:`claude-info-row`,children:[(0,U.jsx)(`span`,{className:`claude-info-label`,children:`Plan`}),(0,U.jsx)(`span`,{className:`claude-info-value`,style:{textTransform:`capitalize`},children:p})]}),d&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`div`,{className:`claude-info-row`,children:[(0,U.jsx)(`span`,{className:`claude-info-label`,children:`Usage`}),(0,U.jsxs)(`span`,{className:`claude-info-value`,children:[Math.round(d.utilization*100),`%`]})]}),(0,U.jsxs)(`div`,{className:`claude-info-row`,children:[(0,U.jsx)(`span`,{className:`claude-info-label`,children:`Resets in`}),(0,U.jsx)(`span`,{className:`claude-info-value`,children:m(d.resetsAt)})]}),d.isUsingOverage&&(0,U.jsxs)(`div`,{className:`claude-info-row`,children:[(0,U.jsx)(`span`,{className:`claude-info-label`,children:`Overage`}),(0,U.jsx)(`span`,{className:`claude-info-value`,children:`Active`})]})]}),f>0&&(0,U.jsxs)(`div`,{className:`claude-info-row`,children:[(0,U.jsx)(`span`,{className:`claude-info-label`,children:`Session cost`}),(0,U.jsxs)(`span`,{className:`claude-info-value`,children:[`$`,f<.01?f.toFixed(4):f.toFixed(2)]})]})]}),(0,U.jsxs)(`div`,{className:`claude-info-section`,children:[(0,U.jsxs)(`div`,{className:`claude-info-row`,children:[(0,U.jsx)(`span`,{className:`claude-info-label`,children:`Model`}),(0,U.jsx)(`span`,{className:`claude-info-value`,children:r?.model??`…`})]}),(0,U.jsxs)(`div`,{className:`claude-info-row`,children:[(0,U.jsx)(`span`,{className:`claude-info-label`,children:`Context used`}),(0,U.jsx)(`span`,{className:`claude-info-value`,children:l>0?`${l}%`:`—`})]}),(0,U.jsxs)(`div`,{className:`claude-info-row`,children:[(0,U.jsx)(`span`,{className:`claude-info-label`,children:`Tokens`}),(0,U.jsx)(`span`,{className:`claude-info-value`,children:u>0?St(u):`—`})]}),(0,U.jsxs)(`div`,{className:`claude-info-row`,children:[(0,U.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,U.jsx)(`span`,{className:`claude-info-value`,children:xt(a)})]}),o&&(0,U.jsxs)(`div`,{className:`claude-info-row`,children:[(0,U.jsx)(`span`,{className:`claude-info-label`,children:`Conversation`}),(0,U.jsx)(`span`,{className:`claude-info-value`,style:{fontFamily:`monospace`,fontSize:10},children:o.slice(0,8)})]})]})]})})}var fD=5e3,pD={atPhase:8};function mD({show:e,onClose:t,versionInfo:n,sessionKey:r,onUpgradeComplete:i}){let[a,o]=(0,H.useState)(`prompt`),[s,c]=(0,H.useState)(``),[l,u]=(0,H.useState)(!1),[d,f]=(0,H.useState)(null),[p,m]=(0,H.useState)(null),[h,g]=(0,H.useState)(null),_=(0,H.useRef)(null),v=n?.latest??null,y=(0,H.useCallback)(()=>{_.current&&=(clearInterval(_.current),null)},[]);(0,H.useEffect)(()=>{e||(y(),o(`prompt`),c(``),u(!1),f(null),m(null),g(null))},[e,y]),(0,H.useEffect)(()=>y,[y]),(0,H.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{}},fD),y},[e,a,v,i,y]);let b=(0,H.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,U.jsx)(`div`,{className:`claude-info-overlay`,onClick:()=>{(a===`prompt`||a===`succeeded`||a===`launch-failed`)&&t()},children:(0,U.jsxs)(`div`,{className:`claude-info-modal update-modal`,onClick:e=>e.stopPropagation(),children:[(0,U.jsxs)(`div`,{className:`claude-info-header`,children:[(0,U.jsx)(oe,{size:12}),`Software Update`,(0,U.jsx)(`button`,{className:`claude-info-close`,onClick:t,children:`✕`})]}),(0,U.jsxs)(`div`,{className:`update-modal-body`,children:[(0,U.jsxs)(`div`,{className:`update-modal-versions`,children:[(0,U.jsxs)(`div`,{className:`claude-info-row`,children:[(0,U.jsx)(`span`,{className:`claude-info-label`,children:`Installed`}),(0,U.jsxs)(`span`,{className:`claude-info-value`,children:[`v`,n?.installed??`…`]})]}),(0,U.jsxs)(`div`,{className:`claude-info-row`,children:[(0,U.jsx)(`span`,{className:`claude-info-label`,children:`Available`}),(0,U.jsxs)(`span`,{className:`claude-info-value update-version-new`,children:[`v`,v??`…`]})]})]}),(a===`prompt`||a===`priming`||a===`launch-failed`)&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(`div`,{className:`form-input__field`,style:{marginTop:12},children:[(0,U.jsx)(`label`,{className:`form-input__label`,htmlFor:`upgrade-sudo`,children:`Device password`}),(0,U.jsxs)(`div`,{className:`tunnel-route__row`,children:[(0,U.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,U.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,U.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,U.jsx)(`div`,{className:`tunnel-route__error`,children:d}),p&&(0,U.jsx)(`div`,{className:`tunnel-route__error`,role:`alert`,children:p})]}),(0,U.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,U.jsx)(`div`,{className:`update-modal-terminal`,style:{height:360,marginTop:10},children:(0,U.jsx)(yE,{actionId:h,sessionKey:r,selfRestart:pD})}),a===`succeeded`&&(0,U.jsxs)(`div`,{className:`update-modal-result`,children:[(0,U.jsx)(B,{size:14,className:`update-success-icon`}),(0,U.jsxs)(`span`,{children:[`Upgraded to v`,v,` — reloading…`]})]})]})]})}):null}function hD(e){let{conversationId:t,sessionKey:n,disconnecting:r,onOpenConversations:i,handleDisconnect:a,onAfterAction:o}=e,s=!t&&!n;return(0,U.jsxs)(`div`,{className:`chat-actions-menu`,children:[(0,U.jsxs)(`button`,{type:`button`,className:`chat-action`,onClick:()=>{o(),i()},children:[(0,U.jsx)(Xe,{size:14}),(0,U.jsx)(`span`,{className:`action-label`,children:`Conversations`})]}),(0,U.jsxs)(`button`,{type:`button`,className:`chat-action`,disabled:r,onClick:async()=>{o(),await a()},children:[r?(0,U.jsx)(ge,{size:14,className:`animate-spin`}):(0,U.jsx)(Se,{size:14}),(0,U.jsx)(`span`,{className:`action-label`,children:r?`Disconnecting...`:`Disconnect Claude`})]}),(0,U.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=`${sD({conversationId:t,sessionKey:n},`stream`)}&download=1`,e.click()},children:[(0,U.jsx)(ut,{size:14}),(0,U.jsx)(`span`,{className:`action-label`,children:`Stream log`})]})]})}function gD(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:L,stopStreaming:re,disconnecting:ie,handleDisconnect:ae,claudeInfo:R,setClaudeInfo:z,setShowClaudeInfo:oe,conversationId:se,sessionKey:ce,onNewConversation:le,newConversationDisabled:ue,onOpenConversations:de,sidebarVisible:fe}=e,[pe,me]=(0,H.useState)(!1),he=(0,H.useRef)(null),[ge,_e]=(0,H.useState)(!1),ve=(0,H.useRef)(null),ye=(0,H.useRef)(!1),be=ee(),xe=be.state===`recording`||be.state===`paused`||be.state===`sending`,Se=!xe&&!M&&!l.trim()&&g.length===0;async function Ce(){let e=await be.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}L(`[Voice note]`,[n])}return(0,H.useEffect)(()=>{t||_e(!1)},[t]),(0,H.useEffect)(()=>{if(!ge)return;let e=e=>{e.target.closest(`.selection-copy-wrap`)||_e(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[ge]),(0,H.useEffect)(()=>{if(!pe)return;let e=e=>{if(e.key===`Escape`){me(!1);return}if(e.key===`Tab`&&he.current){let t=he.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=>{he.current&&!he.current.contains(e.target)&&me(!1)};return document.addEventListener(`keydown`,e),document.addEventListener(`mousedown`,t),()=>{document.removeEventListener(`keydown`,e),document.removeEventListener(`mousedown`,t)}},[pe]),t?(0,U.jsx)(`div`,{className:`chat-input-area`,children:(0,U.jsxs)(`div`,{className:`selection-bar`,children:[(0,U.jsxs)(`span`,{className:`selection-count`,children:[n.size,` Selected`]}),(0,U.jsxs)(`div`,{className:`selection-copy-wrap`,children:[(0,U.jsxs)(`button`,{type:`button`,className:`selection-copy`,onPointerDown:()=>{if(ge){_e(!1);return}ye.current=!1,ve.current=setTimeout(()=>{ye.current=!0,_e(!0),ve.current=null},500)},onPointerUp:()=>{ve.current!==null&&(clearTimeout(ve.current),ve.current=null)},onPointerLeave:()=>{ve.current!==null&&(clearTimeout(ve.current),ve.current=null)},onPointerCancel:()=>{ve.current!==null&&(clearTimeout(ve.current),ve.current=null)},onClick:async()=>{ye.current||await o(e=>YE(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,U.jsx)(f,{size:18}),(0,U.jsx)(`span`,{children:`Copy`})]}),ge&&(0,U.jsx)(`div`,{className:`copy-menu`,children:[[`all`,`All events`],[`text`,`Text messages only`],[`non-text`,`Non-text only`]].map(([e,t])=>(0,U.jsx)(`button`,{type:`button`,className:`copy-menu-item`,onClick:async()=>{let t=XE(P,e);t&&s(await I(t)),i()},children:t},e))})]}),(0,U.jsx)(`button`,{type:`button`,className:`selection-cancel`,onClick:i,children:`Cancel`})]})}):(0,U.jsxs)(`div`,{className:`chat-input-area`,children:[(0,U.jsx)(`input`,{ref:x,type:`file`,multiple:!0,accept:wt,style:{display:`none`},onChange:e=>{e.target.files&&S([...e.target.files]),e.target.value=``}}),g.length>0&&(0,U.jsx)(`div`,{className:`attachment-strip`,children:g.map((e,t)=>(0,U.jsxs)(`div`,{className:`attachment-chip`,children:[e.type.startsWith(`image/`)?(0,U.jsx)(`img`,{src:URL.createObjectURL(e),alt:e.name,className:`attachment-chip-thumb`}):e.type===`application/pdf`?(0,U.jsx)(c,{size:14}):(0,U.jsx)(E,{size:14}),(0,U.jsx)(`span`,{className:`attachment-chip-name`,children:e.name}),(0,U.jsx)(`button`,{type:`button`,className:`attachment-chip-remove`,onClick:()=>C(t),"aria-label":`Remove ${e.name}`,children:`×`})]},t))}),b&&(0,U.jsx)(`p`,{className:`attach-error`,children:b}),be.state===`error`&&be.errorMessage&&(0,U.jsxs)(`p`,{className:`voice-error`,role:`alert`,children:[(0,U.jsx)(m,{size:14}),be.errorMessage]}),(0,U.jsx)(T,{inputRef:h}),xe?(0,U.jsx)(`div`,{className:`chat-form voice-active`,children:(0,U.jsx)(A,{state:be.state,elapsedSeconds:be.elapsedSeconds,waveform:be.waveform,onTogglePause:be.togglePause,onDiscard:be.discard,onSend:Ce})}):(0,U.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}L(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,U.jsx)(w,{variant:`icon`,type:`button`,onClick:()=>x.current?.click(),"aria-label":`Attach file`,children:(0,U.jsx)(u,{size:14})}),(0,U.jsx)(N,{ref:h,value:l,onChange:p}),j?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(w,{variant:`send`,type:`button`,onClick:()=>re(!0),"aria-label":`Pause`,style:{background:`var(--text-secondary)`},children:(0,U.jsx)(d,{size:14})}),(0,U.jsx)(w,{variant:`send`,type:`button`,onClick:()=>re(!1),"aria-label":`Stop`,style:{background:`var(--danger)`},children:(0,U.jsx)(pt,{size:14})})]}):Se?(0,U.jsx)(w,{variant:`send`,type:`button`,onClick:be.start,"aria-label":`Record voice note`,children:(0,U.jsx)(m,{size:14})}):(0,U.jsx)(w,{variant:`send`,type:`submit`,disabled:!l.trim()&&g.length===0&&!M,"aria-label":`Send message`,children:M?(0,U.jsx)(_,{size:14}):(0,U.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,U.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,U.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,U.jsxs)(`div`,{className:`chat-actions`,ref:he,children:[!fe&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`button`,{className:`burger-trigger`,onClick:()=>me(e=>!e),"aria-expanded":pe,"aria-haspopup":`true`,"aria-label":`Conversation actions`,children:(0,U.jsx)(Pe,{size:16})}),(0,U.jsx)(`div`,{className:`actions-menu-items${pe?` actions-menu-open`:``}`,children:(0,U.jsx)(hD,{conversationId:se,sessionKey:ce,disconnecting:ie,onOpenConversations:de,handleDisconnect:ae,onAfterAction:()=>me(!1)})})]}),(0,U.jsx)(`button`,{type:`button`,className:`chat-action-icon`,title:`New conversation`,"aria-label":`New conversation`,disabled:ue,onClick:le,children:(0,U.jsx)(Ve,{size:16})}),(0,U.jsx)(`button`,{type:`button`,className:`chat-action-icon`,title:`Select messages`,"aria-label":`Select messages`,onClick:a,children:(0,U.jsx)(ne,{size:16})}),(0,U.jsxs)(`div`,{className:`powered-by`,onClick:async()=>{if(oe(!0),!R){let e=await fetch(`/api/admin/claude-info`);e.ok&&z(await e.json())}},children:[(0,U.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`powered-by-icon`}),(0,U.jsx)(`span`,{children:`Powered by Claude Code`})]})]})]})}var _D=`maxy-vnc-overlay-popout`;function vD(e){let[t,n]=(0,H.useState)(!1),r=(0,H.useRef)(null),i=(0,H.useRef)(null),a=(0,H.useCallback)(()=>{i.current&&=(clearInterval(i.current),null),r.current&&!r.current.closed&&r.current.close(),r.current=null,n(!1)},[]),o=(0,H.useCallback)(()=>{let t=`/vnc-popout.html?title=${encodeURIComponent(C.productName)}`,o=window.open(t,_D,`width=1024,height=768`);o&&(r.current=o,n(!0),i.current=setInterval(()=>{r.current?.closed&&(a(),e?.())},500))},[a,e]);return(0,H.useEffect)(()=>()=>a(),[a]),{poppedOut:t,popout:o,cleanupPopout:a}}var yD=(0,H.forwardRef)(function({onClose:e},t){bt();let{poppedOut:n,popout:r,cleanupPopout:i}=vD(e);return(0,H.useImperativeHandle)(t,()=>({popout:r}),[r]),n?(0,U.jsxs)(`div`,{className:`browser-overlay-popout`,children:[(0,U.jsx)(D,{className:`browser-viewer__icon`}),(0,U.jsx)(`span`,{className:`browser-viewer__title`,children:C.productName}),(0,U.jsx)(`span`,{className:`browser-viewer__popout-label`,children:`Popped out`}),(0,U.jsx)(w,{variant:`ghost`,size:`sm`,icon:rt,onClick:()=>i(),"aria-label":`Pop back in`}),e&&(0,U.jsx)(w,{variant:`ghost`,size:`sm`,icon:ie,onClick:()=>{i(),e()},"aria-label":`Close`})]}):(0,U.jsx)(`iframe`,{src:`/vnc-viewer.html`,className:`browser-surface__iframe`,title:C.productName})});function bD({onClose:e}){bt();let{poppedOut:t,popout:n,cleanupPopout:r}=vD(e),i=(0,H.useCallback)(()=>{r(),e()},[r,e]);(0,H.useEffect)(()=>{if(t)return;let e=e=>{e.key===`Escape`&&i()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,i]);let a=an({handlePopout:n,disabled:t});return t?(0,U.jsxs)(`div`,{className:`browser-overlay-popout`,children:[(0,U.jsx)(D,{className:`browser-viewer__icon`}),(0,U.jsx)(`span`,{className:`browser-viewer__title`,children:C.productName}),(0,U.jsx)(`span`,{className:`browser-viewer__popout-label`,children:`Popped out`}),(0,U.jsx)(w,{variant:`ghost`,size:`sm`,icon:rt,onClick:()=>{r()},"aria-label":`Pop back in`}),(0,U.jsx)(w,{variant:`ghost`,size:`sm`,icon:ie,onClick:i,"aria-label":`Close`})]}):(0,U.jsxs)(`div`,{className:`browser-viewer-fullscreen`,children:[(0,U.jsxs)(`div`,{className:`browser-viewer-fullscreen__bar`,...a,children:[(0,U.jsx)(D,{className:`browser-viewer__icon`}),(0,U.jsx)(`span`,{className:`browser-viewer-fullscreen__title`,children:C.productName}),(0,U.jsxs)(`div`,{className:`browser-viewer-fullscreen__actions`,children:[(0,U.jsx)(w,{variant:`ghost`,size:`sm`,icon:Fe,onClick:n,"aria-label":`Pop out`}),(0,U.jsx)(w,{variant:`ghost`,size:`sm`,icon:ie,onClick:i,"aria-label":`Close`})]})]}),(0,U.jsx)(`iframe`,{src:`/vnc-viewer.html`,className:`browser-viewer-fullscreen__iframe`,title:C.productName})]})}var xD=`maxy-admin-session-key`,SD=(0,H.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:g,onSelectProjects:_,onSelectPeople:v,onSelectTasks:y,onSelectAgents:b,onCloseMobileDrawer:x,collapsed:S,onToggleCollapsed:w,actions:T,recentsActions:E}=e;(0,H.useEffect)(()=>{f()},[f]);let D=(0,H.useRef)(null),{popover:O,popoverRef:k,toggle:A,close:j}=iD(D),M=aD(r,E.setSessions),N=C.productName,P=typeof o==`string`?o:o===null?`name unavailable`:n||N,ee=(P.trim().charAt(0)||`?`).toUpperCase(),[te,F]=(0,H.useState)(`all`),ne=(0,H.useMemo)(()=>l.filter(e=>e.name).filter(e=>te===`all`?!0:(e.channel??`webchat`)===te),[l,te]),I=ne.length,L=i??r,[R,z]=(0,H.useState)(`chat`),[oe,se]=(0,H.useState)([]),[ce,le]=(0,H.useState)(!1),[ue,de]=(0,H.useState)(null),[fe,me]=(0,H.useState)(!1);(0,H.useImperativeHandle)(t,()=>({patchArtefact(e,t){se(n=>n.map(n=>n.id===e?{...n,...t}:n))}}),[]);let[he,_e]=(0,H.useState)(!1),ve=(0,H.useRef)(null);(0,H.useEffect)(()=>{if(!he)return;function e(e){ve.current&&!ve.current.contains(e.target)&&_e(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[he]);let ye=(0,H.useCallback)(async()=>{if(r){me(!0),de(null);try{let e=await fetch(`/api/admin/sidebar-artefacts?session_key=${encodeURIComponent(r)}`);if(!e.ok)throw Error(`status ${e.status}`);se((await e.json()).artefacts??[]),le(!0)}catch(e){let t=e instanceof Error?e.message:String(e);de(`Failed to load artefacts: ${t}`),console.error(`[admin-ui] sidebar-artefacts fetch failed: ${t}`)}finally{me(!1)}}},[r]),be=()=>{z(`chat`),console.info(`[admin-ui] sidebar-nav surface=chat count=${I}`)},xe=()=>{z(`artefacts`),console.info(`[admin-ui] sidebar-nav surface=artefacts count=${ce?oe.length:0}`),ce||ye()},Se=S?24:16,Te=R===`chat`?`Recents`:`Artefacts`,Ee=R===`chat`?u?`…`:String(I):fe?`…`:String(oe.length),B=R===`chat`?u:fe,De=()=>{R===`chat`?p():ye(),console.info(`[admin-ui] sidebar-refresh surface=${R}`)};return(0,U.jsxs)(`aside`,{className:`side`,children:[(0,U.jsx)(`div`,{className:`side-head`,children:(0,U.jsx)(`button`,{className:`icon-btn side-head-toggle`,title:S?`Expand sidebar`:`Collapse sidebar`,type:`button`,"aria-label":S?`Expand sidebar`:`Collapse sidebar`,onClick:w,children:S?(0,U.jsx)(st,{size:28}):(0,U.jsx)(ot,{size:28})})}),(0,U.jsxs)(`nav`,{className:`side-nav`,children:[(0,U.jsxs)(`button`,{type:`button`,className:`nav-row${R===`chat`?` active`:``}`,onClick:be,children:[(0,U.jsx)(nt,{size:Se}),(0,U.jsx)(`span`,{className:`label`,children:`Chat`}),(0,U.jsx)(`span`,{className:`kbd`})]}),(0,U.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=people`),v(),x()},children:[(0,U.jsx)(_t,{size:Se}),(0,U.jsx)(`span`,{className:`label`,children:`People`}),(0,U.jsx)(`span`,{className:`kbd`})]}),(0,U.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=agents`),b(),x()},children:[(0,U.jsx)(Ce,{size:Se}),(0,U.jsx)(`span`,{className:`label`,children:`Agents`}),(0,U.jsx)(`span`,{className:`kbd`})]}),(0,U.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=projects`),_(),x()},children:[(0,U.jsx)(we,{size:Se}),(0,U.jsx)(`span`,{className:`label`,children:`Projects`}),(0,U.jsx)(`span`,{className:`kbd`})]}),(0,U.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=tasks`),y(),x()},children:[(0,U.jsx)(Ye,{size:Se}),(0,U.jsx)(`span`,{className:`label`,children:`Tasks`}),(0,U.jsx)(`span`,{className:`kbd`})]}),(0,U.jsxs)(`button`,{type:`button`,className:`nav-row${R===`artefacts`?` active`:``}`,onClick:xe,children:[(0,U.jsx)(c,{size:Se}),(0,U.jsx)(`span`,{className:`label`,children:`Artefacts`}),(0,U.jsx)(`span`,{className:`kbd`})]})]}),(0,U.jsxs)(`div`,{className:`side-list`,ref:D,children:[(0,U.jsxs)(`div`,{className:`group-head`,children:[(0,U.jsx)(`span`,{children:Te}),(0,U.jsxs)(`span`,{className:`group-head-meta`,children:[(0,U.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh ${Te.toLowerCase()}`,"aria-label":`Refresh ${Te.toLowerCase()}`,onClick:De,disabled:B,children:(0,U.jsx)(ae,{size:12,className:B?`spinning`:void 0})}),(0,U.jsx)(`span`,{children:Ee})]})]}),R===`chat`&&(0,U.jsxs)(U.Fragment,{children:[d&&(0,U.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:d}),(0,U.jsxs)(en,{className:`conv-channel-filter`,value:te,onChange:e=>{let t=e.target.value;F(t),console.info(`[admin-ui] sidebar-channel-filter set value=${t}`)},"aria-label":`Filter conversations by channel`,children:[(0,U.jsx)(`option`,{value:`all`,children:`All channels`}),(0,U.jsx)(`option`,{value:`webchat`,children:`Web`})]}),ne.map(e=>{let t=e.conversationId??e.sessionKey??``,n=t!==``&&t===L,i=e.channel??`webchat`,a=e.phase===`pre-flush`,o=M.isEditingRow(e.conversationId),s=o&&M.editState?.phase===`loading`,c=o&&M.editState?.phase===`editing`,l=o&&M.editState?.phase===`error`,u=t=>{let n=e.sessionKey?e.sessionKey.slice(0,8):`null`,r=e.conversationId?e.conversationId.slice(0,8):`null`;console.info(`[admin-session-identity] sessionKey=${n} conversationId=${r} phase=${e.phase} surface=sidebar-recents action=${t}`)};return(0,U.jsxs)(`div`,{className:`conv${n?` active`:``}${a?` conv-pre-flush`:``}${o?` conv-editing`:``}`,children:[!o&&(0,U.jsxs)(`button`,{type:`button`,className:`conv-name-button`,onClick:()=>{u(`select`),m(e),x()},children:[i===`whatsapp`&&(0,U.jsx)($e,{size:12,className:`conv-channel-icon`,"aria-label":`WhatsApp`}),(0,U.jsx)(`span`,{className:`conv-name`,children:e.name??`(untitled)`})]}),s&&(0,U.jsxs)(`span`,{className:`conversations-row-name conversations-edit-loading conv-edit-loading`,children:[(0,U.jsx)(ge,{size:12,className:`spin`}),` Generating suggestion…`]}),c&&(0,U.jsxs)(`div`,{className:`conversations-edit-inline conv-edit-inline`,children:[(0,U.jsx)(`input`,{ref:M.editInputRef,type:`text`,className:`conversations-edit-input`,value:M.editValue,onChange:e=>M.setEditValue(e.target.value),onKeyDown:t=>{t.key===`Enter`&&M.editValue.trim()&&e.conversationId&&M.confirmRename(e.conversationId),t.key===`Escape`&&M.cancelEdit()},maxLength:200}),(0,U.jsx)(`button`,{type:`button`,className:`conversations-action conversations-confirm`,title:`Confirm rename`,disabled:!M.editValue.trim()||M.confirming,onClick:()=>e.conversationId&&M.confirmRename(e.conversationId),children:M.confirming?(0,U.jsx)(ge,{size:13,className:`spin`}):(0,U.jsx)(h,{size:13})}),(0,U.jsx)(`button`,{type:`button`,className:`conversations-action conversations-cancel`,title:`Cancel`,onClick:M.cancelEdit,children:(0,U.jsx)(ie,{size:13})})]}),l&&(0,U.jsxs)(`div`,{className:`conversations-edit-inline conv-edit-inline`,children:[(0,U.jsx)(`span`,{className:`conversations-edit-error`,children:M.editState.reason}),(0,U.jsx)(`button`,{type:`button`,className:`conversations-action conversations-retry`,title:`Retry`,onClick:()=>e.conversationId&&M.requestSuggestion(e.conversationId),children:(0,U.jsx)(re,{size:13})}),(0,U.jsx)(`button`,{type:`button`,className:`conversations-action conversations-cancel`,title:`Cancel`,onClick:M.cancelEdit,children:(0,U.jsx)(ie,{size:13})})]}),!o&&(0,U.jsx)(tD,{row:e,surface:`sidebar-recents`,rowId:t,isStreaming:E.isStreaming,activeSessionKey:r,isLogsOpen:O?.rowId===t,onLogsToggle:n=>{u(`logs`),A(t,{conversationId:e.conversationId,sessionKey:e.sessionKey},n)},onRequestRename:()=>{e.conversationId&&(u(`rename`),M.requestSuggestion(e.conversationId))},onResume:()=>{!e.conversationId||E.isStreaming||(u(`resume`),m(e),x())},onDelete:()=>{if(!e.conversationId)return;u(`delete`);let t=e.conversationId;E.setSessions(e=>e.filter(e=>e.conversationId!==t)),r&&fetch(`/api/admin/sessions/${encodeURIComponent(t)}?session_key=${encodeURIComponent(r)}`,{method:`DELETE`}).catch(e=>console.error(`[chat] conversation delete failed:`,e))},onSwitchPreFlush:()=>{if(E.isStreaming||!r||!e.sessionKey)return;let t=e.sessionKey;u(`switch-pre-flush target=${t.slice(0,8)}`),E.resetConversation(),E.setMessages([]),fetch(`/api/admin/sessions/switch?session_key=${encodeURIComponent(r)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({target_session_key:t})}).then(e=>e.ok?e.json():Promise.reject(Error(`switch returned ${e.status}`))).then(e=>{try{sessionStorage.setItem(xD,e.session_key)}catch{}pe(e.session_key,`chat`),E.setSessionKey(e.session_key),E.setConversationId(e.conversationId)}).catch(e=>{console.error(`[chat] pre-flush session switch failed:`,e),E.setMessages([{role:`maxy`,events:[{type:`text`,content:`Could not switch into that session.`}],timestamp:Date.now()-1,historical:!0}])})}})]},t===``?e.updatedAt:t)})]}),R===`artefacts`&&(0,U.jsxs)(U.Fragment,{children:[ue&&(0,U.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:ue}),ce&&!ue&&oe.length===0&&(0,U.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No artefacts yet`}),oe.map(e=>(0,U.jsxs)(`button`,{type:`button`,className:`conv`,onClick:()=>{g({docId:e.id,name:e.name,content:e.content,editable:e.editable,mimeType:e.mimeType,skipReason:e.skipReason},`sidebar-artefacts`),x()},children:[(0,U.jsx)(`span`,{className:`conv-name`,children:e.name}),(0,U.jsx)(`span`,{className:`conv-kind`,"data-kind":e.kind===`agent-template`?`agent`:`doc`,children:e.kind===`agent-template`?`agent`:`doc`})]},e.id))]}),(0,U.jsx)(rD,{state:O,popoverRef:k,surface:`sidebar-recents`,buildLogsUrl:sD,onClose:j})]}),(0,U.jsxs)(`div`,{className:`side-foot`,ref:ve,children:[(0,U.jsx)(`div`,{className:`avatar`,children:s?(0,U.jsx)(`img`,{src:s,alt:P}):ee}),(0,U.jsxs)(`div`,{className:`who`,children:[(0,U.jsx)(`span`,{className:`name`,children:P}),(0,U.jsx)(`span`,{className:`role`,children:a??`operator`})]}),(0,U.jsx)(`button`,{className:`icon-btn side-foot-actions-trigger`,title:`Conversation actions`,type:`button`,"aria-label":`Conversation actions`,"aria-haspopup":`true`,"aria-expanded":he,onClick:()=>_e(e=>!e),children:(0,U.jsx)(Pe,{size:Se})}),he&&(0,U.jsx)(`div`,{className:`side-foot-actions-popover`,children:(0,U.jsx)(hD,{...T,onAfterAction:()=>_e(!1)})})]})]})}),CD=()=>{},wD={"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,U.jsxs)(`div`,{className:`art-skip-banner`,role:`status`,children:[(0,U.jsx)(Re,{size:14}),(0,U.jsx)(`span`,{children:wD[e]})]})}function ED({src:e,name:t,docId:n}){let[r,i]=(0,H.useState)(!1),a=(0,H.useRef)(null),o=(0,H.useRef)(!1),s=(0,H.useRef)(!1),l=(0,H.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,H.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,U.jsxs)(`a`,{className:`art-pdf-fallback`,href:e,download:t,children:[(0,U.jsx)(c,{size:20}),(0,U.jsxs)(`div`,{className:`art-pdf-fallback-text`,children:[(0,U.jsx)(`div`,{className:`art-pdf-fallback-name`,children:t}),(0,U.jsx)(`div`,{className:`art-pdf-fallback-hint`,children:`Your browser can't display this PDF inline. Click to download.`})]}),(0,U.jsx)(oe,{size:16})]}):(0,U.jsx)(`iframe`,{ref:a,className:`art-pdf`,src:e,title:t,"aria-label":`PDF preview of ${t}`,onLoad:u,onError:()=>l(`onerror`)})}var DD={browser:`Browser`,data:`Data`,graph:`Graph`};function OD({selection:e,trigger:t,sessionKey:n,onClose:r,onArtefactSaved:i,onSwapToGraph:a}){let o=e!==null,s=e?.surface??null,c=(0,H.useRef)(null),l=(0,H.useRef)(null),[u,d]=(0,H.useState)(null),p=e?.surface===`doc`?e.docId:null,m=(0,H.useCallback)(e=>{if(!n||!p)return;let t={};try{t=JSON.parse(e)}catch{return}t.action!==`save`||typeof t.content!=`string`||(d(null),fetch(`/api/admin/sidebar-artefact-save?session_key=${encodeURIComponent(n)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({id:p,content:t.content})}).then(async e=>{if(!e.ok){let t=(await e.json().catch(()=>({}))).error??`status ${e.status}`;d(`Save failed: ${t}`),console.error(`[admin-ui] artefact-save-failed docId=${p} status=${e.status} error="${t}"`);return}let n=await e.json();i?.(p,n.updatedAt,t.content)}).catch(e=>{let t=e instanceof Error?e.message:String(e);d(`Save failed: ${t}`),console.error(`[admin-ui] artefact-save-failed docId=${p} error="${t}"`)}))},[n,p,i]);(0,H.useEffect)(()=>{d(null)},[p]),(0,H.useEffect)(()=>{let n=e?.surface===`doc`?e.docId:null,r=e?.surface===`graph`?e.focusNodeId??null:null,i=e?.surface??null,a=i===null?`closed`:`${i}:${n??`none`}:${r??`none`}`;if(a===c.current)return;let s=o?`open`:`closed`,l=o?t??`chat-link`:`toolbar-close`,u=i??c.current?.split(`:`)[0]??`doc`;console.info(`[admin-ui] artefact-pane state=${s} docId=${n??`none`} trigger=${l} surface=${u}`),c.current=a},[e,t,o]);let h=e?.surface===`doc`,g=h?(e.tag||e.name.split(`.`).pop()||`doc`).toUpperCase().slice(0,6):``,_=h?e.revision||`rev 1`:`live`,v=e&&e.surface!==`doc`?DD[e.surface]:``,y=h?e.name:v;return(0,U.jsxs)(`aside`,{className:`artefact`,"data-open":o,"data-surface":s??`none`,children:[(0,U.jsxs)(`div`,{className:`art-head`,children:[(0,U.jsxs)(`div`,{className:`left`,children:[!h&&s===`browser`&&(0,U.jsx)(D,{size:14,className:`art-head-surface-icon`}),!h&&s===`data`&&(0,U.jsx)(fe,{size:14,className:`art-head-surface-icon`}),!h&&s===`graph`&&(0,U.jsx)(he,{size:14,className:`art-head-surface-icon`}),(0,U.jsx)(`span`,{className:`file-name`,children:y}),h&&(0,U.jsx)(`span`,{className:`file-tag`,children:g})]}),(0,U.jsxs)(`div`,{className:`right`,children:[h&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`button`,{className:`icon-btn`,title:`Copy`,type:`button`,"aria-label":`Copy`,onClick:()=>{I(e.content)},children:(0,U.jsx)(f,{size:14})}),(0,U.jsx)(`button`,{className:`icon-btn`,title:`Refresh`,type:`button`,"aria-label":`Refresh`,children:(0,U.jsx)(re,{size:14})})]}),s===`browser`&&(0,U.jsx)(`button`,{className:`icon-btn`,title:`Pop out`,type:`button`,"aria-label":`Pop out`,onClick:()=>l.current?.popout(),children:(0,U.jsx)(Fe,{size:14})}),o&&(0,U.jsx)(`button`,{className:`icon-btn`,title:`Close`,type:`button`,"aria-label":`Close`,onClick:r,children:(0,U.jsx)(ie,{size:14})})]})]}),(0,U.jsxs)(`div`,{className:`art-toolbar`,children:[(0,U.jsxs)(`span`,{className:`seg`,children:[(0,U.jsx)(`span`,{className:`bullet`}),(0,U.jsx)(`strong`,{children:h?`Artefact`:v})]}),(0,U.jsx)(`span`,{className:`right-meta`,children:_})]}),(0,U.jsxs)(`div`,{className:`art-body`,"data-surface":s??`none`,children:[h&&(()=>{let t=e.editable!==!1,r=e.skipReason??null,i=(e.mimeType??``).startsWith(`application/pdf`);if(r)return(0,U.jsx)(TD,{reason:r});if(i&&n){let t=`/api/admin/sidebar-artefact-content?id=${encodeURIComponent(e.docId)}&session_key=${encodeURIComponent(n)}`;return(0,U.jsx)(ED,{src:t,name:e.name,docId:e.docId},t)}return(0,U.jsxs)(U.Fragment,{children:[u&&(0,U.jsx)(`div`,{className:`art-save-error`,role:`alert`,children:u}),(0,U.jsx)(rT,{data:{title:e.name,content:e.content,readOnly:!t},onSubmit:t?m:CD,submitted:!1})]})})(),s===`browser`&&(0,U.jsx)(yD,{ref:l,onClose:r}),s===`data`&&n&&(0,U.jsx)(ce,{sessionKey:n,onOpenInGraph:a?e=>{let t=le(e.properties);a(e.nodeId,t??e.labels[0]??null)}:void 0}),e?.surface===`graph`&&n&&(0,U.jsx)(z,{sessionKey:n,initialFocus:e.focusNodeId?{nodeId:e.focusNodeId,nodeLabel:e.focusNodeLabel??null}:null,initialLabels:e.initialLabels??null})]}),(0,U.jsxs)(`div`,{className:`art-foot`,children:[(0,U.jsx)(`span`,{className:`left`,children:_}),(0,U.jsx)(`span`,{className:`right in-sync`,children:`in sync`})]})]})}var kD=`maxy-shell-artefact-px`;function AD(){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 MD(Math.round((e-n)*(2/3)))}function jD(){if(typeof window>`u`)return 320;try{let e=window.localStorage.getItem(kD);if(!e)return AD();let t=parseInt(e,10);if(Number.isFinite(t)&&t>=320)return t}catch{}return AD()}function MD(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 ND({targetSelector:e=`.platform`}){let t=(0,H.useRef)(null),[n,r]=(0,H.useState)(()=>jD()),i=(0,H.useRef)(n);(0,H.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,H.useCallback)(()=>{r(e=>{let t=MD(e);return t===e?e:t})},[]);(0,H.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(MD(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(kD,String(t))}catch{}console.info(`[admin-ui] artefact-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=AD();r(e);try{window.localStorage.removeItem(kD)}catch{}console.info(`[admin-ui] artefact-resize px=${e}`)};return(0,U.jsx)(`div`,{ref:t,className:`art-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize artefact pane`,onPointerDown:o,onDoubleClick:s})}var PD=`maxy-shell-side-px`;function FD(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .artefact`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function ID(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=Math.max(248,t-480-FD());return Math.min(Math.max(e,248),n)}function LD(){if(typeof window>`u`)return 264;try{let e=window.localStorage.getItem(PD);if(!e)return 264;let t=parseInt(e,10);if(Number.isFinite(t)&&t>=248)return ID(t)}catch{}return 264}function RD({targetSelector:e=`.platform`}){let t=(0,H.useRef)(null),[n,r]=(0,H.useState)(()=>LD()),i=(0,H.useRef)(n);(0,H.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,H.useCallback)(()=>{r(e=>{let t=ID(e);return t===e?e:t})},[]);(0,H.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(ID(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(PD,String(t))}catch{}console.info(`[admin-ui] sidebar-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=ID(264);r(e);try{window.localStorage.removeItem(PD)}catch{}console.info(`[admin-ui] sidebar-resize px=${e}`)};return(0,U.jsx)(`div`,{ref:t,className:`side-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize sidebar`,onPointerDown:o,onDoubleClick:s})}var zD=50;function BD(e){let[t,n]=(0,H.useState)([]),[r,i]=(0,H.useState)(!1),[a,o]=(0,H.useState)(null),[s,c]=(0,H.useState)(null),l=(0,H.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,H.useEffect)(()=>{e||(c(null),n([]),o(null))},[e]);let u=(0,H.useCallback)(()=>l(!1),[l]),d=(0,H.useCallback)(()=>l(!0),[l]),f=(0,H.useRef)(d);return(0,H.useEffect)(()=>{f.current=d},[d]),(0,H.useEffect)(()=>{if(!e)return;let t=null,n=R(()=>{t&&clearTimeout(t),t=setTimeout(()=>{t=null,f.current()},zD)});return()=>{t&&clearTimeout(t),n()}},[e]),{sessions:t,setSessions:n,loading:r,loaded:s!==null&&s===e,error:a,ensureLoaded:u,refetch:d}}function VD(){bt();let e=(0,H.useRef)(null),[t,n]=(0,H.useState)(null),[r,a]=(0,H.useState)(!1),[o,s]=(0,H.useState)(!1),[c,l]=(0,H.useState)(``),[u,d]=(0,H.useState)(!1),[f,p]=(0,H.useState)(null),[m,_]=(0,H.useState)(!1),[v,y]=(0,H.useState)(null),[b,x]=(0,H.useState)(null),[w,T]=(0,H.useState)(!1),[E,O]=(0,H.useState)(null),[k,A]=(0,H.useState)(!1),[j,M]=(0,H.useState)(null),[N,P]=(0,H.useState)(!1),[ee,te]=(0,H.useState)(!1),[ne,L]=(0,H.useState)(!1),[re,ae]=(0,H.useState)(!1),[R,z]=(0,H.useState)(null),[oe,se]=(0,H.useState)(null),ce=(0,H.useRef)(null),[le,de]=(0,H.useState)(()=>typeof window<`u`&&window.matchMedia(`(min-width: 721px)`).matches);(0,H.useEffect)(()=>{let e=window.matchMedia(`(min-width: 721px)`),t=e=>de(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let[pe,_e]=(0,H.useState)(()=>typeof window<`u`&&window.matchMedia(`(min-width: 1080px)`).matches);(0,H.useEffect)(()=>{let e=window.matchMedia(`(min-width: 1080px)`),t=e=>_e(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let ve=(0,H.useRef)(!1),ye=(0,H.useRef)(!1),be=(0,H.useRef)(!1),xe=(0,H.useRef)(!1),Se=(0,H.useRef)(null),[Ce,we]=(0,H.useState)(null),Te=g(),Ee=Ct(),B=kt(),De=Wt(),Oe=BD(B.sessionKey),V=Ut({sessionKey:B.sessionKey,setSessionKey:B.setSessionKey,setAppState:B.setAppState,conversationId:B.conversationId,setConversationId:B.setConversationId,startElapsedTimer:Ee.startElapsedTimer,stopElapsedTimer:Ee.stopElapsedTimer,resetTimerState:Ee.resetTimerState,pausedElapsedRef:Ee.pausedElapsedRef,expandAllDefaultRef:B.expandAllDefaultRef,setExpandAll:B.setExpandAll,getPendingFiles:()=>De.pendingFiles,clearPendingFiles:De.clearFiles,inputRef:e});(0,H.useEffect)(()=>{l(window.location.hostname.startsWith(`admin.`)?window.location.origin.replace(`admin.`,`public.`):window.location.origin)},[]),(0,H.useEffect)(()=>{function e(e){e.key===`Escape`&&(t?n(null):Te.selectionMode&&Te.exitSelection())}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,Te.selectionMode]),(0,H.useEffect)(()=>{(B.appState===`set-pin`||B.appState===`enter-pin`)&&setTimeout(()=>B.pinInputRef.current?.focus(),100),B.appState===`chat`&&setTimeout(()=>e.current?.focus(),100)},[B.appState,V.greetingGeneration]),(0,H.useEffect)(()=>{if(B.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)},[B.appState]);let ke=(0,H.useRef)(V.greetingGeneration);if((0,H.useEffect)(()=>{V.greetingGeneration!==ke.current&&(ke.current=V.greetingGeneration,B.onboardingComplete===!1&&(ve.current=!1))},[V.greetingGeneration,B.onboardingComplete]),(0,H.useEffect)(()=>{B.appState===`chat`&&B.onboardingComplete===!1&&(ve.current||(ve.current=!0,V.sendSystemPrompt(`[Begin onboarding.]`)))},[B.appState,B.onboardingComplete,V.greetingGeneration]),(0,H.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,H.useEffect)(()=>{if(B.appState!==`chat`){be.current=!1,xe.current=!1;return}if(be.current)return;be.current=!0;let e=!1;return fetch(`/api/admin/version`).then(e=>e.json()).then(t=>{e||(O(t),!(!t.updateAvailable||xe.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}},[B.appState]),(0,H.useEffect)(()=>{if(B.appState!==`chat`||!B.sessionKey)return;let e=B.conversationId?`flushed`:`pre-flush`,t=B.sessionKey.slice(0,8),n=B.conversationId?B.conversationId.slice(0,8):`null`;console.info(`[admin-session-identity] sessionKey=${t} conversationId=${n} phase=${e} surface=chat-header`)},[B.appState,B.sessionKey,B.conversationId]),(0,H.useEffect)(()=>{if(B.appState!==`chat`){ye.current=!1;return}if(ye.current||!Oe.loaded)return;ye.current=!0;let e=Oe.sessions.filter(e=>e.name).length,t=R?`open`:`closed`;console.info(`[admin-ui] platform-shell brand=${C.productName} sidebar=${e} artefact=${t}`)},[B.appState,Oe.loaded,Oe.sessions,R]),(0,H.useEffect)(()=>{if(!u){p(null),y(null),x(null),O(null);return}function e(e){Se.current&&!Se.current.contains(e.target)&&d(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[u]),(0,H.useEffect)(()=>{if(typeof BroadcastChannel>`u`)return;let e=new BroadcastChannel(`platform-onboarding`);return e.onmessage=e=>{e.data?.type===`remote-password-set`&&V.sendMessageRef.current(`I've set the remote password`)},()=>e.close()},[]),B.appState===`loading`)return(0,U.jsx)(`div`,{className:`chat-page admin-page`,children:(0,U.jsx)(`header`,{className:`chat-header`,children:(0,U.jsx)(`img`,{src:F,alt:C.productName,className:`chat-logo`})})});if(B.appState===`set-pin`)return(0,U.jsx)(Kt,{pin:B.pin,setPin:B.setPin,confirmPin:B.confirmPin,setConfirmPin:B.setConfirmPin,operatorName:B.operatorName,setOperatorName:B.setOperatorName,showPin:B.showPin,setShowPin:B.setShowPin,pinLoading:B.pinLoading,pinError:B.pinError,pinInputRef:B.pinInputRef,confirmPinInputRef:B.confirmPinInputRef,setPinFormRef:B.setPinFormRef,onSubmit:B.handleSetPin});if(B.appState===`onboarding-choice`)return(0,U.jsx)(Xt,{setAppState:B.setAppState,setOnboardingComplete:B.setOnboardingComplete});if(B.appState===`connect-claude`)return(0,U.jsx)(Yt,{authPolling:B.authPolling,setAuthPolling:B.setAuthPolling,authLoading:B.authLoading,setAuthLoading:B.setAuthLoading,pinError:B.pinError,setPinError:B.setPinError,setAppState:B.setAppState});if(B.appState===`enter-pin`)return(0,U.jsx)(qt,{pin:B.pin,setPin:B.setPin,showPin:B.showPin,setShowPin:B.setShowPin,pinLoading:B.pinLoading,pinError:B.pinError,pinInputRef:B.pinInputRef,onSubmit:B.handleLogin,onChangePin:B.handleChangePin});if(B.appState===`account-picker`)return(0,U.jsx)(Jt,{accounts:B.accounts,loading:B.accountPickerLoading,error:B.pinError,onSelect:B.handleAccountSelect});let Ae=R?`open`:`closed`,je=re&&le,Me=`platform${ne?` menu-open`:``}${je?` sidebar-collapsed`:``}`,Ne=e=>{if(!V.isStreaming&&B.sessionKey){if(!e.conversationId){V.resetConversation(),V.setMessages([]),B.setConversationId(null);return}V.resetConversation(),V.setMessages([]),fetch(`/api/admin/sessions/${encodeURIComponent(e.conversationId)}/resume?session_key=${encodeURIComponent(B.sessionKey)}`,{method:`POST`}).then(e=>e.ok?e.json():Promise.reject(Error(`resume returned ${e.status}`))).then(e=>{e.conversationId&&B.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}:{},...e.role===`user`&&eD(e.content)?{hidden:!0}:{},timestamp:new Date(e.createdAt).getTime()||0,historical:!0,...e.messageId?{messageId:e.messageId}:{}}));t.length>0&&V.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&&V.seedSubmittedComponents(n)}).catch(e=>{console.error(`[chat] sidebar conversation resume failed:`,e),V.setMessages([{role:`maxy`,events:[{type:`text`,content:`Could not load conversation history.`}],timestamp:Date.now()-1,historical:!0}])})}},Pe={conversationId:B.conversationId,sessionKey:B.sessionKey,disconnecting:B.disconnecting,onOpenConversations:()=>{T(!0),Oe.refetch()},handleDisconnect:B.handleDisconnect};return(0,U.jsx)(S,{value:{onShowVnc:()=>P(!0)},children:(0,U.jsxs)(`div`,{className:Me,"data-artefact":Ae,children:[(0,U.jsx)(`div`,{className:`scrim`,onClick:()=>{L(!1),console.info(`[admin-ui] mobile-drawer state=closed`)}}),(0,U.jsx)(SD,{ref:ce,businessName:B.businessName??null,sessionKey:B.sessionKey,conversationId:B.conversationId,role:B.role,userName:B.userName,userAvatar:B.userAvatar,sessions:Oe.sessions,sessionsLoading:Oe.loading,sessionsError:Oe.error,ensureSessionsLoaded:Oe.ensureLoaded,refetchSessions:Oe.refetch,recentsActions:{setSessions:Oe.setSessions,isStreaming:V.isStreaming,resetConversation:V.resetConversation,setMessages:V.setMessages,setConversationId:B.setConversationId,setSessionKey:B.setSessionKey},onSelectSession:Ne,onSelectArtefact:(e,t)=>{z({surface:`doc`,...e}),se(t)},onSelectProjects:()=>{z({surface:`graph`,initialLabels:[`Project`]}),se(`sidebar-projects`)},onSelectPeople:()=>{z({surface:`graph`,initialLabels:[`Person`]}),se(`sidebar-people`)},onSelectTasks:()=>{z({surface:`graph`,initialLabels:[`Task`]}),se(`sidebar-tasks`)},onSelectAgents:()=>{z({surface:`graph`,initialLabels:[`Agent`]}),se(`sidebar-agents`)},onCloseMobileDrawer:()=>{ne&&(L(!1),console.info(`[admin-ui] mobile-drawer state=closed`))},collapsed:je,onToggleCollapsed:()=>ae(e=>!e),actions:Pe}),(0,U.jsxs)(`div`,{className:`chat-page admin-page`,children:[(0,U.jsxs)(`header`,{className:`chat-header`,children:[(0,U.jsx)(`button`,{type:`button`,className:`icon-btn mobile-menu`,"aria-label":`Show sidebar`,title:`Show sidebar`,onClick:()=>{L(e=>{let t=!e;return console.info(`[admin-ui] mobile-drawer state=${t?`open`:`closed`}`),t})},children:(0,U.jsx)(st,{size:16})}),(0,U.jsx)(`img`,{src:F,alt:C.productName,className:`chat-logo`}),(!C.logoContainsName||B.businessName)&&(0,U.jsx)(`div`,{children:(0,U.jsx)(`h1`,{className:`chat-tagline`,children:B.businessName||C.productName})}),(B.sessionKey||B.conversationId)&&(0,U.jsxs)(`button`,{type:`button`,className:`chat-session-chip chat-session-chip-${B.conversationId?`flushed`:`pre-flush`}`+(Ce===`copied`?` copied`:``)+(Ce===`failed`?` copy-failed`:``),title:B.conversationId?`conversation ${B.conversationId} — click to copy`:`session ${B.sessionKey} (pre-flush, first turn pending) — click to copy`,onClick:async()=>{let e=B.conversationId??B.sessionKey;e&&(we(await I(e)?`copied`:`failed`),setTimeout(()=>we(null),1200))},children:[(0,U.jsx)(`span`,{className:`chat-session-chip-label`,children:Ce===`copied`?`copied`:Ce===`failed`?`copy failed`:B.conversationId?`conversation`:`session`}),(0,U.jsx)(`span`,{className:`chat-session-chip-id`,children:Ce===`copied`?`✓`:Ce===`failed`?`✕`:`${(B.conversationId??B.sessionKey??``).slice(0,8)}…`})]}),(0,U.jsxs)(`div`,{className:`chat-burger-wrap`,ref:Se,children:[(0,U.jsx)(`button`,{type:`button`,className:`chat-burger`,onClick:()=>d(e=>!e),"aria-label":`Menu`,"aria-haspopup":`true`,"aria-expanded":u,children:(0,U.jsx)(ue,{size:20})}),u&&(0,U.jsxs)(`div`,{className:`chat-menu`,children:[(0,U.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:async()=>{if(!ee&&!(!pe&&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`);pe?(z({surface:`browser`}),se(`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,U.jsx)(D,{size:14}),` Browser`,ee&&(0,U.jsx)(ge,{size:12,className:`spin`})]}),(0,U.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{d(!1),pe?(z({surface:`data`}),se(`header-menu`)):window.location.href=`/data`},children:[(0,U.jsx)(fe,{size:14}),` Data`]}),(0,U.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{d(!1),pe?(z({surface:`graph`}),se(`header-menu`)):window.location.href=`/graph`},children:[(0,U.jsx)(he,{size:14}),` Graph`]}),(0,U.jsx)(`div`,{className:`chat-menu-divider`}),(0,U.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,U.jsx)(Fe,{size:14}),` Public`,m&&(0,U.jsx)(ge,{size:12,className:`spin`})]}),f!==null&&(0,U.jsxs)(`div`,{className:`chat-menu-agents`,children:[v&&(0,U.jsx)(`span`,{className:`chat-menu-agent-error`,children:v}),f.length===0&&!v&&(0,U.jsx)(`span`,{className:`chat-menu-agent-empty`,children:`No public agents configured`}),f.map(e=>(0,U.jsxs)(`div`,{className:`chat-menu-item chat-menu-agent-item`,children:[(0,U.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),(0,U.jsxs)(`span`,{className:`agent-text`,children:[(0,U.jsx)(`span`,{className:`agent-display-name`,children:e.displayName}),(0,U.jsxs)(`span`,{className:`agent-slug`,children:[`/`,e.slug]})]}),b===e.slug?(0,U.jsxs)(`span`,{className:`agent-actions agent-confirm`,children:[(0,U.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,U.jsx)(h,{size:12})}),(0,U.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-no`,title:`Cancel`,onClick:()=>x(null),children:(0,U.jsx)(ie,{size:12})})]}):(0,U.jsxs)(`span`,{className:`agent-actions`,children:[(0,U.jsx)(`a`,{href:`${c}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`agent-action-btn`,title:`Open agent`,onClick:()=>d(!1),children:(0,U.jsx)(Fe,{size:12})}),(0,U.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-delete-btn`,title:`Delete agent`,onClick:()=>x(e.slug),children:(0,U.jsx)(i,{size:12})})]})]},e.slug))]}),(0,U.jsx)(`div`,{className:`chat-menu-divider`}),E?.updateAvailable?(0,U.jsxs)(`button`,{type:`button`,className:`chat-menu-version`,onClick:()=>{E.latest&&(M(E),d(!1),A(!0))},children:[(0,U.jsx)(We,{size:14}),(0,U.jsxs)(`span`,{className:`version-installed`,children:[`v`,E.installed,(0,U.jsx)(`span`,{className:`version-update-dot`})]})]}):(0,U.jsxs)(`div`,{className:`chat-menu-version chat-menu-version-passive`,children:[(0,U.jsx)(We,{size:14}),(0,U.jsxs)(`span`,{className:`version-installed`,children:[E?`v${E.installed}`:`…`,E&&!E.updateAvailable&&(0,U.jsx)(`span`,{className:`version-uptodate-dot`})]})]}),(0,U.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{d(!1),B.handleLogout(),V.setMessages([])},children:[(0,U.jsx)(me,{size:14}),` Log out`]})]})]})]}),(0,U.jsxs)(`div`,{className:`chat-content`,children:[(0,U.jsx)(qE,{messages:V.messages,isStreaming:V.isStreaming,elapsedSeconds:Ee.elapsedSeconds,sessionTurnStart:Ee.sessionTurnStart,expandAll:B.expandAll,setExpandAll:B.setExpandAll,conversationCompacted:V.conversationCompacted,isCompacting:V.isCompacting,setShowCompactConfirm:s,handleComponentSubmit:V.handleComponentSubmit,effectiveSubmitted:V.effectiveSubmitted,selectionMode:Te.selectionMode,selectedItems:Te.selectedItems,toggleSelectItem:Te.toggleSelectItem,sessionKey:B.sessionKey,setLightboxSrc:n,messageQueue:V.messageQueue,messageQueueRef:V.messageQueueRef,setQueue:V.setQueue,sendMessage:V.sendMessage,appState:B.appState,onboardingComplete:B.onboardingComplete,onOpenArtefact:e=>{z({surface:`doc`,...e}),se(`chat-link`)}}),(0,U.jsx)(JE,{offer:V.topicChangeOffer,onFreshStart:V.handleTopicFreshStart,onContinue:V.handleTopicContinue,disabled:V.isStreaming}),(0,U.jsx)(gD,{selectionMode:Te.selectionMode,selectedItems:Te.selectedItems,copyToast:Te.copyToast||null,exitSelection:Te.exitSelection,enterSelection:Te.enterSelection,copySelected:Te.copySelected,showCopyToast:Te.showCopyToast,input:V.input,setInput:V.setInput,inputRef:e,pendingFiles:De.pendingFiles,setPendingFiles:De.setPendingFiles,isDragOver:De.isDragOver,attachError:De.attachError,fileInputRef:De.fileInputRef,addFiles:De.addFiles,removeFile:De.removeFile,onDragOver:De.onDragOver,onDragLeave:De.onDragLeave,onDrop:De.onDrop,isStreaming:V.isStreaming,wasPaused:V.wasPaused,messages:V.messages,messageQueueRef:V.messageQueueRef,setQueue:V.setQueue,sendMessage:V.sendMessage,stopStreaming:V.stopStreaming,disconnecting:B.disconnecting,handleDisconnect:B.handleDisconnect,claudeInfo:B.claudeInfo,setClaudeInfo:B.setClaudeInfo,setShowClaudeInfo:a,conversationId:B.conversationId,sessionKey:B.sessionKey,onNewConversation:V.startNewConversation,newConversationDisabled:V.isStreaming||V.isCompacting,onOpenConversations:()=>{T(!0),Oe.refetch()},sidebarVisible:le})]}),Te.copyToast&&(0,U.jsx)(`span`,{className:`copy-toast${Te.copyToast===`failed`?` copy-toast-failed`:``}`,children:Te.copyToast===`copied`?`Copied`:`Copy failed`}),(0,U.jsx)(cD,{show:w,onClose:()=>T(!1),conversationsLoading:Oe.loading,conversationsError:Oe.error,conversationsList:Oe.sessions,setConversationsList:Oe.setSessions,sessionKey:B.sessionKey,setSessionKey:B.setSessionKey,isStreaming:V.isStreaming,resetConversation:V.resetConversation,setMessages:V.setMessages,setConversationId:B.setConversationId}),(0,U.jsx)(lD,{src:t,onClose:()=>n(null)}),(0,U.jsx)(uD,{show:o,onClose:()=>s(!1),onConfirm:V.handleCompactNow}),(0,U.jsx)(dD,{show:r,onClose:()=>{a(!1),B.setClaudeInfo(null)},claudeInfo:B.claudeInfo,messages:V.messages,sessionElapsed:Ee.sessionElapsed,conversationId:B.conversationId}),(0,U.jsx)(mD,{show:k,onClose:()=>{A(!1),xe.current=!0},versionInfo:j,sessionKey:B.sessionKey,onUpgradeComplete:()=>O(null)}),N&&(0,U.jsx)(bD,{onClose:()=>P(!1)})]}),(0,U.jsx)(RD,{}),(0,U.jsx)(ND,{}),(0,U.jsx)(OD,{selection:R,trigger:oe,sessionKey:B.sessionKey,onClose:()=>{z(null),se(null)},onArtefactSaved:(e,t,n)=>{ce.current?.patchArtefact(e,{updatedAt:t,content:n})},onSwapToGraph:(e,t)=>{z({surface:`graph`,focusNodeId:e,focusNodeLabel:t}),se(`chat-link`)}})]})})}(0,ve.createRoot)(document.getElementById(`root`)).render((0,U.jsx)(VD,{}));
@@ -5,7 +5,7 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
6
  <title>Real Agent</title>
7
7
  <link rel="icon" href="/favicon.ico">
8
- <script type="module" crossorigin src="/assets/admin-CvwOOG4D.js"></script>
8
+ <script type="module" crossorigin src="/assets/admin-CedLGnCT.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-WW3O7tSz.js">
11
11
  <link rel="modulepreload" crossorigin href="/assets/preload-helper-qlgyTAkD.js">
@@ -45,7 +45,7 @@ import {
45
45
  vncLog,
46
46
  waitForExit,
47
47
  writeChromiumWrapper
48
- } from "./chunk-LU2UG7KB.js";
48
+ } from "./chunk-NYGJNXX2.js";
49
49
  import {
50
50
  ACCOUNTS_DIR,
51
51
  COMMERCIAL_MODE,