teodor-new-chat-ui 4.3.222 → 4.3.224

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -14441,9 +14441,9 @@ const Hc = (e, t) => (e == null ? void 0 : e.id) ?? `message-${t}`, jC = (e) =>
14441
14441
  /* @__PURE__ */ u.jsxs("div", { className: "relative flex-1 overflow-y-auto pt-5 pb-5 pr-1", children: [
14442
14442
  /* @__PURE__ */ u.jsxs("div", { className: "absolute left-0 right-0 top-1 flex items-center justify-between px-2 pb-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground", children: [
14443
14443
  /* @__PURE__ */ u.jsx("span", { children: "Timeline" }),
14444
- /* @__PURE__ */ u.jsxs("div", { className: "group relative", children: [
14444
+ /* @__PURE__ */ u.jsxs("div", { className: "group relative z-50", children: [
14445
14445
  /* @__PURE__ */ u.jsx(ym, { className: "h-3.5 w-3.5 text-muted-foreground cursor-help" }),
14446
- /* @__PURE__ */ u.jsx("div", { className: "pointer-events-auto fixed hidden w-40 rounded-md border bg-background p-3 text-[11px] font-normal text-muted-foreground shadow-lg group-hover:block whitespace-normal leading-relaxed z-40", style: { bottom: "auto", left: "20rem", top: "1rem" }, children: 'Shows user inputs and the latest loop checkpoint. Click a dot to jump the chat to that point. Click on the "Latest" button to return to the most recent messages.' })
14446
+ /* @__PURE__ */ u.jsx("div", { className: "pointer-events-auto absolute hidden w-40 rounded-md border bg-background p-3 text-[11px] font-normal text-muted-foreground shadow-lg group-hover:block whitespace-normal leading-relaxed left-full ml-2 top-0 z-50", children: 'Shows user inputs and the latest loop checkpoint. Click a dot to jump the chat to that point. Click on the "Latest" button to return to the most recent messages.' })
14447
14447
  ] })
14448
14448
  ] }),
14449
14449
  /* @__PURE__ */ u.jsx("div", { className: "pointer-events-none absolute left-5 top-0 bottom-0 w-px bg-border/50" }),
package/dist/index.umd.js CHANGED
@@ -134,4 +134,4 @@ ${t}</tr>
134
134
  `+(h.tokens?this.parseInline(h.tokens):h.text);r+=n?this.renderer.paragraph(p):p;continue}default:{const j='Token with "'+h.type+'" type was not found.';if(this.options.silent){console.error(j);return}else throw new Error(j)}}}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 Ls{constructor(t){this.options=t||lr}preprocess(t){return t}postprocess(t){return t}}Kh(Ls,"passThroughHooks",new Set(["preprocess","postprocess"]));function bS(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>"+Ft(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 fp(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...xe.defaults,...s};const i=bS(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(xS(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&&xe.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;xe.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(xe.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&&xe.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function xe(e,t,n){return fp(Bn.lex,Hn.parse)(e,t,n)}xe.options=xe.setOptions=function(e){return xe.defaults={...xe.defaults,...e},oS(xe.defaults),xe},xe.getDefaults=ep,xe.defaults=lr,xe.use=function(...e){const t=xe.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=xe.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=xe.defaults.renderer||new Ra;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=xe.defaults.tokenizer||new _a;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=xe.defaults.hooks||new Ls;for(const s in n.hooks){const i=o[s];Ls.passThroughHooks.has(s)?o[s]=a=>{if(xe.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=xe.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}}xe.setOptions(r)})},xe.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(xe,r)),r.type){case"table":{for(const o of r.header)n=n.concat(xe.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(xe.walkTokens(s.tokens,t));break}case"list":{n=n.concat(xe.walkTokens(r.items,t));break}default:xe.defaults.extensions&&xe.defaults.extensions.childTokens&&xe.defaults.extensions.childTokens[r.type]?xe.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(xe.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(xe.walkTokens(r.tokens,t)))}return n},xe.parseInline=fp(Bn.lexInline,Hn.parseInline),xe.Parser=Hn,xe.parser=Hn.parse,xe.Renderer=Ra,xe.TextRenderer=up,xe.Lexer=Bn,xe.lexer=Bn.lex,xe.Tokenizer=_a,xe.Slugger=dp,xe.Hooks=Ls,xe.parse=xe,xe.options,xe.setOptions,xe.use,xe.walkTokens,xe.parseInline,Hn.parse,Bn.lex;function ho({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 xe.parse=="function"?xe.parse(i):xe(i)}return typeof xe.parse=="function"?xe.parse(e):xe(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:Q("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 wS="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 SS(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function pp(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 Fs(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function CS(e){const t=o=>{try{const s=fo(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
136
  `)):r=t(e),r||""}function TS(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function hp(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 kS({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:Q("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const Pa=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,customStyles:p={},onEdit:h,onRegenerate:m,onCancelEdit:x,onCopy:y,activeInterrupt:g,disableInterruptActions:b=!1,onInterruptActionStart:S,onInterruptActionEnd:k,checkpointCandidates:T=[],activeCheckpointId:C=null,onSelectCheckpoint:E,defaultCheckpointId:j=null,messageParentCheckpointId:N=null}){const[A,O]=w.useState(!1),[F,$]=w.useState("preview"),[R,z]=w.useState(!1),{currentThreadId:_}=Oo(),{respondToInterrupt:B}=Mo(),L=l==="phone"||l==="half-screen",M=t.role,J=M==="tool",X=w.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),he=!!X,Ne=!(r&&M!=="user"),{uploadingFiles:_e,handleFileClick:K,fileViewerOpen:ee,currentFileInfo:q,closeFileViewer:D}=IS({allowFileOpen:Ne,currentThreadId:_}),H=w.useMemo(()=>{switch(M){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))]"}},[M]),te=w.useMemo(()=>X?"":SS(t.content),[X,t]),se=w.useMemo(()=>X?{}:pp(t),[X,t]),ne=w.useMemo(()=>X?[]:t.content.filter(W=>W.type==="image_url"),[X,t]),ke=w.useMemo(()=>X?[]:t.content.filter(W=>W.type==="file"),[X,t]),Z=w.useMemo(()=>X?[]:t.content.filter(W=>W.type==="interrupt"),[X,t]),fe=(g==null?void 0:g.id)??(g==null?void 0:g.interrupt_id),Ie=Fs(fe),Ae=g==null?void 0:g.value,Le=w.useMemo(()=>X?"":CS(t.content),[X,t]),Ze=w.useCallback(async()=>{const W=J?Le:te;async function be(ye){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(ye);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const dt=new Blob([ye],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":dt})]);return}throw new Error("Clipboard API not supported in this context.")}try{await be(W),O(!0),setTimeout(()=>O(!1),2e3),y==null||y(W)}catch(ye){console.error("Failed to copy:",ye)}},[J,Le,te,y]),We=w.useCallback(()=>{if(!h)return;const W=J?Le:te,be="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};h(t.id,W,be)},[h,t.id,J,Le,te,t]),Ve=w.useCallback(()=>{m==null||m(n)},[m,n]),Ke=w.useCallback(()=>{const be=Q(L?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",H);switch(M){case"user":return u.jsx(oe.User,{className:be});case"assistant":return u.jsx(oe.Bot,{className:be});case"tool":return u.jsx(oe.Wrench,{className:be});default:return u.jsx(oe.Bot,{className:be})}},[L,H,M]),Xe=w.useCallback(()=>{const W="group relative mb-4 flex w-full";switch(M){case"user":return Q(W,"justify-end");case"assistant":case"tool":case"system":return Q(W,"justify-start");default:return W}},[M]),Qe=w.useCallback(()=>{const W=Q("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",L&&"px-3 py-2 text-sm");if(he)return Q(W,"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(M){case"user":return Q(W,"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 Q(W,"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 Q(W,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return Q(W,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return Q(W,"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")}},[L,he,M]);if(he&&X)return u.jsx("div",{className:Q(Xe(),p.container),children:u.jsxs("div",{className:Q(Qe(),p.content),children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2 pb-2 border-b border-current/10",children:[u.jsx(oe.Bot,{className:Q("h-4 w-4",H)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(ho,{content:X.content,className:"text-current"})]})});const et=w.useCallback(async W=>{if(b)return;const be=Fs((W==null?void 0:W.id)??(W==null?void 0:W.interrupt_id));if(!be){console.warn("Interrupt part missing id",W);return}try{S==null||S(),await B(be,!0)}catch(ye){console.error("Failed to approve interrupt:",ye)}finally{k==null||k()}},[b,k,S,B]),It=w.useCallback(async W=>{if(b)return;const be=Fs((W==null?void 0:W.id)??(W==null?void 0:W.interrupt_id));if(!be){console.warn("Interrupt part missing id",W);return}try{S==null||S(),await B(be,!1)}catch(ye){console.error("Failed to reject interrupt:",ye)}finally{k==null||k()}},[b,k,S,B]),ht=w.useCallback(({part:W,i:be})=>{if(W.type==="text"){const ye=W.text??"",dt=ye.trim(),mt=Ia(dt);return mt&&M!=="tool"?u.jsx(mp,{data:mt},be):M==="user"&&c&&dt.length>d?u.jsx(NS,{text:dt,expanded:R,onExpandedChange:z,previewLength:d,isCompact:L},be):u.jsx(ho,{content:ye,allowHtml:!1},be)}if(W.type==="image_url"){const ye=W;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:ye.url,alt:ye.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},be)}if(W.type==="file"){const ye=W,dt=ye.name||"file";return u.jsxs("a",{href:ye.url,onClick:mt=>K(mt,ye,be),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
137
- dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[_e[be]?u.jsx(oe.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[dt,_e[be]?" (processing)":""]})]},be)}if(W.type==="interrupt"){const ye=W,dt=Fs((ye==null?void 0:ye.id)??(ye==null?void 0:ye.interrupt_id)),mt=!!(Ie&&dt&&dt===Ie),St=mt?Ae??(ye==null?void 0:ye.value):ye==null?void 0:ye.value,Oe=dt?{...ye,id:dt,interrupt_id:dt}:ye;return u.jsx(ES,{interruptPart:Oe,onApprove:et,onReject:It,disabled:b,isActive:mt,payload:St},be)}return null},[K,_e,et,It,M,c,d,R,L,Ie,Ae,g,b,Z]),it=w.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(oe.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),de=w.useCallback(()=>{const W=te.trim().length>0||ne.length>0||ke.length>0||Z.length>0;if(!J&&ke.length>0&&!r)return it();if(!J&&!W&&!r)return null;if(J)return u.jsx(AS,{message:t,viewMode:F},t.id);if(!J&&!X){const be=t,ye=u.jsx("div",{className:"space-y-2",children:be.content.map((dt,mt)=>u.jsx(ht,{part:dt,i:mt},mt))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[ye,u.jsx(kS,{className:H})]}):ye}},[te,ne.length,ke.length,Z.length,r,J,F,it,H]),pe=w.useMemo(()=>X?"Assistant":TS(t),[X,t]),ge=w.useMemo(()=>X?[]:Array.isArray(T)?T:[],[T,X]),qe=w.useMemo(()=>{var W;return ge.length?j&&ge.some(be=>be.id===j)?j:((W=ge[0])==null?void 0:W.id)??null:null},[j,ge]),xt=w.useMemo(()=>!ge.length||!C?null:ge.some(W=>W.id===C)?C:null,[C,ge])??qe,Nt=M==="user"&&ge.length>0&&typeof E=="function",ot=w.useCallback(W=>{if(!E)return;const be=(W==null?void 0:W.id)??null,ye=(W==null?void 0:W.parentId)??N??null;E(be,ye)},[N,E]),ze=w.useMemo(()=>xt?ge.findIndex(W=>W.id===xt):-1,[xt,ge]),jt=w.useMemo(()=>ze<0?null:ge[ze]??null,[ze,ge]),At=w.useCallback(W=>{const be=[];if(W.step!==null&&be.push(`Step ${W.step}`),W.source&&be.push(W.source),!W.createdAt)return be.length?be.join(" • "):W.id.slice(0,8);let ye="";try{const dt=new Date(W.createdAt);Number.isNaN(dt.getTime())||(ye=new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(dt))}catch{ye=""}return`${ye}`},[]);return J&&!f?null:u.jsxs(u.Fragment,{children:[u.jsx("div",{className:Q(Xe(),p.container),children:u.jsxs("div",{className:Q(Qe(),p.content),children:[(i||a||J)&&u.jsxs("div",{className:Q("flex items-center justify-between mb-2 pb-2 border-b border-current/10",L&&"mb-1 pb-1",H,p.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[Ke(),a&&pe&&u.jsx("span",{className:Q("font-medium",L?"text-xs":"text-sm"),children:pe}),J&&u.jsxs(Tf,{variant:"outline",className:Q("text-xs flex items-center gap-1 cursor-pointer select-none",H,"border border-current/40",L&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":F==="expanded",onClick:()=>$(W=>W==="expanded"?"preview":"expanded"),onKeyDown:W=>{(W.key==="Enter"||W.key===" ")&&(W.preventDefault(),$(be=>be==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:se.name??"Tool Output"}),se.toolCallId&&u.jsx("span",{className:"opacity-70",children:se.toolCallId.slice(0,8)}),F==="expanded"?u.jsx(oe.ChevronUp,{className:"h-3 w-3"}):u.jsx(oe.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[Nt&&jt&&ze>=0&&u.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[u.jsx("button",{type:"button",className:Q("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",ze>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(ze<=0)return;const W=ge[ze-1];W&&ot(W)},"aria-label":"Previous checkpoint",disabled:ze<=0,children:u.jsx(oe.ChevronLeft,{className:"h-3 w-3"})}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs("span",{className:"whitespace-nowrap",children:[ze+1," / ",ge.length]}),u.jsx("span",{className:"text-muted-foreground",children:At(jt)})]}),u.jsx("button",{type:"button",className:Q("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",ze<ge.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(ze>=ge.length-1)return;const W=ge[ze+1];W&&ot(W)},"aria-label":"Next checkpoint",disabled:ze>=ge.length-1,children:u.jsx(oe.ChevronRight,{className:"h-3 w-3"})})]}),i&&t.createdAt&&u.jsx("time",{className:Q("text-xs opacity-60",H,L&&"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:Q("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>Ze(),className:Q("h-6 w-6 p-0 hover:bg-foreground/10",H,L&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(oe.Copy,{className:Q(A?"text-success":H,L?"h-3 w-3":"h-4 w-4")})})}),M==="user"&&h&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:We,className:Q("h-6 w-6 p-0 hover:bg-foreground/10",H,L&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(oe.Edit,{className:Q(H,L?"h-3 w-3":"h-4 w-4")})}),M==="assistant"&&m&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:Ve,className:Q("h-6 w-6 p-0 hover:bg-foreground/10",H,L&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(oe.RotateCcw,{className:Q(H,L?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsx("div",{className:"relative",children:de()}),J&&F==="expanded"&&(se.toolCallId||se.name)&&u.jsxs("div",{className:Q("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",L&&"text-xs"),children:[se.name&&u.jsxs("div",{children:["Function: ",se.name]}),se.toolCallId&&u.jsxs("div",{children:["Call ID: ",se.toolCallId]})]}),!(i||a||J)&&s&&!o&&u.jsxs("div",{className:Q("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>Ze(),className:Q("h-6 w-6 p-0 hover:bg-background/50 text-current",L&&"h-5 w-5"),children:u.jsx(oe.Copy,{className:Q(A?"text-success":"text-current",L?"h-3 w-3":"h-4 w-4")})}),M==="user"&&h&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:We,className:Q("h-6 w-6 p-0 hover:bg-background/50 text-current",L&&"h-5 w-5"),children:u.jsx(oe.Edit,{className:Q("text-current",L?"h-3 w-3":"h-4 w-4")})}),M==="assistant"&&m&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:Ve,className:Q("h-6 w-6 p-0 hover:bg-background/50 text-current",L&&"h-5 w-5"),children:u.jsx(oe.RotateCcw,{className:Q("text-current",L?"h-3 w-3":"h-4 w-4")})})]})]})}),q&&u.jsx(rS,{isOpen:ee,onClose:D,fileId:q.id,fileName:q.name,mimeType:q.mimeType})]})},(e,t)=>{var i,a,l,c,d,f,p,h;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&hp(e.message)===hp(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages"].every(m=>e[m]===t[m]),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 mp({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:wS,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:po(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:po(e)})}function ES({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=po(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(io,{className:Q("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(ao,{className:"pb-3",children:[u.jsx(lo,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(kf,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(co,{className:"pt-0 pb-3",children:a}),u.jsx(Ef,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(nt,{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(nt,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}function IS(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=Ea(),[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,m,x)=>{var y,g;if(!t){h.preventDefault();return}if(o[x]){h.preventDefault();return}try{const b=String(m.url??""),S=b.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){h.preventDefault();const k=S[1],T=m.name||`file_${k}`,C=m.mimeType||"application/octet-stream";f({id:k,name:T,mimeType:C});return}if(b.startsWith("data:")){h.preventDefault(),s(T=>({...T,[x]:!0}));const k=r({title:"Fetching file...",description:"",open:!0});try{const T=await B0(n??void 0);if(!T||!Array.isArray(T))throw new Error("Invalid file list response");const C=T.find(E=>!E||typeof E!="object"||!((E.filename??"")===(m.name??""))?!1:typeof m.size=="number"&&typeof E.size=="number"?E.size===m.size:!0);if(!(C!=null&&C.id))throw new Error(`File "${m.name}" is not yet available on the server`);if(!C.id||!C.filename)throw new Error("Invalid file data received from server");f({id:C.id,name:m.name||C.filename||`file_${C.id}`,mimeType:m.mimeType||C.mime_type||"application/octet-stream"}),(y=k.update)==null||y.call(k,{id:k.id,title:"Success",description:`Opened ${m.name}`,open:!0})}catch(T){console.error("Failed to fetch server file:",T);const C=T instanceof Error?T.message:"Unknown error occurred";(g=k.update)==null||g.call(k,{id:k.id,title:"Failed",description:C}),r({title:"Failed to fetch file",description:C,open:!0})}finally{s(T=>({...T,[x]:!1}))}}}catch(b){console.error("File click error:",b),s(S=>({...S,[x]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:p,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function NS({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:Q("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(ho,{content:e,allowHtml:!1}):u.jsxs("pre",{className:Q("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(nt,{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(oe.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(oe.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function AS({message:e,viewMode:t}){const r=pp(e).name||"tool",o=c=>{if(c==null)return null;const d=typeof c=="string"?Ia(c)??c:c;if(d&&typeof d=="object")return u.jsx(mp,{data:d});const f=typeof d=="string"?d:(()=>{try{return po(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}=U0(c);return f?u.jsx(ho,{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(oe.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=Ns(d);return s(f)}const a=fo(i),l=Ns(a);return s(l)}const gp=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,jS=e=>{const t=e.additionalKwargs??{},n=e.responseMetadata??{},r=t.originalMessageId??n.originalMessageId??t.original_message_id??n.original_message_id;return typeof r=="string"&&r.trim()?r.trim():e.id},Oa=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:m=!0,isNavigatingCheckpoint:x=!1,onScrollAway:y,onAtBottom:g,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:T,showToolMessages:C=!0,checkpointMetaById:E,checkpointIndexByKey:j,activeCheckpointId:N,onSelectCheckpoint:A,timelineCheckpoints:O},F)=>{const $=w.useRef(null),R=w.useRef(null),z=w.useRef(!1),[_,B]=w.useState(!0),L=w.useMemo(()=>b?e.some(Z=>"type"in Z&&Z.type==="default_message"?!1:Array.isArray(Z==null?void 0:Z.content)&&Z.content.some(fe=>fe&&fe.type==="interrupt"&&(fe.id??fe.interrupt_id)===b.id)):!1,[b,e]),M=w.useMemo(()=>{if(!b||L)return null;const Z=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let fe;const Ie=b.value;if(Ie&&typeof Ie=="object"&&!Array.isArray(Ie)){const Ae=Ie.title;typeof Ae=="string"&&Ae.trim()&&(fe=Ae.trim())}return{id:`interrupt-${Z}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:Z,value:Ie,title:fe}]}},[b,L]),J=w.useMemo(()=>M?[...e,M]:e,[e,M]),X=w.useMemo(()=>C?J:J.filter(Z=>(Z==null?void 0:Z.role)!=="tool"),[J,C]),he=w.useMemo(()=>{const Z=new Set,fe=[];for(let Ie=X.length-1;Ie>=0;Ie--){const Ae=X[Ie];if(!Ae)continue;if("type"in Ae&&Ae.type==="default_message"){fe.push(Ae);continue}const Le=Ae,Ze=jS(Le);Z.has(Ze)||(Z.add(Ze),fe.push(Le))}return fe.reverse()},[X]),Ne=w.useCallback(Z=>{B(Z),y&&y(!Z),g&&g(Z)},[y,g]),_e=w.useMemo(()=>{if(a)return async()=>{if(!z.current){z.current=!0;try{await a()}finally{z.current=!1}}}},[a]),K=w.useMemo(()=>!m||x?!1:_?"auto":!1,[_,m,x]),ee=w.useMemo(()=>O??[],[O]),q=N??(ee.length?ee[ee.length-1].id:null),D=ee.length>0,H=w.useMemo(()=>{if(typeof h!="string")return null;const Z=h.trim();return Z?{id:"default-message",role:"assistant",type:"default_message",content:Z,createdAt:new Date().toISOString()}:null},[h]),te=D?u.jsxs("div",{className:"w-48 flex-shrink-0 flex-col border-r border-border/40 pr-4 flex",children:[u.jsxs("div",{className:"relative flex-1 overflow-y-auto pt-5 pb-5 pr-1",children:[u.jsxs("div",{className:"absolute left-0 right-0 top-1 flex items-center justify-between px-2 pb-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:[u.jsx("span",{children:"Timeline"}),u.jsxs("div",{className:"group relative",children:[u.jsx(oe.Info,{className:"h-3.5 w-3.5 text-muted-foreground cursor-help"}),u.jsx("div",{className:"pointer-events-auto fixed hidden w-40 rounded-md border bg-background p-3 text-[11px] font-normal text-muted-foreground shadow-lg group-hover:block whitespace-normal leading-relaxed z-40",style:{bottom:"auto",left:"20rem",top:"1rem"},children:'Shows user inputs and the latest loop checkpoint. Click a dot to jump the chat to that point. Click on the "Latest" button to return to the most recent messages.'})]})]}),u.jsx("div",{className:"pointer-events-none absolute left-5 top-0 bottom-0 w-px bg-border/50"}),u.jsx("div",{className:"flex flex-col gap-4",children:ee.map(Z=>{const fe=q===Z.id;return u.jsxs("button",{type:"button",disabled:!A,onClick:()=>A==null?void 0:A(Z.id),className:`relative flex items-start gap-3 text-left text-xs transition ${fe?"text-primary":"text-muted-foreground"} ${A?"hover:text-foreground":"cursor-default opacity-70"}`,children:[u.jsx("span",{className:`mt-1 inline-flex h-4 w-4 items-center justify-center rounded-full border ${fe?"border-primary bg-primary/10 text-primary":"border-border bg-background"}`,children:u.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${fe?"bg-primary":"bg-border"}`})}),u.jsxs("span",{className:"flex-1",children:[u.jsx("span",{className:"block font-medium",children:Z.label||"User input"}),u.jsxs("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground/70",children:[Z.step!==null?`STEP ${Z.step}`:"STEP —",Z.next?` - ${Z.next}`:""]})]})]},Z.id)})})]}),A&&u.jsx("button",{type:"button",onClick:()=>A==null?void 0:A(null),className:"mt-auto rounded-md border border-border/70 px-3 py-2 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground transition hover:border-foreground/60 hover:text-foreground",children:"Latest"})]}):null,se=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),ne=()=>H?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Pa,{message:H,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{}})})}):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!"}),ke=he.length>0;return w.useImperativeHandle(F,()=>({scrollToLatest:()=>{var Z,fe;if($.current&&he.length>0){const Ie=he.length-1;(fe=(Z=$.current).scrollToIndex)==null||fe.call(Z,{index:Ie,align:"end",behavior:"auto"})}else R.current&&(R.current.scrollTop=R.current.scrollHeight)},scrollToTop:()=>{var Z,fe;$.current&&he.length>0?(fe=(Z=$.current).scrollToIndex)==null||fe.call(Z,{index:0,align:"start",behavior:"auto"}):R.current&&(R.current.scrollTop=0)}}),[he]),u.jsxs("div",{className:se,style:p,children:[te,u.jsx("div",{className:"relative flex-1 min-h-0",children:ke?u.jsx(v0,{ref:Z=>{$.current=Z},scrollerRef:Z=>{R.current=Z instanceof HTMLDivElement?Z:null},data:he,followOutput:K,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{_e&&_e()},atBottomStateChange:Ne,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(Z,fe)=>gp(fe,Z),itemContent:(Z,fe)=>{var et;const Ie=gp(fe,Z),Ae="type"in fe&&fe.type==="default_message";let Le=[],Ze=null,We={},Ve={},Ke=null,Xe=null;if(!Ae){const It=fe,ht=It.checkpointId??null;We=It.additionalKwargs??{},Ve=It.responseMetadata??{};const it=ht&&E?E.get(ht)??null:null;Ke=typeof We.step=="number"?We.step:typeof Ve.step=="number"?Ve.step:(it==null?void 0:it.step)??null;const de=typeof We.source=="string"?We.source:typeof Ve.source=="string"?Ve.source:(it==null?void 0:it.source)??null;Xe=de?String(de):null;const pe=Ke!==null&&Xe?`${Ke}:${Xe}`:null;pe&&(j!=null&&j.has(pe))?Le=j.get(pe)??[]:ht&&it&&(Le=[it]),Ze=ht??((et=Le[0])==null?void 0:et.id)??null}const Qe=(()=>{if(typeof We.parentCheckpointId=="string")return We.parentCheckpointId;if(typeof Ve.parentCheckpointId=="string")return Ve.parentCheckpointId})();return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":Ie,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Pa,{message:fe,messageIndex:Z,isStreamingMessage:t&&n===fe.id,streamingDebounceMs:r,isEditing:i===fe.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:l,onRegenerate:()=>c(Z),onCancelEdit:d,activeInterrupt:b,disableInterruptActions:S,onInterruptActionStart:k,onInterruptActionEnd:T,showToolMessages:C,checkpointCandidates:Le,activeCheckpointId:N??null,onSelectCheckpoint:A,defaultCheckpointId:Ze,messageParentCheckpointId:Qe})})}}):ne()})]})});Oa.displayName="MessageList";const xp={value:""};function $s({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,customStyles:f={},onMessageSent:p,onExcelUploadSuccess:h,onError:m}){const{api:x}=fi(),{currentThreadId:y}=Oo(),{threadId:g,messages:b,hasMore:S,isHistoryLoading:k,isLoading:T,loadOlder:C,navigateToCheckpoint:E,returnToLatest:j,checkpoint:N,checkpoints:A,interrupt:O,metadata:F}=Mo(),{isStreaming:$,error:R,connectionState:z,submit:_,stop:B}=pc(),L=g??y??null,M=(N==null?void 0:N.id)??null,J=(N==null?void 0:N.namespace)??null,X=(F==null?void 0:F.assemblingMessageId)??null,he=O,[Ne,_e]=w.useState(!1);w.useEffect(()=>{he||_e(!1)},[he]);const K=w.useCallback(()=>{_e(!0)},[]),ee=w.useCallback(()=>{_e(!1)},[]),q=!!he||Ne,[D,H]=w.useState(null),[te,se]=w.useState(""),[ne,ke]=w.useState(null),[Z,fe]=w.useState(null),[Ie,Ae]=w.useState([]),[Le,Ze]=w.useState(0),[We,Ve]=w.useState(0),[Ke,Xe]=w.useState(!1),[Qe,et]=w.useState(null),[It,ht]=w.useState(null),[it,de]=w.useState(!1),[pe,ge]=w.useState(null),[qe,Fe]=w.useState(!1),xt=w.useRef(!1),[Nt,ot]=w.useState(()=>xp.value),ze=w.useRef(Nt),jt=w.useRef(null),At=w.useCallback(G=>{xp.value=G,ot(G)},[]),[W,be]=w.useState(!1),ye=w.useRef(null),dt=w.useCallback(G=>{if(!Array.isArray(G))return{text:null,messageId:null};for(let re=G.length-1;re>=0;re--){const ae=G[re];if(!ae||ae.role!=="user")continue;const Se=(ae.content??[]).filter(Ye=>(Ye==null?void 0:Ye.type)==="text").map(Ye=>Ye.text).filter(Ye=>typeof Ye=="string"&&Ye.trim().length>0);return{text:Se.length?Se.join(" ").trim():null,messageId:ae.id??null}}return{text:null,messageId:null}},[]),mt=w.useCallback((G,re)=>{if(!G||typeof G!="object")return null;const ae=G[re];return typeof ae=="number"?ae:null},[]),St=w.useCallback((G,re)=>{if(!G||typeof G!="object")return null;const ae=G[re];return typeof ae=="string"&&ae.trim()?ae:null},[]),Oe=w.useMemo(()=>{const G=Se=>{if(!Array.isArray(Se)||Se.length===0)return null;const ut=Se.map(Ye=>{if(typeof Ye=="string")return Ye.trim();if(Ye&&typeof Ye=="object"&&"type"in Ye){const tt=Ye;if(typeof tt.type=="string")return tt.type}return null}).filter(Ye=>!!(Ye&&Ye.length));return ut.length?ut.join(", "):null},re=Array.isArray(A)?A.map(Se=>{const ut=G(Se.next);return ut?{...Se,metadata:{...Se.metadata??{},next:ut}}:Se}):[];return re.some(Se=>mt(Se.metadata,"step")!==null)&&re.sort((Se,ut)=>{const Ye=mt(Se.metadata,"step"),tt=mt(ut.metadata,"step");if(Ye!==null||tt!==null)return(tt??Number.NEGATIVE_INFINITY)-(Ye??Number.NEGATIVE_INFINITY);const Ot=Date.parse(Se.createdAt??""),ln=Date.parse(ut.createdAt??"");return Number.isNaN(Ot)||Number.isNaN(ln)?0:ln-Ot}),re},[A,mt]),{checkpointMetaById:Kt,checkpointIndexByKey:at}=w.useMemo(()=>{const G=new Map,re=new Map;for(const ae of Oe){const Se=ae.checkpointId??null;if(!Se)continue;const ut=mt(ae.metadata,"step"),Ye=St(ae.metadata,"source"),tt={id:Se,step:ut,source:Ye,createdAt:ae.createdAt??null,namespace:ae.checkpointNs??null,parentId:ae.parentId??null};if(G.set(Se,tt),ut!==null&&Ye){const Ot=`${ut}:${Ye}`,ln=re.get(Ot)??[];ln.push(tt),re.set(Ot,ln)}}for(const ae of re.values())ae.sort((Se,ut)=>{const Ye=Se.createdAt??"";return(ut.createdAt??"").localeCompare(Ye)});return{checkpointMetaById:G,checkpointIndexByKey:re}},[Oe,mt,St]),Ct=w.useMemo(()=>{var Ye;if(!Oe.length)return[];const G=[...Oe].reverse(),re=(tt,Ot)=>{const ln=tt.checkpointId??null;if(!ln)return null;const pr=St(tt.metadata,"source");St(tt.metadata,"next");const{text:Vh,messageId:WC}=dt(tt.messages),Za=Vh&&Vh.replace(/\s+/g," ").trim()||St(tt.metadata,"title")||St(tt.metadata,"label")||Ot||pr||"Checkpoint",VC=Za.length>60?`${Za.slice(0,57)}…`:Za;return{id:ln,label:VC,messageId:WC??null,createdAt:tt.createdAt??null,step:mt(tt.metadata,"step"),source:pr??null,next:St(tt.metadata,"next")}},ae=[],Se=new Set;for(const tt of G){const Ot=((Ye=St(tt.metadata,"source"))==null?void 0:Ye.toLowerCase())??null;if(!(Ot==="input"||Ot==="user_input"||Ot==="user"))continue;const pr=re(tt,"User input");pr&&!Se.has(pr.id)&&(ae.push(pr),Se.add(pr.id))}if(!ae.length)for(const tt of G){const Ot=re(tt);Ot&&!Se.has(Ot.id)&&(ae.push(Ot),Se.add(Ot.id))}const ut=Oe.find(tt=>{var ln;return(((ln=St(tt.metadata,"source"))==null?void 0:ln.toLowerCase())??null)==="loop"});if(ut){const tt=re(ut,"Latest loop");tt&&!Se.has(tt.id)&&(ae.push(tt),Se.add(tt.id))}return ae},[Oe,dt,mt,St]),Kn=w.useRef(null),fr=w.useRef(null),qn=w.useCallback(()=>{Kn.current&&(Kn.current.value=""),fr.current&&(fr.current.value=""),Ze(G=>G+1),Ve(G=>G+1)},[]),Ya=w.useCallback(G=>{At(G)},[At]),Xs=w.useRef(!1);w.useEffect(()=>{Xs.current&&!$&&(Ae([]),qn()),Xs.current=$},[$,qn]);const[Xa,Ja]=w.useState("desktop");w.useEffect(()=>{const G=()=>{const re=window.innerWidth;Ja(re<640?"phone":re<1024?"tablet":"desktop")};return G(),window.addEventListener("resize",G),()=>window.removeEventListener("resize",G)},[]),w.useEffect(()=>{Fe(!1),xt.current=!1},[L]),w.useEffect(()=>{ze.current=Nt},[Nt]),w.useEffect(()=>{if(!D){jt.current=null;return}jt.current===null&&(jt.current=ze.current),At(te??"")},[te,D,At]);const I=w.useCallback(async()=>{if(!(!S||k||!qe))try{await C()}catch(G){console.warn("loadOlder failed",G)}},[S,qe,k,C]);w.useEffect(()=>{(async()=>{if(!x.baseUrl){ge(null);return}try{const ae=(await x.getAgent("default")).uiDefaultMessage||"";ge(ae||null)}catch(re){console.warn("Failed to fetch default message:",re),ge(null)}})()},[x.baseUrl]),w.useEffect(()=>{R&&!it&&(m==null||m(R))},[R,it,m]);const V=G=>{if(G.length>fs)return`Message too long (${G.length}/${fs} characters)`;try{return cw(G),null}catch(re){return(re==null?void 0:re.message)||"Invalid message"}},ie=async G=>{const re=G.trim();if(!(!re&&Ie.length===0)){if(re){const ae=V(re);if(ae){fe(ae);return}}try{const ae=M??void 0,Se=J??void 0,ut=D?{edit:!0,originalMessageId:D,...ne!=null&&ne.checkpointId?{originalCheckpointId:ne.checkpointId}:{},...ne!=null&&ne.checkpointNs?{originalCheckpointNs:ne.checkpointNs}:{}}:void 0;await _({text:re||"",attachments:Ie,messageAdditionalKwargs:ut},{checkpointId:ae,checkpointNs:Se}),p==null||p(re),At(""),fe(null),Ae([]),qn(),H(null),se(""),ke(null)}catch(ae){const Se=(ae==null?void 0:ae.message)||"Failed to send message";fe(Se),m==null||m(Se)}}},we=w.useCallback((G,re,ae)=>{c&&(jt.current=Nt,H(G),se(re),At(re),fe(null),ke({checkpointId:(ae==null?void 0:ae.checkpointId)??null,checkpointNs:(ae==null?void 0:ae.checkpointNs)??null}))},[Nt,c,At]),Ge=w.useCallback(()=>{H(null),se(""),ke(null),fe(null),At(jt.current??Nt),jt.current=null},[Nt,At]),st=w.useCallback((G,re,ae)=>{we(G,re,ae)},[we]),Be=w.useCallback(G=>{for(let re=G-1;re>=0;re--)if(b[re].role==="user"){const ae=b[re].content||[],ut=ae.filter(Ye=>Ye.type==="text").map(Ye=>Ye.text).join("")||(()=>{try{return JSON.stringify(ae,null,2)}catch{return String(ae)}})();ut&&_({text:ut},{checkpointId:M??void 0,checkpointNs:J??void 0});break}},[b,_,M,J]),$e=G=>{const re=Array.from(G.target.files||[]);Ae(ae=>[...ae,...re]),G.target.value=""},Pt=G=>{Ae(re=>{const ae=re.filter((Se,ut)=>G!==ut);return ae.length===0&&qn(),ae})},vt=async G=>{const re=(G.target.files||[])[0];if(re){et(null),ht(null),Xe(!0);try{await _({attachments:[re]},{checkpointId:M??void 0,checkpointNs:J??void 0});const ae=`Uploaded ${re.name} - processing through chat stream`;ht(ae)}catch(ae){const Se=ae instanceof Error?ae.message:"Failed to upload Excel file";console.error("Excel upload failed",ae),et(Se),m==null||m(Se)}finally{Xe(!1),G.target.value="",qn()}}},yt=async G=>{if(y){be(!0);try{if(!G){await j(),Fe(!1),requestAnimationFrame(()=>{var Se;(Se=ye.current)==null||Se.scrollToLatest()});return}const re=Oe.find(Se=>Se.checkpointId===G),ae=(re==null?void 0:re.checkpointNs)??null;await E(G,ae),Fe(!0),requestAnimationFrame(()=>{var Se;(Se=ye.current)==null||Se.scrollToTop()})}finally{be(!1)}}},qt=w.useCallback(async G=>{await yt(G)},[yt]),Gn=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${f.container||""}`,Rn=`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 ${f.messagesArea||""}`,$t=`flex-shrink-0 w-full border-t p-4 bg-transparent ${f.inputArea||""}`,go=w.useCallback(G=>{if(!G)return"Latest";const re=[];G.step!==null&&re.push(`Step ${G.step}`),G.source&&re.push(G.source);const ae=G.createdAt?new Date(G.createdAt):null,Se=ae&&!Number.isNaN(ae.getTime())?ae.toLocaleString():G.createdAt??G.id,ut=re.length?` — ${re.join(" • ")}`:"";return`${Se}${ut}`},[]);return u.jsxs("div",{className:Gn,children:[!!R&&!it&&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:R}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>de(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(oe.X,{size:16})})]}),y&&Oe.length>0&&u.jsxs("div",{className:"flex-shrink-0 flex items-center gap-2 px-4 py-2 border-b border-border bg-muted/60 text-xs dark:bg-muted/50",children:[u.jsx("span",{className:"opacity-70",children:"Checkpoint:"}),u.jsxs("select",{className:"border border-border rounded px-2 py-1 text-xs bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring dark:bg-secondary",value:M??"",onChange:G=>{const re=G.target.value||null;yt(re)},children:[u.jsx("option",{value:"",children:"Latest"}),Oe.map(G=>{const re=Kt.get(G.checkpointId??"")??null;return u.jsx("option",{value:G.checkpointId??void 0,children:go(re)},G.checkpointId)})]})]}),u.jsxs("div",{className:`relative ${Rn}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(Oa,{ref:ye,className:"h-full",style:{height:"100%"},messages:b,isStreaming:$,streamingAssistantId:X,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:Xa,enableMessageEditing:c,editingMessageId:D,onStartReached:()=>{qe&&I()},onScrollAway:G=>{if(!xt.current){xt.current=!0;return}G&&Fe(!0)},onEdit:st,onRegenerate:Be,onCancelEdit:Ge,emptyMessage:pe??void 0,isNavigatingCheckpoint:W,activeInterrupt:he,disableInterruptActions:Ne,onInterruptActionStart:K,onInterruptActionEnd:ee,showToolMessages:d,checkpointMetaById:Kt,checkpointIndexByKey:at,activeCheckpointId:M,onSelectCheckpoint:qt,timelineCheckpoints:Ct}),(z==="reconnecting"||z==="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(oe.Loader2,{className:"h-3 w-3 animate-spin"}),z==="reconnecting"?"Reconnecting…":"Connecting…"]})}),z==="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"}),T&&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(oe.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(oe.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:$t,children:[D&&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(oe.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:Ge,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(oe.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:Kn,type:"file",multiple:!0,onChange:G=>$e(G),className:"hidden"},Le),Ie.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:Ie.map((G,re)=>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(oe.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:G.name}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>Pt(re),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 ${G.name}`,children:u.jsx(oe.X,{size:12})})]},re))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:fr,type:"file",accept:".xls,.xlsx,.xlsm",onChange:vt,className:"hidden"},We),Ke&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(oe.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),It&&!Ke&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:It}),Qe&&!Ke&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:Qe})]})]}),Z&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:Z}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(Qb,{children:[u.jsx(ew,{asChild:!0,children:u.jsx(nt,{type:"button",size:"icon",variant:"outline",disabled:$||q,title:"More input actions",className:f.moreButton||"",children:u.jsx(oe.Plus,{size:16})})}),u.jsxs(Td,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(ea,{onClick:()=>{var G;return(G=Kn.current)==null?void 0:G.click()},className:"cursor-pointer",children:[u.jsx(oe.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(ea,{onClick:()=>{var G;Ke||(G=fr.current)==null||G.click()},className:`cursor-pointer ${Ke?"opacity-60 pointer-events-none":""}`,children:[u.jsx(oe.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(ex,{initialValue:te,editingMessageId:D,value:Nt,onValueChange:Ya,placeholder:D?"Edit your message...":t,isStreaming:$,disabled:q,maxLength:fs,onSend:ie,onCancelEdit:Ge,onStop:B,allowEmptySend:Ie.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${D?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${Z?"border-red-400":""} ${f.textarea||""}`})})]})]})]})}const zs=v.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:Q("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}));zs.displayName="Input";function Ma(e,[t,n]){return Math.min(n,Math.max(t,e))}function _S(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Da="ScrollArea",[yp,wT]=In(Da),[RS,sn]=yp(Da),vp=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,m]=v.useState(null),[x,y]=v.useState(null),[g,b]=v.useState(0),[S,k]=v.useState(0),[T,C]=v.useState(!1),[E,j]=v.useState(!1),N=He(t,O=>l(O)),A=Lo(o);return u.jsx(RS,{scope:n,type:r,dir:A,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:p,scrollbarX:h,onScrollbarXChange:m,scrollbarXEnabled:T,onScrollbarXEnabledChange:C,scrollbarY:x,onScrollbarYChange:y,scrollbarYEnabled:E,onScrollbarYEnabledChange:j,onCornerWidthChange:b,onCornerHeightChange:k,children:u.jsx(Re.div,{dir:A,...i,ref:N,style:{position:"relative","--radix-scroll-area-corner-width":g+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});vp.displayName=Da;var bp="ScrollAreaViewport",wp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=sn(bp,n),a=v.useRef(null),l=He(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(Re.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})})]})});wp.displayName=bp;var kn="ScrollAreaScrollbar",La=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=sn(kn,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(PS,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(OS,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(Sp,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Fa,{...r,ref:t}):null});La.displayName=kn;var PS=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=sn(kn,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(tn,{present:n||s,children:u.jsx(Sp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),OS=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=sn(kn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Ws(()=>l("SCROLL_END"),100),[a,l]=_S("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(tn,{present:n||a!=="hidden",children:u.jsx(Fa,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ue(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:ue(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),Sp=v.forwardRef((e,t)=>{const n=sn(kn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=v.useState(!1),a=e.orientation==="horizontal",l=Ws(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return Ar(n.viewport,l),Ar(n.content,l),u.jsx(tn,{present:r||s,children:u.jsx(Fa,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Fa=v.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=sn(kn,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=Ip(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 zS(p,i.current,a,h)}return n==="horizontal"?u.jsx(MS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollLeft,h=Np(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(DS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollTop,h=Np(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}),MS=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=sn(kn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=He(t,l,s.onScrollbarXChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Tp,{"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":Us(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),jp(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:Hs(i.paddingLeft),paddingEnd:Hs(i.paddingRight)}})}})}),DS=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=sn(kn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=He(t,l,s.onScrollbarYChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Tp,{"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":Us(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),jp(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:Hs(i.paddingTop),paddingEnd:Hs(i.paddingBottom)}})}})}),[LS,Cp]=yp(kn),Tp=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=sn(kn,n),[m,x]=v.useState(null),y=He(t,N=>x(N)),g=v.useRef(null),b=v.useRef(""),S=h.viewport,k=r.content-r.viewport,T=Rt(d),C=Rt(l),E=Ws(f,10);function j(N){if(g.current){const A=N.clientX-g.current.left,O=N.clientY-g.current.top;c({x:A,y:O})}}return v.useEffect(()=>{const N=A=>{const O=A.target;(m==null?void 0:m.contains(O))&&T(A,k)};return document.addEventListener("wheel",N,{passive:!1}),()=>document.removeEventListener("wheel",N,{passive:!1})},[S,m,k,T]),v.useEffect(C,[r,C]),Ar(m,E),Ar(h.content,E),u.jsx(LS,{scope:n,scrollbar:m,hasThumb:o,onThumbChange:Rt(s),onThumbPointerUp:Rt(i),onThumbPositionChange:C,onThumbPointerDown:Rt(a),children:u.jsx(Re.div,{...p,ref:y,style:{position:"absolute",...p.style},onPointerDown:ue(e.onPointerDown,N=>{N.button===0&&(N.target.setPointerCapture(N.pointerId),g.current=m.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",h.viewport&&(h.viewport.style.scrollBehavior="auto"),j(N))}),onPointerMove:ue(e.onPointerMove,j),onPointerUp:ue(e.onPointerUp,N=>{const A=N.target;A.hasPointerCapture(N.pointerId)&&A.releasePointerCapture(N.pointerId),document.body.style.webkitUserSelect=b.current,h.viewport&&(h.viewport.style.scrollBehavior=""),g.current=null})})})}),Bs="ScrollAreaThumb",kp=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Cp(Bs,e.__scopeScrollArea);return u.jsx(tn,{present:n||o.hasThumb,children:u.jsx(FS,{ref:t,...r})})}),FS=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=sn(Bs,n),i=Cp(Bs,n),{onThumbPositionChange:a}=i,l=He(t,f=>i.onThumbChange(f)),c=v.useRef(void 0),d=Ws(()=>{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=BS(f,a);c.current=h,a()}};return a(),f.addEventListener("scroll",p),()=>f.removeEventListener("scroll",p)}},[s.viewport,d,a]),u.jsx(Re.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:ue(e.onPointerDownCapture,f=>{const h=f.target.getBoundingClientRect(),m=f.clientX-h.left,x=f.clientY-h.top;i.onThumbPointerDown({x:m,y:x})}),onPointerUp:ue(e.onPointerUp,i.onThumbPointerUp)})});kp.displayName=Bs;var $a="ScrollAreaCorner",Ep=v.forwardRef((e,t)=>{const n=sn($a,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx($S,{...e,ref:t}):null});Ep.displayName=$a;var $S=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=sn($a,n),[s,i]=v.useState(0),[a,l]=v.useState(0),c=!!(s&&a);return Ar(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),Ar(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(Re.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 Hs(e){return e?parseInt(e,10):0}function Ip(e,t){const n=e/t;return isNaN(n)?0:n}function Us(e){const t=Ip(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function zS(e,t,n,r="ltr"){const o=Us(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 Ap([l,c],f)(e)}function Np(e,t,n="ltr"){const r=Us(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=Ma(e,l);return Ap([0,i],[0,a])(c)}function Ap(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 jp(e,t){return e>0&&e<t}var BS=(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 Ws(e,t){const n=Rt(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 Ar(e,t){const n=Rt(t);_t(()=>{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 _p=vp,HS=wp,US=Ep;const Rp=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(_p,{ref:r,className:Q("relative overflow-hidden",e),...n,children:[u.jsx(HS,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(Pp,{}),u.jsx(US,{})]}));Rp.displayName=_p.displayName;const Pp=v.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(La,{ref:r,orientation:t,className:Q("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(kp,{className:"relative flex-1 rounded-full bg-border"})}));Pp.displayName=La.displayName;const Op=25;function za({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:m,actions:x}=Oo(),{loadThread:y}=Mo(),{createThread:g,deleteThread:b,renameThread:S}=x,[k,T]=w.useState(Array.isArray(f)?f:[]),C=w.useRef(k.length>0),E=w.useRef(null),j=w.useRef(0),[N,A]=w.useState(null),[O,F]=w.useState(""),[$,R]=w.useState(!1);w.useEffect(()=>{const K=Array.isArray(f)?f:[];if(K.length>0){C.current=!0,T(K);return}m||(C.current=!1,T(K))},[f,m]),w.useEffect(()=>{if(!E.current)return;const K=E.current.querySelector("[data-radix-scroll-area-viewport]");if(!K)return;let ee=null,q=null;return ee=requestAnimationFrame(()=>{q=requestAnimationFrame(()=>{K.scrollTop=j.current})}),()=>{ee!==null&&cancelAnimationFrame(ee),q!==null&&cancelAnimationFrame(q)}},[k]);const z=async K=>{try{h(K),await y(K),a==null||a(K),l==null||l(K)}catch(ee){console.error("Failed to select thread:",ee)}},_=async()=>{try{R(!0);const K=await g();K&&(c==null||c(K),a==null||a(K))}catch(K){console.error("Failed to create thread:",K)}finally{R(!1)}},B=async(K,ee)=>{if(ee.stopPropagation(),!!confirm("Delete this thread?")){if(E.current){const q=E.current.querySelector("[data-radix-scroll-area-viewport]");q&&(j.current=q.scrollTop)}try{await b(K),d==null||d(K)}catch(q){console.error("Failed to delete thread:",q)}}},L=(K,ee)=>{ee.stopPropagation(),A(K.threadId),F(K.title||`Thread ${K.threadId.slice(0,8)}`)},M=async K=>{if(O.trim())try{await S(K,O.trim()),A(null),F("")}catch(ee){console.error("Failed to update title:",ee)}},J=()=>{A(null),F("")},X=(K,ee)=>{K.key==="Enter"?M(ee):K.key==="Escape"&&J()},he=K=>{if(!K)return"";try{const ee=new Date(K),D=new Date().getTime()-ee.getTime(),H=Math.floor(D/(1e3*60*60*24));return H===0?ee.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):H===1?"Yesterday":H<7?`${H} days ago`:ee.toLocaleDateString()}catch{return""}},Ne=K=>K.title||`Thread ${K.threadId.slice(0,8)}`,_e=K=>{const ee=Ne(K);return ee.length<=Op?ee:`${ee.slice(0,Op)}...`};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(nt,{onClick:_,disabled:$||m,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:$?"Creating...":"New Chat",children:u.jsx(oe.MessageSquarePlus,{size:20})})}),u.jsx(Rp,{ref:E,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:m?u.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[u.jsx(oe.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(oe.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((K,ee)=>new Date(ee.updatedAt||ee.createdAt||"").getTime()-new Date(K.updatedAt||K.createdAt||"").getTime()).map(K=>u.jsxs("div",{onClick:()=>z(K.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??p)===K.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:N===K.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:ee=>ee.stopPropagation(),children:[u.jsx(zs,{value:O,onChange:ee=>F(ee.target.value),onKeyDown:ee=>X(ee,K.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>M(K.threadId),className:"h-6 w-6 p-0",children:u.jsx(oe.Check,{size:12})}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:J,className:"h-6 w-6 p-0",children:u.jsx(oe.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:_e(K)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(oe.Calendar,{size:10}),u.jsx("span",{children:he(K.updatedAt||K.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&N!==K.threadId&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:ee=>L(K,ee),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(oe.Edit3,{size:12})}),n&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:ee=>B(K.threadId,ee),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(oe.Trash2,{size:12})})]})]}),i===K.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},K.threadId))})})]})}function jr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function WS(e){if(typeof e!="string")return;const t=e.trim();if(t)return En(t)}function Mp(){const e=[jr("__API_BASE_URL__"),jr("__CHAT_API_BASE_URL__"),jr("__CHAT_API_URL__")];for(const t of e){const n=WS(t);if(n)return n}}function Dp(){const e=[jr("__API_AUTH_TOKEN__"),jr("__CHAT_API_KEY__"),jr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function Lp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return En(t);return En()}function Fp(){const e={},t=Mp(),n=Dp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function $p(){const e=Fp(),t=Pn.getAuthToken(),n=Mp();return{apiBaseUrl:Lp(e.baseUrl,Pn.baseUrl,n),apiKey:t||e.apiKey||Dp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const zp="chat-settings";function VS(){try{const e=localStorage.getItem(zp);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function KS(e){try{const t={...e,apiBaseUrl:En(e.apiBaseUrl)};localStorage.setItem(zp,JSON.stringify(t)),t.apiKey&&Pn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function qS(){const e=$p(),t=VS(),n=Pn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Lp(Pn.baseUrl,r,e.apiBaseUrl)}}function GS(e){Pn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),KS(e)}var YS="Label",Bp=v.forwardRef((e,t)=>u.jsx(Re.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())}}));Bp.displayName=YS;var Hp=Bp;const XS=xo.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),an=v.forwardRef(({className:e,...t},n)=>u.jsx(Hp,{ref:n,className:Q(XS(),e),...t}));an.displayName=Hp.displayName;function Up(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 Vs="Switch",[JS,ST]=In(Vs),[ZS,QS]=JS(Vs),Wp=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),m=He(t,S=>h(S)),x=v.useRef(!1),y=p?d||!!p.closest("form"):!0,[g,b]=xr({prop:o,defaultProp:s??!1,onChange:c,caller:Vs});return u.jsxs(ZS,{scope:n,checked:g,disabled:a,children:[u.jsx(Re.button,{type:"button",role:"switch","aria-checked":g,"aria-required":i,"data-state":Gp(g),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:m,onClick:ue(e.onClick,S=>{b(k=>!k),y&&(x.current=S.isPropagationStopped(),x.current||S.stopPropagation())})}),y&&u.jsx(qp,{control:p,bubbles:!x.current,name:r,value:l,checked:g,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Wp.displayName=Vs;var Vp="SwitchThumb",Kp=v.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=QS(Vp,n);return u.jsx(Re.span,{"data-state":Gp(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Kp.displayName=Vp;var eC="SwitchBubbleInput",qp=v.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=v.useRef(null),a=He(i,s),l=Up(n),c=Jc(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 m=new Event("click",{bubbles:r});h.call(d,n),d.dispatchEvent(m)}},[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}})});qp.displayName=eC;function Gp(e){return e?"checked":"unchecked"}var Yp=Wp,tC=Kp;const Un=v.forwardRef(({className:e,...t},n)=>u.jsx(Yp,{className:Q("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(tC,{className:Q("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")})}));Un.displayName=Yp.displayName;var Xp=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"}),nC="VisuallyHidden",rC=v.forwardRef((e,t)=>u.jsx(Re.span,{...e,ref:t,style:{...Xp,...e.style}}));rC.displayName=nC;var oC=[" ","Enter","ArrowUp","ArrowDown"],sC=[" ","Enter"],cr="Select",[Ks,qs,iC]=vi(cr),[_r,CT]=In(cr,[iC,Xo]),Gs=Xo(),[aC,Wn]=_r(cr),[lC,cC]=_r(cr),Jp=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:m}=e,x=Gs(t),[y,g]=v.useState(null),[b,S]=v.useState(null),[k,T]=v.useState(!1),C=Lo(c),[E,j]=xr({prop:r,defaultProp:o??!1,onChange:s,caller:cr}),[N,A]=xr({prop:i,defaultProp:a,onChange:l,caller:cr}),O=v.useRef(null),F=y?m||!!y.closest("form"):!0,[$,R]=v.useState(new Set),z=Array.from($).map(_=>_.props.value).join(";");return u.jsx(au,{...x,children:u.jsxs(aC,{required:h,scope:t,trigger:y,onTriggerChange:g,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:k,onValueNodeHasChildrenChange:T,contentId:Nn(),value:N,onValueChange:A,open:E,onOpenChange:j,dir:C,triggerPointerDownPosRef:O,disabled:p,children:[u.jsx(Ks.Provider,{scope:t,children:u.jsx(lC,{scope:e.__scopeSelect,onNativeOptionAdd:v.useCallback(_=>{R(B=>new Set(B).add(_))},[]),onNativeOptionRemove:v.useCallback(_=>{R(B=>{const L=new Set(B);return L.delete(_),L})},[]),children:n})}),F?u.jsxs(wh,{"aria-hidden":!0,required:h,tabIndex:-1,name:d,autoComplete:f,value:N,onChange:_=>A(_.target.value),disabled:p,form:m,children:[N===void 0?u.jsx("option",{value:""}):null,Array.from($)]},z):null]})})};Jp.displayName=cr;var Zp="SelectTrigger",Qp=v.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Gs(n),i=Wn(Zp,n),a=i.disabled||r,l=He(t,i.onTriggerChange),c=qs(n),d=v.useRef("touch"),[f,p,h]=Ch(x=>{const y=c().filter(S=>!S.disabled),g=y.find(S=>S.value===i.value),b=Th(y,x,g);b!==void 0&&i.onValueChange(b.value)}),m=x=>{a||(i.onOpenChange(!0),h()),x&&(i.triggerPointerDownPosRef.current={x:Math.round(x.pageX),y:Math.round(x.pageY)})};return u.jsx(lu,{asChild:!0,...s,children:u.jsx(Re.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":Sh(i.value)?"":void 0,...o,ref:l,onClick:ue(o.onClick,x=>{x.currentTarget.focus(),d.current!=="mouse"&&m(x)}),onPointerDown:ue(o.onPointerDown,x=>{d.current=x.pointerType;const y=x.target;y.hasPointerCapture(x.pointerId)&&y.releasePointerCapture(x.pointerId),x.button===0&&x.ctrlKey===!1&&x.pointerType==="mouse"&&(m(x),x.preventDefault())}),onKeyDown:ue(o.onKeyDown,x=>{const y=f.current!=="";!(x.ctrlKey||x.altKey||x.metaKey)&&x.key.length===1&&p(x.key),!(y&&x.key===" ")&&oC.includes(x.key)&&(m(),x.preventDefault())})})})});Qp.displayName=Zp;var eh="SelectValue",th=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Wn(eh,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=He(t,l.onValueNodeChange);return _t(()=>{c(d)},[c,d]),u.jsx(Re.span,{...a,ref:f,style:{pointerEvents:"none"},children:Sh(l.value)?u.jsx(u.Fragment,{children:i}):s})});th.displayName=eh;var uC="SelectIcon",nh=v.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(Re.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});nh.displayName=uC;var dC="SelectPortal",rh=e=>u.jsx(Jo,{asChild:!0,...e});rh.displayName=dC;var ur="SelectContent",oh=v.forwardRef((e,t)=>{const n=Wn(ur,e.__scopeSelect),[r,o]=v.useState();if(_t(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?yo.createPortal(u.jsx(sh,{scope:e.__scopeSelect,children:u.jsx(Ks.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(ih,{...e,ref:t})});oh.displayName=ur;var mn=10,[sh,Vn]=_r(ur),fC="SelectContentImpl",pC=Yn.createSlot("SelectContent.RemoveScroll"),ih=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:m,hideWhenDetached:x,avoidCollisions:y,...g}=e,b=Wn(ur,n),[S,k]=v.useState(null),[T,C]=v.useState(null),E=He(t,q=>k(q)),[j,N]=v.useState(null),[A,O]=v.useState(null),F=qs(n),[$,R]=v.useState(!1),z=v.useRef(!1);v.useEffect(()=>{if(S)return Bi(S)},[S]),Si();const _=v.useCallback(q=>{const[D,...H]=F().map(ne=>ne.ref.current),[te]=H.slice(-1),se=document.activeElement;for(const ne of q)if(ne===se||(ne==null||ne.scrollIntoView({block:"nearest"}),ne===D&&T&&(T.scrollTop=0),ne===te&&T&&(T.scrollTop=T.scrollHeight),ne==null||ne.focus(),document.activeElement!==se))return},[F,T]),B=v.useCallback(()=>_([j,S]),[_,j,S]);v.useEffect(()=>{$&&B()},[$,B]);const{onOpenChange:L,triggerPointerDownPosRef:M}=b;v.useEffect(()=>{if(S){let q={x:0,y:0};const D=te=>{var se,ne;q={x:Math.abs(Math.round(te.pageX)-(((se=M.current)==null?void 0:se.x)??0)),y:Math.abs(Math.round(te.pageY)-(((ne=M.current)==null?void 0:ne.y)??0))}},H=te=>{q.x<=10&&q.y<=10?te.preventDefault():S.contains(te.target)||L(!1),document.removeEventListener("pointermove",D),M.current=null};return M.current!==null&&(document.addEventListener("pointermove",D),document.addEventListener("pointerup",H,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",D),document.removeEventListener("pointerup",H,{capture:!0})}}},[S,L,M]),v.useEffect(()=>{const q=()=>L(!1);return window.addEventListener("blur",q),window.addEventListener("resize",q),()=>{window.removeEventListener("blur",q),window.removeEventListener("resize",q)}},[L]);const[J,X]=Ch(q=>{const D=F().filter(se=>!se.disabled),H=D.find(se=>se.ref.current===document.activeElement),te=Th(D,q,H);te&&setTimeout(()=>te.ref.current.focus())}),he=v.useCallback((q,D,H)=>{const te=!z.current&&!H;(b.value!==void 0&&b.value===D||te)&&(N(q),te&&(z.current=!0))},[b.value]),Ne=v.useCallback(()=>S==null?void 0:S.focus(),[S]),_e=v.useCallback((q,D,H)=>{const te=!z.current&&!H;(b.value!==void 0&&b.value===D||te)&&O(q)},[b.value]),K=r==="popper"?Ba:ah,ee=K===Ba?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:m,hideWhenDetached:x,avoidCollisions:y}:{};return u.jsx(sh,{scope:n,content:S,viewport:T,onViewportChange:C,itemRefCallback:he,selectedItem:j,onItemLeave:Ne,itemTextRefCallback:_e,focusSelectedItem:B,selectedItemText:A,position:r,isPositioned:$,searchRef:J,children:u.jsx(is,{as:pC,allowPinchZoom:!0,children:u.jsx($o,{asChild:!0,trapped:b.open,onMountAutoFocus:q=>{q.preventDefault()},onUnmountAutoFocus:ue(o,q=>{var D;(D=b.trigger)==null||D.focus({preventScroll:!0}),q.preventDefault()}),children:u.jsx(Fo,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:q=>q.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:u.jsx(K,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:q=>q.preventDefault(),...g,...ee,onPlaced:()=>R(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...g.style},onKeyDown:ue(g.onKeyDown,q=>{const D=q.ctrlKey||q.altKey||q.metaKey;if(q.key==="Tab"&&q.preventDefault(),!D&&q.key.length===1&&X(q.key),["ArrowUp","ArrowDown","Home","End"].includes(q.key)){let te=F().filter(se=>!se.disabled).map(se=>se.ref.current);if(["ArrowUp","End"].includes(q.key)&&(te=te.slice().reverse()),["ArrowUp","ArrowDown"].includes(q.key)){const se=q.target,ne=te.indexOf(se);te=te.slice(ne+1)}setTimeout(()=>_(te)),q.preventDefault()}})})})})})})});ih.displayName=fC;var hC="SelectItemAlignedPosition",ah=v.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Wn(ur,n),i=Vn(ur,n),[a,l]=v.useState(null),[c,d]=v.useState(null),f=He(t,E=>d(E)),p=qs(n),h=v.useRef(!1),m=v.useRef(!0),{viewport:x,selectedItem:y,selectedItemText:g,focusSelectedItem:b}=i,S=v.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&x&&y&&g){const E=s.trigger.getBoundingClientRect(),j=c.getBoundingClientRect(),N=s.valueNode.getBoundingClientRect(),A=g.getBoundingClientRect();if(s.dir!=="rtl"){const se=A.left-j.left,ne=N.left-se,ke=E.left-ne,Z=E.width+ke,fe=Math.max(Z,j.width),Ie=window.innerWidth-mn,Ae=Ma(ne,[mn,Math.max(mn,Ie-fe)]);a.style.minWidth=Z+"px",a.style.left=Ae+"px"}else{const se=j.right-A.right,ne=window.innerWidth-N.right-se,ke=window.innerWidth-E.right-ne,Z=E.width+ke,fe=Math.max(Z,j.width),Ie=window.innerWidth-mn,Ae=Ma(ne,[mn,Math.max(mn,Ie-fe)]);a.style.minWidth=Z+"px",a.style.right=Ae+"px"}const O=p(),F=window.innerHeight-mn*2,$=x.scrollHeight,R=window.getComputedStyle(c),z=parseInt(R.borderTopWidth,10),_=parseInt(R.paddingTop,10),B=parseInt(R.borderBottomWidth,10),L=parseInt(R.paddingBottom,10),M=z+_+$+L+B,J=Math.min(y.offsetHeight*5,M),X=window.getComputedStyle(x),he=parseInt(X.paddingTop,10),Ne=parseInt(X.paddingBottom,10),_e=E.top+E.height/2-mn,K=F-_e,ee=y.offsetHeight/2,q=y.offsetTop+ee,D=z+_+q,H=M-D;if(D<=_e){const se=O.length>0&&y===O[O.length-1].ref.current;a.style.bottom="0px";const ne=c.clientHeight-x.offsetTop-x.offsetHeight,ke=Math.max(K,ee+(se?Ne:0)+ne+B),Z=D+ke;a.style.height=Z+"px"}else{const se=O.length>0&&y===O[0].ref.current;a.style.top="0px";const ke=Math.max(_e,z+x.offsetTop+(se?he:0)+ee)+H;a.style.height=ke+"px",x.scrollTop=D-_e+x.offsetTop}a.style.margin=`${mn}px 0`,a.style.minHeight=J+"px",a.style.maxHeight=F+"px",r==null||r(),requestAnimationFrame(()=>h.current=!0)}},[p,s.trigger,s.valueNode,a,c,x,y,g,s.dir,r]);_t(()=>S(),[S]);const[k,T]=v.useState();_t(()=>{c&&T(window.getComputedStyle(c).zIndex)},[c]);const C=v.useCallback(E=>{E&&m.current===!0&&(S(),b==null||b(),m.current=!1)},[S,b]);return u.jsx(gC,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:h,onScrollButtonChange:C,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:k},children:u.jsx(Re.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});ah.displayName=hC;var mC="SelectPopperPosition",Ba=v.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=mn,...s}=e,i=Gs(n);return u.jsx(cu,{...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)"}})});Ba.displayName=mC;var[gC,Ha]=_r(ur,{}),Ua="SelectViewport",lh=v.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Vn(Ua,n),i=Ha(Ua,n),a=He(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(Ks.Slot,{scope:n,children:u.jsx(Re.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:ue(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 m=window.innerHeight-mn*2,x=parseFloat(f.style.minHeight),y=parseFloat(f.style.height),g=Math.max(x,y);if(g<m){const b=g+h,S=Math.min(m,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})})})]})});lh.displayName=Ua;var ch="SelectGroup",[xC,yC]=_r(ch),vC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Nn();return u.jsx(xC,{scope:n,id:o,children:u.jsx(Re.div,{role:"group","aria-labelledby":o,...r,ref:t})})});vC.displayName=ch;var uh="SelectLabel",dh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=yC(uh,n);return u.jsx(Re.div,{id:o.id,...r,ref:t})});dh.displayName=uh;var Ys="SelectItem",[bC,fh]=_r(Ys),ph=v.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Wn(Ys,n),l=Vn(Ys,n),c=a.value===r,[d,f]=v.useState(s??""),[p,h]=v.useState(!1),m=He(t,b=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,b,r,o)}),x=Nn(),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(bC,{scope:n,value:r,disabled:o,textId:x,isSelected:c,onItemTextChange:v.useCallback(b=>{f(S=>S||((b==null?void 0:b.textContent)??"").trim())},[]),children:u.jsx(Ks.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(Re.div,{role:"option","aria-labelledby":x,"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:m,onFocus:ue(i.onFocus,()=>h(!0)),onBlur:ue(i.onBlur,()=>h(!1)),onClick:ue(i.onClick,()=>{y.current!=="mouse"&&g()}),onPointerUp:ue(i.onPointerUp,()=>{y.current==="mouse"&&g()}),onPointerDown:ue(i.onPointerDown,b=>{y.current=b.pointerType}),onPointerMove:ue(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:ue(i.onPointerLeave,b=>{var S;b.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:ue(i.onKeyDown,b=>{var k;((k=l.searchRef)==null?void 0:k.current)!==""&&b.key===" "||(sC.includes(b.key)&&g(),b.key===" "&&b.preventDefault())})})})})});ph.displayName=Ys;var mo="SelectItemText",hh=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Wn(mo,n),a=Vn(mo,n),l=fh(mo,n),c=cC(mo,n),[d,f]=v.useState(null),p=He(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,m=v.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:h},l.value),[l.disabled,l.value,h]),{onNativeOptionAdd:x,onNativeOptionRemove:y}=c;return _t(()=>(x(m),()=>y(m)),[x,y,m]),u.jsxs(u.Fragment,{children:[u.jsx(Re.span,{id:l.textId,...s,ref:p}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?yo.createPortal(s.children,i.valueNode):null]})});hh.displayName=mo;var mh="SelectItemIndicator",gh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return fh(mh,n).isSelected?u.jsx(Re.span,{"aria-hidden":!0,...r,ref:t}):null});gh.displayName=mh;var Wa="SelectScrollUpButton",xh=v.forwardRef((e,t)=>{const n=Vn(Wa,e.__scopeSelect),r=Ha(Wa,e.__scopeSelect),[o,s]=v.useState(!1),i=He(t,r.onScrollButtonChange);return _t(()=>{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(vh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});xh.displayName=Wa;var Va="SelectScrollDownButton",yh=v.forwardRef((e,t)=>{const n=Vn(Va,e.__scopeSelect),r=Ha(Va,e.__scopeSelect),[o,s]=v.useState(!1),i=He(t,r.onScrollButtonChange);return _t(()=>{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(vh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});yh.displayName=Va;var vh=v.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Vn("SelectScrollButton",n),i=v.useRef(null),a=qs(n),l=v.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return v.useEffect(()=>()=>l(),[l]),_t(()=>{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(Re.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:ue(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:ue(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:ue(o.onPointerLeave,()=>{l()})})}),wC="SelectSeparator",bh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(Re.div,{"aria-hidden":!0,...r,ref:t})});bh.displayName=wC;var Ka="SelectArrow",SC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Gs(n),s=Wn(Ka,n),i=Vn(Ka,n);return s.open&&i.position==="popper"?u.jsx(uu,{...o,...r,ref:t}):null});SC.displayName=Ka;var CC="SelectBubbleInput",wh=v.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=v.useRef(null),s=He(r,o),i=Up(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(Re.select,{...n,style:{...Xp,...n.style},ref:s,defaultValue:t})});wh.displayName=CC;function Sh(e){return e===""||e===void 0}function Ch(e){const t=Rt(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 Th(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=TC(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 TC(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var kC=Jp,kh=Qp,EC=th,IC=nh,NC=rh,Eh=oh,AC=lh,Ih=dh,Nh=ph,jC=hh,_C=gh,Ah=xh,jh=yh,_h=bh;const Rh=kC,Ph=EC,qa=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(kh,{ref:r,className:Q("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(IC,{asChild:!0,children:u.jsx(oe.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));qa.displayName=kh.displayName;const Oh=v.forwardRef(({className:e,...t},n)=>u.jsx(Ah,{ref:n,className:Q("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(oe.ChevronUp,{className:"h-4 w-4"})}));Oh.displayName=Ah.displayName;const Mh=v.forwardRef(({className:e,...t},n)=>u.jsx(jh,{ref:n,className:Q("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(oe.ChevronDown,{className:"h-4 w-4"})}));Mh.displayName=jh.displayName;const Ga=v.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(NC,{children:u.jsxs(Eh,{ref:o,className:Q("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(Oh,{}),u.jsx(AC,{className:Q("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(Mh,{})]})}));Ga.displayName=Eh.displayName;const RC=v.forwardRef(({className:e,...t},n)=>u.jsx(Ih,{ref:n,className:Q("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));RC.displayName=Ih.displayName;const dr=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Nh,{ref:r,className:Q("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(_C,{children:u.jsx(oe.Check,{className:"h-4 w-4"})})}),u.jsx(jC,{children:t})]}));dr.displayName=Nh.displayName;const PC=v.forwardRef(({className:e,...t},n)=>u.jsx(_h,{ref:n,className:Q("-mx-1 my-1 h-px bg-muted",e),...t}));PC.displayName=_h.displayName;var OC="Separator",Dh="horizontal",MC=["horizontal","vertical"],Lh=v.forwardRef((e,t)=>{const{decorative:n,orientation:r=Dh,...o}=e,s=DC(r)?r:Dh,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(Re.div,{"data-orientation":s,...a,...o,ref:t})});Lh.displayName=OC;function DC(e){return MC.includes(e)}var Fh=Lh;const $h=v.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(Fh,{ref:o,decorative:n,orientation:t,className:Q("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));$h.displayName=Fh.displayName;const LC=qf,FC=Q0,$C=Gf,zh=v.forwardRef(({className:e,...t},n)=>u.jsx(_s,{className:Q("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}));zh.displayName=_s.displayName;const zC=xo.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"}}),Bh=v.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs($C,{children:[u.jsx(zh,{}),u.jsxs(Rs,{ref:o,className:Q(zC({side:e}),t),...r,children:[n,u.jsxs(Yf,{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(oe.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Bh.displayName=Rs.displayName;const Hh=({className:e,...t})=>u.jsx("div",{className:Q("flex flex-col space-y-2 text-center sm:text-left",e),...t});Hh.displayName="SheetHeader";const Uh=v.forwardRef(({className:e,...t},n)=>u.jsx(ar,{ref:n,className:Q("text-lg font-semibold text-foreground",e),...t}));Uh.displayName=ar.displayName;const Wh=v.forwardRef(({className:e,...t},n)=>u.jsx(Ps,{ref:n,className:Q("text-sm text-muted-foreground",e),...t}));Wh.displayName=Ps.displayName;const BC={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 HC({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}=Ea();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(BC),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},m=()=>{l(e),d(!1),o(!1)},x=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(LC,{open:r,onOpenChange:o,children:[u.jsx(FC,{asChild:!0,children:u.jsxs(nt,{variant:"outline",size:"sm",className:n,children:[u.jsx(oe.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(Tf,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(Bh,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(Hh,{children:[u.jsx(Uh,{children:"Chat Settings"}),u.jsx(Wh,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(oe.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(an,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(zs,{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(nt,{variant:"outline",onClick:x,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(an,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(Un,{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(an,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(zs,{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(nt,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?u.jsx(oe.EyeOff,{className:"h-4 w-4"}):u.jsx(oe.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(oe.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(an,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(Rh,{value:a.ui.layout,onValueChange:y=>l(g=>({...g,ui:{...g.ui,layout:y}})),children:[u.jsx(qa,{children:u.jsx(Ph,{})}),u.jsxs(Ga,{children:[u.jsx(dr,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(dr,{value:"fullscreen",children:"Fullscreen"}),u.jsx(dr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(an,{htmlFor:"theme",children:"Theme"}),u.jsxs(Rh,{value:a.ui.theme,onValueChange:y=>l(g=>({...g,ui:{...g.ui,theme:y}})),children:[u.jsx(qa,{children:u.jsx(Ph,{})}),u.jsxs(Ga,{children:[u.jsx(dr,{value:"light",children:"Light"}),u.jsx(dr,{value:"dark",children:"Dark"}),u.jsx(dr,{value:"system",children:"System"})]})]})]}),u.jsx($h,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(an,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(Un,{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(an,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(Un,{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(an,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(Un,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,compactMessages:y}}))})]})]})]})]}),u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(oe.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(an,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(Un,{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(an,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx(Un,{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(an,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx(Un,{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(nt,{variant:"outline",onClick:h,children:[u.jsx(oe.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(nt,{variant:"outline",onClick:m,children:"Cancel"}),u.jsxs(nt,{onClick:p,disabled:!c,children:[u.jsx(oe.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function UC({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(Do,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx($s,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(Do,{...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(za,{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($s,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(Do,{...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(za,{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($s,{onError:s.onError,enableFileUpload:!0})})]})})}Ee.ChatApi=ql,Ee.ChatInput=mc,Ee.ChatInterface=$s,Ee.ChatProviders=Do,Ee.ChatSettings=HC,Ee.MarkdownContent=ho,Ee.MessageComponent=Pa,Ee.MessageList=Oa,Ee.ThreadManager=za,Ee.applySettings=GS,Ee.chatApiClient=Pn,Ee.default=UC,Ee.del=Kl,Ee.get=Qt,Ee.getChatToken=Ul,Ee.getCurrentSettings=qS,Ee.getDefaultApiConfig=Fp,Ee.getDefaultChatSettings=$p,Ee.onChatTokenChanged=Wl,Ee.post=di,Ee.put=Vl,Ee.setChatToken=jo,Ee.useApi=fi,Ee.useChatStream=lc,Ee.useMessagesReducer=ec,Ee.useStream=pc,Ee.useThreadState=Mo,Ee.useThreads=Oo,Object.defineProperties(Ee,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
137
+ dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[_e[be]?u.jsx(oe.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[dt,_e[be]?" (processing)":""]})]},be)}if(W.type==="interrupt"){const ye=W,dt=Fs((ye==null?void 0:ye.id)??(ye==null?void 0:ye.interrupt_id)),mt=!!(Ie&&dt&&dt===Ie),St=mt?Ae??(ye==null?void 0:ye.value):ye==null?void 0:ye.value,Oe=dt?{...ye,id:dt,interrupt_id:dt}:ye;return u.jsx(ES,{interruptPart:Oe,onApprove:et,onReject:It,disabled:b,isActive:mt,payload:St},be)}return null},[K,_e,et,It,M,c,d,R,L,Ie,Ae,g,b,Z]),it=w.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(oe.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),de=w.useCallback(()=>{const W=te.trim().length>0||ne.length>0||ke.length>0||Z.length>0;if(!J&&ke.length>0&&!r)return it();if(!J&&!W&&!r)return null;if(J)return u.jsx(AS,{message:t,viewMode:F},t.id);if(!J&&!X){const be=t,ye=u.jsx("div",{className:"space-y-2",children:be.content.map((dt,mt)=>u.jsx(ht,{part:dt,i:mt},mt))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[ye,u.jsx(kS,{className:H})]}):ye}},[te,ne.length,ke.length,Z.length,r,J,F,it,H]),pe=w.useMemo(()=>X?"Assistant":TS(t),[X,t]),ge=w.useMemo(()=>X?[]:Array.isArray(T)?T:[],[T,X]),qe=w.useMemo(()=>{var W;return ge.length?j&&ge.some(be=>be.id===j)?j:((W=ge[0])==null?void 0:W.id)??null:null},[j,ge]),xt=w.useMemo(()=>!ge.length||!C?null:ge.some(W=>W.id===C)?C:null,[C,ge])??qe,Nt=M==="user"&&ge.length>0&&typeof E=="function",ot=w.useCallback(W=>{if(!E)return;const be=(W==null?void 0:W.id)??null,ye=(W==null?void 0:W.parentId)??N??null;E(be,ye)},[N,E]),ze=w.useMemo(()=>xt?ge.findIndex(W=>W.id===xt):-1,[xt,ge]),jt=w.useMemo(()=>ze<0?null:ge[ze]??null,[ze,ge]),At=w.useCallback(W=>{const be=[];if(W.step!==null&&be.push(`Step ${W.step}`),W.source&&be.push(W.source),!W.createdAt)return be.length?be.join(" • "):W.id.slice(0,8);let ye="";try{const dt=new Date(W.createdAt);Number.isNaN(dt.getTime())||(ye=new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(dt))}catch{ye=""}return`${ye}`},[]);return J&&!f?null:u.jsxs(u.Fragment,{children:[u.jsx("div",{className:Q(Xe(),p.container),children:u.jsxs("div",{className:Q(Qe(),p.content),children:[(i||a||J)&&u.jsxs("div",{className:Q("flex items-center justify-between mb-2 pb-2 border-b border-current/10",L&&"mb-1 pb-1",H,p.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[Ke(),a&&pe&&u.jsx("span",{className:Q("font-medium",L?"text-xs":"text-sm"),children:pe}),J&&u.jsxs(Tf,{variant:"outline",className:Q("text-xs flex items-center gap-1 cursor-pointer select-none",H,"border border-current/40",L&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":F==="expanded",onClick:()=>$(W=>W==="expanded"?"preview":"expanded"),onKeyDown:W=>{(W.key==="Enter"||W.key===" ")&&(W.preventDefault(),$(be=>be==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:se.name??"Tool Output"}),se.toolCallId&&u.jsx("span",{className:"opacity-70",children:se.toolCallId.slice(0,8)}),F==="expanded"?u.jsx(oe.ChevronUp,{className:"h-3 w-3"}):u.jsx(oe.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[Nt&&jt&&ze>=0&&u.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[u.jsx("button",{type:"button",className:Q("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",ze>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(ze<=0)return;const W=ge[ze-1];W&&ot(W)},"aria-label":"Previous checkpoint",disabled:ze<=0,children:u.jsx(oe.ChevronLeft,{className:"h-3 w-3"})}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs("span",{className:"whitespace-nowrap",children:[ze+1," / ",ge.length]}),u.jsx("span",{className:"text-muted-foreground",children:At(jt)})]}),u.jsx("button",{type:"button",className:Q("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",ze<ge.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(ze>=ge.length-1)return;const W=ge[ze+1];W&&ot(W)},"aria-label":"Next checkpoint",disabled:ze>=ge.length-1,children:u.jsx(oe.ChevronRight,{className:"h-3 w-3"})})]}),i&&t.createdAt&&u.jsx("time",{className:Q("text-xs opacity-60",H,L&&"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:Q("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>Ze(),className:Q("h-6 w-6 p-0 hover:bg-foreground/10",H,L&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(oe.Copy,{className:Q(A?"text-success":H,L?"h-3 w-3":"h-4 w-4")})})}),M==="user"&&h&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:We,className:Q("h-6 w-6 p-0 hover:bg-foreground/10",H,L&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(oe.Edit,{className:Q(H,L?"h-3 w-3":"h-4 w-4")})}),M==="assistant"&&m&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:Ve,className:Q("h-6 w-6 p-0 hover:bg-foreground/10",H,L&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(oe.RotateCcw,{className:Q(H,L?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsx("div",{className:"relative",children:de()}),J&&F==="expanded"&&(se.toolCallId||se.name)&&u.jsxs("div",{className:Q("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",L&&"text-xs"),children:[se.name&&u.jsxs("div",{children:["Function: ",se.name]}),se.toolCallId&&u.jsxs("div",{children:["Call ID: ",se.toolCallId]})]}),!(i||a||J)&&s&&!o&&u.jsxs("div",{className:Q("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>Ze(),className:Q("h-6 w-6 p-0 hover:bg-background/50 text-current",L&&"h-5 w-5"),children:u.jsx(oe.Copy,{className:Q(A?"text-success":"text-current",L?"h-3 w-3":"h-4 w-4")})}),M==="user"&&h&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:We,className:Q("h-6 w-6 p-0 hover:bg-background/50 text-current",L&&"h-5 w-5"),children:u.jsx(oe.Edit,{className:Q("text-current",L?"h-3 w-3":"h-4 w-4")})}),M==="assistant"&&m&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:Ve,className:Q("h-6 w-6 p-0 hover:bg-background/50 text-current",L&&"h-5 w-5"),children:u.jsx(oe.RotateCcw,{className:Q("text-current",L?"h-3 w-3":"h-4 w-4")})})]})]})}),q&&u.jsx(rS,{isOpen:ee,onClose:D,fileId:q.id,fileName:q.name,mimeType:q.mimeType})]})},(e,t)=>{var i,a,l,c,d,f,p,h;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&hp(e.message)===hp(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages"].every(m=>e[m]===t[m]),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 mp({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:wS,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:po(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:po(e)})}function ES({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=po(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(io,{className:Q("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(ao,{className:"pb-3",children:[u.jsx(lo,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(kf,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(co,{className:"pt-0 pb-3",children:a}),u.jsx(Ef,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(nt,{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(nt,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}function IS(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=Ea(),[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,m,x)=>{var y,g;if(!t){h.preventDefault();return}if(o[x]){h.preventDefault();return}try{const b=String(m.url??""),S=b.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){h.preventDefault();const k=S[1],T=m.name||`file_${k}`,C=m.mimeType||"application/octet-stream";f({id:k,name:T,mimeType:C});return}if(b.startsWith("data:")){h.preventDefault(),s(T=>({...T,[x]:!0}));const k=r({title:"Fetching file...",description:"",open:!0});try{const T=await B0(n??void 0);if(!T||!Array.isArray(T))throw new Error("Invalid file list response");const C=T.find(E=>!E||typeof E!="object"||!((E.filename??"")===(m.name??""))?!1:typeof m.size=="number"&&typeof E.size=="number"?E.size===m.size:!0);if(!(C!=null&&C.id))throw new Error(`File "${m.name}" is not yet available on the server`);if(!C.id||!C.filename)throw new Error("Invalid file data received from server");f({id:C.id,name:m.name||C.filename||`file_${C.id}`,mimeType:m.mimeType||C.mime_type||"application/octet-stream"}),(y=k.update)==null||y.call(k,{id:k.id,title:"Success",description:`Opened ${m.name}`,open:!0})}catch(T){console.error("Failed to fetch server file:",T);const C=T instanceof Error?T.message:"Unknown error occurred";(g=k.update)==null||g.call(k,{id:k.id,title:"Failed",description:C}),r({title:"Failed to fetch file",description:C,open:!0})}finally{s(T=>({...T,[x]:!1}))}}}catch(b){console.error("File click error:",b),s(S=>({...S,[x]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:p,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function NS({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:Q("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(ho,{content:e,allowHtml:!1}):u.jsxs("pre",{className:Q("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(nt,{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(oe.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(oe.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function AS({message:e,viewMode:t}){const r=pp(e).name||"tool",o=c=>{if(c==null)return null;const d=typeof c=="string"?Ia(c)??c:c;if(d&&typeof d=="object")return u.jsx(mp,{data:d});const f=typeof d=="string"?d:(()=>{try{return po(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}=U0(c);return f?u.jsx(ho,{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(oe.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=Ns(d);return s(f)}const a=fo(i),l=Ns(a);return s(l)}const gp=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,jS=e=>{const t=e.additionalKwargs??{},n=e.responseMetadata??{},r=t.originalMessageId??n.originalMessageId??t.original_message_id??n.original_message_id;return typeof r=="string"&&r.trim()?r.trim():e.id},Oa=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:m=!0,isNavigatingCheckpoint:x=!1,onScrollAway:y,onAtBottom:g,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:T,showToolMessages:C=!0,checkpointMetaById:E,checkpointIndexByKey:j,activeCheckpointId:N,onSelectCheckpoint:A,timelineCheckpoints:O},F)=>{const $=w.useRef(null),R=w.useRef(null),z=w.useRef(!1),[_,B]=w.useState(!0),L=w.useMemo(()=>b?e.some(Z=>"type"in Z&&Z.type==="default_message"?!1:Array.isArray(Z==null?void 0:Z.content)&&Z.content.some(fe=>fe&&fe.type==="interrupt"&&(fe.id??fe.interrupt_id)===b.id)):!1,[b,e]),M=w.useMemo(()=>{if(!b||L)return null;const Z=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let fe;const Ie=b.value;if(Ie&&typeof Ie=="object"&&!Array.isArray(Ie)){const Ae=Ie.title;typeof Ae=="string"&&Ae.trim()&&(fe=Ae.trim())}return{id:`interrupt-${Z}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:Z,value:Ie,title:fe}]}},[b,L]),J=w.useMemo(()=>M?[...e,M]:e,[e,M]),X=w.useMemo(()=>C?J:J.filter(Z=>(Z==null?void 0:Z.role)!=="tool"),[J,C]),he=w.useMemo(()=>{const Z=new Set,fe=[];for(let Ie=X.length-1;Ie>=0;Ie--){const Ae=X[Ie];if(!Ae)continue;if("type"in Ae&&Ae.type==="default_message"){fe.push(Ae);continue}const Le=Ae,Ze=jS(Le);Z.has(Ze)||(Z.add(Ze),fe.push(Le))}return fe.reverse()},[X]),Ne=w.useCallback(Z=>{B(Z),y&&y(!Z),g&&g(Z)},[y,g]),_e=w.useMemo(()=>{if(a)return async()=>{if(!z.current){z.current=!0;try{await a()}finally{z.current=!1}}}},[a]),K=w.useMemo(()=>!m||x?!1:_?"auto":!1,[_,m,x]),ee=w.useMemo(()=>O??[],[O]),q=N??(ee.length?ee[ee.length-1].id:null),D=ee.length>0,H=w.useMemo(()=>{if(typeof h!="string")return null;const Z=h.trim();return Z?{id:"default-message",role:"assistant",type:"default_message",content:Z,createdAt:new Date().toISOString()}:null},[h]),te=D?u.jsxs("div",{className:"w-48 flex-shrink-0 flex-col border-r border-border/40 pr-4 flex",children:[u.jsxs("div",{className:"relative flex-1 overflow-y-auto pt-5 pb-5 pr-1",children:[u.jsxs("div",{className:"absolute left-0 right-0 top-1 flex items-center justify-between px-2 pb-3 text-xs 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(oe.Info,{className:"h-3.5 w-3.5 text-muted-foreground cursor-help"}),u.jsx("div",{className:"pointer-events-auto absolute hidden w-40 rounded-md border bg-background p-3 text-[11px] font-normal text-muted-foreground shadow-lg group-hover:block whitespace-normal leading-relaxed left-full ml-2 top-0 z-50",children:'Shows user inputs and the latest loop checkpoint. Click a dot to jump the chat to that point. Click on the "Latest" button to return to the most recent messages.'})]})]}),u.jsx("div",{className:"pointer-events-none absolute left-5 top-0 bottom-0 w-px bg-border/50"}),u.jsx("div",{className:"flex flex-col gap-4",children:ee.map(Z=>{const fe=q===Z.id;return u.jsxs("button",{type:"button",disabled:!A,onClick:()=>A==null?void 0:A(Z.id),className:`relative flex items-start gap-3 text-left text-xs transition ${fe?"text-primary":"text-muted-foreground"} ${A?"hover:text-foreground":"cursor-default opacity-70"}`,children:[u.jsx("span",{className:`mt-1 inline-flex h-4 w-4 items-center justify-center rounded-full border ${fe?"border-primary bg-primary/10 text-primary":"border-border bg-background"}`,children:u.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${fe?"bg-primary":"bg-border"}`})}),u.jsxs("span",{className:"flex-1",children:[u.jsx("span",{className:"block font-medium",children:Z.label||"User input"}),u.jsxs("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground/70",children:[Z.step!==null?`STEP ${Z.step}`:"STEP —",Z.next?` - ${Z.next}`:""]})]})]},Z.id)})})]}),A&&u.jsx("button",{type:"button",onClick:()=>A==null?void 0:A(null),className:"mt-auto rounded-md border border-border/70 px-3 py-2 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground transition hover:border-foreground/60 hover:text-foreground",children:"Latest"})]}):null,se=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),ne=()=>H?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Pa,{message:H,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{}})})}):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!"}),ke=he.length>0;return w.useImperativeHandle(F,()=>({scrollToLatest:()=>{var Z,fe;if($.current&&he.length>0){const Ie=he.length-1;(fe=(Z=$.current).scrollToIndex)==null||fe.call(Z,{index:Ie,align:"end",behavior:"auto"})}else R.current&&(R.current.scrollTop=R.current.scrollHeight)},scrollToTop:()=>{var Z,fe;$.current&&he.length>0?(fe=(Z=$.current).scrollToIndex)==null||fe.call(Z,{index:0,align:"start",behavior:"auto"}):R.current&&(R.current.scrollTop=0)}}),[he]),u.jsxs("div",{className:se,style:p,children:[te,u.jsx("div",{className:"relative flex-1 min-h-0",children:ke?u.jsx(v0,{ref:Z=>{$.current=Z},scrollerRef:Z=>{R.current=Z instanceof HTMLDivElement?Z:null},data:he,followOutput:K,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{_e&&_e()},atBottomStateChange:Ne,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(Z,fe)=>gp(fe,Z),itemContent:(Z,fe)=>{var et;const Ie=gp(fe,Z),Ae="type"in fe&&fe.type==="default_message";let Le=[],Ze=null,We={},Ve={},Ke=null,Xe=null;if(!Ae){const It=fe,ht=It.checkpointId??null;We=It.additionalKwargs??{},Ve=It.responseMetadata??{};const it=ht&&E?E.get(ht)??null:null;Ke=typeof We.step=="number"?We.step:typeof Ve.step=="number"?Ve.step:(it==null?void 0:it.step)??null;const de=typeof We.source=="string"?We.source:typeof Ve.source=="string"?Ve.source:(it==null?void 0:it.source)??null;Xe=de?String(de):null;const pe=Ke!==null&&Xe?`${Ke}:${Xe}`:null;pe&&(j!=null&&j.has(pe))?Le=j.get(pe)??[]:ht&&it&&(Le=[it]),Ze=ht??((et=Le[0])==null?void 0:et.id)??null}const Qe=(()=>{if(typeof We.parentCheckpointId=="string")return We.parentCheckpointId;if(typeof Ve.parentCheckpointId=="string")return Ve.parentCheckpointId})();return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":Ie,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Pa,{message:fe,messageIndex:Z,isStreamingMessage:t&&n===fe.id,streamingDebounceMs:r,isEditing:i===fe.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:l,onRegenerate:()=>c(Z),onCancelEdit:d,activeInterrupt:b,disableInterruptActions:S,onInterruptActionStart:k,onInterruptActionEnd:T,showToolMessages:C,checkpointCandidates:Le,activeCheckpointId:N??null,onSelectCheckpoint:A,defaultCheckpointId:Ze,messageParentCheckpointId:Qe})})}}):ne()})]})});Oa.displayName="MessageList";const xp={value:""};function $s({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,customStyles:f={},onMessageSent:p,onExcelUploadSuccess:h,onError:m}){const{api:x}=fi(),{currentThreadId:y}=Oo(),{threadId:g,messages:b,hasMore:S,isHistoryLoading:k,isLoading:T,loadOlder:C,navigateToCheckpoint:E,returnToLatest:j,checkpoint:N,checkpoints:A,interrupt:O,metadata:F}=Mo(),{isStreaming:$,error:R,connectionState:z,submit:_,stop:B}=pc(),L=g??y??null,M=(N==null?void 0:N.id)??null,J=(N==null?void 0:N.namespace)??null,X=(F==null?void 0:F.assemblingMessageId)??null,he=O,[Ne,_e]=w.useState(!1);w.useEffect(()=>{he||_e(!1)},[he]);const K=w.useCallback(()=>{_e(!0)},[]),ee=w.useCallback(()=>{_e(!1)},[]),q=!!he||Ne,[D,H]=w.useState(null),[te,se]=w.useState(""),[ne,ke]=w.useState(null),[Z,fe]=w.useState(null),[Ie,Ae]=w.useState([]),[Le,Ze]=w.useState(0),[We,Ve]=w.useState(0),[Ke,Xe]=w.useState(!1),[Qe,et]=w.useState(null),[It,ht]=w.useState(null),[it,de]=w.useState(!1),[pe,ge]=w.useState(null),[qe,Fe]=w.useState(!1),xt=w.useRef(!1),[Nt,ot]=w.useState(()=>xp.value),ze=w.useRef(Nt),jt=w.useRef(null),At=w.useCallback(G=>{xp.value=G,ot(G)},[]),[W,be]=w.useState(!1),ye=w.useRef(null),dt=w.useCallback(G=>{if(!Array.isArray(G))return{text:null,messageId:null};for(let re=G.length-1;re>=0;re--){const ae=G[re];if(!ae||ae.role!=="user")continue;const Se=(ae.content??[]).filter(Ye=>(Ye==null?void 0:Ye.type)==="text").map(Ye=>Ye.text).filter(Ye=>typeof Ye=="string"&&Ye.trim().length>0);return{text:Se.length?Se.join(" ").trim():null,messageId:ae.id??null}}return{text:null,messageId:null}},[]),mt=w.useCallback((G,re)=>{if(!G||typeof G!="object")return null;const ae=G[re];return typeof ae=="number"?ae:null},[]),St=w.useCallback((G,re)=>{if(!G||typeof G!="object")return null;const ae=G[re];return typeof ae=="string"&&ae.trim()?ae:null},[]),Oe=w.useMemo(()=>{const G=Se=>{if(!Array.isArray(Se)||Se.length===0)return null;const ut=Se.map(Ye=>{if(typeof Ye=="string")return Ye.trim();if(Ye&&typeof Ye=="object"&&"type"in Ye){const tt=Ye;if(typeof tt.type=="string")return tt.type}return null}).filter(Ye=>!!(Ye&&Ye.length));return ut.length?ut.join(", "):null},re=Array.isArray(A)?A.map(Se=>{const ut=G(Se.next);return ut?{...Se,metadata:{...Se.metadata??{},next:ut}}:Se}):[];return re.some(Se=>mt(Se.metadata,"step")!==null)&&re.sort((Se,ut)=>{const Ye=mt(Se.metadata,"step"),tt=mt(ut.metadata,"step");if(Ye!==null||tt!==null)return(tt??Number.NEGATIVE_INFINITY)-(Ye??Number.NEGATIVE_INFINITY);const Ot=Date.parse(Se.createdAt??""),ln=Date.parse(ut.createdAt??"");return Number.isNaN(Ot)||Number.isNaN(ln)?0:ln-Ot}),re},[A,mt]),{checkpointMetaById:Kt,checkpointIndexByKey:at}=w.useMemo(()=>{const G=new Map,re=new Map;for(const ae of Oe){const Se=ae.checkpointId??null;if(!Se)continue;const ut=mt(ae.metadata,"step"),Ye=St(ae.metadata,"source"),tt={id:Se,step:ut,source:Ye,createdAt:ae.createdAt??null,namespace:ae.checkpointNs??null,parentId:ae.parentId??null};if(G.set(Se,tt),ut!==null&&Ye){const Ot=`${ut}:${Ye}`,ln=re.get(Ot)??[];ln.push(tt),re.set(Ot,ln)}}for(const ae of re.values())ae.sort((Se,ut)=>{const Ye=Se.createdAt??"";return(ut.createdAt??"").localeCompare(Ye)});return{checkpointMetaById:G,checkpointIndexByKey:re}},[Oe,mt,St]),Ct=w.useMemo(()=>{var Ye;if(!Oe.length)return[];const G=[...Oe].reverse(),re=(tt,Ot)=>{const ln=tt.checkpointId??null;if(!ln)return null;const pr=St(tt.metadata,"source");St(tt.metadata,"next");const{text:Vh,messageId:WC}=dt(tt.messages),Za=Vh&&Vh.replace(/\s+/g," ").trim()||St(tt.metadata,"title")||St(tt.metadata,"label")||Ot||pr||"Checkpoint",VC=Za.length>60?`${Za.slice(0,57)}…`:Za;return{id:ln,label:VC,messageId:WC??null,createdAt:tt.createdAt??null,step:mt(tt.metadata,"step"),source:pr??null,next:St(tt.metadata,"next")}},ae=[],Se=new Set;for(const tt of G){const Ot=((Ye=St(tt.metadata,"source"))==null?void 0:Ye.toLowerCase())??null;if(!(Ot==="input"||Ot==="user_input"||Ot==="user"))continue;const pr=re(tt,"User input");pr&&!Se.has(pr.id)&&(ae.push(pr),Se.add(pr.id))}if(!ae.length)for(const tt of G){const Ot=re(tt);Ot&&!Se.has(Ot.id)&&(ae.push(Ot),Se.add(Ot.id))}const ut=Oe.find(tt=>{var ln;return(((ln=St(tt.metadata,"source"))==null?void 0:ln.toLowerCase())??null)==="loop"});if(ut){const tt=re(ut,"Latest loop");tt&&!Se.has(tt.id)&&(ae.push(tt),Se.add(tt.id))}return ae},[Oe,dt,mt,St]),Kn=w.useRef(null),fr=w.useRef(null),qn=w.useCallback(()=>{Kn.current&&(Kn.current.value=""),fr.current&&(fr.current.value=""),Ze(G=>G+1),Ve(G=>G+1)},[]),Ya=w.useCallback(G=>{At(G)},[At]),Xs=w.useRef(!1);w.useEffect(()=>{Xs.current&&!$&&(Ae([]),qn()),Xs.current=$},[$,qn]);const[Xa,Ja]=w.useState("desktop");w.useEffect(()=>{const G=()=>{const re=window.innerWidth;Ja(re<640?"phone":re<1024?"tablet":"desktop")};return G(),window.addEventListener("resize",G),()=>window.removeEventListener("resize",G)},[]),w.useEffect(()=>{Fe(!1),xt.current=!1},[L]),w.useEffect(()=>{ze.current=Nt},[Nt]),w.useEffect(()=>{if(!D){jt.current=null;return}jt.current===null&&(jt.current=ze.current),At(te??"")},[te,D,At]);const I=w.useCallback(async()=>{if(!(!S||k||!qe))try{await C()}catch(G){console.warn("loadOlder failed",G)}},[S,qe,k,C]);w.useEffect(()=>{(async()=>{if(!x.baseUrl){ge(null);return}try{const ae=(await x.getAgent("default")).uiDefaultMessage||"";ge(ae||null)}catch(re){console.warn("Failed to fetch default message:",re),ge(null)}})()},[x.baseUrl]),w.useEffect(()=>{R&&!it&&(m==null||m(R))},[R,it,m]);const V=G=>{if(G.length>fs)return`Message too long (${G.length}/${fs} characters)`;try{return cw(G),null}catch(re){return(re==null?void 0:re.message)||"Invalid message"}},ie=async G=>{const re=G.trim();if(!(!re&&Ie.length===0)){if(re){const ae=V(re);if(ae){fe(ae);return}}try{const ae=M??void 0,Se=J??void 0,ut=D?{edit:!0,originalMessageId:D,...ne!=null&&ne.checkpointId?{originalCheckpointId:ne.checkpointId}:{},...ne!=null&&ne.checkpointNs?{originalCheckpointNs:ne.checkpointNs}:{}}:void 0;await _({text:re||"",attachments:Ie,messageAdditionalKwargs:ut},{checkpointId:ae,checkpointNs:Se}),p==null||p(re),At(""),fe(null),Ae([]),qn(),H(null),se(""),ke(null)}catch(ae){const Se=(ae==null?void 0:ae.message)||"Failed to send message";fe(Se),m==null||m(Se)}}},we=w.useCallback((G,re,ae)=>{c&&(jt.current=Nt,H(G),se(re),At(re),fe(null),ke({checkpointId:(ae==null?void 0:ae.checkpointId)??null,checkpointNs:(ae==null?void 0:ae.checkpointNs)??null}))},[Nt,c,At]),Ge=w.useCallback(()=>{H(null),se(""),ke(null),fe(null),At(jt.current??Nt),jt.current=null},[Nt,At]),st=w.useCallback((G,re,ae)=>{we(G,re,ae)},[we]),Be=w.useCallback(G=>{for(let re=G-1;re>=0;re--)if(b[re].role==="user"){const ae=b[re].content||[],ut=ae.filter(Ye=>Ye.type==="text").map(Ye=>Ye.text).join("")||(()=>{try{return JSON.stringify(ae,null,2)}catch{return String(ae)}})();ut&&_({text:ut},{checkpointId:M??void 0,checkpointNs:J??void 0});break}},[b,_,M,J]),$e=G=>{const re=Array.from(G.target.files||[]);Ae(ae=>[...ae,...re]),G.target.value=""},Pt=G=>{Ae(re=>{const ae=re.filter((Se,ut)=>G!==ut);return ae.length===0&&qn(),ae})},vt=async G=>{const re=(G.target.files||[])[0];if(re){et(null),ht(null),Xe(!0);try{await _({attachments:[re]},{checkpointId:M??void 0,checkpointNs:J??void 0});const ae=`Uploaded ${re.name} - processing through chat stream`;ht(ae)}catch(ae){const Se=ae instanceof Error?ae.message:"Failed to upload Excel file";console.error("Excel upload failed",ae),et(Se),m==null||m(Se)}finally{Xe(!1),G.target.value="",qn()}}},yt=async G=>{if(y){be(!0);try{if(!G){await j(),Fe(!1),requestAnimationFrame(()=>{var Se;(Se=ye.current)==null||Se.scrollToLatest()});return}const re=Oe.find(Se=>Se.checkpointId===G),ae=(re==null?void 0:re.checkpointNs)??null;await E(G,ae),Fe(!0),requestAnimationFrame(()=>{var Se;(Se=ye.current)==null||Se.scrollToTop()})}finally{be(!1)}}},qt=w.useCallback(async G=>{await yt(G)},[yt]),Gn=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${f.container||""}`,Rn=`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 ${f.messagesArea||""}`,$t=`flex-shrink-0 w-full border-t p-4 bg-transparent ${f.inputArea||""}`,go=w.useCallback(G=>{if(!G)return"Latest";const re=[];G.step!==null&&re.push(`Step ${G.step}`),G.source&&re.push(G.source);const ae=G.createdAt?new Date(G.createdAt):null,Se=ae&&!Number.isNaN(ae.getTime())?ae.toLocaleString():G.createdAt??G.id,ut=re.length?` — ${re.join(" • ")}`:"";return`${Se}${ut}`},[]);return u.jsxs("div",{className:Gn,children:[!!R&&!it&&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:R}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>de(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(oe.X,{size:16})})]}),y&&Oe.length>0&&u.jsxs("div",{className:"flex-shrink-0 flex items-center gap-2 px-4 py-2 border-b border-border bg-muted/60 text-xs dark:bg-muted/50",children:[u.jsx("span",{className:"opacity-70",children:"Checkpoint:"}),u.jsxs("select",{className:"border border-border rounded px-2 py-1 text-xs bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring dark:bg-secondary",value:M??"",onChange:G=>{const re=G.target.value||null;yt(re)},children:[u.jsx("option",{value:"",children:"Latest"}),Oe.map(G=>{const re=Kt.get(G.checkpointId??"")??null;return u.jsx("option",{value:G.checkpointId??void 0,children:go(re)},G.checkpointId)})]})]}),u.jsxs("div",{className:`relative ${Rn}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(Oa,{ref:ye,className:"h-full",style:{height:"100%"},messages:b,isStreaming:$,streamingAssistantId:X,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:Xa,enableMessageEditing:c,editingMessageId:D,onStartReached:()=>{qe&&I()},onScrollAway:G=>{if(!xt.current){xt.current=!0;return}G&&Fe(!0)},onEdit:st,onRegenerate:Be,onCancelEdit:Ge,emptyMessage:pe??void 0,isNavigatingCheckpoint:W,activeInterrupt:he,disableInterruptActions:Ne,onInterruptActionStart:K,onInterruptActionEnd:ee,showToolMessages:d,checkpointMetaById:Kt,checkpointIndexByKey:at,activeCheckpointId:M,onSelectCheckpoint:qt,timelineCheckpoints:Ct}),(z==="reconnecting"||z==="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(oe.Loader2,{className:"h-3 w-3 animate-spin"}),z==="reconnecting"?"Reconnecting…":"Connecting…"]})}),z==="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"}),T&&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(oe.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(oe.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:$t,children:[D&&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(oe.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:Ge,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(oe.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:Kn,type:"file",multiple:!0,onChange:G=>$e(G),className:"hidden"},Le),Ie.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:Ie.map((G,re)=>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(oe.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:G.name}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>Pt(re),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 ${G.name}`,children:u.jsx(oe.X,{size:12})})]},re))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:fr,type:"file",accept:".xls,.xlsx,.xlsm",onChange:vt,className:"hidden"},We),Ke&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(oe.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),It&&!Ke&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:It}),Qe&&!Ke&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:Qe})]})]}),Z&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:Z}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(Qb,{children:[u.jsx(ew,{asChild:!0,children:u.jsx(nt,{type:"button",size:"icon",variant:"outline",disabled:$||q,title:"More input actions",className:f.moreButton||"",children:u.jsx(oe.Plus,{size:16})})}),u.jsxs(Td,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(ea,{onClick:()=>{var G;return(G=Kn.current)==null?void 0:G.click()},className:"cursor-pointer",children:[u.jsx(oe.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(ea,{onClick:()=>{var G;Ke||(G=fr.current)==null||G.click()},className:`cursor-pointer ${Ke?"opacity-60 pointer-events-none":""}`,children:[u.jsx(oe.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(ex,{initialValue:te,editingMessageId:D,value:Nt,onValueChange:Ya,placeholder:D?"Edit your message...":t,isStreaming:$,disabled:q,maxLength:fs,onSend:ie,onCancelEdit:Ge,onStop:B,allowEmptySend:Ie.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${D?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${Z?"border-red-400":""} ${f.textarea||""}`})})]})]})]})}const zs=v.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:Q("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}));zs.displayName="Input";function Ma(e,[t,n]){return Math.min(n,Math.max(t,e))}function _S(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Da="ScrollArea",[yp,wT]=In(Da),[RS,sn]=yp(Da),vp=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,m]=v.useState(null),[x,y]=v.useState(null),[g,b]=v.useState(0),[S,k]=v.useState(0),[T,C]=v.useState(!1),[E,j]=v.useState(!1),N=He(t,O=>l(O)),A=Lo(o);return u.jsx(RS,{scope:n,type:r,dir:A,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:p,scrollbarX:h,onScrollbarXChange:m,scrollbarXEnabled:T,onScrollbarXEnabledChange:C,scrollbarY:x,onScrollbarYChange:y,scrollbarYEnabled:E,onScrollbarYEnabledChange:j,onCornerWidthChange:b,onCornerHeightChange:k,children:u.jsx(Re.div,{dir:A,...i,ref:N,style:{position:"relative","--radix-scroll-area-corner-width":g+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});vp.displayName=Da;var bp="ScrollAreaViewport",wp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=sn(bp,n),a=v.useRef(null),l=He(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(Re.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})})]})});wp.displayName=bp;var kn="ScrollAreaScrollbar",La=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=sn(kn,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(PS,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(OS,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(Sp,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Fa,{...r,ref:t}):null});La.displayName=kn;var PS=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=sn(kn,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(tn,{present:n||s,children:u.jsx(Sp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),OS=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=sn(kn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Ws(()=>l("SCROLL_END"),100),[a,l]=_S("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(tn,{present:n||a!=="hidden",children:u.jsx(Fa,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ue(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:ue(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),Sp=v.forwardRef((e,t)=>{const n=sn(kn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=v.useState(!1),a=e.orientation==="horizontal",l=Ws(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return Ar(n.viewport,l),Ar(n.content,l),u.jsx(tn,{present:r||s,children:u.jsx(Fa,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Fa=v.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=sn(kn,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=Ip(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 zS(p,i.current,a,h)}return n==="horizontal"?u.jsx(MS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollLeft,h=Np(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(DS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollTop,h=Np(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}),MS=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=sn(kn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=He(t,l,s.onScrollbarXChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Tp,{"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":Us(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),jp(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:Hs(i.paddingLeft),paddingEnd:Hs(i.paddingRight)}})}})}),DS=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=sn(kn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=He(t,l,s.onScrollbarYChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Tp,{"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":Us(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),jp(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:Hs(i.paddingTop),paddingEnd:Hs(i.paddingBottom)}})}})}),[LS,Cp]=yp(kn),Tp=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=sn(kn,n),[m,x]=v.useState(null),y=He(t,N=>x(N)),g=v.useRef(null),b=v.useRef(""),S=h.viewport,k=r.content-r.viewport,T=Rt(d),C=Rt(l),E=Ws(f,10);function j(N){if(g.current){const A=N.clientX-g.current.left,O=N.clientY-g.current.top;c({x:A,y:O})}}return v.useEffect(()=>{const N=A=>{const O=A.target;(m==null?void 0:m.contains(O))&&T(A,k)};return document.addEventListener("wheel",N,{passive:!1}),()=>document.removeEventListener("wheel",N,{passive:!1})},[S,m,k,T]),v.useEffect(C,[r,C]),Ar(m,E),Ar(h.content,E),u.jsx(LS,{scope:n,scrollbar:m,hasThumb:o,onThumbChange:Rt(s),onThumbPointerUp:Rt(i),onThumbPositionChange:C,onThumbPointerDown:Rt(a),children:u.jsx(Re.div,{...p,ref:y,style:{position:"absolute",...p.style},onPointerDown:ue(e.onPointerDown,N=>{N.button===0&&(N.target.setPointerCapture(N.pointerId),g.current=m.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",h.viewport&&(h.viewport.style.scrollBehavior="auto"),j(N))}),onPointerMove:ue(e.onPointerMove,j),onPointerUp:ue(e.onPointerUp,N=>{const A=N.target;A.hasPointerCapture(N.pointerId)&&A.releasePointerCapture(N.pointerId),document.body.style.webkitUserSelect=b.current,h.viewport&&(h.viewport.style.scrollBehavior=""),g.current=null})})})}),Bs="ScrollAreaThumb",kp=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Cp(Bs,e.__scopeScrollArea);return u.jsx(tn,{present:n||o.hasThumb,children:u.jsx(FS,{ref:t,...r})})}),FS=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=sn(Bs,n),i=Cp(Bs,n),{onThumbPositionChange:a}=i,l=He(t,f=>i.onThumbChange(f)),c=v.useRef(void 0),d=Ws(()=>{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=BS(f,a);c.current=h,a()}};return a(),f.addEventListener("scroll",p),()=>f.removeEventListener("scroll",p)}},[s.viewport,d,a]),u.jsx(Re.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:ue(e.onPointerDownCapture,f=>{const h=f.target.getBoundingClientRect(),m=f.clientX-h.left,x=f.clientY-h.top;i.onThumbPointerDown({x:m,y:x})}),onPointerUp:ue(e.onPointerUp,i.onThumbPointerUp)})});kp.displayName=Bs;var $a="ScrollAreaCorner",Ep=v.forwardRef((e,t)=>{const n=sn($a,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx($S,{...e,ref:t}):null});Ep.displayName=$a;var $S=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=sn($a,n),[s,i]=v.useState(0),[a,l]=v.useState(0),c=!!(s&&a);return Ar(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),Ar(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(Re.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 Hs(e){return e?parseInt(e,10):0}function Ip(e,t){const n=e/t;return isNaN(n)?0:n}function Us(e){const t=Ip(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function zS(e,t,n,r="ltr"){const o=Us(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 Ap([l,c],f)(e)}function Np(e,t,n="ltr"){const r=Us(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=Ma(e,l);return Ap([0,i],[0,a])(c)}function Ap(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 jp(e,t){return e>0&&e<t}var BS=(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 Ws(e,t){const n=Rt(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 Ar(e,t){const n=Rt(t);_t(()=>{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 _p=vp,HS=wp,US=Ep;const Rp=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(_p,{ref:r,className:Q("relative overflow-hidden",e),...n,children:[u.jsx(HS,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(Pp,{}),u.jsx(US,{})]}));Rp.displayName=_p.displayName;const Pp=v.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(La,{ref:r,orientation:t,className:Q("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(kp,{className:"relative flex-1 rounded-full bg-border"})}));Pp.displayName=La.displayName;const Op=25;function za({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:m,actions:x}=Oo(),{loadThread:y}=Mo(),{createThread:g,deleteThread:b,renameThread:S}=x,[k,T]=w.useState(Array.isArray(f)?f:[]),C=w.useRef(k.length>0),E=w.useRef(null),j=w.useRef(0),[N,A]=w.useState(null),[O,F]=w.useState(""),[$,R]=w.useState(!1);w.useEffect(()=>{const K=Array.isArray(f)?f:[];if(K.length>0){C.current=!0,T(K);return}m||(C.current=!1,T(K))},[f,m]),w.useEffect(()=>{if(!E.current)return;const K=E.current.querySelector("[data-radix-scroll-area-viewport]");if(!K)return;let ee=null,q=null;return ee=requestAnimationFrame(()=>{q=requestAnimationFrame(()=>{K.scrollTop=j.current})}),()=>{ee!==null&&cancelAnimationFrame(ee),q!==null&&cancelAnimationFrame(q)}},[k]);const z=async K=>{try{h(K),await y(K),a==null||a(K),l==null||l(K)}catch(ee){console.error("Failed to select thread:",ee)}},_=async()=>{try{R(!0);const K=await g();K&&(c==null||c(K),a==null||a(K))}catch(K){console.error("Failed to create thread:",K)}finally{R(!1)}},B=async(K,ee)=>{if(ee.stopPropagation(),!!confirm("Delete this thread?")){if(E.current){const q=E.current.querySelector("[data-radix-scroll-area-viewport]");q&&(j.current=q.scrollTop)}try{await b(K),d==null||d(K)}catch(q){console.error("Failed to delete thread:",q)}}},L=(K,ee)=>{ee.stopPropagation(),A(K.threadId),F(K.title||`Thread ${K.threadId.slice(0,8)}`)},M=async K=>{if(O.trim())try{await S(K,O.trim()),A(null),F("")}catch(ee){console.error("Failed to update title:",ee)}},J=()=>{A(null),F("")},X=(K,ee)=>{K.key==="Enter"?M(ee):K.key==="Escape"&&J()},he=K=>{if(!K)return"";try{const ee=new Date(K),D=new Date().getTime()-ee.getTime(),H=Math.floor(D/(1e3*60*60*24));return H===0?ee.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):H===1?"Yesterday":H<7?`${H} days ago`:ee.toLocaleDateString()}catch{return""}},Ne=K=>K.title||`Thread ${K.threadId.slice(0,8)}`,_e=K=>{const ee=Ne(K);return ee.length<=Op?ee:`${ee.slice(0,Op)}...`};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(nt,{onClick:_,disabled:$||m,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:$?"Creating...":"New Chat",children:u.jsx(oe.MessageSquarePlus,{size:20})})}),u.jsx(Rp,{ref:E,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:m?u.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[u.jsx(oe.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(oe.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((K,ee)=>new Date(ee.updatedAt||ee.createdAt||"").getTime()-new Date(K.updatedAt||K.createdAt||"").getTime()).map(K=>u.jsxs("div",{onClick:()=>z(K.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??p)===K.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:N===K.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:ee=>ee.stopPropagation(),children:[u.jsx(zs,{value:O,onChange:ee=>F(ee.target.value),onKeyDown:ee=>X(ee,K.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:()=>M(K.threadId),className:"h-6 w-6 p-0",children:u.jsx(oe.Check,{size:12})}),u.jsx(nt,{variant:"ghost",size:"sm",onClick:J,className:"h-6 w-6 p-0",children:u.jsx(oe.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:_e(K)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(oe.Calendar,{size:10}),u.jsx("span",{children:he(K.updatedAt||K.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&N!==K.threadId&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:ee=>L(K,ee),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(oe.Edit3,{size:12})}),n&&u.jsx(nt,{variant:"ghost",size:"sm",onClick:ee=>B(K.threadId,ee),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(oe.Trash2,{size:12})})]})]}),i===K.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},K.threadId))})})]})}function jr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function WS(e){if(typeof e!="string")return;const t=e.trim();if(t)return En(t)}function Mp(){const e=[jr("__API_BASE_URL__"),jr("__CHAT_API_BASE_URL__"),jr("__CHAT_API_URL__")];for(const t of e){const n=WS(t);if(n)return n}}function Dp(){const e=[jr("__API_AUTH_TOKEN__"),jr("__CHAT_API_KEY__"),jr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function Lp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return En(t);return En()}function Fp(){const e={},t=Mp(),n=Dp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function $p(){const e=Fp(),t=Pn.getAuthToken(),n=Mp();return{apiBaseUrl:Lp(e.baseUrl,Pn.baseUrl,n),apiKey:t||e.apiKey||Dp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const zp="chat-settings";function VS(){try{const e=localStorage.getItem(zp);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function KS(e){try{const t={...e,apiBaseUrl:En(e.apiBaseUrl)};localStorage.setItem(zp,JSON.stringify(t)),t.apiKey&&Pn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function qS(){const e=$p(),t=VS(),n=Pn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Lp(Pn.baseUrl,r,e.apiBaseUrl)}}function GS(e){Pn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),KS(e)}var YS="Label",Bp=v.forwardRef((e,t)=>u.jsx(Re.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())}}));Bp.displayName=YS;var Hp=Bp;const XS=xo.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),an=v.forwardRef(({className:e,...t},n)=>u.jsx(Hp,{ref:n,className:Q(XS(),e),...t}));an.displayName=Hp.displayName;function Up(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 Vs="Switch",[JS,ST]=In(Vs),[ZS,QS]=JS(Vs),Wp=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),m=He(t,S=>h(S)),x=v.useRef(!1),y=p?d||!!p.closest("form"):!0,[g,b]=xr({prop:o,defaultProp:s??!1,onChange:c,caller:Vs});return u.jsxs(ZS,{scope:n,checked:g,disabled:a,children:[u.jsx(Re.button,{type:"button",role:"switch","aria-checked":g,"aria-required":i,"data-state":Gp(g),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:m,onClick:ue(e.onClick,S=>{b(k=>!k),y&&(x.current=S.isPropagationStopped(),x.current||S.stopPropagation())})}),y&&u.jsx(qp,{control:p,bubbles:!x.current,name:r,value:l,checked:g,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Wp.displayName=Vs;var Vp="SwitchThumb",Kp=v.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=QS(Vp,n);return u.jsx(Re.span,{"data-state":Gp(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Kp.displayName=Vp;var eC="SwitchBubbleInput",qp=v.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=v.useRef(null),a=He(i,s),l=Up(n),c=Jc(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 m=new Event("click",{bubbles:r});h.call(d,n),d.dispatchEvent(m)}},[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}})});qp.displayName=eC;function Gp(e){return e?"checked":"unchecked"}var Yp=Wp,tC=Kp;const Un=v.forwardRef(({className:e,...t},n)=>u.jsx(Yp,{className:Q("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(tC,{className:Q("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")})}));Un.displayName=Yp.displayName;var Xp=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"}),nC="VisuallyHidden",rC=v.forwardRef((e,t)=>u.jsx(Re.span,{...e,ref:t,style:{...Xp,...e.style}}));rC.displayName=nC;var oC=[" ","Enter","ArrowUp","ArrowDown"],sC=[" ","Enter"],cr="Select",[Ks,qs,iC]=vi(cr),[_r,CT]=In(cr,[iC,Xo]),Gs=Xo(),[aC,Wn]=_r(cr),[lC,cC]=_r(cr),Jp=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:m}=e,x=Gs(t),[y,g]=v.useState(null),[b,S]=v.useState(null),[k,T]=v.useState(!1),C=Lo(c),[E,j]=xr({prop:r,defaultProp:o??!1,onChange:s,caller:cr}),[N,A]=xr({prop:i,defaultProp:a,onChange:l,caller:cr}),O=v.useRef(null),F=y?m||!!y.closest("form"):!0,[$,R]=v.useState(new Set),z=Array.from($).map(_=>_.props.value).join(";");return u.jsx(au,{...x,children:u.jsxs(aC,{required:h,scope:t,trigger:y,onTriggerChange:g,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:k,onValueNodeHasChildrenChange:T,contentId:Nn(),value:N,onValueChange:A,open:E,onOpenChange:j,dir:C,triggerPointerDownPosRef:O,disabled:p,children:[u.jsx(Ks.Provider,{scope:t,children:u.jsx(lC,{scope:e.__scopeSelect,onNativeOptionAdd:v.useCallback(_=>{R(B=>new Set(B).add(_))},[]),onNativeOptionRemove:v.useCallback(_=>{R(B=>{const L=new Set(B);return L.delete(_),L})},[]),children:n})}),F?u.jsxs(wh,{"aria-hidden":!0,required:h,tabIndex:-1,name:d,autoComplete:f,value:N,onChange:_=>A(_.target.value),disabled:p,form:m,children:[N===void 0?u.jsx("option",{value:""}):null,Array.from($)]},z):null]})})};Jp.displayName=cr;var Zp="SelectTrigger",Qp=v.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Gs(n),i=Wn(Zp,n),a=i.disabled||r,l=He(t,i.onTriggerChange),c=qs(n),d=v.useRef("touch"),[f,p,h]=Ch(x=>{const y=c().filter(S=>!S.disabled),g=y.find(S=>S.value===i.value),b=Th(y,x,g);b!==void 0&&i.onValueChange(b.value)}),m=x=>{a||(i.onOpenChange(!0),h()),x&&(i.triggerPointerDownPosRef.current={x:Math.round(x.pageX),y:Math.round(x.pageY)})};return u.jsx(lu,{asChild:!0,...s,children:u.jsx(Re.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":Sh(i.value)?"":void 0,...o,ref:l,onClick:ue(o.onClick,x=>{x.currentTarget.focus(),d.current!=="mouse"&&m(x)}),onPointerDown:ue(o.onPointerDown,x=>{d.current=x.pointerType;const y=x.target;y.hasPointerCapture(x.pointerId)&&y.releasePointerCapture(x.pointerId),x.button===0&&x.ctrlKey===!1&&x.pointerType==="mouse"&&(m(x),x.preventDefault())}),onKeyDown:ue(o.onKeyDown,x=>{const y=f.current!=="";!(x.ctrlKey||x.altKey||x.metaKey)&&x.key.length===1&&p(x.key),!(y&&x.key===" ")&&oC.includes(x.key)&&(m(),x.preventDefault())})})})});Qp.displayName=Zp;var eh="SelectValue",th=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Wn(eh,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=He(t,l.onValueNodeChange);return _t(()=>{c(d)},[c,d]),u.jsx(Re.span,{...a,ref:f,style:{pointerEvents:"none"},children:Sh(l.value)?u.jsx(u.Fragment,{children:i}):s})});th.displayName=eh;var uC="SelectIcon",nh=v.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(Re.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});nh.displayName=uC;var dC="SelectPortal",rh=e=>u.jsx(Jo,{asChild:!0,...e});rh.displayName=dC;var ur="SelectContent",oh=v.forwardRef((e,t)=>{const n=Wn(ur,e.__scopeSelect),[r,o]=v.useState();if(_t(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?yo.createPortal(u.jsx(sh,{scope:e.__scopeSelect,children:u.jsx(Ks.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(ih,{...e,ref:t})});oh.displayName=ur;var mn=10,[sh,Vn]=_r(ur),fC="SelectContentImpl",pC=Yn.createSlot("SelectContent.RemoveScroll"),ih=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:m,hideWhenDetached:x,avoidCollisions:y,...g}=e,b=Wn(ur,n),[S,k]=v.useState(null),[T,C]=v.useState(null),E=He(t,q=>k(q)),[j,N]=v.useState(null),[A,O]=v.useState(null),F=qs(n),[$,R]=v.useState(!1),z=v.useRef(!1);v.useEffect(()=>{if(S)return Bi(S)},[S]),Si();const _=v.useCallback(q=>{const[D,...H]=F().map(ne=>ne.ref.current),[te]=H.slice(-1),se=document.activeElement;for(const ne of q)if(ne===se||(ne==null||ne.scrollIntoView({block:"nearest"}),ne===D&&T&&(T.scrollTop=0),ne===te&&T&&(T.scrollTop=T.scrollHeight),ne==null||ne.focus(),document.activeElement!==se))return},[F,T]),B=v.useCallback(()=>_([j,S]),[_,j,S]);v.useEffect(()=>{$&&B()},[$,B]);const{onOpenChange:L,triggerPointerDownPosRef:M}=b;v.useEffect(()=>{if(S){let q={x:0,y:0};const D=te=>{var se,ne;q={x:Math.abs(Math.round(te.pageX)-(((se=M.current)==null?void 0:se.x)??0)),y:Math.abs(Math.round(te.pageY)-(((ne=M.current)==null?void 0:ne.y)??0))}},H=te=>{q.x<=10&&q.y<=10?te.preventDefault():S.contains(te.target)||L(!1),document.removeEventListener("pointermove",D),M.current=null};return M.current!==null&&(document.addEventListener("pointermove",D),document.addEventListener("pointerup",H,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",D),document.removeEventListener("pointerup",H,{capture:!0})}}},[S,L,M]),v.useEffect(()=>{const q=()=>L(!1);return window.addEventListener("blur",q),window.addEventListener("resize",q),()=>{window.removeEventListener("blur",q),window.removeEventListener("resize",q)}},[L]);const[J,X]=Ch(q=>{const D=F().filter(se=>!se.disabled),H=D.find(se=>se.ref.current===document.activeElement),te=Th(D,q,H);te&&setTimeout(()=>te.ref.current.focus())}),he=v.useCallback((q,D,H)=>{const te=!z.current&&!H;(b.value!==void 0&&b.value===D||te)&&(N(q),te&&(z.current=!0))},[b.value]),Ne=v.useCallback(()=>S==null?void 0:S.focus(),[S]),_e=v.useCallback((q,D,H)=>{const te=!z.current&&!H;(b.value!==void 0&&b.value===D||te)&&O(q)},[b.value]),K=r==="popper"?Ba:ah,ee=K===Ba?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:m,hideWhenDetached:x,avoidCollisions:y}:{};return u.jsx(sh,{scope:n,content:S,viewport:T,onViewportChange:C,itemRefCallback:he,selectedItem:j,onItemLeave:Ne,itemTextRefCallback:_e,focusSelectedItem:B,selectedItemText:A,position:r,isPositioned:$,searchRef:J,children:u.jsx(is,{as:pC,allowPinchZoom:!0,children:u.jsx($o,{asChild:!0,trapped:b.open,onMountAutoFocus:q=>{q.preventDefault()},onUnmountAutoFocus:ue(o,q=>{var D;(D=b.trigger)==null||D.focus({preventScroll:!0}),q.preventDefault()}),children:u.jsx(Fo,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:q=>q.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:u.jsx(K,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:q=>q.preventDefault(),...g,...ee,onPlaced:()=>R(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...g.style},onKeyDown:ue(g.onKeyDown,q=>{const D=q.ctrlKey||q.altKey||q.metaKey;if(q.key==="Tab"&&q.preventDefault(),!D&&q.key.length===1&&X(q.key),["ArrowUp","ArrowDown","Home","End"].includes(q.key)){let te=F().filter(se=>!se.disabled).map(se=>se.ref.current);if(["ArrowUp","End"].includes(q.key)&&(te=te.slice().reverse()),["ArrowUp","ArrowDown"].includes(q.key)){const se=q.target,ne=te.indexOf(se);te=te.slice(ne+1)}setTimeout(()=>_(te)),q.preventDefault()}})})})})})})});ih.displayName=fC;var hC="SelectItemAlignedPosition",ah=v.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Wn(ur,n),i=Vn(ur,n),[a,l]=v.useState(null),[c,d]=v.useState(null),f=He(t,E=>d(E)),p=qs(n),h=v.useRef(!1),m=v.useRef(!0),{viewport:x,selectedItem:y,selectedItemText:g,focusSelectedItem:b}=i,S=v.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&x&&y&&g){const E=s.trigger.getBoundingClientRect(),j=c.getBoundingClientRect(),N=s.valueNode.getBoundingClientRect(),A=g.getBoundingClientRect();if(s.dir!=="rtl"){const se=A.left-j.left,ne=N.left-se,ke=E.left-ne,Z=E.width+ke,fe=Math.max(Z,j.width),Ie=window.innerWidth-mn,Ae=Ma(ne,[mn,Math.max(mn,Ie-fe)]);a.style.minWidth=Z+"px",a.style.left=Ae+"px"}else{const se=j.right-A.right,ne=window.innerWidth-N.right-se,ke=window.innerWidth-E.right-ne,Z=E.width+ke,fe=Math.max(Z,j.width),Ie=window.innerWidth-mn,Ae=Ma(ne,[mn,Math.max(mn,Ie-fe)]);a.style.minWidth=Z+"px",a.style.right=Ae+"px"}const O=p(),F=window.innerHeight-mn*2,$=x.scrollHeight,R=window.getComputedStyle(c),z=parseInt(R.borderTopWidth,10),_=parseInt(R.paddingTop,10),B=parseInt(R.borderBottomWidth,10),L=parseInt(R.paddingBottom,10),M=z+_+$+L+B,J=Math.min(y.offsetHeight*5,M),X=window.getComputedStyle(x),he=parseInt(X.paddingTop,10),Ne=parseInt(X.paddingBottom,10),_e=E.top+E.height/2-mn,K=F-_e,ee=y.offsetHeight/2,q=y.offsetTop+ee,D=z+_+q,H=M-D;if(D<=_e){const se=O.length>0&&y===O[O.length-1].ref.current;a.style.bottom="0px";const ne=c.clientHeight-x.offsetTop-x.offsetHeight,ke=Math.max(K,ee+(se?Ne:0)+ne+B),Z=D+ke;a.style.height=Z+"px"}else{const se=O.length>0&&y===O[0].ref.current;a.style.top="0px";const ke=Math.max(_e,z+x.offsetTop+(se?he:0)+ee)+H;a.style.height=ke+"px",x.scrollTop=D-_e+x.offsetTop}a.style.margin=`${mn}px 0`,a.style.minHeight=J+"px",a.style.maxHeight=F+"px",r==null||r(),requestAnimationFrame(()=>h.current=!0)}},[p,s.trigger,s.valueNode,a,c,x,y,g,s.dir,r]);_t(()=>S(),[S]);const[k,T]=v.useState();_t(()=>{c&&T(window.getComputedStyle(c).zIndex)},[c]);const C=v.useCallback(E=>{E&&m.current===!0&&(S(),b==null||b(),m.current=!1)},[S,b]);return u.jsx(gC,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:h,onScrollButtonChange:C,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:k},children:u.jsx(Re.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});ah.displayName=hC;var mC="SelectPopperPosition",Ba=v.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=mn,...s}=e,i=Gs(n);return u.jsx(cu,{...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)"}})});Ba.displayName=mC;var[gC,Ha]=_r(ur,{}),Ua="SelectViewport",lh=v.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Vn(Ua,n),i=Ha(Ua,n),a=He(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(Ks.Slot,{scope:n,children:u.jsx(Re.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:ue(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 m=window.innerHeight-mn*2,x=parseFloat(f.style.minHeight),y=parseFloat(f.style.height),g=Math.max(x,y);if(g<m){const b=g+h,S=Math.min(m,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})})})]})});lh.displayName=Ua;var ch="SelectGroup",[xC,yC]=_r(ch),vC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Nn();return u.jsx(xC,{scope:n,id:o,children:u.jsx(Re.div,{role:"group","aria-labelledby":o,...r,ref:t})})});vC.displayName=ch;var uh="SelectLabel",dh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=yC(uh,n);return u.jsx(Re.div,{id:o.id,...r,ref:t})});dh.displayName=uh;var Ys="SelectItem",[bC,fh]=_r(Ys),ph=v.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Wn(Ys,n),l=Vn(Ys,n),c=a.value===r,[d,f]=v.useState(s??""),[p,h]=v.useState(!1),m=He(t,b=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,b,r,o)}),x=Nn(),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(bC,{scope:n,value:r,disabled:o,textId:x,isSelected:c,onItemTextChange:v.useCallback(b=>{f(S=>S||((b==null?void 0:b.textContent)??"").trim())},[]),children:u.jsx(Ks.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(Re.div,{role:"option","aria-labelledby":x,"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:m,onFocus:ue(i.onFocus,()=>h(!0)),onBlur:ue(i.onBlur,()=>h(!1)),onClick:ue(i.onClick,()=>{y.current!=="mouse"&&g()}),onPointerUp:ue(i.onPointerUp,()=>{y.current==="mouse"&&g()}),onPointerDown:ue(i.onPointerDown,b=>{y.current=b.pointerType}),onPointerMove:ue(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:ue(i.onPointerLeave,b=>{var S;b.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:ue(i.onKeyDown,b=>{var k;((k=l.searchRef)==null?void 0:k.current)!==""&&b.key===" "||(sC.includes(b.key)&&g(),b.key===" "&&b.preventDefault())})})})})});ph.displayName=Ys;var mo="SelectItemText",hh=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Wn(mo,n),a=Vn(mo,n),l=fh(mo,n),c=cC(mo,n),[d,f]=v.useState(null),p=He(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,m=v.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:h},l.value),[l.disabled,l.value,h]),{onNativeOptionAdd:x,onNativeOptionRemove:y}=c;return _t(()=>(x(m),()=>y(m)),[x,y,m]),u.jsxs(u.Fragment,{children:[u.jsx(Re.span,{id:l.textId,...s,ref:p}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?yo.createPortal(s.children,i.valueNode):null]})});hh.displayName=mo;var mh="SelectItemIndicator",gh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return fh(mh,n).isSelected?u.jsx(Re.span,{"aria-hidden":!0,...r,ref:t}):null});gh.displayName=mh;var Wa="SelectScrollUpButton",xh=v.forwardRef((e,t)=>{const n=Vn(Wa,e.__scopeSelect),r=Ha(Wa,e.__scopeSelect),[o,s]=v.useState(!1),i=He(t,r.onScrollButtonChange);return _t(()=>{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(vh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});xh.displayName=Wa;var Va="SelectScrollDownButton",yh=v.forwardRef((e,t)=>{const n=Vn(Va,e.__scopeSelect),r=Ha(Va,e.__scopeSelect),[o,s]=v.useState(!1),i=He(t,r.onScrollButtonChange);return _t(()=>{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(vh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});yh.displayName=Va;var vh=v.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Vn("SelectScrollButton",n),i=v.useRef(null),a=qs(n),l=v.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return v.useEffect(()=>()=>l(),[l]),_t(()=>{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(Re.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:ue(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:ue(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:ue(o.onPointerLeave,()=>{l()})})}),wC="SelectSeparator",bh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(Re.div,{"aria-hidden":!0,...r,ref:t})});bh.displayName=wC;var Ka="SelectArrow",SC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Gs(n),s=Wn(Ka,n),i=Vn(Ka,n);return s.open&&i.position==="popper"?u.jsx(uu,{...o,...r,ref:t}):null});SC.displayName=Ka;var CC="SelectBubbleInput",wh=v.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=v.useRef(null),s=He(r,o),i=Up(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(Re.select,{...n,style:{...Xp,...n.style},ref:s,defaultValue:t})});wh.displayName=CC;function Sh(e){return e===""||e===void 0}function Ch(e){const t=Rt(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 Th(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=TC(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 TC(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var kC=Jp,kh=Qp,EC=th,IC=nh,NC=rh,Eh=oh,AC=lh,Ih=dh,Nh=ph,jC=hh,_C=gh,Ah=xh,jh=yh,_h=bh;const Rh=kC,Ph=EC,qa=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(kh,{ref:r,className:Q("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(IC,{asChild:!0,children:u.jsx(oe.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));qa.displayName=kh.displayName;const Oh=v.forwardRef(({className:e,...t},n)=>u.jsx(Ah,{ref:n,className:Q("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(oe.ChevronUp,{className:"h-4 w-4"})}));Oh.displayName=Ah.displayName;const Mh=v.forwardRef(({className:e,...t},n)=>u.jsx(jh,{ref:n,className:Q("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(oe.ChevronDown,{className:"h-4 w-4"})}));Mh.displayName=jh.displayName;const Ga=v.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(NC,{children:u.jsxs(Eh,{ref:o,className:Q("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(Oh,{}),u.jsx(AC,{className:Q("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(Mh,{})]})}));Ga.displayName=Eh.displayName;const RC=v.forwardRef(({className:e,...t},n)=>u.jsx(Ih,{ref:n,className:Q("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));RC.displayName=Ih.displayName;const dr=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Nh,{ref:r,className:Q("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(_C,{children:u.jsx(oe.Check,{className:"h-4 w-4"})})}),u.jsx(jC,{children:t})]}));dr.displayName=Nh.displayName;const PC=v.forwardRef(({className:e,...t},n)=>u.jsx(_h,{ref:n,className:Q("-mx-1 my-1 h-px bg-muted",e),...t}));PC.displayName=_h.displayName;var OC="Separator",Dh="horizontal",MC=["horizontal","vertical"],Lh=v.forwardRef((e,t)=>{const{decorative:n,orientation:r=Dh,...o}=e,s=DC(r)?r:Dh,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(Re.div,{"data-orientation":s,...a,...o,ref:t})});Lh.displayName=OC;function DC(e){return MC.includes(e)}var Fh=Lh;const $h=v.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(Fh,{ref:o,decorative:n,orientation:t,className:Q("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));$h.displayName=Fh.displayName;const LC=qf,FC=Q0,$C=Gf,zh=v.forwardRef(({className:e,...t},n)=>u.jsx(_s,{className:Q("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}));zh.displayName=_s.displayName;const zC=xo.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"}}),Bh=v.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs($C,{children:[u.jsx(zh,{}),u.jsxs(Rs,{ref:o,className:Q(zC({side:e}),t),...r,children:[n,u.jsxs(Yf,{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(oe.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Bh.displayName=Rs.displayName;const Hh=({className:e,...t})=>u.jsx("div",{className:Q("flex flex-col space-y-2 text-center sm:text-left",e),...t});Hh.displayName="SheetHeader";const Uh=v.forwardRef(({className:e,...t},n)=>u.jsx(ar,{ref:n,className:Q("text-lg font-semibold text-foreground",e),...t}));Uh.displayName=ar.displayName;const Wh=v.forwardRef(({className:e,...t},n)=>u.jsx(Ps,{ref:n,className:Q("text-sm text-muted-foreground",e),...t}));Wh.displayName=Ps.displayName;const BC={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 HC({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}=Ea();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(BC),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},m=()=>{l(e),d(!1),o(!1)},x=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(LC,{open:r,onOpenChange:o,children:[u.jsx(FC,{asChild:!0,children:u.jsxs(nt,{variant:"outline",size:"sm",className:n,children:[u.jsx(oe.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(Tf,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(Bh,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(Hh,{children:[u.jsx(Uh,{children:"Chat Settings"}),u.jsx(Wh,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(oe.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(an,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(zs,{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(nt,{variant:"outline",onClick:x,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(an,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(Un,{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(an,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(zs,{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(nt,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?u.jsx(oe.EyeOff,{className:"h-4 w-4"}):u.jsx(oe.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(oe.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(an,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(Rh,{value:a.ui.layout,onValueChange:y=>l(g=>({...g,ui:{...g.ui,layout:y}})),children:[u.jsx(qa,{children:u.jsx(Ph,{})}),u.jsxs(Ga,{children:[u.jsx(dr,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(dr,{value:"fullscreen",children:"Fullscreen"}),u.jsx(dr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(an,{htmlFor:"theme",children:"Theme"}),u.jsxs(Rh,{value:a.ui.theme,onValueChange:y=>l(g=>({...g,ui:{...g.ui,theme:y}})),children:[u.jsx(qa,{children:u.jsx(Ph,{})}),u.jsxs(Ga,{children:[u.jsx(dr,{value:"light",children:"Light"}),u.jsx(dr,{value:"dark",children:"Dark"}),u.jsx(dr,{value:"system",children:"System"})]})]})]}),u.jsx($h,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(an,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(Un,{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(an,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(Un,{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(an,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(Un,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,compactMessages:y}}))})]})]})]})]}),u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(oe.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(an,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(Un,{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(an,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx(Un,{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(an,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx(Un,{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(nt,{variant:"outline",onClick:h,children:[u.jsx(oe.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(nt,{variant:"outline",onClick:m,children:"Cancel"}),u.jsxs(nt,{onClick:p,disabled:!c,children:[u.jsx(oe.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function UC({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(Do,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx($s,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(Do,{...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(za,{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($s,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(Do,{...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(za,{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($s,{onError:s.onError,enableFileUpload:!0})})]})})}Ee.ChatApi=ql,Ee.ChatInput=mc,Ee.ChatInterface=$s,Ee.ChatProviders=Do,Ee.ChatSettings=HC,Ee.MarkdownContent=ho,Ee.MessageComponent=Pa,Ee.MessageList=Oa,Ee.ThreadManager=za,Ee.applySettings=GS,Ee.chatApiClient=Pn,Ee.default=UC,Ee.del=Kl,Ee.get=Qt,Ee.getChatToken=Ul,Ee.getCurrentSettings=qS,Ee.getDefaultApiConfig=Fp,Ee.getDefaultChatSettings=$p,Ee.onChatTokenChanged=Wl,Ee.post=di,Ee.put=Vl,Ee.setChatToken=jo,Ee.useApi=fi,Ee.useChatStream=lc,Ee.useMessagesReducer=ec,Ee.useStream=pc,Ee.useThreadState=Mo,Ee.useThreads=Oo,Object.defineProperties(Ee,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teodor-new-chat-ui",
3
- "version": "4.3.222",
3
+ "version": "4.3.224",
4
4
  "description": "React chat UI components with streaming support, tool calls, and modern design",
5
5
  "main": "dist/index.umd.js",
6
6
  "module": "dist/index.esm.js",