lua-ai-chat 0.0.16 → 0.0.18
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 +10 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
'use strict';var luaniverse=require('luaniverse'),react=require('react'),jsxRuntime=require('react/jsx-runtime'),reactVisuallyHidden=require('@radix-ui/react-visually-hidden'),Ot=require('react-markdown'),prismReactRenderer=require('prism-react-renderer'),el=require('dompurify'),reactLeaflet=require('react-leaflet');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var Ot__default=/*#__PURE__*/_interopDefault(Ot);var el__default=/*#__PURE__*/_interopDefault(el);function jl({onAudioRecorded:t,onClose:e,inputMessage:a}){let[l,r]=react.useState(false),[o,u]=react.useState(0),[c,i]=react.useState([]),[m,g]=react.useState(null),[n,s]=react.useState(null),p=react.useRef(null),y=react.useRef(null),d=react.useRef([]),v=react.useRef(null),h=react.useRef(null),k=react.useRef(null),w=react.useRef(null),f=react.useRef(false),x=react.useRef(false),U=react.useRef(null);react.useEffect(()=>{if(!l||!m)return;let P=setInterval(()=>{let N=Math.floor((Date.now()-m)/1e3);u(N);},1e3);return ()=>clearInterval(P)},[l,m]),react.useEffect(()=>((async()=>{if(!(f.current||x.current))try{f.current=!0;let N=await navigator.mediaDevices.getUserMedia({audio:!0});p.current=N,v.current=new AudioContext,h.current=v.current.createAnalyser(),h.current.fftSize=256,v.current.createMediaStreamSource(N).connect(h.current),k.current=new Uint8Array(h.current.frequencyBinCount);let _=()=>{if(!h.current||!k.current)return;h.current.getByteFrequencyData(k.current);let Kt=Array.from(k.current).map(Qt=>Qt/255);i(Kt),w.current=requestAnimationFrame(_);};_(),Xt();}catch(N){console.error("Error accessing microphone:",N),e();}finally{f.current=false;}})(),()=>{O();}),[]);let O=()=>{if(!x.current)try{if(x.current=!0,l&&y.current&&(y.current.stop(),r(!1),g(null)),p.current){let P=p.current.getAudioTracks(),N=p.current.getVideoTracks();P.forEach(A=>{A.stop(),A.enabled=!1;}),N.forEach(A=>{A.stop(),A.enabled=!1;});}w.current&&cancelAnimationFrame(w.current),v.current&&v.current.close(),p.current=null,y.current=null,d.current=[],v.current=null,h.current=null,k.current=null,w.current=null;}finally{x.current=false;}},Xt=()=>{if(!p.current)return;let N=["audio/webm","audio/mp4","audio/ogg","audio/wav"].find(_=>MediaRecorder.isTypeSupported(_));if(!N){console.error("No supported MIME type found for MediaRecorder"),e();return}U.current=N;let A=new MediaRecorder(p.current,{mimeType:N});y.current=A,d.current=[],A.ondataavailable=_=>{_.data.size>0&&d.current.push(_.data);},A.start(),r(true),g(Date.now()),u(0);},Gt=async()=>{if(!y.current||!p.current)return;r(false),s(o),g(null),y.current.stop(),await new Promise(N=>{y.current&&(y.current.onstop=()=>N());});let P=new Blob(d.current,{type:U.current||"audio/webm"});t(P,a),O(),e();},gt=P=>{let N=Math.floor(P/60),A=P%60;return `${N.toString().padStart(2,"0")}:${A.toString().padStart(2,"0")}`};return jsxRuntime.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:[jsxRuntime.jsx(luaniverse.IconButton,{variant:"muted",onClick:async()=>{O(),e();},className:"audio-recorder-close-button lua:flex-shrink-0",children:jsxRuntime.jsx(luaniverse.XIcon,{className:"audio-recorder-close-icon",color:"#00000099"})}),jsxRuntime.jsxs("div",{className:"audio-recorder-status lua:flex lua:items-center lua:gap-2",children:[jsxRuntime.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"}`}),jsxRuntime.jsx("span",{className:"audio-recorder-time lua:text-gray-700 lua:text-sm",children:gt(l?o:n||0)})]}),jsxRuntime.jsx("div",{className:"audio-recorder-visualizer lua:flex-1","data-testid":"audio-visualizer-bar",children:c.length>0&&jsxRuntime.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 lua:md:gap-1",children:c.slice(0,50).map((P,N)=>jsxRuntime.jsx("div",{className:"audio-recorder-bar lua:flex-1 lua:bg-blue-500",style:{height:`${P*100}%`}},N))})}),jsxRuntime.jsx(luaniverse.IconButton,{onClick:Gt,className:"audio-recorder-send-button lua:flex-shrink-0 lua:mr-1","data-testid":"send-audio-button",children:jsxRuntime.jsx(luaniverse.ArrowUp,{className:"audio-recorder-send-icon",color:"white"})})]})}function oa(t){let e=Math.floor(t/60),a=t%60;return `${e.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`}function Yl({videoRef:t,isRecording:e,recordingTime:a,loading:l,onStartRecording:r,onStopRecording:o,onClose:u,open:c}){return jsxRuntime.jsx(luaniverse.Dialog,{open:c,onOpenChange:u,children:jsxRuntime.jsxs(luaniverse.DialogContent,{className:"lua:w-full lua:max-w-2xl lua:p-2.5",showClose:false,children:[jsxRuntime.jsx(reactVisuallyHidden.VisuallyHidden,{children:jsxRuntime.jsx(luaniverse.DialogTitle,{})}),jsxRuntime.jsxs("div",{className:"lua:relative lua:aspect-[4/3] lua:bg-black lua:rounded-xl lua:overflow-hidden lua:mb-8",children:[jsxRuntime.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&&jsxRuntime.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:[jsxRuntime.jsx("div",{className:"lua:w-2 lua:h-2 lua:rounded-full lua:bg-red-500 lua:animate-pulse"}),jsxRuntime.jsx("span",{className:"lua:text-sm lua:font-medium lua:text-white",children:oa(a)})]})]}),jsxRuntime.jsx("div",{className:"lua:flex lua:justify-center lua:items-center lua:gap-5 lua:mb-2.5",children:e?jsxRuntime.jsx(luaniverse.IconButton,{"data-testid":"stop-recording-button",onClick:o,disabled:l,variant:"secondary",children:jsxRuntime.jsx(luaniverse.XIcon,{className:"lua:text-gray-900 lua:dark:text-gray-100"})}):jsxRuntime.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:[jsxRuntime.jsx("rect",{x:"2",y:"2",width:"36",height:"36",rx:"18",stroke:"#FF0342",strokeWidth:"4"}),jsxRuntime.jsx("rect",{x:"6",y:"6",width:"28",height:"28",rx:"14",fill:"#FF0342"})]})})]})})}function yt({url:t,alt:e,open:a,onClose:l}){return jsxRuntime.jsxs(luaniverse.Dialog,{open:a,onOpenChange:l,children:[jsxRuntime.jsx(reactVisuallyHidden.VisuallyHidden,{children:jsxRuntime.jsx(luaniverse.DialogTitle,{})}),jsxRuntime.jsx(luaniverse.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:jsxRuntime.jsxs("div",{className:"lua:relative lua:w-full lua:h-full",children:[jsxRuntime.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:jsxRuntime.jsx(luaniverse.XIcon,{color:"white",className:"lua:w-6 lua:h-6"})}),jsxRuntime.jsx("div",{className:"lua:w-full lua:h-full lua:flex lua:items-center lua:justify-center",children:jsxRuntime.jsx("img",{src:t,alt:e,className:"sm:lua:aspect-[16/9] lua:object-contain lua:rounded-none sm:lua:rounded-lg"})})]})})]})}function bt({images:t,initialIndex:e=0,open:a,onClose:l}){let[r,o]=react.useState(),[u,c]=react.useState(0);return react.useEffect(()=>{if(!r)return;e>0&&e<t.length&&(r.scrollTo(e),c(e));let i=()=>{c(r.selectedScrollSnap());};return r.on("select",i),i(),()=>{r?.off("select",i);}},[r,e,t.length]),jsxRuntime.jsxs(luaniverse.Dialog,{open:a,onOpenChange:l,children:[jsxRuntime.jsx(reactVisuallyHidden.VisuallyHidden,{children:jsxRuntime.jsx(luaniverse.DialogTitle,{})}),jsxRuntime.jsx(luaniverse.DialogContent,{className:"lua:w-full lua:m-0",showClose:false,children:jsxRuntime.jsxs("div",{className:"lua:relative lua:w-full lua:h-full",children:[jsxRuntime.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:jsxRuntime.jsx(luaniverse.XIcon,{color:"white",className:"lua:w-6 lua:h-6"})}),t.length>1&&jsxRuntime.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:[u+1," / ",t.length]}),jsxRuntime.jsx("div",{className:"lua:w-full lua:h-full lua:flex lua:items-center lua:justify-center lua:px-16",children:jsxRuntime.jsxs(luaniverse.Carousel,{setApi:o,className:"lua:w-full lua:max-w-5xl",opts:{align:"center",loop:t.length>1},children:[jsxRuntime.jsx(luaniverse.CarouselContent,{children:t.map((i,m)=>jsxRuntime.jsx(luaniverse.CarouselItem,{className:"lua:flex lua:items-center lua:justify-center",children:jsxRuntime.jsx("img",{src:i.src,alt:i.alt||`Image ${m+1}`,className:"lua:max-w-full lua:max-h-screen lua:object-contain lua:rounded-none sm:lua:rounded-lg",draggable:false})},m))}),t.length>1&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(luaniverse.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"}),jsxRuntime.jsx(luaniverse.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 gr({videoRef:t,canvasRef:e,onCapture:a,onClose:l,open:r}){return jsxRuntime.jsxs(luaniverse.Dialog,{open:r,onOpenChange:l,children:[jsxRuntime.jsx(reactVisuallyHidden.VisuallyHidden,{children:jsxRuntime.jsx(luaniverse.DialogTitle,{})}),jsxRuntime.jsxs(luaniverse.DialogContent,{className:"lua:w-full lua:max-w-2xl lua:p-2.5",showClose:false,children:[jsxRuntime.jsxs("div",{className:"lua:relative lua:aspect-[16/9] lua:bg-black lua:rounded-xl lua:overflow-hidden",children:[jsxRuntime.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"}}),jsxRuntime.jsx("canvas",{ref:e,className:"lua:hidden"})]}),jsxRuntime.jsxs("div",{className:"lua:flex lua:justify-center lua:items-center lua:gap-5 lua:mb-2.5 lua:mt-6",children:[jsxRuntime.jsx(luaniverse.IconButton,{onClick:a,"data-testid":"capture-button",children:jsxRuntime.jsx(luaniverse.Camera,{className:"lua:text-white"})}),jsxRuntime.jsx(luaniverse.IconButton,{onClick:l,variant:"secondary",children:jsxRuntime.jsx(luaniverse.XIcon,{className:"lua:text-gray-900 lua:dark:text-gray-100"})})]})]})]})}function hr({locationError:t,currentLocation:e,loading:a,onShare:l,onClose:r}){return jsxRuntime.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:jsxRuntime.jsxs("div",{className:"lua:bg-white lua:dark:bg-gray-800 lua:rounded-lg lua:p-4 lua:max-w-2xl lua:w-full lua:mx-4",children:[jsxRuntime.jsxs("div",{className:"lua:flex lua:justify-between lua:items-center lua:mb-4",children:[jsxRuntime.jsx("h3",{className:"lua:text-lg lua:font-semibold lua:text-gray-900 lua:dark:text-gray-50",children:"Share Location"}),jsxRuntime.jsx("button",{onClick:r,className:"lua:text-gray-500 lua:dark:text-gray-400 lua:hover:text-gray-700 lua:dark:hover:text-gray-200",children:jsxRuntime.jsx("svg",{className:"lua:w-6 lua:h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsxRuntime.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),t?jsxRuntime.jsx("div",{className:"lua:bg-red-50 lua:dark:bg-red-900/30 lua:text-red-500 lua:dark:text-red-400 lua:p-4 lua:rounded-lg lua:mb-4",children:t}):e?jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsxs("div",{className:"lua:mb-4",children:[jsxRuntime.jsx("div",{className:"lua:text-sm lua:text-gray-500 lua:dark:text-gray-400 lua:mb-2",children:"Current Location:"}),jsxRuntime.jsx("div",{className:"lua:text-gray-700 lua:dark:text-gray-200 lua:mb-2",children:e.address}),jsxRuntime.jsxs("div",{className:"lua:text-sm lua:text-gray-500 lua:dark:text-gray-400",children:[e.latitude.toFixed(6),","," ",e.longitude.toFixed(6)]})]})}):jsxRuntime.jsx("div",{className:"lua:flex lua:justify-center lua:items-center lua:h-48",children:jsxRuntime.jsx("div",{className:"lua:animate-spin lua:rounded-full lua:h-8 lua:w-8 lua:border-b-2 lua:border-blue-500"})}),jsxRuntime.jsx("div",{className:"lua:flex lua:justify-center",children:e&&jsxRuntime.jsxs("button",{onClick:l,disabled:a,className:`lua:px-4 lua:py-2 lua:rounded-full ${a?"lua:bg-blue-300 lua:dark:bg-blue-800 lua:cursor-not-allowed":"lua:bg-blue-500 lua:hover:bg-blue-600 lua:dark:bg-blue-600 lua:dark:hover:bg-blue-700"} lua:text-white lua:flex lua:items-center lua:gap-2`,children:[jsxRuntime.jsx("svg",{className:"lua:w-5 lua:h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsxRuntime.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 Ra(t){let e=[],a=t.split(`
|
|
2
|
-
`).filter(l=>l.trim()!=="");for(let l of a){let r=/\[([^\]]+)\]\(([^)]+)\)\s+filename:([^\s]+)\s+mime:([^\s]+)/g,o;for(;(o=r.exec(l))!==null;){let[,u,c,i,m]=o;e.push({fileName:u.trim(),url:c.trim(),filename:i.trim(),mediaType:m.trim()});}}return e}var Ie=Ra;function
|
|
3
|
-
`)?jsxRuntime.jsx("code",{className:T.code,...l,children:e}):jsxRuntime.jsx(
|
|
1
|
+
'use strict';var luaniverse=require('luaniverse'),react=require('react'),jsxRuntime=require('react/jsx-runtime'),reactVisuallyHidden=require('@radix-ui/react-visually-hidden'),Ot=require('react-markdown'),prismReactRenderer=require('prism-react-renderer'),el=require('dompurify'),reactLeaflet=require('react-leaflet');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var Ot__default=/*#__PURE__*/_interopDefault(Ot);var el__default=/*#__PURE__*/_interopDefault(el);function jl({onAudioRecorded:t,onClose:e,inputMessage:a}){let[l,r]=react.useState(false),[o,u]=react.useState(0),[c,i]=react.useState([]),[m,p]=react.useState(null),[n,s]=react.useState(null),g=react.useRef(null),x=react.useRef(null),d=react.useRef([]),v=react.useRef(null),h=react.useRef(null),N=react.useRef(null),w=react.useRef(null),f=react.useRef(false),y=react.useRef(false),U=react.useRef(null);react.useEffect(()=>{if(!l||!m)return;let P=setInterval(()=>{let k=Math.floor((Date.now()-m)/1e3);u(k);},1e3);return ()=>clearInterval(P)},[l,m]),react.useEffect(()=>((async()=>{if(!(f.current||y.current))try{f.current=!0;let k=await navigator.mediaDevices.getUserMedia({audio:!0});g.current=k,v.current=new AudioContext,h.current=v.current.createAnalyser(),h.current.fftSize=256,v.current.createMediaStreamSource(k).connect(h.current),N.current=new Uint8Array(h.current.frequencyBinCount);let _=()=>{if(!h.current||!N.current)return;h.current.getByteFrequencyData(N.current);let Kt=Array.from(N.current).map(Qt=>Qt/255);i(Kt),w.current=requestAnimationFrame(_);};_(),Xt();}catch(k){console.error("Error accessing microphone:",k),e();}finally{f.current=false;}})(),()=>{O();}),[]);let O=()=>{if(!y.current)try{if(y.current=!0,l&&x.current&&(x.current.stop(),r(!1),p(null)),g.current){let P=g.current.getAudioTracks(),k=g.current.getVideoTracks();P.forEach(A=>{A.stop(),A.enabled=!1;}),k.forEach(A=>{A.stop(),A.enabled=!1;});}w.current&&cancelAnimationFrame(w.current),v.current&&v.current.close(),g.current=null,x.current=null,d.current=[],v.current=null,h.current=null,N.current=null,w.current=null;}finally{y.current=false;}},Xt=()=>{if(!g.current)return;let k=["audio/webm","audio/mp4","audio/ogg","audio/wav"].find(_=>MediaRecorder.isTypeSupported(_));if(!k){console.error("No supported MIME type found for MediaRecorder"),e();return}U.current=k;let A=new MediaRecorder(g.current,{mimeType:k});x.current=A,d.current=[],A.ondataavailable=_=>{_.data.size>0&&d.current.push(_.data);},A.start(),r(true),p(Date.now()),u(0);},Gt=async()=>{if(!x.current||!g.current)return;r(false),s(o),p(null),x.current.stop(),await new Promise(k=>{x.current&&(x.current.onstop=()=>k());});let P=new Blob(d.current,{type:U.current||"audio/webm"});t(P,a),O(),e();},pt=P=>{let k=Math.floor(P/60),A=P%60;return `${k.toString().padStart(2,"0")}:${A.toString().padStart(2,"0")}`};return jsxRuntime.jsxs("div",{className:"audio-recorder-container lua:bg-muted lua:rounded-lg lua:p-2 lua:flex lua:items-center lua:gap-4",children:[jsxRuntime.jsx(luaniverse.IconButton,{variant:"muted",onClick:async()=>{O(),e();},className:"audio-recorder-close-button lua:flex-shrink-0",children:jsxRuntime.jsx(luaniverse.XIcon,{className:"audio-recorder-close-icon",color:"#00000099"})}),jsxRuntime.jsxs("div",{className:"audio-recorder-status lua:flex lua:items-center lua:gap-2",children:[jsxRuntime.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"}`}),jsxRuntime.jsx("span",{className:"audio-recorder-time lua:text-gray-700 lua:text-sm",children:pt(l?o:n||0)})]}),jsxRuntime.jsx("div",{className:"audio-recorder-visualizer lua:flex-1","data-testid":"audio-visualizer-bar",children:c.length>0&&jsxRuntime.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 lua:md:gap-1",children:c.slice(0,50).map((P,k)=>jsxRuntime.jsx("div",{className:"audio-recorder-bar lua:flex-1 lua:bg-blue-500",style:{height:`${P*100}%`}},k))})}),jsxRuntime.jsx(luaniverse.IconButton,{onClick:Gt,className:"audio-recorder-send-button lua:flex-shrink-0 lua:mr-1","data-testid":"send-audio-button",children:jsxRuntime.jsx(luaniverse.ArrowUp,{className:"audio-recorder-send-icon",color:"white"})})]})}function oa(t){let e=Math.floor(t/60),a=t%60;return `${e.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`}function Yl({videoRef:t,isRecording:e,recordingTime:a,loading:l,onStartRecording:r,onStopRecording:o,onClose:u,open:c}){return jsxRuntime.jsx(luaniverse.Dialog,{open:c,onOpenChange:u,children:jsxRuntime.jsxs(luaniverse.DialogContent,{className:"lua:w-full lua:max-w-2xl lua:p-2.5",showClose:false,children:[jsxRuntime.jsx(reactVisuallyHidden.VisuallyHidden,{children:jsxRuntime.jsx(luaniverse.DialogTitle,{})}),jsxRuntime.jsxs("div",{className:"lua:relative lua:aspect-[4/3] lua:bg-black lua:rounded-xl lua:overflow-hidden lua:mb-8",children:[jsxRuntime.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&&jsxRuntime.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:[jsxRuntime.jsx("div",{className:"lua:w-2 lua:h-2 lua:rounded-full lua:bg-red-500 lua:animate-pulse"}),jsxRuntime.jsx("span",{className:"lua:text-sm lua:font-medium lua:text-white",children:oa(a)})]})]}),jsxRuntime.jsx("div",{className:"lua:flex lua:justify-center lua:items-center lua:gap-5 lua:mb-2.5",children:e?jsxRuntime.jsx(luaniverse.IconButton,{"data-testid":"stop-recording-button",onClick:o,disabled:l,variant:"secondary",children:jsxRuntime.jsx(luaniverse.XIcon,{className:"lua:text-gray-900 lua:dark:text-gray-100"})}):jsxRuntime.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:[jsxRuntime.jsx("rect",{x:"2",y:"2",width:"36",height:"36",rx:"18",stroke:"#FF0342",strokeWidth:"4"}),jsxRuntime.jsx("rect",{x:"6",y:"6",width:"28",height:"28",rx:"14",fill:"#FF0342"})]})})]})})}function xt({url:t,alt:e,open:a,onClose:l}){return jsxRuntime.jsxs(luaniverse.Dialog,{open:a,onOpenChange:l,children:[jsxRuntime.jsx(reactVisuallyHidden.VisuallyHidden,{children:jsxRuntime.jsx(luaniverse.DialogTitle,{})}),jsxRuntime.jsx(luaniverse.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:jsxRuntime.jsxs("div",{className:"lua:relative lua:w-full lua:h-full",children:[jsxRuntime.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:jsxRuntime.jsx(luaniverse.XIcon,{color:"white",className:"lua:w-6 lua:h-6"})}),jsxRuntime.jsx("div",{className:"lua:w-full lua:h-full lua:flex lua:items-center lua:justify-center",children:jsxRuntime.jsx("img",{src:t,alt:e,className:"sm:lua:aspect-[16/9] lua:object-contain lua:rounded-none sm:lua:rounded-lg"})})]})})]})}function bt({images:t,initialIndex:e=0,open:a,onClose:l}){let[r,o]=react.useState(),[u,c]=react.useState(0);return react.useEffect(()=>{if(!r)return;e>0&&e<t.length&&(r.scrollTo(e),c(e));let i=()=>{c(r.selectedScrollSnap());};return r.on("select",i),i(),()=>{r?.off("select",i);}},[r,e,t.length]),jsxRuntime.jsxs(luaniverse.Dialog,{open:a,onOpenChange:l,children:[jsxRuntime.jsx(reactVisuallyHidden.VisuallyHidden,{children:jsxRuntime.jsx(luaniverse.DialogTitle,{})}),jsxRuntime.jsx(luaniverse.DialogContent,{className:"lua:w-full lua:m-0",showClose:false,children:jsxRuntime.jsxs("div",{className:"lua:relative lua:w-full lua:h-full",children:[jsxRuntime.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:jsxRuntime.jsx(luaniverse.XIcon,{color:"white",className:"lua:w-6 lua:h-6"})}),t.length>1&&jsxRuntime.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:[u+1," / ",t.length]}),jsxRuntime.jsx("div",{className:"lua:w-full lua:h-full lua:flex lua:items-center lua:justify-center lua:px-16",children:jsxRuntime.jsxs(luaniverse.Carousel,{setApi:o,className:"lua:w-full lua:max-w-5xl",opts:{align:"center",loop:t.length>1},children:[jsxRuntime.jsx(luaniverse.CarouselContent,{children:t.map((i,m)=>jsxRuntime.jsx(luaniverse.CarouselItem,{className:"lua:flex lua:items-center lua:justify-center",children:jsxRuntime.jsx("img",{src:i.src,alt:i.alt||`Image ${m+1}`,className:"lua:max-w-full lua:max-h-screen lua:object-contain lua:rounded-none sm:lua:rounded-lg",draggable:false})},m))}),t.length>1&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(luaniverse.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"}),jsxRuntime.jsx(luaniverse.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 pr({videoRef:t,canvasRef:e,onCapture:a,onClose:l,open:r}){return jsxRuntime.jsxs(luaniverse.Dialog,{open:r,onOpenChange:l,children:[jsxRuntime.jsx(reactVisuallyHidden.VisuallyHidden,{children:jsxRuntime.jsx(luaniverse.DialogTitle,{})}),jsxRuntime.jsxs(luaniverse.DialogContent,{className:"lua:w-full lua:max-w-2xl lua:p-2.5",showClose:false,children:[jsxRuntime.jsxs("div",{className:"lua:relative lua:aspect-[16/9] lua:bg-black lua:rounded-xl lua:overflow-hidden",children:[jsxRuntime.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"}}),jsxRuntime.jsx("canvas",{ref:e,className:"lua:hidden"})]}),jsxRuntime.jsxs("div",{className:"lua:flex lua:justify-center lua:items-center lua:gap-5 lua:mb-2.5 lua:mt-6",children:[jsxRuntime.jsx(luaniverse.IconButton,{onClick:a,"data-testid":"capture-button",children:jsxRuntime.jsx(luaniverse.Camera,{className:"lua:text-white"})}),jsxRuntime.jsx(luaniverse.IconButton,{onClick:l,variant:"secondary",children:jsxRuntime.jsx(luaniverse.XIcon,{className:"lua:text-gray-900 lua:dark:text-gray-100"})})]})]})]})}function hr({locationError:t,currentLocation:e,loading:a,onShare:l,onClose:r}){return jsxRuntime.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:jsxRuntime.jsxs("div",{className:"lua:bg-card lua:rounded-lg lua:p-4 lua:max-w-2xl lua:w-full lua:mx-4",children:[jsxRuntime.jsxs("div",{className:"lua:flex lua:justify-between lua:items-center lua:mb-4",children:[jsxRuntime.jsx("h3",{className:"lua:text-lg lua:font-semibold lua:text-gray-900 lua:dark:text-gray-50",children:"Share Location"}),jsxRuntime.jsx("button",{onClick:r,className:"lua:text-gray-500 lua:dark:text-gray-400 lua:hover:text-gray-700 lua:dark:hover:text-gray-200",children:jsxRuntime.jsx("svg",{className:"lua:w-6 lua:h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsxRuntime.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),t?jsxRuntime.jsx("div",{className:"lua:bg-red-50 lua:dark:bg-red-900/30 lua:text-red-500 lua:dark:text-red-400 lua:p-4 lua:rounded-lg lua:mb-4",children:t}):e?jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsxs("div",{className:"lua:mb-4",children:[jsxRuntime.jsx("div",{className:"lua:text-sm lua:text-gray-500 lua:dark:text-gray-400 lua:mb-2",children:"Current Location:"}),jsxRuntime.jsx("div",{className:"lua:text-gray-700 lua:dark:text-gray-200 lua:mb-2",children:e.address}),jsxRuntime.jsxs("div",{className:"lua:text-sm lua:text-gray-500 lua:dark:text-gray-400",children:[e.latitude.toFixed(6),","," ",e.longitude.toFixed(6)]})]})}):jsxRuntime.jsx("div",{className:"lua:flex lua:justify-center lua:items-center lua:h-48",children:jsxRuntime.jsx("div",{className:"lua:animate-spin lua:rounded-full lua:h-8 lua:w-8 lua:border-b-2 lua:border-blue-500"})}),jsxRuntime.jsx("div",{className:"lua:flex lua:justify-center",children:e&&jsxRuntime.jsxs("button",{onClick:l,disabled:a,className:`lua:px-4 lua:py-2 lua:rounded-full ${a?"lua:bg-blue-300 lua:dark:bg-blue-800 lua:cursor-not-allowed":"lua:bg-blue-500 lua:hover:bg-blue-600 lua:dark:bg-blue-600 lua:dark:hover:bg-blue-700"} lua:text-white lua:flex lua:items-center lua:gap-2`,children:[jsxRuntime.jsx("svg",{className:"lua:w-5 lua:h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsxRuntime.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 Ra(t){let e=[],a=t.split(`
|
|
2
|
+
`).filter(l=>l.trim()!=="");for(let l of a){let r=/\[([^\]]+)\]\(([^)]+)\)\s+filename:([^\s]+)\s+mime:([^\s]+)/g,o;for(;(o=r.exec(l))!==null;){let[,u,c,i,m]=o;e.push({fileName:u.trim(),url:c.trim(),filename:i.trim(),mediaType:m.trim()});}}return e}var Ie=Ra;function Nt({children:t,language:e=""}){let[a,l]=react.useState(false),r=typeof t=="string"?t:String(t),o=e||"javascript";return jsxRuntime.jsxs("div",{className:"lua:relative lua:my-4 lua:rounded-lg lua:overflow-hidden lua:mx-4 lua:sm:mx-5 lua:grid",children:[jsxRuntime.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:[jsxRuntime.jsx("span",{className:"lua:text-xs lua:font-mono",children:o}),jsxRuntime.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"})]}),jsxRuntime.jsx(prismReactRenderer.Highlight,{theme:prismReactRenderer.themes.vsDark,code:r,language:o,children:({className:c,style:i,tokens:m,getLineProps:p,getTokenProps:n})=>jsxRuntime.jsx("pre",{className:`${c} lua:p-4 lua:overflow-x-auto`,style:i,children:m.map((s,g)=>jsxRuntime.jsx("div",{...p({line:s}),children:s.map((x,d)=>jsxRuntime.jsx("span",{...n({token:x})},d))},g))})})]})}var T={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:dark:text-gray-200 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:dark:text-blue-400 lua:hover:underline",blockquote:"lua:border-l-4 lua:border-gray-200 lua:dark:border-gray-600 lua:pl-4 lua:italic lua:my-4",pre:"lua:contents lua:bg-gray-100 lua:dark:bg-gray-700 lua:rounded lua:px-1 lua:text-gray-700 lua:dark:text-gray-200 lua:mx-4 lua:sm:mx-5",code:"lua:bg-gray-100 lua:dark:bg-gray-700 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:dark:border-gray-700 lua:my-4",th:"lua:bg-gray-100 lua:dark:bg-gray-700 lua:border lua:border-gray-200 lua:dark:border-gray-700 lua:px-4 lua:py-2",td:"lua:border lua:border-gray-200 lua:dark:border-gray-700 lua:px-4 lua:py-2"};var Ea=t=>({code({children:e,className:a,...l}){let r=a?.replace("language-","")||"";return typeof e=="string"&&!e.includes(`
|
|
3
|
+
`)?jsxRuntime.jsx("code",{className:T.code,...l,children:e}):jsxRuntime.jsx(Nt,{language:r,className:a,children:e})},p({children:e,...a}){return jsxRuntime.jsx("p",{className:T.p,...a,children:e})},h1({children:e,...a}){return jsxRuntime.jsx("h1",{className:T.h1,...a,children:e})},h2({children:e,...a}){return jsxRuntime.jsx("h2",{className:T.h2,...a,children:e})},h3({children:e,...a}){return jsxRuntime.jsx("h3",{className:T.h3,...a,children:e})},h4({children:e,...a}){return jsxRuntime.jsx("h4",{className:T.h4,...a,children:e})},img({src:e,alt:a}){return jsxRuntime.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 jsxRuntime.jsx("ul",{className:T.ul,...a,children:e})},ol({children:e,...a}){return jsxRuntime.jsx("ol",{className:T.ol,...a,children:e})},li({children:e,...a}){return jsxRuntime.jsx("li",{className:`${T.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 jsxRuntime.jsx("a",{href:e,className:T.a,target:"_blank",rel:"noopener noreferrer",...l,children:a})},blockquote({children:e,...a}){return jsxRuntime.jsx("blockquote",{className:T.blockquote,...a,children:e})},pre({children:e}){return jsxRuntime.jsx(jsxRuntime.Fragment,{children:e})},table({children:e,...a}){return jsxRuntime.jsx("table",{className:T.table,...a,children:e})},th({children:e,...a}){return jsxRuntime.jsx("th",{className:T.th,...a,children:e})},td({children:e,...a}){return jsxRuntime.jsx("td",{className:T.td,...a,children:e})}}),be=Ea;function Ha(t){let e=new URL(t,"http://lua"),a=decodeURIComponent(e.pathname),l={};for(let[r,o]of e.searchParams.entries())l[r]=decodeURIComponent(o);return {pathname:a,queryParams:l}}var we=Ha;function Fa(t){let e=t.match(/\[navigate\]\(([^)]+)\)/);return e?e[1]:null}var kt=Fa;var za=react.memo(function({block:e,onCardClick:a,onListItemClick:l,onNavigate:r}){let o=e.content.match(/^#\s+(.+)$/m),u=e.content.match(/!\[.*?]\((.*)\)/),c=o?o[1]:"",i=u?u[1]:null,m=kt(e.content),p=e.content.replace(/^#\s+.+$/m,"").replace(/!\[.*?]\(.*?\)/g,"").replace(/\[.*?]\(.*?\)/g,"").trim(),n=be(l);return jsxRuntime.jsxs("div",{onClick:()=>{if(r&&m){let g=we(m);r(g.pathname,{...g.queryParams&&{query:g.queryParams}});}else a(e.content);},className:"chat-list-item group",children:[jsxRuntime.jsx("div",{className:"lua:absolute lua:inset-0 lua:bg-blue-500 lua:opacity-0 group-hover:lua:opacity-5 lua:dark:group-hover:lua:opacity-10 lua:rounded-lg lua:transition-opacity lua:duration-200"}),jsxRuntime.jsxs("div",{className:"chat-list-item-content",children:[i?jsxRuntime.jsx("div",{className:"chat-list-item-image-wrapper",children:jsxRuntime.jsx("img",{className:"chat-list-item-image",src:i,alt:c})}):null,jsxRuntime.jsxs("div",{className:"content-container",children:[jsxRuntime.jsx("h1",{className:"lua:text-base lua:leading-6 lua:font-semibold lua:text-gray-900 lua:dark:text-gray-50 lua:mb-0",children:c}),jsxRuntime.jsx("div",{className:"lua:text-sm lua:leading-6 lua:font-normal lua:text-gray-600 lua:dark:text-gray-300",children:jsxRuntime.jsx(Ot__default.default,{components:n,children:p})})]})]})]})}),oe=za;var Va=react.memo(function({group:e,onCardClick:a,onListItemClick:l,onNavigate:r}){return jsxRuntime.jsx("div",{className:"lua:w-full",children:jsxRuntime.jsx("div",{className:"chat-list-item-container",children:e.map((o,u)=>jsxRuntime.jsx(oe,{block:o,onCardClick:a,onListItemClick:l,onNavigate:r},u))})})}),Mt=Va;function _a(t){return {icon:()=>null}}function Ne({documents:t}){return t.map(e=>{let l=_a(new File([],"",{type:e.mediaType})).icon;return jsxRuntime.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:jsxRuntime.jsx("div",{className:"lua:flex lua:flex-col lua:gap-8",children:jsxRuntime.jsxs("div",{className:"chat-file-card lua:flex lua:items-center lua:justify-start lua:p-3 lua:border lua:border-border lua:rounded-lg lua:bg-card lua:w-80",children:[jsxRuntime.jsx(l,{className:"lua:w-12 lua:h-12 lua:text-gray-500 lua:dark:text-gray-400"}),jsxRuntime.jsxs("div",{className:"lua:flex lua:flex-col lua:gap-1 lua:pl-2",children:[e.fileName||"File",jsxRuntime.jsx("span",{className:"lua:text-gray-500 lua:dark:text-gray-400 lua:text-sm",children:e.mediaType})]})]})})},e.url)})}function Lt({message:t}){return jsxRuntime.jsx("div",{className:"chat-audio-message lua:flex lua:flex-col lua:mx-4 lua:sm:mx-5","data-testid":"audio-preview",children:jsxRuntime.jsx("div",{className:"chat-audio-container audio-playback-container lua:relative",children:jsxRuntime.jsxs("div",{className:"chat-audio-controls lua:flex lua:items-center lua:gap-2 lua:min-w-full",children:[jsxRuntime.jsx("audio",{src:t.url,controls:true,className:"chat-audio-player lua:h-8",style:{backgroundColor:"transparent",border:"none"}}),t.isUploading&&jsxRuntime.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:jsxRuntime.jsx("div",{className:"lua:text-white lua:text-sm",children:"Uploading..."})})]})})})}function Ee({url:t}){return jsxRuntime.jsxs(luaniverse.Button,{onClick:a=>{if(a.preventDefault(),/iPhone|iPad|iPod|Android/i.test(navigator.userAgent)){window.open(t,"_blank","noopener,noreferrer");return}let r=500,o=600,u=window.screen.width/2-r/2,c=window.screen.height/2-o/2,i=window.open(t,"Payment",`width=${r},height=${o},left=${u},top=${c},toolbar=no,menubar=no,scrollbars=yes,resizable=yes`);(!i||i.closed||typeof i.closed>"u")&&window.open(t,"_blank","noopener,noreferrer");},className:"chat-payment-button lua:rounded-xl",children:[jsxRuntime.jsx(luaniverse.CreditCard,{size:16}),jsxRuntime.jsx("span",{children:"Open payment"})]})}var Ga=t=>t.split(`
|
|
4
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=Ga;var Ka=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},He=Ka;var Qa=t=>{let e=/\[.*?\]\((.*?)\)/g,a=[],l;for(;(l=e.exec(t))!==null;)l[1]&&a.push(l[1]);return a},Fe=Qa;function Oe(t){let e=t.match(/!\[([^\]]+)\]\(([^)]+)\)/);if(!e)return null;let[,a,l]=e;return {text:a,url:l}}var Za=t=>{let e=/\[.*?\]\((.*?)\)/,a=t.match(e);return a?a[1]:null},Be=Za;var ze=t=>typeof t=="string"?t:Array.isArray(t)?t.map(ze).join(""):typeof t=="object"&&t!==null&&"props"in t?ze(t.props.children):"",At=ze;function Ja(t){return t.replace(/([^\n]):::/g,`$1
|
|
5
5
|
:::`)}var Ya=t=>{t=t.replace(/\\n/g,`
|
|
6
|
-
`);let e=[],a="",l="",r="",o="",u="",c="",i="",m="",
|
|
7
|
-
`);for(let w=0;w<
|
|
6
|
+
`);let e=[],a="",l="",r="",o="",u="",c="",i="",m="",p=false,n=false,s=false,g=false,x=false,d=false,v=false,N=Ja(t).split(`
|
|
7
|
+
`);for(let w=0;w<N.length;w++){let f=N[w];if(f.trim()==="::: list-item"||f.trim()===":::list-item"){a.trim()&&(e.push({type:"text",content:a.trim()}),a=""),p=true;continue}if(f.trim()==="::: payment"||f.trim()===":::payment"){a.trim()&&(e.push({type:"text",content:a.trim()}),a=""),n=true;continue}if(f.trim()==="::: actions"||f.trim()===":::actions"){a.trim()&&(e.push({type:"text",content:a.trim()}),a=""),s=true;continue}if(f.trim()==="::: images"||f.trim()===":::images"){a.trim()&&(e.push({type:"text",content:a.trim()}),a=""),g=true;continue}if(f.trim()==="::: links"||f.trim()===":::links"){a.trim()&&(e.push({type:"text",content:a.trim()}),a=""),x=true;continue}if(f.trim()==="::: navigate"||f.trim()===":::navigate"){a.trim()&&(e.push({type:"text",content:a.trim()}),a=""),d=true;continue}if(f.trim()==="::: documents"||f.trim()===":::documents"){a.trim()&&(e.push({type:"text",content:a.trim()}),a=""),v=true;continue}if(f.trim()===":::"&&p){e.push({type:"list-item",content:l.trim(),isComplete:true}),l="",p=false;continue}if(f.trim()===":::"&&n){e.push({type:"payment",content:r.trim(),isComplete:true}),r="",n=false;continue}if(f.trim()===":::"&&s){e.push({type:"actions",content:o.trim(),isComplete:true}),o="",s=false;continue}if(f.trim()===":::"&&g){e.push({type:"images",content:u.trim(),isComplete:true}),u="",g=false;continue}if(f.trim()===":::"&&x){e.push({type:"links",content:c.trim(),isComplete:true}),c="",x=false;continue}if(f.trim()===":::"&&d){e.push({type:"navigate",content:i.trim(),isComplete:true}),i="",d=false;continue}if(f.trim()===":::"&&v){e.push({type:"documents",content:m.trim(),isComplete:true}),m="",v=false;continue}p?l+=f+`
|
|
8
8
|
`:n?r+=f+`
|
|
9
9
|
`:s?o+=f+`
|
|
10
|
-
`:
|
|
11
|
-
`:
|
|
10
|
+
`:g?u+=f+`
|
|
11
|
+
`:x?c+=f+`
|
|
12
12
|
`:d?i+=f+`
|
|
13
13
|
`:v?m+=f+`
|
|
14
14
|
`:a+=f+`
|
|
15
|
-
`;}return g?e.push({type:"list-item",content:l.trim(),isComplete:false}):n?e.push({type:"payment",content:r.trim(),isComplete:false}):s?e.push({type:"actions",content:o.trim(),isComplete:false}):p?e.push({type:"images",content:u.trim(),isComplete:false}):y?e.push({type:"links",content:c.trim(),isComplete:false}):d?e.push({type:"navigate",content:i.trim(),isComplete:false}):v?e.push({type:"documents",content:m.trim(),isComplete:false}):a.trim()&&e.push({type:"text",content:a.trim()}),e},Rt=Ya;function tl(t){let e=new Set(["br","hr","img","input","meta","link"]),a=[],l=/<\/?([a-z][a-z0-9]*)[^>]*>/gi,r=l.exec(t);for(;r!==null;){let o=r[0],u=r[1].toLowerCase();if(e.has(u)||o.endsWith("/>")){r=l.exec(t);continue}if(o.startsWith("</")){if(a.length===0||a.pop()!==u)return false}else a.push(u);r=l.exec(t);}return a.length===0}function It(t){let e=new Set(["br","hr","img","input","meta","link"]),a=/<\/?([a-z][a-z0-9]*)[^>]*>/gi,r=0,o=[],u;for(a.lastIndex=0;(u=a.exec(t))!==null;){let m=u[0],g=u[1].toLowerCase(),s=u.index+m.length;if(e.has(g)||m.endsWith("/>")){o.length===0&&(r=s);continue}m.startsWith("</")?o.length>0&&o[o.length-1]===g&&(o.pop(),o.length===0&&(r=s)):o.push(g);}let c=t.substring(0,r),i=r<t.length||o.length>0;return {completeHtml:c,hasIncompleteContent:i}}function Ut(t){return /^\s*<[a-z]+[\s>]/i.test(t.trim())?{isHtml:true,isComplete:tl(t)}:{isHtml:false,isComplete:false}}function $e(t){if(typeof window>"u")return "";let e={ALLOWED_TAGS:["div","b","ol","ul","li","a","br"],ALLOWED_ATTR:["style","href","target","rel"],ALLOW_DATA_ATTR:false,ALLOWED_URI_REGEXP:/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|data):|[^a-z]|[a-z+.-]+(?:[^a-z+.\-:]|$))/i};return el__default.default.sanitize(t,e)}function Me({images:t}){let[e,a]=react.useState(false),[l,r]=react.useState(0),o=react.useRef(null),[u,c]=react.useState(false),[i,m]=react.useState(0),[g,n]=react.useState(0),[s,p]=react.useState(0),y=react.useCallback(x=>{o.current&&(c(true),m(x.pageX-o.current.offsetLeft),n(o.current.scrollLeft),p(0),x.preventDefault());},[]),d=react.useCallback(x=>{if(!u||!o.current)return;x.preventDefault();let U=x.pageX-o.current.offsetLeft,O=(U-i)*2;o.current.scrollLeft=g-O,p(Math.abs(U-i));},[u,i,g]),v=react.useCallback(()=>{c(false);},[]),h=react.useCallback(()=>{c(false);},[]),k=react.useCallback((x,U)=>{if(s>5){U.preventDefault();return}r(x),a(true);},[s]);return jsxRuntime.jsxs("div",{"data-testid":"image-carousel-message",className:"chat-image-carousel-message lua:w-full",children:[jsxRuntime.jsx("div",{ref:o,className:"chat-image-carousel markdown-image-carousel",style:{cursor:u?"grabbing":"grab"},onMouseDown:y,onMouseMove:d,onMouseUp:v,onMouseLeave:h,onDragStart:x=>{x.preventDefault(),x.stopPropagation();},onDragOver:x=>{x.preventDefault(),x.stopPropagation();},children:t.map((x,U)=>jsxRuntime.jsx("div",{className:"chat-carousel-image-item markdown-image-item",onClick:O=>k(U,O),children:jsxRuntime.jsx("img",{src:x.src,alt:x.alt,draggable:false,style:{userSelect:"none"}})},x.src))}),jsxRuntime.jsx(bt,{images:t,initialIndex:l,open:e,onClose:()=>a(false)})]})}function _e({message:t}){let[e,a]=react.useState(false);return t.url?jsxRuntime.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:[jsxRuntime.jsxs("div",{className:"chat-image-container lua:relative",children:[jsxRuntime.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&&jsxRuntime.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:jsxRuntime.jsxs("div",{className:"lua:text-white lua:text-sm",children:["Uploading..."," ",t.uploadProgress?Math.round(t.uploadProgress):0,"%"]})})]}),!t.isUploading&&t.content.length>0&&jsxRuntime.jsx("div",{className:"chat-image-caption lua:w-full lua:bg-gray-100 lua:dark:bg-gray-800 lua:text-gray-800 lua:dark:text-gray-100 lua:rounded-2xl lua:px-4 lua:p-3 lua:mt-8",children:t.content}),jsxRuntime.jsx(yt,{url:t.url,alt:t.content,open:e,onClose:()=>a(false)})]}):null}function qe({url:t,luaApiUrl:e,authToken:a,disablePreviewOnLinks:l}){let[r,o]=react.useState(null),[u,c]=react.useState(true),[i,m]=react.useState(null);return react.useEffect(()=>{t&&e&&!l&&(async()=>{try{c(!0),m(null);let n=a;if(!n)throw new Error("No auth token available");let s=await fetch(`${e}/chat/url-metadata?url=${encodeURIComponent(t)}`,{headers:{Authorization:`Bearer ${n}`}});if(!s.ok)throw new Error(`Failed to fetch preview: ${s.status}`);let p=await s.json();o(p);}catch(n){console.error("Error fetching link preview:",n),m(n instanceof Error?n.message:"Failed to load preview");}finally{c(false);}})();},[t,e]),l?jsxRuntime.jsx("div",{className:"lua:mb-5 lua:mx-[-30px]",children:jsxRuntime.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",children:jsxRuntime.jsx(luaniverse.Button,{variant:"muted",children:t})})}):u?jsxRuntime.jsxs("div",{className:"lua:animate-pulse",children:[jsxRuntime.jsx("div",{className:"lua:bg-gray-300 lua:dark:bg-gray-600 lua:h-4 lua:w-3/4 lua:mb-2 lua:rounded"}),jsxRuntime.jsx("div",{className:"lua:bg-gray-300 lua:dark:bg-gray-600 lua:h-3 lua:w-1/2 lua:rounded"})]}):i||!r?jsxRuntime.jsx("div",{className:"lua:mb-5 lua:mx-[-30px]",children:jsxRuntime.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",children:jsxRuntime.jsx(luaniverse.Button,{variant:"muted",children:t})})}):jsxRuntime.jsxs("a",{href:r.url||t,target:"_blank",rel:"noopener noreferrer",className:"lua:block lua:border lua:border-gray-200 lua:dark:border-gray-700 lua:rounded-lg lua:p-3 lua:hover:bg-gray-50 lua:dark:hover:bg-gray-800 lua:transition-colors lua:no-underline lua:max-w-sm",children:[r.image&&jsxRuntime.jsx("img",{src:r.image,alt:r.title,className:"lua:w-full lua:h-32 lua:object-cover lua:rounded lua:mb-2",onError:g=>{g.currentTarget.style.display="none";}}),jsxRuntime.jsx("div",{className:"lua:text-sm lua:font-medium lua:text-gray-900 lua:dark:text-gray-50 lua:mb-1 lua:line-clamp-2",children:r.title}),r.description&&jsxRuntime.jsx("div",{className:"lua:text-xs lua:text-gray-600 lua:dark:text-gray-300 lua:line-clamp-2",children:r.description}),jsxRuntime.jsx("div",{className:"lua:text-xs lua:text-gray-400 lua:dark:text-gray-500 lua:mt-1 lua:truncate",children:new URL(r.url||t).hostname})]})}function Le({links:t,luaApiUrl:e,authToken:a,disablePreviewOnLinks:l}){return jsxRuntime.jsx("div",{"data-testid":"link-list-message",className:"chat-link-list-message lua:w-full",children:jsxRuntime.jsx("div",{className:"chat-links-container lua:space-y-2 lua:mx-4 lua:sm:mx-5",children:t.map(r=>jsxRuntime.jsx(qe,{url:r,luaApiUrl:e,authToken:a,disablePreviewOnLinks:l},r))})})}function Xe({location:t}){let e=[t.latitude,t.longitude];return jsxRuntime.jsx("div",{className:"lua:w-full lua:h-48 lua:rounded-lg lua:overflow-hidden lua:border lua:border-gray-200",children:jsxRuntime.jsxs(reactLeaflet.MapContainer,{center:e,zoom:15,scrollWheelZoom:false,className:"lua:w-full lua:h-full",children:[jsxRuntime.jsx(reactLeaflet.TileLayer,{attribution:'\xA9 <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',url:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"}),jsxRuntime.jsx(reactLeaflet.Marker,{position:e,children:t.address&&jsxRuntime.jsx(reactLeaflet.Popup,{children:jsxRuntime.jsx("div",{children:t.address})})})]})})}function Ge({location:t}){return jsxRuntime.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&&jsxRuntime.jsx(Xe,{location:t})})}function Ke({location:t}){return jsxRuntime.jsx("div",{className:"lua:w-full lua:h-60 lua:rounded-lg","data-testid":"location-preview",children:jsxRuntime.jsx(Ge,{location:t})})}function Qe({message:t}){return jsxRuntime.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:dark:bg-gray-800 lua:text-gray-800 lua:dark:text-gray-100 lua:rounded-2xl lua:p-3 lua:mx-4 lua:sm:mx-5",children:jsxRuntime.jsxs("div",{className:"chat-location-preview-container location-preview-container lua:relative",children:[t.location&&jsxRuntime.jsx(Ke,{location:t.location}),t.isUploading&&jsxRuntime.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:jsxRuntime.jsx("div",{className:"lua:text-white lua:text-sm",children:"Sharing location..."})}),jsxRuntime.jsxs("div",{className:"chat-location-info lua:flex lua:items-center lua:gap-2 lua:mt-3",children:[jsxRuntime.jsx(luaniverse.MapPin,{className:"lua:fill-gray-800 lua:dark:fill-gray-100"}),jsxRuntime.jsx("div",{className:"lua:flex-1",children:jsxRuntime.jsx("div",{className:"lua:text-sm",children:t.content})})]})]})})}function Ze({url:t,onNavigate:e}){let[a,l]=react.useState(false);return react.useEffect(()=>{if(e&&!a){l(true);let r=we(t);e(r.pathname,{...r.queryParams&&{query:r.queryParams}});}},[a,e]),null}function et({message:t}){return jsxRuntime.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:[jsxRuntime.jsxs("div",{className:"chat-video-container lua:relative",children:[jsxRuntime.jsx("video",{src:t.url,controls:true,className:"chat-video lua:rounded-lg lua:w-full"}),t.isUploading&&jsxRuntime.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:jsxRuntime.jsxs("div",{className:"lua:text-white lua:text-sm",children:["Uploading..."," ",t.uploadProgress?Math.round(t.uploadProgress):0,"%"]})})]}),!t.isUploading&&t.content&&jsxRuntime.jsx("div",{className:"chat-video-caption lua:w-full lua:bg-gray-100 lua:dark:bg-gray-800 lua:text-gray-800 lua:dark:text-gray-100 lua:rounded-2xl lua:px-4 lua:p-3 lua:mt-8",children:t.content})]})}function fl(t){return new Date(t).toLocaleTimeString()}function hl(t){return {icon:()=>null}}var yn=react.memo(function({message:e,onSelect:a,luaApiUrl:l,authToken:r,disablePreviewOnLinks:o=false,onNavigate:u}){let c=react.useCallback(g=>{let n=g.match(/^#\s+(.+)$/m),s=g.match(/^##\s+(.+)$/m),p=n?n[1]:"",y=s?s[1]:"",d=`${p}. ${y}`;a&&a(d);},[a]),i=react.useCallback(g=>{if(!a)return;let n=At(g).trim();a(n);},[a]),m=react.useCallback(()=>{if(e.type==="location")return jsxRuntime.jsx(Qe,{message:e});if(e.mediaType?.startsWith("video"))return e.url?jsxRuntime.jsx(et,{message:{url:e.url,content:e.content||"",isUploading:e.isUploading,uploadProgress:e.uploadProgress}}):null;if(e.mediaType?.startsWith("image"))return e.url?jsxRuntime.jsx(_e,{message:{url:e.url,content:e.content||"",isUploading:e.isUploading,uploadProgress:e.uploadProgress}}):null;if(e.mediaType?.startsWith("audio"))return jsxRuntime.jsx(Lt,{message:e});if(e.type==="file"&&e.mediaType){let y=hl(new File([],"",{type:e.mediaType})).icon;return jsxRuntime.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:jsxRuntime.jsxs("div",{className:"lua:flex lua:flex-col lua:gap-8",children:[jsxRuntime.jsxs("div",{className:"chat-file-card lua:flex lua:items-center lua:justify-start lua:p-3 lua:border lua:border-gray-200 lua:dark:border-gray-700 lua:rounded-lg lua:bg-white lua:dark:bg-gray-800 lua:w-80",children:[jsxRuntime.jsx(y,{className:"lua:w-12 lua:h-12 lua:text-gray-500 lua:dark:text-gray-400"}),jsxRuntime.jsxs("div",{className:"lua:flex lua:flex-col lua:gap-1 lua:pl-2",children:["File",jsxRuntime.jsx("span",{className:"lua:text-gray-500 lua:dark:text-gray-400 lua:text-sm",children:e.mediaType})]})]}),e.content&&jsxRuntime.jsx("div",{className:"chat-file-content lua:bg-gray-100 lua:dark:bg-gray-800 lua:rounded-2xl lua:px-4 lua:py-2 lua:w-80",children:jsxRuntime.jsx("div",{className:"lua:text-sm lua:text-gray-900 lua:dark:text-gray-100",children:e.content})})]})})}if(e.role==="user")return e.content;if(e.content==="...")return null;let g=Ut(e.content);if(g.isHtml){if(g.isComplete){let d=$e(e.content);return jsxRuntime.jsx("div",{className:"chat-html-content lua:prose lua:prose-sm lua:max-w-none lua:mx-4 lua:sm:mx-5",dangerouslySetInnerHTML:{__html:d}})}let{completeHtml:p,hasIncompleteContent:y}=It(e.content);if(p){let d=$e(p);return jsxRuntime.jsxs("div",{className:"lua:mx-4 lua:sm:mx-5",children:[jsxRuntime.jsx("div",{className:"chat-html-content lua:prose lua:prose-sm lua:max-w-none",dangerouslySetInnerHTML:{__html:d}}),y&&jsxRuntime.jsx("div",{className:"lua:flex lua:items-center lua:gap-2 lua:text-gray-500 lua:dark:text-gray-400 lua:mt-2",children:jsxRuntime.jsx(luaniverse.LogoSpinner,{size:14})})]})}return jsxRuntime.jsx("div",{className:"lua:flex lua:items-center lua:gap-2 lua:text-gray-500 lua:dark:text-gray-400 lua:mx-4 lua:sm:mx-5",children:jsxRuntime.jsx("div",{className:"lua:animate-pulse",children:"\u25CF\u25CF\u25CF"})})}let n=Rt(e.content),s=be(i);return jsxRuntime.jsx("div",{className:"chat-markdown-content lua:prose lua:prose-sm lua:max-w-none",children:jsxRuntime.jsx("div",{className:"lua:flex lua:flex-wrap lua:gap-4",children:(()=>{if(n.filter(d=>d.type==="list-item").length>1){let d=[],v=[];return n.forEach(h=>{h.type==="list-item"?v.push(h):(v.length>0&&(d.push(v),v=[]),d.push([h]));}),v.length>0&&d.push(v),d.map((h,k)=>h.length>1&&h[0].type==="list-item"?jsxRuntime.jsx(Mt,{group:h,onCardClick:c,onListItemClick:i,onNavigate:u},k):h.map((w,f)=>{if(w.type==="list-item")return jsxRuntime.jsx(oe,{block:w,onCardClick:c,onListItemClick:i,onNavigate:u},f);if(w.type==="actions")return Se(w.content).length>0&&w.isComplete,null;if(w.type==="images"){let x=He(w.content);if(x.length>0)return jsxRuntime.jsx(Me,{images:x},f)}if(w.type==="links"){let x=Fe(w.content);return x.length>0&&w.isComplete?jsxRuntime.jsx(Le,{links:x,luaApiUrl:l||"",authToken:r||"",disablePreviewOnLinks:o},f):null}if(w.type==="navigate"){let x=Oe(w.content);return x&&w.isComplete?jsxRuntime.jsx(Ze,{text:x.text,url:x.url,onNavigate:u},f):null}if(w.type==="documents"){let x=Ie(w.content);return jsxRuntime.jsx(ke,{documents:x},f)}if(w.type==="payment"){let x=Be(w.content);return x?jsxRuntime.jsx("div",{className:"chat-payment-message lua:w-full lua:mx-4 lua:sm:mx-5",children:jsxRuntime.jsx(Ee,{url:x})},f):null}return jsxRuntime.jsx("div",{className:"chat-markdown-block lua:w-full",children:jsxRuntime.jsx(Ot__default.default,{components:s,children:w.content})},f)}))}return n.map((d,v)=>{if(d.type==="list-item")return jsxRuntime.jsx(oe,{block:d,onCardClick:c,onListItemClick:i,onNavigate:u},v);if(d.type==="actions")return Se(d.content).length>0&&d.isComplete,null;if(d.type==="images"){let h=He(d.content);if(h.length>0)return jsxRuntime.jsx(Me,{images:h},v)}if(d.type==="navigate"){let h=Oe(d.content);return h&&d.isComplete?jsxRuntime.jsx(Ze,{text:h.text,url:h.url,onNavigate:u},v):null}if(d.type==="documents"){let h=Ie(d.content);return jsxRuntime.jsx(ke,{documents:h},v)}if(d.type==="links"){let h=Fe(d.content);return h.length>0&&d.isComplete?jsxRuntime.jsx(Le,{links:h,luaApiUrl:l||"",authToken:r||"",disablePreviewOnLinks:o},v):null}if(d.type==="payment"){let h=Be(d.content);return h?jsxRuntime.jsx("div",{className:"chat-payment-message lua:w-full lua:mx-4 lua:sm:mx-5 lua:mb-5",children:jsxRuntime.jsx(Ee,{url:h})},v):null}return jsxRuntime.jsx("div",{className:"chat-markdown-block lua:w-full",children:jsxRuntime.jsx(Ot__default.default,{components:s,children:d.content})},v)})})()})})},[e,c,i]);return jsxRuntime.jsxs("div",{className:`chat-message-container lua:flex lua:flex-col ${e.role==="user"?"lua:items-end":"lua:items-start"} lua:gap-1`,children:[jsxRuntime.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!=="..."&&jsxRuntime.jsx("div",{className:`chat-message-bubble ${e.role==="user"?"chat-message-bubble-user lua:max-w-full lua:md:max-w-3/5 lua:bg-gray-100 lua:dark:bg-gray-700 lua:text-gray-800 lua:dark:text-gray-100 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:dark:bg-gray-800 lua:text-gray-800 lua:dark:text-gray-100 lua:rounded-lg lua:py-3 lua:rounded-bl-none"}`,style:{wordBreak:"break-word"},children:m()}),["file","image","video","location"].includes(e.type||"")&&m()]}),jsxRuntime.jsx("div",{className:`lua-message-timestamp lua:text-xs lua:text-gray-400 lua:dark:text-gray-500 lua:px-1 ${e.role==="user"?"lua:mr-4 sm:lua:mr-5":"lua:ml-4 sm:lua:ml-5"}`,children:fl(e.createdAt)})]})});var at=react.createContext(void 0),lt=react.createContext(void 0),rt=react.createContext(void 0),ot=react.createContext(void 0),nt=react.createContext(void 0);function kn({children:t}){let[e,a]=react.useState([]),[l,r]=react.useState(""),[o,u]=react.useState(null),[c,i]=react.useState(false),[m]=react.useState(new Map),g=react.useCallback(s=>{if(!m.has(s)){let p=URL.createObjectURL(s);m.set(s,p);}return m.get(s)},[m]),n=react.useCallback(s=>{let p=m.get(s);p&&(URL.revokeObjectURL(p),m.delete(s));},[m]);return react.useEffect(()=>()=>{e.forEach(s=>{s.url&&s.url.startsWith("blob:")&&URL.revokeObjectURL(s.url);}),m.forEach(s=>URL.revokeObjectURL(s));},[e,m]),jsxRuntime.jsx(at.Provider,{value:{messages:e,setMessages:a},children:jsxRuntime.jsx(lt.Provider,{value:{inputMessage:l,setInputMessage:r},children:jsxRuntime.jsx(rt.Provider,{value:{loadingMessage:o,setLoadingMessage:u},children:jsxRuntime.jsx(ot.Provider,{value:{hasUnreadMessages:c,setHasUnreadMessages:i},children:jsxRuntime.jsx(nt.Provider,{value:{getFileUrl:g,removeFileUrl:n},children:t})})})})})}function Nn(){let t=react.useContext(at);if(t===void 0)throw new Error("useMessages must be used within a ChatProvider");return t}function zt(){let t=react.useContext(lt);if(t===void 0)throw new Error("useInput must be used within a ChatProvider");return t}function Mn(){let t=react.useContext(rt);if(t===void 0)throw new Error("useLoadingMessage must be used within a ChatProvider");return t}function Tn(){let t=react.useContext(nt);if(t===void 0)throw new Error("useFileUrls must be used within a ChatProvider");return t}function Ln(){let t=react.useContext(ot);if(t===void 0)throw new Error("useUnreadMessages must be used within a ChatProvider");return t}function z(){let t=react.useContext(at),e=react.useContext(lt),a=react.useContext(rt),l=react.useContext(ot),r=react.useContext(nt);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 Un(){let{loadingMessage:t}=z();return t?jsxRuntime.jsxs("div",{className:"chat-loading-message lua:flex lua:items-center lua:gap-2 lua:mx-4 lua:sm:mx-5",children:[jsxRuntime.jsx(luaniverse.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"}}),jsxRuntime.jsx("div",{className:"chat-loading-text lua:text-sm lua:opacity-40",children:t||"Lua is typing..."})]}):null}function Vt({buttons:t,onClick:e}){return jsxRuntime.jsx("div",{className:"chat-action-message lua:w-full",children:jsxRuntime.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)=>jsxRuntime.jsx(luaniverse.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,`
|
|
15
|
+
`;}return p?e.push({type:"list-item",content:l.trim(),isComplete:false}):n?e.push({type:"payment",content:r.trim(),isComplete:false}):s?e.push({type:"actions",content:o.trim(),isComplete:false}):g?e.push({type:"images",content:u.trim(),isComplete:false}):x?e.push({type:"links",content:c.trim(),isComplete:false}):d?e.push({type:"navigate",content:i.trim(),isComplete:false}):v?e.push({type:"documents",content:m.trim(),isComplete:false}):a.trim()&&e.push({type:"text",content:a.trim()}),e},Rt=Ya;function tl(t){let e=new Set(["br","hr","img","input","meta","link"]),a=[],l=/<\/?([a-z][a-z0-9]*)[^>]*>/gi,r=l.exec(t);for(;r!==null;){let o=r[0],u=r[1].toLowerCase();if(e.has(u)||o.endsWith("/>")){r=l.exec(t);continue}if(o.startsWith("</")){if(a.length===0||a.pop()!==u)return false}else a.push(u);r=l.exec(t);}return a.length===0}function It(t){let e=new Set(["br","hr","img","input","meta","link"]),a=/<\/?([a-z][a-z0-9]*)[^>]*>/gi,r=0,o=[],u;for(a.lastIndex=0;(u=a.exec(t))!==null;){let m=u[0],p=u[1].toLowerCase(),s=u.index+m.length;if(e.has(p)||m.endsWith("/>")){o.length===0&&(r=s);continue}m.startsWith("</")?o.length>0&&o[o.length-1]===p&&(o.pop(),o.length===0&&(r=s)):o.push(p);}let c=t.substring(0,r),i=r<t.length||o.length>0;return {completeHtml:c,hasIncompleteContent:i}}function Ut(t){return /^\s*<[a-z]+[\s>]/i.test(t.trim())?{isHtml:true,isComplete:tl(t)}:{isHtml:false,isComplete:false}}function $e(t){if(typeof window>"u")return "";let e={ALLOWED_TAGS:["div","b","ol","ul","li","a","br"],ALLOWED_ATTR:["style","href","target","rel"],ALLOW_DATA_ATTR:false,ALLOWED_URI_REGEXP:/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|data):|[^a-z]|[a-z+.-]+(?:[^a-z+.\-:]|$))/i};return el__default.default.sanitize(t,e)}function Me({images:t}){let[e,a]=react.useState(false),[l,r]=react.useState(0),o=react.useRef(null),[u,c]=react.useState(false),[i,m]=react.useState(0),[p,n]=react.useState(0),[s,g]=react.useState(0),x=react.useCallback(y=>{o.current&&(c(true),m(y.pageX-o.current.offsetLeft),n(o.current.scrollLeft),g(0),y.preventDefault());},[]),d=react.useCallback(y=>{if(!u||!o.current)return;y.preventDefault();let U=y.pageX-o.current.offsetLeft,O=(U-i)*2;o.current.scrollLeft=p-O,g(Math.abs(U-i));},[u,i,p]),v=react.useCallback(()=>{c(false);},[]),h=react.useCallback(()=>{c(false);},[]),N=react.useCallback((y,U)=>{if(s>5){U.preventDefault();return}r(y),a(true);},[s]);return jsxRuntime.jsxs("div",{"data-testid":"image-carousel-message",className:"chat-image-carousel-message lua:w-full",children:[jsxRuntime.jsx("div",{ref:o,className:"chat-image-carousel markdown-image-carousel",style:{cursor:u?"grabbing":"grab"},onMouseDown:x,onMouseMove:d,onMouseUp:v,onMouseLeave:h,onDragStart:y=>{y.preventDefault(),y.stopPropagation();},onDragOver:y=>{y.preventDefault(),y.stopPropagation();},children:t.map((y,U)=>jsxRuntime.jsx("div",{className:"chat-carousel-image-item markdown-image-item",onClick:O=>N(U,O),children:jsxRuntime.jsx("img",{src:y.src,alt:y.alt,draggable:false,style:{userSelect:"none"}})},y.src))}),jsxRuntime.jsx(bt,{images:t,initialIndex:l,open:e,onClose:()=>a(false)})]})}function _e({message:t}){let[e,a]=react.useState(false);return t.url?jsxRuntime.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:[jsxRuntime.jsxs("div",{className:"chat-image-container lua:relative",children:[jsxRuntime.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&&jsxRuntime.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:jsxRuntime.jsxs("div",{className:"lua:text-white lua:text-sm",children:["Uploading..."," ",t.uploadProgress?Math.round(t.uploadProgress):0,"%"]})})]}),!t.isUploading&&t.content.length>0&&jsxRuntime.jsx("div",{className:"chat-image-caption lua:w-full lua:bg-muted lua:text-foreground lua:rounded-2xl lua:px-4 lua:p-3 lua:mt-8",children:t.content}),jsxRuntime.jsx(xt,{url:t.url,alt:t.content,open:e,onClose:()=>a(false)})]}):null}function qe({url:t,luaApiUrl:e,authToken:a,disablePreviewOnLinks:l}){let[r,o]=react.useState(null),[u,c]=react.useState(true),[i,m]=react.useState(null);return react.useEffect(()=>{t&&e&&!l&&(async()=>{try{c(!0),m(null);let n=a;if(!n)throw new Error("No auth token available");let s=await fetch(`${e}/chat/url-metadata?url=${encodeURIComponent(t)}`,{headers:{Authorization:`Bearer ${n}`}});if(!s.ok)throw new Error(`Failed to fetch preview: ${s.status}`);let g=await s.json();o(g);}catch(n){console.error("Error fetching link preview:",n),m(n instanceof Error?n.message:"Failed to load preview");}finally{c(false);}})();},[t,e]),l?jsxRuntime.jsx("div",{className:"lua:mb-5 lua:mx-[-30px]",children:jsxRuntime.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",children:jsxRuntime.jsx(luaniverse.Button,{variant:"muted",children:t})})}):u?jsxRuntime.jsxs("div",{className:"lua:animate-pulse",children:[jsxRuntime.jsx("div",{className:"lua:bg-gray-300 lua:dark:bg-gray-600 lua:h-4 lua:w-3/4 lua:mb-2 lua:rounded"}),jsxRuntime.jsx("div",{className:"lua:bg-gray-300 lua:dark:bg-gray-600 lua:h-3 lua:w-1/2 lua:rounded"})]}):i||!r?jsxRuntime.jsx("div",{className:"lua:mb-5 lua:mx-[-30px]",children:jsxRuntime.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",children:jsxRuntime.jsx(luaniverse.Button,{variant:"muted",children:t})})}):jsxRuntime.jsxs("a",{href:r.url||t,target:"_blank",rel:"noopener noreferrer",className:"lua:block lua:border lua:border-gray-200 lua:dark:border-gray-700 lua:rounded-lg lua:p-3 lua:hover:bg-gray-50 lua:dark:hover:bg-gray-800 lua:transition-colors lua:no-underline lua:max-w-sm",children:[r.image&&jsxRuntime.jsx("img",{src:r.image,alt:r.title,className:"lua:w-full lua:h-32 lua:object-cover lua:rounded lua:mb-2",onError:p=>{p.currentTarget.style.display="none";}}),jsxRuntime.jsx("div",{className:"lua:text-sm lua:font-medium lua:text-gray-900 lua:dark:text-gray-50 lua:mb-1 lua:line-clamp-2",children:r.title}),r.description&&jsxRuntime.jsx("div",{className:"lua:text-xs lua:text-gray-600 lua:dark:text-gray-300 lua:line-clamp-2",children:r.description}),jsxRuntime.jsx("div",{className:"lua:text-xs lua:text-gray-400 lua:dark:text-gray-500 lua:mt-1 lua:truncate",children:new URL(r.url||t).hostname})]})}function Le({links:t,luaApiUrl:e,authToken:a,disablePreviewOnLinks:l}){return jsxRuntime.jsx("div",{"data-testid":"link-list-message",className:"chat-link-list-message lua:w-full",children:jsxRuntime.jsx("div",{className:"chat-links-container lua:space-y-2 lua:mx-4 lua:sm:mx-5",children:t.map(r=>jsxRuntime.jsx(qe,{url:r,luaApiUrl:e,authToken:a,disablePreviewOnLinks:l},r))})})}function Xe({location:t}){let e=[t.latitude,t.longitude];return jsxRuntime.jsx("div",{className:"lua:w-full lua:h-48 lua:rounded-lg lua:overflow-hidden",children:jsxRuntime.jsxs(reactLeaflet.MapContainer,{center:e,zoom:15,scrollWheelZoom:false,className:"lua:w-full lua:h-full",children:[jsxRuntime.jsx(reactLeaflet.TileLayer,{attribution:'\xA9 <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',url:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"}),jsxRuntime.jsx(reactLeaflet.Marker,{position:e,children:t.address&&jsxRuntime.jsx(reactLeaflet.Popup,{children:jsxRuntime.jsx("div",{children:t.address})})})]})})}function Ge({location:t}){return jsxRuntime.jsx("div",{className:"lua:w-full lua:h-full lua:rounded-lg lua:flex lua:items-center lua:justify-center lua:flex-col",children:t.address&&jsxRuntime.jsx(Xe,{location:t})})}function Ke({location:t}){return jsxRuntime.jsx("div",{className:"lua:w-full lua:h-60 lua:rounded-lg","data-testid":"location-preview",children:jsxRuntime.jsx(Ge,{location:t})})}function Qe({message:t}){return jsxRuntime.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-muted lua:text-foreground lua:rounded-2xl lua:p-3 lua:mx-4 lua:sm:mx-5",children:jsxRuntime.jsxs("div",{className:"chat-location-preview-container location-preview-container lua:relative",children:[t.location&&jsxRuntime.jsx(Ke,{location:t.location}),t.isUploading&&jsxRuntime.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:jsxRuntime.jsx("div",{className:"lua:text-white lua:text-sm",children:"Sharing location..."})}),jsxRuntime.jsxs("div",{className:"chat-location-info lua:flex lua:items-center lua:gap-2 lua:mt-3",children:[jsxRuntime.jsx(luaniverse.MapPin,{className:"lua:fill-gray-800 lua:dark:fill-gray-100"}),jsxRuntime.jsx("div",{className:"lua:flex-1",children:jsxRuntime.jsx("div",{className:"lua:text-sm",children:t.content})})]})]})})}function Ze({url:t,onNavigate:e}){let[a,l]=react.useState(false);return react.useEffect(()=>{if(e&&!a){l(true);let r=we(t);e(r.pathname,{...r.queryParams&&{query:r.queryParams}});}},[a,e]),null}function et({message:t}){return jsxRuntime.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:[jsxRuntime.jsxs("div",{className:"chat-video-container lua:relative",children:[jsxRuntime.jsx("video",{src:t.url,controls:true,className:"chat-video lua:rounded-lg lua:w-full"}),t.isUploading&&jsxRuntime.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:jsxRuntime.jsxs("div",{className:"lua:text-white lua:text-sm",children:["Uploading..."," ",t.uploadProgress?Math.round(t.uploadProgress):0,"%"]})})]}),!t.isUploading&&t.content&&jsxRuntime.jsx("div",{className:"chat-video-caption lua:w-full lua:bg-muted lua:text-foreground lua:rounded-2xl lua:px-4 lua:p-3 lua:mt-8",children:t.content})]})}function fl(t){return new Date(t).toLocaleTimeString()}function hl(t){return {icon:()=>null}}var xn=react.memo(function({message:e,onSelect:a,luaApiUrl:l,authToken:r,disablePreviewOnLinks:o=false,onNavigate:u}){let c=react.useCallback(p=>{let n=p.match(/^#\s+(.+)$/m),s=p.match(/^##\s+(.+)$/m),g=n?n[1]:"",x=s?s[1]:"",d=`${g}. ${x}`;a&&a(d);},[a]),i=react.useCallback(p=>{if(!a)return;let n=At(p).trim();a(n);},[a]),m=react.useCallback(()=>{if(e.type==="location")return jsxRuntime.jsx(Qe,{message:e});if(e.mediaType?.startsWith("video"))return e.url?jsxRuntime.jsx(et,{message:{url:e.url,content:e.content||"",isUploading:e.isUploading,uploadProgress:e.uploadProgress}}):null;if(e.mediaType?.startsWith("image"))return e.url?jsxRuntime.jsx(_e,{message:{url:e.url,content:e.content||"",isUploading:e.isUploading,uploadProgress:e.uploadProgress}}):null;if(e.mediaType?.startsWith("audio"))return jsxRuntime.jsx(Lt,{message:e});if(e.type==="file"&&e.mediaType){let x=hl(new File([],"",{type:e.mediaType})).icon;return jsxRuntime.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:jsxRuntime.jsxs("div",{className:"lua:flex lua:flex-col lua:gap-8",children:[jsxRuntime.jsxs("div",{className:"chat-file-card lua:flex lua:items-center lua:justify-start lua:p-3 lua:border lua:border-border lua:rounded-lg lua:bg-card lua:dark:bg-card lua:w-80",children:[jsxRuntime.jsx(x,{className:"lua:w-12 lua:h-12 lua:text-gray-500 lua:dark:text-gray-400"}),jsxRuntime.jsxs("div",{className:"lua:flex lua:flex-col lua:gap-1 lua:pl-2",children:["File",jsxRuntime.jsx("span",{className:"lua:text-gray-500 lua:dark:text-gray-400 lua:text-sm",children:e.mediaType})]})]}),e.content&&jsxRuntime.jsx("div",{className:"chat-file-content lua:bg-muted lua:dark:bg-muted lua:rounded-2xl lua:px-4 lua:py-2 lua:w-80",children:jsxRuntime.jsx("div",{className:"lua:text-sm lua:text-foreground",children:e.content})})]})})}if(e.role==="user")return e.content;if(e.content==="...")return null;let p=Ut(e.content);if(p.isHtml){if(p.isComplete){let d=$e(e.content);return jsxRuntime.jsx("div",{className:"chat-html-content lua:prose lua:prose-sm lua:max-w-none lua:mx-4 lua:sm:mx-5",dangerouslySetInnerHTML:{__html:d}})}let{completeHtml:g,hasIncompleteContent:x}=It(e.content);if(g){let d=$e(g);return jsxRuntime.jsxs("div",{className:"lua:mx-4 lua:sm:mx-5",children:[jsxRuntime.jsx("div",{className:"chat-html-content lua:prose lua:prose-sm lua:max-w-none",dangerouslySetInnerHTML:{__html:d}}),x&&jsxRuntime.jsx("div",{className:"lua:flex lua:items-center lua:gap-2 lua:text-gray-500 lua:dark:text-gray-400 lua:mt-2",children:jsxRuntime.jsx(luaniverse.LogoSpinner,{size:14})})]})}return jsxRuntime.jsx("div",{className:"lua:flex lua:items-center lua:gap-2 lua:text-gray-500 lua:dark:text-gray-400 lua:mx-4 lua:sm:mx-5",children:jsxRuntime.jsx("div",{className:"lua:animate-pulse",children:"\u25CF\u25CF\u25CF"})})}let n=Rt(e.content),s=be(i);return jsxRuntime.jsx("div",{className:"chat-markdown-content lua:prose lua:prose-sm lua:max-w-none",children:jsxRuntime.jsx("div",{className:"lua:flex lua:flex-wrap lua:gap-4",children:(()=>{if(n.filter(d=>d.type==="list-item").length>1){let d=[],v=[];return n.forEach(h=>{h.type==="list-item"?v.push(h):(v.length>0&&(d.push(v),v=[]),d.push([h]));}),v.length>0&&d.push(v),d.map((h,N)=>h.length>1&&h[0].type==="list-item"?jsxRuntime.jsx(Mt,{group:h,onCardClick:c,onListItemClick:i,onNavigate:u},N):h.map((w,f)=>{if(w.type==="list-item")return jsxRuntime.jsx(oe,{block:w,onCardClick:c,onListItemClick:i,onNavigate:u},f);if(w.type==="actions")return Se(w.content).length>0&&w.isComplete,null;if(w.type==="images"){let y=He(w.content);if(y.length>0)return jsxRuntime.jsx(Me,{images:y},f)}if(w.type==="links"){let y=Fe(w.content);return y.length>0&&w.isComplete?jsxRuntime.jsx(Le,{links:y,luaApiUrl:l||"",authToken:r||"",disablePreviewOnLinks:o},f):null}if(w.type==="navigate"){let y=Oe(w.content);return y&&w.isComplete?jsxRuntime.jsx(Ze,{text:y.text,url:y.url,onNavigate:u},f):null}if(w.type==="documents"){let y=Ie(w.content);return jsxRuntime.jsx(Ne,{documents:y},f)}if(w.type==="payment"){let y=Be(w.content);return y?jsxRuntime.jsx("div",{className:"chat-payment-message lua:w-full lua:mx-4 lua:sm:mx-5",children:jsxRuntime.jsx(Ee,{url:y})},f):null}return jsxRuntime.jsx("div",{className:"chat-markdown-block lua:w-full",children:jsxRuntime.jsx(Ot__default.default,{components:s,children:w.content})},f)}))}return n.map((d,v)=>{if(d.type==="list-item")return jsxRuntime.jsx(oe,{block:d,onCardClick:c,onListItemClick:i,onNavigate:u},v);if(d.type==="actions")return Se(d.content).length>0&&d.isComplete,null;if(d.type==="images"){let h=He(d.content);if(h.length>0)return jsxRuntime.jsx(Me,{images:h},v)}if(d.type==="navigate"){let h=Oe(d.content);return h&&d.isComplete?jsxRuntime.jsx(Ze,{text:h.text,url:h.url,onNavigate:u},v):null}if(d.type==="documents"){let h=Ie(d.content);return jsxRuntime.jsx(Ne,{documents:h},v)}if(d.type==="links"){let h=Fe(d.content);return h.length>0&&d.isComplete?jsxRuntime.jsx(Le,{links:h,luaApiUrl:l||"",authToken:r||"",disablePreviewOnLinks:o},v):null}if(d.type==="payment"){let h=Be(d.content);return h?jsxRuntime.jsx("div",{className:"chat-payment-message lua:w-full lua:mx-4 lua:sm:mx-5 lua:mb-5",children:jsxRuntime.jsx(Ee,{url:h})},v):null}return jsxRuntime.jsx("div",{className:"chat-markdown-block lua:w-full",children:jsxRuntime.jsx(Ot__default.default,{components:s,children:d.content})},v)})})()})})},[e,c,i]);return jsxRuntime.jsxs("div",{className:`chat-message-container lua:flex lua:flex-col ${e.role==="user"?"lua:items-end":"lua:items-start"} lua:gap-1`,children:[jsxRuntime.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!=="..."&&jsxRuntime.jsx("div",{className:`chat-message-bubble ${e.role==="user"?"chat-message-bubble-user lua:max-w-full lua:md:max-w-3/5 lua:bg-muted lua:dark:bg-muted lua:text-foreground 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-card lua:dark:bg-card lua:text-foreground lua:rounded-lg lua:py-3 lua:rounded-bl-none"}`,style:{wordBreak:"break-word"},children:m()}),["file","image","video","location"].includes(e.type||"")&&m()]}),jsxRuntime.jsx("div",{className:`lua-message-timestamp lua:text-xs lua:text-gray-400 lua:dark:text-gray-500 lua:px-1 ${e.role==="user"?"lua:mr-4 sm:lua:mr-5":"lua:ml-4 sm:lua:ml-5"}`,children:fl(e.createdAt)})]})});var at=react.createContext(void 0),lt=react.createContext(void 0),rt=react.createContext(void 0),ot=react.createContext(void 0),nt=react.createContext(void 0);function Nn({children:t}){let[e,a]=react.useState([]),[l,r]=react.useState(""),[o,u]=react.useState(null),[c,i]=react.useState(false),[m]=react.useState(new Map),p=react.useCallback(s=>{if(!m.has(s)){let g=URL.createObjectURL(s);m.set(s,g);}return m.get(s)},[m]),n=react.useCallback(s=>{let g=m.get(s);g&&(URL.revokeObjectURL(g),m.delete(s));},[m]);return react.useEffect(()=>()=>{e.forEach(s=>{s.url&&s.url.startsWith("blob:")&&URL.revokeObjectURL(s.url);}),m.forEach(s=>URL.revokeObjectURL(s));},[e,m]),jsxRuntime.jsx(at.Provider,{value:{messages:e,setMessages:a},children:jsxRuntime.jsx(lt.Provider,{value:{inputMessage:l,setInputMessage:r},children:jsxRuntime.jsx(rt.Provider,{value:{loadingMessage:o,setLoadingMessage:u},children:jsxRuntime.jsx(ot.Provider,{value:{hasUnreadMessages:c,setHasUnreadMessages:i},children:jsxRuntime.jsx(nt.Provider,{value:{getFileUrl:p,removeFileUrl:n},children:t})})})})})}function kn(){let t=react.useContext(at);if(t===void 0)throw new Error("useMessages must be used within a ChatProvider");return t}function zt(){let t=react.useContext(lt);if(t===void 0)throw new Error("useInput must be used within a ChatProvider");return t}function Mn(){let t=react.useContext(rt);if(t===void 0)throw new Error("useLoadingMessage must be used within a ChatProvider");return t}function Tn(){let t=react.useContext(nt);if(t===void 0)throw new Error("useFileUrls must be used within a ChatProvider");return t}function Ln(){let t=react.useContext(ot);if(t===void 0)throw new Error("useUnreadMessages must be used within a ChatProvider");return t}function z(){let t=react.useContext(at),e=react.useContext(lt),a=react.useContext(rt),l=react.useContext(ot),r=react.useContext(nt);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 Un(){let{loadingMessage:t}=z();return t?jsxRuntime.jsxs("div",{className:"chat-loading-message lua:flex lua:items-center lua:gap-2 lua:mx-4 lua:sm:mx-5",children:[jsxRuntime.jsx(luaniverse.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"}}),jsxRuntime.jsx("div",{className:"chat-loading-text lua:text-sm lua:opacity-40",children:t||"Lua is typing..."})]}):null}function Vt({buttons:t,onClick:e}){return jsxRuntime.jsx("div",{className:"chat-action-message lua:w-full",children:jsxRuntime.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)=>jsxRuntime.jsx(luaniverse.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(g=>g.trim()).filter(g=>g&&g.startsWith("-")).map(g=>({text:g.replace(/^-[\s]?/,"").trim(),onClick:g.replace(/^-[\s]?/,"").trim()}))};function Vn({onSelect:t}){let{messages:e}=z();if(e.length===0)return null;let a=e[e.length-1],l=_t(a.content);return l.length===0?null:jsxRuntime.jsx(Vt,{buttons:l,onClick:t})}var di=react.memo(function({onSend:e,disabled:a=false,onFilePaste:l}){let{inputMessage:r,setInputMessage:o}=zt(),[u,c]=react.useState(false),i=react.useRef(null);react.useEffect(()=>{let n=()=>{c(window.matchMedia("(max-width: 768px)").matches||/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));};return n(),window.addEventListener("resize",n),()=>{window.removeEventListener("resize",n);}},[]),react.useEffect(()=>{let n=i.current;n&&(a||(n.style.height="auto",n.style.height=`${n.scrollHeight}px`));},[r]);let m=n=>{if(n.key==="Enter"){if(u||n.shiftKey||n.metaKey||n.ctrlKey)return;n.preventDefault(),e();}},g=react.useCallback(n=>{let{items:s}=n.clipboardData;if(!s||!l)return;let p=[];for(let y=0;y<s.length;y++){let d=s[y];if(d.kind==="file"){let v=d.getAsFile();v&&p.push(v);}}p.length>0&&(n.preventDefault(),l(p));},[l]);return jsxRuntime.jsxs("div",{className:"lua:flex lua:gap-3 lua:py-2 lua:px-3 lua:items-start",children:[jsxRuntime.jsx(luaniverse.Logo,{size:32,className:"lua:w-8 lua:h-8 lua:rounded-full lua:flex-shrink-0 lua:m-1"}),jsxRuntime.jsx("div",{className:"lua:flex-1 lua:flex",children:jsxRuntime.jsx("textarea",{ref:i,disabled:a,value:r,onChange:n=>o(n.target.value),onKeyDown:m,onPaste:g,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:dark:text-gray-200 lua:placeholder:text-gray-400 lua:dark:placeholder:text-gray-500 lua:min-h-10 lua:max-h-48 lua:bg-transparent${a?" lua:cursor-not-allowed lua:h-14":""}`,rows:1})})]})});function Al(){return localStorage.getItem("authToken")}async function Z(t,e,a){let l=Al();if(!l)throw new Error("No auth token found");return new Promise((r,o)=>{let u=new XMLHttpRequest,c=new FormData;c.append("file",t),u.upload.addEventListener("progress",i=>{if(i.lengthComputable&&a){let m=i.loaded/i.total*100;a(m);}}),u.addEventListener("load",()=>{if(u.status>=200&&u.status<300)try{let i=JSON.parse(u.responseText);r(i);}catch{o(new Error("Failed to parse response"));}else o(new Error(`Failed to upload file: ${u.status}`));}),u.addEventListener("error",()=>{o(new Error("Network error occurred"));}),u.open("POST",`${e}/upload`),u.setRequestHeader("Authorization",`Bearer ${l}`),u.send(c);})}function Dl(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 ct({file:t,onRemove:e,cdnUrl:a,initialUrl:l,onUploadComplete:r}){let o=Dl(t),u=o.icon,[c,i]=react.useState(false),[m,g]=react.useState(0),[n,s]=react.useState(l||null),p=react.useRef(false);return react.useEffect(()=>{if(n||p.current)return;(async()=>{i(true),p.current=true;try{let{fileId:d}=await Z(t,a,h=>{g(h);}),v=`${a}/${d}`;s(v),i(!1),r&&r(t,v);}catch(d){console.error("Upload failed for file:",t.name,d),i(false),p.current=false;}})();},[t,a,r,n]),jsxRuntime.jsxs("div",{className:"lua:flex lua:items-center lua:gap-4 lua:p-3 lua:bg-white lua:dark:bg-gray-800 lua:border lua:border-gray-200 lua:dark:border-gray-700 lua:rounded-lg",children:[jsxRuntime.jsx("div",{className:"lua:flex-shrink-0",children:c?jsxRuntime.jsxs("div",{className:"lua:w-8 lua:h-8 lua:flex lua:flex-col lua:items-center lua:justify-center",children:[jsxRuntime.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"}),jsxRuntime.jsxs("div",{className:"lua:mt-1 lua:text-xs lua:text-gray-600 lua:dark:text-gray-300 lua:font-medium",children:[Math.round(m),"%"]})]}):jsxRuntime.jsx(u,{className:"lua:w-8 lua:h-8 lua:text-gray-600 lua:dark:text-gray-400"})}),jsxRuntime.jsxs("div",{className:"lua:flex-grow lua:min-w-0",children:[jsxRuntime.jsx("p",{className:"lua:text-sm lua:font-medium lua:text-gray-900 lua:dark:text-gray-100 lua:truncate",children:t.name}),jsxRuntime.jsx("p",{className:"lua:text-xs lua:text-gray-500 lua:dark:text-gray-400",children:o.label})]}),jsxRuntime.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-gray-800 lua:dark:bg-gray-700 lua:text-white lua:hover:bg-gray-700 lua:dark:hover:bg-gray-600 lua:transition-colors",children:jsxRuntime.jsx(luaniverse.XIcon,{className:"lua:w-4 lua:h-4"})})]})}function dt({file:t,onRemove:e,cdnUrl:a,initialUrl:l,onUploadComplete:r}){let{getFileUrl:o}=z(),[u,c]=react.useState(false),[i,m]=react.useState(0),[g,n]=react.useState(l||null),[s,p]=react.useState(false);react.useEffect(()=>{if(l||s)return;(async()=>{c(true),p(true);try{let{fileId:v}=await Z(t,a,k=>{m(k);}),h=`${a}/${v}`;n(h),c(!1),r&&r(t,h);}catch(v){console.error("Upload failed:",v),c(false);}})();},[t,l,a,s,r]);let y=g||(u?void 0:o(t));return jsxRuntime.jsxs("div",{className:"lua:relative lua:flex-shrink-0",children:[u?jsxRuntime.jsxs("div",{className:"lua:w-32 lua:h-32 lua:bg-gray-100 lua:dark:bg-gray-800 lua:rounded-lg lua:flex lua:flex-col lua:items-center lua:justify-center",children:[jsxRuntime.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"}),jsxRuntime.jsxs("div",{className:"lua:mt-2 lua:text-xs lua:text-gray-600 lua:dark:text-gray-300 lua:font-medium",children:[Math.round(i),"%"]})]}):y?jsxRuntime.jsx("img",{"data-testid":"image-thumbnail",src:y,alt:t.name,className:"lua:w-32 lua:h-32 lua:object-cover lua:rounded-lg"}):jsxRuntime.jsx("div",{className:"lua:w-32 lua:h-32 lua:bg-gray-200 lua:dark:bg-gray-700 lua:rounded-lg lua:flex lua:items-center lua:justify-center",children:jsxRuntime.jsx("span",{className:"lua:text-gray-500 lua:dark:text-gray-400",children:"No preview"})}),jsxRuntime.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"]}),jsxRuntime.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-gray-800 lua:dark:bg-gray-700 lua:text-white lua:hover:bg-gray-700 lua:dark:hover:bg-gray-600 lua:transition-colors",children:jsxRuntime.jsx("span",{className:"lua:text-sm",children:"\xD7"})})]})}function mt({file:t,onRemove:e,cdnUrl:a,initialUrl:l,thumbnailUrl:r,onUploadComplete:o}){let{getFileUrl:u}=z(),[c,i]=react.useState(false),[m,g]=react.useState(0),[n,s]=react.useState(l||null),[p,y]=react.useState(false),[d,v]=react.useState(r||null);return react.useEffect(()=>{if(!r&&!d){let h=u(t),k=document.createElement("video");k.src=h;let w=()=>{try{k.currentTime=0,setTimeout(()=>{let f=document.createElement("canvas");f.width=k.videoWidth,f.height=k.videoHeight;let x=f.getContext("2d");if(!x){console.error("Could not get canvas context");return}x.drawImage(k,0,0);let U=f.toDataURL("image/jpeg",.8);v(U);},100);}catch(f){console.error("Error generating thumbnail:",f);}finally{URL.revokeObjectURL(h),k.removeEventListener("canplay",w);}};k.addEventListener("canplay",w),k.load();}},[t,r,d]),react.useEffect(()=>{if(l||p)return;(async()=>{i(true),y(true);try{let{fileId:k}=await Z(t,a,f=>{g(f);}),w=`${a}/${k}`;s(w),i(!1),o&&o(t,w);}catch(k){console.error("Upload failed:",k),i(false);}})();},[t,l,a,p,o]),jsxRuntime.jsxs("div",{className:"lua:relative lua:flex-shrink-0",children:[c?jsxRuntime.jsxs("div",{className:"lua:w-32 lua:h-32 lua:bg-gray-100 lua:dark:bg-gray-800 lua:rounded-lg lua:flex lua:flex-col lua:items-center lua:justify-center",children:[jsxRuntime.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"}),jsxRuntime.jsxs("div",{className:"lua:mt-2 lua:text-xs lua:text-gray-600 lua:dark:text-gray-300 lua:font-medium",children:[Math.round(m),"%"]})]}):jsxRuntime.jsxs("div",{className:"lua:relative",children:[jsxRuntime.jsx("img",{"data-testid":"video-thumbnail",src:d||n||"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 lua:dark:bg-gray-800"}),jsxRuntime.jsx("div",{className:"lua:absolute lua:inset-0 lua:flex lua:items-center lua:justify-center",children:jsxRuntime.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:jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:jsxRuntime.jsx("path",{d:"M5 3L19 12L5 21V3Z",fill:"white"})})})})]}),jsxRuntime.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"]}),jsxRuntime.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-gray-800 lua:dark:bg-gray-700 lua:text-white lua:hover:bg-gray-700 lua:dark:hover:bg-gray-600 lua:transition-colors",children:jsxRuntime.jsx("span",{className:"lua:text-sm",children:"\xD7"})})]})}function jt(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 Ei({files:t,onRemove:e,cdnUrl:a,fileMetadata:l=[],onFileUploadComplete:r}){let[o,u]=react.useState({});return react.useEffect(()=>{t.forEach((c,i)=>{let m=jt(c),g=l.find(n=>n.file===c);if(m.category==="video"&&!o[i]&&!g){let n=URL.createObjectURL(c),s=document.createElement("video");s.src=n;let p=()=>{try{s.currentTime=0,setTimeout(()=>{let y=document.createElement("canvas");y.width=s.videoWidth,y.height=s.videoHeight;let d=y.getContext("2d");if(!d){console.error("Could not get canvas context");return}d.drawImage(s,0,0);let v=y.toDataURL("image/jpeg",.8);u(h=>({...h,[i]:v}));},100);}catch(y){console.error("Error generating thumbnail:",y);}finally{URL.revokeObjectURL(n),s.removeEventListener("canplay",p);}};s.addEventListener("canplay",p),s.load();}});},[t,l]),t.length===0?null:jsxRuntime.jsx("div",{className:"lua:px-4 lua:py-2 lua:border-b lua:border-gray-200",children:jsxRuntime.jsx("div",{className:"lua:flex lua:gap-2 lua:overflow-x-auto scrollbar-hide",children:t.map((c,i)=>{let m=jt(c),g=l.find(n=>n.file===c);return t.length>1?jsxRuntime.jsx("div",{className:"lua:flex-shrink-0 lua:w-64",children:jsxRuntime.jsx(ct,{file:c,onRemove:()=>e(i),cdnUrl:a,onUploadComplete:(n,s)=>{r&&r(n,s);}})},i):m.category==="image"?jsxRuntime.jsx(dt,{file:c,onRemove:()=>e(i),cdnUrl:a,initialUrl:g?.url,onUploadComplete:(n,s)=>{r&&r(n,s);}},c.name):m.category==="video"?jsxRuntime.jsx(mt,{file:c,onRemove:()=>e(i),cdnUrl:a,initialUrl:g?.url,thumbnailUrl:o[i],onUploadComplete:(n,s)=>{r&&r(n,s);}},c.name):jsxRuntime.jsx("div",{className:"lua:flex-shrink-0 lua:w-64",children:jsxRuntime.jsx(ct,{file:c,onRemove:()=>e(i),cdnUrl:a,onUploadComplete:(n,s)=>{r&&r(n,s);}})},i)})})})}var ee={CHAT:{TOOLBAR_ACTION:{FILE_UPLOAD:"file_upload",CAMERA:"camera",VIDEO:"video",AUDIO:"audio",LOCATION:"location"},MESSAGE_SENT:"message_sent"}};function te(t){console.log("Analytics event:",t);}function Oi({loading:t,onFileClick:e,onCameraClick:a,onVideoClick:l,onAudioClick:r,onLocationClick:o,onSendClick:u}){return jsxRuntime.jsxs("div",{className:"lua:flex lua:items-center lua:justify-between lua:border-t lua:border-gray-200 lua:dark:border-gray-700 lua:bg-gray-50 lua:dark:bg-gray-800 lua:px-3 lua:py-2",children:[jsxRuntime.jsxs("div",{className:"lua:flex lua:items-center lua:gap-2",children:[jsxRuntime.jsxs(luaniverse.Tooltip,{children:[jsxRuntime.jsx(luaniverse.TooltipTrigger,{asChild:true,children:jsxRuntime.jsx(luaniverse.IconButton,{className:"lua:rounded-lg",variant:"muted",onClick:()=>{te(ee.CHAT.TOOLBAR_ACTION.FILE_UPLOAD),e();},disabled:t,"data-testid":"file-upload-button",children:jsxRuntime.jsx(luaniverse.Paperclip,{className:"lua:text-gray-600 lua:dark:text-gray-300"})})}),jsxRuntime.jsxs(luaniverse.TooltipContent,{children:[jsxRuntime.jsx(luaniverse.TooltipArrow,{}),jsxRuntime.jsx("p",{children:"Attach files"})]})]}),jsxRuntime.jsx("div",{className:"lua:w-px lua:h-5 lua:bg-gray-200 lua:dark:bg-gray-600"}),jsxRuntime.jsxs(luaniverse.Tooltip,{children:[jsxRuntime.jsx(luaniverse.TooltipTrigger,{asChild:true,children:jsxRuntime.jsx(luaniverse.IconButton,{className:"lua:rounded-lg",variant:"muted",onClick:()=>{te(ee.CHAT.TOOLBAR_ACTION.CAMERA),a();},disabled:t,"data-testid":"camera-button",children:jsxRuntime.jsx(luaniverse.Camera,{className:"lua:text-gray-600 lua:dark:text-gray-300"})})}),jsxRuntime.jsxs(luaniverse.TooltipContent,{children:[jsxRuntime.jsx(luaniverse.TooltipArrow,{}),jsxRuntime.jsx("p",{children:"Take a picture"})]})]}),jsxRuntime.jsxs(luaniverse.Tooltip,{children:[jsxRuntime.jsx(luaniverse.TooltipTrigger,{asChild:true,children:jsxRuntime.jsx(luaniverse.IconButton,{className:"lua:rounded-lg",variant:"muted",onClick:()=>{te(ee.CHAT.TOOLBAR_ACTION.VIDEO),l();},disabled:t,"data-testid":"video-button",children:jsxRuntime.jsx(luaniverse.VideoCamera,{className:"lua:text-gray-600 lua:dark:text-gray-300"})})}),jsxRuntime.jsxs(luaniverse.TooltipContent,{children:[jsxRuntime.jsx(luaniverse.TooltipArrow,{}),jsxRuntime.jsx("p",{children:"Record video"})]})]}),jsxRuntime.jsxs(luaniverse.Tooltip,{children:[jsxRuntime.jsx(luaniverse.TooltipTrigger,{asChild:true,children:jsxRuntime.jsx(luaniverse.IconButton,{className:"lua:rounded-lg",variant:"muted",onClick:()=>{te(ee.CHAT.TOOLBAR_ACTION.AUDIO),r();},disabled:t,"data-testid":"audio-button",children:jsxRuntime.jsx(luaniverse.Microphone,{className:"lua:text-gray-600 lua:dark:text-gray-300"})})}),jsxRuntime.jsxs(luaniverse.TooltipContent,{children:[jsxRuntime.jsx(luaniverse.TooltipArrow,{}),jsxRuntime.jsx("p",{children:"Record voice message"})]})]}),jsxRuntime.jsx("div",{className:"lua:w-px lua:h-5 lua:bg-gray-200 lua:dark:bg-gray-600"}),jsxRuntime.jsxs(luaniverse.Tooltip,{children:[jsxRuntime.jsx(luaniverse.TooltipTrigger,{asChild:true,children:jsxRuntime.jsx(luaniverse.IconButton,{className:"lua:rounded-lg",variant:"muted",onClick:()=>{te(ee.CHAT.TOOLBAR_ACTION.LOCATION),o();},disabled:t,"data-testid":"location-button",children:jsxRuntime.jsx(luaniverse.MapPin,{className:"lua:text-gray-600 lua:dark:text-gray-300"})})}),jsxRuntime.jsxs(luaniverse.TooltipContent,{children:[jsxRuntime.jsx(luaniverse.TooltipArrow,{}),jsxRuntime.jsx("p",{children:"Share location"})]})]})]}),jsxRuntime.jsx(luaniverse.IconButton,{onClick:()=>{te(ee.CHAT.MESSAGE_SENT),u();},disabled:t,"data-testid":"send-button",variant:"default",children:jsxRuntime.jsx(luaniverse.ArrowUp,{})})]})}
|
|
18
|
-
exports.ActionMessage=Vt;exports.AudioPreview=Lt;exports.AudioRecorder=jl;exports.CameraDialog=
|
|
17
|
+
`).map(p=>p.trim()).filter(p=>p&&p.startsWith("-")).map(p=>({text:p.replace(/^-[\s]?/,"").trim(),onClick:p.replace(/^-[\s]?/,"").trim()}))};function Vn({onSelect:t}){let{messages:e}=z();if(e.length===0)return null;let a=e[e.length-1],l=_t(a.content);return l.length===0?null:jsxRuntime.jsx(Vt,{buttons:l,onClick:t})}var di=react.memo(function({onSend:e,disabled:a=false,onFilePaste:l}){let{inputMessage:r,setInputMessage:o}=zt(),[u,c]=react.useState(false),i=react.useRef(null);react.useEffect(()=>{let n=()=>{c(window.matchMedia("(max-width: 768px)").matches||/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));};return n(),window.addEventListener("resize",n),()=>{window.removeEventListener("resize",n);}},[]),react.useEffect(()=>{let n=i.current;n&&(a||(n.style.height="auto",n.style.height=`${n.scrollHeight}px`));},[r]);let m=n=>{if(n.key==="Enter"){if(u||n.shiftKey||n.metaKey||n.ctrlKey)return;n.preventDefault(),e();}},p=react.useCallback(n=>{let{items:s}=n.clipboardData;if(!s||!l)return;let g=[];for(let x=0;x<s.length;x++){let d=s[x];if(d.kind==="file"){let v=d.getAsFile();v&&g.push(v);}}g.length>0&&(n.preventDefault(),l(g));},[l]);return jsxRuntime.jsxs("div",{className:"lua:flex lua:gap-3 lua:py-2 lua:px-3 lua:items-start",children:[jsxRuntime.jsx(luaniverse.Logo,{size:32,className:"lua:w-8 lua:h-8 lua:rounded-full lua:flex-shrink-0 lua:m-1"}),jsxRuntime.jsx("div",{className:"lua:flex-1 lua:flex",children:jsxRuntime.jsx("textarea",{ref:i,disabled:a,value:r,onChange:n=>o(n.target.value),onKeyDown:m,onPaste:p,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:dark:text-gray-200 lua:placeholder:text-gray-400 lua:dark:placeholder:text-gray-500 lua:min-h-10 lua:max-h-48 lua:bg-transparent${a?" lua:cursor-not-allowed lua:h-14":""}`,rows:1})})]})});function Al(){return localStorage.getItem("authToken")}async function Z(t,e,a){let l=Al();if(!l)throw new Error("No auth token found");return new Promise((r,o)=>{let u=new XMLHttpRequest,c=new FormData;c.append("file",t),u.upload.addEventListener("progress",i=>{if(i.lengthComputable&&a){let m=i.loaded/i.total*100;a(m);}}),u.addEventListener("load",()=>{if(u.status>=200&&u.status<300)try{let i=JSON.parse(u.responseText);r(i);}catch{o(new Error("Failed to parse response"));}else o(new Error(`Failed to upload file: ${u.status}`));}),u.addEventListener("error",()=>{o(new Error("Network error occurred"));}),u.open("POST",`${e}/upload`),u.setRequestHeader("Authorization",`Bearer ${l}`),u.send(c);})}function Dl(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 ct({file:t,onRemove:e,cdnUrl:a,initialUrl:l,onUploadComplete:r}){let o=Dl(t),u=o.icon,[c,i]=react.useState(false),[m,p]=react.useState(0),[n,s]=react.useState(l||null),g=react.useRef(false);return react.useEffect(()=>{if(n||g.current)return;(async()=>{i(true),g.current=true;try{let{fileId:d}=await Z(t,a,h=>{p(h);}),v=`${a}/${d}`;s(v),i(!1),r&&r(t,v);}catch(d){console.error("Upload failed for file:",t.name,d),i(false),g.current=false;}})();},[t,a,r,n]),jsxRuntime.jsxs("div",{className:"lua:flex lua:items-center lua:gap-4 lua:p-3 lua:bg-card lua:border lua:border-border lua:rounded-lg",children:[jsxRuntime.jsx("div",{className:"lua:flex-shrink-0",children:c?jsxRuntime.jsxs("div",{className:"lua:w-8 lua:h-8 lua:flex lua:flex-col lua:items-center lua:justify-center",children:[jsxRuntime.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"}),jsxRuntime.jsxs("div",{className:"lua:mt-1 lua:text-xs lua:text-gray-600 lua:dark:text-gray-300 lua:font-medium",children:[Math.round(m),"%"]})]}):jsxRuntime.jsx(u,{className:"lua:w-8 lua:h-8 lua:text-gray-600 lua:dark:text-gray-400"})}),jsxRuntime.jsxs("div",{className:"lua:flex-grow lua:min-w-0",children:[jsxRuntime.jsx("p",{className:"lua:text-sm lua:font-medium lua:text-gray-900 lua:dark:text-gray-100 lua:truncate",children:t.name}),jsxRuntime.jsx("p",{className:"lua:text-xs lua:text-gray-500 lua:dark:text-gray-400",children:o.label})]}),jsxRuntime.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-gray-800 lua:dark:bg-gray-700 lua:text-white lua:hover:bg-gray-700 lua:dark:hover:bg-gray-600 lua:transition-colors",children:jsxRuntime.jsx(luaniverse.XIcon,{className:"lua:w-4 lua:h-4"})})]})}function dt({file:t,onRemove:e,cdnUrl:a,initialUrl:l,onUploadComplete:r}){let{getFileUrl:o}=z(),[u,c]=react.useState(false),[i,m]=react.useState(0),[p,n]=react.useState(l||null),[s,g]=react.useState(false);react.useEffect(()=>{if(l||s)return;(async()=>{c(true),g(true);try{let{fileId:v}=await Z(t,a,N=>{m(N);}),h=`${a}/${v}`;n(h),c(!1),r&&r(t,h);}catch(v){console.error("Upload failed:",v),c(false);}})();},[t,l,a,s,r]);let x=p||(u?void 0:o(t));return jsxRuntime.jsxs("div",{className:"lua:relative lua:flex-shrink-0",children:[u?jsxRuntime.jsxs("div",{className:"lua:w-32 lua:h-32 lua:bg-muted lua:rounded-lg lua:flex lua:flex-col lua:items-center lua:justify-center",children:[jsxRuntime.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"}),jsxRuntime.jsxs("div",{className:"lua:mt-2 lua:text-xs lua:text-gray-600 lua:dark:text-gray-300 lua:font-medium",children:[Math.round(i),"%"]})]}):x?jsxRuntime.jsx("img",{"data-testid":"image-thumbnail",src:x,alt:t.name,className:"lua:w-32 lua:h-32 lua:object-cover lua:rounded-lg"}):jsxRuntime.jsx("div",{className:"lua:w-32 lua:h-32 lua:bg-muted lua:rounded-lg lua:flex lua:items-center lua:justify-center",children:jsxRuntime.jsx("span",{className:"lua:text-gray-500 lua:dark:text-gray-400",children:"No preview"})}),jsxRuntime.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"]}),jsxRuntime.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-gray-800 lua:dark:bg-gray-700 lua:text-white lua:hover:bg-gray-700 lua:dark:hover:bg-gray-600 lua:transition-colors",children:jsxRuntime.jsx("span",{className:"lua:text-sm",children:"\xD7"})})]})}function mt({file:t,onRemove:e,cdnUrl:a,initialUrl:l,thumbnailUrl:r,onUploadComplete:o}){let{getFileUrl:u}=z(),[c,i]=react.useState(false),[m,p]=react.useState(0),[n,s]=react.useState(l||null),[g,x]=react.useState(false),[d,v]=react.useState(r||null);return react.useEffect(()=>{if(!r&&!d){let h=u(t),N=document.createElement("video");N.src=h;let w=()=>{try{N.currentTime=0,setTimeout(()=>{let f=document.createElement("canvas");f.width=N.videoWidth,f.height=N.videoHeight;let y=f.getContext("2d");if(!y){console.error("Could not get canvas context");return}y.drawImage(N,0,0);let U=f.toDataURL("image/jpeg",.8);v(U);},100);}catch(f){console.error("Error generating thumbnail:",f);}finally{URL.revokeObjectURL(h),N.removeEventListener("canplay",w);}};N.addEventListener("canplay",w),N.load();}},[t,r,d]),react.useEffect(()=>{if(l||g)return;(async()=>{i(true),x(true);try{let{fileId:N}=await Z(t,a,f=>{p(f);}),w=`${a}/${N}`;s(w),i(!1),o&&o(t,w);}catch(N){console.error("Upload failed:",N),i(false);}})();},[t,l,a,g,o]),jsxRuntime.jsxs("div",{className:"lua:relative lua:flex-shrink-0",children:[c?jsxRuntime.jsxs("div",{className:"lua:w-32 lua:h-32 lua:bg-muted lua:rounded-lg lua:flex lua:flex-col lua:items-center lua:justify-center",children:[jsxRuntime.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"}),jsxRuntime.jsxs("div",{className:"lua:mt-2 lua:text-xs lua:text-gray-600 lua:dark:text-gray-300 lua:font-medium",children:[Math.round(m),"%"]})]}):jsxRuntime.jsxs("div",{className:"lua:relative",children:[jsxRuntime.jsx("img",{"data-testid":"video-thumbnail",src:d||n||"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",alt:t.name,className:"lua:w-32 lua:h-32 lua:object-cover lua:rounded-lg lua:bg-muted"}),jsxRuntime.jsx("div",{className:"lua:absolute lua:inset-0 lua:flex lua:items-center lua:justify-center",children:jsxRuntime.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:jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:jsxRuntime.jsx("path",{d:"M5 3L19 12L5 21V3Z",fill:"white"})})})})]}),jsxRuntime.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"]}),jsxRuntime.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-gray-800 lua:dark:bg-gray-700 lua:text-white lua:hover:bg-gray-700 lua:dark:hover:bg-gray-600 lua:transition-colors",children:jsxRuntime.jsx("span",{className:"lua:text-sm",children:"\xD7"})})]})}function jt(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 Ei({files:t,onRemove:e,cdnUrl:a,fileMetadata:l=[],onFileUploadComplete:r}){let[o,u]=react.useState({});return react.useEffect(()=>{t.forEach((c,i)=>{let m=jt(c),p=l.find(n=>n.file===c);if(m.category==="video"&&!o[i]&&!p){let n=URL.createObjectURL(c),s=document.createElement("video");s.src=n;let g=()=>{try{s.currentTime=0,setTimeout(()=>{let x=document.createElement("canvas");x.width=s.videoWidth,x.height=s.videoHeight;let d=x.getContext("2d");if(!d){console.error("Could not get canvas context");return}d.drawImage(s,0,0);let v=x.toDataURL("image/jpeg",.8);u(h=>({...h,[i]:v}));},100);}catch(x){console.error("Error generating thumbnail:",x);}finally{URL.revokeObjectURL(n),s.removeEventListener("canplay",g);}};s.addEventListener("canplay",g),s.load();}});},[t,l]),t.length===0?null:jsxRuntime.jsx("div",{className:"lua:px-4 lua:py-2 lua:border-b lua:border-gray-200 lua:dark:border-gray-700",children:jsxRuntime.jsx("div",{className:"lua:flex lua:gap-2 lua:overflow-x-auto scrollbar-hide",children:t.map((c,i)=>{let m=jt(c),p=l.find(n=>n.file===c);return t.length>1?jsxRuntime.jsx("div",{className:"lua:flex-shrink-0 lua:w-64",children:jsxRuntime.jsx(ct,{file:c,onRemove:()=>e(i),cdnUrl:a,onUploadComplete:(n,s)=>{r&&r(n,s);}})},i):m.category==="image"?jsxRuntime.jsx(dt,{file:c,onRemove:()=>e(i),cdnUrl:a,initialUrl:p?.url,onUploadComplete:(n,s)=>{r&&r(n,s);}},c.name):m.category==="video"?jsxRuntime.jsx(mt,{file:c,onRemove:()=>e(i),cdnUrl:a,initialUrl:p?.url,thumbnailUrl:o[i],onUploadComplete:(n,s)=>{r&&r(n,s);}},c.name):jsxRuntime.jsx("div",{className:"lua:flex-shrink-0 lua:w-64",children:jsxRuntime.jsx(ct,{file:c,onRemove:()=>e(i),cdnUrl:a,onUploadComplete:(n,s)=>{r&&r(n,s);}})},i)})})})}var ee={CHAT:{TOOLBAR_ACTION:{FILE_UPLOAD:"file_upload",CAMERA:"camera",VIDEO:"video",AUDIO:"audio",LOCATION:"location"},MESSAGE_SENT:"message_sent"}};function te(t){console.log("Analytics event:",t);}function Oi({loading:t,onFileClick:e,onCameraClick:a,onVideoClick:l,onAudioClick:r,onLocationClick:o,onSendClick:u}){return jsxRuntime.jsxs("div",{className:"lua:flex lua:items-center lua:justify-between lua:border-t lua:border-border lua:bg-muted/50 lua:dark:bg-muted/50 lua:px-3 lua:py-2",children:[jsxRuntime.jsxs("div",{className:"lua:flex lua:items-center lua:gap-2",children:[jsxRuntime.jsxs(luaniverse.Tooltip,{children:[jsxRuntime.jsx(luaniverse.TooltipTrigger,{asChild:true,children:jsxRuntime.jsx(luaniverse.IconButton,{className:"lua:rounded-lg",variant:"muted",onClick:()=>{te(ee.CHAT.TOOLBAR_ACTION.FILE_UPLOAD),e();},disabled:t,"data-testid":"file-upload-button",children:jsxRuntime.jsx(luaniverse.Paperclip,{className:"lua:text-gray-600 lua:dark:text-gray-300"})})}),jsxRuntime.jsxs(luaniverse.TooltipContent,{children:[jsxRuntime.jsx(luaniverse.TooltipArrow,{}),jsxRuntime.jsx("p",{children:"Attach files"})]})]}),jsxRuntime.jsx("div",{className:"lua:w-px lua:h-5 lua:bg-border"}),jsxRuntime.jsxs(luaniverse.Tooltip,{children:[jsxRuntime.jsx(luaniverse.TooltipTrigger,{asChild:true,children:jsxRuntime.jsx(luaniverse.IconButton,{className:"lua:rounded-lg",variant:"muted",onClick:()=>{te(ee.CHAT.TOOLBAR_ACTION.CAMERA),a();},disabled:t,"data-testid":"camera-button",children:jsxRuntime.jsx(luaniverse.Camera,{className:"lua:text-gray-600 lua:dark:text-gray-300"})})}),jsxRuntime.jsxs(luaniverse.TooltipContent,{children:[jsxRuntime.jsx(luaniverse.TooltipArrow,{}),jsxRuntime.jsx("p",{children:"Take a picture"})]})]}),jsxRuntime.jsxs(luaniverse.Tooltip,{children:[jsxRuntime.jsx(luaniverse.TooltipTrigger,{asChild:true,children:jsxRuntime.jsx(luaniverse.IconButton,{className:"lua:rounded-lg",variant:"muted",onClick:()=>{te(ee.CHAT.TOOLBAR_ACTION.VIDEO),l();},disabled:t,"data-testid":"video-button",children:jsxRuntime.jsx(luaniverse.VideoCamera,{className:"lua:text-gray-600 lua:dark:text-gray-300"})})}),jsxRuntime.jsxs(luaniverse.TooltipContent,{children:[jsxRuntime.jsx(luaniverse.TooltipArrow,{}),jsxRuntime.jsx("p",{children:"Record video"})]})]}),jsxRuntime.jsxs(luaniverse.Tooltip,{children:[jsxRuntime.jsx(luaniverse.TooltipTrigger,{asChild:true,children:jsxRuntime.jsx(luaniverse.IconButton,{className:"lua:rounded-lg",variant:"muted",onClick:()=>{te(ee.CHAT.TOOLBAR_ACTION.AUDIO),r();},disabled:t,"data-testid":"audio-button",children:jsxRuntime.jsx(luaniverse.Microphone,{className:"lua:text-gray-600 lua:dark:text-gray-300"})})}),jsxRuntime.jsxs(luaniverse.TooltipContent,{children:[jsxRuntime.jsx(luaniverse.TooltipArrow,{}),jsxRuntime.jsx("p",{children:"Record voice message"})]})]}),jsxRuntime.jsx("div",{className:"lua:w-px lua:h-5 lua:bg-border"}),jsxRuntime.jsxs(luaniverse.Tooltip,{children:[jsxRuntime.jsx(luaniverse.TooltipTrigger,{asChild:true,children:jsxRuntime.jsx(luaniverse.IconButton,{className:"lua:rounded-lg",variant:"muted",onClick:()=>{te(ee.CHAT.TOOLBAR_ACTION.LOCATION),o();},disabled:t,"data-testid":"location-button",children:jsxRuntime.jsx(luaniverse.MapPin,{className:"lua:text-gray-600 lua:dark:text-gray-300"})})}),jsxRuntime.jsxs(luaniverse.TooltipContent,{children:[jsxRuntime.jsx(luaniverse.TooltipArrow,{}),jsxRuntime.jsx("p",{children:"Share location"})]})]})]}),jsxRuntime.jsx(luaniverse.IconButton,{onClick:()=>{te(ee.CHAT.MESSAGE_SENT),u();},disabled:t,"data-testid":"send-button",variant:"default",children:jsxRuntime.jsx(luaniverse.ArrowUp,{})})]})}
|
|
18
|
+
exports.ActionMessage=Vt;exports.AudioPreview=Lt;exports.AudioRecorder=jl;exports.CameraDialog=pr;exports.CarouselImageDialog=bt;exports.ChatActions=Vn;exports.ChatInput=di;exports.ChatMessage=xn;exports.ChatProvider=Nn;exports.CodeBlock=Nt;exports.FilePreview=Ei;exports.FilePreviewCard=ct;exports.ImageDialog=xt;exports.LoadingMessage=Un;exports.LocationDialog=hr;exports.PaymentPreview=Ee;exports.Toolbar=Oi;exports.VideoDialog=Yl;exports.markdownStyles=T;exports.parseActions=_t;exports.uploadFile=Z;exports.useChat=z;exports.useFileUrls=Tn;exports.useInput=zt;exports.useLoadingMessage=Mn;exports.useMessages=kn;exports.useUnreadMessages=Ln;//# sourceMappingURL=index.js.map
|
|
19
19
|
//# sourceMappingURL=index.js.map
|