Spaces:
Running
Running
File size: 14,469 Bytes
14aee29 77c3110 14aee29 | 1 2 3 4 5 6 7 | import{c as C,r as j,j as t,R as g}from"./index-Dq4RFSP6.js";import{M as S,S as w,A as P,o as R,s as b,v as $}from"./chatSessions-DWxbbxRV.js";import"./katex.min-BSBacQyE.js";import{H as T,a as I,b as M}from"./hover-card-BxOV7XYi.js";import{r as H,a as U,P as F}from"./PaperPreviewLink-BqCm1Tow.js";import{M as L,r as A,d as B}from"./index-CIS6RuaO.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 O=C("Pencil",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]),ue=({onSend:e,busy:s,placeholder:a,autoFocus:n,draft:i,onDraftChange:o,onStop:r,models:d=[],selectedModel:l,onModelChange:h})=>{const[u,f]=j.useState(""),p=j.useRef(null);j.useEffect(()=>{const c=p.current;c&&(c.style.height="auto",c.style.height=`${Math.min(c.scrollHeight,200)}px`)},[u]),j.useEffect(()=>{var c;n&&((c=p.current)==null||c.focus())},[n]),j.useEffect(()=>{i!==void 0&&f(i)},[i]);const x=()=>{const c=u.trim();!c||s||(f(""),o==null||o(""),e(c))};return t.jsxs("div",{className:"chat-composer",children:[t.jsx("textarea",{ref:p,rows:1,value:u,placeholder:a||"Ask anything about research…",onChange:c=>{f(c.target.value),o==null||o(c.target.value)},onKeyDown:c=>{c.key==="Enter"&&!c.shiftKey&&(c.preventDefault(),x())}}),t.jsxs("div",{className:"chat-composer-row",children:[t.jsxs("div",{className:"chat-composer-tools",children:[d.length>0&&l&&h&&t.jsx(S,{models:d,selectedModel:l,onModelChange:h,disabled:s}),t.jsx("span",{className:"chat-composer-hint",children:"Enter to send · Shift+Enter for newline"})]}),t.jsx("button",{type:"button",className:`chat-send${s||u.trim()?" chat-send-on":""}`,onClick:s?r:x,disabled:s?!r:!u.trim(),"aria-label":s?"Stop generating":"Send message",children:s?r?t.jsx("span",{"aria-hidden":"true",children:"■"}):t.jsx(w,{light:!0}):t.jsx(P,{})})]})]})},v=new Map,q=e=>{if(!e)return Promise.resolve();const s=v.get(e);if(s)return s;const a=new Promise(n=>{const i=new Image;i.onload=()=>{n()},i.onerror=()=>{v.delete(e),n()},i.src=e});return v.set(e,a),a},V=new Set(["huggingface.co","www.huggingface.co"]),K=new Set(["api","blog","chat","collections","docs","enterprise","join","login","models","new","organizations","papers","posts","pricing","search","settings","spaces","tasks"]);function z(e){let s;try{s=new URL(e)}catch{return null}if(s.protocol!=="https:"||!V.has(s.hostname))return null;const a=s.pathname.split("/").filter(Boolean),n=a[0]==="datasets"?"dataset":"model",i=n==="dataset"?a.slice(1):a;if(i.length!==2||n==="model"&&K.has(i[0])||i.some(h=>!h||h==="."||h===".."))return null;const o=i.join("/"),r=i.map(encodeURIComponent).join("/"),d=n==="dataset"?`datasets/${r}`:r,l=n==="dataset"?"datasets":"models";return{type:n,repoId:o,url:`https://huggingface.co/${d}`,thumbnailUrl:`https://cdn-thumbnails.huggingface.co/social-thumbnails/${l}/${r}.png`}}const D=()=>typeof window.matchMedia=="function"&&window.matchMedia("(hover: none), (pointer: coarse)").matches,W=({repo:e})=>{const[s,a]=g.useState(!1);return t.jsxs("div",{className:"hf-preview-card",children:[s?t.jsx("div",{className:"hf-preview-fallback","aria-hidden":"true",children:"🤗"}):t.jsx("img",{className:"hf-preview-image","data-testid":"hf-preview-image",src:e.thumbnailUrl,alt:"",loading:"eager",decoding:"async",onError:()=>a(!0)}),t.jsxs("div",{className:"hf-preview-meta",children:[t.jsxs("span",{className:"hf-preview-kind",children:["Hugging Face ",e.type]}),t.jsx("strong",{children:e.repoId}),t.jsx("span",{children:"huggingface.co"})]})]})},X=({repo:e,children:s})=>{const[a,n]=g.useState(!1),i=g.useRef(null),o=g.useCallback(()=>{q(e.thumbnailUrl)},[e.thumbnailUrl]);return g.useEffect(()=>{const r=i.current;if(!r||typeof IntersectionObserver>"u")return;const d=new IntersectionObserver(([l])=>{l.isIntersecting&&(o(),d.disconnect())},{rootMargin:"200px"});return d.observe(r),()=>d.disconnect()},[o]),t.jsxs(T,{open:a,onOpenChange:r=>{(!r||!D())&&n(r)},openDelay:150,closeDelay:100,children:[t.jsx(I,{asChild:!0,children:t.jsx("a",{ref:i,className:"chat-paper-link chat-hf-link",href:e.url,target:"_blank",rel:"noopener noreferrer",onPointerEnter:o,onFocus:o,children:s})}),t.jsx(M,{className:"hf-preview-pop",side:"bottom",align:"start",collisionPadding:12,children:t.jsx(W,{repo:e})})]})};function Y(e,s,a){if(s)return{routeId:e,title:s.title,arxivId:s.metadata.arxiv_id,source:s.metadata.source,sourceUrl:s.metadata.source_url,thumbnailUrl:s.metadata.thumbnail_url,authors:s.metadata.authors.map(n=>n.name),published:s.metadata.published,conference:s.metadata.conference,citationCount:s.metadata.citation_count,tasks:s.metadata.tasks};if(a)return{routeId:e,title:a.title,arxivId:a.arxiv_id??null,source:a.arxiv_id?"arxiv":"external",sourceUrl:a.source_url,thumbnailUrl:a.thumbnail_url??null,authors:a.authors??[],published:a.published??null,conference:a.conference??null,citationCount:a.citation_count??null,tasks:[]}}const k=({routeId:e,paper:s,citation:a,className:n="chat-paper-link",children:i})=>t.jsx(F,{routeId:e,initialData:Y(e,s,a),className:n,target:"_blank",children:i});function G(e){const s=e.lastIndexOf("[");if(s===-1)return e;const a=e.slice(s);return/^\[[^\]]*(\]\(?[^)\s]*)?$/.test(a)?e.slice(0,s):e}const J=e=>e.startsWith("paper:")?e:B(e),N=({text:e,streaming:s,papers:a,citations:n})=>{const i=s?G(e):e;return t.jsx(L,{remarkPlugins:[A,U],rehypePlugins:[H],urlTransform:J,components:{a:({href:o,children:r})=>{if(o!=null&&o.startsWith("paper:")){const l=o.slice(6);return!a[l]&&!(n!=null&&n[l])?t.jsx("span",{className:"chat-invalid-citation",children:r}):t.jsx(k,{routeId:l,paper:a[l],citation:n==null?void 0:n[l],children:r})}const d=o?z(o):null;return d?t.jsx(X,{repo:d,children:r}):t.jsx("span",{children:r})}},children:i})};function Q(e){if(!e.authors.length)return"";const s=e.authors.slice(0,3).map(a=>a.name).join(", ");return e.authors.length>3?`${s}, et al.`:s}function Z(e){var a;if(e.conference)return e.conference;const s=(a=e.published)==null?void 0:a.slice(0,4);if(e.arxiv_id)return s?`arXiv ${s}`:"arXiv";if(e.source_url)try{return new URL(e.source_url).hostname.replace(/^www\./,"")}catch{}return s??"external"}function ee(e,s=240){const a=e.content.trim();return a.length<=s?a:`${a.slice(0,s).trimEnd()}…`}const E=()=>t.jsx("span",{className:"chat-caret"}),te=e=>{var a;if(!e.streaming)return!1;const s=(a=e.blocks)==null?void 0:a.at(-1);return s?s.kind==="reasoning"?!s.active:s.kind==="tool"?s.status!=="running":!1:!0},se=e=>{var x,c;if(e.button!==0||e.detail!==2)return;e.preventDefault();const s=e.currentTarget,a=s.ownerDocument,n=(x=a.caretPositionFromPoint)==null?void 0:x.call(a,e.clientX,e.clientY),i=n?null:(c=a.caretRangeFromPoint)==null?void 0:c.call(a,e.clientX,e.clientY),o=(n==null?void 0:n.offsetNode)??(i==null?void 0:i.startContainer),r=(n==null?void 0:n.offset)??(i==null?void 0:i.startOffset);if(!(o instanceof Text)||r===void 0||!s.contains(o))return;const d=o.data,l=/[\p{L}\p{M}\p{N}_'-]/u;let h=Math.min(r,d.length),u=h;for(;h>0&&l.test(d[h-1]);)h-=1;for(;u<d.length&&l.test(d[u]);)u+=1;if(h===u)return;const f=a.getSelection();if(!f)return;const p=a.createRange();p.setStart(o,h),p.setEnd(o,u),f.removeAllRanges(),f.addRange(p)},ae=({block:e,papers:s,citations:a,onToggle:n})=>e.active?t.jsxs("div",{className:"chat-reason-live",children:[t.jsxs("div",{className:"chat-reason-live-head",children:[t.jsx(w,{})," ",t.jsx("span",{children:"Thinking…"})]}),t.jsxs("div",{className:"chat-reason-live-body chat-answer chat-reason-markdown",children:[t.jsx(N,{text:e.text,streaming:!0,papers:s,citations:a}),t.jsx(E,{})]})]}):t.jsxs("div",{className:"chat-reason-done",children:[t.jsxs("button",{type:"button",className:"chat-reason-done-head",onClick:n,"aria-expanded":e.open,children:[t.jsx(R,{}),t.jsx("span",{children:"Thought for a few seconds"}),t.jsx(b,{open:e.open})]}),e.open&&t.jsx("div",{className:"chat-reason-done-body chat-answer chat-reason-markdown",children:t.jsx(N,{text:e.text,papers:s,citations:a})})]}),ne=({block:e,papers:s,onToggle:a})=>{var u,f,p,x;const n=e.status==="running",i=e.schema_version===2||!!e.content,o=e.status==="error"||e.status==="denied",r=typeof e.args.query=="string"?e.args.query:"",d=typeof e.args.command=="string"?e.args.command:typeof e.args.file_path=="string"?e.args.file_path:r,l=((u=e.content)==null?void 0:u.map(c=>c.text).join(""))??"",h=n?"running…":i?`${e.status} · ${e.took_ms??0} ms`:`${e.hits} results · ${e.took_ms} ms`;return t.jsxs("div",{className:`chat-tool${n?" chat-tool-running":""}${o?" chat-tool-failed":""}`,children:[t.jsxs("button",{type:"button",className:"chat-tool-head",onClick:a,disabled:n,"aria-expanded":n?void 0:e.open,children:[t.jsxs("span",{className:"chat-tool-head-left",children:[n?t.jsx(w,{}):t.jsx($,{}),t.jsx("code",{className:"chat-tool-name",children:e.name}),t.jsx("span",{className:"chat-tool-query",children:i?d:`("${r}")`})]}),t.jsxs("span",{className:"chat-tool-head-right",children:[t.jsx("span",{className:"chat-tool-status",children:h}),!n&&t.jsx(b,{open:e.open})]})]}),!n&&e.open&&t.jsxs("div",{className:"chat-tool-body",children:[t.jsxs("div",{className:"chat-tool-args",children:[t.jsx("span",{className:"chat-tool-label",children:"arguments"}),t.jsx("pre",{children:JSON.stringify(e.args,null,2)})]}),i?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"chat-tool-output-head",children:[t.jsx("span",{className:"chat-tool-label",children:"result"}),t.jsx("button",{type:"button",className:"chat-tool-copy",onClick:()=>void navigator.clipboard.writeText(l),children:"Copy"})]}),t.jsx("pre",{className:"chat-tool-output",children:t.jsx("code",{children:l})}),((f=e.metadata)==null?void 0:f.output_truncated)&&t.jsx("div",{className:"chat-tool-truncated",children:"Output was truncated."})]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"chat-tool-label chat-tool-results-label",children:["returned ",((p=e.results)==null?void 0:p.length)??0," papers"]}),t.jsx("ol",{className:"chat-tool-results",children:(x=e.results)==null?void 0:x.map(c=>t.jsxs("li",{className:"chat-hit",children:[t.jsx("div",{className:"chat-hit-top",children:t.jsx(k,{routeId:c.route_id,paper:s[c.route_id],className:"chat-hit-title",children:c.title})}),t.jsx("div",{className:"chat-hit-meta",children:[Q(c.metadata),Z(c.metadata)].filter(Boolean).join(" · ")}),t.jsxs("div",{className:"chat-hit-snippet",children:[ee(c),c.content_truncated&&t.jsx("span",{className:"chat-hit-truncated",children:" (truncated)"})]})]},c.route_id))})]})]})]})},re=({block:e,papers:s,citations:a,streaming:n})=>t.jsxs("div",{className:"chat-answer",children:[t.jsx(N,{text:e.text,streaming:n,papers:s,citations:a}),n&&!!e.text.trim()&&t.jsx(E,{})]}),me=({id:e,text:s,editingAllowed:a=!1,editing:n=!1,editNotice:i,onEdit:o,onCancel:r,onResend:d})=>{const[l,h]=g.useState(s),[u,f]=g.useState(!1),p=g.useRef(null),x=g.useCallback(()=>{const m=p.current;if(!m)return;m.style.height="auto";const _=Math.max(120,window.innerHeight*.4);m.style.height=`${Math.min(m.scrollHeight,_)}px`,m.style.overflowY=m.scrollHeight>_?"auto":"hidden"},[]);g.useLayoutEffect(()=>{if(!n)return;h(s),f(!1);const m=p.current;m&&(m.focus(),m.setSelectionRange(s.length,s.length),x())},[n,x,s]),g.useLayoutEffect(x,[x,l]);const c=!!l.trim()&&l.length<=8e3,y=()=>{!c||u||(f(!0),d!=null&&d(l)||f(!1))};return n?t.jsx("div",{className:"chat-msg chat-msg-user chat-msg-user-editing","data-message-id":e,children:t.jsxs("div",{className:"chat-inline-editor",children:[t.jsx("textarea",{ref:p,className:"chat-inline-editor-textarea","aria-label":"Edit message",value:l,maxLength:8e3,onChange:m=>h(m.target.value),onKeyDown:m=>{m.key==="Escape"?(m.preventDefault(),r==null||r()):m.key==="Enter"&&!m.shiftKey&&!m.nativeEvent.isComposing&&(m.preventDefault(),y())}}),i&&t.jsx("div",{className:"chat-inline-editor-notice",children:i}),t.jsxs("div",{className:"chat-inline-editor-actions",children:[t.jsx("button",{type:"button",onClick:r,children:"Cancel"}),t.jsx("button",{type:"button",className:"chat-inline-editor-send",disabled:!c||u,onClick:y,children:"Send"})]})]})}):t.jsx("div",{className:"chat-msg chat-msg-user","data-message-id":e,children:t.jsxs("div",{className:"chat-user-message-wrap",children:[t.jsx("div",{className:"chat-bubble",children:t.jsx("span",{className:"chat-bubble-text",onMouseDown:se,children:s})}),a&&t.jsx("div",{className:"chat-user-actions",children:t.jsx("button",{type:"button",className:"chat-user-edit","aria-label":"Edit message",title:"Edit",onClick:o,children:t.jsx(O,{"aria-hidden":"true"})})})]})})},fe=({msg:e,papers:s,onToggleBlock:a,onArchiveOldChats:n,archivePending:i=!1})=>{var o;return t.jsx("div",{className:"chat-msg chat-msg-assistant",children:t.jsxs("div",{className:"chat-msg-blocks",children:[(o=e.blocks)==null?void 0:o.map((r,d)=>{var f;const l=`${e.id}-${d}`,h="citations"in r&&r.citations!==void 0?r.citations:e.citations??[],u=Object.fromEntries(h.map(p=>[p.route_id,p]));return r.kind==="reasoning"?t.jsx(ae,{block:r,papers:s,citations:u,onToggle:()=>a(e.id,d)},l):r.kind==="tool"?t.jsx(ne,{block:r,papers:s,onToggle:()=>a(e.id,d)},l):t.jsx(re,{block:r,papers:s,citations:u,streaming:!!(e.streaming&&d===(((f=e.blocks)==null?void 0:f.length)??0)-1)},l)}),te(e)&&t.jsx("div",{className:"chat-waiting",role:"status","aria-live":"polite",children:t.jsx("span",{className:"chat-thinking",children:e.status??"Thinking…"})}),e.error&&t.jsxs("div",{className:"chat-error",children:[t.jsx("span",{children:e.errorCode==="chat_session_quota_exceeded"?e.error:`The assistant hit an error: ${e.error}`}),["hf_inference_billing_required","hf_inference_billing_exhausted"].includes(e.errorCode??"")&&t.jsx("a",{href:"/settings",children:e.errorCode==="hf_inference_billing_required"?"Add HF token in Settings":"Review billing settings"}),e.errorCode==="chat_session_quota_exceeded"&&n&&t.jsx("button",{type:"button",disabled:i,onClick:n,children:i?"Archiving…":"Archive chats older than 30 days"})]}),!e.streaming&&e.finishReason&&e.finishReason!=="success"&&t.jsx("div",{className:"chat-finish-note",children:["tool_limit","max_turns"].includes(e.finishReason)?"The assistant stopped at the execution limit.":`The assistant stopped early (${e.finishReason.replace(/_/g," ")}).`})]})})};export{fe as A,ue as C,me as U};
|