@rubytech/create-maxy-code 0.1.228 → 0.1.230
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/plugins/admin/mcp/dist/index.js +9 -20
- package/payload/platform/plugins/admin/mcp/dist/index.js.map +1 -1
- package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +33 -1
- package/payload/platform/plugins/admin/skills/qr-code/SKILL.md +6 -5
- package/payload/platform/plugins/admin/skills/qr-code/references/data-formats.md +2 -2
- package/payload/platform/plugins/admin/skills/unzip-attachment/SKILL.md +1 -1
- package/payload/platform/plugins/cloudflare/references/dashboard-guide.md +28 -0
- package/payload/platform/plugins/cloudflare/references/serving-published-sites.md +73 -0
- package/payload/platform/plugins/cloudflare/skills/setup-tunnel/SKILL.md +1 -1
- package/payload/platform/plugins/docs/references/troubleshooting.md +32 -0
- package/payload/platform/services/claude-session-manager/dist/http-server.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/http-server.js +29 -4
- package/payload/platform/services/claude-session-manager/dist/http-server.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/rc-daemon.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/rc-daemon.js +5 -2
- package/payload/platform/services/claude-session-manager/dist/rc-daemon.js.map +1 -1
- package/payload/server/public/assets/AdminShell-D_eg2QKE.js +1 -0
- package/payload/server/public/assets/{admin-CE1Dy8-O.js → admin-BKawc0eQ.js} +1 -1
- package/payload/server/public/assets/data-JoiWCmz6.js +1 -0
- package/payload/server/public/assets/graph-DmOvqjTa.js +51 -0
- package/payload/server/public/data.html +2 -2
- package/payload/server/public/graph.html +2 -2
- package/payload/server/public/index.html +2 -2
- package/payload/server/public/assets/AdminShell-BHSiRGiE.js +0 -1
- package/payload/server/public/assets/data-CKk52rib.js +0 -1
- package/payload/server/public/assets/graph-TuzretIr.js +0 -51
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./chunk-DD-I1_y5.js";import{a as t,d as n,o as r,t as i,u as a}from"./brand-Dmpzr6Qq.js";import{a as o,r as s,t as c,u as l}from"./AdminShell-BHSiRGiE.js";import{t as u}from"./Checkbox-CfE7p1Tv.js";import{r as d,t as f}from"./useSelectionMode-BbLqtKTJ.js";var p=a(),m=e(n(),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 h(e){switch(e){case`expanded`:return!0;case`collapsed`:return!1;default:return}}var g=`admin-landing-redirected`,_=`/graph`;function v(e){return e.appState===`chat`&&!e.alreadyRedirected}function y(){let[e,t]=(0,m.useState)(`loading`),[n,r]=(0,m.useState)(``),[i,a]=(0,m.useState)(``),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)(!1),[u,d]=(0,m.useState)(!1),[f,p]=(0,m.useState)(!1),[y,b]=(0,m.useState)(!1),[x,S]=(0,m.useState)(!1),[C,w]=(0,m.useState)(null),[T,E]=(0,m.useState)(null),[D,O]=(0,m.useState)(void 0),[k,A]=(0,m.useState)(null),[j,M]=(0,m.useState)(void 0),[N,P]=(0,m.useState)(null),[F,I]=(0,m.useState)(null),[L,R]=(0,m.useState)([]),[z,B]=(0,m.useState)(!1),[V,H]=(0,m.useState)(void 0),U=(0,m.useRef)(void 0),[W,G]=(0,m.useState)(!1);(0,m.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&&G(!0)}).catch(()=>{})},[]);let K=(0,m.useRef)(null),q=(0,m.useRef)(null);(0,m.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();w(r.session_key),I(r.sessionId??null),O(r.businessName),A(r.role??null),M(r.userName===void 0?null:r.userName),P(r.avatar??null);let i=h(r.thinkingView);return U.current=i,H(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.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,m.useEffect)(()=>{e===`chat`&&fetch(`/api/admin/claude-info`).then(e=>{if(e.ok)return e.json()}).then(e=>{e&&E(e)}).catch(()=>{})},[e]),(0,m.useEffect)(()=>{if(typeof window>`u`)return;let t=!1;try{t=sessionStorage.getItem(g)===`1`}catch{}if(v({appState:e,alreadyRedirected:t})){try{sessionStorage.setItem(g,`1`)}catch{}console.info(`[admin-ui] landing-redirect target=${_}`),window.location.replace(_)}},[e]);let J=(0,m.useRef)(null);(0,m.useEffect)(()=>{if(e!==`chat`)return;let n=setInterval(async()=>{try{let e=await fetch(`/api/health`);if(e.ok){let n=await e.json();if(n.auth_status===`dead`||n.auth_status===`missing`){t(`connect-claude`);return}}}catch{}if(C)try{let e=await fetch(`/api/admin/session?session_key=${encodeURIComponent(C)}`);if(e.status!==401)return;let t=(await e.clone().json().catch(()=>null))?.code??`unknown-401`;console.warn(`[admin-auth] outcome=heartbeat-detected-expiry code=${t}`),J.current?.()}catch{}},300*1e3);return()=>clearInterval(n)},[e,C]),(0,m.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 Y(e,n){d(!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){s((await i.json().catch(()=>({}))).error||`Invalid PIN`);return}let a=await i.json();if(a.accounts&&!a.session_key){console.log(`[admin] account picker shown: userId=${a.userId} accountCount=${a.accounts.length}`),R(a.accounts),t(`account-picker`);return}w(a.session_key),I(a.sessionId??null),O(a.businessName),A(a.role??null),M(a.userName===void 0?null:a.userName),P(a.avatar??null);let o=h(a.thinkingView);if(U.current=o,H(o),n)try{sessionStorage.setItem(`maxy-account-id`,n)}catch{}try{sessionStorage.setItem(`maxy-admin-session-key`,a.session_key)}catch{}r(``),t(`chat`)}catch(e){console.error(`[admin] connection error:`,e),s(`Could not connect.`)}finally{d(!1),B(!1)}}let X=(0,m.useCallback)(async e=>{if(e.preventDefault(),u)return;s(``);let a=i.trim();if(!a){s(`Please enter your name.`);return}if(n.length<4){s(`PIN must be at least 4 characters.`);return}let o=n;d(!0);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:o,name:a})});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`):s(n.error||`Failed to set PIN.`)}else t(`enter-pin`)}catch{t(`enter-pin`)}return}s(n.error||`Failed to set PIN.`);return}let n=await fetch(`/api/health`);if((n.ok?await n.json():null)?.claude_authenticated){await Y(o);return}r(``),t(`connect-claude`)}catch(e){console.error(`[admin] connection error:`,e),s(`Could not connect.`)}finally{d(!1)}},[n,u,i]),Z=(0,m.useCallback)(async e=>{e.preventDefault(),s(``),await Y(n)},[n]),Q=(0,m.useCallback)(async()=>{S(!0);try{await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`logout`})}),w(null),A(null),M(void 0),P(null);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}t(`connect-claude`)}finally{S(!1)}},[]),$=(0,m.useCallback)(()=>{w(null),A(null),M(void 0),P(null);try{sessionStorage.removeItem(`maxy-admin-session-key`),sessionStorage.removeItem(`maxy-account-id`),sessionStorage.removeItem(g)}catch{}r(``),s(``),t(`enter-pin`)},[]);return(0,m.useEffect)(()=>{J.current=$},[$]),{appState:e,setAppState:t,pin:n,setPin:r,operatorName:i,setOperatorName:a,pinError:o,setPinError:s,showPin:c,setShowPin:l,pinLoading:u,authPolling:f,setAuthPolling:p,authLoading:y,setAuthLoading:b,disconnecting:x,cacheKey:C,setCacheKey:w,claudeInfo:T,setClaudeInfo:E,businessName:D,role:k,userName:j,userAvatar:N,sessionId:F,setSessionId:I,accounts:L,accountPickerLoading:z,expandAll:V,setExpandAll:H,expandAllDefaultRef:U,remoteAuthEnabled:W,pinInputRef:K,setPinFormRef:q,handleSetPin:X,handleLogin:Z,handleAccountSelect:(0,m.useCallback)(async e=>{B(!0),s(``),await Y(n,e)},[n]),handleDisconnect:Q,handleLogout:$,handleChangePin:(0,m.useCallback)(async()=>{if(!n){s(`Enter your current PIN first.`);return}d(!0),s(``);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify({currentPin:n})});if(!e.ok){s((await e.json().catch(()=>({error:`Incorrect PIN.`}))).error||`Incorrect PIN.`);return}r(``),s(``),t(`set-pin`)}catch(e){console.error(`[admin-auth] change pin failed:`,e),s(e instanceof Error?e.message:String(e))}finally{d(!1)}},[n])}}var b=r();function x({inputRef:e,value:t,onChange:n,onComplete:r,showPin:i,autoFocus:a}){let o=(0,m.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,b.jsx)(`div`,{className:`pin-field`,children:Array.from({length:6}).map((n,r)=>(0,b.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 S(e){let{pin:n,setPin:r,showPin:a,setShowPin:o,pinLoading:s,pinError:c,pinInputRef:l,setPinFormRef:f,onSubmit:p,operatorName:m,setOperatorName:h}=e;return(0,b.jsx)(`div`,{className:`connect-page`,children:(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsx)(`img`,{src:t,alt:i.productName,className:`connect-logo connect-logo--maxy`}),!i.logoContainsName&&(0,b.jsxs)(`h1`,{className:`connect-title`,children:[`Welcome to `,i.productName]}),(0,b.jsxs)(`p`,{className:`connect-subtitle`,children:[`Tell `,i.productName,` who you are, then choose a PIN.`]}),(0,b.jsxs)(`form`,{ref:f,onSubmit:p,className:`connect-pin-form`,children:[(0,b.jsxs)(`div`,{className:`pin-input-row`,children:[(0,b.jsx)(`input`,{type:`text`,className:`connect-name-input`,placeholder:`Your full name`,value:m,onChange:e=>h(e.target.value),autoComplete:`name`,autoFocus:!0,required:!0,"aria-label":`Your full name`}),(0,b.jsx)(`div`,{style:{width:38,flexShrink:0},"aria-hidden":`true`})]}),(0,b.jsxs)(`div`,{className:`pin-input-row`,children:[(0,b.jsx)(x,{inputRef:l,value:n,onChange:r,onComplete:()=>{},showPin:a}),(0,b.jsx)(d,{variant:`send`,type:`submit`,disabled:!n||!m.trim(),loading:s,"aria-label":`Set PIN`,children:(0,b.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,b.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,b.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,b.jsx)(u,{checked:a,onChange:()=>o(e=>!e),label:`Show PIN`})]}),c&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:c})]})})}function C(e){let{pin:n,setPin:r,showPin:a,setShowPin:o,pinLoading:s,pinError:c,pinInputRef:l,onSubmit:f,onChangePin:p,remoteAuthEnabled:m,onSignOutRemote:h}=e;return(0,b.jsxs)(`div`,{className:`connect-page`,children:[m&&h&&(0,b.jsx)(`button`,{type:`button`,className:`connect-signout`,onClick:h,children:`Sign out`}),(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsx)(`img`,{src:t,alt:i.productName,className:`connect-logo connect-logo--maxy`}),!i.logoContainsName&&(0,b.jsx)(`h1`,{className:`connect-title`,children:i.productName}),(0,b.jsxs)(`form`,{onSubmit:f,className:`connect-pin-form`,children:[(0,b.jsxs)(`div`,{className:`pin-input-row`,children:[(0,b.jsx)(x,{inputRef:l,value:n,onChange:r,onComplete:()=>{},showPin:a,autoFocus:!0}),(0,b.jsx)(d,{variant:`send`,type:`submit`,disabled:!n,loading:s,children:(0,b.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,b.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,b.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,b.jsxs)(`div`,{className:`pin-options`,children:[(0,b.jsx)(u,{checked:a,onChange:()=>o(e=>!e),label:`Show PIN`}),(0,b.jsx)(d,{type:`button`,variant:`ghost`,onClick:p,children:`Change PIN`})]})]}),c&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:c})]})]})}function w(e){let{accounts:n,loading:r,error:a,onSelect:o}=e;return(0,b.jsx)(`div`,{className:`connect-page`,children:(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsx)(`img`,{src:t,alt:i.productName,className:`connect-logo connect-logo--maxy`}),!i.logoContainsName&&(0,b.jsx)(`h1`,{className:`connect-title`,children:i.productName}),(0,b.jsx)(`p`,{className:`connect-subtitle`,children:`Select an account`}),(0,b.jsx)(`div`,{className:`account-picker-list`,children:n.map(e=>(0,b.jsxs)(`button`,{className:`account-picker-card`,onClick:()=>o(e.accountId),disabled:r,type:`button`,children:[(0,b.jsx)(`span`,{className:`account-picker-name`,children:e.businessName||e.accountId}),(0,b.jsx)(`span`,{className:`account-picker-role`,children:e.role}),r&&(0,b.jsx)(l,{className:`account-picker-spinner`,size:16})]},e.accountId))}),a&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:a})]})})}function T(e){let{authPolling:n,setAuthPolling:r,authLoading:a,setAuthLoading:o,pinError:s,setPinError:c,setAppState:l}=e,[u,f]=(0,m.useState)(!1),[p,h]=(0,m.useState)(!1);async function g(){h(!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.`)}h(!1)}async function _(){o(!0),c(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`})).json();if(e.started){r(!0),f(!0),o(!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.`),r(!1)}else e.error&&c(e.error)}catch(e){console.error(`[admin] auth flow error:`,e),c(`Could not start auth flow.`)}o(!1)}async function v(){await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),r(!1),c(``)}return n||u?(0,b.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100dvh`,overflow:`auto`},children:[(0,b.jsxs)(`header`,{className:`chat-header`,style:{paddingBottom:`12px`,flexShrink:0,position:`relative`,maxWidth:`680px`,width:`100%`,margin:`0 auto`,padding:`24px 20px 12px`},children:[n?(0,b.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,b.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,b.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`chat-logo`}),(0,b.jsx)(`h1`,{className:`chat-tagline`,children:`Connect Claude`}),(0,b.jsx)(`p`,{className:`chat-intro`,children:n?`Sign in and authorize in the browser below.`:`Open your email or prepare your accounts, then sign in.`}),!n&&(0,b.jsx)(`div`,{style:{marginTop:`12px`},children:(0,b.jsx)(d,{variant:`primary`,onClick:_,disabled:a,children:a?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`})})]}),(0,b.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,minHeight:0,gap:`10px`,padding:`0 0 16px`},children:(0,b.jsx)(`iframe`,{src:`/vnc-viewer.html`,style:{flex:1,width:`100%`,minHeight:0,border:`none`,background:`#111`,display:`block`},title:`Claude Sign-in`})}),s&&(0,b.jsx)(`p`,{className:`admin-pin-error`,style:{textAlign:`center`,padding:`0 20px 16px`},children:s})]}):(0,b.jsx)(`div`,{className:`connect-page`,children:(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsxs)(`div`,{className:`connect-logos`,children:[(0,b.jsx)(`div`,{className:`connect-logo-wrap`,children:(0,b.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`connect-logo`})}),(0,b.jsx)(`svg`,{className:`connect-arrow`,viewBox:`0 0 48 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,b.jsx)(`path`,{d:`M0 12h44m0 0l-8-8m8 8l-8 8`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}),(0,b.jsxs)(`div`,{className:`connect-logo-wrap`,children:[(0,b.jsx)(`img`,{src:t,alt:i.productName,className:`connect-logo connect-logo--maxy`}),!i.logoContainsName&&(0,b.jsx)(`span`,{className:`connect-logo-label`,children:i.productName})]})]}),(0,b.jsxs)(`h1`,{className:`connect-title`,children:[`Connect Claude to power `,i.productName]}),(0,b.jsx)(`p`,{className:`connect-subtitle`,children:`Sign in with your Anthropic account to get started.`}),(0,b.jsx)(d,{variant:`primary`,onClick:_,disabled:a,children:a?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`}),(0,b.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,b.jsx)(`button`,{onClick:g,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`}),s&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:s})]})})}function E({onOpen:e}){return(0,b.jsx)(`footer`,{className:`admin-footer`,children:(0,b.jsxs)(`div`,{className:`powered-by`,role:`button`,tabIndex:0,onClick:e,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),e())},"aria-label":`Powered by Claude Code — show details`,children:[(0,b.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`powered-by-icon`}),(0,b.jsx)(`span`,{children:`Powered by Claude Code`})]})})}function D(e){if(e<60)return`${e}s`;let t=Math.floor(e/60),n=e%60;return n>0?`${t}m ${n}s`:`${t}m`}function O(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function k(e){let{show:t,onClose:n,claudeInfo:r,messages:i,sessionElapsed:a,sessionId:o,cacheKey:s}=e,[c,l]=(0,m.useState)(null);if(!t)return null;let u=i.flatMap(e=>e.events?.filter(e=>e.type===`usage`)??[]),d=u.at(-1),p=d?.peak_request_pct==null?d?.context_window?Math.round((d.input_tokens+d.cache_creation_tokens+d.cache_read_tokens)/d.context_window*100):0:Math.round(d.peak_request_pct*100),h=u.reduce((e,t)=>e+t.input_tokens+t.cache_creation_tokens+t.cache_read_tokens+t.output_tokens,0),g=i.flatMap(e=>e.events?.filter(e=>e.type===`rate_limit`)??[]).at(-1),_=u.reduce((e,t)=>e+(t.total_cost_usd??0),0),v=r?.account?.subscriptionType,y=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,b.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,b.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,b.jsxs)(`div`,{className:`claude-info-header`,children:[(0,b.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`claude-info-icon`}),(0,b.jsx)(`span`,{children:`Claude Code`}),(0,b.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,b.jsxs)(`div`,{className:`claude-info-section`,children:[(0,b.jsxs)(`div`,{className:`claude-info-row`,children:[(0,b.jsx)(`span`,{className:`claude-info-label`,children:`Version`}),(0,b.jsx)(`span`,{className:`claude-info-value`,children:r?r.version:`…`})]}),(0,b.jsxs)(`div`,{className:`claude-info-row`,children:[(0,b.jsx)(`span`,{className:`claude-info-label`,children:`Email`}),(0,b.jsx)(`span`,{className:`claude-info-value`,children:r?.account?.email??`…`})]})]}),(v||g||_>0)&&(0,b.jsxs)(`div`,{className:`claude-info-section`,children:[v&&(0,b.jsxs)(`div`,{className:`claude-info-row`,children:[(0,b.jsx)(`span`,{className:`claude-info-label`,children:`Plan`}),(0,b.jsx)(`span`,{className:`claude-info-value`,style:{textTransform:`capitalize`},children:v})]}),g&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(`div`,{className:`claude-info-row`,children:[(0,b.jsx)(`span`,{className:`claude-info-label`,children:`Usage`}),(0,b.jsxs)(`span`,{className:`claude-info-value`,children:[Math.round(g.utilization*100),`%`]})]}),(0,b.jsxs)(`div`,{className:`claude-info-row`,children:[(0,b.jsx)(`span`,{className:`claude-info-label`,children:`Resets in`}),(0,b.jsx)(`span`,{className:`claude-info-value`,children:y(g.resetsAt)})]}),g.isUsingOverage&&(0,b.jsxs)(`div`,{className:`claude-info-row`,children:[(0,b.jsx)(`span`,{className:`claude-info-label`,children:`Overage`}),(0,b.jsx)(`span`,{className:`claude-info-value`,children:`Active`})]})]}),_>0&&(0,b.jsxs)(`div`,{className:`claude-info-row`,children:[(0,b.jsx)(`span`,{className:`claude-info-label`,children:`Session cost`}),(0,b.jsxs)(`span`,{className:`claude-info-value`,children:[`$`,_<.01?_.toFixed(4):_.toFixed(2)]})]})]}),(0,b.jsxs)(`div`,{className:`claude-info-section`,children:[(0,b.jsxs)(`div`,{className:`claude-info-row`,children:[(0,b.jsx)(`span`,{className:`claude-info-label`,children:`Model`}),(0,b.jsx)(`span`,{className:`claude-info-value`,children:r?.model??`…`})]}),(0,b.jsxs)(`div`,{className:`claude-info-row`,children:[(0,b.jsx)(`span`,{className:`claude-info-label`,children:`Context used`}),(0,b.jsx)(`span`,{className:`claude-info-value`,children:p>0?`${p}%`:`—`})]}),(0,b.jsxs)(`div`,{className:`claude-info-row`,children:[(0,b.jsx)(`span`,{className:`claude-info-label`,children:`Tokens`}),(0,b.jsx)(`span`,{className:`claude-info-value`,children:h>0?O(h):`—`})]}),(0,b.jsxs)(`div`,{className:`claude-info-row`,children:[(0,b.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,b.jsx)(`span`,{className:`claude-info-value`,children:D(a)})]}),(o||s)&&(()=>{let e=o??s??``;return(0,b.jsxs)(`div`,{className:`claude-info-row`,children:[(0,b.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,b.jsx)(`button`,{type:`button`,className:`claude-info-value claude-info-id-copy`,title:`${e} (${o?`flushed`:`pre-flush`}) — click to copy`,onClick:async()=>{l(await f(e)?`copied`:`failed`),setTimeout(()=>l(null),1200)},children:c===`copied`?`copied ✓`:c===`failed`?`copy failed ✕`:`${e.slice(0,8)}…`})]})})()]})]})})}function A(){let e=y(),[t,n]=(0,m.useState)(!1);(0,m.useEffect)(()=>{if(!t)return;let e=e=>{e.key===`Escape`&&n(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let r=(0,m.useCallback)(async()=>{let t=e.claudeInfo!=null;if(n(!0),t){console.info(`[admin-ui] claude-info-open cached=true ms=0`);return}let r=Date.now();try{let t=await fetch(`/api/admin/claude-info`);if(t.ok){let n=await t.json();e.setClaudeInfo(n)}console.info(`[admin-ui] claude-info-open cached=false ms=${Date.now()-r}`)}catch(e){console.error(`[admin-ui] claude-info-fetch-failed ms=${Date.now()-r} error="${e instanceof Error?e.message:String(e)}"`)}},[e]),i=(0,m.useCallback)(({code:t,path:n})=>{console.warn(`[admin-auth] outcome=chat-tab-logout-on-401 code=${t} path=${n}`),e.handleLogout()},[e]);return e.appState===`loading`?(0,b.jsx)(`div`,{className:`connect-page`}):e.appState===`set-pin`?(0,b.jsx)(S,{pin:e.pin,setPin:e.setPin,showPin:e.showPin,setShowPin:e.setShowPin,pinLoading:e.pinLoading,pinError:e.pinError,pinInputRef:e.pinInputRef,setPinFormRef:e.setPinFormRef,onSubmit:e.handleSetPin,operatorName:e.operatorName,setOperatorName:e.setOperatorName}):e.appState===`connect-claude`?(0,b.jsx)(T,{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,b.jsx)(C,{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,b.jsx)(w,{accounts:e.accounts,loading:e.accountPickerLoading,error:e.pinError,onSelect:e.handleAccountSelect}):(0,b.jsx)(s,{cacheKey:e.cacheKey,onSessionExpired:i,surface:`chat`,children:(0,b.jsx)(c,{cacheKey:e.cacheKey,businessName:e.businessName,sessionId:e.sessionId,onLogout:e.handleLogout,userName:e.userName,userAvatar:e.userAvatar,role:e.role,footer:(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(E,{onOpen:r}),(0,b.jsx)(k,{show:t,onClose:()=>n(!1),claudeInfo:e.claudeInfo,messages:[],sessionElapsed:0,sessionId:e.sessionId,cacheKey:e.cacheKey})]}),children:()=>(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(o,{}),(0,b.jsx)(`main`,{})]})})})}(0,p.createRoot)(document.getElementById(`root`)).render((0,b.jsx)(A,{}));
|
|
1
|
+
import{o as e}from"./chunk-DD-I1_y5.js";import{a as t,d as n,o as r,t as i,u as a}from"./brand-Dmpzr6Qq.js";import{a as o,r as s,t as c,u as l}from"./AdminShell-D_eg2QKE.js";import{t as u}from"./Checkbox-CfE7p1Tv.js";import{r as d,t as f}from"./useSelectionMode-BbLqtKTJ.js";var p=a(),m=e(n(),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 h(e){switch(e){case`expanded`:return!0;case`collapsed`:return!1;default:return}}var g=`admin-landing-redirected`,_=`/graph`;function v(e){return e.appState===`chat`&&!e.alreadyRedirected}function y(){let[e,t]=(0,m.useState)(`loading`),[n,r]=(0,m.useState)(``),[i,a]=(0,m.useState)(``),[o,s]=(0,m.useState)(``),[c,l]=(0,m.useState)(!1),[u,d]=(0,m.useState)(!1),[f,p]=(0,m.useState)(!1),[y,b]=(0,m.useState)(!1),[x,S]=(0,m.useState)(!1),[C,w]=(0,m.useState)(null),[T,E]=(0,m.useState)(null),[D,O]=(0,m.useState)(void 0),[k,A]=(0,m.useState)(null),[j,M]=(0,m.useState)(void 0),[N,P]=(0,m.useState)(null),[F,I]=(0,m.useState)(null),[L,R]=(0,m.useState)([]),[z,B]=(0,m.useState)(!1),[V,H]=(0,m.useState)(void 0),U=(0,m.useRef)(void 0),[W,G]=(0,m.useState)(!1);(0,m.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&&G(!0)}).catch(()=>{})},[]);let K=(0,m.useRef)(null),q=(0,m.useRef)(null);(0,m.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();w(r.session_key),I(r.sessionId??null),O(r.businessName),A(r.role??null),M(r.userName===void 0?null:r.userName),P(r.avatar??null);let i=h(r.thinkingView);return U.current=i,H(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.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,m.useEffect)(()=>{e===`chat`&&fetch(`/api/admin/claude-info`).then(e=>{if(e.ok)return e.json()}).then(e=>{e&&E(e)}).catch(()=>{})},[e]),(0,m.useEffect)(()=>{if(typeof window>`u`)return;let t=!1;try{t=sessionStorage.getItem(g)===`1`}catch{}if(v({appState:e,alreadyRedirected:t})){try{sessionStorage.setItem(g,`1`)}catch{}console.info(`[admin-ui] landing-redirect target=${_}`),window.location.replace(_)}},[e]);let J=(0,m.useRef)(null);(0,m.useEffect)(()=>{if(e!==`chat`)return;let n=setInterval(async()=>{try{let e=await fetch(`/api/health`);if(e.ok){let n=await e.json();if(n.auth_status===`dead`||n.auth_status===`missing`){t(`connect-claude`);return}}}catch{}if(C)try{let e=await fetch(`/api/admin/session?session_key=${encodeURIComponent(C)}`);if(e.status!==401)return;let t=(await e.clone().json().catch(()=>null))?.code??`unknown-401`;console.warn(`[admin-auth] outcome=heartbeat-detected-expiry code=${t}`),J.current?.()}catch{}},300*1e3);return()=>clearInterval(n)},[e,C]),(0,m.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 Y(e,n){d(!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){s((await i.json().catch(()=>({}))).error||`Invalid PIN`);return}let a=await i.json();if(a.accounts&&!a.session_key){console.log(`[admin] account picker shown: userId=${a.userId} accountCount=${a.accounts.length}`),R(a.accounts),t(`account-picker`);return}w(a.session_key),I(a.sessionId??null),O(a.businessName),A(a.role??null),M(a.userName===void 0?null:a.userName),P(a.avatar??null);let o=h(a.thinkingView);if(U.current=o,H(o),n)try{sessionStorage.setItem(`maxy-account-id`,n)}catch{}try{sessionStorage.setItem(`maxy-admin-session-key`,a.session_key)}catch{}r(``),t(`chat`)}catch(e){console.error(`[admin] connection error:`,e),s(`Could not connect.`)}finally{d(!1),B(!1)}}let X=(0,m.useCallback)(async e=>{if(e.preventDefault(),u)return;s(``);let a=i.trim();if(!a){s(`Please enter your name.`);return}if(n.length<4){s(`PIN must be at least 4 characters.`);return}let o=n;d(!0);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:o,name:a})});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`):s(n.error||`Failed to set PIN.`)}else t(`enter-pin`)}catch{t(`enter-pin`)}return}s(n.error||`Failed to set PIN.`);return}let n=await fetch(`/api/health`);if((n.ok?await n.json():null)?.claude_authenticated){await Y(o);return}r(``),t(`connect-claude`)}catch(e){console.error(`[admin] connection error:`,e),s(`Could not connect.`)}finally{d(!1)}},[n,u,i]),Z=(0,m.useCallback)(async e=>{e.preventDefault(),s(``),await Y(n)},[n]),Q=(0,m.useCallback)(async()=>{S(!0);try{await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`logout`})}),w(null),A(null),M(void 0),P(null);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}t(`connect-claude`)}finally{S(!1)}},[]),$=(0,m.useCallback)(()=>{w(null),A(null),M(void 0),P(null);try{sessionStorage.removeItem(`maxy-admin-session-key`),sessionStorage.removeItem(`maxy-account-id`),sessionStorage.removeItem(g)}catch{}r(``),s(``),t(`enter-pin`)},[]);return(0,m.useEffect)(()=>{J.current=$},[$]),{appState:e,setAppState:t,pin:n,setPin:r,operatorName:i,setOperatorName:a,pinError:o,setPinError:s,showPin:c,setShowPin:l,pinLoading:u,authPolling:f,setAuthPolling:p,authLoading:y,setAuthLoading:b,disconnecting:x,cacheKey:C,setCacheKey:w,claudeInfo:T,setClaudeInfo:E,businessName:D,role:k,userName:j,userAvatar:N,sessionId:F,setSessionId:I,accounts:L,accountPickerLoading:z,expandAll:V,setExpandAll:H,expandAllDefaultRef:U,remoteAuthEnabled:W,pinInputRef:K,setPinFormRef:q,handleSetPin:X,handleLogin:Z,handleAccountSelect:(0,m.useCallback)(async e=>{B(!0),s(``),await Y(n,e)},[n]),handleDisconnect:Q,handleLogout:$,handleChangePin:(0,m.useCallback)(async()=>{if(!n){s(`Enter your current PIN first.`);return}d(!0),s(``);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify({currentPin:n})});if(!e.ok){s((await e.json().catch(()=>({error:`Incorrect PIN.`}))).error||`Incorrect PIN.`);return}r(``),s(``),t(`set-pin`)}catch(e){console.error(`[admin-auth] change pin failed:`,e),s(e instanceof Error?e.message:String(e))}finally{d(!1)}},[n])}}var b=r();function x({inputRef:e,value:t,onChange:n,onComplete:r,showPin:i,autoFocus:a}){let o=(0,m.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,b.jsx)(`div`,{className:`pin-field`,children:Array.from({length:6}).map((n,r)=>(0,b.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 S(e){let{pin:n,setPin:r,showPin:a,setShowPin:o,pinLoading:s,pinError:c,pinInputRef:l,setPinFormRef:f,onSubmit:p,operatorName:m,setOperatorName:h}=e;return(0,b.jsx)(`div`,{className:`connect-page`,children:(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsx)(`img`,{src:t,alt:i.productName,className:`connect-logo connect-logo--maxy`}),!i.logoContainsName&&(0,b.jsxs)(`h1`,{className:`connect-title`,children:[`Welcome to `,i.productName]}),(0,b.jsxs)(`p`,{className:`connect-subtitle`,children:[`Tell `,i.productName,` who you are, then choose a PIN.`]}),(0,b.jsxs)(`form`,{ref:f,onSubmit:p,className:`connect-pin-form`,children:[(0,b.jsxs)(`div`,{className:`pin-input-row`,children:[(0,b.jsx)(`input`,{type:`text`,className:`connect-name-input`,placeholder:`Your full name`,value:m,onChange:e=>h(e.target.value),autoComplete:`name`,autoFocus:!0,required:!0,"aria-label":`Your full name`}),(0,b.jsx)(`div`,{style:{width:38,flexShrink:0},"aria-hidden":`true`})]}),(0,b.jsxs)(`div`,{className:`pin-input-row`,children:[(0,b.jsx)(x,{inputRef:l,value:n,onChange:r,onComplete:()=>{},showPin:a}),(0,b.jsx)(d,{variant:`send`,type:`submit`,disabled:!n||!m.trim(),loading:s,"aria-label":`Set PIN`,children:(0,b.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,b.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,b.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,b.jsx)(u,{checked:a,onChange:()=>o(e=>!e),label:`Show PIN`})]}),c&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:c})]})})}function C(e){let{pin:n,setPin:r,showPin:a,setShowPin:o,pinLoading:s,pinError:c,pinInputRef:l,onSubmit:f,onChangePin:p,remoteAuthEnabled:m,onSignOutRemote:h}=e;return(0,b.jsxs)(`div`,{className:`connect-page`,children:[m&&h&&(0,b.jsx)(`button`,{type:`button`,className:`connect-signout`,onClick:h,children:`Sign out`}),(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsx)(`img`,{src:t,alt:i.productName,className:`connect-logo connect-logo--maxy`}),!i.logoContainsName&&(0,b.jsx)(`h1`,{className:`connect-title`,children:i.productName}),(0,b.jsxs)(`form`,{onSubmit:f,className:`connect-pin-form`,children:[(0,b.jsxs)(`div`,{className:`pin-input-row`,children:[(0,b.jsx)(x,{inputRef:l,value:n,onChange:r,onComplete:()=>{},showPin:a,autoFocus:!0}),(0,b.jsx)(d,{variant:`send`,type:`submit`,disabled:!n,loading:s,children:(0,b.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,b.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,b.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,b.jsxs)(`div`,{className:`pin-options`,children:[(0,b.jsx)(u,{checked:a,onChange:()=>o(e=>!e),label:`Show PIN`}),(0,b.jsx)(d,{type:`button`,variant:`ghost`,onClick:p,children:`Change PIN`})]})]}),c&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:c})]})]})}function w(e){let{accounts:n,loading:r,error:a,onSelect:o}=e;return(0,b.jsx)(`div`,{className:`connect-page`,children:(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsx)(`img`,{src:t,alt:i.productName,className:`connect-logo connect-logo--maxy`}),!i.logoContainsName&&(0,b.jsx)(`h1`,{className:`connect-title`,children:i.productName}),(0,b.jsx)(`p`,{className:`connect-subtitle`,children:`Select an account`}),(0,b.jsx)(`div`,{className:`account-picker-list`,children:n.map(e=>(0,b.jsxs)(`button`,{className:`account-picker-card`,onClick:()=>o(e.accountId),disabled:r,type:`button`,children:[(0,b.jsx)(`span`,{className:`account-picker-name`,children:e.businessName||e.accountId}),(0,b.jsx)(`span`,{className:`account-picker-role`,children:e.role}),r&&(0,b.jsx)(l,{className:`account-picker-spinner`,size:16})]},e.accountId))}),a&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:a})]})})}function T(e){let{authPolling:n,setAuthPolling:r,authLoading:a,setAuthLoading:o,pinError:s,setPinError:c,setAppState:l}=e,[u,f]=(0,m.useState)(!1),[p,h]=(0,m.useState)(!1);async function g(){h(!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.`)}h(!1)}async function _(){o(!0),c(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`})).json();if(e.started){r(!0),f(!0),o(!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.`),r(!1)}else e.error&&c(e.error)}catch(e){console.error(`[admin] auth flow error:`,e),c(`Could not start auth flow.`)}o(!1)}async function v(){await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),r(!1),c(``)}return n||u?(0,b.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100dvh`,overflow:`auto`},children:[(0,b.jsxs)(`header`,{className:`chat-header`,style:{paddingBottom:`12px`,flexShrink:0,position:`relative`,maxWidth:`680px`,width:`100%`,margin:`0 auto`,padding:`24px 20px 12px`},children:[n?(0,b.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,b.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,b.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`chat-logo`}),(0,b.jsx)(`h1`,{className:`chat-tagline`,children:`Connect Claude`}),(0,b.jsx)(`p`,{className:`chat-intro`,children:n?`Sign in and authorize in the browser below.`:`Open your email or prepare your accounts, then sign in.`}),!n&&(0,b.jsx)(`div`,{style:{marginTop:`12px`},children:(0,b.jsx)(d,{variant:`primary`,onClick:_,disabled:a,children:a?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`})})]}),(0,b.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,minHeight:0,gap:`10px`,padding:`0 0 16px`},children:(0,b.jsx)(`iframe`,{src:`/vnc-viewer.html`,style:{flex:1,width:`100%`,minHeight:0,border:`none`,background:`#111`,display:`block`},title:`Claude Sign-in`})}),s&&(0,b.jsx)(`p`,{className:`admin-pin-error`,style:{textAlign:`center`,padding:`0 20px 16px`},children:s})]}):(0,b.jsx)(`div`,{className:`connect-page`,children:(0,b.jsxs)(`div`,{className:`connect-content`,children:[(0,b.jsxs)(`div`,{className:`connect-logos`,children:[(0,b.jsx)(`div`,{className:`connect-logo-wrap`,children:(0,b.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`connect-logo`})}),(0,b.jsx)(`svg`,{className:`connect-arrow`,viewBox:`0 0 48 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,b.jsx)(`path`,{d:`M0 12h44m0 0l-8-8m8 8l-8 8`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}),(0,b.jsxs)(`div`,{className:`connect-logo-wrap`,children:[(0,b.jsx)(`img`,{src:t,alt:i.productName,className:`connect-logo connect-logo--maxy`}),!i.logoContainsName&&(0,b.jsx)(`span`,{className:`connect-logo-label`,children:i.productName})]})]}),(0,b.jsxs)(`h1`,{className:`connect-title`,children:[`Connect Claude to power `,i.productName]}),(0,b.jsx)(`p`,{className:`connect-subtitle`,children:`Sign in with your Anthropic account to get started.`}),(0,b.jsx)(d,{variant:`primary`,onClick:_,disabled:a,children:a?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`}),(0,b.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,b.jsx)(`button`,{onClick:g,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`}),s&&(0,b.jsx)(`p`,{className:`admin-pin-error`,children:s})]})})}function E({onOpen:e}){return(0,b.jsx)(`footer`,{className:`admin-footer`,children:(0,b.jsxs)(`div`,{className:`powered-by`,role:`button`,tabIndex:0,onClick:e,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),e())},"aria-label":`Powered by Claude Code — show details`,children:[(0,b.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`powered-by-icon`}),(0,b.jsx)(`span`,{children:`Powered by Claude Code`})]})})}function D(e){if(e<60)return`${e}s`;let t=Math.floor(e/60),n=e%60;return n>0?`${t}m ${n}s`:`${t}m`}function O(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function k(e){let{show:t,onClose:n,claudeInfo:r,messages:i,sessionElapsed:a,sessionId:o,cacheKey:s}=e,[c,l]=(0,m.useState)(null);if(!t)return null;let u=i.flatMap(e=>e.events?.filter(e=>e.type===`usage`)??[]),d=u.at(-1),p=d?.peak_request_pct==null?d?.context_window?Math.round((d.input_tokens+d.cache_creation_tokens+d.cache_read_tokens)/d.context_window*100):0:Math.round(d.peak_request_pct*100),h=u.reduce((e,t)=>e+t.input_tokens+t.cache_creation_tokens+t.cache_read_tokens+t.output_tokens,0),g=i.flatMap(e=>e.events?.filter(e=>e.type===`rate_limit`)??[]).at(-1),_=u.reduce((e,t)=>e+(t.total_cost_usd??0),0),v=r?.account?.subscriptionType,y=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,b.jsx)(`div`,{className:`claude-info-overlay`,onClick:n,children:(0,b.jsxs)(`div`,{className:`claude-info-modal`,onClick:e=>e.stopPropagation(),children:[(0,b.jsxs)(`div`,{className:`claude-info-header`,children:[(0,b.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`claude-info-icon`}),(0,b.jsx)(`span`,{children:`Claude Code`}),(0,b.jsx)(`button`,{className:`claude-info-close`,onClick:n,"aria-label":`Close`,children:`✕`})]}),(0,b.jsxs)(`div`,{className:`claude-info-section`,children:[(0,b.jsxs)(`div`,{className:`claude-info-row`,children:[(0,b.jsx)(`span`,{className:`claude-info-label`,children:`Version`}),(0,b.jsx)(`span`,{className:`claude-info-value`,children:r?r.version:`…`})]}),(0,b.jsxs)(`div`,{className:`claude-info-row`,children:[(0,b.jsx)(`span`,{className:`claude-info-label`,children:`Email`}),(0,b.jsx)(`span`,{className:`claude-info-value`,children:r?.account?.email??`…`})]})]}),(v||g||_>0)&&(0,b.jsxs)(`div`,{className:`claude-info-section`,children:[v&&(0,b.jsxs)(`div`,{className:`claude-info-row`,children:[(0,b.jsx)(`span`,{className:`claude-info-label`,children:`Plan`}),(0,b.jsx)(`span`,{className:`claude-info-value`,style:{textTransform:`capitalize`},children:v})]}),g&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(`div`,{className:`claude-info-row`,children:[(0,b.jsx)(`span`,{className:`claude-info-label`,children:`Usage`}),(0,b.jsxs)(`span`,{className:`claude-info-value`,children:[Math.round(g.utilization*100),`%`]})]}),(0,b.jsxs)(`div`,{className:`claude-info-row`,children:[(0,b.jsx)(`span`,{className:`claude-info-label`,children:`Resets in`}),(0,b.jsx)(`span`,{className:`claude-info-value`,children:y(g.resetsAt)})]}),g.isUsingOverage&&(0,b.jsxs)(`div`,{className:`claude-info-row`,children:[(0,b.jsx)(`span`,{className:`claude-info-label`,children:`Overage`}),(0,b.jsx)(`span`,{className:`claude-info-value`,children:`Active`})]})]}),_>0&&(0,b.jsxs)(`div`,{className:`claude-info-row`,children:[(0,b.jsx)(`span`,{className:`claude-info-label`,children:`Session cost`}),(0,b.jsxs)(`span`,{className:`claude-info-value`,children:[`$`,_<.01?_.toFixed(4):_.toFixed(2)]})]})]}),(0,b.jsxs)(`div`,{className:`claude-info-section`,children:[(0,b.jsxs)(`div`,{className:`claude-info-row`,children:[(0,b.jsx)(`span`,{className:`claude-info-label`,children:`Model`}),(0,b.jsx)(`span`,{className:`claude-info-value`,children:r?.model??`…`})]}),(0,b.jsxs)(`div`,{className:`claude-info-row`,children:[(0,b.jsx)(`span`,{className:`claude-info-label`,children:`Context used`}),(0,b.jsx)(`span`,{className:`claude-info-value`,children:p>0?`${p}%`:`—`})]}),(0,b.jsxs)(`div`,{className:`claude-info-row`,children:[(0,b.jsx)(`span`,{className:`claude-info-label`,children:`Tokens`}),(0,b.jsx)(`span`,{className:`claude-info-value`,children:h>0?O(h):`—`})]}),(0,b.jsxs)(`div`,{className:`claude-info-row`,children:[(0,b.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,b.jsx)(`span`,{className:`claude-info-value`,children:D(a)})]}),(o||s)&&(()=>{let e=o??s??``;return(0,b.jsxs)(`div`,{className:`claude-info-row`,children:[(0,b.jsx)(`span`,{className:`claude-info-label`,children:`Session`}),(0,b.jsx)(`button`,{type:`button`,className:`claude-info-value claude-info-id-copy`,title:`${e} (${o?`flushed`:`pre-flush`}) — click to copy`,onClick:async()=>{l(await f(e)?`copied`:`failed`),setTimeout(()=>l(null),1200)},children:c===`copied`?`copied ✓`:c===`failed`?`copy failed ✕`:`${e.slice(0,8)}…`})]})})()]})]})})}function A(){let e=y(),[t,n]=(0,m.useState)(!1);(0,m.useEffect)(()=>{if(!t)return;let e=e=>{e.key===`Escape`&&n(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let r=(0,m.useCallback)(async()=>{let t=e.claudeInfo!=null;if(n(!0),t){console.info(`[admin-ui] claude-info-open cached=true ms=0`);return}let r=Date.now();try{let t=await fetch(`/api/admin/claude-info`);if(t.ok){let n=await t.json();e.setClaudeInfo(n)}console.info(`[admin-ui] claude-info-open cached=false ms=${Date.now()-r}`)}catch(e){console.error(`[admin-ui] claude-info-fetch-failed ms=${Date.now()-r} error="${e instanceof Error?e.message:String(e)}"`)}},[e]),i=(0,m.useCallback)(({code:t,path:n})=>{console.warn(`[admin-auth] outcome=chat-tab-logout-on-401 code=${t} path=${n}`),e.handleLogout()},[e]);return e.appState===`loading`?(0,b.jsx)(`div`,{className:`connect-page`}):e.appState===`set-pin`?(0,b.jsx)(S,{pin:e.pin,setPin:e.setPin,showPin:e.showPin,setShowPin:e.setShowPin,pinLoading:e.pinLoading,pinError:e.pinError,pinInputRef:e.pinInputRef,setPinFormRef:e.setPinFormRef,onSubmit:e.handleSetPin,operatorName:e.operatorName,setOperatorName:e.setOperatorName}):e.appState===`connect-claude`?(0,b.jsx)(T,{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,b.jsx)(C,{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,b.jsx)(w,{accounts:e.accounts,loading:e.accountPickerLoading,error:e.pinError,onSelect:e.handleAccountSelect}):(0,b.jsx)(s,{cacheKey:e.cacheKey,onSessionExpired:i,surface:`chat`,children:(0,b.jsx)(c,{cacheKey:e.cacheKey,businessName:e.businessName,sessionId:e.sessionId,onLogout:e.handleLogout,userName:e.userName,userAvatar:e.userAvatar,role:e.role,footer:(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(E,{onOpen:r}),(0,b.jsx)(k,{show:t,onClose:()=>n(!1),claudeInfo:e.claudeInfo,messages:[],sessionElapsed:0,sessionId:e.sessionId,cacheKey:e.cacheKey})]}),children:()=>(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(o,{}),(0,b.jsx)(`main`,{})]})})})}(0,p.createRoot)(document.getElementById(`root`)).render((0,b.jsx)(A,{}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{o as e}from"./chunk-DD-I1_y5.js";import{d as t,l as n,o as r,s as i,u as a}from"./brand-Dmpzr6Qq.js";import{a as o,c as s,d as c,f as l,i as u,n as d,r as f,t as p,u as m}from"./AdminShell-D_eg2QKE.js";import{i as h,t as g}from"./graph-labels-iPC15OmD.js";var _=n(`circle-arrow-up`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m16 12-4-4-4 4`,key:`177agl`}],[`path`,{d:`M12 16V8`,key:`1sbj14`}]]),v=n(`file`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}]]),y=n(`folder`,[[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]),b=n(`upload`,[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]),x=a(),S=e(t(),1);function C(e){let t=new Set,n=[];for(let r of e)for(let e of r.labels)e&&(t.has(e)||g.has(e)&&(t.add(e),n.push(e)));return n}var w=r();function T(){let[e,t]=(0,S.useState)(null),[n,r]=(0,S.useState)(!1),[i,a]=(0,S.useState)(void 0),[s,c]=(0,S.useState)(null),[u,d]=(0,S.useState)(void 0),[h,g]=(0,S.useState)(null),[_,v]=(0,S.useState)(null);(0,S.useEffect)(()=>{let e=!1,n=null;try{n=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!n){t(null),r(!0);return}return fetch(`/api/admin/session?session_key=${encodeURIComponent(n)}`).then(async i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}if(i.ok)try{let e=await i.json();typeof e.businessName==`string`&&a(e.businessName),e.sessionId!==void 0&&c(e.sessionId??null),v(e.role??null),d(e.userName===void 0?null:e.userName),g(e.avatar??null)}catch{}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]);let y=(0,S.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]);return n?e?(0,w.jsx)(f,{cacheKey:e,surface:`data`,onSessionExpired:({code:e,path:t})=>{console.warn(`[admin-auth] outcome=session-expired-redirect code=${e} path=${t} surface=data`);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},children:(0,w.jsxs)(p,{cacheKey:e,businessName:i,sessionId:s,onLogout:y,userName:u,userAvatar:h,role:_,children:[(0,w.jsx)(o,{}),(0,w.jsxs)(`div`,{className:`data-page`,children:[(0,w.jsx)(`header`,{className:`data-header`,children:(0,w.jsxs)(`h1`,{className:`data-title`,children:[(0,w.jsx)(l,{size:18}),` Data`]})}),(0,w.jsx)(E,{cacheKey:e})]})]})}):(0,w.jsxs)(`div`,{className:`data-page`,children:[(0,w.jsx)(`header`,{className:`data-header`,children:(0,w.jsxs)(`h1`,{className:`data-title`,children:[(0,w.jsx)(l,{size:18}),` Data`]})}),(0,w.jsxs)(`div`,{className:`data-empty`,children:[(0,w.jsx)(`p`,{children:`You are not signed in.`}),(0,w.jsxs)(`p`,{children:[`Open the `,(0,w.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})]}):(0,w.jsx)(`div`,{className:`data-page`,children:(0,w.jsxs)(`div`,{className:`data-loading`,children:[(0,w.jsx)(m,{size:18,className:`spin`}),` Loading…`]})})}function E({cacheKey:e}){let{adminFetch:t,cacheKey:n,sessionRefetchNonce:r}=u({initialCacheKey:e,surface:`data`});return(0,w.jsxs)(`main`,{className:`data-main`,children:[(0,w.jsx)(D,{adminFetch:t,cacheKey:n,sessionRefetchNonce:r}),(0,w.jsx)(F,{adminFetch:t,cacheKey:n,sessionRefetchNonce:r})]})}function D({adminFetch:e,cacheKey:t,sessionRefetchNonce:n}){let[r,i]=(0,S.useState)(``),[a,o]=(0,S.useState)(``),[s,c]=(0,S.useState)(null),[l,u]=(0,S.useState)(`hybrid`),[d,f]=(0,S.useState)(!1),[p,g]=(0,S.useState)(null),[_,v]=(0,S.useState)(null),[y,b]=(0,S.useState)(0),[x,T]=(0,S.useState)(!1);(0,S.useEffect)(()=>{let e=r.trim();if(!e){o(``),c(null);return}T(!1);let t=setTimeout(()=>o(e),300);return()=>clearTimeout(t)},[r]),(0,S.useEffect)(()=>{if(!a)return;let t=!1;return f(!0),g(null),e(`/api/admin/graph-search?q=${encodeURIComponent(a)}&labels=FileArtifact&limit=20${x?`&threshold=0`:``}`).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);return t}).then(e=>{t||(c(e.results),u(e.mode??`hybrid`),b(typeof e.suppressed==`number`?e.suppressed:0))}).catch(e=>{t||g(e instanceof Error?e.message:String(e))}).finally(()=>{t||f(!1)}),()=>{t=!0}},[a,e,n,x]);let E=(0,S.useMemo)(()=>s?C(s):[],[s]),D=_&&E.includes(_)?_:null,A=(0,S.useMemo)(()=>s?D?s.filter(e=>e.labels.includes(D)):s:null,[s,D]),j=(0,S.useCallback)(e=>{let n=e.properties.relativePath;if(typeof n!=`string`||n.length===0)return;let r=`/api/admin/files/download?session_key=${encodeURIComponent(t)}&path=${encodeURIComponent(n)}`,i=document.createElement(`a`);i.href=r,i.rel=`noopener noreferrer`,document.body.appendChild(i),i.click(),i.remove()},[t]);return(0,w.jsxs)(`section`,{className:`data-panel`,children:[(0,w.jsx)(`h2`,{className:`data-panel-title`,children:`Search`}),(0,w.jsx)(`p`,{className:`data-panel-subtitle`,children:`Find anything in your knowledge base by keyword.`}),(0,w.jsxs)(`div`,{className:`data-search-input`,children:[(0,w.jsx)(h,{size:14}),(0,w.jsx)(`input`,{type:`text`,placeholder:`Search your knowledge…`,value:r,onChange:e=>i(e.target.value),autoFocus:!0,autoComplete:`off`,spellCheck:!1}),d&&(0,w.jsx)(m,{size:14,className:`spin`})]}),p&&(0,w.jsxs)(`div`,{className:`data-error`,children:[`Search failed: `,p]}),E.length>0&&(0,w.jsx)(`div`,{className:`data-chip-row`,role:`group`,"aria-label":`Filter by type`,children:E.map(e=>{let t=e===D;return(0,w.jsx)(`button`,{type:`button`,className:`data-chip`,"data-active":t,onClick:()=>v(t?null:e),children:k([e])??e},e)})}),s&&!d&&(0,w.jsxs)(`div`,{className:`data-results-meta`,children:[A.length,` of `,s.length,` result`,s.length===1?``:`s`]}),s&&!d&&!D&&y>0&&!x&&(0,w.jsxs)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>T(!0),children:[y,` low-confidence result`,y===1?``:`s`,` hidden — show all`]}),s&&!d&&!D&&x&&(0,w.jsx)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>T(!1),children:`Showing all results — hide low-confidence`}),s&&s.length===0&&!d&&(0,w.jsx)(`div`,{className:`data-empty-results`,children:`No matches. Try a different keyword.`}),A&&A.length>0&&(0,w.jsx)(`ul`,{className:`data-results`,children:A.map(e=>(0,w.jsx)(O,{hit:e,mode:l,onDownload:j},e.nodeId))})]})}function O({hit:e,mode:t,onDownload:n}){let r=A(e.properties),i=j(e.properties),a=k(e.labels),o=M(e.properties),[s,c]=(0,S.useState)(!1),l=i&&i.length>280,u=s||!l?i:i?.slice(0,280)+`…`,d=t===`bm25`?`bm25 ${e.bm25Score.toFixed(2)}`:`vector ${e.vectorScore.toFixed(2)} · bm25 ${e.bm25Score.toFixed(2)} · combined ${e.score.toFixed(2)}`;return(0,w.jsxs)(`li`,{className:`data-result`,children:[(0,w.jsxs)(`div`,{role:`button`,tabIndex:0,className:`data-result-open`,onClick:()=>n(e),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),n(e))},"aria-label":`Download ${r??a??`file`}`,children:[a&&(0,w.jsx)(`div`,{className:`data-result-header`,children:(0,w.jsx)(`span`,{className:`data-result-labels`,children:a})}),r&&(0,w.jsx)(`div`,{className:`data-result-title`,children:r}),i&&(0,w.jsx)(`pre`,{className:`data-result-body`,children:u}),(0,w.jsxs)(`div`,{className:`data-result-scores`,children:[o&&(0,w.jsxs)(`span`,{className:`data-result-updated`,children:[`Updated `,L(o),` · `]}),d]})]}),l&&(0,w.jsx)(`button`,{type:`button`,className:`data-result-toggle`,onClick:()=>c(e=>!e),children:s?`Show less`:`Show more`})]})}function k(e){if(e.length===0)return null;let t=e[0].replace(/([a-z])([A-Z])/g,`$1 $2`);return t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()}function A(e){for(let t of[`title`,`name`,`summary`,`headline`]){let n=e[t];if(typeof n==`string`&&n.length>0)return n.length>140?n.slice(0,140)+`…`:n}return null}function j(e){for(let t of[`content`,`summary`,`body`,`description`,`text`]){let n=e[t];if(typeof n==`string`&&n.length>0)return n}return null}function M(e){for(let t of[`updatedAt`,`modifiedAt`,`fetchedAt`,`createdAt`,`lastModified`]){let n=e[t];if(typeof n==`string`&&n.length>0)return n}return null}function N(){if(typeof window>`u`)return`.`;let e=new URLSearchParams(window.location.hash.replace(/^#/,``)).get(`path`);return e&&e.length>0?e:`.`}function P(e){if(typeof window>`u`)return;let t=new URL(window.location.href);t.hash=e===`.`?``:`path=${encodeURIComponent(e)}`,window.history.replaceState(window.history.state,``,t.toString())}function F({adminFetch:e,cacheKey:t,sessionRefetchNonce:n}){let[r,a]=(0,S.useState)(()=>N()),[o,l]=(0,S.useState)(null),[u,f]=(0,S.useState)([]),[p,h]=(0,S.useState)(!1),[g,x]=(0,S.useState)(null),[C,T]=(0,S.useState)(!1),[E,D]=(0,S.useState)(null),[O,k]=(0,S.useState)(null),[A,j]=(0,S.useState)(null),[M,F]=(0,S.useState)(null),R=(0,S.useRef)(null),[z,B]=(0,S.useState)(0);(0,S.useEffect)(()=>{let t=!1;return h(!0),x(null),e(`/api/admin/files?path=${encodeURIComponent(r===`.`?``:r)}`).then(async e=>{let t=await e.json().catch(()=>({error:`HTTP ${e.status}`}));if(!e.ok)throw Error(t.error??`HTTP ${e.status}`);return t}).then(e=>{t||(l(e.entries),f(e.displayPath??[]))}).catch(e=>{t||(l([]),f([]),x(e instanceof Error?e.message:String(e)))}).finally(()=>{t||h(!1)}),()=>{t=!0}},[e,r,z,n]),(0,S.useEffect)(()=>{P(r)},[r]);let V=(0,S.useCallback)(()=>{B(e=>e+1)},[]),H=(0,S.useCallback)(e=>{a(e)},[]),U=(0,S.useCallback)(()=>{if(r===`.`||r===``)return;let e=r.split(`/`).filter(Boolean);e.pop(),a(e.length===0?`.`:e.join(`/`))},[r]),W=(0,S.useCallback)(e=>{d(t,r===`.`?e.name:`${r}/${e.name}`)},[r,t]),G=(0,S.useCallback)(()=>{R.current?.click()},[]),K=(0,S.useCallback)(e=>{k(null),F(e.name)},[]),q=(0,S.useCallback)(()=>{F(null)},[]),J=(0,S.useCallback)(async t=>{let n=r===`.`?t.name:`${r}/${t.name}`;k(null),F(null),j(t.name);try{let t=await e(`/api/admin/files?path=${encodeURIComponent(n)}`,{method:`DELETE`}),r=await t.json().catch(()=>({error:`HTTP ${t.status}`}));if(!t.ok)throw Error(r.error??`HTTP ${t.status}`);B(e=>e+1)}catch(e){k(e instanceof Error?e.message:String(e))}finally{j(null)}},[r,e]);(0,S.useEffect)(()=>{if(!M)return;let e=e=>{e.key===`Escape`&&F(null)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[M]);let Y=(0,S.useCallback)(async e=>{D(null),T(!0);try{let n=new FormData;n.append(`session_key`,t),n.append(`file`,e);let r=await fetch(`/api/admin/files/upload`,{method:`POST`,body:n}),i=await r.json().catch(()=>({error:`HTTP ${r.status}`}));if(!r.ok)throw Error(i.error??`HTTP ${r.status}`);a(i.path.split(`/`).slice(0,-1).join(`/`)||`.`),B(e=>e+1)}catch(e){D(e instanceof Error?e.message:String(e))}finally{T(!1),R.current&&(R.current.value=``)}},[t]);return(0,w.jsxs)(`section`,{className:`data-panel`,children:[(0,w.jsxs)(`div`,{className:`data-panel-heading`,children:[(0,w.jsx)(`h2`,{className:`data-panel-title`,children:`Files`}),(0,w.jsxs)(`div`,{className:`data-file-actions`,children:[(0,w.jsxs)(`button`,{type:`button`,className:`data-btn`,onClick:V,disabled:p,title:`Refresh this folder`,"aria-label":`Refresh this folder`,children:[p?(0,w.jsx)(m,{size:14,className:`spin`}):(0,w.jsx)(s,{size:14}),` Refresh`]}),(0,w.jsxs)(`button`,{type:`button`,className:`data-btn`,onClick:G,disabled:C,children:[C?(0,w.jsx)(m,{size:14,className:`spin`}):(0,w.jsx)(b,{size:14}),` Upload`]}),(0,w.jsx)(`input`,{type:`file`,ref:R,hidden:!0,onChange:e=>{let t=e.target.files?.[0];t&&Y(t)}})]})]}),(0,w.jsxs)(`p`,{className:`data-panel-subtitle`,children:[`Everything under your install's `,(0,w.jsx)(`code`,{children:`data/`}),` directory. Click a folder to open it, a file to download it. Uploads go to `,(0,w.jsx)(`code`,{children:`data/uploads/`}),`.`]}),(0,w.jsxs)(`div`,{className:`data-breadcrumbs`,children:[(0,w.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>H(`.`),children:`data`}),u.map((e,t)=>{let n=u.slice(0,t+1).map(e=>e.name).join(`/`);return(0,w.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,w.jsx)(`span`,{className:`data-crumb-sep`,children:`/`}),(0,w.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>H(n),title:e.name,children:e.displayName??e.name})]},n)}),r!==`.`&&(0,w.jsxs)(`button`,{type:`button`,className:`data-btn data-btn-ghost data-up-btn`,onClick:U,children:[(0,w.jsx)(_,{size:14}),` Up`]})]}),E&&(0,w.jsxs)(`div`,{className:`data-error`,children:[`Upload failed: `,E]}),O&&(0,w.jsxs)(`div`,{className:`data-error`,children:[`Delete failed: `,O]}),g&&(0,w.jsx)(`div`,{className:`data-error`,children:g}),p&&(0,w.jsxs)(`div`,{className:`data-loading`,children:[(0,w.jsx)(m,{size:14,className:`spin`}),` Loading…`]}),!p&&o&&o.length===0&&!g&&(0,w.jsx)(`div`,{className:`data-empty-results`,children:`Empty directory.`}),!p&&o&&o.length>0&&(0,w.jsx)(`ul`,{className:`data-entries`,children:o.map(e=>{let t=e.displayName??e.name,n=A===e.name,a=M===e.name;return(0,w.jsx)(`li`,{className:`data-entry`,children:e.kind===`directory`?(0,w.jsxs)(`button`,{type:`button`,className:`data-entry-btn`,onClick:()=>H(r===`.`?e.name:`${r}/${e.name}`),children:[(0,w.jsx)(y,{size:14}),(0,w.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t})]}):e.kind===`file`?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(`button`,{type:`button`,className:`data-entry-btn`,onClick:()=>W(e),title:`Download ${t}`,disabled:a,children:[(0,w.jsx)(v,{size:14}),(0,w.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t}),(0,w.jsxs)(`span`,{className:`data-entry-meta`,title:`Modified ${L(e.modifiedAt)}`,children:[I(e.sizeBytes),` · `,L(e.modifiedAt)]}),(0,w.jsx)(c,{size:12,className:`data-entry-download-icon`})]}),a?(0,w.jsxs)(`div`,{className:`data-entry-confirm`,role:`group`,"aria-label":`Confirm delete ${t}`,children:[(0,w.jsx)(`span`,{className:`data-entry-confirm-label`,children:`Delete?`}),(0,w.jsx)(`button`,{type:`button`,className:`data-entry-confirm-yes`,onClick:()=>J(e),autoFocus:!0,children:`Yes`}),(0,w.jsx)(`button`,{type:`button`,className:`data-entry-confirm-no`,onClick:q,children:`No`})]}):(0,w.jsx)(`button`,{type:`button`,className:`data-entry-delete`,onClick:()=>K(e),disabled:n,title:`Delete ${t}`,"aria-label":`Delete ${t}`,children:n?(0,w.jsx)(m,{size:14,className:`spin`}):(0,w.jsx)(i,{size:14})})]}):(0,w.jsxs)(`div`,{className:`data-entry-btn data-entry-disabled`,children:[(0,w.jsx)(v,{size:14}),(0,w.jsx)(`span`,{className:`data-entry-name`,children:t}),(0,w.jsx)(`span`,{className:`data-entry-meta`,children:`special`})]})},e.name)})})]})}function I(e){return e==null?``:e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:e<1024*1024*1024?`${(e/1024/1024).toFixed(1)} MB`:`${(e/1024/1024/1024).toFixed(1)} GB`}function L(e){try{let t=new Date(e);if(isNaN(t.getTime()))return`—`;let n=typeof navigator<`u`?navigator.languages&&navigator.languages.length>0?[...navigator.languages]:[navigator.language]:void 0;return t.toLocaleString(n,{dateStyle:`medium`,timeStyle:`short`})}catch{return`—`}}(0,x.createRoot)(document.getElementById(`root`)).render((0,w.jsx)(T,{}));
|