research-agent-ui 0.1.10 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -13,7 +13,7 @@
13
13
  #5a922c calc(50% / var(--repeating-conic-gradient-times)),
14
14
  #4c7894 calc(75% / var(--repeating-conic-gradient-times)),
15
15
  #dd7bbb calc(100% / var(--repeating-conic-gradient-times))
16
- )`},className:D(`pointer-events-none absolute inset-0 rounded-[inherit] opacity-100 transition-opacity`,o&&`opacity-100`,e>0&&`blur-[var(--blur)] `,s,u&&`!hidden`),children:(0,f.jsx)(`div`,{className:D(`glow`,`rounded-[inherit]`,`after:content-[""] after:rounded-[inherit] after:absolute after:inset-[calc(-1*var(--glowingeffect-border-width))]`,`after:[border:var(--glowingeffect-border-width)_solid_transparent]`,`after:[background:var(--gradient)] after:[background-attachment:fixed]`,`after:opacity-[var(--active)] after:transition-opacity after:duration-300`,`after:[mask-clip:padding-box,border-box]`,`after:[mask-composite:intersect]`,`after:[mask-image:linear-gradient(#0000,#0000),conic-gradient(from_calc((var(--start)-var(--spread))*1deg),#00000000_0deg,#fff,#00000000_calc(var(--spread)*2deg))]`)})})]})});k.displayName=`GlowingEffect`;var A=(0,n.createContext)(void 0),j=()=>{let e=(0,n.useContext)(A);if(!e)throw Error(`useExtractPanel must be used within an ExtractPanelProvider`);return e},M=({children:e})=>{let[t,r]=(0,n.useState)(!1),[i,a]=(0,n.useState)(``),[o,s]=(0,n.useState)(``),[c,l]=(0,n.useState)(600);return(0,f.jsx)(A.Provider,{value:{isOpen:t,url:i,searchText:o,panelWidth:c,setIsOpen:r,setUrl:a,setSearchText:s,setPanelWidth:l,openPanel:(e,t=``)=>{console.log(`[ExtractPanelContext] openPanel called with URL:`,e);try{let t=new URL(e);(t.pathname===`/`||t.pathname===``)&&console.error(`[ExtractPanelContext] URL is domain-only, missing article path:`,e)}catch(t){console.error(`[ExtractPanelContext] Invalid URL format:`,e,t)}if(a(e),s(t),r(!0),typeof window<`u`){let t=new URLSearchParams(window.location.search);t.set(`extract`,encodeURIComponent(e));let n=`${window.location.pathname}?${t.toString()}`;window.history.pushState({},``,n)}},closePanel:()=>{if(r(!1),typeof window<`u`){let e=new URLSearchParams(window.location.search);e.delete(`extract`);let t=e.toString()?`${window.location.pathname}?${e.toString()}`:window.location.pathname;window.history.pushState({},``,t)}}},children:e})},N=[{code:`general`,icon:`/icons/categories/icon-search-web.svg`,name:`Web`},{code:`news`,icon:`/icons/categories/icon-search-news.svg`,name:`News`},{code:`videos`,icon:`/icons/categories/icon-search-videos.svg`,name:`Videos`},{code:`images`,icon:`/icons/categories/icon-search-images.svg`,name:`Images`},{code:`science`,icon:`/icons/categories/icon-search-academic.svg`,name:`Academic`},{code:`files`,icon:`/icons/categories/icon-search-files.svg`,name:`Files`}],P=({sources:e,query:t})=>{let[r,i]=(0,n.useState)(`general`),[a,o]=(0,n.useState)(e),[d,p]=(0,n.useState)(!1),[m,h]=(0,n.useState)(!1),[g,_]=(0,n.useState)(1),[v,y]=(0,n.useState)(!0),[b,x]=(0,n.useState)(!1),S=(0,n.useRef)(null),C=(0,n.useRef)(!1),w=(0,n.useRef)(!1),{openPanel:T,isOpen:E}=j(),[O,A]=(0,n.useState)({});(0,n.useEffect)(()=>{let e=()=>{x(window.innerWidth>=1024)};return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]),(0,n.useEffect)(()=>{o(e),i(`general`),_(1),y(!0),A({}),M(e)},[e]);let M=(0,n.useCallback)(async e=>{let t=e.filter(e=>e.metadata.url&&e.metadata.url!==`File`&&!e.metadata.iframe_src);for(let e of t)try{let t=await(await fetch(`/api/doc/article?url=${encodeURIComponent(e.metadata.url)}`)).json();t.cached&&t.article?.html&&A(t=>({...t,[e.metadata.url]:`loaded`}))}catch{}},[]);(0,n.useEffect)(()=>{if(typeof window<`u`){let e=new URLSearchParams(window.location.search).get(`extract`);e&&(T(decodeURIComponent(e),``),w.current=!1)}},[T]),(0,n.useEffect)(()=>{w.current=!1},[e]),(0,n.useEffect)(()=>{C.current&&!E&&(w.current=!0),C.current=E},[E]),(0,n.useEffect)(()=>{if(b&&a&&a.length>0&&!E&&!w.current){let e=a[0];e?.metadata?.url&&T(e.metadata.url,``)}},[a,b]);let P=async(e,t)=>{e.preventDefault(),w.current=!1,A(e=>({...e,[t]:`loading`})),T(t,``);try{await(0,l.getArticle)({query:{url:t}}),A(e=>({...e,[t]:`loaded`}))}catch{A(e=>({...e,[t]:`loaded`}))}},F=(0,n.useCallback)(async()=>{if(!t||m||!v)return;h(!0);let e=g+1,{data:n}=await(0,l.agentSearch)({query:{q:t,cat:r,page:e}}),i=n?.results??[];if(i.length===0){y(!1),h(!1);return}let a=i.map(e=>{if(e.url)try{let t=new URL(e.url);(t.pathname===`/`||t.pathname===``)&&console.warn(`[MessageSources] Search result URL is domain-only:`,e.url,`Title:`,e.title)}catch{console.error(`[MessageSources] Invalid URL in search result:`,e.url)}return{pageContent:e.snippet||e.content||``,metadata:{title:e.title||``,source:e.source||``,thumbnail:e.thumbnail||``,url:e.url||``,...e.thumbnail&&{thumbnail:e.thumbnail}}}});o(e=>[...e,...a]),_(e),h(!1)},[t,r,g,m,v]),I=async e=>{if(!(e===r||!t)){i(e),p(!0),_(1),y(!0);try{let{data:n}=await(0,l.agentSearch)({query:{q:t,cat:e,page:1}}),r=(n?.results??[]).map(e=>{if(e.url)try{let t=new URL(e.url);(t.pathname===`/`||t.pathname===``)&&console.warn(`[MessageSources] Category search result URL is domain-only:`,e.url,`Title:`,e.title)}catch{console.error(`[MessageSources] Invalid URL in category search result:`,e.url)}return{pageContent:e.snippet||e.content||``,metadata:{title:e.title||``,source:e.source||``,thumbnail:e.thumbnail||``,url:e.url||``,...e.img_src&&{img_src:e.img_src},...e.thumbnail&&{thumbnail:e.thumbnail},...e.iframe_src&&{iframe_src:e.iframe_src}}}});o(r)}catch(e){console.error(`Error searching:`,e)}finally{p(!1)}}};(0,n.useEffect)(()=>{let e=S.current;if(!e)return;let t=()=>{let{scrollTop:t,scrollHeight:n,clientHeight:r}=e;n-t-r<100&&F()};return e.addEventListener(`scroll`,t),()=>e.removeEventListener(`scroll`,t)},[F]);let L=(e,t)=>{let n=r===`images`,i=r===`videos`,a=e.metadata.img_src||e.metadata.thumbnail;if(n&&a)return(0,f.jsx)(`div`,{className:`relative rounded-lg group`,children:(0,f.jsxs)(`a`,{className:`relative block overflow-hidden rounded-lg cursor-pointer`,href:e.metadata.url,onClick:t=>P(t,e.metadata.url),children:[(0,f.jsx)(`img`,{src:a,alt:e.metadata.title,className:`w-full h-auto object-cover rounded-lg hover:scale-105 transition-transform duration-200`,loading:`lazy`}),(0,f.jsxs)(`div`,{className:`absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/70 to-transparent p-2 opacity-0 group-hover:opacity-100 transition-opacity duration-200`,children:[(0,f.jsx)(`p`,{className:`text-xs text-white line-clamp-2`,children:(0,u.convertURLSafeHTMLToHTML)(e.metadata.title)}),(0,f.jsx)(`p`,{className:`text-[10px] text-white/70 truncate mt-0.5`,children:e.metadata.source})]})]})},t);if(i&&a)return(0,f.jsxs)(`div`,{className:`relative rounded-xl`,children:[(0,f.jsx)(k,{spread:40,glow:!0,disabled:!1,proximity:64,inactiveZone:.01,borderWidth:2}),(0,f.jsxs)(`a`,{className:`relative bg-card text-card-foreground border border-border rounded-xl overflow-hidden flex flex-col cursor-pointer shadow-sm hover:shadow-md transition-all duration-200`,href:e.metadata.url,target:`_blank`,rel:`noopener noreferrer`,children:[(0,f.jsxs)(`div`,{className:`relative`,children:[(0,f.jsx)(`img`,{src:a,alt:e.metadata.title,className:`w-full h-24 object-cover`}),(0,f.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,f.jsx)(`div`,{className:`w-10 h-10 bg-black/60 rounded-full flex items-center justify-center`,children:(0,f.jsx)(s.Video,{size:18,className:`text-white ml-0.5`})})})]}),(0,f.jsx)(`p`,{className:`text-xs line-clamp-2 p-2 text-muted-foreground`,children:(0,u.convertURLSafeHTMLToHTML)(e.metadata.title)})]})]},t);let o=O[e.metadata.url];return(0,f.jsxs)(`div`,{className:`relative rounded-xl group h-full`,children:[(0,f.jsx)(k,{spread:40,glow:!0,disabled:!1,proximity:64,inactiveZone:.01,borderWidth:2}),(0,f.jsxs)(`div`,{className:`relative bg-card text-card-foreground border border-border rounded-xl p-2.5 flex flex-col font-medium cursor-pointer shadow-sm hover:shadow-md transition-all duration-200 h-full`,onClick:t=>P(t,e.metadata.url),children:[o&&(0,f.jsx)(`div`,{className:`absolute top-1.5 left-1.5 p-1 rounded-md bg-background/80 backdrop-blur-sm z-[5]`,children:o===`loading`?(0,f.jsx)(s.Loader2,{size:14,className:`text-primary animate-spin`}):(0,f.jsx)(s.FileText,{size:14,className:`text-green-500`})}),(0,f.jsx)(`a`,{href:e.metadata.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`absolute top-1.5 right-1.5 p-1 rounded-md bg-secondary/50 opacity-0 group-hover:opacity-100 transition-opacity hover:bg-secondary z-10`,title:`Open in new tab`,children:(0,f.jsx)(s.ExternalLink,{size:12,className:`text-muted-foreground`})}),(0,f.jsxs)(`p`,{className:`text-xs line-clamp-4 text-muted-foreground`,children:[(0,f.jsxs)(`span`,{className:`inline-flex items-center gap-1 font-semibold text-foreground/70 align-middle`,children:[e.metadata.url===`File`?(0,f.jsx)(`span`,{className:`inline-flex items-center justify-center w-3.5 h-3.5 rounded-full bg-secondary flex-shrink-0`,children:(0,f.jsx)(s.File,{size:10,className:`text-muted-foreground`})}):(0,f.jsx)(`img`,{src:`https://s2.googleusercontent.com/s2/favicons?domain_url=${e.metadata.url}`,width:20,height:20,alt:`favicon`,className:`inline rounded h-5 w-5 flex-shrink-0`}),e.metadata.source]}),` `,(0,f.jsx)(`span`,{className:`align-middle`,children:(0,u.convertURLSafeHTMLToHTML)(e.metadata.title)})]})]})]},t)};return(0,f.jsxs)(f.Fragment,{children:[t&&(0,f.jsx)(`div`,{className:`flex items-center gap-1 mb-3 overflow-x-auto pb-1`,children:N.map(e=>(0,f.jsxs)(`button`,{onClick:()=>I(e.code),disabled:d,className:D(`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-sm font-medium transition-all duration-200 whitespace-nowrap`,r===e.code?`bg-primary text-primary-foreground`:`bg-secondary/50 text-muted-foreground hover:bg-secondary hover:text-foreground`),children:[(0,f.jsx)(c.default,{src:e.icon,alt:e.name,width:16,height:16,className:`w-4 h-4`}),(0,f.jsx)(`span`,{children:e.name})]},e.code))}),(0,f.jsx)(`div`,{ref:S,className:D(`overflow-y-auto pb-2 pr-1`,r===`images`?`max-h-[400px] lg:max-h-[500px]`:`max-h-[180px] lg:max-h-[280px]`),children:d?(0,f.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,f.jsx)(s.Loader2,{className:`w-6 h-6 animate-spin text-muted-foreground`})}):a.length>0?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`div`,{className:D(r===`images`?`columns-2 sm:columns-3 lg:columns-4 gap-2 [&>div]:mb-2 [&>div]:break-inside-avoid`:D(`grid gap-3 auto-rows-fr`,E&&b?`grid-cols-2`:`grid-cols-3`)),children:a.map((e,t)=>L(e,t))}),m&&(0,f.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,f.jsx)(s.Loader2,{className:`w-5 h-5 animate-spin text-muted-foreground`})}),!v&&a.length>0&&(0,f.jsx)(`div`,{className:`flex items-center justify-center py-4 text-muted-foreground text-xs`,children:`No more results`})]}):(0,f.jsx)(`div`,{className:`flex items-center justify-center py-8 text-muted-foreground text-sm`,children:`No results found`})})]})},F={extract:`Extract`,arxiv:`ArXiv`,"google scholar":`Scholar`,pubmed:`PubMed`,wolframalpha:`Wolfram`,youtube:`YouTube`,Web:`Web`};function I(e){return e?F[e]??e:`Web`}function L({queries:e,loading:t}){let n=e.filter(e=>e.status===`done`).length,r=e.length,i=t&&e.some(e=>e.status===`running`);return(0,f.jsxs)(`div`,{className:`rounded-xl border border-border bg-secondary/20 overflow-hidden text-sm`,children:[(0,f.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border/50`,children:[(0,f.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,children:[i?(0,f.jsx)(s.Loader2,{className:`w-3.5 h-3.5 animate-spin`}):(0,f.jsx)(s.Search,{className:`w-3.5 h-3.5`}),(0,f.jsx)(`span`,{className:`font-medium text-foreground`,children:i?`Running analysis…`:`Analysis complete`})]}),r>0&&(0,f.jsxs)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:[n,`/`,r,` searches`]})]}),e.length>0&&(0,f.jsx)(`div`,{className:`divide-y divide-border/40`,children:e.map((e,t)=>(0,f.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3 py-2`,children:[e.status===`running`?(0,f.jsx)(s.Loader2,{className:`w-3.5 h-3.5 text-muted-foreground animate-spin flex-shrink-0`}):(0,f.jsx)(s.Search,{className:D(`w-3.5 h-3.5 flex-shrink-0`,e.status===`done`?`text-muted-foreground`:`text-muted-foreground/40`)}),(0,f.jsxs)(`div`,{className:`flex items-baseline gap-1.5 min-w-0 flex-1`,children:[(0,f.jsxs)(`span`,{className:`text-xs text-muted-foreground whitespace-nowrap flex-shrink-0`,children:[I(e.category),` ·`]}),(0,f.jsx)(`span`,{className:`text-foreground/80 truncate`,children:e.query})]})]},t))})]})}function R(e,t){let[r,i]=(0,n.useState)(`stopped`),a=(0,n.useRef)(null),o=(0,n.useRef)(null),s=(0,n.useRef)(null),c=(0,n.useRef)(t);c.current=t;let l=(0,n.useCallback)(()=>{a.current&&=(a.current.pause(),a.current.src.startsWith(`blob:`)&&URL.revokeObjectURL(a.current.src),null),s.current?.abort(),s.current=null},[]),u=(0,n.useCallback)(()=>{if(!(`speechSynthesis`in window))return!1;try{window.speechSynthesis.cancel();let t=new SpeechSynthesisUtterance(e);return o.current=t,t.onend=()=>{o.current=null,i(`stopped`)},t.onerror=()=>{o.current=null,i(`stopped`)},window.speechSynthesis.speak(t),i(`started`),!0}catch{return!1}},[e]);return{speechStatus:r,start:(0,n.useCallback)(async()=>{if(!e?.trim())return;l(),window.speechSynthesis?.cancel(),o.current=null,i(`started`);let t=new AbortController;s.current=t;try{let n=await(0,p.default)(`/api/agent/tts`,{method:`POST`,body:{text:e.slice(0,5e3),speaker:localStorage.getItem(`ttsSpeaker`)||`angus`},signal:t.signal}),r=typeof n.blob==`function`?await n.blob():n;if(!r||r.size===0){u()||i(`stopped`);return}let o=URL.createObjectURL(r),s=new Audio(o);a.current=s,s.onended=()=>{i(`stopped`),URL.revokeObjectURL(o),a.current=null},s.onerror=()=>{URL.revokeObjectURL(o),a.current=null,u()||i(`stopped`)},await s.play()}catch{u()||i(`stopped`)}},[e,l,u]),stop:(0,n.useCallback)(()=>{l(),o.current=null,window.speechSynthesis?.cancel(),i(`stopped`)},[l])}}var ee=async(e,t,n)=>{let r=localStorage.getItem(`chatModelKey`),i=localStorage.getItem(`chatModelProviderId`),a=(await(0,p.default)(`/api/agent/providers`))?.providers||[];if(!a||a.length===0){t(!0);return}let o=a.find(e=>e.id===i&&(e.chatModels?.length??0)>0);if(o||=a.find(e=>e.name.toLowerCase().includes(`openrouter`)&&(e.chatModels?.length??0)>0)||a.find(e=>e.name.toLowerCase().includes(`nvidia`)&&(e.chatModels?.length??0)>0)||a.find(e=>(e.chatModels?.length??0)>0),!o){t(!0);return}i=o.id;let s=o.chatModels.find(e=>e.key===r);if(s||(o.name.toLowerCase().includes(`openrouter`)&&(s=o.chatModels.find(e=>e.key===`openrouter/free`)),!s&&o.name.toLowerCase().includes(`openrouter`)&&(s=o.chatModels.find(e=>e.key===`nvidia/nemotron-3-super-120b-a12b:free`)),s||=o.chatModels.find(e=>(e.key.toLowerCase().includes(`nemotron-3-super`)||e.name.toLowerCase().includes(`nemotron 3 super`))&&e.key.toLowerCase().includes(`120b`)),s||=o.chatModels.find(e=>e.key.toLowerCase().includes(`nemotron`)||e.name.toLowerCase().includes(`nemotron`)),s||=o.chatModels[0]),!s){t(!0);return}r=s.key,localStorage.setItem(`chatModelKey`,r),localStorage.setItem(`chatModelProviderId`,i),e({key:r,providerId:i}),t(!0)},z=`qwksearch_guest_chats`,B=typeof window<`u`;function V(){if(!B)return[];try{let e=localStorage.getItem(z);return e?JSON.parse(e).sort((e,t)=>new Date(t.createdAt).getTime()-new Date(e.createdAt).getTime()):[]}catch(e){return console.error(`Failed to get guest chats:`,e),[]}}function H(e){return B&&V().find(t=>t.id===e)||null}function U(e){if(B)try{let t=V(),n=t.findIndex(t=>t.id===e.id);n>=0?t[n]=e:t.push(e),localStorage.setItem(z,JSON.stringify(t))}catch(e){console.error(`Failed to save guest chat:`,e)}}function te(e){if(B)try{let t=V().filter(t=>t.id!==e);localStorage.setItem(z,JSON.stringify(t))}catch(e){console.error(`Failed to delete guest chat:`,e)}}function W(){if(B)try{localStorage.removeItem(z)}catch(e){console.error(`Failed to clear guest chats:`,e)}}var ne=async(e,t,n,r,i,a,o,s,c)=>{if(!t){let t=H(e);if(t){n(t.messages);let e=t.messages.filter(e=>e.role===`user`||e.role===`assistant`),o=e.map(e=>[e.role,e.content]);e.length>0&&(document.title=e[0].content),s(t.files||[]),c((t.files||[]).map(e=>e.fileId)),i(o),a(t.focusMode),r(!0);return}try{let t=await fetch(`/api/agent/chats/${e}`,{headers:{"Content-Type":`application/json`}});if(!t.ok){if(t.status===404||t.status===403){o(!0),r(!0);return}throw Error(`HTTP ${t.status}: ${t.statusText}`)}let{messages:l,chat:u}=await t.json();if(!l||!u){o(!0),r(!0);return}n(l);let d=l.filter(e=>e.role===`user`||e.role===`assistant`),f=d.map(e=>[e.role,e.content]);d.length>0&&(document.title=d[0].content);let p=u.files.map(e=>({fileName:e.name,fileExtension:e.name.split(`.`).pop(),fileId:e.fileId}));s(p),c(p.map(e=>e.fileId)),i(f),a(u.focusMode),r(!0);return}catch(e){console.error(`[chatMessages] Failed to load public chat:`,e),o(!0),r(!0);return}}try{let t=await fetch(`/api/agent/chats/${e}`,{credentials:`include`,headers:{"Content-Type":`application/json`}});if(!t.ok){if(t.status===404||t.status===401||t.status===403){o(!0),r(!0);return}throw Error(`HTTP ${t.status}: ${t.statusText}`)}let{messages:l,chat:u}=await t.json();if(!l||!u){o(!0),r(!0);return}n(l);let d=l.filter(e=>e.role===`user`||e.role===`assistant`),f=d.map(e=>[e.role,e.content]);console.debug(new Date,`app:messages_loaded`),d.length>0&&(document.title=d[0].content);let p=u.files.map(e=>({fileName:e.name,fileExtension:e.name.split(`.`).pop(),fileId:e.fileId}));s(p),c(p.map(e=>e.fileId)),i(f),a(u.focusMode),r(!0)}catch(e){console.error(`[chatMessages] Failed to load chat:`,e),o(!0),r(!0)}},re=e=>{let t=[];return e.forEach((n,r)=>{if(n.role===`user`){let i=e.findIndex((e,t)=>t>r&&e.role===`user`),a=e.find((e,t)=>t>r&&e.role===`assistant`&&(i===-1||t<i)),o=e.find((e,t)=>t>r&&e.role===`source`&&e.sources&&(i===-1||t<i)),s=e.find((e,t)=>t>r&&e.role===`searching`&&(i===-1||t<i)),c=!1,l=a?.content??``,u=a?.content??``,d=[];if(a){let t=/\[([^\]]+)\]/g,n=/\[(\d+)\]/g;if(l.includes(`<think>`)){let e=l.match(/<think>/g)?.length||0,t=l.match(/<\/think>/g)?.length||0;e&&!t&&(l+=`</think> <a> </a>`)}a.content.includes(`</think>`)&&(c=!0),o&&o.sources&&o.sources.length>0?(l=l.replace(t,(e,t)=>t.split(`,`).map(e=>e.trim()).map(e=>{let t=parseInt(e);if(isNaN(t)||t<=0)return`[${e}]`;let n=(o.sources?.[t-1])?.metadata?.url;return n?`<citation href="${n}">${e}</citation>`:``}).join(``)),u=a.content.replace(n,``)):(l=l.replace(n,``),u=a.content.replace(n,``));let s=e.find((e,t)=>t>r&&e.role===`suggestion`&&(i===-1||t<i));s&&s.suggestions.length>0&&(d=s.suggestions)}t.push({userMessage:n,assistantMessage:a,sourceMessage:o,searchingMessage:s,parsedAssistantMessage:l,speechMessage:u,thinkingEnded:c,suggestions:d})}}),t},ie=async e=>{let t=localStorage.getItem(`chatModelKey`),n=localStorage.getItem(`chatModelProviderId`),r=parseInt(localStorage.getItem(`maxFollowupQuestions`)||`4`),i=e.filter(e=>e.role===`user`||e.role===`assistant`);try{let e=await(0,p.default)(`agent/suggestions`,{method:`POST`,body:JSON.stringify({chatHistory:i,chatModel:{providerId:n,key:t},maxQuestions:r})});return Array.isArray(e.suggestions)?e.suggestions:[]}catch{return[]}},ae=3,oe=()=>Array.from(crypto.getRandomValues(new Uint8Array(7)),e=>e.toString(16).padStart(2,`0`)).join(``),se=`sourceExtractionEnabled`,G=`thinkingTimeLimit`;async function K(e,n){let{message:r,messageId:i,rewrite:a=!1}=e,{chatId:o,loading:s,messages:c,fileIds:l,focusMode:u,category:d,optimizationMode:f,chatHistory:h,chatModelProvider:g,isAuthenticated:_,messagesRef:v,abortControllerRef:y,setLoading:b,setMessageAppeared:x,setMessages:S,setChatHistory:C,setChatModelProvider:w}=n,T=typeof window<`u`&&localStorage.getItem(se)===`true`,E=typeof window<`u`&&Number(localStorage.getItem(G)??`0`)||0;if(s||!r)return;let D=new AbortController;y.current=D,b(!0),x(!1),c.length<=1&&window.history.replaceState(null,``,`/c/${o}`);let O=``,k=!1,A=!1,j=[],M=Date.now(),N=E>0,P=``,F=``,I=i??oe();S(e=>[...e,{content:r,messageId:I,chatId:o,role:`user`,createdAt:new Date}]);let L=async e=>{if(e.type===`error`){let t=e.data;typeof t==`string`&&(t.includes(`no longer available`)||t.includes(`deprecated`)||t.includes(`410`))&&(localStorage.removeItem(`chatModelKey`),localStorage.removeItem(`chatModelProviderId`),w?.({key:``,providerId:``})),m.toast.error(t),b(!1);return}if(e.type===`searching`){let t=e.data;S(n=>{let r=n.findIndex(t=>t.messageId===e.messageId&&t.role===`searching`);return r===-1?[...n,{role:`searching`,messageId:e.messageId,chatId:o,createdAt:new Date,queries:[{query:t.query,category:t.category,status:t.status}]}]:n.map((e,n)=>{if(n!==r)return e;let i=e,a=i.queries.findIndex(e=>e.query===t.query);if(a===-1)return{...i,queries:[...i.queries,{query:t.query,category:t.category,status:t.status}]};let o=i.queries.map((e,n)=>n===a?{...e,status:t.status}:e);return{...i,queries:o}})})}if(e.type===`sources`&&(j=e.data||[],S(t=>[...t,{messageId:e.messageId,chatId:o,role:`source`,sources:j,createdAt:new Date}]),j.length>0&&(x(!0),j.slice(0,ae).forEach(e=>{let t=e?.metadata?.url;t&&t!==`File`&&(0,p.default)(`doc/article?url=${encodeURIComponent(t)}`).catch(()=>{})}))),e.type===`message`&&(O+=e.data,N?(P+=e.data,F||=e.messageId,k=!0):k?S(t=>t.map(t=>t.messageId===e.messageId&&t.role===`assistant`?{...t,content:t.content+e.data}:t)):(S(t=>[...t,{content:e.data,messageId:e.messageId,chatId:o,role:`assistant`,createdAt:new Date}]),k=!0,x(!0))),e.type===`messageEnd`){let e=async()=>{N&&P&&(S(e=>[...e,{content:P,messageId:F,chatId:o,role:`assistant`,createdAt:new Date}]),x(!0)),C(e=>[...e,[`human`,r],[`assistant`,O]]),b(!1);let e=v.current[v.current.length-1];if(t.researchAgentUIConfig.getAutoMediaSearch()&&(document.getElementById(`search-images-${e.messageId}`)?.click(),document.getElementById(`search-videos-${e.messageId}`)?.click()),!A){A=!0;let e=await ie(v.current),t=oe();if(S(n=>[...n,{role:`suggestion`,suggestions:e,chatId:o,createdAt:new Date,messageId:t}]),_&&e.length>0)try{await fetch(`/api/agent/messages`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({chatId:o,messageId:t,role:`suggestion`,suggestions:e})})}catch(e){console.error(`Failed to save suggestions:`,e)}}};if(N){let e=Date.now()-M,t=E*1e3-e;t>0&&await new Promise(e=>setTimeout(e,t))}await e()}},R=c.findIndex(e=>e.messageId===I);try{let e=await fetch(`/api/agent/chat`,{method:`POST`,signal:D.signal,headers:{"Content-Type":`application/json`},body:JSON.stringify({content:r,message:{messageId:I,chatId:o,content:r},chatId:o,files:l,focusMode:u,category:d,optimizationMode:f,history:a?h.slice(0,R===-1?void 0:R):h,chatModel:{key:g.key,providerId:g.providerId},sourceExtractionEnabled:T,thinkingTimeLimit:E,systemInstructions:localStorage.getItem(`systemInstructions`)})});if(!e.ok){let t=`Failed to send message. Please try again.`;try{let n=await e.clone().json();n?.message&&(t=n.message)}catch{}if(e.status===401&&_){m.toast.error(`Your session has expired. Please sign in again.`),b(!1),window.location.href=`/`;return}m.toast.error(t),b(!1);return}if(!e.body)throw Error(`No response body`);let t=e.body.getReader(),n=new TextDecoder(`utf-8`),i=``;for(;;){let{value:e,done:r}=await t.read();if(r)break;i+=n.decode(e,{stream:!0});try{let e=i.split(`
16
+ )`},className:D(`pointer-events-none absolute inset-0 rounded-[inherit] opacity-100 transition-opacity`,o&&`opacity-100`,e>0&&`blur-[var(--blur)] `,s,u&&`!hidden`),children:(0,f.jsx)(`div`,{className:D(`glow`,`rounded-[inherit]`,`after:content-[""] after:rounded-[inherit] after:absolute after:inset-[calc(-1*var(--glowingeffect-border-width))]`,`after:[border:var(--glowingeffect-border-width)_solid_transparent]`,`after:[background:var(--gradient)] after:[background-attachment:fixed]`,`after:opacity-[var(--active)] after:transition-opacity after:duration-300`,`after:[mask-clip:padding-box,border-box]`,`after:[mask-composite:intersect]`,`after:[mask-image:linear-gradient(#0000,#0000),conic-gradient(from_calc((var(--start)-var(--spread))*1deg),#00000000_0deg,#fff,#00000000_calc(var(--spread)*2deg))]`)})})]})});k.displayName=`GlowingEffect`;var A=(0,n.createContext)(void 0),j=()=>{let e=(0,n.useContext)(A);if(!e)throw Error(`useExtractPanel must be used within an ExtractPanelProvider`);return e},M=({children:e})=>{let[t,r]=(0,n.useState)(!1),[i,a]=(0,n.useState)(``),[o,s]=(0,n.useState)(``),[c,l]=(0,n.useState)(600);return(0,f.jsx)(A.Provider,{value:{isOpen:t,url:i,searchText:o,panelWidth:c,setIsOpen:r,setUrl:a,setSearchText:s,setPanelWidth:l,openPanel:(e,t=``)=>{console.log(`[ExtractPanelContext] openPanel called with URL:`,e);try{let t=new URL(e);(t.pathname===`/`||t.pathname===``)&&console.error(`[ExtractPanelContext] URL is domain-only, missing article path:`,e)}catch(t){console.error(`[ExtractPanelContext] Invalid URL format:`,e,t)}if(a(e),s(t),r(!0),typeof window<`u`){let t=new URLSearchParams(window.location.search);t.set(`extract`,encodeURIComponent(e));let n=`${window.location.pathname}?${t.toString()}`;window.history.pushState({},``,n)}},closePanel:()=>{if(r(!1),typeof window<`u`){let e=new URLSearchParams(window.location.search);e.delete(`extract`);let t=e.toString()?`${window.location.pathname}?${e.toString()}`:window.location.pathname;window.history.pushState({},``,t)}}},children:e})},N=[{code:`general`,icon:`/icons/categories/icon-search-web.svg`,name:`Web`},{code:`news`,icon:`/icons/categories/icon-search-news.svg`,name:`News`},{code:`videos`,icon:`/icons/categories/icon-search-videos.svg`,name:`Videos`},{code:`images`,icon:`/icons/categories/icon-search-images.svg`,name:`Images`},{code:`science`,icon:`/icons/categories/icon-search-academic.svg`,name:`Academic`},{code:`files`,icon:`/icons/categories/icon-search-files.svg`,name:`Files`}],P=({sources:e,query:t})=>{let[r,i]=(0,n.useState)(`general`),[a,o]=(0,n.useState)(e),[d,p]=(0,n.useState)(!1),[m,h]=(0,n.useState)(!1),[g,_]=(0,n.useState)(1),[v,y]=(0,n.useState)(!0),[b,x]=(0,n.useState)(!1),S=(0,n.useRef)(null),C=(0,n.useRef)(!1),w=(0,n.useRef)(!1),{openPanel:T,isOpen:E}=j(),[O,A]=(0,n.useState)({});(0,n.useEffect)(()=>{let e=()=>{x(window.innerWidth>=1024)};return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]),(0,n.useEffect)(()=>{o(e),i(`general`),_(1),y(!0),A({}),M(e)},[e]);let M=(0,n.useCallback)(async e=>{let t=e.filter(e=>e.metadata.url&&e.metadata.url!==`File`&&!e.metadata.iframe_src);for(let e of t)try{let t=await(await fetch(`/api/doc/article?url=${encodeURIComponent(e.metadata.url)}`)).json();t.cached&&t.article?.html&&A(t=>({...t,[e.metadata.url]:`loaded`}))}catch{}},[]);(0,n.useEffect)(()=>{if(typeof window<`u`){let e=new URLSearchParams(window.location.search).get(`extract`);e&&(T(decodeURIComponent(e),``),w.current=!1)}},[T]),(0,n.useEffect)(()=>{w.current=!1},[e]),(0,n.useEffect)(()=>{C.current&&!E&&(w.current=!0),C.current=E},[E]),(0,n.useEffect)(()=>{if(b&&a&&a.length>0&&!E&&!w.current){let e=a[0];e?.metadata?.url&&T(e.metadata.url,``)}},[a,b]);let P=async(e,t)=>{e.preventDefault(),w.current=!1,A(e=>({...e,[t]:`loading`})),T(t,``);try{await(0,l.getArticle)({query:{url:t}}),A(e=>({...e,[t]:`loaded`}))}catch{A(e=>({...e,[t]:`loaded`}))}},F=(0,n.useCallback)(async()=>{if(!t||m||!v)return;h(!0);let e=g+1,{data:n}=await(0,l.agentSearch)({query:{q:t,cat:r,page:e}}),i=n?.results??[];if(i.length===0){y(!1),h(!1);return}let a=i.map(e=>{if(e.url)try{let t=new URL(e.url);(t.pathname===`/`||t.pathname===``)&&console.warn(`[MessageSources] Search result URL is domain-only:`,e.url,`Title:`,e.title)}catch{console.error(`[MessageSources] Invalid URL in search result:`,e.url)}return{pageContent:e.snippet||e.content||``,metadata:{title:e.title||``,source:e.source||``,thumbnail:e.thumbnail||``,url:e.url||``,...e.thumbnail&&{thumbnail:e.thumbnail}}}});o(e=>[...e,...a]),_(e),h(!1)},[t,r,g,m,v]),I=async e=>{if(!(e===r||!t)){i(e),p(!0),_(1),y(!0);try{let{data:n}=await(0,l.agentSearch)({query:{q:t,cat:e,page:1}}),r=(n?.results??[]).map(e=>{if(e.url)try{let t=new URL(e.url);(t.pathname===`/`||t.pathname===``)&&console.warn(`[MessageSources] Category search result URL is domain-only:`,e.url,`Title:`,e.title)}catch{console.error(`[MessageSources] Invalid URL in category search result:`,e.url)}return{pageContent:e.snippet||e.content||``,metadata:{title:e.title||``,source:e.source||``,thumbnail:e.thumbnail||``,url:e.url||``,...e.img_src&&{img_src:e.img_src},...e.thumbnail&&{thumbnail:e.thumbnail},...e.iframe_src&&{iframe_src:e.iframe_src}}}});o(r)}catch(e){console.error(`Error searching:`,e)}finally{p(!1)}}};(0,n.useEffect)(()=>{let e=S.current;if(!e)return;let t=()=>{let{scrollTop:t,scrollHeight:n,clientHeight:r}=e;n-t-r<100&&F()};return e.addEventListener(`scroll`,t),()=>e.removeEventListener(`scroll`,t)},[F]);let L=(e,t)=>{let n=r===`images`,i=r===`videos`,a=e.metadata.img_src||e.metadata.thumbnail;if(n&&a)return(0,f.jsx)(`div`,{className:`relative rounded-lg group`,children:(0,f.jsxs)(`a`,{className:`relative block overflow-hidden rounded-lg cursor-pointer`,href:e.metadata.url,onClick:t=>P(t,e.metadata.url),children:[(0,f.jsx)(`img`,{src:a,alt:e.metadata.title,className:`w-full h-auto object-cover rounded-lg hover:scale-105 transition-transform duration-200`,loading:`lazy`}),(0,f.jsxs)(`div`,{className:`absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/70 to-transparent p-2 opacity-0 group-hover:opacity-100 transition-opacity duration-200`,children:[(0,f.jsx)(`p`,{className:`text-xs text-white line-clamp-2`,children:(0,u.convertURLSafeHTMLToHTML)(e.metadata.title)}),(0,f.jsx)(`p`,{className:`text-[10px] text-white/70 truncate mt-0.5`,children:e.metadata.source})]})]})},t);if(i&&a)return(0,f.jsxs)(`div`,{className:`relative rounded-xl`,children:[(0,f.jsx)(k,{spread:40,glow:!0,disabled:!1,proximity:64,inactiveZone:.01,borderWidth:2}),(0,f.jsxs)(`a`,{className:`relative bg-card text-card-foreground border border-border rounded-xl overflow-hidden flex flex-col cursor-pointer shadow-sm hover:shadow-md transition-all duration-200`,href:e.metadata.url,target:`_blank`,rel:`noopener noreferrer`,children:[(0,f.jsxs)(`div`,{className:`relative`,children:[(0,f.jsx)(`img`,{src:a,alt:e.metadata.title,className:`w-full h-24 object-cover`}),(0,f.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:(0,f.jsx)(`div`,{className:`w-10 h-10 bg-black/60 rounded-full flex items-center justify-center`,children:(0,f.jsx)(s.Video,{size:18,className:`text-white ml-0.5`})})})]}),(0,f.jsx)(`p`,{className:`text-xs line-clamp-2 p-2 text-muted-foreground`,children:(0,u.convertURLSafeHTMLToHTML)(e.metadata.title)})]})]},t);let o=O[e.metadata.url];return(0,f.jsxs)(`div`,{className:`relative rounded-xl group h-full`,children:[(0,f.jsx)(k,{spread:40,glow:!0,disabled:!1,proximity:64,inactiveZone:.01,borderWidth:2}),(0,f.jsxs)(`div`,{className:`relative bg-card text-card-foreground border border-border rounded-xl p-2.5 flex flex-col font-medium cursor-pointer shadow-sm hover:shadow-md transition-all duration-200 h-full`,onClick:t=>P(t,e.metadata.url),children:[o&&(0,f.jsx)(`div`,{className:`absolute top-1.5 left-1.5 p-1 rounded-md bg-background/80 backdrop-blur-sm z-[5]`,children:o===`loading`?(0,f.jsx)(s.Loader2,{size:14,className:`text-primary animate-spin`}):(0,f.jsx)(s.FileText,{size:14,className:`text-green-500`})}),(0,f.jsx)(`a`,{href:e.metadata.url,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`absolute top-1.5 right-1.5 p-1 rounded-md bg-secondary/50 opacity-0 group-hover:opacity-100 transition-opacity hover:bg-secondary z-10`,title:`Open in new tab`,children:(0,f.jsx)(s.ExternalLink,{size:12,className:`text-muted-foreground`})}),(0,f.jsxs)(`p`,{className:`text-xs line-clamp-4 text-muted-foreground`,children:[(0,f.jsxs)(`span`,{className:`inline-flex items-center gap-1 font-semibold text-foreground/70 align-middle`,children:[e.metadata.url===`File`?(0,f.jsx)(`span`,{className:`inline-flex items-center justify-center w-3.5 h-3.5 rounded-full bg-secondary flex-shrink-0`,children:(0,f.jsx)(s.File,{size:10,className:`text-muted-foreground`})}):(0,f.jsx)(`img`,{src:`https://s2.googleusercontent.com/s2/favicons?domain_url=${e.metadata.url}`,width:20,height:20,alt:`favicon`,className:`inline rounded h-5 w-5 flex-shrink-0`}),e.metadata.source]}),` `,(0,f.jsx)(`span`,{className:`align-middle`,children:(0,u.convertURLSafeHTMLToHTML)(e.metadata.title)})]})]})]},t)};return(0,f.jsxs)(f.Fragment,{children:[t&&(0,f.jsx)(`div`,{className:`flex items-center gap-1 mb-3 overflow-x-auto pb-1`,children:N.map(e=>(0,f.jsxs)(`button`,{onClick:()=>I(e.code),disabled:d,className:D(`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-sm font-medium transition-all duration-200 whitespace-nowrap`,r===e.code?`bg-primary text-primary-foreground`:`bg-secondary/50 text-muted-foreground hover:bg-secondary hover:text-foreground`),children:[(0,f.jsx)(c.default,{src:e.icon,alt:e.name,width:16,height:16,className:`w-4 h-4`}),(0,f.jsx)(`span`,{children:e.name})]},e.code))}),(0,f.jsx)(`div`,{ref:S,className:D(`overflow-y-auto pb-2 pr-1`,r===`images`?`max-h-[400px] lg:max-h-[500px]`:`max-h-[180px] lg:max-h-[280px]`),children:d?(0,f.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,f.jsx)(s.Loader2,{className:`w-6 h-6 animate-spin text-muted-foreground`})}):a.length>0?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`div`,{className:D(r===`images`?`columns-2 sm:columns-3 lg:columns-4 gap-2 [&>div]:mb-2 [&>div]:break-inside-avoid`:D(`grid gap-3 auto-rows-fr`,E&&b?`grid-cols-2`:`grid-cols-3`)),children:a.map((e,t)=>L(e,t))}),m&&(0,f.jsx)(`div`,{className:`flex items-center justify-center py-4`,children:(0,f.jsx)(s.Loader2,{className:`w-5 h-5 animate-spin text-muted-foreground`})}),!v&&a.length>0&&(0,f.jsx)(`div`,{className:`flex items-center justify-center py-4 text-muted-foreground text-xs`,children:`No more results`})]}):(0,f.jsx)(`div`,{className:`flex items-center justify-center py-8 text-muted-foreground text-sm`,children:`No results found`})})]})},F={extract:`Extract`,arxiv:`ArXiv`,"google scholar":`Scholar`,pubmed:`PubMed`,wolframalpha:`Wolfram`,youtube:`YouTube`,Web:`Web`};function I(e){return e?F[e]??e:`Web`}function L({queries:e,loading:t}){let n=e.filter(e=>e.status===`done`).length,r=e.length,i=t&&e.some(e=>e.status===`running`);return t?(0,f.jsxs)(`div`,{className:`rounded-xl border border-border bg-secondary/20 overflow-hidden text-sm`,children:[(0,f.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border/50`,children:[(0,f.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,children:[i?(0,f.jsx)(s.Loader2,{className:`w-3.5 h-3.5 animate-spin`}):(0,f.jsx)(s.Search,{className:`w-3.5 h-3.5`}),(0,f.jsx)(`span`,{className:`font-medium text-foreground`,children:i?`Running analysis…`:`Analysis complete`})]}),r>0&&(0,f.jsxs)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:[n,`/`,r,` searches`]})]}),e.length>0&&(0,f.jsx)(`div`,{className:`divide-y divide-border/40`,children:e.map((e,t)=>(0,f.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3 py-2`,children:[e.status===`running`?(0,f.jsx)(s.Loader2,{className:`w-3.5 h-3.5 text-muted-foreground animate-spin flex-shrink-0`}):(0,f.jsx)(s.Search,{className:D(`w-3.5 h-3.5 flex-shrink-0`,e.status===`done`?`text-muted-foreground`:`text-muted-foreground/40`)}),(0,f.jsxs)(`div`,{className:`flex items-baseline gap-1.5 min-w-0 flex-1`,children:[(0,f.jsxs)(`span`,{className:`text-xs text-muted-foreground whitespace-nowrap flex-shrink-0`,children:[I(e.category),` ·`]}),(0,f.jsx)(`span`,{className:`text-foreground/80 truncate`,children:e.query})]})]},t))})]}):null}function R(e,t){let[r,i]=(0,n.useState)(`stopped`),a=(0,n.useRef)(null),o=(0,n.useRef)(null),s=(0,n.useRef)(null),c=(0,n.useRef)(t);c.current=t;let l=(0,n.useCallback)(()=>{a.current&&=(a.current.pause(),a.current.src.startsWith(`blob:`)&&URL.revokeObjectURL(a.current.src),null),s.current?.abort(),s.current=null},[]),u=(0,n.useCallback)(()=>{if(!(`speechSynthesis`in window))return!1;try{window.speechSynthesis.cancel();let t=new SpeechSynthesisUtterance(e);return o.current=t,t.onend=()=>{o.current=null,i(`stopped`)},t.onerror=()=>{o.current=null,i(`stopped`)},window.speechSynthesis.speak(t),i(`started`),!0}catch{return!1}},[e]);return{speechStatus:r,start:(0,n.useCallback)(async()=>{if(!e?.trim())return;l(),window.speechSynthesis?.cancel(),o.current=null,i(`started`);let t=new AbortController;s.current=t;try{let n=await(0,p.default)(`/api/agent/tts`,{method:`POST`,body:{text:e.slice(0,5e3),speaker:localStorage.getItem(`ttsSpeaker`)||`angus`},signal:t.signal}),r=typeof n.blob==`function`?await n.blob():n;if(!r||r.size===0){u()||i(`stopped`);return}let o=URL.createObjectURL(r),s=new Audio(o);a.current=s,s.onended=()=>{i(`stopped`),URL.revokeObjectURL(o),a.current=null},s.onerror=()=>{URL.revokeObjectURL(o),a.current=null,u()||i(`stopped`)},await s.play()}catch{u()||i(`stopped`)}},[e,l,u]),stop:(0,n.useCallback)(()=>{l(),o.current=null,window.speechSynthesis?.cancel(),i(`stopped`)},[l])}}var ee=async(e,t,n)=>{let r=localStorage.getItem(`chatModelKey`),i=localStorage.getItem(`chatModelProviderId`),a=(await(0,p.default)(`/api/agent/providers`))?.providers||[];if(!a||a.length===0){t(!0);return}let o=a.find(e=>e.id===i&&(e.chatModels?.length??0)>0);if(o||=a.find(e=>e.name.toLowerCase().includes(`openrouter`)&&(e.chatModels?.length??0)>0)||a.find(e=>e.name.toLowerCase().includes(`nvidia`)&&(e.chatModels?.length??0)>0)||a.find(e=>(e.chatModels?.length??0)>0),!o){t(!0);return}i=o.id;let s=o.chatModels.find(e=>e.key===r);if(s||(o.name.toLowerCase().includes(`openrouter`)&&(s=o.chatModels.find(e=>e.key===`openrouter/free`)),!s&&o.name.toLowerCase().includes(`openrouter`)&&(s=o.chatModels.find(e=>e.key===`nvidia/nemotron-3-super-120b-a12b:free`)),s||=o.chatModels.find(e=>(e.key.toLowerCase().includes(`nemotron-3-super`)||e.name.toLowerCase().includes(`nemotron 3 super`))&&e.key.toLowerCase().includes(`120b`)),s||=o.chatModels.find(e=>e.key.toLowerCase().includes(`nemotron`)||e.name.toLowerCase().includes(`nemotron`)),s||=o.chatModels[0]),!s){t(!0);return}r=s.key,localStorage.setItem(`chatModelKey`,r),localStorage.setItem(`chatModelProviderId`,i),e({key:r,providerId:i}),t(!0)},z=`qwksearch_guest_chats`,B=typeof window<`u`;function V(){if(!B)return[];try{let e=localStorage.getItem(z);return e?JSON.parse(e).sort((e,t)=>new Date(t.createdAt).getTime()-new Date(e.createdAt).getTime()):[]}catch(e){return console.error(`Failed to get guest chats:`,e),[]}}function H(e){return B&&V().find(t=>t.id===e)||null}function U(e){if(B)try{let t=V(),n=t.findIndex(t=>t.id===e.id);n>=0?t[n]=e:t.push(e),localStorage.setItem(z,JSON.stringify(t))}catch(e){console.error(`Failed to save guest chat:`,e)}}function te(e){if(B)try{let t=V().filter(t=>t.id!==e);localStorage.setItem(z,JSON.stringify(t))}catch(e){console.error(`Failed to delete guest chat:`,e)}}function W(){if(B)try{localStorage.removeItem(z)}catch(e){console.error(`Failed to clear guest chats:`,e)}}var ne=async(e,t,n,r,i,a,o,s,c)=>{if(!t){let t=H(e);if(t){n(t.messages);let e=t.messages.filter(e=>e.role===`user`||e.role===`assistant`),o=e.map(e=>[e.role,e.content]);e.length>0&&(document.title=e[0].content),s(t.files||[]),c((t.files||[]).map(e=>e.fileId)),i(o),a(t.focusMode),r(!0);return}try{let t=await fetch(`/api/agent/chats/${e}`,{headers:{"Content-Type":`application/json`}});if(!t.ok){if(t.status===404||t.status===403){o(!0),r(!0);return}throw Error(`HTTP ${t.status}: ${t.statusText}`)}let{messages:l,chat:u}=await t.json();if(!l||!u){o(!0),r(!0);return}n(l);let d=l.filter(e=>e.role===`user`||e.role===`assistant`),f=d.map(e=>[e.role,e.content]);d.length>0&&(document.title=d[0].content);let p=u.files.map(e=>({fileName:e.name,fileExtension:e.name.split(`.`).pop(),fileId:e.fileId}));s(p),c(p.map(e=>e.fileId)),i(f),a(u.focusMode),r(!0);return}catch(e){console.error(`[chatMessages] Failed to load public chat:`,e),o(!0),r(!0);return}}try{let t=await fetch(`/api/agent/chats/${e}`,{credentials:`include`,headers:{"Content-Type":`application/json`}});if(!t.ok){if(t.status===404||t.status===401||t.status===403){o(!0),r(!0);return}throw Error(`HTTP ${t.status}: ${t.statusText}`)}let{messages:l,chat:u}=await t.json();if(!l||!u){o(!0),r(!0);return}n(l);let d=l.filter(e=>e.role===`user`||e.role===`assistant`),f=d.map(e=>[e.role,e.content]);console.debug(new Date,`app:messages_loaded`),d.length>0&&(document.title=d[0].content);let p=u.files.map(e=>({fileName:e.name,fileExtension:e.name.split(`.`).pop(),fileId:e.fileId}));s(p),c(p.map(e=>e.fileId)),i(f),a(u.focusMode),r(!0)}catch(e){console.error(`[chatMessages] Failed to load chat:`,e),o(!0),r(!0)}},re=e=>{let t=[];return e.forEach((n,r)=>{if(n.role===`user`){let i=e.findIndex((e,t)=>t>r&&e.role===`user`),a=e.find((e,t)=>t>r&&e.role===`assistant`&&(i===-1||t<i)),o=e.find((e,t)=>t>r&&e.role===`source`&&e.sources&&(i===-1||t<i)),s=e.find((e,t)=>t>r&&e.role===`searching`&&(i===-1||t<i)),c=!1,l=a?.content??``,u=a?.content??``,d=[];if(a){let t=/\[([^\]]+)\]/g,n=/\[(\d+)\]/g;if(l.includes(`<think>`)){let e=l.match(/<think>/g)?.length||0,t=l.match(/<\/think>/g)?.length||0;e&&!t&&(l+=`</think> <a> </a>`)}a.content.includes(`</think>`)&&(c=!0),o&&o.sources&&o.sources.length>0?(l=l.replace(t,(e,t)=>t.split(`,`).map(e=>e.trim()).map(e=>{let t=parseInt(e);if(isNaN(t)||t<=0)return`[${e}]`;let n=(o.sources?.[t-1])?.metadata?.url;return n?`<citation href="${n}">${e}</citation>`:``}).join(``)),u=a.content.replace(n,``)):(l=l.replace(n,``),u=a.content.replace(n,``));let s=e.find((e,t)=>t>r&&e.role===`suggestion`&&(i===-1||t<i));s&&s.suggestions.length>0&&(d=s.suggestions)}t.push({userMessage:n,assistantMessage:a,sourceMessage:o,searchingMessage:s,parsedAssistantMessage:l,speechMessage:u,thinkingEnded:c,suggestions:d})}}),t},ie=async e=>{let t=localStorage.getItem(`chatModelKey`),n=localStorage.getItem(`chatModelProviderId`),r=parseInt(localStorage.getItem(`maxFollowupQuestions`)||`4`),i=e.filter(e=>e.role===`user`||e.role===`assistant`);try{let e=await(0,p.default)(`agent/suggestions`,{method:`POST`,body:JSON.stringify({chatHistory:i,chatModel:{providerId:n,key:t},maxQuestions:r})});return Array.isArray(e.suggestions)?e.suggestions:[]}catch{return[]}},ae=3,oe=()=>Array.from(crypto.getRandomValues(new Uint8Array(7)),e=>e.toString(16).padStart(2,`0`)).join(``),se=`sourceExtractionEnabled`,G=`thinkingTimeLimit`;async function K(e,n){let{message:r,messageId:i,rewrite:a=!1}=e,{chatId:o,loading:s,messages:c,fileIds:l,focusMode:u,category:d,optimizationMode:f,chatHistory:h,chatModelProvider:g,isAuthenticated:_,messagesRef:v,abortControllerRef:y,setLoading:b,setMessageAppeared:x,setMessages:S,setChatHistory:C,setChatModelProvider:w}=n,T=typeof window<`u`&&localStorage.getItem(se)===`true`,E=typeof window<`u`&&Number(localStorage.getItem(G)??`0`)||0;if(s||!r)return;let D=new AbortController;y.current=D,b(!0),x(!1),c.length<=1&&window.history.replaceState(null,``,`/c/${o}`);let O=``,k=!1,A=!1,j=[],M=Date.now(),N=E>0,P=``,F=``,I=i??oe();S(e=>[...e,{content:r,messageId:I,chatId:o,role:`user`,createdAt:new Date}]);let L=async e=>{if(e.type===`error`){let t=e.data;typeof t==`string`&&(t.includes(`no longer available`)||t.includes(`deprecated`)||t.includes(`410`))&&(localStorage.removeItem(`chatModelKey`),localStorage.removeItem(`chatModelProviderId`),w?.({key:``,providerId:``})),m.toast.error(t),b(!1);return}if(e.type===`searching`){let t=e.data;S(n=>{let r=n.findIndex(t=>t.messageId===e.messageId&&t.role===`searching`);return r===-1?[...n,{role:`searching`,messageId:e.messageId,chatId:o,createdAt:new Date,queries:[{query:t.query,category:t.category,status:t.status}]}]:n.map((e,n)=>{if(n!==r)return e;let i=e,a=i.queries.findIndex(e=>e.query===t.query);if(a===-1)return{...i,queries:[...i.queries,{query:t.query,category:t.category,status:t.status}]};let o=i.queries.map((e,n)=>n===a?{...e,status:t.status}:e);return{...i,queries:o}})})}if(e.type===`sources`&&(j=e.data||[],S(t=>[...t,{messageId:e.messageId,chatId:o,role:`source`,sources:j,createdAt:new Date}]),j.length>0&&(x(!0),j.slice(0,ae).forEach(e=>{let t=e?.metadata?.url;t&&t!==`File`&&(0,p.default)(`doc/article?url=${encodeURIComponent(t)}`).catch(()=>{})}))),e.type===`message`&&(O+=e.data,N?(P+=e.data,F||=e.messageId,k=!0):k?S(t=>t.map(t=>t.messageId===e.messageId&&t.role===`assistant`?{...t,content:t.content+e.data}:t)):(S(t=>[...t,{content:e.data,messageId:e.messageId,chatId:o,role:`assistant`,createdAt:new Date}]),k=!0,x(!0))),e.type===`messageEnd`){let e=async()=>{N&&P&&(S(e=>[...e,{content:P,messageId:F,chatId:o,role:`assistant`,createdAt:new Date}]),x(!0)),C(e=>[...e,[`human`,r],[`assistant`,O]]),b(!1);let e=v.current[v.current.length-1];if(t.researchAgentUIConfig.getAutoMediaSearch()&&(document.getElementById(`search-images-${e.messageId}`)?.click(),document.getElementById(`search-videos-${e.messageId}`)?.click()),!A){A=!0;let e=await ie(v.current),t=oe();if(S(n=>[...n,{role:`suggestion`,suggestions:e,chatId:o,createdAt:new Date,messageId:t}]),_&&e.length>0)try{await fetch(`/api/agent/messages`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({chatId:o,messageId:t,role:`suggestion`,suggestions:e})})}catch(e){console.error(`Failed to save suggestions:`,e)}}};if(N){let e=Date.now()-M,t=E*1e3-e;t>0&&await new Promise(e=>setTimeout(e,t))}await e()}},R=c.findIndex(e=>e.messageId===I);try{let e=await fetch(`/api/agent/chat`,{method:`POST`,signal:D.signal,headers:{"Content-Type":`application/json`},body:JSON.stringify({content:r,message:{messageId:I,chatId:o,content:r},chatId:o,files:l,focusMode:u,category:d,optimizationMode:f,history:a?h.slice(0,R===-1?void 0:R):h,chatModel:{key:g.key,providerId:g.providerId},sourceExtractionEnabled:T,thinkingTimeLimit:E,systemInstructions:localStorage.getItem(`systemInstructions`)})});if(!e.ok){let t=`Failed to send message. Please try again.`;try{let n=await e.clone().json();n?.message&&(t=n.message)}catch{}if(e.status===401&&_){m.toast.error(`Your session has expired. Please sign in again.`),b(!1),window.location.href=`/`;return}m.toast.error(t),b(!1);return}if(!e.body)throw Error(`No response body`);let t=e.body.getReader(),n=new TextDecoder(`utf-8`),i=``;for(;;){let{value:e,done:r}=await t.read();if(r)break;i+=n.decode(e,{stream:!0});try{let e=i.split(`
17
17
  `);i=e.pop()??``;for(let t of e)if(t.trim())try{L(JSON.parse(t))}catch{}}catch{}}}catch(e){if(e.name===`AbortError`){N&&P&&(S(e=>[...e,{content:P,messageId:F,chatId:o,role:`assistant`,createdAt:new Date}]),x(!0)),O&&C(e=>[...e,[`human`,r],[`assistant`,O]]),b(!1),y.current=null;return}throw e}y.current=null}function ce(e){let[t,r]=(0,n.useState)(e),[i,a]=(0,n.useState)(!1),[o,s]=(0,n.useState)(!1),[c,l]=(0,n.useState)(!1),[u,d]=(0,n.useState)(!1),[f,p]=(0,n.useState)(!1),[m,h]=(0,n.useState)(!1),[g,_]=(0,n.useState)(!1),[v,y]=(0,n.useState)(!1),[b,x]=(0,n.useState)([]),[S,C]=(0,n.useState)([]),[w,T]=(0,n.useState)([]),[E,D]=(0,n.useState)([]),[O,k]=(0,n.useState)(`webSearch`),[A,j]=(0,n.useState)(`general`),[M,N]=(0,n.useState)(`speed`),[P,F]=(0,n.useState)({key:``,providerId:``}),I=(0,n.useRef)([]),L=(0,n.useMemo)(()=>S.filter(e=>e.role===`user`||e.role===`assistant`),[S]),R=(0,n.useMemo)(()=>re(S),[S]);return{state:{chatId:t,newChatCreated:i,loading:o,messageAppeared:c,chatHistory:b,messages:S,files:w,fileIds:E,focusMode:O,category:A,optimizationMode:M,isMessagesLoaded:u,notFound:v,chatModelProvider:P,isConfigReady:f,hasError:m,isReady:g},setters:{setChatId:r,setNewChatCreated:a,setLoading:s,setMessageAppeared:l,setChatHistory:x,setMessages:C,setFiles:T,setFileIds:D,setFocusMode:k,setCategory:j,setOptimizationMode:N,setIsMessagesLoaded:d,setNotFound:y,setChatModelProvider:F,setIsConfigReady:p,setHasError:h,setIsReady:_},messagesRef:I,chatTurns:L,sections:R}}var le=(0,n.createContext)({chatHistory:[],chatId:``,fileIds:[],files:[],focusMode:``,category:``,hasError:!1,isMessagesLoaded:!1,isReady:!1,loading:!1,messageAppeared:!1,messages:[],chatTurns:[],sections:[],notFound:!1,optimizationMode:``,chatModelProvider:{key:``,providerId:``},rewrite:()=>{},sendMessage:async()=>{},setFileIds:()=>{},setFiles:()=>{},setFocusMode:()=>{},setCategory:()=>{},setOptimizationMode:()=>{},setChatModelProvider:()=>{},stopStreaming:()=>{},newChat:()=>{},incognito:!1,setIncognito:()=>{}});function q(){return(0,n.useContext)(le)}var ue=(0,n.createContext)({user:null,isLoading:!0,isAuthenticated:!1,signIn:()=>{},signOut:async()=>{}});function de({children:e,authClient:t}){let[r,i]=(0,n.useState)(null),[a,o]=(0,n.useState)(!0);return(0,n.useEffect)(()=>{(async()=>{try{let{data:e}=await t.getSession();i(e?.user??null)}catch(e){console.error(`Failed to fetch session:`,e),i(null)}finally{o(!1)}})()},[]),(0,n.useEffect)(()=>{a||r||t.oneTap({fetchOptions:{onSuccess:async()=>{let{data:e}=await t.getSession();i(e?.user??null)}}})},[a,r]),(0,f.jsx)(ue.Provider,{value:{user:r,isLoading:a,isAuthenticated:!!r,signIn:()=>{t.signIn.social({provider:`google`,callbackURL:`/`})},signOut:async()=>{try{await t.signOut({fetchOptions:{onSuccess:()=>{i(null),window.location.href=`/`}}})}catch(e){console.error(`Sign out failed:`,e)}}},children:e})}function fe(){let e=(0,n.useContext)(ue);if(!e)throw Error(`useSession must be used within SessionProvider`);return e}function pe({children:e}){let t=(0,r.useParams)(),i=(0,r.useSearchParams)(),a=(0,r.useRouter)(),o=i.get(`q`),{isAuthenticated:s,isLoading:c}=fe(),{state:l,setters:u,messagesRef:d,chatTurns:p,sections:m}=ce(t.chatId),h=(0,n.useRef)(null),[g,_]=(0,n.useState)(!1);(0,n.useEffect)(()=>{ee(u.setChatModelProvider,u.setIsConfigReady,u.setHasError)},[]),(0,n.useEffect)(()=>{t.chatId&&t.chatId!==l.chatId&&(u.setChatId(t.chatId),u.setMessages([]),u.setChatHistory([]),u.setFiles([]),u.setFileIds([]),u.setIsMessagesLoaded(!1),u.setNotFound(!1),u.setNewChatCreated(!1))},[t.chatId,l.chatId]),(0,n.useEffect)(()=>{if(l.chatId&&!l.newChatCreated&&!l.isMessagesLoaded&&l.messages.length===0){if(c)return;ne(l.chatId,s,u.setMessages,u.setIsMessagesLoaded,u.setChatHistory,u.setFocusMode,u.setNotFound,u.setFiles,u.setFileIds)}else l.chatId||(u.setNewChatCreated(!0),u.setIsMessagesLoaded(!0),u.setChatId(crypto.randomUUID()))},[l.chatId,l.isMessagesLoaded,l.newChatCreated,l.messages.length,s,c]),(0,n.useEffect)(()=>{if(!g&&!s&&l.chatId&&l.messages.length>0){let e=l.messages.filter(e=>e.role===`user`||e.role===`assistant`);if(e.length>0){let t=e[0].content.slice(0,50);U({id:l.chatId,title:t,createdAt:new Date().toISOString(),focusMode:l.focusMode,files:l.files,messages:l.messages})}}},[l.messages,l.chatId,s,l.focusMode,l.files]),(0,n.useEffect)(()=>{d.current=l.messages},[l.messages]),(0,n.useEffect)(()=>{l.isMessagesLoaded&&l.isConfigReady?(u.setIsReady(!0),console.debug(new Date,`app:ready`)):u.setIsReady(!1)},[l.isMessagesLoaded,l.isConfigReady]),(0,n.useEffect)(()=>{l.isReady&&o&&l.isConfigReady&&v(o)},[l.isConfigReady,l.isReady,o]);let v=(0,n.useCallback)(async(e,t,n=!1)=>{l.chatId&&await K({message:e,messageId:t,rewrite:n},{chatId:l.chatId,loading:l.loading,messages:l.messages,fileIds:l.fileIds,focusMode:l.focusMode,category:l.category,optimizationMode:l.optimizationMode,chatHistory:l.chatHistory,chatModelProvider:l.chatModelProvider,isAuthenticated:s,messagesRef:d,abortControllerRef:h,setLoading:u.setLoading,setMessageAppeared:u.setMessageAppeared,setMessages:u.setMessages,setChatHistory:u.setChatHistory,setChatModelProvider:u.setChatModelProvider})},[l.chatId,l.loading,l.messages,l.fileIds,l.focusMode,l.category,l.optimizationMode,l.chatHistory,l.chatModelProvider,s,d]),y=(0,n.useCallback)(e=>{let t=l.messages.findIndex(t=>t.messageId===e),n=p.findIndex(t=>t.messageId===e);if(t===-1)return;let r=p[n-1];u.setMessages(e=>[...e.slice(0,l.messages.length>2?l.messages.indexOf(r):0)]),u.setChatHistory(e=>[...e.slice(0,p.length>2?n-1:0)]),v(r.content,r.messageId,!0)},[l.messages,p,v]),b=(0,n.useCallback)(()=>{h.current&&=(h.current.abort(),null)},[]),x=(0,n.useCallback)(()=>{b(),u.setMessages([]),u.setChatHistory([]),u.setFiles([]),u.setFileIds([]),u.setChatId(void 0),u.setNewChatCreated(!1),u.setIsMessagesLoaded(!1),u.setNotFound(!1),a.push(`/`)},[b,a]),S={messages:l.messages,chatTurns:p,sections:m,chatHistory:l.chatHistory,files:l.files,fileIds:l.fileIds,focusMode:l.focusMode,category:l.category,chatId:l.chatId,hasError:l.hasError,isMessagesLoaded:l.isMessagesLoaded,isReady:l.isReady,loading:l.loading,messageAppeared:l.messageAppeared,notFound:l.notFound,optimizationMode:l.optimizationMode,chatModelProvider:l.chatModelProvider,incognito:g,setFileIds:u.setFileIds,setFiles:u.setFiles,setFocusMode:u.setFocusMode,setCategory:u.setCategory,setOptimizationMode:u.setOptimizationMode,rewrite:y,sendMessage:v,setChatModelProvider:u.setChatModelProvider,stopStreaming:b,newChat:x,setIncognito:_};return(0,f.jsx)(le.Provider,{value:S,children:e})}function me({delayDuration:e=0,...t}){return(0,f.jsx)(h.Provider,{"data-slot":`tooltip-provider`,delayDuration:e,...t})}function J({...e}){return(0,f.jsx)(me,{children:(0,f.jsx)(h.Root,{"data-slot":`tooltip`,...e})})}function Y({...e}){return(0,f.jsx)(h.Trigger,{"data-slot":`tooltip-trigger`,...e})}function X({className:e,sideOffset:t=0,children:n,...r}){return(0,f.jsx)(h.Portal,{children:(0,f.jsxs)(h.Content,{"data-slot":`tooltip-content`,sideOffset:t,className:D(`bg-primary text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-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-fit origin-(--radix-tooltip-content-transform-origin) rounded-2xl px-3 py-1.5 text-xs text-balance`,e),...r,children:[n,(0,f.jsx)(h.Arrow,{className:`bg-primary fill-primary z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]`})]})})}var he=({href:e,children:t,sources:r})=>{let{openPanel:i}=j(),a=(0,n.useMemo)(()=>!r||!e?null:r.find(t=>t.metadata?.url===e)??null,[r,e]),o=(0,n.useMemo)(()=>{try{return new URL(e).hostname.replace(`www.`,``)}catch{return a?.metadata?.source||``}},[e,a]),s=a?.metadata?.title||``,c=`https://s2.googleusercontent.com/s2/favicons?domain_url=${e}`;return(0,f.jsxs)(J,{children:[(0,f.jsx)(Y,{asChild:!0,children:(0,f.jsx)(`a`,{href:e,onClick:t=>{t.preventDefault(),i(e,``)},className:`bg-light-secondary dark:bg-dark-secondary px-1 rounded ml-1 no-underline text-xs text-black/70 dark:text-white/70 relative cursor-pointer hover:bg-black/10 dark:hover:bg-white/20 transition-colors`,children:t})}),(0,f.jsx)(X,{side:`top`,className:`max-w-72 p-2.5`,children:(0,f.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,f.jsx)(`img`,{src:c,alt:``,width:16,height:16,className:`rounded flex-shrink-0 mt-0.5`}),(0,f.jsxs)(`div`,{className:`min-w-0`,children:[(0,f.jsx)(`p`,{className:`text-xs font-medium leading-snug line-clamp-2`,children:s||o}),s&&(0,f.jsx)(`p`,{className:`text-[10px] opacity-70 truncate mt-0.5`,children:o})]})]})})]})},ge=({content:e,thinkingEnded:t})=>{let[r,i]=(0,n.useState)(!0);return(0,n.useEffect)(()=>{i(!t)},[t]),(0,f.jsxs)(`div`,{className:`my-4 bg-secondary/50 rounded-xl border border-border overflow-hidden`,children:[(0,f.jsxs)(`button`,{onClick:()=>i(!r),className:`w-full flex items-center justify-between px-4 py-1 text-foreground/90 hover:bg-secondary transition duration-200`,children:[(0,f.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,f.jsx)(s.BrainCircuit,{size:20,className:`text-accent-foreground`}),(0,f.jsx)(`p`,{className:`font-medium text-sm`,children:`Thinking Process`})]}),r?(0,f.jsx)(s.ChevronUp,{size:18,className:`text-muted-foreground`}):(0,f.jsx)(s.ChevronDown,{size:18,className:`text-muted-foreground`})]}),r&&(0,f.jsx)(`div`,{className:`px-4 py-3 text-foreground/80 text-sm border-t border-border bg-muted/50 whitespace-pre-wrap`,children:e})]})},_e=({children:e,thinkingEnded:t})=>(0,f.jsx)(ge,{content:e,thinkingEnded:t}),ve=({section:e,isExpanded:t,setIsExpanded:r,isEditing:i,setIsEditing:a,editText:o,setEditText:c,handleEditSubmit:l,copiedUserMsg:u,handleCopyUserMsg:d})=>{let p=(0,n.useRef)(null);return(0,f.jsxs)(`div`,{className:`w-full pt-8 break-words`,children:[(0,f.jsxs)(`button`,{onClick:()=>r(!t),className:`flex items-center gap-3 group text-left w-full`,children:[(0,f.jsx)(`div`,{className:`flex-shrink-0 p-1.5 rounded-lg bg-secondary/50 group-hover:bg-secondary transition-colors duration-200`,children:t?(0,f.jsx)(s.ChevronDown,{size:18,className:`text-muted-foreground group-hover:text-foreground transition-colors`}):(0,f.jsx)(s.ChevronRight,{size:18,className:`text-muted-foreground group-hover:text-foreground transition-colors`})}),(0,f.jsx)(`h2`,{className:`text-foreground font-medium text-lg lg:text-3xl lg:w-9/12 group-hover:text-foreground/80 transition-colors line-clamp-3 lg:line-clamp-none`,children:e.userMessage.content})]}),(0,f.jsxs)(`div`,{className:`flex items-center gap-0.5 mt-1 ml-10`,children:[(0,f.jsxs)(J,{children:[(0,f.jsx)(Y,{asChild:!0,children:(0,f.jsx)(`button`,{onClick:d,className:`p-1.5 text-muted-foreground rounded-lg hover:bg-secondary transition-all duration-200 hover:text-foreground`,children:(0,f.jsx)(`span`,{className:D(`flex items-center transition-all duration-300`,u?`scale-110`:`scale-100`),children:u?(0,f.jsx)(s.Check,{size:14,className:`text-green-500`}):(0,f.jsx)(s.ClipboardList,{size:14})})})}),(0,f.jsx)(X,{side:`bottom`,children:u?`Copied!`:`Copy prompt`})]}),(0,f.jsxs)(J,{children:[(0,f.jsx)(Y,{asChild:!0,children:(0,f.jsx)(`button`,{onClick:()=>{c(e.userMessage.content),a(!0),setTimeout(()=>p.current?.focus(),50)},className:`p-1.5 text-muted-foreground rounded-lg hover:bg-secondary transition-all duration-200 hover:text-foreground`,children:(0,f.jsx)(s.Pencil,{size:14})})}),(0,f.jsx)(X,{side:`bottom`,children:`Edit & resubmit`})]})]}),i&&(0,f.jsxs)(`div`,{className:`mt-3 ml-10 flex flex-col gap-2`,children:[(0,f.jsx)(`textarea`,{ref:p,value:o,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),l()),e.key===`Escape`&&a(!1)},rows:3,className:`w-full rounded-xl border border-border bg-background p-3 text-sm resize-none focus:outline-none focus:ring-2 focus:ring-primary/30 transition-colors`}),(0,f.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,f.jsx)(`button`,{onClick:()=>a(!1),className:`px-3 py-1.5 text-sm text-muted-foreground rounded-lg hover:bg-secondary transition-colors duration-200`,children:`Cancel`}),(0,f.jsx)(`button`,{onClick:l,disabled:!o.trim(),className:`px-3 py-1.5 text-sm bg-primary text-primary-foreground rounded-lg hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors duration-200`,children:`Resubmit`})]})]})]})};function ye({...e}){return(0,f.jsx)(g.Root,{"data-slot":`dropdown-menu`,...e})}function be({...e}){return(0,f.jsx)(g.Trigger,{"data-slot":`dropdown-menu-trigger`,...e})}function xe({className:e,sideOffset:t=4,...n}){return(0,f.jsx)(g.Portal,{children:(0,f.jsx)(g.Content,{"data-slot":`dropdown-menu-content`,sideOffset:t,className:D(`bg-card 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 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-2xl border p-1 shadow-md`,e),...n})})}function Z({className:e,inset:t,variant:n=`default`,...r}){return(0,f.jsx)(g.Item,{"data-slot":`dropdown-menu-item`,"data-inset":t,"data-variant":n,className:D(`focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-2xl px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,e),...r})}function Se({className:e,children:t,checked:n,...r}){return(0,f.jsxs)(g.CheckboxItem,{"data-slot":`dropdown-menu-checkbox-item`,className:D(`focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-2xl py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,e),checked:n,...r,children:[(0,f.jsx)(`span`,{className:`pointer-events-none absolute left-2 flex size-3.5 items-center justify-center`,children:(0,f.jsx)(g.ItemIndicator,{children:(0,f.jsx)(s.CheckIcon,{className:`size-4`})})}),t]})}function Ce({className:e,inset:t,...n}){return(0,f.jsx)(g.Label,{"data-slot":`dropdown-menu-label`,"data-inset":t,className:D(`px-2 py-1.5 text-sm font-medium data-[inset]:pl-8`,e),...n})}function Q({className:e,...t}){return(0,f.jsx)(g.Separator,{"data-slot":`dropdown-menu-separator`,className:D(`bg-border -mx-1 my-1 h-px`,e),...t})}function we({...e}){return(0,f.jsx)(g.Sub,{"data-slot":`dropdown-menu-sub`,...e})}function Te({className:e,inset:t,children:n,...r}){return(0,f.jsxs)(g.SubTrigger,{"data-slot":`dropdown-menu-sub-trigger`,"data-inset":t,className:D(`focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground flex cursor-default items-center rounded-2xl px-2 py-1.5 text-sm outline-hidden select-none data-[inset]:pl-8`,e),...r,children:[n,(0,f.jsx)(s.ChevronRightIcon,{className:`ml-auto size-4`})]})}function Ee({className:e,...t}){return(0,f.jsx)(g.SubContent,{"data-slot":`dropdown-menu-sub-content`,className:D(`bg-card 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 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-2xl border p-1 shadow-lg`,e),...t})}var De=({section:e,initialMessage:t})=>{let[r,i]=(0,n.useState)(!1);return(0,f.jsxs)(J,{children:[(0,f.jsx)(Y,{asChild:!0,children:(0,f.jsx)(`button`,{onClick:()=>{let n=`${t}${e?.sourceMessage?.sources&&e.sourceMessage.sources.length>0&&`\n\nCitations:\n${e.sourceMessage.sources?.map((e,t)=>`[${t+1}] ${e.metadata.url}`).join(`
18
18
  `)}`}`;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,f.jsx)(s.Check,{size:18}):(0,f.jsx)(s.ClipboardList,{size:18})})}),(0,f.jsx)(X,{side:`bottom`,children:r?`Copied!`:`Copy`})]})};function Oe({...e}){return(0,f.jsx)(_.Root,{"data-slot":`popover`,...e})}function ke({...e}){return(0,f.jsx)(_.Trigger,{"data-slot":`popover-trigger`,...e})}function Ae({className:e,align:t=`center`,sideOffset:n=4,container:r,...i}){return(0,f.jsx)(_.Portal,{container:r,children:(0,f.jsx)(_.Content,{"data-slot":`popover-content`,align:t,sideOffset:n,className:D(`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 $={Plus:s.Plus,Paperclip:s.Paperclip,Cloud:s.Cloud,Upload:s.Upload,File:s.File,SquarePen:s.SquarePen,Thinking:e=>(0,f.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 20 20`,fill:`currentColor`,xmlns:`http://www.w3.org/2000/svg`,...e,children:(0,f.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,f.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:`20`,height:`20`,viewBox:`0 0 20 20`,fill:`currentColor`,...e,children:(0,f.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`})})},je=({messageId:e})=>{let{rewrite:t,chatModelProvider:r,setChatModelProvider:i}=q(),[a,o]=(0,n.useState)([]),[c,u]=(0,n.useState)(!0),[d,p]=(0,n.useState)(``),[m,h]=(0,n.useState)(!1);(0,n.useEffect)(()=>{m&&(async()=>{try{u(!0);let{data:e}=await(0,l.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(d.toLowerCase())||e.name.toLowerCase().includes(d.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,f.jsxs)(Oe,{open:m,onOpenChange:h,children:[(0,f.jsxs)(J,{children:[(0,f.jsx)(Y,{asChild:!0,children:(0,f.jsx)(ke,{asChild:!0,children:(0,f.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,f.jsx)(s.ArrowLeftRight,{size:18})})})}),(0,f.jsxs)(X,{side:`bottom`,children:[`Rewrite with `,_]})]}),(0,f.jsx)(Ae,{className:`w-[280px] p-0`,align:`start`,side:`top`,sideOffset:8,children:(0,f.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,f.jsx)(`div`,{className:`p-3 border-b border-[#EEEEEE] dark:border-[#30302E]`,children:(0,f.jsxs)(`div`,{className:`relative`,children:[(0,f.jsx)(s.Search,{size:14,className:`absolute left-3 top-1/2 -translate-y-1/2 text-text-400 dark:text-[#999999]`}),(0,f.jsx)(`input`,{type:`text`,placeholder:`Search models...`,value:d,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,f.jsx)(`div`,{className:`max-h-[320px] overflow-y-auto`,children:c?(0,f.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,f.jsx)($.Loader2,{className:`animate-spin text-text-400 dark:text-[#999999]`,size:20})}):g.length===0?(0,f.jsx)(`div`,{className:`text-center py-12 px-4 text-text-400 dark:text-[#999999] text-sm`,children:d?`No models found`:`No chat models configured`}):(0,f.jsx)(`div`,{className:`flex flex-col`,children:g.map((e,t)=>(0,f.jsxs)(`div`,{children:[(0,f.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,f.jsx)(`p`,{className:`text-[11px] text-text-400 dark:text-[#999999] uppercase tracking-wider font-medium`,children:e.name})}),(0,f.jsx)(`div`,{className:`flex flex-col px-1.5 py-1.5 space-y-0.5`,children:e.chatModels.map(t=>(0,f.jsxs)(`button`,{onClick:()=>v(e.id,t.key),type:`button`,className:D(`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,f.jsxs)(`div`,{className:`flex items-center space-x-2.5 min-w-0 flex-1`,children:[(0,f.jsx)(s.Cpu,{size:14,className:D(`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,f.jsx)(`p`,{className:D(`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,f.jsx)($.Check,{className:`w-4 h-4 text-sky-500 shrink-0`})]},t.key))}),t<g.length-1&&(0,f.jsx)(`div`,{className:`h-px bg-[#EEEEEE] dark:bg-[#30302E] mx-2`})]},e.id))})})]})})]})},Me=new Map;function Ne(e){if(typeof window>`u`)return Promise.reject(Error(`CDN scripts require a browser environment`));let t=Me.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=()=>{Me.delete(e),n(Error(`Failed to load ${e}`))},document.head.appendChild(i)});return Me.set(e,n),n}var Pe=`https://cdn.jsdelivr.net/npm/jspdf@2.5.2/dist/jspdf.umd.min.js`,Fe=`https://cdn.jsdelivr.net/npm/docx@9.5.1/build/index.umd.min.js`;async function Ie(){await Ne(Pe);let e=window.jspdf?.jsPDF;if(!e)throw Error(`jsPDF global not found after CDN load`);return e}async function Le(){await Ne(Fe);let e=window.docx;if(!e)throw Error(`docx global not found after CDN load`);return e}async function Re(e,t){He(`# ${e}\n\n${new y.default({headingStyle:`atx`,codeBlockStyle:`fenced`}).turndown(t)}`,`${e}.md`,`text/markdown`)}async function ze(e,t){let{Document:n,Paragraph:r,TextRun:i,HeadingLevel:a,Packer:o}=await Le(),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 Be(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=`
19
19
  <h1 style="font-size: 24pt; margin-bottom: 20px;">${e}</h1>
@@ -31,7 +31,7 @@
31
31
  `,"aria-label":A?`Stop listening`:`Voice input`,children:(0,f.jsx)($.Mic,{className:`w-5 h-5`})}),(0,f.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,f.jsx)(`span`,{className:`text-[#ECECEC] dark:text-[#1F1E1D]`,children:A?`Stop listening`:`Voice input`})})]}),p.length>0&&(0,f.jsxs)(`div`,{className:`relative flex shrink !shrink-0 group`,children:[(0,f.jsx)(`button`,{onClick:e=>{e.stopPropagation(),u()},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,f.jsx)($.SquarePen,{className:`w-5 h-5`})}),(0,f.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,f.jsx)(`span`,{className:`text-[#ECECEC] dark:text-[#1F1E1D]`,children:`New chat`})})]}),(0,f.jsxs)(`div`,{className:`relative flex shrink !shrink-0 group`,children:[t?(0,f.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,f.jsx)($.Stop,{className:`w-3.5 h-3.5 fill-current`})}):(0,f.jsx)(`button`,{onClick:e=>{e.stopPropagation(),le()},disabled:!de,className:`inline-flex items-center justify-center shrink-0 transition-all duration-200 h-8 w-8 rounded-full active:scale-95
32
32
  ${de?`bg-accent text-bg-0 hover:bg-accent-hover shadow-md`:`bg-bg-300 text-text-400 cursor-default opacity-50`}
33
33
  `,type:`button`,"aria-label":`Send message`,children:(0,f.jsx)($.ArrowUp,{className:`w-4 h-4`})}),(0,f.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,f.jsx)(`span`,{className:`text-[#ECECEC] dark:text-[#1F1E1D]`,children:t?`Stop generating`:`Send message`})})]})]})]}),(0,f.jsx)(d.AnimatePresence,{children:te&&K>0&&(0,f.jsx)(d.motion.div,{ref:e=>{e&&_.current&&_.current.contains(e)},initial:{opacity:0,y:ne===`above`?4:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:ne===`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 ${ne===`above`?`bottom-full`:`top-full`}`,onMouseDown:e=>e.preventDefault(),children:(0,f.jsxs)(`ul`,{className:`max-h-72 overflow-y-auto custom-scrollbar py-1`,children:[B.map((e,t)=>(0,f.jsx)(`li`,{children:(0,f.jsxs)(`button`,{type:`button`,onMouseEnter:()=>U(t),onClick:()=>G(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,f.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,f.jsx)(`img`,{src:e.favicon,alt:``,className:`w-4 h-4 rounded-sm shrink-0`}),(0,f.jsx)(`span`,{className:`truncate font-medium`,children:e.name||e.domain}),(0,f.jsx)(`span`,{className:`truncate text-[13px] text-text-400 shrink-0`,children:e.domain})]})},`domain-${e.domain}`)),ee.map((e,t)=>{let n=B.length+t;return(0,f.jsx)(`li`,{children:(0,f.jsxs)(`button`,{type:`button`,onMouseEnter:()=>U(n),onClick:()=>se(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,f.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,f.jsx)(s.Search,{className:`w-4 h-4 text-text-400 shrink-0`}),(0,f.jsx)(`span`,{className:`truncate`,children:e})]})},`${e}-${t}`)})]})})}),S&&(0,f.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,f.jsx)($.Archive,{className:`w-10 h-10 text-accent mb-2 animate-bounce`}),(0,f.jsx)(`p`,{className:`text-accent font-medium`,children:`Drop files to upload`})]})]})};function wt({...e}){return(0,f.jsx)(C.Root,{"data-slot":`dialog`,...e})}function Tt({...e}){return(0,f.jsx)(C.Trigger,{"data-slot":`dialog-trigger`,...e})}function Et({...e}){return(0,f.jsx)(C.Portal,{"data-slot":`dialog-portal`,...e})}function Dt({className:e,...t}){return(0,f.jsx)(C.Overlay,{"data-slot":`dialog-overlay`,className:D(`data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50 backdrop-blur-xs`,e),...t})}function Ot({className:e,children:t,hideCloseButton:n=!1,...r}){return(0,f.jsxs)(Et,{"data-slot":`dialog-portal`,children:[(0,f.jsx)(Dt,{}),(0,f.jsxs)(C.Content,{"data-slot":`dialog-content`,"aria-describedby":r[`aria-describedby`]??void 0,className:D(`z-[9999] bg-background 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 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-2xl border p-6 shadow-lg duration-200`,e),...r,children:[t,!n&&(0,f.jsxs)(C.Close,{className:`ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,children:[(0,f.jsx)(s.XIcon,{}),(0,f.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]})}function kt({className:e,...t}){return(0,f.jsx)(C.Title,{"data-slot":`dialog-title`,className:D(`text-lg leading-none font-semibold`,e),...t})}function At({className:e,...t}){return(0,f.jsx)(C.Description,{"data-slot":`dialog-description`,className:D(`text-muted-foreground text-sm`,e),...t})}var jt=n.forwardRef(({className:e,...t},n)=>(0,f.jsx)(`span`,{ref:n,className:D(`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}));jt.displayName=`VisuallyHidden`;var Mt=({onClose:e})=>(0,f.jsx)(`div`,{className:`flex items-center justify-between bg-secondary px-4 py-3 border-b border-border`,children:(0,f.jsx)(`button`,{onClick:e,className:`rounded-md p-1 hover:bg-accent transition-colors`,children:(0,f.jsx)(s.X,{className:`h-5 w-5`})})}),Nt=(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 Pt({className:e,variant:t,size:n,asChild:r=!1,...i}){return(0,f.jsx)(r?b.Slot:`button`,{"data-slot":`button`,className:D(Nt({variant:t,size:n,className:e})),...i})}var Ft=({isLoadingAI:e,isLoadingFollowups:t,isLoadingFavorite:n,isFavorited:r,isHighlightMode:i,onAskClick:a,onSuggestClick:o,onCopyClick:c,onFavoriteClick:l,onHighlightToggle:u})=>(0,f.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 rounded-2xl border border-muted bg-gradient-to-b from-background to-muted/30 p-1 shadow-sm`,children:[(0,f.jsxs)(Pt,{onClick:a,disabled:e,variant:`ghost`,size:`sm`,className:D(`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,f.jsx)(s.Bot,{className:`size-4`}),(0,f.jsx)(`span`,{className:`font-medium`,children:e?`...`:`Ask`})]}),(0,f.jsxs)(Pt,{onClick:o,disabled:t,variant:`ghost`,size:`sm`,className:D(`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,f.jsx)(s.MessageCircleQuestion,{className:`size-4`}),(0,f.jsx)(`span`,{className:`font-medium`,children:`Suggest`})]}),(0,f.jsx)(Pt,{onClick:c,variant:`ghost`,size:`icon`,className:D(`h-9 w-9 rounded-xl transition-all duration-200`,`hover:bg-muted/80 hover:text-foreground text-muted-foreground`),children:(0,f.jsx)(s.Clipboard,{className:`size-4`})}),(0,f.jsx)(Pt,{onClick:u,variant:`ghost`,size:`icon`,className:D(`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`),title:i?`Disable highlighting`:`Enable highlighting`,children:(0,f.jsx)(s.Highlighter,{className:`size-4`})}),(0,f.jsx)(Pt,{onClick:l,disabled:n,variant:`ghost`,size:`icon`,className:D(`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`),title:r?`Remove from favorites`:`Add to favorites`,children:(0,f.jsx)(s.Star,{className:D(`size-4`,r&&`fill-yellow-400`)})})]}),It=({value:e,onChange:t,onSubmit:n})=>(0,f.jsx)(`div`,{className:`relative`,children:(0,f.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`})}),Lt=({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,f.jsxs)(f.Fragment,{children:[o.length>0&&(0,f.jsxs)(`div`,{className:`space-y-3 bg-accent/30 rounded-lg p-4 border border-primary/20`,children:[(0,f.jsx)(`h3`,{className:`text-sm font-bold text-primary mb-2`,children:`💡 Suggested Follow-up Questions`}),(0,f.jsxs)(`div`,{className:`space-y-2`,children:[(0,f.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,f.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,f.jsx)(`div`,{className:`flex justify-center`,children:(0,f.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-blue-500`})}),i&&(0,f.jsx)(`div`,{className:`bg-red-500 text-white p-2 rounded-md text-sm`,children:i})]})},Rt=({response:e,isLoading:t,error:n})=>(0,f.jsxs)(f.Fragment,{children:[t&&(0,f.jsx)(`div`,{className:`flex justify-center`,children:(0,f.jsx)(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-blue-500`})}),e&&(0,f.jsx)(`div`,{ref:e=>{},className:`bg-muted rounded-lg shadow-md p-4`,dangerouslySetInnerHTML:{__html:e}}),n&&(0,f.jsx)(`div`,{className:`bg-red-500 text-white p-2 rounded-md text-sm`,children:n})]}),zt=({html:e,isHighlightMode:t=!1})=>{let[r,i]=(0,n.useState)(``);return(0,n.useEffect)(()=>{i(w.default.sanitize(e||``,{ADD_TAGS:[`figure`,`figcaption`],ADD_ATTR:[`loading`]}))},[e]),(0,f.jsx)(`div`,{className:`prose prose-neutral dark:prose-invert max-w-none ${t?`select-text`:``}`,dangerouslySetInnerHTML:{__html:r}})},Bt=({article:e,isHighlightMode:t})=>(0,f.jsx)(`div`,{className:`border-t border-border pt-6`,children:(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`div`,{className:`flex items-start justify-between mb-2`}),e.url&&(0,f.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1.5 mb-3 text-sm text-primary hover:underline truncate max-w-full`,children:[(0,f.jsx)(s.ExternalLink,{className:`flex-shrink-0 size-3.5`}),(0,f.jsx)(`span`,{className:`truncate`,children:e.url})]}),e.cite&&(0,f.jsx)(`div`,{className:`mb-3 text-sm text-muted-foreground`,dangerouslySetInnerHTML:{__html:e.cite}}),(0,f.jsx)(`div`,{className:`mb-3 text-xs text-muted-foreground space-y-1`,children:e.word_count&&(0,f.jsxs)(`p`,{children:[(0,f.jsx)(`span`,{className:`font-semibold`,children:`Words:`}),` `,e.word_count.toLocaleString()]})}),(0,f.jsx)(`div`,{id:`article-content`,children:(0,f.jsx)(zt,{html:e.html||``,isHighlightMode:t})})]})}),Vt=/(?:https?:\/\/)?(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)/g,Ht=/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g;function Ut(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 Wt(e){return/^https?:\/\//i.test(e)?e:`https://${e}`}function Gt(e){if(!e||typeof e!=`string`)return e;let t=e,n=[],r;for(Ht.lastIndex=0;(r=Ht.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(Vt.lastIndex=0;(a=Vt.exec(t))!==null;){let e=a[0],n=a.index;if(Ht.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}Ut(e)&&i.push({url:e,index:n})}for(let e=i.length-1;e>=0;e--){let{url:n,index:r}=i[e],a=Wt(n);t=t.substring(0,r)+`[${n}](${a})`+t.substring(r+n.length)}return t}function Kt(e){return!e||e.startsWith(`http://`)||e.startsWith(`https://`)||e.includes(`://`)?!1:e.startsWith(`/`)||e.startsWith(`#`)}function qt(e,t){if(t.startsWith(`#`)){e.preventDefault();let n=t.substring(1),r=document.getElementById(n);r&&r.scrollIntoView({behavior:`smooth`,block:`start`})}}function Jt({code:e}){let[t,r]=(0,n.useState)(!1);return(0,f.jsx)(`button`,{onClick:(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]),className:D(`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,f.jsx)(s.Check,{className:`h-4 w-4 text-green-600 dark:text-green-400`}):(0,f.jsx)(s.Copy,{className:`h-4 w-4`})})}function Yt({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,f.jsxs)(`div`,{className:`relative group my-5`,children:[(0,f.jsx)(`pre`,{ref:t,className:D(`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,f.jsx)(Jt,{code:r})]})}var Xt=n.default.memo(({content:e,className:t,isStreaming:n=!1})=>{if(!e)return(0,f.jsx)(`div`,{className:D(`text-muted-foreground text-sm`,t),children:`No content`});let r=Gt(e);return(0,f.jsx)(`div`,{className:D(`kortix-markdown`,t),children:(0,f.jsx)(E.Streamdown,{isAnimating:n,components:{h1:({children:e})=>(0,f.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,f.jsx)(`h2`,{className:`text-xl font-semibold tracking-tight text-foreground mt-8 mb-3 first:mt-0`,children:e}),h3:({children:e})=>(0,f.jsx)(`h3`,{className:`text-lg font-semibold text-foreground mt-6 mb-2 first:mt-0`,children:e}),h4:({children:e})=>(0,f.jsx)(`h4`,{className:`text-base font-semibold text-foreground mt-5 mb-2 first:mt-0`,children:e}),h5:({children:e})=>(0,f.jsx)(`h5`,{className:`text-sm font-semibold text-foreground mt-4 mb-1 first:mt-0`,children:e}),h6:({children:e})=>(0,f.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,f.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,f.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,f.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,f.jsx)(`li`,{className:`text-sm text-foreground leading-relaxed pl-1`,children:e}),a:({href:e,children:t})=>{let n=Kt(e),r=e?.startsWith(`#`),i=D(`font-medium text-foreground`,`underline decoration-foreground/30 underline-offset-[3px] decoration-[1px]`,`hover:decoration-foreground/60 transition-colors duration-150`);return r?(0,f.jsx)(`a`,{href:e,onClick:t=>qt(t,e),className:i,children:t}):n?(0,f.jsx)(T.default,{href:e||`#`,className:i,children:t}):(0,f.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,className:i,children:t})},code:({children:e,className:t})=>t?.includes(`language-`)?(0,f.jsx)(`code`,{className:`text-[13px] leading-relaxed text-inherit`,children:e}):(0,f.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,f.jsx)(Yt,{children:e}),blockquote:({children:e})=>(0,f.jsx)(`blockquote`,{className:D(`my-5 pl-4 py-1 text-sm`,`border-l-2 border-border`,`text-muted-foreground`,`[&>p]:my-2`),children:e}),hr:()=>(0,f.jsx)(`hr`,{className:`my-8 border-0 h-px bg-border/60`}),table:({children:e})=>(0,f.jsx)(`div`,{className:`my-5 overflow-x-auto rounded-xl border border-border/60`,children:(0,f.jsx)(`table`,{className:`w-full text-sm`,children:e})}),thead:({children:e})=>(0,f.jsx)(`thead`,{className:`bg-muted/50 dark:bg-muted/30 border-b border-border/60`,children:e}),tbody:({children:e})=>(0,f.jsx)(`tbody`,{className:`divide-y divide-border/40`,children:e}),tr:({children:e})=>(0,f.jsx)(`tr`,{className:`transition-colors hover:bg-muted/30`,children:e}),th:({children:e})=>(0,f.jsx)(`th`,{className:`px-4 py-3 text-left text-xs font-semibold text-foreground uppercase tracking-wider`,children:e}),td:({children:e})=>(0,f.jsx)(`td`,{className:`px-4 py-3 text-foreground`,children:e}),img:({src:e,alt:t})=>e?(0,f.jsxs)(`span`,{className:`block my-5`,children:[(0,f.jsx)(`img`,{src:e,alt:t||``,className:D(`max-w-full h-auto rounded-xl`,`border border-border/40`,`shadow-sm`),loading:`lazy`}),t&&(0,f.jsx)(`span`,{className:`block mt-2 text-center text-sm text-muted-foreground`,children:t})]}):null,strong:({children:e})=>(0,f.jsx)(`strong`,{className:`font-semibold text-foreground`,children:e}),em:({children:e})=>(0,f.jsx)(`em`,{className:`italic text-foreground/90`,children:e}),del:({children:e})=>(0,f.jsx)(`del`,{className:`line-through text-muted-foreground decoration-muted-foreground/50`,children:e}),input:({checked:e,...t})=>(0,f.jsx)(`input`,{type:`checkbox`,checked:e,readOnly:!0,className:D(`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,f.jsx)(`div`,{className:D(`text-sm text-foreground`,n),style:t,...r,children:e}),span:({children:e,style:t,className:n,...r})=>(0,f.jsx)(`span`,{className:D(`text-foreground`,n),style:t,...r,children:e})},children:r})})});Xt.displayName=`UnifiedMarkdown`;var Zt=e=>{let{isOpen:r,url:i,searchText:a,panelWidth:o,setPanelWidth:s,closePanel:c}=j(),{isAuthenticated:u}=fe(),d=e.isOpen===void 0?r:e.isOpen,p=e.onClose||c,h=e.url||i,g=e.searchText===void 0?a:e.searchText,[_,v]=(0,n.useState)(null),[y,b]=(0,n.useState)([]),[x,S]=(0,n.useState)(!1),[C,w]=(0,n.useState)(t.researchAgentUIConfig.defaultSummarizePrompt),[T,E]=(0,n.useState)(!1),[D,O]=(0,n.useState)(!1),[k,A]=(0,n.useState)(!1),[M,N]=(0,n.useState)(``),[P,F]=(0,n.useState)(``),[I,L]=(0,n.useState)([]),[R,ee]=(0,n.useState)(``),[z,B]=(0,n.useState)(!1),[V,H]=(0,n.useState)(!1),[U,te]=(0,n.useState)(!1),[W,ne]=(0,n.useState)(!1),[re,ie]=(0,n.useState)(o),[ae,oe]=(0,n.useState)(!1),[se,G]=(0,n.useState)(!1),K=(0,n.useRef)(null);(0,n.useEffect)(()=>{let e=()=>{ne(window.innerWidth>=1024)};return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]),(0,n.useEffect)(()=>{let e=e=>{if(!ae)return;let t=window.innerWidth-e.clientX,n=Math.max(400,Math.min(t,window.innerWidth-100));ie(n),s(n)},t=()=>{oe(!1)};return ae&&(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=``}},[ae,s]),(0,n.useEffect)(()=>{d&&h?(G(!1),ce()):d||G(!1)},[d,h]);let ce=async()=>{console.log(`[ArticleExtractPanel] Extracting URL:`,h);try{let e=new URL(h);if([/^https?:\/\/(www\.)?google\.[^/]+\/search/i,/^https?:\/\/(www\.)?bing\.com\/search/i,/^https?:\/\/(www\.)?duckduckgo\.com\/\?/i].some(e=>e.test(h))){m.toast.error(`Cannot extract articles from search result pages`),E(!1),G(!0);return}(e.pathname===`/`||e.pathname===``)&&(console.error(`[ArticleExtractPanel] URL is domain-only, missing article path:`,h),m.toast.error(`Invalid article URL - only domain provided`))}catch(e){console.error(`[ArticleExtractPanel] Invalid URL format:`,h,e)}E(!0);try{let{data:e}=await(0,l.getArticle)({query:{url:h}}),t=e?.article,n=t?.html?.replace(/<[^>]*>/g,``).trim()||``;t?.error||n.length<20?(document.dispatchEvent(new CustomEvent(`onInvokeChromeAPI`,{detail:{type:`extractURL`,url:h}})),await Promise.race([new Promise(e=>{let t=async n=>{window.removeEventListener(`onExtractionResult`,t);let{data:r}=await(0,l.getArticle)({query:{url:h}}),i=r?.article;i&&(v(i),i.followUpQuestions?.length>0&&L(i.followUpQuestions)),e()};window.addEventListener(`onExtractionResult`,t)}),new Promise(e=>setTimeout(e,1e4))])):(v(t),t?.followUpQuestions&&t.followUpQuestions.length>0&&L(t.followUpQuestions)),u&&le()}catch(e){console.error(`[ArticleExtractPanel] Error extracting URL:`,e),m.toast.error(`Failed to load article`)}finally{E(!1),G(!0)}},le=async()=>{try{let{data:e}=await(0,l.listFavorites)(),t=e?.favorites?.some(e=>e.url===h);B(!!t)}catch(e){console.error(`Error checking favorite status:`,e)}},q=async()=>{if(_){H(!0);try{z?(await(0,l.removeFavorite)({query:{url:h}}),B(!1),m.toast.info(`Removed from favorites`)):(await(0,l.addFavorite)({body:{url:_.url||h,title:_.title,cite:_.cite,author:_.author,author_cite:_.author_cite,date:_.date,source:_.source,word_count:_.word_count,html:_.html}}),B(!0),m.toast.success(`Added to favorites`))}catch(e){console.error(`Error toggling favorite:`,e),m.toast.error(`Failed to toggle favorite`)}finally{H(!1)}}},ue=async e=>{if(!_)return;let n=_.html?.replace(/<[^>]*>?/g,``).slice(0,t.researchAgentUIConfig.maxArticleLength),r=e===`question`,i=r?O:A,a=r?F:ee;i(!0),a(``);try{if(r){let{data:e,error:t}=await(0,l.articleQa)({body:{article:n,question:[g,C].filter(Boolean).join(`
34
- `),chatHistory:y.slice(-5),provider:`groq`}});if(t)throw Error(t.error||`Article QA failed`);let r=e?.content||``;N(r),b(e=>[...e,{role:`user`,content:C,time:new Date().toISOString()},{role:`assistant`,content:r,time:new Date().toISOString()}]);try{await(0,l.updateArticle)({body:{url:h,question:C,answer:r}})}catch(e){console.error(`Error storing Q&A in cache:`,e)}}else{let e=parseInt(localStorage.getItem(`maxFollowupQuestions`)||`4`),{data:t,error:r}=await(0,l.articleFollowups)({body:{article:n,chatHistory:y.slice(-5),maxQuestions:e,provider:`groq`}});if(r)throw Error(r.error||`Article followups failed`);let i=t?.extract||[];L(i);try{await(0,l.updateArticle)({body:{url:h,followUpQuestions:i}})}catch(e){console.error(`Error storing follow-up questions in cache:`,e)}}}catch(e){console.error(`Error calling language API:`,e),a(`Failed to get AI response`)}finally{i(!1)}},de=e=>{w(e),ue(`question`)},pe=async()=>{if(!_)return;let e=`${M}\n\n\n${_.cite||``}\n\n\n${_.html}`;try{await navigator.clipboard.writeText(e),S(!0),setTimeout(()=>S(!1),2e3)}catch(e){console.error(`Failed to copy to clipboard:`,e)}},me=()=>(0,f.jsxs)(`div`,{className:`flex h-full flex-col bg-background shadow-xl`,children:[(0,f.jsx)(Mt,{onClose:p}),(0,f.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:(0,f.jsxs)(`div`,{className:`p-4 space-y-6`,children:[(0,f.jsxs)(`div`,{className:`space-y-4`,children:[(0,f.jsx)(Ft,{isLoadingAI:D,isLoadingFollowups:k,isLoadingFavorite:V,isFavorited:z,isHighlightMode:U,onAskClick:()=>ue(`question`),onSuggestClick:()=>ue(`suggest-followups`),onCopyClick:pe,onFavoriteClick:q,onHighlightToggle:()=>te(!U)}),x&&(0,f.jsx)(`div`,{className:`bg-blue-500 text-white text-sm font-medium px-3 py-2 rounded-md shadow-lg`,children:`Copied!`}),(0,f.jsx)(It,{value:C,onChange:w,onSubmit:()=>ue(`question`)}),(0,f.jsx)(Lt,{questions:I,isLoading:k,error:R,onQuestionClick:de}),y.length>0&&(0,f.jsx)(`div`,{className:`space-y-4`,children:y.map((e,t)=>(0,f.jsx)(`div`,{className:`space-y-2`,children:e.role===`user`?(0,f.jsxs)(`div`,{className:`bg-primary/10 border border-primary/20 rounded-lg p-3`,children:[(0,f.jsx)(`div`,{className:`text-xs font-semibold text-primary mb-1`,children:`Your Question`}),(0,f.jsx)(`div`,{className:`text-sm text-foreground`,children:e.content})]}):(0,f.jsxs)(`div`,{className:`bg-muted rounded-lg shadow-md p-4`,children:[(0,f.jsx)(`div`,{className:`text-xs font-semibold text-muted-foreground mb-2`,children:`AI Response`}),(0,f.jsx)(`div`,{className:`text-sm`,dangerouslySetInnerHTML:{__html:e.content}})]})},t))}),(D||M&&y.length===0)&&(0,f.jsx)(Rt,{response:M,isLoading:D,error:P}),P&&!D&&(0,f.jsx)(`div`,{className:`bg-red-500 text-white p-2 rounded-md text-sm`,children:P})]}),_&&(0,f.jsx)(Bt,{article:_,isHighlightMode:U})]})})]});return!d||!se?null:W?(0,f.jsxs)(`div`,{className:`fixed top-0 right-0 h-screen z-40 transition-all duration-300`,style:{width:`${re}px`},children:[(0,f.jsx)(`div`,{ref:K,onMouseDown:()=>oe(!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,f.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`})}),me()]}):(0,f.jsx)(wt,{open:d,onOpenChange:e=>!e&&p(),children:(0,f.jsxs)(Ot,{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,f.jsx)(jt,{children:(0,f.jsx)(kt,{children:`Article Details`})}),(0,f.jsx)(`div`,{className:`h-full overflow-y-auto`,children:me()})]})})},Qt=`qwksearch_pinned_chats`;function $t(){if(typeof window>`u`)return[];try{let e=localStorage.getItem(Qt);return e?JSON.parse(e):[]}catch{return[]}}function en(e){typeof window>`u`||localStorage.setItem(Qt,JSON.stringify(e))}function tn(){let[e,t]=(0,n.useState)([]),[r,i]=(0,n.useState)(!0),[a,o]=(0,n.useState)(!1),[s,c]=(0,n.useState)(null),[l,u]=(0,n.useState)(!1),[d,f]=(0,n.useState)(!1),[p,h]=(0,n.useState)(!1),[g,_]=(0,n.useState)([]),[v,y]=(0,n.useState)(``),[b,x]=(0,n.useState)([]),[S,C]=(0,n.useState)(!1),{isAuthenticated:w,isLoading:T}=fe(),{incognito:E,setIncognito:D}=q();(0,n.useEffect)(()=>{_($t())},[]);let O=(0,n.useCallback)((e,t)=>{e.preventDefault(),e.stopPropagation(),_(e=>{let n=e.includes(t)?e.filter(e=>e!==t):[...e,t];return en(n),n})},[]),k=(0,n.useMemo)(()=>[...e].sort((e,t)=>{let n=g.includes(e.id),r=g.includes(t.id);return n&&!r?-1:!n&&r?1:0}),[e,g]),A=(0,n.useMemo)(()=>v.trim()?b:k,[v,b,k]),j=(0,n.useCallback)(async()=>{if(!T){i(!0);try{if(w){let e=await fetch(`/api/agent/chats`,{credentials:`include`,headers:{"Content-Type":`application/json`}});if(e.status===401){let e=V().map(e=>({...e,messageCount:e.messages?.filter(e=>e.role===`user`).length??0}));t(e);return}if(!e.ok)throw Error(`HTTP ${e.status}: ${e.statusText}`);let n=await e.json();t(Array.isArray(n?.chats)?n.chats:[])}else{let e=V().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)}}},[w,T]);(0,n.useEffect)(()=>{j()},[j]);let M=(e,t)=>{e.preventDefault(),e.stopPropagation(),c(t),o(!0)},N=async()=>{if(s){u(!0);try{if(w){let e=await fetch(`/api/agent/chats/${s}`,{method:`DELETE`,credentials:`include`,headers:{"Content-Type":`application/json`}});if(!e.ok)throw Error(`HTTP ${e.status}: ${e.statusText}`)}else te(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),c(null),u(!1)}}},P=()=>{f(!0)},F=async()=>{h(!0);try{if(w){let e=await fetch(`/api/agent/chats`,{method:`DELETE`,credentials:`include`,headers:{"Content-Type":`application/json`}});if(!e.ok)throw Error(`HTTP ${e.status}: ${e.statusText}`)}else W();t([]),m.toast.success(`All history cleared`)}catch(e){m.toast.error(e.message||`Failed to clear history`)}finally{f(!1),h(!1)}},I=()=>{D(!E),m.toast.success(E?`Private mode off`:`Private mode on — messages won't be saved`)},L=(0,n.useCallback)(async e=>{if(!e.trim()){x([]),C(!1);return}C(!0);try{if(w){let t=await fetch(`/api/agent/chats/search?q=${encodeURIComponent(e)}`,{credentials:`include`,headers:{"Content-Type":`application/json`}});if(!t.ok)throw Error(`HTTP ${t.status}: ${t.statusText}`);let n=await t.json();x(Array.isArray(n?.chats)?n.chats:[])}else{let t=V().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});x(t.map(e=>({...e,messageCount:e.messages?.filter(e=>e.role===`user`).length??0})))}}catch(e){console.error(`Failed to search chat history:`,e),x([]),m.toast.error(`Failed to search chat history`)}finally{C(!1)}},[w]);return(0,n.useEffect)(()=>{let e=setTimeout(()=>{L(v)},300);return()=>clearTimeout(e)},[v,L]),{chats:e,sortedChats:k,displayChats:A,loading:r,pinnedIds:g,togglePin:O,incognito:E,toggleIncognito:I,searchQuery:v,searchResults:b,searching:S,handleSearchChange:(0,n.useCallback)(e=>{y(e)},[]),deleteDialogOpen:a,setDeleteDialogOpen:o,chatToDelete:s,setChatToDelete:c,deleting:l,handleDeleteClick:M,handleConfirmDelete:N,clearAllDialogOpen:d,setClearAllDialogOpen:f,clearingAll:p,handleClearAllClick:P,handleConfirmClearAll:F}}function nn({incognito:e,onToggleIncognito:t,showClearAll:n,onClearAll:r,searchQuery:i,onSearchChange:a}){return(0,f.jsxs)(`div`,{className:`mb-2 pb-2 border-b border-border space-y-2`,children:[(0,f.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,f.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground/80 uppercase tracking-wide`,children:`Chat History`}),(0,f.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,f.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,f.jsx)(s.Lock,{size:12}),(0,f.jsx)(`span`,{children:`Private`})]}),n&&(0,f.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,f.jsx)(s.Trash2,{size:12}),(0,f.jsx)(`span`,{children:`Clear All`})]})]})]}),(0,f.jsxs)(`div`,{className:`relative`,children:[(0,f.jsx)(s.Search,{className:`absolute left-2 top-1/2 -translate-y-1/2 text-muted-foreground`,size:14}),(0,f.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,f.jsx)(`button`,{onClick:()=>a(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground`,children:(0,f.jsx)(s.X,{size:14})})]})]})}function rn({chat:e,isPinned:t,onTogglePin:n,onDelete:r}){let i=e.messageCount??0;return(0,f.jsxs)(`div`,{className:`group flex items-center gap-1 px-2 py-1 rounded-lg hover:bg-secondary transition-colors duration-200`,children:[(0,f.jsxs)(T.default,{href:`/c/${e.id}`,className:`flex-1 min-w-0 flex items-center gap-1.5`,children:[(0,f.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[i>0&&(0,f.jsxs)(Ge,{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:[i,`Q`]}),(0,f.jsx)(Ge,{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:O(new Date,e.createdAt)})]}),(0,f.jsxs)(`p`,{className:`text-xs text-popover-foreground truncate`,children:[t&&(0,f.jsx)(s.Pin,{size:10,className:`inline mr-1 text-primary`}),e.title]})]}),(0,f.jsx)(`button`,{onClick:t=>n(t,e.id),className:`p-1.5 rounded-lg transition-all duration-200 ${t?`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:t?`Unpin chat`:`Pin chat`,children:(0,f.jsx)(s.Pin,{size:14})}),(0,f.jsx)(`button`,{onClick:t=>r(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,f.jsx)(s.Trash,{size:14})})]})}function an({open:e,onOpenChange:t,title:n,description:r,confirmLabel:i,loadingLabel:a,loading:o,onConfirm:s}){return(0,f.jsx)(wt,{open:e,onOpenChange:e=>{!e&&!o&&t(!1)},children:(0,f.jsxs)(Ot,{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,f.jsx)(kt,{className:`text-lg font-medium leading-6 dark:text-white`,children:n}),(0,f.jsx)(At,{className:`text-sm dark:text-white/70 text-black/70 mt-2`,children:r}),(0,f.jsxs)(`div`,{className:`flex flex-row items-end justify-end space-x-4 mt-6`,children:[(0,f.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,f.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 on({deleteDialogOpen:e,setDeleteDialogOpen:t,chatToDelete:n,setChatToDelete:r,deleting:i,onConfirmDelete:a,clearAllDialogOpen:o,setClearAllDialogOpen:s,clearingAll:c,onConfirmClearAll:l}){return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(an,{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,f.jsx)(an,{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 sn={Today:(0,f.jsx)(s.Sun,{size:12}),Yesterday:(0,f.jsx)(s.Clock,{size:12}),"This Week":(0,f.jsx)(s.CalendarDays,{size:12}),Older:(0,f.jsx)(s.Archive,{size:12})};function cn(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()-6*864e5),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 ln=({showLabel:e=!1})=>{let t=tn();return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsxs)(wt,{children:[(0,f.jsxs)(Tt,{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,f.jsx)(s.History,{size:e?14:18}),e&&(0,f.jsx)(`span`,{children:`History`})]}),(0,f.jsxs)(Ot,{className:`max-w-[420px] p-3`,children:[(0,f.jsx)(kt,{className:`sr-only`,children:`Chat History`}),(0,f.jsx)(nn,{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,f.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,f.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,f.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,f.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,f.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,f.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No matching chats found.`})}):t.chats.length===0?(0,f.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,f.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No chats found.`})}):(0,f.jsx)(`div`,{className:`space-y-1 max-h-[500px] overflow-y-auto`,children:t.searchQuery.trim()?t.displayChats.map(e=>(0,f.jsx)(rn,{chat:e,isPinned:t.pinnedIds.includes(e.id),onTogglePin:t.togglePin,onDelete:t.handleDeleteClick},e.id)):cn(t.displayChats).map(({label:e,chats:n})=>(0,f.jsxs)(`div`,{children:[(0,f.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:[sn[e],e]}),n.map(e=>(0,f.jsx)(rn,{chat:e,isPinned:t.pinnedIds.includes(e.id),onTogglePin:t.togglePin,onDelete:t.handleDeleteClick},e.id))]},e))}),t.chats.length>0&&(0,f.jsx)(`div`,{className:`mt-2 pt-2 border-t border-border`,children:(0,f.jsx)(T.default,{href:`/library`,className:`block text-center text-xs text-primary hover:underline`,children:`View all chats`})})]})]}),(0,f.jsx)(on,{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})]})},un=()=>{let{sections:e,chatTurns:r,loading:i,messageAppeared:a,newChat:o,chatId:s}=q(),{isOpen:c,panelWidth:l}=j(),{isAuthenticated:u}=fe(),[d,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 _=d&&c?{width:`calc(100% - ${l}px)`}:{};return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`div`,{className:`fixed top-0 z-50 flex items-center gap-1 px-4 py-3 transition-all duration-300`,style:{right:d&&c?`${l}px`:`0`},children:(0,f.jsx)(ln,{})}),(0,f.jsxs)(`div`,{className:`flex flex-col min-h-full transition-all duration-300`,style:_,children:[(0,f.jsxs)(`div`,{className:`flex-1 flex flex-col space-y-3 pb-48 ${d&&!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,f.jsxs)(n.Fragment,{children:[(0,f.jsx)(qe,{section:t,sectionIndex:r,dividerRef:i?m:void 0,isLast:i}),!i&&(0,f.jsx)(`div`,{className:`h-px w-full bg-light-secondary dark:bg-dark-secondary`})]},t.userMessage.messageId)}),i&&!a&&(0,f.jsx)(`div`,{className:`flex items-center justify-center`,children:(0,f.jsx)(`div`,{style:{height:`200px`,width:`100%`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:(0,f.jsx)(S.default,{autoRandomize:!0,onSphereClick:()=>console.log(`Sphere clicked`),className:`my-custom-class`})})}),(0,f.jsx)(`div`,{ref:h,className:`h-0`})]}),(0,f.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,f.jsx)(Ct,{})})]}),(0,f.jsx)(Zt,{})]})};function dn({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=()=>{n.width=window.innerWidth,n.height=window.innerHeight};a();let l=()=>{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 a={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(a);let o=[];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&&o.push(n)}for(let e=o.length-1;e>=0;e--)c.current.splice(o[e],1);i.globalAlpha=1,requestAnimationFrame(l)},d=e=>{s.current.x=e.pageX,s.current.y=e.pageY},f=e=>{s.current.x=e.touches[0].pageX,s.current.y=e.touches[0].pageY};return window.addEventListener(`mousemove`,d),window.addEventListener(`touchmove`,f,{passive:!0}),window.addEventListener(`resize`,a),l(),()=>{window.removeEventListener(`mousemove`,d),window.removeEventListener(`touchmove`,f),window.removeEventListener(`resize`,a)}},[e,t,r,i,a]),(0,f.jsx)(`div`,{className:`relative w-full h-screen overflow-hidden pointer-events-none`,children:(0,f.jsx)(`canvas`,{ref:o,className:`absolute inset-0`,style:{background:`transparent`}})})}function fn(){let{chats:e,loading:t}=tn(),n=[...e].sort((e,t)=>new Date(t.createdAt).getTime()-new Date(e.createdAt).getTime()).slice(0,3);return t?null:(0,f.jsxs)(`div`,{className:`flex flex-row items-center justify-center gap-2 flex-wrap`,children:[(0,f.jsx)(ln,{showLabel:!0}),n.map(e=>(0,f.jsx)(T.default,{href:`/c/${e.id}`,className:`px-3 py-1 rounded-full text-xs text-muted-foreground bg-secondary hover:bg-secondary/80 hover:text-foreground transition-colors duration-150 truncate max-w-[160px]`,title:e.title,children:e.title},e.id))]})}function pn({listFooterLinks:e=[],optionShowIcons:t=!0,optionBackgroundColor:n=`bg-black/40`}){return(0,f.jsx)(`div`,{className:`absolute bottom-2 left-1/2 -translate-x-1/2 text-slate-200 text-xs z-20 ${n} rounded-lg px-2 py-1 shadow-lg hover:shadow-xl hover:-translate-y-1 transition-all duration-300 flex flex-wrap items-center justify-center gap-x-6 max-w-[90vw]`,children:(0,f.jsx)(`div`,{className:`max-w-4xl mx-auto grid grid-cols-3 gap-2`,children:e.map(({url:e,text:n,icon:r})=>{let i=r?s[r]:null,a=e.startsWith(`http`),o=a?{target:`_blank`,rel:`noopener noreferrer`}:{},c=(0,f.jsxs)(f.Fragment,{children:[t&&i&&(0,f.jsx)(i,{size:14}),(0,f.jsx)(`span`,{className:`font-semibold tracking-wide text-md`,style:{fontVariant:`small-caps`},children:n}),(0,f.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 a?(0,f.jsx)(`a`,{href:e,...o,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:c},e):(0,f.jsx)(T.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:c},e)})})})}function mn(){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 hn(){let{sendMessage:e}=q(),[r,i]=(0,n.useState)(null),[a,o]=(0,n.useState)(null),[s,c]=(0,n.useState)(!1),[l,u]=(0,n.useState)({os:``});(0,n.useEffect)(()=>{if(localStorage.getItem(`showBackgroundArt`)===`false`)return;i(mn());let e=setInterval(()=>{let e=mn();o(e),c(!0),setTimeout(()=>{i(e),c(!1),o(null)},1e3)},2e4);return()=>clearInterval(e)},[]),(0,n.useEffect)(()=>{if(typeof window<`u`){let e=window.navigator.userAgent.toLowerCase();e.includes(`win`)?u({os:`Windows`}):e.includes(`mac`)?u({os:`MacOS`}):u({os:`Other`})}},[]);let d=e=>e.endsWith(`.webm`)||e.endsWith(`.mp4`),p=(e,t)=>d(e)?(0,f.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,f.jsx)(`img`,{src:e,alt:``,className:`absolute inset-0 w-full h-full object-cover transition-opacity duration-1000 ${t}`},e);return(0,f.jsxs)(`div`,{className:`relative min-h-screen w-full`,children:[(0,f.jsxs)(`div`,{className:`fixed inset-0 z-0`,children:[r&&p(r,s?`opacity-0`:`opacity-30`),a&&p(a,s?`opacity-30`:`opacity-0`),(0,f.jsx)(dn,{})]}),(0,f.jsx)(`div`,{className:`relative z-10`,children:(0,f.jsxs)(`div`,{className:`flex flex-col items-center justify-center min-h-screen max-w-screen-sm mx-auto p-2`,children:[(0,f.jsx)(`div`,{style:{height:`200px`,width:`100%`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:(0,f.jsx)(S.default,{autoRandomize:!0,onSphereClick:()=>console.log(`Sphere clicked`),className:`my-custom-class`})}),(0,f.jsxs)(`p`,{className:`text-lg text-gray-500 text-center justify-center mt-4`,children:[(0,f.jsx)(`a`,{"aria-label":`Chrome Web Store`,className:`download-chrome download-btn text-center justify-center`,target:`_blank`,href:t.researchAgentUIConfig.downloadChromeUrl}),(0,f.jsx)(`a`,{"aria-label":`Microsoft Store`,className:`download-windows download-btn text-center justify-center`,target:`_blank`,href:l.os==`Windows`?`ms-windows-store://pdp/?productid=${t.researchAgentUIConfig.downloadWindowsStoreId}`:`https://apps.microsoft.com/detail/${t.researchAgentUIConfig.downloadWindowsStoreId}?rtc=1`})]}),(0,f.jsxs)(`div`,{className:`w-full max-w-2xl mt-8 space-y-2`,children:[(0,f.jsx)(fn,{}),(0,f.jsx)(Ct,{})]})]})}),(0,f.jsx)(pn,{listFooterLinks:t.researchAgentUIConfig.footerLinks})]})}var gn=()=>(0,f.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,f.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,f.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 _n(){return(0,f.jsx)(`div`,{className:`flex min-h-screen flex-col items-center justify-center p-8`,children:(0,f.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,f.jsxs)(`div`,{className:`space-y-2`,children:[(0,f.jsx)(`h1`,{className:`text-2xl font-semibold text-black dark:text-white`,children:`⚠️ Configuration Required`}),(0,f.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,f.jsxs)(`div`,{className:`space-y-4`,children:[(0,f.jsx)(`h2`,{className:`text-lg font-medium text-black dark:text-white`,children:`Quick Setup:`}),(0,f.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,f.jsxs)(`div`,{className:`bg-black/5 dark:bg-white/5 rounded p-4`,children:[(0,f.jsx)(`p`,{className:`font-medium text-black dark:text-white mb-2`,children:`1. Create environment file:`}),(0,f.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,f.jsxs)(`div`,{className:`bg-black/5 dark:bg-white/5 rounded p-4`,children:[(0,f.jsx)(`p`,{className:`font-medium text-black dark:text-white mb-2`,children:`2. Add required variables:`}),(0,f.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
+ `),chatHistory:y.slice(-5),provider:`groq`}});if(t)throw Error(t.error||`Article QA failed`);let r=e?.content||``;N(r),b(e=>[...e,{role:`user`,content:C,time:new Date().toISOString()},{role:`assistant`,content:r,time:new Date().toISOString()}]);try{await(0,l.updateArticle)({body:{url:h,question:C,answer:r}})}catch(e){console.error(`Error storing Q&A in cache:`,e)}}else{let e=parseInt(localStorage.getItem(`maxFollowupQuestions`)||`4`),{data:t,error:r}=await(0,l.articleFollowups)({body:{article:n,chatHistory:y.slice(-5),maxQuestions:e,provider:`groq`}});if(r)throw Error(r.error||`Article followups failed`);let i=t?.extract||[];L(i);try{await(0,l.updateArticle)({body:{url:h,followUpQuestions:i}})}catch(e){console.error(`Error storing follow-up questions in cache:`,e)}}}catch(e){console.error(`Error calling language API:`,e),a(`Failed to get AI response`)}finally{i(!1)}},de=e=>{w(e),ue(`question`)},pe=async()=>{if(!_)return;let e=`${M}\n\n\n${_.cite||``}\n\n\n${_.html}`;try{await navigator.clipboard.writeText(e),S(!0),setTimeout(()=>S(!1),2e3)}catch(e){console.error(`Failed to copy to clipboard:`,e)}},me=()=>(0,f.jsxs)(`div`,{className:`flex h-full flex-col bg-background shadow-xl`,children:[(0,f.jsx)(Mt,{onClose:p}),(0,f.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:(0,f.jsxs)(`div`,{className:`p-4 space-y-6`,children:[(0,f.jsxs)(`div`,{className:`space-y-4`,children:[(0,f.jsx)(Ft,{isLoadingAI:D,isLoadingFollowups:k,isLoadingFavorite:V,isFavorited:z,isHighlightMode:U,onAskClick:()=>ue(`question`),onSuggestClick:()=>ue(`suggest-followups`),onCopyClick:pe,onFavoriteClick:q,onHighlightToggle:()=>te(!U)}),x&&(0,f.jsx)(`div`,{className:`bg-blue-500 text-white text-sm font-medium px-3 py-2 rounded-md shadow-lg`,children:`Copied!`}),(0,f.jsx)(It,{value:C,onChange:w,onSubmit:()=>ue(`question`)}),(0,f.jsx)(Lt,{questions:I,isLoading:k,error:R,onQuestionClick:de}),y.length>0&&(0,f.jsx)(`div`,{className:`space-y-4`,children:y.map((e,t)=>(0,f.jsx)(`div`,{className:`space-y-2`,children:e.role===`user`?(0,f.jsxs)(`div`,{className:`bg-primary/10 border border-primary/20 rounded-lg p-3`,children:[(0,f.jsx)(`div`,{className:`text-xs font-semibold text-primary mb-1`,children:`Your Question`}),(0,f.jsx)(`div`,{className:`text-sm text-foreground`,children:e.content})]}):(0,f.jsxs)(`div`,{className:`bg-muted rounded-lg shadow-md p-4`,children:[(0,f.jsx)(`div`,{className:`text-xs font-semibold text-muted-foreground mb-2`,children:`AI Response`}),(0,f.jsx)(`div`,{className:`text-sm`,dangerouslySetInnerHTML:{__html:e.content}})]})},t))}),(D||M&&y.length===0)&&(0,f.jsx)(Rt,{response:M,isLoading:D,error:P}),P&&!D&&(0,f.jsx)(`div`,{className:`bg-red-500 text-white p-2 rounded-md text-sm`,children:P})]}),_&&(0,f.jsx)(Bt,{article:_,isHighlightMode:U})]})})]});return!d||!se?null:W?(0,f.jsxs)(`div`,{className:`fixed top-0 right-0 h-screen z-40 transition-all duration-300`,style:{width:`${re}px`},children:[(0,f.jsx)(`div`,{ref:K,onMouseDown:()=>oe(!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,f.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`})}),me()]}):(0,f.jsx)(wt,{open:d,onOpenChange:e=>!e&&p(),children:(0,f.jsxs)(Ot,{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,f.jsx)(jt,{children:(0,f.jsx)(kt,{children:`Article Details`})}),(0,f.jsx)(`div`,{className:`h-full overflow-y-auto`,children:me()})]})})},Qt=()=>{let{sections:e,chatTurns:r,loading:i,messageAppeared:a,newChat:o,chatId:s}=q(),{isOpen:c,panelWidth:l}=j(),{isAuthenticated:u}=fe(),[d,p]=(0,n.useState)(!1),m=(0,n.useRef)(null),h=(0,n.useRef)(null),g=(0,n.useRef)(!1);return(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]),(0,f.jsxs)(f.Fragment,{children:[(0,f.jsxs)(`div`,{className:`flex flex-col min-h-full transition-all duration-300`,style:d&&c?{width:`calc(100% - ${l}px)`}:{},children:[(0,f.jsxs)(`div`,{className:`flex-1 flex flex-col space-y-3 pb-48 ${d&&!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,f.jsxs)(n.Fragment,{children:[(0,f.jsx)(qe,{section:t,sectionIndex:r,dividerRef:i?m:void 0,isLast:i}),!i&&(0,f.jsx)(`div`,{className:`h-px w-full bg-light-secondary dark:bg-dark-secondary`})]},t.userMessage.messageId)}),i&&!a&&(0,f.jsx)(`div`,{className:`flex items-center justify-center`,children:(0,f.jsx)(`div`,{style:{height:`200px`,width:`100%`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:(0,f.jsx)(S.default,{autoRandomize:!0,onSphereClick:()=>console.log(`Sphere clicked`),className:`my-custom-class`})})}),(0,f.jsx)(`div`,{ref:h,className:`h-0`})]}),(0,f.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,f.jsx)(Ct,{})})]}),(0,f.jsx)(Zt,{})]})};function $t({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=()=>{n.width=window.innerWidth,n.height=window.innerHeight};a();let l=()=>{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 a={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(a);let o=[];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&&o.push(n)}for(let e=o.length-1;e>=0;e--)c.current.splice(o[e],1);i.globalAlpha=1,requestAnimationFrame(l)},d=e=>{s.current.x=e.pageX,s.current.y=e.pageY},f=e=>{s.current.x=e.touches[0].pageX,s.current.y=e.touches[0].pageY};return window.addEventListener(`mousemove`,d),window.addEventListener(`touchmove`,f,{passive:!0}),window.addEventListener(`resize`,a),l(),()=>{window.removeEventListener(`mousemove`,d),window.removeEventListener(`touchmove`,f),window.removeEventListener(`resize`,a)}},[e,t,r,i,a]),(0,f.jsx)(`div`,{className:`relative w-full h-screen overflow-hidden pointer-events-none`,children:(0,f.jsx)(`canvas`,{ref:o,className:`absolute inset-0`,style:{background:`transparent`}})})}var en=`qwksearch_pinned_chats`;function tn(){if(typeof window>`u`)return[];try{let e=localStorage.getItem(en);return e?JSON.parse(e):[]}catch{return[]}}function nn(e){typeof window>`u`||localStorage.setItem(en,JSON.stringify(e))}function rn(){let[e,t]=(0,n.useState)([]),[r,i]=(0,n.useState)(!0),[a,o]=(0,n.useState)(!1),[s,c]=(0,n.useState)(null),[l,u]=(0,n.useState)(!1),[d,f]=(0,n.useState)(!1),[p,h]=(0,n.useState)(!1),[g,_]=(0,n.useState)([]),[v,y]=(0,n.useState)(``),[b,x]=(0,n.useState)([]),[S,C]=(0,n.useState)(!1),{isAuthenticated:w,isLoading:T}=fe(),{incognito:E,setIncognito:D}=q();(0,n.useEffect)(()=>{_(tn())},[]);let O=(0,n.useCallback)((e,t)=>{e.preventDefault(),e.stopPropagation(),_(e=>{let n=e.includes(t)?e.filter(e=>e!==t):[...e,t];return nn(n),n})},[]),k=(0,n.useMemo)(()=>[...e].sort((e,t)=>{let n=g.includes(e.id),r=g.includes(t.id);return n&&!r?-1:!n&&r?1:0}),[e,g]),A=(0,n.useMemo)(()=>v.trim()?b:k,[v,b,k]),j=(0,n.useCallback)(async()=>{if(!T){i(!0);try{if(w){let e=await fetch(`/api/agent/chats`,{credentials:`include`,headers:{"Content-Type":`application/json`}});if(e.status===401){let e=V().map(e=>({...e,messageCount:e.messages?.filter(e=>e.role===`user`).length??0}));t(e);return}if(!e.ok)throw Error(`HTTP ${e.status}: ${e.statusText}`);let n=await e.json();t(Array.isArray(n?.chats)?n.chats:[])}else{let e=V().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)}}},[w,T]);(0,n.useEffect)(()=>{j()},[j]);let M=(e,t)=>{e.preventDefault(),e.stopPropagation(),c(t),o(!0)},N=async()=>{if(s){u(!0);try{if(w){let e=await fetch(`/api/agent/chats/${s}`,{method:`DELETE`,credentials:`include`,headers:{"Content-Type":`application/json`}});if(!e.ok)throw Error(`HTTP ${e.status}: ${e.statusText}`)}else te(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),c(null),u(!1)}}},P=()=>{f(!0)},F=async()=>{h(!0);try{if(w){let e=await fetch(`/api/agent/chats`,{method:`DELETE`,credentials:`include`,headers:{"Content-Type":`application/json`}});if(!e.ok)throw Error(`HTTP ${e.status}: ${e.statusText}`)}else W();t([]),m.toast.success(`All history cleared`)}catch(e){m.toast.error(e.message||`Failed to clear history`)}finally{f(!1),h(!1)}},I=()=>{D(!E),m.toast.success(E?`Private mode off`:`Private mode on — messages won't be saved`)},L=(0,n.useCallback)(async e=>{if(!e.trim()){x([]),C(!1);return}C(!0);try{if(w){let t=await fetch(`/api/agent/chats/search?q=${encodeURIComponent(e)}`,{credentials:`include`,headers:{"Content-Type":`application/json`}});if(!t.ok)throw Error(`HTTP ${t.status}: ${t.statusText}`);let n=await t.json();x(Array.isArray(n?.chats)?n.chats:[])}else{let t=V().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});x(t.map(e=>({...e,messageCount:e.messages?.filter(e=>e.role===`user`).length??0})))}}catch(e){console.error(`Failed to search chat history:`,e),x([]),m.toast.error(`Failed to search chat history`)}finally{C(!1)}},[w]);return(0,n.useEffect)(()=>{let e=setTimeout(()=>{L(v)},300);return()=>clearTimeout(e)},[v,L]),{chats:e,sortedChats:k,displayChats:A,loading:r,pinnedIds:g,togglePin:O,incognito:E,toggleIncognito:I,searchQuery:v,searchResults:b,searching:S,handleSearchChange:(0,n.useCallback)(e=>{y(e)},[]),deleteDialogOpen:a,setDeleteDialogOpen:o,chatToDelete:s,setChatToDelete:c,deleting:l,handleDeleteClick:M,handleConfirmDelete:N,clearAllDialogOpen:d,setClearAllDialogOpen:f,clearingAll:p,handleClearAllClick:P,handleConfirmClearAll:F}}function an({incognito:e,onToggleIncognito:t,showClearAll:n,onClearAll:r,searchQuery:i,onSearchChange:a}){return(0,f.jsxs)(`div`,{className:`mb-2 pb-2 border-b border-border space-y-2`,children:[(0,f.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,f.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground/80 uppercase tracking-wide`,children:`Chat History`}),(0,f.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,f.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,f.jsx)(s.Lock,{size:12}),(0,f.jsx)(`span`,{children:`Private`})]}),n&&(0,f.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,f.jsx)(s.Trash2,{size:12}),(0,f.jsx)(`span`,{children:`Clear All`})]})]})]}),(0,f.jsxs)(`div`,{className:`relative`,children:[(0,f.jsx)(s.Search,{className:`absolute left-2 top-1/2 -translate-y-1/2 text-muted-foreground`,size:14}),(0,f.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,f.jsx)(`button`,{onClick:()=>a(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground`,children:(0,f.jsx)(s.X,{size:14})})]})]})}function on({chat:e,isPinned:t,onTogglePin:n,onDelete:r}){let i=e.messageCount??0;return(0,f.jsxs)(`div`,{className:`group flex items-center gap-1 px-2 py-1 rounded-lg hover:bg-secondary transition-colors duration-200`,children:[(0,f.jsxs)(T.default,{href:`/c/${e.id}`,className:`flex-1 min-w-0 flex items-center gap-1.5`,children:[(0,f.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0`,children:[i>0&&(0,f.jsxs)(Ge,{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:[i,`Q`]}),(0,f.jsx)(Ge,{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:O(new Date,e.createdAt)})]}),(0,f.jsxs)(`p`,{className:`text-xs text-popover-foreground truncate`,children:[t&&(0,f.jsx)(s.Pin,{size:10,className:`inline mr-1 text-primary`}),e.title]})]}),(0,f.jsx)(`button`,{onClick:t=>n(t,e.id),className:`p-1.5 rounded-lg transition-all duration-200 ${t?`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:t?`Unpin chat`:`Pin chat`,children:(0,f.jsx)(s.Pin,{size:14})}),(0,f.jsx)(`button`,{onClick:t=>r(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,f.jsx)(s.Trash,{size:14})})]})}function sn({open:e,onOpenChange:t,title:n,description:r,confirmLabel:i,loadingLabel:a,loading:o,onConfirm:s}){return(0,f.jsx)(wt,{open:e,onOpenChange:e=>{!e&&!o&&t(!1)},children:(0,f.jsxs)(Ot,{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,f.jsx)(kt,{className:`text-lg font-medium leading-6 dark:text-white`,children:n}),(0,f.jsx)(At,{className:`text-sm dark:text-white/70 text-black/70 mt-2`,children:r}),(0,f.jsxs)(`div`,{className:`flex flex-row items-end justify-end space-x-4 mt-6`,children:[(0,f.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,f.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 cn({deleteDialogOpen:e,setDeleteDialogOpen:t,chatToDelete:n,setChatToDelete:r,deleting:i,onConfirmDelete:a,clearAllDialogOpen:o,setClearAllDialogOpen:s,clearingAll:c,onConfirmClearAll:l}){return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(sn,{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,f.jsx)(sn,{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 ln={Today:(0,f.jsx)(s.Sun,{size:12}),Yesterday:(0,f.jsx)(s.Clock,{size:12}),"This Week":(0,f.jsx)(s.CalendarDays,{size:12}),Older:(0,f.jsx)(s.Archive,{size:12})};function un(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()-6*864e5),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 dn=({showLabel:e=!1})=>{let t=rn();return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsxs)(wt,{children:[(0,f.jsxs)(Tt,{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,f.jsx)(s.History,{size:e?14:18}),e&&(0,f.jsx)(`span`,{children:`History`})]}),(0,f.jsxs)(Ot,{className:`max-w-[420px] p-3`,children:[(0,f.jsx)(kt,{className:`sr-only`,children:`Chat History`}),(0,f.jsx)(an,{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,f.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,f.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,f.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,f.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,f.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,f.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No matching chats found.`})}):t.chats.length===0?(0,f.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,f.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No chats found.`})}):(0,f.jsx)(`div`,{className:`space-y-1 max-h-[500px] overflow-y-auto`,children:t.searchQuery.trim()?t.displayChats.map(e=>(0,f.jsx)(on,{chat:e,isPinned:t.pinnedIds.includes(e.id),onTogglePin:t.togglePin,onDelete:t.handleDeleteClick},e.id)):un(t.displayChats).map(({label:e,chats:n})=>(0,f.jsxs)(`div`,{children:[(0,f.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:[ln[e],e]}),n.map(e=>(0,f.jsx)(on,{chat:e,isPinned:t.pinnedIds.includes(e.id),onTogglePin:t.togglePin,onDelete:t.handleDeleteClick},e.id))]},e))}),t.chats.length>0&&(0,f.jsx)(`div`,{className:`mt-2 pt-2 border-t border-border`,children:(0,f.jsx)(T.default,{href:`/library`,className:`block text-center text-xs text-primary hover:underline`,children:`View all chats`})})]})]}),(0,f.jsx)(cn,{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})]})};function fn(){let{chats:e,loading:t}=rn(),n=[...e].sort((e,t)=>new Date(t.createdAt).getTime()-new Date(e.createdAt).getTime()).slice(0,3);return t?null:(0,f.jsxs)(`div`,{className:`flex flex-row items-center justify-center gap-2 flex-wrap`,children:[(0,f.jsx)(dn,{showLabel:!0}),n.map(e=>(0,f.jsx)(T.default,{href:`/c/${e.id}`,className:`px-3 py-1 rounded-full text-xs text-muted-foreground bg-secondary hover:bg-secondary/80 hover:text-foreground transition-colors duration-150 truncate max-w-[160px]`,title:e.title,children:e.title},e.id))]})}function pn({listFooterLinks:e=[],optionShowIcons:t=!0,optionBackgroundColor:n=`bg-black/40`}){return(0,f.jsx)(`div`,{className:`absolute bottom-2 left-1/2 -translate-x-1/2 text-slate-200 text-xs z-20 ${n} rounded-lg px-2 py-1 shadow-lg hover:shadow-xl hover:-translate-y-1 transition-all duration-300 flex flex-wrap items-center justify-center gap-x-6 max-w-[90vw]`,children:(0,f.jsx)(`div`,{className:`max-w-4xl mx-auto grid grid-cols-3 gap-2`,children:e.map(({url:e,text:n,icon:r})=>{let i=r?s[r]:null,a=e.startsWith(`http`),o=a?{target:`_blank`,rel:`noopener noreferrer`}:{},c=(0,f.jsxs)(f.Fragment,{children:[t&&i&&(0,f.jsx)(i,{size:14}),(0,f.jsx)(`span`,{className:`font-semibold tracking-wide text-md`,style:{fontVariant:`small-caps`},children:n}),(0,f.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 a?(0,f.jsx)(`a`,{href:e,...o,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:c},e):(0,f.jsx)(T.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:c},e)})})})}function mn(){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 hn(){let{sendMessage:e}=q(),[r,i]=(0,n.useState)(null),[a,o]=(0,n.useState)(null),[s,c]=(0,n.useState)(!1),[l,u]=(0,n.useState)({os:``});(0,n.useEffect)(()=>{if(localStorage.getItem(`showBackgroundArt`)===`false`)return;i(mn());let e=setInterval(()=>{let e=mn();o(e),c(!0),setTimeout(()=>{i(e),c(!1),o(null)},1e3)},2e4);return()=>clearInterval(e)},[]),(0,n.useEffect)(()=>{if(typeof window<`u`){let e=window.navigator.userAgent.toLowerCase();e.includes(`win`)?u({os:`Windows`}):e.includes(`mac`)?u({os:`MacOS`}):u({os:`Other`})}},[]);let d=e=>e.endsWith(`.webm`)||e.endsWith(`.mp4`),p=(e,t)=>d(e)?(0,f.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,f.jsx)(`img`,{src:e,alt:``,className:`absolute inset-0 w-full h-full object-cover transition-opacity duration-1000 ${t}`},e);return(0,f.jsxs)(`div`,{className:`relative min-h-screen w-full`,children:[(0,f.jsxs)(`div`,{className:`fixed inset-0 z-0`,children:[r&&p(r,s?`opacity-0`:`opacity-30`),a&&p(a,s?`opacity-30`:`opacity-0`),(0,f.jsx)($t,{})]}),(0,f.jsx)(`div`,{className:`relative z-10`,children:(0,f.jsxs)(`div`,{className:`flex flex-col items-center justify-center min-h-screen max-w-screen-sm mx-auto p-2`,children:[(0,f.jsx)(`div`,{style:{height:`200px`,width:`100%`,display:`flex`,alignItems:`center`,justifyContent:`center`},children:(0,f.jsx)(S.default,{autoRandomize:!0,onSphereClick:()=>console.log(`Sphere clicked`),className:`my-custom-class`})}),(0,f.jsxs)(`p`,{className:`text-lg text-gray-500 text-center justify-center mt-4`,children:[(0,f.jsx)(`a`,{"aria-label":`Chrome Web Store`,className:`download-chrome download-btn text-center justify-center`,target:`_blank`,href:t.researchAgentUIConfig.downloadChromeUrl}),(0,f.jsx)(`a`,{"aria-label":`Microsoft Store`,className:`download-windows download-btn text-center justify-center`,target:`_blank`,href:l.os==`Windows`?`ms-windows-store://pdp/?productid=${t.researchAgentUIConfig.downloadWindowsStoreId}`:`https://apps.microsoft.com/detail/${t.researchAgentUIConfig.downloadWindowsStoreId}?rtc=1`})]}),(0,f.jsxs)(`div`,{className:`w-full max-w-2xl mt-8 space-y-2`,children:[(0,f.jsx)(fn,{}),(0,f.jsx)(Ct,{})]})]})}),(0,f.jsx)(pn,{listFooterLinks:t.researchAgentUIConfig.footerLinks})]})}var gn=()=>(0,f.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,f.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,f.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 _n(){return(0,f.jsx)(`div`,{className:`flex min-h-screen flex-col items-center justify-center p-8`,children:(0,f.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,f.jsxs)(`div`,{className:`space-y-2`,children:[(0,f.jsx)(`h1`,{className:`text-2xl font-semibold text-black dark:text-white`,children:`⚠️ Configuration Required`}),(0,f.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,f.jsxs)(`div`,{className:`space-y-4`,children:[(0,f.jsx)(`h2`,{className:`text-lg font-medium text-black dark:text-white`,children:`Quick Setup:`}),(0,f.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,f.jsxs)(`div`,{className:`bg-black/5 dark:bg-white/5 rounded p-4`,children:[(0,f.jsx)(`p`,{className:`font-medium text-black dark:text-white mb-2`,children:`1. Create environment file:`}),(0,f.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,f.jsxs)(`div`,{className:`bg-black/5 dark:bg-white/5 rounded p-4`,children:[(0,f.jsx)(`p`,{className:`font-medium text-black dark:text-white mb-2`,children:`2. Add required variables:`}),(0,f.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
35
35
  DATABASE_URL=file:./data/qwksearch.db
36
36
 
37
37
  # Auth (generate: openssl rand -base64 32)
@@ -49,4 +49,4 @@ OPENAI_API_KEY=sk-your_key_here
49
49
  OPENAI_BASE_URL=https://api.openai.com/v1
50
50
 
51
51
  # Or Anthropic
52
- ANTHROPIC_API_KEY=sk-ant-your_key_here`})]}),(0,f.jsxs)(`div`,{className:`bg-black/5 dark:bg-white/5 rounded p-4`,children:[(0,f.jsx)(`p`,{className:`font-medium text-black dark:text-white mb-2`,children:`3. Restart the server`}),(0,f.jsx)(`code`,{className:`block bg-black/10 dark:bg-white/10 rounded p-2 text-xs`,children:`Ctrl+C, then: npm run dev`})]})]}),(0,f.jsxs)(`div`,{className:`pt-4 border-t border-black/10 dark:border-white/10`,children:[(0,f.jsx)(`h3`,{className:`font-medium text-black dark:text-white mb-2`,children:`Get API Keys:`}),(0,f.jsxs)(`ul`,{className:`space-y-2 text-sm text-black/70 dark:text-white/70`,children:[(0,f.jsxs)(`li`,{children:[(0,f.jsx)(`strong`,{children:`Groq`}),` (FREE): `,(0,f.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,f.jsxs)(`li`,{children:[(0,f.jsx)(`strong`,{children:`OpenAI`}),`: `,(0,f.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,f.jsxs)(`li`,{children:[(0,f.jsx)(`strong`,{children:`Anthropic`}),`: `,(0,f.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,f.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,f.jsx)(`code`,{children:`SETUP_INSTRUCTIONS.md`}),` in the project root for full details.`]})]})})}var vn=()=>{let e=(0,r.useRouter)(),{hasError:t,isReady:i,notFound:a,messages:o}=q(),{isAuthenticated:s}=fe();return(0,n.useEffect)(()=>{i&&a&&!s&&e.replace(`/`)},[i,a,s,e]),t?(0,f.jsx)(_n,{}):i&&a&&!s?(0,f.jsx)(`div`,{className:`flex flex-row items-center justify-center min-h-screen`,children:(0,f.jsx)(gn,{})}):i?a?(0,f.jsxs)(`div`,{className:`flex min-h-screen flex-col items-center justify-center gap-3 px-4 text-center`,children:[(0,f.jsx)(`p`,{className:`text-sm text-black/70 dark:text-white/70`,children:`This chat could not be found.`}),(0,f.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,f.jsx)(`div`,{children:o.length>0?(0,f.jsx)(f.Fragment,{children:(0,f.jsx)(un,{})}):(0,f.jsx)(hn,{})}):(0,f.jsx)(`div`,{className:`flex flex-row items-center justify-center min-h-screen`,children:(0,f.jsx)(gn,{})})};exports.ArticleAIResponse=Rt,exports.ArticleActionButtons=Ft,exports.ArticleContent=Bt,exports.ArticleFollowupQuestions=Lt,exports.ArticlePanelHeader=Mt,exports.ArticlePromptInput=It,exports.ChatProvider=pe,exports.ChatWindow=vn,exports.ExtractPanelProvider=M,exports.HistoryDialogs=on,exports.HistoryDropdown=ln,exports.LexicalArticleViewer=zt,exports.SessionProvider=de,exports.UnifiedMarkdown=Xt,exports.cn=D,exports.configureResearchAgentUI=t.configureResearchAgentUI,exports.formatTimeDifference=O,exports.researchAgentUIConfig=t.researchAgentUIConfig,exports.useChat=q,exports.useChatState=ce,exports.useExtractPanel=j,exports.useHistoryState=tn,exports.useSession=fe;
52
+ ANTHROPIC_API_KEY=sk-ant-your_key_here`})]}),(0,f.jsxs)(`div`,{className:`bg-black/5 dark:bg-white/5 rounded p-4`,children:[(0,f.jsx)(`p`,{className:`font-medium text-black dark:text-white mb-2`,children:`3. Restart the server`}),(0,f.jsx)(`code`,{className:`block bg-black/10 dark:bg-white/10 rounded p-2 text-xs`,children:`Ctrl+C, then: npm run dev`})]})]}),(0,f.jsxs)(`div`,{className:`pt-4 border-t border-black/10 dark:border-white/10`,children:[(0,f.jsx)(`h3`,{className:`font-medium text-black dark:text-white mb-2`,children:`Get API Keys:`}),(0,f.jsxs)(`ul`,{className:`space-y-2 text-sm text-black/70 dark:text-white/70`,children:[(0,f.jsxs)(`li`,{children:[(0,f.jsx)(`strong`,{children:`Groq`}),` (FREE): `,(0,f.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,f.jsxs)(`li`,{children:[(0,f.jsx)(`strong`,{children:`OpenAI`}),`: `,(0,f.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,f.jsxs)(`li`,{children:[(0,f.jsx)(`strong`,{children:`Anthropic`}),`: `,(0,f.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,f.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,f.jsx)(`code`,{children:`SETUP_INSTRUCTIONS.md`}),` in the project root for full details.`]})]})})}var vn=()=>{let e=(0,r.useRouter)(),{hasError:t,isReady:i,notFound:a,messages:o}=q(),{isAuthenticated:s}=fe();return(0,n.useEffect)(()=>{i&&a&&!s&&e.replace(`/`)},[i,a,s,e]),t?(0,f.jsx)(_n,{}):i&&a&&!s?(0,f.jsx)(`div`,{className:`flex flex-row items-center justify-center min-h-screen`,children:(0,f.jsx)(gn,{})}):i?a?(0,f.jsxs)(`div`,{className:`flex min-h-screen flex-col items-center justify-center gap-3 px-4 text-center`,children:[(0,f.jsx)(`p`,{className:`text-sm text-black/70 dark:text-white/70`,children:`This chat could not be found.`}),(0,f.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,f.jsx)(`div`,{children:o.length>0?(0,f.jsx)(f.Fragment,{children:(0,f.jsx)(Qt,{})}):(0,f.jsx)(hn,{})}):(0,f.jsx)(`div`,{className:`flex flex-row items-center justify-center min-h-screen`,children:(0,f.jsx)(gn,{})})};exports.ArticleAIResponse=Rt,exports.ArticleActionButtons=Ft,exports.ArticleContent=Bt,exports.ArticleFollowupQuestions=Lt,exports.ArticlePanelHeader=Mt,exports.ArticlePromptInput=It,exports.ChatProvider=pe,exports.ChatWindow=vn,exports.ExtractPanelProvider=M,exports.HistoryDialogs=cn,exports.HistoryDropdown=dn,exports.LexicalArticleViewer=zt,exports.SessionProvider=de,exports.UnifiedMarkdown=Xt,exports.cn=D,exports.configureResearchAgentUI=t.configureResearchAgentUI,exports.formatTimeDifference=O,exports.researchAgentUIConfig=t.researchAgentUIConfig,exports.useChat=q,exports.useChatState=ce,exports.useExtractPanel=j,exports.useHistoryState=rn,exports.useSession=fe;
package/dist/index.mjs CHANGED
@@ -484,7 +484,7 @@ function bt(e) {
484
484
  }
485
485
  function xt({ queries: e, loading: t }) {
486
486
  let n = e.filter((e) => e.status === "done").length, r = e.length, i = t && e.some((e) => e.status === "running");
487
- return /* @__PURE__ */ K("div", {
487
+ return t ? /* @__PURE__ */ K("div", {
488
488
  className: "rounded-xl border border-border bg-secondary/20 overflow-hidden text-sm",
489
489
  children: [/* @__PURE__ */ K("div", {
490
490
  className: "flex items-center justify-between px-3 py-2 border-b border-border/50",
@@ -519,7 +519,7 @@ function xt({ queries: e, loading: t }) {
519
519
  })]
520
520
  }, t))
521
521
  })]
522
- });
522
+ }) : null;
523
523
  }
524
524
  //#endregion
525
525
  //#region src/hooks/voice/useTextToVoice.ts
@@ -4951,28 +4951,147 @@ var Mr = (e) => {
4951
4951
  })]
4952
4952
  })
