@rubytech/create-realagent-code 0.1.12 → 0.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rubytech/create-realagent-code",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "Install Real Agent — Built for agents. By agents.",
5
5
  "bin": {
6
6
  "create-realagent-code": "./dist/index.js"
@@ -0,0 +1 @@
1
+ import{o as e}from"./chunk-DD-I1_y5.js";import{a as t,i as n,n as r,r as i,t as a}from"./jsx-runtime-LncohCxF.js";import{a as o,i as s,o as c,s as l,t as u}from"./brand-29DyfElX.js";import{t as d}from"./loader-circle-DwwVih2K.js";import{n as f,t as p}from"./refresh-cw-Ho-xY4LQ.js";import{t as m}from"./Checkbox-D5bsL5IO.js";var h=n(),g=e(t(),1);new Set(`image/jpeg,image/png,image/gif,image/webp,application/pdf,text/plain,text/markdown,text/csv,text/html,text/calendar,application/zip,application/x-zip-compressed,audio/ogg,audio/opus,audio/mp4,audio/mpeg,audio/webm,audio/wav,.opus,.ogg,.m4a,.mp3,.wav,.webm`.split(`,`).filter(e=>!e.startsWith(`.`)));function _(e){switch(e){case`expanded`:return!0;case`collapsed`:return!1;default:return}}function v(){let[e,t]=(0,g.useState)(`loading`),[n,r]=(0,g.useState)(``),[i,a]=(0,g.useState)(``),[o,s]=(0,g.useState)(``),[c,l]=(0,g.useState)(``),[u,d]=(0,g.useState)(!1),[f,p]=(0,g.useState)(!1),[m,h]=(0,g.useState)(!1),[v,y]=(0,g.useState)(!1),[ee,b]=(0,g.useState)(!1),[te,x]=(0,g.useState)(null),[ne,S]=(0,g.useState)(null),[re,C]=(0,g.useState)(void 0),[ie,w]=(0,g.useState)(void 0),[T,E]=(0,g.useState)(null),[D,O]=(0,g.useState)(void 0),[k,A]=(0,g.useState)(null),[ae,j]=(0,g.useState)(null),[M,N]=(0,g.useState)([]),[P,F]=(0,g.useState)(!1),[I,L]=(0,g.useState)(void 0),R=(0,g.useRef)(void 0),[z,B]=(0,g.useState)(!1);(0,g.useEffect)(()=>{typeof window>`u`||window.location.hostname.startsWith(`admin.`)&&fetch(`/api/remote-auth/status`).then(e=>e.ok?e.json():null).then(e=>{e?.configured&&B(!0)}).catch(()=>{})},[]);let oe=(0,g.useRef)(null),V=(0,g.useRef)(null),se=(0,g.useRef)(null);(0,g.useEffect)(()=>{async function e(){let e=null;try{e=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!e)return!1;try{let n=await fetch(`/api/admin/session?session_key=${encodeURIComponent(e)}`);if(n.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}return!1}if(!n.ok)return!1;let r=await n.json();x(r.session_key),j(r.conversationId??null),C(r.onboardingComplete),w(r.businessName),E(r.role??null),O(r.userName===void 0?null:r.userName),A(r.avatar??null);let i=_(r.thinkingView);return R.current=i,L(i),t(`chat`),!0}catch(e){return console.error(`[admin] session restore failed:`,e),!1}}async function n(r=2){try{let i=await fetch(`/api/health`);if(!i.ok){if(r>0)return await new Promise(e=>setTimeout(e,1500)),n(r-1);console.error(`[admin] health check returned ${i.status} after retries`),t(`set-pin`);return}let a=await i.json();if(!a.pin_configured){t(`set-pin`);return}if(a.onboarding_complete===!1){t(`onboarding-choice`);return}if(!a.claude_authenticated){t(`connect-claude`);return}if(await e())return;t(`enter-pin`)}catch(e){if(r>0)return await new Promise(e=>setTimeout(e,1500)),n(r-1);console.error(`[admin] health check failed:`,e),t(`set-pin`)}}n()},[]),(0,g.useEffect)(()=>{e===`chat`&&fetch(`/api/admin/claude-info`).then(e=>{if(e.ok)return e.json()}).then(e=>{e&&S(e)}).catch(()=>{})},[e]),(0,g.useEffect)(()=>{if(e!==`chat`)return;let n=setInterval(async()=>{try{let e=await fetch(`/api/health`);if(!e.ok)return;let n=await e.json();(n.auth_status===`dead`||n.auth_status===`missing`)&&t(`connect-claude`)}catch{}},300*1e3);return()=>clearInterval(n)},[e]),(0,g.useEffect)(()=>{e===`connect-claude`&&fetch(`/api/health`).then(e=>e.ok?e.json():null).then(e=>{e?.claude_authenticated&&t(`enter-pin`)}).catch(()=>{})},[e]);async function H(e,n){p(!0);try{let i=await fetch(`/api/admin/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:e,...n?{accountId:n}:{}})});if(!i.ok){l((await i.json().catch(()=>({}))).error||`Invalid PIN`);return}let o=await i.json();if(o.accounts&&!o.session_key){console.log(`[admin] account picker shown: userId=${o.userId} accountCount=${o.accounts.length}`),N(o.accounts),t(`account-picker`);return}x(o.session_key),j(o.conversationId??null),C(o.onboardingComplete??!0),w(o.businessName),E(o.role??null),O(o.userName===void 0?null:o.userName),A(o.avatar??null);let s=_(o.thinkingView);if(R.current=s,L(s),n)try{sessionStorage.setItem(`maxy-account-id`,n)}catch{}try{sessionStorage.setItem(`maxy-admin-session-key`,o.session_key)}catch{}r(``),a(``),t(`chat`)}catch(e){console.error(`[admin] connection error:`,e),l(`Could not connect.`)}finally{p(!1),F(!1)}}let U=(0,g.useCallback)(async e=>{if(e.preventDefault(),f)return;l(``);let s=o.trim();if(!s){l(`Please enter your name.`);return}if(n.length<4){l(`PIN must be at least 4 characters.`);return}if(n!==i){l(`PINs do not match.`);return}let c=n;p(!0);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:c,name:s})});if(!e.ok){let n=await e.json().catch(()=>({}));if(e.status===409){console.log(`[admin] PIN already configured — re-checking health`);try{let e=await fetch(`/api/health`);if(e.ok){let r=await e.json();r.pin_configured&&r.claude_authenticated?t(`enter-pin`):r.pin_configured?t(`connect-claude`):l(n.error||`Failed to set PIN.`)}else t(`enter-pin`)}catch{t(`enter-pin`)}return}l(n.error||`Failed to set PIN.`);return}let n=await fetch(`/api/health`),i=n.ok?await n.json():null;if(i?.onboarding_complete===!1){r(``),a(``),t(`onboarding-choice`);return}if(i?.claude_authenticated){await H(c);return}r(``),a(``),t(`onboarding-choice`)}catch(e){console.error(`[admin] connection error:`,e),l(`Could not connect.`)}finally{p(!1)}},[n,i,f,o]),W=(0,g.useCallback)(async e=>{e.preventDefault(),l(``),await H(n)},[n]),G=(0,g.useCallback)(async()=>{b(!0);try{await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`logout`})}),x(null),E(null),O(void 0),A(null);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}t(`connect-claude`)}finally{b(!1)}},[]),K=(0,g.useCallback)(()=>{x(null),E(null),O(void 0),A(null);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}r(``),a(``),l(``),t(`enter-pin`)},[]);return{appState:e,setAppState:t,pin:n,setPin:r,confirmPin:i,setConfirmPin:a,operatorName:o,setOperatorName:s,pinError:c,setPinError:l,showPin:u,setShowPin:d,pinLoading:f,authPolling:m,setAuthPolling:h,authLoading:v,setAuthLoading:y,disconnecting:ee,cacheKey:te,setCacheKey:x,claudeInfo:ne,setClaudeInfo:S,onboardingComplete:re,setOnboardingComplete:C,businessName:ie,role:T,userName:D,userAvatar:k,conversationId:ae,setConversationId:j,accounts:M,accountPickerLoading:P,expandAll:I,setExpandAll:L,expandAllDefaultRef:R,remoteAuthEnabled:z,pinInputRef:oe,confirmPinInputRef:V,setPinFormRef:se,handleSetPin:U,handleLogin:W,handleAccountSelect:(0,g.useCallback)(async e=>{F(!0),l(``),await H(n,e)},[n]),handleDisconnect:G,handleLogout:K,handleChangePin:(0,g.useCallback)(async()=>{if(!n){l(`Enter your current PIN first.`);return}p(!0),l(``);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify({currentPin:n})});if(!e.ok){l((await e.json().catch(()=>({error:`Incorrect PIN.`}))).error||`Incorrect PIN.`);return}r(``),a(``),l(``),t(`set-pin`)}catch(e){console.error(`[admin-auth] change pin failed:`,e),l(e instanceof Error?e.message:String(e))}finally{p(!1)}},[n])}}function y(e){let[t,n]=(0,g.useState)([]),[r,i]=(0,g.useState)(!1),[a,o]=(0,g.useState)(null),[s,c]=(0,g.useState)(null),l=(0,g.useCallback)(async t=>{if(e&&!(!t&&s===e)){i(!0),o(null);try{let t=await fetch(`/api/admin/claude-sessions?session_key=${encodeURIComponent(e)}`);if(!t.ok)throw Error(`claude-sessions fetch returned ${t.status}`);let r=await t.json();n(Array.isArray(r)?r:r.sessions??[]),c(e)}catch(e){console.error(`[admin/claude-sessions] fetch failed:`,e),o(e instanceof Error?e.message:String(e))}finally{i(!1)}}},[e,s]);(0,g.useEffect)(()=>{e||(c(null),n([]),o(null))},[e]);let u=(0,g.useCallback)(()=>l(!1),[l]),d=(0,g.useCallback)(()=>l(!0),[l]),f=(0,g.useRef)(d);return(0,g.useEffect)(()=>{f.current=d},[d]),(0,g.useEffect)(()=>{if(!e)return;let t=setInterval(()=>{f.current()},3e3);return()=>clearInterval(t)},[e]),{sessions:t,setSessions:n,loading:r,loaded:s!==null&&s===e,error:a,ensureLoaded:u,refetch:d}}var ee=i(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),b=i(`box`,[[`path`,{d:`M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z`,key:`hh9hay`}],[`path`,{d:`m3.3 7 8.7 5 8.7-5`,key:`g66t2b`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}]]),te=i(`ellipsis-vertical`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]]),x=i(`external-link`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]),ne=i(`list-todo`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),S=i(`panel-left-close`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`m16 15-3-3 3-3`,key:`14y99z`}]]),re=i(`panel-left-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`m14 9 3 3-3 3`,key:`8010ee`}]]),C=i(`terminal`,[[`path`,{d:`M12 19h8`,key:`baeox8`}],[`path`,{d:`m4 17 6-6-6-6`,key:`1yngyt`}]]),ie=i(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),w=a();function T({inputRef:e,value:t,onChange:n,onComplete:r,showPin:i,autoFocus:a}){let o=(0,g.useRef)([]);function s(e,r){r.key===`Backspace`?(r.preventDefault(),t[e]?n(t.slice(0,e)+t.slice(e+1)):e>0&&(n(t.slice(0,e-1)+t.slice(e)),o.current[e-1]?.focus())):r.key===`ArrowLeft`&&e>0?o.current[e-1]?.focus():r.key===`ArrowRight`&&e<5?o.current[e+1]?.focus():r.key===`Enter`&&(r.preventDefault(),r.currentTarget.form?.requestSubmit())}function c(e,i){let a=i.nativeEvent.data;if(!a||!/^\d$/.test(a))return;let s=t.split(``);for(s[e]=a;s.length<e;)s.push(``);let c=s.join(``).replace(/\D/g,``).slice(0,6);n(c),c.length===6?r?.(c):e<5&&o.current[e+1]?.focus()}function l(e){e.preventDefault();let t=e.clipboardData.getData(`text`).replace(/\D/g,``).slice(0,6);t&&(n(t),t.length===6?r?.(t):o.current[t.length]?.focus())}return(0,w.jsx)(`div`,{className:`pin-field`,children:Array.from({length:6}).map((n,r)=>(0,w.jsx)(`input`,{ref:t=>{o.current[r]=t,r===0&&e&&(e.current=t)},type:`text`,inputMode:`numeric`,className:`pin-box${t[r]?` pin-box-filled`:``}`,value:t[r]?i?t[r]:`•`:``,onKeyDown:e=>s(r,e),onInput:e=>c(r,e),onPaste:l,onFocus:e=>e.target.select(),autoFocus:a&&r===0,autoComplete:`off`,maxLength:1,"aria-label":`PIN digit ${r+1}`},r))})}function E(e){let{pin:t,setPin:n,confirmPin:r,setConfirmPin:i,showPin:a,setShowPin:c,pinLoading:l,pinError:d,pinInputRef:f,confirmPinInputRef:p,setPinFormRef:h,onSubmit:g,operatorName:_,setOperatorName:v}=e;return(0,w.jsx)(`div`,{className:`connect-page`,children:(0,w.jsxs)(`div`,{className:`connect-content`,children:[(0,w.jsx)(`img`,{src:s,alt:u.productName,className:`connect-logo connect-logo--maxy`}),!u.logoContainsName&&(0,w.jsxs)(`h1`,{className:`connect-title`,children:[`Welcome to `,u.productName]}),(0,w.jsxs)(`p`,{className:`connect-subtitle`,children:[`Tell `,u.productName,` who you are, then choose a PIN.`]}),(0,w.jsxs)(`form`,{ref:h,onSubmit:g,className:`connect-pin-form`,children:[(0,w.jsxs)(`div`,{className:`pin-input-row`,children:[(0,w.jsx)(`input`,{type:`text`,className:`connect-name-input`,placeholder:`Your full name`,value:_,onChange:e=>v(e.target.value),autoComplete:`name`,autoFocus:!0,required:!0,"aria-label":`Your full name`}),(0,w.jsx)(`div`,{style:{width:38,flexShrink:0},"aria-hidden":`true`})]}),(0,w.jsxs)(`div`,{className:`pin-input-row`,children:[(0,w.jsx)(T,{inputRef:f,value:t,onChange:n,onComplete:()=>p.current?.focus(),showPin:a}),(0,w.jsx)(`div`,{style:{width:38,flexShrink:0},"aria-hidden":`true`})]}),(0,w.jsxs)(`div`,{className:`pin-input-row`,children:[(0,w.jsx)(T,{inputRef:p,value:r,onChange:i,onComplete:()=>{},showPin:a}),(0,w.jsx)(o,{variant:`send`,type:`submit`,disabled:!t||!r||!_.trim(),loading:l,"aria-label":`Set PIN`,children:(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.jsx)(m,{checked:a,onChange:()=>c(e=>!e),label:`Show PIN`})]}),d&&(0,w.jsx)(`p`,{className:`admin-pin-error`,children:d})]})})}function D(e){let{pin:t,setPin:n,showPin:r,setShowPin:i,pinLoading:a,pinError:c,pinInputRef:l,onSubmit:d,onChangePin:f,remoteAuthEnabled:p,onSignOutRemote:h}=e;return(0,w.jsxs)(`div`,{className:`connect-page`,children:[p&&h&&(0,w.jsx)(`button`,{type:`button`,className:`connect-signout`,onClick:h,children:`Sign out`}),(0,w.jsxs)(`div`,{className:`connect-content`,children:[(0,w.jsx)(`img`,{src:s,alt:u.productName,className:`connect-logo connect-logo--maxy`}),!u.logoContainsName&&(0,w.jsx)(`h1`,{className:`connect-title`,children:u.productName}),(0,w.jsxs)(`form`,{onSubmit:d,className:`connect-pin-form`,children:[(0,w.jsxs)(`div`,{className:`pin-input-row`,children:[(0,w.jsx)(T,{inputRef:l,value:t,onChange:n,onComplete:()=>{},showPin:r,autoFocus:!0}),(0,w.jsx)(o,{variant:`send`,type:`submit`,disabled:!t,loading:a,children:(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:`pin-options`,children:[(0,w.jsx)(m,{checked:r,onChange:()=>i(e=>!e),label:`Show PIN`}),(0,w.jsx)(o,{type:`button`,variant:`ghost`,onClick:f,children:`Change PIN`})]})]}),c&&(0,w.jsx)(`p`,{className:`admin-pin-error`,children:c})]})]})}function O(e){let{accounts:t,loading:n,error:r,onSelect:i}=e;return(0,w.jsx)(`div`,{className:`connect-page`,children:(0,w.jsxs)(`div`,{className:`connect-content`,children:[(0,w.jsx)(`img`,{src:s,alt:u.productName,className:`connect-logo connect-logo--maxy`}),!u.logoContainsName&&(0,w.jsx)(`h1`,{className:`connect-title`,children:u.productName}),(0,w.jsx)(`p`,{className:`connect-subtitle`,children:`Select an account`}),(0,w.jsx)(`div`,{className:`account-picker-list`,children:t.map(e=>(0,w.jsxs)(`button`,{className:`account-picker-card`,onClick:()=>i(e.accountId),disabled:n,type:`button`,children:[(0,w.jsx)(`span`,{className:`account-picker-name`,children:e.businessName||e.accountId}),(0,w.jsx)(`span`,{className:`account-picker-role`,children:e.role}),n&&(0,w.jsx)(d,{className:`account-picker-spinner`,size:16})]},e.accountId))}),r&&(0,w.jsx)(`p`,{className:`admin-pin-error`,children:r})]})})}function k(e){let{authPolling:t,setAuthPolling:n,authLoading:r,setAuthLoading:i,pinError:a,setPinError:c,setAppState:l}=e,[d,f]=(0,g.useState)(!1),[p,m]=(0,g.useState)(!1);async function h(){m(!0),c(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`launch-browser`})})).json();e.launched?f(!0):e.error&&c(e.error)}catch(e){console.error(`[admin] browser launch error:`,e),c(`Could not launch browser.`)}m(!1)}async function _(){i(!0),c(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`})).json();if(e.started){n(!0),f(!0),i(!1);for(let e=0;e<120;e++)if(await new Promise(e=>setTimeout(e,2e3)),(await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`wait`})})).json()).authenticated){await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),l(`enter-pin`);return}c(`Timed out waiting for sign-in. Try again.`),n(!1)}else e.error&&c(e.error)}catch(e){console.error(`[admin] auth flow error:`,e),c(`Could not start auth flow.`)}i(!1)}async function v(){await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),n(!1),c(``)}return t||d?(0,w.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100dvh`,overflow:`auto`},children:[(0,w.jsxs)(`header`,{className:`chat-header`,style:{paddingBottom:`12px`,flexShrink:0,position:`relative`,maxWidth:`680px`,width:`100%`,margin:`0 auto`,padding:`24px 20px 12px`},children:[t?(0,w.jsx)(`button`,{onClick:v,style:{position:`absolute`,top:`12px`,right:`12px`,background:`none`,border:`none`,color:`#999`,fontSize:`13px`,cursor:`pointer`,padding:`4px 8px`},"aria-label":`Cancel`,children:`✕`}):(0,w.jsx)(`button`,{onClick:()=>f(!1),style:{position:`absolute`,top:`12px`,right:`12px`,background:`none`,border:`none`,color:`#999`,fontSize:`13px`,cursor:`pointer`,padding:`4px 8px`},"aria-label":`Close browser`,children:`✕`}),(0,w.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`chat-logo`}),(0,w.jsx)(`h1`,{className:`chat-tagline`,children:`Connect Claude`}),(0,w.jsx)(`p`,{className:`chat-intro`,children:t?`Sign in and authorize in the browser below.`:`Open your email or prepare your accounts, then sign in.`}),!t&&(0,w.jsx)(`div`,{style:{marginTop:`12px`},children:(0,w.jsx)(o,{variant:`primary`,onClick:_,disabled:r,children:r?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`})})]}),(0,w.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,minHeight:0,gap:`10px`,padding:`0 0 16px`},children:(0,w.jsx)(`iframe`,{src:`/vnc-viewer.html`,style:{flex:1,width:`100%`,minHeight:0,border:`none`,background:`#111`,display:`block`},title:`Claude Sign-in`})}),a&&(0,w.jsx)(`p`,{className:`admin-pin-error`,style:{textAlign:`center`,padding:`0 20px 16px`},children:a})]}):(0,w.jsxs)(`div`,{className:`connect-page`,children:[(0,w.jsx)(`button`,{onClick:()=>l(`onboarding-choice`),style:{position:`fixed`,top:`16px`,left:`16px`,background:`none`,border:`none`,color:`#999`,fontSize:`13px`,cursor:`pointer`,padding:`4px 8px`},"aria-label":`Back to setup choice`,children:`← Back`}),(0,w.jsxs)(`div`,{className:`connect-content`,children:[(0,w.jsxs)(`div`,{className:`connect-logos`,children:[(0,w.jsx)(`div`,{className:`connect-logo-wrap`,children:(0,w.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`connect-logo`})}),(0,w.jsx)(`svg`,{className:`connect-arrow`,viewBox:`0 0 48 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,w.jsx)(`path`,{d:`M0 12h44m0 0l-8-8m8 8l-8 8`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}),(0,w.jsxs)(`div`,{className:`connect-logo-wrap`,children:[(0,w.jsx)(`img`,{src:s,alt:u.productName,className:`connect-logo connect-logo--maxy`}),!u.logoContainsName&&(0,w.jsx)(`span`,{className:`connect-logo-label`,children:u.productName})]})]}),(0,w.jsxs)(`h1`,{className:`connect-title`,children:[`Connect Claude to power `,u.productName]}),(0,w.jsx)(`p`,{className:`connect-subtitle`,children:`Sign in with your Anthropic account to get started.`}),(0,w.jsx)(o,{variant:`primary`,onClick:_,disabled:r,children:r?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`}),(0,w.jsx)(`p`,{style:{marginTop:`6px`,fontSize:`11px`,color:`#999`,maxWidth:`300px`,textAlign:`center`,lineHeight:`1.4`},children:`First time? You may need to sign into your email and Anthropic account in the browser before connecting.`}),(0,w.jsx)(`button`,{onClick:h,disabled:p,style:{marginTop:`12px`,background:`none`,border:`none`,color:`var(--color-primary, #666)`,fontSize:`13px`,cursor:`pointer`,textDecoration:`underline`,textUnderlineOffset:`3px`},children:p?`Launching…`:`Open browser first`}),a&&(0,w.jsx)(`p`,{className:`admin-pin-error`,children:a})]})]})}function A({setAppState:e,setOnboardingComplete:t}){let[n,r]=(0,g.useState)(!1),[i,a]=(0,g.useState)(``);async function c(n){r(!0),a(``);try{let r=await fetch(`/api/onboarding/skip`,{method:`POST`,headers:n===`minimal`?{"Content-Type":`application/json`}:{},body:n===`minimal`?JSON.stringify({minimal:!0}):void 0});if(!r.ok){a((await r.json().catch(()=>({}))).error||`Failed to apply defaults.`);return}t(!0),e(`connect-claude`)}catch(e){console.error(`[admin] skip onboarding error:`,e),a(`Could not apply defaults.`)}finally{r(!1)}}function l(){e(`connect-claude`)}return(0,w.jsx)(`div`,{className:`connect-page`,children:(0,w.jsxs)(`div`,{className:`connect-content`,children:[(0,w.jsxs)(`div`,{className:`connect-logo-wrap`,children:[(0,w.jsx)(`img`,{src:s,alt:u.productName,className:`connect-logo connect-logo--maxy`}),!u.logoContainsName&&(0,w.jsx)(`span`,{className:`connect-logo-label`,children:u.productName})]}),(0,w.jsx)(`h1`,{className:`connect-title`,children:`How would you like to get started?`}),(0,w.jsx)(`p`,{className:`connect-subtitle`,style:{fontSize:`0.8rem`,maxWidth:`320px`},children:`Defaults: core plugins only, auto-detected timezone, concise output style, and a minimal personality. No WiFi or optional plugins. Minimal also skips remote access, public-agent API key, and business profile.`}),(0,w.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`10px`,width:`100%`,maxWidth:`320px`,alignItems:`center`},children:[(0,w.jsx)(o,{variant:`primary`,onClick:()=>c(`default`),disabled:n,children:n?`Applying defaults…`:`Use defaults`}),(0,w.jsx)(`button`,{onClick:l,disabled:n,style:{background:`none`,border:`none`,padding:`8px`,cursor:`pointer`,fontSize:`0.95rem`,color:`var(--text-secondary, #666)`,textDecoration:`none`},children:`Guided setup`}),(0,w.jsx)(`button`,{onClick:()=>c(`minimal`),disabled:n,style:{background:`none`,border:`none`,padding:`8px`,cursor:`pointer`,fontSize:`0.95rem`,color:`var(--text-secondary, #666)`,textDecoration:`none`},children:`Minimal`})]}),(0,w.jsx)(`p`,{className:`connect-subtitle`,style:{marginTop:`12px`},children:`You can change any setting later through conversation.`}),i&&(0,w.jsx)(`p`,{className:`admin-pin-error`,children:i})]})})}var ae=(()=>null),j=(0,g.forwardRef)(function(e,t){let{businessName:n,cacheKey:i,role:a,userName:o,userAvatar:s,sessions:m,sessionsLoading:h,sessionsError:_,ensureSessionsLoaded:v,refetchSessions:y,onSelectArtefact:T,onSelectProjects:E,onSelectPeople:D,onSelectTasks:O,onSelectAgents:k,onCloseMobileDrawer:A,collapsed:j,onToggleCollapsed:M,mobileDrawerOpen:N,actions:P,recentsActions:F}=e;(0,g.useEffect)(()=>{v()},[v]);let I=(0,g.useRef)(null),[L,R]=(0,g.useState)(!1),[z,B]=(0,g.useState)(null),oe=u.productName,V=typeof o==`string`?o:o===null?`name unavailable`:n||oe,se=(V.trim().charAt(0)||`?`).toUpperCase(),H=m,U=H.length,[W,G]=(0,g.useState)(`chat`),[K,ce]=(0,g.useState)([]),[q,le]=(0,g.useState)(!1),[J,ue]=(0,g.useState)(null),[de,fe]=(0,g.useState)(!1);(0,g.useImperativeHandle)(t,()=>({patchArtefact(e,t){ce(n=>n.map(n=>n.id===e?{...n,...t}:n))}}),[]);let[Y,X]=(0,g.useState)(!1),Z=(0,g.useRef)(null);(0,g.useEffect)(()=>{if(!Y)return;function e(e){Z.current&&!Z.current.contains(e.target)&&X(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[Y]);let pe=(0,g.useCallback)(async()=>{if(i){fe(!0),ue(null);try{let e=await fetch(`/api/admin/sidebar-artefacts?session_key=${encodeURIComponent(i)}`);if(!e.ok)throw Error(`status ${e.status}`);ce((await e.json()).artefacts??[]),le(!0)}catch(e){let t=e instanceof Error?e.message:String(e);ue(`Failed to load artefacts: ${t}`),console.error(`[admin-ui] sidebar-artefacts fetch failed: ${t}`)}finally{fe(!1)}}},[i]),me=()=>{G(`chat`),console.info(`[admin-ui] sidebar-nav surface=sessions count=${U}`)},he=()=>{G(`artefacts`),console.info(`[admin-ui] sidebar-nav surface=artefacts count=${q?K.length:0} collapsed=${j}`),j&&M(),q||pe()},Q=j?24:16,$=W===`chat`?`Sessions`:`Artefacts`,ge=W===`chat`?h?`…`:String(U):de?`…`:String(K.length),_e=W===`chat`?h:de,ve=()=>{W===`chat`?y():pe(),console.info(`[admin-ui] sidebar-refresh surface=${W}`)},ye=(0,g.useCallback)(async()=>{if(!(L||!i)){R(!0),B(null);try{let e=await fetch(`/api/admin/claude-sessions?session_key=${encodeURIComponent(i)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({channel:`browser`})}),t=await e.json();if(!e.ok||!(`sessionId`in t)){B(t.error??`POST returned ${e.status}`);return}console.info(`[admin-ui] sidebar-new-session pid=${t.pid} sessionId=${t.sessionId}`),F.setSessions(e=>[t,...e])}catch(e){let t=e instanceof Error?e.message:String(e);B(t),console.error(`[admin-ui] sidebar-new-session failed:`,t)}finally{R(!1)}}},[i,L,F]),be=(0,g.useCallback)(async e=>{if(i)try{let t=await fetch(`/api/admin/claude-sessions/resume?session_key=${encodeURIComponent(i)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({claudeSessionId:e,channel:`browser`})}),n=await t.json();if(!t.ok||!(`sessionId`in n)){let e=n.error??`POST returned ${t.status}`;console.error(`[admin-ui] sidebar-resume failed: ${e}`);return}console.info(`[admin-ui] sidebar-resume claudeSessionId=${e} pid=${n.pid} sessionId=${n.sessionId}`),F.setSessions(t=>[n,...t.filter(t=>t.sessionId!==e)])}catch(e){console.error(`[admin-ui] sidebar-resume threw:`,e),F.refetch()}},[i,F]),xe=(0,g.useCallback)(async e=>{F.setSessions(t=>t.filter(t=>t.sessionId!==e));try{let t=await fetch(`/api/admin/claude-sessions/${encodeURIComponent(e)}?session_key=${encodeURIComponent(i)}`,{method:`DELETE`});if(!t.ok){let e=await t.text().catch(()=>``);throw Error(`DELETE ${t.status} ${e.slice(0,200)}`)}console.info(`[admin-ui] sidebar-end-session sessionId=${e}`)}catch(e){console.error(`[admin-ui] sidebar-end-session failed:`,e),F.refetch()}},[i,F]);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:N?`Close sidebar`:j?`Expand sidebar`:`Collapse sidebar`,type:`button`,"aria-label":N?`Close sidebar`:j?`Expand sidebar`:`Collapse sidebar`,onClick:()=>{N?(console.info(`[admin-ui] sidebar-head-toggle action=close-drawer state=closed`),A()):(console.info(`[admin-ui] sidebar-head-toggle action=toggle-collapsed state=${j?`expanded`:`collapsed`}`),M())},children:j?(0,w.jsx)(re,{size:28}):(0,w.jsx)(S,{size:28})})}),(0,w.jsxs)(`nav`,{className:`side-nav`,children:[(0,w.jsxs)(`button`,{type:`button`,className:`nav-row${W===`chat`?` active`:``}`,onClick:me,children:[(0,w.jsx)(C,{size:Q}),(0,w.jsx)(`span`,{className:`label`,children:`Sessions`}),(0,w.jsx)(`span`,{className:`kbd`})]}),(0,w.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=people`),D(),A()},children:[(0,w.jsx)(ie,{size:Q}),(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`),k(),A()},children:[(0,w.jsx)(ee,{size:Q}),(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`),E(),A()},children:[(0,w.jsx)(b,{size:Q}),(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`),O(),A()},children:[(0,w.jsx)(ne,{size:Q}),(0,w.jsx)(`span`,{className:`label`,children:`Tasks`}),(0,w.jsx)(`span`,{className:`kbd`})]}),(0,w.jsxs)(`button`,{type:`button`,className:`nav-row${W===`artefacts`?` active`:``}`,onClick:he,children:[(0,w.jsx)(l,{size:Q}),(0,w.jsx)(`span`,{className:`label`,children:`Artefacts`}),(0,w.jsx)(`span`,{className:`kbd`})]})]}),(0,w.jsxs)(`div`,{className:`side-list`,ref:I,children:[(0,w.jsxs)(`div`,{className:`group-head`,children:[(0,w.jsx)(`span`,{children:$}),(0,w.jsxs)(`span`,{className:`group-head-meta`,children:[W===`chat`&&(0,w.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`New session`,"aria-label":`New session`,onClick:()=>void ye(),disabled:L||!i,children:L?(0,w.jsx)(d,{size:12,className:`spinning`}):(0,w.jsx)(f,{size:12})}),(0,w.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh ${$.toLowerCase()}`,"aria-label":`Refresh ${$.toLowerCase()}`,onClick:ve,disabled:_e,children:(0,w.jsx)(p,{size:12,className:_e?`spinning`:void 0})}),(0,w.jsx)(`span`,{children:ge})]})]}),z&&W===`chat`&&(0,w.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:z}),W===`chat`&&(0,w.jsxs)(w.Fragment,{children:[_&&(0,w.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:_}),H.map(e=>{let t=e.sessionId.slice(0,8),n=e.status===`ended`,i=n?`ended`:`pid ${e.pid??`?`}`;return(0,w.jsxs)(`div`,{className:`conv`,children:[(0,w.jsxs)(`button`,{type:`button`,className:`conv-name-button`,onClick:()=>{if(n){be(e.sessionId),A();return}console.info(`[admin-ui] sidebar-open-session sessionId=${e.sessionId}`),e.url&&window.open(e.url,`_blank`,`noopener,noreferrer`),A()},title:n?`Resume this session`:`Open session in a new tab`,children:[(0,w.jsx)(C,{size:12,className:`conv-channel-icon`,"aria-label":`claude session`}),(0,w.jsxs)(`span`,{className:`conv-name`,children:[t,` · `,i]})]}),n?(0,w.jsx)(`button`,{type:`button`,className:`conversations-action`,title:`Resume session`,"aria-label":`Resume session`,onClick:()=>void be(e.sessionId),children:(0,w.jsx)(c,{size:13})}):(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`button`,{type:`button`,className:`conversations-action`,title:`Open in new tab`,"aria-label":`Open in new tab`,onClick:()=>{console.info(`[admin-ui] sidebar-open-session sessionId=${e.sessionId}`),e.url&&window.open(e.url,`_blank`,`noopener,noreferrer`)},children:(0,w.jsx)(x,{size:13})}),(0,w.jsx)(`button`,{type:`button`,className:`conversations-action`,title:`End session`,"aria-label":`End session`,onClick:()=>void xe(e.sessionId),children:(0,w.jsx)(r,{size:13})})]})]},e.sessionId)})]}),W===`artefacts`&&(0,w.jsxs)(w.Fragment,{children:[J&&(0,w.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:J}),q&&!J&&K.length===0&&(0,w.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No artefacts yet`}),K.map(e=>(0,w.jsxs)(`button`,{type:`button`,className:`conv`,onClick:()=>{T({docId:e.id,name:e.name,content:e.content,editable:e.editable,mimeType:e.mimeType,skipReason:e.skipReason},`sidebar-artefacts`),A()},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:Z,children:[(0,w.jsx)(`div`,{className:`avatar`,children:s?(0,w.jsx)(`img`,{src:s,alt:V}):se}),(0,w.jsxs)(`div`,{className:`who`,children:[(0,w.jsx)(`span`,{className:`name`,children:V}),(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":Y,onClick:()=>X(e=>!e),children:(0,w.jsx)(te,{size:Q})}),Y&&(0,w.jsx)(`div`,{className:`side-foot-actions-popover`,children:(0,w.jsx)(ae,{...P,onAfterAction:()=>X(!1)})})]})]})}),M=`maxy-shell-side-px`;function N(){if(typeof window>`u`)return 0;let e=document.querySelector(`.platform > .artefact`)?.getBoundingClientRect();return e&&e.width>0?Math.round(e.width):0}function P(e){if(typeof window>`u`)return e;let t=window.innerWidth,n=Math.max(248,t-480-N());return Math.min(Math.max(e,248),n)}function F(){if(typeof window>`u`)return 264;try{let e=window.localStorage.getItem(M);if(!e)return 264;let t=parseInt(e,10);if(Number.isFinite(t)&&t>=248)return P(t)}catch{}return 264}function I({targetSelector:e=`.platform`}){let t=(0,g.useRef)(null),[n,r]=(0,g.useState)(()=>F()),i=(0,g.useRef)(n);(0,g.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,g.useCallback)(()=>{r(e=>{let t=P(e);return t===e?e:t})},[]);(0,g.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(P(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(M,String(t))}catch{}console.info(`[admin-ui] sidebar-resize px=${t}`)};window.addEventListener(`pointermove`,o),window.addEventListener(`pointerup`,s)},s=()=>{let e=P(264);r(e);try{window.localStorage.removeItem(M)}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 L(){let e=v(),t=y(e.cacheKey),[n,r]=(0,g.useState)(!1),[i,a]=(0,g.useState)(!1);return e.appState===`loading`?(0,w.jsx)(`div`,{className:`connect-page`}):e.appState===`set-pin`?(0,w.jsx)(E,{pin:e.pin,setPin:e.setPin,confirmPin:e.confirmPin,setConfirmPin:e.setConfirmPin,showPin:e.showPin,setShowPin:e.setShowPin,pinLoading:e.pinLoading,pinError:e.pinError,pinInputRef:e.pinInputRef,confirmPinInputRef:e.confirmPinInputRef,setPinFormRef:e.setPinFormRef,onSubmit:e.handleSetPin,operatorName:e.operatorName,setOperatorName:e.setOperatorName}):e.appState===`onboarding-choice`?(0,w.jsx)(A,{setAppState:e.setAppState,setOnboardingComplete:e.setOnboardingComplete}):e.appState===`connect-claude`?(0,w.jsx)(k,{authPolling:e.authPolling,setAuthPolling:e.setAuthPolling,authLoading:e.authLoading,setAuthLoading:e.setAuthLoading,pinError:e.pinError,setPinError:e.setPinError,setAppState:e.setAppState}):e.appState===`enter-pin`?(0,w.jsx)(D,{pin:e.pin,setPin:e.setPin,showPin:e.showPin,setShowPin:e.setShowPin,pinLoading:e.pinLoading,pinError:e.pinError,pinInputRef:e.pinInputRef,onSubmit:e.handleLogin,onChangePin:e.handleChangePin,remoteAuthEnabled:e.remoteAuthEnabled,onSignOutRemote:e.handleLogout}):e.appState===`account-picker`?(0,w.jsx)(O,{accounts:e.accounts,loading:e.accountPickerLoading,error:e.pinError,onSelect:e.handleAccountSelect}):(0,w.jsxs)(`div`,{className:`platform${i?` menu-open`:``}${n?` sidebar-collapsed`:``}`,children:[(0,w.jsx)(j,{businessName:e.businessName,cacheKey:e.cacheKey,role:e.role,userName:e.userName,userAvatar:e.userAvatar,sessions:t.sessions,sessionsLoading:t.loading,sessionsError:t.error,ensureSessionsLoaded:t.ensureLoaded,refetchSessions:t.refetch,onSelectArtefact:e=>{},onSelectProjects:()=>{window.location.href=`/graph?label=Project`},onSelectPeople:()=>{window.location.href=`/graph?label=Person`},onSelectTasks:()=>{window.location.href=`/graph?label=Task`},onSelectAgents:()=>{window.location.href=`/graph?label=Agent`},onCloseMobileDrawer:()=>a(!1),collapsed:n,onToggleCollapsed:()=>r(e=>!e),mobileDrawerOpen:i,actions:{},recentsActions:{setSessions:t.setSessions,refetch:t.refetch}}),(0,w.jsx)(I,{})]})}(0,h.createRoot)(document.getElementById(`root`)).render((0,w.jsx)(L,{}));
@@ -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-Jg-kYJ64.js"></script>
8
+ <script type="module" crossorigin src="/assets/admin-d9iNQ85D.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-LncohCxF.js">
11
11
  <link rel="modulepreload" crossorigin href="/assets/brand-29DyfElX.js">
@@ -1 +0,0 @@
1
- import{o as e}from"./chunk-DD-I1_y5.js";import{a as t,i as n,n as r,r as i,t as a}from"./jsx-runtime-LncohCxF.js";import{a as o,i as s,o as c,s as l,t as u}from"./brand-29DyfElX.js";import{t as d}from"./loader-circle-DwwVih2K.js";import{n as f,t as p}from"./refresh-cw-Ho-xY4LQ.js";import{t as m}from"./Checkbox-D5bsL5IO.js";var h=n(),g=e(t(),1);new Set(`image/jpeg,image/png,image/gif,image/webp,application/pdf,text/plain,text/markdown,text/csv,text/html,text/calendar,application/zip,application/x-zip-compressed,audio/ogg,audio/opus,audio/mp4,audio/mpeg,audio/webm,audio/wav,.opus,.ogg,.m4a,.mp3,.wav,.webm`.split(`,`).filter(e=>!e.startsWith(`.`)));function _(e){switch(e){case`expanded`:return!0;case`collapsed`:return!1;default:return}}function v(){let[e,t]=(0,g.useState)(`loading`),[n,r]=(0,g.useState)(``),[i,a]=(0,g.useState)(``),[o,s]=(0,g.useState)(``),[c,l]=(0,g.useState)(``),[u,d]=(0,g.useState)(!1),[f,p]=(0,g.useState)(!1),[m,h]=(0,g.useState)(!1),[v,y]=(0,g.useState)(!1),[ee,b]=(0,g.useState)(!1),[te,x]=(0,g.useState)(null),[ne,S]=(0,g.useState)(null),[C,w]=(0,g.useState)(void 0),[re,T]=(0,g.useState)(void 0),[E,D]=(0,g.useState)(null),[O,k]=(0,g.useState)(void 0),[A,j]=(0,g.useState)(null),[ie,M]=(0,g.useState)(null),[N,P]=(0,g.useState)([]),[F,I]=(0,g.useState)(!1),[ae,L]=(0,g.useState)(void 0),R=(0,g.useRef)(void 0),[z,B]=(0,g.useState)(!1);(0,g.useEffect)(()=>{typeof window>`u`||window.location.hostname.startsWith(`admin.`)&&fetch(`/api/remote-auth/status`).then(e=>e.ok?e.json():null).then(e=>{e?.configured&&B(!0)}).catch(()=>{})},[]);let oe=(0,g.useRef)(null),V=(0,g.useRef)(null),se=(0,g.useRef)(null);(0,g.useEffect)(()=>{async function e(){let e=null;try{e=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!e)return!1;try{let n=await fetch(`/api/admin/session?session_key=${encodeURIComponent(e)}`);if(n.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}return!1}if(!n.ok)return!1;let r=await n.json();x(r.session_key),M(r.conversationId??null),w(r.onboardingComplete),T(r.businessName),D(r.role??null),k(r.userName===void 0?null:r.userName),j(r.avatar??null);let i=_(r.thinkingView);return R.current=i,L(i),t(`chat`),!0}catch(e){return console.error(`[admin] session restore failed:`,e),!1}}async function n(r=2){try{let i=await fetch(`/api/health`);if(!i.ok){if(r>0)return await new Promise(e=>setTimeout(e,1500)),n(r-1);console.error(`[admin] health check returned ${i.status} after retries`),t(`set-pin`);return}let a=await i.json();if(!a.pin_configured){t(`set-pin`);return}if(a.onboarding_complete===!1){t(`onboarding-choice`);return}if(!a.claude_authenticated){t(`connect-claude`);return}if(await e())return;t(`enter-pin`)}catch(e){if(r>0)return await new Promise(e=>setTimeout(e,1500)),n(r-1);console.error(`[admin] health check failed:`,e),t(`set-pin`)}}n()},[]),(0,g.useEffect)(()=>{e===`chat`&&fetch(`/api/admin/claude-info`).then(e=>{if(e.ok)return e.json()}).then(e=>{e&&S(e)}).catch(()=>{})},[e]),(0,g.useEffect)(()=>{if(e!==`chat`)return;let n=setInterval(async()=>{try{let e=await fetch(`/api/health`);if(!e.ok)return;let n=await e.json();(n.auth_status===`dead`||n.auth_status===`missing`)&&t(`connect-claude`)}catch{}},300*1e3);return()=>clearInterval(n)},[e]),(0,g.useEffect)(()=>{e===`connect-claude`&&fetch(`/api/health`).then(e=>e.ok?e.json():null).then(e=>{e?.claude_authenticated&&t(`enter-pin`)}).catch(()=>{})},[e]);async function H(e,n){p(!0);try{let i=await fetch(`/api/admin/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:e,...n?{accountId:n}:{}})});if(!i.ok){l((await i.json().catch(()=>({}))).error||`Invalid PIN`);return}let o=await i.json();if(o.accounts&&!o.session_key){console.log(`[admin] account picker shown: userId=${o.userId} accountCount=${o.accounts.length}`),P(o.accounts),t(`account-picker`);return}x(o.session_key),M(o.conversationId??null),w(o.onboardingComplete??!0),T(o.businessName),D(o.role??null),k(o.userName===void 0?null:o.userName),j(o.avatar??null);let s=_(o.thinkingView);if(R.current=s,L(s),n)try{sessionStorage.setItem(`maxy-account-id`,n)}catch{}try{sessionStorage.setItem(`maxy-admin-session-key`,o.session_key)}catch{}r(``),a(``),t(`chat`)}catch(e){console.error(`[admin] connection error:`,e),l(`Could not connect.`)}finally{p(!1),I(!1)}}let U=(0,g.useCallback)(async e=>{if(e.preventDefault(),f)return;l(``);let s=o.trim();if(!s){l(`Please enter your name.`);return}if(n.length<4){l(`PIN must be at least 4 characters.`);return}if(n!==i){l(`PINs do not match.`);return}let c=n;p(!0);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:c,name:s})});if(!e.ok){let n=await e.json().catch(()=>({}));if(e.status===409){console.log(`[admin] PIN already configured — re-checking health`);try{let e=await fetch(`/api/health`);if(e.ok){let r=await e.json();r.pin_configured&&r.claude_authenticated?t(`enter-pin`):r.pin_configured?t(`connect-claude`):l(n.error||`Failed to set PIN.`)}else t(`enter-pin`)}catch{t(`enter-pin`)}return}l(n.error||`Failed to set PIN.`);return}let n=await fetch(`/api/health`),i=n.ok?await n.json():null;if(i?.onboarding_complete===!1){r(``),a(``),t(`onboarding-choice`);return}if(i?.claude_authenticated){await H(c);return}r(``),a(``),t(`onboarding-choice`)}catch(e){console.error(`[admin] connection error:`,e),l(`Could not connect.`)}finally{p(!1)}},[n,i,f,o]),W=(0,g.useCallback)(async e=>{e.preventDefault(),l(``),await H(n)},[n]),G=(0,g.useCallback)(async()=>{b(!0);try{await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`logout`})}),x(null),D(null),k(void 0),j(null);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}t(`connect-claude`)}finally{b(!1)}},[]),K=(0,g.useCallback)(()=>{x(null),D(null),k(void 0),j(null);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}r(``),a(``),l(``),t(`enter-pin`)},[]);return{appState:e,setAppState:t,pin:n,setPin:r,confirmPin:i,setConfirmPin:a,operatorName:o,setOperatorName:s,pinError:c,setPinError:l,showPin:u,setShowPin:d,pinLoading:f,authPolling:m,setAuthPolling:h,authLoading:v,setAuthLoading:y,disconnecting:ee,cacheKey:te,setCacheKey:x,claudeInfo:ne,setClaudeInfo:S,onboardingComplete:C,setOnboardingComplete:w,businessName:re,role:E,userName:O,userAvatar:A,conversationId:ie,setConversationId:M,accounts:N,accountPickerLoading:F,expandAll:ae,setExpandAll:L,expandAllDefaultRef:R,remoteAuthEnabled:z,pinInputRef:oe,confirmPinInputRef:V,setPinFormRef:se,handleSetPin:U,handleLogin:W,handleAccountSelect:(0,g.useCallback)(async e=>{I(!0),l(``),await H(n,e)},[n]),handleDisconnect:G,handleLogout:K,handleChangePin:(0,g.useCallback)(async()=>{if(!n){l(`Enter your current PIN first.`);return}p(!0),l(``);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify({currentPin:n})});if(!e.ok){l((await e.json().catch(()=>({error:`Incorrect PIN.`}))).error||`Incorrect PIN.`);return}r(``),a(``),l(``),t(`set-pin`)}catch(e){console.error(`[admin-auth] change pin failed:`,e),l(e instanceof Error?e.message:String(e))}finally{p(!1)}},[n])}}function y(e){let[t,n]=(0,g.useState)([]),[r,i]=(0,g.useState)(!1),[a,o]=(0,g.useState)(null),[s,c]=(0,g.useState)(null),l=(0,g.useCallback)(async t=>{if(e&&!(!t&&s===e)){i(!0),o(null);try{let t=await fetch(`/api/admin/claude-sessions?session_key=${encodeURIComponent(e)}`);if(!t.ok)throw Error(`claude-sessions fetch returned ${t.status}`);let r=await t.json();n(Array.isArray(r)?r:r.sessions??[]),c(e)}catch(e){console.error(`[admin/claude-sessions] fetch failed:`,e),o(e instanceof Error?e.message:String(e))}finally{i(!1)}}},[e,s]);(0,g.useEffect)(()=>{e||(c(null),n([]),o(null))},[e]);let u=(0,g.useCallback)(()=>l(!1),[l]),d=(0,g.useCallback)(()=>l(!0),[l]),f=(0,g.useRef)(d);return(0,g.useEffect)(()=>{f.current=d},[d]),(0,g.useEffect)(()=>{if(!e)return;let t=setInterval(()=>{f.current()},3e3);return()=>clearInterval(t)},[e]),{sessions:t,setSessions:n,loading:r,loaded:s!==null&&s===e,error:a,ensureLoaded:u,refetch:d}}var ee=i(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),b=i(`box`,[[`path`,{d:`M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z`,key:`hh9hay`}],[`path`,{d:`m3.3 7 8.7 5 8.7-5`,key:`g66t2b`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}]]),te=i(`ellipsis-vertical`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]]),x=i(`external-link`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]),ne=i(`list-todo`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),S=i(`panel-left-close`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`m16 15-3-3 3-3`,key:`14y99z`}]]),C=i(`panel-left-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`m14 9 3 3-3 3`,key:`8010ee`}]]),w=i(`terminal`,[[`path`,{d:`M12 19h8`,key:`baeox8`}],[`path`,{d:`m4 17 6-6-6-6`,key:`1yngyt`}]]),re=i(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),T=a();function E({inputRef:e,value:t,onChange:n,onComplete:r,showPin:i,autoFocus:a}){let o=(0,g.useRef)([]);function s(e,r){r.key===`Backspace`?(r.preventDefault(),t[e]?n(t.slice(0,e)+t.slice(e+1)):e>0&&(n(t.slice(0,e-1)+t.slice(e)),o.current[e-1]?.focus())):r.key===`ArrowLeft`&&e>0?o.current[e-1]?.focus():r.key===`ArrowRight`&&e<5?o.current[e+1]?.focus():r.key===`Enter`&&(r.preventDefault(),r.currentTarget.form?.requestSubmit())}function c(e,i){let a=i.nativeEvent.data;if(!a||!/^\d$/.test(a))return;let s=t.split(``);for(s[e]=a;s.length<e;)s.push(``);let c=s.join(``).replace(/\D/g,``).slice(0,6);n(c),c.length===6?r?.(c):e<5&&o.current[e+1]?.focus()}function l(e){e.preventDefault();let t=e.clipboardData.getData(`text`).replace(/\D/g,``).slice(0,6);t&&(n(t),t.length===6?r?.(t):o.current[t.length]?.focus())}return(0,T.jsx)(`div`,{className:`pin-field`,children:Array.from({length:6}).map((n,r)=>(0,T.jsx)(`input`,{ref:t=>{o.current[r]=t,r===0&&e&&(e.current=t)},type:`text`,inputMode:`numeric`,className:`pin-box${t[r]?` pin-box-filled`:``}`,value:t[r]?i?t[r]:`•`:``,onKeyDown:e=>s(r,e),onInput:e=>c(r,e),onPaste:l,onFocus:e=>e.target.select(),autoFocus:a&&r===0,autoComplete:`off`,maxLength:1,"aria-label":`PIN digit ${r+1}`},r))})}function D(e){let{pin:t,setPin:n,confirmPin:r,setConfirmPin:i,showPin:a,setShowPin:c,pinLoading:l,pinError:d,pinInputRef:f,confirmPinInputRef:p,setPinFormRef:h,onSubmit:g,operatorName:_,setOperatorName:v}=e;return(0,T.jsx)(`div`,{className:`connect-page`,children:(0,T.jsxs)(`div`,{className:`connect-content`,children:[(0,T.jsx)(`img`,{src:s,alt:u.productName,className:`connect-logo connect-logo--maxy`}),!u.logoContainsName&&(0,T.jsxs)(`h1`,{className:`connect-title`,children:[`Welcome to `,u.productName]}),(0,T.jsxs)(`p`,{className:`connect-subtitle`,children:[`Tell `,u.productName,` who you are, then choose a PIN.`]}),(0,T.jsxs)(`form`,{ref:h,onSubmit:g,className:`connect-pin-form`,children:[(0,T.jsxs)(`div`,{className:`pin-input-row`,children:[(0,T.jsx)(`input`,{type:`text`,className:`connect-name-input`,placeholder:`Your full name`,value:_,onChange:e=>v(e.target.value),autoComplete:`name`,autoFocus:!0,required:!0,"aria-label":`Your full name`}),(0,T.jsx)(`div`,{style:{width:38,flexShrink:0},"aria-hidden":`true`})]}),(0,T.jsxs)(`div`,{className:`pin-input-row`,children:[(0,T.jsx)(E,{inputRef:f,value:t,onChange:n,onComplete:()=>p.current?.focus(),showPin:a}),(0,T.jsx)(`div`,{style:{width:38,flexShrink:0},"aria-hidden":`true`})]}),(0,T.jsxs)(`div`,{className:`pin-input-row`,children:[(0,T.jsx)(E,{inputRef:p,value:r,onChange:i,onComplete:()=>{},showPin:a}),(0,T.jsx)(o,{variant:`send`,type:`submit`,disabled:!t||!r||!_.trim(),loading:l,"aria-label":`Set PIN`,children:(0,T.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,T.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,T.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,T.jsx)(m,{checked:a,onChange:()=>c(e=>!e),label:`Show PIN`})]}),d&&(0,T.jsx)(`p`,{className:`admin-pin-error`,children:d})]})})}function O(e){let{pin:t,setPin:n,showPin:r,setShowPin:i,pinLoading:a,pinError:c,pinInputRef:l,onSubmit:d,onChangePin:f,remoteAuthEnabled:p,onSignOutRemote:h}=e;return(0,T.jsxs)(`div`,{className:`connect-page`,children:[p&&h&&(0,T.jsx)(`button`,{type:`button`,className:`connect-signout`,onClick:h,children:`Sign out`}),(0,T.jsxs)(`div`,{className:`connect-content`,children:[(0,T.jsx)(`img`,{src:s,alt:u.productName,className:`connect-logo connect-logo--maxy`}),!u.logoContainsName&&(0,T.jsx)(`h1`,{className:`connect-title`,children:u.productName}),(0,T.jsxs)(`form`,{onSubmit:d,className:`connect-pin-form`,children:[(0,T.jsxs)(`div`,{className:`pin-input-row`,children:[(0,T.jsx)(E,{inputRef:l,value:t,onChange:n,onComplete:()=>{},showPin:r,autoFocus:!0}),(0,T.jsx)(o,{variant:`send`,type:`submit`,disabled:!t,loading:a,children:(0,T.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,T.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,T.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,T.jsxs)(`div`,{className:`pin-options`,children:[(0,T.jsx)(m,{checked:r,onChange:()=>i(e=>!e),label:`Show PIN`}),(0,T.jsx)(o,{type:`button`,variant:`ghost`,onClick:f,children:`Change PIN`})]})]}),c&&(0,T.jsx)(`p`,{className:`admin-pin-error`,children:c})]})]})}function k(e){let{accounts:t,loading:n,error:r,onSelect:i}=e;return(0,T.jsx)(`div`,{className:`connect-page`,children:(0,T.jsxs)(`div`,{className:`connect-content`,children:[(0,T.jsx)(`img`,{src:s,alt:u.productName,className:`connect-logo connect-logo--maxy`}),!u.logoContainsName&&(0,T.jsx)(`h1`,{className:`connect-title`,children:u.productName}),(0,T.jsx)(`p`,{className:`connect-subtitle`,children:`Select an account`}),(0,T.jsx)(`div`,{className:`account-picker-list`,children:t.map(e=>(0,T.jsxs)(`button`,{className:`account-picker-card`,onClick:()=>i(e.accountId),disabled:n,type:`button`,children:[(0,T.jsx)(`span`,{className:`account-picker-name`,children:e.businessName||e.accountId}),(0,T.jsx)(`span`,{className:`account-picker-role`,children:e.role}),n&&(0,T.jsx)(d,{className:`account-picker-spinner`,size:16})]},e.accountId))}),r&&(0,T.jsx)(`p`,{className:`admin-pin-error`,children:r})]})})}function A(e){let{authPolling:t,setAuthPolling:n,authLoading:r,setAuthLoading:i,pinError:a,setPinError:c,setAppState:l}=e,[d,f]=(0,g.useState)(!1),[p,m]=(0,g.useState)(!1);async function h(){m(!0),c(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`launch-browser`})})).json();e.launched?f(!0):e.error&&c(e.error)}catch(e){console.error(`[admin] browser launch error:`,e),c(`Could not launch browser.`)}m(!1)}async function _(){i(!0),c(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`})).json();if(e.started){n(!0),f(!0),i(!1);for(let e=0;e<120;e++)if(await new Promise(e=>setTimeout(e,2e3)),(await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`wait`})})).json()).authenticated){await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),l(`enter-pin`);return}c(`Timed out waiting for sign-in. Try again.`),n(!1)}else e.error&&c(e.error)}catch(e){console.error(`[admin] auth flow error:`,e),c(`Could not start auth flow.`)}i(!1)}async function v(){await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),n(!1),c(``)}return t||d?(0,T.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100dvh`,overflow:`auto`},children:[(0,T.jsxs)(`header`,{className:`chat-header`,style:{paddingBottom:`12px`,flexShrink:0,position:`relative`,maxWidth:`680px`,width:`100%`,margin:`0 auto`,padding:`24px 20px 12px`},children:[t?(0,T.jsx)(`button`,{onClick:v,style:{position:`absolute`,top:`12px`,right:`12px`,background:`none`,border:`none`,color:`#999`,fontSize:`13px`,cursor:`pointer`,padding:`4px 8px`},"aria-label":`Cancel`,children:`✕`}):(0,T.jsx)(`button`,{onClick:()=>f(!1),style:{position:`absolute`,top:`12px`,right:`12px`,background:`none`,border:`none`,color:`#999`,fontSize:`13px`,cursor:`pointer`,padding:`4px 8px`},"aria-label":`Close browser`,children:`✕`}),(0,T.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`chat-logo`}),(0,T.jsx)(`h1`,{className:`chat-tagline`,children:`Connect Claude`}),(0,T.jsx)(`p`,{className:`chat-intro`,children:t?`Sign in and authorize in the browser below.`:`Open your email or prepare your accounts, then sign in.`}),!t&&(0,T.jsx)(`div`,{style:{marginTop:`12px`},children:(0,T.jsx)(o,{variant:`primary`,onClick:_,disabled:r,children:r?(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`})})]}),(0,T.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,minHeight:0,gap:`10px`,padding:`0 0 16px`},children:(0,T.jsx)(`iframe`,{src:`/vnc-viewer.html`,style:{flex:1,width:`100%`,minHeight:0,border:`none`,background:`#111`,display:`block`},title:`Claude Sign-in`})}),a&&(0,T.jsx)(`p`,{className:`admin-pin-error`,style:{textAlign:`center`,padding:`0 20px 16px`},children:a})]}):(0,T.jsxs)(`div`,{className:`connect-page`,children:[(0,T.jsx)(`button`,{onClick:()=>l(`onboarding-choice`),style:{position:`fixed`,top:`16px`,left:`16px`,background:`none`,border:`none`,color:`#999`,fontSize:`13px`,cursor:`pointer`,padding:`4px 8px`},"aria-label":`Back to setup choice`,children:`← Back`}),(0,T.jsxs)(`div`,{className:`connect-content`,children:[(0,T.jsxs)(`div`,{className:`connect-logos`,children:[(0,T.jsx)(`div`,{className:`connect-logo-wrap`,children:(0,T.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`connect-logo`})}),(0,T.jsx)(`svg`,{className:`connect-arrow`,viewBox:`0 0 48 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,T.jsx)(`path`,{d:`M0 12h44m0 0l-8-8m8 8l-8 8`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}),(0,T.jsxs)(`div`,{className:`connect-logo-wrap`,children:[(0,T.jsx)(`img`,{src:s,alt:u.productName,className:`connect-logo connect-logo--maxy`}),!u.logoContainsName&&(0,T.jsx)(`span`,{className:`connect-logo-label`,children:u.productName})]})]}),(0,T.jsxs)(`h1`,{className:`connect-title`,children:[`Connect Claude to power `,u.productName]}),(0,T.jsx)(`p`,{className:`connect-subtitle`,children:`Sign in with your Anthropic account to get started.`}),(0,T.jsx)(o,{variant:`primary`,onClick:_,disabled:r,children:r?(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`}),(0,T.jsx)(`p`,{style:{marginTop:`6px`,fontSize:`11px`,color:`#999`,maxWidth:`300px`,textAlign:`center`,lineHeight:`1.4`},children:`First time? You may need to sign into your email and Anthropic account in the browser before connecting.`}),(0,T.jsx)(`button`,{onClick:h,disabled:p,style:{marginTop:`12px`,background:`none`,border:`none`,color:`var(--color-primary, #666)`,fontSize:`13px`,cursor:`pointer`,textDecoration:`underline`,textUnderlineOffset:`3px`},children:p?`Launching…`:`Open browser first`}),a&&(0,T.jsx)(`p`,{className:`admin-pin-error`,children:a})]})]})}function j({setAppState:e,setOnboardingComplete:t}){let[n,r]=(0,g.useState)(!1),[i,a]=(0,g.useState)(``);async function c(n){r(!0),a(``);try{let r=await fetch(`/api/onboarding/skip`,{method:`POST`,headers:n===`minimal`?{"Content-Type":`application/json`}:{},body:n===`minimal`?JSON.stringify({minimal:!0}):void 0});if(!r.ok){a((await r.json().catch(()=>({}))).error||`Failed to apply defaults.`);return}t(!0),e(`connect-claude`)}catch(e){console.error(`[admin] skip onboarding error:`,e),a(`Could not apply defaults.`)}finally{r(!1)}}function l(){e(`connect-claude`)}return(0,T.jsx)(`div`,{className:`connect-page`,children:(0,T.jsxs)(`div`,{className:`connect-content`,children:[(0,T.jsxs)(`div`,{className:`connect-logo-wrap`,children:[(0,T.jsx)(`img`,{src:s,alt:u.productName,className:`connect-logo connect-logo--maxy`}),!u.logoContainsName&&(0,T.jsx)(`span`,{className:`connect-logo-label`,children:u.productName})]}),(0,T.jsx)(`h1`,{className:`connect-title`,children:`How would you like to get started?`}),(0,T.jsx)(`p`,{className:`connect-subtitle`,style:{fontSize:`0.8rem`,maxWidth:`320px`},children:`Defaults: core plugins only, auto-detected timezone, concise output style, and a minimal personality. No WiFi or optional plugins. Minimal also skips remote access, public-agent API key, and business profile.`}),(0,T.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,gap:`10px`,width:`100%`,maxWidth:`320px`,alignItems:`center`},children:[(0,T.jsx)(o,{variant:`primary`,onClick:()=>c(`default`),disabled:n,children:n?`Applying defaults…`:`Use defaults`}),(0,T.jsx)(`button`,{onClick:l,disabled:n,style:{background:`none`,border:`none`,padding:`8px`,cursor:`pointer`,fontSize:`0.95rem`,color:`var(--text-secondary, #666)`,textDecoration:`none`},children:`Guided setup`}),(0,T.jsx)(`button`,{onClick:()=>c(`minimal`),disabled:n,style:{background:`none`,border:`none`,padding:`8px`,cursor:`pointer`,fontSize:`0.95rem`,color:`var(--text-secondary, #666)`,textDecoration:`none`},children:`Minimal`})]}),(0,T.jsx)(`p`,{className:`connect-subtitle`,style:{marginTop:`12px`},children:`You can change any setting later through conversation.`}),i&&(0,T.jsx)(`p`,{className:`admin-pin-error`,children:i})]})})}var ie=(()=>null),M=(0,g.forwardRef)(function(e,t){let{businessName:n,cacheKey:i,role:a,userName:o,userAvatar:s,sessions:m,sessionsLoading:h,sessionsError:_,ensureSessionsLoaded:v,refetchSessions:y,onSelectArtefact:E,onSelectProjects:D,onSelectPeople:O,onSelectTasks:k,onSelectAgents:A,onCloseMobileDrawer:j,collapsed:M,onToggleCollapsed:N,mobileDrawerOpen:P,actions:F,recentsActions:I}=e;(0,g.useEffect)(()=>{v()},[v]);let ae=(0,g.useRef)(null),[L,R]=(0,g.useState)(!1),[z,B]=(0,g.useState)(null),oe=u.productName,V=typeof o==`string`?o:o===null?`name unavailable`:n||oe,se=(V.trim().charAt(0)||`?`).toUpperCase(),H=m,U=H.length,[W,G]=(0,g.useState)(`chat`),[K,ce]=(0,g.useState)([]),[q,le]=(0,g.useState)(!1),[J,ue]=(0,g.useState)(null),[de,fe]=(0,g.useState)(!1);(0,g.useImperativeHandle)(t,()=>({patchArtefact(e,t){ce(n=>n.map(n=>n.id===e?{...n,...t}:n))}}),[]);let[Y,X]=(0,g.useState)(!1),Z=(0,g.useRef)(null);(0,g.useEffect)(()=>{if(!Y)return;function e(e){Z.current&&!Z.current.contains(e.target)&&X(!1)}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[Y]);let pe=(0,g.useCallback)(async()=>{if(i){fe(!0),ue(null);try{let e=await fetch(`/api/admin/sidebar-artefacts?session_key=${encodeURIComponent(i)}`);if(!e.ok)throw Error(`status ${e.status}`);ce((await e.json()).artefacts??[]),le(!0)}catch(e){let t=e instanceof Error?e.message:String(e);ue(`Failed to load artefacts: ${t}`),console.error(`[admin-ui] sidebar-artefacts fetch failed: ${t}`)}finally{fe(!1)}}},[i]),me=()=>{G(`chat`),console.info(`[admin-ui] sidebar-nav surface=sessions count=${U}`)},he=()=>{G(`artefacts`),console.info(`[admin-ui] sidebar-nav surface=artefacts count=${q?K.length:0} collapsed=${M}`),M&&N(),q||pe()},Q=M?24:16,$=W===`chat`?`Sessions`:`Artefacts`,ge=W===`chat`?h?`…`:String(U):de?`…`:String(K.length),_e=W===`chat`?h:de,ve=()=>{W===`chat`?y():pe(),console.info(`[admin-ui] sidebar-refresh surface=${W}`)},ye=(0,g.useCallback)(async()=>{if(!(L||!i)){R(!0),B(null);try{let e=await fetch(`/api/admin/claude-sessions?session_key=${encodeURIComponent(i)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({channel:`browser`})}),t=await e.json();if(!e.ok||!(`sessionId`in t)){B(t.error??`POST returned ${e.status}`);return}console.info(`[admin-ui] sidebar-new-session pid=${t.pid} sessionId=${t.sessionId}`),I.setSessions(e=>[t,...e])}catch(e){let t=e instanceof Error?e.message:String(e);B(t),console.error(`[admin-ui] sidebar-new-session failed:`,t)}finally{R(!1)}}},[i,L,I]),be=(0,g.useCallback)(async e=>{if(i)try{let t=await fetch(`/api/admin/claude-sessions/resume?session_key=${encodeURIComponent(i)}`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({claudeSessionId:e,channel:`browser`})}),n=await t.json();if(!t.ok||!(`sessionId`in n)){let e=n.error??`POST returned ${t.status}`;console.error(`[admin-ui] sidebar-resume failed: ${e}`);return}console.info(`[admin-ui] sidebar-resume claudeSessionId=${e} pid=${n.pid} sessionId=${n.sessionId}`),I.setSessions(t=>[n,...t.filter(t=>t.sessionId!==e)])}catch(e){console.error(`[admin-ui] sidebar-resume threw:`,e),I.refetch()}},[i,I]),xe=(0,g.useCallback)(async e=>{I.setSessions(t=>t.filter(t=>t.sessionId!==e));try{let t=await fetch(`/api/admin/claude-sessions/${encodeURIComponent(e)}?session_key=${encodeURIComponent(i)}`,{method:`DELETE`});if(!t.ok){let e=await t.text().catch(()=>``);throw Error(`DELETE ${t.status} ${e.slice(0,200)}`)}console.info(`[admin-ui] sidebar-end-session sessionId=${e}`)}catch(e){console.error(`[admin-ui] sidebar-end-session failed:`,e),I.refetch()}},[i,I]);return(0,T.jsxs)(`aside`,{className:`side`,children:[(0,T.jsx)(`div`,{className:`side-head`,children:(0,T.jsx)(`button`,{className:`icon-btn side-head-toggle`,title:P?`Close sidebar`:M?`Expand sidebar`:`Collapse sidebar`,type:`button`,"aria-label":P?`Close sidebar`:M?`Expand sidebar`:`Collapse sidebar`,onClick:()=>{P?(console.info(`[admin-ui] sidebar-head-toggle action=close-drawer state=closed`),j()):(console.info(`[admin-ui] sidebar-head-toggle action=toggle-collapsed state=${M?`expanded`:`collapsed`}`),N())},children:M?(0,T.jsx)(C,{size:28}):(0,T.jsx)(S,{size:28})})}),(0,T.jsxs)(`nav`,{className:`side-nav`,children:[(0,T.jsxs)(`button`,{type:`button`,className:`nav-row${W===`chat`?` active`:``}`,onClick:me,children:[(0,T.jsx)(w,{size:Q}),(0,T.jsx)(`span`,{className:`label`,children:`Sessions`}),(0,T.jsx)(`span`,{className:`kbd`})]}),(0,T.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=people`),O(),j()},children:[(0,T.jsx)(re,{size:Q}),(0,T.jsx)(`span`,{className:`label`,children:`People`}),(0,T.jsx)(`span`,{className:`kbd`})]}),(0,T.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=agents`),A(),j()},children:[(0,T.jsx)(ee,{size:Q}),(0,T.jsx)(`span`,{className:`label`,children:`Agents`}),(0,T.jsx)(`span`,{className:`kbd`})]}),(0,T.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=projects`),D(),j()},children:[(0,T.jsx)(b,{size:Q}),(0,T.jsx)(`span`,{className:`label`,children:`Projects`}),(0,T.jsx)(`span`,{className:`kbd`})]}),(0,T.jsxs)(`button`,{type:`button`,className:`nav-row`,onClick:()=>{console.info(`[admin-ui] sidebar-nav surface=tasks`),k(),j()},children:[(0,T.jsx)(ne,{size:Q}),(0,T.jsx)(`span`,{className:`label`,children:`Tasks`}),(0,T.jsx)(`span`,{className:`kbd`})]}),(0,T.jsxs)(`button`,{type:`button`,className:`nav-row${W===`artefacts`?` active`:``}`,onClick:he,children:[(0,T.jsx)(l,{size:Q}),(0,T.jsx)(`span`,{className:`label`,children:`Artefacts`}),(0,T.jsx)(`span`,{className:`kbd`})]})]}),(0,T.jsxs)(`div`,{className:`side-list`,ref:ae,children:[(0,T.jsxs)(`div`,{className:`group-head`,children:[(0,T.jsx)(`span`,{children:$}),(0,T.jsxs)(`span`,{className:`group-head-meta`,children:[W===`chat`&&(0,T.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`New session`,"aria-label":`New session`,onClick:()=>void ye(),disabled:L||!i,children:L?(0,T.jsx)(d,{size:12,className:`spinning`}):(0,T.jsx)(f,{size:12})}),(0,T.jsx)(`button`,{type:`button`,className:`group-head-refresh`,title:`Refresh ${$.toLowerCase()}`,"aria-label":`Refresh ${$.toLowerCase()}`,onClick:ve,disabled:_e,children:(0,T.jsx)(p,{size:12,className:_e?`spinning`:void 0})}),(0,T.jsx)(`span`,{children:ge})]})]}),z&&W===`chat`&&(0,T.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:z}),W===`chat`&&(0,T.jsxs)(T.Fragment,{children:[_&&(0,T.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:_}),H.map(e=>{let t=e.sessionId.slice(0,8),n=e.status===`ended`,i=n?`ended`:`pid ${e.pid??`?`}`;return(0,T.jsxs)(`div`,{className:`conv`,children:[(0,T.jsxs)(`button`,{type:`button`,className:`conv-name-button`,onClick:()=>{if(n){be(e.sessionId),j();return}console.info(`[admin-ui] sidebar-open-session sessionId=${e.sessionId}`),e.url&&window.open(e.url,`_blank`,`noopener,noreferrer`),j()},title:n?`Resume this session`:`Open session in a new tab`,children:[(0,T.jsx)(w,{size:12,className:`conv-channel-icon`,"aria-label":`claude session`}),(0,T.jsxs)(`span`,{className:`conv-name`,children:[t,` · `,i]})]}),n?(0,T.jsx)(`button`,{type:`button`,className:`conversations-action`,title:`Resume session`,"aria-label":`Resume session`,onClick:()=>void be(e.sessionId),children:(0,T.jsx)(c,{size:13})}):(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(`button`,{type:`button`,className:`conversations-action`,title:`Open in new tab`,"aria-label":`Open in new tab`,onClick:()=>{console.info(`[admin-ui] sidebar-open-session sessionId=${e.sessionId}`),e.url&&window.open(e.url,`_blank`,`noopener,noreferrer`)},children:(0,T.jsx)(x,{size:13})}),(0,T.jsx)(`button`,{type:`button`,className:`conversations-action`,title:`End session`,"aria-label":`End session`,onClick:()=>void xe(e.sessionId),children:(0,T.jsx)(r,{size:13})})]})]},e.sessionId)})]}),W===`artefacts`&&(0,T.jsxs)(T.Fragment,{children:[J&&(0,T.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:J}),q&&!J&&K.length===0&&(0,T.jsx)(`div`,{className:`conv`,style:{color:`var(--text-tertiary)`,cursor:`default`},children:`No artefacts yet`}),K.map(e=>(0,T.jsxs)(`button`,{type:`button`,className:`conv`,onClick:()=>{E({docId:e.id,name:e.name,content:e.content,editable:e.editable,mimeType:e.mimeType,skipReason:e.skipReason},`sidebar-artefacts`),j()},children:[(0,T.jsx)(`span`,{className:`conv-name`,children:e.name}),(0,T.jsx)(`span`,{className:`conv-kind`,"data-kind":e.kind===`agent-template`?`agent`:`doc`,children:e.kind===`agent-template`?`agent`:`doc`})]},e.id))]})]}),(0,T.jsxs)(`div`,{className:`side-foot`,ref:Z,children:[(0,T.jsx)(`div`,{className:`avatar`,children:s?(0,T.jsx)(`img`,{src:s,alt:V}):se}),(0,T.jsxs)(`div`,{className:`who`,children:[(0,T.jsx)(`span`,{className:`name`,children:V}),(0,T.jsx)(`span`,{className:`role`,children:a??`operator`})]}),(0,T.jsx)(`button`,{className:`icon-btn side-foot-actions-trigger`,title:`Conversation actions`,type:`button`,"aria-label":`Conversation actions`,"aria-haspopup":`true`,"aria-expanded":Y,onClick:()=>X(e=>!e),children:(0,T.jsx)(te,{size:Q})}),Y&&(0,T.jsx)(`div`,{className:`side-foot-actions-popover`,children:(0,T.jsx)(ie,{...F,onAfterAction:()=>X(!1)})})]})]})});function N(){let e=v(),t=y(e.cacheKey),[n,r]=(0,g.useState)(!1),[i,a]=(0,g.useState)(!1);return e.appState===`loading`?(0,T.jsx)(`div`,{className:`connect-page`}):e.appState===`set-pin`?(0,T.jsx)(D,{pin:e.pin,setPin:e.setPin,confirmPin:e.confirmPin,setConfirmPin:e.setConfirmPin,showPin:e.showPin,setShowPin:e.setShowPin,pinLoading:e.pinLoading,pinError:e.pinError,pinInputRef:e.pinInputRef,confirmPinInputRef:e.confirmPinInputRef,setPinFormRef:e.setPinFormRef,onSubmit:e.handleSetPin,operatorName:e.operatorName,setOperatorName:e.setOperatorName}):e.appState===`onboarding-choice`?(0,T.jsx)(j,{setAppState:e.setAppState,setOnboardingComplete:e.setOnboardingComplete}):e.appState===`connect-claude`?(0,T.jsx)(A,{authPolling:e.authPolling,setAuthPolling:e.setAuthPolling,authLoading:e.authLoading,setAuthLoading:e.setAuthLoading,pinError:e.pinError,setPinError:e.setPinError,setAppState:e.setAppState}):e.appState===`enter-pin`?(0,T.jsx)(O,{pin:e.pin,setPin:e.setPin,showPin:e.showPin,setShowPin:e.setShowPin,pinLoading:e.pinLoading,pinError:e.pinError,pinInputRef:e.pinInputRef,onSubmit:e.handleLogin,onChangePin:e.handleChangePin,remoteAuthEnabled:e.remoteAuthEnabled,onSignOutRemote:e.handleLogout}):e.appState===`account-picker`?(0,T.jsx)(k,{accounts:e.accounts,loading:e.accountPickerLoading,error:e.pinError,onSelect:e.handleAccountSelect}):(0,T.jsx)(`div`,{className:`platform${i?` menu-open`:``}${n?` sidebar-collapsed`:``}`,children:(0,T.jsx)(M,{businessName:e.businessName,cacheKey:e.cacheKey,role:e.role,userName:e.userName,userAvatar:e.userAvatar,sessions:t.sessions,sessionsLoading:t.loading,sessionsError:t.error,ensureSessionsLoaded:t.ensureLoaded,refetchSessions:t.refetch,onSelectArtefact:e=>{},onSelectProjects:()=>{window.location.href=`/graph?label=Project`},onSelectPeople:()=>{window.location.href=`/graph?label=Person`},onSelectTasks:()=>{window.location.href=`/graph?label=Task`},onSelectAgents:()=>{window.location.href=`/graph?label=Agent`},onCloseMobileDrawer:()=>a(!1),collapsed:n,onToggleCollapsed:()=>r(e=>!e),mobileDrawerOpen:i,actions:{},recentsActions:{setSessions:t.setSessions,refetch:t.refetch}})})}(0,h.createRoot)(document.getElementById(`root`)).render((0,T.jsx)(N,{}));