lua-ai-chat 0.0.4 → 0.0.5

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 CHANGED
@@ -12,7 +12,7 @@
12
12
  `:v?n+=m+`
13
13
  `:g?p+=m+`
14
14
  `:a+=m+`
15
- `;}return f?e.push({type:"list-item",content:l.trim(),isComplete:false}):o?e.push({type:"payment",content:r.trim(),isComplete:false}):i?e.push({type:"actions",content:s.trim(),isComplete:false}):h?e.push({type:"images",content:d.trim(),isComplete:false}):c?e.push({type:"links",content:u.trim(),isComplete:false}):v?e.push({type:"navigate",content:n.trim(),isComplete:false}):g?e.push({type:"documents",content:p.trim(),isComplete:false}):a.trim()&&e.push({type:"text",content:a.trim()}),e},At=Qa;function Me({images:t}){let[e,a]=react.useState(false),[l,r]=react.useState(0),s=react.useRef(null),[d,u]=react.useState(false),[n,p]=react.useState(0),[f,o]=react.useState(0),[i,h]=react.useState(0),c=react.useCallback(w=>{s.current&&(u(true),p(w.pageX-s.current.offsetLeft),o(s.current.scrollLeft),h(0),w.preventDefault());},[]),v=react.useCallback(w=>{if(!d||!s.current)return;w.preventDefault();let U=w.pageX-s.current.offsetLeft,B=(U-n)*2;s.current.scrollLeft=f-B,h(Math.abs(U-n));},[d,n,f]),g=react.useCallback(()=>{u(false);},[]),C=react.useCallback(()=>{u(false);},[]),x=react.useCallback((w,U)=>{if(i>5){U.preventDefault();return}r(w),a(true);},[i]);return jsxRuntime.jsxs("div",{"data-testid":"image-carousel-message",className:"chat-image-carousel-message lua:w-full",children:[jsxRuntime.jsx("div",{ref:s,className:"chat-image-carousel markdown-image-carousel",style:{cursor:d?"grabbing":"grab"},onMouseDown:c,onMouseMove:v,onMouseUp:g,onMouseLeave:C,onDragStart:w=>{w.preventDefault(),w.stopPropagation();},onDragOver:w=>{w.preventDefault(),w.stopPropagation();},children:t.map((w,U)=>jsxRuntime.jsx("div",{className:"chat-carousel-image-item markdown-image-item",onClick:B=>x(U,B),children:jsxRuntime.jsx("img",{src:w.src,alt:w.alt,draggable:false,style:{userSelect:"none"}})},w.src))}),jsxRuntime.jsx(yt,{images:t,initialIndex:l,open:e,onClose:()=>a(false)})]})}function ze({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:text-gray-800 lua:rounded-2xl lua:px-4 lua:p-3 lua:mt-8",children:t.content}),jsxRuntime.jsx(vt,{url:t.url,alt:t.content,open:e,onClose:()=>a(false)})]}):null}function _e({url:t,luaApiUrl:e,authToken:a,disablePreviewOnLinks:l}){let[r,s]=react.useState(null),[d,u]=react.useState(true),[n,p]=react.useState(null);return react.useEffect(()=>{t&&e&&!l&&(async()=>{try{u(!0),p(null);let o=a;if(!o)throw new Error("No auth token available");let i=await fetch(`${e}/chat/url-metadata?url=${encodeURIComponent(t)}`,{headers:{Authorization:`Bearer ${o}`}});if(!i.ok)throw new Error(`Failed to fetch preview: ${i.status}`);let h=await i.json();s(h);}catch(o){console.error("Error fetching link preview:",o),p(o instanceof Error?o.message:"Failed to load preview");}finally{u(false);}})();},[t,e]),l?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})})}):d?jsxRuntime.jsxs("div",{className:"lua:animate-pulse",children:[jsxRuntime.jsx("div",{className:"lua:bg-gray-300 lua:h-4 lua:w-3/4 lua:mb-2 lua:rounded"}),jsxRuntime.jsx("div",{className:"lua:bg-gray-300 lua:h-3 lua:w-1/2 lua:rounded"})]}):n||!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:rounded-lg lua:p-3 lua:hover:bg-gray-50 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:f=>{f.currentTarget.style.display="none";}}),jsxRuntime.jsx("div",{className:"lua:text-sm lua:font-medium lua:text-gray-900 lua:mb-1 lua:line-clamp-2",children:r.title}),r.description&&jsxRuntime.jsx("div",{className:"lua:text-xs lua:text-gray-600 lua:line-clamp-2",children:r.description}),jsxRuntime.jsx("div",{className:"lua:text-xs lua:text-gray-400 lua:mt-1 lua:truncate",children:new URL(r.url||t).hostname})]})}function Te({links:t,luaApiUrl:e,authToken:a,disablePreviewOnLinks:l}){return 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(_e,{url:r,luaApiUrl:e,authToken:a,disablePreviewOnLinks:l},r))})})}function We({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 Xe({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(We,{location:t})})}function Ge({location:t}){return jsxRuntime.jsx("div",{className:"lua:w-full lua:h-60 lua:rounded-lg","data-testid":"location-preview",children:jsxRuntime.jsx(Xe,{location:t})})}function Ke({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:text-gray-800 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(Ge,{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,{fill:"black"}),jsxRuntime.jsx("div",{className:"lua:flex-1",children:jsxRuntime.jsx("div",{className:"lua:text-sm",children:t.content})})]})]})})}function Qe({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 Ye({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:text-gray-800 lua:rounded-2xl lua:px-4 lua:p-3 lua:mt-8",children:t.content})]})}function cl(t){return new Date(t).toLocaleTimeString()}function dl(t){return {icon:()=>null}}var nn=react.memo(function({message:e,onSelect:a,luaApiUrl:l,authToken:r,disablePreviewOnLinks:s=false,onNavigate:d}){let u=react.useCallback(f=>{let o=f.match(/^#\s+(.+)$/m),i=f.match(/^##\s+(.+)$/m),h=o?o[1]:"",c=i?i[1]:"",v=`${h}. ${c}`;a&&a(v);},[a]),n=react.useCallback(f=>{if(!a)return;let o=Pt(f).trim();a(o);},[a]),p=react.useCallback(()=>{if(e.type==="location")return jsxRuntime.jsx(Ke,{message:e});if(e.mimeType?.startsWith("video"))return e.url?jsxRuntime.jsx(Ye,{message:{url:e.url,content:e.content||"",isUploading:e.isUploading,uploadProgress:e.uploadProgress}}):null;if(e.mimeType?.startsWith("image"))return e.url?jsxRuntime.jsx(ze,{message:{url:e.url,content:e.content||"",isUploading:e.isUploading,uploadProgress:e.uploadProgress}}):null;if(e.mimeType?.startsWith("audio"))return jsxRuntime.jsx(Lt,{message:e});if(e.type==="file"&&e.mimeType){let h=dl(new File([],"",{type:e.mimeType})).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:rounded-lg lua:bg-white lua:w-80",children:[jsxRuntime.jsx(h,{className:"lua:w-12 lua:h-12 lua:text-gray-500"}),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:text-sm",children:e.mimeType})]})]}),e.content&&jsxRuntime.jsx("div",{className:"chat-file-content lua:bg-gray-100 lua:rounded-2xl lua:px-4 lua:py-2 lua:w-80",children:jsxRuntime.jsx("div",{className:"lua:text-sm lua:text-gray-900",children:e.content})})]})})}if(e.role==="user")return e.content;if(e.content==="...")return null;let f=At(e.content),o=be(n);return 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(f.filter(c=>c.type==="list-item").length>1){let c=[],v=[];return f.forEach(g=>{g.type==="list-item"?v.push(g):(v.length>0&&(c.push(v),v=[]),c.push([g]));}),v.length>0&&c.push(v),c.map((g,C)=>g.length>1&&g[0].type==="list-item"?jsxRuntime.jsx(kt,{group:g,onCardClick:u,onListItemClick:n,onNavigate:d},C):g.map((x,N)=>{if(x.type==="list-item")return jsxRuntime.jsx(re,{block:x,onCardClick:u,onListItemClick:n,onNavigate:d},N);if(x.type==="actions")return Se(x.content).length>0&&x.isComplete,null;if(x.type==="images"){let m=Fe(x.content);if(m.length>0)return jsxRuntime.jsx(Me,{images:m},N)}if(x.type==="links"){let m=He(x.content);return m.length>0&&x.isComplete?jsxRuntime.jsx(Te,{links:m,luaApiUrl:l||"",authToken:r||"",disablePreviewOnLinks:s},N):null}if(x.type==="navigate"){let m=Be(x.content);return m&&x.isComplete?jsxRuntime.jsx(Qe,{text:m.text,url:m.url,onNavigate:d},N):null}if(x.type==="documents"){let m=De(x.content);return jsxRuntime.jsx(Ne,{documents:m},N)}if(x.type==="payment"){let m=Oe(x.content);return m?jsxRuntime.jsx("div",{className:"chat-payment-message lua:w-full lua:mx-4 lua:sm:mx-5",children:jsxRuntime.jsx(Ee,{url:m})},N):null}return jsxRuntime.jsx("div",{className:"chat-markdown-block lua:w-full",children:jsxRuntime.jsx(St__default.default,{components:o,children:x.content})},N)}))}return f.map((c,v)=>{if(c.type==="list-item")return jsxRuntime.jsx(re,{block:c,onCardClick:u,onListItemClick:n,onNavigate:d},v);if(c.type==="actions")return Se(c.content).length>0&&c.isComplete,null;if(c.type==="images"){let g=Fe(c.content);if(g.length>0)return jsxRuntime.jsx(Me,{images:g},v)}if(c.type==="navigate"){let g=Be(c.content);return g&&c.isComplete?jsxRuntime.jsx(Qe,{text:g.text,url:g.url,onNavigate:d},v):null}if(c.type==="documents"){let g=De(c.content);return jsxRuntime.jsx(Ne,{documents:g},v)}if(c.type==="links"){let g=He(c.content);return g.length>0&&c.isComplete?jsxRuntime.jsx(Te,{links:g,luaApiUrl:l||"",authToken:r||"",disablePreviewOnLinks:s},v):null}if(c.type==="payment"){let g=Oe(c.content);return g?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:g})},v):null}return jsxRuntime.jsx("div",{className:"chat-markdown-block lua:w-full",children:jsxRuntime.jsx(St__default.default,{components:o,children:c.content})},v)})})()})})},[e,u,n]);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 md:lua:max-w-3/5 lua:bg-gray-100 lua:text-gray-800 lua:rounded-2xl lua:px-4 lua:py-3 lua:mx-4 lua:sm:mx-5 lua:whitespace-pre-wrap":"chat-message-bubble-agent lua:w-full lua:bg-white lua:text-gray-800 lua:rounded-lg lua:py-3 lua:rounded-bl-none"}`,style:{wordBreak:"break-word"},children:p()}),["file","image","video","location"].includes(e.type||"")&&p()]}),jsxRuntime.jsx("div",{className:`lua-message-timestamp lua:text-xs lua:text-gray-400 lua:px-1 ${e.role==="user"?"lua:mr-4 sm:lua:mr-5":"lua:ml-4 sm:lua:ml-5"}`,children:cl(e.createdAt)})]})});var tt=react.createContext(void 0),at=react.createContext(void 0),lt=react.createContext(void 0),rt=react.createContext(void 0),ot=react.createContext(void 0);function mn({children:t}){let[e,a]=react.useState([]),[l,r]=react.useState(""),[s,d]=react.useState(null),[u,n]=react.useState(false),[p]=react.useState(new Map),f=react.useCallback(i=>{if(!p.has(i)){let h=URL.createObjectURL(i);p.set(i,h);}return p.get(i)},[p]),o=react.useCallback(i=>{let h=p.get(i);h&&(URL.revokeObjectURL(h),p.delete(i));},[p]);return react.useEffect(()=>()=>{e.forEach(i=>{i.url&&i.url.startsWith("blob:")&&URL.revokeObjectURL(i.url);}),p.forEach(i=>URL.revokeObjectURL(i));},[e,p]),jsxRuntime.jsx(tt.Provider,{value:{messages:e,setMessages:a},children:jsxRuntime.jsx(at.Provider,{value:{inputMessage:l,setInputMessage:r},children:jsxRuntime.jsx(lt.Provider,{value:{loadingMessage:s,setLoadingMessage:d},children:jsxRuntime.jsx(rt.Provider,{value:{hasUnreadMessages:u,setHasUnreadMessages:n},children:jsxRuntime.jsx(ot.Provider,{value:{getFileUrl:f,removeFileUrl:o},children:t})})})})})}function pn(){let t=react.useContext(tt);if(t===void 0)throw new Error("useMessages must be used within a ChatProvider");return t}function Ht(){let t=react.useContext(at);if(t===void 0)throw new Error("useInput must be used within a ChatProvider");return t}function gn(){let t=react.useContext(lt);if(t===void 0)throw new Error("useLoadingMessage must be used within a ChatProvider");return t}function fn(){let t=react.useContext(ot);if(t===void 0)throw new Error("useFileUrls must be used within a ChatProvider");return t}function hn(){let t=react.useContext(rt);if(t===void 0)throw new Error("useUnreadMessages must be used within a ChatProvider");return t}function $(){let t=react.useContext(tt),e=react.useContext(at),a=react.useContext(lt),l=react.useContext(rt),r=react.useContext(ot);if(t===void 0||e===void 0||a===void 0||l===void 0||r===void 0)throw new Error("useChat must be used within a ChatProvider");return {...t,...e,...a,...l,...r}}function wn(){let{loadingMessage:t}=$();return t?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 Ot({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 f?e.push({type:"list-item",content:l.trim(),isComplete:false}):o?e.push({type:"payment",content:r.trim(),isComplete:false}):i?e.push({type:"actions",content:s.trim(),isComplete:false}):h?e.push({type:"images",content:d.trim(),isComplete:false}):c?e.push({type:"links",content:u.trim(),isComplete:false}):v?e.push({type:"navigate",content:n.trim(),isComplete:false}):g?e.push({type:"documents",content:p.trim(),isComplete:false}):a.trim()&&e.push({type:"text",content:a.trim()}),e},At=Qa;function Me({images:t}){let[e,a]=react.useState(false),[l,r]=react.useState(0),s=react.useRef(null),[d,u]=react.useState(false),[n,p]=react.useState(0),[f,o]=react.useState(0),[i,h]=react.useState(0),c=react.useCallback(w=>{s.current&&(u(true),p(w.pageX-s.current.offsetLeft),o(s.current.scrollLeft),h(0),w.preventDefault());},[]),v=react.useCallback(w=>{if(!d||!s.current)return;w.preventDefault();let U=w.pageX-s.current.offsetLeft,B=(U-n)*2;s.current.scrollLeft=f-B,h(Math.abs(U-n));},[d,n,f]),g=react.useCallback(()=>{u(false);},[]),C=react.useCallback(()=>{u(false);},[]),x=react.useCallback((w,U)=>{if(i>5){U.preventDefault();return}r(w),a(true);},[i]);return jsxRuntime.jsxs("div",{"data-testid":"image-carousel-message",className:"chat-image-carousel-message lua:w-full",children:[jsxRuntime.jsx("div",{ref:s,className:"chat-image-carousel markdown-image-carousel",style:{cursor:d?"grabbing":"grab"},onMouseDown:c,onMouseMove:v,onMouseUp:g,onMouseLeave:C,onDragStart:w=>{w.preventDefault(),w.stopPropagation();},onDragOver:w=>{w.preventDefault(),w.stopPropagation();},children:t.map((w,U)=>jsxRuntime.jsx("div",{className:"chat-carousel-image-item markdown-image-item",onClick:B=>x(U,B),children:jsxRuntime.jsx("img",{src:w.src,alt:w.alt,draggable:false,style:{userSelect:"none"}})},w.src))}),jsxRuntime.jsx(yt,{images:t,initialIndex:l,open:e,onClose:()=>a(false)})]})}function ze({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:text-gray-800 lua:rounded-2xl lua:px-4 lua:p-3 lua:mt-8",children:t.content}),jsxRuntime.jsx(vt,{url:t.url,alt:t.content,open:e,onClose:()=>a(false)})]}):null}function _e({url:t,luaApiUrl:e,authToken:a,disablePreviewOnLinks:l}){let[r,s]=react.useState(null),[d,u]=react.useState(true),[n,p]=react.useState(null);return react.useEffect(()=>{t&&e&&!l&&(async()=>{try{u(!0),p(null);let o=a;if(!o)throw new Error("No auth token available");let i=await fetch(`${e}/chat/url-metadata?url=${encodeURIComponent(t)}`,{headers:{Authorization:`Bearer ${o}`}});if(!i.ok)throw new Error(`Failed to fetch preview: ${i.status}`);let h=await i.json();s(h);}catch(o){console.error("Error fetching link preview:",o),p(o instanceof Error?o.message:"Failed to load preview");}finally{u(false);}})();},[t,e]),l?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})})}):d?jsxRuntime.jsxs("div",{className:"lua:animate-pulse",children:[jsxRuntime.jsx("div",{className:"lua:bg-gray-300 lua:h-4 lua:w-3/4 lua:mb-2 lua:rounded"}),jsxRuntime.jsx("div",{className:"lua:bg-gray-300 lua:h-3 lua:w-1/2 lua:rounded"})]}):n||!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:rounded-lg lua:p-3 lua:hover:bg-gray-50 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:f=>{f.currentTarget.style.display="none";}}),jsxRuntime.jsx("div",{className:"lua:text-sm lua:font-medium lua:text-gray-900 lua:mb-1 lua:line-clamp-2",children:r.title}),r.description&&jsxRuntime.jsx("div",{className:"lua:text-xs lua:text-gray-600 lua:line-clamp-2",children:r.description}),jsxRuntime.jsx("div",{className:"lua:text-xs lua:text-gray-400 lua:mt-1 lua:truncate",children:new URL(r.url||t).hostname})]})}function Te({links:t,luaApiUrl:e,authToken:a,disablePreviewOnLinks:l}){return 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(_e,{url:r,luaApiUrl:e,authToken:a,disablePreviewOnLinks:l},r))})})}function We({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 Xe({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(We,{location:t})})}function Ge({location:t}){return jsxRuntime.jsx("div",{className:"lua:w-full lua:h-60 lua:rounded-lg","data-testid":"location-preview",children:jsxRuntime.jsx(Xe,{location:t})})}function Ke({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:text-gray-800 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(Ge,{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,{fill:"black"}),jsxRuntime.jsx("div",{className:"lua:flex-1",children:jsxRuntime.jsx("div",{className:"lua:text-sm",children:t.content})})]})]})})}function Qe({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 Ye({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:text-gray-800 lua:rounded-2xl lua:px-4 lua:p-3 lua:mt-8",children:t.content})]})}function cl(t){return new Date(t).toLocaleTimeString()}function dl(t){return {icon:()=>null}}var nn=react.memo(function({message:e,onSelect:a,luaApiUrl:l,authToken:r,disablePreviewOnLinks:s=false,onNavigate:d}){let u=react.useCallback(f=>{let o=f.match(/^#\s+(.+)$/m),i=f.match(/^##\s+(.+)$/m),h=o?o[1]:"",c=i?i[1]:"",v=`${h}. ${c}`;a&&a(v);},[a]),n=react.useCallback(f=>{if(!a)return;let o=Pt(f).trim();a(o);},[a]),p=react.useCallback(()=>{if(e.type==="location")return jsxRuntime.jsx(Ke,{message:e});if(e.mimeType?.startsWith("video"))return e.url?jsxRuntime.jsx(Ye,{message:{url:e.url,content:e.content||"",isUploading:e.isUploading,uploadProgress:e.uploadProgress}}):null;if(e.mimeType?.startsWith("image"))return e.url?jsxRuntime.jsx(ze,{message:{url:e.url,content:e.content||"",isUploading:e.isUploading,uploadProgress:e.uploadProgress}}):null;if(e.mimeType?.startsWith("audio"))return jsxRuntime.jsx(Lt,{message:e});if(e.type==="file"&&e.mimeType){let h=dl(new File([],"",{type:e.mimeType})).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:rounded-lg lua:bg-white lua:w-80",children:[jsxRuntime.jsx(h,{className:"lua:w-12 lua:h-12 lua:text-gray-500"}),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:text-sm",children:e.mimeType})]})]}),e.content&&jsxRuntime.jsx("div",{className:"chat-file-content lua:bg-gray-100 lua:rounded-2xl lua:px-4 lua:py-2 lua:w-80",children:jsxRuntime.jsx("div",{className:"lua:text-sm lua:text-gray-900",children:e.content})})]})})}if(e.role==="user")return e.content;if(e.content==="...")return null;let f=At(e.content),o=be(n);return 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(f.filter(c=>c.type==="list-item").length>1){let c=[],v=[];return f.forEach(g=>{g.type==="list-item"?v.push(g):(v.length>0&&(c.push(v),v=[]),c.push([g]));}),v.length>0&&c.push(v),c.map((g,C)=>g.length>1&&g[0].type==="list-item"?jsxRuntime.jsx(kt,{group:g,onCardClick:u,onListItemClick:n,onNavigate:d},C):g.map((x,N)=>{if(x.type==="list-item")return jsxRuntime.jsx(re,{block:x,onCardClick:u,onListItemClick:n,onNavigate:d},N);if(x.type==="actions")return Se(x.content).length>0&&x.isComplete,null;if(x.type==="images"){let m=Fe(x.content);if(m.length>0)return jsxRuntime.jsx(Me,{images:m},N)}if(x.type==="links"){let m=He(x.content);return m.length>0&&x.isComplete?jsxRuntime.jsx(Te,{links:m,luaApiUrl:l||"",authToken:r||"",disablePreviewOnLinks:s},N):null}if(x.type==="navigate"){let m=Be(x.content);return m&&x.isComplete?jsxRuntime.jsx(Qe,{text:m.text,url:m.url,onNavigate:d},N):null}if(x.type==="documents"){let m=De(x.content);return jsxRuntime.jsx(Ne,{documents:m},N)}if(x.type==="payment"){let m=Oe(x.content);return m?jsxRuntime.jsx("div",{className:"chat-payment-message lua:w-full lua:mx-4 lua:sm:mx-5",children:jsxRuntime.jsx(Ee,{url:m})},N):null}return jsxRuntime.jsx("div",{className:"chat-markdown-block lua:w-full",children:jsxRuntime.jsx(St__default.default,{components:o,children:x.content})},N)}))}return f.map((c,v)=>{if(c.type==="list-item")return jsxRuntime.jsx(re,{block:c,onCardClick:u,onListItemClick:n,onNavigate:d},v);if(c.type==="actions")return Se(c.content).length>0&&c.isComplete,null;if(c.type==="images"){let g=Fe(c.content);if(g.length>0)return jsxRuntime.jsx(Me,{images:g},v)}if(c.type==="navigate"){let g=Be(c.content);return g&&c.isComplete?jsxRuntime.jsx(Qe,{text:g.text,url:g.url,onNavigate:d},v):null}if(c.type==="documents"){let g=De(c.content);return jsxRuntime.jsx(Ne,{documents:g},v)}if(c.type==="links"){let g=He(c.content);return g.length>0&&c.isComplete?jsxRuntime.jsx(Te,{links:g,luaApiUrl:l||"",authToken:r||"",disablePreviewOnLinks:s},v):null}if(c.type==="payment"){let g=Oe(c.content);return g?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:g})},v):null}return jsxRuntime.jsx("div",{className:"chat-markdown-block lua:w-full",children:jsxRuntime.jsx(St__default.default,{components:o,children:c.content})},v)})})()})})},[e,u,n]);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 md:lua:max-w-3/5 lua:bg-gray-100 lua:text-gray-800 lua:rounded-2xl lua:px-4 lua:py-3 lua:mx-4 lua:sm:mx-5 lua:whitespace-pre-wrap":"chat-message-bubble-agent lua:w-full lua:bg-white lua:text-gray-800 lua:rounded-lg lua:py-3 lua:rounded-bl-none"}`,style:{wordBreak:"break-word"},children:p()}),["file","image","video","location"].includes(e.type||"")&&p()]}),jsxRuntime.jsx("div",{className:`lua-message-timestamp lua:text-xs lua:text-gray-400 lua:px-1 ${e.role==="user"?"lua:mr-4 sm:lua:mr-5":"lua:ml-4 sm:lua:ml-5"}`,children:cl(e.createdAt)})]})});var tt=react.createContext(void 0),at=react.createContext(void 0),lt=react.createContext(void 0),rt=react.createContext(void 0),ot=react.createContext(void 0);function mn({children:t}){let[e,a]=react.useState([]),[l,r]=react.useState(""),[s,d]=react.useState(null),[u,n]=react.useState(false),[p]=react.useState(new Map),f=react.useCallback(i=>{if(!p.has(i)){let h=URL.createObjectURL(i);p.set(i,h);}return p.get(i)},[p]),o=react.useCallback(i=>{let h=p.get(i);h&&(URL.revokeObjectURL(h),p.delete(i));},[p]);return react.useEffect(()=>()=>{e.forEach(i=>{i.url&&i.url.startsWith("blob:")&&URL.revokeObjectURL(i.url);}),p.forEach(i=>URL.revokeObjectURL(i));},[e,p]),jsxRuntime.jsx(tt.Provider,{value:{messages:e,setMessages:a},children:jsxRuntime.jsx(at.Provider,{value:{inputMessage:l,setInputMessage:r},children:jsxRuntime.jsx(lt.Provider,{value:{loadingMessage:s,setLoadingMessage:d},children:jsxRuntime.jsx(rt.Provider,{value:{hasUnreadMessages:u,setHasUnreadMessages:n},children:jsxRuntime.jsx(ot.Provider,{value:{getFileUrl:f,removeFileUrl:o},children:t})})})})})}function pn(){let t=react.useContext(tt);if(t===void 0)throw new Error("useMessages must be used within a ChatProvider");return t}function Ht(){let t=react.useContext(at);if(t===void 0)throw new Error("useInput must be used within a ChatProvider");return t}function gn(){let t=react.useContext(lt);if(t===void 0)throw new Error("useLoadingMessage must be used within a ChatProvider");return t}function fn(){let t=react.useContext(ot);if(t===void 0)throw new Error("useFileUrls must be used within a ChatProvider");return t}function hn(){let t=react.useContext(rt);if(t===void 0)throw new Error("useUnreadMessages must be used within a ChatProvider");return t}function $(){let t=react.useContext(tt),e=react.useContext(at),a=react.useContext(lt),l=react.useContext(rt),r=react.useContext(ot);if(t===void 0||e===void 0||a===void 0||l===void 0||r===void 0)throw new Error("useChat must be used within a ChatProvider");return {...t,...e,...a,...l,...r}}function wn(){let{loadingMessage:t}=$();return t?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 Ot({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",a=":::",l=t.indexOf(e);if(l===-1)return [];let r=t.indexOf(a,l+e.length);return r===-1?[]:t.slice(l+e.length,r).trim().replace(/\\n/g,`
16
16
  `).split(`
17
17
  `).map(f=>f.trim()).filter(f=>f&&f.startsWith("-")).map(f=>({text:f.replace(/^-[\s]?/,"").trim(),onClick:f.replace(/^-[\s]?/,"").trim()}))};function In({onSelect:t}){let{messages:e}=$();if(e.length===0)return null;let a=e[e.length-1],l=$t(a.content);return l.length===0?null:jsxRuntime.jsx(Ot,{buttons:l,onClick:t})}var ei=react.memo(function({onSend:e,disabled:a=false,onFilePaste:l}){let{inputMessage:r,setInputMessage:s}=Ht(),[d,u]=react.useState(false),n=react.useRef(null);react.useEffect(()=>{let o=()=>{u(window.matchMedia("(max-width: 768px)").matches||/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));};return o(),window.addEventListener("resize",o),()=>{window.removeEventListener("resize",o);}},[]),react.useEffect(()=>{let o=n.current;o&&(a||(o.style.height="auto",o.style.height=`${o.scrollHeight}px`));},[r]);let p=o=>{if(o.key==="Enter"){if(d||o.shiftKey||o.metaKey||o.ctrlKey)return;o.preventDefault(),e();}},f=react.useCallback(o=>{let{items:i}=o.clipboardData;if(!i||!l)return;let h=[];for(let c=0;c<i.length;c++){let v=i[c];if(v.kind==="file"){let g=v.getAsFile();g&&h.push(g);}}h.length>0&&(o.preventDefault(),l(h));},[l]);return 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:n,disabled:a,value:r,onChange:o=>s(o.target.value),onKeyDown:p,onPaste:f,placeholder:a?"This conversation's chat window has already been closed":"Reply to user",className:`lua:w-full lua:pl-0 lua:pr-4 lua:py-2 lua:resize-none lua:overflow-y-auto lua:border-none lua:focus:outline-none lua:focus:ring-0 lua:text-gray-700 lua:min-h-10 lua:max-h-48 lua:bg-white${a?" lua:cursor-not-allowed lua:h-14":""}`,rows:1})})]})});function Nl(){return localStorage.getItem("authToken")}async function Q(t,e,a){let l=Nl();if(!l)throw new Error("No auth token found");return new Promise((r,s)=>{let d=new XMLHttpRequest,u=new FormData;u.append("file",t),d.upload.addEventListener("progress",n=>{if(n.lengthComputable&&a){let p=n.loaded/n.total*100;a(p);}}),d.addEventListener("load",()=>{if(d.status>=200&&d.status<300)try{let n=JSON.parse(d.responseText);r(n);}catch{s(new Error("Failed to parse response"));}else s(new Error(`Failed to upload file: ${d.status}`));}),d.addEventListener("error",()=>{s(new Error("Network error occurred"));}),d.open("POST",`${e}/upload`),d.setRequestHeader("Authorization",`Bearer ${l}`),d.send(u);})}function Tl(t){let e=t.type,a="File";return e.startsWith("image/")?a="Image":e.startsWith("video/")?a="Video":e.startsWith("audio/")&&(a="Audio"),{icon:()=>null,label:a}}function ut({file:t,onRemove:e,cdnUrl:a,initialUrl:l,onUploadComplete:r}){let s=Tl(t),d=s.icon,[u,n]=react.useState(false),[p,f]=react.useState(0),[o,i]=react.useState(l||null),h=react.useRef(false);return react.useEffect(()=>{if(o||h.current)return;(async()=>{n(true),h.current=true;try{let{fileId:v}=await Q(t,a,C=>{f(C);}),g=`${a}/${v}`;i(g),n(!1),r&&r(t,g);}catch(v){console.error("Upload failed for file:",t.name,v),n(false),h.current=false;}})();},[t,a,r,o]),jsxRuntime.jsxs("div",{className:"lua:flex lua:items-center lua:gap-4 lua:p-3 lua:bg-white lua:border lua:border-gray-200 lua:rounded-lg",children:[jsxRuntime.jsx("div",{className:"lua:flex-shrink-0",children:u?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:font-medium",children:[Math.round(p),"%"]})]}):jsxRuntime.jsx(d,{className:"lua:w-8 lua:h-8 lua:text-gray-600"})}),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:truncate",children:t.name}),jsxRuntime.jsx("p",{className:"lua:text-xs lua:text-gray-500",children:s.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-black lua:text-white lua:hover:bg-gray-800 lua:transition-colors",children:jsxRuntime.jsx(luaniverse.XIcon,{className:"lua:w-4 lua:h-4"})})]})}function ct({file:t,onRemove:e,cdnUrl:a,initialUrl:l,onUploadComplete:r}){let{getFileUrl:s}=$(),[d,u]=react.useState(false),[n,p]=react.useState(0),[f,o]=react.useState(l||null),[i,h]=react.useState(false);react.useEffect(()=>{if(l||i)return;(async()=>{u(true),h(true);try{let{fileId:g}=await Q(t,a,x=>{p(x);}),C=`${a}/${g}`;o(C),u(!1),r&&r(t,C);}catch(g){console.error("Upload failed:",g),u(false);}})();},[t,l,a,i,r]);let c=f||(d?void 0:s(t));return jsxRuntime.jsxs("div",{className:"lua:relative lua:flex-shrink-0",children:[d?jsxRuntime.jsxs("div",{className:"lua:w-32 lua:h-32 lua:bg-gray-100 lua:rounded-lg lua:flex lua:flex-col lua:items-center lua:justify-center",children:[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:font-medium",children:[Math.round(n),"%"]})]}):c?jsxRuntime.jsx("img",{"data-testid":"image-thumbnail",src:c,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:rounded-lg lua:flex lua:items-center lua:justify-center",children:jsxRuntime.jsx("span",{className:"lua:text-gray-500",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-black lua:text-white lua:hover:bg-gray-800 lua:transition-colors",children:jsxRuntime.jsx("span",{className:"lua:text-sm",children:"\xD7"})})]})}function dt({file:t,onRemove:e,cdnUrl:a,initialUrl:l,thumbnailUrl:r,onUploadComplete:s}){let{getFileUrl:d}=$(),[u,n]=react.useState(false),[p,f]=react.useState(0),[o,i]=react.useState(l||null),[h,c]=react.useState(false),[v,g]=react.useState(r||null);return react.useEffect(()=>{if(!r&&!v){let C=d(t),x=document.createElement("video");x.src=C;let N=()=>{try{x.currentTime=0,setTimeout(()=>{let m=document.createElement("canvas");m.width=x.videoWidth,m.height=x.videoHeight;let w=m.getContext("2d");if(!w){console.error("Could not get canvas context");return}w.drawImage(x,0,0);let U=m.toDataURL("image/jpeg",.8);g(U);},100);}catch(m){console.error("Error generating thumbnail:",m);}finally{URL.revokeObjectURL(C),x.removeEventListener("canplay",N);}};x.addEventListener("canplay",N),x.load();}},[t,r,v]),react.useEffect(()=>{if(l||h)return;(async()=>{n(true),c(true);try{let{fileId:x}=await Q(t,a,m=>{f(m);}),N=`${a}/${x}`;i(N),n(!1),s&&s(t,N);}catch(x){console.error("Upload failed:",x),n(false);}})();},[t,l,a,h,s]),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: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:font-medium",children:[Math.round(p),"%"]})]}):jsxRuntime.jsxs("div",{className:"lua:relative",children:[jsxRuntime.jsx("img",{"data-testid":"video-thumbnail",src:v||o||"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",alt:t.name,className:"lua:w-32 lua:h-32 lua:object-cover lua:rounded-lg lua:bg-gray-100"}),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-black lua:text-white lua:hover:bg-gray-800 lua:transition-colors",children:jsxRuntime.jsx("span",{className:"lua:text-sm",children:"\xD7"})})]})}function qt(t){let e=t.type,a="other",l="File";return e.startsWith("image/")?(a="image",l="Image"):e.startsWith("video/")?(a="video",l="Video"):e.startsWith("audio/")&&(a="audio",l="Audio"),{category:a,icon:()=>null,label:l}}function Ni({files:t,onRemove:e,cdnUrl:a,fileMetadata:l=[],onFileUploadComplete:r}){let[s,d]=react.useState({});return react.useEffect(()=>{t.forEach((u,n)=>{let p=qt(u),f=l.find(o=>o.file===u);if(p.category==="video"&&!s[n]&&!f){let o=URL.createObjectURL(u),i=document.createElement("video");i.src=o;let h=()=>{try{i.currentTime=0,setTimeout(()=>{let c=document.createElement("canvas");c.width=i.videoWidth,c.height=i.videoHeight;let v=c.getContext("2d");if(!v){console.error("Could not get canvas context");return}v.drawImage(i,0,0);let g=c.toDataURL("image/jpeg",.8);d(C=>({...C,[n]:g}));},100);}catch(c){console.error("Error generating thumbnail:",c);}finally{URL.revokeObjectURL(o),i.removeEventListener("canplay",h);}};i.addEventListener("canplay",h),i.load();}});},[t,l]),t.length===0?null: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((u,n)=>{let p=qt(u),f=l.find(o=>o.file===u);return t.length>1?jsxRuntime.jsx("div",{className:"lua:flex-shrink-0 lua:w-64",children:jsxRuntime.jsx(ut,{file:u,onRemove:()=>e(n),cdnUrl:a,onUploadComplete:(o,i)=>{r&&r(o,i);}})},n):p.category==="image"?jsxRuntime.jsx(ct,{file:u,onRemove:()=>e(n),cdnUrl:a,initialUrl:f?.url,onUploadComplete:(o,i)=>{r&&r(o,i);}},u.name):p.category==="video"?jsxRuntime.jsx(dt,{file:u,onRemove:()=>e(n),cdnUrl:a,initialUrl:f?.url,thumbnailUrl:s[n],onUploadComplete:(o,i)=>{r&&r(o,i);}},u.name):jsxRuntime.jsx("div",{className:"lua:flex-shrink-0 lua:w-64",children:jsxRuntime.jsx(ut,{file:u,onRemove:()=>e(n),cdnUrl:a,onUploadComplete:(o,i)=>{r&&r(o,i);}})},n)})})})}var Y={CHAT:{TOOLBAR_ACTION:{FILE_UPLOAD:"file_upload",CAMERA:"camera",VIDEO:"video",AUDIO:"audio",LOCATION:"location"},MESSAGE_SENT:"message_sent"}};function ee(t){console.log("Analytics event:",t);}function Ti({loading:t,onFileClick:e,onCameraClick:a,onVideoClick:l,onAudioClick:r,onLocationClick:s,onSendClick:d}){return jsxRuntime.jsxs("div",{className:"lua:flex lua:items-center lua:justify-between lua:border-t lua:border-gray-200 lua:bg-gray-50 lua:px-3 lua:py-2",children:[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:()=>{ee(Y.CHAT.TOOLBAR_ACTION.FILE_UPLOAD),e();},disabled:t,"data-testid":"file-upload-button",children:jsxRuntime.jsx(luaniverse.Paperclip,{color:"#00000099"})})}),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"}),jsxRuntime.jsxs(luaniverse.Tooltip,{children:[jsxRuntime.jsx(luaniverse.TooltipTrigger,{asChild:true,children:jsxRuntime.jsx(luaniverse.IconButton,{className:"lua:rounded-lg",variant:"muted",onClick:()=>{ee(Y.CHAT.TOOLBAR_ACTION.CAMERA),a();},disabled:t,"data-testid":"camera-button",children:jsxRuntime.jsx(luaniverse.Camera,{color:"#00000099"})})}),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:()=>{ee(Y.CHAT.TOOLBAR_ACTION.VIDEO),l();},disabled:t,"data-testid":"video-button",children:jsxRuntime.jsx(luaniverse.VideoCamera,{color:"#00000099"})})}),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:()=>{ee(Y.CHAT.TOOLBAR_ACTION.AUDIO),r();},disabled:t,"data-testid":"audio-button",children:jsxRuntime.jsx(luaniverse.Microphone,{color:"#00000099"})})}),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"}),jsxRuntime.jsxs(luaniverse.Tooltip,{children:[jsxRuntime.jsx(luaniverse.TooltipTrigger,{asChild:true,children:jsxRuntime.jsx(luaniverse.IconButton,{className:"lua:rounded-lg",variant:"muted",onClick:()=>{ee(Y.CHAT.TOOLBAR_ACTION.LOCATION),s();},disabled:t,"data-testid":"location-button",children:jsxRuntime.jsx(luaniverse.MapPin,{color:"#00000099"})})}),jsxRuntime.jsxs(luaniverse.TooltipContent,{children:[jsxRuntime.jsx(luaniverse.TooltipArrow,{}),jsxRuntime.jsx("p",{children:"Share location"})]})]})]}),jsxRuntime.jsx(luaniverse.IconButton,{className:"lua:rounded-full",onClick:()=>{ee(Y.CHAT.MESSAGE_SENT),d();},disabled:t,"data-testid":"send-button",children:jsxRuntime.jsx(luaniverse.ArrowUp,{color:"#FFFFFF"})})]})}
18
18
  exports.ActionMessage=Ot;exports.AudioPreview=Lt;exports.AudioRecorder=$l;exports.CameraDialog=ir;exports.CarouselImageDialog=yt;exports.ChatActions=In;exports.ChatInput=ei;exports.ChatMessage=nn;exports.ChatProvider=mn;exports.CodeBlock=Ct;exports.FilePreview=Ni;exports.FilePreviewCard=ut;exports.ImageDialog=vt;exports.LoadingMessage=wn;exports.LocationDialog=cr;exports.PaymentPreview=Ee;exports.Toolbar=Ti;exports.VideoDialog=Xl;exports.markdownStyles=L;exports.parseActions=$t;exports.uploadFile=Q;exports.useChat=$;exports.useFileUrls=fn;exports.useInput=Ht;exports.useLoadingMessage=gn;exports.useMessages=pn;exports.useUnreadMessages=hn;//# sourceMappingURL=index.js.map