teodor-new-chat-ui 4.3.326 → 4.3.327
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 +1 -1
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -14089,7 +14089,7 @@ const Oc = tm(function({
|
|
|
14089
14089
|
defaultCheckpointId: N = null,
|
|
14090
14090
|
messageParentCheckpointId: L = null
|
|
14091
14091
|
}) {
|
|
14092
|
-
const [j, O] = ge(!1), [$, E] = ge("preview"), [F, _] = ge(!1), { currentThreadId: J } = da(), { respondToInterrupt: B } = fa(), A = l === "phone" || l === "half-screen", G = t.role, X = G === "tool", oe = $e(() => null, [t]), ve = !!oe, _e = !(r && G !== "user"), {
|
|
14092
|
+
const [j, O] = ge(!1), [$, E] = ge("preview"), [F, _] = ge(!1), { currentThreadId: J } = da(), { respondToInterrupt: B } = fa(), A = l === "phone" || l === "half-screen", G = t.role, X = G === "tool", oe = $e(() => "type" in t && t.type === "default_message" ? t : null, [t]), ve = !!oe, _e = !(r && G !== "user"), {
|
|
14093
14093
|
uploadingFiles: W,
|
|
14094
14094
|
handleFileClick: z,
|
|
14095
14095
|
fileViewerOpen: K,
|
package/dist/index.umd.js
CHANGED
|
@@ -133,5 +133,5 @@ ${t}</tr>
|
|
|
133
133
|
`}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=tp(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=tp(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 ip{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 ap{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 On{constructor(t){this.options=t||er,this.options.renderer=this.options.renderer||new Aa,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new ip,this.slugger=new ap}static parse(t,n){return new On(n).parse(t)}static parseInline(t,n){return new On(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,c,d,f,p,h,x,m,y,g,b,S,k,C,T;const I=t.length;for(o=0;o<I;o++){if(h=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[h.type]&&(T=this.options.extensions.renderers[h.type].call({parser:this},h),T!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(h.type))){r+=T||"";continue}switch(h.type){case"space":continue;case"hr":{r+=this.renderer.hr();continue}case"heading":{r+=this.renderer.heading(this.parseInline(h.tokens),h.depth,ep(this.parseInline(h.tokens,this.textRenderer)),this.slugger);continue}case"code":{r+=this.renderer.code(h.text,h.lang,h.escaped);continue}case"table":{for(f="",d="",a=h.header.length,s=0;s<a;s++)d+=this.renderer.tablecell(this.parseInline(h.header[s].tokens),{header:!0,align:h.align[s]});for(f+=this.renderer.tablerow(d),p="",a=h.rows.length,s=0;s<a;s++){for(c=h.rows[s],d="",l=c.length,i=0;i<l;i++)d+=this.renderer.tablecell(this.parseInline(c[i].tokens),{header:!1,align:h.align[i]});p+=this.renderer.tablerow(d)}r+=this.renderer.table(f,p);continue}case"blockquote":{p=this.parse(h.tokens),r+=this.renderer.blockquote(p);continue}case"list":{for(x=h.ordered,m=h.start,y=h.loose,a=h.items.length,p="",s=0;s<a;s++)b=h.items[s],S=b.checked,k=b.task,g="",b.task&&(C=this.renderer.checkbox(S),y?b.tokens.length>0&&b.tokens[0].type==="paragraph"?(b.tokens[0].text=C+" "+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=C+" "+b.tokens[0].tokens[0].text)):b.tokens.unshift({type:"text",text:C}):g+=C),g+=this.parse(b.tokens,y),p+=this.renderer.listitem(g,k,S);r+=this.renderer.list(p,x,m);continue}case"html":{r+=this.renderer.html(h.text);continue}case"paragraph":{r+=this.renderer.paragraph(this.parseInline(h.tokens));continue}case"text":{for(p=h.tokens?this.parseInline(h.tokens):h.text;o+1<I&&t[o+1].type==="text";)h=t[++o],p+=`
|
|
134
134
|
`+(h.tokens?this.parseInline(h.tokens):h.text);r+=n?this.renderer.paragraph(p):p;continue}default:{const A='Token with "'+h.type+'" type was not found.';if(this.options.silent){console.error(A);return}else throw new Error(A)}}}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 _s{constructor(t){this.options=t||er}preprocess(t){return t}postprocess(t){return t}}zh(_s,"passThroughHooks",new Set(["preprocess","postprocess"]));function DS(e,t,n){return r=>{if(r.message+=`
|
|
135
135
|
Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+Rt(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 lp(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...ge.defaults,...s};const i=DS(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(PS(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 p;if(!f)try{r.walkTokens&&ge.walkTokens(l,r.walkTokens),p=t(l,r),r.hooks&&(p=r.hooks.postprocess(p))}catch(h){f=h}return r.highlight=a,f?i(f):o(null,p)};if(!a||a.length<3||(delete r.highlight,!l.length))return c();let d=0;ge.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(p,h){if(p)return c(p);h!=null&&h!==f.text&&(f.text=h,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(ge.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&&ge.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function ge(e,t,n){return lp(Mn.lex,On.parse)(e,t,n)}ge.options=ge.setOptions=function(e){return ge.defaults={...ge.defaults,...e},bS(ge.defaults),ge},ge.getDefaults=Xf,ge.defaults=er,ge.use=function(...e){const t=ge.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=ge.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=ge.defaults.renderer||new Aa;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=ge.defaults.tokenizer||new Ea;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=ge.defaults.hooks||new _s;for(const s in n.hooks){const i=o[s];_s.passThroughHooks.has(s)?o[s]=a=>{if(ge.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=ge.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}}ge.setOptions(r)})},ge.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(ge,r)),r.type){case"table":{for(const o of r.header)n=n.concat(ge.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(ge.walkTokens(s.tokens,t));break}case"list":{n=n.concat(ge.walkTokens(r.items,t));break}default:ge.defaults.extensions&&ge.defaults.extensions.childTokens&&ge.defaults.extensions.childTokens[r.type]?ge.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(ge.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(ge.walkTokens(r.tokens,t)))}return n},ge.parseInline=lp(Mn.lexInline,On.parseInline),ge.Parser=On,ge.parser=On.parse,ge.Renderer=Aa,ge.TextRenderer=ip,ge.Lexer=Mn,ge.lexer=Mn.lex,ge.Tokenizer=Ea,ge.Slugger=ap,ge.Hooks=_s,ge.parse=ge,ge.options,ge.setOptions,ge.use,ge.walkTokens,ge.parseInline,On.parse,Mn.lex;function oo({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 typeof ge.parse=="function"?ge.parse(i):ge(i)}return typeof ge.parse=="function"?ge.parse(e):ge(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:te("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 LS="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 $S(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function cp(e){const t=e.content.find(s=>s.type==="tool_call"),n=e.additionalKwargs??{},r=typeof(t==null?void 0:t.id)=="string"&&t.id||typeof n.toolCallId=="string"&&n.toolCallId||(e.id.startsWith("tool-")?e.id.slice(5):void 0);return{name:(typeof(t==null?void 0:t.name)=="string"&&t.name||typeof n.toolName=="string"&&n.toolName||e.name&&String(e.name))??void 0,toolCallId:r??void 0}}function js(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function FS(e){const t=o=>{try{const s=no(o);return typeof s=="string"?s:JSON.stringify(s??"")}catch{return""}},n=e.filter(o=>o.type==="text");let r="";return n.length?r=t(n.map(o=>o.text).join(`
|
|
136
|
-
`)):r=t(e),r||""}function BS(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function up(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"interrupt":return"interrupt";default:return"unknown"}}).join("|"):"";return`${e.id}:${t}:${n}`}function zS(e){if(!e)return"image/png";const t=e.trim();return t?t.includes("/")?t:`image/${t}`:"image/png"}function US(e){const t=[],n=r=>{r&&r.trim()&&t.push(r.trim())};return e&&(n(e.plotId),n(e.artifactId)),t}function HS({base64:e,url:t,formatHint:n,extras:r}){const o=typeof e=="string"&&e.length>0,s=zS(n),i=o?`data:${s};base64,${e}`:t,a=US(r),l=a.length?a.join(" / "):void 0,c=l?`${l} artifact`:"artifact image";return{src:i,alt:c,label:l}}function WS(e){var s,i;const t=((s=e.content_base64)==null?void 0:s.trim())||void 0,n=((i=e.url)==null?void 0:i.trim())||void 0,r=e.format||e.mimeType||e.mime_type;return HS({base64:t,url:n,formatHint:r,extras:{plotId:e.plotId,artifactId:e.artifactId}})}function VS({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:te("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const Na=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=500,showToolMessages:f=!0,showArtifactPreviews:p=!0,customStyles:h={},onEdit:x,onRegenerate:m,onCancelEdit:y,onCopy:g,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,checkpointCandidates:T=[],activeCheckpointId:I=null,onSelectCheckpoint:A,defaultCheckpointId:j=null,messageParentCheckpointId:$=null}){const[P,O]=w.useState(!1),[F,N]=w.useState("preview"),[B,R]=w.useState(!1),{currentThreadId:Z}=Io(),{respondToInterrupt:z}=Eo(),_=l==="phone"||l==="half-screen",Y=t.role,J=Y==="tool",oe=w.useMemo(()=>null,[t]),ve=!!oe,Re=!(r&&Y!=="user"),{uploadingFiles:V,handleFileClick:U,fileViewerOpen:q,currentFileInfo:L,closeFileViewer:G}=GS({allowFileOpen:Re,currentThreadId:Z}),Q=w.useMemo(()=>{switch(Y){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))]"}},[Y]),le=w.useMemo(()=>{if(oe)return"";const D=t.content;return Array.isArray(D)?$S(D):""},[oe,t]),re=w.useMemo(()=>{if(oe)return{};const D=t.content;return Array.isArray(D)?cp(t):{}},[oe,t]),Ae=w.useMemo(()=>{if(oe)return[];const D=t.content;return Array.isArray(D)?D.filter(X=>X.type==="image_url"):[]},[oe,t]),He=w.useMemo(()=>{if(oe)return[];const D=t.content;return Array.isArray(D)?D.filter(X=>X.type==="file"):[]},[oe,t]),De=w.useMemo(()=>{if(oe)return[];const D=t.content;return Array.isArray(D)?D.filter(X=>X.type==="interrupt"):[]},[oe,t]),qe=(b==null?void 0:b.id)??(b==null?void 0:b.interrupt_id),We=js(qe),de=b==null?void 0:b.value,he=w.useMemo(()=>{if(oe)return"";const D=t.content;return Array.isArray(D)?FS(D):""},[oe,t]),Pe=w.useMemo(()=>{if(oe||!p)return[];const X=t.artifact;if(!X)return[];const ne=[],Se=[...Array.isArray(X.plots)?X.plots:[]];for(const Je of Se){const xe=WS(Je);xe&&ne.push(xe)}return ne},[oe,t,p]),Fe=w.useCallback(async()=>{const D=J?he:le;async function X(ne){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(ne);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const Se=new Blob([ne],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":Se})]);return}throw new Error("Clipboard API not supported in this context.")}try{await X(D),O(!0),setTimeout(()=>O(!1),2e3),g==null||g(D)}catch(ne){console.error("Failed to copy:",ne)}},[J,he,le,g]),ot=w.useCallback(()=>{if(!x)return;const D=J?he:le,X="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};x(t.id,D,X)},[x,t.id,J,he,le,t]),Ve=w.useCallback(()=>{m==null||m(n)},[m,n]),Ge=w.useCallback(()=>{const X=te(_?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",Q);switch(Y){case"user":return u.jsx(se.User,{className:X});case"assistant":return u.jsx(se.Bot,{className:X});case"tool":return u.jsx(se.Wrench,{className:X});default:return u.jsx(se.Bot,{className:X})}},[_,Q,Y]),et=w.useCallback(()=>{const D="group relative mb-4 flex w-full";switch(Y){case"user":return te(D,"justify-end");case"assistant":case"tool":case"system":return te(D,"justify-start");default:return D}},[Y]),Tt=w.useCallback(()=>{const D=te("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",_&&"px-3 py-2 text-sm");if(ve)return te(D,"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(Y){case"user":return te(D,"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 te(D,"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 te(D,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return te(D,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return te(D,"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")}},[_,ve,Y]),pt=w.useCallback(async D=>{if(S)return;const X=js((D==null?void 0:D.id)??(D==null?void 0:D.interrupt_id));if(!X){console.warn("Interrupt part missing id",D);return}try{k==null||k(),await z(X,!0)}catch(ne){console.error("Failed to approve interrupt:",ne)}finally{C==null||C()}},[S,C,k,z]),mt=w.useCallback(async D=>{if(S)return;const X=js((D==null?void 0:D.id)??(D==null?void 0:D.interrupt_id));if(!X){console.warn("Interrupt part missing id",D);return}try{k==null||k(),await z(X,!1)}catch(ne){console.error("Failed to reject interrupt:",ne)}finally{C==null||C()}},[S,C,k,z]),bt=w.useCallback(({part:D,i:X})=>{if(D.type==="text"){const ne=D.text??"",Se=ne.trim(),Je=Ca(Se);return Je&&Y!=="tool"?u.jsx(dp,{data:Je},X):Y==="user"&&c&&Se.length>d?u.jsx(YS,{text:Se,expanded:B,onExpandedChange:R,previewLength:d,isCompact:_},X):u.jsx(oo,{content:ne,allowHtml:!1},X)}if(D.type==="image_url"){const ne=D;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:ne.url,alt:ne.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},X)}if(D.type==="file"){const ne=D,Se=ne.name||"file";return u.jsxs("a",{href:ne.url,onClick:Je=>U(Je.nativeEvent,ne,X),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
|
|
136
|
+
`)):r=t(e),r||""}function BS(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function up(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"interrupt":return"interrupt";default:return"unknown"}}).join("|"):"";return`${e.id}:${t}:${n}`}function zS(e){if(!e)return"image/png";const t=e.trim();return t?t.includes("/")?t:`image/${t}`:"image/png"}function US(e){const t=[],n=r=>{r&&r.trim()&&t.push(r.trim())};return e&&(n(e.plotId),n(e.artifactId)),t}function HS({base64:e,url:t,formatHint:n,extras:r}){const o=typeof e=="string"&&e.length>0,s=zS(n),i=o?`data:${s};base64,${e}`:t,a=US(r),l=a.length?a.join(" / "):void 0,c=l?`${l} artifact`:"artifact image";return{src:i,alt:c,label:l}}function WS(e){var s,i;const t=((s=e.content_base64)==null?void 0:s.trim())||void 0,n=((i=e.url)==null?void 0:i.trim())||void 0,r=e.format||e.mimeType||e.mime_type;return HS({base64:t,url:n,formatHint:r,extras:{plotId:e.plotId,artifactId:e.artifactId}})}function VS({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:te("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const Na=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=500,showToolMessages:f=!0,showArtifactPreviews:p=!0,customStyles:h={},onEdit:x,onRegenerate:m,onCancelEdit:y,onCopy:g,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,checkpointCandidates:T=[],activeCheckpointId:I=null,onSelectCheckpoint:A,defaultCheckpointId:j=null,messageParentCheckpointId:$=null}){const[P,O]=w.useState(!1),[F,N]=w.useState("preview"),[B,R]=w.useState(!1),{currentThreadId:Z}=Io(),{respondToInterrupt:z}=Eo(),_=l==="phone"||l==="half-screen",Y=t.role,J=Y==="tool",oe=w.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),ve=!!oe,Re=!(r&&Y!=="user"),{uploadingFiles:V,handleFileClick:U,fileViewerOpen:q,currentFileInfo:L,closeFileViewer:G}=GS({allowFileOpen:Re,currentThreadId:Z}),Q=w.useMemo(()=>{switch(Y){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))]"}},[Y]),le=w.useMemo(()=>{if(oe)return"";const D=t.content;return Array.isArray(D)?$S(D):""},[oe,t]),re=w.useMemo(()=>{if(oe)return{};const D=t.content;return Array.isArray(D)?cp(t):{}},[oe,t]),Ae=w.useMemo(()=>{if(oe)return[];const D=t.content;return Array.isArray(D)?D.filter(X=>X.type==="image_url"):[]},[oe,t]),He=w.useMemo(()=>{if(oe)return[];const D=t.content;return Array.isArray(D)?D.filter(X=>X.type==="file"):[]},[oe,t]),De=w.useMemo(()=>{if(oe)return[];const D=t.content;return Array.isArray(D)?D.filter(X=>X.type==="interrupt"):[]},[oe,t]),qe=(b==null?void 0:b.id)??(b==null?void 0:b.interrupt_id),We=js(qe),de=b==null?void 0:b.value,he=w.useMemo(()=>{if(oe)return"";const D=t.content;return Array.isArray(D)?FS(D):""},[oe,t]),Pe=w.useMemo(()=>{if(oe||!p)return[];const X=t.artifact;if(!X)return[];const ne=[],Se=[...Array.isArray(X.plots)?X.plots:[]];for(const Je of Se){const xe=WS(Je);xe&&ne.push(xe)}return ne},[oe,t,p]),Fe=w.useCallback(async()=>{const D=J?he:le;async function X(ne){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(ne);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const Se=new Blob([ne],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":Se})]);return}throw new Error("Clipboard API not supported in this context.")}try{await X(D),O(!0),setTimeout(()=>O(!1),2e3),g==null||g(D)}catch(ne){console.error("Failed to copy:",ne)}},[J,he,le,g]),ot=w.useCallback(()=>{if(!x)return;const D=J?he:le,X="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};x(t.id,D,X)},[x,t.id,J,he,le,t]),Ve=w.useCallback(()=>{m==null||m(n)},[m,n]),Ge=w.useCallback(()=>{const X=te(_?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",Q);switch(Y){case"user":return u.jsx(se.User,{className:X});case"assistant":return u.jsx(se.Bot,{className:X});case"tool":return u.jsx(se.Wrench,{className:X});default:return u.jsx(se.Bot,{className:X})}},[_,Q,Y]),et=w.useCallback(()=>{const D="group relative mb-4 flex w-full";switch(Y){case"user":return te(D,"justify-end");case"assistant":case"tool":case"system":return te(D,"justify-start");default:return D}},[Y]),Tt=w.useCallback(()=>{const D=te("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",_&&"px-3 py-2 text-sm");if(ve)return te(D,"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(Y){case"user":return te(D,"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 te(D,"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 te(D,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return te(D,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return te(D,"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")}},[_,ve,Y]),pt=w.useCallback(async D=>{if(S)return;const X=js((D==null?void 0:D.id)??(D==null?void 0:D.interrupt_id));if(!X){console.warn("Interrupt part missing id",D);return}try{k==null||k(),await z(X,!0)}catch(ne){console.error("Failed to approve interrupt:",ne)}finally{C==null||C()}},[S,C,k,z]),mt=w.useCallback(async D=>{if(S)return;const X=js((D==null?void 0:D.id)??(D==null?void 0:D.interrupt_id));if(!X){console.warn("Interrupt part missing id",D);return}try{k==null||k(),await z(X,!1)}catch(ne){console.error("Failed to reject interrupt:",ne)}finally{C==null||C()}},[S,C,k,z]),bt=w.useCallback(({part:D,i:X})=>{if(D.type==="text"){const ne=D.text??"",Se=ne.trim(),Je=Ca(Se);return Je&&Y!=="tool"?u.jsx(dp,{data:Je},X):Y==="user"&&c&&Se.length>d?u.jsx(YS,{text:Se,expanded:B,onExpandedChange:R,previewLength:d,isCompact:_},X):u.jsx(oo,{content:ne,allowHtml:!1},X)}if(D.type==="image_url"){const ne=D;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:ne.url,alt:ne.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},X)}if(D.type==="file"){const ne=D,Se=ne.name||"file";return u.jsxs("a",{href:ne.url,onClick:Je=>U(Je.nativeEvent,ne,X),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
|
|
137
137
|
dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[V[X]?u.jsx(se.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[Se,V[X]?" (processing)":""]})]},X)}if(D.type==="interrupt"){const ne=D,Se=js((ne==null?void 0:ne.id)??(ne==null?void 0:ne.interrupt_id)),Je=!!(We&&Se&&Se===We),xe=Je?de??(ne==null?void 0:ne.value):ne==null?void 0:ne.value,ut=Se?{...ne,id:Se,interrupt_id:Se}:ne;return u.jsx(qS,{interruptPart:ut,onApprove:pt,onReject:mt,disabled:S,isActive:Je,payload:xe},X)}return null},[U,V,pt,mt,Y,c,d,B,_,We,de,b,S,De]),St=w.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(se.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),Lt=w.useCallback(()=>{const D=le.trim().length>0||Ae.length>0||He.length>0||De.length>0;if(!J&&He.length>0&&!r)return St();if(!J&&!D&&!r)return null;if(J)return!f&&Pe.length>0?null:f?u.jsx(XS,{message:t,viewMode:F},t.id):null;if(!J&&!oe){const X=t,ne=u.jsx("div",{className:"space-y-2",children:X.content.map((Se,Je)=>u.jsx(bt,{part:Se,i:Je},Je))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[ne,u.jsx(VS,{className:Q})]}):ne}},[le,Ae.length,He.length,De.length,r,J,F,f,Pe.length,St,Q]),Pt=w.useMemo(()=>oe?"Assistant":BS(t),[oe,t]),tt=w.useMemo(()=>oe?[]:Array.isArray(T)?T:[],[T,oe]),Et=w.useMemo(()=>{var D;return tt.length?j&&tt.some(X=>X.id===j)?j:((D=tt[0])==null?void 0:D.id)??null:null},[j,tt]),Xe=w.useMemo(()=>!tt.length||!I?null:tt.some(D=>D.id===I)?I:null,[I,tt])??Et,nt=Y==="user"&&tt.length>0&&typeof A=="function",ht=w.useCallback((D,X=!1)=>{if(!A)return;const ne=(D==null?void 0:D.id)??null,Se=(D==null?void 0:D.parentId)??$??null;A(ne,Se,X)},[$,A]),W=w.useMemo(()=>Xe?tt.findIndex(D=>D.id===Xe):-1,[Xe,tt]),ie=w.useMemo(()=>W<0?null:tt[W]??null,[W,tt]);return J&&!f&&Pe.length===0?null:ve&&oe?u.jsx("div",{className:te(et(),h.container),children:u.jsxs("div",{className:te(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(se.Bot,{className:te("h-4 w-4",Q)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(oo,{content:oe.content,className:"text-current"})]})}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:te(et(),h.container),children:u.jsxs("div",{className:te(Tt(),h.content),children:[(i||a||J)&&u.jsxs("div",{className:te("flex items-center justify-between mb-2 pb-2 border-b border-current/10",_&&"mb-1 pb-1",Q,h.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[Ge(),a&&Pt&&u.jsx("span",{className:te("font-medium",_?"text-xs":"text-sm"),children:Pt}),J&&u.jsxs(Sf,{variant:"outline",className:te("text-xs flex items-center gap-1 cursor-pointer select-none",Q,"border border-current/40",_&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":F==="expanded",onClick:()=>N(D=>D==="expanded"?"preview":"expanded"),onKeyDown:D=>{(D.key==="Enter"||D.key===" ")&&(D.preventDefault(),N(X=>X==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:re.name??"Tool Output"}),re.toolCallId&&u.jsx("span",{className:"opacity-70",children:re.toolCallId.slice(0,8)}),F==="expanded"?u.jsx(se.ChevronUp,{className:"h-3 w-3"}):u.jsx(se.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[nt&&ie&&W>=0&&u.jsx("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("button",{type:"button",className:te("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",W<tt.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(W>=tt.length-1)return;const D=tt[W+1];D&&ht(D)},"aria-label":"Older checkpoint (back in time)",disabled:W>=tt.length-1,children:u.jsx(se.ChevronLeft,{className:"h-3 w-3"})}),u.jsx("div",{className:"flex items-center gap-2",children:u.jsxs("span",{className:"whitespace-nowrap",children:[tt.length-W," / ",tt.length]})}),u.jsx("button",{type:"button",className:te("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",W>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(!(W<=0))if(W===1)ht(null,!0);else{const D=tt[W-1];D&&ht(D,!1)}},"aria-label":"Newer checkpoint (forward in time)",disabled:W<=0,children:u.jsx(se.ChevronRight,{className:"h-3 w-3"})})]})}),i&&t.createdAt&&u.jsx("time",{className:te("text-xs opacity-60",Q,_&&"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:te("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:()=>Fe(),className:te("h-6 w-6 p-0 hover:bg-foreground/10",Q,_&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(se.Copy,{className:te(P?"text-success":Q,_?"h-3 w-3":"h-4 w-4")})})}),Y==="user"&&x&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:ot,className:te("h-6 w-6 p-0 hover:bg-foreground/10",Q,_&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(se.Edit,{className:te(Q,_?"h-3 w-3":"h-4 w-4")})}),Y==="assistant"&&m&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:Ve,className:te("h-6 w-6 p-0 hover:bg-foreground/10",Q,_&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(se.RotateCcw,{className:te(Q,_?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsxs("div",{className:"relative",children:[Lt(),p&&Pe.length>0&&u.jsx("div",{className:"mt-3 space-y-4",children:Pe.map((D,X)=>u.jsx(KS,{preview:D,idx:X},`artifact-${X}`))})]}),J&&F==="expanded"&&(re.toolCallId||re.name)&&u.jsxs("div",{className:te("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",_&&"text-xs"),children:[re.name&&u.jsxs("div",{children:["Function: ",re.name]}),re.toolCallId&&u.jsxs("div",{children:["Call ID: ",re.toolCallId]})]}),!(i||a||J)&&s&&!o&&u.jsxs("div",{className:te("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:()=>Fe(),className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",_&&"h-5 w-5"),children:u.jsx(se.Copy,{className:te(P?"text-success":"text-current",_?"h-3 w-3":"h-4 w-4")})}),Y==="user"&&x&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:ot,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",_&&"h-5 w-5"),children:u.jsx(se.Edit,{className:te("text-current",_?"h-3 w-3":"h-4 w-4")})}),Y==="assistant"&&m&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:Ve,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",_&&"h-5 w-5"),children:u.jsx(se.RotateCcw,{className:te("text-current",_?"h-3 w-3":"h-4 w-4")})})]})]})}),L&&u.jsx(vS,{isOpen:q,onClose:G,fileId:L.id,fileName:L.name,mimeType:L.mimeType})]})},(e,t)=>{var i,a,l,c,d,f,p,h;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&up(e.message)===up(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages","attemptMeta"].every(x=>e[x]===t[x]),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)&&((p=e.customStyles)==null?void 0:p.header)===((h=t.customStyles)==null?void 0:h.header);return o&&s});function KS({preview:e,idx:t}){return w.useEffect(()=>{sS()&&console.debug(`[MessageComponent] Preview ${t} mounted:`,{src:e.src.substring(0,100),alt:e.alt,label:e.label})},[t,e]),u.jsxs("div",{className:"space-y-2",children:[e.label&&u.jsxs("p",{className:"text-[0.65rem] uppercase tracking-wide text-muted-foreground",children:["Artifact: ",e.label]}),u.jsx("div",{className:"overflow-hidden rounded border border-border/60 bg-background/60 p-1 shadow-sm",children:u.jsx("img",{src:e.src,alt:e.alt,title:e.label,loading:"lazy",className:"h-auto max-h-[420px] w-full rounded object-contain",onLoad:()=>{},onError:n=>{console.error(`[MessageComponent] ❌ Image failed to load for artifact ${t}:`,{alt:e.alt,label:e.label,message:n.target.alt})}})})]})}function dp({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:LS,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:ro(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:ro(e)})}function qS({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=ro(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(Jr,{className:te("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(Zr,{className:"pb-3",children:[u.jsx(Qr,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(Cf,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(eo,{className:"pt-0 pb-3",children:a}),u.jsx(Tf,{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 GS(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=Sa(),[o,s]=w.useState({}),[i,a]=w.useState(null),[l,c]=w.useState(!1),d=w.useCallback(()=>{c(!1),a(null)},[]),f=w.useCallback(h=>{a(h),c(!0)},[]),p=w.useCallback(async(h,x,m)=>{var y,g;if(!t){h.preventDefault();return}if(o[m]){h.preventDefault();return}try{const b=String(x.url??""),S=b.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){h.preventDefault();const k=S[1],C=x.name||`file_${k}`,T=x.mimeType||"application/octet-stream";f({id:k,name:C,mimeType:T});return}if(b.startsWith("data:")){h.preventDefault(),s(C=>({...C,[m]:!0}));const k=r({title:"Fetching file...",description:"",open:!0});try{const C=await K0(n??void 0);if(!C||!Array.isArray(C))throw new Error("Invalid file list response");const T=C.find(I=>!I||typeof I!="object"||!((I.filename??"")===(x.name??""))?!1:typeof x.size=="number"&&typeof I.size=="number"?I.size===x.size:!0);if(!(T!=null&&T.id))throw new Error(`File "${x.name}" is not yet available on the server`);if(!T.id||!T.filename)throw new Error("Invalid file data received from server");f({id:T.id,name:x.name||T.filename||`file_${T.id}`,mimeType:x.mimeType||T.mime_type||"application/octet-stream"}),(y=k.update)==null||y.call(k,{id:k.id,title:"Success",description:`Opened ${x.name}`,open:!0})}catch(C){console.error("Failed to fetch server file:",C);const T=C instanceof Error?C.message:"Unknown error occurred";(g=k.update)==null||g.call(k,{id:k.id,title:"Failed",description:T}),r({title:"Failed to fetch file",description:T,open:!0})}finally{s(C=>({...C,[m]:!1}))}}}catch(b){console.error("File click error:",b),s(S=>({...S,[m]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:p,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function YS({text:e,expanded:t,onExpandedChange:n,previewLength:r,isCompact:o}){const s=Math.max(e.length-r,0),i=e.substring(0,r);return u.jsxs("div",{className:"flex flex-col gap-1",children:[u.jsx("div",{className:te("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(oo,{content:e,allowHtml:!1}):u.jsxs("pre",{className:te("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:[i,"..."]})}),u.jsx(Ze,{type:"button",variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",onClick:()=>n(!t),children:t?u.jsxs(u.Fragment,{children:[u.jsx(se.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(se.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function XS({message:e,viewMode:t}){const r=cp(e).name||"tool",o=c=>{if(c==null)return null;const d=typeof c=="string"?Ca(c)??c:c;if(d&&typeof d=="object")return u.jsx(dp,{data:d});const f=typeof d=="string"?d:(()=>{try{return ro(d)}catch{return String(d??"")}})();return u.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm text-foreground/90",children:f})},s=c=>{if(c==null)return null;const{content:d,isMarkdown:f}=eS(c);return f?u.jsx(oo,{content:d,className:"text-current"}):o(c)};if(t==="preview")return null;const i=e.content.find(c=>c.type!=="tool_call");if(!i)return u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(se.Loader,{className:"h-4 w-4 animate-spin"}),u.jsxs("span",{children:["Waiting for ",r," output…"]})]});if(i.type==="text"){const d=(i.text??"").trim();if(!d)return null;const f=ws(d);return s(f)}const a=no(i),l=ws(a);return s(l)}const JS=({timelineEntries:e,activeCheckpointId:t,onSelectCheckpoint:n,messagePreviews:r})=>{const o=e??[],s=o.length>0,i=w.useMemo(()=>s?[...o].reverse():[],[o,s]),a=t??(o.length?o[o.length-1].id:null);return w.useEffect(()=>{console.debug("[TimelineColumn] entries:",o.length)},[o.length]),s?u.jsxs("div",{className:"w-32 flex-shrink-0 flex-col border-r border-border/40 pr-2 flex",children:[u.jsxs("div",{className:"relative flex-1 overflow-y-auto pt-4 pb-2 pr-1",children:[u.jsxs("div",{className:"absolute left-0 right-0 top-1 flex items-center justify-between px-2 pb-3 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:[u.jsx("span",{children:"Timeline"}),u.jsxs("div",{className:"group relative z-50",children:[u.jsx(se.Info,{className:"h-3 w-3 text-muted-foreground cursor-help"}),u.jsx("div",{className:"pointer-events-auto fixed hidden w-56 rounded-md border bg-background p-3 text-[10px] font-normal text-muted-foreground shadow-lg group-hover:block whitespace-normal leading-relaxed",style:{zIndex:9999},children:"Backend pre-selects user inputs + latest loop checkpoint. Click a dot to jump, or use “Latest” to return to the newest messages."})]})]}),u.jsx("div",{className:"pointer-events-none absolute left-3 top-0 bottom-0 w-px bg-border/40"}),u.jsx("div",{className:"flex flex-col gap-3 pt-6 pr-2",children:i.map(l=>{const c=a===l.id,d=l.messageId?(r==null?void 0:r.get(l.messageId))??null:null;return u.jsxs("button",{type:"button",disabled:!n,onClick:()=>n==null?void 0:n(l.id),className:`relative flex items-start gap-2 text-left text-[11px] transition ${c?"text-primary":"text-muted-foreground"} ${n?"hover:text-foreground":"cursor-default opacity-70"}`,children:[u.jsx("span",{className:`mt-1 inline-flex h-3 w-3 items-center justify-center rounded-full border ${c?"border-primary bg-primary/10 text-primary":"border-border bg-background"}`,children:u.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${c?"bg-primary":"bg-border"}`})}),u.jsxs("span",{className:"flex-1",children:[u.jsx("span",{className:"block font-medium leading-tight",children:l.label||"User input"}),u.jsxs("span",{className:"text-[9px] uppercase tracking-wide text-muted-foreground/70",children:[l.step!==null?`STEP ${l.step}`:"STEP —",l.next?` - ${l.next}`:""]}),d&&u.jsx("p",{className:"text-[10px] text-muted-foreground/80 mt-1 line-clamp-2",title:d,children:d})]})]},l.id)})})]}),n&&u.jsx("button",{type:"button",onClick:()=>n==null?void 0:n(null),className:"mt-auto mb-3 rounded-md border border-border/70 px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground transition hover:border-foreground/60 hover:text-foreground",children:"Latest"})]}):null},fp=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,_a=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:p,emptyMessage:h,followNewMessages:x=!0,isNavigatingCheckpoint:m=!1,onScrollAway:y,onAtBottom:g,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T=!0,showArtifactPreviews:I=!0,checkpointMetaById:A,checkpointIndexByKey:j,attemptMetaById:$,userMessageIdToAttempts:P,activeCheckpointId:O,onSelectCheckpoint:F,timelineCheckpoints:N,messagePreviews:B,createSyntheticThinkingMessage:R=!1},Z)=>{const z=w.useRef(null),_=w.useRef(null),Y=w.useRef(!1),[J,oe]=w.useState(!0),ve=w.useMemo(()=>b?e.some(de=>"type"in de&&de.type==="default_message"?!1:Array.isArray(de==null?void 0:de.content)&&de.content.some(he=>he&&he.type==="interrupt"&&(he.id??he.interrupt_id)===b.id)):!1,[b,e]),Re=w.useMemo(()=>{if(!b||ve)return null;const de=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let he;const Pe=b.value;if(Pe&&typeof Pe=="object"&&!Array.isArray(Pe)){const Fe=Pe.title;typeof Fe=="string"&&Fe.trim()&&(he=Fe.trim())}return{id:`interrupt-${de}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:de,value:Pe,title:he}]}},[b,ve]),V=w.useMemo(()=>Re?[...e,Re]:e,[e,Re]),U=w.useMemo(()=>!R||!t?V:!V.some(he=>he.role==="assistant")&&V.length>0?[...V,{id:"thinking-assistant",role:"assistant",content:[],createdAt:new Date().toISOString()}]:V,[V,t,R]),q=w.useMemo(()=>T?U:U.filter(de=>(de==null?void 0:de.role)!=="tool"),[U,T]),L=w.useCallback(de=>{oe(de),y&&y(!de),g&&g(de)},[y,g]),G=w.useMemo(()=>{if(a)return async()=>{if(!Y.current){Y.current=!0;try{await a()}finally{Y.current=!1}}}},[a]),Q=w.useMemo(()=>!x||m?!1:J?"auto":!1,[J,x,m]),le=N??[],re=le.length>0,Ae=w.useMemo(()=>{if(typeof h!="string")return null;const de=h.trim();return de?{id:"default-message",role:"assistant",type:"default_message",content:de,createdAt:new Date().toISOString()}:null},[h]),He=re?u.jsx(JS,{timelineEntries:le,activeCheckpointId:O??null,onSelectCheckpoint:F,messagePreviews:B}):null,De=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),qe=()=>Ae?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Na,{message:Ae,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{},showArtifactPreviews:I})})}):u.jsx("div",{className:"flex h-full items-center justify-center py-8 text-center text-muted-foreground",children:h??"No messages yet. Start a conversation!"}),We=q.length>0;return w.useImperativeHandle(Z,()=>({scrollToLatest:()=>{var de,he;if(z.current&&q.length>0){const Pe=q.length-1;(he=(de=z.current).scrollToIndex)==null||he.call(de,{index:Pe,align:"end",behavior:"auto"})}else _.current&&(_.current.scrollTop=_.current.scrollHeight)},scrollToTop:()=>{var de,he;z.current&&q.length>0?(he=(de=z.current).scrollToIndex)==null||he.call(de,{index:0,align:"start",behavior:"auto"}):_.current&&(_.current.scrollTop=0)}}),[q]),u.jsxs("div",{className:De,style:p,children:[He,u.jsx("div",{className:"relative flex-1 min-h-0",children:We?u.jsx(_0,{ref:de=>{z.current=de},scrollerRef:de=>{_.current=de instanceof HTMLDivElement?de:null},data:q,followOutput:Q,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!0,startReached:()=>{G&&G()},atBottomStateChange:L,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(de,he)=>fp(he,de),itemContent:(de,he)=>{const Pe=fp(he,de),Fe="type"in he&&he.type==="default_message",{checkpointCandidates:ot,defaultCheckpointId:Ve,attemptMeta:Ge}=bw(he,{checkpointMetaById:A,checkpointIndexByKey:j,attemptMetaById:$,userMessageIdToAttempts:P}),et=he&&!Fe?he.additionalKwargs??{}:{},Tt=he&&!Fe?he.responseMetadata??{}:{},pt=(()=>{if(typeof et.parentCheckpointId=="string")return et.parentCheckpointId;if(typeof Tt.parentCheckpointId=="string")return Tt.parentCheckpointId})();return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":Pe,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Na,{message:he,messageIndex:de,isStreamingMessage:t&&n===he.id,streamingDebounceMs:r,isEditing:i===he.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:l,onRegenerate:()=>c(de),onCancelEdit:d,activeInterrupt:b,disableInterruptActions:S,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T,showArtifactPreviews:I,checkpointCandidates:ot,activeCheckpointId:O??null,onSelectCheckpoint:F,defaultCheckpointId:Ve,messageParentCheckpointId:pt,attemptMeta:Ge})})}}):qe()})]})});_a.displayName="MessageList";const pp={value:""};function Rs({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:c=!0,showToolMessages:d=!0,showArtifactPreviews:f=!0,customStyles:p={},onMessageSent:h,onExcelUploadSuccess:x,onError:m}){const{api:y}=li(),{currentThreadId:g}=Io(),{threadId:b,messages:S,isHistoryLoading:k,isLoading:C,navigateToCheckpoint:T,returnToLatest:I,checkpoint:A,checkpoints:j,interrupt:$,metadata:P,timelineCheckpoints:O,messagePreviews:F}=Eo(),{isStreaming:N,error:B,connectionState:R,submit:Z,stop:z}=cc(),_=b??g??null,Y=(A==null?void 0:A.id)??null,J=(A==null?void 0:A.namespace)??null,oe=(P==null?void 0:P.assemblingMessageId)??null,ve=$,[Re,V]=w.useState(!1);w.useEffect(()=>{ve||V(!1)},[ve]);const U=w.useCallback(()=>{V(!0)},[]),q=w.useCallback(()=>{V(!1)},[]),L=!!ve||Re,[G,Q]=w.useState(null),[le,re]=w.useState(""),[Ae,He]=w.useState(null),[De,qe]=w.useState(null),[We,de]=w.useState([]),[he,Pe]=w.useState(0),[Fe,ot]=w.useState(0),[Ve,Ge]=w.useState(!1),[et,Tt]=w.useState(null),[pt,mt]=w.useState(null),[bt,St]=w.useState(!1),[Lt,Pt]=w.useState(null),tt=w.useRef(!1),[Et,vn]=w.useState(()=>pp.value),Xe=w.useRef(Et),nt=w.useRef(null),ht=w.useCallback(pe=>{pp.value=pe,vn(pe)},[]),[W,ie]=w.useState(!1),D=w.useRef(null),{checkpointMetaById:X,checkpointIndexByKey:ne,attemptMetaById:Se,userMessageIdToAttempts:Je}=gw(j),xe=O??[],ut=w.useRef(null),be=w.useRef(null),rt=w.useCallback(()=>{ut.current&&(ut.current.value=""),be.current&&(be.current.value=""),Pe(pe=>pe+1),ot(pe=>pe+1)},[]),io=w.useCallback(pe=>{ht(pe)},[ht]),ao=w.useRef(!1);w.useEffect(()=>{ao.current&&!N&&(de([]),rt()),ao.current=N},[N,rt]);const[Hs,Va]=w.useState("desktop");w.useEffect(()=>{const pe=()=>{const Te=window.innerWidth;Va(Te<640?"phone":Te<1024?"tablet":"desktop")};return pe(),window.addEventListener("resize",pe),()=>window.removeEventListener("resize",pe)},[]),w.useEffect(()=>{tt.current=!1},[_]),w.useEffect(()=>{Xe.current=Et},[Et]),w.useEffect(()=>{if(!G){nt.current=null;return}nt.current===null&&(nt.current=Xe.current),ht(le??"")},[le,G,ht]),w.useEffect(()=>{(async()=>{if(!y.baseUrl){Pt(null);return}try{const Ee=(await y.getAgent("default")).uiDefaultMessage||"";Pt(Ee||null)}catch(Te){console.warn("Failed to fetch default message:",Te),Pt(null)}})()},[y.baseUrl]),w.useEffect(()=>{B&&!bt&&(m==null||m(B))},[B,bt,m]);const Ka=pe=>{if(pe.length>ss)return`Message too long (${pe.length}/${ss} characters)`;try{return vw(pe),null}catch(Te){return(Te==null?void 0:Te.message)||"Invalid message"}},qa=async pe=>{const Te=pe.trim();if(!(!Te&&We.length===0)){if(Te){const Ee=Ka(Te);if(Ee){qe(Ee);return}}try{const Ee=Y??void 0,Be=J??void 0,Fn=G?{edit:!0,originalMessageId:G,...Ae!=null&&Ae.checkpointId?{originalCheckpointId:Ae.checkpointId}:{},...Ae!=null&&Ae.checkpointNs?{originalCheckpointNs:Ae.checkpointNs}:{}}:void 0;await Z({text:Te||"",attachments:We,messageAdditionalKwargs:Fn},{checkpointId:Ee,checkpointNs:Be}),h==null||h(Te),ht(""),qe(null),de([]),rt(),Q(null),re(""),He(null)}catch(Ee){const Be=(Ee==null?void 0:Ee.message)||"Failed to send message";qe(Be),m==null||m(Be)}}},Ws=w.useCallback((pe,Te,Ee)=>{c&&(nt.current=Et,Q(pe),re(Te),ht(Te),qe(null),He({checkpointId:(Ee==null?void 0:Ee.checkpointId)??null,checkpointNs:(Ee==null?void 0:Ee.checkpointNs)??null}))},[Et,c,ht]),E=w.useCallback(()=>{Q(null),re(""),He(null),qe(null),ht(nt.current??Et),nt.current=null},[Et,ht]),K=w.useCallback((pe,Te,Ee)=>{Ws(pe,Te,Ee)},[Ws]),ae=w.useCallback(pe=>{let Te=null,Ee=null;for(let ln=pe-1;ln>=0;ln--)if(S[ln].role==="user"){Te=S[ln],Ee=S[ln].id;break}if(!Te||!Ee)return;const Be=Array.isArray(Te.content)?Te.content:[],Vs=Be.filter(ln=>(ln==null?void 0:ln.type)==="text").map(ln=>ln.text).join("")||(()=>{try{return JSON.stringify(Be,null,2)}catch{return String(Be)}})();if(!Vs)return;const Bn=Ug(j,Ee),dT=(Bn==null?void 0:Bn.checkpointId)??Y??void 0,fT=(Bn==null?void 0:Bn.checkpointNs)??J??void 0;Z({text:Vs},{checkpointId:dT,checkpointNs:fT})},[S,Z,j,Y,J]),Ce=pe=>{const Te=Array.from(pe.target.files||[]);de(Ee=>[...Ee,...Te]),pe.target.value=""},Ye=pe=>{de(Te=>{const Ee=Te.filter((Be,Fn)=>pe!==Fn);return Ee.length===0&&rt(),Ee})},st=async pe=>{const Te=(pe.target.files||[])[0];if(Te){Tt(null),mt(null),Ge(!0);try{await Z({attachments:[Te]},{checkpointId:Y??void 0,checkpointNs:J??void 0});const Ee=`Uploaded ${Te.name} - processing through chat stream`;mt(Ee)}catch(Ee){const Be=Ee instanceof Error?Ee.message:"Failed to upload Excel file";console.error("Excel upload failed",Ee),Tt(Be),m==null||m(Be)}finally{Ge(!1),pe.target.value="",rt()}}},$e=async pe=>{if(g){ie(!0);try{if(!pe){await I(),requestAnimationFrame(()=>{var Be;(Be=D.current)==null||Be.scrollToLatest()});return}const Te=j.find(Be=>Be.checkpointId===pe),Ee=(Te==null?void 0:Te.checkpointNs)??null;await T(pe,Ee),requestAnimationFrame(()=>{var Be;(Be=D.current)==null||Be.scrollToTop()})}finally{ie(!1)}}},Le=w.useCallback(async(pe,Te,Ee)=>{await $e(Ee?null:pe)},[$e]),At=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${p.container||""}`,gt=`flex-1 min-h-0 min-w-0 max-h-full w-full overflow-hidden overscroll-contain break-words break-anywhere p-4 bg-transparent ${p.messagesArea||""}`,xt=`flex-shrink-0 w-full border-t p-4 bg-transparent ${p.inputArea||""}`;return u.jsxs("div",{className:At,children:[!!B&&!bt&&u.jsxs("div",{className:"flex-shrink-0 bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[u.jsx("span",{children:B}),u.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>St(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(se.X,{size:16})})]}),u.jsxs("div",{className:`relative ${gt}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(_a,{ref:D,className:"h-full",style:{height:"100%"},messages:S,isStreaming:N,streamingAssistantId:oe,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:Hs,enableMessageEditing:c,editingMessageId:G,onEdit:K,onRegenerate:ae,onCancelEdit:E,emptyMessage:Lt??void 0,isNavigatingCheckpoint:W,activeInterrupt:ve,disableInterruptActions:Re,onInterruptActionStart:U,onInterruptActionEnd:q,showToolMessages:d,showArtifactPreviews:f,checkpointMetaById:X,checkpointIndexByKey:ne,attemptMetaById:Se,userMessageIdToAttempts:Je,activeCheckpointId:Y,onSelectCheckpoint:Le,timelineCheckpoints:xe,messagePreviews:F}),(R==="reconnecting"||R==="connecting")&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-muted/80 px-3 py-1 text-xs font-medium text-foreground shadow-sm backdrop-blur-sm dark:bg-muted/60",children:u.jsxs("span",{className:"flex items-center gap-2",children:[u.jsx(se.Loader2,{className:"h-3 w-3 animate-spin"}),R==="reconnecting"?"Reconnecting…":"Connecting…"]})}),R==="error"&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-destructive/10 px-3 py-1 text-xs font-semibold text-destructive shadow-sm",children:"Connection lost"}),C&&u.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[u.jsx(se.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]}),(k||W)&&u.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[u.jsx(se.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading checkpoint…"})]})]}),u.jsxs("div",{className:xt,children:[G&&u.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx(se.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(Ze,{variant:"ghost",size:"sm",onClick:E,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(se.X,{size:16})})]})}),(a||l)&&u.jsxs("div",{className:"mb-3 space-y-3",children:[a&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:ut,type:"file",multiple:!0,onChange:pe=>Ce(pe),className:"hidden"},he),We.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:We.map((pe,Te)=>u.jsxs("div",{className:"flex items-center gap-2 bg-gray-100 dark:bg-gray-800 rounded-lg px-3 py-2 text-sm text-gray-900 dark:text-gray-100",children:[u.jsx(se.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:pe.name}),u.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>Ye(Te),className:"h-4 w-4 p-0 text-gray-500 dark:text-gray-400 hover:text-red-500 dark:hover:text-red-400","aria-label":`Remove ${pe.name}`,children:u.jsx(se.X,{size:12})})]},Te))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:be,type:"file",accept:".xls,.xlsx,.xlsm",onChange:st,className:"hidden"},Fe),Ve&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(se.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),pt&&!Ve&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:pt}),et&&!Ve&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:et})]})]}),De&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:De}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(nw,{children:[u.jsx(rw,{asChild:!0,children:u.jsx(Ze,{type:"button",size:"icon",variant:"outline",disabled:N||L,title:"More input actions",className:p.moreButton||"",children:u.jsx(se.Plus,{size:16})})}),u.jsxs(bd,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(Xi,{onClick:()=>{var pe;return(pe=ut.current)==null?void 0:pe.click()},className:"cursor-pointer",children:[u.jsx(se.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(Xi,{onClick:()=>{var pe;Ve||(pe=be.current)==null||pe.click()},className:`cursor-pointer ${Ve?"opacity-60 pointer-events-none":""}`,children:[u.jsx(se.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(rx,{initialValue:le,editingMessageId:G,value:Et,onValueChange:io,placeholder:G?"Edit your message...":t,isStreaming:N,disabled:L,maxLength:ss,onSend:qa,onCancelEdit:E,onStop:z,allowEmptySend:We.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${G?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${De?"border-red-400":""} ${p.textarea||""}`})})]})]})]})}const Ps=v.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:te("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),ref:r,...n}));Ps.displayName="Input";function ja(e,[t,n]){return Math.min(n,Math.max(t,e))}function ZS(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Ra="ScrollArea",[hp,UT]=wn(Ra),[QS,Zt]=hp(Ra),mp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=v.useState(null),[c,d]=v.useState(null),[f,p]=v.useState(null),[h,x]=v.useState(null),[m,y]=v.useState(null),[g,b]=v.useState(0),[S,k]=v.useState(0),[C,T]=v.useState(!1),[I,A]=v.useState(!1),j=ze(t,P=>l(P)),$=No(o);return u.jsx(QS,{scope:n,type:r,dir:$,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:p,scrollbarX:h,onScrollbarXChange:x,scrollbarXEnabled:C,onScrollbarXEnabledChange:T,scrollbarY:m,onScrollbarYChange:y,scrollbarYEnabled:I,onScrollbarYEnabledChange:A,onCornerWidthChange:b,onCornerHeightChange:k,children:u.jsx(_e.div,{dir:$,...i,ref:j,style:{position:"relative","--radix-scroll-area-corner-width":g+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});mp.displayName=Ra;var gp="ScrollAreaViewport",xp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=Zt(gp,n),a=v.useRef(null),l=ze(t,a,i.onViewportChange);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:o}),u.jsx(_e.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:u.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});xp.displayName=gp;var yn="ScrollAreaScrollbar",Pa=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Zt(yn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return v.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?u.jsx(eC,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(tC,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(yp,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Ma,{...r,ref:t}):null});Pa.displayName=yn;var eC=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Zt(yn,e.__scopeScrollArea),[s,i]=v.useState(!1);return v.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const c=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",c),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",c),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),u.jsx(Gt,{present:n||s,children:u.jsx(yp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),tC=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Zt(yn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Ls(()=>l("SCROLL_END"),100),[a,l]=ZS("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return v.useEffect(()=>{if(a==="idle"){const c=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[a,o.scrollHideDelay,l]),v.useEffect(()=>{const c=o.viewport,d=s?"scrollLeft":"scrollTop";if(c){let f=c[d];const p=()=>{const h=c[d];f!==h&&(l("SCROLL"),i()),f=h};return c.addEventListener("scroll",p),()=>c.removeEventListener("scroll",p)}},[o.viewport,s,l,i]),u.jsx(Gt,{present:n||a!=="hidden",children:u.jsx(Ma,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:fe(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:fe(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),yp=v.forwardRef((e,t)=>{const n=Zt(yn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=v.useState(!1),a=e.orientation==="horizontal",l=Ls(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return wr(n.viewport,l),wr(n.content,l),u.jsx(Gt,{present:r||s,children:u.jsx(Ma,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Ma=v.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=Zt(yn,e.__scopeScrollArea),s=v.useRef(null),i=v.useRef(0),[a,l]=v.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=Cp(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:c>0&&c<1,onThumbChange:p=>s.current=p,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:p=>i.current=p};function f(p,h){return aC(p,i.current,a,h)}return n==="horizontal"?u.jsx(nC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollLeft,h=Tp(p,a,o.dir);s.current.style.transform=`translate3d(${h}px, 0, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollLeft=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollLeft=f(p,o.dir))}}):n==="vertical"?u.jsx(rC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollTop,h=Tp(p,a);s.current.style.transform=`translate3d(0, ${h}px, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollTop=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollTop=f(p))}}):null}),nC=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Zt(yn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=ze(t,l,s.onScrollbarXChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(bp,{"data-orientation":"horizontal",...o,ref:c,sizes:n,style:{bottom:0,left:s.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:s.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":Ds(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const p=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(p),Ip(p,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:Os(i.paddingLeft),paddingEnd:Os(i.paddingRight)}})}})}),rC=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Zt(yn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=ze(t,l,s.onScrollbarYChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(bp,{"data-orientation":"vertical",...o,ref:c,sizes:n,style:{top:0,right:s.dir==="ltr"?0:void 0,left:s.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":Ds(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const p=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(p),Ip(p,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:Os(i.paddingTop),paddingEnd:Os(i.paddingBottom)}})}})}),[oC,vp]=hp(yn),bp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:c,onWheelScroll:d,onResize:f,...p}=e,h=Zt(yn,n),[x,m]=v.useState(null),y=ze(t,j=>m(j)),g=v.useRef(null),b=v.useRef(""),S=h.viewport,k=r.content-r.viewport,C=It(d),T=It(l),I=Ls(f,10);function A(j){if(g.current){const $=j.clientX-g.current.left,P=j.clientY-g.current.top;c({x:$,y:P})}}return v.useEffect(()=>{const j=$=>{const P=$.target;(x==null?void 0:x.contains(P))&&C($,k)};return document.addEventListener("wheel",j,{passive:!1}),()=>document.removeEventListener("wheel",j,{passive:!1})},[S,x,k,C]),v.useEffect(T,[r,T]),wr(x,I),wr(h.content,I),u.jsx(oC,{scope:n,scrollbar:x,hasThumb:o,onThumbChange:It(s),onThumbPointerUp:It(i),onThumbPositionChange:T,onThumbPointerDown:It(a),children:u.jsx(_e.div,{...p,ref:y,style:{position:"absolute",...p.style},onPointerDown:fe(e.onPointerDown,j=>{j.button===0&&(j.target.setPointerCapture(j.pointerId),g.current=x.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",h.viewport&&(h.viewport.style.scrollBehavior="auto"),A(j))}),onPointerMove:fe(e.onPointerMove,A),onPointerUp:fe(e.onPointerUp,j=>{const $=j.target;$.hasPointerCapture(j.pointerId)&&$.releasePointerCapture(j.pointerId),document.body.style.webkitUserSelect=b.current,h.viewport&&(h.viewport.style.scrollBehavior=""),g.current=null})})})}),Ms="ScrollAreaThumb",wp=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=vp(Ms,e.__scopeScrollArea);return u.jsx(Gt,{present:n||o.hasThumb,children:u.jsx(sC,{ref:t,...r})})}),sC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=Zt(Ms,n),i=vp(Ms,n),{onThumbPositionChange:a}=i,l=ze(t,f=>i.onThumbChange(f)),c=v.useRef(void 0),d=Ls(()=>{c.current&&(c.current(),c.current=void 0)},100);return v.useEffect(()=>{const f=s.viewport;if(f){const p=()=>{if(d(),!c.current){const h=lC(f,a);c.current=h,a()}};return a(),f.addEventListener("scroll",p),()=>f.removeEventListener("scroll",p)}},[s.viewport,d,a]),u.jsx(_e.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:l,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:fe(e.onPointerDownCapture,f=>{const h=f.target.getBoundingClientRect(),x=f.clientX-h.left,m=f.clientY-h.top;i.onThumbPointerDown({x,y:m})}),onPointerUp:fe(e.onPointerUp,i.onThumbPointerUp)})});wp.displayName=Ms;var Oa="ScrollAreaCorner",Sp=v.forwardRef((e,t)=>{const n=Zt(Oa,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(iC,{...e,ref:t}):null});Sp.displayName=Oa;var iC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=Zt(Oa,n),[s,i]=v.useState(0),[a,l]=v.useState(0),c=!!(s&&a);return wr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),wr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(_e.div,{...r,ref:t,style:{width:s,height:a,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function Os(e){return e?parseInt(e,10):0}function Cp(e,t){const n=e/t;return isNaN(n)?0:n}function Ds(e){const t=Cp(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function aC(e,t,n,r="ltr"){const o=Ds(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,c=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,f=r==="ltr"?[0,d]:[d*-1,0];return kp([l,c],f)(e)}function Tp(e,t,n="ltr"){const r=Ds(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],c=ja(e,l);return kp([0,i],[0,a])(c)}function kp(e,t){return n=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const r=(t[1]-t[0])/(e[1]-e[0]);return t[0]+r*(n-e[0])}}function Ip(e,t){return e>0&&e<t}var lC=(e,t=()=>{})=>{let n={left:e.scrollLeft,top:e.scrollTop},r=0;return function o(){const s={left:e.scrollLeft,top:e.scrollTop},i=n.left!==s.left,a=n.top!==s.top;(i||a)&&t(),n=s,r=window.requestAnimationFrame(o)}(),()=>window.cancelAnimationFrame(r)};function Ls(e,t){const n=It(e),r=v.useRef(0);return v.useEffect(()=>()=>window.clearTimeout(r.current),[]),v.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function wr(e,t){const n=It(t);kt(()=>{let r=0;if(e){const o=new ResizeObserver(()=>{cancelAnimationFrame(r),r=window.requestAnimationFrame(n)});return o.observe(e),()=>{window.cancelAnimationFrame(r),o.unobserve(e)}}},[e,n])}var Ep=mp,cC=xp,uC=Sp;const Ap=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Ep,{ref:r,className:te("relative overflow-hidden",e),...n,children:[u.jsx(cC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(Np,{}),u.jsx(uC,{})]}));Ap.displayName=Ep.displayName;const Np=v.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(Pa,{ref:r,orientation:t,className:te("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:u.jsx(wp,{className:"relative flex-1 rounded-full bg-border"})}));Np.displayName=Pa.displayName;const _p=25;function Da({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:c,onThreadDelete:d}){const{threads:f,currentThreadId:p,setCurrentThreadId:h,isLoading:x,actions:m}=Io(),{loadThread:y}=Eo(),{createThread:g,deleteThread:b,renameThread:S}=m,[k,C]=w.useState(Array.isArray(f)?f:[]),T=w.useRef(k.length>0),I=w.useRef(null),A=w.useRef(0),[j,$]=w.useState(null),[P,O]=w.useState(""),[F,N]=w.useState(!1);w.useEffect(()=>{const V=Array.isArray(f)?f:[];if(V.length>0){T.current=!0,C(V);return}x||(T.current=!1,C(V))},[f,x]),w.useEffect(()=>{if(!I.current)return;const V=I.current.querySelector("[data-radix-scroll-area-viewport]");if(!V)return;let U=null,q=null;return U=requestAnimationFrame(()=>{q=requestAnimationFrame(()=>{V.scrollTop=A.current})}),()=>{U!==null&&cancelAnimationFrame(U),q!==null&&cancelAnimationFrame(q)}},[k]);const B=async V=>{try{h(V),await y(V),a==null||a(V),l==null||l(V)}catch(U){console.error("Failed to select thread:",U)}},R=async()=>{try{N(!0);const V=await g();V&&(c==null||c(V),a==null||a(V))}catch(V){console.error("Failed to create thread:",V)}finally{N(!1)}},Z=async(V,U)=>{if(U.stopPropagation(),!!confirm("Delete this thread?")){if(I.current){const q=I.current.querySelector("[data-radix-scroll-area-viewport]");q&&(A.current=q.scrollTop)}try{await b(V),d==null||d(V)}catch(q){console.error("Failed to delete thread:",q)}}},z=(V,U)=>{U.stopPropagation(),$(V.threadId),O(V.title||`Thread ${V.threadId.slice(0,8)}`)},_=async V=>{if(P.trim())try{await S(V,P.trim()),$(null),O("")}catch(U){console.error("Failed to update title:",U)}},Y=()=>{$(null),O("")},J=(V,U)=>{V.key==="Enter"?_(U):V.key==="Escape"&&Y()},oe=V=>{if(!V)return"";try{const U=new Date(V),L=new Date().getTime()-U.getTime(),G=Math.floor(L/(1e3*60*60*24));return G===0?U.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):G===1?"Yesterday":G<7?`${G} days ago`:U.toLocaleDateString()}catch{return""}},ve=V=>V.title||`Thread ${V.threadId.slice(0,8)}`,Re=V=>{const U=ve(V);return U.length<=_p?U:`${U.slice(0,_p)}...`};return u.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&u.jsx("div",{className:s.header||"flex-shrink-0 p-2 border-b bg-slate-800 border-slate-700 text-slate-100 flex justify-end",children:u.jsx(Ze,{onClick:R,disabled:F||x,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:F?"Creating...":"New Chat",children:u.jsx(se.MessageSquarePlus,{size:20})})}),u.jsx(Ap,{ref:I,className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:u.jsx("div",{className:"p-2 space-y-1 pb-4",children:x?u.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[u.jsx(se.Loader2,{className:"h-5 w-5 animate-spin"}),u.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):k.length===0?u.jsxs("div",{className:"text-center py-8 text-slate-400",children:[u.jsx(se.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),u.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):k.slice().sort((V,U)=>new Date(U.updatedAt||U.createdAt||"").getTime()-new Date(V.updatedAt||V.createdAt||"").getTime()).map(V=>u.jsxs("div",{onClick:()=>B(V.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??p)===V.threadId?`${s.activeThread||"bg-slate-600 border-slate-500"} `:`${s.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${s.threadItem||""} text-gray-900 dark:text-slate-100`,children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("div",{className:"flex-1 min-w-0",children:j===V.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:U=>U.stopPropagation(),children:[u.jsx(Ps,{value:P,onChange:U=>O(U.target.value),onKeyDown:U=>J(U,V.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(Ze,{variant:"ghost",size:"sm",onClick:()=>_(V.threadId),className:"h-6 w-6 p-0",children:u.jsx(se.Check,{size:12})}),u.jsx(Ze,{variant:"ghost",size:"sm",onClick:Y,className:"h-6 w-6 p-0",children:u.jsx(se.X,{size:12})})]}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:Re(V)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(se.Calendar,{size:10}),u.jsx("span",{children:oe(V.updatedAt||V.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&j!==V.threadId&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:U=>z(V,U),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(se.Edit3,{size:12})}),n&&u.jsx(Ze,{variant:"ghost",size:"sm",onClick:U=>Z(V.threadId,U),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:u.jsx(se.Trash2,{size:12})})]})]}),i===V.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},V.threadId))})})]})}function Sr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function dC(e){if(typeof e!="string")return;const t=e.trim();if(t)return bn(t)}function jp(){const e=[Sr("__API_BASE_URL__"),Sr("__CHAT_API_BASE_URL__"),Sr("__CHAT_API_URL__")];for(const t of e){const n=dC(t);if(n)return n}}function Rp(){const e=[Sr("__API_AUTH_TOKEN__"),Sr("__CHAT_API_KEY__"),Sr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function Pp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return bn(t);return bn()}function Mp(){const e={},t=jp(),n=Rp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Op(){const e=Mp(),t=In.getAuthToken(),n=jp();return{apiBaseUrl:Pp(e.baseUrl,In.baseUrl,n),apiKey:t||e.apiKey||Rp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const Dp="chat-settings";function fC(){try{const e=localStorage.getItem(Dp);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function pC(e){try{const t={...e,apiBaseUrl:bn(e.apiBaseUrl)};localStorage.setItem(Dp,JSON.stringify(t)),t.apiKey&&In.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function hC(){const e=Op(),t=fC(),n=In.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Pp(In.baseUrl,r,e.apiBaseUrl)}}function mC(e){In.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),pC(e)}var gC="Label",Lp=v.forwardRef((e,t)=>u.jsx(_e.label,{...e,ref:t,onMouseDown:n=>{var o;n.target.closest("button, input, select, textarea")||((o=e.onMouseDown)==null||o.call(e,n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));Lp.displayName=gC;var $p=Lp;const xC=lo.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Qt=v.forwardRef(({className:e,...t},n)=>u.jsx($p,{ref:n,className:te(xC(),e),...t}));Qt.displayName=$p.displayName;function Fp(e){const t=v.useRef({value:e,previous:e});return v.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var Bp=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),yC="VisuallyHidden",vC=v.forwardRef((e,t)=>u.jsx(_e.span,{...e,ref:t,style:{...Bp,...e.style}}));vC.displayName=yC;var bC=[" ","Enter","ArrowUp","ArrowDown"],wC=[" ","Enter"],tr="Select",[$s,Fs,SC]=mi(tr),[Cr,HT]=wn(tr,[SC,Uo]),Bs=Uo(),[CC,Dn]=Cr(tr),[TC,kC]=Cr(tr),zp=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:c,name:d,autoComplete:f,disabled:p,required:h,form:x}=e,m=Bs(t),[y,g]=v.useState(null),[b,S]=v.useState(null),[k,C]=v.useState(!1),T=No(c),[I,A]=cr({prop:r,defaultProp:o??!1,onChange:s,caller:tr}),[j,$]=cr({prop:i,defaultProp:a,onChange:l,caller:tr}),P=v.useRef(null),O=y?x||!!y.closest("form"):!0,[F,N]=v.useState(new Set),B=Array.from(F).map(R=>R.props.value).join(";");return u.jsx(ru,{...m,children:u.jsxs(CC,{required:h,scope:t,trigger:y,onTriggerChange:g,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:k,onValueNodeHasChildrenChange:C,contentId:Sn(),value:j,onValueChange:$,open:I,onOpenChange:A,dir:T,triggerPointerDownPosRef:P,disabled:p,children:[u.jsx($s.Provider,{scope:t,children:u.jsx(TC,{scope:e.__scopeSelect,onNativeOptionAdd:v.useCallback(R=>{N(Z=>new Set(Z).add(R))},[]),onNativeOptionRemove:v.useCallback(R=>{N(Z=>{const z=new Set(Z);return z.delete(R),z})},[]),children:n})}),O?u.jsxs(dh,{"aria-hidden":!0,required:h,tabIndex:-1,name:d,autoComplete:f,value:j,onChange:R=>$(R.target.value),disabled:p,form:x,children:[j===void 0?u.jsx("option",{value:""}):null,Array.from(F)]},B):null]})})};zp.displayName=tr;var Up="SelectTrigger",Hp=v.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Bs(n),i=Dn(Up,n),a=i.disabled||r,l=ze(t,i.onTriggerChange),c=Fs(n),d=v.useRef("touch"),[f,p,h]=ph(m=>{const y=c().filter(S=>!S.disabled),g=y.find(S=>S.value===i.value),b=hh(y,m,g);b!==void 0&&i.onValueChange(b.value)}),x=m=>{a||(i.onOpenChange(!0),h()),m&&(i.triggerPointerDownPosRef.current={x:Math.round(m.pageX),y:Math.round(m.pageY)})};return u.jsx(ou,{asChild:!0,...s,children:u.jsx(_e.button,{type:"button",role:"combobox","aria-controls":i.contentId,"aria-expanded":i.open,"aria-required":i.required,"aria-autocomplete":"none",dir:i.dir,"data-state":i.open?"open":"closed",disabled:a,"data-disabled":a?"":void 0,"data-placeholder":fh(i.value)?"":void 0,...o,ref:l,onClick:fe(o.onClick,m=>{m.currentTarget.focus(),d.current!=="mouse"&&x(m)}),onPointerDown:fe(o.onPointerDown,m=>{d.current=m.pointerType;const y=m.target;y.hasPointerCapture(m.pointerId)&&y.releasePointerCapture(m.pointerId),m.button===0&&m.ctrlKey===!1&&m.pointerType==="mouse"&&(x(m),m.preventDefault())}),onKeyDown:fe(o.onKeyDown,m=>{const y=f.current!=="";!(m.ctrlKey||m.altKey||m.metaKey)&&m.key.length===1&&p(m.key),!(y&&m.key===" ")&&bC.includes(m.key)&&(x(),m.preventDefault())})})})});Hp.displayName=Up;var Wp="SelectValue",Vp=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Dn(Wp,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=ze(t,l.onValueNodeChange);return kt(()=>{c(d)},[c,d]),u.jsx(_e.span,{...a,ref:f,style:{pointerEvents:"none"},children:fh(l.value)?u.jsx(u.Fragment,{children:i}):s})});Vp.displayName=Wp;var IC="SelectIcon",Kp=v.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(_e.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Kp.displayName=IC;var EC="SelectPortal",qp=e=>u.jsx(Ho,{asChild:!0,...e});qp.displayName=EC;var nr="SelectContent",Gp=v.forwardRef((e,t)=>{const n=Dn(nr,e.__scopeSelect),[r,o]=v.useState();if(kt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?co.createPortal(u.jsx(Yp,{scope:e.__scopeSelect,children:u.jsx($s.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(Xp,{...e,ref:t})});Gp.displayName=nr;var an=10,[Yp,Ln]=Cr(nr),AC="SelectContentImpl",NC=zn.createSlot("SelectContent.RemoveScroll"),Xp=v.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:x,hideWhenDetached:m,avoidCollisions:y,...g}=e,b=Dn(nr,n),[S,k]=v.useState(null),[C,T]=v.useState(null),I=ze(t,q=>k(q)),[A,j]=v.useState(null),[$,P]=v.useState(null),O=Fs(n),[F,N]=v.useState(!1),B=v.useRef(!1);v.useEffect(()=>{if(S)return Li(S)},[S]),yi();const R=v.useCallback(q=>{const[L,...G]=O().map(re=>re.ref.current),[Q]=G.slice(-1),le=document.activeElement;for(const re of q)if(re===le||(re==null||re.scrollIntoView({block:"nearest"}),re===L&&C&&(C.scrollTop=0),re===Q&&C&&(C.scrollTop=C.scrollHeight),re==null||re.focus(),document.activeElement!==le))return},[O,C]),Z=v.useCallback(()=>R([A,S]),[R,A,S]);v.useEffect(()=>{F&&Z()},[F,Z]);const{onOpenChange:z,triggerPointerDownPosRef:_}=b;v.useEffect(()=>{if(S){let q={x:0,y:0};const L=Q=>{var le,re;q={x:Math.abs(Math.round(Q.pageX)-(((le=_.current)==null?void 0:le.x)??0)),y:Math.abs(Math.round(Q.pageY)-(((re=_.current)==null?void 0:re.y)??0))}},G=Q=>{q.x<=10&&q.y<=10?Q.preventDefault():S.contains(Q.target)||z(!1),document.removeEventListener("pointermove",L),_.current=null};return _.current!==null&&(document.addEventListener("pointermove",L),document.addEventListener("pointerup",G,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",L),document.removeEventListener("pointerup",G,{capture:!0})}}},[S,z,_]),v.useEffect(()=>{const q=()=>z(!1);return window.addEventListener("blur",q),window.addEventListener("resize",q),()=>{window.removeEventListener("blur",q),window.removeEventListener("resize",q)}},[z]);const[Y,J]=ph(q=>{const L=O().filter(le=>!le.disabled),G=L.find(le=>le.ref.current===document.activeElement),Q=hh(L,q,G);Q&&setTimeout(()=>Q.ref.current.focus())}),oe=v.useCallback((q,L,G)=>{const Q=!B.current&&!G;(b.value!==void 0&&b.value===L||Q)&&(j(q),Q&&(B.current=!0))},[b.value]),ve=v.useCallback(()=>S==null?void 0:S.focus(),[S]),Re=v.useCallback((q,L,G)=>{const Q=!B.current&&!G;(b.value!==void 0&&b.value===L||Q)&&P(q)},[b.value]),V=r==="popper"?La:Jp,U=V===La?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:x,hideWhenDetached:m,avoidCollisions:y}:{};return u.jsx(Yp,{scope:n,content:S,viewport:C,onViewportChange:T,itemRefCallback:oe,selectedItem:A,onItemLeave:ve,itemTextRefCallback:Re,focusSelectedItem:Z,selectedItemText:$,position:r,isPositioned:F,searchRef:Y,children:u.jsx(Zo,{as:NC,allowPinchZoom:!0,children:u.jsx(jo,{asChild:!0,trapped:b.open,onMountAutoFocus:q=>{q.preventDefault()},onUnmountAutoFocus:fe(o,q=>{var L;(L=b.trigger)==null||L.focus({preventScroll:!0}),q.preventDefault()}),children:u.jsx(_o,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:q=>q.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:u.jsx(V,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:q=>q.preventDefault(),...g,...U,onPlaced:()=>N(!0),ref:I,style:{display:"flex",flexDirection:"column",outline:"none",...g.style},onKeyDown:fe(g.onKeyDown,q=>{const L=q.ctrlKey||q.altKey||q.metaKey;if(q.key==="Tab"&&q.preventDefault(),!L&&q.key.length===1&&J(q.key),["ArrowUp","ArrowDown","Home","End"].includes(q.key)){let Q=O().filter(le=>!le.disabled).map(le=>le.ref.current);if(["ArrowUp","End"].includes(q.key)&&(Q=Q.slice().reverse()),["ArrowUp","ArrowDown"].includes(q.key)){const le=q.target,re=Q.indexOf(le);Q=Q.slice(re+1)}setTimeout(()=>R(Q)),q.preventDefault()}})})})})})})});Xp.displayName=AC;var _C="SelectItemAlignedPosition",Jp=v.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Dn(nr,n),i=Ln(nr,n),[a,l]=v.useState(null),[c,d]=v.useState(null),f=ze(t,I=>d(I)),p=Fs(n),h=v.useRef(!1),x=v.useRef(!0),{viewport:m,selectedItem:y,selectedItemText:g,focusSelectedItem:b}=i,S=v.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&m&&y&&g){const I=s.trigger.getBoundingClientRect(),A=c.getBoundingClientRect(),j=s.valueNode.getBoundingClientRect(),$=g.getBoundingClientRect();if(s.dir!=="rtl"){const le=$.left-A.left,re=j.left-le,Ae=I.left-re,He=I.width+Ae,De=Math.max(He,A.width),qe=window.innerWidth-an,We=ja(re,[an,Math.max(an,qe-De)]);a.style.minWidth=He+"px",a.style.left=We+"px"}else{const le=A.right-$.right,re=window.innerWidth-j.right-le,Ae=window.innerWidth-I.right-re,He=I.width+Ae,De=Math.max(He,A.width),qe=window.innerWidth-an,We=ja(re,[an,Math.max(an,qe-De)]);a.style.minWidth=He+"px",a.style.right=We+"px"}const P=p(),O=window.innerHeight-an*2,F=m.scrollHeight,N=window.getComputedStyle(c),B=parseInt(N.borderTopWidth,10),R=parseInt(N.paddingTop,10),Z=parseInt(N.borderBottomWidth,10),z=parseInt(N.paddingBottom,10),_=B+R+F+z+Z,Y=Math.min(y.offsetHeight*5,_),J=window.getComputedStyle(m),oe=parseInt(J.paddingTop,10),ve=parseInt(J.paddingBottom,10),Re=I.top+I.height/2-an,V=O-Re,U=y.offsetHeight/2,q=y.offsetTop+U,L=B+R+q,G=_-L;if(L<=Re){const le=P.length>0&&y===P[P.length-1].ref.current;a.style.bottom="0px";const re=c.clientHeight-m.offsetTop-m.offsetHeight,Ae=Math.max(V,U+(le?ve:0)+re+Z),He=L+Ae;a.style.height=He+"px"}else{const le=P.length>0&&y===P[0].ref.current;a.style.top="0px";const Ae=Math.max(Re,B+m.offsetTop+(le?oe:0)+U)+G;a.style.height=Ae+"px",m.scrollTop=L-Re+m.offsetTop}a.style.margin=`${an}px 0`,a.style.minHeight=Y+"px",a.style.maxHeight=O+"px",r==null||r(),requestAnimationFrame(()=>h.current=!0)}},[p,s.trigger,s.valueNode,a,c,m,y,g,s.dir,r]);kt(()=>S(),[S]);const[k,C]=v.useState();kt(()=>{c&&C(window.getComputedStyle(c).zIndex)},[c]);const T=v.useCallback(I=>{I&&x.current===!0&&(S(),b==null||b(),x.current=!1)},[S,b]);return u.jsx(RC,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:h,onScrollButtonChange:T,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:k},children:u.jsx(_e.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Jp.displayName=_C;var jC="SelectPopperPosition",La=v.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=an,...s}=e,i=Bs(n);return u.jsx(su,{...i,...s,ref:t,align:r,collisionPadding:o,style:{boxSizing:"border-box",...s.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});La.displayName=jC;var[RC,$a]=Cr(nr,{}),Fa="SelectViewport",Zp=v.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Ln(Fa,n),i=$a(Fa,n),a=ze(t,s.onViewportChange),l=v.useRef(0);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),u.jsx($s.Slot,{scope:n,children:u.jsx(_e.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:fe(o.onScroll,c=>{const d=c.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:p}=i;if(p!=null&&p.current&&f){const h=Math.abs(l.current-d.scrollTop);if(h>0){const x=window.innerHeight-an*2,m=parseFloat(f.style.minHeight),y=parseFloat(f.style.height),g=Math.max(m,y);if(g<x){const b=g+h,S=Math.min(x,b),k=b-S;f.style.height=S+"px",f.style.bottom==="0px"&&(d.scrollTop=k>0?k:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});Zp.displayName=Fa;var Qp="SelectGroup",[PC,MC]=Cr(Qp),OC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Sn();return u.jsx(PC,{scope:n,id:o,children:u.jsx(_e.div,{role:"group","aria-labelledby":o,...r,ref:t})})});OC.displayName=Qp;var eh="SelectLabel",th=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=MC(eh,n);return u.jsx(_e.div,{id:o.id,...r,ref:t})});th.displayName=eh;var zs="SelectItem",[DC,nh]=Cr(zs),rh=v.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Dn(zs,n),l=Ln(zs,n),c=a.value===r,[d,f]=v.useState(s??""),[p,h]=v.useState(!1),x=ze(t,b=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,b,r,o)}),m=Sn(),y=v.useRef("touch"),g=()=>{o||(a.onValueChange(r),a.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return u.jsx(DC,{scope:n,value:r,disabled:o,textId:m,isSelected:c,onItemTextChange:v.useCallback(b=>{f(S=>S||((b==null?void 0:b.textContent)??"").trim())},[]),children:u.jsx($s.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(_e.div,{role:"option","aria-labelledby":m,"data-highlighted":p?"":void 0,"aria-selected":c&&p,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:x,onFocus:fe(i.onFocus,()=>h(!0)),onBlur:fe(i.onBlur,()=>h(!1)),onClick:fe(i.onClick,()=>{y.current!=="mouse"&&g()}),onPointerUp:fe(i.onPointerUp,()=>{y.current==="mouse"&&g()}),onPointerDown:fe(i.onPointerDown,b=>{y.current=b.pointerType}),onPointerMove:fe(i.onPointerMove,b=>{var S;y.current=b.pointerType,o?(S=l.onItemLeave)==null||S.call(l):y.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:fe(i.onPointerLeave,b=>{var S;b.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:fe(i.onKeyDown,b=>{var k;((k=l.searchRef)==null?void 0:k.current)!==""&&b.key===" "||(wC.includes(b.key)&&g(),b.key===" "&&b.preventDefault())})})})})});rh.displayName=zs;var so="SelectItemText",oh=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Dn(so,n),a=Ln(so,n),l=nh(so,n),c=kC(so,n),[d,f]=v.useState(null),p=ze(t,g=>f(g),l.onItemTextChange,g=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,g,l.value,l.disabled)}),h=d==null?void 0:d.textContent,x=v.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:h},l.value),[l.disabled,l.value,h]),{onNativeOptionAdd:m,onNativeOptionRemove:y}=c;return kt(()=>(m(x),()=>y(x)),[m,y,x]),u.jsxs(u.Fragment,{children:[u.jsx(_e.span,{id:l.textId,...s,ref:p}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?co.createPortal(s.children,i.valueNode):null]})});oh.displayName=so;var sh="SelectItemIndicator",ih=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return nh(sh,n).isSelected?u.jsx(_e.span,{"aria-hidden":!0,...r,ref:t}):null});ih.displayName=sh;var Ba="SelectScrollUpButton",ah=v.forwardRef((e,t)=>{const n=Ln(Ba,e.__scopeSelect),r=$a(Ba,e.__scopeSelect),[o,s]=v.useState(!1),i=ze(t,r.onScrollButtonChange);return kt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollTop>0;s(c)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(ch,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});ah.displayName=Ba;var za="SelectScrollDownButton",lh=v.forwardRef((e,t)=>{const n=Ln(za,e.__scopeSelect),r=$a(za,e.__scopeSelect),[o,s]=v.useState(!1),i=ze(t,r.onScrollButtonChange);return kt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<c;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(ch,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});lh.displayName=za;var ch=v.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Ln("SelectScrollButton",n),i=v.useRef(null),a=Fs(n),l=v.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return v.useEffect(()=>()=>l(),[l]),kt(()=>{var d;const c=a().find(f=>f.ref.current===document.activeElement);(d=c==null?void 0:c.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),u.jsx(_e.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:fe(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:fe(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:fe(o.onPointerLeave,()=>{l()})})}),LC="SelectSeparator",uh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(_e.div,{"aria-hidden":!0,...r,ref:t})});uh.displayName=LC;var Ua="SelectArrow",$C=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Bs(n),s=Dn(Ua,n),i=Ln(Ua,n);return s.open&&i.position==="popper"?u.jsx(iu,{...o,...r,ref:t}):null});$C.displayName=Ua;var FC="SelectBubbleInput",dh=v.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=v.useRef(null),s=ze(r,o),i=Fp(t);return v.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),u.jsx(_e.select,{...n,style:{...Bp,...n.style},ref:s,defaultValue:t})});dh.displayName=FC;function fh(e){return e===""||e===void 0}function ph(e){const t=It(e),n=v.useRef(""),r=v.useRef(0),o=v.useCallback(i=>{const a=n.current+i;t(a),function l(c){n.current=c,window.clearTimeout(r.current),c!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(a)},[t]),s=v.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return v.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function hh(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=BC(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function BC(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var zC=zp,mh=Hp,UC=Vp,HC=Kp,WC=qp,gh=Gp,VC=Zp,xh=th,yh=rh,KC=oh,qC=ih,vh=ah,bh=lh,wh=uh;const Sh=zC,Ch=UC,Ha=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(mh,{ref:r,className:te("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",e),...n,children:[t,u.jsx(HC,{asChild:!0,children:u.jsx(se.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Ha.displayName=mh.displayName;const Th=v.forwardRef(({className:e,...t},n)=>u.jsx(vh,{ref:n,className:te("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(se.ChevronUp,{className:"h-4 w-4"})}));Th.displayName=vh.displayName;const kh=v.forwardRef(({className:e,...t},n)=>u.jsx(bh,{ref:n,className:te("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(se.ChevronDown,{className:"h-4 w-4"})}));kh.displayName=bh.displayName;const Wa=v.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(WC,{children:u.jsxs(gh,{ref:o,className:te("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md 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-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[u.jsx(Th,{}),u.jsx(VC,{className:te("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(kh,{})]})}));Wa.displayName=gh.displayName;const GC=v.forwardRef(({className:e,...t},n)=>u.jsx(xh,{ref:n,className:te("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));GC.displayName=xh.displayName;const rr=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(yh,{ref:r,className:te("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(qC,{children:u.jsx(se.Check,{className:"h-4 w-4"})})}),u.jsx(KC,{children:t})]}));rr.displayName=yh.displayName;const YC=v.forwardRef(({className:e,...t},n)=>u.jsx(wh,{ref:n,className:te("-mx-1 my-1 h-px bg-muted",e),...t}));YC.displayName=wh.displayName;var XC="Separator",Ih="horizontal",JC=["horizontal","vertical"],Eh=v.forwardRef((e,t)=>{const{decorative:n,orientation:r=Ih,...o}=e,s=ZC(r)?r:Ih,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(_e.div,{"data-orientation":s,...a,...o,ref:t})});Eh.displayName=XC;function ZC(e){return JC.includes(e)}var Ah=Eh;const Nh=v.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(Ah,{ref:o,decorative:n,orientation:t,className:te("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Nh.displayName=Ah.displayName;const QC=Hf,eT=mS,tT=Wf,_h=v.forwardRef(({className:e,...t},n)=>u.jsx(Ts,{className:te("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",e),...t,ref:n}));_h.displayName=Ts.displayName;const nT=lo.cva("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm"}},defaultVariants:{side:"right"}}),jh=v.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(tT,{children:[u.jsx(_h,{}),u.jsxs(ks,{ref:o,className:te(nT({side:e}),t),...r,children:[n,u.jsxs(Vf,{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-secondary",children:[u.jsx(se.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));jh.displayName=ks.displayName;const Rh=({className:e,...t})=>u.jsx("div",{className:te("flex flex-col space-y-2 text-center sm:text-left",e),...t});Rh.displayName="SheetHeader";const Ph=v.forwardRef(({className:e,...t},n)=>u.jsx(Qn,{ref:n,className:te("text-lg font-semibold text-foreground",e),...t}));Ph.displayName=Qn.displayName;const Mh=v.forwardRef(({className:e,...t},n)=>u.jsx(Is,{ref:n,className:te("text-sm text-muted-foreground",e),...t}));Mh.displayName=Is.displayName;var Us="Switch",[rT,WT]=wn(Us),[oT,sT]=rT(Us),Oh=v.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:c,form:d,...f}=e,[p,h]=v.useState(null),x=ze(t,S=>h(S)),m=v.useRef(!1),y=p?d||!!p.closest("form"):!0,[g,b]=cr({prop:o,defaultProp:s??!1,onChange:c,caller:Us});return u.jsxs(oT,{scope:n,checked:g,disabled:a,children:[u.jsx(_e.button,{type:"button",role:"switch","aria-checked":g,"aria-required":i,"data-state":Fh(g),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:x,onClick:fe(e.onClick,S=>{b(k=>!k),y&&(m.current=S.isPropagationStopped(),m.current||S.stopPropagation())})}),y&&u.jsx($h,{control:p,bubbles:!m.current,name:r,value:l,checked:g,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Oh.displayName=Us;var Dh="SwitchThumb",Lh=v.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=sT(Dh,n);return u.jsx(_e.span,{"data-state":Fh(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Lh.displayName=Dh;var iT="SwitchBubbleInput",$h=v.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=v.useRef(null),a=ze(i,s),l=Fp(n),c=qc(t);return v.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,h=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&h){const x=new Event("click",{bubbles:r});h.call(d,n),d.dispatchEvent(x)}},[l,n,r]),u.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...c,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});$h.displayName=iT;function Fh(e){return e?"checked":"unchecked"}var Bh=Oh,aT=Lh;const $n=v.forwardRef(({className:e,...t},n)=>u.jsx(Bh,{className:te("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:n,children:u.jsx(aT,{className:te("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));$n.displayName=Bh.displayName;const lT={api:{baseUrl:"http://localhost:8000/api",authToken:"",enableAuth:!1},ui:{layout:"sidebar",theme:"light",showTimestamps:!0,showAgentNames:!0,compactMessages:!1},behavior:{autoSave:!0,enableStreaming:!0,showTypingIndicator:!0}};function cT({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=w.useState(!1),[s,i]=w.useState(!1),[a,l]=w.useState(e),[c,d]=w.useState(!1),{toast:f}=Sa();w.useEffect(()=>{const y=JSON.stringify(a)!==JSON.stringify(e);d(y)},[a,e]),w.useEffect(()=>{l(e)},[e]);const p=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},h=()=>{l(lT),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},x=()=>{l(e),d(!1),o(!1)},m=async()=>{try{const g=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${g.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return u.jsxs(QC,{open:r,onOpenChange:o,children:[u.jsx(eT,{asChild:!0,children:u.jsxs(Ze,{variant:"outline",size:"sm",className:n,children:[u.jsx(se.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(Sf,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(jh,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(Rh,{children:[u.jsx(Ph,{children:"Chat Settings"}),u.jsx(Mh,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(Jr,{children:[u.jsx(Zr,{className:"pb-3",children:u.jsxs(Qr,{className:"text-lg flex items-center gap-2",children:[u.jsx(se.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(eo,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(Qt,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Ps,{id:"api-url",value:a.api.baseUrl,onChange:y=>l(g=>({...g,api:{...g.api,baseUrl:y.target.value}})),placeholder:"http://localhost:8000/api"}),u.jsx(Ze,{variant:"outline",onClick:m,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(Qt,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx($n,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:y=>l(g=>({...g,api:{...g.api,enableAuth:y}}))})]}),a.api.enableAuth&&u.jsxs("div",{className:"space-y-2",children:[u.jsx(Qt,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Ps,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:y=>l(g=>({...g,api:{...g.api,authToken:y.target.value}})),placeholder:"Enter your Bearer token"}),u.jsx(Ze,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?u.jsx(se.EyeOff,{className:"h-4 w-4"}):u.jsx(se.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(Jr,{children:[u.jsx(Zr,{className:"pb-3",children:u.jsxs(Qr,{className:"text-lg flex items-center gap-2",children:[u.jsx(se.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(eo,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(Qt,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(Sh,{value:a.ui.layout,onValueChange:y=>l(g=>({...g,ui:{...g.ui,layout:y}})),children:[u.jsx(Ha,{children:u.jsx(Ch,{})}),u.jsxs(Wa,{children:[u.jsx(rr,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(rr,{value:"fullscreen",children:"Fullscreen"}),u.jsx(rr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(Qt,{htmlFor:"theme",children:"Theme"}),u.jsxs(Sh,{value:a.ui.theme,onValueChange:y=>l(g=>({...g,ui:{...g.ui,theme:y}})),children:[u.jsx(Ha,{children:u.jsx(Ch,{})}),u.jsxs(Wa,{children:[u.jsx(rr,{value:"light",children:"Light"}),u.jsx(rr,{value:"dark",children:"Dark"}),u.jsx(rr,{value:"system",children:"System"})]})]})]}),u.jsx(Nh,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(Qt,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx($n,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,showTimestamps:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(Qt,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx($n,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,showAgentNames:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(Qt,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx($n,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,compactMessages:y}}))})]})]})]})]}),u.jsxs(Jr,{children:[u.jsx(Zr,{className:"pb-3",children:u.jsxs(Qr,{className:"text-lg flex items-center gap-2",children:[u.jsx(se.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(eo,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(Qt,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx($n,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:y=>l(g=>({...g,behavior:{...g.behavior,autoSave:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(Qt,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx($n,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:y=>l(g=>({...g,behavior:{...g.behavior,enableStreaming:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(Qt,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx($n,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:y=>l(g=>({...g,behavior:{...g.behavior,showTypingIndicator:y}}))})]})]})]})]}),u.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[u.jsxs(Ze,{variant:"outline",onClick:h,children:[u.jsx(se.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Ze,{variant:"outline",onClick:x,children:"Cancel"}),u.jsxs(Ze,{onClick:p,disabled:!c,children:[u.jsx(se.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function uT({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=c=>{const d="h-full";switch(c){case"phone":return`${d} max-w-none`;case"tablet":return`${d} max-w-4xl mx-auto`;case"half-screen":return`${d} max-w-2xl`;case"desktop":default:return`${d} max-w-7xl mx-auto`}},a=c=>({"--chat-sidebar-width":c==="phone"?"100%":c==="tablet"?"280px":c==="half-screen"?"240px":"320px","--chat-message-max-width":c==="phone"?"95%":c==="tablet"?"90%":c==="half-screen"?"85%":"80%","--chat-input-height":c==="phone"?"120px":"100px"}),l=w.useCallback(c=>{var d;(d=s.onThreadChange)==null||d.call(s,c)},[s]);return e==="fullscreen"?u.jsx(Ao,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx(Rs,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(Ao,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&u.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(Da,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx(Rs,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(Ao,{...s,onThreadChange:l,children:u.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&u.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:u.jsx(Da,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx(Rs,{onError:s.onError,enableFileUpload:!0})})]})})}ke.ChatApi=Ul,ke.ChatInput=dc,ke.ChatInterface=Rs,ke.ChatProviders=Ao,ke.ChatSettings=cT,ke.MarkdownContent=oo,ke.MessageComponent=Na,ke.MessageList=_a,ke.ThreadManager=Da,ke.applySettings=mC,ke.buildMessagePreviewMap=Yl,ke.chatApiClient=In,ke.default=uT,ke.del=zl,ke.get=Kt,ke.getChatToken=$l,ke.getCurrentSettings=hC,ke.getDefaultApiConfig=Mp,ke.getDefaultChatSettings=Op,ke.onChatTokenChanged=Fl,ke.post=ai,ke.put=Bl,ke.setChatToken=So,ke.useApi=li,ke.useChatStream=Xl,ke.useMessagesReducer=Jl,ke.useStream=cc,ke.useThreadState=Eo,ke.useThreads=Io,Object.defineProperties(ke,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/package.json
CHANGED