@rubytech/create-sitedesk-code 0.1.611 → 0.1.612
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/skills/whats-new/SKILL.md +4 -0
- package/payload/server/public/assets/{AdminLoginScreens-Bjsr45ed.js → AdminLoginScreens-BiHOXO0Y.js} +1 -1
- package/payload/server/public/assets/AdminLoginScreens-BiHOXO0Y.js.br +0 -0
- package/payload/server/public/assets/AdminLoginScreens-BiHOXO0Y.js.gz +0 -0
- package/payload/server/public/assets/{admin-B2IkUoSc.js → admin-Bs6cPAbz.js} +1 -1
- package/payload/server/public/assets/admin-Bs6cPAbz.js.br +0 -0
- package/payload/server/public/assets/admin-Bs6cPAbz.js.gz +0 -0
- package/payload/server/public/assets/chat-UvZFrM0K.js +1 -0
- package/payload/server/public/assets/chat-UvZFrM0K.js.br +3 -0
- package/payload/server/public/assets/chat-UvZFrM0K.js.gz +0 -0
- package/payload/server/public/assets/data-BBEjTZO8.js +1 -0
- package/payload/server/public/assets/data-BBEjTZO8.js.br +1 -0
- package/payload/server/public/assets/data-BBEjTZO8.js.gz +0 -0
- package/payload/server/public/assets/{operator-CO5ma-ky.js → operator-DxwbldCs.js} +1 -1
- package/payload/server/public/assets/operator-DxwbldCs.js.br +0 -0
- package/payload/server/public/assets/operator-DxwbldCs.js.gz +0 -0
- package/payload/server/public/assets/{page-CdRrpkky.js → page-BF6bGLX_.js} +1 -1
- package/payload/server/public/assets/page-BF6bGLX_.js.br +0 -0
- package/payload/server/public/assets/page-BF6bGLX_.js.gz +0 -0
- package/payload/server/public/assets/{page-BBRWbFzG.js → page-Bkl56P8R.js} +1 -1
- package/payload/server/public/assets/page-Bkl56P8R.js.br +0 -0
- package/payload/server/public/assets/page-Bkl56P8R.js.gz +0 -0
- package/payload/server/public/assets/{public-2mLo4k7L.js → public-D6YxlJcZ.js} +1 -1
- package/payload/server/public/assets/public-D6YxlJcZ.js.br +0 -0
- package/payload/server/public/assets/public-D6YxlJcZ.js.gz +0 -0
- package/payload/server/public/assets/useVoiceRecorder-Cvu4TePf.js +2 -0
- package/payload/server/public/assets/useVoiceRecorder-Cvu4TePf.js.br +0 -0
- package/payload/server/public/assets/useVoiceRecorder-Cvu4TePf.js.gz +0 -0
- package/payload/server/public/chat.html +3 -3
- package/payload/server/public/data.html +3 -3
- package/payload/server/public/index.html +4 -4
- package/payload/server/public/operator.html +4 -4
- package/payload/server/public/public.html +3 -3
- package/payload/server/public/assets/AdminLoginScreens-Bjsr45ed.js.br +0 -0
- package/payload/server/public/assets/AdminLoginScreens-Bjsr45ed.js.gz +0 -0
- package/payload/server/public/assets/admin-B2IkUoSc.js.br +0 -0
- package/payload/server/public/assets/admin-B2IkUoSc.js.gz +0 -0
- package/payload/server/public/assets/chat-fP4sE4pU.js +0 -1
- package/payload/server/public/assets/chat-fP4sE4pU.js.br +0 -2
- package/payload/server/public/assets/chat-fP4sE4pU.js.gz +0 -0
- package/payload/server/public/assets/data-DKz9_73S.js +0 -1
- package/payload/server/public/assets/data-DKz9_73S.js.br +0 -1
- package/payload/server/public/assets/data-DKz9_73S.js.gz +0 -0
- package/payload/server/public/assets/operator-CO5ma-ky.js.br +0 -0
- package/payload/server/public/assets/operator-CO5ma-ky.js.gz +0 -0
- package/payload/server/public/assets/page-BBRWbFzG.js.br +0 -0
- package/payload/server/public/assets/page-BBRWbFzG.js.gz +0 -0
- package/payload/server/public/assets/page-CdRrpkky.js.br +0 -0
- package/payload/server/public/assets/page-CdRrpkky.js.gz +0 -0
- package/payload/server/public/assets/public-2mLo4k7L.js.br +0 -0
- package/payload/server/public/assets/public-2mLo4k7L.js.gz +0 -0
- package/payload/server/public/assets/useVoiceRecorder-D7_wLtrS.js +0 -2
- package/payload/server/public/assets/useVoiceRecorder-D7_wLtrS.js.br +0 -0
- package/payload/server/public/assets/useVoiceRecorder-D7_wLtrS.js.gz +0 -0
package/package.json
CHANGED
|
@@ -9,6 +9,10 @@ Invoked by the admin agent directly.
|
|
|
9
9
|
|
|
10
10
|
This is the platform's release timeline, newest first. Each entry shows the date it shipped and the version it shipped in, so you can tell the operator how current their install is. To compare, read the installed version from `capabilities-here` and match it against the versions below. Keep answers high level and in plain English; this is a summary, not a full commit log.
|
|
11
11
|
|
|
12
|
+
## 2026-08-15 (0.1.612)
|
|
13
|
+
|
|
14
|
+
- A conversation opened from the dashboard could show as completely empty even though the agent had answered in it. The reader was discarding the agent's replies instead of drawing them, so the thread looked like nothing had ever been said. Those replies now appear.
|
|
15
|
+
|
|
12
16
|
## 2026-08-15 (0.1.611)
|
|
13
17
|
|
|
14
18
|
- A message you send by hand to a switched-off agent is now recorded in the conversation instead of being refused. It was delivered as though it had arrived from the other person, so an agent that was off declined to take it.
|
package/payload/server/public/assets/{AdminLoginScreens-Bjsr45ed.js → AdminLoginScreens-BiHOXO0Y.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./chunk-BycB0eMI.js";import{i as t,t as n}from"./jsx-runtime-BY35JYDT.js";import{N as r,it as i,lt as a,ot as o}from"./useMediaQuery-e4ciNiuO.js";import{P as s}from"./useVoiceRecorder-D7_wLtrS.js";import{D as c,O as l,k as u,p as d}from"./AdminShell-Dm_nY4jF.js";var f=e(t(),1);function p(e=`admin`){let[t,n]=(0,f.useState)(`loading`),[r,i]=(0,f.useState)(``),[o,c]=(0,f.useState)(``),[l,d]=(0,f.useState)(``),[p,m]=(0,f.useState)(!1),[h,g]=(0,f.useState)(!1),[_,v]=(0,f.useState)(!1),[y,b]=(0,f.useState)(!1),[x,S]=(0,f.useState)(!1),[C,w]=(0,f.useState)(null),[T,E]=(0,f.useState)(null),[D,O]=(0,f.useState)(void 0),[k,A]=(0,f.useState)(null),[j,M]=(0,f.useState)(void 0),[N,P]=(0,f.useState)(null),[F,I]=(0,f.useState)(null),[L,R]=(0,f.useState)(void 0),z=(0,f.useRef)(void 0),[B,V]=(0,f.useState)(!1),[H,U]=(0,f.useState)(!0);(0,f.useEffect)(()=>{typeof window>`u`||fetch(`/api/remote-auth/status`).then(e=>e.ok?e.json():null).then(e=>{e?.configured&&V(!0)}).catch(()=>{})},[]);let W=(0,f.useRef)(null),G=(0,f.useRef)(null);(0,f.useEffect)(()=>{async function e(){let e=null;try{e=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!e)return!1;try{let t=await fetch(`/api/admin/session?session_key=${encodeURIComponent(e)}`);if(t.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}return!1}if(!t.ok)return!1;let r=await t.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=s(r.thinkingView);return z.current=i,R(i),n(`chat`),!0}catch(e){return console.error(`[admin] session restore failed:`,e),!1}}async function t(r=2){try{let i=await fetch(`/api/health`);if(!i.ok){if(r>0)return await new Promise(e=>setTimeout(e,1500)),t(r-1);console.error(`[admin] health check returned ${i.status} after retries`),n(`set-pin`);return}let a=await i.json();if(!a.pin_configured){n(`set-pin`);return}U(!!a.claude_authenticated);let o=!1;try{o=new URLSearchParams(window.location.search).get(`connect`)===`claude`}catch{}if(o){try{let e=new URL(window.location.href);e.searchParams.delete(`connect`),window.history.replaceState(null,``,e.pathname+e.search+e.hash)}catch{}if(!a.claude_authenticated){n(`connect-claude`);return}}if(await e())return;n(`enter-pin`)}catch(e){if(r>0)return await new Promise(e=>setTimeout(e,1500)),t(r-1);console.error(`[admin] health check failed:`,e),n(`set-pin`)}}t()},[]),(0,f.useEffect)(()=>{t===`chat`&&C&&fetch(`/api/admin/claude-info?session_key=${encodeURIComponent(C)}`).then(e=>{if(e.ok)return e.json()}).then(e=>{e&&E(e)}).catch(()=>{})},[t,C]);let K=(0,f.useRef)(null);(0,f.useEffect)(()=>{if(t!==`chat`)return;let e=setInterval(async()=>{try{let e=await fetch(`/api/health`);if(e.ok){let t=await e.json();U(t.auth_status!==`dead`&&t.auth_status!==`missing`)}}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`;if(t===`remote-auth-required`){a(`heartbeat`,`/api/admin/session`);return}console.warn(`[admin-auth] outcome=heartbeat-detected-expiry code=${t}`),K.current?.()}catch{}},300*1e3);return()=>clearInterval(e)},[t,C]),(0,f.useEffect)(()=>{t===`connect-claude`&&fetch(`/api/health`).then(e=>e.ok?e.json():null).then(e=>{e?.claude_authenticated&&(U(!0),n(`enter-pin`))}).catch(()=>{})},[t]);async function q(e,t){g(!0);try{let r=await fetch(`/api/admin/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:e,...t?{accountId:t}:{}})});if(!r.ok){let e=await r.json().catch(()=>({}));if(r.status===401&&e?.code===`remote-auth-required`){a(`enter-pin`,`/api/admin/session`);return}d(e.error||`Invalid PIN`);return}let o=await r.json();w(o.session_key),I(o.sessionId??null),O(o.businessName),A(o.role??null),M(o.userName===void 0?null:o.userName),P(o.avatar??null);let c=s(o.thinkingView);z.current=c,R(c);try{sessionStorage.setItem(`maxy-admin-session-key`,o.session_key)}catch{}i(``),n(`chat`)}catch(e){console.error(`[admin] connection error:`,e),d(`Could not connect.`)}finally{g(!1)}}let J=(0,f.useCallback)(async e=>{if(e.preventDefault(),h)return;d(``);let t=o.trim();if(!t){d(`Please enter your name.`);return}if(r.length<4){d(`PIN must be at least 4 characters.`);return}let s=r;g(!0);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:s,name:t})});if(!e.ok){let t=await e.json().catch(()=>({}));if(e.status===401&&t?.code===`remote-auth-required`){a(`set-pin`,`/api/onboarding/set-pin`);return}if(e.status===409){try{let e=await fetch(`/api/health`);if(e.ok){let r=await e.json();r.pin_configured&&r.claude_authenticated?n(`enter-pin`):r.pin_configured?n(`connect-claude`):d(t.error||`Failed to set PIN.`)}else n(`enter-pin`)}catch{n(`enter-pin`)}return}d(t.error||`Failed to set PIN.`);return}let r=await fetch(`/api/health`);if((r.ok?await r.json():null)?.claude_authenticated){await q(s);return}i(``),n(`connect-claude`)}catch(e){console.error(`[admin] connection error:`,e),d(`Could not connect.`)}finally{g(!1)}},[r,h,o]),Y=(0,f.useCallback)(async e=>{e.preventDefault(),d(``),await q(r)},[r]),X=(0,f.useCallback)(async()=>{S(!0);try{if(!await u())return console.warn(`[admin-ui] claude-disconnect not verified — credentials may persist; staying put`),!1;U(!1),w(null),A(null),M(void 0),P(null);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}return n(`connect-claude`),!0}finally{S(!1)}},[]),Z=(0,f.useCallback)(()=>{w(null),A(null),M(void 0),P(null);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}i(``),d(``),n(`enter-pin`)},[]);return(0,f.useEffect)(()=>{K.current=Z},[Z]),{appState:t,setAppState:n,pin:r,setPin:i,operatorName:o,setOperatorName:c,pinError:l,setPinError:d,showPin:p,setShowPin:m,pinLoading:h,authPolling:_,setAuthPolling:v,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,expandAll:L,setExpandAll:R,expandAllDefaultRef:z,remoteAuthEnabled:B,claudeConnected:H,pinInputRef:W,setPinFormRef:G,handleSetPin:J,handleLogin:Y,handleDisconnect:X,handleLogout:Z}}var m=n();function h({inputRef:e,value:t,onChange:n,onComplete:r,showPin:i,autoFocus:a}){let o=(0,f.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,m.jsx)(`div`,{className:`pin-field`,children:Array.from({length:6}).map((n,r)=>(0,m.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 g(e){let{pin:t,setPin:n,showPin:r,setShowPin:a,pinLoading:s,pinError:u,pinInputRef:d,setPinFormRef:f,onSubmit:p,operatorName:g,setOperatorName:_}=e;return(0,m.jsx)(`div`,{className:`connect-page`,children:(0,m.jsxs)(`div`,{className:`connect-content`,children:[(0,m.jsx)(`img`,{src:o,alt:i.productName,className:`connect-logo connect-logo--maxy`}),!i.logoContainsName&&(0,m.jsxs)(`h1`,{className:`connect-title`,children:[`Welcome to `,i.productName]}),(0,m.jsxs)(`p`,{className:`connect-subtitle`,children:[`Tell `,i.productName,` who you are, then choose a PIN.`]}),(0,m.jsxs)(`form`,{ref:f,onSubmit:p,className:`connect-pin-form`,children:[(0,m.jsxs)(`div`,{className:`pin-input-row`,children:[(0,m.jsx)(`input`,{type:`text`,className:`connect-name-input`,placeholder:`Your full name`,value:g,onChange:e=>_(e.target.value),autoComplete:`name`,autoFocus:!0,required:!0,"aria-label":`Your full name`}),(0,m.jsx)(`div`,{style:{width:38,flexShrink:0},"aria-hidden":`true`})]}),(0,m.jsxs)(`div`,{className:`pin-input-row`,children:[(0,m.jsx)(h,{inputRef:d,value:t,onChange:n,onComplete:()=>{},showPin:r}),(0,m.jsx)(c,{variant:`send`,type:`submit`,disabled:!t||!g.trim(),loading:s,"aria-label":`Set PIN`,children:(0,m.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,m.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,m.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,m.jsx)(l,{checked:r,onChange:()=>a(e=>!e),label:`Show PIN`})]}),u&&(0,m.jsx)(`p`,{className:`admin-pin-error`,children:u})]})})}function _(e){let{pin:t,setPin:n,showPin:r,setShowPin:a,pinLoading:s,pinError:u,pinInputRef:d,onSubmit:f,remoteAuthEnabled:p,onSignOutRemote:g}=e;return(0,m.jsxs)(`div`,{className:`connect-page`,children:[p&&g&&(0,m.jsx)(`button`,{type:`button`,className:`connect-signout`,onClick:g,children:`Sign out`}),(0,m.jsxs)(`div`,{className:`connect-content`,children:[(0,m.jsx)(`img`,{src:o,alt:i.productName,className:`connect-logo connect-logo--maxy`}),!i.logoContainsName&&(0,m.jsx)(`h1`,{className:`connect-title`,children:i.productName}),(0,m.jsxs)(`form`,{onSubmit:f,className:`connect-pin-form`,children:[(0,m.jsxs)(`div`,{className:`pin-input-row`,children:[(0,m.jsx)(h,{inputRef:d,value:t,onChange:n,onComplete:()=>{},showPin:r,autoFocus:!0}),(0,m.jsx)(c,{variant:`send`,type:`submit`,disabled:!t,loading:s,children:(0,m.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,m.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,m.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,m.jsx)(`div`,{className:`pin-options`,children:(0,m.jsx)(l,{checked:r,onChange:()=>a(e=>!e),label:`Show PIN`})})]}),u&&(0,m.jsx)(`p`,{className:`admin-pin-error`,children:u})]})]})}function v(e){let{authPolling:t,setAuthPolling:n,authLoading:r,setAuthLoading:a,pinError:s,setPinError:l,setAppState:u}=e,[p,h]=(0,f.useState)(!1),[g,_]=(0,f.useState)(!1),[v,y]=(0,f.useState)(``),[b,x]=(0,f.useState)(``),[S,C]=(0,f.useState)(``),[w,T]=(0,f.useState)(null),[E,D]=(0,f.useState)(null),[O,k]=(0,f.useState)(!1),A=(0,f.useRef)(0);(0,f.useEffect)(()=>{try{D(sessionStorage.getItem(`maxy-admin-session-key`))}catch{}k(!0)},[]);async function j(){C(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`paste-code`,code:b})})).json();e.accepted?(C(`Code submitted. Finishing sign-in…`),x(``)):C(e.error||`Could not submit code.`)}catch(e){console.error(`[admin] paste-code error:`,e),C(`Could not submit code.`)}}async function M(){_(!0),l(``);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?h(!0):e.error&&l(e.error)}catch(e){console.error(`[admin] browser launch error:`,e),l(`Could not launch browser.`)}_(!1)}async function N(){let e=++A.current;a(!0),l(``);try{let t=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`})).json();if(t.started){n(!0),h(!0),a(!1),y(t.transport||``);for(let t=0;t<120;t++){if(await new Promise(e=>setTimeout(e,2e3)),A.current!==e)return;let t=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`wait`})})).json();if(typeof t.authTargetId==`string`&&T(t.authTargetId),t.authenticated){await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),u(`enter-pin`);return}}l(`Timed out waiting for sign-in. Try again.`),n(!1)}else t.error&&l(t.error)}catch(e){console.error(`[admin] auth flow error:`,e),l(`Could not start auth flow.`)}a(!1)}async function P(){A.current++,await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),n(!1),l(``)}return t||p?(0,m.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100dvh`,overflow:`auto`},children:[(0,m.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,m.jsx)(`button`,{onClick:P,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,m.jsx)(`button`,{onClick:()=>h(!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,m.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`chat-logo`}),(0,m.jsx)(`h1`,{className:`chat-tagline`,children:`Connect Claude`}),(0,m.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,m.jsx)(`div`,{style:{marginTop:`12px`},children:(0,m.jsx)(c,{variant:`primary`,onClick:N,disabled:r,children:r?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`})}),t&&v===`native`&&(0,m.jsxs)(`div`,{style:{marginTop:`14px`,maxWidth:`420px`,margin:`14px auto 0`,display:`flex`,flexDirection:`column`,gap:`8px`},children:[(0,m.jsx)(`label`,{style:{fontSize:`12px`,color:`#999`,lineHeight:1.4},children:`If the browser didn't finish sign-in, paste the code or full redirect URL from Claude's page:`}),(0,m.jsxs)(`div`,{style:{display:`flex`,gap:`8px`},children:[(0,m.jsx)(`input`,{type:`text`,value:b,onChange:e=>x(e.target.value),placeholder:`Paste code or redirect URL`,style:{flex:1,padding:`8px 10px`,fontSize:`13px`,border:`1px solid #ccc`,borderRadius:`6px`}}),(0,m.jsx)(c,{variant:`primary`,onClick:j,disabled:!b.trim(),children:`Submit`})]}),S&&(0,m.jsx)(`p`,{style:{fontSize:`12px`,color:`#999`,margin:0},children:S})]})]}),(0,m.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,minHeight:0,gap:`10px`,padding:`0 0 16px`},children:O&&(0,m.jsx)(d,{preferTargetId:w,cacheKey:E,chrome:!1})}),s&&(0,m.jsx)(`p`,{className:`admin-pin-error`,style:{textAlign:`center`,padding:`0 20px 16px`},children:s})]}):(0,m.jsx)(`div`,{className:`connect-page`,children:(0,m.jsxs)(`div`,{className:`connect-content`,children:[(0,m.jsxs)(`div`,{className:`connect-logos`,children:[(0,m.jsx)(`div`,{className:`connect-logo-wrap`,children:(0,m.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`connect-logo`})}),(0,m.jsx)(`svg`,{className:`connect-arrow`,viewBox:`0 0 48 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,m.jsx)(`path`,{d:`M0 12h44m0 0l-8-8m8 8l-8 8`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}),(0,m.jsxs)(`div`,{className:`connect-logo-wrap`,children:[(0,m.jsx)(`img`,{src:o,alt:i.productName,className:`connect-logo connect-logo--maxy`}),!i.logoContainsName&&(0,m.jsx)(`span`,{className:`connect-logo-label`,children:i.productName})]})]}),(0,m.jsxs)(`h1`,{className:`connect-title`,children:[`Connect Claude to power `,i.productName]}),(0,m.jsx)(`p`,{className:`connect-subtitle`,children:`Sign in with your Anthropic account to get started.`}),(0,m.jsx)(c,{variant:`primary`,onClick:N,disabled:r,children:r?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`}),(0,m.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,m.jsx)(`button`,{onClick:M,disabled:g,style:{marginTop:`12px`,background:`none`,border:`none`,color:`var(--color-primary, #666)`,fontSize:`13px`,cursor:`pointer`,textDecoration:`underline`,textUnderlineOffset:`3px`},children:g?`Launching…`:`Open browser first`}),s&&(0,m.jsx)(`p`,{className:`admin-pin-error`,children:s})]})})}function y({auth:e}){return e.appState===`loading`?(0,m.jsx)(r,{surface:`gate`}):e.appState===`set-pin`?(0,m.jsx)(g,{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,m.jsx)(v,{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,m.jsx)(_,{pin:e.pin,setPin:e.setPin,showPin:e.showPin,setShowPin:e.setShowPin,pinLoading:e.pinLoading,pinError:e.pinError,pinInputRef:e.pinInputRef,onSubmit:e.handleLogin,remoteAuthEnabled:e.remoteAuthEnabled,onSignOutRemote:()=>{window.location.href=`/__remote-auth/logout`}}):null}export{p as n,y as t};
|
|
1
|
+
import{o as e}from"./chunk-BycB0eMI.js";import{i as t,t as n}from"./jsx-runtime-BY35JYDT.js";import{N as r,it as i,lt as a,ot as o}from"./useMediaQuery-e4ciNiuO.js";import{P as s}from"./useVoiceRecorder-Cvu4TePf.js";import{D as c,O as l,k as u,p as d}from"./AdminShell-Dm_nY4jF.js";var f=e(t(),1);function p(e=`admin`){let[t,n]=(0,f.useState)(`loading`),[r,i]=(0,f.useState)(``),[o,c]=(0,f.useState)(``),[l,d]=(0,f.useState)(``),[p,m]=(0,f.useState)(!1),[h,g]=(0,f.useState)(!1),[_,v]=(0,f.useState)(!1),[y,b]=(0,f.useState)(!1),[x,S]=(0,f.useState)(!1),[C,w]=(0,f.useState)(null),[T,E]=(0,f.useState)(null),[D,O]=(0,f.useState)(void 0),[k,A]=(0,f.useState)(null),[j,M]=(0,f.useState)(void 0),[N,P]=(0,f.useState)(null),[F,I]=(0,f.useState)(null),[L,R]=(0,f.useState)(void 0),z=(0,f.useRef)(void 0),[B,V]=(0,f.useState)(!1),[H,U]=(0,f.useState)(!0);(0,f.useEffect)(()=>{typeof window>`u`||fetch(`/api/remote-auth/status`).then(e=>e.ok?e.json():null).then(e=>{e?.configured&&V(!0)}).catch(()=>{})},[]);let W=(0,f.useRef)(null),G=(0,f.useRef)(null);(0,f.useEffect)(()=>{async function e(){let e=null;try{e=sessionStorage.getItem(`maxy-admin-session-key`)}catch{}if(!e)return!1;try{let t=await fetch(`/api/admin/session?session_key=${encodeURIComponent(e)}`);if(t.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}return!1}if(!t.ok)return!1;let r=await t.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=s(r.thinkingView);return z.current=i,R(i),n(`chat`),!0}catch(e){return console.error(`[admin] session restore failed:`,e),!1}}async function t(r=2){try{let i=await fetch(`/api/health`);if(!i.ok){if(r>0)return await new Promise(e=>setTimeout(e,1500)),t(r-1);console.error(`[admin] health check returned ${i.status} after retries`),n(`set-pin`);return}let a=await i.json();if(!a.pin_configured){n(`set-pin`);return}U(!!a.claude_authenticated);let o=!1;try{o=new URLSearchParams(window.location.search).get(`connect`)===`claude`}catch{}if(o){try{let e=new URL(window.location.href);e.searchParams.delete(`connect`),window.history.replaceState(null,``,e.pathname+e.search+e.hash)}catch{}if(!a.claude_authenticated){n(`connect-claude`);return}}if(await e())return;n(`enter-pin`)}catch(e){if(r>0)return await new Promise(e=>setTimeout(e,1500)),t(r-1);console.error(`[admin] health check failed:`,e),n(`set-pin`)}}t()},[]),(0,f.useEffect)(()=>{t===`chat`&&C&&fetch(`/api/admin/claude-info?session_key=${encodeURIComponent(C)}`).then(e=>{if(e.ok)return e.json()}).then(e=>{e&&E(e)}).catch(()=>{})},[t,C]);let K=(0,f.useRef)(null);(0,f.useEffect)(()=>{if(t!==`chat`)return;let e=setInterval(async()=>{try{let e=await fetch(`/api/health`);if(e.ok){let t=await e.json();U(t.auth_status!==`dead`&&t.auth_status!==`missing`)}}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`;if(t===`remote-auth-required`){a(`heartbeat`,`/api/admin/session`);return}console.warn(`[admin-auth] outcome=heartbeat-detected-expiry code=${t}`),K.current?.()}catch{}},300*1e3);return()=>clearInterval(e)},[t,C]),(0,f.useEffect)(()=>{t===`connect-claude`&&fetch(`/api/health`).then(e=>e.ok?e.json():null).then(e=>{e?.claude_authenticated&&(U(!0),n(`enter-pin`))}).catch(()=>{})},[t]);async function q(e,t){g(!0);try{let r=await fetch(`/api/admin/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:e,...t?{accountId:t}:{}})});if(!r.ok){let e=await r.json().catch(()=>({}));if(r.status===401&&e?.code===`remote-auth-required`){a(`enter-pin`,`/api/admin/session`);return}d(e.error||`Invalid PIN`);return}let o=await r.json();w(o.session_key),I(o.sessionId??null),O(o.businessName),A(o.role??null),M(o.userName===void 0?null:o.userName),P(o.avatar??null);let c=s(o.thinkingView);z.current=c,R(c);try{sessionStorage.setItem(`maxy-admin-session-key`,o.session_key)}catch{}i(``),n(`chat`)}catch(e){console.error(`[admin] connection error:`,e),d(`Could not connect.`)}finally{g(!1)}}let J=(0,f.useCallback)(async e=>{if(e.preventDefault(),h)return;d(``);let t=o.trim();if(!t){d(`Please enter your name.`);return}if(r.length<4){d(`PIN must be at least 4 characters.`);return}let s=r;g(!0);try{let e=await fetch(`/api/onboarding/set-pin`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({pin:s,name:t})});if(!e.ok){let t=await e.json().catch(()=>({}));if(e.status===401&&t?.code===`remote-auth-required`){a(`set-pin`,`/api/onboarding/set-pin`);return}if(e.status===409){try{let e=await fetch(`/api/health`);if(e.ok){let r=await e.json();r.pin_configured&&r.claude_authenticated?n(`enter-pin`):r.pin_configured?n(`connect-claude`):d(t.error||`Failed to set PIN.`)}else n(`enter-pin`)}catch{n(`enter-pin`)}return}d(t.error||`Failed to set PIN.`);return}let r=await fetch(`/api/health`);if((r.ok?await r.json():null)?.claude_authenticated){await q(s);return}i(``),n(`connect-claude`)}catch(e){console.error(`[admin] connection error:`,e),d(`Could not connect.`)}finally{g(!1)}},[r,h,o]),Y=(0,f.useCallback)(async e=>{e.preventDefault(),d(``),await q(r)},[r]),X=(0,f.useCallback)(async()=>{S(!0);try{if(!await u())return console.warn(`[admin-ui] claude-disconnect not verified — credentials may persist; staying put`),!1;U(!1),w(null),A(null),M(void 0),P(null);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}return n(`connect-claude`),!0}finally{S(!1)}},[]),Z=(0,f.useCallback)(()=>{w(null),A(null),M(void 0),P(null);try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}i(``),d(``),n(`enter-pin`)},[]);return(0,f.useEffect)(()=>{K.current=Z},[Z]),{appState:t,setAppState:n,pin:r,setPin:i,operatorName:o,setOperatorName:c,pinError:l,setPinError:d,showPin:p,setShowPin:m,pinLoading:h,authPolling:_,setAuthPolling:v,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,expandAll:L,setExpandAll:R,expandAllDefaultRef:z,remoteAuthEnabled:B,claudeConnected:H,pinInputRef:W,setPinFormRef:G,handleSetPin:J,handleLogin:Y,handleDisconnect:X,handleLogout:Z}}var m=n();function h({inputRef:e,value:t,onChange:n,onComplete:r,showPin:i,autoFocus:a}){let o=(0,f.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,m.jsx)(`div`,{className:`pin-field`,children:Array.from({length:6}).map((n,r)=>(0,m.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 g(e){let{pin:t,setPin:n,showPin:r,setShowPin:a,pinLoading:s,pinError:u,pinInputRef:d,setPinFormRef:f,onSubmit:p,operatorName:g,setOperatorName:_}=e;return(0,m.jsx)(`div`,{className:`connect-page`,children:(0,m.jsxs)(`div`,{className:`connect-content`,children:[(0,m.jsx)(`img`,{src:o,alt:i.productName,className:`connect-logo connect-logo--maxy`}),!i.logoContainsName&&(0,m.jsxs)(`h1`,{className:`connect-title`,children:[`Welcome to `,i.productName]}),(0,m.jsxs)(`p`,{className:`connect-subtitle`,children:[`Tell `,i.productName,` who you are, then choose a PIN.`]}),(0,m.jsxs)(`form`,{ref:f,onSubmit:p,className:`connect-pin-form`,children:[(0,m.jsxs)(`div`,{className:`pin-input-row`,children:[(0,m.jsx)(`input`,{type:`text`,className:`connect-name-input`,placeholder:`Your full name`,value:g,onChange:e=>_(e.target.value),autoComplete:`name`,autoFocus:!0,required:!0,"aria-label":`Your full name`}),(0,m.jsx)(`div`,{style:{width:38,flexShrink:0},"aria-hidden":`true`})]}),(0,m.jsxs)(`div`,{className:`pin-input-row`,children:[(0,m.jsx)(h,{inputRef:d,value:t,onChange:n,onComplete:()=>{},showPin:r}),(0,m.jsx)(c,{variant:`send`,type:`submit`,disabled:!t||!g.trim(),loading:s,"aria-label":`Set PIN`,children:(0,m.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,m.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,m.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,m.jsx)(l,{checked:r,onChange:()=>a(e=>!e),label:`Show PIN`})]}),u&&(0,m.jsx)(`p`,{className:`admin-pin-error`,children:u})]})})}function _(e){let{pin:t,setPin:n,showPin:r,setShowPin:a,pinLoading:s,pinError:u,pinInputRef:d,onSubmit:f,remoteAuthEnabled:p,onSignOutRemote:g}=e;return(0,m.jsxs)(`div`,{className:`connect-page`,children:[p&&g&&(0,m.jsx)(`button`,{type:`button`,className:`connect-signout`,onClick:g,children:`Sign out`}),(0,m.jsxs)(`div`,{className:`connect-content`,children:[(0,m.jsx)(`img`,{src:o,alt:i.productName,className:`connect-logo connect-logo--maxy`}),!i.logoContainsName&&(0,m.jsx)(`h1`,{className:`connect-title`,children:i.productName}),(0,m.jsxs)(`form`,{onSubmit:f,className:`connect-pin-form`,children:[(0,m.jsxs)(`div`,{className:`pin-input-row`,children:[(0,m.jsx)(h,{inputRef:d,value:t,onChange:n,onComplete:()=>{},showPin:r,autoFocus:!0}),(0,m.jsx)(c,{variant:`send`,type:`submit`,disabled:!t,loading:s,children:(0,m.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,m.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,m.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]}),(0,m.jsx)(`div`,{className:`pin-options`,children:(0,m.jsx)(l,{checked:r,onChange:()=>a(e=>!e),label:`Show PIN`})})]}),u&&(0,m.jsx)(`p`,{className:`admin-pin-error`,children:u})]})]})}function v(e){let{authPolling:t,setAuthPolling:n,authLoading:r,setAuthLoading:a,pinError:s,setPinError:l,setAppState:u}=e,[p,h]=(0,f.useState)(!1),[g,_]=(0,f.useState)(!1),[v,y]=(0,f.useState)(``),[b,x]=(0,f.useState)(``),[S,C]=(0,f.useState)(``),[w,T]=(0,f.useState)(null),[E,D]=(0,f.useState)(null),[O,k]=(0,f.useState)(!1),A=(0,f.useRef)(0);(0,f.useEffect)(()=>{try{D(sessionStorage.getItem(`maxy-admin-session-key`))}catch{}k(!0)},[]);async function j(){C(``);try{let e=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`paste-code`,code:b})})).json();e.accepted?(C(`Code submitted. Finishing sign-in…`),x(``)):C(e.error||`Could not submit code.`)}catch(e){console.error(`[admin] paste-code error:`,e),C(`Could not submit code.`)}}async function M(){_(!0),l(``);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?h(!0):e.error&&l(e.error)}catch(e){console.error(`[admin] browser launch error:`,e),l(`Could not launch browser.`)}_(!1)}async function N(){let e=++A.current;a(!0),l(``);try{let t=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`})).json();if(t.started){n(!0),h(!0),a(!1),y(t.transport||``);for(let t=0;t<120;t++){if(await new Promise(e=>setTimeout(e,2e3)),A.current!==e)return;let t=await(await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`wait`})})).json();if(typeof t.authTargetId==`string`&&T(t.authTargetId),t.authenticated){await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),u(`enter-pin`);return}}l(`Timed out waiting for sign-in. Try again.`),n(!1)}else t.error&&l(t.error)}catch(e){console.error(`[admin] auth flow error:`,e),l(`Could not start auth flow.`)}a(!1)}async function P(){A.current++,await fetch(`/api/onboarding/claude-auth`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:`stop`})}),n(!1),l(``)}return t||p?(0,m.jsxs)(`div`,{style:{display:`flex`,flexDirection:`column`,height:`100dvh`,overflow:`auto`},children:[(0,m.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,m.jsx)(`button`,{onClick:P,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,m.jsx)(`button`,{onClick:()=>h(!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,m.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`chat-logo`}),(0,m.jsx)(`h1`,{className:`chat-tagline`,children:`Connect Claude`}),(0,m.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,m.jsx)(`div`,{style:{marginTop:`12px`},children:(0,m.jsx)(c,{variant:`primary`,onClick:N,disabled:r,children:r?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`})}),t&&v===`native`&&(0,m.jsxs)(`div`,{style:{marginTop:`14px`,maxWidth:`420px`,margin:`14px auto 0`,display:`flex`,flexDirection:`column`,gap:`8px`},children:[(0,m.jsx)(`label`,{style:{fontSize:`12px`,color:`#999`,lineHeight:1.4},children:`If the browser didn't finish sign-in, paste the code or full redirect URL from Claude's page:`}),(0,m.jsxs)(`div`,{style:{display:`flex`,gap:`8px`},children:[(0,m.jsx)(`input`,{type:`text`,value:b,onChange:e=>x(e.target.value),placeholder:`Paste code or redirect URL`,style:{flex:1,padding:`8px 10px`,fontSize:`13px`,border:`1px solid #ccc`,borderRadius:`6px`}}),(0,m.jsx)(c,{variant:`primary`,onClick:j,disabled:!b.trim(),children:`Submit`})]}),S&&(0,m.jsx)(`p`,{style:{fontSize:`12px`,color:`#999`,margin:0},children:S})]})]}),(0,m.jsx)(`div`,{style:{flex:1,display:`flex`,flexDirection:`column`,minHeight:0,gap:`10px`,padding:`0 0 16px`},children:O&&(0,m.jsx)(d,{preferTargetId:w,cacheKey:E,chrome:!1})}),s&&(0,m.jsx)(`p`,{className:`admin-pin-error`,style:{textAlign:`center`,padding:`0 20px 16px`},children:s})]}):(0,m.jsx)(`div`,{className:`connect-page`,children:(0,m.jsxs)(`div`,{className:`connect-content`,children:[(0,m.jsxs)(`div`,{className:`connect-logos`,children:[(0,m.jsx)(`div`,{className:`connect-logo-wrap`,children:(0,m.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`connect-logo`})}),(0,m.jsx)(`svg`,{className:`connect-arrow`,viewBox:`0 0 48 24`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:(0,m.jsx)(`path`,{d:`M0 12h44m0 0l-8-8m8 8l-8 8`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`})}),(0,m.jsxs)(`div`,{className:`connect-logo-wrap`,children:[(0,m.jsx)(`img`,{src:o,alt:i.productName,className:`connect-logo connect-logo--maxy`}),!i.logoContainsName&&(0,m.jsx)(`span`,{className:`connect-logo-label`,children:i.productName})]})]}),(0,m.jsxs)(`h1`,{className:`connect-title`,children:[`Connect Claude to power `,i.productName]}),(0,m.jsx)(`p`,{className:`connect-subtitle`,children:`Sign in with your Anthropic account to get started.`}),(0,m.jsx)(c,{variant:`primary`,onClick:N,disabled:r,children:r?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`span`,{className:`spin`,style:{display:`inline-block`},children:`✱`}),` Connecting…`]}):`Sign in to Claude`}),(0,m.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,m.jsx)(`button`,{onClick:M,disabled:g,style:{marginTop:`12px`,background:`none`,border:`none`,color:`var(--color-primary, #666)`,fontSize:`13px`,cursor:`pointer`,textDecoration:`underline`,textUnderlineOffset:`3px`},children:g?`Launching…`:`Open browser first`}),s&&(0,m.jsx)(`p`,{className:`admin-pin-error`,children:s})]})})}function y({auth:e}){return e.appState===`loading`?(0,m.jsx)(r,{surface:`gate`}):e.appState===`set-pin`?(0,m.jsx)(g,{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,m.jsx)(v,{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,m.jsx)(_,{pin:e.pin,setPin:e.setPin,showPin:e.showPin,setShowPin:e.setShowPin,pinLoading:e.pinLoading,pinError:e.pinError,pinInputRef:e.pinInputRef,onSubmit:e.handleLogin,remoteAuthEnabled:e.remoteAuthEnabled,onSignOutRemote:()=>{window.location.href=`/__remote-auth/logout`}}):null}export{p as n,y as t};
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./chunk-BycB0eMI.js";import{i as t,n,t as r}from"./jsx-runtime-BY35JYDT.js";import{C as i,E as a,F as o,P as s,R as c,ct as l,h as u,i as d,k as f,p,y as ee}from"./useMediaQuery-e4ciNiuO.js";import{n as m,t as h}from"./AdminLoginScreens-Bjsr45ed.js";import{T as g,c as _,p as te}from"./useVoiceRecorder-D7_wLtrS.js";import{h as ne,i as v,t as y,w as re,x as b}from"./AdminShell-Dm_nY4jF.js";import{t as x}from"./chevron-left-D3_hiHLC.js";import{i as S,n as C,r as ie}from"./page-CdRrpkky.js";import{t as ae}from"./file-text-CVZAL3Er.js";import"./graph-labels-BTFUSc63.js";import{n as oe}from"./file-download-B7zwa78w.js";var w=n(),T=e(t(),1),E=r();function D({onOpen:e}){return(0,E.jsx)(`footer`,{className:`admin-footer`,children:(0,E.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,E.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`powered-by-icon`}),(0,E.jsx)(`span`,{children:`Powered by Claude Code`})]})})}function O({sessionId:e,projectDir:t,sessionKey:n,contactName:r,onBack:i}){return(0,E.jsxs)(`div`,{className:`wa-web`,children:[(0,E.jsxs)(`header`,{className:`wa-web-header`,children:[i&&(0,E.jsx)(`button`,{type:`button`,className:`wa-web-back`,onClick:i,"aria-label":`Back`,children:(0,E.jsx)(x,{size:20})}),(0,E.jsx)(`span`,{className:`wa-web-avatar`,"aria-hidden":!0,children:(0,E.jsx)(g,{size:20})}),(0,E.jsx)(`div`,{className:`wa-web-titles`,children:(0,E.jsx)(`span`,{className:`wa-web-name`,children:r})})]}),(0,E.jsx)(`div`,{className:`wa-web-body`,children:(0,E.jsx)(_,{sessionId:e,projectDir:t,sessionKey:n,forceDeliveredOnly:!0})})]})}var k=6e4,A=60*k,j=24*A,M=k,N=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],P=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function F(e){return e<10?`0${e}`:String(e)}function I(e,t){let n=f(e,t);return Date.UTC(n.y,n.m-1,n.d)}function L(e,t,n){if(!Number.isFinite(e)||e<=0||!Number.isFinite(t))return`—`;let r=t-e;if(r<-M)return`—`;let i=r<0?0:r;if(i<k)return`just now`;if(i<A)return`${Math.floor(i/k)}m`;if(i<j)return`${Math.floor(i/A)}h`;let a=I(new Date(t),n),o=I(new Date(e),n),s=Math.round((a-o)/j);if(s===1)return`yesterday`;let c=f(new Date(e),n);if(s>=2&&s<=6)return P[new Date(o).getUTCDay()];let l=F(c.d),u=N[c.m-1],d=f(new Date(t),n).y;return c.y===d?`${l} ${u}`:`${l} ${u} ${c.y}`}function R({variant:e=`row`,count:t=1}){return(0,E.jsx)(E.Fragment,{children:Array.from({length:t},(t,n)=>(0,E.jsx)(`span`,{className:`dashboard-skeleton dashboard-skeleton--${e}`,"data-testid":`dashboard-skeleton`,"aria-hidden":`true`},n))})}var se=6e4;function ce(e){return e<12?`morning`:e<18?`afternoon`:`evening`}function z(e){return e&&e.trim().split(/\s+/)[0]||`there`}function le(e){if(!e)return`everything is running normally.`;let t=e.cpuPct,n=e.memUsedPct;return t!==null&&t>=.98||n!==null&&n>=.98?`system load is critical.`:t!==null&&t>=.9||n!==null&&n>=.9?`system load is high.`:`everything is running normally.`}function B(e){return e==null?`—`:`${Math.round(e*100)}%`}function V(e){let t=Date.parse(e.lastMessageAt??``);return Number.isFinite(t)?t:-1/0}function ue(e,t,n){if(!e)return!1;let r=Date.parse(e);return Number.isFinite(r)?a(new Date(r),n)===a(new Date(t),n):!1}function de(e){return e?e.replace(/^claude-/,``):null}function fe(e,t,n,r,i){let a=0;for(let e=1;e<n.length;e+=1)V(n[e-1])<V(n[e])&&(a+=1);let o=!1;for(let e=1;e<t.length;e+=1)if(t[e-1].channel!==t[e].channel){o=!0;break}let s=new Map;for(let t of e)s.set(t.channel,(s.get(t.channel)??0)+1);return{feedRows:e.length,renderedRows:n.length,cap:r,hidden:e.length-n.length,expanded:i,outOfOrder:a,undated:e.filter(e=>V(e)===-1/0).length,channels:[...s.entries()].map(([e,t])=>`${e}:${t}`).join(`,`),interleaved:o}}var H=new Set([`sessions`,`conversations`,`tasks`,`artefacts`,`skills`,`stats`]),U=!1;function pe(e,t,n,r){let i=e=>t.get(e)??null,a=r?r.getEntriesByType(`navigation`)[0]:void 0,o=r?r.getEntriesByType(`resource`).filter(e=>new URL(e.name,`http://x`).pathname.startsWith(`/assets/`)):[],s=e=>e===void 0||!Number.isFinite(e)?null:Math.round(e),c=e=>e?s(e):null;return{batchMs:e,sessionsMs:i(`sessions`),conversationsMs:i(`conversations`),tasksMs:i(`tasks`),artefactsMs:i(`artefacts`),skillsMs:i(`skills`),statsMs:i(`stats`),failed:[...H].filter(e=>n.has(e)).join(`,`)||`none`,ttfbMs:s(a?.responseStart),domContentLoadedMs:c(a?.domContentLoadedEventEnd),loadMs:c(a?.loadEventEnd),assetCount:o.length,assetBytes:o.reduce((e,t)=>e+(t.transferSize||0),0),assetMs:o.length?s(Math.max(...o.map(e=>e.responseEnd))):null}}function W({cacheKey:e,userName:t,onSelectWhatsappConversation:n}){let{zone:r}=i(),a=o(e),[s,f]=(0,T.useState)(null),[m,h]=(0,T.useState)(null),[g,_]=(0,T.useState)(null),[v,y]=(0,T.useState)(null),[x,S]=(0,T.useState)(null),[C,ie]=(0,T.useState)(null),[w,D]=(0,T.useState)(null),[O,k]=(0,T.useState)(null),[A,j]=(0,T.useState)(null),[M,N]=(0,T.useState)(new Set),[P,F]=(0,T.useState)(()=>new Set),I=(0,T.useCallback)(e=>{F(t=>t.has(e)?t:new Set(t).add(e))},[]),H=Date.now(),W=(0,T.useRef)(!1),G=(0,T.useRef)(new Map),me=(0,T.useRef)(new Set),K=(0,T.useRef)(null);(0,T.useEffect)(()=>{if(!e)return;let t=!1;async function n(e,n,r,i){let o=Date.now(),s=typeof n==`string`?n:`unresolved`;try{typeof n!=`string`&&(s=await n());let e=await a(s);if(!e.ok)throw Error(`status ${e.status}`);let o=await e.json();t||i(r(o))}catch(t){me.current.add(e),console.error(`[admin-ui] dashboard-fetch-failed slice=${e} url=${s} ms=${Date.now()-o} reason=${t instanceof Error?t.message:String(t)}`)}finally{G.current.set(e,Date.now()-o),I(e)}}async function r(){if(!K.current){let e=await a(`/api/admin/accounts`);if(!e.ok)throw Error(`accounts status ${e.status}`);let t=await e.json(),n=t.accounts??[],r=t.activeAccountId??null,i=n.find(e=>e.accountId===r);if(!i)throw Error(`accounts: active ${r??`none`} absent from list of ${n.length}`);let o=i.isHouse||n.length===1;K.current={accountId:i.accountId,isHouse:o}}let{accountId:e,isHouse:t}=K.current;return t?`/api/operator-conversations/conversations-all`:`/api/operator-conversations/conversations`}let i={"sidebar-sessions":()=>n(`sessions`,`/api/admin/sidebar-sessions`,e=>e.sessions??[],f),"conversations-all":()=>n(`conversations`,r,e=>e.conversations??[],h),"tasks-list":()=>n(`tasks`,`/api/admin/tasks-list`,e=>e,y),"sidebar-artefacts":()=>n(`artefacts`,`/api/admin/sidebar-artefacts`,e=>e.artefacts??[],S),skills:()=>n(`skills`,`/api/admin/skills`,e=>e.skills??[],ie)};async function o(){if(W.current)return;W.current=!0;let e=Date.now();try{await Promise.all([...Object.values(i).map(e=>e()),n(`stats`,`/api/admin/system-stats`,e=>e,_),n(`bookingLink`,`/api/admin/calendar/booking-link`,e=>e.bookingDomain??null,D),n(`portalLink`,`/api/admin/data-portal/portal-link`,e=>e.portalDomain??null,k),n(`plannerLink`,`/api/admin/dispatch-planner/planner-link`,e=>e.plannerUrl??null,j)])}finally{W.current=!1;let t=Date.now()-e;if(!U){U=!0;try{let e=pe(t,G.current,me.current,typeof performance>`u`?null:performance);fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`event`,source:`dashboard-load`,...e}),keepalive:!0}).catch(()=>{})}catch{}}}}o();let s=null;try{s=new EventSource(l(`/api/admin/events`,e)),s.onmessage=e=>{if(document.visibilityState===`visible`)try{let{resource:t}=JSON.parse(e.data),n=t?i[t]:void 0;n&&n()}catch{}},s.onerror=()=>{console.error(`[admin-ui] dashboard-events stream error`)}}catch(e){console.error(`[admin-ui] dashboard-events unavailable reason=${e instanceof Error?e.message:String(e)}`)}let c=setInterval(()=>{document.visibilityState===`visible`&&o()},se),u=()=>{document.visibilityState===`visible`&&o()};return document.addEventListener(`visibilitychange`,u),()=>{t=!0,W.current=!1,clearInterval(c),s?.close(),document.removeEventListener(`visibilitychange`,u)}},[e,a]);let q=(0,T.useMemo)(()=>(s??[]).filter(e=>!e.isSubagent),[s]),J=(0,T.useMemo)(()=>q.filter(e=>e.live),[q]),he=(0,T.useMemo)(()=>(m??[]).filter(e=>ue(e.lastMessageAt,H,r)).length,[m,H]),ge=v?.open.length??0,Y=(0,T.useMemo)(()=>[...m??[]].sort((e,t)=>{let n=V(e),r=V(t);return n===r?0:r>n?1:-1}),[m]),[X,_e]=(0,T.useState)(!1),Z=X?Y:Y.slice(0,8),ve=Y.length-Z.length,ye=(0,T.useRef)(null),Q=(0,T.useRef)(null);(0,T.useEffect)(()=>{if(!P.has(`conversations`))return;let e=fe(m??[],Y,Z,8,X),t=JSON.stringify(e);ye.current!==t&&(ye.current=t,Q.current===null&&(Q.current=d()),fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`event`,source:`channels-card`,renderId:Q.current,...e})}).catch(()=>{}))},[P,m,Y,Z,X]);let be=(0,T.useRef)(!1);(0,T.useEffect)(()=>{be.current||!P.has(`bookingLink`)||!P.has(`portalLink`)||!P.has(`plannerLink`)||(be.current=!0)},[P,w,O,A]);let xe=(0,T.useCallback)(async e=>{if(!M.has(e)){N(t=>new Set(t).add(e));try{let t=await a(`/api/admin/session-stop`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e})});if(!t.ok){console.error(`[admin-ui] dashboard-session-stop-failed sessionId=${e} status=${t.status}`);return}f(t=>(t??[]).map(t=>t.sessionId===e?{...t,live:!1}:t))}catch(t){console.error(`[admin-ui] dashboard-session-stop-failed sessionId=${e} reason=${t instanceof Error?t.message:String(t)}`)}finally{N(t=>{let n=new Set(t);return n.delete(e),n})}}},[a,M]),Se=(0,T.useCallback)(t=>{if(!e||!t.downloadPath){console.error(`[admin-ui] dashboard-artefact-download-blocked id=${t.id} reason=${e?`not-downloadable`:`no-cache-key`}`);return}oe(e,t.downloadPath,t.downloadRoot??`data`)},[e]),$=ce(new Date(H).getHours());return(0,E.jsxs)(`div`,{className:`ui-page ui-page--full dashboard-home`,children:[(0,E.jsx)(`p`,{className:`dashboard-greeting`,children:P.has(`stats`)?`Good ${$}, ${z(t)} — ${le(g)}`:`Good ${$}, ${z(t)}`}),(0,E.jsxs)(`div`,{className:`dashboard-stats`,children:[(0,E.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,E.jsx)(`span`,{className:`dashboard-stat-label`,children:`Live sessions`}),P.has(`sessions`)?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`span`,{className:`dashboard-stat-value`,children:J.length}),(0,E.jsxs)(`span`,{className:`dashboard-stat-delta`,children:[`of `,q.length,` total`]})]}):(0,E.jsx)(R,{variant:`value`})]}),(0,E.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,E.jsx)(`span`,{className:`dashboard-stat-label`,children:`Messages today`}),P.has(`conversations`)?(0,E.jsx)(`span`,{className:`dashboard-stat-value`,children:he}):(0,E.jsx)(R,{variant:`value`})]}),(0,E.jsxs)(`a`,{className:`admin-stat-card dashboard-stat-card dashboard-stat-card--link`,href:`/tasks`,children:[(0,E.jsx)(`span`,{className:`dashboard-stat-label`,children:`Open tasks`}),P.has(`tasks`)?(0,E.jsx)(`span`,{className:`dashboard-stat-value`,children:ge}):(0,E.jsx)(R,{variant:`value`})]}),(0,E.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,E.jsx)(`span`,{className:`dashboard-stat-label`,children:`Host CPU`}),P.has(`stats`)?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`span`,{className:`dashboard-stat-value`,children:B(g?.cpuPct??null)}),(0,E.jsxs)(`span`,{className:`dashboard-stat-delta`,children:[`RAM `,B(g?.memUsedPct??null)]})]}):(0,E.jsx)(R,{variant:`value`})]})]}),(0,E.jsxs)(`div`,{className:`dashboard-columns`,children:[(0,E.jsxs)(`div`,{className:`dashboard-col`,children:[(w||O||A)&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Public pages`}),(0,E.jsxs)(`div`,{className:`admin-card dashboard-public-pages`,children:[w&&(0,E.jsxs)(`a`,{className:`admin-row dashboard-public-row`,href:`https://${w}`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,E.jsx)(`span`,{className:`dashboard-public-icon`,children:(0,E.jsx)(b,{size:16})}),(0,E.jsx)(`span`,{className:`dashboard-public-name`,children:`Booking page`})]}),O&&(0,E.jsxs)(`a`,{className:`admin-row dashboard-public-row`,href:`https://${O}`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,E.jsx)(`span`,{className:`dashboard-public-icon`,children:(0,E.jsx)(b,{size:16})}),(0,E.jsx)(`span`,{className:`dashboard-public-name`,children:`File drop`})]}),A&&(0,E.jsxs)(`a`,{className:`admin-row dashboard-public-row`,href:A,target:`_blank`,rel:`noopener noreferrer`,children:[(0,E.jsx)(`span`,{className:`dashboard-public-icon`,children:(0,E.jsx)(b,{size:16})}),(0,E.jsx)(`span`,{className:`dashboard-public-name`,children:`Planner`})]})]})]}),(0,E.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Live now`}),P.has(`sessions`)?J.length===0?(0,E.jsx)(`div`,{className:`admin-card dashboard-empty`,children:`No live sessions right now.`}):J.map(e=>{let t=[e.sessionId.slice(0,8),de(e.model),L(Date.parse(e.startedAt),H,r)].filter(Boolean).join(` · `);return(0,E.jsxs)(`div`,{className:`admin-card dashboard-live-card`,children:[(0,E.jsx)(`span`,{className:`admin-status-dot is-live`}),(0,E.jsxs)(`div`,{className:`dashboard-live-main`,children:[(0,E.jsx)(`span`,{className:`dashboard-live-name`,children:e.title}),(0,E.jsx)(`span`,{className:`dashboard-live-meta`,children:t})]}),(0,E.jsx)(`a`,{className:`admin-btn-cta dashboard-open-btn`,href:`/chat?session=${encodeURIComponent(e.sessionId)}`,children:`Open`}),(0,E.jsx)(`button`,{type:`button`,className:`dashboard-stop-btn`,"aria-label":`Stop ${e.title}`,disabled:M.has(e.sessionId),onClick:()=>void xe(e.sessionId),children:(0,E.jsx)(c,{size:12})})]},e.sessionId)}):(0,E.jsx)(R,{variant:`card`,count:2}),(0,E.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Recent artefacts`}),(0,E.jsx)(`div`,{className:`admin-card dashboard-artefacts`,children:P.has(`artefacts`)?(x??[]).length===0?(0,E.jsx)(`div`,{className:`dashboard-empty`,children:`No recent artefacts.`}):(x??[]).slice(0,6).map(e=>(0,E.jsxs)(`button`,{type:`button`,className:`admin-row dashboard-artefact-row`,onClick:()=>Se(e),children:[(0,E.jsx)(`span`,{className:`dashboard-artefact-icon`,children:e.kind===`agent-template`?(0,E.jsx)(re,{size:16}):(0,E.jsx)(ae,{size:16})}),(0,E.jsx)(`div`,{className:`dashboard-artefact-body`,children:(0,E.jsx)(`span`,{className:`dashboard-artefact-name`,children:e.name})}),(0,E.jsx)(`span`,{className:`dashboard-artefact-time`,children:L(Date.parse(e.updatedAt),H,r)})]},e.id)):(0,E.jsx)(R,{count:3})}),(0,E.jsx)(`a`,{className:`admin-section-label dashboard-col-label dashboard-skills-label`,href:`/skills`,children:`Skills`}),(0,E.jsx)(`div`,{className:`admin-card dashboard-skills`,children:P.has(`skills`)?(C??[]).length===0?(0,E.jsx)(`div`,{className:`dashboard-empty`,children:`No skills yet.`}):(C??[]).map(e=>(0,E.jsxs)(`a`,{className:`admin-row dashboard-skill-row`,href:`/skills`,children:[(0,E.jsx)(`span`,{className:`dashboard-skill-icon`,children:(0,E.jsx)(ne,{size:16})}),(0,E.jsxs)(`div`,{className:`dashboard-skill-body`,children:[(0,E.jsx)(`span`,{className:`dashboard-skill-name`,children:e.skill}),(0,E.jsx)(`span`,{className:`dashboard-skill-plugin`,children:e.plugin})]})]},`${e.plugin}/${e.skill}`)):(0,E.jsx)(R,{count:2})})]}),(0,E.jsxs)(`div`,{className:`dashboard-col`,children:[(0,E.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Channels`}),P.has(`conversations`)?Y.length===0?(0,E.jsx)(`div`,{className:`admin-card dashboard-empty`,children:`No channel activity.`}):(0,E.jsxs)(`div`,{className:`admin-card dashboard-channel-card`,children:[(0,E.jsx)(`div`,{className:`dashboard-channel-convs`,children:Z.map(t=>(0,E.jsxs)(`button`,{type:`button`,className:`admin-row dashboard-channel-conv-row`,onClick:()=>n(t),title:t.title,children:[(0,E.jsxs)(`span`,{className:`dashboard-channel-conv-line`,children:[(0,E.jsx)(`span`,{className:`dashboard-channel-conv-glyph`,children:(0,E.jsx)(ee,{channel:t.channel,size:13})}),(0,E.jsx)(te,{accountId:t.accountId??``,jid:t.remoteJid,sessionKey:e??``,className:`dashboard-channel-conv-avatar`,size:16}),(0,E.jsx)(`span`,{className:`dashboard-channel-conv-name`,children:p(t)}),t.isGroup===!0&&(0,E.jsx)(`span`,{className:`dashboard-channel-conv-tag is-group`,children:`Group`}),t.role===`public`&&(0,E.jsx)(`span`,{className:`dashboard-channel-conv-tag is-public`,children:`Public`}),(0,E.jsx)(`span`,{className:`dashboard-channel-conv-tag`,children:t.isHouse?`House`:`Client`}),!t.preview&&t.lastMessageAt&&(0,E.jsx)(`span`,{className:`dashboard-channel-conv-time`,children:L(Date.parse(t.lastMessageAt),H,r)})]}),t.preview?(0,E.jsxs)(`span`,{className:`dashboard-channel-conv-sub`,children:[(0,E.jsx)(`span`,{className:`dashboard-channel-conv-preview`,children:t.preview}),t.lastMessageAt&&(0,E.jsx)(`span`,{className:`dashboard-channel-conv-time`,children:L(Date.parse(t.lastMessageAt),H,r)})]}):null]},u(t)))}),ve>0&&(0,E.jsxs)(`button`,{type:`button`,className:`dashboard-channel-more`,onClick:()=>_e(!0),children:[`Show `,ve,` more`]})]}):(0,E.jsx)(R,{variant:`card`,count:2})]})]})]})}function G(){let e=m(),[t,n]=(0,T.useState)(!1);(0,T.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,T.useCallback)(async()=>{let t=e.claudeInfo!=null;if(n(!0),t)return;let r=Date.now();if(!e.cacheKey){console.error(`[admin-ui] claude-info-fetch-skipped reason=no-session-key`);return}try{let t=await fetch(`/api/admin/claude-info?session_key=${encodeURIComponent(e.cacheKey)}`);if(t.ok){let n=await t.json();e.setClaudeInfo(n)}}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,T.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===`chat`?(0,E.jsx)(s,{cacheKey:e.cacheKey,onSessionExpired:i,surface:`chat`,children:(0,E.jsx)(y,{cacheKey:e.cacheKey,businessName:e.businessName,sessionId:e.sessionId,onLogout:e.handleLogout,onDisconnect:e.handleDisconnect,disconnecting:e.disconnecting,claudeConnected:e.claudeConnected,onConnectClaude:()=>e.setAppState(`connect-claude`),userName:e.userName,userAvatar:e.userAvatar,role:e.role,footer:(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(D,{onOpen:r}),(0,E.jsx)(v,{show:t,onClose:()=>n(!1),claudeInfo:e.claudeInfo,messages:[],sessionElapsed:0,sessionId:e.sessionId,cacheKey:e.cacheKey})]}),children:t=>(0,E.jsx)(E.Fragment,{children:t.dataOpen&&e.cacheKey?(0,E.jsx)(C,{cacheKey:e.cacheKey}):t.selectedWhatsapp&&e.cacheKey?t.selectedWhatsapp.source===`store`&&t.selectedWhatsapp.channel===`telegram`&&t.selectedWhatsapp.channelKey&&t.selectedWhatsapp.accountId?(0,E.jsx)(S,{accountId:t.selectedWhatsapp.accountId,channelKey:t.selectedWhatsapp.channelKey,contactName:p(t.selectedWhatsapp),sessionKey:e.cacheKey,onBack:t.onClearWhatsapp},u(t.selectedWhatsapp)):t.selectedWhatsapp.source===`store`&&t.selectedWhatsapp.remoteJid&&t.selectedWhatsapp.accountId?(0,E.jsx)(ie,{accountId:t.selectedWhatsapp.accountId,remoteJid:t.selectedWhatsapp.remoteJid,contactName:p(t.selectedWhatsapp),sessionKey:e.cacheKey,onBack:t.onClearWhatsapp},u(t.selectedWhatsapp)):(0,E.jsx)(O,{sessionId:t.selectedWhatsapp.sessionId,projectDir:t.selectedWhatsapp.projectDir,sessionKey:e.cacheKey,contactName:p(t.selectedWhatsapp),onBack:t.onClearWhatsapp},u(t.selectedWhatsapp)):(0,E.jsx)(W,{cacheKey:e.cacheKey,userName:e.userName,onSelectWhatsappConversation:t.onSelectWhatsappConversation})})})}):(0,E.jsx)(h,{auth:e})}(0,w.createRoot)(document.getElementById(`root`)).render((0,E.jsx)(G,{}));
|
|
1
|
+
import{o as e}from"./chunk-BycB0eMI.js";import{i as t,n,t as r}from"./jsx-runtime-BY35JYDT.js";import{C as i,E as a,F as o,P as s,R as c,ct as l,h as u,i as d,k as f,p,y as ee}from"./useMediaQuery-e4ciNiuO.js";import{n as m,t as h}from"./AdminLoginScreens-BiHOXO0Y.js";import{T as g,c as _,p as te}from"./useVoiceRecorder-Cvu4TePf.js";import{h as ne,i as v,t as y,w as re,x as b}from"./AdminShell-Dm_nY4jF.js";import{t as x}from"./chevron-left-D3_hiHLC.js";import{i as S,n as C,r as ie}from"./page-BF6bGLX_.js";import{t as ae}from"./file-text-CVZAL3Er.js";import"./graph-labels-BTFUSc63.js";import{n as oe}from"./file-download-B7zwa78w.js";var w=n(),T=e(t(),1),E=r();function D({onOpen:e}){return(0,E.jsx)(`footer`,{className:`admin-footer`,children:(0,E.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,E.jsx)(`img`,{src:`/brand/claude.png`,alt:`Claude`,className:`powered-by-icon`}),(0,E.jsx)(`span`,{children:`Powered by Claude Code`})]})})}function O({sessionId:e,projectDir:t,sessionKey:n,contactName:r,onBack:i}){return(0,E.jsxs)(`div`,{className:`wa-web`,children:[(0,E.jsxs)(`header`,{className:`wa-web-header`,children:[i&&(0,E.jsx)(`button`,{type:`button`,className:`wa-web-back`,onClick:i,"aria-label":`Back`,children:(0,E.jsx)(x,{size:20})}),(0,E.jsx)(`span`,{className:`wa-web-avatar`,"aria-hidden":!0,children:(0,E.jsx)(g,{size:20})}),(0,E.jsx)(`div`,{className:`wa-web-titles`,children:(0,E.jsx)(`span`,{className:`wa-web-name`,children:r})})]}),(0,E.jsx)(`div`,{className:`wa-web-body`,children:(0,E.jsx)(_,{sessionId:e,projectDir:t,sessionKey:n,forceDeliveredOnly:!0})})]})}var k=6e4,A=60*k,j=24*A,M=k,N=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],P=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function F(e){return e<10?`0${e}`:String(e)}function I(e,t){let n=f(e,t);return Date.UTC(n.y,n.m-1,n.d)}function L(e,t,n){if(!Number.isFinite(e)||e<=0||!Number.isFinite(t))return`—`;let r=t-e;if(r<-M)return`—`;let i=r<0?0:r;if(i<k)return`just now`;if(i<A)return`${Math.floor(i/k)}m`;if(i<j)return`${Math.floor(i/A)}h`;let a=I(new Date(t),n),o=I(new Date(e),n),s=Math.round((a-o)/j);if(s===1)return`yesterday`;let c=f(new Date(e),n);if(s>=2&&s<=6)return P[new Date(o).getUTCDay()];let l=F(c.d),u=N[c.m-1],d=f(new Date(t),n).y;return c.y===d?`${l} ${u}`:`${l} ${u} ${c.y}`}function R({variant:e=`row`,count:t=1}){return(0,E.jsx)(E.Fragment,{children:Array.from({length:t},(t,n)=>(0,E.jsx)(`span`,{className:`dashboard-skeleton dashboard-skeleton--${e}`,"data-testid":`dashboard-skeleton`,"aria-hidden":`true`},n))})}var se=6e4;function ce(e){return e<12?`morning`:e<18?`afternoon`:`evening`}function z(e){return e&&e.trim().split(/\s+/)[0]||`there`}function le(e){if(!e)return`everything is running normally.`;let t=e.cpuPct,n=e.memUsedPct;return t!==null&&t>=.98||n!==null&&n>=.98?`system load is critical.`:t!==null&&t>=.9||n!==null&&n>=.9?`system load is high.`:`everything is running normally.`}function B(e){return e==null?`—`:`${Math.round(e*100)}%`}function V(e){let t=Date.parse(e.lastMessageAt??``);return Number.isFinite(t)?t:-1/0}function ue(e,t,n){if(!e)return!1;let r=Date.parse(e);return Number.isFinite(r)?a(new Date(r),n)===a(new Date(t),n):!1}function de(e){return e?e.replace(/^claude-/,``):null}function fe(e,t,n,r,i){let a=0;for(let e=1;e<n.length;e+=1)V(n[e-1])<V(n[e])&&(a+=1);let o=!1;for(let e=1;e<t.length;e+=1)if(t[e-1].channel!==t[e].channel){o=!0;break}let s=new Map;for(let t of e)s.set(t.channel,(s.get(t.channel)??0)+1);return{feedRows:e.length,renderedRows:n.length,cap:r,hidden:e.length-n.length,expanded:i,outOfOrder:a,undated:e.filter(e=>V(e)===-1/0).length,channels:[...s.entries()].map(([e,t])=>`${e}:${t}`).join(`,`),interleaved:o}}var H=new Set([`sessions`,`conversations`,`tasks`,`artefacts`,`skills`,`stats`]),U=!1;function pe(e,t,n,r){let i=e=>t.get(e)??null,a=r?r.getEntriesByType(`navigation`)[0]:void 0,o=r?r.getEntriesByType(`resource`).filter(e=>new URL(e.name,`http://x`).pathname.startsWith(`/assets/`)):[],s=e=>e===void 0||!Number.isFinite(e)?null:Math.round(e),c=e=>e?s(e):null;return{batchMs:e,sessionsMs:i(`sessions`),conversationsMs:i(`conversations`),tasksMs:i(`tasks`),artefactsMs:i(`artefacts`),skillsMs:i(`skills`),statsMs:i(`stats`),failed:[...H].filter(e=>n.has(e)).join(`,`)||`none`,ttfbMs:s(a?.responseStart),domContentLoadedMs:c(a?.domContentLoadedEventEnd),loadMs:c(a?.loadEventEnd),assetCount:o.length,assetBytes:o.reduce((e,t)=>e+(t.transferSize||0),0),assetMs:o.length?s(Math.max(...o.map(e=>e.responseEnd))):null}}function W({cacheKey:e,userName:t,onSelectWhatsappConversation:n}){let{zone:r}=i(),a=o(e),[s,f]=(0,T.useState)(null),[m,h]=(0,T.useState)(null),[g,_]=(0,T.useState)(null),[v,y]=(0,T.useState)(null),[x,S]=(0,T.useState)(null),[C,ie]=(0,T.useState)(null),[w,D]=(0,T.useState)(null),[O,k]=(0,T.useState)(null),[A,j]=(0,T.useState)(null),[M,N]=(0,T.useState)(new Set),[P,F]=(0,T.useState)(()=>new Set),I=(0,T.useCallback)(e=>{F(t=>t.has(e)?t:new Set(t).add(e))},[]),H=Date.now(),W=(0,T.useRef)(!1),G=(0,T.useRef)(new Map),me=(0,T.useRef)(new Set),K=(0,T.useRef)(null);(0,T.useEffect)(()=>{if(!e)return;let t=!1;async function n(e,n,r,i){let o=Date.now(),s=typeof n==`string`?n:`unresolved`;try{typeof n!=`string`&&(s=await n());let e=await a(s);if(!e.ok)throw Error(`status ${e.status}`);let o=await e.json();t||i(r(o))}catch(t){me.current.add(e),console.error(`[admin-ui] dashboard-fetch-failed slice=${e} url=${s} ms=${Date.now()-o} reason=${t instanceof Error?t.message:String(t)}`)}finally{G.current.set(e,Date.now()-o),I(e)}}async function r(){if(!K.current){let e=await a(`/api/admin/accounts`);if(!e.ok)throw Error(`accounts status ${e.status}`);let t=await e.json(),n=t.accounts??[],r=t.activeAccountId??null,i=n.find(e=>e.accountId===r);if(!i)throw Error(`accounts: active ${r??`none`} absent from list of ${n.length}`);let o=i.isHouse||n.length===1;K.current={accountId:i.accountId,isHouse:o}}let{accountId:e,isHouse:t}=K.current;return t?`/api/operator-conversations/conversations-all`:`/api/operator-conversations/conversations`}let i={"sidebar-sessions":()=>n(`sessions`,`/api/admin/sidebar-sessions`,e=>e.sessions??[],f),"conversations-all":()=>n(`conversations`,r,e=>e.conversations??[],h),"tasks-list":()=>n(`tasks`,`/api/admin/tasks-list`,e=>e,y),"sidebar-artefacts":()=>n(`artefacts`,`/api/admin/sidebar-artefacts`,e=>e.artefacts??[],S),skills:()=>n(`skills`,`/api/admin/skills`,e=>e.skills??[],ie)};async function o(){if(W.current)return;W.current=!0;let e=Date.now();try{await Promise.all([...Object.values(i).map(e=>e()),n(`stats`,`/api/admin/system-stats`,e=>e,_),n(`bookingLink`,`/api/admin/calendar/booking-link`,e=>e.bookingDomain??null,D),n(`portalLink`,`/api/admin/data-portal/portal-link`,e=>e.portalDomain??null,k),n(`plannerLink`,`/api/admin/dispatch-planner/planner-link`,e=>e.plannerUrl??null,j)])}finally{W.current=!1;let t=Date.now()-e;if(!U){U=!0;try{let e=pe(t,G.current,me.current,typeof performance>`u`?null:performance);fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`event`,source:`dashboard-load`,...e}),keepalive:!0}).catch(()=>{})}catch{}}}}o();let s=null;try{s=new EventSource(l(`/api/admin/events`,e)),s.onmessage=e=>{if(document.visibilityState===`visible`)try{let{resource:t}=JSON.parse(e.data),n=t?i[t]:void 0;n&&n()}catch{}},s.onerror=()=>{console.error(`[admin-ui] dashboard-events stream error`)}}catch(e){console.error(`[admin-ui] dashboard-events unavailable reason=${e instanceof Error?e.message:String(e)}`)}let c=setInterval(()=>{document.visibilityState===`visible`&&o()},se),u=()=>{document.visibilityState===`visible`&&o()};return document.addEventListener(`visibilitychange`,u),()=>{t=!0,W.current=!1,clearInterval(c),s?.close(),document.removeEventListener(`visibilitychange`,u)}},[e,a]);let q=(0,T.useMemo)(()=>(s??[]).filter(e=>!e.isSubagent),[s]),J=(0,T.useMemo)(()=>q.filter(e=>e.live),[q]),he=(0,T.useMemo)(()=>(m??[]).filter(e=>ue(e.lastMessageAt,H,r)).length,[m,H]),ge=v?.open.length??0,Y=(0,T.useMemo)(()=>[...m??[]].sort((e,t)=>{let n=V(e),r=V(t);return n===r?0:r>n?1:-1}),[m]),[X,_e]=(0,T.useState)(!1),Z=X?Y:Y.slice(0,8),ve=Y.length-Z.length,ye=(0,T.useRef)(null),Q=(0,T.useRef)(null);(0,T.useEffect)(()=>{if(!P.has(`conversations`))return;let e=fe(m??[],Y,Z,8,X),t=JSON.stringify(e);ye.current!==t&&(ye.current=t,Q.current===null&&(Q.current=d()),fetch(`/api/_client-error`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({kind:`event`,source:`channels-card`,renderId:Q.current,...e})}).catch(()=>{}))},[P,m,Y,Z,X]);let be=(0,T.useRef)(!1);(0,T.useEffect)(()=>{be.current||!P.has(`bookingLink`)||!P.has(`portalLink`)||!P.has(`plannerLink`)||(be.current=!0)},[P,w,O,A]);let xe=(0,T.useCallback)(async e=>{if(!M.has(e)){N(t=>new Set(t).add(e));try{let t=await a(`/api/admin/session-stop`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({sessionId:e})});if(!t.ok){console.error(`[admin-ui] dashboard-session-stop-failed sessionId=${e} status=${t.status}`);return}f(t=>(t??[]).map(t=>t.sessionId===e?{...t,live:!1}:t))}catch(t){console.error(`[admin-ui] dashboard-session-stop-failed sessionId=${e} reason=${t instanceof Error?t.message:String(t)}`)}finally{N(t=>{let n=new Set(t);return n.delete(e),n})}}},[a,M]),Se=(0,T.useCallback)(t=>{if(!e||!t.downloadPath){console.error(`[admin-ui] dashboard-artefact-download-blocked id=${t.id} reason=${e?`not-downloadable`:`no-cache-key`}`);return}oe(e,t.downloadPath,t.downloadRoot??`data`)},[e]),$=ce(new Date(H).getHours());return(0,E.jsxs)(`div`,{className:`ui-page ui-page--full dashboard-home`,children:[(0,E.jsx)(`p`,{className:`dashboard-greeting`,children:P.has(`stats`)?`Good ${$}, ${z(t)} — ${le(g)}`:`Good ${$}, ${z(t)}`}),(0,E.jsxs)(`div`,{className:`dashboard-stats`,children:[(0,E.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,E.jsx)(`span`,{className:`dashboard-stat-label`,children:`Live sessions`}),P.has(`sessions`)?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`span`,{className:`dashboard-stat-value`,children:J.length}),(0,E.jsxs)(`span`,{className:`dashboard-stat-delta`,children:[`of `,q.length,` total`]})]}):(0,E.jsx)(R,{variant:`value`})]}),(0,E.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,E.jsx)(`span`,{className:`dashboard-stat-label`,children:`Messages today`}),P.has(`conversations`)?(0,E.jsx)(`span`,{className:`dashboard-stat-value`,children:he}):(0,E.jsx)(R,{variant:`value`})]}),(0,E.jsxs)(`a`,{className:`admin-stat-card dashboard-stat-card dashboard-stat-card--link`,href:`/tasks`,children:[(0,E.jsx)(`span`,{className:`dashboard-stat-label`,children:`Open tasks`}),P.has(`tasks`)?(0,E.jsx)(`span`,{className:`dashboard-stat-value`,children:ge}):(0,E.jsx)(R,{variant:`value`})]}),(0,E.jsxs)(`div`,{className:`admin-stat-card dashboard-stat-card`,children:[(0,E.jsx)(`span`,{className:`dashboard-stat-label`,children:`Host CPU`}),P.has(`stats`)?(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`span`,{className:`dashboard-stat-value`,children:B(g?.cpuPct??null)}),(0,E.jsxs)(`span`,{className:`dashboard-stat-delta`,children:[`RAM `,B(g?.memUsedPct??null)]})]}):(0,E.jsx)(R,{variant:`value`})]})]}),(0,E.jsxs)(`div`,{className:`dashboard-columns`,children:[(0,E.jsxs)(`div`,{className:`dashboard-col`,children:[(w||O||A)&&(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Public pages`}),(0,E.jsxs)(`div`,{className:`admin-card dashboard-public-pages`,children:[w&&(0,E.jsxs)(`a`,{className:`admin-row dashboard-public-row`,href:`https://${w}`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,E.jsx)(`span`,{className:`dashboard-public-icon`,children:(0,E.jsx)(b,{size:16})}),(0,E.jsx)(`span`,{className:`dashboard-public-name`,children:`Booking page`})]}),O&&(0,E.jsxs)(`a`,{className:`admin-row dashboard-public-row`,href:`https://${O}`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,E.jsx)(`span`,{className:`dashboard-public-icon`,children:(0,E.jsx)(b,{size:16})}),(0,E.jsx)(`span`,{className:`dashboard-public-name`,children:`File drop`})]}),A&&(0,E.jsxs)(`a`,{className:`admin-row dashboard-public-row`,href:A,target:`_blank`,rel:`noopener noreferrer`,children:[(0,E.jsx)(`span`,{className:`dashboard-public-icon`,children:(0,E.jsx)(b,{size:16})}),(0,E.jsx)(`span`,{className:`dashboard-public-name`,children:`Planner`})]})]})]}),(0,E.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Live now`}),P.has(`sessions`)?J.length===0?(0,E.jsx)(`div`,{className:`admin-card dashboard-empty`,children:`No live sessions right now.`}):J.map(e=>{let t=[e.sessionId.slice(0,8),de(e.model),L(Date.parse(e.startedAt),H,r)].filter(Boolean).join(` · `);return(0,E.jsxs)(`div`,{className:`admin-card dashboard-live-card`,children:[(0,E.jsx)(`span`,{className:`admin-status-dot is-live`}),(0,E.jsxs)(`div`,{className:`dashboard-live-main`,children:[(0,E.jsx)(`span`,{className:`dashboard-live-name`,children:e.title}),(0,E.jsx)(`span`,{className:`dashboard-live-meta`,children:t})]}),(0,E.jsx)(`a`,{className:`admin-btn-cta dashboard-open-btn`,href:`/chat?session=${encodeURIComponent(e.sessionId)}`,children:`Open`}),(0,E.jsx)(`button`,{type:`button`,className:`dashboard-stop-btn`,"aria-label":`Stop ${e.title}`,disabled:M.has(e.sessionId),onClick:()=>void xe(e.sessionId),children:(0,E.jsx)(c,{size:12})})]},e.sessionId)}):(0,E.jsx)(R,{variant:`card`,count:2}),(0,E.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Recent artefacts`}),(0,E.jsx)(`div`,{className:`admin-card dashboard-artefacts`,children:P.has(`artefacts`)?(x??[]).length===0?(0,E.jsx)(`div`,{className:`dashboard-empty`,children:`No recent artefacts.`}):(x??[]).slice(0,6).map(e=>(0,E.jsxs)(`button`,{type:`button`,className:`admin-row dashboard-artefact-row`,onClick:()=>Se(e),children:[(0,E.jsx)(`span`,{className:`dashboard-artefact-icon`,children:e.kind===`agent-template`?(0,E.jsx)(re,{size:16}):(0,E.jsx)(ae,{size:16})}),(0,E.jsx)(`div`,{className:`dashboard-artefact-body`,children:(0,E.jsx)(`span`,{className:`dashboard-artefact-name`,children:e.name})}),(0,E.jsx)(`span`,{className:`dashboard-artefact-time`,children:L(Date.parse(e.updatedAt),H,r)})]},e.id)):(0,E.jsx)(R,{count:3})}),(0,E.jsx)(`a`,{className:`admin-section-label dashboard-col-label dashboard-skills-label`,href:`/skills`,children:`Skills`}),(0,E.jsx)(`div`,{className:`admin-card dashboard-skills`,children:P.has(`skills`)?(C??[]).length===0?(0,E.jsx)(`div`,{className:`dashboard-empty`,children:`No skills yet.`}):(C??[]).map(e=>(0,E.jsxs)(`a`,{className:`admin-row dashboard-skill-row`,href:`/skills`,children:[(0,E.jsx)(`span`,{className:`dashboard-skill-icon`,children:(0,E.jsx)(ne,{size:16})}),(0,E.jsxs)(`div`,{className:`dashboard-skill-body`,children:[(0,E.jsx)(`span`,{className:`dashboard-skill-name`,children:e.skill}),(0,E.jsx)(`span`,{className:`dashboard-skill-plugin`,children:e.plugin})]})]},`${e.plugin}/${e.skill}`)):(0,E.jsx)(R,{count:2})})]}),(0,E.jsxs)(`div`,{className:`dashboard-col`,children:[(0,E.jsx)(`span`,{className:`admin-section-label dashboard-col-label`,children:`Channels`}),P.has(`conversations`)?Y.length===0?(0,E.jsx)(`div`,{className:`admin-card dashboard-empty`,children:`No channel activity.`}):(0,E.jsxs)(`div`,{className:`admin-card dashboard-channel-card`,children:[(0,E.jsx)(`div`,{className:`dashboard-channel-convs`,children:Z.map(t=>(0,E.jsxs)(`button`,{type:`button`,className:`admin-row dashboard-channel-conv-row`,onClick:()=>n(t),title:t.title,children:[(0,E.jsxs)(`span`,{className:`dashboard-channel-conv-line`,children:[(0,E.jsx)(`span`,{className:`dashboard-channel-conv-glyph`,children:(0,E.jsx)(ee,{channel:t.channel,size:13})}),(0,E.jsx)(te,{accountId:t.accountId??``,jid:t.remoteJid,sessionKey:e??``,className:`dashboard-channel-conv-avatar`,size:16}),(0,E.jsx)(`span`,{className:`dashboard-channel-conv-name`,children:p(t)}),t.isGroup===!0&&(0,E.jsx)(`span`,{className:`dashboard-channel-conv-tag is-group`,children:`Group`}),t.role===`public`&&(0,E.jsx)(`span`,{className:`dashboard-channel-conv-tag is-public`,children:`Public`}),(0,E.jsx)(`span`,{className:`dashboard-channel-conv-tag`,children:t.isHouse?`House`:`Client`}),!t.preview&&t.lastMessageAt&&(0,E.jsx)(`span`,{className:`dashboard-channel-conv-time`,children:L(Date.parse(t.lastMessageAt),H,r)})]}),t.preview?(0,E.jsxs)(`span`,{className:`dashboard-channel-conv-sub`,children:[(0,E.jsx)(`span`,{className:`dashboard-channel-conv-preview`,children:t.preview}),t.lastMessageAt&&(0,E.jsx)(`span`,{className:`dashboard-channel-conv-time`,children:L(Date.parse(t.lastMessageAt),H,r)})]}):null]},u(t)))}),ve>0&&(0,E.jsxs)(`button`,{type:`button`,className:`dashboard-channel-more`,onClick:()=>_e(!0),children:[`Show `,ve,` more`]})]}):(0,E.jsx)(R,{variant:`card`,count:2})]})]})]})}function G(){let e=m(),[t,n]=(0,T.useState)(!1);(0,T.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,T.useCallback)(async()=>{let t=e.claudeInfo!=null;if(n(!0),t)return;let r=Date.now();if(!e.cacheKey){console.error(`[admin-ui] claude-info-fetch-skipped reason=no-session-key`);return}try{let t=await fetch(`/api/admin/claude-info?session_key=${encodeURIComponent(e.cacheKey)}`);if(t.ok){let n=await t.json();e.setClaudeInfo(n)}}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,T.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===`chat`?(0,E.jsx)(s,{cacheKey:e.cacheKey,onSessionExpired:i,surface:`chat`,children:(0,E.jsx)(y,{cacheKey:e.cacheKey,businessName:e.businessName,sessionId:e.sessionId,onLogout:e.handleLogout,onDisconnect:e.handleDisconnect,disconnecting:e.disconnecting,claudeConnected:e.claudeConnected,onConnectClaude:()=>e.setAppState(`connect-claude`),userName:e.userName,userAvatar:e.userAvatar,role:e.role,footer:(0,E.jsxs)(E.Fragment,{children:[(0,E.jsx)(D,{onOpen:r}),(0,E.jsx)(v,{show:t,onClose:()=>n(!1),claudeInfo:e.claudeInfo,messages:[],sessionElapsed:0,sessionId:e.sessionId,cacheKey:e.cacheKey})]}),children:t=>(0,E.jsx)(E.Fragment,{children:t.dataOpen&&e.cacheKey?(0,E.jsx)(C,{cacheKey:e.cacheKey}):t.selectedWhatsapp&&e.cacheKey?t.selectedWhatsapp.source===`store`&&t.selectedWhatsapp.channel===`telegram`&&t.selectedWhatsapp.channelKey&&t.selectedWhatsapp.accountId?(0,E.jsx)(S,{accountId:t.selectedWhatsapp.accountId,channelKey:t.selectedWhatsapp.channelKey,contactName:p(t.selectedWhatsapp),sessionKey:e.cacheKey,onBack:t.onClearWhatsapp},u(t.selectedWhatsapp)):t.selectedWhatsapp.source===`store`&&t.selectedWhatsapp.remoteJid&&t.selectedWhatsapp.accountId?(0,E.jsx)(ie,{accountId:t.selectedWhatsapp.accountId,remoteJid:t.selectedWhatsapp.remoteJid,contactName:p(t.selectedWhatsapp),sessionKey:e.cacheKey,onBack:t.onClearWhatsapp},u(t.selectedWhatsapp)):(0,E.jsx)(O,{sessionId:t.selectedWhatsapp.sessionId,projectDir:t.selectedWhatsapp.projectDir,sessionKey:e.cacheKey,contactName:p(t.selectedWhatsapp),onBack:t.onClearWhatsapp},u(t.selectedWhatsapp)):(0,E.jsx)(W,{cacheKey:e.cacheKey,userName:e.userName,onSelectWhatsappConversation:t.onSelectWhatsappConversation})})})}):(0,E.jsx)(h,{auth:e})}(0,w.createRoot)(document.getElementById(`root`)).render((0,E.jsx)(G,{}));
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,t}from"./jsx-runtime-BY35JYDT.js";import"./useMediaQuery-e4ciNiuO.js";import"./useVoiceRecorder-Cvu4TePf.js";import"./AdminShell-Dm_nY4jF.js";import{n}from"./page-Bkl56P8R.js";import"./useCopyFeedback-1MKNUzp3.js";var r=e(),i=t();(0,r.createRoot)(document.getElementById(`root`)).render((0,i.jsx)(n,{}));
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,t}from"./jsx-runtime-BY35JYDT.js";import"./useMediaQuery-e4ciNiuO.js";import"./useVoiceRecorder-Cvu4TePf.js";import{t as n}from"./page-BF6bGLX_.js";import"./graph-labels-BTFUSc63.js";var r=e(),i=t();(0,r.createRoot)(document.getElementById(`root`)).render((0,i.jsx)(n,{}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@�j[�2�[x3M��-�3
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./chunk-BycB0eMI.js";import{i as t,n,t as r}from"./jsx-runtime-BY35JYDT.js";import"./useMediaQuery-e4ciNiuO.js";import{n as i,t as a}from"./AdminLoginScreens-
|
|
1
|
+
import{o as e}from"./chunk-BycB0eMI.js";import{i as t,n,t as r}from"./jsx-runtime-BY35JYDT.js";import"./useMediaQuery-e4ciNiuO.js";import{n as i,t as a}from"./AdminLoginScreens-BiHOXO0Y.js";import"./useVoiceRecorder-Cvu4TePf.js";import"./AdminShell-Dm_nY4jF.js";import{t as o}from"./page-Bkl56P8R.js";import"./useCopyFeedback-1MKNUzp3.js";var s=n(),c=e(t(),1),l=r();function u(){let e=i(`operator`),t=(0,c.useRef)(null);return(0,c.useEffect)(()=>{e.appState!==`chat`&&t.current!==e.appState&&(t.current=e.appState)},[e.appState]),e.appState===`chat`?(0,l.jsx)(o,{variant:`operator`,forceCanonicalSession:window.location.pathname!==`/chat`}):(0,l.jsx)(a,{auth:e})}(0,s.createRoot)(document.getElementById(`root`)).render((0,l.jsx)(u,{}));
|
|
Binary file
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./chunk-BycB0eMI.js";import{i as t,r as n,t as r}from"./jsx-runtime-BY35JYDT.js";import{A as i,B as a,C as o,H as s,I as c,K as l,L as u,N as d,P as f,R as p,S as m,V as h,X as ee,Y as g,f as _,g as v,h as y,n as te,p as b,rt as x,t as ne,tt as re,ut as S,x as C,y as w,z as ie}from"./useMediaQuery-e4ciNiuO.js";import{A as ae,M as T,N as E,T as oe,c as D,k as se,n as O,p as k,r as A}from"./useVoiceRecorder-D7_wLtrS.js";import{t as j}from"./chevron-left-D3_hiHLC.js";import{t as ce}from"./file-text-CVZAL3Er.js";import{i as le,t as M}from"./graph-labels-BTFUSc63.js";import{t as ue}from"./triangle-alert-C_68TrTq.js";import{i as de,n as fe,t as pe}from"./file-download-B7zwa78w.js";var me=x(`ellipsis`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`19`,cy:`12`,r:`1`,key:`1wjl8i`}],[`circle`,{cx:`5`,cy:`12`,r:`1`,key:`1pcz8c`}]]),he=x(`folder-plus`,[[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`M9 13h6`,key:`1uhe8q`}],[`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`}]]),N=x(`image`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]),ge=x(`layout-grid`,[[`rect`,{width:`7`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`1g98yp`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`3`,rx:`1`,key:`6d4xhi`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`14`,rx:`1`,key:`nxv5o0`}],[`rect`,{width:`7`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`1bb6yr`}]]),_e=x(`list`,[[`path`,{d:`M3 5h.01`,key:`18ugdj`}],[`path`,{d:`M3 12h.01`,key:`nlz23k`}],[`path`,{d:`M3 19h.01`,key:`noohij`}],[`path`,{d:`M8 5h13`,key:`1pao27`}],[`path`,{d:`M8 12h13`,key:`1za7za`}],[`path`,{d:`M8 19h13`,key:`m83p4d`}]]),ve=x(`send-horizontal`,[[`path`,{d:`M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z`,key:`117uat`}],[`path`,{d:`M6 12h16`,key:`s4cdu5`}]]),P=x(`smile`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M8 14s1.5 2 4 2 4-2 4-2`,key:`1y1vjs`}],[`line`,{x1:`9`,x2:`9.01`,y1:`9`,y2:`9`,key:`yxxnd0`}],[`line`,{x1:`15`,x2:`15.01`,y1:`9`,y2:`9`,key:`1p4y9e`}]]),ye=x(`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`}]]),F=e(t(),1);function be(){let[e,t]=(0,F.useState)([]),[n,r]=(0,F.useState)(!1),[i,a]=(0,F.useState)(null),o=(0,F.useRef)(null),s=(0,F.useCallback)(e=>{a(null);let n=e.find(e=>!A(e.type,E));if(n){a(`Unsupported file type: "${n.type}". Supported: images, PDF, plain text, markdown, CSV, calendar, zip, voice notes.`);return}let r=e.find(e=>e.size>T);if(r){a(`"${r.name}" exceeds the 50 MB limit.`);return}t(t=>[...t,...e].slice(0,5))},[]);return{pendingFiles:e,setPendingFiles:t,isDragOver:n,attachError:i,setAttachError:a,fileInputRef:o,addFiles:s,clearFiles:(0,F.useCallback)(()=>{t([]),a(null)},[]),removeFile:(0,F.useCallback)(e=>{t(t=>t.filter((t,n)=>n!==e))},[]),onDragOver:(0,F.useCallback)(e=>{e.preventDefault(),r(!0)},[]),onDragLeave:(0,F.useCallback)(()=>{r(!1)},[]),onDrop:(0,F.useCallback)(e=>{e.preventDefault(),r(!1),s([...e.dataTransfer.files])},[s])}}var xe=[[128512],[128515],[128516],[128513],[128518],[128517],[128514],[129315],[128578],[128579],[128521],[128522],[128519],[128525],[128536],[128535],[128540],[128541],[129303],[129300],[128528],[128566],[128564],[128526],[129395],[128546],[128557],[128548],[128544],[128533],[128556],[129393],[128077],[128078],[128076],[128591],[128079],[128588],[128170],[128075],[129309],[10084,65039],[128293],[11088],[127881],[10024],[128175],[128064]].map(e=>String.fromCodePoint(...e));function Se(e,t,n,r){let i=e.length,a=Math.max(0,Math.min(n??i,i)),o=Math.max(a,Math.min(r??a,i));return{value:e.slice(0,a)+t+e.slice(o),caret:a+t.length}}var I=r();function Ce({onSelect:e}){return(0,I.jsx)(`div`,{className:`wa-emoji-popover`,role:`menu`,"aria-label":`Emoji picker`,children:xe.map((t,n)=>(0,I.jsx)(`button`,{type:`button`,role:`menuitem`,className:`wa-emoji-item`,onClick:()=>e(t),children:t},n))})}function we({sessionKey:e,onPick:t,onClose:n}){let[r,i]=(0,F.useState)(``),[a,o]=(0,F.useState)(null),[s,l]=(0,F.useState)(null),[u,d]=(0,F.useState)(!1),f=(0,F.useCallback)(t=>{d(!0),l(null),fetch(`/api/admin/files?path=${encodeURIComponent(t)}&session_key=${encodeURIComponent(e)}`).then(async e=>{let t=await e.json().catch(()=>({}));if(!e.ok)throw Error(t.error??`Could not list files`);return t}).then(e=>{o(e),i(e.path===`.`?``:e.path)}).catch(e=>l(e instanceof Error?e.message:String(e))).finally(()=>d(!1))},[e]);(0,F.useEffect)(()=>{f(``)},[f]);let p=e=>f(r?`${r}/${e}`:e),m=()=>{let e=r.split(`/`).filter(Boolean);e.pop(),f(e.join(`/`))},h=e=>{let n=e.entryPath??e.name;t({path:r?`${r}/${n}`:n,name:e.displayName??e.name})};return(0,I.jsx)(`div`,{className:`wa-picker-backdrop`,role:`dialog`,"aria-label":`Choose a device file`,onClick:n,children:(0,I.jsxs)(`div`,{className:`wa-picker`,onClick:e=>e.stopPropagation(),children:[(0,I.jsxs)(`div`,{className:`wa-picker-head`,children:[r&&(0,I.jsx)(`button`,{type:`button`,className:`wa-picker-icon-btn`,onClick:m,"aria-label":`Up one folder`,children:(0,I.jsx)(j,{size:18})}),(0,I.jsx)(`span`,{className:`wa-picker-title`,children:r||`Device storage`}),(0,I.jsx)(`button`,{type:`button`,className:`wa-picker-icon-btn`,onClick:n,"aria-label":`Close file picker`,children:(0,I.jsx)(c,{size:18})})]}),s&&(0,I.jsx)(`p`,{className:`wa-picker-error`,role:`alert`,children:s}),u&&(0,I.jsx)(`p`,{className:`wa-picker-empty`,children:`Loading…`}),a&&!u&&(0,I.jsxs)(`ul`,{className:`wa-picker-list`,children:[a.entries.length===0&&(0,I.jsx)(`li`,{className:`wa-picker-empty`,children:`This folder is empty.`}),a.entries.map(e=>(0,I.jsx)(`li`,{children:e.kind===`directory`?(0,I.jsxs)(`button`,{type:`button`,className:`wa-picker-row`,onClick:()=>p(e.name),children:[(0,I.jsx)(g,{size:16,"aria-hidden":!0}),(0,I.jsx)(`span`,{className:`wa-picker-name`,children:e.displayName??e.name})]}):e.kind===`file`?(0,I.jsxs)(`button`,{type:`button`,className:`wa-picker-row`,onClick:()=>h(e),children:[(0,I.jsx)(ce,{size:16,"aria-hidden":!0}),(0,I.jsx)(`span`,{className:`wa-picker-name`,children:e.displayName??e.name})]}):null},e.name))]})]})})}var Te=n();function Ee(e){return`${Math.floor(e/60)}:${String(e%60).padStart(2,`0`)}`}function L({transport:e,sessionKey:t,replyTo:n,onClearReply:r,features:i}){let a=i?.attachments!==!1,o=i?.voice!==!1,s=i?.deviceFiles!==!1,l=i?.quote!==!1,[d,f]=(0,F.useState)(``),[m,ee]=(0,F.useState)(!1),[g,_]=(0,F.useState)(null),[v,y]=(0,F.useState)(null),[te,b]=(0,F.useState)(!1),[x,re]=(0,F.useState)(!1),[S,C]=(0,F.useState)(!1),[w,ie]=(0,F.useState)([]),T=(0,F.useRef)(null),{pendingFiles:E,attachError:oe,setAttachError:D,addFiles:k,removeFile:A,clearFiles:j}=be(),{state:le,elapsedSeconds:M,errorMessage:ue,start:de,send:fe,discard:pe}=O(),me=le===`recording`||le===`paused`,he=(0,F.useCallback)(()=>{de()},[de]),ge=(0,F.useCallback)(async()=>{let e=await fe();if(e){let t=e.type===`audio/ogg`?`.ogg`:e.type===`audio/mp4`?`.m4a`:`.webm`;k([new File([e],`voice-note${t}`,{type:e.type})])}},[M,fe,k]),_e=(0,F.useCallback)(()=>{pe()},[M,pe]),ye=(0,F.useRef)(!1),xe=()=>Math.round((typeof window>`u`?900:window.innerHeight)/3),[L,R]=(0,F.useState)(null),[z,De]=(0,F.useState)(null),B=(0,F.useRef)(null),V=(0,F.useCallback)(e=>{let t=B.current;t&&R(Math.min(xe(),Math.max(44,t.startH+(t.startY-e.clientY))))},[]),Oe=(0,F.useCallback)(()=>{B.current=null,window.removeEventListener(`pointermove`,V),window.removeEventListener(`pointerup`,Oe)},[V]),ke=(0,F.useCallback)(e=>{B.current={startY:e.clientY,startH:T.current?.offsetHeight??44},window.addEventListener(`pointermove`,V),window.addEventListener(`pointerup`,Oe),e.preventDefault()},[V,Oe]),H=(0,F.useCallback)(e=>{let t=L??T.current?.offsetHeight??44,n=null;e.key===`ArrowUp`?(e.preventDefault(),n=Math.min(xe(),t+24)):e.key===`ArrowDown`&&(e.preventDefault(),n=Math.max(44,t-24)),n!==null&&R(n)},[L]),Ae=(0,F.useRef)(``);(0,F.useEffect)(()=>{let e=T.current;if(!e)return;let t=Ae.current!==``&&d===``;if(Ae.current=d,L!==null){t&&R(null);return}let n=e.style.height;e.style.height=`auto`;let r=Math.min(xe(),Math.max(44,e.scrollHeight));e.style.height=n,De(r)},[d,L]);let je=(d.trim().length>0||E.length>0||w.length>0)&&!m,Me=(0,F.useCallback)(async()=>{if(!ye.current&&!(d.trim().length===0&&E.length===0&&w.length===0)){ye.current=!0,ee(!0),_(null),y(null);try{let i=`${e.endpoint}?session_key=${encodeURIComponent(t)}`,a;if(E.length>0||w.length>0){let t=new FormData;for(let[n,r]of Object.entries(e.fields))t.append(n,r);d.trim()&&t.append(`text`,d);for(let e of E)t.append(`files`,e);for(let e of w)t.append(`fileRefs`,e.path);n&&t.append(`quotedId`,n.msgKeyId),a=await fetch(i,{method:`POST`,body:t})}else a=await fetch(i,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({...e.fields,text:d,...n?{quotedId:n.msgKeyId}:{}})});let o=await a.json().catch(()=>({}));if(!a.ok){_(o.error??`Send failed.`),console.warn(`[operator-ui] op=reply-fail endpoint=${e.endpoint} error=${o.error??`unknown`}`);return}let s=o.context;s&&s.written===!1&&(y(`Sent. The agent's record was not updated: ${s.reason??`unknown`}.`),console.warn(`[operator-ui] op=context-not-written endpoint=${e.endpoint} reason=${s.reason??`unknown`}`)),f(``),j(),ie([]),r?.()}catch(t){_(`Could not reach the server. Try again.`),console.warn(`[operator-ui] op=reply-fail endpoint=${e.endpoint} error=${String(t)}`)}finally{ye.current=!1,ee(!1)}}},[d,E,w,n,r,e,t,j]),Ne=(0,F.useCallback)(e=>{let t=T.current,{value:n,caret:r}=Se(d,e,t?t.selectionStart:null,t?t.selectionEnd:null);f(n),b(!1),requestAnimationFrame(()=>{let e=T.current;e&&(e.focus(),e.setSelectionRange(r,r))})},[d]),Pe=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),je&&Me())},Fe=e=>e.dataTransfer.types.includes(`Files`),Ie=(0,F.useCallback)(e=>{Fe(e)&&(e.preventDefault(),a&&C(!0))},[a]),Le=(0,F.useCallback)(()=>C(!1),[]),Re=(0,F.useCallback)(e=>{if(!Fe(e))return;e.preventDefault(),C(!1);let t=[...e.dataTransfer.files];if(t.length!==0){if(!a){D(`This conversation takes text only. Attachments cannot be sent here.`);return}Math.max(0,E.length+t.length-5),k(t)}},[E.length,k,a,D]),ze=e=>e.startsWith(`image/`)?(0,I.jsx)(N,{size:14}):e===`application/pdf`?(0,I.jsx)(ce,{size:14}):(0,I.jsx)(ae,{size:14}),Be=ne(`(max-width: 720px)`),[Ve,U]=(0,F.useState)(null);(0,F.useEffect)(()=>{U(Be?document.querySelector(`.admin-footer`):null)},[Be]);let W=(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`button`,{type:`button`,className:`wa-reply-emoji`,onClick:()=>b(e=>!e),disabled:m,"aria-label":`Emoji`,"aria-expanded":te,children:(0,I.jsx)(P,{size:22})}),(a||s)&&(0,I.jsx)(`button`,{type:`button`,className:`wa-reply-attach`,onClick:()=>re(!0),disabled:m,"aria-label":`Attach files`,children:(0,I.jsx)(h,{size:22})})]});return(0,I.jsxs)(`div`,{className:`wa-reply${S?` wa-reply-drag-over`:``}`,onDragOver:Ie,onDragLeave:Le,onDrop:Re,children:[x&&(0,I.jsx)(we,{sessionKey:t,onPick:e=>{ie(t=>[...t,e].slice(0,5)),re(!1)},onClose:()=>re(!1)}),te&&(0,I.jsx)(Ce,{onSelect:Ne}),g&&(0,I.jsx)(`p`,{className:`wa-reply-error`,role:`alert`,children:g}),v&&(0,I.jsx)(`p`,{className:`wa-reply-notice`,role:`status`,children:v}),oe&&(0,I.jsx)(`p`,{className:`wa-reply-error`,role:`alert`,children:oe}),le===`error`&&ue&&(0,I.jsx)(`p`,{className:`wa-reply-error`,role:`alert`,children:ue}),(E.length>0||w.length>0)&&(0,I.jsxs)(`div`,{className:`wa-reply-attachments`,children:[E.map((e,t)=>(0,I.jsxs)(`div`,{className:`wa-reply-chip`,children:[ze(e.type),(0,I.jsx)(`span`,{className:`wa-reply-chip-name`,children:e.name}),(0,I.jsx)(`button`,{type:`button`,onClick:()=>A(t),"aria-label":`Remove ${e.name}`,children:(0,I.jsx)(c,{size:12})})]},`f-${t}`)),w.map((e,t)=>(0,I.jsxs)(`div`,{className:`wa-reply-chip wa-reply-chip-ref`,children:[(0,I.jsx)(ce,{size:14}),(0,I.jsx)(`span`,{className:`wa-reply-chip-name`,children:e.name}),(0,I.jsx)(`button`,{type:`button`,onClick:()=>ie(e=>e.filter((e,n)=>n!==t)),"aria-label":`Remove ${e.name}`,children:(0,I.jsx)(c,{size:12})})]},`r-${t}`))]}),l&&n&&(0,I.jsxs)(`div`,{className:`wa-reply-quote`,children:[(0,I.jsxs)(`div`,{className:`wa-reply-quote-body`,children:[(0,I.jsx)(`span`,{className:`wa-reply-quote-who`,children:n.fromMe?`You`:n.senderName??`Contact`}),(0,I.jsx)(`span`,{className:`wa-reply-quote-text`,children:n.body||`Message`})]}),(0,I.jsx)(`button`,{type:`button`,className:`wa-reply-quote-cancel`,onClick:()=>r?.(),"aria-label":`Cancel reply`,children:(0,I.jsx)(c,{size:14})})]}),!me&&(0,I.jsx)(`div`,{className:`wa-reply-resize-handle`,role:`separator`,"aria-orientation":`horizontal`,"aria-label":`Resize input — drag up to enlarge`,tabIndex:0,onPointerDown:ke,onKeyDown:H}),(0,I.jsx)(`div`,{className:`wa-reply-row`,children:me?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`button`,{type:`button`,className:`wa-reply-attach`,onClick:_e,"aria-label":`Cancel recording`,children:(0,I.jsx)(u,{size:20})}),(0,I.jsxs)(`span`,{className:`wa-rec-live`,role:`status`,children:[(0,I.jsx)(`span`,{className:`wa-rec-dot`,"aria-hidden":!0}),Ee(M)]}),(0,I.jsx)(`button`,{type:`button`,className:`wa-reply-send`,onClick:()=>void ge(),"aria-label":`Stop recording`,children:(0,I.jsx)(p,{size:20})})]}):(0,I.jsxs)(I.Fragment,{children:[Ve?(0,Te.createPortal)((0,I.jsx)(`div`,{className:`wa-reply-footer-actions`,children:W}),Ve):W,(0,I.jsxs)(`div`,{className:`wa-reply-inputwrap`,children:[(0,I.jsx)(`textarea`,{ref:T,className:`wa-reply-input`,value:d,rows:1,style:{height:`${L??z??44}px`},placeholder:`Type a message`,disabled:m,onChange:e=>f(e.target.value),onKeyDown:Pe}),o&&d.length===0&&(0,I.jsx)(`button`,{type:`button`,className:`wa-reply-mic`,onClick:()=>void he(),disabled:m,"aria-label":`Record voice note`,children:(0,I.jsx)(se,{size:22})})]}),(0,I.jsx)(`button`,{type:`button`,className:`wa-reply-send`,onClick:()=>void Me(),disabled:!je,"aria-label":`Send`,children:(0,I.jsx)(ve,{size:20})})]})})]})}function R({accountId:e,channelKey:t,contactName:n,sessionKey:r,sendable:i=!0,onBack:a}){let o=t.slice(t.indexOf(`:`)+1),s=n===o?void 0:o;return(0,I.jsxs)(`div`,{className:`wa-web tg-web`,children:[(0,I.jsxs)(`header`,{className:`wa-web-header`,children:[a&&(0,I.jsx)(`button`,{type:`button`,className:`wa-web-back`,onClick:a,"aria-label":`Back`,children:(0,I.jsx)(j,{size:20})}),(0,I.jsx)(`span`,{className:`wa-web-avatar`,"aria-hidden":!0,children:(0,I.jsx)(oe,{size:20})}),(0,I.jsxs)(`div`,{className:`wa-web-titles`,children:[(0,I.jsx)(`span`,{className:`wa-web-name`,children:n}),s&&(0,I.jsx)(`span`,{className:`wa-web-subtitle`,children:s})]})]}),(0,I.jsx)(`div`,{className:`wa-web-body`,"data-testid":`telegram-web-conversation`,children:(0,I.jsx)(D,{sessionId:``,projectDir:``,sessionKey:r,forceDeliveredOnly:!0,suppressDirectives:!0,store:{channel:`telegram`,accountId:e,channelKey:t}})}),i&&(0,I.jsx)(L,{transport:{endpoint:`/api/telegram-reader/send`,fields:{accountId:e,channelKey:t}},sessionKey:r,features:{attachments:!1,voice:!1,deviceFiles:!1,quote:!1}})]})}function z({accountId:e,remoteJid:t,contactName:n,sessionKey:r,onBack:i}){let a=v(t),o=t.split(`@`)[0],s=a?`Group`:n===`+${o}`?void 0:`+${o}`,[l,u]=(0,F.useState)(!1),[d,f]=(0,F.useState)(``),p=()=>{u(!1),f(``)},[m,h]=(0,F.useState)(null);return(0,I.jsxs)(`div`,{className:`wa-web`,children:[(0,I.jsxs)(`header`,{className:`wa-web-header`,children:[i&&(0,I.jsx)(`button`,{type:`button`,className:`wa-web-back`,onClick:i,"aria-label":`Back`,children:(0,I.jsx)(j,{size:20})}),(0,I.jsx)(k,{accountId:e,jid:t,sessionKey:r}),l?(0,I.jsxs)(`div`,{className:`wa-web-search`,children:[(0,I.jsx)(le,{size:18,"aria-hidden":!0}),(0,I.jsx)(`input`,{className:`wa-web-search-input`,type:`text`,autoFocus:!0,placeholder:`Search messages`,"aria-label":`Search messages`,value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Escape`&&p()}}),(0,I.jsx)(`button`,{type:`button`,className:`wa-web-search-close`,onClick:p,"aria-label":`Close search`,children:(0,I.jsx)(c,{size:18})})]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`div`,{className:`wa-web-titles`,children:[(0,I.jsx)(`span`,{className:`wa-web-name`,children:n}),s&&(0,I.jsx)(`span`,{className:`wa-web-subtitle`,children:s})]}),(0,I.jsx)(`button`,{type:`button`,className:`wa-web-search-toggle`,onClick:()=>u(!0),"aria-label":`Search messages`,children:(0,I.jsx)(le,{size:20})})]})]}),(0,I.jsx)(`div`,{className:`wa-web-body`,children:(0,I.jsx)(D,{sessionId:``,projectDir:``,sessionKey:r,forceDeliveredOnly:!0,suppressDirectives:!0,store:{channel:`whatsapp`,accountId:e,remoteJid:t},search:l?d:void 0,onReplyTo:h,groupThread:a})}),(0,I.jsx)(L,{transport:{endpoint:`/api/whatsapp-reader/reply`,fields:{accountId:e,remoteJid:t}},sessionKey:r,replyTo:m,onClearReply:()=>h(null)})]})}function De(e){let t=new Set,n=[];for(let r of e)for(let e of r.labels)e&&(t.has(e)||M.has(e)&&(t.add(e),n.push(e)));return n}function B(e,t){return m(e,t)}function V({conversations:e,sessionKey:t,onBack:n}){let{zone:r}=o(),[i,a]=(0,F.useState)(null),s=_(e);return i?i.source===`store`&&i.channel===`telegram`&&i.accountId&&i.channelKey?(0,I.jsx)(R,{accountId:i.accountId,channelKey:i.channelKey,contactName:b(i),sessionKey:t,onBack:()=>a(null)},y(i)):i.source===`store`&&i.accountId&&i.remoteJid?(0,I.jsx)(z,{accountId:i.accountId,remoteJid:i.remoteJid,contactName:b(i),sessionKey:t,onBack:()=>a(null)},y(i)):(0,I.jsxs)(`div`,{className:`op-conv op-conv-reader`,children:[(0,I.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,I.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:()=>a(null),"aria-label":`Back to conversations`,children:[(0,I.jsx)(j,{size:16}),` Back`]}),(0,I.jsx)(`span`,{className:`op-conv-title`,children:b(i)})]}),(0,I.jsx)(D,{sessionId:i.sessionId,projectDir:i.projectDir,sessionKey:t,forceDeliveredOnly:!0,suppressDirectives:i.source===`store`,store:i.source===`store`?{channel:`whatsapp`,accountId:i.accountId,remoteJid:i.remoteJid}:void 0},y(i))]}):(0,I.jsxs)(`div`,{className:`op-conv op-conv-list`,children:[(0,I.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,I.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:n,"aria-label":`Back to chat`,children:[(0,I.jsx)(j,{size:16}),` Chat`]}),(0,I.jsx)(`span`,{className:`op-conv-title`,children:`Conversations`})]}),s.map(e=>(0,I.jsxs)(`div`,{className:`op-conv-group`,children:[(0,I.jsxs)(`div`,{className:`op-conv-group-head`,children:[(0,I.jsx)(w,{channel:e.channel,size:14}),e.label]}),e.rows.map(e=>(0,I.jsxs)(`button`,{type:`button`,className:`op-conv-row`,onClick:()=>{a(e)},children:[e.source===`store`&&e.accountId&&e.remoteJid&&(0,I.jsx)(k,{accountId:e.accountId,jid:e.remoteJid,sessionKey:t,className:`op-conv-avatar`,size:16}),(0,I.jsx)(`span`,{className:`op-conv-name`,children:b(e)}),e.modelGated&&(0,I.jsx)(`span`,{className:`op-conv-gated`,role:`img`,"aria-label":`Model unavailable`,children:(0,I.jsx)(ue,{size:13})}),(0,I.jsx)(`span`,{className:`op-conv-when`,children:B(e.lastMessageAt,r)})]},y(e)))]},e.channel))]})}var Oe=/\.(png|jpe?g|gif|webp|svg)$/i;function ke(e){return Oe.test(e)}function H(e){return e.entryPath??e.name}var Ae=`maxy-data-view`,je=95*1024*1024,Me=48*1024*1024;function Ne(){return typeof window>`u`?`list`:window.localStorage.getItem(Ae)===`grid`?`grid`:`list`}function Pe(){let[e,t]=(0,F.useState)(null),[n,r]=(0,F.useState)(!1);return(0,F.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(i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]),n?e?(0,I.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,I.jsx)(C,{cacheKey:e,children:(0,I.jsx)(`div`,{className:`data-page data-page-full`,children:(0,I.jsx)(Fe,{cacheKey:e})})})}):(0,I.jsx)(`div`,{className:`data-page`,children:(0,I.jsxs)(`div`,{className:`data-empty`,children:[(0,I.jsx)(`p`,{children:`You are not signed in.`}),(0,I.jsxs)(`p`,{children:[`Open the `,(0,I.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,I.jsx)(d,{surface:`gate`})}function Fe({cacheKey:e}){let{adminFetch:t,cacheKey:n,sessionRefetchNonce:r}=S({initialCacheKey:e,surface:`data`});return(0,I.jsx)(W,{adminFetch:t,cacheKey:n,sessionRefetchNonce:r})}function Ie(){if(typeof window>`u`)return`@home`;let e=new URLSearchParams(window.location.hash.replace(/^#/,``)).get(`path`);return e&&e.length>0?e:`@home`}function Le(e){if(typeof window>`u`)return;let t=new URL(window.location.href);t.hash=e===`.`||e===`@home`?``:`path=${encodeURIComponent(e)}`,window.history.replaceState(window.history.state,``,t.toString())}function Re(e){return new Promise((t,n)=>{let r=[],i=()=>e.readEntries(e=>{e.length===0?t(r):(r.push(...e),i())},n);i()})}function ze(e){return new Promise((t,n)=>e.file(t,n))}async function Be(e,t=``){let n=[];for(let r of e){if(!r)continue;let e=t?`${t}/${r.name}`:r.name;if(r.isFile)n.push({file:await ze(r),relpath:e});else if(r.isDirectory){let t=await Re(r.createReader());n.push(...await Be(t,e))}}return n}function Ve(e,t){if(e===422&&typeof t==`string`){if(/exceeds the .* limit/i.test(t))return`size`;if(/unsupported file type/i.test(t))return`mime`}return`http=${e}`}function U({adminFetch:e,cacheKey:t,sessionRefetchNonce:n}){let{zone:r}=o(),[i,f]=(0,F.useState)(``),p=(0,F.useRef)(null),[m,h]=(0,F.useState)(``),[_,v]=(0,F.useState)(null),[y,te]=(0,F.useState)(`hybrid`),[b,x]=(0,F.useState)(!1),[ne,S]=(0,F.useState)(null),[C,w]=(0,F.useState)(null),[ae,T]=(0,F.useState)(0),[E,oe]=(0,F.useState)(!1),[D,se]=(0,F.useState)(()=>Ie()),[O,k]=(0,F.useState)(null),[A,j]=(0,F.useState)(()=>Ne()),[M,ue]=(0,F.useState)(null),[N,ve]=(0,F.useState)([]),[P,be]=(0,F.useState)(null),[xe,Se]=(0,F.useState)(0),[Ce,we]=(0,F.useState)(null),Te=(0,F.useRef)(null),Ee=N.slice(0,-1).map(e=>e.name).join(`/`),L=(()=>{let e=N.map(e=>e.name);return e.length>=2&&e[0]===`accounts`?`${e[0]}/${e[1]}`:null})(),R=P?Ee:D,z=(0,F.useCallback)(e=>R===`.`||R===``?e:`${R}/${e}`,[R]),[B,V]=(0,F.useState)(!1),[Oe,Pe]=(0,F.useState)(!1),[Fe,Re]=(0,F.useState)(null),[ze,U]=(0,F.useState)(!1),[W,G]=(0,F.useState)(null),[We,Ge]=(0,F.useState)(null),[Ke,Ye]=(0,F.useState)(null),[Xe,Ze]=(0,F.useState)(!1),[Qe,$e]=(0,F.useState)(null),et=(0,F.useRef)(null),[tt,nt]=(0,F.useState)(0),[rt,it]=(0,F.useState)(!1),[at,ot]=(0,F.useState)(``),[st,ct]=(0,F.useState)(null),[lt,ut]=(0,F.useState)(``),[dt,ft]=(0,F.useState)(null),K=(()=>{let e=D===`.`?[]:D.split(`/`).filter(Boolean);return e.some(e=>e.startsWith(`@`))?!1:e.length>=2&&e[0]===`accounts`})(),[pt,mt]=(0,F.useState)(!1),ht=(0,F.useRef)(null),[gt,q]=(0,F.useState)(!1),_t=(0,F.useRef)(null);(0,F.useEffect)(()=>{let e=i.trim();if(!e){h(``),v(null),S(null);return}oe(!1);let t=setTimeout(()=>h(e),300);return()=>clearTimeout(t)},[i]),(0,F.useEffect)(()=>{if(!m){x(!1);return}let t=!1;return x(!0),S(null),e(`/api/admin/graph-search?q=${encodeURIComponent(m)}&labels=FileArtifact&limit=20${E?`&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||(v(e.results),te(e.mode??`hybrid`),T(typeof e.suppressed==`number`?e.suppressed:0))}).catch(e=>{t||S(e instanceof Error?e.message:String(e))}).finally(()=>{t||x(!1)}),()=>{t=!0}},[m,e,n,E]);let vt=(0,F.useMemo)(()=>_?De(_):[],[_]),yt=C&&vt.includes(C)?C:null,bt=(0,F.useMemo)(()=>_?yt?_.filter(e=>e.labels.includes(yt)):_:null,[_,yt]),xt=(0,F.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]);(0,F.useEffect)(()=>{if(!_)return;let e=_.filter(e=>{let t=e.properties.relativePath;return typeof t!=`string`||t.length===0});e.length>0&&console.warn(`[data-search] op=locate-link-missing nodeId=${e.map(e=>e.nodeId).join(`,`)}`)},[_]),(0,F.useEffect)(()=>{let t=!1;return V(!0),Re(null),e(`/api/admin/files?path=${encodeURIComponent(D===`.`?``:D)}`).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||(k(e.entries),ve(e.displayPath??[]),be(e.view??null),Se(typeof e.systemCount==`number`?e.systemCount:0))}).catch(e=>{t||(k([]),ve([]),be(null),Se(0),Re(e instanceof Error?e.message:String(e)))}).finally(()=>{t||(V(!1),Pe(!0))}),()=>{t=!0}},[e,D,tt,n]),(0,F.useEffect)(()=>{if(P!==null||!L||Te.current===L)return;Te.current=L;let t=!1;return e(`/api/admin/files?path=${encodeURIComponent(`${L}/@home`)}`).then(e=>e.ok?e.json():null).then(e=>{t||!e||we((e.entries??[]).map(e=>e.name))}).catch(e=>{console.warn(`[data-ui] op=rail-buckets status=error reason="${e instanceof Error?e.message:String(e)}"`)}),()=>{t=!0}},[e,P,L]),(0,F.useEffect)(()=>{Le(D)},[D]);let St=(0,F.useCallback)(()=>{nt(e=>e+1)},[]),J=(0,F.useCallback)(e=>{mt(!1),se(e)},[]),Ct=(0,F.useCallback)(e=>{let t=e.properties.relativePath;if(typeof t!=`string`||t.length===0)return;let n=t.lastIndexOf(`/`),r=n===-1?`.`:t.slice(0,n);f(``),S(null),w(null),J(r)},[J]),wt=(0,F.useCallback)(()=>{if(!D.split(`/`).some(e=>e.startsWith(`@`))){if(D===`.`||D===``)return;let e=D.split(`/`).filter(Boolean);e.pop(),se(e.length===0?`.`:e.join(`/`));return}N.length!==0&&se(N.length>=2?N.slice(0,N.length-1).map(e=>e.name).join(`/`):`.`)},[D,N]),Tt=(0,F.useCallback)(e=>{fe(t,z(H(e)))},[z,t]),[Y,Et]=(0,F.useState)(!1),[X,Dt]=(0,F.useState)(new Set),Ot=(0,F.useRef)(null),Z=(0,F.useRef)(!1),kt=typeof navigator<`u`&&typeof navigator.share==`function`&&typeof navigator.canShare==`function`,At=(0,F.useCallback)(e=>{Et(!0),Dt(new Set([e]))},[]),Q=(0,F.useCallback)(e=>{Et(!1),Dt(new Set)},[]),jt=(0,F.useCallback)(e=>{Dt(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Mt=(0,F.useCallback)(e=>{Z.current=!1,Ot.current=setTimeout(()=>{Z.current=!0,At(e)},500)},[At]),$=(0,F.useCallback)(()=>{Ot.current&&=(clearTimeout(Ot.current),null)},[]),Nt=(0,F.useCallback)(e=>{if(Z.current){Z.current=!1;return}if(Y){jt(e.name);return}Tt(e)},[Y,jt,Tt]),Pt=(0,F.useCallback)(e=>{j(e),typeof window<`u`&&window.localStorage.setItem(Ae,e)},[]),Ft=(0,F.useCallback)(e=>{if(Z.current){Z.current=!1;return}if(Y){jt(e.name);return}ue({src:pe(t,z(H(e))),alt:e.displayName??e.name})},[Y,jt,z,t]),It=(0,F.useCallback)(()=>(O??[]).filter(e=>e.kind===`file`&&X.has(e.name)),[O,X]),Lt=(0,F.useCallback)(()=>{if(X.size!==1)return null;let e=(O??[]).find(e=>X.has(e.name));return e&&!e.entryPath?e:null},[O,X]),Rt=(0,F.useCallback)(()=>(O??[]).filter(e=>(e.kind===`file`||e.kind===`directory`)&&X.has(e.name)),[O,X]),zt=(0,F.useCallback)(()=>{let e=Rt(),n=e.some(e=>e.kind===`directory`);e.length===1&&!n?Tt(e[0]):e.length>=1&&de(t,e.map(e=>z(H(e)))),Q(`action`)},[Rt,Tt,z,t,Q]),Bt=(0,F.useCallback)(async()=>{let t=It(),n=t.filter(e=>!e.protected),r=t.length-n.length;$e(r>0?`${r} protected file(s) kept`:null);for(let t of n){let n=z(H(t));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}`)}catch(e){$e(e instanceof Error?e.message:String(e))}}nt(e=>e+1),Q(`action`)},[It,z,e,Q]),Vt=(0,F.useCallback)(async()=>{let e=It();if(kt)try{let n=await Promise.all(e.map(async e=>{let n=z(H(e)),r=`/api/admin/files/download?session_key=${encodeURIComponent(t)}&path=${encodeURIComponent(n)}`,i=await(await fetch(r)).blob();return new File([i],e.displayName??e.name,{type:i.type||`application/octet-stream`})}));navigator.canShare({files:n})&&await navigator.share({files:n})}catch(e){console.warn(`[data-ui] op=share-failed err=${e instanceof Error?e.message:String(e)}`)}},[It,kt,z,t]),Ht=(0,F.useCallback)(()=>{et.current?.click()},[]),Ut=(0,F.useCallback)((e,n={})=>{let r=(r,i,a)=>{let o=new URLSearchParams({session_key:t,path:D===`.`?``:D,filename:e.name});n.relpath&&o.set(`relpath`,n.relpath),n.token&&o.set(`token`,n.token);for(let[e,t]of Object.entries(i))o.set(e,t);return new Promise(t=>{let n=new XMLHttpRequest;n.open(`POST`,`/api/admin/files/upload?${o.toString()}`),n.setRequestHeader(`Content-Type`,e.type||`application/octet-stream`),a&&(n.upload.onprogress=e=>{e.lengthComputable&&a(e.loaded)}),n.onload=()=>{let e={};try{e=JSON.parse(n.responseText)}catch{}t({status:n.status,data:e})},n.onerror=()=>t({status:0,data:{}}),n.onabort=()=>t({status:0,data:{error:`aborted`}}),n.send(r)})};if(e.size<=je)return r(e,{},t=>n.onProgress?.(t,e.size));let i=`${Date.now().toString(36)}-${Math.random().toString(16).slice(2,10)}`,a=Math.ceil(e.size/Me);return(async()=>{let t={status:0,data:{}};for(let o=0;o<a;o++){let s=o*Me;if(t=await r(e.slice(s,Math.min(s+Me,e.size)),{uploadId:i,seq:String(o),total:String(a)},t=>n.onProgress?.(s+t,e.size)),!(t.status>=200&&t.status<300))return t}return t})()},[t,D]),Wt=(0,F.useCallback)(async e=>{Ge(null),U(!0),G({loaded:0,total:e.size});try{let{status:t,data:n}=await Ut(e,{onProgress:(e,t)=>G({loaded:e,total:t})});t>=200&&t<300&&n.path?(se(n.path.split(`/`).slice(0,-1).join(`/`)||`.`),nt(e=>e+1)):Ge(t===0?`Network error during upload — the connection failed before the server responded.`:n.error??`Upload failed (HTTP ${t}).`)}finally{U(!1),G(null),et.current&&(et.current.value=``)}},[Ut]),Gt=(0,F.useCallback)(e=>{K&&Array.from(e.dataTransfer.types).includes(`Files`)&&(e.preventDefault(),Ze(!0))},[K]),Kt=(0,F.useCallback)(e=>{e.currentTarget.contains(e.relatedTarget)||Ze(!1)},[]),qt=(0,F.useCallback)(async e=>{e.preventDefault(),Ze(!1);let t=Math.random().toString(16).slice(2,10),n=Array.from(e.dataTransfer.items);if(n.length===0)return;if(!K){Ge(`Open a folder inside your account to upload`);return}let r=n.map(e=>e.webkitGetAsEntry?.()).filter(e=>!!e);U(!0),Ge(null),Ye(null);try{let e=await Be(r),n=0,i=[];for(let r=0;r<e.length;r++){let{file:a,relpath:o}=e[r];G({loaded:0,total:a.size});let{status:s,data:c}=await Ut(a,{relpath:o,token:t,onProgress:(e,t)=>G({loaded:e,total:t})});if(s>=200&&s<300)n++;else{let e=s===0?`http=0`:Ve(s,c.error);i.push(`${o} (${e})`)}}Ye(`Uploaded ${n}, skipped ${i.length}${i.length?`: ${i.join(`, `)}`:``}`),nt(e=>e+1)}catch(e){Ge(e instanceof Error?e.message:String(e))}finally{U(!1),G(null)}},[K,Ut]),Jt=(0,F.useCallback)(async()=>{let t=at.trim();if(t){ft(null);try{let n=await e(`/api/admin/files/folder`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:D===`.`?``:D,name:t})}),r=await n.json().catch(()=>({error:`HTTP ${n.status}`}));if(!n.ok)throw Error(r.error??`HTTP ${n.status}`);it(!1),ot(``),nt(e=>e+1)}catch(e){ft(e instanceof Error?e.message:String(e))}}},[e,at,D]),Yt=(0,F.useCallback)(async()=>{if(!st)return;let t=lt.trim();if(!t)return;ft(null);let n=z(st);try{let r=await e(`/api/admin/files/rename`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:n,newName:t})}),i=await r.json().catch(()=>({error:`HTTP ${r.status}`}));if(!r.ok)throw Error(i.error??`HTTP ${r.status}`);ct(null),ut(``),Q(`action`),nt(e=>e+1)}catch(e){ft(e instanceof Error?e.message:String(e))}},[e,lt,st,z,Q]);(0,F.useEffect)(()=>{if(!pt)return;let e=e=>{ht.current&&!ht.current.contains(e.target)&&mt(!1)},t=e=>{e.key===`Escape`&&mt(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[pt]),(0,F.useEffect)(()=>{if(!gt)return;let e=e=>{_t.current&&!_t.current.contains(e.target)&&q(!1)},t=e=>{e.key===`Escape`&&q(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[gt]);let Xt=(0,F.useCallback)(e=>N.slice(0,e+1).map(e=>e.name).join(`/`),[N]),Zt=N.length>=2,Qt=Zt?[{name:`.`,label:`data`},...N.slice(0,N.length-2).map((e,t)=>({name:Xt(t),label:e.displayName??e.name}))]:[];return Oe?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`div`,{className:`data-toolbar`,children:[Y?(0,I.jsxs)(`button`,{type:`button`,className:`data-select-cancel`,onClick:()=>Q(`cancel`),"aria-label":`Cancel selection`,children:[(0,I.jsx)(c,{size:14}),` Cancel`]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`div`,{className:`data-search-input`,children:[i===``&&(0,I.jsx)(le,{size:14}),(0,I.jsx)(`input`,{ref:p,type:`text`,value:i,onChange:e=>f(e.target.value),autoFocus:!0,autoComplete:`off`,spellCheck:!1}),b&&(0,I.jsx)(l,{size:14,className:`spin`}),i!==``&&(0,I.jsx)(`button`,{type:`button`,className:`data-search-inline-btn`,onClick:()=>{f(``),p.current?.focus()},title:`Clear search`,"aria-label":`Clear search`,children:(0,I.jsx)(c,{size:14})})]}),(0,I.jsxs)(`div`,{className:`data-toolbar-actions`,ref:_t,children:[(0,I.jsx)(`button`,{type:`button`,className:`data-action-overflow`,onClick:()=>q(e=>!e),"aria-haspopup":`menu`,"aria-expanded":gt,"aria-label":`File actions`,title:`File actions`,children:(0,I.jsx)(me,{size:16})}),(0,I.jsxs)(`div`,{className:`data-action-group`,role:`group`,"aria-label":`File actions`,"data-open":gt?`true`:void 0,children:[(0,I.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{St(),q(!1)},disabled:B,title:`Refresh this folder`,"aria-label":`Refresh this folder`,children:[B?(0,I.jsx)(l,{size:16,className:`spin`}):(0,I.jsx)(a,{size:16}),(0,I.jsx)(`span`,{className:`data-action-label`,children:`Refresh`})]}),(0,I.jsxs)(`button`,{type:`button`,className:`data-action-btn admin-btn-cta`,onClick:()=>{Ht(),q(!1)},disabled:ze||!K,title:K?`Upload a file`:`Open a folder inside your account to upload`,"aria-label":`Upload a file`,children:[ze?W&&W.total>0?(0,I.jsxs)(`span`,{className:`data-upload-pct`,children:[Math.round(W.loaded/W.total*100),`%`]}):(0,I.jsx)(l,{size:16,className:`spin`}):(0,I.jsx)(ye,{size:16}),(0,I.jsx)(`span`,{className:`data-action-label`,children:`Upload`})]}),(0,I.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{it(e=>!e),ot(``),ft(null),q(!1)},disabled:ze||!K,title:K?`New folder`:`Open a folder inside your account to create one`,"aria-label":`New folder`,children:[(0,I.jsx)(he,{size:16}),(0,I.jsx)(`span`,{className:`data-action-label`,children:`New folder`})]}),(0,I.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{Pt(A===`grid`?`list`:`grid`),q(!1)},title:A===`grid`?`List view`:`Grid view`,"aria-label":A===`grid`?`Switch to list view`:`Switch to grid view`,"aria-pressed":A===`grid`,children:[A===`grid`?(0,I.jsx)(_e,{size:16}):(0,I.jsx)(ge,{size:16}),(0,I.jsx)(`span`,{className:`data-action-label`,children:A===`grid`?`List view`:`Grid view`})]})]})]})]}),(0,I.jsxs)(`div`,{className:`data-breadcrumbs`,children:[D!==`.`&&(0,I.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost data-back-btn`,onClick:wt,title:`Up one level`,"aria-label":`Up one level`,children:(0,I.jsx)(re,{size:14})}),Zt?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`span`,{className:`data-crumb-wrap`,ref:ht,children:[(0,I.jsx)(`button`,{type:`button`,className:`data-crumb data-crumb-ellipsis`,onClick:()=>mt(e=>!e),"aria-haspopup":`menu`,"aria-expanded":pt,"aria-label":`Show parent folders`,title:`Show parent folders`,children:`…`}),pt&&(0,I.jsx)(`div`,{className:`data-crumb-menu`,role:`menu`,children:Qt.map(e=>(0,I.jsx)(`button`,{type:`button`,role:`menuitem`,className:`data-crumb-menu-item`,onClick:()=>J(e.name),title:e.label,children:e.label},e.name))})]}),[N.length-2,N.length-1].map(e=>{let t=N[e];return(0,I.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,I.jsx)(`span`,{className:`data-crumb-sep`,children:`›`}),(0,I.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>J(Xt(e)),title:t.name,children:t.displayName??t.name})]},Xt(e))})]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>J(`.`),children:`data`}),N.map((e,t)=>(0,I.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,I.jsx)(`span`,{className:`data-crumb-sep`,children:`›`}),(0,I.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>J(Xt(t)),title:e.name,children:e.displayName??e.name})]},Xt(t)))]})]}),rt&&(0,I.jsxs)(`div`,{className:`data-inline-form`,children:[(0,I.jsx)(`input`,{type:`text`,className:`data-inline-input`,placeholder:`Folder name`,value:at,autoFocus:!0,onChange:e=>ot(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Jt(),e.key===`Escape`&&it(!1)}}),(0,I.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:Jt,children:`Create`}),(0,I.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost`,onClick:()=>it(!1),children:`Cancel`})]}),st&&(0,I.jsxs)(`div`,{className:`data-inline-form`,children:[(0,I.jsx)(`input`,{type:`text`,className:`data-inline-input`,placeholder:`New name`,value:lt,autoFocus:!0,onChange:e=>ut(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Yt(),e.key===`Escape`&&ct(null)}}),(0,I.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:Yt,children:`Rename`}),(0,I.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost`,onClick:()=>ct(null),children:`Cancel`})]}),dt&&(0,I.jsx)(`div`,{className:`data-error`,children:dt}),(0,I.jsx)(`input`,{type:`file`,ref:et,hidden:!0,onChange:e=>{let t=e.target.files?.[0];t&&Wt(t)}})]}),(0,I.jsxs)(`div`,{className:`data-body`,"data-drag-active":Xe?`true`:void 0,onDragEnter:Gt,onDragOver:Gt,onDragLeave:Kt,onDrop:qt,children:[P===null&&L&&Ce&&Ce.length>0&&(0,I.jsxs)(`aside`,{className:`data-rail`,"aria-label":`Folders`,children:[(0,I.jsx)(`span`,{className:`data-rail-label`,children:`Folders`}),(0,I.jsx)(`ul`,{className:`data-rail-list`,children:Ce.map(e=>{let t=`${L}/${e}`,n=D===t||D.startsWith(`${t}/`);return(0,I.jsx)(`li`,{children:(0,I.jsxs)(`button`,{type:`button`,className:`data-rail-item`,"aria-current":n?`true`:void 0,onClick:()=>J(t),children:[(0,I.jsx)(g,{size:13}),(0,I.jsx)(`span`,{className:`data-rail-item-name`,children:e})]})},e)})})]}),(0,I.jsxs)(`div`,{className:`data-content`,children:[(ne!==null||_!==null)&&(0,I.jsxs)(`section`,{className:`data-panel admin-card`,children:[ne&&(0,I.jsxs)(`div`,{className:`data-error`,children:[`Search failed: `,ne]}),vt.length>0&&(0,I.jsx)(`div`,{className:`data-chip-row`,role:`group`,"aria-label":`Filter by type`,children:vt.map(e=>{let t=e===yt;return(0,I.jsx)(`button`,{type:`button`,className:`data-chip`,"data-active":t,onClick:()=>w(t?null:e),children:Ue([e])??e},e)})}),_&&!b&&(0,I.jsxs)(`div`,{className:`data-results-meta`,children:[bt.length,` of `,_.length,` result`,_.length===1?``:`s`]}),_&&!b&&!yt&&ae>0&&!E&&(0,I.jsxs)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>oe(!0),children:[ae,` low-confidence result`,ae===1?``:`s`,` hidden — show all`]}),_&&!b&&!yt&&E&&(0,I.jsx)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>oe(!1),children:`Showing all results — hide low-confidence`}),_&&_.length===0&&!b&&(0,I.jsx)(`div`,{className:`data-empty-results`,children:`No matches. Try a different keyword.`}),bt&&bt.length>0&&(0,I.jsx)(`ul`,{className:`data-results`,children:bt.map(e=>(0,I.jsx)(He,{hit:e,mode:y,onDownload:xt,onLocate:Ct},e.nodeId))})]}),(0,I.jsxs)(`section`,{className:P===`home`?`data-panel data-panel--wide`:`data-panel data-panel--wide admin-card`,children:[W&&(0,I.jsxs)(`div`,{className:`data-upload-progress`,role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":W.total>0?Math.round(W.loaded/W.total*100):void 0,children:[(0,I.jsx)(`div`,{className:`data-upload-progress-track`,children:(0,I.jsx)(`div`,{className:`data-upload-progress-fill`,style:{width:`${W.total>0?Math.round(W.loaded/W.total*100):0}%`}})}),(0,I.jsxs)(`span`,{className:`data-upload-progress-label`,children:[`Uploading… `,W.total>0?`${Math.round(W.loaded/W.total*100)}%`:``]})]}),We&&(0,I.jsxs)(`div`,{className:`data-error`,children:[`Upload failed: `,We]}),Ke&&(0,I.jsx)(`div`,{className:`data-status`,children:Ke}),Qe&&(0,I.jsxs)(`div`,{className:`data-error`,children:[`Delete failed: `,Qe]}),Fe&&(0,I.jsx)(`div`,{className:`data-error`,children:Fe}),B&&(0,I.jsxs)(`div`,{className:`data-loading`,children:[(0,I.jsx)(l,{size:14,className:`spin`}),` Loading…`]}),!B&&P!==`home`&&O&&O.length===0&&!Fe&&(0,I.jsx)(`div`,{className:`data-empty-results`,children:`Empty directory.`}),!B&&P===`home`&&O&&(0,I.jsxs)(`ul`,{className:`routine-list data-home-list`,children:[O.map(e=>(0,I.jsxs)(`li`,{className:`data-home-card`,children:[(0,I.jsxs)(`button`,{type:`button`,className:`data-home-card-head`,onClick:()=>J(z(e.name)),children:[(0,I.jsx)(`span`,{className:`data-home-card-title`,children:e.name}),(0,I.jsx)(`span`,{className:`data-home-card-count`,children:e.childCount===null||e.childCount===void 0?`—`:`${e.childCount} ${e.childCount===1?`item`:`items`}`})]}),(0,I.jsxs)(`ul`,{className:`data-home-card-children`,children:[e.childCount===null&&(0,I.jsx)(`li`,{className:`data-home-card-error`,children:`Could not read this folder.`}),e.childCount===0&&(0,I.jsx)(`li`,{className:`data-home-card-empty`,children:`Empty.`}),(e.children??[]).map(e=>(0,I.jsxs)(`li`,{className:`data-home-card-child`,children:[e.kind===`directory`?(0,I.jsx)(g,{size:12}):(0,I.jsx)(ce,{size:12}),(0,I.jsx)(`span`,{className:`data-home-card-child-name`,children:e.name})]},e.name)),typeof e.childCount==`number`&&e.childCount>(e.children?.length??0)&&(0,I.jsxs)(`li`,{className:`data-home-card-more`,children:[`+`,e.childCount-(e.children?.length??0),` more`]})]})]},e.name)),(0,I.jsxs)(`li`,{className:`data-home-card`,children:[(0,I.jsxs)(`button`,{type:`button`,className:`data-home-card-head`,onClick:()=>J(z(`@system`)),children:[(0,I.jsx)(`span`,{className:`data-home-card-title`,children:`system`}),(0,I.jsxs)(`span`,{className:`data-home-card-count`,children:[xe,` `,xe===1?`item`:`items`]})]}),(0,I.jsx)(`ul`,{className:`data-home-card-children`,children:(0,I.jsx)(`li`,{className:`data-home-card-empty`,children:`Platform and plugin folders.`})})]})]}),!B&&P!==`home`&&O&&O.length>0&&A===`grid`&&(0,I.jsx)(`ul`,{className:`data-grid`,children:O.map(e=>{let n=e.displayName??e.name,r=Y&&X.has(e.name);if(e.kind===`directory`)return(0,I.jsx)(`li`,{className:`data-grid-cell`,"data-selected":r?`true`:void 0,children:(0,I.jsxs)(`button`,{type:`button`,className:`data-grid-tile`,onPointerDown:()=>Mt(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>{if(Z.current){Z.current=!1;return}if(Y){jt(e.name);return}J(z(e.name))},children:[Y&&(0,I.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,I.jsx)(g,{size:28,className:`data-grid-glyph`}),(0,I.jsx)(`span`,{className:`data-grid-label`,title:e.name,children:n})]})},e.name);if(e.kind===`file`){let i=ke(H(e)),a=z(H(e));return(0,I.jsx)(`li`,{className:`data-grid-cell`,"data-selected":r?`true`:void 0,children:(0,I.jsxs)(`button`,{type:`button`,className:`data-grid-tile${i?` data-grid-tile-image`:``}`,onPointerDown:()=>Mt(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>i?Ft(e):Nt(e),title:Y?void 0:i?`Preview ${n}`:`Download ${n}`,children:[Y&&(0,I.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),i?(0,I.jsx)(`img`,{className:`data-grid-thumb`,src:pe(t,a),alt:n,loading:`lazy`,onError:()=>console.warn(`[data] op=thumb-error path=${a}`)}):(0,I.jsx)(ce,{size:28,className:`data-grid-glyph`}),(0,I.jsx)(`span`,{className:`data-grid-label`,title:e.name,children:n}),!i&&(0,I.jsx)(`span`,{className:`data-grid-sub`,children:qe(e.sizeBytes)})]})},e.name)}return(0,I.jsx)(`li`,{className:`data-grid-cell`,children:(0,I.jsxs)(`div`,{className:`data-grid-tile data-entry-disabled`,children:[(0,I.jsx)(ce,{size:28,className:`data-grid-glyph`}),(0,I.jsx)(`span`,{className:`data-grid-label`,children:n}),(0,I.jsx)(`span`,{className:`data-grid-sub`,children:`special`})]})},e.name)})}),!B&&P!==`home`&&O&&O.length>0&&A===`list`&&(0,I.jsx)(`ul`,{className:`data-entries`,children:O.map(e=>{let t=e.displayName??e.name;if(e.kind===`directory`){let n=Y&&X.has(e.name);return(0,I.jsx)(`li`,{className:`data-entry`,"data-selected":n?`true`:void 0,children:(0,I.jsxs)(`button`,{type:`button`,className:`data-entry-btn`,onPointerDown:()=>Mt(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>{if(Z.current){Z.current=!1;return}if(Y){jt(e.name);return}J(z(e.name))},children:[Y&&(0,I.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,I.jsx)(g,{size:14}),(0,I.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t})]})},e.name)}if(e.kind===`file`){let n=Y&&X.has(e.name);return(0,I.jsx)(`li`,{className:`data-entry`,"data-selected":n?`true`:void 0,children:(0,I.jsxs)(`button`,{type:`button`,className:`data-entry-btn data-entry-file`,onPointerDown:()=>Mt(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>Nt(e),title:Y?void 0:`Download ${t}`,children:[Y&&(0,I.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,I.jsxs)(`span`,{className:`data-entry-text`,children:[(0,I.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t}),(0,I.jsxs)(`span`,{className:`data-entry-meta`,title:`Modified ${Je(e.modifiedAt,r)}`,children:[qe(e.sizeBytes),` · `,Je(e.modifiedAt,r)]})]})]})},e.name)}return(0,I.jsx)(`li`,{className:`data-entry`,children:(0,I.jsx)(`div`,{className:`data-entry-btn data-entry-file data-entry-disabled`,children:(0,I.jsxs)(`span`,{className:`data-entry-text`,children:[(0,I.jsx)(`span`,{className:`data-entry-name`,children:t}),(0,I.jsx)(`span`,{className:`data-entry-meta`,children:`special`})]})})},e.name)})})]})]})]}),Y&&(0,I.jsx)(`div`,{className:`data-select-bar`,role:`toolbar`,"aria-label":`Selection actions`,children:(0,I.jsxs)(`div`,{className:`data-select-bar-inner`,children:[(0,I.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:Vt,disabled:!kt||X.size===0,title:kt?`Share selected files`:`Sharing is not supported on this device`,children:[(0,I.jsx)(ie,{size:16}),` Share`]}),(0,I.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:zt,disabled:X.size===0,children:[(0,I.jsx)(ee,{size:16}),` Download`]}),(0,I.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:()=>{let e=Lt();e&&(ct(e.name),ut(e.name))},disabled:!Lt(),children:[(0,I.jsx)(s,{size:16}),` Rename`]}),(0,I.jsxs)(`button`,{type:`button`,className:`data-select-action data-select-delete`,onClick:Bt,disabled:X.size===0,children:[(0,I.jsx)(u,{size:16}),` Delete`]})]})}),M&&(0,I.jsx)(`div`,{className:`chat-attachment-overlay`,role:`dialog`,"aria-label":M.alt,onClick:()=>ue(null),children:(0,I.jsx)(`img`,{className:`chat-attachment-overlay-image`,src:M.src,alt:M.alt})})]}):(0,I.jsx)(d,{surface:`gate`})}function W({adminFetch:e,cacheKey:t,sessionRefetchNonce:n}){let r=(0,F.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]),a=(0,F.useCallback)(e=>{e===`chat`&&(window.location.href=`/`)},[]),[o,s]=(0,F.useState)([]),[c,l]=(0,F.useState)(`files`),{subAccounts:u,activeAccountId:d,switching:f,switchAccount:p}=te(t);return(0,F.useEffect)(()=>{if(!t)return;let e=!1;return fetch(`/api/operator-conversations/conversations?session_key=${encodeURIComponent(t)}`).then(e=>e.ok?e.json():{conversations:[]}).then(t=>{e||s(t.conversations??[])}).catch(()=>{}),()=>{e=!0}},[t]),(0,I.jsxs)(`main`,{className:`data-main`,children:[(0,I.jsx)(i,{variant:`operator`,onNavigate:a,onOpenConversations:o.length>0?()=>l(`conversations`):void 0,onToggleSidebar:()=>{},sidebarOpen:!1,onLogout:r,onDisconnect:async()=>!0,disconnecting:!1,subAccounts:u,activeAccountId:d,switchingAccount:f,onSwitchAccount:p}),c===`conversations`?(0,I.jsx)(V,{conversations:o,sessionKey:t,onBack:()=>l(`files`)}):(0,I.jsx)(U,{adminFetch:e,cacheKey:t,sessionRefetchNonce:n})]})}function G({cacheKey:e}){let{adminFetch:t,cacheKey:n,sessionRefetchNonce:r}=S({initialCacheKey:e,surface:`data`});return(0,I.jsx)(`div`,{className:`data-page`,children:(0,I.jsx)(`main`,{className:`data-main`,children:(0,I.jsx)(U,{adminFetch:t,cacheKey:n,sessionRefetchNonce:r})})})}function He({hit:e,mode:t,onDownload:n,onLocate:r}){let{zone:i}=o(),a=We(e.properties),s=Ge(e.properties),c=Ue(e.labels),l=Ke(e.properties),[u,d]=(0,F.useState)(!1),f=s&&s.length>280,p=u||!f?s:s?.slice(0,280)+`…`,m=t===`bm25`?`bm25 ${e.bm25Score.toFixed(2)}`:`vector ${e.vectorScore.toFixed(2)} · bm25 ${e.bm25Score.toFixed(2)} · combined ${e.score.toFixed(2)}`,h=e.properties.relativePath,ee=typeof h==`string`&&h.length>0,_=ee?h.lastIndexOf(`/`):-1,v=ee?_===-1?`data`:h.slice(0,_):null;return(0,I.jsxs)(`li`,{className:`data-result`,children:[(0,I.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 ${a??c??`file`}`,children:[c&&(0,I.jsx)(`div`,{className:`data-result-header`,children:(0,I.jsx)(`span`,{className:`data-result-labels`,children:c})}),a&&(0,I.jsx)(`div`,{className:`data-result-title`,children:a}),s&&(0,I.jsx)(`pre`,{className:`data-result-body`,children:p}),(0,I.jsxs)(`div`,{className:`data-result-scores`,children:[l&&(0,I.jsxs)(`span`,{className:`data-result-updated`,children:[`Updated `,Je(l,i),` · `]}),m]})]}),ee&&(0,I.jsxs)(`button`,{type:`button`,className:`data-result-locate`,onClick:()=>r(e),title:`Locate in ${v}`,"aria-label":`Locate in ${v}`,children:[(0,I.jsx)(g,{size:12}),v]}),f&&(0,I.jsx)(`button`,{type:`button`,className:`data-result-toggle`,onClick:()=>d(e=>!e),children:u?`Show less`:`Show more`})]})}function Ue(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 We(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 Ge(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 Ke(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 qe(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 Je(e,t){return m(e,t)||`—`}export{R as i,G as n,z as r,Pe as t};
|
|
1
|
+
import{o as e}from"./chunk-BycB0eMI.js";import{i as t,r as n,t as r}from"./jsx-runtime-BY35JYDT.js";import{A as i,B as a,C as o,H as s,I as c,K as l,L as u,N as d,P as f,R as p,S as m,V as h,X as ee,Y as g,f as _,g as v,h as y,n as te,p as b,rt as x,t as ne,tt as re,ut as S,x as C,y as w,z as ie}from"./useMediaQuery-e4ciNiuO.js";import{A as ae,M as T,N as E,T as oe,c as D,k as se,n as O,p as k,r as A}from"./useVoiceRecorder-Cvu4TePf.js";import{t as j}from"./chevron-left-D3_hiHLC.js";import{t as ce}from"./file-text-CVZAL3Er.js";import{i as le,t as M}from"./graph-labels-BTFUSc63.js";import{t as ue}from"./triangle-alert-C_68TrTq.js";import{i as de,n as fe,t as pe}from"./file-download-B7zwa78w.js";var me=x(`ellipsis`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`19`,cy:`12`,r:`1`,key:`1wjl8i`}],[`circle`,{cx:`5`,cy:`12`,r:`1`,key:`1pcz8c`}]]),he=x(`folder-plus`,[[`path`,{d:`M12 10v6`,key:`1bos4e`}],[`path`,{d:`M9 13h6`,key:`1uhe8q`}],[`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`}]]),N=x(`image`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]),ge=x(`layout-grid`,[[`rect`,{width:`7`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`1g98yp`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`3`,rx:`1`,key:`6d4xhi`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`14`,rx:`1`,key:`nxv5o0`}],[`rect`,{width:`7`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`1bb6yr`}]]),_e=x(`list`,[[`path`,{d:`M3 5h.01`,key:`18ugdj`}],[`path`,{d:`M3 12h.01`,key:`nlz23k`}],[`path`,{d:`M3 19h.01`,key:`noohij`}],[`path`,{d:`M8 5h13`,key:`1pao27`}],[`path`,{d:`M8 12h13`,key:`1za7za`}],[`path`,{d:`M8 19h13`,key:`m83p4d`}]]),ve=x(`send-horizontal`,[[`path`,{d:`M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z`,key:`117uat`}],[`path`,{d:`M6 12h16`,key:`s4cdu5`}]]),P=x(`smile`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M8 14s1.5 2 4 2 4-2 4-2`,key:`1y1vjs`}],[`line`,{x1:`9`,x2:`9.01`,y1:`9`,y2:`9`,key:`yxxnd0`}],[`line`,{x1:`15`,x2:`15.01`,y1:`9`,y2:`9`,key:`1p4y9e`}]]),ye=x(`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`}]]),F=e(t(),1);function be(){let[e,t]=(0,F.useState)([]),[n,r]=(0,F.useState)(!1),[i,a]=(0,F.useState)(null),o=(0,F.useRef)(null),s=(0,F.useCallback)(e=>{a(null);let n=e.find(e=>!A(e.type,E));if(n){a(`Unsupported file type: "${n.type}". Supported: images, PDF, plain text, markdown, CSV, calendar, zip, voice notes.`);return}let r=e.find(e=>e.size>T);if(r){a(`"${r.name}" exceeds the 50 MB limit.`);return}t(t=>[...t,...e].slice(0,5))},[]);return{pendingFiles:e,setPendingFiles:t,isDragOver:n,attachError:i,setAttachError:a,fileInputRef:o,addFiles:s,clearFiles:(0,F.useCallback)(()=>{t([]),a(null)},[]),removeFile:(0,F.useCallback)(e=>{t(t=>t.filter((t,n)=>n!==e))},[]),onDragOver:(0,F.useCallback)(e=>{e.preventDefault(),r(!0)},[]),onDragLeave:(0,F.useCallback)(()=>{r(!1)},[]),onDrop:(0,F.useCallback)(e=>{e.preventDefault(),r(!1),s([...e.dataTransfer.files])},[s])}}var xe=[[128512],[128515],[128516],[128513],[128518],[128517],[128514],[129315],[128578],[128579],[128521],[128522],[128519],[128525],[128536],[128535],[128540],[128541],[129303],[129300],[128528],[128566],[128564],[128526],[129395],[128546],[128557],[128548],[128544],[128533],[128556],[129393],[128077],[128078],[128076],[128591],[128079],[128588],[128170],[128075],[129309],[10084,65039],[128293],[11088],[127881],[10024],[128175],[128064]].map(e=>String.fromCodePoint(...e));function Se(e,t,n,r){let i=e.length,a=Math.max(0,Math.min(n??i,i)),o=Math.max(a,Math.min(r??a,i));return{value:e.slice(0,a)+t+e.slice(o),caret:a+t.length}}var I=r();function Ce({onSelect:e}){return(0,I.jsx)(`div`,{className:`wa-emoji-popover`,role:`menu`,"aria-label":`Emoji picker`,children:xe.map((t,n)=>(0,I.jsx)(`button`,{type:`button`,role:`menuitem`,className:`wa-emoji-item`,onClick:()=>e(t),children:t},n))})}function we({sessionKey:e,onPick:t,onClose:n}){let[r,i]=(0,F.useState)(``),[a,o]=(0,F.useState)(null),[s,l]=(0,F.useState)(null),[u,d]=(0,F.useState)(!1),f=(0,F.useCallback)(t=>{d(!0),l(null),fetch(`/api/admin/files?path=${encodeURIComponent(t)}&session_key=${encodeURIComponent(e)}`).then(async e=>{let t=await e.json().catch(()=>({}));if(!e.ok)throw Error(t.error??`Could not list files`);return t}).then(e=>{o(e),i(e.path===`.`?``:e.path)}).catch(e=>l(e instanceof Error?e.message:String(e))).finally(()=>d(!1))},[e]);(0,F.useEffect)(()=>{f(``)},[f]);let p=e=>f(r?`${r}/${e}`:e),m=()=>{let e=r.split(`/`).filter(Boolean);e.pop(),f(e.join(`/`))},h=e=>{let n=e.entryPath??e.name;t({path:r?`${r}/${n}`:n,name:e.displayName??e.name})};return(0,I.jsx)(`div`,{className:`wa-picker-backdrop`,role:`dialog`,"aria-label":`Choose a device file`,onClick:n,children:(0,I.jsxs)(`div`,{className:`wa-picker`,onClick:e=>e.stopPropagation(),children:[(0,I.jsxs)(`div`,{className:`wa-picker-head`,children:[r&&(0,I.jsx)(`button`,{type:`button`,className:`wa-picker-icon-btn`,onClick:m,"aria-label":`Up one folder`,children:(0,I.jsx)(j,{size:18})}),(0,I.jsx)(`span`,{className:`wa-picker-title`,children:r||`Device storage`}),(0,I.jsx)(`button`,{type:`button`,className:`wa-picker-icon-btn`,onClick:n,"aria-label":`Close file picker`,children:(0,I.jsx)(c,{size:18})})]}),s&&(0,I.jsx)(`p`,{className:`wa-picker-error`,role:`alert`,children:s}),u&&(0,I.jsx)(`p`,{className:`wa-picker-empty`,children:`Loading…`}),a&&!u&&(0,I.jsxs)(`ul`,{className:`wa-picker-list`,children:[a.entries.length===0&&(0,I.jsx)(`li`,{className:`wa-picker-empty`,children:`This folder is empty.`}),a.entries.map(e=>(0,I.jsx)(`li`,{children:e.kind===`directory`?(0,I.jsxs)(`button`,{type:`button`,className:`wa-picker-row`,onClick:()=>p(e.name),children:[(0,I.jsx)(g,{size:16,"aria-hidden":!0}),(0,I.jsx)(`span`,{className:`wa-picker-name`,children:e.displayName??e.name})]}):e.kind===`file`?(0,I.jsxs)(`button`,{type:`button`,className:`wa-picker-row`,onClick:()=>h(e),children:[(0,I.jsx)(ce,{size:16,"aria-hidden":!0}),(0,I.jsx)(`span`,{className:`wa-picker-name`,children:e.displayName??e.name})]}):null},e.name))]})]})})}var Te=n();function Ee(e){return`${Math.floor(e/60)}:${String(e%60).padStart(2,`0`)}`}function L({transport:e,sessionKey:t,replyTo:n,onClearReply:r,features:i}){let a=i?.attachments!==!1,o=i?.voice!==!1,s=i?.deviceFiles!==!1,l=i?.quote!==!1,[d,f]=(0,F.useState)(``),[m,ee]=(0,F.useState)(!1),[g,_]=(0,F.useState)(null),[v,y]=(0,F.useState)(null),[te,b]=(0,F.useState)(!1),[x,re]=(0,F.useState)(!1),[S,C]=(0,F.useState)(!1),[w,ie]=(0,F.useState)([]),T=(0,F.useRef)(null),{pendingFiles:E,attachError:oe,setAttachError:D,addFiles:k,removeFile:A,clearFiles:j}=be(),{state:le,elapsedSeconds:M,errorMessage:ue,start:de,send:fe,discard:pe}=O(),me=le===`recording`||le===`paused`,he=(0,F.useCallback)(()=>{de()},[de]),ge=(0,F.useCallback)(async()=>{let e=await fe();if(e){let t=e.type===`audio/ogg`?`.ogg`:e.type===`audio/mp4`?`.m4a`:`.webm`;k([new File([e],`voice-note${t}`,{type:e.type})])}},[M,fe,k]),_e=(0,F.useCallback)(()=>{pe()},[M,pe]),ye=(0,F.useRef)(!1),xe=()=>Math.round((typeof window>`u`?900:window.innerHeight)/3),[L,R]=(0,F.useState)(null),[z,De]=(0,F.useState)(null),B=(0,F.useRef)(null),V=(0,F.useCallback)(e=>{let t=B.current;t&&R(Math.min(xe(),Math.max(44,t.startH+(t.startY-e.clientY))))},[]),Oe=(0,F.useCallback)(()=>{B.current=null,window.removeEventListener(`pointermove`,V),window.removeEventListener(`pointerup`,Oe)},[V]),ke=(0,F.useCallback)(e=>{B.current={startY:e.clientY,startH:T.current?.offsetHeight??44},window.addEventListener(`pointermove`,V),window.addEventListener(`pointerup`,Oe),e.preventDefault()},[V,Oe]),H=(0,F.useCallback)(e=>{let t=L??T.current?.offsetHeight??44,n=null;e.key===`ArrowUp`?(e.preventDefault(),n=Math.min(xe(),t+24)):e.key===`ArrowDown`&&(e.preventDefault(),n=Math.max(44,t-24)),n!==null&&R(n)},[L]),Ae=(0,F.useRef)(``);(0,F.useEffect)(()=>{let e=T.current;if(!e)return;let t=Ae.current!==``&&d===``;if(Ae.current=d,L!==null){t&&R(null);return}let n=e.style.height;e.style.height=`auto`;let r=Math.min(xe(),Math.max(44,e.scrollHeight));e.style.height=n,De(r)},[d,L]);let je=(d.trim().length>0||E.length>0||w.length>0)&&!m,Me=(0,F.useCallback)(async()=>{if(!ye.current&&!(d.trim().length===0&&E.length===0&&w.length===0)){ye.current=!0,ee(!0),_(null),y(null);try{let i=`${e.endpoint}?session_key=${encodeURIComponent(t)}`,a;if(E.length>0||w.length>0){let t=new FormData;for(let[n,r]of Object.entries(e.fields))t.append(n,r);d.trim()&&t.append(`text`,d);for(let e of E)t.append(`files`,e);for(let e of w)t.append(`fileRefs`,e.path);n&&t.append(`quotedId`,n.msgKeyId),a=await fetch(i,{method:`POST`,body:t})}else a=await fetch(i,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({...e.fields,text:d,...n?{quotedId:n.msgKeyId}:{}})});let o=await a.json().catch(()=>({}));if(!a.ok){_(o.error??`Send failed.`),console.warn(`[operator-ui] op=reply-fail endpoint=${e.endpoint} error=${o.error??`unknown`}`);return}let s=o.context;s&&s.written===!1&&(y(`Sent. The agent's record was not updated: ${s.reason??`unknown`}.`),console.warn(`[operator-ui] op=context-not-written endpoint=${e.endpoint} reason=${s.reason??`unknown`}`)),f(``),j(),ie([]),r?.()}catch(t){_(`Could not reach the server. Try again.`),console.warn(`[operator-ui] op=reply-fail endpoint=${e.endpoint} error=${String(t)}`)}finally{ye.current=!1,ee(!1)}}},[d,E,w,n,r,e,t,j]),Ne=(0,F.useCallback)(e=>{let t=T.current,{value:n,caret:r}=Se(d,e,t?t.selectionStart:null,t?t.selectionEnd:null);f(n),b(!1),requestAnimationFrame(()=>{let e=T.current;e&&(e.focus(),e.setSelectionRange(r,r))})},[d]),Pe=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),je&&Me())},Fe=e=>e.dataTransfer.types.includes(`Files`),Ie=(0,F.useCallback)(e=>{Fe(e)&&(e.preventDefault(),a&&C(!0))},[a]),Le=(0,F.useCallback)(()=>C(!1),[]),Re=(0,F.useCallback)(e=>{if(!Fe(e))return;e.preventDefault(),C(!1);let t=[...e.dataTransfer.files];if(t.length!==0){if(!a){D(`This conversation takes text only. Attachments cannot be sent here.`);return}Math.max(0,E.length+t.length-5),k(t)}},[E.length,k,a,D]),ze=e=>e.startsWith(`image/`)?(0,I.jsx)(N,{size:14}):e===`application/pdf`?(0,I.jsx)(ce,{size:14}):(0,I.jsx)(ae,{size:14}),Be=ne(`(max-width: 720px)`),[Ve,U]=(0,F.useState)(null);(0,F.useEffect)(()=>{U(Be?document.querySelector(`.admin-footer`):null)},[Be]);let W=(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`button`,{type:`button`,className:`wa-reply-emoji`,onClick:()=>b(e=>!e),disabled:m,"aria-label":`Emoji`,"aria-expanded":te,children:(0,I.jsx)(P,{size:22})}),(a||s)&&(0,I.jsx)(`button`,{type:`button`,className:`wa-reply-attach`,onClick:()=>re(!0),disabled:m,"aria-label":`Attach files`,children:(0,I.jsx)(h,{size:22})})]});return(0,I.jsxs)(`div`,{className:`wa-reply${S?` wa-reply-drag-over`:``}`,onDragOver:Ie,onDragLeave:Le,onDrop:Re,children:[x&&(0,I.jsx)(we,{sessionKey:t,onPick:e=>{ie(t=>[...t,e].slice(0,5)),re(!1)},onClose:()=>re(!1)}),te&&(0,I.jsx)(Ce,{onSelect:Ne}),g&&(0,I.jsx)(`p`,{className:`wa-reply-error`,role:`alert`,children:g}),v&&(0,I.jsx)(`p`,{className:`wa-reply-notice`,role:`status`,children:v}),oe&&(0,I.jsx)(`p`,{className:`wa-reply-error`,role:`alert`,children:oe}),le===`error`&&ue&&(0,I.jsx)(`p`,{className:`wa-reply-error`,role:`alert`,children:ue}),(E.length>0||w.length>0)&&(0,I.jsxs)(`div`,{className:`wa-reply-attachments`,children:[E.map((e,t)=>(0,I.jsxs)(`div`,{className:`wa-reply-chip`,children:[ze(e.type),(0,I.jsx)(`span`,{className:`wa-reply-chip-name`,children:e.name}),(0,I.jsx)(`button`,{type:`button`,onClick:()=>A(t),"aria-label":`Remove ${e.name}`,children:(0,I.jsx)(c,{size:12})})]},`f-${t}`)),w.map((e,t)=>(0,I.jsxs)(`div`,{className:`wa-reply-chip wa-reply-chip-ref`,children:[(0,I.jsx)(ce,{size:14}),(0,I.jsx)(`span`,{className:`wa-reply-chip-name`,children:e.name}),(0,I.jsx)(`button`,{type:`button`,onClick:()=>ie(e=>e.filter((e,n)=>n!==t)),"aria-label":`Remove ${e.name}`,children:(0,I.jsx)(c,{size:12})})]},`r-${t}`))]}),l&&n&&(0,I.jsxs)(`div`,{className:`wa-reply-quote`,children:[(0,I.jsxs)(`div`,{className:`wa-reply-quote-body`,children:[(0,I.jsx)(`span`,{className:`wa-reply-quote-who`,children:n.fromMe?`You`:n.senderName??`Contact`}),(0,I.jsx)(`span`,{className:`wa-reply-quote-text`,children:n.body||`Message`})]}),(0,I.jsx)(`button`,{type:`button`,className:`wa-reply-quote-cancel`,onClick:()=>r?.(),"aria-label":`Cancel reply`,children:(0,I.jsx)(c,{size:14})})]}),!me&&(0,I.jsx)(`div`,{className:`wa-reply-resize-handle`,role:`separator`,"aria-orientation":`horizontal`,"aria-label":`Resize input — drag up to enlarge`,tabIndex:0,onPointerDown:ke,onKeyDown:H}),(0,I.jsx)(`div`,{className:`wa-reply-row`,children:me?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`button`,{type:`button`,className:`wa-reply-attach`,onClick:_e,"aria-label":`Cancel recording`,children:(0,I.jsx)(u,{size:20})}),(0,I.jsxs)(`span`,{className:`wa-rec-live`,role:`status`,children:[(0,I.jsx)(`span`,{className:`wa-rec-dot`,"aria-hidden":!0}),Ee(M)]}),(0,I.jsx)(`button`,{type:`button`,className:`wa-reply-send`,onClick:()=>void ge(),"aria-label":`Stop recording`,children:(0,I.jsx)(p,{size:20})})]}):(0,I.jsxs)(I.Fragment,{children:[Ve?(0,Te.createPortal)((0,I.jsx)(`div`,{className:`wa-reply-footer-actions`,children:W}),Ve):W,(0,I.jsxs)(`div`,{className:`wa-reply-inputwrap`,children:[(0,I.jsx)(`textarea`,{ref:T,className:`wa-reply-input`,value:d,rows:1,style:{height:`${L??z??44}px`},placeholder:`Type a message`,disabled:m,onChange:e=>f(e.target.value),onKeyDown:Pe}),o&&d.length===0&&(0,I.jsx)(`button`,{type:`button`,className:`wa-reply-mic`,onClick:()=>void he(),disabled:m,"aria-label":`Record voice note`,children:(0,I.jsx)(se,{size:22})})]}),(0,I.jsx)(`button`,{type:`button`,className:`wa-reply-send`,onClick:()=>void Me(),disabled:!je,"aria-label":`Send`,children:(0,I.jsx)(ve,{size:20})})]})})]})}function R({accountId:e,channelKey:t,contactName:n,sessionKey:r,sendable:i=!0,onBack:a}){let o=t.slice(t.indexOf(`:`)+1),s=n===o?void 0:o;return(0,I.jsxs)(`div`,{className:`wa-web tg-web`,children:[(0,I.jsxs)(`header`,{className:`wa-web-header`,children:[a&&(0,I.jsx)(`button`,{type:`button`,className:`wa-web-back`,onClick:a,"aria-label":`Back`,children:(0,I.jsx)(j,{size:20})}),(0,I.jsx)(`span`,{className:`wa-web-avatar`,"aria-hidden":!0,children:(0,I.jsx)(oe,{size:20})}),(0,I.jsxs)(`div`,{className:`wa-web-titles`,children:[(0,I.jsx)(`span`,{className:`wa-web-name`,children:n}),s&&(0,I.jsx)(`span`,{className:`wa-web-subtitle`,children:s})]})]}),(0,I.jsx)(`div`,{className:`wa-web-body`,"data-testid":`telegram-web-conversation`,children:(0,I.jsx)(D,{sessionId:``,projectDir:``,sessionKey:r,forceDeliveredOnly:!0,suppressDirectives:!0,store:{channel:`telegram`,accountId:e,channelKey:t}})}),i&&(0,I.jsx)(L,{transport:{endpoint:`/api/telegram-reader/send`,fields:{accountId:e,channelKey:t}},sessionKey:r,features:{attachments:!1,voice:!1,deviceFiles:!1,quote:!1}})]})}function z({accountId:e,remoteJid:t,contactName:n,sessionKey:r,onBack:i}){let a=v(t),o=t.split(`@`)[0],s=a?`Group`:n===`+${o}`?void 0:`+${o}`,[l,u]=(0,F.useState)(!1),[d,f]=(0,F.useState)(``),p=()=>{u(!1),f(``)},[m,h]=(0,F.useState)(null);return(0,I.jsxs)(`div`,{className:`wa-web`,children:[(0,I.jsxs)(`header`,{className:`wa-web-header`,children:[i&&(0,I.jsx)(`button`,{type:`button`,className:`wa-web-back`,onClick:i,"aria-label":`Back`,children:(0,I.jsx)(j,{size:20})}),(0,I.jsx)(k,{accountId:e,jid:t,sessionKey:r}),l?(0,I.jsxs)(`div`,{className:`wa-web-search`,children:[(0,I.jsx)(le,{size:18,"aria-hidden":!0}),(0,I.jsx)(`input`,{className:`wa-web-search-input`,type:`text`,autoFocus:!0,placeholder:`Search messages`,"aria-label":`Search messages`,value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Escape`&&p()}}),(0,I.jsx)(`button`,{type:`button`,className:`wa-web-search-close`,onClick:p,"aria-label":`Close search`,children:(0,I.jsx)(c,{size:18})})]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`div`,{className:`wa-web-titles`,children:[(0,I.jsx)(`span`,{className:`wa-web-name`,children:n}),s&&(0,I.jsx)(`span`,{className:`wa-web-subtitle`,children:s})]}),(0,I.jsx)(`button`,{type:`button`,className:`wa-web-search-toggle`,onClick:()=>u(!0),"aria-label":`Search messages`,children:(0,I.jsx)(le,{size:20})})]})]}),(0,I.jsx)(`div`,{className:`wa-web-body`,children:(0,I.jsx)(D,{sessionId:``,projectDir:``,sessionKey:r,forceDeliveredOnly:!0,suppressDirectives:!0,store:{channel:`whatsapp`,accountId:e,remoteJid:t},search:l?d:void 0,onReplyTo:h,groupThread:a})}),(0,I.jsx)(L,{transport:{endpoint:`/api/whatsapp-reader/reply`,fields:{accountId:e,remoteJid:t}},sessionKey:r,replyTo:m,onClearReply:()=>h(null)})]})}function De(e){let t=new Set,n=[];for(let r of e)for(let e of r.labels)e&&(t.has(e)||M.has(e)&&(t.add(e),n.push(e)));return n}function B(e,t){return m(e,t)}function V({conversations:e,sessionKey:t,onBack:n}){let{zone:r}=o(),[i,a]=(0,F.useState)(null),s=_(e);return i?i.source===`store`&&i.channel===`telegram`&&i.accountId&&i.channelKey?(0,I.jsx)(R,{accountId:i.accountId,channelKey:i.channelKey,contactName:b(i),sessionKey:t,onBack:()=>a(null)},y(i)):i.source===`store`&&i.accountId&&i.remoteJid?(0,I.jsx)(z,{accountId:i.accountId,remoteJid:i.remoteJid,contactName:b(i),sessionKey:t,onBack:()=>a(null)},y(i)):(0,I.jsxs)(`div`,{className:`op-conv op-conv-reader`,children:[(0,I.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,I.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:()=>a(null),"aria-label":`Back to conversations`,children:[(0,I.jsx)(j,{size:16}),` Back`]}),(0,I.jsx)(`span`,{className:`op-conv-title`,children:b(i)})]}),(0,I.jsx)(D,{sessionId:i.sessionId,projectDir:i.projectDir,sessionKey:t,forceDeliveredOnly:!0,suppressDirectives:i.source===`store`,store:i.source===`store`?{channel:`whatsapp`,accountId:i.accountId,remoteJid:i.remoteJid}:void 0},y(i))]}):(0,I.jsxs)(`div`,{className:`op-conv op-conv-list`,children:[(0,I.jsxs)(`div`,{className:`op-conv-bar`,children:[(0,I.jsxs)(`button`,{type:`button`,className:`op-conv-back`,onClick:n,"aria-label":`Back to chat`,children:[(0,I.jsx)(j,{size:16}),` Chat`]}),(0,I.jsx)(`span`,{className:`op-conv-title`,children:`Conversations`})]}),s.map(e=>(0,I.jsxs)(`div`,{className:`op-conv-group`,children:[(0,I.jsxs)(`div`,{className:`op-conv-group-head`,children:[(0,I.jsx)(w,{channel:e.channel,size:14}),e.label]}),e.rows.map(e=>(0,I.jsxs)(`button`,{type:`button`,className:`op-conv-row`,onClick:()=>{a(e)},children:[e.source===`store`&&e.accountId&&e.remoteJid&&(0,I.jsx)(k,{accountId:e.accountId,jid:e.remoteJid,sessionKey:t,className:`op-conv-avatar`,size:16}),(0,I.jsx)(`span`,{className:`op-conv-name`,children:b(e)}),e.modelGated&&(0,I.jsx)(`span`,{className:`op-conv-gated`,role:`img`,"aria-label":`Model unavailable`,children:(0,I.jsx)(ue,{size:13})}),(0,I.jsx)(`span`,{className:`op-conv-when`,children:B(e.lastMessageAt,r)})]},y(e)))]},e.channel))]})}var Oe=/\.(png|jpe?g|gif|webp|svg)$/i;function ke(e){return Oe.test(e)}function H(e){return e.entryPath??e.name}var Ae=`maxy-data-view`,je=95*1024*1024,Me=48*1024*1024;function Ne(){return typeof window>`u`?`list`:window.localStorage.getItem(Ae)===`grid`?`grid`:`list`}function Pe(){let[e,t]=(0,F.useState)(null),[n,r]=(0,F.useState)(!1);return(0,F.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(i=>{if(!e){if(i.status===401){try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`;return}t(n),r(!0)}}).catch(()=>{e||(t(n),r(!0))}),()=>{e=!0}},[]),n?e?(0,I.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,I.jsx)(C,{cacheKey:e,children:(0,I.jsx)(`div`,{className:`data-page data-page-full`,children:(0,I.jsx)(Fe,{cacheKey:e})})})}):(0,I.jsx)(`div`,{className:`data-page`,children:(0,I.jsxs)(`div`,{className:`data-empty`,children:[(0,I.jsx)(`p`,{children:`You are not signed in.`}),(0,I.jsxs)(`p`,{children:[`Open the `,(0,I.jsx)(`a`,{href:`/`,className:`data-link`,children:`main admin page`}),` and log in, then return here.`]})]})}):(0,I.jsx)(d,{surface:`gate`})}function Fe({cacheKey:e}){let{adminFetch:t,cacheKey:n,sessionRefetchNonce:r}=S({initialCacheKey:e,surface:`data`});return(0,I.jsx)(W,{adminFetch:t,cacheKey:n,sessionRefetchNonce:r})}function Ie(){if(typeof window>`u`)return`@home`;let e=new URLSearchParams(window.location.hash.replace(/^#/,``)).get(`path`);return e&&e.length>0?e:`@home`}function Le(e){if(typeof window>`u`)return;let t=new URL(window.location.href);t.hash=e===`.`||e===`@home`?``:`path=${encodeURIComponent(e)}`,window.history.replaceState(window.history.state,``,t.toString())}function Re(e){return new Promise((t,n)=>{let r=[],i=()=>e.readEntries(e=>{e.length===0?t(r):(r.push(...e),i())},n);i()})}function ze(e){return new Promise((t,n)=>e.file(t,n))}async function Be(e,t=``){let n=[];for(let r of e){if(!r)continue;let e=t?`${t}/${r.name}`:r.name;if(r.isFile)n.push({file:await ze(r),relpath:e});else if(r.isDirectory){let t=await Re(r.createReader());n.push(...await Be(t,e))}}return n}function Ve(e,t){if(e===422&&typeof t==`string`){if(/exceeds the .* limit/i.test(t))return`size`;if(/unsupported file type/i.test(t))return`mime`}return`http=${e}`}function U({adminFetch:e,cacheKey:t,sessionRefetchNonce:n}){let{zone:r}=o(),[i,f]=(0,F.useState)(``),p=(0,F.useRef)(null),[m,h]=(0,F.useState)(``),[_,v]=(0,F.useState)(null),[y,te]=(0,F.useState)(`hybrid`),[b,x]=(0,F.useState)(!1),[ne,S]=(0,F.useState)(null),[C,w]=(0,F.useState)(null),[ae,T]=(0,F.useState)(0),[E,oe]=(0,F.useState)(!1),[D,se]=(0,F.useState)(()=>Ie()),[O,k]=(0,F.useState)(null),[A,j]=(0,F.useState)(()=>Ne()),[M,ue]=(0,F.useState)(null),[N,ve]=(0,F.useState)([]),[P,be]=(0,F.useState)(null),[xe,Se]=(0,F.useState)(0),[Ce,we]=(0,F.useState)(null),Te=(0,F.useRef)(null),Ee=N.slice(0,-1).map(e=>e.name).join(`/`),L=(()=>{let e=N.map(e=>e.name);return e.length>=2&&e[0]===`accounts`?`${e[0]}/${e[1]}`:null})(),R=P?Ee:D,z=(0,F.useCallback)(e=>R===`.`||R===``?e:`${R}/${e}`,[R]),[B,V]=(0,F.useState)(!1),[Oe,Pe]=(0,F.useState)(!1),[Fe,Re]=(0,F.useState)(null),[ze,U]=(0,F.useState)(!1),[W,G]=(0,F.useState)(null),[We,Ge]=(0,F.useState)(null),[Ke,Ye]=(0,F.useState)(null),[Xe,Ze]=(0,F.useState)(!1),[Qe,$e]=(0,F.useState)(null),et=(0,F.useRef)(null),[tt,nt]=(0,F.useState)(0),[rt,it]=(0,F.useState)(!1),[at,ot]=(0,F.useState)(``),[st,ct]=(0,F.useState)(null),[lt,ut]=(0,F.useState)(``),[dt,ft]=(0,F.useState)(null),K=(()=>{let e=D===`.`?[]:D.split(`/`).filter(Boolean);return e.some(e=>e.startsWith(`@`))?!1:e.length>=2&&e[0]===`accounts`})(),[pt,mt]=(0,F.useState)(!1),ht=(0,F.useRef)(null),[gt,q]=(0,F.useState)(!1),_t=(0,F.useRef)(null);(0,F.useEffect)(()=>{let e=i.trim();if(!e){h(``),v(null),S(null);return}oe(!1);let t=setTimeout(()=>h(e),300);return()=>clearTimeout(t)},[i]),(0,F.useEffect)(()=>{if(!m){x(!1);return}let t=!1;return x(!0),S(null),e(`/api/admin/graph-search?q=${encodeURIComponent(m)}&labels=FileArtifact&limit=20${E?`&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||(v(e.results),te(e.mode??`hybrid`),T(typeof e.suppressed==`number`?e.suppressed:0))}).catch(e=>{t||S(e instanceof Error?e.message:String(e))}).finally(()=>{t||x(!1)}),()=>{t=!0}},[m,e,n,E]);let vt=(0,F.useMemo)(()=>_?De(_):[],[_]),yt=C&&vt.includes(C)?C:null,bt=(0,F.useMemo)(()=>_?yt?_.filter(e=>e.labels.includes(yt)):_:null,[_,yt]),xt=(0,F.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]);(0,F.useEffect)(()=>{if(!_)return;let e=_.filter(e=>{let t=e.properties.relativePath;return typeof t!=`string`||t.length===0});e.length>0&&console.warn(`[data-search] op=locate-link-missing nodeId=${e.map(e=>e.nodeId).join(`,`)}`)},[_]),(0,F.useEffect)(()=>{let t=!1;return V(!0),Re(null),e(`/api/admin/files?path=${encodeURIComponent(D===`.`?``:D)}`).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||(k(e.entries),ve(e.displayPath??[]),be(e.view??null),Se(typeof e.systemCount==`number`?e.systemCount:0))}).catch(e=>{t||(k([]),ve([]),be(null),Se(0),Re(e instanceof Error?e.message:String(e)))}).finally(()=>{t||(V(!1),Pe(!0))}),()=>{t=!0}},[e,D,tt,n]),(0,F.useEffect)(()=>{if(P!==null||!L||Te.current===L)return;Te.current=L;let t=!1;return e(`/api/admin/files?path=${encodeURIComponent(`${L}/@home`)}`).then(e=>e.ok?e.json():null).then(e=>{t||!e||we((e.entries??[]).map(e=>e.name))}).catch(e=>{console.warn(`[data-ui] op=rail-buckets status=error reason="${e instanceof Error?e.message:String(e)}"`)}),()=>{t=!0}},[e,P,L]),(0,F.useEffect)(()=>{Le(D)},[D]);let St=(0,F.useCallback)(()=>{nt(e=>e+1)},[]),J=(0,F.useCallback)(e=>{mt(!1),se(e)},[]),Ct=(0,F.useCallback)(e=>{let t=e.properties.relativePath;if(typeof t!=`string`||t.length===0)return;let n=t.lastIndexOf(`/`),r=n===-1?`.`:t.slice(0,n);f(``),S(null),w(null),J(r)},[J]),wt=(0,F.useCallback)(()=>{if(!D.split(`/`).some(e=>e.startsWith(`@`))){if(D===`.`||D===``)return;let e=D.split(`/`).filter(Boolean);e.pop(),se(e.length===0?`.`:e.join(`/`));return}N.length!==0&&se(N.length>=2?N.slice(0,N.length-1).map(e=>e.name).join(`/`):`.`)},[D,N]),Tt=(0,F.useCallback)(e=>{fe(t,z(H(e)))},[z,t]),[Y,Et]=(0,F.useState)(!1),[X,Dt]=(0,F.useState)(new Set),Ot=(0,F.useRef)(null),Z=(0,F.useRef)(!1),kt=typeof navigator<`u`&&typeof navigator.share==`function`&&typeof navigator.canShare==`function`,At=(0,F.useCallback)(e=>{Et(!0),Dt(new Set([e]))},[]),Q=(0,F.useCallback)(e=>{Et(!1),Dt(new Set)},[]),jt=(0,F.useCallback)(e=>{Dt(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Mt=(0,F.useCallback)(e=>{Z.current=!1,Ot.current=setTimeout(()=>{Z.current=!0,At(e)},500)},[At]),$=(0,F.useCallback)(()=>{Ot.current&&=(clearTimeout(Ot.current),null)},[]),Nt=(0,F.useCallback)(e=>{if(Z.current){Z.current=!1;return}if(Y){jt(e.name);return}Tt(e)},[Y,jt,Tt]),Pt=(0,F.useCallback)(e=>{j(e),typeof window<`u`&&window.localStorage.setItem(Ae,e)},[]),Ft=(0,F.useCallback)(e=>{if(Z.current){Z.current=!1;return}if(Y){jt(e.name);return}ue({src:pe(t,z(H(e))),alt:e.displayName??e.name})},[Y,jt,z,t]),It=(0,F.useCallback)(()=>(O??[]).filter(e=>e.kind===`file`&&X.has(e.name)),[O,X]),Lt=(0,F.useCallback)(()=>{if(X.size!==1)return null;let e=(O??[]).find(e=>X.has(e.name));return e&&!e.entryPath?e:null},[O,X]),Rt=(0,F.useCallback)(()=>(O??[]).filter(e=>(e.kind===`file`||e.kind===`directory`)&&X.has(e.name)),[O,X]),zt=(0,F.useCallback)(()=>{let e=Rt(),n=e.some(e=>e.kind===`directory`);e.length===1&&!n?Tt(e[0]):e.length>=1&&de(t,e.map(e=>z(H(e)))),Q(`action`)},[Rt,Tt,z,t,Q]),Bt=(0,F.useCallback)(async()=>{let t=It(),n=t.filter(e=>!e.protected),r=t.length-n.length;$e(r>0?`${r} protected file(s) kept`:null);for(let t of n){let n=z(H(t));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}`)}catch(e){$e(e instanceof Error?e.message:String(e))}}nt(e=>e+1),Q(`action`)},[It,z,e,Q]),Vt=(0,F.useCallback)(async()=>{let e=It();if(kt)try{let n=await Promise.all(e.map(async e=>{let n=z(H(e)),r=`/api/admin/files/download?session_key=${encodeURIComponent(t)}&path=${encodeURIComponent(n)}`,i=await(await fetch(r)).blob();return new File([i],e.displayName??e.name,{type:i.type||`application/octet-stream`})}));navigator.canShare({files:n})&&await navigator.share({files:n})}catch(e){console.warn(`[data-ui] op=share-failed err=${e instanceof Error?e.message:String(e)}`)}},[It,kt,z,t]),Ht=(0,F.useCallback)(()=>{et.current?.click()},[]),Ut=(0,F.useCallback)((e,n={})=>{let r=(r,i,a)=>{let o=new URLSearchParams({session_key:t,path:D===`.`?``:D,filename:e.name});n.relpath&&o.set(`relpath`,n.relpath),n.token&&o.set(`token`,n.token);for(let[e,t]of Object.entries(i))o.set(e,t);return new Promise(t=>{let n=new XMLHttpRequest;n.open(`POST`,`/api/admin/files/upload?${o.toString()}`),n.setRequestHeader(`Content-Type`,e.type||`application/octet-stream`),a&&(n.upload.onprogress=e=>{e.lengthComputable&&a(e.loaded)}),n.onload=()=>{let e={};try{e=JSON.parse(n.responseText)}catch{}t({status:n.status,data:e})},n.onerror=()=>t({status:0,data:{}}),n.onabort=()=>t({status:0,data:{error:`aborted`}}),n.send(r)})};if(e.size<=je)return r(e,{},t=>n.onProgress?.(t,e.size));let i=`${Date.now().toString(36)}-${Math.random().toString(16).slice(2,10)}`,a=Math.ceil(e.size/Me);return(async()=>{let t={status:0,data:{}};for(let o=0;o<a;o++){let s=o*Me;if(t=await r(e.slice(s,Math.min(s+Me,e.size)),{uploadId:i,seq:String(o),total:String(a)},t=>n.onProgress?.(s+t,e.size)),!(t.status>=200&&t.status<300))return t}return t})()},[t,D]),Wt=(0,F.useCallback)(async e=>{Ge(null),U(!0),G({loaded:0,total:e.size});try{let{status:t,data:n}=await Ut(e,{onProgress:(e,t)=>G({loaded:e,total:t})});t>=200&&t<300&&n.path?(se(n.path.split(`/`).slice(0,-1).join(`/`)||`.`),nt(e=>e+1)):Ge(t===0?`Network error during upload — the connection failed before the server responded.`:n.error??`Upload failed (HTTP ${t}).`)}finally{U(!1),G(null),et.current&&(et.current.value=``)}},[Ut]),Gt=(0,F.useCallback)(e=>{K&&Array.from(e.dataTransfer.types).includes(`Files`)&&(e.preventDefault(),Ze(!0))},[K]),Kt=(0,F.useCallback)(e=>{e.currentTarget.contains(e.relatedTarget)||Ze(!1)},[]),qt=(0,F.useCallback)(async e=>{e.preventDefault(),Ze(!1);let t=Math.random().toString(16).slice(2,10),n=Array.from(e.dataTransfer.items);if(n.length===0)return;if(!K){Ge(`Open a folder inside your account to upload`);return}let r=n.map(e=>e.webkitGetAsEntry?.()).filter(e=>!!e);U(!0),Ge(null),Ye(null);try{let e=await Be(r),n=0,i=[];for(let r=0;r<e.length;r++){let{file:a,relpath:o}=e[r];G({loaded:0,total:a.size});let{status:s,data:c}=await Ut(a,{relpath:o,token:t,onProgress:(e,t)=>G({loaded:e,total:t})});if(s>=200&&s<300)n++;else{let e=s===0?`http=0`:Ve(s,c.error);i.push(`${o} (${e})`)}}Ye(`Uploaded ${n}, skipped ${i.length}${i.length?`: ${i.join(`, `)}`:``}`),nt(e=>e+1)}catch(e){Ge(e instanceof Error?e.message:String(e))}finally{U(!1),G(null)}},[K,Ut]),Jt=(0,F.useCallback)(async()=>{let t=at.trim();if(t){ft(null);try{let n=await e(`/api/admin/files/folder`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:D===`.`?``:D,name:t})}),r=await n.json().catch(()=>({error:`HTTP ${n.status}`}));if(!n.ok)throw Error(r.error??`HTTP ${n.status}`);it(!1),ot(``),nt(e=>e+1)}catch(e){ft(e instanceof Error?e.message:String(e))}}},[e,at,D]),Yt=(0,F.useCallback)(async()=>{if(!st)return;let t=lt.trim();if(!t)return;ft(null);let n=z(st);try{let r=await e(`/api/admin/files/rename`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:n,newName:t})}),i=await r.json().catch(()=>({error:`HTTP ${r.status}`}));if(!r.ok)throw Error(i.error??`HTTP ${r.status}`);ct(null),ut(``),Q(`action`),nt(e=>e+1)}catch(e){ft(e instanceof Error?e.message:String(e))}},[e,lt,st,z,Q]);(0,F.useEffect)(()=>{if(!pt)return;let e=e=>{ht.current&&!ht.current.contains(e.target)&&mt(!1)},t=e=>{e.key===`Escape`&&mt(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[pt]),(0,F.useEffect)(()=>{if(!gt)return;let e=e=>{_t.current&&!_t.current.contains(e.target)&&q(!1)},t=e=>{e.key===`Escape`&&q(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[gt]);let Xt=(0,F.useCallback)(e=>N.slice(0,e+1).map(e=>e.name).join(`/`),[N]),Zt=N.length>=2,Qt=Zt?[{name:`.`,label:`data`},...N.slice(0,N.length-2).map((e,t)=>({name:Xt(t),label:e.displayName??e.name}))]:[];return Oe?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`div`,{className:`data-toolbar`,children:[Y?(0,I.jsxs)(`button`,{type:`button`,className:`data-select-cancel`,onClick:()=>Q(`cancel`),"aria-label":`Cancel selection`,children:[(0,I.jsx)(c,{size:14}),` Cancel`]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`div`,{className:`data-search-input`,children:[i===``&&(0,I.jsx)(le,{size:14}),(0,I.jsx)(`input`,{ref:p,type:`text`,value:i,onChange:e=>f(e.target.value),autoFocus:!0,autoComplete:`off`,spellCheck:!1}),b&&(0,I.jsx)(l,{size:14,className:`spin`}),i!==``&&(0,I.jsx)(`button`,{type:`button`,className:`data-search-inline-btn`,onClick:()=>{f(``),p.current?.focus()},title:`Clear search`,"aria-label":`Clear search`,children:(0,I.jsx)(c,{size:14})})]}),(0,I.jsxs)(`div`,{className:`data-toolbar-actions`,ref:_t,children:[(0,I.jsx)(`button`,{type:`button`,className:`data-action-overflow`,onClick:()=>q(e=>!e),"aria-haspopup":`menu`,"aria-expanded":gt,"aria-label":`File actions`,title:`File actions`,children:(0,I.jsx)(me,{size:16})}),(0,I.jsxs)(`div`,{className:`data-action-group`,role:`group`,"aria-label":`File actions`,"data-open":gt?`true`:void 0,children:[(0,I.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{St(),q(!1)},disabled:B,title:`Refresh this folder`,"aria-label":`Refresh this folder`,children:[B?(0,I.jsx)(l,{size:16,className:`spin`}):(0,I.jsx)(a,{size:16}),(0,I.jsx)(`span`,{className:`data-action-label`,children:`Refresh`})]}),(0,I.jsxs)(`button`,{type:`button`,className:`data-action-btn admin-btn-cta`,onClick:()=>{Ht(),q(!1)},disabled:ze||!K,title:K?`Upload a file`:`Open a folder inside your account to upload`,"aria-label":`Upload a file`,children:[ze?W&&W.total>0?(0,I.jsxs)(`span`,{className:`data-upload-pct`,children:[Math.round(W.loaded/W.total*100),`%`]}):(0,I.jsx)(l,{size:16,className:`spin`}):(0,I.jsx)(ye,{size:16}),(0,I.jsx)(`span`,{className:`data-action-label`,children:`Upload`})]}),(0,I.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{it(e=>!e),ot(``),ft(null),q(!1)},disabled:ze||!K,title:K?`New folder`:`Open a folder inside your account to create one`,"aria-label":`New folder`,children:[(0,I.jsx)(he,{size:16}),(0,I.jsx)(`span`,{className:`data-action-label`,children:`New folder`})]}),(0,I.jsxs)(`button`,{type:`button`,className:`data-action-btn`,onClick:()=>{Pt(A===`grid`?`list`:`grid`),q(!1)},title:A===`grid`?`List view`:`Grid view`,"aria-label":A===`grid`?`Switch to list view`:`Switch to grid view`,"aria-pressed":A===`grid`,children:[A===`grid`?(0,I.jsx)(_e,{size:16}):(0,I.jsx)(ge,{size:16}),(0,I.jsx)(`span`,{className:`data-action-label`,children:A===`grid`?`List view`:`Grid view`})]})]})]})]}),(0,I.jsxs)(`div`,{className:`data-breadcrumbs`,children:[D!==`.`&&(0,I.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost data-back-btn`,onClick:wt,title:`Up one level`,"aria-label":`Up one level`,children:(0,I.jsx)(re,{size:14})}),Zt?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(`span`,{className:`data-crumb-wrap`,ref:ht,children:[(0,I.jsx)(`button`,{type:`button`,className:`data-crumb data-crumb-ellipsis`,onClick:()=>mt(e=>!e),"aria-haspopup":`menu`,"aria-expanded":pt,"aria-label":`Show parent folders`,title:`Show parent folders`,children:`…`}),pt&&(0,I.jsx)(`div`,{className:`data-crumb-menu`,role:`menu`,children:Qt.map(e=>(0,I.jsx)(`button`,{type:`button`,role:`menuitem`,className:`data-crumb-menu-item`,onClick:()=>J(e.name),title:e.label,children:e.label},e.name))})]}),[N.length-2,N.length-1].map(e=>{let t=N[e];return(0,I.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,I.jsx)(`span`,{className:`data-crumb-sep`,children:`›`}),(0,I.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>J(Xt(e)),title:t.name,children:t.displayName??t.name})]},Xt(e))})]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>J(`.`),children:`data`}),N.map((e,t)=>(0,I.jsxs)(`span`,{className:`data-crumb-wrap`,children:[(0,I.jsx)(`span`,{className:`data-crumb-sep`,children:`›`}),(0,I.jsx)(`button`,{type:`button`,className:`data-crumb`,onClick:()=>J(Xt(t)),title:e.name,children:e.displayName??e.name})]},Xt(t)))]})]}),rt&&(0,I.jsxs)(`div`,{className:`data-inline-form`,children:[(0,I.jsx)(`input`,{type:`text`,className:`data-inline-input`,placeholder:`Folder name`,value:at,autoFocus:!0,onChange:e=>ot(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Jt(),e.key===`Escape`&&it(!1)}}),(0,I.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:Jt,children:`Create`}),(0,I.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost`,onClick:()=>it(!1),children:`Cancel`})]}),st&&(0,I.jsxs)(`div`,{className:`data-inline-form`,children:[(0,I.jsx)(`input`,{type:`text`,className:`data-inline-input`,placeholder:`New name`,value:lt,autoFocus:!0,onChange:e=>ut(e.target.value),onKeyDown:e=>{e.key===`Enter`&&Yt(),e.key===`Escape`&&ct(null)}}),(0,I.jsx)(`button`,{type:`button`,className:`data-btn`,onClick:Yt,children:`Rename`}),(0,I.jsx)(`button`,{type:`button`,className:`data-btn data-btn-ghost`,onClick:()=>ct(null),children:`Cancel`})]}),dt&&(0,I.jsx)(`div`,{className:`data-error`,children:dt}),(0,I.jsx)(`input`,{type:`file`,ref:et,hidden:!0,onChange:e=>{let t=e.target.files?.[0];t&&Wt(t)}})]}),(0,I.jsxs)(`div`,{className:`data-body`,"data-drag-active":Xe?`true`:void 0,onDragEnter:Gt,onDragOver:Gt,onDragLeave:Kt,onDrop:qt,children:[P===null&&L&&Ce&&Ce.length>0&&(0,I.jsxs)(`aside`,{className:`data-rail`,"aria-label":`Folders`,children:[(0,I.jsx)(`span`,{className:`data-rail-label`,children:`Folders`}),(0,I.jsx)(`ul`,{className:`data-rail-list`,children:Ce.map(e=>{let t=`${L}/${e}`,n=D===t||D.startsWith(`${t}/`);return(0,I.jsx)(`li`,{children:(0,I.jsxs)(`button`,{type:`button`,className:`data-rail-item`,"aria-current":n?`true`:void 0,onClick:()=>J(t),children:[(0,I.jsx)(g,{size:13}),(0,I.jsx)(`span`,{className:`data-rail-item-name`,children:e})]})},e)})})]}),(0,I.jsxs)(`div`,{className:`data-content`,children:[(ne!==null||_!==null)&&(0,I.jsxs)(`section`,{className:`data-panel admin-card`,children:[ne&&(0,I.jsxs)(`div`,{className:`data-error`,children:[`Search failed: `,ne]}),vt.length>0&&(0,I.jsx)(`div`,{className:`data-chip-row`,role:`group`,"aria-label":`Filter by type`,children:vt.map(e=>{let t=e===yt;return(0,I.jsx)(`button`,{type:`button`,className:`data-chip`,"data-active":t,onClick:()=>w(t?null:e),children:Ue([e])??e},e)})}),_&&!b&&(0,I.jsxs)(`div`,{className:`data-results-meta`,children:[bt.length,` of `,_.length,` result`,_.length===1?``:`s`]}),_&&!b&&!yt&&ae>0&&!E&&(0,I.jsxs)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>oe(!0),children:[ae,` low-confidence result`,ae===1?``:`s`,` hidden — show all`]}),_&&!b&&!yt&&E&&(0,I.jsx)(`button`,{type:`button`,className:`data-suppressed-banner`,onClick:()=>oe(!1),children:`Showing all results — hide low-confidence`}),_&&_.length===0&&!b&&(0,I.jsx)(`div`,{className:`data-empty-results`,children:`No matches. Try a different keyword.`}),bt&&bt.length>0&&(0,I.jsx)(`ul`,{className:`data-results`,children:bt.map(e=>(0,I.jsx)(He,{hit:e,mode:y,onDownload:xt,onLocate:Ct},e.nodeId))})]}),(0,I.jsxs)(`section`,{className:P===`home`?`data-panel data-panel--wide`:`data-panel data-panel--wide admin-card`,children:[W&&(0,I.jsxs)(`div`,{className:`data-upload-progress`,role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":W.total>0?Math.round(W.loaded/W.total*100):void 0,children:[(0,I.jsx)(`div`,{className:`data-upload-progress-track`,children:(0,I.jsx)(`div`,{className:`data-upload-progress-fill`,style:{width:`${W.total>0?Math.round(W.loaded/W.total*100):0}%`}})}),(0,I.jsxs)(`span`,{className:`data-upload-progress-label`,children:[`Uploading… `,W.total>0?`${Math.round(W.loaded/W.total*100)}%`:``]})]}),We&&(0,I.jsxs)(`div`,{className:`data-error`,children:[`Upload failed: `,We]}),Ke&&(0,I.jsx)(`div`,{className:`data-status`,children:Ke}),Qe&&(0,I.jsxs)(`div`,{className:`data-error`,children:[`Delete failed: `,Qe]}),Fe&&(0,I.jsx)(`div`,{className:`data-error`,children:Fe}),B&&(0,I.jsxs)(`div`,{className:`data-loading`,children:[(0,I.jsx)(l,{size:14,className:`spin`}),` Loading…`]}),!B&&P!==`home`&&O&&O.length===0&&!Fe&&(0,I.jsx)(`div`,{className:`data-empty-results`,children:`Empty directory.`}),!B&&P===`home`&&O&&(0,I.jsxs)(`ul`,{className:`routine-list data-home-list`,children:[O.map(e=>(0,I.jsxs)(`li`,{className:`data-home-card`,children:[(0,I.jsxs)(`button`,{type:`button`,className:`data-home-card-head`,onClick:()=>J(z(e.name)),children:[(0,I.jsx)(`span`,{className:`data-home-card-title`,children:e.name}),(0,I.jsx)(`span`,{className:`data-home-card-count`,children:e.childCount===null||e.childCount===void 0?`—`:`${e.childCount} ${e.childCount===1?`item`:`items`}`})]}),(0,I.jsxs)(`ul`,{className:`data-home-card-children`,children:[e.childCount===null&&(0,I.jsx)(`li`,{className:`data-home-card-error`,children:`Could not read this folder.`}),e.childCount===0&&(0,I.jsx)(`li`,{className:`data-home-card-empty`,children:`Empty.`}),(e.children??[]).map(e=>(0,I.jsxs)(`li`,{className:`data-home-card-child`,children:[e.kind===`directory`?(0,I.jsx)(g,{size:12}):(0,I.jsx)(ce,{size:12}),(0,I.jsx)(`span`,{className:`data-home-card-child-name`,children:e.name})]},e.name)),typeof e.childCount==`number`&&e.childCount>(e.children?.length??0)&&(0,I.jsxs)(`li`,{className:`data-home-card-more`,children:[`+`,e.childCount-(e.children?.length??0),` more`]})]})]},e.name)),(0,I.jsxs)(`li`,{className:`data-home-card`,children:[(0,I.jsxs)(`button`,{type:`button`,className:`data-home-card-head`,onClick:()=>J(z(`@system`)),children:[(0,I.jsx)(`span`,{className:`data-home-card-title`,children:`system`}),(0,I.jsxs)(`span`,{className:`data-home-card-count`,children:[xe,` `,xe===1?`item`:`items`]})]}),(0,I.jsx)(`ul`,{className:`data-home-card-children`,children:(0,I.jsx)(`li`,{className:`data-home-card-empty`,children:`Platform and plugin folders.`})})]})]}),!B&&P!==`home`&&O&&O.length>0&&A===`grid`&&(0,I.jsx)(`ul`,{className:`data-grid`,children:O.map(e=>{let n=e.displayName??e.name,r=Y&&X.has(e.name);if(e.kind===`directory`)return(0,I.jsx)(`li`,{className:`data-grid-cell`,"data-selected":r?`true`:void 0,children:(0,I.jsxs)(`button`,{type:`button`,className:`data-grid-tile`,onPointerDown:()=>Mt(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>{if(Z.current){Z.current=!1;return}if(Y){jt(e.name);return}J(z(e.name))},children:[Y&&(0,I.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,I.jsx)(g,{size:28,className:`data-grid-glyph`}),(0,I.jsx)(`span`,{className:`data-grid-label`,title:e.name,children:n})]})},e.name);if(e.kind===`file`){let i=ke(H(e)),a=z(H(e));return(0,I.jsx)(`li`,{className:`data-grid-cell`,"data-selected":r?`true`:void 0,children:(0,I.jsxs)(`button`,{type:`button`,className:`data-grid-tile${i?` data-grid-tile-image`:``}`,onPointerDown:()=>Mt(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>i?Ft(e):Nt(e),title:Y?void 0:i?`Preview ${n}`:`Download ${n}`,children:[Y&&(0,I.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),i?(0,I.jsx)(`img`,{className:`data-grid-thumb`,src:pe(t,a),alt:n,loading:`lazy`,onError:()=>console.warn(`[data] op=thumb-error path=${a}`)}):(0,I.jsx)(ce,{size:28,className:`data-grid-glyph`}),(0,I.jsx)(`span`,{className:`data-grid-label`,title:e.name,children:n}),!i&&(0,I.jsx)(`span`,{className:`data-grid-sub`,children:qe(e.sizeBytes)})]})},e.name)}return(0,I.jsx)(`li`,{className:`data-grid-cell`,children:(0,I.jsxs)(`div`,{className:`data-grid-tile data-entry-disabled`,children:[(0,I.jsx)(ce,{size:28,className:`data-grid-glyph`}),(0,I.jsx)(`span`,{className:`data-grid-label`,children:n}),(0,I.jsx)(`span`,{className:`data-grid-sub`,children:`special`})]})},e.name)})}),!B&&P!==`home`&&O&&O.length>0&&A===`list`&&(0,I.jsx)(`ul`,{className:`data-entries`,children:O.map(e=>{let t=e.displayName??e.name;if(e.kind===`directory`){let n=Y&&X.has(e.name);return(0,I.jsx)(`li`,{className:`data-entry`,"data-selected":n?`true`:void 0,children:(0,I.jsxs)(`button`,{type:`button`,className:`data-entry-btn`,onPointerDown:()=>Mt(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>{if(Z.current){Z.current=!1;return}if(Y){jt(e.name);return}J(z(e.name))},children:[Y&&(0,I.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,I.jsx)(g,{size:14}),(0,I.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t})]})},e.name)}if(e.kind===`file`){let n=Y&&X.has(e.name);return(0,I.jsx)(`li`,{className:`data-entry`,"data-selected":n?`true`:void 0,children:(0,I.jsxs)(`button`,{type:`button`,className:`data-entry-btn data-entry-file`,onPointerDown:()=>Mt(e.name),onPointerUp:$,onPointerMove:$,onPointerLeave:$,onPointerCancel:$,onClick:()=>Nt(e),title:Y?void 0:`Download ${t}`,children:[Y&&(0,I.jsx)(`span`,{className:`data-entry-select-indicator`,"aria-hidden":`true`}),(0,I.jsxs)(`span`,{className:`data-entry-text`,children:[(0,I.jsx)(`span`,{className:`data-entry-name`,title:e.name,children:t}),(0,I.jsxs)(`span`,{className:`data-entry-meta`,title:`Modified ${Je(e.modifiedAt,r)}`,children:[qe(e.sizeBytes),` · `,Je(e.modifiedAt,r)]})]})]})},e.name)}return(0,I.jsx)(`li`,{className:`data-entry`,children:(0,I.jsx)(`div`,{className:`data-entry-btn data-entry-file data-entry-disabled`,children:(0,I.jsxs)(`span`,{className:`data-entry-text`,children:[(0,I.jsx)(`span`,{className:`data-entry-name`,children:t}),(0,I.jsx)(`span`,{className:`data-entry-meta`,children:`special`})]})})},e.name)})})]})]})]}),Y&&(0,I.jsx)(`div`,{className:`data-select-bar`,role:`toolbar`,"aria-label":`Selection actions`,children:(0,I.jsxs)(`div`,{className:`data-select-bar-inner`,children:[(0,I.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:Vt,disabled:!kt||X.size===0,title:kt?`Share selected files`:`Sharing is not supported on this device`,children:[(0,I.jsx)(ie,{size:16}),` Share`]}),(0,I.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:zt,disabled:X.size===0,children:[(0,I.jsx)(ee,{size:16}),` Download`]}),(0,I.jsxs)(`button`,{type:`button`,className:`data-select-action`,onClick:()=>{let e=Lt();e&&(ct(e.name),ut(e.name))},disabled:!Lt(),children:[(0,I.jsx)(s,{size:16}),` Rename`]}),(0,I.jsxs)(`button`,{type:`button`,className:`data-select-action data-select-delete`,onClick:Bt,disabled:X.size===0,children:[(0,I.jsx)(u,{size:16}),` Delete`]})]})}),M&&(0,I.jsx)(`div`,{className:`chat-attachment-overlay`,role:`dialog`,"aria-label":M.alt,onClick:()=>ue(null),children:(0,I.jsx)(`img`,{className:`chat-attachment-overlay-image`,src:M.src,alt:M.alt})})]}):(0,I.jsx)(d,{surface:`gate`})}function W({adminFetch:e,cacheKey:t,sessionRefetchNonce:n}){let r=(0,F.useCallback)(()=>{try{sessionStorage.removeItem(`maxy-admin-session-key`)}catch{}window.location.href=`/`},[]),a=(0,F.useCallback)(e=>{e===`chat`&&(window.location.href=`/`)},[]),[o,s]=(0,F.useState)([]),[c,l]=(0,F.useState)(`files`),{subAccounts:u,activeAccountId:d,switching:f,switchAccount:p}=te(t);return(0,F.useEffect)(()=>{if(!t)return;let e=!1;return fetch(`/api/operator-conversations/conversations?session_key=${encodeURIComponent(t)}`).then(e=>e.ok?e.json():{conversations:[]}).then(t=>{e||s(t.conversations??[])}).catch(()=>{}),()=>{e=!0}},[t]),(0,I.jsxs)(`main`,{className:`data-main`,children:[(0,I.jsx)(i,{variant:`operator`,onNavigate:a,onOpenConversations:o.length>0?()=>l(`conversations`):void 0,onToggleSidebar:()=>{},sidebarOpen:!1,onLogout:r,onDisconnect:async()=>!0,disconnecting:!1,subAccounts:u,activeAccountId:d,switchingAccount:f,onSwitchAccount:p}),c===`conversations`?(0,I.jsx)(V,{conversations:o,sessionKey:t,onBack:()=>l(`files`)}):(0,I.jsx)(U,{adminFetch:e,cacheKey:t,sessionRefetchNonce:n})]})}function G({cacheKey:e}){let{adminFetch:t,cacheKey:n,sessionRefetchNonce:r}=S({initialCacheKey:e,surface:`data`});return(0,I.jsx)(`div`,{className:`data-page`,children:(0,I.jsx)(`main`,{className:`data-main`,children:(0,I.jsx)(U,{adminFetch:t,cacheKey:n,sessionRefetchNonce:r})})})}function He({hit:e,mode:t,onDownload:n,onLocate:r}){let{zone:i}=o(),a=We(e.properties),s=Ge(e.properties),c=Ue(e.labels),l=Ke(e.properties),[u,d]=(0,F.useState)(!1),f=s&&s.length>280,p=u||!f?s:s?.slice(0,280)+`…`,m=t===`bm25`?`bm25 ${e.bm25Score.toFixed(2)}`:`vector ${e.vectorScore.toFixed(2)} · bm25 ${e.bm25Score.toFixed(2)} · combined ${e.score.toFixed(2)}`,h=e.properties.relativePath,ee=typeof h==`string`&&h.length>0,_=ee?h.lastIndexOf(`/`):-1,v=ee?_===-1?`data`:h.slice(0,_):null;return(0,I.jsxs)(`li`,{className:`data-result`,children:[(0,I.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 ${a??c??`file`}`,children:[c&&(0,I.jsx)(`div`,{className:`data-result-header`,children:(0,I.jsx)(`span`,{className:`data-result-labels`,children:c})}),a&&(0,I.jsx)(`div`,{className:`data-result-title`,children:a}),s&&(0,I.jsx)(`pre`,{className:`data-result-body`,children:p}),(0,I.jsxs)(`div`,{className:`data-result-scores`,children:[l&&(0,I.jsxs)(`span`,{className:`data-result-updated`,children:[`Updated `,Je(l,i),` · `]}),m]})]}),ee&&(0,I.jsxs)(`button`,{type:`button`,className:`data-result-locate`,onClick:()=>r(e),title:`Locate in ${v}`,"aria-label":`Locate in ${v}`,children:[(0,I.jsx)(g,{size:12}),v]}),f&&(0,I.jsx)(`button`,{type:`button`,className:`data-result-toggle`,onClick:()=>d(e=>!e),children:u?`Show less`:`Show more`})]})}function Ue(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 We(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 Ge(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 Ke(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 qe(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 Je(e,t){return m(e,t)||`—`}export{R as i,G as n,z as r,Pe as t};
|
|
Binary file
|
|
Binary file
|