teodor-new-chat-ui 4.3.85 → 4.3.86

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 CHANGED
@@ -11671,7 +11671,7 @@ const ru = U.memo(function({
11671
11671
  if (ne)
11672
11672
  return te(
11673
11673
  ie,
11674
- "w-full md:max-w-[95%]",
11674
+ "w-full",
11675
11675
  "bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]",
11676
11676
  "border border-border/60 dark:border-border/40 shadow-sm"
11677
11677
  );
@@ -12321,7 +12321,7 @@ const ou = (e, t) => (e == null ? void 0 : e.id) ?? `message-${t}`, Bf = U.forwa
12321
12321
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
12322
12322
  } : null;
12323
12323
  }, [p]);
12324
- return L.length === 0 ? fe ? /* @__PURE__ */ u.jsx("div", { className: f, style: h, children: /* @__PURE__ */ u.jsx("div", { className: "p-6 overflow-y-auto h-full flex items-start justify-center", children: /* @__PURE__ */ u.jsx("div", { className: "w-full max-w-2xl", children: /* @__PURE__ */ u.jsx(
12324
+ return L.length === 0 ? fe ? /* @__PURE__ */ u.jsx("div", { className: f, style: h, children: /* @__PURE__ */ u.jsx("div", { className: "p-6 overflow-y-auto h-full flex items-start justify-center", children: /* @__PURE__ */ u.jsx("div", { className: "w-full max-w-full", children: /* @__PURE__ */ u.jsx(
12325
12325
  ru,
12326
12326
  {
12327
12327
  message: fe,
package/dist/index.umd.js CHANGED
@@ -124,8 +124,8 @@ ${t}</tr>
124
124
  `}tablecell(t,n){const r=n.header?"th":"td";return(n.align?`<${r} align="${n.align}">`:`<${r}>`)+t+`</${r}>
125
125
  `}strong(t){return`<strong>${t}</strong>`}em(t){return`<em>${t}</em>`}codespan(t){return`<code>${t}</code>`}br(){return this.options.xhtml?"<br/>":"<br>"}del(t){return`<del>${t}</del>`}link(t,n,r){if(t=Zd(this.options.sanitize,this.options.baseUrl,t),t===null)return r;let o='<a href="'+t+'"';return n&&(o+=' title="'+n+'"'),o+=">"+r+"</a>",o}image(t,n,r){if(t=Zd(this.options.sanitize,this.options.baseUrl,t),t===null)return r;let o=`<img src="${t}" alt="${r}"`;return n&&(o+=` title="${n}"`),o+=this.options.xhtml?"/>":">",o}text(t){return t}}class rf{strong(t){return t}em(t){return t}codespan(t){return t}del(t){return t}html(t){return t}text(t){return t}link(t,n,r){return""+r}image(t,n,r){return""+r}br(){return""}}class of{constructor(){this.seen={}}serialize(t){return t.toLowerCase().trim().replace(/<[!\/a-z].*?>/ig,"").replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g,"").replace(/\s/g,"-")}getNextSafeSlug(t,n){let r=t,o=0;if(this.seen.hasOwnProperty(r)){o=this.seen[t];do o++,r=t+"-"+o;while(this.seen.hasOwnProperty(r))}return n||(this.seen[t]=o,this.seen[r]=0),r}slug(t,n={}){const r=this.serialize(t);return this.getNextSafeSlug(r,n.dryrun)}}class Jn{constructor(t){this.options=t||xr,this.options.renderer=this.options.renderer||new Oa,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new rf,this.slugger=new of}static parse(t,n){return new Jn(n).parse(t)}static parseInline(t,n){return new Jn(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,c,d,f,h,p,g,y,v,x,b,S,T,k,C;const E=t.length;for(o=0;o<E;o++){if(p=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[p.type]&&(C=this.options.extensions.renderers[p.type].call({parser:this},p),C!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(p.type))){r+=C||"";continue}switch(p.type){case"space":continue;case"hr":{r+=this.renderer.hr();continue}case"heading":{r+=this.renderer.heading(this.parseInline(p.tokens),p.depth,Jd(this.parseInline(p.tokens,this.textRenderer)),this.slugger);continue}case"code":{r+=this.renderer.code(p.text,p.lang,p.escaped);continue}case"table":{for(f="",d="",a=p.header.length,s=0;s<a;s++)d+=this.renderer.tablecell(this.parseInline(p.header[s].tokens),{header:!0,align:p.align[s]});for(f+=this.renderer.tablerow(d),h="",a=p.rows.length,s=0;s<a;s++){for(c=p.rows[s],d="",l=c.length,i=0;i<l;i++)d+=this.renderer.tablecell(this.parseInline(c[i].tokens),{header:!1,align:p.align[i]});h+=this.renderer.tablerow(d)}r+=this.renderer.table(f,h);continue}case"blockquote":{h=this.parse(p.tokens),r+=this.renderer.blockquote(h);continue}case"list":{for(g=p.ordered,y=p.start,v=p.loose,a=p.items.length,h="",s=0;s<a;s++)b=p.items[s],S=b.checked,T=b.task,x="",b.task&&(k=this.renderer.checkbox(S),v?b.tokens.length>0&&b.tokens[0].type==="paragraph"?(b.tokens[0].text=k+" "+b.tokens[0].text,b.tokens[0].tokens&&b.tokens[0].tokens.length>0&&b.tokens[0].tokens[0].type==="text"&&(b.tokens[0].tokens[0].text=k+" "+b.tokens[0].tokens[0].text)):b.tokens.unshift({type:"text",text:k}):x+=k),x+=this.parse(b.tokens,v),h+=this.renderer.listitem(x,T,S);r+=this.renderer.list(h,g,y);continue}case"html":{r+=this.renderer.html(p.text);continue}case"paragraph":{r+=this.renderer.paragraph(this.parseInline(p.tokens));continue}case"text":{for(h=p.tokens?this.parseInline(p.tokens):p.text;o+1<E&&t[o+1].type==="text";)p=t[++o],h+=`
126
126
  `+(p.tokens?this.parseInline(p.tokens):p.text);r+=n?this.renderer.paragraph(h):h;continue}default:{const _='Token with "'+p.type+'" type was not found.';if(this.options.silent){console.error(_);return}else throw new Error(_)}}}return r}parseInline(t,n){n=n||this.renderer;let r="",o,s,i;const a=t.length;for(o=0;o<a;o++){if(s=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[s.type]&&(i=this.options.extensions.renderers[s.type].call({parser:this},s),i!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type))){r+=i||"";continue}switch(s.type){case"escape":{r+=n.text(s.text);break}case"html":{r+=n.html(s.text);break}case"link":{r+=n.link(s.href,s.title,this.parseInline(s.tokens,n));break}case"image":{r+=n.image(s.href,s.title,s.text);break}case"strong":{r+=n.strong(this.parseInline(s.tokens,n));break}case"em":{r+=n.em(this.parseInline(s.tokens,n));break}case"codespan":{r+=n.codespan(s.text);break}case"br":{r+=n.br();break}case"del":{r+=n.del(this.parseInline(s.tokens,n));break}case"text":{r+=n.text(s.text);break}default:{const l='Token with "'+s.type+'" type was not found.';if(this.options.silent){console.error(l);return}else throw new Error(l)}}}return r}}class Ms{constructor(t){this.options=t||xr}preprocess(t){return t}postprocess(t){return t}}Cm(Ms,"passThroughHooks",new Set(["preprocess","postprocess"]));function Cw(e,t,n){return r=>{if(r.message+=`
127
- Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+Mt(r.message+"",!0)+"</pre>";if(t)return Promise.resolve(o);if(n){n(null,o);return}return o}if(t)return Promise.reject(r);if(n){n(r);return}throw r}}function sf(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...Se.defaults,...s};const i=Cw(r.silent,r.async,o);if(typeof n>"u"||n===null)return i(new Error("marked(): input parameter is undefined or null"));if(typeof n!="string")return i(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(n)+", string expected"));if(bw(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(f){return i(f)}const c=function(f){let h;if(!f)try{r.walkTokens&&Se.walkTokens(l,r.walkTokens),h=t(l,r),r.hooks&&(h=r.hooks.postprocess(h))}catch(p){f=p}return r.highlight=a,f?i(f):o(null,h)};if(!a||a.length<3||(delete r.highlight,!l.length))return c();let d=0;Se.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(h,p){if(h)return c(h);p!=null&&p!==f.text&&(f.text=p,f.escaped=!0),d--,d===0&&c()})},0))}),d===0&&c();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(Se.walkTokens(a,r.walkTokens)).then(()=>a):a).then(a=>t(a,r)).then(a=>r.hooks?r.hooks.postprocess(a):a).catch(i);try{r.hooks&&(n=r.hooks.preprocess(n));const a=e(n,r);r.walkTokens&&Se.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function Se(e,t,n){return sf(Xn.lex,Jn.parse)(e,t,n)}Se.options=Se.setOptions=function(e){return Se.defaults={...Se.defaults,...e},aw(Se.defaults),Se},Se.getDefaults=Kd,Se.defaults=xr,Se.use=function(...e){const t=Se.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=Se.defaults.async||r.async||!1,n.extensions&&(n.extensions.forEach(o=>{if(!o.name)throw new Error("extension name required");if(o.renderer){const s=t.renderers[o.name];s?t.renderers[o.name]=function(...i){let a=o.renderer.apply(this,i);return a===!1&&(a=s.apply(this,i)),a}:t.renderers[o.name]=o.renderer}if(o.tokenizer){if(!o.level||o.level!=="block"&&o.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");t[o.level]?t[o.level].unshift(o.tokenizer):t[o.level]=[o.tokenizer],o.start&&(o.level==="block"?t.startBlock?t.startBlock.push(o.start):t.startBlock=[o.start]:o.level==="inline"&&(t.startInline?t.startInline.push(o.start):t.startInline=[o.start]))}o.childTokens&&(t.childTokens[o.name]=o.childTokens)}),r.extensions=t),n.renderer){const o=Se.defaults.renderer||new Oa;for(const s in n.renderer){const i=o[s];o[s]=(...a)=>{let l=n.renderer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.renderer=o}if(n.tokenizer){const o=Se.defaults.tokenizer||new Pa;for(const s in n.tokenizer){const i=o[s];o[s]=(...a)=>{let l=n.tokenizer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.tokenizer=o}if(n.hooks){const o=Se.defaults.hooks||new Ms;for(const s in n.hooks){const i=o[s];Ms.passThroughHooks.has(s)?o[s]=a=>{if(Se.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(c=>i.call(o,c));const l=n.hooks[s].call(o,a);return i.call(o,l)}:o[s]=(...a)=>{let l=n.hooks[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.hooks=o}if(n.walkTokens){const o=Se.defaults.walkTokens;r.walkTokens=function(s){let i=[];return i.push(n.walkTokens.call(this,s)),o&&(i=i.concat(o.call(this,s))),i}}Se.setOptions(r)})},Se.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(Se,r)),r.type){case"table":{for(const o of r.header)n=n.concat(Se.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(Se.walkTokens(s.tokens,t));break}case"list":{n=n.concat(Se.walkTokens(r.items,t));break}default:Se.defaults.extensions&&Se.defaults.extensions.childTokens&&Se.defaults.extensions.childTokens[r.type]?Se.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(Se.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(Se.walkTokens(r.tokens,t)))}return n},Se.parseInline=sf(Xn.lexInline,Jn.parseInline),Se.Parser=Jn,Se.parser=Jn.parse,Se.Renderer=Oa,Se.TextRenderer=rf,Se.Lexer=Xn,Se.lexer=Xn.lex,Se.Tokenizer=Pa,Se.Slugger=of,Se.Hooks=Ms,Se.parse=Se,Se.options,Se.setOptions,Se.use,Se.walkTokens,Se.parseInline,Jn.parse,Xn.lex;function Ds({content:e,className:t="",allowHtml:n=!1,style:r}){const o=w.useMemo(()=>{try{if(!n){const i=e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,"").replace(/javascript:/gi,"").replace(/on\w+\s*=/gi,"");return Se.parse(i)}return Se.parse(e)}catch(i){return console.error("[MarkdownContent] parse error",i),`<pre class="font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words">Error rendering markdown: ${String(i)}</pre>`}},[e,n]),s=w.useMemo(()=>{const i={color:"currentColor",...r};if(r&&r.color){const a=r.color;return{...i,"--tw-prose-body":a,"--tw-prose-headings":a,"--tw-prose-links":a,"--tw-prose-bold":a,"--tw-prose-counters":a,"--tw-prose-bullets":a,"--tw-prose-hr":a,"--tw-prose-quotes":a,"--tw-prose-quote-borders":a,"--tw-prose-captions":a,"--tw-prose-code":a,"--tw-prose-pre-code":a,"--tw-prose-pre-bg":"inherit","--tw-prose-th-borders":a,"--tw-prose-td-borders":a}}return i},[r]);return u.jsx("div",{className:ee("markdown prose prose-sm max-w-none break-words","dark:prose-invert","text-current","prose-headings:text-current prose-p:text-current prose-li:text-current prose-a:text-current prose-strong:text-current","prose-em:text-current prose-blockquote:text-current prose-table:text-current prose-td:text-current prose-th:text-current","prose-pre:font-mono prose-pre:text-xs prose-pre:bg-background/50 prose-pre:border prose-pre:rounded prose-pre:p-3 prose-pre:whitespace-pre prose-pre:overflow-x-auto","prose-code:font-mono prose-code:text-sm prose-code:bg-background/50 prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:text-current",t),style:s,dangerouslySetInnerHTML:{__html:o}})}const kw="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 Tw(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function af(e){const t=e.find(r=>r.type==="tool_call"),n=e.find(r=>r.type==="tool_end");return{name:t==null?void 0:t.name,toolCallId:(n==null?void 0:n.toolCallId)??(t==null?void 0:t.id)}}function Ls(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function Ew(e){const t=o=>{try{const s=xo(o);return typeof s=="string"?s:JSON.stringify(s??"")}catch{return""}},n=e.filter(o=>o.type==="tool_end");let r="";if(n.length)try{n.length===1?r=t(n[0].output):r=t(n.map(o=>({toolCallId:o.toolCallId,output:o.output})))}catch{r=""}else r=t(e);return r||""}function Iw(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function lf(e){if("type"in e&&e.type==="default_message")return`default:${e.content.length}`;const t=e.updatedAt??e.createdAt??"",n=Array.isArray(e.content)?e.content.map(r=>{switch(r.type){case"text":return`t:${r.text.length}`;case"image_url":return"img";case"file":return"file";case"tool_call":return"call";case"tool_end":return"end";default:return"unknown"}}).join("|"):"";return`${e.id}:${t}:${n}`}function Aw({className:e}){const[t,n]=w.useState(0);return w.useEffect(()=>{const r=setInterval(()=>n(o=>(o+1)%4),500);return()=>clearInterval(r)},[]),u.jsxs("span",{"aria-live":"polite",className:ee("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const Ma=w.memo(function({message:t,messageIndex:n,isStreamingMessage:r=!1,isEditing:o=!1,showActions:s=!0,showTimestamp:i=!0,showAgentName:a=!0,layoutSize:l="desktop",truncateUserMessages:c=!0,userMessagePreviewLength:d=200,showToolMessages:f=!0,customStyles:h={},onEdit:p,onRegenerate:g,onCancelEdit:y,onCopy:v,activeInterrupt:x,disableInterruptActions:b=!1,onInterruptActionStart:S,onInterruptActionEnd:T}){const[k,C]=w.useState(!1),[E,_]=w.useState("preview"),[j,D]=w.useState(!1),{currentThreadId:$}=Yo(),{respondToInterrupt:K}=Xo(),P=l==="phone"||l==="half-screen",R=t.role,L=R==="tool",F=w.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),ne=!!F,q=!(r&&R!=="user"),{uploadingFiles:B,handleFileClick:pe,fileViewerOpen:W,currentFileInfo:ce,closeFileViewer:H}=_w({allowFileOpen:q,currentThreadId:$}),Z=w.useMemo(()=>{switch(R){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))]"}},[R]),be=w.useMemo(()=>F?"":Tw(t.content),[F,t]),ye=w.useMemo(()=>F?{}:af(t.content),[F,t]),G=w.useMemo(()=>F?[]:t.content.filter(ie=>ie.type==="image_url"),[F,t]),M=w.useMemo(()=>F?[]:t.content.filter(ie=>ie.type==="file"),[F,t]),X=w.useMemo(()=>F?[]:t.content.filter(ie=>ie.type==="interrupt"),[F,t]),oe=(x==null?void 0:x.id)??(x==null?void 0:x.interrupt_id),xe=Ls(oe),se=x==null?void 0:x.value,re=w.useMemo(()=>F?"":Ew(t.content),[F,t]),Ue=w.useCallback(async()=>{const ie=L?re:be;async function je(ke){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(ke);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const Ke=new Blob([ke],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":Ke})]);return}throw new Error("Clipboard API not supported in this context.")}try{await je(ie),C(!0),setTimeout(()=>C(!1),2e3),v==null||v(ie)}catch(ke){console.error("Failed to copy:",ke)}},[L,re,be,v]),qe=w.useCallback(()=>{if(!p)return;const ie=L?re:be;p(t.id,ie)},[p,t.id,L,re,be]),ot=w.useCallback(()=>{g==null||g(n)},[g,n]),at=w.useCallback(()=>{const je=ee(P?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",Z);switch(R){case"user":return u.jsx(fe.User,{className:je});case"assistant":return u.jsx(fe.Bot,{className:je});case"tool":return u.jsx(fe.Wrench,{className:je});default:return u.jsx(fe.Bot,{className:je})}},[P,Z,R]),ht=w.useCallback(()=>{const ie="group relative mb-4 flex w-full";switch(R){case"user":return ee(ie,"justify-end");case"assistant":case"tool":case"system":return ee(ie,"justify-start");default:return ie}},[R]),tt=w.useCallback(()=>{const ie=ee("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",P&&"px-3 py-2 text-sm");if(ne)return ee(ie,"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 shadow-sm");switch(R){case"user":return ee(ie,"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 ee(ie,"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 ee(ie,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return ee(ie,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return ee(ie,"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")}},[P,ne,R]);if(ne&&F)return u.jsx("div",{className:ee(ht(),h.container),children:u.jsxs("div",{className:ee(tt(),h.content),children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2 pb-2 border-b border-current/10",children:[u.jsx(fe.Bot,{className:ee("h-4 w-4",Z)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(Ds,{content:F.content,className:"text-current"})]})});const Me=w.useCallback(async ie=>{if(b)return;const je=Ls((ie==null?void 0:ie.id)??(ie==null?void 0:ie.interrupt_id));if(!je){console.warn("Interrupt part missing id",ie);return}try{S==null||S(),await K(je,!0)}catch(ke){console.error("Failed to approve interrupt:",ke)}finally{T==null||T()}},[b,T,S,K]),We=w.useCallback(async ie=>{if(b)return;const je=Ls((ie==null?void 0:ie.id)??(ie==null?void 0:ie.interrupt_id));if(!je){console.warn("Interrupt part missing id",ie);return}try{S==null||S(),await K(je,!1)}catch(ke){console.error("Failed to reject interrupt:",ke)}finally{T==null||T()}},[b,T,S,K]),lt=w.useCallback(({part:ie,i:je})=>{if(ie.type==="text"){const ke=ie.text??"",Ke=ke.trim(),nt=Qu(Ke);return nt&&R!=="tool"?u.jsx(cf,{data:nt},je):R==="user"&&c&&Ke.length>d?u.jsx(jw,{text:Ke,expanded:j,onExpandedChange:D,previewLength:d,isCompact:P},je):u.jsx(Ds,{content:ke,allowHtml:!1},je)}if(ie.type==="image_url"){const ke=ie;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:ke.url,alt:ke.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},je)}if(ie.type==="file"){const ke=ie,Ke=ke.name||"file";return u.jsxs("a",{href:ke.url,onClick:nt=>pe(nt,ke,je),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
128
- dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[B[je]?u.jsx(fe.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[Ke,B[je]?" (processing)":""]})]},je)}if(ie.type==="interrupt"){const ke=ie,Ke=Ls((ke==null?void 0:ke.id)??(ke==null?void 0:ke.interrupt_id)),nt=!!(xe&&Ke&&Ke===xe),Oe=nt?se??(ke==null?void 0:ke.value):ke==null?void 0:ke.value,Xe=Ke?{...ke,id:Ke,interrupt_id:Ke}:ke;return u.jsx(Nw,{interruptPart:Xe,onApprove:Me,onReject:We,disabled:b,isActive:nt,payload:Oe},je)}return null},[pe,B,Me,We,R,c,d,j,P,xe,se,x,b,X]),yt=w.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(fe.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),dt=w.useCallback(()=>{const ie=be.trim().length>0||G.length>0||M.length>0||X.length>0;if(!L&&M.length>0&&!r)return yt();if(!L&&!ie&&!r)return null;if(L)return u.jsx(Rw,{message:t,viewMode:E},t.id);if(!L&&!F){const je=t,ke=u.jsx("div",{className:"space-y-2",children:je.content.map((Ke,nt)=>u.jsx(lt,{part:Ke,i:nt},nt))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[ke,u.jsx(Aw,{className:Z})]}):ke}},[be,G.length,M.length,X.length,r,L,E,yt,Z]),Je=w.useMemo(()=>F?"Assistant":Iw(t),[F,t]);return L&&!f?null:u.jsxs(u.Fragment,{children:[u.jsx("div",{className:ee(ht(),h.container),children:u.jsxs("div",{className:ee(tt(),h.content),children:[(i||a||L)&&u.jsxs("div",{className:ee("flex items-center justify-between mb-2 pb-2 border-b border-current/10",P&&"mb-1 pb-1",Z,h.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[at(),a&&Je&&u.jsx("span",{className:ee("font-medium",P?"text-xs":"text-sm"),children:Je}),L&&u.jsxs(Hu,{variant:"outline",className:ee("text-xs flex items-center gap-1 cursor-pointer select-none",Z,"border border-current/40",P&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":E==="expanded",onClick:()=>_(ie=>ie==="expanded"?"preview":"expanded"),onKeyDown:ie=>{(ie.key==="Enter"||ie.key===" ")&&(ie.preventDefault(),_(je=>je==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:ye.name??"Tool Output"}),ye.toolCallId&&u.jsx("span",{className:"opacity-70",children:ye.toolCallId.slice(0,8)}),E==="expanded"?u.jsx(fe.ChevronUp,{className:"h-3 w-3"}):u.jsx(fe.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[i&&t.createdAt&&u.jsx("time",{className:ee("text-xs opacity-60",Z,P&&"text-xs"),dateTime:new Date(t.createdAt).toISOString(),title:new Date(t.createdAt).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t.createdAt))}),s&&!o&&u.jsxs("div",{className:ee("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>Ue(),className:ee("h-6 w-6 p-0 hover:bg-foreground/10",Z,P&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(fe.Copy,{className:ee(k?"text-success":Z,P?"h-3 w-3":"h-4 w-4")})})}),R==="user"&&p&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:qe,className:ee("h-6 w-6 p-0 hover:bg-foreground/10",Z,P&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(fe.Edit,{className:ee(Z,P?"h-3 w-3":"h-4 w-4")})}),R==="assistant"&&g&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:ot,className:ee("h-6 w-6 p-0 hover:bg-foreground/10",Z,P&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(fe.RotateCcw,{className:ee(Z,P?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsx("div",{className:"relative",children:dt()}),L&&E==="expanded"&&(ye.toolCallId||ye.name)&&u.jsxs("div",{className:ee("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",P&&"text-xs"),children:[ye.name&&u.jsxs("div",{children:["Function: ",ye.name]}),ye.toolCallId&&u.jsxs("div",{children:["Call ID: ",ye.toolCallId]})]}),!(i||a||L)&&s&&!o&&u.jsxs("div",{className:ee("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>Ue(),className:ee("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:u.jsx(fe.Copy,{className:ee(k?"text-success":"text-current",P?"h-3 w-3":"h-4 w-4")})}),R==="user"&&p&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:qe,className:ee("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:u.jsx(fe.Edit,{className:ee("text-current",P?"h-3 w-3":"h-4 w-4")})}),R==="assistant"&&g&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:ot,className:ee("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:u.jsx(fe.RotateCcw,{className:ee("text-current",P?"h-3 w-3":"h-4 w-4")})})]})]})}),ce&&u.jsx(iw,{isOpen:W,onClose:H,fileId:ce.id,fileName:ce.name,mimeType:ce.mimeType})]})},(e,t)=>{var i,a,l,c,d,f,h,p;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&lf(e.message)===lf(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages"].every(g=>e[g]===t[g]),s=((i=e.customStyles)==null?void 0:i.container)===((a=t.customStyles)==null?void 0:a.container)&&((l=e.customStyles)==null?void 0:l.content)===((c=t.customStyles)==null?void 0:c.content)&&((d=e.customStyles)==null?void 0:d.actions)===((f=t.customStyles)==null?void 0:f.actions)&&((h=e.customStyles)==null?void 0:h.header)===((p=t.customStyles)==null?void 0:p.header);return o&&s});function cf({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:kw,children:u.jsx("ul",{className:"list-disc pl-5",children:e.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:ms(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:ms(e)})}function Nw({interruptPart:e,onApprove:t,onReject:n,disabled:r,isActive:o,payload:s}){const i=e.title??"Approve the result?";let a=null;if(s!=null)if(typeof s=="string")a=u.jsx("p",{className:"text-sm leading-relaxed text-blue-800/90 dark:text-blue-200/90 whitespace-pre-wrap",children:s});else{const c=ms(s);a=u.jsx("pre",{className:"max-h-48 overflow-auto rounded bg-blue-100/60 p-2 text-xs text-blue-900/90 dark:bg-blue-900/40 dark:text-blue-100/80",children:c})}const l=o?"Please approve or reject this action to resume the workflow.":"Waiting for approval from another participant.";return u.jsxs(fo,{className:ee("border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10 transition-shadow",o?"shadow-md ring-1 ring-blue-300 dark:ring-blue-500/70":"opacity-80"),children:[u.jsxs(ho,{className:"pb-3",children:[u.jsx(po,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(Uu,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(mo,{className:"pt-0 pb-3",children:a}),u.jsx(Wu,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(Ze,{size:"sm",variant:"outline",onClick:()=>n(e),className:"border-red-300 text-red-700 hover:bg-red-50 dark:border-red-700 dark:text-red-300 dark:hover:bg-red-950/50",disabled:r||!o,children:"Reject"}),u.jsx(Ze,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}function _w(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=ya(),[o,s]=w.useState({}),[i,a]=w.useState(null),[l,c]=w.useState(!1),d=w.useCallback(()=>{c(!1),a(null)},[]),f=w.useCallback(p=>{a(p),c(!0)},[]),h=w.useCallback(async(p,g,y)=>{var v,x;if(!t){p.preventDefault();return}if(o[y]){p.preventDefault();return}try{const b=String(g.url??""),S=b.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){p.preventDefault();const T=S[1],k=g.name||`file_${T}`,C=g.mimeType||"application/octet-stream";f({id:T,name:k,mimeType:C});return}if(b.startsWith("data:")){p.preventDefault(),s(k=>({...k,[y]:!0}));const T=r({title:"Fetching file...",description:"",open:!0});try{const k=await Vv(n??void 0);if(!k||!Array.isArray(k))throw new Error("Invalid file list response");const C=k.find(E=>!E||typeof E!="object"||!((E.filename??"")===(g.name??""))?!1:typeof g.size=="number"&&typeof E.size=="number"?E.size===g.size:!0);if(!(C!=null&&C.id))throw new Error(`File "${g.name}" is not yet available on the server`);if(!C.id||!C.filename)throw new Error("Invalid file data received from server");f({id:C.id,name:g.name||C.filename||`file_${C.id}`,mimeType:g.mimeType||C.mime_type||"application/octet-stream"}),(v=T.update)==null||v.call(T,{id:T.id,title:"Success",description:`Opened ${g.name}`,open:!0})}catch(k){console.error("Failed to fetch server file:",k);const C=k instanceof Error?k.message:"Unknown error occurred";(x=T.update)==null||x.call(T,{id:T.id,title:"Failed",description:C}),r({title:"Failed to fetch file",description:C,open:!0})}finally{s(k=>({...k,[y]:!1}))}}}catch(b){console.error("File click error:",b),s(S=>({...S,[y]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:h,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function jw({text:e,expanded:t,onExpandedChange:n,previewLength:r,isCompact:o}){return u.jsxs(Lv,{open:t,onOpenChange:n,children:[u.jsx("div",{className:ee("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(Ds,{content:e,allowHtml:!1}):u.jsxs("pre",{className:ee("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:[e.substring(0,r),"..."]})}),u.jsx(Fv,{asChild:!0,children:u.jsx(Ze,{variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",children:t?u.jsxs(u.Fragment,{children:[u.jsx(fe.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(fe.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",e.length-r," chars)"]})})})]})}function Rw({message:e,viewMode:t}){const r=af(e.content).name||"tool",o=a=>{if(a==null)return null;const l=typeof a=="string"?Qu(a)??a:a;if(l&&typeof l=="object")return u.jsx(cf,{data:l});const c=typeof l=="string"?l:(()=>{try{return ms(l)}catch{return String(l??"")}})();return u.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm text-foreground/90",children:c})};if(t==="preview")return null;const s=e.content.find(a=>a.type!=="tool_call");if(!s)return u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(fe.Loader,{className:"h-4 w-4 animate-spin"}),u.jsxs("span",{children:["Waiting for ",r," output…"]})]});if(s.type==="text"){const l=(s.text??"").trim();return l?o(l):null}const i=xo(s);return o(i)}const uf=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,Da=w.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:c,onCancelEdit:d,className:f,style:h,emptyMessage:p,followNewMessages:g=!0,isNavigatingCheckpoint:y=!1,onScrollAway:v,onAtBottom:x,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:T,onInterruptActionEnd:k,showToolMessages:C=!0},E)=>{const _=w.useRef(null),j=w.useRef(null),D=w.useRef(!1),[$,K]=w.useState(!0),P=w.useMemo(()=>b?e.some(W=>"type"in W&&W.type==="default_message"?!1:Array.isArray(W==null?void 0:W.content)&&W.content.some(ce=>ce&&ce.type==="interrupt"&&(ce.id??ce.interrupt_id)===b.id)):!1,[b,e]),R=w.useMemo(()=>{if(!b||P)return null;const W=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let ce;const H=b.value;if(H&&typeof H=="object"&&!Array.isArray(H)){const Z=H.title;typeof Z=="string"&&Z.trim()&&(ce=Z.trim())}return{id:`interrupt-${W}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:W,value:H,title:ce}]}},[b,P]),L=w.useMemo(()=>R?[...e,R]:e,[e,R]),F=w.useMemo(()=>C?L:L.filter(W=>(W==null?void 0:W.role)!=="tool"),[L,C]),ne=w.useCallback(W=>{K(W),v&&v(!W),x&&x(W)},[v,x]),q=w.useMemo(()=>{if(a)return async()=>{if(!D.current){D.current=!0;try{await a()}finally{D.current=!1}}}},[a]),B=w.useMemo(()=>!g||y?!1:$?"auto":!1,[$,g,y]),pe=w.useMemo(()=>{if(typeof p!="string")return null;const W=p.trim();return W?{id:"default-message",role:"assistant",type:"default_message",content:W,createdAt:new Date().toISOString()}:null},[p]);return F.length===0?pe?u.jsx("div",{className:f,style:h,children:u.jsx("div",{className:"p-6 overflow-y-auto h-full flex items-start justify-center",children:u.jsx("div",{className:"w-full max-w-2xl",children:u.jsx(Ma,{message:pe,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{}})})})}):u.jsx("div",{className:f,style:h,children:u.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-center max-w-2xl mx-auto",children:p||"No messages yet. Start a conversation!"})}):u.jsx("div",{className:f,style:h,children:u.jsx(sv,{ref:W=>{_.current=W},scrollerRef:W=>{j.current=W instanceof HTMLDivElement?W:null},data:F,followOutput:B,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{q&&q()},atBottomStateChange:ne,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(W,ce)=>uf(ce,W),itemContent:(W,ce)=>{const H=uf(ce,W);return u.jsx("div",{className:"mb-4 last:mb-0","data-message-id":H,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Ma,{message:ce,messageIndex:W,isStreamingMessage:t&&n===ce.id,streamingDebounceMs:r,isEditing:i===ce.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:l,onRegenerate:()=>c(W),onCancelEdit:d,activeInterrupt:b,disableInterruptActions:S,onInterruptActionStart:T,onInterruptActionEnd:k,showToolMessages:C})})}})})});Da.displayName="MessageList";const Fs=1e4;function Pw(e){if(typeof e!="string")return String(e);const t=[/<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=e;for(const o of t)n=n.replace(o,"");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,`
127
+ Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+Mt(r.message+"",!0)+"</pre>";if(t)return Promise.resolve(o);if(n){n(null,o);return}return o}if(t)return Promise.reject(r);if(n){n(r);return}throw r}}function sf(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...Se.defaults,...s};const i=Cw(r.silent,r.async,o);if(typeof n>"u"||n===null)return i(new Error("marked(): input parameter is undefined or null"));if(typeof n!="string")return i(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(n)+", string expected"));if(bw(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(f){return i(f)}const c=function(f){let h;if(!f)try{r.walkTokens&&Se.walkTokens(l,r.walkTokens),h=t(l,r),r.hooks&&(h=r.hooks.postprocess(h))}catch(p){f=p}return r.highlight=a,f?i(f):o(null,h)};if(!a||a.length<3||(delete r.highlight,!l.length))return c();let d=0;Se.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(h,p){if(h)return c(h);p!=null&&p!==f.text&&(f.text=p,f.escaped=!0),d--,d===0&&c()})},0))}),d===0&&c();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(Se.walkTokens(a,r.walkTokens)).then(()=>a):a).then(a=>t(a,r)).then(a=>r.hooks?r.hooks.postprocess(a):a).catch(i);try{r.hooks&&(n=r.hooks.preprocess(n));const a=e(n,r);r.walkTokens&&Se.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function Se(e,t,n){return sf(Xn.lex,Jn.parse)(e,t,n)}Se.options=Se.setOptions=function(e){return Se.defaults={...Se.defaults,...e},aw(Se.defaults),Se},Se.getDefaults=Kd,Se.defaults=xr,Se.use=function(...e){const t=Se.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=Se.defaults.async||r.async||!1,n.extensions&&(n.extensions.forEach(o=>{if(!o.name)throw new Error("extension name required");if(o.renderer){const s=t.renderers[o.name];s?t.renderers[o.name]=function(...i){let a=o.renderer.apply(this,i);return a===!1&&(a=s.apply(this,i)),a}:t.renderers[o.name]=o.renderer}if(o.tokenizer){if(!o.level||o.level!=="block"&&o.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");t[o.level]?t[o.level].unshift(o.tokenizer):t[o.level]=[o.tokenizer],o.start&&(o.level==="block"?t.startBlock?t.startBlock.push(o.start):t.startBlock=[o.start]:o.level==="inline"&&(t.startInline?t.startInline.push(o.start):t.startInline=[o.start]))}o.childTokens&&(t.childTokens[o.name]=o.childTokens)}),r.extensions=t),n.renderer){const o=Se.defaults.renderer||new Oa;for(const s in n.renderer){const i=o[s];o[s]=(...a)=>{let l=n.renderer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.renderer=o}if(n.tokenizer){const o=Se.defaults.tokenizer||new Pa;for(const s in n.tokenizer){const i=o[s];o[s]=(...a)=>{let l=n.tokenizer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.tokenizer=o}if(n.hooks){const o=Se.defaults.hooks||new Ms;for(const s in n.hooks){const i=o[s];Ms.passThroughHooks.has(s)?o[s]=a=>{if(Se.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(c=>i.call(o,c));const l=n.hooks[s].call(o,a);return i.call(o,l)}:o[s]=(...a)=>{let l=n.hooks[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.hooks=o}if(n.walkTokens){const o=Se.defaults.walkTokens;r.walkTokens=function(s){let i=[];return i.push(n.walkTokens.call(this,s)),o&&(i=i.concat(o.call(this,s))),i}}Se.setOptions(r)})},Se.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(Se,r)),r.type){case"table":{for(const o of r.header)n=n.concat(Se.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(Se.walkTokens(s.tokens,t));break}case"list":{n=n.concat(Se.walkTokens(r.items,t));break}default:Se.defaults.extensions&&Se.defaults.extensions.childTokens&&Se.defaults.extensions.childTokens[r.type]?Se.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(Se.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(Se.walkTokens(r.tokens,t)))}return n},Se.parseInline=sf(Xn.lexInline,Jn.parseInline),Se.Parser=Jn,Se.parser=Jn.parse,Se.Renderer=Oa,Se.TextRenderer=rf,Se.Lexer=Xn,Se.lexer=Xn.lex,Se.Tokenizer=Pa,Se.Slugger=of,Se.Hooks=Ms,Se.parse=Se,Se.options,Se.setOptions,Se.use,Se.walkTokens,Se.parseInline,Jn.parse,Xn.lex;function Ds({content:e,className:t="",allowHtml:n=!1,style:r}){const o=w.useMemo(()=>{try{if(!n){const i=e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,"").replace(/javascript:/gi,"").replace(/on\w+\s*=/gi,"");return Se.parse(i)}return Se.parse(e)}catch(i){return console.error("[MarkdownContent] parse error",i),`<pre class="font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words">Error rendering markdown: ${String(i)}</pre>`}},[e,n]),s=w.useMemo(()=>{const i={color:"currentColor",...r};if(r&&r.color){const a=r.color;return{...i,"--tw-prose-body":a,"--tw-prose-headings":a,"--tw-prose-links":a,"--tw-prose-bold":a,"--tw-prose-counters":a,"--tw-prose-bullets":a,"--tw-prose-hr":a,"--tw-prose-quotes":a,"--tw-prose-quote-borders":a,"--tw-prose-captions":a,"--tw-prose-code":a,"--tw-prose-pre-code":a,"--tw-prose-pre-bg":"inherit","--tw-prose-th-borders":a,"--tw-prose-td-borders":a}}return i},[r]);return u.jsx("div",{className:ee("markdown prose prose-sm max-w-none break-words","dark:prose-invert","text-current","prose-headings:text-current prose-p:text-current prose-li:text-current prose-a:text-current prose-strong:text-current","prose-em:text-current prose-blockquote:text-current prose-table:text-current prose-td:text-current prose-th:text-current","prose-pre:font-mono prose-pre:text-xs prose-pre:bg-background/50 prose-pre:border prose-pre:rounded prose-pre:p-3 prose-pre:whitespace-pre prose-pre:overflow-x-auto","prose-code:font-mono prose-code:text-sm prose-code:bg-background/50 prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:text-current",t),style:s,dangerouslySetInnerHTML:{__html:o}})}const kw="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 Tw(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function af(e){const t=e.find(r=>r.type==="tool_call"),n=e.find(r=>r.type==="tool_end");return{name:t==null?void 0:t.name,toolCallId:(n==null?void 0:n.toolCallId)??(t==null?void 0:t.id)}}function Ls(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function Ew(e){const t=o=>{try{const s=xo(o);return typeof s=="string"?s:JSON.stringify(s??"")}catch{return""}},n=e.filter(o=>o.type==="tool_end");let r="";if(n.length)try{n.length===1?r=t(n[0].output):r=t(n.map(o=>({toolCallId:o.toolCallId,output:o.output})))}catch{r=""}else r=t(e);return r||""}function Iw(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function lf(e){if("type"in e&&e.type==="default_message")return`default:${e.content.length}`;const t=e.updatedAt??e.createdAt??"",n=Array.isArray(e.content)?e.content.map(r=>{switch(r.type){case"text":return`t:${r.text.length}`;case"image_url":return"img";case"file":return"file";case"tool_call":return"call";case"tool_end":return"end";default:return"unknown"}}).join("|"):"";return`${e.id}:${t}:${n}`}function Aw({className:e}){const[t,n]=w.useState(0);return w.useEffect(()=>{const r=setInterval(()=>n(o=>(o+1)%4),500);return()=>clearInterval(r)},[]),u.jsxs("span",{"aria-live":"polite",className:ee("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const Ma=w.memo(function({message:t,messageIndex:n,isStreamingMessage:r=!1,isEditing:o=!1,showActions:s=!0,showTimestamp:i=!0,showAgentName:a=!0,layoutSize:l="desktop",truncateUserMessages:c=!0,userMessagePreviewLength:d=200,showToolMessages:f=!0,customStyles:h={},onEdit:p,onRegenerate:g,onCancelEdit:y,onCopy:v,activeInterrupt:x,disableInterruptActions:b=!1,onInterruptActionStart:S,onInterruptActionEnd:T}){const[k,C]=w.useState(!1),[E,_]=w.useState("preview"),[j,D]=w.useState(!1),{currentThreadId:$}=Yo(),{respondToInterrupt:K}=Xo(),P=l==="phone"||l==="half-screen",R=t.role,L=R==="tool",F=w.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),ne=!!F,q=!(r&&R!=="user"),{uploadingFiles:B,handleFileClick:pe,fileViewerOpen:W,currentFileInfo:ce,closeFileViewer:H}=_w({allowFileOpen:q,currentThreadId:$}),Z=w.useMemo(()=>{switch(R){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))]"}},[R]),be=w.useMemo(()=>F?"":Tw(t.content),[F,t]),ye=w.useMemo(()=>F?{}:af(t.content),[F,t]),G=w.useMemo(()=>F?[]:t.content.filter(ie=>ie.type==="image_url"),[F,t]),M=w.useMemo(()=>F?[]:t.content.filter(ie=>ie.type==="file"),[F,t]),X=w.useMemo(()=>F?[]:t.content.filter(ie=>ie.type==="interrupt"),[F,t]),oe=(x==null?void 0:x.id)??(x==null?void 0:x.interrupt_id),xe=Ls(oe),se=x==null?void 0:x.value,re=w.useMemo(()=>F?"":Ew(t.content),[F,t]),Ue=w.useCallback(async()=>{const ie=L?re:be;async function je(ke){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(ke);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const Ke=new Blob([ke],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":Ke})]);return}throw new Error("Clipboard API not supported in this context.")}try{await je(ie),C(!0),setTimeout(()=>C(!1),2e3),v==null||v(ie)}catch(ke){console.error("Failed to copy:",ke)}},[L,re,be,v]),qe=w.useCallback(()=>{if(!p)return;const ie=L?re:be;p(t.id,ie)},[p,t.id,L,re,be]),ot=w.useCallback(()=>{g==null||g(n)},[g,n]),at=w.useCallback(()=>{const je=ee(P?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",Z);switch(R){case"user":return u.jsx(fe.User,{className:je});case"assistant":return u.jsx(fe.Bot,{className:je});case"tool":return u.jsx(fe.Wrench,{className:je});default:return u.jsx(fe.Bot,{className:je})}},[P,Z,R]),ht=w.useCallback(()=>{const ie="group relative mb-4 flex w-full";switch(R){case"user":return ee(ie,"justify-end");case"assistant":case"tool":case"system":return ee(ie,"justify-start");default:return ie}},[R]),tt=w.useCallback(()=>{const ie=ee("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",P&&"px-3 py-2 text-sm");if(ne)return ee(ie,"w-full","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40 shadow-sm");switch(R){case"user":return ee(ie,"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 ee(ie,"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 ee(ie,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return ee(ie,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return ee(ie,"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")}},[P,ne,R]);if(ne&&F)return u.jsx("div",{className:ee(ht(),h.container),children:u.jsxs("div",{className:ee(tt(),h.content),children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2 pb-2 border-b border-current/10",children:[u.jsx(fe.Bot,{className:ee("h-4 w-4",Z)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(Ds,{content:F.content,className:"text-current"})]})});const Me=w.useCallback(async ie=>{if(b)return;const je=Ls((ie==null?void 0:ie.id)??(ie==null?void 0:ie.interrupt_id));if(!je){console.warn("Interrupt part missing id",ie);return}try{S==null||S(),await K(je,!0)}catch(ke){console.error("Failed to approve interrupt:",ke)}finally{T==null||T()}},[b,T,S,K]),We=w.useCallback(async ie=>{if(b)return;const je=Ls((ie==null?void 0:ie.id)??(ie==null?void 0:ie.interrupt_id));if(!je){console.warn("Interrupt part missing id",ie);return}try{S==null||S(),await K(je,!1)}catch(ke){console.error("Failed to reject interrupt:",ke)}finally{T==null||T()}},[b,T,S,K]),lt=w.useCallback(({part:ie,i:je})=>{if(ie.type==="text"){const ke=ie.text??"",Ke=ke.trim(),nt=Qu(Ke);return nt&&R!=="tool"?u.jsx(cf,{data:nt},je):R==="user"&&c&&Ke.length>d?u.jsx(jw,{text:Ke,expanded:j,onExpandedChange:D,previewLength:d,isCompact:P},je):u.jsx(Ds,{content:ke,allowHtml:!1},je)}if(ie.type==="image_url"){const ke=ie;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:ke.url,alt:ke.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},je)}if(ie.type==="file"){const ke=ie,Ke=ke.name||"file";return u.jsxs("a",{href:ke.url,onClick:nt=>pe(nt,ke,je),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
128
+ dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[B[je]?u.jsx(fe.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[Ke,B[je]?" (processing)":""]})]},je)}if(ie.type==="interrupt"){const ke=ie,Ke=Ls((ke==null?void 0:ke.id)??(ke==null?void 0:ke.interrupt_id)),nt=!!(xe&&Ke&&Ke===xe),Oe=nt?se??(ke==null?void 0:ke.value):ke==null?void 0:ke.value,Xe=Ke?{...ke,id:Ke,interrupt_id:Ke}:ke;return u.jsx(Nw,{interruptPart:Xe,onApprove:Me,onReject:We,disabled:b,isActive:nt,payload:Oe},je)}return null},[pe,B,Me,We,R,c,d,j,P,xe,se,x,b,X]),yt=w.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(fe.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),dt=w.useCallback(()=>{const ie=be.trim().length>0||G.length>0||M.length>0||X.length>0;if(!L&&M.length>0&&!r)return yt();if(!L&&!ie&&!r)return null;if(L)return u.jsx(Rw,{message:t,viewMode:E},t.id);if(!L&&!F){const je=t,ke=u.jsx("div",{className:"space-y-2",children:je.content.map((Ke,nt)=>u.jsx(lt,{part:Ke,i:nt},nt))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[ke,u.jsx(Aw,{className:Z})]}):ke}},[be,G.length,M.length,X.length,r,L,E,yt,Z]),Je=w.useMemo(()=>F?"Assistant":Iw(t),[F,t]);return L&&!f?null:u.jsxs(u.Fragment,{children:[u.jsx("div",{className:ee(ht(),h.container),children:u.jsxs("div",{className:ee(tt(),h.content),children:[(i||a||L)&&u.jsxs("div",{className:ee("flex items-center justify-between mb-2 pb-2 border-b border-current/10",P&&"mb-1 pb-1",Z,h.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[at(),a&&Je&&u.jsx("span",{className:ee("font-medium",P?"text-xs":"text-sm"),children:Je}),L&&u.jsxs(Hu,{variant:"outline",className:ee("text-xs flex items-center gap-1 cursor-pointer select-none",Z,"border border-current/40",P&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":E==="expanded",onClick:()=>_(ie=>ie==="expanded"?"preview":"expanded"),onKeyDown:ie=>{(ie.key==="Enter"||ie.key===" ")&&(ie.preventDefault(),_(je=>je==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:ye.name??"Tool Output"}),ye.toolCallId&&u.jsx("span",{className:"opacity-70",children:ye.toolCallId.slice(0,8)}),E==="expanded"?u.jsx(fe.ChevronUp,{className:"h-3 w-3"}):u.jsx(fe.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[i&&t.createdAt&&u.jsx("time",{className:ee("text-xs opacity-60",Z,P&&"text-xs"),dateTime:new Date(t.createdAt).toISOString(),title:new Date(t.createdAt).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t.createdAt))}),s&&!o&&u.jsxs("div",{className:ee("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>Ue(),className:ee("h-6 w-6 p-0 hover:bg-foreground/10",Z,P&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(fe.Copy,{className:ee(k?"text-success":Z,P?"h-3 w-3":"h-4 w-4")})})}),R==="user"&&p&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:qe,className:ee("h-6 w-6 p-0 hover:bg-foreground/10",Z,P&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(fe.Edit,{className:ee(Z,P?"h-3 w-3":"h-4 w-4")})}),R==="assistant"&&g&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:ot,className:ee("h-6 w-6 p-0 hover:bg-foreground/10",Z,P&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(fe.RotateCcw,{className:ee(Z,P?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsx("div",{className:"relative",children:dt()}),L&&E==="expanded"&&(ye.toolCallId||ye.name)&&u.jsxs("div",{className:ee("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",P&&"text-xs"),children:[ye.name&&u.jsxs("div",{children:["Function: ",ye.name]}),ye.toolCallId&&u.jsxs("div",{children:["Call ID: ",ye.toolCallId]})]}),!(i||a||L)&&s&&!o&&u.jsxs("div",{className:ee("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>Ue(),className:ee("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:u.jsx(fe.Copy,{className:ee(k?"text-success":"text-current",P?"h-3 w-3":"h-4 w-4")})}),R==="user"&&p&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:qe,className:ee("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:u.jsx(fe.Edit,{className:ee("text-current",P?"h-3 w-3":"h-4 w-4")})}),R==="assistant"&&g&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:ot,className:ee("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:u.jsx(fe.RotateCcw,{className:ee("text-current",P?"h-3 w-3":"h-4 w-4")})})]})]})}),ce&&u.jsx(iw,{isOpen:W,onClose:H,fileId:ce.id,fileName:ce.name,mimeType:ce.mimeType})]})},(e,t)=>{var i,a,l,c,d,f,h,p;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&lf(e.message)===lf(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages"].every(g=>e[g]===t[g]),s=((i=e.customStyles)==null?void 0:i.container)===((a=t.customStyles)==null?void 0:a.container)&&((l=e.customStyles)==null?void 0:l.content)===((c=t.customStyles)==null?void 0:c.content)&&((d=e.customStyles)==null?void 0:d.actions)===((f=t.customStyles)==null?void 0:f.actions)&&((h=e.customStyles)==null?void 0:h.header)===((p=t.customStyles)==null?void 0:p.header);return o&&s});function cf({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:kw,children:u.jsx("ul",{className:"list-disc pl-5",children:e.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:ms(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:ms(e)})}function Nw({interruptPart:e,onApprove:t,onReject:n,disabled:r,isActive:o,payload:s}){const i=e.title??"Approve the result?";let a=null;if(s!=null)if(typeof s=="string")a=u.jsx("p",{className:"text-sm leading-relaxed text-blue-800/90 dark:text-blue-200/90 whitespace-pre-wrap",children:s});else{const c=ms(s);a=u.jsx("pre",{className:"max-h-48 overflow-auto rounded bg-blue-100/60 p-2 text-xs text-blue-900/90 dark:bg-blue-900/40 dark:text-blue-100/80",children:c})}const l=o?"Please approve or reject this action to resume the workflow.":"Waiting for approval from another participant.";return u.jsxs(fo,{className:ee("border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10 transition-shadow",o?"shadow-md ring-1 ring-blue-300 dark:ring-blue-500/70":"opacity-80"),children:[u.jsxs(ho,{className:"pb-3",children:[u.jsx(po,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(Uu,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(mo,{className:"pt-0 pb-3",children:a}),u.jsx(Wu,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(Ze,{size:"sm",variant:"outline",onClick:()=>n(e),className:"border-red-300 text-red-700 hover:bg-red-50 dark:border-red-700 dark:text-red-300 dark:hover:bg-red-950/50",disabled:r||!o,children:"Reject"}),u.jsx(Ze,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}function _w(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=ya(),[o,s]=w.useState({}),[i,a]=w.useState(null),[l,c]=w.useState(!1),d=w.useCallback(()=>{c(!1),a(null)},[]),f=w.useCallback(p=>{a(p),c(!0)},[]),h=w.useCallback(async(p,g,y)=>{var v,x;if(!t){p.preventDefault();return}if(o[y]){p.preventDefault();return}try{const b=String(g.url??""),S=b.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){p.preventDefault();const T=S[1],k=g.name||`file_${T}`,C=g.mimeType||"application/octet-stream";f({id:T,name:k,mimeType:C});return}if(b.startsWith("data:")){p.preventDefault(),s(k=>({...k,[y]:!0}));const T=r({title:"Fetching file...",description:"",open:!0});try{const k=await Vv(n??void 0);if(!k||!Array.isArray(k))throw new Error("Invalid file list response");const C=k.find(E=>!E||typeof E!="object"||!((E.filename??"")===(g.name??""))?!1:typeof g.size=="number"&&typeof E.size=="number"?E.size===g.size:!0);if(!(C!=null&&C.id))throw new Error(`File "${g.name}" is not yet available on the server`);if(!C.id||!C.filename)throw new Error("Invalid file data received from server");f({id:C.id,name:g.name||C.filename||`file_${C.id}`,mimeType:g.mimeType||C.mime_type||"application/octet-stream"}),(v=T.update)==null||v.call(T,{id:T.id,title:"Success",description:`Opened ${g.name}`,open:!0})}catch(k){console.error("Failed to fetch server file:",k);const C=k instanceof Error?k.message:"Unknown error occurred";(x=T.update)==null||x.call(T,{id:T.id,title:"Failed",description:C}),r({title:"Failed to fetch file",description:C,open:!0})}finally{s(k=>({...k,[y]:!1}))}}}catch(b){console.error("File click error:",b),s(S=>({...S,[y]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:h,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function jw({text:e,expanded:t,onExpandedChange:n,previewLength:r,isCompact:o}){return u.jsxs(Lv,{open:t,onOpenChange:n,children:[u.jsx("div",{className:ee("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(Ds,{content:e,allowHtml:!1}):u.jsxs("pre",{className:ee("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:[e.substring(0,r),"..."]})}),u.jsx(Fv,{asChild:!0,children:u.jsx(Ze,{variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",children:t?u.jsxs(u.Fragment,{children:[u.jsx(fe.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(fe.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",e.length-r," chars)"]})})})]})}function Rw({message:e,viewMode:t}){const r=af(e.content).name||"tool",o=a=>{if(a==null)return null;const l=typeof a=="string"?Qu(a)??a:a;if(l&&typeof l=="object")return u.jsx(cf,{data:l});const c=typeof l=="string"?l:(()=>{try{return ms(l)}catch{return String(l??"")}})();return u.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm text-foreground/90",children:c})};if(t==="preview")return null;const s=e.content.find(a=>a.type!=="tool_call");if(!s)return u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(fe.Loader,{className:"h-4 w-4 animate-spin"}),u.jsxs("span",{children:["Waiting for ",r," output…"]})]});if(s.type==="text"){const l=(s.text??"").trim();return l?o(l):null}const i=xo(s);return o(i)}const uf=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,Da=w.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:c,onCancelEdit:d,className:f,style:h,emptyMessage:p,followNewMessages:g=!0,isNavigatingCheckpoint:y=!1,onScrollAway:v,onAtBottom:x,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:T,onInterruptActionEnd:k,showToolMessages:C=!0},E)=>{const _=w.useRef(null),j=w.useRef(null),D=w.useRef(!1),[$,K]=w.useState(!0),P=w.useMemo(()=>b?e.some(W=>"type"in W&&W.type==="default_message"?!1:Array.isArray(W==null?void 0:W.content)&&W.content.some(ce=>ce&&ce.type==="interrupt"&&(ce.id??ce.interrupt_id)===b.id)):!1,[b,e]),R=w.useMemo(()=>{if(!b||P)return null;const W=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let ce;const H=b.value;if(H&&typeof H=="object"&&!Array.isArray(H)){const Z=H.title;typeof Z=="string"&&Z.trim()&&(ce=Z.trim())}return{id:`interrupt-${W}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:W,value:H,title:ce}]}},[b,P]),L=w.useMemo(()=>R?[...e,R]:e,[e,R]),F=w.useMemo(()=>C?L:L.filter(W=>(W==null?void 0:W.role)!=="tool"),[L,C]),ne=w.useCallback(W=>{K(W),v&&v(!W),x&&x(W)},[v,x]),q=w.useMemo(()=>{if(a)return async()=>{if(!D.current){D.current=!0;try{await a()}finally{D.current=!1}}}},[a]),B=w.useMemo(()=>!g||y?!1:$?"auto":!1,[$,g,y]),pe=w.useMemo(()=>{if(typeof p!="string")return null;const W=p.trim();return W?{id:"default-message",role:"assistant",type:"default_message",content:W,createdAt:new Date().toISOString()}:null},[p]);return F.length===0?pe?u.jsx("div",{className:f,style:h,children:u.jsx("div",{className:"p-6 overflow-y-auto h-full flex items-start justify-center",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Ma,{message:pe,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{}})})})}):u.jsx("div",{className:f,style:h,children:u.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-center max-w-2xl mx-auto",children:p||"No messages yet. Start a conversation!"})}):u.jsx("div",{className:f,style:h,children:u.jsx(sv,{ref:W=>{_.current=W},scrollerRef:W=>{j.current=W instanceof HTMLDivElement?W:null},data:F,followOutput:B,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{q&&q()},atBottomStateChange:ne,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(W,ce)=>uf(ce,W),itemContent:(W,ce)=>{const H=uf(ce,W);return u.jsx("div",{className:"mb-4 last:mb-0","data-message-id":H,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Ma,{message:ce,messageIndex:W,isStreamingMessage:t&&n===ce.id,streamingDebounceMs:r,isEditing:i===ce.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:l,onRegenerate:()=>c(W),onCancelEdit:d,activeInterrupt:b,disableInterruptActions:S,onInterruptActionStart:T,onInterruptActionEnd:k,showToolMessages:C})})}})})});Da.displayName="MessageList";const Fs=1e4;function Pw(e){if(typeof e!="string")return String(e);const t=[/<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=e;for(const o of t)n=n.replace(o,"");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,`
129
129
  `).replace(/<p>(.*?)<\/p>/gi,`$1
130
130
 
131
131
  `).replace(/<h([1-6])>(.*?)<\/h[1-6]>/gi,(o,s,i)=>`${"#".repeat(parseInt(s))} ${i}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teodor-new-chat-ui",
3
- "version": "4.3.85",
3
+ "version": "4.3.86",
4
4
  "description": "React chat UI components with streaming support, tool calls, and modern design",
5
5
  "main": "dist/index.umd.js",
6
6
  "module": "dist/index.esm.js",