@rubytech/create-realagent 1.0.823 → 1.0.824
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/payload/platform/neo4j/migrations/006-prune-bogus-whatsapp-persons.ts +132 -0
- package/payload/platform/plugins/admin/hooks/__tests__/archive-ingest-surface-gate.test.sh +1 -1
- package/payload/platform/plugins/admin/hooks/archive-ingest-surface-gate.sh +2 -2
- package/payload/platform/plugins/docs/references/plugins-guide.md +1 -1
- package/payload/platform/plugins/memory/mcp/dist/tools/memory-archive-write.d.ts.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/tools/memory-archive-write.js +10 -5
- package/payload/platform/plugins/memory/mcp/dist/tools/memory-archive-write.js.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/tools/whatsapp-export-insight-pass.d.ts +4 -0
- package/payload/platform/plugins/memory/mcp/dist/tools/whatsapp-export-insight-pass.d.ts.map +1 -1
- package/payload/platform/plugins/memory/mcp/dist/tools/whatsapp-export-insight-pass.js +106 -30
- package/payload/platform/plugins/memory/mcp/dist/tools/whatsapp-export-insight-pass.js.map +1 -1
- package/payload/platform/plugins/whatsapp-import/bin/ingest.mjs +174 -115
- package/payload/platform/plugins/whatsapp-import/bin/whatsapp-ingest.sh +18 -7
- package/payload/platform/plugins/whatsapp-import/lib/dist/parse-export.js +24 -0
- package/payload/platform/plugins/whatsapp-import/lib/dist/parse-export.js.map +1 -1
- package/payload/platform/plugins/whatsapp-import/lib/src/__tests__/filter-gate.test.ts +2 -0
- package/payload/platform/plugins/whatsapp-import/lib/src/__tests__/parse-export-lrm.test.ts +83 -0
- package/payload/platform/plugins/whatsapp-import/lib/src/parse-export.ts +25 -0
- package/payload/platform/plugins/whatsapp-import/skills/whatsapp-import/SKILL.md +11 -9
- package/payload/platform/templates/specialists/agents/database-operator.md +1 -1
- package/payload/server/chunk-JNVZQMTZ.js +593 -0
- package/payload/server/chunk-L3T7ECLI.js +1116 -0
- package/payload/server/chunk-LFOR2ACU.js +10079 -0
- package/payload/server/chunk-NAP6XMLW.js +2233 -0
- package/payload/server/client-pool-M2DU74ZP.js +32 -0
- package/payload/server/cloudflare-task-tracker-6S23B7QX.js +17 -0
- package/payload/server/maxy-edge.js +3 -3
- package/payload/server/neo4j-migrations-YED5CFPF.js +428 -0
- package/payload/server/public/assets/{admin-Bnj-1qCb.js → admin-DOkUspG1.js} +1 -1
- package/payload/server/public/index.html +1 -1
- package/payload/server/server.js +120 -7
|
@@ -349,4 +349,4 @@ ${JSON.stringify(u.input,null,2)}`,f=B.get(r),p=o?void 0:f??t;return(0,W.jsx)(WE
|
|
|
349
349
|
|
|
350
350
|
---
|
|
351
351
|
|
|
352
|
-
`)}var XE=[{type:`stream`,label:`Stream`},{type:`error`,label:`Errors`},{type:`sse`,label:`SSE`}];function ZE(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 QE(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,U.useState)(null),[v,y]=(0,U.useState)(null),[b,x]=(0,U.useState)(``),[S,C]=(0,U.useState)(!1),w=(0,U.useRef)(null),[T,E]=(0,U.useState)(null),[D,O]=(0,U.useState)(null),[k,A]=(0,U.useState)(null),j=(0,U.useRef)(null),M=(0,U.useRef)(null),N=(0,U.useRef)(null);(0,U.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,U.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,U.useEffect)(()=>{v?.phase===`editing`&&(w.current?.focus(),w.current?.select())},[v]);function P(){g(null),y(null),x(``),C(!1)}async function F(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 ee(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 I(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 te(e){await L(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,W.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,W.jsxs)(`div`,{className:`claude-info-modal conversations-modal`,onClick:e=>e.stopPropagation(),children:[(0,W.jsxs)(`div`,{className:`claude-info-header`,children:[(0,W.jsx)(Je,{size:12}),`Conversations`,(0,W.jsx)(`button`,{className:`claude-info-close`,onClick:n,children:`✕`})]}),(0,W.jsxs)(`div`,{className:`conversations-list`,children:[r&&(0,W.jsxs)(`div`,{className:`conversations-empty`,children:[(0,W.jsx)(me,{size:14,className:`spin`}),` Loading…`]}),a&&(0,W.jsx)(`div`,{className:`conversations-empty conversations-error`,children:a}),!r&&!a&&o.length===0&&(0,W.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,W.jsxs)(`div`,{className:`conversations-row${r?` conversations-row-pre-flush`:``}`,children:[(0,W.jsxs)(`div`,{className:`conversations-row-info`,children:[o&&(0,W.jsxs)(`span`,{className:`conversations-row-name conversations-edit-loading`,children:[(0,W.jsx)(me,{size:12,className:`spin`}),` Generating suggestion…`]}),g&&(0,W.jsxs)(`div`,{className:`conversations-edit-inline`,children:[(0,W.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()&&ee(e.conversationId),t.key===`Escape`&&P()},maxLength:200}),(0,W.jsx)(`button`,{type:`button`,className:`conversations-action conversations-confirm`,title:`Confirm rename`,disabled:!b.trim()||S,onClick:()=>ee(e.conversationId),children:S?(0,W.jsx)(me,{size:13,className:`spin`}):(0,W.jsx)(h,{size:13})}),(0,W.jsx)(`button`,{type:`button`,className:`conversations-action conversations-cancel`,title:`Cancel`,onClick:P,children:(0,W.jsx)(ie,{size:13})})]}),y&&(0,W.jsxs)(`div`,{className:`conversations-edit-inline`,children:[(0,W.jsx)(`span`,{className:`conversations-edit-error`,children:v.reason}),(0,W.jsx)(`button`,{type:`button`,className:`conversations-action conversations-retry`,title:`Retry`,onClick:()=>F(e.conversationId),children:(0,W.jsx)(re,{size:13})}),(0,W.jsx)(`button`,{type:`button`,className:`conversations-action conversations-cancel`,title:`Cancel`,onClick:P,children:(0,W.jsx)(ie,{size:13})})]}),!a&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`span`,{className:`conversations-row-name`,children:[e.name||(r?`session ${C}`:C),r&&(0,W.jsx)(`span`,{className:`conversations-row-phase-badge`,title:`Pre-flush — conversation not yet persisted`,children:`pre-flush`})]}),(0,W.jsxs)(`span`,{className:`conversations-row-meta`,children:[(0,W.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(),te(t)},children:D===t?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(h,{size:10}),` copied`]}):k===t?`copy failed`:C.slice(0,8)}),(0,W.jsxs)(`span`,{className:`conversations-row-time`,children:[(0,W.jsx)(H,{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,W.jsx)(`div`,{className:`conversations-row-actions`,children:!a&&(0,W.jsxs)(W.Fragment,{children:[(0,W.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(),I(t,{conversationId:e.conversationId,sessionKey:e.sessionKey},n.currentTarget)},children:(0,W.jsx)(c,{size:13})}),!r&&e.conversationId&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`button`,{type:`button`,className:`conversations-action conversations-rename`,title:`Rename conversation`,onClick:()=>F(e.conversationId),children:(0,W.jsx)(ot,{size:13})}),(0,W.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`?e.events??(e.content?[{type:`text`,content:e.content}]:[]):void 0,...e.role===`user`&&e.attachments&&e.attachments.length>0?{attachments:e.attachments}:{},timestamp:new Date(e.createdAt).getTime()||0,historical:!0,...e.messageId?{messageId:e.messageId}:{}}));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,W.jsx)(_,{size:13})}),(0,W.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,W.jsx)(i,{size:13})})]})]})})]},t)})]}),T&&(0,W.jsx)(`div`,{ref:N,className:`conversations-logs-popover`,role:`menu`,style:{top:T.top,right:T.right},children:XE.map(({type:e,label:t})=>(0,W.jsxs)(`a`,{role:`menuitem`,className:`conversations-logs-popover-item`,href:ZE({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,W.jsx)(c,{size:12}),(0,W.jsx)(`span`,{children:t})]},e))})]})}):null}function $E({src:e,onClose:t}){return e?(0,W.jsxs)(`div`,{className:`attachment-lightbox`,onClick:t,children:[(0,W.jsx)(`button`,{className:`attachment-lightbox-close`,onClick:t,"aria-label":`Close`,children:`×`}),(0,W.jsx)(`img`,{src:e,alt:`Attachment`,onClick:e=>e.stopPropagation()})]}):null}function eD({show:e,onClose:t,onConfirm:n}){return e?(0,W.jsx)(`div`,{className:`claude-info-overlay`,onClick:t,children:(0,W.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,W.jsxs)(`div`,{className:`claude-info-header`,children:[(0,W.jsx)(`span`,{children:`Compact conversation?`}),(0,W.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:`✕`})]}),(0,W.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,W.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,W.jsx)(w,{variant:`secondary`,size:`sm`,style:{background:`var(--accent)`,flex:1},onClick:()=>{t(),n()},children:`Yes, compact`}),(0,W.jsx)(w,{variant:`secondary`,size:`sm`,style:{flex:1},onClick:t,children:`No`})]})]})}):null}function tD(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,W.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,W.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,W.jsxs)(`div`,{className:`claude-info-header`,children:[(0,W.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`claude-info-icon`}),(0,W.jsx)(`span`,{children:`Claude Code`}),(0,W.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,W.jsxs)(`div`,{className:`claude-info-section`,children:[(0,W.jsxs)(`div`,{className:`claude-info-row`,children:[(0,W.jsx)(`span`,{className:`claude-info-label`,children:`Version`}),(0,W.jsx)(`span`,{className:`claude-info-value`,children:r?r.version:`…`})]}),(0,W.jsxs)(`div`,{className:`claude-info-row`,children:[(0,W.jsx)(`span`,{className:`claude-info-label`,children:`Email`}),(0,W.jsx)(`span`,{className:`claude-info-value`,children:r?.account?.email??`…`})]})]}),(p||d||f>0)&&(0,W.jsxs)(`div`,{className:`claude-info-section`,children:[p&&(0,W.jsxs)(`div`,{className:`claude-info-row`,children:[(0,W.jsx)(`span`,{className:`claude-info-label`,children:`Plan`}),(0,W.jsx)(`span`,{className:`claude-info-value`,style:{textTransform:`capitalize`},children:p})]}),d&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{className:`claude-info-row`,children:[(0,W.jsx)(`span`,{className:`claude-info-label`,children:`Usage`}),(0,W.jsxs)(`span`,{className:`claude-info-value`,children:[Math.round(d.utilization*100),`%`]})]}),(0,W.jsxs)(`div`,{className:`claude-info-row`,children:[(0,W.jsx)(`span`,{className:`claude-info-label`,children:`Resets in`}),(0,W.jsx)(`span`,{className:`claude-info-value`,children:m(d.resetsAt)})]}),d.isUsingOverage&&(0,W.jsxs)(`div`,{className:`claude-info-row`,children:[(0,W.jsx)(`span`,{className:`claude-info-label`,children:`Overage`}),(0,W.jsx)(`span`,{className:`claude-info-value`,children:`Active`})]})]}),f>0&&(0,W.jsxs)(`div`,{className:`claude-info-row`,children:[(0,W.jsx)(`span`,{className:`claude-info-label`,children:`Session cost`}),(0,W.jsxs)(`span`,{className:`claude-info-value`,children:[`$`,f<.01?f.toFixed(4):f.toFixed(2)]})]})]}),(0,W.jsxs)(`div`,{className:`claude-info-section`,children:[(0,W.jsxs)(`div`,{className:`claude-info-row`,children:[(0,W.jsx)(`span`,{className:`claude-info-label`,children:`Model`}),(0,W.jsx)(`span`,{className:`claude-info-value`,children:r?.model??`…`})]}),(0,W.jsxs)(`div`,{className:`claude-info-row`,children:[(0,W.jsx)(`span`,{className:`claude-info-label`,children:`Context used`}),(0,W.jsx)(`span`,{className:`claude-info-value`,children:l>0?`${l}%`:`—`})]}),(0,W.jsxs)(`div`,{className:`claude-info-row`,children:[(0,W.jsx)(`span`,{className:`claude-info-label`,children:`Tokens`}),(0,W.jsx)(`span`,{className:`claude-info-value`,children:u>0?bt(u):`—`})]}),(0,W.jsxs)(`div`,{className:`claude-info-row`,children:[(0,W.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,W.jsx)(`span`,{className:`claude-info-value`,children:yt(a)})]}),o&&(0,W.jsxs)(`div`,{className:`claude-info-row`,children:[(0,W.jsx)(`span`,{className:`claude-info-label`,children:`Conversation`}),(0,W.jsx)(`span`,{className:`claude-info-value`,style:{fontFamily:`monospace`,fontSize:10},children:o.slice(0,8)})]})]})]})})}var nD=5e3,rD={atPhase:8};function iD({show:e,onClose:t,versionInfo:n,sessionKey:r,onUpgradeComplete:i}){let[a,o]=(0,U.useState)(`prompt`),[s,c]=(0,U.useState)(``),[l,u]=(0,U.useState)(!1),[d,f]=(0,U.useState)(null),[p,m]=(0,U.useState)(null),[h,g]=(0,U.useState)(null),_=(0,U.useRef)(null),v=n?.latest??null,y=(0,U.useCallback)(()=>{_.current&&=(clearInterval(_.current),null)},[]);(0,U.useEffect)(()=>{e||(y(),o(`prompt`),c(``),u(!1),f(null),m(null),g(null))},[e,y]),(0,U.useEffect)(()=>y,[y]),(0,U.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{}},nD),y},[e,a,v,i,y]);let b=(0,U.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,W.jsx)(`div`,{className:`claude-info-overlay`,onClick:()=>{(a===`prompt`||a===`succeeded`||a===`launch-failed`)&&t()},children:(0,W.jsxs)(`div`,{className:`claude-info-modal update-modal`,onClick:e=>e.stopPropagation(),children:[(0,W.jsxs)(`div`,{className:`claude-info-header`,children:[(0,W.jsx)(B,{size:12}),`Software Update`,(0,W.jsx)(`button`,{className:`claude-info-close`,onClick:t,children:`✕`})]}),(0,W.jsxs)(`div`,{className:`update-modal-body`,children:[(0,W.jsxs)(`div`,{className:`update-modal-versions`,children:[(0,W.jsxs)(`div`,{className:`claude-info-row`,children:[(0,W.jsx)(`span`,{className:`claude-info-label`,children:`Installed`}),(0,W.jsxs)(`span`,{className:`claude-info-value`,children:[`v`,n?.installed??`…`]})]}),(0,W.jsxs)(`div`,{className:`claude-info-row`,children:[(0,W.jsx)(`span`,{className:`claude-info-label`,children:`Available`}),(0,W.jsxs)(`span`,{className:`claude-info-value update-version-new`,children:[`v`,v??`…`]})]})]}),(a===`prompt`||a===`priming`||a===`launch-failed`)&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{className:`form-input__field`,style:{marginTop:12},children:[(0,W.jsx)(`label`,{className:`form-input__label`,htmlFor:`upgrade-sudo`,children:`Device password`}),(0,W.jsxs)(`div`,{className:`tunnel-route__row`,children:[(0,W.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,W.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,W.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,W.jsx)(`div`,{className:`tunnel-route__error`,children:d}),p&&(0,W.jsx)(`div`,{className:`tunnel-route__error`,role:`alert`,children:p})]}),(0,W.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,W.jsx)(`div`,{className:`update-modal-terminal`,style:{height:360,marginTop:10},children:(0,W.jsx)(vE,{actionId:h,sessionKey:r,selfRestart:rD})}),a===`succeeded`&&(0,W.jsxs)(`div`,{className:`update-modal-result`,children:[(0,W.jsx)(Te,{size:14,className:`update-success-icon`}),(0,W.jsxs)(`span`,{children:[`Upgraded to v`,v,` — reloading…`]})]})]})]})}):null}function aD(e){let{conversationId:t,sessionKey:n,disconnecting:r,onOpenConversations:i,handleDisconnect:a,onAfterAction:o}=e,s=!t&&!n;return(0,W.jsxs)(`div`,{className:`chat-actions-menu`,children:[(0,W.jsxs)(`button`,{type:`button`,className:`chat-action`,onClick:()=>{o(),i()},children:[(0,W.jsx)(Je,{size:14}),(0,W.jsx)(`span`,{className:`action-label`,children:`Conversations`})]}),(0,W.jsxs)(`button`,{type:`button`,className:`chat-action`,disabled:r,onClick:async()=>{o(),await a()},children:[r?(0,W.jsx)(me,{size:14,className:`animate-spin`}):(0,W.jsx)(be,{size:14}),(0,W.jsx)(`span`,{className:`action-label`,children:r?`Disconnecting...`:`Disconnect Claude`})]}),(0,W.jsxs)(`button`,{type:`button`,className:`chat-action`,disabled:s,title:t?`Download stream log`:n?`Download stream log (pre-flush)`:`No session active — reload the page to start one`,onClick:()=>{if(o(),s){console.debug(`[stream-log-button] no-identity sessionKey=null conversationId=null`);return}let e=document.createElement(`a`);e.href=`${ZE({conversationId:t,sessionKey:n},`stream`)}&download=1`,e.click()},children:[(0,W.jsx)(ct,{size:14}),(0,W.jsx)(`span`,{className:`action-label`,children:`Stream log`})]})]})}function oD(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:ee,setQueue:I,sendMessage:R,stopStreaming:ne,disconnecting:re,handleDisconnect:ie,claudeInfo:z,setClaudeInfo:B,setShowClaudeInfo:ae,conversationId:oe,sessionKey:se,onNewConversation:ce,newConversationDisabled:le,onOpenConversations:ue,sidebarVisible:de}=e,[fe,pe]=(0,U.useState)(!1),me=(0,U.useRef)(null),[he,ge]=(0,U.useState)(!1),_e=(0,U.useRef)(null),ve=(0,U.useRef)(!1),ye=F(),be=ye.state===`recording`||ye.state===`paused`||ye.state===`sending`,xe=!be&&!M&&!l.trim()&&g.length===0;async function Se(){let e=await ye.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){I([...ee.current,{text:`[Voice note]`,files:[n],timestamp:Date.now()}]);return}R(`[Voice note]`,[n])}return(0,U.useEffect)(()=>{t||ge(!1)},[t]),(0,U.useEffect)(()=>{if(!he)return;let e=e=>{e.target.closest(`.selection-copy-wrap`)||ge(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[he]),(0,U.useEffect)(()=>{if(!fe)return;let e=e=>{if(e.key===`Escape`){pe(!1);return}if(e.key===`Tab`&&me.current){let t=me.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=>{me.current&&!me.current.contains(e.target)&&pe(!1)};return document.addEventListener(`keydown`,e),document.addEventListener(`mousedown`,t),()=>{document.removeEventListener(`keydown`,e),document.removeEventListener(`mousedown`,t)}},[fe]),t?(0,W.jsx)(`div`,{className:`chat-input-area`,children:(0,W.jsxs)(`div`,{className:`selection-bar`,children:[(0,W.jsxs)(`span`,{className:`selection-count`,children:[n.size,` Selected`]}),(0,W.jsxs)(`div`,{className:`selection-copy-wrap`,children:[(0,W.jsxs)(`button`,{type:`button`,className:`selection-copy`,onPointerDown:()=>{if(he){ge(!1);return}ve.current=!1,_e.current=setTimeout(()=>{ve.current=!0,ge(!0),_e.current=null},500)},onPointerUp:()=>{_e.current!==null&&(clearTimeout(_e.current),_e.current=null)},onPointerLeave:()=>{_e.current!==null&&(clearTimeout(_e.current),_e.current=null)},onPointerCancel:()=>{_e.current!==null&&(clearTimeout(_e.current),_e.current=null)},onClick:async()=>{ve.current||await o(e=>JE(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,W.jsx)(f,{size:18}),(0,W.jsx)(`span`,{children:`Copy`})]}),he&&(0,W.jsx)(`div`,{className:`copy-menu`,children:[[`all`,`All events`],[`text`,`Text messages only`],[`non-text`,`Non-text only`]].map(([e,t])=>(0,W.jsx)(`button`,{type:`button`,className:`copy-menu-item`,onClick:async()=>{let t=YE(P,e);t&&s(await L(t)),i()},children:t},e))})]}),(0,W.jsx)(`button`,{type:`button`,className:`selection-cancel`,onClick:i,children:`Cancel`})]})}):(0,W.jsxs)(`div`,{className:`chat-input-area`,children:[(0,W.jsx)(`input`,{ref:x,type:`file`,multiple:!0,accept:St,style:{display:`none`},onChange:e=>{e.target.files&&S([...e.target.files]),e.target.value=``}}),g.length>0&&(0,W.jsx)(`div`,{className:`attachment-strip`,children:g.map((e,t)=>(0,W.jsxs)(`div`,{className:`attachment-chip`,children:[e.type.startsWith(`image/`)?(0,W.jsx)(`img`,{src:URL.createObjectURL(e),alt:e.name,className:`attachment-chip-thumb`}):e.type===`application/pdf`?(0,W.jsx)(c,{size:14}):(0,W.jsx)(E,{size:14}),(0,W.jsx)(`span`,{className:`attachment-chip-name`,children:e.name}),(0,W.jsx)(`button`,{type:`button`,className:`attachment-chip-remove`,onClick:()=>C(t),"aria-label":`Remove ${e.name}`,children:`×`})]},t))}),b&&(0,W.jsx)(`p`,{className:`attach-error`,children:b}),ye.state===`error`&&ye.errorMessage&&(0,W.jsxs)(`p`,{className:`voice-error`,role:`alert`,children:[(0,W.jsx)(m,{size:14}),ye.errorMessage]}),(0,W.jsx)(T,{inputRef:h}),be?(0,W.jsx)(`div`,{className:`chat-form voice-active`,children:(0,W.jsx)(A,{state:ye.state,elapsedSeconds:ye.elapsedSeconds,waveform:ye.waveform,onTogglePause:ye.togglePause,onDiscard:ye.discard,onSend:Se})}):(0,W.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){I([...ee.current,{text:t,files:[...g],timestamp:Date.now()}]),p(``),v([]),h.current?.resetHeight();return}R(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,W.jsx)(w,{variant:`icon`,type:`button`,onClick:()=>x.current?.click(),"aria-label":`Attach file`,children:(0,W.jsx)(u,{size:14})}),(0,W.jsx)(N,{ref:h,value:l,onChange:p}),j?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(w,{variant:`send`,type:`button`,onClick:()=>ne(!0),"aria-label":`Pause`,style:{background:`var(--text-secondary)`},children:(0,W.jsx)(d,{size:14})}),(0,W.jsx)(w,{variant:`send`,type:`button`,onClick:()=>ne(!1),"aria-label":`Stop`,style:{background:`var(--danger)`},children:(0,W.jsx)(dt,{size:14})})]}):xe?(0,W.jsx)(w,{variant:`send`,type:`button`,onClick:ye.start,"aria-label":`Record voice note`,children:(0,W.jsx)(m,{size:14})}):(0,W.jsx)(w,{variant:`send`,type:`submit`,disabled:!l.trim()&&g.length===0&&!M,"aria-label":`Send message`,children:M?(0,W.jsx)(_,{size:14}):(0,W.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,W.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,W.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,W.jsxs)(`div`,{className:`chat-actions`,ref:me,children:[(0,W.jsx)(`button`,{type:`button`,className:`chat-action-icon`,title:`New conversation`,"aria-label":`New conversation`,disabled:le,onClick:ce,children:(0,W.jsx)(ze,{size:16})}),(0,W.jsx)(`button`,{type:`button`,className:`chat-action-icon`,title:`Select messages`,"aria-label":`Select messages`,onClick:a,children:(0,W.jsx)(te,{size:16})}),!de&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`button`,{className:`burger-trigger`,onClick:()=>pe(e=>!e),"aria-expanded":fe,"aria-haspopup":`true`,"aria-label":`Conversation actions`,children:(0,W.jsx)(Me,{size:16})}),(0,W.jsx)(`div`,{className:`actions-menu-items${fe?` actions-menu-open`:``}`,children:(0,W.jsx)(aD,{conversationId:oe,sessionKey:se,disconnecting:re,onOpenConversations:ue,handleDisconnect:ie,onAfterAction:()=>pe(!1)})})]}),(0,W.jsxs)(`div`,{className:`powered-by`,onClick:async()=>{if(ae(!0),!z){let e=await fetch(`/api/admin/claude-info`);e.ok&&B(await e.json())}},children:[(0,W.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`powered-by-icon`}),(0,W.jsx)(`span`,{children:`Powered by Claude Code`})]})]})]})}var sD=`maxy-vnc-overlay-popout`;function cD(e){let[t,n]=(0,U.useState)(!1),r=(0,U.useRef)(null),i=(0,U.useRef)(null),a=(0,U.useCallback)(()=>{i.current&&=(clearInterval(i.current),null),r.current&&!r.current.closed&&r.current.close(),r.current=null,n(!1)},[]),o=(0,U.useCallback)(()=>{let t=`/vnc-popout.html?title=${encodeURIComponent(C.productName)}`,o=window.open(t,sD,`width=1024,height=768`);o&&(r.current=o,n(!0),i.current=setInterval(()=>{r.current?.closed&&(a(),e?.())},500))},[a,e]);return(0,U.useEffect)(()=>()=>a(),[a]),{poppedOut:t,popout:o,cleanupPopout:a}}var lD=(0,U.forwardRef)(function({onClose:e},t){vt();let{poppedOut:n,popout:r,cleanupPopout:i}=cD(e);return(0,U.useImperativeHandle)(t,()=>({popout:r}),[r]),n?(0,W.jsxs)(`div`,{className:`browser-overlay-popout`,children:[(0,W.jsx)(D,{className:`browser-viewer__icon`}),(0,W.jsx)(`span`,{className:`browser-viewer__title`,children:C.productName}),(0,W.jsx)(`span`,{className:`browser-viewer__popout-label`,children:`Popped out`}),(0,W.jsx)(w,{variant:`ghost`,size:`sm`,icon:tt,onClick:()=>i(),"aria-label":`Pop back in`}),e&&(0,W.jsx)(w,{variant:`ghost`,size:`sm`,icon:ie,onClick:()=>{i(),e()},"aria-label":`Close`})]}):(0,W.jsx)(`iframe`,{src:`/vnc-viewer.html`,className:`browser-surface__iframe`,title:C.productName})});function uD({onClose:e}){vt();let{poppedOut:t,popout:n,cleanupPopout:r}=cD(e),i=(0,U.useCallback)(()=>{r(),e()},[r,e]);(0,U.useEffect)(()=>{if(t)return;let e=e=>{e.key===`Escape`&&i()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,i]);let a=nn({handlePopout:n,disabled:t});return t?(0,W.jsxs)(`div`,{className:`browser-overlay-popout`,children:[(0,W.jsx)(D,{className:`browser-viewer__icon`}),(0,W.jsx)(`span`,{className:`browser-viewer__title`,children:C.productName}),(0,W.jsx)(`span`,{className:`browser-viewer__popout-label`,children:`Popped out`}),(0,W.jsx)(w,{variant:`ghost`,size:`sm`,icon:tt,onClick:()=>{r()},"aria-label":`Pop back in`}),(0,W.jsx)(w,{variant:`ghost`,size:`sm`,icon:ie,onClick:i,"aria-label":`Close`})]}):(0,W.jsxs)(`div`,{className:`browser-viewer-fullscreen`,children:[(0,W.jsxs)(`div`,{className:`browser-viewer-fullscreen__bar`,...a,children:[(0,W.jsx)(D,{className:`browser-viewer__icon`}),(0,W.jsx)(`span`,{className:`browser-viewer-fullscreen__title`,children:C.productName}),(0,W.jsxs)(`div`,{className:`browser-viewer-fullscreen__actions`,children:[(0,W.jsx)(w,{variant:`ghost`,size:`sm`,icon:Ne,onClick:n,"aria-label":`Pop out`}),(0,W.jsx)(w,{variant:`ghost`,size:`sm`,icon:ie,onClick:i,"aria-label":`Close`})]})]}),(0,W.jsx)(`iframe`,{src:`/vnc-viewer.html`,className:`browser-viewer-fullscreen__iframe`,title:C.productName})]})}var dD=(0,U.forwardRef)(function(e,t){let{businessName:n,sessionKey:r,conversationId:i,role:a,userName:o,userAvatar:s,sessions:l,sessionsLoading:u,sessionsError:d,ensureSessionsLoaded:f,refetchSessions:p,onSelectSession:m,onSelectArtefact:h,onSelectProjects:g,onSelectPeople:_,onSelectTasks:v,onSelectAgents:y,onCloseMobileDrawer:b,collapsed:x,onToggleCollapsed:S,actions:w}=e;(0,U.useEffect)(()=>{f()},[f]);let T=C.productName,E=typeof o==`string`?o:o===null?`name unavailable`:n||T,D=(E.trim().charAt(0)||`?`).toUpperCase(),[O,k]=(0,U.useState)(`all`),A=(0,U.useMemo)(()=>l.filter(e=>e.name).filter(e=>O===`all`?!0:(e.channel??`webchat`)===O),[l,O]),j=A.length,M=i??r,[N,P]=(0,U.useState)(`chat`),[F,ee]=(0,U.useState)([]),[I,te]=(0,U.useState)(!1),[L,R]=(0,U.useState)(null),[re,ie]=(0,U.useState)(!1);(0,U.useImperativeHandle)(t,()=>({patchArtefact(e,t){ee(n=>n.map(n=>n.id===e?{...n,...t}:n))}}),[]);let[z,B]=(0,U.useState)(!1),ae=(0,U.useRef)(null);(0,U.useEffect)(()=>{if(!z)return;function e(e){ae.current&&!ae.current.contains(e.target)&&B(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[z]);let oe=(0,U.useCallback)(async()=>{if(r){ie(!0),R(null);try{let e=await fetch(`/api/admin/sidebar-artefacts?session_key=${encodeURIComponent(r)}`);if(!e.ok)throw Error(`status ${e.status}`);ee((await e.json()).artefacts??[]),te(!0)}catch(e){let t=e instanceof Error?e.message:String(e);R(`Failed to load artefacts: ${t}`),console.error(`[admin-ui] sidebar-artefacts fetch failed: ${t}`)}finally{ie(!1)}}},[r]),se=()=>{P(`chat`),console.info(`[admin-ui] sidebar-nav surface=chat count=${j}`)},ce=()=>{P(`artefacts`),console.info(`[admin-ui] sidebar-nav surface=artefacts count=${I?F.length:0}`),I||oe()},le=x?24:16,ue=N===`chat`?`Recents`:`Artefacts`,de=N===`chat`?u?`…`:String(j):re?`…`:String(F.length),fe=N===`chat`?u:re,pe=()=>{N===`chat`?p():oe(),console.info(`[admin-ui] sidebar-refresh surface=${N}`)};return(0,W.jsxs)(`aside`,{className:`side`,children:[(0,W.jsx)(`div`,{className:`side-head`,children:(0,W.jsx)(`button`,{className:`icon-btn side-head-toggle`,title:x?`Expand sidebar`:`Collapse sidebar`,type:`button`,"aria-label":x?`Expand sidebar`:`Collapse sidebar`,onClick:S,children:x?(0,W.jsx)(at,{size:28}):(0,W.jsx)(it,{size:28})})}),(0,W.jsxs)(`nav`,{className:`side-nav`,children:[(0,W.jsxs)(`button`,{type:`button`,className:`nav-row${N===`chat`?` active`:``}`,onClick:se,children:[(0,W.jsx)(et,{size:le}),(0,W.jsx)(`span`,{className:`label`,children:`Chat`}),(0,W.jsx)(`span`,{className:`kbd`})]}),(0,W.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=people`),_(),b()},children:[(0,W.jsx)(ht,{size:le}),(0,W.jsx)(`span`,{className:`label`,children:`People`}),(0,W.jsx)(`span`,{className:`kbd`})]}),(0,W.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=agents`),y(),b()},children:[(0,W.jsx)(xe,{size:le}),(0,W.jsx)(`span`,{className:`label`,children:`Agents`}),(0,W.jsx)(`span`,{className:`kbd`})]}),(0,W.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=projects`),g(),b()},children:[(0,W.jsx)(Se,{size:le}),(0,W.jsx)(`span`,{className:`label`,children:`Projects`}),(0,W.jsx)(`span`,{className:`kbd`})]}),(0,W.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=tasks`),v(),b()},children:[(0,W.jsx)(qe,{size:le}),(0,W.jsx)(`span`,{className:`label`,children:`Tasks`}),(0,W.jsx)(`span`,{className:`kbd`})]}),(0,W.jsxs)(`button`,{type:`button`,className:`nav-row${N===`artefacts`?` active`:``}`,onClick:ce,children:[(0,W.jsx)(c,{size:le}),(0,W.jsx)(`span`,{className:`label`,children:`Artefacts`}),(0,W.jsx)(`span`,{className:`kbd`})]})]}),(0,W.jsxs)(`div`,{className:`side-list`,children:[(0,W.jsxs)(`div`,{className:`group-head`,children:[(0,W.jsx)(`span`,{children:ue}),(0,W.jsxs)(`span`,{className:`group-head-meta`,children:[(0,W.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh ${ue.toLowerCase()}`,"aria-label":`Refresh ${ue.toLowerCase()}`,onClick:pe,disabled:fe,children:(0,W.jsx)(ne,{size:12,className:fe?`spinning`:void 0})}),(0,W.jsx)(`span`,{children:de})]})]}),N===`chat`&&(0,W.jsxs)(W.Fragment,{children:[d&&(0,W.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:d}),(0,W.jsxs)(Qt,{className:`conv-channel-filter`,value:O,onChange:e=>{let t=e.target.value;k(t),console.info(`[admin-ui] sidebar-channel-filter set value=${t}`)},"aria-label":`Filter conversations by channel`,children:[(0,W.jsx)(`option`,{value:`all`,children:`All channels`}),(0,W.jsx)(`option`,{value:`webchat`,children:`Web`})]}),A.map(e=>{let t=e.conversationId??e.sessionKey,n=t!==null&&t===M,r=e.channel??`webchat`;return(0,W.jsxs)(`button`,{type:`button`,className:`conv${n?` active`:``}`,onClick:()=>{let t=e.sessionKey?e.sessionKey.slice(0,8):`null`,n=e.conversationId?e.conversationId.slice(0,8):`null`;console.info(`[admin-session-identity] sessionKey=${t} conversationId=${n} phase=${e.phase} surface=sidebar-recents`),m(e),b()},children:[r===`whatsapp`&&(0,W.jsx)(Ze,{size:12,className:`conv-channel-icon`,"aria-label":`WhatsApp`}),(0,W.jsx)(`span`,{className:`conv-name`,children:e.name??`(untitled)`})]},t??e.updatedAt)})]}),N===`artefacts`&&(0,W.jsxs)(W.Fragment,{children:[L&&(0,W.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:L}),I&&!L&&F.length===0&&(0,W.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No artefacts yet`}),F.map(e=>(0,W.jsxs)(`button`,{type:`button`,className:`conv`,onClick:()=>{h({docId:e.id,name:e.name,content:e.content,editable:e.editable,mimeType:e.mimeType,skipReason:e.skipReason},`sidebar-artefacts`),b()},children:[(0,W.jsx)(`span`,{className:`conv-name`,children:e.name}),(0,W.jsx)(`span`,{className:`conv-kind`,"data-kind":e.kind===`agent-template`?`agent`:`doc`,children:e.kind===`agent-template`?`agent`:`doc`})]},e.id))]})]}),(0,W.jsxs)(`div`,{className:`side-foot`,ref:ae,children:[(0,W.jsx)(`div`,{className:`avatar`,children:s?(0,W.jsx)(`img`,{src:s,alt:E}):D}),(0,W.jsxs)(`div`,{className:`who`,children:[(0,W.jsx)(`span`,{className:`name`,children:E}),(0,W.jsx)(`span`,{className:`role`,children:a??`operator`})]}),(0,W.jsx)(`button`,{className:`icon-btn side-foot-actions-trigger`,title:`Conversation actions`,type:`button`,"aria-label":`Conversation actions`,"aria-haspopup":`true`,"aria-expanded":z,onClick:()=>B(e=>!e),children:(0,W.jsx)(Me,{size:le})}),z&&(0,W.jsx)(`div`,{className:`side-foot-actions-popover`,children:(0,W.jsx)(aD,{...w,onAfterAction:()=>B(!1)})})]})]})}),fD=()=>{},pD={"null-attachmentId":`No file backing this artefact.`,"non-text-mime":`Content type cannot be displayed inline.`,"containment-rejected":`File path failed containment check; cannot display.`,"missing-on-disk":`File is missing on disk.`};function mD({reason:e}){return(0,W.jsxs)(`div`,{className:`art-skip-banner`,role:`status`,children:[(0,W.jsx)(Ie,{size:14}),(0,W.jsx)(`span`,{children:pD[e]})]})}function hD({src:e,name:t,docId:n}){let[r,i]=(0,U.useState)(!1),a=(0,U.useRef)(null),o=(0,U.useRef)(!1),s=(0,U.useRef)(!1),l=(0,U.useCallback)(e=>{s.current||(s.current=!0,console.info(`[admin-ui] artefact-pdf-fallback id=${n.slice(0,8)} reason=${e}`),i(!0))},[n]);(0,U.useEffect)(()=>{let e=setTimeout(()=>{o.current||l(`onload-timeout`)},3e3);return()=>clearTimeout(e)},[l]);let u=()=>{o.current=!0;try{let e=a.current?.contentDocument?.body;e&&e.children.length===0&&!e.textContent?.trim()&&l(`empty-body`)}catch{}};return r?(0,W.jsxs)(`a`,{className:`art-pdf-fallback`,href:e,download:t,children:[(0,W.jsx)(c,{size:20}),(0,W.jsxs)(`div`,{className:`art-pdf-fallback-text`,children:[(0,W.jsx)(`div`,{className:`art-pdf-fallback-name`,children:t}),(0,W.jsx)(`div`,{className:`art-pdf-fallback-hint`,children:`Your browser can't display this PDF inline. Click to download.`})]}),(0,W.jsx)(B,{size:16})]}):(0,W.jsx)(`iframe`,{ref:a,className:`art-pdf`,src:e,title:t,"aria-label":`PDF preview of ${t}`,onLoad:u,onError:()=>l(`onerror`)})}var gD={browser:`Browser`,data:`Data`,graph:`Graph`};function _D({selection:e,trigger:t,sessionKey:n,onClose:r,onArtefactSaved:i,onSwapToGraph:a}){let o=e!==null,s=e?.surface??null,c=(0,U.useRef)(null),l=(0,U.useRef)(null),[u,d]=(0,U.useState)(null),p=e?.surface===`doc`?e.docId:null,m=(0,U.useCallback)(e=>{if(!n||!p)return;let t={};try{t=JSON.parse(e)}catch{return}t.action!==`save`||typeof t.content!=`string`||(d(null),fetch(`/api/admin/sidebar-artefact-save?session_key=${encodeURIComponent(n)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({id:p,content:t.content})}).then(async e=>{if(!e.ok){let t=(await e.json().catch(()=>({}))).error??`status ${e.status}`;d(`Save failed: ${t}`),console.error(`[admin-ui] artefact-save-failed docId=${p} status=${e.status} error="${t}"`);return}let n=await e.json();i?.(p,n.updatedAt,t.content)}).catch(e=>{let t=e instanceof Error?e.message:String(e);d(`Save failed: ${t}`),console.error(`[admin-ui] artefact-save-failed docId=${p} error="${t}"`)}))},[n,p,i]);(0,U.useEffect)(()=>{d(null)},[p]),(0,U.useEffect)(()=>{let n=e?.surface===`doc`?e.docId:null,r=e?.surface===`graph`?e.focusNodeId??null:null,i=e?.surface??null,a=i===null?`closed`:`${i}:${n??`none`}:${r??`none`}`;if(a===c.current)return;let s=o?`open`:`closed`,l=o?t??`chat-link`:`toolbar-close`,u=i??c.current?.split(`:`)[0]??`doc`;console.info(`[admin-ui] artefact-pane state=${s} docId=${n??`none`} trigger=${l} surface=${u}`),c.current=a},[e,t,o]);let h=e?.surface===`doc`,g=h?(e.tag||e.name.split(`.`).pop()||`doc`).toUpperCase().slice(0,6):``,_=h?e.revision||`rev 1`:`live`,v=e&&e.surface!==`doc`?gD[e.surface]:``,y=h?e.name:v;return(0,W.jsxs)(`aside`,{className:`artefact`,"data-open":o,"data-surface":s??`none`,children:[(0,W.jsxs)(`div`,{className:`art-head`,children:[(0,W.jsxs)(`div`,{className:`left`,children:[!h&&s===`browser`&&(0,W.jsx)(D,{size:14,className:`art-head-surface-icon`}),!h&&s===`data`&&(0,W.jsx)(ue,{size:14,className:`art-head-surface-icon`}),!h&&s===`graph`&&(0,W.jsx)(pe,{size:14,className:`art-head-surface-icon`}),(0,W.jsx)(`span`,{className:`file-name`,children:y}),h&&(0,W.jsx)(`span`,{className:`file-tag`,children:g})]}),(0,W.jsxs)(`div`,{className:`right`,children:[h&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`button`,{className:`icon-btn`,title:`Copy`,type:`button`,"aria-label":`Copy`,onClick:()=>{L(e.content)},children:(0,W.jsx)(f,{size:14})}),(0,W.jsx)(`button`,{className:`icon-btn`,title:`Refresh`,type:`button`,"aria-label":`Refresh`,children:(0,W.jsx)(re,{size:14})})]}),s===`browser`&&(0,W.jsx)(`button`,{className:`icon-btn`,title:`Pop out`,type:`button`,"aria-label":`Pop out`,onClick:()=>l.current?.popout(),children:(0,W.jsx)(Ne,{size:14})}),o&&(0,W.jsx)(`button`,{className:`icon-btn`,title:`Close`,type:`button`,"aria-label":`Close`,onClick:r,children:(0,W.jsx)(ie,{size:14})})]})]}),(0,W.jsxs)(`div`,{className:`art-toolbar`,children:[(0,W.jsxs)(`span`,{className:`seg`,children:[(0,W.jsx)(`span`,{className:`bullet`}),(0,W.jsx)(`strong`,{children:h?`Artefact`:v})]}),(0,W.jsx)(`span`,{className:`right-meta`,children:_})]}),(0,W.jsxs)(`div`,{className:`art-body`,"data-surface":s??`none`,children:[h&&(()=>{let t=e.editable!==!1,r=e.skipReason??null,i=(e.mimeType??``).startsWith(`application/pdf`);if(r)return(0,W.jsx)(mD,{reason:r});if(i&&n){let t=`/api/admin/sidebar-artefact-content?id=${encodeURIComponent(e.docId)}&session_key=${encodeURIComponent(n)}`;return(0,W.jsx)(hD,{src:t,name:e.name,docId:e.docId},t)}return(0,W.jsxs)(W.Fragment,{children:[u&&(0,W.jsx)(`div`,{className:`art-save-error`,role:`alert`,children:u}),(0,W.jsx)(nT,{data:{title:e.name,content:e.content,readOnly:!t},onSubmit:t?m:fD,submitted:!1})]})})(),s===`browser`&&(0,W.jsx)(lD,{ref:l,onClose:r}),s===`data`&&n&&(0,W.jsx)(oe,{sessionKey:n,onOpenInGraph:a?e=>{let t=se(e.properties);a(e.nodeId,t??e.labels[0]??null)}:void 0}),e?.surface===`graph`&&n&&(0,W.jsx)(z,{sessionKey:n,initialFocus:e.focusNodeId?{nodeId:e.focusNodeId,nodeLabel:e.focusNodeLabel??null}:null,initialLabels:e.initialLabels??null})]}),(0,W.jsxs)(`div`,{className:`art-foot`,children:[(0,W.jsx)(`span`,{className:`left`,children:_}),(0,W.jsx)(`span`,{className:`right in-sync`,children:`in sync`})]})]})}var vD=`maxy-shell-artefact-px`;function yD(){if(typeof window>`u`)return 320;let e=window.innerWidth,t=document.querySelector(`.platform > .side`)?.getBoundingClientRect(),n=t?t.right:Math.round(e*.3);return xD(Math.round((e-n)*(2/3)))}function bD(){if(typeof window>`u`)return 320;try{let e=window.localStorage.getItem(vD);if(!e)return yD();let t=parseInt(e,10);if(Number.isFinite(t)&&t>=320)return t}catch{}return yD()}function xD(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=document.querySelector(`.platform > .side`)?.getBoundingClientRect(),r=n?n.right:Math.round(t*.3),i=Math.max(320,t-r-480);return Math.min(Math.max(e,320),i)}function SD({targetSelector:e=`.platform`}){let t=(0,U.useRef)(null),[n,r]=(0,U.useState)(()=>bD()),i=(0,U.useRef)(n);(0,U.useEffect)(()=>{let t=document.querySelector(e);!t||!(t instanceof HTMLElement)||(t.style.setProperty(`--artefact-px`,`${n}px`),i.current=n)},[n,e]);let a=(0,U.useCallback)(()=>{r(e=>{let t=xD(e);return t===e?e:t})},[]);(0,U.useEffect)(()=>(a(),window.addEventListener(`resize`,a),()=>window.removeEventListener(`resize`,a)),[a]);let o=e=>{e.preventDefault();let n=t.current;if(!n)return;n.setPointerCapture(e.pointerId),n.classList.add(`dragging`);let a=!1,o=e=>{a=!0,r(xD(Math.round(window.innerWidth-e.clientX)))},s=()=>{if(n.releasePointerCapture(e.pointerId),n.classList.remove(`dragging`),window.removeEventListener(`pointermove`,o),window.removeEventListener(`pointerup`,s),!a)return;let t=i.current;try{window.localStorage.setItem(vD,String(t))}catch{}console.info(`[admin-ui] artefact-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=yD();r(e);try{window.localStorage.removeItem(vD)}catch{}console.info(`[admin-ui] artefact-resize px=${e}`)};return(0,W.jsx)(`div`,{ref:t,className:`art-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize artefact pane`,onPointerDown:o,onDoubleClick:s})}var CD=`maxy-shell-side-px`;function wD(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .artefact`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function TD(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=Math.max(220,t-480-wD());return Math.min(Math.max(e,220),n)}function ED(){if(typeof window>`u`)return 264;try{let e=window.localStorage.getItem(CD);if(!e)return 264;let t=parseInt(e,10);if(Number.isFinite(t)&&t>=220)return TD(t)}catch{}return 264}function DD({targetSelector:e=`.platform`}){let t=(0,U.useRef)(null),[n,r]=(0,U.useState)(()=>ED()),i=(0,U.useRef)(n);(0,U.useEffect)(()=>{let t=document.querySelector(e);!t||!(t instanceof HTMLElement)||(t.style.setProperty(`--side-px`,`${n}px`),i.current=n)},[n,e]);let a=(0,U.useCallback)(()=>{r(e=>{let t=TD(e);return t===e?e:t})},[]);(0,U.useEffect)(()=>{a(),window.addEventListener(`resize`,a);let t=document.querySelector(e),n=null;return t instanceof HTMLElement&&(n=new MutationObserver(a),n.observe(t,{attributes:!0,attributeFilter:[`data-artefact`,`class`]})),()=>{window.removeEventListener(`resize`,a),n?.disconnect()}},[a,e]);let o=e=>{e.preventDefault();let n=t.current;if(!n)return;n.setPointerCapture(e.pointerId),n.classList.add(`dragging`);let a=!1,o=e=>{a=!0,r(TD(Math.round(e.clientX)))},s=()=>{if(n.releasePointerCapture(e.pointerId),n.classList.remove(`dragging`),window.removeEventListener(`pointermove`,o),window.removeEventListener(`pointerup`,s),!a)return;let t=i.current;try{window.localStorage.setItem(CD,String(t))}catch{}console.info(`[admin-ui] sidebar-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=TD(264);r(e);try{window.localStorage.removeItem(CD)}catch{}console.info(`[admin-ui] sidebar-resize px=${e}`)};return(0,W.jsx)(`div`,{ref:t,className:`side-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize sidebar`,onPointerDown:o,onDoubleClick:s})}function OD(e){let[t,n]=(0,U.useState)([]),[r,i]=(0,U.useState)(!1),[a,o]=(0,U.useState)(null),[s,c]=(0,U.useState)(null),l=(0,U.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,U.useEffect)(()=>{e||(c(null),n([]),o(null))},[e]);let u=(0,U.useCallback)(()=>l(!1),[l]),d=(0,U.useCallback)(()=>l(!0),[l]);return{sessions:t,setSessions:n,loading:r,loaded:s!==null&&s===e,error:a,ensureLoaded:u,refetch:d}}function kD(){vt();let e=(0,U.useRef)(null),[t,n]=(0,U.useState)(null),[r,a]=(0,U.useState)(!1),[o,s]=(0,U.useState)(!1),[c,l]=(0,U.useState)(``),[u,d]=(0,U.useState)(!1),[f,p]=(0,U.useState)(null),[m,_]=(0,U.useState)(!1),[v,y]=(0,U.useState)(null),[b,x]=(0,U.useState)(null),[w,T]=(0,U.useState)(!1),[E,O]=(0,U.useState)(null),[k,A]=(0,U.useState)(!1),[j,M]=(0,U.useState)(null),[N,P]=(0,U.useState)(!1),[F,ee]=(0,U.useState)(!1),[te,R]=(0,U.useState)(!1),[ne,re]=(0,U.useState)(!1),[z,B]=(0,U.useState)(null),[ae,oe]=(0,U.useState)(null),se=(0,U.useRef)(null),[le,de]=(0,U.useState)(()=>typeof window<`u`&&window.matchMedia(`(min-width: 641px)`).matches);(0,U.useEffect)(()=>{let e=window.matchMedia(`(min-width: 641px)`),t=e=>de(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let[he,ge]=(0,U.useState)(()=>typeof window<`u`&&window.matchMedia(`(min-width: 1080px)`).matches);(0,U.useEffect)(()=>{let e=window.matchMedia(`(min-width: 1080px)`),t=e=>ge(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let _e=(0,U.useRef)(!1),ve=(0,U.useRef)(!1),ye=(0,U.useRef)(!1),be=(0,U.useRef)(!1),xe=(0,U.useRef)(null),[Se,Ce]=(0,U.useState)(null),we=g(),Te=xt(),V=Dt(),Ee=Ht(),De=OD(V.sessionKey),H=Vt({sessionKey:V.sessionKey,setSessionKey:V.setSessionKey,setAppState:V.setAppState,conversationId:V.conversationId,setConversationId:V.setConversationId,startElapsedTimer:Te.startElapsedTimer,stopElapsedTimer:Te.stopElapsedTimer,resetTimerState:Te.resetTimerState,pausedElapsedRef:Te.pausedElapsedRef,expandAllDefaultRef:V.expandAllDefaultRef,setExpandAll:V.setExpandAll,getPendingFiles:()=>Ee.pendingFiles,clearPendingFiles:Ee.clearFiles,inputRef:e});(0,U.useEffect)(()=>{l(window.location.hostname.startsWith(`admin.`)?window.location.origin.replace(`admin.`,`public.`):window.location.origin)},[]),(0,U.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,U.useEffect)(()=>{(V.appState===`set-pin`||V.appState===`enter-pin`)&&setTimeout(()=>V.pinInputRef.current?.focus(),100),V.appState===`chat`&&setTimeout(()=>e.current?.focus(),100)},[V.appState,H.greetingGeneration]),(0,U.useEffect)(()=>{if(V.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)},[V.appState]);let Oe=(0,U.useRef)(H.greetingGeneration);if((0,U.useEffect)(()=>{H.greetingGeneration!==Oe.current&&(Oe.current=H.greetingGeneration,V.onboardingComplete===!1&&(_e.current=!1))},[H.greetingGeneration,V.onboardingComplete]),(0,U.useEffect)(()=>{V.appState===`chat`&&V.onboardingComplete===!1&&(_e.current||(_e.current=!0,H.sendSystemPrompt(`[Begin onboarding.]`)))},[V.appState,V.onboardingComplete,H.greetingGeneration]),(0,U.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,U.useEffect)(()=>{if(V.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}},[V.appState]),(0,U.useEffect)(()=>{if(V.appState!==`chat`||!V.sessionKey)return;let e=V.conversationId?`flushed`:`pre-flush`,t=V.sessionKey.slice(0,8),n=V.conversationId?V.conversationId.slice(0,8):`null`;console.info(`[admin-session-identity] sessionKey=${t} conversationId=${n} phase=${e} surface=chat-header`)},[V.appState,V.sessionKey,V.conversationId]),(0,U.useEffect)(()=>{if(V.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=z?`open`:`closed`;console.info(`[admin-ui] platform-shell brand=${C.productName} sidebar=${e} artefact=${t}`)},[V.appState,De.loaded,De.sessions,z]),(0,U.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,U.useEffect)(()=>{if(typeof BroadcastChannel>`u`)return;let e=new BroadcastChannel(`platform-onboarding`);return e.onmessage=e=>{e.data?.type===`remote-password-set`&&H.sendMessageRef.current(`I've set the remote password`)},()=>e.close()},[]),V.appState===`loading`)return(0,W.jsx)(`div`,{className:`chat-page admin-page`,children:(0,W.jsx)(`header`,{className:`chat-header`,children:(0,W.jsx)(`img`,{src:I,alt:C.productName,className:`chat-logo`})})});if(V.appState===`set-pin`)return(0,W.jsx)(Wt,{pin:V.pin,setPin:V.setPin,confirmPin:V.confirmPin,setConfirmPin:V.setConfirmPin,operatorName:V.operatorName,setOperatorName:V.setOperatorName,showPin:V.showPin,setShowPin:V.setShowPin,pinLoading:V.pinLoading,pinError:V.pinError,pinInputRef:V.pinInputRef,confirmPinInputRef:V.confirmPinInputRef,setPinFormRef:V.setPinFormRef,onSubmit:V.handleSetPin});if(V.appState===`onboarding-choice`)return(0,W.jsx)(Jt,{setAppState:V.setAppState,setOnboardingComplete:V.setOnboardingComplete});if(V.appState===`connect-claude`)return(0,W.jsx)(qt,{authPolling:V.authPolling,setAuthPolling:V.setAuthPolling,authLoading:V.authLoading,setAuthLoading:V.setAuthLoading,pinError:V.pinError,setPinError:V.setPinError,setAppState:V.setAppState});if(V.appState===`enter-pin`)return(0,W.jsx)(Gt,{pin:V.pin,setPin:V.setPin,showPin:V.showPin,setShowPin:V.setShowPin,pinLoading:V.pinLoading,pinError:V.pinError,pinInputRef:V.pinInputRef,onSubmit:V.handleLogin,onChangePin:V.handleChangePin});if(V.appState===`account-picker`)return(0,W.jsx)(Kt,{accounts:V.accounts,loading:V.accountPickerLoading,error:V.pinError,onSelect:V.handleAccountSelect});let ke=z?`open`:`closed`,Ae=ne&&le,je=`platform${te?` menu-open`:``}${Ae?` sidebar-collapsed`:``}`,Me=e=>{if(!H.isStreaming&&V.sessionKey){if(!e.conversationId){H.resetConversation(),H.setMessages([]),V.setConversationId(null);return}H.resetConversation(),H.setMessages([]),fetch(`/api/admin/sessions/${encodeURIComponent(e.conversationId)}/resume?session_key=${encodeURIComponent(V.sessionKey)}`,{method:`POST`}).then(e=>e.ok?e.json():Promise.reject(Error(`resume returned ${e.status}`))).then(e=>{e.conversationId&&V.setConversationId(e.conversationId);let t=(e.messages??[]).map(e=>({role:e.role===`user`?`admin`:`maxy`,content:e.role===`user`?e.content:void 0,events:e.role===`assistant`?e.events??[]:void 0,...e.role===`user`&&e.attachments&&e.attachments.length>0?{attachments:e.attachments}:{},timestamp:new Date(e.createdAt).getTime()||0,historical:!0,...e.messageId?{messageId:e.messageId}:{}}));t.length>0&&H.setMessages(t);let n=[];for(let t of e.messages??[]){if(t.role!==`assistant`||!t.submittedEventIndices?.length)continue;let e=new Date(t.createdAt).getTime()||0;for(let r of t.submittedEventIndices)n.push(`${e}_${r}`)}n.length>0&&H.seedSubmittedComponents(n)}).catch(e=>{console.error(`[chat] sidebar conversation resume failed:`,e),H.setMessages([{role:`maxy`,events:[{type:`text`,content:`Could not load conversation history.`}],timestamp:Date.now()-1,historical:!0}])})}},Pe={conversationId:V.conversationId,sessionKey:V.sessionKey,disconnecting:V.disconnecting,onOpenConversations:()=>{T(!0),De.refetch()},handleDisconnect:V.handleDisconnect};return(0,W.jsx)(S,{value:{onShowVnc:()=>P(!0)},children:(0,W.jsxs)(`div`,{className:je,"data-artefact":ke,children:[(0,W.jsx)(`div`,{className:`scrim`,onClick:()=>{R(!1),console.info(`[admin-ui] mobile-drawer state=closed`)}}),(0,W.jsx)(dD,{ref:se,businessName:V.businessName??null,sessionKey:V.sessionKey,conversationId:V.conversationId,role:V.role,userName:V.userName,userAvatar:V.userAvatar,sessions:De.sessions,sessionsLoading:De.loading,sessionsError:De.error,ensureSessionsLoaded:De.ensureLoaded,refetchSessions:De.refetch,onSelectSession:Me,onSelectArtefact:(e,t)=>{B({surface:`doc`,...e}),oe(t)},onSelectProjects:()=>{B({surface:`graph`,initialLabels:[`Project`]}),oe(`sidebar-projects`)},onSelectPeople:()=>{B({surface:`graph`,initialLabels:[`Person`]}),oe(`sidebar-people`)},onSelectTasks:()=>{B({surface:`graph`,initialLabels:[`Task`]}),oe(`sidebar-tasks`)},onSelectAgents:()=>{B({surface:`graph`,initialLabels:[`Agent`]}),oe(`sidebar-agents`)},onCloseMobileDrawer:()=>{te&&(R(!1),console.info(`[admin-ui] mobile-drawer state=closed`))},collapsed:Ae,onToggleCollapsed:()=>re(e=>!e),actions:Pe}),(0,W.jsxs)(`div`,{className:`chat-page admin-page`,children:[(0,W.jsxs)(`header`,{className:`chat-header`,children:[(0,W.jsx)(`button`,{type:`button`,className:`icon-btn mobile-menu`,"aria-label":`Show sidebar`,title:`Show sidebar`,onClick:()=>{R(e=>{let t=!e;return console.info(`[admin-ui] mobile-drawer state=${t?`open`:`closed`}`),t})},children:(0,W.jsx)(at,{size:16})}),(0,W.jsx)(`img`,{src:I,alt:C.productName,className:`chat-logo`}),(!C.logoContainsName||V.businessName)&&(0,W.jsx)(`div`,{children:(0,W.jsx)(`h1`,{className:`chat-tagline`,children:V.businessName||C.productName})}),(V.sessionKey||V.conversationId)&&(0,W.jsxs)(`button`,{type:`button`,className:`chat-session-chip chat-session-chip-${V.conversationId?`flushed`:`pre-flush`}`+(Se===`copied`?` copied`:``)+(Se===`failed`?` copy-failed`:``),title:V.conversationId?`conversation ${V.conversationId} — click to copy`:`session ${V.sessionKey} (pre-flush, first turn pending) — click to copy`,onClick:async()=>{let e=V.conversationId??V.sessionKey;e&&(Ce(await L(e)?`copied`:`failed`),setTimeout(()=>Ce(null),1200))},children:[(0,W.jsx)(`span`,{className:`chat-session-chip-label`,children:Se===`copied`?`copied`:Se===`failed`?`copy failed`:V.conversationId?`conversation`:`session`}),(0,W.jsx)(`span`,{className:`chat-session-chip-id`,children:Se===`copied`?`✓`:Se===`failed`?`✕`:`${(V.conversationId??V.sessionKey??``).slice(0,8)}…`})]}),(0,W.jsxs)(`div`,{className:`chat-burger-wrap`,ref:xe,children:[(0,W.jsx)(`button`,{type:`button`,className:`chat-burger`,onClick:()=>d(e=>!e),"aria-label":`Menu`,"aria-haspopup":`true`,"aria-expanded":u,children:(0,W.jsx)(ce,{size:20})}),u&&(0,W.jsxs)(`div`,{className:`chat-menu`,children:[(0,W.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:async()=>{if(!F&&!(!he&&N)){ee(!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`);he?(B({surface:`browser`}),oe(`header-menu`)):P(!0)}catch(e){console.error(`[browser] Launch failed:`,e),alert(e instanceof Error?e.message:`Failed to launch browser`)}finally{ee(!1)}}},disabled:F,children:[(0,W.jsx)(D,{size:14}),` Browser`,F&&(0,W.jsx)(me,{size:12,className:`spin`})]}),(0,W.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{d(!1),he?(B({surface:`data`}),oe(`header-menu`)):window.location.href=`/data`},children:[(0,W.jsx)(ue,{size:14}),` Data`]}),(0,W.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{d(!1),he?(B({surface:`graph`}),oe(`header-menu`)):window.location.href=`/graph`},children:[(0,W.jsx)(pe,{size:14}),` Graph`]}),(0,W.jsx)(`div`,{className:`chat-menu-divider`}),(0,W.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,W.jsx)(Ne,{size:14}),` Public`,m&&(0,W.jsx)(me,{size:12,className:`spin`})]}),f!==null&&(0,W.jsxs)(`div`,{className:`chat-menu-agents`,children:[v&&(0,W.jsx)(`span`,{className:`chat-menu-agent-error`,children:v}),f.length===0&&!v&&(0,W.jsx)(`span`,{className:`chat-menu-agent-empty`,children:`No public agents configured`}),f.map(e=>(0,W.jsxs)(`div`,{className:`chat-menu-item chat-menu-agent-item`,children:[(0,W.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),(0,W.jsxs)(`span`,{className:`agent-text`,children:[(0,W.jsx)(`span`,{className:`agent-display-name`,children:e.displayName}),(0,W.jsxs)(`span`,{className:`agent-slug`,children:[`/`,e.slug]})]}),b===e.slug?(0,W.jsxs)(`span`,{className:`agent-actions agent-confirm`,children:[(0,W.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,W.jsx)(h,{size:12})}),(0,W.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-no`,title:`Cancel`,onClick:()=>x(null),children:(0,W.jsx)(ie,{size:12})})]}):(0,W.jsxs)(`span`,{className:`agent-actions`,children:[(0,W.jsx)(`a`,{href:`${c}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`agent-action-btn`,title:`Open agent`,onClick:()=>d(!1),children:(0,W.jsx)(Ne,{size:12})}),(0,W.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-delete-btn`,title:`Delete agent`,onClick:()=>x(e.slug),children:(0,W.jsx)(i,{size:12})})]})]},e.slug))]}),(0,W.jsx)(`div`,{className:`chat-menu-divider`}),E?.updateAvailable?(0,W.jsxs)(`button`,{type:`button`,className:`chat-menu-version`,onClick:()=>{E.latest&&(M(E),d(!1),A(!0))},children:[(0,W.jsx)(He,{size:14}),(0,W.jsxs)(`span`,{className:`version-installed`,children:[`v`,E.installed,(0,W.jsx)(`span`,{className:`version-update-dot`})]})]}):(0,W.jsxs)(`div`,{className:`chat-menu-version chat-menu-version-passive`,children:[(0,W.jsx)(He,{size:14}),(0,W.jsxs)(`span`,{className:`version-installed`,children:[E?`v${E.installed}`:`…`,E&&!E.updateAvailable&&(0,W.jsx)(`span`,{className:`version-uptodate-dot`})]})]}),(0,W.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{d(!1),V.handleLogout(),H.setMessages([])},children:[(0,W.jsx)(fe,{size:14}),` Log out`]})]})]})]}),(0,W.jsxs)(`div`,{className:`chat-content`,children:[(0,W.jsx)(KE,{messages:H.messages,isStreaming:H.isStreaming,elapsedSeconds:Te.elapsedSeconds,sessionTurnStart:Te.sessionTurnStart,expandAll:V.expandAll,setExpandAll:V.setExpandAll,conversationCompacted:H.conversationCompacted,isCompacting:H.isCompacting,setShowCompactConfirm:s,handleComponentSubmit:H.handleComponentSubmit,effectiveSubmitted:H.effectiveSubmitted,selectionMode:we.selectionMode,selectedItems:we.selectedItems,toggleSelectItem:we.toggleSelectItem,sessionKey:V.sessionKey,setLightboxSrc:n,messageQueue:H.messageQueue,messageQueueRef:H.messageQueueRef,setQueue:H.setQueue,sendMessage:H.sendMessage,appState:V.appState,onboardingComplete:V.onboardingComplete,onOpenArtefact:e=>{B({surface:`doc`,...e}),oe(`chat-link`)}}),(0,W.jsx)(qE,{offer:H.topicChangeOffer,onFreshStart:H.handleTopicFreshStart,onContinue:H.handleTopicContinue,disabled:H.isStreaming}),(0,W.jsx)(oD,{selectionMode:we.selectionMode,selectedItems:we.selectedItems,copyToast:we.copyToast||null,exitSelection:we.exitSelection,enterSelection:we.enterSelection,copySelected:we.copySelected,showCopyToast:we.showCopyToast,input:H.input,setInput:H.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:H.isStreaming,wasPaused:H.wasPaused,messages:H.messages,messageQueueRef:H.messageQueueRef,setQueue:H.setQueue,sendMessage:H.sendMessage,stopStreaming:H.stopStreaming,disconnecting:V.disconnecting,handleDisconnect:V.handleDisconnect,claudeInfo:V.claudeInfo,setClaudeInfo:V.setClaudeInfo,setShowClaudeInfo:a,conversationId:V.conversationId,sessionKey:V.sessionKey,onNewConversation:H.startNewConversation,newConversationDisabled:H.isStreaming||H.isCompacting,onOpenConversations:()=>{T(!0),De.refetch()},sidebarVisible:le})]}),we.copyToast&&(0,W.jsx)(`span`,{className:`copy-toast${we.copyToast===`failed`?` copy-toast-failed`:``}`,children:we.copyToast===`copied`?`Copied`:`Copy failed`}),(0,W.jsx)(QE,{show:w,onClose:()=>T(!1),conversationsLoading:De.loading,conversationsError:De.error,conversationsList:De.sessions,setConversationsList:De.setSessions,sessionKey:V.sessionKey,isStreaming:H.isStreaming,resetConversation:H.resetConversation,setMessages:H.setMessages,setConversationId:V.setConversationId}),(0,W.jsx)($E,{src:t,onClose:()=>n(null)}),(0,W.jsx)(eD,{show:o,onClose:()=>s(!1),onConfirm:H.handleCompactNow}),(0,W.jsx)(tD,{show:r,onClose:()=>{a(!1),V.setClaudeInfo(null)},claudeInfo:V.claudeInfo,messages:H.messages,sessionElapsed:Te.sessionElapsed,conversationId:V.conversationId}),(0,W.jsx)(iD,{show:k,onClose:()=>{A(!1),be.current=!0},versionInfo:j,sessionKey:V.sessionKey,onUpgradeComplete:()=>O(null)}),N&&(0,W.jsx)(uD,{onClose:()=>P(!1)})]}),(0,W.jsx)(DD,{}),(0,W.jsx)(SD,{}),(0,W.jsx)(_D,{selection:z,trigger:ae,sessionKey:V.sessionKey,onClose:()=>{B(null),oe(null)},onArtefactSaved:(e,t,n)=>{se.current?.patchArtefact(e,{updatedAt:t,content:n})},onSwapToGraph:(e,t)=>{B({surface:`graph`,focusNodeId:e,focusNodeLabel:t}),oe(`chat-link`)}})]})})}(0,ge.createRoot)(document.getElementById(`root`)).render((0,W.jsx)(kD,{}));
|
|
352
|
+
`)}var XE=`maxy-admin-session-key`,ZE=[{type:`stream`,label:`Stream`},{type:`error`,label:`Errors`},{type:`sse`,label:`SSE`}];function QE(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 $E(e){let{show:t,onClose:n,conversationsLoading:r,conversationsError:a,conversationsList:o,setConversationsList:s,sessionKey:l,setSessionKey:u,isStreaming:d,resetConversation:f,setMessages:p,setConversationId:m}=e,[g,v]=(0,U.useState)(null),[y,b]=(0,U.useState)(null),[x,S]=(0,U.useState)(``),[C,w]=(0,U.useState)(!1),T=(0,U.useRef)(null),[E,D]=(0,U.useState)(null),[O,k]=(0,U.useState)(null),[A,j]=(0,U.useState)(null),M=(0,U.useRef)(null),N=(0,U.useRef)(null),P=(0,U.useRef)(null);(0,U.useEffect)(()=>{t||(v(null),b(null),S(``),w(!1),D(null),k(null),j(null),M.current&&=(clearTimeout(M.current),null),N.current&&=(clearTimeout(N.current),null))},[t]),(0,U.useEffect)(()=>{if(!E)return;function e(e){let t=e.target;t&&P.current?.contains(t)||t&&t.closest?.(`.conversations-logs`)||D(null)}function t(e){e.key===`Escape`&&D(null)}return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[E]),(0,U.useEffect)(()=>{y?.phase===`editing`&&(T.current?.focus(),T.current?.select())},[y]);function F(){v(null),b(null),S(``),w(!1)}async function ee(e){if(l){F(),v(e),b({phase:`loading`});try{let t=await fetch(`/api/admin/sessions/${encodeURIComponent(e)}/label?session_key=${encodeURIComponent(l)}`,{method:`POST`});if(!t.ok){b({phase:`error`,reason:(await t.json().catch(()=>({}))).error||`Request failed`});return}let n=await t.json();n.label?(b({phase:`editing`}),S(n.label)):b({phase:`error`,reason:`Not enough message content to suggest a name`})}catch(e){console.error(`[admin-modal] label suggestion failed:`,e),b({phase:`error`,reason:e instanceof Error?e.message:String(e)})}}}async function I(e){if(!(!l||!x.trim()||C)){w(!0);try{let t=await fetch(`/api/admin/sessions/${encodeURIComponent(e)}/label`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({label:x.trim(),session_key:l})});if(!t.ok){b({phase:`error`,reason:(await t.json().catch(()=>({}))).error||`Rename failed`}),w(!1);return}s(t=>t.map(t=>t.conversationId===e?{...t,name:x.trim()}:t)),F()}catch(e){console.error(`[admin-modal] label rename failed:`,e),b({phase:`error`,reason:e instanceof Error?e.message:String(e)}),w(!1)}}}function te(e,t,n){if(E?.rowId===e){D(null);return}let r=n.getBoundingClientRect();D({rowId:e,conversationId:t.conversationId,sessionKey:t.sessionKey,top:r.bottom+4,right:Math.max(8,window.innerWidth-r.right)})}async function R(e){await L(e)?(k(e),j(null),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>k(null),1500)):(j(e),k(null),N.current&&clearTimeout(N.current),N.current=setTimeout(()=>j(null),1500))}return t?(0,W.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,W.jsxs)(`div`,{className:`claude-info-modal conversations-modal`,onClick:e=>e.stopPropagation(),children:[(0,W.jsxs)(`div`,{className:`claude-info-header`,children:[(0,W.jsx)(Je,{size:12}),`Conversations`,(0,W.jsx)(`button`,{className:`claude-info-close`,onClick:n,children:`✕`})]}),(0,W.jsxs)(`div`,{className:`conversations-list`,children:[r&&(0,W.jsxs)(`div`,{className:`conversations-empty`,children:[(0,W.jsx)(me,{size:14,className:`spin`}),` Loading…`]}),a&&(0,W.jsx)(`div`,{className:`conversations-empty conversations-error`,children:a}),!r&&!a&&o.length===0&&(0,W.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&&g===e.conversationId,o=a&&y?.phase===`loading`,v=a&&y?.phase===`editing`,b=a&&y?.phase===`error`,w=e.conversationId??e.sessionKey??``;return(0,W.jsxs)(`div`,{className:`conversations-row${r?` conversations-row-pre-flush`:``}`,children:[(0,W.jsxs)(`div`,{className:`conversations-row-info`,children:[o&&(0,W.jsxs)(`span`,{className:`conversations-row-name conversations-edit-loading`,children:[(0,W.jsx)(me,{size:12,className:`spin`}),` Generating suggestion…`]}),v&&(0,W.jsxs)(`div`,{className:`conversations-edit-inline`,children:[(0,W.jsx)(`input`,{ref:T,type:`text`,className:`conversations-edit-input`,value:x,onChange:e=>S(e.target.value),onKeyDown:t=>{t.key===`Enter`&&x.trim()&&I(e.conversationId),t.key===`Escape`&&F()},maxLength:200}),(0,W.jsx)(`button`,{type:`button`,className:`conversations-action conversations-confirm`,title:`Confirm rename`,disabled:!x.trim()||C,onClick:()=>I(e.conversationId),children:C?(0,W.jsx)(me,{size:13,className:`spin`}):(0,W.jsx)(h,{size:13})}),(0,W.jsx)(`button`,{type:`button`,className:`conversations-action conversations-cancel`,title:`Cancel`,onClick:F,children:(0,W.jsx)(ie,{size:13})})]}),b&&(0,W.jsxs)(`div`,{className:`conversations-edit-inline`,children:[(0,W.jsx)(`span`,{className:`conversations-edit-error`,children:y.reason}),(0,W.jsx)(`button`,{type:`button`,className:`conversations-action conversations-retry`,title:`Retry`,onClick:()=>ee(e.conversationId),children:(0,W.jsx)(re,{size:13})}),(0,W.jsx)(`button`,{type:`button`,className:`conversations-action conversations-cancel`,title:`Cancel`,onClick:F,children:(0,W.jsx)(ie,{size:13})})]}),!a&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`span`,{className:`conversations-row-name`,children:[e.name||(r?`session ${w}`:w),r&&(0,W.jsx)(`span`,{className:`conversations-row-phase-badge`,title:`Pre-flush — conversation not yet persisted`,children:`pre-flush`})]}),(0,W.jsxs)(`span`,{className:`conversations-row-meta`,children:[(0,W.jsx)(`button`,{type:`button`,className:`conversations-row-id${O===t?` copied`:``}${A===t?` copy-failed`:``}`,title:w,"aria-label":r?`Copy session key ${w}`:`Copy conversation id ${w}`,onClick:e=>{e.stopPropagation(),R(t)},children:O===t?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(h,{size:10}),` copied`]}):A===t?`copy failed`:w.slice(0,8)}),(0,W.jsxs)(`span`,{className:`conversations-row-time`,children:[(0,W.jsx)(H,{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,W.jsx)(`div`,{className:`conversations-row-actions`,children:!a&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`button`,{type:`button`,className:`conversations-action conversations-logs`,title:r?`View pre-flush logs`:`View logs`,"aria-haspopup":`menu`,"aria-expanded":E?.rowId===t,onClick:n=>{n.stopPropagation(),te(t,{conversationId:e.conversationId,sessionKey:e.sessionKey},n.currentTarget)},children:(0,W.jsx)(c,{size:13})}),r&&e.sessionKey&&e.sessionKey!==l&&(0,W.jsx)(`button`,{type:`button`,className:`conversations-action conversations-play`,title:`Switch into this in-memory session`,disabled:d||!l,onClick:()=>{if(d||!l||!e.sessionKey)return;let t=e.sessionKey;n(),f(),p([]),fetch(`/api/admin/sessions/switch?session_key=${encodeURIComponent(l)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({target_session_key:t})}).then(e=>e.ok?e.json():Promise.reject(Error(`switch returned ${e.status}`))).then(e=>{try{sessionStorage.setItem(XE,e.session_key)}catch{}de(e.session_key,`chat`),u(e.session_key),m(e.conversationId)}).catch(e=>{console.error(`[chat] pre-flush session switch failed:`,e),p([{role:`maxy`,events:[{type:`text`,content:`Could not switch into that session.`}],timestamp:Date.now()-1,historical:!0}])})},children:(0,W.jsx)(_,{size:13})}),!r&&e.conversationId&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`button`,{type:`button`,className:`conversations-action conversations-rename`,title:`Rename conversation`,onClick:()=>ee(e.conversationId),children:(0,W.jsx)(ot,{size:13})}),(0,W.jsx)(`button`,{type:`button`,className:`conversations-action conversations-play`,title:`Resume conversation`,disabled:d,onClick:()=>{d||!l||(n(),f(),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&&m(e.conversationId);let t=(e.messages??[]).map(e=>({role:e.role===`user`?`admin`:`maxy`,content:e.role===`user`?e.content:void 0,events:e.role===`assistant`?e.events??(e.content?[{type:`text`,content:e.content}]:[]):void 0,...e.role===`user`&&e.attachments&&e.attachments.length>0?{attachments:e.attachments}:{},timestamp:new Date(e.createdAt).getTime()||0,historical:!0,...e.messageId?{messageId:e.messageId}:{}}));t.length>0&&p(t)}).catch(e=>{console.error(`[chat] conversation resume failed:`,e),p([{role:`maxy`,events:[{type:`text`,content:`Could not load conversation history.`}],timestamp:Date.now()-1,historical:!0}])}))},children:(0,W.jsx)(_,{size:13})}),(0,W.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,W.jsx)(i,{size:13})})]})]})})]},t)})]}),E&&(0,W.jsx)(`div`,{ref:P,className:`conversations-logs-popover`,role:`menu`,style:{top:E.top,right:E.right},children:ZE.map(({type:e,label:t})=>(0,W.jsxs)(`a`,{role:`menuitem`,className:`conversations-logs-popover-item`,href:QE({conversationId:E.conversationId,sessionKey:E.sessionKey},e),target:`_blank`,rel:`noopener noreferrer`,onClick:()=>{console.debug(`[admin-modal] open-log`,{conversationId:E.conversationId,sessionKey:E.sessionKey,type:e}),D(null)},children:[(0,W.jsx)(c,{size:12}),(0,W.jsx)(`span`,{children:t})]},e))})]})}):null}function eD({src:e,onClose:t}){return e?(0,W.jsxs)(`div`,{className:`attachment-lightbox`,onClick:t,children:[(0,W.jsx)(`button`,{className:`attachment-lightbox-close`,onClick:t,"aria-label":`Close`,children:`×`}),(0,W.jsx)(`img`,{src:e,alt:`Attachment`,onClick:e=>e.stopPropagation()})]}):null}function tD({show:e,onClose:t,onConfirm:n}){return e?(0,W.jsx)(`div`,{className:`claude-info-overlay`,onClick:t,children:(0,W.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,W.jsxs)(`div`,{className:`claude-info-header`,children:[(0,W.jsx)(`span`,{children:`Compact conversation?`}),(0,W.jsx)(`button`,{className:`claude-info-close`,onClick:t,"aria-label":`Close`,children:`✕`})]}),(0,W.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,W.jsxs)(`div`,{className:`claude-info-section`,style:{display:`flex`,gap:`8px`,padding:`10px 14px`},children:[(0,W.jsx)(w,{variant:`secondary`,size:`sm`,style:{background:`var(--accent)`,flex:1},onClick:()=>{t(),n()},children:`Yes, compact`}),(0,W.jsx)(w,{variant:`secondary`,size:`sm`,style:{flex:1},onClick:t,children:`No`})]})]})}):null}function nD(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,W.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,W.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,W.jsxs)(`div`,{className:`claude-info-header`,children:[(0,W.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`claude-info-icon`}),(0,W.jsx)(`span`,{children:`Claude Code`}),(0,W.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,W.jsxs)(`div`,{className:`claude-info-section`,children:[(0,W.jsxs)(`div`,{className:`claude-info-row`,children:[(0,W.jsx)(`span`,{className:`claude-info-label`,children:`Version`}),(0,W.jsx)(`span`,{className:`claude-info-value`,children:r?r.version:`…`})]}),(0,W.jsxs)(`div`,{className:`claude-info-row`,children:[(0,W.jsx)(`span`,{className:`claude-info-label`,children:`Email`}),(0,W.jsx)(`span`,{className:`claude-info-value`,children:r?.account?.email??`…`})]})]}),(p||d||f>0)&&(0,W.jsxs)(`div`,{className:`claude-info-section`,children:[p&&(0,W.jsxs)(`div`,{className:`claude-info-row`,children:[(0,W.jsx)(`span`,{className:`claude-info-label`,children:`Plan`}),(0,W.jsx)(`span`,{className:`claude-info-value`,style:{textTransform:`capitalize`},children:p})]}),d&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{className:`claude-info-row`,children:[(0,W.jsx)(`span`,{className:`claude-info-label`,children:`Usage`}),(0,W.jsxs)(`span`,{className:`claude-info-value`,children:[Math.round(d.utilization*100),`%`]})]}),(0,W.jsxs)(`div`,{className:`claude-info-row`,children:[(0,W.jsx)(`span`,{className:`claude-info-label`,children:`Resets in`}),(0,W.jsx)(`span`,{className:`claude-info-value`,children:m(d.resetsAt)})]}),d.isUsingOverage&&(0,W.jsxs)(`div`,{className:`claude-info-row`,children:[(0,W.jsx)(`span`,{className:`claude-info-label`,children:`Overage`}),(0,W.jsx)(`span`,{className:`claude-info-value`,children:`Active`})]})]}),f>0&&(0,W.jsxs)(`div`,{className:`claude-info-row`,children:[(0,W.jsx)(`span`,{className:`claude-info-label`,children:`Session cost`}),(0,W.jsxs)(`span`,{className:`claude-info-value`,children:[`$`,f<.01?f.toFixed(4):f.toFixed(2)]})]})]}),(0,W.jsxs)(`div`,{className:`claude-info-section`,children:[(0,W.jsxs)(`div`,{className:`claude-info-row`,children:[(0,W.jsx)(`span`,{className:`claude-info-label`,children:`Model`}),(0,W.jsx)(`span`,{className:`claude-info-value`,children:r?.model??`…`})]}),(0,W.jsxs)(`div`,{className:`claude-info-row`,children:[(0,W.jsx)(`span`,{className:`claude-info-label`,children:`Context used`}),(0,W.jsx)(`span`,{className:`claude-info-value`,children:l>0?`${l}%`:`—`})]}),(0,W.jsxs)(`div`,{className:`claude-info-row`,children:[(0,W.jsx)(`span`,{className:`claude-info-label`,children:`Tokens`}),(0,W.jsx)(`span`,{className:`claude-info-value`,children:u>0?bt(u):`—`})]}),(0,W.jsxs)(`div`,{className:`claude-info-row`,children:[(0,W.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,W.jsx)(`span`,{className:`claude-info-value`,children:yt(a)})]}),o&&(0,W.jsxs)(`div`,{className:`claude-info-row`,children:[(0,W.jsx)(`span`,{className:`claude-info-label`,children:`Conversation`}),(0,W.jsx)(`span`,{className:`claude-info-value`,style:{fontFamily:`monospace`,fontSize:10},children:o.slice(0,8)})]})]})]})})}var rD=5e3,iD={atPhase:8};function aD({show:e,onClose:t,versionInfo:n,sessionKey:r,onUpgradeComplete:i}){let[a,o]=(0,U.useState)(`prompt`),[s,c]=(0,U.useState)(``),[l,u]=(0,U.useState)(!1),[d,f]=(0,U.useState)(null),[p,m]=(0,U.useState)(null),[h,g]=(0,U.useState)(null),_=(0,U.useRef)(null),v=n?.latest??null,y=(0,U.useCallback)(()=>{_.current&&=(clearInterval(_.current),null)},[]);(0,U.useEffect)(()=>{e||(y(),o(`prompt`),c(``),u(!1),f(null),m(null),g(null))},[e,y]),(0,U.useEffect)(()=>y,[y]),(0,U.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{}},rD),y},[e,a,v,i,y]);let b=(0,U.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,W.jsx)(`div`,{className:`claude-info-overlay`,onClick:()=>{(a===`prompt`||a===`succeeded`||a===`launch-failed`)&&t()},children:(0,W.jsxs)(`div`,{className:`claude-info-modal update-modal`,onClick:e=>e.stopPropagation(),children:[(0,W.jsxs)(`div`,{className:`claude-info-header`,children:[(0,W.jsx)(B,{size:12}),`Software Update`,(0,W.jsx)(`button`,{className:`claude-info-close`,onClick:t,children:`✕`})]}),(0,W.jsxs)(`div`,{className:`update-modal-body`,children:[(0,W.jsxs)(`div`,{className:`update-modal-versions`,children:[(0,W.jsxs)(`div`,{className:`claude-info-row`,children:[(0,W.jsx)(`span`,{className:`claude-info-label`,children:`Installed`}),(0,W.jsxs)(`span`,{className:`claude-info-value`,children:[`v`,n?.installed??`…`]})]}),(0,W.jsxs)(`div`,{className:`claude-info-row`,children:[(0,W.jsx)(`span`,{className:`claude-info-label`,children:`Available`}),(0,W.jsxs)(`span`,{className:`claude-info-value update-version-new`,children:[`v`,v??`…`]})]})]}),(a===`prompt`||a===`priming`||a===`launch-failed`)&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{className:`form-input__field`,style:{marginTop:12},children:[(0,W.jsx)(`label`,{className:`form-input__label`,htmlFor:`upgrade-sudo`,children:`Device password`}),(0,W.jsxs)(`div`,{className:`tunnel-route__row`,children:[(0,W.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,W.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,W.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,W.jsx)(`div`,{className:`tunnel-route__error`,children:d}),p&&(0,W.jsx)(`div`,{className:`tunnel-route__error`,role:`alert`,children:p})]}),(0,W.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,W.jsx)(`div`,{className:`update-modal-terminal`,style:{height:360,marginTop:10},children:(0,W.jsx)(vE,{actionId:h,sessionKey:r,selfRestart:iD})}),a===`succeeded`&&(0,W.jsxs)(`div`,{className:`update-modal-result`,children:[(0,W.jsx)(Te,{size:14,className:`update-success-icon`}),(0,W.jsxs)(`span`,{children:[`Upgraded to v`,v,` — reloading…`]})]})]})]})}):null}function oD(e){let{conversationId:t,sessionKey:n,disconnecting:r,onOpenConversations:i,handleDisconnect:a,onAfterAction:o}=e,s=!t&&!n;return(0,W.jsxs)(`div`,{className:`chat-actions-menu`,children:[(0,W.jsxs)(`button`,{type:`button`,className:`chat-action`,onClick:()=>{o(),i()},children:[(0,W.jsx)(Je,{size:14}),(0,W.jsx)(`span`,{className:`action-label`,children:`Conversations`})]}),(0,W.jsxs)(`button`,{type:`button`,className:`chat-action`,disabled:r,onClick:async()=>{o(),await a()},children:[r?(0,W.jsx)(me,{size:14,className:`animate-spin`}):(0,W.jsx)(be,{size:14}),(0,W.jsx)(`span`,{className:`action-label`,children:r?`Disconnecting...`:`Disconnect Claude`})]}),(0,W.jsxs)(`button`,{type:`button`,className:`chat-action`,disabled:s,title:t?`Download stream log`:n?`Download stream log (pre-flush)`:`No session active — reload the page to start one`,onClick:()=>{if(o(),s){console.debug(`[stream-log-button] no-identity sessionKey=null conversationId=null`);return}let e=document.createElement(`a`);e.href=`${QE({conversationId:t,sessionKey:n},`stream`)}&download=1`,e.click()},children:[(0,W.jsx)(ct,{size:14}),(0,W.jsx)(`span`,{className:`action-label`,children:`Stream log`})]})]})}function sD(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:ee,setQueue:I,sendMessage:R,stopStreaming:ne,disconnecting:re,handleDisconnect:ie,claudeInfo:z,setClaudeInfo:B,setShowClaudeInfo:ae,conversationId:oe,sessionKey:se,onNewConversation:ce,newConversationDisabled:le,onOpenConversations:ue,sidebarVisible:de}=e,[fe,pe]=(0,U.useState)(!1),me=(0,U.useRef)(null),[he,ge]=(0,U.useState)(!1),_e=(0,U.useRef)(null),ve=(0,U.useRef)(!1),ye=F(),be=ye.state===`recording`||ye.state===`paused`||ye.state===`sending`,xe=!be&&!M&&!l.trim()&&g.length===0;async function Se(){let e=await ye.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){I([...ee.current,{text:`[Voice note]`,files:[n],timestamp:Date.now()}]);return}R(`[Voice note]`,[n])}return(0,U.useEffect)(()=>{t||ge(!1)},[t]),(0,U.useEffect)(()=>{if(!he)return;let e=e=>{e.target.closest(`.selection-copy-wrap`)||ge(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[he]),(0,U.useEffect)(()=>{if(!fe)return;let e=e=>{if(e.key===`Escape`){pe(!1);return}if(e.key===`Tab`&&me.current){let t=me.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=>{me.current&&!me.current.contains(e.target)&&pe(!1)};return document.addEventListener(`keydown`,e),document.addEventListener(`mousedown`,t),()=>{document.removeEventListener(`keydown`,e),document.removeEventListener(`mousedown`,t)}},[fe]),t?(0,W.jsx)(`div`,{className:`chat-input-area`,children:(0,W.jsxs)(`div`,{className:`selection-bar`,children:[(0,W.jsxs)(`span`,{className:`selection-count`,children:[n.size,` Selected`]}),(0,W.jsxs)(`div`,{className:`selection-copy-wrap`,children:[(0,W.jsxs)(`button`,{type:`button`,className:`selection-copy`,onPointerDown:()=>{if(he){ge(!1);return}ve.current=!1,_e.current=setTimeout(()=>{ve.current=!0,ge(!0),_e.current=null},500)},onPointerUp:()=>{_e.current!==null&&(clearTimeout(_e.current),_e.current=null)},onPointerLeave:()=>{_e.current!==null&&(clearTimeout(_e.current),_e.current=null)},onPointerCancel:()=>{_e.current!==null&&(clearTimeout(_e.current),_e.current=null)},onClick:async()=>{ve.current||await o(e=>JE(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,W.jsx)(f,{size:18}),(0,W.jsx)(`span`,{children:`Copy`})]}),he&&(0,W.jsx)(`div`,{className:`copy-menu`,children:[[`all`,`All events`],[`text`,`Text messages only`],[`non-text`,`Non-text only`]].map(([e,t])=>(0,W.jsx)(`button`,{type:`button`,className:`copy-menu-item`,onClick:async()=>{let t=YE(P,e);t&&s(await L(t)),i()},children:t},e))})]}),(0,W.jsx)(`button`,{type:`button`,className:`selection-cancel`,onClick:i,children:`Cancel`})]})}):(0,W.jsxs)(`div`,{className:`chat-input-area`,children:[(0,W.jsx)(`input`,{ref:x,type:`file`,multiple:!0,accept:St,style:{display:`none`},onChange:e=>{e.target.files&&S([...e.target.files]),e.target.value=``}}),g.length>0&&(0,W.jsx)(`div`,{className:`attachment-strip`,children:g.map((e,t)=>(0,W.jsxs)(`div`,{className:`attachment-chip`,children:[e.type.startsWith(`image/`)?(0,W.jsx)(`img`,{src:URL.createObjectURL(e),alt:e.name,className:`attachment-chip-thumb`}):e.type===`application/pdf`?(0,W.jsx)(c,{size:14}):(0,W.jsx)(E,{size:14}),(0,W.jsx)(`span`,{className:`attachment-chip-name`,children:e.name}),(0,W.jsx)(`button`,{type:`button`,className:`attachment-chip-remove`,onClick:()=>C(t),"aria-label":`Remove ${e.name}`,children:`×`})]},t))}),b&&(0,W.jsx)(`p`,{className:`attach-error`,children:b}),ye.state===`error`&&ye.errorMessage&&(0,W.jsxs)(`p`,{className:`voice-error`,role:`alert`,children:[(0,W.jsx)(m,{size:14}),ye.errorMessage]}),(0,W.jsx)(T,{inputRef:h}),be?(0,W.jsx)(`div`,{className:`chat-form voice-active`,children:(0,W.jsx)(A,{state:ye.state,elapsedSeconds:ye.elapsedSeconds,waveform:ye.waveform,onTogglePause:ye.togglePause,onDiscard:ye.discard,onSend:Se})}):(0,W.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){I([...ee.current,{text:t,files:[...g],timestamp:Date.now()}]),p(``),v([]),h.current?.resetHeight();return}R(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,W.jsx)(w,{variant:`icon`,type:`button`,onClick:()=>x.current?.click(),"aria-label":`Attach file`,children:(0,W.jsx)(u,{size:14})}),(0,W.jsx)(N,{ref:h,value:l,onChange:p}),j?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(w,{variant:`send`,type:`button`,onClick:()=>ne(!0),"aria-label":`Pause`,style:{background:`var(--text-secondary)`},children:(0,W.jsx)(d,{size:14})}),(0,W.jsx)(w,{variant:`send`,type:`button`,onClick:()=>ne(!1),"aria-label":`Stop`,style:{background:`var(--danger)`},children:(0,W.jsx)(dt,{size:14})})]}):xe?(0,W.jsx)(w,{variant:`send`,type:`button`,onClick:ye.start,"aria-label":`Record voice note`,children:(0,W.jsx)(m,{size:14})}):(0,W.jsx)(w,{variant:`send`,type:`submit`,disabled:!l.trim()&&g.length===0&&!M,"aria-label":`Send message`,children:M?(0,W.jsx)(_,{size:14}):(0,W.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,W.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,W.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,W.jsxs)(`div`,{className:`chat-actions`,ref:me,children:[(0,W.jsx)(`button`,{type:`button`,className:`chat-action-icon`,title:`New conversation`,"aria-label":`New conversation`,disabled:le,onClick:ce,children:(0,W.jsx)(ze,{size:16})}),(0,W.jsx)(`button`,{type:`button`,className:`chat-action-icon`,title:`Select messages`,"aria-label":`Select messages`,onClick:a,children:(0,W.jsx)(te,{size:16})}),!de&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`button`,{className:`burger-trigger`,onClick:()=>pe(e=>!e),"aria-expanded":fe,"aria-haspopup":`true`,"aria-label":`Conversation actions`,children:(0,W.jsx)(Me,{size:16})}),(0,W.jsx)(`div`,{className:`actions-menu-items${fe?` actions-menu-open`:``}`,children:(0,W.jsx)(oD,{conversationId:oe,sessionKey:se,disconnecting:re,onOpenConversations:ue,handleDisconnect:ie,onAfterAction:()=>pe(!1)})})]}),(0,W.jsxs)(`div`,{className:`powered-by`,onClick:async()=>{if(ae(!0),!z){let e=await fetch(`/api/admin/claude-info`);e.ok&&B(await e.json())}},children:[(0,W.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`powered-by-icon`}),(0,W.jsx)(`span`,{children:`Powered by Claude Code`})]})]})]})}var cD=`maxy-vnc-overlay-popout`;function lD(e){let[t,n]=(0,U.useState)(!1),r=(0,U.useRef)(null),i=(0,U.useRef)(null),a=(0,U.useCallback)(()=>{i.current&&=(clearInterval(i.current),null),r.current&&!r.current.closed&&r.current.close(),r.current=null,n(!1)},[]),o=(0,U.useCallback)(()=>{let t=`/vnc-popout.html?title=${encodeURIComponent(C.productName)}`,o=window.open(t,cD,`width=1024,height=768`);o&&(r.current=o,n(!0),i.current=setInterval(()=>{r.current?.closed&&(a(),e?.())},500))},[a,e]);return(0,U.useEffect)(()=>()=>a(),[a]),{poppedOut:t,popout:o,cleanupPopout:a}}var uD=(0,U.forwardRef)(function({onClose:e},t){vt();let{poppedOut:n,popout:r,cleanupPopout:i}=lD(e);return(0,U.useImperativeHandle)(t,()=>({popout:r}),[r]),n?(0,W.jsxs)(`div`,{className:`browser-overlay-popout`,children:[(0,W.jsx)(D,{className:`browser-viewer__icon`}),(0,W.jsx)(`span`,{className:`browser-viewer__title`,children:C.productName}),(0,W.jsx)(`span`,{className:`browser-viewer__popout-label`,children:`Popped out`}),(0,W.jsx)(w,{variant:`ghost`,size:`sm`,icon:tt,onClick:()=>i(),"aria-label":`Pop back in`}),e&&(0,W.jsx)(w,{variant:`ghost`,size:`sm`,icon:ie,onClick:()=>{i(),e()},"aria-label":`Close`})]}):(0,W.jsx)(`iframe`,{src:`/vnc-viewer.html`,className:`browser-surface__iframe`,title:C.productName})});function dD({onClose:e}){vt();let{poppedOut:t,popout:n,cleanupPopout:r}=lD(e),i=(0,U.useCallback)(()=>{r(),e()},[r,e]);(0,U.useEffect)(()=>{if(t)return;let e=e=>{e.key===`Escape`&&i()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,i]);let a=nn({handlePopout:n,disabled:t});return t?(0,W.jsxs)(`div`,{className:`browser-overlay-popout`,children:[(0,W.jsx)(D,{className:`browser-viewer__icon`}),(0,W.jsx)(`span`,{className:`browser-viewer__title`,children:C.productName}),(0,W.jsx)(`span`,{className:`browser-viewer__popout-label`,children:`Popped out`}),(0,W.jsx)(w,{variant:`ghost`,size:`sm`,icon:tt,onClick:()=>{r()},"aria-label":`Pop back in`}),(0,W.jsx)(w,{variant:`ghost`,size:`sm`,icon:ie,onClick:i,"aria-label":`Close`})]}):(0,W.jsxs)(`div`,{className:`browser-viewer-fullscreen`,children:[(0,W.jsxs)(`div`,{className:`browser-viewer-fullscreen__bar`,...a,children:[(0,W.jsx)(D,{className:`browser-viewer__icon`}),(0,W.jsx)(`span`,{className:`browser-viewer-fullscreen__title`,children:C.productName}),(0,W.jsxs)(`div`,{className:`browser-viewer-fullscreen__actions`,children:[(0,W.jsx)(w,{variant:`ghost`,size:`sm`,icon:Ne,onClick:n,"aria-label":`Pop out`}),(0,W.jsx)(w,{variant:`ghost`,size:`sm`,icon:ie,onClick:i,"aria-label":`Close`})]})]}),(0,W.jsx)(`iframe`,{src:`/vnc-viewer.html`,className:`browser-viewer-fullscreen__iframe`,title:C.productName})]})}var fD=(0,U.forwardRef)(function(e,t){let{businessName:n,sessionKey:r,conversationId:i,role:a,userName:o,userAvatar:s,sessions:l,sessionsLoading:u,sessionsError:d,ensureSessionsLoaded:f,refetchSessions:p,onSelectSession:m,onSelectArtefact:h,onSelectProjects:g,onSelectPeople:_,onSelectTasks:v,onSelectAgents:y,onCloseMobileDrawer:b,collapsed:x,onToggleCollapsed:S,actions:w}=e;(0,U.useEffect)(()=>{f()},[f]);let T=C.productName,E=typeof o==`string`?o:o===null?`name unavailable`:n||T,D=(E.trim().charAt(0)||`?`).toUpperCase(),[O,k]=(0,U.useState)(`all`),A=(0,U.useMemo)(()=>l.filter(e=>e.name).filter(e=>O===`all`?!0:(e.channel??`webchat`)===O),[l,O]),j=A.length,M=i??r,[N,P]=(0,U.useState)(`chat`),[F,ee]=(0,U.useState)([]),[I,te]=(0,U.useState)(!1),[L,R]=(0,U.useState)(null),[re,ie]=(0,U.useState)(!1);(0,U.useImperativeHandle)(t,()=>({patchArtefact(e,t){ee(n=>n.map(n=>n.id===e?{...n,...t}:n))}}),[]);let[z,B]=(0,U.useState)(!1),ae=(0,U.useRef)(null);(0,U.useEffect)(()=>{if(!z)return;function e(e){ae.current&&!ae.current.contains(e.target)&&B(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[z]);let oe=(0,U.useCallback)(async()=>{if(r){ie(!0),R(null);try{let e=await fetch(`/api/admin/sidebar-artefacts?session_key=${encodeURIComponent(r)}`);if(!e.ok)throw Error(`status ${e.status}`);ee((await e.json()).artefacts??[]),te(!0)}catch(e){let t=e instanceof Error?e.message:String(e);R(`Failed to load artefacts: ${t}`),console.error(`[admin-ui] sidebar-artefacts fetch failed: ${t}`)}finally{ie(!1)}}},[r]),se=()=>{P(`chat`),console.info(`[admin-ui] sidebar-nav surface=chat count=${j}`)},ce=()=>{P(`artefacts`),console.info(`[admin-ui] sidebar-nav surface=artefacts count=${I?F.length:0}`),I||oe()},le=x?24:16,ue=N===`chat`?`Recents`:`Artefacts`,de=N===`chat`?u?`…`:String(j):re?`…`:String(F.length),fe=N===`chat`?u:re,pe=()=>{N===`chat`?p():oe(),console.info(`[admin-ui] sidebar-refresh surface=${N}`)};return(0,W.jsxs)(`aside`,{className:`side`,children:[(0,W.jsx)(`div`,{className:`side-head`,children:(0,W.jsx)(`button`,{className:`icon-btn side-head-toggle`,title:x?`Expand sidebar`:`Collapse sidebar`,type:`button`,"aria-label":x?`Expand sidebar`:`Collapse sidebar`,onClick:S,children:x?(0,W.jsx)(at,{size:28}):(0,W.jsx)(it,{size:28})})}),(0,W.jsxs)(`nav`,{className:`side-nav`,children:[(0,W.jsxs)(`button`,{type:`button`,className:`nav-row${N===`chat`?` active`:``}`,onClick:se,children:[(0,W.jsx)(et,{size:le}),(0,W.jsx)(`span`,{className:`label`,children:`Chat`}),(0,W.jsx)(`span`,{className:`kbd`})]}),(0,W.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=people`),_(),b()},children:[(0,W.jsx)(ht,{size:le}),(0,W.jsx)(`span`,{className:`label`,children:`People`}),(0,W.jsx)(`span`,{className:`kbd`})]}),(0,W.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=agents`),y(),b()},children:[(0,W.jsx)(xe,{size:le}),(0,W.jsx)(`span`,{className:`label`,children:`Agents`}),(0,W.jsx)(`span`,{className:`kbd`})]}),(0,W.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=projects`),g(),b()},children:[(0,W.jsx)(Se,{size:le}),(0,W.jsx)(`span`,{className:`label`,children:`Projects`}),(0,W.jsx)(`span`,{className:`kbd`})]}),(0,W.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=tasks`),v(),b()},children:[(0,W.jsx)(qe,{size:le}),(0,W.jsx)(`span`,{className:`label`,children:`Tasks`}),(0,W.jsx)(`span`,{className:`kbd`})]}),(0,W.jsxs)(`button`,{type:`button`,className:`nav-row${N===`artefacts`?` active`:``}`,onClick:ce,children:[(0,W.jsx)(c,{size:le}),(0,W.jsx)(`span`,{className:`label`,children:`Artefacts`}),(0,W.jsx)(`span`,{className:`kbd`})]})]}),(0,W.jsxs)(`div`,{className:`side-list`,children:[(0,W.jsxs)(`div`,{className:`group-head`,children:[(0,W.jsx)(`span`,{children:ue}),(0,W.jsxs)(`span`,{className:`group-head-meta`,children:[(0,W.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh ${ue.toLowerCase()}`,"aria-label":`Refresh ${ue.toLowerCase()}`,onClick:pe,disabled:fe,children:(0,W.jsx)(ne,{size:12,className:fe?`spinning`:void 0})}),(0,W.jsx)(`span`,{children:de})]})]}),N===`chat`&&(0,W.jsxs)(W.Fragment,{children:[d&&(0,W.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:d}),(0,W.jsxs)(Qt,{className:`conv-channel-filter`,value:O,onChange:e=>{let t=e.target.value;k(t),console.info(`[admin-ui] sidebar-channel-filter set value=${t}`)},"aria-label":`Filter conversations by channel`,children:[(0,W.jsx)(`option`,{value:`all`,children:`All channels`}),(0,W.jsx)(`option`,{value:`webchat`,children:`Web`})]}),A.map(e=>{let t=e.conversationId??e.sessionKey,n=t!==null&&t===M,r=e.channel??`webchat`;return(0,W.jsxs)(`button`,{type:`button`,className:`conv${n?` active`:``}`,onClick:()=>{let t=e.sessionKey?e.sessionKey.slice(0,8):`null`,n=e.conversationId?e.conversationId.slice(0,8):`null`;console.info(`[admin-session-identity] sessionKey=${t} conversationId=${n} phase=${e.phase} surface=sidebar-recents`),m(e),b()},children:[r===`whatsapp`&&(0,W.jsx)(Ze,{size:12,className:`conv-channel-icon`,"aria-label":`WhatsApp`}),(0,W.jsx)(`span`,{className:`conv-name`,children:e.name??`(untitled)`})]},t??e.updatedAt)})]}),N===`artefacts`&&(0,W.jsxs)(W.Fragment,{children:[L&&(0,W.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:L}),I&&!L&&F.length===0&&(0,W.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No artefacts yet`}),F.map(e=>(0,W.jsxs)(`button`,{type:`button`,className:`conv`,onClick:()=>{h({docId:e.id,name:e.name,content:e.content,editable:e.editable,mimeType:e.mimeType,skipReason:e.skipReason},`sidebar-artefacts`),b()},children:[(0,W.jsx)(`span`,{className:`conv-name`,children:e.name}),(0,W.jsx)(`span`,{className:`conv-kind`,"data-kind":e.kind===`agent-template`?`agent`:`doc`,children:e.kind===`agent-template`?`agent`:`doc`})]},e.id))]})]}),(0,W.jsxs)(`div`,{className:`side-foot`,ref:ae,children:[(0,W.jsx)(`div`,{className:`avatar`,children:s?(0,W.jsx)(`img`,{src:s,alt:E}):D}),(0,W.jsxs)(`div`,{className:`who`,children:[(0,W.jsx)(`span`,{className:`name`,children:E}),(0,W.jsx)(`span`,{className:`role`,children:a??`operator`})]}),(0,W.jsx)(`button`,{className:`icon-btn side-foot-actions-trigger`,title:`Conversation actions`,type:`button`,"aria-label":`Conversation actions`,"aria-haspopup":`true`,"aria-expanded":z,onClick:()=>B(e=>!e),children:(0,W.jsx)(Me,{size:le})}),z&&(0,W.jsx)(`div`,{className:`side-foot-actions-popover`,children:(0,W.jsx)(oD,{...w,onAfterAction:()=>B(!1)})})]})]})}),pD=()=>{},mD={"null-attachmentId":`No file backing this artefact.`,"non-text-mime":`Content type cannot be displayed inline.`,"containment-rejected":`File path failed containment check; cannot display.`,"missing-on-disk":`File is missing on disk.`};function hD({reason:e}){return(0,W.jsxs)(`div`,{className:`art-skip-banner`,role:`status`,children:[(0,W.jsx)(Ie,{size:14}),(0,W.jsx)(`span`,{children:mD[e]})]})}function gD({src:e,name:t,docId:n}){let[r,i]=(0,U.useState)(!1),a=(0,U.useRef)(null),o=(0,U.useRef)(!1),s=(0,U.useRef)(!1),l=(0,U.useCallback)(e=>{s.current||(s.current=!0,console.info(`[admin-ui] artefact-pdf-fallback id=${n.slice(0,8)} reason=${e}`),i(!0))},[n]);(0,U.useEffect)(()=>{let e=setTimeout(()=>{o.current||l(`onload-timeout`)},3e3);return()=>clearTimeout(e)},[l]);let u=()=>{o.current=!0;try{let e=a.current?.contentDocument?.body;e&&e.children.length===0&&!e.textContent?.trim()&&l(`empty-body`)}catch{}};return r?(0,W.jsxs)(`a`,{className:`art-pdf-fallback`,href:e,download:t,children:[(0,W.jsx)(c,{size:20}),(0,W.jsxs)(`div`,{className:`art-pdf-fallback-text`,children:[(0,W.jsx)(`div`,{className:`art-pdf-fallback-name`,children:t}),(0,W.jsx)(`div`,{className:`art-pdf-fallback-hint`,children:`Your browser can't display this PDF inline. Click to download.`})]}),(0,W.jsx)(B,{size:16})]}):(0,W.jsx)(`iframe`,{ref:a,className:`art-pdf`,src:e,title:t,"aria-label":`PDF preview of ${t}`,onLoad:u,onError:()=>l(`onerror`)})}var _D={browser:`Browser`,data:`Data`,graph:`Graph`};function vD({selection:e,trigger:t,sessionKey:n,onClose:r,onArtefactSaved:i,onSwapToGraph:a}){let o=e!==null,s=e?.surface??null,c=(0,U.useRef)(null),l=(0,U.useRef)(null),[u,d]=(0,U.useState)(null),p=e?.surface===`doc`?e.docId:null,m=(0,U.useCallback)(e=>{if(!n||!p)return;let t={};try{t=JSON.parse(e)}catch{return}t.action!==`save`||typeof t.content!=`string`||(d(null),fetch(`/api/admin/sidebar-artefact-save?session_key=${encodeURIComponent(n)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({id:p,content:t.content})}).then(async e=>{if(!e.ok){let t=(await e.json().catch(()=>({}))).error??`status ${e.status}`;d(`Save failed: ${t}`),console.error(`[admin-ui] artefact-save-failed docId=${p} status=${e.status} error="${t}"`);return}let n=await e.json();i?.(p,n.updatedAt,t.content)}).catch(e=>{let t=e instanceof Error?e.message:String(e);d(`Save failed: ${t}`),console.error(`[admin-ui] artefact-save-failed docId=${p} error="${t}"`)}))},[n,p,i]);(0,U.useEffect)(()=>{d(null)},[p]),(0,U.useEffect)(()=>{let n=e?.surface===`doc`?e.docId:null,r=e?.surface===`graph`?e.focusNodeId??null:null,i=e?.surface??null,a=i===null?`closed`:`${i}:${n??`none`}:${r??`none`}`;if(a===c.current)return;let s=o?`open`:`closed`,l=o?t??`chat-link`:`toolbar-close`,u=i??c.current?.split(`:`)[0]??`doc`;console.info(`[admin-ui] artefact-pane state=${s} docId=${n??`none`} trigger=${l} surface=${u}`),c.current=a},[e,t,o]);let h=e?.surface===`doc`,g=h?(e.tag||e.name.split(`.`).pop()||`doc`).toUpperCase().slice(0,6):``,_=h?e.revision||`rev 1`:`live`,v=e&&e.surface!==`doc`?_D[e.surface]:``,y=h?e.name:v;return(0,W.jsxs)(`aside`,{className:`artefact`,"data-open":o,"data-surface":s??`none`,children:[(0,W.jsxs)(`div`,{className:`art-head`,children:[(0,W.jsxs)(`div`,{className:`left`,children:[!h&&s===`browser`&&(0,W.jsx)(D,{size:14,className:`art-head-surface-icon`}),!h&&s===`data`&&(0,W.jsx)(ue,{size:14,className:`art-head-surface-icon`}),!h&&s===`graph`&&(0,W.jsx)(pe,{size:14,className:`art-head-surface-icon`}),(0,W.jsx)(`span`,{className:`file-name`,children:y}),h&&(0,W.jsx)(`span`,{className:`file-tag`,children:g})]}),(0,W.jsxs)(`div`,{className:`right`,children:[h&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`button`,{className:`icon-btn`,title:`Copy`,type:`button`,"aria-label":`Copy`,onClick:()=>{L(e.content)},children:(0,W.jsx)(f,{size:14})}),(0,W.jsx)(`button`,{className:`icon-btn`,title:`Refresh`,type:`button`,"aria-label":`Refresh`,children:(0,W.jsx)(re,{size:14})})]}),s===`browser`&&(0,W.jsx)(`button`,{className:`icon-btn`,title:`Pop out`,type:`button`,"aria-label":`Pop out`,onClick:()=>l.current?.popout(),children:(0,W.jsx)(Ne,{size:14})}),o&&(0,W.jsx)(`button`,{className:`icon-btn`,title:`Close`,type:`button`,"aria-label":`Close`,onClick:r,children:(0,W.jsx)(ie,{size:14})})]})]}),(0,W.jsxs)(`div`,{className:`art-toolbar`,children:[(0,W.jsxs)(`span`,{className:`seg`,children:[(0,W.jsx)(`span`,{className:`bullet`}),(0,W.jsx)(`strong`,{children:h?`Artefact`:v})]}),(0,W.jsx)(`span`,{className:`right-meta`,children:_})]}),(0,W.jsxs)(`div`,{className:`art-body`,"data-surface":s??`none`,children:[h&&(()=>{let t=e.editable!==!1,r=e.skipReason??null,i=(e.mimeType??``).startsWith(`application/pdf`);if(r)return(0,W.jsx)(hD,{reason:r});if(i&&n){let t=`/api/admin/sidebar-artefact-content?id=${encodeURIComponent(e.docId)}&session_key=${encodeURIComponent(n)}`;return(0,W.jsx)(gD,{src:t,name:e.name,docId:e.docId},t)}return(0,W.jsxs)(W.Fragment,{children:[u&&(0,W.jsx)(`div`,{className:`art-save-error`,role:`alert`,children:u}),(0,W.jsx)(nT,{data:{title:e.name,content:e.content,readOnly:!t},onSubmit:t?m:pD,submitted:!1})]})})(),s===`browser`&&(0,W.jsx)(uD,{ref:l,onClose:r}),s===`data`&&n&&(0,W.jsx)(oe,{sessionKey:n,onOpenInGraph:a?e=>{let t=se(e.properties);a(e.nodeId,t??e.labels[0]??null)}:void 0}),e?.surface===`graph`&&n&&(0,W.jsx)(z,{sessionKey:n,initialFocus:e.focusNodeId?{nodeId:e.focusNodeId,nodeLabel:e.focusNodeLabel??null}:null,initialLabels:e.initialLabels??null})]}),(0,W.jsxs)(`div`,{className:`art-foot`,children:[(0,W.jsx)(`span`,{className:`left`,children:_}),(0,W.jsx)(`span`,{className:`right in-sync`,children:`in sync`})]})]})}var yD=`maxy-shell-artefact-px`;function bD(){if(typeof window>`u`)return 320;let e=window.innerWidth,t=document.querySelector(`.platform > .side`)?.getBoundingClientRect(),n=t?t.right:Math.round(e*.3);return SD(Math.round((e-n)*(2/3)))}function xD(){if(typeof window>`u`)return 320;try{let e=window.localStorage.getItem(yD);if(!e)return bD();let t=parseInt(e,10);if(Number.isFinite(t)&&t>=320)return t}catch{}return bD()}function SD(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=document.querySelector(`.platform > .side`)?.getBoundingClientRect(),r=n?n.right:Math.round(t*.3),i=Math.max(320,t-r-480);return Math.min(Math.max(e,320),i)}function CD({targetSelector:e=`.platform`}){let t=(0,U.useRef)(null),[n,r]=(0,U.useState)(()=>xD()),i=(0,U.useRef)(n);(0,U.useEffect)(()=>{let t=document.querySelector(e);!t||!(t instanceof HTMLElement)||(t.style.setProperty(`--artefact-px`,`${n}px`),i.current=n)},[n,e]);let a=(0,U.useCallback)(()=>{r(e=>{let t=SD(e);return t===e?e:t})},[]);(0,U.useEffect)(()=>(a(),window.addEventListener(`resize`,a),()=>window.removeEventListener(`resize`,a)),[a]);let o=e=>{e.preventDefault();let n=t.current;if(!n)return;n.setPointerCapture(e.pointerId),n.classList.add(`dragging`);let a=!1,o=e=>{a=!0,r(SD(Math.round(window.innerWidth-e.clientX)))},s=()=>{if(n.releasePointerCapture(e.pointerId),n.classList.remove(`dragging`),window.removeEventListener(`pointermove`,o),window.removeEventListener(`pointerup`,s),!a)return;let t=i.current;try{window.localStorage.setItem(yD,String(t))}catch{}console.info(`[admin-ui] artefact-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=bD();r(e);try{window.localStorage.removeItem(yD)}catch{}console.info(`[admin-ui] artefact-resize px=${e}`)};return(0,W.jsx)(`div`,{ref:t,className:`art-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize artefact pane`,onPointerDown:o,onDoubleClick:s})}var wD=`maxy-shell-side-px`;function TD(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .artefact`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function ED(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=Math.max(220,t-480-TD());return Math.min(Math.max(e,220),n)}function DD(){if(typeof window>`u`)return 264;try{let e=window.localStorage.getItem(wD);if(!e)return 264;let t=parseInt(e,10);if(Number.isFinite(t)&&t>=220)return ED(t)}catch{}return 264}function OD({targetSelector:e=`.platform`}){let t=(0,U.useRef)(null),[n,r]=(0,U.useState)(()=>DD()),i=(0,U.useRef)(n);(0,U.useEffect)(()=>{let t=document.querySelector(e);!t||!(t instanceof HTMLElement)||(t.style.setProperty(`--side-px`,`${n}px`),i.current=n)},[n,e]);let a=(0,U.useCallback)(()=>{r(e=>{let t=ED(e);return t===e?e:t})},[]);(0,U.useEffect)(()=>{a(),window.addEventListener(`resize`,a);let t=document.querySelector(e),n=null;return t instanceof HTMLElement&&(n=new MutationObserver(a),n.observe(t,{attributes:!0,attributeFilter:[`data-artefact`,`class`]})),()=>{window.removeEventListener(`resize`,a),n?.disconnect()}},[a,e]);let o=e=>{e.preventDefault();let n=t.current;if(!n)return;n.setPointerCapture(e.pointerId),n.classList.add(`dragging`);let a=!1,o=e=>{a=!0,r(ED(Math.round(e.clientX)))},s=()=>{if(n.releasePointerCapture(e.pointerId),n.classList.remove(`dragging`),window.removeEventListener(`pointermove`,o),window.removeEventListener(`pointerup`,s),!a)return;let t=i.current;try{window.localStorage.setItem(wD,String(t))}catch{}console.info(`[admin-ui] sidebar-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=ED(264);r(e);try{window.localStorage.removeItem(wD)}catch{}console.info(`[admin-ui] sidebar-resize px=${e}`)};return(0,W.jsx)(`div`,{ref:t,className:`side-resize-handle`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize sidebar`,onPointerDown:o,onDoubleClick:s})}function kD(e){let[t,n]=(0,U.useState)([]),[r,i]=(0,U.useState)(!1),[a,o]=(0,U.useState)(null),[s,c]=(0,U.useState)(null),l=(0,U.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,U.useEffect)(()=>{e||(c(null),n([]),o(null))},[e]);let u=(0,U.useCallback)(()=>l(!1),[l]),d=(0,U.useCallback)(()=>l(!0),[l]);return{sessions:t,setSessions:n,loading:r,loaded:s!==null&&s===e,error:a,ensureLoaded:u,refetch:d}}function AD(){vt();let e=(0,U.useRef)(null),[t,n]=(0,U.useState)(null),[r,a]=(0,U.useState)(!1),[o,s]=(0,U.useState)(!1),[c,l]=(0,U.useState)(``),[u,d]=(0,U.useState)(!1),[f,p]=(0,U.useState)(null),[m,_]=(0,U.useState)(!1),[v,y]=(0,U.useState)(null),[b,x]=(0,U.useState)(null),[w,T]=(0,U.useState)(!1),[E,O]=(0,U.useState)(null),[k,A]=(0,U.useState)(!1),[j,M]=(0,U.useState)(null),[N,P]=(0,U.useState)(!1),[F,ee]=(0,U.useState)(!1),[te,R]=(0,U.useState)(!1),[ne,re]=(0,U.useState)(!1),[z,B]=(0,U.useState)(null),[ae,oe]=(0,U.useState)(null),se=(0,U.useRef)(null),[le,de]=(0,U.useState)(()=>typeof window<`u`&&window.matchMedia(`(min-width: 641px)`).matches);(0,U.useEffect)(()=>{let e=window.matchMedia(`(min-width: 641px)`),t=e=>de(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let[he,ge]=(0,U.useState)(()=>typeof window<`u`&&window.matchMedia(`(min-width: 1080px)`).matches);(0,U.useEffect)(()=>{let e=window.matchMedia(`(min-width: 1080px)`),t=e=>ge(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let _e=(0,U.useRef)(!1),ve=(0,U.useRef)(!1),ye=(0,U.useRef)(!1),be=(0,U.useRef)(!1),xe=(0,U.useRef)(null),[Se,Ce]=(0,U.useState)(null),we=g(),Te=xt(),V=Dt(),Ee=Ht(),De=kD(V.sessionKey),H=Vt({sessionKey:V.sessionKey,setSessionKey:V.setSessionKey,setAppState:V.setAppState,conversationId:V.conversationId,setConversationId:V.setConversationId,startElapsedTimer:Te.startElapsedTimer,stopElapsedTimer:Te.stopElapsedTimer,resetTimerState:Te.resetTimerState,pausedElapsedRef:Te.pausedElapsedRef,expandAllDefaultRef:V.expandAllDefaultRef,setExpandAll:V.setExpandAll,getPendingFiles:()=>Ee.pendingFiles,clearPendingFiles:Ee.clearFiles,inputRef:e});(0,U.useEffect)(()=>{l(window.location.hostname.startsWith(`admin.`)?window.location.origin.replace(`admin.`,`public.`):window.location.origin)},[]),(0,U.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,U.useEffect)(()=>{(V.appState===`set-pin`||V.appState===`enter-pin`)&&setTimeout(()=>V.pinInputRef.current?.focus(),100),V.appState===`chat`&&setTimeout(()=>e.current?.focus(),100)},[V.appState,H.greetingGeneration]),(0,U.useEffect)(()=>{if(V.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)},[V.appState]);let Oe=(0,U.useRef)(H.greetingGeneration);if((0,U.useEffect)(()=>{H.greetingGeneration!==Oe.current&&(Oe.current=H.greetingGeneration,V.onboardingComplete===!1&&(_e.current=!1))},[H.greetingGeneration,V.onboardingComplete]),(0,U.useEffect)(()=>{V.appState===`chat`&&V.onboardingComplete===!1&&(_e.current||(_e.current=!0,H.sendSystemPrompt(`[Begin onboarding.]`)))},[V.appState,V.onboardingComplete,H.greetingGeneration]),(0,U.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,U.useEffect)(()=>{if(V.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}},[V.appState]),(0,U.useEffect)(()=>{if(V.appState!==`chat`||!V.sessionKey)return;let e=V.conversationId?`flushed`:`pre-flush`,t=V.sessionKey.slice(0,8),n=V.conversationId?V.conversationId.slice(0,8):`null`;console.info(`[admin-session-identity] sessionKey=${t} conversationId=${n} phase=${e} surface=chat-header`)},[V.appState,V.sessionKey,V.conversationId]),(0,U.useEffect)(()=>{if(V.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=z?`open`:`closed`;console.info(`[admin-ui] platform-shell brand=${C.productName} sidebar=${e} artefact=${t}`)},[V.appState,De.loaded,De.sessions,z]),(0,U.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,U.useEffect)(()=>{if(typeof BroadcastChannel>`u`)return;let e=new BroadcastChannel(`platform-onboarding`);return e.onmessage=e=>{e.data?.type===`remote-password-set`&&H.sendMessageRef.current(`I've set the remote password`)},()=>e.close()},[]),V.appState===`loading`)return(0,W.jsx)(`div`,{className:`chat-page admin-page`,children:(0,W.jsx)(`header`,{className:`chat-header`,children:(0,W.jsx)(`img`,{src:I,alt:C.productName,className:`chat-logo`})})});if(V.appState===`set-pin`)return(0,W.jsx)(Wt,{pin:V.pin,setPin:V.setPin,confirmPin:V.confirmPin,setConfirmPin:V.setConfirmPin,operatorName:V.operatorName,setOperatorName:V.setOperatorName,showPin:V.showPin,setShowPin:V.setShowPin,pinLoading:V.pinLoading,pinError:V.pinError,pinInputRef:V.pinInputRef,confirmPinInputRef:V.confirmPinInputRef,setPinFormRef:V.setPinFormRef,onSubmit:V.handleSetPin});if(V.appState===`onboarding-choice`)return(0,W.jsx)(Jt,{setAppState:V.setAppState,setOnboardingComplete:V.setOnboardingComplete});if(V.appState===`connect-claude`)return(0,W.jsx)(qt,{authPolling:V.authPolling,setAuthPolling:V.setAuthPolling,authLoading:V.authLoading,setAuthLoading:V.setAuthLoading,pinError:V.pinError,setPinError:V.setPinError,setAppState:V.setAppState});if(V.appState===`enter-pin`)return(0,W.jsx)(Gt,{pin:V.pin,setPin:V.setPin,showPin:V.showPin,setShowPin:V.setShowPin,pinLoading:V.pinLoading,pinError:V.pinError,pinInputRef:V.pinInputRef,onSubmit:V.handleLogin,onChangePin:V.handleChangePin});if(V.appState===`account-picker`)return(0,W.jsx)(Kt,{accounts:V.accounts,loading:V.accountPickerLoading,error:V.pinError,onSelect:V.handleAccountSelect});let ke=z?`open`:`closed`,Ae=ne&&le,je=`platform${te?` menu-open`:``}${Ae?` sidebar-collapsed`:``}`,Me=e=>{if(!H.isStreaming&&V.sessionKey){if(!e.conversationId){H.resetConversation(),H.setMessages([]),V.setConversationId(null);return}H.resetConversation(),H.setMessages([]),fetch(`/api/admin/sessions/${encodeURIComponent(e.conversationId)}/resume?session_key=${encodeURIComponent(V.sessionKey)}`,{method:`POST`}).then(e=>e.ok?e.json():Promise.reject(Error(`resume returned ${e.status}`))).then(e=>{e.conversationId&&V.setConversationId(e.conversationId);let t=(e.messages??[]).map(e=>({role:e.role===`user`?`admin`:`maxy`,content:e.role===`user`?e.content:void 0,events:e.role===`assistant`?e.events??[]:void 0,...e.role===`user`&&e.attachments&&e.attachments.length>0?{attachments:e.attachments}:{},timestamp:new Date(e.createdAt).getTime()||0,historical:!0,...e.messageId?{messageId:e.messageId}:{}}));t.length>0&&H.setMessages(t);let n=[];for(let t of e.messages??[]){if(t.role!==`assistant`||!t.submittedEventIndices?.length)continue;let e=new Date(t.createdAt).getTime()||0;for(let r of t.submittedEventIndices)n.push(`${e}_${r}`)}n.length>0&&H.seedSubmittedComponents(n)}).catch(e=>{console.error(`[chat] sidebar conversation resume failed:`,e),H.setMessages([{role:`maxy`,events:[{type:`text`,content:`Could not load conversation history.`}],timestamp:Date.now()-1,historical:!0}])})}},Pe={conversationId:V.conversationId,sessionKey:V.sessionKey,disconnecting:V.disconnecting,onOpenConversations:()=>{T(!0),De.refetch()},handleDisconnect:V.handleDisconnect};return(0,W.jsx)(S,{value:{onShowVnc:()=>P(!0)},children:(0,W.jsxs)(`div`,{className:je,"data-artefact":ke,children:[(0,W.jsx)(`div`,{className:`scrim`,onClick:()=>{R(!1),console.info(`[admin-ui] mobile-drawer state=closed`)}}),(0,W.jsx)(fD,{ref:se,businessName:V.businessName??null,sessionKey:V.sessionKey,conversationId:V.conversationId,role:V.role,userName:V.userName,userAvatar:V.userAvatar,sessions:De.sessions,sessionsLoading:De.loading,sessionsError:De.error,ensureSessionsLoaded:De.ensureLoaded,refetchSessions:De.refetch,onSelectSession:Me,onSelectArtefact:(e,t)=>{B({surface:`doc`,...e}),oe(t)},onSelectProjects:()=>{B({surface:`graph`,initialLabels:[`Project`]}),oe(`sidebar-projects`)},onSelectPeople:()=>{B({surface:`graph`,initialLabels:[`Person`]}),oe(`sidebar-people`)},onSelectTasks:()=>{B({surface:`graph`,initialLabels:[`Task`]}),oe(`sidebar-tasks`)},onSelectAgents:()=>{B({surface:`graph`,initialLabels:[`Agent`]}),oe(`sidebar-agents`)},onCloseMobileDrawer:()=>{te&&(R(!1),console.info(`[admin-ui] mobile-drawer state=closed`))},collapsed:Ae,onToggleCollapsed:()=>re(e=>!e),actions:Pe}),(0,W.jsxs)(`div`,{className:`chat-page admin-page`,children:[(0,W.jsxs)(`header`,{className:`chat-header`,children:[(0,W.jsx)(`button`,{type:`button`,className:`icon-btn mobile-menu`,"aria-label":`Show sidebar`,title:`Show sidebar`,onClick:()=>{R(e=>{let t=!e;return console.info(`[admin-ui] mobile-drawer state=${t?`open`:`closed`}`),t})},children:(0,W.jsx)(at,{size:16})}),(0,W.jsx)(`img`,{src:I,alt:C.productName,className:`chat-logo`}),(!C.logoContainsName||V.businessName)&&(0,W.jsx)(`div`,{children:(0,W.jsx)(`h1`,{className:`chat-tagline`,children:V.businessName||C.productName})}),(V.sessionKey||V.conversationId)&&(0,W.jsxs)(`button`,{type:`button`,className:`chat-session-chip chat-session-chip-${V.conversationId?`flushed`:`pre-flush`}`+(Se===`copied`?` copied`:``)+(Se===`failed`?` copy-failed`:``),title:V.conversationId?`conversation ${V.conversationId} — click to copy`:`session ${V.sessionKey} (pre-flush, first turn pending) — click to copy`,onClick:async()=>{let e=V.conversationId??V.sessionKey;e&&(Ce(await L(e)?`copied`:`failed`),setTimeout(()=>Ce(null),1200))},children:[(0,W.jsx)(`span`,{className:`chat-session-chip-label`,children:Se===`copied`?`copied`:Se===`failed`?`copy failed`:V.conversationId?`conversation`:`session`}),(0,W.jsx)(`span`,{className:`chat-session-chip-id`,children:Se===`copied`?`✓`:Se===`failed`?`✕`:`${(V.conversationId??V.sessionKey??``).slice(0,8)}…`})]}),(0,W.jsxs)(`div`,{className:`chat-burger-wrap`,ref:xe,children:[(0,W.jsx)(`button`,{type:`button`,className:`chat-burger`,onClick:()=>d(e=>!e),"aria-label":`Menu`,"aria-haspopup":`true`,"aria-expanded":u,children:(0,W.jsx)(ce,{size:20})}),u&&(0,W.jsxs)(`div`,{className:`chat-menu`,children:[(0,W.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:async()=>{if(!F&&!(!he&&N)){ee(!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`);he?(B({surface:`browser`}),oe(`header-menu`)):P(!0)}catch(e){console.error(`[browser] Launch failed:`,e),alert(e instanceof Error?e.message:`Failed to launch browser`)}finally{ee(!1)}}},disabled:F,children:[(0,W.jsx)(D,{size:14}),` Browser`,F&&(0,W.jsx)(me,{size:12,className:`spin`})]}),(0,W.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{d(!1),he?(B({surface:`data`}),oe(`header-menu`)):window.location.href=`/data`},children:[(0,W.jsx)(ue,{size:14}),` Data`]}),(0,W.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{d(!1),he?(B({surface:`graph`}),oe(`header-menu`)):window.location.href=`/graph`},children:[(0,W.jsx)(pe,{size:14}),` Graph`]}),(0,W.jsx)(`div`,{className:`chat-menu-divider`}),(0,W.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,W.jsx)(Ne,{size:14}),` Public`,m&&(0,W.jsx)(me,{size:12,className:`spin`})]}),f!==null&&(0,W.jsxs)(`div`,{className:`chat-menu-agents`,children:[v&&(0,W.jsx)(`span`,{className:`chat-menu-agent-error`,children:v}),f.length===0&&!v&&(0,W.jsx)(`span`,{className:`chat-menu-agent-empty`,children:`No public agents configured`}),f.map(e=>(0,W.jsxs)(`div`,{className:`chat-menu-item chat-menu-agent-item`,children:[(0,W.jsx)(`span`,{className:`agent-status-dot ${e.status}`}),(0,W.jsxs)(`span`,{className:`agent-text`,children:[(0,W.jsx)(`span`,{className:`agent-display-name`,children:e.displayName}),(0,W.jsxs)(`span`,{className:`agent-slug`,children:[`/`,e.slug]})]}),b===e.slug?(0,W.jsxs)(`span`,{className:`agent-actions agent-confirm`,children:[(0,W.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,W.jsx)(h,{size:12})}),(0,W.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-confirm-no`,title:`Cancel`,onClick:()=>x(null),children:(0,W.jsx)(ie,{size:12})})]}):(0,W.jsxs)(`span`,{className:`agent-actions`,children:[(0,W.jsx)(`a`,{href:`${c}/${e.slug}`,target:`_blank`,rel:`noopener noreferrer`,className:`agent-action-btn`,title:`Open agent`,onClick:()=>d(!1),children:(0,W.jsx)(Ne,{size:12})}),(0,W.jsx)(`button`,{type:`button`,className:`agent-action-btn agent-delete-btn`,title:`Delete agent`,onClick:()=>x(e.slug),children:(0,W.jsx)(i,{size:12})})]})]},e.slug))]}),(0,W.jsx)(`div`,{className:`chat-menu-divider`}),E?.updateAvailable?(0,W.jsxs)(`button`,{type:`button`,className:`chat-menu-version`,onClick:()=>{E.latest&&(M(E),d(!1),A(!0))},children:[(0,W.jsx)(He,{size:14}),(0,W.jsxs)(`span`,{className:`version-installed`,children:[`v`,E.installed,(0,W.jsx)(`span`,{className:`version-update-dot`})]})]}):(0,W.jsxs)(`div`,{className:`chat-menu-version chat-menu-version-passive`,children:[(0,W.jsx)(He,{size:14}),(0,W.jsxs)(`span`,{className:`version-installed`,children:[E?`v${E.installed}`:`…`,E&&!E.updateAvailable&&(0,W.jsx)(`span`,{className:`version-uptodate-dot`})]})]}),(0,W.jsxs)(`button`,{type:`button`,className:`chat-menu-item`,onClick:()=>{d(!1),V.handleLogout(),H.setMessages([])},children:[(0,W.jsx)(fe,{size:14}),` Log out`]})]})]})]}),(0,W.jsxs)(`div`,{className:`chat-content`,children:[(0,W.jsx)(KE,{messages:H.messages,isStreaming:H.isStreaming,elapsedSeconds:Te.elapsedSeconds,sessionTurnStart:Te.sessionTurnStart,expandAll:V.expandAll,setExpandAll:V.setExpandAll,conversationCompacted:H.conversationCompacted,isCompacting:H.isCompacting,setShowCompactConfirm:s,handleComponentSubmit:H.handleComponentSubmit,effectiveSubmitted:H.effectiveSubmitted,selectionMode:we.selectionMode,selectedItems:we.selectedItems,toggleSelectItem:we.toggleSelectItem,sessionKey:V.sessionKey,setLightboxSrc:n,messageQueue:H.messageQueue,messageQueueRef:H.messageQueueRef,setQueue:H.setQueue,sendMessage:H.sendMessage,appState:V.appState,onboardingComplete:V.onboardingComplete,onOpenArtefact:e=>{B({surface:`doc`,...e}),oe(`chat-link`)}}),(0,W.jsx)(qE,{offer:H.topicChangeOffer,onFreshStart:H.handleTopicFreshStart,onContinue:H.handleTopicContinue,disabled:H.isStreaming}),(0,W.jsx)(sD,{selectionMode:we.selectionMode,selectedItems:we.selectedItems,copyToast:we.copyToast||null,exitSelection:we.exitSelection,enterSelection:we.enterSelection,copySelected:we.copySelected,showCopyToast:we.showCopyToast,input:H.input,setInput:H.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:H.isStreaming,wasPaused:H.wasPaused,messages:H.messages,messageQueueRef:H.messageQueueRef,setQueue:H.setQueue,sendMessage:H.sendMessage,stopStreaming:H.stopStreaming,disconnecting:V.disconnecting,handleDisconnect:V.handleDisconnect,claudeInfo:V.claudeInfo,setClaudeInfo:V.setClaudeInfo,setShowClaudeInfo:a,conversationId:V.conversationId,sessionKey:V.sessionKey,onNewConversation:H.startNewConversation,newConversationDisabled:H.isStreaming||H.isCompacting,onOpenConversations:()=>{T(!0),De.refetch()},sidebarVisible:le})]}),we.copyToast&&(0,W.jsx)(`span`,{className:`copy-toast${we.copyToast===`failed`?` copy-toast-failed`:``}`,children:we.copyToast===`copied`?`Copied`:`Copy failed`}),(0,W.jsx)($E,{show:w,onClose:()=>T(!1),conversationsLoading:De.loading,conversationsError:De.error,conversationsList:De.sessions,setConversationsList:De.setSessions,sessionKey:V.sessionKey,setSessionKey:V.setSessionKey,isStreaming:H.isStreaming,resetConversation:H.resetConversation,setMessages:H.setMessages,setConversationId:V.setConversationId}),(0,W.jsx)(eD,{src:t,onClose:()=>n(null)}),(0,W.jsx)(tD,{show:o,onClose:()=>s(!1),onConfirm:H.handleCompactNow}),(0,W.jsx)(nD,{show:r,onClose:()=>{a(!1),V.setClaudeInfo(null)},claudeInfo:V.claudeInfo,messages:H.messages,sessionElapsed:Te.sessionElapsed,conversationId:V.conversationId}),(0,W.jsx)(aD,{show:k,onClose:()=>{A(!1),be.current=!0},versionInfo:j,sessionKey:V.sessionKey,onUpgradeComplete:()=>O(null)}),N&&(0,W.jsx)(dD,{onClose:()=>P(!1)})]}),(0,W.jsx)(OD,{}),(0,W.jsx)(CD,{}),(0,W.jsx)(vD,{selection:z,trigger:ae,sessionKey:V.sessionKey,onClose:()=>{B(null),oe(null)},onArtefactSaved:(e,t,n)=>{se.current?.patchArtefact(e,{updatedAt:t,content:n})},onSwapToGraph:(e,t)=>{B({surface:`graph`,focusNodeId:e,focusNodeLabel:t}),oe(`chat-link`)}})]})})}(0,ge.createRoot)(document.getElementById(`root`)).render((0,W.jsx)(AD,{}));
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>Real Agent</title>
|
|
7
7
|
<link rel="icon" href="/favicon.ico">
|
|
8
|
-
<script type="module" crossorigin src="/assets/admin-
|
|
8
|
+
<script type="module" crossorigin src="/assets/admin-DOkUspG1.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-DkaAusaX.js">
|
|
11
11
|
<link rel="modulepreload" crossorigin href="/assets/preload-helper-qlgyTAkD.js">
|
package/payload/server/server.js
CHANGED
|
@@ -51,7 +51,7 @@ import {
|
|
|
51
51
|
vncLog,
|
|
52
52
|
waitForExit,
|
|
53
53
|
writeChromiumWrapper
|
|
54
|
-
} from "./chunk-
|
|
54
|
+
} from "./chunk-LFOR2ACU.js";
|
|
55
55
|
import {
|
|
56
56
|
agentLogStream,
|
|
57
57
|
clearSessionHistory,
|
|
@@ -79,7 +79,7 @@ import {
|
|
|
79
79
|
sigtermFlushStreamLogs,
|
|
80
80
|
unregisterSession,
|
|
81
81
|
validateSession
|
|
82
|
-
} from "./chunk-
|
|
82
|
+
} from "./chunk-L3T7ECLI.js";
|
|
83
83
|
import {
|
|
84
84
|
ACCOUNTS_DIR,
|
|
85
85
|
PLATFORM_ROOT,
|
|
@@ -96,7 +96,7 @@ import {
|
|
|
96
96
|
completeCloudflareTask,
|
|
97
97
|
openCloudflareTask,
|
|
98
98
|
readTunnelState
|
|
99
|
-
} from "./chunk-
|
|
99
|
+
} from "./chunk-JNVZQMTZ.js";
|
|
100
100
|
import {
|
|
101
101
|
GREETING_DIRECTIVE,
|
|
102
102
|
HAIKU_MODEL,
|
|
@@ -128,7 +128,7 @@ import {
|
|
|
128
128
|
verifyAndGetConversationUpdatedAt,
|
|
129
129
|
verifyConversationOwnership,
|
|
130
130
|
writeAdminUserAndPerson
|
|
131
|
-
} from "./chunk-
|
|
131
|
+
} from "./chunk-NAP6XMLW.js";
|
|
132
132
|
|
|
133
133
|
// ../lib/graph-trash/dist/index.js
|
|
134
134
|
var require_dist = __commonJS({
|
|
@@ -7284,7 +7284,7 @@ var app11 = new Hono();
|
|
|
7284
7284
|
app11.post("/cancel", requireAdminSession, async (c) => {
|
|
7285
7285
|
const session_key = c.var.sessionKey;
|
|
7286
7286
|
try {
|
|
7287
|
-
const { interruptClient: interruptClient2 } = await import("./client-pool-
|
|
7287
|
+
const { interruptClient: interruptClient2 } = await import("./client-pool-M2DU74ZP.js");
|
|
7288
7288
|
await interruptClient2(session_key);
|
|
7289
7289
|
return c.json({ ok: true });
|
|
7290
7290
|
} catch (err) {
|
|
@@ -8205,6 +8205,33 @@ app17.post("/new", requireAdminSession, async (c) => {
|
|
|
8205
8205
|
console.log(`[session] ${(/* @__PURE__ */ new Date()).toISOString()} session reset for new conversation: oldSessionKey=${oldSessionKey.slice(0, 8)}\u2026 newSessionKey=${newSessionKey.slice(0, 8)}\u2026 previousConversationId=${previousConversationId?.slice(0, 8) ?? "none"}\u2026 newConversationId=deferred`);
|
|
8206
8206
|
return c.json({ session_key: newSessionKey, conversationId: null });
|
|
8207
8207
|
});
|
|
8208
|
+
app17.post("/switch", requireAdminSession, async (c) => {
|
|
8209
|
+
const sessionKey = c.var.sessionKey;
|
|
8210
|
+
const accountId = getAccountIdForSession(sessionKey);
|
|
8211
|
+
const userId = getUserIdForSession(sessionKey);
|
|
8212
|
+
if (!accountId || !userId) {
|
|
8213
|
+
return c.json({ error: "Session missing account or user context" }, 400);
|
|
8214
|
+
}
|
|
8215
|
+
const body = await c.req.json().catch(() => ({}));
|
|
8216
|
+
const targetSessionKey = typeof body.target_session_key === "string" ? body.target_session_key : "";
|
|
8217
|
+
if (!targetSessionKey) {
|
|
8218
|
+
return c.json({ error: "target_session_key required" }, 400);
|
|
8219
|
+
}
|
|
8220
|
+
const targetCheck = validateSession(targetSessionKey, "admin");
|
|
8221
|
+
if (!targetCheck.ok) {
|
|
8222
|
+
console.error(`[session-switch] reject reason=${targetCheck.reason} from=${sessionKey.slice(0, 8)} target=${targetSessionKey.slice(0, 8)}`);
|
|
8223
|
+
return c.json({ error: "Target session not registered or wrong agent type", code: targetCheck.reason }, 404);
|
|
8224
|
+
}
|
|
8225
|
+
const targetAccountId = getAccountIdForSession(targetSessionKey);
|
|
8226
|
+
const targetUserId = getUserIdForSession(targetSessionKey);
|
|
8227
|
+
if (targetAccountId !== accountId || targetUserId !== userId) {
|
|
8228
|
+
console.error(`[session-switch] reject reason=ownership-mismatch from=${sessionKey.slice(0, 8)} target=${targetSessionKey.slice(0, 8)} accountMatch=${targetAccountId === accountId} userMatch=${targetUserId === userId}`);
|
|
8229
|
+
return c.json({ error: "Target session not owned by current operator" }, 403);
|
|
8230
|
+
}
|
|
8231
|
+
const targetConversationId = getConversationIdForSession(targetSessionKey) ?? null;
|
|
8232
|
+
console.log(`[session-switch] from=${sessionKey.slice(0, 8)} to=${targetSessionKey.slice(0, 8)} targetConvId=${targetConversationId?.slice(0, 8) ?? "none"} accountId=${accountId.slice(0, 8)}`);
|
|
8233
|
+
return c.json({ session_key: targetSessionKey, conversationId: targetConversationId });
|
|
8234
|
+
});
|
|
8208
8235
|
app17.delete("/:id", requireAdminSession, async (c) => {
|
|
8209
8236
|
const conversationId = c.req.param("id");
|
|
8210
8237
|
const sessionKey = c.var.sessionKey;
|
|
@@ -10521,7 +10548,22 @@ async function handleNeighbourhood(c, accountId) {
|
|
|
10521
10548
|
});
|
|
10522
10549
|
allowedIds = searchRes.results.map((r) => r.nodeId);
|
|
10523
10550
|
}
|
|
10524
|
-
|
|
10551
|
+
let rootLabels = [];
|
|
10552
|
+
if (allowedIds === null) {
|
|
10553
|
+
const labelRes = await session.executeRead(async (tx) => {
|
|
10554
|
+
return await tx.run(
|
|
10555
|
+
`MATCH (n) WHERE elementId(n) = $elementId
|
|
10556
|
+
AND n.accountId = $accountId
|
|
10557
|
+
AND NOT n:Trashed
|
|
10558
|
+
AND n.deletedAt IS NULL
|
|
10559
|
+
RETURN labels(n) AS labels LIMIT 1`,
|
|
10560
|
+
{ elementId, accountId }
|
|
10561
|
+
);
|
|
10562
|
+
});
|
|
10563
|
+
rootLabels = labelRes.records[0]?.get("labels") ?? [];
|
|
10564
|
+
}
|
|
10565
|
+
const isPersonRoot = rootLabels.includes("Person");
|
|
10566
|
+
const cypher = allowedIds !== null ? NEIGHBOURHOOD_SEARCH_INTERSECT_CYPHER : isPersonRoot ? NEIGHBOURHOOD_CYPHER_PERSON_ROOT : NEIGHBOURHOOD_CYPHER;
|
|
10525
10567
|
const cypherParams = {
|
|
10526
10568
|
accountId,
|
|
10527
10569
|
elementId,
|
|
@@ -10566,6 +10608,18 @@ async function handleNeighbourhood(c, accountId) {
|
|
|
10566
10608
|
);
|
|
10567
10609
|
}
|
|
10568
10610
|
}
|
|
10611
|
+
if (allowedIds === null) {
|
|
10612
|
+
const rootNode = nodes[0];
|
|
10613
|
+
const rootIsMessage = rootNode?.labels.includes("Message") ?? false;
|
|
10614
|
+
const totalMessages = nodes.filter((n) => n.labels.includes("Message")).length;
|
|
10615
|
+
const clusterMessageCount = totalMessages - (rootIsMessage ? 1 : 0);
|
|
10616
|
+
const convNode = nodes.find((n) => n.labels.some((lbl) => CLUSTER_CONVERSATION_LABELS.has(lbl)));
|
|
10617
|
+
const convIsExtra = convNode != null && convNode.id !== rootNode?.id ? 1 : 0;
|
|
10618
|
+
const neighbourCount = Math.max(0, nodes.length - 1 - clusterMessageCount - convIsExtra);
|
|
10619
|
+
console.error(
|
|
10620
|
+
`[graph-subgraph] expand root=${elementId} labels=${(rootNode?.labels ?? []).join(",")} clusterMessages=${clusterMessageCount} neighbours=${neighbourCount}`
|
|
10621
|
+
);
|
|
10622
|
+
}
|
|
10569
10623
|
if (allowedIds !== null) {
|
|
10570
10624
|
console.error(
|
|
10571
10625
|
`[graph-page] neighbourhood-search-intersect q="${q}" allowed=${allowedIds.length} root=${elementId} rendered=${nodes.length}`
|
|
@@ -10726,6 +10780,65 @@ var NEIGHBOURHOOD_CYPHER = `
|
|
|
10726
10780
|
[x IN windowNodes | {id: elementId(x), labels: labels(x), properties: ${CONVERSATION_PROPS_PROJECTION}}] AS nodes,
|
|
10727
10781
|
[e IN rawEdges WHERE e IS NOT NULL] AS edges
|
|
10728
10782
|
`;
|
|
10783
|
+
var NEIGHBOURHOOD_CYPHER_PERSON_ROOT = `
|
|
10784
|
+
MATCH (n)
|
|
10785
|
+
WHERE elementId(n) = $elementId
|
|
10786
|
+
AND n.accountId = $accountId
|
|
10787
|
+
AND NOT n:Trashed
|
|
10788
|
+
AND n.deletedAt IS NULL
|
|
10789
|
+
|
|
10790
|
+
OPTIONAL MATCH (n)-[:PART_OF]->(convFromMsg:Conversation)
|
|
10791
|
+
WHERE convFromMsg.accountId = $accountId
|
|
10792
|
+
AND NOT convFromMsg:Trashed
|
|
10793
|
+
AND convFromMsg.deletedAt IS NULL
|
|
10794
|
+
WITH n, CASE
|
|
10795
|
+
WHEN any(lbl IN labels(n) WHERE lbl IN ['Conversation','AdminConversation','PublicConversation']) THEN n
|
|
10796
|
+
ELSE convFromMsg
|
|
10797
|
+
END AS conv
|
|
10798
|
+
|
|
10799
|
+
OPTIONAL MATCH (conv)<-[:PART_OF]-(siblingMsg:Message)
|
|
10800
|
+
WHERE siblingMsg.accountId = $accountId
|
|
10801
|
+
AND NOT siblingMsg:Trashed
|
|
10802
|
+
AND siblingMsg.deletedAt IS NULL
|
|
10803
|
+
AND elementId(siblingMsg) <> elementId(n)
|
|
10804
|
+
WITH n, conv, collect(DISTINCT siblingMsg) AS siblingMessages
|
|
10805
|
+
WITH n, conv, siblingMessages[0..$clusterMessagesCap] AS clusterMessages
|
|
10806
|
+
|
|
10807
|
+
OPTIONAL MATCH (n)-[r]-(m)
|
|
10808
|
+
WHERE m.accountId = $accountId
|
|
10809
|
+
AND NOT m:Trashed
|
|
10810
|
+
AND m.deletedAt IS NULL
|
|
10811
|
+
AND NOT any(lbl IN labels(m) WHERE lbl IN $agentActionLabels)
|
|
10812
|
+
AND type(r) <> 'SENT'
|
|
10813
|
+
WITH n, conv, clusterMessages, m
|
|
10814
|
+
LIMIT $neighbourhoodLimit
|
|
10815
|
+
WITH n, conv, clusterMessages, collect(DISTINCT m) AS neighbours
|
|
10816
|
+
|
|
10817
|
+
WITH [n]
|
|
10818
|
+
+ (CASE WHEN conv IS NOT NULL AND elementId(conv) <> elementId(n) THEN [conv] ELSE [] END)
|
|
10819
|
+
+ clusterMessages
|
|
10820
|
+
+ [x IN neighbours WHERE x IS NOT NULL
|
|
10821
|
+
AND elementId(x) <> elementId(n)
|
|
10822
|
+
AND (conv IS NULL OR elementId(x) <> elementId(conv))
|
|
10823
|
+
AND none(c IN clusterMessages WHERE elementId(c) = elementId(x))]
|
|
10824
|
+
AS windowNodes
|
|
10825
|
+
WITH windowNodes, [x IN windowNodes | elementId(x)] AS windowIds
|
|
10826
|
+
UNWIND windowNodes AS w
|
|
10827
|
+
OPTIONAL MATCH (w)-[r]-(o)
|
|
10828
|
+
WHERE elementId(o) IN windowIds
|
|
10829
|
+
AND type(r) <> 'SENT'
|
|
10830
|
+
WITH windowNodes,
|
|
10831
|
+
collect(DISTINCT CASE WHEN r IS NULL THEN null ELSE {
|
|
10832
|
+
id: elementId(r),
|
|
10833
|
+
from: elementId(startNode(r)),
|
|
10834
|
+
to: elementId(endNode(r)),
|
|
10835
|
+
type: type(r),
|
|
10836
|
+
properties: properties(r)
|
|
10837
|
+
} END) AS rawEdges
|
|
10838
|
+
RETURN
|
|
10839
|
+
[x IN windowNodes | {id: elementId(x), labels: labels(x), properties: ${CONVERSATION_PROPS_PROJECTION}}] AS nodes,
|
|
10840
|
+
[e IN rawEdges WHERE e IS NOT NULL] AS edges
|
|
10841
|
+
`;
|
|
10729
10842
|
var NEIGHBOURHOOD_SEARCH_INTERSECT_CYPHER = `
|
|
10730
10843
|
MATCH (n)
|
|
10731
10844
|
WHERE elementId(n) = $elementId
|
|
@@ -12600,7 +12713,7 @@ autoDeliverPremiumPlugins(bootEntitlement?.purchasedPlugins ?? void 0);
|
|
|
12600
12713
|
(async () => {
|
|
12601
12714
|
if (!bootAccount) return;
|
|
12602
12715
|
try {
|
|
12603
|
-
const { recoverRunningCloudflareTasks } = await import("./cloudflare-task-tracker-
|
|
12716
|
+
const { recoverRunningCloudflareTasks } = await import("./cloudflare-task-tracker-6S23B7QX.js");
|
|
12604
12717
|
const result = await recoverRunningCloudflareTasks(
|
|
12605
12718
|
bootAccount.accountId,
|
|
12606
12719
|
configDirForWhatsApp,
|