1import{a as s,j as e}from"./vendor-react-BieOFGTO.js";import{u as ne,a1 as oe}from"./vendor-utils-Uev4__JX.js";import{c as ie,u as ce,B as w,F as le,X as de,k as me,o as ue,t as xe,L as pe,V as he,U as ge,n as fe}from"./index-Bca1piM7.js";import{T as R}from"./textarea-DwgfvJTR.js";import{B as N}from"./badge-DRB4Qwvn.js";import{U as ve,D as je,N as be}from"./NotesPicker-E6quw-_2.js";import{T as we}from"./triangle-alert-B9y4pClh.js";import{D as P}from"./DomoAIMicroLogo-BwWUQdjX.js";import{A as Ne}from"./arrow-left-dzFqS96Z.js";import{S as B}from"./sparkles-BmRHc6Ak.js";import{B as T}from"./bot-F45RDGx7.js";import{C as ye}from"./copy-BZmBdsr_.js";import"./vendor-query-Bf7VLrsv.js";import"./vendor-radix-Cx3Dvb0S.js";import"./vendor-motion-B4SuNsHa.js";import"./sticky-note-CIEbBcwE.js";import"./search-C8hOgTjE.js";import"./tag-D8tPgDQq.js";import"./arrow-right-DAXW6Ax9.js";const ke=ie("FileType",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M9 13v-1h6v1",key:"1bb014"}],["path",{d:"M12 12v6",key:"3ahymv"}],["path",{d:"M11 18h2",key:"12mj7e"}]]);class $ extends s.Component{constructor(){super(...arguments),this.state={hasError:!1}}static getDerivedStateFromError(c){return{hasError:!0,error:c}}componentDidCatch(c,a){console.error("ErrorBoundary caught an error:",c,a)}render(){return this.state.hasError?this.props.fallback?this.props.fallback:this.props.showError?e.jsxs("div",{className:"flex items-center gap-2 text-red-500 text-sm",children:[e.jsx(we,{size:16}),e.jsx("span",{children:"Component error"})]}):null:this.props.children}}const z={"application/pdf":"PDF","application/msword":"Word","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"Word","text/plain":"Text","text/markdown":"Markdown"},Ce=[".pdf",".doc",".docx",".txt",".md"];function De(l){const c=z[l.type];if(c)return c;const a=l.name.split(".").pop()?.toLowerCase()??"";return{pdf:"PDF",doc:"Word",docx:"Word",txt:"Text",md:"Markdown"}[a]??a.toUpperCase()}function Se({msg:l,onCopy:c}){const[a,i]=s.useState(!1),d=l.role==="user",x=()=>{c(l.content),i(!0),setTimeout(()=>i(!1),2e3)};return e.jsxs("div",{className:`flex gap-2 ${d?"flex-row-reverse":"flex-row"}`,children:[e.jsx("div",{className:`shrink-0 w-7 h-7 rounded-full flex items-center justify-center mt-1 ${d?"bg-primary/10":"bg-green-500/10"}`,children:d?e.jsx(ge,{className:"h-3.5 w-3.5 text-primary"}):e.jsx(T,{className:"h-3.5 w-3.5 text-green-600 dark:text-green-400"})}),e.jsxs("div",{className:`group relative max-w-[85%] rounded-2xl px-4 py-2.5 text-sm leading-relaxed ${d?"bg-primary text-primary-foreground rounded-tr-sm":"bg-muted rounded-tl-sm"}`,children:[e.jsx("div",{className:"whitespace-pre-wrap break-words",children:l.content}),e.jsx("button",{onClick:x,className:`absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity p-1 rounded ${d?"hover:bg-white/20":"hover:bg-accent"}`,title:"Copy",children:a?e.jsx(fe,{className:"h-3 w-3"}):e.jsx(ye,{className:"h-3 w-3"})})]})]})}function He(){const[,l]=ne(),c=oe(),{toast:a}=ce(),[i,d]=s.useState(null),[x,U]=s.useState(""),[W,y]=s.useState(!1),[k,O]=s.useState(!1),[f,v]=s.useState(""),[K,X]=s.useState(""),[V,q]=s.useState(0),[H,Y]=s.useState(!1),[C,D]=s.useState(""),[p,m]=s.useState([]),[S,j]=s.useState(""),[h,F]=s.useState(!1),b=s.useRef(null),A=s.useRef(null),I=s.useRef(null),E=s.useRef(!1);s.useEffect(()=>{A.current?.scrollIntoView({behavior:"smooth"})},[p,h]);const M=t=>{const n="."+(t.name.split(".").pop()?.toLowerCase()??""),r=Object.keys(z).includes(t.type),o=Ce.includes(n);if(!r&&!o){a({title:"Unsupported file",description:"Please upload a PDF, Word (.doc/.docx), or text file.",variant:"destructive"});return}d(t),v(""),D(""),m([])};s.useEffect(()=>{if(E.current)return;const t=new URLSearchParams(c),n=t.get("fileUrl"),r=t.get("fileName")||"document";if(!n)return;E.current=!0;const o=localStorage.getItem("sessionId");fetch(n,{headers:o?{Authorization:`Bearer ${o}`}:{}}).then(async g=>{if(!g.ok)throw new Error("Could not fetch file");const u=await g.blob(),ae=new File([u],r,{type:u.type||"application/octet-stream"});M(ae),a({title:"File loaded from Caleidoscope",description:r})}).catch(()=>{a({title:"Could not load file",description:"Try uploading it manually.",variant:"destructive"})})},[c]);const _=t=>{t.target.files?.[0]&&M(t.target.files[0])},J=s.useCallback(t=>{t.preventDefault(),y(!1),t.dataTransfer.files?.[0]&&M(t.dataTransfer.files[0])},[]),Q=t=>{t.preventDefault(),y(!0)},Z=()=>y(!1),G=()=>{d(null),v(""),D(""),m([]),b.current&&(b.current.value="")},ee=async()=>
1{if(!i){a({title:"No file selected",description:"Please upload a document first.",variant:"destructive"});return}O(!0),v(""),m([]);try{const t=localStorage.getItem("sessionId"),n=new FormData;n.append("document",i),x.trim()&&n.append("instructions",x.trim());const r=await fetch("/api/ai/document-review",{method:"POST",credentials:"include",headers:t?{Authorization:`Bearer ${t}`}:{},body:n});if(r.status===401){a({title:"Please sign in",description:"You must be logged in to use document review.",variant:"destructive"});return}const o=await r.json();if(!r.ok){a({title:"Review failed",description:o.message||"Something went wrong.",variant:"destructive"});return}v(o.review),X(o.fileName),q(o.characterCount),Y(o.truncated),D(o.documentText||"")}catch{a({title:"Connection error",description:"Could not reach AIDOMO. Please try again.",variant:"destructive"})}finally{O(!1)}},L=async()=>{const t=S.trim();if(!t||!C)return;const n={role:"user",content:t};m(r=>[...r,n]),j(""),F(!0);try{const r=localStorage.getItem("sessionId"),o=await fetch("/api/ai/document-chat",{method:"POST",credentials:"include",headers:{"Content-Type":"application/json",...r?{Authorization:`Bearer ${r}`}:{}},body:JSON.stringify({documentText:C,messages:p,userMessage:t})}),g=await o.json();if(!o.ok){a({title:"Chat failed",description:g.message||"Something went wrong.",variant:"destructive"}),m(u=>u.slice(0,-1));return}m(u=>[...u,{role:"assistant",content:g.reply}])}catch{a({title:"Connection error",description:"Could not reach AIDOMO.",variant:"destructive"}),m(r=>r.slice(0,-1))}finally{F(!1),I.current?.focus()}},te=t=>{t.key==="Enter"&&!t.shiftKey&&(t.preventDefault(),L())},se=t=>{navigator.clipboard.writeText(t).then(()=>{a({title:"Copied to clipboard"})})},re=["Make the tone more professional","Fix all grammar errors","Simplify the language","Shorten this document","Rewrite the introduction","Make it more formal"];return e.jsxs("div",{className:"container max-w-4xl mx-auto py-6 px-4",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[e.jsx(w,{variant:"ghost",size:"icon",onClick:()=>l("/"),children:e.jsx(Ne,{className:"h-5 w-5"})}),e.jsxs("div",{className:"flex flex-col items-center gap-0.5",children:[e.jsx($,{children:e.jsx(P,{size:32})}),e.jsx("span",{className:"text-[10px] font-semibold tracking-widest uppercase text-green-600 dark:text-green-400 leading-none",children:"Document Review"})]}),e.jsx("h1",{className:"text-2xl font-semibold",children:"Document Review"}),e.jsxs(N,{variant:"secondary",className:"bg-green-500/10 text-green-700 dark:text-green-400 border-green-500/30",children:[e.jsx(B,{className:"h-3 w-3 mr-1"}),"AIDOMO"]})]}),e.jsx("p",{className:"text-muted-foreground mb-6",children:"Upload a document and AIDOMO will inspect it for grammar, clarity, structure, and tone â then chat to make changes."}),e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{onDrop:J,onDragOver:Q,onDragLeave:Z,onClick:()=>!i&&b.current?.click(),className:` 2 relative border-2 border-dashed rounded-xl p-8 text-center transition-all cursor-pointer select-none 3 ${W?"border-green-500 bg-green-500/10":"border-border hover:border-green-500/50 hover:bg-green-500/5"} 4 ${i?"cursor-default":""} 5 `,children:[e.jsx("input",{ref:b,type:"file",accept:".pdf,.doc,.docx,.txt,.md",className:"hidden",onChange:_}),i?e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 text-left min-w-0",children:[e.jsx("div",{className:"shrink-0 w-10 h-10 rounded-lg bg-green-500/10 flex items-center justify-center",children:e.jsx(le,{className:"h-5 w-5 text-green-600 dark:text-green-400"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-medium truncate",children:i.name}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[De(i)," · ",(i.size/1024).toFixed(0)," KB"]})]})]}),e.jsx(w,{variant:"ghost",size:"icon",className:"shrink-0",onClick:t=>{t.stopPropagation(),G()},children:e.jsx(de,{className:"h-4 w-4"})})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"mx-auto w-12 h-12 rounded-full bg-green-500/10 flex items-center justify-center",children:e.jsx(ve,{className:"h-6 w-6 text-green-600 dark:text-green-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Drop your document here, or click to browse"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Supported: PDF, Word (.doc/.docx), Text, Markdown · Ma
5x 20 MB"})]}),e.jsx("div",{className:"flex items-center justify-center gap-2 flex-wrap",children:["PDF","DOC","DOCX","TXT","MD"].map(t=>e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs bg-muted px-2 py-0.5 rounded-full",children:[e.jsx(ke,{className:"h-3 w-3"}),t]},t))})]})]}),e.jsxs("div",{children:[e.jsxs(me,{htmlFor:"doc-instructions",className:"mb-1.5 block",children:["Additional instructions ",e.jsx("span",{className:"text-muted-foreground font-normal",children:"(optional)"})]}),e.jsx(R,{id:"doc-instructions",placeholder:"e.g. Focus on grammar only, make the tone more professional, simplify complex sentences...",value:x,onChange:t=>U(t.target.value),rows:3})]}),e.jsxs(w,{onClick:ee,disabled:k||!i,className:"w-full bg-green-600 hover:bg-green-700 text-white",size:"lg",children:[e.jsx($,{children:e.jsx(P,{size:18})}),e.jsx("span",{className:"ml-2",children:k?"AIDOMO is reviewing your document...":"Review Document with AIDOMO"})]}),f&&e.jsxs("div",{className:"mt-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("p",{className:"text-sm font-medium text-muted-foreground",children:["Review for: ",e.jsx("span",{className:"text-foreground",children:K})]}),e.jsxs(N,{variant:"outline",className:"text-xs",children:[V.toLocaleString()," characters"]}),H&&e.jsx(N,{variant:"outline",className:"text-xs text-yellow-600 border-yellow-500/40 bg-yellow-500/10",children:"First 30,000 characters reviewed"})]}),e.jsx(je,{response:f,title:"AIDOMO Document Review",author:"AIDOMO AI Assistant",streaming:!0,speed:10,showHeader:!0,className:"border-green-200 dark:border-green-800 bg-green-50/50 dark:bg-green-950/10 w-full min-h-[40vh]"})]}),k&&!f&&e.jsx(ue,{className:"border-green-200 dark:border-green-800 bg-green-50/50 dark:bg-green-950/10",children:e.jsxs(xe,{className:"p-6 flex flex-col items-center gap-3 text-center",children:[e.jsx("div",{className:"w-8 h-8 rounded-full border-2 border-green-500 border-t-transparent animate-spin"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"AIDOMO is carefully reading and reviewing your document..."})]})}),f&&C&&e.jsxs("div",{className:"mt-6 border rounded-2xl overflow-hidden bg-background shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 border-b bg-green-500/5",children:[e.jsx(T,{className:"h-4 w-4 text-green-600 dark:text-green-400"}),e.jsx("span",{className:"font-medium text-sm",children:"Chat with AIDOMO to edit your document"}),e.jsxs(N,{variant:"secondary",className:"ml-auto text-xs bg-green-500/10 text-green-700 dark:text-green-400 border-green-500/20",children:[e.jsx(B,{className:"h-3 w-3 mr-1"}),"Live editing"]})]}),p.length===0&&e.jsxs("div",{className:"px-4 pt-4 pb-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Quick suggestions:"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:re.map(t=>e.jsx("button",{onClick:()=>{j(t),I.current?.focus()},className:"text-xs px-3 py-1.5 rounded-full border border-green-500/30 hover:bg-green-500/10 hover:border-green-500 transition-colors text-muted-foreground hover:text-foreground",children:t},t))})]}),p.length>0&&e.jsxs("div",{className:"px-4 py-4 space-y-4 max-h-[500px] overflow-y-auto",children:[p.map((t,n)=>e.jsx(Se,{msg:t,onCopy:se},n)),h&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("div",{className:"shrink-0 w-7 h-7 rounded-full bg-green-500/10 flex items-center justify-center mt-1",children:e.jsx(T,{className:"h-3.5 w-3.5 text-green-600 dark:text-green-400"})}),e.jsxs("div",{className:"bg-muted rounded-2xl rounded-tl-sm px-4 py-3 flex items-center gap-1.5",children:[e.jsx("span",{className:"w-1.5 h-1.5 bg-green-500 rounded-full animate-bounce",style:{animationDelay:"0ms"}}),e.jsx("span",{className:"w-1.5 h-1.5 bg-green-500 rounded-full animate-bounce",style:{animationDelay:"150ms"}}),e.jsx("span",{className:"w-1.5 h-1.5 bg-green-500 rounded-full animate-bounce",style:{animationDelay:"300ms"}})]})]}),e.jsx("div",{ref:A})]}),e.jsxs("div",{className:"px-4 pt-2 pb-1 border-t bg-muted/30 flex flex-col gap-1.5",children:[e.jsx("div",{className:"flex items-center gap-1",children:e.jsx(be,{buttonLabel:"Insert from Notes",onInsert:(t,n)=>j(r=>r?`${r} 6 7[Note: "${n}"] 8${t}`:`[Note: "${n}"] 9${t}`)})}),e.jsxs("div",{className:"flex gap-2 items-end",children:[e.jsx(R,{ref:I,value:S,onChange:t=>j(t.target.value),onKeyDown:te,placeholder:"Ask AIDOMO to make changes⦠e.g. 'Fix the grammar', 'Make this more concise', 'Rewrite paragraph 2'",rows:2,className:"resize-none flex-1 text-sm bg-background border-green-500/30 focus-visible:ring-green-500/50",disabled:h}),e.jsx(w,{onClick:L,disabled:h||!S.trim(),size:"icon",className:"h-10 w-10 shrink-0 bg-green-600 hover:bg-green-700 text-white",children:h?e.jsx(pe,{className:"h-4 w-4 animate-spin"}):e.jsx(he,{className:"h-4 w-4"})})]})]})]})]})]})}export{He 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.