lua-ai-chat 0.0.1 → 0.0.3
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/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {memo,useCallback,createContext,useState,useRef,useEffect,useContext}from'react';import {Logo,MapPin,Button,CreditCard,Dialog,DialogTitle,DialogContent,XIcon,Carousel,CarouselContent,CarouselItem,CarouselPrevious,CarouselNext,IconButton,ArrowUp,Camera,Tooltip,TooltipTrigger,Paperclip,TooltipContent,TooltipArrow,VideoCamera,Microphone}from'@lua-ai-global/luaniverse';import {jsxs,jsx,Fragment}from'react/jsx-runtime';import {VisuallyHidden}from'@radix-ui/react-visually-hidden';import Ft from'react-markdown';import {Highlight,themes}from'prism-react-renderer';import {MapContainer,TileLayer,Marker,Popup}from'react-leaflet';function $l({onAudioRecorded:t,onClose:e,inputMessage:a}){let[l,r]=useState(false),[s,d]=useState(0),[u,n]=useState([]),[p,f]=useState(null),[o,i]=useState(null),h=useRef(null),c=useRef(null),v=useRef([]),g=useRef(null),C=useRef(null),x=useRef(null),N=useRef(null),m=useRef(false),w=useRef(false),U=useRef(null);useEffect(()=>{if(!l||!p)return;let P=setInterval(()=>{let k=Math.floor((Date.now()-p)/1e3);d(k);},1e3);return ()=>clearInterval(P)},[l,p]),useEffect(()=>((async()=>{if(!(m.current||w.current))try{m.current=!0;let k=await navigator.mediaDevices.getUserMedia({audio:!0});h.current=k,g.current=new AudioContext,C.current=g.current.createAnalyser(),C.current.fftSize=256,g.current.createMediaStreamSource(k).connect(C.current),x.current=new Uint8Array(C.current.frequencyBinCount);let q=()=>{if(!C.current||!x.current)return;C.current.getByteFrequencyData(x.current);let Wt=Array.from(x.current).map(Xt=>Xt/255);n(Wt),N.current=requestAnimationFrame(q);};q(),_t();}catch(k){console.error("Error accessing microphone:",k),e();}finally{m.current=false;}})(),()=>{B();}),[]);let B=()=>{if(!w.current)try{if(w.current=!0,l&&c.current&&(c.current.stop(),r(!1),f(null)),h.current){let P=h.current.getAudioTracks(),k=h.current.getVideoTracks();P.forEach(R=>{R.stop(),R.enabled=!1;}),k.forEach(R=>{R.stop(),R.enabled=!1;});}N.current&&cancelAnimationFrame(N.current),g.current&&g.current.close(),h.current=null,c.current=null,v.current=[],g.current=null,C.current=null,x.current=null,N.current=null;}finally{w.current=false;}},_t=()=>{if(!h.current)return;let k=["audio/webm","audio/mp4","audio/ogg","audio/wav"].find(q=>MediaRecorder.isTypeSupported(q));if(!k){console.error("No supported MIME type found for MediaRecorder"),e();return}U.current=k;let R=new MediaRecorder(h.current,{mimeType:k});c.current=R,v.current=[],R.ondataavailable=q=>{q.data.size>0&&v.current.push(q.data);},R.start(),r(true),f(Date.now()),d(0);},jt=async()=>{if(!c.current||!h.current)return;r(false),i(s),f(null),c.current.stop(),await new Promise(k=>{c.current&&(c.current.onstop=()=>k());});let P=new Blob(v.current,{type:U.current||"audio/webm"});t(P,a),B(),e();},mt=P=>{let k=Math.floor(P/60),R=P%60;return `${k.toString().padStart(2,"0")}:${R.toString().padStart(2,"0")}`};return jsxs("div",{className:"audio-recorder-container lua:bg-gray-100 lua:rounded-lg lua:p-2 lua:flex lua:items-center lua:gap-4",children:[jsx(IconButton,{variant:"muted",onClick:async()=>{B(),e();},className:"audio-recorder-close-button lua:flex-shrink-0",children:jsx(XIcon,{className:"audio-recorder-close-icon",color:"#00000099"})}),jsxs("div",{className:"audio-recorder-status lua:flex lua:items-center lua:gap-2",children:[jsx("div",{className:`audio-recorder-indicator lua:w-3 lua:h-3 lua:rounded-full ${l?"lua:bg-red-500 lua:animate-pulse":"lua:bg-gray-400"}`}),jsx("span",{className:"audio-recorder-time lua:text-gray-700 lua:text-sm",children:mt(l?s:o||0)})]}),jsx("div",{className:"audio-recorder-visualizer lua:flex-1","data-testid":"audio-visualizer-bar",children:u.length>0&&jsx("div",{className:"audio-recorder-bars lua:h-8 lua:flex lua:items-center lua:w-full lua:gap-px sm:lua:gap-0.5 md:lua:gap-1",children:u.slice(0,50).map((P,k)=>jsx("div",{className:"audio-recorder-bar lua:flex-1 lua:bg-blue-500",style:{height:`${P*100}%`}},k))})}),jsx(IconButton,{onClick:jt,className:"audio-recorder-send-button lua:flex-shrink-0 lua:mr-1","data-testid":"send-audio-button",children:jsx(ArrowUp,{className:"audio-recorder-send-icon",color:"white"})})]})}function aa(t){let e=Math.floor(t/60),a=t%60;return `${e.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`}function Xl({videoRef:t,isRecording:e,recordingTime:a,loading:l,onStartRecording:r,onStopRecording:s,onClose:d,open:u}){return jsx(Dialog,{open:u,onOpenChange:d,children:jsxs(DialogContent,{className:"lua:w-full lua:max-w-2xl lua:p-2.5",showClose:false,children:[jsx(VisuallyHidden,{children:jsx(DialogTitle,{})}),jsxs("div",{className:"lua:relative lua:aspect-[4/3] lua:bg-black lua:rounded-xl lua:overflow-hidden lua:mb-8",children:[jsx("video",{ref:t,autoPlay:true,playsInline:true,muted:true,className:"lua:absolute lua:inset-0 lua:w-full lua:h-full lua:object-cover",style:{backgroundColor:"black"}}),e&&jsxs("div",{className:"lua:absolute lua:top-4 lua:left-4 lua:flex lua:items-center lua:gap-2 lua:bg-black lua:bg-opacity-50 lua:px-3 lua:py-1 lua:rounded-full",children:[jsx("div",{className:"lua:w-2 lua:h-2 lua:rounded-full lua:bg-red-500 lua:animate-pulse"}),jsx("span",{className:"lua:text-sm lua:font-medium lua:text-white",children:aa(a)})]})]}),jsx("div",{className:"lua:flex lua:justify-center lua:items-center lua:gap-5 lua:mb-2.5",children:e?jsx(IconButton,{"data-testid":"stop-recording-button",onClick:s,disabled:l,variant:"secondary",children:jsx(XIcon,{color:"#000000"})}):jsxs("svg",{onClick:r,"data-testid":"start-recording-button",width:"40",height:"40",viewBox:"0 0 40 40",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"cursor-pointer",children:[jsx("rect",{x:"2",y:"2",width:"36",height:"36",rx:"18",stroke:"#FF0342",strokeWidth:"4"}),jsx("rect",{x:"6",y:"6",width:"28",height:"28",rx:"14",fill:"#FF0342"})]})})]})})}function vt({url:t,alt:e,open:a,onClose:l}){return jsxs(Dialog,{open:a,onOpenChange:l,children:[jsx(VisuallyHidden,{children:jsx(DialogTitle,{})}),jsx(DialogContent,{className:"lua:w-full lua:fixed lua:inset-0 lua:h-full lua:max-w-none lua:p-0 lua:bg-transparent lua:shadow-none lua:translate-x-0 lua:translate-y-0 lua:m-0 lua:rounded-none",showClose:false,children:jsxs("div",{className:"lua:relative lua:w-full lua:h-full",children:[jsx("button",{onClick:l,className:"lua:cursor-pointer lua:absolute lua:top-4 lua:left-4 lua:z-10 lua:p-2 lua:bg-black/50 lua:rounded-full lua:hover:bg-black/70 lua:transition-colors",children:jsx(XIcon,{color:"white",className:"lua:w-6 lua:h-6"})}),jsx("div",{className:"lua:w-full lua:h-full lua:flex lua:items-center lua:justify-center",children:jsx("img",{src:t,alt:e,className:"sm:lua:aspect-[16/9] lua:object-contain lua:rounded-none sm:lua:rounded-lg"})})]})})]})}function yt({images:t,initialIndex:e=0,open:a,onClose:l}){let[r,s]=useState(),[d,u]=useState(0);return useEffect(()=>{if(!r)return;e>0&&e<t.length&&(r.scrollTo(e),u(e));let n=()=>{u(r.selectedScrollSnap());};return r.on("select",n),n(),()=>{r?.off("select",n);}},[r,e,t.length]),jsxs(Dialog,{open:a,onOpenChange:l,children:[jsx(VisuallyHidden,{children:jsx(DialogTitle,{})}),jsx(DialogContent,{className:"lua:w-full lua:m-0",showClose:false,children:jsxs("div",{className:"lua:relative lua:w-full lua:h-full",children:[jsx("button",{onClick:l,className:"lua:cursor-pointer lua:absolute lua:top-4 lua:left-4 lua:z-10 lua:p-2 lua:bg-black/50 lua:rounded-full lua:hover:bg-black/70 lua:transition-colors",children:jsx(XIcon,{color:"white",className:"lua:w-6 lua:h-6"})}),t.length>1&&jsxs("div",{className:"lua:absolute lua:top-4 lua:right-4 lua:z-10 lua:px-3 lua:py-1 lua:bg-black/50 lua:rounded-full lua:text-white lua:text-sm",children:[d+1," / ",t.length]}),jsx("div",{className:"lua:w-full lua:h-full lua:flex lua:items-center lua:justify-center lua:px-16",children:jsxs(Carousel,{setApi:s,className:"lua:w-full lua:max-w-5xl",opts:{align:"center",loop:t.length>1},children:[jsx(CarouselContent,{children:t.map((n,p)=>jsx(CarouselItem,{className:"lua:flex lua:items-center lua:justify-center",children:jsx("img",{src:n.src,alt:n.alt||`Image ${p+1}`,className:"lua:max-w-full lua:max-h-screen lua:object-contain lua:rounded-none sm:lua:rounded-lg",draggable:false})},p))}),t.length>1&&jsxs(Fragment,{children:[jsx(CarouselPrevious,{className:"lua:left-4 lua:bg-black/50 lua:border-none lua:text-white lua:hover:bg-black/70 lua:hover:text-white-white/70"}),jsx(CarouselNext,{className:"lua:right-4 lua:bg-black/50 lua:border-none lua:text-white lua:hover:bg-black/70 lua:hover:text-white-white/70"})]})]})})]})})]})}function ir({videoRef:t,canvasRef:e,onCapture:a,onClose:l,open:r}){return jsxs(Dialog,{open:r,onOpenChange:l,children:[jsx(VisuallyHidden,{children:jsx(DialogTitle,{})}),jsxs(DialogContent,{className:"lua:w-full lua:max-w-2xl lua:p-2.5",showClose:false,children:[jsxs("div",{className:"lua:relative lua:aspect-[16/9] lua:bg-black lua:rounded-xl lua:overflow-hidden",children:[jsx("video",{ref:t,autoPlay:true,playsInline:true,muted:true,className:"lua:absolute lua:inset-0 lua:w-full lua:h-full lua:object-cover",style:{backgroundColor:"black"}}),jsx("canvas",{ref:e,className:"lua:hidden"})]}),jsxs("div",{className:"lua:flex lua:justify-center lua:items-center lua:gap-5 lua:mb-2.5 lua:mt-6",children:[jsx(IconButton,{onClick:a,"data-testid":"capture-button",children:jsx(Camera,{color:"#FFFFFF"})}),jsx(IconButton,{onClick:l,variant:"secondary",children:jsx(XIcon,{color:"#000000"})})]})]})]})}function cr({locationError:t,currentLocation:e,loading:a,onShare:l,onClose:r}){return jsx("div",{className:"lua:fixed lua:inset-0 lua:bg-black lua:bg-opacity-75 lua:flex lua:items-center lua:justify-center lua:z-50",children:jsxs("div",{className:"lua:bg-white lua:rounded-lg lua:p-4 lua:max-w-2xl lua:w-full lua:mx-4",children:[jsxs("div",{className:"lua:flex lua:justify-between lua:items-center lua:mb-4",children:[jsx("h3",{className:"lua:text-lg lua:font-semibold",children:"Share Location"}),jsx("button",{onClick:r,className:"lua:text-gray-500 lua:hover:text-gray-700",children:jsx("svg",{className:"lua:w-6 lua:h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),t?jsx("div",{className:"lua:bg-red-50 lua:text-red-500 lua:p-4 lua:rounded-lg lua:mb-4",children:t}):e?jsx(Fragment,{children:jsxs("div",{className:"lua:mb-4",children:[jsx("div",{className:"lua:text-sm lua:text-gray-500 lua:mb-2",children:"Current Location:"}),jsx("div",{className:"lua:text-gray-700 lua:mb-2",children:e.address}),jsxs("div",{className:"lua:text-sm lua:text-gray-500",children:[e.latitude.toFixed(6),","," ",e.longitude.toFixed(6)]})]})}):jsx("div",{className:"lua:flex lua:justify-center lua:items-center lua:h-48",children:jsx("div",{className:"lua:animate-spin lua:rounded-full lua:h-8 lua:w-8 lua:border-b-2 lua:border-blue-500"})}),jsx("div",{className:"lua:flex lua:justify-center",children:e&&jsxs("button",{onClick:l,disabled:a,className:`lua:px-4 lua:py-2 lua:rounded-full ${a?"lua:bg-blue-300 lua:cursor-not-allowed":"lua:bg-blue-500 lua:hover:bg-blue-600"} lua:text-white lua:flex lua:items-center lua:gap-2`,children:[jsx("svg",{className:"lua:w-5 lua:h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"})}),a?"Sharing...":"Share Location"]})})]})})}function Ct({children:t,language:e=""}){let[a,l]=useState(false),r=typeof t=="string"?t:String(t),s=e||"javascript";return jsxs("div",{className:"lua:relative lua:my-4 lua:rounded-lg lua:overflow-hidden lua:mx-4 lua:sm:mx-5 lua:grid",children:[jsxs("div",{className:"lua:flex lua:items-center lua:justify-between lua:bg-gray-800 lua:text-gray-200 lua:px-4 lua:py-2",children:[jsx("span",{className:"lua:text-xs lua:font-mono",children:s}),jsx("button",{onClick:()=>{navigator.clipboard.writeText(r),l(true),setTimeout(()=>l(false),2e3);},className:"lua:text-xs lua:bg-gray-700 lua:hover:bg-gray-600 lua:rounded lua:px-2 lua:py-1 lua:transition-colors","aria-label":"Copy code",children:a?"Copied!":"Copy"})]}),jsx(Highlight,{theme:themes.vsDark,code:r,language:s,children:({className:u,style:n,tokens:p,getLineProps:f,getTokenProps:o})=>jsx("pre",{className:`${u} lua:p-4 lua:overflow-x-auto`,style:n,children:p.map((i,h)=>jsx("div",{...f({line:i}),children:i.map((c,v)=>jsx("span",{...o({token:c})},v))},h))})})]})}var L={p:"lua:mb-2 lua:last:mb-0 lua:mx-4 lua:sm:mx-5 lua-paragraph-markdown",h1:"lua:text-2xl lua:font-bold lua:mb-2 lua:mx-4 lua:sm:mx-5",h2:"lua:text-xl lua:font-semibold lua:mb-2 lua:text-gray-700 lua:mx-4 lua:sm:mx-5",h3:"lua:text-lg lua:font-medium lua:mb-2 lua:mx-4 lua:sm:mx-5",h4:"lua:mx-4 lua:sm:mx-5",ul:"lua:list-disc lua:pl-6 lua:mb-4",ol:"lua:list-decimal lua:pl-6 lua:mb-4 lua:mx-4 lua:sm:mx-5",li:"lua:mb-1 lua:mx-4 lua:sm:mx-5",a:"lua:text-blue-500 lua:hover:underline",blockquote:"lua:border-l-4 lua:border-gray-200 lua:pl-4 lua:italic lua:my-4",pre:"lua:contents lua:bg-gray-100 lua:rounded lua:px-1 lua:text-gray-700 lua:mx-4 lua:sm:mx-5",code:"lua:bg-gray-100 lua:rounded lua:px-1 lua:mx-4 lua:sm:mx-5",img:"lua:max-w-full lua:h-auto lua:rounded-lg lua:mb-2",table:"lua:min-w-full lua:border lua:border-gray-200 lua:my-4",th:"lua:bg-gray-100 lua:border lua:border-gray-200 lua:px-4 lua:py-2",td:"lua:border lua:border-gray-200 lua:px-4 lua:py-2"};var Aa=t=>({code({children:e,className:a,...l}){let r=a?.replace("language-","")||"";return typeof e=="string"&&!e.includes(`
|
|
2
|
-
`)?jsx("code",{className:L.code,...l,children:e}):jsx(Ct,{language:r,className:a,children:e})},p({children:e,...a}){return jsx("p",{className:L.p,...a,children:e})},h1({children:e,...a}){return jsx("h1",{className:L.h1,...a,children:e})},h2({children:e,...a}){return jsx("h2",{className:L.h2,...a,children:e})},h3({children:e,...a}){return jsx("h3",{className:L.h3,...a,children:e})},h4({children:e,...a}){return jsx("h4",{className:L.h4,...a,children:e})},img({src:e,alt:a}){return jsx("img",{src:e,alt:a,className:"lua:w-full lua:h-48 lua:object-cover lua:rounded-lg lua:mb-3"})},ul({children:e,...a}){return jsx("ul",{className:L.ul,...a,children:e})},ol({children:e,...a}){return jsx("ol",{className:L.ol,...a,children:e})},li({children:e,...a}){return jsx("li",{className:`${L.li} cursor-pointer hover:bg-gray-50 rounded px-2 -mx-2 transition-colors`,onClick:()=>t(e),...a,children:e})},a({href:e,children:a,...l}){return jsx("a",{href:e,className:L.a,target:"_blank",rel:"noopener noreferrer",...l,children:a})},blockquote({children:e,...a}){return jsx("blockquote",{className:L.blockquote,...a,children:e})},pre({children:e}){return jsx(Fragment,{children:e})},table({children:e,...a}){return jsx("table",{className:L.table,...a,children:e})},th({children:e,...a}){return jsx("th",{className:L.th,...a,children:e})},td({children:e,...a}){return jsx("td",{className:L.td,...a,children:e})}}),be=
|
|
1
|
+
import {memo,useCallback,createContext,useState,useRef,useEffect,useContext}from'react';import {Logo,MapPin,Button,CreditCard,Dialog,DialogTitle,DialogContent,XIcon,Carousel,CarouselContent,CarouselItem,CarouselPrevious,CarouselNext,IconButton,ArrowUp,Camera,Tooltip,TooltipTrigger,Paperclip,TooltipContent,TooltipArrow,VideoCamera,Microphone}from'@lua-ai-global/luaniverse';import {jsxs,jsx,Fragment}from'react/jsx-runtime';import {VisuallyHidden}from'@radix-ui/react-visually-hidden';import St from'react-markdown';import {Highlight,themes}from'prism-react-renderer';import {MapContainer,TileLayer,Marker,Popup}from'react-leaflet';function $l({onAudioRecorded:t,onClose:e,inputMessage:a}){let[l,r]=useState(false),[s,d]=useState(0),[u,n]=useState([]),[p,f]=useState(null),[o,i]=useState(null),h=useRef(null),c=useRef(null),v=useRef([]),g=useRef(null),C=useRef(null),x=useRef(null),N=useRef(null),m=useRef(false),w=useRef(false),U=useRef(null);useEffect(()=>{if(!l||!p)return;let P=setInterval(()=>{let k=Math.floor((Date.now()-p)/1e3);d(k);},1e3);return ()=>clearInterval(P)},[l,p]),useEffect(()=>((async()=>{if(!(m.current||w.current))try{m.current=!0;let k=await navigator.mediaDevices.getUserMedia({audio:!0});h.current=k,g.current=new AudioContext,C.current=g.current.createAnalyser(),C.current.fftSize=256,g.current.createMediaStreamSource(k).connect(C.current),x.current=new Uint8Array(C.current.frequencyBinCount);let q=()=>{if(!C.current||!x.current)return;C.current.getByteFrequencyData(x.current);let Wt=Array.from(x.current).map(Xt=>Xt/255);n(Wt),N.current=requestAnimationFrame(q);};q(),_t();}catch(k){console.error("Error accessing microphone:",k),e();}finally{m.current=false;}})(),()=>{B();}),[]);let B=()=>{if(!w.current)try{if(w.current=!0,l&&c.current&&(c.current.stop(),r(!1),f(null)),h.current){let P=h.current.getAudioTracks(),k=h.current.getVideoTracks();P.forEach(A=>{A.stop(),A.enabled=!1;}),k.forEach(A=>{A.stop(),A.enabled=!1;});}N.current&&cancelAnimationFrame(N.current),g.current&&g.current.close(),h.current=null,c.current=null,v.current=[],g.current=null,C.current=null,x.current=null,N.current=null;}finally{w.current=false;}},_t=()=>{if(!h.current)return;let k=["audio/webm","audio/mp4","audio/ogg","audio/wav"].find(q=>MediaRecorder.isTypeSupported(q));if(!k){console.error("No supported MIME type found for MediaRecorder"),e();return}U.current=k;let A=new MediaRecorder(h.current,{mimeType:k});c.current=A,v.current=[],A.ondataavailable=q=>{q.data.size>0&&v.current.push(q.data);},A.start(),r(true),f(Date.now()),d(0);},jt=async()=>{if(!c.current||!h.current)return;r(false),i(s),f(null),c.current.stop(),await new Promise(k=>{c.current&&(c.current.onstop=()=>k());});let P=new Blob(v.current,{type:U.current||"audio/webm"});t(P,a),B(),e();},mt=P=>{let k=Math.floor(P/60),A=P%60;return `${k.toString().padStart(2,"0")}:${A.toString().padStart(2,"0")}`};return jsxs("div",{className:"audio-recorder-container lua:bg-gray-100 lua:rounded-lg lua:p-2 lua:flex lua:items-center lua:gap-4",children:[jsx(IconButton,{variant:"muted",onClick:async()=>{B(),e();},className:"audio-recorder-close-button lua:flex-shrink-0",children:jsx(XIcon,{className:"audio-recorder-close-icon",color:"#00000099"})}),jsxs("div",{className:"audio-recorder-status lua:flex lua:items-center lua:gap-2",children:[jsx("div",{className:`audio-recorder-indicator lua:w-3 lua:h-3 lua:rounded-full ${l?"lua:bg-red-500 lua:animate-pulse":"lua:bg-gray-400"}`}),jsx("span",{className:"audio-recorder-time lua:text-gray-700 lua:text-sm",children:mt(l?s:o||0)})]}),jsx("div",{className:"audio-recorder-visualizer lua:flex-1","data-testid":"audio-visualizer-bar",children:u.length>0&&jsx("div",{className:"audio-recorder-bars lua:h-8 lua:flex lua:items-center lua:w-full lua:gap-px sm:lua:gap-0.5 md:lua:gap-1",children:u.slice(0,50).map((P,k)=>jsx("div",{className:"audio-recorder-bar lua:flex-1 lua:bg-blue-500",style:{height:`${P*100}%`}},k))})}),jsx(IconButton,{onClick:jt,className:"audio-recorder-send-button lua:flex-shrink-0 lua:mr-1","data-testid":"send-audio-button",children:jsx(ArrowUp,{className:"audio-recorder-send-icon",color:"white"})})]})}function aa(t){let e=Math.floor(t/60),a=t%60;return `${e.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`}function Xl({videoRef:t,isRecording:e,recordingTime:a,loading:l,onStartRecording:r,onStopRecording:s,onClose:d,open:u}){return jsx(Dialog,{open:u,onOpenChange:d,children:jsxs(DialogContent,{className:"lua:w-full lua:max-w-2xl lua:p-2.5",showClose:false,children:[jsx(VisuallyHidden,{children:jsx(DialogTitle,{})}),jsxs("div",{className:"lua:relative lua:aspect-[4/3] lua:bg-black lua:rounded-xl lua:overflow-hidden lua:mb-8",children:[jsx("video",{ref:t,autoPlay:true,playsInline:true,muted:true,className:"lua:absolute lua:inset-0 lua:w-full lua:h-full lua:object-cover",style:{backgroundColor:"black"}}),e&&jsxs("div",{className:"lua:absolute lua:top-4 lua:left-4 lua:flex lua:items-center lua:gap-2 lua:bg-black lua:bg-opacity-50 lua:px-3 lua:py-1 lua:rounded-full",children:[jsx("div",{className:"lua:w-2 lua:h-2 lua:rounded-full lua:bg-red-500 lua:animate-pulse"}),jsx("span",{className:"lua:text-sm lua:font-medium lua:text-white",children:aa(a)})]})]}),jsx("div",{className:"lua:flex lua:justify-center lua:items-center lua:gap-5 lua:mb-2.5",children:e?jsx(IconButton,{"data-testid":"stop-recording-button",onClick:s,disabled:l,variant:"secondary",children:jsx(XIcon,{color:"#000000"})}):jsxs("svg",{onClick:r,"data-testid":"start-recording-button",width:"40",height:"40",viewBox:"0 0 40 40",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"cursor-pointer",children:[jsx("rect",{x:"2",y:"2",width:"36",height:"36",rx:"18",stroke:"#FF0342",strokeWidth:"4"}),jsx("rect",{x:"6",y:"6",width:"28",height:"28",rx:"14",fill:"#FF0342"})]})})]})})}function vt({url:t,alt:e,open:a,onClose:l}){return jsxs(Dialog,{open:a,onOpenChange:l,children:[jsx(VisuallyHidden,{children:jsx(DialogTitle,{})}),jsx(DialogContent,{className:"lua:w-full lua:fixed lua:inset-0 lua:h-full lua:max-w-none lua:p-0 lua:bg-transparent lua:shadow-none lua:translate-x-0 lua:translate-y-0 lua:m-0 lua:rounded-none",showClose:false,children:jsxs("div",{className:"lua:relative lua:w-full lua:h-full",children:[jsx("button",{onClick:l,className:"lua:cursor-pointer lua:absolute lua:top-4 lua:left-4 lua:z-10 lua:p-2 lua:bg-black/50 lua:rounded-full lua:hover:bg-black/70 lua:transition-colors",children:jsx(XIcon,{color:"white",className:"lua:w-6 lua:h-6"})}),jsx("div",{className:"lua:w-full lua:h-full lua:flex lua:items-center lua:justify-center",children:jsx("img",{src:t,alt:e,className:"sm:lua:aspect-[16/9] lua:object-contain lua:rounded-none sm:lua:rounded-lg"})})]})})]})}function yt({images:t,initialIndex:e=0,open:a,onClose:l}){let[r,s]=useState(),[d,u]=useState(0);return useEffect(()=>{if(!r)return;e>0&&e<t.length&&(r.scrollTo(e),u(e));let n=()=>{u(r.selectedScrollSnap());};return r.on("select",n),n(),()=>{r?.off("select",n);}},[r,e,t.length]),jsxs(Dialog,{open:a,onOpenChange:l,children:[jsx(VisuallyHidden,{children:jsx(DialogTitle,{})}),jsx(DialogContent,{className:"lua:w-full lua:m-0",showClose:false,children:jsxs("div",{className:"lua:relative lua:w-full lua:h-full",children:[jsx("button",{onClick:l,className:"lua:cursor-pointer lua:absolute lua:top-4 lua:left-4 lua:z-10 lua:p-2 lua:bg-black/50 lua:rounded-full lua:hover:bg-black/70 lua:transition-colors",children:jsx(XIcon,{color:"white",className:"lua:w-6 lua:h-6"})}),t.length>1&&jsxs("div",{className:"lua:absolute lua:top-4 lua:right-4 lua:z-10 lua:px-3 lua:py-1 lua:bg-black/50 lua:rounded-full lua:text-white lua:text-sm",children:[d+1," / ",t.length]}),jsx("div",{className:"lua:w-full lua:h-full lua:flex lua:items-center lua:justify-center lua:px-16",children:jsxs(Carousel,{setApi:s,className:"lua:w-full lua:max-w-5xl",opts:{align:"center",loop:t.length>1},children:[jsx(CarouselContent,{children:t.map((n,p)=>jsx(CarouselItem,{className:"lua:flex lua:items-center lua:justify-center",children:jsx("img",{src:n.src,alt:n.alt||`Image ${p+1}`,className:"lua:max-w-full lua:max-h-screen lua:object-contain lua:rounded-none sm:lua:rounded-lg",draggable:false})},p))}),t.length>1&&jsxs(Fragment,{children:[jsx(CarouselPrevious,{className:"lua:left-4 lua:bg-black/50 lua:border-none lua:text-white lua:hover:bg-black/70 lua:hover:text-white-white/70"}),jsx(CarouselNext,{className:"lua:right-4 lua:bg-black/50 lua:border-none lua:text-white lua:hover:bg-black/70 lua:hover:text-white-white/70"})]})]})})]})})]})}function ir({videoRef:t,canvasRef:e,onCapture:a,onClose:l,open:r}){return jsxs(Dialog,{open:r,onOpenChange:l,children:[jsx(VisuallyHidden,{children:jsx(DialogTitle,{})}),jsxs(DialogContent,{className:"lua:w-full lua:max-w-2xl lua:p-2.5",showClose:false,children:[jsxs("div",{className:"lua:relative lua:aspect-[16/9] lua:bg-black lua:rounded-xl lua:overflow-hidden",children:[jsx("video",{ref:t,autoPlay:true,playsInline:true,muted:true,className:"lua:absolute lua:inset-0 lua:w-full lua:h-full lua:object-cover",style:{backgroundColor:"black"}}),jsx("canvas",{ref:e,className:"lua:hidden"})]}),jsxs("div",{className:"lua:flex lua:justify-center lua:items-center lua:gap-5 lua:mb-2.5 lua:mt-6",children:[jsx(IconButton,{onClick:a,"data-testid":"capture-button",children:jsx(Camera,{color:"#FFFFFF"})}),jsx(IconButton,{onClick:l,variant:"secondary",children:jsx(XIcon,{color:"#000000"})})]})]})]})}function cr({locationError:t,currentLocation:e,loading:a,onShare:l,onClose:r}){return jsx("div",{className:"lua:fixed lua:inset-0 lua:bg-black lua:bg-opacity-75 lua:flex lua:items-center lua:justify-center lua:z-50",children:jsxs("div",{className:"lua:bg-white lua:rounded-lg lua:p-4 lua:max-w-2xl lua:w-full lua:mx-4",children:[jsxs("div",{className:"lua:flex lua:justify-between lua:items-center lua:mb-4",children:[jsx("h3",{className:"lua:text-lg lua:font-semibold",children:"Share Location"}),jsx("button",{onClick:r,className:"lua:text-gray-500 lua:hover:text-gray-700",children:jsx("svg",{className:"lua:w-6 lua:h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),t?jsx("div",{className:"lua:bg-red-50 lua:text-red-500 lua:p-4 lua:rounded-lg lua:mb-4",children:t}):e?jsx(Fragment,{children:jsxs("div",{className:"lua:mb-4",children:[jsx("div",{className:"lua:text-sm lua:text-gray-500 lua:mb-2",children:"Current Location:"}),jsx("div",{className:"lua:text-gray-700 lua:mb-2",children:e.address}),jsxs("div",{className:"lua:text-sm lua:text-gray-500",children:[e.latitude.toFixed(6),","," ",e.longitude.toFixed(6)]})]})}):jsx("div",{className:"lua:flex lua:justify-center lua:items-center lua:h-48",children:jsx("div",{className:"lua:animate-spin lua:rounded-full lua:h-8 lua:w-8 lua:border-b-2 lua:border-blue-500"})}),jsx("div",{className:"lua:flex lua:justify-center",children:e&&jsxs("button",{onClick:l,disabled:a,className:`lua:px-4 lua:py-2 lua:rounded-full ${a?"lua:bg-blue-300 lua:cursor-not-allowed":"lua:bg-blue-500 lua:hover:bg-blue-600"} lua:text-white lua:flex lua:items-center lua:gap-2`,children:[jsx("svg",{className:"lua:w-5 lua:h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"})}),a?"Sharing...":"Share Location"]})})]})})}function Ct({children:t,language:e=""}){let[a,l]=useState(false),r=typeof t=="string"?t:String(t),s=e||"javascript";return jsxs("div",{className:"lua:relative lua:my-4 lua:rounded-lg lua:overflow-hidden lua:mx-4 lua:sm:mx-5 lua:grid",children:[jsxs("div",{className:"lua:flex lua:items-center lua:justify-between lua:bg-gray-800 lua:text-gray-200 lua:px-4 lua:py-2",children:[jsx("span",{className:"lua:text-xs lua:font-mono",children:s}),jsx("button",{onClick:()=>{navigator.clipboard.writeText(r),l(true),setTimeout(()=>l(false),2e3);},className:"lua:text-xs lua:bg-gray-700 lua:hover:bg-gray-600 lua:rounded lua:px-2 lua:py-1 lua:transition-colors","aria-label":"Copy code",children:a?"Copied!":"Copy"})]}),jsx(Highlight,{theme:themes.vsDark,code:r,language:s,children:({className:u,style:n,tokens:p,getLineProps:f,getTokenProps:o})=>jsx("pre",{className:`${u} lua:p-4 lua:overflow-x-auto`,style:n,children:p.map((i,h)=>jsx("div",{...f({line:i}),children:i.map((c,v)=>jsx("span",{...o({token:c})},v))},h))})})]})}var L={p:"lua:mb-2 lua:last:mb-0 lua:mx-4 lua:sm:mx-5 lua-paragraph-markdown",h1:"lua:text-2xl lua:font-bold lua:mb-2 lua:mx-4 lua:sm:mx-5",h2:"lua:text-xl lua:font-semibold lua:mb-2 lua:text-gray-700 lua:mx-4 lua:sm:mx-5",h3:"lua:text-lg lua:font-medium lua:mb-2 lua:mx-4 lua:sm:mx-5",h4:"lua:mx-4 lua:sm:mx-5",ul:"lua:list-disc lua:pl-6 lua:mb-4",ol:"lua:list-decimal lua:pl-6 lua:mb-4 lua:mx-4 lua:sm:mx-5",li:"lua:mb-1 lua:mx-4 lua:sm:mx-5",a:"lua:text-blue-500 lua:hover:underline",blockquote:"lua:border-l-4 lua:border-gray-200 lua:pl-4 lua:italic lua:my-4",pre:"lua:contents lua:bg-gray-100 lua:rounded lua:px-1 lua:text-gray-700 lua:mx-4 lua:sm:mx-5",code:"lua:bg-gray-100 lua:rounded lua:px-1 lua:mx-4 lua:sm:mx-5",img:"lua:max-w-full lua:h-auto lua:rounded-lg lua:mb-2",table:"lua:min-w-full lua:border lua:border-gray-200 lua:my-4",th:"lua:bg-gray-100 lua:border lua:border-gray-200 lua:px-4 lua:py-2",td:"lua:border lua:border-gray-200 lua:px-4 lua:py-2"};var Ra=t=>({code({children:e,className:a,...l}){let r=a?.replace("language-","")||"";return typeof e=="string"&&!e.includes(`
|
|
2
|
+
`)?jsx("code",{className:L.code,...l,children:e}):jsx(Ct,{language:r,className:a,children:e})},p({children:e,...a}){return jsx("p",{className:L.p,...a,children:e})},h1({children:e,...a}){return jsx("h1",{className:L.h1,...a,children:e})},h2({children:e,...a}){return jsx("h2",{className:L.h2,...a,children:e})},h3({children:e,...a}){return jsx("h3",{className:L.h3,...a,children:e})},h4({children:e,...a}){return jsx("h4",{className:L.h4,...a,children:e})},img({src:e,alt:a}){return jsx("img",{src:e,alt:a,className:"lua:w-full lua:h-48 lua:object-cover lua:rounded-lg lua:mb-3"})},ul({children:e,...a}){return jsx("ul",{className:L.ul,...a,children:e})},ol({children:e,...a}){return jsx("ol",{className:L.ol,...a,children:e})},li({children:e,...a}){return jsx("li",{className:`${L.li} cursor-pointer hover:bg-gray-50 rounded px-2 -mx-2 transition-colors`,onClick:()=>t(e),...a,children:e})},a({href:e,children:a,...l}){return jsx("a",{href:e,className:L.a,target:"_blank",rel:"noopener noreferrer",...l,children:a})},blockquote({children:e,...a}){return jsx("blockquote",{className:L.blockquote,...a,children:e})},pre({children:e}){return jsx(Fragment,{children:e})},table({children:e,...a}){return jsx("table",{className:L.table,...a,children:e})},th({children:e,...a}){return jsx("th",{className:L.th,...a,children:e})},td({children:e,...a}){return jsx("td",{className:L.td,...a,children:e})}}),be=Ra;function Ua(t){let e=new URL(t,"http://lua"),a=decodeURIComponent(e.pathname),l={};for(let[r,s]of e.searchParams.entries())l[r]=decodeURIComponent(s);return {pathname:a,queryParams:l}}var we=Ua;function Da(t){let e=t.match(/\[navigate\]\(([^)]+)\)/);return e?e[1]:null}var Nt=Da;var Fa=memo(function({block:e,onCardClick:a,onListItemClick:l,onNavigate:r}){let s=e.content.match(/^#\s+(.+)$/m),d=e.content.match(/!\[.*?]\((.*)\)/),u=s?s[1]:"",n=d?d[1]:null,p=Nt(e.content),f=e.content.replace(/^#\s+.+$/m,"").replace(/!\[.*?]\(.*?\)/g,"").replace(/\[.*?]\(.*?\)/g,"").trim(),o=be(l);return jsxs("div",{onClick:()=>{if(r&&p){let h=we(p);r(h.pathname,{...h.queryParams&&{query:h.queryParams}});}else a(e.content);},className:"chat-list-item group",children:[jsx("div",{className:"lua:absolute lua:inset-0 lua:bg-blue-500 lua:opacity-0 group-hover:lua:opacity-5 lua:rounded-lg lua:transition-opacity lua:duration-200"}),jsxs("div",{className:"chat-list-item-content",children:[n?jsx("div",{className:"chat-list-item-image-wrapper",children:jsx("img",{className:"chat-list-item-image",src:n,alt:u})}):null,jsxs("div",{className:"content-container",children:[jsx("h1",{className:"lua:text-base lua:leading-6 lua:font-semibold lua:text-gray-900 lua:mb-0",children:u}),jsx("div",{className:"lua:text-sm lua:leading-6 lua:font-normal lua:text-gray-600",children:jsx(St,{components:o,children:f})})]})]})]})}),re=Fa;var Ba=memo(function({group:e,onCardClick:a,onListItemClick:l,onNavigate:r}){return jsx("div",{className:"lua:w-full",children:jsx("div",{className:"chat-list-item-container",children:e.map((s,d)=>jsx(re,{block:s,onCardClick:a,onListItemClick:l,onNavigate:r},d))})})}),kt=Ba;function Oa(t){return {icon:()=>null}}function Ne({documents:t}){return t.map(e=>{let l=Oa(new File([],"",{type:e.mimeType})).icon;return jsx("a",{"data-testid":"chat-file-message",href:e.url,target:"_blank",rel:"noopener noreferrer",className:"chat-file-message lua:mx-4 lua:sm:mx-5",children:jsx("div",{className:"lua:flex lua:flex-col lua:gap-8",children:jsxs("div",{className:"chat-file-card lua:flex lua:items-center lua:justify-start lua:p-3 lua:border lua:border-gray-200 lua:rounded-lg lua:bg-white lua:w-80",children:[jsx(l,{className:"lua:w-12 lua:h-12 lua:text-gray-500"}),jsxs("div",{className:"lua:flex lua:flex-col lua:gap-1 lua:pl-2",children:[e.fileName||"File",jsx("span",{className:"lua:text-gray-500 lua:text-sm",children:e.mimeType})]})]})})},e.url)})}function $a(t){let e=[],a=t.split(`
|
|
3
3
|
`).filter(l=>l.trim()!=="");for(let l of a){let r=/\[([^\]]+)\]\(([^)]+)\)\s+filename:([^\s]+)\s+mime:([^\s]+)/g,s;for(;(s=r.exec(l))!==null;){let[,d,u,n,p]=s;e.push({fileName:d.trim(),url:u.trim(),filename:n.trim(),mimeType:p.trim()});}}return e}var De=$a;function Lt({message:t}){return jsx("div",{className:"chat-audio-message lua:flex lua:flex-col lua:mx-4 lua:sm:mx-5","data-testid":"audio-preview",children:jsx("div",{className:"chat-audio-container audio-playback-container lua:relative",children:jsxs("div",{className:"chat-audio-controls lua:flex lua:items-center lua:gap-2 lua:min-w-full",children:[jsx("audio",{src:t.url,controls:true,className:"chat-audio-player lua:h-8",style:{backgroundColor:"transparent",border:"none"}}),t.isUploading&&jsx("div",{className:"chat-audio-upload-overlay lua:absolute lua:inset-0 lua:bg-black lua:bg-opacity-50 lua:rounded-lg lua:flex lua:items-center lua:justify-center",children:jsx("div",{className:"lua:text-white lua:text-sm",children:"Uploading..."})})]})})})}function Ee({url:t}){return jsxs(Button,{onClick:a=>{if(a.preventDefault(),/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)){window.open(t,"_blank","noopener,noreferrer");return}let r=500,s=600,d=window.screen.width/2-r/2,u=window.screen.height/2-s/2,n=window.open(t,"Payment",`width=${r},height=${s},left=${d},top=${u},toolbar=no,menubar=no,scrollbars=yes,resizable=yes`);(!n||n.closed||typeof n.closed>"u")&&window.open(t,"_blank","noopener,noreferrer");},className:"chat-payment-button lua:rounded-xl",children:[jsx(CreditCard,{size:16}),jsx("span",{children:"Open payment"})]})}var ja=t=>t.split(`
|
|
4
|
-
`).filter(a=>a.trim()).filter(a=>a.trim().startsWith("-")).map(a=>({text:a.trim().substring(1).trim(),onClick:a.trim().substring(1).trim()})),
|
|
4
|
+
`).filter(a=>a.trim()).filter(a=>a.trim().startsWith("-")).map(a=>({text:a.trim().substring(1).trim(),onClick:a.trim().substring(1).trim()})),Se=ja;var Wa=t=>{let e=/!\[(.*?)\]\((.*)\)/g,a=[],l;for(;(l=e.exec(t))!==null;)l[1]&&l[2]&&a.push({alt:l[1],src:l[2]});return a},Fe=Wa;var Xa=t=>{let e=/\[.*?\]\((.*?)\)/g,a=[],l;for(;(l=e.exec(t))!==null;)l[1]&&a.push(l[1]);return a},He=Xa;function Be(t){let e=t.match(/!\[([^\]]+)\]\(([^)]+)\)/);if(!e)return null;let[,a,l]=e;return {text:a,url:l}}var Ga=t=>{let e=/\[.*?\]\((.*?)\)/,a=t.match(e);return a?a[1]:null},Oe=Ga;var $e=t=>typeof t=="string"?t:Array.isArray(t)?t.map($e).join(""):typeof t=="object"&&t!==null&&"props"in t?$e(t.props.children):"",Pt=$e;function Ka(t){return t.replace(/([^\n]):::/g,`$1
|
|
5
5
|
:::`)}var Qa=t=>{t=t.replace(/\\n/g,`
|
|
6
6
|
`);let e=[],a="",l="",r="",s="",d="",u="",n="",p="",f=false,o=false,i=false,h=false,c=false,v=false,g=false,x=Ka(t).split(`
|
|
7
7
|
`);for(let N=0;N<x.length;N++){let m=x[N];if(m.trim()==="::: list-item"||m.trim()===":::list-item"){a.trim()&&(e.push({type:"text",content:a.trim()}),a=""),f=true;continue}if(m.trim()==="::: payment"||m.trim()===":::payment"){a.trim()&&(e.push({type:"text",content:a.trim()}),a=""),o=true;continue}if(m.trim()==="::: actions"||m.trim()===":::actions"){a.trim()&&(e.push({type:"text",content:a.trim()}),a=""),i=true;continue}if(m.trim()==="::: images"||m.trim()===":::images"){a.trim()&&(e.push({type:"text",content:a.trim()}),a=""),h=true;continue}if(m.trim()==="::: links"||m.trim()===":::links"){a.trim()&&(e.push({type:"text",content:a.trim()}),a=""),c=true;continue}if(m.trim()==="::: navigate"||m.trim()===":::navigate"){a.trim()&&(e.push({type:"text",content:a.trim()}),a=""),v=true;continue}if(m.trim()==="::: documents"||m.trim()===":::documents"){a.trim()&&(e.push({type:"text",content:a.trim()}),a=""),g=true;continue}if(m.trim()===":::"&&f){e.push({type:"list-item",content:l.trim(),isComplete:true}),l="",f=false;continue}if(m.trim()===":::"&&o){e.push({type:"payment",content:r.trim(),isComplete:true}),r="",o=false;continue}if(m.trim()===":::"&&i){e.push({type:"actions",content:s.trim(),isComplete:true}),s="",i=false;continue}if(m.trim()===":::"&&h){e.push({type:"images",content:d.trim(),isComplete:true}),d="",h=false;continue}if(m.trim()===":::"&&c){e.push({type:"links",content:u.trim(),isComplete:true}),u="",c=false;continue}if(m.trim()===":::"&&v){e.push({type:"navigate",content:n.trim(),isComplete:true}),n="",v=false;continue}if(m.trim()===":::"&&g){e.push({type:"documents",content:p.trim(),isComplete:true}),p="",g=false;continue}f?l+=m+`
|
|
@@ -12,8 +12,8 @@ import {memo,useCallback,createContext,useState,useRef,useEffect,useContext}from
|
|
|
12
12
|
`:v?n+=m+`
|
|
13
13
|
`:g?p+=m+`
|
|
14
14
|
`:a+=m+`
|
|
15
|
-
`;}return f?e.push({type:"list-item",content:l.trim(),isComplete:false}):o?e.push({type:"payment",content:r.trim(),isComplete:false}):i?e.push({type:"actions",content:s.trim(),isComplete:false}):h?e.push({type:"images",content:d.trim(),isComplete:false}):c?e.push({type:"links",content:u.trim(),isComplete:false}):v?e.push({type:"navigate",content:n.trim(),isComplete:false}):g?e.push({type:"documents",content:p.trim(),isComplete:false}):a.trim()&&e.push({type:"text",content:a.trim()}),e},Rt=Qa;function Me({images:t}){let[e,a]=useState(false),[l,r]=useState(0),s=useRef(null),[d,u]=useState(false),[n,p]=useState(0),[f,o]=useState(0),[i,h]=useState(0),c=useCallback(w=>{s.current&&(u(true),p(w.pageX-s.current.offsetLeft),o(s.current.scrollLeft),h(0),w.preventDefault());},[]),v=useCallback(w=>{if(!d||!s.current)return;w.preventDefault();let U=w.pageX-s.current.offsetLeft,B=(U-n)*2;s.current.scrollLeft=f-B,h(Math.abs(U-n));},[d,n,f]),g=useCallback(()=>{u(false);},[]),C=useCallback(()=>{u(false);},[]),x=useCallback((w,U)=>{if(i>5){U.preventDefault();return}r(w),a(true);},[i]);return jsxs("div",{"data-testid":"image-carousel-message",className:"chat-image-carousel-message lua:w-full",children:[jsx("div",{ref:s,className:"chat-image-carousel markdown-image-carousel",style:{cursor:d?"grabbing":"grab"},onMouseDown:c,onMouseMove:v,onMouseUp:g,onMouseLeave:C,onDragStart:w=>{w.preventDefault(),w.stopPropagation();},onDragOver:w=>{w.preventDefault(),w.stopPropagation();},children:t.map((w,U)=>jsx("div",{className:"chat-carousel-image-item markdown-image-item",onClick:B=>x(U,B),children:jsx("img",{src:w.src,alt:w.alt,draggable:false,style:{userSelect:"none"}})},w.src))}),jsx(yt,{images:t,initialIndex:l,open:e,onClose:()=>a(false)})]})}function ze({message:t}){let[e,a]=useState(false);return t.url?jsxs("div",{"data-testid":"image-message",className:"chat-image-message lua:flex lua:flex-col lua:w-3/5 lua:mx-4 lua:sm:mx-5",children:[jsxs("div",{className:"chat-image-container lua:relative",children:[jsx("img",{src:t.url,alt:t.content,className:"chat-image lua:rounded-lg lua:w-full lua:cursor-pointer",onClick:()=>a(true)}),t.isUploading&&jsx("div",{className:"chat-image-upload-overlay lua:absolute lua:inset-0 lua:bg-black lua:bg-opacity-50 lua:rounded-lg lua:flex lua:items-center lua:justify-center",children:jsxs("div",{className:"lua:text-white lua:text-sm",children:["Uploading..."," ",t.uploadProgress?Math.round(t.uploadProgress):0,"%"]})})]}),!t.isUploading&&t.content.length>0&&jsx("div",{className:"chat-image-caption lua:w-full lua:bg-gray-100 lua:text-gray-800 lua:rounded-2xl lua:px-4 lua:p-3 lua:mt-8",children:t.content}),jsx(vt,{url:t.url,alt:t.content,open:e,onClose:()=>a(false)})]}):null}function _e({url:t,luaApiUrl:e,authToken:a,disablePreviewOnLinks:l}){let[r,s]=useState(null),[d,u]=useState(true),[n,p]=useState(null);return useEffect(()=>{t&&e&&!l&&(async()=>{try{u(!0),p(null);let o=a;if(!o)throw new Error("No auth token available");let i=await fetch(`${e}/chat/url-metadata?url=${encodeURIComponent(t)}`,{headers:{Authorization:`Bearer ${o}`}});if(!i.ok)throw new Error(`Failed to fetch preview: ${i.status}`);let h=await i.json();s(h);}catch(o){console.error("Error fetching link preview:",o),p(o instanceof Error?o.message:"Failed to load preview");}finally{u(false);}})();},[t,e]),l?jsx("div",{className:"lua:mb-5 lua:mx-[-30px]",children:jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",children:jsx(Button,{variant:"muted",children:t})})}):d?jsxs("div",{className:"lua:animate-pulse",children:[jsx("div",{className:"lua:bg-gray-300 lua:h-4 lua:w-3/4 lua:mb-2 lua:rounded"}),jsx("div",{className:"lua:bg-gray-300 lua:h-3 lua:w-1/2 lua:rounded"})]}):n||!r?jsx("div",{className:"lua:mb-5 lua:mx-[-30px]",children:jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",children:jsx(Button,{variant:"muted",children:t})})}):jsxs("a",{href:r.url||t,target:"_blank",rel:"noopener noreferrer",className:"lua:block lua:border lua:border-gray-200 lua:rounded-lg lua:p-3 lua:hover:bg-gray-50 lua:transition-colors lua:no-underline lua:max-w-sm",children:[r.image&&jsx("img",{src:r.image,alt:r.title,className:"lua:w-full lua:h-32 lua:object-cover lua:rounded lua:mb-2",onError:f=>{f.currentTarget.style.display="none";}}),jsx("div",{className:"lua:text-sm lua:font-medium lua:text-gray-900 lua:mb-1 lua:line-clamp-2",children:r.title}),r.description&&jsx("div",{className:"lua:text-xs lua:text-gray-600 lua:line-clamp-2",children:r.description}),jsx("div",{className:"lua:text-xs lua:text-gray-400 lua:mt-1 lua:truncate",children:new URL(r.url||t).hostname})]})}function Te({links:t,luaApiUrl:e,authToken:a,disablePreviewOnLinks:l}){return jsx("div",{"data-testid":"link-list-message",className:"chat-link-list-message lua:w-full",children:jsx("div",{className:"chat-links-container lua:space-y-2 lua:mx-4 lua:sm:mx-5",children:t.map(r=>jsx(_e,{url:r,luaApiUrl:e,authToken:a,disablePreviewOnLinks:l},r))})})}function We({location:t}){let e=[t.latitude,t.longitude];return jsx("div",{className:"lua:w-full lua:h-48 lua:rounded-lg lua:overflow-hidden lua:border lua:border-gray-200",children:jsxs(MapContainer,{center:e,zoom:15,scrollWheelZoom:false,className:"lua:w-full lua:h-full",children:[jsx(TileLayer,{attribution:'\xA9 <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',url:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"}),jsx(Marker,{position:e,children:t.address&&jsx(Popup,{children:jsx("div",{children:t.address})})})]})})}function Xe({location:t}){return jsx("div",{className:"lua:w-full lua:h-full lua:bg-gray-200 lua:rounded-lg lua:flex lua:items-center lua:justify-center lua:flex-col",children:t.address&&jsx(We,{location:t})})}function Ge({location:t}){return jsx("div",{className:"lua:w-full lua:h-60 lua:rounded-lg","data-testid":"location-preview",children:jsx(Xe,{location:t})})}function Ke({message:t}){return jsx("div",{"data-testid":"location-message",className:"chat-location-message lua:flex lua:flex-col lua:w-11/12 sm:lua:w-3/5 lua:bg-gray-100 lua:text-gray-800 lua:rounded-2xl lua:p-3 lua:mx-4 lua:sm:mx-5",children:jsxs("div",{className:"chat-location-preview-container location-preview-container lua:relative",children:[t.location&&jsx(Ge,{location:t.location}),t.isUploading&&jsx("div",{className:"chat-location-upload-overlay lua:absolute lua:inset-0 lua:bg-black lua:bg-opacity-50 lua:rounded-lg lua:flex lua:items-center lua:justify-center",children:jsx("div",{className:"lua:text-white lua:text-sm",children:"Sharing location..."})}),jsxs("div",{className:"chat-location-info lua:flex lua:items-center lua:gap-2 lua:mt-3",children:[jsx(MapPin,{fill:"black"}),jsx("div",{className:"lua:flex-1",children:jsx("div",{className:"lua:text-sm",children:t.content})})]})]})})}function Qe({url:t,onNavigate:e}){let[a,l]=useState(false);return useEffect(()=>{if(e&&!a){l(true);let r=we(t);e(r.pathname,{...r.queryParams&&{query:r.queryParams}});}},[a,e]),null}function Ye({message:t}){return jsxs("div",{"data-testid":"video-message",className:"chat-video-message lua:flex lua:flex-col lua:w-3/5 lua:mx-4 lua:sm:mx-5",children:[jsxs("div",{className:"chat-video-container lua:relative",children:[jsx("video",{src:t.url,controls:true,className:"chat-video lua:rounded-lg lua:w-full"}),t.isUploading&&jsx("div",{className:"chat-video-upload-overlay lua:absolute lua:inset-0 lua:bg-black lua:bg-opacity-50 lua:rounded-lg lua:flex lua:items-center lua:justify-center",children:jsxs("div",{className:"lua:text-white lua:text-sm",children:["Uploading..."," ",t.uploadProgress?Math.round(t.uploadProgress):0,"%"]})})]}),!t.isUploading&&t.content&&jsx("div",{className:"chat-video-caption lua:w-full lua:bg-gray-100 lua:text-gray-800 lua:rounded-2xl lua:px-4 lua:p-3 lua:mt-8",children:t.content})]})}function cl(t){return new Date(t).toLocaleTimeString()}function dl(t){return {icon:()=>null}}var nn=memo(function({message:e,onSelect:a,luaApiUrl:l,authToken:r,disablePreviewOnLinks:s=false,onNavigate:d}){let u=useCallback(f=>{let o=f.match(/^#\s+(.+)$/m),i=f.match(/^##\s+(.+)$/m),h=o?o[1]:"",c=i?i[1]:"",v=`${h}. ${c}`;a&&a(v);},[a]),n=useCallback(f=>{if(!a)return;let o=Pt(f).trim();a(o);},[a]),p=useCallback(()=>{if(e.type==="location")return jsx(Ke,{message:e});if(e.mimeType?.startsWith("video"))return e.url?jsx(Ye,{message:{url:e.url,content:e.content||"",isUploading:e.isUploading,uploadProgress:e.uploadProgress}}):null;if(e.mimeType?.startsWith("image"))return e.url?jsx(ze,{message:{url:e.url,content:e.content||"",isUploading:e.isUploading,uploadProgress:e.uploadProgress}}):null;if(e.mimeType?.startsWith("audio"))return jsx(Lt,{message:e});if(e.type==="file"&&e.mimeType){let h=dl(new File([],"",{type:e.mimeType})).icon;return jsx("a",{"data-testid":"chat-file-message",href:e.url,target:"_blank",rel:"noopener noreferrer",className:"chat-file-message lua:mx-4 lua:sm:mx-5",children:jsxs("div",{className:"lua:flex lua:flex-col lua:gap-8",children:[jsxs("div",{className:"chat-file-card lua:flex lua:items-center lua:justify-start lua:p-3 lua:border lua:border-gray-200 lua:rounded-lg lua:bg-white lua:w-80",children:[jsx(h,{className:"lua:w-12 lua:h-12 lua:text-gray-500"}),jsxs("div",{className:"lua:flex lua:flex-col lua:gap-1 lua:pl-2",children:["File",jsx("span",{className:"lua:text-gray-500 lua:text-sm",children:e.mimeType})]})]}),e.content&&jsx("div",{className:"chat-file-content lua:bg-gray-100 lua:rounded-2xl lua:px-4 lua:py-2 lua:w-80",children:jsx("div",{className:"lua:text-sm lua:text-gray-900",children:e.content})})]})})}if(e.role==="user")return e.content;if(e.content==="...")return null;let f=Rt(e.content),o=be(n);return jsx("div",{className:"chat-markdown-content lua:prose lua:prose-sm lua:max-w-none",children:jsx("div",{className:"lua:flex lua:flex-wrap lua:gap-4",children:(()=>{if(f.filter(c=>c.type==="list-item").length>1){let c=[],v=[];return f.forEach(g=>{g.type==="list-item"?v.push(g):(v.length>0&&(c.push(v),v=[]),c.push([g]));}),v.length>0&&c.push(v),c.map((g,C)=>g.length>1&&g[0].type==="list-item"?jsx(kt,{group:g,onCardClick:u,onListItemClick:n,onNavigate:d},C):g.map((x,N)=>{if(x.type==="list-item")return jsx(re,{block:x,onCardClick:u,onListItemClick:n,onNavigate:d},N);if(x.type==="actions")return Fe(x.content).length>0&&x.isComplete,null;if(x.type==="images"){let m=Se(x.content);if(m.length>0)return jsx(Me,{images:m},N)}if(x.type==="links"){let m=He(x.content);return m.length>0&&x.isComplete?jsx(Te,{links:m,luaApiUrl:l||"",authToken:r||"",disablePreviewOnLinks:s},N):null}if(x.type==="navigate"){let m=Be(x.content);return m&&x.isComplete?jsx(Qe,{text:m.text,url:m.url,onNavigate:d},N):null}if(x.type==="documents"){let m=De(x.content);return jsx(Ne,{documents:m},N)}if(x.type==="payment"){let m=Oe(x.content);return m?jsx("div",{className:"chat-payment-message lua:w-full lua:mx-4 lua:sm:mx-5",children:jsx(Ee,{url:m})},N):null}return jsx("div",{className:"chat-markdown-block lua:w-full",children:jsx(Ft,{components:o,children:x.content})},N)}))}return f.map((c,v)=>{if(c.type==="list-item")return jsx(re,{block:c,onCardClick:u,onListItemClick:n,onNavigate:d},v);if(c.type==="actions")return Fe(c.content).length>0&&c.isComplete,null;if(c.type==="images"){let g=Se(c.content);if(g.length>0)return jsx(Me,{images:g},v)}if(c.type==="navigate"){let g=Be(c.content);return g&&c.isComplete?jsx(Qe,{text:g.text,url:g.url,onNavigate:d},v):null}if(c.type==="documents"){let g=De(c.content);return jsx(Ne,{documents:g},v)}if(c.type==="links"){let g=He(c.content);return g.length>0&&c.isComplete?jsx(Te,{links:g,luaApiUrl:l||"",authToken:r||"",disablePreviewOnLinks:s},v):null}if(c.type==="payment"){let g=Oe(c.content);return g?jsx("div",{className:"chat-payment-message lua:w-full lua:mx-4 lua:sm:mx-5 lua:mb-5",children:jsx(Ee,{url:g})},v):null}return jsx("div",{className:"chat-markdown-block lua:w-full",children:jsx(Ft,{components:o,children:c.content})},v)})})()})})},[e,u,n]);return jsxs("div",{className:`chat-message-container lua:flex lua:flex-col ${e.role==="user"?"lua:items-end":"lua:items-start"} lua:gap-1`,children:[jsxs("div",{className:`lua:flex ${e.role==="user"?"lua:justify-end":"lua:justify-start"} lua:items-start lua:gap-2 lua:w-full`,children:[!["file","image","video","tool","location"].includes(e.type||"")&&e.content!=="..."&&jsx("div",{className:`chat-message-bubble ${e.role==="user"?"chat-message-bubble-user lua:max-w-full md:lua:max-w-3/5 lua:bg-gray-100 lua:text-gray-800 lua:rounded-2xl lua:px-4 lua:py-3 lua:mx-4 lua:sm:mx-5 lua:whitespace-pre-wrap":"chat-message-bubble-agent lua:w-full lua:bg-white lua:text-gray-800 lua:rounded-lg lua:py-3 lua:rounded-bl-none"}`,style:{wordBreak:"break-word"},children:p()}),["file","image","video","location"].includes(e.type||"")&&p()]}),jsx("div",{className:`lua-message-timestamp lua:text-xs lua:text-gray-400 lua:px-1 ${e.role==="user"?"lua:mr-4 sm:lua:mr-5":"lua:ml-4 sm:lua:ml-5"}`,children:cl(e.createdAt)})]})});var tt=createContext(void 0),at=createContext(void 0),lt=createContext(void 0),rt=createContext(void 0),ot=createContext(void 0);function mn({children:t}){let[e,a]=useState([]),[l,r]=useState(""),[s,d]=useState(null),[u,n]=useState(false),[p]=useState(new Map),f=useCallback(i=>{if(!p.has(i)){let h=URL.createObjectURL(i);p.set(i,h);}return p.get(i)},[p]),o=useCallback(i=>{let h=p.get(i);h&&(URL.revokeObjectURL(h),p.delete(i));},[p]);return useEffect(()=>()=>{e.forEach(i=>{i.url&&i.url.startsWith("blob:")&&URL.revokeObjectURL(i.url);}),p.forEach(i=>URL.revokeObjectURL(i));},[e,p]),jsx(tt.Provider,{value:{messages:e,setMessages:a},children:jsx(at.Provider,{value:{inputMessage:l,setInputMessage:r},children:jsx(lt.Provider,{value:{loadingMessage:s,setLoadingMessage:d},children:jsx(rt.Provider,{value:{hasUnreadMessages:u,setHasUnreadMessages:n},children:jsx(ot.Provider,{value:{getFileUrl:f,removeFileUrl:o},children:t})})})})})}function pn(){let t=useContext(tt);if(t===void 0)throw new Error("useMessages must be used within a ChatProvider");return t}function Ht(){let t=useContext(at);if(t===void 0)throw new Error("useInput must be used within a ChatProvider");return t}function gn(){let t=useContext(lt);if(t===void 0)throw new Error("useLoadingMessage must be used within a ChatProvider");return t}function fn(){let t=useContext(ot);if(t===void 0)throw new Error("useFileUrls must be used within a ChatProvider");return t}function hn(){let t=useContext(rt);if(t===void 0)throw new Error("useUnreadMessages must be used within a ChatProvider");return t}function $(){let t=useContext(tt),e=useContext(at),a=useContext(lt),l=useContext(rt),r=useContext(ot);if(t===void 0||e===void 0||a===void 0||l===void 0||r===void 0)throw new Error("useChat must be used within a ChatProvider");return {...t,...e,...a,...l,...r}}function wn(){let{loadingMessage:t}=$();return t?jsxs("div",{className:"chat-loading-message lua:flex lua:items-center lua:gap-2 lua:mx-4 lua:sm:mx-5",children:[jsx(Logo,{size:24,className:"chat-loading-logo lua:w-6 lua:h-6 lua:rounded-full lua:flex-shrink-0 lua:animate-spin",style:{animationDuration:"3s"}}),jsx("div",{className:"chat-loading-text lua:text-sm lua:opacity-40",children:t||"Lua is typing..."})]}):null}function Ot({buttons:t,onClick:e}){return jsx("div",{className:"chat-action-message lua:w-full",children:jsx("div",{className:"chat-action-buttons lua:flex lua:gap-2 lua:flex-wrap lua:mx-4 lua:sm:mx-5",children:t.map((a,l)=>jsx(Button,{variant:"tertiary",className:"chat-action-button lua:font-normal lua:rounded-lg lua:py-2 lua:h-auto",onClick:()=>e(a.text),children:a.text},l))})})}var $t=t=>{let e="::: actions",a=":::",l=t.indexOf(e);if(l===-1)return [];let r=t.indexOf(a,l+e.length);return r===-1?[]:t.slice(l+e.length,r).trim().replace(/\\n/g,`
|
|
15
|
+
`;}return f?e.push({type:"list-item",content:l.trim(),isComplete:false}):o?e.push({type:"payment",content:r.trim(),isComplete:false}):i?e.push({type:"actions",content:s.trim(),isComplete:false}):h?e.push({type:"images",content:d.trim(),isComplete:false}):c?e.push({type:"links",content:u.trim(),isComplete:false}):v?e.push({type:"navigate",content:n.trim(),isComplete:false}):g?e.push({type:"documents",content:p.trim(),isComplete:false}):a.trim()&&e.push({type:"text",content:a.trim()}),e},At=Qa;function Me({images:t}){let[e,a]=useState(false),[l,r]=useState(0),s=useRef(null),[d,u]=useState(false),[n,p]=useState(0),[f,o]=useState(0),[i,h]=useState(0),c=useCallback(w=>{s.current&&(u(true),p(w.pageX-s.current.offsetLeft),o(s.current.scrollLeft),h(0),w.preventDefault());},[]),v=useCallback(w=>{if(!d||!s.current)return;w.preventDefault();let U=w.pageX-s.current.offsetLeft,B=(U-n)*2;s.current.scrollLeft=f-B,h(Math.abs(U-n));},[d,n,f]),g=useCallback(()=>{u(false);},[]),C=useCallback(()=>{u(false);},[]),x=useCallback((w,U)=>{if(i>5){U.preventDefault();return}r(w),a(true);},[i]);return jsxs("div",{"data-testid":"image-carousel-message",className:"chat-image-carousel-message lua:w-full",children:[jsx("div",{ref:s,className:"chat-image-carousel markdown-image-carousel",style:{cursor:d?"grabbing":"grab"},onMouseDown:c,onMouseMove:v,onMouseUp:g,onMouseLeave:C,onDragStart:w=>{w.preventDefault(),w.stopPropagation();},onDragOver:w=>{w.preventDefault(),w.stopPropagation();},children:t.map((w,U)=>jsx("div",{className:"chat-carousel-image-item markdown-image-item",onClick:B=>x(U,B),children:jsx("img",{src:w.src,alt:w.alt,draggable:false,style:{userSelect:"none"}})},w.src))}),jsx(yt,{images:t,initialIndex:l,open:e,onClose:()=>a(false)})]})}function ze({message:t}){let[e,a]=useState(false);return t.url?jsxs("div",{"data-testid":"image-message",className:"chat-image-message lua:flex lua:flex-col lua:w-3/5 lua:mx-4 lua:sm:mx-5",children:[jsxs("div",{className:"chat-image-container lua:relative",children:[jsx("img",{src:t.url,alt:t.content,className:"chat-image lua:rounded-lg lua:w-full lua:cursor-pointer",onClick:()=>a(true)}),t.isUploading&&jsx("div",{className:"chat-image-upload-overlay lua:absolute lua:inset-0 lua:bg-black lua:bg-opacity-50 lua:rounded-lg lua:flex lua:items-center lua:justify-center",children:jsxs("div",{className:"lua:text-white lua:text-sm",children:["Uploading..."," ",t.uploadProgress?Math.round(t.uploadProgress):0,"%"]})})]}),!t.isUploading&&t.content.length>0&&jsx("div",{className:"chat-image-caption lua:w-full lua:bg-gray-100 lua:text-gray-800 lua:rounded-2xl lua:px-4 lua:p-3 lua:mt-8",children:t.content}),jsx(vt,{url:t.url,alt:t.content,open:e,onClose:()=>a(false)})]}):null}function _e({url:t,luaApiUrl:e,authToken:a,disablePreviewOnLinks:l}){let[r,s]=useState(null),[d,u]=useState(true),[n,p]=useState(null);return useEffect(()=>{t&&e&&!l&&(async()=>{try{u(!0),p(null);let o=a;if(!o)throw new Error("No auth token available");let i=await fetch(`${e}/chat/url-metadata?url=${encodeURIComponent(t)}`,{headers:{Authorization:`Bearer ${o}`}});if(!i.ok)throw new Error(`Failed to fetch preview: ${i.status}`);let h=await i.json();s(h);}catch(o){console.error("Error fetching link preview:",o),p(o instanceof Error?o.message:"Failed to load preview");}finally{u(false);}})();},[t,e]),l?jsx("div",{className:"lua:mb-5 lua:mx-[-30px]",children:jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",children:jsx(Button,{variant:"muted",children:t})})}):d?jsxs("div",{className:"lua:animate-pulse",children:[jsx("div",{className:"lua:bg-gray-300 lua:h-4 lua:w-3/4 lua:mb-2 lua:rounded"}),jsx("div",{className:"lua:bg-gray-300 lua:h-3 lua:w-1/2 lua:rounded"})]}):n||!r?jsx("div",{className:"lua:mb-5 lua:mx-[-30px]",children:jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",children:jsx(Button,{variant:"muted",children:t})})}):jsxs("a",{href:r.url||t,target:"_blank",rel:"noopener noreferrer",className:"lua:block lua:border lua:border-gray-200 lua:rounded-lg lua:p-3 lua:hover:bg-gray-50 lua:transition-colors lua:no-underline lua:max-w-sm",children:[r.image&&jsx("img",{src:r.image,alt:r.title,className:"lua:w-full lua:h-32 lua:object-cover lua:rounded lua:mb-2",onError:f=>{f.currentTarget.style.display="none";}}),jsx("div",{className:"lua:text-sm lua:font-medium lua:text-gray-900 lua:mb-1 lua:line-clamp-2",children:r.title}),r.description&&jsx("div",{className:"lua:text-xs lua:text-gray-600 lua:line-clamp-2",children:r.description}),jsx("div",{className:"lua:text-xs lua:text-gray-400 lua:mt-1 lua:truncate",children:new URL(r.url||t).hostname})]})}function Te({links:t,luaApiUrl:e,authToken:a,disablePreviewOnLinks:l}){return jsx("div",{"data-testid":"link-list-message",className:"chat-link-list-message lua:w-full",children:jsx("div",{className:"chat-links-container lua:space-y-2 lua:mx-4 lua:sm:mx-5",children:t.map(r=>jsx(_e,{url:r,luaApiUrl:e,authToken:a,disablePreviewOnLinks:l},r))})})}function We({location:t}){let e=[t.latitude,t.longitude];return jsx("div",{className:"lua:w-full lua:h-48 lua:rounded-lg lua:overflow-hidden lua:border lua:border-gray-200",children:jsxs(MapContainer,{center:e,zoom:15,scrollWheelZoom:false,className:"lua:w-full lua:h-full",children:[jsx(TileLayer,{attribution:'\xA9 <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',url:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"}),jsx(Marker,{position:e,children:t.address&&jsx(Popup,{children:jsx("div",{children:t.address})})})]})})}function Xe({location:t}){return jsx("div",{className:"lua:w-full lua:h-full lua:bg-gray-200 lua:rounded-lg lua:flex lua:items-center lua:justify-center lua:flex-col",children:t.address&&jsx(We,{location:t})})}function Ge({location:t}){return jsx("div",{className:"lua:w-full lua:h-60 lua:rounded-lg","data-testid":"location-preview",children:jsx(Xe,{location:t})})}function Ke({message:t}){return jsx("div",{"data-testid":"location-message",className:"chat-location-message lua:flex lua:flex-col lua:w-11/12 sm:lua:w-3/5 lua:bg-gray-100 lua:text-gray-800 lua:rounded-2xl lua:p-3 lua:mx-4 lua:sm:mx-5",children:jsxs("div",{className:"chat-location-preview-container location-preview-container lua:relative",children:[t.location&&jsx(Ge,{location:t.location}),t.isUploading&&jsx("div",{className:"chat-location-upload-overlay lua:absolute lua:inset-0 lua:bg-black lua:bg-opacity-50 lua:rounded-lg lua:flex lua:items-center lua:justify-center",children:jsx("div",{className:"lua:text-white lua:text-sm",children:"Sharing location..."})}),jsxs("div",{className:"chat-location-info lua:flex lua:items-center lua:gap-2 lua:mt-3",children:[jsx(MapPin,{fill:"black"}),jsx("div",{className:"lua:flex-1",children:jsx("div",{className:"lua:text-sm",children:t.content})})]})]})})}function Qe({url:t,onNavigate:e}){let[a,l]=useState(false);return useEffect(()=>{if(e&&!a){l(true);let r=we(t);e(r.pathname,{...r.queryParams&&{query:r.queryParams}});}},[a,e]),null}function Ye({message:t}){return jsxs("div",{"data-testid":"video-message",className:"chat-video-message lua:flex lua:flex-col lua:w-3/5 lua:mx-4 lua:sm:mx-5",children:[jsxs("div",{className:"chat-video-container lua:relative",children:[jsx("video",{src:t.url,controls:true,className:"chat-video lua:rounded-lg lua:w-full"}),t.isUploading&&jsx("div",{className:"chat-video-upload-overlay lua:absolute lua:inset-0 lua:bg-black lua:bg-opacity-50 lua:rounded-lg lua:flex lua:items-center lua:justify-center",children:jsxs("div",{className:"lua:text-white lua:text-sm",children:["Uploading..."," ",t.uploadProgress?Math.round(t.uploadProgress):0,"%"]})})]}),!t.isUploading&&t.content&&jsx("div",{className:"chat-video-caption lua:w-full lua:bg-gray-100 lua:text-gray-800 lua:rounded-2xl lua:px-4 lua:p-3 lua:mt-8",children:t.content})]})}function cl(t){return new Date(t).toLocaleTimeString()}function dl(t){return {icon:()=>null}}var nn=memo(function({message:e,onSelect:a,luaApiUrl:l,authToken:r,disablePreviewOnLinks:s=false,onNavigate:d}){let u=useCallback(f=>{let o=f.match(/^#\s+(.+)$/m),i=f.match(/^##\s+(.+)$/m),h=o?o[1]:"",c=i?i[1]:"",v=`${h}. ${c}`;a&&a(v);},[a]),n=useCallback(f=>{if(!a)return;let o=Pt(f).trim();a(o);},[a]),p=useCallback(()=>{if(e.type==="location")return jsx(Ke,{message:e});if(e.mimeType?.startsWith("video"))return e.url?jsx(Ye,{message:{url:e.url,content:e.content||"",isUploading:e.isUploading,uploadProgress:e.uploadProgress}}):null;if(e.mimeType?.startsWith("image"))return e.url?jsx(ze,{message:{url:e.url,content:e.content||"",isUploading:e.isUploading,uploadProgress:e.uploadProgress}}):null;if(e.mimeType?.startsWith("audio"))return jsx(Lt,{message:e});if(e.type==="file"&&e.mimeType){let h=dl(new File([],"",{type:e.mimeType})).icon;return jsx("a",{"data-testid":"chat-file-message",href:e.url,target:"_blank",rel:"noopener noreferrer",className:"chat-file-message lua:mx-4 lua:sm:mx-5",children:jsxs("div",{className:"lua:flex lua:flex-col lua:gap-8",children:[jsxs("div",{className:"chat-file-card lua:flex lua:items-center lua:justify-start lua:p-3 lua:border lua:border-gray-200 lua:rounded-lg lua:bg-white lua:w-80",children:[jsx(h,{className:"lua:w-12 lua:h-12 lua:text-gray-500"}),jsxs("div",{className:"lua:flex lua:flex-col lua:gap-1 lua:pl-2",children:["File",jsx("span",{className:"lua:text-gray-500 lua:text-sm",children:e.mimeType})]})]}),e.content&&jsx("div",{className:"chat-file-content lua:bg-gray-100 lua:rounded-2xl lua:px-4 lua:py-2 lua:w-80",children:jsx("div",{className:"lua:text-sm lua:text-gray-900",children:e.content})})]})})}if(e.role==="user")return e.content;if(e.content==="...")return null;let f=At(e.content),o=be(n);return jsx("div",{className:"chat-markdown-content lua:prose lua:prose-sm lua:max-w-none",children:jsx("div",{className:"lua:flex lua:flex-wrap lua:gap-4",children:(()=>{if(f.filter(c=>c.type==="list-item").length>1){let c=[],v=[];return f.forEach(g=>{g.type==="list-item"?v.push(g):(v.length>0&&(c.push(v),v=[]),c.push([g]));}),v.length>0&&c.push(v),c.map((g,C)=>g.length>1&&g[0].type==="list-item"?jsx(kt,{group:g,onCardClick:u,onListItemClick:n,onNavigate:d},C):g.map((x,N)=>{if(x.type==="list-item")return jsx(re,{block:x,onCardClick:u,onListItemClick:n,onNavigate:d},N);if(x.type==="actions")return Se(x.content).length>0&&x.isComplete,null;if(x.type==="images"){let m=Fe(x.content);if(m.length>0)return jsx(Me,{images:m},N)}if(x.type==="links"){let m=He(x.content);return m.length>0&&x.isComplete?jsx(Te,{links:m,luaApiUrl:l||"",authToken:r||"",disablePreviewOnLinks:s},N):null}if(x.type==="navigate"){let m=Be(x.content);return m&&x.isComplete?jsx(Qe,{text:m.text,url:m.url,onNavigate:d},N):null}if(x.type==="documents"){let m=De(x.content);return jsx(Ne,{documents:m},N)}if(x.type==="payment"){let m=Oe(x.content);return m?jsx("div",{className:"chat-payment-message lua:w-full lua:mx-4 lua:sm:mx-5",children:jsx(Ee,{url:m})},N):null}return jsx("div",{className:"chat-markdown-block lua:w-full",children:jsx(St,{components:o,children:x.content})},N)}))}return f.map((c,v)=>{if(c.type==="list-item")return jsx(re,{block:c,onCardClick:u,onListItemClick:n,onNavigate:d},v);if(c.type==="actions")return Se(c.content).length>0&&c.isComplete,null;if(c.type==="images"){let g=Fe(c.content);if(g.length>0)return jsx(Me,{images:g},v)}if(c.type==="navigate"){let g=Be(c.content);return g&&c.isComplete?jsx(Qe,{text:g.text,url:g.url,onNavigate:d},v):null}if(c.type==="documents"){let g=De(c.content);return jsx(Ne,{documents:g},v)}if(c.type==="links"){let g=He(c.content);return g.length>0&&c.isComplete?jsx(Te,{links:g,luaApiUrl:l||"",authToken:r||"",disablePreviewOnLinks:s},v):null}if(c.type==="payment"){let g=Oe(c.content);return g?jsx("div",{className:"chat-payment-message lua:w-full lua:mx-4 lua:sm:mx-5 lua:mb-5",children:jsx(Ee,{url:g})},v):null}return jsx("div",{className:"chat-markdown-block lua:w-full",children:jsx(St,{components:o,children:c.content})},v)})})()})})},[e,u,n]);return jsxs("div",{className:`chat-message-container lua:flex lua:flex-col ${e.role==="user"?"lua:items-end":"lua:items-start"} lua:gap-1`,children:[jsxs("div",{className:`lua:flex ${e.role==="user"?"lua:justify-end":"lua:justify-start"} lua:items-start lua:gap-2 lua:w-full`,children:[!["file","image","video","tool","location"].includes(e.type||"")&&e.content!=="..."&&jsx("div",{className:`chat-message-bubble ${e.role==="user"?"chat-message-bubble-user lua:max-w-full md:lua:max-w-3/5 lua:bg-gray-100 lua:text-gray-800 lua:rounded-2xl lua:px-4 lua:py-3 lua:mx-4 lua:sm:mx-5 lua:whitespace-pre-wrap":"chat-message-bubble-agent lua:w-full lua:bg-white lua:text-gray-800 lua:rounded-lg lua:py-3 lua:rounded-bl-none"}`,style:{wordBreak:"break-word"},children:p()}),["file","image","video","location"].includes(e.type||"")&&p()]}),jsx("div",{className:`lua-message-timestamp lua:text-xs lua:text-gray-400 lua:px-1 ${e.role==="user"?"lua:mr-4 sm:lua:mr-5":"lua:ml-4 sm:lua:ml-5"}`,children:cl(e.createdAt)})]})});var tt=createContext(void 0),at=createContext(void 0),lt=createContext(void 0),rt=createContext(void 0),ot=createContext(void 0);function mn({children:t}){let[e,a]=useState([]),[l,r]=useState(""),[s,d]=useState(null),[u,n]=useState(false),[p]=useState(new Map),f=useCallback(i=>{if(!p.has(i)){let h=URL.createObjectURL(i);p.set(i,h);}return p.get(i)},[p]),o=useCallback(i=>{let h=p.get(i);h&&(URL.revokeObjectURL(h),p.delete(i));},[p]);return useEffect(()=>()=>{e.forEach(i=>{i.url&&i.url.startsWith("blob:")&&URL.revokeObjectURL(i.url);}),p.forEach(i=>URL.revokeObjectURL(i));},[e,p]),jsx(tt.Provider,{value:{messages:e,setMessages:a},children:jsx(at.Provider,{value:{inputMessage:l,setInputMessage:r},children:jsx(lt.Provider,{value:{loadingMessage:s,setLoadingMessage:d},children:jsx(rt.Provider,{value:{hasUnreadMessages:u,setHasUnreadMessages:n},children:jsx(ot.Provider,{value:{getFileUrl:f,removeFileUrl:o},children:t})})})})})}function pn(){let t=useContext(tt);if(t===void 0)throw new Error("useMessages must be used within a ChatProvider");return t}function Ht(){let t=useContext(at);if(t===void 0)throw new Error("useInput must be used within a ChatProvider");return t}function gn(){let t=useContext(lt);if(t===void 0)throw new Error("useLoadingMessage must be used within a ChatProvider");return t}function fn(){let t=useContext(ot);if(t===void 0)throw new Error("useFileUrls must be used within a ChatProvider");return t}function hn(){let t=useContext(rt);if(t===void 0)throw new Error("useUnreadMessages must be used within a ChatProvider");return t}function $(){let t=useContext(tt),e=useContext(at),a=useContext(lt),l=useContext(rt),r=useContext(ot);if(t===void 0||e===void 0||a===void 0||l===void 0||r===void 0)throw new Error("useChat must be used within a ChatProvider");return {...t,...e,...a,...l,...r}}function wn(){let{loadingMessage:t}=$();return t?jsxs("div",{className:"chat-loading-message lua:flex lua:items-center lua:gap-2 lua:mx-4 lua:sm:mx-5",children:[jsx(Logo,{size:24,className:"chat-loading-logo lua:w-6 lua:h-6 lua:rounded-full lua:flex-shrink-0 lua:animate-spin",style:{animationDuration:"3s"}}),jsx("div",{className:"chat-loading-text lua:text-sm lua:opacity-40",children:t||"Lua is typing..."})]}):null}function Ot({buttons:t,onClick:e}){return jsx("div",{className:"chat-action-message lua:w-full",children:jsx("div",{className:"chat-action-buttons lua:flex lua:gap-2 lua:flex-wrap lua:mx-4 lua:sm:mx-5",children:t.map((a,l)=>jsx(Button,{variant:"tertiary",className:"chat-action-button lua:font-normal lua:rounded-lg lua:py-2 lua:h-auto",onClick:()=>e(a.text),children:a.text},l))})})}var $t=t=>{let e="::: actions",l=t.indexOf(e);if(l===-1)return [];let r=t.indexOf(":::",l+e.length);return r===-1?[]:t.slice(l+e.length,r).trim().replace(/\\n/g,`
|
|
16
16
|
`).split(`
|
|
17
|
-
`).map(f=>f.trim()).filter(f=>f&&f.startsWith("-")).map(f=>({text:f.replace(/^-[\s]?/,"").trim(),onClick:f.replace(/^-[\s]?/,"").trim()}))};function In({onSelect:t}){let{messages:e}=$();if(e.length===0)return null;let a=e[e.length-1],l=$t(a.content);return l.length===0?null:jsx(Ot,{buttons:l,onClick:t})}var ei=memo(function({onSend:e,disabled:a=false,onFilePaste:l}){let{inputMessage:r,setInputMessage:s}=Ht(),[d,u]=useState(false),n=useRef(null);useEffect(()=>{let o=()=>{u(window.matchMedia("(max-width: 768px)").matches||/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));};return o(),window.addEventListener("resize",o),()=>{window.removeEventListener("resize",o);}},[]),useEffect(()=>{let o=n.current;o&&(a||(o.style.height="auto",o.style.height=`${o.scrollHeight}px`));},[r]);let p=o=>{if(o.key==="Enter"){if(d||o.shiftKey||o.metaKey||o.ctrlKey)return;o.preventDefault(),e();}},f=useCallback(o=>{let{items:i}=o.clipboardData;if(!i||!l)return;let h=[];for(let c=0;c<i.length;c++){let v=i[c];if(v.kind==="file"){let g=v.getAsFile();g&&h.push(g);}}h.length>0&&(o.preventDefault(),l(h));},[l]);return jsxs("div",{className:"lua:flex lua:gap-3 lua:py-2 lua:px-3 lua:items-start",children:[jsx(Logo,{size:32,className:"lua:w-8 lua:h-8 lua:rounded-full lua:flex-shrink-0 lua:m-1"}),jsx("div",{className:"lua:flex-1 lua:flex",children:jsx("textarea",{ref:n,disabled:a,value:r,onChange:o=>s(o.target.value),onKeyDown:p,onPaste:f,placeholder:a?"This conversation's chat window has already been closed":"Reply to user",className:`lua:w-full lua:pl-0 lua:pr-4 lua:py-2 lua:resize-none lua:overflow-y-auto lua:border-none lua:focus:outline-none lua:focus:ring-0 lua:text-gray-700 lua:min-h-10 lua:max-h-48 lua:bg-white${a?" lua:cursor-not-allowed lua:h-14":""}`,rows:1})})]})});async function Q(t,e,a){throw new Error("No auth token found");}function Tl(t){let e=t.type,a="File";return e.startsWith("image/")?a="Image":e.startsWith("video/")?a="Video":e.startsWith("audio/")&&(a="Audio"),{icon:()=>null,label:a}}function ut({file:t,onRemove:e,cdnUrl:a,initialUrl:l,onUploadComplete:r}){let s=Tl(t),d=s.icon,[u,n]=useState(false),[p,f]=useState(0),[o,i]=useState(l||null),h=useRef(false);return useEffect(()=>{if(o||h.current)return;(async()=>{n(true),h.current=true;try{let{fileId:v}=await Q(t,a,C=>{f(C);}),g=`${a}/${v}`;i(g),n(!1),r&&r(t,g);}catch(v){console.error("Upload failed for file:",t.name,v),n(false),h.current=false;}})();},[t,a,r,o]),jsxs("div",{className:"lua:flex lua:items-center lua:gap-4 lua:p-3 lua:bg-white lua:border lua:border-gray-200 lua:rounded-lg",children:[jsx("div",{className:"lua:flex-shrink-0",children:u?jsxs("div",{className:"lua:w-8 lua:h-8 lua:flex lua:flex-col lua:items-center lua:justify-center",children:[jsx("div",{className:"lua:w-6 lua:h-6 lua:border-2 lua:border-t-blue-500 lua:border-r-transparent lua:border-b-transparent lua:border-l-transparent lua:rounded-full lua:animate-spin"}),jsxs("div",{className:"lua:mt-1 lua:text-xs lua:text-gray-600 lua:font-medium",children:[Math.round(p),"%"]})]}):jsx(d,{className:"lua:w-8 lua:h-8 lua:text-gray-600"})}),jsxs("div",{className:"lua:flex-grow lua:min-w-0",children:[jsx("p",{className:"lua:text-sm lua:font-medium lua:text-gray-900 lua:truncate",children:t.name}),jsx("p",{className:"lua:text-xs lua:text-gray-500",children:s.label})]}),jsx("button",{onClick:e,className:"lua:flex-shrink-0 lua:w-6 lua:h-6 lua:flex lua:items-center lua:justify-center lua:rounded-full lua:bg-black lua:text-white lua:hover:bg-gray-800 lua:transition-colors",children:jsx(XIcon,{className:"lua:w-4 lua:h-4"})})]})}function ct({file:t,onRemove:e,cdnUrl:a,initialUrl:l,onUploadComplete:r}){let{getFileUrl:s}=$(),[d,u]=useState(false),[n,p]=useState(0),[f,o]=useState(l||null),[i,h]=useState(false);useEffect(()=>{if(l||i)return;(async()=>{u(true),h(true);try{let{fileId:g}=await Q(t,a,x=>{p(x);}),C=`${a}/${g}`;o(C),u(!1),r&&r(t,C);}catch(g){console.error("Upload failed:",g),u(false);}})();},[t,l,a,i,r]);let c=f||(d?void 0:s(t));return jsxs("div",{className:"lua:relative lua:flex-shrink-0",children:[d?jsxs("div",{className:"lua:w-32 lua:h-32 lua:bg-gray-100 lua:rounded-lg lua:flex lua:flex-col lua:items-center lua:justify-center",children:[jsx("div",{className:"lua:w-8 lua:h-8 lua:border-2 lua:border-t-blue-500 lua:border-r-transparent lua:border-b-transparent lua:border-l-transparent lua:rounded-full lua:animate-spin"}),jsxs("div",{className:"lua:mt-2 lua:text-xs lua:text-gray-600 lua:font-medium",children:[Math.round(n),"%"]})]}):c?jsx("img",{"data-testid":"image-thumbnail",src:c,alt:t.name,className:"lua:w-32 lua:h-32 lua:object-cover lua:rounded-lg"}):jsx("div",{className:"lua:w-32 lua:h-32 lua:bg-gray-200 lua:rounded-lg lua:flex lua:items-center lua:justify-center",children:jsx("span",{className:"lua:text-gray-500",children:"No preview"})}),jsxs("div",{className:"lua:absolute lua:bottom-1 lua:left-1 lua:px-1.5 lua:py-0.5 lua:rounded lua:bg-black/50 lua:text-white lua:text-xs",children:[Math.floor(t.size/1024/1024),"MB"]}),jsx("button",{onClick:()=>e(),className:"lua:absolute lua:top-1 lua:right-1 lua:w-6 lua:h-6 lua:flex lua:items-center lua:justify-center lua:rounded-full lua:bg-black lua:text-white lua:hover:bg-gray-800 lua:transition-colors",children:jsx("span",{className:"lua:text-sm",children:"\xD7"})})]})}function dt({file:t,onRemove:e,cdnUrl:a,initialUrl:l,thumbnailUrl:r,onUploadComplete:s}){let{getFileUrl:d}=$(),[u,n]=useState(false),[p,f]=useState(0),[o,i]=useState(l||null),[h,c]=useState(false),[v,g]=useState(r||null);return useEffect(()=>{if(!r&&!v){let C=d(t),x=document.createElement("video");x.src=C;let N=()=>{try{x.currentTime=0,setTimeout(()=>{let m=document.createElement("canvas");m.width=x.videoWidth,m.height=x.videoHeight;let w=m.getContext("2d");if(!w){console.error("Could not get canvas context");return}w.drawImage(x,0,0);let U=m.toDataURL("image/jpeg",.8);g(U);},100);}catch(m){console.error("Error generating thumbnail:",m);}finally{URL.revokeObjectURL(C),x.removeEventListener("canplay",N);}};x.addEventListener("canplay",N),x.load();}},[t,r,v]),useEffect(()=>{if(l||h)return;(async()=>{n(true),c(true);try{let{fileId:x}=await Q(t,a,m=>{f(m);}),N=`${a}/${x}`;i(N),n(!1),s&&s(t,N);}catch(x){console.error("Upload failed:",x),n(false);}})();},[t,l,a,h,s]),jsxs("div",{className:"lua:relative lua:flex-shrink-0",children:[u?jsxs("div",{className:"lua:w-32 lua:h-32 lua:bg-gray-100 lua:rounded-lg lua:flex lua:flex-col lua:items-center lua:justify-center",children:[jsx("div",{className:"lua:w-8 lua:h-8 lua:border-2 lua:border-t-blue-500 lua:border-r-transparent lua:border-b-transparent lua:border-l-transparent lua:rounded-full lua:animate-spin"}),jsxs("div",{className:"lua:mt-2 lua:text-xs lua:text-gray-600 lua:font-medium",children:[Math.round(p),"%"]})]}):jsxs("div",{className:"lua:relative",children:[jsx("img",{"data-testid":"video-thumbnail",src:v||o||"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",alt:t.name,className:"lua:w-32 lua:h-32 lua:object-cover lua:rounded-lg lua:bg-gray-100"}),jsx("div",{className:"lua:absolute lua:inset-0 lua:flex lua:items-center lua:justify-center",children:jsx("div",{className:"lua:w-10 lua:h-10 lua:rounded-full lua:bg-black/50 lua:flex lua:items-center lua:justify-center",children:jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:jsx("path",{d:"M5 3L19 12L5 21V3Z",fill:"white"})})})})]}),jsxs("div",{className:"lua:absolute lua:bottom-1 lua:left-1 lua:px-1.5 lua:py-0.5 lua:rounded lua:bg-black/50 lua:text-white lua:text-xs",children:[Math.floor(t.size/1024/1024),"MB"]}),jsx("button",{onClick:()=>e(),className:"lua:absolute lua:top-1 lua:right-1 lua:w-6 lua:h-6 lua:flex lua:items-center lua:justify-center lua:rounded-full lua:bg-black lua:text-white lua:hover:bg-gray-800 lua:transition-colors",children:jsx("span",{className:"lua:text-sm",children:"\xD7"})})]})}function qt(t){let e=t.type,a="other",l="File";return e.startsWith("image/")?(a="image",l="Image"):e.startsWith("video/")?(a="video",l="Video"):e.startsWith("audio/")&&(a="audio",l="Audio"),{category:a,icon:()=>null,label:l}}function Ni({files:t,onRemove:e,cdnUrl:a,fileMetadata:l=[],onFileUploadComplete:r}){let[s,d]=useState({});return useEffect(()=>{t.forEach((u,n)=>{let p=qt(u),f=l.find(o=>o.file===u);if(p.category==="video"&&!s[n]&&!f){let o=URL.createObjectURL(u),i=document.createElement("video");i.src=o;let h=()=>{try{i.currentTime=0,setTimeout(()=>{let c=document.createElement("canvas");c.width=i.videoWidth,c.height=i.videoHeight;let v=c.getContext("2d");if(!v){console.error("Could not get canvas context");return}v.drawImage(i,0,0);let g=c.toDataURL("image/jpeg",.8);d(C=>({...C,[n]:g}));},100);}catch(c){console.error("Error generating thumbnail:",c);}finally{URL.revokeObjectURL(o),i.removeEventListener("canplay",h);}};i.addEventListener("canplay",h),i.load();}});},[t,l]),t.length===0?null:jsx("div",{className:"lua:px-4 lua:py-2 lua:border-b lua:border-gray-200",children:jsx("div",{className:"lua:flex lua:gap-2 lua:overflow-x-auto scrollbar-hide",children:t.map((u,n)=>{let p=qt(u),f=l.find(o=>o.file===u);return t.length>1?jsx("div",{className:"lua:flex-shrink-0 lua:w-64",children:jsx(ut,{file:u,onRemove:()=>e(n),cdnUrl:a,onUploadComplete:(o,i)=>{r&&r(o,i);}})},n):p.category==="image"?jsx(ct,{file:u,onRemove:()=>e(n),cdnUrl:a,initialUrl:f?.url,onUploadComplete:(o,i)=>{r&&r(o,i);}},u.name):p.category==="video"?jsx(dt,{file:u,onRemove:()=>e(n),cdnUrl:a,initialUrl:f?.url,thumbnailUrl:s[n],onUploadComplete:(o,i)=>{r&&r(o,i);}},u.name):jsx("div",{className:"lua:flex-shrink-0 lua:w-64",children:jsx(ut,{file:u,onRemove:()=>e(n),cdnUrl:a,onUploadComplete:(o,i)=>{r&&r(o,i);}})},n)})})})}var Y={CHAT:{TOOLBAR_ACTION:{FILE_UPLOAD:"file_upload",CAMERA:"camera",VIDEO:"video",AUDIO:"audio",LOCATION:"location"},MESSAGE_SENT:"message_sent"}};function ee(t){console.log("Analytics event:",t);}function Ti({loading:t,onFileClick:e,onCameraClick:a,onVideoClick:l,onAudioClick:r,onLocationClick:s,onSendClick:d}){return jsxs("div",{className:"lua:flex lua:items-center lua:justify-between lua:border-t lua:border-gray-200 lua:bg-gray-50 lua:px-3 lua:py-2",children:[jsxs("div",{className:"lua:flex lua:items-center lua:gap-2",children:[jsxs(Tooltip,{children:[jsx(TooltipTrigger,{asChild:true,children:jsx(IconButton,{className:"lua:rounded-lg",variant:"muted",onClick:()=>{ee(Y.CHAT.TOOLBAR_ACTION.FILE_UPLOAD),e();},disabled:t,"data-testid":"file-upload-button",children:jsx(Paperclip,{color:"#00000099"})})}),jsxs(TooltipContent,{children:[jsx(TooltipArrow,{}),jsx("p",{children:"Attach files"})]})]}),jsx("div",{className:"lua:w-px lua:h-5 lua:bg-gray-200"}),jsxs(Tooltip,{children:[jsx(TooltipTrigger,{asChild:true,children:jsx(IconButton,{className:"lua:rounded-lg",variant:"muted",onClick:()=>{ee(Y.CHAT.TOOLBAR_ACTION.CAMERA),a();},disabled:t,"data-testid":"camera-button",children:jsx(Camera,{color:"#00000099"})})}),jsxs(TooltipContent,{children:[jsx(TooltipArrow,{}),jsx("p",{children:"Take a picture"})]})]}),jsxs(Tooltip,{children:[jsx(TooltipTrigger,{asChild:true,children:jsx(IconButton,{className:"lua:rounded-lg",variant:"muted",onClick:()=>{ee(Y.CHAT.TOOLBAR_ACTION.VIDEO),l();},disabled:t,"data-testid":"video-button",children:jsx(VideoCamera,{color:"#00000099"})})}),jsxs(TooltipContent,{children:[jsx(TooltipArrow,{}),jsx("p",{children:"Record video"})]})]}),jsxs(Tooltip,{children:[jsx(TooltipTrigger,{asChild:true,children:jsx(IconButton,{className:"lua:rounded-lg",variant:"muted",onClick:()=>{ee(Y.CHAT.TOOLBAR_ACTION.AUDIO),r();},disabled:t,"data-testid":"audio-button",children:jsx(Microphone,{color:"#00000099"})})}),jsxs(TooltipContent,{children:[jsx(TooltipArrow,{}),jsx("p",{children:"Record voice message"})]})]}),jsx("div",{className:"lua:w-px lua:h-5 lua:bg-gray-200"}),jsxs(Tooltip,{children:[jsx(TooltipTrigger,{asChild:true,children:jsx(IconButton,{className:"lua:rounded-lg",variant:"muted",onClick:()=>{ee(Y.CHAT.TOOLBAR_ACTION.LOCATION),s();},disabled:t,"data-testid":"location-button",children:jsx(MapPin,{color:"#00000099"})})}),jsxs(TooltipContent,{children:[jsx(TooltipArrow,{}),jsx("p",{children:"Share location"})]})]})]}),jsx(IconButton,{className:"lua:rounded-full",onClick:()=>{ee(Y.CHAT.MESSAGE_SENT),d();},disabled:t,"data-testid":"send-button",children:jsx(ArrowUp,{color:"#FFFFFF"})})]})}
|
|
17
|
+
`).map(f=>f.trim()).filter(f=>f&&f.startsWith("-")).map(f=>({text:f.replace(/^-[\s]?/,"").trim(),onClick:f.replace(/^-[\s]?/,"").trim()}))};function In({onSelect:t}){let{messages:e}=$();if(e.length===0)return null;let a=e[e.length-1],l=$t(a.content);return l.length===0?null:jsx(Ot,{buttons:l,onClick:t})}var ei=memo(function({onSend:e,disabled:a=false,onFilePaste:l}){let{inputMessage:r,setInputMessage:s}=Ht(),[d,u]=useState(false),n=useRef(null);useEffect(()=>{let o=()=>{u(window.matchMedia("(max-width: 768px)").matches||/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));};return o(),window.addEventListener("resize",o),()=>{window.removeEventListener("resize",o);}},[]),useEffect(()=>{let o=n.current;o&&(a||(o.style.height="auto",o.style.height=`${o.scrollHeight}px`));},[r]);let p=o=>{if(o.key==="Enter"){if(d||o.shiftKey||o.metaKey||o.ctrlKey)return;o.preventDefault(),e();}},f=useCallback(o=>{let{items:i}=o.clipboardData;if(!i||!l)return;let h=[];for(let c=0;c<i.length;c++){let v=i[c];if(v.kind==="file"){let g=v.getAsFile();g&&h.push(g);}}h.length>0&&(o.preventDefault(),l(h));},[l]);return jsxs("div",{className:"lua:flex lua:gap-3 lua:py-2 lua:px-3 lua:items-start",children:[jsx(Logo,{size:32,className:"lua:w-8 lua:h-8 lua:rounded-full lua:flex-shrink-0 lua:m-1"}),jsx("div",{className:"lua:flex-1 lua:flex",children:jsx("textarea",{ref:n,disabled:a,value:r,onChange:o=>s(o.target.value),onKeyDown:p,onPaste:f,placeholder:a?"This conversation's chat window has already been closed":"Reply to user",className:`lua:w-full lua:pl-0 lua:pr-4 lua:py-2 lua:resize-none lua:overflow-y-auto lua:border-none lua:focus:outline-none lua:focus:ring-0 lua:text-gray-700 lua:min-h-10 lua:max-h-48 lua:bg-white${a?" lua:cursor-not-allowed lua:h-14":""}`,rows:1})})]})});function Nl(){return localStorage.getItem("authToken")}async function Q(t,e,a){let l=Nl();if(!l)throw new Error("No auth token found");return new Promise((r,s)=>{let d=new XMLHttpRequest,u=new FormData;u.append("file",t),d.upload.addEventListener("progress",n=>{if(n.lengthComputable&&a){let p=n.loaded/n.total*100;a(p);}}),d.addEventListener("load",()=>{if(d.status>=200&&d.status<300)try{let n=JSON.parse(d.responseText);r(n);}catch{s(new Error("Failed to parse response"));}else s(new Error(`Failed to upload file: ${d.status}`));}),d.addEventListener("error",()=>{s(new Error("Network error occurred"));}),d.open("POST",`${e}/upload`),d.setRequestHeader("Authorization",`Bearer ${l}`),d.send(u);})}function Tl(t){let e=t.type,a="File";return e.startsWith("image/")?a="Image":e.startsWith("video/")?a="Video":e.startsWith("audio/")&&(a="Audio"),{icon:()=>null,label:a}}function ut({file:t,onRemove:e,cdnUrl:a,initialUrl:l,onUploadComplete:r}){let s=Tl(t),d=s.icon,[u,n]=useState(false),[p,f]=useState(0),[o,i]=useState(l||null),h=useRef(false);return useEffect(()=>{if(o||h.current)return;(async()=>{n(true),h.current=true;try{let{fileId:v}=await Q(t,a,C=>{f(C);}),g=`${a}/${v}`;i(g),n(!1),r&&r(t,g);}catch(v){console.error("Upload failed for file:",t.name,v),n(false),h.current=false;}})();},[t,a,r,o]),jsxs("div",{className:"lua:flex lua:items-center lua:gap-4 lua:p-3 lua:bg-white lua:border lua:border-gray-200 lua:rounded-lg",children:[jsx("div",{className:"lua:flex-shrink-0",children:u?jsxs("div",{className:"lua:w-8 lua:h-8 lua:flex lua:flex-col lua:items-center lua:justify-center",children:[jsx("div",{className:"lua:w-6 lua:h-6 lua:border-2 lua:border-t-blue-500 lua:border-r-transparent lua:border-b-transparent lua:border-l-transparent lua:rounded-full lua:animate-spin"}),jsxs("div",{className:"lua:mt-1 lua:text-xs lua:text-gray-600 lua:font-medium",children:[Math.round(p),"%"]})]}):jsx(d,{className:"lua:w-8 lua:h-8 lua:text-gray-600"})}),jsxs("div",{className:"lua:flex-grow lua:min-w-0",children:[jsx("p",{className:"lua:text-sm lua:font-medium lua:text-gray-900 lua:truncate",children:t.name}),jsx("p",{className:"lua:text-xs lua:text-gray-500",children:s.label})]}),jsx("button",{onClick:e,className:"lua:flex-shrink-0 lua:w-6 lua:h-6 lua:flex lua:items-center lua:justify-center lua:rounded-full lua:bg-black lua:text-white lua:hover:bg-gray-800 lua:transition-colors",children:jsx(XIcon,{className:"lua:w-4 lua:h-4"})})]})}function ct({file:t,onRemove:e,cdnUrl:a,initialUrl:l,onUploadComplete:r}){let{getFileUrl:s}=$(),[d,u]=useState(false),[n,p]=useState(0),[f,o]=useState(l||null),[i,h]=useState(false);useEffect(()=>{if(l||i)return;(async()=>{u(true),h(true);try{let{fileId:g}=await Q(t,a,x=>{p(x);}),C=`${a}/${g}`;o(C),u(!1),r&&r(t,C);}catch(g){console.error("Upload failed:",g),u(false);}})();},[t,l,a,i,r]);let c=f||(d?void 0:s(t));return jsxs("div",{className:"lua:relative lua:flex-shrink-0",children:[d?jsxs("div",{className:"lua:w-32 lua:h-32 lua:bg-gray-100 lua:rounded-lg lua:flex lua:flex-col lua:items-center lua:justify-center",children:[jsx("div",{className:"lua:w-8 lua:h-8 lua:border-2 lua:border-t-blue-500 lua:border-r-transparent lua:border-b-transparent lua:border-l-transparent lua:rounded-full lua:animate-spin"}),jsxs("div",{className:"lua:mt-2 lua:text-xs lua:text-gray-600 lua:font-medium",children:[Math.round(n),"%"]})]}):c?jsx("img",{"data-testid":"image-thumbnail",src:c,alt:t.name,className:"lua:w-32 lua:h-32 lua:object-cover lua:rounded-lg"}):jsx("div",{className:"lua:w-32 lua:h-32 lua:bg-gray-200 lua:rounded-lg lua:flex lua:items-center lua:justify-center",children:jsx("span",{className:"lua:text-gray-500",children:"No preview"})}),jsxs("div",{className:"lua:absolute lua:bottom-1 lua:left-1 lua:px-1.5 lua:py-0.5 lua:rounded lua:bg-black/50 lua:text-white lua:text-xs",children:[Math.floor(t.size/1024/1024),"MB"]}),jsx("button",{onClick:()=>e(),className:"lua:absolute lua:top-1 lua:right-1 lua:w-6 lua:h-6 lua:flex lua:items-center lua:justify-center lua:rounded-full lua:bg-black lua:text-white lua:hover:bg-gray-800 lua:transition-colors",children:jsx("span",{className:"lua:text-sm",children:"\xD7"})})]})}function dt({file:t,onRemove:e,cdnUrl:a,initialUrl:l,thumbnailUrl:r,onUploadComplete:s}){let{getFileUrl:d}=$(),[u,n]=useState(false),[p,f]=useState(0),[o,i]=useState(l||null),[h,c]=useState(false),[v,g]=useState(r||null);return useEffect(()=>{if(!r&&!v){let C=d(t),x=document.createElement("video");x.src=C;let N=()=>{try{x.currentTime=0,setTimeout(()=>{let m=document.createElement("canvas");m.width=x.videoWidth,m.height=x.videoHeight;let w=m.getContext("2d");if(!w){console.error("Could not get canvas context");return}w.drawImage(x,0,0);let U=m.toDataURL("image/jpeg",.8);g(U);},100);}catch(m){console.error("Error generating thumbnail:",m);}finally{URL.revokeObjectURL(C),x.removeEventListener("canplay",N);}};x.addEventListener("canplay",N),x.load();}},[t,r,v]),useEffect(()=>{if(l||h)return;(async()=>{n(true),c(true);try{let{fileId:x}=await Q(t,a,m=>{f(m);}),N=`${a}/${x}`;i(N),n(!1),s&&s(t,N);}catch(x){console.error("Upload failed:",x),n(false);}})();},[t,l,a,h,s]),jsxs("div",{className:"lua:relative lua:flex-shrink-0",children:[u?jsxs("div",{className:"lua:w-32 lua:h-32 lua:bg-gray-100 lua:rounded-lg lua:flex lua:flex-col lua:items-center lua:justify-center",children:[jsx("div",{className:"lua:w-8 lua:h-8 lua:border-2 lua:border-t-blue-500 lua:border-r-transparent lua:border-b-transparent lua:border-l-transparent lua:rounded-full lua:animate-spin"}),jsxs("div",{className:"lua:mt-2 lua:text-xs lua:text-gray-600 lua:font-medium",children:[Math.round(p),"%"]})]}):jsxs("div",{className:"lua:relative",children:[jsx("img",{"data-testid":"video-thumbnail",src:v||o||"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",alt:t.name,className:"lua:w-32 lua:h-32 lua:object-cover lua:rounded-lg lua:bg-gray-100"}),jsx("div",{className:"lua:absolute lua:inset-0 lua:flex lua:items-center lua:justify-center",children:jsx("div",{className:"lua:w-10 lua:h-10 lua:rounded-full lua:bg-black/50 lua:flex lua:items-center lua:justify-center",children:jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:jsx("path",{d:"M5 3L19 12L5 21V3Z",fill:"white"})})})})]}),jsxs("div",{className:"lua:absolute lua:bottom-1 lua:left-1 lua:px-1.5 lua:py-0.5 lua:rounded lua:bg-black/50 lua:text-white lua:text-xs",children:[Math.floor(t.size/1024/1024),"MB"]}),jsx("button",{onClick:()=>e(),className:"lua:absolute lua:top-1 lua:right-1 lua:w-6 lua:h-6 lua:flex lua:items-center lua:justify-center lua:rounded-full lua:bg-black lua:text-white lua:hover:bg-gray-800 lua:transition-colors",children:jsx("span",{className:"lua:text-sm",children:"\xD7"})})]})}function qt(t){let e=t.type,a="other",l="File";return e.startsWith("image/")?(a="image",l="Image"):e.startsWith("video/")?(a="video",l="Video"):e.startsWith("audio/")&&(a="audio",l="Audio"),{category:a,icon:()=>null,label:l}}function Ni({files:t,onRemove:e,cdnUrl:a,fileMetadata:l=[],onFileUploadComplete:r}){let[s,d]=useState({});return useEffect(()=>{t.forEach((u,n)=>{let p=qt(u),f=l.find(o=>o.file===u);if(p.category==="video"&&!s[n]&&!f){let o=URL.createObjectURL(u),i=document.createElement("video");i.src=o;let h=()=>{try{i.currentTime=0,setTimeout(()=>{let c=document.createElement("canvas");c.width=i.videoWidth,c.height=i.videoHeight;let v=c.getContext("2d");if(!v){console.error("Could not get canvas context");return}v.drawImage(i,0,0);let g=c.toDataURL("image/jpeg",.8);d(C=>({...C,[n]:g}));},100);}catch(c){console.error("Error generating thumbnail:",c);}finally{URL.revokeObjectURL(o),i.removeEventListener("canplay",h);}};i.addEventListener("canplay",h),i.load();}});},[t,l]),t.length===0?null:jsx("div",{className:"lua:px-4 lua:py-2 lua:border-b lua:border-gray-200",children:jsx("div",{className:"lua:flex lua:gap-2 lua:overflow-x-auto scrollbar-hide",children:t.map((u,n)=>{let p=qt(u),f=l.find(o=>o.file===u);return t.length>1?jsx("div",{className:"lua:flex-shrink-0 lua:w-64",children:jsx(ut,{file:u,onRemove:()=>e(n),cdnUrl:a,onUploadComplete:(o,i)=>{r&&r(o,i);}})},n):p.category==="image"?jsx(ct,{file:u,onRemove:()=>e(n),cdnUrl:a,initialUrl:f?.url,onUploadComplete:(o,i)=>{r&&r(o,i);}},u.name):p.category==="video"?jsx(dt,{file:u,onRemove:()=>e(n),cdnUrl:a,initialUrl:f?.url,thumbnailUrl:s[n],onUploadComplete:(o,i)=>{r&&r(o,i);}},u.name):jsx("div",{className:"lua:flex-shrink-0 lua:w-64",children:jsx(ut,{file:u,onRemove:()=>e(n),cdnUrl:a,onUploadComplete:(o,i)=>{r&&r(o,i);}})},n)})})})}var Y={CHAT:{TOOLBAR_ACTION:{FILE_UPLOAD:"file_upload",CAMERA:"camera",VIDEO:"video",AUDIO:"audio",LOCATION:"location"},MESSAGE_SENT:"message_sent"}};function ee(t){console.log("Analytics event:",t);}function Ti({loading:t,onFileClick:e,onCameraClick:a,onVideoClick:l,onAudioClick:r,onLocationClick:s,onSendClick:d}){return jsxs("div",{className:"lua:flex lua:items-center lua:justify-between lua:border-t lua:border-gray-200 lua:bg-gray-50 lua:px-3 lua:py-2",children:[jsxs("div",{className:"lua:flex lua:items-center lua:gap-2",children:[jsxs(Tooltip,{children:[jsx(TooltipTrigger,{asChild:true,children:jsx(IconButton,{className:"lua:rounded-lg",variant:"muted",onClick:()=>{ee(Y.CHAT.TOOLBAR_ACTION.FILE_UPLOAD),e();},disabled:t,"data-testid":"file-upload-button",children:jsx(Paperclip,{color:"#00000099"})})}),jsxs(TooltipContent,{children:[jsx(TooltipArrow,{}),jsx("p",{children:"Attach files"})]})]}),jsx("div",{className:"lua:w-px lua:h-5 lua:bg-gray-200"}),jsxs(Tooltip,{children:[jsx(TooltipTrigger,{asChild:true,children:jsx(IconButton,{className:"lua:rounded-lg",variant:"muted",onClick:()=>{ee(Y.CHAT.TOOLBAR_ACTION.CAMERA),a();},disabled:t,"data-testid":"camera-button",children:jsx(Camera,{color:"#00000099"})})}),jsxs(TooltipContent,{children:[jsx(TooltipArrow,{}),jsx("p",{children:"Take a picture"})]})]}),jsxs(Tooltip,{children:[jsx(TooltipTrigger,{asChild:true,children:jsx(IconButton,{className:"lua:rounded-lg",variant:"muted",onClick:()=>{ee(Y.CHAT.TOOLBAR_ACTION.VIDEO),l();},disabled:t,"data-testid":"video-button",children:jsx(VideoCamera,{color:"#00000099"})})}),jsxs(TooltipContent,{children:[jsx(TooltipArrow,{}),jsx("p",{children:"Record video"})]})]}),jsxs(Tooltip,{children:[jsx(TooltipTrigger,{asChild:true,children:jsx(IconButton,{className:"lua:rounded-lg",variant:"muted",onClick:()=>{ee(Y.CHAT.TOOLBAR_ACTION.AUDIO),r();},disabled:t,"data-testid":"audio-button",children:jsx(Microphone,{color:"#00000099"})})}),jsxs(TooltipContent,{children:[jsx(TooltipArrow,{}),jsx("p",{children:"Record voice message"})]})]}),jsx("div",{className:"lua:w-px lua:h-5 lua:bg-gray-200"}),jsxs(Tooltip,{children:[jsx(TooltipTrigger,{asChild:true,children:jsx(IconButton,{className:"lua:rounded-lg",variant:"muted",onClick:()=>{ee(Y.CHAT.TOOLBAR_ACTION.LOCATION),s();},disabled:t,"data-testid":"location-button",children:jsx(MapPin,{color:"#00000099"})})}),jsxs(TooltipContent,{children:[jsx(TooltipArrow,{}),jsx("p",{children:"Share location"})]})]})]}),jsx(IconButton,{className:"lua:rounded-full",onClick:()=>{ee(Y.CHAT.MESSAGE_SENT),d();},disabled:t,"data-testid":"send-button",children:jsx(ArrowUp,{color:"#FFFFFF"})})]})}
|
|
18
18
|
export{Ot as ActionMessage,Lt as AudioPreview,$l as AudioRecorder,ir as CameraDialog,yt as CarouselImageDialog,In as ChatActions,ei as ChatInput,nn as ChatMessage,mn as ChatProvider,Ct as CodeBlock,Ni as FilePreview,ut as FilePreviewCard,vt as ImageDialog,wn as LoadingMessage,cr as LocationDialog,Ee as PaymentPreview,Ti as Toolbar,Xl as VideoDialog,L as markdownStyles,$t as parseActions,Q as uploadFile,$ as useChat,fn as useFileUrls,Ht as useInput,gn as useLoadingMessage,pn as useMessages,hn as useUnreadMessages};//# sourceMappingURL=index.mjs.map
|
|
19
19
|
//# sourceMappingURL=index.mjs.map
|