research-agent-ui 0.1.155 → 0.1.157

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.
@@ -17,7 +17,7 @@ const e=require("./rolldown-runtime-BocRIvOZ.cjs"),t=require("./config.cjs");let
17
17
  `)}`}`;navigator.clipboard.writeText(n),i(!0),setTimeout(()=>i(!1),1e3)},className:`p-2 text-muted-foreground rounded-full backdrop-blur-md bg-white/10 dark:bg-black/10 hover:bg-white/20 dark:hover:bg-black/20 transition duration-200 hover:text-foreground`,children:r?(0,d.jsx)(s.Check,{size:18}):(0,d.jsx)(s.ClipboardList,{size:18})})}),(0,d.jsx)(J,{side:`bottom`,children:r?`Copied!`:`Copy`})]})};function St({...e}){return(0,d.jsx)(_.Root,{"data-slot":`popover`,...e})}function Ct({...e}){return(0,d.jsx)(_.Trigger,{"data-slot":`popover-trigger`,...e})}function wt({className:e,align:t=`center`,sideOffset:n=4,container:r,...i}){return(0,d.jsx)(_.Portal,{container:r,children:(0,d.jsx)(_.Content,{"data-slot":`popover-content`,align:t,sideOffset:n,className:F(`bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-2xl border p-4 shadow-md outline-hidden`,e),...i})})}var Z={Plus:s.Plus,Paperclip:s.Paperclip,Cloud:s.Cloud,Upload:s.Upload,File:s.File,SquarePen:s.SquarePen,Thinking:e=>(0,d.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 20 20`,fill:`currentColor`,xmlns:`http://www.w3.org/2000/svg`,...e,children:(0,d.jsx)(`path`,{d:`M10.3857 2.50977C14.3486 2.71054 17.5 5.98724 17.5 10C17.5 14.1421 14.1421 17.5 10 17.5C5.85786 17.5 2.5 14.1421 2.5 10C2.5 9.72386 2.72386 9.5 3 9.5C3.27614 9.5 3.5 9.72386 3.5 10C3.5 13.5899 6.41015 16.5 10 16.5C13.5899 16.5 16.5 13.5899 16.5 10C16.5 6.5225 13.7691 3.68312 10.335 3.50879L10 3.5L9.89941 3.49023C9.67145 3.44371 9.5 3.24171 9.5 3C9.5 2.72386 9.72386 2.5 10 2.5L10.3857 2.50977ZM10 5.5C10.2761 5.5 10.5 5.72386 10.5 6V9.69043L13.2236 11.0527C13.4706 11.1762 13.5708 11.4766 13.4473 11.7236C13.3392 11.9397 13.0957 12.0435 12.8711 11.9834L12.7764 11.9473L9.77637 10.4473C9.60698 10.3626 9.5 10.1894 9.5 10V6C9.5 5.72386 9.72386 5.5 10 5.5ZM3.66211 6.94141C4.0273 6.94159 4.32303 7.23735 4.32324 7.60254C4.32324 7.96791 4.02743 8.26446 3.66211 8.26465C3.29663 8.26465 3 7.96802 3 7.60254C3.00021 7.23723 3.29676 6.94141 3.66211 6.94141ZM4.95605 4.29395C5.32146 4.29404 5.61719 4.59063 5.61719 4.95605C5.6171 5.3214 5.3214 5.61709 4.95605 5.61719C4.59063 5.61719 4.29403 5.32146 4.29395 4.95605C4.29395 4.59057 4.59057 4.29395 4.95605 4.29395ZM7.60254 3C7.96802 3 8.26465 3.29663 8.26465 3.66211C8.26446 4.02743 7.96791 4.32324 7.60254 4.32324C7.23736 4.32302 6.94159 4.0273 6.94141 3.66211C6.94141 3.29676 7.23724 3.00022 7.60254 3Z`})}),SelectArrow:s.ChevronDown,ArrowUp:s.ArrowUp,X:s.X,FileText:s.FileText,Loader2:s.Loader2,Check:s.Check,Archive:s.Archive,Mic:s.Mic,Stop:s.Square,Clock:e=>(0,d.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`20`,height:`20`,viewBox:`0 0 20 20`,fill:`currentColor`,...e,children:(0,d.jsx)(`path`,{d:`M10.3857 2.50977C14.3486 2.71054 17.5 5.98724 17.5 10C17.5 14.1421 14.1421 17.5 10 17.5C5.85786 17.5 2.5 14.1421 2.5 10C2.5 9.72386 2.72386 9.5 3 9.5C3.27614 9.5 3.5 9.72386 3.5 10C3.5 13.5899 6.41015 16.5 10 16.5C13.5899 16.5 16.5 13.5899 16.5 10C16.5 6.5225 13.7691 3.68312 10.335 3.50879L10 3.5L9.89941 3.49023C9.67145 3.44371 9.5 3.24171 9.5 3C9.5 2.72386 9.72386 2.5 10 2.5L10.3857 2.50977ZM10 5.5C10.2761 5.5 10.5 5.72386 10.5 6V9.69043L13.2236 11.0527C13.4706 11.1762 13.5708 11.4766 13.4473 11.7236C13.3392 11.9397 13.0957 12.0435 12.8711 11.9834L12.7764 11.9473L9.77637 10.4473C9.60698 10.3626 9.5 10.1894 9.5 10V6C9.5 5.72386 9.72386 5.5 10 5.5ZM3.66211 6.94141C4.0273 6.94159 4.32303 7.23735 4.32324 7.60254C4.32324 7.96791 4.02743 8.26446 3.66211 8.26465C3.29663 8.26465 3 7.96802 3 7.60254C3.00021 7.23723 3.29676 6.94141 3.66211 6.94141ZM4.95605 4.29395C5.32146 4.29404 5.61719 4.59063 5.61719 4.95605C5.6171 5.3214 5.3214 5.61709 4.95605 5.61719C4.59063 5.61719 4.29403 5.32146 4.29395 4.95605C4.29395 4.59057 4.59057 4.29395 4.95605 4.29395ZM7.60254 3C7.96802 3 8.26465 3.29663 8.26465 3.66211C8.26446 4.02743 7.96791 4.32324 7.60254 4.32324C7.23736 4.32302 6.94159 4.0273 6.94141 3.66211C6.94141 3.29676 7.23724 3.00022 7.60254 3Z`})})},Tt=({messageId:e})=>{let{rewrite:t,chatModelProvider:r,setChatModelProvider:i}=G(),[a,o]=(0,n.useState)([]),[l,u]=(0,n.useState)(!0),[f,p]=(0,n.useState)(``),[m,h]=(0,n.useState)(!1);(0,n.useEffect)(()=>{m&&(async()=>{try{u(!0);let{data:e}=await(0,c.listProviders)();o(e?.providers??[])}catch(e){console.error(`Error loading providers:`,e)}finally{u(!1)}})()},[m]);let g=(0,n.useMemo)(()=>{if(!r?.providerId)return a;let e=a.findIndex(e=>e.id===r.providerId);return e===-1?a:[a[e],...a.filter((t,n)=>n!==e)]},[a,r]).map(e=>({...e,chatModels:(e.chatModels??[]).filter(t=>t.name.toLowerCase().includes(f.toLowerCase())||e.name.toLowerCase().includes(f.toLowerCase()))})).filter(e=>e.chatModels.length>0),_=(0,n.useMemo)(()=>{if(!r.key)return`Rewrite`;for(let e of a){let t=e.chatModels.find(e=>e.key===r.key);if(t)return t.name}return r.key},[a,r.key]),v=(n,r)=>{i({providerId:n,key:r}),localStorage.setItem(`chatModelProviderId`,n),localStorage.setItem(`chatModelKey`,r),h(!1),t(e)};return(0,d.jsxs)(St,{open:m,onOpenChange:h,children:[(0,d.jsxs)(K,{children:[(0,d.jsx)(q,{asChild:!0,children:(0,d.jsx)(Ct,{asChild:!0,children:(0,d.jsx)(`button`,{className:`p-2 text-muted-foreground rounded-full backdrop-blur-md bg-white/10 dark:bg-black/10 hover:bg-white/20 dark:hover:bg-black/20 transition duration-200 hover:text-foreground`,children:(0,d.jsx)(s.ArrowLeftRight,{size:18})})})}),(0,d.jsxs)(J,{side:`bottom`,children:[`Rewrite with `,_]})]}),(0,d.jsx)(wt,{className:`w-[280px] p-0`,align:`start`,side:`top`,sideOffset:8,children:(0,d.jsxs)(`div`,{className:`bg-white dark:bg-[#212121] max-h-[400px] border rounded-2xl border-[#DDDDDD] dark:border-[#30302E] w-full flex flex-col shadow-2xl overflow-hidden`,children:[(0,d.jsx)(`div`,{className:`p-3 border-b border-[#EEEEEE] dark:border-[#30302E]`,children:(0,d.jsxs)(`div`,{className:`relative`,children:[(0,d.jsx)(s.Search,{size:14,className:`absolute left-3 top-1/2 -translate-y-1/2 text-text-400 dark:text-[#999999]`}),(0,d.jsx)(`input`,{type:`text`,placeholder:`Search models...`,value:f,onChange:e=>p(e.target.value),className:`w-full pl-9 pr-3 py-2 text-[13px] bg-bg-100 dark:bg-[#30302E] border border-bg-300 dark:border-[#404040] rounded-lg text-text-100 dark:text-[#ECECEC] placeholder:text-text-400 dark:placeholder:text-[#999999] focus:outline-none focus:ring-2 focus:ring-sky-500/20 focus:border-sky-500/30 transition-all`})]})}),(0,d.jsx)(`div`,{className:`max-h-[320px] overflow-y-auto`,children:l?(0,d.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,d.jsx)(Z.Loader2,{className:`animate-spin text-text-400 dark:text-[#999999]`,size:20})}):g.length===0?(0,d.jsx)(`div`,{className:`text-center py-12 px-4 text-text-400 dark:text-[#999999] text-sm`,children:f?`No models found`:`No chat models configured`}):(0,d.jsx)(`div`,{className:`flex flex-col`,children:g.map((e,t)=>(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`px-4 py-2 sticky top-0 bg-white dark:bg-[#212121] border-b border-[#EEEEEE]/50 dark:border-[#30302E]/50`,children:(0,d.jsx)(`p`,{className:`text-[11px] text-text-400 dark:text-[#999999] uppercase tracking-wider font-medium`,children:e.name})}),(0,d.jsx)(`div`,{className:`flex flex-col px-1.5 py-1.5 space-y-0.5`,children:e.chatModels.map(t=>(0,d.jsxs)(`button`,{onClick:()=>v(e.id,t.key),type:`button`,className:F(`px-3 py-2 flex items-center justify-between text-start duration-200 cursor-pointer transition rounded-xl group`,r?.providerId===e.id&&r?.key===t.key?`bg-sky-50 dark:bg-sky-500/10`:`hover:bg-bg-100 dark:hover:bg-[#30302E]`),children:[(0,d.jsxs)(`div`,{className:`flex items-center space-x-2.5 min-w-0 flex-1`,children:[(0,d.jsx)(s.Cpu,{size:14,className:F(`shrink-0`,r?.providerId===e.id&&r?.key===t.key?`text-sky-500`:`text-text-400 dark:text-[#999999] group-hover:text-text-300 dark:group-hover:text-[#B4B4B4]`)}),(0,d.jsx)(`p`,{className:F(`text-[13px] truncate`,r?.providerId===e.id&&r?.key===t.key?`text-sky-600 dark:text-sky-400 font-medium`:`text-text-200 dark:text-[#ECECEC] group-hover:text-text-100 dark:group-hover:text-white`),children:t.name})]}),r?.providerId===e.id&&r?.key===t.key&&(0,d.jsx)(Z.Check,{className:`w-4 h-4 text-sky-500 shrink-0`})]},t.key))}),t<g.length-1&&(0,d.jsx)(`div`,{className:`h-px bg-[#EEEEEE] dark:bg-[#30302E] mx-2`})]},e.id))})})]})})]})},Et=new Map;function Dt(e){if(typeof window>`u`)return Promise.reject(Error(`CDN scripts require a browser environment`));let t=Et.get(e);if(t)return t;let n=new Promise((t,n)=>{let r=document.querySelector(`script[data-cdn-loader="${e}"]`);if(r){r.dataset.loaded===`true`?t():(r.addEventListener(`load`,()=>t(),{once:!0}),r.addEventListener(`error`,()=>n(Error(`Failed to load ${e}`)),{once:!0}));return}let i=document.createElement(`script`);i.src=e,i.async=!0,i.dataset.cdnLoader=e,i.onload=()=>{i.dataset.loaded=`true`,t()},i.onerror=()=>{Et.delete(e),n(Error(`Failed to load ${e}`))},document.head.appendChild(i)});return Et.set(e,n),n}var Ot=`https://cdn.jsdelivr.net/npm/jspdf@2.5.2/dist/jspdf.umd.min.js`,kt=`https://cdn.jsdelivr.net/npm/docx@9.5.1/build/index.umd.min.js`;async function At(){await Dt(Ot);let e=window.jspdf?.jsPDF;if(!e)throw Error(`jsPDF global not found after CDN load`);return e}async function jt(){await Dt(kt);let e=window.docx;if(!e)throw Error(`docx global not found after CDN load`);return e}async function Mt(e,t){It(`# ${e}\n\n${new y.default({headingStyle:`atx`,codeBlockStyle:`fenced`}).turndown(t)}`,`${e}.md`,`text/markdown`)}async function Nt(e,t){let{Document:n,Paragraph:r,TextRun:i,HeadingLevel:a,Packer:o}=await jt(),s=new DOMParser().parseFromString(t,`text/html`),c=[];c.push(new r({text:e,heading:a.HEADING_1,spacing:{after:200}}));let l=e=>{if(e.nodeType===Node.TEXT_NODE){let t=e.textContent?.trim();t&&c.push(new r({children:[new i(t)]}))}else if(e.nodeType===Node.ELEMENT_NODE){let t=e,n=t.tagName.toLowerCase();switch(n){case`h1`:c.push(new r({text:t.textContent||``,heading:a.HEADING_1}));break;case`h2`:c.push(new r({text:t.textContent||``,heading:a.HEADING_2}));break;case`h3`:c.push(new r({text:t.textContent||``,heading:a.HEADING_3}));break;case`p`:let e=[];t.childNodes.forEach(t=>{if(t.nodeType===Node.TEXT_NODE)e.push(new i(t.textContent||``));else if(t.nodeType===Node.ELEMENT_NODE){let n=t,r={text:n.textContent||``};(n.tagName===`STRONG`||n.tagName===`B`)&&(r.bold=!0),(n.tagName===`EM`||n.tagName===`I`)&&(r.italics=!0),n.tagName===`U`&&(r.underline={}),n.tagName===`CODE`&&(r.font=`Courier New`),e.push(new i(r))}}),e.length>0?c.push(new r({children:e})):c.push(new r({text:t.textContent||``}));break;case`ul`:case`ol`:t.querySelectorAll(`li`).forEach(e=>{c.push(new r({text:e.textContent||``,bullet:n===`ul`?{level:0}:void 0,numbering:n===`ol`?{reference:`default`,level:0}:void 0}))});break;case`blockquote`:c.push(new r({children:[new i({text:t.textContent||``,italics:!0})],indent:{left:720}}));break;default:t.childNodes.forEach(l)}}};s.body.childNodes.forEach(l);let u=new n({sections:[{properties:{},children:c}]}),d=await o.toBlob(u),f=URL.createObjectURL(d),p=document.createElement(`a`);p.href=f,p.download=`${e}.docx`,p.click(),URL.revokeObjectURL(f)}async function Pt(e,t){let n=document.createElement(`div`);n.style.position=`absolute`,n.style.left=`-9999px`,n.style.width=`210mm`,n.style.padding=`20mm`,n.style.backgroundColor=`white`,n.style.fontFamily=`Arial, sans-serif`,n.style.fontSize=`12pt`,n.style.lineHeight=`1.6`,n.innerHTML=`
18
18
  <h1 style="font-size: 24pt; margin-bottom: 20px;">${e}</h1>
19
19
  ${t}
20
- `,document.body.appendChild(n);try{let t=await At(),r=await(0,v.default)(n,{scale:2,useCORS:!0,logging:!1}),i=r.toDataURL(`image/png`),a=new t({orientation:`portrait`,unit:`mm`,format:`a4`}),o=r.height*210/r.width,s=o,c=0;for(a.addImage(i,`PNG`,0,c,210,o),s-=297;s>=0;)c=s-o,a.addPage(),a.addImage(i,`PNG`,0,c,210,o),s-=297;a.save(`${e}.pdf`)}finally{document.body.removeChild(n)}}async function Ft(e,t){try{let n=`${e}\n\n${new y.default().turndown(t)}`;await navigator.clipboard.writeText(n),window.open(`https://docs.google.com/document/create`,`_blank`),alert(`Content copied to clipboard! Paste it into the new Google Doc.`)}catch(e){console.error(`Failed to export to Google Docs:`,e),alert(`Failed to copy content to clipboard. Please try again.`)}}function It(e,t,n){let r=new Blob([e],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,a.click(),URL.revokeObjectURL(i)}var Lt=({section:e,speechStatus:t,start:n,stop:r,handleOpenInLLM:i})=>e.assistantMessage?(0,d.jsx)(`div`,{className:`flex flex-row items-center justify-end w-full text-foreground py-4 -mx-2`,children:(0,d.jsxs)(`div`,{className:`flex flex-row items-center space-x-1`,children:[(0,d.jsx)(Tt,{messageId:e.assistantMessage.messageId}),(0,d.jsx)(xt,{initialMessage:e.assistantMessage.content,section:e}),(0,d.jsxs)(K,{children:[(0,d.jsx)(q,{asChild:!0,children:(0,d.jsx)(`button`,{onClick:()=>{t===`started`?r():n()},className:`p-2 text-muted-foreground rounded-full backdrop-blur-md bg-white/10 dark:bg-black/10 hover:bg-white/20 dark:hover:bg-black/20 transition duration-200 hover:text-foreground`,children:t===`started`?(0,d.jsx)(s.StopCircle,{size:18}):(0,d.jsx)(s.Volume2,{size:18})})}),(0,d.jsx)(J,{side:`bottom`,children:t===`started`?`Stop`:`Read aloud`})]}),(0,d.jsxs)(pt,{children:[(0,d.jsxs)(K,{children:[(0,d.jsx)(q,{asChild:!0,children:(0,d.jsx)(mt,{asChild:!0,children:(0,d.jsx)(`button`,{className:`p-2 text-muted-foreground rounded-full backdrop-blur-md bg-white/10 dark:bg-black/10 hover:bg-white/20 dark:hover:bg-black/20 transition duration-200 hover:text-foreground`,children:(0,d.jsx)(s.Download,{size:18})})})}),(0,d.jsx)(J,{side:`bottom`,children:`Export`})]}),(0,d.jsxs)(ht,{align:`end`,side:`top`,children:[(0,d.jsxs)(Y,{onClick:()=>Mt(e.userMessage.content,e.assistantMessage.content),children:[(0,d.jsx)(s.FileText,{size:16}),`Markdown`]}),(0,d.jsxs)(Y,{onClick:()=>Pt(e.userMessage.content,e.assistantMessage.content),children:[(0,d.jsx)(s.FileType,{size:16}),`PDF`]}),(0,d.jsxs)(Y,{onClick:()=>Nt(e.userMessage.content,e.assistantMessage.content),children:[(0,d.jsx)(s.FileDown,{size:16}),`DOCX`]}),(0,d.jsxs)(Y,{onClick:()=>Ft(e.userMessage.content,e.assistantMessage.content),children:[(0,d.jsx)(s.FileSpreadsheet,{size:16}),`Google Docs`]})]})]}),(0,d.jsxs)(pt,{children:[(0,d.jsxs)(K,{children:[(0,d.jsx)(q,{asChild:!0,children:(0,d.jsx)(mt,{asChild:!0,children:(0,d.jsx)(`button`,{className:`p-2 text-muted-foreground rounded-full backdrop-blur-md bg-white/10 dark:bg-black/10 hover:bg-white/20 dark:hover:bg-black/20 transition duration-200 hover:text-foreground`,children:(0,d.jsx)(s.ExternalLink,{size:18})})})}),(0,d.jsx)(J,{side:`bottom`,children:`Open in LLM`})]}),(0,d.jsxs)(ht,{align:`end`,side:`top`,children:[(0,d.jsx)(Y,{onClick:()=>i(`qwksearch`),children:`QwkSearch`}),(0,d.jsx)(Y,{onClick:()=>i(`claude`),children:`Claude`}),(0,d.jsx)(Y,{onClick:()=>i(`perplexity`),children:`Perplexity`}),(0,d.jsx)(Y,{onClick:()=>i(`gemini`),children:`Google Gemini`}),(0,d.jsx)(Y,{onClick:()=>i(`chatgpt`),children:`ChatGPT`})]})]})]})}):null,Rt=(0,x.cva)(`inline-flex items-center justify-center rounded-2xl border px-3 py-1.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden`,{variants:{variant:{default:`border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90`,secondary:`border-transparent bg-gray-100 text-gray-700 [a&]:hover:bg-gray-200 dark:bg-gray-800 dark:text-gray-300 dark:[a&]:hover:bg-gray-700`,destructive:`border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60`,outline:`text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground`,new:`text-purple-600 dark:text-purple-300 bg-purple-600/30 dark:bg-purple-600/30`,beta:`text-blue-600 dark:text-blue-300 bg-blue-600/30 dark:bg-blue-600/30`,highlight:`text-green-800 dark:text-green-300 bg-green-600/30 dark:bg-green-600/30`}},defaultVariants:{variant:`default`}});function zt({className:e,variant:t,asChild:n=!1,...r}){return(0,d.jsx)(n?b.Slot:`span`,{"data-slot":`badge`,className:F(Rt({variant:t}),e),...r})}var Bt=({section:e,isLast:t,loading:r,sendMessage:i})=>{let a=(0,n.useRef)([]);return(0,n.useEffect)(()=>{e.suggestions&&e.suggestions.length>0&&(a.current=e.suggestions.slice(0,5))},[e.suggestions]),(0,n.useEffect)(()=>{let e=e=>{let t=e.target;if(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable)return;let n=e.key,r=parseInt(n);r>=1&&r<=5&&a.current.length>=r&&(e.preventDefault(),i(a.current[r-1]))};if(t&&a.current.length>0)return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,i]),!e.suggestions||e.suggestions.length===0||!e.assistantMessage?null:(0,d.jsx)(`div`,{className:`mt-8 pt-6 border-t border-border/50`,children:(0,d.jsx)(`div`,{className:`space-y-2`,children:e.suggestions?.slice(0,5).map((e,t)=>(0,d.jsx)(`button`,{onClick:()=>i(e),className:`group w-full px-4 py-4 text-left transition-all duration-200 cursor-pointer rounded-lg border border-border/50 hover:border-primary/30 hover:bg-accent/50 hover:shadow-sm`,children:(0,d.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,d.jsx)(zt,{variant:`secondary`,className:`flex-shrink-0 h-6 w-6 p-0 flex items-center justify-center rounded-full text-sm font-semibold`,children:t+1}),(0,d.jsx)(`p`,{className:`flex-1 text-base font-medium text-muted-foreground group-hover:text-primary transition-colors duration-200 leading-relaxed`,children:e}),(0,d.jsx)(s.Plus,{size:18,className:`text-muted-foreground/60 group-hover:text-primary transition-colors duration-200 flex-shrink-0`})]})},t))})})},Vt=({section:e,dividerRef:t,isLast:r})=>{let{loading:i,sendMessage:a}=G(),[s,c]=(0,n.useState)(!0),[l,u]=(0,n.useState)(!1),[f,p]=(0,n.useState)(!1),[m,h]=(0,n.useState)(e.userMessage.content),g=()=>{navigator.clipboard.writeText(e.userMessage.content),u(!0),setTimeout(()=>u(!1),1500)},_=()=>{m.trim()&&(a(m.trim()),p(!1))},v=e.parsedAssistantMessage||``,y=e.speechMessage||``,b=e.thinkingEnded,{speechStatus:x,start:S,stop:C}=Me(y,{enableInterrupt:!0}),w=t=>{if(!e.assistantMessage)return;let n=`${e.userMessage.content}\n\n${e.assistantMessage.content}`;navigator.clipboard.writeText(n);let r={qwksearch:`https://qwksearch.com/?q=`,claude:`https://claude.ai/new?q=`,perplexity:`https://www.perplexity.ai/?q=`,gemini:`https://gemini.google.com/?q=`,chatgpt:`https://chat.openai.com/?q=`}[t];r&&window.open(`${r}${encodeURIComponent(n)}`,`_blank`)},T={overrides:{think:{component:st,props:{thinkingEnded:b}},citation:{component:at,props:{sources:e.sourceMessage?.sources||[]}},table:{component:({children:e,...t})=>(0,d.jsx)(`div`,{className:`not-prose -mx-2 my-4 max-w-full overflow-x-auto sm:mx-0`,children:(0,d.jsx)(`table`,{...t,className:`w-max min-w-full border-collapse text-sm`,children:e})})}}};return(0,d.jsxs)(`div`,{className:`space-y-3`,children:[(0,d.jsx)(ft,{section:e,isExpanded:s,setIsExpanded:c,isEditing:f,setIsEditing:p,editText:m,setEditText:h,handleEditSubmit:_,copiedUserMsg:l,handleCopyUserMsg:g}),(0,d.jsx)(`div`,{className:F(`flex flex-col space-y-3 overflow-hidden transition-all duration-300 ease-in-out`,s?`max-h-[100000px] opacity-100`:`max-h-0 opacity-0`),children:(0,d.jsxs)(`div`,{ref:t,className:`flex flex-col space-y-6 w-full`,children:[e.searchingMessage&&e.searchingMessage.queries.length>0&&(0,d.jsx)(ye,{queries:e.searchingMessage.queries,loading:i&&r}),e.sourceMessage&&e.sourceMessage.sources.length>0&&(0,d.jsx)(`div`,{className:`flex flex-col space-y-2`,children:(0,d.jsx)(ge,{sources:e.sourceMessage.sources,query:e.userMessage.content})}),(0,d.jsx)(`div`,{className:`flex min-w-0 flex-col space-y-2`,children:e.assistantMessage&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(o.default,{className:F(`prose prose-lg 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-loose prose-pre:p-0 font-[400]`,`min-w-0 max-w-none break-words text-foreground font-inter`),options:T,children:v}),i&&r?null:(0,d.jsx)(Lt,{section:e,speechStatus:x,start:S,stop:C,handleOpenInLLM:w}),(0,d.jsx)(Bt,{section:e,isLast:r,loading:i,sendMessage:a})]})})]})})]})},Ht=`quantumSphere`,Ut=Object.fromEntries(Object.entries(C).filter(([e,t])=>typeof t==`function`&&e.startsWith(`loading`))),Wt=[Ht,...Object.keys(Ut).sort()],Gt;function Kt(){let e=Wt.filter(e=>e!==Gt),t=e.length>0?e:Wt;return Gt=t[Math.floor(Math.random()*t.length)],Gt}function qt(e,t){let n=Ut[e];return n?n({size:t,raw:!0}):``}var Jt=({size:e=140,className:t})=>{let[r,i]=(0,n.useState)(null);return(0,n.useEffect)(()=>{i(Kt())},[]),(0,d.jsx)(`div`,{role:`status`,"aria-label":`Loading`,className:F(`flex items-center justify-center w-full h-[200px]`,t),children:r===`quantumSphere`?(0,d.jsx)(S.default,{autoRandomize:!0}):r?(0,d.jsx)(`div`,{className:`flex items-center justify-center`,dangerouslySetInnerHTML:{__html:qt(r,e)}}):null})},Yt=e=>{if(e===0)return`0 Bytes`;let t=1024,n=[`Bytes`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**r).toFixed(2))+` `+n[r]},Xt=({file:e,onRemove:t})=>{let n=e.type.startsWith(`image/`)&&e.preview;return(0,d.jsxs)(`div`,{className:`relative group flex-shrink-0 w-24 h-24 rounded-xl overflow-hidden border border-bg-300 bg-bg-200 animate-fade-in transition-all hover:border-text-400`,children:[n?(0,d.jsxs)(`div`,{className:`w-full h-full relative`,children:[(0,d.jsx)(`img`,{src:e.preview,alt:e.file.name,className:`w-full h-full object-cover`}),(0,d.jsx)(`div`,{className:`absolute inset-0 bg-black/20 group-hover:bg-black/0 transition-colors`}),(0,d.jsx)(`span`,{className:`absolute bottom-1 left-1 px-1.5 py-0.5 rounded-md bg-black/60 text-white text-[10px] font-medium leading-none backdrop-blur-sm pointer-events-none`,title:e.file.name,children:Yt(e.file.size)})]}):(0,d.jsxs)(`div`,{className:`w-full h-full p-3 flex flex-col justify-between`,children:[(0,d.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,d.jsx)(`div`,{className:`p-1.5 bg-bg-300 rounded`,children:(0,d.jsx)(Z.FileText,{className:`w-4 h-4 text-text-300`})}),(0,d.jsx)(`span`,{className:`text-[10px] font-medium text-text-400 uppercase tracking-wider truncate`,children:e.file.name.split(`.`).pop()})]}),(0,d.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,d.jsx)(`p`,{className:`text-xs font-medium text-text-200 truncate`,title:e.file.name,children:e.file.name}),(0,d.jsx)(`p`,{className:`text-[10px] text-text-500`,children:Yt(e.file.size)})]})]}),(0,d.jsx)(`button`,{onClick:()=>t(e.id),className:`absolute top-1 right-1 p-1 bg-black/50 hover:bg-black/70 rounded-full text-white opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,d.jsx)(Z.X,{className:`w-3 h-3`})}),e.uploadStatus===`uploading`&&(0,d.jsx)(`div`,{className:`absolute inset-0 bg-black/40 flex items-center justify-center`,children:(0,d.jsx)(Z.Loader2,{className:`w-5 h-5 text-white animate-spin`})}),e.uploadStatus===`error`&&(0,d.jsx)(`div`,{className:`absolute inset-0 bg-red-900/60 flex items-center justify-center`,children:(0,d.jsx)(Z.X,{className:`w-5 h-5 text-red-300`})})]})},Zt=({content:e,onRemove:t})=>(0,d.jsxs)(`div`,{className:`relative group flex-shrink-0 w-28 h-28 rounded-2xl overflow-hidden border border-[#E5E5E5] dark:border-[#30302E] bg-white dark:bg-[#20201F] animate-fade-in p-3 flex flex-col justify-between shadow-[0_1px_2px_rgba(0,0,0,0.05)]`,children:[(0,d.jsx)(`div`,{className:`overflow-hidden w-full`,children:(0,d.jsx)(`p`,{className:`text-[10px] text-[#9CA3AF] leading-[1.4] font-mono break-words whitespace-pre-wrap line-clamp-4 select-none`,children:e.content})}),(0,d.jsx)(`div`,{className:`flex items-center justify-between w-full mt-2`,children:(0,d.jsx)(`div`,{className:`inline-flex items-center justify-center px-1.5 py-[2px] rounded border border-[#E5E5E5] dark:border-[#404040] bg-white dark:bg-transparent`,children:(0,d.jsx)(`span`,{className:`text-[9px] font-bold text-[#6B7280] dark:text-[#9CA3AF] uppercase tracking-wider font-sans`,children:`PASTED`})})}),(0,d.jsx)(`button`,{onClick:()=>t(e.id),className:`absolute top-2 right-2 p-[3px] bg-white dark:bg-[#30302E] border border-[#E5E5E5] dark:border-[#404040] rounded-full text-[#9CA3AF] hover:text-[#6B7280] dark:hover:text-white transition-colors shadow-sm opacity-0 group-hover:opacity-100`,children:(0,d.jsx)(Z.X,{className:`w-2 h-2`})})]});function Qt(){return typeof window>`u`?!1:!!(window.SpeechRecognition||window.webkitSpeechRecognition)}function $t(e,t,r={}){let[i,a]=(0,n.useState)(!1),[o,s]=(0,n.useState)(``),[c,l]=(0,n.useState)(``),[u,d]=(0,n.useState)(0),f=(0,n.useRef)(null),h=(0,n.useRef)(null),g=(0,n.useRef)([]),_=(0,n.useRef)({onTranscript:e,onEnd:t,onPartial:r.onPartial});_.current={onTranscript:e,onEnd:t,onPartial:r.onPartial};let v=(0,n.useMemo)(()=>new w.LiveTranscriber({engine:`webspeech`,language:r.language??`en-US`,onStateChange:a,onPartial:e=>{s(e),e&&(l(e),d(e=>e+1)),_.current.onPartial?.(e)},onCommit:e=>{s(``),l(e),d(e=>e+1),_.current.onTranscript(e)},onError:()=>{m.toast.error(`Speech recognition stopped unexpectedly.`)}}),[r.language]),y=(0,n.useCallback)(()=>{let e=f.current;if(e&&e.state!==`inactive`){e.stop();return}h.current?.getTracks().forEach(e=>e.stop()),h.current=null,f.current=null},[]),b=async e=>{let t=new FormData;return t.append(`file`,e,`speech-input.webm`),t.append(`languageCode`,`en`),((await(0,p.default)(`agent/transcript`,{method:`POST`,body:t}))?.text??``).trim()},x=(0,n.useCallback)(async()=>{if(typeof navigator>`u`||!navigator.mediaDevices?.getUserMedia||typeof MediaRecorder>`u`){m.toast.error(`Speech input is not supported in this browser`,{duration:5e3}),a(!1),_.current.onEnd();return}try{let e=await navigator.mediaDevices.getUserMedia({audio:!0}),t=new MediaRecorder(e);g.current=[],h.current=e,f.current=t,t.ondataavailable=e=>{e.data.size>0&&g.current.push(e.data)},t.onstart=()=>{a(!0)},t.onstop=async()=>{try{let e=new Blob(g.current,{type:`audio/webm`});if(g.current=[],h.current?.getTracks().forEach(e=>e.stop()),h.current=null,f.current=null,a(!1),e.size===0)return;let t=await b(e);t?(l(t),d(e=>e+1),_.current.onTranscript(t)):m.toast.error(`No speech detected. Please try again.`)}catch{m.toast.error(`Unable to transcribe audio.`)}finally{_.current.onEnd()}},t.start()}catch{m.toast.error(`Microphone access is required for speech input.`),a(!1),_.current.onEnd()}},[]),S=(0,n.useCallback)(async()=>{if(v.isListening()){await v.stop(),s(``),_.current.onEnd();return}if(f.current){y();return}if(Qt()){await v.start();return}await x()},[v,x,y]);(0,n.useEffect)(()=>{let e=e=>{e.ctrlKey&&e.key==="`"&&(e.preventDefault(),S())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[S]),(0,n.useEffect)(()=>()=>{v.stop(),y()},[v,y]);let C=typeof navigator<`u`&&!!navigator.mediaDevices?.getUserMedia&&typeof MediaRecorder<`u`;return{isListening:i,toggleSpeech:S,isSpeechSupported:Qt()||C,partial:o,lastPhrase:c,phraseId:u}}var en=`voiceAutoStart`,tn=`voiceAutoStartTriggered`,nn=typeof window<`u`;function rn(){return nn?localStorage.getItem(en)===`true`:!1}function an(e){nn&&localStorage.setItem(en,String(e))}function on(){nn&&localStorage.setItem(tn,`true`)}function sn({enabled:e,isSpeechSupported:t,isListening:n},r){return e&&t&&!n&&!r}function cn(){return nn?localStorage.getItem(tn)===`true`:!1}function ln({isSpeechSupported:e,isListening:t,toggleSpeech:r}){(0,n.useEffect)(()=>{sn({enabled:rn(),isSpeechSupported:e,isListening:t},cn())&&(on(),r())},[e])}var un=[`pdf`,`docx`,`txt`,`md`,`html`,`htm`],dn=[`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`avif`],fn=[...un,...dn],pn=10,mn=52428800,hn=(e,t)=>{if(e&&typeof e==`object`){let t=e.message??e.error??e.data?.message;if(typeof t==`string`&&t.length>0)return t}return typeof e==`string`&&e.length>0?e:t};function gn({setMessage:e,contextFiles:t,contextFileIds:r,setContextFiles:i,setContextFileIds:a}){let[o,s]=(0,n.useState)([]),[l,u]=(0,n.useState)([]),[d,f]=(0,n.useState)(!1),[p,h]=(0,n.useState)(!1),g=(0,n.useCallback)(async e=>{let n=Array.from(e);n.length>pn&&(m.toast.error(`You can attach up to ${pn} files at a time.`),n=n.slice(0,pn));let o=n.filter(e=>e.size>mn);if(o.length>0&&(m.toast.error(`${o.map(e=>e.name).join(`, `)} exceed${o.length===1?`s`:``} the 50 MB per-file limit.`),n=n.filter(e=>e.size<=mn)),n.length===0)return;let l=n.map(e=>{let t=e.type.startsWith(`image/`)||/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(e.name),n=e.name.split(`.`).pop()?.toLowerCase()??``,r=fn.includes(n);return{id:Math.random().toString(36).substr(2,9),file:e,type:t?`image/unknown`:e.type||`application/octet-stream`,preview:t?URL.createObjectURL(e):null,uploadStatus:r?`uploading`:`pending`,_ext:n}});s(e=>[...e,...l]),l.filter(e=>!fn.includes(e._ext)).forEach(e=>{setTimeout(()=>{s(t=>t.map(t=>t.id===e.id?{...t,uploadStatus:`complete`}:t))},600+Math.random()*600)});let u=l.filter(e=>fn.includes(e._ext));if(u.length!==0)try{let{data:e,error:n}=await(0,c.uploadFiles)({body:{files:u.map(e=>e.file)}});if(n||!e?.files)throw Error(hn(n??e,`Upload failed.`));s(e=>e.map(e=>u.some(t=>t.id===e.id)?{...e,uploadStatus:`complete`}:e)),i([...t,...e.files]),a([...r,...e.files.map(e=>e.fileId)])}catch(e){m.toast.error(hn(e,`Failed to upload files.`)),s(e=>e.map(e=>u.some(t=>t.id===e.id)?{...e,uploadStatus:`error`}:e))}},[e,t,r,i,a]);return{files:o,setFiles:s,pastedContent:l,setPastedContent:u,isDragging:d,isExtractingUrl:p,handleFiles:g,extractUrl:(0,n.useCallback)(async e=>{let n=e.trim();if(!/^https?:\/\//i.test(n))return m.toast.error(`Enter a valid http(s) URL.`),!1;h(!0);try{let e=await(await fetch(`/api/doc/uploads`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({url:n})})).json();if(!e?.files||e.files.length===0)throw Error(hn(e,`Could not extract content from ${n}`));return i([...t,...e.files]),a([...r,...e.files.map(e=>e.fileId)]),m.toast.success(`Added "${e.files[0].fileName}" as context.`),!0}catch(e){return m.toast.error(hn(e,`Failed to extract URL.`)),!1}finally{h(!1)}},[t,r,i,a]),onDragOver:e=>{e.preventDefault(),f(!0)},onDragLeave:e=>{e.preventDefault(),f(!1)},onDrop:e=>{e.preventDefault(),f(!1),e.dataTransfer.files&&g(e.dataTransfer.files)},handlePaste:e=>{let t=e.clipboardData.items,n=[];for(let e=0;e<t.length;e++)if(t[e].kind===`file`){let r=t[e].getAsFile();r&&n.push(r)}if(n.length>0){e.preventDefault(),g(n);return}let r=e.clipboardData.getData(`text`);if(r.length>300){e.preventDefault();let t={id:Math.random().toString(36).substr(2,9),content:r,timestamp:new Date};u(e=>[...e,t])}},resetAttachments:()=>{s([]),u([]),i([]),a([])}}}var _n=()=>window.gapi,vn=()=>window.google,yn=()=>{let e=(0,n.useRef)(!1),r=(0,n.useRef)(!1);return(0,n.useEffect)(()=>{_n()?r.current=!0:(()=>{let e=document.createElement(`script`);e.src=`https://apis.google.com/js/api.js`,e.onload=()=>{_n()?.load(`client:picker`,()=>{r.current=!0})},document.body.appendChild(e)})(),vn()?.picker?e.current=!0:(()=>{let t=document.createElement(`script`);t.src=`https://www.google.com/jsapi`,t.onload=()=>{e.current=!0},document.body.appendChild(t)})()},[]),{openPicker:async(e,n,i)=>{let a=vn();if(!r.current||!a?.picker){i?.(`Google Picker API not loaded yet. Please try again.`);return}try{let{picker:r}=a,i=new r.PickerBuilder().addView(r.ViewId.DOCS).addView(r.ViewId.DOCS_IMAGES).addView(r.ViewId.DOCS_VIDEOS).addView(new r.DocsView().setIncludeFolders(!0).setMimeTypes(`application/pdf,application/vnd.google-apps.document,application/vnd.google-apps.spreadsheet,text/plain,image/jpeg,image/png`)).setOAuthToken(e).setDeveloperKey(t.researchAgentUIConfig.googleApiKey);t.researchAgentUIConfig.googleAppId&&i.setAppId(t.researchAgentUIConfig.googleAppId),i.setCallback(e=>{if(e.action===r.Action.PICKED){let t=e.docs;t&&n(t)}else e.action===r.Action.CANCEL&&console.log(`User cancelled picker`)}).build().setVisible(!0)}catch(e){i?.(e.message||`Failed to open Google Picker`)}}}},bn=()=>{let{chatModelProvider:e,setChatModelProvider:t}=G(),[i,a]=(0,n.useState)([]),[o,l]=(0,n.useState)(!0),u=(0,r.useRouter)();(0,n.useEffect)(()=>{(async()=>{try{l(!0);let{data:n}=await(0,c.listProviders)(),r=n?.providers??[];if(a(r),!e.key&&r.length>0){let e=localStorage.getItem(`chatModelKey`),n=localStorage.getItem(`chatModelProviderId`);if(e&&n)t({key:e,providerId:n});else{let e=r.find(e=>e.chatModels.length>0);e&&t({key:e.chatModels[0].key,providerId:e.id})}}}catch(e){console.error(`Error loading providers:`,e)}finally{l(!1)}})()},[]);let f=(0,n.useMemo)(()=>{if(!e.key)return`Select`;for(let t of i){let n=t.chatModels.find(t=>t.key===e.key);if(n)return n.name}return e.key},[i,e.key]),p=(e,n)=>{t({providerId:e,key:n}),localStorage.setItem(`chatModelProviderId`,e),localStorage.setItem(`chatModelKey`,n)};return(0,d.jsxs)(vt,{children:[(0,d.jsxs)(yt,{className:`gap-2`,children:[(0,d.jsx)(s.Cpu,{className:`w-4 h-4 flex-shrink-0 text-sky-500`}),(0,d.jsx)(`span`,{children:`Model`}),(0,d.jsx)(`span`,{className:`ml-auto text-xs text-muted-foreground truncate max-w-[55px]`,children:f})]}),(0,d.jsxs)(bt,{className:`w-52 max-h-[400px] overflow-y-auto`,children:[o?(0,d.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,d.jsx)(s.Loader2,{className:`h-4 w-4 animate-spin text-muted-foreground`})}):i.length===0?(0,d.jsx)(`div`,{className:`px-3 py-2 text-xs text-muted-foreground`,children:`No models configured`}):i.map((t,n)=>(0,d.jsxs)(`div`,{children:[(0,d.jsx)(_t,{className:`text-[10px] uppercase tracking-wider text-muted-foreground font-medium`,children:t.name}),t.chatModels.map(n=>(0,d.jsxs)(Y,{onSelect:()=>p(t.id,n.key),className:F(`gap-2`,e?.providerId===t.id&&e?.key===n.key&&`bg-secondary`),children:[(0,d.jsx)(s.Cpu,{className:F(`h-3.5 w-3.5 flex-shrink-0`,e?.providerId===t.id&&e?.key===n.key?`text-sky-500`:`text-muted-foreground`)}),(0,d.jsx)(`span`,{className:`truncate`,children:n.name}),e?.providerId===t.id&&e?.key===n.key&&(0,d.jsx)(`svg`,{className:`w-3 h-3 text-primary ml-auto shrink-0`,fill:`none`,viewBox:`0 0 10 10`,children:(0,d.jsx)(`path`,{d:`M1.5 5l2.5 2.5 4.5-4.5`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`})})]},n.key)),n<i.length-1&&(0,d.jsx)(X,{})]},t.id)),(0,d.jsx)(X,{}),(0,d.jsxs)(Y,{onSelect:()=>u.push(`/settings?section=models`),className:`gap-2`,children:[(0,d.jsx)(s.Plus,{className:`h-3.5 w-3.5 text-sky-500 flex-shrink-0`}),(0,d.jsx)(`span`,{children:`Add model`})]})]})]})};function xn(e){let t=e.messages?.[e.messages.length-1],n=t&&`createdAt`in t?t.createdAt:void 0;if(n){let e=new Date(n).getTime();if(!Number.isNaN(e))return new Date(e).toISOString()}return e.createdAt}var Sn=e=>new Date(e.lastMessageAt||e.createdAt).getTime();function Cn(){return Ie().map(e=>({...e,messageCount:e.messages?.filter(e=>e.role===`user`).length??0,lastMessageAt:xn(e)}))}function wn(e=10){let[t,r]=(0,n.useState)([]),[i,a]=(0,n.useState)(!1),{isAuthenticated:o,isLoading:s}=nt(),l=(0,n.useRef)(!1),u=(0,n.useCallback)(async(e=!1)=>{if(!s&&(!l.current||e)){l.current=!0,a(!0);try{if(o){let{data:e,error:t}=await(0,c.listChats)();if(t){r(Cn());return}r(Array.isArray(e?.chats)?e.chats:[])}else r(Cn())}catch(e){console.error(`Failed to fetch recent chats:`,e),r([])}finally{a(!1)}}},[o,s]);return{recentChats:[...t].sort((e,t)=>Sn(t)-Sn(e)).slice(0,e),loading:i,load:u}}function Tn(e){let t=new Date(e).getTime();if(Number.isNaN(t))return``;let n=Math.round((Date.now()-t)/1e3);if(n<5)return`just now`;if(n<60)return`${n} sec`;let r=Math.round(n/60);if(r<60)return`${r} min`;let i=Math.round(r/60);if(i<24)return`${i} hr`;let a=Math.round(i/24);if(a<7)return`${a} day${a===1?``:`s`}`;let o=Math.round(a/7);if(o<5)return`${o} week${o===1?``:`s`}`;let s=Math.round(a/30);if(s<12)return`${s} month${s===1?``:`s`}`;let c=Math.round(a/365);return`${c} year${c===1?``:`s`}`}var En=10,Dn=()=>{let e=(0,r.useRouter)(),{incognito:n,setIncognito:i}=G(),{recentChats:a,loading:o,load:c}=wn(En),l=e=>{i(e),m.toast.success(e?`Private mode on — messages won't be saved`:`Private mode off`)},u=n=>{t.researchAgentUIConfig.onOpenChat?.(n)||e.push(`/c/${n}`)};return(0,d.jsxs)(vt,{onOpenChange:e=>{e&&c()},children:[(0,d.jsxs)(yt,{className:`gap-2`,children:[(0,d.jsx)(s.History,{className:`w-4 h-4 flex-shrink-0 text-muted-foreground`}),(0,d.jsx)(`span`,{children:`History`})]}),(0,d.jsxs)(bt,{className:`w-64 max-h-[70vh] overflow-y-auto`,children:[(0,d.jsxs)(gt,{checked:n,onCheckedChange:l,onSelect:e=>e.preventDefault(),className:`gap-2`,children:[(0,d.jsx)(s.EyeOff,{className:`w-4 h-4 flex-shrink-0 text-muted-foreground`}),(0,d.jsx)(`span`,{children:`Private`})]}),(0,d.jsx)(X,{}),o?(0,d.jsxs)(Y,{disabled:!0,className:`gap-2`,children:[(0,d.jsx)(s.Loader2,{className:`w-3.5 h-3.5 animate-spin flex-shrink-0`}),(0,d.jsx)(`span`,{children:`Loading…`})]}):a.length===0?(0,d.jsx)(Y,{disabled:!0,children:(0,d.jsx)(`span`,{className:`text-muted-foreground`,children:`No recent chats`})}):a.map(e=>{let t=Tn(e.lastMessageAt||e.createdAt);return(0,d.jsxs)(Y,{onSelect:()=>u(e.id),className:`gap-2`,title:e.title,children:[(0,d.jsx)(`span`,{className:`truncate`,children:e.title}),t&&(0,d.jsx)(`span`,{className:`ml-auto pl-2 text-xs italic text-muted-foreground/70 whitespace-nowrap`,children:t})]},e.id)}),(0,d.jsx)(X,{}),(0,d.jsxs)(Y,{onSelect:()=>e.push(`/library`),className:`gap-2`,children:[(0,d.jsx)(s.History,{className:`w-4 h-4 flex-shrink-0 text-muted-foreground`}),(0,d.jsx)(`span`,{children:`All history`})]})]})]})},On=[{label:`5s`,value:5},{label:`15s`,value:15},{label:`30s`,value:30},{label:`45s`,value:45},{label:`60s`,value:60},{label:`Unlimited`,value:0}],kn=[`pdf`,`docx`,`txt`,`md`,`html`,`htm`],An=`markdown.js.jsx.ts.tsx.py.rb.go.rs.java.c.cpp.h.hpp.cs.swift.kt.sh.bash.zsh.json.yaml.yml.toml.ini.cfg.conf.xml.csv.tsv.log.env.sql.graphql.vue.svelte.astro.css.scss.less.sass.tex.bib.rst.adoc.org`.split(`.`),jn=({onFileSelect:e,disabled:i=!1})=>{let a=(0,r.useRouter)(),{category:o,setCategory:l,sections:u,chatId:f}=G(),{isAuthenticated:p}=nt(),h=o?o.split(`,`).filter(Boolean):[`general`],g=H.find(e=>e.code===h[0])||H[0],_=e=>{let t=o?o.split(`,`).filter(Boolean):[`general`],n=t.includes(e)?t.filter(t=>t!==e):[...t,e];l(n.length>0?n.join(`,`):`general`)},[v,y]=(0,n.useState)(!1),[b,x]=(0,n.useState)(!1),[S,C]=(0,n.useState)(!1),[w,T]=(0,n.useState)(!1),[E,D]=(0,n.useState)(()=>{if(typeof window>`u`)return 5;let e=Number(localStorage.getItem(`thinkingTimeLimit`)??`5`);return Number.isFinite(e)?e:5}),O=n.default.useRef(null),{openPicker:k}=yn();(0,n.useEffect)(()=>{A()},[]);let A=async()=>{try{let{data:e}=await(0,c.googleDocsAuthStatus)();y(e?.isConnected||!1)}catch{}},j=e=>{D(e),localStorage.setItem(`thinkingTimeLimit`,String(e))},M=async()=>{if(`showOpenFilePicker`in window)try{let t=await window.showOpenFilePicker({multiple:!0,types:[{description:`Supported files`,accept:{"application/pdf":[`.pdf`],"application/vnd.openxmlformats-officedocument.wordprocessingml.document":[`.docx`],"text/plain":[`.txt`],"text/markdown":[`.md`],"text/html":[`.html`,`.htm`],"image/*":[`.jpg`,`.jpeg`,`.png`,`.gif`,`.webp`,`.svg`]}}]}),n=await Promise.all(t.map(e=>e.getFile()));n.length>0&&e(n)}catch(e){e?.name!==`AbortError`&&(console.error(`Failed to open file picker:`,e),O.current?.click())}else O.current?.click()};async function N(e,t=``){let n=[];for await(let r of e.values())if(r.kind===`file`){let e=await r.getFile(),i=e.name.split(`.`).pop()?.toLowerCase()??``;if(kn.includes(i))n.push(e);else if(An.includes(i))try{let r=await e.text(),i=t?`${t}/${e.name}`:e.name;n.push(new File([r],`${i.replace(/[/\\]/g,`_`)}.txt`,{type:`text/plain`}))}catch{}}else if(r.kind===`directory`){let e=r;if(e.name.startsWith(`.`)||e.name===`node_modules`||e.name===`__pycache__`)continue;n.push(...await N(e,t?`${t}/${e.name}`:e.name))}return n}let P=async()=>{if(!(`showDirectoryPicker`in window)){alert(`Your browser does not support the File System Access API. Please use Chrome or Edge.`);return}T(!0);try{let t=await N(await window.showDirectoryPicker({mode:`read`}));t.length>0?e(t):alert(`No supported files found in the selected folder.`)}catch(e){e?.name!==`AbortError`&&console.error(`Failed to access folder:`,e)}finally{T(!1)}},I=async()=>{x(!0);try{let{data:e}=await(0,c.googleDocsAuth)();if(e?.success&&e?.data?.authUrl){let t=e.data.authUrl,n=window.screenX+(window.outerWidth-600)/2,r=window.screenY+(window.outerHeight-700)/2,i=window.open(t,`Google Drive Authorization`,`width=600,height=700,left=${n},top=${r}`),a=e=>{e.data.type===`google-drive-connected`&&(y(!0),i?.close(),window.removeEventListener(`message`,a))};window.addEventListener(`message`,a)}}catch{console.error(`Failed to connect to Google Drive`)}finally{x(!1)}},L=async()=>{try{let{data:t}=await(0,c.getGoogleToken)();if(!t?.success||!t.accessToken)throw Error(`Failed to get access token`);await k(t.accessToken,async t=>{C(!0);try{let n=[];for(let e of t){let{data:t}=await(0,c.getGoogleDriveFile)({query:{fileId:e.id}});if(t?.success&&t?.file){let e=atob(t.file.content),r=new Uint8Array(e.length);for(let t=0;t<e.length;t++)r[t]=e.charCodeAt(t);n.push(new File([new Blob([r],{type:t.file.mimeType})],t.file.name,{type:t.file.mimeType}))}}n.length>0&&e(n)}catch{alert(`Failed to load files from Google Drive`)}finally{C(!1)}},e=>{console.error(`Google Picker error:`,e),alert(e)})}catch(e){alert(e.message||`Failed to open Google Drive picker`)}},R=On.find(e=>e.value===E)?.label??`Unlimited`;return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(`div`,{className:`relative flex shrink min-w-8 !shrink-0 group`,children:[(0,d.jsxs)(pt,{children:[(0,d.jsx)(mt,{asChild:!0,children:(0,d.jsx)(`button`,{disabled:i,className:`inline-flex items-center justify-center relative shrink-0 transition-colors duration-200 h-8 w-8 rounded-lg active:scale-95 text-text-400 hover:text-text-200 hover:bg-bg-200 disabled:opacity-50 disabled:cursor-not-allowed group-active:scale-95`,type:`button`,"aria-label":`Search options`,children:(0,d.jsx)(s.SlidersHorizontal,{className:`w-5 h-5`})})}),(0,d.jsxs)(ht,{align:`start`,side:`top`,sideOffset:8,className:`w-44`,children:[(0,d.jsxs)(vt,{children:[(0,d.jsxs)(yt,{className:`gap-2`,children:[g&&(0,d.jsx)(g.icon,{className:`w-4 h-4 flex-shrink-0`}),(0,d.jsx)(`span`,{children:`Category`})]}),(0,d.jsxs)(bt,{className:`w-44`,children:[(0,d.jsxs)(gt,{checked:h.length===0,onCheckedChange:()=>l(`general`),onSelect:e=>e.preventDefault(),className:`gap-2`,children:[(0,d.jsx)(`div`,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,d.jsx)(`span`,{children:`None`})]}),(0,d.jsx)(X,{}),H.map(e=>(0,d.jsxs)(gt,{checked:h.includes(e.code),onCheckedChange:()=>_(e.code),onSelect:e=>e.preventDefault(),className:`gap-2`,children:[e.icon&&(0,d.jsx)(e.icon,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,d.jsx)(`span`,{children:e.name})]},e.code))]})]}),(0,d.jsxs)(vt,{children:[(0,d.jsxs)(yt,{className:`gap-2`,children:[(0,d.jsx)(s.Clock,{className:`w-4 h-4 flex-shrink-0 text-muted-foreground`}),(0,d.jsx)(`span`,{children:`Speed`}),(0,d.jsx)(`span`,{className:`ml-auto text-xs text-muted-foreground`,children:R})]}),(0,d.jsx)(bt,{className:`w-36`,children:On.map(e=>(0,d.jsxs)(Y,{onSelect:()=>j(e.value),className:F(`justify-between`,E===e.value&&`bg-secondary`),children:[(0,d.jsx)(`span`,{children:e.label}),E===e.value&&(0,d.jsx)(`svg`,{className:`w-3 h-3 text-primary`,fill:`none`,viewBox:`0 0 10 10`,children:(0,d.jsx)(`path`,{d:`M1.5 5l2.5 2.5 4.5-4.5`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`})})]},e.value))})]}),(0,d.jsx)(X,{}),(0,d.jsx)(bn,{}),(0,d.jsx)(X,{}),(0,d.jsxs)(vt,{children:[(0,d.jsxs)(yt,{className:`gap-2`,children:[(0,d.jsx)(s.Upload,{className:`w-4 h-4 flex-shrink-0 text-muted-foreground`}),(0,d.jsx)(`span`,{children:`Upload`})]}),(0,d.jsxs)(bt,{className:`w-44`,children:[(0,d.jsxs)(Y,{onSelect:M,className:`gap-2`,children:[(0,d.jsx)(s.Upload,{className:`h-3.5 w-3.5 flex-shrink-0`}),(0,d.jsx)(`span`,{children:`Your Device`})]}),(0,d.jsxs)(Y,{onSelect:P,disabled:w,className:`gap-2`,children:[w?(0,d.jsx)(s.Loader2,{className:`h-3.5 w-3.5 animate-spin flex-shrink-0`}):(0,d.jsx)(s.FolderOpen,{className:`h-3.5 w-3.5 flex-shrink-0`}),(0,d.jsx)(`span`,{children:w?`Scanning…`:`Local Folder`})]}),(0,d.jsx)(X,{}),(0,d.jsx)(_t,{className:`text-xs font-normal text-muted-foreground`,children:`Cloud`}),v?(0,d.jsxs)(Y,{onSelect:L,disabled:S,className:`gap-2`,children:[S?(0,d.jsx)(s.Loader2,{className:`h-3.5 w-3.5 animate-spin flex-shrink-0`}):(0,d.jsx)(s.CloudIcon,{className:`h-3.5 w-3.5 flex-shrink-0`}),(0,d.jsx)(`span`,{children:S?`Loading…`:`Google Drive`})]}):(0,d.jsxs)(Y,{onSelect:I,disabled:b,className:`gap-2`,children:[b?(0,d.jsx)(s.Loader2,{className:`h-3.5 w-3.5 animate-spin flex-shrink-0`}):(0,d.jsx)(s.CloudIcon,{className:`h-3.5 w-3.5 flex-shrink-0`}),(0,d.jsx)(`span`,{children:b?`Connecting…`:`Connect Google Drive`})]})]})]}),(0,d.jsx)(X,{}),u.length>0&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(vt,{children:[(0,d.jsxs)(yt,{className:`gap-2`,children:[(0,d.jsx)(s.Share2,{className:`w-4 h-4 flex-shrink-0 text-muted-foreground`}),(0,d.jsx)(`span`,{children:`Share`})]}),(0,d.jsxs)(bt,{className:`w-48`,children:[(0,d.jsxs)(Y,{onSelect:async()=>{if(!f){m.toast.error(`No chat to share`);return}if(!p){m.toast.error(`Please sign in to share chats`);return}try{let{data:e,error:t}=await(0,c.shareChat)({body:{chatId:f}});if(!t&&e?.success&&e?.data?.shareUrl)await navigator.clipboard.writeText(e.data.shareUrl),m.toast.success(`Chat is now public - link copied to clipboard`);else throw Error(t?.error||`Failed to share chat`)}catch(e){console.error(`Error sharing chat:`,e);let t=e instanceof Error?e.message:`Failed to share chat`;m.toast.error(t)}},className:`gap-2`,children:[(0,d.jsx)(s.Link,{className:`w-4 h-4 flex-shrink-0`}),(0,d.jsx)(`span`,{children:`Copy link`})]}),(0,d.jsxs)(Y,{onSelect:async()=>{let e=u[0]?.userMessage?.content||`Chat`,t=u.map(e=>`## ${e.userMessage.content}\n\n${e.assistantMessage?.content||``}`).join(`
20
+ `,document.body.appendChild(n);try{let t=await At(),r=await(0,v.default)(n,{scale:2,useCORS:!0,logging:!1}),i=r.toDataURL(`image/png`),a=new t({orientation:`portrait`,unit:`mm`,format:`a4`}),o=r.height*210/r.width,s=o,c=0;for(a.addImage(i,`PNG`,0,c,210,o),s-=297;s>=0;)c=s-o,a.addPage(),a.addImage(i,`PNG`,0,c,210,o),s-=297;a.save(`${e}.pdf`)}finally{document.body.removeChild(n)}}async function Ft(e,t){try{let n=`${e}\n\n${new y.default().turndown(t)}`;await navigator.clipboard.writeText(n),window.open(`https://docs.google.com/document/create`,`_blank`),alert(`Content copied to clipboard! Paste it into the new Google Doc.`)}catch(e){console.error(`Failed to export to Google Docs:`,e),alert(`Failed to copy content to clipboard. Please try again.`)}}function It(e,t,n){let r=new Blob([e],{type:n}),i=URL.createObjectURL(r),a=document.createElement(`a`);a.href=i,a.download=t,a.click(),URL.revokeObjectURL(i)}var Lt=({section:e,speechStatus:t,start:n,stop:r,handleOpenInLLM:i})=>e.assistantMessage?(0,d.jsx)(`div`,{className:`flex flex-row items-center justify-end w-full text-foreground py-4 -mx-2`,children:(0,d.jsxs)(`div`,{className:`flex flex-row items-center space-x-1`,children:[(0,d.jsx)(Tt,{messageId:e.assistantMessage.messageId}),(0,d.jsx)(xt,{initialMessage:e.assistantMessage.content,section:e}),(0,d.jsxs)(K,{children:[(0,d.jsx)(q,{asChild:!0,children:(0,d.jsx)(`button`,{onClick:()=>{t===`started`?r():n()},className:`p-2 text-muted-foreground rounded-full backdrop-blur-md bg-white/10 dark:bg-black/10 hover:bg-white/20 dark:hover:bg-black/20 transition duration-200 hover:text-foreground`,children:t===`started`?(0,d.jsx)(s.StopCircle,{size:18}):(0,d.jsx)(s.Volume2,{size:18})})}),(0,d.jsx)(J,{side:`bottom`,children:t===`started`?`Stop`:`Read aloud`})]}),(0,d.jsxs)(pt,{children:[(0,d.jsxs)(K,{children:[(0,d.jsx)(q,{asChild:!0,children:(0,d.jsx)(mt,{asChild:!0,children:(0,d.jsx)(`button`,{className:`p-2 text-muted-foreground rounded-full backdrop-blur-md bg-white/10 dark:bg-black/10 hover:bg-white/20 dark:hover:bg-black/20 transition duration-200 hover:text-foreground`,children:(0,d.jsx)(s.Download,{size:18})})})}),(0,d.jsx)(J,{side:`bottom`,children:`Export`})]}),(0,d.jsxs)(ht,{align:`end`,side:`top`,children:[(0,d.jsxs)(Y,{onClick:()=>Mt(e.userMessage.content,e.assistantMessage.content),children:[(0,d.jsx)(s.FileText,{size:16}),`Markdown`]}),(0,d.jsxs)(Y,{onClick:()=>Pt(e.userMessage.content,e.assistantMessage.content),children:[(0,d.jsx)(s.FileType,{size:16}),`PDF`]}),(0,d.jsxs)(Y,{onClick:()=>Nt(e.userMessage.content,e.assistantMessage.content),children:[(0,d.jsx)(s.FileDown,{size:16}),`DOCX`]}),(0,d.jsxs)(Y,{onClick:()=>Ft(e.userMessage.content,e.assistantMessage.content),children:[(0,d.jsx)(s.FileSpreadsheet,{size:16}),`Google Docs`]})]})]}),(0,d.jsxs)(pt,{children:[(0,d.jsxs)(K,{children:[(0,d.jsx)(q,{asChild:!0,children:(0,d.jsx)(mt,{asChild:!0,children:(0,d.jsx)(`button`,{className:`p-2 text-muted-foreground rounded-full backdrop-blur-md bg-white/10 dark:bg-black/10 hover:bg-white/20 dark:hover:bg-black/20 transition duration-200 hover:text-foreground`,children:(0,d.jsx)(s.ExternalLink,{size:18})})})}),(0,d.jsx)(J,{side:`bottom`,children:`Open in LLM`})]}),(0,d.jsxs)(ht,{align:`end`,side:`top`,children:[(0,d.jsx)(Y,{onClick:()=>i(`qwksearch`),children:`QwkSearch`}),(0,d.jsx)(Y,{onClick:()=>i(`claude`),children:`Claude`}),(0,d.jsx)(Y,{onClick:()=>i(`perplexity`),children:`Perplexity`}),(0,d.jsx)(Y,{onClick:()=>i(`gemini`),children:`Google Gemini`}),(0,d.jsx)(Y,{onClick:()=>i(`chatgpt`),children:`ChatGPT`})]})]})]})}):null,Rt=(0,x.cva)(`inline-flex items-center justify-center rounded-2xl border px-3 py-1.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden`,{variants:{variant:{default:`border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90`,secondary:`border-transparent bg-gray-100 text-gray-700 [a&]:hover:bg-gray-200 dark:bg-gray-800 dark:text-gray-300 dark:[a&]:hover:bg-gray-700`,destructive:`border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60`,outline:`text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground`,new:`text-purple-600 dark:text-purple-300 bg-purple-600/30 dark:bg-purple-600/30`,beta:`text-blue-600 dark:text-blue-300 bg-blue-600/30 dark:bg-blue-600/30`,highlight:`text-green-800 dark:text-green-300 bg-green-600/30 dark:bg-green-600/30`}},defaultVariants:{variant:`default`}});function zt({className:e,variant:t,asChild:n=!1,...r}){return(0,d.jsx)(n?b.Slot:`span`,{"data-slot":`badge`,className:F(Rt({variant:t}),e),...r})}var Bt=({section:e,isLast:t,loading:r,sendMessage:i})=>{let a=(0,n.useRef)([]);return(0,n.useEffect)(()=>{e.suggestions&&e.suggestions.length>0&&(a.current=e.suggestions.slice(0,5))},[e.suggestions]),(0,n.useEffect)(()=>{let e=e=>{let t=e.target;if(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable)return;let n=e.key,r=parseInt(n);r>=1&&r<=5&&a.current.length>=r&&(e.preventDefault(),i(a.current[r-1]))};if(t&&a.current.length>0)return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,i]),!e.suggestions||e.suggestions.length===0||!e.assistantMessage?null:(0,d.jsx)(`div`,{className:`mt-8 pt-6 border-t border-border/50`,children:(0,d.jsx)(`div`,{className:`space-y-2`,children:e.suggestions?.slice(0,5).map((e,t)=>(0,d.jsx)(`button`,{onClick:()=>i(e),className:`group w-full px-4 py-4 text-left transition-all duration-200 cursor-pointer rounded-lg border border-border/50 hover:border-primary/30 hover:bg-accent/50 hover:shadow-sm`,children:(0,d.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,d.jsx)(zt,{variant:`secondary`,className:`flex-shrink-0 h-6 w-6 p-0 flex items-center justify-center rounded-full text-sm font-semibold`,children:t+1}),(0,d.jsx)(`p`,{className:`flex-1 text-base font-medium text-muted-foreground group-hover:text-primary transition-colors duration-200 leading-relaxed`,children:e}),(0,d.jsx)(s.Plus,{size:18,className:`text-muted-foreground/60 group-hover:text-primary transition-colors duration-200 flex-shrink-0`})]})},t))})})},Vt=({section:e,dividerRef:t,isLast:r})=>{let{loading:i,sendMessage:a}=G(),[s,c]=(0,n.useState)(!0),[l,u]=(0,n.useState)(!1),[f,p]=(0,n.useState)(!1),[m,h]=(0,n.useState)(e.userMessage.content),g=()=>{navigator.clipboard.writeText(e.userMessage.content),u(!0),setTimeout(()=>u(!1),1500)},_=()=>{m.trim()&&(a(m.trim()),p(!1))},v=e.parsedAssistantMessage||``,y=e.speechMessage||``,b=e.thinkingEnded,{speechStatus:x,start:S,stop:C}=Me(y,{enableInterrupt:!0}),w=t=>{if(!e.assistantMessage)return;let n=`${e.userMessage.content}\n\n${e.assistantMessage.content}`;navigator.clipboard.writeText(n);let r={qwksearch:`https://qwksearch.com/?q=`,claude:`https://claude.ai/new?q=`,perplexity:`https://www.perplexity.ai/?q=`,gemini:`https://gemini.google.com/?q=`,chatgpt:`https://chat.openai.com/?q=`}[t];r&&window.open(`${r}${encodeURIComponent(n)}`,`_blank`)},T={overrides:{think:{component:st,props:{thinkingEnded:b}},citation:{component:at,props:{sources:e.sourceMessage?.sources||[]}},table:{component:({children:e,...t})=>(0,d.jsx)(`div`,{className:`not-prose -mx-2 my-4 max-w-full overflow-x-auto sm:mx-0`,children:(0,d.jsx)(`table`,{...t,className:`w-max min-w-full border-collapse text-sm`,children:e})})}}};return(0,d.jsxs)(`div`,{className:`space-y-3`,children:[(0,d.jsx)(ft,{section:e,isExpanded:s,setIsExpanded:c,isEditing:f,setIsEditing:p,editText:m,setEditText:h,handleEditSubmit:_,copiedUserMsg:l,handleCopyUserMsg:g}),(0,d.jsx)(`div`,{className:F(`flex flex-col space-y-3 overflow-hidden transition-all duration-300 ease-in-out`,s?`max-h-[100000px] opacity-100`:`max-h-0 opacity-0`),children:(0,d.jsxs)(`div`,{ref:t,className:`flex flex-col space-y-6 w-full`,children:[e.searchingMessage&&e.searchingMessage.queries.length>0&&(0,d.jsx)(ye,{queries:e.searchingMessage.queries,loading:i&&r}),e.sourceMessage&&e.sourceMessage.sources.length>0&&(0,d.jsx)(`div`,{className:`flex flex-col space-y-2`,children:(0,d.jsx)(ge,{sources:e.sourceMessage.sources,query:e.userMessage.content})}),(0,d.jsx)(`div`,{className:`flex min-w-0 flex-col space-y-2`,children:e.assistantMessage&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(o.default,{className:F(`prose prose-lg 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-loose prose-pre:p-0 font-[400]`,`min-w-0 max-w-none break-words text-foreground font-inter`),options:T,children:v}),i&&r?null:(0,d.jsx)(Lt,{section:e,speechStatus:x,start:S,stop:C,handleOpenInLLM:w}),(0,d.jsx)(Bt,{section:e,isLast:r,loading:i,sendMessage:a})]})})]})})]})},Ht=[`default`,`circle`,`pinwheel`,`circle-filled`,`ellipsis`,`ring`,`bars`,`infinite`],Ut=`M12 12c-2-2.67-4-4-6-4a4 4 0 1 0 0 8c2 0 4-1.33 6-4Zm0 0c2 2.67 4 4 6 4a4 4 0 0 0 0-8c-2 0-4 1.33-6 4Z`,Wt={transformBox:`view-box`,transformOrigin:`center`},Gt=[[12,2,12,6],[16.24,7.76,19.07,4.93],[18,12,22,12],[16.24,16.24,19.07,19.07],[12,18,12,22],[4.93,19.07,7.76,16.24],[2,12,6,12],[4.93,4.93,7.76,7.76]],Kt=e=>{switch(e){case`circle`:return(0,d.jsx)(`g`,{className:`animate-spin`,style:Wt,children:(0,d.jsx)(`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`})});case`pinwheel`:return(0,d.jsxs)(`g`,{className:`animate-spin`,style:Wt,children:[(0,d.jsx)(`path`,{d:`M22 12a1 1 0 0 1-10 0 1 1 0 0 0-10 0`}),(0,d.jsx)(`path`,{d:`M7 20.7a1 1 0 1 1 5-8.7 1 1 0 1 0 5-8.6`}),(0,d.jsx)(`path`,{d:`M7 3.3a1 1 0 1 1 5 8.6 1 1 0 1 0 5 8.6`}),(0,d.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`})]});case`circle-filled`:return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`,opacity:`0.2`}),(0,d.jsx)(`g`,{className:`animate-spin`,style:Wt,children:(0,d.jsx)(`path`,{d:`M21 12a9 9 0 0 0-9-9`})})]});case`ellipsis`:return(0,d.jsx)(`g`,{fill:`currentColor`,stroke:`none`,children:[4,12,20].map((e,t)=>(0,d.jsx)(`circle`,{cx:e,cy:`12`,r:`2.5`,children:(0,d.jsx)(`animate`,{attributeName:`cy`,values:`12;7.5;12`,keyTimes:`0;0.5;1`,dur:`1.2s`,begin:`${t*.16}s`,repeatCount:`indefinite`})},e))});case`ring`:return(0,d.jsx)(d.Fragment,{children:[0,-.8].map(e=>(0,d.jsxs)(`circle`,{cx:`12`,cy:`12`,r:`2`,children:[(0,d.jsx)(`animate`,{attributeName:`r`,values:`2;11`,dur:`1.6s`,begin:`${e}s`,repeatCount:`indefinite`}),(0,d.jsx)(`animate`,{attributeName:`opacity`,values:`1;0`,dur:`1.6s`,begin:`${e}s`,repeatCount:`indefinite`})]},e))});case`bars`:return(0,d.jsx)(`g`,{fill:`currentColor`,stroke:`none`,children:[2.5,10,17.5].map((e,t)=>(0,d.jsxs)(`rect`,{x:e,y:`8`,width:`4`,height:`8`,rx:`1.5`,children:[(0,d.jsx)(`animate`,{attributeName:`height`,values:`8;18;8`,keyTimes:`0;0.5;1`,dur:`1.1s`,begin:`${t*.18}s`,repeatCount:`indefinite`}),(0,d.jsx)(`animate`,{attributeName:`y`,values:`8;3;8`,keyTimes:`0;0.5;1`,dur:`1.1s`,begin:`${t*.18}s`,repeatCount:`indefinite`})]},e))});case`infinite`:return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`path`,{d:Ut,opacity:`0.2`}),(0,d.jsx)(`path`,{d:Ut,pathLength:`100`,strokeDasharray:`25 75`,children:(0,d.jsx)(`animate`,{attributeName:`stroke-dashoffset`,values:`100;0`,dur:`1.5s`,repeatCount:`indefinite`})})]});default:return(0,d.jsx)(`g`,{className:`animate-spin`,style:Wt,children:Gt.map(([e,t,n,r],i)=>(0,d.jsx)(`line`,{x1:e,y1:t,x2:n,y2:r,opacity:1-i*.1},`${e}-${t}`))})}},qt=({variant:e=`default`,size:t=24,className:n,...r})=>(0,d.jsx)(`svg`,{"aria-hidden":`true`,xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,width:t,height:t,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,className:F(`shrink-0`,n),...r,children:Kt(e)}),Jt=`quantumSphere`,Yt=`spinner:`,Xt=new Set([`loadingSpokes`,`loadingCircleNotch`,`loadingPinwheel`,`loadingCircleTrack`,`loadingDotsBounce`,`loadingPulseRing`,`loadingEqualizerBars`,`loadingInfiniteDash`]),Zt=Object.fromEntries(Object.entries(C).filter(([e,t])=>typeof t==`function`&&e.startsWith(`loading`)&&!Xt.has(e))),Qt=[Jt,...Ht.map(e=>`${Yt}${e}`),...Object.keys(Zt).sort()],$t;function en(){let e=Qt.filter(e=>e!==$t),t=e.length>0?e:Qt;return $t=t[Math.floor(Math.random()*t.length)],$t}function tn(e){if(!e.startsWith(`spinner:`))return;let t=e.slice(8);return Ht.find(e=>e===t)}function nn(e,t){let n=Zt[e];return n?n({size:t,raw:!0}):``}var rn=({size:e=140,className:t})=>{let[r,i]=(0,n.useState)(null);(0,n.useEffect)(()=>{i(en())},[]);let a=r?tn(r):void 0;return(0,d.jsx)(`div`,{role:`status`,"aria-label":`Loading`,className:F(`flex items-center justify-center w-full h-[200px]`,t),children:r===`quantumSphere`?(0,d.jsx)(S.default,{autoRandomize:!0}):a?(0,d.jsx)(qt,{variant:a,size:e,className:`text-muted-foreground`}):r?(0,d.jsx)(`div`,{className:`flex items-center justify-center`,dangerouslySetInnerHTML:{__html:nn(r,e)}}):null})},an=e=>{if(e===0)return`0 Bytes`;let t=1024,n=[`Bytes`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**r).toFixed(2))+` `+n[r]},on=({file:e,onRemove:t})=>{let n=e.type.startsWith(`image/`)&&e.preview;return(0,d.jsxs)(`div`,{className:`relative group flex-shrink-0 w-24 h-24 rounded-xl overflow-hidden border border-bg-300 bg-bg-200 animate-fade-in transition-all hover:border-text-400`,children:[n?(0,d.jsxs)(`div`,{className:`w-full h-full relative`,children:[(0,d.jsx)(`img`,{src:e.preview,alt:e.file.name,className:`w-full h-full object-cover`}),(0,d.jsx)(`div`,{className:`absolute inset-0 bg-black/20 group-hover:bg-black/0 transition-colors`}),(0,d.jsx)(`span`,{className:`absolute bottom-1 left-1 px-1.5 py-0.5 rounded-md bg-black/60 text-white text-[10px] font-medium leading-none backdrop-blur-sm pointer-events-none`,title:e.file.name,children:an(e.file.size)})]}):(0,d.jsxs)(`div`,{className:`w-full h-full p-3 flex flex-col justify-between`,children:[(0,d.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,d.jsx)(`div`,{className:`p-1.5 bg-bg-300 rounded`,children:(0,d.jsx)(Z.FileText,{className:`w-4 h-4 text-text-300`})}),(0,d.jsx)(`span`,{className:`text-[10px] font-medium text-text-400 uppercase tracking-wider truncate`,children:e.file.name.split(`.`).pop()})]}),(0,d.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,d.jsx)(`p`,{className:`text-xs font-medium text-text-200 truncate`,title:e.file.name,children:e.file.name}),(0,d.jsx)(`p`,{className:`text-[10px] text-text-500`,children:an(e.file.size)})]})]}),(0,d.jsx)(`button`,{onClick:()=>t(e.id),className:`absolute top-1 right-1 p-1 bg-black/50 hover:bg-black/70 rounded-full text-white opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,d.jsx)(Z.X,{className:`w-3 h-3`})}),e.uploadStatus===`uploading`&&(0,d.jsx)(`div`,{className:`absolute inset-0 bg-black/40 flex items-center justify-center`,children:(0,d.jsx)(Z.Loader2,{className:`w-5 h-5 text-white animate-spin`})}),e.uploadStatus===`error`&&(0,d.jsx)(`div`,{className:`absolute inset-0 bg-red-900/60 flex items-center justify-center`,children:(0,d.jsx)(Z.X,{className:`w-5 h-5 text-red-300`})})]})},sn=({content:e,onRemove:t})=>(0,d.jsxs)(`div`,{className:`relative group flex-shrink-0 w-28 h-28 rounded-2xl overflow-hidden border border-[#E5E5E5] dark:border-[#30302E] bg-white dark:bg-[#20201F] animate-fade-in p-3 flex flex-col justify-between shadow-[0_1px_2px_rgba(0,0,0,0.05)]`,children:[(0,d.jsx)(`div`,{className:`overflow-hidden w-full`,children:(0,d.jsx)(`p`,{className:`text-[10px] text-[#9CA3AF] leading-[1.4] font-mono break-words whitespace-pre-wrap line-clamp-4 select-none`,children:e.content})}),(0,d.jsx)(`div`,{className:`flex items-center justify-between w-full mt-2`,children:(0,d.jsx)(`div`,{className:`inline-flex items-center justify-center px-1.5 py-[2px] rounded border border-[#E5E5E5] dark:border-[#404040] bg-white dark:bg-transparent`,children:(0,d.jsx)(`span`,{className:`text-[9px] font-bold text-[#6B7280] dark:text-[#9CA3AF] uppercase tracking-wider font-sans`,children:`PASTED`})})}),(0,d.jsx)(`button`,{onClick:()=>t(e.id),className:`absolute top-2 right-2 p-[3px] bg-white dark:bg-[#30302E] border border-[#E5E5E5] dark:border-[#404040] rounded-full text-[#9CA3AF] hover:text-[#6B7280] dark:hover:text-white transition-colors shadow-sm opacity-0 group-hover:opacity-100`,children:(0,d.jsx)(Z.X,{className:`w-2 h-2`})})]});function cn(){return typeof window>`u`?!1:!!(window.SpeechRecognition||window.webkitSpeechRecognition)}function ln(e,t,r={}){let[i,a]=(0,n.useState)(!1),[o,s]=(0,n.useState)(``),[c,l]=(0,n.useState)(``),[u,d]=(0,n.useState)(0),f=(0,n.useRef)(null),h=(0,n.useRef)(null),g=(0,n.useRef)([]),_=(0,n.useRef)({onTranscript:e,onEnd:t,onPartial:r.onPartial});_.current={onTranscript:e,onEnd:t,onPartial:r.onPartial};let v=(0,n.useMemo)(()=>new w.LiveTranscriber({engine:`webspeech`,language:r.language??`en-US`,onStateChange:a,onPartial:e=>{s(e),e&&(l(e),d(e=>e+1)),_.current.onPartial?.(e)},onCommit:e=>{s(``),l(e),d(e=>e+1),_.current.onTranscript(e)},onError:()=>{m.toast.error(`Speech recognition stopped unexpectedly.`)}}),[r.language]),y=(0,n.useCallback)(()=>{let e=f.current;if(e&&e.state!==`inactive`){e.stop();return}h.current?.getTracks().forEach(e=>e.stop()),h.current=null,f.current=null},[]),b=async e=>{let t=new FormData;return t.append(`file`,e,`speech-input.webm`),t.append(`languageCode`,`en`),((await(0,p.default)(`agent/transcript`,{method:`POST`,body:t}))?.text??``).trim()},x=(0,n.useCallback)(async()=>{if(typeof navigator>`u`||!navigator.mediaDevices?.getUserMedia||typeof MediaRecorder>`u`){m.toast.error(`Speech input is not supported in this browser`,{duration:5e3}),a(!1),_.current.onEnd();return}try{let e=await navigator.mediaDevices.getUserMedia({audio:!0}),t=new MediaRecorder(e);g.current=[],h.current=e,f.current=t,t.ondataavailable=e=>{e.data.size>0&&g.current.push(e.data)},t.onstart=()=>{a(!0)},t.onstop=async()=>{try{let e=new Blob(g.current,{type:`audio/webm`});if(g.current=[],h.current?.getTracks().forEach(e=>e.stop()),h.current=null,f.current=null,a(!1),e.size===0)return;let t=await b(e);t?(l(t),d(e=>e+1),_.current.onTranscript(t)):m.toast.error(`No speech detected. Please try again.`)}catch{m.toast.error(`Unable to transcribe audio.`)}finally{_.current.onEnd()}},t.start()}catch{m.toast.error(`Microphone access is required for speech input.`),a(!1),_.current.onEnd()}},[]),S=(0,n.useCallback)(async()=>{if(v.isListening()){await v.stop(),s(``),_.current.onEnd();return}if(f.current){y();return}if(cn()){await v.start();return}await x()},[v,x,y]);(0,n.useEffect)(()=>{let e=e=>{e.ctrlKey&&e.key==="`"&&(e.preventDefault(),S())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[S]),(0,n.useEffect)(()=>()=>{v.stop(),y()},[v,y]);let C=typeof navigator<`u`&&!!navigator.mediaDevices?.getUserMedia&&typeof MediaRecorder<`u`;return{isListening:i,toggleSpeech:S,isSpeechSupported:cn()||C,partial:o,lastPhrase:c,phraseId:u}}var un=`voiceAutoStart`,dn=`voiceAutoStartTriggered`,fn=typeof window<`u`;function pn(){return fn?localStorage.getItem(un)===`true`:!1}function mn(e){fn&&localStorage.setItem(un,String(e))}function hn(){fn&&localStorage.setItem(dn,`true`)}function gn({enabled:e,isSpeechSupported:t,isListening:n},r){return e&&t&&!n&&!r}function _n(){return fn?localStorage.getItem(dn)===`true`:!1}function vn({isSpeechSupported:e,isListening:t,toggleSpeech:r}){(0,n.useEffect)(()=>{gn({enabled:pn(),isSpeechSupported:e,isListening:t},_n())&&(hn(),r())},[e])}var yn=[`pdf`,`docx`,`txt`,`md`,`html`,`htm`],bn=[`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`avif`],xn=[...yn,...bn],Sn=10,Cn=52428800,wn=(e,t)=>{if(e&&typeof e==`object`){let t=e.message??e.error??e.data?.message;if(typeof t==`string`&&t.length>0)return t}return typeof e==`string`&&e.length>0?e:t};function Tn({setMessage:e,contextFiles:t,contextFileIds:r,setContextFiles:i,setContextFileIds:a}){let[o,s]=(0,n.useState)([]),[l,u]=(0,n.useState)([]),[d,f]=(0,n.useState)(!1),[p,h]=(0,n.useState)(!1),g=(0,n.useCallback)(async e=>{let n=Array.from(e);n.length>Sn&&(m.toast.error(`You can attach up to ${Sn} files at a time.`),n=n.slice(0,Sn));let o=n.filter(e=>e.size>Cn);if(o.length>0&&(m.toast.error(`${o.map(e=>e.name).join(`, `)} exceed${o.length===1?`s`:``} the 50 MB per-file limit.`),n=n.filter(e=>e.size<=Cn)),n.length===0)return;let l=n.map(e=>{let t=e.type.startsWith(`image/`)||/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(e.name),n=e.name.split(`.`).pop()?.toLowerCase()??``,r=xn.includes(n);return{id:Math.random().toString(36).substr(2,9),file:e,type:t?`image/unknown`:e.type||`application/octet-stream`,preview:t?URL.createObjectURL(e):null,uploadStatus:r?`uploading`:`pending`,_ext:n}});s(e=>[...e,...l]),l.filter(e=>!xn.includes(e._ext)).forEach(e=>{setTimeout(()=>{s(t=>t.map(t=>t.id===e.id?{...t,uploadStatus:`complete`}:t))},600+Math.random()*600)});let u=l.filter(e=>xn.includes(e._ext));if(u.length!==0)try{let{data:e,error:n}=await(0,c.uploadFiles)({body:{files:u.map(e=>e.file)}});if(n||!e?.files)throw Error(wn(n??e,`Upload failed.`));s(e=>e.map(e=>u.some(t=>t.id===e.id)?{...e,uploadStatus:`complete`}:e)),i([...t,...e.files]),a([...r,...e.files.map(e=>e.fileId)])}catch(e){m.toast.error(wn(e,`Failed to upload files.`)),s(e=>e.map(e=>u.some(t=>t.id===e.id)?{...e,uploadStatus:`error`}:e))}},[e,t,r,i,a]);return{files:o,setFiles:s,pastedContent:l,setPastedContent:u,isDragging:d,isExtractingUrl:p,handleFiles:g,extractUrl:(0,n.useCallback)(async e=>{let n=e.trim();if(!/^https?:\/\//i.test(n))return m.toast.error(`Enter a valid http(s) URL.`),!1;h(!0);try{let e=await(await fetch(`/api/doc/uploads`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({url:n})})).json();if(!e?.files||e.files.length===0)throw Error(wn(e,`Could not extract content from ${n}`));return i([...t,...e.files]),a([...r,...e.files.map(e=>e.fileId)]),m.toast.success(`Added "${e.files[0].fileName}" as context.`),!0}catch(e){return m.toast.error(wn(e,`Failed to extract URL.`)),!1}finally{h(!1)}},[t,r,i,a]),onDragOver:e=>{e.preventDefault(),f(!0)},onDragLeave:e=>{e.preventDefault(),f(!1)},onDrop:e=>{e.preventDefault(),f(!1),e.dataTransfer.files&&g(e.dataTransfer.files)},handlePaste:e=>{let t=e.clipboardData.items,n=[];for(let e=0;e<t.length;e++)if(t[e].kind===`file`){let r=t[e].getAsFile();r&&n.push(r)}if(n.length>0){e.preventDefault(),g(n);return}let r=e.clipboardData.getData(`text`);if(r.length>300){e.preventDefault();let t={id:Math.random().toString(36).substr(2,9),content:r,timestamp:new Date};u(e=>[...e,t])}},resetAttachments:()=>{s([]),u([]),i([]),a([])}}}var En=()=>window.gapi,Dn=()=>window.google,On=()=>{let e=(0,n.useRef)(!1),r=(0,n.useRef)(!1);return(0,n.useEffect)(()=>{En()?r.current=!0:(()=>{let e=document.createElement(`script`);e.src=`https://apis.google.com/js/api.js`,e.onload=()=>{En()?.load(`client:picker`,()=>{r.current=!0})},document.body.appendChild(e)})(),Dn()?.picker?e.current=!0:(()=>{let t=document.createElement(`script`);t.src=`https://www.google.com/jsapi`,t.onload=()=>{e.current=!0},document.body.appendChild(t)})()},[]),{openPicker:async(e,n,i)=>{let a=Dn();if(!r.current||!a?.picker){i?.(`Google Picker API not loaded yet. Please try again.`);return}try{let{picker:r}=a,i=new r.PickerBuilder().addView(r.ViewId.DOCS).addView(r.ViewId.DOCS_IMAGES).addView(r.ViewId.DOCS_VIDEOS).addView(new r.DocsView().setIncludeFolders(!0).setMimeTypes(`application/pdf,application/vnd.google-apps.document,application/vnd.google-apps.spreadsheet,text/plain,image/jpeg,image/png`)).setOAuthToken(e).setDeveloperKey(t.researchAgentUIConfig.googleApiKey);t.researchAgentUIConfig.googleAppId&&i.setAppId(t.researchAgentUIConfig.googleAppId),i.setCallback(e=>{if(e.action===r.Action.PICKED){let t=e.docs;t&&n(t)}else e.action===r.Action.CANCEL&&console.log(`User cancelled picker`)}).build().setVisible(!0)}catch(e){i?.(e.message||`Failed to open Google Picker`)}}}},kn=()=>{let{chatModelProvider:e,setChatModelProvider:t}=G(),[i,a]=(0,n.useState)([]),[o,l]=(0,n.useState)(!0),u=(0,r.useRouter)();(0,n.useEffect)(()=>{(async()=>{try{l(!0);let{data:n}=await(0,c.listProviders)(),r=n?.providers??[];if(a(r),!e.key&&r.length>0){let e=localStorage.getItem(`chatModelKey`),n=localStorage.getItem(`chatModelProviderId`);if(e&&n)t({key:e,providerId:n});else{let e=r.find(e=>e.chatModels.length>0);e&&t({key:e.chatModels[0].key,providerId:e.id})}}}catch(e){console.error(`Error loading providers:`,e)}finally{l(!1)}})()},[]);let f=(0,n.useMemo)(()=>{if(!e.key)return`Select`;for(let t of i){let n=t.chatModels.find(t=>t.key===e.key);if(n)return n.name}return e.key},[i,e.key]),p=(e,n)=>{t({providerId:e,key:n}),localStorage.setItem(`chatModelProviderId`,e),localStorage.setItem(`chatModelKey`,n)};return(0,d.jsxs)(vt,{children:[(0,d.jsxs)(yt,{className:`gap-2`,children:[(0,d.jsx)(s.Cpu,{className:`w-4 h-4 flex-shrink-0 text-sky-500`}),(0,d.jsx)(`span`,{children:`Model`}),(0,d.jsx)(`span`,{className:`ml-auto text-xs text-muted-foreground truncate max-w-[55px]`,children:f})]}),(0,d.jsxs)(bt,{className:`w-52 max-h-[400px] overflow-y-auto`,children:[o?(0,d.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,d.jsx)(s.Loader2,{className:`h-4 w-4 animate-spin text-muted-foreground`})}):i.length===0?(0,d.jsx)(`div`,{className:`px-3 py-2 text-xs text-muted-foreground`,children:`No models configured`}):i.map((t,n)=>(0,d.jsxs)(`div`,{children:[(0,d.jsx)(_t,{className:`text-[10px] uppercase tracking-wider text-muted-foreground font-medium`,children:t.name}),t.chatModels.map(n=>(0,d.jsxs)(Y,{onSelect:()=>p(t.id,n.key),className:F(`gap-2`,e?.providerId===t.id&&e?.key===n.key&&`bg-secondary`),children:[(0,d.jsx)(s.Cpu,{className:F(`h-3.5 w-3.5 flex-shrink-0`,e?.providerId===t.id&&e?.key===n.key?`text-sky-500`:`text-muted-foreground`)}),(0,d.jsx)(`span`,{className:`truncate`,children:n.name}),e?.providerId===t.id&&e?.key===n.key&&(0,d.jsx)(`svg`,{className:`w-3 h-3 text-primary ml-auto shrink-0`,fill:`none`,viewBox:`0 0 10 10`,children:(0,d.jsx)(`path`,{d:`M1.5 5l2.5 2.5 4.5-4.5`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`})})]},n.key)),n<i.length-1&&(0,d.jsx)(X,{})]},t.id)),(0,d.jsx)(X,{}),(0,d.jsxs)(Y,{onSelect:()=>u.push(`/settings?section=models`),className:`gap-2`,children:[(0,d.jsx)(s.Plus,{className:`h-3.5 w-3.5 text-sky-500 flex-shrink-0`}),(0,d.jsx)(`span`,{children:`Add model`})]})]})]})};function An(e){let t=e.messages?.[e.messages.length-1],n=t&&`createdAt`in t?t.createdAt:void 0;if(n){let e=new Date(n).getTime();if(!Number.isNaN(e))return new Date(e).toISOString()}return e.createdAt}var jn=e=>new Date(e.lastMessageAt||e.createdAt).getTime();function Mn(){return Ie().map(e=>({...e,messageCount:e.messages?.filter(e=>e.role===`user`).length??0,lastMessageAt:An(e)}))}function Nn(e=10){let[t,r]=(0,n.useState)([]),[i,a]=(0,n.useState)(!1),{isAuthenticated:o,isLoading:s}=nt(),l=(0,n.useRef)(!1),u=(0,n.useCallback)(async(e=!1)=>{if(!s&&(!l.current||e)){l.current=!0,a(!0);try{if(o){let{data:e,error:t}=await(0,c.listChats)();if(t){r(Mn());return}r(Array.isArray(e?.chats)?e.chats:[])}else r(Mn())}catch(e){console.error(`Failed to fetch recent chats:`,e),r([])}finally{a(!1)}}},[o,s]);return{recentChats:[...t].sort((e,t)=>jn(t)-jn(e)).slice(0,e),loading:i,load:u}}function Pn(e){let t=new Date(e).getTime();if(Number.isNaN(t))return``;let n=Math.round((Date.now()-t)/1e3);if(n<5)return`just now`;if(n<60)return`${n} sec`;let r=Math.round(n/60);if(r<60)return`${r} min`;let i=Math.round(r/60);if(i<24)return`${i} hr`;let a=Math.round(i/24);if(a<7)return`${a} day${a===1?``:`s`}`;let o=Math.round(a/7);if(o<5)return`${o} week${o===1?``:`s`}`;let s=Math.round(a/30);if(s<12)return`${s} month${s===1?``:`s`}`;let c=Math.round(a/365);return`${c} year${c===1?``:`s`}`}var Fn=10,In=()=>{let e=(0,r.useRouter)(),{incognito:n,setIncognito:i}=G(),{recentChats:a,loading:o,load:c}=Nn(Fn),l=e=>{i(e),m.toast.success(e?`Private mode on — messages won't be saved`:`Private mode off`)},u=n=>{t.researchAgentUIConfig.onOpenChat?.(n)||e.push(`/c/${n}`)};return(0,d.jsxs)(vt,{onOpenChange:e=>{e&&c()},children:[(0,d.jsxs)(yt,{className:`gap-2`,children:[(0,d.jsx)(s.History,{className:`w-4 h-4 flex-shrink-0 text-muted-foreground`}),(0,d.jsx)(`span`,{children:`History`})]}),(0,d.jsxs)(bt,{className:`w-64 max-h-[70vh] overflow-y-auto`,children:[(0,d.jsxs)(gt,{checked:n,onCheckedChange:l,onSelect:e=>e.preventDefault(),className:`gap-2`,children:[(0,d.jsx)(s.EyeOff,{className:`w-4 h-4 flex-shrink-0 text-muted-foreground`}),(0,d.jsx)(`span`,{children:`Private`})]}),(0,d.jsx)(X,{}),o?(0,d.jsxs)(Y,{disabled:!0,className:`gap-2`,children:[(0,d.jsx)(s.Loader2,{className:`w-3.5 h-3.5 animate-spin flex-shrink-0`}),(0,d.jsx)(`span`,{children:`Loading…`})]}):a.length===0?(0,d.jsx)(Y,{disabled:!0,children:(0,d.jsx)(`span`,{className:`text-muted-foreground`,children:`No recent chats`})}):a.map(e=>{let t=Pn(e.lastMessageAt||e.createdAt);return(0,d.jsxs)(Y,{onSelect:()=>u(e.id),className:`gap-2`,title:e.title,children:[(0,d.jsx)(`span`,{className:`truncate`,children:e.title}),t&&(0,d.jsx)(`span`,{className:`ml-auto pl-2 text-xs italic text-muted-foreground/70 whitespace-nowrap`,children:t})]},e.id)}),(0,d.jsx)(X,{}),(0,d.jsxs)(Y,{onSelect:()=>e.push(`/library`),className:`gap-2`,children:[(0,d.jsx)(s.History,{className:`w-4 h-4 flex-shrink-0 text-muted-foreground`}),(0,d.jsx)(`span`,{children:`All history`})]})]})]})},Ln=[{label:`5s`,value:5},{label:`15s`,value:15},{label:`30s`,value:30},{label:`45s`,value:45},{label:`60s`,value:60},{label:`Unlimited`,value:0}],Rn=[`pdf`,`docx`,`txt`,`md`,`html`,`htm`],zn=`markdown.js.jsx.ts.tsx.py.rb.go.rs.java.c.cpp.h.hpp.cs.swift.kt.sh.bash.zsh.json.yaml.yml.toml.ini.cfg.conf.xml.csv.tsv.log.env.sql.graphql.vue.svelte.astro.css.scss.less.sass.tex.bib.rst.adoc.org`.split(`.`),Bn=({onFileSelect:e,disabled:i=!1})=>{let a=(0,r.useRouter)(),{category:o,setCategory:l,sections:u,chatId:f}=G(),{isAuthenticated:p}=nt(),h=o?o.split(`,`).filter(Boolean):[`general`],g=H.find(e=>e.code===h[0])||H[0],_=e=>{let t=o?o.split(`,`).filter(Boolean):[`general`],n=t.includes(e)?t.filter(t=>t!==e):[...t,e];l(n.length>0?n.join(`,`):`general`)},[v,y]=(0,n.useState)(!1),[b,x]=(0,n.useState)(!1),[S,C]=(0,n.useState)(!1),[w,T]=(0,n.useState)(!1),[E,D]=(0,n.useState)(()=>{if(typeof window>`u`)return 5;let e=Number(localStorage.getItem(`thinkingTimeLimit`)??`5`);return Number.isFinite(e)?e:5}),O=n.default.useRef(null),{openPicker:k}=On();(0,n.useEffect)(()=>{A()},[]);let A=async()=>{try{let{data:e}=await(0,c.googleDocsAuthStatus)();y(e?.isConnected||!1)}catch{}},j=e=>{D(e),localStorage.setItem(`thinkingTimeLimit`,String(e))},M=async()=>{if(`showOpenFilePicker`in window)try{let t=await window.showOpenFilePicker({multiple:!0,types:[{description:`Supported files`,accept:{"application/pdf":[`.pdf`],"application/vnd.openxmlformats-officedocument.wordprocessingml.document":[`.docx`],"text/plain":[`.txt`],"text/markdown":[`.md`],"text/html":[`.html`,`.htm`],"image/*":[`.jpg`,`.jpeg`,`.png`,`.gif`,`.webp`,`.svg`]}}]}),n=await Promise.all(t.map(e=>e.getFile()));n.length>0&&e(n)}catch(e){e?.name!==`AbortError`&&(console.error(`Failed to open file picker:`,e),O.current?.click())}else O.current?.click()};async function N(e,t=``){let n=[];for await(let r of e.values())if(r.kind===`file`){let e=await r.getFile(),i=e.name.split(`.`).pop()?.toLowerCase()??``;if(Rn.includes(i))n.push(e);else if(zn.includes(i))try{let r=await e.text(),i=t?`${t}/${e.name}`:e.name;n.push(new File([r],`${i.replace(/[/\\]/g,`_`)}.txt`,{type:`text/plain`}))}catch{}}else if(r.kind===`directory`){let e=r;if(e.name.startsWith(`.`)||e.name===`node_modules`||e.name===`__pycache__`)continue;n.push(...await N(e,t?`${t}/${e.name}`:e.name))}return n}let P=async()=>{if(!(`showDirectoryPicker`in window)){alert(`Your browser does not support the File System Access API. Please use Chrome or Edge.`);return}T(!0);try{let t=await N(await window.showDirectoryPicker({mode:`read`}));t.length>0?e(t):alert(`No supported files found in the selected folder.`)}catch(e){e?.name!==`AbortError`&&console.error(`Failed to access folder:`,e)}finally{T(!1)}},I=async()=>{x(!0);try{let{data:e}=await(0,c.googleDocsAuth)();if(e?.success&&e?.data?.authUrl){let t=e.data.authUrl,n=window.screenX+(window.outerWidth-600)/2,r=window.screenY+(window.outerHeight-700)/2,i=window.open(t,`Google Drive Authorization`,`width=600,height=700,left=${n},top=${r}`),a=e=>{e.data.type===`google-drive-connected`&&(y(!0),i?.close(),window.removeEventListener(`message`,a))};window.addEventListener(`message`,a)}}catch{console.error(`Failed to connect to Google Drive`)}finally{x(!1)}},L=async()=>{try{let{data:t}=await(0,c.getGoogleToken)();if(!t?.success||!t.accessToken)throw Error(`Failed to get access token`);await k(t.accessToken,async t=>{C(!0);try{let n=[];for(let e of t){let{data:t}=await(0,c.getGoogleDriveFile)({query:{fileId:e.id}});if(t?.success&&t?.file){let e=atob(t.file.content),r=new Uint8Array(e.length);for(let t=0;t<e.length;t++)r[t]=e.charCodeAt(t);n.push(new File([new Blob([r],{type:t.file.mimeType})],t.file.name,{type:t.file.mimeType}))}}n.length>0&&e(n)}catch{alert(`Failed to load files from Google Drive`)}finally{C(!1)}},e=>{console.error(`Google Picker error:`,e),alert(e)})}catch(e){alert(e.message||`Failed to open Google Drive picker`)}},R=Ln.find(e=>e.value===E)?.label??`Unlimited`;return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(`div`,{className:`relative flex shrink min-w-8 !shrink-0 group`,children:[(0,d.jsxs)(pt,{children:[(0,d.jsx)(mt,{asChild:!0,children:(0,d.jsx)(`button`,{disabled:i,className:`inline-flex items-center justify-center relative shrink-0 transition-colors duration-200 h-8 w-8 rounded-lg active:scale-95 text-text-400 hover:text-text-200 hover:bg-bg-200 disabled:opacity-50 disabled:cursor-not-allowed group-active:scale-95`,type:`button`,"aria-label":`Search options`,children:(0,d.jsx)(s.SlidersHorizontal,{className:`w-5 h-5`})})}),(0,d.jsxs)(ht,{align:`start`,side:`top`,sideOffset:8,className:`w-44`,children:[(0,d.jsxs)(vt,{children:[(0,d.jsxs)(yt,{className:`gap-2`,children:[g&&(0,d.jsx)(g.icon,{className:`w-4 h-4 flex-shrink-0`}),(0,d.jsx)(`span`,{children:`Category`})]}),(0,d.jsxs)(bt,{className:`w-44`,children:[(0,d.jsxs)(gt,{checked:h.length===0,onCheckedChange:()=>l(`general`),onSelect:e=>e.preventDefault(),className:`gap-2`,children:[(0,d.jsx)(`div`,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,d.jsx)(`span`,{children:`None`})]}),(0,d.jsx)(X,{}),H.map(e=>(0,d.jsxs)(gt,{checked:h.includes(e.code),onCheckedChange:()=>_(e.code),onSelect:e=>e.preventDefault(),className:`gap-2`,children:[e.icon&&(0,d.jsx)(e.icon,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,d.jsx)(`span`,{children:e.name})]},e.code))]})]}),(0,d.jsxs)(vt,{children:[(0,d.jsxs)(yt,{className:`gap-2`,children:[(0,d.jsx)(s.Clock,{className:`w-4 h-4 flex-shrink-0 text-muted-foreground`}),(0,d.jsx)(`span`,{children:`Speed`}),(0,d.jsx)(`span`,{className:`ml-auto text-xs text-muted-foreground`,children:R})]}),(0,d.jsx)(bt,{className:`w-36`,children:Ln.map(e=>(0,d.jsxs)(Y,{onSelect:()=>j(e.value),className:F(`justify-between`,E===e.value&&`bg-secondary`),children:[(0,d.jsx)(`span`,{children:e.label}),E===e.value&&(0,d.jsx)(`svg`,{className:`w-3 h-3 text-primary`,fill:`none`,viewBox:`0 0 10 10`,children:(0,d.jsx)(`path`,{d:`M1.5 5l2.5 2.5 4.5-4.5`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`})})]},e.value))})]}),(0,d.jsx)(X,{}),(0,d.jsx)(kn,{}),(0,d.jsx)(X,{}),(0,d.jsxs)(vt,{children:[(0,d.jsxs)(yt,{className:`gap-2`,children:[(0,d.jsx)(s.Upload,{className:`w-4 h-4 flex-shrink-0 text-muted-foreground`}),(0,d.jsx)(`span`,{children:`Upload`})]}),(0,d.jsxs)(bt,{className:`w-44`,children:[(0,d.jsxs)(Y,{onSelect:M,className:`gap-2`,children:[(0,d.jsx)(s.Upload,{className:`h-3.5 w-3.5 flex-shrink-0`}),(0,d.jsx)(`span`,{children:`Your Device`})]}),(0,d.jsxs)(Y,{onSelect:P,disabled:w,className:`gap-2`,children:[w?(0,d.jsx)(s.Loader2,{className:`h-3.5 w-3.5 animate-spin flex-shrink-0`}):(0,d.jsx)(s.FolderOpen,{className:`h-3.5 w-3.5 flex-shrink-0`}),(0,d.jsx)(`span`,{children:w?`Scanning…`:`Local Folder`})]}),(0,d.jsx)(X,{}),(0,d.jsx)(_t,{className:`text-xs font-normal text-muted-foreground`,children:`Cloud`}),v?(0,d.jsxs)(Y,{onSelect:L,disabled:S,className:`gap-2`,children:[S?(0,d.jsx)(s.Loader2,{className:`h-3.5 w-3.5 animate-spin flex-shrink-0`}):(0,d.jsx)(s.CloudIcon,{className:`h-3.5 w-3.5 flex-shrink-0`}),(0,d.jsx)(`span`,{children:S?`Loading…`:`Google Drive`})]}):(0,d.jsxs)(Y,{onSelect:I,disabled:b,className:`gap-2`,children:[b?(0,d.jsx)(s.Loader2,{className:`h-3.5 w-3.5 animate-spin flex-shrink-0`}):(0,d.jsx)(s.CloudIcon,{className:`h-3.5 w-3.5 flex-shrink-0`}),(0,d.jsx)(`span`,{children:b?`Connecting…`:`Connect Google Drive`})]})]})]}),(0,d.jsx)(X,{}),u.length>0&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(vt,{children:[(0,d.jsxs)(yt,{className:`gap-2`,children:[(0,d.jsx)(s.Share2,{className:`w-4 h-4 flex-shrink-0 text-muted-foreground`}),(0,d.jsx)(`span`,{children:`Share`})]}),(0,d.jsxs)(bt,{className:`w-48`,children:[(0,d.jsxs)(Y,{onSelect:async()=>{if(!f){m.toast.error(`No chat to share`);return}if(!p){m.toast.error(`Please sign in to share chats`);return}try{let{data:e,error:t}=await(0,c.shareChat)({body:{chatId:f}});if(!t&&e?.success&&e?.data?.shareUrl)await navigator.clipboard.writeText(e.data.shareUrl),m.toast.success(`Chat is now public - link copied to clipboard`);else throw Error(t?.error||`Failed to share chat`)}catch(e){console.error(`Error sharing chat:`,e);let t=e instanceof Error?e.message:`Failed to share chat`;m.toast.error(t)}},className:`gap-2`,children:[(0,d.jsx)(s.Link,{className:`w-4 h-4 flex-shrink-0`}),(0,d.jsx)(`span`,{children:`Copy link`})]}),(0,d.jsxs)(Y,{onSelect:async()=>{let e=u[0]?.userMessage?.content||`Chat`,t=u.map(e=>`## ${e.userMessage.content}\n\n${e.assistantMessage?.content||``}`).join(`
21
21
 
22
22
  ---
23
23
 
@@ -25,12 +25,12 @@ const e=require("./rolldown-runtime-BocRIvOZ.cjs"),t=require("./config.cjs");let
25
25
  `))},className:`gap-2`,children:[(0,d.jsx)(s.FileText,{className:`w-4 h-4 flex-shrink-0`}),(0,d.jsx)(`span`,{children:`Export as Markdown`})]}),(0,d.jsxs)(Y,{onSelect:()=>{Pt(u[0]?.userMessage?.content||`Chat`,u.map(e=>`<h2>${e.userMessage.content}</h2>${e.assistantMessage?.content||``}`).join(`
26
26
  `))},className:`gap-2`,children:[(0,d.jsx)(s.FileType,{className:`w-4 h-4 flex-shrink-0`}),(0,d.jsx)(`span`,{children:`Export as PDF`})]}),(0,d.jsxs)(Y,{onSelect:()=>{Nt(u[0]?.userMessage?.content||`Chat`,u.map(e=>`<h2>${e.userMessage.content}</h2>${e.assistantMessage?.content||``}`).join(`
27
27
  `))},className:`gap-2`,children:[(0,d.jsx)(s.FileDown,{className:`w-4 h-4 flex-shrink-0`}),(0,d.jsx)(`span`,{children:`Export as DOCX`})]}),(0,d.jsxs)(Y,{onSelect:()=>{Ft(u[0]?.userMessage?.content||`Chat`,u.map(e=>`<h2>${e.userMessage.content}</h2>${e.assistantMessage?.content||``}`).join(`
28
- `))},className:`gap-2`,children:[(0,d.jsx)(s.FileSpreadsheet,{className:`w-4 h-4 flex-shrink-0`}),(0,d.jsx)(`span`,{children:`Export to Google Docs`})]})]})]}),(0,d.jsx)(X,{})]}),(0,d.jsx)(Dn,{}),(0,d.jsxs)(Y,{onSelect:()=>{t.researchAgentUIConfig.onOpenSettings?.()||a.push(`/settings`)},className:`gap-2`,children:[(0,d.jsx)(s.Settings,{className:`w-4 h-4 flex-shrink-0 text-muted-foreground`}),(0,d.jsx)(`span`,{children:`Settings`})]})]})]}),(0,d.jsx)(`div`,{className:`absolute bottom-full left-1/2 -translate-x-1/2 mb-2 px-2 py-1 bg-[#1F1E1D] dark:bg-[#EEEEEC] text-[11px] font-medium rounded-[6px] opacity-0 group-hover:opacity-100 transition-opacity whitespace-nowrap pointer-events-none z-50 shadow-sm tracking-wide`,children:(0,d.jsx)(`span`,{className:`text-[#ECECEC] dark:text-[#1F1E1D]`,children:`Search options`})})]}),(0,d.jsxs)(`div`,{className:`relative hidden sm:flex shrink-0 group -ml-1`,children:[(0,d.jsx)(`button`,{type:`button`,disabled:i,onClick:M,"aria-label":`Attach files`,className:`inline-flex items-center justify-center relative shrink-0 transition-colors duration-200 h-7 w-7 rounded-md active:scale-95 text-text-400 hover:text-text-200 hover:bg-bg-200 disabled:opacity-50 disabled:cursor-not-allowed group-active:scale-95`,children:(0,d.jsx)(s.Paperclip,{className:`w-[18px] h-[18px]`})}),(0,d.jsx)(`div`,{className:`absolute bottom-full left-1/2 -translate-x-1/2 mb-2 px-2 py-1 bg-[#1F1E1D] dark:bg-[#EEEEEC] text-[11px] font-medium rounded-[6px] opacity-0 group-hover:opacity-100 transition-opacity whitespace-nowrap pointer-events-none z-50 shadow-sm tracking-wide`,children:(0,d.jsx)(`span`,{className:`text-[#ECECEC] dark:text-[#1F1E1D]`,children:`Attach files`})})]}),(0,d.jsx)(`input`,{ref:O,type:`file`,multiple:!0,onChange:t=>{t.target.files&&(e(t.target.files),t.target.value=``)},className:`hidden`})]})},Mn=(0,n.forwardRef)(({active:e=!1,processing:t=!1,barWidth:r=3,barHeight:i=4,barGap:a=1,barRadius:o=1.5,barColor:s,fadeEdges:c=!0,fadeWidth:l=24,height:u=64,sensitivity:f=1,smoothingTimeConstant:p=.8,fftSize:m=256,historySize:h=60,updateRate:g=30,mode:_=`static`,onError:v,onStreamReady:y,onStreamEnd:b,className:x,...S},C)=>{let w=(0,n.useRef)(null),T=(0,n.useRef)(null),E=(0,n.useRef)(null),D=(0,n.useRef)(null),O=(0,n.useRef)(null),k=(0,n.useRef)(0),A=(0,n.useRef)([]),j=(0,n.useRef)(0),M=(0,n.useRef)(0),N=(0,n.useCallback)(()=>{k.current&&=(cancelAnimationFrame(k.current),0),O.current&&=(O.current.disconnect(),null),D.current&&=(D.current.getTracks().forEach(e=>e.stop()),null),T.current&&=(T.current.close().catch(()=>{}),null),E.current=null,A.current=[],b?.()},[b]),P=(0,n.useCallback)((e,t,n,s,c)=>{let l=r+a,u=Math.floor(t/c/l),d=u*l-a,p=(t/c-d)/2,m=s.length;for(let t=0;t<u;t++){let a=s[Math.floor(t/u*m)]/255*f,d=Math.max(i,n/c*a),h=p+t*l,g=(n/c-d)/2;e.beginPath(),e.roundRect(h*c,g*c,r*c,d*c,o*c),e.fill()}},[r,a,i,o,f]),F=(0,n.useCallback)((e,t,n,s)=>{let c=A.current,l=r+a,u=Math.min(c.length,h),d=t/s-u*l;for(let t=0;t<u;t++){let a=c[c.length-u+t]*f,p=Math.max(i,n/s*a),m=d+t*l,h=(n/s-p)/2;e.beginPath(),e.roundRect(m*s,h*s,r*s,p*s,o*s),e.fill()}},[r,a,i,o,f,h]),I=(0,n.useCallback)((e,t,n,s,c)=>{let l=r+a,u=Math.floor(t/s/l),d=u*l-a,f=(t/s-d)/2;for(let t=0;t<u;t++){let a=Math.sin(t/u*Math.PI*2+c)*.5+.5,d=Math.max(i,n/s*a*.6),p=f+t*l,m=(n/s-d)/2;e.beginPath(),e.roundRect(p*s,m*s,r*s,d*s,o*s),e.fill()}},[r,a,i,o]),L=(0,n.useCallback)((e,t,n)=>{if(!c)return;e.save(),e.globalCompositeOperation=`destination-in`;let r=e.createLinearGradient(0,0,t,0);r.addColorStop(0,`rgba(0,0,0,0)`),r.addColorStop(Math.min(l/(t||1),.3),`rgba(0,0,0,1)`),r.addColorStop(Math.max(1-l/(t||1),.7),`rgba(0,0,0,1)`),r.addColorStop(1,`rgba(0,0,0,0)`),e.fillStyle=r,e.fillRect(0,0,t,n),e.restore()},[c,l]);(0,n.useEffect)(()=>{if(!e&&!t){let e=w.current;if(e){let t=e.getContext(`2d`);t&&t.clearRect(0,0,e.width,e.height)}return}let n=!0,r=i=>{if(!n)return;let a=w.current;if(!a){k.current=requestAnimationFrame(r);return}if(i-M.current<g){k.current=requestAnimationFrame(r);return}M.current=i;let o=window.devicePixelRatio||1,c=a.getBoundingClientRect(),l=c.width*o,u=c.height*o;(a.width!==l||a.height!==u)&&(a.width=l,a.height=u);let d=a.getContext(`2d`);if(!d){k.current=requestAnimationFrame(r);return}if(d.clearRect(0,0,l,u),d.fillStyle=s||getComputedStyle(a).getPropertyValue(`color`)||`#888`,d.save(),d.setTransform(1,0,0,1,0,0),t&&!e)j.current+=.06,I(d,l,u,o,j.current);else if(e&&E.current){let e=new Uint8Array(E.current.frequencyBinCount);if(E.current.getByteFrequencyData(e),_===`scrolling`){let t=0;for(let n=0;n<e.length;n++)t+=e[n];let n=t/e.length/255;A.current.push(n),A.current.length>h*2&&(A.current=A.current.slice(-h)),F(d,l,u,o)}else P(d,l,u,e,o)}L(d,l,u),d.restore(),k.current=requestAnimationFrame(r)};return k.current=requestAnimationFrame(r),()=>{n=!1,k.current&&=(cancelAnimationFrame(k.current),0)}},[e,t,_,s,g,h,P,F,I,L]),(0,n.useEffect)(()=>{if(!e){N();return}let t=!1;return(async()=>{try{let e=await navigator.mediaDevices.getUserMedia({audio:!0});if(t){e.getTracks().forEach(e=>e.stop());return}let n=new AudioContext,r=n.createAnalyser();r.fftSize=m,r.smoothingTimeConstant=p;let i=n.createMediaStreamSource(e);i.connect(r),T.current=n,E.current=r,D.current=e,O.current=i,y?.(e)}catch(e){t||v?.(e instanceof Error?e:Error(String(e)))}})(),()=>{t=!0,N()}},[e,m,p,N,v,y]);let R=typeof u==`number`?`${u}px`:u;return(0,d.jsx)(`div`,{ref:C,className:x,style:{height:R,width:`100%`,position:`relative`},...S,children:(0,d.jsx)(`canvas`,{ref:w,style:{width:`100%`,height:`100%`,display:`block`,color:s||`currentColor`}})})});Mn.displayName=`LiveWaveform`;var Nn=[`What are you curious to research?`,`Search the latest news...`,`Analyze a video, doc, or URL...`,`Find academic research on...`,`Compare products to buy...`],Pn={initial:{},animate:{transition:{staggerChildren:.025}},exit:{transition:{staggerChildren:.015,staggerDirection:-1}}},Fn={initial:{opacity:0,filter:`blur(12px)`,y:10},animate:{opacity:1,filter:`blur(0px)`,y:0,transition:{opacity:{duration:.25},filter:{duration:.4},y:{type:`spring`,stiffness:80,damping:20}}},exit:{opacity:0,filter:`blur(12px)`,y:-10,transition:{opacity:{duration:.2},filter:{duration:.3},y:{type:`spring`,stiffness:80,damping:20}}}},In=({onNewChat:e})=>{let{loading:t,sendMessage:r,stopStreaming:i,files:a,fileIds:o,setFiles:l,setFileIds:f,newChat:p,sections:m}=G(),[h,g]=(0,n.useState)(``),_=(0,n.useRef)(null),v=(0,n.useRef)(null),{files:y,setFiles:b,pastedContent:x,setPastedContent:S,isDragging:C,handleFiles:w,onDragOver:E,onDragLeave:D,onDrop:O,handlePaste:k,resetAttachments:A}=gn({setMessage:g,contextFiles:a,contextFileIds:o,setContextFiles:l,setContextFileIds:f}),j=()=>{g(``),A(),_.current&&(_.current.style.height=`auto`)},M=(0,n.useRef)(``),N=(e,t)=>e&&!/\s$/.test(e)?`${e} ${t}`:`${e}${t}`,{isListening:P,toggleSpeech:F,isSpeechSupported:I,lastPhrase:L,phraseId:R}=$t(e=>{g(()=>{let t=`${N(M.current,e)} `;return M.current=t,t})},()=>{g(e=>(e.trim()&&setTimeout(()=>{r(e),j()},0),e))},{onPartial:e=>g(e?N(M.current,e):M.current)});(0,n.useEffect)(()=>{P&&(M.current=h)},[P]),ln({isSpeechSupported:I,isListening:P,toggleSpeech:F});let[z,ee]=(0,n.useState)(0),[te,ne]=(0,n.useState)(!0),[B,re]=(0,n.useState)(!1),[ie,ae]=(0,n.useState)([]),[V,oe]=(0,n.useState)([]),[H,U]=(0,n.useState)(-1),[se,ce]=(0,n.useState)(!1),[le,ue]=(0,n.useState)(`below`),de=(0,n.useRef)(!1),fe=(0,n.useRef)(null);(0,n.useEffect)(()=>{if(de.current){de.current=!1;return}let{query:e}=pe(h);if(!B||e.length<2){ae([]),oe([]),ce(!1),U(-1);return}let t=setTimeout(async()=>{fe.current?.abort();let t=new AbortController;fe.current=t;try{let{data:n,error:r}=await(0,c.autocomplete)({query:{q:e,limit:8},signal:t.signal});if(r)return;let i=Array.isArray(n?.suggestions)?n.suggestions:[],a=Array.isArray(n?.domains)?n.domains:[];if(ae(i),oe(a),i.length+a.length>0){if(v.current){let e=v.current.getBoundingClientRect(),t=window.innerHeight-e.bottom,n=e.top;t<Math.min(288,(i.length+a.length)*36)&&n>t?ue(`above`):ue(`below`)}ce(!0)}else ce(!1);U(-1)}catch(e){e?.name!==`AbortError`&&console.error(`Autocomplete fetch failed`,e)}},180);return()=>clearTimeout(t)},[h,B]);let pe=e=>{let t=e.trimEnd();if(!t)return{prefix:``,query:``};let n=t.split(/\s+/),r=Math.min(4,n.length),i=n.slice(-r).join(` `);return{prefix:n.length>r?n.slice(0,-r).join(` `)+` `:``,query:i}},me=e=>{de.current=!0;let{prefix:t}=pe(h);g(t+e),ae([]),oe([]),ce(!1),U(-1),_.current?.focus()},he=e=>{ce(!1),U(-1),window.location.href=`https://${e.domain}`},W=V.length+ie.length,ge=e=>{e<V.length?he(V[e]):me(ie[e-V.length])};(0,n.useEffect)(()=>{if(B||h)return;let e=setInterval(()=>{ne(!1),setTimeout(()=>{ee(e=>(e+1)%Nn.length),ne(!0)},400)},3e3);return()=>clearInterval(e)},[B,h]),(0,n.useEffect)(()=>{let e=e=>{v.current&&!v.current.contains(e.target)&&(h||re(!1))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[h]),(0,n.useEffect)(()=>{_.current&&(_.current.style.height=`auto`,_.current.style.height=Math.min(_.current.scrollHeight,384)+`px`)},[h]);let _e=()=>{t||(h.trim()||y.length!==0||x.length!==0)&&(r(h),j())},ve=e=>{if(se&&W>0){if(e.key===`ArrowDown`){e.preventDefault(),U(e=>(e+1)%W);return}if(e.key===`ArrowUp`){e.preventDefault(),U(e=>e<=0?W-1:e-1);return}if(e.key===`Escape`){e.preventDefault(),ce(!1),U(-1);return}if(e.key===`Tab`&&H>=0){e.preventDefault(),ge(H);return}if(e.key===`Enter`&&!e.shiftKey&&H>=0){e.preventDefault(),ge(H);return}let t=parseInt(e.key,10);if(t>=1&&t<=W&&t<=9){e.preventDefault(),ge(t-1);return}}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),_e())},ye=!!(h.trim()||y.length>0||x.length>0);return(0,d.jsxs)(`div`,{className:`relative w-full max-w-2xl mx-auto transition-all duration-300 font-sans`,onDragOver:E,onDragLeave:D,onDrop:O,children:[(0,d.jsxs)(u.motion.div,{ref:v,className:`!box-content flex flex-col mx-2 md:mx-0 items-stretch relative z-10 rounded-[28px] bg-gray-50 dark:bg-[#30302E] border border-bg-300 dark:border-transparent cursor-text font-sans antialiased`,animate:{boxShadow:B||h?`0 8px 32px 0 rgba(0,0,0,0.16)`:`0 2px 8px 0 rgba(0,0,0,0.08)`},transition:{type:`spring`,stiffness:120,damping:18},onClick:()=>re(!0),children:[(y.length>0||x.length>0)&&(0,d.jsxs)(`div`,{className:`flex gap-3 overflow-x-auto custom-scrollbar px-3 pt-3 pb-1`,children:[x.map(e=>(0,d.jsx)(Zt,{content:e,onRemove:e=>S(t=>t.filter(t=>t.id!==e))},e.id)),y.map(e=>(0,d.jsx)(Xt,{file:e,onRemove:e=>b(t=>t.filter(t=>t.id!==e))},e.id))]}),P&&(0,d.jsx)(`div`,{className:`px-3 pt-2`,children:(0,d.jsx)(Mn,{active:P,mode:`static`,height:48,barWidth:3,barGap:2,barColor:`gray`,fadeEdges:!0,sensitivity:1.2,className:`w-full rounded-lg`})}),(0,d.jsx)(T.SpokenPhraseOverlay,{phrase:L,phraseId:R,visible:P}),(0,d.jsxs)(`div`,{className:`flex items-center gap-2 p-3`,children:[(0,d.jsx)(jn,{onFileSelect:w,disabled:t}),(0,d.jsxs)(`div`,{className:`relative flex-1`,children:[(0,d.jsx)(`div`,{className:`max-h-96 w-full overflow-y-auto custom-scrollbar`,children:(0,d.jsx)(`textarea`,{ref:_,value:h,onChange:e=>g(e.target.value),onPaste:k,onKeyDown:ve,onFocus:()=>re(!0),className:`w-full bg-transparent border-0 outline-none text-text-200 dark:text-text-100 text-[16px] resize-none overflow-hidden py-1 leading-relaxed block font-normal antialiased`,rows:1,autoFocus:!0,style:{minHeight:`1.5em`}})}),(0,d.jsx)(`div`,{className:`absolute left-0 top-0 w-full h-full pointer-events-none flex items-center`,children:(0,d.jsx)(u.AnimatePresence,{mode:`wait`,children:te&&!B&&!h&&(0,d.jsx)(u.motion.span,{className:`absolute left-0 top-1/2 -translate-y-1/2 text-text-400 select-none pointer-events-none text-[16px] font-normal`,style:{whiteSpace:`nowrap`,overflow:`hidden`,textOverflow:`ellipsis`},variants:Pn,initial:`initial`,animate:`animate`,exit:`exit`,children:Nn[z].split(``).map((e,t)=>(0,d.jsx)(u.motion.span,{variants:Fn,style:{display:`inline-block`},children:e===` `?`\xA0`:e},t))},z)})})]}),I&&(0,d.jsxs)(`div`,{className:`relative flex shrink !shrink-0 group`,children:[(0,d.jsx)(`button`,{onClick:e=>{e.stopPropagation(),F()},disabled:t,className:`transition-all duration-200 h-8 w-8 flex items-center justify-center rounded-full active:scale-95
28
+ `))},className:`gap-2`,children:[(0,d.jsx)(s.FileSpreadsheet,{className:`w-4 h-4 flex-shrink-0`}),(0,d.jsx)(`span`,{children:`Export to Google Docs`})]})]})]}),(0,d.jsx)(X,{})]}),(0,d.jsx)(In,{}),(0,d.jsxs)(Y,{onSelect:()=>{t.researchAgentUIConfig.onOpenSettings?.()||a.push(`/settings`)},className:`gap-2`,children:[(0,d.jsx)(s.Settings,{className:`w-4 h-4 flex-shrink-0 text-muted-foreground`}),(0,d.jsx)(`span`,{children:`Settings`})]})]})]}),(0,d.jsx)(`div`,{className:`absolute bottom-full left-1/2 -translate-x-1/2 mb-2 px-2 py-1 bg-[#1F1E1D] dark:bg-[#EEEEEC] text-[11px] font-medium rounded-[6px] opacity-0 group-hover:opacity-100 transition-opacity whitespace-nowrap pointer-events-none z-50 shadow-sm tracking-wide`,children:(0,d.jsx)(`span`,{className:`text-[#ECECEC] dark:text-[#1F1E1D]`,children:`Search options`})})]}),(0,d.jsxs)(`div`,{className:`relative hidden sm:flex shrink-0 group -ml-1`,children:[(0,d.jsx)(`button`,{type:`button`,disabled:i,onClick:M,"aria-label":`Attach files`,className:`inline-flex items-center justify-center relative shrink-0 transition-colors duration-200 h-7 w-7 rounded-md active:scale-95 text-text-400 hover:text-text-200 hover:bg-bg-200 disabled:opacity-50 disabled:cursor-not-allowed group-active:scale-95`,children:(0,d.jsx)(s.Paperclip,{className:`w-[18px] h-[18px]`})}),(0,d.jsx)(`div`,{className:`absolute bottom-full left-1/2 -translate-x-1/2 mb-2 px-2 py-1 bg-[#1F1E1D] dark:bg-[#EEEEEC] text-[11px] font-medium rounded-[6px] opacity-0 group-hover:opacity-100 transition-opacity whitespace-nowrap pointer-events-none z-50 shadow-sm tracking-wide`,children:(0,d.jsx)(`span`,{className:`text-[#ECECEC] dark:text-[#1F1E1D]`,children:`Attach files`})})]}),(0,d.jsx)(`input`,{ref:O,type:`file`,multiple:!0,onChange:t=>{t.target.files&&(e(t.target.files),t.target.value=``)},className:`hidden`})]})},Vn=(0,n.forwardRef)(({active:e=!1,processing:t=!1,barWidth:r=3,barHeight:i=4,barGap:a=1,barRadius:o=1.5,barColor:s,fadeEdges:c=!0,fadeWidth:l=24,height:u=64,sensitivity:f=1,smoothingTimeConstant:p=.8,fftSize:m=256,historySize:h=60,updateRate:g=30,mode:_=`static`,onError:v,onStreamReady:y,onStreamEnd:b,className:x,...S},C)=>{let w=(0,n.useRef)(null),T=(0,n.useRef)(null),E=(0,n.useRef)(null),D=(0,n.useRef)(null),O=(0,n.useRef)(null),k=(0,n.useRef)(0),A=(0,n.useRef)([]),j=(0,n.useRef)(0),M=(0,n.useRef)(0),N=(0,n.useCallback)(()=>{k.current&&=(cancelAnimationFrame(k.current),0),O.current&&=(O.current.disconnect(),null),D.current&&=(D.current.getTracks().forEach(e=>e.stop()),null),T.current&&=(T.current.close().catch(()=>{}),null),E.current=null,A.current=[],b?.()},[b]),P=(0,n.useCallback)((e,t,n,s,c)=>{let l=r+a,u=Math.floor(t/c/l),d=u*l-a,p=(t/c-d)/2,m=s.length;for(let t=0;t<u;t++){let a=s[Math.floor(t/u*m)]/255*f,d=Math.max(i,n/c*a),h=p+t*l,g=(n/c-d)/2;e.beginPath(),e.roundRect(h*c,g*c,r*c,d*c,o*c),e.fill()}},[r,a,i,o,f]),F=(0,n.useCallback)((e,t,n,s)=>{let c=A.current,l=r+a,u=Math.min(c.length,h),d=t/s-u*l;for(let t=0;t<u;t++){let a=c[c.length-u+t]*f,p=Math.max(i,n/s*a),m=d+t*l,h=(n/s-p)/2;e.beginPath(),e.roundRect(m*s,h*s,r*s,p*s,o*s),e.fill()}},[r,a,i,o,f,h]),I=(0,n.useCallback)((e,t,n,s,c)=>{let l=r+a,u=Math.floor(t/s/l),d=u*l-a,f=(t/s-d)/2;for(let t=0;t<u;t++){let a=Math.sin(t/u*Math.PI*2+c)*.5+.5,d=Math.max(i,n/s*a*.6),p=f+t*l,m=(n/s-d)/2;e.beginPath(),e.roundRect(p*s,m*s,r*s,d*s,o*s),e.fill()}},[r,a,i,o]),L=(0,n.useCallback)((e,t,n)=>{if(!c)return;e.save(),e.globalCompositeOperation=`destination-in`;let r=e.createLinearGradient(0,0,t,0);r.addColorStop(0,`rgba(0,0,0,0)`),r.addColorStop(Math.min(l/(t||1),.3),`rgba(0,0,0,1)`),r.addColorStop(Math.max(1-l/(t||1),.7),`rgba(0,0,0,1)`),r.addColorStop(1,`rgba(0,0,0,0)`),e.fillStyle=r,e.fillRect(0,0,t,n),e.restore()},[c,l]);(0,n.useEffect)(()=>{if(!e&&!t){let e=w.current;if(e){let t=e.getContext(`2d`);t&&t.clearRect(0,0,e.width,e.height)}return}let n=!0,r=i=>{if(!n)return;let a=w.current;if(!a){k.current=requestAnimationFrame(r);return}if(i-M.current<g){k.current=requestAnimationFrame(r);return}M.current=i;let o=window.devicePixelRatio||1,c=a.getBoundingClientRect(),l=c.width*o,u=c.height*o;(a.width!==l||a.height!==u)&&(a.width=l,a.height=u);let d=a.getContext(`2d`);if(!d){k.current=requestAnimationFrame(r);return}if(d.clearRect(0,0,l,u),d.fillStyle=s||getComputedStyle(a).getPropertyValue(`color`)||`#888`,d.save(),d.setTransform(1,0,0,1,0,0),t&&!e)j.current+=.06,I(d,l,u,o,j.current);else if(e&&E.current){let e=new Uint8Array(E.current.frequencyBinCount);if(E.current.getByteFrequencyData(e),_===`scrolling`){let t=0;for(let n=0;n<e.length;n++)t+=e[n];let n=t/e.length/255;A.current.push(n),A.current.length>h*2&&(A.current=A.current.slice(-h)),F(d,l,u,o)}else P(d,l,u,e,o)}L(d,l,u),d.restore(),k.current=requestAnimationFrame(r)};return k.current=requestAnimationFrame(r),()=>{n=!1,k.current&&=(cancelAnimationFrame(k.current),0)}},[e,t,_,s,g,h,P,F,I,L]),(0,n.useEffect)(()=>{if(!e){N();return}let t=!1;return(async()=>{try{let e=await navigator.mediaDevices.getUserMedia({audio:!0});if(t){e.getTracks().forEach(e=>e.stop());return}let n=new AudioContext,r=n.createAnalyser();r.fftSize=m,r.smoothingTimeConstant=p;let i=n.createMediaStreamSource(e);i.connect(r),T.current=n,E.current=r,D.current=e,O.current=i,y?.(e)}catch(e){t||v?.(e instanceof Error?e:Error(String(e)))}})(),()=>{t=!0,N()}},[e,m,p,N,v,y]);let R=typeof u==`number`?`${u}px`:u;return(0,d.jsx)(`div`,{ref:C,className:x,style:{height:R,width:`100%`,position:`relative`},...S,children:(0,d.jsx)(`canvas`,{ref:w,style:{width:`100%`,height:`100%`,display:`block`,color:s||`currentColor`}})})});Vn.displayName=`LiveWaveform`;var Hn=[`What are you curious to research?`,`Search the latest news...`,`Analyze a video, doc, or URL...`,`Find academic research on...`,`Compare products to buy...`],Un={initial:{},animate:{transition:{staggerChildren:.025}},exit:{transition:{staggerChildren:.015,staggerDirection:-1}}},Wn={initial:{opacity:0,filter:`blur(12px)`,y:10},animate:{opacity:1,filter:`blur(0px)`,y:0,transition:{opacity:{duration:.25},filter:{duration:.4},y:{type:`spring`,stiffness:80,damping:20}}},exit:{opacity:0,filter:`blur(12px)`,y:-10,transition:{opacity:{duration:.2},filter:{duration:.3},y:{type:`spring`,stiffness:80,damping:20}}}},Gn=({onNewChat:e})=>{let{loading:t,sendMessage:r,stopStreaming:i,files:a,fileIds:o,setFiles:l,setFileIds:f,newChat:p,sections:m}=G(),[h,g]=(0,n.useState)(``),_=(0,n.useRef)(null),v=(0,n.useRef)(null),{files:y,setFiles:b,pastedContent:x,setPastedContent:S,isDragging:C,handleFiles:w,onDragOver:E,onDragLeave:D,onDrop:O,handlePaste:k,resetAttachments:A}=Tn({setMessage:g,contextFiles:a,contextFileIds:o,setContextFiles:l,setContextFileIds:f}),j=()=>{g(``),A(),_.current&&(_.current.style.height=`auto`)},M=(0,n.useRef)(``),N=(e,t)=>e&&!/\s$/.test(e)?`${e} ${t}`:`${e}${t}`,{isListening:P,toggleSpeech:F,isSpeechSupported:I,lastPhrase:L,phraseId:R}=ln(e=>{g(()=>{let t=`${N(M.current,e)} `;return M.current=t,t})},()=>{g(e=>(e.trim()&&setTimeout(()=>{r(e),j()},0),e))},{onPartial:e=>g(e?N(M.current,e):M.current)});(0,n.useEffect)(()=>{P&&(M.current=h)},[P]),vn({isSpeechSupported:I,isListening:P,toggleSpeech:F});let[z,ee]=(0,n.useState)(0),[te,ne]=(0,n.useState)(!0),[B,re]=(0,n.useState)(!1),[ie,ae]=(0,n.useState)([]),[V,oe]=(0,n.useState)([]),[H,U]=(0,n.useState)(-1),[se,ce]=(0,n.useState)(!1),[le,ue]=(0,n.useState)(`below`),de=(0,n.useRef)(!1),fe=(0,n.useRef)(null);(0,n.useEffect)(()=>{if(de.current){de.current=!1;return}let{query:e}=pe(h);if(!B||e.length<2){ae([]),oe([]),ce(!1),U(-1);return}let t=setTimeout(async()=>{fe.current?.abort();let t=new AbortController;fe.current=t;try{let{data:n,error:r}=await(0,c.autocomplete)({query:{q:e,limit:8},signal:t.signal});if(r)return;let i=Array.isArray(n?.suggestions)?n.suggestions:[],a=Array.isArray(n?.domains)?n.domains:[];if(ae(i),oe(a),i.length+a.length>0){if(v.current){let e=v.current.getBoundingClientRect(),t=window.innerHeight-e.bottom,n=e.top;t<Math.min(288,(i.length+a.length)*36)&&n>t?ue(`above`):ue(`below`)}ce(!0)}else ce(!1);U(-1)}catch(e){e?.name!==`AbortError`&&console.error(`Autocomplete fetch failed`,e)}},180);return()=>clearTimeout(t)},[h,B]);let pe=e=>{let t=e.trimEnd();if(!t)return{prefix:``,query:``};let n=t.split(/\s+/),r=Math.min(4,n.length),i=n.slice(-r).join(` `);return{prefix:n.length>r?n.slice(0,-r).join(` `)+` `:``,query:i}},me=e=>{de.current=!0;let{prefix:t}=pe(h);g(t+e),ae([]),oe([]),ce(!1),U(-1),_.current?.focus()},he=e=>{ce(!1),U(-1),window.location.href=`https://${e.domain}`},W=V.length+ie.length,ge=e=>{e<V.length?he(V[e]):me(ie[e-V.length])};(0,n.useEffect)(()=>{if(B||h)return;let e=setInterval(()=>{ne(!1),setTimeout(()=>{ee(e=>(e+1)%Hn.length),ne(!0)},400)},3e3);return()=>clearInterval(e)},[B,h]),(0,n.useEffect)(()=>{let e=e=>{v.current&&!v.current.contains(e.target)&&(h||re(!1))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[h]),(0,n.useEffect)(()=>{_.current&&(_.current.style.height=`auto`,_.current.style.height=Math.min(_.current.scrollHeight,384)+`px`)},[h]);let _e=()=>{t||(h.trim()||y.length!==0||x.length!==0)&&(r(h),j())},ve=e=>{if(se&&W>0){if(e.key===`ArrowDown`){e.preventDefault(),U(e=>(e+1)%W);return}if(e.key===`ArrowUp`){e.preventDefault(),U(e=>e<=0?W-1:e-1);return}if(e.key===`Escape`){e.preventDefault(),ce(!1),U(-1);return}if(e.key===`Tab`&&H>=0){e.preventDefault(),ge(H);return}if(e.key===`Enter`&&!e.shiftKey&&H>=0){e.preventDefault(),ge(H);return}let t=parseInt(e.key,10);if(t>=1&&t<=W&&t<=9){e.preventDefault(),ge(t-1);return}}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),_e())},ye=!!(h.trim()||y.length>0||x.length>0);return(0,d.jsxs)(`div`,{className:`relative w-full max-w-2xl mx-auto transition-all duration-300 font-sans`,onDragOver:E,onDragLeave:D,onDrop:O,children:[(0,d.jsxs)(u.motion.div,{ref:v,className:`!box-content flex flex-col mx-2 md:mx-0 items-stretch relative z-10 rounded-[28px] bg-gray-50 dark:bg-[#30302E] border border-bg-300 dark:border-transparent cursor-text font-sans antialiased`,animate:{boxShadow:B||h?`0 8px 32px 0 rgba(0,0,0,0.16)`:`0 2px 8px 0 rgba(0,0,0,0.08)`},transition:{type:`spring`,stiffness:120,damping:18},onClick:()=>re(!0),children:[(y.length>0||x.length>0)&&(0,d.jsxs)(`div`,{className:`flex gap-3 overflow-x-auto custom-scrollbar px-3 pt-3 pb-1`,children:[x.map(e=>(0,d.jsx)(sn,{content:e,onRemove:e=>S(t=>t.filter(t=>t.id!==e))},e.id)),y.map(e=>(0,d.jsx)(on,{file:e,onRemove:e=>b(t=>t.filter(t=>t.id!==e))},e.id))]}),P&&(0,d.jsx)(`div`,{className:`px-3 pt-2`,children:(0,d.jsx)(Vn,{active:P,mode:`static`,height:48,barWidth:3,barGap:2,barColor:`gray`,fadeEdges:!0,sensitivity:1.2,className:`w-full rounded-lg`})}),(0,d.jsx)(T.SpokenPhraseOverlay,{phrase:L,phraseId:R,visible:P}),(0,d.jsxs)(`div`,{className:`flex items-center gap-2 p-3`,children:[(0,d.jsx)(Bn,{onFileSelect:w,disabled:t}),(0,d.jsxs)(`div`,{className:`relative flex-1`,children:[(0,d.jsx)(`div`,{className:`max-h-96 w-full overflow-y-auto custom-scrollbar`,children:(0,d.jsx)(`textarea`,{ref:_,value:h,onChange:e=>g(e.target.value),onPaste:k,onKeyDown:ve,onFocus:()=>re(!0),className:`w-full bg-transparent border-0 outline-none text-text-200 dark:text-text-100 text-[16px] resize-none overflow-hidden py-1 leading-relaxed block font-normal antialiased`,rows:1,autoFocus:!0,style:{minHeight:`1.5em`}})}),(0,d.jsx)(`div`,{className:`absolute left-0 top-0 w-full h-full pointer-events-none flex items-center`,children:(0,d.jsx)(u.AnimatePresence,{mode:`wait`,children:te&&!B&&!h&&(0,d.jsx)(u.motion.span,{className:`absolute left-0 top-1/2 -translate-y-1/2 text-text-400 select-none pointer-events-none text-[16px] font-normal`,style:{whiteSpace:`nowrap`,overflow:`hidden`,textOverflow:`ellipsis`},variants:Un,initial:`initial`,animate:`animate`,exit:`exit`,children:Hn[z].split(``).map((e,t)=>(0,d.jsx)(u.motion.span,{variants:Wn,style:{display:`inline-block`},children:e===` `?`\xA0`:e},t))},z)})})]}),I&&(0,d.jsxs)(`div`,{className:`relative flex shrink !shrink-0 group`,children:[(0,d.jsx)(`button`,{onClick:e=>{e.stopPropagation(),F()},disabled:t,className:`transition-all duration-200 h-8 w-8 flex items-center justify-center rounded-full active:scale-95
29
29
  ${P?`text-red-500 bg-red-500/10 animate-pulse`:`text-text-400 hover:text-text-200 hover:bg-bg-200`}
30
30
  `,"aria-label":P?`Stop listening`:`Voice input`,children:(0,d.jsx)(Z.Mic,{className:`w-5 h-5`})}),(0,d.jsx)(`div`,{className:`absolute bottom-full left-1/2 -translate-x-1/2 mb-2 px-2 py-1 bg-[#1F1E1D] dark:bg-[#EEEEEC] text-[11px] font-medium rounded-[6px] opacity-0 group-hover:opacity-100 transition-opacity whitespace-nowrap pointer-events-none z-50 shadow-sm tracking-wide`,children:(0,d.jsx)(`span`,{className:`text-[#ECECEC] dark:text-[#1F1E1D]`,children:P?`Stop listening`:`Voice input`})})]}),m.length>0&&(0,d.jsxs)(`div`,{className:`relative flex shrink !shrink-0 group`,children:[(0,d.jsx)(`button`,{onClick:e=>{e.stopPropagation(),p()},disabled:t,className:`transition-all duration-200 h-8 w-8 flex items-center justify-center rounded-full active:scale-95 text-text-400 hover:text-text-200 hover:bg-bg-200`,"aria-label":`New chat`,children:(0,d.jsx)(Z.SquarePen,{className:`w-5 h-5`})}),(0,d.jsx)(`div`,{className:`absolute bottom-full left-1/2 -translate-x-1/2 mb-2 px-2 py-1 bg-[#1F1E1D] dark:bg-[#EEEEEC] text-[11px] font-medium rounded-[6px] opacity-0 group-hover:opacity-100 transition-opacity whitespace-nowrap pointer-events-none z-50 shadow-sm tracking-wide`,children:(0,d.jsx)(`span`,{className:`text-[#ECECEC] dark:text-[#1F1E1D]`,children:`New chat`})})]}),(0,d.jsxs)(`div`,{className:`relative flex shrink !shrink-0 group`,children:[t?(0,d.jsx)(`button`,{onClick:e=>{e.stopPropagation(),i()},className:`inline-flex items-center justify-center shrink-0 transition-colors h-8 w-8 rounded-full active:scale-95 bg-red-500 text-white hover:bg-red-600 shadow-md`,type:`button`,"aria-label":`Stop generating`,children:(0,d.jsx)(Z.Stop,{className:`w-3.5 h-3.5 fill-current`})}):(0,d.jsx)(`button`,{onClick:e=>{e.stopPropagation(),_e()},disabled:!ye,className:`inline-flex items-center justify-center shrink-0 transition-all duration-200 h-8 w-8 rounded-full active:scale-95
31
31
  ${ye?`bg-accent text-bg-0 hover:bg-accent-hover shadow-md`:`bg-bg-300 text-text-400 cursor-default opacity-50`}
32
- `,type:`button`,"aria-label":`Send message`,children:(0,d.jsx)(Z.ArrowUp,{className:`w-4 h-4`})}),(0,d.jsx)(`div`,{className:`absolute bottom-full left-1/2 -translate-x-1/2 mb-2 px-2 py-1 bg-[#1F1E1D] dark:bg-[#EEEEEC] text-[11px] font-medium rounded-[6px] opacity-0 group-hover:opacity-100 transition-opacity whitespace-nowrap pointer-events-none z-50 shadow-sm tracking-wide`,children:(0,d.jsx)(`span`,{className:`text-[#ECECEC] dark:text-[#1F1E1D]`,children:t?`Stop generating`:`Send message`})})]})]})]}),(0,d.jsx)(u.AnimatePresence,{children:se&&W>0&&(0,d.jsx)(u.motion.div,{ref:e=>{e&&v.current&&v.current.contains(e)},initial:{opacity:0,y:le===`above`?4:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:le===`above`?4:-4},transition:{duration:.12},className:`absolute left-2 right-2 md:left-0 md:right-0 z-20 rounded-2xl bg-gray-50 dark:bg-[#30302E] border border-bg-300 dark:border-transparent shadow-xl overflow-hidden ${le===`above`?`bottom-full`:`top-full`}`,onMouseDown:e=>e.preventDefault(),children:(0,d.jsxs)(`ul`,{className:`max-h-72 overflow-y-auto custom-scrollbar py-1`,children:[V.map((e,t)=>(0,d.jsx)(`li`,{children:(0,d.jsxs)(`button`,{type:`button`,onMouseEnter:()=>U(t),onClick:()=>he(e),className:`w-full text-left px-4 py-1.5 text-[15px] flex items-center gap-3 transition-colors ${t===H?`bg-bg-200 text-text-100`:`text-text-200 hover:bg-bg-100 dark:hover:bg-[#3A3A38]`}`,children:[(0,d.jsx)(`span`,{className:`w-5 h-5 flex items-center justify-center rounded bg-bg-200 dark:bg-[#3A3A38] text-[11px] font-semibold text-text-400 shrink-0`,children:t+1}),(0,d.jsx)(`img`,{src:e.favicon,alt:``,className:`w-4 h-4 rounded-sm shrink-0`}),(0,d.jsx)(`span`,{className:`truncate font-medium`,children:e.name||e.domain}),(0,d.jsx)(`span`,{className:`truncate text-[13px] text-text-400 shrink-0`,children:e.domain}),Number.isFinite(e.rank)&&e.rank<2**53-1&&(0,d.jsxs)(`span`,{className:`ml-auto shrink-0 px-1.5 py-0.5 rounded-full text-[10px] font-semibold tabular-nums bg-bg-200 dark:bg-[#3A3A38] text-text-400`,children:[`#`,e.rank.toLocaleString()]})]})},`domain-${e.domain}`)),ie.map((e,t)=>{let n=V.length+t;return(0,d.jsx)(`li`,{children:(0,d.jsxs)(`button`,{type:`button`,onMouseEnter:()=>U(n),onClick:()=>me(e),className:`w-full text-left px-4 py-1.5 text-[15px] flex items-center gap-3 transition-colors ${n===H?`bg-bg-200 text-text-100`:`text-text-200 hover:bg-bg-100 dark:hover:bg-[#3A3A38]`}`,children:[(0,d.jsx)(`span`,{className:`w-5 h-5 flex items-center justify-center rounded bg-bg-200 dark:bg-[#3A3A38] text-[11px] font-semibold text-text-400 shrink-0`,children:n+1}),(0,d.jsx)(s.Search,{className:`w-4 h-4 text-text-400 shrink-0`}),(0,d.jsx)(`span`,{className:`truncate`,children:e})]})},`${e}-${t}`)})]})})}),C&&(0,d.jsxs)(`div`,{className:`absolute inset-0 bg-bg-200/90 border-2 border-dashed border-accent rounded-[28px] z-50 flex flex-col items-center justify-center backdrop-blur-sm pointer-events-none`,children:[(0,d.jsx)(Z.Archive,{className:`w-10 h-10 text-accent mb-2 animate-bounce`}),(0,d.jsx)(`p`,{className:`text-accent font-medium`,children:`Drop files to upload`})]})]})},Ln=n.forwardRef(({className:e,...t},n)=>(0,d.jsx)(`span`,{ref:n,className:F(`absolute w-px h-px p-0 -m-px overflow-hidden whitespace-nowrap border-0`,e),style:{clip:`rect(0, 0, 0, 0)`,clipPath:`inset(50%)`},...t}));Ln.displayName=`VisuallyHidden`;var Rn=({onClose:e})=>(0,d.jsx)(`div`,{className:`flex items-center justify-between bg-secondary px-4 py-3 border-b border-border`,children:(0,d.jsx)(`button`,{onClick:e,className:`rounded-md p-1 hover:bg-accent transition-colors`,children:(0,d.jsx)(s.X,{className:`h-5 w-5`})})}),zn=(0,x.cva)(`inline-flex cursor-pointer items-center justify-center gap-2 whitespace-nowrap rounded-2xl text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive`,{variants:{variant:{default:`bg-primary text-primary-foreground hover:bg-primary/90`,destructive:`bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60`,outline:`border-[1.5px] bg-background hover:bg-accent hover:text-accent-foreground dark:bg-card dark:hover:bg-card/50`,secondary:`bg-secondary text-secondary-foreground hover:bg-secondary/80`,ghost:`hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50`,link:`text-primary underline-offset-4 hover:underline`},size:{default:`h-9 px-4 py-2 has-[>svg]:px-3`,sm:`h-8 gap-1.5 px-3 has-[>svg]:px-2.5`,lg:`h-10 px-6 has-[>svg]:px-4`,icon:`size-9`}},defaultVariants:{variant:`default`,size:`default`}});function Q({className:e,variant:t,size:n,asChild:r=!1,...i}){return(0,d.jsx)(r?b.Slot:`button`,{"data-slot":`button`,className:F(zn({variant:t,size:n,className:e})),...i})}var Bn={ask:{alt:!0,key:`a`},suggest:{alt:!0,key:`s`},copy:{alt:!0,key:`c`},highlight:{alt:!0,key:`h`},favorite:{alt:!0,key:`f`},open:{alt:!0,key:`o`},zoomOut:{alt:!0,key:`-`},zoomReset:{alt:!0,key:`0`},zoomIn:{alt:!0,key:`=`},close:{alt:!1,key:`Escape`}},Vn=typeof navigator<`u`&&/Mac|iPhone|iPad|iPod/.test(navigator.platform||navigator.userAgent||``);function Hn(e){let{alt:t,key:n}=Bn[e],r=n===`Escape`?`Esc`:n.length===1?n.toUpperCase():n;return t?Vn?`⌥${r}`:`Alt+${r}`:r}var Un=F(`h-9 w-9 rounded-xl transition-all duration-200`,`hover:bg-muted/80 hover:text-foreground text-muted-foreground`),$=({label:e,action:t,children:n})=>(0,d.jsxs)(K,{children:[(0,d.jsx)(q,{asChild:!0,children:n}),(0,d.jsx)(J,{side:`bottom`,children:(0,d.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,d.jsx)(`span`,{children:e}),t&&(0,d.jsx)(`kbd`,{className:`rounded bg-primary-foreground/20 px-1 py-0.5 text-[10px] font-semibold leading-none tracking-wide`,children:Hn(t)})]})})]}),Wn=({isLoadingAI:e,isLoadingFollowups:t,isLoadingFavorite:n,isFavorited:r,isHighlightMode:i,articleUrl:a,fontScale:o,onAskClick:c,onSuggestClick:l,onCopyClick:u,onShareClick:f,onFavoriteClick:p,onHighlightToggle:m,onZoomIn:h,onZoomOut:g,onZoomReset:_,onClose:v})=>{let y=h||g,b=Math.round((o??1)*100);return(0,d.jsxs)(`div`,{className:`flex flex-nowrap items-center gap-1 rounded-2xl border border-muted bg-gradient-to-b from-background to-muted/30 p-1 shadow-sm`,children:[(0,d.jsx)($,{label:`Ask AI about this article`,action:`ask`,children:(0,d.jsxs)(Q,{onClick:c,disabled:e,variant:`ghost`,size:`sm`,className:F(`flex items-center gap-2 px-3 h-9 rounded-xl transition-all duration-200`,`hover:bg-muted/80 hover:text-foreground text-muted-foreground`),children:[(0,d.jsx)(s.Bot,{className:`size-4`}),(0,d.jsx)(`span`,{className:`font-medium`,children:e?`...`:`Ask`})]})}),(0,d.jsx)($,{label:`Suggest follow-up questions`,action:`suggest`,children:(0,d.jsxs)(Q,{onClick:l,disabled:t,variant:`ghost`,size:`sm`,className:F(`flex items-center gap-2 px-3 h-9 rounded-xl transition-all duration-200`,`hover:bg-muted/80 hover:text-foreground text-muted-foreground`),children:[(0,d.jsx)(s.MessageCircleQuestion,{className:`size-4`}),(0,d.jsx)(`span`,{className:`font-medium`,children:`Suggest`})]})}),(0,d.jsx)($,{label:`Copy article`,action:`copy`,children:(0,d.jsx)(Q,{onClick:u,variant:`ghost`,size:`icon`,className:Un,children:(0,d.jsx)(s.Clipboard,{className:`size-4`})})}),(0,d.jsx)($,{label:`Share article`,children:(0,d.jsx)(Q,{onClick:f,variant:`ghost`,size:`icon`,className:Un,children:(0,d.jsx)(s.Share2,{className:`size-4`})})}),(0,d.jsx)($,{label:i?`Disable highlighting`:`Enable highlighting`,action:`highlight`,children:(0,d.jsx)(Q,{onClick:m,variant:`ghost`,size:`icon`,className:F(`h-9 w-9 rounded-xl transition-all duration-200`,i?`text-yellow-500 bg-yellow-50 dark:bg-yellow-950/30 hover:bg-yellow-100 dark:hover:bg-yellow-950/50`:`hover:bg-muted/80 hover:text-foreground text-muted-foreground`),children:(0,d.jsx)(s.Highlighter,{className:`size-4`})})}),(0,d.jsx)($,{label:r?`Remove from favorites`:`Add to favorites`,action:`favorite`,children:(0,d.jsx)(Q,{onClick:p,disabled:n,variant:`ghost`,size:`icon`,className:F(`h-9 w-9 rounded-xl transition-all duration-200`,r?`text-yellow-500 hover:text-yellow-600 hover:bg-yellow-50 dark:hover:bg-yellow-950/30`:`hover:bg-muted/80 hover:text-foreground text-muted-foreground`),children:(0,d.jsx)(s.Star,{className:F(`size-4`,r&&`fill-yellow-400`)})})}),a&&(0,d.jsx)($,{label:`Open in new tab`,action:`open`,children:(0,d.jsx)(Q,{asChild:!0,variant:`ghost`,size:`icon`,className:Un,children:(0,d.jsx)(`a`,{href:a,target:`_blank`,rel:`noopener noreferrer`,children:(0,d.jsx)(s.ExternalLink,{className:`size-4`})})})}),y&&(0,d.jsxs)(`div`,{className:`ml-auto flex items-center gap-0.5 rounded-xl border border-muted/60 bg-muted/20 px-1`,children:[(0,d.jsx)($,{label:`Zoom out`,action:`zoomOut`,children:(0,d.jsx)(Q,{onClick:g,variant:`ghost`,size:`icon`,className:`h-8 w-8 rounded-lg text-muted-foreground transition-all duration-200 hover:bg-muted/80 hover:text-foreground`,children:(0,d.jsx)(s.ZoomOut,{className:`size-4`})})}),(0,d.jsx)($,{label:`Reset zoom`,action:`zoomReset`,children:(0,d.jsxs)(`button`,{type:`button`,onClick:_,className:`min-w-[3rem] rounded-md px-1 text-center text-xs font-medium tabular-nums text-muted-foreground transition-colors hover:text-foreground`,children:[b,`%`]})}),(0,d.jsx)($,{label:`Zoom in`,action:`zoomIn`,children:(0,d.jsx)(Q,{onClick:h,variant:`ghost`,size:`icon`,className:`h-8 w-8 rounded-lg text-muted-foreground transition-all duration-200 hover:bg-muted/80 hover:text-foreground`,children:(0,d.jsx)(s.ZoomIn,{className:`size-4`})})})]}),(0,d.jsx)($,{label:`Close`,action:`close`,children:(0,d.jsx)(Q,{onClick:v,variant:`ghost`,size:`icon`,className:F(Un,!y&&`ml-auto`),children:(0,d.jsx)(s.X,{className:`size-4`})})})]})},Gn=({value:e,onChange:t,onSubmit:n})=>(0,d.jsx)(`div`,{className:`relative`,children:(0,d.jsx)(`input`,{value:e,onChange:e=>t(e.target.value),onKeyDown:e=>e.key===`Enter`&&n(),type:`text`,placeholder:`Ask AI any question...`,className:`w-full px-3 py-2 text-sm rounded-md border border-input bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-ring`})}),Kn=({questions:e,isLoading:r,error:i,onQuestionClick:a})=>{let o=n.default.useMemo(()=>{let t=[];return e.forEach(e=>{e.includes(`?`)&&e.split(`?`).length>2?e.split(`?`).map(e=>e.trim()).filter(Boolean).forEach(e=>{t.push(e.endsWith(`?`)?e:`${e}?`)}):t.push(e)}),t},[e]);return(0,d.jsxs)(d.Fragment,{children:[o.length>0&&(0,d.jsxs)(`div`,{className:`space-y-3 bg-accent/30 rounded-lg p-4 border border-primary/20`,children:[(0,d.jsx)(`h3`,{className:`text-sm font-bold text-primary mb-2`,children:`💡 Suggested Follow-up Questions`}),(0,d.jsxs)(`div`,{className:`space-y-2`,children:[(0,d.jsx)(`div`,{onClick:()=>a(t.researchAgentUIConfig.defaultSummarizePrompt),className:`cursor-pointer rounded-md p-3 text-sm font-semibold hover:bg-primary/10 bg-background border border-primary/30 transition-all hover:border-primary shadow-sm hover:shadow-md`,children:t.researchAgentUIConfig.defaultSummarizePrompt}),o.map((e,t)=>(0,d.jsx)(`div`,{onClick:()=>a(e),className:`cursor-pointer rounded-md p-3 text-sm font-semibold hover:bg-primary/10 bg-background border border-border transition-all hover:border-primary shadow-sm hover:shadow-md`,dangerouslySetInnerHTML:{__html:e}},t))]})]}),r&&(0,d.jsx)(`div`,{className:`flex justify-center`,children:(0,d.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-blue-500`})}),i&&(0,d.jsx)(`div`,{className:`bg-red-500 text-white p-2 rounded-md text-sm`,children:i})]})},qn=({response:e,isLoading:t,error:n})=>(0,d.jsxs)(d.Fragment,{children:[t&&(0,d.jsx)(`div`,{className:`flex justify-center`,children:(0,d.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-blue-500`})}),e&&(0,d.jsx)(`div`,{ref:e=>{},className:`bg-muted rounded-lg shadow-md p-4`,dangerouslySetInnerHTML:{__html:e}}),n&&(0,d.jsx)(`div`,{className:`bg-red-500 text-white p-2 rounded-md text-sm`,children:n})]}),Jn=({html:e,isHighlightMode:t=!1,fontScale:r=1})=>{let[i,a]=(0,n.useState)(``);return(0,n.useEffect)(()=>{a(E.default.sanitize(e||``,{ADD_TAGS:[`figure`,`figcaption`],ADD_ATTR:[`loading`]}))},[e]),(0,d.jsx)(`div`,{className:[`prose prose-neutral dark:prose-invert max-w-none`,`prose-p:leading-[1.9] prose-li:leading-[1.9] prose-p:my-5 prose-li:my-1.5`,`prose-headings:font-semibold prose-headings:tracking-tight prose-headings:leading-snug`,`prose-h1:mt-8 prose-h2:mt-8 prose-h3:mt-6`,`prose-blockquote:leading-[1.8] prose-blockquote:border-l-2`,`prose-img:rounded-lg prose-img:my-6`,t?`select-text`:``].join(` `),style:{fontSize:`${r}em`,fontFamily:`ui-serif, Georgia, Cambria, "Times New Roman", Times, serif`},dangerouslySetInnerHTML:{__html:i}})},Yn=({article:e,isHighlightMode:t,fontScale:n=1})=>(0,d.jsx)(`div`,{className:`border-t border-border pt-6`,children:(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`flex items-start justify-between mb-2`}),e.cite&&(0,d.jsx)(`div`,{className:`mb-3 text-sm text-muted-foreground`,dangerouslySetInnerHTML:{__html:e.cite}}),(0,d.jsx)(`div`,{className:`mb-3 text-xs text-muted-foreground space-y-1`,children:e.word_count&&(0,d.jsxs)(`p`,{children:[(0,d.jsx)(`span`,{className:`font-semibold`,children:`Words:`}),` `,e.word_count.toLocaleString()]})}),(0,d.jsx)(`div`,{id:`article-content`,children:(0,d.jsx)(Jn,{html:e.html||``,isHighlightMode:t,fontScale:n})})]})}),Xn=/(?:https?:\/\/)?(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)/g,Zn=/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g;function Qn(e){return e.includes(`](`)||e.includes(`)[`)?!1:/\.(com|org|net|io|dev|co|uk|de|fr|it|es|jp|cn|in|br|au|ca|us|gov|edu|mil|int|xyz|info|app|tech|online|site|website|store|shop|blog|news|tv|me|cc|ws|name|mobi|asia|tel|travel|jobs|pro|museum|coop|aero|arpa|biz|cat|jobs|post|tel|xxx|ac|ad|ae|af|ag|ai|al|am|ao|aq|ar|as|at|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cw|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|za|zm|zw)(?:\/|$)/i.test(e)}function $n(e){return/^https?:\/\//i.test(e)?e:`https://${e}`}function er(e){if(!e||typeof e!=`string`)return e;let t=e,n=[],r;for(Zn.lastIndex=0;(r=Zn.exec(t))!==null;){let e=r[0],i=r.index,a=t.substring(0,i),o=t.substring(i+e.length);!a.endsWith(`](`)&&!o.startsWith(`)`)&&n.push({email:e,index:i})}for(let e=n.length-1;e>=0;e--){let{email:r,index:i}=n[e];t=t.substring(0,i)+`[${r}](mailto:${r})`+t.substring(i+r.length)}let i=[],a;for(Xn.lastIndex=0;(a=Xn.exec(t))!==null;){let e=a[0],n=a.index;if(Zn.test(e))continue;let r=t.substring(0,n),o=t.substring(n+e.length);if(r.endsWith(`](`)||o.startsWith(`)`)||(r.match(/```/g)||[]).length%2!=0)continue;let s=r.lastIndexOf("`");if(s!==-1){let e=t.substring(s+1).indexOf("`");if(e!==-1&&e>n-s-1)continue}Qn(e)&&i.push({url:e,index:n})}for(let e=i.length-1;e>=0;e--){let{url:n,index:r}=i[e],a=$n(n);t=t.substring(0,r)+`[${n}](${a})`+t.substring(r+n.length)}return t}function tr(e){return!e||e.startsWith(`http://`)||e.startsWith(`https://`)||e.includes(`://`)?!1:e.startsWith(`/`)||e.startsWith(`#`)}function nr(e,t){if(t.startsWith(`#`)){e.preventDefault();let n=t.substring(1),r=document.getElementById(n);r&&r.scrollIntoView({behavior:`smooth`,block:`start`})}}function rr({code:e}){let[t,r]=(0,n.useState)(!1),i=(0,n.useCallback)(async()=>{try{await navigator.clipboard.writeText(e),r(!0),setTimeout(()=>r(!1),2e3)}catch(e){console.error(`Failed to copy:`,e)}},[e]);return(0,d.jsx)(`button`,{onClick:i,className:F(`absolute top-3 right-3 p-1.5 rounded-md`,`opacity-0 group-hover:opacity-100 transition-opacity duration-150`,`bg-zinc-200/80 hover:bg-zinc-300 dark:bg-zinc-700/80 dark:hover:bg-zinc-600`,`text-zinc-600 hover:text-zinc-800 dark:text-zinc-400 dark:hover:text-zinc-200`,`focus:outline-none focus:ring-1 focus:ring-zinc-400 dark:focus:ring-zinc-500`),"aria-label":t?`Copied!`:`Copy code`,children:t?(0,d.jsx)(s.Check,{className:`h-4 w-4 text-green-600 dark:text-green-400`}):(0,d.jsx)(s.Copy,{className:`h-4 w-4`})})}function ir({children:e}){let t=(0,n.useRef)(null),[r,i]=(0,n.useState)(``);return(0,n.useEffect)(()=>{if(t.current){let e=t.current.querySelector(`code`);if(e){let t=e.textContent||``;i(t.trim())}}},[e]),(0,d.jsxs)(`div`,{className:`relative group my-5`,children:[(0,d.jsx)(`pre`,{ref:t,className:F(`p-4 rounded-xl overflow-x-auto`,`bg-zinc-100 dark:bg-zinc-900`,`border border-zinc-200 dark:border-zinc-800`,`text-[13px] font-mono leading-relaxed`,`text-zinc-800 dark:text-zinc-200`,`[&_code]:bg-transparent [&_code]:text-inherit [&_code]:p-0`),children:e}),r&&(0,d.jsx)(rr,{code:r})]})}var ar=n.default.memo(({content:e,className:t,isStreaming:n=!1})=>{if(!e)return(0,d.jsx)(`div`,{className:F(`text-muted-foreground text-sm`,t),children:`No content`});let r=er(e);return(0,d.jsx)(`div`,{className:F(`kortix-markdown`,t),children:(0,d.jsx)(O.Streamdown,{isAnimating:n,components:{h1:({children:e})=>(0,d.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight text-foreground mt-8 mb-4 first:mt-0 pb-2 border-b border-border/40`,children:e}),h2:({children:e})=>(0,d.jsx)(`h2`,{className:`text-xl font-semibold tracking-tight text-foreground mt-8 mb-3 first:mt-0`,children:e}),h3:({children:e})=>(0,d.jsx)(`h3`,{className:`text-lg font-semibold text-foreground mt-6 mb-2 first:mt-0`,children:e}),h4:({children:e})=>(0,d.jsx)(`h4`,{className:`text-base font-semibold text-foreground mt-5 mb-2 first:mt-0`,children:e}),h5:({children:e})=>(0,d.jsx)(`h5`,{className:`text-sm font-semibold text-foreground mt-4 mb-1 first:mt-0`,children:e}),h6:({children:e})=>(0,d.jsx)(`h6`,{className:`text-sm font-medium text-muted-foreground mt-4 mb-1 first:mt-0 uppercase tracking-wide`,children:e}),p:({children:e})=>(0,d.jsx)(`p`,{className:`text-sm text-foreground leading-relaxed my-4 first:mt-0 last:mb-0 [&:has(img)]:my-0`,children:e}),ul:({children:e})=>(0,d.jsx)(`ul`,{className:`my-4 ml-6 list-disc marker:text-muted-foreground/60 space-y-2 first:mt-0 last:mb-0 text-sm`,children:e}),ol:({children:e})=>(0,d.jsx)(`ol`,{className:`my-4 ml-6 list-decimal marker:text-muted-foreground/60 marker:font-medium space-y-2 first:mt-0 last:mb-0 text-sm`,children:e}),li:({children:e})=>(0,d.jsx)(`li`,{className:`text-sm text-foreground leading-relaxed pl-1`,children:e}),a:({href:e,children:t})=>{let n=tr(e),r=e?.startsWith(`#`),i=F(`font-medium text-foreground`,`underline decoration-foreground/30 underline-offset-[3px] decoration-[1px]`,`hover:decoration-foreground/60 transition-colors duration-150`);return r?(0,d.jsx)(`a`,{href:e,onClick:t=>nr(t,e),className:i,children:t}):n?(0,d.jsx)(D.default,{href:e||`#`,className:i,children:t}):(0,d.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,className:i,children:t})},code:({children:e,className:t})=>t?.includes(`language-`)?(0,d.jsx)(`code`,{className:`text-[13px] leading-relaxed text-inherit`,children:e}):(0,d.jsx)(`code`,{className:`px-2 py-1 rounded-md text-[13px] font-mono bg-card dark:bg-[#161618] border border-neutral-200 dark:border-neutral-700/50 text-foreground`,children:e}),pre:({children:e})=>(0,d.jsx)(ir,{children:e}),blockquote:({children:e})=>(0,d.jsx)(`blockquote`,{className:F(`my-5 pl-4 py-1 text-sm`,`border-l-2 border-border`,`text-muted-foreground`,`[&>p]:my-2`),children:e}),hr:()=>(0,d.jsx)(`hr`,{className:`my-8 border-0 h-px bg-border/60`}),table:({children:e})=>(0,d.jsx)(`div`,{className:`my-5 overflow-x-auto rounded-xl border border-border/60`,children:(0,d.jsx)(`table`,{className:`w-full text-sm`,children:e})}),thead:({children:e})=>(0,d.jsx)(`thead`,{className:`bg-muted/50 dark:bg-muted/30 border-b border-border/60`,children:e}),tbody:({children:e})=>(0,d.jsx)(`tbody`,{className:`divide-y divide-border/40`,children:e}),tr:({children:e})=>(0,d.jsx)(`tr`,{className:`transition-colors hover:bg-muted/30`,children:e}),th:({children:e})=>(0,d.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-semibold text-foreground uppercase tracking-wider`,children:e}),td:({children:e})=>(0,d.jsx)(`td`,{className:`px-4 py-3 text-foreground`,children:e}),img:({src:e,alt:t})=>e?(0,d.jsxs)(`span`,{className:`block my-5`,children:[(0,d.jsx)(`img`,{src:e,alt:t||``,className:F(`max-w-full h-auto rounded-xl`,`border border-border/40`,`shadow-sm`),loading:`lazy`}),t&&(0,d.jsx)(`span`,{className:`block mt-2 text-center text-sm text-muted-foreground`,children:t})]}):null,strong:({children:e})=>(0,d.jsx)(`strong`,{className:`font-semibold text-foreground`,children:e}),em:({children:e})=>(0,d.jsx)(`em`,{className:`italic text-foreground/90`,children:e}),del:({children:e})=>(0,d.jsx)(`del`,{className:`line-through text-muted-foreground decoration-muted-foreground/50`,children:e}),input:({checked:e,...t})=>(0,d.jsx)(`input`,{type:`checkbox`,checked:e,readOnly:!0,className:F(`mr-2 h-4 w-4 rounded border-border`,`accent-secondary cursor-default`,`align-middle relative -top-[1px]`),...t}),div:({children:e,style:t,className:n,...r})=>(0,d.jsx)(`div`,{className:F(`text-sm text-foreground`,n),style:t,...r,children:e}),span:({children:e,style:t,className:n,...r})=>(0,d.jsx)(`span`,{className:F(`text-foreground`,n),style:t,...r,children:e})},children:r})})});ar.displayName=`UnifiedMarkdown`;function or(e){return e instanceof Error&&e.name===`AbortError`}async function sr(e,t){if(t.share)try{return await t.share(e),`shared`}catch(e){if(or(e))return`cancelled`}return await t.writeText(e.url),`copied`}var cr=e=>{let{isOpen:r,url:i,searchText:a,panelWidth:o,setPanelWidth:s,closePanel:l}=ee(),{isAuthenticated:u}=nt(),{chatModelProvider:f}=G(),p=e.isOpen===void 0?r:e.isOpen,h=e.onClose||l,g=e.url||i,_=e.searchText===void 0?a:e.searchText,[v,y]=(0,n.useState)(null),[b,x]=(0,n.useState)([]),[S,C]=(0,n.useState)(!1),[w,T]=(0,n.useState)(!1),[E,D]=(0,n.useState)(t.researchAgentUIConfig.defaultSummarizePrompt),[O,k]=(0,n.useState)(!1),[A,j]=(0,n.useState)(!1),[M,N]=(0,n.useState)(!1),[P,F]=(0,n.useState)(``),[I,L]=(0,n.useState)(``),[R,z]=(0,n.useState)([]),[te,ne]=(0,n.useState)(``),[B,re]=(0,n.useState)(!1),[ie,ae]=(0,n.useState)(!1),[V,oe]=(0,n.useState)(!1),[H,se]=(0,n.useState)(!1),[ce,le]=(0,n.useState)(o),[fe,pe]=(0,n.useState)(!1),[me,he]=(0,n.useState)(!1),[W,ge]=(0,n.useState)(1),_e=(0,n.useRef)(null),ve=(0,n.useRef)({}),ye=.5,be=1.8,xe=.1;(0,n.useEffect)(()=>{let e=parseFloat(localStorage.getItem(`articleFontScale`)||``);Number.isNaN(e)||ge(Math.min(be,Math.max(ye,e)))},[]);let Se=e=>{let t=Math.min(be,Math.max(ye,Math.round(e*100)/100));ge(t);try{localStorage.setItem(`articleFontScale`,String(t))}catch(e){console.error(`Error storing article font scale:`,e)}},Ce=()=>Se(W+xe),we=()=>Se(W-xe),Te=()=>Se(1);(0,n.useEffect)(()=>{let e=()=>{se(window.innerWidth>=1024)};return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]),(0,n.useEffect)(()=>{let e=e=>{if(!fe)return;let t=window.innerWidth-e.clientX,n=Math.max(400,Math.min(t,window.innerWidth-100));le(n),s(n)},t=()=>{pe(!1)};return fe&&(document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,t),document.body.style.cursor=`ew-resize`,document.body.style.userSelect=`none`),()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,t),document.body.style.cursor=``,document.body.style.userSelect=``}},[fe,s]),(0,n.useEffect)(()=>{p&&g?(he(!1),Ee()):p||he(!1)},[p,g]);let Ee=async()=>{console.log(`[ArticleExtractPanel] Extracting URL:`,g);try{let e=new URL(g);if([/^https?:\/\/(www\.)?google\.[^/]+\/search/i,/^https?:\/\/(www\.)?bing\.com\/search/i,/^https?:\/\/(www\.)?duckduckgo\.com\/\?/i].some(e=>e.test(g))){m.toast.error(`Cannot extract articles from search result pages`),k(!1),he(!0);return}(e.pathname===`/`||e.pathname===``)&&(console.error(`[ArticleExtractPanel] URL is domain-only, missing article path:`,g),m.toast.error(`Invalid article URL - only domain provided`))}catch(e){console.error(`[ArticleExtractPanel] Invalid URL format:`,g,e)}k(!0);try{let{data:e}=await(0,c.getArticle)({query:{url:g}}),t=e?.article,n=t?.html?.replace(/<[^>]*>/g,``).trim()||``;t?.error||n.length<20?(document.dispatchEvent(new CustomEvent(`onInvokeChromeAPI`,{detail:{type:`extractURL`,url:g}})),await Promise.race([new Promise(e=>{let t=async n=>{window.removeEventListener(`onExtractionResult`,t);let{data:r}=await(0,c.getArticle)({query:{url:g}}),i=r?.article;i&&(y(i),i.followUpQuestions?.length>0&&z(i.followUpQuestions)),e()};window.addEventListener(`onExtractionResult`,t)}),new Promise(e=>setTimeout(e,1e4))])):(y(t),t?.followUpQuestions&&t.followUpQuestions.length>0&&z(t.followUpQuestions)),u&&De()}catch(e){console.error(`[ArticleExtractPanel] Error extracting URL:`,e),m.toast.error(`Failed to load article`)}finally{k(!1),he(!0)}},De=async()=>{try{let{data:e}=await(0,c.listFavorites)(),t=e?.favorites?.some(e=>e.url===g);re(!!t)}catch(e){console.error(`Error checking favorite status:`,e)}},Oe=async()=>{if(v){ae(!0);try{B?(await(0,c.removeFavorite)({query:{url:g}}),re(!1),m.toast.info(`Removed from favorites`)):(await(0,c.addFavorite)({body:{url:v.url||g,title:v.title,cite:v.cite,author:v.author,author_cite:v.author_cite,date:v.date,source:v.source,word_count:v.word_count,html:v.html}}),re(!0),m.toast.success(`Added to favorites`))}catch(e){console.error(`Error toggling favorite:`,e),m.toast.error(`Failed to toggle favorite`)}finally{ae(!1)}}},ke=()=>{if(f?.key&&f?.providerId)return f;try{let e=localStorage.getItem(`chatModelKey`)||``,t=localStorage.getItem(`chatModelProviderId`)||``;if(e&&t)return{key:e,providerId:t}}catch(e){console.error(`Error reading persisted chat model:`,e)}return f},Ae=async e=>{if(!v)return;let n=ke(),r=v.html?.replace(/<[^>]*>?/g,``).slice(0,t.researchAgentUIConfig.maxArticleLength),i=e===`question`,a=i?j:N,o=i?L:ne;a(!0),o(``);try{if(i){let e=[_,E].filter(Boolean).join(`
33
- `);if(!r||r.length===0)throw Error(`Article content is empty`);let{data:t,error:i}=await(0,c.articleQa)({body:{article:r,question:e,chatHistory:b.slice(-5),chatModel:n}});if(i){let e=i.details||i.error||i.message||`Article QA failed`;throw Error(e)}let a=t?.content||``;F(a),x(e=>[...e,{role:`user`,content:E,time:new Date().toISOString()},{role:`assistant`,content:a,time:new Date().toISOString()}]);try{await(0,c.updateArticle)({body:{url:g,question:E,answer:a}})}catch(e){console.error(`Error storing Q&A in cache:`,e)}}else{let e=parseInt(localStorage.getItem(`maxFollowupQuestions`)||`4`);if(!r||r.length===0)throw Error(`Article content is empty`);let{data:t,error:i}=await(0,c.articleFollowups)({body:{article:r,chatHistory:b.slice(-5),maxQuestions:e,chatModel:n}});if(i){let e=i.details||i.error||i.message||`Article followups failed`;throw Error(e)}let a=t?.extract||[];z(a);try{await(0,c.updateArticle)({body:{url:g,followUpQuestions:a}})}catch(e){console.error(`Error storing follow-up questions in cache:`,e)}}}catch(e){console.error(`Error calling language API:`,e),o(e instanceof Error||typeof e==`object`&&e&&`message`in e?e.message:`Failed to get AI response`)}finally{a(!1)}},je=e=>{D(e),Ae(`question`)},Me=async()=>{if(!v)return;let e=`${P}\n\n\n${v.cite||``}\n\n\n${v.html}`;try{await navigator.clipboard.writeText(e),C(!0),setTimeout(()=>C(!1),2e3)}catch(e){console.error(`Failed to copy to clipboard:`,e)}},Ne=async()=>{let e=v?.url||g;if(e)try{await sr({title:v?.title,text:v?.cite,url:e},{share:typeof navigator<`u`&&navigator.share?e=>navigator.share(e):void 0,writeText:e=>navigator.clipboard.writeText(e)})===`copied`&&(T(!0),setTimeout(()=>T(!1),2e3))}catch(e){console.error(`Failed to share article:`,e)}};ve.current={ask:()=>Ae(`question`),suggest:()=>Ae(`suggest-followups`),copy:Me,highlight:()=>oe(e=>!e),favorite:Oe,open:()=>{let e=v?.url||g;e&&window.open(e,`_blank`,`noopener,noreferrer`)},zoomIn:Ce,zoomOut:we,zoomReset:Te,close:h},(0,n.useEffect)(()=>{if(!p)return;let e=e=>/^[a-z]$/.test(e)?`Key${e.toUpperCase()}`:/^[0-9]$/.test(e)?`Digit${e}`:e===`-`?`Minus`:e===`=`?`Equal`:e,t={};Object.keys(Bn).forEach(n=>{let{alt:r,key:i}=Bn[n];r&&(t[e(i.toLowerCase())]=n)});let n=e=>{if(e.key===`Escape`){ve.current.close?.();return}if(!e.altKey||e.ctrlKey||e.metaKey)return;let n=e.target;if(n&&(n.tagName===`INPUT`||n.tagName===`TEXTAREA`||n.isContentEditable))return;let r=t[e.code];if(!r)return;let i=ve.current[r];i&&(e.preventDefault(),i())};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[p]);let Pe=()=>(0,d.jsxs)(`div`,{className:`flex h-full flex-col bg-background shadow-xl`,children:[(0,d.jsx)(`div`,{className:`shrink-0 border-b border-border bg-background/95 px-4 py-3 backdrop-blur supports-[backdrop-filter]:bg-background/80`,children:(0,d.jsx)(Wn,{isLoadingAI:A,isLoadingFollowups:M,isLoadingFavorite:ie,isFavorited:B,isHighlightMode:V,articleUrl:v?.url||g,fontScale:W,onAskClick:()=>Ae(`question`),onSuggestClick:()=>Ae(`suggest-followups`),onCopyClick:Me,onShareClick:Ne,onFavoriteClick:Oe,onHighlightToggle:()=>oe(!V),onZoomIn:Ce,onZoomOut:we,onZoomReset:Te,onClose:h})}),(0,d.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:(0,d.jsxs)(`div`,{className:`p-4 space-y-6`,children:[(0,d.jsxs)(`div`,{className:`space-y-4`,children:[S&&(0,d.jsx)(`div`,{className:`bg-blue-500 text-white text-sm font-medium px-3 py-2 rounded-md shadow-lg`,children:`Copied!`}),w&&(0,d.jsx)(`div`,{className:`bg-blue-500 text-white text-sm font-medium px-3 py-2 rounded-md shadow-lg`,children:`Link copied!`}),(0,d.jsx)(Gn,{value:E,onChange:D,onSubmit:()=>Ae(`question`)}),(0,d.jsx)(Kn,{questions:R,isLoading:M,error:te,onQuestionClick:je}),b.length>0&&(0,d.jsx)(`div`,{className:`space-y-4`,children:b.map((e,t)=>(0,d.jsx)(`div`,{className:`space-y-2`,children:e.role===`user`?(0,d.jsxs)(`div`,{className:`bg-primary/10 border border-primary/20 rounded-lg p-3`,children:[(0,d.jsx)(`div`,{className:`text-xs font-semibold text-primary mb-1`,children:`Your Question`}),(0,d.jsx)(`div`,{className:`text-sm text-foreground`,children:e.content})]}):(0,d.jsxs)(`div`,{className:`bg-muted rounded-lg shadow-md p-4`,children:[(0,d.jsx)(`div`,{className:`text-xs font-semibold text-muted-foreground mb-2`,children:`AI Response`}),(0,d.jsx)(`div`,{className:`text-sm`,dangerouslySetInnerHTML:{__html:e.content}})]})},t))}),(A||P&&b.length===0)&&(0,d.jsx)(qn,{response:P,isLoading:A,error:I}),I&&!A&&(0,d.jsx)(`div`,{className:`bg-red-500 text-white p-2 rounded-md text-sm`,children:I})]}),v&&(0,d.jsx)(Yn,{article:v,isHighlightMode:V,fontScale:W})]})})]});return!p||!me?null:H?(0,d.jsxs)(`div`,{className:`fixed top-0 right-0 h-screen z-40 transition-all duration-300`,style:{width:`${ce}px`},children:[(0,d.jsx)(`div`,{ref:_e,onMouseDown:()=>pe(!0),className:`absolute left-0 top-0 bottom-0 w-1 cursor-ew-resize hover:bg-primary bg-transparent transition-colors z-50`,style:{touchAction:`none`},children:(0,d.jsx)(`div`,{className:`absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-1 h-12 rounded-full bg-muted-foreground opacity-50 hover:opacity-100 transition-opacity`})}),Pe()]}):(0,d.jsx)(U,{open:p,onOpenChange:e=>!e&&h(),children:(0,d.jsxs)(ue,{className:`pointer-events-auto fixed inset-0 !top-0 !left-0 !translate-x-0 !translate-y-0 h-full w-full max-w-none p-0 m-0 rounded-none border-0 overflow-hidden data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right`,hideCloseButton:!0,children:[(0,d.jsx)(Ln,{children:(0,d.jsx)(de,{children:`Article Details`})}),(0,d.jsx)(`div`,{className:`h-full overflow-y-auto`,children:Pe()})]})})},lr=()=>{let{sections:e,chatTurns:r,loading:i,messageAppeared:a,newChat:o,chatId:s}=G(),{isOpen:c,panelWidth:l}=ee(),{isAuthenticated:u}=nt(),[f,p]=(0,n.useState)(!1),m=(0,n.useRef)(null),h=(0,n.useRef)(null),g=(0,n.useRef)(!1);(0,n.useEffect)(()=>{let e=()=>{p(window.innerWidth>=1024)};return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]),(0,n.useEffect)(()=>{if(r.length===1&&(document.title=`${r[0].content.substring(0,30)} - ${t.researchAgentUIConfig.appName}`),r[r.length-1]?.role===`user`){g.current=!0,h.current?.scrollIntoView({behavior:`auto`}),setTimeout(()=>{g.current=!1},100);return}},[r]);let _=f&&c?{width:`calc(100% - ${l}px)`}:{};return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(`div`,{className:`flex flex-col min-h-full transition-all duration-300`,style:_,children:[(0,d.jsxs)(`div`,{className:`flex-1 flex flex-col space-y-3 pb-48 ${f&&!c?`px-0 max-w-[800px] mx-auto w-full`:`px-4 lg:px-8`}`,children:[e.map((t,r)=>{let i=r===e.length-1;return(0,d.jsxs)(n.Fragment,{children:[(0,d.jsx)(Vt,{section:t,sectionIndex:r,dividerRef:i?m:void 0,isLast:i}),!i&&(0,d.jsx)(`div`,{className:`h-px w-full bg-light-secondary dark:bg-dark-secondary`})]},t.userMessage.messageId)}),i&&!a&&(0,d.jsx)(Jt,{}),(0,d.jsx)(`div`,{ref:h,className:`h-0`})]}),(0,d.jsx)(`div`,{className:`sticky bottom-[60px] md:bottom-0 z-40 bg-gradient-to-t from-background via-background to-transparent pt-4 pb-2`,children:(0,d.jsx)(In,{})})]}),(0,d.jsx)(cr,{})]})};function ur({radius:e=60,opacityDecay:t=.025,backgroundColor:r=`transparent`,color:i,colorGenerator:a}){let o=(0,n.useRef)(null),s=(0,n.useRef)({x:0,y:0}),c=(0,n.useRef)([]),l=()=>[Math.floor(Math.random()*130+10),Math.floor(.5*Math.random()*50),Math.floor(.5*Math.random()*255)],u=()=>i||a?.()||l();return(0,n.useEffect)(()=>{let n=o.current;if(!n)return;let i=n.getContext(`2d`);if(!i)return;let a=0,l=()=>{n.width=window.innerWidth,n.height=window.innerHeight};l();let d=()=>{i.globalCompositeOperation=`source-over`,r===`transparent`?i.clearRect(0,0,n.width,n.height):(i.fillStyle=r,i.fillRect(0,0,n.width,n.height)),i.globalCompositeOperation=`lighter`;let o={col:u(),x:s.current.x,y:s.current.y,grdblur:i.createRadialGradient(s.current.x,s.current.y,0,s.current.x,s.current.y,e),alpha:1};c.current.push(o);let l=[];for(let n=0;n<c.current.length;n++){let r=c.current[n];r.grdblur.addColorStop(0,`rgba(${r.col[0]},${r.col[1]},${r.col[2]},0.95)`),r.grdblur.addColorStop(.2,`rgba(${r.col[0]},${r.col[1]},${r.col[2]},0.7)`),r.grdblur.addColorStop(.5,`rgba(${r.col[0]},${r.col[1]},${r.col[2]},0.3)`),r.grdblur.addColorStop(1,`rgba(${r.col[0]},${r.col[1]},${r.col[2]},0)`),i.beginPath(),i.fillStyle=r.grdblur,i.globalAlpha=r.alpha,i.arc(r.x,r.y,e,0,Math.PI*2),i.fill(),r.alpha-=t,r.alpha<=0&&l.push(n)}for(let e=l.length-1;e>=0;e--)c.current.splice(l[e],1);i.globalAlpha=1,a=requestAnimationFrame(d)},f=e=>{s.current.x=e.pageX,s.current.y=e.pageY},p=e=>{s.current.x=e.touches[0].pageX,s.current.y=e.touches[0].pageY};return window.addEventListener(`mousemove`,f),window.addEventListener(`touchmove`,p,{passive:!0}),window.addEventListener(`resize`,l),d(),()=>{cancelAnimationFrame(a),window.removeEventListener(`mousemove`,f),window.removeEventListener(`touchmove`,p),window.removeEventListener(`resize`,l),c.current=[]}},[e,t,r,i,a]),(0,d.jsx)(`div`,{className:`relative w-full h-screen overflow-hidden pointer-events-none`,children:(0,d.jsx)(`canvas`,{ref:o,className:`absolute inset-0`,style:{background:`transparent`}})})}var dr=200,fr=[`message`,`error`,`detail`];function pr(e){return e.length>dr?`${e.slice(0,199).trimEnd()}…`:e}function mr(e,t){let n=t?`HTTP ${t}`:`Unknown error`;if(typeof e==`string`){let t=e.trim();return!t||t.startsWith(`<`)?n:pr(t)}if(e&&typeof e==`object`){let t=e;for(let e of fr){let n=t[e];if(typeof n==`string`&&n.trim())return pr(n.trim())}}return n}var hr=`qwksearch_pinned_chats`;function gr(e){let t=e.messages?.[e.messages.length-1],n=t&&`createdAt`in t?t.createdAt:void 0;if(n){let e=new Date(n).getTime();if(!Number.isNaN(e))return new Date(e).toISOString()}return e.createdAt}function _r(){if(typeof window>`u`)return[];try{let e=localStorage.getItem(hr);return e?JSON.parse(e):[]}catch{return[]}}function vr(e){typeof window>`u`||localStorage.setItem(hr,JSON.stringify(e))}function yr(){let[e,t]=(0,n.useState)([]),[r,i]=(0,n.useState)(!0),[a,o]=(0,n.useState)(!1),[s,l]=(0,n.useState)(null),[u,d]=(0,n.useState)(!1),[f,p]=(0,n.useState)(!1),[h,g]=(0,n.useState)(!1),[_,v]=(0,n.useState)([]),[y,b]=(0,n.useState)(``),[x,S]=(0,n.useState)([]),[C,w]=(0,n.useState)(!1),{isAuthenticated:T,isLoading:E}=nt(),{incognito:D,setIncognito:O}=G();(0,n.useEffect)(()=>{v(_r())},[]);let k=(0,n.useCallback)((e,t)=>{e.preventDefault(),e.stopPropagation(),v(e=>{let n=e.includes(t)?e.filter(e=>e!==t):[...e,t];return vr(n),n})},[]),A=(0,n.useMemo)(()=>[...e].sort((e,t)=>{let n=_.includes(e.id),r=_.includes(t.id);return n&&!r?-1:!n&&r?1:0}),[e,_]),j=(0,n.useMemo)(()=>y.trim()?x:A,[y,x,A]),M=(0,n.useCallback)(async()=>{if(!E){i(!0);try{if(T){let{data:e,error:n,response:r}=await(0,c.listChats)();if(n&&r?.status===401){let e=Ie().map(e=>({...e,messageCount:e.messages?.filter(e=>e.role===`user`).length??0,lastMessageAt:gr(e)}));t(e);return}if(n)throw Error(`Failed to fetch chats: ${mr(n,r?.status)}`);t(Array.isArray(e?.chats)?e.chats:[])}else{let e=Ie().map(e=>({...e,messageCount:e.messages?.filter(e=>e.role===`user`).length??0}));t(e)}}catch(e){console.error(`Failed to fetch chat history:`,e),t([]),m.toast.error(`Failed to load chat history`)}finally{i(!1)}}},[T,E]);(0,n.useEffect)(()=>{M()},[M]);let N=(e,t)=>{e.preventDefault(),e.stopPropagation(),l(t),o(!0)},P=async()=>{if(s){d(!0);try{if(T){let{error:e,response:t}=await(0,c.deleteChatById)({path:{id:s}});if(e)throw Error(`Failed to delete chat: ${mr(e,t?.status)}`)}else ze(s);t(e=>e.filter(e=>e.id!==s)),m.toast.success(`Chat deleted`)}catch(e){m.toast.error(e.message||`Failed to delete chat`)}finally{o(!1),l(null),d(!1)}}},F=()=>{p(!0)},I=async()=>{g(!0);try{if(T){let{error:e,response:t}=await(0,c.deleteAllChats)();if(e)throw Error(`Failed to clear history: ${mr(e,t?.status)}`)}else Be();t([]),m.toast.success(`All history cleared`)}catch(e){m.toast.error(e.message||`Failed to clear history`)}finally{p(!1),g(!1)}},L=()=>{O(!D),m.toast.success(D?`Private mode off`:`Private mode on — messages won't be saved`)},R=(0,n.useCallback)(async e=>{if(!e.trim()){S([]),w(!1);return}w(!0);try{if(T){let{data:t,error:n,response:r}=await(0,c.searchChats)({query:{q:e}});if(n)throw Error(`Failed to search chats: ${mr(n,r?.status)}`);S(Array.isArray(t?.chats)?t.chats:[])}else{let t=Ie().filter(t=>{let n=t.title.toLowerCase().includes(e.toLowerCase()),r=t.messages?.some(t=>`content`in t&&t.content?.toLowerCase().includes(e.toLowerCase()));return n||r});S(t.map(e=>({...e,messageCount:e.messages?.filter(e=>e.role===`user`).length??0,lastMessageAt:gr(e)})))}}catch(e){console.error(`Failed to search chat history:`,e),S([]),m.toast.error(`Failed to search chat history`)}finally{w(!1)}},[T]);return(0,n.useEffect)(()=>{let e=setTimeout(()=>{R(y)},300);return()=>clearTimeout(e)},[y,R]),{chats:e,sortedChats:A,displayChats:j,loading:r,pinnedIds:_,togglePin:k,incognito:D,toggleIncognito:L,searchQuery:y,searchResults:x,searching:C,handleSearchChange:(0,n.useCallback)(e=>{b(e)},[]),deleteDialogOpen:a,setDeleteDialogOpen:o,chatToDelete:s,setChatToDelete:l,deleting:u,handleDeleteClick:N,handleConfirmDelete:P,clearAllDialogOpen:f,setClearAllDialogOpen:p,clearingAll:h,handleClearAllClick:F,handleConfirmClearAll:I}}function br({incognito:e,onToggleIncognito:t,showClearAll:n,onClearAll:r,searchQuery:i,onSearchChange:a}){return(0,d.jsxs)(`div`,{className:`mb-2 pb-2 border-b border-border space-y-2`,children:[(0,d.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,d.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground/80 uppercase tracking-wide`,children:`Chat History`}),(0,d.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,d.jsxs)(`button`,{onClick:t,className:`flex items-center gap-1 px-2 py-1 text-xs rounded-lg transition-colors duration-200 ${e?`text-primary bg-primary/10`:`text-muted-foreground hover:text-foreground hover:bg-secondary`}`,title:e?`Private mode on`:`Private mode`,children:[(0,d.jsx)(s.Lock,{size:12}),(0,d.jsx)(`span`,{children:`Private`})]}),n&&(0,d.jsxs)(`button`,{onClick:r,className:`flex items-center gap-1 px-2 py-1 text-xs text-muted-foreground hover:text-red-500 hover:bg-red-500/10 rounded-lg transition-colors duration-200`,title:`Clear all history`,children:[(0,d.jsx)(s.Trash2,{size:12}),(0,d.jsx)(`span`,{children:`Clear All`})]})]})]}),(0,d.jsxs)(`div`,{className:`relative`,children:[(0,d.jsx)(s.Search,{className:`absolute left-2 top-1/2 -translate-y-1/2 text-muted-foreground`,size:14}),(0,d.jsx)(`input`,{type:`text`,placeholder:`Search chats...`,value:i,onChange:e=>a(e.target.value),className:`w-full pl-7 pr-7 py-1.5 text-sm bg-secondary/50 border border-border rounded-lg focus:outline-none focus:ring-2 focus:ring-primary/50 placeholder:text-muted-foreground/50`}),i&&(0,d.jsx)(`button`,{onClick:()=>a(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground`,children:(0,d.jsx)(s.X,{size:14})})]})]})}function xr({chat:e,isPinned:n,onTogglePin:r,onDelete:i}){let a=e.messageCount??0;return(0,d.jsxs)(`div`,{className:`group flex items-center gap-1 px-2 py-1 rounded-lg hover:bg-secondary transition-colors duration-200`,children:[(0,d.jsxs)(D.default,{href:`/c/${e.id}`,onClick:n=>{t.researchAgentUIConfig.onOpenChat?.(e.id)&&n.preventDefault()},className:`flex-1 min-w-0 flex items-center gap-1.5`,children:[(0,d.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[a>0&&(0,d.jsxs)(zt,{className:`px-1.5 py-0 text-[10px] font-medium bg-zinc-200 text-zinc-700 hover:bg-zinc-200 dark:bg-zinc-700 dark:text-zinc-300 dark:hover:bg-zinc-700 border-0 rounded-md`,children:[a,`Q`]}),(0,d.jsx)(zt,{className:`px-1.5 py-0 text-[10px] font-medium bg-zinc-100 text-zinc-500 hover:bg-zinc-100 dark:bg-zinc-800 dark:text-zinc-400 dark:hover:bg-zinc-800 border-0 rounded-md`,children:L(new Date,e.createdAt)})]}),(0,d.jsxs)(`p`,{className:`text-xs text-popover-foreground truncate`,children:[n&&(0,d.jsx)(s.Pin,{size:10,className:`inline mr-1 text-primary`}),e.title]})]}),(0,d.jsx)(`button`,{onClick:t=>r(t,e.id),className:`p-1.5 rounded-lg transition-all duration-200 ${n?`opacity-100 text-primary hover:bg-primary/10`:`opacity-0 group-hover:opacity-100 text-muted-foreground hover:text-primary hover:bg-primary/10`}`,title:n?`Unpin chat`:`Pin chat`,children:(0,d.jsx)(s.Pin,{size:14})}),(0,d.jsx)(`button`,{onClick:t=>i(t,e.id),className:`opacity-0 group-hover:opacity-100 p-1.5 rounded-lg hover:bg-red-500/10 text-muted-foreground hover:text-red-500 transition-all duration-200`,title:`Delete chat`,children:(0,d.jsx)(s.Trash,{size:14})})]})}function Sr({open:e,onOpenChange:t,title:n,description:r,confirmLabel:i,loadingLabel:a,loading:o,onConfirm:s}){return(0,d.jsx)(U,{open:e,onOpenChange:e=>{!e&&!o&&t(!1)},children:(0,d.jsxs)(ue,{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`,children:[(0,d.jsx)(de,{className:`text-lg font-medium leading-6 dark:text-white`,children:n}),(0,d.jsx)(fe,{className:`text-sm dark:text-white/70 text-black/70 mt-2`,children:r}),(0,d.jsxs)(`div`,{className:`flex flex-row items-end justify-end space-x-4 mt-6`,children:[(0,d.jsx)(`button`,{onClick:()=>{o||t(!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,d.jsx)(`button`,{onClick:s,disabled:o,className:`text-red-400 text-sm hover:text-red-500 transition duration-200 disabled:opacity-50`,children:o?a:i})]})]})})}function Cr({deleteDialogOpen:e,setDeleteDialogOpen:t,chatToDelete:n,setChatToDelete:r,deleting:i,onConfirmDelete:a,clearAllDialogOpen:o,setClearAllDialogOpen:s,clearingAll:c,onConfirmClearAll:l}){return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(Sr,{open:e,onOpenChange:e=>{t(e),e||r(null)},title:`Delete Confirmation`,description:`Are you sure you want to delete this chat?`,confirmLabel:`Delete`,loadingLabel:`Deleting...`,loading:i,onConfirm:a}),(0,d.jsx)(Sr,{open:o,onOpenChange:s,title:`Clear All History`,description:`Are you sure you want to delete all your chat history? This action cannot be undone.`,confirmLabel:`Clear All`,loadingLabel:`Clearing...`,loading:c,onConfirm:l})]})}var wr={Today:(0,d.jsx)(s.Sun,{size:12}),Yesterday:(0,d.jsx)(s.Clock,{size:12}),"This Week":(0,d.jsx)(s.CalendarDays,{size:12}),Older:(0,d.jsx)(s.Archive,{size:12})};function Tr(e){let t=new Date,n=new Date(t.getFullYear(),t.getMonth(),t.getDate()),r=new Date(n.getTime()-864e5),i=new Date(n.getTime()-5184e5),a={Today:[],Yesterday:[],"This Week":[],Older:[]};for(let t of e){let e=new Date(t.createdAt);e>=n?a.Today.push(t):e>=r?a.Yesterday.push(t):e>=i?a[`This Week`].push(t):a.Older.push(t)}return[`Today`,`Yesterday`,`This Week`,`Older`].filter(e=>a[e].length>0).map(e=>({label:e,chats:a[e]}))}var Er=({showLabel:e=!1})=>{let t=yr();return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(U,{children:[(0,d.jsxs)(se,{className:e?`inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-xs text-muted-foreground bg-secondary hover:bg-secondary/80 hover:text-foreground transition-colors duration-150`:`p-2 text-muted-foreground rounded-2xl bg-background/60 backdrop-blur-md hover:bg-secondary/80 transition duration-200 hover:text-foreground border border-border/30`,children:[(0,d.jsx)(s.History,{size:e?14:18}),e&&(0,d.jsx)(`span`,{children:`History`})]}),(0,d.jsxs)(ue,{className:`max-w-[420px] p-3`,children:[(0,d.jsx)(de,{className:`sr-only`,children:`Chat History`}),(0,d.jsx)(br,{incognito:t.incognito,onToggleIncognito:t.toggleIncognito,showClearAll:t.chats.length>0&&!t.loading,onClearAll:t.handleClearAllClick,searchQuery:t.searchQuery,onSearchChange:t.handleSearchChange}),t.loading||t.searching?(0,d.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,d.jsxs)(`svg`,{"aria-hidden":`true`,className:`w-6 h-6 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,d.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,d.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`})]})}):t.searchQuery.trim()&&t.displayChats.length===0?(0,d.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No matching chats found.`})}):t.chats.length===0?(0,d.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No chats found.`})}):(0,d.jsx)(`div`,{className:`space-y-1 max-h-[500px] overflow-y-auto`,children:t.searchQuery.trim()?t.displayChats.map(e=>(0,d.jsx)(xr,{chat:e,isPinned:t.pinnedIds.includes(e.id),onTogglePin:t.togglePin,onDelete:t.handleDeleteClick},e.id)):Tr(t.displayChats).map(({label:e,chats:n})=>(0,d.jsxs)(`div`,{children:[(0,d.jsxs)(`div`,{className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-semibold text-muted-foreground/70 uppercase tracking-wider`,children:[wr[e],e]}),n.map(e=>(0,d.jsx)(xr,{chat:e,isPinned:t.pinnedIds.includes(e.id),onTogglePin:t.togglePin,onDelete:t.handleDeleteClick},e.id))]},e))}),t.chats.length>0&&(0,d.jsx)(`div`,{className:`mt-2 pt-2 border-t border-border`,children:(0,d.jsx)(D.default,{href:`/library`,className:`block text-center text-xs text-primary hover:underline`,children:`View all chats`})})]})]}),(0,d.jsx)(Cr,{deleteDialogOpen:t.deleteDialogOpen,setDeleteDialogOpen:t.setDeleteDialogOpen,chatToDelete:t.chatToDelete,setChatToDelete:t.setChatToDelete,deleting:t.deleting,onConfirmDelete:t.handleConfirmDelete,clearAllDialogOpen:t.clearAllDialogOpen,setClearAllDialogOpen:t.setClearAllDialogOpen,clearingAll:t.clearingAll,onConfirmClearAll:t.handleConfirmClearAll})]})},Dr=e=>new Date(e.lastMessageAt||e.createdAt).getTime();function Or(){let{chats:e,loading:n}=yr(),r=[...e].sort((e,t)=>Dr(t)-Dr(e)).slice(0,5);return n||r.length===0?null:(0,d.jsxs)(`div`,{className:`flex flex-row items-center justify-center gap-2 flex-wrap`,children:[(0,d.jsx)(Er,{showLabel:!0}),r.map(e=>{let n=Tn(e.lastMessageAt||e.createdAt);return(0,d.jsxs)(D.default,{href:`/c/${e.id}`,onClick:n=>{t.researchAgentUIConfig.onOpenChat?.(e.id)&&n.preventDefault()},className:`flex items-center gap-1.5 px-3 py-1 rounded-full text-xs text-muted-foreground bg-secondary hover:bg-secondary/80 hover:text-foreground transition-colors duration-150 max-w-[220px]`,title:e.title,children:[(0,d.jsx)(`span`,{className:`truncate`,children:e.title}),n&&(0,d.jsx)(`span`,{className:`italic text-muted-foreground/70 whitespace-nowrap`,children:n})]},e.id)})]})}function kr({listFooterLinks:e=[],optionShowIcons:t=!0,optionBackgroundColor:r=`bg-black/40`}){let[i,a]=(0,n.useState)(!1),o=(0,n.useRef)(null);(0,n.useEffect)(()=>{if(!i)return;let e=e=>{o.current&&!o.current.contains(e.target)&&a(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[i]);let c=()=>e.map(({url:e,text:n,icon:r,onClick:i})=>{let a=r?s[r]:null,o=e.startsWith(`http`),c=o?{target:`_blank`,rel:`noopener noreferrer`}:{},l=(0,d.jsxs)(d.Fragment,{children:[t&&a&&(0,d.jsx)(a,{size:14}),(0,d.jsx)(`span`,{className:`font-semibold tracking-wide text-md`,style:{fontVariant:`small-caps`},children:n}),(0,d.jsx)(`span`,{className:`absolute bottom-0 left-0 w-0 h-0.5 bg-current transition-all duration-300 group-hover:w-full group-hover:shadow-[0_0_8px_rgba(255,255,255,0.6)]`})]});return i?(0,d.jsx)(`button`,{type:`button`,onClick:i,className:`relative group inline-flex items-center gap-1 hover:text-white hover:drop-shadow-[0_0_8px_rgba(255,255,255,0.8)] transition-all duration-300 whitespace-nowrap`,children:l},e):o?(0,d.jsx)(`a`,{href:e,...c,className:`relative group inline-flex items-center gap-1 hover:text-white hover:drop-shadow-[0_0_8px_rgba(255,255,255,0.8)] transition-all duration-300 whitespace-nowrap`,children:l},e):(0,d.jsx)(D.default,{href:e,className:`relative group inline-flex items-center gap-1 hover:text-white hover:drop-shadow-[0_0_8px_rgba(255,255,255,0.8)] transition-all duration-300 whitespace-nowrap`,children:l},e)}),l=s.Info;return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`div`,{className:`hidden md:flex absolute bottom-2 left-1/2 -translate-x-1/2 text-slate-200 text-xs z-20 ${r} rounded-lg px-2 py-1 shadow-lg hover:shadow-xl hover:-translate-y-1 transition-all duration-300 flex-wrap items-center justify-center gap-x-6 max-w-[90vw]`,children:(0,d.jsx)(`div`,{className:`max-w-4xl mx-auto grid grid-cols-3 gap-2`,children:c()})}),(0,d.jsxs)(`div`,{ref:o,className:`md:hidden fixed top-[calc(8px+env(safe-area-inset-top,0px))] right-2 z-30`,children:[i&&(0,d.jsx)(`div`,{className:`absolute top-full right-0 mt-2 text-slate-200 text-xs ${r} rounded-lg px-3 py-2 shadow-lg flex flex-col items-start gap-2 backdrop-blur-sm`,children:c()}),(0,d.jsx)(`button`,{type:`button`,onClick:()=>a(e=>!e),"aria-label":i?`Hide links`:`Show links`,"aria-expanded":i,className:`flex items-center justify-center h-8 w-8 rounded-full text-slate-200 ${r} shadow-lg backdrop-blur-sm hover:text-white transition-all duration-300`,children:l?(0,d.jsx)(l,{size:16}):`i`})]})]})}function Ar({open:e,onOpenChange:n}){return(0,d.jsx)(U,{open:e,onOpenChange:n,children:(0,d.jsxs)(ue,{className:`w-full max-w-md rounded-2xl bg-light-secondary dark:bg-dark-secondary border border-light-200 dark:border-dark-200 p-6 text-center align-middle shadow-xl`,children:[(0,d.jsx)(de,{className:`text-lg font-medium leading-6 dark:text-white`,children:`Download QwkSearch`}),(0,d.jsx)(fe,{className:`text-sm dark:text-white/70 text-black/70 mt-2`,children:`Get QwkSearch on your browser or desktop.`}),(0,d.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-3 mt-6`,children:[(0,d.jsx)(k.DownloadAppButton,{platform:`chrome-extension`,href:t.researchAgentUIConfig.downloadChromeUrl,autoHighlight:!0}),(0,d.jsx)(k.DownloadAppButton,{platform:`windows`,appId:t.researchAgentUIConfig.downloadWindowsStoreId,autoHighlight:!0})]})]})})}function jr(){let e=`hyZbH3n.mp4,iOeZcCk.mp4,dUZlxYE.mp4,GpWeP6E.gif,LuKUsLE.png,w7X11Dd.png,MHmVtCr.png,HmnUAee.png,vKP22VU.png,l1lsV39.png,Ku8F2qc.png,KUEXtwm.png,vvKFPmY.png,5p8eaEf.png,VAKuJcG.png,sTMPtQW.png,m0gHbZZ.png,cKu7dWQ.png,ogfefYD.png,ey5vAae.png,twuLrvk.png,ELILiYt.png,9el5qpP.png,Up6xTkk.png,W1XKBo0.png,1Y6xvW0.png,JXOytMz.png,DNiI6pp.png,XDv5s6p.jpeg,eRwiRJ9.jpeg,DRAfJoc.jpeg,ASVRQ1G.jpeg,35svwUT.jpeg,81xLiVI.jpeg,6kod2Em.jpeg,eU0C8zt.jpeg,Bv0PBY8.jpeg,DQNbjIZ.jpeg,2uACPqZ.jpeg,XEKltMF.jpeg,WHgLfBm.jpeg,QFYM0Fw.jpeg,K12HCao.jpeg,oN8rtsE.jpeg,9fGnrns.jpeg,2ONJJeW.jpeg,DO23Va7.jpeg,QaKeoXk.jpeg,QU5oCBR.jpeg,MhlYZmh.jpeg,ylL1ToB.jpeg,AWWsCv8.jpeg,Tk9Tzzj.jpeg`.split(`,`);return`https://i.imgur.com/`+e[Math.floor(Math.random()*e.length)]}function Mr(e){return e?e.split(/\r?\n/).map(e=>e.trim()).filter(Boolean).map(e=>{let t=e.split(`,`).map(e=>e.trim()),n=Number(t[t.length-2]),r=Number(t[t.length-1]);return t.length>=2&&t[t.length-2]!==``&&t[t.length-1]!==``&&Number.isFinite(n)&&Number.isFinite(r)?{label:t.slice(0,t.length-2).filter(Boolean).join(`, `)||void 0,latitude:n,longitude:r}:{label:e}}):[]}function Nr(){let{sendMessage:e}=G(),[r,i]=(0,n.useState)(null),[a,o]=(0,n.useState)(null),[s,c]=(0,n.useState)(!1),[l,u]=(0,n.useState)(!1),[f,p]=(0,n.useState)([]),[m,h]=(0,n.useState)(!0),[g,_]=(0,n.useState)(5),[v,y]=(0,n.useState)(12),[b,x]=(0,n.useState)(`fahrenheit`),[C,w]=(0,n.useState)(null),[T,E]=(0,n.useState)(!0),[D,O]=(0,n.useState)(6),[k,M]=(0,n.useState)(!0),[N,P]=(0,n.useState)(!1),[F,I]=(0,n.useState)(!1),L=t.researchAgentUIConfig.footerLinks.map(e=>e.url===`/#downloads`?{...e,onClick:()=>u(!0)}:e);(0,n.useEffect)(()=>{let e=()=>{p(Mr(localStorage.getItem(`weatherLocations`))),h(localStorage.getItem(`showWeatherWidget`)!==`false`),_(Number(localStorage.getItem(`weatherForecastDays`))||5),y(Number(localStorage.getItem(`weatherForecastHours`))||12),x(localStorage.getItem(`weatherTemperatureUnit`)===`celsius`?`celsius`:`fahrenheit`),w(localStorage.getItem(`trendingNewsApiUrl`)),E(localStorage.getItem(`showTrendingNewsWidget`)!==`false`),O(Number(localStorage.getItem(`trendingNewsMaxTopics`))||6),M(localStorage.getItem(`trendingNewsShowImages`)!==`false`),P(localStorage.getItem(`orbHoverGlow`)===`true`),I(localStorage.getItem(`cursorGlowTrail`)===`true`)};return e(),window.addEventListener(`client-config-changed`,e),window.addEventListener(`storage`,e),()=>{window.removeEventListener(`client-config-changed`,e),window.removeEventListener(`storage`,e)}},[]),(0,n.useEffect)(()=>{if(localStorage.getItem(`showBackgroundArt`)===`false`)return;i(jr());let e=setInterval(()=>{let e=jr();o(e),c(!0),setTimeout(()=>{i(e),c(!1),o(null)},1e3)},2e4);return()=>clearInterval(e)},[]);let R=e=>e.endsWith(`.webm`)||e.endsWith(`.mp4`),z=(e,t)=>R(e)?(0,d.jsx)(`video`,{src:e,autoPlay:!0,loop:!0,muted:!0,playsInline:!0,className:`absolute inset-0 w-full h-full object-cover transition-opacity duration-1000 ${t}`},e):(0,d.jsx)(`img`,{src:e,alt:``,className:`absolute inset-0 w-full h-full object-cover transition-opacity duration-1000 ${t}`},e);return(0,d.jsxs)(`div`,{className:`relative min-h-screen w-full`,children:[(0,d.jsxs)(`div`,{className:`absolute inset-0 z-0`,children:[r&&z(r,s?`opacity-0`:`opacity-30`),a&&z(a,s?`opacity-30`:`opacity-0`),F&&(0,d.jsx)(ur,{})]}),(0,d.jsx)(`div`,{className:`relative z-10`,children:(0,d.jsxs)(`div`,{className:`flex flex-col items-center justify-end md:justify-center min-h-[calc(100dvh-64px)] md:min-h-screen max-w-screen-sm mx-auto p-2 pb-1 md:pb-2`,children:[(0,d.jsx)(`div`,{style:{height:`200px`,width:`100%`,display:`flex`,alignItems:`center`,justifyContent:`center`},className:N?void 0:`pointer-events-none`,children:(0,d.jsx)(S.default,{autoRandomize:!0,onSphereClick:()=>console.log(`Sphere clicked`),className:`my-custom-class`})}),(0,d.jsxs)(`div`,{className:`w-full max-w-2xl mt-8 space-y-2`,children:[(0,d.jsx)(Or,{}),(m||T)&&(0,d.jsxs)(`div`,{className:`flex flex-col gap-2 w-full`,children:[T&&(0,d.jsx)(j.TrendingNews,{compact:!0,expandable:!0,maxTopics:D,showImages:k,apiEndpoint:C||void 0,className:`rounded-2xl w-full`,style:{background:`rgba(255,255,255,0.08)`,border:`1px solid rgba(255,255,255,0.15)`,color:`inherit`,backdropFilter:`blur(8px)`,maxWidth:`100%`}}),m&&(0,d.jsx)(A.WeatherForecast,{compact:!0,forecastDays:g,forecastHours:v,temperatureUnit:b,locations:f.length>0?f:void 0,className:`rounded-2xl w-full`,style:{background:`rgba(255,255,255,0.08)`,border:`1px solid rgba(255,255,255,0.15)`,color:`inherit`,backdropFilter:`blur(8px)`}})]}),(0,d.jsx)(In,{})]})]})}),(0,d.jsx)(kr,{listFooterLinks:L}),(0,d.jsx)(Ar,{open:l,onOpenChange:u})]})}var Pr=()=>(0,d.jsxs)(`svg`,{"aria-hidden":`true`,className:`w-8 h-8 text-border fill-secondary animate-spin`,viewBox:`0 0 100 101`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,d.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,d.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`})]});function Fr(){return(0,d.jsx)(`div`,{className:`flex min-h-screen flex-col items-center justify-center p-8`,children:(0,d.jsxs)(`div`,{className:`max-w-2xl w-full space-y-6 bg-light-secondary dark:bg-dark-secondary rounded-lg p-8 border border-black/10 dark:border-white/10`,children:[(0,d.jsxs)(`div`,{className:`space-y-2`,children:[(0,d.jsx)(`h1`,{className:`text-2xl font-semibold text-black dark:text-white`,children:`⚠️ Configuration Required`}),(0,d.jsx)(`p`,{className:`text-black/70 dark:text-white/70`,children:`No AI model providers are configured. Add at least one API key to continue.`})]}),(0,d.jsxs)(`div`,{className:`space-y-4`,children:[(0,d.jsx)(`h2`,{className:`text-lg font-medium text-black dark:text-white`,children:`Quick Setup:`}),(0,d.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,d.jsxs)(`div`,{className:`bg-black/5 dark:bg-white/5 rounded p-4`,children:[(0,d.jsx)(`p`,{className:`font-medium text-black dark:text-white mb-2`,children:`1. Create environment file:`}),(0,d.jsx)(`code`,{className:`block bg-black/10 dark:bg-white/10 rounded p-2 text-xs overflow-x-auto`,children:`apps/qwksearch-web/.env.local`})]}),(0,d.jsxs)(`div`,{className:`bg-black/5 dark:bg-white/5 rounded p-4`,children:[(0,d.jsx)(`p`,{className:`font-medium text-black dark:text-white mb-2`,children:`2. Add required variables:`}),(0,d.jsx)(`pre`,{className:`block bg-black/10 dark:bg-white/10 rounded p-3 text-xs overflow-x-auto text-black/80 dark:text-white/80`,children:`# Database
32
+ `,type:`button`,"aria-label":`Send message`,children:(0,d.jsx)(Z.ArrowUp,{className:`w-4 h-4`})}),(0,d.jsx)(`div`,{className:`absolute bottom-full left-1/2 -translate-x-1/2 mb-2 px-2 py-1 bg-[#1F1E1D] dark:bg-[#EEEEEC] text-[11px] font-medium rounded-[6px] opacity-0 group-hover:opacity-100 transition-opacity whitespace-nowrap pointer-events-none z-50 shadow-sm tracking-wide`,children:(0,d.jsx)(`span`,{className:`text-[#ECECEC] dark:text-[#1F1E1D]`,children:t?`Stop generating`:`Send message`})})]})]})]}),(0,d.jsx)(u.AnimatePresence,{children:se&&W>0&&(0,d.jsx)(u.motion.div,{ref:e=>{e&&v.current&&v.current.contains(e)},initial:{opacity:0,y:le===`above`?4:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:le===`above`?4:-4},transition:{duration:.12},className:`absolute left-2 right-2 md:left-0 md:right-0 z-20 rounded-2xl bg-gray-50 dark:bg-[#30302E] border border-bg-300 dark:border-transparent shadow-xl overflow-hidden ${le===`above`?`bottom-full`:`top-full`}`,onMouseDown:e=>e.preventDefault(),children:(0,d.jsxs)(`ul`,{className:`max-h-72 overflow-y-auto custom-scrollbar py-1`,children:[V.map((e,t)=>(0,d.jsx)(`li`,{children:(0,d.jsxs)(`button`,{type:`button`,onMouseEnter:()=>U(t),onClick:()=>he(e),className:`w-full text-left px-4 py-1.5 text-[15px] flex items-center gap-3 transition-colors ${t===H?`bg-bg-200 text-text-100`:`text-text-200 hover:bg-bg-100 dark:hover:bg-[#3A3A38]`}`,children:[(0,d.jsx)(`span`,{className:`w-5 h-5 flex items-center justify-center rounded bg-bg-200 dark:bg-[#3A3A38] text-[11px] font-semibold text-text-400 shrink-0`,children:t+1}),(0,d.jsx)(`img`,{src:e.favicon,alt:``,className:`w-4 h-4 rounded-sm shrink-0`}),(0,d.jsx)(`span`,{className:`truncate font-medium`,children:e.name||e.domain}),(0,d.jsx)(`span`,{className:`truncate text-[13px] text-text-400 shrink-0`,children:e.domain}),Number.isFinite(e.rank)&&e.rank<2**53-1&&(0,d.jsxs)(`span`,{className:`ml-auto shrink-0 px-1.5 py-0.5 rounded-full text-[10px] font-semibold tabular-nums bg-bg-200 dark:bg-[#3A3A38] text-text-400`,children:[`#`,e.rank.toLocaleString()]})]})},`domain-${e.domain}`)),ie.map((e,t)=>{let n=V.length+t;return(0,d.jsx)(`li`,{children:(0,d.jsxs)(`button`,{type:`button`,onMouseEnter:()=>U(n),onClick:()=>me(e),className:`w-full text-left px-4 py-1.5 text-[15px] flex items-center gap-3 transition-colors ${n===H?`bg-bg-200 text-text-100`:`text-text-200 hover:bg-bg-100 dark:hover:bg-[#3A3A38]`}`,children:[(0,d.jsx)(`span`,{className:`w-5 h-5 flex items-center justify-center rounded bg-bg-200 dark:bg-[#3A3A38] text-[11px] font-semibold text-text-400 shrink-0`,children:n+1}),(0,d.jsx)(s.Search,{className:`w-4 h-4 text-text-400 shrink-0`}),(0,d.jsx)(`span`,{className:`truncate`,children:e})]})},`${e}-${t}`)})]})})}),C&&(0,d.jsxs)(`div`,{className:`absolute inset-0 bg-bg-200/90 border-2 border-dashed border-accent rounded-[28px] z-50 flex flex-col items-center justify-center backdrop-blur-sm pointer-events-none`,children:[(0,d.jsx)(Z.Archive,{className:`w-10 h-10 text-accent mb-2 animate-bounce`}),(0,d.jsx)(`p`,{className:`text-accent font-medium`,children:`Drop files to upload`})]})]})},Kn=n.forwardRef(({className:e,...t},n)=>(0,d.jsx)(`span`,{ref:n,className:F(`absolute w-px h-px p-0 -m-px overflow-hidden whitespace-nowrap border-0`,e),style:{clip:`rect(0, 0, 0, 0)`,clipPath:`inset(50%)`},...t}));Kn.displayName=`VisuallyHidden`;var qn=({onClose:e})=>(0,d.jsx)(`div`,{className:`flex items-center justify-between bg-secondary px-4 py-3 border-b border-border`,children:(0,d.jsx)(`button`,{onClick:e,className:`rounded-md p-1 hover:bg-accent transition-colors`,children:(0,d.jsx)(s.X,{className:`h-5 w-5`})})}),Jn=(0,x.cva)(`inline-flex cursor-pointer items-center justify-center gap-2 whitespace-nowrap rounded-2xl text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive`,{variants:{variant:{default:`bg-primary text-primary-foreground hover:bg-primary/90`,destructive:`bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60`,outline:`border-[1.5px] bg-background hover:bg-accent hover:text-accent-foreground dark:bg-card dark:hover:bg-card/50`,secondary:`bg-secondary text-secondary-foreground hover:bg-secondary/80`,ghost:`hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50`,link:`text-primary underline-offset-4 hover:underline`},size:{default:`h-9 px-4 py-2 has-[>svg]:px-3`,sm:`h-8 gap-1.5 px-3 has-[>svg]:px-2.5`,lg:`h-10 px-6 has-[>svg]:px-4`,icon:`size-9`}},defaultVariants:{variant:`default`,size:`default`}});function Q({className:e,variant:t,size:n,asChild:r=!1,...i}){return(0,d.jsx)(r?b.Slot:`button`,{"data-slot":`button`,className:F(Jn({variant:t,size:n,className:e})),...i})}var Yn={ask:{alt:!0,key:`a`},suggest:{alt:!0,key:`s`},copy:{alt:!0,key:`c`},highlight:{alt:!0,key:`h`},favorite:{alt:!0,key:`f`},open:{alt:!0,key:`o`},zoomOut:{alt:!0,key:`-`},zoomReset:{alt:!0,key:`0`},zoomIn:{alt:!0,key:`=`},close:{alt:!1,key:`Escape`}},Xn=typeof navigator<`u`&&/Mac|iPhone|iPad|iPod/.test(navigator.platform||navigator.userAgent||``);function Zn(e){let{alt:t,key:n}=Yn[e],r=n===`Escape`?`Esc`:n.length===1?n.toUpperCase():n;return t?Xn?`⌥${r}`:`Alt+${r}`:r}var Qn=F(`h-9 w-9 rounded-xl transition-all duration-200`,`hover:bg-muted/80 hover:text-foreground text-muted-foreground`),$=({label:e,action:t,children:n})=>(0,d.jsxs)(K,{children:[(0,d.jsx)(q,{asChild:!0,children:n}),(0,d.jsx)(J,{side:`bottom`,children:(0,d.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,d.jsx)(`span`,{children:e}),t&&(0,d.jsx)(`kbd`,{className:`rounded bg-primary-foreground/20 px-1 py-0.5 text-[10px] font-semibold leading-none tracking-wide`,children:Zn(t)})]})})]}),$n=({isLoadingAI:e,isLoadingFollowups:t,isLoadingFavorite:n,isFavorited:r,isHighlightMode:i,articleUrl:a,fontScale:o,onAskClick:c,onSuggestClick:l,onCopyClick:u,onShareClick:f,onFavoriteClick:p,onHighlightToggle:m,onZoomIn:h,onZoomOut:g,onZoomReset:_,onClose:v})=>{let y=h||g,b=Math.round((o??1)*100);return(0,d.jsxs)(`div`,{className:`flex flex-nowrap items-center gap-1 rounded-2xl border border-muted bg-gradient-to-b from-background to-muted/30 p-1 shadow-sm`,children:[(0,d.jsx)($,{label:`Ask AI about this article`,action:`ask`,children:(0,d.jsxs)(Q,{onClick:c,disabled:e,variant:`ghost`,size:`sm`,className:F(`flex items-center gap-2 px-3 h-9 rounded-xl transition-all duration-200`,`hover:bg-muted/80 hover:text-foreground text-muted-foreground`),children:[(0,d.jsx)(s.Bot,{className:`size-4`}),(0,d.jsx)(`span`,{className:`font-medium`,children:e?`...`:`Ask`})]})}),(0,d.jsx)($,{label:`Suggest follow-up questions`,action:`suggest`,children:(0,d.jsxs)(Q,{onClick:l,disabled:t,variant:`ghost`,size:`sm`,className:F(`flex items-center gap-2 px-3 h-9 rounded-xl transition-all duration-200`,`hover:bg-muted/80 hover:text-foreground text-muted-foreground`),children:[(0,d.jsx)(s.MessageCircleQuestion,{className:`size-4`}),(0,d.jsx)(`span`,{className:`font-medium`,children:`Suggest`})]})}),(0,d.jsx)($,{label:`Copy article`,action:`copy`,children:(0,d.jsx)(Q,{onClick:u,variant:`ghost`,size:`icon`,className:Qn,children:(0,d.jsx)(s.Clipboard,{className:`size-4`})})}),(0,d.jsx)($,{label:`Share article`,children:(0,d.jsx)(Q,{onClick:f,variant:`ghost`,size:`icon`,className:Qn,children:(0,d.jsx)(s.Share2,{className:`size-4`})})}),(0,d.jsx)($,{label:i?`Disable highlighting`:`Enable highlighting`,action:`highlight`,children:(0,d.jsx)(Q,{onClick:m,variant:`ghost`,size:`icon`,className:F(`h-9 w-9 rounded-xl transition-all duration-200`,i?`text-yellow-500 bg-yellow-50 dark:bg-yellow-950/30 hover:bg-yellow-100 dark:hover:bg-yellow-950/50`:`hover:bg-muted/80 hover:text-foreground text-muted-foreground`),children:(0,d.jsx)(s.Highlighter,{className:`size-4`})})}),(0,d.jsx)($,{label:r?`Remove from favorites`:`Add to favorites`,action:`favorite`,children:(0,d.jsx)(Q,{onClick:p,disabled:n,variant:`ghost`,size:`icon`,className:F(`h-9 w-9 rounded-xl transition-all duration-200`,r?`text-yellow-500 hover:text-yellow-600 hover:bg-yellow-50 dark:hover:bg-yellow-950/30`:`hover:bg-muted/80 hover:text-foreground text-muted-foreground`),children:(0,d.jsx)(s.Star,{className:F(`size-4`,r&&`fill-yellow-400`)})})}),a&&(0,d.jsx)($,{label:`Open in new tab`,action:`open`,children:(0,d.jsx)(Q,{asChild:!0,variant:`ghost`,size:`icon`,className:Qn,children:(0,d.jsx)(`a`,{href:a,target:`_blank`,rel:`noopener noreferrer`,children:(0,d.jsx)(s.ExternalLink,{className:`size-4`})})})}),y&&(0,d.jsxs)(`div`,{className:`ml-auto flex items-center gap-0.5 rounded-xl border border-muted/60 bg-muted/20 px-1`,children:[(0,d.jsx)($,{label:`Zoom out`,action:`zoomOut`,children:(0,d.jsx)(Q,{onClick:g,variant:`ghost`,size:`icon`,className:`h-8 w-8 rounded-lg text-muted-foreground transition-all duration-200 hover:bg-muted/80 hover:text-foreground`,children:(0,d.jsx)(s.ZoomOut,{className:`size-4`})})}),(0,d.jsx)($,{label:`Reset zoom`,action:`zoomReset`,children:(0,d.jsxs)(`button`,{type:`button`,onClick:_,className:`min-w-[3rem] rounded-md px-1 text-center text-xs font-medium tabular-nums text-muted-foreground transition-colors hover:text-foreground`,children:[b,`%`]})}),(0,d.jsx)($,{label:`Zoom in`,action:`zoomIn`,children:(0,d.jsx)(Q,{onClick:h,variant:`ghost`,size:`icon`,className:`h-8 w-8 rounded-lg text-muted-foreground transition-all duration-200 hover:bg-muted/80 hover:text-foreground`,children:(0,d.jsx)(s.ZoomIn,{className:`size-4`})})})]}),(0,d.jsx)($,{label:`Close`,action:`close`,children:(0,d.jsx)(Q,{onClick:v,variant:`ghost`,size:`icon`,className:F(Qn,!y&&`ml-auto`),children:(0,d.jsx)(s.X,{className:`size-4`})})})]})},er=({value:e,onChange:t,onSubmit:n})=>(0,d.jsx)(`div`,{className:`relative`,children:(0,d.jsx)(`input`,{value:e,onChange:e=>t(e.target.value),onKeyDown:e=>e.key===`Enter`&&n(),type:`text`,placeholder:`Ask AI any question...`,className:`w-full px-3 py-2 text-sm rounded-md border border-input bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-ring`})}),tr=({questions:e,isLoading:r,error:i,onQuestionClick:a})=>{let o=n.default.useMemo(()=>{let t=[];return e.forEach(e=>{e.includes(`?`)&&e.split(`?`).length>2?e.split(`?`).map(e=>e.trim()).filter(Boolean).forEach(e=>{t.push(e.endsWith(`?`)?e:`${e}?`)}):t.push(e)}),t},[e]);return(0,d.jsxs)(d.Fragment,{children:[o.length>0&&(0,d.jsxs)(`div`,{className:`space-y-3 bg-accent/30 rounded-lg p-4 border border-primary/20`,children:[(0,d.jsx)(`h3`,{className:`text-sm font-bold text-primary mb-2`,children:`💡 Suggested Follow-up Questions`}),(0,d.jsxs)(`div`,{className:`space-y-2`,children:[(0,d.jsx)(`div`,{onClick:()=>a(t.researchAgentUIConfig.defaultSummarizePrompt),className:`cursor-pointer rounded-md p-3 text-sm font-semibold hover:bg-primary/10 bg-background border border-primary/30 transition-all hover:border-primary shadow-sm hover:shadow-md`,children:t.researchAgentUIConfig.defaultSummarizePrompt}),o.map((e,t)=>(0,d.jsx)(`div`,{onClick:()=>a(e),className:`cursor-pointer rounded-md p-3 text-sm font-semibold hover:bg-primary/10 bg-background border border-border transition-all hover:border-primary shadow-sm hover:shadow-md`,dangerouslySetInnerHTML:{__html:e}},t))]})]}),r&&(0,d.jsx)(`div`,{className:`flex justify-center`,children:(0,d.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-blue-500`})}),i&&(0,d.jsx)(`div`,{className:`bg-red-500 text-white p-2 rounded-md text-sm`,children:i})]})},nr=({response:e,isLoading:t,error:n})=>(0,d.jsxs)(d.Fragment,{children:[t&&(0,d.jsx)(`div`,{className:`flex justify-center`,children:(0,d.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-blue-500`})}),e&&(0,d.jsx)(`div`,{ref:e=>{},className:`bg-muted rounded-lg shadow-md p-4`,dangerouslySetInnerHTML:{__html:e}}),n&&(0,d.jsx)(`div`,{className:`bg-red-500 text-white p-2 rounded-md text-sm`,children:n})]}),rr=({html:e,isHighlightMode:t=!1,fontScale:r=1})=>{let[i,a]=(0,n.useState)(``);return(0,n.useEffect)(()=>{a(E.default.sanitize(e||``,{ADD_TAGS:[`figure`,`figcaption`],ADD_ATTR:[`loading`]}))},[e]),(0,d.jsx)(`div`,{className:[`prose prose-neutral dark:prose-invert max-w-none`,`prose-p:leading-[1.9] prose-li:leading-[1.9] prose-p:my-5 prose-li:my-1.5`,`prose-headings:font-semibold prose-headings:tracking-tight prose-headings:leading-snug`,`prose-h1:mt-8 prose-h2:mt-8 prose-h3:mt-6`,`prose-blockquote:leading-[1.8] prose-blockquote:border-l-2`,`prose-img:rounded-lg prose-img:my-6`,t?`select-text`:``].join(` `),style:{fontSize:`${r}em`,fontFamily:`ui-serif, Georgia, Cambria, "Times New Roman", Times, serif`},dangerouslySetInnerHTML:{__html:i}})},ir=({article:e,isHighlightMode:t,fontScale:n=1})=>(0,d.jsx)(`div`,{className:`border-t border-border pt-6`,children:(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`flex items-start justify-between mb-2`}),e.cite&&(0,d.jsx)(`div`,{className:`mb-3 text-sm text-muted-foreground`,dangerouslySetInnerHTML:{__html:e.cite}}),(0,d.jsx)(`div`,{className:`mb-3 text-xs text-muted-foreground space-y-1`,children:e.word_count&&(0,d.jsxs)(`p`,{children:[(0,d.jsx)(`span`,{className:`font-semibold`,children:`Words:`}),` `,e.word_count.toLocaleString()]})}),(0,d.jsx)(`div`,{id:`article-content`,children:(0,d.jsx)(rr,{html:e.html||``,isHighlightMode:t,fontScale:n})})]})}),ar=/(?:https?:\/\/)?(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)/g,or=/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g;function sr(e){return e.includes(`](`)||e.includes(`)[`)?!1:/\.(com|org|net|io|dev|co|uk|de|fr|it|es|jp|cn|in|br|au|ca|us|gov|edu|mil|int|xyz|info|app|tech|online|site|website|store|shop|blog|news|tv|me|cc|ws|name|mobi|asia|tel|travel|jobs|pro|museum|coop|aero|arpa|biz|cat|jobs|post|tel|xxx|ac|ad|ae|af|ag|ai|al|am|ao|aq|ar|as|at|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cw|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|za|zm|zw)(?:\/|$)/i.test(e)}function cr(e){return/^https?:\/\//i.test(e)?e:`https://${e}`}function lr(e){if(!e||typeof e!=`string`)return e;let t=e,n=[],r;for(or.lastIndex=0;(r=or.exec(t))!==null;){let e=r[0],i=r.index,a=t.substring(0,i),o=t.substring(i+e.length);!a.endsWith(`](`)&&!o.startsWith(`)`)&&n.push({email:e,index:i})}for(let e=n.length-1;e>=0;e--){let{email:r,index:i}=n[e];t=t.substring(0,i)+`[${r}](mailto:${r})`+t.substring(i+r.length)}let i=[],a;for(ar.lastIndex=0;(a=ar.exec(t))!==null;){let e=a[0],n=a.index;if(or.test(e))continue;let r=t.substring(0,n),o=t.substring(n+e.length);if(r.endsWith(`](`)||o.startsWith(`)`)||(r.match(/```/g)||[]).length%2!=0)continue;let s=r.lastIndexOf("`");if(s!==-1){let e=t.substring(s+1).indexOf("`");if(e!==-1&&e>n-s-1)continue}sr(e)&&i.push({url:e,index:n})}for(let e=i.length-1;e>=0;e--){let{url:n,index:r}=i[e],a=cr(n);t=t.substring(0,r)+`[${n}](${a})`+t.substring(r+n.length)}return t}function ur(e){return!e||e.startsWith(`http://`)||e.startsWith(`https://`)||e.includes(`://`)?!1:e.startsWith(`/`)||e.startsWith(`#`)}function dr(e,t){if(t.startsWith(`#`)){e.preventDefault();let n=t.substring(1),r=document.getElementById(n);r&&r.scrollIntoView({behavior:`smooth`,block:`start`})}}function fr({code:e}){let[t,r]=(0,n.useState)(!1),i=(0,n.useCallback)(async()=>{try{await navigator.clipboard.writeText(e),r(!0),setTimeout(()=>r(!1),2e3)}catch(e){console.error(`Failed to copy:`,e)}},[e]);return(0,d.jsx)(`button`,{onClick:i,className:F(`absolute top-3 right-3 p-1.5 rounded-md`,`opacity-0 group-hover:opacity-100 transition-opacity duration-150`,`bg-zinc-200/80 hover:bg-zinc-300 dark:bg-zinc-700/80 dark:hover:bg-zinc-600`,`text-zinc-600 hover:text-zinc-800 dark:text-zinc-400 dark:hover:text-zinc-200`,`focus:outline-none focus:ring-1 focus:ring-zinc-400 dark:focus:ring-zinc-500`),"aria-label":t?`Copied!`:`Copy code`,children:t?(0,d.jsx)(s.Check,{className:`h-4 w-4 text-green-600 dark:text-green-400`}):(0,d.jsx)(s.Copy,{className:`h-4 w-4`})})}function pr({children:e}){let t=(0,n.useRef)(null),[r,i]=(0,n.useState)(``);return(0,n.useEffect)(()=>{if(t.current){let e=t.current.querySelector(`code`);if(e){let t=e.textContent||``;i(t.trim())}}},[e]),(0,d.jsxs)(`div`,{className:`relative group my-5`,children:[(0,d.jsx)(`pre`,{ref:t,className:F(`p-4 rounded-xl overflow-x-auto`,`bg-zinc-100 dark:bg-zinc-900`,`border border-zinc-200 dark:border-zinc-800`,`text-[13px] font-mono leading-relaxed`,`text-zinc-800 dark:text-zinc-200`,`[&_code]:bg-transparent [&_code]:text-inherit [&_code]:p-0`),children:e}),r&&(0,d.jsx)(fr,{code:r})]})}var mr=n.default.memo(({content:e,className:t,isStreaming:n=!1})=>{if(!e)return(0,d.jsx)(`div`,{className:F(`text-muted-foreground text-sm`,t),children:`No content`});let r=lr(e);return(0,d.jsx)(`div`,{className:F(`kortix-markdown`,t),children:(0,d.jsx)(O.Streamdown,{isAnimating:n,components:{h1:({children:e})=>(0,d.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight text-foreground mt-8 mb-4 first:mt-0 pb-2 border-b border-border/40`,children:e}),h2:({children:e})=>(0,d.jsx)(`h2`,{className:`text-xl font-semibold tracking-tight text-foreground mt-8 mb-3 first:mt-0`,children:e}),h3:({children:e})=>(0,d.jsx)(`h3`,{className:`text-lg font-semibold text-foreground mt-6 mb-2 first:mt-0`,children:e}),h4:({children:e})=>(0,d.jsx)(`h4`,{className:`text-base font-semibold text-foreground mt-5 mb-2 first:mt-0`,children:e}),h5:({children:e})=>(0,d.jsx)(`h5`,{className:`text-sm font-semibold text-foreground mt-4 mb-1 first:mt-0`,children:e}),h6:({children:e})=>(0,d.jsx)(`h6`,{className:`text-sm font-medium text-muted-foreground mt-4 mb-1 first:mt-0 uppercase tracking-wide`,children:e}),p:({children:e})=>(0,d.jsx)(`p`,{className:`text-sm text-foreground leading-relaxed my-4 first:mt-0 last:mb-0 [&:has(img)]:my-0`,children:e}),ul:({children:e})=>(0,d.jsx)(`ul`,{className:`my-4 ml-6 list-disc marker:text-muted-foreground/60 space-y-2 first:mt-0 last:mb-0 text-sm`,children:e}),ol:({children:e})=>(0,d.jsx)(`ol`,{className:`my-4 ml-6 list-decimal marker:text-muted-foreground/60 marker:font-medium space-y-2 first:mt-0 last:mb-0 text-sm`,children:e}),li:({children:e})=>(0,d.jsx)(`li`,{className:`text-sm text-foreground leading-relaxed pl-1`,children:e}),a:({href:e,children:t})=>{let n=ur(e),r=e?.startsWith(`#`),i=F(`font-medium text-foreground`,`underline decoration-foreground/30 underline-offset-[3px] decoration-[1px]`,`hover:decoration-foreground/60 transition-colors duration-150`);return r?(0,d.jsx)(`a`,{href:e,onClick:t=>dr(t,e),className:i,children:t}):n?(0,d.jsx)(D.default,{href:e||`#`,className:i,children:t}):(0,d.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,className:i,children:t})},code:({children:e,className:t})=>t?.includes(`language-`)?(0,d.jsx)(`code`,{className:`text-[13px] leading-relaxed text-inherit`,children:e}):(0,d.jsx)(`code`,{className:`px-2 py-1 rounded-md text-[13px] font-mono bg-card dark:bg-[#161618] border border-neutral-200 dark:border-neutral-700/50 text-foreground`,children:e}),pre:({children:e})=>(0,d.jsx)(pr,{children:e}),blockquote:({children:e})=>(0,d.jsx)(`blockquote`,{className:F(`my-5 pl-4 py-1 text-sm`,`border-l-2 border-border`,`text-muted-foreground`,`[&>p]:my-2`),children:e}),hr:()=>(0,d.jsx)(`hr`,{className:`my-8 border-0 h-px bg-border/60`}),table:({children:e})=>(0,d.jsx)(`div`,{className:`my-5 overflow-x-auto rounded-xl border border-border/60`,children:(0,d.jsx)(`table`,{className:`w-full text-sm`,children:e})}),thead:({children:e})=>(0,d.jsx)(`thead`,{className:`bg-muted/50 dark:bg-muted/30 border-b border-border/60`,children:e}),tbody:({children:e})=>(0,d.jsx)(`tbody`,{className:`divide-y divide-border/40`,children:e}),tr:({children:e})=>(0,d.jsx)(`tr`,{className:`transition-colors hover:bg-muted/30`,children:e}),th:({children:e})=>(0,d.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-semibold text-foreground uppercase tracking-wider`,children:e}),td:({children:e})=>(0,d.jsx)(`td`,{className:`px-4 py-3 text-foreground`,children:e}),img:({src:e,alt:t})=>e?(0,d.jsxs)(`span`,{className:`block my-5`,children:[(0,d.jsx)(`img`,{src:e,alt:t||``,className:F(`max-w-full h-auto rounded-xl`,`border border-border/40`,`shadow-sm`),loading:`lazy`}),t&&(0,d.jsx)(`span`,{className:`block mt-2 text-center text-sm text-muted-foreground`,children:t})]}):null,strong:({children:e})=>(0,d.jsx)(`strong`,{className:`font-semibold text-foreground`,children:e}),em:({children:e})=>(0,d.jsx)(`em`,{className:`italic text-foreground/90`,children:e}),del:({children:e})=>(0,d.jsx)(`del`,{className:`line-through text-muted-foreground decoration-muted-foreground/50`,children:e}),input:({checked:e,...t})=>(0,d.jsx)(`input`,{type:`checkbox`,checked:e,readOnly:!0,className:F(`mr-2 h-4 w-4 rounded border-border`,`accent-secondary cursor-default`,`align-middle relative -top-[1px]`),...t}),div:({children:e,style:t,className:n,...r})=>(0,d.jsx)(`div`,{className:F(`text-sm text-foreground`,n),style:t,...r,children:e}),span:({children:e,style:t,className:n,...r})=>(0,d.jsx)(`span`,{className:F(`text-foreground`,n),style:t,...r,children:e})},children:r})})});mr.displayName=`UnifiedMarkdown`;function hr(e){return e instanceof Error&&e.name===`AbortError`}async function gr(e,t){if(t.share)try{return await t.share(e),`shared`}catch(e){if(hr(e))return`cancelled`}return await t.writeText(e.url),`copied`}var _r=e=>{let{isOpen:r,url:i,searchText:a,panelWidth:o,setPanelWidth:s,closePanel:l}=ee(),{isAuthenticated:u}=nt(),{chatModelProvider:f}=G(),p=e.isOpen===void 0?r:e.isOpen,h=e.onClose||l,g=e.url||i,_=e.searchText===void 0?a:e.searchText,[v,y]=(0,n.useState)(null),[b,x]=(0,n.useState)([]),[S,C]=(0,n.useState)(!1),[w,T]=(0,n.useState)(!1),[E,D]=(0,n.useState)(t.researchAgentUIConfig.defaultSummarizePrompt),[O,k]=(0,n.useState)(!1),[A,j]=(0,n.useState)(!1),[M,N]=(0,n.useState)(!1),[P,F]=(0,n.useState)(``),[I,L]=(0,n.useState)(``),[R,z]=(0,n.useState)([]),[te,ne]=(0,n.useState)(``),[B,re]=(0,n.useState)(!1),[ie,ae]=(0,n.useState)(!1),[V,oe]=(0,n.useState)(!1),[H,se]=(0,n.useState)(!1),[ce,le]=(0,n.useState)(o),[fe,pe]=(0,n.useState)(!1),[me,he]=(0,n.useState)(!1),[W,ge]=(0,n.useState)(1),_e=(0,n.useRef)(null),ve=(0,n.useRef)({}),ye=.5,be=1.8,xe=.1;(0,n.useEffect)(()=>{let e=parseFloat(localStorage.getItem(`articleFontScale`)||``);Number.isNaN(e)||ge(Math.min(be,Math.max(ye,e)))},[]);let Se=e=>{let t=Math.min(be,Math.max(ye,Math.round(e*100)/100));ge(t);try{localStorage.setItem(`articleFontScale`,String(t))}catch(e){console.error(`Error storing article font scale:`,e)}},Ce=()=>Se(W+xe),we=()=>Se(W-xe),Te=()=>Se(1);(0,n.useEffect)(()=>{let e=()=>{se(window.innerWidth>=1024)};return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]),(0,n.useEffect)(()=>{let e=e=>{if(!fe)return;let t=window.innerWidth-e.clientX,n=Math.max(400,Math.min(t,window.innerWidth-100));le(n),s(n)},t=()=>{pe(!1)};return fe&&(document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,t),document.body.style.cursor=`ew-resize`,document.body.style.userSelect=`none`),()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,t),document.body.style.cursor=``,document.body.style.userSelect=``}},[fe,s]),(0,n.useEffect)(()=>{p&&g?(he(!1),Ee()):p||he(!1)},[p,g]);let Ee=async()=>{console.log(`[ArticleExtractPanel] Extracting URL:`,g);try{let e=new URL(g);if([/^https?:\/\/(www\.)?google\.[^/]+\/search/i,/^https?:\/\/(www\.)?bing\.com\/search/i,/^https?:\/\/(www\.)?duckduckgo\.com\/\?/i].some(e=>e.test(g))){m.toast.error(`Cannot extract articles from search result pages`),k(!1),he(!0);return}(e.pathname===`/`||e.pathname===``)&&(console.error(`[ArticleExtractPanel] URL is domain-only, missing article path:`,g),m.toast.error(`Invalid article URL - only domain provided`))}catch(e){console.error(`[ArticleExtractPanel] Invalid URL format:`,g,e)}k(!0);try{let{data:e}=await(0,c.getArticle)({query:{url:g}}),t=e?.article,n=t?.html?.replace(/<[^>]*>/g,``).trim()||``;t?.error||n.length<20?(document.dispatchEvent(new CustomEvent(`onInvokeChromeAPI`,{detail:{type:`extractURL`,url:g}})),await Promise.race([new Promise(e=>{let t=async n=>{window.removeEventListener(`onExtractionResult`,t);let{data:r}=await(0,c.getArticle)({query:{url:g}}),i=r?.article;i&&(y(i),i.followUpQuestions?.length>0&&z(i.followUpQuestions)),e()};window.addEventListener(`onExtractionResult`,t)}),new Promise(e=>setTimeout(e,1e4))])):(y(t),t?.followUpQuestions&&t.followUpQuestions.length>0&&z(t.followUpQuestions)),u&&De()}catch(e){console.error(`[ArticleExtractPanel] Error extracting URL:`,e),m.toast.error(`Failed to load article`)}finally{k(!1),he(!0)}},De=async()=>{try{let{data:e}=await(0,c.listFavorites)(),t=e?.favorites?.some(e=>e.url===g);re(!!t)}catch(e){console.error(`Error checking favorite status:`,e)}},Oe=async()=>{if(v){ae(!0);try{B?(await(0,c.removeFavorite)({query:{url:g}}),re(!1),m.toast.info(`Removed from favorites`)):(await(0,c.addFavorite)({body:{url:v.url||g,title:v.title,cite:v.cite,author:v.author,author_cite:v.author_cite,date:v.date,source:v.source,word_count:v.word_count,html:v.html}}),re(!0),m.toast.success(`Added to favorites`))}catch(e){console.error(`Error toggling favorite:`,e),m.toast.error(`Failed to toggle favorite`)}finally{ae(!1)}}},ke=()=>{if(f?.key&&f?.providerId)return f;try{let e=localStorage.getItem(`chatModelKey`)||``,t=localStorage.getItem(`chatModelProviderId`)||``;if(e&&t)return{key:e,providerId:t}}catch(e){console.error(`Error reading persisted chat model:`,e)}return f},Ae=async e=>{if(!v)return;let n=ke(),r=v.html?.replace(/<[^>]*>?/g,``).slice(0,t.researchAgentUIConfig.maxArticleLength),i=e===`question`,a=i?j:N,o=i?L:ne;a(!0),o(``);try{if(i){let e=[_,E].filter(Boolean).join(`
33
+ `);if(!r||r.length===0)throw Error(`Article content is empty`);let{data:t,error:i}=await(0,c.articleQa)({body:{article:r,question:e,chatHistory:b.slice(-5),chatModel:n}});if(i){let e=i.details||i.error||i.message||`Article QA failed`;throw Error(e)}let a=t?.content||``;F(a),x(e=>[...e,{role:`user`,content:E,time:new Date().toISOString()},{role:`assistant`,content:a,time:new Date().toISOString()}]);try{await(0,c.updateArticle)({body:{url:g,question:E,answer:a}})}catch(e){console.error(`Error storing Q&A in cache:`,e)}}else{let e=parseInt(localStorage.getItem(`maxFollowupQuestions`)||`4`);if(!r||r.length===0)throw Error(`Article content is empty`);let{data:t,error:i}=await(0,c.articleFollowups)({body:{article:r,chatHistory:b.slice(-5),maxQuestions:e,chatModel:n}});if(i){let e=i.details||i.error||i.message||`Article followups failed`;throw Error(e)}let a=t?.extract||[];z(a);try{await(0,c.updateArticle)({body:{url:g,followUpQuestions:a}})}catch(e){console.error(`Error storing follow-up questions in cache:`,e)}}}catch(e){console.error(`Error calling language API:`,e),o(e instanceof Error||typeof e==`object`&&e&&`message`in e?e.message:`Failed to get AI response`)}finally{a(!1)}},je=e=>{D(e),Ae(`question`)},Me=async()=>{if(!v)return;let e=`${P}\n\n\n${v.cite||``}\n\n\n${v.html}`;try{await navigator.clipboard.writeText(e),C(!0),setTimeout(()=>C(!1),2e3)}catch(e){console.error(`Failed to copy to clipboard:`,e)}},Ne=async()=>{let e=v?.url||g;if(e)try{await gr({title:v?.title,text:v?.cite,url:e},{share:typeof navigator<`u`&&navigator.share?e=>navigator.share(e):void 0,writeText:e=>navigator.clipboard.writeText(e)})===`copied`&&(T(!0),setTimeout(()=>T(!1),2e3))}catch(e){console.error(`Failed to share article:`,e)}};ve.current={ask:()=>Ae(`question`),suggest:()=>Ae(`suggest-followups`),copy:Me,highlight:()=>oe(e=>!e),favorite:Oe,open:()=>{let e=v?.url||g;e&&window.open(e,`_blank`,`noopener,noreferrer`)},zoomIn:Ce,zoomOut:we,zoomReset:Te,close:h},(0,n.useEffect)(()=>{if(!p)return;let e=e=>/^[a-z]$/.test(e)?`Key${e.toUpperCase()}`:/^[0-9]$/.test(e)?`Digit${e}`:e===`-`?`Minus`:e===`=`?`Equal`:e,t={};Object.keys(Yn).forEach(n=>{let{alt:r,key:i}=Yn[n];r&&(t[e(i.toLowerCase())]=n)});let n=e=>{if(e.key===`Escape`){ve.current.close?.();return}if(!e.altKey||e.ctrlKey||e.metaKey)return;let n=e.target;if(n&&(n.tagName===`INPUT`||n.tagName===`TEXTAREA`||n.isContentEditable))return;let r=t[e.code];if(!r)return;let i=ve.current[r];i&&(e.preventDefault(),i())};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[p]);let Pe=()=>(0,d.jsxs)(`div`,{className:`flex h-full flex-col bg-background shadow-xl`,children:[(0,d.jsx)(`div`,{className:`shrink-0 border-b border-border bg-background/95 px-4 py-3 backdrop-blur supports-[backdrop-filter]:bg-background/80`,children:(0,d.jsx)($n,{isLoadingAI:A,isLoadingFollowups:M,isLoadingFavorite:ie,isFavorited:B,isHighlightMode:V,articleUrl:v?.url||g,fontScale:W,onAskClick:()=>Ae(`question`),onSuggestClick:()=>Ae(`suggest-followups`),onCopyClick:Me,onShareClick:Ne,onFavoriteClick:Oe,onHighlightToggle:()=>oe(!V),onZoomIn:Ce,onZoomOut:we,onZoomReset:Te,onClose:h})}),(0,d.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:(0,d.jsxs)(`div`,{className:`p-4 space-y-6`,children:[(0,d.jsxs)(`div`,{className:`space-y-4`,children:[S&&(0,d.jsx)(`div`,{className:`bg-blue-500 text-white text-sm font-medium px-3 py-2 rounded-md shadow-lg`,children:`Copied!`}),w&&(0,d.jsx)(`div`,{className:`bg-blue-500 text-white text-sm font-medium px-3 py-2 rounded-md shadow-lg`,children:`Link copied!`}),(0,d.jsx)(er,{value:E,onChange:D,onSubmit:()=>Ae(`question`)}),(0,d.jsx)(tr,{questions:R,isLoading:M,error:te,onQuestionClick:je}),b.length>0&&(0,d.jsx)(`div`,{className:`space-y-4`,children:b.map((e,t)=>(0,d.jsx)(`div`,{className:`space-y-2`,children:e.role===`user`?(0,d.jsxs)(`div`,{className:`bg-primary/10 border border-primary/20 rounded-lg p-3`,children:[(0,d.jsx)(`div`,{className:`text-xs font-semibold text-primary mb-1`,children:`Your Question`}),(0,d.jsx)(`div`,{className:`text-sm text-foreground`,children:e.content})]}):(0,d.jsxs)(`div`,{className:`bg-muted rounded-lg shadow-md p-4`,children:[(0,d.jsx)(`div`,{className:`text-xs font-semibold text-muted-foreground mb-2`,children:`AI Response`}),(0,d.jsx)(`div`,{className:`text-sm`,dangerouslySetInnerHTML:{__html:e.content}})]})},t))}),(A||P&&b.length===0)&&(0,d.jsx)(nr,{response:P,isLoading:A,error:I}),I&&!A&&(0,d.jsx)(`div`,{className:`bg-red-500 text-white p-2 rounded-md text-sm`,children:I})]}),v&&(0,d.jsx)(ir,{article:v,isHighlightMode:V,fontScale:W})]})})]});return!p||!me?null:H?(0,d.jsxs)(`div`,{className:`fixed top-0 right-0 h-screen z-40 transition-all duration-300`,style:{width:`${ce}px`},children:[(0,d.jsx)(`div`,{ref:_e,onMouseDown:()=>pe(!0),className:`absolute left-0 top-0 bottom-0 w-1 cursor-ew-resize hover:bg-primary bg-transparent transition-colors z-50`,style:{touchAction:`none`},children:(0,d.jsx)(`div`,{className:`absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 w-1 h-12 rounded-full bg-muted-foreground opacity-50 hover:opacity-100 transition-opacity`})}),Pe()]}):(0,d.jsx)(U,{open:p,onOpenChange:e=>!e&&h(),children:(0,d.jsxs)(ue,{className:`pointer-events-auto fixed inset-0 !top-0 !left-0 !translate-x-0 !translate-y-0 h-full w-full max-w-none p-0 m-0 rounded-none border-0 overflow-hidden data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right`,hideCloseButton:!0,children:[(0,d.jsx)(Kn,{children:(0,d.jsx)(de,{children:`Article Details`})}),(0,d.jsx)(`div`,{className:`h-full overflow-y-auto`,children:Pe()})]})})},vr=()=>{let{sections:e,chatTurns:r,loading:i,messageAppeared:a,newChat:o,chatId:s}=G(),{isOpen:c,panelWidth:l}=ee(),{isAuthenticated:u}=nt(),[f,p]=(0,n.useState)(!1),m=(0,n.useRef)(null),h=(0,n.useRef)(null),g=(0,n.useRef)(!1);(0,n.useEffect)(()=>{let e=()=>{p(window.innerWidth>=1024)};return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]),(0,n.useEffect)(()=>{if(r.length===1&&(document.title=`${r[0].content.substring(0,30)} - ${t.researchAgentUIConfig.appName}`),r[r.length-1]?.role===`user`){g.current=!0,h.current?.scrollIntoView({behavior:`auto`}),setTimeout(()=>{g.current=!1},100);return}},[r]);let _=f&&c?{width:`calc(100% - ${l}px)`}:{};return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(`div`,{className:`flex flex-col min-h-full transition-all duration-300`,style:_,children:[(0,d.jsxs)(`div`,{className:`flex-1 flex flex-col space-y-3 pb-48 ${f&&!c?`px-0 max-w-[800px] mx-auto w-full`:`px-4 lg:px-8`}`,children:[e.map((t,r)=>{let i=r===e.length-1;return(0,d.jsxs)(n.Fragment,{children:[(0,d.jsx)(Vt,{section:t,sectionIndex:r,dividerRef:i?m:void 0,isLast:i}),!i&&(0,d.jsx)(`div`,{className:`h-px w-full bg-light-secondary dark:bg-dark-secondary`})]},t.userMessage.messageId)}),i&&!a&&(0,d.jsx)(rn,{}),(0,d.jsx)(`div`,{ref:h,className:`h-0`})]}),(0,d.jsx)(`div`,{className:`sticky bottom-[60px] md:bottom-0 z-40 bg-gradient-to-t from-background via-background to-transparent pt-4 pb-2`,children:(0,d.jsx)(Gn,{})})]}),(0,d.jsx)(_r,{})]})};function yr({radius:e=60,opacityDecay:t=.025,backgroundColor:r=`transparent`,color:i,colorGenerator:a}){let o=(0,n.useRef)(null),s=(0,n.useRef)({x:0,y:0}),c=(0,n.useRef)([]),l=()=>[Math.floor(Math.random()*130+10),Math.floor(.5*Math.random()*50),Math.floor(.5*Math.random()*255)],u=()=>i||a?.()||l();return(0,n.useEffect)(()=>{let n=o.current;if(!n)return;let i=n.getContext(`2d`);if(!i)return;let a=0,l=()=>{n.width=window.innerWidth,n.height=window.innerHeight};l();let d=()=>{i.globalCompositeOperation=`source-over`,r===`transparent`?i.clearRect(0,0,n.width,n.height):(i.fillStyle=r,i.fillRect(0,0,n.width,n.height)),i.globalCompositeOperation=`lighter`;let o={col:u(),x:s.current.x,y:s.current.y,grdblur:i.createRadialGradient(s.current.x,s.current.y,0,s.current.x,s.current.y,e),alpha:1};c.current.push(o);let l=[];for(let n=0;n<c.current.length;n++){let r=c.current[n];r.grdblur.addColorStop(0,`rgba(${r.col[0]},${r.col[1]},${r.col[2]},0.95)`),r.grdblur.addColorStop(.2,`rgba(${r.col[0]},${r.col[1]},${r.col[2]},0.7)`),r.grdblur.addColorStop(.5,`rgba(${r.col[0]},${r.col[1]},${r.col[2]},0.3)`),r.grdblur.addColorStop(1,`rgba(${r.col[0]},${r.col[1]},${r.col[2]},0)`),i.beginPath(),i.fillStyle=r.grdblur,i.globalAlpha=r.alpha,i.arc(r.x,r.y,e,0,Math.PI*2),i.fill(),r.alpha-=t,r.alpha<=0&&l.push(n)}for(let e=l.length-1;e>=0;e--)c.current.splice(l[e],1);i.globalAlpha=1,a=requestAnimationFrame(d)},f=e=>{s.current.x=e.pageX,s.current.y=e.pageY},p=e=>{s.current.x=e.touches[0].pageX,s.current.y=e.touches[0].pageY};return window.addEventListener(`mousemove`,f),window.addEventListener(`touchmove`,p,{passive:!0}),window.addEventListener(`resize`,l),d(),()=>{cancelAnimationFrame(a),window.removeEventListener(`mousemove`,f),window.removeEventListener(`touchmove`,p),window.removeEventListener(`resize`,l),c.current=[]}},[e,t,r,i,a]),(0,d.jsx)(`div`,{className:`relative w-full h-screen overflow-hidden pointer-events-none`,children:(0,d.jsx)(`canvas`,{ref:o,className:`absolute inset-0`,style:{background:`transparent`}})})}var br=200,xr=[`message`,`error`,`detail`];function Sr(e){return e.length>br?`${e.slice(0,199).trimEnd()}…`:e}function Cr(e,t){let n=t?`HTTP ${t}`:`Unknown error`;if(typeof e==`string`){let t=e.trim();return!t||t.startsWith(`<`)?n:Sr(t)}if(e&&typeof e==`object`){let t=e;for(let e of xr){let n=t[e];if(typeof n==`string`&&n.trim())return Sr(n.trim())}}return n}var wr=`qwksearch_pinned_chats`;function Tr(e){let t=e.messages?.[e.messages.length-1],n=t&&`createdAt`in t?t.createdAt:void 0;if(n){let e=new Date(n).getTime();if(!Number.isNaN(e))return new Date(e).toISOString()}return e.createdAt}function Er(){if(typeof window>`u`)return[];try{let e=localStorage.getItem(wr);return e?JSON.parse(e):[]}catch{return[]}}function Dr(e){typeof window>`u`||localStorage.setItem(wr,JSON.stringify(e))}function Or(){let[e,t]=(0,n.useState)([]),[r,i]=(0,n.useState)(!0),[a,o]=(0,n.useState)(!1),[s,l]=(0,n.useState)(null),[u,d]=(0,n.useState)(!1),[f,p]=(0,n.useState)(!1),[h,g]=(0,n.useState)(!1),[_,v]=(0,n.useState)([]),[y,b]=(0,n.useState)(``),[x,S]=(0,n.useState)([]),[C,w]=(0,n.useState)(!1),{isAuthenticated:T,isLoading:E}=nt(),{incognito:D,setIncognito:O}=G();(0,n.useEffect)(()=>{v(Er())},[]);let k=(0,n.useCallback)((e,t)=>{e.preventDefault(),e.stopPropagation(),v(e=>{let n=e.includes(t)?e.filter(e=>e!==t):[...e,t];return Dr(n),n})},[]),A=(0,n.useMemo)(()=>[...e].sort((e,t)=>{let n=_.includes(e.id),r=_.includes(t.id);return n&&!r?-1:!n&&r?1:0}),[e,_]),j=(0,n.useMemo)(()=>y.trim()?x:A,[y,x,A]),M=(0,n.useCallback)(async()=>{if(!E){i(!0);try{if(T){let{data:e,error:n,response:r}=await(0,c.listChats)();if(n&&r?.status===401){let e=Ie().map(e=>({...e,messageCount:e.messages?.filter(e=>e.role===`user`).length??0,lastMessageAt:Tr(e)}));t(e);return}if(n)throw Error(`Failed to fetch chats: ${Cr(n,r?.status)}`);t(Array.isArray(e?.chats)?e.chats:[])}else{let e=Ie().map(e=>({...e,messageCount:e.messages?.filter(e=>e.role===`user`).length??0}));t(e)}}catch(e){console.error(`Failed to fetch chat history:`,e),t([]),m.toast.error(`Failed to load chat history`)}finally{i(!1)}}},[T,E]);(0,n.useEffect)(()=>{M()},[M]);let N=(e,t)=>{e.preventDefault(),e.stopPropagation(),l(t),o(!0)},P=async()=>{if(s){d(!0);try{if(T){let{error:e,response:t}=await(0,c.deleteChatById)({path:{id:s}});if(e)throw Error(`Failed to delete chat: ${Cr(e,t?.status)}`)}else ze(s);t(e=>e.filter(e=>e.id!==s)),m.toast.success(`Chat deleted`)}catch(e){m.toast.error(e.message||`Failed to delete chat`)}finally{o(!1),l(null),d(!1)}}},F=()=>{p(!0)},I=async()=>{g(!0);try{if(T){let{error:e,response:t}=await(0,c.deleteAllChats)();if(e)throw Error(`Failed to clear history: ${Cr(e,t?.status)}`)}else Be();t([]),m.toast.success(`All history cleared`)}catch(e){m.toast.error(e.message||`Failed to clear history`)}finally{p(!1),g(!1)}},L=()=>{O(!D),m.toast.success(D?`Private mode off`:`Private mode on — messages won't be saved`)},R=(0,n.useCallback)(async e=>{if(!e.trim()){S([]),w(!1);return}w(!0);try{if(T){let{data:t,error:n,response:r}=await(0,c.searchChats)({query:{q:e}});if(n)throw Error(`Failed to search chats: ${Cr(n,r?.status)}`);S(Array.isArray(t?.chats)?t.chats:[])}else{let t=Ie().filter(t=>{let n=t.title.toLowerCase().includes(e.toLowerCase()),r=t.messages?.some(t=>`content`in t&&t.content?.toLowerCase().includes(e.toLowerCase()));return n||r});S(t.map(e=>({...e,messageCount:e.messages?.filter(e=>e.role===`user`).length??0,lastMessageAt:Tr(e)})))}}catch(e){console.error(`Failed to search chat history:`,e),S([]),m.toast.error(`Failed to search chat history`)}finally{w(!1)}},[T]);return(0,n.useEffect)(()=>{let e=setTimeout(()=>{R(y)},300);return()=>clearTimeout(e)},[y,R]),{chats:e,sortedChats:A,displayChats:j,loading:r,pinnedIds:_,togglePin:k,incognito:D,toggleIncognito:L,searchQuery:y,searchResults:x,searching:C,handleSearchChange:(0,n.useCallback)(e=>{b(e)},[]),deleteDialogOpen:a,setDeleteDialogOpen:o,chatToDelete:s,setChatToDelete:l,deleting:u,handleDeleteClick:N,handleConfirmDelete:P,clearAllDialogOpen:f,setClearAllDialogOpen:p,clearingAll:h,handleClearAllClick:F,handleConfirmClearAll:I}}function kr({incognito:e,onToggleIncognito:t,showClearAll:n,onClearAll:r,searchQuery:i,onSearchChange:a}){return(0,d.jsxs)(`div`,{className:`mb-2 pb-2 border-b border-border space-y-2`,children:[(0,d.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,d.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground/80 uppercase tracking-wide`,children:`Chat History`}),(0,d.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,d.jsxs)(`button`,{onClick:t,className:`flex items-center gap-1 px-2 py-1 text-xs rounded-lg transition-colors duration-200 ${e?`text-primary bg-primary/10`:`text-muted-foreground hover:text-foreground hover:bg-secondary`}`,title:e?`Private mode on`:`Private mode`,children:[(0,d.jsx)(s.Lock,{size:12}),(0,d.jsx)(`span`,{children:`Private`})]}),n&&(0,d.jsxs)(`button`,{onClick:r,className:`flex items-center gap-1 px-2 py-1 text-xs text-muted-foreground hover:text-red-500 hover:bg-red-500/10 rounded-lg transition-colors duration-200`,title:`Clear all history`,children:[(0,d.jsx)(s.Trash2,{size:12}),(0,d.jsx)(`span`,{children:`Clear All`})]})]})]}),(0,d.jsxs)(`div`,{className:`relative`,children:[(0,d.jsx)(s.Search,{className:`absolute left-2 top-1/2 -translate-y-1/2 text-muted-foreground`,size:14}),(0,d.jsx)(`input`,{type:`text`,placeholder:`Search chats...`,value:i,onChange:e=>a(e.target.value),className:`w-full pl-7 pr-7 py-1.5 text-sm bg-secondary/50 border border-border rounded-lg focus:outline-none focus:ring-2 focus:ring-primary/50 placeholder:text-muted-foreground/50`}),i&&(0,d.jsx)(`button`,{onClick:()=>a(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground`,children:(0,d.jsx)(s.X,{size:14})})]})]})}function Ar({chat:e,isPinned:n,onTogglePin:r,onDelete:i}){let a=e.messageCount??0;return(0,d.jsxs)(`div`,{className:`group flex items-center gap-1 px-2 py-1 rounded-lg hover:bg-secondary transition-colors duration-200`,children:[(0,d.jsxs)(D.default,{href:`/c/${e.id}`,onClick:n=>{t.researchAgentUIConfig.onOpenChat?.(e.id)&&n.preventDefault()},className:`flex-1 min-w-0 flex items-center gap-1.5`,children:[(0,d.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[a>0&&(0,d.jsxs)(zt,{className:`px-1.5 py-0 text-[10px] font-medium bg-zinc-200 text-zinc-700 hover:bg-zinc-200 dark:bg-zinc-700 dark:text-zinc-300 dark:hover:bg-zinc-700 border-0 rounded-md`,children:[a,`Q`]}),(0,d.jsx)(zt,{className:`px-1.5 py-0 text-[10px] font-medium bg-zinc-100 text-zinc-500 hover:bg-zinc-100 dark:bg-zinc-800 dark:text-zinc-400 dark:hover:bg-zinc-800 border-0 rounded-md`,children:L(new Date,e.createdAt)})]}),(0,d.jsxs)(`p`,{className:`text-xs text-popover-foreground truncate`,children:[n&&(0,d.jsx)(s.Pin,{size:10,className:`inline mr-1 text-primary`}),e.title]})]}),(0,d.jsx)(`button`,{onClick:t=>r(t,e.id),className:`p-1.5 rounded-lg transition-all duration-200 ${n?`opacity-100 text-primary hover:bg-primary/10`:`opacity-0 group-hover:opacity-100 text-muted-foreground hover:text-primary hover:bg-primary/10`}`,title:n?`Unpin chat`:`Pin chat`,children:(0,d.jsx)(s.Pin,{size:14})}),(0,d.jsx)(`button`,{onClick:t=>i(t,e.id),className:`opacity-0 group-hover:opacity-100 p-1.5 rounded-lg hover:bg-red-500/10 text-muted-foreground hover:text-red-500 transition-all duration-200`,title:`Delete chat`,children:(0,d.jsx)(s.Trash,{size:14})})]})}function jr({open:e,onOpenChange:t,title:n,description:r,confirmLabel:i,loadingLabel:a,loading:o,onConfirm:s}){return(0,d.jsx)(U,{open:e,onOpenChange:e=>{!e&&!o&&t(!1)},children:(0,d.jsxs)(ue,{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`,children:[(0,d.jsx)(de,{className:`text-lg font-medium leading-6 dark:text-white`,children:n}),(0,d.jsx)(fe,{className:`text-sm dark:text-white/70 text-black/70 mt-2`,children:r}),(0,d.jsxs)(`div`,{className:`flex flex-row items-end justify-end space-x-4 mt-6`,children:[(0,d.jsx)(`button`,{onClick:()=>{o||t(!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,d.jsx)(`button`,{onClick:s,disabled:o,className:`text-red-400 text-sm hover:text-red-500 transition duration-200 disabled:opacity-50`,children:o?a:i})]})]})})}function Mr({deleteDialogOpen:e,setDeleteDialogOpen:t,chatToDelete:n,setChatToDelete:r,deleting:i,onConfirmDelete:a,clearAllDialogOpen:o,setClearAllDialogOpen:s,clearingAll:c,onConfirmClearAll:l}){return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(jr,{open:e,onOpenChange:e=>{t(e),e||r(null)},title:`Delete Confirmation`,description:`Are you sure you want to delete this chat?`,confirmLabel:`Delete`,loadingLabel:`Deleting...`,loading:i,onConfirm:a}),(0,d.jsx)(jr,{open:o,onOpenChange:s,title:`Clear All History`,description:`Are you sure you want to delete all your chat history? This action cannot be undone.`,confirmLabel:`Clear All`,loadingLabel:`Clearing...`,loading:c,onConfirm:l})]})}var Nr={Today:(0,d.jsx)(s.Sun,{size:12}),Yesterday:(0,d.jsx)(s.Clock,{size:12}),"This Week":(0,d.jsx)(s.CalendarDays,{size:12}),Older:(0,d.jsx)(s.Archive,{size:12})};function Pr(e){let t=new Date,n=new Date(t.getFullYear(),t.getMonth(),t.getDate()),r=new Date(n.getTime()-864e5),i=new Date(n.getTime()-5184e5),a={Today:[],Yesterday:[],"This Week":[],Older:[]};for(let t of e){let e=new Date(t.createdAt);e>=n?a.Today.push(t):e>=r?a.Yesterday.push(t):e>=i?a[`This Week`].push(t):a.Older.push(t)}return[`Today`,`Yesterday`,`This Week`,`Older`].filter(e=>a[e].length>0).map(e=>({label:e,chats:a[e]}))}var Fr=({showLabel:e=!1})=>{let t=Or();return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(U,{children:[(0,d.jsxs)(se,{className:e?`inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-xs text-muted-foreground bg-secondary hover:bg-secondary/80 hover:text-foreground transition-colors duration-150`:`p-2 text-muted-foreground rounded-2xl bg-background/60 backdrop-blur-md hover:bg-secondary/80 transition duration-200 hover:text-foreground border border-border/30`,children:[(0,d.jsx)(s.History,{size:e?14:18}),e&&(0,d.jsx)(`span`,{children:`History`})]}),(0,d.jsxs)(ue,{className:`max-w-[420px] p-3`,children:[(0,d.jsx)(de,{className:`sr-only`,children:`Chat History`}),(0,d.jsx)(kr,{incognito:t.incognito,onToggleIncognito:t.toggleIncognito,showClearAll:t.chats.length>0&&!t.loading,onClearAll:t.handleClearAllClick,searchQuery:t.searchQuery,onSearchChange:t.handleSearchChange}),t.loading||t.searching?(0,d.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,d.jsxs)(`svg`,{"aria-hidden":`true`,className:`w-6 h-6 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,d.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,d.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`})]})}):t.searchQuery.trim()&&t.displayChats.length===0?(0,d.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No matching chats found.`})}):t.chats.length===0?(0,d.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No chats found.`})}):(0,d.jsx)(`div`,{className:`space-y-1 max-h-[500px] overflow-y-auto`,children:t.searchQuery.trim()?t.displayChats.map(e=>(0,d.jsx)(Ar,{chat:e,isPinned:t.pinnedIds.includes(e.id),onTogglePin:t.togglePin,onDelete:t.handleDeleteClick},e.id)):Pr(t.displayChats).map(({label:e,chats:n})=>(0,d.jsxs)(`div`,{children:[(0,d.jsxs)(`div`,{className:`flex items-center gap-1.5 px-3 py-1.5 text-xs font-semibold text-muted-foreground/70 uppercase tracking-wider`,children:[Nr[e],e]}),n.map(e=>(0,d.jsx)(Ar,{chat:e,isPinned:t.pinnedIds.includes(e.id),onTogglePin:t.togglePin,onDelete:t.handleDeleteClick},e.id))]},e))}),t.chats.length>0&&(0,d.jsx)(`div`,{className:`mt-2 pt-2 border-t border-border`,children:(0,d.jsx)(D.default,{href:`/library`,className:`block text-center text-xs text-primary hover:underline`,children:`View all chats`})})]})]}),(0,d.jsx)(Mr,{deleteDialogOpen:t.deleteDialogOpen,setDeleteDialogOpen:t.setDeleteDialogOpen,chatToDelete:t.chatToDelete,setChatToDelete:t.setChatToDelete,deleting:t.deleting,onConfirmDelete:t.handleConfirmDelete,clearAllDialogOpen:t.clearAllDialogOpen,setClearAllDialogOpen:t.setClearAllDialogOpen,clearingAll:t.clearingAll,onConfirmClearAll:t.handleConfirmClearAll})]})},Ir=e=>new Date(e.lastMessageAt||e.createdAt).getTime();function Lr(){let{chats:e,loading:n}=Or(),r=[...e].sort((e,t)=>Ir(t)-Ir(e)).slice(0,5);return n||r.length===0?null:(0,d.jsxs)(`div`,{className:`flex flex-row items-center justify-center gap-2 flex-wrap`,children:[(0,d.jsx)(Fr,{showLabel:!0}),r.map(e=>{let n=Pn(e.lastMessageAt||e.createdAt);return(0,d.jsxs)(D.default,{href:`/c/${e.id}`,onClick:n=>{t.researchAgentUIConfig.onOpenChat?.(e.id)&&n.preventDefault()},className:`flex items-center gap-1.5 px-3 py-1 rounded-full text-xs text-muted-foreground bg-secondary hover:bg-secondary/80 hover:text-foreground transition-colors duration-150 max-w-[220px]`,title:e.title,children:[(0,d.jsx)(`span`,{className:`truncate`,children:e.title}),n&&(0,d.jsx)(`span`,{className:`italic text-muted-foreground/70 whitespace-nowrap`,children:n})]},e.id)})]})}function Rr({listFooterLinks:e=[],optionShowIcons:t=!0,optionBackgroundColor:r=`bg-black/40`}){let[i,a]=(0,n.useState)(!1),o=(0,n.useRef)(null);(0,n.useEffect)(()=>{if(!i)return;let e=e=>{o.current&&!o.current.contains(e.target)&&a(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[i]);let c=()=>e.map(({url:e,text:n,icon:r,onClick:i})=>{let a=r?s[r]:null,o=e.startsWith(`http`),c=o?{target:`_blank`,rel:`noopener noreferrer`}:{},l=(0,d.jsxs)(d.Fragment,{children:[t&&a&&(0,d.jsx)(a,{size:14}),(0,d.jsx)(`span`,{className:`font-semibold tracking-wide text-md`,style:{fontVariant:`small-caps`},children:n}),(0,d.jsx)(`span`,{className:`absolute bottom-0 left-0 w-0 h-0.5 bg-current transition-all duration-300 group-hover:w-full group-hover:shadow-[0_0_8px_rgba(255,255,255,0.6)]`})]});return i?(0,d.jsx)(`button`,{type:`button`,onClick:i,className:`relative group inline-flex items-center gap-1 hover:text-white hover:drop-shadow-[0_0_8px_rgba(255,255,255,0.8)] transition-all duration-300 whitespace-nowrap`,children:l},e):o?(0,d.jsx)(`a`,{href:e,...c,className:`relative group inline-flex items-center gap-1 hover:text-white hover:drop-shadow-[0_0_8px_rgba(255,255,255,0.8)] transition-all duration-300 whitespace-nowrap`,children:l},e):(0,d.jsx)(D.default,{href:e,className:`relative group inline-flex items-center gap-1 hover:text-white hover:drop-shadow-[0_0_8px_rgba(255,255,255,0.8)] transition-all duration-300 whitespace-nowrap`,children:l},e)}),l=s.Info;return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`div`,{className:`hidden md:flex absolute bottom-2 left-1/2 -translate-x-1/2 text-slate-200 text-xs z-20 ${r} rounded-lg px-2 py-1 shadow-lg hover:shadow-xl hover:-translate-y-1 transition-all duration-300 flex-wrap items-center justify-center gap-x-6 max-w-[90vw]`,children:(0,d.jsx)(`div`,{className:`max-w-4xl mx-auto grid grid-cols-3 gap-2`,children:c()})}),(0,d.jsxs)(`div`,{ref:o,className:`md:hidden fixed top-[calc(8px+env(safe-area-inset-top,0px))] right-2 z-30`,children:[i&&(0,d.jsx)(`div`,{className:`absolute top-full right-0 mt-2 text-slate-200 text-xs ${r} rounded-lg px-3 py-2 shadow-lg flex flex-col items-start gap-2 backdrop-blur-sm`,children:c()}),(0,d.jsx)(`button`,{type:`button`,onClick:()=>a(e=>!e),"aria-label":i?`Hide links`:`Show links`,"aria-expanded":i,className:`flex items-center justify-center h-8 w-8 rounded-full text-slate-200 ${r} shadow-lg backdrop-blur-sm hover:text-white transition-all duration-300`,children:l?(0,d.jsx)(l,{size:16}):`i`})]})]})}function zr({open:e,onOpenChange:n}){return(0,d.jsx)(U,{open:e,onOpenChange:n,children:(0,d.jsxs)(ue,{className:`w-full max-w-md rounded-2xl bg-light-secondary dark:bg-dark-secondary border border-light-200 dark:border-dark-200 p-6 text-center align-middle shadow-xl`,children:[(0,d.jsx)(de,{className:`text-lg font-medium leading-6 dark:text-white`,children:`Download QwkSearch`}),(0,d.jsx)(fe,{className:`text-sm dark:text-white/70 text-black/70 mt-2`,children:`Get QwkSearch on your browser or desktop.`}),(0,d.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-3 mt-6`,children:[(0,d.jsx)(k.DownloadAppButton,{platform:`chrome-extension`,href:t.researchAgentUIConfig.downloadChromeUrl,autoHighlight:!0}),(0,d.jsx)(k.DownloadAppButton,{platform:`windows`,appId:t.researchAgentUIConfig.downloadWindowsStoreId,autoHighlight:!0})]})]})})}function Br(){let e=`hyZbH3n.mp4,iOeZcCk.mp4,dUZlxYE.mp4,GpWeP6E.gif,LuKUsLE.png,w7X11Dd.png,MHmVtCr.png,HmnUAee.png,vKP22VU.png,l1lsV39.png,Ku8F2qc.png,KUEXtwm.png,vvKFPmY.png,5p8eaEf.png,VAKuJcG.png,sTMPtQW.png,m0gHbZZ.png,cKu7dWQ.png,ogfefYD.png,ey5vAae.png,twuLrvk.png,ELILiYt.png,9el5qpP.png,Up6xTkk.png,W1XKBo0.png,1Y6xvW0.png,JXOytMz.png,DNiI6pp.png,XDv5s6p.jpeg,eRwiRJ9.jpeg,DRAfJoc.jpeg,ASVRQ1G.jpeg,35svwUT.jpeg,81xLiVI.jpeg,6kod2Em.jpeg,eU0C8zt.jpeg,Bv0PBY8.jpeg,DQNbjIZ.jpeg,2uACPqZ.jpeg,XEKltMF.jpeg,WHgLfBm.jpeg,QFYM0Fw.jpeg,K12HCao.jpeg,oN8rtsE.jpeg,9fGnrns.jpeg,2ONJJeW.jpeg,DO23Va7.jpeg,QaKeoXk.jpeg,QU5oCBR.jpeg,MhlYZmh.jpeg,ylL1ToB.jpeg,AWWsCv8.jpeg,Tk9Tzzj.jpeg`.split(`,`);return`https://i.imgur.com/`+e[Math.floor(Math.random()*e.length)]}function Vr(e){return e?e.split(/\r?\n/).map(e=>e.trim()).filter(Boolean).map(e=>{let t=e.split(`,`).map(e=>e.trim()),n=Number(t[t.length-2]),r=Number(t[t.length-1]);return t.length>=2&&t[t.length-2]!==``&&t[t.length-1]!==``&&Number.isFinite(n)&&Number.isFinite(r)?{label:t.slice(0,t.length-2).filter(Boolean).join(`, `)||void 0,latitude:n,longitude:r}:{label:e}}):[]}function Hr(){let{sendMessage:e}=G(),[r,i]=(0,n.useState)(null),[a,o]=(0,n.useState)(null),[s,c]=(0,n.useState)(!1),[l,u]=(0,n.useState)(!1),[f,p]=(0,n.useState)([]),[m,h]=(0,n.useState)(!0),[g,_]=(0,n.useState)(5),[v,y]=(0,n.useState)(12),[b,x]=(0,n.useState)(`fahrenheit`),[C,w]=(0,n.useState)(null),[T,E]=(0,n.useState)(!0),[D,O]=(0,n.useState)(6),[k,M]=(0,n.useState)(!0),[N,P]=(0,n.useState)(!1),[F,I]=(0,n.useState)(!1),L=t.researchAgentUIConfig.footerLinks.map(e=>e.url===`/#downloads`?{...e,onClick:()=>u(!0)}:e);(0,n.useEffect)(()=>{let e=()=>{p(Vr(localStorage.getItem(`weatherLocations`))),h(localStorage.getItem(`showWeatherWidget`)!==`false`),_(Number(localStorage.getItem(`weatherForecastDays`))||5),y(Number(localStorage.getItem(`weatherForecastHours`))||12),x(localStorage.getItem(`weatherTemperatureUnit`)===`celsius`?`celsius`:`fahrenheit`),w(localStorage.getItem(`trendingNewsApiUrl`)),E(localStorage.getItem(`showTrendingNewsWidget`)!==`false`),O(Number(localStorage.getItem(`trendingNewsMaxTopics`))||6),M(localStorage.getItem(`trendingNewsShowImages`)!==`false`),P(localStorage.getItem(`orbHoverGlow`)===`true`),I(localStorage.getItem(`cursorGlowTrail`)===`true`)};return e(),window.addEventListener(`client-config-changed`,e),window.addEventListener(`storage`,e),()=>{window.removeEventListener(`client-config-changed`,e),window.removeEventListener(`storage`,e)}},[]),(0,n.useEffect)(()=>{if(localStorage.getItem(`showBackgroundArt`)===`false`)return;i(Br());let e=setInterval(()=>{let e=Br();o(e),c(!0),setTimeout(()=>{i(e),c(!1),o(null)},1e3)},2e4);return()=>clearInterval(e)},[]);let R=e=>e.endsWith(`.webm`)||e.endsWith(`.mp4`),z=(e,t)=>R(e)?(0,d.jsx)(`video`,{src:e,autoPlay:!0,loop:!0,muted:!0,playsInline:!0,className:`absolute inset-0 w-full h-full object-cover transition-opacity duration-1000 ${t}`},e):(0,d.jsx)(`img`,{src:e,alt:``,className:`absolute inset-0 w-full h-full object-cover transition-opacity duration-1000 ${t}`},e);return(0,d.jsxs)(`div`,{className:`relative min-h-screen w-full`,children:[(0,d.jsxs)(`div`,{className:`absolute inset-0 z-0`,children:[r&&z(r,s?`opacity-0`:`opacity-30`),a&&z(a,s?`opacity-30`:`opacity-0`),F&&(0,d.jsx)(yr,{})]}),(0,d.jsx)(`div`,{className:`relative z-10`,children:(0,d.jsxs)(`div`,{className:`flex flex-col items-center justify-end md:justify-center min-h-[calc(100dvh-64px)] md:min-h-screen max-w-screen-sm mx-auto p-2 pb-1 md:pb-2`,children:[(0,d.jsx)(`div`,{style:{height:`200px`,width:`100%`,display:`flex`,alignItems:`center`,justifyContent:`center`},className:N?void 0:`pointer-events-none`,children:(0,d.jsx)(S.default,{autoRandomize:!0,onSphereClick:()=>console.log(`Sphere clicked`),className:`my-custom-class`})}),(0,d.jsxs)(`div`,{className:`w-full max-w-2xl mt-8 space-y-2`,children:[(0,d.jsx)(Lr,{}),(m||T)&&(0,d.jsxs)(`div`,{className:`flex flex-col gap-2 w-full`,children:[T&&(0,d.jsx)(j.TrendingNews,{compact:!0,expandable:!0,maxTopics:D,showImages:k,apiEndpoint:C||void 0,className:`rounded-2xl w-full`,style:{background:`rgba(255,255,255,0.08)`,border:`1px solid rgba(255,255,255,0.15)`,color:`inherit`,backdropFilter:`blur(8px)`,maxWidth:`100%`}}),m&&(0,d.jsx)(A.WeatherForecast,{compact:!0,forecastDays:g,forecastHours:v,temperatureUnit:b,locations:f.length>0?f:void 0,className:`rounded-2xl w-full`,style:{background:`rgba(255,255,255,0.08)`,border:`1px solid rgba(255,255,255,0.15)`,color:`inherit`,backdropFilter:`blur(8px)`}})]}),(0,d.jsx)(Gn,{})]})]})}),(0,d.jsx)(Rr,{listFooterLinks:L}),(0,d.jsx)(zr,{open:l,onOpenChange:u})]})}var Ur=()=>(0,d.jsxs)(`svg`,{"aria-hidden":`true`,className:`w-8 h-8 text-border fill-secondary animate-spin`,viewBox:`0 0 100 101`,fill:`none`,xmlns:`http://www.w3.org/2000/svg`,children:[(0,d.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,d.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`})]});function Wr(){return(0,d.jsx)(`div`,{className:`flex min-h-screen flex-col items-center justify-center p-8`,children:(0,d.jsxs)(`div`,{className:`max-w-2xl w-full space-y-6 bg-light-secondary dark:bg-dark-secondary rounded-lg p-8 border border-black/10 dark:border-white/10`,children:[(0,d.jsxs)(`div`,{className:`space-y-2`,children:[(0,d.jsx)(`h1`,{className:`text-2xl font-semibold text-black dark:text-white`,children:`⚠️ Configuration Required`}),(0,d.jsx)(`p`,{className:`text-black/70 dark:text-white/70`,children:`No AI model providers are configured. Add at least one API key to continue.`})]}),(0,d.jsxs)(`div`,{className:`space-y-4`,children:[(0,d.jsx)(`h2`,{className:`text-lg font-medium text-black dark:text-white`,children:`Quick Setup:`}),(0,d.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,d.jsxs)(`div`,{className:`bg-black/5 dark:bg-white/5 rounded p-4`,children:[(0,d.jsx)(`p`,{className:`font-medium text-black dark:text-white mb-2`,children:`1. Create environment file:`}),(0,d.jsx)(`code`,{className:`block bg-black/10 dark:bg-white/10 rounded p-2 text-xs overflow-x-auto`,children:`apps/qwksearch-web/.env.local`})]}),(0,d.jsxs)(`div`,{className:`bg-black/5 dark:bg-white/5 rounded p-4`,children:[(0,d.jsx)(`p`,{className:`font-medium text-black dark:text-white mb-2`,children:`2. Add required variables:`}),(0,d.jsx)(`pre`,{className:`block bg-black/10 dark:bg-white/10 rounded p-3 text-xs overflow-x-auto text-black/80 dark:text-white/80`,children:`# Database
34
34
  DATABASE_URL=file:./data/qwksearch.db
35
35
 
36
36
  # Auth (generate: openssl rand -base64 32)
@@ -48,4 +48,4 @@ OPENAI_API_KEY=sk-your_key_here
48
48
  OPENAI_BASE_URL=https://api.openai.com/v1
49
49
 
50
50
  # Or Anthropic
51
- ANTHROPIC_API_KEY=sk-ant-your_key_here`})]}),(0,d.jsxs)(`div`,{className:`bg-black/5 dark:bg-white/5 rounded p-4`,children:[(0,d.jsx)(`p`,{className:`font-medium text-black dark:text-white mb-2`,children:`3. Restart the server`}),(0,d.jsx)(`code`,{className:`block bg-black/10 dark:bg-white/10 rounded p-2 text-xs`,children:`Ctrl+C, then: npm run dev`})]})]}),(0,d.jsxs)(`div`,{className:`pt-4 border-t border-black/10 dark:border-white/10`,children:[(0,d.jsx)(`h3`,{className:`font-medium text-black dark:text-white mb-2`,children:`Get API Keys:`}),(0,d.jsxs)(`ul`,{className:`space-y-2 text-sm text-black/70 dark:text-white/70`,children:[(0,d.jsxs)(`li`,{children:[(0,d.jsx)(`strong`,{children:`Groq`}),` (FREE): `,(0,d.jsx)(`a`,{href:`https://console.groq.com/keys`,target:`_blank`,rel:`noopener noreferrer`,className:`text-blue-600 dark:text-blue-400 hover:underline`,children:`console.groq.com/keys`})]}),(0,d.jsxs)(`li`,{children:[(0,d.jsx)(`strong`,{children:`OpenAI`}),`: `,(0,d.jsx)(`a`,{href:`https://platform.openai.com/api-keys`,target:`_blank`,rel:`noopener noreferrer`,className:`text-blue-600 dark:text-blue-400 hover:underline`,children:`platform.openai.com/api-keys`})]}),(0,d.jsxs)(`li`,{children:[(0,d.jsx)(`strong`,{children:`Anthropic`}),`: `,(0,d.jsx)(`a`,{href:`https://console.anthropic.com/settings/keys`,target:`_blank`,rel:`noopener noreferrer`,className:`text-blue-600 dark:text-blue-400 hover:underline`,children:`console.anthropic.com`})]})]})]})]}),(0,d.jsxs)(`div`,{className:`text-xs text-black/50 dark:text-white/50 pt-4 border-t border-black/10 dark:border-white/10`,children:[`See `,(0,d.jsx)(`code`,{children:`SETUP_INSTRUCTIONS.md`}),` in the project root for full details.`]})]})})}var Ir=()=>{let e=(0,r.useRouter)(),{hasError:t,isReady:i,notFound:a,messages:o}=G(),{isAuthenticated:s}=nt();return(0,n.useEffect)(()=>{i&&a&&!s&&e.replace(`/`)},[i,a,s,e]),t?(0,d.jsx)(Fr,{}):i&&a&&!s?(0,d.jsx)(`div`,{className:`flex flex-row items-center justify-center min-h-screen`,children:(0,d.jsx)(Pr,{})}):i?a?(0,d.jsxs)(`div`,{className:`flex min-h-screen flex-col items-center justify-center gap-3 px-4 text-center`,children:[(0,d.jsx)(`p`,{className:`text-sm text-black/70 dark:text-white/70`,children:`This chat could not be found.`}),(0,d.jsx)(`button`,{type:`button`,onClick:()=>e.push(`/`),className:`rounded-md border border-black/15 px-3 py-1.5 text-sm hover:bg-black/5 dark:border-white/20 dark:hover:bg-white/10`,children:`Go Home`})]}):(0,d.jsx)(`div`,{children:o.length>0?(0,d.jsx)(d.Fragment,{children:(0,d.jsx)(lr,{})}):(0,d.jsx)(Nr,{})}):(0,d.jsx)(`div`,{className:`flex flex-row items-center justify-center min-h-screen`,children:(0,d.jsx)(Pr,{})})};function Lr(e,t){let[r,i]=(0,n.useState)(`idle`),[a,o]=(0,n.useState)(!1),[s,c]=(0,n.useState)([]),[l,u]=(0,n.useState)(`af_heart`),[d,f]=(0,n.useState)(null),p=(0,n.useRef)(null),m=(0,n.useRef)(null);(0,n.useEffect)(()=>{t?.autoPreload&&!a&&g()},[t?.autoPreload,a]),(0,n.useEffect)(()=>{let e=localStorage.getItem(`kokoroVoice`);e&&u(e)},[]),(0,n.useEffect)(()=>()=>{p.current&&p.current.pause(),m.current?.abort()},[]);let h=(0,n.useCallback)(()=>{p.current&&=(p.current.pause(),p.current.src.startsWith(`blob:`)&&URL.revokeObjectURL(p.current.src),null),m.current?.abort(),m.current=null},[]),g=(0,n.useCallback)(async()=>{try{i(`loading`),f(null),await Oe();let e=await Ae();c(e),e.length&&!e.includes(l)&&u(e[0]),o(!0),i(`idle`)}catch(e){let t=e instanceof Error?e.message:`Failed to load model`;f(t),i(`error`),console.error(`Failed to load Kokoro model:`,e)}},[l]);return{status:r,modelReady:a,voices:s,selectedVoice:l,error:d,warmupModel:g,speak:(0,n.useCallback)(async()=>{if(e?.trim()){if(!a){f(`Model not loaded. Click "Preload Model" first.`);return}try{h(),i(`generating`),f(null);let t=new AbortController;m.current=t;let n=(await(await ke()).generate(e.slice(0,5e3),{voice:l})).toWav(),r=new Blob([n],{type:`audio/wav`}),a=URL.createObjectURL(r),o=new Audio(a);p.current=o,o.onended=()=>{i(`idle`),URL.revokeObjectURL(a),p.current=null},o.onerror=()=>{i(`error`),f(`Failed to play audio`),URL.revokeObjectURL(a),p.current=null},i(`playing`),await o.play()}catch(e){if(e?.name!==`AbortError`){let t=e instanceof Error?e.message:`Speech generation failed`;f(t),i(`error`),console.error(`Kokoro TTS error:`,e)}}}},[e,l,a,h]),stop:(0,n.useCallback)(()=>{h(),i(`idle`),f(null)},[h]),changeVoice:(0,n.useCallback)(e=>{u(e),localStorage.setItem(`kokoroVoice`,e)},[]),backend:je()}}var Rr={af_heart:`American Female - Heart`,af_bella:`American Female - Bella`,af_nicole:`American Female - Nicole`,af_sarah:`American Female - Sarah`,am_adam:`American Male - Adam`,am_michael:`American Male - Michael`,am_tony:`American Male - Tony`,bf_emma:`British Female - Emma`,bm_george:`British Male - George`,bm_thomas:`British Male - Thomas`};function zr({preloadOnMount:e=!1}){let{status:t,modelReady:r,voices:i,selectedVoice:a,error:o,warmupModel:c,changeVoice:l,backend:u}=Lr(``,{autoPreload:e}),[f,p]=(0,n.useState)(!1),m=t===`loading`,h=t===`error`;return(0,d.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,d.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,d.jsxs)(K,{children:[(0,d.jsx)(q,{asChild:!0,children:(0,d.jsx)(`button`,{onClick:c,disabled:m||r,className:F(`p-2 rounded-full transition duration-200`,r?`bg-green-500/10 text-green-600 dark:text-green-400`:`bg-white/10 dark:bg-black/10 text-muted-foreground hover:bg-white/20 dark:hover:bg-black/20`,m&&`opacity-70 cursor-not-allowed`),children:m?(0,d.jsx)(s.Loader2,{size:18,className:`animate-spin`}):(0,d.jsx)(s.Download,{size:18})})}),(0,d.jsx)(J,{side:`bottom`,children:m?`Loading Kokoro model...`:r?`Model ready`:`Preload Kokoro.js model`})]}),r&&u&&(0,d.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[u,` • `,i.length,` voices`]}),h&&(0,d.jsxs)(K,{children:[(0,d.jsx)(q,{asChild:!0,children:(0,d.jsx)(s.AlertCircle,{size:18,className:`text-red-500`})}),(0,d.jsx)(J,{side:`bottom`,className:`max-w-xs`,children:o})]})]}),r&&(0,d.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,d.jsx)(`button`,{onClick:()=>p(!f),className:`w-full text-left px-3 py-2 rounded-md bg-white/5 dark:bg-black/5 hover:bg-white/10 dark:hover:bg-black/10 transition text-sm font-medium`,children:(0,d.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,d.jsx)(s.Volume2,{size:16}),Rr[a]||a]})}),f&&(0,d.jsx)(`div`,{className:`grid grid-cols-2 gap-2 p-2 bg-white/5 dark:bg-black/5 rounded-md max-h-64 overflow-y-auto`,children:i.map(e=>(0,d.jsx)(`button`,{onClick:()=>{l(e),p(!1)},className:F(`p-2 text-left text-sm rounded transition duration-200`,a===e?`bg-blue-500/20 text-blue-600 dark:text-blue-400 font-medium`:`bg-white/5 dark:bg-black/5 text-foreground hover:bg-white/10 dark:hover:bg-black/10`),children:Rr[e]||e},e))})]})]})}function Br(){let[e,t]=(0,n.useState)(!1),[r,i]=(0,n.useState)(()=>localStorage.getItem(`useTTSKokoro`)!==`false`),[a,o]=(0,n.useState)(()=>localStorage.getItem(`ttsSpeaker`)||`angus`),[c,l]=(0,n.useState)(()=>rn()),{start:u,speechStatus:f}=Me(`This is a preview of the selected voice.`,{enableInterrupt:!1}),p=e=>{i(e),localStorage.setItem(`useTTSKokoro`,String(e))},m=e=>{o(e),localStorage.setItem(`ttsSpeaker`,e)},h=e=>{l(e),an(e)};return(0,d.jsxs)(`div`,{className:`space-y-4`,children:[(0,d.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,d.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,d.jsx)(s.Settings2,{size:18}),(0,d.jsx)(`h3`,{className:`font-semibold`,children:`Voice Settings`})]}),(0,d.jsx)(`button`,{onClick:()=>t(!e),className:`text-xs px-3 py-1 rounded-md bg-white/10 dark:bg-black/10 hover:bg-white/20 dark:hover:bg-black/20 transition`,children:e?`Collapse`:`Expand`})]}),e&&(0,d.jsxs)(`div`,{className:`space-y-4 p-4 rounded-lg bg-white/5 dark:bg-black/5 border border-white/10 dark:border-black/10`,children:[(0,d.jsxs)(`div`,{className:`space-y-2`,children:[(0,d.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,d.jsx)(`input`,{type:`checkbox`,checked:r,onChange:e=>p(e.target.checked),className:`rounded`}),(0,d.jsx)(`span`,{className:`font-medium text-sm`,children:`Use Kokoro.js (Local TTS)`}),(0,d.jsxs)(K,{children:[(0,d.jsx)(q,{asChild:!0,children:(0,d.jsx)(`span`,{className:`text-xs text-muted-foreground cursor-help`,children:`ⓘ`})}),(0,d.jsx)(J,{side:`right`,className:`max-w-xs`,children:`Runs locally in your browser. No server requests, lower latency, and multiple voice options.`})]})]}),r&&(0,d.jsx)(zr,{preloadOnMount:!1})]}),(0,d.jsxs)(`div`,{className:`space-y-2`,children:[(0,d.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,d.jsx)(`input`,{type:`checkbox`,checked:!r,onChange:e=>p(!e.target.checked),className:`rounded`}),(0,d.jsx)(`span`,{className:`font-medium text-sm`,children:`Use Cloudflare TTS (Fallback)`}),(0,d.jsxs)(K,{children:[(0,d.jsx)(q,{asChild:!0,children:(0,d.jsx)(`span`,{className:`text-xs text-muted-foreground cursor-help`,children:`ⓘ`})}),(0,d.jsx)(J,{side:`right`,className:`max-w-xs`,children:`Uses Cloudflare Workers AI. Slightly higher latency but can be a fallback.`})]})]}),!r&&(0,d.jsxs)(`div`,{className:`space-y-2`,children:[(0,d.jsxs)(`select`,{value:a,onChange:e=>m(e.target.value),className:`w-full px-3 py-2 rounded-md bg-white/10 dark:bg-black/10 border border-white/20 dark:border-black/20 text-sm`,children:[(0,d.jsx)(`option`,{value:`angus`,children:`Angus`}),(0,d.jsx)(`option`,{value:`flora`,children:`Flora`}),(0,d.jsx)(`option`,{value:`james`,children:`James`}),(0,d.jsx)(`option`,{value:`natalie`,children:`Natalie`})]}),(0,d.jsxs)(`button`,{onClick:()=>u(),disabled:f===`started`,className:F(`w-full flex items-center justify-center gap-2 px-3 py-2 rounded-md text-sm font-medium transition`,f===`started`?`bg-gray-500/20 text-gray-600 dark:text-gray-400 cursor-not-allowed`:`bg-blue-500/20 text-blue-600 dark:text-blue-400 hover:bg-blue-500/30`),children:[(0,d.jsx)(s.Volume2,{size:16}),f===`started`?`Playing...`:`Preview`]})]})]}),(0,d.jsx)(`div`,{className:`space-y-2 pt-2 border-t border-white/10 dark:border-black/10`,children:(0,d.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,d.jsx)(`input`,{type:`checkbox`,checked:c,onChange:e=>h(e.target.checked),className:`rounded`}),(0,d.jsx)(`span`,{className:`font-medium text-sm`,children:`Start talking automatically on first visit`}),(0,d.jsxs)(K,{children:[(0,d.jsx)(q,{asChild:!0,children:(0,d.jsx)(`span`,{className:`text-xs text-muted-foreground cursor-help`,children:`ⓘ`})}),(0,d.jsx)(J,{side:`right`,className:`max-w-xs`,children:`Opens the mic the first time you load the chat composer in this browser, so you can start talking right away instead of clicking the mic button.`})]})]})}),(0,d.jsx)(`div`,{className:`text-xs text-muted-foreground pt-2 border-t border-white/10 dark:border-black/10`,children:(0,d.jsxs)(`p`,{children:[(0,d.jsx)(`strong`,{children:`Tip:`}),` Kokoro.js loads once and runs locally. The first model load may take a few seconds, but subsequent TTS generation is very fast.`]})})]})]})}function Vr(e,t){if(!e.startsWith(`/`)||e.includes(`#`)||e.includes(`?`))return!1;let n=e.replace(/\/+$/,``)||`/`,r=t.replace(/\/+$/,``)||`/`;return n===`/`?r===`/`:r===n||r.startsWith(`${n}/`)}function Hr(e,t){return t?e.filter(e=>!Vr(e.url,t)):e}var Ur=(0,n.createContext)(null),Wr=`qwksearch-main-view`;function Gr({children:e,docsEnabled:t=!0}){let[r,i]=(0,n.useState)(`research`),[a,o]=(0,n.useState)(0),s=(0,n.useCallback)(e=>i(t?e:`research`),[t]);(0,n.useEffect)(()=>{if(typeof window>`u`||!t)return;let e=window.localStorage.getItem(Wr);(e===`research`||e===`docs`)&&i(e)},[t]),(0,n.useEffect)(()=>{typeof window<`u`&&t&&window.localStorage.setItem(Wr,r)},[r,t]);let c=(0,n.useMemo)(()=>({activeView:r,setActiveView:s,docsEnabled:t,toggleToDocs:()=>s(`docs`),toggleToResearch:()=>s(`research`),filesSidebarRequestId:a,requestFilesSidebar:()=>o(e=>e+1)}),[r,s,t,a]);return(0,d.jsx)(Ur.Provider,{value:c,children:e})}function Kr(){let e=(0,n.useContext)(Ur);if(!e)throw Error(`useMainView must be used within a MainViewProvider`);return e}var qr=`data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='iso-8859-1'?%3e%3csvg%20height='800px'%20width='800px'%20version='1.1'%20id='Layer_1'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20viewBox='0%200%20512%20512'%20xml:space='preserve'%3e%3cpath%20style='fill:%23FE5022;'%20d='M438.802,390.609V278.595h55.174c9.938,0,18.023,8.085,18.023,18.023v75.967%20c0,9.938-8.086,18.024-18.023,18.024L438.802,390.609L438.802,390.609z'/%3e%3cpath%20style='fill:%23ECE5DD;'%20d='M28.107,511.637C12.609,511.637,0,499.027,0,483.529V134.326c0-1.441,0-12.123,0-12.123%20L121.715,0.363c0,0,10.8,0,12.248,0h271.569c15.498,0,28.107,12.609,28.107,28.106v455.059c0,15.499-12.609,28.108-28.107,28.108%20H28.107V511.637z'/%3e%3cpath%20style='fill:%23D9CBBD;'%20d='M405.533,0.363h-31.991c15.498,0,28.107,12.609,28.107,28.107v455.059%20c0,15.499-12.609,28.108-28.107,28.108h31.991c15.498,0,28.107-12.609,28.107-28.108V28.469%20C433.64,12.972,421.031,0.363,405.533,0.363z'/%3e%3cg%3e%3cpath%20style='fill:%23BABABA;'%20d='M167.639,132.2h133.086c4.594,0,8.318-3.723,8.318-8.318c0-4.595-3.724-8.318-8.318-8.318H167.639%20c-4.594,0-8.318,3.723-8.318,8.318C159.321,128.477,163.045,132.2,167.639,132.2z'/%3e%3cpath%20style='fill:%23BABABA;'%20d='M356.178,132.2h22.181c4.594,0,8.318-3.723,8.318-8.318c0-4.595-3.724-8.318-8.318-8.318h-22.181%20c-4.594,0-8.318,3.723-8.318,8.318C347.86,128.477,351.584,132.2,356.178,132.2z'/%3e%3cpath%20style='fill:%23BABABA;'%20d='M242.5,212.606c0-4.595-3.724-8.318-8.318-8.318H56.734c-4.594,0-8.318,3.723-8.318,8.318%20s3.724,8.318,8.318,8.318h177.449C238.776,220.924,242.5,217.201,242.5,212.606z'/%3e%3cpath%20style='fill:%23BABABA;'%20d='M378.359,204.288h-99.815c-4.594,0-8.318,3.723-8.318,8.318s3.724,8.318,8.318,8.318h99.815%20c4.594,0,8.318-3.723,8.318-8.318S382.953,204.288,378.359,204.288z'/%3e%3c/g%3e%3cpath%20style='fill:%23D9CBBD;'%20d='M0.726,123.171L122.442,1.331l1.39,105.939c0,9.465-7.7,17.166-17.166,17.166L0.726,123.171z'/%3e%3cpath%20style='fill:%23FFB656;'%20d='M270.226,401.7V267.504H456.87c5.938,0,10.768,4.83,10.768,10.768v112.659%20c0,5.938-4.83,10.769-10.768,10.769H270.226z'/%3e%3cpath%20style='fill:%23D9CBBD;'%20d='M367.785,335.156c-12.822,0-23.252-10.431-23.252-23.254v-44.399h89.833v44.399%20c0,12.823-10.431,23.254-23.252,23.254H367.785z'/%3e%3cg%3e%3cpath%20style='fill:%23BABABA;'%20d='M167.639,132.2h133.086c4.594,0,8.318-3.723,8.318-8.318c0-4.595-3.724-8.318-8.318-8.318H167.639%20c-4.594,0-8.318,3.723-8.318,8.318C159.321,128.477,163.045,132.2,167.639,132.2z'/%3e%3cpath%20style='fill:%23BABABA;'%20d='M356.178,132.2h22.181c4.594,0,8.318-3.723,8.318-8.318c0-4.595-3.724-8.318-8.318-8.318h-22.181%20c-4.594,0-8.318,3.723-8.318,8.318C347.86,128.477,351.584,132.2,356.178,132.2z'/%3e%3cpath%20style='fill:%23BABABA;'%20d='M242.5,212.606c0-4.595-3.724-8.318-8.318-8.318H56.734c-4.594,0-8.318,3.723-8.318,8.318%20s3.724,8.318,8.318,8.318h177.449C238.776,220.924,242.5,217.201,242.5,212.606z'/%3e%3cpath%20style='fill:%23BABABA;'%20d='M378.359,204.288h-99.815c-4.594,0-8.318,3.723-8.318,8.318s3.724,8.318,8.318,8.318h99.815%20c4.594,0,8.318-3.723,8.318-8.318S382.953,204.288,378.359,204.288z'/%3e%3cpath%20style='fill:%23BABABA;'%20d='M345.087,448.28H101.096c-4.594,0-8.318,3.723-8.318,8.318c0,4.595,3.724,8.318,8.318,8.318h243.992%20c4.594,0,8.318-3.723,8.318-8.318C353.405,452.003,349.681,448.28,345.087,448.28z'/%3e%3c/g%3e%3cpath%20style='fill:%23FE5022;'%20d='M163.689,357.337c-3.692,0-6.094-3.886-4.443-7.189l16.225-32.451%20c1.799-3.597,5.416-5.833,9.438-5.833h44.282v45.471h-65.503V357.337z'/%3e%3cpolygon%20style='fill:%23FFB656;'%20points='256.918,278.252%20211.447,300.988%20211.447,368.216%20256.918,390.953%20284.321,390.953%20284.321,278.214%20'/%3e%3cg%3e%3cpath%20style='fill:%23FE5022;'%20d='M268.64,401.7c-7.075,0-12.832-5.756-12.832-12.832V280.336c0-7.075,5.756-12.831,12.832-12.831%20h19.808c7.075,0,12.832,5.756,12.832,12.831v108.532c0,7.076-5.756,12.832-12.832,12.832H268.64z'/%3e%3cpath%20style='fill:%23FE5022;'%20d='M104.156,379.377H26.143V301.33h91.398c8.546,0,14.88,7.936,12.986,16.27l-11.313,49.758%20C117.615,374.388,111.366,379.377,104.156,379.377z'/%3e%3c/g%3e%3c/svg%3e`,Jr=`data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='utf-8'?%3e%3csvg%20height='800px'%20width='800px'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20viewBox='0%200%2064%2064'%20xml:space='preserve'%3e%3cstyle%20type='text/css'%3e%20.st0{fill:%2376C2AF;}%20.st1{fill:%234F5D73;}%20.st2{opacity:0.2;}%20.st3{fill:%23231F20;}%20.st4{fill:%23FFFFFF;}%20%3c/style%3e%3cg%20id='Layer_1'%3e%3cg%3e%3ccircle%20class='st0'%20cx='32'%20cy='32'%20r='32'/%3e%3c/g%3e%3cg%3e%3cpath%20class='st1'%20d='M32,52c-1.1,0-2-0.9-2-2V18c0-1.1,0.9-2,2-2l0,0c1.1,0,2,0.9,2,2v32C34,51.1,33.1,52,32,52L32,52z'/%3e%3c/g%3e%3cg%3e%3cpath%20class='st1'%20d='M46,52c-1.1,0-2-0.9-2-2V18c0-1.1,0.9-2,2-2l0,0c1.1,0,2,0.9,2,2v32C48,51.1,47.1,52,46,52L46,52z'/%3e%3c/g%3e%3cg%3e%3cpath%20class='st1'%20d='M18,52c-1.1,0-2-0.9-2-2V18c0-1.1,0.9-2,2-2l0,0c1.1,0,2,0.9,2,2v32C20,51.1,19.1,52,18,52L18,52z'/%3e%3c/g%3e%3cg%20class='st2'%3e%3ccircle%20class='st3'%20cx='45.9'%20cy='38'%20r='4'/%3e%3c/g%3e%3cg%20class='st2'%3e%3ccircle%20class='st3'%20cx='32'%20cy='27'%20r='4'/%3e%3c/g%3e%3cg%20class='st2'%3e%3ccircle%20class='st3'%20cx='18'%20cy='44'%20r='4'/%3e%3c/g%3e%3cg%3e%3ccircle%20class='st4'%20cx='45.9'%20cy='36'%20r='4'/%3e%3c/g%3e%3cg%3e%3ccircle%20class='st4'%20cx='32'%20cy='25'%20r='4'/%3e%3c/g%3e%3cg%3e%3ccircle%20class='st4'%20cx='18'%20cy='42'%20r='4'/%3e%3c/g%3e%3c/g%3e%3cg%20id='Layer_2'%3e%3c/g%3e%3c/svg%3e`;function Yr(){let e=(0,r.usePathname)(),n=(0,r.useRouter)(),{isAuthenticated:i,signIn:a,signOut:o}=nt(),{newChat:c}=G(),{activeView:l,setActiveView:u,docsEnabled:f,requestFilesSidebar:p}=Kr(),m=[{href:`/`,label:`Research`,icon:t.researchAgentUIConfig.appIconUrl},...f?[{href:`/workspace`,label:`Docs`,icon:(0,d.jsx)(P.default,{src:qr,alt:`Docs`,width:24,height:24,className:`w-full h-full`})}]:[]],h=e===`/`||e.startsWith(`/c`),g=Hr(t.researchAgentUIConfig.footerLinks,e),_=[...m.map(({href:e,label:t,icon:n})=>({key:e,label:t,icon:n,active:e===`/`?l===`research`:l===`docs`,onClick:()=>{if(e===`/`){u(`research`),h&&c();return}u(`docs`)}})),...f?[{key:`files`,label:`Files`,icon:(0,d.jsx)(s.FileText,{className:`w-full h-full p-1`}),onClick:()=>{u(`docs`),p()}}]:[],{key:`settings`,label:`Settings`,icon:(0,d.jsx)(P.default,{src:Jr,alt:`Settings`,width:24,height:24,className:`w-full h-full`}),menu:{renderContent:()=>(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(N.DropdownMenuItem,{onClick:()=>{t.researchAgentUIConfig.onOpenSettings?.()||n.push(`/settings`)},className:`cursor-pointer py-1 h-7`,children:[(0,d.jsx)(s.Settings,{className:`mr-2 h-3.5 w-3.5`}),(0,d.jsx)(`span`,{className:`text-sm`,children:`Settings`})]}),(0,d.jsxs)(N.DropdownMenuSub,{children:[(0,d.jsxs)(N.DropdownMenuSubTrigger,{className:`cursor-pointer py-1 h-7`,children:[(0,d.jsx)(s.Link2,{className:`mr-2 h-3.5 w-3.5`}),(0,d.jsx)(`span`,{className:`text-sm`,children:`Site Links`})]}),(0,d.jsx)(N.DropdownMenuSubContent,{children:g.map(({url:e,text:t,icon:n})=>{let r=n?s[n]:null,i=e.startsWith(`http`);return(0,d.jsx)(N.DropdownMenuItem,{asChild:!0,className:`cursor-pointer py-1 h-7`,children:i?(0,d.jsxs)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,children:[r&&(0,d.jsx)(r,{className:`mr-2 h-3.5 w-3.5`}),(0,d.jsx)(`span`,{className:`text-sm`,children:t})]}):(0,d.jsxs)(D.default,{href:e,children:[r&&(0,d.jsx)(r,{className:`mr-2 h-3.5 w-3.5`}),(0,d.jsx)(`span`,{className:`text-sm`,children:t})]})},e)})})]}),i?(0,d.jsxs)(N.DropdownMenuItem,{onClick:()=>o(),className:`cursor-pointer py-1 h-7`,children:[(0,d.jsx)(s.LogOut,{className:`mr-2 h-3.5 w-3.5`}),(0,d.jsx)(`span`,{className:`text-sm`,children:`Logout`})]}):(0,d.jsxs)(N.DropdownMenuItem,{onClick:()=>a(),className:`cursor-pointer py-1 h-7`,children:[(0,d.jsx)(s.LogIn,{className:`mr-2 h-3.5 w-3.5`}),(0,d.jsx)(`span`,{className:`text-sm`,children:`Login`})]}),(0,d.jsx)(N.DropdownMenuSeparator,{}),(0,d.jsx)(N.ThemeMenu,{})]})}}],v=_.filter(e=>e.key!==`files`),y=(e,t,n)=>(0,d.jsx)(P.default,{src:e,alt:t,width:n,height:n,unoptimized:!0,className:`w-full h-full`});return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(N.CategoryDock,{items:v,enableKeyboardShortcuts:!0,placements:{desktop:!0,mobile:!1},renderImage:y}),(0,d.jsx)(N.CategoryDock,{items:_,placements:{desktop:!1,mobile:!0},mobileAlign:l===`docs`?`end`:`center`,renderImage:y})]})}function Xr(){let[e,r]=(0,n.useState)(!1),i=(0,n.useRef)(null);return(0,n.useEffect)(()=>{localStorage.getItem(`cookie-consent`)||r(!0)},[]),(0,n.useEffect)(()=>{let t=document.documentElement,n=i.current;if(!e||!n){t.style.removeProperty(`--qs-bottom-right-inset`);return}let r=()=>t.style.setProperty(`--qs-bottom-right-inset`,`${Math.ceil(n.getBoundingClientRect().height)+16}px`);r();let a=typeof ResizeObserver>`u`?null:new ResizeObserver(r);return a?.observe(n),()=>{a?.disconnect(),t.style.removeProperty(`--qs-bottom-right-inset`)}},[e]),e?(0,d.jsx)(`div`,{className:`fixed bottom-0 right-0 m-4 max-w-sm z-50`,children:(0,d.jsxs)(`div`,{ref:i,className:`bg-light-secondary dark:bg-dark-secondary rounded-lg shadow-lg border border-light-tertiary dark:border-dark-tertiary p-4 space-y-3`,children:[(0,d.jsxs)(`div`,{className:`flex justify-between items-start gap-3`,children:[(0,d.jsxs)(`div`,{className:`flex-1`,children:[(0,d.jsx)(`h3`,{className:`font-semibold text-sm text-black dark:text-white mb-2`,children:`Cookies & Privacy`}),(0,d.jsxs)(`p`,{className:`text-xs text-black/70 dark:text-white/70 mb-3`,children:[t.researchAgentUIConfig.appName,` uses cookies to enhance your research experience, analyze usage patterns, and improve our service. We respect your privacy and only use essential cookies by default.`]}),(0,d.jsx)(`div`,{className:`flex flex-wrap gap-2 text-xs mb-3`,children:t.researchAgentUIConfig.footerLinks.map(e=>(0,d.jsx)(`a`,{href:e.url,target:e.url.startsWith(`/`)?void 0:`_blank`,rel:e.url.startsWith(`/`)?void 0:`noopener noreferrer`,className:`text-blue-600 dark:text-blue-400 hover:underline`,children:e.text},e.url))})]}),(0,d.jsx)(`button`,{onClick:()=>{r(!1)},className:`text-black/50 dark:text-white/50 hover:text-black dark:hover:text-white transition-colors`,"aria-label":`Close`,children:(0,d.jsx)(s.X,{className:`w-4 h-4`})})]}),(0,d.jsxs)(`div`,{className:`flex gap-2`,children:[(0,d.jsx)(Q,{onClick:()=>{localStorage.setItem(`cookie-consent`,JSON.stringify({analytics:!0,marketing:!0,functional:!0,timestamp:new Date().toISOString()})),r(!1)},size:`sm`,className:`flex-1 bg-blue-600 hover:bg-blue-700 text-white`,children:`Accept All`}),(0,d.jsx)(Q,{onClick:()=>{localStorage.setItem(`cookie-consent`,JSON.stringify({analytics:!1,marketing:!1,functional:!0,timestamp:new Date().toISOString()})),r(!1)},size:`sm`,variant:`outline`,className:`flex-1 bg-light-tertiary dark:bg-dark-tertiary text-black dark:text-white border-0 hover:bg-light-tertiary/80 dark:hover:bg-dark-tertiary/80`,children:`Reject`})]})]})}):null}var Zr=`qwk:chunk-error-reload`,Qr=e=>typeof e==`string`&&/Loading (chunk|CSS chunk)|ChunkLoadError/i.test(e);function $r(){(0,n.useEffect)(()=>{let e=e=>{Qr(e)&&(sessionStorage.getItem(Zr)||(sessionStorage.setItem(Zr,`1`),window.location.reload()))},t=t=>e(t.message),n=t=>e(t.reason?.message??t.reason);return window.addEventListener(`error`,t),window.addEventListener(`unhandledrejection`,n),()=>{window.removeEventListener(`error`,t),window.removeEventListener(`unhandledrejection`,n)}},[])}var ei=({children:e})=>(0,d.jsx)(d.Fragment,{children:e});function ti(e){let[t,r]=(0,n.useState)(e===!0);return(0,n.useEffect)(()=>{if(e!==`auto`){r(e);return}let t=!1;return(0,p.default)(`auth/providers`).then(e=>{t||r(!!e.providers?.includes(`google`))}).catch(()=>{t||r(!1)}),()=>{t=!0}},[e]),t}function ni({children:e,authClient:n,config:r,googleOneTap:i=`auto`,docsEnabled:a=!0,ChromeProvider:o=ei,showDock:s=!0,showCookieConsent:c=!0,showToaster:l=!0}){r&&t.configureResearchAgentUI(r);let u=ti(i);return $r(),(0,d.jsx)(M.ThemeProvider,{attribute:`class`,defaultTheme:`system`,enableSystem:!0,disableTransitionOnChange:!0,children:(0,d.jsx)(tt,{authClient:n,enableGoogleOneTap:u,children:(0,d.jsx)(te,{children:(0,d.jsxs)(rt,{children:[(0,d.jsx)(N.CategoryDockProvider,{children:(0,d.jsx)(o,{children:(0,d.jsx)(Gr,{docsEnabled:a,children:(0,d.jsxs)(`div`,{id:`app-scroll-root`,className:`w-screen h-screen overflow-y-auto overflow-x-hidden pb-[calc(60px+env(safe-area-inset-bottom,0px))] md:pb-0`,children:[s&&(0,d.jsx)(Yr,{}),(0,d.jsx)(`main`,{className:`bg-light-primary dark:bg-dark-primary min-h-screen`,children:e})]})})})}),l&&(0,d.jsx)(m.Toaster,{toastOptions:{unstyled:!0,classNames:{toast:`bg-light-secondary dark:bg-dark-secondary dark:text-white/70 text-black-70 rounded-lg p-4 flex flex-row items-center space-x-2`}}}),c&&(0,d.jsx)(Xr,{})]})})})})}function ri(e){return(0,d.jsx)(ni,{...e,docsEnabled:!1,children:(0,d.jsx)(Ir,{})})}var ii=`qwksearch-open-chat-tabs`,ai=50;function oi(){if(typeof window>`u`)return[];try{let e=window.localStorage.getItem(ii);return e?JSON.parse(e):[]}catch{return[]}}function si(){let{chatId:e,chatTurns:t,startNewChat:r,switchToChat:i}=G(),[a,o]=(0,n.useState)(oi);(0,n.useEffect)(()=>{window.localStorage.setItem(ii,JSON.stringify(a))},[a]),(0,n.useEffect)(()=>{if(!e)return;let n=t[0]?.content?.slice(0,ai),r=t.length>0;o(t=>{let i=t.find(t=>t.id===e);return i?n&&i.title!==n||i.hasMessages!==r?t.map(t=>t.id===e?{...t,title:n||t.title,hasMessages:r}:t):t:[...t,{id:e,title:n||`New Chat`,hasMessages:r}]})},[e,t]);let s=(0,n.useCallback)((e,t)=>{let n=t.find(t=>t.id===e);n&&!n.hasMessages?r(e):i(e)},[r,i]),c=(0,n.useCallback)(e=>{s(e,a)},[s,a]),l=(0,n.useCallback)(()=>{let e=crypto.randomUUID();return o(t=>[...t,{id:e,title:`New Chat`}]),r(e),e},[r]),u=(0,n.useCallback)(t=>{let n=new Set(t),r=a.filter(e=>!n.has(e.id));o(r);let i=e!=null&&n.has(e);if(!i)return{closedWasActive:!1,nextActiveId:null};if(r.length===0)return{closedWasActive:i,nextActiveId:null};let c=a.findIndex(t=>t.id===e),l=e=>e!=null&&!n.has(e.id),u;for(let e=c-1;e>=0&&!u;e--)l(a[e])&&(u=a[e]);for(let e=c+1;e<a.length&&!u;e++)l(a[e])&&(u=a[e]);let d=(u??r[0]).id;return s(d,r),{closedWasActive:i,nextActiveId:d}},[a,e,s]),d=(0,n.useCallback)(e=>u([e]),[u]);return{chatTabs:a,activeChatId:e??null,openChat:c,newChat:l,closeChat:d,closeChats:u}}Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return G}}),Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return Wn}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return rt}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return In}}),Object.defineProperty(exports,"F",{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,"I",{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,"L",{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,"M",{enumerable:!0,get:function(){return Me}}),Object.defineProperty(exports,"N",{enumerable:!0,get:function(){return te}}),Object.defineProperty(exports,"O",{enumerable:!0,get:function(){return tt}}),Object.defineProperty(exports,"P",{enumerable:!0,get:function(){return ee}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return Bn}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return Rn}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return Yn}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return Xr}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return Kn}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return Kr}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return Lr}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return Ir}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return ar}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return yr}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return $r}}),Object.defineProperty(exports,"j",{enumerable:!0,get:function(){return Ze}}),Object.defineProperty(exports,"k",{enumerable:!0,get:function(){return nt}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return Br}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return Cr}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return ri}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return Yr}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return Er}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return ni}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return Gr}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return si}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return zr}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return Jn}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return Hn}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return Gn}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return qn}});
51
+ ANTHROPIC_API_KEY=sk-ant-your_key_here`})]}),(0,d.jsxs)(`div`,{className:`bg-black/5 dark:bg-white/5 rounded p-4`,children:[(0,d.jsx)(`p`,{className:`font-medium text-black dark:text-white mb-2`,children:`3. Restart the server`}),(0,d.jsx)(`code`,{className:`block bg-black/10 dark:bg-white/10 rounded p-2 text-xs`,children:`Ctrl+C, then: npm run dev`})]})]}),(0,d.jsxs)(`div`,{className:`pt-4 border-t border-black/10 dark:border-white/10`,children:[(0,d.jsx)(`h3`,{className:`font-medium text-black dark:text-white mb-2`,children:`Get API Keys:`}),(0,d.jsxs)(`ul`,{className:`space-y-2 text-sm text-black/70 dark:text-white/70`,children:[(0,d.jsxs)(`li`,{children:[(0,d.jsx)(`strong`,{children:`Groq`}),` (FREE): `,(0,d.jsx)(`a`,{href:`https://console.groq.com/keys`,target:`_blank`,rel:`noopener noreferrer`,className:`text-blue-600 dark:text-blue-400 hover:underline`,children:`console.groq.com/keys`})]}),(0,d.jsxs)(`li`,{children:[(0,d.jsx)(`strong`,{children:`OpenAI`}),`: `,(0,d.jsx)(`a`,{href:`https://platform.openai.com/api-keys`,target:`_blank`,rel:`noopener noreferrer`,className:`text-blue-600 dark:text-blue-400 hover:underline`,children:`platform.openai.com/api-keys`})]}),(0,d.jsxs)(`li`,{children:[(0,d.jsx)(`strong`,{children:`Anthropic`}),`: `,(0,d.jsx)(`a`,{href:`https://console.anthropic.com/settings/keys`,target:`_blank`,rel:`noopener noreferrer`,className:`text-blue-600 dark:text-blue-400 hover:underline`,children:`console.anthropic.com`})]})]})]})]}),(0,d.jsxs)(`div`,{className:`text-xs text-black/50 dark:text-white/50 pt-4 border-t border-black/10 dark:border-white/10`,children:[`See `,(0,d.jsx)(`code`,{children:`SETUP_INSTRUCTIONS.md`}),` in the project root for full details.`]})]})})}var Gr=()=>{let e=(0,r.useRouter)(),{hasError:t,isReady:i,notFound:a,messages:o}=G(),{isAuthenticated:s}=nt();return(0,n.useEffect)(()=>{i&&a&&!s&&e.replace(`/`)},[i,a,s,e]),t?(0,d.jsx)(Wr,{}):i&&a&&!s?(0,d.jsx)(`div`,{className:`flex flex-row items-center justify-center min-h-screen`,children:(0,d.jsx)(Ur,{})}):i?a?(0,d.jsxs)(`div`,{className:`flex min-h-screen flex-col items-center justify-center gap-3 px-4 text-center`,children:[(0,d.jsx)(`p`,{className:`text-sm text-black/70 dark:text-white/70`,children:`This chat could not be found.`}),(0,d.jsx)(`button`,{type:`button`,onClick:()=>e.push(`/`),className:`rounded-md border border-black/15 px-3 py-1.5 text-sm hover:bg-black/5 dark:border-white/20 dark:hover:bg-white/10`,children:`Go Home`})]}):(0,d.jsx)(`div`,{children:o.length>0?(0,d.jsx)(d.Fragment,{children:(0,d.jsx)(vr,{})}):(0,d.jsx)(Hr,{})}):(0,d.jsx)(`div`,{className:`flex flex-row items-center justify-center min-h-screen`,children:(0,d.jsx)(Ur,{})})};function Kr(e,t){let[r,i]=(0,n.useState)(`idle`),[a,o]=(0,n.useState)(!1),[s,c]=(0,n.useState)([]),[l,u]=(0,n.useState)(`af_heart`),[d,f]=(0,n.useState)(null),p=(0,n.useRef)(null),m=(0,n.useRef)(null);(0,n.useEffect)(()=>{t?.autoPreload&&!a&&g()},[t?.autoPreload,a]),(0,n.useEffect)(()=>{let e=localStorage.getItem(`kokoroVoice`);e&&u(e)},[]),(0,n.useEffect)(()=>()=>{p.current&&p.current.pause(),m.current?.abort()},[]);let h=(0,n.useCallback)(()=>{p.current&&=(p.current.pause(),p.current.src.startsWith(`blob:`)&&URL.revokeObjectURL(p.current.src),null),m.current?.abort(),m.current=null},[]),g=(0,n.useCallback)(async()=>{try{i(`loading`),f(null),await Oe();let e=await Ae();c(e),e.length&&!e.includes(l)&&u(e[0]),o(!0),i(`idle`)}catch(e){let t=e instanceof Error?e.message:`Failed to load model`;f(t),i(`error`),console.error(`Failed to load Kokoro model:`,e)}},[l]);return{status:r,modelReady:a,voices:s,selectedVoice:l,error:d,warmupModel:g,speak:(0,n.useCallback)(async()=>{if(e?.trim()){if(!a){f(`Model not loaded. Click "Preload Model" first.`);return}try{h(),i(`generating`),f(null);let t=new AbortController;m.current=t;let n=(await(await ke()).generate(e.slice(0,5e3),{voice:l})).toWav(),r=new Blob([n],{type:`audio/wav`}),a=URL.createObjectURL(r),o=new Audio(a);p.current=o,o.onended=()=>{i(`idle`),URL.revokeObjectURL(a),p.current=null},o.onerror=()=>{i(`error`),f(`Failed to play audio`),URL.revokeObjectURL(a),p.current=null},i(`playing`),await o.play()}catch(e){if(e?.name!==`AbortError`){let t=e instanceof Error?e.message:`Speech generation failed`;f(t),i(`error`),console.error(`Kokoro TTS error:`,e)}}}},[e,l,a,h]),stop:(0,n.useCallback)(()=>{h(),i(`idle`),f(null)},[h]),changeVoice:(0,n.useCallback)(e=>{u(e),localStorage.setItem(`kokoroVoice`,e)},[]),backend:je()}}var qr={af_heart:`American Female - Heart`,af_bella:`American Female - Bella`,af_nicole:`American Female - Nicole`,af_sarah:`American Female - Sarah`,am_adam:`American Male - Adam`,am_michael:`American Male - Michael`,am_tony:`American Male - Tony`,bf_emma:`British Female - Emma`,bm_george:`British Male - George`,bm_thomas:`British Male - Thomas`};function Jr({preloadOnMount:e=!1}){let{status:t,modelReady:r,voices:i,selectedVoice:a,error:o,warmupModel:c,changeVoice:l,backend:u}=Kr(``,{autoPreload:e}),[f,p]=(0,n.useState)(!1),m=t===`loading`,h=t===`error`;return(0,d.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,d.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,d.jsxs)(K,{children:[(0,d.jsx)(q,{asChild:!0,children:(0,d.jsx)(`button`,{onClick:c,disabled:m||r,className:F(`p-2 rounded-full transition duration-200`,r?`bg-green-500/10 text-green-600 dark:text-green-400`:`bg-white/10 dark:bg-black/10 text-muted-foreground hover:bg-white/20 dark:hover:bg-black/20`,m&&`opacity-70 cursor-not-allowed`),children:m?(0,d.jsx)(s.Loader2,{size:18,className:`animate-spin`}):(0,d.jsx)(s.Download,{size:18})})}),(0,d.jsx)(J,{side:`bottom`,children:m?`Loading Kokoro model...`:r?`Model ready`:`Preload Kokoro.js model`})]}),r&&u&&(0,d.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[u,` • `,i.length,` voices`]}),h&&(0,d.jsxs)(K,{children:[(0,d.jsx)(q,{asChild:!0,children:(0,d.jsx)(s.AlertCircle,{size:18,className:`text-red-500`})}),(0,d.jsx)(J,{side:`bottom`,className:`max-w-xs`,children:o})]})]}),r&&(0,d.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,d.jsx)(`button`,{onClick:()=>p(!f),className:`w-full text-left px-3 py-2 rounded-md bg-white/5 dark:bg-black/5 hover:bg-white/10 dark:hover:bg-black/10 transition text-sm font-medium`,children:(0,d.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,d.jsx)(s.Volume2,{size:16}),qr[a]||a]})}),f&&(0,d.jsx)(`div`,{className:`grid grid-cols-2 gap-2 p-2 bg-white/5 dark:bg-black/5 rounded-md max-h-64 overflow-y-auto`,children:i.map(e=>(0,d.jsx)(`button`,{onClick:()=>{l(e),p(!1)},className:F(`p-2 text-left text-sm rounded transition duration-200`,a===e?`bg-blue-500/20 text-blue-600 dark:text-blue-400 font-medium`:`bg-white/5 dark:bg-black/5 text-foreground hover:bg-white/10 dark:hover:bg-black/10`),children:qr[e]||e},e))})]})]})}function Yr(){let[e,t]=(0,n.useState)(!1),[r,i]=(0,n.useState)(()=>localStorage.getItem(`useTTSKokoro`)!==`false`),[a,o]=(0,n.useState)(()=>localStorage.getItem(`ttsSpeaker`)||`angus`),[c,l]=(0,n.useState)(()=>pn()),{start:u,speechStatus:f}=Me(`This is a preview of the selected voice.`,{enableInterrupt:!1}),p=e=>{i(e),localStorage.setItem(`useTTSKokoro`,String(e))},m=e=>{o(e),localStorage.setItem(`ttsSpeaker`,e)},h=e=>{l(e),mn(e)};return(0,d.jsxs)(`div`,{className:`space-y-4`,children:[(0,d.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,d.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,d.jsx)(s.Settings2,{size:18}),(0,d.jsx)(`h3`,{className:`font-semibold`,children:`Voice Settings`})]}),(0,d.jsx)(`button`,{onClick:()=>t(!e),className:`text-xs px-3 py-1 rounded-md bg-white/10 dark:bg-black/10 hover:bg-white/20 dark:hover:bg-black/20 transition`,children:e?`Collapse`:`Expand`})]}),e&&(0,d.jsxs)(`div`,{className:`space-y-4 p-4 rounded-lg bg-white/5 dark:bg-black/5 border border-white/10 dark:border-black/10`,children:[(0,d.jsxs)(`div`,{className:`space-y-2`,children:[(0,d.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,d.jsx)(`input`,{type:`checkbox`,checked:r,onChange:e=>p(e.target.checked),className:`rounded`}),(0,d.jsx)(`span`,{className:`font-medium text-sm`,children:`Use Kokoro.js (Local TTS)`}),(0,d.jsxs)(K,{children:[(0,d.jsx)(q,{asChild:!0,children:(0,d.jsx)(`span`,{className:`text-xs text-muted-foreground cursor-help`,children:`ⓘ`})}),(0,d.jsx)(J,{side:`right`,className:`max-w-xs`,children:`Runs locally in your browser. No server requests, lower latency, and multiple voice options.`})]})]}),r&&(0,d.jsx)(Jr,{preloadOnMount:!1})]}),(0,d.jsxs)(`div`,{className:`space-y-2`,children:[(0,d.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,d.jsx)(`input`,{type:`checkbox`,checked:!r,onChange:e=>p(!e.target.checked),className:`rounded`}),(0,d.jsx)(`span`,{className:`font-medium text-sm`,children:`Use Cloudflare TTS (Fallback)`}),(0,d.jsxs)(K,{children:[(0,d.jsx)(q,{asChild:!0,children:(0,d.jsx)(`span`,{className:`text-xs text-muted-foreground cursor-help`,children:`ⓘ`})}),(0,d.jsx)(J,{side:`right`,className:`max-w-xs`,children:`Uses Cloudflare Workers AI. Slightly higher latency but can be a fallback.`})]})]}),!r&&(0,d.jsxs)(`div`,{className:`space-y-2`,children:[(0,d.jsxs)(`select`,{value:a,onChange:e=>m(e.target.value),className:`w-full px-3 py-2 rounded-md bg-white/10 dark:bg-black/10 border border-white/20 dark:border-black/20 text-sm`,children:[(0,d.jsx)(`option`,{value:`angus`,children:`Angus`}),(0,d.jsx)(`option`,{value:`flora`,children:`Flora`}),(0,d.jsx)(`option`,{value:`james`,children:`James`}),(0,d.jsx)(`option`,{value:`natalie`,children:`Natalie`})]}),(0,d.jsxs)(`button`,{onClick:()=>u(),disabled:f===`started`,className:F(`w-full flex items-center justify-center gap-2 px-3 py-2 rounded-md text-sm font-medium transition`,f===`started`?`bg-gray-500/20 text-gray-600 dark:text-gray-400 cursor-not-allowed`:`bg-blue-500/20 text-blue-600 dark:text-blue-400 hover:bg-blue-500/30`),children:[(0,d.jsx)(s.Volume2,{size:16}),f===`started`?`Playing...`:`Preview`]})]})]}),(0,d.jsx)(`div`,{className:`space-y-2 pt-2 border-t border-white/10 dark:border-black/10`,children:(0,d.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,d.jsx)(`input`,{type:`checkbox`,checked:c,onChange:e=>h(e.target.checked),className:`rounded`}),(0,d.jsx)(`span`,{className:`font-medium text-sm`,children:`Start talking automatically on first visit`}),(0,d.jsxs)(K,{children:[(0,d.jsx)(q,{asChild:!0,children:(0,d.jsx)(`span`,{className:`text-xs text-muted-foreground cursor-help`,children:`ⓘ`})}),(0,d.jsx)(J,{side:`right`,className:`max-w-xs`,children:`Opens the mic the first time you load the chat composer in this browser, so you can start talking right away instead of clicking the mic button.`})]})]})}),(0,d.jsx)(`div`,{className:`text-xs text-muted-foreground pt-2 border-t border-white/10 dark:border-black/10`,children:(0,d.jsxs)(`p`,{children:[(0,d.jsx)(`strong`,{children:`Tip:`}),` Kokoro.js loads once and runs locally. The first model load may take a few seconds, but subsequent TTS generation is very fast.`]})})]})]})}function Xr(e,t){if(!e.startsWith(`/`)||e.includes(`#`)||e.includes(`?`))return!1;let n=e.replace(/\/+$/,``)||`/`,r=t.replace(/\/+$/,``)||`/`;return n===`/`?r===`/`:r===n||r.startsWith(`${n}/`)}function Zr(e,t){return t?e.filter(e=>!Xr(e.url,t)):e}var Qr=(0,n.createContext)(null),$r=`qwksearch-main-view`;function ei({children:e,docsEnabled:t=!0}){let[r,i]=(0,n.useState)(`research`),[a,o]=(0,n.useState)(0),s=(0,n.useCallback)(e=>i(t?e:`research`),[t]);(0,n.useEffect)(()=>{if(typeof window>`u`||!t)return;let e=window.localStorage.getItem($r);(e===`research`||e===`docs`)&&i(e)},[t]),(0,n.useEffect)(()=>{typeof window<`u`&&t&&window.localStorage.setItem($r,r)},[r,t]);let c=(0,n.useMemo)(()=>({activeView:r,setActiveView:s,docsEnabled:t,toggleToDocs:()=>s(`docs`),toggleToResearch:()=>s(`research`),filesSidebarRequestId:a,requestFilesSidebar:()=>o(e=>e+1)}),[r,s,t,a]);return(0,d.jsx)(Qr.Provider,{value:c,children:e})}function ti(){let e=(0,n.useContext)(Qr);if(!e)throw Error(`useMainView must be used within a MainViewProvider`);return e}var ni=`data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='iso-8859-1'?%3e%3csvg%20height='800px'%20width='800px'%20version='1.1'%20id='Layer_1'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20viewBox='0%200%20512%20512'%20xml:space='preserve'%3e%3cpath%20style='fill:%23FE5022;'%20d='M438.802,390.609V278.595h55.174c9.938,0,18.023,8.085,18.023,18.023v75.967%20c0,9.938-8.086,18.024-18.023,18.024L438.802,390.609L438.802,390.609z'/%3e%3cpath%20style='fill:%23ECE5DD;'%20d='M28.107,511.637C12.609,511.637,0,499.027,0,483.529V134.326c0-1.441,0-12.123,0-12.123%20L121.715,0.363c0,0,10.8,0,12.248,0h271.569c15.498,0,28.107,12.609,28.107,28.106v455.059c0,15.499-12.609,28.108-28.107,28.108%20H28.107V511.637z'/%3e%3cpath%20style='fill:%23D9CBBD;'%20d='M405.533,0.363h-31.991c15.498,0,28.107,12.609,28.107,28.107v455.059%20c0,15.499-12.609,28.108-28.107,28.108h31.991c15.498,0,28.107-12.609,28.107-28.108V28.469%20C433.64,12.972,421.031,0.363,405.533,0.363z'/%3e%3cg%3e%3cpath%20style='fill:%23BABABA;'%20d='M167.639,132.2h133.086c4.594,0,8.318-3.723,8.318-8.318c0-4.595-3.724-8.318-8.318-8.318H167.639%20c-4.594,0-8.318,3.723-8.318,8.318C159.321,128.477,163.045,132.2,167.639,132.2z'/%3e%3cpath%20style='fill:%23BABABA;'%20d='M356.178,132.2h22.181c4.594,0,8.318-3.723,8.318-8.318c0-4.595-3.724-8.318-8.318-8.318h-22.181%20c-4.594,0-8.318,3.723-8.318,8.318C347.86,128.477,351.584,132.2,356.178,132.2z'/%3e%3cpath%20style='fill:%23BABABA;'%20d='M242.5,212.606c0-4.595-3.724-8.318-8.318-8.318H56.734c-4.594,0-8.318,3.723-8.318,8.318%20s3.724,8.318,8.318,8.318h177.449C238.776,220.924,242.5,217.201,242.5,212.606z'/%3e%3cpath%20style='fill:%23BABABA;'%20d='M378.359,204.288h-99.815c-4.594,0-8.318,3.723-8.318,8.318s3.724,8.318,8.318,8.318h99.815%20c4.594,0,8.318-3.723,8.318-8.318S382.953,204.288,378.359,204.288z'/%3e%3c/g%3e%3cpath%20style='fill:%23D9CBBD;'%20d='M0.726,123.171L122.442,1.331l1.39,105.939c0,9.465-7.7,17.166-17.166,17.166L0.726,123.171z'/%3e%3cpath%20style='fill:%23FFB656;'%20d='M270.226,401.7V267.504H456.87c5.938,0,10.768,4.83,10.768,10.768v112.659%20c0,5.938-4.83,10.769-10.768,10.769H270.226z'/%3e%3cpath%20style='fill:%23D9CBBD;'%20d='M367.785,335.156c-12.822,0-23.252-10.431-23.252-23.254v-44.399h89.833v44.399%20c0,12.823-10.431,23.254-23.252,23.254H367.785z'/%3e%3cg%3e%3cpath%20style='fill:%23BABABA;'%20d='M167.639,132.2h133.086c4.594,0,8.318-3.723,8.318-8.318c0-4.595-3.724-8.318-8.318-8.318H167.639%20c-4.594,0-8.318,3.723-8.318,8.318C159.321,128.477,163.045,132.2,167.639,132.2z'/%3e%3cpath%20style='fill:%23BABABA;'%20d='M356.178,132.2h22.181c4.594,0,8.318-3.723,8.318-8.318c0-4.595-3.724-8.318-8.318-8.318h-22.181%20c-4.594,0-8.318,3.723-8.318,8.318C347.86,128.477,351.584,132.2,356.178,132.2z'/%3e%3cpath%20style='fill:%23BABABA;'%20d='M242.5,212.606c0-4.595-3.724-8.318-8.318-8.318H56.734c-4.594,0-8.318,3.723-8.318,8.318%20s3.724,8.318,8.318,8.318h177.449C238.776,220.924,242.5,217.201,242.5,212.606z'/%3e%3cpath%20style='fill:%23BABABA;'%20d='M378.359,204.288h-99.815c-4.594,0-8.318,3.723-8.318,8.318s3.724,8.318,8.318,8.318h99.815%20c4.594,0,8.318-3.723,8.318-8.318S382.953,204.288,378.359,204.288z'/%3e%3cpath%20style='fill:%23BABABA;'%20d='M345.087,448.28H101.096c-4.594,0-8.318,3.723-8.318,8.318c0,4.595,3.724,8.318,8.318,8.318h243.992%20c4.594,0,8.318-3.723,8.318-8.318C353.405,452.003,349.681,448.28,345.087,448.28z'/%3e%3c/g%3e%3cpath%20style='fill:%23FE5022;'%20d='M163.689,357.337c-3.692,0-6.094-3.886-4.443-7.189l16.225-32.451%20c1.799-3.597,5.416-5.833,9.438-5.833h44.282v45.471h-65.503V357.337z'/%3e%3cpolygon%20style='fill:%23FFB656;'%20points='256.918,278.252%20211.447,300.988%20211.447,368.216%20256.918,390.953%20284.321,390.953%20284.321,278.214%20'/%3e%3cg%3e%3cpath%20style='fill:%23FE5022;'%20d='M268.64,401.7c-7.075,0-12.832-5.756-12.832-12.832V280.336c0-7.075,5.756-12.831,12.832-12.831%20h19.808c7.075,0,12.832,5.756,12.832,12.831v108.532c0,7.076-5.756,12.832-12.832,12.832H268.64z'/%3e%3cpath%20style='fill:%23FE5022;'%20d='M104.156,379.377H26.143V301.33h91.398c8.546,0,14.88,7.936,12.986,16.27l-11.313,49.758%20C117.615,374.388,111.366,379.377,104.156,379.377z'/%3e%3c/g%3e%3c/svg%3e`,ri=`data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='utf-8'?%3e%3csvg%20height='800px'%20width='800px'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20viewBox='0%200%2064%2064'%20xml:space='preserve'%3e%3cstyle%20type='text/css'%3e%20.st0{fill:%2376C2AF;}%20.st1{fill:%234F5D73;}%20.st2{opacity:0.2;}%20.st3{fill:%23231F20;}%20.st4{fill:%23FFFFFF;}%20%3c/style%3e%3cg%20id='Layer_1'%3e%3cg%3e%3ccircle%20class='st0'%20cx='32'%20cy='32'%20r='32'/%3e%3c/g%3e%3cg%3e%3cpath%20class='st1'%20d='M32,52c-1.1,0-2-0.9-2-2V18c0-1.1,0.9-2,2-2l0,0c1.1,0,2,0.9,2,2v32C34,51.1,33.1,52,32,52L32,52z'/%3e%3c/g%3e%3cg%3e%3cpath%20class='st1'%20d='M46,52c-1.1,0-2-0.9-2-2V18c0-1.1,0.9-2,2-2l0,0c1.1,0,2,0.9,2,2v32C48,51.1,47.1,52,46,52L46,52z'/%3e%3c/g%3e%3cg%3e%3cpath%20class='st1'%20d='M18,52c-1.1,0-2-0.9-2-2V18c0-1.1,0.9-2,2-2l0,0c1.1,0,2,0.9,2,2v32C20,51.1,19.1,52,18,52L18,52z'/%3e%3c/g%3e%3cg%20class='st2'%3e%3ccircle%20class='st3'%20cx='45.9'%20cy='38'%20r='4'/%3e%3c/g%3e%3cg%20class='st2'%3e%3ccircle%20class='st3'%20cx='32'%20cy='27'%20r='4'/%3e%3c/g%3e%3cg%20class='st2'%3e%3ccircle%20class='st3'%20cx='18'%20cy='44'%20r='4'/%3e%3c/g%3e%3cg%3e%3ccircle%20class='st4'%20cx='45.9'%20cy='36'%20r='4'/%3e%3c/g%3e%3cg%3e%3ccircle%20class='st4'%20cx='32'%20cy='25'%20r='4'/%3e%3c/g%3e%3cg%3e%3ccircle%20class='st4'%20cx='18'%20cy='42'%20r='4'/%3e%3c/g%3e%3c/g%3e%3cg%20id='Layer_2'%3e%3c/g%3e%3c/svg%3e`;function ii(){let e=(0,r.usePathname)(),n=(0,r.useRouter)(),{isAuthenticated:i,signIn:a,signOut:o}=nt(),{newChat:c}=G(),{activeView:l,setActiveView:u,docsEnabled:f,requestFilesSidebar:p}=ti(),m=[{href:`/`,label:`Research`,icon:t.researchAgentUIConfig.appIconUrl},...f?[{href:`/workspace`,label:`Docs`,icon:(0,d.jsx)(P.default,{src:ni,alt:`Docs`,width:24,height:24,className:`w-full h-full`})}]:[]],h=e===`/`||e.startsWith(`/c`),g=Zr(t.researchAgentUIConfig.footerLinks,e),_=[...m.map(({href:e,label:t,icon:n})=>({key:e,label:t,icon:n,active:e===`/`?l===`research`:l===`docs`,onClick:()=>{if(e===`/`){u(`research`),h&&c();return}u(`docs`)}})),...f?[{key:`files`,label:`Files`,icon:(0,d.jsx)(s.FileText,{className:`w-full h-full p-1`}),onClick:()=>{u(`docs`),p()}}]:[],{key:`settings`,label:`Settings`,icon:(0,d.jsx)(P.default,{src:ri,alt:`Settings`,width:24,height:24,className:`w-full h-full`}),menu:{renderContent:()=>(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(N.DropdownMenuItem,{onClick:()=>{t.researchAgentUIConfig.onOpenSettings?.()||n.push(`/settings`)},className:`cursor-pointer py-1 h-7`,children:[(0,d.jsx)(s.Settings,{className:`mr-2 h-3.5 w-3.5`}),(0,d.jsx)(`span`,{className:`text-sm`,children:`Settings`})]}),(0,d.jsxs)(N.DropdownMenuSub,{children:[(0,d.jsxs)(N.DropdownMenuSubTrigger,{className:`cursor-pointer py-1 h-7`,children:[(0,d.jsx)(s.Link2,{className:`mr-2 h-3.5 w-3.5`}),(0,d.jsx)(`span`,{className:`text-sm`,children:`Site Links`})]}),(0,d.jsx)(N.DropdownMenuSubContent,{children:g.map(({url:e,text:t,icon:n})=>{let r=n?s[n]:null,i=e.startsWith(`http`);return(0,d.jsx)(N.DropdownMenuItem,{asChild:!0,className:`cursor-pointer py-1 h-7`,children:i?(0,d.jsxs)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,children:[r&&(0,d.jsx)(r,{className:`mr-2 h-3.5 w-3.5`}),(0,d.jsx)(`span`,{className:`text-sm`,children:t})]}):(0,d.jsxs)(D.default,{href:e,children:[r&&(0,d.jsx)(r,{className:`mr-2 h-3.5 w-3.5`}),(0,d.jsx)(`span`,{className:`text-sm`,children:t})]})},e)})})]}),i?(0,d.jsxs)(N.DropdownMenuItem,{onClick:()=>o(),className:`cursor-pointer py-1 h-7`,children:[(0,d.jsx)(s.LogOut,{className:`mr-2 h-3.5 w-3.5`}),(0,d.jsx)(`span`,{className:`text-sm`,children:`Logout`})]}):(0,d.jsxs)(N.DropdownMenuItem,{onClick:()=>a(),className:`cursor-pointer py-1 h-7`,children:[(0,d.jsx)(s.LogIn,{className:`mr-2 h-3.5 w-3.5`}),(0,d.jsx)(`span`,{className:`text-sm`,children:`Login`})]}),(0,d.jsx)(N.DropdownMenuSeparator,{}),(0,d.jsx)(N.ThemeMenu,{})]})}}],v=_.filter(e=>e.key!==`files`),y=(e,t,n)=>(0,d.jsx)(P.default,{src:e,alt:t,width:n,height:n,unoptimized:!0,className:`w-full h-full`});return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(N.CategoryDock,{items:v,enableKeyboardShortcuts:!0,placements:{desktop:!0,mobile:!1},renderImage:y}),(0,d.jsx)(N.CategoryDock,{items:_,placements:{desktop:!1,mobile:!0},mobileAlign:l===`docs`?`end`:`center`,renderImage:y})]})}function ai(){let[e,r]=(0,n.useState)(!1),i=(0,n.useRef)(null);return(0,n.useEffect)(()=>{localStorage.getItem(`cookie-consent`)||r(!0)},[]),(0,n.useEffect)(()=>{let t=document.documentElement,n=i.current;if(!e||!n){t.style.removeProperty(`--qs-bottom-right-inset`);return}let r=()=>t.style.setProperty(`--qs-bottom-right-inset`,`${Math.ceil(n.getBoundingClientRect().height)+16}px`);r();let a=typeof ResizeObserver>`u`?null:new ResizeObserver(r);return a?.observe(n),()=>{a?.disconnect(),t.style.removeProperty(`--qs-bottom-right-inset`)}},[e]),e?(0,d.jsx)(`div`,{className:`fixed bottom-0 right-0 m-4 max-w-sm z-50`,children:(0,d.jsxs)(`div`,{ref:i,className:`bg-light-secondary dark:bg-dark-secondary rounded-lg shadow-lg border border-light-tertiary dark:border-dark-tertiary p-4 space-y-3`,children:[(0,d.jsxs)(`div`,{className:`flex justify-between items-start gap-3`,children:[(0,d.jsxs)(`div`,{className:`flex-1`,children:[(0,d.jsx)(`h3`,{className:`font-semibold text-sm text-black dark:text-white mb-2`,children:`Cookies & Privacy`}),(0,d.jsxs)(`p`,{className:`text-xs text-black/70 dark:text-white/70 mb-3`,children:[t.researchAgentUIConfig.appName,` uses cookies to enhance your research experience, analyze usage patterns, and improve our service. We respect your privacy and only use essential cookies by default.`]}),(0,d.jsx)(`div`,{className:`flex flex-wrap gap-2 text-xs mb-3`,children:t.researchAgentUIConfig.footerLinks.map(e=>(0,d.jsx)(`a`,{href:e.url,target:e.url.startsWith(`/`)?void 0:`_blank`,rel:e.url.startsWith(`/`)?void 0:`noopener noreferrer`,className:`text-blue-600 dark:text-blue-400 hover:underline`,children:e.text},e.url))})]}),(0,d.jsx)(`button`,{onClick:()=>{r(!1)},className:`text-black/50 dark:text-white/50 hover:text-black dark:hover:text-white transition-colors`,"aria-label":`Close`,children:(0,d.jsx)(s.X,{className:`w-4 h-4`})})]}),(0,d.jsxs)(`div`,{className:`flex gap-2`,children:[(0,d.jsx)(Q,{onClick:()=>{localStorage.setItem(`cookie-consent`,JSON.stringify({analytics:!0,marketing:!0,functional:!0,timestamp:new Date().toISOString()})),r(!1)},size:`sm`,className:`flex-1 bg-blue-600 hover:bg-blue-700 text-white`,children:`Accept All`}),(0,d.jsx)(Q,{onClick:()=>{localStorage.setItem(`cookie-consent`,JSON.stringify({analytics:!1,marketing:!1,functional:!0,timestamp:new Date().toISOString()})),r(!1)},size:`sm`,variant:`outline`,className:`flex-1 bg-light-tertiary dark:bg-dark-tertiary text-black dark:text-white border-0 hover:bg-light-tertiary/80 dark:hover:bg-dark-tertiary/80`,children:`Reject`})]})]})}):null}var oi=`qwk:chunk-error-reload`,si=e=>typeof e==`string`&&/Loading (chunk|CSS chunk)|ChunkLoadError/i.test(e);function ci(){(0,n.useEffect)(()=>{let e=e=>{si(e)&&(sessionStorage.getItem(oi)||(sessionStorage.setItem(oi,`1`),window.location.reload()))},t=t=>e(t.message),n=t=>e(t.reason?.message??t.reason);return window.addEventListener(`error`,t),window.addEventListener(`unhandledrejection`,n),()=>{window.removeEventListener(`error`,t),window.removeEventListener(`unhandledrejection`,n)}},[])}var li=({children:e})=>(0,d.jsx)(d.Fragment,{children:e});function ui(e){let[t,r]=(0,n.useState)(e===!0);return(0,n.useEffect)(()=>{if(e!==`auto`){r(e);return}let t=!1;return(0,p.default)(`auth/providers`).then(e=>{t||r(!!e.providers?.includes(`google`))}).catch(()=>{t||r(!1)}),()=>{t=!0}},[e]),t}function di({children:e,authClient:n,config:r,googleOneTap:i=`auto`,docsEnabled:a=!0,ChromeProvider:o=li,showDock:s=!0,showCookieConsent:c=!0,showToaster:l=!0}){r&&t.configureResearchAgentUI(r);let u=ui(i);return ci(),(0,d.jsx)(M.ThemeProvider,{attribute:`class`,defaultTheme:`system`,enableSystem:!0,disableTransitionOnChange:!0,children:(0,d.jsx)(tt,{authClient:n,enableGoogleOneTap:u,children:(0,d.jsx)(te,{children:(0,d.jsxs)(rt,{children:[(0,d.jsx)(N.CategoryDockProvider,{children:(0,d.jsx)(o,{children:(0,d.jsx)(ei,{docsEnabled:a,children:(0,d.jsxs)(`div`,{id:`app-scroll-root`,className:`w-screen h-screen overflow-y-auto overflow-x-hidden pb-[calc(60px+env(safe-area-inset-bottom,0px))] md:pb-0`,children:[s&&(0,d.jsx)(ii,{}),(0,d.jsx)(`main`,{className:`bg-light-primary dark:bg-dark-primary min-h-screen`,children:e})]})})})}),l&&(0,d.jsx)(m.Toaster,{toastOptions:{unstyled:!0,classNames:{toast:`bg-light-secondary dark:bg-dark-secondary dark:text-white/70 text-black-70 rounded-lg p-4 flex flex-row items-center space-x-2`}}}),c&&(0,d.jsx)(ai,{})]})})})})}function fi(e){return(0,d.jsx)(di,{...e,docsEnabled:!1,children:(0,d.jsx)(Gr,{})})}var pi=`qwksearch-open-chat-tabs`,mi=50;function hi(){if(typeof window>`u`)return[];try{let e=window.localStorage.getItem(pi);return e?JSON.parse(e):[]}catch{return[]}}function gi(){let{chatId:e,chatTurns:t,startNewChat:r,switchToChat:i}=G(),[a,o]=(0,n.useState)(hi);(0,n.useEffect)(()=>{window.localStorage.setItem(pi,JSON.stringify(a))},[a]),(0,n.useEffect)(()=>{if(!e)return;let n=t[0]?.content?.slice(0,mi),r=t.length>0;o(t=>{let i=t.find(t=>t.id===e);return i?n&&i.title!==n||i.hasMessages!==r?t.map(t=>t.id===e?{...t,title:n||t.title,hasMessages:r}:t):t:[...t,{id:e,title:n||`New Chat`,hasMessages:r}]})},[e,t]);let s=(0,n.useCallback)((e,t)=>{let n=t.find(t=>t.id===e);n&&!n.hasMessages?r(e):i(e)},[r,i]),c=(0,n.useCallback)(e=>{s(e,a)},[s,a]),l=(0,n.useCallback)(()=>{let e=crypto.randomUUID();return o(t=>[...t,{id:e,title:`New Chat`}]),r(e),e},[r]),u=(0,n.useCallback)(t=>{let n=new Set(t),r=a.filter(e=>!n.has(e.id));o(r);let i=e!=null&&n.has(e);if(!i)return{closedWasActive:!1,nextActiveId:null};if(r.length===0)return{closedWasActive:i,nextActiveId:null};let c=a.findIndex(t=>t.id===e),l=e=>e!=null&&!n.has(e.id),u;for(let e=c-1;e>=0&&!u;e--)l(a[e])&&(u=a[e]);for(let e=c+1;e<a.length&&!u;e++)l(a[e])&&(u=a[e]);let d=(u??r[0]).id;return s(d,r),{closedWasActive:i,nextActiveId:d}},[a,e,s]),d=(0,n.useCallback)(e=>u([e]),[u]);return{chatTabs:a,activeChatId:e??null,openChat:c,newChat:l,closeChat:d,closeChats:u}}Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return G}}),Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return $n}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return rt}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return Gn}}),Object.defineProperty(exports,"F",{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,"I",{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,"L",{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,"M",{enumerable:!0,get:function(){return Me}}),Object.defineProperty(exports,"N",{enumerable:!0,get:function(){return te}}),Object.defineProperty(exports,"O",{enumerable:!0,get:function(){return tt}}),Object.defineProperty(exports,"P",{enumerable:!0,get:function(){return ee}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return Yn}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return qn}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return ir}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return ai}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return tr}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return ti}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return Kr}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return Gr}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return mr}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return Or}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return ci}}),Object.defineProperty(exports,"j",{enumerable:!0,get:function(){return Ze}}),Object.defineProperty(exports,"k",{enumerable:!0,get:function(){return nt}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return Yr}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return Mr}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return fi}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return ii}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return Fr}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return di}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return ei}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return gi}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return Jr}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return rr}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return Zn}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return er}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return nr}});