@rubytech/create-realagent 1.0.840 → 1.0.842
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/lib/account-enumeration/dist/__tests__/enumerate.test.d.ts +2 -0
- package/payload/platform/lib/account-enumeration/dist/__tests__/enumerate.test.d.ts.map +1 -0
- package/payload/platform/lib/account-enumeration/dist/__tests__/enumerate.test.js +88 -0
- package/payload/platform/lib/account-enumeration/dist/__tests__/enumerate.test.js.map +1 -0
- package/payload/platform/lib/account-enumeration/dist/index.d.ts +23 -0
- package/payload/platform/lib/account-enumeration/dist/index.d.ts.map +1 -0
- package/payload/platform/lib/account-enumeration/dist/index.js +96 -0
- package/payload/platform/lib/account-enumeration/dist/index.js.map +1 -0
- package/payload/platform/lib/account-enumeration/src/__tests__/enumerate.test.ts +94 -0
- package/payload/platform/lib/account-enumeration/src/index.ts +96 -0
- package/payload/platform/lib/account-enumeration/tsconfig.json +8 -0
- package/payload/platform/lib/graph-write/dist/__tests__/account-id-gate.test.d.ts +2 -0
- package/payload/platform/lib/graph-write/dist/__tests__/account-id-gate.test.d.ts.map +1 -0
- package/payload/platform/lib/graph-write/dist/__tests__/account-id-gate.test.js +165 -0
- package/payload/platform/lib/graph-write/dist/__tests__/account-id-gate.test.js.map +1 -0
- package/payload/platform/lib/graph-write/dist/__tests__/action-provenance-gate.test.js +15 -5
- package/payload/platform/lib/graph-write/dist/__tests__/action-provenance-gate.test.js.map +1 -1
- package/payload/platform/lib/graph-write/dist/index.d.ts +12 -0
- package/payload/platform/lib/graph-write/dist/index.d.ts.map +1 -1
- package/payload/platform/lib/graph-write/dist/index.js +25 -0
- package/payload/platform/lib/graph-write/dist/index.js.map +1 -1
- package/payload/platform/lib/graph-write/src/__tests__/account-id-gate.test.ts +189 -0
- package/payload/platform/lib/graph-write/src/__tests__/action-provenance-gate.test.ts +16 -5
- package/payload/platform/lib/graph-write/src/index.ts +45 -1
- package/payload/platform/package.json +2 -2
- package/payload/platform/plugins/docs/references/attachments.md +2 -2
- package/payload/platform/plugins/docs/references/internals.md +1 -1
- package/payload/platform/plugins/docs/references/troubleshooting.md +1 -1
- package/payload/platform/plugins/whatsapp/PLUGIN.md +1 -1
- package/payload/platform/templates/agents/admin/IDENTITY.md +4 -0
- package/payload/server/adminuser-self-heal-RY4NFCI7.js +45 -0
- package/payload/server/chunk-2YG3AYAH.js +1508 -0
- package/payload/server/chunk-7DFOKDNM.js +2098 -0
- package/payload/server/chunk-DTWW35TK.js +667 -0
- package/payload/server/chunk-HTYXRFT6.js +727 -0
- package/payload/server/chunk-NPVEOM3D.js +1508 -0
- package/payload/server/chunk-QGM4M3NI.js +37 -0
- package/payload/server/chunk-S27QCBFQ.js +10071 -0
- package/payload/server/chunk-TS6CKCGU.js +727 -0
- package/payload/server/chunk-XECKT3YB.js +10071 -0
- package/payload/server/client-pool-2WQ2Q3TF.js +32 -0
- package/payload/server/client-pool-SMWCZMZG.js +32 -0
- package/payload/server/cloudflare-task-tracker-NQK7A2EQ.js +20 -0
- package/payload/server/cloudflare-task-tracker-O4ZA4TAS.js +20 -0
- package/payload/server/cloudflare-task-tracker-XFGXO7ZV.js +20 -0
- package/payload/server/maxy-edge.js +2 -2
- package/payload/server/public/assets/{admin-D678VwpH.js → admin-CvwOOG4D.js} +1 -1
- package/payload/server/public/assets/{public-C7mCgRX0.js → public-Br9YjNs_.js} +2 -2
- package/payload/server/public/index.html +1 -1
- package/payload/server/public/public.html +1 -1
- package/payload/server/server.js +65 -41
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{o as e}from"./chunk-DD-I1_y5.js";import{i as t,o as n,r,t as i}from"./jsx-runtime-WW3O7tSz.js";import{A as a,D as o,M as s,N as c,O as l,S as u,_ as d,a as f,b as p,c as m,g as h,h as g,i as _,j as v,n as y,o as b,r as x,s as S,t as C,u as w,v as T,w as E,x as D}from"./useVoiceRecorder-Bx903Mk1.js";import{t as O}from"./Checkbox-aCc0UGp3.js";var k=r(`square-plus`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}],[`path`,{d:`M12 8v8`,key:`napkw2`}]]),A=t(),j=e(n(),1),M=`image/jpeg,image/png,image/gif,image/webp,application/pdf,text/plain,text/markdown,text/csv,text/html,text/calendar`,N=new Set(M.split(`,`)),P=20*1024*1024,F=typeof window<`u`&&/^(localhost|127\.0\.0\.1|[a-z0-9-]+\.local)(:|$)/.test(window.location.hostname);function I(){let e=crypto.getRandomValues(new Uint8Array(16));e[6]=e[6]&15|64,e[8]=e[8]&63|128;let t=[...e].map(e=>e.toString(16).padStart(2,`0`)).join(``);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}function L(){let e=window.location.pathname;if(e.startsWith(`/g/`))return;let t=e.match(/^\/([a-z][a-z0-9-]{2,49})$/);return t?t[1]:void 0}function R(){let e=window.location.pathname.match(/^\/g\/([a-z0-9][a-z0-9-]{0,49})$/);return e?e[1]:void 0}function z(e){return[{key:`length`,label:`At least 8 characters`,met:e.length>=8},{key:`number`,label:`Contains a number`,met:/\d/.test(e)},{key:`special`,label:`Contains a special character`,met:/[^A-Za-z0-9]/.test(e)},{key:`whitespace`,label:`No spaces`,met:e.length>0&&!/\s/.test(e)}]}function B(e,t){if(t===`phone`)return e.length>4?e.slice(0,e.length-4).replace(/\d/g,`•`)+` `+e.slice(-4):e;let n=e.indexOf(`@`);return n<=2?e:e.slice(0,2)+`•••`+e.slice(n)}function ee(e){let[t,n]=(0,j.useState)(null),[r,i]=(0,j.useState)(null),[a,o]=(0,j.useState)(`loading`),[s,c]=(0,j.useState)(``),[l,u]=(0,j.useState)(null),[d,f]=(0,j.useState)(null),[p,m]=(0,j.useState)(!1),[h,g]=(0,j.useState)(null),_=(0,j.useMemo)(()=>L(),[]),v=(0,j.useMemo)(()=>R(),[]),[y,b]=(0,j.useState)(null),x=(0,j.useRef)(_||``),S=(0,j.useRef)(null),C=(0,j.useRef)(null),w=(0,j.useRef)(!1),T=(0,j.useRef)(null),[E,D]=(0,j.useState)(`sign-in`),[O,k]=(0,j.useState)(null),A=(0,j.useRef)(null),M=(0,j.useRef)(null);(0,j.useEffect)(()=>{try{let e=sessionStorage.getItem(`maxy_session`);e&&(M.current=e)}catch{}},[]);let N=(0,j.useCallback)(t=>{S.current=t,n(t);try{sessionStorage.setItem(`maxy_session`,t)}catch{}o(`chat`),e(t)},[e]),P=(0,j.useCallback)(()=>{S.current=null;try{sessionStorage.removeItem(`maxy_session`)}catch{}n(null),o(`auth-required`),D(`sign-in`)},[]),z=(0,j.useCallback)(async e=>{try{let t=x.current,n=await fetch(`/api/access/verify-token`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({token:e,agentSlug:t})}),r=await n.json();n.ok?(A.current=r.session_key,k(r.grant),D(`set-password`),window.history.replaceState({},``,window.location.pathname)):D(`link-expired`)}catch{D(`sign-in`)}},[]),B=(0,j.useCallback)(async()=>{if(S.current)return S.current;if(C.current)return C.current;let e=(async()=>{try{let e=M.current,t=await fetch(`/api/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({session_id:I(),..._?{agent:_}:{},...v?{group_slug:v}:{},...e?{session_key:e}:{}})});if(!t.ok){let e=await t.json().catch(()=>({error:``}));return F&&console.error(`[session] POST /api/session failed: ${t.status} ${t.statusText}`,e),t.status===404?i(e.error||`Agent not found`):t.status===503&&i(e.error||`Service unavailable`),null}let r=await t.json();if(r.auth_required){r.agent_id&&(x.current=r.agent_id),c(r.displayName||``),r.agentImage&&u(r.agentImage),r.agentImageShape&&f(r.agentImageShape),r.showAgentName&&m(r.showAgentName),r.branding&&g(r.branding),o(`auth-required`);let e=new URLSearchParams(window.location.search).get(`token`);return e?z(e):D(`sign-in`),null}S.current=r.session_key,n(r.session_key),r.displayName&&c(r.displayName),r.agentImage&&u(r.agentImage),r.agentImageShape&&f(r.agentImageShape),r.showAgentName&&m(r.showAgentName),r.branding&&g(r.branding),o(`chat`),r.resumed&&r.messages&&(w.current=!0,T.current=r.messages),r.group&&b({groupSlug:r.groupSlug,groupName:r.groupName,participants:r.participants??[]});try{sessionStorage.setItem(`maxy_session`,r.session_key)}catch{}return r.session_key}catch(e){return F&&console.error(`[session] fetch /api/session threw:`,e),i(`Unable to connect. Please check your connection and try again.`),null}finally{C.current=null}})();return C.current=e,e},[_,v,z]);return{sessionId:t,sessionKeyRef:S,sessionError:r,pageState:a,setPageState:o,agentDisplayName:s,agentImage:l,agentImageShape:d,showAgentName:p,agentSlug:_,branding:h,resolvedSlugRef:x,ensureSession:B,startNewSession:(0,j.useCallback)(async()=>{S.current=null,C.current=null,M.current=null,w.current=!1,T.current=null,n(null),i(null);try{sessionStorage.removeItem(`maxy_session`)}catch{}let t=await B();t&&e(t)},[B,e]),enterChat:N,enterGate:P,resumedRef:w,resumeMessagesRef:T,gateState:E,setGateState:D,grantInfo:O,setGrantInfo:k,gateSessionKeyRef:A,groupContext:y,groupSlug:v}}function te({sessionKeyRef:e,ensureSession:t,sessionError:n,pageState:r,inputRef:i}){let[a,o]=(0,j.useState)([]),[s,c]=(0,j.useState)(!1),l=(0,j.useRef)(!1),u=e=>{l.current=e,c(e)},d=(0,j.useCallback)(async a=>{if(!l.current){u(!0),o([{role:`maxy`,content:``,timestamp:Date.now()}]);try{let n=await fetch(`/api/chat`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({greeting:!0,session_key:a})});if(n.status===401){e.current=null;try{sessionStorage.removeItem(`maxy_session`)}catch{}F&&console.warn(`[greeting] stale session, retrying with fresh session`);let r=await t();if(!r)return;n=await fetch(`/api/chat`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({greeting:!0,session_key:r})})}if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error||`Something went wrong`)}let r=``,i=``,s=()=>{i&&(r+=i,i=``,o(e=>{let t=[...e];return t[0]={...t[0],content:r},t}))},c=setInterval(s,60);try{for await(let e of p(n)){if(e.error)throw Object.assign(Error(e.error),{fromSSE:!0});e.text&&(i+=e.text),e.type===`component`&&(s(),o(t=>{let n=[...t],r={...n[0]},i=[...r.components||[]];return i.push({name:e.name,data:e.data,submitted:!1}),n[0]={...r,components:i},n}))}}finally{clearInterval(c),s()}}catch(e){if(F&&console.error(`[chat] greeting failed:`,e),r===`auth-required`)return;let t=e instanceof Error?e.message:String(e);o([{role:`maxy`,content:e instanceof Error&&e.fromSSE?t:n??`I'm having trouble connecting right now. Try refreshing the page.`,timestamp:Date.now()}])}finally{u(!1),r===`chat`&&i.current?.focus()}}},[e,t,n,r,i]),f=(0,j.useCallback)(async(a,s)=>{let c=s?.hidden??!1,d=s?.files??[];if(!a&&d.length===0||l.current)return;u(!0);let f=d.map(e=>({filename:e.name,mimeType:e.type})),m={role:`visitor`,content:a,attachments:f.length>0?f:void 0,timestamp:Date.now(),hidden:c},h;o(e=>{let t=[...e,m,{role:`maxy`,content:``,timestamp:Date.now()}];return h=t.length-1,t});try{let n=await t();if(!n)throw Error(`session`);let r=e=>{if(d.length>0){let t=new FormData;t.append(`message`,a),t.append(`session_key`,e);for(let e of d)t.append(`attachments`,e);return{body:t,headers:{}}}return{body:JSON.stringify({message:a,session_key:e}),headers:{"Content-Type":`application/json`}}},{body:i,headers:s}=r(n),c=await fetch(`/api/chat`,{method:`POST`,headers:s,body:i});if(c.status===401){e.current=null;try{sessionStorage.removeItem(`maxy_session`)}catch{}F&&console.warn(`[session-expired] stale key cleared, retrying with fresh session`);let n=await t();if(!n)throw Error(`session`);({body:i,headers:s}=r(n)),c=await fetch(`/api/chat`,{method:`POST`,headers:s,body:i})}if(!c.ok){let e=await c.json().catch(()=>({}));throw Error(e.error||`Something went wrong`)}let l=``,u=``,f=()=>{u&&(l+=u,u=``,o(e=>{let t=[...e];return t[h]={...t[h],content:l},t}))},m=setInterval(f,60);try{for await(let e of p(c)){if(e.error)throw Object.assign(Error(e.error),{fromSSE:!0});e.text&&(u+=e.text),e.type===`component`&&(f(),o(t=>{let n=[...t],r={...n[h]},i=[...r.components||[]];return i.push({name:e.name,data:e.data,submitted:!1}),n[h]={...r,components:i},n}))}}finally{clearInterval(m),f()}}catch(e){if(F&&console.error(`[chat] sendMessage failed:`,e),r===`auth-required`)return;let t=e instanceof Error?e.message:String(e),i=e instanceof Error&&e.fromSSE;o(e=>{let r=[...e];return r[h]={...r[h],content:i?t:t===`session`?n??`I'm having trouble connecting right now. Try refreshing the page.`:`Sorry, I hit a snag. Try again in a moment.`},r})}finally{u(!1),r===`chat`&&i.current?.focus()}},[e,t,n,r,i]);return{messages:a,setMessages:o,isStreaming:s,sendMessage:f,sendGreeting:d,handleComponentSubmit:(0,j.useCallback)((e,t,n)=>{o(n=>{let r=[...n],i={...r[e]},a=[...i.components||[]];return a[t]={...a[t],submitted:!0},r[e]={...i,components:a},r}),f(n,{hidden:!0})},[f])}}function ne({sessionKeyRef:e,groupSlug:t,isStreaming:n,setMessages:r}){let i=(0,j.useRef)(new Date().toISOString()),a=(0,j.useRef)(!0);(0,j.useEffect)(()=>{let e=()=>{a.current=document.visibilityState===`visible`};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[]);let o=(0,j.useCallback)(async()=>{let n=e.current;if(!(!n||!t))try{let e=await fetch(`/api/group/messages?session_key=${encodeURIComponent(n)}&since=${encodeURIComponent(i.current)}`);if(!e.ok)return;let t=await e.json();if(!t.messages||t.messages.length===0)return;let a=t.messages[t.messages.length-1];a.timestamp&&(i.current=new Date(a.timestamp).toISOString()),r(e=>{let n=new Set(e.filter(e=>e.messageId).map(e=>e.messageId)),r=t.messages.filter(e=>!n.has(e.messageId)).map(e=>({role:e.role,content:e.content,timestamp:e.timestamp,senderName:e.senderName??void 0,senderVisitorId:e.senderVisitorId??void 0,messageId:e.messageId}));if(r.length===0)return e;let i=[...e,...r];return i.sort((e,t)=>e.timestamp-t.timestamp),i})}catch(e){console.error(`[group-poll] failed: ${e instanceof Error?e.message:String(e)}`)}},[e,t,r]);(0,j.useEffect)(()=>{if(!t)return;let e,r=!1;function i(){if(r)return;let t=a.current?3e3:3e4;e=setTimeout(async()=>{n||await o(),i()},t)}return i(),()=>{r=!0,clearTimeout(e)}},[t,n,o])}var V=i();function H({value:e,onChange:t,onComplete:n,disabled:r}){let i=(0,j.useRef)([]);function a(n,r){r.key===`Backspace`?(r.preventDefault(),e[n]?t(e.slice(0,n)+e.slice(n+1)):n>0&&(t(e.slice(0,n-1)+e.slice(n)),i.current[n-1]?.focus())):r.key===`ArrowLeft`&&n>0?i.current[n-1]?.focus():r.key===`ArrowRight`&&n<5&&i.current[n+1]?.focus()}function o(r,a){let o=a.nativeEvent.data;if(!o||!/^\d$/.test(o))return;let s=e.split(``);for(s[r]=o;s.length<r;)s.push(``);let c=s.join(``).replace(/\D/g,``).slice(0,6);t(c),c.length===6?n(c):r<5&&i.current[r+1]?.focus()}function s(e){e.preventDefault();let r=e.clipboardData.getData(`text`).replace(/\D/g,``).slice(0,6);r&&(t(r),r.length===6?n(r):i.current[r.length]?.focus())}return(0,V.jsx)(`div`,{className:`gate-otp-field`,children:Array.from({length:6}).map((t,n)=>(0,V.jsx)(`input`,{ref:e=>{i.current[n]=e},type:`text`,inputMode:`numeric`,className:`pin-box${e[n]?` pin-box-filled`:``}`,value:e[n]||``,onKeyDown:e=>a(n,e),onInput:e=>o(n,e),onPaste:s,onFocus:e=>e.target.select(),autoFocus:n===0,autoComplete:`off`,maxLength:1,disabled:r,"aria-label":`Code digit ${n+1}`},n))})}function U({gateState:e,setGateState:t,grantInfo:n,setGrantInfo:r,gateSessionKeyRef:i,resolvedSlugRef:a,onAuthenticated:o}){let[s,c]=(0,j.useState)(``),[l,u]=(0,j.useState)(``),[d,f]=(0,j.useState)(``),[p,m]=(0,j.useState)(!1),[h,_]=(0,j.useState)(``),[v,y]=(0,j.useState)(``),[b,x]=(0,j.useState)(!1),[S,C]=(0,j.useState)(null),[w,T]=(0,j.useState)(null),[E,D]=(0,j.useState)(!1);async function k(e){if(e.preventDefault(),!E){C(null),D(!0);try{let e=a.current,n=await fetch(`/api/access/login`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({contact:s,password:l,agentSlug:e})}),i=await n.json();n.ok?o(i.session_key):n.status===401?i.error?.includes(`setup not complete`)||i.error?.includes(`invitation link`)?(t(`private-agent`),C(null)):C(i.error||`Invalid credentials`):n.status===403?(t(`access-expired`),i.expiresAt&&r(e=>e?{...e,expiresAt:i.expiresAt}:{displayName:null,contactValue:s,contactMethod:`email`,expiresAt:i.expiresAt,status:`expired`})):n.status===429?C(i.error||`Too many attempts. Please try again later.`):C(i.error||`Something went wrong`)}catch{C(`Unable to connect. Please try again.`)}finally{D(!1)}}}async function A(e){if(!E){C(null),D(!0);try{let n=a.current,o=await fetch(`/api/access/verify-otp`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({phone:v,code:e,agentSlug:n})}),s=await o.json();o.ok?(i.current=s.session_key,r(s.grant),t(`set-password`)):o.status===429?t(`otp-failed`):(C(s.error||`Invalid code`),_(``))}catch{C(`Unable to connect. Please try again.`)}finally{D(!1)}}}async function M(e){if(e.preventDefault(),!E){if(C(null),l!==d){C(`Passwords do not match`);return}if(!z(l).every(e=>e.met)){C(`Password does not meet requirements`);return}D(!0);try{let e=i.current;if(!e){C(`Session expired. Please use your invitation link again.`);return}let t=await fetch(`/api/access/create-credentials`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({session_key:e,password:l})}),n=await t.json();t.ok?o(n.session_key):t.status===400&&n.requirements?C(n.requirements.filter(e=>!e.met).map(e=>e.label).join(`, `)):C(n.error||`Something went wrong`)}catch{C(`Unable to connect. Please try again.`)}finally{D(!1)}}}async function N(e){if(e.preventDefault(),!(E||!s)){C(null),D(!0);try{let e=a.current,t=await fetch(`/api/access/forgot-password`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({contact:s,agentSlug:e})});t.status===429?C((await t.json()).error||`Too many attempts. Please try again later.`):(T(`If an account exists, a reset link has been sent.`),setTimeout(()=>{x(!1),T(null)},4e3))}catch{C(`Unable to connect. Please try again.`)}finally{D(!1)}}}switch(e){case`set-password`:{let e=z(l),t=e.every(e=>e.met),r=l===d,i=t&&r&&d.length>0;return(0,V.jsx)(`div`,{className:`gate-wrap`,children:(0,V.jsxs)(`div`,{className:`gate-card`,children:[n?.expiresAt&&(0,V.jsxs)(`div`,{className:`gate-expiry-badge`,children:[`Access until `,new Date(n.expiresAt).toLocaleDateString(`en-GB`,{day:`numeric`,month:`short`,year:`numeric`})]}),(0,V.jsxs)(`h2`,{className:`gate-title`,children:[`Welcome, `,n?.displayName||`there`]}),(0,V.jsx)(`p`,{className:`gate-subtitle`,children:`Create a password to access this agent in the future.`}),(0,V.jsxs)(`form`,{className:`gate-form`,onSubmit:M,children:[(0,V.jsxs)(`div`,{className:`gate-field`,children:[(0,V.jsx)(`label`,{htmlFor:`gate-display-name`,children:`Display name`}),(0,V.jsx)(`input`,{id:`gate-display-name`,type:`text`,value:n?.displayName||``,disabled:!0})]}),(0,V.jsxs)(`div`,{className:`gate-field gate-pw-row`,children:[(0,V.jsx)(`label`,{htmlFor:`gate-pw`,children:`Password`}),(0,V.jsx)(`div`,{className:`gate-pw-toggle`,children:(0,V.jsx)(O,{checked:p,onChange:m,label:`Show`})}),(0,V.jsx)(`input`,{id:`gate-pw`,type:p?`text`:`password`,value:l,onChange:e=>u(e.target.value),placeholder:`Your password`,autoFocus:!0,autoComplete:`new-password`}),l.length>0&&(0,V.jsx)(`div`,{className:`gate-strength`,children:e.map(e=>(0,V.jsxs)(`span`,{className:`gate-strength-item${e.met?` met`:``}`,children:[e.met?`✓`:`○`,` `,e.label]},e.key))})]}),(0,V.jsxs)(`div`,{className:`gate-field`,children:[(0,V.jsx)(`label`,{htmlFor:`gate-pw-confirm`,children:`Confirm password`}),(0,V.jsx)(`input`,{id:`gate-pw-confirm`,type:p?`text`:`password`,value:d,onChange:e=>f(e.target.value),placeholder:`Confirm your password`,autoComplete:`new-password`}),d.length>0&&!r&&(0,V.jsx)(`div`,{className:`gate-error`,children:`Passwords do not match`})]}),S&&(0,V.jsx)(`div`,{className:`gate-error`,children:S}),(0,V.jsx)(`div`,{className:`gate-submit`,children:(0,V.jsx)(g,{variant:`primary`,type:`submit`,fullWidth:!0,disabled:!i||E,loading:E,children:`Create account & enter chat`})})]})]})})}case`enter-otp`:return(0,V.jsx)(`div`,{className:`gate-wrap`,children:(0,V.jsxs)(`div`,{className:`gate-card`,children:[(0,V.jsx)(`h2`,{className:`gate-title`,children:`Enter your code`}),(0,V.jsxs)(`p`,{className:`gate-subtitle`,children:[`Enter the 6-digit code sent to `,B(v,`phone`)]}),(0,V.jsx)(H,{value:h,onChange:_,onComplete:A,disabled:E}),S&&(0,V.jsx)(`div`,{className:`gate-error`,children:S}),E&&(0,V.jsxs)(`div`,{className:`gate-loading`,children:[(0,V.jsx)(`span`,{className:`spinner`}),`Verifying...`]}),(0,V.jsx)(`div`,{className:`gate-resend`,children:(0,V.jsx)(`button`,{type:`button`,className:`gate-link`,onClick:()=>{t(`sign-in`),_(``),C(null)},children:`Use a different number`})})]})});case`sign-in`:case`private-agent`:return(0,V.jsx)(`div`,{className:`gate-wrap`,children:(0,V.jsxs)(`div`,{className:`gate-card`,children:[(0,V.jsx)(`h2`,{className:`gate-title`,children:e===`private-agent`?`Private Agent`:`Welcome back`}),(0,V.jsx)(`p`,{className:`gate-subtitle`,children:e===`private-agent`?`This agent is invitation-only. If you have an account, sign in below.`:`Sign in to continue your conversation.`}),b?(0,V.jsxs)(`form`,{className:`gate-form`,onSubmit:N,children:[(0,V.jsxs)(`div`,{className:`gate-field`,children:[(0,V.jsx)(`label`,{htmlFor:`gate-forgot-contact`,children:`Email or phone`}),(0,V.jsx)(`input`,{id:`gate-forgot-contact`,type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:`you@example.com`,autoFocus:!0,autoComplete:`email`})]}),S&&(0,V.jsx)(`div`,{className:`gate-error`,children:S}),w&&(0,V.jsx)(`div`,{className:`gate-success`,children:w}),(0,V.jsx)(`div`,{className:`gate-submit`,children:(0,V.jsx)(g,{variant:`primary`,type:`submit`,fullWidth:!0,disabled:!s.trim()||E,loading:E,children:`Send reset link`})}),(0,V.jsx)(`div`,{className:`gate-actions`,children:(0,V.jsx)(`button`,{type:`button`,className:`gate-link`,onClick:()=>{x(!1),C(null),T(null)},children:`Back to sign in`})})]}):(0,V.jsxs)(`form`,{className:`gate-form`,onSubmit:k,children:[(0,V.jsxs)(`div`,{className:`gate-field`,children:[(0,V.jsx)(`label`,{htmlFor:`gate-contact`,children:`Email or phone`}),(0,V.jsx)(`input`,{id:`gate-contact`,type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:`you@example.com`,autoFocus:!0,autoComplete:`email`})]}),(0,V.jsxs)(`div`,{className:`gate-field gate-pw-row`,children:[(0,V.jsx)(`label`,{htmlFor:`gate-login-pw`,children:`Password`}),(0,V.jsx)(`div`,{className:`gate-pw-toggle`,children:(0,V.jsx)(O,{checked:p,onChange:m,label:`Show`})}),(0,V.jsx)(`input`,{id:`gate-login-pw`,type:p?`text`:`password`,value:l,onChange:e=>u(e.target.value),placeholder:`Your password`,autoComplete:`current-password`})]}),S&&(0,V.jsx)(`div`,{className:`gate-error`,children:S}),(0,V.jsx)(`div`,{className:`gate-submit`,children:(0,V.jsx)(g,{variant:`primary`,type:`submit`,fullWidth:!0,disabled:!s.trim()||!l||E,loading:E,children:`Sign in`})}),(0,V.jsx)(`div`,{className:`gate-actions`,children:(0,V.jsx)(`button`,{type:`button`,className:`gate-link`,onClick:()=>{x(!0),C(null)},children:`Forgot password?`})})]}),e===`private-agent`&&(0,V.jsx)(`p`,{className:`gate-hint`,children:`No account? You need an invitation from the agent owner.`})]})});case`access-expired`:return(0,V.jsx)(`div`,{className:`gate-wrap`,children:(0,V.jsxs)(`div`,{className:`gate-card`,children:[(0,V.jsx)(`div`,{className:`gate-icon`,children:`⏰`}),(0,V.jsx)(`h2`,{className:`gate-title`,children:`Access expired`}),(0,V.jsxs)(`p`,{className:`gate-subtitle`,children:[n?.expiresAt?`Your access expired on ${new Date(n.expiresAt).toLocaleDateString(`en-GB`,{day:`numeric`,month:`long`,year:`numeric`})}.`:`Your access to this agent has expired.`,` `,`Contact the agent owner to renew.`]}),(0,V.jsx)(`div`,{className:`gate-actions`,children:(0,V.jsx)(g,{variant:`secondary`,onClick:()=>{t(`sign-in`),C(null),u(``)},children:`Sign in with a different account`})})]})});case`link-expired`:return(0,V.jsx)(`div`,{className:`gate-wrap`,children:(0,V.jsxs)(`div`,{className:`gate-card`,children:[(0,V.jsx)(`div`,{className:`gate-icon`,children:`⚠️`}),(0,V.jsx)(`h2`,{className:`gate-title`,children:`Link expired`}),(0,V.jsx)(`p`,{className:`gate-subtitle`,children:`This invitation link has expired or has already been used. If you already set your password, sign in below. Otherwise, ask the agent owner to send a new invitation.`}),(0,V.jsx)(`div`,{className:`gate-actions`,children:(0,V.jsx)(g,{variant:`primary`,onClick:()=>{t(`sign-in`),C(null)},children:`Go to sign in`})})]})});case`otp-failed`:return(0,V.jsx)(`div`,{className:`gate-wrap`,children:(0,V.jsxs)(`div`,{className:`gate-card`,children:[(0,V.jsx)(`div`,{className:`gate-icon`,children:`⛔`}),(0,V.jsx)(`h2`,{className:`gate-title`,children:`Too many attempts`}),(0,V.jsx)(`p`,{className:`gate-subtitle`,children:`You've entered the wrong code too many times. Ask the agent owner to send a new code.`}),(0,V.jsx)(`div`,{className:`gate-actions`,children:(0,V.jsx)(g,{variant:`secondary`,onClick:()=>{t(`sign-in`),C(null),_(``)},children:`Back to sign in`})})]})})}}var W={"single-select":m,"multi-select":S,"action-buttons":b};function G({name:e,data:t,onSubmit:n,submitted:r}){let i=W[e];return i?(0,V.jsx)(i,{data:t,onSubmit:n,submitted:r}):(console.warn(`[PublicComponentRenderer] Unknown component: "${e}". Registered: ${Object.keys(W).join(`, `)}`),(0,V.jsx)(`div`,{className:`component-card component-card--error`,children:(0,V.jsxs)(`p`,{style:{fontFamily:`var(--font-body)`,fontSize:12,color:`var(--text-secondary)`},children:[`Component “`,e,`” is not available. This may require a platform update.`]})}))}function re({messages:e,isStreaming:t,sessionError:n,selectionMode:r,selectedItems:i,toggleSelectItem:o,onComponentSubmit:s,remainingSuggestions:l,onSuggestionClick:u,isAtBottom:d,setIsAtBottom:p,isGroup:m,sessionId:h}){let[_,y]=(0,j.useState)(new Set),[b,x]=(0,j.useState)(new Set),S=(0,j.useRef)(null),C=(0,j.useRef)(null),T=(0,j.useRef)(null),E=(0,j.useRef)(!1),D=(0,j.useRef)(!1),k=(0,j.useRef)(!1),A=(0,j.useRef)(0),M=(0,j.useRef)(!1),N=(0,j.useRef)(new Map);M.current=t,(0,j.useEffect)(()=>{t&&!E.current&&d&&(D.current=!0)},[t,d]),(0,j.useEffect)(()=>{if(!D.current&&!d){E.current=t,k.current=!1;return}if(E.current&&!t&&T.current&&C.current){let e=T.current;if(e.offsetHeight>C.current.clientHeight){D.current=!1,k.current=!0,e.scrollIntoView({behavior:`smooth`,block:`start`}),E.current=t;return}}(d||D.current)&&!k.current&&S.current?.scrollIntoView({behavior:`smooth`}),E.current&&!t&&(D.current=!1),E.current=t},[e,d,t]),(0,j.useEffect)(()=>{let e=C.current;if(!e)return;let t=()=>{let t=e.scrollTop;M.current&&t<A.current&&(D.current=!1),A.current=t,p(e.scrollHeight-e.scrollTop-e.clientHeight<80)};return e.addEventListener(`scroll`,t,{passive:!0}),t(),()=>e.removeEventListener(`scroll`,t)},[p]),(0,j.useEffect)(()=>{function e(){x(e=>{let t=new Set;return N.current.forEach((n,r)=>{n.isConnected&&(_.has(r)?e.has(r)&&t.add(r):n.scrollHeight>n.clientHeight+2&&t.add(r))}),e.size===t.size&&[...e].every(e=>t.has(e))?e:t})}e();let t=new ResizeObserver(e);return N.current.forEach(e=>t.observe(e)),()=>t.disconnect()},[e.length,_]);let P=[...e].sort((e,t)=>e.timestamp-t.timestamp);(0,j.useEffect)(()=>{r&&console.log(`[selection] entered`,{conversationId:h??`unknown`,order:P.map(e=>({ts:e.timestamp,role:e.role,id:e.messageId}))})},[r]);let F=P.reduce((e,t,n)=>t.role===`maxy`&&!t.hidden?n:e,-1);return(0,V.jsxs)(`div`,{className:`chat-messages-wrap`,children:[r&&(0,V.jsx)(`div`,{className:`selection-overlay-band`}),(0,V.jsxs)(`div`,{className:`chat-messages`,ref:C,children:[n&&e.length===0&&(0,V.jsx)(`div`,{className:`session-error`,children:(0,V.jsx)(`p`,{children:n})}),P.map((e,n)=>{if(e.hidden)return null;let l=t&&n===P.length-1,u=`${e.timestamp}_${e.role}`,d=i.has(u);return(0,V.jsxs)(`div`,{ref:n===F?T:void 0,className:`message ${e.role}${d?` selected`:``}`,children:[r&&!l&&(0,V.jsx)(`div`,{className:`message-select-check`,children:(0,V.jsx)(O,{checked:d,onChange:()=>o(u)})}),(0,V.jsxs)(`div`,{className:`bubble`,children:[m&&e.role===`visitor`&&e.senderName&&(0,V.jsx)(`span`,{className:`bubble-sender`,children:e.senderName}),e.role===`visitor`&&e.content?(()=>{let t=_.has(n),r=b.has(n);return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`div`,{ref:e=>{e?N.current.set(n,e):N.current.delete(n)},className:t?`bubble-content`:`bubble-content clamped${r?` overflowing`:``}`,children:e.content}),r&&(0,V.jsx)(`div`,{className:`bubble-expand`,children:(0,V.jsx)(g,{variant:`icon`,className:t?`expanded`:``,onClick:()=>y(e=>{let t=new Set(e);return t.has(n)?t.delete(n):t.add(n),t}),"aria-label":t?`Collapse message`:`Expand message`,children:(0,V.jsx)(c,{size:14})})})]})})():e.content?(0,V.jsx)(w,{content:e.content,timestamp:f(e.timestamp)}):(0,V.jsxs)(`span`,{className:`typing-indicator`,children:[(0,V.jsx)(`span`,{className:`typing-dot`}),(0,V.jsx)(`span`,{className:`typing-dot`}),(0,V.jsx)(`span`,{className:`typing-dot`})]}),e.attachments&&e.attachments.length>0&&(0,V.jsx)(`div`,{className:`message-attachments`,children:e.attachments.map((e,t)=>(0,V.jsxs)(`span`,{className:`message-attachment-chip no-action`,children:[e.mimeType===`application/pdf`?(0,V.jsx)(a,{size:12}):e.mimeType.startsWith(`text/`)?(0,V.jsx)(v,{size:12}):null,(0,V.jsx)(`span`,{children:e.filename})]},t))}),e.role===`visitor`&&(0,V.jsx)(`span`,{className:`message-timestamp`,children:f(e.timestamp)})]}),e.role===`maxy`&&e.components&&e.components.length>0&&(0,V.jsx)(`div`,{className:`public-components`,children:e.components.map((e,t)=>(0,V.jsx)(`div`,{className:`public-component-enter`,children:(0,V.jsx)(G,{name:e.name,data:e.data,onSubmit:e=>s(n,t,e),submitted:e.submitted})},t))})]},n)}),!t&&l.length>0&&(0,V.jsx)(`div`,{className:`chat-suggestions`,children:l.map(e=>(0,V.jsx)(g,{variant:`suggestion`,onClick:()=>u(e),children:e},e))}),(0,V.jsx)(`div`,{ref:S})]}),!d&&(0,V.jsx)(`button`,{className:`scroll-to-bottom`,onClick:()=>S.current?.scrollIntoView({behavior:`smooth`}),"aria-label":`Scroll to bottom`,children:(0,V.jsx)(c,{size:18})})]})}function ie({selectedItems:e,messages:t,isStreaming:n,copySelected:r,selectAll:i,exitSelection:a,showCopyToast:o}){let[c,l]=(0,j.useState)(!1),u=(0,j.useRef)(null),d=(0,j.useRef)(!1);function f(e){let n=e.lastIndexOf(`_`),r=e.slice(0,n),i=e.slice(n+1),a=parseInt(r,10);return t.find(e=>e.timestamp===a&&e.role===i)?.content??``}function p(e,t){return parseInt(e.slice(0,e.lastIndexOf(`_`)),10)-parseInt(t.slice(0,t.lastIndexOf(`_`)),10)}function m(){let e=[...t].sort((e,t)=>e.timestamp-t.timestamp),n=[];for(let t of e){if(t.hidden||!t.content)continue;let e=t.role===`visitor`?`Visitor`:`Maxy`;n.push(`${e}:\n${t.content}`)}return n.join(`
|
|
1
|
+
import{o as e}from"./chunk-DD-I1_y5.js";import{i as t,o as n,r,t as i}from"./jsx-runtime-WW3O7tSz.js";import{A as a,D as o,M as s,N as c,O as l,S as u,_ as d,a as f,b as p,c as m,g as h,h as g,i as _,j as v,n as y,o as b,r as x,s as S,t as C,u as w,v as T,w as E,x as D}from"./useVoiceRecorder-Bx903Mk1.js";import{t as O}from"./Checkbox-aCc0UGp3.js";var k=r(`square-plus`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M8 12h8`,key:`1wcyev`}],[`path`,{d:`M12 8v8`,key:`napkw2`}]]),A=t(),j=e(n(),1),M=`image/jpeg,image/png,image/gif,image/webp,application/pdf,text/plain,text/markdown,text/csv,text/html,text/calendar`,N=new Set(M.split(`,`)),P=50*1024*1024,F=typeof window<`u`&&/^(localhost|127\.0\.0\.1|[a-z0-9-]+\.local)(:|$)/.test(window.location.hostname);function I(){let e=crypto.getRandomValues(new Uint8Array(16));e[6]=e[6]&15|64,e[8]=e[8]&63|128;let t=[...e].map(e=>e.toString(16).padStart(2,`0`)).join(``);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}function L(){let e=window.location.pathname;if(e.startsWith(`/g/`))return;let t=e.match(/^\/([a-z][a-z0-9-]{2,49})$/);return t?t[1]:void 0}function R(){let e=window.location.pathname.match(/^\/g\/([a-z0-9][a-z0-9-]{0,49})$/);return e?e[1]:void 0}function z(e){return[{key:`length`,label:`At least 8 characters`,met:e.length>=8},{key:`number`,label:`Contains a number`,met:/\d/.test(e)},{key:`special`,label:`Contains a special character`,met:/[^A-Za-z0-9]/.test(e)},{key:`whitespace`,label:`No spaces`,met:e.length>0&&!/\s/.test(e)}]}function B(e,t){if(t===`phone`)return e.length>4?e.slice(0,e.length-4).replace(/\d/g,`•`)+` `+e.slice(-4):e;let n=e.indexOf(`@`);return n<=2?e:e.slice(0,2)+`•••`+e.slice(n)}function ee(e){let[t,n]=(0,j.useState)(null),[r,i]=(0,j.useState)(null),[a,o]=(0,j.useState)(`loading`),[s,c]=(0,j.useState)(``),[l,u]=(0,j.useState)(null),[d,f]=(0,j.useState)(null),[p,m]=(0,j.useState)(!1),[h,g]=(0,j.useState)(null),_=(0,j.useMemo)(()=>L(),[]),v=(0,j.useMemo)(()=>R(),[]),[y,b]=(0,j.useState)(null),x=(0,j.useRef)(_||``),S=(0,j.useRef)(null),C=(0,j.useRef)(null),w=(0,j.useRef)(!1),T=(0,j.useRef)(null),[E,D]=(0,j.useState)(`sign-in`),[O,k]=(0,j.useState)(null),A=(0,j.useRef)(null),M=(0,j.useRef)(null);(0,j.useEffect)(()=>{try{let e=sessionStorage.getItem(`maxy_session`);e&&(M.current=e)}catch{}},[]);let N=(0,j.useCallback)(t=>{S.current=t,n(t);try{sessionStorage.setItem(`maxy_session`,t)}catch{}o(`chat`),e(t)},[e]),P=(0,j.useCallback)(()=>{S.current=null;try{sessionStorage.removeItem(`maxy_session`)}catch{}n(null),o(`auth-required`),D(`sign-in`)},[]),z=(0,j.useCallback)(async e=>{try{let t=x.current,n=await fetch(`/api/access/verify-token`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({token:e,agentSlug:t})}),r=await n.json();n.ok?(A.current=r.session_key,k(r.grant),D(`set-password`),window.history.replaceState({},``,window.location.pathname)):D(`link-expired`)}catch{D(`sign-in`)}},[]),B=(0,j.useCallback)(async()=>{if(S.current)return S.current;if(C.current)return C.current;let e=(async()=>{try{let e=M.current,t=await fetch(`/api/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({session_id:I(),..._?{agent:_}:{},...v?{group_slug:v}:{},...e?{session_key:e}:{}})});if(!t.ok){let e=await t.json().catch(()=>({error:``}));return F&&console.error(`[session] POST /api/session failed: ${t.status} ${t.statusText}`,e),t.status===404?i(e.error||`Agent not found`):t.status===503&&i(e.error||`Service unavailable`),null}let r=await t.json();if(r.auth_required){r.agent_id&&(x.current=r.agent_id),c(r.displayName||``),r.agentImage&&u(r.agentImage),r.agentImageShape&&f(r.agentImageShape),r.showAgentName&&m(r.showAgentName),r.branding&&g(r.branding),o(`auth-required`);let e=new URLSearchParams(window.location.search).get(`token`);return e?z(e):D(`sign-in`),null}S.current=r.session_key,n(r.session_key),r.displayName&&c(r.displayName),r.agentImage&&u(r.agentImage),r.agentImageShape&&f(r.agentImageShape),r.showAgentName&&m(r.showAgentName),r.branding&&g(r.branding),o(`chat`),r.resumed&&r.messages&&(w.current=!0,T.current=r.messages),r.group&&b({groupSlug:r.groupSlug,groupName:r.groupName,participants:r.participants??[]});try{sessionStorage.setItem(`maxy_session`,r.session_key)}catch{}return r.session_key}catch(e){return F&&console.error(`[session] fetch /api/session threw:`,e),i(`Unable to connect. Please check your connection and try again.`),null}finally{C.current=null}})();return C.current=e,e},[_,v,z]);return{sessionId:t,sessionKeyRef:S,sessionError:r,pageState:a,setPageState:o,agentDisplayName:s,agentImage:l,agentImageShape:d,showAgentName:p,agentSlug:_,branding:h,resolvedSlugRef:x,ensureSession:B,startNewSession:(0,j.useCallback)(async()=>{S.current=null,C.current=null,M.current=null,w.current=!1,T.current=null,n(null),i(null);try{sessionStorage.removeItem(`maxy_session`)}catch{}let t=await B();t&&e(t)},[B,e]),enterChat:N,enterGate:P,resumedRef:w,resumeMessagesRef:T,gateState:E,setGateState:D,grantInfo:O,setGrantInfo:k,gateSessionKeyRef:A,groupContext:y,groupSlug:v}}function te({sessionKeyRef:e,ensureSession:t,sessionError:n,pageState:r,inputRef:i}){let[a,o]=(0,j.useState)([]),[s,c]=(0,j.useState)(!1),l=(0,j.useRef)(!1),u=e=>{l.current=e,c(e)},d=(0,j.useCallback)(async a=>{if(!l.current){u(!0),o([{role:`maxy`,content:``,timestamp:Date.now()}]);try{let n=await fetch(`/api/chat`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({greeting:!0,session_key:a})});if(n.status===401){e.current=null;try{sessionStorage.removeItem(`maxy_session`)}catch{}F&&console.warn(`[greeting] stale session, retrying with fresh session`);let r=await t();if(!r)return;n=await fetch(`/api/chat`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({greeting:!0,session_key:r})})}if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error||`Something went wrong`)}let r=``,i=``,s=()=>{i&&(r+=i,i=``,o(e=>{let t=[...e];return t[0]={...t[0],content:r},t}))},c=setInterval(s,60);try{for await(let e of p(n)){if(e.error)throw Object.assign(Error(e.error),{fromSSE:!0});e.text&&(i+=e.text),e.type===`component`&&(s(),o(t=>{let n=[...t],r={...n[0]},i=[...r.components||[]];return i.push({name:e.name,data:e.data,submitted:!1}),n[0]={...r,components:i},n}))}}finally{clearInterval(c),s()}}catch(e){if(F&&console.error(`[chat] greeting failed:`,e),r===`auth-required`)return;let t=e instanceof Error?e.message:String(e);o([{role:`maxy`,content:e instanceof Error&&e.fromSSE?t:n??`I'm having trouble connecting right now. Try refreshing the page.`,timestamp:Date.now()}])}finally{u(!1),r===`chat`&&i.current?.focus()}}},[e,t,n,r,i]),f=(0,j.useCallback)(async(a,s)=>{let c=s?.hidden??!1,d=s?.files??[];if(!a&&d.length===0||l.current)return;u(!0);let f=d.map(e=>({filename:e.name,mimeType:e.type})),m={role:`visitor`,content:a,attachments:f.length>0?f:void 0,timestamp:Date.now(),hidden:c},h;o(e=>{let t=[...e,m,{role:`maxy`,content:``,timestamp:Date.now()}];return h=t.length-1,t});try{let n=await t();if(!n)throw Error(`session`);let r=e=>{if(d.length>0){let t=new FormData;t.append(`message`,a),t.append(`session_key`,e);for(let e of d)t.append(`attachments`,e);return{body:t,headers:{}}}return{body:JSON.stringify({message:a,session_key:e}),headers:{"Content-Type":`application/json`}}},{body:i,headers:s}=r(n),c=await fetch(`/api/chat`,{method:`POST`,headers:s,body:i});if(c.status===401){e.current=null;try{sessionStorage.removeItem(`maxy_session`)}catch{}F&&console.warn(`[session-expired] stale key cleared, retrying with fresh session`);let n=await t();if(!n)throw Error(`session`);({body:i,headers:s}=r(n)),c=await fetch(`/api/chat`,{method:`POST`,headers:s,body:i})}if(!c.ok){let e=await c.json().catch(()=>({}));throw Error(e.error||`Something went wrong`)}let l=``,u=``,f=()=>{u&&(l+=u,u=``,o(e=>{let t=[...e];return t[h]={...t[h],content:l},t}))},m=setInterval(f,60);try{for await(let e of p(c)){if(e.error)throw Object.assign(Error(e.error),{fromSSE:!0});e.text&&(u+=e.text),e.type===`component`&&(f(),o(t=>{let n=[...t],r={...n[h]},i=[...r.components||[]];return i.push({name:e.name,data:e.data,submitted:!1}),n[h]={...r,components:i},n}))}}finally{clearInterval(m),f()}}catch(e){if(F&&console.error(`[chat] sendMessage failed:`,e),r===`auth-required`)return;let t=e instanceof Error?e.message:String(e),i=e instanceof Error&&e.fromSSE;o(e=>{let r=[...e];return r[h]={...r[h],content:i?t:t===`session`?n??`I'm having trouble connecting right now. Try refreshing the page.`:`Sorry, I hit a snag. Try again in a moment.`},r})}finally{u(!1),r===`chat`&&i.current?.focus()}},[e,t,n,r,i]);return{messages:a,setMessages:o,isStreaming:s,sendMessage:f,sendGreeting:d,handleComponentSubmit:(0,j.useCallback)((e,t,n)=>{o(n=>{let r=[...n],i={...r[e]},a=[...i.components||[]];return a[t]={...a[t],submitted:!0},r[e]={...i,components:a},r}),f(n,{hidden:!0})},[f])}}function ne({sessionKeyRef:e,groupSlug:t,isStreaming:n,setMessages:r}){let i=(0,j.useRef)(new Date().toISOString()),a=(0,j.useRef)(!0);(0,j.useEffect)(()=>{let e=()=>{a.current=document.visibilityState===`visible`};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[]);let o=(0,j.useCallback)(async()=>{let n=e.current;if(!(!n||!t))try{let e=await fetch(`/api/group/messages?session_key=${encodeURIComponent(n)}&since=${encodeURIComponent(i.current)}`);if(!e.ok)return;let t=await e.json();if(!t.messages||t.messages.length===0)return;let a=t.messages[t.messages.length-1];a.timestamp&&(i.current=new Date(a.timestamp).toISOString()),r(e=>{let n=new Set(e.filter(e=>e.messageId).map(e=>e.messageId)),r=t.messages.filter(e=>!n.has(e.messageId)).map(e=>({role:e.role,content:e.content,timestamp:e.timestamp,senderName:e.senderName??void 0,senderVisitorId:e.senderVisitorId??void 0,messageId:e.messageId}));if(r.length===0)return e;let i=[...e,...r];return i.sort((e,t)=>e.timestamp-t.timestamp),i})}catch(e){console.error(`[group-poll] failed: ${e instanceof Error?e.message:String(e)}`)}},[e,t,r]);(0,j.useEffect)(()=>{if(!t)return;let e,r=!1;function i(){if(r)return;let t=a.current?3e3:3e4;e=setTimeout(async()=>{n||await o(),i()},t)}return i(),()=>{r=!0,clearTimeout(e)}},[t,n,o])}var V=i();function H({value:e,onChange:t,onComplete:n,disabled:r}){let i=(0,j.useRef)([]);function a(n,r){r.key===`Backspace`?(r.preventDefault(),e[n]?t(e.slice(0,n)+e.slice(n+1)):n>0&&(t(e.slice(0,n-1)+e.slice(n)),i.current[n-1]?.focus())):r.key===`ArrowLeft`&&n>0?i.current[n-1]?.focus():r.key===`ArrowRight`&&n<5&&i.current[n+1]?.focus()}function o(r,a){let o=a.nativeEvent.data;if(!o||!/^\d$/.test(o))return;let s=e.split(``);for(s[r]=o;s.length<r;)s.push(``);let c=s.join(``).replace(/\D/g,``).slice(0,6);t(c),c.length===6?n(c):r<5&&i.current[r+1]?.focus()}function s(e){e.preventDefault();let r=e.clipboardData.getData(`text`).replace(/\D/g,``).slice(0,6);r&&(t(r),r.length===6?n(r):i.current[r.length]?.focus())}return(0,V.jsx)(`div`,{className:`gate-otp-field`,children:Array.from({length:6}).map((t,n)=>(0,V.jsx)(`input`,{ref:e=>{i.current[n]=e},type:`text`,inputMode:`numeric`,className:`pin-box${e[n]?` pin-box-filled`:``}`,value:e[n]||``,onKeyDown:e=>a(n,e),onInput:e=>o(n,e),onPaste:s,onFocus:e=>e.target.select(),autoFocus:n===0,autoComplete:`off`,maxLength:1,disabled:r,"aria-label":`Code digit ${n+1}`},n))})}function U({gateState:e,setGateState:t,grantInfo:n,setGrantInfo:r,gateSessionKeyRef:i,resolvedSlugRef:a,onAuthenticated:o}){let[s,c]=(0,j.useState)(``),[l,u]=(0,j.useState)(``),[d,f]=(0,j.useState)(``),[p,m]=(0,j.useState)(!1),[h,_]=(0,j.useState)(``),[v,y]=(0,j.useState)(``),[b,x]=(0,j.useState)(!1),[S,C]=(0,j.useState)(null),[w,T]=(0,j.useState)(null),[E,D]=(0,j.useState)(!1);async function k(e){if(e.preventDefault(),!E){C(null),D(!0);try{let e=a.current,n=await fetch(`/api/access/login`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({contact:s,password:l,agentSlug:e})}),i=await n.json();n.ok?o(i.session_key):n.status===401?i.error?.includes(`setup not complete`)||i.error?.includes(`invitation link`)?(t(`private-agent`),C(null)):C(i.error||`Invalid credentials`):n.status===403?(t(`access-expired`),i.expiresAt&&r(e=>e?{...e,expiresAt:i.expiresAt}:{displayName:null,contactValue:s,contactMethod:`email`,expiresAt:i.expiresAt,status:`expired`})):n.status===429?C(i.error||`Too many attempts. Please try again later.`):C(i.error||`Something went wrong`)}catch{C(`Unable to connect. Please try again.`)}finally{D(!1)}}}async function A(e){if(!E){C(null),D(!0);try{let n=a.current,o=await fetch(`/api/access/verify-otp`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({phone:v,code:e,agentSlug:n})}),s=await o.json();o.ok?(i.current=s.session_key,r(s.grant),t(`set-password`)):o.status===429?t(`otp-failed`):(C(s.error||`Invalid code`),_(``))}catch{C(`Unable to connect. Please try again.`)}finally{D(!1)}}}async function M(e){if(e.preventDefault(),!E){if(C(null),l!==d){C(`Passwords do not match`);return}if(!z(l).every(e=>e.met)){C(`Password does not meet requirements`);return}D(!0);try{let e=i.current;if(!e){C(`Session expired. Please use your invitation link again.`);return}let t=await fetch(`/api/access/create-credentials`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({session_key:e,password:l})}),n=await t.json();t.ok?o(n.session_key):t.status===400&&n.requirements?C(n.requirements.filter(e=>!e.met).map(e=>e.label).join(`, `)):C(n.error||`Something went wrong`)}catch{C(`Unable to connect. Please try again.`)}finally{D(!1)}}}async function N(e){if(e.preventDefault(),!(E||!s)){C(null),D(!0);try{let e=a.current,t=await fetch(`/api/access/forgot-password`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({contact:s,agentSlug:e})});t.status===429?C((await t.json()).error||`Too many attempts. Please try again later.`):(T(`If an account exists, a reset link has been sent.`),setTimeout(()=>{x(!1),T(null)},4e3))}catch{C(`Unable to connect. Please try again.`)}finally{D(!1)}}}switch(e){case`set-password`:{let e=z(l),t=e.every(e=>e.met),r=l===d,i=t&&r&&d.length>0;return(0,V.jsx)(`div`,{className:`gate-wrap`,children:(0,V.jsxs)(`div`,{className:`gate-card`,children:[n?.expiresAt&&(0,V.jsxs)(`div`,{className:`gate-expiry-badge`,children:[`Access until `,new Date(n.expiresAt).toLocaleDateString(`en-GB`,{day:`numeric`,month:`short`,year:`numeric`})]}),(0,V.jsxs)(`h2`,{className:`gate-title`,children:[`Welcome, `,n?.displayName||`there`]}),(0,V.jsx)(`p`,{className:`gate-subtitle`,children:`Create a password to access this agent in the future.`}),(0,V.jsxs)(`form`,{className:`gate-form`,onSubmit:M,children:[(0,V.jsxs)(`div`,{className:`gate-field`,children:[(0,V.jsx)(`label`,{htmlFor:`gate-display-name`,children:`Display name`}),(0,V.jsx)(`input`,{id:`gate-display-name`,type:`text`,value:n?.displayName||``,disabled:!0})]}),(0,V.jsxs)(`div`,{className:`gate-field gate-pw-row`,children:[(0,V.jsx)(`label`,{htmlFor:`gate-pw`,children:`Password`}),(0,V.jsx)(`div`,{className:`gate-pw-toggle`,children:(0,V.jsx)(O,{checked:p,onChange:m,label:`Show`})}),(0,V.jsx)(`input`,{id:`gate-pw`,type:p?`text`:`password`,value:l,onChange:e=>u(e.target.value),placeholder:`Your password`,autoFocus:!0,autoComplete:`new-password`}),l.length>0&&(0,V.jsx)(`div`,{className:`gate-strength`,children:e.map(e=>(0,V.jsxs)(`span`,{className:`gate-strength-item${e.met?` met`:``}`,children:[e.met?`✓`:`○`,` `,e.label]},e.key))})]}),(0,V.jsxs)(`div`,{className:`gate-field`,children:[(0,V.jsx)(`label`,{htmlFor:`gate-pw-confirm`,children:`Confirm password`}),(0,V.jsx)(`input`,{id:`gate-pw-confirm`,type:p?`text`:`password`,value:d,onChange:e=>f(e.target.value),placeholder:`Confirm your password`,autoComplete:`new-password`}),d.length>0&&!r&&(0,V.jsx)(`div`,{className:`gate-error`,children:`Passwords do not match`})]}),S&&(0,V.jsx)(`div`,{className:`gate-error`,children:S}),(0,V.jsx)(`div`,{className:`gate-submit`,children:(0,V.jsx)(g,{variant:`primary`,type:`submit`,fullWidth:!0,disabled:!i||E,loading:E,children:`Create account & enter chat`})})]})]})})}case`enter-otp`:return(0,V.jsx)(`div`,{className:`gate-wrap`,children:(0,V.jsxs)(`div`,{className:`gate-card`,children:[(0,V.jsx)(`h2`,{className:`gate-title`,children:`Enter your code`}),(0,V.jsxs)(`p`,{className:`gate-subtitle`,children:[`Enter the 6-digit code sent to `,B(v,`phone`)]}),(0,V.jsx)(H,{value:h,onChange:_,onComplete:A,disabled:E}),S&&(0,V.jsx)(`div`,{className:`gate-error`,children:S}),E&&(0,V.jsxs)(`div`,{className:`gate-loading`,children:[(0,V.jsx)(`span`,{className:`spinner`}),`Verifying...`]}),(0,V.jsx)(`div`,{className:`gate-resend`,children:(0,V.jsx)(`button`,{type:`button`,className:`gate-link`,onClick:()=>{t(`sign-in`),_(``),C(null)},children:`Use a different number`})})]})});case`sign-in`:case`private-agent`:return(0,V.jsx)(`div`,{className:`gate-wrap`,children:(0,V.jsxs)(`div`,{className:`gate-card`,children:[(0,V.jsx)(`h2`,{className:`gate-title`,children:e===`private-agent`?`Private Agent`:`Welcome back`}),(0,V.jsx)(`p`,{className:`gate-subtitle`,children:e===`private-agent`?`This agent is invitation-only. If you have an account, sign in below.`:`Sign in to continue your conversation.`}),b?(0,V.jsxs)(`form`,{className:`gate-form`,onSubmit:N,children:[(0,V.jsxs)(`div`,{className:`gate-field`,children:[(0,V.jsx)(`label`,{htmlFor:`gate-forgot-contact`,children:`Email or phone`}),(0,V.jsx)(`input`,{id:`gate-forgot-contact`,type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:`you@example.com`,autoFocus:!0,autoComplete:`email`})]}),S&&(0,V.jsx)(`div`,{className:`gate-error`,children:S}),w&&(0,V.jsx)(`div`,{className:`gate-success`,children:w}),(0,V.jsx)(`div`,{className:`gate-submit`,children:(0,V.jsx)(g,{variant:`primary`,type:`submit`,fullWidth:!0,disabled:!s.trim()||E,loading:E,children:`Send reset link`})}),(0,V.jsx)(`div`,{className:`gate-actions`,children:(0,V.jsx)(`button`,{type:`button`,className:`gate-link`,onClick:()=>{x(!1),C(null),T(null)},children:`Back to sign in`})})]}):(0,V.jsxs)(`form`,{className:`gate-form`,onSubmit:k,children:[(0,V.jsxs)(`div`,{className:`gate-field`,children:[(0,V.jsx)(`label`,{htmlFor:`gate-contact`,children:`Email or phone`}),(0,V.jsx)(`input`,{id:`gate-contact`,type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:`you@example.com`,autoFocus:!0,autoComplete:`email`})]}),(0,V.jsxs)(`div`,{className:`gate-field gate-pw-row`,children:[(0,V.jsx)(`label`,{htmlFor:`gate-login-pw`,children:`Password`}),(0,V.jsx)(`div`,{className:`gate-pw-toggle`,children:(0,V.jsx)(O,{checked:p,onChange:m,label:`Show`})}),(0,V.jsx)(`input`,{id:`gate-login-pw`,type:p?`text`:`password`,value:l,onChange:e=>u(e.target.value),placeholder:`Your password`,autoComplete:`current-password`})]}),S&&(0,V.jsx)(`div`,{className:`gate-error`,children:S}),(0,V.jsx)(`div`,{className:`gate-submit`,children:(0,V.jsx)(g,{variant:`primary`,type:`submit`,fullWidth:!0,disabled:!s.trim()||!l||E,loading:E,children:`Sign in`})}),(0,V.jsx)(`div`,{className:`gate-actions`,children:(0,V.jsx)(`button`,{type:`button`,className:`gate-link`,onClick:()=>{x(!0),C(null)},children:`Forgot password?`})})]}),e===`private-agent`&&(0,V.jsx)(`p`,{className:`gate-hint`,children:`No account? You need an invitation from the agent owner.`})]})});case`access-expired`:return(0,V.jsx)(`div`,{className:`gate-wrap`,children:(0,V.jsxs)(`div`,{className:`gate-card`,children:[(0,V.jsx)(`div`,{className:`gate-icon`,children:`⏰`}),(0,V.jsx)(`h2`,{className:`gate-title`,children:`Access expired`}),(0,V.jsxs)(`p`,{className:`gate-subtitle`,children:[n?.expiresAt?`Your access expired on ${new Date(n.expiresAt).toLocaleDateString(`en-GB`,{day:`numeric`,month:`long`,year:`numeric`})}.`:`Your access to this agent has expired.`,` `,`Contact the agent owner to renew.`]}),(0,V.jsx)(`div`,{className:`gate-actions`,children:(0,V.jsx)(g,{variant:`secondary`,onClick:()=>{t(`sign-in`),C(null),u(``)},children:`Sign in with a different account`})})]})});case`link-expired`:return(0,V.jsx)(`div`,{className:`gate-wrap`,children:(0,V.jsxs)(`div`,{className:`gate-card`,children:[(0,V.jsx)(`div`,{className:`gate-icon`,children:`⚠️`}),(0,V.jsx)(`h2`,{className:`gate-title`,children:`Link expired`}),(0,V.jsx)(`p`,{className:`gate-subtitle`,children:`This invitation link has expired or has already been used. If you already set your password, sign in below. Otherwise, ask the agent owner to send a new invitation.`}),(0,V.jsx)(`div`,{className:`gate-actions`,children:(0,V.jsx)(g,{variant:`primary`,onClick:()=>{t(`sign-in`),C(null)},children:`Go to sign in`})})]})});case`otp-failed`:return(0,V.jsx)(`div`,{className:`gate-wrap`,children:(0,V.jsxs)(`div`,{className:`gate-card`,children:[(0,V.jsx)(`div`,{className:`gate-icon`,children:`⛔`}),(0,V.jsx)(`h2`,{className:`gate-title`,children:`Too many attempts`}),(0,V.jsx)(`p`,{className:`gate-subtitle`,children:`You've entered the wrong code too many times. Ask the agent owner to send a new code.`}),(0,V.jsx)(`div`,{className:`gate-actions`,children:(0,V.jsx)(g,{variant:`secondary`,onClick:()=>{t(`sign-in`),C(null),_(``)},children:`Back to sign in`})})]})})}}var W={"single-select":m,"multi-select":S,"action-buttons":b};function G({name:e,data:t,onSubmit:n,submitted:r}){let i=W[e];return i?(0,V.jsx)(i,{data:t,onSubmit:n,submitted:r}):(console.warn(`[PublicComponentRenderer] Unknown component: "${e}". Registered: ${Object.keys(W).join(`, `)}`),(0,V.jsx)(`div`,{className:`component-card component-card--error`,children:(0,V.jsxs)(`p`,{style:{fontFamily:`var(--font-body)`,fontSize:12,color:`var(--text-secondary)`},children:[`Component “`,e,`” is not available. This may require a platform update.`]})}))}function re({messages:e,isStreaming:t,sessionError:n,selectionMode:r,selectedItems:i,toggleSelectItem:o,onComponentSubmit:s,remainingSuggestions:l,onSuggestionClick:u,isAtBottom:d,setIsAtBottom:p,isGroup:m,sessionId:h}){let[_,y]=(0,j.useState)(new Set),[b,x]=(0,j.useState)(new Set),S=(0,j.useRef)(null),C=(0,j.useRef)(null),T=(0,j.useRef)(null),E=(0,j.useRef)(!1),D=(0,j.useRef)(!1),k=(0,j.useRef)(!1),A=(0,j.useRef)(0),M=(0,j.useRef)(!1),N=(0,j.useRef)(new Map);M.current=t,(0,j.useEffect)(()=>{t&&!E.current&&d&&(D.current=!0)},[t,d]),(0,j.useEffect)(()=>{if(!D.current&&!d){E.current=t,k.current=!1;return}if(E.current&&!t&&T.current&&C.current){let e=T.current;if(e.offsetHeight>C.current.clientHeight){D.current=!1,k.current=!0,e.scrollIntoView({behavior:`smooth`,block:`start`}),E.current=t;return}}(d||D.current)&&!k.current&&S.current?.scrollIntoView({behavior:`smooth`}),E.current&&!t&&(D.current=!1),E.current=t},[e,d,t]),(0,j.useEffect)(()=>{let e=C.current;if(!e)return;let t=()=>{let t=e.scrollTop;M.current&&t<A.current&&(D.current=!1),A.current=t,p(e.scrollHeight-e.scrollTop-e.clientHeight<80)};return e.addEventListener(`scroll`,t,{passive:!0}),t(),()=>e.removeEventListener(`scroll`,t)},[p]),(0,j.useEffect)(()=>{function e(){x(e=>{let t=new Set;return N.current.forEach((n,r)=>{n.isConnected&&(_.has(r)?e.has(r)&&t.add(r):n.scrollHeight>n.clientHeight+2&&t.add(r))}),e.size===t.size&&[...e].every(e=>t.has(e))?e:t})}e();let t=new ResizeObserver(e);return N.current.forEach(e=>t.observe(e)),()=>t.disconnect()},[e.length,_]);let P=[...e].sort((e,t)=>e.timestamp-t.timestamp);(0,j.useEffect)(()=>{r&&console.log(`[selection] entered`,{conversationId:h??`unknown`,order:P.map(e=>({ts:e.timestamp,role:e.role,id:e.messageId}))})},[r]);let F=P.reduce((e,t,n)=>t.role===`maxy`&&!t.hidden?n:e,-1);return(0,V.jsxs)(`div`,{className:`chat-messages-wrap`,children:[r&&(0,V.jsx)(`div`,{className:`selection-overlay-band`}),(0,V.jsxs)(`div`,{className:`chat-messages`,ref:C,children:[n&&e.length===0&&(0,V.jsx)(`div`,{className:`session-error`,children:(0,V.jsx)(`p`,{children:n})}),P.map((e,n)=>{if(e.hidden)return null;let l=t&&n===P.length-1,u=`${e.timestamp}_${e.role}`,d=i.has(u);return(0,V.jsxs)(`div`,{ref:n===F?T:void 0,className:`message ${e.role}${d?` selected`:``}`,children:[r&&!l&&(0,V.jsx)(`div`,{className:`message-select-check`,children:(0,V.jsx)(O,{checked:d,onChange:()=>o(u)})}),(0,V.jsxs)(`div`,{className:`bubble`,children:[m&&e.role===`visitor`&&e.senderName&&(0,V.jsx)(`span`,{className:`bubble-sender`,children:e.senderName}),e.role===`visitor`&&e.content?(()=>{let t=_.has(n),r=b.has(n);return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`div`,{ref:e=>{e?N.current.set(n,e):N.current.delete(n)},className:t?`bubble-content`:`bubble-content clamped${r?` overflowing`:``}`,children:e.content}),r&&(0,V.jsx)(`div`,{className:`bubble-expand`,children:(0,V.jsx)(g,{variant:`icon`,className:t?`expanded`:``,onClick:()=>y(e=>{let t=new Set(e);return t.has(n)?t.delete(n):t.add(n),t}),"aria-label":t?`Collapse message`:`Expand message`,children:(0,V.jsx)(c,{size:14})})})]})})():e.content?(0,V.jsx)(w,{content:e.content,timestamp:f(e.timestamp)}):(0,V.jsxs)(`span`,{className:`typing-indicator`,children:[(0,V.jsx)(`span`,{className:`typing-dot`}),(0,V.jsx)(`span`,{className:`typing-dot`}),(0,V.jsx)(`span`,{className:`typing-dot`})]}),e.attachments&&e.attachments.length>0&&(0,V.jsx)(`div`,{className:`message-attachments`,children:e.attachments.map((e,t)=>(0,V.jsxs)(`span`,{className:`message-attachment-chip no-action`,children:[e.mimeType===`application/pdf`?(0,V.jsx)(a,{size:12}):e.mimeType.startsWith(`text/`)?(0,V.jsx)(v,{size:12}):null,(0,V.jsx)(`span`,{children:e.filename})]},t))}),e.role===`visitor`&&(0,V.jsx)(`span`,{className:`message-timestamp`,children:f(e.timestamp)})]}),e.role===`maxy`&&e.components&&e.components.length>0&&(0,V.jsx)(`div`,{className:`public-components`,children:e.components.map((e,t)=>(0,V.jsx)(`div`,{className:`public-component-enter`,children:(0,V.jsx)(G,{name:e.name,data:e.data,onSubmit:e=>s(n,t,e),submitted:e.submitted})},t))})]},n)}),!t&&l.length>0&&(0,V.jsx)(`div`,{className:`chat-suggestions`,children:l.map(e=>(0,V.jsx)(g,{variant:`suggestion`,onClick:()=>u(e),children:e},e))}),(0,V.jsx)(`div`,{ref:S})]}),!d&&(0,V.jsx)(`button`,{className:`scroll-to-bottom`,onClick:()=>S.current?.scrollIntoView({behavior:`smooth`}),"aria-label":`Scroll to bottom`,children:(0,V.jsx)(c,{size:18})})]})}function ie({selectedItems:e,messages:t,isStreaming:n,copySelected:r,selectAll:i,exitSelection:a,showCopyToast:o}){let[c,l]=(0,j.useState)(!1),u=(0,j.useRef)(null),d=(0,j.useRef)(!1);function f(e){let n=e.lastIndexOf(`_`),r=e.slice(0,n),i=e.slice(n+1),a=parseInt(r,10);return t.find(e=>e.timestamp===a&&e.role===i)?.content??``}function p(e,t){return parseInt(e.slice(0,e.lastIndexOf(`_`)),10)-parseInt(t.slice(0,t.lastIndexOf(`_`)),10)}function m(){let e=[...t].sort((e,t)=>e.timestamp-t.timestamp),n=[];for(let t of e){if(t.hidden||!t.content)continue;let e=t.role===`visitor`?`Visitor`:`Maxy`;n.push(`${e}:\n${t.content}`)}return n.join(`
|
|
2
2
|
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
`)}j.useEffect(()=>{if(!c)return;let e=e=>{e.target.closest(`.selection-copy-wrap`)||l(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[c]);function h(){u.current!==null&&(clearTimeout(u.current),u.current=null)}let g=[...t].sort((e,t)=>e.timestamp-t.timestamp),_=g.reduce((e,t,r)=>(t.hidden||n&&r===g.length-1||e.push(`${t.timestamp}_${t.role}`),e),[]),v=_.length>0&&_.every(t=>e.has(t));return(0,V.jsx)(`div`,{className:`chat-input-area`,children:(0,V.jsxs)(`div`,{className:`selection-bar`,children:[(0,V.jsxs)(`div`,{className:`selection-bar-left`,children:[(0,V.jsxs)(`button`,{type:`button`,className:`selection-select-all`,onClick:()=>i(_),disabled:_.length===0,"aria-label":v?`Deselect all`:`Select all`,title:v?`Deselect all`:`Select all`,children:[(0,V.jsx)(E,{size:16}),(0,V.jsx)(`span`,{children:v?`Deselect all`:`Select all`})]}),(0,V.jsxs)(`span`,{className:`selection-count`,children:[e.size,` Selected`]})]}),(0,V.jsxs)(`div`,{className:`selection-copy-wrap`,children:[(0,V.jsxs)(`button`,{type:`button`,className:`selection-copy`,onPointerDown:()=>{if(c){l(!1);return}d.current=!1,u.current=setTimeout(()=>{d.current=!0,l(!0),u.current=null},500)},onPointerUp:h,onPointerLeave:h,onPointerCancel:h,onClick:async()=>{d.current||await r(f,p)},children:[(0,V.jsx)(s,{size:18}),(0,V.jsx)(`span`,{children:`Copy`})]}),c&&(0,V.jsx)(`div`,{className:`copy-menu`,children:(0,V.jsx)(`button`,{type:`button`,className:`copy-menu-item`,onClick:async()=>{let e=m();e&&o(await D(e)),a()},children:`Copy all`})})]}),(0,V.jsx)(`button`,{type:`button`,className:`selection-cancel`,onClick:a,children:`Cancel`})]})})}function ae({input:e,setInput:t,isStreaming:n,pendingFiles:r,setPendingFiles:i,attachError:s,setAttachError:c,isDragOver:u,setIsDragOver:d,inputRef:f,onSubmit:p,onSendVoiceNote:m}){let h=(0,j.useRef)(null),b=C(),S=b.state===`recording`||b.state===`paused`||b.state===`sending`,w=!S&&!n&&!e.trim()&&r.length===0;async function T(){let e=await b.send();if(!e)return;let t=e.type===`audio/ogg`?`.ogg`:e.type===`audio/mp4`?`.m4a`:`.webm`;m(new File([e],`voice-note${t}`,{type:e.type}))}function E(e){c(null);let t=e.find(e=>!N.has(e.type));if(t){c(`Unsupported file type: "${t.type}". Supported: images, PDF, plain text, markdown, CSV, calendar.`);return}let n=e.find(e=>e.size>P);if(n){c(`"${n.name}" exceeds the 20 MB limit.`);return}i(t=>[...t,...e].slice(0,5))}function D(e){e.preventDefault(),d(!0)}function O(){d(!1)}function k(e){e.preventDefault(),d(!1),E([...e.dataTransfer.files])}return(0,V.jsxs)(`div`,{className:`chat-input-area`,children:[(0,V.jsx)(`input`,{ref:h,type:`file`,multiple:!0,accept:M,style:{display:`none`},onChange:e=>{e.target.files&&E([...e.target.files]),e.target.value=``}}),r.length>0&&(0,V.jsx)(`div`,{className:`attachment-strip`,children:r.map((e,t)=>(0,V.jsxs)(`div`,{className:`attachment-chip`,children:[e.type.startsWith(`image/`)?(0,V.jsx)(`img`,{src:URL.createObjectURL(e),alt:e.name,className:`attachment-chip-thumb`}):e.type===`application/pdf`?(0,V.jsx)(a,{size:14}):(0,V.jsx)(v,{size:14}),(0,V.jsx)(`span`,{className:`attachment-chip-name`,children:e.name}),(0,V.jsx)(`button`,{type:`button`,className:`attachment-chip-remove`,onClick:()=>i(e=>e.filter((e,n)=>n!==t)),"aria-label":`Remove ${e.name}`,children:`×`})]},t))}),s&&(0,V.jsx)(`p`,{className:`attach-error`,children:s}),b.state===`error`&&b.errorMessage&&(0,V.jsxs)(`p`,{className:`voice-error`,role:`alert`,children:[(0,V.jsx)(l,{size:14}),b.errorMessage]}),(0,V.jsx)(_,{inputRef:f}),S?(0,V.jsx)(`div`,{className:`chat-form voice-active`,children:(0,V.jsx)(y,{state:b.state,elapsedSeconds:b.elapsedSeconds,waveform:b.waveform,onTogglePause:b.togglePause,onDiscard:b.discard,onSend:T})}):(0,V.jsxs)(`form`,{className:`chat-form${u?` drag-over`:``}`,onSubmit:p,onDragOver:D,onDragLeave:O,onDrop:k,onPaste:e=>{let t=e.clipboardData?.items;if(!t)return;let n=[];for(let e of t){if(e.kind!==`file`)continue;let t=e.getAsFile();if(!t)continue;let r=t.type.split(`/`)[1]?.replace(`jpeg`,`jpg`)||`png`;n.push(new File([t],`pasted-image-${Date.now()}.${r}`,{type:t.type}))}n.length>0&&E(n)},children:[(0,V.jsx)(g,{variant:`icon`,type:`button`,onClick:()=>h.current?.click(),disabled:n,"aria-label":`Attach file`,children:(0,V.jsx)(o,{size:14})}),(0,V.jsx)(x,{ref:f,value:e,onChange:t}),w?(0,V.jsx)(g,{variant:`send`,type:`button`,onClick:b.start,disabled:n,"aria-label":`Record voice note`,children:(0,V.jsx)(l,{size:14})}):(0,V.jsx)(g,{variant:`send`,type:`submit`,disabled:n||!e.trim()&&r.length===0,"aria-label":`Send message`,children:(0,V.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,V.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,V.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]})]})}var K=[];function q(){let[e,t]=(0,j.useState)(``),[n,r]=(0,j.useState)([]),[i,a]=(0,j.useState)(!1),[o,s]=(0,j.useState)(null),[c,l]=(0,j.useState)(K),[f,p]=(0,j.useState)(!0),m=(0,j.useRef)(null),{selectionMode:g,selectedItems:_,copyToast:v,exitSelection:y,enterSelection:b,toggleSelectItem:x,selectAll:S,copySelected:C,showCopyToast:w}=u(),D=(0,j.useRef)(()=>{}),O=ee((0,j.useCallback)(e=>{D.current(e)},[])),{sessionId:A,sessionKeyRef:M,sessionError:N,pageState:P,agentDisplayName:F,agentImage:I,agentImageShape:L,showAgentName:R,branding:z,ensureSession:B,startNewSession:H,resumedRef:W,resumeMessagesRef:G,groupContext:q,groupSlug:oe}=O,{messages:J,setMessages:Y,isStreaming:X,sendMessage:Z,sendGreeting:Q,handleComponentSubmit:se}=te({sessionKeyRef:M,ensureSession:B,sessionError:N,pageState:P,inputRef:m});(0,j.useEffect)(()=>{D.current=Q},[Q]),ne({sessionKeyRef:M,groupSlug:oe,isStreaming:X,setMessages:Y}),(0,j.useEffect)(()=>{let e=!1;return(async()=>{let t=await B();if(!e&&t){if(W.current&&G.current&&G.current.length>0){let e=G.current.map(e=>({role:e.role,content:e.content,timestamp:e.timestamp}));e.sort((e,t)=>e.timestamp-t.timestamp),Y(e),G.current=null;return}Q(t)}})(),()=>{e=!0}},[]),(0,j.useEffect)(()=>{P===`chat`&&m.current?.focus()},[P]),(0,j.useEffect)(()=>{if(P!==`chat`)return;history.pushState({maxyChat:!0},``);function e(){history.pushState({maxyChat:!0},``)}return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[P]),(0,j.useEffect)(()=>{if(!z)return;let e=document.documentElement;if(z.primaryColor&&(e.style.setProperty(`--sage`,z.primaryColor),e.style.setProperty(`--sage-hover`,z.primaryColor),e.style.setProperty(`--sage-subtle`,z.primaryColor+`14`),e.style.setProperty(`--sage-glow`,z.primaryColor+`26`)),z.accentColor&&e.style.setProperty(`--visitor-bubble`,z.accentColor),z.backgroundColor&&e.style.setProperty(`--bg`,z.backgroundColor),document.title=z.name,z.primaryColor){let e=document.querySelector(`meta[name="theme-color"]`);e||(e=document.createElement(`meta`),e.name=`theme-color`,document.head.appendChild(e)),e.content=z.primaryColor}if(z.faviconUrl){let e=document.querySelector(`link[rel="icon"]`);e||(e=document.createElement(`link`),e.rel=`icon`,document.head.appendChild(e)),e.href=z.faviconUrl}},[z]),(0,j.useEffect)(()=>{function e(e){e.key===`Escape`&&g&&y()}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[g,y]);function ce(){X||(Y([]),l(K),H())}function $(e){if(!e&&n.length===0||X)return;Y(e=>e.map(e=>e.components?.some(e=>!e.submitted)?{...e,components:e.components.map(e=>e.submitted?e:{...e,submitted:!0})}:e)),l(t=>t.filter(t=>t!==e)),p(!0);let i=[...n];t(``),r([]),s(null),Z(e,{files:i})}function le(t){t.preventDefault(),$(e.trim()),m.current?.resetHeight()}return(0,V.jsxs)(`div`,{className:`chat-page`,children:[(0,V.jsxs)(`header`,{className:`chat-header`,children:[(0,V.jsx)(`img`,{src:I||z?.logoUrl||T,alt:z?.name||h.productName,className:`chat-logo${I&&L===`circle`?` chat-logo--circle`:``}${I&&L===`rounded`?` chat-logo--rounded`:``}`,onError:e=>{e.target.src=z?.logoUrl||T}}),(0,V.jsxs)(`div`,{className:`chat-header-text`,children:[R!==`none`&&(0,V.jsx)(`h1`,{className:`chat-tagline`,children:q?.groupName||R&&F||z?.name||h.productName}),(0,V.jsx)(`p`,{className:`chat-intro`,children:q?`${q.participants.length} participants`:z?.tagline||``}),(0,V.jsx)(`p`,{className:`chat-ai-indicator`,children:`AI assistant`})]}),P===`chat`&&!g&&(0,V.jsxs)(`div`,{className:`chat-header-actions`,children:[(0,V.jsx)(`button`,{className:`chat-header-action`,onClick:ce,disabled:X,title:`New conversation`,"aria-label":`New conversation`,children:(0,V.jsx)(k,{size:16})}),(0,V.jsx)(`button`,{className:`chat-header-action`,onClick:b,title:`Select messages`,"aria-label":`Select messages`,children:(0,V.jsx)(E,{size:16})})]})]}),P===`loading`&&(0,V.jsx)(`div`,{className:`gate-wrap`,children:(0,V.jsx)(`div`,{className:`gate-loading`,children:(0,V.jsx)(`span`,{className:`spinner`})})}),P===`auth-required`&&(0,V.jsx)(U,{gateState:O.gateState,setGateState:O.setGateState,grantInfo:O.grantInfo,setGrantInfo:O.setGrantInfo,gateSessionKeyRef:O.gateSessionKeyRef,resolvedSlugRef:O.resolvedSlugRef,onAuthenticated:O.enterChat}),P===`chat`&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(re,{messages:J,isStreaming:X,sessionError:N,selectionMode:g,selectedItems:_,toggleSelectItem:x,onComponentSubmit:se,remainingSuggestions:c,onSuggestionClick:$,isAtBottom:f,setIsAtBottom:p,isGroup:!!q,sessionId:A}),g?(0,V.jsx)(ie,{selectedItems:_,messages:J,isStreaming:X,copySelected:C,selectAll:S,exitSelection:y,showCopyToast:w}):(0,V.jsx)(ae,{input:e,setInput:t,isStreaming:X,pendingFiles:n,setPendingFiles:r,attachError:o,setAttachError:s,isDragOver:i,setIsDragOver:a,inputRef:m,onSubmit:le,onSendVoiceNote:e=>{t(``),r([]),s(null),Z(`[Voice note]`,{files:[e]})}})]}),v&&(0,V.jsx)(`span`,{className:`copy-toast${v===`failed`?` copy-toast-failed`:``}`,children:v===`copied`?`Copied`:`Copy failed`}),(0,V.jsxs)(`footer`,{className:`chat-footer`,children:[(0,V.jsxs)(`a`,{href:d,children:[h.domain,` `,`↗`]}),A&&(0,V.jsxs)(`span`,{style:{opacity:.35,fontSize:`10px`,fontFamily:`monospace`,marginLeft:`1rem`},children:[`Conversation · `,A.slice(0,8)]})]})]})}(0,A.createRoot)(document.getElementById(`root`)).render((0,V.jsx)(q,{}));
|
|
5
|
+
`)}j.useEffect(()=>{if(!c)return;let e=e=>{e.target.closest(`.selection-copy-wrap`)||l(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[c]);function h(){u.current!==null&&(clearTimeout(u.current),u.current=null)}let g=[...t].sort((e,t)=>e.timestamp-t.timestamp),_=g.reduce((e,t,r)=>(t.hidden||n&&r===g.length-1||e.push(`${t.timestamp}_${t.role}`),e),[]),v=_.length>0&&_.every(t=>e.has(t));return(0,V.jsx)(`div`,{className:`chat-input-area`,children:(0,V.jsxs)(`div`,{className:`selection-bar`,children:[(0,V.jsxs)(`div`,{className:`selection-bar-left`,children:[(0,V.jsxs)(`button`,{type:`button`,className:`selection-select-all`,onClick:()=>i(_),disabled:_.length===0,"aria-label":v?`Deselect all`:`Select all`,title:v?`Deselect all`:`Select all`,children:[(0,V.jsx)(E,{size:16}),(0,V.jsx)(`span`,{children:v?`Deselect all`:`Select all`})]}),(0,V.jsxs)(`span`,{className:`selection-count`,children:[e.size,` Selected`]})]}),(0,V.jsxs)(`div`,{className:`selection-copy-wrap`,children:[(0,V.jsxs)(`button`,{type:`button`,className:`selection-copy`,onPointerDown:()=>{if(c){l(!1);return}d.current=!1,u.current=setTimeout(()=>{d.current=!0,l(!0),u.current=null},500)},onPointerUp:h,onPointerLeave:h,onPointerCancel:h,onClick:async()=>{d.current||await r(f,p)},children:[(0,V.jsx)(s,{size:18}),(0,V.jsx)(`span`,{children:`Copy`})]}),c&&(0,V.jsx)(`div`,{className:`copy-menu`,children:(0,V.jsx)(`button`,{type:`button`,className:`copy-menu-item`,onClick:async()=>{let e=m();e&&o(await D(e)),a()},children:`Copy all`})})]}),(0,V.jsx)(`button`,{type:`button`,className:`selection-cancel`,onClick:a,children:`Cancel`})]})})}function ae({input:e,setInput:t,isStreaming:n,pendingFiles:r,setPendingFiles:i,attachError:s,setAttachError:c,isDragOver:u,setIsDragOver:d,inputRef:f,onSubmit:p,onSendVoiceNote:m}){let h=(0,j.useRef)(null),b=C(),S=b.state===`recording`||b.state===`paused`||b.state===`sending`,w=!S&&!n&&!e.trim()&&r.length===0;async function T(){let e=await b.send();if(!e)return;let t=e.type===`audio/ogg`?`.ogg`:e.type===`audio/mp4`?`.m4a`:`.webm`;m(new File([e],`voice-note${t}`,{type:e.type}))}function E(e){c(null);let t=e.find(e=>!N.has(e.type));if(t){c(`Unsupported file type: "${t.type}". Supported: images, PDF, plain text, markdown, CSV, calendar.`);return}let n=e.find(e=>e.size>P);if(n){c(`"${n.name}" exceeds the 50 MB limit.`);return}i(t=>[...t,...e].slice(0,5))}function D(e){e.preventDefault(),d(!0)}function O(){d(!1)}function k(e){e.preventDefault(),d(!1),E([...e.dataTransfer.files])}return(0,V.jsxs)(`div`,{className:`chat-input-area`,children:[(0,V.jsx)(`input`,{ref:h,type:`file`,multiple:!0,accept:M,style:{display:`none`},onChange:e=>{e.target.files&&E([...e.target.files]),e.target.value=``}}),r.length>0&&(0,V.jsx)(`div`,{className:`attachment-strip`,children:r.map((e,t)=>(0,V.jsxs)(`div`,{className:`attachment-chip`,children:[e.type.startsWith(`image/`)?(0,V.jsx)(`img`,{src:URL.createObjectURL(e),alt:e.name,className:`attachment-chip-thumb`}):e.type===`application/pdf`?(0,V.jsx)(a,{size:14}):(0,V.jsx)(v,{size:14}),(0,V.jsx)(`span`,{className:`attachment-chip-name`,children:e.name}),(0,V.jsx)(`button`,{type:`button`,className:`attachment-chip-remove`,onClick:()=>i(e=>e.filter((e,n)=>n!==t)),"aria-label":`Remove ${e.name}`,children:`×`})]},t))}),s&&(0,V.jsx)(`p`,{className:`attach-error`,children:s}),b.state===`error`&&b.errorMessage&&(0,V.jsxs)(`p`,{className:`voice-error`,role:`alert`,children:[(0,V.jsx)(l,{size:14}),b.errorMessage]}),(0,V.jsx)(_,{inputRef:f}),S?(0,V.jsx)(`div`,{className:`chat-form voice-active`,children:(0,V.jsx)(y,{state:b.state,elapsedSeconds:b.elapsedSeconds,waveform:b.waveform,onTogglePause:b.togglePause,onDiscard:b.discard,onSend:T})}):(0,V.jsxs)(`form`,{className:`chat-form${u?` drag-over`:``}`,onSubmit:p,onDragOver:D,onDragLeave:O,onDrop:k,onPaste:e=>{let t=e.clipboardData?.items;if(!t)return;let n=[];for(let e of t){if(e.kind!==`file`)continue;let t=e.getAsFile();if(!t)continue;let r=t.type.split(`/`)[1]?.replace(`jpeg`,`jpg`)||`png`;n.push(new File([t],`pasted-image-${Date.now()}.${r}`,{type:t.type}))}n.length>0&&E(n)},children:[(0,V.jsx)(g,{variant:`icon`,type:`button`,onClick:()=>h.current?.click(),disabled:n,"aria-label":`Attach file`,children:(0,V.jsx)(o,{size:14})}),(0,V.jsx)(x,{ref:f,value:e,onChange:t}),w?(0,V.jsx)(g,{variant:`send`,type:`button`,onClick:b.start,disabled:n,"aria-label":`Record voice note`,children:(0,V.jsx)(l,{size:14})}):(0,V.jsx)(g,{variant:`send`,type:`submit`,disabled:n||!e.trim()&&r.length===0,"aria-label":`Send message`,children:(0,V.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,V.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,V.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]})]})}var K=[];function q(){let[e,t]=(0,j.useState)(``),[n,r]=(0,j.useState)([]),[i,a]=(0,j.useState)(!1),[o,s]=(0,j.useState)(null),[c,l]=(0,j.useState)(K),[f,p]=(0,j.useState)(!0),m=(0,j.useRef)(null),{selectionMode:g,selectedItems:_,copyToast:v,exitSelection:y,enterSelection:b,toggleSelectItem:x,selectAll:S,copySelected:C,showCopyToast:w}=u(),D=(0,j.useRef)(()=>{}),O=ee((0,j.useCallback)(e=>{D.current(e)},[])),{sessionId:A,sessionKeyRef:M,sessionError:N,pageState:P,agentDisplayName:F,agentImage:I,agentImageShape:L,showAgentName:R,branding:z,ensureSession:B,startNewSession:H,resumedRef:W,resumeMessagesRef:G,groupContext:q,groupSlug:oe}=O,{messages:J,setMessages:Y,isStreaming:X,sendMessage:Z,sendGreeting:Q,handleComponentSubmit:se}=te({sessionKeyRef:M,ensureSession:B,sessionError:N,pageState:P,inputRef:m});(0,j.useEffect)(()=>{D.current=Q},[Q]),ne({sessionKeyRef:M,groupSlug:oe,isStreaming:X,setMessages:Y}),(0,j.useEffect)(()=>{let e=!1;return(async()=>{let t=await B();if(!e&&t){if(W.current&&G.current&&G.current.length>0){let e=G.current.map(e=>({role:e.role,content:e.content,timestamp:e.timestamp}));e.sort((e,t)=>e.timestamp-t.timestamp),Y(e),G.current=null;return}Q(t)}})(),()=>{e=!0}},[]),(0,j.useEffect)(()=>{P===`chat`&&m.current?.focus()},[P]),(0,j.useEffect)(()=>{if(P!==`chat`)return;history.pushState({maxyChat:!0},``);function e(){history.pushState({maxyChat:!0},``)}return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[P]),(0,j.useEffect)(()=>{if(!z)return;let e=document.documentElement;if(z.primaryColor&&(e.style.setProperty(`--sage`,z.primaryColor),e.style.setProperty(`--sage-hover`,z.primaryColor),e.style.setProperty(`--sage-subtle`,z.primaryColor+`14`),e.style.setProperty(`--sage-glow`,z.primaryColor+`26`)),z.accentColor&&e.style.setProperty(`--visitor-bubble`,z.accentColor),z.backgroundColor&&e.style.setProperty(`--bg`,z.backgroundColor),document.title=z.name,z.primaryColor){let e=document.querySelector(`meta[name="theme-color"]`);e||(e=document.createElement(`meta`),e.name=`theme-color`,document.head.appendChild(e)),e.content=z.primaryColor}if(z.faviconUrl){let e=document.querySelector(`link[rel="icon"]`);e||(e=document.createElement(`link`),e.rel=`icon`,document.head.appendChild(e)),e.href=z.faviconUrl}},[z]),(0,j.useEffect)(()=>{function e(e){e.key===`Escape`&&g&&y()}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[g,y]);function ce(){X||(Y([]),l(K),H())}function $(e){if(!e&&n.length===0||X)return;Y(e=>e.map(e=>e.components?.some(e=>!e.submitted)?{...e,components:e.components.map(e=>e.submitted?e:{...e,submitted:!0})}:e)),l(t=>t.filter(t=>t!==e)),p(!0);let i=[...n];t(``),r([]),s(null),Z(e,{files:i})}function le(t){t.preventDefault(),$(e.trim()),m.current?.resetHeight()}return(0,V.jsxs)(`div`,{className:`chat-page`,children:[(0,V.jsxs)(`header`,{className:`chat-header`,children:[(0,V.jsx)(`img`,{src:I||z?.logoUrl||T,alt:z?.name||h.productName,className:`chat-logo${I&&L===`circle`?` chat-logo--circle`:``}${I&&L===`rounded`?` chat-logo--rounded`:``}`,onError:e=>{e.target.src=z?.logoUrl||T}}),(0,V.jsxs)(`div`,{className:`chat-header-text`,children:[R!==`none`&&(0,V.jsx)(`h1`,{className:`chat-tagline`,children:q?.groupName||R&&F||z?.name||h.productName}),(0,V.jsx)(`p`,{className:`chat-intro`,children:q?`${q.participants.length} participants`:z?.tagline||``}),(0,V.jsx)(`p`,{className:`chat-ai-indicator`,children:`AI assistant`})]}),P===`chat`&&!g&&(0,V.jsxs)(`div`,{className:`chat-header-actions`,children:[(0,V.jsx)(`button`,{className:`chat-header-action`,onClick:ce,disabled:X,title:`New conversation`,"aria-label":`New conversation`,children:(0,V.jsx)(k,{size:16})}),(0,V.jsx)(`button`,{className:`chat-header-action`,onClick:b,title:`Select messages`,"aria-label":`Select messages`,children:(0,V.jsx)(E,{size:16})})]})]}),P===`loading`&&(0,V.jsx)(`div`,{className:`gate-wrap`,children:(0,V.jsx)(`div`,{className:`gate-loading`,children:(0,V.jsx)(`span`,{className:`spinner`})})}),P===`auth-required`&&(0,V.jsx)(U,{gateState:O.gateState,setGateState:O.setGateState,grantInfo:O.grantInfo,setGrantInfo:O.setGrantInfo,gateSessionKeyRef:O.gateSessionKeyRef,resolvedSlugRef:O.resolvedSlugRef,onAuthenticated:O.enterChat}),P===`chat`&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(re,{messages:J,isStreaming:X,sessionError:N,selectionMode:g,selectedItems:_,toggleSelectItem:x,onComponentSubmit:se,remainingSuggestions:c,onSuggestionClick:$,isAtBottom:f,setIsAtBottom:p,isGroup:!!q,sessionId:A}),g?(0,V.jsx)(ie,{selectedItems:_,messages:J,isStreaming:X,copySelected:C,selectAll:S,exitSelection:y,showCopyToast:w}):(0,V.jsx)(ae,{input:e,setInput:t,isStreaming:X,pendingFiles:n,setPendingFiles:r,attachError:o,setAttachError:s,isDragOver:i,setIsDragOver:a,inputRef:m,onSubmit:le,onSendVoiceNote:e=>{t(``),r([]),s(null),Z(`[Voice note]`,{files:[e]})}})]}),v&&(0,V.jsx)(`span`,{className:`copy-toast${v===`failed`?` copy-toast-failed`:``}`,children:v===`copied`?`Copied`:`Copy failed`}),(0,V.jsxs)(`footer`,{className:`chat-footer`,children:[(0,V.jsxs)(`a`,{href:d,children:[h.domain,` `,`↗`]}),A&&(0,V.jsxs)(`span`,{style:{opacity:.35,fontSize:`10px`,fontFamily:`monospace`,marginLeft:`1rem`},children:[`Conversation · `,A.slice(0,8)]})]})]})}(0,A.createRoot)(document.getElementById(`root`)).render((0,V.jsx)(q,{}));
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>Real Agent</title>
|
|
7
7
|
<link rel="icon" href="/favicon.ico">
|
|
8
|
-
<script type="module" crossorigin src="/assets/admin-
|
|
8
|
+
<script type="module" crossorigin src="/assets/admin-CvwOOG4D.js"></script>
|
|
9
9
|
<link rel="modulepreload" crossorigin href="/assets/chunk-DD-I1_y5.js">
|
|
10
10
|
<link rel="modulepreload" crossorigin href="/assets/jsx-runtime-WW3O7tSz.js">
|
|
11
11
|
<link rel="modulepreload" crossorigin href="/assets/preload-helper-qlgyTAkD.js">
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>Real Agent</title>
|
|
7
7
|
<link rel="icon" href="/favicon.ico">
|
|
8
|
-
<script type="module" crossorigin src="/assets/public-
|
|
8
|
+
<script type="module" crossorigin src="/assets/public-Br9YjNs_.js"></script>
|
|
9
9
|
<link rel="modulepreload" crossorigin href="/assets/chunk-DD-I1_y5.js">
|
|
10
10
|
<link rel="modulepreload" crossorigin href="/assets/jsx-runtime-WW3O7tSz.js">
|
|
11
11
|
<link rel="modulepreload" crossorigin href="/assets/preload-helper-qlgyTAkD.js">
|
package/payload/server/server.js
CHANGED
|
@@ -45,7 +45,7 @@ import {
|
|
|
45
45
|
vncLog,
|
|
46
46
|
waitForExit,
|
|
47
47
|
writeChromiumWrapper
|
|
48
|
-
} from "./chunk-
|
|
48
|
+
} from "./chunk-S27QCBFQ.js";
|
|
49
49
|
import {
|
|
50
50
|
ACCOUNTS_DIR,
|
|
51
51
|
COMMERCIAL_MODE,
|
|
@@ -88,7 +88,7 @@ import {
|
|
|
88
88
|
unregisterSession,
|
|
89
89
|
validateAgentSlug,
|
|
90
90
|
validateSession
|
|
91
|
-
} from "./chunk-
|
|
91
|
+
} from "./chunk-2YG3AYAH.js";
|
|
92
92
|
import {
|
|
93
93
|
CLOUDFLARE_TASK_DIAGNOSTICS,
|
|
94
94
|
appendCloudflareSteps,
|
|
@@ -96,7 +96,7 @@ import {
|
|
|
96
96
|
openCloudflareTask,
|
|
97
97
|
readTunnelState,
|
|
98
98
|
resolveUnitGoneVerdict
|
|
99
|
-
} from "./chunk-
|
|
99
|
+
} from "./chunk-DTWW35TK.js";
|
|
100
100
|
import {
|
|
101
101
|
GREETING_DIRECTIVE,
|
|
102
102
|
HAIKU_MODEL,
|
|
@@ -1868,17 +1868,17 @@ var INBOUND_TTL_MS = 20 * 6e4;
|
|
|
1868
1868
|
var INBOUND_MAX = 5e3;
|
|
1869
1869
|
var agentSentCache = /* @__PURE__ */ new Map();
|
|
1870
1870
|
var inboundCache = /* @__PURE__ */ new Map();
|
|
1871
|
-
function pruneCache(
|
|
1871
|
+
function pruneCache(cache2, ttl, max) {
|
|
1872
1872
|
const now = Date.now();
|
|
1873
|
-
for (const [key, entry] of
|
|
1874
|
-
if (now - entry.ts > ttl)
|
|
1873
|
+
for (const [key, entry] of cache2) {
|
|
1874
|
+
if (now - entry.ts > ttl) cache2.delete(key);
|
|
1875
1875
|
}
|
|
1876
|
-
if (
|
|
1877
|
-
const excess =
|
|
1876
|
+
if (cache2.size > max) {
|
|
1877
|
+
const excess = cache2.size - max;
|
|
1878
1878
|
let count = 0;
|
|
1879
|
-
for (const key of
|
|
1879
|
+
for (const key of cache2.keys()) {
|
|
1880
1880
|
if (count >= excess) break;
|
|
1881
|
-
|
|
1881
|
+
cache2.delete(key);
|
|
1882
1882
|
count++;
|
|
1883
1883
|
}
|
|
1884
1884
|
}
|
|
@@ -2247,35 +2247,22 @@ async function ensureWhatsAppConversation(input) {
|
|
|
2247
2247
|
}
|
|
2248
2248
|
}
|
|
2249
2249
|
|
|
2250
|
-
//
|
|
2250
|
+
// ../lib/account-enumeration/src/index.ts
|
|
2251
2251
|
import { readdirSync, readFileSync as readFileSync2 } from "fs";
|
|
2252
2252
|
import { resolve as resolve2 } from "path";
|
|
2253
2253
|
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
2254
|
-
var
|
|
2255
|
-
var cachedAccountsDir = null;
|
|
2256
|
-
function resolvePlatformAccountId(accountsDir = ACCOUNTS_DIR) {
|
|
2257
|
-
if (cached !== null && cachedAccountsDir === accountsDir) return cached;
|
|
2258
|
-
const valid = enumerateValidAccountIds(accountsDir);
|
|
2259
|
-
if (valid.length === 0) {
|
|
2260
|
-
throw new Error(
|
|
2261
|
-
`[whatsapp-persist] resolvePlatformAccountId: no platform account found under ${accountsDir} \u2014 corrupt install? Cannot stamp n.accountId without a valid UUID.`
|
|
2262
|
-
);
|
|
2263
|
-
}
|
|
2264
|
-
if (valid.length > 1) {
|
|
2265
|
-
throw new Error(
|
|
2266
|
-
`[whatsapp-persist] resolvePlatformAccountId: multiple platform accounts found under ${accountsDir} (${valid.join(", ")}) \u2014 Phase 0 invariant requires exactly one. Loud-fail rather than picking one silently.`
|
|
2267
|
-
);
|
|
2268
|
-
}
|
|
2269
|
-
cached = valid[0];
|
|
2270
|
-
cachedAccountsDir = accountsDir;
|
|
2271
|
-
return cached;
|
|
2272
|
-
}
|
|
2254
|
+
var cache = /* @__PURE__ */ new Map();
|
|
2273
2255
|
function enumerateValidAccountIds(accountsDir) {
|
|
2256
|
+
const cached2 = cache.get(accountsDir);
|
|
2257
|
+
if (cached2 !== void 0) return cached2;
|
|
2274
2258
|
let names;
|
|
2275
2259
|
try {
|
|
2276
2260
|
names = readdirSync(accountsDir);
|
|
2277
2261
|
} catch (err) {
|
|
2278
|
-
if (err.code === "ENOENT")
|
|
2262
|
+
if (err.code === "ENOENT") {
|
|
2263
|
+
cache.set(accountsDir, []);
|
|
2264
|
+
return [];
|
|
2265
|
+
}
|
|
2279
2266
|
throw err;
|
|
2280
2267
|
}
|
|
2281
2268
|
const valid = [];
|
|
@@ -2290,8 +2277,39 @@ function enumerateValidAccountIds(accountsDir) {
|
|
|
2290
2277
|
if (code === "ENOENT") continue;
|
|
2291
2278
|
}
|
|
2292
2279
|
}
|
|
2280
|
+
cache.set(accountsDir, valid);
|
|
2293
2281
|
return valid;
|
|
2294
2282
|
}
|
|
2283
|
+
function getAccountsDirFromEnv() {
|
|
2284
|
+
const root = process.env.MAXY_PLATFORM_ROOT;
|
|
2285
|
+
if (!root) {
|
|
2286
|
+
throw new Error(
|
|
2287
|
+
"[graph-write] MAXY_PLATFORM_ROOT not set \u2014 cannot enforce accountId gate. Set MAXY_PLATFORM_ROOT in the spawning process or pass `accountsDir` explicitly."
|
|
2288
|
+
);
|
|
2289
|
+
}
|
|
2290
|
+
return resolve2(root, "..", "data/accounts");
|
|
2291
|
+
}
|
|
2292
|
+
|
|
2293
|
+
// app/lib/whatsapp/platform-account-id.ts
|
|
2294
|
+
var cached = null;
|
|
2295
|
+
var cachedAccountsDir = null;
|
|
2296
|
+
function resolvePlatformAccountId(accountsDir = ACCOUNTS_DIR) {
|
|
2297
|
+
if (cached !== null && cachedAccountsDir === accountsDir) return cached;
|
|
2298
|
+
const valid = enumerateValidAccountIds(accountsDir);
|
|
2299
|
+
if (valid.length === 0) {
|
|
2300
|
+
throw new Error(
|
|
2301
|
+
`[whatsapp-persist] resolvePlatformAccountId: no platform account found under ${accountsDir} \u2014 corrupt install? Cannot stamp n.accountId without a valid UUID.`
|
|
2302
|
+
);
|
|
2303
|
+
}
|
|
2304
|
+
if (valid.length > 1) {
|
|
2305
|
+
throw new Error(
|
|
2306
|
+
`[whatsapp-persist] resolvePlatformAccountId: multiple platform accounts found under ${accountsDir} (${valid.join(", ")}) \u2014 Phase 0 invariant requires exactly one. Loud-fail rather than picking one silently.`
|
|
2307
|
+
);
|
|
2308
|
+
}
|
|
2309
|
+
cached = valid[0];
|
|
2310
|
+
cachedAccountsDir = accountsDir;
|
|
2311
|
+
return cached;
|
|
2312
|
+
}
|
|
2295
2313
|
|
|
2296
2314
|
// app/lib/whatsapp/inbound/media.ts
|
|
2297
2315
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
@@ -3919,7 +3937,7 @@ var SUPPORTED_MIME_TYPES = /* @__PURE__ */ new Set([
|
|
|
3919
3937
|
"application/zip",
|
|
3920
3938
|
"application/x-zip-compressed"
|
|
3921
3939
|
]);
|
|
3922
|
-
var MAX_FILE_SIZE_BYTES =
|
|
3940
|
+
var MAX_FILE_SIZE_BYTES = 50 * 1024 * 1024;
|
|
3923
3941
|
var MAX_FILES_PER_MESSAGE = 5;
|
|
3924
3942
|
var MAX_ZIP_UNCOMPRESSED_BYTES = 100 * 1024 * 1024;
|
|
3925
3943
|
function assertSupportedMime(mimeType) {
|
|
@@ -3952,7 +3970,7 @@ async function storeAttachment(accountId, file) {
|
|
|
3952
3970
|
assertSupportedMime(file.type);
|
|
3953
3971
|
if (file.size > MAX_FILE_SIZE_BYTES) {
|
|
3954
3972
|
throw new Error(
|
|
3955
|
-
`File "${file.name}" exceeds the
|
|
3973
|
+
`File "${file.name}" exceeds the 50 MB limit (${(file.size / 1024 / 1024).toFixed(1)} MB).`
|
|
3956
3974
|
);
|
|
3957
3975
|
}
|
|
3958
3976
|
const buffer = Buffer.from(await file.arrayBuffer());
|
|
@@ -3962,7 +3980,7 @@ async function storePublicAttachment(sessionId, file, buffer) {
|
|
|
3962
3980
|
assertSupportedMime(file.type);
|
|
3963
3981
|
if (file.size > MAX_FILE_SIZE_BYTES) {
|
|
3964
3982
|
throw new Error(
|
|
3965
|
-
`File "${file.name}" exceeds the
|
|
3983
|
+
`File "${file.name}" exceeds the 50 MB limit (${(file.size / 1024 / 1024).toFixed(1)} MB).`
|
|
3966
3984
|
);
|
|
3967
3985
|
}
|
|
3968
3986
|
return writeAttachment(`public/${sessionId}`, file.name, file.type, file.size, buffer);
|
|
@@ -4006,7 +4024,7 @@ async function storeGeneratedFile(accountId, filePath) {
|
|
|
4006
4024
|
const fileStat = await stat2(filePath);
|
|
4007
4025
|
if (fileStat.size > MAX_FILE_SIZE_BYTES) {
|
|
4008
4026
|
throw new Error(
|
|
4009
|
-
`File exceeds the
|
|
4027
|
+
`File exceeds the 50 MB limit (${(fileStat.size / 1024 / 1024).toFixed(1)} MB).`
|
|
4010
4028
|
);
|
|
4011
4029
|
}
|
|
4012
4030
|
const filename = basename(filePath);
|
|
@@ -4383,7 +4401,7 @@ app3.post("/", async (c) => {
|
|
|
4383
4401
|
assertSupportedMime(file.type);
|
|
4384
4402
|
if (file.size > MAX_FILE_SIZE_BYTES) {
|
|
4385
4403
|
throw new Error(
|
|
4386
|
-
`File "${file.name}" exceeds the
|
|
4404
|
+
`File "${file.name}" exceeds the 50 MB limit (${(file.size / 1024 / 1024).toFixed(1)} MB).`
|
|
4387
4405
|
);
|
|
4388
4406
|
}
|
|
4389
4407
|
} catch (err) {
|
|
@@ -6189,7 +6207,7 @@ app7.post("/send-document", async (c) => {
|
|
|
6189
6207
|
}
|
|
6190
6208
|
const fileStat = await stat3(resolvedPath);
|
|
6191
6209
|
if (fileStat.size > MAX_FILE_SIZE_BYTES) {
|
|
6192
|
-
return c.json({ error: `File exceeds
|
|
6210
|
+
return c.json({ error: `File exceeds 50 MB limit (${(fileStat.size / 1024 / 1024).toFixed(1)} MB)` }, 400);
|
|
6193
6211
|
}
|
|
6194
6212
|
const buffer = Buffer.from(await readFile2(resolvedPath));
|
|
6195
6213
|
const filename = basename2(resolvedPath);
|
|
@@ -7493,7 +7511,7 @@ var app11 = new Hono();
|
|
|
7493
7511
|
app11.post("/cancel", requireAdminSession, async (c) => {
|
|
7494
7512
|
const session_key = c.var.sessionKey;
|
|
7495
7513
|
try {
|
|
7496
|
-
const { interruptClient: interruptClient2 } = await import("./client-pool-
|
|
7514
|
+
const { interruptClient: interruptClient2 } = await import("./client-pool-SMWCZMZG.js");
|
|
7497
7515
|
await interruptClient2(session_key);
|
|
7498
7516
|
return c.json({ ok: true });
|
|
7499
7517
|
} catch (err) {
|
|
@@ -7541,7 +7559,7 @@ app11.post("/", requireAdminSession, async (c) => {
|
|
|
7541
7559
|
assertSupportedMime(file.type);
|
|
7542
7560
|
if (file.size > MAX_FILE_SIZE_BYTES) {
|
|
7543
7561
|
throw new Error(
|
|
7544
|
-
`File "${file.name}" exceeds the
|
|
7562
|
+
`File "${file.name}" exceeds the 50 MB limit (${(file.size / 1024 / 1024).toFixed(1)} MB).`
|
|
7545
7563
|
);
|
|
7546
7564
|
}
|
|
7547
7565
|
} catch (err) {
|
|
@@ -9962,7 +9980,7 @@ app22.post("/upload", requireAdminSession, async (c) => {
|
|
|
9962
9980
|
if (file.size > MAX_FILE_SIZE_BYTES) {
|
|
9963
9981
|
console.error(`[data] file-upload rejected reason="size" filename="${file.name}" size=${file.size}`);
|
|
9964
9982
|
return c.json({
|
|
9965
|
-
error: `File "${file.name}" exceeds the
|
|
9983
|
+
error: `File "${file.name}" exceeds the 50 MB limit (${(file.size / 1024 / 1024).toFixed(1)} MB).`
|
|
9966
9984
|
}, 422);
|
|
9967
9985
|
}
|
|
9968
9986
|
if (!SUPPORTED_MIME_TYPES.has(file.type)) {
|
|
@@ -13066,6 +13084,12 @@ try {
|
|
|
13066
13084
|
}
|
|
13067
13085
|
})();
|
|
13068
13086
|
startGraphHealthTimer();
|
|
13087
|
+
try {
|
|
13088
|
+
const accounts = enumerateValidAccountIds(getAccountsDirFromEnv());
|
|
13089
|
+
console.error(`[graph-health] account-enumeration accounts=${accounts.length}`);
|
|
13090
|
+
} catch (err) {
|
|
13091
|
+
console.error(`[graph-health] account-enumeration unavailable reason=${err instanceof Error ? err.message : String(err)}`);
|
|
13092
|
+
}
|
|
13069
13093
|
var configDirForWhatsApp = basename5(MAXY_DIR) || ".maxy";
|
|
13070
13094
|
var bootAccount = resolveAccount();
|
|
13071
13095
|
var bootAccountConfig = bootAccount?.config;
|
|
@@ -13083,7 +13107,7 @@ autoDeliverPremiumPlugins(bootEntitlement?.purchasedPlugins ?? void 0);
|
|
|
13083
13107
|
(async () => {
|
|
13084
13108
|
if (!bootAccount) return;
|
|
13085
13109
|
try {
|
|
13086
|
-
const { recoverRunningCloudflareTasks } = await import("./cloudflare-task-tracker-
|
|
13110
|
+
const { recoverRunningCloudflareTasks } = await import("./cloudflare-task-tracker-NQK7A2EQ.js");
|
|
13087
13111
|
const result = await recoverRunningCloudflareTasks(
|
|
13088
13112
|
bootAccount.accountId,
|
|
13089
13113
|
configDirForWhatsApp,
|