1import{b as Me,aZ as Oe,bj as Ve,r as n,bQ as _e,t as $e,bR as V,bS as L,z as D,j as e,bu as Ge,af as ie,F as Be,a1 as de,G as He,I as me,L as F,ak as Ye,C as _,T as ce,V as qe,bG as Ke,bH as Je,k as We,D as Qe,ac as Ze,M as Xe}from"./index-BawMCgu8.js";import{S as et}from"./Select-CBvYay3K.js";import{u as tt}from"./chat-Cp3tSG9E.js";import{u as at}from"./useTextCreditEstimate-BRFi1zgD.js";import{L as rt}from"./link-C1iEqoKY.js";import"./locale-en-B8Z5F_o1.js";import"./locale-zh-CN-CFdD1mPv.js";import"./locale-fr-j4CMJpfE.js";import"./locale-de-DuE2gagy.js";import"./locale-it-C6yb6RzN.js";import"./locale-ja-VjZBy5eF.js";import"./locale-ko-Cl0W-Az5.js";import"./locale-es-DwboUZze.js";import"./locale-zh-Hant-uT5aTnfX.js";import"./locale-ru-DEr1xfTZ.js";import"./locale-id-Buh3Uolz.js";import"./locale-pt-BR-CqD5J4_0.js";const st=[{id:"text",icon:Be},{id:"document",icon:de},{id:"url",icon:He},{id:"image",icon:me}],ue="summary_active_source",xe="summary_page_state",lt=()=>{try{const r=localStorage.getItem(ue);if(r&&["text","document","url","video","image"].includes(r))return r}catch{}return"text"},nt=()=>{try{const r=localStorage.getItem(xe);if(r)return JSON.parse(r)}catch{}return{}};function St(){const{t:r,i18n:Q}=Me(),{requireAuth:pe}=Oe(),{confirm:ge,ConfirmDialogElement:he}=Ve(),{selectedModel:S,setSelectedModel:fe}=tt(),[I]=n.useState(nt),[p,ye]=n.useState(()=>I.language||_e(Q.language)),[l,be]=n.useState(lt),[o,Z]=n.useState(I.textInput||""),[i,X]=n.useState(I.urlInput||""),[c,ee]=n.useState(I.videoUrlInput||""),[x,E]=n.useState(null),[$,te]=n.useState(null),[R,G]=n.useState(null),ve=n.useMemo(()=>l==="text"?o.length:l==="url"?i.length+5e3:l==="video"?c.length+8e3:l==="document"?5e3:l==="image"?500:0,[l,o,i,c]),{estimate:je,insufficient:ae}=at(S,ve,500),[B,re]=n.useState([]),[Ne,se]=n.useState(!1),C=300,k=!0,[H,we]=n.useState({text:"",document:"",url:"",video:"",image:"",...I.results}),[N,Y]=n.useState(!1),{copy:Se,copied:Ce}=$e(),[T,ke]=n.useState(!1),[q,U]=n.useState(!1),[Ie,b]=n.useState(""),v=n.useRef(null),A=n.useRef(null),P=n.useRef(null),z=n.useRef(null),m=H[l],w=t=>we(a=>({...a,[l]:t}));n.useEffect(()=>{try{localStorage.setItem(ue,l)}catch{}},[l]),n.useEffect(()=>{try{const t={textInput:o,urlInput:i,videoUrlInput:c,language:p,results:H};localStorage.setItem(xe,JSON.stringify(t))}catch{}},[o,i,c,p,H]),n.useEffect(()=>{l==="document"&&B.length===0&&M()},[l]),n.useEffect(()=>{N&&z.current&&(z.current.scrollTop=z.current.scrollHeight)},[m,N]);const M=async()=>{var t;se(!0);try{const a=await V.list({page:1,limit:50});(t=a.data)!=null&&t.documents&&re(a.data.documents)}catch(a){console.error("Failed to load documents:",a)}finally{se(!1)}},Re=async(t,a)=>{if(a.stopPropagation(),!!await ge({message:r("summary.confirmDeleteDoc"),variant:"danger"}))try{await V.delete(t),re(s=>s.filter(d=>d.id!==t)),x===t&&E(null)}catch(s){console.error("Failed to delete document:",s),D.error(r("summary.toast.deleteFailed"))}},K=n.useCallback(()=>{switch(l){case"text":return o.trim().length>0;case"document":return x!==null;case"url":return i.trim().length>0&&le(i);case"video":return c.trim().length>0&&ne(c);case"image":return $!==null;default:return!1}},[l,o,x,i,c,$]),le=t=>{try{return new URL(t),!0}catch{return!1}},ne=t=>t.includes("youtube.com")||t.includes("youtu.be")||t.includes("bilibili.com"),Ue=(t,a=1024,s=.8)=>new Promise((d,u)=>{const g=new FileReader;g.onload=J=>{var W;const h=new window.Image;h.onload=()=>{const j=document.createElement("canvas");let{width:f,height:y}=h;(f>a||y>a)&&(f>y?(y=y/f*a,f=a):(f=f/y*a,y=a)),j.width=f,j.height=y;const O=j.getContext("2d");if(!O){u(new Error("Failed to get canvas context"));return}O.fillStyle="#FFFFFF",O.fillRect(0,0,f,y),O.drawImage(h,0,0,f,y);const ze=j.toDataURL("image/jpeg",s);d(ze)},h.onerror=()=>u(new Error("Failed to load image")),h.src=(W=J.target)==null?void 0:W.result},g.onerror=()=>u(new Error("Failed to read file")),g.readAsDataURL(t)}),Le=async t=>{var s,d;const a=(s=t.target.files)==null?void 0:s[0];if(a){if(a.size>10*1024*1024){D.error(r("summary.toast.fileTooLarge","File size cannot exceed 10MB"));return}U(!0),b(r("summary.uploading"));try{b(r("summary.uploadingFile"));const u=await V.upload(a);if((d=u.data)!=null&&d.id){b(r("summary.uploadedProcessing")),E(u.data.id),M();let g=0;const J=120,h=setInterval(async()=>{g++;try{const j=(await V.get(u.data.id)).data;j.status==="ready"||j.status==="completed"?(clearInterval(h),b(""),U(!1),M()):j.status==="failed"?(clearInterval(h),D.error(r("summary.toast.process
1Failed","Document processing failed, please check the file format")),b(""),U(!1),M()):b(r("summary.processingDoc"))}catch{}g>=J&&(clearInterval(h),b(""),U(!1))},2e3)}}catch(u){D.error(u instanceof Error?u.message:r("summary.toast.uploadFailed","Upload failed")),U(!1),b("")}finally{P.current&&(P.current.value="")}}},De=async t=>{var s;const a=(s=t.target.files)==null?void 0:s[0];if(a){te(a);try{const d=await Ue(a,1024,.85);G(d)}catch{const d=new FileReader;d.onload=u=>{var g;return G((g=u.target)==null?void 0:g.result)},d.readAsDataURL(a)}}},oe=()=>{te(null),G(null),A.current&&(A.current.value="")},Fe=n.useCallback(async()=>{if(pe()&&K()){Y(!0),w(""),v.current=new AbortController;try{if(l==="text"&&o){let t="";for await(const a of L.summarizeTextStream({text:o,maxLength:C,bulletPoints:k,language:p,model:S},v.current.signal))t+=a,w(t);return}if(l==="document"&&x){let t="";for await(const a of L.summarizeDocumentStream(x,{maxLength:C,bulletPoints:k,language:p,model:S},v.current.signal))t+=a,w(t);return}if(l==="url"&&i){let t="";for await(const a of L.summarizeWebpageStream({url:i,maxLength:C,bulletPoints:k,language:p,model:S},v.current.signal))t+=a,w(t);return}if(l==="video"&&c){let t="";for await(const a of L.summarizeVideoStream({url:c,maxLength:C,bulletPoints:k,language:p,model:S},v.current.signal))t+=a,w(t);return}if(l==="image"&&R){let t="";for await(const a of L.summarizeImageStream({imageUrl:R,maxLength:C,bulletPoints:k,language:p},v.current.signal))t+=a,w(t);return}}catch(t){if(t.name==="AbortError")return;const a=t instanceof Error?t.message:"";let s=r("summary.toast.analysisFailed","Analysis failed");a.includes("timeout")||a.includes("ECONNABORTED")||a.includes("è¶
æ¶")?s=r("summary.toast.errorTimeout","Request timeout, the webpage took too long to respond"):a.includes("403")||a.includes("forbidden")||a.includes("blocks")||a.includes("ç¦æ¢")?s=r("summary.toast.errorForbidden","This webpage blocks automated access"):a.includes("404")||a.includes("not found")||a.includes("ä¸åå¨")?s=r("summary.toast.errorNotFound","Webpage not found, please check the URL"):a.includes("extract")||a.includes("meaningful")||a.includes("æ æ³æå")?s=r("summary.toast.errorNoContent","Unable to extract content from this webpage"):a.includes("Unsupported video")||a.includes("䏿¯æ")?s=r("summary.toast.errorUnsupportedPlatform","Unsupported platform, only YouTube and Bilibili are supported"):a.includes("yt-dlp")||a.includes("æªå®è£
")?s=r("summary.toast.errorVideoService","Video extraction service unavailable"):a.includes("åå¹")||a.includes("subtitle")||a.includes("transcript")?s=r("summary.toast.errorNoSubtitle","No subtitles available for this video"):a.includes("è§é¢ä¿¡æ¯")||a.includes("video info")?s=r("summary.toast.errorVideoFetch","Failed to get video info, please check the URL"):a.includes("image")||a.includes("å¾ç")?s=r("summary.toast.errorImageFailed","Image analysis failed"):a&&(s=a),D.error(s)}finally{Y(!1),v.current=null}}},[l,o,x,i,c,R,C,k,p,K]),Ee=()=>{var t;(t=v.current)==null||t.abort(),Y(!1)},Te=()=>{m&&Se(m)},Ae=()=>{if(!m)return;const t=new Blob([m],{type:"text/plain;charset=utf-8"}),a=URL.createObjectURL(t),s=document.createElement("a");s.href=a,s.download=`summary-${Date.now()}.txt`,s.click(),URL.revokeObjectURL(a)},Pe=()=>{Z(""),X(""),ee(""),E(null),oe(),w("")};return e.jsxs("div",{className:"h-full flex flex-col bg-[var(--bg-primary)]",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 md:px-6 py-3 border-b border-ui-border",children:[l!=="image"&&e.jsx(Ge,{featureKey:"agent_summary",value:S,onChange:fe}),e.jsxs("button",{className:"flex items-center gap-2 text-sm text-[var(--text-tertiary)] hover:text-[var(--text-primary)]",children:[e.jsx(ie,{className:"w-4 h-4"}),r("summary.headerTitle")]})]}),e.jsxs("div",{className:"flex-1 flex flex-col md:flex-row overflow-hidden",children:[e.jsx("div",{className:"w-full md:w-1/2 border-b md:border-b-0 md:border-r border-ui-border flex flex-col overflow-y-auto max-h-[50vh] md:max-h-none",children:e.jsxs("div",{className:"p-4 md:p-6 flex flex-col gap-4 md:gap-6",children:[e.jsx("div",{className:"flex bg-[var(--bg-tertiary)] rounded-lg p-1 overflow-x-auto",children:st.map(t=>{const a=t.icon,s=l===t.id;return e.jsxs("button",{onClick:()=>be(t.id),className:`flex-1 shrink-0 flex items-center justify-center gap-1.5 md:gap-2 px-2 md:px-3 py-2 text-sm font-medium rounded-md transition-colors whitespace-nowrap ${s?"bg-[var(--bg-primary)] text-[var(--text-primary)] shadow-sm":"text-[var(--text-tertiary)] hover:text-[var(--text-primary)]"}`,children:[e.jsx(a,{className:"w-4 h-4"}),e.jsx("span",{children:r(`summary.tab.${t.id}`)})]},t.id)})}),e.jsxs("div",{className:"flex-1",children:[l==="text"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-[var(--text-secondary)] mb-2 block",children:r("summary.inputTextLabel")}),e.jsx("textarea",{className:"w-full h-40 p-4 border border-ui-border rounded-lg resize-none focus:outline-none focus:ring-2 focus:ring-gray-400 bg-[var(--bg-primary)] text-[var(--text-primary)] placeholder-gray-400",placeholder:r("summary.inputTextPlaceholder"),value:o,onChange:t=>Z(t.target.value),maxLength:2e4}),e.jsxs("div",{className:"mt-2 flex items-center justify-between text-xs text-[var(--text-tertiary)]",children:[e.jsxs("span",{children:[o.length.toLocaleStr
1ing()," ",r("common.characters","characters")]}),o.length>0&&e.jsx("span",{children:r("summary.readTime",{count:Math.ceil(o.length/500)})})]})]}),l==="document"&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("label",{className:"text-sm font-medium text-[var(--text-secondary)] block",children:r("summary.selectDocLabel")}),e.jsx("div",{className:`border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors ${q?"border-gray-400 bg-[var(--bg-tertiary)]":"border-ui-border hover:border-gray-400 hover:bg-[var(--bg-hover)]"}`,onClick:()=>{var t;return!q&&((t=P.current)==null?void 0:t.click())},children:q?e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx(F,{className:"w-6 h-6 animate-spin text-[var(--text-tertiary)]"}),e.jsx("span",{className:"text-sm text-[var(--text-secondary)]",children:Ie||r("summary.processing")})]}):e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx(Ye,{className:"w-6 h-6 text-gray-400"}),e.jsx("span",{className:"text-sm text-[var(--text-secondary)]",children:r("summary.clickToUploadDoc")}),e.jsx("span",{className:"text-xs text-gray-400",children:r("summary.docFormats")})]})}),e.jsx("input",{ref:P,type:"file",accept:".pdf,.doc,.docx,.txt,.md,.ppt,.pptx",onChange:Le,className:"hidden"}),Ne?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-[var(--text-tertiary)] py-4",children:[e.jsx(F,{className:"w-4 h-4 animate-spin"}),r("summary.loadingDocs")]}):B.length>0&&e.jsx("div",{className:"space-y-2 max-h-[200px] overflow-y-auto",children:B.map(t=>{const a=t.status==="ready"||t.status==="completed",s=t.status==="processing"||t.status==="pending";return e.jsxs("div",{className:`group flex items-center gap-3 p-3 rounded-lg cursor-pointer transition-colors ${x===t.id?"bg-[var(--bg-tertiary)] border border-[var(--text-secondary)]":"bg-[var(--bg-tertiary)] border border-transparent hover:bg-[var(--bg-hover)]"} ${a?"":"opacity-60"}`,onClick:()=>a&&E(t.id),children:[e.jsx("div",{className:`p-2 rounded-lg ${x===t.id?"bg-[var(--bg-secondary)]":"bg-[var(--bg-tertiary)]"}`,children:s?e.jsx(F,{className:"w-4 h-4 animate-spin text-[var(--text-tertiary)]"}):e.jsx(de,{className:`w-4 h-4 ${x===t.id?"text-[var(--text-primary)]":"text-[var(--text-tertiary)]"}`})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate text-[var(--text-primary)]",children:t.filename||t.title||t.name||r("summary.unnamedDoc")}),e.jsxs("p",{className:"text-xs text-[var(--text-tertiary)]",children:[s&&r("summary.processing"),t.status==="failed"&&e.jsx("span",{className:"text-red-500",children:r("summary.processFailed")}),a&&(t.pageCount||t.pages)&&r("summary.pageCount",{count:t.pageCount||t.pages})]})]}),x===t.id&&a&&e.jsx(_,{className:"w-5 h-5 text-[var(--text-primary)]"}),e.jsx("button",{className:"p-1.5 hover:bg-red-100 rounded-lg opacity-0 group-hover:opacity-100 transition-all",onClick:d=>Re(t.id,d),title:r("summary.deleteDoc"),children:e.jsx(ce,{className:"w-4 h-4 text-red-500"})})]},t.id)})})]}),l==="url"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-[var(--text-secondary)] mb-2 block",children:r("summary.urlLabel")}),e.jsxs("div",{className:"flex items-center gap-3 p-3 border border-ui-border rounded-lg focus-within:ring-2 focus-within:ring-gray-400 bg-[var(--bg-tertiary)]",children:[e.jsx(rt,{className:"w-4 h-4 text-gray-400"}),e.jsx("input",{type:"url",className:"flex-1 bg-transparent outline-none text-sm text-[var(--text-primary)] placeholder-gray-400",placeholder:r("summary.urlPlaceholder"),value:i,maxLength:500,onChange:t=>X(t.target.value)}),i&&le(i)&&e.jsx(_,{className:"w-4 h-4 text-green-500"})]}),e.jsx("p",{className:"mt-2 text-xs text-[var(--text-tertiary)]",children:r("summary.urlHint")})]}),l==="video"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-[var(--text-secondary)] mb-2 block",children:r("summary.videoUrlLabel")}),e.jsxs("div",{className:"flex items-center gap-3 p-3 border border-ui-border rounded-lg focus-within:ring-2 focus-within:ring-gray-400 bg-[var(--bg-tertiary)]",children:[e.jsx(qe,{className:"w-4 h-4 text-gray-400"}),e.jsx("input",{type:"url",className:"flex-1 bg-transparent outline-none text-sm text-[var(--text-primary)] placeholder-gray-400",placeholder:r("summary.videoUrlPlaceholder"),value:c,maxLength:500,onChange:t=>ee(t.target.value)}),c&&ne(c)&&e.jsx(_,{className:"w-4 h-4 text-green-500"})]}),e.jsxs("div",{className:"mt-2 flex items-center gap-2 text-xs text-[var(--text-tertiary)]",children:[e.jsx("span",{children:r("summary.videoSupports")}),e.jsx("span",{className:"px-2 py-0.5 bg-[var(--bg-tertiary)] text-[var(--text-secondary)] rounded",children:"YouTube"}),e.jsx("span",{className:"px-2 py-0.5 bg-[var(--bg-tertiary)] text-[var(--text-secondary)] rounded",children:"Bilibili"})]})]}),l==="image"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-[var(--text-secondary)] mb-2 block",children:r("summary.uploadImageLabel")}),R?e.jsxs("div",{className:"relative group",children:[e.jsx("img",{src:R,alt:"Preview",className:"max-h-[200px] rounded-lg mx-auto border border-ui-border"}),e.jsx("div",{className:"absolute inset-0 bg-black/50 opacity-0 group-hover:opacity-100 transition-opacity rounded-lg flex items-center justify-center",children:e.jsx("button",{className:"p-2 bg-red-500 text-white rounded-full hover:bg-red-600 transition-colors",onClick:oe,children:e.jsx(ce,{className:"w-4 h-4"})})})]}):e.jsxs("div",{className:"border-2 border-dashed border-ui-border rounded-lg p-8 text-center cursor-pointer hover:border-gray-400 hover:bg-[var(--bg-hover)] transition-colors",onClick:()=>{var t;return(t=A.current)==null?void 0:t.click()},children:[e.jsx(me,{className:"w-8 h-8 text-gray-400 mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-[var(--text-secondary)]",children:r("summary.clickOrDragImage")}),e.jsx("p",{className:"text-xs text-gray-400 mt-1",children:r("summary.imageFormats")})]}),e.jsx("input",{ref:A,type:"file",accept:"image/*",onChange:De,className:"hidden"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium text-[var(--text-secondary)] mb-2 block",children:r("summary.languageLabel")}),e.jsx(et,{value:p,onChange:t=>ye(t),options:Ke.map(t=>({value:t.code,label:Je(t,Q.language)})),className:"w-full"})]}),e.jsxs("div",{className:"flex items-center gap-4 mt-4",children:[(o||i||c||x||$)&&e.jsx("button",{onClick:Pe,className:"px-4 py-3 text-sm text-[var(--text-tertiary)] hover:text-[var(--text-primary)] border border-ui-border rounded-lg hover:bg-[var(--bg-hover)] transition-colors",children:r("common.clear","Clear")}),e.jsx("button",{onClick:N?Ee:Fe,disabled:(!K()||ae)&&!N,title:ae&&!N?r("summary.insufficientCredits",{count:je??0}):void 0,className:"flex-1 bg-[var(--theme)] text-white rounded-lg px-6 py-3 hover:bg-[var(--theme-hover)] disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2 font-medium transition-all",children:N?e.jsxs(e.Fragment,{children:[e.jsx(F,{className:"w-5 h-5 animate-spin"}),r("summary.generating")]}):e.jsxs(e.Fragment,{children:[e.jsx(ie,{className:"w-5 h-5"}),r("summary.startAnalysis")]})})]})]})}),e.jsxs("div",{className:`${T?"fixed inset-0 z-50":"w-full md:w-1/2"} flex flex-col bg-[var(--bg-secondary)]`,children:[e.jsxs("div",{className:"flex items-center justify-between px-4 md:px-6 py-3 md:py-4 border-b border-ui-border",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("span",{className:"text-sm text-[var(--text-tertiary)]",children:r("summary.resultTitle")}),N&&e.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-[var(--text-tertiary)] animate-pulse",children:[e.jsx(F,{className:"w-3 h-3 animate-spin"}),r("summary.generating")]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:Te,disabled:!m,className:"p-2 rounded-lg hover:bg-[var(--bg-hover)] text-[var(--text-tertiary)] disabled:opacity-50 disabled:cursor-not-allowed transition-colors",title:r("common.copy","Copy"),children:Ce?e.jsx(_,{className:"w-4 h-4 text-green-500"}):e.jsx(We,{className:"w-4 h-4"})}),e.jsx("button",{onClick:Ae,disabled:!m,className:"p-2 rounded-lg hover:bg-[var(--bg-hover)] text-[var(--text-tertiary)] disabled:opacity-50 disabled:cursor-not-allowed transition-colors",title:r("common.download","Download"),children:e.jsx(Qe,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>ke(!T),className:"p-2 rounded-lg hover:bg-[var(--bg-hover)] text-[var(--text-tertiary)] transition-colors",title:T?r("common.collapse","Collapse"):r("common.expand","Expand"),children:T?e.jsx(Ze,{className:"w-4 h-4"}):e.jsx(Xe,{className:"w-4 h-4"})})]})]}),e.jsx("div",{ref:z,className:"flex-1 overflow-y-auto p-6",children:m?e.jsx("div",{className:"whitespace-pre-wrap text-sm leading-relaxed text-[var(--text-primary)]",children:m}):e.jsx("div",{className:"h-full flex items-center justify-center text-[var(--text-muted)]",children:e.jsx("p",{children:r("summary.resultHint")})})}),m&&e.jsx("div",{className:"border-t border-ui-border p-4",children:e.jsxs("div",{className:"text-xs text-[var(--text-tertiary)]",children:[e.jsxs("span",{children:[m.length.toLocaleStr
1ing()," ",r("common.characters","characters")]}),e.jsx("span",{className:"mx-2",children:"·"}),e.jsx("span",{children:r("summary.readTime",{count:Math.ceil(m.length/300)})})]})})]})]}),he]})}export{St as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.