@rubytech/create-realagent 1.0.859 → 1.0.860
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/cloudflare/PLUGIN.md +4 -0
- package/payload/server/public/assets/admin-4cZM7db3.js +352 -0
- package/payload/server/public/assets/{public-BhyNH7eq.js → public-DRrf63wm.js} +2 -2
- package/payload/server/public/assets/{useVoiceRecorder-B_zVS4Oe.js → useVoiceRecorder-CR8gcELb.js} +1 -1
- package/payload/server/public/index.html +2 -2
- package/payload/server/public/public.html +2 -2
- package/payload/server/public/assets/admin-BumnnEDn.js +0 -352
|
@@ -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-DnY0498s.js";import{A as a,C as o,E as s,F as c,M as l,N as u,P as d,S as f,_ as p,a as m,b as h,c as g,g as _,h as v,i as y,k as b,n as x,o as S,r as C,s as w,t as T,u as E,v as D,w as O,y as k}from"./useVoiceRecorder-B_zVS4Oe.js";import{t as A}from"./Checkbox-BySsatDO.js";var j=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`}]]),M=t(),N=e(n(),1),P=`image/jpeg,image/png,image/gif,image/webp,application/pdf,text/plain,text/markdown,text/csv,text/html,text/calendar,audio/ogg,audio/opus,audio/mp4,audio/mpeg,audio/webm,audio/wav,.opus,.ogg,.m4a,.mp3,.wav,.webm`,F=new Set(P.split(`,`).filter(e=>!e.startsWith(`.`))),I=50*1024*1024,L=typeof window<`u`&&/^(localhost|127\.0\.0\.1|[a-z0-9-]+\.local)(:|$)/.test(window.location.hostname);function R(){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 z(){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 B(){let e=window.location.pathname.match(/^\/g\/([a-z0-9][a-z0-9-]{0,49})$/);return e?e[1]:void 0}function V(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 H(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,N.useState)(null),[r,i]=(0,N.useState)(null),[a,o]=(0,N.useState)(`loading`),[s,c]=(0,N.useState)(``),[l,u]=(0,N.useState)(null),[d,f]=(0,N.useState)(null),[p,m]=(0,N.useState)(!1),[h,g]=(0,N.useState)(null),_=(0,N.useMemo)(()=>z(),[]),v=(0,N.useMemo)(()=>B(),[]),[y,b]=(0,N.useState)(null),x=(0,N.useRef)(_||``),S=(0,N.useRef)(null),C=(0,N.useRef)(null),w=(0,N.useRef)(!1),T=(0,N.useRef)(null),[E,D]=(0,N.useState)(`sign-in`),[O,k]=(0,N.useState)(null),A=(0,N.useRef)(null),j=(0,N.useRef)(null);(0,N.useEffect)(()=>{try{let e=sessionStorage.getItem(`maxy_session`);e&&(j.current=e)}catch{}},[]);let M=(0,N.useCallback)(t=>{S.current=t,n(t);try{sessionStorage.setItem(`maxy_session`,t)}catch{}o(`chat`),e(t)},[e]),P=(0,N.useCallback)(()=>{S.current=null;try{sessionStorage.removeItem(`maxy_session`)}catch{}n(null),o(`auth-required`),D(`sign-in`)},[]),F=(0,N.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`)}},[]),I=(0,N.useCallback)(async()=>{if(S.current)return S.current;if(C.current)return C.current;let e=(async()=>{try{let e=j.current,t=await fetch(`/api/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({session_id:R(),..._?{agent:_}:{},...v?{group_slug:v}:{},...e?{session_key:e}:{}})});if(!t.ok){let e=await t.json().catch(()=>({error:``}));return L&&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?F(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 L&&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,F]);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:I,startNewSession:(0,N.useCallback)(async()=>{S.current=null,C.current=null,j.current=null,w.current=!1,T.current=null,n(null),i(null);try{sessionStorage.removeItem(`maxy_session`)}catch{}let t=await I();t&&e(t)},[I,e]),enterChat:M,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,N.useState)([]),[s,c]=(0,N.useState)(!1),l=(0,N.useRef)(!1),u=e=>{l.current=e,c(e)},d=(0,N.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{}L&&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 f(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(L&&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]),p=(0,N.useCallback)(async(a,s)=>{let c=s?.hidden??!1,d=s?.files??[];if(!a&&d.length===0||l.current)return;u(!0);let p=d.map(e=>({filename:e.name,mimeType:e.type})),m={role:`visitor`,content:a,attachments:p.length>0?p: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{}L&&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=``,p=()=>{u&&(l+=u,u=``,o(e=>{let t=[...e];return t[h]={...t[h],content:l},t}))},m=setInterval(p,60);try{for await(let e of f(c)){if(e.error)throw Object.assign(Error(e.error),{fromSSE:!0});e.text&&(u+=e.text),e.type===`component`&&(p(),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),p()}}catch(e){if(L&&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:p,sendGreeting:d,handleComponentSubmit:(0,N.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}),p(n,{hidden:!0})},[p])}}function ne({sessionKeyRef:e,groupSlug:t,isStreaming:n,setMessages:r}){let i=(0,N.useRef)(new Date().toISOString()),a=(0,N.useRef)(!0);(0,N.useEffect)(()=>{let e=()=>{a.current=document.visibilityState===`visible`};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[]);let o=(0,N.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,N.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 U=i();function W({value:e,onChange:t,onComplete:n,disabled:r}){let i=(0,N.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,U.jsx)(`div`,{className:`gate-otp-field`,children:Array.from({length:6}).map((t,n)=>(0,U.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 re({gateState:e,setGateState:t,grantInfo:n,setGrantInfo:r,gateSessionKeyRef:i,resolvedSlugRef:a,onAuthenticated:o}){let[s,c]=(0,N.useState)(``),[l,u]=(0,N.useState)(``),[d,f]=(0,N.useState)(``),[p,m]=(0,N.useState)(!1),[h,g]=(0,N.useState)(``),[_,y]=(0,N.useState)(``),[b,x]=(0,N.useState)(!1),[S,C]=(0,N.useState)(null),[w,T]=(0,N.useState)(null),[E,D]=(0,N.useState)(!1);async function O(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 k(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:_,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`),g(``))}catch{C(`Unable to connect. Please try again.`)}finally{D(!1)}}}async function j(e){if(e.preventDefault(),!E){if(C(null),l!==d){C(`Passwords do not match`);return}if(!V(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 M(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=V(l),t=e.every(e=>e.met),r=l===d,i=t&&r&&d.length>0;return(0,U.jsx)(`div`,{className:`gate-wrap`,children:(0,U.jsxs)(`div`,{className:`gate-card`,children:[n?.expiresAt&&(0,U.jsxs)(`div`,{className:`gate-expiry-badge`,children:[`Access until `,new Date(n.expiresAt).toLocaleDateString(`en-GB`,{day:`numeric`,month:`short`,year:`numeric`})]}),(0,U.jsxs)(`h2`,{className:`gate-title`,children:[`Welcome, `,n?.displayName||`there`]}),(0,U.jsx)(`p`,{className:`gate-subtitle`,children:`Create a password to access this agent in the future.`}),(0,U.jsxs)(`form`,{className:`gate-form`,onSubmit:j,children:[(0,U.jsxs)(`div`,{className:`gate-field`,children:[(0,U.jsx)(`label`,{htmlFor:`gate-display-name`,children:`Display name`}),(0,U.jsx)(`input`,{id:`gate-display-name`,type:`text`,value:n?.displayName||``,disabled:!0})]}),(0,U.jsxs)(`div`,{className:`gate-field gate-pw-row`,children:[(0,U.jsx)(`label`,{htmlFor:`gate-pw`,children:`Password`}),(0,U.jsx)(`div`,{className:`gate-pw-toggle`,children:(0,U.jsx)(A,{checked:p,onChange:m,label:`Show`})}),(0,U.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,U.jsx)(`div`,{className:`gate-strength`,children:e.map(e=>(0,U.jsxs)(`span`,{className:`gate-strength-item${e.met?` met`:``}`,children:[e.met?`✓`:`○`,` `,e.label]},e.key))})]}),(0,U.jsxs)(`div`,{className:`gate-field`,children:[(0,U.jsx)(`label`,{htmlFor:`gate-pw-confirm`,children:`Confirm password`}),(0,U.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,U.jsx)(`div`,{className:`gate-error`,children:`Passwords do not match`})]}),S&&(0,U.jsx)(`div`,{className:`gate-error`,children:S}),(0,U.jsx)(`div`,{className:`gate-submit`,children:(0,U.jsx)(v,{variant:`primary`,type:`submit`,fullWidth:!0,disabled:!i||E,loading:E,children:`Create account & enter chat`})})]})]})})}case`enter-otp`:return(0,U.jsx)(`div`,{className:`gate-wrap`,children:(0,U.jsxs)(`div`,{className:`gate-card`,children:[(0,U.jsx)(`h2`,{className:`gate-title`,children:`Enter your code`}),(0,U.jsxs)(`p`,{className:`gate-subtitle`,children:[`Enter the 6-digit code sent to `,H(_,`phone`)]}),(0,U.jsx)(W,{value:h,onChange:g,onComplete:k,disabled:E}),S&&(0,U.jsx)(`div`,{className:`gate-error`,children:S}),E&&(0,U.jsxs)(`div`,{className:`gate-loading`,children:[(0,U.jsx)(`span`,{className:`spinner`}),`Verifying...`]}),(0,U.jsx)(`div`,{className:`gate-resend`,children:(0,U.jsx)(`button`,{type:`button`,className:`gate-link`,onClick:()=>{t(`sign-in`),g(``),C(null)},children:`Use a different number`})})]})});case`sign-in`:case`private-agent`:return(0,U.jsx)(`div`,{className:`gate-wrap`,children:(0,U.jsxs)(`div`,{className:`gate-card`,children:[(0,U.jsx)(`h2`,{className:`gate-title`,children:e===`private-agent`?`Private Agent`:`Welcome back`}),(0,U.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,U.jsxs)(`form`,{className:`gate-form`,onSubmit:M,children:[(0,U.jsxs)(`div`,{className:`gate-field`,children:[(0,U.jsx)(`label`,{htmlFor:`gate-forgot-contact`,children:`Email or phone`}),(0,U.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,U.jsx)(`div`,{className:`gate-error`,children:S}),w&&(0,U.jsx)(`div`,{className:`gate-success`,children:w}),(0,U.jsx)(`div`,{className:`gate-submit`,children:(0,U.jsx)(v,{variant:`primary`,type:`submit`,fullWidth:!0,disabled:!s.trim()||E,loading:E,children:`Send reset link`})}),(0,U.jsx)(`div`,{className:`gate-actions`,children:(0,U.jsx)(`button`,{type:`button`,className:`gate-link`,onClick:()=>{x(!1),C(null),T(null)},children:`Back to sign in`})})]}):(0,U.jsxs)(`form`,{className:`gate-form`,onSubmit:O,children:[(0,U.jsxs)(`div`,{className:`gate-field`,children:[(0,U.jsx)(`label`,{htmlFor:`gate-contact`,children:`Email or phone`}),(0,U.jsx)(`input`,{id:`gate-contact`,type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:`you@example.com`,autoFocus:!0,autoComplete:`email`})]}),(0,U.jsxs)(`div`,{className:`gate-field gate-pw-row`,children:[(0,U.jsx)(`label`,{htmlFor:`gate-login-pw`,children:`Password`}),(0,U.jsx)(`div`,{className:`gate-pw-toggle`,children:(0,U.jsx)(A,{checked:p,onChange:m,label:`Show`})}),(0,U.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,U.jsx)(`div`,{className:`gate-error`,children:S}),(0,U.jsx)(`div`,{className:`gate-submit`,children:(0,U.jsx)(v,{variant:`primary`,type:`submit`,fullWidth:!0,disabled:!s.trim()||!l||E,loading:E,children:`Sign in`})}),(0,U.jsx)(`div`,{className:`gate-actions`,children:(0,U.jsx)(`button`,{type:`button`,className:`gate-link`,onClick:()=>{x(!0),C(null)},children:`Forgot password?`})})]}),e===`private-agent`&&(0,U.jsx)(`p`,{className:`gate-hint`,children:`No account? You need an invitation from the agent owner.`})]})});case`access-expired`:return(0,U.jsx)(`div`,{className:`gate-wrap`,children:(0,U.jsxs)(`div`,{className:`gate-card`,children:[(0,U.jsx)(`div`,{className:`gate-icon`,children:`⏰`}),(0,U.jsx)(`h2`,{className:`gate-title`,children:`Access expired`}),(0,U.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,U.jsx)(`div`,{className:`gate-actions`,children:(0,U.jsx)(v,{variant:`secondary`,onClick:()=>{t(`sign-in`),C(null),u(``)},children:`Sign in with a different account`})})]})});case`link-expired`:return(0,U.jsx)(`div`,{className:`gate-wrap`,children:(0,U.jsxs)(`div`,{className:`gate-card`,children:[(0,U.jsx)(`div`,{className:`gate-icon`,children:`⚠️`}),(0,U.jsx)(`h2`,{className:`gate-title`,children:`Link expired`}),(0,U.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,U.jsx)(`div`,{className:`gate-actions`,children:(0,U.jsx)(v,{variant:`primary`,onClick:()=>{t(`sign-in`),C(null)},children:`Go to sign in`})})]})});case`otp-failed`:return(0,U.jsx)(`div`,{className:`gate-wrap`,children:(0,U.jsxs)(`div`,{className:`gate-card`,children:[(0,U.jsx)(`div`,{className:`gate-icon`,children:`⛔`}),(0,U.jsx)(`h2`,{className:`gate-title`,children:`Too many attempts`}),(0,U.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,U.jsx)(`div`,{className:`gate-actions`,children:(0,U.jsx)(v,{variant:`secondary`,onClick:()=>{t(`sign-in`),C(null),g(``)},children:`Back to sign in`})})]})})}}var G={"single-select":g,"multi-select":w,"action-buttons":S};function K({name:e,data:t,onSubmit:n,submitted:r}){let i=G[e];return i?(0,U.jsx)(i,{data:t,onSubmit:n,submitted:r}):(console.warn(`[PublicComponentRenderer] Unknown component: "${e}". Registered: ${Object.keys(G).join(`, `)}`),(0,U.jsx)(`div`,{className:`component-card component-card--error`,children:(0,U.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 ie({messages:e,isStreaming:t,sessionError:n,selectionMode:r,selectedItems:i,toggleSelectItem:a,onComponentSubmit:o,remainingSuggestions:s,onSuggestionClick:d,isAtBottom:f,setIsAtBottom:p,isGroup:h,sessionId:g}){let[_,y]=(0,N.useState)(new Set),[b,x]=(0,N.useState)(new Set),S=(0,N.useRef)(null),C=(0,N.useRef)(null),w=(0,N.useRef)(null),T=(0,N.useRef)(!1),D=(0,N.useRef)(!1),O=(0,N.useRef)(!1),k=(0,N.useRef)(0),j=(0,N.useRef)(!1),M=(0,N.useRef)(new Map);j.current=t,(0,N.useEffect)(()=>{t&&!T.current&&f&&(D.current=!0)},[t,f]),(0,N.useEffect)(()=>{if(!D.current&&!f){T.current=t,O.current=!1;return}if(T.current&&!t&&w.current&&C.current){let e=w.current;if(e.offsetHeight>C.current.clientHeight){D.current=!1,O.current=!0,e.scrollIntoView({behavior:`smooth`,block:`start`}),T.current=t;return}}(f||D.current)&&!O.current&&S.current?.scrollIntoView({behavior:`smooth`}),T.current&&!t&&(D.current=!1),T.current=t},[e,f,t]),(0,N.useEffect)(()=>{let e=C.current;if(!e)return;let t=()=>{let t=e.scrollTop;j.current&&t<k.current&&(D.current=!1),k.current=t,p(e.scrollHeight-e.scrollTop-e.clientHeight<80)};return e.addEventListener(`scroll`,t,{passive:!0}),t(),()=>e.removeEventListener(`scroll`,t)},[p]),(0,N.useEffect)(()=>{function e(){x(e=>{let t=new Set;return M.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 M.current.forEach(e=>t.observe(e)),()=>t.disconnect()},[e.length,_]);let P=[...e].sort((e,t)=>e.timestamp-t.timestamp);(0,N.useEffect)(()=>{r&&console.log(`[selection] entered`,{conversationId:g??`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,U.jsxs)(`div`,{className:`chat-messages-wrap`,children:[r&&(0,U.jsx)(`div`,{className:`selection-overlay-band`}),(0,U.jsxs)(`div`,{className:`chat-messages`,ref:C,children:[n&&e.length===0&&(0,U.jsx)(`div`,{className:`session-error`,children:(0,U.jsx)(`p`,{children:n})}),P.map((e,n)=>{if(e.hidden)return null;let s=t&&n===P.length-1,d=`${e.timestamp}_${e.role}`,f=i.has(d);return(0,U.jsxs)(`div`,{ref:n===F?w:void 0,className:`message ${e.role}${f?` selected`:``}`,children:[r&&!s&&(0,U.jsx)(`div`,{className:`message-select-check`,children:(0,U.jsx)(A,{checked:f,onChange:()=>a(d)})}),(0,U.jsxs)(`div`,{className:`bubble`,children:[h&&e.role===`visitor`&&e.senderName&&(0,U.jsx)(`span`,{className:`bubble-sender`,children:e.senderName}),e.role===`visitor`&&e.content?(()=>{let t=_.has(n),r=b.has(n);return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`div`,{ref:e=>{e?M.current.set(n,e):M.current.delete(n)},className:t?`bubble-content`:`bubble-content clamped${r?` overflowing`:``}`,children:e.content}),r&&(0,U.jsx)(`div`,{className:`bubble-expand`,children:(0,U.jsx)(v,{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,U.jsx)(c,{size:14})})})]})})():e.content?(0,U.jsx)(E,{content:e.content,timestamp:m(e.timestamp)}):(0,U.jsxs)(`span`,{className:`typing-indicator`,children:[(0,U.jsx)(`span`,{className:`typing-dot`}),(0,U.jsx)(`span`,{className:`typing-dot`}),(0,U.jsx)(`span`,{className:`typing-dot`})]}),e.attachments&&e.attachments.length>0&&(0,U.jsx)(`div`,{className:`message-attachments`,children:e.attachments.map((e,t)=>(0,U.jsxs)(`span`,{className:`message-attachment-chip no-action`,children:[e.mimeType===`application/pdf`?(0,U.jsx)(l,{size:12}):e.mimeType.startsWith(`text/`)?(0,U.jsx)(u,{size:12}):null,(0,U.jsx)(`span`,{children:e.filename})]},t))}),e.role===`visitor`&&(0,U.jsx)(`span`,{className:`message-timestamp`,children:m(e.timestamp)})]}),e.role===`maxy`&&e.components&&e.components.length>0&&(0,U.jsx)(`div`,{className:`public-components`,children:e.components.map((e,t)=>(0,U.jsx)(`div`,{className:`public-component-enter`,children:(0,U.jsx)(K,{name:e.name,data:e.data,onSubmit:e=>o(n,t,e),submitted:e.submitted})},t))})]},n)}),!t&&s.length>0&&(0,U.jsx)(`div`,{className:`chat-suggestions`,children:s.map(e=>(0,U.jsx)(v,{variant:`suggestion`,onClick:()=>d(e),children:e},e))}),(0,U.jsx)(`div`,{ref:S})]}),!f&&(0,U.jsx)(`button`,{className:`scroll-to-bottom`,onClick:()=>S.current?.scrollIntoView({behavior:`smooth`}),"aria-label":`Scroll to bottom`,children:(0,U.jsx)(c,{size:18})})]})}function ae({selectedItems:e,messages:t,isStreaming:n,copySelected:r,selectAll:i,exitSelection:a,showCopyToast:c}){let[l,u]=(0,N.useState)(!1),f=(0,N.useRef)(null),p=(0,N.useRef)(!1);function m(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 h(e,t){return parseInt(e.slice(0,e.lastIndexOf(`_`)),10)-parseInt(t.slice(0,t.lastIndexOf(`_`)),10)}function g(){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-DnY0498s.js";import{A as a,C as o,D as s,F as c,I as l,N as u,P as d,T as f,_ as p,a as m,b as h,c as g,g as _,i as v,j as y,n as b,o as x,r as S,s as C,t as w,u as T,v as E,w as D,x as O,y as k}from"./useVoiceRecorder-CR8gcELb.js";import{t as A}from"./Checkbox-BySsatDO.js";var j=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`}]]),M=t(),N=e(n(),1),P=`image/jpeg,image/png,image/gif,image/webp,application/pdf,text/plain,text/markdown,text/csv,text/html,text/calendar,audio/ogg,audio/opus,audio/mp4,audio/mpeg,audio/webm,audio/wav,.opus,.ogg,.m4a,.mp3,.wav,.webm`,F=new Set(P.split(`,`).filter(e=>!e.startsWith(`.`))),I=50*1024*1024,L=typeof window<`u`&&/^(localhost|127\.0\.0\.1|[a-z0-9-]+\.local)(:|$)/.test(window.location.hostname);function R(){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 z(){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 B(){let e=window.location.pathname.match(/^\/g\/([a-z0-9][a-z0-9-]{0,49})$/);return e?e[1]:void 0}function V(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 H(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,N.useState)(null),[r,i]=(0,N.useState)(null),[a,o]=(0,N.useState)(`loading`),[s,c]=(0,N.useState)(``),[l,u]=(0,N.useState)(null),[d,f]=(0,N.useState)(null),[p,m]=(0,N.useState)(!1),[h,g]=(0,N.useState)(null),_=(0,N.useMemo)(()=>z(),[]),v=(0,N.useMemo)(()=>B(),[]),[y,b]=(0,N.useState)(null),x=(0,N.useRef)(_||``),S=(0,N.useRef)(null),C=(0,N.useRef)(null),w=(0,N.useRef)(!1),T=(0,N.useRef)(null),[E,D]=(0,N.useState)(`sign-in`),[O,k]=(0,N.useState)(null),A=(0,N.useRef)(null),j=(0,N.useRef)(null);(0,N.useEffect)(()=>{try{let e=sessionStorage.getItem(`maxy_session`);e&&(j.current=e)}catch{}},[]);let M=(0,N.useCallback)(t=>{S.current=t,n(t);try{sessionStorage.setItem(`maxy_session`,t)}catch{}o(`chat`),e(t)},[e]),P=(0,N.useCallback)(()=>{S.current=null;try{sessionStorage.removeItem(`maxy_session`)}catch{}n(null),o(`auth-required`),D(`sign-in`)},[]),F=(0,N.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`)}},[]),I=(0,N.useCallback)(async()=>{if(S.current)return S.current;if(C.current)return C.current;let e=(async()=>{try{let e=j.current,t=await fetch(`/api/session`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({session_id:R(),..._?{agent:_}:{},...v?{group_slug:v}:{},...e?{session_key:e}:{}})});if(!t.ok){let e=await t.json().catch(()=>({error:``}));return L&&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?F(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 L&&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,F]);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:I,startNewSession:(0,N.useCallback)(async()=>{S.current=null,C.current=null,j.current=null,w.current=!1,T.current=null,n(null),i(null);try{sessionStorage.removeItem(`maxy_session`)}catch{}let t=await I();t&&e(t)},[I,e]),enterChat:M,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,s]=(0,N.useState)([]),[c,l]=(0,N.useState)(!1),u=(0,N.useRef)(!1),d=e=>{u.current=e,l(e)},f=(0,N.useCallback)(async a=>{if(!u.current){d(!0),s([{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{}L&&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=``,c=()=>{i&&(r+=i,i=``,s(e=>{let t=[...e];return t[0]={...t[0],content:r},t}))},l=setInterval(c,60);try{for await(let e of o(n)){if(e.error)throw Object.assign(Error(e.error),{fromSSE:!0});e.text&&(i+=e.text),e.type===`component`&&(c(),s(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(l),c()}}catch(e){if(L&&console.error(`[chat] greeting failed:`,e),r===`auth-required`)return;let t=e instanceof Error?e.message:String(e);s([{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{d(!1),r===`chat`&&i.current?.focus()}}},[e,t,n,r,i]),p=(0,N.useCallback)(async(a,c)=>{let l=c?.hidden??!1,f=c?.files??[];if(!a&&f.length===0||u.current)return;d(!0);let p=f.map(e=>({filename:e.name,mimeType:e.type})),m={role:`visitor`,content:a,attachments:p.length>0?p:void 0,timestamp:Date.now(),hidden:l},h;s(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(f.length>0){let t=new FormData;t.append(`message`,a),t.append(`session_key`,e);for(let e of f)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:c}=r(n),l=await fetch(`/api/chat`,{method:`POST`,headers:c,body:i});if(l.status===401){e.current=null;try{sessionStorage.removeItem(`maxy_session`)}catch{}L&&console.warn(`[session-expired] stale key cleared, retrying with fresh session`);let n=await t();if(!n)throw Error(`session`);({body:i,headers:c}=r(n)),l=await fetch(`/api/chat`,{method:`POST`,headers:c,body:i})}if(!l.ok){let e=await l.json().catch(()=>({}));throw Error(e.error||`Something went wrong`)}let u=``,d=``,p=()=>{d&&(u+=d,d=``,s(e=>{let t=[...e];return t[h]={...t[h],content:u},t}))},m=setInterval(p,60);try{for await(let e of o(l)){if(e.error)throw Object.assign(Error(e.error),{fromSSE:!0});e.text&&(d+=e.text),e.type===`component`&&(p(),s(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),p()}}catch(e){if(L&&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;s(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{d(!1),r===`chat`&&i.current?.focus()}},[e,t,n,r,i]);return{messages:a,setMessages:s,isStreaming:c,sendMessage:p,sendGreeting:f,handleComponentSubmit:(0,N.useCallback)((e,t,n)=>{s(n=>{let r=[...n],i={...r[e]},a=[...i.components||[]];return a[t]={...a[t],submitted:!0},r[e]={...i,components:a},r}),p(n,{hidden:!0})},[p])}}function ne({sessionKeyRef:e,groupSlug:t,isStreaming:n,setMessages:r}){let i=(0,N.useRef)(new Date().toISOString()),a=(0,N.useRef)(!0);(0,N.useEffect)(()=>{let e=()=>{a.current=document.visibilityState===`visible`};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[]);let o=(0,N.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,N.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 U=i();function W({value:e,onChange:t,onComplete:n,disabled:r}){let i=(0,N.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,U.jsx)(`div`,{className:`gate-otp-field`,children:Array.from({length:6}).map((t,n)=>(0,U.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 re({gateState:e,setGateState:t,grantInfo:n,setGrantInfo:r,gateSessionKeyRef:i,resolvedSlugRef:a,onAuthenticated:o}){let[s,c]=(0,N.useState)(``),[l,u]=(0,N.useState)(``),[d,f]=(0,N.useState)(``),[p,m]=(0,N.useState)(!1),[h,g]=(0,N.useState)(``),[v,y]=(0,N.useState)(``),[b,x]=(0,N.useState)(!1),[S,C]=(0,N.useState)(null),[w,T]=(0,N.useState)(null),[E,D]=(0,N.useState)(!1);async function O(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 k(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`),g(``))}catch{C(`Unable to connect. Please try again.`)}finally{D(!1)}}}async function j(e){if(e.preventDefault(),!E){if(C(null),l!==d){C(`Passwords do not match`);return}if(!V(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 M(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=V(l),t=e.every(e=>e.met),r=l===d,i=t&&r&&d.length>0;return(0,U.jsx)(`div`,{className:`gate-wrap`,children:(0,U.jsxs)(`div`,{className:`gate-card`,children:[n?.expiresAt&&(0,U.jsxs)(`div`,{className:`gate-expiry-badge`,children:[`Access until `,new Date(n.expiresAt).toLocaleDateString(`en-GB`,{day:`numeric`,month:`short`,year:`numeric`})]}),(0,U.jsxs)(`h2`,{className:`gate-title`,children:[`Welcome, `,n?.displayName||`there`]}),(0,U.jsx)(`p`,{className:`gate-subtitle`,children:`Create a password to access this agent in the future.`}),(0,U.jsxs)(`form`,{className:`gate-form`,onSubmit:j,children:[(0,U.jsxs)(`div`,{className:`gate-field`,children:[(0,U.jsx)(`label`,{htmlFor:`gate-display-name`,children:`Display name`}),(0,U.jsx)(`input`,{id:`gate-display-name`,type:`text`,value:n?.displayName||``,disabled:!0})]}),(0,U.jsxs)(`div`,{className:`gate-field gate-pw-row`,children:[(0,U.jsx)(`label`,{htmlFor:`gate-pw`,children:`Password`}),(0,U.jsx)(`div`,{className:`gate-pw-toggle`,children:(0,U.jsx)(A,{checked:p,onChange:m,label:`Show`})}),(0,U.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,U.jsx)(`div`,{className:`gate-strength`,children:e.map(e=>(0,U.jsxs)(`span`,{className:`gate-strength-item${e.met?` met`:``}`,children:[e.met?`✓`:`○`,` `,e.label]},e.key))})]}),(0,U.jsxs)(`div`,{className:`gate-field`,children:[(0,U.jsx)(`label`,{htmlFor:`gate-pw-confirm`,children:`Confirm password`}),(0,U.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,U.jsx)(`div`,{className:`gate-error`,children:`Passwords do not match`})]}),S&&(0,U.jsx)(`div`,{className:`gate-error`,children:S}),(0,U.jsx)(`div`,{className:`gate-submit`,children:(0,U.jsx)(_,{variant:`primary`,type:`submit`,fullWidth:!0,disabled:!i||E,loading:E,children:`Create account & enter chat`})})]})]})})}case`enter-otp`:return(0,U.jsx)(`div`,{className:`gate-wrap`,children:(0,U.jsxs)(`div`,{className:`gate-card`,children:[(0,U.jsx)(`h2`,{className:`gate-title`,children:`Enter your code`}),(0,U.jsxs)(`p`,{className:`gate-subtitle`,children:[`Enter the 6-digit code sent to `,H(v,`phone`)]}),(0,U.jsx)(W,{value:h,onChange:g,onComplete:k,disabled:E}),S&&(0,U.jsx)(`div`,{className:`gate-error`,children:S}),E&&(0,U.jsxs)(`div`,{className:`gate-loading`,children:[(0,U.jsx)(`span`,{className:`spinner`}),`Verifying...`]}),(0,U.jsx)(`div`,{className:`gate-resend`,children:(0,U.jsx)(`button`,{type:`button`,className:`gate-link`,onClick:()=>{t(`sign-in`),g(``),C(null)},children:`Use a different number`})})]})});case`sign-in`:case`private-agent`:return(0,U.jsx)(`div`,{className:`gate-wrap`,children:(0,U.jsxs)(`div`,{className:`gate-card`,children:[(0,U.jsx)(`h2`,{className:`gate-title`,children:e===`private-agent`?`Private Agent`:`Welcome back`}),(0,U.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,U.jsxs)(`form`,{className:`gate-form`,onSubmit:M,children:[(0,U.jsxs)(`div`,{className:`gate-field`,children:[(0,U.jsx)(`label`,{htmlFor:`gate-forgot-contact`,children:`Email or phone`}),(0,U.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,U.jsx)(`div`,{className:`gate-error`,children:S}),w&&(0,U.jsx)(`div`,{className:`gate-success`,children:w}),(0,U.jsx)(`div`,{className:`gate-submit`,children:(0,U.jsx)(_,{variant:`primary`,type:`submit`,fullWidth:!0,disabled:!s.trim()||E,loading:E,children:`Send reset link`})}),(0,U.jsx)(`div`,{className:`gate-actions`,children:(0,U.jsx)(`button`,{type:`button`,className:`gate-link`,onClick:()=>{x(!1),C(null),T(null)},children:`Back to sign in`})})]}):(0,U.jsxs)(`form`,{className:`gate-form`,onSubmit:O,children:[(0,U.jsxs)(`div`,{className:`gate-field`,children:[(0,U.jsx)(`label`,{htmlFor:`gate-contact`,children:`Email or phone`}),(0,U.jsx)(`input`,{id:`gate-contact`,type:`text`,value:s,onChange:e=>c(e.target.value),placeholder:`you@example.com`,autoFocus:!0,autoComplete:`email`})]}),(0,U.jsxs)(`div`,{className:`gate-field gate-pw-row`,children:[(0,U.jsx)(`label`,{htmlFor:`gate-login-pw`,children:`Password`}),(0,U.jsx)(`div`,{className:`gate-pw-toggle`,children:(0,U.jsx)(A,{checked:p,onChange:m,label:`Show`})}),(0,U.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,U.jsx)(`div`,{className:`gate-error`,children:S}),(0,U.jsx)(`div`,{className:`gate-submit`,children:(0,U.jsx)(_,{variant:`primary`,type:`submit`,fullWidth:!0,disabled:!s.trim()||!l||E,loading:E,children:`Sign in`})}),(0,U.jsx)(`div`,{className:`gate-actions`,children:(0,U.jsx)(`button`,{type:`button`,className:`gate-link`,onClick:()=>{x(!0),C(null)},children:`Forgot password?`})})]}),e===`private-agent`&&(0,U.jsx)(`p`,{className:`gate-hint`,children:`No account? You need an invitation from the agent owner.`})]})});case`access-expired`:return(0,U.jsx)(`div`,{className:`gate-wrap`,children:(0,U.jsxs)(`div`,{className:`gate-card`,children:[(0,U.jsx)(`div`,{className:`gate-icon`,children:`⏰`}),(0,U.jsx)(`h2`,{className:`gate-title`,children:`Access expired`}),(0,U.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,U.jsx)(`div`,{className:`gate-actions`,children:(0,U.jsx)(_,{variant:`secondary`,onClick:()=>{t(`sign-in`),C(null),u(``)},children:`Sign in with a different account`})})]})});case`link-expired`:return(0,U.jsx)(`div`,{className:`gate-wrap`,children:(0,U.jsxs)(`div`,{className:`gate-card`,children:[(0,U.jsx)(`div`,{className:`gate-icon`,children:`⚠️`}),(0,U.jsx)(`h2`,{className:`gate-title`,children:`Link expired`}),(0,U.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,U.jsx)(`div`,{className:`gate-actions`,children:(0,U.jsx)(_,{variant:`primary`,onClick:()=>{t(`sign-in`),C(null)},children:`Go to sign in`})})]})});case`otp-failed`:return(0,U.jsx)(`div`,{className:`gate-wrap`,children:(0,U.jsxs)(`div`,{className:`gate-card`,children:[(0,U.jsx)(`div`,{className:`gate-icon`,children:`⛔`}),(0,U.jsx)(`h2`,{className:`gate-title`,children:`Too many attempts`}),(0,U.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,U.jsx)(`div`,{className:`gate-actions`,children:(0,U.jsx)(_,{variant:`secondary`,onClick:()=>{t(`sign-in`),C(null),g(``)},children:`Back to sign in`})})]})})}}var G={"single-select":g,"multi-select":C,"action-buttons":x};function K({name:e,data:t,onSubmit:n,submitted:r}){let i=G[e];return i?(0,U.jsx)(i,{data:t,onSubmit:n,submitted:r}):(console.warn(`[PublicComponentRenderer] Unknown component: "${e}". Registered: ${Object.keys(G).join(`, `)}`),(0,U.jsx)(`div`,{className:`component-card component-card--error`,children:(0,U.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 ie({messages:e,isStreaming:t,sessionError:n,selectionMode:r,selectedItems:i,toggleSelectItem:a,onComponentSubmit:o,remainingSuggestions:s,onSuggestionClick:c,isAtBottom:f,setIsAtBottom:p,isGroup:h,sessionId:g}){let[v,y]=(0,N.useState)(new Set),[b,x]=(0,N.useState)(new Set),S=(0,N.useRef)(null),C=(0,N.useRef)(null),w=(0,N.useRef)(null),E=(0,N.useRef)(!1),D=(0,N.useRef)(!1),O=(0,N.useRef)(!1),k=(0,N.useRef)(0),j=(0,N.useRef)(!1),M=(0,N.useRef)(new Map);j.current=t,(0,N.useEffect)(()=>{t&&!E.current&&f&&(D.current=!0)},[t,f]),(0,N.useEffect)(()=>{if(!D.current&&!f){E.current=t,O.current=!1;return}if(E.current&&!t&&w.current&&C.current){let e=w.current;if(e.offsetHeight>C.current.clientHeight){D.current=!1,O.current=!0,e.scrollIntoView({behavior:`smooth`,block:`start`}),E.current=t;return}}(f||D.current)&&!O.current&&S.current?.scrollIntoView({behavior:`smooth`}),E.current&&!t&&(D.current=!1),E.current=t},[e,f,t]),(0,N.useEffect)(()=>{let e=C.current;if(!e)return;let t=()=>{let t=e.scrollTop;j.current&&t<k.current&&(D.current=!1),k.current=t,p(e.scrollHeight-e.scrollTop-e.clientHeight<80)};return e.addEventListener(`scroll`,t,{passive:!0}),t(),()=>e.removeEventListener(`scroll`,t)},[p]),(0,N.useEffect)(()=>{function e(){x(e=>{let t=new Set;return M.current.forEach((n,r)=>{n.isConnected&&(v.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 M.current.forEach(e=>t.observe(e)),()=>t.disconnect()},[e.length,v]);let P=[...e].sort((e,t)=>e.timestamp-t.timestamp);(0,N.useEffect)(()=>{r&&console.log(`[selection] entered`,{conversationId:g??`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,U.jsxs)(`div`,{className:`chat-messages-wrap`,children:[r&&(0,U.jsx)(`div`,{className:`selection-overlay-band`}),(0,U.jsxs)(`div`,{className:`chat-messages`,ref:C,children:[n&&e.length===0&&(0,U.jsx)(`div`,{className:`session-error`,children:(0,U.jsx)(`p`,{children:n})}),P.map((e,n)=>{if(e.hidden)return null;let s=t&&n===P.length-1,c=`${e.timestamp}_${e.role}`,f=i.has(c);return(0,U.jsxs)(`div`,{ref:n===F?w:void 0,className:`message ${e.role}${f?` selected`:``}`,children:[r&&!s&&(0,U.jsx)(`div`,{className:`message-select-check`,children:(0,U.jsx)(A,{checked:f,onChange:()=>a(c)})}),(0,U.jsxs)(`div`,{className:`bubble`,children:[h&&e.role===`visitor`&&e.senderName&&(0,U.jsx)(`span`,{className:`bubble-sender`,children:e.senderName}),e.role===`visitor`&&e.content?(()=>{let t=v.has(n),r=b.has(n);return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(`div`,{ref:e=>{e?M.current.set(n,e):M.current.delete(n)},className:t?`bubble-content`:`bubble-content clamped${r?` overflowing`:``}`,children:e.content}),r&&(0,U.jsx)(`div`,{className:`bubble-expand`,children:(0,U.jsx)(_,{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,U.jsx)(l,{size:14})})})]})})():e.content?(0,U.jsx)(T,{content:e.content,timestamp:m(e.timestamp)}):(0,U.jsxs)(`span`,{className:`typing-indicator`,children:[(0,U.jsx)(`span`,{className:`typing-dot`}),(0,U.jsx)(`span`,{className:`typing-dot`}),(0,U.jsx)(`span`,{className:`typing-dot`})]}),e.attachments&&e.attachments.length>0&&(0,U.jsx)(`div`,{className:`message-attachments`,children:e.attachments.map((e,t)=>(0,U.jsxs)(`span`,{className:`message-attachment-chip no-action`,children:[e.mimeType===`application/pdf`?(0,U.jsx)(u,{size:12}):e.mimeType.startsWith(`text/`)?(0,U.jsx)(d,{size:12}):null,(0,U.jsx)(`span`,{children:e.filename})]},t))}),e.role===`visitor`&&(0,U.jsx)(`span`,{className:`message-timestamp`,children:m(e.timestamp)})]}),e.role===`maxy`&&e.components&&e.components.length>0&&(0,U.jsx)(`div`,{className:`public-components`,children:e.components.map((e,t)=>(0,U.jsx)(`div`,{className:`public-component-enter`,children:(0,U.jsx)(K,{name:e.name,data:e.data,onSubmit:e=>o(n,t,e),submitted:e.submitted})},t))})]},n)}),!t&&s.length>0&&(0,U.jsx)(`div`,{className:`chat-suggestions`,children:s.map(e=>(0,U.jsx)(_,{variant:`suggestion`,onClick:()=>c(e),children:e},e))}),(0,U.jsx)(`div`,{ref:S})]}),!f&&(0,U.jsx)(`button`,{className:`scroll-to-bottom`,onClick:()=>S.current?.scrollIntoView({behavior:`smooth`}),"aria-label":`Scroll to bottom`,children:(0,U.jsx)(l,{size:18})})]})}function ae({selectedItems:e,messages:t,isStreaming:n,copySelected:r,selectAll:i,exitSelection:a,showCopyToast:o}){let[l,u]=(0,N.useState)(!1),d=(0,N.useRef)(null),f=(0,N.useRef)(!1);function p(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 m(e,t){return parseInt(e.slice(0,e.lastIndexOf(`_`)),10)-parseInt(t.slice(0,t.lastIndexOf(`_`)),10)}function h(){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
|
-
`)}N.useEffect(()=>{if(!l)return;let e=e=>{e.target.closest(`.selection-copy-wrap`)||u(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[l]);function _(){f.current!==null&&(clearTimeout(f.current),f.current=null)}let v=[...t].sort((e,t)=>e.timestamp-t.timestamp),y=v.reduce((e,t,r)=>(t.hidden||n&&r===v.length-1||e.push(`${t.timestamp}_${t.role}`),e),[]),b=y.length>0&&y.every(t=>e.has(t));return(0,U.jsx)(`div`,{className:`chat-input-area`,children:(0,U.jsxs)(`div`,{className:`selection-bar`,children:[(0,U.jsxs)(`div`,{className:`selection-bar-left`,children:[(0,U.jsxs)(`button`,{type:`button`,className:`selection-select-all`,onClick:()=>i(y),disabled:y.length===0,"aria-label":b?`Deselect all`:`Select all`,title:b?`Deselect all`:`Select all`,children:[(0,U.jsx)(s,{size:16}),(0,U.jsx)(`span`,{children:b?`Deselect all`:`Select all`})]}),(0,U.jsxs)(`span`,{className:`selection-count`,children:[e.size,` Selected`]})]}),(0,U.jsxs)(`div`,{className:`selection-copy-wrap`,children:[(0,U.jsxs)(`button`,{type:`button`,className:`selection-copy`,onPointerDown:()=>{if(l){u(!1);return}p.current=!1,f.current=setTimeout(()=>{p.current=!0,u(!0),f.current=null},500)},onPointerUp:_,onPointerLeave:_,onPointerCancel:_,onClick:async()=>{p.current||await r(m,h)},children:[(0,U.jsx)(d,{size:18}),(0,U.jsx)(`span`,{children:`Copy`})]}),l&&(0,U.jsx)(`div`,{className:`copy-menu`,children:(0,U.jsx)(`button`,{type:`button`,className:`copy-menu-item`,onClick:async()=>{let e=g();e&&c(await o(e)),a()},children:`Copy all`})})]}),(0,U.jsx)(`button`,{type:`button`,className:`selection-cancel`,onClick:a,children:`Cancel`})]})})}function oe({input:e,setInput:t,isStreaming:n,pendingFiles:r,setPendingFiles:i,attachError:o,setAttachError:s,isDragOver:c,setIsDragOver:d,inputRef:f,onSubmit:m,onSendVoiceNote:h}){let g=(0,N.useRef)(null),S=T(),w=S.state===`recording`||S.state===`paused`||S.state===`sending`,E=!w&&!n&&!e.trim()&&r.length===0;async function D(){let e=await S.send();if(!e)return;let t=e.type===`audio/ogg`?`.ogg`:e.type===`audio/mp4`?`.m4a`:`.webm`;h(new File([e],`voice-note${t}`,{type:e.type}))}function O(e){s(null);let t=e.map(_),n=t.find(e=>!p(e.type,F));if(n){s(`Unsupported file type: "${n.type}". Supported: images, PDF, plain text, markdown, CSV, calendar, voice notes.`);return}let r=t.find(e=>e.size>I);if(r){s(`"${r.name}" exceeds the 50 MB limit.`);return}i(e=>[...e,...t].slice(0,5))}function k(e){e.preventDefault(),d(!0)}function A(){d(!1)}function j(e){e.preventDefault(),d(!1),O([...e.dataTransfer.files])}return(0,U.jsxs)(`div`,{className:`chat-input-area`,children:[(0,U.jsx)(`input`,{ref:g,type:`file`,multiple:!0,accept:P,style:{display:`none`},onChange:e=>{e.target.files&&O([...e.target.files]),e.target.value=``}}),r.length>0&&(0,U.jsx)(`div`,{className:`attachment-strip`,children:r.map((e,t)=>(0,U.jsxs)(`div`,{className:`attachment-chip`,children:[e.type.startsWith(`image/`)?(0,U.jsx)(`img`,{src:URL.createObjectURL(e),alt:e.name,className:`attachment-chip-thumb`}):e.type.startsWith(`audio/`)?(0,U.jsx)(a,{size:14}):e.type===`application/pdf`?(0,U.jsx)(l,{size:14}):(0,U.jsx)(u,{size:14}),(0,U.jsx)(`span`,{className:`attachment-chip-name`,children:e.name}),(0,U.jsx)(`button`,{type:`button`,className:`attachment-chip-remove`,onClick:()=>i(e=>e.filter((e,n)=>n!==t)),"aria-label":`Remove ${e.name}`,children:`×`})]},t))}),o&&(0,U.jsx)(`p`,{className:`attach-error`,children:o}),S.state===`error`&&S.errorMessage&&(0,U.jsxs)(`p`,{className:`voice-error`,role:`alert`,children:[(0,U.jsx)(a,{size:14}),S.errorMessage]}),(0,U.jsx)(y,{inputRef:f}),w?(0,U.jsx)(`div`,{className:`chat-form voice-active`,children:(0,U.jsx)(x,{state:S.state,elapsedSeconds:S.elapsedSeconds,waveform:S.waveform,onTogglePause:S.togglePause,onDiscard:S.discard,onSend:D})}):(0,U.jsxs)(`form`,{className:`chat-form${c?` drag-over`:``}`,onSubmit:m,onDragOver:k,onDragLeave:A,onDrop:j,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&&O(n)},children:[(0,U.jsx)(v,{variant:`icon`,type:`button`,onClick:()=>g.current?.click(),disabled:n,"aria-label":`Attach file`,children:(0,U.jsx)(b,{size:14})}),(0,U.jsx)(C,{ref:f,value:e,onChange:t}),E?(0,U.jsx)(v,{variant:`send`,type:`button`,onClick:S.start,disabled:n,"aria-label":`Record voice note`,children:(0,U.jsx)(a,{size:14})}):(0,U.jsx)(v,{variant:`send`,type:`submit`,disabled:n||!e.trim()&&r.length===0,"aria-label":`Send message`,children:(0,U.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,U.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,U.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]})]})}var q=[];function J(){let[e,t]=(0,N.useState)(``),[n,r]=(0,N.useState)([]),[i,a]=(0,N.useState)(!1),[o,c]=(0,N.useState)(null),[l,u]=(0,N.useState)(q),[d,f]=(0,N.useState)(!0),p=(0,N.useRef)(null),{selectionMode:m,selectedItems:g,copyToast:_,exitSelection:v,enterSelection:y,toggleSelectItem:b,selectAll:x,copySelected:S,showCopyToast:C}=O(),w=(0,N.useRef)(()=>{}),T=ee((0,N.useCallback)(e=>{w.current(e)},[])),{sessionId:E,sessionKeyRef:A,sessionError:M,pageState:P,agentDisplayName:F,agentImage:I,agentImageShape:L,showAgentName:R,branding:z,ensureSession:B,startNewSession:V,resumedRef:H,resumeMessagesRef:W,groupContext:G,groupSlug:K}=T,{messages:J,setMessages:Y,isStreaming:X,sendMessage:Z,sendGreeting:Q,handleComponentSubmit:se}=te({sessionKeyRef:A,ensureSession:B,sessionError:M,pageState:P,inputRef:p});(0,N.useEffect)(()=>{w.current=Q},[Q]),ne({sessionKeyRef:A,groupSlug:K,isStreaming:X,setMessages:Y}),(0,N.useEffect)(()=>{let e=!1;return(async()=>{let t=await B();if(!e&&t){if(H.current&&W.current&&W.current.length>0){let e=W.current.map(e=>({role:e.role,content:e.content,timestamp:e.timestamp}));e.sort((e,t)=>e.timestamp-t.timestamp),Y(e),W.current=null;return}Q(t)}})(),()=>{e=!0}},[]),(0,N.useEffect)(()=>{P===`chat`&&p.current?.focus()},[P]),(0,N.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,N.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,N.useEffect)(()=>{function e(e){e.key===`Escape`&&m&&v()}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[m,v]);function ce(){X||(Y([]),u(q),V())}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)),u(t=>t.filter(t=>t!==e)),f(!0);let i=[...n];t(``),r([]),c(null),Z(e,{files:i})}function le(t){t.preventDefault(),$(e.trim()),p.current?.resetHeight()}return(0,U.jsxs)(`div`,{className:`chat-page`,children:[(0,U.jsxs)(`header`,{className:`chat-header`,children:[(0,U.jsx)(`img`,{src:I||z?.logoUrl||h,alt:z?.name||D.productName,className:`chat-logo${I&&L===`circle`?` chat-logo--circle`:``}${I&&L===`rounded`?` chat-logo--rounded`:``}`,onError:e=>{e.target.src=z?.logoUrl||h}}),(0,U.jsxs)(`div`,{className:`chat-header-text`,children:[R!==`none`&&(0,U.jsx)(`h1`,{className:`chat-tagline`,children:G?.groupName||R&&F||z?.name||D.productName}),(0,U.jsx)(`p`,{className:`chat-intro`,children:G?`${G.participants.length} participants`:z?.tagline||``}),(0,U.jsx)(`p`,{className:`chat-ai-indicator`,children:`AI assistant`})]}),P===`chat`&&!m&&(0,U.jsxs)(`div`,{className:`chat-header-actions`,children:[(0,U.jsx)(`button`,{className:`chat-header-action`,onClick:ce,disabled:X,title:`New conversation`,"aria-label":`New conversation`,children:(0,U.jsx)(j,{size:16})}),(0,U.jsx)(`button`,{className:`chat-header-action`,onClick:y,title:`Select messages`,"aria-label":`Select messages`,children:(0,U.jsx)(s,{size:16})})]})]}),P===`loading`&&(0,U.jsx)(`div`,{className:`gate-wrap`,children:(0,U.jsx)(`div`,{className:`gate-loading`,children:(0,U.jsx)(`span`,{className:`spinner`})})}),P===`auth-required`&&(0,U.jsx)(re,{gateState:T.gateState,setGateState:T.setGateState,grantInfo:T.grantInfo,setGrantInfo:T.setGrantInfo,gateSessionKeyRef:T.gateSessionKeyRef,resolvedSlugRef:T.resolvedSlugRef,onAuthenticated:T.enterChat}),P===`chat`&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(ie,{messages:J,isStreaming:X,sessionError:M,selectionMode:m,selectedItems:g,toggleSelectItem:b,onComponentSubmit:se,remainingSuggestions:l,onSuggestionClick:$,isAtBottom:d,setIsAtBottom:f,isGroup:!!G,sessionId:E}),m?(0,U.jsx)(ae,{selectedItems:g,messages:J,isStreaming:X,copySelected:S,selectAll:x,exitSelection:v,showCopyToast:C}):(0,U.jsx)(oe,{input:e,setInput:t,isStreaming:X,pendingFiles:n,setPendingFiles:r,attachError:o,setAttachError:c,isDragOver:i,setIsDragOver:a,inputRef:p,onSubmit:le,onSendVoiceNote:e=>{t(``),r([]),c(null),Z(`[Voice note]`,{files:[e]})}})]}),_&&(0,U.jsx)(`span`,{className:`copy-toast${_===`failed`?` copy-toast-failed`:``}`,children:_===`copied`?`Copied`:`Copy failed`}),(0,U.jsxs)(`footer`,{className:`chat-footer`,children:[(0,U.jsxs)(`a`,{href:k,children:[D.domain,` `,`↗`]}),E&&(0,U.jsxs)(`span`,{style:{opacity:.35,fontSize:`10px`,fontFamily:`monospace`,marginLeft:`1rem`},children:[`Conversation · `,E.slice(0,8)]})]})]})}(0,M.createRoot)(document.getElementById(`root`)).render((0,U.jsx)(J,{}));
|
|
5
|
+
`)}N.useEffect(()=>{if(!l)return;let e=e=>{e.target.closest(`.selection-copy-wrap`)||u(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[l]);function g(){d.current!==null&&(clearTimeout(d.current),d.current=null)}let _=[...t].sort((e,t)=>e.timestamp-t.timestamp),v=_.reduce((e,t,r)=>(t.hidden||n&&r===_.length-1||e.push(`${t.timestamp}_${t.role}`),e),[]),y=v.length>0&&v.every(t=>e.has(t));return(0,U.jsx)(`div`,{className:`chat-input-area`,children:(0,U.jsxs)(`div`,{className:`selection-bar`,children:[(0,U.jsxs)(`div`,{className:`selection-bar-left`,children:[(0,U.jsxs)(`button`,{type:`button`,className:`selection-select-all`,onClick:()=>i(v),disabled:v.length===0,"aria-label":y?`Deselect all`:`Select all`,title:y?`Deselect all`:`Select all`,children:[(0,U.jsx)(s,{size:16}),(0,U.jsx)(`span`,{children:y?`Deselect all`:`Select all`})]}),(0,U.jsxs)(`span`,{className:`selection-count`,children:[e.size,` Selected`]})]}),(0,U.jsxs)(`div`,{className:`selection-copy-wrap`,children:[(0,U.jsxs)(`button`,{type:`button`,className:`selection-copy`,onPointerDown:()=>{if(l){u(!1);return}f.current=!1,d.current=setTimeout(()=>{f.current=!0,u(!0),d.current=null},500)},onPointerUp:g,onPointerLeave:g,onPointerCancel:g,onClick:async()=>{f.current||await r(p,m)},children:[(0,U.jsx)(c,{size:18}),(0,U.jsx)(`span`,{children:`Copy`})]}),l&&(0,U.jsx)(`div`,{className:`copy-menu`,children:(0,U.jsx)(`button`,{type:`button`,className:`copy-menu-item`,onClick:async()=>{let e=h();e&&o(await D(e)),a()},children:`Copy all`})})]}),(0,U.jsx)(`button`,{type:`button`,className:`selection-cancel`,onClick:a,children:`Cancel`})]})})}function oe({input:e,setInput:t,isStreaming:n,pendingFiles:r,setPendingFiles:i,attachError:o,setAttachError:s,isDragOver:c,setIsDragOver:l,inputRef:f,onSubmit:m,onSendVoiceNote:h}){let g=(0,N.useRef)(null),x=w(),C=x.state===`recording`||x.state===`paused`||x.state===`sending`,T=!C&&!n&&!e.trim()&&r.length===0;async function D(){let e=await x.send();if(!e)return;let t=e.type===`audio/ogg`?`.ogg`:e.type===`audio/mp4`?`.m4a`:`.webm`;h(new File([e],`voice-note${t}`,{type:e.type}))}function O(e){s(null);let t=e.map(p),n=t.find(e=>!E(e.type,F));if(n){s(`Unsupported file type: "${n.type}". Supported: images, PDF, plain text, markdown, CSV, calendar, voice notes.`);return}let r=t.find(e=>e.size>I);if(r){s(`"${r.name}" exceeds the 50 MB limit.`);return}i(e=>[...e,...t].slice(0,5))}function k(e){e.preventDefault(),l(!0)}function A(){l(!1)}function j(e){e.preventDefault(),l(!1),O([...e.dataTransfer.files])}return(0,U.jsxs)(`div`,{className:`chat-input-area`,children:[(0,U.jsx)(`input`,{ref:g,type:`file`,multiple:!0,accept:P,style:{display:`none`},onChange:e=>{e.target.files&&O([...e.target.files]),e.target.value=``}}),r.length>0&&(0,U.jsx)(`div`,{className:`attachment-strip`,children:r.map((e,t)=>(0,U.jsxs)(`div`,{className:`attachment-chip`,children:[e.type.startsWith(`image/`)?(0,U.jsx)(`img`,{src:URL.createObjectURL(e),alt:e.name,className:`attachment-chip-thumb`}):e.type.startsWith(`audio/`)?(0,U.jsx)(y,{size:14}):e.type===`application/pdf`?(0,U.jsx)(u,{size:14}):(0,U.jsx)(d,{size:14}),(0,U.jsx)(`span`,{className:`attachment-chip-name`,children:e.name}),(0,U.jsx)(`button`,{type:`button`,className:`attachment-chip-remove`,onClick:()=>i(e=>e.filter((e,n)=>n!==t)),"aria-label":`Remove ${e.name}`,children:`×`})]},t))}),o&&(0,U.jsx)(`p`,{className:`attach-error`,children:o}),x.state===`error`&&x.errorMessage&&(0,U.jsxs)(`p`,{className:`voice-error`,role:`alert`,children:[(0,U.jsx)(y,{size:14}),x.errorMessage]}),(0,U.jsx)(v,{inputRef:f}),C?(0,U.jsx)(`div`,{className:`chat-form voice-active`,children:(0,U.jsx)(b,{state:x.state,elapsedSeconds:x.elapsedSeconds,waveform:x.waveform,onTogglePause:x.togglePause,onDiscard:x.discard,onSend:D})}):(0,U.jsxs)(`form`,{className:`chat-form${c?` drag-over`:``}`,onSubmit:m,onDragOver:k,onDragLeave:A,onDrop:j,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&&O(n)},children:[(0,U.jsx)(_,{variant:`icon`,type:`button`,onClick:()=>g.current?.click(),disabled:n,"aria-label":`Attach file`,children:(0,U.jsx)(a,{size:14})}),(0,U.jsx)(S,{ref:f,value:e,onChange:t}),T?(0,U.jsx)(_,{variant:`send`,type:`button`,onClick:x.start,disabled:n,"aria-label":`Record voice note`,children:(0,U.jsx)(y,{size:14})}):(0,U.jsx)(_,{variant:`send`,type:`submit`,disabled:n||!e.trim()&&r.length===0,"aria-label":`Send message`,children:(0,U.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,U.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,U.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]})]})}var q=[];function J(){let[e,t]=(0,N.useState)(``),[n,r]=(0,N.useState)([]),[i,a]=(0,N.useState)(!1),[o,c]=(0,N.useState)(null),[l,u]=(0,N.useState)(q),[d,p]=(0,N.useState)(!0),m=(0,N.useRef)(null),{selectionMode:g,selectedItems:_,copyToast:v,exitSelection:y,enterSelection:b,toggleSelectItem:x,selectAll:S,copySelected:C,showCopyToast:w}=f(),T=(0,N.useRef)(()=>{}),E=ee((0,N.useCallback)(e=>{T.current(e)},[])),{sessionId:D,sessionKeyRef:A,sessionError:M,pageState:P,agentDisplayName:F,agentImage:I,agentImageShape:L,showAgentName:R,branding:z,ensureSession:B,startNewSession:V,resumedRef:H,resumeMessagesRef:W,groupContext:G,groupSlug:K}=E,{messages:J,setMessages:Y,isStreaming:X,sendMessage:Z,sendGreeting:Q,handleComponentSubmit:se}=te({sessionKeyRef:A,ensureSession:B,sessionError:M,pageState:P,inputRef:m});(0,N.useEffect)(()=>{T.current=Q},[Q]),ne({sessionKeyRef:A,groupSlug:K,isStreaming:X,setMessages:Y}),(0,N.useEffect)(()=>{let e=!1;return(async()=>{let t=await B();if(!e&&t){if(H.current&&W.current&&W.current.length>0){let e=W.current.map(e=>({role:e.role,content:e.content,timestamp:e.timestamp}));e.sort((e,t)=>e.timestamp-t.timestamp),Y(e),W.current=null;return}Q(t)}})(),()=>{e=!0}},[]),(0,N.useEffect)(()=>{P===`chat`&&m.current?.focus()},[P]),(0,N.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,N.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,N.useEffect)(()=>{function e(e){e.key===`Escape`&&g&&y()}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[g,y]);function ce(){X||(Y([]),u(q),V())}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)),u(t=>t.filter(t=>t!==e)),p(!0);let i=[...n];t(``),r([]),c(null),Z(e,{files:i})}function le(t){t.preventDefault(),$(e.trim()),m.current?.resetHeight()}return(0,U.jsxs)(`div`,{className:`chat-page`,children:[(0,U.jsxs)(`header`,{className:`chat-header`,children:[(0,U.jsx)(`img`,{src:I||z?.logoUrl||O,alt:z?.name||k.productName,className:`chat-logo${I&&L===`circle`?` chat-logo--circle`:``}${I&&L===`rounded`?` chat-logo--rounded`:``}`,onError:e=>{e.target.src=z?.logoUrl||O}}),(0,U.jsxs)(`div`,{className:`chat-header-text`,children:[R!==`none`&&(0,U.jsx)(`h1`,{className:`chat-tagline`,children:G?.groupName||R&&F||z?.name||k.productName}),(0,U.jsx)(`p`,{className:`chat-intro`,children:G?`${G.participants.length} participants`:z?.tagline||``}),(0,U.jsx)(`p`,{className:`chat-ai-indicator`,children:`AI assistant`})]}),P===`chat`&&!g&&(0,U.jsxs)(`div`,{className:`chat-header-actions`,children:[(0,U.jsx)(`button`,{className:`chat-header-action`,onClick:ce,disabled:X,title:`New conversation`,"aria-label":`New conversation`,children:(0,U.jsx)(j,{size:16})}),(0,U.jsx)(`button`,{className:`chat-header-action`,onClick:b,title:`Select messages`,"aria-label":`Select messages`,children:(0,U.jsx)(s,{size:16})})]})]}),P===`loading`&&(0,U.jsx)(`div`,{className:`gate-wrap`,children:(0,U.jsx)(`div`,{className:`gate-loading`,children:(0,U.jsx)(`span`,{className:`spinner`})})}),P===`auth-required`&&(0,U.jsx)(re,{gateState:E.gateState,setGateState:E.setGateState,grantInfo:E.grantInfo,setGrantInfo:E.setGrantInfo,gateSessionKeyRef:E.gateSessionKeyRef,resolvedSlugRef:E.resolvedSlugRef,onAuthenticated:E.enterChat}),P===`chat`&&(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(ie,{messages:J,isStreaming:X,sessionError:M,selectionMode:g,selectedItems:_,toggleSelectItem:x,onComponentSubmit:se,remainingSuggestions:l,onSuggestionClick:$,isAtBottom:d,setIsAtBottom:p,isGroup:!!G,sessionId:D}),g?(0,U.jsx)(ae,{selectedItems:_,messages:J,isStreaming:X,copySelected:C,selectAll:S,exitSelection:y,showCopyToast:w}):(0,U.jsx)(oe,{input:e,setInput:t,isStreaming:X,pendingFiles:n,setPendingFiles:r,attachError:o,setAttachError:c,isDragOver:i,setIsDragOver:a,inputRef:m,onSubmit:le,onSendVoiceNote:e=>{t(``),r([]),c(null),Z(`[Voice note]`,{files:[e]})}})]}),v&&(0,U.jsx)(`span`,{className:`copy-toast${v===`failed`?` copy-toast-failed`:``}`,children:v===`copied`?`Copied`:`Copy failed`}),(0,U.jsxs)(`footer`,{className:`chat-footer`,children:[(0,U.jsxs)(`a`,{href:h,children:[k.domain,` `,`↗`]}),D&&(0,U.jsxs)(`span`,{style:{opacity:.35,fontSize:`10px`,fontFamily:`monospace`,marginLeft:`1rem`},children:[`Conversation · `,D.slice(0,8)]})]})]})}(0,M.createRoot)(document.getElementById(`root`)).render((0,U.jsx)(J,{}));
|
package/payload/server/public/assets/{useVoiceRecorder-B_zVS4Oe.js → useVoiceRecorder-CR8gcELb.js}
RENAMED
|
@@ -33,4 +33,4 @@ import{o as e,r as t,t as n}from"./chunk-DD-I1_y5.js";import{n as r,o as i,r as
|
|
|
33
33
|
`,...a.current()});return/^[\t ]/.test(l)&&(l=Ps(l.charCodeAt(0))+l.slice(1)),l=l?o+` `+l:o,n.options.closeAtx&&(l+=` `+o),c(),s(),l}Bs.peek=Vs;function Bs(e){return e.value||``}function Vs(){return`<`}Hs.peek=Us;function Hs(e,t,n,r){let i=js(n),a=i===`"`?`Quote`:`Apostrophe`,o=n.enter(`image`),s=n.enter(`label`),c=n.createTracker(r),l=c.move(`![`);return l+=c.move(n.safe(e.alt,{before:l,after:`]`,...c.current()})),l+=c.move(`](`),s(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(s=n.enter(`destinationLiteral`),l+=c.move(`<`),l+=c.move(n.safe(e.url,{before:l,after:`>`,...c.current()})),l+=c.move(`>`)):(s=n.enter(`destinationRaw`),l+=c.move(n.safe(e.url,{before:l,after:e.title?` `:`)`,...c.current()}))),s(),e.title&&(s=n.enter(`title${a}`),l+=c.move(` `+i),l+=c.move(n.safe(e.title,{before:l,after:i,...c.current()})),l+=c.move(i),s()),l+=c.move(`)`),o(),l}function Us(){return`!`}Ws.peek=Gs;function Ws(e,t,n,r){let i=e.referenceType,a=n.enter(`imageReference`),o=n.enter(`label`),s=n.createTracker(r),c=s.move(`![`),l=n.safe(e.alt,{before:c,after:`]`,...s.current()});c+=s.move(l+`][`),o();let u=n.stack;n.stack=[],o=n.enter(`reference`);let d=n.safe(n.associationId(e),{before:c,after:`]`,...s.current()});return o(),n.stack=u,a(),i===`full`||!l||l!==d?c+=s.move(d+`]`):i===`shortcut`?c=c.slice(0,-1):c+=s.move(`]`),c}function Gs(){return`!`}Ks.peek=qs;function Ks(e,t,n){let r=e.value||``,i="`",a=-1;for(;RegExp("(^|[^`])"+i+"([^`]|$)").test(r);)i+="`";for(/[^ \r\n]/.test(r)&&(/^[ \r\n]/.test(r)&&/[ \r\n]$/.test(r)||/^`|`$/.test(r))&&(r=` `+r+` `);++a<n.unsafe.length;){let e=n.unsafe[a],t=n.compilePattern(e),i;if(e.atBreak)for(;i=t.exec(r);){let e=i.index;r.charCodeAt(e)===10&&r.charCodeAt(e-1)===13&&e--,r=r.slice(0,e)+` `+r.slice(i.index+1)}}return i+r+i}function qs(){return"`"}function Js(e,t){let n=jt(e);return!!(!t.options.resourceLink&&e.url&&!e.title&&e.children&&e.children.length===1&&e.children[0].type===`text`&&(n===e.url||`mailto:`+n===e.url)&&/^[a-z][a-z+.-]+:/i.test(e.url)&&!/[\0- <>\u007F]/.test(e.url))}Ys.peek=Xs;function Ys(e,t,n,r){let i=js(n),a=i===`"`?`Quote`:`Apostrophe`,o=n.createTracker(r),s,c;if(Js(e,n)){let t=n.stack;n.stack=[],s=n.enter(`autolink`);let r=o.move(`<`);return r+=o.move(n.containerPhrasing(e,{before:r,after:`>`,...o.current()})),r+=o.move(`>`),s(),n.stack=t,r}s=n.enter(`link`),c=n.enter(`label`);let l=o.move(`[`);return l+=o.move(n.containerPhrasing(e,{before:l,after:`](`,...o.current()})),l+=o.move(`](`),c(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(c=n.enter(`destinationLiteral`),l+=o.move(`<`),l+=o.move(n.safe(e.url,{before:l,after:`>`,...o.current()})),l+=o.move(`>`)):(c=n.enter(`destinationRaw`),l+=o.move(n.safe(e.url,{before:l,after:e.title?` `:`)`,...o.current()}))),c(),e.title&&(c=n.enter(`title${a}`),l+=o.move(` `+i),l+=o.move(n.safe(e.title,{before:l,after:i,...o.current()})),l+=o.move(i),c()),l+=o.move(`)`),s(),l}function Xs(e,t,n){return Js(e,n)?`<`:`[`}Zs.peek=Qs;function Zs(e,t,n,r){let i=e.referenceType,a=n.enter(`linkReference`),o=n.enter(`label`),s=n.createTracker(r),c=s.move(`[`),l=n.containerPhrasing(e,{before:c,after:`]`,...s.current()});c+=s.move(l+`][`),o();let u=n.stack;n.stack=[],o=n.enter(`reference`);let d=n.safe(n.associationId(e),{before:c,after:`]`,...s.current()});return o(),n.stack=u,a(),i===`full`||!l||l!==d?c+=s.move(d+`]`):i===`shortcut`?c=c.slice(0,-1):c+=s.move(`]`),c}function Qs(){return`[`}function $s(e){let t=e.options.bullet||`*`;if(t!==`*`&&t!==`+`&&t!==`-`)throw Error("Cannot serialize items with `"+t+"` for `options.bullet`, expected `*`, `+`, or `-`");return t}function ec(e){let t=$s(e),n=e.options.bulletOther;if(!n)return t===`*`?`-`:`*`;if(n!==`*`&&n!==`+`&&n!==`-`)throw Error("Cannot serialize items with `"+n+"` for `options.bulletOther`, expected `*`, `+`, or `-`");if(n===t)throw Error("Expected `bullet` (`"+t+"`) and `bulletOther` (`"+n+"`) to be different");return n}function tc(e){let t=e.options.bulletOrdered||`.`;if(t!==`.`&&t!==`)`)throw Error("Cannot serialize items with `"+t+"` for `options.bulletOrdered`, expected `.` or `)`");return t}function nc(e){let t=e.options.rule||`*`;if(t!==`*`&&t!==`-`&&t!==`_`)throw Error("Cannot serialize rules with `"+t+"` for `options.rule`, expected `*`, `-`, or `_`");return t}function rc(e,t,n,r){let i=n.enter(`list`),a=n.bulletCurrent,o=e.ordered?tc(n):$s(n),s=e.ordered?o===`.`?`)`:`.`:ec(n),c=t&&n.bulletLastUsed?o===n.bulletLastUsed:!1;if(!e.ordered){let t=e.children?e.children[0]:void 0;if((o===`*`||o===`-`)&&t&&(!t.children||!t.children[0])&&n.stack[n.stack.length-1]===`list`&&n.stack[n.stack.length-2]===`listItem`&&n.stack[n.stack.length-3]===`list`&&n.stack[n.stack.length-4]===`listItem`&&n.indexStack[n.indexStack.length-1]===0&&n.indexStack[n.indexStack.length-2]===0&&n.indexStack[n.indexStack.length-3]===0&&(c=!0),nc(n)===o&&t){let t=-1;for(;++t<e.children.length;){let n=e.children[t];if(n&&n.type===`listItem`&&n.children&&n.children[0]&&n.children[0].type===`thematicBreak`){c=!0;break}}}}c&&(o=s),n.bulletCurrent=o;let l=n.containerFlow(e,r);return n.bulletLastUsed=o,n.bulletCurrent=a,i(),l}function ic(e){let t=e.options.listItemIndent||`one`;if(t!==`tab`&&t!==`one`&&t!==`mixed`)throw Error("Cannot serialize items with `"+t+"` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`");return t}function ac(e,t,n,r){let i=ic(n),a=n.bulletCurrent||$s(n);t&&t.type===`list`&&t.ordered&&(a=(typeof t.start==`number`&&t.start>-1?t.start:1)+(n.options.incrementListMarker===!1?0:t.children.indexOf(e))+a);let o=a.length+1;(i===`tab`||i===`mixed`&&(t&&t.type===`list`&&t.spread||e.spread))&&(o=Math.ceil(o/4)*4);let s=n.createTracker(r);s.move(a+` `.repeat(o-a.length)),s.shift(o);let c=n.enter(`listItem`),l=n.indentLines(n.containerFlow(e,s.current()),u);return c(),l;function u(e,t,n){return t?(n?``:` `.repeat(o))+e:(n?a:a+` `.repeat(o-a.length))+e}}function oc(e,t,n,r){let i=n.enter(`paragraph`),a=n.enter(`phrasing`),o=n.containerPhrasing(e,r);return a(),i(),o}var sc=ma([`break`,`delete`,`emphasis`,`footnote`,`footnoteReference`,`image`,`imageReference`,`inlineCode`,`inlineMath`,`link`,`linkReference`,`mdxJsxTextElement`,`mdxTextExpression`,`strong`,`text`,`textDirective`]);function cc(e,t,n,r){return(e.children.some(function(e){return sc(e)})?n.containerPhrasing:n.containerFlow).call(n,e,r)}function lc(e){let t=e.options.strong||`*`;if(t!==`*`&&t!==`_`)throw Error("Cannot serialize strong with `"+t+"` for `options.strong`, expected `*`, or `_`");return t}uc.peek=dc;function uc(e,t,n,r){let i=lc(n),a=n.enter(`strong`),o=n.createTracker(r),s=o.move(i+i),c=o.move(n.containerPhrasing(e,{after:i,before:s,...o.current()})),l=c.charCodeAt(0),u=Fs(r.before.charCodeAt(r.before.length-1),l,i);u.inside&&(c=Ps(l)+c.slice(1));let d=c.charCodeAt(c.length-1),f=Fs(r.after.charCodeAt(0),d,i);f.inside&&(c=c.slice(0,-1)+Ps(d));let p=o.move(i+i);return a(),n.attentionEncodeSurroundingInfo={after:f.outside,before:u.outside},s+c+p}function dc(e,t,n){return n.options.strong||`*`}function fc(e,t,n,r){return n.safe(e.value,r)}function pc(e){let t=e.options.ruleRepetition||3;if(t<3)throw Error("Cannot serialize rules with repetition `"+t+"` for `options.ruleRepetition`, expected `3` or more");return t}function mc(e,t,n){let r=(nc(n)+(n.options.ruleSpaces?` `:``)).repeat(pc(n));return n.options.ruleSpaces?r.slice(0,-1):r}var hc={blockquote:xs,break:Ts,code:ks,definition:Ms,emphasis:Is,hardBreak:Ts,heading:zs,html:Bs,image:Hs,imageReference:Ws,inlineCode:Ks,link:Ys,linkReference:Zs,list:rc,listItem:ac,paragraph:oc,root:cc,strong:uc,text:fc,thematicBreak:mc};function gc(){return{enter:{table:_c,tableData:xc,tableHeader:xc,tableRow:yc},exit:{codeText:Sc,table:vc,tableData:bc,tableHeader:bc,tableRow:bc}}}function _c(e){let t=e._align;this.enter({type:`table`,align:t.map(function(e){return e===`none`?null:e}),children:[]},e),this.data.inTable=!0}function vc(e){this.exit(e),this.data.inTable=void 0}function yc(e){this.enter({type:`tableRow`,children:[]},e)}function bc(e){this.exit(e)}function xc(e){this.enter({type:`tableCell`,children:[]},e)}function Sc(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,Cc));let n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function Cc(e,t){return t===`|`?t:e}function wc(e){let t=e||{},n=t.tableCellPadding,r=t.tablePipeAlign,i=t.stringLength,a=n?` `:`|`;return{unsafe:[{character:`\r`,inConstruct:`tableCell`},{character:`
|
|
34
34
|
`,inConstruct:`tableCell`},{atBreak:!0,character:`|`,after:`[ :-]`},{character:`|`,inConstruct:`tableCell`},{atBreak:!0,character:`:`,after:`-`},{atBreak:!0,character:`-`,after:`[:|-]`}],handlers:{inlineCode:f,table:o,tableCell:c,tableRow:s}};function o(e,t,n,r){return l(u(e,n,r),e.align)}function s(e,t,n,r){let i=l([d(e,n,r)]);return i.slice(0,i.indexOf(`
|
|
35
35
|
`))}function c(e,t,n,r){let i=n.enter(`tableCell`),o=n.enter(`phrasing`),s=n.containerPhrasing(e,{...r,before:a,after:a});return o(),i(),s}function l(e,t){return vs(e,{align:t,alignDelimiters:r,padding:n,stringLength:i})}function u(e,t,n){let r=e.children,i=-1,a=[],o=t.enter(`table`);for(;++i<r.length;)a[i]=d(r[i],t,n);return o(),a}function d(e,t,n){let r=e.children,i=-1,a=[],o=t.enter(`tableRow`);for(;++i<r.length;)a[i]=c(r[i],e,t,n);return o(),a}function f(e,t,n){let r=hc.inlineCode(e,t,n);return n.stack.includes(`tableCell`)&&(r=r.replace(/\|/g,`\\$&`)),r}}function Tc(){return{exit:{taskListCheckValueChecked:Dc,taskListCheckValueUnchecked:Dc,paragraph:Oc}}}function Ec(){return{unsafe:[{atBreak:!0,character:`-`,after:`[:|-]`}],handlers:{listItem:kc}}}function Dc(e){let t=this.stack[this.stack.length-2];t.type,t.checked=e.type===`taskListCheckValueChecked`}function Oc(e){let t=this.stack[this.stack.length-2];if(t&&t.type===`listItem`&&typeof t.checked==`boolean`){let e=this.stack[this.stack.length-1];e.type;let n=e.children[0];if(n&&n.type===`text`){let r=t.children,i=-1,a;for(;++i<r.length;){let e=r[i];if(e.type===`paragraph`){a=e;break}}a===e&&(n.value=n.value.slice(1),n.value.length===0?e.children.shift():e.position&&n.position&&typeof n.position.start.offset==`number`&&(n.position.start.column++,n.position.start.offset++,e.position.start=Object.assign({},n.position.start)))}}this.exit(e)}function kc(e,t,n,r){let i=e.children[0],a=typeof e.checked==`boolean`&&i&&i.type===`paragraph`,o=`[`+(e.checked?`x`:` `)+`] `,s=n.createTracker(r);a&&s.move(o);let c=hc.listItem(e,t,n,{...r,...s.current()});return a&&(c=c.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,l)),c;function l(e){return e+o}}function Ac(){return[Io(),os(),ds(),gc(),Tc()]}function jc(e){return{extensions:[Lo(),ss(e),fs(),wc(e),Ec()]}}var Mc={tokenize:Wc,partial:!0},Nc={tokenize:Gc,partial:!0},Pc={tokenize:Kc,partial:!0},Fc={tokenize:qc,partial:!0},Ic={tokenize:Jc,partial:!0},Lc={name:`wwwAutolink`,tokenize:Hc,previous:Yc},Rc={name:`protocolAutolink`,tokenize:Uc,previous:Xc},Q={name:`emailAutolink`,tokenize:Vc,previous:Zc},$={};function zc(){return{text:$}}for(var Bc=48;Bc<123;)$[Bc]=Q,Bc++,Bc===58?Bc=65:Bc===91&&(Bc=97);$[43]=Q,$[45]=Q,$[46]=Q,$[95]=Q,$[72]=[Q,Rc],$[104]=[Q,Rc],$[87]=[Q,Lc],$[119]=[Q,Lc];function Vc(e,t,n){let r=this,i,a;return o;function o(t){return!Qc(t)||!Zc.call(r,r.previous)||$c(r.events)?n(t):(e.enter(`literalAutolink`),e.enter(`literalAutolinkEmail`),s(t))}function s(t){return Qc(t)?(e.consume(t),s):t===64?(e.consume(t),c):n(t)}function c(t){return t===46?e.check(Ic,u,l)(t):t===45||t===95||W(t)?(a=!0,e.consume(t),c):u(t)}function l(t){return e.consume(t),i=!0,c}function u(o){return a&&i&&U(r.previous)?(e.exit(`literalAutolinkEmail`),e.exit(`literalAutolink`),t(o)):n(o)}}function Hc(e,t,n){let r=this;return i;function i(t){return t!==87&&t!==119||!Yc.call(r,r.previous)||$c(r.events)?n(t):(e.enter(`literalAutolink`),e.enter(`literalAutolinkWww`),e.check(Mc,e.attempt(Nc,e.attempt(Pc,a),n),n)(t))}function a(n){return e.exit(`literalAutolinkWww`),e.exit(`literalAutolink`),t(n)}}function Uc(e,t,n){let r=this,i=``,a=!1;return o;function o(t){return(t===72||t===104)&&Xc.call(r,r.previous)&&!$c(r.events)?(e.enter(`literalAutolink`),e.enter(`literalAutolinkHttp`),i+=String.fromCodePoint(t),e.consume(t),s):n(t)}function s(t){if(U(t)&&i.length<5)return i+=String.fromCodePoint(t),e.consume(t),s;if(t===58){let n=i.toLowerCase();if(n===`http`||n===`https`)return e.consume(t),c}return n(t)}function c(t){return t===47?(e.consume(t),a?l:(a=!0,c)):n(t)}function l(t){return t===null||Ut(t)||K(t)||Jt(t)||qt(t)?n(t):e.attempt(Nc,e.attempt(Pc,u),n)(t)}function u(n){return e.exit(`literalAutolinkHttp`),e.exit(`literalAutolink`),t(n)}}function Wc(e,t,n){let r=0;return i;function i(t){return(t===87||t===119)&&r<3?(r++,e.consume(t),i):t===46&&r===3?(e.consume(t),a):n(t)}function a(e){return e===null?n(e):t(e)}}function Gc(e,t,n){let r,i,a;return o;function o(t){return t===46||t===95?e.check(Fc,c,s)(t):t===null||K(t)||Jt(t)||t!==45&&qt(t)?c(t):(a=!0,e.consume(t),o)}function s(t){return t===95?r=!0:(i=r,r=void 0),e.consume(t),o}function c(e){return i||r||!a?n(e):t(e)}}function Kc(e,t){let n=0,r=0;return i;function i(o){return o===40?(n++,e.consume(o),i):o===41&&r<n?a(o):o===33||o===34||o===38||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===60||o===63||o===93||o===95||o===126?e.check(Fc,t,a)(o):o===null||K(o)||Jt(o)?t(o):(e.consume(o),i)}function a(t){return t===41&&r++,e.consume(t),i}}function qc(e,t,n){return r;function r(o){return o===33||o===34||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===63||o===95||o===126?(e.consume(o),r):o===38?(e.consume(o),a):o===93?(e.consume(o),i):o===60||o===null||K(o)||Jt(o)?t(o):n(o)}function i(e){return e===null||e===40||e===91||K(e)||Jt(e)?t(e):r(e)}function a(e){return U(e)?o(e):n(e)}function o(t){return t===59?(e.consume(t),r):U(t)?(e.consume(t),o):n(t)}}function Jc(e,t,n){return r;function r(t){return e.consume(t),i}function i(e){return W(e)?n(e):t(e)}}function Yc(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||K(e)}function Xc(e){return!U(e)}function Zc(e){return!(e===47||Qc(e))}function Qc(e){return e===43||e===45||e===46||e===95||W(e)}function $c(e){let t=e.length,n=!1;for(;t--;){let r=e[t][1];if((r.type===`labelLink`||r.type===`labelImage`)&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}var el={tokenize:cl,partial:!0};function tl(){return{document:{91:{name:`gfmFootnoteDefinition`,tokenize:al,continuation:{tokenize:ol},exit:sl}},text:{91:{name:`gfmFootnoteCall`,tokenize:il},93:{name:`gfmPotentialFootnoteCall`,add:`after`,tokenize:nl,resolveTo:rl}}}}function nl(e,t,n){let r=this,i=r.events.length,a=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),o;for(;i--;){let e=r.events[i][1];if(e.type===`labelImage`){o=e;break}if(e.type===`gfmFootnoteCall`||e.type===`labelLink`||e.type===`label`||e.type===`image`||e.type===`link`)break}return s;function s(i){if(!o||!o._balanced)return n(i);let s=H(r.sliceSerialize({start:o.end,end:r.now()}));return s.codePointAt(0)!==94||!a.includes(s.slice(1))?n(i):(e.enter(`gfmFootnoteCallLabelMarker`),e.consume(i),e.exit(`gfmFootnoteCallLabelMarker`),t(i))}}function rl(e,t){let n=e.length;for(;n--;)if(e[n][1].type===`labelImage`&&e[n][0]===`enter`){e[n][1];break}e[n+1][1].type=`data`,e[n+3][1].type=`gfmFootnoteCallLabelMarker`;let r={type:`gfmFootnoteCall`,start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:`gfmFootnoteCallMarker`,start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;let a={type:`gfmFootnoteCallString`,start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},o={type:`chunkString`,contentType:`string`,start:Object.assign({},a.start),end:Object.assign({},a.end)},s=[e[n+1],e[n+2],[`enter`,r,t],e[n+3],e[n+4],[`enter`,i,t],[`exit`,i,t],[`enter`,a,t],[`enter`,o,t],[`exit`,o,t],[`exit`,a,t],e[e.length-2],e[e.length-1],[`exit`,r,t]];return e.splice(n,e.length-n+1,...s),e}function il(e,t,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),a=0,o;return s;function s(t){return e.enter(`gfmFootnoteCall`),e.enter(`gfmFootnoteCallLabelMarker`),e.consume(t),e.exit(`gfmFootnoteCallLabelMarker`),c}function c(t){return t===94?(e.enter(`gfmFootnoteCallMarker`),e.consume(t),e.exit(`gfmFootnoteCallMarker`),e.enter(`gfmFootnoteCallString`),e.enter(`chunkString`).contentType=`string`,l):n(t)}function l(s){if(a>999||s===93&&!o||s===null||s===91||K(s))return n(s);if(s===93){e.exit(`chunkString`);let a=e.exit(`gfmFootnoteCallString`);return i.includes(H(r.sliceSerialize(a)))?(e.enter(`gfmFootnoteCallLabelMarker`),e.consume(s),e.exit(`gfmFootnoteCallLabelMarker`),e.exit(`gfmFootnoteCall`),t):n(s)}return K(s)||(o=!0),a++,e.consume(s),s===92?u:l}function u(t){return t===91||t===92||t===93?(e.consume(t),a++,l):l(t)}}function al(e,t,n){let r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]),a,o=0,s;return c;function c(t){return e.enter(`gfmFootnoteDefinition`)._container=!0,e.enter(`gfmFootnoteDefinitionLabel`),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),l}function l(t){return t===94?(e.enter(`gfmFootnoteDefinitionMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionMarker`),e.enter(`gfmFootnoteDefinitionLabelString`),e.enter(`chunkString`).contentType=`string`,u):n(t)}function u(t){if(o>999||t===93&&!s||t===null||t===91||K(t))return n(t);if(t===93){e.exit(`chunkString`);let n=e.exit(`gfmFootnoteDefinitionLabelString`);return a=H(r.sliceSerialize(n)),e.enter(`gfmFootnoteDefinitionLabelMarker`),e.consume(t),e.exit(`gfmFootnoteDefinitionLabelMarker`),e.exit(`gfmFootnoteDefinitionLabel`),f}return K(t)||(s=!0),o++,e.consume(t),t===92?d:u}function d(t){return t===91||t===92||t===93?(e.consume(t),o++,u):u(t)}function f(t){return t===58?(e.enter(`definitionMarker`),e.consume(t),e.exit(`definitionMarker`),i.includes(a)||i.push(a),Y(e,p,`gfmFootnoteDefinitionWhitespace`)):n(t)}function p(e){return t(e)}}function ol(e,t,n){return e.check(dn,t,e.attempt(el,t,n))}function sl(e){e.exit(`gfmFootnoteDefinition`)}function cl(e,t,n){let r=this;return Y(e,i,`gfmFootnoteDefinitionIndent`,5);function i(e){let i=r.events[r.events.length-1];return i&&i[1].type===`gfmFootnoteDefinitionIndent`&&i[2].sliceSerialize(i[1],!0).length===4?t(e):n(e)}}function ll(e){let t=(e||{}).singleTilde,n={name:`strikethrough`,tokenize:i,resolveAll:r};return t??=!0,{text:{126:n},insideSpan:{null:[n]},attentionMarkers:{null:[126]}};function r(e,t){let n=-1;for(;++n<e.length;)if(e[n][0]===`enter`&&e[n][1].type===`strikethroughSequenceTemporary`&&e[n][1]._close){let r=n;for(;r--;)if(e[r][0]===`exit`&&e[r][1].type===`strikethroughSequenceTemporary`&&e[r][1]._open&&e[n][1].end.offset-e[n][1].start.offset===e[r][1].end.offset-e[r][1].start.offset){e[n][1].type=`strikethroughSequence`,e[r][1].type=`strikethroughSequence`;let i={type:`strikethrough`,start:Object.assign({},e[r][1].start),end:Object.assign({},e[n][1].end)},a={type:`strikethroughText`,start:Object.assign({},e[r][1].end),end:Object.assign({},e[n][1].start)},o=[[`enter`,i,t],[`enter`,e[r][1],t],[`exit`,e[r][1],t],[`enter`,a,t]],s=t.parser.constructs.insideSpan.null;s&&B(o,o.length,0,rn(s,e.slice(r+1,n),t)),B(o,o.length,0,[[`exit`,a,t],[`enter`,e[n][1],t],[`exit`,e[n][1],t],[`exit`,i,t]]),B(e,r-1,n-r+3,o),n=r+o.length-2;break}}for(n=-1;++n<e.length;)e[n][1].type===`strikethroughSequenceTemporary`&&(e[n][1].type=`data`);return e}function i(e,n,r){let i=this.previous,a=this.events,o=0;return s;function s(t){return i===126&&a[a.length-1][1].type!==`characterEscape`?r(t):(e.enter(`strikethroughSequenceTemporary`),c(t))}function c(a){let s=nn(i);if(a===126)return o>1?r(a):(e.consume(a),o++,c);if(o<2&&!t)return r(a);let l=e.exit(`strikethroughSequenceTemporary`),u=nn(a);return l._open=!u||u===2&&!!s,l._close=!s||s===2&&!!u,n(a)}}}var ul=class{constructor(){this.map=[]}add(e,t,n){dl(this,e,t,n)}consume(e){if(this.map.sort(function(e,t){return e[0]-t[0]}),this.map.length===0)return;let t=this.map.length,n=[];for(;t>0;)--t,n.push(e.slice(this.map[t][0]+this.map[t][1]),this.map[t][2]),e.length=this.map[t][0];n.push(e.slice()),e.length=0;let r=n.pop();for(;r;){for(let t of r)e.push(t);r=n.pop()}this.map.length=0}};function dl(e,t,n,r){let i=0;if(!(n===0&&r.length===0)){for(;i<e.map.length;){if(e.map[i][0]===t){e.map[i][1]+=n,e.map[i][2].push(...r);return}i+=1}e.map.push([t,n,r])}}function fl(e,t){let n=!1,r=[];for(;t<e.length;){let i=e[t];if(n){if(i[0]===`enter`)i[1].type===`tableContent`&&r.push(e[t+1][1].type===`tableDelimiterMarker`?`left`:`none`);else if(i[1].type===`tableContent`){if(e[t-1][1].type===`tableDelimiterMarker`){let e=r.length-1;r[e]=r[e]===`left`?`center`:`right`}}else if(i[1].type===`tableDelimiterRow`)break}else i[0]===`enter`&&i[1].type===`tableDelimiterRow`&&(n=!0);t+=1}return r}function pl(){return{flow:{null:{name:`table`,tokenize:ml,resolveAll:hl}}}}function ml(e,t,n){let r=this,i=0,a=0,o;return s;function s(e){let t=r.events.length-1;for(;t>-1;){let e=r.events[t][1].type;if(e===`lineEnding`||e===`linePrefix`)t--;else break}let i=t>-1?r.events[t][1].type:null,a=i===`tableHead`||i===`tableRow`?S:c;return a===S&&r.parser.lazy[r.now().line]?n(e):a(e)}function c(t){return e.enter(`tableHead`),e.enter(`tableRow`),l(t)}function l(e){return e===124?u(e):(o=!0,a+=1,u(e))}function u(t){return t===null?n(t):G(t)?a>1?(a=0,r.interrupt=!0,e.exit(`tableRow`),e.enter(`lineEnding`),e.consume(t),e.exit(`lineEnding`),p):n(t):q(t)?Y(e,u,`whitespace`)(t):(a+=1,o&&(o=!1,i+=1),t===124?(e.enter(`tableCellDivider`),e.consume(t),e.exit(`tableCellDivider`),o=!0,u):(e.enter(`data`),d(t)))}function d(t){return t===null||t===124||K(t)?(e.exit(`data`),u(t)):(e.consume(t),t===92?f:d)}function f(t){return t===92||t===124?(e.consume(t),d):d(t)}function p(t){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(t):(e.enter(`tableDelimiterRow`),o=!1,q(t)?Y(e,m,`linePrefix`,r.parser.constructs.disable.null.includes(`codeIndented`)?void 0:4)(t):m(t))}function m(t){return t===45||t===58?g(t):t===124?(o=!0,e.enter(`tableCellDivider`),e.consume(t),e.exit(`tableCellDivider`),h):x(t)}function h(t){return q(t)?Y(e,g,`whitespace`)(t):g(t)}function g(t){return t===58?(a+=1,o=!0,e.enter(`tableDelimiterMarker`),e.consume(t),e.exit(`tableDelimiterMarker`),_):t===45?(a+=1,_(t)):t===null||G(t)?b(t):x(t)}function _(t){return t===45?(e.enter(`tableDelimiterFiller`),v(t)):x(t)}function v(t){return t===45?(e.consume(t),v):t===58?(o=!0,e.exit(`tableDelimiterFiller`),e.enter(`tableDelimiterMarker`),e.consume(t),e.exit(`tableDelimiterMarker`),y):(e.exit(`tableDelimiterFiller`),y(t))}function y(t){return q(t)?Y(e,b,`whitespace`)(t):b(t)}function b(n){return n===124?m(n):n===null||G(n)?!o||i!==a?x(n):(e.exit(`tableDelimiterRow`),e.exit(`tableHead`),t(n)):x(n)}function x(e){return n(e)}function S(t){return e.enter(`tableRow`),C(t)}function C(n){return n===124?(e.enter(`tableCellDivider`),e.consume(n),e.exit(`tableCellDivider`),C):n===null||G(n)?(e.exit(`tableRow`),t(n)):q(n)?Y(e,C,`whitespace`)(n):(e.enter(`data`),w(n))}function w(t){return t===null||t===124||K(t)?(e.exit(`data`),C(t)):(e.consume(t),t===92?T:w)}function T(t){return t===92||t===124?(e.consume(t),w):w(t)}}function hl(e,t){let n=-1,r=!0,i=0,a=[0,0,0,0],o=[0,0,0,0],s=!1,c=0,l,u,d,f=new ul;for(;++n<e.length;){let p=e[n],m=p[1];p[0]===`enter`?m.type===`tableHead`?(s=!1,c!==0&&(_l(f,t,c,l,u),u=void 0,c=0),l={type:`table`,start:Object.assign({},m.start),end:Object.assign({},m.end)},f.add(n,0,[[`enter`,l,t]])):m.type===`tableRow`||m.type===`tableDelimiterRow`?(r=!0,d=void 0,a=[0,0,0,0],o=[0,n+1,0,0],s&&(s=!1,u={type:`tableBody`,start:Object.assign({},m.start),end:Object.assign({},m.end)},f.add(n,0,[[`enter`,u,t]])),i=m.type===`tableDelimiterRow`?2:u?3:1):i&&(m.type===`data`||m.type===`tableDelimiterMarker`||m.type===`tableDelimiterFiller`)?(r=!1,o[2]===0&&(a[1]!==0&&(o[0]=o[1],d=gl(f,t,a,i,void 0,d),a=[0,0,0,0]),o[2]=n)):m.type===`tableCellDivider`&&(r?r=!1:(a[1]!==0&&(o[0]=o[1],d=gl(f,t,a,i,void 0,d)),a=o,o=[a[1],n,0,0])):m.type===`tableHead`?(s=!0,c=n):m.type===`tableRow`||m.type===`tableDelimiterRow`?(c=n,a[1]===0?o[1]!==0&&(d=gl(f,t,o,i,n,d)):(o[0]=o[1],d=gl(f,t,a,i,n,d)),i=0):i&&(m.type===`data`||m.type===`tableDelimiterMarker`||m.type===`tableDelimiterFiller`)&&(o[3]=n)}for(c!==0&&_l(f,t,c,l,u),f.consume(t.events),n=-1;++n<t.events.length;){let e=t.events[n];e[0]===`enter`&&e[1].type===`table`&&(e[1]._align=fl(t.events,n))}return e}function gl(e,t,n,r,i,a){let o=r===1?`tableHeader`:r===2?`tableDelimiter`:`tableData`;n[0]!==0&&(a.end=Object.assign({},vl(t.events,n[0])),e.add(n[0],0,[[`exit`,a,t]]));let s=vl(t.events,n[1]);if(a={type:o,start:Object.assign({},s),end:Object.assign({},s)},e.add(n[1],0,[[`enter`,a,t]]),n[2]!==0){let i=vl(t.events,n[2]),a=vl(t.events,n[3]),o={type:`tableContent`,start:Object.assign({},i),end:Object.assign({},a)};if(e.add(n[2],0,[[`enter`,o,t]]),r!==2){let r=t.events[n[2]],i=t.events[n[3]];if(r[1].end=Object.assign({},i[1].end),r[1].type=`chunkText`,r[1].contentType=`text`,n[3]>n[2]+1){let t=n[2]+1,r=n[3]-n[2]-1;e.add(t,r,[])}}e.add(n[3]+1,0,[[`exit`,o,t]])}return i!==void 0&&(a.end=Object.assign({},vl(t.events,i)),e.add(i,0,[[`exit`,a,t]]),a=void 0),a}function _l(e,t,n,r,i){let a=[],o=vl(t.events,n);i&&(i.end=Object.assign({},o),a.push([`exit`,i,t])),r.end=Object.assign({},o),a.push([`exit`,r,t]),e.add(n+1,0,a)}function vl(e,t){let n=e[t],r=n[0]===`enter`?`start`:`end`;return n[1][r]}var yl={name:`tasklistCheck`,tokenize:xl};function bl(){return{text:{91:yl}}}function xl(e,t,n){let r=this;return i;function i(t){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(t):(e.enter(`taskListCheck`),e.enter(`taskListCheckMarker`),e.consume(t),e.exit(`taskListCheckMarker`),a)}function a(t){return K(t)?(e.enter(`taskListCheckValueUnchecked`),e.consume(t),e.exit(`taskListCheckValueUnchecked`),o):t===88||t===120?(e.enter(`taskListCheckValueChecked`),e.consume(t),e.exit(`taskListCheckValueChecked`),o):n(t)}function o(t){return t===93?(e.enter(`taskListCheckMarker`),e.consume(t),e.exit(`taskListCheckMarker`),e.exit(`taskListCheck`),s):n(t)}function s(r){return G(r)?t(r):q(r)?e.check({tokenize:Sl},t,n)(r):n(r)}}function Sl(e,t,n){return Y(e,r,`whitespace`);function r(e){return e===null?n(e):t(e)}}function Cl(e){return Rt([zc(),tl(),ll(e),pl(),bl()])}var wl={};function Tl(e){let t=this,n=e||wl,r=t.data(),i=r.micromarkExtensions||=[],a=r.fromMarkdownExtensions||=[],o=r.toMarkdownExtensions||=[];i.push(Cl(n)),a.push(Ac()),o.push(jc(n))}var El=100;function Dl(e){let t;try{t=JSON.parse(e)}catch(e){return{ok:!1,reason:`invalid JSON: ${e instanceof Error?e.message:String(e)}`}}if(typeof t!=`object`||!t||Array.isArray(t))return{ok:!1,reason:`payload is not a JSON object`};let n=t;if(typeof n.url!=`string`||n.url.length===0)return{ok:!1,reason:`url is required`};let r;try{r=new URL(n.url)}catch{return{ok:!1,reason:`url is not a valid URL`}}if(r.protocol!==`http:`&&r.protocol!==`https:`)return{ok:!1,reason:`url scheme ${r.protocol} is not permitted (http/https only)`};if(typeof n.intent!=`string`||n.intent.length===0)return{ok:!1,reason:`intent is required`};if(n.intent.length>El)return{ok:!1,reason:`intent exceeds ${El} chars`};let i;if(n.hostname!==void 0){if(typeof n.hostname!=`string`)return{ok:!1,reason:`hostname must be a string when provided`};i=n.hostname}return{ok:!0,payload:i?{url:n.url,intent:n.intent,hostname:i}:{url:n.url,intent:n.intent}}}var Ol=(0,x.createContext)(null);function kl({value:e,children:t}){return(0,j.jsx)(Ol.Provider,{value:e,children:t})}function Al(){return(0,x.useContext)(Ol)}var jl={ok:`succeeded`,timeout:`navigation timed out`,"cdp-unreachable":`device browser is not responding`,error:`navigation error`};async function Ml(e,t){try{await fetch(`/api/admin/events`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({event:e,fields:t})})}catch(t){console.error(`[device-url:event] failed to post event`,e,t)}}function Nl({raw:e,reason:t}){return(0,x.useEffect)(()=>{Ml(`device-url:malformed`,{reason:t.slice(0,200),length:e.length})},[e,t]),(0,j.jsx)(`pre`,{className:`md-pre md-device-url-malformed`,children:(0,j.jsxs)(`code`,{className:`md-code`,children:[(0,j.jsxs)(`span`,{className:`md-device-url-malformed-label`,children:[(0,j.jsx)(b,{size:12}),` device-URL block is malformed: `,t]}),`
|
|
36
|
-
`,e]})})}function Pl({payload:e,reason:t}){let[n,r]=(0,x.useState)(`idle`);(0,x.useEffect)(()=>{Ml(`device-url:fallback-shown`,{intent:e.intent,reason:t,hostname:e.hostname??``})},[e.intent,e.hostname,t]);let i=async()=>{try{await navigator.clipboard.writeText(e.url),r(`copied`),window.setTimeout(()=>r(`idle`),2e3)}catch(t){r(`failed`),Ml(`device-url:fallback-shown`,{intent:e.intent,reason:`clipboard-api-unavailable`,hostname:e.hostname??``,detail:t instanceof Error?t.message.slice(0,200):String(t).slice(0,200)})}},a=e.hostname?` on the device (${e.hostname})`:` on the device`;return(0,j.jsxs)(`div`,{className:`md-device-url md-device-url-fallback`,role:`group`,children:[(0,j.jsxs)(`div`,{className:`md-device-url-fallback-message`,children:[(0,j.jsx)(b,{size:14}),(0,j.jsxs)(`span`,{children:[`Could not open `,(0,j.jsx)(`strong`,{children:e.intent}),a,` automatically (`,t,`). Copy the URL and open it in a browser on the device:`]})]}),(0,j.jsxs)(`div`,{className:`md-device-url-fallback-url`,children:[(0,j.jsx)(`code`,{children:e.url}),(0,j.jsxs)(`button`,{type:`button`,className:`md-device-url-fallback-copy`,onClick:i,"aria-label":`Copy URL`,children:[n===`copied`?(0,j.jsx)(l,{size:14}):(0,j.jsx)(d,{size:14}),n===`copied`?`Copied`:n===`failed`?`Copy failed`:`Copy`]})]}),n===`failed`&&(0,j.jsx)(`div`,{className:`md-device-url-fallback-copy-failed`,children:`Your browser blocked the copy action. Select the URL text above manually to copy it.`})]})}function Fl({payload:e}){let t=Al(),[n,r]=(0,x.useState)({phase:`idle`});(0,x.useEffect)(()=>{Ml(`device-url:render`,{intent:e.intent,url:e.url,hostname:e.hostname??``,origin:`tool`})},[e.intent,e.url,e.hostname]);let i=async()=>{if(n.phase!==`navigating`){r({phase:`navigating`});try{let n=await fetch(`/api/admin/device-browser/navigate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)}),i=await n.json().catch(()=>({}));if(n.ok&&i.ok){r({phase:`succeeded`}),t&&(t.onShowVnc(),Ml(`device-url:vnc-surface-shown`,{intent:e.intent})),window.setTimeout(()=>r({phase:`idle`}),2500);return}r({phase:`fallback`,reason:i.navigateResult?jl[i.navigateResult]:i.detail?i.detail.slice(0,80):`navigation failed`})}catch(e){r({phase:`fallback`,reason:(e instanceof Error?e.message:String(e)).slice(0,80)})}}},a=n.phase===`navigating`,o=n.phase===`succeeded`;return(0,j.jsxs)(`div`,{className:`md-device-url`,children:[(0,j.jsxs)(`button`,{type:`button`,className:`md-device-url-button`,onClick:i,disabled:a,"aria-label":`Open ${e.intent} on the device's browser`,title:e.hostname?`Opens on device: ${e.hostname}`:`Opens on the device running Maxy`,children:[(0,j.jsx)(m,{size:16,className:`md-device-url-icon`}),(0,j.jsx)(`span`,{className:`md-device-url-label`,children:a?`Opening…`:o?`Opened on device`:`Open ${e.intent} on device`})]}),n.phase===`fallback`&&(0,j.jsx)(Pl,{payload:e,reason:n.reason})]})}function Il({source:e}){let t=Dl(e.trim());return t.ok?(0,j.jsx)(Fl,{payload:t.payload}):(0,j.jsx)(Nl,{raw:e,reason:t.reason})}var Ll=null;function Rl(){return Ll||=c(async()=>{let{default:e}=await import(`./mermaid.core-CCUSwZB_.js`);return{default:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21])).then(({default:e})=>(e.initialize({startOnLoad:!1,theme:`neutral`}),e)),Ll}function zl({source:e}){let t=(0,x.useRef)(null),[n,r]=(0,x.useState)(null);return(0,x.useEffect)(()=>{let n=!1,i=`mermaid-${Math.random().toString(36).slice(2,9)}`;return Rl().then(t=>t.render(i,e)).then(({svg:e})=>{!n&&t.current&&(t.current.innerHTML=e)}).catch(t=>{n||(console.error(`[MermaidBlock] render failed:`,e,t),r(t instanceof Error?t.message:`Diagram render failed`))}),()=>{n=!0}},[e]),n?(0,j.jsxs)(`div`,{className:`md-mermaid md-mermaid-error`,children:[(0,j.jsx)(`div`,{className:`md-mermaid-error-label`,children:`Diagram render error`}),(0,j.jsx)(`pre`,{className:`md-pre`,children:(0,j.jsx)(`code`,{className:`md-code`,children:e})})]}):(0,j.jsx)(`div`,{className:`md-mermaid`,ref:t})}var Bl=/\.(mp4|webm|mov)(\?.*)?$/i,Vl=/(?:youtube\.com\/watch\?v=|youtu\.be\/)([\w-]+)/,Hl=/vimeo\.com\/(\d+)/;function Ul(e){return!!e&&Bl.test(e)}function Wl(e){if(!e)return null;let t=e.match(Vl);return t?t[1]:null}function Gl(e){if(!e)return null;let t=e.match(Hl);return t?t[1]:null}function Kl({src:e}){return(0,j.jsx)(`video`,{className:`md-video`,controls:!0,playsInline:!0,preload:`metadata`,children:(0,j.jsx)(`source`,{src:e})})}function ql({videoId:e}){return(0,j.jsx)(`div`,{className:`md-video-iframe`,children:(0,j.jsx)(`iframe`,{src:`https://www.youtube-nocookie.com/embed/${e}`,allow:`accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture`,allowFullScreen:!0,loading:`lazy`})})}function Jl({videoId:e}){return(0,j.jsx)(`div`,{className:`md-video-iframe`,children:(0,j.jsx)(`iframe`,{src:`https://player.vimeo.com/video/${e}`,allow:`autoplay; fullscreen; picture-in-picture`,allowFullScreen:!0,loading:`lazy`})})}function Yl(e){if(Ul(e))return(0,j.jsx)(Kl,{src:e});let t=Wl(e);if(t)return(0,j.jsx)(ql,{videoId:t});let n=Gl(e);return n?(0,j.jsx)(Jl,{videoId:n}):null}var Xl={p:({children:e})=>(0,j.jsx)(`p`,{className:`md-p`,children:e}),h1:({children:e})=>(0,j.jsx)(`h1`,{className:`md-heading`,children:e}),h2:({children:e})=>(0,j.jsx)(`h2`,{className:`md-heading`,children:e}),h3:({children:e})=>(0,j.jsx)(`h3`,{className:`md-heading`,children:e}),code:({children:e,className:t})=>t===`language-mermaid`?(0,j.jsx)(zl,{source:String(e).replace(/\n$/,``)}):t===`language-maxy-device-url`?(0,j.jsx)(Il,{source:String(e).replace(/\n$/,``)}):(0,j.jsx)(`code`,{className:`md-code ${t||``}`.trim(),children:e}),pre:({children:e,node:t})=>{let n=t?.children?.[0];if(n?.type===`element`&&n.tagName===`code`){let t=n.properties?.className??[];if(t.includes(`language-mermaid`)||t.includes(`language-maxy-device-url`))return(0,j.jsx)(j.Fragment,{children:e})}return(0,j.jsx)(`pre`,{className:`md-pre`,children:e})},ul:({children:e})=>(0,j.jsx)(`ul`,{className:`md-list`,children:e}),ol:({children:e})=>(0,j.jsx)(`ol`,{className:`md-list md-list-ordered`,children:e}),li:({children:e})=>(0,j.jsx)(`li`,{className:`md-list-item`,children:e}),hr:()=>(0,j.jsx)(`hr`,{className:`md-hr`}),strong:({children:e})=>(0,j.jsx)(`strong`,{className:`md-strong`,children:e}),img:({src:e,alt:t})=>Yl(e)||(0,j.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,children:(0,j.jsx)(`img`,{className:`md-img`,src:e,alt:t||``,loading:`lazy`})}),a:({href:e,children:t})=>Yl(e)||(0,j.jsx)(`a`,{href:e,className:`md-link`,target:`_blank`,rel:`noopener noreferrer`,children:t}),table:({children:e})=>(0,j.jsx)(`table`,{className:`md-table`,children:e}),thead:({children:e})=>(0,j.jsx)(`thead`,{className:`md-thead`,children:e}),tbody:({children:e})=>(0,j.jsx)(`tbody`,{children:e}),tr:({children:e})=>(0,j.jsx)(`tr`,{className:`md-tr`,children:e}),th:({children:e})=>(0,j.jsx)(`th`,{className:`md-th`,children:e}),td:({children:e})=>(0,j.jsx)(`td`,{className:`md-td`,children:e})};function Zl({content:e,elapsedSeconds:t,timestamp:n}){return(0,j.jsxs)(`div`,{className:`markdown-message`,children:[(0,j.jsx)(Co,{remarkPlugins:[Tl],components:Xl,children:e}),t!==void 0&&(0,j.jsxs)(`div`,{className:`message-meta`,children:[t,`s`]}),n&&(0,j.jsx)(`span`,{className:`message-timestamp`,children:n})]})}function Ql({submitted:e,submittedLabel:t=`Submitted`,actions:n,children:r}){return(0,j.jsxs)(`div`,{className:`component-card${e?` component-card--submitted`:``}`,children:[r,(0,j.jsx)(`div`,{className:`component-card__actions`,children:e?(0,j.jsx)(`span`,{className:`component-card__done-label`,children:t}):n.map((e,t)=>(0,j.jsx)(M,{variant:e.variant,size:`sm`,disabled:e.disabled,onClick:e.onClick,children:e.label},t))})]})}function $l({data:e,onSubmit:t,submitted:n}){let r=e,i=Array.isArray(r?.options)?r.options:[],[a,o]=(0,x.useState)(null),[s,c]=(0,x.useState)(`Submitted`);if(i.length===0)return null;let l=e=>{n||o(e)},u=()=>{if(!a||n)return;let e=i.find(e=>e.value===a);c(e?.label??`Submitted`),t((r?.submitMessage??`Selected: {{value}}`).replace(`{{value}}`,a).replace(`{{label}}`,e?.label??a))},d=()=>{n||(c(r?.backLabel??`Back`),t(r?.backMessage??``))},f=(e,t)=>{if(!n)if(e.key===`ArrowDown`||e.key===`ArrowRight`){e.preventDefault();let n=(t+1)%i.length;l(i[n].value),(e.currentTarget.parentElement?.children[n])?.focus()}else if(e.key===`ArrowUp`||e.key===`ArrowLeft`){e.preventDefault();let n=(t-1+i.length)%i.length;l(i[n].value),(e.currentTarget.parentElement?.children[n])?.focus()}else (e.key===` `||e.key===`Enter`)&&(e.preventDefault(),l(i[t].value))};return(0,j.jsx)(Ql,{submitted:n,submittedLabel:s,actions:[...r?.backLabel&&r?.backMessage?[{label:r.backLabel,variant:`ghost`,onClick:d}]:[],{label:r?.submitLabel??`Confirm`,variant:`primary`,disabled:!a,onClick:u}],children:(0,j.jsxs)(`div`,{className:`single-select`,role:`radiogroup`,"aria-label":r?.title??`Select one`,children:[r?.title&&(0,j.jsx)(`div`,{className:`single-select__title`,children:r.title}),i.map((e,t)=>(0,j.jsxs)(`div`,{className:`single-select__row${a===e.value?` single-select__row--selected`:``}`,role:`radio`,"aria-checked":a===e.value,tabIndex:a===e.value||!a&&t===0?0:-1,onClick:()=>l(e.value),onKeyDown:e=>f(e,t),children:[(0,j.jsx)(`span`,{className:`single-select__radio${a===e.value?` single-select__radio--checked`:``}`}),(0,j.jsxs)(`div`,{className:`single-select__info`,children:[(0,j.jsxs)(`span`,{className:`single-select__label`,children:[e.icon&&(0,j.jsx)(`span`,{className:`single-select__icon`,children:e.icon}),e.label]}),e.description&&(0,j.jsx)(`span`,{className:`single-select__desc`,children:e.description})]})]},e.value))]})})}function eu({data:e,onSubmit:t,submitted:n}){let r=e,i=Array.isArray(r?.options)?r.options:[],[a,o]=(0,x.useState)(i.map(e=>!!e.locked||!!e.defaultSelected)),[c,l]=(0,x.useState)(`Submitted`);if(i.length===0)return null;let u=i.some(e=>e.locked),d=i.every((e,t)=>e.locked||a[t]),f=e=>{n||i[e].locked||o(t=>t.map((t,n)=>n===e?!t:t))},p=()=>{n||o(i.map((e,t)=>e.locked?a[t]:!d))},m=i.filter((e,t)=>!e.locked&&a[t]).map(e=>e.value),h=m.length>0||u,g=()=>{if(!(!h||n)){if(l(`Submitted`),m.length===0){t(`No optional plugins selected`);return}t((r?.submitMessage??`Selected: {{values}}`).replace(`{{values}}`,m.join(`, `)))}},_=()=>{n||(l(`Skipped`),t(r?.skipMessage??`Skipped`))},v=()=>{n||(l(r?.backLabel??`Back`),t(r?.backMessage??``))},y=[];return r?.backLabel&&r?.backMessage&&y.push({label:r.backLabel,variant:`ghost`,onClick:v}),r?.skipLabel&&y.push({label:r.skipLabel,variant:`ghost`,onClick:_}),y.push({label:r?.submitLabel??`Confirm`,variant:`primary`,disabled:!h,onClick:g}),(0,j.jsx)(Ql,{submitted:n,submittedLabel:c,actions:y,children:(0,j.jsxs)(`div`,{className:`multi-select`,children:[r?.title&&(0,j.jsx)(`div`,{className:`multi-select__title`,children:r.title}),r?.selectAll&&(0,j.jsx)(`div`,{className:`multi-select__header`,children:(0,j.jsx)(s,{checked:d,onChange:p,label:`Select all`,disabled:n})}),(0,j.jsx)(`div`,{className:`multi-select__list`,role:`group`,"aria-label":r?.title??`Select options`,children:i.map((e,t)=>{let r=e.group&&(t===0||e.group!==i[t-1].group),o=!!e.locked;return(0,j.jsxs)(x.Fragment,{children:[r&&(0,j.jsx)(`div`,{className:`multi-select__group-header`,children:e.group}),(0,j.jsxs)(`div`,{className:`multi-select__row${o?` multi-select__row--locked`:``}`,role:`checkbox`,"aria-checked":a[t],"aria-disabled":o||void 0,tabIndex:o?-1:0,onClick:()=>f(t),onKeyDown:e=>{n||o||(e.key===` `||e.key===`Enter`)&&(e.preventDefault(),f(t))},children:[(0,j.jsx)(s,{checked:a[t],onChange:()=>f(t),disabled:n||o}),(0,j.jsxs)(`div`,{className:`multi-select__info`,children:[(0,j.jsxs)(`span`,{className:`multi-select__label`,children:[e.label,e.badge&&(0,j.jsx)(`span`,{className:`multi-select__badge`,children:e.badge})]}),e.description&&(0,j.jsx)(`span`,{className:`multi-select__desc`,children:e.description})]})]})]},e.value)})})]})})}function tu({data:e,onSubmit:t,submitted:n}){let r=e,i=Array.isArray(r?.buttons)?r.buttons:[],[a,o]=(0,x.useState)(`Submitted`);if(i.length===0)return null;let s=e=>{n||(o(e.label),t(e.value))};return(0,j.jsx)(Ql,{submitted:n,submittedLabel:a,actions:i.map(e=>({label:e.label,variant:`primary`,onClick:()=>s(e)})),children:(0,j.jsx)(j.Fragment,{})})}function nu(e){let t=new Date(e),n=new Date,r=String(t.getHours()).padStart(2,`0`),i=String(t.getMinutes()).padStart(2,`0`),a=String(t.getSeconds()).padStart(2,`0`);return t.toDateString()===n.toDateString()?`${r}:${i}:${a}`:`${String(t.getDate()).padStart(2,`0`)}-${String(t.getMonth()+1).padStart(2,`0`)}-${t.getFullYear()} ${r}:${i}:${a}`}var ru=44,iu=(0,x.forwardRef)(function({value:e,onChange:t,placeholder:n,disabled:r},i){let a=(0,x.useRef)(null),o=(0,x.useRef)(!1),s=(0,x.useCallback)((e,t)=>{let n=e.closest(`.chat-form`);n&&(n.dataset.expanded=t>ru?`true`:``)},[]),c=(0,x.useCallback)(e=>{if(o.current)return;let t=window.innerHeight*.75;e.style.height=`auto`;let n=Math.min(e.scrollHeight,t);e.style.height=`${n}px`,e.style.overflowY=e.scrollHeight>t?`auto`:`hidden`,s(e,n)},[s]);return(0,x.useImperativeHandle)(i,()=>({focus(){a.current?.focus()},resetHeight(){if(!a.current)return;o.current=!1,a.current.style.height=``,a.current.style.overflowY=``;let e=a.current.closest(`.chat-form`);e&&(e.dataset.expanded=``)},getOffsetHeight(){return a.current?.offsetHeight??36},setHeight(e){a.current&&(o.current=!0,a.current.style.height=`${e}px`,s(a.current,e))}})),(0,j.jsx)(`textarea`,{ref:a,className:`chat-input`,rows:1,value:e,onChange:e=>{t(e.target.value),c(e.target)},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),e.currentTarget.closest(`form`)?.requestSubmit())},placeholder:n,disabled:r,"aria-label":n||`Type a message...`})});function au({inputRef:e}){let t=(0,x.useRef)(null);function n(n){e.current&&(n.preventDefault(),n.target.setPointerCapture(n.pointerId),t.current={startY:n.clientY,startH:e.current.getOffsetHeight()})}function r(n){if(!t.current||!e.current)return;let r=t.current.startY-n.clientY,i=window.innerHeight*.75,a=Math.max(36,Math.min(i,t.current.startH+r));e.current.setHeight(a)}function i(){t.current=null}return(0,j.jsx)(`div`,{className:`chat-resize-handle`,onPointerDown:n,onPointerMove:r,onPointerUp:i,"aria-label":`Resize input`,children:(0,j.jsx)(`div`,{className:`chat-resize-handle-bar`})})}function ou(e){return`${Math.floor(e/60)}:${(e%60).toString().padStart(2,`0`)}`}function su({data:e,active:t}){let n=[];if(e&&e.length>0&&t){let t=Math.floor(e.length/24);for(let r=0;r<24;r++){let i=e[r*t]??128,a=Math.abs(i-128)/128;n.push(Math.max(.15,a))}}else for(let e=0;e<24;e++)n.push(.15);return(0,j.jsx)(`div`,{className:`voice-waveform`,"aria-hidden":`true`,children:n.map((e,t)=>(0,j.jsx)(`div`,{className:`voice-waveform-bar`,style:{height:`${Math.round(e*100)}%`}},t))})}function cu({state:e,elapsedSeconds:t,waveform:n,onTogglePause:i,onDiscard:a,onSend:o}){if(e===`idle`||e===`error`)return null;let s=e===`recording`,c=e===`paused`,l=e===`sending`;return(0,j.jsxs)(`div`,{className:`voice-recorder`,role:`region`,"aria-label":`Voice recording`,"aria-live":`polite`,children:[(0,j.jsx)(`button`,{type:`button`,className:`voice-trash`,onClick:a,disabled:l,"aria-label":`Discard recording`,children:(0,j.jsx)(r,{size:16})}),(0,j.jsx)(`span`,{className:`voice-timer`,"aria-live":`polite`,"aria-atomic":`true`,children:ou(t)}),(0,j.jsx)(su,{data:n,active:s}),(0,j.jsx)(`button`,{type:`button`,className:`voice-pause`,onClick:i,disabled:l,"aria-label":c?`Resume recording`:`Pause recording`,children:c?(0,j.jsx)(v,{size:14}):(0,j.jsx)(_,{size:14})}),(0,j.jsx)(M,{variant:`send`,type:`button`,onClick:o,disabled:l,loading:l,"aria-label":`Send voice note`,children:(0,j.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,j.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,j.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]})}var lu=[`audio/ogg;codecs=opus`,`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`];function uu(){for(let e of lu)if(MediaRecorder.isTypeSupported(e))return e;return``}function du(e){return e.split(`;`)[0]}function fu(){let[e,t]=(0,x.useState)(`idle`),[n,r]=(0,x.useState)(0),[i,a]=(0,x.useState)(null),[o,s]=(0,x.useState)(null),c=(0,x.useRef)(null),l=(0,x.useRef)(null),u=(0,x.useRef)([]),d=(0,x.useRef)(``),f=(0,x.useRef)(null),p=(0,x.useRef)(0),m=(0,x.useRef)(0),h=(0,x.useRef)(null),g=(0,x.useRef)(null),_=(0,x.useRef)(0),v=(0,x.useCallback)(()=>{if(f.current&&=(clearInterval(f.current),null),_.current&&=(cancelAnimationFrame(_.current),0),c.current&&c.current.state!==`inactive`)try{c.current.stop()}catch{}c.current=null,u.current=[],l.current&&=(l.current.getTracks().forEach(e=>e.stop()),null),h.current&&(h.current.close().catch(()=>{}),h.current=null,g.current=null),m.current=0,p.current=0},[]);(0,x.useEffect)(()=>v,[v]);let y=(0,x.useCallback)(()=>{p.current=Date.now(),f.current=setInterval(()=>{let e=Date.now()-p.current,t=m.current+e;r(Math.floor(t/1e3))},200)},[]),b=(0,x.useCallback)(()=>{f.current&&=(clearInterval(f.current),null);let e=Date.now()-p.current;m.current+=e},[]),S=(0,x.useCallback)(()=>{let e=g.current;if(!e)return;let t=new Uint8Array(e.frequencyBinCount),n=()=>{e.getByteTimeDomainData(t),a(new Uint8Array(t)),_.current=requestAnimationFrame(n)};n()},[]),C=(0,x.useCallback)(()=>{_.current&&=(cancelAnimationFrame(_.current),0)},[]),w=(0,x.useCallback)(async()=>{if(!(e!==`idle`&&e!==`error`)){if(s(null),typeof window<`u`&&!window.isSecureContext){t(`error`),s(`Voice recording requires a secure connection (HTTPS). Use your tunnel URL for voice notes.`);return}if(typeof navigator>`u`||!navigator.mediaDevices?.getUserMedia){t(`error`),s(`Voice recording is not supported in this browser.`);return}if(typeof MediaRecorder>`u`){t(`error`),s(`Voice recording is not supported in this browser.`);return}try{let e=await navigator.mediaDevices.getUserMedia({audio:!0});l.current=e;let n=new AudioContext;h.current=n;let i=n.createMediaStreamSource(e),o=n.createAnalyser();o.fftSize=256,i.connect(o),g.current=o;let s=uu();d.current=s;let f=new MediaRecorder(e,s?{mimeType:s}:void 0);c.current=f,u.current=[],f.ondataavailable=e=>{e.data.size>0&&u.current.push(e.data)},e.getAudioTracks()[0]?.addEventListener(`ended`,()=>{v(),t(`idle`),r(0),a(null)}),f.start(1e3),t(`recording`),r(0),y(),S()}catch(e){v(),t(`error`),e instanceof DOMException?e.name===`NotAllowedError`?s(`Microphone access was denied. Check your browser permissions to enable voice recording.`):e.name===`NotFoundError`?s(`No microphone found. Connect a microphone to use voice recording.`):s(`Microphone error: ${e.message}`):s(`Could not start recording.`)}}},[e,v,y,S]),T=(0,x.useCallback)(()=>{let n=c.current;n&&(e===`recording`&&n.state===`recording`?(n.pause(),b(),C(),t(`paused`)):e===`paused`&&n.state===`paused`&&(n.resume(),y(),S(),t(`recording`)))},[e,b,y,S,C]),E=(0,x.useCallback)(()=>{e!==`recording`&&e!==`paused`||(v(),t(`idle`),r(0),a(null))},[e,v]),D=(0,x.useCallback)(async()=>{if(e!==`recording`&&e!==`paused`)return null;let n=c.current;if(!n)return null;let i=e===`recording`?Date.now()-p.current:0;return m.current+i<1e3?(E(),null):(t(`sending`),b(),C(),new Promise(e=>{n.onstop=()=>{let i=d.current||n.mimeType||`audio/webm`,o=new Blob(u.current,{type:du(i)});v(),t(`idle`),r(0),a(null),e(o.size>0?o:null)},n.stop()}))},[e,E,b,C,v]);return(0,x.useEffect)(()=>{if(e!==`error`)return;let n=setTimeout(()=>{t(`idle`),s(null)},8e3);return()=>clearTimeout(n)},[e]),{state:e,elapsedSeconds:n,waveform:i,errorMessage:o,start:w,togglePause:T,discard:E,send:D}}export{h as A,S as C,v as D,y as E,u as F,l as I,p as M,f as N,_ as O,d as P,w as S,b as T,A as _,nu as a,D as b,$l as c,Il as d,kl as f,te as g,M as h,au as i,m as j,g as k,Ql as l,Co as m,cu as n,tu as o,Tl as p,iu as r,eu as s,fu as t,Zl as u,T as v,C as w,E as x,O as y};
|
|
36
|
+
`,e]})})}function Pl({payload:e,reason:t}){let[n,r]=(0,x.useState)(`idle`);(0,x.useEffect)(()=>{Ml(`device-url:fallback-shown`,{intent:e.intent,reason:t,hostname:e.hostname??``})},[e.intent,e.hostname,t]);let i=async()=>{try{await navigator.clipboard.writeText(e.url),r(`copied`),window.setTimeout(()=>r(`idle`),2e3)}catch(t){r(`failed`),Ml(`device-url:fallback-shown`,{intent:e.intent,reason:`clipboard-api-unavailable`,hostname:e.hostname??``,detail:t instanceof Error?t.message.slice(0,200):String(t).slice(0,200)})}},a=e.hostname?` on the device (${e.hostname})`:` on the device`;return(0,j.jsxs)(`div`,{className:`md-device-url md-device-url-fallback`,role:`group`,children:[(0,j.jsxs)(`div`,{className:`md-device-url-fallback-message`,children:[(0,j.jsx)(b,{size:14}),(0,j.jsxs)(`span`,{children:[`Could not open `,(0,j.jsx)(`strong`,{children:e.intent}),a,` automatically (`,t,`). Copy the URL and open it in a browser on the device:`]})]}),(0,j.jsxs)(`div`,{className:`md-device-url-fallback-url`,children:[(0,j.jsx)(`code`,{children:e.url}),(0,j.jsxs)(`button`,{type:`button`,className:`md-device-url-fallback-copy`,onClick:i,"aria-label":`Copy URL`,children:[n===`copied`?(0,j.jsx)(l,{size:14}):(0,j.jsx)(d,{size:14}),n===`copied`?`Copied`:n===`failed`?`Copy failed`:`Copy`]})]}),n===`failed`&&(0,j.jsx)(`div`,{className:`md-device-url-fallback-copy-failed`,children:`Your browser blocked the copy action. Select the URL text above manually to copy it.`})]})}function Fl({payload:e}){let t=Al(),[n,r]=(0,x.useState)({phase:`idle`});(0,x.useEffect)(()=>{Ml(`device-url:render`,{intent:e.intent,url:e.url,hostname:e.hostname??``,origin:`tool`})},[e.intent,e.url,e.hostname]);let i=async()=>{if(n.phase!==`navigating`){r({phase:`navigating`});try{let n=await fetch(`/api/admin/device-browser/navigate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)}),i=await n.json().catch(()=>({}));if(n.ok&&i.ok){r({phase:`succeeded`}),t&&(t.onShowVnc(),Ml(`device-url:vnc-surface-shown`,{intent:e.intent})),window.setTimeout(()=>r({phase:`idle`}),2500);return}r({phase:`fallback`,reason:i.navigateResult?jl[i.navigateResult]:i.detail?i.detail.slice(0,80):`navigation failed`})}catch(e){r({phase:`fallback`,reason:(e instanceof Error?e.message:String(e)).slice(0,80)})}}},a=n.phase===`navigating`,o=n.phase===`succeeded`;return(0,j.jsxs)(`div`,{className:`md-device-url`,children:[(0,j.jsxs)(`button`,{type:`button`,className:`md-device-url-button`,onClick:i,disabled:a,"aria-label":`Open ${e.intent} on the device's browser`,title:e.hostname?`Opens on device: ${e.hostname}`:`Opens on the device running Maxy`,children:[(0,j.jsx)(m,{size:16,className:`md-device-url-icon`}),(0,j.jsx)(`span`,{className:`md-device-url-label`,children:a?`Opening…`:o?`Opened on device`:`Open ${e.intent} on device`})]}),n.phase===`fallback`&&(0,j.jsx)(Pl,{payload:e,reason:n.reason})]})}function Il({source:e}){let t=Dl(e.trim());return t.ok?(0,j.jsx)(Fl,{payload:t.payload}):(0,j.jsx)(Nl,{raw:e,reason:t.reason})}var Ll=null;function Rl(){return Ll||=c(async()=>{let{default:e}=await import(`./mermaid.core-CCUSwZB_.js`);return{default:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21])).then(({default:e})=>(e.initialize({startOnLoad:!1,theme:`neutral`}),e)),Ll}function zl({source:e}){let t=(0,x.useRef)(null),[n,r]=(0,x.useState)(null);return(0,x.useEffect)(()=>{let n=!1,i=`mermaid-${Math.random().toString(36).slice(2,9)}`;return Rl().then(t=>t.render(i,e)).then(({svg:e})=>{!n&&t.current&&(t.current.innerHTML=e)}).catch(t=>{n||(console.error(`[MermaidBlock] render failed:`,e,t),r(t instanceof Error?t.message:`Diagram render failed`))}),()=>{n=!0}},[e]),n?(0,j.jsxs)(`div`,{className:`md-mermaid md-mermaid-error`,children:[(0,j.jsx)(`div`,{className:`md-mermaid-error-label`,children:`Diagram render error`}),(0,j.jsx)(`pre`,{className:`md-pre`,children:(0,j.jsx)(`code`,{className:`md-code`,children:e})})]}):(0,j.jsx)(`div`,{className:`md-mermaid`,ref:t})}var Bl=/\.(mp4|webm|mov)(\?.*)?$/i,Vl=/(?:youtube\.com\/watch\?v=|youtu\.be\/)([\w-]+)/,Hl=/vimeo\.com\/(\d+)/;function Ul(e){return!!e&&Bl.test(e)}function Wl(e){if(!e)return null;let t=e.match(Vl);return t?t[1]:null}function Gl(e){if(!e)return null;let t=e.match(Hl);return t?t[1]:null}function Kl({src:e}){return(0,j.jsx)(`video`,{className:`md-video`,controls:!0,playsInline:!0,preload:`metadata`,children:(0,j.jsx)(`source`,{src:e})})}function ql({videoId:e}){return(0,j.jsx)(`div`,{className:`md-video-iframe`,children:(0,j.jsx)(`iframe`,{src:`https://www.youtube-nocookie.com/embed/${e}`,allow:`accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture`,allowFullScreen:!0,loading:`lazy`})})}function Jl({videoId:e}){return(0,j.jsx)(`div`,{className:`md-video-iframe`,children:(0,j.jsx)(`iframe`,{src:`https://player.vimeo.com/video/${e}`,allow:`autoplay; fullscreen; picture-in-picture`,allowFullScreen:!0,loading:`lazy`})})}function Yl(e){if(Ul(e))return(0,j.jsx)(Kl,{src:e});let t=Wl(e);if(t)return(0,j.jsx)(ql,{videoId:t});let n=Gl(e);return n?(0,j.jsx)(Jl,{videoId:n}):null}var Xl={p:({children:e})=>(0,j.jsx)(`p`,{className:`md-p`,children:e}),h1:({children:e})=>(0,j.jsx)(`h1`,{className:`md-heading`,children:e}),h2:({children:e})=>(0,j.jsx)(`h2`,{className:`md-heading`,children:e}),h3:({children:e})=>(0,j.jsx)(`h3`,{className:`md-heading`,children:e}),code:({children:e,className:t})=>t===`language-mermaid`?(0,j.jsx)(zl,{source:String(e).replace(/\n$/,``)}):t===`language-maxy-device-url`?(0,j.jsx)(Il,{source:String(e).replace(/\n$/,``)}):(0,j.jsx)(`code`,{className:`md-code ${t||``}`.trim(),children:e}),pre:({children:e,node:t})=>{let n=t?.children?.[0];if(n?.type===`element`&&n.tagName===`code`){let t=n.properties?.className??[];if(t.includes(`language-mermaid`)||t.includes(`language-maxy-device-url`))return(0,j.jsx)(j.Fragment,{children:e})}return(0,j.jsx)(`pre`,{className:`md-pre`,children:e})},ul:({children:e})=>(0,j.jsx)(`ul`,{className:`md-list`,children:e}),ol:({children:e})=>(0,j.jsx)(`ol`,{className:`md-list md-list-ordered`,children:e}),li:({children:e})=>(0,j.jsx)(`li`,{className:`md-list-item`,children:e}),hr:()=>(0,j.jsx)(`hr`,{className:`md-hr`}),strong:({children:e})=>(0,j.jsx)(`strong`,{className:`md-strong`,children:e}),img:({src:e,alt:t})=>Yl(e)||(0,j.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,children:(0,j.jsx)(`img`,{className:`md-img`,src:e,alt:t||``,loading:`lazy`})}),a:({href:e,children:t})=>Yl(e)||(0,j.jsx)(`a`,{href:e,className:`md-link`,target:`_blank`,rel:`noopener noreferrer`,children:t}),table:({children:e})=>(0,j.jsx)(`table`,{className:`md-table`,children:e}),thead:({children:e})=>(0,j.jsx)(`thead`,{className:`md-thead`,children:e}),tbody:({children:e})=>(0,j.jsx)(`tbody`,{children:e}),tr:({children:e})=>(0,j.jsx)(`tr`,{className:`md-tr`,children:e}),th:({children:e})=>(0,j.jsx)(`th`,{className:`md-th`,children:e}),td:({children:e})=>(0,j.jsx)(`td`,{className:`md-td`,children:e})};function Zl({content:e,elapsedSeconds:t,timestamp:n}){return(0,j.jsxs)(`div`,{className:`markdown-message`,children:[(0,j.jsx)(Co,{remarkPlugins:[Tl],components:Xl,children:e}),t!==void 0&&(0,j.jsxs)(`div`,{className:`message-meta`,children:[t,`s`]}),n&&(0,j.jsx)(`span`,{className:`message-timestamp`,children:n})]})}function Ql({submitted:e,submittedLabel:t=`Submitted`,actions:n,children:r}){return(0,j.jsxs)(`div`,{className:`component-card${e?` component-card--submitted`:``}`,children:[r,(0,j.jsx)(`div`,{className:`component-card__actions`,children:e?(0,j.jsx)(`span`,{className:`component-card__done-label`,children:t}):n.map((e,t)=>(0,j.jsx)(M,{variant:e.variant,size:`sm`,disabled:e.disabled,onClick:e.onClick,children:e.label},t))})]})}function $l({data:e,onSubmit:t,submitted:n}){let r=e,i=Array.isArray(r?.options)?r.options:[],[a,o]=(0,x.useState)(null),[s,c]=(0,x.useState)(`Submitted`);if(i.length===0)return null;let l=e=>{n||o(e)},u=()=>{if(!a||n)return;let e=i.find(e=>e.value===a);c(e?.label??`Submitted`),t((r?.submitMessage??`Selected: {{value}}`).replace(`{{value}}`,a).replace(`{{label}}`,e?.label??a))},d=()=>{n||(c(r?.backLabel??`Back`),t(r?.backMessage??``))},f=(e,t)=>{if(!n)if(e.key===`ArrowDown`||e.key===`ArrowRight`){e.preventDefault();let n=(t+1)%i.length;l(i[n].value),(e.currentTarget.parentElement?.children[n])?.focus()}else if(e.key===`ArrowUp`||e.key===`ArrowLeft`){e.preventDefault();let n=(t-1+i.length)%i.length;l(i[n].value),(e.currentTarget.parentElement?.children[n])?.focus()}else (e.key===` `||e.key===`Enter`)&&(e.preventDefault(),l(i[t].value))};return(0,j.jsx)(Ql,{submitted:n,submittedLabel:s,actions:[...r?.backLabel&&r?.backMessage?[{label:r.backLabel,variant:`ghost`,onClick:d}]:[],{label:r?.submitLabel??`Confirm`,variant:`primary`,disabled:!a,onClick:u}],children:(0,j.jsxs)(`div`,{className:`single-select`,role:`radiogroup`,"aria-label":r?.title??`Select one`,children:[r?.title&&(0,j.jsx)(`div`,{className:`single-select__title`,children:r.title}),i.map((e,t)=>(0,j.jsxs)(`div`,{className:`single-select__row${a===e.value?` single-select__row--selected`:``}`,role:`radio`,"aria-checked":a===e.value,tabIndex:a===e.value||!a&&t===0?0:-1,onClick:()=>l(e.value),onKeyDown:e=>f(e,t),children:[(0,j.jsx)(`span`,{className:`single-select__radio${a===e.value?` single-select__radio--checked`:``}`}),(0,j.jsxs)(`div`,{className:`single-select__info`,children:[(0,j.jsxs)(`span`,{className:`single-select__label`,children:[e.icon&&(0,j.jsx)(`span`,{className:`single-select__icon`,children:e.icon}),e.label]}),e.description&&(0,j.jsx)(`span`,{className:`single-select__desc`,children:e.description})]})]},e.value))]})})}function eu({data:e,onSubmit:t,submitted:n}){let r=e,i=Array.isArray(r?.options)?r.options:[],[a,o]=(0,x.useState)(i.map(e=>!!e.locked||!!e.defaultSelected)),[c,l]=(0,x.useState)(`Submitted`);if(i.length===0)return null;let u=i.some(e=>e.locked),d=i.every((e,t)=>e.locked||a[t]),f=e=>{n||i[e].locked||o(t=>t.map((t,n)=>n===e?!t:t))},p=()=>{n||o(i.map((e,t)=>e.locked?a[t]:!d))},m=i.filter((e,t)=>!e.locked&&a[t]).map(e=>e.value),h=m.length>0||u,g=()=>{if(!(!h||n)){if(l(`Submitted`),m.length===0){t(`No optional plugins selected`);return}t((r?.submitMessage??`Selected: {{values}}`).replace(`{{values}}`,m.join(`, `)))}},_=()=>{n||(l(`Skipped`),t(r?.skipMessage??`Skipped`))},v=()=>{n||(l(r?.backLabel??`Back`),t(r?.backMessage??``))},y=[];return r?.backLabel&&r?.backMessage&&y.push({label:r.backLabel,variant:`ghost`,onClick:v}),r?.skipLabel&&y.push({label:r.skipLabel,variant:`ghost`,onClick:_}),y.push({label:r?.submitLabel??`Confirm`,variant:`primary`,disabled:!h,onClick:g}),(0,j.jsx)(Ql,{submitted:n,submittedLabel:c,actions:y,children:(0,j.jsxs)(`div`,{className:`multi-select`,children:[r?.title&&(0,j.jsx)(`div`,{className:`multi-select__title`,children:r.title}),r?.selectAll&&(0,j.jsx)(`div`,{className:`multi-select__header`,children:(0,j.jsx)(s,{checked:d,onChange:p,label:`Select all`,disabled:n})}),(0,j.jsx)(`div`,{className:`multi-select__list`,role:`group`,"aria-label":r?.title??`Select options`,children:i.map((e,t)=>{let r=e.group&&(t===0||e.group!==i[t-1].group),o=!!e.locked;return(0,j.jsxs)(x.Fragment,{children:[r&&(0,j.jsx)(`div`,{className:`multi-select__group-header`,children:e.group}),(0,j.jsxs)(`div`,{className:`multi-select__row${o?` multi-select__row--locked`:``}`,role:`checkbox`,"aria-checked":a[t],"aria-disabled":o||void 0,tabIndex:o?-1:0,onClick:()=>f(t),onKeyDown:e=>{n||o||(e.key===` `||e.key===`Enter`)&&(e.preventDefault(),f(t))},children:[(0,j.jsx)(s,{checked:a[t],onChange:()=>f(t),disabled:n||o}),(0,j.jsxs)(`div`,{className:`multi-select__info`,children:[(0,j.jsxs)(`span`,{className:`multi-select__label`,children:[e.label,e.badge&&(0,j.jsx)(`span`,{className:`multi-select__badge`,children:e.badge})]}),e.description&&(0,j.jsx)(`span`,{className:`multi-select__desc`,children:e.description})]})]})]},e.value)})})]})})}function tu({data:e,onSubmit:t,submitted:n}){let r=e,i=Array.isArray(r?.buttons)?r.buttons:[],[a,o]=(0,x.useState)(`Submitted`);if(i.length===0)return null;let s=e=>{n||(o(e.label),t(e.value))};return(0,j.jsx)(Ql,{submitted:n,submittedLabel:a,actions:i.map(e=>({label:e.label,variant:`primary`,onClick:()=>s(e)})),children:(0,j.jsx)(j.Fragment,{})})}function nu(e){let t=new Date(e),n=new Date,r=String(t.getHours()).padStart(2,`0`),i=String(t.getMinutes()).padStart(2,`0`),a=String(t.getSeconds()).padStart(2,`0`);return t.toDateString()===n.toDateString()?`${r}:${i}:${a}`:`${String(t.getDate()).padStart(2,`0`)}-${String(t.getMonth()+1).padStart(2,`0`)}-${t.getFullYear()} ${r}:${i}:${a}`}var ru=44,iu=(0,x.forwardRef)(function({value:e,onChange:t,placeholder:n,disabled:r},i){let a=(0,x.useRef)(null),o=(0,x.useRef)(!1),s=(0,x.useCallback)((e,t)=>{let n=e.closest(`.chat-form`);n&&(n.dataset.expanded=t>ru?`true`:``)},[]),c=(0,x.useCallback)(e=>{if(o.current)return;let t=window.innerHeight*.75;e.style.height=`auto`;let n=Math.min(e.scrollHeight,t);e.style.height=`${n}px`,e.style.overflowY=e.scrollHeight>t?`auto`:`hidden`,s(e,n)},[s]);return(0,x.useImperativeHandle)(i,()=>({focus(){a.current?.focus()},resetHeight(){if(!a.current)return;o.current=!1,a.current.style.height=``,a.current.style.overflowY=``;let e=a.current.closest(`.chat-form`);e&&(e.dataset.expanded=``)},getOffsetHeight(){return a.current?.offsetHeight??36},setHeight(e){a.current&&(o.current=!0,a.current.style.height=`${e}px`,s(a.current,e))}})),(0,j.jsx)(`textarea`,{ref:a,className:`chat-input`,rows:1,value:e,onChange:e=>{t(e.target.value),c(e.target)},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),e.currentTarget.closest(`form`)?.requestSubmit())},placeholder:n,disabled:r,"aria-label":n||`Type a message...`})});function au({inputRef:e}){let t=(0,x.useRef)(null);function n(n){e.current&&(n.preventDefault(),n.target.setPointerCapture(n.pointerId),t.current={startY:n.clientY,startH:e.current.getOffsetHeight()})}function r(n){if(!t.current||!e.current)return;let r=t.current.startY-n.clientY,i=window.innerHeight*.75,a=Math.max(36,Math.min(i,t.current.startH+r));e.current.setHeight(a)}function i(){t.current=null}return(0,j.jsx)(`div`,{className:`chat-resize-handle`,onPointerDown:n,onPointerMove:r,onPointerUp:i,"aria-label":`Resize input`,children:(0,j.jsx)(`div`,{className:`chat-resize-handle-bar`})})}function ou(e){return`${Math.floor(e/60)}:${(e%60).toString().padStart(2,`0`)}`}function su({data:e,active:t}){let n=[];if(e&&e.length>0&&t){let t=Math.floor(e.length/24);for(let r=0;r<24;r++){let i=e[r*t]??128,a=Math.abs(i-128)/128;n.push(Math.max(.15,a))}}else for(let e=0;e<24;e++)n.push(.15);return(0,j.jsx)(`div`,{className:`voice-waveform`,"aria-hidden":`true`,children:n.map((e,t)=>(0,j.jsx)(`div`,{className:`voice-waveform-bar`,style:{height:`${Math.round(e*100)}%`}},t))})}function cu({state:e,elapsedSeconds:t,waveform:n,onTogglePause:i,onDiscard:a,onSend:o}){if(e===`idle`||e===`error`)return null;let s=e===`recording`,c=e===`paused`,l=e===`sending`;return(0,j.jsxs)(`div`,{className:`voice-recorder`,role:`region`,"aria-label":`Voice recording`,"aria-live":`polite`,children:[(0,j.jsx)(`button`,{type:`button`,className:`voice-trash`,onClick:a,disabled:l,"aria-label":`Discard recording`,children:(0,j.jsx)(r,{size:16})}),(0,j.jsx)(`span`,{className:`voice-timer`,"aria-live":`polite`,"aria-atomic":`true`,children:ou(t)}),(0,j.jsx)(su,{data:n,active:s}),(0,j.jsx)(`button`,{type:`button`,className:`voice-pause`,onClick:i,disabled:l,"aria-label":c?`Resume recording`:`Pause recording`,children:c?(0,j.jsx)(v,{size:14}):(0,j.jsx)(_,{size:14})}),(0,j.jsx)(M,{variant:`send`,type:`button`,onClick:o,disabled:l,loading:l,"aria-label":`Send voice note`,children:(0,j.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,j.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`}),(0,j.jsx)(`polyline`,{points:`12 5 19 12 12 19`})]})})]})}var lu=[`audio/ogg;codecs=opus`,`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`];function uu(){for(let e of lu)if(MediaRecorder.isTypeSupported(e))return e;return``}function du(e){return e.split(`;`)[0]}function fu(){let[e,t]=(0,x.useState)(`idle`),[n,r]=(0,x.useState)(0),[i,a]=(0,x.useState)(null),[o,s]=(0,x.useState)(null),c=(0,x.useRef)(null),l=(0,x.useRef)(null),u=(0,x.useRef)([]),d=(0,x.useRef)(``),f=(0,x.useRef)(null),p=(0,x.useRef)(0),m=(0,x.useRef)(0),h=(0,x.useRef)(null),g=(0,x.useRef)(null),_=(0,x.useRef)(0),v=(0,x.useCallback)(()=>{if(f.current&&=(clearInterval(f.current),null),_.current&&=(cancelAnimationFrame(_.current),0),c.current&&c.current.state!==`inactive`)try{c.current.stop()}catch{}c.current=null,u.current=[],l.current&&=(l.current.getTracks().forEach(e=>e.stop()),null),h.current&&(h.current.close().catch(()=>{}),h.current=null,g.current=null),m.current=0,p.current=0},[]);(0,x.useEffect)(()=>v,[v]);let y=(0,x.useCallback)(()=>{p.current=Date.now(),f.current=setInterval(()=>{let e=Date.now()-p.current,t=m.current+e;r(Math.floor(t/1e3))},200)},[]),b=(0,x.useCallback)(()=>{f.current&&=(clearInterval(f.current),null);let e=Date.now()-p.current;m.current+=e},[]),S=(0,x.useCallback)(()=>{let e=g.current;if(!e)return;let t=new Uint8Array(e.frequencyBinCount),n=()=>{e.getByteTimeDomainData(t),a(new Uint8Array(t)),_.current=requestAnimationFrame(n)};n()},[]),C=(0,x.useCallback)(()=>{_.current&&=(cancelAnimationFrame(_.current),0)},[]),w=(0,x.useCallback)(async()=>{if(!(e!==`idle`&&e!==`error`)){if(s(null),typeof window<`u`&&!window.isSecureContext){t(`error`),s(`Voice recording requires a secure connection (HTTPS). Use your tunnel URL for voice notes.`);return}if(typeof navigator>`u`||!navigator.mediaDevices?.getUserMedia){t(`error`),s(`Voice recording is not supported in this browser.`);return}if(typeof MediaRecorder>`u`){t(`error`),s(`Voice recording is not supported in this browser.`);return}try{let e=await navigator.mediaDevices.getUserMedia({audio:!0});l.current=e;let n=new AudioContext;h.current=n;let i=n.createMediaStreamSource(e),o=n.createAnalyser();o.fftSize=256,i.connect(o),g.current=o;let s=uu();d.current=s;let f=new MediaRecorder(e,s?{mimeType:s}:void 0);c.current=f,u.current=[],f.ondataavailable=e=>{e.data.size>0&&u.current.push(e.data)},e.getAudioTracks()[0]?.addEventListener(`ended`,()=>{v(),t(`idle`),r(0),a(null)}),f.start(1e3),t(`recording`),r(0),y(),S()}catch(e){v(),t(`error`),e instanceof DOMException?e.name===`NotAllowedError`?s(`Microphone access was denied. Check your browser permissions to enable voice recording.`):e.name===`NotFoundError`?s(`No microphone found. Connect a microphone to use voice recording.`):s(`Microphone error: ${e.message}`):s(`Could not start recording.`)}}},[e,v,y,S]),T=(0,x.useCallback)(()=>{let n=c.current;n&&(e===`recording`&&n.state===`recording`?(n.pause(),b(),C(),t(`paused`)):e===`paused`&&n.state===`paused`&&(n.resume(),y(),S(),t(`recording`)))},[e,b,y,S,C]),E=(0,x.useCallback)(()=>{e!==`recording`&&e!==`paused`||(v(),t(`idle`),r(0),a(null))},[e,v]),D=(0,x.useCallback)(async()=>{if(e!==`recording`&&e!==`paused`)return null;let n=c.current;if(!n)return null;let i=e===`recording`?Date.now()-p.current:0;return m.current+i<1e3?(E(),null):(t(`sending`),b(),C(),new Promise(e=>{n.onstop=()=>{let i=d.current||n.mimeType||`audio/webm`,o=new Blob(u.current,{type:du(i)});v(),t(`idle`),r(0),a(null),e(o.size>0?o:null)},n.stop()}))},[e,E,b,C,v]);return(0,x.useEffect)(()=>{if(e!==`error`)return;let n=setTimeout(()=>{t(`idle`),s(null)},8e3);return()=>clearTimeout(n)},[e]),{state:e,elapsedSeconds:n,waveform:i,errorMessage:o,start:w,togglePause:T,discard:E,send:D}}export{g as A,w as C,y as D,b as E,d as F,u as I,l as L,m as M,p as N,v as O,f as P,E as S,C as T,te as _,nu as a,O as b,$l as c,Il as d,kl as f,M as g,Co as h,au as i,h as j,_ as k,Ql as l,Tl as m,cu as n,tu as o,Al as p,iu as r,eu as s,fu as t,Zl as u,A as v,S as w,D as x,T as y};
|
|
@@ -5,12 +5,12 @@
|
|
|
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-4cZM7db3.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-DnY0498s.js">
|
|
11
11
|
<link rel="modulepreload" crossorigin href="/assets/preload-helper-qlgyTAkD.js">
|
|
12
12
|
<link rel="modulepreload" crossorigin href="/assets/Checkbox-BySsatDO.js">
|
|
13
|
-
<link rel="modulepreload" crossorigin href="/assets/useVoiceRecorder-
|
|
13
|
+
<link rel="modulepreload" crossorigin href="/assets/useVoiceRecorder-CR8gcELb.js">
|
|
14
14
|
<link rel="modulepreload" crossorigin href="/assets/useAdminFetch-B3MO55eB.js">
|
|
15
15
|
<link rel="modulepreload" crossorigin href="/assets/page-Ddc_nKh8.js">
|
|
16
16
|
<link rel="modulepreload" crossorigin href="/assets/page-IQBQoOdT.js">
|
|
@@ -5,12 +5,12 @@
|
|
|
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-DRrf63wm.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-DnY0498s.js">
|
|
11
11
|
<link rel="modulepreload" crossorigin href="/assets/preload-helper-qlgyTAkD.js">
|
|
12
12
|
<link rel="modulepreload" crossorigin href="/assets/Checkbox-BySsatDO.js">
|
|
13
|
-
<link rel="modulepreload" crossorigin href="/assets/useVoiceRecorder-
|
|
13
|
+
<link rel="modulepreload" crossorigin href="/assets/useVoiceRecorder-CR8gcELb.js">
|
|
14
14
|
<link rel="stylesheet" crossorigin href="/assets/jsx-runtime-O5ef8xK8.css">
|
|
15
15
|
<link rel="stylesheet" href="/brand-defaults.css">
|
|
16
16
|
</head>
|