teodor-new-chat-ui 4.3.353 → 4.3.354

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.
@@ -0,0 +1,7 @@
1
+ import type { ChatMessage } from "@/types/api";
2
+ interface StreamProgressProps {
3
+ message: ChatMessage;
4
+ isStreaming?: boolean;
5
+ }
6
+ export declare function StreamProgress({ message, isStreaming }: StreamProgressProps): import("react/jsx-runtime").JSX.Element | null;
7
+ export {};
@@ -2,6 +2,7 @@ import type { ChatMessage } from "@/types/api";
2
2
  interface ToolComponentProps {
3
3
  message: ChatMessage;
4
4
  viewMode: "preview" | "expanded";
5
+ isStreaming?: boolean;
5
6
  }
6
- export declare function ToolComponent({ message, viewMode }: ToolComponentProps): import("react/jsx-runtime").JSX.Element | null;
7
+ export declare function ToolComponent({ message, viewMode, isStreaming }: ToolComponentProps): import("react/jsx-runtime").JSX.Element;
7
8
  export {};
@@ -1,7 +1,7 @@
1
1
  export { ArtifactPreviewItem } from "./ArtifactPreviewItem";
2
2
  export { InterruptPartRenderer } from "./InterruptPartRenderer";
3
3
  export { SimpleJsonView } from "./SimpleJsonView";
4
- export { StreamComponent } from "./StreamComponent";
4
+ export { StreamProgress } from "./StreamProgress";
5
5
  export { ToolComponent } from "./ToolComponent";
6
6
  export { useFilePreview } from "./useFilePreview";
7
7
  export { UserTextContent } from "./UserTextContent";
package/dist/index.esm.js CHANGED
@@ -14164,86 +14164,86 @@ const lT = "prose prose-sm max-w-none break-words dark:prose-invert prose-headin
14164
14164
  function Rp({ data: e }) {
14165
14165
  return Array.isArray(e) ? e.every((n) => n === null || ["string", "number", "boolean"].includes(typeof n)) ? /* @__PURE__ */ u.jsx("div", { className: lT, children: /* @__PURE__ */ u.jsx("ul", { className: "list-disc pl-5", children: e.map((n, r) => /* @__PURE__ */ u.jsx("li", { children: String(n) }, r)) }) }) : /* @__PURE__ */ u.jsx("pre", { className: "font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words", children: so(e) }) : /* @__PURE__ */ u.jsx("pre", { className: "font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words", children: so(e) });
14166
14166
  }
