Spaces:
Running
Running
File size: 46,065 Bytes
6ed5ced | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | import{d as ut,j as e,L as K,i as c,X as Vt,n as Zt,b as Z,o as Qe,q as Jt,C as Se,r as me,a as es,s as ts,t as pt,v as Rt,w as mt,l as ss,x as Xe,e as os,f as ns,y as qe,k as as,z as it,B as At,D as is,g as ft,E as rs,F as ls}from"./index-BASp1Jlg.js";import{S as $t,U as cs,t as ds}from"./taskIcons-CioPx4GI.js";import{c as Mt,d as Ot,a as us,t as fe,h as ps,F as hs,e as Bt,f as Ht,g as Ut,b as ms,i as zt,u as fs,j as gs,k as ws,l as Ve,m as xs,n as bs,o as js,p as ys,q as gt,v as st,w as Ge,x as vs,y as ks}from"./researchTopic-EcV81Yhu.js";import{P as le}from"./plus-CVmfXvuq.js";import{d as Te,t as Ns}from"./transform-DhU91To3.js";import{A as Kt}from"./arrow-right-38Jlsj5C.js";import{C as Ss,P as qt,u as Ts,a as Cs,b as Fs,D as ot,q as _s,c as Es,d as Ls,i as Ps,e as Ds,A as Is,f as Rs,S as xe,g as As}from"./index-RY-JbNzf.js";import{D as $s,a as Ms,b as Os}from"./dialog-B6TxG4et.js";import{S as Bs}from"./switch-BNLdCfup.js";import{T as Hs,a as Us,b as wt,c as xt}from"./tabs-DkCbqcY5.js";import{u as zs}from"./useDebounce-DWrCqwFE.js";import{T as Ks}from"./trash-2-Bqm24T_F.js";import{U as qs}from"./undo-2-DYDt0Ktb.js";import{A as Gs}from"./arrow-up-right-CU37Swce.js";import{c as Ws,h as Ys}from"./colors-BkWRhvFI.js";import{b as Qs,u as Xs,a as Vs,c as Zs,P as Js}from"./usePapers-C2R45kwJ.js";import{M as eo}from"./McpShowcase-CE9dCqp6.js";import{c as to}from"./chat-CX2NZ81t.js";import{S as bt}from"./skeleton-CX3VRuwp.js";import{A as We,a as Ye}from"./alert-TcODKBfp.js";import{u as so}from"./useDocumentTitle-CMM05SJc.js";import{H as oo}from"./pageTitles-Bh_-lk2I.js";import"./search-YB9HB-wG.js";import"./triangle-alert-CY0vyiZI.js";import"./share-2-BzPDfiIY.js";import"./trending-up-DNwBPAkn.js";import"./moon-DCQQ31LV.js";import"./thumbs-up-CZdkIxIJ.js";import"./database-CkzQMAnd.js";import"./link-2-Ct3NReEP.js";import"./trophy-CEbxwKxa.js";import"./file-text-DZZy1wIH.js";import"./activity-Bl2LDq2s.js";import"./globe-CYbzSeri.js";import"./useMutation-xugMiFBh.js";import"./index-D9FIGwYR.js";import"./PaperCard-CzBTorCo.js";import"./AuthorAvatar-BAJQT_MK.js";import"./SotaBadges-BA1Qj0d3.js";import"./Icon-BcUEVdYy.js";import"./LatexTitle-Bn8J4lXx.js";import"./safeExternalHref-CkBrsh84.js";import"./popover-BTdJz23k.js";import"./useIntersectionObserver-hY-0DhOW.js";import"./useInfiniteQuery-BTPNq34r.js";import"./AgentLogos-BeJ1dOob.js";/**
* @license lucide-react v0.462.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const no=ut("Building2",[["path",{d:"M6 22V4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2v18Z",key:"1b4qmf"}],["path",{d:"M6 12H4a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h2",key:"i71pzd"}],["path",{d:"M18 9h2a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2h-2",key:"10jefs"}],["path",{d:"M10 6h4",key:"1itunk"}],["path",{d:"M10 10h4",key:"tcdvrf"}],["path",{d:"M10 14h4",key:"kelpxr"}],["path",{d:"M10 18h4",key:"1ulq68"}]]);/**
* @license lucide-react v0.462.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const ao=ut("GripVertical",[["circle",{cx:"9",cy:"12",r:"1",key:"1vctgf"}],["circle",{cx:"9",cy:"5",r:"1",key:"hp0tcf"}],["circle",{cx:"9",cy:"19",r:"1",key:"fkjjf6"}],["circle",{cx:"15",cy:"12",r:"1",key:"1tmaij"}],["circle",{cx:"15",cy:"5",r:"1",key:"19l28e"}],["circle",{cx:"15",cy:"19",r:"1",key:"f4zoj3"}]]);/**
* @license lucide-react v0.462.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const io=ut("User",[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]]);function ro({onBuild:t}){return e.jsxs("section",{className:"following-intro","aria-labelledby":"following-intro-title",children:[e.jsx("h2",{id:"following-intro-title",children:"Build your personal research feed"}),e.jsx("p",{className:"following-intro-lead",children:"Describe topics in your own words, or follow the tasks, benchmarks, authors, and organizations you care about, and this page collects their latest papers and results in one place."}),t&&e.jsxs("button",{type:"button",className:"research-topic-save following-intro-topic",onClick:t,children:[e.jsx($t,{"aria-hidden":"true"}),"Build your feed"]}),e.jsxs("p",{className:"following-intro-note",children:["Matching papers also arrive as a weekly email, which you can turn off in"," ",e.jsx(K,{to:"/settings",children:"Settings"}),"."]})]})}const Gt="pwc:home-follow-card:dismissed",lo=[{kind:"method",id:1004,name:"Recursive Self-Improvement"},{kind:"topic",id:23,name:"OCR releases"},{kind:"topic",id:51,name:"Small language models (<4B)"},{kind:"task",id:862,name:"Auto-Research"},{kind:"method",id:1048,name:"Decision Models"},{kind:"task",id:438,name:"Deep Research Agents"}];function co(){try{return localStorage.getItem(Gt)==="1"}catch{return!1}}function uo({onBuild:t}){const s=Mt(),o=Ot(),[u,a]=c.useState(co);if(u)return null;const y=()=>{try{localStorage.setItem(Gt,"1")}catch{}a(!0)},S=p=>p.kind==="topic"?s.follow(p.id):o.follow(p.kind,p.id,p.name);return e.jsxs("section",{className:"home-follow-card","aria-labelledby":"home-follow-card-title",children:[e.jsx("button",{type:"button",className:"home-follow-card-close","aria-label":"Dismiss",onClick:y,children:e.jsx(Vt,{"aria-hidden":"true"})}),e.jsx("h2",{id:"home-follow-card-title",children:"Get a feed for your research"}),e.jsx("p",{children:"Follow topics, tasks, authors and labs, and their new papers collect on your following page and in a weekly email."}),e.jsx("div",{className:"topic-dialog-chips home-follow-card-topics",children:lo.map(p=>e.jsxs("button",{type:"button",className:"topic-dialog-chip","aria-pressed":"false",disabled:s.finishing||o.pending,onClick:()=>S(p),children:[e.jsx(le,{"aria-hidden":"true"}),p.name]},`${p.kind}:${p.id}`))}),(s.failed||o.failed)&&e.jsx("p",{className:"home-follow-card-error",role:"alert",children:"Could not follow that. Please try again."}),e.jsxs("button",{type:"button",className:"research-topic-save",onClick:t,children:[e.jsx($t,{"aria-hidden":"true"}),"Build your feed"]})]})}function rt({topic:t,action:s,newTab:o=!1,showCreator:u=!1,kindLabel:a,as:y="li",className:S}){var p;return e.jsx(Wt,{title:fe(t),href:us(t),kindLabel:a,creator:u?(p=t.creator)==null?void 0:p.username:void 0,followers:t.followers,avatars:t.follower_avatars??[],weekPapers:t.week_papers,paper:t.top_paper,action:s,newTab:o,as:y,className:S})}function Wt({title:t,href:s,kindLabel:o,creator:u,followers:a,avatars:y,weekPapers:S,paper:p,action:x,newTab:L=!1,as:I="li",className:R}){return e.jsxs(I,{className:["home-topic-card",R].filter(Boolean).join(" "),children:[o&&e.jsx("span",{className:"home-topic-kind",children:o}),e.jsx(jt,{to:s,newTab:L,className:"home-topic-title",children:t}),u&&e.jsxs("div",{className:"home-topic-creator",children:["by @",u]}),a!=null&&e.jsxs("div",{className:"home-topic-followers",children:[y.length>0&&e.jsx("span",{className:"home-topic-avatars","aria-hidden":"true",children:y.map(E=>e.jsx(po,{person:E},E.username))}),a," ",a===1?"follower":"followers"]}),!!S&&e.jsxs("div",{className:"home-topic-meta",children:[S," new ",S===1?"paper":"papers"," this week"]}),p&&e.jsx(jt,{to:`/paper/${p.arxiv_id||p.id}`,newTab:L,className:"home-topic-paper",title:p.title,children:p.title}),x]})}function jt({to:t,newTab:s,className:o,title:u,children:a}){return s?e.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:o,title:u,children:a}):e.jsx(K,{to:t,className:o,title:u,children:a})}function po({person:t}){const[s,o]=c.useState(!1);return s?e.jsx("span",{className:"topic-avatar home-topic-avatar-initial",children:t.username.charAt(0).toUpperCase()}):e.jsx("img",{className:"topic-avatar",src:Zt(t.avatar_url)??void 0,alt:"",width:20,height:20,loading:"lazy",onError:()=>o(!0)})}const yt={topic:"Topic",task:"Task",method:"Method"},vt={task:0,method:1,topic:2},nt=t=>`${t.kind}:${t.entity_id}`;function ho({followedIds:t,followedKeys:s,onBuild:o}){const u=Z(me.featuredTopics()),a=Z(me.popularFollows()),{follow:y,finishing:S,failed:p}=Mt(),x=Ot(),L=ps(u.data??[]).slice(0,hs),I=[...(a.data??[]).map(i=>({kind:i.kind,follow:i,followers:i.followers})),...L.map(i=>({kind:"topic",topic:i,followers:i.followers}))].sort((i,h)=>h.followers-i.followers||vt[i.kind]-vt[h.kind]),R=i=>x.follow(i.kind,i.entity_id,i.kind==="task"?Te(i.name):i.name),E=((t==null?void 0:t.size)??0)>=Qe,g=c.useRef(null),[k,A]=c.useState({start:!0,end:!0});c.useEffect(()=>{const i=g.current;if(!i)return;const h=()=>A({start:i.scrollLeft<=1,end:i.scrollLeft+i.clientWidth>=i.scrollWidth-1});return h(),i.addEventListener("scroll",h,{passive:!0}),window.addEventListener("resize",h),()=>{i.removeEventListener("scroll",h),window.removeEventListener("resize",h)}},[I.length]);const w=i=>{const h=g.current;if(!h)return;const O=parseFloat(getComputedStyle(h).columnGap)||0;h.scrollBy({left:i*(h.clientWidth+O),behavior:"smooth"})};if(I.length===0)return null;function q(i){return t?t.has(i.id)?e.jsxs(K,{to:`/following?topic=${i.id}`,className:"home-topic-follow is-following",children:[e.jsx(Se,{"aria-hidden":"true"}),"Following"]}):e.jsxs("button",{type:"button",className:"home-topic-follow",disabled:S||x.pending||E,title:E?`You follow ${Qe} topics, the most allowed. Remove one to add another.`:void 0,onClick:()=>y(i.id),"aria-label":`Follow ${fe(i)}`,children:[e.jsx(le,{"aria-hidden":"true"}),"Follow"]}):e.jsxs("span",{className:"home-topic-follow is-pending","aria-hidden":"true",children:[e.jsx(le,{}),"Follow"]})}function $(i){return s?s.has(nt(i))?e.jsxs(K,{to:`/following?follow=${nt(i)}`,className:"home-topic-follow is-following",children:[e.jsx(Se,{"aria-hidden":"true"}),"Following"]}):e.jsxs("button",{type:"button",className:"home-topic-follow",disabled:S||x.pending,onClick:()=>R(i),"aria-label":`Follow ${i.kind==="task"?Te(i.name):i.name}`,children:[e.jsx(le,{"aria-hidden":"true"}),"Follow"]}):e.jsxs("span",{className:"home-topic-follow is-pending","aria-hidden":"true",children:[e.jsx(le,{}),"Follow"]})}return e.jsxs("section",{className:"home-topics","aria-labelledby":"home-topics-title",children:[e.jsxs("div",{className:"home-topics-header",children:[e.jsxs("h2",{id:"home-topics-title",children:[e.jsx(cs,{"aria-hidden":"true"}),"Most followed"]}),e.jsxs("div",{className:"home-topics-actions",children:[e.jsxs("button",{type:"button",className:"home-topics-own",onClick:o,children:["Create your own topic",e.jsx(Kt,{"aria-hidden":"true"})]}),!(k.start&&k.end)&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"home-topics-page","aria-label":"Previous cards",disabled:k.start,onClick:()=>w(-1),children:e.jsx(Ss,{"aria-hidden":"true"})}),e.jsx("button",{type:"button",className:"home-topics-page","aria-label":"More cards",disabled:k.end,onClick:()=>w(1),children:e.jsx(Jt,{"aria-hidden":"true"})})]})]})]}),e.jsx("ul",{ref:g,className:"home-topics-list is-scroller",children:I.map(i=>i.kind==="topic"?e.jsx(rt,{topic:i.topic,kindLabel:yt.topic,action:q(i.topic)},`topic:${i.topic.id}`):e.jsx(Wt,{title:i.kind==="task"?Te(i.follow.name):i.follow.name,href:i.follow.url,kindLabel:yt[i.kind],followers:i.follow.followers,avatars:i.follow.follower_avatars,weekPapers:i.follow.week_papers,paper:i.follow.top_paper,action:$(i.follow)},nt(i.follow)))}),(p||x.failed)&&e.jsx("p",{className:"home-topics-error",role:"alert",children:"Could not follow that. Please try again."})]})}const lt=180,kt=`transform ${lt}ms cubic-bezier(0.2, 0, 0, 1), box-shadow ${lt}ms ease`,Nt=()=>{var t;return((t=window.matchMedia)==null?void 0:t.call(window,"(prefers-reduced-motion: reduce)").matches)??!1};function mo(t){const s=getComputedStyle(t).transform.match(/matrix(3d)?\(([^)]+)\)/);if(!s)return{x:0,y:0};const o=s[2].split(",").map(Number);return s[1]?{x:o[12]||0,y:o[13]||0}:{x:o[4]||0,y:o[5]||0}}function fo({items:t,itemKey:s,itemLabel:o,onReorder:u,renderItem:a,className:y,disabled:S=!1,grid:p=!1}){const[x,L]=c.useState(null),[I,R]=c.useState(null),[E,g]=c.useState(null),k=c.useRef(new Map),A=c.useRef(new Map),w=c.useRef({x:0,y:0,grabX:0,grabY:0}),q=(x==null?void 0:x.order)??((E==null?void 0:E.from)===t?E.order:t),$=(F,f)=>F.length===f.length&&F.every((d,b)=>s(d)===s(f[b])),i=(F,f)=>p?`translate(${F}px, ${f}px)`:`translateY(${f}px)`,h=F=>{F.style.transition="none";const{x:f,y:d,grabX:b,grabY:N}=w.current;F.style.transform=i(f-b-F.offsetLeft,d-N-F.offsetTop)};c.useLayoutEffect(()=>{const F=!Nt();k.current.forEach((f,d)=>{const b={x:f.offsetLeft,y:f.offsetTop},N=A.current.get(d);if(A.current.set(d,b),d===(x==null?void 0:x.key))return h(f);if(!F||N===void 0||N.x===b.x&&N.y===b.y)return;const m=mo(f);f.style.transition="none",f.style.transform=i(N.x+m.x-b.x,N.y+m.y-b.y),f.offsetHeight,f.style.transition=kt,f.style.transform=""})});const O=c.useRef({items:t,onReorder:u,drag:x});O.current={items:t,onReorder:u,drag:x};const J=x!==null;c.useEffect(()=>{if(!J)return;const F=N=>{var B;w.current.x=N.clientX,w.current.y=N.clientY;const m=(B=O.current.drag)==null?void 0:B.key,_=m===void 0?void 0:k.current.get(m);_&&h(_);const M=w.current.y-w.current.grabY+((_==null?void 0:_.offsetHeight)??0)/2,U=w.current.x-w.current.grabX+((_==null?void 0:_.offsetWidth)??0)/2,ce=(T,se)=>p?T.offsetTop+T.offsetHeight<M?!0:T.offsetTop>M?!1:T.offsetLeft<=U&&U<=T.offsetLeft+T.offsetWidth?se:T.offsetLeft+T.offsetWidth/2<U:T.offsetTop+T.offsetHeight/2<M;L(T=>{if(!T)return T;const se=T.order.findIndex(C=>s(C)===T.key),de=T.order[se],ne=T.order.filter(C=>s(C)!==T.key),X=ne.filter(C=>{const ae=k.current.get(s(C));return ae?ce(ae,T.order.indexOf(C)>se):!1}).length,G=[...ne.slice(0,X),de,...ne.slice(X)];return $(G,T.order)?T:{...T,order:G}})},f=N=>{const{drag:m,items:_,onReorder:M}=O.current,U=m?k.current.get(m.key):void 0;if(U&&m){const ce=!Nt();U.style.transition=ce?kt:"none",U.style.transform="",ce&&(R(m.key),window.setTimeout(()=>R(B=>B===m.key?null:B),lt))}N&&m&&!$(m.order,_)&&(g({from:_,order:m.order}),M(m.order)),L(null)},d=()=>f(!0),b=()=>f(!1);return window.addEventListener("pointermove",F),window.addEventListener("pointerup",d),window.addEventListener("pointercancel",b),()=>{window.removeEventListener("pointermove",F),window.removeEventListener("pointerup",d),window.removeEventListener("pointercancel",b)}},[J]);const Q=(F,f)=>{const d=t.findIndex(m=>s(m)===F),b=d+f;if(b<0||b>=t.length)return;const N=[...t];N.splice(b,0,...N.splice(d,1)),g({from:t,order:N}),u(N)};return e.jsx("ul",{className:["sortable-list",y].filter(Boolean).join(" "),children:q.map(F=>{const f=s(F),d=(x==null?void 0:x.key)===f,b=d||I===f,N=e.jsx("button",{type:"button",className:"sortable-handle",disabled:S||t.length<2,"aria-label":`Reorder ${o(F)}. Use the ${p?"arrow":"up and down arrow"} keys to move it.`,onPointerDown:m=>{if(m.button!==0)return;m.preventDefault();const _=k.current.get(f);w.current={x:m.clientX,y:m.clientY,grabX:m.clientX-((_==null?void 0:_.offsetLeft)??0),grabY:m.clientY-((_==null?void 0:_.offsetTop)??0)},L({key:f,order:t})},onKeyDown:m=>{const M=(p?{ArrowUp:-1,ArrowDown:1,ArrowLeft:-1,ArrowRight:1}:{ArrowUp:-1,ArrowDown:1})[m.key];M&&(m.preventDefault(),Q(f,M))},children:e.jsx(ao,{"aria-hidden":"true"})});return e.jsx("li",{className:b?"sortable-item is-dragging":"sortable-item",ref:m=>{m?k.current.set(f,m):k.current.delete(f)},children:a(F,N,d)},f)})})}const Ze="pwcTopicDialog";function go(t){window.history.replaceState({...window.history.state,[Ze]:t},"")}function wo(){var t;return((t=window.history.state)==null?void 0:t[Ze])??null}function xo(){var s;if(!((s=window.history.state)!=null&&s[Ze]))return;const t={...window.history.state};delete t[Ze],window.history.replaceState(t,"")}const St=16,bo=6;function jo({open:t,topicId:s=null,afterSavePath:o,restore:u,onOpenChange:a}){return e.jsx($s,{open:t,onOpenChange:a,children:e.jsx(Ms,{className:"topic-dialog","aria-describedby":void 0,children:e.jsx(yo,{topicId:s,afterSavePath:o,restore:u,onDone:()=>a(!1)},s??"new")})})}function Tt({to:t,name:s}){return e.jsx(K,{className:"topic-dialog-chip-open",to:t,"aria-label":`Open the ${s} page`,title:"Open its page",children:e.jsx(Gs,{"aria-hidden":"true"})})}function yo({topicId:t,afterSavePath:s,restore:o,onDone:u}){var $e,Me,Oe,Be,l,j,Y,oe,ze;const{user:a}=es(),y=ts(),S=pt(),p=Rt(),x=Bt(),L=Ht(),I=Z(Xe.trendingTasks({limit:St,level:0})),R=Z(Xe.trendingMethods({limit:St})),E=Z(me.followSuggestions()),g=Z(me.featuredTopics()),k=(n=[])=>n.map(r=>({id:String(r.entity_id),name:r.name,image:r.image_url,url:r.url})),[A,w]=c.useState(o?o.editId:t),[q,$]=c.useState((o==null?void 0:o.draft)??null),[i,h]=c.useState((o==null?void 0:o.selection)??[]),[O,J]=c.useState((o==null?void 0:o.removals)??[]),[Q,F]=c.useState((o==null?void 0:o.topicFollows)??[]),[f,d]=c.useState((o==null?void 0:o.order)??null),[b,N]=c.useState((o==null?void 0:o.privacy)??{}),[m,_]=c.useState((o==null?void 0:o.tab)??"topics"),M=c.useRef(null),U=c.useRef((o==null?void 0:o.scrollTop)??0);c.useLayoutEffect(()=>{var r;const n=(r=M.current)==null?void 0:r.closest(".topic-dialog");!U.current||!n||n.scrollHeight-n.clientHeight<U.current||(n.scrollTop=U.current,U.current=0)});const ce=n=>{var v,D;const r=n.target.closest("a");!r||r.target==="_blank"||n.button!==0||n.metaKey||n.ctrlKey||n.shiftKey||n.altKey||new URL(r.href,window.location.href).origin!==window.location.origin||go({topicId:t,editId:A,draft:q,selection:i,removals:O,topicFollows:Q,order:f,privacy:b,tab:m,scrollTop:((D=(v=M.current)==null?void 0:v.closest(".topic-dialog"))==null?void 0:D.scrollTop)??0})},B=Ut(),T=ms(),se=zt(),de=fs(),ne=gs(),X=ws(),G=x.data??[],C=G.find(n=>n.id===A),ae=zs(Ft(q??(C==null?void 0:C.text)??"").toLowerCase()),Ce=Z({...me.topicMatches(ae),enabled:ae.length>=3}),ge=(f==null?void 0:f.length)===G.length&&f.every(n=>G.some(r=>r.id===n.id)),be=f&&ge?f:G,Fe=be.some((n,r)=>{var v;return n.id!==((v=G[r])==null?void 0:v.id)}),ee=O.filter(n=>G.some(r=>r.id===n)),_e=Object.entries(b).map(([n,r])=>({id:Number(n),isPublic:r})).filter(({id:n,isPublic:r})=>!ee.includes(n)&&G.some(v=>v.id===n&&v.is_creator&&v.is_public!==r)),Ee=(g.data??[]).filter(n=>!G.some(r=>r.id===n.id)).slice(0,bo),H=Q.filter(n=>Ee.some(r=>r.id===n)),we=(C==null?void 0:C.text)??"",je=q??we,z=Ft(je),ie=ae===z.toLowerCase()&&!Ce.isFetching?Ce.data??[]:[],ue=Ve(B.error)&&(($e=B.variables)==null?void 0:$e.text)===z?B.error:null,ye=(C==null?void 0:C.status)==="failed"&&z===we,Le=G.length-ee.length+H.length>=Qe,re=z.length>=3&&(z!==we||ye)&&!ie.length&&(C?!ee.includes(C.id):!Le),[et,tt]=c.useState(!1),ve=c.useRef(!0);c.useEffect(()=>(ve.current=!0,()=>{ve.current=!1}),[]);const W=B.isPending||T.isPending||se.isPending||de.isPending||ne.isPending||X.isPending||et,ke=(n,r)=>{var v;return((v=L.data)==null?void 0:v.some(D=>D.kind===n&&String(D.entity_id)===r))??!1},Ne=(n,r)=>{var v;return((v=i.find(D=>D.kind===n&&D.id===r))==null?void 0:v.follow)??ke(n,r)},te=i.filter(n=>n.follow!==ke(n.kind,n.id)),Ue=ee.length+H.length+_e.length+(Fe?1:0),Pe=!W&&(re||te.length>0||Ue>0),De=(n,r,v)=>h(D=>[...D.filter(he=>he.kind!==n||he.id!==r),{kind:n,id:r,name:v,follow:!Ne(n,r)}]),Ie=n=>{w(n),$(null)},Re=()=>{if(!Pe)return;if(!a){re&&xs(z),te.length&&bs(te),H.length&&js(H),window.location.href=ss(s??`${y.pathname}${y.search}`);return}const n=ee.length?T.mutateAsync(ee):Promise.resolve(),r=be.filter(V=>!ee.includes(V.id)),v=n.catch(()=>{}).then(()=>Fe?ne.mutateAsync(r):void 0),D=v.catch(()=>{}),he=[...te.length?[se.mutateAsync(te)]:[],n,v,..._e.map(V=>X.mutateAsync(V)),...re?[D.then(()=>B.mutateAsync({id:C==null?void 0:C.id,text:z}))]:[],...H.map(V=>D.then(()=>de.mutateAsync(V)))];Promise.allSettled(he).then(async V=>{if(V.every(P=>P.status==="fulfilled")){if(s){if(tt(!0),await Promise.all([p.refetchQueries({queryKey:me.follows(a.hf_subject).queryKey}),p.refetchQueries({queryKey:me.topics(a.hf_subject).queryKey})]),!ve.current)return;u(),S(s);return}u()}})},pe=(n,r,v,D)=>{const V=[...(L.data??[]).filter(P=>P.kind===r).map(P=>({id:String(P.entity_id),name:P.name,slug:P.url.split("/").pop(),image:P.image_url,url:P.url})),...v.filter(P=>!ke(r,P.id)).map(P=>({...P,suggested:!0}))];return V.length>0&&e.jsxs("div",{className:"topic-dialog-group",children:[e.jsx("h3",{children:n}),e.jsxs(vo,{children:[V.map(P=>{const ht=Ne(r,P.id),Ke=r==="task"?Te(P.name,P.slug??void 0):P.name,Xt=P.url??`/${r==="task"?"tasks":"methods"}/${P.slug??P.id}`;return e.jsxs("span",{className:"topic-dialog-chip-wrap","data-suggested":"suggested"in P||void 0,children:[e.jsxs("button",{type:"button",className:"topic-dialog-chip","aria-pressed":ht,disabled:W,onClick:()=>De(r,P.id,Ke),children:[ht?e.jsx(Se,{"aria-hidden":"true"}):e.jsx(le,{"aria-hidden":"true"}),(r==="author"||r==="organization")&&e.jsx(ko,{kind:r,name:Ke,src:P.image}),Ke]}),e.jsx(Tt,{to:Xt,name:Ke})]},P.id)}),D&&e.jsxs(K,{to:D.to,className:"topic-dialog-browse",children:[D.label,e.jsx(Kt,{"aria-hidden":"true"})]})]})]})},Ae=C?b[C.id]??C.is_public:!0;return e.jsxs("form",{ref:M,className:"topic-dialog-form",onClickCapture:ce,onSubmit:n=>{n.preventDefault(),Re()},children:[e.jsx(Os,{className:"topic-dialog-title",children:(Me=x.data)!=null&&Me.length||(Oe=L.data)!=null&&Oe.length?"Edit your research feed":"Build your research feed"}),e.jsxs(Hs,{value:m,onValueChange:_,className:"topic-dialog-tabs",children:[e.jsxs(Us,{className:"topic-dialog-tab-list",children:[e.jsxs(wt,{value:"topics",className:"topic-dialog-tab",children:["Topics",e.jsx(Ct,{count:H.length+ee.length})]}),e.jsxs(wt,{value:"catalog",className:"topic-dialog-tab",children:["Tasks, methods & more",e.jsx(Ct,{count:te.length})]})]}),e.jsxs(xt,{value:"topics",className:"topic-dialog-panel",children:[e.jsxs("div",{className:"topic-dialog-group",children:[e.jsx("h3",{children:e.jsx("label",{htmlFor:"topic-dialog-input",children:C?`Reword β${fe(C)}β`:(Be=x.data)!=null&&Be.length?"Add a topic in your own words":"Describe a topic in your own words"})}),e.jsx("p",{className:"topic-dialog-hint",children:!C&&Le?`You follow ${Qe} topics, the most allowed. Remove one below to add another.`:e.jsxs(e.Fragment,{children:["A model reads every new paper and adds the ones that match to your ",e.jsx(K,{to:"/following",className:"topic-dialog-feed-link",onClick:u,children:"Following feed"}),". New topics are public and show your Hugging Face username; make one private from its β button below, or remove one with its trash button."]})}),e.jsx("textarea",{id:"topic-dialog-input",className:"research-topic-input",rows:4,maxLength:mt,"aria-label":"Research topic",placeholder:"e.g. diffusion policies for robot manipulation, or speculative decoding for LLM inference",value:je,onChange:n=>$(n.target.value),onKeyDown:n=>{n.key==="Enter"&&!n.shiftKey&&!n.nativeEvent.isComposing&&(n.preventDefault(),Re())}}),e.jsxs("span",{className:"research-topic-count",children:[je.length,"/",mt]}),ie.length>0&&e.jsxs("div",{className:"topic-dialog-duplicate",role:"status",children:[e.jsxs("p",{children:["Papers with Code already has ",ie.length>1?"pages":`a ${ie[0].kind} page`," for β",z,"β. Follow ",ie.length>1?"one":"it"," instead of adding a topic:"]}),e.jsx("div",{className:"topic-dialog-chips",children:ie.map(n=>{const r=String(n.entity_id),v=Ne(n.kind,r);return e.jsxs("span",{className:"topic-dialog-chip-wrap",children:[e.jsxs("button",{type:"button",className:"topic-dialog-chip","aria-pressed":v,disabled:W,onClick:()=>De(n.kind,r,n.name),children:[v?e.jsx(Se,{"aria-hidden":"true"}):e.jsx(le,{"aria-hidden":"true"}),n.name]}),e.jsx(Tt,{to:n.url,name:n.name})]},`${n.kind}:${r}`)})})]}),C&&e.jsxs("div",{className:"topic-dialog-editing",children:[C.is_creator&&e.jsxs("label",{className:"topic-dialog-privacy",children:[e.jsx(Bs,{checked:Ae,disabled:W,"aria-label":"Public topic",onCheckedChange:n=>N(r=>({...r,[C.id]:n}))}),Ae?"Public: anyone can find and follow it":"Private: only you see it"]}),e.jsx("button",{type:"button",className:"link-button",disabled:W,onClick:()=>Ie(null),children:"Add a new topic instead"})]})]}),G.length>0&&e.jsxs("div",{className:"topic-dialog-group",children:[e.jsx("h3",{children:"Your topics"}),e.jsx(fo,{className:"home-topics-list topic-dialog-topic-cards",grid:!0,items:be,itemKey:n=>n.id,itemLabel:n=>fe(n),disabled:W,onReorder:d,renderItem:(n,r)=>{const v=!O.includes(n.id),D=fe(n),he=()=>J(V=>v?[...V,n.id]:V.filter(P=>P!==n.id));return e.jsx(rt,{as:"div",topic:n,showCreator:!0,className:`topic-dialog-own-topic ${n.id===A?"is-editing":""} ${v?"":"is-removed"}`,action:e.jsxs("div",{className:"topic-dialog-card-actions",children:[e.jsxs("button",{type:"button",className:`home-topic-follow ${v?"is-following":""}`,"aria-pressed":v,"aria-label":D,title:v?"Remove from your feed on Save":"Keep this topic",disabled:W,onClick:he,children:[v?e.jsx(Se,{"aria-hidden":"true"}):e.jsx(le,{"aria-hidden":"true"}),v?"Following":"Follow"]}),e.jsx("button",{type:"button",className:"topic-dialog-chip-open",disabled:W||n.id===A,"aria-label":`Reword ${D}`,title:"Reword this topic",onClick:()=>Ie(n.id),children:e.jsx(qt,{"aria-hidden":"true"})}),e.jsx("button",{type:"button",className:"topic-dialog-chip-open topic-dialog-chip-remove",disabled:W,"aria-label":v?`Remove ${D}`:`Keep ${D}`,title:v?"Remove from your feed on Save":"Keep this topic",onClick:he,children:v?e.jsx(Ks,{"aria-hidden":"true"}):e.jsx(qs,{"aria-hidden":"true"})}),e.jsx("span",{className:"topic-dialog-card-handle",children:r})]})})}})]}),Ee.length>0&&e.jsxs("div",{className:"topic-dialog-group",children:[e.jsx("h3",{children:"Popular topics"}),e.jsx("ul",{className:"home-topics-list topic-dialog-topic-cards",children:Ee.map(n=>{const r=Q.includes(n.id);return e.jsx(rt,{topic:n,showCreator:!0,action:e.jsxs("button",{type:"button",className:`home-topic-follow ${r?"is-following":""}`,"aria-pressed":r,"aria-label":`Follow ${fe(n)}`,disabled:W||!r&&Le,onClick:()=>F(v=>r?v.filter(D=>D!==n.id):[...v,n.id]),children:[r?e.jsx(Se,{"aria-hidden":"true"}):e.jsx(le,{"aria-hidden":"true"}),r?"Following":"Follow"]})},n.id)})})]})]}),e.jsxs(xt,{value:"catalog",className:"topic-dialog-panel",children:[pe("Trending tasks","task",((l=I.data)==null?void 0:l.results)??[],{to:"/tasks",label:"Browse tasks"}),pe("Trending methods","method",((j=R.data)==null?void 0:j.results)??[],{to:"/methods",label:"Browse methods"}),pe("Popular benchmarks","benchmark",k((Y=E.data)==null?void 0:Y.benchmarks),{to:"/tasks",label:"Browse benchmarks"}),pe("Popular authors","author",k((oe=E.data)==null?void 0:oe.authors)),pe("Popular organizations","organization",k((ze=E.data)==null?void 0:ze.organizations),{to:"/organizations",label:"Browse organizations"})]})]}),ue&&e.jsxs("p",{className:"settings-token-error",role:"alert",children:[ue.message,"."]}),(B.error&&!Ve(B.error)||T.error||se.error||de.error||ne.error||X.error)&&e.jsx("p",{className:"settings-token-error",role:"alert",children:"Could not save your feed. Please try again."}),e.jsxs("div",{className:"topic-dialog-actions",children:[e.jsx("button",{type:"button",className:"research-follow-action",disabled:W,onClick:u,children:"Cancel"}),e.jsx("button",{type:"submit",className:"research-topic-save",disabled:!Pe,children:te.some(n=>n.follow===!1)||ee.length||Fe||_e.length?"Save":te.length||H.length?"Follow":ye?"Retry":C?"Update topic":"Follow"})]})]})}function Ct({count:t}){return t>0?e.jsx("span",{className:"topic-dialog-tab-count","aria-label":`${t} unsaved`,children:t}):null}function vo({children:t}){const s=c.useRef(null);return c.useLayoutEffect(()=>{const o=s.current;if(!o)return;const u=()=>{const a=[...o.children],y=a.filter(p=>p.dataset.suggested);y.forEach(p=>{p.hidden=!1});const S=()=>new Set(a.filter(p=>!p.hidden).map(p=>p.offsetTop)).size;for(let p=y.length-1;p>=0&&S()>2;p--)y[p].hidden=!0};return u(),window.addEventListener("resize",u),()=>window.removeEventListener("resize",u)}),e.jsx("div",{ref:s,className:"topic-dialog-chips",children:t})}function ko({kind:t,name:s,src:o}){const[u,a]=c.useState(!1);if(o&&!u)return e.jsx("img",{className:`topic-dialog-chip-image is-${t}`,src:o,alt:"",loading:"lazy",onError:()=>a(!0)});if(t!=="author")return null;const y=s.split(/\s+/).filter(Boolean).map(S=>S[0]).slice(0,2).join("").toUpperCase();return e.jsx("span",{className:"topic-dialog-chip-image is-author is-initials","aria-hidden":"true",children:y})}const Ft=t=>t.trim().replace(/\s+/g," "),_t=12,Et=["organization","author","task","method","benchmark"],No={task:"Task",method:"Method",benchmark:"Benchmark",author:"Author",organization:"Organization"},So={topicIds:[],follows:[]},at=t=>`${t.kind}:${t.entity_id}`;function To(t){return[...t].sort((s,o)=>Et.indexOf(s.kind)-Et.indexOf(o.kind)||o.created_at.localeCompare(s.created_at))}function Co({follow:t}){if(t.kind==="task"){const s=t.url.split("/").pop()??"",o=ds(s,t.parent_slug??void 0);return e.jsx(o,{size:14,strokeWidth:2,"aria-hidden":"true",style:{color:Ws(Ys(s)).dot}})}if(t.kind==="author"||t.kind==="organization"){if(t.image_url)return e.jsx("img",{src:t.image_url,alt:"",width:18,height:18,loading:"lazy"});const s=t.kind==="author"?io:no;return e.jsx(s,{size:14,"aria-hidden":"true"})}return null}const Lt=(t,s)=>t.includes(s)?t.filter(o=>o!==s):[...t,s];function Fo({topics:t,follows:s,active:o,hrefFor:u,onEdit:a,editLabel:y}){const[S,p]=c.useState(!1),x=[...t.map(g=>({key:`topic:${g.id}`,filter:{...o,topicIds:Lt(o.topicIds,g.id)},name:fe(g),title:g.text,mark:null,on:o.topicIds.includes(g.id)})),...To(s).map(g=>({key:at(g),filter:{...o,follows:Lt(o.follows,at(g))},name:g.name,title:`${No[g.kind]} Β· ${g.name}`,mark:e.jsx(Co,{follow:g}),on:o.follows.includes(at(g))}))],L=o.topicIds.length===0&&o.follows.length===0,R=!S&&x.length>_t+1?x.filter((g,k)=>k<_t||g.on):x,E=x.length-R.length;return e.jsxs("nav",{className:"topic-bubbles follow-bubbles","aria-label":"Filter your feed",children:[x.length>0&&e.jsx(K,{className:`topic-bubble ${L?"active":""}`,to:u(So),"aria-current":L?"true":void 0,children:e.jsx("span",{className:"topic-bubble-name",children:"All"})}),R.map(g=>e.jsxs(K,{className:`topic-bubble ${g.on?"active":""}`,to:u(g.filter),title:g.title,"aria-current":g.on?"true":void 0,children:[g.mark,e.jsx("span",{className:"topic-bubble-name",children:g.name})]},g.key)),E>0&&e.jsx("button",{type:"button",className:"topic-bubble topic-bubble-more",onClick:()=>p(!0),children:e.jsxs("span",{className:"topic-bubble-name",children:["+",E," more"]})}),a&&e.jsxs("button",{type:"button",className:"topic-bubble topic-bubble-add",onClick:a,children:[e.jsx(qt,{size:13,"aria-hidden":"true"}),e.jsx("span",{className:"topic-bubble-name",children:y})]})]})}const Pt=45,_o=1800,Eo=25,Lo=350,Po=t=>{const[s,o]=c.useState(xe[0].slice(0,1)),[u,a]=c.useState(0);return c.useEffect(()=>{var I,R;if(!t)return;if((R=(I=window.matchMedia)==null?void 0:I.call(window,"(prefers-reduced-motion: reduce)"))!=null&&R.matches){o(xe[0]),a(0);return}let y=0,S=1,p=!1,x;o(xe[0].slice(0,S)),a(0);const L=()=>{const E=xe[y];if(!p){if(S+=1,o(E.slice(0,S)),S===E.length){p=!0,x=window.setTimeout(L,_o);return}x=window.setTimeout(L,Pt);return}if(S-=1,o(E.slice(0,S)),S===0){p=!1,y=(y+1)%xe.length,a(y),x=window.setTimeout(L,Lo);return}x=window.setTimeout(L,Eo)};return x=window.setTimeout(L,Pt),()=>window.clearTimeout(x)},[t]),{placeholder:s,prompt:xe[u]}},Do=()=>{var f;const t=pt(),s=At(),[o,u]=c.useState({text:"",paperMentions:[]}),a=o.text,[y,S]=c.useState(0),[p,x]=c.useState(!1),[L,I]=c.useState(null),{placeholder:R,prompt:E}=Po(!a),g=c.useRef(null),k=Z({queryKey:["chatAvailability"],queryFn:()=>to.getAvailability(),retry:!1,enabled:it()}),A=it()&&((f=k.data)==null?void 0:f.paper_mentions_enabled)!==!1,w=Ts({draft:o,onChange:u,enabled:A,textareaRef:g}),q=c.useRef(!1),[$,i]=c.useState(!1),h=Cs({draft:o,onChange:u,textareaRef:g,onEnd:d=>{q.current&&!d&&i(!0),q.current=!1}}),O=()=>{q.current=!0,h.finish()},J=Fs(o,w.open),Q=a?J.completion:E;c.useLayoutEffect(()=>{const d=g.current;if(!d)return;const b=()=>{if(d.style.height="auto",a){d.style.height=`${Math.min(As(d),160)}px`;return}const N=d.placeholder,m=xe.reduce((_,M)=>(d.placeholder=M,Math.max(_,d.scrollHeight)),0);d.placeholder=N,d.style.height=`${Math.min(m,160)}px`};return b(),window.addEventListener("resize",b),()=>window.removeEventListener("resize",b)},[a,Q]),c.useEffect(()=>{$&&(i(!1),F())},[$]);const F=async(d=o)=>{const b=d.text.trim();if(!(!b||p)){if(s){const N=new URLSearchParams({q:b,model:ot}),m=`${is}?${N}`,_=window.open(m,"_blank");if(!_){I(m);return}_.opener=null,I(null),u({text:"",paperMentions:[]});return}x(!0),_s(d,ot);try{const N=await Es(ot);t(`/chat/${N.id}`)}catch{t("/chat")}}};return e.jsx(e.Fragment,{children:e.jsxs("div",{className:"ask-home",children:[e.jsxs("div",{className:"ask-home-row",children:[e.jsxs("div",{className:"ask-home-textarea-wrap",children:[e.jsx(Ls,{text:o.text,mentions:o.paperMentions,scrollTop:y,variant:"home",completion:a?Q:""}),e.jsx("textarea",{ref:g,rows:1,value:a,placeholder:R,"aria-label":"Ask the assistant",disabled:p,readOnly:h.active,onChange:d=>{w.updateText(d.target.value,d.target.selectionStart),J.trackCaret(d.target)},onSelect:d=>{w.refresh(d.currentTarget.selectionStart),J.trackCaret(d.currentTarget)},onClick:d=>{w.refresh(d.currentTarget.selectionStart),J.trackCaret(d.currentTarget)},onScroll:d=>S(d.currentTarget.scrollTop),onBlur:d=>{var b,N;(N=(b=d.relatedTarget)==null?void 0:b.closest)!=null&&N.call(b,".chat-paper-picker")||window.setTimeout(w.close,0)},onKeyDown:d=>{if(h.active){d.key==="Enter"&&!d.shiftKey&&(d.preventDefault(),h.phase==="recording"&&O());return}if(!w.keyDown(d)){if(Ps(d)&&Q){d.preventDefault();const b=a+Q;w.updateText(b,b.length),window.requestAnimationFrame(()=>{var N;return(N=g.current)==null?void 0:N.setSelectionRange(b.length,b.length)});return}d.key==="Enter"&&!d.shiftKey&&(d.preventDefault(),F())}},role:A?"combobox":void 0,"aria-expanded":A?w.open:void 0,"aria-controls":w.open?w.pickerId:void 0,"aria-activedescendant":w.open&&w.results.length?`${w.optionIdPrefix}-${w.activeIndex}`:void 0,"aria-autocomplete":A?"list":void 0,"aria-describedby":w.message?"ask-home-paper-mention-message":void 0})]}),!s&&e.jsx(Ds,{dictation:h,disabled:p}),e.jsx("button",{type:"button",className:`chat-send${a.trim()||h.phase==="recording"?" chat-send-on":""}`,onClick:()=>h.active?O():void F(),disabled:p||(h.active?h.phase!=="recording":!a.trim()),"aria-label":"Ask the assistant",children:e.jsx(Is,{})})]}),L&&e.jsx("div",{className:"chat-paper-mention-message",role:"alert",children:e.jsx("a",{href:L,target:"_blank",rel:"noreferrer",children:"Open this question on paperswithcode.co"})}),h.error&&e.jsx("div",{className:"chat-paper-mention-message",role:"alert",children:h.error}),w.message&&e.jsx("div",{id:"ask-home-paper-mention-message",className:"chat-paper-mention-message",role:"alert",children:w.message}),e.jsx(Rs,{open:w.open,query:w.query,results:w.results,activeIndex:w.activeIndex,loading:w.loading,error:w.error,onSelect:w.select,id:w.pickerId,optionIdPrefix:w.optionIdPrefix})]})})},Io=30,Ro=6,ct="pwc:following-last-seen",Yt="pwc:following-new-since",Ao=60*60*1e3;function dt(t){try{return localStorage.getItem(t)}catch{return null}}function Dt(t,s){try{localStorage.setItem(t,s)}catch{}}const Qt=(t,s)=>s-Date.parse(t)>Ao;function $o(t=Date.now()){const s=dt(ct);return s?Qt(s,t)?s:dt(Yt):null}function Mo(t,s=Date.now()){const o=dt(ct);o&&!(t&&Qt(o,s))||(o&&Dt(Yt,o),Dt(ct,new Date(s).toISOString()))}const It=40,Oo=100,Bo=async t=>{const s=await t;return{results:s.results.map(o=>({paper:o})),next_page:s.next_page}},Ho=({mode:t})=>{var W,ke,Ne,te,Ue,Pe,De,Ie,Re,pe,Ae,$e,Me,Oe,Be;const s=t==="following",o=pt(),u=os(),a=u==null?void 0:u.user,[y,S]=ns(),p=Qs(y,void 0,t==="trending"?"week":"month"),x=l=>{const j=new URLSearchParams(y);j.delete("order_by"),j.delete("only"),j.delete("topic"),j.delete("follow");const Y=j.toString();o(Y?`${l}?${Y}`:l)},L={topicIds:[],follows:[]},I=l=>{const j=new URLSearchParams(y);j.delete("only"),j.delete("topic"),j.delete("follow"),l.topicIds.forEach(oe=>j.append("topic",String(oe))),l.follows.forEach(oe=>j.append("follow",oe));const Y=j.toString();return Y?`/following?${Y}`:"/following"},R=Z(Xe.topTasks(8)),E=Z(Xe.trendingTasks({limit:8,min_recent_papers:10})),g=s&&y.get("only")==="topic",k=s?{topicIds:[...new Set(y.getAll("topic").map(Number).filter(Number.isInteger))],follows:[...new Set(y.getAll("follow").filter(l=>/^(task|method|benchmark|author|organization):\d+$/.test(l)))]}:L,A=k.topicIds.length>0||k.follows.length>0,w={start_date:p.startDate,end_date:p.endDate},q={...p,topicOnly:g,...k},$=Xs(s?qe.following(a==null?void 0:a.hf_subject,q):qe.trending(w),async l=>{if(s){const Y=await ft.following(l,q),oe=Y.length===It?l+It:null;return{results:Y,next_page:oe}}const j={...w,page:l,page_size:Io,include_resources:!0};return Bo(rs.list({...j,order_by:"trending",order_dir:"desc",latest_only:!0}))},{enabled:!s||!!a,initialPage:s?0:1}),i=Ht(),h=Bt(!0,1e4),O=!!((W=i.data)!=null&&W.length)||!!((ke=h.data)!=null&&ke.length),J=fe,Q=((Ne=h.data)==null?void 0:Ne.filter(ys))??[],F=Q.filter(l=>k.topicIds.length?k.topicIds.includes(l.id):!k.follows.length),f=k.topicIds.length===1&&!k.follows.length?(te=h.data)==null?void 0:te.find(l=>l.id===k.topicIds[0]):void 0,[d,b]=c.useState(()=>wo()),[N,m]=c.useState(()=>d?d.topicId:s&&y.get("edit")==="1"?null:void 0),_=Rt(),M=Q.map(l=>l.id).join(","),U=c.useRef([]);c.useEffect(()=>{const l=M?M.split(","):[];U.current.some(j=>!l.includes(j))&&_.invalidateQueries({queryKey:qe.following(a==null?void 0:a.hf_subject)}),U.current=l},[M,_,a==null?void 0:a.hf_subject]);const ce=s&&!!a&&((Ue=i.data)==null?void 0:Ue.length)===0&&h.isSuccess&&h.data.length===0,B=s&&!(u!=null&&u.isLoading)&&!a||ce,T=!!a||!as(),se=c.useMemo(()=>{var l;return new Set((l=h.data)==null?void 0:l.map(j=>j.id))},[h.data]),de=c.useMemo(()=>{var l;return new Set((l=i.data)==null?void 0:l.map(j=>`${j.kind}:${j.entity_id}`))},[i.data]),ne=!s&&T&&!(u!=null&&u.isLoading)&&(!a||i.isSuccess&&h.isSuccess&&!O),[X]=c.useState(()=>$o());c.useEffect(()=>{a&&(s||O)&&Mo(s)},[a,s,O]);const C=((Pe=Z({...me.followingNewCount(a==null?void 0:a.hf_subject,X??""),enabled:!!a&&O&&!!X}).data)==null?void 0:Pe.count)??0,ae=s&&X?Date.parse(X):NaN,Ce={topicOnly:g,...k,addedAfter:X??void 0},ge=Z({queryKey:[...qe.following(a==null?void 0:a.hf_subject),"new",Ce],queryFn:()=>ft.following(0,Ce,Oo),enabled:s&&!!a&&!!X,staleTime:5*60*1e3,placeholderData:ls}),[be,Fe]=c.useState(!1),[ee]=c.useState(()=>!!gt()||st().length>0||Ge().length>0),[_e,Ee]=c.useState(!1);!be&&((De=h.data)!=null&&De.length||(Ie=i.data)!=null&&Ie.length)&&Fe(!0),B&&!_e&&(Ee(!0),T&&!be&&!ee&&m(null));const H=Ut(),{mutate:we}=H,je=c.useRef(!1);c.useEffect(()=>{const l=gt();!a||!h.isSuccess||!l||je.current||(je.current=!0,h.data.some(j=>j.text===l)?vs():we({text:l}))},[a,h.isSuccess,h.data,we]);const z=zt(),{mutate:He}=z,ie=c.useRef(!1);c.useEffect(()=>{const l=st();!a||!l.length||ie.current||(ie.current=!0,He(l))},[a,He]);const ue=ks(),{mutate:ye}=ue,Je=c.useRef(!1);c.useEffect(()=>{const l=Ge();!a||!l.length||Je.current||(Je.current=!0,ye(l))},[a,ye]);const Le=h.isFetching||i.isFetching||st().length>0&&!z.isError||Ge().length>0&&!ue.isError,re=A&&h.isSuccess&&i.isSuccess?{topicIds:k.topicIds.filter(l=>h.data.some(j=>j.id===l)),follows:k.follows.filter(l=>i.data.some(j=>`${j.kind}:${j.entity_id}`===l))}:void 0,et=!!re&&!Le&&(re.topicIds.length<k.topicIds.length||re.follows.length<k.follows.length);c.useEffect(()=>{et&&re&&o(I(re),{replace:!0})});const tt=c.useMemo(()=>{var n;const l=r=>({...Ns(r.paper),followReasons:r.reasons,isNew:!!r.added_at&&Date.parse(r.added_at)>ae}),j=ge.isPlaceholderData?void 0:ge.data,Y=$.data&&j?j.map(l).filter(r=>r.isNew):[],oe=new Set(Y.map(r=>r.id)),ze=((n=$.data)==null?void 0:n.pages.flatMap(r=>r.results.map(l)))??[];return[...Y,...ze.filter(r=>!oe.has(r.id))]},[$.data,ge.data,ge.isPlaceholderData,ae]),ve=$.error;return e.jsxs("div",{className:"page",children:[e.jsx("div",{className:"feed-header",children:e.jsxs("div",{children:[e.jsxs("h1",{className:"feed-title",children:["Trending ",e.jsx("em",{children:"Research"})]}),e.jsx("div",{className:"feed-subtitle",children:"Curated daily from arXiv and Hugging Face"})]})}),e.jsxs("div",{className:"layout-with-sidebar",children:[e.jsxs("aside",{className:"sidebar feed-sidebar",children:[e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"sidebar-section sidebar-section-top-domains",children:[e.jsx("div",{className:"sidebar-label",children:"Top Domains"}),R.isLoading&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:Array.from({length:6}).map((l,j)=>e.jsx(bt,{className:"h-5 w-full"},j))}),e.jsxs("div",{className:"sidebar-links",children:[(Re=R.data)==null?void 0:Re.map(l=>e.jsxs(K,{to:`/tasks/${l.slug}`,className:"sidebar-link",children:[Te(l.name,l.slug),l.paper_count!=null&&e.jsx("span",{className:"count",children:l.paper_count})]},l.id)),e.jsx(K,{to:"/tasks",className:"sidebar-link sidebar-link-more",children:"all domains β"})]})]}),e.jsxs("div",{className:"sidebar-section sidebar-section-trending-domains",children:[e.jsx("div",{className:"sidebar-label",children:"Trending Domains"}),E.isLoading&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:Array.from({length:6}).map((l,j)=>e.jsx(bt,{className:"h-5 w-full"},j))}),((Ae=(pe=E.data)==null?void 0:pe.results)==null?void 0:Ae.length)===0&&!E.isLoading&&e.jsx("div",{style:{fontSize:12,color:"var(--ink-faint)"},children:"No domains gaining momentum right now."}),e.jsx("div",{className:"sidebar-links",children:(Me=($e=E.data)==null?void 0:$e.results)==null?void 0:Me.map(l=>e.jsxs(K,{to:`/tasks/${l.slug}`,className:"sidebar-link",children:[Te(l.name,l.slug),e.jsxs("span",{className:"count",children:[l.share_lift.toFixed(1),"x"]})]},l.id))})]})]}),e.jsx(eo,{})]}),e.jsxs("div",{className:"feed-main",children:[(it()||At())&&e.jsx("div",{className:"feed-chat",children:e.jsx(Do,{})}),e.jsxs("div",{className:"feed-content",children:[!s&&T&&e.jsx(ho,{followedIds:!(u!=null&&u.isLoading)&&(!a||h.isSuccess)?se:null,followedKeys:!(u!=null&&u.isLoading)&&(!a||i.isSuccess)?de:null,onBuild:()=>m(null)}),e.jsxs("div",{className:"sort-bar home-feed-sort-bar",children:[e.jsx("div",{className:"paper-feed-toolbar-controls",children:e.jsxs("div",{className:"sort-options",children:[e.jsx("button",{className:`sort-btn ${t==="trending"?"active":""}`,onClick:()=>x("/"),children:"trending"}),e.jsxs("button",{className:`sort-btn ${s?"active":""}`,onClick:()=>x("/following"),children:["following",C>0&&e.jsx("span",{className:"nav-new-badge feed-tab-new",title:"New papers since your last visit",children:"New"})]})]})}),e.jsx(Vs,{startDate:p.startDate,endDate:p.endDate,onChange:l=>S(Zs(y,l))})]}),s&&(!!a||!(u!=null&&u.isLoading))&&e.jsx(Fo,{topics:h.data??[],follows:i.data??[],active:k,hrefFor:I,onEdit:T?()=>m(null):void 0,editLabel:(Oe=h.data)!=null&&Oe.length||(Be=i.data)!=null&&Be.length?"Edit feed":"Build feed"}),ve&&e.jsx(We,{variant:"destructive",className:"mb-4",children:e.jsxs(Ye,{children:["Failed to load papers. ",e.jsx("button",{type:"button",onClick:()=>void $.refetch(),children:"Try again"})]})}),H.isError&&H.variables&&e.jsx(We,{variant:"destructive",className:"mb-4",children:e.jsx(Ye,{children:Ve(H.error)?e.jsxs(e.Fragment,{children:["Could not follow β",H.variables.text,"β: ",H.error.message,"."]}):e.jsxs(e.Fragment,{children:["Could not follow β",H.variables.text,"β. ",e.jsx("button",{type:"button",onClick:()=>we(H.variables),children:"Try again"})]})})}),z.isError&&z.variables&&e.jsx(We,{variant:"destructive",className:"mb-4",children:e.jsxs(Ye,{children:["Could not follow ",z.variables.map(l=>l.name).join(", "),". ",e.jsx("button",{type:"button",onClick:()=>He(z.variables),children:"Try again"})]})}),ue.isError&&e.jsx(We,{variant:"destructive",className:"mb-4",children:e.jsx(Ye,{children:Ve(ue.error)?e.jsxs(e.Fragment,{children:["Could not follow the popular topics you picked: ",ue.error.message,"."]}):e.jsxs(e.Fragment,{children:["Could not follow the popular topics you picked. ",e.jsx("button",{type:"button",onClick:()=>ye(Ge()),children:"Try again"})]})})}),s&&F.length>0&&e.jsxs("div",{className:"following-topic-note",role:"status",children:["Showing the closest papers about ",F.map(l=>`β${J(l)}β`).join(" and ")," now. A model is reading papers to refine these matches, which takes a few minutes."]}),T&&e.jsx(jo,{open:N!==void 0,topicId:N??null,afterSavePath:s?void 0:"/following",restore:d,onOpenChange:l=>{if(!l&&(xo(),b(null),m(void 0),y.has("edit"))){const j=new URLSearchParams(y);j.delete("edit"),S(j,{replace:!0})}}}),g&&!A&&e.jsxs("div",{className:"following-topic-note following-topic-filter",role:"status",children:["Showing only papers about your topics. ",e.jsx(K,{to:I(L),children:"Show everything you follow"})]}),B?e.jsx(ro,{onBuild:T?()=>m(null):void 0}):e.jsx(Js,{query:$,isLoading:$.isLoading||ge.isLoading||s&&!!(u!=null&&u.isLoading),cards:tt,skeleton:"card",rootMargin:"400px",cardHeader:ne?l=>l===Ro&&e.jsx(uo,{onBuild:()=>m(null)}):void 0,empty:ve?null:f?e.jsxs(e.Fragment,{children:["No papers about this topic match these filters. Widen the date range or ",e.jsx("button",{type:"button",className:"link-button",onClick:()=>m(f.id),children:"edit the topic"}),"."]}):A?e.jsx(e.Fragment,{children:"No papers match the selected bubbles in this window. Widen the date range or pick more bubbles."}):g?e.jsx(e.Fragment,{children:"No papers about your topics match these filters. Widen the date range or follow more topics."}):s?e.jsxs(e.Fragment,{children:["No papers from your topics or follows match these filters. Widen the date range, or follow more from ",e.jsx(K,{to:"/tasks",children:"tasks"}),", ",e.jsx(K,{to:"/methods",children:"methods"}),", benchmark, author, or organization pages."]}):"No papers in this window."})]})]})]})]})},Rn=()=>(so(oo),e.jsx(Ho,{mode:"trending"}));export{Do as AskAssistant,Ho as HomeFeed,Rn as default};
|