@rubytech/create-maxy 1.0.750 → 1.0.751

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rubytech/create-maxy",
3
- "version": "1.0.750",
3
+ "version": "1.0.751",
4
4
  "description": "Install Maxy — AI for Productive People",
5
5
  "bin": {
6
6
  "create-maxy": "./dist/index.js"
@@ -349,4 +349,4 @@ ${JSON.stringify(u.input,null,2)}`,f=se.get(r),p=o?void 0:f??t;return(0,z.jsx)(b
349
349
 
350
350
  ---
351
351
 
352
- `)}var EE=[{type:`stream`,label:`Stream`},{type:`error`,label:`Errors`},{type:`sse`,label:`SSE`}];function DE(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 OE(e){let{show:t,onClose:n,conversationsLoading:r,conversationsError:a,conversationsList:o,setConversationsList:s,sessionKey:l,isStreaming:u,resetConversation:d,setMessages:f,setConversationId:p}=e,[m,g]=(0,R.useState)(null),[v,y]=(0,R.useState)(null),[b,x]=(0,R.useState)(``),[S,C]=(0,R.useState)(!1),w=(0,R.useRef)(null),[T,E]=(0,R.useState)(null),[D,O]=(0,R.useState)(null),[k,A]=(0,R.useState)(null),j=(0,R.useRef)(null),M=(0,R.useRef)(null),N=(0,R.useRef)(null);(0,R.useEffect)(()=>{t||(g(null),y(null),x(``),C(!1),E(null),O(null),A(null),j.current&&=(clearTimeout(j.current),null),M.current&&=(clearTimeout(M.current),null))},[t]),(0,R.useEffect)(()=>{if(!T)return;function e(e){let t=e.target;t&&N.current?.contains(t)||t&&t.closest?.(`.conversations-logs`)||E(null)}function t(e){e.key===`Escape`&&E(null)}return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[T]),(0,R.useEffect)(()=>{v?.phase===`editing`&&(w.current?.focus(),w.current?.select())},[v]);function P(){g(null),y(null),x(``),C(!1)}async function ee(e){if(l){P(),g(e),y({phase:`loading`});try{let t=await fetch(`/api/admin/sessions/${encodeURIComponent(e)}/label?session_key=${encodeURIComponent(l)}`,{method:`POST`});if(!t.ok){y({phase:`error`,reason:(await t.json().catch(()=>({}))).error||`Request failed`});return}let n=await t.json();n.label?(y({phase:`editing`}),x(n.label)):y({phase:`error`,reason:`Not enough message content to suggest a name`})}catch(e){console.error(`[admin-modal] label suggestion failed:`,e),y({phase:`error`,reason:e instanceof Error?e.message:String(e)})}}}async function te(e){if(!(!l||!b.trim()||S)){C(!0);try{let t=await fetch(`/api/admin/sessions/${encodeURIComponent(e)}/label`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({label:b.trim(),session_key:l})});if(!t.ok){y({phase:`error`,reason:(await t.json().catch(()=>({}))).error||`Rename failed`}),C(!1);return}s(t=>t.map(t=>t.conversationId===e?{...t,name:b.trim()}:t)),P()}catch(e){console.error(`[admin-modal] label rename failed:`,e),y({phase:`error`,reason:e instanceof Error?e.message:String(e)}),C(!1)}}}function ne(e,t,n){if(T?.rowId===e){E(null);return}let r=n.getBoundingClientRect();E({rowId:e,conversationId:t.conversationId,sessionKey:t.sessionKey,top:r.bottom+4,right:Math.max(8,window.innerWidth-r.right)})}async function F(e){await re(e)?(O(e),A(null),j.current&&clearTimeout(j.current),j.current=setTimeout(()=>O(null),1500)):(A(e),O(null),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>A(null),1500))}return t?(0,z.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,z.jsxs)(`div`,{className:`claude-info-modal conversations-modal`,onClick:e=>e.stopPropagation(),children:[(0,z.jsxs)(`div`,{className:`claude-info-header`,children:[(0,z.jsx)(Ge,{size:12}),`Conversations`,(0,z.jsx)(`button`,{className:`claude-info-close`,onClick:n,children:`✕`})]}),(0,z.jsxs)(`div`,{className:`conversations-list`,children:[r&&(0,z.jsxs)(`div`,{className:`conversations-empty`,children:[(0,z.jsx)(ae,{size:14,className:`spin`}),` Loading…`]}),a&&(0,z.jsx)(`div`,{className:`conversations-empty conversations-error`,children:a}),!r&&!a&&o.length===0&&(0,z.jsx)(`div`,{className:`conversations-empty`,children:`No recent conversations`}),!r&&!a&&o.map(e=>{let t=e.conversationId??e.sessionKey??``,r=e.phase===`pre-flush`,a=!r&&m===e.conversationId,o=a&&v?.phase===`loading`,g=a&&v?.phase===`editing`,y=a&&v?.phase===`error`,C=e.conversationId??e.sessionKey??``;return(0,z.jsxs)(`div`,{className:`conversations-row${r?` conversations-row-pre-flush`:``}`,children:[(0,z.jsxs)(`div`,{className:`conversations-row-info`,children:[o&&(0,z.jsxs)(`span`,{className:`conversations-row-name conversations-edit-loading`,children:[(0,z.jsx)(ae,{size:12,className:`spin`}),` Generating suggestion…`]}),g&&(0,z.jsxs)(`div`,{className:`conversations-edit-inline`,children:[(0,z.jsx)(`input`,{ref:w,type:`text`,className:`conversations-edit-input`,value:b,onChange:e=>x(e.target.value),onKeyDown:t=>{t.key===`Enter`&&b.trim()&&te(e.conversationId),t.key===`Escape`&&P()},maxLength:200}),(0,z.jsx)(`button`,{type:`button`,className:`conversations-action conversations-confirm`,title:`Confirm rename`,disabled:!b.trim()||S,onClick:()=>te(e.conversationId),children:S?(0,z.jsx)(ae,{size:13,className:`spin`}):(0,z.jsx)(h,{size:13})}),(0,z.jsx)(`button`,{type:`button`,className:`conversations-action conversations-cancel`,title:`Cancel`,onClick:P,children:(0,z.jsx)(me,{size:13})})]}),y&&(0,z.jsxs)(`div`,{className:`conversations-edit-inline`,children:[(0,z.jsx)(`span`,{className:`conversations-edit-error`,children:v.reason}),(0,z.jsx)(`button`,{type:`button`,className:`conversations-action conversations-retry`,title:`Retry`,onClick:()=>ee(e.conversationId),children:(0,z.jsx)(pe,{size:13})}),(0,z.jsx)(`button`,{type:`button`,className:`conversations-action conversations-cancel`,title:`Cancel`,onClick:P,children:(0,z.jsx)(me,{size:13})})]}),!a&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`span`,{className:`conversations-row-name`,children:[e.name||(r?`session ${C}`:C),r&&(0,z.jsx)(`span`,{className:`conversations-row-phase-badge`,title:`Pre-flush — conversation not yet persisted`,children:`pre-flush`})]}),(0,z.jsxs)(`span`,{className:`conversations-row-meta`,children:[(0,z.jsx)(`button`,{type:`button`,className:`conversations-row-id${D===t?` copied`:``}${k===t?` copy-failed`:``}`,title:C,"aria-label":r?`Copy session key ${C}`:`Copy conversation id ${C}`,onClick:e=>{e.stopPropagation(),F(t)},children:D===t?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(h,{size:10}),` copied`]}):k===t?`copy failed`:C.slice(0,8)}),(0,z.jsxs)(`span`,{className:`conversations-row-time`,children:[(0,z.jsx)(De,{size:10}),(()=>{try{let t=new Date(e.updatedAt),n=Date.now()-t.getTime();return n<6e4?`just now`:n<36e5?`${Math.floor(n/6e4)}m ago`:n<864e5?`${Math.floor(n/36e5)}h ago`:`${Math.floor(n/864e5)}d ago`}catch{return``}})()]})]})]})]}),(0,z.jsx)(`div`,{className:`conversations-row-actions`,children:!a&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`button`,{type:`button`,className:`conversations-action conversations-logs`,title:r?`View pre-flush logs`:`View logs`,"aria-haspopup":`menu`,"aria-expanded":T?.rowId===t,onClick:n=>{n.stopPropagation(),ne(t,{conversationId:e.conversationId,sessionKey:e.sessionKey},n.currentTarget)},children:(0,z.jsx)(c,{size:13})}),!r&&e.conversationId&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`button`,{type:`button`,className:`conversations-action conversations-rename`,title:`Rename conversation`,onClick:()=>ee(e.conversationId),children:(0,z.jsx)(et,{size:13})}),(0,z.jsx)(`button`,{type:`button`,className:`conversations-action conversations-play`,title:`Resume conversation`,disabled:u,onClick:()=>{u||!l||(n(),d(),fetch(`/api/admin/sessions/${encodeURIComponent(e.conversationId)}/resume?session_key=${encodeURIComponent(l)}`,{method:`POST`}).then(e=>e.ok?e.json():Promise.reject(Error(`Failed to resume conversation`))).then(e=>{e.conversationId&&p(e.conversationId);let t=(e.messages??[]).map(e=>({role:e.role===`user`?`admin`:`maxy`,content:e.role===`user`?e.content:void 0,events:e.role===`assistant`?[{type:`text`,content:e.content}]:void 0,timestamp:new Date(e.createdAt).getTime()||0,historical:!0}));t.length>0&&f(t)}).catch(e=>{console.error(`[chat] conversation resume failed:`,e),f([{role:`maxy`,events:[{type:`text`,content:`Could not load conversation history.`}],timestamp:Date.now()-1,historical:!0}])}))},children:(0,z.jsx)(_,{size:13})}),(0,z.jsx)(`button`,{type:`button`,className:`conversations-action conversations-delete`,title:`Delete conversation`,onClick:()=>{s(t=>t.filter(t=>t.conversationId!==e.conversationId)),l&&fetch(`/api/admin/sessions/${encodeURIComponent(e.conversationId)}?session_key=${encodeURIComponent(l)}`,{method:`DELETE`}).catch(e=>console.error(`[chat] conversation delete failed:`,e))},children:(0,z.jsx)(i,{size:13})})]})]})})]},t)})]}),T&&(0,z.jsx)(`div`,{ref:N,className:`conversations-logs-popover`,role:`menu`,style:{top:T.top,right:T.right},children:EE.map(({type:e,label:t})=>(0,z.jsxs)(`a`,{role:`menuitem`,className:`conversations-logs-popover-item`,href:DE({conversationId:T.conversationId,sessionKey:T.sessionKey},e),target:`_blank`,rel:`noopener noreferrer`,onClick:()=>{console.debug(`[admin-modal] open-log`,{conversationId:T.conversationId,sessionKey:T.sessionKey,type:e}),E(null)},children:[(0,z.jsx)(c,{size:12}),(0,z.jsx)(`span`,{children:t})]},e))})]})}):null}function kE({src:e,onClose:t}){return e?(0,z.jsxs)(`div`,{className:`attachment-lightbox`,onClick:t,children:[(0,z.jsx)(`button`,{className:`attachment-lightbox-close`,onClick:t,"aria-label":`Close`,children:`×`}),(0,z.jsx)(`img`,{src:e,alt:`Attachment`,onClick:e=>e.stopPropagation()})]}):null}function AE({show:e,onClose:t,onConfirm:n}){return e?(0,z.jsx)(`div`,{className:`claude-info-overlay`,onClick:t,children:(0,z.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,z.jsxs)(`div`,{className:`claude-info-header`,children:[(0,z.jsx)(`span`,{children:`Compact conversation?`}),(0,z.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:`✕`})]}),(0,z.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,z.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,z.jsx)(w,{variant:`secondary`,size:`sm`,style:{background:`var(--accent)`,flex:1},onClick:()=>{t(),n()},children:`Yes, compact`}),(0,z.jsx)(w,{variant:`secondary`,size:`sm`,style:{flex:1},onClick:t,children:`No`})]})]})}):null}function jE(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,z.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,z.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,z.jsxs)(`div`,{className:`claude-info-header`,children:[(0,z.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`claude-info-icon`}),(0,z.jsx)(`span`,{children:`Claude Code`}),(0,z.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,z.jsxs)(`div`,{className:`claude-info-section`,children:[(0,z.jsxs)(`div`,{className:`claude-info-row`,children:[(0,z.jsx)(`span`,{className:`claude-info-label`,children:`Version`}),(0,z.jsx)(`span`,{className:`claude-info-value`,children:r?r.version:`…`})]}),(0,z.jsxs)(`div`,{className:`claude-info-row`,children:[(0,z.jsx)(`span`,{className:`claude-info-label`,children:`Email`}),(0,z.jsx)(`span`,{className:`claude-info-value`,children:r?.account?.email??`…`})]})]}),(p||d||f>0)&&(0,z.jsxs)(`div`,{className:`claude-info-section`,children:[p&&(0,z.jsxs)(`div`,{className:`claude-info-row`,children:[(0,z.jsx)(`span`,{className:`claude-info-label`,children:`Plan`}),(0,z.jsx)(`span`,{className:`claude-info-value`,style:{textTransform:`capitalize`},children:p})]}),d&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`div`,{className:`claude-info-row`,children:[(0,z.jsx)(`span`,{className:`claude-info-label`,children:`Usage`}),(0,z.jsxs)(`span`,{className:`claude-info-value`,children:[Math.round(d.utilization*100),`%`]})]}),(0,z.jsxs)(`div`,{className:`claude-info-row`,children:[(0,z.jsx)(`span`,{className:`claude-info-label`,children:`Resets in`}),(0,z.jsx)(`span`,{className:`claude-info-value`,children:m(d.resetsAt)})]}),d.isUsingOverage&&(0,z.jsxs)(`div`,{className:`claude-info-row`,children:[(0,z.jsx)(`span`,{className:`claude-info-label`,children:`Overage`}),(0,z.jsx)(`span`,{className:`claude-info-value`,children:`Active`})]})]}),f>0&&(0,z.jsxs)(`div`,{className:`claude-info-row`,children:[(0,z.jsx)(`span`,{className:`claude-info-label`,children:`Session cost`}),(0,z.jsxs)(`span`,{className:`claude-info-value`,children:[`$`,f<.01?f.toFixed(4):f.toFixed(2)]})]})]}),(0,z.jsxs)(`div`,{className:`claude-info-section`,children:[(0,z.jsxs)(`div`,{className:`claude-info-row`,children:[(0,z.jsx)(`span`,{className:`claude-info-label`,children:`Model`}),(0,z.jsx)(`span`,{className:`claude-info-value`,children:r?.model??`…`})]}),(0,z.jsxs)(`div`,{className:`claude-info-row`,children:[(0,z.jsx)(`span`,{className:`claude-info-label`,children:`Context used`}),(0,z.jsx)(`span`,{className:`claude-info-value`,children:l>0?`${l}%`:`—`})]}),(0,z.jsxs)(`div`,{className:`claude-info-row`,children:[(0,z.jsx)(`span`,{className:`claude-info-label`,children:`Tokens`}),(0,z.jsx)(`span`,{className:`claude-info-value`,children:u>0?pt(u):`—`})]}),(0,z.jsxs)(`div`,{className:`claude-info-row`,children:[(0,z.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,z.jsx)(`span`,{className:`claude-info-value`,children:ft(a)})]}),o&&(0,z.jsxs)(`div`,{className:`claude-info-row`,children:[(0,z.jsx)(`span`,{className:`claude-info-label`,children:`Conversation`}),(0,z.jsx)(`span`,{className:`claude-info-value`,style:{fontFamily:`monospace`,fontSize:10},children:o.slice(0,8)})]})]})]})})}var ME=5e3,NE={atPhase:8};function PE({show:e,onClose:t,versionInfo:n,sessionKey:r,onUpgradeComplete:i}){let[a,o]=(0,R.useState)(`prompt`),[s,c]=(0,R.useState)(``),[l,u]=(0,R.useState)(!1),[d,f]=(0,R.useState)(null),[p,m]=(0,R.useState)(null),[h,g]=(0,R.useState)(null),_=(0,R.useRef)(null),v=n?.latest??null,y=(0,R.useCallback)(()=>{_.current&&=(clearInterval(_.current),null)},[]);(0,R.useEffect)(()=>{e||(y(),o(`prompt`),c(``),u(!1),f(null),m(null),g(null))},[e,y]),(0,R.useEffect)(()=>y,[y]),(0,R.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{}},ME),y},[e,a,v,i,y]);let b=(0,R.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,z.jsx)(`div`,{className:`claude-info-overlay`,onClick:()=>{(a===`prompt`||a===`succeeded`||a===`launch-failed`)&&t()},children:(0,z.jsxs)(`div`,{className:`claude-info-modal update-modal`,onClick:e=>e.stopPropagation(),children:[(0,z.jsxs)(`div`,{className:`claude-info-header`,children:[(0,z.jsx)(de,{size:12}),`Software Update`,(0,z.jsx)(`button`,{className:`claude-info-close`,onClick:t,children:`✕`})]}),(0,z.jsxs)(`div`,{className:`update-modal-body`,children:[(0,z.jsxs)(`div`,{className:`update-modal-versions`,children:[(0,z.jsxs)(`div`,{className:`claude-info-row`,children:[(0,z.jsx)(`span`,{className:`claude-info-label`,children:`Installed`}),(0,z.jsxs)(`span`,{className:`claude-info-value`,children:[`v`,n?.installed??`…`]})]}),(0,z.jsxs)(`div`,{className:`claude-info-row`,children:[(0,z.jsx)(`span`,{className:`claude-info-label`,children:`Available`}),(0,z.jsxs)(`span`,{className:`claude-info-value update-version-new`,children:[`v`,v??`…`]})]})]}),(a===`prompt`||a===`priming`||a===`launch-failed`)&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`div`,{className:`form-input__field`,style:{marginTop:12},children:[(0,z.jsx)(`label`,{className:`form-input__label`,htmlFor:`upgrade-sudo`,children:`Device password`}),(0,z.jsxs)(`div`,{className:`tunnel-route__row`,children:[(0,z.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,z.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,z.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,z.jsx)(`div`,{className:`tunnel-route__error`,children:d}),p&&(0,z.jsx)(`div`,{className:`tunnel-route__error`,role:`alert`,children:p})]}),(0,z.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,z.jsx)(`div`,{className:`update-modal-terminal`,style:{height:360,marginTop:10},children:(0,z.jsx)(XT,{actionId:h,sessionKey:r,selfRestart:NE})}),a===`succeeded`&&(0,z.jsxs)(`div`,{className:`update-modal-result`,children:[(0,z.jsx)(we,{size:14,className:`update-success-icon`}),(0,z.jsxs)(`span`,{children:[`Upgraded to v`,v,` — reloading…`]})]})]})]})}):null}function FE(e){let{conversationId:t,sessionKey:n,newConversationDisabled:r,disconnecting:i,onNewConversation:a,onOpenConversations:o,handleDisconnect:s,enterSelection:c,onAfterAction:l}=e,u=!t&&!n;return(0,z.jsxs)(`div`,{className:`chat-actions-menu`,children:[(0,z.jsxs)(`button`,{type:`button`,className:`chat-action`,disabled:r,onClick:()=>{l(),a()},children:[(0,z.jsx)(Le,{size:14}),(0,z.jsx)(`span`,{className:`action-label`,children:`New conversation`})]}),(0,z.jsxs)(`button`,{type:`button`,className:`chat-action`,onClick:()=>{l(),o()},children:[(0,z.jsx)(Ge,{size:14}),(0,z.jsx)(`span`,{className:`action-label`,children:`Conversations`})]}),(0,z.jsxs)(`button`,{type:`button`,className:`chat-action`,disabled:i,onClick:async()=>{l(),await s()},children:[i?(0,z.jsx)(ae,{size:14,className:`animate-spin`}):(0,z.jsx)(be,{size:14}),(0,z.jsx)(`span`,{className:`action-label`,children:i?`Disconnecting...`:`Disconnect Claude`})]}),(0,z.jsxs)(`button`,{type:`button`,className:`chat-action`,disabled:u,title:t?`Download stream log`:n?`Download stream log (pre-flush)`:`No session active — reload the page to start one`,onClick:()=>{if(l(),u){console.debug(`[stream-log-button] no-identity sessionKey=null conversationId=null`);return}let e=document.createElement(`a`);e.href=`${DE({conversationId:t,sessionKey:n},`stream`)}&download=1`,e.click()},children:[(0,z.jsx)(nt,{size:14}),(0,z.jsx)(`span`,{className:`action-label`,children:`Stream log`})]}),(0,z.jsxs)(`button`,{type:`button`,className:`chat-action`,title:`Select messages`,onClick:()=>{l(),c()},children:[(0,z.jsx)(F,{size:14}),(0,z.jsx)(`span`,{className:`action-label`,children:`Select`})]})]})}function IE(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:ne,sendMessage:F,stopStreaming:ie,disconnecting:ae,handleDisconnect:oe,claudeInfo:se,setClaudeInfo:ce,setShowClaudeInfo:le,conversationId:ue,sessionKey:de,onNewConversation:fe,newConversationDisabled:pe,onOpenConversations:me,sidebarVisible:he}=e,[ge,_e]=(0,R.useState)(!1),ve=(0,R.useRef)(null),[ye,be]=(0,R.useState)(!1),xe=(0,R.useRef)(null),Se=(0,R.useRef)(!1),Ce=ee(),we=Ce.state===`recording`||Ce.state===`paused`||Ce.state===`sending`,Te=!we&&!M&&!l.trim()&&g.length===0;async function I(){let e=await Ce.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){ne([...te.current,{text:`[Voice note]`,files:[n],timestamp:Date.now()}]);return}F(`[Voice note]`,[n])}return(0,R.useEffect)(()=>{t||be(!1)},[t]),(0,R.useEffect)(()=>{if(!ye)return;let e=e=>{e.target.closest(`.selection-copy-wrap`)||be(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[ye]),(0,R.useEffect)(()=>{if(!ge)return;let e=e=>{if(e.key===`Escape`){_e(!1);return}if(e.key===`Tab`&&ve.current){let t=ve.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=>{ve.current&&!ve.current.contains(e.target)&&_e(!1)};return document.addEventListener(`keydown`,e),document.addEventListener(`mousedown`,t),()=>{document.removeEventListener(`keydown`,e),document.removeEventListener(`mousedown`,t)}},[ge]),t?(0,z.jsx)(`div`,{className:`chat-input-area`,children:(0,z.jsxs)(`div`,{className:`selection-bar`,children:[(0,z.jsxs)(`span`,{className:`selection-count`,children:[n.size,` Selected`]}),(0,z.jsxs)(`div`,{className:`selection-copy-wrap`,children:[(0,z.jsxs)(`button`,{type:`button`,className:`selection-copy`,onPointerDown:()=>{if(ye){be(!1);return}Se.current=!1,xe.current=setTimeout(()=>{Se.current=!0,be(!0),xe.current=null},500)},onPointerUp:()=>{xe.current!==null&&(clearTimeout(xe.current),xe.current=null)},onPointerLeave:()=>{xe.current!==null&&(clearTimeout(xe.current),xe.current=null)},onPointerCancel:()=>{xe.current!==null&&(clearTimeout(xe.current),xe.current=null)},onClick:async()=>{Se.current||await o(e=>wE(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,z.jsx)(f,{size:18}),(0,z.jsx)(`span`,{children:`Copy`})]}),ye&&(0,z.jsx)(`div`,{className:`copy-menu`,children:[[`all`,`All events`],[`text`,`Text messages only`],[`non-text`,`Non-text only`]].map(([e,t])=>(0,z.jsx)(`button`,{type:`button`,className:`copy-menu-item`,onClick:async()=>{let t=TE(P,e);t&&s(await re(t)),i()},children:t},e))})]}),(0,z.jsx)(`button`,{type:`button`,className:`selection-cancel`,onClick:i,children:`Cancel`})]})}):(0,z.jsxs)(`div`,{className:`chat-input-area`,children:[(0,z.jsx)(`input`,{ref:x,type:`file`,multiple:!0,accept:ht,style:{display:`none`},onChange:e=>{e.target.files&&S([...e.target.files]),e.target.value=``}}),g.length>0&&(0,z.jsx)(`div`,{className:`attachment-strip`,children:g.map((e,t)=>(0,z.jsxs)(`div`,{className:`attachment-chip`,children:[e.type.startsWith(`image/`)?(0,z.jsx)(`img`,{src:URL.createObjectURL(e),alt:e.name,className:`attachment-chip-thumb`}):e.type===`application/pdf`?(0,z.jsx)(c,{size:14}):(0,z.jsx)(E,{size:14}),(0,z.jsx)(`span`,{className:`attachment-chip-name`,children:e.name}),(0,z.jsx)(`button`,{type:`button`,className:`attachment-chip-remove`,onClick:()=>C(t),"aria-label":`Remove ${e.name}`,children:`×`})]},t))}),b&&(0,z.jsx)(`p`,{className:`attach-error`,children:b}),Ce.state===`error`&&Ce.errorMessage&&(0,z.jsxs)(`p`,{className:`voice-error`,role:`alert`,children:[(0,z.jsx)(m,{size:14}),Ce.errorMessage]}),(0,z.jsx)(T,{inputRef:h}),we?(0,z.jsx)(`div`,{className:`chat-form voice-active`,children:(0,z.jsx)(A,{state:Ce.state,elapsedSeconds:Ce.elapsedSeconds,waveform:Ce.waveform,onTogglePause:Ce.togglePause,onDiscard:Ce.discard,onSend:I})}):(0,z.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){ne([...te.current,{text:t,files:[...g],timestamp:Date.now()}]),p(``),v([]),h.current?.resetHeight();return}F(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,z.jsx)(w,{variant:`icon`,type:`button`,onClick:()=>x.current?.click(),"aria-label":`Attach file`,children:(0,z.jsx)(u,{size:14})}),(0,z.jsx)(N,{ref:h,value:l,onChange:p}),j?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(w,{variant:`send`,type:`button`,onClick:()=>ie(!0),"aria-label":`Pause`,style:{background:`var(--text-secondary)`},children:(0,z.jsx)(d,{size:14})}),(0,z.jsx)(w,{variant:`send`,type:`button`,onClick:()=>ie(!1),"aria-label":`Stop`,style:{background:`var(--danger)`},children:(0,z.jsx)(at,{size:14})})]}):Te?(0,z.jsx)(w,{variant:`send`,type:`button`,onClick:Ce.start,"aria-label":`Record voice note`,children:(0,z.jsx)(m,{size:14})}):(0,z.jsx)(w,{variant:`send`,type:`submit`,disabled:!l.trim()&&g.length===0&&!M,"aria-label":`Send message`,children:M?(0,z.jsx)(_,{size:14}):(0,z.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,z.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,z.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,z.jsxs)(`div`,{className:`chat-actions`,ref:ve,children:[!he&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`button`,{className:`burger-trigger`,onClick:()=>_e(e=>!e),"aria-expanded":ge,"aria-haspopup":`true`,"aria-label":`Conversation actions`,children:(0,z.jsx)(je,{size:16})}),(0,z.jsx)(`div`,{className:`actions-menu-items${ge?` actions-menu-open`:``}`,children:(0,z.jsx)(FE,{conversationId:ue,sessionKey:de,newConversationDisabled:pe,disconnecting:ae,onNewConversation:fe,onOpenConversations:me,handleDisconnect:oe,enterSelection:a,onAfterAction:()=>_e(!1)})})]}),(0,z.jsxs)(`div`,{className:`powered-by`,onClick:async()=>{if(le(!0),!se){let e=await fetch(`/api/admin/claude-info`);e.ok&&ce(await e.json())}},children:[(0,z.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`powered-by-icon`}),(0,z.jsx)(`span`,{children:`Powered by Claude Code`})]})]})]})}function LE({onClose:e}){dt();let[t,n]=(0,R.useState)(!1),r=(0,R.useRef)(null),i=(0,R.useRef)(null),a=(0,R.useCallback)(()=>{i.current&&=(clearInterval(i.current),null),r.current&&!r.current.closed&&r.current.close(),r.current=null,n(!1)},[]),o=(0,R.useCallback)(()=>{let t=`/vnc-popout.html?title=${encodeURIComponent(C.productName)}`,o=window.open(t,`maxy-vnc-overlay-popout`,`width=1024,height=768`);o&&(r.current=o,n(!0),i.current=setInterval(()=>{r.current?.closed&&(a(),e())},500))},[a,e]),s=(0,R.useCallback)(()=>{a(),e()},[a,e]);(0,R.useEffect)(()=>{if(t)return;let e=e=>{e.key===`Escape`&&s()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,s]),(0,R.useEffect)(()=>()=>a(),[a]);let c=Ht({handlePopout:o,disabled:t});return t?(0,z.jsxs)(`div`,{className:`browser-overlay-popout`,children:[(0,z.jsx)(D,{className:`browser-viewer__icon`}),(0,z.jsx)(`span`,{className:`browser-viewer__title`,children:C.productName}),(0,z.jsx)(`span`,{className:`browser-viewer__popout-label`,children:`Popped out`}),(0,z.jsx)(w,{variant:`ghost`,size:`sm`,icon:Xe,onClick:()=>{a()},"aria-label":`Pop back in`}),(0,z.jsx)(w,{variant:`ghost`,size:`sm`,icon:me,onClick:s,"aria-label":`Close`})]}):(0,z.jsxs)(`div`,{className:`browser-viewer-fullscreen`,children:[(0,z.jsxs)(`div`,{className:`browser-viewer-fullscreen__bar`,...c,children:[(0,z.jsx)(D,{className:`browser-viewer__icon`}),(0,z.jsx)(`span`,{className:`browser-viewer-fullscreen__title`,children:C.productName}),(0,z.jsxs)(`div`,{className:`browser-viewer-fullscreen__actions`,children:[(0,z.jsx)(w,{variant:`ghost`,size:`sm`,icon:Me,onClick:o,"aria-label":`Pop out`}),(0,z.jsx)(w,{variant:`ghost`,size:`sm`,icon:me,onClick:s,"aria-label":`Close`})]})]}),(0,z.jsx)(`iframe`,{src:`/vnc-viewer.html`,className:`browser-viewer-fullscreen__iframe`,title:C.productName})]})}function RE(e){let{businessName:t,sessionKey:n,conversationId:r,sessions:i,sessionsLoading:a,sessionsError:o,ensureSessionsLoaded:s,onSelectSession:c,onCloseMobileDrawer:l,onCollapseSidebar:u,actions:d}=e;(0,R.useEffect)(()=>{s()},[s]);let f=C.productName,p=t||f,m=(p.trim().charAt(0)||`?`).toUpperCase(),h=(0,R.useMemo)(()=>i.filter(e=>e.name),[i]),g=h.length,_=r??n,[v,y]=(0,R.useState)(!1),b=(0,R.useRef)(null);return(0,R.useEffect)(()=>{if(!v)return;function e(e){b.current&&!b.current.contains(e.target)&&y(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[v]),(0,z.jsxs)(`aside`,{className:`side`,children:[(0,z.jsxs)(`div`,{className:`side-head`,children:[(0,z.jsxs)(`div`,{className:`brand-mark`,children:[f,(0,z.jsx)(`span`,{className:`ast`,children:`*`})]}),(0,z.jsx)(`div`,{className:`side-head-tools`,children:(0,z.jsx)(`button`,{className:`icon-btn`,title:`Collapse sidebar`,type:`button`,"aria-label":`Collapse sidebar`,onClick:u,children:(0,z.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,children:[(0,z.jsx)(`rect`,{x:`2`,y:`3`,width:`12`,height:`10`,rx:`1.4`}),(0,z.jsx)(`path`,{d:`M6 3v10`})]})})})]}),(0,z.jsxs)(`nav`,{className:`side-nav`,children:[(0,z.jsxs)(`button`,{type:`button`,className:`nav-row active`,children:[(0,z.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,children:(0,z.jsx)(`path`,{d:`M3 4.5h10M3 8h10M3 11.5h7`})}),(0,z.jsx)(`span`,{className:`label`,children:`Chat`}),(0,z.jsx)(`span`,{className:`kbd`,children:`⌘ N`})]}),(0,z.jsxs)(`button`,{type:`button`,className:`nav-row`,disabled:!0,title:`Coming soon — Task 809`,children:[(0,z.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,children:[(0,z.jsx)(`path`,{d:`M3 5.5 8 3l5 2.5v5L8 13l-5-2.5v-5Z`}),(0,z.jsx)(`path`,{d:`M3 5.5 8 8l5-2.5M8 8v5`})]}),(0,z.jsx)(`span`,{className:`label`,children:`Projects`}),(0,z.jsx)(`span`,{className:`kbd`})]}),(0,z.jsxs)(`button`,{type:`button`,className:`nav-row`,disabled:!0,title:`Coming soon — Task 810`,children:[(0,z.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,children:[(0,z.jsx)(`rect`,{x:`2.8`,y:`3.2`,width:`10.4`,height:`9.6`,rx:`1.4`}),(0,z.jsx)(`path`,{d:`M5.5 6.2h5M5.5 8.6h5M5.5 11h3`})]}),(0,z.jsx)(`span`,{className:`label`,children:`Artefacts`}),(0,z.jsx)(`span`,{className:`kbd`})]})]}),(0,z.jsxs)(`div`,{className:`side-list`,children:[(0,z.jsxs)(`div`,{className:`group-head`,children:[(0,z.jsx)(`span`,{children:`Recents`}),(0,z.jsx)(`span`,{children:a?`…`:g})]}),o&&(0,z.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:o}),h.map(e=>{let t=e.conversationId??e.sessionKey;return(0,z.jsx)(`button`,{type:`button`,className:`conv${t!==null&&t===_?` active`:``}`,onClick:()=>{let t=e.sessionKey?e.sessionKey.slice(0,8):`null`,n=e.conversationId?e.conversationId.slice(0,8):`null`;console.info(`[admin-session-identity] sessionKey=${t} conversationId=${n} phase=${e.phase} surface=sidebar-recents`),c(e),l()},children:e.name??`(untitled)`},t??e.updatedAt)})]}),(0,z.jsxs)(`div`,{className:`side-foot`,ref:b,children:[(0,z.jsx)(`div`,{className:`avatar`,children:m}),(0,z.jsxs)(`div`,{className:`who`,children:[(0,z.jsx)(`span`,{className:`name`,children:p}),(0,z.jsx)(`span`,{className:`role`,children:`operator`})]}),(0,z.jsx)(`button`,{className:`icon-btn side-foot-actions-trigger`,title:`Conversation actions`,type:`button`,"aria-label":`Conversation actions`,"aria-haspopup":`true`,"aria-expanded":v,onClick:()=>y(e=>!e),children:(0,z.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,children:[(0,z.jsx)(`circle`,{cx:`8`,cy:`3.4`,r:`.9`}),(0,z.jsx)(`circle`,{cx:`8`,cy:`8`,r:`.9`}),(0,z.jsx)(`circle`,{cx:`8`,cy:`12.6`,r:`.9`})]})}),v&&(0,z.jsx)(`div`,{className:`side-foot-actions-popover`,children:(0,z.jsx)(FE,{...d,onAfterAction:()=>y(!1)})})]})]})}var zE=()=>{};function BE({selectedDoc:e,onClose:t}){let n=e!==null,r=(0,R.useRef)(null);(0,R.useEffect)(()=>{let t=e?.docId??null;t!==r.current&&(console.info(`[admin-ui] artefact-pane state=${t?`open`:`closed`} docId=${t??`none`} trigger=${t?`chat-link`:`toolbar-close`}`),r.current=t)},[e]);let i=(e?.tag||e?.name.split(`.`).pop()||`doc`).toUpperCase().slice(0,6),a=e?.revision||`rev 1`;return(0,z.jsxs)(`aside`,{className:`artefact`,"data-open":n,children:[(0,z.jsxs)(`div`,{className:`art-head`,children:[(0,z.jsxs)(`div`,{className:`left`,children:[(0,z.jsx)(`span`,{className:`file-name`,children:e?.name??``}),n&&(0,z.jsx)(`span`,{className:`file-tag`,children:i})]}),(0,z.jsx)(`div`,{className:`right`,children:n&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`button`,{className:`icon-btn`,title:`Copy`,type:`button`,"aria-label":`Copy`,onClick:()=>{re(e.content)},children:(0,z.jsx)(f,{size:14})}),(0,z.jsx)(`button`,{className:`icon-btn`,title:`Refresh`,type:`button`,"aria-label":`Refresh`,children:(0,z.jsx)(pe,{size:14})}),(0,z.jsx)(`button`,{className:`icon-btn`,title:`Close`,type:`button`,"aria-label":`Close`,onClick:t,children:(0,z.jsx)(me,{size:14})})]})})]}),(0,z.jsxs)(`div`,{className:`art-toolbar`,children:[(0,z.jsxs)(`span`,{className:`seg`,children:[(0,z.jsx)(`span`,{className:`bullet`}),(0,z.jsx)(`strong`,{children:`Artefact`})]}),(0,z.jsx)(`span`,{className:`right-meta`,children:a})]}),(0,z.jsx)(`div`,{className:`art-body`,children:n&&(0,z.jsx)(Lw,{data:{title:e.name,content:e.content,readOnly:!0},onSubmit:zE,submitted:!0})}),(0,z.jsxs)(`div`,{className:`art-foot`,children:[(0,z.jsx)(`span`,{className:`left`,children:a}),(0,z.jsx)(`span`,{className:`right in-sync`,children:`in sync`})]})]})}function VE(e){let[t,n]=(0,R.useState)([]),[r,i]=(0,R.useState)(!1),[a,o]=(0,R.useState)(null),[s,c]=(0,R.useState)(null),l=(0,R.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,R.useEffect)(()=>{e||(c(null),n([]),o(null))},[e]);let u=(0,R.useCallback)(()=>l(!1),[l]),d=(0,R.useCallback)(()=>l(!0),[l]);return{sessions:t,setSessions:n,loading:r,loaded:s!==null&&s===e,error:a,ensureLoaded:u,refetch:d}}function HE(){dt();let e=(0,R.useRef)(null),[t,n]=(0,R.useState)(null),[r,a]=(0,R.useState)(!1),[o,s]=(0,R.useState)(!1),[c,l]=(0,R.useState)(``),[u,d]=(0,R.useState)(!1),[f,p]=(0,R.useState)(null),[m,_]=(0,R.useState)(!1),[v,y]=(0,R.useState)(null),[b,x]=(0,R.useState)(null),[w,T]=(0,R.useState)(!1),[E,O]=(0,R.useState)(null),[k,A]=(0,R.useState)(!1),[j,M]=(0,R.useState)(null),[N,P]=(0,R.useState)(!1),[ee,te]=(0,R.useState)(!1),[F,ie]=(0,R.useState)(!1),[se,de]=(0,R.useState)(!1),[fe,pe]=(0,R.useState)(null),[he,ge]=(0,R.useState)(()=>typeof window<`u`&&window.matchMedia(`(min-width: 641px)`).matches);(0,R.useEffect)(()=>{let e=window.matchMedia(`(min-width: 641px)`),t=e=>ge(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let _e=(0,R.useRef)(!1),ve=(0,R.useRef)(!1),ye=(0,R.useRef)(!1),be=(0,R.useRef)(!1),xe=(0,R.useRef)(null),[Se,Ce]=(0,R.useState)(null),we=g(),Te=mt(),I=bt(),Ee=kt(),De=VE(I.sessionKey),L=Ot({sessionKey:I.sessionKey,setSessionKey:I.setSessionKey,setAppState:I.setAppState,setConversationId:I.setConversationId,startElapsedTimer:Te.startElapsedTimer,stopElapsedTimer:Te.stopElapsedTimer,resetTimerState:Te.resetTimerState,pausedElapsedRef:Te.pausedElapsedRef,expandAllDefaultRef:I.expandAllDefaultRef,setExpandAll:I.setExpandAll,getPendingFiles:()=>Ee.pendingFiles,clearPendingFiles:Ee.clearFiles,inputRef:e});(0,R.useEffect)(()=>{l(window.location.hostname.startsWith(`admin.`)?window.location.origin.replace(`admin.`,`public.`):window.location.origin)},[]),(0,R.useEffect)(()=>{function e(e){e.key===`Escape`&&(t?n(null):we.selectionMode&&we.exitSelection())}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,we.selectionMode]),(0,R.useEffect)(()=>{(I.appState===`set-pin`||I.appState===`enter-pin`)&&setTimeout(()=>I.pinInputRef.current?.focus(),100),I.appState===`chat`&&setTimeout(()=>e.current?.focus(),100)},[I.appState,L.greetingGeneration]),(0,R.useEffect)(()=>{if(I.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)},[I.appState]);let Oe=(0,R.useRef)(L.greetingGeneration);if((0,R.useEffect)(()=>{L.greetingGeneration!==Oe.current&&(Oe.current=L.greetingGeneration,I.onboardingComplete===!1&&(_e.current=!1))},[L.greetingGeneration,I.onboardingComplete]),(0,R.useEffect)(()=>{I.appState===`chat`&&I.onboardingComplete===!1&&(_e.current||(_e.current=!0,L.sendSystemPrompt(`[Begin onboarding.]`)))},[I.appState,I.onboardingComplete,L.greetingGeneration]),(0,R.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,R.useEffect)(()=>{if(I.appState!==`chat`){ye.current=!1,be.current=!1;return}if(ye.current)return;ye.current=!0;let e=!1;return fetch(`/api/admin/version`).then(e=>e.json()).then(t=>{e||(O(t),!(!t.updateAvailable||be.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}},[I.appState]),(0,R.useEffect)(()=>{if(I.appState!==`chat`||!I.sessionKey)return;let e=I.conversationId?`flushed`:`pre-flush`,t=I.sessionKey.slice(0,8),n=I.conversationId?I.conversationId.slice(0,8):`null`;console.info(`[admin-session-identity] sessionKey=${t} conversationId=${n} phase=${e} surface=chat-header`)},[I.appState,I.sessionKey,I.conversationId]),(0,R.useEffect)(()=>{if(I.appState!==`chat`){ve.current=!1;return}if(ve.current||!De.loaded)return;ve.current=!0;let e=De.sessions.filter(e=>e.name).length,t=fe?`open`:`closed`;console.info(`[admin-ui] platform-shell brand=${C.productName} sidebar=${e} artefact=${t}`)},[I.appState,De.loaded,De.sessions,fe]),(0,R.useEffect)(()=>{if(!u){p(null),y(null),x(null),O(null);return}function e(e){xe.current&&!xe.current.contains(e.target)&&d(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[u]),(0,R.useEffect)(()=>{if(typeof BroadcastChannel>`u`)return;let e=new BroadcastChannel(`platform-onboarding`);return e.onmessage=e=>{e.data?.type===`remote-password-set`&&L.sendMessageRef.current(`I've set the remote password`)},()=>e.close()},[]),I.appState===`loading`)return(0,z.jsx)(`div`,{className:`chat-page admin-page`,children:(0,z.jsx)(`header`,{className:`chat-header`,children:(0,z.jsx)(`img`,{src:ne,alt:C.productName,className:`chat-logo`})})});if(I.appState===`set-pin`)return(0,z.jsx)(jt,{pin:I.pin,setPin:I.setPin,confirmPin:I.confirmPin,setConfirmPin:I.setConfirmPin,showPin:I.showPin,setShowPin:I.setShowPin,pinLoading:I.pinLoading,pinError:I.pinError,pinInputRef:I.pinInputRef,confirmPinInputRef:I.confirmPinInputRef,setPinFormRef:I.setPinFormRef,onSubmit:I.handleSetPin});if(I.appState===`onboarding-choice`)return(0,z.jsx)(Ft,{setAppState:I.setAppState,setOnboardingComplete:I.setOnboardingComplete});if(I.appState===`connect-claude`)return(0,z.jsx)(Pt,{authPolling:I.authPolling,setAuthPolling:I.setAuthPolling,authLoading:I.authLoading,setAuthLoading:I.setAuthLoading,pinError:I.pinError,setPinError:I.setPinError,setAppState:I.setAppState});if(I.appState===`enter-pin`)return(0,z.jsx)(Mt,{pin:I.pin,setPin:I.setPin,showPin:I.showPin,setShowPin:I.setShowPin,pinLoading:I.pinLoading,pinError:I.pinError,pinInputRef:I.pinInputRef,onSubmit:I.handleLogin,onChangePin:I.handleChangePin});if(I.appState===`account-picker`)return(0,z.jsx)(Nt,{accounts:I.accounts,loading:I.accountPickerLoading,error:I.pinError,onSelect:I.handleAccountSelect});let ke=fe?`open`:`closed`,Ae=`platform${F?` menu-open`:``}${se?` sidebar-collapsed`:``}`,je=e=>{L.isStreaming||(L.resetConversation(),L.setMessages([]),I.setConversationId(e.conversationId??null))},Ne={conversationId:I.conversationId,sessionKey:I.sessionKey,newConversationDisabled:L.isStreaming||L.isCompacting,disconnecting:I.disconnecting,onNewConversation:L.startNewConversation,onOpenConversations:()=>{T(!0),De.refetch()},handleDisconnect:I.handleDisconnect,enterSelection:we.enterSelection};return(0,z.jsx)(S,{value:{onShowVnc:()=>P(!0)},children:(0,z.jsxs)(`div`,{className:Ae,"data-artefact":ke,children:[(0,z.jsx)(`div`,{className:`scrim`,onClick:()=>{ie(!1),console.info(`[admin-ui] mobile-drawer state=closed`)}}),(0,z.jsx)(RE,{businessName:I.businessName??null,sessionKey:I.sessionKey,conversationId:I.conversationId,sessions:De.sessions,sessionsLoading:De.loading,sessionsError:De.error,ensureSessionsLoaded:De.ensureLoaded,onSelectSession:je,onCloseMobileDrawer:()=>{F&&(ie(!1),console.info(`[admin-ui] mobile-drawer state=closed`))},onCollapseSidebar:()=>de(!0),actions:Ne}),(0,z.jsxs)(`div`,{className:`chat-page admin-page`,children:[(0,z.jsxs)(`header`,{className:`chat-header`,children:[(0,z.jsx)(`button`,{type:`button`,className:`icon-btn mobile-menu`,"aria-label":`Show sidebar`,title:`Show sidebar`,onClick:()=>{if(se){de(!1),console.info(`[admin-ui] sidebar-collapsed state=false trigger=chat-header-button`);return}ie(e=>{let t=!e;return console.info(`[admin-ui] mobile-drawer state=${t?`open`:`closed`}`),t})},children:(0,z.jsx)($e,{size:16})}),(0,z.jsx)(`img`,{src:ne,alt:C.productName,className:`chat-logo`}),(!C.logoContainsName||I.businessName)&&(0,z.jsx)(`div`,{children:(0,z.jsx)(`h1`,{className:`chat-tagline`,children:I.businessName||C.productName})}),(I.sessionKey||I.conversationId)&&(0,z.jsxs)(`button`,{type:`button`,className:`chat-session-chip chat-session-chip-${I.conversationId?`flushed`:`pre-flush`}`+(Se===`copied`?` copied`:``)+(Se===`failed`?` copy-failed`:``),title:I.conversationId?`conversation ${I.conversationId} — click to copy`:`session ${I.sessionKey} (pre-flush, first turn pending) — click to copy`,onClick:async()=>{let e=I.conversationId??I.sessionKey;e&&(Ce(await re(e)?`copied`:`failed`),setTimeout(()=>Ce(null),1200))},children:[(0,z.jsx)(`span`,{className:`chat-session-chip-label`,children:I.conversationId?`conversation`:`session`}),(0,z.jsxs)(`span`,{className:`chat-session-chip-id`,children:[(I.conversationId??I.sessionKey??``).slice(0,8),`…`]})]}),(0,z.jsxs)(`div`,{className:`chat-burger-wrap`,ref:xe,children:[(0,z.jsx)(`button`,{type:`button`,className:`chat-burger`,onClick:()=>d(e=>!e),"aria-label":`Menu`,"aria-haspopup":`true`,"aria-expanded":u,children:(0,z.jsx)(le,{size:20})}),u&&(0,z.jsxs)(`div`,{className:`chat-menu`,children:[(0,z.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:async()=>{if(!(N||ee)){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`);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,z.jsx)(D,{size:14}),` Browser`,ee&&(0,z.jsx)(ae,{size:12,className:`spin`})]}),(0,z.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{d(!1),window.location.href=`/data`},children:[(0,z.jsx)(ce,{size:14}),` Data`]}),(0,z.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{d(!1),window.location.href=`/graph`},children:[(0,z.jsx)(ue,{size:14}),` Graph`]}),(0,z.jsx)(`div`,{className:`chat-menu-divider`}),(0,z.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,z.jsx)(Me,{size:14}),` Public`,m&&(0,z.jsx)(ae,{size:12,className:`spin`})]}),f!==null&&(0,z.jsxs)(`div`,{className:`chat-menu-agents`,children:[v&&(0,z.jsx)(`span`,{className:`chat-menu-agent-error`,children:v}),f.length===0&&!v&&(0,z.jsx)(`span`,{className:`chat-menu-agent-empty`,children:`No public agents configured`}),f.map(e=>(0,z.jsxs)(`div`,{className:`chat-menu-item chat-menu-agent-item`,children:[(0,z.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),(0,z.jsxs)(`span`,{className:`agent-text`,children:[(0,z.jsx)(`span`,{className:`agent-display-name`,children:e.displayName}),(0,z.jsxs)(`span`,{className:`agent-slug`,children:[`/`,e.slug]})]}),b===e.slug?(0,z.jsxs)(`span`,{className:`agent-actions agent-confirm`,children:[(0,z.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,z.jsx)(h,{size:12})}),(0,z.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-no`,title:`Cancel`,onClick:()=>x(null),children:(0,z.jsx)(me,{size:12})})]}):(0,z.jsxs)(`span`,{className:`agent-actions`,children:[(0,z.jsx)(`a`,{href:`${c}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`agent-action-btn`,title:`Open agent`,onClick:()=>d(!1),children:(0,z.jsx)(Me,{size:12})}),(0,z.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-delete-btn`,title:`Delete agent`,onClick:()=>x(e.slug),children:(0,z.jsx)(i,{size:12})})]})]},e.slug))]}),(0,z.jsx)(`div`,{className:`chat-menu-divider`}),E?.updateAvailable?(0,z.jsxs)(`button`,{type:`button`,className:`chat-menu-version`,onClick:()=>{E.latest&&(M(E),d(!1),A(!0))},children:[(0,z.jsx)(Be,{size:14}),(0,z.jsxs)(`span`,{className:`version-installed`,children:[`v`,E.installed,(0,z.jsx)(`span`,{className:`version-update-dot`})]})]}):(0,z.jsxs)(`div`,{className:`chat-menu-version chat-menu-version-passive`,children:[(0,z.jsx)(Be,{size:14}),(0,z.jsxs)(`span`,{className:`version-installed`,children:[E?`v${E.installed}`:`…`,E&&!E.updateAvailable&&(0,z.jsx)(`span`,{className:`version-uptodate-dot`})]})]}),(0,z.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{d(!1),I.handleLogout(),L.setMessages([])},children:[(0,z.jsx)(oe,{size:14}),` Log out`]})]})]})]}),(0,z.jsxs)(`div`,{className:`chat-content`,children:[(0,z.jsx)(SE,{messages:L.messages,isStreaming:L.isStreaming,elapsedSeconds:Te.elapsedSeconds,sessionTurnStart:Te.sessionTurnStart,expandAll:I.expandAll,setExpandAll:I.setExpandAll,conversationCompacted:L.conversationCompacted,isCompacting:L.isCompacting,setShowCompactConfirm:s,handleComponentSubmit:L.handleComponentSubmit,effectiveSubmitted:L.effectiveSubmitted,selectionMode:we.selectionMode,selectedItems:we.selectedItems,toggleSelectItem:we.toggleSelectItem,sessionKey:I.sessionKey,setLightboxSrc:n,messageQueue:L.messageQueue,messageQueueRef:L.messageQueueRef,setQueue:L.setQueue,sendMessage:L.sendMessage,appState:I.appState,onboardingComplete:I.onboardingComplete,onOpenArtefact:pe}),(0,z.jsx)(CE,{offer:L.topicChangeOffer,onFreshStart:L.handleTopicFreshStart,onContinue:L.handleTopicContinue,disabled:L.isStreaming}),(0,z.jsx)(IE,{selectionMode:we.selectionMode,selectedItems:we.selectedItems,copyToast:we.copyToast||null,exitSelection:we.exitSelection,enterSelection:we.enterSelection,copySelected:we.copySelected,showCopyToast:we.showCopyToast,input:L.input,setInput:L.setInput,inputRef:e,pendingFiles:Ee.pendingFiles,setPendingFiles:Ee.setPendingFiles,isDragOver:Ee.isDragOver,attachError:Ee.attachError,fileInputRef:Ee.fileInputRef,addFiles:Ee.addFiles,removeFile:Ee.removeFile,onDragOver:Ee.onDragOver,onDragLeave:Ee.onDragLeave,onDrop:Ee.onDrop,isStreaming:L.isStreaming,wasPaused:L.wasPaused,messages:L.messages,messageQueueRef:L.messageQueueRef,setQueue:L.setQueue,sendMessage:L.sendMessage,stopStreaming:L.stopStreaming,disconnecting:I.disconnecting,handleDisconnect:I.handleDisconnect,claudeInfo:I.claudeInfo,setClaudeInfo:I.setClaudeInfo,setShowClaudeInfo:a,conversationId:I.conversationId,sessionKey:I.sessionKey,onNewConversation:L.startNewConversation,newConversationDisabled:L.isStreaming||L.isCompacting,onOpenConversations:()=>{T(!0),De.refetch()},sidebarVisible:he&&!se})]}),we.copyToast&&(0,z.jsx)(`span`,{className:`copy-toast${we.copyToast===`failed`?` copy-toast-failed`:``}`,children:we.copyToast===`copied`?`Copied`:`Copy failed`}),(0,z.jsx)(OE,{show:w,onClose:()=>T(!1),conversationsLoading:De.loading,conversationsError:De.error,conversationsList:De.sessions,setConversationsList:De.setSessions,sessionKey:I.sessionKey,isStreaming:L.isStreaming,resetConversation:L.resetConversation,setMessages:L.setMessages,setConversationId:I.setConversationId}),(0,z.jsx)(kE,{src:t,onClose:()=>n(null)}),(0,z.jsx)(AE,{show:o,onClose:()=>s(!1),onConfirm:L.handleCompactNow}),(0,z.jsx)(jE,{show:r,onClose:()=>{a(!1),I.setClaudeInfo(null)},claudeInfo:I.claudeInfo,messages:L.messages,sessionElapsed:Te.sessionElapsed,conversationId:I.conversationId}),(0,z.jsx)(PE,{show:k,onClose:()=>{A(!1),be.current=!0},versionInfo:j,sessionKey:I.sessionKey,onUpgradeComplete:()=>O(null)}),N&&(0,z.jsx)(LE,{onClose:()=>P(!1)})]}),(0,z.jsx)(BE,{selectedDoc:fe,onClose:()=>pe(null)})]})})}(0,ge.createRoot)(document.getElementById(`root`)).render((0,z.jsx)(HE,{}));
352
+ `)}var EE=[{type:`stream`,label:`Stream`},{type:`error`,label:`Errors`},{type:`sse`,label:`SSE`}];function DE(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 OE(e){let{show:t,onClose:n,conversationsLoading:r,conversationsError:a,conversationsList:o,setConversationsList:s,sessionKey:l,isStreaming:u,resetConversation:d,setMessages:f,setConversationId:p}=e,[m,g]=(0,R.useState)(null),[v,y]=(0,R.useState)(null),[b,x]=(0,R.useState)(``),[S,C]=(0,R.useState)(!1),w=(0,R.useRef)(null),[T,E]=(0,R.useState)(null),[D,O]=(0,R.useState)(null),[k,A]=(0,R.useState)(null),j=(0,R.useRef)(null),M=(0,R.useRef)(null),N=(0,R.useRef)(null);(0,R.useEffect)(()=>{t||(g(null),y(null),x(``),C(!1),E(null),O(null),A(null),j.current&&=(clearTimeout(j.current),null),M.current&&=(clearTimeout(M.current),null))},[t]),(0,R.useEffect)(()=>{if(!T)return;function e(e){let t=e.target;t&&N.current?.contains(t)||t&&t.closest?.(`.conversations-logs`)||E(null)}function t(e){e.key===`Escape`&&E(null)}return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[T]),(0,R.useEffect)(()=>{v?.phase===`editing`&&(w.current?.focus(),w.current?.select())},[v]);function P(){g(null),y(null),x(``),C(!1)}async function ee(e){if(l){P(),g(e),y({phase:`loading`});try{let t=await fetch(`/api/admin/sessions/${encodeURIComponent(e)}/label?session_key=${encodeURIComponent(l)}`,{method:`POST`});if(!t.ok){y({phase:`error`,reason:(await t.json().catch(()=>({}))).error||`Request failed`});return}let n=await t.json();n.label?(y({phase:`editing`}),x(n.label)):y({phase:`error`,reason:`Not enough message content to suggest a name`})}catch(e){console.error(`[admin-modal] label suggestion failed:`,e),y({phase:`error`,reason:e instanceof Error?e.message:String(e)})}}}async function te(e){if(!(!l||!b.trim()||S)){C(!0);try{let t=await fetch(`/api/admin/sessions/${encodeURIComponent(e)}/label`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({label:b.trim(),session_key:l})});if(!t.ok){y({phase:`error`,reason:(await t.json().catch(()=>({}))).error||`Rename failed`}),C(!1);return}s(t=>t.map(t=>t.conversationId===e?{...t,name:b.trim()}:t)),P()}catch(e){console.error(`[admin-modal] label rename failed:`,e),y({phase:`error`,reason:e instanceof Error?e.message:String(e)}),C(!1)}}}function ne(e,t,n){if(T?.rowId===e){E(null);return}let r=n.getBoundingClientRect();E({rowId:e,conversationId:t.conversationId,sessionKey:t.sessionKey,top:r.bottom+4,right:Math.max(8,window.innerWidth-r.right)})}async function F(e){await re(e)?(O(e),A(null),j.current&&clearTimeout(j.current),j.current=setTimeout(()=>O(null),1500)):(A(e),O(null),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>A(null),1500))}return t?(0,z.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,z.jsxs)(`div`,{className:`claude-info-modal conversations-modal`,onClick:e=>e.stopPropagation(),children:[(0,z.jsxs)(`div`,{className:`claude-info-header`,children:[(0,z.jsx)(Ge,{size:12}),`Conversations`,(0,z.jsx)(`button`,{className:`claude-info-close`,onClick:n,children:`✕`})]}),(0,z.jsxs)(`div`,{className:`conversations-list`,children:[r&&(0,z.jsxs)(`div`,{className:`conversations-empty`,children:[(0,z.jsx)(ae,{size:14,className:`spin`}),` Loading…`]}),a&&(0,z.jsx)(`div`,{className:`conversations-empty conversations-error`,children:a}),!r&&!a&&o.length===0&&(0,z.jsx)(`div`,{className:`conversations-empty`,children:`No recent conversations`}),!r&&!a&&o.map(e=>{let t=e.conversationId??e.sessionKey??``,r=e.phase===`pre-flush`,a=!r&&m===e.conversationId,o=a&&v?.phase===`loading`,g=a&&v?.phase===`editing`,y=a&&v?.phase===`error`,C=e.conversationId??e.sessionKey??``;return(0,z.jsxs)(`div`,{className:`conversations-row${r?` conversations-row-pre-flush`:``}`,children:[(0,z.jsxs)(`div`,{className:`conversations-row-info`,children:[o&&(0,z.jsxs)(`span`,{className:`conversations-row-name conversations-edit-loading`,children:[(0,z.jsx)(ae,{size:12,className:`spin`}),` Generating suggestion…`]}),g&&(0,z.jsxs)(`div`,{className:`conversations-edit-inline`,children:[(0,z.jsx)(`input`,{ref:w,type:`text`,className:`conversations-edit-input`,value:b,onChange:e=>x(e.target.value),onKeyDown:t=>{t.key===`Enter`&&b.trim()&&te(e.conversationId),t.key===`Escape`&&P()},maxLength:200}),(0,z.jsx)(`button`,{type:`button`,className:`conversations-action conversations-confirm`,title:`Confirm rename`,disabled:!b.trim()||S,onClick:()=>te(e.conversationId),children:S?(0,z.jsx)(ae,{size:13,className:`spin`}):(0,z.jsx)(h,{size:13})}),(0,z.jsx)(`button`,{type:`button`,className:`conversations-action conversations-cancel`,title:`Cancel`,onClick:P,children:(0,z.jsx)(me,{size:13})})]}),y&&(0,z.jsxs)(`div`,{className:`conversations-edit-inline`,children:[(0,z.jsx)(`span`,{className:`conversations-edit-error`,children:v.reason}),(0,z.jsx)(`button`,{type:`button`,className:`conversations-action conversations-retry`,title:`Retry`,onClick:()=>ee(e.conversationId),children:(0,z.jsx)(pe,{size:13})}),(0,z.jsx)(`button`,{type:`button`,className:`conversations-action conversations-cancel`,title:`Cancel`,onClick:P,children:(0,z.jsx)(me,{size:13})})]}),!a&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`span`,{className:`conversations-row-name`,children:[e.name||(r?`session ${C}`:C),r&&(0,z.jsx)(`span`,{className:`conversations-row-phase-badge`,title:`Pre-flush — conversation not yet persisted`,children:`pre-flush`})]}),(0,z.jsxs)(`span`,{className:`conversations-row-meta`,children:[(0,z.jsx)(`button`,{type:`button`,className:`conversations-row-id${D===t?` copied`:``}${k===t?` copy-failed`:``}`,title:C,"aria-label":r?`Copy session key ${C}`:`Copy conversation id ${C}`,onClick:e=>{e.stopPropagation(),F(t)},children:D===t?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(h,{size:10}),` copied`]}):k===t?`copy failed`:C.slice(0,8)}),(0,z.jsxs)(`span`,{className:`conversations-row-time`,children:[(0,z.jsx)(De,{size:10}),(()=>{try{let t=new Date(e.updatedAt),n=Date.now()-t.getTime();return n<6e4?`just now`:n<36e5?`${Math.floor(n/6e4)}m ago`:n<864e5?`${Math.floor(n/36e5)}h ago`:`${Math.floor(n/864e5)}d ago`}catch{return``}})()]})]})]})]}),(0,z.jsx)(`div`,{className:`conversations-row-actions`,children:!a&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`button`,{type:`button`,className:`conversations-action conversations-logs`,title:r?`View pre-flush logs`:`View logs`,"aria-haspopup":`menu`,"aria-expanded":T?.rowId===t,onClick:n=>{n.stopPropagation(),ne(t,{conversationId:e.conversationId,sessionKey:e.sessionKey},n.currentTarget)},children:(0,z.jsx)(c,{size:13})}),!r&&e.conversationId&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`button`,{type:`button`,className:`conversations-action conversations-rename`,title:`Rename conversation`,onClick:()=>ee(e.conversationId),children:(0,z.jsx)(et,{size:13})}),(0,z.jsx)(`button`,{type:`button`,className:`conversations-action conversations-play`,title:`Resume conversation`,disabled:u,onClick:()=>{u||!l||(n(),d(),fetch(`/api/admin/sessions/${encodeURIComponent(e.conversationId)}/resume?session_key=${encodeURIComponent(l)}`,{method:`POST`}).then(e=>e.ok?e.json():Promise.reject(Error(`Failed to resume conversation`))).then(e=>{e.conversationId&&p(e.conversationId);let t=(e.messages??[]).map(e=>({role:e.role===`user`?`admin`:`maxy`,content:e.role===`user`?e.content:void 0,events:e.role===`assistant`?[{type:`text`,content:e.content}]:void 0,timestamp:new Date(e.createdAt).getTime()||0,historical:!0}));t.length>0&&f(t)}).catch(e=>{console.error(`[chat] conversation resume failed:`,e),f([{role:`maxy`,events:[{type:`text`,content:`Could not load conversation history.`}],timestamp:Date.now()-1,historical:!0}])}))},children:(0,z.jsx)(_,{size:13})}),(0,z.jsx)(`button`,{type:`button`,className:`conversations-action conversations-delete`,title:`Delete conversation`,onClick:()=>{s(t=>t.filter(t=>t.conversationId!==e.conversationId)),l&&fetch(`/api/admin/sessions/${encodeURIComponent(e.conversationId)}?session_key=${encodeURIComponent(l)}`,{method:`DELETE`}).catch(e=>console.error(`[chat] conversation delete failed:`,e))},children:(0,z.jsx)(i,{size:13})})]})]})})]},t)})]}),T&&(0,z.jsx)(`div`,{ref:N,className:`conversations-logs-popover`,role:`menu`,style:{top:T.top,right:T.right},children:EE.map(({type:e,label:t})=>(0,z.jsxs)(`a`,{role:`menuitem`,className:`conversations-logs-popover-item`,href:DE({conversationId:T.conversationId,sessionKey:T.sessionKey},e),target:`_blank`,rel:`noopener noreferrer`,onClick:()=>{console.debug(`[admin-modal] open-log`,{conversationId:T.conversationId,sessionKey:T.sessionKey,type:e}),E(null)},children:[(0,z.jsx)(c,{size:12}),(0,z.jsx)(`span`,{children:t})]},e))})]})}):null}function kE({src:e,onClose:t}){return e?(0,z.jsxs)(`div`,{className:`attachment-lightbox`,onClick:t,children:[(0,z.jsx)(`button`,{className:`attachment-lightbox-close`,onClick:t,"aria-label":`Close`,children:`×`}),(0,z.jsx)(`img`,{src:e,alt:`Attachment`,onClick:e=>e.stopPropagation()})]}):null}function AE({show:e,onClose:t,onConfirm:n}){return e?(0,z.jsx)(`div`,{className:`claude-info-overlay`,onClick:t,children:(0,z.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,z.jsxs)(`div`,{className:`claude-info-header`,children:[(0,z.jsx)(`span`,{children:`Compact conversation?`}),(0,z.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:`✕`})]}),(0,z.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,z.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,z.jsx)(w,{variant:`secondary`,size:`sm`,style:{background:`var(--accent)`,flex:1},onClick:()=>{t(),n()},children:`Yes, compact`}),(0,z.jsx)(w,{variant:`secondary`,size:`sm`,style:{flex:1},onClick:t,children:`No`})]})]})}):null}function jE(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,z.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,z.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,z.jsxs)(`div`,{className:`claude-info-header`,children:[(0,z.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`claude-info-icon`}),(0,z.jsx)(`span`,{children:`Claude Code`}),(0,z.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,z.jsxs)(`div`,{className:`claude-info-section`,children:[(0,z.jsxs)(`div`,{className:`claude-info-row`,children:[(0,z.jsx)(`span`,{className:`claude-info-label`,children:`Version`}),(0,z.jsx)(`span`,{className:`claude-info-value`,children:r?r.version:`…`})]}),(0,z.jsxs)(`div`,{className:`claude-info-row`,children:[(0,z.jsx)(`span`,{className:`claude-info-label`,children:`Email`}),(0,z.jsx)(`span`,{className:`claude-info-value`,children:r?.account?.email??`…`})]})]}),(p||d||f>0)&&(0,z.jsxs)(`div`,{className:`claude-info-section`,children:[p&&(0,z.jsxs)(`div`,{className:`claude-info-row`,children:[(0,z.jsx)(`span`,{className:`claude-info-label`,children:`Plan`}),(0,z.jsx)(`span`,{className:`claude-info-value`,style:{textTransform:`capitalize`},children:p})]}),d&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`div`,{className:`claude-info-row`,children:[(0,z.jsx)(`span`,{className:`claude-info-label`,children:`Usage`}),(0,z.jsxs)(`span`,{className:`claude-info-value`,children:[Math.round(d.utilization*100),`%`]})]}),(0,z.jsxs)(`div`,{className:`claude-info-row`,children:[(0,z.jsx)(`span`,{className:`claude-info-label`,children:`Resets in`}),(0,z.jsx)(`span`,{className:`claude-info-value`,children:m(d.resetsAt)})]}),d.isUsingOverage&&(0,z.jsxs)(`div`,{className:`claude-info-row`,children:[(0,z.jsx)(`span`,{className:`claude-info-label`,children:`Overage`}),(0,z.jsx)(`span`,{className:`claude-info-value`,children:`Active`})]})]}),f>0&&(0,z.jsxs)(`div`,{className:`claude-info-row`,children:[(0,z.jsx)(`span`,{className:`claude-info-label`,children:`Session cost`}),(0,z.jsxs)(`span`,{className:`claude-info-value`,children:[`$`,f<.01?f.toFixed(4):f.toFixed(2)]})]})]}),(0,z.jsxs)(`div`,{className:`claude-info-section`,children:[(0,z.jsxs)(`div`,{className:`claude-info-row`,children:[(0,z.jsx)(`span`,{className:`claude-info-label`,children:`Model`}),(0,z.jsx)(`span`,{className:`claude-info-value`,children:r?.model??`…`})]}),(0,z.jsxs)(`div`,{className:`claude-info-row`,children:[(0,z.jsx)(`span`,{className:`claude-info-label`,children:`Context used`}),(0,z.jsx)(`span`,{className:`claude-info-value`,children:l>0?`${l}%`:`—`})]}),(0,z.jsxs)(`div`,{className:`claude-info-row`,children:[(0,z.jsx)(`span`,{className:`claude-info-label`,children:`Tokens`}),(0,z.jsx)(`span`,{className:`claude-info-value`,children:u>0?pt(u):`—`})]}),(0,z.jsxs)(`div`,{className:`claude-info-row`,children:[(0,z.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,z.jsx)(`span`,{className:`claude-info-value`,children:ft(a)})]}),o&&(0,z.jsxs)(`div`,{className:`claude-info-row`,children:[(0,z.jsx)(`span`,{className:`claude-info-label`,children:`Conversation`}),(0,z.jsx)(`span`,{className:`claude-info-value`,style:{fontFamily:`monospace`,fontSize:10},children:o.slice(0,8)})]})]})]})})}var ME=5e3,NE={atPhase:8};function PE({show:e,onClose:t,versionInfo:n,sessionKey:r,onUpgradeComplete:i}){let[a,o]=(0,R.useState)(`prompt`),[s,c]=(0,R.useState)(``),[l,u]=(0,R.useState)(!1),[d,f]=(0,R.useState)(null),[p,m]=(0,R.useState)(null),[h,g]=(0,R.useState)(null),_=(0,R.useRef)(null),v=n?.latest??null,y=(0,R.useCallback)(()=>{_.current&&=(clearInterval(_.current),null)},[]);(0,R.useEffect)(()=>{e||(y(),o(`prompt`),c(``),u(!1),f(null),m(null),g(null))},[e,y]),(0,R.useEffect)(()=>y,[y]),(0,R.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{}},ME),y},[e,a,v,i,y]);let b=(0,R.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,z.jsx)(`div`,{className:`claude-info-overlay`,onClick:()=>{(a===`prompt`||a===`succeeded`||a===`launch-failed`)&&t()},children:(0,z.jsxs)(`div`,{className:`claude-info-modal update-modal`,onClick:e=>e.stopPropagation(),children:[(0,z.jsxs)(`div`,{className:`claude-info-header`,children:[(0,z.jsx)(de,{size:12}),`Software Update`,(0,z.jsx)(`button`,{className:`claude-info-close`,onClick:t,children:`✕`})]}),(0,z.jsxs)(`div`,{className:`update-modal-body`,children:[(0,z.jsxs)(`div`,{className:`update-modal-versions`,children:[(0,z.jsxs)(`div`,{className:`claude-info-row`,children:[(0,z.jsx)(`span`,{className:`claude-info-label`,children:`Installed`}),(0,z.jsxs)(`span`,{className:`claude-info-value`,children:[`v`,n?.installed??`…`]})]}),(0,z.jsxs)(`div`,{className:`claude-info-row`,children:[(0,z.jsx)(`span`,{className:`claude-info-label`,children:`Available`}),(0,z.jsxs)(`span`,{className:`claude-info-value update-version-new`,children:[`v`,v??`…`]})]})]}),(a===`prompt`||a===`priming`||a===`launch-failed`)&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`div`,{className:`form-input__field`,style:{marginTop:12},children:[(0,z.jsx)(`label`,{className:`form-input__label`,htmlFor:`upgrade-sudo`,children:`Device password`}),(0,z.jsxs)(`div`,{className:`tunnel-route__row`,children:[(0,z.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,z.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,z.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,z.jsx)(`div`,{className:`tunnel-route__error`,children:d}),p&&(0,z.jsx)(`div`,{className:`tunnel-route__error`,role:`alert`,children:p})]}),(0,z.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,z.jsx)(`div`,{className:`update-modal-terminal`,style:{height:360,marginTop:10},children:(0,z.jsx)(XT,{actionId:h,sessionKey:r,selfRestart:NE})}),a===`succeeded`&&(0,z.jsxs)(`div`,{className:`update-modal-result`,children:[(0,z.jsx)(we,{size:14,className:`update-success-icon`}),(0,z.jsxs)(`span`,{children:[`Upgraded to v`,v,` — reloading…`]})]})]})]})}):null}function FE(e){let{conversationId:t,sessionKey:n,newConversationDisabled:r,disconnecting:i,onNewConversation:a,onOpenConversations:o,handleDisconnect:s,enterSelection:c,onAfterAction:l}=e,u=!t&&!n;return(0,z.jsxs)(`div`,{className:`chat-actions-menu`,children:[(0,z.jsxs)(`button`,{type:`button`,className:`chat-action`,disabled:r,onClick:()=>{l(),a()},children:[(0,z.jsx)(Le,{size:14}),(0,z.jsx)(`span`,{className:`action-label`,children:`New conversation`})]}),(0,z.jsxs)(`button`,{type:`button`,className:`chat-action`,onClick:()=>{l(),o()},children:[(0,z.jsx)(Ge,{size:14}),(0,z.jsx)(`span`,{className:`action-label`,children:`Conversations`})]}),(0,z.jsxs)(`button`,{type:`button`,className:`chat-action`,disabled:i,onClick:async()=>{l(),await s()},children:[i?(0,z.jsx)(ae,{size:14,className:`animate-spin`}):(0,z.jsx)(be,{size:14}),(0,z.jsx)(`span`,{className:`action-label`,children:i?`Disconnecting...`:`Disconnect Claude`})]}),(0,z.jsxs)(`button`,{type:`button`,className:`chat-action`,disabled:u,title:t?`Download stream log`:n?`Download stream log (pre-flush)`:`No session active — reload the page to start one`,onClick:()=>{if(l(),u){console.debug(`[stream-log-button] no-identity sessionKey=null conversationId=null`);return}let e=document.createElement(`a`);e.href=`${DE({conversationId:t,sessionKey:n},`stream`)}&download=1`,e.click()},children:[(0,z.jsx)(nt,{size:14}),(0,z.jsx)(`span`,{className:`action-label`,children:`Stream log`})]}),(0,z.jsxs)(`button`,{type:`button`,className:`chat-action`,title:`Select messages`,onClick:()=>{l(),c()},children:[(0,z.jsx)(F,{size:14}),(0,z.jsx)(`span`,{className:`action-label`,children:`Select`})]})]})}function IE(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:ne,sendMessage:F,stopStreaming:ie,disconnecting:ae,handleDisconnect:oe,claudeInfo:se,setClaudeInfo:ce,setShowClaudeInfo:le,conversationId:ue,sessionKey:de,onNewConversation:fe,newConversationDisabled:pe,onOpenConversations:me,sidebarVisible:he}=e,[ge,_e]=(0,R.useState)(!1),ve=(0,R.useRef)(null),[ye,be]=(0,R.useState)(!1),xe=(0,R.useRef)(null),Se=(0,R.useRef)(!1),Ce=ee(),we=Ce.state===`recording`||Ce.state===`paused`||Ce.state===`sending`,Te=!we&&!M&&!l.trim()&&g.length===0;async function I(){let e=await Ce.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){ne([...te.current,{text:`[Voice note]`,files:[n],timestamp:Date.now()}]);return}F(`[Voice note]`,[n])}return(0,R.useEffect)(()=>{t||be(!1)},[t]),(0,R.useEffect)(()=>{if(!ye)return;let e=e=>{e.target.closest(`.selection-copy-wrap`)||be(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[ye]),(0,R.useEffect)(()=>{if(!ge)return;let e=e=>{if(e.key===`Escape`){_e(!1);return}if(e.key===`Tab`&&ve.current){let t=ve.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=>{ve.current&&!ve.current.contains(e.target)&&_e(!1)};return document.addEventListener(`keydown`,e),document.addEventListener(`mousedown`,t),()=>{document.removeEventListener(`keydown`,e),document.removeEventListener(`mousedown`,t)}},[ge]),t?(0,z.jsx)(`div`,{className:`chat-input-area`,children:(0,z.jsxs)(`div`,{className:`selection-bar`,children:[(0,z.jsxs)(`span`,{className:`selection-count`,children:[n.size,` Selected`]}),(0,z.jsxs)(`div`,{className:`selection-copy-wrap`,children:[(0,z.jsxs)(`button`,{type:`button`,className:`selection-copy`,onPointerDown:()=>{if(ye){be(!1);return}Se.current=!1,xe.current=setTimeout(()=>{Se.current=!0,be(!0),xe.current=null},500)},onPointerUp:()=>{xe.current!==null&&(clearTimeout(xe.current),xe.current=null)},onPointerLeave:()=>{xe.current!==null&&(clearTimeout(xe.current),xe.current=null)},onPointerCancel:()=>{xe.current!==null&&(clearTimeout(xe.current),xe.current=null)},onClick:async()=>{Se.current||await o(e=>wE(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,z.jsx)(f,{size:18}),(0,z.jsx)(`span`,{children:`Copy`})]}),ye&&(0,z.jsx)(`div`,{className:`copy-menu`,children:[[`all`,`All events`],[`text`,`Text messages only`],[`non-text`,`Non-text only`]].map(([e,t])=>(0,z.jsx)(`button`,{type:`button`,className:`copy-menu-item`,onClick:async()=>{let t=TE(P,e);t&&s(await re(t)),i()},children:t},e))})]}),(0,z.jsx)(`button`,{type:`button`,className:`selection-cancel`,onClick:i,children:`Cancel`})]})}):(0,z.jsxs)(`div`,{className:`chat-input-area`,children:[(0,z.jsx)(`input`,{ref:x,type:`file`,multiple:!0,accept:ht,style:{display:`none`},onChange:e=>{e.target.files&&S([...e.target.files]),e.target.value=``}}),g.length>0&&(0,z.jsx)(`div`,{className:`attachment-strip`,children:g.map((e,t)=>(0,z.jsxs)(`div`,{className:`attachment-chip`,children:[e.type.startsWith(`image/`)?(0,z.jsx)(`img`,{src:URL.createObjectURL(e),alt:e.name,className:`attachment-chip-thumb`}):e.type===`application/pdf`?(0,z.jsx)(c,{size:14}):(0,z.jsx)(E,{size:14}),(0,z.jsx)(`span`,{className:`attachment-chip-name`,children:e.name}),(0,z.jsx)(`button`,{type:`button`,className:`attachment-chip-remove`,onClick:()=>C(t),"aria-label":`Remove ${e.name}`,children:`×`})]},t))}),b&&(0,z.jsx)(`p`,{className:`attach-error`,children:b}),Ce.state===`error`&&Ce.errorMessage&&(0,z.jsxs)(`p`,{className:`voice-error`,role:`alert`,children:[(0,z.jsx)(m,{size:14}),Ce.errorMessage]}),(0,z.jsx)(T,{inputRef:h}),we?(0,z.jsx)(`div`,{className:`chat-form voice-active`,children:(0,z.jsx)(A,{state:Ce.state,elapsedSeconds:Ce.elapsedSeconds,waveform:Ce.waveform,onTogglePause:Ce.togglePause,onDiscard:Ce.discard,onSend:I})}):(0,z.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){ne([...te.current,{text:t,files:[...g],timestamp:Date.now()}]),p(``),v([]),h.current?.resetHeight();return}F(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,z.jsx)(w,{variant:`icon`,type:`button`,onClick:()=>x.current?.click(),"aria-label":`Attach file`,children:(0,z.jsx)(u,{size:14})}),(0,z.jsx)(N,{ref:h,value:l,onChange:p}),j?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(w,{variant:`send`,type:`button`,onClick:()=>ie(!0),"aria-label":`Pause`,style:{background:`var(--text-secondary)`},children:(0,z.jsx)(d,{size:14})}),(0,z.jsx)(w,{variant:`send`,type:`button`,onClick:()=>ie(!1),"aria-label":`Stop`,style:{background:`var(--danger)`},children:(0,z.jsx)(at,{size:14})})]}):Te?(0,z.jsx)(w,{variant:`send`,type:`button`,onClick:Ce.start,"aria-label":`Record voice note`,children:(0,z.jsx)(m,{size:14})}):(0,z.jsx)(w,{variant:`send`,type:`submit`,disabled:!l.trim()&&g.length===0&&!M,"aria-label":`Send message`,children:M?(0,z.jsx)(_,{size:14}):(0,z.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,z.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,z.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,z.jsxs)(`div`,{className:`chat-actions`,ref:ve,children:[!he&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`button`,{className:`burger-trigger`,onClick:()=>_e(e=>!e),"aria-expanded":ge,"aria-haspopup":`true`,"aria-label":`Conversation actions`,children:(0,z.jsx)(je,{size:16})}),(0,z.jsx)(`div`,{className:`actions-menu-items${ge?` actions-menu-open`:``}`,children:(0,z.jsx)(FE,{conversationId:ue,sessionKey:de,newConversationDisabled:pe,disconnecting:ae,onNewConversation:fe,onOpenConversations:me,handleDisconnect:oe,enterSelection:a,onAfterAction:()=>_e(!1)})})]}),(0,z.jsxs)(`div`,{className:`powered-by`,onClick:async()=>{if(le(!0),!se){let e=await fetch(`/api/admin/claude-info`);e.ok&&ce(await e.json())}},children:[(0,z.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`powered-by-icon`}),(0,z.jsx)(`span`,{children:`Powered by Claude Code`})]})]})]})}function LE({onClose:e}){dt();let[t,n]=(0,R.useState)(!1),r=(0,R.useRef)(null),i=(0,R.useRef)(null),a=(0,R.useCallback)(()=>{i.current&&=(clearInterval(i.current),null),r.current&&!r.current.closed&&r.current.close(),r.current=null,n(!1)},[]),o=(0,R.useCallback)(()=>{let t=`/vnc-popout.html?title=${encodeURIComponent(C.productName)}`,o=window.open(t,`maxy-vnc-overlay-popout`,`width=1024,height=768`);o&&(r.current=o,n(!0),i.current=setInterval(()=>{r.current?.closed&&(a(),e())},500))},[a,e]),s=(0,R.useCallback)(()=>{a(),e()},[a,e]);(0,R.useEffect)(()=>{if(t)return;let e=e=>{e.key===`Escape`&&s()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,s]),(0,R.useEffect)(()=>()=>a(),[a]);let c=Ht({handlePopout:o,disabled:t});return t?(0,z.jsxs)(`div`,{className:`browser-overlay-popout`,children:[(0,z.jsx)(D,{className:`browser-viewer__icon`}),(0,z.jsx)(`span`,{className:`browser-viewer__title`,children:C.productName}),(0,z.jsx)(`span`,{className:`browser-viewer__popout-label`,children:`Popped out`}),(0,z.jsx)(w,{variant:`ghost`,size:`sm`,icon:Xe,onClick:()=>{a()},"aria-label":`Pop back in`}),(0,z.jsx)(w,{variant:`ghost`,size:`sm`,icon:me,onClick:s,"aria-label":`Close`})]}):(0,z.jsxs)(`div`,{className:`browser-viewer-fullscreen`,children:[(0,z.jsxs)(`div`,{className:`browser-viewer-fullscreen__bar`,...c,children:[(0,z.jsx)(D,{className:`browser-viewer__icon`}),(0,z.jsx)(`span`,{className:`browser-viewer-fullscreen__title`,children:C.productName}),(0,z.jsxs)(`div`,{className:`browser-viewer-fullscreen__actions`,children:[(0,z.jsx)(w,{variant:`ghost`,size:`sm`,icon:Me,onClick:o,"aria-label":`Pop out`}),(0,z.jsx)(w,{variant:`ghost`,size:`sm`,icon:me,onClick:s,"aria-label":`Close`})]})]}),(0,z.jsx)(`iframe`,{src:`/vnc-viewer.html`,className:`browser-viewer-fullscreen__iframe`,title:C.productName})]})}function RE(e){let{businessName:t,sessionKey:n,conversationId:r,sessions:i,sessionsLoading:a,sessionsError:o,ensureSessionsLoaded:s,onSelectSession:c,onCloseMobileDrawer:l,onCollapseSidebar:u,actions:d}=e;(0,R.useEffect)(()=>{s()},[s]);let f=C.productName,p=t||f,m=(p.trim().charAt(0)||`?`).toUpperCase(),h=(0,R.useMemo)(()=>i.filter(e=>e.name),[i]),g=h.length,_=r??n,[v,y]=(0,R.useState)(!1),b=(0,R.useRef)(null);return(0,R.useEffect)(()=>{if(!v)return;function e(e){b.current&&!b.current.contains(e.target)&&y(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[v]),(0,z.jsxs)(`aside`,{className:`side`,children:[(0,z.jsxs)(`div`,{className:`side-head`,children:[(0,z.jsxs)(`div`,{className:`brand-mark`,children:[f,(0,z.jsx)(`span`,{className:`ast`,children:`*`})]}),(0,z.jsx)(`div`,{className:`side-head-tools`,children:(0,z.jsx)(`button`,{className:`icon-btn`,title:`Collapse sidebar`,type:`button`,"aria-label":`Collapse sidebar`,onClick:u,children:(0,z.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,children:[(0,z.jsx)(`rect`,{x:`2`,y:`3`,width:`12`,height:`10`,rx:`1.4`}),(0,z.jsx)(`path`,{d:`M6 3v10`})]})})})]}),(0,z.jsxs)(`nav`,{className:`side-nav`,children:[(0,z.jsxs)(`button`,{type:`button`,className:`nav-row active`,children:[(0,z.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,children:(0,z.jsx)(`path`,{d:`M3 4.5h10M3 8h10M3 11.5h7`})}),(0,z.jsx)(`span`,{className:`label`,children:`Chat`}),(0,z.jsx)(`span`,{className:`kbd`,children:`⌘ N`})]}),(0,z.jsxs)(`button`,{type:`button`,className:`nav-row`,disabled:!0,title:`Coming soon — Task 809`,children:[(0,z.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,children:[(0,z.jsx)(`path`,{d:`M3 5.5 8 3l5 2.5v5L8 13l-5-2.5v-5Z`}),(0,z.jsx)(`path`,{d:`M3 5.5 8 8l5-2.5M8 8v5`})]}),(0,z.jsx)(`span`,{className:`label`,children:`Projects`}),(0,z.jsx)(`span`,{className:`kbd`})]}),(0,z.jsxs)(`button`,{type:`button`,className:`nav-row`,disabled:!0,title:`Coming soon — Task 810`,children:[(0,z.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,children:[(0,z.jsx)(`rect`,{x:`2.8`,y:`3.2`,width:`10.4`,height:`9.6`,rx:`1.4`}),(0,z.jsx)(`path`,{d:`M5.5 6.2h5M5.5 8.6h5M5.5 11h3`})]}),(0,z.jsx)(`span`,{className:`label`,children:`Artefacts`}),(0,z.jsx)(`span`,{className:`kbd`})]})]}),(0,z.jsxs)(`div`,{className:`side-list`,children:[(0,z.jsxs)(`div`,{className:`group-head`,children:[(0,z.jsx)(`span`,{children:`Recents`}),(0,z.jsx)(`span`,{children:a?`…`:g})]}),o&&(0,z.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:o}),h.map(e=>{let t=e.conversationId??e.sessionKey;return(0,z.jsx)(`button`,{type:`button`,className:`conv${t!==null&&t===_?` active`:``}`,onClick:()=>{let t=e.sessionKey?e.sessionKey.slice(0,8):`null`,n=e.conversationId?e.conversationId.slice(0,8):`null`;console.info(`[admin-session-identity] sessionKey=${t} conversationId=${n} phase=${e.phase} surface=sidebar-recents`),c(e),l()},children:e.name??`(untitled)`},t??e.updatedAt)})]}),(0,z.jsxs)(`div`,{className:`side-foot`,ref:b,children:[(0,z.jsx)(`div`,{className:`avatar`,children:m}),(0,z.jsxs)(`div`,{className:`who`,children:[(0,z.jsx)(`span`,{className:`name`,children:p}),(0,z.jsx)(`span`,{className:`role`,children:`operator`})]}),(0,z.jsx)(`button`,{className:`icon-btn side-foot-actions-trigger`,title:`Conversation actions`,type:`button`,"aria-label":`Conversation actions`,"aria-haspopup":`true`,"aria-expanded":v,onClick:()=>y(e=>!e),children:(0,z.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,children:[(0,z.jsx)(`circle`,{cx:`8`,cy:`3.4`,r:`.9`}),(0,z.jsx)(`circle`,{cx:`8`,cy:`8`,r:`.9`}),(0,z.jsx)(`circle`,{cx:`8`,cy:`12.6`,r:`.9`})]})}),v&&(0,z.jsx)(`div`,{className:`side-foot-actions-popover`,children:(0,z.jsx)(FE,{...d,onAfterAction:()=>y(!1)})})]})]})}var zE=()=>{};function BE({selectedDoc:e,onClose:t}){let n=e!==null,r=(0,R.useRef)(null);(0,R.useEffect)(()=>{let t=e?.docId??null;t!==r.current&&(console.info(`[admin-ui] artefact-pane state=${t?`open`:`closed`} docId=${t??`none`} trigger=${t?`chat-link`:`toolbar-close`}`),r.current=t)},[e]);let i=(e?.tag||e?.name.split(`.`).pop()||`doc`).toUpperCase().slice(0,6),a=e?.revision||`rev 1`;return(0,z.jsxs)(`aside`,{className:`artefact`,"data-open":n,children:[(0,z.jsxs)(`div`,{className:`art-head`,children:[(0,z.jsxs)(`div`,{className:`left`,children:[(0,z.jsx)(`span`,{className:`file-name`,children:e?.name??``}),n&&(0,z.jsx)(`span`,{className:`file-tag`,children:i})]}),(0,z.jsx)(`div`,{className:`right`,children:n&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`button`,{className:`icon-btn`,title:`Copy`,type:`button`,"aria-label":`Copy`,onClick:()=>{re(e.content)},children:(0,z.jsx)(f,{size:14})}),(0,z.jsx)(`button`,{className:`icon-btn`,title:`Refresh`,type:`button`,"aria-label":`Refresh`,children:(0,z.jsx)(pe,{size:14})}),(0,z.jsx)(`button`,{className:`icon-btn`,title:`Close`,type:`button`,"aria-label":`Close`,onClick:t,children:(0,z.jsx)(me,{size:14})})]})})]}),(0,z.jsxs)(`div`,{className:`art-toolbar`,children:[(0,z.jsxs)(`span`,{className:`seg`,children:[(0,z.jsx)(`span`,{className:`bullet`}),(0,z.jsx)(`strong`,{children:`Artefact`})]}),(0,z.jsx)(`span`,{className:`right-meta`,children:a})]}),(0,z.jsx)(`div`,{className:`art-body`,children:n&&(0,z.jsx)(Lw,{data:{title:e.name,content:e.content,readOnly:!0},onSubmit:zE,submitted:!0})}),(0,z.jsxs)(`div`,{className:`art-foot`,children:[(0,z.jsx)(`span`,{className:`left`,children:a}),(0,z.jsx)(`span`,{className:`right in-sync`,children:`in sync`})]})]})}function VE(e){let[t,n]=(0,R.useState)([]),[r,i]=(0,R.useState)(!1),[a,o]=(0,R.useState)(null),[s,c]=(0,R.useState)(null),l=(0,R.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,R.useEffect)(()=>{e||(c(null),n([]),o(null))},[e]);let u=(0,R.useCallback)(()=>l(!1),[l]),d=(0,R.useCallback)(()=>l(!0),[l]);return{sessions:t,setSessions:n,loading:r,loaded:s!==null&&s===e,error:a,ensureLoaded:u,refetch:d}}function HE(){dt();let e=(0,R.useRef)(null),[t,n]=(0,R.useState)(null),[r,a]=(0,R.useState)(!1),[o,s]=(0,R.useState)(!1),[c,l]=(0,R.useState)(``),[u,d]=(0,R.useState)(!1),[f,p]=(0,R.useState)(null),[m,_]=(0,R.useState)(!1),[v,y]=(0,R.useState)(null),[b,x]=(0,R.useState)(null),[w,T]=(0,R.useState)(!1),[E,O]=(0,R.useState)(null),[k,A]=(0,R.useState)(!1),[j,M]=(0,R.useState)(null),[N,P]=(0,R.useState)(!1),[ee,te]=(0,R.useState)(!1),[F,ie]=(0,R.useState)(!1),[se,de]=(0,R.useState)(!1),[fe,pe]=(0,R.useState)(null),[he,ge]=(0,R.useState)(()=>typeof window<`u`&&window.matchMedia(`(min-width: 641px)`).matches);(0,R.useEffect)(()=>{let e=window.matchMedia(`(min-width: 641px)`),t=e=>ge(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let _e=(0,R.useRef)(!1),ve=(0,R.useRef)(!1),ye=(0,R.useRef)(!1),be=(0,R.useRef)(!1),xe=(0,R.useRef)(null),[Se,Ce]=(0,R.useState)(null),we=g(),Te=mt(),I=bt(),Ee=kt(),De=VE(I.sessionKey),L=Ot({sessionKey:I.sessionKey,setSessionKey:I.setSessionKey,setAppState:I.setAppState,setConversationId:I.setConversationId,startElapsedTimer:Te.startElapsedTimer,stopElapsedTimer:Te.stopElapsedTimer,resetTimerState:Te.resetTimerState,pausedElapsedRef:Te.pausedElapsedRef,expandAllDefaultRef:I.expandAllDefaultRef,setExpandAll:I.setExpandAll,getPendingFiles:()=>Ee.pendingFiles,clearPendingFiles:Ee.clearFiles,inputRef:e});(0,R.useEffect)(()=>{l(window.location.hostname.startsWith(`admin.`)?window.location.origin.replace(`admin.`,`public.`):window.location.origin)},[]),(0,R.useEffect)(()=>{function e(e){e.key===`Escape`&&(t?n(null):we.selectionMode&&we.exitSelection())}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,we.selectionMode]),(0,R.useEffect)(()=>{(I.appState===`set-pin`||I.appState===`enter-pin`)&&setTimeout(()=>I.pinInputRef.current?.focus(),100),I.appState===`chat`&&setTimeout(()=>e.current?.focus(),100)},[I.appState,L.greetingGeneration]),(0,R.useEffect)(()=>{if(I.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)},[I.appState]);let Oe=(0,R.useRef)(L.greetingGeneration);if((0,R.useEffect)(()=>{L.greetingGeneration!==Oe.current&&(Oe.current=L.greetingGeneration,I.onboardingComplete===!1&&(_e.current=!1))},[L.greetingGeneration,I.onboardingComplete]),(0,R.useEffect)(()=>{I.appState===`chat`&&I.onboardingComplete===!1&&(_e.current||(_e.current=!0,L.sendSystemPrompt(`[Begin onboarding.]`)))},[I.appState,I.onboardingComplete,L.greetingGeneration]),(0,R.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,R.useEffect)(()=>{if(I.appState!==`chat`){ye.current=!1,be.current=!1;return}if(ye.current)return;ye.current=!0;let e=!1;return fetch(`/api/admin/version`).then(e=>e.json()).then(t=>{e||(O(t),!(!t.updateAvailable||be.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}},[I.appState]),(0,R.useEffect)(()=>{if(I.appState!==`chat`||!I.sessionKey)return;let e=I.conversationId?`flushed`:`pre-flush`,t=I.sessionKey.slice(0,8),n=I.conversationId?I.conversationId.slice(0,8):`null`;console.info(`[admin-session-identity] sessionKey=${t} conversationId=${n} phase=${e} surface=chat-header`)},[I.appState,I.sessionKey,I.conversationId]),(0,R.useEffect)(()=>{if(I.appState!==`chat`){ve.current=!1;return}if(ve.current||!De.loaded)return;ve.current=!0;let e=De.sessions.filter(e=>e.name).length,t=fe?`open`:`closed`;console.info(`[admin-ui] platform-shell brand=${C.productName} sidebar=${e} artefact=${t}`)},[I.appState,De.loaded,De.sessions,fe]),(0,R.useEffect)(()=>{if(!u){p(null),y(null),x(null),O(null);return}function e(e){xe.current&&!xe.current.contains(e.target)&&d(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[u]),(0,R.useEffect)(()=>{if(typeof BroadcastChannel>`u`)return;let e=new BroadcastChannel(`platform-onboarding`);return e.onmessage=e=>{e.data?.type===`remote-password-set`&&L.sendMessageRef.current(`I've set the remote password`)},()=>e.close()},[]),I.appState===`loading`)return(0,z.jsx)(`div`,{className:`chat-page admin-page`,children:(0,z.jsx)(`header`,{className:`chat-header`,children:(0,z.jsx)(`img`,{src:ne,alt:C.productName,className:`chat-logo`})})});if(I.appState===`set-pin`)return(0,z.jsx)(jt,{pin:I.pin,setPin:I.setPin,confirmPin:I.confirmPin,setConfirmPin:I.setConfirmPin,showPin:I.showPin,setShowPin:I.setShowPin,pinLoading:I.pinLoading,pinError:I.pinError,pinInputRef:I.pinInputRef,confirmPinInputRef:I.confirmPinInputRef,setPinFormRef:I.setPinFormRef,onSubmit:I.handleSetPin});if(I.appState===`onboarding-choice`)return(0,z.jsx)(Ft,{setAppState:I.setAppState,setOnboardingComplete:I.setOnboardingComplete});if(I.appState===`connect-claude`)return(0,z.jsx)(Pt,{authPolling:I.authPolling,setAuthPolling:I.setAuthPolling,authLoading:I.authLoading,setAuthLoading:I.setAuthLoading,pinError:I.pinError,setPinError:I.setPinError,setAppState:I.setAppState});if(I.appState===`enter-pin`)return(0,z.jsx)(Mt,{pin:I.pin,setPin:I.setPin,showPin:I.showPin,setShowPin:I.setShowPin,pinLoading:I.pinLoading,pinError:I.pinError,pinInputRef:I.pinInputRef,onSubmit:I.handleLogin,onChangePin:I.handleChangePin});if(I.appState===`account-picker`)return(0,z.jsx)(Nt,{accounts:I.accounts,loading:I.accountPickerLoading,error:I.pinError,onSelect:I.handleAccountSelect});let ke=fe?`open`:`closed`,Ae=`platform${F?` menu-open`:``}${se?` sidebar-collapsed`:``}`,je=e=>{if(!L.isStreaming&&I.sessionKey){if(!e.conversationId){L.resetConversation(),L.setMessages([]),I.setConversationId(null);return}L.resetConversation(),L.setMessages([]),fetch(`/api/admin/sessions/${encodeURIComponent(e.conversationId)}/resume?session_key=${encodeURIComponent(I.sessionKey)}`,{method:`POST`}).then(e=>e.ok?e.json():Promise.reject(Error(`resume returned ${e.status}`))).then(e=>{e.conversationId&&I.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`?[{type:`text`,content:e.content}]:void 0,timestamp:new Date(e.createdAt).getTime()||0,historical:!0}));t.length>0&&L.setMessages(t)}).catch(e=>{console.error(`[chat] sidebar conversation resume failed:`,e),L.setMessages([{role:`maxy`,events:[{type:`text`,content:`Could not load conversation history.`}],timestamp:Date.now()-1,historical:!0}])})}},Ne={conversationId:I.conversationId,sessionKey:I.sessionKey,newConversationDisabled:L.isStreaming||L.isCompacting,disconnecting:I.disconnecting,onNewConversation:L.startNewConversation,onOpenConversations:()=>{T(!0),De.refetch()},handleDisconnect:I.handleDisconnect,enterSelection:we.enterSelection};return(0,z.jsx)(S,{value:{onShowVnc:()=>P(!0)},children:(0,z.jsxs)(`div`,{className:Ae,"data-artefact":ke,children:[(0,z.jsx)(`div`,{className:`scrim`,onClick:()=>{ie(!1),console.info(`[admin-ui] mobile-drawer state=closed`)}}),(0,z.jsx)(RE,{businessName:I.businessName??null,sessionKey:I.sessionKey,conversationId:I.conversationId,sessions:De.sessions,sessionsLoading:De.loading,sessionsError:De.error,ensureSessionsLoaded:De.ensureLoaded,onSelectSession:je,onCloseMobileDrawer:()=>{F&&(ie(!1),console.info(`[admin-ui] mobile-drawer state=closed`))},onCollapseSidebar:()=>de(!0),actions:Ne}),(0,z.jsxs)(`div`,{className:`chat-page admin-page`,children:[(0,z.jsxs)(`header`,{className:`chat-header`,children:[(0,z.jsx)(`button`,{type:`button`,className:`icon-btn mobile-menu`,"aria-label":`Show sidebar`,title:`Show sidebar`,onClick:()=>{if(se){de(!1),console.info(`[admin-ui] sidebar-collapsed state=false trigger=chat-header-button`);return}ie(e=>{let t=!e;return console.info(`[admin-ui] mobile-drawer state=${t?`open`:`closed`}`),t})},children:(0,z.jsx)($e,{size:16})}),(0,z.jsx)(`img`,{src:ne,alt:C.productName,className:`chat-logo`}),(!C.logoContainsName||I.businessName)&&(0,z.jsx)(`div`,{children:(0,z.jsx)(`h1`,{className:`chat-tagline`,children:I.businessName||C.productName})}),(I.sessionKey||I.conversationId)&&(0,z.jsxs)(`button`,{type:`button`,className:`chat-session-chip chat-session-chip-${I.conversationId?`flushed`:`pre-flush`}`+(Se===`copied`?` copied`:``)+(Se===`failed`?` copy-failed`:``),title:I.conversationId?`conversation ${I.conversationId} — click to copy`:`session ${I.sessionKey} (pre-flush, first turn pending) — click to copy`,onClick:async()=>{let e=I.conversationId??I.sessionKey;e&&(Ce(await re(e)?`copied`:`failed`),setTimeout(()=>Ce(null),1200))},children:[(0,z.jsx)(`span`,{className:`chat-session-chip-label`,children:Se===`copied`?`copied`:Se===`failed`?`copy failed`:I.conversationId?`conversation`:`session`}),(0,z.jsx)(`span`,{className:`chat-session-chip-id`,children:Se===`copied`?`✓`:Se===`failed`?`✕`:`${(I.conversationId??I.sessionKey??``).slice(0,8)}…`})]}),(0,z.jsxs)(`div`,{className:`chat-burger-wrap`,ref:xe,children:[(0,z.jsx)(`button`,{type:`button`,className:`chat-burger`,onClick:()=>d(e=>!e),"aria-label":`Menu`,"aria-haspopup":`true`,"aria-expanded":u,children:(0,z.jsx)(le,{size:20})}),u&&(0,z.jsxs)(`div`,{className:`chat-menu`,children:[(0,z.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:async()=>{if(!(N||ee)){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`);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,z.jsx)(D,{size:14}),` Browser`,ee&&(0,z.jsx)(ae,{size:12,className:`spin`})]}),(0,z.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{d(!1),window.location.href=`/data`},children:[(0,z.jsx)(ce,{size:14}),` Data`]}),(0,z.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{d(!1),window.location.href=`/graph`},children:[(0,z.jsx)(ue,{size:14}),` Graph`]}),(0,z.jsx)(`div`,{className:`chat-menu-divider`}),(0,z.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,z.jsx)(Me,{size:14}),` Public`,m&&(0,z.jsx)(ae,{size:12,className:`spin`})]}),f!==null&&(0,z.jsxs)(`div`,{className:`chat-menu-agents`,children:[v&&(0,z.jsx)(`span`,{className:`chat-menu-agent-error`,children:v}),f.length===0&&!v&&(0,z.jsx)(`span`,{className:`chat-menu-agent-empty`,children:`No public agents configured`}),f.map(e=>(0,z.jsxs)(`div`,{className:`chat-menu-item chat-menu-agent-item`,children:[(0,z.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),(0,z.jsxs)(`span`,{className:`agent-text`,children:[(0,z.jsx)(`span`,{className:`agent-display-name`,children:e.displayName}),(0,z.jsxs)(`span`,{className:`agent-slug`,children:[`/`,e.slug]})]}),b===e.slug?(0,z.jsxs)(`span`,{className:`agent-actions agent-confirm`,children:[(0,z.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,z.jsx)(h,{size:12})}),(0,z.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-no`,title:`Cancel`,onClick:()=>x(null),children:(0,z.jsx)(me,{size:12})})]}):(0,z.jsxs)(`span`,{className:`agent-actions`,children:[(0,z.jsx)(`a`,{href:`${c}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`agent-action-btn`,title:`Open agent`,onClick:()=>d(!1),children:(0,z.jsx)(Me,{size:12})}),(0,z.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-delete-btn`,title:`Delete agent`,onClick:()=>x(e.slug),children:(0,z.jsx)(i,{size:12})})]})]},e.slug))]}),(0,z.jsx)(`div`,{className:`chat-menu-divider`}),E?.updateAvailable?(0,z.jsxs)(`button`,{type:`button`,className:`chat-menu-version`,onClick:()=>{E.latest&&(M(E),d(!1),A(!0))},children:[(0,z.jsx)(Be,{size:14}),(0,z.jsxs)(`span`,{className:`version-installed`,children:[`v`,E.installed,(0,z.jsx)(`span`,{className:`version-update-dot`})]})]}):(0,z.jsxs)(`div`,{className:`chat-menu-version chat-menu-version-passive`,children:[(0,z.jsx)(Be,{size:14}),(0,z.jsxs)(`span`,{className:`version-installed`,children:[E?`v${E.installed}`:`…`,E&&!E.updateAvailable&&(0,z.jsx)(`span`,{className:`version-uptodate-dot`})]})]}),(0,z.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{d(!1),I.handleLogout(),L.setMessages([])},children:[(0,z.jsx)(oe,{size:14}),` Log out`]})]})]})]}),(0,z.jsxs)(`div`,{className:`chat-content`,children:[(0,z.jsx)(SE,{messages:L.messages,isStreaming:L.isStreaming,elapsedSeconds:Te.elapsedSeconds,sessionTurnStart:Te.sessionTurnStart,expandAll:I.expandAll,setExpandAll:I.setExpandAll,conversationCompacted:L.conversationCompacted,isCompacting:L.isCompacting,setShowCompactConfirm:s,handleComponentSubmit:L.handleComponentSubmit,effectiveSubmitted:L.effectiveSubmitted,selectionMode:we.selectionMode,selectedItems:we.selectedItems,toggleSelectItem:we.toggleSelectItem,sessionKey:I.sessionKey,setLightboxSrc:n,messageQueue:L.messageQueue,messageQueueRef:L.messageQueueRef,setQueue:L.setQueue,sendMessage:L.sendMessage,appState:I.appState,onboardingComplete:I.onboardingComplete,onOpenArtefact:pe}),(0,z.jsx)(CE,{offer:L.topicChangeOffer,onFreshStart:L.handleTopicFreshStart,onContinue:L.handleTopicContinue,disabled:L.isStreaming}),(0,z.jsx)(IE,{selectionMode:we.selectionMode,selectedItems:we.selectedItems,copyToast:we.copyToast||null,exitSelection:we.exitSelection,enterSelection:we.enterSelection,copySelected:we.copySelected,showCopyToast:we.showCopyToast,input:L.input,setInput:L.setInput,inputRef:e,pendingFiles:Ee.pendingFiles,setPendingFiles:Ee.setPendingFiles,isDragOver:Ee.isDragOver,attachError:Ee.attachError,fileInputRef:Ee.fileInputRef,addFiles:Ee.addFiles,removeFile:Ee.removeFile,onDragOver:Ee.onDragOver,onDragLeave:Ee.onDragLeave,onDrop:Ee.onDrop,isStreaming:L.isStreaming,wasPaused:L.wasPaused,messages:L.messages,messageQueueRef:L.messageQueueRef,setQueue:L.setQueue,sendMessage:L.sendMessage,stopStreaming:L.stopStreaming,disconnecting:I.disconnecting,handleDisconnect:I.handleDisconnect,claudeInfo:I.claudeInfo,setClaudeInfo:I.setClaudeInfo,setShowClaudeInfo:a,conversationId:I.conversationId,sessionKey:I.sessionKey,onNewConversation:L.startNewConversation,newConversationDisabled:L.isStreaming||L.isCompacting,onOpenConversations:()=>{T(!0),De.refetch()},sidebarVisible:he&&!se})]}),we.copyToast&&(0,z.jsx)(`span`,{className:`copy-toast${we.copyToast===`failed`?` copy-toast-failed`:``}`,children:we.copyToast===`copied`?`Copied`:`Copy failed`}),(0,z.jsx)(OE,{show:w,onClose:()=>T(!1),conversationsLoading:De.loading,conversationsError:De.error,conversationsList:De.sessions,setConversationsList:De.setSessions,sessionKey:I.sessionKey,isStreaming:L.isStreaming,resetConversation:L.resetConversation,setMessages:L.setMessages,setConversationId:I.setConversationId}),(0,z.jsx)(kE,{src:t,onClose:()=>n(null)}),(0,z.jsx)(AE,{show:o,onClose:()=>s(!1),onConfirm:L.handleCompactNow}),(0,z.jsx)(jE,{show:r,onClose:()=>{a(!1),I.setClaudeInfo(null)},claudeInfo:I.claudeInfo,messages:L.messages,sessionElapsed:Te.sessionElapsed,conversationId:I.conversationId}),(0,z.jsx)(PE,{show:k,onClose:()=>{A(!1),be.current=!0},versionInfo:j,sessionKey:I.sessionKey,onUpgradeComplete:()=>O(null)}),N&&(0,z.jsx)(LE,{onClose:()=>P(!1)})]}),(0,z.jsx)(BE,{selectedDoc:fe,onClose:()=>pe(null)})]})})}(0,ge.createRoot)(document.getElementById(`root`)).render((0,z.jsx)(HE,{}));
@@ -5,7 +5,7 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
6
  <title>Maxy</title>
7
7
  <link rel="icon" href="/favicon.ico">
8
- <script type="module" crossorigin src="/assets/admin-Dob7h_6l.js"></script>
8
+ <script type="module" crossorigin src="/assets/admin-Bb1mJY86.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-DbyFfBdY.js">
11
11
  <link rel="modulepreload" crossorigin href="/assets/preload-helper-BEFjQwLd.js">