teodor-new-chat-ui 4.3.263 → 4.3.264

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
@@ -14688,7 +14688,7 @@ const Mc = (e, t) => (e == null ? void 0 : e.id) ?? `message-${t}`, kC = (e) =>
14688
14688
  increaseViewportBy: { top: 100, bottom: 200 },
14689
14689
  defaultItemHeight: 80,
14690
14690
  atBottomThreshold: 50,
14691
- alignToBottom: !1,
14691
+ alignToBottom: !0,
14692
14692
  startReached: () => {
14693
14693
  ne && ne();
14694
14694
  },
package/dist/index.umd.js CHANGED
@@ -134,4 +134,4 @@ ${t}</tr>
134
134
  `+(p.tokens?this.parseInline(p.tokens):p.text);r+=n?this.renderer.paragraph(h):h;continue}default:{const N='Token with "'+p.type+'" type was not found.';if(this.options.silent){console.error(N);return}else throw new Error(N)}}}return r}parseInline(t,n){n=n||this.renderer;let r="",o,s,i;const a=t.length;for(o=0;o<a;o++){if(s=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[s.type]&&(i=this.options.extensions.renderers[s.type].call({parser:this},s),i!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type))){r+=i||"";continue}switch(s.type){case"escape":{r+=n.text(s.text);break}case"html":{r+=n.html(s.text);break}case"link":{r+=n.link(s.href,s.title,this.parseInline(s.tokens,n));break}case"image":{r+=n.image(s.href,s.title,s.text);break}case"strong":{r+=n.strong(this.parseInline(s.tokens,n));break}case"em":{r+=n.em(this.parseInline(s.tokens,n));break}case"codespan":{r+=n.codespan(s.text);break}case"br":{r+=n.br();break}case"del":{r+=n.del(this.parseInline(s.tokens,n));break}case"text":{r+=n.text(s.text);break}default:{const l='Token with "'+s.type+'" type was not found.';if(this.options.silent){console.error(l);return}else throw new Error(l)}}}return r}}class _s{constructor(t){this.options=t||nr}preprocess(t){return t}postprocess(t){return t}}Fp(_s,"passThroughHooks",new Set(["preprocess","postprocess"]));function gS(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>"+Ot(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 ih(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...ve.defaults,...s};const i=gS(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(hS(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(f){return i(f)}const c=function(f){let h;if(!f)try{r.walkTokens&&ve.walkTokens(l,r.walkTokens),h=t(l,r),r.hooks&&(h=r.hooks.postprocess(h))}catch(p){f=p}return r.highlight=a,f?i(f):o(null,h)};if(!a||a.length<3||(delete r.highlight,!l.length))return c();let d=0;ve.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(h,p){if(h)return c(h);p!=null&&p!==f.text&&(f.text=p,f.escaped=!0),d--,d===0&&c()})},0))}),d===0&&c();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(ve.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&&ve.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function ve(e,t,n){return ih($n.lex,Fn.parse)(e,t,n)}ve.options=ve.setOptions=function(e){return ve.defaults={...ve.defaults,...e},eS(ve.defaults),ve},ve.getDefaults=Gf,ve.defaults=nr,ve.use=function(...e){const t=ve.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=ve.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=ve.defaults.renderer||new Ea;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=ve.defaults.tokenizer||new ka;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=ve.defaults.hooks||new _s;for(const s in n.hooks){const i=o[s];_s.passThroughHooks.has(s)?o[s]=a=>{if(ve.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=ve.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}}ve.setOptions(r)})},ve.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(ve,r)),r.type){case"table":{for(const o of r.header)n=n.concat(ve.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(ve.walkTokens(s.tokens,t));break}case"list":{n=n.concat(ve.walkTokens(r.items,t));break}default:ve.defaults.extensions&&ve.defaults.extensions.childTokens&&ve.defaults.extensions.childTokens[r.type]?ve.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(ve.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(ve.walkTokens(r.tokens,t)))}return n},ve.parseInline=ih($n.lexInline,Fn.parseInline),ve.Parser=Fn,ve.parser=Fn.parse,ve.Renderer=Ea,ve.TextRenderer=oh,ve.Lexer=$n,ve.lexer=$n.lex,ve.Tokenizer=ka,ve.Slugger=sh,ve.Hooks=_s,ve.parse=ve,ve.options,ve.setOptions,ve.use,ve.walkTokens,ve.parseInline,Fn.parse,$n.lex;function so({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 ve.parse=="function"?ve.parse(i):ve(i)}return typeof ve.parse=="function"?ve.parse(e):ve(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:Z("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 xS="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 yS(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function ah(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 Rs(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function vS(e){const t=o=>{try{const s=ro(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 bS(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function lh(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 wS({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:Z("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const Ia=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:h={},onEdit:p,onRegenerate:m,onCancelEdit:y,onCopy:x,activeInterrupt:g,disableInterruptActions:b=!1,onInterruptActionStart:S,onInterruptActionEnd:k,checkpointCandidates:T=[],activeCheckpointId:C=null,onSelectCheckpoint:E,defaultCheckpointId:N=null,messageParentCheckpointId:j=null}){const[A,P]=w.useState(!1),[$,B]=w.useState("preview"),[_,z]=w.useState(!1),{currentThreadId:R}=No(),{respondToInterrupt:K}=Ao(),O=l==="phone"||l==="half-screen",L=t.role,q=L==="tool",G=w.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),ye=!!G,Se=!(r&&L!=="user"),{uploadingFiles:Te,handleFileClick:Y,fileViewerOpen:ne,currentFileInfo:H,closeFileViewer:D}=CS({allowFileOpen:Se,currentThreadId:R}),U=w.useMemo(()=>{switch(L){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))]"}},[L]),Q=w.useMemo(()=>G?"":yS(t.content),[G,t]),te=w.useMemo(()=>G?{}:ah(t),[G,t]),le=w.useMemo(()=>G?[]:t.content.filter(F=>F.type==="image_url"),[G,t]),_e=w.useMemo(()=>G?[]:t.content.filter(F=>F.type==="file"),[G,t]),He=w.useMemo(()=>G?[]:t.content.filter(F=>F.type==="interrupt"),[G,t]),Xe=(g==null?void 0:g.id)??(g==null?void 0:g.interrupt_id),Ke=Rs(Xe),J=g==null?void 0:g.value,he=w.useMemo(()=>G?"":vS(t.content),[G,t]),De=w.useCallback(async()=>{const F=q?he:Q;async function pe(me){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(me);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const ot=new Blob([me],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":ot})]);return}throw new Error("Clipboard API not supported in this context.")}try{await pe(F),P(!0),setTimeout(()=>P(!1),2e3),x==null||x(F)}catch(me){console.error("Failed to copy:",me)}},[q,he,Q,x]),Fe=w.useCallback(()=>{if(!p)return;const F=q?he:Q,pe="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};p(t.id,F,pe)},[p,t.id,q,he,Q,t]),qe=w.useCallback(()=>{m==null||m(n)},[m,n]),Ge=w.useCallback(()=>{const pe=Z(O?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",U);switch(L){case"user":return u.jsx(ie.User,{className:pe});case"assistant":return u.jsx(ie.Bot,{className:pe});case"tool":return u.jsx(ie.Wrench,{className:pe});default:return u.jsx(ie.Bot,{className:pe})}},[O,U,L]),Re=w.useCallback(()=>{const F="group relative mb-4 flex w-full";switch(L){case"user":return Z(F,"justify-end");case"assistant":case"tool":case"system":return Z(F,"justify-start");default:return F}},[L]),Be=w.useCallback(()=>{const F=Z("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",O&&"px-3 py-2 text-sm");if(ye)return Z(F,"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(L){case"user":return Z(F,"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 Z(F,"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 Z(F,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return Z(F,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return Z(F,"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")}},[O,ye,L]);if(ye&&G)return u.jsx("div",{className:Z(Re(),h.container),children:u.jsxs("div",{className:Z(Be(),h.content),children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2 pb-2 border-b border-current/10",children:[u.jsx(ie.Bot,{className:Z("h-4 w-4",U)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(so,{content:G.content,className:"text-current"})]})});const Qe=w.useCallback(async F=>{if(b)return;const pe=Rs((F==null?void 0:F.id)??(F==null?void 0:F.interrupt_id));if(!pe){console.warn("Interrupt part missing id",F);return}try{S==null||S(),await K(pe,!0)}catch(me){console.error("Failed to approve interrupt:",me)}finally{k==null||k()}},[b,k,S,K]),Tt=w.useCallback(async F=>{if(b)return;const pe=Rs((F==null?void 0:F.id)??(F==null?void 0:F.interrupt_id));if(!pe){console.warn("Interrupt part missing id",F);return}try{S==null||S(),await K(pe,!1)}catch(me){console.error("Failed to reject interrupt:",me)}finally{k==null||k()}},[b,k,S,K]),xt=w.useCallback(({part:F,i:pe})=>{if(F.type==="text"){const me=F.text??"",ot=me.trim(),kt=wa(ot);return kt&&L!=="tool"?u.jsx(ch,{data:kt},pe):L==="user"&&c&&ot.length>d?u.jsx(TS,{text:ot,expanded:_,onExpandedChange:z,previewLength:d,isCompact:O},pe):u.jsx(so,{content:me,allowHtml:!1},pe)}if(F.type==="image_url"){const me=F;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:me.url,alt:me.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},pe)}if(F.type==="file"){const me=F,ot=me.name||"file";return u.jsxs("a",{href:me.url,onClick:kt=>Y(kt,me,pe),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:[Te[pe]?u.jsx(ie.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[ot,Te[pe]?" (processing)":""]})]},pe)}if(F.type==="interrupt"){const me=F,ot=Rs((me==null?void 0:me.id)??(me==null?void 0:me.interrupt_id)),kt=!!(Ke&&ot&&ot===Ke),rn=kt?J??(me==null?void 0:me.value):me==null?void 0:me.value,Ye=ot?{...me,id:ot,interrupt_id:ot}:me;return u.jsx(SS,{interruptPart:Ye,onApprove:Qe,onReject:Tt,disabled:b,isActive:kt,payload:rn},pe)}return null},[Y,Te,Qe,Tt,L,c,d,_,O,Ke,J,g,b,He]),yt=w.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(ie.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),dt=w.useCallback(()=>{const F=Q.trim().length>0||le.length>0||_e.length>0||He.length>0;if(!q&&_e.length>0&&!r)return yt();if(!q&&!F&&!r)return null;if(q)return u.jsx(kS,{message:t,viewMode:$},t.id);if(!q&&!G){const pe=t,me=u.jsx("div",{className:"space-y-2",children:pe.content.map((ot,kt)=>u.jsx(xt,{part:ot,i:kt},kt))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[me,u.jsx(wS,{className:U})]}):me}},[Q,le.length,_e.length,He.length,r,q,$,yt,U]),at=w.useMemo(()=>G?"Assistant":bS(t),[G,t]),Le=w.useMemo(()=>G?[]:Array.isArray(T)?T:[],[T,G]),At=w.useMemo(()=>{var F;return Le.length?N&&Le.some(pe=>pe.id===N)?N:((F=Le[0])==null?void 0:F.id)??null:null},[N,Le]),re=w.useMemo(()=>!Le.length||!C?null:Le.some(F=>F.id===C)?C:null,[C,Le])??At,be=L==="user"&&Le.length>0&&typeof E=="function",ge=w.useCallback(F=>{if(!E)return;const pe=(F==null?void 0:F.id)??null,me=(F==null?void 0:F.parentId)??j??null;E(pe,me)},[j,E]),oe=w.useMemo(()=>re?Le.findIndex(F=>F.id===re):-1,[re,Le]),Ne=w.useMemo(()=>oe<0?null:Le[oe]??null,[oe,Le]),lt=w.useCallback(F=>{const pe=[];if(F.step!==null&&pe.push(`Step ${F.step}`),F.source&&pe.push(F.source),!F.createdAt)return pe.length?pe.join(" • "):F.id.slice(0,8);let me="";try{const ot=new Date(F.createdAt);Number.isNaN(ot.getTime())||(me=new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(ot))}catch{me=""}return`${me}`},[]);return q&&!f?null:u.jsxs(u.Fragment,{children:[u.jsx("div",{className:Z(Re(),h.container),children:u.jsxs("div",{className:Z(Be(),h.content),children:[(i||a||q)&&u.jsxs("div",{className:Z("flex items-center justify-between mb-2 pb-2 border-b border-current/10",O&&"mb-1 pb-1",U,h.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[Ge(),a&&at&&u.jsx("span",{className:Z("font-medium",O?"text-xs":"text-sm"),children:at}),q&&u.jsxs(yf,{variant:"outline",className:Z("text-xs flex items-center gap-1 cursor-pointer select-none",U,"border border-current/40",O&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":$==="expanded",onClick:()=>B(F=>F==="expanded"?"preview":"expanded"),onKeyDown:F=>{(F.key==="Enter"||F.key===" ")&&(F.preventDefault(),B(pe=>pe==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:te.name??"Tool Output"}),te.toolCallId&&u.jsx("span",{className:"opacity-70",children:te.toolCallId.slice(0,8)}),$==="expanded"?u.jsx(ie.ChevronUp,{className:"h-3 w-3"}):u.jsx(ie.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[be&&Ne&&oe>=0&&u.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[u.jsx("button",{type:"button",className:Z("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",oe>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(oe<=0)return;const F=Le[oe-1];F&&ge(F)},"aria-label":"Previous checkpoint",disabled:oe<=0,children:u.jsx(ie.ChevronLeft,{className:"h-3 w-3"})}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs("span",{className:"whitespace-nowrap",children:[oe+1," / ",Le.length]}),u.jsx("span",{className:"text-muted-foreground",children:lt(Ne)})]}),u.jsx("button",{type:"button",className:Z("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",oe<Le.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(oe>=Le.length-1)return;const F=Le[oe+1];F&&ge(F)},"aria-label":"Next checkpoint",disabled:oe>=Le.length-1,children:u.jsx(ie.ChevronRight,{className:"h-3 w-3"})})]}),i&&t.createdAt&&u.jsx("time",{className:Z("text-xs opacity-60",U,O&&"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:Z("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(tt,{variant:"ghost",size:"sm",onClick:()=>De(),className:Z("h-6 w-6 p-0 hover:bg-foreground/10",U,O&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(ie.Copy,{className:Z(A?"text-success":U,O?"h-3 w-3":"h-4 w-4")})})}),L==="user"&&p&&u.jsx(tt,{variant:"ghost",size:"sm",onClick:Fe,className:Z("h-6 w-6 p-0 hover:bg-foreground/10",U,O&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(ie.Edit,{className:Z(U,O?"h-3 w-3":"h-4 w-4")})}),L==="assistant"&&m&&u.jsx(tt,{variant:"ghost",size:"sm",onClick:qe,className:Z("h-6 w-6 p-0 hover:bg-foreground/10",U,O&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(ie.RotateCcw,{className:Z(U,O?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsx("div",{className:"relative",children:dt()}),q&&$==="expanded"&&(te.toolCallId||te.name)&&u.jsxs("div",{className:Z("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",O&&"text-xs"),children:[te.name&&u.jsxs("div",{children:["Function: ",te.name]}),te.toolCallId&&u.jsxs("div",{children:["Call ID: ",te.toolCallId]})]}),!(i||a||q)&&s&&!o&&u.jsxs("div",{className:Z("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx(tt,{variant:"ghost",size:"sm",onClick:()=>De(),className:Z("h-6 w-6 p-0 hover:bg-background/50 text-current",O&&"h-5 w-5"),children:u.jsx(ie.Copy,{className:Z(A?"text-success":"text-current",O?"h-3 w-3":"h-4 w-4")})}),L==="user"&&p&&u.jsx(tt,{variant:"ghost",size:"sm",onClick:Fe,className:Z("h-6 w-6 p-0 hover:bg-background/50 text-current",O&&"h-5 w-5"),children:u.jsx(ie.Edit,{className:Z("text-current",O?"h-3 w-3":"h-4 w-4")})}),L==="assistant"&&m&&u.jsx(tt,{variant:"ghost",size:"sm",onClick:qe,className:Z("h-6 w-6 p-0 hover:bg-background/50 text-current",O&&"h-5 w-5"),children:u.jsx(ie.RotateCcw,{className:Z("text-current",O?"h-3 w-3":"h-4 w-4")})})]})]})}),H&&u.jsx(Q0,{isOpen:ne,onClose:D,fileId:H.id,fileName:H.name,mimeType:H.mimeType})]})},(e,t)=>{var i,a,l,c,d,f,h,p;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&lh(e.message)===lh(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)&&((h=e.customStyles)==null?void 0:h.header)===((p=t.customStyles)==null?void 0:p.header);return o&&s});function ch({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:xS,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:oo(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:oo(e)})}function SS({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=oo(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(Zr,{className:Z("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(Qr,{className:"pb-3",children:[u.jsx(eo,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(vf,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(to,{className:"pt-0 pb-3",children:a}),u.jsx(bf,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(tt,{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(tt,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}function CS(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=ba(),[o,s]=w.useState({}),[i,a]=w.useState(null),[l,c]=w.useState(!1),d=w.useCallback(()=>{c(!1),a(null)},[]),f=w.useCallback(p=>{a(p),c(!0)},[]),h=w.useCallback(async(p,m,y)=>{var x,g;if(!t){p.preventDefault();return}if(o[y]){p.preventDefault();return}try{const b=String(m.url??""),S=b.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){p.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:")){p.preventDefault(),s(T=>({...T,[y]:!0}));const k=r({title:"Fetching file...",description:"",open:!0});try{const T=await L0(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"}),(x=k.update)==null||x.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,[y]:!1}))}}}catch(b){console.error("File click error:",b),s(S=>({...S,[y]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:h,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function TS({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:Z("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(so,{content:e,allowHtml:!1}):u.jsxs("pre",{className:Z("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(tt,{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(ie.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(ie.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function kS({message:e,viewMode:t}){const r=ah(e).name||"tool",o=c=>{if(c==null)return null;const d=typeof c=="string"?wa(c)??c:c;if(d&&typeof d=="object")return u.jsx(ch,{data:d});const f=typeof d=="string"?d:(()=>{try{return oo(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}=F0(c);return f?u.jsx(so,{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(ie.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=Ss(d);return s(f)}const a=ro(i),l=Ss(a);return s(l)}const uh=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,ES=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},Na=w.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:c,onCancelEdit:d,className:f,style:h,emptyMessage:p,followNewMessages:m=!0,isNavigatingCheckpoint:y=!1,onScrollAway:x,onAtBottom:g,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:T,showToolMessages:C=!0,checkpointMetaById:E,checkpointIndexByKey:N,activeCheckpointId:j,onSelectCheckpoint:A,timelineCheckpoints:P,createSyntheticThinkingMessage:$=!1},B)=>{const _=w.useRef(null),z=w.useRef(null),R=w.useRef(!1),[K,O]=w.useState(!0),L=w.useMemo(()=>b?e.some(J=>"type"in J&&J.type==="default_message"?!1:Array.isArray(J==null?void 0:J.content)&&J.content.some(he=>he&&he.type==="interrupt"&&(he.id??he.interrupt_id)===b.id)):!1,[b,e]),q=w.useMemo(()=>{if(!b||L)return null;const J=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let he;const De=b.value;if(De&&typeof De=="object"&&!Array.isArray(De)){const Fe=De.title;typeof Fe=="string"&&Fe.trim()&&(he=Fe.trim())}return{id:`interrupt-${J}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:J,value:De,title:he}]}},[b,L]),G=w.useMemo(()=>q?[...e,q]:e,[e,q]),ye=w.useMemo(()=>!$||!t?G:!G.some(he=>he.role==="assistant")&&G.length>0?[...G,{id:"thinking-assistant",role:"assistant",content:[],createdAt:new Date().toISOString()}]:G,[G,t,$]),Se=w.useMemo(()=>C?ye:ye.filter(J=>(J==null?void 0:J.role)!=="tool"),[ye,C]),Te=w.useMemo(()=>{const J=new Set,he=[];for(let De=Se.length-1;De>=0;De--){const Fe=Se[De];if(!Fe)continue;if("type"in Fe&&Fe.type==="default_message"){he.push(Fe);continue}const qe=Fe,Ge=ES(qe);J.has(Ge)||(J.add(Ge),he.push(qe))}return he.reverse()},[Se]),Y=w.useCallback(J=>{O(J),x&&x(!J),g&&g(J)},[x,g]),ne=w.useMemo(()=>{if(a)return async()=>{if(!R.current){R.current=!0;try{await a()}finally{R.current=!1}}}},[a]),H=w.useMemo(()=>!m||y?!1:K?"auto":!1,[K,m,y]),D=P??[],U=w.useMemo(()=>[...D].reverse(),[D]);w.useEffect(()=>{console.debug("[MessageList] timeline entries:",D.length,D.map(J=>({id:J.id,step:J.step,label:J.label})))},[D]);const Q=j??(D.length?D[D.length-1].id:null),te=D.length>0,le=w.useMemo(()=>{if(typeof p!="string")return null;const J=p.trim();return J?{id:"default-message",role:"assistant",type:"default_message",content:J,createdAt:new Date().toISOString()}:null},[p]),_e=te?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(ie.Info,{className:"h-3.5 w-3.5 text-muted-foreground cursor-help"}),u.jsx("div",{className:"pointer-events-auto fixed hidden w-64 rounded-md border bg-background p-3 text-[11px] font-normal text-muted-foreground shadow-lg group-hover:block whitespace-normal leading-relaxed",style:{zIndex:9999},children:'Backend pre-selects user inputs + the latest loop checkpoint. Click a dot to jump the chat to that point, or use the "Latest" button to return to the newest 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:U.map(J=>{const he=Q===J.id;return u.jsxs("button",{type:"button",disabled:!A,onClick:()=>A==null?void 0:A(J.id),className:`relative flex items-start gap-3 text-left text-xs transition ${he?"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 ${he?"border-primary bg-primary/10 text-primary":"border-border bg-background"}`,children:u.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${he?"bg-primary":"bg-border"}`})}),u.jsxs("span",{className:"flex-1",children:[u.jsx("span",{className:"block font-medium",children:J.label||"User input"}),u.jsxs("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground/70",children:[J.step!==null?`STEP ${J.step}`:"STEP —",J.next?` - ${J.next}`:""]})]})]},J.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,He=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),Xe=()=>le?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Ia,{message:le,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:p??"No messages yet. Start a conversation!"}),Ke=Te.length>0;return w.useImperativeHandle(B,()=>({scrollToLatest:()=>{var J,he;if(_.current&&Te.length>0){const De=Te.length-1;(he=(J=_.current).scrollToIndex)==null||he.call(J,{index:De,align:"end",behavior:"auto"})}else z.current&&(z.current.scrollTop=z.current.scrollHeight)},scrollToTop:()=>{var J,he;_.current&&Te.length>0?(he=(J=_.current).scrollToIndex)==null||he.call(J,{index:0,align:"start",behavior:"auto"}):z.current&&(z.current.scrollTop=0)}}),[Te]),u.jsxs("div",{className:He,style:h,children:[_e,u.jsx("div",{className:"relative flex-1 min-h-0",children:Ke?u.jsx(m0,{ref:J=>{_.current=J},scrollerRef:J=>{z.current=J instanceof HTMLDivElement?J:null},data:Te,followOutput:H,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{ne&&ne()},atBottomStateChange:Y,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(J,he)=>uh(he,J),itemContent:(J,he)=>{var yt;const De=uh(he,J),Fe="type"in he&&he.type==="default_message";let qe=[],Ge=null,Re={},Be={},Qe=null,Tt=null;if(!Fe){const dt=he,at=dt.checkpointId??null;Re=dt.additionalKwargs??{},Be=dt.responseMetadata??{};const Le=at&&E?E.get(at)??null:null;Qe=typeof Re.step=="number"?Re.step:typeof Be.step=="number"?Be.step:(Le==null?void 0:Le.step)??null;const At=typeof Re.source=="string"?Re.source:typeof Be.source=="string"?Be.source:(Le==null?void 0:Le.source)??null;Tt=At?String(At):null;const Kt=Qe!==null&&Tt?`${Qe}:${Tt}`:null;Kt&&(N!=null&&N.has(Kt))?qe=N.get(Kt)??[]:at&&Le&&(qe=[Le]),Ge=at??((yt=qe[0])==null?void 0:yt.id)??null}const xt=(()=>{if(typeof Re.parentCheckpointId=="string")return Re.parentCheckpointId;if(typeof Be.parentCheckpointId=="string")return Be.parentCheckpointId})();return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":De,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Ia,{message:he,messageIndex:J,isStreamingMessage:t&&n===he.id,streamingDebounceMs:r,isEditing:i===he.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:l,onRegenerate:()=>c(J),onCancelEdit:d,activeInterrupt:b,disableInterruptActions:S,onInterruptActionStart:k,onInterruptActionEnd:T,showToolMessages:C,checkpointCandidates:qe,activeCheckpointId:j??null,onSelectCheckpoint:A,defaultCheckpointId:Ge,messageParentCheckpointId:xt})})}}):Xe()})]})});Na.displayName="MessageList";const dh={value:""};function Ps({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:h,onExcelUploadSuccess:p,onError:m}){const{api:y}=ii(),{currentThreadId:x}=No(),{threadId:g,messages:b,hasMore:S,isHistoryLoading:k,isLoading:T,loadOlder:C,navigateToCheckpoint:E,returnToLatest:N,checkpoint:j,checkpoints:A,interrupt:P,metadata:$,timelineCheckpoints:B}=Ao(),{isStreaming:_,error:z,connectionState:R,submit:K,stop:O}=ac(),L=g??x??null,q=(j==null?void 0:j.id)??null,G=(j==null?void 0:j.namespace)??null,ye=($==null?void 0:$.assemblingMessageId)??null,Se=P,[Te,Y]=w.useState(!1);w.useEffect(()=>{Se||Y(!1)},[Se]);const ne=w.useCallback(()=>{Y(!0)},[]),H=w.useCallback(()=>{Y(!1)},[]),D=!!Se||Te,[U,Q]=w.useState(null),[te,le]=w.useState(""),[_e,He]=w.useState(null),[Xe,Ke]=w.useState(null),[J,he]=w.useState([]),[De,Fe]=w.useState(0),[qe,Ge]=w.useState(0),[Re,Be]=w.useState(!1),[Qe,Tt]=w.useState(null),[xt,yt]=w.useState(null),[dt,at]=w.useState(!1),[Le,At]=w.useState(null),Kt=w.useRef(!1),[re,be]=w.useState(()=>dh.value),ge=w.useRef(re),oe=w.useRef(null),Ne=w.useCallback(ee=>{dh.value=ee,be(ee)},[]),[lt,F]=w.useState(!1),pe=w.useRef(null),me=w.useCallback((ee,de)=>{if(!ee||typeof ee!="object")return null;const se=ee[de];return typeof se=="number"?se:null},[]),ot=w.useCallback((ee,de)=>{if(!ee||typeof ee!="object")return null;const se=ee[de];return typeof se=="string"&&se.trim()?se:null},[]),kt=w.useMemo(()=>{const ee=Pe=>{if(!Array.isArray(Pe)||Pe.length===0)return null;const ft=Pe.map(gt=>{if(typeof gt=="string")return gt.trim();if(gt&&typeof gt=="object"&&"type"in gt){const An=gt;if(typeof An.type=="string")return An.type}return null}).filter(gt=>!!(gt&&gt.length));return ft.length?ft.join(", "):null},de=Array.isArray(A)?A.map(Pe=>{const ft=ee(Pe.next);return ft?{...Pe,metadata:{...Pe.metadata??{},next:ft}}:Pe}):[];return de.some(Pe=>me(Pe.metadata,"step")!==null)&&de.sort((Pe,ft)=>{const gt=me(Pe.metadata,"step"),An=me(ft.metadata,"step");if(gt!==null||An!==null)return(An??Number.NEGATIVE_INFINITY)-(gt??Number.NEGATIVE_INFINITY);const lo=Date.parse(Pe.createdAt??""),co=Date.parse(ft.createdAt??"");return Number.isNaN(lo)||Number.isNaN(co)?0:co-lo}),de},[A,me]),{checkpointMetaById:rn,checkpointIndexByKey:Ye}=w.useMemo(()=>{const ee=new Map,de=new Map;for(const se of kt){const Pe=se.checkpointId??null;if(!Pe)continue;const ft=me(se.metadata,"step"),gt=ot(se.metadata,"source"),An={id:Pe,step:ft,source:gt,createdAt:se.createdAt??null,namespace:se.checkpointNs??null,parentId:se.parentId??null};if(ee.set(Pe,An),ft!==null&&gt){const lo=`${ft}:${gt}`,co=de.get(lo)??[];co.push(An),de.set(lo,co)}}for(const se of de.values())se.sort((Pe,ft)=>{const gt=Pe.createdAt??"";return(ft.createdAt??"").localeCompare(gt)});return{checkpointMetaById:ee,checkpointIndexByKey:de}},[kt,me,ot]),qt=B??[],et=w.useRef(null),mt=w.useRef(null),Nn=w.useCallback(()=>{et.current&&(et.current.value=""),mt.current&&(mt.current.value=""),Fe(ee=>ee+1),Ge(ee=>ee+1)},[]),Ws=w.useCallback(ee=>{Ne(ee)},[Ne]),ao=w.useRef(!1);w.useEffect(()=>{ao.current&&!_&&(he([]),Nn()),ao.current=_},[_,Nn]);const[Ua,Wa]=w.useState("desktop");w.useEffect(()=>{const ee=()=>{const de=window.innerWidth;Wa(de<640?"phone":de<1024?"tablet":"desktop")};return ee(),window.addEventListener("resize",ee),()=>window.removeEventListener("resize",ee)},[]),w.useEffect(()=>{Kt.current=!1},[L]),w.useEffect(()=>{ge.current=re},[re]),w.useEffect(()=>{if(!U){oe.current=null;return}oe.current===null&&(oe.current=ge.current),Ne(te??"")},[te,U,Ne]),w.useEffect(()=>{(async()=>{if(!y.baseUrl){At(null);return}try{const se=(await y.getAgent("default")).uiDefaultMessage||"";At(se||null)}catch(de){console.warn("Failed to fetch default message:",de),At(null)}})()},[y.baseUrl]),w.useEffect(()=>{z&&!dt&&(m==null||m(z))},[z,dt,m]);const Va=ee=>{if(ee.length>is)return`Message too long (${ee.length}/${is} characters)`;try{return sw(ee),null}catch(de){return(de==null?void 0:de.message)||"Invalid message"}},Ka=async ee=>{const de=ee.trim();if(!(!de&&J.length===0)){if(de){const se=Va(de);if(se){Ke(se);return}}try{const se=q??void 0,Pe=G??void 0,ft=U?{edit:!0,originalMessageId:U,..._e!=null&&_e.checkpointId?{originalCheckpointId:_e.checkpointId}:{},..._e!=null&&_e.checkpointNs?{originalCheckpointNs:_e.checkpointNs}:{}}:void 0;await K({text:de||"",attachments:J,messageAdditionalKwargs:ft},{checkpointId:se,checkpointNs:Pe}),h==null||h(de),Ne(""),Ke(null),he([]),Nn(),Q(null),le(""),He(null)}catch(se){const Pe=(se==null?void 0:se.message)||"Failed to send message";Ke(Pe),m==null||m(Pe)}}},I=w.useCallback((ee,de,se)=>{c&&(oe.current=re,Q(ee),le(de),Ne(de),Ke(null),He({checkpointId:(se==null?void 0:se.checkpointId)??null,checkpointNs:(se==null?void 0:se.checkpointNs)??null}))},[re,c,Ne]),V=w.useCallback(()=>{Q(null),le(""),He(null),Ke(null),Ne(oe.current??re),oe.current=null},[re,Ne]),ae=w.useCallback((ee,de,se)=>{I(ee,de,se)},[I]),ke=w.useCallback(ee=>{for(let de=ee-1;de>=0;de--)if(b[de].role==="user"){const se=b[de].content||[],ft=se.filter(gt=>gt.type==="text").map(gt=>gt.text).join("")||(()=>{try{return JSON.stringify(se,null,2)}catch{return String(se)}})();ft&&K({text:ft},{checkpointId:q??void 0,checkpointNs:G??void 0});break}},[b,K,q,G]),Ze=ee=>{const de=Array.from(ee.target.files||[]);he(se=>[...se,...de]),ee.target.value=""},rt=ee=>{he(de=>{const se=de.filter((Pe,ft)=>ee!==ft);return se.length===0&&Nn(),se})},Ue=async ee=>{const de=(ee.target.files||[])[0];if(de){Tt(null),yt(null),Be(!0);try{await K({attachments:[de]},{checkpointId:q??void 0,checkpointNs:G??void 0});const se=`Uploaded ${de.name} - processing through chat stream`;yt(se)}catch(se){const Pe=se instanceof Error?se.message:"Failed to upload Excel file";console.error("Excel upload failed",se),Tt(Pe),m==null||m(Pe)}finally{Be(!1),ee.target.value="",Nn()}}},ze=async ee=>{if(x){F(!0);try{if(!ee){await N(),requestAnimationFrame(()=>{var Pe;(Pe=pe.current)==null||Pe.scrollToLatest()});return}const de=kt.find(Pe=>Pe.checkpointId===ee),se=(de==null?void 0:de.checkpointNs)??null;await E(ee,se),requestAnimationFrame(()=>{var Pe;(Pe=pe.current)==null||Pe.scrollToTop()})}finally{F(!1)}}},jt=w.useCallback(async ee=>{await ze(ee)},[ze]),vt=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${f.container||""}`,bt=`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||""}`,Bt=`flex-shrink-0 w-full border-t p-4 bg-transparent ${f.inputArea||""}`;return w.useCallback(ee=>{if(!ee)return"Latest";const de=[];ee.step!==null&&de.push(`Step ${ee.step}`),ee.source&&de.push(ee.source);const se=ee.createdAt?new Date(ee.createdAt):null,Pe=se&&!Number.isNaN(se.getTime())?se.toLocaleString():ee.createdAt??ee.id,ft=de.length?` — ${de.join(" • ")}`:"";return`${Pe}${ft}`},[]),u.jsxs("div",{className:vt,children:[!!z&&!dt&&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:z}),u.jsx(tt,{variant:"ghost",size:"sm",onClick:()=>at(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(ie.X,{size:16})})]}),u.jsxs("div",{className:`relative ${bt}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(Na,{ref:pe,className:"h-full",style:{height:"100%"},messages:b,isStreaming:_,streamingAssistantId:ye,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:Ua,enableMessageEditing:c,editingMessageId:U,onEdit:ae,onRegenerate:ke,onCancelEdit:V,emptyMessage:Le??void 0,isNavigatingCheckpoint:lt,activeInterrupt:Se,disableInterruptActions:Te,onInterruptActionStart:ne,onInterruptActionEnd:H,showToolMessages:d,checkpointMetaById:rn,checkpointIndexByKey:Ye,activeCheckpointId:q,onSelectCheckpoint:jt,timelineCheckpoints:qt}),(R==="reconnecting"||R==="connecting")&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-muted/80 px-3 py-1 text-xs font-medium text-foreground shadow-sm backdrop-blur-sm dark:bg-muted/60",children:u.jsxs("span",{className:"flex items-center gap-2",children:[u.jsx(ie.Loader2,{className:"h-3 w-3 animate-spin"}),R==="reconnecting"?"Reconnecting…":"Connecting…"]})}),R==="error"&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-destructive/10 px-3 py-1 text-xs font-semibold text-destructive shadow-sm",children:"Connection lost"}),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(ie.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]}),(k||lt)&&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(ie.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:Bt,children:[U&&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(ie.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(tt,{variant:"ghost",size:"sm",onClick:V,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(ie.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:et,type:"file",multiple:!0,onChange:ee=>Ze(ee),className:"hidden"},De),J.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:J.map((ee,de)=>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(ie.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:ee.name}),u.jsx(tt,{variant:"ghost",size:"sm",onClick:()=>rt(de),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 ${ee.name}`,children:u.jsx(ie.X,{size:12})})]},de))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:mt,type:"file",accept:".xls,.xlsx,.xlsm",onChange:Ue,className:"hidden"},qe),Re&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(ie.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),xt&&!Re&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:xt}),Qe&&!Re&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:Qe})]})]}),Xe&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:Xe}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(Yb,{children:[u.jsx(Xb,{asChild:!0,children:u.jsx(tt,{type:"button",size:"icon",variant:"outline",disabled:_||D,title:"More input actions",className:f.moreButton||"",children:u.jsx(ie.Plus,{size:16})})}),u.jsxs(yd,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(Gi,{onClick:()=>{var ee;return(ee=et.current)==null?void 0:ee.click()},className:"cursor-pointer",children:[u.jsx(ie.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(Gi,{onClick:()=>{var ee;Re||(ee=mt.current)==null||ee.click()},className:`cursor-pointer ${Re?"opacity-60 pointer-events-none":""}`,children:[u.jsx(ie.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(Xg,{initialValue:te,editingMessageId:U,value:re,onValueChange:Ws,placeholder:U?"Edit your message...":t,isStreaming:_,disabled:D,maxLength:is,onSend:Ka,onCancelEdit:V,onStop:O,allowEmptySend:J.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${U?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${Xe?"border-red-400":""} ${f.textarea||""}`})})]})]})]})}const Os=v.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:Z("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}));Os.displayName="Input";function Aa(e,[t,n]){return Math.min(n,Math.max(t,e))}function IS(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var ja="ScrollArea",[fh,mT]=Cn(ja),[NS,tn]=fh(ja),hh=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,h]=v.useState(null),[p,m]=v.useState(null),[y,x]=v.useState(null),[g,b]=v.useState(0),[S,k]=v.useState(0),[T,C]=v.useState(!1),[E,N]=v.useState(!1),j=We(t,P=>l(P)),A=_o(o);return u.jsx(NS,{scope:n,type:r,dir:A,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:m,scrollbarXEnabled:T,onScrollbarXEnabledChange:C,scrollbarY:y,onScrollbarYChange:x,scrollbarYEnabled:E,onScrollbarYEnabledChange:N,onCornerWidthChange:b,onCornerHeightChange:k,children:u.jsx(je.div,{dir:A,...i,ref:j,style:{position:"relative","--radix-scroll-area-corner-width":g+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});hh.displayName=ja;var ph="ScrollAreaViewport",mh=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=tn(ph,n),a=v.useRef(null),l=We(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(je.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})})]})});mh.displayName=ph;var wn="ScrollAreaScrollbar",_a=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=tn(wn,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(AS,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(jS,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(gh,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Ra,{...r,ref:t}):null});_a.displayName=wn;var AS=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=tn(wn,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(Jt,{present:n||s,children:u.jsx(gh,{"data-state":s?"visible":"hidden",...r,ref:t})})}),jS=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=tn(wn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=$s(()=>l("SCROLL_END"),100),[a,l]=IS("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 h=()=>{const p=c[d];f!==p&&(l("SCROLL"),i()),f=p};return c.addEventListener("scroll",h),()=>c.removeEventListener("scroll",h)}},[o.viewport,s,l,i]),u.jsx(Jt,{present:n||a!=="hidden",children:u.jsx(Ra,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:fe(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:fe(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),gh=v.forwardRef((e,t)=>{const n=tn(wn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=v.useState(!1),a=e.orientation==="horizontal",l=$s(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return wr(n.viewport,l),wr(n.content,l),u.jsx(Jt,{present:r||s,children:u.jsx(Ra,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Ra=v.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=tn(wn,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=wh(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:c>0&&c<1,onThumbChange:h=>s.current=h,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:h=>i.current=h};function f(h,p){return DS(h,i.current,a,p)}return n==="horizontal"?u.jsx(_S,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=Sh(h,a,o.dir);s.current.style.transform=`translate3d(${p}px, 0, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollLeft=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollLeft=f(h,o.dir))}}):n==="vertical"?u.jsx(RS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=Sh(h,a);s.current.style.transform=`translate3d(0, ${p}px, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollTop=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollTop=f(h))}}):null}),_S=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=tn(wn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=We(t,l,s.onScrollbarXChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(yh,{"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":Ls(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(h),Th(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:Ds(i.paddingLeft),paddingEnd:Ds(i.paddingRight)}})}})}),RS=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=tn(wn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=We(t,l,s.onScrollbarYChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(yh,{"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":Ls(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(h),Th(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:Ds(i.paddingTop),paddingEnd:Ds(i.paddingBottom)}})}})}),[PS,xh]=fh(wn),yh=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,...h}=e,p=tn(wn,n),[m,y]=v.useState(null),x=We(t,j=>y(j)),g=v.useRef(null),b=v.useRef(""),S=p.viewport,k=r.content-r.viewport,T=Nt(d),C=Nt(l),E=$s(f,10);function N(j){if(g.current){const A=j.clientX-g.current.left,P=j.clientY-g.current.top;c({x:A,y:P})}}return v.useEffect(()=>{const j=A=>{const P=A.target;(m==null?void 0:m.contains(P))&&T(A,k)};return document.addEventListener("wheel",j,{passive:!1}),()=>document.removeEventListener("wheel",j,{passive:!1})},[S,m,k,T]),v.useEffect(C,[r,C]),wr(m,E),wr(p.content,E),u.jsx(PS,{scope:n,scrollbar:m,hasThumb:o,onThumbChange:Nt(s),onThumbPointerUp:Nt(i),onThumbPositionChange:C,onThumbPointerDown:Nt(a),children:u.jsx(je.div,{...h,ref:x,style:{position:"absolute",...h.style},onPointerDown:fe(e.onPointerDown,j=>{j.button===0&&(j.target.setPointerCapture(j.pointerId),g.current=m.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),N(j))}),onPointerMove:fe(e.onPointerMove,N),onPointerUp:fe(e.onPointerUp,j=>{const A=j.target;A.hasPointerCapture(j.pointerId)&&A.releasePointerCapture(j.pointerId),document.body.style.webkitUserSelect=b.current,p.viewport&&(p.viewport.style.scrollBehavior=""),g.current=null})})})}),Ms="ScrollAreaThumb",vh=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=xh(Ms,e.__scopeScrollArea);return u.jsx(Jt,{present:n||o.hasThumb,children:u.jsx(OS,{ref:t,...r})})}),OS=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=tn(Ms,n),i=xh(Ms,n),{onThumbPositionChange:a}=i,l=We(t,f=>i.onThumbChange(f)),c=v.useRef(void 0),d=$s(()=>{c.current&&(c.current(),c.current=void 0)},100);return v.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(d(),!c.current){const p=LS(f,a);c.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,d,a]),u.jsx(je.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:l,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:fe(e.onPointerDownCapture,f=>{const p=f.target.getBoundingClientRect(),m=f.clientX-p.left,y=f.clientY-p.top;i.onThumbPointerDown({x:m,y})}),onPointerUp:fe(e.onPointerUp,i.onThumbPointerUp)})});vh.displayName=Ms;var Pa="ScrollAreaCorner",bh=v.forwardRef((e,t)=>{const n=tn(Pa,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(MS,{...e,ref:t}):null});bh.displayName=Pa;var MS=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=tn(Pa,n),[s,i]=v.useState(0),[a,l]=v.useState(0),c=!!(s&&a);return wr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),wr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(je.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 Ds(e){return e?parseInt(e,10):0}function wh(e,t){const n=e/t;return isNaN(n)?0:n}function Ls(e){const t=wh(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function DS(e,t,n,r="ltr"){const o=Ls(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 Ch([l,c],f)(e)}function Sh(e,t,n="ltr"){const r=Ls(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=Aa(e,l);return Ch([0,i],[0,a])(c)}function Ch(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 Th(e,t){return e>0&&e<t}var LS=(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 $s(e,t){const n=Nt(e),r=v.useRef(0);return v.useEffect(()=>()=>window.clearTimeout(r.current),[]),v.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function wr(e,t){const n=Nt(t);It(()=>{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 kh=hh,$S=mh,FS=bh;const Eh=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(kh,{ref:r,className:Z("relative overflow-hidden",e),...n,children:[u.jsx($S,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(Ih,{}),u.jsx(FS,{})]}));Eh.displayName=kh.displayName;const Ih=v.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(_a,{ref:r,orientation:t,className:Z("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(vh,{className:"relative flex-1 rounded-full bg-border"})}));Ih.displayName=_a.displayName;const Nh=25;function Oa({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:h,setCurrentThreadId:p,isLoading:m,actions:y}=No(),{loadThread:x}=Ao(),{createThread:g,deleteThread:b,renameThread:S}=y,[k,T]=w.useState(Array.isArray(f)?f:[]),C=w.useRef(k.length>0),E=w.useRef(null),N=w.useRef(0),[j,A]=w.useState(null),[P,$]=w.useState(""),[B,_]=w.useState(!1);w.useEffect(()=>{const Y=Array.isArray(f)?f:[];if(Y.length>0){C.current=!0,T(Y);return}m||(C.current=!1,T(Y))},[f,m]),w.useEffect(()=>{if(!E.current)return;const Y=E.current.querySelector("[data-radix-scroll-area-viewport]");if(!Y)return;let ne=null,H=null;return ne=requestAnimationFrame(()=>{H=requestAnimationFrame(()=>{Y.scrollTop=N.current})}),()=>{ne!==null&&cancelAnimationFrame(ne),H!==null&&cancelAnimationFrame(H)}},[k]);const z=async Y=>{try{p(Y),await x(Y),a==null||a(Y),l==null||l(Y)}catch(ne){console.error("Failed to select thread:",ne)}},R=async()=>{try{_(!0);const Y=await g();Y&&(c==null||c(Y),a==null||a(Y))}catch(Y){console.error("Failed to create thread:",Y)}finally{_(!1)}},K=async(Y,ne)=>{if(ne.stopPropagation(),!!confirm("Delete this thread?")){if(E.current){const H=E.current.querySelector("[data-radix-scroll-area-viewport]");H&&(N.current=H.scrollTop)}try{await b(Y),d==null||d(Y)}catch(H){console.error("Failed to delete thread:",H)}}},O=(Y,ne)=>{ne.stopPropagation(),A(Y.threadId),$(Y.title||`Thread ${Y.threadId.slice(0,8)}`)},L=async Y=>{if(P.trim())try{await S(Y,P.trim()),A(null),$("")}catch(ne){console.error("Failed to update title:",ne)}},q=()=>{A(null),$("")},G=(Y,ne)=>{Y.key==="Enter"?L(ne):Y.key==="Escape"&&q()},ye=Y=>{if(!Y)return"";try{const ne=new Date(Y),D=new Date().getTime()-ne.getTime(),U=Math.floor(D/(1e3*60*60*24));return U===0?ne.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):U===1?"Yesterday":U<7?`${U} days ago`:ne.toLocaleDateString()}catch{return""}},Se=Y=>Y.title||`Thread ${Y.threadId.slice(0,8)}`,Te=Y=>{const ne=Se(Y);return ne.length<=Nh?ne:`${ne.slice(0,Nh)}...`};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(tt,{onClick:R,disabled:B||m,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:B?"Creating...":"New Chat",children:u.jsx(ie.MessageSquarePlus,{size:20})})}),u.jsx(Eh,{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(ie.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(ie.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((Y,ne)=>new Date(ne.updatedAt||ne.createdAt||"").getTime()-new Date(Y.updatedAt||Y.createdAt||"").getTime()).map(Y=>u.jsxs("div",{onClick:()=>z(Y.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??h)===Y.threadId?`${s.activeThread||"bg-slate-600 border-slate-500"} `:`${s.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${s.threadItem||""} text-gray-900 dark:text-slate-100`,children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("div",{className:"flex-1 min-w-0",children:j===Y.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:ne=>ne.stopPropagation(),children:[u.jsx(Os,{value:P,onChange:ne=>$(ne.target.value),onKeyDown:ne=>G(ne,Y.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(tt,{variant:"ghost",size:"sm",onClick:()=>L(Y.threadId),className:"h-6 w-6 p-0",children:u.jsx(ie.Check,{size:12})}),u.jsx(tt,{variant:"ghost",size:"sm",onClick:q,className:"h-6 w-6 p-0",children:u.jsx(ie.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:Te(Y)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(ie.Calendar,{size:10}),u.jsx("span",{children:ye(Y.updatedAt||Y.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&j!==Y.threadId&&u.jsx(tt,{variant:"ghost",size:"sm",onClick:ne=>O(Y,ne),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(ie.Edit3,{size:12})}),n&&u.jsx(tt,{variant:"ghost",size:"sm",onClick:ne=>K(Y.threadId,ne),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(ie.Trash2,{size:12})})]})]}),i===Y.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},Y.threadId))})})]})}function Sr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function zS(e){if(typeof e!="string")return;const t=e.trim();if(t)return Sn(t)}function Ah(){const e=[Sr("__API_BASE_URL__"),Sr("__CHAT_API_BASE_URL__"),Sr("__CHAT_API_URL__")];for(const t of e){const n=zS(t);if(n)return n}}function jh(){const e=[Sr("__API_AUTH_TOKEN__"),Sr("__CHAT_API_KEY__"),Sr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function _h(...e){for(const t of e)if(typeof t=="string"&&t.trim())return Sn(t);return Sn()}function Rh(){const e={},t=Ah(),n=jh();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Ph(){const e=Rh(),t=jn.getAuthToken(),n=Ah();return{apiBaseUrl:_h(e.baseUrl,jn.baseUrl,n),apiKey:t||e.apiKey||jh()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const Oh="chat-settings";function BS(){try{const e=localStorage.getItem(Oh);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function HS(e){try{const t={...e,apiBaseUrl:Sn(e.apiBaseUrl)};localStorage.setItem(Oh,JSON.stringify(t)),t.apiKey&&jn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function US(){const e=Ph(),t=BS(),n=jn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:_h(jn.baseUrl,r,e.apiBaseUrl)}}function WS(e){jn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),HS(e)}var VS="Label",Mh=v.forwardRef((e,t)=>u.jsx(je.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())}}));Mh.displayName=VS;var Dh=Mh;const KS=uo.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),nn=v.forwardRef(({className:e,...t},n)=>u.jsx(Dh,{ref:n,className:Z(KS(),e),...t}));nn.displayName=Dh.displayName;function Lh(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 Fs="Switch",[qS,gT]=Cn(Fs),[GS,YS]=qS(Fs),$h=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,[h,p]=v.useState(null),m=We(t,S=>p(S)),y=v.useRef(!1),x=h?d||!!h.closest("form"):!0,[g,b]=cr({prop:o,defaultProp:s??!1,onChange:c,caller:Fs});return u.jsxs(GS,{scope:n,checked:g,disabled:a,children:[u.jsx(je.button,{type:"button",role:"switch","aria-checked":g,"aria-required":i,"data-state":Hh(g),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:m,onClick:fe(e.onClick,S=>{b(k=>!k),x&&(y.current=S.isPropagationStopped(),y.current||S.stopPropagation())})}),x&&u.jsx(Bh,{control:h,bubbles:!y.current,name:r,value:l,checked:g,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});$h.displayName=Fs;var Fh="SwitchThumb",zh=v.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=YS(Fh,n);return u.jsx(je.span,{"data-state":Hh(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});zh.displayName=Fh;var XS="SwitchBubbleInput",Bh=v.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=v.useRef(null),a=We(i,s),l=Lh(n),c=Vc(t);return v.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&p){const m=new Event("click",{bubbles:r});p.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}})});Bh.displayName=XS;function Hh(e){return e?"checked":"unchecked"}var Uh=$h,JS=zh;const zn=v.forwardRef(({className:e,...t},n)=>u.jsx(Uh,{className:Z("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(JS,{className:Z("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")})}));zn.displayName=Uh.displayName;var Wh=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"}),ZS="VisuallyHidden",QS=v.forwardRef((e,t)=>u.jsx(je.span,{...e,ref:t,style:{...Wh,...e.style}}));QS.displayName=ZS;var eC=[" ","Enter","ArrowUp","ArrowDown"],tC=[" ","Enter"],rr="Select",[zs,Bs,nC]=hi(rr),[Cr,xT]=Cn(rr,[nC,Wo]),Hs=Wo(),[rC,Bn]=Cr(rr),[oC,sC]=Cr(rr),Vh=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:h,required:p,form:m}=e,y=Hs(t),[x,g]=v.useState(null),[b,S]=v.useState(null),[k,T]=v.useState(!1),C=_o(c),[E,N]=cr({prop:r,defaultProp:o??!1,onChange:s,caller:rr}),[j,A]=cr({prop:i,defaultProp:a,onChange:l,caller:rr}),P=v.useRef(null),$=x?m||!!x.closest("form"):!0,[B,_]=v.useState(new Set),z=Array.from(B).map(R=>R.props.value).join(";");return u.jsx(tu,{...y,children:u.jsxs(rC,{required:p,scope:t,trigger:x,onTriggerChange:g,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:k,onValueNodeHasChildrenChange:T,contentId:Tn(),value:j,onValueChange:A,open:E,onOpenChange:N,dir:C,triggerPointerDownPosRef:P,disabled:h,children:[u.jsx(zs.Provider,{scope:t,children:u.jsx(oC,{scope:e.__scopeSelect,onNativeOptionAdd:v.useCallback(R=>{_(K=>new Set(K).add(R))},[]),onNativeOptionRemove:v.useCallback(R=>{_(K=>{const O=new Set(K);return O.delete(R),O})},[]),children:n})}),$?u.jsxs(mp,{"aria-hidden":!0,required:p,tabIndex:-1,name:d,autoComplete:f,value:j,onChange:R=>A(R.target.value),disabled:h,form:m,children:[j===void 0?u.jsx("option",{value:""}):null,Array.from(B)]},z):null]})})};Vh.displayName=rr;var Kh="SelectTrigger",qh=v.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Hs(n),i=Bn(Kh,n),a=i.disabled||r,l=We(t,i.onTriggerChange),c=Bs(n),d=v.useRef("touch"),[f,h,p]=xp(y=>{const x=c().filter(S=>!S.disabled),g=x.find(S=>S.value===i.value),b=yp(x,y,g);b!==void 0&&i.onValueChange(b.value)}),m=y=>{a||(i.onOpenChange(!0),p()),y&&(i.triggerPointerDownPosRef.current={x:Math.round(y.pageX),y:Math.round(y.pageY)})};return u.jsx(nu,{asChild:!0,...s,children:u.jsx(je.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":gp(i.value)?"":void 0,...o,ref:l,onClick:fe(o.onClick,y=>{y.currentTarget.focus(),d.current!=="mouse"&&m(y)}),onPointerDown:fe(o.onPointerDown,y=>{d.current=y.pointerType;const x=y.target;x.hasPointerCapture(y.pointerId)&&x.releasePointerCapture(y.pointerId),y.button===0&&y.ctrlKey===!1&&y.pointerType==="mouse"&&(m(y),y.preventDefault())}),onKeyDown:fe(o.onKeyDown,y=>{const x=f.current!=="";!(y.ctrlKey||y.altKey||y.metaKey)&&y.key.length===1&&h(y.key),!(x&&y.key===" ")&&eC.includes(y.key)&&(m(),y.preventDefault())})})})});qh.displayName=Kh;var Gh="SelectValue",Yh=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Bn(Gh,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=We(t,l.onValueNodeChange);return It(()=>{c(d)},[c,d]),u.jsx(je.span,{...a,ref:f,style:{pointerEvents:"none"},children:gp(l.value)?u.jsx(u.Fragment,{children:i}):s})});Yh.displayName=Gh;var iC="SelectIcon",Xh=v.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(je.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Xh.displayName=iC;var aC="SelectPortal",Jh=e=>u.jsx(Vo,{asChild:!0,...e});Jh.displayName=aC;var or="SelectContent",Zh=v.forwardRef((e,t)=>{const n=Bn(or,e.__scopeSelect),[r,o]=v.useState();if(It(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?fo.createPortal(u.jsx(Qh,{scope:e.__scopeSelect,children:u.jsx(zs.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(ep,{...e,ref:t})});Zh.displayName=or;var dn=10,[Qh,Hn]=Cr(or),lC="SelectContentImpl",cC=Un.createSlot("SelectContent.RemoveScroll"),ep=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:h,collisionPadding:p,sticky:m,hideWhenDetached:y,avoidCollisions:x,...g}=e,b=Bn(or,n),[S,k]=v.useState(null),[T,C]=v.useState(null),E=We(t,H=>k(H)),[N,j]=v.useState(null),[A,P]=v.useState(null),$=Bs(n),[B,_]=v.useState(!1),z=v.useRef(!1);v.useEffect(()=>{if(S)return Mi(S)},[S]),gi();const R=v.useCallback(H=>{const[D,...U]=$().map(le=>le.ref.current),[Q]=U.slice(-1),te=document.activeElement;for(const le of H)if(le===te||(le==null||le.scrollIntoView({block:"nearest"}),le===D&&T&&(T.scrollTop=0),le===Q&&T&&(T.scrollTop=T.scrollHeight),le==null||le.focus(),document.activeElement!==te))return},[$,T]),K=v.useCallback(()=>R([N,S]),[R,N,S]);v.useEffect(()=>{B&&K()},[B,K]);const{onOpenChange:O,triggerPointerDownPosRef:L}=b;v.useEffect(()=>{if(S){let H={x:0,y:0};const D=Q=>{var te,le;H={x:Math.abs(Math.round(Q.pageX)-(((te=L.current)==null?void 0:te.x)??0)),y:Math.abs(Math.round(Q.pageY)-(((le=L.current)==null?void 0:le.y)??0))}},U=Q=>{H.x<=10&&H.y<=10?Q.preventDefault():S.contains(Q.target)||O(!1),document.removeEventListener("pointermove",D),L.current=null};return L.current!==null&&(document.addEventListener("pointermove",D),document.addEventListener("pointerup",U,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",D),document.removeEventListener("pointerup",U,{capture:!0})}}},[S,O,L]),v.useEffect(()=>{const H=()=>O(!1);return window.addEventListener("blur",H),window.addEventListener("resize",H),()=>{window.removeEventListener("blur",H),window.removeEventListener("resize",H)}},[O]);const[q,G]=xp(H=>{const D=$().filter(te=>!te.disabled),U=D.find(te=>te.ref.current===document.activeElement),Q=yp(D,H,U);Q&&setTimeout(()=>Q.ref.current.focus())}),ye=v.useCallback((H,D,U)=>{const Q=!z.current&&!U;(b.value!==void 0&&b.value===D||Q)&&(j(H),Q&&(z.current=!0))},[b.value]),Se=v.useCallback(()=>S==null?void 0:S.focus(),[S]),Te=v.useCallback((H,D,U)=>{const Q=!z.current&&!U;(b.value!==void 0&&b.value===D||Q)&&P(H)},[b.value]),Y=r==="popper"?Ma:tp,ne=Y===Ma?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:m,hideWhenDetached:y,avoidCollisions:x}:{};return u.jsx(Qh,{scope:n,content:S,viewport:T,onViewportChange:C,itemRefCallback:ye,selectedItem:N,onItemLeave:Se,itemTextRefCallback:Te,focusSelectedItem:K,selectedItemText:A,position:r,isPositioned:B,searchRef:q,children:u.jsx(es,{as:cC,allowPinchZoom:!0,children:u.jsx(Po,{asChild:!0,trapped:b.open,onMountAutoFocus:H=>{H.preventDefault()},onUnmountAutoFocus:fe(o,H=>{var D;(D=b.trigger)==null||D.focus({preventScroll:!0}),H.preventDefault()}),children:u.jsx(Ro,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:H=>H.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:u.jsx(Y,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:H=>H.preventDefault(),...g,...ne,onPlaced:()=>_(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...g.style},onKeyDown:fe(g.onKeyDown,H=>{const D=H.ctrlKey||H.altKey||H.metaKey;if(H.key==="Tab"&&H.preventDefault(),!D&&H.key.length===1&&G(H.key),["ArrowUp","ArrowDown","Home","End"].includes(H.key)){let Q=$().filter(te=>!te.disabled).map(te=>te.ref.current);if(["ArrowUp","End"].includes(H.key)&&(Q=Q.slice().reverse()),["ArrowUp","ArrowDown"].includes(H.key)){const te=H.target,le=Q.indexOf(te);Q=Q.slice(le+1)}setTimeout(()=>R(Q)),H.preventDefault()}})})})})})})});ep.displayName=lC;var uC="SelectItemAlignedPosition",tp=v.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Bn(or,n),i=Hn(or,n),[a,l]=v.useState(null),[c,d]=v.useState(null),f=We(t,E=>d(E)),h=Bs(n),p=v.useRef(!1),m=v.useRef(!0),{viewport:y,selectedItem:x,selectedItemText:g,focusSelectedItem:b}=i,S=v.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&y&&x&&g){const E=s.trigger.getBoundingClientRect(),N=c.getBoundingClientRect(),j=s.valueNode.getBoundingClientRect(),A=g.getBoundingClientRect();if(s.dir!=="rtl"){const te=A.left-N.left,le=j.left-te,_e=E.left-le,He=E.width+_e,Xe=Math.max(He,N.width),Ke=window.innerWidth-dn,J=Aa(le,[dn,Math.max(dn,Ke-Xe)]);a.style.minWidth=He+"px",a.style.left=J+"px"}else{const te=N.right-A.right,le=window.innerWidth-j.right-te,_e=window.innerWidth-E.right-le,He=E.width+_e,Xe=Math.max(He,N.width),Ke=window.innerWidth-dn,J=Aa(le,[dn,Math.max(dn,Ke-Xe)]);a.style.minWidth=He+"px",a.style.right=J+"px"}const P=h(),$=window.innerHeight-dn*2,B=y.scrollHeight,_=window.getComputedStyle(c),z=parseInt(_.borderTopWidth,10),R=parseInt(_.paddingTop,10),K=parseInt(_.borderBottomWidth,10),O=parseInt(_.paddingBottom,10),L=z+R+B+O+K,q=Math.min(x.offsetHeight*5,L),G=window.getComputedStyle(y),ye=parseInt(G.paddingTop,10),Se=parseInt(G.paddingBottom,10),Te=E.top+E.height/2-dn,Y=$-Te,ne=x.offsetHeight/2,H=x.offsetTop+ne,D=z+R+H,U=L-D;if(D<=Te){const te=P.length>0&&x===P[P.length-1].ref.current;a.style.bottom="0px";const le=c.clientHeight-y.offsetTop-y.offsetHeight,_e=Math.max(Y,ne+(te?Se:0)+le+K),He=D+_e;a.style.height=He+"px"}else{const te=P.length>0&&x===P[0].ref.current;a.style.top="0px";const _e=Math.max(Te,z+y.offsetTop+(te?ye:0)+ne)+U;a.style.height=_e+"px",y.scrollTop=D-Te+y.offsetTop}a.style.margin=`${dn}px 0`,a.style.minHeight=q+"px",a.style.maxHeight=$+"px",r==null||r(),requestAnimationFrame(()=>p.current=!0)}},[h,s.trigger,s.valueNode,a,c,y,x,g,s.dir,r]);It(()=>S(),[S]);const[k,T]=v.useState();It(()=>{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(fC,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:p,onScrollButtonChange:C,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:k},children:u.jsx(je.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});tp.displayName=uC;var dC="SelectPopperPosition",Ma=v.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=dn,...s}=e,i=Hs(n);return u.jsx(ru,{...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)"}})});Ma.displayName=dC;var[fC,Da]=Cr(or,{}),La="SelectViewport",np=v.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Hn(La,n),i=Da(La,n),a=We(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(zs.Slot,{scope:n,children:u.jsx(je.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:fe(o.onScroll,c=>{const d=c.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:h}=i;if(h!=null&&h.current&&f){const p=Math.abs(l.current-d.scrollTop);if(p>0){const m=window.innerHeight-dn*2,y=parseFloat(f.style.minHeight),x=parseFloat(f.style.height),g=Math.max(y,x);if(g<m){const b=g+p,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})})})]})});np.displayName=La;var rp="SelectGroup",[hC,pC]=Cr(rp),mC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Tn();return u.jsx(hC,{scope:n,id:o,children:u.jsx(je.div,{role:"group","aria-labelledby":o,...r,ref:t})})});mC.displayName=rp;var op="SelectLabel",sp=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=pC(op,n);return u.jsx(je.div,{id:o.id,...r,ref:t})});sp.displayName=op;var Us="SelectItem",[gC,ip]=Cr(Us),ap=v.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Bn(Us,n),l=Hn(Us,n),c=a.value===r,[d,f]=v.useState(s??""),[h,p]=v.useState(!1),m=We(t,b=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,b,r,o)}),y=Tn(),x=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(gC,{scope:n,value:r,disabled:o,textId:y,isSelected:c,onItemTextChange:v.useCallback(b=>{f(S=>S||((b==null?void 0:b.textContent)??"").trim())},[]),children:u.jsx(zs.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(je.div,{role:"option","aria-labelledby":y,"data-highlighted":h?"":void 0,"aria-selected":c&&h,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:m,onFocus:fe(i.onFocus,()=>p(!0)),onBlur:fe(i.onBlur,()=>p(!1)),onClick:fe(i.onClick,()=>{x.current!=="mouse"&&g()}),onPointerUp:fe(i.onPointerUp,()=>{x.current==="mouse"&&g()}),onPointerDown:fe(i.onPointerDown,b=>{x.current=b.pointerType}),onPointerMove:fe(i.onPointerMove,b=>{var S;x.current=b.pointerType,o?(S=l.onItemLeave)==null||S.call(l):x.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:fe(i.onPointerLeave,b=>{var S;b.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:fe(i.onKeyDown,b=>{var k;((k=l.searchRef)==null?void 0:k.current)!==""&&b.key===" "||(tC.includes(b.key)&&g(),b.key===" "&&b.preventDefault())})})})})});ap.displayName=Us;var io="SelectItemText",lp=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Bn(io,n),a=Hn(io,n),l=ip(io,n),c=sC(io,n),[d,f]=v.useState(null),h=We(t,g=>f(g),l.onItemTextChange,g=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,g,l.value,l.disabled)}),p=d==null?void 0:d.textContent,m=v.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:p},l.value),[l.disabled,l.value,p]),{onNativeOptionAdd:y,onNativeOptionRemove:x}=c;return It(()=>(y(m),()=>x(m)),[y,x,m]),u.jsxs(u.Fragment,{children:[u.jsx(je.span,{id:l.textId,...s,ref:h}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?fo.createPortal(s.children,i.valueNode):null]})});lp.displayName=io;var cp="SelectItemIndicator",up=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return ip(cp,n).isSelected?u.jsx(je.span,{"aria-hidden":!0,...r,ref:t}):null});up.displayName=cp;var $a="SelectScrollUpButton",dp=v.forwardRef((e,t)=>{const n=Hn($a,e.__scopeSelect),r=Da($a,e.__scopeSelect),[o,s]=v.useState(!1),i=We(t,r.onScrollButtonChange);return It(()=>{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(hp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});dp.displayName=$a;var Fa="SelectScrollDownButton",fp=v.forwardRef((e,t)=>{const n=Hn(Fa,e.__scopeSelect),r=Da(Fa,e.__scopeSelect),[o,s]=v.useState(!1),i=We(t,r.onScrollButtonChange);return It(()=>{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(hp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});fp.displayName=Fa;var hp=v.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Hn("SelectScrollButton",n),i=v.useRef(null),a=Bs(n),l=v.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return v.useEffect(()=>()=>l(),[l]),It(()=>{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(je.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:fe(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:fe(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:fe(o.onPointerLeave,()=>{l()})})}),xC="SelectSeparator",pp=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(je.div,{"aria-hidden":!0,...r,ref:t})});pp.displayName=xC;var za="SelectArrow",yC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Hs(n),s=Bn(za,n),i=Hn(za,n);return s.open&&i.position==="popper"?u.jsx(ou,{...o,...r,ref:t}):null});yC.displayName=za;var vC="SelectBubbleInput",mp=v.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=v.useRef(null),s=We(r,o),i=Lh(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(je.select,{...n,style:{...Wh,...n.style},ref:s,defaultValue:t})});mp.displayName=vC;function gp(e){return e===""||e===void 0}function xp(e){const t=Nt(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 yp(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=bC(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function bC(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var wC=Vh,vp=qh,SC=Yh,CC=Xh,TC=Jh,bp=Zh,kC=np,wp=sp,Sp=ap,EC=lp,IC=up,Cp=dp,Tp=fp,kp=pp;const Ep=wC,Ip=SC,Ba=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(vp,{ref:r,className:Z("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(CC,{asChild:!0,children:u.jsx(ie.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Ba.displayName=vp.displayName;const Np=v.forwardRef(({className:e,...t},n)=>u.jsx(Cp,{ref:n,className:Z("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ie.ChevronUp,{className:"h-4 w-4"})}));Np.displayName=Cp.displayName;const Ap=v.forwardRef(({className:e,...t},n)=>u.jsx(Tp,{ref:n,className:Z("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ie.ChevronDown,{className:"h-4 w-4"})}));Ap.displayName=Tp.displayName;const Ha=v.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(TC,{children:u.jsxs(bp,{ref:o,className:Z("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(Np,{}),u.jsx(kC,{className:Z("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(Ap,{})]})}));Ha.displayName=bp.displayName;const NC=v.forwardRef(({className:e,...t},n)=>u.jsx(wp,{ref:n,className:Z("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));NC.displayName=wp.displayName;const sr=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Sp,{ref:r,className:Z("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(IC,{children:u.jsx(ie.Check,{className:"h-4 w-4"})})}),u.jsx(EC,{children:t})]}));sr.displayName=Sp.displayName;const AC=v.forwardRef(({className:e,...t},n)=>u.jsx(kp,{ref:n,className:Z("-mx-1 my-1 h-px bg-muted",e),...t}));AC.displayName=kp.displayName;var jC="Separator",jp="horizontal",_C=["horizontal","vertical"],_p=v.forwardRef((e,t)=>{const{decorative:n,orientation:r=jp,...o}=e,s=RC(r)?r:jp,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(je.div,{"data-orientation":s,...a,...o,ref:t})});_p.displayName=jC;function RC(e){return _C.includes(e)}var Rp=_p;const Pp=v.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(Rp,{ref:o,decorative:n,orientation:t,className:Z("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Pp.displayName=Rp.displayName;const PC=Bf,OC=Y0,MC=Hf,Op=v.forwardRef(({className:e,...t},n)=>u.jsx(ks,{className:Z("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}));Op.displayName=ks.displayName;const DC=uo.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"}}),Mp=v.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(MC,{children:[u.jsx(Op,{}),u.jsxs(Es,{ref:o,className:Z(DC({side:e}),t),...r,children:[n,u.jsxs(Uf,{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(ie.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Mp.displayName=Es.displayName;const Dp=({className:e,...t})=>u.jsx("div",{className:Z("flex flex-col space-y-2 text-center sm:text-left",e),...t});Dp.displayName="SheetHeader";const Lp=v.forwardRef(({className:e,...t},n)=>u.jsx(tr,{ref:n,className:Z("text-lg font-semibold text-foreground",e),...t}));Lp.displayName=tr.displayName;const $p=v.forwardRef(({className:e,...t},n)=>u.jsx(Is,{ref:n,className:Z("text-sm text-muted-foreground",e),...t}));$p.displayName=Is.displayName;const LC={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 $C({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}=ba();w.useEffect(()=>{const x=JSON.stringify(a)!==JSON.stringify(e);d(x)},[a,e]),w.useEffect(()=>{l(e)},[e]);const h=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},p=()=>{l(LC),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},m=()=>{l(e),d(!1),o(!1)},y=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(PC,{open:r,onOpenChange:o,children:[u.jsx(OC,{asChild:!0,children:u.jsxs(tt,{variant:"outline",size:"sm",className:n,children:[u.jsx(ie.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(yf,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(Mp,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(Dp,{children:[u.jsx(Lp,{children:"Chat Settings"}),u.jsx($p,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(Zr,{children:[u.jsx(Qr,{className:"pb-3",children:u.jsxs(eo,{className:"text-lg flex items-center gap-2",children:[u.jsx(ie.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(to,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(nn,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Os,{id:"api-url",value:a.api.baseUrl,onChange:x=>l(g=>({...g,api:{...g.api,baseUrl:x.target.value}})),placeholder:"http://localhost:8000/api"}),u.jsx(tt,{variant:"outline",onClick:y,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(nn,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(zn,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:x=>l(g=>({...g,api:{...g.api,enableAuth:x}}))})]}),a.api.enableAuth&&u.jsxs("div",{className:"space-y-2",children:[u.jsx(nn,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Os,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:x=>l(g=>({...g,api:{...g.api,authToken:x.target.value}})),placeholder:"Enter your Bearer token"}),u.jsx(tt,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?u.jsx(ie.EyeOff,{className:"h-4 w-4"}):u.jsx(ie.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(Zr,{children:[u.jsx(Qr,{className:"pb-3",children:u.jsxs(eo,{className:"text-lg flex items-center gap-2",children:[u.jsx(ie.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(to,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(nn,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(Ep,{value:a.ui.layout,onValueChange:x=>l(g=>({...g,ui:{...g.ui,layout:x}})),children:[u.jsx(Ba,{children:u.jsx(Ip,{})}),u.jsxs(Ha,{children:[u.jsx(sr,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(sr,{value:"fullscreen",children:"Fullscreen"}),u.jsx(sr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(nn,{htmlFor:"theme",children:"Theme"}),u.jsxs(Ep,{value:a.ui.theme,onValueChange:x=>l(g=>({...g,ui:{...g.ui,theme:x}})),children:[u.jsx(Ba,{children:u.jsx(Ip,{})}),u.jsxs(Ha,{children:[u.jsx(sr,{value:"light",children:"Light"}),u.jsx(sr,{value:"dark",children:"Dark"}),u.jsx(sr,{value:"system",children:"System"})]})]})]}),u.jsx(Pp,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(nn,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(zn,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:x=>l(g=>({...g,ui:{...g.ui,showTimestamps:x}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(nn,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(zn,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:x=>l(g=>({...g,ui:{...g.ui,showAgentNames:x}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(nn,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(zn,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:x=>l(g=>({...g,ui:{...g.ui,compactMessages:x}}))})]})]})]})]}),u.jsxs(Zr,{children:[u.jsx(Qr,{className:"pb-3",children:u.jsxs(eo,{className:"text-lg flex items-center gap-2",children:[u.jsx(ie.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(to,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(nn,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(zn,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:x=>l(g=>({...g,behavior:{...g.behavior,autoSave:x}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(nn,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx(zn,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:x=>l(g=>({...g,behavior:{...g.behavior,enableStreaming:x}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(nn,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx(zn,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:x=>l(g=>({...g,behavior:{...g.behavior,showTypingIndicator:x}}))})]})]})]})]}),u.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[u.jsxs(tt,{variant:"outline",onClick:p,children:[u.jsx(ie.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(tt,{variant:"outline",onClick:m,children:"Cancel"}),u.jsxs(tt,{onClick:h,disabled:!c,children:[u.jsx(ie.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function FC({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(jo,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx(Ps,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(jo,{...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(Oa,{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(Ps,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(jo,{...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(Oa,{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(Ps,{onError:s.onError,enableFileUpload:!0})})]})})}Ie.ChatApi=Bl,Ie.ChatInput=cc,Ie.ChatInterface=Ps,Ie.ChatProviders=jo,Ie.ChatSettings=$C,Ie.MarkdownContent=so,Ie.MessageComponent=Ia,Ie.MessageList=Na,Ie.ThreadManager=Oa,Ie.applySettings=WS,Ie.chatApiClient=jn,Ie.default=FC,Ie.del=zl,Ie.get=Yt,Ie.getChatToken=Ll,Ie.getCurrentSettings=US,Ie.getDefaultApiConfig=Rh,Ie.getDefaultChatSettings=Ph,Ie.onChatTokenChanged=$l,Ie.post=si,Ie.put=Fl,Ie.setChatToken=To,Ie.useApi=ii,Ie.useChatStream=Gl,Ie.useMessagesReducer=Yl,Ie.useStream=ac,Ie.useThreadState=Ao,Ie.useThreads=No,Object.defineProperties(Ie,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
137
+ dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[Te[pe]?u.jsx(ie.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[ot,Te[pe]?" (processing)":""]})]},pe)}if(F.type==="interrupt"){const me=F,ot=Rs((me==null?void 0:me.id)??(me==null?void 0:me.interrupt_id)),kt=!!(Ke&&ot&&ot===Ke),rn=kt?J??(me==null?void 0:me.value):me==null?void 0:me.value,Ye=ot?{...me,id:ot,interrupt_id:ot}:me;return u.jsx(SS,{interruptPart:Ye,onApprove:Qe,onReject:Tt,disabled:b,isActive:kt,payload:rn},pe)}return null},[Y,Te,Qe,Tt,L,c,d,_,O,Ke,J,g,b,He]),yt=w.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(ie.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),dt=w.useCallback(()=>{const F=Q.trim().length>0||le.length>0||_e.length>0||He.length>0;if(!q&&_e.length>0&&!r)return yt();if(!q&&!F&&!r)return null;if(q)return u.jsx(kS,{message:t,viewMode:$},t.id);if(!q&&!G){const pe=t,me=u.jsx("div",{className:"space-y-2",children:pe.content.map((ot,kt)=>u.jsx(xt,{part:ot,i:kt},kt))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[me,u.jsx(wS,{className:U})]}):me}},[Q,le.length,_e.length,He.length,r,q,$,yt,U]),at=w.useMemo(()=>G?"Assistant":bS(t),[G,t]),Le=w.useMemo(()=>G?[]:Array.isArray(T)?T:[],[T,G]),At=w.useMemo(()=>{var F;return Le.length?N&&Le.some(pe=>pe.id===N)?N:((F=Le[0])==null?void 0:F.id)??null:null},[N,Le]),re=w.useMemo(()=>!Le.length||!C?null:Le.some(F=>F.id===C)?C:null,[C,Le])??At,be=L==="user"&&Le.length>0&&typeof E=="function",ge=w.useCallback(F=>{if(!E)return;const pe=(F==null?void 0:F.id)??null,me=(F==null?void 0:F.parentId)??j??null;E(pe,me)},[j,E]),oe=w.useMemo(()=>re?Le.findIndex(F=>F.id===re):-1,[re,Le]),Ne=w.useMemo(()=>oe<0?null:Le[oe]??null,[oe,Le]),lt=w.useCallback(F=>{const pe=[];if(F.step!==null&&pe.push(`Step ${F.step}`),F.source&&pe.push(F.source),!F.createdAt)return pe.length?pe.join(" • "):F.id.slice(0,8);let me="";try{const ot=new Date(F.createdAt);Number.isNaN(ot.getTime())||(me=new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(ot))}catch{me=""}return`${me}`},[]);return q&&!f?null:u.jsxs(u.Fragment,{children:[u.jsx("div",{className:Z(Re(),h.container),children:u.jsxs("div",{className:Z(Be(),h.content),children:[(i||a||q)&&u.jsxs("div",{className:Z("flex items-center justify-between mb-2 pb-2 border-b border-current/10",O&&"mb-1 pb-1",U,h.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[Ge(),a&&at&&u.jsx("span",{className:Z("font-medium",O?"text-xs":"text-sm"),children:at}),q&&u.jsxs(yf,{variant:"outline",className:Z("text-xs flex items-center gap-1 cursor-pointer select-none",U,"border border-current/40",O&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":$==="expanded",onClick:()=>B(F=>F==="expanded"?"preview":"expanded"),onKeyDown:F=>{(F.key==="Enter"||F.key===" ")&&(F.preventDefault(),B(pe=>pe==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:te.name??"Tool Output"}),te.toolCallId&&u.jsx("span",{className:"opacity-70",children:te.toolCallId.slice(0,8)}),$==="expanded"?u.jsx(ie.ChevronUp,{className:"h-3 w-3"}):u.jsx(ie.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[be&&Ne&&oe>=0&&u.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[u.jsx("button",{type:"button",className:Z("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",oe>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(oe<=0)return;const F=Le[oe-1];F&&ge(F)},"aria-label":"Previous checkpoint",disabled:oe<=0,children:u.jsx(ie.ChevronLeft,{className:"h-3 w-3"})}),u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs("span",{className:"whitespace-nowrap",children:[oe+1," / ",Le.length]}),u.jsx("span",{className:"text-muted-foreground",children:lt(Ne)})]}),u.jsx("button",{type:"button",className:Z("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",oe<Le.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(oe>=Le.length-1)return;const F=Le[oe+1];F&&ge(F)},"aria-label":"Next checkpoint",disabled:oe>=Le.length-1,children:u.jsx(ie.ChevronRight,{className:"h-3 w-3"})})]}),i&&t.createdAt&&u.jsx("time",{className:Z("text-xs opacity-60",U,O&&"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:Z("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(tt,{variant:"ghost",size:"sm",onClick:()=>De(),className:Z("h-6 w-6 p-0 hover:bg-foreground/10",U,O&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(ie.Copy,{className:Z(A?"text-success":U,O?"h-3 w-3":"h-4 w-4")})})}),L==="user"&&p&&u.jsx(tt,{variant:"ghost",size:"sm",onClick:Fe,className:Z("h-6 w-6 p-0 hover:bg-foreground/10",U,O&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(ie.Edit,{className:Z(U,O?"h-3 w-3":"h-4 w-4")})}),L==="assistant"&&m&&u.jsx(tt,{variant:"ghost",size:"sm",onClick:qe,className:Z("h-6 w-6 p-0 hover:bg-foreground/10",U,O&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(ie.RotateCcw,{className:Z(U,O?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsx("div",{className:"relative",children:dt()}),q&&$==="expanded"&&(te.toolCallId||te.name)&&u.jsxs("div",{className:Z("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",O&&"text-xs"),children:[te.name&&u.jsxs("div",{children:["Function: ",te.name]}),te.toolCallId&&u.jsxs("div",{children:["Call ID: ",te.toolCallId]})]}),!(i||a||q)&&s&&!o&&u.jsxs("div",{className:Z("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx(tt,{variant:"ghost",size:"sm",onClick:()=>De(),className:Z("h-6 w-6 p-0 hover:bg-background/50 text-current",O&&"h-5 w-5"),children:u.jsx(ie.Copy,{className:Z(A?"text-success":"text-current",O?"h-3 w-3":"h-4 w-4")})}),L==="user"&&p&&u.jsx(tt,{variant:"ghost",size:"sm",onClick:Fe,className:Z("h-6 w-6 p-0 hover:bg-background/50 text-current",O&&"h-5 w-5"),children:u.jsx(ie.Edit,{className:Z("text-current",O?"h-3 w-3":"h-4 w-4")})}),L==="assistant"&&m&&u.jsx(tt,{variant:"ghost",size:"sm",onClick:qe,className:Z("h-6 w-6 p-0 hover:bg-background/50 text-current",O&&"h-5 w-5"),children:u.jsx(ie.RotateCcw,{className:Z("text-current",O?"h-3 w-3":"h-4 w-4")})})]})]})}),H&&u.jsx(Q0,{isOpen:ne,onClose:D,fileId:H.id,fileName:H.name,mimeType:H.mimeType})]})},(e,t)=>{var i,a,l,c,d,f,h,p;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&lh(e.message)===lh(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)&&((h=e.customStyles)==null?void 0:h.header)===((p=t.customStyles)==null?void 0:p.header);return o&&s});function ch({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:xS,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:oo(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:oo(e)})}function SS({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=oo(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(Zr,{className:Z("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(Qr,{className:"pb-3",children:[u.jsx(eo,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(vf,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(to,{className:"pt-0 pb-3",children:a}),u.jsx(bf,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(tt,{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(tt,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}function CS(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=ba(),[o,s]=w.useState({}),[i,a]=w.useState(null),[l,c]=w.useState(!1),d=w.useCallback(()=>{c(!1),a(null)},[]),f=w.useCallback(p=>{a(p),c(!0)},[]),h=w.useCallback(async(p,m,y)=>{var x,g;if(!t){p.preventDefault();return}if(o[y]){p.preventDefault();return}try{const b=String(m.url??""),S=b.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){p.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:")){p.preventDefault(),s(T=>({...T,[y]:!0}));const k=r({title:"Fetching file...",description:"",open:!0});try{const T=await L0(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"}),(x=k.update)==null||x.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,[y]:!1}))}}}catch(b){console.error("File click error:",b),s(S=>({...S,[y]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:h,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function TS({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:Z("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(so,{content:e,allowHtml:!1}):u.jsxs("pre",{className:Z("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(tt,{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(ie.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(ie.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function kS({message:e,viewMode:t}){const r=ah(e).name||"tool",o=c=>{if(c==null)return null;const d=typeof c=="string"?wa(c)??c:c;if(d&&typeof d=="object")return u.jsx(ch,{data:d});const f=typeof d=="string"?d:(()=>{try{return oo(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}=F0(c);return f?u.jsx(so,{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(ie.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=Ss(d);return s(f)}const a=ro(i),l=Ss(a);return s(l)}const uh=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,ES=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},Na=w.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:c,onCancelEdit:d,className:f,style:h,emptyMessage:p,followNewMessages:m=!0,isNavigatingCheckpoint:y=!1,onScrollAway:x,onAtBottom:g,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:T,showToolMessages:C=!0,checkpointMetaById:E,checkpointIndexByKey:N,activeCheckpointId:j,onSelectCheckpoint:A,timelineCheckpoints:P,createSyntheticThinkingMessage:$=!1},B)=>{const _=w.useRef(null),z=w.useRef(null),R=w.useRef(!1),[K,O]=w.useState(!0),L=w.useMemo(()=>b?e.some(J=>"type"in J&&J.type==="default_message"?!1:Array.isArray(J==null?void 0:J.content)&&J.content.some(he=>he&&he.type==="interrupt"&&(he.id??he.interrupt_id)===b.id)):!1,[b,e]),q=w.useMemo(()=>{if(!b||L)return null;const J=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let he;const De=b.value;if(De&&typeof De=="object"&&!Array.isArray(De)){const Fe=De.title;typeof Fe=="string"&&Fe.trim()&&(he=Fe.trim())}return{id:`interrupt-${J}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:J,value:De,title:he}]}},[b,L]),G=w.useMemo(()=>q?[...e,q]:e,[e,q]),ye=w.useMemo(()=>!$||!t?G:!G.some(he=>he.role==="assistant")&&G.length>0?[...G,{id:"thinking-assistant",role:"assistant",content:[],createdAt:new Date().toISOString()}]:G,[G,t,$]),Se=w.useMemo(()=>C?ye:ye.filter(J=>(J==null?void 0:J.role)!=="tool"),[ye,C]),Te=w.useMemo(()=>{const J=new Set,he=[];for(let De=Se.length-1;De>=0;De--){const Fe=Se[De];if(!Fe)continue;if("type"in Fe&&Fe.type==="default_message"){he.push(Fe);continue}const qe=Fe,Ge=ES(qe);J.has(Ge)||(J.add(Ge),he.push(qe))}return he.reverse()},[Se]),Y=w.useCallback(J=>{O(J),x&&x(!J),g&&g(J)},[x,g]),ne=w.useMemo(()=>{if(a)return async()=>{if(!R.current){R.current=!0;try{await a()}finally{R.current=!1}}}},[a]),H=w.useMemo(()=>!m||y?!1:K?"auto":!1,[K,m,y]),D=P??[],U=w.useMemo(()=>[...D].reverse(),[D]);w.useEffect(()=>{console.debug("[MessageList] timeline entries:",D.length,D.map(J=>({id:J.id,step:J.step,label:J.label})))},[D]);const Q=j??(D.length?D[D.length-1].id:null),te=D.length>0,le=w.useMemo(()=>{if(typeof p!="string")return null;const J=p.trim();return J?{id:"default-message",role:"assistant",type:"default_message",content:J,createdAt:new Date().toISOString()}:null},[p]),_e=te?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(ie.Info,{className:"h-3.5 w-3.5 text-muted-foreground cursor-help"}),u.jsx("div",{className:"pointer-events-auto fixed hidden w-64 rounded-md border bg-background p-3 text-[11px] font-normal text-muted-foreground shadow-lg group-hover:block whitespace-normal leading-relaxed",style:{zIndex:9999},children:'Backend pre-selects user inputs + the latest loop checkpoint. Click a dot to jump the chat to that point, or use the "Latest" button to return to the newest 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:U.map(J=>{const he=Q===J.id;return u.jsxs("button",{type:"button",disabled:!A,onClick:()=>A==null?void 0:A(J.id),className:`relative flex items-start gap-3 text-left text-xs transition ${he?"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 ${he?"border-primary bg-primary/10 text-primary":"border-border bg-background"}`,children:u.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${he?"bg-primary":"bg-border"}`})}),u.jsxs("span",{className:"flex-1",children:[u.jsx("span",{className:"block font-medium",children:J.label||"User input"}),u.jsxs("span",{className:"text-[10px] uppercase tracking-wide text-muted-foreground/70",children:[J.step!==null?`STEP ${J.step}`:"STEP —",J.next?` - ${J.next}`:""]})]})]},J.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,He=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),Xe=()=>le?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Ia,{message:le,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:p??"No messages yet. Start a conversation!"}),Ke=Te.length>0;return w.useImperativeHandle(B,()=>({scrollToLatest:()=>{var J,he;if(_.current&&Te.length>0){const De=Te.length-1;(he=(J=_.current).scrollToIndex)==null||he.call(J,{index:De,align:"end",behavior:"auto"})}else z.current&&(z.current.scrollTop=z.current.scrollHeight)},scrollToTop:()=>{var J,he;_.current&&Te.length>0?(he=(J=_.current).scrollToIndex)==null||he.call(J,{index:0,align:"start",behavior:"auto"}):z.current&&(z.current.scrollTop=0)}}),[Te]),u.jsxs("div",{className:He,style:h,children:[_e,u.jsx("div",{className:"relative flex-1 min-h-0",children:Ke?u.jsx(m0,{ref:J=>{_.current=J},scrollerRef:J=>{z.current=J instanceof HTMLDivElement?J:null},data:Te,followOutput:H,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!0,startReached:()=>{ne&&ne()},atBottomStateChange:Y,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(J,he)=>uh(he,J),itemContent:(J,he)=>{var yt;const De=uh(he,J),Fe="type"in he&&he.type==="default_message";let qe=[],Ge=null,Re={},Be={},Qe=null,Tt=null;if(!Fe){const dt=he,at=dt.checkpointId??null;Re=dt.additionalKwargs??{},Be=dt.responseMetadata??{};const Le=at&&E?E.get(at)??null:null;Qe=typeof Re.step=="number"?Re.step:typeof Be.step=="number"?Be.step:(Le==null?void 0:Le.step)??null;const At=typeof Re.source=="string"?Re.source:typeof Be.source=="string"?Be.source:(Le==null?void 0:Le.source)??null;Tt=At?String(At):null;const Kt=Qe!==null&&Tt?`${Qe}:${Tt}`:null;Kt&&(N!=null&&N.has(Kt))?qe=N.get(Kt)??[]:at&&Le&&(qe=[Le]),Ge=at??((yt=qe[0])==null?void 0:yt.id)??null}const xt=(()=>{if(typeof Re.parentCheckpointId=="string")return Re.parentCheckpointId;if(typeof Be.parentCheckpointId=="string")return Be.parentCheckpointId})();return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":De,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Ia,{message:he,messageIndex:J,isStreamingMessage:t&&n===he.id,streamingDebounceMs:r,isEditing:i===he.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:l,onRegenerate:()=>c(J),onCancelEdit:d,activeInterrupt:b,disableInterruptActions:S,onInterruptActionStart:k,onInterruptActionEnd:T,showToolMessages:C,checkpointCandidates:qe,activeCheckpointId:j??null,onSelectCheckpoint:A,defaultCheckpointId:Ge,messageParentCheckpointId:xt})})}}):Xe()})]})});Na.displayName="MessageList";const dh={value:""};function Ps({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:h,onExcelUploadSuccess:p,onError:m}){const{api:y}=ii(),{currentThreadId:x}=No(),{threadId:g,messages:b,hasMore:S,isHistoryLoading:k,isLoading:T,loadOlder:C,navigateToCheckpoint:E,returnToLatest:N,checkpoint:j,checkpoints:A,interrupt:P,metadata:$,timelineCheckpoints:B}=Ao(),{isStreaming:_,error:z,connectionState:R,submit:K,stop:O}=ac(),L=g??x??null,q=(j==null?void 0:j.id)??null,G=(j==null?void 0:j.namespace)??null,ye=($==null?void 0:$.assemblingMessageId)??null,Se=P,[Te,Y]=w.useState(!1);w.useEffect(()=>{Se||Y(!1)},[Se]);const ne=w.useCallback(()=>{Y(!0)},[]),H=w.useCallback(()=>{Y(!1)},[]),D=!!Se||Te,[U,Q]=w.useState(null),[te,le]=w.useState(""),[_e,He]=w.useState(null),[Xe,Ke]=w.useState(null),[J,he]=w.useState([]),[De,Fe]=w.useState(0),[qe,Ge]=w.useState(0),[Re,Be]=w.useState(!1),[Qe,Tt]=w.useState(null),[xt,yt]=w.useState(null),[dt,at]=w.useState(!1),[Le,At]=w.useState(null),Kt=w.useRef(!1),[re,be]=w.useState(()=>dh.value),ge=w.useRef(re),oe=w.useRef(null),Ne=w.useCallback(ee=>{dh.value=ee,be(ee)},[]),[lt,F]=w.useState(!1),pe=w.useRef(null),me=w.useCallback((ee,de)=>{if(!ee||typeof ee!="object")return null;const se=ee[de];return typeof se=="number"?se:null},[]),ot=w.useCallback((ee,de)=>{if(!ee||typeof ee!="object")return null;const se=ee[de];return typeof se=="string"&&se.trim()?se:null},[]),kt=w.useMemo(()=>{const ee=Pe=>{if(!Array.isArray(Pe)||Pe.length===0)return null;const ft=Pe.map(gt=>{if(typeof gt=="string")return gt.trim();if(gt&&typeof gt=="object"&&"type"in gt){const An=gt;if(typeof An.type=="string")return An.type}return null}).filter(gt=>!!(gt&&gt.length));return ft.length?ft.join(", "):null},de=Array.isArray(A)?A.map(Pe=>{const ft=ee(Pe.next);return ft?{...Pe,metadata:{...Pe.metadata??{},next:ft}}:Pe}):[];return de.some(Pe=>me(Pe.metadata,"step")!==null)&&de.sort((Pe,ft)=>{const gt=me(Pe.metadata,"step"),An=me(ft.metadata,"step");if(gt!==null||An!==null)return(An??Number.NEGATIVE_INFINITY)-(gt??Number.NEGATIVE_INFINITY);const lo=Date.parse(Pe.createdAt??""),co=Date.parse(ft.createdAt??"");return Number.isNaN(lo)||Number.isNaN(co)?0:co-lo}),de},[A,me]),{checkpointMetaById:rn,checkpointIndexByKey:Ye}=w.useMemo(()=>{const ee=new Map,de=new Map;for(const se of kt){const Pe=se.checkpointId??null;if(!Pe)continue;const ft=me(se.metadata,"step"),gt=ot(se.metadata,"source"),An={id:Pe,step:ft,source:gt,createdAt:se.createdAt??null,namespace:se.checkpointNs??null,parentId:se.parentId??null};if(ee.set(Pe,An),ft!==null&&gt){const lo=`${ft}:${gt}`,co=de.get(lo)??[];co.push(An),de.set(lo,co)}}for(const se of de.values())se.sort((Pe,ft)=>{const gt=Pe.createdAt??"";return(ft.createdAt??"").localeCompare(gt)});return{checkpointMetaById:ee,checkpointIndexByKey:de}},[kt,me,ot]),qt=B??[],et=w.useRef(null),mt=w.useRef(null),Nn=w.useCallback(()=>{et.current&&(et.current.value=""),mt.current&&(mt.current.value=""),Fe(ee=>ee+1),Ge(ee=>ee+1)},[]),Ws=w.useCallback(ee=>{Ne(ee)},[Ne]),ao=w.useRef(!1);w.useEffect(()=>{ao.current&&!_&&(he([]),Nn()),ao.current=_},[_,Nn]);const[Ua,Wa]=w.useState("desktop");w.useEffect(()=>{const ee=()=>{const de=window.innerWidth;Wa(de<640?"phone":de<1024?"tablet":"desktop")};return ee(),window.addEventListener("resize",ee),()=>window.removeEventListener("resize",ee)},[]),w.useEffect(()=>{Kt.current=!1},[L]),w.useEffect(()=>{ge.current=re},[re]),w.useEffect(()=>{if(!U){oe.current=null;return}oe.current===null&&(oe.current=ge.current),Ne(te??"")},[te,U,Ne]),w.useEffect(()=>{(async()=>{if(!y.baseUrl){At(null);return}try{const se=(await y.getAgent("default")).uiDefaultMessage||"";At(se||null)}catch(de){console.warn("Failed to fetch default message:",de),At(null)}})()},[y.baseUrl]),w.useEffect(()=>{z&&!dt&&(m==null||m(z))},[z,dt,m]);const Va=ee=>{if(ee.length>is)return`Message too long (${ee.length}/${is} characters)`;try{return sw(ee),null}catch(de){return(de==null?void 0:de.message)||"Invalid message"}},Ka=async ee=>{const de=ee.trim();if(!(!de&&J.length===0)){if(de){const se=Va(de);if(se){Ke(se);return}}try{const se=q??void 0,Pe=G??void 0,ft=U?{edit:!0,originalMessageId:U,..._e!=null&&_e.checkpointId?{originalCheckpointId:_e.checkpointId}:{},..._e!=null&&_e.checkpointNs?{originalCheckpointNs:_e.checkpointNs}:{}}:void 0;await K({text:de||"",attachments:J,messageAdditionalKwargs:ft},{checkpointId:se,checkpointNs:Pe}),h==null||h(de),Ne(""),Ke(null),he([]),Nn(),Q(null),le(""),He(null)}catch(se){const Pe=(se==null?void 0:se.message)||"Failed to send message";Ke(Pe),m==null||m(Pe)}}},I=w.useCallback((ee,de,se)=>{c&&(oe.current=re,Q(ee),le(de),Ne(de),Ke(null),He({checkpointId:(se==null?void 0:se.checkpointId)??null,checkpointNs:(se==null?void 0:se.checkpointNs)??null}))},[re,c,Ne]),V=w.useCallback(()=>{Q(null),le(""),He(null),Ke(null),Ne(oe.current??re),oe.current=null},[re,Ne]),ae=w.useCallback((ee,de,se)=>{I(ee,de,se)},[I]),ke=w.useCallback(ee=>{for(let de=ee-1;de>=0;de--)if(b[de].role==="user"){const se=b[de].content||[],ft=se.filter(gt=>gt.type==="text").map(gt=>gt.text).join("")||(()=>{try{return JSON.stringify(se,null,2)}catch{return String(se)}})();ft&&K({text:ft},{checkpointId:q??void 0,checkpointNs:G??void 0});break}},[b,K,q,G]),Ze=ee=>{const de=Array.from(ee.target.files||[]);he(se=>[...se,...de]),ee.target.value=""},rt=ee=>{he(de=>{const se=de.filter((Pe,ft)=>ee!==ft);return se.length===0&&Nn(),se})},Ue=async ee=>{const de=(ee.target.files||[])[0];if(de){Tt(null),yt(null),Be(!0);try{await K({attachments:[de]},{checkpointId:q??void 0,checkpointNs:G??void 0});const se=`Uploaded ${de.name} - processing through chat stream`;yt(se)}catch(se){const Pe=se instanceof Error?se.message:"Failed to upload Excel file";console.error("Excel upload failed",se),Tt(Pe),m==null||m(Pe)}finally{Be(!1),ee.target.value="",Nn()}}},ze=async ee=>{if(x){F(!0);try{if(!ee){await N(),requestAnimationFrame(()=>{var Pe;(Pe=pe.current)==null||Pe.scrollToLatest()});return}const de=kt.find(Pe=>Pe.checkpointId===ee),se=(de==null?void 0:de.checkpointNs)??null;await E(ee,se),requestAnimationFrame(()=>{var Pe;(Pe=pe.current)==null||Pe.scrollToTop()})}finally{F(!1)}}},jt=w.useCallback(async ee=>{await ze(ee)},[ze]),vt=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${f.container||""}`,bt=`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||""}`,Bt=`flex-shrink-0 w-full border-t p-4 bg-transparent ${f.inputArea||""}`;return w.useCallback(ee=>{if(!ee)return"Latest";const de=[];ee.step!==null&&de.push(`Step ${ee.step}`),ee.source&&de.push(ee.source);const se=ee.createdAt?new Date(ee.createdAt):null,Pe=se&&!Number.isNaN(se.getTime())?se.toLocaleString():ee.createdAt??ee.id,ft=de.length?` — ${de.join(" • ")}`:"";return`${Pe}${ft}`},[]),u.jsxs("div",{className:vt,children:[!!z&&!dt&&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:z}),u.jsx(tt,{variant:"ghost",size:"sm",onClick:()=>at(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(ie.X,{size:16})})]}),u.jsxs("div",{className:`relative ${bt}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(Na,{ref:pe,className:"h-full",style:{height:"100%"},messages:b,isStreaming:_,streamingAssistantId:ye,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:Ua,enableMessageEditing:c,editingMessageId:U,onEdit:ae,onRegenerate:ke,onCancelEdit:V,emptyMessage:Le??void 0,isNavigatingCheckpoint:lt,activeInterrupt:Se,disableInterruptActions:Te,onInterruptActionStart:ne,onInterruptActionEnd:H,showToolMessages:d,checkpointMetaById:rn,checkpointIndexByKey:Ye,activeCheckpointId:q,onSelectCheckpoint:jt,timelineCheckpoints:qt}),(R==="reconnecting"||R==="connecting")&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-muted/80 px-3 py-1 text-xs font-medium text-foreground shadow-sm backdrop-blur-sm dark:bg-muted/60",children:u.jsxs("span",{className:"flex items-center gap-2",children:[u.jsx(ie.Loader2,{className:"h-3 w-3 animate-spin"}),R==="reconnecting"?"Reconnecting…":"Connecting…"]})}),R==="error"&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-destructive/10 px-3 py-1 text-xs font-semibold text-destructive shadow-sm",children:"Connection lost"}),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(ie.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]}),(k||lt)&&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(ie.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:Bt,children:[U&&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(ie.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(tt,{variant:"ghost",size:"sm",onClick:V,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(ie.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:et,type:"file",multiple:!0,onChange:ee=>Ze(ee),className:"hidden"},De),J.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:J.map((ee,de)=>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(ie.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:ee.name}),u.jsx(tt,{variant:"ghost",size:"sm",onClick:()=>rt(de),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 ${ee.name}`,children:u.jsx(ie.X,{size:12})})]},de))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:mt,type:"file",accept:".xls,.xlsx,.xlsm",onChange:Ue,className:"hidden"},qe),Re&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(ie.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),xt&&!Re&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:xt}),Qe&&!Re&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:Qe})]})]}),Xe&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:Xe}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(Yb,{children:[u.jsx(Xb,{asChild:!0,children:u.jsx(tt,{type:"button",size:"icon",variant:"outline",disabled:_||D,title:"More input actions",className:f.moreButton||"",children:u.jsx(ie.Plus,{size:16})})}),u.jsxs(yd,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(Gi,{onClick:()=>{var ee;return(ee=et.current)==null?void 0:ee.click()},className:"cursor-pointer",children:[u.jsx(ie.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(Gi,{onClick:()=>{var ee;Re||(ee=mt.current)==null||ee.click()},className:`cursor-pointer ${Re?"opacity-60 pointer-events-none":""}`,children:[u.jsx(ie.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(Xg,{initialValue:te,editingMessageId:U,value:re,onValueChange:Ws,placeholder:U?"Edit your message...":t,isStreaming:_,disabled:D,maxLength:is,onSend:Ka,onCancelEdit:V,onStop:O,allowEmptySend:J.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${U?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${Xe?"border-red-400":""} ${f.textarea||""}`})})]})]})]})}const Os=v.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:Z("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}));Os.displayName="Input";function Aa(e,[t,n]){return Math.min(n,Math.max(t,e))}function IS(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var ja="ScrollArea",[fh,mT]=Cn(ja),[NS,tn]=fh(ja),hh=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,h]=v.useState(null),[p,m]=v.useState(null),[y,x]=v.useState(null),[g,b]=v.useState(0),[S,k]=v.useState(0),[T,C]=v.useState(!1),[E,N]=v.useState(!1),j=We(t,P=>l(P)),A=_o(o);return u.jsx(NS,{scope:n,type:r,dir:A,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:m,scrollbarXEnabled:T,onScrollbarXEnabledChange:C,scrollbarY:y,onScrollbarYChange:x,scrollbarYEnabled:E,onScrollbarYEnabledChange:N,onCornerWidthChange:b,onCornerHeightChange:k,children:u.jsx(je.div,{dir:A,...i,ref:j,style:{position:"relative","--radix-scroll-area-corner-width":g+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});hh.displayName=ja;var ph="ScrollAreaViewport",mh=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=tn(ph,n),a=v.useRef(null),l=We(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(je.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})})]})});mh.displayName=ph;var wn="ScrollAreaScrollbar",_a=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=tn(wn,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(AS,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(jS,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(gh,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Ra,{...r,ref:t}):null});_a.displayName=wn;var AS=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=tn(wn,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(Jt,{present:n||s,children:u.jsx(gh,{"data-state":s?"visible":"hidden",...r,ref:t})})}),jS=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=tn(wn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=$s(()=>l("SCROLL_END"),100),[a,l]=IS("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 h=()=>{const p=c[d];f!==p&&(l("SCROLL"),i()),f=p};return c.addEventListener("scroll",h),()=>c.removeEventListener("scroll",h)}},[o.viewport,s,l,i]),u.jsx(Jt,{present:n||a!=="hidden",children:u.jsx(Ra,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:fe(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:fe(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),gh=v.forwardRef((e,t)=>{const n=tn(wn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=v.useState(!1),a=e.orientation==="horizontal",l=$s(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return wr(n.viewport,l),wr(n.content,l),u.jsx(Jt,{present:r||s,children:u.jsx(Ra,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Ra=v.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=tn(wn,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=wh(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:c>0&&c<1,onThumbChange:h=>s.current=h,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:h=>i.current=h};function f(h,p){return DS(h,i.current,a,p)}return n==="horizontal"?u.jsx(_S,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=Sh(h,a,o.dir);s.current.style.transform=`translate3d(${p}px, 0, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollLeft=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollLeft=f(h,o.dir))}}):n==="vertical"?u.jsx(RS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=Sh(h,a);s.current.style.transform=`translate3d(0, ${p}px, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollTop=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollTop=f(h))}}):null}),_S=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=tn(wn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=We(t,l,s.onScrollbarXChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(yh,{"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":Ls(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(h),Th(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:Ds(i.paddingLeft),paddingEnd:Ds(i.paddingRight)}})}})}),RS=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=tn(wn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=We(t,l,s.onScrollbarYChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(yh,{"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":Ls(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(h),Th(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:Ds(i.paddingTop),paddingEnd:Ds(i.paddingBottom)}})}})}),[PS,xh]=fh(wn),yh=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,...h}=e,p=tn(wn,n),[m,y]=v.useState(null),x=We(t,j=>y(j)),g=v.useRef(null),b=v.useRef(""),S=p.viewport,k=r.content-r.viewport,T=Nt(d),C=Nt(l),E=$s(f,10);function N(j){if(g.current){const A=j.clientX-g.current.left,P=j.clientY-g.current.top;c({x:A,y:P})}}return v.useEffect(()=>{const j=A=>{const P=A.target;(m==null?void 0:m.contains(P))&&T(A,k)};return document.addEventListener("wheel",j,{passive:!1}),()=>document.removeEventListener("wheel",j,{passive:!1})},[S,m,k,T]),v.useEffect(C,[r,C]),wr(m,E),wr(p.content,E),u.jsx(PS,{scope:n,scrollbar:m,hasThumb:o,onThumbChange:Nt(s),onThumbPointerUp:Nt(i),onThumbPositionChange:C,onThumbPointerDown:Nt(a),children:u.jsx(je.div,{...h,ref:x,style:{position:"absolute",...h.style},onPointerDown:fe(e.onPointerDown,j=>{j.button===0&&(j.target.setPointerCapture(j.pointerId),g.current=m.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),N(j))}),onPointerMove:fe(e.onPointerMove,N),onPointerUp:fe(e.onPointerUp,j=>{const A=j.target;A.hasPointerCapture(j.pointerId)&&A.releasePointerCapture(j.pointerId),document.body.style.webkitUserSelect=b.current,p.viewport&&(p.viewport.style.scrollBehavior=""),g.current=null})})})}),Ms="ScrollAreaThumb",vh=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=xh(Ms,e.__scopeScrollArea);return u.jsx(Jt,{present:n||o.hasThumb,children:u.jsx(OS,{ref:t,...r})})}),OS=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=tn(Ms,n),i=xh(Ms,n),{onThumbPositionChange:a}=i,l=We(t,f=>i.onThumbChange(f)),c=v.useRef(void 0),d=$s(()=>{c.current&&(c.current(),c.current=void 0)},100);return v.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(d(),!c.current){const p=LS(f,a);c.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,d,a]),u.jsx(je.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:l,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:fe(e.onPointerDownCapture,f=>{const p=f.target.getBoundingClientRect(),m=f.clientX-p.left,y=f.clientY-p.top;i.onThumbPointerDown({x:m,y})}),onPointerUp:fe(e.onPointerUp,i.onThumbPointerUp)})});vh.displayName=Ms;var Pa="ScrollAreaCorner",bh=v.forwardRef((e,t)=>{const n=tn(Pa,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(MS,{...e,ref:t}):null});bh.displayName=Pa;var MS=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=tn(Pa,n),[s,i]=v.useState(0),[a,l]=v.useState(0),c=!!(s&&a);return wr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),wr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(je.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 Ds(e){return e?parseInt(e,10):0}function wh(e,t){const n=e/t;return isNaN(n)?0:n}function Ls(e){const t=wh(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function DS(e,t,n,r="ltr"){const o=Ls(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 Ch([l,c],f)(e)}function Sh(e,t,n="ltr"){const r=Ls(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=Aa(e,l);return Ch([0,i],[0,a])(c)}function Ch(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 Th(e,t){return e>0&&e<t}var LS=(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 $s(e,t){const n=Nt(e),r=v.useRef(0);return v.useEffect(()=>()=>window.clearTimeout(r.current),[]),v.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function wr(e,t){const n=Nt(t);It(()=>{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 kh=hh,$S=mh,FS=bh;const Eh=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(kh,{ref:r,className:Z("relative overflow-hidden",e),...n,children:[u.jsx($S,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(Ih,{}),u.jsx(FS,{})]}));Eh.displayName=kh.displayName;const Ih=v.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(_a,{ref:r,orientation:t,className:Z("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(vh,{className:"relative flex-1 rounded-full bg-border"})}));Ih.displayName=_a.displayName;const Nh=25;function Oa({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:h,setCurrentThreadId:p,isLoading:m,actions:y}=No(),{loadThread:x}=Ao(),{createThread:g,deleteThread:b,renameThread:S}=y,[k,T]=w.useState(Array.isArray(f)?f:[]),C=w.useRef(k.length>0),E=w.useRef(null),N=w.useRef(0),[j,A]=w.useState(null),[P,$]=w.useState(""),[B,_]=w.useState(!1);w.useEffect(()=>{const Y=Array.isArray(f)?f:[];if(Y.length>0){C.current=!0,T(Y);return}m||(C.current=!1,T(Y))},[f,m]),w.useEffect(()=>{if(!E.current)return;const Y=E.current.querySelector("[data-radix-scroll-area-viewport]");if(!Y)return;let ne=null,H=null;return ne=requestAnimationFrame(()=>{H=requestAnimationFrame(()=>{Y.scrollTop=N.current})}),()=>{ne!==null&&cancelAnimationFrame(ne),H!==null&&cancelAnimationFrame(H)}},[k]);const z=async Y=>{try{p(Y),await x(Y),a==null||a(Y),l==null||l(Y)}catch(ne){console.error("Failed to select thread:",ne)}},R=async()=>{try{_(!0);const Y=await g();Y&&(c==null||c(Y),a==null||a(Y))}catch(Y){console.error("Failed to create thread:",Y)}finally{_(!1)}},K=async(Y,ne)=>{if(ne.stopPropagation(),!!confirm("Delete this thread?")){if(E.current){const H=E.current.querySelector("[data-radix-scroll-area-viewport]");H&&(N.current=H.scrollTop)}try{await b(Y),d==null||d(Y)}catch(H){console.error("Failed to delete thread:",H)}}},O=(Y,ne)=>{ne.stopPropagation(),A(Y.threadId),$(Y.title||`Thread ${Y.threadId.slice(0,8)}`)},L=async Y=>{if(P.trim())try{await S(Y,P.trim()),A(null),$("")}catch(ne){console.error("Failed to update title:",ne)}},q=()=>{A(null),$("")},G=(Y,ne)=>{Y.key==="Enter"?L(ne):Y.key==="Escape"&&q()},ye=Y=>{if(!Y)return"";try{const ne=new Date(Y),D=new Date().getTime()-ne.getTime(),U=Math.floor(D/(1e3*60*60*24));return U===0?ne.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):U===1?"Yesterday":U<7?`${U} days ago`:ne.toLocaleDateString()}catch{return""}},Se=Y=>Y.title||`Thread ${Y.threadId.slice(0,8)}`,Te=Y=>{const ne=Se(Y);return ne.length<=Nh?ne:`${ne.slice(0,Nh)}...`};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(tt,{onClick:R,disabled:B||m,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:B?"Creating...":"New Chat",children:u.jsx(ie.MessageSquarePlus,{size:20})})}),u.jsx(Eh,{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(ie.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(ie.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((Y,ne)=>new Date(ne.updatedAt||ne.createdAt||"").getTime()-new Date(Y.updatedAt||Y.createdAt||"").getTime()).map(Y=>u.jsxs("div",{onClick:()=>z(Y.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??h)===Y.threadId?`${s.activeThread||"bg-slate-600 border-slate-500"} `:`${s.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${s.threadItem||""} text-gray-900 dark:text-slate-100`,children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx("div",{className:"flex-1 min-w-0",children:j===Y.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:ne=>ne.stopPropagation(),children:[u.jsx(Os,{value:P,onChange:ne=>$(ne.target.value),onKeyDown:ne=>G(ne,Y.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(tt,{variant:"ghost",size:"sm",onClick:()=>L(Y.threadId),className:"h-6 w-6 p-0",children:u.jsx(ie.Check,{size:12})}),u.jsx(tt,{variant:"ghost",size:"sm",onClick:q,className:"h-6 w-6 p-0",children:u.jsx(ie.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:Te(Y)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(ie.Calendar,{size:10}),u.jsx("span",{children:ye(Y.updatedAt||Y.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&j!==Y.threadId&&u.jsx(tt,{variant:"ghost",size:"sm",onClick:ne=>O(Y,ne),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(ie.Edit3,{size:12})}),n&&u.jsx(tt,{variant:"ghost",size:"sm",onClick:ne=>K(Y.threadId,ne),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(ie.Trash2,{size:12})})]})]}),i===Y.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},Y.threadId))})})]})}function Sr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function zS(e){if(typeof e!="string")return;const t=e.trim();if(t)return Sn(t)}function Ah(){const e=[Sr("__API_BASE_URL__"),Sr("__CHAT_API_BASE_URL__"),Sr("__CHAT_API_URL__")];for(const t of e){const n=zS(t);if(n)return n}}function jh(){const e=[Sr("__API_AUTH_TOKEN__"),Sr("__CHAT_API_KEY__"),Sr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function _h(...e){for(const t of e)if(typeof t=="string"&&t.trim())return Sn(t);return Sn()}function Rh(){const e={},t=Ah(),n=jh();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Ph(){const e=Rh(),t=jn.getAuthToken(),n=Ah();return{apiBaseUrl:_h(e.baseUrl,jn.baseUrl,n),apiKey:t||e.apiKey||jh()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const Oh="chat-settings";function BS(){try{const e=localStorage.getItem(Oh);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function HS(e){try{const t={...e,apiBaseUrl:Sn(e.apiBaseUrl)};localStorage.setItem(Oh,JSON.stringify(t)),t.apiKey&&jn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function US(){const e=Ph(),t=BS(),n=jn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:_h(jn.baseUrl,r,e.apiBaseUrl)}}function WS(e){jn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),HS(e)}var VS="Label",Mh=v.forwardRef((e,t)=>u.jsx(je.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())}}));Mh.displayName=VS;var Dh=Mh;const KS=uo.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),nn=v.forwardRef(({className:e,...t},n)=>u.jsx(Dh,{ref:n,className:Z(KS(),e),...t}));nn.displayName=Dh.displayName;function Lh(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 Fs="Switch",[qS,gT]=Cn(Fs),[GS,YS]=qS(Fs),$h=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,[h,p]=v.useState(null),m=We(t,S=>p(S)),y=v.useRef(!1),x=h?d||!!h.closest("form"):!0,[g,b]=cr({prop:o,defaultProp:s??!1,onChange:c,caller:Fs});return u.jsxs(GS,{scope:n,checked:g,disabled:a,children:[u.jsx(je.button,{type:"button",role:"switch","aria-checked":g,"aria-required":i,"data-state":Hh(g),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:m,onClick:fe(e.onClick,S=>{b(k=>!k),x&&(y.current=S.isPropagationStopped(),y.current||S.stopPropagation())})}),x&&u.jsx(Bh,{control:h,bubbles:!y.current,name:r,value:l,checked:g,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});$h.displayName=Fs;var Fh="SwitchThumb",zh=v.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=YS(Fh,n);return u.jsx(je.span,{"data-state":Hh(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});zh.displayName=Fh;var XS="SwitchBubbleInput",Bh=v.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=v.useRef(null),a=We(i,s),l=Lh(n),c=Vc(t);return v.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&p){const m=new Event("click",{bubbles:r});p.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}})});Bh.displayName=XS;function Hh(e){return e?"checked":"unchecked"}var Uh=$h,JS=zh;const zn=v.forwardRef(({className:e,...t},n)=>u.jsx(Uh,{className:Z("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(JS,{className:Z("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")})}));zn.displayName=Uh.displayName;var Wh=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"}),ZS="VisuallyHidden",QS=v.forwardRef((e,t)=>u.jsx(je.span,{...e,ref:t,style:{...Wh,...e.style}}));QS.displayName=ZS;var eC=[" ","Enter","ArrowUp","ArrowDown"],tC=[" ","Enter"],rr="Select",[zs,Bs,nC]=hi(rr),[Cr,xT]=Cn(rr,[nC,Wo]),Hs=Wo(),[rC,Bn]=Cr(rr),[oC,sC]=Cr(rr),Vh=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:h,required:p,form:m}=e,y=Hs(t),[x,g]=v.useState(null),[b,S]=v.useState(null),[k,T]=v.useState(!1),C=_o(c),[E,N]=cr({prop:r,defaultProp:o??!1,onChange:s,caller:rr}),[j,A]=cr({prop:i,defaultProp:a,onChange:l,caller:rr}),P=v.useRef(null),$=x?m||!!x.closest("form"):!0,[B,_]=v.useState(new Set),z=Array.from(B).map(R=>R.props.value).join(";");return u.jsx(tu,{...y,children:u.jsxs(rC,{required:p,scope:t,trigger:x,onTriggerChange:g,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:k,onValueNodeHasChildrenChange:T,contentId:Tn(),value:j,onValueChange:A,open:E,onOpenChange:N,dir:C,triggerPointerDownPosRef:P,disabled:h,children:[u.jsx(zs.Provider,{scope:t,children:u.jsx(oC,{scope:e.__scopeSelect,onNativeOptionAdd:v.useCallback(R=>{_(K=>new Set(K).add(R))},[]),onNativeOptionRemove:v.useCallback(R=>{_(K=>{const O=new Set(K);return O.delete(R),O})},[]),children:n})}),$?u.jsxs(mp,{"aria-hidden":!0,required:p,tabIndex:-1,name:d,autoComplete:f,value:j,onChange:R=>A(R.target.value),disabled:h,form:m,children:[j===void 0?u.jsx("option",{value:""}):null,Array.from(B)]},z):null]})})};Vh.displayName=rr;var Kh="SelectTrigger",qh=v.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Hs(n),i=Bn(Kh,n),a=i.disabled||r,l=We(t,i.onTriggerChange),c=Bs(n),d=v.useRef("touch"),[f,h,p]=xp(y=>{const x=c().filter(S=>!S.disabled),g=x.find(S=>S.value===i.value),b=yp(x,y,g);b!==void 0&&i.onValueChange(b.value)}),m=y=>{a||(i.onOpenChange(!0),p()),y&&(i.triggerPointerDownPosRef.current={x:Math.round(y.pageX),y:Math.round(y.pageY)})};return u.jsx(nu,{asChild:!0,...s,children:u.jsx(je.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":gp(i.value)?"":void 0,...o,ref:l,onClick:fe(o.onClick,y=>{y.currentTarget.focus(),d.current!=="mouse"&&m(y)}),onPointerDown:fe(o.onPointerDown,y=>{d.current=y.pointerType;const x=y.target;x.hasPointerCapture(y.pointerId)&&x.releasePointerCapture(y.pointerId),y.button===0&&y.ctrlKey===!1&&y.pointerType==="mouse"&&(m(y),y.preventDefault())}),onKeyDown:fe(o.onKeyDown,y=>{const x=f.current!=="";!(y.ctrlKey||y.altKey||y.metaKey)&&y.key.length===1&&h(y.key),!(x&&y.key===" ")&&eC.includes(y.key)&&(m(),y.preventDefault())})})})});qh.displayName=Kh;var Gh="SelectValue",Yh=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Bn(Gh,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=We(t,l.onValueNodeChange);return It(()=>{c(d)},[c,d]),u.jsx(je.span,{...a,ref:f,style:{pointerEvents:"none"},children:gp(l.value)?u.jsx(u.Fragment,{children:i}):s})});Yh.displayName=Gh;var iC="SelectIcon",Xh=v.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(je.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Xh.displayName=iC;var aC="SelectPortal",Jh=e=>u.jsx(Vo,{asChild:!0,...e});Jh.displayName=aC;var or="SelectContent",Zh=v.forwardRef((e,t)=>{const n=Bn(or,e.__scopeSelect),[r,o]=v.useState();if(It(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?fo.createPortal(u.jsx(Qh,{scope:e.__scopeSelect,children:u.jsx(zs.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(ep,{...e,ref:t})});Zh.displayName=or;var dn=10,[Qh,Hn]=Cr(or),lC="SelectContentImpl",cC=Un.createSlot("SelectContent.RemoveScroll"),ep=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:h,collisionPadding:p,sticky:m,hideWhenDetached:y,avoidCollisions:x,...g}=e,b=Bn(or,n),[S,k]=v.useState(null),[T,C]=v.useState(null),E=We(t,H=>k(H)),[N,j]=v.useState(null),[A,P]=v.useState(null),$=Bs(n),[B,_]=v.useState(!1),z=v.useRef(!1);v.useEffect(()=>{if(S)return Mi(S)},[S]),gi();const R=v.useCallback(H=>{const[D,...U]=$().map(le=>le.ref.current),[Q]=U.slice(-1),te=document.activeElement;for(const le of H)if(le===te||(le==null||le.scrollIntoView({block:"nearest"}),le===D&&T&&(T.scrollTop=0),le===Q&&T&&(T.scrollTop=T.scrollHeight),le==null||le.focus(),document.activeElement!==te))return},[$,T]),K=v.useCallback(()=>R([N,S]),[R,N,S]);v.useEffect(()=>{B&&K()},[B,K]);const{onOpenChange:O,triggerPointerDownPosRef:L}=b;v.useEffect(()=>{if(S){let H={x:0,y:0};const D=Q=>{var te,le;H={x:Math.abs(Math.round(Q.pageX)-(((te=L.current)==null?void 0:te.x)??0)),y:Math.abs(Math.round(Q.pageY)-(((le=L.current)==null?void 0:le.y)??0))}},U=Q=>{H.x<=10&&H.y<=10?Q.preventDefault():S.contains(Q.target)||O(!1),document.removeEventListener("pointermove",D),L.current=null};return L.current!==null&&(document.addEventListener("pointermove",D),document.addEventListener("pointerup",U,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",D),document.removeEventListener("pointerup",U,{capture:!0})}}},[S,O,L]),v.useEffect(()=>{const H=()=>O(!1);return window.addEventListener("blur",H),window.addEventListener("resize",H),()=>{window.removeEventListener("blur",H),window.removeEventListener("resize",H)}},[O]);const[q,G]=xp(H=>{const D=$().filter(te=>!te.disabled),U=D.find(te=>te.ref.current===document.activeElement),Q=yp(D,H,U);Q&&setTimeout(()=>Q.ref.current.focus())}),ye=v.useCallback((H,D,U)=>{const Q=!z.current&&!U;(b.value!==void 0&&b.value===D||Q)&&(j(H),Q&&(z.current=!0))},[b.value]),Se=v.useCallback(()=>S==null?void 0:S.focus(),[S]),Te=v.useCallback((H,D,U)=>{const Q=!z.current&&!U;(b.value!==void 0&&b.value===D||Q)&&P(H)},[b.value]),Y=r==="popper"?Ma:tp,ne=Y===Ma?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:m,hideWhenDetached:y,avoidCollisions:x}:{};return u.jsx(Qh,{scope:n,content:S,viewport:T,onViewportChange:C,itemRefCallback:ye,selectedItem:N,onItemLeave:Se,itemTextRefCallback:Te,focusSelectedItem:K,selectedItemText:A,position:r,isPositioned:B,searchRef:q,children:u.jsx(es,{as:cC,allowPinchZoom:!0,children:u.jsx(Po,{asChild:!0,trapped:b.open,onMountAutoFocus:H=>{H.preventDefault()},onUnmountAutoFocus:fe(o,H=>{var D;(D=b.trigger)==null||D.focus({preventScroll:!0}),H.preventDefault()}),children:u.jsx(Ro,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:H=>H.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:u.jsx(Y,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:H=>H.preventDefault(),...g,...ne,onPlaced:()=>_(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...g.style},onKeyDown:fe(g.onKeyDown,H=>{const D=H.ctrlKey||H.altKey||H.metaKey;if(H.key==="Tab"&&H.preventDefault(),!D&&H.key.length===1&&G(H.key),["ArrowUp","ArrowDown","Home","End"].includes(H.key)){let Q=$().filter(te=>!te.disabled).map(te=>te.ref.current);if(["ArrowUp","End"].includes(H.key)&&(Q=Q.slice().reverse()),["ArrowUp","ArrowDown"].includes(H.key)){const te=H.target,le=Q.indexOf(te);Q=Q.slice(le+1)}setTimeout(()=>R(Q)),H.preventDefault()}})})})})})})});ep.displayName=lC;var uC="SelectItemAlignedPosition",tp=v.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Bn(or,n),i=Hn(or,n),[a,l]=v.useState(null),[c,d]=v.useState(null),f=We(t,E=>d(E)),h=Bs(n),p=v.useRef(!1),m=v.useRef(!0),{viewport:y,selectedItem:x,selectedItemText:g,focusSelectedItem:b}=i,S=v.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&y&&x&&g){const E=s.trigger.getBoundingClientRect(),N=c.getBoundingClientRect(),j=s.valueNode.getBoundingClientRect(),A=g.getBoundingClientRect();if(s.dir!=="rtl"){const te=A.left-N.left,le=j.left-te,_e=E.left-le,He=E.width+_e,Xe=Math.max(He,N.width),Ke=window.innerWidth-dn,J=Aa(le,[dn,Math.max(dn,Ke-Xe)]);a.style.minWidth=He+"px",a.style.left=J+"px"}else{const te=N.right-A.right,le=window.innerWidth-j.right-te,_e=window.innerWidth-E.right-le,He=E.width+_e,Xe=Math.max(He,N.width),Ke=window.innerWidth-dn,J=Aa(le,[dn,Math.max(dn,Ke-Xe)]);a.style.minWidth=He+"px",a.style.right=J+"px"}const P=h(),$=window.innerHeight-dn*2,B=y.scrollHeight,_=window.getComputedStyle(c),z=parseInt(_.borderTopWidth,10),R=parseInt(_.paddingTop,10),K=parseInt(_.borderBottomWidth,10),O=parseInt(_.paddingBottom,10),L=z+R+B+O+K,q=Math.min(x.offsetHeight*5,L),G=window.getComputedStyle(y),ye=parseInt(G.paddingTop,10),Se=parseInt(G.paddingBottom,10),Te=E.top+E.height/2-dn,Y=$-Te,ne=x.offsetHeight/2,H=x.offsetTop+ne,D=z+R+H,U=L-D;if(D<=Te){const te=P.length>0&&x===P[P.length-1].ref.current;a.style.bottom="0px";const le=c.clientHeight-y.offsetTop-y.offsetHeight,_e=Math.max(Y,ne+(te?Se:0)+le+K),He=D+_e;a.style.height=He+"px"}else{const te=P.length>0&&x===P[0].ref.current;a.style.top="0px";const _e=Math.max(Te,z+y.offsetTop+(te?ye:0)+ne)+U;a.style.height=_e+"px",y.scrollTop=D-Te+y.offsetTop}a.style.margin=`${dn}px 0`,a.style.minHeight=q+"px",a.style.maxHeight=$+"px",r==null||r(),requestAnimationFrame(()=>p.current=!0)}},[h,s.trigger,s.valueNode,a,c,y,x,g,s.dir,r]);It(()=>S(),[S]);const[k,T]=v.useState();It(()=>{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(fC,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:p,onScrollButtonChange:C,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:k},children:u.jsx(je.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});tp.displayName=uC;var dC="SelectPopperPosition",Ma=v.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=dn,...s}=e,i=Hs(n);return u.jsx(ru,{...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)"}})});Ma.displayName=dC;var[fC,Da]=Cr(or,{}),La="SelectViewport",np=v.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Hn(La,n),i=Da(La,n),a=We(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(zs.Slot,{scope:n,children:u.jsx(je.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:fe(o.onScroll,c=>{const d=c.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:h}=i;if(h!=null&&h.current&&f){const p=Math.abs(l.current-d.scrollTop);if(p>0){const m=window.innerHeight-dn*2,y=parseFloat(f.style.minHeight),x=parseFloat(f.style.height),g=Math.max(y,x);if(g<m){const b=g+p,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})})})]})});np.displayName=La;var rp="SelectGroup",[hC,pC]=Cr(rp),mC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Tn();return u.jsx(hC,{scope:n,id:o,children:u.jsx(je.div,{role:"group","aria-labelledby":o,...r,ref:t})})});mC.displayName=rp;var op="SelectLabel",sp=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=pC(op,n);return u.jsx(je.div,{id:o.id,...r,ref:t})});sp.displayName=op;var Us="SelectItem",[gC,ip]=Cr(Us),ap=v.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Bn(Us,n),l=Hn(Us,n),c=a.value===r,[d,f]=v.useState(s??""),[h,p]=v.useState(!1),m=We(t,b=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,b,r,o)}),y=Tn(),x=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(gC,{scope:n,value:r,disabled:o,textId:y,isSelected:c,onItemTextChange:v.useCallback(b=>{f(S=>S||((b==null?void 0:b.textContent)??"").trim())},[]),children:u.jsx(zs.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(je.div,{role:"option","aria-labelledby":y,"data-highlighted":h?"":void 0,"aria-selected":c&&h,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:m,onFocus:fe(i.onFocus,()=>p(!0)),onBlur:fe(i.onBlur,()=>p(!1)),onClick:fe(i.onClick,()=>{x.current!=="mouse"&&g()}),onPointerUp:fe(i.onPointerUp,()=>{x.current==="mouse"&&g()}),onPointerDown:fe(i.onPointerDown,b=>{x.current=b.pointerType}),onPointerMove:fe(i.onPointerMove,b=>{var S;x.current=b.pointerType,o?(S=l.onItemLeave)==null||S.call(l):x.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:fe(i.onPointerLeave,b=>{var S;b.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:fe(i.onKeyDown,b=>{var k;((k=l.searchRef)==null?void 0:k.current)!==""&&b.key===" "||(tC.includes(b.key)&&g(),b.key===" "&&b.preventDefault())})})})})});ap.displayName=Us;var io="SelectItemText",lp=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Bn(io,n),a=Hn(io,n),l=ip(io,n),c=sC(io,n),[d,f]=v.useState(null),h=We(t,g=>f(g),l.onItemTextChange,g=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,g,l.value,l.disabled)}),p=d==null?void 0:d.textContent,m=v.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:p},l.value),[l.disabled,l.value,p]),{onNativeOptionAdd:y,onNativeOptionRemove:x}=c;return It(()=>(y(m),()=>x(m)),[y,x,m]),u.jsxs(u.Fragment,{children:[u.jsx(je.span,{id:l.textId,...s,ref:h}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?fo.createPortal(s.children,i.valueNode):null]})});lp.displayName=io;var cp="SelectItemIndicator",up=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return ip(cp,n).isSelected?u.jsx(je.span,{"aria-hidden":!0,...r,ref:t}):null});up.displayName=cp;var $a="SelectScrollUpButton",dp=v.forwardRef((e,t)=>{const n=Hn($a,e.__scopeSelect),r=Da($a,e.__scopeSelect),[o,s]=v.useState(!1),i=We(t,r.onScrollButtonChange);return It(()=>{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(hp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});dp.displayName=$a;var Fa="SelectScrollDownButton",fp=v.forwardRef((e,t)=>{const n=Hn(Fa,e.__scopeSelect),r=Da(Fa,e.__scopeSelect),[o,s]=v.useState(!1),i=We(t,r.onScrollButtonChange);return It(()=>{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(hp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});fp.displayName=Fa;var hp=v.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Hn("SelectScrollButton",n),i=v.useRef(null),a=Bs(n),l=v.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return v.useEffect(()=>()=>l(),[l]),It(()=>{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(je.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:fe(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:fe(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:fe(o.onPointerLeave,()=>{l()})})}),xC="SelectSeparator",pp=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(je.div,{"aria-hidden":!0,...r,ref:t})});pp.displayName=xC;var za="SelectArrow",yC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Hs(n),s=Bn(za,n),i=Hn(za,n);return s.open&&i.position==="popper"?u.jsx(ou,{...o,...r,ref:t}):null});yC.displayName=za;var vC="SelectBubbleInput",mp=v.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=v.useRef(null),s=We(r,o),i=Lh(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(je.select,{...n,style:{...Wh,...n.style},ref:s,defaultValue:t})});mp.displayName=vC;function gp(e){return e===""||e===void 0}function xp(e){const t=Nt(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 yp(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=bC(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function bC(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var wC=Vh,vp=qh,SC=Yh,CC=Xh,TC=Jh,bp=Zh,kC=np,wp=sp,Sp=ap,EC=lp,IC=up,Cp=dp,Tp=fp,kp=pp;const Ep=wC,Ip=SC,Ba=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(vp,{ref:r,className:Z("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(CC,{asChild:!0,children:u.jsx(ie.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Ba.displayName=vp.displayName;const Np=v.forwardRef(({className:e,...t},n)=>u.jsx(Cp,{ref:n,className:Z("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ie.ChevronUp,{className:"h-4 w-4"})}));Np.displayName=Cp.displayName;const Ap=v.forwardRef(({className:e,...t},n)=>u.jsx(Tp,{ref:n,className:Z("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ie.ChevronDown,{className:"h-4 w-4"})}));Ap.displayName=Tp.displayName;const Ha=v.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(TC,{children:u.jsxs(bp,{ref:o,className:Z("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(Np,{}),u.jsx(kC,{className:Z("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(Ap,{})]})}));Ha.displayName=bp.displayName;const NC=v.forwardRef(({className:e,...t},n)=>u.jsx(wp,{ref:n,className:Z("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));NC.displayName=wp.displayName;const sr=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Sp,{ref:r,className:Z("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(IC,{children:u.jsx(ie.Check,{className:"h-4 w-4"})})}),u.jsx(EC,{children:t})]}));sr.displayName=Sp.displayName;const AC=v.forwardRef(({className:e,...t},n)=>u.jsx(kp,{ref:n,className:Z("-mx-1 my-1 h-px bg-muted",e),...t}));AC.displayName=kp.displayName;var jC="Separator",jp="horizontal",_C=["horizontal","vertical"],_p=v.forwardRef((e,t)=>{const{decorative:n,orientation:r=jp,...o}=e,s=RC(r)?r:jp,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(je.div,{"data-orientation":s,...a,...o,ref:t})});_p.displayName=jC;function RC(e){return _C.includes(e)}var Rp=_p;const Pp=v.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(Rp,{ref:o,decorative:n,orientation:t,className:Z("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Pp.displayName=Rp.displayName;const PC=Bf,OC=Y0,MC=Hf,Op=v.forwardRef(({className:e,...t},n)=>u.jsx(ks,{className:Z("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}));Op.displayName=ks.displayName;const DC=uo.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"}}),Mp=v.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(MC,{children:[u.jsx(Op,{}),u.jsxs(Es,{ref:o,className:Z(DC({side:e}),t),...r,children:[n,u.jsxs(Uf,{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(ie.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Mp.displayName=Es.displayName;const Dp=({className:e,...t})=>u.jsx("div",{className:Z("flex flex-col space-y-2 text-center sm:text-left",e),...t});Dp.displayName="SheetHeader";const Lp=v.forwardRef(({className:e,...t},n)=>u.jsx(tr,{ref:n,className:Z("text-lg font-semibold text-foreground",e),...t}));Lp.displayName=tr.displayName;const $p=v.forwardRef(({className:e,...t},n)=>u.jsx(Is,{ref:n,className:Z("text-sm text-muted-foreground",e),...t}));$p.displayName=Is.displayName;const LC={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 $C({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}=ba();w.useEffect(()=>{const x=JSON.stringify(a)!==JSON.stringify(e);d(x)},[a,e]),w.useEffect(()=>{l(e)},[e]);const h=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},p=()=>{l(LC),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},m=()=>{l(e),d(!1),o(!1)},y=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(PC,{open:r,onOpenChange:o,children:[u.jsx(OC,{asChild:!0,children:u.jsxs(tt,{variant:"outline",size:"sm",className:n,children:[u.jsx(ie.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(yf,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(Mp,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(Dp,{children:[u.jsx(Lp,{children:"Chat Settings"}),u.jsx($p,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(Zr,{children:[u.jsx(Qr,{className:"pb-3",children:u.jsxs(eo,{className:"text-lg flex items-center gap-2",children:[u.jsx(ie.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(to,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(nn,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Os,{id:"api-url",value:a.api.baseUrl,onChange:x=>l(g=>({...g,api:{...g.api,baseUrl:x.target.value}})),placeholder:"http://localhost:8000/api"}),u.jsx(tt,{variant:"outline",onClick:y,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(nn,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(zn,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:x=>l(g=>({...g,api:{...g.api,enableAuth:x}}))})]}),a.api.enableAuth&&u.jsxs("div",{className:"space-y-2",children:[u.jsx(nn,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Os,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:x=>l(g=>({...g,api:{...g.api,authToken:x.target.value}})),placeholder:"Enter your Bearer token"}),u.jsx(tt,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?u.jsx(ie.EyeOff,{className:"h-4 w-4"}):u.jsx(ie.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(Zr,{children:[u.jsx(Qr,{className:"pb-3",children:u.jsxs(eo,{className:"text-lg flex items-center gap-2",children:[u.jsx(ie.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(to,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(nn,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(Ep,{value:a.ui.layout,onValueChange:x=>l(g=>({...g,ui:{...g.ui,layout:x}})),children:[u.jsx(Ba,{children:u.jsx(Ip,{})}),u.jsxs(Ha,{children:[u.jsx(sr,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(sr,{value:"fullscreen",children:"Fullscreen"}),u.jsx(sr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(nn,{htmlFor:"theme",children:"Theme"}),u.jsxs(Ep,{value:a.ui.theme,onValueChange:x=>l(g=>({...g,ui:{...g.ui,theme:x}})),children:[u.jsx(Ba,{children:u.jsx(Ip,{})}),u.jsxs(Ha,{children:[u.jsx(sr,{value:"light",children:"Light"}),u.jsx(sr,{value:"dark",children:"Dark"}),u.jsx(sr,{value:"system",children:"System"})]})]})]}),u.jsx(Pp,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(nn,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(zn,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:x=>l(g=>({...g,ui:{...g.ui,showTimestamps:x}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(nn,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(zn,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:x=>l(g=>({...g,ui:{...g.ui,showAgentNames:x}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(nn,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(zn,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:x=>l(g=>({...g,ui:{...g.ui,compactMessages:x}}))})]})]})]})]}),u.jsxs(Zr,{children:[u.jsx(Qr,{className:"pb-3",children:u.jsxs(eo,{className:"text-lg flex items-center gap-2",children:[u.jsx(ie.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(to,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(nn,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(zn,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:x=>l(g=>({...g,behavior:{...g.behavior,autoSave:x}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(nn,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx(zn,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:x=>l(g=>({...g,behavior:{...g.behavior,enableStreaming:x}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(nn,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx(zn,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:x=>l(g=>({...g,behavior:{...g.behavior,showTypingIndicator:x}}))})]})]})]})]}),u.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[u.jsxs(tt,{variant:"outline",onClick:p,children:[u.jsx(ie.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(tt,{variant:"outline",onClick:m,children:"Cancel"}),u.jsxs(tt,{onClick:h,disabled:!c,children:[u.jsx(ie.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function FC({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(jo,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx(Ps,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(jo,{...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(Oa,{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(Ps,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(jo,{...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(Oa,{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(Ps,{onError:s.onError,enableFileUpload:!0})})]})})}Ie.ChatApi=Bl,Ie.ChatInput=cc,Ie.ChatInterface=Ps,Ie.ChatProviders=jo,Ie.ChatSettings=$C,Ie.MarkdownContent=so,Ie.MessageComponent=Ia,Ie.MessageList=Na,Ie.ThreadManager=Oa,Ie.applySettings=WS,Ie.chatApiClient=jn,Ie.default=FC,Ie.del=zl,Ie.get=Yt,Ie.getChatToken=Ll,Ie.getCurrentSettings=US,Ie.getDefaultApiConfig=Rh,Ie.getDefaultChatSettings=Ph,Ie.onChatTokenChanged=$l,Ie.post=si,Ie.put=Fl,Ie.setChatToken=To,Ie.useApi=ii,Ie.useChatStream=Gl,Ie.useMessagesReducer=Yl,Ie.useStream=ac,Ie.useThreadState=Ao,Ie.useThreads=No,Object.defineProperties(Ie,{__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.263",
3
+ "version": "4.3.264",
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",