4953
4953
  });
4954
- }, Nr = "qwksearch_pinned_chats";
4955
- function Pr() {
4954
+ }, Nr = () => {
4955
+ let { sections: e, chatTurns: n, loading: r, messageAppeared: a, newChat: o, chatId: s } = X(), { isOpen: c, panelWidth: l } = ht(), { isAuthenticated: d } = Ut(), [m, h] = p(!1), g = f(null), _ = f(null), v = f(!1);
4956
+ return u(() => {
4957
+ let e = () => {
4958
+ h(window.innerWidth >= 1024);
4959
+ };
4960
+ return e(), window.addEventListener("resize", e), () => window.removeEventListener("resize", e);
4961
+ }, []), u(() => {
4962
+ if (n.length === 1 && (document.title = `${n[0].content.substring(0, 30)} - ${t.appName}`), n[n.length - 1]?.role === "user") {
4963
+ v.current = !0, _.current?.scrollIntoView({ behavior: "auto" }), setTimeout(() => {
4964
+ v.current = !1;
4965
+ }, 100);
4966
+ return;
4967
+ }
4968
+ }, [n]), /* @__PURE__ */ K(W, { children: [/* @__PURE__ */ K("div", {
4969
+ className: "flex flex-col min-h-full transition-all duration-300",
4970
+ style: m && c ? { width: `calc(100% - ${l}px)` } : {},
4971
+ children: [/* @__PURE__ */ K("div", {
4972
+ className: `flex-1 flex flex-col space-y-3 pb-48 ${m && !c ? "px-0 max-w-[800px] mx-auto w-full" : "px-4 lg:px-8"}`,
4973
+ children: [
4974
+ e.map((t, n) => {
4975
+ let r = n === e.length - 1;
4976
+ return /* @__PURE__ */ K(i, { children: [/* @__PURE__ */ G(On, {
4977
+ section: t,
4978
+ sectionIndex: n,
4979
+ dividerRef: r ? g : void 0,
4980
+ isLast: r
4981
+ }), !r && /* @__PURE__ */ G("div", { className: "h-px w-full bg-light-secondary dark:bg-dark-secondary" })] }, t.userMessage.messageId);
4982
+ }),
4983
+ r && !a && /* @__PURE__ */ G("div", {
4984
+ className: "flex items-center justify-center",
4985
+ children: /* @__PURE__ */ G("div", {
4986
+ style: {
4987
+ height: "200px",
4988
+ width: "100%",
4989
+ display: "flex",
4990
+ alignItems: "center",
4991
+ justifyContent: "center"
4992
+ },
4993
+ children: /* @__PURE__ */ G(st, {
4994
+ autoRandomize: !0,
4995
+ onSphereClick: () => console.log("Sphere clicked"),
4996
+ className: "my-custom-class"
4997
+ })
4998
+ })
4999
+ }),
5000
+ /* @__PURE__ */ G("div", {
5001
+ ref: _,
5002
+ className: "h-0"
5003
+ })
5004
+ ]
5005
+ }), /* @__PURE__ */ G("div", {
5006
+ className: "sticky bottom-[60px] md:bottom-0 z-40 bg-gradient-to-t from-background via-background to-transparent pt-4 pb-2",
5007
+ children: /* @__PURE__ */ G(ir, {})
5008
+ })]
5009
+ }), /* @__PURE__ */ G(Mr, {})] });
5010
+ };
5011
+ //#endregion
5012
+ //#region src/ui/gradient-blur.tsx
5013
+ function Pr({ radius: e = 60, opacityDecay: t = .025, backgroundColor: n = "transparent", color: r, colorGenerator: i }) {
5014
+ let a = f(null), o = f({
5015
+ x: 0,
5016
+ y: 0
5017
+ }), s = f([]), c = () => [
5018
+ Math.floor(Math.random() * 130 + 10),
5019
+ Math.floor(.5 * Math.random() * 50),
5020
+ Math.floor(.5 * Math.random() * 255)
5021
+ ], l = () => r || i?.() || c();
5022
+ return u(() => {
5023
+ let r = a.current;
5024
+ if (!r) return;
5025
+ let i = r.getContext("2d");
5026
+ if (!i) return;
5027
+ let c = () => {
5028
+ r.width = window.innerWidth, r.height = window.innerHeight;
5029
+ };
5030
+ c();
5031
+ let u = () => {
5032
+ i.globalCompositeOperation = "source-over", n === "transparent" ? i.clearRect(0, 0, r.width, r.height) : (i.fillStyle = n, i.fillRect(0, 0, r.width, r.height)), i.globalCompositeOperation = "lighter";
5033
+ let a = {
5034
+ col: l(),
5035
+ x: o.current.x,
5036
+ y: o.current.y,
5037
+ grdblur: i.createRadialGradient(o.current.x, o.current.y, 0, o.current.x, o.current.y, e),
5038
+ alpha: 1
5039
+ };
5040
+ s.current.push(a);
5041
+ let c = [];
5042
+ for (let n = 0; n < s.current.length; n++) {
5043
+ let r = s.current[n];
5044
+ 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 && c.push(n);
5045
+ }
5046
+ for (let e = c.length - 1; e >= 0; e--) s.current.splice(c[e], 1);
5047
+ i.globalAlpha = 1, requestAnimationFrame(u);
5048
+ }, d = (e) => {
5049
+ o.current.x = e.pageX, o.current.y = e.pageY;
5050
+ }, f = (e) => {
5051
+ o.current.x = e.touches[0].pageX, o.current.y = e.touches[0].pageY;
5052
+ };
5053
+ return window.addEventListener("mousemove", d), window.addEventListener("touchmove", f, { passive: !0 }), window.addEventListener("resize", c), u(), () => {
5054
+ window.removeEventListener("mousemove", d), window.removeEventListener("touchmove", f), window.removeEventListener("resize", c);
5055
+ };
5056
+ }, [
5057
+ e,
5058
+ t,
5059
+ n,
5060
+ r,
5061
+ i
5062
+ ]), /* @__PURE__ */ G("div", {
5063
+ className: "relative w-full h-screen overflow-hidden pointer-events-none",
5064
+ children: /* @__PURE__ */ G("canvas", {
5065
+ ref: a,
5066
+ className: "absolute inset-0",
5067
+ style: { background: "transparent" }
5068
+ })
5069
+ });
5070
+ }
5071
+ //#endregion
5072
+ //#region src/components/ChatHistoryDropdown/useHistoryState.ts
5073
+ var Fr = "qwksearch_pinned_chats";
5074
+ function Ir() {
4956
5075
  if (typeof window > "u") return [];
4957
5076
  try {
4958
- let e = localStorage.getItem(Nr);
5077
+ let e = localStorage.getItem(Fr);
4959
5078
  return e ? JSON.parse(e) : [];
4960
5079
  } catch {
4961
5080
  return [];
4962
5081
  }
4963
5082
  }
