diff --git "a/assets/PaperDetailView-CtpAIvmc.js" "b/assets/PaperDetailView-CtpAIvmc.js" new file mode 100644--- /dev/null +++ "b/assets/PaperDetailView-CtpAIvmc.js" @@ -0,0 +1,34 @@ +import{d as Ee,b as X,D as Vs,E as re,F as Ws,n as Jt,G as W,i as g,I as Ys,J as he,y as z,K as mt,j as e,C as ht,o as Y,t as Q,M as Ne,N as pt,X as Zt,O as Js,P as es,Q as J,R as ts,S as ge,U as fe,V as ss,W as ft,Y as we,Z as It,_ as Rt,$ as Zs,a0 as ea,L as O,a1 as ta,a2 as sa,a3 as aa,a4 as ra,a5 as as,a6 as na,l as ia,a7 as oa,A as Ce,w as la,a as Pe,a8 as rs,a9 as Se,aa as Lt,k as ns,u as ca,ab as At,ac as da,ad as Tt,ae as ua,B as Dt,af as ma,ag as ha,ah as pa,ai as fa,aj as ga,ak as xa,al as ba}from"./index-NBcO0l8D.js";import{u as ae}from"./useMutation-DDSpe6vv.js";import{I as U}from"./Icon-CDHwqzqr.js";import{T as ja,M as va,S as _a,P as ya}from"./SotaBadges-DiTOKEsv.js";import{L as ye,a as nt}from"./LatexTitle-DQVlWHLt.js";import{u as is}from"./preferences-B0V402st.js";import{s as ka,a as Na}from"./transform-CgEp4jFP.js";import{r as os,p as wa}from"./paperReader-td2aJigh.js";import{u as Ca,f as Sa}from"./useDocumentTitle-Ui-QY8AA.js";import{s as V}from"./safeExternalHref-CkBrsh84.js";import{m as Ea}from"./mlIntern-Cyqp95uv.js";import{S as pe}from"./skeleton-CoO_k1O1.js";import{A as Pa,a as $a}from"./alert-qWa4oUsY.js";import{B as A}from"./button-oeFzivcP.js";import{D as $e,a as Ie,c as Re,b as Le,d as Ae,e as gt}from"./dialog-8YRX2SvO.js";import{A as Ia,a as Ra}from"./AgentLogos-Dy25zW40.js";import{C as La}from"./copy-BeESXR2q.js";import{i as ls,a as cs,r as Aa,b as Ta,e as Da,p as Ua}from"./cacheSync-KjnuatN5.js";import{I as M}from"./input-BRXQunEQ.js";import{S as Ut}from"./searchable-select-DdU29VrE.js";import{L as xt}from"./loader-circle-DcA0voV3.js";import{T as Te,n as Fa,C as Ma}from"./CatalogEntityPreviewLink-DP54Q4yL.js";import{S as ds,L as q,a as Ba}from"./SignInToEditDialog-CNMoKtNX.js";import{u as je}from"./useQueries-VMfgzxeu.js";import{s as us,p as ms}from"./submissions-BPMY0Yrj.js";import{D as za}from"./database-Ccm7PzzG.js";import{P as De}from"./plus-DbzbV8Ld.js";import{S as it}from"./search-B6A4FiI8.js";import{B as Ha}from"./badge-Dq4khHZL.js";import{G as Oa}from"./globe-CxqD68qn.js";import{G as qa}from"./github-CbYlLJ0T.js";import{u as hs}from"./index-DvPWahG-.js";import{C as Ga,E as Xa}from"./ExternalSourceEvalBadge-bbpsmeCD.js";import{M as Ka}from"./index-CiRaZp-O.js";import{r as Qa}from"./index-8xRFMkAV.js";import{u as Va}from"./useIntersectionObserver-BQ1a_M2T.js";import{S as Ft,s as Wa}from"./savedPapersAuth-BhcVCLzK.js";import{o as Ya}from"./organizationNames-BVKzYEBp.js";import{A as Ja}from"./AuthorAvatar-DKabVZBT.js";import"./colors-BkWRhvFI.js";import"./popover-DB7OhDWW.js";import"./hover-card-BBEfZSpy.js";import"./textarea-DE_Y_DjL.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 Za=Ee("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 er=Ee("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 tr=Ee("EyeOff",[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]);/** + * @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 sr=Ee("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 ar(t){return t!=null&&t.can_directly_edit_catalog?"direct":"pending"}function rr(t){return(t??[]).filter(s=>!!(s.dataset_slug&&s.task_slug))}function nr(t,s,r="https://paperswithcode.co"){return s.map(a=>{const n=encodeURIComponent(a.evaluation_id),d=`${r}/api/v1/papers/${encodeURIComponent(t)}/leaderboard-badge.svg?eval=${n}&live=1`,c=`${r}/api/v1/papers/${encodeURIComponent(t)}/leaderboard-badge-link?eval=${n}`;return`[![${`Papers with Code: ${a.best_rank===1?"SOTA":`#${a.best_rank}`} on ${a.dataset_name}`}](${d})](${c})`}).join(` +`)}const ir={models:"https://huggingface.co/",datasets:"https://huggingface.co/datasets/",spaces:"https://huggingface.co/spaces/"},qe=(t,s)=>{const r=(t[s]||[]).length;return r<100?{count:r,isLimited:!1}:{count:r,isLimited:!0}},Ge=(t,s)=>{const r=t[s];return Array.isArray(r)?r.map(a=>{if(typeof a=="string")return a;if(a&&typeof a=="object"){const n=a;return n.id||n.repoId||null}return null}).filter(a=>!!a).map(a=>`${ir[s]}${a}`):[]},or=async t=>{try{return(await fetch(`https://huggingface.co/api/papers/${re(t)}`)).ok}catch{return!1}},lr=async t=>{const s=re(t),[r,a]=await Promise.all([fetch(`https://huggingface.co/api/arxiv/${s}/repos`).then(async o=>o.ok?o.json():(console.warn(`Failed to fetch repos for arXiv:${s}, status: ${o.status}`),null)).catch(o=>(console.warn(`Failed to fetch repos for arXiv:${s}:`,o),null)),or(s)]);if(!r)return{models:0,datasets:0,spaces:0,modelUrls:[],datasetUrls:[],spaceUrls:[],isLimited:!1,paperExists:a};const n=qe(r,"models"),d=qe(r,"datasets"),c=qe(r,"spaces");return{models:n.count,datasets:d.count,spaces:c.count,modelUrls:Ge(r,"models"),datasetUrls:Ge(r,"datasets"),spaceUrls:Ge(r,"spaces"),isLimited:n.isLimited||d.isLimited||c.isLimited,paperExists:a}},cr=t=>X({queryKey:["huggingface-repos",t],queryFn:()=>lr(t),enabled:!!t,staleTime:Vs,retry:1});function dr(t,s){try{const r=new URL(t),a=r.pathname.split("/").filter(Boolean);return(a[0]==="datasets"||a[0]==="spaces")&&a.shift(),a.slice(0,2).join("/")||r.hostname.replace(/^www\./,"")}catch{return s}}function Xe(t,s,r){return[...new Set([...t,...s??[]])].map(a=>({href:a,label:dr(a,r)}))}function Ke(t,s,r){if(r==null&&t.length===0&&!(s!=null&&s.length))return;const a=new Set([...t,...s??[]]);return Math.max(a.size,r??0)}function Qe(t,s){if(!(t==null&&s==null))return Math.max(t??0,s??0)}function Ve(t){return t[0]??"https://huggingface.co"}function We(t,s){return s[0]??t}function ur(t){const s=`${t.title.slice(0,60)}${t.title.length>60?"…":""}`,r=`${t.authors[0]||""}${t.authors.length>1?" et al.":""}`,a=t.authors.join(" and "),n=(t.published||"").slice(0,4)||"—",d=(c,o)=>t.arxiv_id?`@article{${t.arxiv_id.replace(".","")}, + title={{${c}}}, + author=${o}, + year={{${n}}}, + eprint={{${t.arxiv_id}}}, + archivePrefix={{arXiv}} +}`:`@misc{paper${t.id}, + title={{${c}}}, + author=${o}, + year={{${n}}}, + url={{${t.source_url||t.url_abs||""}}} +}`;return{citationDisplay:d(s,`{{${r}}}`),citationCopy:d(t.title,`{${a}}`)}}function mr(t,s,r){var m,b,i;const a={models:t.hf_models??[],datasets:t.hf_datasets??[],spaces:t.hf_spaces??[]},n=t.linked_hf_artifacts,d=t.hf_artifact_summary,c={models:[...(s==null?void 0:s.modelUrls)??[],...(n==null?void 0:n.models)??[]],datasets:[...(s==null?void 0:s.datasetUrls)??[],...(n==null?void 0:n.datasets)??[]],spaces:[...(s==null?void 0:s.spaceUrls)??[],...(n==null?void 0:n.spaces)??[]]},o={models:Qe(s==null?void 0:s.models,d==null?void 0:d.model_count),datasets:Qe(s==null?void 0:s.datasets,d==null?void 0:d.dataset_count),spaces:Qe(s==null?void 0:s.spaces,d==null?void 0:d.space_count)},u={models:Xe(a.models,c.models,"Model"),datasets:Xe(a.datasets,c.datasets,"Dataset"),spaces:Xe(a.spaces,c.spaces,"Space")},x={models:u.models.map(({href:f})=>f),datasets:u.datasets.map(({href:f})=>f),spaces:u.spaces.map(({href:f})=>f)},p=t.arxiv_id!=null?re(t.arxiv_id):null,j=t.arxiv_id?{isLoading:r,paperHref:`https://huggingface.co/papers/${p}`,rows:[{label:"Models",href:We(`https://huggingface.co/models?other=arxiv:${t.arxiv_id}`,a.models),count:Ke(a.models,c.models,o.models),isLimited:s==null?void 0:s.isLimited,links:u.models},{label:"Datasets",href:We(`https://huggingface.co/datasets?other=arxiv:${t.arxiv_id}`,a.datasets),count:Ke(a.datasets,c.datasets,o.datasets),isLimited:s==null?void 0:s.isLimited,links:u.datasets},{label:"Spaces",href:We(`https://huggingface.co/papers/${p}`,a.spaces),count:Ke(a.spaces,c.spaces,o.spaces),isLimited:s==null?void 0:s.isLimited,links:u.spaces}],footer:`Cite arxiv.org/abs/${p} in a HF README to link it here.`}:{isLoading:!1,paperHref:null,rows:[{label:"Models",href:Ve(a.models),count:a.models.length,links:u.models},{label:"Datasets",href:Ve(a.datasets),count:a.datasets.length,links:u.datasets},{label:"Spaces",href:Ve(a.spaces),count:a.spaces.length,links:u.spaces}],footer:null},l=(t.methods??[]).filter(({source_paper_id:f})=>f===t.id),h=t.introduced_benchmarks??[],v=t.introduced_frameworks??[],w=[l.length&&(l.length===1?"this method":"these methods"),h.length&&(h.length===1?"this benchmark":"these benchmarks"),v.length&&(v.length===1?"this framework":"these frameworks")].filter(f=>!!f);return{...ur(t),allHfArtifactUrls:x,authorEntries:t.authors.map((f,_)=>{var S,E,$,C,R,L;return{name:f,id:((E=(S=t.author_links)==null?void 0:S[_])==null?void 0:E.id)??null,hf_username:((C=($=t.author_links)==null?void 0:$[_])==null?void 0:C.hf_username)??null,hf_avatar_url:((L=(R=t.author_links)==null?void 0:R[_])==null?void 0:L.hf_avatar_url)??null}}),copyableRanks:rr(t.leaderboard_ranks),hasIntroducedItems:w.length>0,hasLineageItems:!!((m=t.predecessor_papers)!=null&&m.length||(b=t.successor_papers)!=null&&b.length),hfArtifactViewer:j,hfPaperExists:!!(s!=null&&s.paperExists),introducedBenchmarks:h,introducedFrameworks:v,introducedMethods:l,introducedSummary:w.join(" and "),numPages:t.num_pages||null,paperSourceLabel:t.arxiv_id?`arXiv:${t.arxiv_id}`:"External resource",predecessorPapers:t.predecessor_papers??[],projectPages:((i=t.project_pages)==null?void 0:i.filter(({url:f})=>f).map(f=>({...f,safeHref:V(f.url)})))??[],repoSummary:ka(t.repositories),safeAbstractUrl:V(t.url_abs),safeConferenceUrl:V(t.conference_url_abs),safePdfUrl:V(t.url_pdf),successorPapers:t.successor_papers??[]}}const hr=["tldr","abstract","tasks","methods","results"];function pr(t){if(!t)return{section:null,resultsTaskSlug:null};const[s,r]=t.split("?",2);if(!hr.includes(s))return{section:null,resultsTaskSlug:null};const a=s;return a!=="results"||!r?{section:a,resultsTaskSlug:null}:{section:a,resultsTaskSlug:new URLSearchParams(r).get("task")}}const ps=t=>`results-task-${t}`,fr=t=>`#results?task=${encodeURIComponent(t)}`;function gr({direct:t,paperId:s,refetchEvaluations:r,refetchPaper:a}){a(),r(),!(!t||!s)&&(z.primeCurationState(s,!0).catch(()=>{}),mt.primeCurationState(s,!0).catch(()=>{}))}function xr(t,s){const r=t?Ws(t):"",a=Jt(),{toast:n}=W(),{preferences:d}=is(),c=X(he.detail(r)),o=c.data,[u,x]=g.useState(!1);g.useEffect(()=>{!t||t===r||a(`/paper/${r}${window.location.search}${window.location.hash}`,{replace:!0})},[r,a,t]),Ca((o==null?void 0:o.title)&&(o.page_title||Sa(o.title))),g.useEffect(()=>{if(x(!1),!(o!=null&&o.id))return;const f=window.setTimeout(()=>x(!0),0);return()=>window.clearTimeout(f)},[o==null?void 0:o.id]);const p=u&&!!(o!=null&&o.id),j=cr(u?o==null?void 0:o.arxiv_id:void 0),l=X({...Ys.byPaper(o==null?void 0:o.id),enabled:p,refetchOnMount:"always"}),h=X({...he.versions(o!=null&&o.arxiv_id?re(o.arxiv_id):void 0),enabled:p}),v=X({...he.related((o==null?void 0:o.arxiv_id)||(o==null?void 0:o.id)),enabled:p});g.useEffect(()=>{const f=()=>{gr({direct:s==="direct",paperId:o==null?void 0:o.id,refetchEvaluations:l.refetch,refetchPaper:c.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",f),()=>window.removeEventListener("pwc:catalog-conflict",f)},[s,l.refetch,o==null?void 0:o.id,c.refetch,n]);const w=g.useMemo(()=>{const f=l.data;return!f||!d.hide_closed_source_evals?f:f.filter(_=>_.is_open!==!1)},[l.data,d.hide_closed_source_evals]),m=g.useMemo(()=>{if(!w)return[];const f=new Map;for(const _ of w){const S=f.get(_.task_id);S?S.rows.push(_):f.set(_.task_id,{taskId:_.task_id,taskName:_.task_name||"—",taskSlug:_.task_slug,rows:[_]})}return[...f.values()]},[w]),b=g.useMemo(()=>o?mr(o,j.data,j.isLoading):null,[j.data,j.isLoading,o]),i=g.useRef(!1);return g.useEffect(()=>{i.current=!1},[r]),g.useEffect(()=>{let f=0;const _=(E=!1,$=!1)=>{const{section:C,resultsTaskSlug:R}=pr(window.location.hash.slice(1));if(!C||!o||C==="tldr"&&!o.tldr||C==="results"&&(!p||l.isLoading)||!E&&i.current)return;let L=C==="results"&&R?document.getElementById(ps(R)):document.getElementById(C);if(!L&&C==="results"&&R){if(m.some(({taskSlug:B})=>B===R))return;L=document.getElementById("results")}L&&(f=window.requestAnimationFrame(()=>{i.current=!0,L.scrollIntoView({block:"start",behavior:$?"smooth":"auto"})}))};_();const S=()=>{i.current=!1,_(!0,!0)};return window.addEventListener("hashchange",S),()=>{window.removeEventListener("hashchange",S),f&&window.cancelAnimationFrame(f)}},[m,l.isLoading,o,p]),{arxivId:r,evaluations:l.data,evaluationsByTask:m,evaluationsLoading:l.isLoading,paper:o,paperError:c.error,paperLoading:c.isLoading,presentation:b,refetchEvaluations:l.refetch,refetchPaper:c.refetch,relatedQuery:v,versions:h.data??[],visibleEvaluations:w}}function br(){const[t,s]=g.useState(null),r=g.useCallback(n=>{s(n)},[]),a=g.useCallback((n,d)=>{s(c=>d?n:c===n?null:c)},[]);return{activeEditor:t,openEditor:r,setEditorOpen:a}}function jr({paperId:t}){const[s,r]=g.useState(!1),[a,n]=g.useState(!1),[d,c]=g.useState(!1),o=`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),n(!1),c(!0)},children:[e.jsx(Ia,{}),"Edit with your agent"]}),e.jsx($e,{open:d,onOpenChange:c,children:e.jsxs(Ie,{className:"max-w-2xl",children:[e.jsxs(Re,{children:[e.jsx(Le,{children:"Edit this paper with your agent"}),e.jsx(Ae,{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(Ra,{}),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:o,className:"h-48 w-full resize-none rounded border bg-muted/40 p-3 font-mono text-xs",onFocus:u=>u.currentTarget.select()}),a&&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(A,{className:"justify-self-end",onClick:async()=>{try{await navigator.clipboard.writeText(o),r(!0),n(!1)}catch{n(!0)}},children:[s?e.jsx(ht,{size:14}):e.jsx(La,{size:14}),s?"Prompt copied":"Copy prompt"]})]})})]})}function vr(t){return t.map(s=>{const r=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:r,metric_value:String(s.metrics[r]??""),original_metrics:{...s.metrics},original_metric_name:r,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 _r(t,s){const r={...t.original_metrics},a=r[t.original_metric_name];return t.original_metric_name!==s&&delete r[t.original_metric_name],r[s]=a!=null&&t.metric_value===String(a)?a:t.metric_value,r}function yr(t){const s=t==null?void 0:t.trim();return s?Number(s):void 0}function Mt(t){const s=t.trim();return s?Number(s):null}function Ye(t){return t.trim()||null}function Je(t){return!!(t&&/^\d+$/.test(t.trim())&&Number.isSafeInteger(Number(t))&&Number(t)>0)}function fs(t){const s=[];return t.forEach((r,a)=>{var c;if(r.operation==="unchanged")return;const n=(o,u)=>{s.push({rowIndex:a,field:o,message:u})};if(r.operation!=="create"&&!Je(r.id)&&n("id","This result has no valid evaluation ID. Reload the paper before editing it."),r.operation==="delete")return;Je(r.task_id)||n("task_id","Select a valid task."),Je(r.dataset_id)||n("dataset_id","Select a valid dataset.");const d=r.metric_name.trim();d?d!==r.original_metric_name&&Object.prototype.hasOwnProperty.call(r.original_metrics,d)&&n("metric_name",`Cannot rename a metric to "${d}": this evaluation already has that score.`):n("metric_name","Select a metric."),(c=r.best_rank)!=null&&c.trim()&&!Number.isSafeInteger(Number(r.best_rank))&&n("best_rank","Enter a whole-number rank."),r.num_parameters.trim()&&(!Number.isSafeInteger(Number(r.num_parameters))||Number(r.num_parameters)<0)&&n("num_parameters","Enter a non-negative whole-number parameter count."),r.metric_value.trim()||n("metric_value","Enter a metric value.")}),s}function kr(t,s){const r=fs(t);return r.length?{valid:!1,errors:r}:{valid:!0,operations:Nr(t,s)}}function Nr(t,s){const r=[];for(const a of t){if(a.operation==="delete"){r.push({op:"delete",evaluation_id:Number(a.id)});continue}if(a.operation!=="create"&&a.operation!=="update")continue;const n=a.metric_name.trim(),d=s(a.task_id,a.dataset_id),c={task_id:Number(a.task_id),dataset_id:Number(a.dataset_id),metrics:_r(a,n),best_metric:n,is_open:a.is_open},o=a.model_name.trim(),u=yr(a.best_rank);if(a.operation==="create"){const x=Mt(a.num_parameters),p=Ye(a.hf_model_url);r.push({op:"create",data:{...c,...o?{model_name:o}:{},...d&&a.harness.trim()?{harness:a.harness.trim()}:{},...u!==void 0?{best_rank:u}:{},...x!==null?{num_parameters:x}:{},...p!==null?{hf_model_url:p}:{}}});continue}r.push({op:"update",evaluation_id:Number(a.id),data:{...c,...o?{model_name:o}:{},harness:d?Ye(a.harness):null,...u!==void 0?{best_rank:u}:{},num_parameters:Mt(a.num_parameters),hf_model_url:Ye(a.hf_model_url)}})}return r}function wr(t,s){return s.map(r=>{switch(r.op){case"delete":return{operation:"delete",evaluation_id:r.evaluation_id};case"update":return{operation:"update",evaluation_id:r.evaluation_id,payload:r.data};case"create":return{operation:"create",payload:{paper_id:t,...r.data}}}})}function Cr(t,s){const r=t.metrics(s.task_id,s.dataset_id).metrics.map(a=>({value:a.metric_name,label:a.metric_name,description:a.metric_direction==="higher_is_better"?"Higher is better":"Lower is better"}));return s.metric_name&&!r.some(a=>a.value===s.metric_name)&&r.unshift({value:s.metric_name,label:`${s.metric_name} (legacy)`}),r}const G="text-left py-2 px-2 font-medium text-sm";function Sr({rows:t,catalog:s,draftErrors:r,errorId:a,isAdmin:n,showHarnessColumn:d,onFieldChange:c,onOpenSourceChange:o,onDelete:u}){const x=(l,h)=>r.some(v=>v.rowIndex===l&&v.field===h),p=(l,h)=>{const v=r.find(w=>w.rowIndex===l&&w.field===h);return v?e.jsx("p",{id:`${a}-${l}-${h}-error`,className:"text-xs text-destructive",children:v.message}):null},j=(l,h)=>({id:`${a}-${l}-${h}`,"aria-invalid":x(l,h),"aria-describedby":`${a}-${l}-${h}-error`});return 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:`${G} min-w-[180px]`,children:"Task"}),e.jsx("th",{className:`${G} min-w-[180px]`,children:"Dataset"}),e.jsx("th",{className:`${G} ${d?"min-w-[140px]":"min-w-[240px]"}`,children:"Model"}),d&&e.jsx("th",{className:`${G} min-w-[140px]`,children:"Harness"}),e.jsx("th",{className:`${G} min-w-[140px]`,children:"Metric"}),e.jsx("th",{className:G,children:"Value"}),e.jsx("th",{className:G,children:"Parameters"}),e.jsx("th",{className:`${G} min-w-[200px]`,children:"HF model URL"}),e.jsx("th",{className:`${G} w-20`,children:"Open source"}),e.jsx("th",{className:`${G} w-16`,children:"Action"})]})}),e.jsx("tbody",{children:t.map((l,h)=>{if(l.operation==="delete")return null;const v=s.task(l.task_id),w=s.dataset(l.dataset_id),m=s.metrics(l.task_id,l.dataset_id),b=Cr(s,l);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":`${a}-${h}-task_id-error`,children:[e.jsx(Ut,{value:l.task_id,onChange:i=>c(h,"task_id",i),placeholder:"Select task",searchPlaceholder:"Search tasks...",emptyMessage:"No tasks found.",selectedOption:v?{value:v.id,label:v.name}:null,queryKey:["eval-edit-task-search"],queryFn:s.searchTasks}),p(h,"task_id")]})}),e.jsx("td",{className:"py-2 px-2",children:e.jsxs("div",{role:"group","aria-label":"Dataset","aria-describedby":`${a}-${h}-dataset_id-error`,children:[e.jsx(Ut,{value:l.dataset_id,onChange:i=>c(h,"dataset_id",i),placeholder:l.task_id?"Select dataset":"Select task first",searchPlaceholder:"Search datasets...",emptyMessage:l.task_id?"No datasets found for this task.":"Select a task first.",disabled:!l.task_id,selectedOption:w?{value:w.id,label:w.name}:null,queryKey:["eval-edit-dataset-search",l.task_id],queryFn:s.searchDatasets(l.task_id),enabled:!!l.task_id}),p(h,"dataset_id")]})}),e.jsx("td",{className:"py-2 px-2",children:e.jsx(M,{type:"text",className:"w-full text-sm",placeholder:"Model name",value:l.model_name,onChange:i=>c(h,"model_name",i.target.value)})}),d&&e.jsx("td",{className:"py-2 px-2",children:s.supportsHarness(l.task_id,l.dataset_id)?e.jsx(M,{type:"text",className:"w-full text-sm",placeholder:"Claude Code, Terminus, ...",value:l.harness,onChange:i=>c(h,"harness",i.target.value)}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"Not supported"})}),e.jsxs("td",{className:"py-2 px-2",children:[!l.task_id||!l.dataset_id?e.jsx("span",{className:"text-xs text-muted-foreground",children:"Select task + dataset"}):m.loading?e.jsxs("span",{className:"inline-flex items-center text-xs text-muted-foreground",children:[e.jsx(xt,{className:"mr-1 h-3 w-3 animate-spin"}),"Loading metrics..."]}):b.length>0?e.jsxs("select",{className:"w-full rounded-md border border-border bg-background px-2 py-1 text-sm",...j(h,"metric_name"),value:l.metric_name,onChange:i=>c(h,"metric_name",i.target.value),children:[e.jsx("option",{value:"",children:"Select metric"}),b.map(i=>e.jsx("option",{value:i.value,children:i.label},i.value))]}):!m.error&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"No configured metrics"}),m.error&&e.jsx("p",{className:"text-xs text-destructive",children:"Could not load metrics"}),p(h,"metric_name")]}),e.jsxs("td",{className:"py-2 px-2",children:[e.jsx(M,{type:"text",className:"w-full text-sm",placeholder:"44.9",...j(h,"metric_value"),value:l.metric_value,onChange:i=>c(h,"metric_value",i.target.value)}),p(h,"metric_value")]}),e.jsxs("td",{className:"py-2 px-2",children:[e.jsx(M,{type:"number",min:0,step:1,className:"w-full text-sm",placeholder:"e.g. 7000000000",...j(h,"num_parameters"),value:l.num_parameters,onChange:i=>c(h,"num_parameters",i.target.value),title:"Raw model parameter count (e.g. 7000000000 for a 7B model). Leave blank if unknown."}),p(h,"num_parameters")]}),e.jsx("td",{className:"py-2 px-2",children:e.jsx(M,{type:"url",className:"w-full text-sm",placeholder:"https://huggingface.co/org/model",value:l.hf_model_url,onChange:i=>c(h,"hf_model_url",i.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:l.is_open,onChange:i=>o(h,i.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(A,{variant:"ghost",size:"sm",onClick:()=>u(h),className:"h-8 w-8 p-0 text-destructive hover:text-destructive",title:l.id&&!n?"Only administrators can delete published results":"Remove row",disabled:!!l.id&&!n,children:e.jsx(Te,{className:"w-4 h-4"})})})]},h)})})]})})}function Er(t){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 go live right away."}),e.jsx("p",{className:"mt-1 leading-snug",children:s?"This exercises staging-local pending behavior and is not queued for production review.":"Edits are applied immediately and reviewed afterwards. A few, such as links to unfamiliar sites, are held for an admin first."})]})}function Z({title:t,description:s,className:r,submitMode:a,isAuthor:n=!1,onOpenChange:d,onSave:c,isSaving:o,saveDisabled:u=!1,footerStart:x,children:p}){const j=a==="pending";return e.jsx($e,{open:!0,onOpenChange:d,children:e.jsxs(Ie,{className:r,children:[e.jsxs(Re,{children:[e.jsx(Le,{children:t}),e.jsx(Ae,{children:s})]}),j&&e.jsx(Er,{isAuthor:n}),p,e.jsxs(gt,{children:[x,e.jsx(A,{variant:"outline",onClick:()=>d(!1),children:"Cancel"}),e.jsx(A,{onClick:c,disabled:o||u,children:o?e.jsxs(e.Fragment,{children:[e.jsx(xt,{className:"w-4 h-4 mr-2 animate-spin"}),j?"Submitting...":"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ht,{className:"w-4 h-4 mr-2"}),j?"Submit for review":"Save Changes"]})})]})]})})}const Ze=100,Pr=t=>Q.task(t).queryKey,$r=t=>Q.dataset(t).queryKey;function de(...t){return new Map(t.flat().flatMap(s=>s?[[s.id,s]]:[]))}function et(t){return[...new Set(t.filter(Boolean))]}function Ir(t,s){var b;const r=Y(),a=g.useMemo(()=>et(t.map(i=>i.task_id)),[t]),n=g.useMemo(()=>et(t.map(i=>i.dataset_id)),[t]),d=g.useMemo(()=>et(t.map(i=>i.task_id&&i.dataset_id?`${i.task_id}:${i.dataset_id}`:"")),[t]),c=g.useMemo(()=>de(s.map(i=>i.task_name?{id:i.task_id,name:i.task_name,slug:i.task_slug,level:0}:void 0)),[s]),o=g.useMemo(()=>de(s.map(i=>i.dataset_name?{id:i.dataset_id,name:i.dataset_name,slug:i.dataset_slug}:void 0)),[s]),u=je({queries:a.filter(i=>!c.has(i)).map(i=>({...Q.task(i),staleTime:1/0})),combine:i=>i.map(f=>f.data)}),x=je({queries:a.map(i=>({...Q.datasetList({task_id:Number(i),page_size:Ze}),select:f=>f.results}))}),p=de(...x.map(i=>i.data??[])),j=je({queries:n.filter(i=>!o.has(i)&&!p.has(i)).map(i=>({...Q.dataset(i),staleTime:1/0})),combine:i=>({data:i.map(f=>f.data),loaded:i.every(f=>f.isSuccess)})}),l=je({queries:d.map(i=>{const[f,_]=i.split(":");return{...Q.leaderboardMetrics(_,f),staleTime:0}})}),h=de([...c.values()],u),v=de([...o.values()],[...p.values()],j.data),w=((b=x.find(i=>i.error))==null?void 0:b.error)??null,m=x.every(i=>i.isSuccess)&&j.loaded;return{task:i=>h.get(i),dataset:i=>v.get(i),supportsHarness:(i,f)=>{var _;return!!(i&&f&&((_=v.get(f))!=null&&_.supports_harness))},metrics:(i,f)=>{const _=l[d.indexOf(`${i}:${f}`)];return{metrics:(_==null?void 0:_.data)??[],loading:(_==null?void 0:_.isFetching)??!1,error:(_==null?void 0:_.error)??null}},datasetListError:w,harnessSupportKnown:m,searchTasks:async i=>{const f=await Ne.listTasks({page_size:Ze,...i?{q:i}:{}});return f.results.forEach(_=>r.setQueryData(Pr(_.id),_)),f.results.map(_=>{var S;return{value:_.id,label:_.name,description:(S=_.description)==null?void 0:S.slice(0,100)}})},searchDatasets:i=>async f=>{const _=await Ne.listDatasets({task_id:Number(i),page_size:Ze,...f?{q:f}:{}});return _.results.forEach(S=>r.setQueryData($r(S.id),S)),_.results.map(S=>({value:S.id,label:S.name,description:S.full_name}))}}}function Rr(t,{toast:s,queryClient:r,paperIds:a,queuedDescription:n}){if(t.status==="approved"){ls(r,a),cs(r),s({title:"Edit applied",description:"Your change is now live on this paper."});return}s({title:"Edit submitted for review",description:n})}function ee({editType:t,paperId:s,arxivId:r,submitMode:a,messages:n,toPendingPayload:d,applyDirect:c,applyOptimistic:o,onSaved:u,onClose:x,removal:p}){const j=Y(),{toast:l}=W(),h=a==="pending",v=ae({mutationFn:async m=>h?{submitted:await us.submit(ms(Number(s),t,d(m)))}:{paper:await c(m)},onMutate:async m=>{if(h||!o)return{};const b=await o(m);return x(),{rollback:b}},onSuccess:(m,b)=>{"submitted"in m?(Rr(m.submitted,{toast:l,queryClient:j,paperIds:[s,r],queuedDescription:`Thanks! An admin will review your proposed ${n.proposal} shortly.`}),u==null||u(b,{direct:!1,live:m.submitted.status==="approved"})):(m.paper&&Aa(j,m.paper,[s,r]),u==null||u(b,{direct:!0,live:!0})),x()},onError:(m,b,i)=>{var f;(f=i==null?void 0:i.rollback)==null||f.call(i),l({title:h?"Could not submit edit":`Could not save ${n.noun}`,description:pt(m,h?"Failed to submit your edit. Please try again.":n.failure),variant:"destructive"})}});return{submit:m=>{!h&&(p!=null&&p.removes(m))&&!window.confirm(p.prompt)||v.mutate(m)},isPending:v.isPending}}const Lr={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"};function Ar(t){return(t??[]).some(s=>s.slug==="coding-agents"||s.name.trim().toLowerCase()==="coding agents")}function Bt(t,s){return{...t,...s,operation:t.operation==="unchanged"?"update":t.operation}}function Tr({onOpenChange:t,paperId:s,arxivId:r,initialEvaluations:a,paperTasks:n,submitMode:d="direct",isAdmin:c=!1,isAuthor:o=!1}){const u=g.useId(),x=Ar(n),[p,j]=g.useState(null),l=g.useMemo(()=>vr(a),[a]),h=p??l,[v,w]=g.useState(!1),m=v?fs(h):[],[b,i]=g.useState(null),f=Ir(h,a),_=Y(),{toast:S}=W(),E=ee({editType:"evaluations",paperId:s,arxivId:r,submitMode:d,messages:{proposal:"evaluation changes",noun:"evaluations",failure:"Failed to update evaluations."},toPendingPayload:k=>({operations:k}),applyDirect:async k=>{if(!c&&k.length>50)throw new Error("Contributor evaluation batches are limited to 50 operations; contact an admin.");const P=Number(s);await mt.batch(P,wr(P,k))},onSaved:(k,{live:P})=>{P&&Ta(_,Da(s,a,k,r))},onClose:()=>t(!1)}),$=(k,P)=>j(h.map((y,I)=>I===k?P(y):y)),C=k=>{if(!h[k].id){j(h.filter((P,y)=>y!==k));return}window.confirm("Delete this evaluation? You will be asked to sign in again if your session is older than 15 minutes.")&&$(k,P=>({...P,operation:"delete"}))},R=(k,P,y)=>{$(k,I=>{if(I[P]===y)return I;const T={[P]:y};return(P==="task_id"||P==="dataset_id")&&Object.assign(T,{original_metrics:{},original_metric_name:"",metric_value:"",best_rank:"",metric_name:""}),P==="task_id"&&Object.assign(T,{dataset_id:"",harness:""}),P==="dataset_id"&&y&&!f.supportsHarness(I.task_id,y)&&(T.harness=""),Bt(I,T)})},L=()=>{w(!0);const k=kr(h,f.supportsHarness);if(k.valid){if(k.operations.length===0){S({title:"No changes to submit",description:"Your evaluation list matches the existing data."});return}E.submit(k.operations)}},B=k=>h.slice(0,k+1).filter(P=>P.operation!=="delete").length;return e.jsxs(e.Fragment,{children:[e.jsxs(Z,{title:"Edit Evaluation Results",description:"Add, edit, or remove evaluation results for this paper. Each row represents a benchmark result.",className:"max-w-6xl max-h-[800px]",submitMode:d,isAuthor:o,onOpenChange:t,onSave:L,isSaving:E.isPending,saveDisabled:!f.harnessSupportKnown,footerStart:e.jsxs("div",{className:"flex flex-wrap gap-2 sm:mr-auto",children:[e.jsx(A,{variant:"ghost",onClick:()=>i("benchmark"),children:"Suggest a new benchmark"}),e.jsx(A,{variant:"ghost",onClick:()=>i("metric"),children:"Suggest a new metric"})]}),children:[m.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:m.map(k=>e.jsxs("li",{children:["Row ",B(k.rowIndex),": ",k.message]},`${k.rowIndex}-${k.field}`))})]}),f.datasetListError&&e.jsxs("p",{className:"text-sm text-destructive",children:["Could not load the benchmarks for these tasks: ",f.datasetListError.message]}),e.jsxs("div",{className:"py-4 overflow-y-auto max-h-[600px]",children:[h.some(k=>k.operation!=="delete")?e.jsx(Sr,{rows:h,catalog:f,draftErrors:m,errorId:u,isAdmin:c,showHarnessColumn:x,onFieldChange:R,onOpenSourceChange:(k,P)=>$(k,y=>Bt(y,{is_open:P})),onDelete:C}):e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(za,{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(A,{variant:"outline",size:"sm",onClick:()=>j([...h,Lr]),className:"flex items-center space-x-2",children:[e.jsx(De,{className:"w-4 h-4"}),e.jsx("span",{children:"Add Row"})]})})]})]}),e.jsx(ds,{open:b!==null,onOpenChange:k=>{k||i(null)},paperId:s,kind:b??"benchmark"})]})}const ve=[{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 zt(t){return t.map(s=>s.trim()).filter(Boolean)}function tt(t,s){const r=zt(t).sort(),a=zt(s).sort();return r.length!==a.length?!1:r.every((n,d)=>n===a[d])}function Dr(t,s){return tt(t.hf_models,s.hf_models)&&tt(t.hf_datasets,s.hf_datasets)&&tt(t.hf_spaces,s.hf_spaces)}function Ur({onOpenChange:t,paperId:s,arxivId:r,initialArtifacts:a,submitMode:n="direct",isAuthor:d=!1}){const[c,o]=g.useState(a),[u,x]=g.useState({hf_models:"",hf_datasets:"",hf_spaces:""}),p=ee({editType:"hf_artifacts",paperId:s,arxivId:r,submitMode:n,messages:{proposal:"Hugging Face artifact changes",noun:"Hugging Face artifacts",failure:"Failed to update Hugging Face artifacts."},toPendingPayload:m=>m,applyDirect:m=>z.updateHfArtifacts(s,m),onClose:()=>t(!1),removal:{removes:m=>ve.some(({key:b})=>a[b].some(i=>!m[b].includes(i))),prompt:"Remove one or more Hugging Face artifact links?"}}),j=()=>{const m={hf_models:[...c.hf_models],hf_datasets:[...c.hf_datasets],hf_spaces:[...c.hf_spaces]};for(const{key:b}of ve){const i=u[b].trim();if(i){if(m[b].some(f=>f.trim()===i))return alert(`This ${b.replace("hf_","")} URL is already added`),null;m[b]=[...m[b],i]}}return m},l=m=>{const b=u[m].trim();if(b){if(c[m].some(i=>i.trim()===b)){alert(`This ${m.replace("hf_","")} URL is already added`);return}o(i=>({...i,[m]:[...i[m],b]})),x(i=>({...i,[m]:""}))}},h=(m,b)=>{o(i=>({...i,[m]:i[m].filter(f=>f!==b)}))},v=()=>{const m=j();m!==null&&p.submit(m)},w=g.useMemo(()=>{const m={hf_models:[...c.hf_models],hf_datasets:[...c.hf_datasets],hf_spaces:[...c.hf_spaces]};for(const{key:b}of ve){const i=u[b].trim();if(i){if(m[b].some(f=>f.trim()===i))return!1;m[b]=[...m[b],i]}}return!Dr(m,a)},[c,u,a]);return e.jsx(Z,{title:"Edit Hugging Face Artifacts",description:"Add or remove linked Hugging Face models, datasets, and Spaces for this paper.",className:"max-w-2xl max-h-[700px]",submitMode:n,isAuthor:d,onOpenChange:t,onSave:v,isSaving:p.isPending,saveDisabled:!w,children:e.jsx("div",{className:"space-y-6 py-2 overflow-y-auto max-h-[460px]",children:ve.map(({key:m,label:b,placeholder:i})=>e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:b}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(M,{type:"url",placeholder:i,value:u[m],onChange:f=>x(_=>({..._,[m]:f.target.value})),onKeyPress:f=>{f.key==="Enter"&&(f.preventDefault(),l(m))},className:"flex-1"}),e.jsxs(A,{onClick:()=>l(m),size:"sm",disabled:!u[m].trim(),children:[e.jsx(De,{className:"w-4 h-4 mr-1"}),"Add"]})]}),c[m].length>0?e.jsx("div",{className:"space-y-2",children:c[m].map(f=>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:f}),e.jsx(A,{variant:"ghost",size:"sm",onClick:()=>h(m,f),className:"h-8 px-2 text-destructive hover:text-destructive",title:`Remove ${b.toLowerCase()} URL`,children:e.jsx(Te,{className:"w-4 h-4"})})]},f))}):e.jsxs("div",{className:"text-xs text-muted-foreground",children:["No ",b.toLowerCase()," linked yet."]})]},m))})})}const gs=["image/jpeg","image/png","image/webp","image/gif"],Fr=2*1024*1024;function Mr(t){return gs.includes(t.type)?t.size>Fr?Promise.reject(new Error("Logo must be 2 MB or smaller.")):new Promise((s,r)=>{const a=new FileReader;a.onload=()=>s({file_name:t.name,mime_type:t.type,data_url:String(a.result)}),a.onerror=()=>r(new Error("Could not read that logo.")),a.readAsDataURL(t)}):Promise.reject(new Error("Choose a JPEG, PNG, WebP, or GIF logo."))}function Br({paperId:t,initialName:s,onApplied:r,onUnsentChange:a}){const[n,d]=g.useState(s),[c,o]=g.useState(""),[u,x]=g.useState(""),[p,j]=g.useState(null),[l,h]=g.useState(""),v=ae({mutationFn:()=>us.submit(ms(Number(t),"new_organization",{name:n.trim(),...c.trim()?{hf_slug:c.trim()}:{},...u.trim()?{website_url:u.trim()}:{},...p?{image:p}:{}})),onSuccess:m=>{m.status==="approved"&&r(n.trim())}}),w=!v.isSuccess&&!!(c.trim()||u.trim()||p);return g.useEffect(()=>a(w),[a,w]),g.useEffect(()=>()=>a(!1),[a]),v.isSuccess?e.jsxs("p",{className:"rounded border p-3 text-sm",children:['Thanks! "',n.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:m=>{m.preventDefault(),v.mutate()},children:[e.jsx("p",{className:"text-sm font-medium",children:"Suggest a new organization"}),e.jsx(M,{"aria-label":"Organization name",placeholder:"Name",value:n,maxLength:200,onChange:m=>d(m.target.value)}),e.jsx(M,{"aria-label":"Hugging Face organization",placeholder:"Hugging Face organization (e.g. https://huggingface.co/PrimeIntellect)",value:c,onChange:m=>o(m.target.value)}),e.jsx(M,{"aria-label":"Website",type:"url",placeholder:"Website (e.g. https://www.primeintellect.ai)",value:u,onChange:m=>x(m.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:m=>{var i;const b=(i=m.target.files)==null?void 0:i[0];j(null),h(""),b&&Mr(b).then(j,f=>h(f.message))}})]}),p&&e.jsx("img",{src:p.data_url,alt:"Selected logo",className:"h-12 w-12 rounded border object-contain"}),l&&e.jsx("p",{className:"text-sm text-destructive",children:l}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"With a Hugging Face organization it is added right away; otherwise an admin reviews it."}),e.jsx(A,{type:"submit",variant:"outline",disabled:!n.trim()||!c.trim()&&!u.trim()||v.isPending,children:v.isPending?"Submitting...":"Submit organization"})]}),v.error&&e.jsx("p",{className:"text-sm text-destructive",children:pt(v.error,"Could not submit this organization.")})]})}const zr=({onOpenChange:t,paperId:s,arxivId:r,initialOrganizationIds:a,submitMode:n="direct",isAuthor:d})=>{var b;const[c,o]=g.useState(a),[u,x]=g.useState(""),[p,j]=g.useState(!1),l=Y(),{toast:h}=W(),v=X({...Q.organizations(),staleTime:0}),w=g.useMemo(()=>{var _,S;const i=u.trim().toLocaleLowerCase();if(!i)return((_=v.data)==null?void 0:_.results)??[];const f=E=>E===i?0:E.startsWith(i)?1:E.split(/[^\p{L}\p{N}]+/u).some($=>$.startsWith(i))?2:3;return(((S=v.data)==null?void 0:S.results)??[]).map(E=>({organization:E,name:E.name.toLocaleLowerCase()})).filter(({name:E})=>E.includes(i)).sort((E,$)=>f(E.name)-f($.name)).map(({organization:E})=>E)},[(b=v.data)==null?void 0:b.results,u]),m=ee({editType:"organizations",paperId:s,arxivId:r,submitMode:n,messages:{proposal:"organization changes",noun:"organizations",failure:"Failed to update organizations."},toPendingPayload:i=>({organization_ids:i}),applyDirect:i=>z.updateOrganizations(s,i),onClose:()=>t(!1),removal:{removes:i=>a.some(f=>!i.includes(f)),prompt:"Remove one or more organizations from this paper? Destructive edits may require a fresh sign-in."}});return e.jsxs(Z,{title:"Edit organizations",description:"Associate organizations with this paper. If one is missing, search for it and suggest it for review.",submitMode:n,isAuthor:d,onOpenChange:t,onSave:()=>m.submit(c),isSaving:m.isPending,saveDisabled:p,children:[e.jsxs("div",{className:"relative",children:[e.jsx(it,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(M,{type:"search","aria-label":"Search organizations",placeholder:"Search organizations...",value:u,onChange:i=>x(i.target.value),className:"pl-9 pr-9"}),u&&e.jsx("button",{type:"button",onClick:()=>x(""),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(Zt,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"max-h-80 space-y-2 overflow-auto",children:[w.map(i=>{const f=Number(i.id);return e.jsxs("label",{className:"flex items-center gap-2 rounded border p-2",children:[e.jsx("input",{type:"checkbox",checked:c.includes(f),onChange:_=>o(S=>_.target.checked?[...S,f]:S.filter(E=>E!==f))}),i.name]},i.id)}),!v.isLoading&&w.length===0&&e.jsx("p",{className:"py-8 text-center text-sm text-muted-foreground",children:u.trim()?`No organizations found matching "${u.trim()}"`:"No organizations available"})]}),!v.isLoading&&w.length===0&&u.trim()&&e.jsx(Br,{paperId:s,initialName:u.trim(),onApplied:i=>{t(!1),h({title:"Organization added",description:`Added "${i}" to this paper.`}),ls(l,[s]),cs(l),l.invalidateQueries({queryKey:Js.organizations})},onUnsentChange:j},u.trim()),p&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Submit the organization above, or clear the search, before saving."})]})};function Hr({onOpenChange:t,paperId:s,arxivId:r,initialUrl:a,submitMode:n="direct",isAuthor:d=!1}){const[c,o]=g.useState(a),u=ee({editType:"source_url",paperId:s,arxivId:r,submitMode:n,messages:{proposal:"source URL change",noun:"source URL",failure:"Failed to update source URL."},toPendingPayload:h=>({source_url:h}),applyDirect:h=>z.updateSourceUrl(s,h),onClose:()=>t(!1)}),x=c.trim(),p=/^https?:\/\//i.test(x),j=x!==(a||"").trim(),l=()=>{p&&u.submit(x)};return e.jsx(Z,{title:"Edit Source URL",description:'Update the canonical URL for this external paper. This is the page the "Source page" button links to. ArXiv papers cannot edit this field.',className:"max-w-2xl",submitMode:n,isAuthor:d,onOpenChange:t,onSave:l,isSaving:u.isPending,saveDisabled:!p||!j,children:e.jsxs("div",{className:"space-y-2 py-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Source URL"}),e.jsx(M,{type:"url",placeholder:"https://example.com/paper",value:c,onChange:h=>o(h.target.value),onKeyPress:h=>{h.key==="Enter"&&p&&j&&(h.preventDefault(),l())}}),!p&&x.length>0&&e.jsx("p",{className:"text-xs text-destructive",children:"URL must start with http:// or https://"})]})})}const Or={repositories:{canonical:t=>Fa(t)??t.trim(),toPayload:t=>({repositories:t}),update:(t,s)=>z.updateRepositories(t,s),icon:qa,title:"Edit Paper Repositories",description:"Add or remove GitHub repository URLs associated with this paper. Mark repositories as official if they are created by the paper authors.",addLabel:"Add Repository URL",placeholder:"https://github.com/owner/repo",singular:"repository",plural:"repositories",failure:"Failed to update paper repositories."},project_pages:{canonical:t=>t.trim(),toPayload:t=>({project_pages:t}),update:(t,s)=>z.updateProjectPages(t,s),icon:Oa,title:"Edit Paper Project Pages",description:"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.",addLabel:"Add Project Page URL",placeholder:"https://example.com/project",singular:"project page",plural:"project pages",failure:"Failed to update project pages."}};function Ht({kind:t,onOpenChange:s,paperId:r,arxivId:a,initialItems:n,submitMode:d="direct",isAuthor:c=!1}){const o=Or[t],u=o.icon,[x,p]=g.useState(n),[j,l]=g.useState(""),h=C=>{const R=new Map;for(const{url:L,is_official:B}of C){const k=o.canonical(L),P=R.get(k);R.set(k,{url:k,is_official:!!(P!=null&&P.is_official||B)})}return[...R.values()]},v=C=>new Set(C.map(({url:R})=>o.canonical(R))),w=ee({editType:t,paperId:r,arxivId:a,submitMode:d,messages:{proposal:`${o.singular} changes`,noun:o.plural,failure:o.failure},toPendingPayload:o.toPayload,applyDirect:C=>o.update(r,C),onClose:()=>s(!1),removal:{removes:C=>{const R=v(C);return n.some(({url:L})=>!R.has(o.canonical(L)))},prompt:`Remove one or more ${o.plural} from this paper?`}}),m=j.trim(),b=m?[...x,{url:m,is_official:!1}]:x,i=()=>m&&v(x).has(o.canonical(m))?(alert(`This ${o.singular} URL is already added`),null):h(b),f=()=>{const C=i();C===null||C.length===x.length||(p(C),l(""))},_=()=>{const C=i();C!==null&&w.submit(C)},S=new Map(h(n).map(({url:C,is_official:R})=>[C,R])),E=h(b),$=b.length!==n.length||E.length!==S.size||E.some(({url:C,is_official:R})=>S.get(C)!==R);return e.jsxs(Z,{title:o.title,description:o.description,className:"max-w-2xl max-h-[600px]",submitMode:d,isAuthor:c,onOpenChange:s,onSave:_,isSaving:w.isPending,saveDisabled:!$,children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:o.addLabel}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(M,{type:"url",placeholder:o.placeholder,value:j,onChange:C=>l(C.target.value),onKeyDown:C=>{C.key==="Enter"&&(C.preventDefault(),f())},className:"flex-1"}),e.jsxs(A,{onClick:f,size:"sm",disabled:!m,children:[e.jsx(De,{className:"w-4 h-4 mr-1"}),"Add"]})]})]}),e.jsx("div",{className:"py-4 overflow-y-auto max-h-[350px]",children:x.length>0?e.jsx("div",{className:"space-y-2",children:x.map((C,R)=>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(u,{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:C.url}),C.is_official&&e.jsx(Ha,{variant:"secondary",className:"text-xs",children:"Official"})]})}),e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsxs(A,{variant:C.is_official?"default":"outline",size:"sm",onClick:()=>p(x.map(L=>L.url===C.url?{...L,is_official:!L.is_official}:L)),className:"h-8 px-2 text-xs",title:C.is_official?"Click to unmark as official (created by paper authors)":"Click to mark as official (created by paper authors)",children:[e.jsx(sr,{className:`w-3.5 h-3.5 mr-1 ${C.is_official?"fill-current":""}`}),C.is_official?"Official":"Mark official"]}),e.jsx(A,{variant:"ghost",size:"sm",onClick:()=>p(x.filter(L=>L.url!==C.url)),className:"h-8 px-2 text-destructive hover:text-destructive",title:`Remove ${o.singular}`,children:e.jsx(Te,{className:"w-4 h-4"})})]})]},R))}):e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(u,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),e.jsxs("p",{className:"text-sm",children:["No ",o.plural," added yet"]}),e.jsxs("p",{className:"text-xs mt-1",children:["Add a ",o.singular," URL above to get started"]})]})})]})}var Ue="Checkbox",[qr]=ft(Ue),[Gr,bt]=qr(Ue);function Xr(t){const{__scopeCheckbox:s,checked:r,children:a,defaultChecked:n,disabled:d,form:c,name:o,onCheckedChange:u,required:x,value:p="on",internal_do_not_use_render:j}=t,[l,h]=ts({prop:r,defaultProp:n??!1,onChange:u,caller:Ue}),[v,w]=g.useState(null),[m,b]=g.useState(null),i=g.useRef(!1),f=v?!!c||!!v.closest("form"):!0,_={checked:l,disabled:d,setChecked:h,control:v,setControl:w,name:o,form:c,value:p,hasConsumerStoppedPropagationRef:i,required:x,defaultChecked:K(n)?!1:n,isFormControl:f,bubbleInput:m,setBubbleInput:b};return e.jsx(Gr,{scope:s,..._,children:Kr(j)?j(_):a})}var xs="CheckboxTrigger",bs=g.forwardRef(({__scopeCheckbox:t,onKeyDown:s,onClick:r,...a},n)=>{const{control:d,value:c,disabled:o,checked:u,required:x,setControl:p,setChecked:j,hasConsumerStoppedPropagationRef:l,isFormControl:h,bubbleInput:v}=bt(xs,t),w=ge(n,p),m=g.useRef(u);return g.useEffect(()=>{const b=d==null?void 0:d.form;if(b){const i=()=>j(m.current);return b.addEventListener("reset",i),()=>b.removeEventListener("reset",i)}},[d,j]),e.jsx(J.button,{type:"button",role:"checkbox","aria-checked":K(u)?"mixed":u,"aria-required":x,"data-state":ks(u),"data-disabled":o?"":void 0,disabled:o,value:c,...a,ref:w,onKeyDown:fe(s,b=>{b.key==="Enter"&&b.preventDefault()}),onClick:fe(r,b=>{j(i=>K(i)?!0:!i),v&&h&&(l.current=b.isPropagationStopped(),l.current||b.stopPropagation())})})});bs.displayName=xs;var jt=g.forwardRef((t,s)=>{const{__scopeCheckbox:r,name:a,checked:n,defaultChecked:d,required:c,disabled:o,value:u,onCheckedChange:x,form:p,...j}=t;return e.jsx(Xr,{__scopeCheckbox:r,checked:n,defaultChecked:d,disabled:o,required:c,onCheckedChange:x,name:a,form:p,value:u,internal_do_not_use_render:({isFormControl:l})=>e.jsxs(e.Fragment,{children:[e.jsx(bs,{...j,ref:s,__scopeCheckbox:r}),l&&e.jsx(ys,{__scopeCheckbox:r})]})})});jt.displayName=Ue;var js="CheckboxIndicator",vs=g.forwardRef((t,s)=>{const{__scopeCheckbox:r,forceMount:a,...n}=t,d=bt(js,r);return e.jsx(es,{present:a||K(d.checked)||d.checked===!0,children:e.jsx(J.span,{"data-state":ks(d.checked),"data-disabled":d.disabled?"":void 0,...n,ref:s,style:{pointerEvents:"none",...t.style}})})});vs.displayName=js;var _s="CheckboxBubbleInput",ys=g.forwardRef(({__scopeCheckbox:t,...s},r)=>{const{control:a,hasConsumerStoppedPropagationRef:n,checked:d,defaultChecked:c,required:o,disabled:u,name:x,value:p,form:j,bubbleInput:l,setBubbleInput:h}=bt(_s,t),v=ge(r,h),w=hs(d),m=ss(a);g.useEffect(()=>{const i=l;if(!i)return;const f=window.HTMLInputElement.prototype,S=Object.getOwnPropertyDescriptor(f,"checked").set,E=!n.current;if(w!==d&&S){const $=new Event("click",{bubbles:E});i.indeterminate=K(d),S.call(i,K(d)?!1:d),i.dispatchEvent($)}},[l,w,d,n]);const b=g.useRef(K(d)?!1:d);return e.jsx(J.input,{type:"checkbox","aria-hidden":!0,defaultChecked:c??b.current,required:o,disabled:u,name:x,value:p,form:j,...s,tabIndex:-1,ref:v,style:{...s.style,...m,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});ys.displayName=_s;function Kr(t){return typeof t=="function"}function K(t){return t==="indeterminate"}function ks(t){return K(t)?"indeterminate":t?"checked":"unchecked"}const vt=g.forwardRef(({className:t,style:s,...r},a)=>e.jsx(jt,{ref:a,className:we("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},...r,children:e.jsx(vs,{className:we("flex items-center justify-center text-current"),children:e.jsx(ht,{className:"h-4 w-4"})})}));vt.displayName=jt.displayName;const Qr=250,Vr=100,Wr={editType:"tasks",singular:"task",plural:"tasks",title:"Edit Paper Tasks",description:"Select the tasks that this paper addresses. You can select multiple tasks.",search:t=>Ne.listTasks(t),toPendingPayload:t=>({task_ids:t}),applyDirect:(t,s)=>z.updateTasks(t,s),patchPaper:(t,s)=>({...t,tasks:[...s].sort((r,a)=>r.name.localeCompare(a.name))})},Yr={editType:"methods",singular:"method",plural:"methods",title:"Edit Paper Methods",description:"Select the methods and techniques used in this paper. You can select multiple methods.",search:t=>Ne.listMethods(t),toPendingPayload:t=>({method_ids:t}),applyDirect:(t,s)=>z.updateMethods(t,s),subtitle:t=>t.full_name!==t.name?t.full_name:void 0},Jr=t=>t[0].toUpperCase()+t.slice(1),te=t=>t.map(s=>Number(s.id));function Ot(t){return t.kind==="task"?e.jsx(qt,{...t,tagKind:Wr}):e.jsx(qt,{...t,tagKind:Yr})}function qt({tagKind:t,onOpenChange:s,paperId:r,arxivId:a,initialItems:n,submitMode:d="direct",isAuthor:c=!1}){const{singular:o,plural:u,patchPaper:x}=t,[p,j]=g.useState(n),[l,h]=g.useState(!1),[v,w]=g.useState(""),[m,b]=g.useState(""),i=Y(),{toast:f}=W();g.useEffect(()=>{const k=window.setTimeout(()=>{b(v.trim())},Qr);return()=>window.clearTimeout(k)},[v]);const{data:_,isFetching:S}=X({queryKey:[`${u}-search`,m],queryFn:()=>t.search({page_size:Vr,...m?{q:m}:{}})}),E=ee({editType:t.editType,paperId:r,arxivId:a,submitMode:d,messages:{proposal:`${o} changes`,noun:u,failure:`Failed to update paper ${u}.`},toPendingPayload:k=>t.toPendingPayload(te(k)),applyDirect:k=>t.applyDirect(r,te(k)),applyOptimistic:x&&(k=>Ua(i,[r,a],P=>x(P,k))),onSaved:(k,{direct:P})=>{P&&f({title:`${Jr(u)} updated`,description:`Saved ${k.length} ${k.length===1?o:u} for this paper.`})},onClose:()=>s(!1),removal:{removes:k=>{const P=new Set(te(k));return te(n).some(y=>!P.has(y))},prompt:`Remove one or more ${o} links from this paper?`}}),$=g.useMemo(()=>new Set(te(p)),[p]),C=g.useMemo(()=>te(n),[n]),R=g.useMemo(()=>{const k=(_==null?void 0:_.results)??[],P=m?[...k,...p]:[...p,...k];return P.filter((y,I)=>P.findIndex(({id:T})=>T===y.id)===I)},[_,p,m]),L=p.length!==C.length||C.some(k=>!$.has(k)),B=(k,P)=>{j(y=>P?y.some(I=>I.id===k.id)?y:[...y,k]:y.filter(I=>I.id!==k.id))};return e.jsxs(e.Fragment,{children:[e.jsxs(Z,{title:t.title,description:t.description,className:"max-w-2xl max-h-[600px]",submitMode:d,isAuthor:c,onOpenChange:s,onSave:()=>E.submit(p),isSaving:E.isPending,saveDisabled:!L,footerStart:e.jsxs(A,{variant:"ghost",className:"sm:mr-auto",onClick:()=>h(!0),children:["Suggest a new ",o]}),children:[e.jsxs("div",{className:"relative mb-4",children:[e.jsx(it,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(M,{type:"text",placeholder:`Search ${u}...`,value:v,onChange:k=>w(k.target.value),className:"pl-9 pr-9"}),v&&e.jsx("button",{type:"button",onClick:()=>w(""),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(Zt,{className:"w-4 h-4"})})]}),e.jsx("div",{className:"py-4 overflow-y-auto max-h-[400px]",children:R.length>0?e.jsx("div",{className:"space-y-2",children:R.map(k=>{var y;const P=(y=t.subtitle)==null?void 0:y.call(t,k);return e.jsxs("div",{className:"flex items-center space-x-2 p-2 hover:bg-muted/50 rounded-md",children:[e.jsx(vt,{id:`${o}-${k.id}`,checked:$.has(Number(k.id)),onCheckedChange:I=>B(k,I===!0),className:"!border !border-black data-[state=checked]:!bg-black data-[state=checked]:!text-white"}),e.jsxs("label",{htmlFor:`${o}-${k.id}`,className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 cursor-pointer flex-1",children:[k.name,P&&e.jsx("span",{className:"block text-xs text-muted-foreground font-normal",children:P}),k.description&&e.jsxs("span",{className:"block text-xs text-muted-foreground font-normal mt-1",children:[k.description.substring(0,100),k.description.length>100?"...":""]})]})]},k.id)})}):S?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(xt,{className:"w-8 h-8 mx-auto mb-2 animate-spin"}),e.jsxs("p",{children:["Loading ",u,"..."]})]}):e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(it,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:m?`No ${u} found matching "${m}"`:`No ${u} available`})]})})]}),e.jsx(ds,{open:l,onOpenChange:h,paperId:r,kind:o})]})}const Gt=10,Zr=/^https?:\/\/(?:www\.|mobile\.)?(?:x|twitter)\.com\/(?:[A-Za-z0-9_]{1,15}|i\/web|i)\/status(?:es)?\/(\d{1,25})(?:[/?#].*)?$/;function se(t){var s;return((s=Zr.exec(t.trim()))==null?void 0:s[1])??null}function en({onOpenChange:t,paperId:s,arxivId:r,initialUrls:a,submitMode:n="direct",isAuthor:d=!1}){const[c,o]=g.useState(a),[u,x]=g.useState(""),[p,j]=g.useState(null),l=ee({editType:"x_threads",paperId:s,arxivId:r,submitMode:n,messages:{proposal:"X threads",noun:"X threads",failure:"Failed to update X threads."},toPendingPayload:i=>({x_threads:i}),applyDirect:i=>z.updateXThreads(s,i),onClose:()=>t(!1),removal:{removes:i=>a.some(f=>!i.some(_=>se(_)===se(f))),prompt:"Remove one or more X threads from this paper?"}}),h=()=>{const i=u.trim();if(!i)return c;const f=se(i);return f?c.some(_=>se(_)===f)?(j("This post is already listed."),null):c.length>=Gt?(j(`A paper can link at most ${Gt} X threads.`),null):[...c,i]:(j("Paste a post URL such as https://x.com/user/status/123…"),null)},v=()=>{const i=h();i!==null&&(o(i),x(""),j(null))},w=(i,f)=>{const _=[...c];[_[i],_[i+f]]=[_[i+f],_[i]],o(_)},m=()=>{const i=h();i!==null&&l.submit(i)},b=g.useMemo(()=>(u.trim()?[...c,u.trim()]:c).map(se).join()!==a.map(se).join(),[c,u,a]);return e.jsxs(Z,{title:"Edit X threads",description:"Link posts on X (formerly Twitter) in which the authors introduce this paper. A preview of each post is shown on the paper page.",className:"max-w-2xl max-h-[600px]",submitMode:n,isAuthor:d,onOpenChange:t,onSave:m,isSaving:l.isPending,saveDisabled:!b,children:[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(M,{id:"x-thread-url",type:"url",placeholder:"https://x.com/user/status/1234567890",value:u,onChange:i=>{x(i.target.value),j(null)},onKeyDown:i=>{i.key==="Enter"&&(i.preventDefault(),v())},"aria-invalid":!!p,className:"flex-1"}),e.jsxs(A,{onClick:v,size:"sm",disabled:!u.trim(),children:[e.jsx(De,{className:"w-4 h-4 mr-1"}),"Add"]})]}),p&&e.jsx("p",{className:"text-xs text-destructive",children:p})]}),e.jsx("div",{className:"py-4 overflow-y-auto max-h-[350px]",children:c.length>0?e.jsx("div",{className:"space-y-2",children:c.map((i,f)=>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:i}),e.jsx(A,{variant:"ghost",size:"sm",className:"h-8 px-2",disabled:f===0,onClick:()=>w(f,-1),"aria-label":"Move up",children:e.jsx(er,{className:"w-4 h-4"})}),e.jsx(A,{variant:"ghost",size:"sm",className:"h-8 px-2",disabled:f===c.length-1,onClick:()=>w(f,1),"aria-label":"Move down",children:e.jsx(Za,{className:"w-4 h-4"})}),e.jsx(A,{variant:"ghost",size:"sm",className:"h-8 px-2 text-destructive hover:text-destructive",onClick:()=>o(c.filter(_=>_!==i)),"aria-label":"Remove X thread",children:e.jsx(Te,{className:"w-4 h-4"})})]},i))}):e.jsx("p",{className:"text-center py-8 text-sm text-muted-foreground",children:"No X threads linked yet"})})]})}function tn({activeEditor:t,arxivId:s,editSubmitMode:r,evaluations:a,isAdmin:n,isLinkedAuthor:d,onOpenChange:c,paper:o}){if(!t)return null;const u={paperId:o.id,arxivId:s,submitMode:r,isAuthor:d,onOpenChange:j=>c(t,j)},x=j=>(j==null?void 0:j.map(({url:l,is_official:h})=>({url:l,is_official:!!h})))??[],p={tasks:()=>e.jsx(Ot,{...u,kind:"task",initialItems:o.tasks??[]}),methods:()=>e.jsx(Ot,{...u,kind:"method",initialItems:o.methods??[]}),repositories:()=>e.jsx(Ht,{...u,kind:"repositories",initialItems:x(o.repositories)}),project_pages:()=>e.jsx(Ht,{...u,kind:"project_pages",initialItems:x(o.project_pages)}),evaluations:()=>e.jsx(Tr,{...u,initialEvaluations:a,paperTasks:o.tasks??[],isAdmin:n}),source_url:()=>e.jsx(Hr,{...u,initialUrl:o.source_url??o.url_abs??""}),hf_artifacts:()=>e.jsx(Ur,{...u,initialArtifacts:{hf_models:o.hf_models??[],hf_datasets:o.hf_datasets??[],hf_spaces:o.hf_spaces??[]}}),x_threads:()=>{var j;return e.jsx(en,{...u,initialUrls:((j=o.x_threads)==null?void 0:j.map(({url:l})=>l))??[]})},organizations:()=>e.jsx(zr,{...u,initialOrganizationIds:(o.organizations??[]).map(({id:j})=>Number(j))})};return e.jsx(g.Fragment,{children:p[t]()},t)}const sn={"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"},"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"}},Xt=new Set(["queued","dispatching","running","awaiting_markdown"]);function an({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(Ka,{remarkPlugins:[Qa],components:{a:({children:s,...r})=>e.jsx("a",{...r,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 Ns({kind:t,paperId:s,paperTitle:r,triggerClassName:a,onComplete:n}){var E;const d=sn[t],c=Y(),[o,u]=g.useState(!1),[x,p]=g.useState(null),j=g.useRef(null),l=X({...It.codexPaperJob(t,x),refetchInterval:$=>{var R;const C=(R=$.state.data)==null?void 0:R.status;return C==="awaiting_markdown"?6e4:C&&Xt.has(C)?2e3:!1},retry:!1}),h=$=>{c.setQueryData(It.codexPaperJob(t,$.id).queryKey,$),p($.id)},v=ae({mutationFn:()=>Rt.startPaperJob(t,s),onSuccess:h}),w=ae({mutationFn:$=>Rt.cancelPaperJob(t,$),onSuccess:h}),m=x?l.data:void 0,b=(m==null?void 0:m.status)==="awaiting_markdown",i=m?Xt.has(m.status):!1,f=l.errorUpdatedAt>l.dataUpdatedAt?l.error:null,_=(E=v.error??w.error??f)==null?void 0:E.message;g.useEffect(()=>{(m==null?void 0:m.status)!=="completed"||j.current===m.id||(j.current=m.id,n())},[m,n]);const S=()=>{p(null),v.reset(),w.reset(),j.current=null};return e.jsxs($e,{open:o,onOpenChange:u,children:[e.jsx("button",{type:"button",className:a,onClick:()=>u(!0),children:b?"waiting for Markdown…":i?d.running:(m==null?void 0:m.status)==="completed"?d.complete:d.trigger}),e.jsxs(Ie,{className:"max-h-[90vh] w-[calc(100vw-2rem)] min-w-0 max-w-2xl overflow-hidden",children:[e.jsxs(Re,{className:"min-w-0",children:[e.jsx(Le,{children:d.title}),e.jsx(Ae,{children:d.description(r)})]}),m?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: ",m.status.replace("_"," ")]}),m.hf_job_url&&e.jsx("a",{className:"text-sm underline",href:m.hf_job_url,target:"_blank",rel:"noreferrer",children:"View Hugging Face Job"}),b&&e.jsxs("div",{className:"rounded-md border bg-muted/40 p-3 text-sm",children:[Zs," You can close this window and return."]}),i&&!b&&e.jsxs("div",{className:"rounded-md border bg-muted/40 p-3 text-sm",children:[m.status==="queued"?"This job is queued and will start after the current Codex job finishes.":d.progress," ","This can take several minutes; you can close this window and return."]}),m.report&&e.jsx(an,{report:m.report}),m.error&&!b&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive",children:m.error})]}):e.jsx("div",{className:"rounded-md border bg-muted/40 p-3 text-sm text-muted-foreground",children:d.notice}),_&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive",children:_}),e.jsxs(gt,{children:[e.jsx(A,{variant:"outline",onClick:()=>u(!1),children:i?"Close":"Cancel"}),i&&m&&e.jsx(A,{variant:"outline",onClick:()=>w.mutate(m.id),children:"Cancel job"}),!m&&e.jsx(A,{onClick:()=>v.mutate(),disabled:v.isPending,children:v.isPending?"Starting…":d.action}),m&&!i&&e.jsx(A,{variant:"outline",onClick:S,children:"Run again"})]})]})]})}function ke({accent:t,id:s,label:r}){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:r})}),t]})}const rn="/settings#closed-source-evals";function nn({count:t,everyResultHidden:s,onShow:r}){const a=t===1?"result":"results";return e.jsxs("div",{className:"hidden-evals-notice",role:"note",children:[e.jsx(tr,{className:"hidden-evals-notice-icon","aria-hidden":"true"}),e.jsxs("div",{className:"hidden-evals-notice-body",children:[e.jsx("p",{className:"hidden-evals-notice-title",children:s?`No evals shown for this paper: all ${t} ${a} are from closed-source models.`:`${t} closed-source ${a} hidden.`}),e.jsxs("p",{className:"hidden-evals-notice-desc",children:["You turned on ",e.jsx("strong",{children:"Hide closed-source models"})," in your settings. Turn it off to see closed-source results here and on every leaderboard."]}),e.jsxs("div",{className:"hidden-evals-notice-actions",children:[e.jsx("button",{type:"button",className:"hidden-evals-notice-show",onClick:r,children:"Show closed-source results"}),e.jsx(O,{to:rn,className:"hidden-evals-notice-link",children:"Change in Settings →"})]})]})]})}function on({canCopyBadge:t,canEdit:s,evaluationsByTask:r,evaluationsLoading:a,hiddenClosedSourceCount:n,isAdmin:d,onCopyBadge:c,onEdit:o,onRefresh:u,onShowClosedSourceEvals:x,paper:p,visibleEvaluationCount:j}){return e.jsxs(e.Fragment,{children:[e.jsx(ke,{id:"results",label:"Results",accent:e.jsxs("span",{className:"accent",children:[j," 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(U,{name:"copy",size:10})," Copy PwC badge"]}),d&&ea()&&e.jsx(Ns,{kind:"add-evals",triggerClassName:"edit-link",paperId:Number(p.id),paperTitle:p.title,onComplete:u}),s&&e.jsx("button",{type:"button",onClick:o,className:"edit-link",children:"edit"})]})}),!a&&n>0&&e.jsx(nn,{count:n,everyResultHidden:r.length===0,onShow:x}),a?e.jsx(pe,{className:"h-32 w-full"}):r.length>0?r.map(l=>e.jsxs("div",{className:l.taskSlug?"paper-section-anchor":void 0,id:l.taskSlug?ps(l.taskSlug):void 0,children:[e.jsxs("div",{className:"section-rule",children:[e.jsx("span",{children:l.taskSlug?e.jsxs(e.Fragment,{children:[e.jsx(O,{to:`/tasks/${l.taskSlug}`,children:l.taskName}),e.jsx("a",{href:fr(l.taskSlug),className:"section-anchor-link results-task-permalink","aria-label":`Permalink to ${l.taskName} results on this paper`,title:"Link to this task's results",children:"#"})]}):l.taskName}),e.jsxs("span",{className:"accent",children:[l.rows.length," ",l.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:l.rows.map(h=>{var v;return e.jsxs("tr",{children:[e.jsx("td",{className:"benchmark",children:h.dataset_slug?e.jsx(O,{to:`/benchmark/${h.dataset_slug}`,children:h.dataset_name||"—"}):h.dataset_name||"—"}),e.jsxs("td",{className:"model",title:h.model_name||void 0,children:[h.hf_model_url?e.jsx("a",{href:h.hf_model_url,target:"_blank",rel:"noopener noreferrer",className:"model-hf-link",title:`Open ${h.model_name||"model"} on Hugging Face`,children:h.model_name||"—"}):h.model_name||"—",h.is_open===!1&&e.jsx(Ga,{}),(h.external??h.is_external)&&e.jsx(Xa,{sourceUrl:h.source_url||h.external_source_url||h.result_url})]}),e.jsx("td",{className:"metric",children:h.best_metric}),e.jsx("td",{className:"value",children:ta((v=h.metrics)==null?void 0:v[h.best_metric||""])}),e.jsx("td",{className:"rank",children:h.best_rank!=null?`#${h.best_rank}`:"—"}),e.jsx("td",{className:"compare",children:h.dataset_slug&&e.jsx(O,{to:`/benchmark/${h.dataset_slug}?${[h.task_slug?`task=${encodeURIComponent(h.task_slug)}`:"",`eval=${encodeURIComponent(h.id)}`].filter(Boolean).join("&")}`,children:"Compare →"})})]},h.id)})})]})]},l.taskId)):n>0?null:e.jsx("p",{style:{fontFamily:"var(--mono)",fontSize:12,color:"var(--ink-faint)"},children:"No benchmark results recorded yet."})]})}var _t="Radio",[ln,ws]=ft(_t),[cn,dn]=ln(_t),Cs=g.forwardRef((t,s)=>{const{__scopeRadio:r,name:a,checked:n=!1,required:d,disabled:c,value:o="on",onCheck:u,form:x,...p}=t,[j,l]=g.useState(null),h=ge(s,m=>l(m)),v=g.useRef(!1),w=j?x||!!j.closest("form"):!0;return e.jsxs(cn,{scope:r,checked:n,disabled:c,children:[e.jsx(J.button,{type:"button",role:"radio","aria-checked":n,"data-state":$s(n),"data-disabled":c?"":void 0,disabled:c,value:o,...p,ref:h,onClick:fe(t.onClick,m=>{n||u==null||u(),w&&(v.current=m.isPropagationStopped(),v.current||m.stopPropagation())})}),w&&e.jsx(Ps,{control:j,bubbles:!v.current,name:a,value:o,checked:n,required:d,disabled:c,form:x,style:{transform:"translateX(-100%)"}})]})});Cs.displayName=_t;var Ss="RadioIndicator",Es=g.forwardRef((t,s)=>{const{__scopeRadio:r,forceMount:a,...n}=t,d=dn(Ss,r);return e.jsx(es,{present:a||d.checked,children:e.jsx(J.span,{"data-state":$s(d.checked),"data-disabled":d.disabled?"":void 0,...n,ref:s})})});Es.displayName=Ss;var un="RadioBubbleInput",Ps=g.forwardRef(({__scopeRadio:t,control:s,checked:r,bubbles:a=!0,...n},d)=>{const c=g.useRef(null),o=ge(c,d),u=hs(r),x=ss(s);return g.useEffect(()=>{const p=c.current;if(!p)return;const j=window.HTMLInputElement.prototype,h=Object.getOwnPropertyDescriptor(j,"checked").set;if(u!==r&&h){const v=new Event("click",{bubbles:a});h.call(p,r),p.dispatchEvent(v)}},[u,r,a]),e.jsx(J.input,{type:"radio","aria-hidden":!0,defaultChecked:r,...n,tabIndex:-1,ref:o,style:{...n.style,...x,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});Ps.displayName=un;function $s(t){return t?"checked":"unchecked"}var mn=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],Fe="RadioGroup",[hn]=ft(Fe,[as,ws]),Is=as(),Rs=ws(),[pn,fn]=hn(Fe),Ls=g.forwardRef((t,s)=>{const{__scopeRadioGroup:r,name:a,defaultValue:n,value:d,required:c=!1,disabled:o=!1,orientation:u,dir:x,loop:p=!0,onValueChange:j,...l}=t,h=Is(r),v=sa(x),[w,m]=ts({prop:d,defaultProp:n??null,onChange:j,caller:Fe});return e.jsx(pn,{scope:r,name:a,required:c,disabled:o,value:w,onValueChange:m,children:e.jsx(aa,{asChild:!0,...h,orientation:u,dir:v,loop:p,children:e.jsx(J.div,{role:"radiogroup","aria-required":c,"aria-orientation":u,"data-disabled":o?"":void 0,dir:v,...l,ref:s})})})});Ls.displayName=Fe;var As="RadioGroupItem",Ts=g.forwardRef((t,s)=>{const{__scopeRadioGroup:r,disabled:a,...n}=t,d=fn(As,r),c=d.disabled||a,o=Is(r),u=Rs(r),x=g.useRef(null),p=ge(s,x),j=d.value===n.value,l=g.useRef(!1);return g.useEffect(()=>{const h=w=>{mn.includes(w.key)&&(l.current=!0)},v=()=>l.current=!1;return document.addEventListener("keydown",h),document.addEventListener("keyup",v),()=>{document.removeEventListener("keydown",h),document.removeEventListener("keyup",v)}},[]),e.jsx(ra,{asChild:!0,...o,focusable:!c,active:j,children:e.jsx(Cs,{disabled:c,required:d.required,checked:j,...u,...n,name:d.name,ref:p,onCheck:()=>d.onValueChange(n.value),onKeyDown:fe(h=>{h.key==="Enter"&&h.preventDefault()}),onFocus:fe(n.onFocus,()=>{var h;l.current&&((h=x.current)==null||h.click())})})})});Ts.displayName=As;var gn="RadioGroupIndicator",Ds=g.forwardRef((t,s)=>{const{__scopeRadioGroup:r,...a}=t,n=Rs(r);return e.jsx(Es,{...n,...a,ref:s})});Ds.displayName=gn;var Us=Ls,Fs=Ts,xn=Ds;const ot=g.forwardRef(({className:t,...s},r)=>e.jsx(Us,{className:we("grid gap-2",t),...s,ref:r}));ot.displayName=Us.displayName;const me=g.forwardRef(({className:t,...s},r)=>e.jsx(Fs,{ref:r,className:we("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(xn,{className:"flex items-center justify-center",children:e.jsx(na,{className:"h-2.5 w-2.5 fill-current text-current"})})}));me.displayName=Fs.displayName;const bn={pdf:"PDF",model:"Model",dataset:"Dataset",space:"Space",github:"GitHub"},lt=/^[A-Za-z0-9][A-Za-z0-9._-]*$/,jn=/^[A-Za-z0-9][\w.-]*\/[A-Za-z0-9][\w.-]*$/,vn=20,ct="copy_to_bucket";function _n(t){const s=t.trim();if(!jn.test(s))return null;const[r,a]=s.split("/");return`https://huggingface.co/buckets/${encodeURIComponent(r)}/${encodeURIComponent(a)}`}function dt(t){return`pwc:bucket-copy:${t}`}function yn(t){if(typeof window>"u"||new URL(window.location.href).searchParams.get(ct)!==t)return null;try{const r=window.sessionStorage.getItem(dt(t));if(!r)return null;const a=JSON.parse(r);return a.paperId!==t||typeof a.bucketId!="string"||!["new","existing"].includes(a.destinationMode)||!["public","private"].includes(a.visibility)||!Array.isArray(a.selectedIds)||a.selectedIds.some(n=>typeof n!="string")?null:a}catch{return null}}function kn(t,s=vn){if(s<1)throw new Error("Bucket copy batch size must be positive");const r=[];for(let a=0;a!lt.test(u)))return null;const c=d.join("/"),o=s==="model"?"":`${s}s/`;return{id:`${s}:${c}`,kind:s,label:c,url:`https://huggingface.co/${o}${c}`,source:`hf://${o}${c}/`,destination:`${s}s/${c}/`,repoId:c}}catch{return null}}function Nn(t){try{const s=new URL(t);if(s.hostname!=="github.com"&&s.hostname!=="www.github.com")return null;const r=s.pathname.split("/").filter(Boolean);if(r.length<2)return null;const a=r[0],n=r[1].replace(/\.git$/,"");if(!lt.test(a)||!lt.test(n))return null;const d=`${a}/${n}`;return{id:`github:${d}`,kind:"github",label:d,url:`https://github.com/${d}`,source:`https://github.com/${d}.git`,destination:`github/${d}/`}}catch{return null}}function wn({githubUrls:t,hfModelUrls:s,hfDatasetUrls:r,hfSpaceUrls:a,paperId:n,pdfName:d,pdfUrl:c}){const o=[c?{id:"pdf",kind:"pdf",label:"Paper PDF",url:c,source:c,destination:`paper/${d||n}.pdf`}:null,...s.map(x=>st(x,"model")),...r.map(x=>st(x,"dataset")),...a.map(x=>st(x,"space")),...t.map(Nn)],u=new Set;return o.filter(x=>!x||u.has(x.id)?!1:(u.add(x.id),!0))}function Cn(t,s,r){const a=["# Requires the Hugging Face CLI: https://huggingface.co/docs/huggingface_hub/guides/cli",`HF_BUCKET=${_e(t.trim())}`];r.create&&a.push(`hf buckets create "$HF_BUCKET" --exist-ok${r.isPrivate?" --private":""}`);for(const c of s.filter(o=>o.kind!=="github"&&o.kind!=="pdf"))a.push(`hf cp ${_e(c.source)} "hf://buckets/$HF_BUCKET/${c.destination}"`);const n=s.find(c=>c.kind==="pdf");n&&a.push('PWC_PDF="$(mktemp)"',`trap 'rm -f "$PWC_PDF"' EXIT`,`curl --fail --location ${_e(n.source)} --output "$PWC_PDF"`,`hf cp "$PWC_PDF" "hf://buckets/$HF_BUCKET/${n.destination}"`);const d=s.filter(c=>c.kind==="github");if(d.length){a.push('PWC_COPY_DIR="$(mktemp -d)"',`trap 'rm -rf "$PWC_COPY_DIR"' EXIT`);for(const c of d){const o=`$PWC_COPY_DIR/${c.destination.replace(/\/$/,"")}`;a.push(`git clone --depth 1 -- ${_e(c.source)} "${o}"`,`hf sync "${o}" "hf://buckets/$HF_BUCKET/${c.destination}" --exclude '.git/**'`)}}return a.join(` +`)}function Sn(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 En(t){const{toast:s}=W(),r=g.useMemo(()=>wn({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]),a=g.useMemo(()=>yn(t.paperId),[t.paperId]),[n,d]=g.useState(!!a),[c,o]=g.useState((a==null?void 0:a.destinationMode)??"new"),[u,x]=g.useState((a==null?void 0:a.bucketId)??""),[p,j]=g.useState((a==null?void 0:a.visibility)??"public"),[l,h]=g.useState(()=>new Set((a==null?void 0:a.selectedIds)??r.map(y=>y.id))),[v,w]=g.useState(!1),[m,b]=g.useState(null),[i,f]=g.useState(!!a),_=r.filter(y=>l.has(y.id)),S=_.length===r.length,E=_n(u),$=E!==null,C=Cn(u,_,{create:c==="new",isPrivate:p==="private"}),R=(y,I)=>{h(T=>{const H=new Set(T);return I?H.add(y):H.delete(y),H})},L=async()=>{try{await navigator.clipboard.writeText(C),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"})}},B=g.useCallback(()=>{const y=new URL(window.location.href);y.searchParams.set(ct,t.paperId),window.sessionStorage.setItem(dt(t.paperId),JSON.stringify({paperId:t.paperId,bucketId:u.trim(),destinationMode:c,visibility:p,selectedIds:Array.from(l)})),window.location.assign(ia(y.toString(),{authorizeBucket:!0,bucketCreate:c==="new"}))},[u,c,t.paperId,l,p]),k=g.useCallback(async()=>{if(!t.isSignedIn){B();return}w(!0);let y=0,I=0;try{const T=_.filter(F=>F.kind!=="pdf"&&F.kind!=="github"&&!!F.repoId).map(F=>({kind:F.kind,repo_id:F.repoId})),H=kn(T);H.length||H.push([]);for(const[F,Me]of H.entries()){b({current:F+1,total:H.length});const ie=await z.copyToBucket(t.paperId,{bucket_id:u.trim(),create:F===0&&c==="new",private:p==="private",include_pdf:F===0&&_.some(Be=>Be.kind==="pdf"),artifacts:Me});y+=ie.copied.length,I+=ie.errors.length}const ne=_.filter(F=>F.kind==="github").length;s({title:I?"Bucket copy partially completed":"Copied to bucket",description:[`${y} item${y===1?"":"s"} copied.`,I?`${I} item${I===1?"":"s"} failed.`:"",ne?"Use the generated commands below to copy GitHub repositories.":""].filter(Boolean).join(" "),variant:I?"destructive":void 0,action:E?e.jsx(oa,{altText:"Open destination bucket",asChild:!0,children:e.jsx("a",{href:E,target:"_blank",rel:"noopener noreferrer",children:"Open bucket"})}):void 0}),!I&&!ne&&d(!1)}catch(T){if(T instanceof Ce&&T.code==="bucket_authorization_required"){B();return}s({title:y?"Bucket copy partially completed":"Bucket copy failed",description:y?`${y} item${y===1?"":"s"} copied before the request failed. You can retry or use the CLI commands below.`:T instanceof Ce&&typeof T.detail=="string"?T.detail:"Hugging Face could not complete the copy. You can still use the CLI commands below.",variant:"destructive"})}finally{w(!1),b(null)}},[B,u,E,c,t.isSignedIn,t.paperId,_,s,p]);g.useEffect(()=>{if(!i||!t.isSignedIn)return;f(!1),window.sessionStorage.removeItem(dt(t.paperId));const y=new URL(window.location.href);y.searchParams.delete(ct),window.history.replaceState({},"",`${y.pathname}${y.search}${y.hash}`),k()},[k,t.isSignedIn,t.paperId,i]);const P=()=>{h(new Set(r.map(y=>y.id))),!u&&t.suggestedBucketId&&x(t.suggestedBucketId),d(!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:P,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:r.length?`${r.length} linked artifact${r.length===1?"":"s"}`:"No linked artifacts yet"})]}),e.jsx($e,{open:n,onOpenChange:d,children:e.jsxs(Ie,{className:"max-h-[90vh] max-w-2xl grid-rows-[auto_minmax(0,1fr)_auto] overflow-hidden",children:[e.jsxs(Re,{children:[e.jsxs(Le,{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(Ae,{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:r.length?e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(q,{children:"Choose your destination"}),e.jsxs(ot,{value:c,onValueChange:y=>o(y),className:"grid grid-cols-2 gap-2",children:[e.jsxs(q,{className:"bucket-choice",children:[e.jsx(me,{value:"new"}),"New bucket"]}),e.jsxs(q,{className:"bucket-choice",children:[e.jsx(me,{value:"existing"}),"Existing bucket"]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(q,{htmlFor:"bucket-id",children:"Bucket name"}),e.jsx(M,{id:"bucket-id",value:u,onChange:y=>x(y.target.value),placeholder:t.suggestedBucketId||"username/paper-artifacts","aria-invalid":u.length>0&&!$}),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."}),E&&e.jsxs("a",{href:E,target:"_blank",rel:"noopener noreferrer",className:"inline-flex shrink-0 items-center gap-1 underline underline-offset-4",children:["View bucket",e.jsx(U,{name:"external",size:10})]})]})]}),c==="new"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(q,{children:"Bucket visibility"}),e.jsxs(ot,{value:p,onValueChange:y=>j(y),className:"flex gap-5",children:[e.jsxs(q,{className:"flex items-center gap-2 font-normal",children:[e.jsx(me,{value:"public"}),"Public"]}),e.jsxs(q,{className:"flex items-center gap-2 font-normal",children:[e.jsx(me,{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(q,{children:"Artifacts"}),e.jsx(A,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>h(S?new Set:new Set(r.map(y=>y.id))),children:S?"Deselect all":"Select all"})]}),e.jsx("div",{className:"bucket-artifact-list",children:r.map(y=>e.jsxs("div",{className:"bucket-artifact-row",children:[e.jsx(vt,{id:`bucket-artifact-${y.id}`,checked:l.has(y.id),onCheckedChange:I=>R(y.id,I===!0)}),e.jsxs(q,{htmlFor:`bucket-artifact-${y.id}`,className:"min-w-0 flex-1 cursor-pointer font-normal",children:[e.jsx("span",{className:"bucket-artifact-kind",children:bn[y.kind]}),e.jsx("span",{className:"bucket-artifact-name",children:y.label})]}),e.jsxs("a",{href:V(y.url)??void 0,target:"_blank",rel:"noopener noreferrer",className:"bucket-artifact-open",children:["Open",e.jsx(U,{name:"external",size:10})]})]},y.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(q,{htmlFor:"bucket-copy-commands",children:"CLI fallback"}),e.jsx("pre",{id:"bucket-copy-commands",className:"bucket-copy-commands h-[190px]",children:$?C:"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(gt,{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(A,{type:"button",onClick:L,variant:"outline",disabled:!$||_.length===0,children:[e.jsx(U,{name:"copy",size:12}),"Copy commands"]}),e.jsx(A,{type:"button",onClick:k,disabled:v||t.isSignedIn&&(!$||!_.some(y=>y.kind!=="github")),children:v?m&&m.total>1?`Copying ${m.current}/${m.total}…`:"Copying…":t.isSignedIn?"Copy now":"Sign in & copy"})]})]})})]})}function Pn({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(r=>e.jsxs(O,{to:`/paper/${r.arxiv_id||r.id}`,target:"_blank",rel:"noopener noreferrer",className:"related-paper",style:{textDecoration:"none",color:"inherit"},children:[e.jsx("div",{className:"related-title",children:e.jsx(ye,{title:r.title})}),e.jsxs("div",{className:"related-meta",children:[e.jsx("span",{children:r.arxiv_id?`arXiv:${r.arxiv_id}`:"External resource"}),r.citation_count!=null&&e.jsxs("span",{children:[r.citation_count.toLocaleString()," cites"]})]})]},r.id))]}):null}const $n=/(https?:\/\/[^\s]+)/g;function In({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 Rn(t){return new Date(t).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}function Ln({text:t}){return e.jsx("p",{className:"x-thread-text",children:t.split($n).map((s,r)=>r%2===1?e.jsx("span",{className:"x-thread-link",children:s.replace(/^https?:\/\/(www\.)?/,"").replace(/\/$/,"")},r):e.jsx(g.Fragment,{children:s},r))})}function An({thread:t}){const[s,r]=g.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:()=>r(!0)})}function Tn(){var t;return((t=window.matchMedia)==null?void 0:t.call(window,"(prefers-reduced-motion: reduce)").matches)??!1}function Dn({thread:t}){const[s,r]=g.useState(!1),[a,n]=g.useState(null),[d,c]=g.useState(!1),o=g.useRef(null),{targetRef:u,isIntersecting:x}=Va({rootMargin:"200px"}),p=t.video_url;if(g.useEffect(()=>{if(!p||a||d||!x||Tn())return;const l=new AbortController;return fetch(p,{referrerPolicy:"no-referrer",signal:l.signal}).then(h=>{if(!h.ok)throw new Error(`HTTP ${h.status}`);return h.blob()}).then(h=>n(URL.createObjectURL(h))).catch(()=>{l.signal.aborted||c(!0)}),()=>l.abort()},[p,a,d,x]),g.useEffect(()=>()=>{a&&URL.revokeObjectURL(a)},[a]),g.useEffect(()=>{const l=o.current;l&&(x?l.play().catch(()=>{}):l.pause())},[x,a]),!t.media_url||s)return null;const j=a&&!d;return e.jsx("div",{className:"x-thread-media",ref:u,children:j?e.jsx("video",{ref:o,src:a,poster:t.media_url,muted:!0,loop:!0,playsInline:!0,autoPlay:!0,"aria-label":"Video",onError:()=>c(!0)}):e.jsxs(e.Fragment,{children:[e.jsx("img",{src:t.media_url,alt:"",loading:"lazy",referrerPolicy:"no-referrer",onError:()=>r(!0)}),t.media_type==="video"&&e.jsx("span",{className:"x-thread-play","aria-label":"Video",children:"▶"})]})})}function Un({thread:t}){const s=V(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(An,{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(In,{})})]}),e.jsx(Ln,{text:t.text}),e.jsx(Dn,{thread:t}),e.jsxs("div",{className:"x-thread-meta",children:[t.posted_at&&e.jsx("time",{dateTime:t.posted_at,children:Rn(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 Fn({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(r=>e.jsx(Un,{thread:r},r.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 at=3,Qt=3;function Mn(t){return t>=1e3?`${(t/1e3).toFixed(1)}k`:String(t)}function Bn({allHfArtifactUrls:t,citationCopied:s,citationDisplay:r,hfArtifactViewer:a,onCopyCitation:n,onEditHfArtifacts:d,onEditRepositories:c,onEditXThreads:o,paper:u,relatedIsLoading:x,relatedPapers:p,user:j}){var m;const[l,h]=g.useState(!1),v=[...u.repositories??[]].sort((b,i)=>Number(i.is_official)-Number(b.is_official)||(i.num_stars||0)-(b.num_stars||0)),w=(l?v:v.slice(0,at)).map(b=>({...b,safeHref:V(b.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:[v.length," repo",v.length===1?"":"s",e.jsx("button",{type:"button",onClick:c,className:"edit-link",children:"edit"})]})]}),w.filter(({safeHref:b})=>b).map(b=>e.jsxs("a",{href:b.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(U,{name:"github",size:12}),e.jsxs("span",{className:"code-line-repo-name",children:[b.owner,"/",b.name]}),b.is_official&&e.jsx("span",{className:"code-line-official",children:"· Official"})]}),e.jsxs("span",{className:"code-line-stars",children:["★ ",Mn(b.num_stars)]})]},b.id)),v.length===0&&e.jsx("div",{style:{fontFamily:"var(--mono)",fontSize:11,color:"var(--ink-faint)",padding:"6px 0"},children:"No GitHub repositories linked yet."}),v.length>at&&e.jsx("button",{type:"button",className:"bench-show-more",onClick:()=>h(b=>!b),children:l?"− show top 3":`+ show ${v.length-at} more repos`})]}),e.jsx(zn,{viewer:a,onEdit:d}),e.jsx(Fn,{threads:u.x_threads??[],onEdit:o}),e.jsx(En,{githubUrls:v.map(({url:b})=>b),hfModelUrls:t.models,hfDatasetUrls:t.datasets,hfSpaceUrls:t.spaces,paperId:u.id,pdfName:((m=u.arxiv_id)==null?void 0:m.replace("/","-"))||u.id,pdfUrl:u.url_pdf,isSignedIn:!!j,suggestedBucketId:j?`${j.username}/${Sn(u.title)}`:void 0}),e.jsx(Pn,{isLoading:x,papers:p}),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(U,{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:r})]})]})}function zn({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(pe,{className:"h-16 w-full"}):e.jsxs(e.Fragment,{children:[s.rows.map(r=>e.jsx(Hn,{...r},r.label)),s.footer&&e.jsx("div",{style:{fontFamily:"var(--mono)",fontSize:10,color:"var(--ink-faint)",marginTop:12},children:s.footer})]})]})}function Hn({count:t,href:s,isLimited:r,label:a,links:n}){const[d,c]=g.useState(!1),o=((n==null?void 0:n.length)??0)>Qt,u=d?n:n==null?void 0:n.slice(0,Qt),x=t!=null?`${t}${r?"+":""}`:"—";return e.jsxs("div",{className:"hf-artifact-row",children:[e.jsxs("div",{className:"hf-artifact-row-header",children:[e.jsx("span",{children:a}),t?e.jsx("a",{href:s,target:"_blank",rel:"noopener noreferrer",className:"hf-artifact-count",children:x}):e.jsx("span",{className:"hf-artifact-count hf-artifact-count--empty",children:x})]}),u!=null&&u.length?e.jsxs("div",{className:"hf-artifact-links",children:[u.map(p=>e.jsx("a",{href:p.href,target:"_blank",rel:"noopener noreferrer",children:p.label},p.href)),o&&e.jsx("button",{type:"button",className:"hf-artifact-toggle","aria-expanded":d,onClick:()=>c(p=>!p),children:d?"Show fewer":`View all ${n.length}`})]}):null]})}function On({abstract:t,mentions:s}){const r=[];let a=0;for(const n of[...s].sort((d,c)=>d.start-c.start))n.startt.length||t.slice(n.start,n.end)===n.surface&&(r.push(e.jsx(nt,{text:t.slice(a,n.start)},`t${a}`)),r.push(e.jsx(Ma,{entity:{kind:n.entity_type,slug:n.slug},className:"abstract-entity-link",newTab:!1,initialPreview:n.preview?{name:n.preview.name,description:n.preview.description??null,imageUrl:n.preview.image_url??null,count:n.preview.count??null,detail:n.preview.detail??null}:void 0,children:n.surface},`m${n.start}`)),a=n.end);return r.push(e.jsx(nt,{text:t.slice(a)},`t${a}`)),e.jsx(e.Fragment,{children:r})}function qn(t,s){const r=t.arxiv_id?` (arXiv:${re(t.arxiv_id)})`:"";return`About the paper "${t.title}"${r}: ${s}`}function Gn({paper:t,readerChatRoute:s}){const r=la()&&!!(t.id&&t.abstract),a=t.suggested_questions,{data:n}=X({...he.suggestedQuestions(String(t.id)),enabled:r&&Array.isArray(a)&&a.length===0,staleTime:c=>{var o;return(o=c.state.data)!=null&&o.questions.length?1/0:0},retry:!1}),d=a!=null&&a.length?a:(n==null?void 0:n.questions)??[];return!r||d.length===0?null:e.jsx("ul",{className:"suggested-questions","aria-label":"Ask about this paper",children:d.map(c=>{const o=s?`${s}?q=${encodeURIComponent(c)}`:`/chat?q=${encodeURIComponent(qn(t,c))}`;return e.jsx("li",{children:e.jsxs(O,{className:"suggested-question",to:o,onClick:s?()=>os(s):void 0,children:[e.jsx(U,{name:"chat",size:12}),e.jsx("span",{children:c})]})},c)})})}function Xn({canEdit:t,onEditMethods:s,onEditTasks:r,paper:a,readerChatRoute:n}){var o,u,x;const d=a.abstract||"",[c]=g.useState(()=>window.location.hash==="#tldr");return e.jsxs(e.Fragment,{children:[e.jsx(ke,{id:"abstract",label:"Abstract"}),e.jsx("p",{className:"abstract-text",children:(o=a.abstract_mentions)!=null&&o.length?e.jsx(On,{abstract:d,mentions:a.abstract_mentions}):e.jsx(nt,{text:d})}),a.tldr&&e.jsxs("details",{className:"tldr-details paper-section-anchor",id:"tldr",open:c,children:[e.jsxs("summary",{children:[e.jsx("span",{className:"tldr-toggle-show",children:"Show TL;DR"}),e.jsx("span",{className:"tldr-toggle-hide",children:"Hide TL;DR"}),e.jsx("span",{className:"tldr-toggle-hint",children:"short summary"})]}),e.jsx("div",{className:"tldr-box",children:a.tldr})]}),e.jsx(Gn,{paper:a,readerChatRoute:n}),e.jsx(ke,{id:"tasks",label:"Tasks",accent:e.jsxs("span",{className:"accent",children:[((u=a.tasks)==null?void 0:u.length)||0," tagged",t&&e.jsx("button",{type:"button",onClick:r,className:"edit-link",children:"edit"})]})}),e.jsx("div",{className:"paper-tags",style:{marginBottom:8},children:(a.tasks??[]).map(p=>e.jsx(ja,{slug:p.slug||"",label:p.name},p.id))}),e.jsx(ke,{id:"methods",label:"Methods",accent:e.jsxs("span",{className:"accent",children:[((x=a.methods)==null?void 0:x.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:(a.methods??[]).map(p=>e.jsx(va,{method:p},p.id))})]})}const ue=rs.bookmarkIds().queryKey,ut="pwc:pending-bookmark";function Vt(t){window.sessionStorage.setItem(ut,JSON.stringify(t)),window.location.assign(Wa(!0))}function Kn(){var a,n;const{user:t}=Pe(),s=X({...rs.bookmarkIds(),enabled:!!t,staleTime:60*1e3}),r=Se.useMemo(()=>{var d;return new Set(((d=s.data)==null?void 0:d.paper_ids)??[])},[(a=s.data)==null?void 0:a.paper_ids]);return{ids:((n=s.data)==null?void 0:n.paper_ids)??[],idSet:r,isLoading:s.isLoading,isError:s.isError}}function Qn(){const{user:t}=Pe(),s=Y(),r=ae({mutationFn:async({paperId:n,isBookmarked:d})=>{d?await Lt.removeBookmark(n):await Lt.addBookmark(n)},onMutate:async({paperId:n,isBookmarked:d})=>{await s.cancelQueries({queryKey:ue});const c=s.getQueryData(ue),o=typeof n=="string"?Number(n):n,u=(c==null?void 0:c.paper_ids)??[],x=d?u.filter(p=>p!==o):[o,...u.filter(p=>p!==o)];return s.setQueryData(ue,{paper_ids:x}),{previous:c}},onError:(n,d,c)=>{c!=null&&c.previous&&s.setQueryData(ue,c.previous),n instanceof Ce&&n.code==="saved_papers_bucket_authorization_required"&&Vt(d)},onSettled:()=>{s.invalidateQueries({queryKey:ue}),s.invalidateQueries({queryKey:he.saved().queryKey})}});return Se.useEffect(()=>{if(!t||r.isPending)return;const n=new URL(window.location.href);if(n.searchParams.get(Ft)!=="1")return;n.searchParams.delete(Ft),window.history.replaceState({},"",`${n.pathname}${n.search}${n.hash}`);const d=window.sessionStorage.getItem(ut);if(d){window.sessionStorage.removeItem(ut);try{const c=JSON.parse(d);(typeof c.paperId=="number"||typeof c.paperId=="string")&&typeof c.isBookmarked=="boolean"&&r.mutate(c)}catch{}}},[r,t]),{toggle:Se.useCallback((n,d)=>{if(!t){if(ns())return;Vt({paperId:n,isBookmarked:d});return}r.mutate({paperId:n,isBookmarked:d})},[r,t]),isPending:r.isPending}}const Vn=({paperId:t})=>{const{user:s}=Pe(),{idSet:r}=Kn(),{toggle:a,isPending:n}=Qn();if(ns())return null;const d=Number(t),c=!!s&&r.has(d),o=()=>{Number.isFinite(d)&&a(d,c)},u=s&&c?"Saved":"Save",x=s?c?"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${c?" is-saved":""}`,onClick:o,disabled:n,"aria-pressed":c,"aria-label":x,title:x,children:[e.jsx(U,{name:"bookmark",size:12}),u]})};function rt({children:t,showEdit:s=!1,onEdit:r,editAriaLabel:a}){return s?e.jsxs("span",{className:"action-btn-composite",children:[t,e.jsx("button",{type:"button",className:"action-btn-segment action-btn-edit",onClick:r,"aria-label":a,children:"edit"})]}):t}function Wt(t){if(!t)return"—";try{return new Date(t).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}catch{return"—"}}function Yt(t,s){try{const r=new URL(t),n=r.pathname.replace(/\/$/,"").split("/").filter(Boolean).at(-1);return n?n.replace(/[-_]+/g," "):r.hostname.replace(/^www\./,"")}catch{return s}}const Mi=()=>{const{arxivId:t}=ca(),s=Jt(),{toast:r}=W(),{user:a}=Pe(),n=(a==null?void 0:a.is_admin)??!1,{setHideClosedSourceEvals:d}=is(),c=!!a,o=ar(a),{arxivId:u,evaluations:x,evaluationsByTask:p,evaluationsLoading:j,paper:l,paperError:h,paperLoading:v,presentation:w,refetchEvaluations:m,refetchPaper:b,relatedQuery:i,versions:f,visibleEvaluations:_}=xr(t,o),[S,E]=g.useState(!1),{activeEditor:$,openEditor:C,setEditorOpen:R}=br();g.useEffect(()=>{o!=="direct"||!(l!=null&&l.id)||($&&$!=="evaluations"&&z.primeCurationState(l.id).catch(()=>{}),$==="evaluations"&&mt.primeCurationState(l.id).catch(()=>{}))},[$,o,l==null?void 0:l.id]);const[L,B]=g.useState(null),k=g.useRef(!1);g.useEffect(()=>{if(!a||!l||k.current)return;const N=sessionStorage.getItem(At);if(!N)return;if(k.current=!0,!z.freshAuthMutationDraft()){sessionStorage.removeItem(At),da(N)&&C(N);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.")){r({title:"Edit kept locally",description:"Nothing was changed. Reload this paper when you are ready to confirm the saved edit."});return}z.resumeFreshAuthMutation().then(()=>{r({title:"Edit applied",description:"The restored catalog edit was applied."}),window.location.reload()}).catch(ce=>{r({variant:"destructive",title:"Could not apply the saved edit",description:ce instanceof Error?ce.message:"Please reload and review the edit again."})})},[C,l,r,a]);const P=g.useMemo(()=>{if(!a||!(l!=null&&l.author_links))return!1;const N=a.username.toLowerCase();return l.author_links.some(D=>!!D.hf_username&&D.hf_username.toLowerCase()===N)},[a,l==null?void 0:l.author_links]),y=N=>{if(!c){B(N);return}C(N)},I=ae({mutationFn:()=>z.indexFromArxiv(u),onSuccess:()=>{r({title:"Indexed",description:"Paper added to database."}),setTimeout(()=>b(),1200)}}),T=I.error?pt(I.error,"Failed to index paper"):null,H=I.error instanceof Ce&&[429,503].includes(I.error.status)?"Try again later after arXiv has lifted the temporary limit.":null,ne=(w==null?void 0:w.citationCopy)??"",F=(w==null?void 0:w.copyableRanks)??[],[Me,ie]=g.useState(!1),Be=async()=>{if(ne)try{await navigator.clipboard.writeText(ne),ie(!0),r({title:"Citation copied",description:"BibTeX entry copied to clipboard."}),window.setTimeout(()=>ie(!1),1500)}catch{r({title:"Copy failed",description:"Could not access the clipboard. Please copy manually.",variant:"destructive"})}},Ms=async()=>{if(!l)return;const N=l.arxiv_id||l.id,D=nr(N,F);if(D)try{await navigator.clipboard.writeText(D),r({title:"PwC badges copied",description:"Each badge follows its current leaderboard result."})}catch{r({title:"Copy failed",description:"Could not access the clipboard. Please try again.",variant:"destructive"})}};if(v)return e.jsxs("div",{className:"page",children:[e.jsx(pe,{className:"h-12 w-3/4 mb-4"}),e.jsx(pe,{className:"h-6 w-1/3 mb-8"}),e.jsx(pe,{className:"h-64 w-full"})]});if(h||!l)return e.jsxs("div",{className:"page",children:[e.jsxs("div",{className:"breadcrumb",children:[e.jsx(O,{to:"/papers",children:"Papers"}),e.jsx("span",{className:"sep",children:"/"}),e.jsxs("span",{style:{color:"var(--ink)"},children:["arXiv:",u]})]}),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:",u]})," in the database. You can index it from arXiv right now."]}),T&&e.jsx(Pa,{variant:"destructive",className:"mt-4 max-w-xl",children:e.jsxs($a,{children:[e.jsx("div",{children:T}),H&&e.jsx("div",{className:"mt-2",children:H})]})}),e.jsxs("div",{className:"action-row",children:[n&&e.jsxs("button",{className:"action-btn",onClick:()=>u&&I.mutate(),disabled:I.isPending,children:[e.jsx(U,{name:"sparkle",size:12}),I.isPending?"Indexing…":"Index from arXiv"]}),e.jsx(A,{variant:"outline",onClick:()=>s("/papers"),children:"Browse Papers"})]})]});if(!w)return null;const{allHfArtifactUrls:Bs,authorEntries:ze,citationDisplay:zs,hasIntroducedItems:Hs,hasLineageItems:Os,hfArtifactViewer:qs,introducedBenchmarks:Gs,introducedFrameworks:yt,introducedMethods:Xs,introducedSummary:Ks,numPages:kt,paperSourceLabel:Nt,predecessorPapers:He,projectPages:oe,safeAbstractUrl:xe,safeConferenceUrl:wt,safePdfUrl:Ct,successorPapers:Oe}=w,be=12,le=wa(l,u),Qs=le&&Tt()&&ua()&&(!Dt()||n)?le:null,St=l.organizations||[],Et=N=>{const D=Ya(N)??N.name;return e.jsx(O,{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:ce=>{var $t;($t=ce.currentTarget.parentElement)==null||$t.classList.remove("detail-title-org--logo"),ce.currentTarget.replaceWith(D)}}):D},N.id)},Pt=S||ze.length<=be?ze:ze.slice(0,be);return e.jsxs("div",{className:"page",children:[e.jsxs("div",{className:"breadcrumb",children:[e.jsx(O,{to:"/",children:"Trending"}),e.jsx("span",{className:"sep",children:"/"}),l.arxiv_id&&xe?e.jsxs("a",{className:"breadcrumb-external",href:xe,target:"_blank",rel:"noopener noreferrer",title:"Open on arXiv",children:[Nt,e.jsx("span",{"aria-hidden":"true",children:"↗"})]}):e.jsx("span",{children:Nt})]}),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(ye,{title:l.title}),St.slice(0,-1).map(Et),e.jsxs("span",{className:"detail-title-tail",children:[St.slice(-1).map(Et),e.jsx("button",{type:"button",className:"detail-title-edit",onClick:()=>y("organizations"),title:"Edit organizations","aria-label":"Edit organizations",children:e.jsx(U,{name:"pencil",size:11})})]})]}),e.jsxs("div",{className:"detail-meta",children:[e.jsxs("span",{children:["Submitted ",Wt(l.published)]}),kt&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsxs("span",{children:[kt," 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}$/,"")})]}),f.length>1&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsx("select",{className:"version-select",value:l.version,onChange:N=>{const D=N.target.value;l.arxiv_id&&s(`/paper/${re(l.arxiv_id)}${D?`?version=${D}`:""}`)},children:f.map(N=>e.jsxs("option",{value:N.version,children:[N.version," — ",Wt(N.published)]},N.version))})]})]}),e.jsxs("div",{className:"detail-authors",children:[Pt.map((N,D)=>e.jsxs(Se.Fragment,{children:[N.hf_username&&e.jsx(Ja,{className:"detail-author-avatar",url:N.hf_avatar_url}),N.id?e.jsx(O,{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}),Dbe&&e.jsx("button",{className:"show-more-authors",onClick:()=>E(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:[le&&Tt()&&(!Dt()||a!=null&&a.is_admin)?e.jsxs(O,{className:"action-btn",to:le,onClick:()=>os(le),children:[e.jsx(U,{name:"pdf",size:12})," Read paper",e.jsx("span",{className:"nav-new-badge","aria-hidden":"true",children:"New"})]}):Ct?e.jsxs("a",{className:"action-btn",href:Ct,target:"_blank",rel:"noopener noreferrer",children:[e.jsx(U,{name:"pdf",size:12})," View PDF"]}):null,xe&&l.source==="external"&&e.jsx(rt,{showEdit:!0,onEdit:()=>y("source_url"),editAriaLabel:"Edit source URL",children:e.jsxs("a",{className:"action-btn-segment action-btn-main",href:xe,target:"_blank",rel:"noopener noreferrer",children:[e.jsx(U,{name:"external",size:12})," Source page"]})}),oe.length===1?e.jsx(rt,{showEdit:!0,onEdit:()=>y("project_pages"),editAriaLabel:"Edit project pages",children:e.jsxs("a",{className:"action-btn-segment action-btn-main",href:oe[0].safeHref??void 0,target:"_blank",rel:"noopener noreferrer",children:[e.jsx(U,{name:"globe",size:12})," Project page"]})}):null,oe.length>1?e.jsx(rt,{showEdit:!0,onEdit:()=>y("project_pages"),editAriaLabel:"Edit project pages",children:e.jsxs(ma,{children:[e.jsx(ha,{asChild:!0,children:e.jsxs("button",{type:"button",className:"action-btn-segment action-btn-main",children:[e.jsx(U,{name:"globe",size:12})," Project page"]})}),e.jsx(pa,{align:"start",className:"project-page-menu",children:oe.map((N,D)=>e.jsx(fa,{asChild:!0,children:N.safeHref?e.jsx("a",{href:N.safeHref,target:"_blank",rel:"noopener noreferrer",children:Yt(N.url,`Project page ${D+1}`)}):e.jsx("span",{children:Yt(N.url,`Project page ${D+1}`)})},N.url))})]})}):null,oe.length===0&&c?e.jsxs("button",{type:"button",className:"action-btn",onClick:()=>y("project_pages"),title:"Add project page",children:[e.jsx(U,{name:"globe",size:12})," Add project page"]}):null,wt&&e.jsxs("a",{className:"action-btn",href:wt,target:"_blank",rel:"noopener noreferrer",children:[e.jsx(U,{name:"external",size:12})," Conference"]}),e.jsxs("a",{className:"action-btn",href:Ea(l.title,l.arxiv_id),target:"_blank",rel:"noopener noreferrer",title:"Ask Hugging Face ML Intern to reproduce this paper",children:[e.jsx("span",{className:"ml-intern-icon",children:e.jsx(U,{name:"robot",size:12})})," Reproduce with ML Intern"]}),e.jsx(jr,{paperId:Number(l.id)}),n&&ga()&&e.jsx(Ns,{kind:"enrich-paper",triggerClassName:"action-btn",paperId:Number(l.id),paperTitle:l.title,onComplete:()=>void b()}),e.jsx(Vn,{paperId:l.id})]}),l.leaderboard_ranks&&l.leaderboard_ranks.length>0&&e.jsx(_a,{wrap:!0,paperHref:`/paper/${l.arxiv_id||l.id}`,ranks:Na(l.leaderboard_ranks)})]}),e.jsx("div",{className:"detail-hero-thumb detail-thumb-wrap",children:e.jsx(ya,{paperId:l.arxiv_id||l.id,title:l.title,thumbnailUrl:xa(l.thumbnail_url),priority:!0})})]}),Hs&&e.jsxs("div",{className:`introduced-banner${yt.length>0?" introduced-banner--framework":""}`,children:[e.jsx("span",{className:"introduced-label",children:"Introduced"}),e.jsxs("div",{className:"introduced-methods",children:[Xs.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}`)),Gs.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}`)),yt.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 ",Ks,"."]})]}),Os&&e.jsxs("div",{className:"introduced-banner lineage-banner",children:[Oe.length>0&&e.jsxs("div",{className:"lineage-row",children:[e.jsx("span",{className:"introduced-label lineage-label",children:Oe.length===1?"Follow-up paper":"Follow-up papers"}),e.jsx("div",{className:"introduced-methods",children:Oe.map(N=>e.jsxs("button",{type:"button",className:"introduced-pill lineage-pill",onClick:()=>s(`/paper/${N.route_identifier}`),children:[e.jsx(ye,{title:N.title}),e.jsx("span",{className:"introduced-arrow",children:"→"})]},`successor-${N.id}`))})]}),He.length>0&&e.jsxs("div",{className:"lineage-row",children:[e.jsx("span",{className:"introduced-label lineage-label",children:He.length===1?"Predecessor paper":"Predecessor papers"}),e.jsx("div",{className:"introduced-methods",children:He.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(ye,{title:N.title})]},`predecessor-${N.id}`))})]})]}),e.jsx(Xn,{canEdit:!0,onEditMethods:()=>y("methods"),onEditTasks:()=>y("tasks"),paper:l,readerChatRoute:Qs}),e.jsx(on,{canCopyBadge:F.length>0,canEdit:!0,evaluationsByTask:p,evaluationsLoading:j,hiddenClosedSourceCount:((x==null?void 0:x.length)??0)-((_==null?void 0:_.length)??0),isAdmin:n,onCopyBadge:Ms,onEdit:()=>y("evaluations"),onRefresh:()=>void m(),onShowClosedSourceEvals:()=>d(!1),paper:l,visibleEvaluationCount:(_==null?void 0:_.length)??0})]}),e.jsx(Bn,{allHfArtifactUrls:Bs,citationCopied:Me,citationDisplay:zs,hfArtifactViewer:qs,onCopyCitation:Be,onEditHfArtifacts:()=>y("hf_artifacts"),onEditRepositories:()=>y("repositories"),onEditXThreads:()=>y("x_threads"),paper:l,relatedIsLoading:i.isLoading,relatedPapers:i.data,user:a})]}),e.jsx(tn,{activeEditor:$,arxivId:u,editSubmitMode:o,evaluations:x??[],isAdmin:n,isLinkedAuthor:P,onOpenChange:R,paper:l}),e.jsx(Ba,{open:L!==null,onOpenChange:N=>{N||B(null)},sectionLabel:L?ba[L]:"this paper",returnTo:typeof window<"u"?window.location.pathname:"/"})]})};export{Mi as default};