teodor-new-chat-ui 3.0.114 → 3.0.115
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +2 -2
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -9360,8 +9360,8 @@ const ri = (e, t) => (e == null ? void 0 : e.id) ?? `message-${t}`, Cd = X.forwa
|
|
|
9360
9360
|
}, [_, t]);
|
|
9361
9361
|
const M = t && b && I.current && !v && I.current ? "smooth" : !1, Y = an(() => {
|
|
9362
9362
|
if (!(S.current || e.length === 0))
|
|
9363
|
-
return
|
|
9364
|
-
}, []), W = {
|
|
9363
|
+
return e.length - 1;
|
|
9364
|
+
}, [e.length]), W = {
|
|
9365
9365
|
// Prevent scroll anchoring issues
|
|
9366
9366
|
overflowAnchor: "none",
|
|
9367
9367
|
// Optimize for scroll performance
|
package/dist/index.umd.js
CHANGED
|
@@ -75,7 +75,7 @@ Check the top-level render call using <`+_e+">.")}return re}}function Jn(I,re){{
|
|
|
75
75
|
If you want to hide the \`${e.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
76
76
|
|
|
77
77
|
For more information, see https://radix-ui.com/primitives/docs/components/${e.docsSlug}`;return T.useEffect(()=>{t&&(document.getElementById(t)||console.error(n))},[n,t]),null},tI="DialogDescriptionWarning",nI=({contentRef:t,descriptionId:e})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${jm(tI).contentName}}.`;return T.useEffect(()=>{var i;const a=(i=t.current)==null?void 0:i.getAttribute("aria-describedby");e&&a&&(document.getElementById(e)||console.warn(r))},[r,t,e]),null},Xm=km,rI=Fm,Zm=Gm,si=Ym,li=Hm,Vn=Vm,ci=$m,Jm=Km;const aI=Xm,iI=Zm,eg=T.forwardRef(({className:t,...e},n)=>u.jsx(si,{ref:n,className:X("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",t),...e}));eg.displayName=si.displayName;const tg=T.forwardRef(({className:t,children:e,...n},r)=>{const a=T.useMemo(()=>{let i=!1;function o(s){T.Children.forEach(s,l=>{if(i||!T.isValidElement(l))return;const c=l.type;if(c===Vn||(c==null?void 0:c.displayName)===Vn.displayName||(c==null?void 0:c.name)==="DialogTitle"){i=!0;return}l.props&&l.props.children&&o(l.props.children)})}return o(e),i},[e]);return u.jsxs(iI,{children:[u.jsx(eg,{}),u.jsxs(li,{ref:r,className:X("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",t),...n,children:[!a&&u.jsx(Vn,{className:"sr-only",children:"Dialog"}),e,u.jsxs(Jm,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[u.jsx(me.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});tg.displayName=li.displayName;const ng=({className:t,...e})=>u.jsx("div",{className:X("flex flex-col space-y-1.5 text-center sm:text-left",t),...e});ng.displayName="DialogHeader";const rg=T.forwardRef(({className:t,...e},n)=>u.jsx(Vn,{ref:n,className:X("text-lg font-semibold leading-none tracking-tight",t),...e}));rg.displayName=Vn.displayName;const oI=T.forwardRef(({className:t,...e},n)=>u.jsx(ci,{ref:n,className:X("text-sm text-muted-foreground",t),...e}));oI.displayName=ci.displayName;function sI({isOpen:t,onClose:e,fileId:n,fileName:r,mimeType:a}){const[i,o]=y.useState(!1),[s,l]=y.useState(null),[c,d]=y.useState(null),{toast:_}=ts();y.useEffect(()=>{t&&n&&p()},[t,n]);const p=async()=>{if(n){o(!0),d(null),l(null);try{const S=await dm(n);l(S)}catch(S){console.error("Failed to load file:",S),d(S instanceof Error?S.message:"Failed to load file")}finally{o(!1)}}},m=async()=>{if(n)try{await YO(n),_({title:"Download started",description:`Downloading ${r}`})}catch(S){console.error("Failed to download file:",S),_({title:"Download failed",description:String(S),variant:"destructive"})}},E=async()=>{if(n)try{const S=await dm(n),b=new Blob([S],{type:a}),h=URL.createObjectURL(b);window.open(h,"_blank"),URL.revokeObjectURL(h)}catch(S){console.error("Failed to open file externally:",S),_({title:"Failed to open file",description:String(S),variant:"destructive"})}},f=()=>i?u.jsxs("div",{className:"flex items-center justify-center py-12",children:[u.jsx(me.Loader,{className:"h-8 w-8 animate-spin mr-3"}),u.jsx("span",{children:"Loading file..."})]}):c?u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx("div",{className:"text-red-500 mb-4",children:"⚠️"}),u.jsx("p",{className:"text-red-600 mb-4",children:c}),u.jsx(We,{onClick:p,variant:"outline",children:"Try Again"})]}):s?a.startsWith("image/")?u.jsx("div",{className:"flex justify-center",children:u.jsx("img",{src:`data:${a};base64,${s}`,alt:r,className:"max-w-full max-h-[70vh] object-contain rounded-lg"})}):a==="application/pdf"?u.jsx("div",{className:"w-full h-[70vh] border rounded-lg overflow-hidden",children:u.jsx("iframe",{src:`data:application/pdf;base64,${s}`,className:"w-full h-full",title:r})}):a.startsWith("text/")||a.includes("json")||a.includes("xml")?u.jsx("div",{className:"bg-gray-50 dark:bg-gray-900 rounded-lg p-4 max-h-[70vh] overflow-auto",children:u.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm",children:s})}):u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[u.jsx(me.FileText,{className:"h-16 w-16 text-gray-400 mb-4"}),u.jsx("p",{className:"text-lg font-medium mb-2",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:[a," • ",s.length," bytes"]}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"This file type cannot be previewed. Use download or external view."})]}):u.jsx("div",{className:"flex items-center justify-center py-12",children:u.jsx("p",{className:"text-muted-foreground",children:"No content to display"})}),g=()=>a.startsWith("image/")?u.jsx(me.Image,{className:"h-5 w-5"}):u.jsx(me.FileText,{className:"h-5 w-5"});return u.jsx(aI,{open:t,onOpenChange:e,children:u.jsxs(tg,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[u.jsx(ng,{children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-3",children:[g(),u.jsxs("div",{children:[u.jsx(rg,{className:"text-left",children:r}),u.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[a," • Click download or external view for full access"]})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(We,{variant:"outline",size:"sm",onClick:E,className:"flex items-center gap-2",children:[u.jsx(me.ExternalLink,{className:"h-4 w-4"}),"External"]}),u.jsxs(We,{variant:"outline",size:"sm",onClick:m,className:"flex items-center gap-2",children:[u.jsx(me.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),u.jsx("div",{className:"flex-1 overflow-hidden",children:f()})]})})}const di="prose prose-sm max-w-none break-words dark:prose-invert prose-headings:break-words prose-p:break-words prose-li:break-words prose-td:break-words prose-th:break-words prose-a:break-all prose-code:break-words prose-blockquote:break-words";function lI({className:t}){const[e,n]=y.useState(0);return y.useEffect(()=>{const r=setInterval(()=>n(a=>(a+1)%4),500);return()=>clearInterval(r)},[]),u.jsxs("span",{"aria-live":"polite",className:X("inline-block text-xs opacity-70 ml-1",t),children:["Is thinking",".".repeat(e)]})}const ag=y.memo(function({message:e,messageIndex:n,isStreamingMessage:r=!1,streamingDebounceMs:a=36,isEditing:i=!1,showActions:o=!0,showTimestamp:s=!0,showAgentName:l=!0,layoutSize:c="desktop",truncateToolMessages:d=!0,toolMessagePreviewLength:_=200,truncateUserMessages:p=!0,userMessagePreviewLength:m=200,customStyles:E={},onEdit:f,onRegenerate:g,onCancelEdit:S,onCopy:b}){const[h,N]=y.useState(!1),[C,R]=y.useState(!1),[v,O]=y.useState(!1),[A,w]=y.useState(!1),{currentThreadId:P}=ya();ts();const[q,$]=y.useState({}),[k,Q]=y.useState(!1),[x,B]=y.useState(null),M=c==="phone"||c==="half-screen",U=e.role,z=U==="tool",K=y.useMemo(()=>{switch(U){case"user":return"text-[hsl(var(--chat-bubble-user-text))]";case"assistant":return"text-[hsl(var(--chat-bubble-ai-text))]";case"tool":return"text-secondary-foreground";case"system":return"text-muted-foreground";default:return"text-[hsl(var(--chat-bubble-ai-text))]"}},[U]),Y=y.useMemo(()=>cI(e.content),[e.content]),F=y.useMemo(()=>mI(e.content),[e.content]),H=y.useMemo(()=>e.content.filter(Ee=>Ee.type==="image_url"),[e.content]),Z=y.useMemo(()=>e.content.filter(Ee=>Ee.type==="file"),[e.content]),ce=EI(Y,r),V=async()=>{try{const Ee=z?_r(e.content):Y;await navigator.clipboard.writeText(Ee),N(!0),setTimeout(()=>N(!1),2e3),b==null||b(Ee)}catch(Ee){console.error("Failed to copy:",Ee)}},L=()=>{if(!f)return;const Ee=z?_r(e.content):Y;f(e.id,Ee)},W=()=>g==null?void 0:g(n),ne=()=>{const Te=X(M?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",K);switch(U){case"user":return u.jsx(me.User,{className:Te});case"assistant":return u.jsx(me.Bot,{className:Te});case"tool":return u.jsx(me.Wrench,{className:Te});default:return u.jsx(me.Bot,{className:Te})}},se=()=>{const Ee="group relative mb-4 flex w-full";switch(U){case"user":return X(Ee,"justify-end");case"assistant":case"tool":case"system":return X(Ee,"justify-start");default:return Ee}},ie=()=>{const Ee=X("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",M&&"px-3 py-2 text-sm");switch(U){case"user":return X(Ee,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-user))] text-[hsl(var(--chat-bubble-user-text))]","border border-transparent");case"assistant":return X(Ee,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40");case"tool":return X(Ee,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return X(Ee,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return X(Ee,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40")}},be=Ee=>{if(!Ee)return"";try{return new Date(Ee).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return""}},Fe=()=>{if(e.model==="reflection"){const J=Y.trim(),ve=Es(J);if(ve&&typeof ve=="object")return u.jsx(fI,{data:ve})}if(z&&F.name==="get_issues"){const J=e.content.find(Oe=>Oe.type==="tool_result"),ve=(J==null?void 0:J.output)??_r(e.content),Ne=sg(ve);if(Ne)return u.jsx(SI,{issues:Ne})}if(z&&!v){const J=_r(e.content).slice(0,80).replace(/\s+/g," ");return u.jsx("div",{className:X("text-xs font-mono opacity-70 flex items-center justify-between gap-2 text-current",M&&"text-[10px]"),children:u.jsxs("span",{className:"truncate max-w-full text-current",children:[J,J.length>=80?"…":""]})})}if(z&&d){const J=_r(e.content),ve=J.length>_;return u.jsx(rm,{open:C,onOpenChange:R,children:u.jsxs("div",{className:"font-mono text-sm text-current",children:[u.jsx("pre",{className:X("whitespace-pre-wrap break-words text-current",M&&"text-xs"),children:ve&&!C?J.substring(0,_)+"...":J}),ve&&u.jsx(am,{asChild:!0,children:u.jsx(We,{variant:"ghost",size:"sm",className:"h-6 text-xs text-current",children:C?u.jsxs(u.Fragment,{children:[u.jsx(me.ChevronUp,{className:"h-3 w-3 mr-1"}),"Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(me.ChevronDown,{className:"h-3 w-3 mr-1"}),"Show more (",J.length-_," chars)"]})})})]})})}if(z&&v&&!d){const J=bI(e.content);if(J&&dI(J))return u.jsx($a,{content:J.trim(),hideFallbackDuringStreaming:!0});const ve=_r(e.content);return u.jsx("div",{className:"font-mono text-sm text-current",children:u.jsx("pre",{className:X("whitespace-pre-wrap break-words text-current",M&&"text-xs"),children:ve})})}const Ee=H.length>0&&U!=="tool",Te=Z.length>0&&U!=="tool"&&!1;return u.jsxs("div",{children:[r?u.jsxs("div",{className:X("relative transition-all duration-200 ease-out",M?"text-xs":"text-sm"),style:{minHeight:80},children:[(()=>{const J=Es(ce);if(J!==null)return u.jsx(ig,{data:J});const ve=_I(uI(ce)),Ne=ce.trim().length===0;return u.jsx(u.Fragment,{children:Ne?u.jsx("div",{className:"w-full",children:u.jsxs("div",{className:"animate-pulse space-y-2",children:[u.jsx("div",{className:"h-3 bg-slate-200 dark:bg-slate-700 rounded w-3/4"}),u.jsx("div",{className:"h-3 bg-slate-200 dark:bg-slate-700 rounded w-5/6"}),u.jsx("div",{className:"h-3 bg-slate-200 dark:bg-slate-700 rounded w-2/3"})]})}):u.jsx("pre",{className:X("whitespace-pre-wrap break-words font-sans leading-relaxed transition-opacity duration-200",M&&"text-xs"),children:ve})})})(),u.jsx("div",{className:"mt-2",children:u.jsx(lI,{className:X(K,M?"text-xs":"text-sm")})})]}):(()=>{const J=Es(Y.trim());if(J!==null)return u.jsx(ig,{data:J});if(U==="user"&&p){const ve=Y.trim();if(ve.length>m)return u.jsxs(rm,{open:A,onOpenChange:w,children:[u.jsx("div",{className:X("text-sm text-[hsl(var(--chat-bubble-user-text))]",M&&"text-xs"),children:A?u.jsx($a,{content:ve,hideFallbackDuringStreaming:!0}):u.jsxs("pre",{className:X("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",M&&"text-xs"),children:[ve.substring(0,m),"..."]})}),u.jsx(am,{asChild:!0,children:u.jsx(We,{variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",children:A?u.jsxs(u.Fragment,{children:[u.jsx(me.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(me.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",ve.length-m," chars)"]})})})]})}return u.jsx($a,{content:Y.trim(),isStreaming:r,hideFallbackDuringStreaming:!0,streamingThrottleMs:a})})(),Ee&&u.jsx("div",{className:"mt-2 grid grid-cols-2 gap-2",children:H.map((J,ve)=>{const Ne=J,Oe=typeof Ne.width=="number"?Ne.width:void 0,je=typeof Ne.height=="number"?Ne.height:void 0,it=Oe&&je&&je>0?`${Oe} / ${je}`:"4 / 3",ee=Oe&&je&&je>0?Math.max(120,Math.round(je/Oe*140)):160;return u.jsxs("div",{className:"relative border rounded overflow-hidden bg-gray-100 dark:bg-gray-900/40",style:{aspectRatio:it,minHeight:ee},"data-placeholder-height":ee,children:[u.jsx("img",{src:Ne.url,alt:Ne.alt??"image",loading:"lazy",className:"absolute inset-0 h-full w-full object-contain"}),u.jsxs("div",{className:"absolute top-1 right-1 bg-background/70 rounded px-1 py-0.5 text-[10px] flex items-center gap-1",children:[u.jsx(me.Image,{className:"h-3 w-3"}),u.jsx("span",{children:"image"})]})]},ve)})}),Te]})},Ae=y.useMemo(()=>gI(e),[e]);return u.jsxs(u.Fragment,{children:[u.jsx("div",{className:X(se(),E.container),children:u.jsxs("div",{className:X(ie(),E.content),children:[(s||l||z)&&u.jsxs("div",{className:X("flex items-center justify-between mb-2 pb-2 border-b border-current/10",M&&"mb-1 pb-1",K,E.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[ne(),l&&Ae&&u.jsx("span",{className:X("font-medium",M?"text-xs":"text-sm"),children:Ae}),z&&F.name&&u.jsxs(Xp,{variant:"outline",className:X("text-xs flex items-center gap-1 cursor-pointer",K,"border border-current/40",M&&"text-xs h-4"),onClick:()=>O(Ee=>!Ee),children:[u.jsx("span",{children:F.name}),u.jsx("span",{className:"inline-flex items-center",children:v?u.jsx(me.ChevronUp,{className:"h-3 w-3"}):u.jsx(me.ChevronDown,{className:"h-3 w-3"})})]}),z&&!F.name&&u.jsx(We,{variant:"ghost",size:"sm",className:X("h-6 px-1",K,"hover:bg-foreground/10"),onClick:()=>O(Ee=>!Ee),children:u.jsxs("span",{className:"text-xs flex items-center gap-1",children:["Tool Output ",v?u.jsx(me.ChevronUp,{className:"h-3 w-3"}):u.jsx(me.ChevronDown,{className:"h-3 w-3"})]})})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[s&&u.jsx("span",{className:X("text-xs opacity-60",K,M&&"text-xs"),children:be(e.createdAt)}),o&&!i&&u.jsxs("div",{className:X("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",E.actions),children:[u.jsx(We,{variant:"ghost",size:"sm",onClick:V,className:X("h-6 w-6 p-0 hover:bg-foreground/10",K,M&&"h-5 w-5"),children:u.jsx(me.Copy,{className:X(h?"text-success":K,M?"h-3 w-3":"h-4 w-4")})}),U==="user"&&f&&u.jsx(We,{variant:"ghost",size:"sm",onClick:L,className:X("h-6 w-6 p-0 hover:bg-foreground/10",K,M&&"h-5 w-5"),children:u.jsx(me.Edit,{className:X(K,M?"h-3 w-3":"h-4 w-4")})}),U==="assistant"&&g&&u.jsx(We,{variant:"ghost",size:"sm",onClick:W,className:X("h-6 w-6 p-0 hover:bg-foreground/10",K,M&&"h-5 w-5"),children:u.jsx(me.RotateCcw,{className:X(K,M?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsx("div",{className:"relative",children:Fe()}),z&&v&&(F.toolCallId||F.name)&&u.jsxs("div",{className:X("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",M&&"text-xs"),children:[F.name&&u.jsxs("div",{children:["Function: ",F.name]}),F.toolCallId&&u.jsxs("div",{children:["Call ID: ",F.toolCallId]})]}),!(s||l||z)&&o&&!i&&u.jsxs("div",{className:X("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",E.actions),children:[u.jsx(We,{variant:"ghost",size:"sm",onClick:V,className:X("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(me.Copy,{className:X(h?"text-success":"text-current",M?"h-3 w-3":"h-4 w-4")})}),U==="user"&&f&&u.jsx(We,{variant:"ghost",size:"sm",onClick:L,className:X("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(me.Edit,{className:X("text-current",M?"h-3 w-3":"h-4 w-4")})}),U==="assistant"&&g&&u.jsx(We,{variant:"ghost",size:"sm",onClick:W,className:X("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(me.RotateCcw,{className:X("text-current",M?"h-3 w-3":"h-4 w-4")})})]})]})}),x&&u.jsx(sI,{isOpen:k,onClose:()=>{Q(!1),B(null)},fileId:x.id,fileName:x.name,mimeType:x.mimeType})]})},(t,e)=>e.isStreamingMessage?!1:t.message.id===e.message.id&&t.message.content===e.message.content&&t.isStreamingMessage===e.isStreamingMessage&&t.isEditing===e.isEditing);function cI(t){const e=t.filter(n=>n.type==="text").map(n=>n.text).join("");return e||JSON.stringify(t)}function dI(t){return t.includes(`
|
|
78
|
-
`)||t.includes("```")||/[-*] /.test(t)||/#+\s/.test(t)}function uI(t){let e=t;try{(e.match(/```/g)||[]).length%2===1&&(e+="\n```"),(e.replace(/```[\s\S]*?```/g,"").match(new RegExp("(?<!`)`(?!`)","g"))||[]).length%2===1&&(e+="`")}catch{}return e}function _I(t){let e=t;try{const n=[],r=[],a="\0F",i="\0I";let o=e.replace(/```[\s\S]*?```/g,s=>(n.push(s),`${a}${n.length-1}\0`));o=o.replace(/`[^`]*`/g,s=>(r.push(s),`${i}${r.length-1}\0`)),o=o.replace(/\b([A-Za-z0-9_&\/-]+)\b(\s+\1\b)+/g,"$1").replace(/\b([A-Za-z0-9_&\/-]+\s+[A-Za-z0-9_&\/-]+)\b(\s+\1\b)+/g,"$1").replace(/([\.,;:!\?\-])\1+/g,"$1").replace(/([:;!\?\)])([A-Za-z])/g,"$1 $2").replace(/\s{3,}/g," "),o=o.replace(/\u0000F(\d+)\u0000/g,(s,l)=>n[Number(l)]??""),o=o.replace(/\u0000I(\d+)\u0000/g,(s,l)=>r[Number(l)]??""),e=o}catch{}return e}function Es(t){const e=t==null?void 0:t.trim();if(!e||!(e.startsWith("{")||e.startsWith("[")))return null;try{return JSON.parse(e)}catch{return null}}function ig({data:t}){if(Array.isArray(t))return t.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:di,children:u.jsx("ul",{className:"list-disc pl-5",children:t.map((n,r)=>u.jsx("li",{children:String(n)},r))})}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:jr(t)});if(t&&typeof t=="object"){const e=Array.isArray(t.distilled_facts)?t.distilled_facts:null,n=Array.isArray(t.follow_up_queries)?t.follow_up_queries:null,r=typeof t.is_sufficient=="boolean"?t.is_sufficient:void 0;if(e||n||typeof r=="boolean")return u.jsxs("div",{className:di,children:[typeof r=="boolean"&&u.jsxs("p",{children:[u.jsx("strong",{children:"Is sufficient:"})," ",r?"Yes":"No"]}),n&&n.length>0&&u.jsxs("div",{children:[u.jsx("p",{children:u.jsx("strong",{children:"Follow-up queries:"})}),u.jsx("ul",{className:"list-disc pl-5",children:n.map((i,o)=>u.jsx("li",{children:String(i)},o))})]}),e&&e.length>0&&u.jsxs("div",{children:[u.jsx("p",{children:u.jsx("strong",{children:"Facts:"})}),u.jsx("ul",{className:"list-disc pl-5",children:e.map((i,o)=>u.jsx("li",{children:String(i)},o))})]})]});const a=Object.entries(t);return u.jsx("div",{className:di,children:u.jsx("dl",{className:"mt-0",children:a.map(([i,o])=>u.jsxs("div",{className:"mb-1",children:[u.jsxs("dt",{className:"inline font-medium mr-1",children:[i,":"]}),u.jsx("dd",{className:"inline",children:pI(o)})]},i))})})}return u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:jr(t)})}function pI(t){if(t==null)return String(t);const e=typeof t;if(e==="string"||e==="number"||e==="boolean")return String(t);if(Array.isArray(t)&&t.every(r=>r===null||["string","number","boolean"].includes(typeof r)))return t.join(", ");try{return u.jsx("code",{className:"text-xs",children:JSON.stringify(ui(t))})}catch{return String(t)}}function og(t){return!!(t&&typeof t=="object"&&(t.type==="file"||t.mimeType||t.filename||t.sourceType==="base64"))}function ui(t){if(typeof t=="string")return t.length>2e3?t.slice(0,2e3)+"... [truncated]":t;if(t&&typeof t=="object"){if(Array.isArray(t)){const n=t.map(ui).filter(r=>r!==void 0);return n.length?n:void 0}if(og(t))return;const e={};for(const n of Object.keys(t)){const r=t[n];if(n==="data"&&typeof r=="string"&&r.length>100)e[n]=`[base64 ${r.length} chars omitted]`;else{const a=ui(r);a!==void 0&&(e[n]=a)}}return Object.keys(e).length?e:void 0}return t}function jr(t){if(typeof t=="string")return t;if(og(t))return"";try{const e=ui(t);return e===void 0?"":typeof e=="string"?e:JSON.stringify(e,null,2)}catch{return""}}function mI(t){const e=t.find(r=>r.type==="tool_call"),n=t.find(r=>r.type==="tool_result");return{name:e==null?void 0:e.name,toolCallId:(n==null?void 0:n.toolCallId)??(e==null?void 0:e.id)}}function gI(t){return t.name&&t.name.trim()?t.name:t.model&&t.model.includes("/")?t.model.split("/").pop()||null:t.model||null}function EI(t,e){const[n,r]=y.useState(t),a=y.useRef(t),i=y.useRef(null);return y.useEffect(()=>{if(!e){r(t);return}return a.current=t,i.current===null&&(i.current=requestAnimationFrame(()=>{i.current=null,r(a.current)})),()=>{i.current&&cancelAnimationFrame(i.current)}},[t,e]),n}function fI({data:t}){return u.jsx("dl",{className:"grid grid-cols-1 gap-y-2",children:Object.entries(t).map(([e,n])=>u.jsxs("div",{className:"flex",children:[u.jsxs("dt",{className:"font-semibold mr-2",children:[e,":"]}),u.jsx("dd",{className:"flex-1 break-words",children:Array.isArray(n)?n.map((r,a)=>u.jsxs("div",{className:"ml-4 break-words",children:["- ",String(r)]},a)):String(n)})]},e))})}function sg(t){if(!t)return null;if(typeof t=="object"&&!Array.isArray(t)){if(t.desirability||t.feasibility||t.viability||t.other)return{desirability:Array.isArray(t.desirability)?t.desirability:[],feasibility:Array.isArray(t.feasibility)?t.feasibility:[],viability:Array.isArray(t.viability)?t.viability:[],other:Array.isArray(t.other)?t.other:[]};if(t.output&&typeof t.output!="object")t=t.output;else if(t.output&&typeof t.output=="object")return sg(t.output)}const e=String(t),n={desirability:[],feasibility:[],viability:[],other:[]};let r=e;const a=Math.min(...["desirability=","feasibility=","viability=","other="].map(o=>{const s=r.toLowerCase().indexOf(o);return s===-1?Number.MAX_SAFE_INTEGER:s}));a!==Number.MAX_SAFE_INTEGER&&(r=r.slice(a));for(const o of Object.keys(n)){const l=new RegExp(o+"\\s*=\\s*\\[([\\s\\S]*?)\\]","i").exec(r);if(!l)continue;const c=l[1],d=/Issue\(([\s\S]*?)\)(?:,|$)/g;let _=null;for(;(_=d.exec(c))!==null;){const p=_[1],m=/title\s*=\s*(['"])([\s\S]*?)\1/.exec(p),E=/description\s*=\s*(['"])([\s\S]*?)\1/.exec(p),f=m?m[2].trim():"",g=E?E[2].trim():"";n[o].push({title:f,description:g})}}return Object.values(n).some(o=>o.length>0)?n:null}function SI({issues:t}){const e=[{key:"desirability",title:"Desirability"},{key:"feasibility",title:"Feasibility"},{key:"viability",title:"Viability"},{key:"other",title:"Other"}];return u.jsx("div",{className:di,children:e.map(n=>{const r=t[n.key];return!r||!r.length?null:u.jsxs("div",{className:"mb-4",children:[u.jsxs("h4",{className:"font-semibold mb-2",children:[n.title," (",r.length,")"]}),u.jsx("ol",{className:"list-decimal pl-5 space-y-2",children:r.map((a,i)=>u.jsxs("li",{children:[u.jsx("div",{className:"font-medium",children:a.title}),u.jsx("div",{className:"text-sm text-muted-foreground",children:a.description})]},i))})]},n.key)})})}function _r(t){const e=t.filter(n=>n.type==="tool_result");if(e.length)try{return e.length===1?jr(e[0].output):jr(e.map(n=>({toolCallId:n.toolCallId,output:n.output})))}catch{}return jr(t)}function bI(t){const e=t.find(r=>r.type==="tool_result");if(!e)return null;const n=e.output;return typeof n=="string"?n:null}const fs=(t,e)=>(t==null?void 0:t.id)??`message-${e}`,Ss=y.forwardRef(({messages:t,isStreaming:e,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:a,enableMessageEditing:i,editingMessageId:o,onStartReached:s,onEdit:l,onRegenerate:c,onCancelEdit:d,className:_,style:p,emptyMessage:m,followNewMessages:E=!0,isNavigatingCheckpoint:f=!1,onScrollAway:g,onAtBottom:S},b)=>{const h=y.useRef(null),N=y.useRef(null),C=y.useRef(!1),R=y.useRef(null),v=y.useRef(null),O=y.useRef(null),A=y.useRef(!0),w=y.useRef(null),P=y.useRef(t.length),q=y.useCallback(Y=>{const F=N.current;if(!F)return null;const H=F.querySelectorAll("[data-message-id]");for(const Z of Array.from(H))if(Z.dataset.messageId===Y)return Z;return null},[]),$=y.useCallback(Y=>{var W;const F=N.current;if(!F)return null;const H=Y??((W=O.current)==null?void 0:W.id)??null;if(!H)return null;const Z=q(H);if(!Z)return null;const ce=F.getBoundingClientRect(),V=Z.getBoundingClientRect(),L={anchorId:H,anchorOffset:V.top-ce.top};return v.current=L,L},[q]),k=y.useCallback((Y,F)=>{var ne,se;const H=N.current;if(!H)return!1;const Z=q(Y);if(!Z)return!1;const ce=H.getBoundingClientRect(),L=Z.getBoundingClientRect().top-ce.top,W=F-L;if(Math.abs(W)>.5){const ie=H.style.scrollBehavior;H.style.scrollBehavior="auto";try{(se=(ne=h.current)==null?void 0:ne.scrollBy)==null||se.call(ne,{top:W,behavior:"auto"})}finally{ie?H.style.scrollBehavior=ie:H.style.removeProperty("scroll-behavior")}}return v.current={anchorId:Y,anchorOffset:F},!0},[q]),Q=y.useCallback(Y=>{const F=A.current;A.current=Y,g&&g(!Y),S&&S(Y),Y&&!F&&requestAnimationFrame(()=>{$()})},[$,g,S]),x=y.useCallback(Y=>{const F=Math.max(0,Y.startIndex),H=t[F];if(!H){O.current=null;return}const Z=fs(H,F);O.current={index:F,id:Z},requestAnimationFrame(()=>{$(Z)})},[$,t]),B=y.useMemo(()=>{if(s)return async()=>{if(C.current)return;const Y=$();Y?R.current={anchorId:Y.anchorId,anchorOffset:Y.anchorOffset,prevLength:t.length,attempts:0}:R.current=null,C.current=!0;try{await s()}finally{C.current=!1}}},[$,t.length,s]);y.useEffect(()=>{if(!R.current||t.length<=R.current.prevLength)return;let Y=!1;const F=()=>{if(Y)return;const H=R.current;if(!H)return;k(H.anchorId,H.anchorOffset)?R.current=null:H.attempts<6?(H.attempts+=1,requestAnimationFrame(F)):R.current=null};return requestAnimationFrame(F),()=>{Y=!0}},[t.length,k]),y.useLayoutEffect(()=>{C.current||requestAnimationFrame(()=>{$()})},[$,t]),y.useEffect(()=>{P.current;const Y=t.length;P.current=Y},[t.length]),y.useEffect(()=>{if(typeof ResizeObserver>"u")return;const Y=N.current;if(!Y)return;const F=()=>{w.current!==null&&(cancelAnimationFrame(w.current),w.current=null)},H=new ResizeObserver(()=>{if(R.current||f||!A.current&&!e)return;const ce=v.current;F(),w.current=requestAnimationFrame(()=>{e&&A.current&&A.current||(!e&&ce&&A.current&&A.current&&k(ce.anchorId,ce.anchorOffset),w.current=null)})}),Z=Y.firstElementChild;return Z&&H.observe(Z),()=>{F(),H.disconnect()}},[k,e]);const U=e&&E&&A.current&&!f&&A.current?"smooth":!1,z=y.useMemo(()=>{if(!(C.current||t.length===0))return Math.max(0,t.length-1)},[]),K={overflowAnchor:"none",willChange:e?"scroll-position":"auto",overscrollBehavior:"contain",contain:"layout style paint"};return t.length===0?u.jsx("div",{className:_,style:p,children:u.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-center max-w-md mx-auto",children:m||"No messages yet. Start a conversation!"})}):u.jsx("div",{className:_,style:p,children:u.jsx(eO,{ref:Y=>{h.current=Y},scrollerRef:Y=>{N.current=Y instanceof HTMLDivElement?Y:null},data:t,followOutput:U,initialTopMostItemIndex:z,overscan:{main:300,reverse:300},increaseViewportBy:{top:600,bottom:600},defaultItemHeight:100,atBottomThreshold:100,alignToBottom:!0,startReached:()=>{B&&B()},atBottomStateChange:Q,rangeChanged:x,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(Y,F)=>fs(F,Y),components:{Scroller:y.forwardRef((Y,F)=>u.jsx("div",{...Y,ref:F,style:{...K,...(Y==null?void 0:Y.style)??{}}}))},itemContent:(Y,F)=>{const H=F.role==="user"&&Y===t.length-1,Z=e&&n===F.id||H&&e,ce=fs(F,Y);return u.jsx("div",{className:"mb-4 last:mb-0","data-message-id":ce,style:{contentVisibility:"auto",minHeight:Z?120:void 0,containIntrinsicSize:Z?"auto 120px":"auto 150px",transform:"translateZ(0)",isolation:"isolate"},children:u.jsx(ag,{message:F,messageIndex:Y,isStreamingMessage:e&&n===F.id,streamingDebounceMs:r,isEditing:o===F.id,showActions:i,showTimestamp:!1,showAgentName:!0,layoutSize:a,truncateToolMessages:!1,toolMessagePreviewLength:200,onEdit:l,onRegenerate:()=>c(Y),onCancelEdit:d},F.id??`msg-${F.role}-${Y}-${F.createdAt??""}`)})}})})});Ss.displayName="MessageList";const _i=1e4;function TI(t){if(typeof t!="string")return String(t);const e=[/<script[^>]*>.*?<\/script>/gi,/<iframe[^>]*>.*?<\/iframe>/gi,/javascript:/gi,/vbscript:/gi,/on\w+\s*=/gi,/<object[^>]*>.*?<\/object>/gi,/<embed[^>]*>.*?<\/embed>/gi,/<form[^>]*>.*?<\/form>/gi];let n=t;for(const a of e)n=n.replace(a,"");return/<[^>]+>/.test(n)&&!/<(?!\/?(?:code|strong|em|b|i|br|p|ul|ol|li|h[1-6])\b)[^>]+>/i.test(n)?n.replace(/<code>(.*?)<\/code>/gi,"`$1`").replace(/<strong>(.*?)<\/strong>/gi,"**$1**").replace(/<b>(.*?)<\/b>/gi,"**$1**").replace(/<em>(.*?)<\/em>/gi,"*$1*").replace(/<i>(.*?)<\/i>/gi,"*$1*").replace(/<br\s*\/?>/gi,`
|
|
78
|
+
`)||t.includes("```")||/[-*] /.test(t)||/#+\s/.test(t)}function uI(t){let e=t;try{(e.match(/```/g)||[]).length%2===1&&(e+="\n```"),(e.replace(/```[\s\S]*?```/g,"").match(new RegExp("(?<!`)`(?!`)","g"))||[]).length%2===1&&(e+="`")}catch{}return e}function _I(t){let e=t;try{const n=[],r=[],a="\0F",i="\0I";let o=e.replace(/```[\s\S]*?```/g,s=>(n.push(s),`${a}${n.length-1}\0`));o=o.replace(/`[^`]*`/g,s=>(r.push(s),`${i}${r.length-1}\0`)),o=o.replace(/\b([A-Za-z0-9_&\/-]+)\b(\s+\1\b)+/g,"$1").replace(/\b([A-Za-z0-9_&\/-]+\s+[A-Za-z0-9_&\/-]+)\b(\s+\1\b)+/g,"$1").replace(/([\.,;:!\?\-])\1+/g,"$1").replace(/([:;!\?\)])([A-Za-z])/g,"$1 $2").replace(/\s{3,}/g," "),o=o.replace(/\u0000F(\d+)\u0000/g,(s,l)=>n[Number(l)]??""),o=o.replace(/\u0000I(\d+)\u0000/g,(s,l)=>r[Number(l)]??""),e=o}catch{}return e}function Es(t){const e=t==null?void 0:t.trim();if(!e||!(e.startsWith("{")||e.startsWith("[")))return null;try{return JSON.parse(e)}catch{return null}}function ig({data:t}){if(Array.isArray(t))return t.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:di,children:u.jsx("ul",{className:"list-disc pl-5",children:t.map((n,r)=>u.jsx("li",{children:String(n)},r))})}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:jr(t)});if(t&&typeof t=="object"){const e=Array.isArray(t.distilled_facts)?t.distilled_facts:null,n=Array.isArray(t.follow_up_queries)?t.follow_up_queries:null,r=typeof t.is_sufficient=="boolean"?t.is_sufficient:void 0;if(e||n||typeof r=="boolean")return u.jsxs("div",{className:di,children:[typeof r=="boolean"&&u.jsxs("p",{children:[u.jsx("strong",{children:"Is sufficient:"})," ",r?"Yes":"No"]}),n&&n.length>0&&u.jsxs("div",{children:[u.jsx("p",{children:u.jsx("strong",{children:"Follow-up queries:"})}),u.jsx("ul",{className:"list-disc pl-5",children:n.map((i,o)=>u.jsx("li",{children:String(i)},o))})]}),e&&e.length>0&&u.jsxs("div",{children:[u.jsx("p",{children:u.jsx("strong",{children:"Facts:"})}),u.jsx("ul",{className:"list-disc pl-5",children:e.map((i,o)=>u.jsx("li",{children:String(i)},o))})]})]});const a=Object.entries(t);return u.jsx("div",{className:di,children:u.jsx("dl",{className:"mt-0",children:a.map(([i,o])=>u.jsxs("div",{className:"mb-1",children:[u.jsxs("dt",{className:"inline font-medium mr-1",children:[i,":"]}),u.jsx("dd",{className:"inline",children:pI(o)})]},i))})})}return u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:jr(t)})}function pI(t){if(t==null)return String(t);const e=typeof t;if(e==="string"||e==="number"||e==="boolean")return String(t);if(Array.isArray(t)&&t.every(r=>r===null||["string","number","boolean"].includes(typeof r)))return t.join(", ");try{return u.jsx("code",{className:"text-xs",children:JSON.stringify(ui(t))})}catch{return String(t)}}function og(t){return!!(t&&typeof t=="object"&&(t.type==="file"||t.mimeType||t.filename||t.sourceType==="base64"))}function ui(t){if(typeof t=="string")return t.length>2e3?t.slice(0,2e3)+"... [truncated]":t;if(t&&typeof t=="object"){if(Array.isArray(t)){const n=t.map(ui).filter(r=>r!==void 0);return n.length?n:void 0}if(og(t))return;const e={};for(const n of Object.keys(t)){const r=t[n];if(n==="data"&&typeof r=="string"&&r.length>100)e[n]=`[base64 ${r.length} chars omitted]`;else{const a=ui(r);a!==void 0&&(e[n]=a)}}return Object.keys(e).length?e:void 0}return t}function jr(t){if(typeof t=="string")return t;if(og(t))return"";try{const e=ui(t);return e===void 0?"":typeof e=="string"?e:JSON.stringify(e,null,2)}catch{return""}}function mI(t){const e=t.find(r=>r.type==="tool_call"),n=t.find(r=>r.type==="tool_result");return{name:e==null?void 0:e.name,toolCallId:(n==null?void 0:n.toolCallId)??(e==null?void 0:e.id)}}function gI(t){return t.name&&t.name.trim()?t.name:t.model&&t.model.includes("/")?t.model.split("/").pop()||null:t.model||null}function EI(t,e){const[n,r]=y.useState(t),a=y.useRef(t),i=y.useRef(null);return y.useEffect(()=>{if(!e){r(t);return}return a.current=t,i.current===null&&(i.current=requestAnimationFrame(()=>{i.current=null,r(a.current)})),()=>{i.current&&cancelAnimationFrame(i.current)}},[t,e]),n}function fI({data:t}){return u.jsx("dl",{className:"grid grid-cols-1 gap-y-2",children:Object.entries(t).map(([e,n])=>u.jsxs("div",{className:"flex",children:[u.jsxs("dt",{className:"font-semibold mr-2",children:[e,":"]}),u.jsx("dd",{className:"flex-1 break-words",children:Array.isArray(n)?n.map((r,a)=>u.jsxs("div",{className:"ml-4 break-words",children:["- ",String(r)]},a)):String(n)})]},e))})}function sg(t){if(!t)return null;if(typeof t=="object"&&!Array.isArray(t)){if(t.desirability||t.feasibility||t.viability||t.other)return{desirability:Array.isArray(t.desirability)?t.desirability:[],feasibility:Array.isArray(t.feasibility)?t.feasibility:[],viability:Array.isArray(t.viability)?t.viability:[],other:Array.isArray(t.other)?t.other:[]};if(t.output&&typeof t.output!="object")t=t.output;else if(t.output&&typeof t.output=="object")return sg(t.output)}const e=String(t),n={desirability:[],feasibility:[],viability:[],other:[]};let r=e;const a=Math.min(...["desirability=","feasibility=","viability=","other="].map(o=>{const s=r.toLowerCase().indexOf(o);return s===-1?Number.MAX_SAFE_INTEGER:s}));a!==Number.MAX_SAFE_INTEGER&&(r=r.slice(a));for(const o of Object.keys(n)){const l=new RegExp(o+"\\s*=\\s*\\[([\\s\\S]*?)\\]","i").exec(r);if(!l)continue;const c=l[1],d=/Issue\(([\s\S]*?)\)(?:,|$)/g;let _=null;for(;(_=d.exec(c))!==null;){const p=_[1],m=/title\s*=\s*(['"])([\s\S]*?)\1/.exec(p),E=/description\s*=\s*(['"])([\s\S]*?)\1/.exec(p),f=m?m[2].trim():"",g=E?E[2].trim():"";n[o].push({title:f,description:g})}}return Object.values(n).some(o=>o.length>0)?n:null}function SI({issues:t}){const e=[{key:"desirability",title:"Desirability"},{key:"feasibility",title:"Feasibility"},{key:"viability",title:"Viability"},{key:"other",title:"Other"}];return u.jsx("div",{className:di,children:e.map(n=>{const r=t[n.key];return!r||!r.length?null:u.jsxs("div",{className:"mb-4",children:[u.jsxs("h4",{className:"font-semibold mb-2",children:[n.title," (",r.length,")"]}),u.jsx("ol",{className:"list-decimal pl-5 space-y-2",children:r.map((a,i)=>u.jsxs("li",{children:[u.jsx("div",{className:"font-medium",children:a.title}),u.jsx("div",{className:"text-sm text-muted-foreground",children:a.description})]},i))})]},n.key)})})}function _r(t){const e=t.filter(n=>n.type==="tool_result");if(e.length)try{return e.length===1?jr(e[0].output):jr(e.map(n=>({toolCallId:n.toolCallId,output:n.output})))}catch{}return jr(t)}function bI(t){const e=t.find(r=>r.type==="tool_result");if(!e)return null;const n=e.output;return typeof n=="string"?n:null}const fs=(t,e)=>(t==null?void 0:t.id)??`message-${e}`,Ss=y.forwardRef(({messages:t,isStreaming:e,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:a,enableMessageEditing:i,editingMessageId:o,onStartReached:s,onEdit:l,onRegenerate:c,onCancelEdit:d,className:_,style:p,emptyMessage:m,followNewMessages:E=!0,isNavigatingCheckpoint:f=!1,onScrollAway:g,onAtBottom:S},b)=>{const h=y.useRef(null),N=y.useRef(null),C=y.useRef(!1),R=y.useRef(null),v=y.useRef(null),O=y.useRef(null),A=y.useRef(!0),w=y.useRef(null),P=y.useRef(t.length),q=y.useCallback(Y=>{const F=N.current;if(!F)return null;const H=F.querySelectorAll("[data-message-id]");for(const Z of Array.from(H))if(Z.dataset.messageId===Y)return Z;return null},[]),$=y.useCallback(Y=>{var W;const F=N.current;if(!F)return null;const H=Y??((W=O.current)==null?void 0:W.id)??null;if(!H)return null;const Z=q(H);if(!Z)return null;const ce=F.getBoundingClientRect(),V=Z.getBoundingClientRect(),L={anchorId:H,anchorOffset:V.top-ce.top};return v.current=L,L},[q]),k=y.useCallback((Y,F)=>{var ne,se;const H=N.current;if(!H)return!1;const Z=q(Y);if(!Z)return!1;const ce=H.getBoundingClientRect(),L=Z.getBoundingClientRect().top-ce.top,W=F-L;if(Math.abs(W)>.5){const ie=H.style.scrollBehavior;H.style.scrollBehavior="auto";try{(se=(ne=h.current)==null?void 0:ne.scrollBy)==null||se.call(ne,{top:W,behavior:"auto"})}finally{ie?H.style.scrollBehavior=ie:H.style.removeProperty("scroll-behavior")}}return v.current={anchorId:Y,anchorOffset:F},!0},[q]),Q=y.useCallback(Y=>{const F=A.current;A.current=Y,g&&g(!Y),S&&S(Y),Y&&!F&&requestAnimationFrame(()=>{$()})},[$,g,S]),x=y.useCallback(Y=>{const F=Math.max(0,Y.startIndex),H=t[F];if(!H){O.current=null;return}const Z=fs(H,F);O.current={index:F,id:Z},requestAnimationFrame(()=>{$(Z)})},[$,t]),B=y.useMemo(()=>{if(s)return async()=>{if(C.current)return;const Y=$();Y?R.current={anchorId:Y.anchorId,anchorOffset:Y.anchorOffset,prevLength:t.length,attempts:0}:R.current=null,C.current=!0;try{await s()}finally{C.current=!1}}},[$,t.length,s]);y.useEffect(()=>{if(!R.current||t.length<=R.current.prevLength)return;let Y=!1;const F=()=>{if(Y)return;const H=R.current;if(!H)return;k(H.anchorId,H.anchorOffset)?R.current=null:H.attempts<6?(H.attempts+=1,requestAnimationFrame(F)):R.current=null};return requestAnimationFrame(F),()=>{Y=!0}},[t.length,k]),y.useLayoutEffect(()=>{C.current||requestAnimationFrame(()=>{$()})},[$,t]),y.useEffect(()=>{P.current;const Y=t.length;P.current=Y},[t.length]),y.useEffect(()=>{if(typeof ResizeObserver>"u")return;const Y=N.current;if(!Y)return;const F=()=>{w.current!==null&&(cancelAnimationFrame(w.current),w.current=null)},H=new ResizeObserver(()=>{if(R.current||f||!A.current&&!e)return;const ce=v.current;F(),w.current=requestAnimationFrame(()=>{e&&A.current&&A.current||(!e&&ce&&A.current&&A.current&&k(ce.anchorId,ce.anchorOffset),w.current=null)})}),Z=Y.firstElementChild;return Z&&H.observe(Z),()=>{F(),H.disconnect()}},[k,e]);const U=e&&E&&A.current&&!f&&A.current?"smooth":!1,z=y.useMemo(()=>{if(!(C.current||t.length===0))return t.length-1},[t.length]),K={overflowAnchor:"none",willChange:e?"scroll-position":"auto",overscrollBehavior:"contain",contain:"layout style paint"};return t.length===0?u.jsx("div",{className:_,style:p,children:u.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-center max-w-md mx-auto",children:m||"No messages yet. Start a conversation!"})}):u.jsx("div",{className:_,style:p,children:u.jsx(eO,{ref:Y=>{h.current=Y},scrollerRef:Y=>{N.current=Y instanceof HTMLDivElement?Y:null},data:t,followOutput:U,initialTopMostItemIndex:z,overscan:{main:300,reverse:300},increaseViewportBy:{top:600,bottom:600},defaultItemHeight:100,atBottomThreshold:100,alignToBottom:!0,startReached:()=>{B&&B()},atBottomStateChange:Q,rangeChanged:x,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(Y,F)=>fs(F,Y),components:{Scroller:y.forwardRef((Y,F)=>u.jsx("div",{...Y,ref:F,style:{...K,...(Y==null?void 0:Y.style)??{}}}))},itemContent:(Y,F)=>{const H=F.role==="user"&&Y===t.length-1,Z=e&&n===F.id||H&&e,ce=fs(F,Y);return u.jsx("div",{className:"mb-4 last:mb-0","data-message-id":ce,style:{contentVisibility:"auto",minHeight:Z?120:void 0,containIntrinsicSize:Z?"auto 120px":"auto 150px",transform:"translateZ(0)",isolation:"isolate"},children:u.jsx(ag,{message:F,messageIndex:Y,isStreamingMessage:e&&n===F.id,streamingDebounceMs:r,isEditing:o===F.id,showActions:i,showTimestamp:!1,showAgentName:!0,layoutSize:a,truncateToolMessages:!1,toolMessagePreviewLength:200,onEdit:l,onRegenerate:()=>c(Y),onCancelEdit:d},F.id??`msg-${F.role}-${Y}-${F.createdAt??""}`)})}})})});Ss.displayName="MessageList";const _i=1e4;function TI(t){if(typeof t!="string")return String(t);const e=[/<script[^>]*>.*?<\/script>/gi,/<iframe[^>]*>.*?<\/iframe>/gi,/javascript:/gi,/vbscript:/gi,/on\w+\s*=/gi,/<object[^>]*>.*?<\/object>/gi,/<embed[^>]*>.*?<\/embed>/gi,/<form[^>]*>.*?<\/form>/gi];let n=t;for(const a of e)n=n.replace(a,"");return/<[^>]+>/.test(n)&&!/<(?!\/?(?:code|strong|em|b|i|br|p|ul|ol|li|h[1-6])\b)[^>]+>/i.test(n)?n.replace(/<code>(.*?)<\/code>/gi,"`$1`").replace(/<strong>(.*?)<\/strong>/gi,"**$1**").replace(/<b>(.*?)<\/b>/gi,"**$1**").replace(/<em>(.*?)<\/em>/gi,"*$1*").replace(/<i>(.*?)<\/i>/gi,"*$1*").replace(/<br\s*\/?>/gi,`
|
|
79
79
|
`).replace(/<p>(.*?)<\/p>/gi,`$1
|
|
80
80
|
|
|
81
81
|
`).replace(/<h([1-6])>(.*?)<\/h[1-6]>/gi,(a,i,o)=>`${"#".repeat(parseInt(i))} ${o}
|
package/package.json
CHANGED