4964
- function Fr(e) {
4965
- typeof window > "u" || localStorage.setItem(Nr, JSON.stringify(e));
5083
+ function Lr(e) {
5084
+ typeof window > "u" || localStorage.setItem(Fr, JSON.stringify(e));
4966
5085
  }
4967
- function Ir() {
5086
+ function Rr() {
4968
5087
  let [e, t] = p([]), [n, r] = p(!0), [i, a] = p(!1), [o, s] = p(null), [l, f] = p(!1), [m, h] = p(!1), [g, _] = p(!1), [v, y] = p([]), [b, x] = p(""), [S, C] = p([]), [w, T] = p(!1), { isAuthenticated: E, isLoading: D } = Ut(), { incognito: O, setIncognito: k } = X();
4969
5088
  u(() => {
4970
- y(Pr());
5089
+ y(Ir());
4971
5090
  }, []);
4972
5091
  let A = c((e, t) => {
4973
5092
  e.preventDefault(), e.stopPropagation(), y((e) => {
4974
5093
  let n = e.includes(t) ? e.filter((e) => e !== t) : [...e, t];
4975
- return Fr(n), n;
5094
+ return Lr(n), n;
4976
5095
  });
4977
5096
  }, []), j = d(() => [...e].sort((e, t) => {
4978
5097
  let n = v.includes(e.id), r = v.includes(t.id);
@@ -5127,7 +5246,7 @@ function Ir() {
5127
5246
  }
5128
5247
  //#endregion
5129
5248
  //#region src/components/ChatHistoryDropdown/HistoryHeader.tsx
5130
- function Lr({ incognito: e, onToggleIncognito: t, showClearAll: n, onClearAll: r, searchQuery: i, onSearchChange: a }) {
5249
+ function zr({ incognito: e, onToggleIncognito: t, showClearAll: n, onClearAll: r, searchQuery: i, onSearchChange: a }) {
5131
5250
  return /* @__PURE__ */ K("div", {
5132
5251
  className: "mb-2 pb-2 border-b border-border space-y-2",
5133
5252
  children: [/* @__PURE__ */ K("div", {
@@ -5174,7 +5293,7 @@ function Lr({ incognito: e, onToggleIncognito: t, showClearAll: n, onClearAll: r
5174
5293
  }
5175
5294
  //#endregion
5176
5295
  //#region src/components/ChatHistoryDropdown/HistoryChatItem.tsx
5177
- function Rr({ chat: e, isPinned: t, onTogglePin: n, onDelete: r }) {
5296
+ function Br({ chat: e, isPinned: t, onTogglePin: n, onDelete: r }) {
5178
5297
  let i = e.messageCount ?? 0;
5179
5298
  return /* @__PURE__ */ K("div", {
5180
5299
  className: "group flex items-center gap-1 px-2 py-1 rounded-lg hover:bg-secondary transition-colors duration-200",
@@ -5216,7 +5335,7 @@ function Rr({ chat: e, isPinned: t, onTogglePin: n, onDelete: r }) {
5216
5335
  }
5217
5336
  //#endregion
5218
5337
  //#region src/components/ChatHistoryDropdown/HistoryDialogs.tsx
5219
- function zr({ open: e, onOpenChange: t, title: n, description: r, confirmLabel: i, loadingLabel: a, loading: o, onConfirm: s }) {
5338
+ function Vr({ open: e, onOpenChange: t, title: n, description: r, confirmLabel: i, loadingLabel: a, loading: o, onConfirm: s }) {
5220
5339
  return /* @__PURE__ */ G(ar, {
5221
5340
  open: e,
5222
5341
  onOpenChange: (e) => {
@@ -5252,8 +5371,8 @@ function zr({ open: e, onOpenChange: t, title: n, description: r, confirmLabel:
5252
5371
  })
5253
5372
  });
5254
5373
  }
5255
- function Br({ deleteDialogOpen: e, setDeleteDialogOpen: t, chatToDelete: n, setChatToDelete: r, deleting: i, onConfirmDelete: a, clearAllDialogOpen: o, setClearAllDialogOpen: s, clearingAll: c, onConfirmClearAll: l }) {
5256
- return /* @__PURE__ */ K(W, { children: [/* @__PURE__ */ G(zr, {
5374
+ function Hr({ deleteDialogOpen: e, setDeleteDialogOpen: t, chatToDelete: n, setChatToDelete: r, deleting: i, onConfirmDelete: a, clearAllDialogOpen: o, setClearAllDialogOpen: s, clearingAll: c, onConfirmClearAll: l }) {
5375
+ return /* @__PURE__ */ K(W, { children: [/* @__PURE__ */ G(Vr, {
5257
5376
  open: e,
5258
5377
  onOpenChange: (e) => {
5259
5378
  t(e), e || r(null);
@@ -5264,7 +5383,7 @@ function Br({ deleteDialogOpen: e, setDeleteDialogOpen: t, chatToDelete: n, setC
5264
5383
  loadingLabel: "Deleting...",
5265
5384
  loading: i,
5266
5385
  onConfirm: a
5267
- }), /* @__PURE__ */ G(zr, {
5386
+ }), /* @__PURE__ */ G(Vr, {
5268
5387
  open: o,
5269
5388
  onOpenChange: s,
5270
5389
  title: "Clear All History",
@@ -5277,13 +5396,13 @@ function Br({ deleteDialogOpen: e, setDeleteDialogOpen: t, chatToDelete: n, setC
5277
5396
  }
5278
5397
  //#endregion
5279
5398
  //#region src/components/ChatHistoryDropdown/HistoryDropdown.tsx
5280
- var Vr = {
5399
+ var Ur = {
5281
5400
  Today: /* @__PURE__ */ G(Te, { size: 12 }),
5282
5401
  Yesterday: /* @__PURE__ */ G(I, { size: 12 }),
5283
5402
  "This Week": /* @__PURE__ */ G(D, { size: 12 }),
5284
5403
  Older: /* @__PURE__ */ G(x, { size: 12 })
5285
5404
  };
5286
- function Hr(e) {
5405
+ function Wr(e) {
5287
5406
  let t = /* @__PURE__ */ new Date(), n = new Date(t.getFullYear(), t.getMonth(), t.getDate()), r = /* @__PURE__ */ new Date(n.getTime() - 864e5), i = /* @__PURE__ */ new Date(n.getTime() - 6 * 864e5), a = {
5288
5407
  Today: [],
5289
5408
  Yesterday: [],
@@ -5304,8 +5423,8 @@ function Hr(e) {
5304
5423
  chats: a[e]
5305
5424
  }));
5306
5425
  }
5307
- var Ur = ({ showLabel: e = !1 }) => {
5308
- let t = Ir();
5426
+ var Gr = ({ showLabel: e = !1 }) => {
5427
+ let t = Rr();
5309
5428
  return /* @__PURE__ */ K(W, { children: [/* @__PURE__ */ K(ar, { children: [/* @__PURE__ */ K(or, {
5310
5429
  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",
5311
5430
  children: [/* @__PURE__ */ G(ce, { size: e ? 14 : 18 }), e && /* @__PURE__ */ G("span", { children: "History" })]
@@ -5316,7 +5435,7 @@ var Ur = ({ showLabel: e = !1 }) => {
5316
5435
  className: "sr-only",
5317
5436
  children: "Chat History"
5318
5437
  }),
5319
- /* @__PURE__ */ G(Lr, {
5438
+ /* @__PURE__ */ G(zr, {
5320
5439
  incognito: t.incognito,
5321
5440
  onToggleIncognito: t.toggleIncognito,
5322
5441
  showClearAll: t.chats.length > 0 && !t.loading,
@@ -5354,15 +5473,15 @@ var Ur = ({ showLabel: e = !1 }) => {
5354
5473
  })
5355
5474
  }) : /* @__PURE__ */ G("div", {
5356
5475
  className: "space-y-1 max-h-[500px] overflow-y-auto",
5357
- children: t.searchQuery.trim() ? t.displayChats.map((e) => /* @__PURE__ */ G(Rr, {
5476
+ children: t.searchQuery.trim() ? t.displayChats.map((e) => /* @__PURE__ */ G(Br, {
5358
5477
  chat: e,
5359
5478
  isPinned: t.pinnedIds.includes(e.id),
5360
5479
  onTogglePin: t.togglePin,
5361
5480
  onDelete: t.handleDeleteClick
5362
- }, e.id)) : Hr(t.displayChats).map(({ label: e, chats: n }) => /* @__PURE__ */ K("div", { children: [/* @__PURE__ */ K("div", {
5481
+ }, e.id)) : Wr(t.displayChats).map(({ label: e, chats: n }) => /* @__PURE__ */ K("div", { children: [/* @__PURE__ */ K("div", {
5363
5482
  className: "flex items-center gap-1.5 px-3 py-1.5 text-xs font-semibold text-muted-foreground/70 uppercase tracking-wider",
5364
- children: [Vr[e], e]
5365
- }), n.map((e) => /* @__PURE__ */ G(Rr, {
5483
+ children: [Ur[e], e]
5484
+ }), n.map((e) => /* @__PURE__ */ G(Br, {
5366
5485
  chat: e,
5367
5486
  isPinned: t.pinnedIds.includes(e.id),
5368
5487
  onTogglePin: t.togglePin,
@@ -5378,7 +5497,7 @@ var Ur = ({ showLabel: e = !1 }) => {
5378
5497
  })
5379
5498
  })
5380
5499
  ]
5381
- })] }), /* @__PURE__ */ G(Br, {
5500
+ })] }), /* @__PURE__ */ G(Hr, {
5382
5501
  deleteDialogOpen: t.deleteDialogOpen,
5383
5502
  setDeleteDialogOpen: t.setDeleteDialogOpen,
5384
5503
  chatToDelete: t.chatToDelete,
@@ -5390,140 +5509,14 @@ var Ur = ({ showLabel: e = !1 }) => {
5390
5509
  clearingAll: t.clearingAll,
5391
5510
  onConfirmClearAll: t.handleConfirmClearAll
5392
5511
  })] });
5393
- }, Wr = () => {
5394
- let { sections: e, chatTurns: n, loading: r, messageAppeared: a, newChat: o, chatId: s } = X(), { isOpen: c, panelWidth: l } = ht(), { isAuthenticated: d } = Ut(), [m, h] = p(!1), g = f(null), _ = f(null), v = f(!1);
5395
- u(() => {
5396
- let e = () => {
5397
- h(window.innerWidth >= 1024);
5398
- };
5399
- return e(), window.addEventListener("resize", e), () => window.removeEventListener("resize", e);
5400
- }, []), u(() => {
5401
- if (n.length === 1 && (document.title = `${n[0].content.substring(0, 30)} - ${t.appName}`), n[n.length - 1]?.role === "user") {
5402
- v.current = !0, _.current?.scrollIntoView({ behavior: "auto" }), setTimeout(() => {
5403
- v.current = !1;
5404
- }, 100);
5405
- return;
5406
- }
5407
- }, [n]);
5408
- let y = m && c ? { width: `calc(100% - ${l}px)` } : {};
5409
- return /* @__PURE__ */ K(W, { children: [
5410
- /* @__PURE__ */ G("div", {
5411
- className: "fixed top-0 z-50 flex items-center gap-1 px-4 py-3 transition-all duration-300",
5412
- style: { right: m && c ? `${l}px` : "0" },
5413
- children: /* @__PURE__ */ G(Ur, {})
5414
- }),
5415
- /* @__PURE__ */ K("div", {
5416
- className: "flex flex-col min-h-full transition-all duration-300",
5417
- style: y,
5418
- children: [/* @__PURE__ */ K("div", {
5419
- className: `flex-1 flex flex-col space-y-3 pb-48 ${m && !c ? "px-0 max-w-[800px] mx-auto w-full" : "px-4 lg:px-8"}`,
5420
- children: [
5421
- e.map((t, n) => {
5422
- let r = n === e.length - 1;
5423
- return /* @__PURE__ */ K(i, { children: [/* @__PURE__ */ G(On, {
5424
- section: t,
5425
- sectionIndex: n,
5426
- dividerRef: r ? g : void 0,
5427
- isLast: r
5428
- }), !r && /* @__PURE__ */ G("div", { className: "h-px w-full bg-light-secondary dark:bg-dark-secondary" })] }, t.userMessage.messageId);
5429
- }),
5430
- r && !a && /* @__PURE__ */ G("div", {
5431
- className: "flex items-center justify-center",
5432
- children: /* @__PURE__ */ G("div", {
5433
- style: {
5434
- height: "200px",
5435
- width: "100%",
5436
- display: "flex",
5437
- alignItems: "center",
5438
- justifyContent: "center"
5439
- },
5440
- children: /* @__PURE__ */ G(st, {
5441
- autoRandomize: !0,
5442
- onSphereClick: () => console.log("Sphere clicked"),
5443
- className: "my-custom-class"
5444
- })
5445
- })
5446
- }),
5447
- /* @__PURE__ */ G("div", {
5448
- ref: _,
5449
- className: "h-0"
5450
- })
5451
- ]
5452
- }), /* @__PURE__ */ G("div", {
5453
- className: "sticky bottom-[60px] md:bottom-0 z-40 bg-gradient-to-t from-background via-background to-transparent pt-4 pb-2",
5454
- children: /* @__PURE__ */ G(ir, {})
5455
- })]
5456
- }),
5457
- /* @__PURE__ */ G(Mr, {})
5458
- ] });
5459
5512
  };
5460
5513
  //#endregion
5461
- //#region src/ui/gradient-blur.tsx
5462
- function Gr({ radius: e = 60, opacityDecay: t = .025, backgroundColor: n = "transparent", color: r, colorGenerator: i }) {
5463
- let a = f(null), o = f({
5464
- x: 0,
5465
- y: 0
5466
- }), s = f([]), c = () => [
5467
- Math.floor(Math.random() * 130 + 10),
5468
- Math.floor(.5 * Math.random() * 50),
5469
- Math.floor(.5 * Math.random() * 255)
5470
- ], l = () => r || i?.() || c();
5471
- return u(() => {
5472
- let r = a.current;
5473
- if (!r) return;
5474
- let i = r.getContext("2d");
5475
- if (!i) return;
5476
- let c = () => {
5477
- r.width = window.innerWidth, r.height = window.innerHeight;
5478
- };
5479
- c();
5480
- let u = () => {
5481
- i.globalCompositeOperation = "source-over", n === "transparent" ? i.clearRect(0, 0, r.width, r.height) : (i.fillStyle = n, i.fillRect(0, 0, r.width, r.height)), i.globalCompositeOperation = "lighter";
5482
- let a = {
5483
- col: l(),
5484
- x: o.current.x,
5485
- y: o.current.y,
5486
- grdblur: i.createRadialGradient(o.current.x, o.current.y, 0, o.current.x, o.current.y, e),
5487
- alpha: 1
5488
- };
5489
- s.current.push(a);
5490
- let c = [];
5491
- for (let n = 0; n < s.current.length; n++) {
5492
- let r = s.current[n];
5493
- 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 && c.push(n);
5494
- }
5495
- for (let e = c.length - 1; e >= 0; e--) s.current.splice(c[e], 1);
5496
- i.globalAlpha = 1, requestAnimationFrame(u);
5497
- }, d = (e) => {
5498
- o.current.x = e.pageX, o.current.y = e.pageY;
5499
- }, f = (e) => {
5500
- o.current.x = e.touches[0].pageX, o.current.y = e.touches[0].pageY;
5501
- };
5502
- return window.addEventListener("mousemove", d), window.addEventListener("touchmove", f, { passive: !0 }), window.addEventListener("resize", c), u(), () => {
5503
- window.removeEventListener("mousemove", d), window.removeEventListener("touchmove", f), window.removeEventListener("resize", c);
5504
- };
5505
- }, [
5506
- e,
5507
- t,
5508
- n,
5509
- r,
5510
- i
5511
- ]), /* @__PURE__ */ G("div", {
5512
- className: "relative w-full h-screen overflow-hidden pointer-events-none",
5513
- children: /* @__PURE__ */ G("canvas", {
5514
- ref: a,
5515
- className: "absolute inset-0",
5516
- style: { background: "transparent" }
5517
- })
5518
- });
5519
- }
5520
- //#endregion
5521
5514
  //#region src/components/ChatConversation/RecentHistoryChips.tsx
5522
5515
  function Kr() {
5523
- let { chats: e, loading: t } = Ir(), n = [...e].sort((e, t) => new Date(t.createdAt).getTime() - new Date(e.createdAt).getTime()).slice(0, 3);
5516
+ let { chats: e, loading: t } = Rr(), n = [...e].sort((e, t) => new Date(t.createdAt).getTime() - new Date(e.createdAt).getTime()).slice(0, 3);
5524
5517
  return t ? null : /* @__PURE__ */ K("div", {
5525
5518
  className: "flex flex-row items-center justify-center gap-2 flex-wrap",
5526
- children: [/* @__PURE__ */ G(Ur, { showLabel: !0 }), n.map((e) => /* @__PURE__ */ G(ut, {
5519
+ children: [/* @__PURE__ */ G(Gr, { showLabel: !0 }), n.map((e) => /* @__PURE__ */ G(ut, {
5527
5520
  href: `/c/${e.id}`,
5528
5521
  className: "px-3 py-1 rounded-full text-xs text-muted-foreground bg-secondary hover:bg-secondary/80 hover:text-foreground transition-colors duration-150 truncate max-w-[160px]",
5529
5522
  title: e.title,
@@ -5611,7 +5604,7 @@ function Yr() {
5611
5604
  children: [
5612
5605
  n && f(n, o ? "opacity-0" : "opacity-30"),
5613
5606
  i && f(i, o ? "opacity-30" : "opacity-0"),
5614
- /* @__PURE__ */ G(Gr, {})
5607
+ /* @__PURE__ */ G(Pr, {})
5615
5608
  ]
5616
5609
  }),
5617
5610
  /* @__PURE__ */ G("div", {
@@ -5817,10 +5810,10 @@ var Qr = () => {
5817
5810
  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",
5818
5811
  children: "Go Home"
5819
5812
  })]
5820
- }) : /* @__PURE__ */ G("div", { children: i.length > 0 ? /* @__PURE__ */ G(W, { children: /* @__PURE__ */ G(Wr, {}) }) : /* @__PURE__ */ G(Yr, {}) }) : /* @__PURE__ */ G("div", {
5813
+ }) : /* @__PURE__ */ G("div", { children: i.length > 0 ? /* @__PURE__ */ G(W, { children: /* @__PURE__ */ G(Nr, {}) }) : /* @__PURE__ */ G(Yr, {}) }) : /* @__PURE__ */ G("div", {
5821
5814
  className: "flex flex-row items-center justify-center min-h-screen",
5822
5815
  children: /* @__PURE__ */ G(Xr, {})
5823
5816
  });
5824
5817
  };
5825
5818
  //#endregion
5826
- export { yr as ArticleAIResponse, gr as ArticleActionButtons, xr as ArticleContent, vr as ArticleFollowupQuestions, pr as ArticlePanelHeader, _r as ArticlePromptInput, Wt as ChatProvider, Qr as ChatWindow, gt as ExtractPanelProvider, Br as HistoryDialogs, Ur as HistoryDropdown, br as LexicalArticleViewer, Ht as SessionProvider, jr as UnifiedMarkdown, Y as cn, e as configureResearchAgentUI, ft as formatTimeDifference, t as researchAgentUIConfig, X as useChat, zt as useChatState, ht as useExtractPanel, Ir as useHistoryState, Ut as useSession };
5819
+ export { yr as ArticleAIResponse, gr as ArticleActionButtons, xr as ArticleContent, vr as ArticleFollowupQuestions, pr as ArticlePanelHeader, _r as ArticlePromptInput, Wt as ChatProvider, Qr as ChatWindow, gt as ExtractPanelProvider, Hr as HistoryDialogs, Gr as HistoryDropdown, br as LexicalArticleViewer, Ht as SessionProvider, jr as UnifiedMarkdown, Y as cn, e as configureResearchAgentUI, ft as formatTimeDifference, t as researchAgentUIConfig, X as useChat, zt as useChatState, ht as useExtractPanel, Rr as useHistoryState, Ut as useSession };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "research-agent-ui",
3
3
  "description": "Chat research agent UI: conversation window, article reader, search config, file uploads, and chat history",
4
- "version": "0.1.10",
4
+ "version": "0.1.11",
5
5
  "author": "vtempest",
6
6
  "repository": {
7
7
  "type": "git",
@@ -60,16 +60,16 @@
60
60
  "@radix-ui/react-slot": "^1.2.5",
61
61
  "@radix-ui/react-tooltip": "^1.2.9",
62
62
  "@ricky0123/vad-web": "^0.0.30",
63
- "chat-agent-toolkit": "^1.2.28",
64
- "domain-rank": "^0.1.17",
63
+ "chat-agent-toolkit": "^1.2.29",
64
+ "domain-rank": "^0.1.18",
65
65
  "drizzle-orm": "^0.45.2",
66
66
  "fuse.js": "^7.1.0",
67
67
  "class-variance-authority": "^0.7.1",
68
68
  "clsx": "^2.1.1",
69
69
  "dompurify": "^3.4.9",
70
- "extract-webpage": "^1.2.30",
70
+ "extract-webpage": "^1.2.31",
71
71
  "framer-motion": "^12.40.0",
72
- "qwksearch-api-client": "^0.0.22",
72
+ "qwksearch-api-client": "^0.0.23",
73
73
  "html2canvas": "^1.4.1",
74
74
  "lucide-react": "^1.17.0",
75
75
  "markdown-to-jsx": "^9.8.2",