14167
- function cT({ message: e, viewMode: t }) {
14168
- const r = Gf(e).name || "tool", o = (c) => {
14169
- if (c == null) return null;
14170
- const d = typeof c == "string" ? za(c) ?? c : c;
14171
- if (d && typeof d == "object")
14172
- return /* @__PURE__ */ u.jsx(Rp, { data: d });
14173
- const f = typeof d == "string" ? d : (() => {
14167
+ function cT({ message: e, isStreaming: t = !1 }) {
14168
+ const n = e.name ?? "tool", r = Pe(() => {
14169
+ const a = e.additionalKwargs ?? {};
14170
+ return Array.isArray(a.toolProgress) ? [...a.toolProgress] : [];
14171
+ }, [e]), s = r.some(
14172
+ (a) => a.type === "tool.start" || a.type === "tool.call" || a.type === "message.start"
14173
+ ) ? `Running ${n}…` : void 0;
14174
+ return t || r.length > 0 ? /* @__PURE__ */ u.jsxs("div", { className: "space-y-2", children: [
14175
+ /* @__PURE__ */ u.jsxs("div", { className: "flex items-center gap-2 text-xs uppercase tracking-wide text-muted-foreground", children: [
14176
+ t && /* @__PURE__ */ u.jsx(na, { className: "h-3 w-3 animate-spin" }),
14177
+ /* @__PURE__ */ u.jsx("span", { children: s ?? `Running ${n}…` })
14178
+ ] }),
14179
+ r.length > 0 && /* @__PURE__ */ u.jsx("div", { className: "space-y-2 text-xs text-muted-foreground", children: r.map((a, l) => {
14180
+ var c;
14181
+ return /* @__PURE__ */ u.jsxs(
14182
+ "div",
14183
+ {
14184
+ className: "rounded border border-current/10 bg-muted/60 p-2 text-[11px] leading-snug",
14185
+ children: [
14186
+ /* @__PURE__ */ u.jsxs("div", { className: "mb-1 flex items-center justify-between text-[8px] uppercase tracking-wide text-muted-foreground", children: [
14187
+ /* @__PURE__ */ u.jsx("span", { children: ((c = a.type) == null ? void 0 : c.replace(/\./g, " ")) ?? "progress" }),
14188
+ /* @__PURE__ */ u.jsx("span", { children: a.idx ?? l + 1 })
14189
+ ] }),
14190
+ a.content && /* @__PURE__ */ u.jsx("p", { className: "mt-1 text-[12px] text-foreground/90", children: a.content }),
14191
+ /* @__PURE__ */ u.jsxs("div", { className: "mt-1 flex flex-wrap gap-2 text-[10px] opacity-70", children: [
14192
+ typeof a.factsFound == "number" && /* @__PURE__ */ u.jsxs("span", { children: [
14193
+ "Facts found: ",
14194
+ a.factsFound
14195
+ ] }),
14196
+ typeof a.isSufficient == "boolean" && /* @__PURE__ */ u.jsxs("span", { children: [
14197
+ "Research ",
14198
+ a.isSufficient ? "sufficient" : "needs more data"
14199
+ ] })
14200
+ ] })
14201
+ ]
14202
+ },
14203
+ `tool-progress-${n}-${l}`
14204
+ );
14205
+ }) })
14206
+ ] }) : null;
14207
+ }
14208
+ function uT({ message: e, viewMode: t, isStreaming: n = !1 }) {
14209
+ const o = Gf(e).name || "tool", s = (l) => {
14210
+ if (l == null) return null;
14211
+ const c = typeof l == "string" ? za(l) ?? l : l;
14212
+ if (c && typeof c == "object")
14213
+ return /* @__PURE__ */ u.jsx(Rp, { data: c });
14214
+ const d = typeof c == "string" ? c : (() => {
14174
14215
  try {
14175
- return so(d);
14216
+ return so(c);
14176
14217
  } catch {
14177
- return String(d ?? "");
14218
+ return String(c ?? "");
14178
14219
  }
14179
14220
  })();
14180
- return /* @__PURE__ */ u.jsx("pre", { className: "whitespace-pre-wrap break-words font-sans text-sm text-foreground/90", children: f });
14181
- }, s = (c) => {
14182
- if (c == null) return null;
14183
- const { content: d, isMarkdown: f } = cC(c);
14184
- return f ? /* @__PURE__ */ u.jsx(cs, { content: d, className: "text-current" }) : o(c);
14221
+ return /* @__PURE__ */ u.jsx("pre", { className: "whitespace-pre-wrap break-words font-sans text-sm text-foreground/90", children: d });
14222
+ }, i = (l) => {
14223
+ if (l == null) return null;
14224
+ const { content: c, isMarkdown: d } = cC(l);
14225
+ return d ? /* @__PURE__ */ u.jsx(cs, { content: c, className: "text-current" }) : s(l);
14226
+ }, a = () => {
14227
+ const l = e.content.find((f) => f.type !== "tool_call");
14228
+ if (!l)
14229
+ return /* @__PURE__ */ u.jsx("div", { className: "flex items-center gap-2 text-sm text-muted-foreground", children: /* @__PURE__ */ u.jsxs("span", { children: [
14230
+ "Running ",
14231
+ o,
14232
+ "…"
14233
+ ] }) });
14234
+ if (l.type === "text") {
14235
+ const p = (l.text ?? "").trim();
14236
+ if (!p)
14237
+ return null;
14238
+ const h = ss(p);
14239
+ return i(h);
14240
+ }
14241
+ const c = oo(l), d = ss(c);
14242
+ return i(d);
14185
14243
  };
14186
- if (t === "preview")
14187
- return null;
14188
- const i = e.content.find((c) => c.type !== "tool_call");
14189
- if (!i)
14190
- return /* @__PURE__ */ u.jsx("div", { className: "flex items-center gap-2 text-sm text-muted-foreground", children: /* @__PURE__ */ u.jsxs("span", { children: [
14191
- "Running ",
14192
- r,
14193
- "…"
14194
- ] }) });
14195
- if (i.type === "text") {
14196
- const d = (i.text ?? "").trim();
14197
- if (!d)
14198
- return null;
14199
- const f = ss(d);
14200
- return s(f);
14201
- }
14202
- const a = oo(i), l = ss(a);
14203
- return s(l);
14204
- }
14205
- function uT({ message: e, viewMode: t, isStreaming: n = !1 }) {
14206
- const r = e.name ?? "tool", o = Pe(() => {
14207
- const l = e.additionalKwargs ?? {};
14208
- return Array.isArray(l.toolProgress) ? [...l.toolProgress] : [];
14209
- }, [e]), i = o.some(
14210
- (l) => l.type === "tool.start" || l.type === "tool.call" || l.type === "message.start"
14211
- ) ? `Running ${r}…` : void 0, a = n || o.length > 0;
14212
14244
  return /* @__PURE__ */ u.jsxs("div", { className: "space-y-2", children: [
14213
- a && /* @__PURE__ */ u.jsxs("div", { className: "space-y-2", children: [
14214
- /* @__PURE__ */ u.jsxs("div", { className: "flex items-center gap-2 text-xs uppercase tracking-wide text-muted-foreground", children: [
14215
- n && /* @__PURE__ */ u.jsx(na, { className: "h-3 w-3 animate-spin" }),
14216
- /* @__PURE__ */ u.jsx("span", { children: i ?? `Running ${r}…` })
14217
- ] }),
14218
- o.length > 0 && /* @__PURE__ */ u.jsx("div", { className: "space-y-2 text-xs text-muted-foreground", children: o.map((l, c) => {
14219
- var d;
14220
- return /* @__PURE__ */ u.jsxs(
14221
- "div",
14222
- {
14223
- className: "rounded border border-current/10 bg-muted/60 p-2 text-[11px] leading-snug",
14224
- children: [
14225
- /* @__PURE__ */ u.jsxs("div", { className: "mb-1 flex items-center justify-between text-[8px] uppercase tracking-wide text-muted-foreground", children: [
14226
- /* @__PURE__ */ u.jsx("span", { children: ((d = l.type) == null ? void 0 : d.replace(/\./g, " ")) ?? "progress" }),
14227
- /* @__PURE__ */ u.jsx("span", { children: l.idx ?? c + 1 })
14228
- ] }),
14229
- l.content && /* @__PURE__ */ u.jsx("p", { className: "mt-1 text-[12px] text-foreground/90", children: l.content }),
14230
- /* @__PURE__ */ u.jsxs("div", { className: "mt-1 flex flex-wrap gap-2 text-[10px] opacity-70", children: [
14231
- typeof l.factsFound == "number" && /* @__PURE__ */ u.jsxs("span", { children: [
14232
- "Facts found: ",
14233
- l.factsFound
14234
- ] }),
14235
- typeof l.isSufficient == "boolean" && /* @__PURE__ */ u.jsxs("span", { children: [
14236
- "Research ",
14237
- l.isSufficient ? "sufficient" : "needs more data"
14238
- ] })
14239
- ] })
14240
- ]
14241
- },
14242
- `tool-progress-${r}-${c}`
14243
- );
14244
- }) })
14245
- ] }),
14246
- /* @__PURE__ */ u.jsx(cT, { message: e, viewMode: t })
14245
+ /* @__PURE__ */ u.jsx(cT, { message: e, isStreaming: n }),
14246
+ t === "expanded" && a()
14247
14247
  ] });
14248
14248
  }
14249
14249
  function dT(e) {
package/dist/index.umd.js CHANGED
@@ -133,5 +133,5 @@ ${t}</tr>
133
133
  `}tablecell(t,n){const r=n.header?"th":"td";return(n.align?`<${r} align="${n.align}">`:`<${r}>`)+t+`</${r}>
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=tp(this.options.sanitize,this.options.baseUrl,t),t===null)return r;let o='<a href="'+t+'"';return n&&(o+=' title="'+n+'"'),o+=">"+r+"</a>",o}image(t,n,r){if(t=tp(this.options.sanitize,this.options.baseUrl,t),t===null)return r;let o=`<img src="${t}" alt="${r}"`;return n&&(o+=` title="${n}"`),o+=this.options.xhtml?"/>":">",o}text(t){return t}}class ip{strong(t){return t}em(t){return t}codespan(t){return t}del(t){return t}html(t){return t}text(t){return t}link(t,n,r){return""+r}image(t,n,r){return""+r}br(){return""}}class ap{constructor(){this.seen={}}serialize(t){return t.toLowerCase().trim().replace(/<[!\/a-z].*?>/ig,"").replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g,"").replace(/\s/g,"-")}getNextSafeSlug(t,n){let r=t,o=0;if(this.seen.hasOwnProperty(r)){o=this.seen[t];do o++,r=t+"-"+o;while(this.seen.hasOwnProperty(r))}return n||(this.seen[t]=o,this.seen[r]=0),r}slug(t,n={}){const r=this.serialize(t);return this.getNextSafeSlug(r,n.dryrun)}}class Fn{constructor(t){this.options=t||or,this.options.renderer=this.options.renderer||new Na,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new ip,this.slugger=new ap}static parse(t,n){return new Fn(n).parse(t)}static parseInline(t,n){return new Fn(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,c,d,f,p,h,g,m,y,x,b,S,k,C,T;const E=t.length;for(o=0;o<E;o++){if(h=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[h.type]&&(T=this.options.extensions.renderers[h.type].call({parser:this},h),T!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(h.type))){r+=T||"";continue}switch(h.type){case"space":continue;case"hr":{r+=this.renderer.hr();continue}case"heading":{r+=this.renderer.heading(this.parseInline(h.tokens),h.depth,ep(this.parseInline(h.tokens,this.textRenderer)),this.slugger);continue}case"code":{r+=this.renderer.code(h.text,h.lang,h.escaped);continue}case"table":{for(f="",d="",a=h.header.length,s=0;s<a;s++)d+=this.renderer.tablecell(this.parseInline(h.header[s].tokens),{header:!0,align:h.align[s]});for(f+=this.renderer.tablerow(d),p="",a=h.rows.length,s=0;s<a;s++){for(c=h.rows[s],d="",l=c.length,i=0;i<l;i++)d+=this.renderer.tablecell(this.parseInline(c[i].tokens),{header:!1,align:h.align[i]});p+=this.renderer.tablerow(d)}r+=this.renderer.table(f,p);continue}case"blockquote":{p=this.parse(h.tokens),r+=this.renderer.blockquote(p);continue}case"list":{for(g=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,x="",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}):x+=C),x+=this.parse(b.tokens,y),p+=this.renderer.listitem(x,k,S);r+=this.renderer.list(p,g,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<E&&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 N='Token with "'+h.type+'" type was not found.';if(this.options.silent){console.error(N);return}else throw new Error(N)}}}return r}parseInline(t,n){n=n||this.renderer;let r="",o,s,i;const a=t.length;for(o=0;o<a;o++){if(s=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[s.type]&&(i=this.options.extensions.renderers[s.type].call({parser:this},s),i!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type))){r+=i||"";continue}switch(s.type){case"escape":{r+=n.text(s.text);break}case"html":{r+=n.html(s.text);break}case"link":{r+=n.link(s.href,s.title,this.parseInline(s.tokens,n));break}case"image":{r+=n.image(s.href,s.title,s.text);break}case"strong":{r+=n.strong(this.parseInline(s.tokens,n));break}case"em":{r+=n.em(this.parseInline(s.tokens,n));break}case"codespan":{r+=n.codespan(s.text);break}case"br":{r+=n.br();break}case"del":{r+=n.del(this.parseInline(s.tokens,n));break}case"text":{r+=n.text(s.text);break}default:{const l='Token with "'+s.type+'" type was not found.';if(this.options.silent){console.error(l);return}else throw new Error(l)}}}return r}}class Ds{constructor(t){this.options=t||or}preprocess(t){return t}postprocess(t){return t}}Hh(Ds,"passThroughHooks",new Set(["preprocess","postprocess"]));function tC(e,t,n){return r=>{if(r.message+=`
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 lp(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...xe.defaults,...s};const i=tC(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(ZS(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(f){return i(f)}const c=function(f){let p;if(!f)try{r.walkTokens&&xe.walkTokens(l,r.walkTokens),p=t(l,r),r.hooks&&(p=r.hooks.postprocess(p))}catch(h){f=h}return r.highlight=a,f?i(f):o(null,p)};if(!a||a.length<3||(delete r.highlight,!l.length))return c();let d=0;xe.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(p,h){if(p)return c(p);h!=null&&h!==f.text&&(f.text=h,f.escaped=!0),d--,d===0&&c()})},0))}),d===0&&c();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(xe.walkTokens(a,r.walkTokens)).then(()=>a):a).then(a=>t(a,r)).then(a=>r.hooks?r.hooks.postprocess(a):a).catch(i);try{r.hooks&&(n=r.hooks.preprocess(n));const a=e(n,r);r.walkTokens&&xe.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function xe(e,t,n){return lp($n.lex,Fn.parse)(e,t,n)}xe.options=xe.setOptions=function(e){return xe.defaults={...xe.defaults,...e},FS(xe.defaults),xe},xe.getDefaults=Xf,xe.defaults=or,xe.use=function(...e){const t=xe.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=xe.defaults.async||r.async||!1,n.extensions&&(n.extensions.forEach(o=>{if(!o.name)throw new Error("extension name required");if(o.renderer){const s=t.renderers[o.name];s?t.renderers[o.name]=function(...i){let a=o.renderer.apply(this,i);return a===!1&&(a=s.apply(this,i)),a}:t.renderers[o.name]=o.renderer}if(o.tokenizer){if(!o.level||o.level!=="block"&&o.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");t[o.level]?t[o.level].unshift(o.tokenizer):t[o.level]=[o.tokenizer],o.start&&(o.level==="block"?t.startBlock?t.startBlock.push(o.start):t.startBlock=[o.start]:o.level==="inline"&&(t.startInline?t.startInline.push(o.start):t.startInline=[o.start]))}o.childTokens&&(t.childTokens[o.name]=o.childTokens)}),r.extensions=t),n.renderer){const o=xe.defaults.renderer||new Na;for(const s in n.renderer){const i=o[s];o[s]=(...a)=>{let l=n.renderer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.renderer=o}if(n.tokenizer){const o=xe.defaults.tokenizer||new Aa;for(const s in n.tokenizer){const i=o[s];o[s]=(...a)=>{let l=n.tokenizer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.tokenizer=o}if(n.hooks){const o=xe.defaults.hooks||new Ds;for(const s in n.hooks){const i=o[s];Ds.passThroughHooks.has(s)?o[s]=a=>{if(xe.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(c=>i.call(o,c));const l=n.hooks[s].call(o,a);return i.call(o,l)}:o[s]=(...a)=>{let l=n.hooks[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.hooks=o}if(n.walkTokens){const o=xe.defaults.walkTokens;r.walkTokens=function(s){let i=[];return i.push(n.walkTokens.call(this,s)),o&&(i=i.concat(o.call(this,s))),i}}xe.setOptions(r)})},xe.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(xe,r)),r.type){case"table":{for(const o of r.header)n=n.concat(xe.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(xe.walkTokens(s.tokens,t));break}case"list":{n=n.concat(xe.walkTokens(r.items,t));break}default:xe.defaults.extensions&&xe.defaults.extensions.childTokens&&xe.defaults.extensions.childTokens[r.type]?xe.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(xe.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(xe.walkTokens(r.tokens,t)))}return n},xe.parseInline=lp($n.lexInline,Fn.parseInline),xe.Parser=Fn,xe.parser=Fn.parse,xe.Renderer=Na,xe.TextRenderer=ip,xe.Lexer=$n,xe.lexer=$n.lex,xe.Tokenizer=Aa,xe.Slugger=ap,xe.Hooks=Ds,xe.parse=xe,xe.options,xe.setOptions,xe.use,xe.walkTokens,xe.parseInline,Fn.parse,$n.lex;function io({content:e,className:t="",allowHtml:n=!1,style:r}){const o=w.useMemo(()=>{try{if(!n){const i=e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,"").replace(/javascript:/gi,"").replace(/on\w+\s*=/gi,"");return typeof xe.parse=="function"?xe.parse(i):xe(i)}return typeof xe.parse=="function"?xe.parse(e):xe(e)}catch(i){return console.error("[MarkdownContent] parse error",i),`<pre class="font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words">Error rendering markdown: ${String(i)}</pre>`}},[e,n]),s=w.useMemo(()=>{const i={color:"currentColor",...r};if(r&&r.color){const a=r.color;return{...i,"--tw-prose-body":a,"--tw-prose-headings":a,"--tw-prose-links":a,"--tw-prose-bold":a,"--tw-prose-counters":a,"--tw-prose-bullets":a,"--tw-prose-hr":a,"--tw-prose-quotes":a,"--tw-prose-quote-borders":a,"--tw-prose-captions":a,"--tw-prose-code":a,"--tw-prose-pre-code":a,"--tw-prose-pre-bg":"inherit","--tw-prose-th-borders":a,"--tw-prose-td-borders":a}}return i},[r]);return u.jsx("div",{className:te("markdown prose prose-sm max-w-none break-words","dark:prose-invert","text-current","prose-headings:text-current prose-p:text-current prose-li:text-current prose-a:text-current prose-strong:text-current","prose-em:text-current prose-blockquote:text-current prose-table:text-current prose-td:text-current prose-th:text-current","prose-pre:font-mono prose-pre:text-xs prose-pre:bg-background/50 prose-pre:border prose-pre:rounded prose-pre:p-3 prose-pre:whitespace-pre prose-pre:overflow-x-auto","prose-code:font-mono prose-code:text-sm prose-code:bg-background/50 prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:text-current",t),style:s,dangerouslySetInnerHTML:{__html:o}})}const nC={MODE:"library"};function rC(){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:Xs&&Xs.tagName.toUpperCase()==="SCRIPT"&&Xs.src||new URL("index.umd.js",document.baseURI).href}<"u"?nC: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 oC(){return!rC()}function sC(){return typeof window>"u"?!1:window.__ARTIFACT_DEBUG__===!0}function iC(){return oC()||sC()}function aC({preview:e,idx:t}){return w.useEffect(()=>{iC()&&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 ao=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));ao.displayName="Card";const lo=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("flex flex-col space-y-1.5 p-6",e),...t}));lo.displayName="CardHeader";const co=v.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:te("text-2xl font-semibold leading-none tracking-tight",e),...t}));co.displayName="CardTitle";const cp=v.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:te("text-sm text-muted-foreground",e),...t}));cp.displayName="CardDescription";const uo=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("p-6 pt-0",e),...t}));uo.displayName="CardContent";const up=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("flex items-center p-6 pt-0",e),...t}));up.displayName="CardFooter";function lC({interruptPart:e,onApprove:t,onReject:n,disabled:r,isActive:o,payload:s}){const i=e.title??"Approve the result?";let a=null;if(s!=null)if(typeof s=="string")a=u.jsx("p",{className:"text-sm leading-relaxed text-blue-800/90 dark:text-blue-200/90 whitespace-pre-wrap",children:s});else{const c=oo(s);a=u.jsx("pre",{className:"max-h-48 overflow-auto rounded bg-blue-100/60 p-2 text-xs text-blue-900/90 dark:bg-blue-900/40 dark:text-blue-100/80",children:c})}const l=o?"Please approve or reject this action to resume the workflow.":"Waiting for approval from another participant.";return u.jsxs(ao,{className:te("border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10 transition-shadow",o?"shadow-md ring-1 ring-blue-300 dark:ring-blue-500/70":"opacity-80"),children:[u.jsxs(lo,{className:"pb-3",children:[u.jsx(co,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(cp,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(uo,{className:"pt-0 pb-3",children:a}),u.jsx(up,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(Je,{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(Je,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}const cC="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 dp({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:cC,children:u.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>u.jsx("li",{children:String(n)},r))})}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:oo(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:oo(e)})}function uC({message:e,viewMode:t}){const r=Sf(e).name||"tool",o=c=>{if(c==null)return null;const d=typeof c=="string"?wa(c)??c:c;if(d&&typeof d=="object")return u.jsx(dp,{data:d});const f=typeof d=="string"?d:(()=>{try{return oo(d)}catch{return String(d??"")}})();return u.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm text-foreground/90",children:f})},s=c=>{if(c==null)return null;const{content:d,isMarkdown:f}=uS(c);return f?u.jsx(io,{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.jsx("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:u.jsxs("span",{children:["Running ",r,"…"]})});if(i.type==="text"){const d=(i.text??"").trim();if(!d)return null;const f=Ts(d);return s(f)}const a=ro(i),l=Ts(a);return s(l)}function dC({message:e,viewMode:t,isStreaming:n=!1}){const r=e.name??"tool",o=w.useMemo(()=>{const l=e.additionalKwargs??{};return Array.isArray(l.toolProgress)?[...l.toolProgress]:[]},[e]),i=o.some(l=>l.type==="tool.start"||l.type==="tool.call"||l.type==="message.start")?`Running ${r}…`:void 0,a=n||o.length>0;return u.jsxs("div",{className:"space-y-2",children:[a&&u.jsxs("div",{className:"space-y-2",children:[u.jsxs("div",{className:"flex items-center gap-2 text-xs uppercase tracking-wide text-muted-foreground",children:[n&&u.jsx(le.Loader,{className:"h-3 w-3 animate-spin"}),u.jsx("span",{children:i??`Running ${r}…`})]}),o.length>0&&u.jsx("div",{className:"space-y-2 text-xs text-muted-foreground",children:o.map((l,c)=>{var d;return u.jsxs("div",{className:"rounded border border-current/10 bg-muted/60 p-2 text-[11px] leading-snug",children:[u.jsxs("div",{className:"mb-1 flex items-center justify-between text-[8px] uppercase tracking-wide text-muted-foreground",children:[u.jsx("span",{children:((d=l.type)==null?void 0:d.replace(/\./g," "))??"progress"}),u.jsx("span",{children:l.idx??c+1})]}),l.content&&u.jsx("p",{className:"mt-1 text-[12px] text-foreground/90",children:l.content}),u.jsxs("div",{className:"mt-1 flex flex-wrap gap-2 text-[10px] opacity-70",children:[typeof l.factsFound=="number"&&u.jsxs("span",{children:["Facts found: ",l.factsFound]}),typeof l.isSufficient=="boolean"&&u.jsxs("span",{children:["Research ",l.isSufficient?"sufficient":"needs more data"]})]})]},`tool-progress-${r}-${c}`)})})]}),u.jsx(uC,{message:e,viewMode:t})]})}function fC(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=Ia(),[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,g,m)=>{var y,x;if(!t){h.preventDefault();return}if(o[m]){h.preventDefault();return}try{const b=String(g.url??""),S=b.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){h.preventDefault();const k=S[1],C=g.name||`file_${k}`,T=g.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 vS(n??void 0);if(!C||!Array.isArray(C))throw new Error("Invalid file list response");const T=C.find(E=>!E||typeof E!="object"||!((E.filename??"")===(g.name??""))?!1:typeof g.size=="number"&&typeof E.size=="number"?E.size===g.size:!0);if(!(T!=null&&T.id))throw new Error(`File "${g.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:g.name||T.filename||`file_${T.id}`,mimeType:g.mimeType||T.mime_type||"application/octet-stream"}),(y=k.update)==null||y.call(k,{id:k.id,title:"Success",description:`Opened ${g.name}`,open:!0})}catch(C){console.error("Failed to fetch server file:",C);const T=C instanceof Error?C.message:"Unknown error occurred";(x=k.update)==null||x.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 pC({text:e,expanded:t,onExpandedChange:n,previewLength:r,isCompact:o}){const s=Math.max(e.length-r,0),i=e.substring(0,r);return u.jsxs("div",{className:"flex flex-col gap-1",children:[u.jsx("div",{className:te("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(io,{content:e,allowHtml:!1}):u.jsxs("pre",{className:te("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:[i,"..."]})}),u.jsx(Je,{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(le.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(le.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function hC({className:e}){const[t,n]=w.useState(0);return w.useEffect(()=>{const r=setInterval(()=>n(o=>(o+1)%4),500);return()=>clearInterval(r)},[]),u.jsxs("span",{"aria-live":"polite",className:te("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}function fp(e){var n;const t=(n=e.additionalKwargs)==null?void 0:n.toolProgress;return Array.isArray(t)?t:[]}const Ls=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:g,onRegenerate:m,onCancelEdit:y,onCopy:x,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,checkpointCandidates:T=[],activeCheckpointId:E=null,onSelectCheckpoint:N,defaultCheckpointId:_=null,messageParentCheckpointId:D=null}){const[B,G]=w.useState(!1),[V,R]=w.useState("preview"),[M,A]=w.useState(!1),{currentThreadId:F}=jo(),{respondToInterrupt:L}=Mo(),P=l==="phone"||l==="half-screen",z=t.role,X=z==="tool",ne=w.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),ye=!!ne,Te=!(r&&z!=="user"),{uploadingFiles:q,handleFileClick:U,fileViewerOpen:J,currentFileInfo:$,closeFileViewer:Y}=fC({allowFileOpen:Te,currentThreadId:F}),Z=w.useMemo(()=>{switch(z){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))]"}},[z]),de=w.useMemo(()=>{if(ne)return"";const j=t.content;return Array.isArray(j)?dS(j):""},[ne,t]),oe=w.useMemo(()=>{if(ne)return{};const j=t.content;return Array.isArray(j)?Sf(t):{}},[ne,t]),_e=w.useMemo(()=>X?!!(t.additionalKwargs??{}).toolStreaming:!1,[X,t]),ze=w.useMemo(()=>{if(ne)return[];const j=t.content;return Array.isArray(j)?j.filter(Q=>Q.type==="image_url"):[]},[ne,t]),se=w.useMemo(()=>{if(ne)return[];const j=t.content;return Array.isArray(j)?j.filter(Q=>Q.type==="file"):[]},[ne,t]),me=w.useMemo(()=>{if(ne)return[];const j=t.content;return Array.isArray(j)?j.filter(Q=>Q.type==="interrupt"):[]},[ne,t]),Re=(b==null?void 0:b.id)??(b==null?void 0:b.interrupt_id),Ve=ks(Re),ut=b==null?void 0:b.value,Ke=w.useMemo(()=>{if(ne)return"";const j=t.content;return Array.isArray(j)?fS(j):""},[ne,t]),qe=w.useMemo(()=>{if(ne||!p)return[];const Q=t.artifact;if(!Q)return[];const re=[],ie=[...Array.isArray(Q.plots)?Q.plots:[]];for(const ce of ie){const Xe=xS(ce);Xe&&re.push(Xe)}return re},[ne,t,p]),Qe=w.useCallback(async()=>{const j=X?Ke:de;async function Q(re){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(re);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const ie=new Blob([re],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":ie})]);return}throw new Error("Clipboard API not supported in this context.")}try{await Q(j),G(!0),setTimeout(()=>G(!1),2e3),x==null||x(j)}catch(re){console.error("Failed to copy:",re)}},[X,Ke,de,x]),Ge=w.useCallback(()=>{if(!g)return;const j=X?Ke:de,Q="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};g(t.id,j,Q)},[g,t.id,X,Ke,de,t]),et=w.useCallback(()=>{m==null||m(n)},[m,n]),st=w.useCallback(()=>{const Q=te(P?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",Z);switch(z){case"user":return u.jsx(le.User,{className:Q});case"assistant":return u.jsx(le.Bot,{className:Q});case"tool":return u.jsx(le.Wrench,{className:Q});default:return u.jsx(le.Bot,{className:Q})}},[P,Z,z]),Mt=w.useCallback(()=>{const j="group relative mb-4 flex w-full";switch(z){case"user":return te(j,"justify-end");case"assistant":case"tool":case"system":return te(j,"justify-start");default:return j}},[z]),gt=w.useCallback(()=>{const j=te("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",P&&"px-3 py-2 text-sm");if(ye)return te(j,"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(z){case"user":return te(j,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-user))] text-[hsl(var(--chat-bubble-user-text))]","border border-transparent");case"assistant":return te(j,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40");case"tool":return te(j,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return te(j,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return te(j,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40")}},[P,ye,z]),Ct=w.useCallback(async j=>{if(S)return;const Q=ks((j==null?void 0:j.id)??(j==null?void 0:j.interrupt_id));if(!Q){console.warn("Interrupt part missing id",j);return}try{k==null||k(),await L(Q,!0)}catch(re){console.error("Failed to approve interrupt:",re)}finally{C==null||C()}},[S,C,k,L]),it=w.useCallback(async j=>{if(S)return;const Q=ks((j==null?void 0:j.id)??(j==null?void 0:j.interrupt_id));if(!Q){console.warn("Interrupt part missing id",j);return}try{k==null||k(),await L(Q,!1)}catch(re){console.error("Failed to reject interrupt:",re)}finally{C==null||C()}},[S,C,k,L]),St=w.useCallback(({part:j,i:Q})=>{if(j.type==="text"){const re=j.text??"",ie=re.trim(),ce=wa(ie);return ce&&z!=="tool"?u.jsx(dp,{data:ce},Q):z==="user"&&c&&ie.length>d?u.jsx(pC,{text:ie,expanded:M,onExpandedChange:A,previewLength:d,isCompact:P},Q):u.jsx(io,{content:re,allowHtml:!1},Q)}if(j.type==="image_url"){const re=j;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:re.url,alt:re.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},Q)}if(j.type==="file"){const re=j,ie=re.name||"file";return u.jsxs("a",{href:re.url,onClick:ce=>U(ce.nativeEvent,re,Q),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
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 lp(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...xe.defaults,...s};const i=tC(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(ZS(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(f){return i(f)}const c=function(f){let p;if(!f)try{r.walkTokens&&xe.walkTokens(l,r.walkTokens),p=t(l,r),r.hooks&&(p=r.hooks.postprocess(p))}catch(h){f=h}return r.highlight=a,f?i(f):o(null,p)};if(!a||a.length<3||(delete r.highlight,!l.length))return c();let d=0;xe.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(p,h){if(p)return c(p);h!=null&&h!==f.text&&(f.text=h,f.escaped=!0),d--,d===0&&c()})},0))}),d===0&&c();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(xe.walkTokens(a,r.walkTokens)).then(()=>a):a).then(a=>t(a,r)).then(a=>r.hooks?r.hooks.postprocess(a):a).catch(i);try{r.hooks&&(n=r.hooks.preprocess(n));const a=e(n,r);r.walkTokens&&xe.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function xe(e,t,n){return lp($n.lex,Fn.parse)(e,t,n)}xe.options=xe.setOptions=function(e){return xe.defaults={...xe.defaults,...e},FS(xe.defaults),xe},xe.getDefaults=Xf,xe.defaults=or,xe.use=function(...e){const t=xe.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=xe.defaults.async||r.async||!1,n.extensions&&(n.extensions.forEach(o=>{if(!o.name)throw new Error("extension name required");if(o.renderer){const s=t.renderers[o.name];s?t.renderers[o.name]=function(...i){let a=o.renderer.apply(this,i);return a===!1&&(a=s.apply(this,i)),a}:t.renderers[o.name]=o.renderer}if(o.tokenizer){if(!o.level||o.level!=="block"&&o.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");t[o.level]?t[o.level].unshift(o.tokenizer):t[o.level]=[o.tokenizer],o.start&&(o.level==="block"?t.startBlock?t.startBlock.push(o.start):t.startBlock=[o.start]:o.level==="inline"&&(t.startInline?t.startInline.push(o.start):t.startInline=[o.start]))}o.childTokens&&(t.childTokens[o.name]=o.childTokens)}),r.extensions=t),n.renderer){const o=xe.defaults.renderer||new Na;for(const s in n.renderer){const i=o[s];o[s]=(...a)=>{let l=n.renderer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.renderer=o}if(n.tokenizer){const o=xe.defaults.tokenizer||new Aa;for(const s in n.tokenizer){const i=o[s];o[s]=(...a)=>{let l=n.tokenizer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.tokenizer=o}if(n.hooks){const o=xe.defaults.hooks||new Ds;for(const s in n.hooks){const i=o[s];Ds.passThroughHooks.has(s)?o[s]=a=>{if(xe.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(c=>i.call(o,c));const l=n.hooks[s].call(o,a);return i.call(o,l)}:o[s]=(...a)=>{let l=n.hooks[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.hooks=o}if(n.walkTokens){const o=xe.defaults.walkTokens;r.walkTokens=function(s){let i=[];return i.push(n.walkTokens.call(this,s)),o&&(i=i.concat(o.call(this,s))),i}}xe.setOptions(r)})},xe.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(xe,r)),r.type){case"table":{for(const o of r.header)n=n.concat(xe.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(xe.walkTokens(s.tokens,t));break}case"list":{n=n.concat(xe.walkTokens(r.items,t));break}default:xe.defaults.extensions&&xe.defaults.extensions.childTokens&&xe.defaults.extensions.childTokens[r.type]?xe.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(xe.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(xe.walkTokens(r.tokens,t)))}return n},xe.parseInline=lp($n.lexInline,Fn.parseInline),xe.Parser=Fn,xe.parser=Fn.parse,xe.Renderer=Na,xe.TextRenderer=ip,xe.Lexer=$n,xe.lexer=$n.lex,xe.Tokenizer=Aa,xe.Slugger=ap,xe.Hooks=Ds,xe.parse=xe,xe.options,xe.setOptions,xe.use,xe.walkTokens,xe.parseInline,Fn.parse,$n.lex;function io({content:e,className:t="",allowHtml:n=!1,style:r}){const o=w.useMemo(()=>{try{if(!n){const i=e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,"").replace(/javascript:/gi,"").replace(/on\w+\s*=/gi,"");return typeof xe.parse=="function"?xe.parse(i):xe(i)}return typeof xe.parse=="function"?xe.parse(e):xe(e)}catch(i){return console.error("[MarkdownContent] parse error",i),`<pre class="font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words">Error rendering markdown: ${String(i)}</pre>`}},[e,n]),s=w.useMemo(()=>{const i={color:"currentColor",...r};if(r&&r.color){const a=r.color;return{...i,"--tw-prose-body":a,"--tw-prose-headings":a,"--tw-prose-links":a,"--tw-prose-bold":a,"--tw-prose-counters":a,"--tw-prose-bullets":a,"--tw-prose-hr":a,"--tw-prose-quotes":a,"--tw-prose-quote-borders":a,"--tw-prose-captions":a,"--tw-prose-code":a,"--tw-prose-pre-code":a,"--tw-prose-pre-bg":"inherit","--tw-prose-th-borders":a,"--tw-prose-td-borders":a}}return i},[r]);return u.jsx("div",{className:te("markdown prose prose-sm max-w-none break-words","dark:prose-invert","text-current","prose-headings:text-current prose-p:text-current prose-li:text-current prose-a:text-current prose-strong:text-current","prose-em:text-current prose-blockquote:text-current prose-table:text-current prose-td:text-current prose-th:text-current","prose-pre:font-mono prose-pre:text-xs prose-pre:bg-background/50 prose-pre:border prose-pre:rounded prose-pre:p-3 prose-pre:whitespace-pre prose-pre:overflow-x-auto","prose-code:font-mono prose-code:text-sm prose-code:bg-background/50 prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:text-current",t),style:s,dangerouslySetInnerHTML:{__html:o}})}const nC={MODE:"library"};function rC(){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:Xs&&Xs.tagName.toUpperCase()==="SCRIPT"&&Xs.src||new URL("index.umd.js",document.baseURI).href}<"u"?nC: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 oC(){return!rC()}function sC(){return typeof window>"u"?!1:window.__ARTIFACT_DEBUG__===!0}function iC(){return oC()||sC()}function aC({preview:e,idx:t}){return w.useEffect(()=>{iC()&&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 ao=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));ao.displayName="Card";const lo=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("flex flex-col space-y-1.5 p-6",e),...t}));lo.displayName="CardHeader";const co=v.forwardRef(({className:e,...t},n)=>u.jsx("h3",{ref:n,className:te("text-2xl font-semibold leading-none tracking-tight",e),...t}));co.displayName="CardTitle";const cp=v.forwardRef(({className:e,...t},n)=>u.jsx("p",{ref:n,className:te("text-sm text-muted-foreground",e),...t}));cp.displayName="CardDescription";const uo=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("p-6 pt-0",e),...t}));uo.displayName="CardContent";const up=v.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:te("flex items-center p-6 pt-0",e),...t}));up.displayName="CardFooter";function lC({interruptPart:e,onApprove:t,onReject:n,disabled:r,isActive:o,payload:s}){const i=e.title??"Approve the result?";let a=null;if(s!=null)if(typeof s=="string")a=u.jsx("p",{className:"text-sm leading-relaxed text-blue-800/90 dark:text-blue-200/90 whitespace-pre-wrap",children:s});else{const c=oo(s);a=u.jsx("pre",{className:"max-h-48 overflow-auto rounded bg-blue-100/60 p-2 text-xs text-blue-900/90 dark:bg-blue-900/40 dark:text-blue-100/80",children:c})}const l=o?"Please approve or reject this action to resume the workflow.":"Waiting for approval from another participant.";return u.jsxs(ao,{className:te("border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10 transition-shadow",o?"shadow-md ring-1 ring-blue-300 dark:ring-blue-500/70":"opacity-80"),children:[u.jsxs(lo,{className:"pb-3",children:[u.jsx(co,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),u.jsx(cp,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&u.jsx(uo,{className:"pt-0 pb-3",children:a}),u.jsx(up,{className:"pt-0",children:u.jsxs("div",{className:"flex gap-2 ml-auto",children:[u.jsx(Je,{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(Je,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,children:"Approve"})]})})]})}const cC="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 dp({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?u.jsx("div",{className:cC,children:u.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>u.jsx("li",{children:String(n)},r))})}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:oo(e)}):u.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:oo(e)})}function uC({message:e,isStreaming:t=!1}){const n=e.name??"tool",r=w.useMemo(()=>{const a=e.additionalKwargs??{};return Array.isArray(a.toolProgress)?[...a.toolProgress]:[]},[e]),s=r.some(a=>a.type==="tool.start"||a.type==="tool.call"||a.type==="message.start")?`Running ${n}…`:void 0;return t||r.length>0?u.jsxs("div",{className:"space-y-2",children:[u.jsxs("div",{className:"flex items-center gap-2 text-xs uppercase tracking-wide text-muted-foreground",children:[t&&u.jsx(le.Loader,{className:"h-3 w-3 animate-spin"}),u.jsx("span",{children:s??`Running ${n}…`})]}),r.length>0&&u.jsx("div",{className:"space-y-2 text-xs text-muted-foreground",children:r.map((a,l)=>{var c;return u.jsxs("div",{className:"rounded border border-current/10 bg-muted/60 p-2 text-[11px] leading-snug",children:[u.jsxs("div",{className:"mb-1 flex items-center justify-between text-[8px] uppercase tracking-wide text-muted-foreground",children:[u.jsx("span",{children:((c=a.type)==null?void 0:c.replace(/\./g," "))??"progress"}),u.jsx("span",{children:a.idx??l+1})]}),a.content&&u.jsx("p",{className:"mt-1 text-[12px] text-foreground/90",children:a.content}),u.jsxs("div",{className:"mt-1 flex flex-wrap gap-2 text-[10px] opacity-70",children:[typeof a.factsFound=="number"&&u.jsxs("span",{children:["Facts found: ",a.factsFound]}),typeof a.isSufficient=="boolean"&&u.jsxs("span",{children:["Research ",a.isSufficient?"sufficient":"needs more data"]})]})]},`tool-progress-${n}-${l}`)})})]}):null}function dC({message:e,viewMode:t,isStreaming:n=!1}){const o=Sf(e).name||"tool",s=l=>{if(l==null)return null;const c=typeof l=="string"?wa(l)??l:l;if(c&&typeof c=="object")return u.jsx(dp,{data:c});const d=typeof c=="string"?c:(()=>{try{return oo(c)}catch{return String(c??"")}})();return u.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-sm text-foreground/90",children:d})},i=l=>{if(l==null)return null;const{content:c,isMarkdown:d}=uS(l);return d?u.jsx(io,{content:c,className:"text-current"}):s(l)},a=()=>{const l=e.content.find(f=>f.type!=="tool_call");if(!l)return u.jsx("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:u.jsxs("span",{children:["Running ",o,"…"]})});if(l.type==="text"){const p=(l.text??"").trim();if(!p)return null;const h=Ts(p);return i(h)}const c=ro(l),d=Ts(c);return i(d)};return u.jsxs("div",{className:"space-y-2",children:[u.jsx(uC,{message:e,isStreaming:n}),t==="expanded"&&a()]})}function fC(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=Ia(),[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,g,m)=>{var y,x;if(!t){h.preventDefault();return}if(o[m]){h.preventDefault();return}try{const b=String(g.url??""),S=b.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){h.preventDefault();const k=S[1],C=g.name||`file_${k}`,T=g.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 vS(n??void 0);if(!C||!Array.isArray(C))throw new Error("Invalid file list response");const T=C.find(E=>!E||typeof E!="object"||!((E.filename??"")===(g.name??""))?!1:typeof g.size=="number"&&typeof E.size=="number"?E.size===g.size:!0);if(!(T!=null&&T.id))throw new Error(`File "${g.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:g.name||T.filename||`file_${T.id}`,mimeType:g.mimeType||T.mime_type||"application/octet-stream"}),(y=k.update)==null||y.call(k,{id:k.id,title:"Success",description:`Opened ${g.name}`,open:!0})}catch(C){console.error("Failed to fetch server file:",C);const T=C instanceof Error?C.message:"Unknown error occurred";(x=k.update)==null||x.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 pC({text:e,expanded:t,onExpandedChange:n,previewLength:r,isCompact:o}){const s=Math.max(e.length-r,0),i=e.substring(0,r);return u.jsxs("div",{className:"flex flex-col gap-1",children:[u.jsx("div",{className:te("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?u.jsx(io,{content:e,allowHtml:!1}):u.jsxs("pre",{className:te("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:[i,"..."]})}),u.jsx(Je,{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(le.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):u.jsxs(u.Fragment,{children:[u.jsx(le.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function hC({className:e}){const[t,n]=w.useState(0);return w.useEffect(()=>{const r=setInterval(()=>n(o=>(o+1)%4),500);return()=>clearInterval(r)},[]),u.jsxs("span",{"aria-live":"polite",className:te("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}function fp(e){var n;const t=(n=e.additionalKwargs)==null?void 0:n.toolProgress;return Array.isArray(t)?t:[]}const Ls=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:g,onRegenerate:m,onCancelEdit:y,onCopy:x,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,checkpointCandidates:T=[],activeCheckpointId:E=null,onSelectCheckpoint:N,defaultCheckpointId:_=null,messageParentCheckpointId:D=null}){const[B,G]=w.useState(!1),[V,R]=w.useState("preview"),[M,A]=w.useState(!1),{currentThreadId:F}=jo(),{respondToInterrupt:L}=Mo(),P=l==="phone"||l==="half-screen",z=t.role,X=z==="tool",ne=w.useMemo(()=>"type"in t&&t.type==="default_message"?t:null,[t]),ye=!!ne,Te=!(r&&z!=="user"),{uploadingFiles:q,handleFileClick:U,fileViewerOpen:J,currentFileInfo:$,closeFileViewer:Y}=fC({allowFileOpen:Te,currentThreadId:F}),Z=w.useMemo(()=>{switch(z){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))]"}},[z]),de=w.useMemo(()=>{if(ne)return"";const j=t.content;return Array.isArray(j)?dS(j):""},[ne,t]),oe=w.useMemo(()=>{if(ne)return{};const j=t.content;return Array.isArray(j)?Sf(t):{}},[ne,t]),_e=w.useMemo(()=>X?!!(t.additionalKwargs??{}).toolStreaming:!1,[X,t]),ze=w.useMemo(()=>{if(ne)return[];const j=t.content;return Array.isArray(j)?j.filter(Q=>Q.type==="image_url"):[]},[ne,t]),se=w.useMemo(()=>{if(ne)return[];const j=t.content;return Array.isArray(j)?j.filter(Q=>Q.type==="file"):[]},[ne,t]),me=w.useMemo(()=>{if(ne)return[];const j=t.content;return Array.isArray(j)?j.filter(Q=>Q.type==="interrupt"):[]},[ne,t]),Re=(b==null?void 0:b.id)??(b==null?void 0:b.interrupt_id),Ve=ks(Re),ut=b==null?void 0:b.value,Ke=w.useMemo(()=>{if(ne)return"";const j=t.content;return Array.isArray(j)?fS(j):""},[ne,t]),qe=w.useMemo(()=>{if(ne||!p)return[];const Q=t.artifact;if(!Q)return[];const re=[],ie=[...Array.isArray(Q.plots)?Q.plots:[]];for(const ce of ie){const Xe=xS(ce);Xe&&re.push(Xe)}return re},[ne,t,p]),Qe=w.useCallback(async()=>{const j=X?Ke:de;async function Q(re){if(navigator.clipboard&&typeof navigator.clipboard.writeText=="function"){await navigator.clipboard.writeText(re);return}if(navigator.clipboard&&typeof navigator.clipboard.write=="function"&&typeof ClipboardItem<"u"){const ie=new Blob([re],{type:"text/plain"});await navigator.clipboard.write([new ClipboardItem({"text/plain":ie})]);return}throw new Error("Clipboard API not supported in this context.")}try{await Q(j),G(!0),setTimeout(()=>G(!1),2e3),x==null||x(j)}catch(re){console.error("Failed to copy:",re)}},[X,Ke,de,x]),Ge=w.useCallback(()=>{if(!g)return;const j=X?Ke:de,Q="type"in t&&t.type==="default_message"?void 0:{checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};g(t.id,j,Q)},[g,t.id,X,Ke,de,t]),et=w.useCallback(()=>{m==null||m(n)},[m,n]),st=w.useCallback(()=>{const Q=te(P?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",Z);switch(z){case"user":return u.jsx(le.User,{className:Q});case"assistant":return u.jsx(le.Bot,{className:Q});case"tool":return u.jsx(le.Wrench,{className:Q});default:return u.jsx(le.Bot,{className:Q})}},[P,Z,z]),Mt=w.useCallback(()=>{const j="group relative mb-4 flex w-full";switch(z){case"user":return te(j,"justify-end");case"assistant":case"tool":case"system":return te(j,"justify-start");default:return j}},[z]),gt=w.useCallback(()=>{const j=te("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",P&&"px-3 py-2 text-sm");if(ye)return te(j,"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(z){case"user":return te(j,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-user))] text-[hsl(var(--chat-bubble-user-text))]","border border-transparent");case"assistant":return te(j,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40");case"tool":return te(j,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return te(j,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return te(j,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40")}},[P,ye,z]),Ct=w.useCallback(async j=>{if(S)return;const Q=ks((j==null?void 0:j.id)??(j==null?void 0:j.interrupt_id));if(!Q){console.warn("Interrupt part missing id",j);return}try{k==null||k(),await L(Q,!0)}catch(re){console.error("Failed to approve interrupt:",re)}finally{C==null||C()}},[S,C,k,L]),it=w.useCallback(async j=>{if(S)return;const Q=ks((j==null?void 0:j.id)??(j==null?void 0:j.interrupt_id));if(!Q){console.warn("Interrupt part missing id",j);return}try{k==null||k(),await L(Q,!1)}catch(re){console.error("Failed to reject interrupt:",re)}finally{C==null||C()}},[S,C,k,L]),St=w.useCallback(({part:j,i:Q})=>{if(j.type==="text"){const re=j.text??"",ie=re.trim(),ce=wa(ie);return ce&&z!=="tool"?u.jsx(dp,{data:ce},Q):z==="user"&&c&&ie.length>d?u.jsx(pC,{text:ie,expanded:M,onExpandedChange:A,previewLength:d,isCompact:P},Q):u.jsx(io,{content:re,allowHtml:!1},Q)}if(j.type==="image_url"){const re=j;return u.jsx("div",{className:"my-2",children:u.jsx("img",{src:re.url,alt:re.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},Q)}if(j.type==="file"){const re=j,ie=re.name||"file";return u.jsxs("a",{href:re.url,onClick:ce=>U(ce.nativeEvent,re,Q),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
137
137
  dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[q[Q]?u.jsx(le.Loader,{className:"h-4 w-4 animate-spin"}):null,u.jsxs("span",{className:"truncate max-w-[180px]",children:[ie,q[Q]?" (processing)":""]})]},Q)}if(j.type==="interrupt"){const re=j,ie=ks((re==null?void 0:re.id)??(re==null?void 0:re.interrupt_id)),ce=!!(Ve&&ie&&ie===Ve),Xe=ce?ut??(re==null?void 0:re.value):re==null?void 0:re.value,Ie=ie?{...re,id:ie,interrupt_id:ie}:re;return u.jsx(lC,{interruptPart:Ie,onApprove:Ct,onReject:it,disabled:S,isActive:ce,payload:Xe},Q)}return null},[U,q,Ct,it,z,c,d,M,P,Ve,ut,b,S,me]),Rt=w.useCallback(()=>u.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[u.jsx(le.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),u.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),zt=w.useCallback(()=>{const j=de.trim().length>0||ze.length>0||se.length>0||me.length>0;if(!X&&se.length>0&&!r)return Rt();if(!X&&!j&&!r)return null;if(X)return!f&&qe.length>0?null:f?u.jsx(dC,{message:t,viewMode:V,isStreaming:_e},t.id):null;if(!X&&!ne){const Q=t,re=u.jsx("div",{className:"space-y-2",children:Q.content.map((ie,ce)=>u.jsx(St,{part:ie,i:ce},ce))});return r?u.jsxs("div",{"aria-busy":"true",role:"status",children:[re,u.jsx(hC,{className:Z})]}):re}},[de,ze.length,se.length,me.length,r,X,V,f,qe.length,Rt,Z]),nn=w.useMemo(()=>ne?"Assistant":pS(t),[ne,t]),Le=w.useMemo(()=>ne?[]:Array.isArray(T)?T:[],[T,ne]),Sn=w.useMemo(()=>{var j;return Le.length?_&&Le.some(Q=>Q.id===_)?_:((j=Le[0])==null?void 0:j.id)??null:null},[_,Le]),We=w.useMemo(()=>!Le.length||!E?null:Le.some(j=>j.id===E)?E:null,[E,Le])??Sn,pt=z==="user"&&Le.length>0&&typeof N=="function",Pt=w.useCallback((j,Q=!1)=>{if(!N)return;const re=(j==null?void 0:j.id)??null,ie=(j==null?void 0:j.parentId)??D??null;N(re,ie,Q)},[D,N]),Ye=w.useMemo(()=>We?Le.findIndex(j=>j.id===We):-1,[We,Le]),H=w.useMemo(()=>Ye<0?null:Le[Ye]??null,[Ye,Le]);return X&&!f&&qe.length===0?null:ye&&ne?u.jsx("div",{className:te(Mt(),h.container),children:u.jsxs("div",{className:te(gt(),h.content),children:[u.jsxs("div",{className:"flex items-center gap-2 mb-2 pb-2 border-b border-current/10",children:[u.jsx(le.Bot,{className:te("h-4 w-4",Z)}),a&&u.jsx("span",{className:"font-medium text-sm",children:"Assistant"})]}),u.jsx(io,{content:ne.content,className:"text-current"})]})}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:te(Mt(),h.container),children:u.jsxs("div",{className:te(gt(),h.content),children:[(i||a||X)&&u.jsxs("div",{className:te("flex items-center justify-between mb-2 pb-2 border-b border-current/10",P&&"mb-1 pb-1",Z,h.header),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[st(),a&&nn&&u.jsx("span",{className:te("font-medium",P?"text-xs":"text-sm"),children:nn}),X&&u.jsxs(bf,{variant:"outline",className:te("text-xs flex items-center gap-1 cursor-pointer select-none",Z,"border border-current/40",P&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":V==="expanded",onClick:()=>R(j=>j==="expanded"?"preview":"expanded"),onKeyDown:j=>{(j.key==="Enter"||j.key===" ")&&(j.preventDefault(),R(Q=>Q==="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)}),V==="expanded"?u.jsx(le.ChevronUp,{className:"h-3 w-3"}):u.jsx(le.ChevronDown,{className:"h-3 w-3"})]})]}),u.jsxs("div",{className:"flex items-center gap-2",children:[pt&&H&&Ye>=0&&u.jsx("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("button",{type:"button",className:te("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",Ye<Le.length-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(Ye>=Le.length-1)return;const j=Le[Ye+1];j&&Pt(j)},"aria-label":"Older checkpoint (back in time)",disabled:Ye>=Le.length-1,children:u.jsx(le.ChevronLeft,{className:"h-3 w-3"})}),u.jsx("div",{className:"flex items-center gap-2",children:u.jsxs("span",{className:"whitespace-nowrap",children:[Le.length-Ye," / ",Le.length]})}),u.jsx("button",{type:"button",className:te("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",Ye>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{if(!(Ye<=0))if(Ye===1)Pt(null,!0);else{const j=Le[Ye-1];j&&Pt(j,!1)}},"aria-label":"Newer checkpoint (forward in time)",disabled:Ye<=0,children:u.jsx(le.ChevronRight,{className:"h-3 w-3"})})]})}),i&&t.createdAt&&u.jsx("time",{className:te("text-xs opacity-60",Z,P&&"text-xs"),dateTime:new Date(t.createdAt).toISOString(),title:new Date(t.createdAt).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t.createdAt))}),s&&!o&&u.jsxs("div",{className:te("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx("div",{className:"relative",children:u.jsx(Je,{variant:"ghost",size:"sm",onClick:()=>Qe(),className:te("h-6 w-6 p-0 hover:bg-foreground/10",Z,P&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:u.jsx(le.Copy,{className:te(B?"text-success":Z,P?"h-3 w-3":"h-4 w-4")})})}),z==="user"&&g&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:Ge,className:te("h-6 w-6 p-0 hover:bg-foreground/10",Z,P&&"h-5 w-5"),"aria-label":"Edit message",children:u.jsx(le.Edit,{className:te(Z,P?"h-3 w-3":"h-4 w-4")})}),z==="assistant"&&m&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:et,className:te("h-6 w-6 p-0 hover:bg-foreground/10",Z,P&&"h-5 w-5"),"aria-label":"Regenerate response",children:u.jsx(le.RotateCcw,{className:te(Z,P?"h-3 w-3":"h-4 w-4")})})]})]})]}),u.jsxs("div",{className:"relative",children:[zt(),p&&qe.length>0&&u.jsx("div",{className:"mt-3 space-y-4",children:qe.map((j,Q)=>u.jsx(aC,{preview:j,idx:Q},`artifact-${Q}`))})]}),X&&V==="expanded"&&(oe.toolCallId||oe.name)&&u.jsxs("div",{className:te("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",P&&"text-xs"),children:[oe.name&&u.jsxs("div",{children:["Function: ",oe.name]}),oe.toolCallId&&u.jsxs("div",{children:["Call ID: ",oe.toolCallId]})]}),!(i||a||X)&&s&&!o&&u.jsxs("div",{className:te("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",h.actions),children:[u.jsx(Je,{variant:"ghost",size:"sm",onClick:()=>Qe(),className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:u.jsx(le.Copy,{className:te(B?"text-success":"text-current",P?"h-3 w-3":"h-4 w-4")})}),z==="user"&&g&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:Ge,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:u.jsx(le.Edit,{className:te("text-current",P?"h-3 w-3":"h-4 w-4")})}),z==="assistant"&&m&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:et,className:te("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:u.jsx(le.RotateCcw,{className:te("text-current",P?"h-3 w-3":"h-4 w-4")})})]})]})}),$&&u.jsx($S,{isOpen:J,onClose:Y,fileId:$.id,fileName:$.name,mimeType:$.mimeType})]})},(e,t)=>{var l,c,d,f,p,h,g,m;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&Cf(e.message)===Cf(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateUserMessages","userMessagePreviewLength","showToolMessages","attemptMeta"].every(y=>e[y]===t[y]),s=((l=e.customStyles)==null?void 0:l.container)===((c=t.customStyles)==null?void 0:c.container)&&((d=e.customStyles)==null?void 0:d.content)===((f=t.customStyles)==null?void 0:f.content)&&((p=e.customStyles)==null?void 0:p.actions)===((h=t.customStyles)==null?void 0:h.actions)&&((g=e.customStyles)==null?void 0:g.header)===((m=t.customStyles)==null?void 0:m.header);if(!o||!s)return!1;const i=fp(e.message),a=fp(t.message);return i.length===a.length});Ls.displayName="MessageComponent";function mC(e,t){return w.useMemo(()=>{var d,f,p,h,g;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 x=y&&t.checkpointMetaById?t.checkpointMetaById.get(y)??null:null;a=typeof s.step=="number"?s.step:typeof i.step=="number"?i.step:(x==null?void 0:x.step)??null;const b=typeof s.source=="string"?s.source:typeof i.source=="string"?i.source:(x==null?void 0:x.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&&x&&(r=[x]),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,E]of t.attemptMetaById.entries())if(E.baseUserMessageId===k){const N=(g=t.checkpointMetaById)==null?void 0:g.get(T);N&&C.push(N)}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 E=t.attemptMetaById.get(C);E&&E.attemptCount===c.attemptCount&&E.baseUserMessageId===c.baseUserMessageId&&k.push(T)}k.sort((C,T)=>{const E=C.createdAt?Date.parse(C.createdAt):0;return(T.createdAt?Date.parse(T.createdAt):0)-E}),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 pp=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,hp=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:g,onInterruptActionEnd:m,showToolMessages:y,showArtifactPreviews:x,checkpointMetaById:b,checkpointIndexByKey:S,attemptMetaById:k,userMessageIdToAttempts:C,activeCheckpointId:T,onSelectCheckpoint:E}){const N=pp(t,n),_="type"in t&&t.type==="default_message",{checkpointCandidates:D,defaultCheckpointId:B,attemptMeta:G}=mC(t,{checkpointMetaById:b,checkpointIndexByKey:S,attemptMetaById:k,userMessageIdToAttempts:C}),V=t&&!_?t.additionalKwargs??{}:{},R=t&&!_?t.responseMetadata??{}:{},M=(()=>{if(typeof V.parentCheckpointId=="string")return V.parentCheckpointId;if(typeof R.parentCheckpointId=="string")return R.parentCheckpointId})();return u.jsx("div",{className:"relative mb-4 last:mb-0","data-message-id":N,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:u.jsx(Ls,{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:g,onInterruptActionEnd:m,showToolMessages:y,showArtifactPreviews:x,checkpointCandidates:D,activeCheckpointId:T??null,onSelectCheckpoint:E,defaultCheckpointId:B,messageParentCheckpointId:M,attemptMeta:G})})});hp.displayName="MessageRow";const _a=w.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:c,onCancelEdit:d,className:f,style:p,emptyMessage:h,followNewMessages:g=!0,isNavigatingCheckpoint:m=!1,onScrollAway:y,onAtBottom:x,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:k,onInterruptActionEnd:C,showToolMessages:T=!0,showArtifactPreviews:E=!0,checkpointMetaById:N,checkpointIndexByKey:_,attemptMetaById:D,userMessageIdToAttempts:B,activeCheckpointId:G,onSelectCheckpoint:V,createSyntheticThinkingMessage:R=!1},M)=>{const A=w.useRef(null),F=w.useRef(null),L=w.useRef(!1),P=w.useRef(!1),[z,X]=w.useState(!0),ne=w.useMemo(()=>b?e.some(se=>"type"in se&&se.type==="default_message"?!1:Array.isArray(se==null?void 0:se.content)&&se.content.some(me=>me&&me.type==="interrupt"&&(me.id??me.interrupt_id)===b.id)):!1,[b,e]),ye=w.useMemo(()=>{if(!b||ne)return null;const se=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let me;const Re=b.value;if(Re&&typeof Re=="object"&&!Array.isArray(Re)){const Ve=Re.title;typeof Ve=="string"&&Ve.trim()&&(me=Ve.trim())}return{id:`interrupt-${se}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:se,value:Re,title:me}]}},[b,ne]),Te=w.useMemo(()=>ye?[...e,ye]:e,[e,ye]),q=w.useMemo(()=>!R||!t?Te:!Te.some(me=>me.role==="assistant")&&Te.length>0?[...Te,{id:"thinking-assistant",role:"assistant",content:[],createdAt:new Date().toISOString()}]:Te,[Te,t,R]),U=w.useMemo(()=>T?q:q.filter(se=>(se==null?void 0:se.role)!=="tool"),[q,T]),J=w.useCallback(se=>{X(se),y&&y(!se),x&&x(se)},[y,x]),$=w.useMemo(()=>{if(a)return async()=>{if(!L.current){L.current=!0;try{await a()}finally{L.current=!1}}}},[a]),Y=w.useMemo(()=>!g||m?!1:z?"auto":!1,[z,g,m]),Z=w.useMemo(()=>{if(typeof h!="string")return null;const se=h.trim();return se?{id:"default-message",role:"assistant",type:"default_message",content:se,createdAt:new Date().toISOString()}:null},[h]),de=["flex h-full flex-col md:flex-row",f].filter(Boolean).join(" "),oe=()=>Z?u.jsx("div",{className:"p-6 h-full overflow-y-auto",children:u.jsx("div",{className:"w-full max-w-full",children:u.jsx(Ls,{message:Z,messageIndex:0,isStreamingMessage:!1,showActions:!1,showTimestamp:!1,showAgentName:!0,layoutSize:o,onEdit:()=>{},onRegenerate:()=>{},onCancelEdit:()=>{},showArtifactPreviews:E})})}):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!"}),_e=U.length,ze=_e>0;return w.useEffect(()=>{var se,me;if(_e===0){P.current=!1;return}if(!P.current)if(P.current=!0,A.current&&U.length>0){const Re=U.length-1;(me=(se=A.current).scrollToIndex)==null||me.call(se,{index:Re,align:"end",behavior:"auto"})}else F.current&&(F.current.scrollTop=F.current.scrollHeight)},[_e,U.length]),w.useImperativeHandle(M,()=>({scrollToLatest:()=>{var se,me;if(A.current&&U.length>0){const Re=U.length-1;(me=(se=A.current).scrollToIndex)==null||me.call(se,{index:Re,align:"end",behavior:"auto"})}else F.current&&(F.current.scrollTop=F.current.scrollHeight)},scrollToTop:()=>{var se,me;A.current&&U.length>0?(me=(se=A.current).scrollToIndex)==null||me.call(se,{index:0,align:"start",behavior:"auto"}):F.current&&(F.current.scrollTop=0)}}),[U]),u.jsx("div",{className:de,style:p,children:u.jsx("div",{className:"relative flex-1 min-h-0",children:ze?u.jsx(q0,{ref:se=>{A.current=se},scrollerRef:se=>{F.current=se instanceof HTMLDivElement?se:null},data:U,followOutput:Y,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,startReached:()=>{$&&$()},atBottomStateChange:J,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(se,me)=>pp(me,se),itemContent:(se,me)=>u.jsx(hp,{message:me,index:se,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:E,checkpointMetaById:N,checkpointIndexByKey:_,attemptMetaById:D,userMessageIdToAttempts:B,activeCheckpointId:G,onSelectCheckpoint:V})}):oe()})})});_a.displayName="MessageList";const mp={value:""};function $s({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:c=!0,showToolMessages:d=!0,showArtifactPreviews:f=!0,customStyles:p={},onMessageSent:h,onExcelUploadSuccess:g,onError:m}){const{api:y}=di(),{currentThreadId:x}=jo(),{threadId:b,messages:S,isHistoryLoading:k,isLoading:C,navigateToCheckpoint:T,returnToLatest:E,checkpoint:N,checkpoints:_,interrupt:D,metadata:B,timelineCheckpoints:G,messagePreviews:V}=Mo(),{isStreaming:R,error:M,connectionState:A,submit:F,stop:L}=cc(),P=b??x??null,z=(N==null?void 0:N.id)??null,X=(N==null?void 0:N.namespace)??null,ne=(B==null?void 0:B.assemblingMessageId)??null,ye=D,[Te,q]=w.useState(!1);w.useEffect(()=>{ye||q(!1)},[ye]);const U=w.useCallback(()=>{q(!0)},[]),J=w.useCallback(()=>{q(!1)},[]),$=!!ye||Te,[Y,Z]=w.useState(null),[de,oe]=w.useState(""),[_e,ze]=w.useState(null),[se,me]=w.useState(null),[Re,Ve]=w.useState([]),[ut,Ke]=w.useState(0),[qe,Qe]=w.useState(0),[Ge,et]=w.useState(!1),[st,Mt]=w.useState(null),[gt,Ct]=w.useState(null),[it,St]=w.useState(!1),[Rt,zt]=w.useState(null),nn=w.useRef(!1),[Le,Sn]=w.useState(()=>mp.value),tt=w.useRef(Le),We=w.useRef(null),pt=w.useCallback(he=>{mp.value=he,Sn(he)},[]),[Pt,Ye]=w.useState(!1),H=w.useRef(null),{checkpointMetaById:j,checkpointIndexByKey:Q,attemptMetaById:re,userMessageIdToAttempts:ie}=Pw(_),ce=G??[],Xe=w.useRef(null),Ie=w.useRef(null),at=w.useCallback(()=>{Xe.current&&(Xe.current.value=""),Ie.current&&(Ie.current.value=""),Ke(he=>he+1),Qe(he=>he+1)},[]),ht=w.useCallback(he=>{pt(he)},[pt]),Kt=w.useRef(!1);w.useEffect(()=>{Kt.current&&!R&&(Ve([]),at()),Kt.current=R},[R,at]);const[Hn,Ar]=w.useState("desktop");w.useEffect(()=>{const he=()=>{const we=window.innerWidth;Ar(we<640?"phone":we<1024?"tablet":"desktop")};return he(),window.addEventListener("resize",he),()=>window.removeEventListener("resize",he)},[]),w.useEffect(()=>{nn.current=!1},[P]),w.useEffect(()=>{tt.current=Le},[Le]),w.useEffect(()=>{if(!Y){We.current=null;return}We.current===null&&(We.current=tt.current),pt(de??"")},[de,Y,pt]),w.useEffect(()=>{(async()=>{if(!y.baseUrl){zt(null);return}try{const Ee=(await y.getAgent("default")).uiDefaultMessage||"";zt(Ee||null)}catch(we){console.warn("Failed to fetch default message:",we),zt(null)}})()},[y.baseUrl]),w.useEffect(()=>{M&&!it&&(m==null||m(M))},[M,it,m]);const Nr=he=>{if(he.length>us)return`Message too long (${he.length}/${us} characters)`;try{return Lw(he),null}catch(we){return(we==null?void 0:we.message)||"Invalid message"}},po=async he=>{const we=he.trim();if(!(!we&&Re.length===0)){if(we){const Ee=Nr(we);if(Ee){me(Ee);return}}try{const Ee=Y?(_e==null?void 0:_e.checkpointId)??z??void 0:z??void 0,Ue=Y?(_e==null?void 0:_e.checkpointNs)??X??void 0:X??void 0;await F({text:we||"",attachments:Re},{checkpointId:Ee,checkpointNs:Ue,edit:!!Y,originalMessageId:Y??void 0}),h==null||h(we),pt(""),me(null),Ve([]),at(),Z(null),oe(""),ze(null)}catch(Ee){const Ue=(Ee==null?void 0:Ee.message)||"Failed to send message";me(Ue),m==null||m(Ue)}}},Nn=w.useCallback((he,we,Ee)=>{c&&(We.current=Le,Z(he),oe(we),pt(we),me(null),ze({checkpointId:(Ee==null?void 0:Ee.checkpointId)??null,checkpointNs:(Ee==null?void 0:Ee.checkpointNs)??null}))},[Le,c,pt]),I=w.useCallback(()=>{Z(null),oe(""),ze(null),me(null),pt(We.current??Le),We.current=null},[Le,pt]),W=w.useCallback((he,we,Ee)=>{Nn(he,we,Ee)},[Nn]),ae=w.useCallback(he=>{let we=null;for(let rn=he-1;rn>=0;rn--)if(S[rn].role==="user"){we=S[rn];break}if(!we)return;const Ee=Array.isArray(we.content)?we.content:[],Wn=Ee.filter(rn=>(rn==null?void 0:rn.type)==="text").map(rn=>rn.text).join("")||(()=>{try{return JSON.stringify(Ee,null,2)}catch{return String(Ee)}})();Wn&&F({text:Wn},{checkpointId:z??void 0,checkpointNs:X??void 0,edit:!0,originalMessageId:we.id})},[S,F,z,X]),be=he=>{const we=Array.from(he.target.files||[]);Ve(Ee=>[...Ee,...we]),he.target.value=""},Be=he=>{Ve(we=>{const Ee=we.filter((Ue,Wn)=>he!==Wn);return Ee.length===0&&at(),Ee})},nt=async he=>{const we=(he.target.files||[])[0];if(we){Mt(null),Ct(null),et(!0);try{await F({attachments:[we]},{checkpointId:z??void 0,checkpointNs:X??void 0});const Ee=`Uploaded ${we.name} - processing through chat stream`;Ct(Ee)}catch(Ee){const Ue=Ee instanceof Error?Ee.message:"Failed to upload Excel file";console.error("Excel upload failed",Ee),Mt(Ue),m==null||m(Ue)}finally{et(!1),he.target.value="",at()}}},De=async he=>{if(x){Ye(!0);try{if(!he){await E(),requestAnimationFrame(()=>{var Ue;(Ue=H.current)==null||Ue.scrollToLatest()});return}const we=_.find(Ue=>Ue.checkpointId===he),Ee=(we==null?void 0:we.checkpointNs)??null;await T(he,Ee),requestAnimationFrame(()=>{var Ue;(Ue=H.current)==null||Ue.scrollToTop()})}finally{Ye(!1)}}},Oe=w.useCallback(async(he,we,Ee)=>{await De(Ee?null:he)},[De]),It=`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:It,children:[!!M&&!it&&u.jsxs("div",{className:"flex-shrink-0 bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[u.jsx("span",{children:M}),u.jsx(Je,{variant:"ghost",size:"sm",onClick:()=>St(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:u.jsx(le.X,{size:16})})]}),u.jsxs("div",{className:`relative ${mt}`,style:r?{maxHeight:r}:void 0,children:[u.jsx(_a,{ref:H,className:"h-full",style:{height:"100%"},messages:S,isStreaming:R,streamingAssistantId:ne,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:Hn,enableMessageEditing:c,editingMessageId:Y,onEdit:W,onRegenerate:ae,onCancelEdit:I,emptyMessage:Rt??void 0,isNavigatingCheckpoint:Pt,activeInterrupt:ye,disableInterruptActions:Te,onInterruptActionStart:U,onInterruptActionEnd:J,showToolMessages:d,showArtifactPreviews:f,checkpointMetaById:j,checkpointIndexByKey:Q,attemptMetaById:re,userMessageIdToAttempts:ie,activeCheckpointId:z,onSelectCheckpoint:Oe,timelineCheckpoints:ce,messagePreviews:V}),(A==="reconnecting"||A==="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(le.Loader2,{className:"h-3 w-3 animate-spin"}),A==="reconnecting"?"Reconnecting…":"Connecting…"]})}),A==="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(le.Loader2,{className:"h-6 w-6 animate-spin"}),u.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]}),(k||Pt)&&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(le.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:[Y&&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(le.Edit3,{size:16,className:"text-blue-600"}),u.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),u.jsx(Je,{variant:"ghost",size:"sm",onClick:I,className:"text-blue-600 hover:bg-blue-100",children:u.jsx(le.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:Xe,type:"file",multiple:!0,onChange:he=>be(he),className:"hidden"},ut),Re.length>0&&u.jsx("div",{className:"flex flex-wrap gap-2",children:Re.map((he,we)=>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(le.Paperclip,{size:14}),u.jsx("span",{className:"truncate max-w-[150px]",children:he.name}),u.jsx(Je,{variant:"ghost",size:"sm",onClick:()=>Be(we),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 ${he.name}`,children:u.jsx(le.X,{size:12})})]},we))})]}),l&&u.jsxs(u.Fragment,{children:[u.jsx("input",{ref:Ie,type:"file",accept:".xls,.xlsx,.xlsm",onChange:nt,className:"hidden"},qe),Ge&&u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(le.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),gt&&!Ge&&u.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:gt}),st&&!Ge&&u.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:st})]})]}),se&&u.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:se}),u.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&u.jsxs(bw,{children:[u.jsx(ww,{asChild:!0,children:u.jsx(Je,{type:"button",size:"icon",variant:"outline",disabled:R||$,title:"More input actions",className:p.moreButton||"",children:u.jsx(le.Plus,{size:16})})}),u.jsxs(bd,{align:"start",sideOffset:6,className:"w-52",children:[a&&u.jsxs(Ji,{onClick:()=>{var he;return(he=Xe.current)==null?void 0:he.click()},className:"cursor-pointer",children:[u.jsx(le.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&u.jsxs(Ji,{onClick:()=>{var he;Ge||(he=Ie.current)==null||he.click()},className:`cursor-pointer ${Ge?"opacity-60 pointer-events-none":""}`,children:[u.jsx(le.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),u.jsx("div",{className:"flex-1",children:u.jsx(wx,{initialValue:de,editingMessageId:Y,value:Le,onValueChange:ht,placeholder:Y?"Edit your message...":t,isStreaming:R,disabled:$,maxLength:us,onSend:po,onCancelEdit:I,onStop:L,allowEmptySend:Re.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${Y?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${se?"border-red-400":""} ${p.textarea||""}`})})]})]})]})}const Fs=v.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:te("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),ref:r,...n}));Fs.displayName="Input";function ja(e,[t,n]){return Math.min(n,Math.max(t,e))}function gC(e,t){return v.useReducer((n,r)=>t[n][r]??n,e)}var Ma="ScrollArea",[gp,ak]=Tn(Ma),[xC,en]=gp(Ma),xp=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,g]=v.useState(null),[m,y]=v.useState(null),[x,b]=v.useState(0),[S,k]=v.useState(0),[C,T]=v.useState(!1),[E,N]=v.useState(!1),_=$e(t,B=>l(B)),D=Po(o);return u.jsx(xC,{scope:n,type:r,dir:D,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:d,content:f,onContentChange:p,scrollbarX:h,onScrollbarXChange:g,scrollbarXEnabled:C,onScrollbarXEnabledChange:T,scrollbarY:m,onScrollbarYChange:y,scrollbarYEnabled:E,onScrollbarYEnabledChange:N,onCornerWidthChange:b,onCornerHeightChange:k,children:u.jsx(Ne.div,{dir:D,...i,ref:_,style:{position:"relative","--radix-scroll-area-corner-width":x+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});xp.displayName=Ma;var yp="ScrollAreaViewport",vp=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=en(yp,n),a=v.useRef(null),l=$e(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(Ne.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})})]})});vp.displayName=yp;var wn="ScrollAreaScrollbar",Ra=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=en(wn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return v.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?u.jsx(yC,{...r,ref:t,forceMount:n}):o.type==="scroll"?u.jsx(vC,{...r,ref:t,forceMount:n}):o.type==="auto"?u.jsx(bp,{...r,ref:t,forceMount:n}):o.type==="always"?u.jsx(Pa,{...r,ref:t}):null});Ra.displayName=wn;var yC=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=en(wn,e.__scopeScrollArea),[s,i]=v.useState(!1);return v.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const c=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",c),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",c),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),u.jsx(Xt,{present:n||s,children:u.jsx(bp,{"data-state":s?"visible":"hidden",...r,ref:t})})}),vC=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=en(wn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Hs(()=>l("SCROLL_END"),100),[a,l]=gC("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(Xt,{present:n||a!=="hidden",children:u.jsx(Pa,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:pe(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:pe(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),bp=v.forwardRef((e,t)=>{const n=en(wn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=v.useState(!1),a=e.orientation==="horizontal",l=Hs(()=>{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(Xt,{present:r||s,children:u.jsx(Pa,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Pa=v.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=en(wn,e.__scopeScrollArea),s=v.useRef(null),i=v.useRef(0),[a,l]=v.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=kp(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 kC(p,i.current,a,h)}return n==="horizontal"?u.jsx(bC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollLeft,h=Ep(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(wC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollTop,h=Ep(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}),bC=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=en(wn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=$e(t,l,s.onScrollbarXChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Sp,{"data-orientation":"horizontal",...o,ref:c,sizes:n,style:{bottom:0,left:s.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:s.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":Us(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const p=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(p),Ap(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:zs(i.paddingLeft),paddingEnd:zs(i.paddingRight)}})}})}),wC=v.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=en(wn,e.__scopeScrollArea),[i,a]=v.useState(),l=v.useRef(null),c=$e(t,l,s.onScrollbarYChange);return v.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),u.jsx(Sp,{"data-orientation":"vertical",...o,ref:c,sizes:n,style:{top:0,right:s.dir==="ltr"?0:void 0,left:s.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":Us(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const p=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(p),Ap(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:zs(i.paddingTop),paddingEnd:zs(i.paddingBottom)}})}})}),[SC,wp]=gp(wn),Sp=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=en(wn,n),[g,m]=v.useState(null),y=$e(t,_=>m(_)),x=v.useRef(null),b=v.useRef(""),S=h.viewport,k=r.content-r.viewport,C=Et(d),T=Et(l),E=Hs(f,10);function N(_){if(x.current){const D=_.clientX-x.current.left,B=_.clientY-x.current.top;c({x:D,y:B})}}return v.useEffect(()=>{const _=D=>{const B=D.target;(g==null?void 0:g.contains(B))&&C(D,k)};return document.addEventListener("wheel",_,{passive:!1}),()=>document.removeEventListener("wheel",_,{passive:!1})},[S,g,k,C]),v.useEffect(T,[r,T]),kr(g,E),kr(h.content,E),u.jsx(SC,{scope:n,scrollbar:g,hasThumb:o,onThumbChange:Et(s),onThumbPointerUp:Et(i),onThumbPositionChange:T,onThumbPointerDown:Et(a),children:u.jsx(Ne.div,{...p,ref:y,style:{position:"absolute",...p.style},onPointerDown:pe(e.onPointerDown,_=>{_.button===0&&(_.target.setPointerCapture(_.pointerId),x.current=g.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",h.viewport&&(h.viewport.style.scrollBehavior="auto"),N(_))}),onPointerMove:pe(e.onPointerMove,N),onPointerUp:pe(e.onPointerUp,_=>{const D=_.target;D.hasPointerCapture(_.pointerId)&&D.releasePointerCapture(_.pointerId),document.body.style.webkitUserSelect=b.current,h.viewport&&(h.viewport.style.scrollBehavior=""),x.current=null})})})}),Bs="ScrollAreaThumb",Cp=v.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=wp(Bs,e.__scopeScrollArea);return u.jsx(Xt,{present:n||o.hasThumb,children:u.jsx(CC,{ref:t,...r})})}),CC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=en(Bs,n),i=wp(Bs,n),{onThumbPositionChange:a}=i,l=$e(t,f=>i.onThumbChange(f)),c=v.useRef(void 0),d=Hs(()=>{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=EC(f,a);c.current=h,a()}};return a(),f.addEventListener("scroll",p),()=>f.removeEventListener("scroll",p)}},[s.viewport,d,a]),u.jsx(Ne.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:pe(e.onPointerDownCapture,f=>{const h=f.target.getBoundingClientRect(),g=f.clientX-h.left,m=f.clientY-h.top;i.onThumbPointerDown({x:g,y:m})}),onPointerUp:pe(e.onPointerUp,i.onThumbPointerUp)})});Cp.displayName=Bs;var Oa="ScrollAreaCorner",Tp=v.forwardRef((e,t)=>{const n=en(Oa,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?u.jsx(TC,{...e,ref:t}):null});Tp.displayName=Oa;var TC=v.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=en(Oa,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(Ne.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 zs(e){return e?parseInt(e,10):0}function kp(e,t){const n=e/t;return isNaN(n)?0:n}function Us(e){const t=kp(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function kC(e,t,n,r="ltr"){const o=Us(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,c=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,f=r==="ltr"?[0,d]:[d*-1,0];return Ip([l,c],f)(e)}function Ep(e,t,n="ltr"){const r=Us(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],c=ja(e,l);return Ip([0,i],[0,a])(c)}function Ip(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 Ap(e,t){return e>0&&e<t}var EC=(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 Hs(e,t){const n=Et(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=Et(t);kt(()=>{let r=0;if(e){const o=new ResizeObserver(()=>{cancelAnimationFrame(r),r=window.requestAnimationFrame(n)});return o.observe(e),()=>{window.cancelAnimationFrame(r),o.unobserve(e)}}},[e,n])}var Np=xp,IC=vp,AC=Tp;const _p=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Np,{ref:r,className:te("relative overflow-hidden",e),...n,children:[u.jsx(IC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),u.jsx(jp,{}),u.jsx(AC,{})]}));_p.displayName=Np.displayName;const jp=v.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(Ra,{ref:r,orientation:t,className:te("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:u.jsx(Cp,{className:"relative flex-1 rounded-full bg-border"})}));jp.displayName=Ra.displayName;const Mp=25;function Da({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:c,onThreadDelete:d}){const{threads:f,currentThreadId:p,setCurrentThreadId:h,isLoading:g,actions:m}=jo(),{loadThread:y}=Mo(),{createThread:x,deleteThread:b,renameThread:S}=m,[k,C]=w.useState(Array.isArray(f)?f:[]),T=w.useRef(k.length>0),E=w.useRef(null),N=w.useRef(0),[_,D]=w.useState(null),[B,G]=w.useState(""),[V,R]=w.useState(!1);w.useEffect(()=>{const q=Array.isArray(f)?f:[];if(q.length>0){T.current=!0,C(q);return}g||(T.current=!1,C(q))},[f,g]),w.useEffect(()=>{if(!E.current)return;const q=E.current.querySelector("[data-radix-scroll-area-viewport]");if(!q)return;let U=null,J=null;return U=requestAnimationFrame(()=>{J=requestAnimationFrame(()=>{q.scrollTop=N.current})}),()=>{U!==null&&cancelAnimationFrame(U),J!==null&&cancelAnimationFrame(J)}},[k]);const M=async q=>{try{h(q),await y(q),a==null||a(q),l==null||l(q)}catch(U){console.error("Failed to select thread:",U)}},A=async()=>{try{R(!0);const q=await x();q&&(c==null||c(q),a==null||a(q))}catch(q){console.error("Failed to create thread:",q)}finally{R(!1)}},F=async(q,U)=>{if(U.stopPropagation(),!!confirm("Delete this thread?")){if(E.current){const J=E.current.querySelector("[data-radix-scroll-area-viewport]");J&&(N.current=J.scrollTop)}try{await b(q),d==null||d(q)}catch(J){console.error("Failed to delete thread:",J)}}},L=(q,U)=>{U.stopPropagation(),D(q.threadId),G(q.title||`Thread ${q.threadId.slice(0,8)}`)},P=async q=>{if(B.trim())try{await S(q,B.trim()),D(null),G("")}catch(U){console.error("Failed to update title:",U)}},z=()=>{D(null),G("")},X=(q,U)=>{q.key==="Enter"?P(U):q.key==="Escape"&&z()},ne=q=>{if(!q)return"";try{const U=new Date(q),$=new Date().getTime()-U.getTime(),Y=Math.floor($/(1e3*60*60*24));return Y===0?U.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):Y===1?"Yesterday":Y<7?`${Y} days ago`:U.toLocaleDateString()}catch{return""}},ye=q=>q.title||`Thread ${q.threadId.slice(0,8)}`,Te=q=>{const U=ye(q);return U.length<=Mp?U:`${U.slice(0,Mp)}...`};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(Je,{onClick:A,disabled:V||g,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:V?"Creating...":"New Chat",children:u.jsx(le.MessageSquarePlus,{size:20})})}),u.jsx(_p,{ref:E,className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:u.jsx("div",{className:"p-2 space-y-1 pb-4",children:g?u.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[u.jsx(le.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(le.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((q,U)=>new Date(U.updatedAt||U.createdAt||"").getTime()-new Date(q.updatedAt||q.createdAt||"").getTime()).map(q=>u.jsxs("div",{onClick:()=>M(q.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??p)===q.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:_===q.threadId?u.jsxs("div",{className:"flex items-center gap-2",onClick:U=>U.stopPropagation(),children:[u.jsx(Fs,{value:B,onChange:U=>G(U.target.value),onKeyDown:U=>X(U,q.threadId),className:"h-6 text-sm",autoFocus:!0}),u.jsx(Je,{variant:"ghost",size:"sm",onClick:()=>P(q.threadId),className:"h-6 w-6 p-0",children:u.jsx(le.Check,{size:12})}),u.jsx(Je,{variant:"ghost",size:"sm",onClick:z,className:"h-6 w-6 p-0",children:u.jsx(le.X,{size:12})})]}):u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:Te(q)}),u.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[u.jsx(le.Calendar,{size:10}),u.jsx("span",{children:ne(q.updatedAt||q.createdAt)})]})]})}),u.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&_!==q.threadId&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:U=>L(q,U),className:"h-6 w-6 p-0",title:"Edit title",children:u.jsx(le.Edit3,{size:12})}),n&&u.jsx(Je,{variant:"ghost",size:"sm",onClick:U=>F(q.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(le.Trash2,{size:12})})]})]}),i===q.threadId&&u.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},q.threadId))})})]})}const NC=({timelineEntries:e,activeCheckpointId:t,onSelectCheckpoint:n,messagePreviews:r,className:o,onHoverStart:s,onHoverEnd:i})=>{const a=e??[],l=a.length>0,c=w.useMemo(()=>l?[...a].reverse():[],[a,l]),d=t??(a.length?a[a.length-1].id:null);if(!l)return null;const p=["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:p,onMouseEnter:s,onMouseLeave:i,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:c.map(h=>{const g=d===h.id,m=(r==null?void 0:r.get(h.id))??null;return u.jsxs("button",{type:"button",disabled:!n,onClick:()=>n==null?void 0:n(h.id),className:`relative flex items-start gap-2 text-left text-[11px] transition ${g?"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 ${g?"border-primary bg-primary/10 text-primary":"border-border bg-background"}`,children:u.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${g?"bg-primary":"bg-border"}`})}),u.jsxs("span",{className:"flex-1",children:[u.jsx("span",{className:"block font-medium leading-tight",children:h.label||"User input"}),u.jsxs("span",{className:"text-[9px] uppercase tracking-wide text-muted-foreground/70",children:[h.step!==null?`STEP ${h.step}`:"STEP —",h.next?` - ${h.next}`:""]}),m&&u.jsx("p",{className:"text-[10px] text-muted-foreground/80 mt-1 line-clamp-2",title:m,children:m})]})]},h.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 Er(e){if(!(typeof globalThis>"u"))return globalThis[e]}function _C(e){if(typeof e!="string")return;const t=e.trim();if(t)return Cn(t)}function Rp(){const e=[Er("__API_BASE_URL__"),Er("__CHAT_API_BASE_URL__"),Er("__CHAT_API_URL__")];for(const t of e){const n=_C(t);if(n)return n}}function Pp(){const e=[Er("__API_AUTH_TOKEN__"),Er("__CHAT_API_KEY__"),Er("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function Op(...e){for(const t of e)if(typeof t=="string"&&t.trim())return Cn(t);return Cn()}function Dp(){const e={},t=Rp(),n=Pp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function Lp(){const e=Dp(),t=_n.getAuthToken(),n=Rp();return{apiBaseUrl:Op(e.baseUrl,_n.baseUrl,n),apiKey:t||e.apiKey||Pp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const $p="chat-settings";function jC(){try{const e=localStorage.getItem($p);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function MC(e){try{const t={...e,apiBaseUrl:Cn(e.apiBaseUrl)};localStorage.setItem($p,JSON.stringify(t)),t.apiKey&&_n.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function RC(){const e=Lp(),t=jC(),n=_n.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Op(_n.baseUrl,r,e.apiBaseUrl)}}function PC(e){_n.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),MC(e)}var OC="Label",Fp=v.forwardRef((e,t)=>u.jsx(Ne.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())}}));Fp.displayName=OC;var Bp=Fp;const DC=ho.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),tn=v.forwardRef(({className:e,...t},n)=>u.jsx(Bp,{ref:n,className:te(DC(),e),...t}));tn.displayName=Bp.displayName;function zp(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 Up=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"}),LC="VisuallyHidden",$C=v.forwardRef((e,t)=>u.jsx(Ne.span,{...e,ref:t,style:{...Up,...e.style}}));$C.displayName=LC;var FC=[" ","Enter","ArrowUp","ArrowDown"],BC=[" ","Enter"],sr="Select",[Ws,Vs,zC]=gi(sr),[Ir,lk]=Tn(sr,[zC,qo]),Ks=qo(),[UC,Bn]=Ir(sr),[HC,WC]=Ir(sr),Hp=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:g}=e,m=Ks(t),[y,x]=v.useState(null),[b,S]=v.useState(null),[k,C]=v.useState(!1),T=Po(c),[E,N]=pr({prop:r,defaultProp:o??!1,onChange:s,caller:sr}),[_,D]=pr({prop:i,defaultProp:a,onChange:l,caller:sr}),B=v.useRef(null),G=y?g||!!y.closest("form"):!0,[V,R]=v.useState(new Set),M=Array.from(V).map(A=>A.props.value).join(";");return u.jsx(ru,{...m,children:u.jsxs(UC,{required:h,scope:t,trigger:y,onTriggerChange:x,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:k,onValueNodeHasChildrenChange:C,contentId:kn(),value:_,onValueChange:D,open:E,onOpenChange:N,dir:T,triggerPointerDownPosRef:B,disabled:p,children:[u.jsx(Ws.Provider,{scope:t,children:u.jsx(HC,{scope:e.__scopeSelect,onNativeOptionAdd:v.useCallback(A=>{R(F=>new Set(F).add(A))},[]),onNativeOptionRemove:v.useCallback(A=>{R(F=>{const L=new Set(F);return L.delete(A),L})},[]),children:n})}),G?u.jsxs(ph,{"aria-hidden":!0,required:h,tabIndex:-1,name:d,autoComplete:f,value:_,onChange:A=>D(A.target.value),disabled:p,form:g,children:[_===void 0?u.jsx("option",{value:""}):null,Array.from(V)]},M):null]})})};Hp.displayName=sr;var Wp="SelectTrigger",Vp=v.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=Ks(n),i=Bn(Wp,n),a=i.disabled||r,l=$e(t,i.onTriggerChange),c=Vs(n),d=v.useRef("touch"),[f,p,h]=mh(m=>{const y=c().filter(S=>!S.disabled),x=y.find(S=>S.value===i.value),b=gh(y,m,x);b!==void 0&&i.onValueChange(b.value)}),g=m=>{a||(i.onOpenChange(!0),h()),m&&(i.triggerPointerDownPosRef.current={x:Math.round(m.pageX),y:Math.round(m.pageY)})};return u.jsx(ou,{asChild:!0,...s,children:u.jsx(Ne.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":hh(i.value)?"":void 0,...o,ref:l,onClick:pe(o.onClick,m=>{m.currentTarget.focus(),d.current!=="mouse"&&g(m)}),onPointerDown:pe(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"&&(g(m),m.preventDefault())}),onKeyDown:pe(o.onKeyDown,m=>{const y=f.current!=="";!(m.ctrlKey||m.altKey||m.metaKey)&&m.key.length===1&&p(m.key),!(y&&m.key===" ")&&FC.includes(m.key)&&(g(),m.preventDefault())})})})});Vp.displayName=Wp;var Kp="SelectValue",qp=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Bn(Kp,n),{onValueNodeHasChildrenChange:c}=l,d=s!==void 0,f=$e(t,l.onValueNodeChange);return kt(()=>{c(d)},[c,d]),u.jsx(Ne.span,{...a,ref:f,style:{pointerEvents:"none"},children:hh(l.value)?u.jsx(u.Fragment,{children:i}):s})});qp.displayName=Kp;var VC="SelectIcon",Gp=v.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return u.jsx(Ne.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Gp.displayName=VC;var KC="SelectPortal",Yp=e=>u.jsx(Go,{asChild:!0,...e});Yp.displayName=KC;var ir="SelectContent",Xp=v.forwardRef((e,t)=>{const n=Bn(ir,e.__scopeSelect),[r,o]=v.useState();if(kt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?mo.createPortal(u.jsx(Jp,{scope:e.__scopeSelect,children:u.jsx(Ws.Slot,{scope:e.__scopeSelect,children:u.jsx("div",{children:e.children})})}),s):null}return u.jsx(Zp,{...e,ref:t})});Xp.displayName=ir;var dn=10,[Jp,zn]=Ir(ir),qC="SelectContentImpl",GC=Vn.createSlot("SelectContent.RemoveScroll"),Zp=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:g,hideWhenDetached:m,avoidCollisions:y,...x}=e,b=Bn(ir,n),[S,k]=v.useState(null),[C,T]=v.useState(null),E=$e(t,J=>k(J)),[N,_]=v.useState(null),[D,B]=v.useState(null),G=Vs(n),[V,R]=v.useState(!1),M=v.useRef(!1);v.useEffect(()=>{if(S)return $i(S)},[S]),vi();const A=v.useCallback(J=>{const[$,...Y]=G().map(oe=>oe.ref.current),[Z]=Y.slice(-1),de=document.activeElement;for(const oe of J)if(oe===de||(oe==null||oe.scrollIntoView({block:"nearest"}),oe===$&&C&&(C.scrollTop=0),oe===Z&&C&&(C.scrollTop=C.scrollHeight),oe==null||oe.focus(),document.activeElement!==de))return},[G,C]),F=v.useCallback(()=>A([N,S]),[A,N,S]);v.useEffect(()=>{V&&F()},[V,F]);const{onOpenChange:L,triggerPointerDownPosRef:P}=b;v.useEffect(()=>{if(S){let J={x:0,y:0};const $=Z=>{var de,oe;J={x:Math.abs(Math.round(Z.pageX)-(((de=P.current)==null?void 0:de.x)??0)),y:Math.abs(Math.round(Z.pageY)-(((oe=P.current)==null?void 0:oe.y)??0))}},Y=Z=>{J.x<=10&&J.y<=10?Z.preventDefault():S.contains(Z.target)||L(!1),document.removeEventListener("pointermove",$),P.current=null};return P.current!==null&&(document.addEventListener("pointermove",$),document.addEventListener("pointerup",Y,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",$),document.removeEventListener("pointerup",Y,{capture:!0})}}},[S,L,P]),v.useEffect(()=>{const J=()=>L(!1);return window.addEventListener("blur",J),window.addEventListener("resize",J),()=>{window.removeEventListener("blur",J),window.removeEventListener("resize",J)}},[L]);const[z,X]=mh(J=>{const $=G().filter(de=>!de.disabled),Y=$.find(de=>de.ref.current===document.activeElement),Z=gh($,J,Y);Z&&setTimeout(()=>Z.ref.current.focus())}),ne=v.useCallback((J,$,Y)=>{const Z=!M.current&&!Y;(b.value!==void 0&&b.value===$||Z)&&(_(J),Z&&(M.current=!0))},[b.value]),ye=v.useCallback(()=>S==null?void 0:S.focus(),[S]),Te=v.useCallback((J,$,Y)=>{const Z=!M.current&&!Y;(b.value!==void 0&&b.value===$||Z)&&B(J)},[b.value]),q=r==="popper"?La:Qp,U=q===La?{side:a,sideOffset:l,align:c,alignOffset:d,arrowPadding:f,collisionBoundary:p,collisionPadding:h,sticky:g,hideWhenDetached:m,avoidCollisions:y}:{};return u.jsx(Jp,{scope:n,content:S,viewport:C,onViewportChange:T,itemRefCallback:ne,selectedItem:N,onItemLeave:ye,itemTextRefCallback:Te,focusSelectedItem:F,selectedItemText:D,position:r,isPositioned:V,searchRef:z,children:u.jsx(rs,{as:GC,allowPinchZoom:!0,children:u.jsx(Do,{asChild:!0,trapped:b.open,onMountAutoFocus:J=>{J.preventDefault()},onUnmountAutoFocus:pe(o,J=>{var $;($=b.trigger)==null||$.focus({preventScroll:!0}),J.preventDefault()}),children:u.jsx(Oo,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:J=>J.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:u.jsx(q,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:J=>J.preventDefault(),...x,...U,onPlaced:()=>R(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...x.style},onKeyDown:pe(x.onKeyDown,J=>{const $=J.ctrlKey||J.altKey||J.metaKey;if(J.key==="Tab"&&J.preventDefault(),!$&&J.key.length===1&&X(J.key),["ArrowUp","ArrowDown","Home","End"].includes(J.key)){let Z=G().filter(de=>!de.disabled).map(de=>de.ref.current);if(["ArrowUp","End"].includes(J.key)&&(Z=Z.slice().reverse()),["ArrowUp","ArrowDown"].includes(J.key)){const de=J.target,oe=Z.indexOf(de);Z=Z.slice(oe+1)}setTimeout(()=>A(Z)),J.preventDefault()}})})})})})})});Zp.displayName=qC;var YC="SelectItemAlignedPosition",Qp=v.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Bn(ir,n),i=zn(ir,n),[a,l]=v.useState(null),[c,d]=v.useState(null),f=$e(t,E=>d(E)),p=Vs(n),h=v.useRef(!1),g=v.useRef(!0),{viewport:m,selectedItem:y,selectedItemText:x,focusSelectedItem:b}=i,S=v.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&c&&m&&y&&x){const E=s.trigger.getBoundingClientRect(),N=c.getBoundingClientRect(),_=s.valueNode.getBoundingClientRect(),D=x.getBoundingClientRect();if(s.dir!=="rtl"){const de=D.left-N.left,oe=_.left-de,_e=E.left-oe,ze=E.width+_e,se=Math.max(ze,N.width),me=window.innerWidth-dn,Re=ja(oe,[dn,Math.max(dn,me-se)]);a.style.minWidth=ze+"px",a.style.left=Re+"px"}else{const de=N.right-D.right,oe=window.innerWidth-_.right-de,_e=window.innerWidth-E.right-oe,ze=E.width+_e,se=Math.max(ze,N.width),me=window.innerWidth-dn,Re=ja(oe,[dn,Math.max(dn,me-se)]);a.style.minWidth=ze+"px",a.style.right=Re+"px"}const B=p(),G=window.innerHeight-dn*2,V=m.scrollHeight,R=window.getComputedStyle(c),M=parseInt(R.borderTopWidth,10),A=parseInt(R.paddingTop,10),F=parseInt(R.borderBottomWidth,10),L=parseInt(R.paddingBottom,10),P=M+A+V+L+F,z=Math.min(y.offsetHeight*5,P),X=window.getComputedStyle(m),ne=parseInt(X.paddingTop,10),ye=parseInt(X.paddingBottom,10),Te=E.top+E.height/2-dn,q=G-Te,U=y.offsetHeight/2,J=y.offsetTop+U,$=M+A+J,Y=P-$;if($<=Te){const de=B.length>0&&y===B[B.length-1].ref.current;a.style.bottom="0px";const oe=c.clientHeight-m.offsetTop-m.offsetHeight,_e=Math.max(q,U+(de?ye:0)+oe+F),ze=$+_e;a.style.height=ze+"px"}else{const de=B.length>0&&y===B[0].ref.current;a.style.top="0px";const _e=Math.max(Te,M+m.offsetTop+(de?ne:0)+U)+Y;a.style.height=_e+"px",m.scrollTop=$-Te+m.offsetTop}a.style.margin=`${dn}px 0`,a.style.minHeight=z+"px",a.style.maxHeight=G+"px",r==null||r(),requestAnimationFrame(()=>h.current=!0)}},[p,s.trigger,s.valueNode,a,c,m,y,x,s.dir,r]);kt(()=>S(),[S]);const[k,C]=v.useState();kt(()=>{c&&C(window.getComputedStyle(c).zIndex)},[c]);const T=v.useCallback(E=>{E&&g.current===!0&&(S(),b==null||b(),g.current=!1)},[S,b]);return u.jsx(JC,{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(Ne.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Qp.displayName=YC;var XC="SelectPopperPosition",La=v.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=dn,...s}=e,i=Ks(n);return u.jsx(su,{...i,...s,ref:t,align:r,collisionPadding:o,style:{boxSizing:"border-box",...s.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});La.displayName=XC;var[JC,$a]=Ir(ir,{}),Fa="SelectViewport",eh=v.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=zn(Fa,n),i=$a(Fa,n),a=$e(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(Ws.Slot,{scope:n,children:u.jsx(Ne.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:pe(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 g=window.innerHeight-dn*2,m=parseFloat(f.style.minHeight),y=parseFloat(f.style.height),x=Math.max(m,y);if(x<g){const b=x+h,S=Math.min(g,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})})})]})});eh.displayName=Fa;var th="SelectGroup",[ZC,QC]=Ir(th),eT=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=kn();return u.jsx(ZC,{scope:n,id:o,children:u.jsx(Ne.div,{role:"group","aria-labelledby":o,...r,ref:t})})});eT.displayName=th;var nh="SelectLabel",rh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=QC(nh,n);return u.jsx(Ne.div,{id:o.id,...r,ref:t})});rh.displayName=nh;var qs="SelectItem",[tT,oh]=Ir(qs),sh=v.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Bn(qs,n),l=zn(qs,n),c=a.value===r,[d,f]=v.useState(s??""),[p,h]=v.useState(!1),g=$e(t,b=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,b,r,o)}),m=kn(),y=v.useRef("touch"),x=()=>{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(tT,{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(Ws.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:u.jsx(Ne.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:g,onFocus:pe(i.onFocus,()=>h(!0)),onBlur:pe(i.onBlur,()=>h(!1)),onClick:pe(i.onClick,()=>{y.current!=="mouse"&&x()}),onPointerUp:pe(i.onPointerUp,()=>{y.current==="mouse"&&x()}),onPointerDown:pe(i.onPointerDown,b=>{y.current=b.pointerType}),onPointerMove:pe(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:pe(i.onPointerLeave,b=>{var S;b.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:pe(i.onKeyDown,b=>{var k;((k=l.searchRef)==null?void 0:k.current)!==""&&b.key===" "||(BC.includes(b.key)&&x(),b.key===" "&&b.preventDefault())})})})})});sh.displayName=qs;var fo="SelectItemText",ih=v.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Bn(fo,n),a=zn(fo,n),l=oh(fo,n),c=WC(fo,n),[d,f]=v.useState(null),p=$e(t,x=>f(x),l.onItemTextChange,x=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,x,l.value,l.disabled)}),h=d==null?void 0:d.textContent,g=v.useMemo(()=>u.jsx("option",{value:l.value,disabled:l.disabled,children:h},l.value),[l.disabled,l.value,h]),{onNativeOptionAdd:m,onNativeOptionRemove:y}=c;return kt(()=>(m(g),()=>y(g)),[m,y,g]),u.jsxs(u.Fragment,{children:[u.jsx(Ne.span,{id:l.textId,...s,ref:p}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?mo.createPortal(s.children,i.valueNode):null]})});ih.displayName=fo;var ah="SelectItemIndicator",lh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return oh(ah,n).isSelected?u.jsx(Ne.span,{"aria-hidden":!0,...r,ref:t}):null});lh.displayName=ah;var Ba="SelectScrollUpButton",ch=v.forwardRef((e,t)=>{const n=zn(Ba,e.__scopeSelect),r=$a(Ba,e.__scopeSelect),[o,s]=v.useState(!1),i=$e(t,r.onScrollButtonChange);return kt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollTop>0;s(c)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(dh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});ch.displayName=Ba;var za="SelectScrollDownButton",uh=v.forwardRef((e,t)=>{const n=zn(za,e.__scopeSelect),r=$a(za,e.__scopeSelect),[o,s]=v.useState(!1),i=$e(t,r.onScrollButtonChange);return kt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const c=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<c;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?u.jsx(dh,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});uh.displayName=za;var dh=v.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=zn("SelectScrollButton",n),i=v.useRef(null),a=Vs(n),l=v.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return v.useEffect(()=>()=>l(),[l]),kt(()=>{var d;const c=a().find(f=>f.ref.current===document.activeElement);(d=c==null?void 0:c.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),u.jsx(Ne.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:pe(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:pe(o.onPointerMove,()=>{var c;(c=s.onItemLeave)==null||c.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:pe(o.onPointerLeave,()=>{l()})})}),nT="SelectSeparator",fh=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return u.jsx(Ne.div,{"aria-hidden":!0,...r,ref:t})});fh.displayName=nT;var Ua="SelectArrow",rT=v.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Ks(n),s=Bn(Ua,n),i=zn(Ua,n);return s.open&&i.position==="popper"?u.jsx(iu,{...o,...r,ref:t}):null});rT.displayName=Ua;var oT="SelectBubbleInput",ph=v.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=v.useRef(null),s=$e(r,o),i=zp(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(Ne.select,{...n,style:{...Up,...n.style},ref:s,defaultValue:t})});ph.displayName=oT;function hh(e){return e===""||e===void 0}function mh(e){const t=Et(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 gh(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=sT(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 sT(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var iT=Hp,xh=Vp,aT=qp,lT=Gp,cT=Yp,yh=Xp,uT=eh,vh=rh,bh=sh,dT=ih,fT=lh,wh=ch,Sh=uh,Ch=fh;const Th=iT,kh=aT,Ha=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(xh,{ref:r,className:te("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",e),...n,children:[t,u.jsx(lT,{asChild:!0,children:u.jsx(le.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Ha.displayName=xh.displayName;const Eh=v.forwardRef(({className:e,...t},n)=>u.jsx(wh,{ref:n,className:te("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(le.ChevronUp,{className:"h-4 w-4"})}));Eh.displayName=wh.displayName;const Ih=v.forwardRef(({className:e,...t},n)=>u.jsx(Sh,{ref:n,className:te("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(le.ChevronDown,{className:"h-4 w-4"})}));Ih.displayName=Sh.displayName;const Wa=v.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>u.jsx(cT,{children:u.jsxs(yh,{ref:o,className:te("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[u.jsx(Eh,{}),u.jsx(uT,{className:te("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(Ih,{})]})}));Wa.displayName=yh.displayName;const pT=v.forwardRef(({className:e,...t},n)=>u.jsx(vh,{ref:n,className:te("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));pT.displayName=vh.displayName;const ar=v.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(bh,{ref:r,className:te("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(fT,{children:u.jsx(le.Check,{className:"h-4 w-4"})})}),u.jsx(dT,{children:t})]}));ar.displayName=bh.displayName;const hT=v.forwardRef(({className:e,...t},n)=>u.jsx(Ch,{ref:n,className:te("-mx-1 my-1 h-px bg-muted",e),...t}));hT.displayName=Ch.displayName;var mT="Separator",Ah="horizontal",gT=["horizontal","vertical"],Nh=v.forwardRef((e,t)=>{const{decorative:n,orientation:r=Ah,...o}=e,s=xT(r)?r:Ah,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return u.jsx(Ne.div,{"data-orientation":s,...a,...o,ref:t})});Nh.displayName=mT;function xT(e){return gT.includes(e)}var _h=Nh;const jh=v.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>u.jsx(_h,{ref:o,decorative:n,orientation:t,className:te("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));jh.displayName=_h.displayName;const yT=Uf,vT=NS,bT=Hf,Mh=v.forwardRef(({className:e,...t},n)=>u.jsx(As,{className:te("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t,ref:n}));Mh.displayName=As.displayName;const wT=ho.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"}}),Rh=v.forwardRef(({side:e="right",className:t,children:n,...r},o)=>u.jsxs(bT,{children:[u.jsx(Mh,{}),u.jsxs(Ns,{ref:o,className:te(wT({side:e}),t),...r,children:[n,u.jsxs(Wf,{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(le.X,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Rh.displayName=Ns.displayName;const Ph=({className:e,...t})=>u.jsx("div",{className:te("flex flex-col space-y-2 text-center sm:text-left",e),...t});Ph.displayName="SheetHeader";const Oh=v.forwardRef(({className:e,...t},n)=>u.jsx(rr,{ref:n,className:te("text-lg font-semibold text-foreground",e),...t}));Oh.displayName=rr.displayName;const Dh=v.forwardRef(({className:e,...t},n)=>u.jsx(_s,{ref:n,className:te("text-sm text-muted-foreground",e),...t}));Dh.displayName=_s.displayName;var Gs="Switch",[ST,ck]=Tn(Gs),[CT,TT]=ST(Gs),Lh=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),g=$e(t,S=>h(S)),m=v.useRef(!1),y=p?d||!!p.closest("form"):!0,[x,b]=pr({prop:o,defaultProp:s??!1,onChange:c,caller:Gs});return u.jsxs(CT,{scope:n,checked:x,disabled:a,children:[u.jsx(Ne.button,{type:"button",role:"switch","aria-checked":x,"aria-required":i,"data-state":zh(x),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:g,onClick:pe(e.onClick,S=>{b(k=>!k),y&&(m.current=S.isPropagationStopped(),m.current||S.stopPropagation())})}),y&&u.jsx(Bh,{control:p,bubbles:!m.current,name:r,value:l,checked:x,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});Lh.displayName=Gs;var $h="SwitchThumb",Fh=v.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=TT($h,n);return u.jsx(Ne.span,{"data-state":zh(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Fh.displayName=$h;var kT="SwitchBubbleInput",Bh=v.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=v.useRef(null),a=$e(i,s),l=zp(n),c=qc(t);return v.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,h=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&h){const g=new Event("click",{bubbles:r});h.call(d,n),d.dispatchEvent(g)}},[l,n,r]),u.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...c,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});Bh.displayName=kT;function zh(e){return e?"checked":"unchecked"}var Uh=Lh,ET=Fh;const Un=v.forwardRef(({className:e,...t},n)=>u.jsx(Uh,{className:te("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:n,children:u.jsx(ET,{className:te("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));Un.displayName=Uh.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}=Ia();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."})},g=()=>{l(e),d(!1),o(!1)},m=async()=>{try{const x=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${x.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return u.jsxs(yT,{open:r,onOpenChange:o,children:[u.jsx(vT,{asChild:!0,children:u.jsxs(Je,{variant:"outline",size:"sm",className:n,children:[u.jsx(le.Settings,{className:"h-4 w-4 mr-2"}),"Settings",c&&u.jsx(bf,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),u.jsxs(Rh,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[u.jsxs(Ph,{children:[u.jsx(Oh,{children:"Chat Settings"}),u.jsx(Dh,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),u.jsxs("div",{className:"space-y-6 py-6",children:[u.jsxs(ao,{children:[u.jsx(lo,{className:"pb-3",children:u.jsxs(co,{className:"text-lg flex items-center gap-2",children:[u.jsx(le.Server,{className:"h-5 w-5"}),"API Configuration"]})}),u.jsxs(uo,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(tn,{htmlFor:"api-url",children:"API Base URL"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Fs,{id:"api-url",value:a.api.baseUrl,onChange:y=>l(x=>({...x,api:{...x.api,baseUrl:y.target.value}})),placeholder:"http://localhost:8000/api"}),u.jsx(Je,{variant:"outline",onClick:m,children:"Test"})]})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(tn,{htmlFor:"enable-auth",children:"Enable Authentication"}),u.jsx(Un,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:y=>l(x=>({...x,api:{...x.api,enableAuth:y}}))})]}),a.api.enableAuth&&u.jsxs("div",{className:"space-y-2",children:[u.jsx(tn,{htmlFor:"auth-token",children:"Authentication Token"}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Fs,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:y=>l(x=>({...x,api:{...x.api,authToken:y.target.value}})),placeholder:"Enter your Bearer token"}),u.jsx(Je,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?u.jsx(le.EyeOff,{className:"h-4 w-4"}):u.jsx(le.Eye,{className:"h-4 w-4"})})]})]})]})]}),u.jsxs(ao,{children:[u.jsx(lo,{className:"pb-3",children:u.jsxs(co,{className:"text-lg flex items-center gap-2",children:[u.jsx(le.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),u.jsxs(uo,{className:"space-y-4",children:[u.jsxs("div",{className:"space-y-2",children:[u.jsx(tn,{htmlFor:"layout",children:"Layout Style"}),u.jsxs(Th,{value:a.ui.layout,onValueChange:y=>l(x=>({...x,ui:{...x.ui,layout:y}})),children:[u.jsx(Ha,{children:u.jsx(kh,{})}),u.jsxs(Wa,{children:[u.jsx(ar,{value:"sidebar",children:"Sidebar Layout"}),u.jsx(ar,{value:"fullscreen",children:"Fullscreen"}),u.jsx(ar,{value:"tabs",children:"Tabbed Interface"})]})]})]}),u.jsxs("div",{className:"space-y-2",children:[u.jsx(tn,{htmlFor:"theme",children:"Theme"}),u.jsxs(Th,{value:a.ui.theme,onValueChange:y=>l(x=>({...x,ui:{...x.ui,theme:y}})),children:[u.jsx(Ha,{children:u.jsx(kh,{})}),u.jsxs(Wa,{children:[u.jsx(ar,{value:"light",children:"Light"}),u.jsx(ar,{value:"dark",children:"Dark"}),u.jsx(ar,{value:"system",children:"System"})]})]})]}),u.jsx(jh,{}),u.jsxs("div",{className:"space-y-3",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(tn,{htmlFor:"show-timestamps",children:"Show Timestamps"}),u.jsx(Un,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:y=>l(x=>({...x,ui:{...x.ui,showTimestamps:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(tn,{htmlFor:"show-agent-names",children:"Show Agent Names"}),u.jsx(Un,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:y=>l(x=>({...x,ui:{...x.ui,showAgentNames:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsx(tn,{htmlFor:"compact-messages",children:"Compact Messages"}),u.jsx(Un,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:y=>l(x=>({...x,ui:{...x.ui,compactMessages:y}}))})]})]})]})]}),u.jsxs(ao,{children:[u.jsx(lo,{className:"pb-3",children:u.jsxs(co,{className:"text-lg flex items-center gap-2",children:[u.jsx(le.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),u.jsxs(uo,{className:"space-y-4",children:[u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(tn,{htmlFor:"auto-save",children:"Auto-save Conversations"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),u.jsx(Un,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:y=>l(x=>({...x,behavior:{...x.behavior,autoSave:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(tn,{htmlFor:"enable-streaming",children:"Enable Streaming"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),u.jsx(Un,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:y=>l(x=>({...x,behavior:{...x.behavior,enableStreaming:y}}))})]}),u.jsxs("div",{className:"flex items-center justify-between",children:[u.jsxs("div",{children:[u.jsx(tn,{htmlFor:"typing-indicator",children:"Typing Indicator"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),u.jsx(Un,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:y=>l(x=>({...x,behavior:{...x.behavior,showTypingIndicator:y}}))})]})]})]})]}),u.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[u.jsxs(Je,{variant:"outline",onClick:h,children:[u.jsx(le.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(Je,{variant:"outline",onClick:g,children:"Cancel"}),u.jsxs(Je,{onClick:p,disabled:!c,children:[u.jsx(le.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function NT({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($s,{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(Da,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx($s,{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(Da,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),u.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:u.jsx($s,{onError:s.onError,enableFileUpload:!0})})]})})}Se.ChatApi=Fl,Se.ChatInput=dc,Se.ChatInterface=$s,Se.ChatProviders=Ro,Se.ChatSettings=AT,Se.MarkdownContent=io,Se.MessageComponent=Ls,Se.MessageList=_a,Se.ThreadManager=Da,Se.TimelineColumn=NC,Se.applySettings=PC,Se.buildMessagePreviewMap=Vg,Se.chatApiClient=_n,Se.default=NT,Se.del=$l,Se.get=Gt,Se.getChatToken=Ol,Se.getCurrentSettings=RC,Se.getDefaultApiConfig=Dp,Se.getDefaultChatSettings=Lp,Se.onChatTokenChanged=Dl,Se.post=ui,Se.put=Ll,Se.setChatToken=Io,Se.useApi=di,Se.useChatStream=Gl,Se.useMessagesReducer=Jl,Se.useStream=cc,Se.useThreadState=Mo,Se.useThreads=jo,Object.defineProperties(Se,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teodor-new-chat-ui",
3
- "version": "4.3.353",
3
+ "version": "4.3.354",
4
4
  "description": "React chat UI components with streaming support, tool calls, and modern design",
5
5
  "main": "dist/index.umd.js",
6
6
  "module": "dist/index.esm.js",
@@ -1,8 +0,0 @@
1
- import type { ChatMessage } from "@/types/api";
2
- interface StreamComponentProps {
3
- message: ChatMessage;
4
- viewMode: "preview" | "expanded";
5
- isStreaming?: boolean;
6
- }
7
- export declare function StreamComponent({ message, viewMode, isStreaming }: StreamComponentProps): import("react/jsx-runtime").JSX.Element;
8
- export {};