diff --git "a/assets/PaperDetailView-D2DMSSYR.js" "b/assets/PaperDetailView-D2DMSSYR.js" new file mode 100644--- /dev/null +++ "b/assets/PaperDetailView-D2DMSSYR.js" @@ -0,0 +1,39 @@ +import{g as Le,n as Us,b as Wt,h as oe,k as Ds,r as m,j as e,l as me,m as he,o as fe,P as Jt,p as ke,q as Yt,s as Fe,t as Re,v as Zt,w as vt,x as Me,X as yt,L as ue,y as Bs,z as zs,R as Hs,I as Ms,B as es,D as qs,E as Os,T as Ks,A as ht,i as Gs,a as Oe,F as qe,G as pt,J as ts,K as Xs,u as Qs,M as Lt,N as Vs,f as Ft,O as Ws,Q as Js,S as Ys,U as Zs,V as ea}from"./index-B9MfhMLC.js";import{I as J,T as ta,M as sa,A as aa,S as ra,a as na}from"./components-BZrNefuY.js";import{L as He,a as ia}from"./LatexTitle-DeUmWtI2.js";import{e as Ke,C as oa,E as la}from"./ExternalSourceEvalBadge-CFCVDZdz.js";import{p as W}from"./papers-BGvqL27Z.js";import{r as ss,p as ca}from"./paperReader-BIpQD5HO.js";import{p as ye}from"./paperQueryKeys-BP2E-0yf.js";import{u as ne}from"./useQuery-Bx81pmgm.js";import{b as da}from"./usePapers-DP7fFbrs.js";import{f as ua,D as ma}from"./latexPlainText-DI8YEXVe.js";import{s as we}from"./safeExternalHref-CkBrsh84.js";import{s as ha}from"./colors-BCIVIuvj.js";import{S as Ie}from"./skeleton-BcfKeAOl.js";import{A as pa,a as fa}from"./alert-Bg2LnrDJ.js";import{B as L}from"./button-DZAojLNy.js";import{D as ee,a as te,b as se,c as ae,d as re,e as le}from"./dialog-CR0TulAY.js";import{u as ga}from"./useInfiniteQuery-4Zdqd3L2.js";import{A as xa,a as ba}from"./AgentLogos-iXpPIhF4.js";import{p as ja}from"./paperEdits-DYztItZs.js";import{C as va}from"./copy-407Yr7lh.js";import{I as V}from"./input-DbV7135c.js";import{S as Tt,a as Ae}from"./searchable-select-C8cfKu2W.js";import{u as ce}from"./useMutation-C2athD5k.js";import{c as _e}from"./catalog-BqDz3O_s.js";import{s as pe,p as ya}from"./submissions-YISzGIO1.js";import{e as wa,r as _a,a as je}from"./evaluationQueryInvalidation-CC5JhGiX.js";import{S as wt,L as de,a as ka}from"./SignInToEditDialog-D7miI02Z.js";import{L as ie}from"./loader-circle-BeMbSHvo.js";import{T as Te,n as Ye,g as Ut}from"./github-CE1K0ZU_.js";import{D as Na,c as Ca,g as Ea,s as Sa,a as Pa,b as $a,d as Ia,i as Ra,e as Aa}from"./codexAddEvals-B53N-zkn.js";import{P as Ue}from"./plus-BZFi6ZWf.js";import{u as as}from"./index-Dcor-vPm.js";import{B as rs}from"./badge-CO0oD6ZM.js";import{G as Dt}from"./github-D0bNa_Wx.js";import{M as La}from"./index-10yxmORR.js";import{r as Fa}from"./index-CSRWQTrf.js";import{u as Ta}from"./useIntersectionObserver-Dg35i96T.js";import{S as Bt,s as Ua}from"./savedPapersAuth-BjQx0VVU.js";import"./hover-card-Bv4bJws5.js";import"./popover-UrZdfRNz.js";import"./textarea-BKTJjgMO.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 Da=Le("ArrowDown",[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]);/** + * @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 Ba=Le("ArrowUp",[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]);/** + * @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 zt=Le("Globe",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]]);/** + * @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 za=Le("History",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M12 7v5l4 2",key:"1fdv2h"}]]);/** + * @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 ns=Le("Star",[["path",{d:"M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z",key:"r04s7s"}]]);function Ha(t){return t!=null&&t.can_directly_edit_catalog?"direct":"pending"}function Ma(t){return(t??[]).filter(s=>!!(s.dataset_slug&&s.task_slug))}function qa(t,s,a="https://paperswithcode.co"){return s.map(r=>{const n=encodeURIComponent(r.evaluation_id),c=`${a}/api/v1/papers/${encodeURIComponent(t)}/leaderboard-badge.svg?eval=${n}&live=1`,o=`${a}/api/v1/papers/${encodeURIComponent(t)}/leaderboard-badge-link?eval=${n}`;return`[![${`Papers with Code: ${r.best_rank===1?"SOTA":`#${r.best_rank}`} on ${r.dataset_name}`}](${c})](${o})`}).join(` +`)}function Oa(t,s=!0){return ne({queryKey:["evaluations","paper",t],queryFn:()=>{if(!t)throw new Error("Paper ID is required");return Ke.byPaper(t)},enabled:s&&!!t,staleTime:0,refetchOnMount:"always"})}const is=t=>t.replace(/v\d+$/,""),Ka={models:"https://huggingface.co/",datasets:"https://huggingface.co/datasets/",spaces:"https://huggingface.co/spaces/"},Ze=(t,s)=>{const a=(t[s]||[]).length;return a<100?{count:a,isLimited:!1}:{count:a,isLimited:!0}},et=(t,s)=>{const a=t[s];return Array.isArray(a)?a.map(r=>{if(typeof r=="string")return r;if(r&&typeof r=="object"){const n=r;return n.id||n.repoId||null}return null}).filter(r=>!!r).map(r=>`${Ka[s]}${r}`):[]},Ga=async t=>{try{return(await fetch(`https://huggingface.co/api/papers/${is(t)}`)).ok}catch{return!1}},Xa=async t=>{const s=is(t),[a,r]=await Promise.all([fetch(`https://huggingface.co/api/arxiv/${s}/repos`).then(async i=>i.ok?i.json():(console.warn(`Failed to fetch repos for arXiv:${s}, status: ${i.status}`),null)).catch(i=>(console.warn(`Failed to fetch repos for arXiv:${s}:`,i),null)),Ga(s)]);if(!a)return{models:0,datasets:0,spaces:0,modelUrls:[],datasetUrls:[],spaceUrls:[],isLimited:!1,paperExists:r};const n=Ze(a,"models"),c=Ze(a,"datasets"),o=Ze(a,"spaces");return{models:n.count,datasets:c.count,spaces:o.count,modelUrls:et(a,"models"),datasetUrls:et(a,"datasets"),spaceUrls:et(a,"spaces"),isLimited:n.isLimited||c.isLimited||o.isLimited,paperExists:r}},Qa=t=>ne({queryKey:["huggingface-repos",t],queryFn:()=>Xa(t),enabled:!!t,staleTime:10*60*1e3,retry:1});function Va(t,s){try{const a=new URL(t),r=a.pathname.replace(/\/$/,"").split("/").filter(Boolean).at(-1);return(r==null?void 0:r.replace(/[-_]+/g," "))||a.hostname.replace(/^www\./,"")}catch{return s}}function tt(t,s,a){return[...new Set([...t,...s??[]])].map(r=>({href:r,label:Va(r,a)}))}function st(t,s,a){if(a==null&&t.length===0&&!(s!=null&&s.length))return;const r=new Set([...t,...s??[]]);return Math.max(r.size,a??0)}function at(t){return t[0]??"https://huggingface.co"}function rt(t,s){return s[0]??t}function Wa(t){const s=`${t.title.slice(0,60)}${t.title.length>60?"…":""}`,a=`${t.authors[0]||""}${t.authors.length>1?" et al.":""}`,r=t.authors.join(" and "),n=(t.published||"").slice(0,4)||"—",c=(o,i)=>t.arxiv_id?`@article{${t.arxiv_id.replace(".","")}, + title={{${o}}}, + author=${i}, + year={{${n}}}, + eprint={{${t.arxiv_id}}}, + archivePrefix={{arXiv}} +}`:`@misc{paper${t.id}, + title={{${o}}}, + author=${i}, + year={{${n}}}, + url={{${t.source_url||t.url_abs||""}}} +}`;return{citationDisplay:c(s,`{{${a}}}`),citationCopy:c(t.title,`{${r}}`)}}function Ja(t,s,a){var g,b,w,j;const r={models:t.hf_models??[],datasets:t.hf_datasets??[],spaces:t.hf_spaces??[]},n={models:tt(r.models,s==null?void 0:s.modelUrls,"Model"),datasets:tt(r.datasets,s==null?void 0:s.datasetUrls,"Dataset"),spaces:tt(r.spaces,s==null?void 0:s.spaceUrls,"Space")},c={models:n.models.map(({href:v})=>v),datasets:n.datasets.map(({href:v})=>v),spaces:n.spaces.map(({href:v})=>v)},o=((g=t.arxiv_id)==null?void 0:g.replace(/v\d+$/,""))??null,i=t.arxiv_id?{isLoading:a,paperHref:`https://huggingface.co/papers/${o}`,rows:[{label:"Models",href:rt(`https://huggingface.co/models?other=arxiv:${t.arxiv_id}`,r.models),count:st(r.models,s==null?void 0:s.modelUrls,s==null?void 0:s.models),isLimited:s==null?void 0:s.isLimited,links:n.models},{label:"Datasets",href:rt(`https://huggingface.co/datasets?other=arxiv:${t.arxiv_id}`,r.datasets),count:st(r.datasets,s==null?void 0:s.datasetUrls,s==null?void 0:s.datasets),isLimited:s==null?void 0:s.isLimited,links:n.datasets},{label:"Spaces",href:rt(`https://huggingface.co/papers/${o}`,r.spaces),count:st(r.spaces,s==null?void 0:s.spaceUrls,s==null?void 0:s.spaces),isLimited:s==null?void 0:s.isLimited,links:n.spaces}],footer:`Cite arxiv.org/abs/${o} in a HF README to link it here.`}:{isLoading:!1,paperHref:null,rows:[{label:"Models",href:at(r.models),count:r.models.length,links:n.models},{label:"Datasets",href:at(r.datasets),count:r.datasets.length,links:n.datasets},{label:"Spaces",href:at(r.spaces),count:r.spaces.length,links:n.spaces}],footer:null},d=(t.methods??[]).filter(({source_paper_id:v})=>v===t.id),p=t.introduced_benchmarks??[],f=t.introduced_frameworks??[],l=[d.length&&(d.length===1?"this method":"these methods"),p.length&&(p.length===1?"this benchmark":"these benchmarks"),f.length&&(f.length===1?"this framework":"these frameworks")].filter(v=>!!v);return{...Wa(t),allHfArtifactUrls:c,authorEntries:t.authors.map((v,C)=>{var P,I,S,_,u,x;return{name:v,id:((I=(P=t.author_links)==null?void 0:P[C])==null?void 0:I.id)??null,hf_username:((_=(S=t.author_links)==null?void 0:S[C])==null?void 0:_.hf_username)??null,hf_avatar_url:((x=(u=t.author_links)==null?void 0:u[C])==null?void 0:x.hf_avatar_url)??null}}),copyableRanks:Ma(t.leaderboard_ranks),hasIntroducedItems:l.length>0,hasLineageItems:!!((b=t.predecessor_papers)!=null&&b.length||(w=t.successor_papers)!=null&&w.length),hfArtifactViewer:i,hfPaperExists:!!(s!=null&&s.paperExists),introducedBenchmarks:p,introducedFrameworks:f,introducedMethods:d,introducedSummary:l.join(" and "),numPages:t.num_pages||null,paperSourceLabel:t.arxiv_id?`arXiv:${t.arxiv_id}`:"External resource",predecessorPapers:t.predecessor_papers??[],projectPages:((j=t.project_pages)==null?void 0:j.filter(({url:v})=>v).map(v=>({...v,safeHref:we(v.url)})))??[],repoSummary:ha(t.repositories),safeAbstractUrl:we(t.url_abs),safeConferenceUrl:we(t.conference_url_abs),safePdfUrl:we(t.url_pdf),sourceActionLabel:t.source==="external"?"Source page":"arXiv page",successorPapers:t.successor_papers??[]}}const Ya=["tldr","abstract","tasks","methods","results"];function Za(t){if(!t)return{section:null,resultsTaskSlug:null};const[s,a]=t.split("?",2);if(!Ya.includes(s))return{section:null,resultsTaskSlug:null};const r=s;return r!=="results"||!a?{section:r,resultsTaskSlug:null}:{section:r,resultsTaskSlug:new URLSearchParams(a).get("task")}}const os=t=>`results-task-${t}`,er=t=>`#results?task=${encodeURIComponent(t)}`;function tr(t,s){return t&&!!s}function sr({direct:t,paperId:s,refetchEvaluations:a,refetchPaper:r}){r(),a(),!(!t||!s)&&(W.primeCurationState(s,!0).catch(()=>{}),Ke.primeCurationState(s,!0).catch(()=>{}))}function ar(t,s){const a=t?Us(t):"",r=Wt(),{toast:n}=oe(),{preferences:c}=Ds(),o=da(a,!!a),i=o.data,[d,p]=m.useState(!1);m.useEffect(()=>{!t||t===a||r(`/paper/${a}${window.location.search}${window.location.hash}`,{replace:!0})},[a,r,t]),m.useEffect(()=>{if(i!=null&&i.title)return document.title=ua(i.title),()=>{document.title=ma}},[i==null?void 0:i.title]),m.useEffect(()=>{if(p(!1),!(i!=null&&i.id))return;const S=window.setTimeout(()=>p(!0),0);return()=>window.clearTimeout(S)},[i==null?void 0:i.id]);const f=tr(d,i==null?void 0:i.id),l=Qa(d?i==null?void 0:i.arxiv_id:void 0),g=Oa(i==null?void 0:i.id,f),b=ne({queryKey:[...ye.feeds.versions,i==null?void 0:i.arxiv_id],queryFn:()=>W.versions(i.arxiv_id.replace(/v\d+$/,"")),enabled:f&&!!(i!=null&&i.arxiv_id),staleTime:10*60*1e3}),w=ne({queryKey:[...ye.feeds.related,i==null?void 0:i.id],queryFn:()=>W.related(i.arxiv_id||i.id,4),enabled:f,staleTime:10*60*1e3});m.useEffect(()=>{const S=()=>{sr({direct:s==="direct",paperId:i==null?void 0:i.id,refetchEvaluations:g.refetch,refetchPaper:o.refetch}),n({title:"This section changed",description:"The latest state has been reloaded. Review your changes before submitting again.",variant:"destructive"})};return window.addEventListener("pwc:catalog-conflict",S),()=>window.removeEventListener("pwc:catalog-conflict",S)},[s,g.refetch,i==null?void 0:i.id,o.refetch,n]);const j=m.useMemo(()=>{const S=g.data;return!S||!c.hide_closed_source_evals?S:S.filter(_=>_.is_open!==!1)},[g.data,c.hide_closed_source_evals]),v=m.useMemo(()=>{if(!j)return[];const S=new Map;for(const _ of j){const u=S.get(_.task_id);u?u.rows.push(_):S.set(_.task_id,{taskId:_.task_id,taskName:_.task_name||"—",taskSlug:_.task_slug,rows:[_]})}return[...S.values()]},[j]),C=m.useMemo(()=>v.map(({taskSlug:S})=>S??"").join("|"),[v]),P=m.useMemo(()=>i?Ja(i,l.data,l.isLoading):null,[l.data,l.isLoading,i]),I=m.useRef(!1);return m.useEffect(()=>{I.current=!1},[a]),m.useEffect(()=>{let S=0;const _=(x=!1,E=!1)=>{const{section:F,resultsTaskSlug:M}=Za(window.location.hash.slice(1));if(!F||!i||F==="tldr"&&!i.tldr||F==="results"&&(!f||g.isLoading)||!x&&I.current)return;let O=F==="results"&&M?document.getElementById(os(M)):document.getElementById(F);if(!O&&F==="results"&&M){if(v.some(({taskSlug:K})=>K===M))return;O=document.getElementById("results")}O&&(S=window.requestAnimationFrame(()=>{I.current=!0,O.scrollIntoView({block:"start",behavior:E?"smooth":"auto"})}))};_();const u=()=>{I.current=!1,_(!0,!0)};return window.addEventListener("hashchange",u),()=>{window.removeEventListener("hashchange",u),S&&window.cancelAnimationFrame(S)}},[v,g.isLoading,i,C,f]),{arxivId:a,evaluations:g.data,evaluationsByTask:v,evaluationsLoading:g.isLoading,hfLoading:l.isLoading,hfRepos:l.data,paper:i,paperError:o.error,paperLoading:o.isLoading,presentation:P,refetchEvaluations:g.refetch,refetchPaper:o.refetch,relatedQuery:w,versions:b.data??[],visibleEvaluations:j}}const rr={tasks:"tasks",methods:"methods",evaluations:"results",repositories:"repositories",project_pages:"project-pages",hf_artifacts:"hf-artifacts",organizations:"organizations",source_url:"source-url",x_threads:"x-threads"};function nr(t){return rr[t]??null}function ir(){const[t,s]=m.useState(null),a=m.useCallback(n=>{s(n)},[]),r=m.useCallback((n,c)=>{s(o=>c?n:o===n?null:o)},[]);return{activeEditor:t,openEditor:a,setEditorOpen:r}}function or({paperId:t,isAdmin:s}){var g;const[a,r]=m.useState(!1),[n,c]=m.useState(!1),[o,i]=m.useState(!1),[d,p]=m.useState(()=>window.location.hash.startsWith("#edit")),f=ga({queryKey:["paper-edit-history",t],queryFn:({pageParam:b})=>ja.history(t,b),initialPageParam:void 0,getNextPageParam:b=>b.next_cursor??void 0,enabled:s&&d}),l=`Help me edit https://paperswithcode.co/paper/${t} using the public pwc CLI from https://github.com/huggingface/pwc-cli. Install or update the CLI following its README, then run pwc skills add to load its instructions. Run pwc auth login --paper ${t}; I will authorize this paper in my browser. Export with pwc paper edit export ${t} --output edits.json, make explicit operations for the corrections I request, and preview before submitting. For organization changes, use an organizations operation with payload {"organization_ids": [existing organization IDs]}; this replaces the paper’s organization links and publishes directly. Use existing organizations, benchmark and metric definitions, preserve unrelated entries, and cite source URLs where available. Never print or copy credentials. Ask me what to change if I have not specified it.`;return e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",className:"action-btn",title:"Edit this paper page with Claude, Codex, Cursor, or OpenCode",onClick:()=>{r(!1),c(!1),i(!0)},children:["Edit with your agent",e.jsx(xa,{})]}),s&&e.jsxs("button",{type:"button",className:"action-btn",onClick:()=>p(!0),children:[e.jsx(za,{size:12})," View edit history"]}),e.jsx(ee,{open:o,onOpenChange:i,children:e.jsxs(te,{className:"max-w-2xl",children:[e.jsxs(se,{children:[e.jsx(ae,{children:"Edit this paper with your agent"}),e.jsx(re,{children:"Spotted a missing code link, a wrong task, or a missing benchmark result? Your favorite coding agent can fix it for you."})]}),e.jsx(ba,{}),e.jsxs("ol",{className:"list-decimal space-y-1 pl-5 text-sm text-muted-foreground",children:[e.jsx("li",{children:"Copy the prompt below."}),e.jsx("li",{children:"Paste it into Claude Code, Codex, Cursor, OpenCode, or another coding agent, and tell it what to change."}),e.jsxs("li",{children:["The agent installs the ",e.jsx("a",{className:"underline",href:"https://github.com/huggingface/pwc-cli",target:"_blank",rel:"noreferrer",children:"pwc CLI"}),", asks you to authorize this paper with your Hugging Face account, and previews the edits before submitting them."]})]}),e.jsx("textarea",{"aria-label":"Paper edit prompt",readOnly:!0,value:l,className:"h-48 w-full resize-none rounded border bg-muted/40 p-3 font-mono text-xs",onFocus:b=>b.currentTarget.select()}),n&&e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:"Could not copy automatically. Select the prompt above and copy it manually."}),e.jsxs(L,{className:"justify-self-end",onClick:async()=>{try{await navigator.clipboard.writeText(l),r(!0),c(!1)}catch{c(!0)}},children:[a?e.jsx(me,{size:14}):e.jsx(va,{size:14}),a?"Prompt copied":"Copy prompt"]})]})}),e.jsx(ee,{open:s&&d,onOpenChange:p,children:e.jsxs(te,{className:"max-h-[85vh] max-w-3xl overflow-y-auto",id:"edit-history",children:[e.jsxs(se,{children:[e.jsx(ae,{children:"Paper edit history"}),e.jsx(re,{children:"Published changes and their contributors."})]}),e.jsxs("div",{className:"space-y-3",children:[f.isLoading&&e.jsx("p",{children:"Loading edit history…"}),f.error&&e.jsx("p",{role:"alert",children:"Could not load edit history."}),f.data&&!f.data.pages[0].events.length&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No edits have been recorded here yet."}),(g=f.data)==null?void 0:g.pages.flatMap(b=>b.events).map(b=>e.jsxs("article",{id:`edit-${b.id}`,className:"rounded border p-3",children:[e.jsxs("p",{className:"text-sm",children:[b.actor_username?e.jsxs("a",{className:"underline",href:`https://huggingface.co/${encodeURIComponent(b.actor_username)}`,children:["@",b.actor_username]}):"Catalog administrator"," · ",new Date(b.created_at).toLocaleString()," · ",b.operation==="rollback"?"Reverted an edit":"Updated this paper"]}),e.jsxs("details",{children:[e.jsx("summary",{className:"cursor-pointer text-sm",children:"View changes"}),e.jsx("pre",{className:"max-h-80 overflow-auto whitespace-pre-wrap text-xs",children:JSON.stringify({before:b.before,after:b.after},null,2)})]})]},b.id)),f.hasNextPage&&e.jsx(L,{variant:"outline",disabled:f.isFetchingNextPage,onClick:()=>void f.fetchNextPage(),children:"Load older edits"})]})]})})]})}function lr(t){return t.map(s=>{const a=s.best_metric||Object.keys(s.metrics)[0]||"";return{id:s.id,task_id:s.task_id,dataset_id:s.dataset_id,model_name:s.model_name||"",harness:s.harness||"",metric_name:a,metric_value:String(s.metrics[a]??""),original_metrics:{...s.metrics},original_metric_name:a,best_rank:s.best_rank!=null?String(s.best_rank):"",num_parameters:s.num_parameters!=null?String(s.num_parameters):"",hf_model_url:s.hf_model_url||"",is_open:s.is_open!==!1,operation:"unchanged"}})}function cr(t,s){const a={...t.original_metrics},r=a[t.original_metric_name];return t.original_metric_name!==s&&delete a[t.original_metric_name],a[s]=r!=null&&t.metric_value===String(r)?r:t.metric_value,a}function dr(t){const s=t==null?void 0:t.trim();return s?Number(s):void 0}function Ht(t){const s=t.trim();return s?Number(s):null}function nt(t){return t.trim()||null}function it(t){return!!(t&&/^\d+$/.test(t.trim())&&Number.isSafeInteger(Number(t))&&Number(t)>0)}function ls(t){const s=[];return t.forEach((a,r)=>{var o;if(!a.operation||a.operation==="unchanged")return;const n=(i,d)=>{s.push({rowIndex:r,field:i,message:d})};if(a.operation!=="create"&&!it(a.id)&&n("id","This result has no valid evaluation ID. Reload the paper before editing it."),a.operation==="delete")return;it(a.task_id)||n("task_id","Select a valid task."),it(a.dataset_id)||n("dataset_id","Select a valid dataset.");const c=a.metric_name.trim();c?c!==a.original_metric_name&&Object.prototype.hasOwnProperty.call(a.original_metrics,c)&&n("metric_name",`Cannot rename a metric to "${c}": this evaluation already has that score.`):n("metric_name","Select a metric."),(o=a.best_rank)!=null&&o.trim()&&!Number.isSafeInteger(Number(a.best_rank))&&n("best_rank","Enter a whole-number rank."),a.num_parameters.trim()&&(!Number.isSafeInteger(Number(a.num_parameters))||Number(a.num_parameters)<0)&&n("num_parameters","Enter a non-negative whole-number parameter count."),a.metric_value.trim()||n("metric_value","Enter a metric value.")}),s}function ur(t,s){const a=ls(t);return a.length?{valid:!1,errors:a}:{valid:!0,operations:mr(t,s)}}function mr(t,s){const a=[];for(const r of t){if(r.operation==="delete"){a.push({kind:"delete",evaluationId:Number(r.id)});continue}if(r.operation!=="create"&&r.operation!=="update")continue;const n=r.metric_name.trim(),c=s(r.task_id,r.dataset_id),o={task_id:Number(r.task_id),dataset_id:Number(r.dataset_id),metrics:cr(r,n),best_metric:n,is_open:r.is_open},i=r.model_name.trim(),d=dr(r.best_rank);if(r.operation==="create"){const p=Ht(r.num_parameters),f=nt(r.hf_model_url);a.push({kind:"create",data:{...o,...i?{model_name:i}:{},...c&&r.harness.trim()?{harness:r.harness.trim()}:{},...d!==void 0?{best_rank:d}:{},...p!==null?{num_parameters:p}:{},...f!==null?{hf_model_url:f}:{}}});continue}a.push({kind:"update",evaluationId:Number(r.id),data:{...o,...i?{model_name:i}:{},harness:c?nt(r.harness):null,...d!==void 0?{best_rank:d}:{},num_parameters:Ht(r.num_parameters),hf_model_url:nt(r.hf_model_url)}})}return a}function hr(t,s){return s.map(a=>a.kind==="delete"?{operation:"delete",evaluation_id:a.evaluationId}:{operation:a.kind,...a.kind==="update"?{evaluation_id:a.evaluationId}:{},payload:a.kind==="create"?{paper_id:t,...a.data}:a.data})}function pr(t){return t.map(s=>s.kind==="delete"?{op:"delete",evaluation_id:s.evaluationId}:s.kind==="update"?{op:"update",evaluation_id:s.evaluationId,data:s.data}:{op:"create",data:s.data})}function ge({isAuthor:t=!1}){const s=typeof window<"u"&&window.location.hostname==="staging.paperswithcode.co";return e.jsxs("div",{className:"rounded-md border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-900 dark:border-amber-900 dark:bg-amber-950/40 dark:text-amber-100",children:[e.jsx("p",{className:"font-medium",children:s?"Test-only: this change stays on staging.":"Your changes will be reviewed by an admin."}),e.jsx("p",{className:"mt-1 leading-snug",children:s?"This exercises staging-local pending behavior and is not queued for production review.":t?"We can see this paper is yours. While we're in early access an admin still reviews each edit; this will become automatic for authors soon.":"Submissions are queued for review and don't change the paper page until an admin approves them."})]})}const ot=100;function fr(t){return(t??[]).some(s=>s.slug==="coding-agents"||s.name.trim().toLowerCase()==="coding agents")}function gr(t){const s=new Map;return t.forEach(a=>{a.task_id&&a.task_name&&s.set(a.task_id,{id:a.task_id,name:a.task_name,slug:a.task_slug,level:0})}),s}function xr(t){const s=new Map;return t.forEach(a=>{a.dataset_id&&a.dataset_name&&s.set(a.dataset_id,{id:a.dataset_id,name:a.dataset_name,slug:a.dataset_slug})}),s}function Mt(t,s){return`${t}:${s}`}function br({open:t,onOpenChange:s,paperId:a,arxivId:r,initialEvaluations:n,paperTasks:c,onSuccess:o,submitMode:i="direct",isAdmin:d=!1,isAuthor:p=!1}){const f=m.useId(),l=fr(c),[g,b]=m.useState([]),[w,j]=m.useState(!1),v=w?ls(g):[],[C,P]=m.useState(null),[I,S]=m.useState(new Map),[_,u]=m.useState(new Map),x=he(),{toast:E}=oe(),F=m.useRef(!1),M=m.useRef(!1);m.useEffect(()=>{if(!t){j(!1),F.current=!1,M.current=!1;return}F.current||M.current||n.length!==0&&(F.current=!0,b(lr(n)),S(gr(n)),u(xr(n)))},[t,n]);const O=m.useMemo(()=>Array.from(new Set(g.map(y=>y.task_id).filter(y=>y&&y!==""))),[g]),K=m.useMemo(()=>{const y=new Set;return g.forEach(k=>{k.task_id&&k.dataset_id&&y.add(Mt(k.task_id,k.dataset_id))}),Array.from(y)},[g]),G=ne({queryKey:["datasets-by-tasks-for-eval-edit",O,t],queryFn:async()=>{const y={};return await Promise.all(O.map(async k=>{try{const A=await _e.listDatasets({task_id:parseInt(k),page_size:ot});y[k]=A.results}catch(A){console.error(`Error fetching datasets for task ${k}:`,A),y[k]=[]}})),y},enabled:t&&O.length>0});m.useEffect(()=>{G.data&&u(y=>{const k=new Map(y);return Object.values(G.data).forEach(A=>{A.forEach(D=>{k.set(D.id,D)})}),k})},[G.data]);const h=ne({queryKey:["leaderboard-metrics-for-eval-edit",K,t],queryFn:async()=>{const y={};return await Promise.all(K.map(async k=>{const[A,D]=k.split(":");try{y[k]=await _e.leaderboardMetrics(D,A)}catch(Q){console.error(`Error fetching metrics for leaderboard ${k}:`,Q),y[k]=[]}})),y},enabled:t&&K.length>0}),$=async y=>{const k=await _e.listTasks({page_size:ot,...y?{q:y}:{}});return S(A=>{const D=new Map(A);return k.results.forEach(Q=>D.set(Q.id,Q)),D}),k.results.map(A=>{var D;return{value:A.id,label:A.name,description:(D=A.description)==null?void 0:D.slice(0,100)}})},R=y=>async k=>{const A=await _e.listDatasets({task_id:parseInt(y),page_size:ot,...k?{q:k}:{}});return u(D=>{const Q=new Map(D);return A.results.forEach(X=>Q.set(X.id,X)),Q}),A.results.map(D=>({value:D.id,label:D.name,description:D.full_name}))},T=(y,k)=>{if(!y||!k)return!1;const A=_.get(k);return!!(A!=null&&A.supports_harness)},U=(y,k,A)=>{var X;if(!y||!k)return[];const Q=(((X=h.data)==null?void 0:X[Mt(y,k)])||[]).map(B=>({value:B.metric_name,label:B.metric_name,description:B.metric_direction==="higher_is_better"?"Higher is better":"Lower is better"}));return A&&!Q.some(B=>B.value===A)&&Q.unshift({value:A,label:`${A} (legacy)`}),Q},z=ce({mutationFn:async({paperId:y,canonical:k})=>{if(!d&&i==="direct"&&k.length>50)throw new Error("Contributor evaluation batches are limited to 50 operations; contact an admin.");const A=Number.parseInt(y,10);if(i==="pending")await pe.submit({paper_id:A,edit_type:"evaluations",proposed_payload:{operations:pr(k)}});else{const D=wa(y,n,k,r);await Ke.batch(A,hr(A,k)),_a(x,D)}},onSuccess:()=>{if(i==="pending"){E({title:"Edit submitted for review",description:"Thanks! An admin will review your proposed evaluation changes shortly."}),o==null||o(),s(!1);return}o==null||o(),s(!1)},onError:y=>{const k=fe(y,i==="pending"?"Failed to submit your edit. Please try again.":"Failed to update evaluations.");E({title:i==="pending"?"Could not submit edit":"Could not save evaluations",description:k,variant:"destructive"})}}),H=()=>{M.current=!0,b([...g,{task_id:"",dataset_id:"",model_name:"",harness:"",metric_name:"",metric_value:"",original_metrics:{},original_metric_name:"",best_rank:"",num_parameters:"",hf_model_url:"",is_open:!0,operation:"create"}])},Y=y=>{if(M.current=!0,g[y].id){if(!window.confirm("Delete this evaluation? You will be asked to sign in again if your session is older than 15 minutes."))return;b(g.map((A,D)=>D===y?{...A,operation:"delete"}:A))}else b(g.filter((A,D)=>D!==y))},Z=(y,k,A)=>{M.current=!0,b(g.map((D,Q)=>{if(Q!==y||D[k]===A)return D;const X={...D,[k]:A};return(k==="task_id"||k==="dataset_id")&&(X.original_metrics={},X.original_metric_name="",X.metric_value="",X.best_rank=""),k==="task_id"&&(X.dataset_id="",X.metric_name="",X.harness=""),k==="dataset_id"&&(X.metric_name="",A&&!T(X.task_id,A)&&(X.harness="")),D.operation==="unchanged"&&(X.operation="update"),X}))},Ve=(y,k)=>{M.current=!0,b(g.map((A,D)=>{if(D!==y)return A;const Q={...A,is_open:k};return A.operation==="unchanged"&&(Q.operation="update"),Q}))},De=()=>{j(!0);const y=ur(g,T);if(y.valid){if(y.operations.length===0){E({title:"No changes to submit",description:"Your evaluation list matches the existing data."});return}z.mutate({paperId:a,canonical:y.operations})}},ve=(y,k)=>{const A=v.find(D=>D.rowIndex===y&&D.field===k);return A?e.jsx("p",{id:`${f}-${y}-${k}-error`,className:"text-xs text-destructive",children:A.message}):null};return e.jsxs(ee,{open:t,onOpenChange:s,children:[e.jsxs(te,{className:"max-w-6xl max-h-[800px]",children:[e.jsxs(se,{children:[e.jsx(ae,{children:"Edit Evaluation Results"}),e.jsx(re,{children:"Add, edit, or remove evaluation results for this paper. Each row represents a benchmark result."})]}),i==="pending"&&e.jsx(ge,{isAuthor:p}),v.length>0&&e.jsxs("div",{role:"alert",className:"text-sm text-destructive",children:["Fix the following errors before saving. No changes have been submitted.",e.jsx("ul",{children:v.map(y=>e.jsxs("li",{children:["Row ",g.slice(0,y.rowIndex+1).filter(k=>k.operation!=="delete").length,": ",y.message]},`${y.rowIndex}-${y.field}`))})]}),e.jsxs("div",{className:"py-4 overflow-y-auto max-h-[600px]",children:[g.filter(y=>y.operation!=="delete").length>0?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border",children:[e.jsx("th",{className:"text-left py-2 px-2 font-medium text-sm min-w-[180px]",children:"Task"}),e.jsx("th",{className:"text-left py-2 px-2 font-medium text-sm min-w-[180px]",children:"Dataset"}),e.jsx("th",{className:`text-left py-2 px-2 font-medium text-sm ${l?"min-w-[140px]":"min-w-[240px]"}`,children:"Model"}),l&&e.jsx("th",{className:"text-left py-2 px-2 font-medium text-sm min-w-[140px]",children:"Harness"}),e.jsx("th",{className:"text-left py-2 px-2 font-medium text-sm min-w-[140px]",children:"Metric"}),e.jsx("th",{className:"text-left py-2 px-2 font-medium text-sm",children:"Value"}),e.jsx("th",{className:"text-left py-2 px-2 font-medium text-sm",children:"Parameters"}),e.jsx("th",{className:"text-left py-2 px-2 font-medium text-sm min-w-[200px]",children:"HF model URL"}),e.jsx("th",{className:"text-left py-2 px-2 font-medium text-sm w-20",children:"Open source"}),e.jsx("th",{className:"text-left py-2 px-2 font-medium text-sm w-16",children:"Action"})]})}),e.jsx("tbody",{children:g.map((y,k)=>{if(y.operation==="delete")return null;const A=I.get(y.task_id),D=_.get(y.dataset_id),Q=U(y.task_id,y.dataset_id,y.metric_name),X=!!(y.task_id&&y.dataset_id)&&h.isFetching;return e.jsxs("tr",{className:"border-b border-border",children:[e.jsx("td",{className:"py-2 px-2",children:e.jsxs("div",{role:"group","aria-label":"Task","aria-describedby":`${f}-${k}-task_id-error`,children:[e.jsx(Tt,{value:y.task_id,onChange:B=>Z(k,"task_id",B),placeholder:"Select task",searchPlaceholder:"Search tasks...",emptyMessage:"No tasks found.",selectedOption:A?{value:A.id,label:A.name}:null,queryKey:["eval-edit-task-search"],queryFn:$,enabled:t}),ve(k,"task_id")]})}),e.jsx("td",{className:"py-2 px-2",children:e.jsxs("div",{role:"group","aria-label":"Dataset","aria-describedby":`${f}-${k}-dataset_id-error`,children:[e.jsx(Tt,{value:y.dataset_id,onChange:B=>Z(k,"dataset_id",B),placeholder:y.task_id?"Select dataset":"Select task first",searchPlaceholder:"Search datasets...",emptyMessage:y.task_id?"No datasets found for this task.":"Select a task first.",disabled:!y.task_id,selectedOption:D?{value:D.id,label:D.name}:null,queryKey:["eval-edit-dataset-search",y.task_id],queryFn:R(y.task_id),enabled:t&&!!y.task_id}),ve(k,"dataset_id")]})}),e.jsx("td",{className:"py-2 px-2",children:e.jsx(V,{type:"text",className:"w-full text-sm",placeholder:"Model name",value:y.model_name,onChange:B=>Z(k,"model_name",B.target.value)})}),l&&e.jsx("td",{className:"py-2 px-2",children:T(y.task_id,y.dataset_id)?e.jsx(V,{type:"text",className:"w-full text-sm",placeholder:"Claude Code, Terminus, ...",value:y.harness,onChange:B=>Z(k,"harness",B.target.value)}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"Not supported"})}),e.jsxs("td",{className:"py-2 px-2",children:[!y.task_id||!y.dataset_id?e.jsx("span",{className:"text-xs text-muted-foreground",children:"Select task + dataset"}):X?e.jsxs("span",{className:"inline-flex items-center text-xs text-muted-foreground",children:[e.jsx(ie,{className:"mr-1 h-3 w-3 animate-spin"}),"Loading metrics..."]}):Q.length>0?e.jsxs("select",{className:"w-full rounded-md border border-border bg-background px-2 py-1 text-sm",id:`${f}-${k}-metric_name`,"aria-invalid":v.some(B=>B.rowIndex===k&&B.field==="metric_name"),"aria-describedby":`${f}-${k}-metric_name-error`,value:y.metric_name,onChange:B=>Z(k,"metric_name",B.target.value),children:[e.jsx("option",{value:"",children:"Select metric"}),Q.map(B=>e.jsx("option",{value:B.value,children:B.label},B.value))]}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"No configured metrics"}),ve(k,"metric_name")]}),e.jsxs("td",{className:"py-2 px-2",children:[e.jsx(V,{type:"text",className:"w-full text-sm",placeholder:"44.9",id:`${f}-${k}-metric_value`,"aria-invalid":v.some(B=>B.rowIndex===k&&B.field==="metric_value"),"aria-describedby":`${f}-${k}-metric_value-error`,value:y.metric_value,onChange:B=>Z(k,"metric_value",B.target.value)}),ve(k,"metric_value")]}),e.jsxs("td",{className:"py-2 px-2",children:[e.jsx(V,{type:"number",min:0,step:1,className:"w-full text-sm",placeholder:"e.g. 7000000000",id:`${f}-${k}-num_parameters`,"aria-invalid":v.some(B=>B.rowIndex===k&&B.field==="num_parameters"),"aria-describedby":`${f}-${k}-num_parameters-error`,value:y.num_parameters,onChange:B=>Z(k,"num_parameters",B.target.value),title:"Raw model parameter count (e.g. 7000000000 for a 7B model). Leave blank if unknown."}),ve(k,"num_parameters")]}),e.jsx("td",{className:"py-2 px-2",children:e.jsx(V,{type:"url",className:"w-full text-sm",placeholder:"https://huggingface.co/org/model",value:y.hf_model_url,onChange:B=>Z(k,"hf_model_url",B.target.value),title:"Hugging Face model page for this row (must start with https://huggingface.co/). Leave blank if none."})}),e.jsx("td",{className:"py-2 px-2 text-center",children:e.jsx("input",{type:"checkbox",className:"h-4 w-4 align-middle",checked:y.is_open,onChange:B=>Ve(k,B.target.checked),title:"Whether the evaluated model is open-source. Uncheck for closed-source models."})}),e.jsx("td",{className:"py-2 px-2",children:e.jsx(L,{variant:"ghost",size:"sm",onClick:()=>Y(k),className:"h-8 w-8 p-0 text-destructive hover:text-destructive",title:y.id&&!d?"Only administrators can delete published results":"Remove row",disabled:!!y.id&&!d,children:e.jsx(Te,{className:"w-4 h-4"})})})]},k)})})]})}):e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(Na,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),e.jsx("p",{children:"No evaluation results yet"}),e.jsx("p",{className:"text-sm mt-2",children:'Click "Add Row" below to add a new evaluation'})]}),e.jsx("div",{className:"mt-4",children:e.jsxs(L,{variant:"outline",size:"sm",onClick:H,className:"flex items-center space-x-2",children:[e.jsx(Ue,{className:"w-4 h-4"}),e.jsx("span",{children:"Add Row"})]})})]}),e.jsxs(le,{children:[e.jsxs("div",{className:"flex flex-wrap gap-2 sm:mr-auto",children:[e.jsx(L,{variant:"ghost",onClick:()=>P("benchmark"),children:"Suggest a new benchmark"}),e.jsx(L,{variant:"ghost",onClick:()=>P("metric"),children:"Suggest a new metric"})]}),e.jsx(L,{variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsx(L,{onClick:De,disabled:z.isPending,children:z.isPending?e.jsxs(e.Fragment,{children:[e.jsx(ie,{className:"w-4 h-4 mr-2 animate-spin"}),i==="pending"?"Submitting...":"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(me,{className:"w-4 h-4 mr-2"}),i==="pending"?"Submit for review":"Save Changes"]})})]})]}),e.jsx(wt,{open:C!==null,onOpenChange:y=>{y||P(null)},paperId:a,kind:C??"benchmark"})]})}const lt=[{key:"hf_models",label:"Models",placeholder:"https://huggingface.co/org/model"},{key:"hf_datasets",label:"Datasets",placeholder:"https://huggingface.co/datasets/org/data"},{key:"hf_spaces",label:"Spaces",placeholder:"https://huggingface.co/spaces/org/demo"}];function qt(t){return t.map(s=>s.trim()).filter(Boolean)}function ct(t,s){const a=qt(t).sort(),r=qt(s).sort();return a.length!==r.length?!1:a.every((n,c)=>n===r[c])}function jr(t,s){return ct(t.hf_models,s.hf_models)&&ct(t.hf_datasets,s.hf_datasets)&&ct(t.hf_spaces,s.hf_spaces)}function vr({open:t,onOpenChange:s,paperId:a,arxivId:r,initialArtifacts:n,onSuccess:c,submitMode:o="direct",isAuthor:i=!1}){const[d,p]=m.useState(n),[f,l]=m.useState({hf_models:"",hf_datasets:"",hf_spaces:""}),g=he(),{toast:b}=oe(),w=m.useRef(!1);m.useEffect(()=>{if(!t){w.current=!1;return}w.current||(w.current=!0,p(n),l({hf_models:"",hf_datasets:"",hf_spaces:""}))},[t,n]);const j=ce({mutationFn:async({paperId:_,artifacts:u})=>o==="pending"?(await pe.submit({paper_id:parseInt(_),edit_type:"hf_artifacts",proposed_payload:u}),null):W.updateHfArtifacts(_,u),onSuccess:_=>{if(o==="pending"){b({title:"Edit submitted for review",description:"Thanks! An admin will review your proposed Hugging Face artifact changes shortly."}),c==null||c(),s(!1),l({hf_models:"",hf_datasets:"",hf_spaces:""});return}_&&je(g,_,[a,r]),c==null||c(),s(!1),l({hf_models:"",hf_datasets:"",hf_spaces:""})},onError:_=>{const u=fe(_,o==="pending"?"Failed to submit your edit. Please try again.":"Failed to update Hugging Face artifacts.");b({title:o==="pending"?"Could not submit edit":"Could not save Hugging Face artifacts",description:u,variant:"destructive"})}}),v=()=>{const _={hf_models:[...d.hf_models],hf_datasets:[...d.hf_datasets],hf_spaces:[...d.hf_spaces]};for(const{key:u}of lt){const x=f[u].trim();if(x){if(_[u].some(E=>E.trim()===x))return alert(`This ${u.replace("hf_","")} URL is already added`),null;_[u]=[..._[u],x]}}return _},C=_=>{const u=f[_].trim();if(u){if(d[_].some(x=>x.trim()===u)){alert(`This ${_.replace("hf_","")} URL is already added`);return}p(x=>({...x,[_]:[...x[_],u]})),l(x=>({...x,[_]:""}))}},P=(_,u)=>{p(x=>({...x,[_]:x[_].filter(E=>E!==u)}))},I=()=>{const _=v();if(_===null)return;const u=Object.keys(n).some(x=>n[x].some(E=>!_[x].includes(E)));o==="direct"&&u&&!window.confirm("Remove one or more Hugging Face artifact links?")||j.mutate({paperId:a,artifacts:_})},S=m.useMemo(()=>{const _={hf_models:[...d.hf_models],hf_datasets:[...d.hf_datasets],hf_spaces:[...d.hf_spaces]};for(const{key:u}of lt){const x=f[u].trim();if(x){if(_[u].some(E=>E.trim()===x))return!1;_[u]=[..._[u],x]}}return!jr(_,n)},[d,f,n]);return e.jsx(ee,{open:t,onOpenChange:s,children:e.jsxs(te,{className:"max-w-2xl max-h-[700px]",children:[e.jsxs(se,{children:[e.jsx(ae,{children:"Edit Hugging Face Artifacts"}),e.jsx(re,{children:"Add or remove linked Hugging Face models, datasets, and Spaces for this paper."})]}),o==="pending"&&e.jsx(ge,{isAuthor:i}),e.jsx("div",{className:"space-y-6 py-2 overflow-y-auto max-h-[460px]",children:lt.map(({key:_,label:u,placeholder:x})=>e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:u}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(V,{type:"url",placeholder:x,value:f[_],onChange:E=>l(F=>({...F,[_]:E.target.value})),onKeyPress:E=>{E.key==="Enter"&&(E.preventDefault(),C(_))},className:"flex-1"}),e.jsxs(L,{onClick:()=>C(_),size:"sm",disabled:!f[_].trim(),children:[e.jsx(Ue,{className:"w-4 h-4 mr-1"}),"Add"]})]}),d[_].length>0?e.jsx("div",{className:"space-y-2",children:d[_].map(E=>e.jsxs("div",{className:"flex items-center space-x-2 p-3 bg-muted/30 rounded-lg hover:bg-muted/50 transition-colors",children:[e.jsx("span",{className:"text-sm font-medium text-paper-blue truncate flex-1",children:E}),e.jsx(L,{variant:"ghost",size:"sm",onClick:()=>P(_,E),className:"h-8 px-2 text-destructive hover:text-destructive",title:`Remove ${u.toLowerCase()} URL`,children:e.jsx(Te,{className:"w-4 h-4"})})]},E))}):e.jsxs("div",{className:"text-xs text-muted-foreground",children:["No ",u.toLowerCase()," linked yet."]})]},_))}),e.jsxs(le,{children:[e.jsx(L,{variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsx(L,{onClick:I,disabled:j.isPending||!S,children:j.isPending?e.jsxs(e.Fragment,{children:[e.jsx(ie,{className:"w-4 h-4 mr-2 animate-spin"}),o==="pending"?"Submitting...":"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(me,{className:"w-4 h-4 mr-2"}),o==="pending"?"Submit for review":"Save Changes"]})})]})]})})}var Ge="Checkbox",[yr]=vt(Ge),[wr,_t]=yr(Ge);function _r(t){const{__scopeCheckbox:s,checked:a,children:r,defaultChecked:n,disabled:c,form:o,name:i,onCheckedChange:d,required:p,value:f="on",internal_do_not_use_render:l}=t,[g,b]=Yt({prop:a,defaultProp:n??!1,onChange:d,caller:Ge}),[w,j]=m.useState(null),[v,C]=m.useState(null),P=m.useRef(!1),I=w?!!o||!!w.closest("form"):!0,S={checked:g,disabled:c,setChecked:b,control:w,setControl:j,name:i,form:o,value:f,hasConsumerStoppedPropagationRef:P,required:p,defaultChecked:be(n)?!1:n,isFormControl:I,bubbleInput:v,setBubbleInput:C};return e.jsx(wr,{scope:s,...S,children:kr(l)?l(S):r})}var cs="CheckboxTrigger",ds=m.forwardRef(({__scopeCheckbox:t,onKeyDown:s,onClick:a,...r},n)=>{const{control:c,value:o,disabled:i,checked:d,required:p,setControl:f,setChecked:l,hasConsumerStoppedPropagationRef:g,isFormControl:b,bubbleInput:w}=_t(cs,t),j=Fe(n,f),v=m.useRef(d);return m.useEffect(()=>{const C=c==null?void 0:c.form;if(C){const P=()=>l(v.current);return C.addEventListener("reset",P),()=>C.removeEventListener("reset",P)}},[c,l]),e.jsx(ke.button,{type:"button",role:"checkbox","aria-checked":be(d)?"mixed":d,"aria-required":p,"data-state":fs(d),"data-disabled":i?"":void 0,disabled:i,value:o,...r,ref:j,onKeyDown:Re(s,C=>{C.key==="Enter"&&C.preventDefault()}),onClick:Re(a,C=>{l(P=>be(P)?!0:!P),w&&b&&(g.current=C.isPropagationStopped(),g.current||C.stopPropagation())})})});ds.displayName=cs;var kt=m.forwardRef((t,s)=>{const{__scopeCheckbox:a,name:r,checked:n,defaultChecked:c,required:o,disabled:i,value:d,onCheckedChange:p,form:f,...l}=t;return e.jsx(_r,{__scopeCheckbox:a,checked:n,defaultChecked:c,disabled:i,required:o,onCheckedChange:p,name:r,form:f,value:d,internal_do_not_use_render:({isFormControl:g})=>e.jsxs(e.Fragment,{children:[e.jsx(ds,{...l,ref:s,__scopeCheckbox:a}),g&&e.jsx(ps,{__scopeCheckbox:a})]})})});kt.displayName=Ge;var us="CheckboxIndicator",ms=m.forwardRef((t,s)=>{const{__scopeCheckbox:a,forceMount:r,...n}=t,c=_t(us,a);return e.jsx(Jt,{present:r||be(c.checked)||c.checked===!0,children:e.jsx(ke.span,{"data-state":fs(c.checked),"data-disabled":c.disabled?"":void 0,...n,ref:s,style:{pointerEvents:"none",...t.style}})})});ms.displayName=us;var hs="CheckboxBubbleInput",ps=m.forwardRef(({__scopeCheckbox:t,...s},a)=>{const{control:r,hasConsumerStoppedPropagationRef:n,checked:c,defaultChecked:o,required:i,disabled:d,name:p,value:f,form:l,bubbleInput:g,setBubbleInput:b}=_t(hs,t),w=Fe(a,b),j=as(c),v=Zt(r);m.useEffect(()=>{const P=g;if(!P)return;const I=window.HTMLInputElement.prototype,_=Object.getOwnPropertyDescriptor(I,"checked").set,u=!n.current;if(j!==c&&_){const x=new Event("click",{bubbles:u});P.indeterminate=be(c),_.call(P,be(c)?!1:c),P.dispatchEvent(x)}},[g,j,c,n]);const C=m.useRef(be(c)?!1:c);return e.jsx(ke.input,{type:"checkbox","aria-hidden":!0,defaultChecked:o??C.current,required:i,disabled:d,name:p,value:f,form:l,...s,tabIndex:-1,ref:w,style:{...s.style,...v,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});ps.displayName=hs;function kr(t){return typeof t=="function"}function be(t){return t==="indeterminate"}function fs(t){return be(t)?"indeterminate":t?"checked":"unchecked"}const Xe=m.forwardRef(({className:t,style:s,...a},r)=>e.jsx(kt,{ref:r,className:Me("peer h-4 w-4 shrink-0 rounded-sm ring-offset-background data-[state=checked]:!bg-black data-[state=checked]:!text-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",t),style:{border:"1px solid #000",...s},...a,children:e.jsx(ms,{className:Me("flex items-center justify-center text-current"),children:e.jsx(me,{className:"h-4 w-4"})})}));Xe.displayName=kt.displayName;const Nr=250,Cr=100;function Er({open:t,onOpenChange:s,paperId:a,arxivId:r,initialMethodIds:n,initialMethods:c,onSuccess:o,submitMode:i="direct",isAuthor:d=!1}){const[p,f]=m.useState(n),[l,g]=m.useState(!1),[b,w]=m.useState(""),[j,v]=m.useState(""),[C,P]=m.useState(new Map),I=he(),{toast:S}=oe(),_=m.useRef(!1);m.useEffect(()=>{if(!t){_.current=!1;return}if(_.current)return;_.current=!0,f(n),w(""),v("");const h=new Map;(c||[]).forEach($=>{const R=parseInt($.id);Number.isNaN(R)||h.set(R,$)}),P(h)},[t,n,c]),m.useEffect(()=>{const h=window.setTimeout(()=>{v(b.trim())},Nr);return()=>window.clearTimeout(h)},[b]);const{data:u,isFetching:x}=ne({queryKey:["methods-search",j],queryFn:()=>_e.listMethods({page_size:Cr,...j?{q:j}:{}}),enabled:t});m.useEffect(()=>{var h;(h=u==null?void 0:u.results)!=null&&h.length&&P($=>{const R=new Map($);return u.results.forEach(T=>{const U=parseInt(T.id);Number.isNaN(U)||R.set(U,T)}),R})},[u]);const E=m.useMemo(()=>{const h=(u==null?void 0:u.results)||[],$=new Set,R=[],T=(H,Y)=>{!Y||Number.isNaN(H)||$.has(H)||(R.push(Y),$.add(H))},U=()=>p.forEach(H=>T(H,C.get(H))),z=()=>h.forEach(H=>T(parseInt(H.id),H));return j?(z(),U()):(U(),z()),R},[u,p,C,j]),F=ce({mutationFn:async({paperId:h,methodIds:$})=>i==="pending"?(await pe.submit({paper_id:parseInt(h),edit_type:"methods",proposed_payload:{method_ids:$}}),null):W.updateMethods(h,$),onSuccess:h=>{if(i==="pending"){S({title:"Edit submitted for review",description:"Thanks! An admin will review your proposed method changes shortly."}),o==null||o(),s(!1);return}h&&je(I,h,[a,r]),S({title:"Methods updated",description:`Saved ${p.length} method${p.length===1?"":"s"} for this paper.`}),o==null||o(),s(!1)},onError:h=>{const $=fe(h,i==="pending"?"Failed to submit your edit. Please try again.":"Failed to update paper methods.");S({title:i==="pending"?"Could not submit edit":"Could not save methods",description:$,variant:"destructive"})}}),M=()=>{i==="direct"&&n.some(h=>!p.includes(h))&&!window.confirm("Remove one or more method links from this paper?")||F.mutate({paperId:a,methodIds:p})},O=m.useMemo(()=>{if(p.length!==n.length)return!0;const h=new Set(n);return p.some($=>!h.has($))},[p,n]),K=(h,$)=>{f(R=>$?R.includes(h)?R:[...R,h]:R.filter(T=>T!==h))},G=()=>w("");return e.jsxs(ee,{open:t,onOpenChange:s,children:[e.jsxs(te,{className:"max-w-2xl max-h-[600px]",children:[e.jsxs(se,{children:[e.jsx(ae,{children:"Edit Paper Methods"}),e.jsx(re,{children:"Select the methods and techniques used in this paper. You can select multiple methods."})]}),i==="pending"&&e.jsx(ge,{isAuthor:d}),e.jsxs("div",{className:"relative mb-4",children:[e.jsx(Ae,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(V,{type:"text",placeholder:"Search methods...",value:b,onChange:h=>w(h.target.value),className:"pl-9 pr-9"}),b&&e.jsx("button",{type:"button",onClick:G,className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 text-muted-foreground hover:text-foreground","aria-label":"Clear search",children:e.jsx(yt,{className:"w-4 h-4"})})]}),e.jsx("div",{className:"py-4 overflow-y-auto max-h-[400px]",children:E.length>0?e.jsx("div",{className:"space-y-2",children:E.map(h=>{const $=parseInt(h.id),R=p.includes($);return e.jsxs("div",{className:"flex items-center space-x-2 p-2 hover:bg-muted/50 rounded-md",children:[e.jsx(Xe,{id:`method-${h.id}`,checked:R,onCheckedChange:T=>K($,T===!0),className:"!border !border-black data-[state=checked]:!bg-black data-[state=checked]:!text-white"}),e.jsxs("label",{htmlFor:`method-${h.id}`,className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 cursor-pointer flex-1",children:[h.name,h.full_name&&h.full_name!==h.name&&e.jsx("span",{className:"block text-xs text-muted-foreground font-normal",children:h.full_name}),h.description&&e.jsxs("span",{className:"block text-xs text-muted-foreground font-normal mt-1",children:[h.description.substring(0,100),h.description.length>100?"...":""]})]})]},h.id)})}):x?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(ie,{className:"w-8 h-8 mx-auto mb-2 animate-spin"}),e.jsx("p",{children:"Loading methods..."})]}):e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(Ae,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:j?`No methods found matching "${j}"`:"No methods available"})]})}),e.jsxs(le,{children:[e.jsx(L,{variant:"ghost",className:"sm:mr-auto",onClick:()=>g(!0),children:"Suggest a new method"}),e.jsx(L,{variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsx(L,{onClick:M,disabled:F.isPending||!O,children:F.isPending?e.jsxs(e.Fragment,{children:[e.jsx(ie,{className:"w-4 h-4 mr-2 animate-spin"}),i==="pending"?"Submitting...":"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(me,{className:"w-4 h-4 mr-2"}),i==="pending"?"Submit for review":"Save Changes"]})})]})]}),e.jsx(wt,{open:l,onOpenChange:g,paperId:a,kind:"method"})]})}const gs=["image/jpeg","image/png","image/webp","image/gif"],Sr=2*1024*1024;function Pr(t){return gs.includes(t.type)?t.size>Sr?Promise.reject(new Error("Logo must be 2 MB or smaller.")):new Promise((s,a)=>{const r=new FileReader;r.onload=()=>s({file_name:t.name,mime_type:t.type,data_url:String(r.result)}),r.onerror=()=>a(new Error("Could not read that logo.")),r.readAsDataURL(t)}):Promise.reject(new Error("Choose a JPEG, PNG, WebP, or GIF logo."))}function $r({paperId:t,initialName:s}){const[a,r]=m.useState(s),[n,c]=m.useState(""),[o,i]=m.useState(""),[d,p]=m.useState(null),[f,l]=m.useState(""),g=ce({mutationFn:()=>pe.submit(ya(Number(t),"new_organization",{name:a.trim(),...n.trim()?{hf_slug:n.trim()}:{},...o.trim()?{website_url:o.trim()}:{},...d?{image:d}:{}}))});return g.isSuccess?e.jsxs("p",{className:"rounded border p-3 text-sm",children:['Thanks! "',a.trim(),'" was submitted for review. Once an admin approves it, the organization is created and added to this paper.']}):e.jsxs("form",{className:"space-y-2 rounded border p-3",onSubmit:b=>{b.preventDefault(),g.mutate()},children:[e.jsx("p",{className:"text-sm font-medium",children:"Suggest a new organization"}),e.jsx(V,{"aria-label":"Organization name",placeholder:"Name",value:a,maxLength:200,onChange:b=>r(b.target.value)}),e.jsx(V,{"aria-label":"Hugging Face organization",placeholder:"Hugging Face organization (e.g. https://huggingface.co/PrimeIntellect)",value:n,onChange:b=>c(b.target.value)}),e.jsx(V,{"aria-label":"Website",type:"url",placeholder:"Website (e.g. https://www.primeintellect.ai)",value:o,onChange:b=>i(b.target.value)}),e.jsxs("label",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:["Logo (optional)",e.jsx("input",{"aria-label":"Logo",type:"file",accept:gs.join(","),onChange:b=>{var j;const w=(j=b.target.files)==null?void 0:j[0];p(null),l(""),w&&Pr(w).then(p,v=>l(v.message))}})]}),d&&e.jsx("img",{src:d.data_url,alt:"Selected logo",className:"h-12 w-12 rounded border object-contain"}),f&&e.jsx("p",{className:"text-sm text-destructive",children:f}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"An admin reviews every new organization."}),e.jsx(L,{type:"submit",variant:"outline",disabled:!a.trim()||!n.trim()&&!o.trim()||g.isPending,children:g.isPending?"Submitting...":"Submit for review"})]}),g.error&&e.jsx("p",{className:"text-sm text-destructive",children:fe(g.error,"Could not submit this organization.")})]})}const Ir=({open:t,onOpenChange:s,paperId:a,initialOrganizationIds:r,submitMode:n,isAuthor:c})=>{var w;const[o,i]=m.useState(r),[d,p]=m.useState(""),f=he();m.useEffect(()=>{t&&(i(r),p(""))},[r,t]);const l=ne({queryKey:["organizations","curation"],queryFn:()=>_e.organizations(!1),enabled:t}),g=m.useMemo(()=>{var C,P;const j=d.trim().toLocaleLowerCase();if(!j)return((C=l.data)==null?void 0:C.results)??[];const v=I=>I===j?0:I.startsWith(j)?1:I.split(/[^\p{L}\p{N}]+/u).some(S=>S.startsWith(j))?2:3;return(((P=l.data)==null?void 0:P.results)??[]).map(I=>({organization:I,name:I.name.toLocaleLowerCase()})).filter(({name:I})=>I.includes(j)).sort((I,S)=>v(I.name)-v(S.name)).map(({organization:I})=>I)},[(w=l.data)==null?void 0:w.results,d]),b=ce({mutationFn:async()=>{if(!(r.some(v=>!o.includes(v))&&!window.confirm("Remove one or more organizations from this paper? Destructive edits may require a fresh sign-in.")))return n==="pending"?(await pe.submit({paper_id:Number(a),edit_type:"organizations",proposed_payload:{organization_ids:o}}),null):W.updateOrganizations(a,o)},onSuccess:j=>{j!==void 0&&(j&&je(f,j,[a]),s(!1))}});return e.jsx(ee,{open:t,onOpenChange:s,children:e.jsxs(te,{children:[e.jsxs(se,{children:[e.jsx(ae,{children:"Edit organizations"}),e.jsx(re,{children:"Associate organizations with this paper. If one is missing, search for it and suggest it for review."})]}),n==="pending"&&e.jsx(ge,{isAuthor:c}),e.jsxs("div",{className:"relative",children:[e.jsx(Ae,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(V,{type:"search","aria-label":"Search organizations",placeholder:"Search organizations...",value:d,onChange:j=>p(j.target.value),className:"pl-9 pr-9"}),d&&e.jsx("button",{type:"button",onClick:()=>p(""),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 text-muted-foreground hover:text-foreground","aria-label":"Clear organization search",children:e.jsx(yt,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"max-h-80 space-y-2 overflow-auto",children:[g.map(j=>{const v=Number(j.id);return e.jsxs("label",{className:"flex items-center gap-2 rounded border p-2",children:[e.jsx("input",{type:"checkbox",checked:o.includes(v),onChange:C=>i(P=>C.target.checked?[...P,v]:P.filter(I=>I!==v))}),j.name]},j.id)}),!l.isLoading&&g.length===0&&e.jsx("p",{className:"py-8 text-center text-sm text-muted-foreground",children:d.trim()?`No organizations found matching "${d.trim()}"`:"No organizations available"})]}),!l.isLoading&&g.length===0&&d.trim()&&e.jsx($r,{paperId:a,initialName:d.trim()},d.trim()),e.jsxs(le,{children:[e.jsx(L,{variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsx(L,{onClick:()=>b.mutate(),disabled:b.isPending,children:n==="pending"?"Submit test edit":"Save changes"})]})]})})};function Rr({open:t,onOpenChange:s,paperId:a,arxivId:r,initialProjectPages:n,onSuccess:c,submitMode:o="direct",isAuthor:i=!1}){const[d,p]=m.useState(n),[f,l]=m.useState(""),g=he(),{toast:b}=oe(),w=m.useRef(!1);m.useEffect(()=>{if(!t){w.current=!1;return}w.current||(w.current=!0,p(n),l(""))},[t,n]);const j=ce({mutationFn:async({paperId:u,projectPages:x})=>o==="pending"?(await pe.submit({paper_id:parseInt(u),edit_type:"project_pages",proposed_payload:{project_pages:x}}),null):W.updateProjectPages(u,x),onSuccess:u=>{if(o==="pending"){b({title:"Edit submitted for review",description:"Thanks! An admin will review your proposed project page changes shortly."}),c==null||c(),s(!1),l("");return}u&&je(g,u,[a,r]),c==null||c(),s(!1),l("")},onError:u=>{const x=fe(u,o==="pending"?"Failed to submit your edit. Please try again.":"Failed to update project pages.");b({title:o==="pending"?"Could not submit edit":"Could not save project pages",description:x,variant:"destructive"})}}),v=()=>{const u=f.trim();return u?d.some(x=>x.url===u)?(alert("This project page URL is already added"),null):[...d,{url:u,is_official:!1}]:d},C=()=>{const u=v();u!==null&&u.length!==d.length&&(p(u),l(""))},P=u=>{p(d.filter(x=>x.url!==u))},I=u=>{p(d.map(x=>x.url===u?{...x,is_official:!x.is_official}:x))},S=()=>{const u=v();u!==null&&(o==="direct"&&n.some(x=>!u.some(E=>E.url===x.url))&&!window.confirm("Remove one or more project pages from this paper?")||j.mutate({paperId:a,projectPages:u}))},_=m.useMemo(()=>{const u=f.trim(),x=u?[...d,{url:u,is_official:!1}]:d;if(x.length!==n.length)return!0;const E=new Map(n.map(F=>[F.url.trim(),!!F.is_official]));return x.some(F=>{const M=E.get(F.url.trim());return M===void 0||M!==!!F.is_official})},[d,f,n]);return e.jsx(ee,{open:t,onOpenChange:s,children:e.jsxs(te,{className:"max-w-2xl max-h-[600px]",children:[e.jsxs(se,{children:[e.jsx(ae,{children:"Edit Paper Project Pages"}),e.jsx(re,{children:"Add or remove project page URLs (e.g. authors' demo or landing pages) associated with this paper. Mark pages as official if they are created by the paper authors."})]}),o==="pending"&&e.jsx(ge,{isAuthor:i}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Add Project Page URL"}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(V,{type:"url",placeholder:"https://example.com/project",value:f,onChange:u=>l(u.target.value),onKeyPress:u=>{u.key==="Enter"&&(u.preventDefault(),C())},className:"flex-1"}),e.jsxs(L,{onClick:C,size:"sm",disabled:!f.trim(),children:[e.jsx(Ue,{className:"w-4 h-4 mr-1"}),"Add"]})]})]}),e.jsx("div",{className:"py-4 overflow-y-auto max-h-[350px]",children:d.length>0?e.jsx("div",{className:"space-y-2",children:d.map((u,x)=>e.jsxs("div",{className:"flex items-center space-x-2 p-3 bg-muted/30 rounded-lg hover:bg-muted/50 transition-colors",children:[e.jsx(zt,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("span",{className:"text-sm font-medium text-paper-blue truncate",children:u.url}),u.is_official&&e.jsx(rs,{variant:"secondary",className:"text-xs",children:"Official"})]})}),e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsxs(L,{variant:u.is_official?"default":"outline",size:"sm",onClick:()=>I(u.url),className:"h-8 px-2 text-xs",title:u.is_official?"Click to unmark as official (created by paper authors)":"Click to mark as official (created by paper authors)",children:[e.jsx(ns,{className:`w-3.5 h-3.5 mr-1 ${u.is_official?"fill-current":""}`}),u.is_official?"Official":"Mark official"]}),e.jsx(L,{variant:"ghost",size:"sm",onClick:()=>P(u.url),className:"h-8 px-2 text-destructive hover:text-destructive",title:"Remove project page",children:e.jsx(Te,{className:"w-4 h-4"})})]})]},x))}):e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(zt,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No project pages added yet"}),e.jsx("p",{className:"text-xs mt-1",children:"Add a project page URL above to get started"})]})}),e.jsxs(le,{children:[e.jsx(L,{variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsx(L,{onClick:S,disabled:j.isPending||!_,children:j.isPending?e.jsxs(e.Fragment,{children:[e.jsx(ie,{className:"w-4 h-4 mr-2 animate-spin"}),o==="pending"?"Submitting...":"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(me,{className:"w-4 h-4 mr-2"}),o==="pending"?"Submit for review":"Save Changes"]})})]})]})})}function Ar({open:t,onOpenChange:s,paperId:a,arxivId:r,initialRepositories:n,onSuccess:c,submitMode:o="direct",isAuthor:i=!1}){const[d,p]=m.useState(n),[f,l]=m.useState(""),g=he(),{toast:b}=oe(),w=m.useRef(!1);m.useEffect(()=>{if(!t){w.current=!1;return}w.current||(w.current=!0,p(n),l(""))},[t,n]);const j=ce({mutationFn:async({paperId:x,repositories:E})=>o==="pending"?(await pe.submit({paper_id:parseInt(x),edit_type:"repositories",proposed_payload:{repositories:E}}),null):W.updateRepositories(x,E),onSuccess:x=>{if(o==="pending"){b({title:"Edit submitted for review",description:"Thanks! An admin will review your proposed repository changes shortly."}),c==null||c(),s(!1),l("");return}x&&je(g,x,[a,r]),c==null||c(),s(!1),l("")},onError:x=>{const E=fe(x,o==="pending"?"Failed to submit your edit. Please try again.":"Failed to update paper repositories.");b({title:o==="pending"?"Could not submit edit":"Could not save repositories",description:E,variant:"destructive"})}}),v=x=>{const E=[];for(const F of x){const M=E.find(O=>Ut(O.url,F.url));if(M)M.is_official=M.is_official||F.is_official;else{const O=Ye(F.url);E.push({url:O??F.url.trim(),is_official:F.is_official})}}return E},C=()=>{const x=f.trim(),E=x?[...d,{url:x,is_official:!1}]:d;return x&&d.some(F=>Ut(F.url,x))?(alert("This repository URL is already added"),null):v(E)},P=()=>{const x=C();x!==null&&x.length!==d.length&&(p(x),l(""))},I=x=>{p(d.filter(E=>E.url!==x))},S=x=>{p(d.map(E=>E.url===x?{...E,is_official:!E.is_official}:E))},_=()=>{const x=C();x!==null&&(o==="direct"&&n.some(E=>!x.some(F=>F.url===E.url))&&!window.confirm("Remove one or more repositories from this paper?")||j.mutate({paperId:a,repositories:x}))},u=m.useMemo(()=>{const x=f.trim(),E=x?[...d,{url:x,is_official:!1}]:d;if(E.length!==n.length)return!0;const F=v(n),M=v(E);if(M.length!==F.length)return!0;const O=new Map(F.map(K=>[Ye(K.url)??K.url.trim(),!!K.is_official]));return M.some(K=>{const G=Ye(K.url)??K.url.trim(),h=O.get(G);return h===void 0||h!==!!K.is_official})},[d,f,n]);return e.jsx(ee,{open:t,onOpenChange:s,children:e.jsxs(te,{className:"max-w-2xl max-h-[600px]",children:[e.jsxs(se,{children:[e.jsx(ae,{children:"Edit Paper Repositories"}),e.jsx(re,{children:"Add or remove GitHub repository URLs associated with this paper. Mark repositories as official if they are created by the paper authors."})]}),o==="pending"&&e.jsx(ge,{isAuthor:i}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Add Repository URL"}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(V,{type:"url",placeholder:"https://github.com/owner/repo",value:f,onChange:x=>l(x.target.value),onKeyPress:x=>{x.key==="Enter"&&(x.preventDefault(),P())},className:"flex-1"}),e.jsxs(L,{onClick:P,size:"sm",disabled:!f.trim(),children:[e.jsx(Ue,{className:"w-4 h-4 mr-1"}),"Add"]})]})]}),e.jsx("div",{className:"py-4 overflow-y-auto max-h-[350px]",children:d.length>0?e.jsx("div",{className:"space-y-2",children:d.map((x,E)=>e.jsxs("div",{className:"flex items-center space-x-2 p-3 bg-muted/30 rounded-lg hover:bg-muted/50 transition-colors",children:[e.jsx(Dt,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("span",{className:"text-sm font-medium text-paper-blue truncate",children:x.url}),x.is_official&&e.jsx(rs,{variant:"secondary",className:"text-xs",children:"Official"})]})}),e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsxs(L,{variant:x.is_official?"default":"outline",size:"sm",onClick:()=>S(x.url),className:"h-8 px-2 text-xs",title:x.is_official?"Click to unmark as official (created by paper authors)":"Click to mark as official (created by paper authors)",children:[e.jsx(ns,{className:`w-3.5 h-3.5 mr-1 ${x.is_official?"fill-current":""}`}),x.is_official?"Official":"Mark official"]}),e.jsx(L,{variant:"ghost",size:"sm",onClick:()=>I(x.url),className:"h-8 px-2 text-destructive hover:text-destructive",title:"Remove repository",children:e.jsx(Te,{className:"w-4 h-4"})})]})]},E))}):e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(Dt,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No repositories added yet"}),e.jsx("p",{className:"text-xs mt-1",children:"Add a repository URL above to get started"})]})}),e.jsxs(le,{children:[e.jsx(L,{variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsx(L,{onClick:_,disabled:j.isPending||!u,children:j.isPending?e.jsxs(e.Fragment,{children:[e.jsx(ie,{className:"w-4 h-4 mr-2 animate-spin"}),o==="pending"?"Submitting...":"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(me,{className:"w-4 h-4 mr-2"}),o==="pending"?"Submit for review":"Save Changes"]})})]})]})})}function Lr({open:t,onOpenChange:s,paperId:a,arxivId:r,initialUrl:n,onSuccess:c,submitMode:o="direct",isAuthor:i=!1}){const[d,p]=m.useState(n),f=he(),{toast:l}=oe(),g=m.useRef(!1);m.useEffect(()=>{if(!t){g.current=!1;return}g.current||(g.current=!0,p(n))},[t,n]);const b=ce({mutationFn:async({paperId:P,sourceUrl:I})=>o==="pending"?(await pe.submit({paper_id:parseInt(P),edit_type:"source_url",proposed_payload:{source_url:I}}),null):W.updateSourceUrl(P,I),onSuccess:P=>{if(o==="pending"){l({title:"Edit submitted for review",description:"Thanks! An admin will review your proposed source URL change shortly."}),c==null||c(),s(!1);return}P&&je(f,P,[a,r]),c==null||c(),s(!1)},onError:P=>{const I=fe(P,o==="pending"?"Failed to submit your edit. Please try again.":"Failed to update source URL.");l({title:o==="pending"?"Could not submit edit":"Could not save source URL",description:I,variant:"destructive"})}}),w=d.trim(),j=/^https?:\/\//i.test(w),v=w!==(n||"").trim(),C=()=>{j&&b.mutate({paperId:a,sourceUrl:w})};return e.jsx(ee,{open:t,onOpenChange:s,children:e.jsxs(te,{className:"max-w-2xl",children:[e.jsxs(se,{children:[e.jsx(ae,{children:"Edit Source URL"}),e.jsxs(re,{children:["Update the canonical URL for this external paper. This is the page the ",'"Source page"'," button links to. ArXiv papers cannot edit this field."]})]}),o==="pending"&&e.jsx(ge,{isAuthor:i}),e.jsxs("div",{className:"space-y-2 py-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Source URL"}),e.jsx(V,{type:"url",placeholder:"https://example.com/paper",value:d,onChange:P=>p(P.target.value),onKeyPress:P=>{P.key==="Enter"&&j&&v&&(P.preventDefault(),C())}}),!j&&w.length>0&&e.jsx("p",{className:"text-xs text-destructive",children:"URL must start with http:// or https://"})]}),e.jsxs(le,{children:[e.jsx(L,{variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsx(L,{onClick:C,disabled:b.isPending||!j||!v,children:b.isPending?e.jsxs(e.Fragment,{children:[e.jsx(ie,{className:"w-4 h-4 mr-2 animate-spin"}),o==="pending"?"Submitting...":"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(me,{className:"w-4 h-4 mr-2"}),o==="pending"?"Submit for review":"Save Changes"]})})]})]})})}const Fr=250,Tr=100;function Ur({open:t,onOpenChange:s,paperId:a,arxivId:r,initialTaskIds:n,initialTasks:c,onSuccess:o,submitMode:i="direct",isAuthor:d=!1}){const[p,f]=m.useState(n),[l,g]=m.useState(!1),[b,w]=m.useState(""),[j,v]=m.useState(""),[C,P]=m.useState(new Map),I=he(),{toast:S}=oe(),_=m.useRef(!1);m.useEffect(()=>{if(!t){_.current=!1;return}if(_.current)return;_.current=!0,f(n),w(""),v("");const h=new Map;(c||[]).forEach($=>{const R=parseInt($.id);Number.isNaN(R)||h.set(R,$)}),P(h)},[t,n,c]),m.useEffect(()=>{const h=window.setTimeout(()=>{v(b.trim())},Fr);return()=>window.clearTimeout(h)},[b]);const{data:u,isFetching:x}=ne({queryKey:["tasks-search",j],queryFn:()=>_e.listTasks({page_size:Tr,...j?{q:j}:{}}),enabled:t});m.useEffect(()=>{var h;(h=u==null?void 0:u.results)!=null&&h.length&&P($=>{const R=new Map($);return u.results.forEach(T=>{const U=parseInt(T.id);Number.isNaN(U)||R.set(U,T)}),R})},[u]);const E=m.useMemo(()=>{const h=(u==null?void 0:u.results)||[],$=new Set,R=[],T=(H,Y)=>{!Y||Number.isNaN(H)||$.has(H)||(R.push(Y),$.add(H))},U=()=>p.forEach(H=>T(H,C.get(H))),z=()=>h.forEach(H=>T(parseInt(H.id),H));return j?(z(),U()):(U(),z()),R},[u,p,C,j]),F=ce({mutationFn:async({paperId:h,taskIds:$})=>i==="pending"?(await pe.submit({paper_id:parseInt(h),edit_type:"tasks",proposed_payload:{task_ids:$}}),null):W.updateTasks(h,$),onMutate:async({taskIds:h})=>{if(i==="pending")return{snapshots:[]};const $=h.map(U=>C.get(U)).filter(U=>!!U).map(U=>({id:U.id,name:U.name,slug:U.slug})).sort((U,z)=>U.name.localeCompare(z.name)),R=Array.from(new Set([a,r].filter(U=>!!U)));await Promise.all(R.flatMap(U=>[I.cancelQueries({queryKey:ye.detail(U)}),I.cancelQueries({queryKey:ye.arxiv(U)})]));const T=[];return R.forEach(U=>{[ye.detail(U),ye.arxiv(U)].forEach(z=>{const H=I.getQueryData(z);T.push({key:z,data:H}),H&&I.setQueryData(z,{...H,tasks:$})})}),S({title:"Tasks updated",description:`Saved ${h.length} task${h.length===1?"":"s"} for this paper.`}),o==null||o(),s(!1),{snapshots:T}},onSuccess:h=>{if(i==="pending"){S({title:"Edit submitted for review",description:"Thanks! An admin will review your proposed task changes shortly."}),o==null||o(),s(!1);return}h&&je(I,h,[a,r])},onError:(h,$,R)=>{var U;(U=R==null?void 0:R.snapshots)==null||U.forEach(({key:z,data:H})=>{I.setQueryData(z,H)});const T=fe(h,i==="pending"?"Failed to submit your edit. Please try again.":"Failed to update paper tasks.");S({title:i==="pending"?"Could not submit edit":"Could not save tasks",description:T,variant:"destructive"})}}),M=()=>{i==="direct"&&n.some(h=>!p.includes(h))&&!window.confirm("Remove one or more task links from this paper?")||F.mutate({paperId:a,taskIds:p})},O=m.useMemo(()=>{if(p.length!==n.length)return!0;const h=new Set(n);return p.some($=>!h.has($))},[p,n]),K=(h,$)=>{f(R=>$?R.includes(h)?R:[...R,h]:R.filter(T=>T!==h))},G=()=>w("");return e.jsxs(ee,{open:t,onOpenChange:s,children:[e.jsxs(te,{className:"max-w-2xl max-h-[600px]",children:[e.jsxs(se,{children:[e.jsx(ae,{children:"Edit Paper Tasks"}),e.jsx(re,{children:"Select the tasks that this paper addresses. You can select multiple tasks."})]}),i==="pending"&&e.jsx(ge,{isAuthor:d}),e.jsxs("div",{className:"relative mb-4",children:[e.jsx(Ae,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(V,{type:"text",placeholder:"Search tasks...",value:b,onChange:h=>w(h.target.value),className:"pl-9 pr-9"}),b&&e.jsx("button",{type:"button",onClick:G,className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 text-muted-foreground hover:text-foreground","aria-label":"Clear search",children:e.jsx(yt,{className:"w-4 h-4"})})]}),e.jsx("div",{className:"py-4 overflow-y-auto max-h-[400px]",children:E.length>0?e.jsx("div",{className:"space-y-2",children:E.map(h=>{const $=parseInt(h.id),R=p.includes($);return e.jsxs("div",{className:"flex items-center space-x-2 p-2 hover:bg-muted/50 rounded-md",children:[e.jsx(Xe,{id:`task-${h.id}`,checked:R,onCheckedChange:T=>K($,T===!0),className:"!border !border-black data-[state=checked]:!bg-black data-[state=checked]:!text-white"}),e.jsxs("label",{htmlFor:`task-${h.id}`,className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 cursor-pointer flex-1",children:[h.name,h.description&&e.jsxs("span",{className:"block text-xs text-muted-foreground font-normal mt-1",children:[h.description.substring(0,100),h.description.length>100?"...":""]})]})]},h.id)})}):x?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(ie,{className:"w-8 h-8 mx-auto mb-2 animate-spin"}),e.jsx("p",{children:"Loading tasks..."})]}):e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(Ae,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:j?`No tasks found matching "${j}"`:"No tasks available"})]})}),e.jsxs(le,{children:[e.jsx(L,{variant:"ghost",className:"sm:mr-auto",onClick:()=>g(!0),children:"Suggest a new task"}),e.jsx(L,{variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsx(L,{onClick:M,disabled:F.isPending||!O,children:F.isPending?e.jsxs(e.Fragment,{children:[e.jsx(ie,{className:"w-4 h-4 mr-2 animate-spin"}),i==="pending"?"Submitting...":"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(me,{className:"w-4 h-4 mr-2"}),i==="pending"?"Submit for review":"Save Changes"]})})]})]}),e.jsx(wt,{open:l,onOpenChange:g,paperId:a,kind:"task"})]})}const Ot=10,Dr=/^https?:\/\/(?:www\.|mobile\.)?(?:x|twitter)\.com\/(?:[A-Za-z0-9_]{1,15}|i\/web|i)\/status(?:es)?\/(\d{1,25})(?:[/?#].*)?$/;function Ne(t){var s;return((s=Dr.exec(t.trim()))==null?void 0:s[1])??null}function Br({open:t,onOpenChange:s,paperId:a,arxivId:r,initialUrls:n,submitMode:c="direct",isAuthor:o=!1}){const[i,d]=m.useState(n),[p,f]=m.useState(""),[l,g]=m.useState(null),b=he(),{toast:w}=oe(),j=m.useRef(!1);m.useEffect(()=>{if(!t){j.current=!1;return}j.current||(j.current=!0,d(n),f(""),g(null))},[t,n]);const v=ce({mutationFn:async u=>c==="pending"?(await pe.submit({paper_id:parseInt(a),edit_type:"x_threads",proposed_payload:{x_threads:u}}),null):W.updateXThreads(a,u),onSuccess:u=>{c==="pending"?w({title:"Edit submitted for review",description:"Thanks! An admin will review your proposed X threads shortly."}):u&&je(b,u,[a,r]),s(!1)},onError:u=>{w({title:c==="pending"?"Could not submit edit":"Could not save X threads",description:fe(u,c==="pending"?"Failed to submit your edit. Please try again.":"Failed to update X threads."),variant:"destructive"})}}),C=()=>{const u=p.trim();if(!u)return i;const x=Ne(u);return x?i.some(E=>Ne(E)===x)?(g("This post is already listed."),null):i.length>=Ot?(g(`A paper can link at most ${Ot} X threads.`),null):[...i,u]:(g("Paste a post URL such as https://x.com/user/status/123…"),null)},P=()=>{const u=C();u!==null&&(d(u),f(""),g(null))},I=(u,x)=>{const E=[...i];[E[u],E[u+x]]=[E[u+x],E[u]],d(E)},S=()=>{const u=C();u!==null&&(c==="direct"&&n.some(x=>!u.some(E=>Ne(E)===Ne(x)))&&!window.confirm("Remove one or more X threads from this paper?")||v.mutate(u))},_=m.useMemo(()=>(p.trim()?[...i,p.trim()]:i).map(Ne).join()!==n.map(Ne).join(),[i,p,n]);return e.jsx(ee,{open:t,onOpenChange:s,children:e.jsxs(te,{className:"max-w-2xl max-h-[600px]",children:[e.jsxs(se,{children:[e.jsx(ae,{children:"Edit X threads"}),e.jsx(re,{children:"Link posts on X (formerly Twitter) in which the authors introduce this paper. A preview of each post is shown on the paper page."})]}),c==="pending"&&e.jsx(ge,{isAuthor:o}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",htmlFor:"x-thread-url",children:"Add X post URL"}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(V,{id:"x-thread-url",type:"url",placeholder:"https://x.com/user/status/1234567890",value:p,onChange:u=>{f(u.target.value),g(null)},onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),P())},"aria-invalid":!!l,className:"flex-1"}),e.jsxs(L,{onClick:P,size:"sm",disabled:!p.trim(),children:[e.jsx(Ue,{className:"w-4 h-4 mr-1"}),"Add"]})]}),l&&e.jsx("p",{className:"text-xs text-destructive",children:l})]}),e.jsx("div",{className:"py-4 overflow-y-auto max-h-[350px]",children:i.length>0?e.jsx("div",{className:"space-y-2",children:i.map((u,x)=>e.jsxs("div",{className:"flex items-center space-x-2 p-3 bg-muted/30 rounded-lg",children:[e.jsx("span",{className:"flex-1 min-w-0 truncate text-sm font-medium",children:u}),e.jsx(L,{variant:"ghost",size:"sm",className:"h-8 px-2",disabled:x===0,onClick:()=>I(x,-1),"aria-label":"Move up",children:e.jsx(Ba,{className:"w-4 h-4"})}),e.jsx(L,{variant:"ghost",size:"sm",className:"h-8 px-2",disabled:x===i.length-1,onClick:()=>I(x,1),"aria-label":"Move down",children:e.jsx(Da,{className:"w-4 h-4"})}),e.jsx(L,{variant:"ghost",size:"sm",className:"h-8 px-2 text-destructive hover:text-destructive",onClick:()=>d(i.filter(E=>E!==u)),"aria-label":"Remove X thread",children:e.jsx(Te,{className:"w-4 h-4"})})]},u))}):e.jsx("p",{className:"text-center py-8 text-sm text-muted-foreground",children:"No X threads linked yet"})}),e.jsxs(le,{children:[e.jsx(L,{variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsx(L,{onClick:S,disabled:v.isPending||!_,children:v.isPending?e.jsxs(e.Fragment,{children:[e.jsx(ie,{className:"w-4 h-4 mr-2 animate-spin"}),c==="pending"?"Submitting...":"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(me,{className:"w-4 h-4 mr-2"}),c==="pending"?"Submit for review":"Save Changes"]})})]})]})})}function zr({activeEditor:t,arxivId:s,editSubmitMode:a,evaluations:r,isAdmin:n,isLinkedAuthor:c,onOpenChange:o,paper:i}){if(!t)return null;const d={open:!0,paperId:i.id,arxivId:s,submitMode:a,isAuthor:c},p=l=>g=>o(l,g);return{tasks:()=>{var l;return e.jsx(Ur,{...d,onOpenChange:p("tasks"),initialTaskIds:((l=i.tasks)==null?void 0:l.map(g=>Number(g.id)))??[],initialTasks:i.tasks??[]})},methods:()=>{var l;return e.jsx(Er,{...d,onOpenChange:p("methods"),initialMethodIds:((l=i.methods)==null?void 0:l.map(g=>Number(g.id)))??[],initialMethods:i.methods??[]})},repositories:()=>{var l;return e.jsx(Ar,{...d,onOpenChange:p("repositories"),initialRepositories:((l=i.repositories)==null?void 0:l.map(({url:g,is_official:b})=>({url:g,is_official:!!b})))??[]})},"project-pages":()=>{var l;return e.jsx(Rr,{...d,onOpenChange:p("project-pages"),initialProjectPages:((l=i.project_pages)==null?void 0:l.map(({url:g,is_official:b})=>({url:g,is_official:!!b})))??[]})},results:()=>e.jsx(br,{...d,onOpenChange:p("results"),initialEvaluations:r,paperTasks:i.tasks??[],isAdmin:n}),"source-url":()=>e.jsx(Lr,{...d,onOpenChange:p("source-url"),initialUrl:i.source_url??i.url_abs??""}),"hf-artifacts":()=>e.jsx(vr,{...d,onOpenChange:p("hf-artifacts"),initialArtifacts:{hf_models:i.hf_models??[],hf_datasets:i.hf_datasets??[],hf_spaces:i.hf_spaces??[]}}),"x-threads":()=>{var l;return e.jsx(Br,{...d,onOpenChange:p("x-threads"),initialUrls:((l=i.x_threads)==null?void 0:l.map(({url:g})=>g))??[]})},organizations:()=>e.jsx(Ir,{open:!0,paperId:i.id,onOpenChange:p("organizations"),initialOrganizationIds:(i.organizations??[]).map(({id:l})=>Number(l)),submitMode:a,isAuthor:c})}[t]()}const Hr={"add-evals":{trigger:"add evals",running:"adding evals…",complete:"add evals ✓",title:"Add evaluations with Codex",description:t=>e.jsxs(e.Fragment,{children:["Codex will run the repository’s add-evals skill for “",t,"”. It will import only paper-native results onto existing, metric-compatible leaderboards. Accepted rows are written directly to the live database."]}),notice:"Comparator rows, unknown benchmarks, and unconfigured metrics will be skipped. Jobs run one at a time in submission order.",progress:"Codex is researching the paper and validating results against the configured leaderboards.",action:"Run add-evals",start:Ia,get:$a,cancel:Pa},"enrich-paper":{trigger:"enrich paper",running:"enriching…",complete:"enriched ✓",title:"Enrich paper with Codex",description:t=>e.jsxs(e.Fragment,{children:["Codex will run the repository’s enrich-paper skill for “",t,"”. It will validate official code and project links, merge high-confidence taxonomy tags, and check the paper thumbnail. Accepted changes are written directly to the live database."]}),notice:"Uncertain URLs and missing taxonomy concepts will be reported rather than guessed. Jobs run one at a time in submission order.",progress:"Codex is validating artifacts, taxonomy tags, and thumbnail quality for this paper.",action:"Run enrich-paper",start:Sa,get:Ea,cancel:Ca}};function Mr({report:t}){return e.jsx("div",{className:"min-w-0 max-h-[50vh] overflow-y-auto overflow-x-hidden rounded-md border bg-muted/40 p-4 text-sm leading-relaxed",children:e.jsx(La,{remarkPlugins:[Fa],components:{a:({children:s,...a})=>e.jsx("a",{...a,className:"break-all underline underline-offset-2",target:"_blank",rel:"noreferrer",children:s}),p:({children:s})=>e.jsx("p",{className:"mb-3 break-words last:mb-0",children:s}),ul:({children:s})=>e.jsx("ul",{className:"mb-3 list-disc space-y-1 pl-5 last:mb-0",children:s}),ol:({children:s})=>e.jsx("ol",{className:"mb-3 list-decimal space-y-1 pl-5 last:mb-0",children:s}),h1:({children:s})=>e.jsx("h3",{className:"mb-2 font-semibold",children:s}),h2:({children:s})=>e.jsx("h3",{className:"mb-2 font-semibold",children:s}),h3:({children:s})=>e.jsx("h3",{className:"mb-2 font-semibold",children:s}),code:({children:s})=>e.jsx("code",{className:"break-all rounded bg-background/80 px-1 py-0.5 font-mono text-xs",children:s}),pre:({children:s})=>e.jsx("pre",{className:"mb-3 max-w-full overflow-x-auto whitespace-pre-wrap break-words rounded bg-background/80 p-3 font-mono text-xs last:mb-0",children:s})},children:t})})}function xs({kind:t,paperId:s,paperTitle:a,triggerClassName:r,onComplete:n}){const c=Hr[t],[o,i]=m.useState(!1),[d,p]=m.useState(null),[f,l]=m.useState(!1),[g,b]=m.useState(null),w=m.useRef(null),j=(d==null?void 0:d.status)==="queued"||(d==null?void 0:d.status)==="dispatching"||(d==null?void 0:d.status)==="running",v=d==null?void 0:d.id;m.useEffect(()=>{if(!j||!v)return;let S=!1;const _=window.setInterval(async()=>{try{const u=await c.get(v);S||(p(u),b(null))}catch(u){S||b(u instanceof Error?u.message:"Could not check job status.")}},2e3);return()=>{S=!0,window.clearInterval(_)}},[j,c,v]),m.useEffect(()=>{(d==null?void 0:d.status)!=="completed"||w.current===d.id||(w.current=d.id,n())},[d,n]);const C=async()=>{l(!0),b(null);try{p(await c.start(s))}catch(S){b(S instanceof Error?S.message:"Could not start Codex.")}finally{l(!1)}},P=()=>{p(null),b(null),w.current=null},I=async()=>{if(d){b(null);try{p(await c.cancel(d.id))}catch(S){b(S instanceof Error?S.message:"Could not cancel Codex.")}}};return e.jsxs(ee,{open:o,onOpenChange:i,children:[e.jsx("button",{type:"button",className:r,onClick:()=>i(!0),children:j?c.running:(d==null?void 0:d.status)==="completed"?c.complete:c.trigger}),e.jsxs(te,{className:"max-h-[90vh] w-[calc(100vw-2rem)] min-w-0 max-w-2xl overflow-hidden",children:[e.jsxs(se,{className:"min-w-0",children:[e.jsx(ae,{children:c.title}),e.jsx(re,{children:c.description(a)})]}),d?e.jsxs("div",{className:"min-w-0 space-y-3 overflow-hidden",children:[e.jsxs("div",{className:"font-mono text-xs uppercase tracking-wide text-muted-foreground",children:["Status: ",d.status]}),d.hf_job_url&&e.jsx("a",{className:"text-sm underline",href:d.hf_job_url,target:"_blank",rel:"noreferrer",children:"View Hugging Face Job"}),j&&e.jsxs("div",{className:"rounded-md border bg-muted/40 p-3 text-sm",children:[d.status==="queued"?"This job is queued and will start after the current Codex job finishes.":c.progress," ","This can take several minutes; you can close this window and return."]}),d.report&&e.jsx(Mr,{report:d.report}),d.error&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive",children:d.error})]}):e.jsx("div",{className:"rounded-md border bg-muted/40 p-3 text-sm text-muted-foreground",children:c.notice}),g&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive",children:g}),e.jsxs(le,{children:[e.jsx(L,{variant:"outline",onClick:()=>i(!1),children:j?"Close":"Cancel"}),j&&e.jsx(L,{variant:"outline",onClick:()=>void I(),children:"Cancel job"}),!d&&e.jsx(L,{onClick:C,disabled:f,children:f?"Starting…":c.action}),d&&!j&&e.jsx(L,{variant:"outline",onClick:P,children:"Run again"})]})]})]})}function qr(t){return e.jsx(xs,{...t,kind:"add-evals",triggerClassName:"edit-link"})}function Pe({accent:t,id:s,label:a}){return e.jsxs("div",{className:"section-rule paper-section-anchor",id:s,children:[e.jsx("span",{children:e.jsx("a",{href:`#${s}`,className:"section-anchor-link",children:a})}),t]})}function Or({canCopyBadge:t,canEdit:s,evaluationsByTask:a,evaluationsLoading:r,isAdmin:n,onCopyBadge:c,onEdit:o,onRefresh:i,paper:d,visibleEvaluationCount:p}){return e.jsxs(e.Fragment,{children:[e.jsx(Pe,{id:"results",label:"Results",accent:e.jsxs("span",{className:"accent",children:[p," benchmarks",t&&e.jsxs("button",{type:"button",className:"edit-link results-badge-copy",onClick:c,title:"Copy live leaderboard badges for your repository README",children:[e.jsx(J,{name:"copy",size:10})," Copy PwC badge"]}),n&&Ra()&&e.jsx(qr,{paperId:Number(d.id),paperTitle:d.title,onComplete:i}),s&&e.jsx("button",{type:"button",onClick:o,className:"edit-link",children:"edit"})]})}),r?e.jsx(Ie,{className:"h-32 w-full"}):a.length>0?a.map(f=>e.jsxs("div",{className:f.taskSlug?"paper-section-anchor":void 0,id:f.taskSlug?os(f.taskSlug):void 0,children:[e.jsxs("div",{className:"section-rule",children:[e.jsx("span",{children:f.taskSlug?e.jsxs(e.Fragment,{children:[e.jsx(ue,{to:`/tasks/${f.taskSlug}`,children:f.taskName}),e.jsx("a",{href:er(f.taskSlug),className:"section-anchor-link results-task-permalink","aria-label":`Permalink to ${f.taskName} results on this paper`,title:"Link to this task's results",children:"#"})]}):f.taskName}),e.jsxs("span",{className:"accent",children:[f.rows.length," ",f.rows.length===1?"result":"results"]})]}),e.jsxs("table",{className:"results-table",children:[e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:"28%"}}),e.jsx("col",{style:{width:"28%"}}),e.jsx("col",{style:{width:"14%"}}),e.jsx("col",{style:{width:"12%"}}),e.jsx("col",{style:{width:"8%"}}),e.jsx("col",{style:{width:"10%"}})]}),e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Benchmark"}),e.jsx("th",{children:"Model"}),e.jsx("th",{children:"Metric"}),e.jsx("th",{children:"Value"}),e.jsx("th",{children:"Rank"}),e.jsx("th",{children:"Compare"})]})}),e.jsx("tbody",{children:f.rows.map(l=>{var g;return e.jsxs("tr",{children:[e.jsx("td",{className:"benchmark",children:l.dataset_slug?e.jsx(ue,{to:`/benchmark/${l.dataset_slug}`,children:l.dataset_name||"—"}):l.dataset_name||"—"}),e.jsxs("td",{className:"model",title:l.model_name||void 0,children:[l.hf_model_url?e.jsx("a",{href:l.hf_model_url,target:"_blank",rel:"noopener noreferrer",className:"model-hf-link",title:`Open ${l.model_name||"model"} on Hugging Face`,children:l.model_name||"—"}):l.model_name||"—",l.is_open===!1&&e.jsx(oa,{}),(l.external??l.is_external)&&e.jsx(la,{sourceUrl:l.source_url||l.external_source_url||l.result_url})]}),e.jsx("td",{className:"metric",children:l.best_metric}),e.jsx("td",{className:"value",children:Bs((g=l.metrics)==null?void 0:g[l.best_metric||""])}),e.jsx("td",{className:"rank",children:l.best_rank!=null?`#${l.best_rank}`:"—"}),e.jsx("td",{className:"compare",children:l.dataset_slug&&e.jsx(ue,{to:`/benchmark/${l.dataset_slug}?${[l.task_slug?`task=${encodeURIComponent(l.task_slug)}`:"",`eval=${encodeURIComponent(l.id)}`].filter(Boolean).join("&")}`,children:"Compare →"})})]},l.id)})})]})]},f.taskId)):e.jsx("p",{style:{fontFamily:"var(--mono)",fontSize:12,color:"var(--ink-faint)"},children:"No benchmark results recorded yet."})]})}var Nt="Radio",[Kr,bs]=vt(Nt),[Gr,Xr]=Kr(Nt),js=m.forwardRef((t,s)=>{const{__scopeRadio:a,name:r,checked:n=!1,required:c,disabled:o,value:i="on",onCheck:d,form:p,...f}=t,[l,g]=m.useState(null),b=Fe(s,v=>g(v)),w=m.useRef(!1),j=l?p||!!l.closest("form"):!0;return e.jsxs(Gr,{scope:a,checked:n,disabled:o,children:[e.jsx(ke.button,{type:"button",role:"radio","aria-checked":n,"data-state":_s(n),"data-disabled":o?"":void 0,disabled:o,value:i,...f,ref:b,onClick:Re(t.onClick,v=>{n||d==null||d(),j&&(w.current=v.isPropagationStopped(),w.current||v.stopPropagation())})}),j&&e.jsx(ws,{control:l,bubbles:!w.current,name:r,value:i,checked:n,required:c,disabled:o,form:p,style:{transform:"translateX(-100%)"}})]})});js.displayName=Nt;var vs="RadioIndicator",ys=m.forwardRef((t,s)=>{const{__scopeRadio:a,forceMount:r,...n}=t,c=Xr(vs,a);return e.jsx(Jt,{present:r||c.checked,children:e.jsx(ke.span,{"data-state":_s(c.checked),"data-disabled":c.disabled?"":void 0,...n,ref:s})})});ys.displayName=vs;var Qr="RadioBubbleInput",ws=m.forwardRef(({__scopeRadio:t,control:s,checked:a,bubbles:r=!0,...n},c)=>{const o=m.useRef(null),i=Fe(o,c),d=as(a),p=Zt(s);return m.useEffect(()=>{const f=o.current;if(!f)return;const l=window.HTMLInputElement.prototype,b=Object.getOwnPropertyDescriptor(l,"checked").set;if(d!==a&&b){const w=new Event("click",{bubbles:r});b.call(f,a),f.dispatchEvent(w)}},[d,a,r]),e.jsx(ke.input,{type:"radio","aria-hidden":!0,defaultChecked:a,...n,tabIndex:-1,ref:i,style:{...n.style,...p,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});ws.displayName=Qr;function _s(t){return t?"checked":"unchecked"}var Vr=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],Qe="RadioGroup",[Wr]=vt(Qe,[es,bs]),ks=es(),Ns=bs(),[Jr,Yr]=Wr(Qe),Cs=m.forwardRef((t,s)=>{const{__scopeRadioGroup:a,name:r,defaultValue:n,value:c,required:o=!1,disabled:i=!1,orientation:d,dir:p,loop:f=!0,onValueChange:l,...g}=t,b=ks(a),w=zs(p),[j,v]=Yt({prop:c,defaultProp:n??null,onChange:l,caller:Qe});return e.jsx(Jr,{scope:a,name:r,required:o,disabled:i,value:j,onValueChange:v,children:e.jsx(Hs,{asChild:!0,...b,orientation:d,dir:w,loop:f,children:e.jsx(ke.div,{role:"radiogroup","aria-required":o,"aria-orientation":d,"data-disabled":i?"":void 0,dir:w,...g,ref:s})})})});Cs.displayName=Qe;var Es="RadioGroupItem",Ss=m.forwardRef((t,s)=>{const{__scopeRadioGroup:a,disabled:r,...n}=t,c=Yr(Es,a),o=c.disabled||r,i=ks(a),d=Ns(a),p=m.useRef(null),f=Fe(s,p),l=c.value===n.value,g=m.useRef(!1);return m.useEffect(()=>{const b=j=>{Vr.includes(j.key)&&(g.current=!0)},w=()=>g.current=!1;return document.addEventListener("keydown",b),document.addEventListener("keyup",w),()=>{document.removeEventListener("keydown",b),document.removeEventListener("keyup",w)}},[]),e.jsx(Ms,{asChild:!0,...i,focusable:!o,active:l,children:e.jsx(js,{disabled:o,required:c.required,checked:l,...d,...n,name:c.name,ref:f,onCheck:()=>c.onValueChange(n.value),onKeyDown:Re(b=>{b.key==="Enter"&&b.preventDefault()}),onFocus:Re(n.onFocus,()=>{var b;g.current&&((b=p.current)==null||b.click())})})})});Ss.displayName=Es;var Zr="RadioGroupIndicator",Ps=m.forwardRef((t,s)=>{const{__scopeRadioGroup:a,...r}=t,n=Ns(a);return e.jsx(ys,{...n,...r,ref:s})});Ps.displayName=Zr;var $s=Cs,Is=Ss,en=Ps;const ft=m.forwardRef(({className:t,...s},a)=>e.jsx($s,{className:Me("grid gap-2",t),...s,ref:a}));ft.displayName=$s.displayName;const $e=m.forwardRef(({className:t,...s},a)=>e.jsx(Is,{ref:a,className:Me("aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",t),...s,children:e.jsx(en,{className:"flex items-center justify-center",children:e.jsx(qs,{className:"h-2.5 w-2.5 fill-current text-current"})})}));$e.displayName=Is.displayName;const tn={pdf:"PDF",model:"Model",dataset:"Dataset",space:"Space",github:"GitHub"},gt=/^[A-Za-z0-9][A-Za-z0-9._-]*$/,sn=/^[A-Za-z0-9][\w.-]*\/[A-Za-z0-9][\w.-]*$/,an=20,xt="copy_to_bucket";function rn(t){const s=t.trim();if(!sn.test(s))return null;const[a,r]=s.split("/");return`https://huggingface.co/buckets/${encodeURIComponent(a)}/${encodeURIComponent(r)}`}function bt(t){return`pwc:bucket-copy:${t}`}function nn(t){if(typeof window>"u"||new URL(window.location.href).searchParams.get(xt)!==t)return null;try{const a=window.sessionStorage.getItem(bt(t));if(!a)return null;const r=JSON.parse(a);return r.paperId!==t||typeof r.bucketId!="string"||!["new","existing"].includes(r.destinationMode)||!["public","private"].includes(r.visibility)||!Array.isArray(r.selectedIds)||r.selectedIds.some(n=>typeof n!="string")?null:r}catch{return null}}function on(t,s=an){if(s<1)throw new Error("Bucket copy batch size must be positive");const a=[];for(let r=0;r!gt.test(d)))return null;const o=c.join("/"),i=s==="model"?"":`${s}s/`;return{id:`${s}:${o}`,kind:s,label:o,url:`https://huggingface.co/${i}${o}`,source:`hf://${i}${o}/`,destination:`${s}s/${o}/`,repoId:o}}catch{return null}}function ln(t){try{const s=new URL(t);if(s.hostname!=="github.com"&&s.hostname!=="www.github.com")return null;const a=s.pathname.split("/").filter(Boolean);if(a.length<2)return null;const r=a[0],n=a[1].replace(/\.git$/,"");if(!gt.test(r)||!gt.test(n))return null;const c=`${r}/${n}`;return{id:`github:${c}`,kind:"github",label:c,url:`https://github.com/${c}`,source:`https://github.com/${c}.git`,destination:`github/${c}/`}}catch{return null}}function cn({githubUrls:t,hfModelUrls:s,hfDatasetUrls:a,hfSpaceUrls:r,paperId:n,pdfName:c,pdfUrl:o}){const i=[o?{id:"pdf",kind:"pdf",label:"Paper PDF",url:o,source:o,destination:`paper/${c||n}.pdf`}:null,...s.map(p=>dt(p,"model")),...a.map(p=>dt(p,"dataset")),...r.map(p=>dt(p,"space")),...t.map(ln)],d=new Set;return i.filter(p=>!p||d.has(p.id)?!1:(d.add(p.id),!0))}function dn(t,s,a){const r=["# Requires the Hugging Face CLI: https://huggingface.co/docs/huggingface_hub/guides/cli",`HF_BUCKET=${ze(t.trim())}`];a.create&&r.push(`hf buckets create "$HF_BUCKET" --exist-ok${a.isPrivate?" --private":""}`);for(const o of s.filter(i=>i.kind!=="github"&&i.kind!=="pdf"))r.push(`hf cp ${ze(o.source)} "hf://buckets/$HF_BUCKET/${o.destination}"`);const n=s.find(o=>o.kind==="pdf");n&&r.push('PWC_PDF="$(mktemp)"',`trap 'rm -f "$PWC_PDF"' EXIT`,`curl --fail --location ${ze(n.source)} --output "$PWC_PDF"`,`hf cp "$PWC_PDF" "hf://buckets/$HF_BUCKET/${n.destination}"`);const c=s.filter(o=>o.kind==="github");if(c.length){r.push('PWC_COPY_DIR="$(mktemp -d)"',`trap 'rm -rf "$PWC_COPY_DIR"' EXIT`);for(const o of c){const i=`$PWC_COPY_DIR/${o.destination.replace(/\/$/,"")}`;r.push(`git clone --depth 1 -- ${ze(o.source)} "${i}"`,`hf sync "${i}" "hf://buckets/$HF_BUCKET/${o.destination}" --exclude '.git/**'`)}}return r.join(` +`)}function un(t){return`${(t.split(/[:|–—]/,1)[0]||t).normalize("NFKD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,48).replace(/-+$/g,"")||"paper"}-artifacts`}function mn(t){const{toast:s}=oe(),a=m.useMemo(()=>cn({githubUrls:t.githubUrls,hfDatasetUrls:t.hfDatasetUrls,hfModelUrls:t.hfModelUrls,hfSpaceUrls:t.hfSpaceUrls,paperId:t.paperId,pdfName:t.pdfName,pdfUrl:t.pdfUrl}),[t.githubUrls,t.hfDatasetUrls,t.hfModelUrls,t.hfSpaceUrls,t.paperId,t.pdfName,t.pdfUrl]),r=m.useMemo(()=>nn(t.paperId),[t.paperId]),[n,c]=m.useState(!!r),[o,i]=m.useState((r==null?void 0:r.destinationMode)??"new"),[d,p]=m.useState((r==null?void 0:r.bucketId)??""),[f,l]=m.useState((r==null?void 0:r.visibility)??"public"),[g,b]=m.useState(()=>new Set((r==null?void 0:r.selectedIds)??a.map(h=>h.id))),[w,j]=m.useState(!1),[v,C]=m.useState(null),[P,I]=m.useState(!!r),S=a.filter(h=>g.has(h.id)),_=S.length===a.length,u=rn(d),x=u!==null,E=dn(d,S,{create:o==="new",isPrivate:f==="private"}),F=(h,$)=>{b(R=>{const T=new Set(R);return $?T.add(h):T.delete(h),T})},M=async()=>{try{await navigator.clipboard.writeText(E),s({title:"Bucket copy commands copied",description:"Run them in a terminal where the Hugging Face CLI is signed in."})}catch{s({title:"Copy failed",description:"Could not access the clipboard. Select and copy the commands manually.",variant:"destructive"})}},O=m.useCallback(()=>{const h=Os("/api/v1/auth/hf/login"),$=new URL(window.location.href);$.searchParams.set(xt,t.paperId),window.sessionStorage.setItem(bt(t.paperId),JSON.stringify({paperId:t.paperId,bucketId:d.trim(),destinationMode:o,visibility:f,selectedIds:Array.from(g)}));const R=new URLSearchParams({return_to:$.toString(),authorize_bucket:"true"});o==="new"&&R.set("bucket_create","true"),window.location.assign(`${h}?${R.toString()}`)},[d,o,t.paperId,g,f]),K=m.useCallback(async()=>{if(!t.isSignedIn){O();return}j(!0);let h=0,$=0;try{const R=S.filter(z=>z.kind!=="pdf"&&z.kind!=="github"&&!!z.repoId).map(z=>({kind:z.kind,repo_id:z.repoId})),T=on(R);T.length||T.push([]);for(const[z,H]of T.entries()){C({current:z+1,total:T.length});const Y=await W.copyToBucket(t.paperId,{bucket_id:d.trim(),create:z===0&&o==="new",private:f==="private",include_pdf:z===0&&S.some(Z=>Z.kind==="pdf"),artifacts:H});h+=Y.copied.length,$+=Y.errors.length}const U=S.filter(z=>z.kind==="github").length;s({title:$?"Bucket copy partially completed":"Copied to bucket",description:[`${h} item${h===1?"":"s"} copied.`,$?`${$} item${$===1?"":"s"} failed.`:"",U?"Use the generated commands below to copy GitHub repositories.":""].filter(Boolean).join(" "),variant:$?"destructive":void 0,action:u?e.jsx(Ks,{altText:"Open destination bucket",asChild:!0,children:e.jsx("a",{href:u,target:"_blank",rel:"noopener noreferrer",children:"Open bucket"})}):void 0}),!$&&!U&&c(!1)}catch(R){if(R instanceof ht&&R.code==="bucket_authorization_required"){O();return}s({title:h?"Bucket copy partially completed":"Bucket copy failed",description:h?`${h} item${h===1?"":"s"} copied before the request failed. You can retry or use the CLI commands below.`:R instanceof ht&&typeof R.detail=="string"?R.detail:"Hugging Face could not complete the copy. You can still use the CLI commands below.",variant:"destructive"})}finally{j(!1),C(null)}},[O,d,u,o,t.isSignedIn,t.paperId,S,s,f]);m.useEffect(()=>{if(!P||!t.isSignedIn)return;I(!1),window.sessionStorage.removeItem(bt(t.paperId));const h=new URL(window.location.href);h.searchParams.delete(xt),window.history.replaceState({},"",`${h.pathname}${h.search}${h.hash}`),K()},[K,t.isSignedIn,t.paperId,P]);const G=()=>{b(new Set(a.map(h=>h.id))),!d&&t.suggestedBucketId&&p(t.suggestedBucketId),c(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"sidebar-card copy-to-bucket-card",children:[e.jsxs("button",{type:"button",className:"copy-to-bucket-trigger",onClick:G,children:[e.jsx("span",{className:"copy-to-bucket-arrow","aria-hidden":"true",children:"→"}),e.jsx("span",{className:"copy-to-bucket-title",children:"Copy to bucket"}),e.jsx("span",{className:"copy-to-bucket-new",children:"New"})]}),e.jsx("div",{className:"copy-to-bucket-meta",children:a.length?`${a.length} linked artifact${a.length===1?"":"s"}`:"No linked artifacts yet"})]}),e.jsx(ee,{open:n,onOpenChange:c,children:e.jsxs(te,{className:"max-h-[90vh] max-w-2xl grid-rows-[auto_minmax(0,1fr)_auto] overflow-hidden",children:[e.jsxs(se,{children:[e.jsxs(ae,{className:"flex items-center gap-2",children:[e.jsx("span",{className:"copy-to-bucket-dialog-arrow","aria-hidden":"true",children:"→"}),"Copy to bucket"]}),e.jsx(re,{children:"Keep your own copy of this paper's PDF, linked code, and Hugging Face artifacts. Hub repositories use Xet's server-side copy; GitHub repositories use the generated CLI fallback."})]}),e.jsx("div",{className:"-mx-6 min-h-0 overflow-y-auto px-6",children:a.length?e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(de,{children:"Choose your destination"}),e.jsxs(ft,{value:o,onValueChange:h=>i(h),className:"grid grid-cols-2 gap-2",children:[e.jsxs(de,{className:"bucket-choice",children:[e.jsx($e,{value:"new"}),"New bucket"]}),e.jsxs(de,{className:"bucket-choice",children:[e.jsx($e,{value:"existing"}),"Existing bucket"]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(de,{htmlFor:"bucket-id",children:"Bucket name"}),e.jsx(V,{id:"bucket-id",value:d,onChange:h=>p(h.target.value),placeholder:t.suggestedBucketId||"username/paper-artifacts","aria-invalid":d.length>0&&!x}),e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs",children:[e.jsx("p",{className:"text-muted-foreground",children:"Use the full Hugging Face bucket ID: namespace/name."}),u&&e.jsxs("a",{href:u,target:"_blank",rel:"noopener noreferrer",className:"inline-flex shrink-0 items-center gap-1 underline underline-offset-4",children:["View bucket",e.jsx(J,{name:"external",size:10})]})]})]}),o==="new"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(de,{children:"Bucket visibility"}),e.jsxs(ft,{value:f,onValueChange:h=>l(h),className:"flex gap-5",children:[e.jsxs(de,{className:"flex items-center gap-2 font-normal",children:[e.jsx($e,{value:"public"}),"Public"]}),e.jsxs(de,{className:"flex items-center gap-2 font-normal",children:[e.jsx($e,{value:"private"}),"Private"]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(de,{children:"Artifacts"}),e.jsx(L,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>b(_?new Set:new Set(a.map(h=>h.id))),children:_?"Deselect all":"Select all"})]}),e.jsx("div",{className:"bucket-artifact-list",children:a.map(h=>e.jsxs("div",{className:"bucket-artifact-row",children:[e.jsx(Xe,{id:`bucket-artifact-${h.id}`,checked:g.has(h.id),onCheckedChange:$=>F(h.id,$===!0)}),e.jsxs(de,{htmlFor:`bucket-artifact-${h.id}`,className:"min-w-0 flex-1 cursor-pointer font-normal",children:[e.jsx("span",{className:"bucket-artifact-kind",children:tn[h.kind]}),e.jsx("span",{className:"bucket-artifact-name",children:h.label})]}),e.jsxs("a",{href:we(h.url)??void 0,target:"_blank",rel:"noopener noreferrer",className:"bucket-artifact-open",children:["Open",e.jsx(J,{name:"external",size:10})]})]},h.id))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"The PDF and Hugging Face artifacts can be copied directly. GitHub repositories require the CLI workflow below."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(de,{htmlFor:"bucket-copy-commands",children:"CLI fallback"}),e.jsx("pre",{id:"bucket-copy-commands",className:"bucket-copy-commands h-[190px]",children:x?E:"Enter a bucket name above to prepare the copy commands."})]})]}):e.jsx("p",{className:"py-5 text-sm text-muted-foreground",children:"This paper does not have a linked GitHub repository or Hugging Face artifact to copy yet."})}),e.jsxs(le,{children:[e.jsx("a",{href:"https://huggingface.co/docs/huggingface_hub/en/guides/buckets",target:"_blank",rel:"noopener noreferrer",className:"mr-auto text-sm text-muted-foreground underline underline-offset-4",children:"About Hugging Face Buckets"}),e.jsxs(L,{type:"button",onClick:M,variant:"outline",disabled:!x||S.length===0,children:[e.jsx(J,{name:"copy",size:12}),"Copy commands"]}),e.jsx(L,{type:"button",onClick:K,disabled:w||t.isSignedIn&&(!x||!S.some(h=>h.kind!=="github")),children:w?v&&v.total>1?`Copying ${v.current}/${v.total}…`:"Copying…":t.isSignedIn?"Copy now":"Sign in & copy"})]})]})})]})}function hn({isLoading:t,papers:s}){return t?e.jsxs("div",{className:"sidebar-card","aria-busy":"true",children:[e.jsx("div",{className:"sidebar-card-title",children:"Related papers"}),e.jsx("div",{className:"related-meta",children:"Finding related work…"})]}):s!=null&&s.length?e.jsxs("div",{className:"sidebar-card",children:[e.jsx("div",{className:"sidebar-card-title",children:"Related papers"}),s.map(a=>e.jsxs(ue,{to:`/paper/${a.arxiv_id||a.id}`,target:"_blank",rel:"noopener noreferrer",className:"related-paper",style:{textDecoration:"none",color:"inherit"},children:[e.jsx("div",{className:"related-title",children:e.jsx(He,{title:a.title})}),e.jsxs("div",{className:"related-meta",children:[e.jsx("span",{children:a.arxiv_id?`arXiv:${a.arxiv_id}`:"External resource"}),a.citation_count!=null&&e.jsxs("span",{children:[a.citation_count.toLocaleString()," cites"]})]})]},a.id))]}):null}const pn=/(https?:\/\/[^\s]+)/g;function fn({size:t=12}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24","aria-hidden":"true",focusable:"false",children:e.jsx("path",{fill:"currentColor",d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"})})}function Kt(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}k`:String(t)}function gn(t){return new Date(t).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}function xn({text:t}){return e.jsx("p",{className:"x-thread-text",children:t.split(pn).map((s,a)=>a%2===1?e.jsx("span",{className:"x-thread-link",children:s.replace(/^https?:\/\/(www\.)?/,"").replace(/\/$/,"")},a):e.jsx(m.Fragment,{children:s},a))})}function bn({thread:t}){const[s,a]=m.useState(!1);return!t.author_avatar_url||s?e.jsx("span",{className:"x-thread-avatar x-thread-avatar--fallback","aria-hidden":"true",children:t.author_name.charAt(0).toUpperCase()}):e.jsx("img",{className:"x-thread-avatar",src:t.author_avatar_url,alt:"",loading:"lazy",referrerPolicy:"no-referrer",onError:()=>a(!0)})}function jn(){var t;return((t=window.matchMedia)==null?void 0:t.call(window,"(prefers-reduced-motion: reduce)").matches)??!1}function vn({thread:t}){const[s,a]=m.useState(!1),[r,n]=m.useState(null),[c,o]=m.useState(!1),i=m.useRef(null),{targetRef:d,isIntersecting:p}=Ta({rootMargin:"200px"}),f=t.video_url;if(m.useEffect(()=>{if(!f||r||c||!p||jn())return;const g=new AbortController;return fetch(f,{referrerPolicy:"no-referrer",signal:g.signal}).then(b=>{if(!b.ok)throw new Error(`HTTP ${b.status}`);return b.blob()}).then(b=>n(URL.createObjectURL(b))).catch(()=>{g.signal.aborted||o(!0)}),()=>g.abort()},[f,r,c,p]),m.useEffect(()=>()=>{r&&URL.revokeObjectURL(r)},[r]),m.useEffect(()=>{const g=i.current;g&&(p?g.play().catch(()=>{}):g.pause())},[p,r]),!t.media_url||s)return null;const l=r&&!c;return e.jsx("div",{className:"x-thread-media",ref:d,children:l?e.jsx("video",{ref:i,src:r,poster:t.media_url,muted:!0,loop:!0,playsInline:!0,autoPlay:!0,"aria-label":"Video",onError:()=>o(!0)}):e.jsxs(e.Fragment,{children:[e.jsx("img",{src:t.media_url,alt:"",loading:"lazy",referrerPolicy:"no-referrer",onError:()=>a(!0)}),t.media_type==="video"&&e.jsx("span",{className:"x-thread-play","aria-label":"Video",children:"▶"})]})})}function yn({thread:t}){const s=we(t.url);return s?e.jsxs("a",{href:s,target:"_blank",rel:"noopener noreferrer",className:"x-thread",children:[e.jsxs("div",{className:"x-thread-header",children:[e.jsx(bn,{thread:t}),e.jsxs("span",{className:"x-thread-author",children:[e.jsx("span",{className:"x-thread-name",children:t.author_name}),e.jsxs("span",{className:"x-thread-handle",children:["@",t.author_handle]})]}),e.jsx("span",{className:"x-thread-logo",children:e.jsx(fn,{})})]}),e.jsx(xn,{text:t.text}),e.jsx(vn,{thread:t}),e.jsxs("div",{className:"x-thread-meta",children:[t.posted_at&&e.jsx("time",{dateTime:t.posted_at,children:gn(t.posted_at)}),t.like_count!=null&&e.jsxs("span",{children:["♥ ",Kt(t.like_count)]}),t.reply_count!=null&&t.reply_count>0&&e.jsxs("span",{children:[Kt(t.reply_count)," ",t.reply_count===1?"reply":"replies"]}),e.jsx("span",{className:"x-thread-read",children:"Read on X →"})]})]}):null}function wn({onEdit:t,threads:s}){return e.jsxs("div",{className:"sidebar-card",children:[e.jsxs("div",{className:"sidebar-card-title",children:[e.jsx("span",{children:"X threads"}),e.jsxs("span",{className:"badge",children:[s.length," post",s.length===1?"":"s",e.jsx("button",{type:"button",onClick:t,className:"edit-link",children:"edit"})]})]}),s.length>0?e.jsx("div",{className:"x-thread-list",children:s.map(a=>e.jsx(yn,{thread:a},a.tweet_id))}):e.jsx("div",{style:{fontFamily:"var(--mono)",fontSize:11,color:"var(--ink-faint)",padding:"6px 0"},children:"No author threads linked yet."})]})}const ut=3,Gt=3;function _n(t){return t>=1e3?`${(t/1e3).toFixed(1)}k`:String(t)}function kn({allHfArtifactUrls:t,citationCopied:s,citationDisplay:a,hfArtifactViewer:r,onCopyCitation:n,onEditHfArtifacts:c,onEditRepositories:o,onEditXThreads:i,paper:d,relatedIsLoading:p,relatedPapers:f,user:l}){var v;const[g,b]=m.useState(!1),w=[...d.repositories??[]].sort((C,P)=>Number(P.is_official)-Number(C.is_official)||(P.num_stars||0)-(C.num_stars||0)),j=(g?w:w.slice(0,ut)).map(C=>({...C,safeHref:we(C.url)}));return e.jsxs("aside",{className:"detail-sidebar",children:[e.jsxs("div",{className:"sidebar-card",children:[e.jsxs("div",{className:"sidebar-card-title",children:[e.jsx("span",{children:"GitHub"}),e.jsxs("span",{className:"badge",children:[w.length," repo",w.length===1?"":"s",e.jsx("button",{type:"button",onClick:o,className:"edit-link",children:"edit"})]})]}),j.filter(({safeHref:C})=>C).map(C=>e.jsxs("a",{href:C.safeHref??void 0,target:"_blank",rel:"noopener noreferrer",className:"code-line",style:{textDecoration:"none"},children:[e.jsxs("span",{className:"code-line-repo",children:[e.jsx(J,{name:"github",size:12}),e.jsxs("span",{className:"code-line-repo-name",children:[C.owner,"/",C.name]}),C.is_official&&e.jsx("span",{className:"code-line-official",children:"· Official"})]}),e.jsxs("span",{className:"code-line-stars",children:["★ ",_n(C.num_stars)]})]},C.id)),w.length===0&&e.jsx("div",{style:{fontFamily:"var(--mono)",fontSize:11,color:"var(--ink-faint)",padding:"6px 0"},children:"No GitHub repositories linked yet."}),w.length>ut&&e.jsx("button",{type:"button",className:"bench-show-more",onClick:()=>b(C=>!C),children:g?"− show top 3":`+ show ${w.length-ut} more repos`})]}),e.jsx(Nn,{viewer:r,onEdit:c}),e.jsx(wn,{threads:d.x_threads??[],onEdit:i}),e.jsx(mn,{githubUrls:w.map(({url:C})=>C),hfModelUrls:t.models,hfDatasetUrls:t.datasets,hfSpaceUrls:t.spaces,paperId:d.id,pdfName:((v=d.arxiv_id)==null?void 0:v.replace("/","-"))||d.id,pdfUrl:d.url_pdf,isSignedIn:!!l,suggestedBucketId:l?`${l.username}/${un(d.title)}`:void 0}),e.jsx(hn,{isLoading:p,papers:f}),e.jsxs("div",{className:"sidebar-card",children:[e.jsxs("div",{className:"sidebar-card-title",children:[e.jsx("span",{children:"Citation"}),e.jsxs("button",{type:"button",className:"citation-copy-btn",onClick:n,"aria-label":"Copy citation to clipboard",title:"Copy citation to clipboard",children:[e.jsx(J,{name:"copy",size:11}),s?"Copied":"Copy"]})]}),e.jsx("pre",{style:{fontFamily:"var(--mono)",fontSize:10.5,lineHeight:1.5,color:"var(--ink-soft)",whiteSpace:"pre-wrap",wordBreak:"break-word",margin:0},children:a})]})]})}function Nn({onEdit:t,viewer:s}){return e.jsxs("div",{className:"sidebar-card",children:[e.jsxs("div",{className:"sidebar-card-title",children:[s.paperHref?e.jsx("a",{href:s.paperHref,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:"🤗 Hugging Face"}):e.jsx("span",{children:"🤗 Hugging Face"}),e.jsx("button",{type:"button",onClick:t,className:"edit-link",children:"edit"})]}),s.isLoading?e.jsx(Ie,{className:"h-16 w-full"}):e.jsxs(e.Fragment,{children:[s.rows.map(a=>e.jsx(Cn,{...a},a.label)),s.footer&&e.jsx("div",{style:{fontFamily:"var(--mono)",fontSize:10,color:"var(--ink-faint)",marginTop:12},children:s.footer})]})]})}function Cn({count:t,href:s,isLimited:a,label:r,links:n}){const[c,o]=m.useState(!1),i=((n==null?void 0:n.length)??0)>Gt,d=c?n:n==null?void 0:n.slice(0,Gt),p=t!=null?`${t}${a?"+":""}`:"—";return e.jsxs("div",{className:"hf-artifact-row",children:[e.jsxs("div",{className:"hf-artifact-row-header",children:[e.jsx("span",{children:r}),t?e.jsx("a",{href:s,target:"_blank",rel:"noopener noreferrer",className:"hf-artifact-count",children:p}):e.jsx("span",{className:"hf-artifact-count hf-artifact-count--empty",children:p})]}),d!=null&&d.length?e.jsxs("div",{className:"hf-artifact-links",children:[d.map(f=>e.jsx("a",{href:f.href,target:"_blank",rel:"noopener noreferrer",children:f.label},f.href)),i&&e.jsx("button",{type:"button",className:"hf-artifact-toggle","aria-expanded":c,onClick:()=>o(f=>!f),children:c?"Show fewer":`View all ${n.length}`})]}):null]})}function En(t,s){const a=t.arxiv_id?` (arXiv:${t.arxiv_id.replace(/v\d+$/i,"")})`:"";return`About the paper "${t.title}"${a}: ${s}`}function Sn({paper:t,readerChatRoute:s}){const a=Gs()&&!!(t.id&&t.abstract),{data:r}=ne({queryKey:["paper-suggested-questions",t.id],queryFn:()=>W.suggestedQuestions(String(t.id)),enabled:a,staleTime:c=>{var o;return(o=c.state.data)!=null&&o.questions.length?1/0:0},retry:!1}),n=(r==null?void 0:r.questions)??[];return!a||n.length===0?null:e.jsx("ul",{className:"suggested-questions","aria-label":"Ask about this paper",children:n.map(c=>{const o=s?`${s}?q=${encodeURIComponent(c)}`:`/chat?q=${encodeURIComponent(En(t,c))}`;return e.jsx("li",{children:e.jsxs(ue,{className:"suggested-question",to:o,onClick:s?()=>ss(s):void 0,children:[e.jsx(J,{name:"chat",size:12}),e.jsx("span",{children:c})]})},c)})})}const Xt=360;function Pn({canEdit:t,onEditMethods:s,onEditTasks:a,paper:r,readerChatRoute:n}){var f,l;const[c,o]=m.useState(!1),i=r.abstract||"",d=i.length>Xt,p=c||!d?i:`${i.slice(0,Xt)}…`;return e.jsxs(e.Fragment,{children:[r.tldr&&e.jsxs(e.Fragment,{children:[e.jsx(Pe,{id:"tldr",label:"TL;DR"}),e.jsx("div",{className:"tldr-box",children:r.tldr})]}),e.jsx(Sn,{paper:r,readerChatRoute:n}),e.jsx(Pe,{id:"abstract",label:"Abstract"}),e.jsx("p",{className:"abstract-text",style:{marginBottom:8},children:e.jsx(ia,{text:p})}),d&&e.jsx("button",{type:"button",className:"read-full",onClick:()=>o(g=>!g),children:c?"− collapse abstract":"+ read full abstract"}),e.jsx(Pe,{id:"tasks",label:"Tasks",accent:e.jsxs("span",{className:"accent",children:[((f=r.tasks)==null?void 0:f.length)||0," tagged",t&&e.jsx("button",{type:"button",onClick:a,className:"edit-link",children:"edit"})]})}),e.jsx("div",{className:"paper-tags",style:{marginBottom:8},children:(r.tasks??[]).map(g=>e.jsx(ta,{slug:g.slug||"",label:g.name},g.id))}),e.jsx(Pe,{id:"methods",label:"Methods",accent:e.jsxs("span",{className:"accent",children:[((l=r.methods)==null?void 0:l.length)||0," used",t&&e.jsx("button",{type:"button",onClick:s,className:"edit-link",children:"edit"})]})}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:8},children:(r.methods??[]).map(g=>e.jsx(sa,{method:g},g.id))})]})}const Ce=["my-bookmark-ids"],jt="pwc:pending-bookmark";function $n(t){window.sessionStorage.setItem(jt,JSON.stringify(t)),window.location.assign(Ua(!0))}function In(){var r,n;const{user:t}=Oe(),s=ne({queryKey:Ce,queryFn:()=>pt.getBookmarkIds(),enabled:!!t,staleTime:60*1e3,refetchOnWindowFocus:!1}),a=qe.useMemo(()=>{var c;return new Set(((c=s.data)==null?void 0:c.paper_ids)??[])},[(r=s.data)==null?void 0:r.paper_ids]);return{ids:((n=s.data)==null?void 0:n.paper_ids)??[],idSet:a,isLoading:s.isLoading,isError:s.isError}}function Rn(){const{user:t}=Oe(),s=he(),a=ce({mutationFn:async({paperId:n,isBookmarked:c})=>{c?await pt.removeBookmark(n):await pt.addBookmark(n)},onMutate:async({paperId:n,isBookmarked:c})=>{await s.cancelQueries({queryKey:Ce});const o=s.getQueryData(Ce),i=typeof n=="string"?Number(n):n,d=(o==null?void 0:o.paper_ids)??[],p=c?d.filter(f=>f!==i):[i,...d.filter(f=>f!==i)];return s.setQueryData(Ce,{paper_ids:p}),{previous:o}},onError:(n,c,o)=>{o!=null&&o.previous&&s.setQueryData(Ce,o.previous),n instanceof ht&&n.code==="saved_papers_bucket_authorization_required"&&$n(c)},onSettled:()=>{s.invalidateQueries({queryKey:Ce}),s.invalidateQueries({queryKey:[...ye.feeds.saved]})}});return qe.useEffect(()=>{if(!t||a.isPending)return;const n=new URL(window.location.href);if(n.searchParams.get(Bt)!=="1")return;n.searchParams.delete(Bt),window.history.replaceState({},"",`${n.pathname}${n.search}${n.hash}`);const c=window.sessionStorage.getItem(jt);if(c){window.sessionStorage.removeItem(jt);try{const o=JSON.parse(c);(typeof o.paperId=="number"||typeof o.paperId=="string")&&typeof o.isBookmarked=="boolean"&&a.mutate(o)}catch{}}},[a,t]),{toggle:qe.useCallback((n,c)=>{if(!t){if(ts())return;const o=typeof window<"u"?window.location.pathname+window.location.search:"/";window.location.href=Xs(`/api/v1/auth/hf/login?return_to=${encodeURIComponent(o)}`);return}a.mutate({paperId:n,isBookmarked:c})},[a,t]),isPending:a.isPending}}const An=({paperId:t})=>{const{user:s}=Oe(),{idSet:a}=In(),{toggle:r,isPending:n}=Rn();if(ts())return null;const c=Number(t),o=!!s&&a.has(c),i=()=>{Number.isFinite(c)&&r(c,o)},d=s&&o?"Saved":"Save",p=s?o?"Remove from saved papers":"Save this paper":"Sign in with Hugging Face to save this paper";return e.jsxs("button",{type:"button",className:`action-btn${o?" is-saved":""}`,onClick:i,disabled:n,"aria-pressed":o,"aria-label":p,title:p,children:[e.jsx(J,{name:"bookmark",size:12}),d]})};function mt({children:t,showEdit:s=!1,onEdit:a,editAriaLabel:r}){return s?e.jsxs("span",{className:"action-btn-composite",children:[t,e.jsx("button",{type:"button",className:"action-btn-segment action-btn-edit",onClick:a,"aria-label":r,children:"edit"})]}):t}function Ln(t){return e.jsx(xs,{...t,kind:"enrich-paper",triggerClassName:"action-btn"})}const Fn={tasks:"tasks",methods:"methods",results:"evaluation results",repositories:"GitHub repositories","project-pages":"project pages","hf-artifacts":"Hugging Face artifacts",organizations:"organizations","source-url":"source URL","x-threads":"X threads"};function Qt(t){if(!t)return"—";try{return new Date(t).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}catch{return"—"}}function Vt(t,s){try{const a=new URL(t),n=a.pathname.replace(/\/$/,"").split("/").filter(Boolean).at(-1);return n?n.replace(/[-_]+/g," "):a.hostname.replace(/^www\./,"")}catch{return s}}const _i=()=>{const{arxivId:t}=Qs(),s=Wt(),{toast:a}=oe(),{user:r}=Oe(),n=(r==null?void 0:r.is_admin)??!1,c=!!r,o=Ha(r),{arxivId:i,evaluations:d,evaluationsByTask:p,evaluationsLoading:f,paper:l,paperError:g,paperLoading:b,presentation:w,refetchEvaluations:j,refetchPaper:v,relatedQuery:C,versions:P,visibleEvaluations:I}=ar(t,o),[S,_]=m.useState(!1),{activeEditor:u,openEditor:x,setEditorOpen:E}=ir();m.useEffect(()=>{o!=="direct"||!(l!=null&&l.id)||(u&&u!=="results"&&W.primeCurationState(l.id).catch(()=>{}),u==="results"&&Ke.primeCurationState(l.id).catch(()=>{}))},[u,o,l==null?void 0:l.id]);const[F,M]=m.useState(null),O=m.useRef(!1);m.useEffect(()=>{if(!r||!l||O.current)return;const N=sessionStorage.getItem("pwc:fresh-auth-edit");if(!N)return;O.current=!0;const q=nr(N);if(!W.freshAuthMutationDraft()){sessionStorage.removeItem("pwc:fresh-auth-edit"),q&&x(q);return}if(!window.confirm("You signed in again. Apply the saved destructive catalog edit now? The server will recheck the current catalog version before changing anything.")){a({title:"Edit kept locally",description:"Nothing was changed. Reload this paper when you are ready to confirm the saved edit."});return}W.resumeFreshAuthMutation().then(()=>{a({title:"Edit applied",description:"The restored catalog edit was applied."}),window.location.reload()}).catch(At=>{a({variant:"destructive",title:"Could not apply the saved edit",description:At instanceof Error?At.message:"Please reload and review the edit again."})})},[x,l,a,r]);const K=m.useMemo(()=>{if(!r||!(l!=null&&l.author_links))return!1;const N=r.username.toLowerCase();return l.author_links.some(q=>!!q.hf_username&&q.hf_username.toLowerCase()===N)},[r,l==null?void 0:l.author_links]),G=N=>{if(!c){M(N);return}x(N)},[h,$]=m.useState("idle"),[R,T]=m.useState(null),[U,z]=m.useState(null),H=async()=>{if(i){$("indexing"),T(null),z(null);try{await W.indexFromArxiv(i),a({title:"Indexed",description:"Paper added to database."}),setTimeout(()=>v(),1200),$("idle")}catch(N){const q=N;let xe=q.message||"Failed to index paper";if(q.response)try{xe=JSON.parse(q.response).detail||xe}catch{xe=q.response}T(xe),(q.status===429||q.status===503)&&z("Try again later after arXiv has lifted the temporary limit."),$("idle")}}},Y=(w==null?void 0:w.citationCopy)??"",Z=(w==null?void 0:w.copyableRanks)??[],[Ve,De]=m.useState(!1),ve=async()=>{if(Y)try{await navigator.clipboard.writeText(Y),De(!0),a({title:"Citation copied",description:"BibTeX entry copied to clipboard."}),window.setTimeout(()=>De(!1),1500)}catch{a({title:"Copy failed",description:"Could not access the clipboard. Please copy manually.",variant:"destructive"})}},y=async()=>{if(!l)return;const N=l.arxiv_id||l.id,q=qa(N,Z);if(q)try{await navigator.clipboard.writeText(q),a({title:"PwC badges copied",description:"Each badge follows its current leaderboard result."})}catch{a({title:"Copy failed",description:"Could not access the clipboard. Please try again.",variant:"destructive"})}};if(b)return e.jsxs("div",{className:"page",children:[e.jsx(Ie,{className:"h-12 w-3/4 mb-4"}),e.jsx(Ie,{className:"h-6 w-1/3 mb-8"}),e.jsx(Ie,{className:"h-64 w-full"})]});if(g||!l)return e.jsxs("div",{className:"page",children:[e.jsxs("div",{className:"breadcrumb",children:[e.jsx(ue,{to:"/papers",children:"Papers"}),e.jsx("span",{className:"sep",children:"/"}),e.jsxs("span",{style:{color:"var(--ink)"},children:["arXiv:",i]})]}),e.jsx("h1",{className:"detail-title",children:"Paper not indexed yet"}),e.jsxs("p",{style:{fontFamily:"var(--serif)",color:"var(--ink-soft)",marginTop:16,maxWidth:640},children:["We don't have ",e.jsxs("span",{style:{fontFamily:"var(--mono)"},children:["arXiv:",i]})," in the database. You can index it from arXiv right now."]}),R&&e.jsx(pa,{variant:"destructive",className:"mt-4 max-w-xl",children:e.jsxs(fa,{children:[e.jsx("div",{children:R}),U&&e.jsx("div",{className:"mt-2",children:U})]})}),e.jsxs("div",{className:"action-row",children:[n&&e.jsxs("button",{className:"action-btn",onClick:H,disabled:h==="indexing",children:[e.jsx(J,{name:"sparkle",size:12}),h==="indexing"?"Indexing…":"Index from arXiv"]}),e.jsx(L,{variant:"outline",onClick:()=>s("/papers"),children:"Browse Papers"})]})]});if(!w)return null;const{allHfArtifactUrls:k,authorEntries:A,citationDisplay:D,hasIntroducedItems:Q,hasLineageItems:X,hfArtifactViewer:B,introducedBenchmarks:Rs,introducedFrameworks:Ct,introducedMethods:As,introducedSummary:Ls,numPages:Et,paperSourceLabel:St,predecessorPapers:We,projectPages:Ee,safeAbstractUrl:Pt,safeConferenceUrl:$t,safePdfUrl:It,sourceActionLabel:Fs,successorPapers:Je}=w,Be=12,Se=ca(l,i),Ts=Se&&Lt()&&Vs()&&(!Ft()||n)?Se:null,Rt=S||A.length<=Be?A:A.slice(0,Be);return e.jsxs("div",{className:"page",children:[e.jsxs("div",{className:"breadcrumb",children:[e.jsx(ue,{to:"/",children:"Trending"}),e.jsx("span",{className:"sep",children:"/"}),e.jsx("span",{children:St})]}),e.jsxs("div",{className:"detail-grid",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"detail-hero",children:[e.jsxs("div",{className:"detail-hero-main",children:[e.jsxs("h1",{className:"detail-title",children:[e.jsx(He,{title:l.title}),(l.organizations||[]).map(N=>e.jsx(ue,{to:`/orgs/${N.slug}`,className:`detail-title-org${N.logo_url?" detail-title-org--logo":""}`,title:N.name,"aria-label":N.name,children:N.logo_url?e.jsx("img",{src:N.logo_url,alt:"",onError:q=>{var xe;(xe=q.currentTarget.parentElement)==null||xe.classList.remove("detail-title-org--logo"),q.currentTarget.replaceWith(N.name)}}):N.name},N.id))]}),e.jsxs("div",{className:"detail-meta",children:[e.jsx("span",{children:St}),e.jsx("span",{children:"·"}),e.jsxs("span",{children:["Submitted ",Qt(l.published)]}),Et&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsxs("span",{children:[Et," pages"]})]}),l.citation_count!=null&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsxs("span",{children:[l.citation_count.toLocaleString()," citations"]})]}),(l.proceeding||l.conference_slug)&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),l.conference_slug?e.jsx("a",{href:`/conferences/${l.conference_slug}`,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent-text)"},children:(l.proceeding||l.conference_name||"").replace(/\s+\d{1,2}$/,"")}):e.jsx("span",{children:l.proceeding.replace(/\s+\d{1,2}$/,"")})]}),P.length>1&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsx("select",{className:"version-select",value:l.version,onChange:N=>{const q=N.target.value;l.arxiv_id&&s(`/paper/${l.arxiv_id.replace(/v\d+$/,"")}${q?`?version=${q}`:""}`)},children:P.map(N=>e.jsxs("option",{value:N.version,children:[N.version," — ",Qt(N.published)]},N.version))})]})]}),e.jsxs("div",{className:"detail-authors",children:[Rt.map((N,q)=>e.jsxs(qe.Fragment,{children:[N.hf_username&&e.jsx(aa,{className:"detail-author-avatar",url:N.hf_avatar_url}),N.id?e.jsx(ue,{to:`/authors/${N.id}`,children:N.name}):N.hf_username?e.jsx("a",{href:`https://huggingface.co/${N.hf_username}`,target:"_blank",rel:"noopener noreferrer",title:`@${N.hf_username} on Hugging Face`,children:N.name}):e.jsx("a",{children:N.name}),qBe&&e.jsx("button",{className:"show-more-authors",onClick:()=>_(N=>!N),style:{marginLeft:8,background:"none",border:"none",cursor:"pointer",color:"var(--accent-text)",fontFamily:"var(--mono)",fontSize:12},children:S?"show fewer":`+${l.authors.length-Be} more`})]}),e.jsxs("div",{className:"action-row",children:[Se&&Lt()&&(!Ft()||r!=null&&r.is_admin)?e.jsxs(ue,{className:"action-btn",to:Se,onClick:()=>ss(Se),children:[e.jsx(J,{name:"pdf",size:12})," Read paper",e.jsx("span",{className:"nav-new-badge","aria-hidden":"true",children:"New"})]}):It?e.jsxs("a",{className:"action-btn",href:It,target:"_blank",rel:"noopener noreferrer",children:[e.jsx(J,{name:"pdf",size:12})," View PDF"]}):null,Pt&&e.jsx(mt,{showEdit:l.source==="external",onEdit:()=>G("source-url"),editAriaLabel:"Edit source URL",children:e.jsxs("a",{className:l.source==="external"?"action-btn-segment action-btn-main":"action-btn",href:Pt,target:"_blank",rel:"noopener noreferrer",children:[e.jsx(J,{name:"external",size:12})," ",Fs]})}),Ee.length===1?e.jsx(mt,{showEdit:!0,onEdit:()=>G("project-pages"),editAriaLabel:"Edit project pages",children:e.jsxs("a",{className:"action-btn-segment action-btn-main",href:Ee[0].safeHref??void 0,target:"_blank",rel:"noopener noreferrer",children:[e.jsx(J,{name:"globe",size:12})," Project page"]})}):null,Ee.length>1?e.jsx(mt,{showEdit:!0,onEdit:()=>G("project-pages"),editAriaLabel:"Edit project pages",children:e.jsxs(Ws,{children:[e.jsx(Js,{asChild:!0,children:e.jsxs("button",{type:"button",className:"action-btn-segment action-btn-main",children:[e.jsx(J,{name:"globe",size:12})," Project page"]})}),e.jsx(Ys,{align:"start",className:"project-page-menu",children:Ee.map((N,q)=>e.jsx(Zs,{asChild:!0,children:N.safeHref?e.jsx("a",{href:N.safeHref,target:"_blank",rel:"noopener noreferrer",children:Vt(N.url,`Project page ${q+1}`)}):e.jsx("span",{children:Vt(N.url,`Project page ${q+1}`)})},N.url))})]})}):null,Ee.length===0&&c?e.jsxs("button",{type:"button",className:"action-btn",onClick:()=>G("project-pages"),title:"Add project page",children:[e.jsx(J,{name:"globe",size:12})," Add project page"]}):null,$t&&e.jsxs("a",{className:"action-btn",href:$t,target:"_blank",rel:"noopener noreferrer",children:[e.jsx(J,{name:"external",size:12})," Conference"]}),e.jsx("button",{type:"button",className:"action-btn",onClick:()=>G("organizations"),children:"Edit organizations"}),e.jsx(or,{paperId:Number(l.id),isAdmin:n}),n&&Aa()&&e.jsx(Ln,{paperId:Number(l.id),paperTitle:l.title,onComplete:()=>void v()}),e.jsx(An,{paperId:l.id})]}),l.leaderboard_ranks&&l.leaderboard_ranks.length>0&&e.jsx(ra,{wrap:!0,paperHref:`/paper/${l.arxiv_id||l.id}`,ranks:l.leaderboard_ranks.filter(N=>N.best_rank>=1&&N.best_rank<=3).map(N=>({name:N.dataset_name,slug:N.dataset_slug||null,rank:N.best_rank}))})]}),e.jsx("div",{className:"detail-hero-thumb detail-thumb-wrap",children:e.jsx(na,{paperId:l.arxiv_id||l.id,title:l.title,thumbnailUrl:ea(l.thumbnail_url),priority:!0})})]}),Q&&e.jsxs("div",{className:`introduced-banner${Ct.length>0?" introduced-banner--framework":""}`,children:[e.jsx("span",{className:"introduced-label",children:"Introduced"}),e.jsxs("div",{className:"introduced-methods",children:[As.map(N=>e.jsxs("button",{type:"button",className:"introduced-pill",onClick:()=>s(`/methods/${N.slug||N.id}`),children:[N.name,e.jsx("span",{className:"introduced-arrow",children:"→"})]},`method-${N.id}`)),Rs.map(N=>e.jsxs("button",{type:"button",className:"introduced-pill",onClick:()=>s(`/benchmark/${N.slug||N.id}`),children:[N.name,e.jsx("span",{className:"introduced-arrow",children:"→"})]},`benchmark-${N.id}`)),Ct.map(N=>e.jsxs("button",{type:"button",className:"introduced-pill",onClick:()=>s(`/frameworks#framework-${N.slug}`),children:[N.name,e.jsx("span",{className:"introduced-arrow",children:"→"})]},`framework-${N.slug}`))]}),e.jsxs("span",{className:"introduced-note",children:["This paper is the canonical source for ",Ls,"."]})]}),X&&e.jsxs("div",{className:"introduced-banner lineage-banner",children:[Je.length>0&&e.jsxs("div",{className:"lineage-row",children:[e.jsx("span",{className:"introduced-label lineage-label",children:Je.length===1?"Follow-up paper":"Follow-up papers"}),e.jsx("div",{className:"introduced-methods",children:Je.map(N=>e.jsxs("button",{type:"button",className:"introduced-pill lineage-pill",onClick:()=>s(`/paper/${N.route_identifier}`),children:[e.jsx(He,{title:N.title}),e.jsx("span",{className:"introduced-arrow",children:"→"})]},`successor-${N.id}`))})]}),We.length>0&&e.jsxs("div",{className:"lineage-row",children:[e.jsx("span",{className:"introduced-label lineage-label",children:We.length===1?"Predecessor paper":"Predecessor papers"}),e.jsx("div",{className:"introduced-methods",children:We.map(N=>e.jsxs("button",{type:"button",className:"introduced-pill lineage-pill",onClick:()=>s(`/paper/${N.route_identifier}`),children:[e.jsx("span",{className:"introduced-arrow lineage-arrow-back",children:"←"}),e.jsx(He,{title:N.title})]},`predecessor-${N.id}`))})]})]}),e.jsx(Pn,{canEdit:!0,onEditMethods:()=>G("methods"),onEditTasks:()=>G("tasks"),paper:l,readerChatRoute:Ts}),e.jsx(Or,{canCopyBadge:Z.length>0,canEdit:!0,evaluationsByTask:p,evaluationsLoading:f,isAdmin:n,onCopyBadge:y,onEdit:()=>G("results"),onRefresh:()=>void j(),paper:l,visibleEvaluationCount:(I==null?void 0:I.length)??0})]}),e.jsx(kn,{allHfArtifactUrls:k,citationCopied:Ve,citationDisplay:D,hfArtifactViewer:B,onCopyCitation:ve,onEditHfArtifacts:()=>G("hf-artifacts"),onEditRepositories:()=>G("repositories"),onEditXThreads:()=>G("x-threads"),paper:l,relatedIsLoading:C.isLoading,relatedPapers:C.data,user:r})]}),e.jsx(zr,{activeEditor:u,arxivId:i,editSubmitMode:o,evaluations:d??[],isAdmin:n,isLinkedAuthor:K,onOpenChange:E,paper:l}),e.jsx(ka,{open:F!==null,onOpenChange:N=>{N||M(null)},sectionLabel:F?Fn[F]:"this paper",returnTo:typeof window<"u"?window.location.pathname:"/"})]})};export{_i as default};