teodor-new-chat-ui 4.3.338 → 4.3.339
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +1 -1
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -16345,7 +16345,7 @@ const DI = ({
|
|
|
16345
16345
|
const s = e ?? [], i = s.length > 0, a = De(() => i ? [...s].reverse() : [], [s, i]), l = t ?? (s.length ? s[s.length - 1].id : null);
|
|
16346
16346
|
if (!i)
|
|
16347
16347
|
return null;
|
|
16348
|
-
const d = ["w-32 flex-shrink-0 flex-col border-r border-border/40 pr-2 flex", o].filter(Boolean).join(" ");
|
|
16348
|
+
const d = ["w-32 flex-shrink-0 flex-col border-r border-border/40 pr-2 flex bg-white text-gray-900 dark:bg-slate-900 dark:text-slate-100", o].filter(Boolean).join(" ");
|
|
16349
16349
|
return /* @__PURE__ */ u.jsxs("div", { className: d, children: [
|
|
16350
16350
|
/* @__PURE__ */ u.jsxs("div", { className: "relative flex-1 overflow-y-auto pt-4 pb-2 pr-1", children: [
|
|
16351
16351
|
/* @__PURE__ */ u.jsx("div", { className: "absolute left-0 right-0 top-1 px-2 pb-3 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground", children: /* @__PURE__ */ u.jsx("span", { children: "Timeline" }) }),
|
package/dist/index.umd.js
CHANGED
|
@@ -134,4 +134,4 @@ ${t}</tr>
|
|
|
134
134
|
`}strong(t){return`<strong>${t}</strong>`}em(t){return`<em>${t}</em>`}codespan(t){return`<code>${t}</code>`}br(){return this.options.xhtml?"<br/>":"<br>"}del(t){return`<del>${t}</del>`}link(t,n,r){if(t=Qf(this.options.sanitize,this.options.baseUrl,t),t===null)return r;let o='<a href="'+t+'"';return n&&(o+=' title="'+n+'"'),o+=">"+r+"</a>",o}image(t,n,r){if(t=Qf(this.options.sanitize,this.options.baseUrl,t),t===null)return r;let o=`<img src="${t}" alt="${r}"`;return n&&(o+=` title="${n}"`),o+=this.options.xhtml?"/>":">",o}text(t){return t}}class op{strong(t){return t}em(t){return t}codespan(t){return t}del(t){return t}html(t){return t}text(t){return t}link(t,n,r){return""+r}image(t,n,r){return""+r}br(){return""}}class sp{constructor(){this.seen={}}serialize(t){return t.toLowerCase().trim().replace(/<[!\/a-z].*?>/ig,"").replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g,"").replace(/\s/g,"-")}getNextSafeSlug(t,n){let r=t,o=0;if(this.seen.hasOwnProperty(r)){o=this.seen[t];do o++,r=t+"-"+o;while(this.seen.hasOwnProperty(r))}return n||(this.seen[t]=o,this.seen[r]=0),r}slug(t,n={}){const r=this.serialize(t);return this.getNextSafeSlug(r,n.dryrun)}}class Ln{constructor(t){this.options=t||nr,this.options.renderer=this.options.renderer||new _a,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new op,this.slugger=new sp}static parse(t,n){return new Ln(n).parse(t)}static parseInline(t,n){return new Ln(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,c,d,f,p,h,x,m,y,g,b,S,k,C,T;const I=t.length;for(o=0;o<I;o++){if(h=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[h.type]&&(T=this.options.extensions.renderers[h.type].call({parser:this},h),T!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(h.type))){r+=T||"";continue}switch(h.type){case"space":continue;case"hr":{r+=this.renderer.hr();continue}case"heading":{r+=this.renderer.heading(this.parseInline(h.tokens),h.depth,Zf(this.parseInline(h.tokens,this.textRenderer)),this.slugger);continue}case"code":{r+=this.renderer.code(h.text,h.lang,h.escaped);continue}case"table":{for(f="",d="",a=h.header.length,s=0;s<a;s++)d+=this.renderer.tablecell(this.parseInline(h.header[s].tokens),{header:!0,align:h.align[s]});for(f+=this.renderer.tablerow(d),p="",a=h.rows.length,s=0;s<a;s++){for(c=h.rows[s],d="",l=c.length,i=0;i<l;i++)d+=this.renderer.tablecell(this.parseInline(c[i].tokens),{header:!1,align:h.align[i]});p+=this.renderer.tablerow(d)}r+=this.renderer.table(f,p);continue}case"blockquote":{p=this.parse(h.tokens),r+=this.renderer.blockquote(p);continue}case"list":{for(x=h.ordered,m=h.start,y=h.loose,a=h.items.length,p="",s=0;s<a;s++)b=h.items[s],S=b.checked,k=b.task,g="",b.task&&(C=this.renderer.checkbox(S),y?b.tokens.length>0&&b.tokens[0].type==="paragraph"?(b.tokens[0].text=C+" "+b.tokens[0].text,b.tokens[0].tokens&&b.tokens[0].tokens.length>0&&b.tokens[0].tokens[0].type==="text"&&(b.tokens[0].tokens[0].text=C+" "+b.tokens[0].tokens[0].text)):b.tokens.unshift({type:"text",text:C}):g+=C),g+=this.parse(b.tokens,y),p+=this.renderer.listitem(g,k,S);r+=this.renderer.list(p,x,m);continue}case"html":{r+=this.renderer.html(h.text);continue}case"paragraph":{r+=this.renderer.paragraph(this.parseInline(h.tokens));continue}case"text":{for(p=h.tokens?this.parseInline(h.tokens):h.text;o+1<I&&t[o+1].type==="text";)h=t[++o],p+=`
|
|
135
135
|
`+(h.tokens?this.parseInline(h.tokens):h.text);r+=n?this.renderer.paragraph(p):p;continue}default:{const A='Token with "'+h.type+'" type was not found.';if(this.options.silent){console.error(A);return}else throw new Error(A)}}}return r}parseInline(t,n){n=n||this.renderer;let r="",o,s,i;const a=t.length;for(o=0;o<a;o++){if(s=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[s.type]&&(i=this.options.extensions.renderers[s.type].call({parser:this},s),i!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type))){r+=i||"";continue}switch(s.type){case"escape":{r+=n.text(s.text);break}case"html":{r+=n.html(s.text);break}case"link":{r+=n.link(s.href,s.title,this.parseInline(s.tokens,n));break}case"image":{r+=n.image(s.href,s.title,s.text);break}case"strong":{r+=n.strong(this.parseInline(s.tokens,n));break}case"em":{r+=n.em(this.parseInline(s.tokens,n));break}case"codespan":{r+=n.codespan(s.text);break}case"br":{r+=n.br();break}case"del":{r+=n.del(this.parseInline(s.tokens,n));break}case"text":{r+=n.text(s.text);break}default:{const l='Token with "'+s.type+'" type was not found.';if(this.options.silent){console.error(l);return}else throw new Error(l)}}}return r}}class Os{constructor(t){this.options=t||nr}preprocess(t){return t}postprocess(t){return t}}Bh(Os,"passThroughHooks",new Set(["preprocess","postprocess"]));function OS(e,t,n){return r=>{if(r.message+=`
|
|
136
136
|
Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+jt(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 ip(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...me.defaults,...s};const i=OS(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(RS(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(f){return i(f)}const c=function(f){let p;if(!f)try{r.walkTokens&&me.walkTokens(l,r.walkTokens),p=t(l,r),r.hooks&&(p=r.hooks.postprocess(p))}catch(h){f=h}return r.highlight=a,f?i(f):o(null,p)};if(!a||a.length<3||(delete r.highlight,!l.length))return c();let d=0;me.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(p,h){if(p)return c(p);h!=null&&h!==f.text&&(f.text=h,f.escaped=!0),d--,d===0&&c()})},0))}),d===0&&c();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(me.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&&me.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function me(e,t,n){return ip(Dn.lex,Ln.parse)(e,t,n)}me.options=me.setOptions=function(e){return me.defaults={...me.defaults,...e},vS(me.defaults),me},me.getDefaults=Gf,me.defaults=nr,me.use=function(...e){const t=me.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=me.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=me.defaults.renderer||new _a;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=me.defaults.tokenizer||new Na;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=me.defaults.hooks||new Os;for(const s in n.hooks){const i=o[s];Os.passThroughHooks.has(s)?o[s]=a=>{if(me.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=me.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}}me.setOptions(r)})},me.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(me,r)),r.type){case"table":{for(const o of r.header)n=n.concat(me.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(me.walkTokens(s.tokens,t));break}case"list":{n=n.concat(me.walkTokens(r.items,t));break}default:me.defaults.extensions&&me.defaults.extensions.childTokens&&me.defaults.extensions.childTokens[r.type]?me.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(me.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(me.walkTokens(r.tokens,t)))}return n},me.parseInline=ip(Dn.lexInline,Ln.parseInline),me.Parser=Ln,me.parser=Ln.parse,me.Renderer=_a,me.TextRenderer=op,me.Lexer=Dn,me.lexer=Dn.lex,me.Tokenizer=Na,me.Slugger=sp,me.Hooks=Os,me.parse=me,me.options,me.setOptions,me.use,me.walkTokens,me.parseInline,Ln.parse,Dn.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 me.parse=="function"?me.parse(i):me(i)}return typeof me.parse=="function"?me.parse(e):me(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:ne("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 DS={MODE:"library"};function LS(){var i;const e=typeof globalThis<"u"?globalThis.process:void 0,t=typeof((i=e==null?void 0:e.env)==null?void 0:i.NODE_ENV)=="string"?e.env.NODE_ENV:void 0;if(t)return t==="production";const n=typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Ys&&Ys.tagName.toUpperCase()==="SCRIPT"&&Ys.src||new URL("index.umd.js",document.baseURI).href}<"u"?DS:void 0,r=typeof(n==null?void 0:n.MODE)=="string"?n.MODE:void 0,o=typeof(n==null?void 0:n.NODE_ENV)=="string"?n.NODE_ENV:void 0;return(r??o)==="production"}function $S(){return!LS()}function FS(){return typeof window>"u"?!1:window.__ARTIFACT_DEBUG__===!0}function BS(){return $S()||FS()}function zS({preview:e,idx:t}){return w.useEffect(()=>{BS()&&console.debug(`[MessageComponent] Preview ${t} mounted:`,{src:e.src.substring(0,100),alt:e.alt,label:e.label})},[t,e]),u.jsxs("div",{className:"space-y-2",children:[e.label&&u.jsxs("p",{className:"text-[0.65rem] uppercase tracking-wide text-muted-foreground",children:["Artifact: ",e.label]}),u.jsx("div",{className:"overflow-hidden rounded border border-border/60 bg-background/60 p-1 shadow-sm",children:u.jsx("img",{src:e.src,alt:e.alt,title:e.label,loading:"lazy",className:"h-auto max-h-[420px] w-full rounded object-contain",onLoad:()=>{},onError:n=>{console.error(`[MessageComponent] ❌ Image failed to load for artifact ${t}:`,{alt:e.alt,label:e.label,message:n.target.alt})}})})]})}const US="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 ap({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:US,children:u.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>u.jsx("li",{children:String(n)},r))})}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:ro(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:ro(e)})}const io=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:ne("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));io.displayName="Card";const ao=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:ne("flex flex-col space-y-1.5 p-6",e),...t}));ao.displayName="CardHeader";const lo=v.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:ne("text-2xl font-semibold leading-none tracking-tight",e),...t}));lo.displayName="CardTitle";const lp=v.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:ne("text-sm text-muted-foreground",e),...t}));lp.displayName="CardDescription";const co=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:ne("p-6 pt-0",e),...t}));co.displayName="CardContent";const cp=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:ne("flex items-center p-6 pt-0",e),...t}));cp.displayName="CardFooter";function HS({interruptPart:e,onApprove:t,onReject:n,disabled:r,isActive:o,payload:s}){const i=e.title??"Approve the result?";let a=null;if(s!=null)if(typeof s=="string")a=u.jsx("p",{className:"text-sm leading-relaxed text-blue-800/90 dark:text-blue-200/90 whitespace-pre-wrap",children:s});else{const c=ro(s);a=u.jsx("pre",{className:"max-h-48 overflow-auto rounded bg-blue-100/60 p-2 text-xs text-blue-900/90 dark:bg-blue-900/40 dark:text-blue-100/80",children:c})}const l=o?"Please approve or reject this action to resume the workflow.":"Waiting for approval from another participant.";return u.jsxs(io,{className:ne("border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10 transition-shadow",o?"shadow-md ring-1 ring-blue-300 dark:ring-blue-500/70":"opacity-80"),children:[u.jsxs(ao,{className:"pb-3",children:[u.jsx(lo,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(lp,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(co,{className:"pt-0 pb-3",children:a}),u.jsx(cp,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(Xe,{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(Xe,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}function WS(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=Aa(),[o,s]=w.useState({}),[i,a]=w.useState(null),[l,c]=w.useState(!1),d=w.useCallback(()=>{c(!1),a(null)},[]),f=w.useCallback(h=>{a(h),c(!0)},[]),p=w.useCallback(async(h,x,m)=>{var y,g;if(!t){h.preventDefault();return}if(o[m]){h.preventDefault();return}try{const b=String(x.url??""),S=b.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){h.preventDefault();const k=S[1],C=x.name||`file_${k}`,T=x.mimeType||"application/octet-stream";f({id:k,name:C,mimeType:T});return}if(b.startsWith("data:")){h.preventDefault(),s(C=>({...C,[m]:!0}));const k=r({title:"Fetching file...",description:"",open:!0});try{const C=await Q0(n??void 0);if(!C||!Array.isArray(C))throw new Error("Invalid file list response");const T=C.find(I=>!I||typeof I!="object"||!((I.filename??"")===(x.name??""))?!1:typeof x.size=="number"&&typeof I.size=="number"?I.size===x.size:!0);if(!(T!=null&&T.id))throw new Error(`File "${x.name}" is not yet available on the server`);if(!T.id||!T.filename)throw new Error("Invalid file data received from server");f({id:T.id,name:x.name||T.filename||`file_${T.id}`,mimeType:x.mimeType||T.mime_type||"application/octet-stream"}),(y=k.update)==null||y.call(k,{id:k.id,title:"Success",description:`Opened ${x.name}`,open:!0})}catch(C){console.error("Failed to fetch server file:",C);const T=C instanceof Error?C.message:"Unknown error occurred";(g=k.update)==null||g.call(k,{id:k.id,title:"Failed",description:T}),r({title:"Failed to fetch file",description:T,open:!0})}finally{s(C=>({...C,[m]:!1}))}}}catch(b){console.error("File click error:",b),s(S=>({...S,[m]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:p,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function VS({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:ne("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:ne("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(Xe,{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(ae.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(ae.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function KS({message:e,viewMode:t}){const r=bf(e).name||"tool",o=c=>{if(c==null)return null;const d=typeof c=="string"?Sa(c)??c:c;if(d&&typeof d=="object")return u.jsx(ap,{data:d});const f=typeof d=="string"?d:(()=>{try{return ro(d)}catch{return String(d??"")}})();return u.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm text-foreground/90",children:f})},s=c=>{if(c==null)return null;const{content:d,isMarkdown:f}=W0(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(ae.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=Cs(d);return s(f)}const a=no(i),l=Cs(a);return s(l)}function qS({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:ne("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const Ds=w.memo(function({message:t,messageIndex:n,isStreamingMessage:r=!1,isEditing:o=!1,showActions:s=!0,showTimestamp:i=!0,showAgentName:a=!0,layoutSize:l="desktop",truncateUserMessages:c=!0,userMessagePreviewLength:d=500,showToolMessages:f=!0,showArtifactPreviews:p=!0,customStyles:h={},onEdit:x,onRegenerate:m,onCancelEdit:y,onCopy:g,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,checkpointCandidates:T=[],activeCheckpointId:I=null,onSelectCheckpoint:A,defaultCheckpointId:R=null,messageParentCheckpointId:L=null}){const[P,D]=w.useState(!1),[F,N]=w.useState("preview"),[B,j]=w.useState(!1),{currentThreadId:V}=_o(),{respondToInterrupt:z}=jo(),M=l==="phone"||l==="half-screen",q=t.role,J=q==="tool",se=w.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),ge=!!se,Ee=!(r&&q!=="user"),{uploadingFiles:Y,handleFileClick:U,fileViewerOpen:Z,currentFileInfo:$,closeFileViewer:K}=WS({allowFileOpen:Ee,currentThreadId:V}),Q=w.useMemo(()=>{switch(q){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))]"}},[q]),ce=w.useMemo(()=>{if(se)return"";const _=t.content;return Array.isArray(_)?V0(_):""},[se,t]),oe=w.useMemo(()=>{if(se)return{};const _=t.content;return Array.isArray(_)?bf(t):{}},[se,t]),Ne=w.useMemo(()=>{if(se)return[];const _=t.content;return Array.isArray(_)?_.filter(X=>X.type==="image_url"):[]},[se,t]),Ue=w.useMemo(()=>{if(se)return[];const _=t.content;return Array.isArray(_)?_.filter(X=>X.type==="file"):[]},[se,t]),re=w.useMemo(()=>{if(se)return[];const _=t.content;return Array.isArray(_)?_.filter(X=>X.type==="interrupt"):[]},[se,t]),xe=(b==null?void 0:b.id)??(b==null?void 0:b.interrupt_id),Pe=Ts(xe),Ze=b==null?void 0:b.value,Qe=w.useMemo(()=>{if(se)return"";const _=t.content;return Array.isArray(_)?K0(_):""},[se,t]),Ve=w.useMemo(()=>{if(se||!p)return[];const X=t.artifact;if(!X)return[];const te=[],pe=[...Array.isArray(X.plots)?X.plots:[]];for(const ve of pe){const we=J0(ve);we&&te.push(we)}return te},[se,t,p]),tt=w.useCallback(async()=>{const _=J?Qe:ce;async function X(te){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(te);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const pe=new Blob([te],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":pe})]);return}throw new Error("Clipboard API not supported in this context.")}try{await X(_),D(!0),setTimeout(()=>D(!1),2e3),g==null||g(_)}catch(te){console.error("Failed to copy:",te)}},[J,Qe,ce,g]),it=w.useCallback(()=>{if(!x)return;const _=J?Qe:ce,X="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};x(t.id,_,X)},[x,t.id,J,Qe,ce,t]),qe=w.useCallback(()=>{m==null||m(n)},[m,n]),nt=w.useCallback(()=>{const X=ne(M?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",Q);switch(q){case"user":return u.jsx(ae.User,{className:X});case"assistant":return u.jsx(ae.Bot,{className:X});case"tool":return u.jsx(ae.Wrench,{className:X});default:return u.jsx(ae.Bot,{className:X})}},[M,Q,q]),at=w.useCallback(()=>{const _="group relative mb-4 flex w-full";switch(q){case"user":return ne(_,"justify-end");case"assistant":case"tool":case"system":return ne(_,"justify-start");default:return _}},[q]),Rt=w.useCallback(()=>{const _=ne("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",M&&"px-3 py-2 text-sm");if(ge)return ne(_,"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(q){case"user":return ne(_,"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 ne(_,"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 ne(_,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return ne(_,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return ne(_,"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")}},[M,ge,q]),gt=w.useCallback(async _=>{if(S)return;const X=Ts((_==null?void 0:_.id)??(_==null?void 0:_.interrupt_id));if(!X){console.warn("Interrupt part missing id",_);return}try{k==null||k(),await z(X,!0)}catch(te){console.error("Failed to approve interrupt:",te)}finally{C==null||C()}},[S,C,k,z]),ht=w.useCallback(async _=>{if(S)return;const X=Ts((_==null?void 0:_.id)??(_==null?void 0:_.interrupt_id));if(!X){console.warn("Interrupt part missing id",_);return}try{k==null||k(),await z(X,!1)}catch(te){console.error("Failed to reject interrupt:",te)}finally{C==null||C()}},[S,C,k,z]),bt=w.useCallback(({part:_,i:X})=>{if(_.type==="text"){const te=_.text??"",pe=te.trim(),ve=Sa(pe);return ve&&q!=="tool"?u.jsx(ap,{data:ve},X):q==="user"&&c&&pe.length>d?u.jsx(VS,{text:pe,expanded:B,onExpandedChange:j,previewLength:d,isCompact:M},X):u.jsx(so,{content:te,allowHtml:!1},X)}if(_.type==="image_url"){const te=_;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:te.url,alt:te.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},X)}if(_.type==="file"){const te=_,pe=te.name||"file";return u.jsxs("a",{href:te.url,onClick:ve=>U(ve.nativeEvent,te,X),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:[Y[X]?u.jsx(ae.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[pe,Y[X]?" (processing)":""]})]},X)}if(_.type==="interrupt"){const te=_,pe=Ts((te==null?void 0:te.id)??(te==null?void 0:te.interrupt_id)),ve=!!(Pe&&pe&&pe===Pe),we=ve?Ze??(te==null?void 0:te.value):te==null?void 0:te.value,Fe=pe?{...te,id:pe,interrupt_id:pe}:te;return u.jsx(HS,{interruptPart:Fe,onApprove:gt,onReject:ht,disabled:S,isActive:ve,payload:we},X)}return null},[U,Y,gt,ht,q,c,d,B,M,Pe,Ze,b,S,re]),St=w.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(ae.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),Lt=w.useCallback(()=>{const _=ce.trim().length>0||Ne.length>0||Ue.length>0||re.length>0;if(!J&&Ue.length>0&&!r)return St();if(!J&&!_&&!r)return null;if(J)return!f&&Ve.length>0?null:f?u.jsx(KS,{message:t,viewMode:F},t.id):null;if(!J&&!se){const X=t,te=u.jsx("div",{className:"space-y-2",children:X.content.map((pe,ve)=>u.jsx(bt,{part:pe,i:ve},ve))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[te,u.jsx(qS,{className:Q})]}):te}},[ce,Ne.length,Ue.length,re.length,r,J,F,f,Ve.length,St,Q]),Mt=w.useMemo(()=>se?"Assistant":q0(t),[se,t]),et=w.useMemo(()=>se?[]:Array.isArray(T)?T:[],[T,se]),It=w.useMemo(()=>{var _;return et.length?R&&et.some(X=>X.id===R)?R:((_=et[0])==null?void 0:_.id)??null:null},[R,et]),Ge=w.useMemo(()=>!et.length||!I?null:et.some(_=>_.id===I)?I:null,[I,et])??It,Ye=q==="user"&&et.length>0&&typeof A=="function",pt=w.useCallback((_,X=!1)=>{if(!A)return;const te=(_==null?void 0:_.id)??null,pe=(_==null?void 0:_.parentId)??L??null;A(te,pe,X)},[L,A]),lt=w.useMemo(()=>Ge?et.findIndex(_=>_.id===Ge):-1,[Ge,et]),G=w.useMemo(()=>lt<0?null:et[lt]??null,[lt,et]);return J&&!f&&Ve.length===0?null:ge&&se?u.jsx("div",{className:ne(at(),h.container),children:u.jsxs("div",{className:ne(Rt(),h.content),children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2 pb-2 border-b border-current/10",children:[u.jsx(ae.Bot,{className:ne("h-4 w-4",Q)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(so,{content:se.content,className:"text-current"})]})}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:ne(at(),h.container),children:u.jsxs("div",{className:ne(Rt(),h.content),children:[(i||a||J)&&u.jsxs("div",{className:ne("flex items-center justify-between mb-2 pb-2 border-b border-current/10",M&&"mb-1 pb-1",Q,h.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[nt(),a&&Mt&&u.jsx("span",{className:ne("font-medium",M?"text-xs":"text-sm"),children:Mt}),J&&u.jsxs(yf,{variant:"outline",className:ne("text-xs flex items-center gap-1 cursor-pointer select-none",Q,"border border-current/40",M&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":F==="expanded",onClick:()=>N(_=>_==="expanded"?"preview":"expanded"),onKeyDown:_=>{(_.key==="Enter"||_.key===" ")&&(_.preventDefault(),N(X=>X==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:oe.name??"Tool Output"}),oe.toolCallId&&u.jsx("span",{className:"opacity-70",children:oe.toolCallId.slice(0,8)}),F==="expanded"?u.jsx(ae.ChevronUp,{className:"h-3 w-3"}):u.jsx(ae.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[Ye&&G&<>=0&&u.jsx("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("button",{type:"button",className:ne("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",lt<et.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(lt>=et.length-1)return;const _=et[lt+1];_&&pt(_)},"aria-label":"Older checkpoint (back in time)",disabled:lt>=et.length-1,children:u.jsx(ae.ChevronLeft,{className:"h-3 w-3"})}),u.jsx("div",{className:"flex items-center gap-2",children:u.jsxs("span",{className:"whitespace-nowrap",children:[et.length-lt," / ",et.length]})}),u.jsx("button",{type:"button",className:ne("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",lt>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(!(lt<=0))if(lt===1)pt(null,!0);else{const _=et[lt-1];_&&pt(_,!1)}},"aria-label":"Newer checkpoint (forward in time)",disabled:lt<=0,children:u.jsx(ae.ChevronRight,{className:"h-3 w-3"})})]})}),i&&t.createdAt&&u.jsx("time",{className:ne("text-xs opacity-60",Q,M&&"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:ne("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>tt(),className:ne("h-6 w-6 p-0 hover:bg-foreground/10",Q,M&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(ae.Copy,{className:ne(P?"text-success":Q,M?"h-3 w-3":"h-4 w-4")})})}),q==="user"&&x&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:it,className:ne("h-6 w-6 p-0 hover:bg-foreground/10",Q,M&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(ae.Edit,{className:ne(Q,M?"h-3 w-3":"h-4 w-4")})}),q==="assistant"&&m&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:qe,className:ne("h-6 w-6 p-0 hover:bg-foreground/10",Q,M&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(ae.RotateCcw,{className:ne(Q,M?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsxs("div",{className:"relative",children:[Lt(),p&&Ve.length>0&&u.jsx("div",{className:"mt-3 space-y-4",children:Ve.map((_,X)=>u.jsx(zS,{preview:_,idx:X},`artifact-${X}`))})]}),J&&F==="expanded"&&(oe.toolCallId||oe.name)&&u.jsxs("div",{className:ne("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",M&&"text-xs"),children:[oe.name&&u.jsxs("div",{children:["Function: ",oe.name]}),oe.toolCallId&&u.jsxs("div",{children:["Call ID: ",oe.toolCallId]})]}),!(i||a||J)&&s&&!o&&u.jsxs("div",{className:ne("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>tt(),className:ne("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(ae.Copy,{className:ne(P?"text-success":"text-current",M?"h-3 w-3":"h-4 w-4")})}),q==="user"&&x&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:it,className:ne("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(ae.Edit,{className:ne("text-current",M?"h-3 w-3":"h-4 w-4")})}),q==="assistant"&&m&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:qe,className:ne("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(ae.RotateCcw,{className:ne("text-current",M?"h-3 w-3":"h-4 w-4")})})]})]})}),$&&u.jsx(yS,{isOpen:Z,onClose:K,fileId:$.id,fileName:$.name,mimeType:$.mimeType})]})},(e,t)=>{var i,a,l,c,d,f,p,h;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&wf(e.message)===wf(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages","attemptMeta"].every(x=>e[x]===t[x]),s=((i=e.customStyles)==null?void 0:i.container)===((a=t.customStyles)==null?void 0:a.container)&&((l=e.customStyles)==null?void 0:l.content)===((c=t.customStyles)==null?void 0:c.content)&&((d=e.customStyles)==null?void 0:d.actions)===((f=t.customStyles)==null?void 0:f.actions)&&((p=e.customStyles)==null?void 0:p.header)===((h=t.customStyles)==null?void 0:h.header);return o&&s});Ds.displayName="MessageComponent";function GS(e,t){return w.useMemo(()=>{var d,f,p,h,x;const n=e&&"type"in e&&e.type==="default_message";let r=[],o=null,s={},i={},a=null,l=null,c=null;if(!n&&e){const m=e,y=m.checkpointId??null;s=m.additionalKwargs??{},i=m.responseMetadata??{};const g=y&&t.checkpointMetaById?t.checkpointMetaById.get(y)??null:null;a=typeof s.step=="number"?s.step:typeof i.step=="number"?i.step:(g==null?void 0:g.step)??null;const b=typeof s.source=="string"?s.source:typeof i.source=="string"?i.source:(g==null?void 0:g.source)??null;l=b?String(b):null;const S=a!==null&&l?`${a}:${l}`:null;if(S&&((d=t.checkpointIndexByKey)!=null&&d.has(S))?r=t.checkpointIndexByKey.get(S)??[]:y&&g&&(r=[g]),o=y??((f=r[0])==null?void 0:f.id)??null,c=y?((p=t.attemptMetaById)==null?void 0:p.get(y))??null:null,!c&&(e==null?void 0:e.role)==="user"&&(e!=null&&e.id)&&t.userMessageIdToAttempts){const k=t.userMessageIdToAttempts.get(e.id);if(k&&k.length>0){const C=k[0].checkpointId;c=((h=t.attemptMetaById)==null?void 0:h.get(C))??null,c&&console.log(`[useMessageMetadata] Found attempt by user message ID "${e.id}":`,k.length,"versions")}}if(!c&&r.length>0&&t.attemptMetaById){const k=t.attemptMetaById.get(r[0].id);k&&(c=k)}if(c&&c.attemptCount>1&&t.attemptMetaById){const k=c.baseUserMessageId;if(k){const C=[];for(const[T,I]of t.attemptMetaById.entries())if(I.baseUserMessageId===k){const A=(x=t.checkpointMetaById)==null?void 0:x.get(T);A&&C.push(A)}C.length>0&&(r=C)}}if(c&&c.attemptCount>1&&t.checkpointMetaById&&t.attemptMetaById){const k=[];for(const[C,T]of t.checkpointMetaById.entries()){const I=t.attemptMetaById.get(C);I&&I.attemptCount===c.attemptCount&&I.baseUserMessageId===c.baseUserMessageId&&k.push(T)}k.sort((C,T)=>{const I=C.createdAt?Date.parse(C.createdAt):0;return(T.createdAt?Date.parse(T.createdAt):0)-I}),k.length>0&&(r=k,console.log("[useMessageMetadata] Populated checkpointCandidates with all attempts:",{messageId:e.id,attemptCount:c.attemptCount,candidateIds:r.map(C=>C.id)}))}}return{checkpointCandidates:r,defaultCheckpointId:o,attemptMeta:c,resolvedStep:a,resolvedSource:l}},[e,t.checkpointMetaById,t.checkpointIndexByKey,t.attemptMetaById,t.userMessageIdToAttempts])}const up=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,dp=w.memo(function({message:t,index:n,isStreaming:r,streamingAssistantId:o,streamingDebounceMs:s,layoutSize:i,enableMessageEditing:a,editingMessageId:l,onEdit:c,onRegenerate:d,onCancelEdit:f,activeInterrupt:p,disableInterruptActions:h,onInterruptActionStart:x,onInterruptActionEnd:m,showToolMessages:y,showArtifactPreviews:g,checkpointMetaById:b,checkpointIndexByKey:S,attemptMetaById:k,userMessageIdToAttempts:C,activeCheckpointId:T,onSelectCheckpoint:I}){const A=up(t,n),R="type"in t&&t.type==="default_message",{checkpointCandidates:L,defaultCheckpointId:P,attemptMeta:D}=GS(t,{checkpointMetaById:b,checkpointIndexByKey:S,attemptMetaById:k,userMessageIdToAttempts:C}),F=t&&!R?t.additionalKwargs??{}:{},N=t&&!R?t.responseMetadata??{}:{},B=(()=>{if(typeof F.parentCheckpointId=="string")return F.parentCheckpointId;if(typeof N.parentCheckpointId=="string")return N.parentCheckpointId})();return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":A,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Ds,{message:t,messageIndex:n,isStreamingMessage:r&&o===t.id,streamingDebounceMs:s,isEditing:l===t.id,showActions:a,showTimestamp:!1,showAgentName:!0,layoutSize:i,onEdit:c,onRegenerate:()=>d(n),onCancelEdit:f,activeInterrupt:p,disableInterruptActions:h,onInterruptActionStart:x,onInterruptActionEnd:m,showToolMessages:y,showArtifactPreviews:g,checkpointCandidates:L,activeCheckpointId:T??null,onSelectCheckpoint:I,defaultCheckpointId:P,messageParentCheckpointId:B,attemptMeta:D})})});dp.displayName="MessageRow";const ja=w.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:c,onCancelEdit:d,className:f,style:p,emptyMessage:h,followNewMessages:x=!0,isNavigatingCheckpoint:m=!1,onScrollAway:y,onAtBottom:g,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T=!0,showArtifactPreviews:I=!0,checkpointMetaById:A,checkpointIndexByKey:R,attemptMetaById:L,userMessageIdToAttempts:P,activeCheckpointId:D,onSelectCheckpoint:F,createSyntheticThinkingMessage:N=!1},B)=>{const j=w.useRef(null),V=w.useRef(null),z=w.useRef(!1),M=w.useRef(!1),[q,J]=w.useState(!0),se=w.useMemo(()=>b?e.some(re=>"type"in re&&re.type==="default_message"?!1:Array.isArray(re==null?void 0:re.content)&&re.content.some(xe=>xe&&xe.type==="interrupt"&&(xe.id??xe.interrupt_id)===b.id)):!1,[b,e]),ge=w.useMemo(()=>{if(!b||se)return null;const re=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let xe;const Pe=b.value;if(Pe&&typeof Pe=="object"&&!Array.isArray(Pe)){const Ze=Pe.title;typeof Ze=="string"&&Ze.trim()&&(xe=Ze.trim())}return{id:`interrupt-${re}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:re,value:Pe,title:xe}]}},[b,se]),Ee=w.useMemo(()=>ge?[...e,ge]:e,[e,ge]),Y=w.useMemo(()=>!N||!t?Ee:!Ee.some(xe=>xe.role==="assistant")&&Ee.length>0?[...Ee,{id:"thinking-assistant",role:"assistant",content:[],createdAt:new Date().toISOString()}]:Ee,[Ee,t,N]),U=w.useMemo(()=>T?Y:Y.filter(re=>(re==null?void 0:re.role)!=="tool"),[Y,T]),Z=w.useCallback(re=>{J(re),y&&y(!re),g&&g(re)},[y,g]),$=w.useMemo(()=>{if(a)return async()=>{if(!z.current){z.current=!0;try{await a()}finally{z.current=!1}}}},[a]),K=w.useMemo(()=>!x||m?!1:q?"auto":!1,[q,x,m]),Q=w.useMemo(()=>{if(typeof h!="string")return null;const re=h.trim();return re?{id:"default-message",role:"assistant",type:"default_message",content:re,createdAt:new Date().toISOString()}:null},[h]),ce=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),oe=()=>Q?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Ds,{message:Q,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{},showArtifactPreviews:I})})}):u.jsx("div",{className:"flex h-full items-center justify-center py-8 text-center text-muted-foreground",children:h??"No messages yet. Start a conversation!"}),Ne=U.length,Ue=Ne>0;return w.useEffect(()=>{var re,xe;if(Ne===0){M.current=!1;return}M.current||(M.current=!0,j.current?(xe=(re=j.current).scrollToIndex)==null||xe.call(re,{index:0,align:"start",behavior:"auto"}):V.current&&(V.current.scrollTop=0))},[Ne]),w.useImperativeHandle(B,()=>({scrollToLatest:()=>{var re,xe;if(j.current&&U.length>0){const Pe=U.length-1;(xe=(re=j.current).scrollToIndex)==null||xe.call(re,{index:Pe,align:"end",behavior:"auto"})}else V.current&&(V.current.scrollTop=V.current.scrollHeight)},scrollToTop:()=>{var re,xe;j.current&&U.length>0?(xe=(re=j.current).scrollToIndex)==null||xe.call(re,{index:0,align:"start",behavior:"auto"}):V.current&&(V.current.scrollTop=0)}}),[U]),u.jsx("div",{className:ce,style:p,children:u.jsx("div",{className:"relative flex-1 min-h-0",children:Ue?u.jsx(E0,{ref:re=>{j.current=re},scrollerRef:re=>{V.current=re instanceof HTMLDivElement?re:null},data:U,followOutput:K,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,startReached:()=>{$&&$()},atBottomStateChange:Z,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(re,xe)=>up(xe,re),itemContent:(re,xe)=>u.jsx(dp,{message:xe,index:re,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onEdit:l,onRegenerate:c,onCancelEdit:d,activeInterrupt:b,disableInterruptActions:S,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T,showArtifactPreviews:I,checkpointMetaById:A,checkpointIndexByKey:R,attemptMetaById:L,userMessageIdToAttempts:P,activeCheckpointId:D,onSelectCheckpoint:F})}):oe()})})});ja.displayName="MessageList";const fp={value:""};function Ls({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:c=!0,showToolMessages:d=!0,showArtifactPreviews:f=!0,customStyles:p={},onMessageSent:h,onExcelUploadSuccess:x,onError:m}){const{api:y}=ui(),{currentThreadId:g}=_o(),{threadId:b,messages:S,isHistoryLoading:k,isLoading:C,navigateToCheckpoint:T,returnToLatest:I,checkpoint:A,checkpoints:R,interrupt:L,metadata:P,timelineCheckpoints:D,messagePreviews:F}=jo(),{isStreaming:N,error:B,connectionState:j,submit:V,stop:z}=ac(),M=b??g??null,q=(A==null?void 0:A.id)??null,J=(A==null?void 0:A.namespace)??null,se=(P==null?void 0:P.assemblingMessageId)??null,ge=L,[Ee,Y]=w.useState(!1);w.useEffect(()=>{ge||Y(!1)},[ge]);const U=w.useCallback(()=>{Y(!0)},[]),Z=w.useCallback(()=>{Y(!1)},[]),$=!!ge||Ee,[K,Q]=w.useState(null),[ce,oe]=w.useState(""),[Ne,Ue]=w.useState(null),[re,xe]=w.useState(null),[Pe,Ze]=w.useState([]),[Qe,Ve]=w.useState(0),[tt,it]=w.useState(0),[qe,nt]=w.useState(!1),[at,Rt]=w.useState(null),[gt,ht]=w.useState(null),[bt,St]=w.useState(!1),[Lt,Mt]=w.useState(null),et=w.useRef(!1),[It,bn]=w.useState(()=>fp.value),Ge=w.useRef(It),Ye=w.useRef(null),pt=w.useCallback(fe=>{fp.value=fe,bn(fe)},[]),[lt,G]=w.useState(!1),_=w.useRef(null),{checkpointMetaById:X,checkpointIndexByKey:te,attemptMetaById:pe,userMessageIdToAttempts:ve}=hw(R),we=D??[],Fe=w.useRef(null),Oe=w.useRef(null),je=w.useCallback(()=>{Fe.current&&(Fe.current.value=""),Oe.current&&(Oe.current.value=""),Ve(fe=>fe+1),it(fe=>fe+1)},[]),Vt=w.useCallback(fe=>{pt(fe)},[pt]),En=w.useRef(!1);w.useEffect(()=>{En.current&&!N&&(Ze([]),je()),En.current=N},[N,je]);const[ir,Ar]=w.useState("desktop");w.useEffect(()=>{const fe=()=>{const Se=window.innerWidth;Ar(Se<640?"phone":Se<1024?"tablet":"desktop")};return fe(),window.addEventListener("resize",fe),()=>window.removeEventListener("resize",fe)},[]),w.useEffect(()=>{et.current=!1},[M]),w.useEffect(()=>{Ge.current=It},[It]),w.useEffect(()=>{if(!K){Ye.current=null;return}Ye.current===null&&(Ye.current=Ge.current),pt(ce??"")},[ce,K,pt]),w.useEffect(()=>{(async()=>{if(!y.baseUrl){Mt(null);return}try{const Ie=(await y.getAgent("default")).uiDefaultMessage||"";Mt(Ie||null)}catch(Se){console.warn("Failed to fetch default message:",Se),Mt(null)}})()},[y.baseUrl]),w.useEffect(()=>{B&&!bt&&(m==null||m(B))},[B,bt,m]);const fo=fe=>{if(fe.length>cs)return`Message too long (${fe.length}/${cs} characters)`;try{return xw(fe),null}catch(Se){return(Se==null?void 0:Se.message)||"Invalid message"}},zn=async fe=>{const Se=fe.trim();if(!(!Se&&Pe.length===0)){if(Se){const Ie=fo(Se);if(Ie){xe(Ie);return}}try{const Ie=K?(Ne==null?void 0:Ne.checkpointId)??q??void 0:q??void 0,He=K?(Ne==null?void 0:Ne.checkpointNs)??J??void 0:J??void 0;await V({text:Se||"",attachments:Pe},{checkpointId:Ie,checkpointNs:He,edit:!!K,originalMessageId:K??void 0}),h==null||h(Se),pt(""),xe(null),Ze([]),je(),Q(null),oe(""),Ue(null)}catch(Ie){const He=(Ie==null?void 0:Ie.message)||"Failed to send message";xe(He),m==null||m(He)}}},ar=w.useCallback((fe,Se,Ie)=>{c&&(Ye.current=It,Q(fe),oe(Se),pt(Se),xe(null),Ue({checkpointId:(Ie==null?void 0:Ie.checkpointId)??null,checkpointNs:(Ie==null?void 0:Ie.checkpointNs)??null}))},[It,c,pt]),E=w.useCallback(()=>{Q(null),oe(""),Ue(null),xe(null),pt(Ye.current??It),Ye.current=null},[It,pt]),W=w.useCallback((fe,Se,Ie)=>{ar(fe,Se,Ie)},[ar]),ie=w.useCallback(fe=>{let Se=null;for(let tn=fe-1;tn>=0;tn--)if(S[tn].role==="user"){Se=S[tn];break}if(!Se)return;const Ie=Array.isArray(Se.content)?Se.content:[],Un=Ie.filter(tn=>(tn==null?void 0:tn.type)==="text").map(tn=>tn.text).join("")||(()=>{try{return JSON.stringify(Ie,null,2)}catch{return String(Ie)}})();Un&&V({text:Un},{checkpointId:q??void 0,checkpointNs:J??void 0,edit:!0,originalMessageId:Se.id})},[S,V,q,J]),be=fe=>{const Se=Array.from(fe.target.files||[]);Ze(Ie=>[...Ie,...Se]),fe.target.value=""},Ke=fe=>{Ze(Se=>{const Ie=Se.filter((He,Un)=>fe!==Un);return Ie.length===0&&je(),Ie})},rt=async fe=>{const Se=(fe.target.files||[])[0];if(Se){Rt(null),ht(null),nt(!0);try{await V({attachments:[Se]},{checkpointId:q??void 0,checkpointNs:J??void 0});const Ie=`Uploaded ${Se.name} - processing through chat stream`;ht(Ie)}catch(Ie){const He=Ie instanceof Error?Ie.message:"Failed to upload Excel file";console.error("Excel upload failed",Ie),Rt(He),m==null||m(He)}finally{nt(!1),fe.target.value="",je()}}},$e=async fe=>{if(g){G(!0);try{if(!fe){await I(),requestAnimationFrame(()=>{var He;(He=_.current)==null||He.scrollToLatest()});return}const Se=R.find(He=>He.checkpointId===fe),Ie=(Se==null?void 0:Se.checkpointNs)??null;await T(fe,Ie),requestAnimationFrame(()=>{var He;(He=_.current)==null||He.scrollToTop()})}finally{G(!1)}}},Le=w.useCallback(async(fe,Se,Ie)=>{await $e(Ie?null:fe)},[$e]),Et=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${p.container||""}`,mt=`flex-1 min-h-0 min-w-0 max-h-full w-full overflow-hidden overscroll-contain break-words break-anywhere p-4 bg-transparent ${p.messagesArea||""}`,xt=`relative flex-shrink-0 w-full border-t p-4 bg-transparent ${p.inputArea||""}`;return u.jsxs("div",{className:Et,children:[!!B&&!bt&&u.jsxs("div",{className:"flex-shrink-0 bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[u.jsx("span",{children:B}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>St(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(ae.X,{size:16})})]}),u.jsxs("div",{className:`relative ${mt}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(ja,{ref:_,className:"h-full",style:{height:"100%"},messages:S,isStreaming:N,streamingAssistantId:se,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:ir,enableMessageEditing:c,editingMessageId:K,onEdit:W,onRegenerate:ie,onCancelEdit:E,emptyMessage:Lt??void 0,isNavigatingCheckpoint:lt,activeInterrupt:ge,disableInterruptActions:Ee,onInterruptActionStart:U,onInterruptActionEnd:Z,showToolMessages:d,showArtifactPreviews:f,checkpointMetaById:X,checkpointIndexByKey:te,attemptMetaById:pe,userMessageIdToAttempts:ve,activeCheckpointId:q,onSelectCheckpoint:Le,timelineCheckpoints:we,messagePreviews:F}),(j==="reconnecting"||j==="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(ae.Loader2,{className:"h-3 w-3 animate-spin"}),j==="reconnecting"?"Reconnecting…":"Connecting…"]})}),j==="error"&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-destructive/10 px-3 py-1 text-xs font-semibold text-destructive shadow-sm",children:"Connection lost"}),C&&u.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[u.jsx(ae.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(ae.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading checkpoint…"})]})]}),u.jsxs("div",{className:xt,children:[K&&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(ae.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:E,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(ae.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:Fe,type:"file",multiple:!0,onChange:fe=>be(fe),className:"hidden"},Qe),Pe.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:Pe.map((fe,Se)=>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(ae.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:fe.name}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>Ke(Se),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 ${fe.name}`,children:u.jsx(ae.X,{size:12})})]},Se))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:Oe,type:"file",accept:".xls,.xlsx,.xlsm",onChange:rt,className:"hidden"},tt),qe&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(ae.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),gt&&!qe&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:gt}),at&&!qe&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:at})]})]}),re&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:re}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(ew,{children:[u.jsx(tw,{asChild:!0,children:u.jsx(Xe,{type:"button",size:"icon",variant:"outline",disabled:N||$,title:"More input actions",className:p.moreButton||"",children:u.jsx(ae.Plus,{size:16})})}),u.jsxs(yd,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(Zi,{onClick:()=>{var fe;return(fe=Fe.current)==null?void 0:fe.click()},className:"cursor-pointer",children:[u.jsx(ae.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(Zi,{onClick:()=>{var fe;qe||(fe=Oe.current)==null||fe.click()},className:`cursor-pointer ${qe?"opacity-60 pointer-events-none":""}`,children:[u.jsx(ae.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(tx,{initialValue:ce,editingMessageId:K,value:It,onValueChange:Vt,placeholder:K?"Edit your message...":t,isStreaming:N,disabled:$,maxLength:cs,onSend:zn,onCancelEdit:E,onStop:z,allowEmptySend:Pe.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${K?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${re?"border-red-400":""} ${p.textarea||""}`})})]})]})]})}const $s=v.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:ne("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}));$s.displayName="Input";function Ra(e,[t,n]){return Math.min(n,Math.max(t,e))}function YS(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Ma="ScrollArea",[pp,FT]=Sn(Ma),[XS,Qt]=pp(Ma),hp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=v.useState(null),[c,d]=v.useState(null),[f,p]=v.useState(null),[h,x]=v.useState(null),[m,y]=v.useState(null),[g,b]=v.useState(0),[S,k]=v.useState(0),[C,T]=v.useState(!1),[I,A]=v.useState(!1),R=Be(t,P=>l(P)),L=Mo(o);return u.jsx(XS,{scope:n,type:r,dir:L,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:p,scrollbarX:h,onScrollbarXChange:x,scrollbarXEnabled:C,onScrollbarXEnabledChange:T,scrollbarY:m,onScrollbarYChange:y,scrollbarYEnabled:I,onScrollbarYEnabledChange:A,onCornerWidthChange:b,onCornerHeightChange:k,children:u.jsx(_e.div,{dir:L,...i,ref:R,style:{position:"relative","--radix-scroll-area-corner-width":g+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});hp.displayName=Ma;var mp="ScrollAreaViewport",gp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=Qt(mp,n),a=v.useRef(null),l=Be(t,a,i.onViewportChange);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:o}),u.jsx(_e.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:u.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});gp.displayName=mp;var vn="ScrollAreaScrollbar",Pa=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Qt(vn,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(JS,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(ZS,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(xp,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Oa,{...r,ref:t}):null});Pa.displayName=vn;var JS=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Qt(vn,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(Yt,{present:n||s,children:u.jsx(xp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),ZS=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Qt(vn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Us(()=>l("SCROLL_END"),100),[a,l]=YS("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return v.useEffect(()=>{if(a==="idle"){const c=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[a,o.scrollHideDelay,l]),v.useEffect(()=>{const c=o.viewport,d=s?"scrollLeft":"scrollTop";if(c){let f=c[d];const p=()=>{const h=c[d];f!==h&&(l("SCROLL"),i()),f=h};return c.addEventListener("scroll",p),()=>c.removeEventListener("scroll",p)}},[o.viewport,s,l,i]),u.jsx(Yt,{present:n||a!=="hidden",children:u.jsx(Oa,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:de(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:de(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),xp=v.forwardRef((e,t)=>{const n=Qt(vn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=v.useState(!1),a=e.orientation==="horizontal",l=Us(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return kr(n.viewport,l),kr(n.content,l),u.jsx(Yt,{present:r||s,children:u.jsx(Oa,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Oa=v.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=Qt(vn,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=Sp(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:c>0&&c<1,onThumbChange:p=>s.current=p,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:p=>i.current=p};function f(p,h){return oC(p,i.current,a,h)}return n==="horizontal"?u.jsx(QS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollLeft,h=Cp(p,a,o.dir);s.current.style.transform=`translate3d(${h}px, 0, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollLeft=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollLeft=f(p,o.dir))}}):n==="vertical"?u.jsx(eC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollTop,h=Cp(p,a);s.current.style.transform=`translate3d(0, ${h}px, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollTop=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollTop=f(p))}}):null}),QS=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Qt(vn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=Be(t,l,s.onScrollbarXChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(vp,{"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":zs(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const p=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(p),kp(p,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:Bs(i.paddingLeft),paddingEnd:Bs(i.paddingRight)}})}})}),eC=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Qt(vn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=Be(t,l,s.onScrollbarYChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(vp,{"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":zs(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const p=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(p),kp(p,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:Bs(i.paddingTop),paddingEnd:Bs(i.paddingBottom)}})}})}),[tC,yp]=pp(vn),vp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:c,onWheelScroll:d,onResize:f,...p}=e,h=Qt(vn,n),[x,m]=v.useState(null),y=Be(t,R=>m(R)),g=v.useRef(null),b=v.useRef(""),S=h.viewport,k=r.content-r.viewport,C=kt(d),T=kt(l),I=Us(f,10);function A(R){if(g.current){const L=R.clientX-g.current.left,P=R.clientY-g.current.top;c({x:L,y:P})}}return v.useEffect(()=>{const R=L=>{const P=L.target;(x==null?void 0:x.contains(P))&&C(L,k)};return document.addEventListener("wheel",R,{passive:!1}),()=>document.removeEventListener("wheel",R,{passive:!1})},[S,x,k,C]),v.useEffect(T,[r,T]),kr(x,I),kr(h.content,I),u.jsx(tC,{scope:n,scrollbar:x,hasThumb:o,onThumbChange:kt(s),onThumbPointerUp:kt(i),onThumbPositionChange:T,onThumbPointerDown:kt(a),children:u.jsx(_e.div,{...p,ref:y,style:{position:"absolute",...p.style},onPointerDown:de(e.onPointerDown,R=>{R.button===0&&(R.target.setPointerCapture(R.pointerId),g.current=x.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",h.viewport&&(h.viewport.style.scrollBehavior="auto"),A(R))}),onPointerMove:de(e.onPointerMove,A),onPointerUp:de(e.onPointerUp,R=>{const L=R.target;L.hasPointerCapture(R.pointerId)&&L.releasePointerCapture(R.pointerId),document.body.style.webkitUserSelect=b.current,h.viewport&&(h.viewport.style.scrollBehavior=""),g.current=null})})})}),Fs="ScrollAreaThumb",bp=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=yp(Fs,e.__scopeScrollArea);return u.jsx(Yt,{present:n||o.hasThumb,children:u.jsx(nC,{ref:t,...r})})}),nC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=Qt(Fs,n),i=yp(Fs,n),{onThumbPositionChange:a}=i,l=Be(t,f=>i.onThumbChange(f)),c=v.useRef(void 0),d=Us(()=>{c.current&&(c.current(),c.current=void 0)},100);return v.useEffect(()=>{const f=s.viewport;if(f){const p=()=>{if(d(),!c.current){const h=sC(f,a);c.current=h,a()}};return a(),f.addEventListener("scroll",p),()=>f.removeEventListener("scroll",p)}},[s.viewport,d,a]),u.jsx(_e.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:l,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:de(e.onPointerDownCapture,f=>{const h=f.target.getBoundingClientRect(),x=f.clientX-h.left,m=f.clientY-h.top;i.onThumbPointerDown({x,y:m})}),onPointerUp:de(e.onPointerUp,i.onThumbPointerUp)})});bp.displayName=Fs;var Da="ScrollAreaCorner",wp=v.forwardRef((e,t)=>{const n=Qt(Da,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(rC,{...e,ref:t}):null});wp.displayName=Da;var rC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=Qt(Da,n),[s,i]=v.useState(0),[a,l]=v.useState(0),c=!!(s&&a);return kr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),kr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(_e.div,{...r,ref:t,style:{width:s,height:a,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function Bs(e){return e?parseInt(e,10):0}function Sp(e,t){const n=e/t;return isNaN(n)?0:n}function zs(e){const t=Sp(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function oC(e,t,n,r="ltr"){const o=zs(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 Tp([l,c],f)(e)}function Cp(e,t,n="ltr"){const r=zs(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=Ra(e,l);return Tp([0,i],[0,a])(c)}function Tp(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 kp(e,t){return e>0&&e<t}var sC=(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 Us(e,t){const n=kt(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 kr(e,t){const n=kt(t);Tt(()=>{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 Ip=hp,iC=gp,aC=wp;const Ep=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Ip,{ref:r,className:ne("relative overflow-hidden",e),...n,children:[u.jsx(iC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(Ap,{}),u.jsx(aC,{})]}));Ep.displayName=Ip.displayName;const Ap=v.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(Pa,{ref:r,orientation:t,className:ne("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(bp,{className:"relative flex-1 rounded-full bg-border"})}));Ap.displayName=Pa.displayName;const Np=25;function La({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:c,onThreadDelete:d}){const{threads:f,currentThreadId:p,setCurrentThreadId:h,isLoading:x,actions:m}=_o(),{loadThread:y}=jo(),{createThread:g,deleteThread:b,renameThread:S}=m,[k,C]=w.useState(Array.isArray(f)?f:[]),T=w.useRef(k.length>0),I=w.useRef(null),A=w.useRef(0),[R,L]=w.useState(null),[P,D]=w.useState(""),[F,N]=w.useState(!1);w.useEffect(()=>{const Y=Array.isArray(f)?f:[];if(Y.length>0){T.current=!0,C(Y);return}x||(T.current=!1,C(Y))},[f,x]),w.useEffect(()=>{if(!I.current)return;const Y=I.current.querySelector("[data-radix-scroll-area-viewport]");if(!Y)return;let U=null,Z=null;return U=requestAnimationFrame(()=>{Z=requestAnimationFrame(()=>{Y.scrollTop=A.current})}),()=>{U!==null&&cancelAnimationFrame(U),Z!==null&&cancelAnimationFrame(Z)}},[k]);const B=async Y=>{try{h(Y),await y(Y),a==null||a(Y),l==null||l(Y)}catch(U){console.error("Failed to select thread:",U)}},j=async()=>{try{N(!0);const Y=await g();Y&&(c==null||c(Y),a==null||a(Y))}catch(Y){console.error("Failed to create thread:",Y)}finally{N(!1)}},V=async(Y,U)=>{if(U.stopPropagation(),!!confirm("Delete this thread?")){if(I.current){const Z=I.current.querySelector("[data-radix-scroll-area-viewport]");Z&&(A.current=Z.scrollTop)}try{await b(Y),d==null||d(Y)}catch(Z){console.error("Failed to delete thread:",Z)}}},z=(Y,U)=>{U.stopPropagation(),L(Y.threadId),D(Y.title||`Thread ${Y.threadId.slice(0,8)}`)},M=async Y=>{if(P.trim())try{await S(Y,P.trim()),L(null),D("")}catch(U){console.error("Failed to update title:",U)}},q=()=>{L(null),D("")},J=(Y,U)=>{Y.key==="Enter"?M(U):Y.key==="Escape"&&q()},se=Y=>{if(!Y)return"";try{const U=new Date(Y),$=new Date().getTime()-U.getTime(),K=Math.floor($/(1e3*60*60*24));return K===0?U.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):K===1?"Yesterday":K<7?`${K} days ago`:U.toLocaleDateString()}catch{return""}},ge=Y=>Y.title||`Thread ${Y.threadId.slice(0,8)}`,Ee=Y=>{const U=ge(Y);return U.length<=Np?U:`${U.slice(0,Np)}...`};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(Xe,{onClick:j,disabled:F||x,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:F?"Creating...":"New Chat",children:u.jsx(ae.MessageSquarePlus,{size:20})})}),u.jsx(Ep,{ref:I,className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:u.jsx("div",{className:"p-2 space-y-1 pb-4",children:x?u.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[u.jsx(ae.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(ae.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,U)=>new Date(U.updatedAt||U.createdAt||"").getTime()-new Date(Y.updatedAt||Y.createdAt||"").getTime()).map(Y=>u.jsxs("div",{onClick:()=>B(Y.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??p)===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:R===Y.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:U=>U.stopPropagation(),children:[u.jsx($s,{value:P,onChange:U=>D(U.target.value),onKeyDown:U=>J(U,Y.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>M(Y.threadId),className:"h-6 w-6 p-0",children:u.jsx(ae.Check,{size:12})}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:q,className:"h-6 w-6 p-0",children:u.jsx(ae.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:Ee(Y)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(ae.Calendar,{size:10}),u.jsx("span",{children:se(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&&R!==Y.threadId&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:U=>z(Y,U),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(ae.Edit3,{size:12})}),n&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:U=>V(Y.threadId,U),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:u.jsx(ae.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))})})]})}const lC=({timelineEntries:e,activeCheckpointId:t,onSelectCheckpoint:n,messagePreviews:r,className:o})=>{const s=e??[],i=s.length>0,a=w.useMemo(()=>i?[...s].reverse():[],[s,i]),l=t??(s.length?s[s.length-1].id:null);if(!i)return null;const d=["w-32 flex-shrink-0 flex-col border-r border-border/40 pr-2 flex",o].filter(Boolean).join(" ");return u.jsxs("div",{className:d,children:[u.jsxs("div",{className:"relative flex-1 overflow-y-auto pt-4 pb-2 pr-1",children:[u.jsx("div",{className:"absolute left-0 right-0 top-1 px-2 pb-3 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:u.jsx("span",{children:"Timeline"})}),u.jsx("div",{className:"pointer-events-none absolute left-3 top-0 bottom-0 w-px bg-border/40"}),u.jsx("div",{className:"flex flex-col gap-3 pt-6 pr-2",children:a.map(f=>{const p=l===f.id,h=f.messageId?(r==null?void 0:r.get(f.messageId))??null:null;return u.jsxs("button",{type:"button",disabled:!n,onClick:()=>n==null?void 0:n(f.id),className:`relative flex items-start gap-2 text-left text-[11px] transition ${p?"text-primary":"text-muted-foreground"} ${n?"hover:text-foreground":"cursor-default opacity-70"}`,children:[u.jsx("span",{className:`mt-1 inline-flex h-3 w-3 items-center justify-center rounded-full border ${p?"border-primary bg-primary/10 text-primary":"border-border bg-background"}`,children:u.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${p?"bg-primary":"bg-border"}`})}),u.jsxs("span",{className:"flex-1",children:[u.jsx("span",{className:"block font-medium leading-tight",children:f.label||"User input"}),u.jsxs("span",{className:"text-[9px] uppercase tracking-wide text-muted-foreground/70",children:[f.step!==null?`STEP ${f.step}`:"STEP —",f.next?` - ${f.next}`:""]}),h&&u.jsx("p",{className:"text-[10px] text-muted-foreground/80 mt-1 line-clamp-2",title:h,children:h})]})]},f.id)})})]}),n&&u.jsx("button",{type:"button",onClick:()=>n==null?void 0:n(null),className:"mt-auto mb-3 rounded-md border border-border/70 px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground transition hover:border-foreground/60 hover:text-foreground",children:"Latest"})]})};function Ir(e){if(!(typeof globalThis>"u"))return globalThis[e]}function cC(e){if(typeof e!="string")return;const t=e.trim();if(t)return wn(t)}function _p(){const e=[Ir("__API_BASE_URL__"),Ir("__CHAT_API_BASE_URL__"),Ir("__CHAT_API_URL__")];for(const t of e){const n=cC(t);if(n)return n}}function jp(){const e=[Ir("__API_AUTH_TOKEN__"),Ir("__CHAT_API_KEY__"),Ir("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function Rp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return wn(t);return wn()}function Mp(){const e={},t=_p(),n=jp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Pp(){const e=Mp(),t=An.getAuthToken(),n=_p();return{apiBaseUrl:Rp(e.baseUrl,An.baseUrl,n),apiKey:t||e.apiKey||jp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const Op="chat-settings";function uC(){try{const e=localStorage.getItem(Op);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function dC(e){try{const t={...e,apiBaseUrl:wn(e.apiBaseUrl)};localStorage.setItem(Op,JSON.stringify(t)),t.apiKey&&An.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function fC(){const e=Pp(),t=uC(),n=An.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Rp(An.baseUrl,r,e.apiBaseUrl)}}function pC(e){An.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),dC(e)}var hC="Label",Dp=v.forwardRef((e,t)=>u.jsx(_e.label,{...e,ref:t,onMouseDown:n=>{var o;n.target.closest("button, input, select, textarea")||((o=e.onMouseDown)==null||o.call(e,n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));Dp.displayName=hC;var Lp=Dp;const mC=po.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),en=v.forwardRef(({className:e,...t},n)=>u.jsx(Lp,{ref:n,className:ne(mC(),e),...t}));en.displayName=Lp.displayName;function $p(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 Fp=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"}),gC="VisuallyHidden",xC=v.forwardRef((e,t)=>u.jsx(_e.span,{...e,ref:t,style:{...Fp,...e.style}}));xC.displayName=gC;var yC=[" ","Enter","ArrowUp","ArrowDown"],vC=[" ","Enter"],rr="Select",[Hs,Ws,bC]=xi(rr),[Er,BT]=Sn(rr,[bC,Ko]),Vs=Ko(),[wC,$n]=Er(rr),[SC,CC]=Er(rr),Bp=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:c,name:d,autoComplete:f,disabled:p,required:h,form:x}=e,m=Vs(t),[y,g]=v.useState(null),[b,S]=v.useState(null),[k,C]=v.useState(!1),T=Mo(c),[I,A]=pr({prop:r,defaultProp:o??!1,onChange:s,caller:rr}),[R,L]=pr({prop:i,defaultProp:a,onChange:l,caller:rr}),P=v.useRef(null),D=y?x||!!y.closest("form"):!0,[F,N]=v.useState(new Set),B=Array.from(F).map(j=>j.props.value).join(";");return u.jsx(tu,{...m,children:u.jsxs(wC,{required:h,scope:t,trigger:y,onTriggerChange:g,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:k,onValueNodeHasChildrenChange:C,contentId:Cn(),value:R,onValueChange:L,open:I,onOpenChange:A,dir:T,triggerPointerDownPosRef:P,disabled:p,children:[u.jsx(Hs.Provider,{scope:t,children:u.jsx(SC,{scope:e.__scopeSelect,onNativeOptionAdd:v.useCallback(j=>{N(V=>new Set(V).add(j))},[]),onNativeOptionRemove:v.useCallback(j=>{N(V=>{const z=new Set(V);return z.delete(j),z})},[]),children:n})}),D?u.jsxs(uh,{"aria-hidden":!0,required:h,tabIndex:-1,name:d,autoComplete:f,value:R,onChange:j=>L(j.target.value),disabled:p,form:x,children:[R===void 0?u.jsx("option",{value:""}):null,Array.from(F)]},B):null]})})};Bp.displayName=rr;var zp="SelectTrigger",Up=v.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Vs(n),i=$n(zp,n),a=i.disabled||r,l=Be(t,i.onTriggerChange),c=Ws(n),d=v.useRef("touch"),[f,p,h]=fh(m=>{const y=c().filter(S=>!S.disabled),g=y.find(S=>S.value===i.value),b=ph(y,m,g);b!==void 0&&i.onValueChange(b.value)}),x=m=>{a||(i.onOpenChange(!0),h()),m&&(i.triggerPointerDownPosRef.current={x:Math.round(m.pageX),y:Math.round(m.pageY)})};return u.jsx(nu,{asChild:!0,...s,children:u.jsx(_e.button,{type:"button",role:"combobox","aria-controls":i.contentId,"aria-expanded":i.open,"aria-required":i.required,"aria-autocomplete":"none",dir:i.dir,"data-state":i.open?"open":"closed",disabled:a,"data-disabled":a?"":void 0,"data-placeholder":dh(i.value)?"":void 0,...o,ref:l,onClick:de(o.onClick,m=>{m.currentTarget.focus(),d.current!=="mouse"&&x(m)}),onPointerDown:de(o.onPointerDown,m=>{d.current=m.pointerType;const y=m.target;y.hasPointerCapture(m.pointerId)&&y.releasePointerCapture(m.pointerId),m.button===0&&m.ctrlKey===!1&&m.pointerType==="mouse"&&(x(m),m.preventDefault())}),onKeyDown:de(o.onKeyDown,m=>{const y=f.current!=="";!(m.ctrlKey||m.altKey||m.metaKey)&&m.key.length===1&&p(m.key),!(y&&m.key===" ")&&yC.includes(m.key)&&(x(),m.preventDefault())})})})});Up.displayName=zp;var Hp="SelectValue",Wp=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=$n(Hp,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=Be(t,l.onValueNodeChange);return Tt(()=>{c(d)},[c,d]),u.jsx(_e.span,{...a,ref:f,style:{pointerEvents:"none"},children:dh(l.value)?u.jsx(u.Fragment,{children:i}):s})});Wp.displayName=Hp;var TC="SelectIcon",Vp=v.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(_e.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Vp.displayName=TC;var kC="SelectPortal",Kp=e=>u.jsx(qo,{asChild:!0,...e});Kp.displayName=kC;var or="SelectContent",qp=v.forwardRef((e,t)=>{const n=$n(or,e.__scopeSelect),[r,o]=v.useState();if(Tt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?ho.createPortal(u.jsx(Gp,{scope:e.__scopeSelect,children:u.jsx(Hs.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(Yp,{...e,ref:t})});qp.displayName=or;var cn=10,[Gp,Fn]=Er(or),IC="SelectContentImpl",EC=Hn.createSlot("SelectContent.RemoveScroll"),Yp=v.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:x,hideWhenDetached:m,avoidCollisions:y,...g}=e,b=$n(or,n),[S,k]=v.useState(null),[C,T]=v.useState(null),I=Be(t,Z=>k(Z)),[A,R]=v.useState(null),[L,P]=v.useState(null),D=Ws(n),[F,N]=v.useState(!1),B=v.useRef(!1);v.useEffect(()=>{if(S)return Fi(S)},[S]),bi();const j=v.useCallback(Z=>{const[$,...K]=D().map(oe=>oe.ref.current),[Q]=K.slice(-1),ce=document.activeElement;for(const oe of Z)if(oe===ce||(oe==null||oe.scrollIntoView({block:"nearest"}),oe===$&&C&&(C.scrollTop=0),oe===Q&&C&&(C.scrollTop=C.scrollHeight),oe==null||oe.focus(),document.activeElement!==ce))return},[D,C]),V=v.useCallback(()=>j([A,S]),[j,A,S]);v.useEffect(()=>{F&&V()},[F,V]);const{onOpenChange:z,triggerPointerDownPosRef:M}=b;v.useEffect(()=>{if(S){let Z={x:0,y:0};const $=Q=>{var ce,oe;Z={x:Math.abs(Math.round(Q.pageX)-(((ce=M.current)==null?void 0:ce.x)??0)),y:Math.abs(Math.round(Q.pageY)-(((oe=M.current)==null?void 0:oe.y)??0))}},K=Q=>{Z.x<=10&&Z.y<=10?Q.preventDefault():S.contains(Q.target)||z(!1),document.removeEventListener("pointermove",$),M.current=null};return M.current!==null&&(document.addEventListener("pointermove",$),document.addEventListener("pointerup",K,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",$),document.removeEventListener("pointerup",K,{capture:!0})}}},[S,z,M]),v.useEffect(()=>{const Z=()=>z(!1);return window.addEventListener("blur",Z),window.addEventListener("resize",Z),()=>{window.removeEventListener("blur",Z),window.removeEventListener("resize",Z)}},[z]);const[q,J]=fh(Z=>{const $=D().filter(ce=>!ce.disabled),K=$.find(ce=>ce.ref.current===document.activeElement),Q=ph($,Z,K);Q&&setTimeout(()=>Q.ref.current.focus())}),se=v.useCallback((Z,$,K)=>{const Q=!B.current&&!K;(b.value!==void 0&&b.value===$||Q)&&(R(Z),Q&&(B.current=!0))},[b.value]),ge=v.useCallback(()=>S==null?void 0:S.focus(),[S]),Ee=v.useCallback((Z,$,K)=>{const Q=!B.current&&!K;(b.value!==void 0&&b.value===$||Q)&&P(Z)},[b.value]),Y=r==="popper"?$a:Xp,U=Y===$a?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:x,hideWhenDetached:m,avoidCollisions:y}:{};return u.jsx(Gp,{scope:n,content:S,viewport:C,onViewportChange:T,itemRefCallback:se,selectedItem:A,onItemLeave:ge,itemTextRefCallback:Ee,focusSelectedItem:V,selectedItemText:L,position:r,isPositioned:F,searchRef:q,children:u.jsx(ns,{as:EC,allowPinchZoom:!0,children:u.jsx(Oo,{asChild:!0,trapped:b.open,onMountAutoFocus:Z=>{Z.preventDefault()},onUnmountAutoFocus:de(o,Z=>{var $;($=b.trigger)==null||$.focus({preventScroll:!0}),Z.preventDefault()}),children:u.jsx(Po,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:Z=>Z.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:u.jsx(Y,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:Z=>Z.preventDefault(),...g,...U,onPlaced:()=>N(!0),ref:I,style:{display:"flex",flexDirection:"column",outline:"none",...g.style},onKeyDown:de(g.onKeyDown,Z=>{const $=Z.ctrlKey||Z.altKey||Z.metaKey;if(Z.key==="Tab"&&Z.preventDefault(),!$&&Z.key.length===1&&J(Z.key),["ArrowUp","ArrowDown","Home","End"].includes(Z.key)){let Q=D().filter(ce=>!ce.disabled).map(ce=>ce.ref.current);if(["ArrowUp","End"].includes(Z.key)&&(Q=Q.slice().reverse()),["ArrowUp","ArrowDown"].includes(Z.key)){const ce=Z.target,oe=Q.indexOf(ce);Q=Q.slice(oe+1)}setTimeout(()=>j(Q)),Z.preventDefault()}})})})})})})});Yp.displayName=IC;var AC="SelectItemAlignedPosition",Xp=v.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=$n(or,n),i=Fn(or,n),[a,l]=v.useState(null),[c,d]=v.useState(null),f=Be(t,I=>d(I)),p=Ws(n),h=v.useRef(!1),x=v.useRef(!0),{viewport:m,selectedItem:y,selectedItemText:g,focusSelectedItem:b}=i,S=v.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&m&&y&&g){const I=s.trigger.getBoundingClientRect(),A=c.getBoundingClientRect(),R=s.valueNode.getBoundingClientRect(),L=g.getBoundingClientRect();if(s.dir!=="rtl"){const ce=L.left-A.left,oe=R.left-ce,Ne=I.left-oe,Ue=I.width+Ne,re=Math.max(Ue,A.width),xe=window.innerWidth-cn,Pe=Ra(oe,[cn,Math.max(cn,xe-re)]);a.style.minWidth=Ue+"px",a.style.left=Pe+"px"}else{const ce=A.right-L.right,oe=window.innerWidth-R.right-ce,Ne=window.innerWidth-I.right-oe,Ue=I.width+Ne,re=Math.max(Ue,A.width),xe=window.innerWidth-cn,Pe=Ra(oe,[cn,Math.max(cn,xe-re)]);a.style.minWidth=Ue+"px",a.style.right=Pe+"px"}const P=p(),D=window.innerHeight-cn*2,F=m.scrollHeight,N=window.getComputedStyle(c),B=parseInt(N.borderTopWidth,10),j=parseInt(N.paddingTop,10),V=parseInt(N.borderBottomWidth,10),z=parseInt(N.paddingBottom,10),M=B+j+F+z+V,q=Math.min(y.offsetHeight*5,M),J=window.getComputedStyle(m),se=parseInt(J.paddingTop,10),ge=parseInt(J.paddingBottom,10),Ee=I.top+I.height/2-cn,Y=D-Ee,U=y.offsetHeight/2,Z=y.offsetTop+U,$=B+j+Z,K=M-$;if($<=Ee){const ce=P.length>0&&y===P[P.length-1].ref.current;a.style.bottom="0px";const oe=c.clientHeight-m.offsetTop-m.offsetHeight,Ne=Math.max(Y,U+(ce?ge:0)+oe+V),Ue=$+Ne;a.style.height=Ue+"px"}else{const ce=P.length>0&&y===P[0].ref.current;a.style.top="0px";const Ne=Math.max(Ee,B+m.offsetTop+(ce?se:0)+U)+K;a.style.height=Ne+"px",m.scrollTop=$-Ee+m.offsetTop}a.style.margin=`${cn}px 0`,a.style.minHeight=q+"px",a.style.maxHeight=D+"px",r==null||r(),requestAnimationFrame(()=>h.current=!0)}},[p,s.trigger,s.valueNode,a,c,m,y,g,s.dir,r]);Tt(()=>S(),[S]);const[k,C]=v.useState();Tt(()=>{c&&C(window.getComputedStyle(c).zIndex)},[c]);const T=v.useCallback(I=>{I&&x.current===!0&&(S(),b==null||b(),x.current=!1)},[S,b]);return u.jsx(_C,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:h,onScrollButtonChange:T,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:k},children:u.jsx(_e.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Xp.displayName=AC;var NC="SelectPopperPosition",$a=v.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=cn,...s}=e,i=Vs(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)"}})});$a.displayName=NC;var[_C,Fa]=Er(or,{}),Ba="SelectViewport",Jp=v.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Fn(Ba,n),i=Fa(Ba,n),a=Be(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(Hs.Slot,{scope:n,children:u.jsx(_e.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:de(o.onScroll,c=>{const d=c.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:p}=i;if(p!=null&&p.current&&f){const h=Math.abs(l.current-d.scrollTop);if(h>0){const x=window.innerHeight-cn*2,m=parseFloat(f.style.minHeight),y=parseFloat(f.style.height),g=Math.max(m,y);if(g<x){const b=g+h,S=Math.min(x,b),k=b-S;f.style.height=S+"px",f.style.bottom==="0px"&&(d.scrollTop=k>0?k:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});Jp.displayName=Ba;var Zp="SelectGroup",[jC,RC]=Er(Zp),MC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Cn();return u.jsx(jC,{scope:n,id:o,children:u.jsx(_e.div,{role:"group","aria-labelledby":o,...r,ref:t})})});MC.displayName=Zp;var Qp="SelectLabel",eh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=RC(Qp,n);return u.jsx(_e.div,{id:o.id,...r,ref:t})});eh.displayName=Qp;var Ks="SelectItem",[PC,th]=Er(Ks),nh=v.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=$n(Ks,n),l=Fn(Ks,n),c=a.value===r,[d,f]=v.useState(s??""),[p,h]=v.useState(!1),x=Be(t,b=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,b,r,o)}),m=Cn(),y=v.useRef("touch"),g=()=>{o||(a.onValueChange(r),a.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return u.jsx(PC,{scope:n,value:r,disabled:o,textId:m,isSelected:c,onItemTextChange:v.useCallback(b=>{f(S=>S||((b==null?void 0:b.textContent)??"").trim())},[]),children:u.jsx(Hs.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(_e.div,{role:"option","aria-labelledby":m,"data-highlighted":p?"":void 0,"aria-selected":c&&p,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:x,onFocus:de(i.onFocus,()=>h(!0)),onBlur:de(i.onBlur,()=>h(!1)),onClick:de(i.onClick,()=>{y.current!=="mouse"&&g()}),onPointerUp:de(i.onPointerUp,()=>{y.current==="mouse"&&g()}),onPointerDown:de(i.onPointerDown,b=>{y.current=b.pointerType}),onPointerMove:de(i.onPointerMove,b=>{var S;y.current=b.pointerType,o?(S=l.onItemLeave)==null||S.call(l):y.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:de(i.onPointerLeave,b=>{var S;b.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:de(i.onKeyDown,b=>{var k;((k=l.searchRef)==null?void 0:k.current)!==""&&b.key===" "||(vC.includes(b.key)&&g(),b.key===" "&&b.preventDefault())})})})})});nh.displayName=Ks;var uo="SelectItemText",rh=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=$n(uo,n),a=Fn(uo,n),l=th(uo,n),c=CC(uo,n),[d,f]=v.useState(null),p=Be(t,g=>f(g),l.onItemTextChange,g=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,g,l.value,l.disabled)}),h=d==null?void 0:d.textContent,x=v.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:h},l.value),[l.disabled,l.value,h]),{onNativeOptionAdd:m,onNativeOptionRemove:y}=c;return Tt(()=>(m(x),()=>y(x)),[m,y,x]),u.jsxs(u.Fragment,{children:[u.jsx(_e.span,{id:l.textId,...s,ref:p}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?ho.createPortal(s.children,i.valueNode):null]})});rh.displayName=uo;var oh="SelectItemIndicator",sh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return th(oh,n).isSelected?u.jsx(_e.span,{"aria-hidden":!0,...r,ref:t}):null});sh.displayName=oh;var za="SelectScrollUpButton",ih=v.forwardRef((e,t)=>{const n=Fn(za,e.__scopeSelect),r=Fa(za,e.__scopeSelect),[o,s]=v.useState(!1),i=Be(t,r.onScrollButtonChange);return Tt(()=>{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(lh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});ih.displayName=za;var Ua="SelectScrollDownButton",ah=v.forwardRef((e,t)=>{const n=Fn(Ua,e.__scopeSelect),r=Fa(Ua,e.__scopeSelect),[o,s]=v.useState(!1),i=Be(t,r.onScrollButtonChange);return Tt(()=>{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(lh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});ah.displayName=Ua;var lh=v.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Fn("SelectScrollButton",n),i=v.useRef(null),a=Ws(n),l=v.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return v.useEffect(()=>()=>l(),[l]),Tt(()=>{var d;const c=a().find(f=>f.ref.current===document.activeElement);(d=c==null?void 0:c.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),u.jsx(_e.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:de(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:de(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:de(o.onPointerLeave,()=>{l()})})}),OC="SelectSeparator",ch=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(_e.div,{"aria-hidden":!0,...r,ref:t})});ch.displayName=OC;var Ha="SelectArrow",DC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Vs(n),s=$n(Ha,n),i=Fn(Ha,n);return s.open&&i.position==="popper"?u.jsx(ou,{...o,...r,ref:t}):null});DC.displayName=Ha;var LC="SelectBubbleInput",uh=v.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=v.useRef(null),s=Be(r,o),i=$p(t);return v.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),u.jsx(_e.select,{...n,style:{...Fp,...n.style},ref:s,defaultValue:t})});uh.displayName=LC;function dh(e){return e===""||e===void 0}function fh(e){const t=kt(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 ph(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=$C(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 $C(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var FC=Bp,hh=Up,BC=Wp,zC=Vp,UC=Kp,mh=qp,HC=Jp,gh=eh,xh=nh,WC=rh,VC=sh,yh=ih,vh=ah,bh=ch;const wh=FC,Sh=BC,Wa=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(hh,{ref:r,className:ne("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(zC,{asChild:!0,children:u.jsx(ae.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Wa.displayName=hh.displayName;const Ch=v.forwardRef(({className:e,...t},n)=>u.jsx(yh,{ref:n,className:ne("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ae.ChevronUp,{className:"h-4 w-4"})}));Ch.displayName=yh.displayName;const Th=v.forwardRef(({className:e,...t},n)=>u.jsx(vh,{ref:n,className:ne("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ae.ChevronDown,{className:"h-4 w-4"})}));Th.displayName=vh.displayName;const Va=v.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(UC,{children:u.jsxs(mh,{ref:o,className:ne("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(Ch,{}),u.jsx(HC,{className:ne("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(Th,{})]})}));Va.displayName=mh.displayName;const KC=v.forwardRef(({className:e,...t},n)=>u.jsx(gh,{ref:n,className:ne("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));KC.displayName=gh.displayName;const sr=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(xh,{ref:r,className:ne("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(VC,{children:u.jsx(ae.Check,{className:"h-4 w-4"})})}),u.jsx(WC,{children:t})]}));sr.displayName=xh.displayName;const qC=v.forwardRef(({className:e,...t},n)=>u.jsx(bh,{ref:n,className:ne("-mx-1 my-1 h-px bg-muted",e),...t}));qC.displayName=bh.displayName;var GC="Separator",kh="horizontal",YC=["horizontal","vertical"],Ih=v.forwardRef((e,t)=>{const{decorative:n,orientation:r=kh,...o}=e,s=XC(r)?r:kh,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(_e.div,{"data-orientation":s,...a,...o,ref:t})});Ih.displayName=GC;function XC(e){return YC.includes(e)}var Eh=Ih;const Ah=v.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(Eh,{ref:o,decorative:n,orientation:t,className:ne("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Ah.displayName=Eh.displayName;const JC=Bf,ZC=cS,QC=zf,Nh=v.forwardRef(({className:e,...t},n)=>u.jsx(Es,{className:ne("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}));Nh.displayName=Es.displayName;const eT=po.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"}}),_h=v.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(QC,{children:[u.jsx(Nh,{}),u.jsxs(As,{ref:o,className:ne(eT({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(ae.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));_h.displayName=As.displayName;const jh=({className:e,...t})=>u.jsx("div",{className:ne("flex flex-col space-y-2 text-center sm:text-left",e),...t});jh.displayName="SheetHeader";const Rh=v.forwardRef(({className:e,...t},n)=>u.jsx(tr,{ref:n,className:ne("text-lg font-semibold text-foreground",e),...t}));Rh.displayName=tr.displayName;const Mh=v.forwardRef(({className:e,...t},n)=>u.jsx(Ns,{ref:n,className:ne("text-sm text-muted-foreground",e),...t}));Mh.displayName=Ns.displayName;var qs="Switch",[tT,zT]=Sn(qs),[nT,rT]=tT(qs),Ph=v.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:c,form:d,...f}=e,[p,h]=v.useState(null),x=Be(t,S=>h(S)),m=v.useRef(!1),y=p?d||!!p.closest("form"):!0,[g,b]=pr({prop:o,defaultProp:s??!1,onChange:c,caller:qs});return u.jsxs(nT,{scope:n,checked:g,disabled:a,children:[u.jsx(_e.button,{type:"button",role:"switch","aria-checked":g,"aria-required":i,"data-state":$h(g),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:x,onClick:de(e.onClick,S=>{b(k=>!k),y&&(m.current=S.isPropagationStopped(),m.current||S.stopPropagation())})}),y&&u.jsx(Lh,{control:p,bubbles:!m.current,name:r,value:l,checked:g,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Ph.displayName=qs;var Oh="SwitchThumb",Dh=v.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=rT(Oh,n);return u.jsx(_e.span,{"data-state":$h(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Dh.displayName=Oh;var oT="SwitchBubbleInput",Lh=v.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=v.useRef(null),a=Be(i,s),l=$p(n),c=Vc(t);return v.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,h=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&h){const x=new Event("click",{bubbles:r});h.call(d,n),d.dispatchEvent(x)}},[l,n,r]),u.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...c,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});Lh.displayName=oT;function $h(e){return e?"checked":"unchecked"}var Fh=Ph,sT=Dh;const Bn=v.forwardRef(({className:e,...t},n)=>u.jsx(Fh,{className:ne("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(sT,{className:ne("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")})}));Bn.displayName=Fh.displayName;const iT={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 aT({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}=Aa();w.useEffect(()=>{const y=JSON.stringify(a)!==JSON.stringify(e);d(y)},[a,e]),w.useEffect(()=>{l(e)},[e]);const p=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},h=()=>{l(iT),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},x=()=>{l(e),d(!1),o(!1)},m=async()=>{try{const g=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${g.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return u.jsxs(JC,{open:r,onOpenChange:o,children:[u.jsx(ZC,{asChild:!0,children:u.jsxs(Xe,{variant:"outline",size:"sm",className:n,children:[u.jsx(ae.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(_h,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(jh,{children:[u.jsx(Rh,{children:"Chat Settings"}),u.jsx(Mh,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(ae.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(en,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx($s,{id:"api-url",value:a.api.baseUrl,onChange:y=>l(g=>({...g,api:{...g.api,baseUrl:y.target.value}})),placeholder:"http://localhost:8000/api"}),u.jsx(Xe,{variant:"outline",onClick:m,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(en,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(Bn,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:y=>l(g=>({...g,api:{...g.api,enableAuth:y}}))})]}),a.api.enableAuth&&u.jsxs("div",{className:"space-y-2",children:[u.jsx(en,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx($s,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:y=>l(g=>({...g,api:{...g.api,authToken:y.target.value}})),placeholder:"Enter your Bearer token"}),u.jsx(Xe,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?u.jsx(ae.EyeOff,{className:"h-4 w-4"}):u.jsx(ae.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(ae.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(en,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(wh,{value:a.ui.layout,onValueChange:y=>l(g=>({...g,ui:{...g.ui,layout:y}})),children:[u.jsx(Wa,{children:u.jsx(Sh,{})}),u.jsxs(Va,{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(en,{htmlFor:"theme",children:"Theme"}),u.jsxs(wh,{value:a.ui.theme,onValueChange:y=>l(g=>({...g,ui:{...g.ui,theme:y}})),children:[u.jsx(Wa,{children:u.jsx(Sh,{})}),u.jsxs(Va,{children:[u.jsx(sr,{value:"light",children:"Light"}),u.jsx(sr,{value:"dark",children:"Dark"}),u.jsx(sr,{value:"system",children:"System"})]})]})]}),u.jsx(Ah,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(en,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(Bn,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,showTimestamps:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(en,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(Bn,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,showAgentNames:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(en,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(Bn,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,compactMessages:y}}))})]})]})]})]}),u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(ae.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(en,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(Bn,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:y=>l(g=>({...g,behavior:{...g.behavior,autoSave:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(en,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx(Bn,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:y=>l(g=>({...g,behavior:{...g.behavior,enableStreaming:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(en,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx(Bn,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:y=>l(g=>({...g,behavior:{...g.behavior,showTypingIndicator:y}}))})]})]})]})]}),u.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[u.jsxs(Xe,{variant:"outline",onClick:h,children:[u.jsx(ae.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Xe,{variant:"outline",onClick:x,children:"Cancel"}),u.jsxs(Xe,{onClick:p,disabled:!c,children:[u.jsx(ae.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function lT({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(Ro,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx(Ls,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(Ro,{...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(La,{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(Ls,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(Ro,{...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(La,{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(Ls,{onError:s.onError,enableFileUpload:!0})})]})})}Ce.ChatApi=Bl,Ce.ChatInput=cc,Ce.ChatInterface=Ls,Ce.ChatProviders=Ro,Ce.ChatSettings=aT,Ce.MarkdownContent=so,Ce.MessageComponent=Ds,Ce.MessageList=ja,Ce.ThreadManager=La,Ce.TimelineColumn=lC,Ce.applySettings=pC,Ce.buildMessagePreviewMap=ql,Ce.chatApiClient=An,Ce.default=lT,Ce.del=Fl,Ce.get=qt,Ce.getChatToken=Dl,Ce.getCurrentSettings=fC,Ce.getDefaultApiConfig=Mp,Ce.getDefaultChatSettings=Pp,Ce.onChatTokenChanged=Ll,Ce.post=ci,Ce.put=$l,Ce.setChatToken=Io,Ce.useApi=ui,Ce.useChatStream=Gl,Ce.useMessagesReducer=Yl,Ce.useStream=ac,Ce.useThreadState=jo,Ce.useThreads=_o,Object.defineProperties(Ce,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
137
|
+
dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[Y[X]?u.jsx(ae.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[pe,Y[X]?" (processing)":""]})]},X)}if(_.type==="interrupt"){const te=_,pe=Ts((te==null?void 0:te.id)??(te==null?void 0:te.interrupt_id)),ve=!!(Pe&&pe&&pe===Pe),we=ve?Ze??(te==null?void 0:te.value):te==null?void 0:te.value,Fe=pe?{...te,id:pe,interrupt_id:pe}:te;return u.jsx(HS,{interruptPart:Fe,onApprove:gt,onReject:ht,disabled:S,isActive:ve,payload:we},X)}return null},[U,Y,gt,ht,q,c,d,B,M,Pe,Ze,b,S,re]),St=w.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(ae.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),Lt=w.useCallback(()=>{const _=ce.trim().length>0||Ne.length>0||Ue.length>0||re.length>0;if(!J&&Ue.length>0&&!r)return St();if(!J&&!_&&!r)return null;if(J)return!f&&Ve.length>0?null:f?u.jsx(KS,{message:t,viewMode:F},t.id):null;if(!J&&!se){const X=t,te=u.jsx("div",{className:"space-y-2",children:X.content.map((pe,ve)=>u.jsx(bt,{part:pe,i:ve},ve))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[te,u.jsx(qS,{className:Q})]}):te}},[ce,Ne.length,Ue.length,re.length,r,J,F,f,Ve.length,St,Q]),Mt=w.useMemo(()=>se?"Assistant":q0(t),[se,t]),et=w.useMemo(()=>se?[]:Array.isArray(T)?T:[],[T,se]),It=w.useMemo(()=>{var _;return et.length?R&&et.some(X=>X.id===R)?R:((_=et[0])==null?void 0:_.id)??null:null},[R,et]),Ge=w.useMemo(()=>!et.length||!I?null:et.some(_=>_.id===I)?I:null,[I,et])??It,Ye=q==="user"&&et.length>0&&typeof A=="function",pt=w.useCallback((_,X=!1)=>{if(!A)return;const te=(_==null?void 0:_.id)??null,pe=(_==null?void 0:_.parentId)??L??null;A(te,pe,X)},[L,A]),lt=w.useMemo(()=>Ge?et.findIndex(_=>_.id===Ge):-1,[Ge,et]),G=w.useMemo(()=>lt<0?null:et[lt]??null,[lt,et]);return J&&!f&&Ve.length===0?null:ge&&se?u.jsx("div",{className:ne(at(),h.container),children:u.jsxs("div",{className:ne(Rt(),h.content),children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2 pb-2 border-b border-current/10",children:[u.jsx(ae.Bot,{className:ne("h-4 w-4",Q)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(so,{content:se.content,className:"text-current"})]})}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:ne(at(),h.container),children:u.jsxs("div",{className:ne(Rt(),h.content),children:[(i||a||J)&&u.jsxs("div",{className:ne("flex items-center justify-between mb-2 pb-2 border-b border-current/10",M&&"mb-1 pb-1",Q,h.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[nt(),a&&Mt&&u.jsx("span",{className:ne("font-medium",M?"text-xs":"text-sm"),children:Mt}),J&&u.jsxs(yf,{variant:"outline",className:ne("text-xs flex items-center gap-1 cursor-pointer select-none",Q,"border border-current/40",M&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":F==="expanded",onClick:()=>N(_=>_==="expanded"?"preview":"expanded"),onKeyDown:_=>{(_.key==="Enter"||_.key===" ")&&(_.preventDefault(),N(X=>X==="expanded"?"preview":"expanded"))},children:[u.jsx("span",{children:oe.name??"Tool Output"}),oe.toolCallId&&u.jsx("span",{className:"opacity-70",children:oe.toolCallId.slice(0,8)}),F==="expanded"?u.jsx(ae.ChevronUp,{className:"h-3 w-3"}):u.jsx(ae.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[Ye&&G&<>=0&&u.jsx("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("button",{type:"button",className:ne("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",lt<et.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(lt>=et.length-1)return;const _=et[lt+1];_&&pt(_)},"aria-label":"Older checkpoint (back in time)",disabled:lt>=et.length-1,children:u.jsx(ae.ChevronLeft,{className:"h-3 w-3"})}),u.jsx("div",{className:"flex items-center gap-2",children:u.jsxs("span",{className:"whitespace-nowrap",children:[et.length-lt," / ",et.length]})}),u.jsx("button",{type:"button",className:ne("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",lt>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(!(lt<=0))if(lt===1)pt(null,!0);else{const _=et[lt-1];_&&pt(_,!1)}},"aria-label":"Newer checkpoint (forward in time)",disabled:lt<=0,children:u.jsx(ae.ChevronRight,{className:"h-3 w-3"})})]})}),i&&t.createdAt&&u.jsx("time",{className:ne("text-xs opacity-60",Q,M&&"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:ne("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>tt(),className:ne("h-6 w-6 p-0 hover:bg-foreground/10",Q,M&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(ae.Copy,{className:ne(P?"text-success":Q,M?"h-3 w-3":"h-4 w-4")})})}),q==="user"&&x&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:it,className:ne("h-6 w-6 p-0 hover:bg-foreground/10",Q,M&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(ae.Edit,{className:ne(Q,M?"h-3 w-3":"h-4 w-4")})}),q==="assistant"&&m&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:qe,className:ne("h-6 w-6 p-0 hover:bg-foreground/10",Q,M&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(ae.RotateCcw,{className:ne(Q,M?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsxs("div",{className:"relative",children:[Lt(),p&&Ve.length>0&&u.jsx("div",{className:"mt-3 space-y-4",children:Ve.map((_,X)=>u.jsx(zS,{preview:_,idx:X},`artifact-${X}`))})]}),J&&F==="expanded"&&(oe.toolCallId||oe.name)&&u.jsxs("div",{className:ne("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",M&&"text-xs"),children:[oe.name&&u.jsxs("div",{children:["Function: ",oe.name]}),oe.toolCallId&&u.jsxs("div",{children:["Call ID: ",oe.toolCallId]})]}),!(i||a||J)&&s&&!o&&u.jsxs("div",{className:ne("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>tt(),className:ne("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(ae.Copy,{className:ne(P?"text-success":"text-current",M?"h-3 w-3":"h-4 w-4")})}),q==="user"&&x&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:it,className:ne("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(ae.Edit,{className:ne("text-current",M?"h-3 w-3":"h-4 w-4")})}),q==="assistant"&&m&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:qe,className:ne("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:u.jsx(ae.RotateCcw,{className:ne("text-current",M?"h-3 w-3":"h-4 w-4")})})]})]})}),$&&u.jsx(yS,{isOpen:Z,onClose:K,fileId:$.id,fileName:$.name,mimeType:$.mimeType})]})},(e,t)=>{var i,a,l,c,d,f,p,h;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&wf(e.message)===wf(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages","attemptMeta"].every(x=>e[x]===t[x]),s=((i=e.customStyles)==null?void 0:i.container)===((a=t.customStyles)==null?void 0:a.container)&&((l=e.customStyles)==null?void 0:l.content)===((c=t.customStyles)==null?void 0:c.content)&&((d=e.customStyles)==null?void 0:d.actions)===((f=t.customStyles)==null?void 0:f.actions)&&((p=e.customStyles)==null?void 0:p.header)===((h=t.customStyles)==null?void 0:h.header);return o&&s});Ds.displayName="MessageComponent";function GS(e,t){return w.useMemo(()=>{var d,f,p,h,x;const n=e&&"type"in e&&e.type==="default_message";let r=[],o=null,s={},i={},a=null,l=null,c=null;if(!n&&e){const m=e,y=m.checkpointId??null;s=m.additionalKwargs??{},i=m.responseMetadata??{};const g=y&&t.checkpointMetaById?t.checkpointMetaById.get(y)??null:null;a=typeof s.step=="number"?s.step:typeof i.step=="number"?i.step:(g==null?void 0:g.step)??null;const b=typeof s.source=="string"?s.source:typeof i.source=="string"?i.source:(g==null?void 0:g.source)??null;l=b?String(b):null;const S=a!==null&&l?`${a}:${l}`:null;if(S&&((d=t.checkpointIndexByKey)!=null&&d.has(S))?r=t.checkpointIndexByKey.get(S)??[]:y&&g&&(r=[g]),o=y??((f=r[0])==null?void 0:f.id)??null,c=y?((p=t.attemptMetaById)==null?void 0:p.get(y))??null:null,!c&&(e==null?void 0:e.role)==="user"&&(e!=null&&e.id)&&t.userMessageIdToAttempts){const k=t.userMessageIdToAttempts.get(e.id);if(k&&k.length>0){const C=k[0].checkpointId;c=((h=t.attemptMetaById)==null?void 0:h.get(C))??null,c&&console.log(`[useMessageMetadata] Found attempt by user message ID "${e.id}":`,k.length,"versions")}}if(!c&&r.length>0&&t.attemptMetaById){const k=t.attemptMetaById.get(r[0].id);k&&(c=k)}if(c&&c.attemptCount>1&&t.attemptMetaById){const k=c.baseUserMessageId;if(k){const C=[];for(const[T,I]of t.attemptMetaById.entries())if(I.baseUserMessageId===k){const A=(x=t.checkpointMetaById)==null?void 0:x.get(T);A&&C.push(A)}C.length>0&&(r=C)}}if(c&&c.attemptCount>1&&t.checkpointMetaById&&t.attemptMetaById){const k=[];for(const[C,T]of t.checkpointMetaById.entries()){const I=t.attemptMetaById.get(C);I&&I.attemptCount===c.attemptCount&&I.baseUserMessageId===c.baseUserMessageId&&k.push(T)}k.sort((C,T)=>{const I=C.createdAt?Date.parse(C.createdAt):0;return(T.createdAt?Date.parse(T.createdAt):0)-I}),k.length>0&&(r=k,console.log("[useMessageMetadata] Populated checkpointCandidates with all attempts:",{messageId:e.id,attemptCount:c.attemptCount,candidateIds:r.map(C=>C.id)}))}}return{checkpointCandidates:r,defaultCheckpointId:o,attemptMeta:c,resolvedStep:a,resolvedSource:l}},[e,t.checkpointMetaById,t.checkpointIndexByKey,t.attemptMetaById,t.userMessageIdToAttempts])}const up=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,dp=w.memo(function({message:t,index:n,isStreaming:r,streamingAssistantId:o,streamingDebounceMs:s,layoutSize:i,enableMessageEditing:a,editingMessageId:l,onEdit:c,onRegenerate:d,onCancelEdit:f,activeInterrupt:p,disableInterruptActions:h,onInterruptActionStart:x,onInterruptActionEnd:m,showToolMessages:y,showArtifactPreviews:g,checkpointMetaById:b,checkpointIndexByKey:S,attemptMetaById:k,userMessageIdToAttempts:C,activeCheckpointId:T,onSelectCheckpoint:I}){const A=up(t,n),R="type"in t&&t.type==="default_message",{checkpointCandidates:L,defaultCheckpointId:P,attemptMeta:D}=GS(t,{checkpointMetaById:b,checkpointIndexByKey:S,attemptMetaById:k,userMessageIdToAttempts:C}),F=t&&!R?t.additionalKwargs??{}:{},N=t&&!R?t.responseMetadata??{}:{},B=(()=>{if(typeof F.parentCheckpointId=="string")return F.parentCheckpointId;if(typeof N.parentCheckpointId=="string")return N.parentCheckpointId})();return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":A,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Ds,{message:t,messageIndex:n,isStreamingMessage:r&&o===t.id,streamingDebounceMs:s,isEditing:l===t.id,showActions:a,showTimestamp:!1,showAgentName:!0,layoutSize:i,onEdit:c,onRegenerate:()=>d(n),onCancelEdit:f,activeInterrupt:p,disableInterruptActions:h,onInterruptActionStart:x,onInterruptActionEnd:m,showToolMessages:y,showArtifactPreviews:g,checkpointCandidates:L,activeCheckpointId:T??null,onSelectCheckpoint:I,defaultCheckpointId:P,messageParentCheckpointId:B,attemptMeta:D})})});dp.displayName="MessageRow";const ja=w.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:c,onCancelEdit:d,className:f,style:p,emptyMessage:h,followNewMessages:x=!0,isNavigatingCheckpoint:m=!1,onScrollAway:y,onAtBottom:g,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T=!0,showArtifactPreviews:I=!0,checkpointMetaById:A,checkpointIndexByKey:R,attemptMetaById:L,userMessageIdToAttempts:P,activeCheckpointId:D,onSelectCheckpoint:F,createSyntheticThinkingMessage:N=!1},B)=>{const j=w.useRef(null),V=w.useRef(null),z=w.useRef(!1),M=w.useRef(!1),[q,J]=w.useState(!0),se=w.useMemo(()=>b?e.some(re=>"type"in re&&re.type==="default_message"?!1:Array.isArray(re==null?void 0:re.content)&&re.content.some(xe=>xe&&xe.type==="interrupt"&&(xe.id??xe.interrupt_id)===b.id)):!1,[b,e]),ge=w.useMemo(()=>{if(!b||se)return null;const re=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let xe;const Pe=b.value;if(Pe&&typeof Pe=="object"&&!Array.isArray(Pe)){const Ze=Pe.title;typeof Ze=="string"&&Ze.trim()&&(xe=Ze.trim())}return{id:`interrupt-${re}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:re,value:Pe,title:xe}]}},[b,se]),Ee=w.useMemo(()=>ge?[...e,ge]:e,[e,ge]),Y=w.useMemo(()=>!N||!t?Ee:!Ee.some(xe=>xe.role==="assistant")&&Ee.length>0?[...Ee,{id:"thinking-assistant",role:"assistant",content:[],createdAt:new Date().toISOString()}]:Ee,[Ee,t,N]),U=w.useMemo(()=>T?Y:Y.filter(re=>(re==null?void 0:re.role)!=="tool"),[Y,T]),Z=w.useCallback(re=>{J(re),y&&y(!re),g&&g(re)},[y,g]),$=w.useMemo(()=>{if(a)return async()=>{if(!z.current){z.current=!0;try{await a()}finally{z.current=!1}}}},[a]),K=w.useMemo(()=>!x||m?!1:q?"auto":!1,[q,x,m]),Q=w.useMemo(()=>{if(typeof h!="string")return null;const re=h.trim();return re?{id:"default-message",role:"assistant",type:"default_message",content:re,createdAt:new Date().toISOString()}:null},[h]),ce=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),oe=()=>Q?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Ds,{message:Q,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{},showArtifactPreviews:I})})}):u.jsx("div",{className:"flex h-full items-center justify-center py-8 text-center text-muted-foreground",children:h??"No messages yet. Start a conversation!"}),Ne=U.length,Ue=Ne>0;return w.useEffect(()=>{var re,xe;if(Ne===0){M.current=!1;return}M.current||(M.current=!0,j.current?(xe=(re=j.current).scrollToIndex)==null||xe.call(re,{index:0,align:"start",behavior:"auto"}):V.current&&(V.current.scrollTop=0))},[Ne]),w.useImperativeHandle(B,()=>({scrollToLatest:()=>{var re,xe;if(j.current&&U.length>0){const Pe=U.length-1;(xe=(re=j.current).scrollToIndex)==null||xe.call(re,{index:Pe,align:"end",behavior:"auto"})}else V.current&&(V.current.scrollTop=V.current.scrollHeight)},scrollToTop:()=>{var re,xe;j.current&&U.length>0?(xe=(re=j.current).scrollToIndex)==null||xe.call(re,{index:0,align:"start",behavior:"auto"}):V.current&&(V.current.scrollTop=0)}}),[U]),u.jsx("div",{className:ce,style:p,children:u.jsx("div",{className:"relative flex-1 min-h-0",children:Ue?u.jsx(E0,{ref:re=>{j.current=re},scrollerRef:re=>{V.current=re instanceof HTMLDivElement?re:null},data:U,followOutput:K,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,startReached:()=>{$&&$()},atBottomStateChange:Z,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(re,xe)=>up(xe,re),itemContent:(re,xe)=>u.jsx(dp,{message:xe,index:re,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onEdit:l,onRegenerate:c,onCancelEdit:d,activeInterrupt:b,disableInterruptActions:S,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T,showArtifactPreviews:I,checkpointMetaById:A,checkpointIndexByKey:R,attemptMetaById:L,userMessageIdToAttempts:P,activeCheckpointId:D,onSelectCheckpoint:F})}):oe()})})});ja.displayName="MessageList";const fp={value:""};function Ls({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:c=!0,showToolMessages:d=!0,showArtifactPreviews:f=!0,customStyles:p={},onMessageSent:h,onExcelUploadSuccess:x,onError:m}){const{api:y}=ui(),{currentThreadId:g}=_o(),{threadId:b,messages:S,isHistoryLoading:k,isLoading:C,navigateToCheckpoint:T,returnToLatest:I,checkpoint:A,checkpoints:R,interrupt:L,metadata:P,timelineCheckpoints:D,messagePreviews:F}=jo(),{isStreaming:N,error:B,connectionState:j,submit:V,stop:z}=ac(),M=b??g??null,q=(A==null?void 0:A.id)??null,J=(A==null?void 0:A.namespace)??null,se=(P==null?void 0:P.assemblingMessageId)??null,ge=L,[Ee,Y]=w.useState(!1);w.useEffect(()=>{ge||Y(!1)},[ge]);const U=w.useCallback(()=>{Y(!0)},[]),Z=w.useCallback(()=>{Y(!1)},[]),$=!!ge||Ee,[K,Q]=w.useState(null),[ce,oe]=w.useState(""),[Ne,Ue]=w.useState(null),[re,xe]=w.useState(null),[Pe,Ze]=w.useState([]),[Qe,Ve]=w.useState(0),[tt,it]=w.useState(0),[qe,nt]=w.useState(!1),[at,Rt]=w.useState(null),[gt,ht]=w.useState(null),[bt,St]=w.useState(!1),[Lt,Mt]=w.useState(null),et=w.useRef(!1),[It,bn]=w.useState(()=>fp.value),Ge=w.useRef(It),Ye=w.useRef(null),pt=w.useCallback(fe=>{fp.value=fe,bn(fe)},[]),[lt,G]=w.useState(!1),_=w.useRef(null),{checkpointMetaById:X,checkpointIndexByKey:te,attemptMetaById:pe,userMessageIdToAttempts:ve}=hw(R),we=D??[],Fe=w.useRef(null),Oe=w.useRef(null),je=w.useCallback(()=>{Fe.current&&(Fe.current.value=""),Oe.current&&(Oe.current.value=""),Ve(fe=>fe+1),it(fe=>fe+1)},[]),Vt=w.useCallback(fe=>{pt(fe)},[pt]),En=w.useRef(!1);w.useEffect(()=>{En.current&&!N&&(Ze([]),je()),En.current=N},[N,je]);const[ir,Ar]=w.useState("desktop");w.useEffect(()=>{const fe=()=>{const Se=window.innerWidth;Ar(Se<640?"phone":Se<1024?"tablet":"desktop")};return fe(),window.addEventListener("resize",fe),()=>window.removeEventListener("resize",fe)},[]),w.useEffect(()=>{et.current=!1},[M]),w.useEffect(()=>{Ge.current=It},[It]),w.useEffect(()=>{if(!K){Ye.current=null;return}Ye.current===null&&(Ye.current=Ge.current),pt(ce??"")},[ce,K,pt]),w.useEffect(()=>{(async()=>{if(!y.baseUrl){Mt(null);return}try{const Ie=(await y.getAgent("default")).uiDefaultMessage||"";Mt(Ie||null)}catch(Se){console.warn("Failed to fetch default message:",Se),Mt(null)}})()},[y.baseUrl]),w.useEffect(()=>{B&&!bt&&(m==null||m(B))},[B,bt,m]);const fo=fe=>{if(fe.length>cs)return`Message too long (${fe.length}/${cs} characters)`;try{return xw(fe),null}catch(Se){return(Se==null?void 0:Se.message)||"Invalid message"}},zn=async fe=>{const Se=fe.trim();if(!(!Se&&Pe.length===0)){if(Se){const Ie=fo(Se);if(Ie){xe(Ie);return}}try{const Ie=K?(Ne==null?void 0:Ne.checkpointId)??q??void 0:q??void 0,He=K?(Ne==null?void 0:Ne.checkpointNs)??J??void 0:J??void 0;await V({text:Se||"",attachments:Pe},{checkpointId:Ie,checkpointNs:He,edit:!!K,originalMessageId:K??void 0}),h==null||h(Se),pt(""),xe(null),Ze([]),je(),Q(null),oe(""),Ue(null)}catch(Ie){const He=(Ie==null?void 0:Ie.message)||"Failed to send message";xe(He),m==null||m(He)}}},ar=w.useCallback((fe,Se,Ie)=>{c&&(Ye.current=It,Q(fe),oe(Se),pt(Se),xe(null),Ue({checkpointId:(Ie==null?void 0:Ie.checkpointId)??null,checkpointNs:(Ie==null?void 0:Ie.checkpointNs)??null}))},[It,c,pt]),E=w.useCallback(()=>{Q(null),oe(""),Ue(null),xe(null),pt(Ye.current??It),Ye.current=null},[It,pt]),W=w.useCallback((fe,Se,Ie)=>{ar(fe,Se,Ie)},[ar]),ie=w.useCallback(fe=>{let Se=null;for(let tn=fe-1;tn>=0;tn--)if(S[tn].role==="user"){Se=S[tn];break}if(!Se)return;const Ie=Array.isArray(Se.content)?Se.content:[],Un=Ie.filter(tn=>(tn==null?void 0:tn.type)==="text").map(tn=>tn.text).join("")||(()=>{try{return JSON.stringify(Ie,null,2)}catch{return String(Ie)}})();Un&&V({text:Un},{checkpointId:q??void 0,checkpointNs:J??void 0,edit:!0,originalMessageId:Se.id})},[S,V,q,J]),be=fe=>{const Se=Array.from(fe.target.files||[]);Ze(Ie=>[...Ie,...Se]),fe.target.value=""},Ke=fe=>{Ze(Se=>{const Ie=Se.filter((He,Un)=>fe!==Un);return Ie.length===0&&je(),Ie})},rt=async fe=>{const Se=(fe.target.files||[])[0];if(Se){Rt(null),ht(null),nt(!0);try{await V({attachments:[Se]},{checkpointId:q??void 0,checkpointNs:J??void 0});const Ie=`Uploaded ${Se.name} - processing through chat stream`;ht(Ie)}catch(Ie){const He=Ie instanceof Error?Ie.message:"Failed to upload Excel file";console.error("Excel upload failed",Ie),Rt(He),m==null||m(He)}finally{nt(!1),fe.target.value="",je()}}},$e=async fe=>{if(g){G(!0);try{if(!fe){await I(),requestAnimationFrame(()=>{var He;(He=_.current)==null||He.scrollToLatest()});return}const Se=R.find(He=>He.checkpointId===fe),Ie=(Se==null?void 0:Se.checkpointNs)??null;await T(fe,Ie),requestAnimationFrame(()=>{var He;(He=_.current)==null||He.scrollToTop()})}finally{G(!1)}}},Le=w.useCallback(async(fe,Se,Ie)=>{await $e(Ie?null:fe)},[$e]),Et=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${p.container||""}`,mt=`flex-1 min-h-0 min-w-0 max-h-full w-full overflow-hidden overscroll-contain break-words break-anywhere p-4 bg-transparent ${p.messagesArea||""}`,xt=`relative flex-shrink-0 w-full border-t p-4 bg-transparent ${p.inputArea||""}`;return u.jsxs("div",{className:Et,children:[!!B&&!bt&&u.jsxs("div",{className:"flex-shrink-0 bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[u.jsx("span",{children:B}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>St(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(ae.X,{size:16})})]}),u.jsxs("div",{className:`relative ${mt}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(ja,{ref:_,className:"h-full",style:{height:"100%"},messages:S,isStreaming:N,streamingAssistantId:se,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:ir,enableMessageEditing:c,editingMessageId:K,onEdit:W,onRegenerate:ie,onCancelEdit:E,emptyMessage:Lt??void 0,isNavigatingCheckpoint:lt,activeInterrupt:ge,disableInterruptActions:Ee,onInterruptActionStart:U,onInterruptActionEnd:Z,showToolMessages:d,showArtifactPreviews:f,checkpointMetaById:X,checkpointIndexByKey:te,attemptMetaById:pe,userMessageIdToAttempts:ve,activeCheckpointId:q,onSelectCheckpoint:Le,timelineCheckpoints:we,messagePreviews:F}),(j==="reconnecting"||j==="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(ae.Loader2,{className:"h-3 w-3 animate-spin"}),j==="reconnecting"?"Reconnecting…":"Connecting…"]})}),j==="error"&&u.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-destructive/10 px-3 py-1 text-xs font-semibold text-destructive shadow-sm",children:"Connection lost"}),C&&u.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[u.jsx(ae.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(ae.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading checkpoint…"})]})]}),u.jsxs("div",{className:xt,children:[K&&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(ae.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:E,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(ae.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:Fe,type:"file",multiple:!0,onChange:fe=>be(fe),className:"hidden"},Qe),Pe.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:Pe.map((fe,Se)=>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(ae.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:fe.name}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>Ke(Se),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 ${fe.name}`,children:u.jsx(ae.X,{size:12})})]},Se))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:Oe,type:"file",accept:".xls,.xlsx,.xlsm",onChange:rt,className:"hidden"},tt),qe&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(ae.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),gt&&!qe&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:gt}),at&&!qe&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:at})]})]}),re&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:re}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(ew,{children:[u.jsx(tw,{asChild:!0,children:u.jsx(Xe,{type:"button",size:"icon",variant:"outline",disabled:N||$,title:"More input actions",className:p.moreButton||"",children:u.jsx(ae.Plus,{size:16})})}),u.jsxs(yd,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(Zi,{onClick:()=>{var fe;return(fe=Fe.current)==null?void 0:fe.click()},className:"cursor-pointer",children:[u.jsx(ae.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(Zi,{onClick:()=>{var fe;qe||(fe=Oe.current)==null||fe.click()},className:`cursor-pointer ${qe?"opacity-60 pointer-events-none":""}`,children:[u.jsx(ae.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(tx,{initialValue:ce,editingMessageId:K,value:It,onValueChange:Vt,placeholder:K?"Edit your message...":t,isStreaming:N,disabled:$,maxLength:cs,onSend:zn,onCancelEdit:E,onStop:z,allowEmptySend:Pe.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${K?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${re?"border-red-400":""} ${p.textarea||""}`})})]})]})]})}const $s=v.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:ne("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}));$s.displayName="Input";function Ra(e,[t,n]){return Math.min(n,Math.max(t,e))}function YS(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Ma="ScrollArea",[pp,FT]=Sn(Ma),[XS,Qt]=pp(Ma),hp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=v.useState(null),[c,d]=v.useState(null),[f,p]=v.useState(null),[h,x]=v.useState(null),[m,y]=v.useState(null),[g,b]=v.useState(0),[S,k]=v.useState(0),[C,T]=v.useState(!1),[I,A]=v.useState(!1),R=Be(t,P=>l(P)),L=Mo(o);return u.jsx(XS,{scope:n,type:r,dir:L,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:p,scrollbarX:h,onScrollbarXChange:x,scrollbarXEnabled:C,onScrollbarXEnabledChange:T,scrollbarY:m,onScrollbarYChange:y,scrollbarYEnabled:I,onScrollbarYEnabledChange:A,onCornerWidthChange:b,onCornerHeightChange:k,children:u.jsx(_e.div,{dir:L,...i,ref:R,style:{position:"relative","--radix-scroll-area-corner-width":g+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});hp.displayName=Ma;var mp="ScrollAreaViewport",gp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=Qt(mp,n),a=v.useRef(null),l=Be(t,a,i.onViewportChange);return u.jsxs(u.Fragment,{children:[u.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-scroll-area-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-scroll-area-viewport]::-webkit-scrollbar{display:none}"},nonce:o}),u.jsx(_e.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:u.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});gp.displayName=mp;var vn="ScrollAreaScrollbar",Pa=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Qt(vn,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(JS,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(ZS,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(xp,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Oa,{...r,ref:t}):null});Pa.displayName=vn;var JS=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Qt(vn,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(Yt,{present:n||s,children:u.jsx(xp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),ZS=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Qt(vn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Us(()=>l("SCROLL_END"),100),[a,l]=YS("hidden",{hidden:{SCROLL:"scrolling"},scrolling:{SCROLL_END:"idle",POINTER_ENTER:"interacting"},interacting:{SCROLL:"interacting",POINTER_LEAVE:"idle"},idle:{HIDE:"hidden",SCROLL:"scrolling",POINTER_ENTER:"interacting"}});return v.useEffect(()=>{if(a==="idle"){const c=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[a,o.scrollHideDelay,l]),v.useEffect(()=>{const c=o.viewport,d=s?"scrollLeft":"scrollTop";if(c){let f=c[d];const p=()=>{const h=c[d];f!==h&&(l("SCROLL"),i()),f=h};return c.addEventListener("scroll",p),()=>c.removeEventListener("scroll",p)}},[o.viewport,s,l,i]),u.jsx(Yt,{present:n||a!=="hidden",children:u.jsx(Oa,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:de(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:de(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),xp=v.forwardRef((e,t)=>{const n=Qt(vn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=v.useState(!1),a=e.orientation==="horizontal",l=Us(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:d)}},10);return kr(n.viewport,l),kr(n.content,l),u.jsx(Yt,{present:r||s,children:u.jsx(Oa,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Oa=v.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=Qt(vn,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=Sp(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:c>0&&c<1,onThumbChange:p=>s.current=p,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:p=>i.current=p};function f(p,h){return oC(p,i.current,a,h)}return n==="horizontal"?u.jsx(QS,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollLeft,h=Cp(p,a,o.dir);s.current.style.transform=`translate3d(${h}px, 0, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollLeft=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollLeft=f(p,o.dir))}}):n==="vertical"?u.jsx(eC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollTop,h=Cp(p,a);s.current.style.transform=`translate3d(0, ${h}px, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollTop=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollTop=f(p))}}):null}),QS=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Qt(vn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=Be(t,l,s.onScrollbarXChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(vp,{"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":zs(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const p=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(p),kp(p,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:Bs(i.paddingLeft),paddingEnd:Bs(i.paddingRight)}})}})}),eC=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Qt(vn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=Be(t,l,s.onScrollbarYChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(vp,{"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":zs(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const p=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(p),kp(p,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:Bs(i.paddingTop),paddingEnd:Bs(i.paddingBottom)}})}})}),[tC,yp]=pp(vn),vp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:c,onWheelScroll:d,onResize:f,...p}=e,h=Qt(vn,n),[x,m]=v.useState(null),y=Be(t,R=>m(R)),g=v.useRef(null),b=v.useRef(""),S=h.viewport,k=r.content-r.viewport,C=kt(d),T=kt(l),I=Us(f,10);function A(R){if(g.current){const L=R.clientX-g.current.left,P=R.clientY-g.current.top;c({x:L,y:P})}}return v.useEffect(()=>{const R=L=>{const P=L.target;(x==null?void 0:x.contains(P))&&C(L,k)};return document.addEventListener("wheel",R,{passive:!1}),()=>document.removeEventListener("wheel",R,{passive:!1})},[S,x,k,C]),v.useEffect(T,[r,T]),kr(x,I),kr(h.content,I),u.jsx(tC,{scope:n,scrollbar:x,hasThumb:o,onThumbChange:kt(s),onThumbPointerUp:kt(i),onThumbPositionChange:T,onThumbPointerDown:kt(a),children:u.jsx(_e.div,{...p,ref:y,style:{position:"absolute",...p.style},onPointerDown:de(e.onPointerDown,R=>{R.button===0&&(R.target.setPointerCapture(R.pointerId),g.current=x.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",h.viewport&&(h.viewport.style.scrollBehavior="auto"),A(R))}),onPointerMove:de(e.onPointerMove,A),onPointerUp:de(e.onPointerUp,R=>{const L=R.target;L.hasPointerCapture(R.pointerId)&&L.releasePointerCapture(R.pointerId),document.body.style.webkitUserSelect=b.current,h.viewport&&(h.viewport.style.scrollBehavior=""),g.current=null})})})}),Fs="ScrollAreaThumb",bp=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=yp(Fs,e.__scopeScrollArea);return u.jsx(Yt,{present:n||o.hasThumb,children:u.jsx(nC,{ref:t,...r})})}),nC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=Qt(Fs,n),i=yp(Fs,n),{onThumbPositionChange:a}=i,l=Be(t,f=>i.onThumbChange(f)),c=v.useRef(void 0),d=Us(()=>{c.current&&(c.current(),c.current=void 0)},100);return v.useEffect(()=>{const f=s.viewport;if(f){const p=()=>{if(d(),!c.current){const h=sC(f,a);c.current=h,a()}};return a(),f.addEventListener("scroll",p),()=>f.removeEventListener("scroll",p)}},[s.viewport,d,a]),u.jsx(_e.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:l,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:de(e.onPointerDownCapture,f=>{const h=f.target.getBoundingClientRect(),x=f.clientX-h.left,m=f.clientY-h.top;i.onThumbPointerDown({x,y:m})}),onPointerUp:de(e.onPointerUp,i.onThumbPointerUp)})});bp.displayName=Fs;var Da="ScrollAreaCorner",wp=v.forwardRef((e,t)=>{const n=Qt(Da,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(rC,{...e,ref:t}):null});wp.displayName=Da;var rC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=Qt(Da,n),[s,i]=v.useState(0),[a,l]=v.useState(0),c=!!(s&&a);return kr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),kr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?u.jsx(_e.div,{...r,ref:t,style:{width:s,height:a,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function Bs(e){return e?parseInt(e,10):0}function Sp(e,t){const n=e/t;return isNaN(n)?0:n}function zs(e){const t=Sp(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function oC(e,t,n,r="ltr"){const o=zs(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 Tp([l,c],f)(e)}function Cp(e,t,n="ltr"){const r=zs(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=Ra(e,l);return Tp([0,i],[0,a])(c)}function Tp(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 kp(e,t){return e>0&&e<t}var sC=(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 Us(e,t){const n=kt(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 kr(e,t){const n=kt(t);Tt(()=>{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 Ip=hp,iC=gp,aC=wp;const Ep=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Ip,{ref:r,className:ne("relative overflow-hidden",e),...n,children:[u.jsx(iC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(Ap,{}),u.jsx(aC,{})]}));Ep.displayName=Ip.displayName;const Ap=v.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(Pa,{ref:r,orientation:t,className:ne("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(bp,{className:"relative flex-1 rounded-full bg-border"})}));Ap.displayName=Pa.displayName;const Np=25;function La({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:c,onThreadDelete:d}){const{threads:f,currentThreadId:p,setCurrentThreadId:h,isLoading:x,actions:m}=_o(),{loadThread:y}=jo(),{createThread:g,deleteThread:b,renameThread:S}=m,[k,C]=w.useState(Array.isArray(f)?f:[]),T=w.useRef(k.length>0),I=w.useRef(null),A=w.useRef(0),[R,L]=w.useState(null),[P,D]=w.useState(""),[F,N]=w.useState(!1);w.useEffect(()=>{const Y=Array.isArray(f)?f:[];if(Y.length>0){T.current=!0,C(Y);return}x||(T.current=!1,C(Y))},[f,x]),w.useEffect(()=>{if(!I.current)return;const Y=I.current.querySelector("[data-radix-scroll-area-viewport]");if(!Y)return;let U=null,Z=null;return U=requestAnimationFrame(()=>{Z=requestAnimationFrame(()=>{Y.scrollTop=A.current})}),()=>{U!==null&&cancelAnimationFrame(U),Z!==null&&cancelAnimationFrame(Z)}},[k]);const B=async Y=>{try{h(Y),await y(Y),a==null||a(Y),l==null||l(Y)}catch(U){console.error("Failed to select thread:",U)}},j=async()=>{try{N(!0);const Y=await g();Y&&(c==null||c(Y),a==null||a(Y))}catch(Y){console.error("Failed to create thread:",Y)}finally{N(!1)}},V=async(Y,U)=>{if(U.stopPropagation(),!!confirm("Delete this thread?")){if(I.current){const Z=I.current.querySelector("[data-radix-scroll-area-viewport]");Z&&(A.current=Z.scrollTop)}try{await b(Y),d==null||d(Y)}catch(Z){console.error("Failed to delete thread:",Z)}}},z=(Y,U)=>{U.stopPropagation(),L(Y.threadId),D(Y.title||`Thread ${Y.threadId.slice(0,8)}`)},M=async Y=>{if(P.trim())try{await S(Y,P.trim()),L(null),D("")}catch(U){console.error("Failed to update title:",U)}},q=()=>{L(null),D("")},J=(Y,U)=>{Y.key==="Enter"?M(U):Y.key==="Escape"&&q()},se=Y=>{if(!Y)return"";try{const U=new Date(Y),$=new Date().getTime()-U.getTime(),K=Math.floor($/(1e3*60*60*24));return K===0?U.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):K===1?"Yesterday":K<7?`${K} days ago`:U.toLocaleDateString()}catch{return""}},ge=Y=>Y.title||`Thread ${Y.threadId.slice(0,8)}`,Ee=Y=>{const U=ge(Y);return U.length<=Np?U:`${U.slice(0,Np)}...`};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(Xe,{onClick:j,disabled:F||x,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:F?"Creating...":"New Chat",children:u.jsx(ae.MessageSquarePlus,{size:20})})}),u.jsx(Ep,{ref:I,className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:u.jsx("div",{className:"p-2 space-y-1 pb-4",children:x?u.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[u.jsx(ae.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(ae.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,U)=>new Date(U.updatedAt||U.createdAt||"").getTime()-new Date(Y.updatedAt||Y.createdAt||"").getTime()).map(Y=>u.jsxs("div",{onClick:()=>B(Y.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??p)===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:R===Y.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:U=>U.stopPropagation(),children:[u.jsx($s,{value:P,onChange:U=>D(U.target.value),onKeyDown:U=>J(U,Y.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:()=>M(Y.threadId),className:"h-6 w-6 p-0",children:u.jsx(ae.Check,{size:12})}),u.jsx(Xe,{variant:"ghost",size:"sm",onClick:q,className:"h-6 w-6 p-0",children:u.jsx(ae.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:Ee(Y)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(ae.Calendar,{size:10}),u.jsx("span",{children:se(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&&R!==Y.threadId&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:U=>z(Y,U),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(ae.Edit3,{size:12})}),n&&u.jsx(Xe,{variant:"ghost",size:"sm",onClick:U=>V(Y.threadId,U),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:u.jsx(ae.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))})})]})}const lC=({timelineEntries:e,activeCheckpointId:t,onSelectCheckpoint:n,messagePreviews:r,className:o})=>{const s=e??[],i=s.length>0,a=w.useMemo(()=>i?[...s].reverse():[],[s,i]),l=t??(s.length?s[s.length-1].id:null);if(!i)return null;const d=["w-32 flex-shrink-0 flex-col border-r border-border/40 pr-2 flex bg-white text-gray-900 dark:bg-slate-900 dark:text-slate-100",o].filter(Boolean).join(" ");return u.jsxs("div",{className:d,children:[u.jsxs("div",{className:"relative flex-1 overflow-y-auto pt-4 pb-2 pr-1",children:[u.jsx("div",{className:"absolute left-0 right-0 top-1 px-2 pb-3 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:u.jsx("span",{children:"Timeline"})}),u.jsx("div",{className:"pointer-events-none absolute left-3 top-0 bottom-0 w-px bg-border/40"}),u.jsx("div",{className:"flex flex-col gap-3 pt-6 pr-2",children:a.map(f=>{const p=l===f.id,h=f.messageId?(r==null?void 0:r.get(f.messageId))??null:null;return u.jsxs("button",{type:"button",disabled:!n,onClick:()=>n==null?void 0:n(f.id),className:`relative flex items-start gap-2 text-left text-[11px] transition ${p?"text-primary":"text-muted-foreground"} ${n?"hover:text-foreground":"cursor-default opacity-70"}`,children:[u.jsx("span",{className:`mt-1 inline-flex h-3 w-3 items-center justify-center rounded-full border ${p?"border-primary bg-primary/10 text-primary":"border-border bg-background"}`,children:u.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${p?"bg-primary":"bg-border"}`})}),u.jsxs("span",{className:"flex-1",children:[u.jsx("span",{className:"block font-medium leading-tight",children:f.label||"User input"}),u.jsxs("span",{className:"text-[9px] uppercase tracking-wide text-muted-foreground/70",children:[f.step!==null?`STEP ${f.step}`:"STEP —",f.next?` - ${f.next}`:""]}),h&&u.jsx("p",{className:"text-[10px] text-muted-foreground/80 mt-1 line-clamp-2",title:h,children:h})]})]},f.id)})})]}),n&&u.jsx("button",{type:"button",onClick:()=>n==null?void 0:n(null),className:"mt-auto mb-3 rounded-md border border-border/70 px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground transition hover:border-foreground/60 hover:text-foreground",children:"Latest"})]})};function Ir(e){if(!(typeof globalThis>"u"))return globalThis[e]}function cC(e){if(typeof e!="string")return;const t=e.trim();if(t)return wn(t)}function _p(){const e=[Ir("__API_BASE_URL__"),Ir("__CHAT_API_BASE_URL__"),Ir("__CHAT_API_URL__")];for(const t of e){const n=cC(t);if(n)return n}}function jp(){const e=[Ir("__API_AUTH_TOKEN__"),Ir("__CHAT_API_KEY__"),Ir("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function Rp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return wn(t);return wn()}function Mp(){const e={},t=_p(),n=jp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Pp(){const e=Mp(),t=An.getAuthToken(),n=_p();return{apiBaseUrl:Rp(e.baseUrl,An.baseUrl,n),apiKey:t||e.apiKey||jp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const Op="chat-settings";function uC(){try{const e=localStorage.getItem(Op);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function dC(e){try{const t={...e,apiBaseUrl:wn(e.apiBaseUrl)};localStorage.setItem(Op,JSON.stringify(t)),t.apiKey&&An.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function fC(){const e=Pp(),t=uC(),n=An.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Rp(An.baseUrl,r,e.apiBaseUrl)}}function pC(e){An.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),dC(e)}var hC="Label",Dp=v.forwardRef((e,t)=>u.jsx(_e.label,{...e,ref:t,onMouseDown:n=>{var o;n.target.closest("button, input, select, textarea")||((o=e.onMouseDown)==null||o.call(e,n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));Dp.displayName=hC;var Lp=Dp;const mC=po.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),en=v.forwardRef(({className:e,...t},n)=>u.jsx(Lp,{ref:n,className:ne(mC(),e),...t}));en.displayName=Lp.displayName;function $p(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 Fp=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"}),gC="VisuallyHidden",xC=v.forwardRef((e,t)=>u.jsx(_e.span,{...e,ref:t,style:{...Fp,...e.style}}));xC.displayName=gC;var yC=[" ","Enter","ArrowUp","ArrowDown"],vC=[" ","Enter"],rr="Select",[Hs,Ws,bC]=xi(rr),[Er,BT]=Sn(rr,[bC,Ko]),Vs=Ko(),[wC,$n]=Er(rr),[SC,CC]=Er(rr),Bp=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:c,name:d,autoComplete:f,disabled:p,required:h,form:x}=e,m=Vs(t),[y,g]=v.useState(null),[b,S]=v.useState(null),[k,C]=v.useState(!1),T=Mo(c),[I,A]=pr({prop:r,defaultProp:o??!1,onChange:s,caller:rr}),[R,L]=pr({prop:i,defaultProp:a,onChange:l,caller:rr}),P=v.useRef(null),D=y?x||!!y.closest("form"):!0,[F,N]=v.useState(new Set),B=Array.from(F).map(j=>j.props.value).join(";");return u.jsx(tu,{...m,children:u.jsxs(wC,{required:h,scope:t,trigger:y,onTriggerChange:g,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:k,onValueNodeHasChildrenChange:C,contentId:Cn(),value:R,onValueChange:L,open:I,onOpenChange:A,dir:T,triggerPointerDownPosRef:P,disabled:p,children:[u.jsx(Hs.Provider,{scope:t,children:u.jsx(SC,{scope:e.__scopeSelect,onNativeOptionAdd:v.useCallback(j=>{N(V=>new Set(V).add(j))},[]),onNativeOptionRemove:v.useCallback(j=>{N(V=>{const z=new Set(V);return z.delete(j),z})},[]),children:n})}),D?u.jsxs(uh,{"aria-hidden":!0,required:h,tabIndex:-1,name:d,autoComplete:f,value:R,onChange:j=>L(j.target.value),disabled:p,form:x,children:[R===void 0?u.jsx("option",{value:""}):null,Array.from(F)]},B):null]})})};Bp.displayName=rr;var zp="SelectTrigger",Up=v.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Vs(n),i=$n(zp,n),a=i.disabled||r,l=Be(t,i.onTriggerChange),c=Ws(n),d=v.useRef("touch"),[f,p,h]=fh(m=>{const y=c().filter(S=>!S.disabled),g=y.find(S=>S.value===i.value),b=ph(y,m,g);b!==void 0&&i.onValueChange(b.value)}),x=m=>{a||(i.onOpenChange(!0),h()),m&&(i.triggerPointerDownPosRef.current={x:Math.round(m.pageX),y:Math.round(m.pageY)})};return u.jsx(nu,{asChild:!0,...s,children:u.jsx(_e.button,{type:"button",role:"combobox","aria-controls":i.contentId,"aria-expanded":i.open,"aria-required":i.required,"aria-autocomplete":"none",dir:i.dir,"data-state":i.open?"open":"closed",disabled:a,"data-disabled":a?"":void 0,"data-placeholder":dh(i.value)?"":void 0,...o,ref:l,onClick:de(o.onClick,m=>{m.currentTarget.focus(),d.current!=="mouse"&&x(m)}),onPointerDown:de(o.onPointerDown,m=>{d.current=m.pointerType;const y=m.target;y.hasPointerCapture(m.pointerId)&&y.releasePointerCapture(m.pointerId),m.button===0&&m.ctrlKey===!1&&m.pointerType==="mouse"&&(x(m),m.preventDefault())}),onKeyDown:de(o.onKeyDown,m=>{const y=f.current!=="";!(m.ctrlKey||m.altKey||m.metaKey)&&m.key.length===1&&p(m.key),!(y&&m.key===" ")&&yC.includes(m.key)&&(x(),m.preventDefault())})})})});Up.displayName=zp;var Hp="SelectValue",Wp=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=$n(Hp,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=Be(t,l.onValueNodeChange);return Tt(()=>{c(d)},[c,d]),u.jsx(_e.span,{...a,ref:f,style:{pointerEvents:"none"},children:dh(l.value)?u.jsx(u.Fragment,{children:i}):s})});Wp.displayName=Hp;var TC="SelectIcon",Vp=v.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(_e.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Vp.displayName=TC;var kC="SelectPortal",Kp=e=>u.jsx(qo,{asChild:!0,...e});Kp.displayName=kC;var or="SelectContent",qp=v.forwardRef((e,t)=>{const n=$n(or,e.__scopeSelect),[r,o]=v.useState();if(Tt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?ho.createPortal(u.jsx(Gp,{scope:e.__scopeSelect,children:u.jsx(Hs.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(Yp,{...e,ref:t})});qp.displayName=or;var cn=10,[Gp,Fn]=Er(or),IC="SelectContentImpl",EC=Hn.createSlot("SelectContent.RemoveScroll"),Yp=v.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:x,hideWhenDetached:m,avoidCollisions:y,...g}=e,b=$n(or,n),[S,k]=v.useState(null),[C,T]=v.useState(null),I=Be(t,Z=>k(Z)),[A,R]=v.useState(null),[L,P]=v.useState(null),D=Ws(n),[F,N]=v.useState(!1),B=v.useRef(!1);v.useEffect(()=>{if(S)return Fi(S)},[S]),bi();const j=v.useCallback(Z=>{const[$,...K]=D().map(oe=>oe.ref.current),[Q]=K.slice(-1),ce=document.activeElement;for(const oe of Z)if(oe===ce||(oe==null||oe.scrollIntoView({block:"nearest"}),oe===$&&C&&(C.scrollTop=0),oe===Q&&C&&(C.scrollTop=C.scrollHeight),oe==null||oe.focus(),document.activeElement!==ce))return},[D,C]),V=v.useCallback(()=>j([A,S]),[j,A,S]);v.useEffect(()=>{F&&V()},[F,V]);const{onOpenChange:z,triggerPointerDownPosRef:M}=b;v.useEffect(()=>{if(S){let Z={x:0,y:0};const $=Q=>{var ce,oe;Z={x:Math.abs(Math.round(Q.pageX)-(((ce=M.current)==null?void 0:ce.x)??0)),y:Math.abs(Math.round(Q.pageY)-(((oe=M.current)==null?void 0:oe.y)??0))}},K=Q=>{Z.x<=10&&Z.y<=10?Q.preventDefault():S.contains(Q.target)||z(!1),document.removeEventListener("pointermove",$),M.current=null};return M.current!==null&&(document.addEventListener("pointermove",$),document.addEventListener("pointerup",K,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",$),document.removeEventListener("pointerup",K,{capture:!0})}}},[S,z,M]),v.useEffect(()=>{const Z=()=>z(!1);return window.addEventListener("blur",Z),window.addEventListener("resize",Z),()=>{window.removeEventListener("blur",Z),window.removeEventListener("resize",Z)}},[z]);const[q,J]=fh(Z=>{const $=D().filter(ce=>!ce.disabled),K=$.find(ce=>ce.ref.current===document.activeElement),Q=ph($,Z,K);Q&&setTimeout(()=>Q.ref.current.focus())}),se=v.useCallback((Z,$,K)=>{const Q=!B.current&&!K;(b.value!==void 0&&b.value===$||Q)&&(R(Z),Q&&(B.current=!0))},[b.value]),ge=v.useCallback(()=>S==null?void 0:S.focus(),[S]),Ee=v.useCallback((Z,$,K)=>{const Q=!B.current&&!K;(b.value!==void 0&&b.value===$||Q)&&P(Z)},[b.value]),Y=r==="popper"?$a:Xp,U=Y===$a?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:x,hideWhenDetached:m,avoidCollisions:y}:{};return u.jsx(Gp,{scope:n,content:S,viewport:C,onViewportChange:T,itemRefCallback:se,selectedItem:A,onItemLeave:ge,itemTextRefCallback:Ee,focusSelectedItem:V,selectedItemText:L,position:r,isPositioned:F,searchRef:q,children:u.jsx(ns,{as:EC,allowPinchZoom:!0,children:u.jsx(Oo,{asChild:!0,trapped:b.open,onMountAutoFocus:Z=>{Z.preventDefault()},onUnmountAutoFocus:de(o,Z=>{var $;($=b.trigger)==null||$.focus({preventScroll:!0}),Z.preventDefault()}),children:u.jsx(Po,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:Z=>Z.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:u.jsx(Y,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:Z=>Z.preventDefault(),...g,...U,onPlaced:()=>N(!0),ref:I,style:{display:"flex",flexDirection:"column",outline:"none",...g.style},onKeyDown:de(g.onKeyDown,Z=>{const $=Z.ctrlKey||Z.altKey||Z.metaKey;if(Z.key==="Tab"&&Z.preventDefault(),!$&&Z.key.length===1&&J(Z.key),["ArrowUp","ArrowDown","Home","End"].includes(Z.key)){let Q=D().filter(ce=>!ce.disabled).map(ce=>ce.ref.current);if(["ArrowUp","End"].includes(Z.key)&&(Q=Q.slice().reverse()),["ArrowUp","ArrowDown"].includes(Z.key)){const ce=Z.target,oe=Q.indexOf(ce);Q=Q.slice(oe+1)}setTimeout(()=>j(Q)),Z.preventDefault()}})})})})})})});Yp.displayName=IC;var AC="SelectItemAlignedPosition",Xp=v.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=$n(or,n),i=Fn(or,n),[a,l]=v.useState(null),[c,d]=v.useState(null),f=Be(t,I=>d(I)),p=Ws(n),h=v.useRef(!1),x=v.useRef(!0),{viewport:m,selectedItem:y,selectedItemText:g,focusSelectedItem:b}=i,S=v.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&m&&y&&g){const I=s.trigger.getBoundingClientRect(),A=c.getBoundingClientRect(),R=s.valueNode.getBoundingClientRect(),L=g.getBoundingClientRect();if(s.dir!=="rtl"){const ce=L.left-A.left,oe=R.left-ce,Ne=I.left-oe,Ue=I.width+Ne,re=Math.max(Ue,A.width),xe=window.innerWidth-cn,Pe=Ra(oe,[cn,Math.max(cn,xe-re)]);a.style.minWidth=Ue+"px",a.style.left=Pe+"px"}else{const ce=A.right-L.right,oe=window.innerWidth-R.right-ce,Ne=window.innerWidth-I.right-oe,Ue=I.width+Ne,re=Math.max(Ue,A.width),xe=window.innerWidth-cn,Pe=Ra(oe,[cn,Math.max(cn,xe-re)]);a.style.minWidth=Ue+"px",a.style.right=Pe+"px"}const P=p(),D=window.innerHeight-cn*2,F=m.scrollHeight,N=window.getComputedStyle(c),B=parseInt(N.borderTopWidth,10),j=parseInt(N.paddingTop,10),V=parseInt(N.borderBottomWidth,10),z=parseInt(N.paddingBottom,10),M=B+j+F+z+V,q=Math.min(y.offsetHeight*5,M),J=window.getComputedStyle(m),se=parseInt(J.paddingTop,10),ge=parseInt(J.paddingBottom,10),Ee=I.top+I.height/2-cn,Y=D-Ee,U=y.offsetHeight/2,Z=y.offsetTop+U,$=B+j+Z,K=M-$;if($<=Ee){const ce=P.length>0&&y===P[P.length-1].ref.current;a.style.bottom="0px";const oe=c.clientHeight-m.offsetTop-m.offsetHeight,Ne=Math.max(Y,U+(ce?ge:0)+oe+V),Ue=$+Ne;a.style.height=Ue+"px"}else{const ce=P.length>0&&y===P[0].ref.current;a.style.top="0px";const Ne=Math.max(Ee,B+m.offsetTop+(ce?se:0)+U)+K;a.style.height=Ne+"px",m.scrollTop=$-Ee+m.offsetTop}a.style.margin=`${cn}px 0`,a.style.minHeight=q+"px",a.style.maxHeight=D+"px",r==null||r(),requestAnimationFrame(()=>h.current=!0)}},[p,s.trigger,s.valueNode,a,c,m,y,g,s.dir,r]);Tt(()=>S(),[S]);const[k,C]=v.useState();Tt(()=>{c&&C(window.getComputedStyle(c).zIndex)},[c]);const T=v.useCallback(I=>{I&&x.current===!0&&(S(),b==null||b(),x.current=!1)},[S,b]);return u.jsx(_C,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:h,onScrollButtonChange:T,children:u.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:k},children:u.jsx(_e.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Xp.displayName=AC;var NC="SelectPopperPosition",$a=v.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=cn,...s}=e,i=Vs(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)"}})});$a.displayName=NC;var[_C,Fa]=Er(or,{}),Ba="SelectViewport",Jp=v.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Fn(Ba,n),i=Fa(Ba,n),a=Be(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(Hs.Slot,{scope:n,children:u.jsx(_e.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:de(o.onScroll,c=>{const d=c.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:p}=i;if(p!=null&&p.current&&f){const h=Math.abs(l.current-d.scrollTop);if(h>0){const x=window.innerHeight-cn*2,m=parseFloat(f.style.minHeight),y=parseFloat(f.style.height),g=Math.max(m,y);if(g<x){const b=g+h,S=Math.min(x,b),k=b-S;f.style.height=S+"px",f.style.bottom==="0px"&&(d.scrollTop=k>0?k:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});Jp.displayName=Ba;var Zp="SelectGroup",[jC,RC]=Er(Zp),MC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Cn();return u.jsx(jC,{scope:n,id:o,children:u.jsx(_e.div,{role:"group","aria-labelledby":o,...r,ref:t})})});MC.displayName=Zp;var Qp="SelectLabel",eh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=RC(Qp,n);return u.jsx(_e.div,{id:o.id,...r,ref:t})});eh.displayName=Qp;var Ks="SelectItem",[PC,th]=Er(Ks),nh=v.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=$n(Ks,n),l=Fn(Ks,n),c=a.value===r,[d,f]=v.useState(s??""),[p,h]=v.useState(!1),x=Be(t,b=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,b,r,o)}),m=Cn(),y=v.useRef("touch"),g=()=>{o||(a.onValueChange(r),a.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return u.jsx(PC,{scope:n,value:r,disabled:o,textId:m,isSelected:c,onItemTextChange:v.useCallback(b=>{f(S=>S||((b==null?void 0:b.textContent)??"").trim())},[]),children:u.jsx(Hs.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(_e.div,{role:"option","aria-labelledby":m,"data-highlighted":p?"":void 0,"aria-selected":c&&p,"data-state":c?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:x,onFocus:de(i.onFocus,()=>h(!0)),onBlur:de(i.onBlur,()=>h(!1)),onClick:de(i.onClick,()=>{y.current!=="mouse"&&g()}),onPointerUp:de(i.onPointerUp,()=>{y.current==="mouse"&&g()}),onPointerDown:de(i.onPointerDown,b=>{y.current=b.pointerType}),onPointerMove:de(i.onPointerMove,b=>{var S;y.current=b.pointerType,o?(S=l.onItemLeave)==null||S.call(l):y.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:de(i.onPointerLeave,b=>{var S;b.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:de(i.onKeyDown,b=>{var k;((k=l.searchRef)==null?void 0:k.current)!==""&&b.key===" "||(vC.includes(b.key)&&g(),b.key===" "&&b.preventDefault())})})})})});nh.displayName=Ks;var uo="SelectItemText",rh=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=$n(uo,n),a=Fn(uo,n),l=th(uo,n),c=CC(uo,n),[d,f]=v.useState(null),p=Be(t,g=>f(g),l.onItemTextChange,g=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,g,l.value,l.disabled)}),h=d==null?void 0:d.textContent,x=v.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:h},l.value),[l.disabled,l.value,h]),{onNativeOptionAdd:m,onNativeOptionRemove:y}=c;return Tt(()=>(m(x),()=>y(x)),[m,y,x]),u.jsxs(u.Fragment,{children:[u.jsx(_e.span,{id:l.textId,...s,ref:p}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?ho.createPortal(s.children,i.valueNode):null]})});rh.displayName=uo;var oh="SelectItemIndicator",sh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return th(oh,n).isSelected?u.jsx(_e.span,{"aria-hidden":!0,...r,ref:t}):null});sh.displayName=oh;var za="SelectScrollUpButton",ih=v.forwardRef((e,t)=>{const n=Fn(za,e.__scopeSelect),r=Fa(za,e.__scopeSelect),[o,s]=v.useState(!1),i=Be(t,r.onScrollButtonChange);return Tt(()=>{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(lh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});ih.displayName=za;var Ua="SelectScrollDownButton",ah=v.forwardRef((e,t)=>{const n=Fn(Ua,e.__scopeSelect),r=Fa(Ua,e.__scopeSelect),[o,s]=v.useState(!1),i=Be(t,r.onScrollButtonChange);return Tt(()=>{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(lh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});ah.displayName=Ua;var lh=v.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Fn("SelectScrollButton",n),i=v.useRef(null),a=Ws(n),l=v.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return v.useEffect(()=>()=>l(),[l]),Tt(()=>{var d;const c=a().find(f=>f.ref.current===document.activeElement);(d=c==null?void 0:c.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),u.jsx(_e.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:de(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:de(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:de(o.onPointerLeave,()=>{l()})})}),OC="SelectSeparator",ch=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(_e.div,{"aria-hidden":!0,...r,ref:t})});ch.displayName=OC;var Ha="SelectArrow",DC=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Vs(n),s=$n(Ha,n),i=Fn(Ha,n);return s.open&&i.position==="popper"?u.jsx(ou,{...o,...r,ref:t}):null});DC.displayName=Ha;var LC="SelectBubbleInput",uh=v.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=v.useRef(null),s=Be(r,o),i=$p(t);return v.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),u.jsx(_e.select,{...n,style:{...Fp,...n.style},ref:s,defaultValue:t})});uh.displayName=LC;function dh(e){return e===""||e===void 0}function fh(e){const t=kt(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 ph(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=$C(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 $C(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var FC=Bp,hh=Up,BC=Wp,zC=Vp,UC=Kp,mh=qp,HC=Jp,gh=eh,xh=nh,WC=rh,VC=sh,yh=ih,vh=ah,bh=ch;const wh=FC,Sh=BC,Wa=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(hh,{ref:r,className:ne("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(zC,{asChild:!0,children:u.jsx(ae.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Wa.displayName=hh.displayName;const Ch=v.forwardRef(({className:e,...t},n)=>u.jsx(yh,{ref:n,className:ne("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ae.ChevronUp,{className:"h-4 w-4"})}));Ch.displayName=yh.displayName;const Th=v.forwardRef(({className:e,...t},n)=>u.jsx(vh,{ref:n,className:ne("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ae.ChevronDown,{className:"h-4 w-4"})}));Th.displayName=vh.displayName;const Va=v.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(UC,{children:u.jsxs(mh,{ref:o,className:ne("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(Ch,{}),u.jsx(HC,{className:ne("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(Th,{})]})}));Va.displayName=mh.displayName;const KC=v.forwardRef(({className:e,...t},n)=>u.jsx(gh,{ref:n,className:ne("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));KC.displayName=gh.displayName;const sr=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(xh,{ref:r,className:ne("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(VC,{children:u.jsx(ae.Check,{className:"h-4 w-4"})})}),u.jsx(WC,{children:t})]}));sr.displayName=xh.displayName;const qC=v.forwardRef(({className:e,...t},n)=>u.jsx(bh,{ref:n,className:ne("-mx-1 my-1 h-px bg-muted",e),...t}));qC.displayName=bh.displayName;var GC="Separator",kh="horizontal",YC=["horizontal","vertical"],Ih=v.forwardRef((e,t)=>{const{decorative:n,orientation:r=kh,...o}=e,s=XC(r)?r:kh,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(_e.div,{"data-orientation":s,...a,...o,ref:t})});Ih.displayName=GC;function XC(e){return YC.includes(e)}var Eh=Ih;const Ah=v.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(Eh,{ref:o,decorative:n,orientation:t,className:ne("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Ah.displayName=Eh.displayName;const JC=Bf,ZC=cS,QC=zf,Nh=v.forwardRef(({className:e,...t},n)=>u.jsx(Es,{className:ne("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}));Nh.displayName=Es.displayName;const eT=po.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"}}),_h=v.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(QC,{children:[u.jsx(Nh,{}),u.jsxs(As,{ref:o,className:ne(eT({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(ae.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));_h.displayName=As.displayName;const jh=({className:e,...t})=>u.jsx("div",{className:ne("flex flex-col space-y-2 text-center sm:text-left",e),...t});jh.displayName="SheetHeader";const Rh=v.forwardRef(({className:e,...t},n)=>u.jsx(tr,{ref:n,className:ne("text-lg font-semibold text-foreground",e),...t}));Rh.displayName=tr.displayName;const Mh=v.forwardRef(({className:e,...t},n)=>u.jsx(Ns,{ref:n,className:ne("text-sm text-muted-foreground",e),...t}));Mh.displayName=Ns.displayName;var qs="Switch",[tT,zT]=Sn(qs),[nT,rT]=tT(qs),Ph=v.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:c,form:d,...f}=e,[p,h]=v.useState(null),x=Be(t,S=>h(S)),m=v.useRef(!1),y=p?d||!!p.closest("form"):!0,[g,b]=pr({prop:o,defaultProp:s??!1,onChange:c,caller:qs});return u.jsxs(nT,{scope:n,checked:g,disabled:a,children:[u.jsx(_e.button,{type:"button",role:"switch","aria-checked":g,"aria-required":i,"data-state":$h(g),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:x,onClick:de(e.onClick,S=>{b(k=>!k),y&&(m.current=S.isPropagationStopped(),m.current||S.stopPropagation())})}),y&&u.jsx(Lh,{control:p,bubbles:!m.current,name:r,value:l,checked:g,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Ph.displayName=qs;var Oh="SwitchThumb",Dh=v.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=rT(Oh,n);return u.jsx(_e.span,{"data-state":$h(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Dh.displayName=Oh;var oT="SwitchBubbleInput",Lh=v.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=v.useRef(null),a=Be(i,s),l=$p(n),c=Vc(t);return v.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,h=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&h){const x=new Event("click",{bubbles:r});h.call(d,n),d.dispatchEvent(x)}},[l,n,r]),u.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...c,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});Lh.displayName=oT;function $h(e){return e?"checked":"unchecked"}var Fh=Ph,sT=Dh;const Bn=v.forwardRef(({className:e,...t},n)=>u.jsx(Fh,{className:ne("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(sT,{className:ne("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")})}));Bn.displayName=Fh.displayName;const iT={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 aT({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}=Aa();w.useEffect(()=>{const y=JSON.stringify(a)!==JSON.stringify(e);d(y)},[a,e]),w.useEffect(()=>{l(e)},[e]);const p=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},h=()=>{l(iT),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},x=()=>{l(e),d(!1),o(!1)},m=async()=>{try{const g=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${g.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return u.jsxs(JC,{open:r,onOpenChange:o,children:[u.jsx(ZC,{asChild:!0,children:u.jsxs(Xe,{variant:"outline",size:"sm",className:n,children:[u.jsx(ae.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(_h,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(jh,{children:[u.jsx(Rh,{children:"Chat Settings"}),u.jsx(Mh,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(ae.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(en,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx($s,{id:"api-url",value:a.api.baseUrl,onChange:y=>l(g=>({...g,api:{...g.api,baseUrl:y.target.value}})),placeholder:"http://localhost:8000/api"}),u.jsx(Xe,{variant:"outline",onClick:m,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(en,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(Bn,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:y=>l(g=>({...g,api:{...g.api,enableAuth:y}}))})]}),a.api.enableAuth&&u.jsxs("div",{className:"space-y-2",children:[u.jsx(en,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx($s,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:y=>l(g=>({...g,api:{...g.api,authToken:y.target.value}})),placeholder:"Enter your Bearer token"}),u.jsx(Xe,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?u.jsx(ae.EyeOff,{className:"h-4 w-4"}):u.jsx(ae.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(ae.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(en,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(wh,{value:a.ui.layout,onValueChange:y=>l(g=>({...g,ui:{...g.ui,layout:y}})),children:[u.jsx(Wa,{children:u.jsx(Sh,{})}),u.jsxs(Va,{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(en,{htmlFor:"theme",children:"Theme"}),u.jsxs(wh,{value:a.ui.theme,onValueChange:y=>l(g=>({...g,ui:{...g.ui,theme:y}})),children:[u.jsx(Wa,{children:u.jsx(Sh,{})}),u.jsxs(Va,{children:[u.jsx(sr,{value:"light",children:"Light"}),u.jsx(sr,{value:"dark",children:"Dark"}),u.jsx(sr,{value:"system",children:"System"})]})]})]}),u.jsx(Ah,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(en,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(Bn,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,showTimestamps:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(en,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(Bn,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,showAgentNames:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(en,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(Bn,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:y=>l(g=>({...g,ui:{...g.ui,compactMessages:y}}))})]})]})]})]}),u.jsxs(io,{children:[u.jsx(ao,{className:"pb-3",children:u.jsxs(lo,{className:"text-lg flex items-center gap-2",children:[u.jsx(ae.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(co,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(en,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(Bn,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:y=>l(g=>({...g,behavior:{...g.behavior,autoSave:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(en,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx(Bn,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:y=>l(g=>({...g,behavior:{...g.behavior,enableStreaming:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(en,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx(Bn,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:y=>l(g=>({...g,behavior:{...g.behavior,showTypingIndicator:y}}))})]})]})]})]}),u.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[u.jsxs(Xe,{variant:"outline",onClick:h,children:[u.jsx(ae.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Xe,{variant:"outline",onClick:x,children:"Cancel"}),u.jsxs(Xe,{onClick:p,disabled:!c,children:[u.jsx(ae.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function lT({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(Ro,{...s,onThreadChange:l,children:u.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:u.jsx(Ls,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?u.jsx(Ro,{...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(La,{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(Ls,{onError:s.onError,enableFileUpload:!0})})]})})}):u.jsx(Ro,{...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(La,{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(Ls,{onError:s.onError,enableFileUpload:!0})})]})})}Ce.ChatApi=Bl,Ce.ChatInput=cc,Ce.ChatInterface=Ls,Ce.ChatProviders=Ro,Ce.ChatSettings=aT,Ce.MarkdownContent=so,Ce.MessageComponent=Ds,Ce.MessageList=ja,Ce.ThreadManager=La,Ce.TimelineColumn=lC,Ce.applySettings=pC,Ce.buildMessagePreviewMap=ql,Ce.chatApiClient=An,Ce.default=lT,Ce.del=Fl,Ce.get=qt,Ce.getChatToken=Dl,Ce.getCurrentSettings=fC,Ce.getDefaultApiConfig=Mp,Ce.getDefaultChatSettings=Pp,Ce.onChatTokenChanged=Ll,Ce.post=ci,Ce.put=$l,Ce.setChatToken=Io,Ce.useApi=ui,Ce.useChatStream=Gl,Ce.useMessagesReducer=Yl,Ce.useStream=ac,Ce.useThreadState=jo,Ce.useThreads=_o,Object.defineProperties(Ce,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/package.json
CHANGED