teodor-new-chat-ui 1.2.3 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +10 -4
- package/dist/index.umd.js +3 -3
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -177,7 +177,7 @@ function ct({
|
|
|
177
177
|
return {
|
|
178
178
|
id: w.id,
|
|
179
179
|
role: w.role === "human" ? "human" : w.role === "ai" ? "ai" : "tool",
|
|
180
|
-
content: L ? zt(w.content, { escapeHtml: !
|
|
180
|
+
content: L ? zt(w.content, { escapeHtml: !1, breaks: !0 }) : w.content,
|
|
181
181
|
timestamp: w.timestamp,
|
|
182
182
|
name: w.name,
|
|
183
183
|
tool_call_id: w.tool_call_id,
|
|
@@ -187,7 +187,7 @@ function ct({
|
|
|
187
187
|
isMarkdown: L
|
|
188
188
|
};
|
|
189
189
|
}), m = (x, w) => typeof x == "string" && Ht(x) ? {
|
|
190
|
-
content: zt(x, { escapeHtml: !
|
|
190
|
+
content: zt(x, { escapeHtml: !1, breaks: !0 }),
|
|
191
191
|
isMarkdown: !0
|
|
192
192
|
} : {
|
|
193
193
|
content: typeof x == "string" ? x : String(x),
|
|
@@ -584,7 +584,7 @@ function lr({
|
|
|
584
584
|
}
|
|
585
585
|
}, E = () => {
|
|
586
586
|
try {
|
|
587
|
-
return typeof e.content == "string" ? me(e.content) : e.role === "tool" && e.args ? me(JSON.stringify(e.args, null, 2)) : me(JSON.stringify(e.content, null, 2));
|
|
587
|
+
return typeof e.content == "string" ? e.role === "ai" && e.isMarkdown ? e.content : me(e.content) : e.role === "tool" && e.args ? me(JSON.stringify(e.args, null, 2)) : me(JSON.stringify(e.content, null, 2));
|
|
588
588
|
} catch (v) {
|
|
589
589
|
return console.warn("Error formatting message content:", v), "[Content formatting error]";
|
|
590
590
|
}
|
|
@@ -742,7 +742,13 @@ function lr({
|
|
|
742
742
|
v.branch_id
|
|
743
743
|
))
|
|
744
744
|
] }),
|
|
745
|
-
(e.role !== "tool" || a) && /* @__PURE__ */ u("div", { className:
|
|
745
|
+
(e.role !== "tool" || a) && /* @__PURE__ */ u("div", { className: `${e.role === "tool" ? "font-mono text-sm" : ""}`, children: e.role === "ai" && e.isMarkdown ? /* @__PURE__ */ u(
|
|
746
|
+
"div",
|
|
747
|
+
{
|
|
748
|
+
className: "whitespace-pre-wrap",
|
|
749
|
+
dangerouslySetInnerHTML: { __html: E() }
|
|
750
|
+
}
|
|
751
|
+
) : /* @__PURE__ */ u("div", { className: "whitespace-pre-wrap", children: E() }) }),
|
|
746
752
|
e.timestamp && /* @__PURE__ */ u("div", { className: "text-xs opacity-70 mt-2", children: new Date(e.timestamp).toLocaleTimeString() })
|
|
747
753
|
] })
|
|
748
754
|
] });
|
package/dist/index.umd.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
(function(O,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("react/jsx-runtime"),require("react"),require("lucide-react"),require("@radix-ui/react-slot"),require("class-variance-authority"),require("clsx"),require("tailwind-merge"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","lucide-react","@radix-ui/react-slot","class-variance-authority","clsx","tailwind-merge","react-dom"],a):(O=typeof globalThis<"u"?globalThis:O||self,a(O.NewChatUI={},O.jsxRuntime,O.React,O.LucideReact,O.reactSlot,O.classVarianceAuthority,O.clsx,O.tailwindMerge,O.ReactDOM))})(this,function(O,a,L,F,Re,Pt,mn,vn,wn){"use strict";function At(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const u=At(L),Ot=At(wn),et=1e4,tt=200,Lt=/^[a-zA-Z0-9\-_]{1,50}$/;function bn(e){return typeof e!="string"?String(e):e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/").trim()}function de(e){if(typeof e!="string")return String(e);const t=[/<script[^>]*>.*?<\/script>/gi,/<iframe[^>]*>.*?<\/iframe>/gi,/javascript:/gi,/vbscript:/gi,/on\w+\s*=/gi,/<object[^>]*>.*?<\/object>/gi,/<embed[^>]*>.*?<\/embed>/gi,/<form[^>]*>.*?<\/form>/gi];let r=e;for(const n of t)r=r.replace(n,"");return r.replace(/</g,"<").replace(/>/g,">").trim()}function _t(e,t=et){if(!e||typeof e!="string")throw new Error("Invalid content: must be a non-empty string");if(e.length>t)throw new Error(`Message exceeds maximum length of ${t} characters`);return e}function yn(e){if(!e||typeof e!="string")throw new Error("Invalid thread ID: must be a non-empty string");if(!Lt.test(e))throw new Error("Invalid thread ID: contains invalid characters");return e}function Te(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),_t(t),de(t)}function xn(e){if(!e||typeof e!="string")throw new Error("Invalid title: must be a non-empty string");if(e.length>tt)throw new Error(`Title exceeds maximum length of ${tt} characters`);return de(e)}function Cn(e){try{const t=JSON.parse(e);if(typeof t=="object"&&t!==null){const r=["__proto__","constructor","prototype"];for(const n of r)if(n in t)throw new Error(`Dangerous property detected: ${n}`)}return t}catch(t){throw new Error(`Invalid JSON: ${t instanceof Error?t.message:"Unknown error"}`)}}function Sn(e,t){return(...r)=>(typeof r[0]=="string"&&(r[0]=t(r[0])),e(...r))}function En(e){return!e||typeof e!="string"?"":e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'").replace(///g,"/")}function Dt(e,t={}){if(!e||typeof e!="string")return"";const{escapeHtml:r=!1,breaks:n=!0}=t;let o=En(e);return r&&(o=o.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")),n&&(o=o.replace(/\n/g,"<br>")),o=o.replace(/^### (.*$)/gm,"<h3>$1</h3>"),o=o.replace(/^## (.*$)/gm,"<h2>$1</h2>"),o=o.replace(/^# (.*$)/gm,"<h1>$1</h1>"),o=o.replace(/\*\*\*(.*?)\*\*\*/g,"<strong><em>$1</em></strong>"),o=o.replace(/\*\*(.*?)\*\*/g,"<strong>$1</strong>"),o=o.replace(/\*(.*?)\*/g,"<em>$1</em>"),o=o.replace(/```([\s\S]*?)```/g,"<pre><code>$1</code></pre>"),o=o.replace(/`(.*?)`/g,"<code>$1</code>"),o=o.replace(/^[\s]*\* (.*$)/gm,"<li>$1</li>"),o=o.replace(/^[\s]*- (.*$)/gm,"<li>$1</li>"),o=o.replace(/^[\s]*\+ (.*$)/gm,"<li>$1</li>"),o=o.replace(/(<li>[\s\S]*?<\/li>)/g,s=>s.includes("<ul>")?s:`<ul>${s}</ul>`),o=o.replace(/^[\s]*\d+\. (.*$)/gm,"<li>$1</li>"),o=o.replace(/(<li>[\s\S]*?<\/li>)/g,(s,i,l,f)=>{const c=f.substring(0,l);return/\d+\.\s/.test(c.split(`
|
|
2
|
-
`).pop()||"")&&!s.includes("<ol>")&&!s.includes("<ul>")?`<ol>${s}</ol>`:s}),o=o.replace(/\[([^\]]+)\]\(([^)]+)\)/g,'<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>'),o=o.replace(/(https?:\/\/[^\s]+)/g,'<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>'),o=o.replace(/^> (.*$)/gm,"<blockquote>$1</blockquote>"),o=o.replace(/<br>\s*<br>/g,"<br>"),o.trim()}function Mt(e){return!e||typeof e!="string"?!1:[/^#+\s/m,/\*\*.*?\*\*/,/\*.*?\*/,/```[\s\S]*?```/,/`.*?`/,/^\s*[-*+]\s/m,/^\s*\d+\.\s/m,/\[.*?\]\(.*?\)/,/^>\s/m].some(r=>r.test(e))}const kt=L.createContext(null),Tn="http://localhost:8000/api/chat";function _e({children:e,apiBaseUrl:t=Tn,enableUrlSync:r=!1,getAuthHeaders:n,authToken:o}){const[s,i]=L.useState({currentThreadId:null,messages:[],isLoading:!1,isLoadingHistory:!1,error:null,interrupt:null,threads:[],loadingThreads:!1,availableBranches:[],currentBranch:null}),l=L.useCallback(()=>r?new URLSearchParams(window.location.search).get("thread"):null,[r]),f=L.useCallback(x=>{if(!r)return;const w=new URL(window.location.href);x?w.searchParams.set("thread",x):w.searchParams.delete("thread"),window.history.pushState({},"",w.toString())},[r]);L.useEffect(()=>{if(r){const x=l();x&&i(w=>({...w,currentThreadId:x}))}},[r,l]),L.useEffect(()=>{if(!r)return;const x=()=>{const w=l();i(P=>({...P,currentThreadId:w}))};return window.addEventListener("popstate",x),()=>window.removeEventListener("popstate",x)},[r,l]);const c=L.useCallback((x={})=>{const w={"Content-Type":"application/json",...x};if(n)return{...w,...n()};if(o)return{...w,Authorization:`Bearer ${o}`};const P=localStorage.getItem("authToken");return P?{...w,Authorization:`Bearer ${P}`}:w},[n,o]),d=L.useCallback(async()=>{i(x=>({...x,loadingThreads:!0}));try{const x=await fetch(`${t}/threads`,{headers:c()});if(!x.ok)throw new Error("Failed to load threads");const w=await x.json();i(P=>({...P,threads:w,loadingThreads:!1}))}catch(x){i(w=>({...w,loadingThreads:!1,error:x instanceof Error?x.message:"Failed to load threads"}))}},[t,c]),h=x=>x.map(w=>{const D=w.role==="ai"&&typeof w.content=="string"&&Mt(w.content);return{id:w.id,role:w.role==="human"?"human":w.role==="ai"?"ai":"tool",content:D?Dt(w.content,{escapeHtml:!
|
|
3
|
-
`);D=j.pop()||"";for(const H of j)if(H.trim()&&H.startsWith("data: "))try{const V=JSON.parse(H.slice(6));V.type==="text"?i(ie=>{const ae=[...ie.messages],Z=ae[ae.length-1];return Z&&Z.role==="ai"?Z.content+=V.text:ae.push({id:`ai-${Date.now()}`,role:"ai",content:V.text,timestamp:new Date().toISOString()}),{...ie,messages:ae}}):V.type==="tool_call"?i(ie=>({...ie,messages:[...ie.messages,{id:`tool-${Date.now()}`,role:"tool",content:V.result||"",name:V.name||"unknown_function",tool_call_id:V.id,args:V.args,timestamp:new Date().toISOString()}]})):V.type==="complete"&&i(ie=>{const ae=[...ie.messages],Z=ae[ae.length-1];if(Z&&Z.role==="ai"&&typeof Z.content=="string"){const Ze=p(Z.content,"ai");Z.content=Ze.content,Z.isMarkdown=Ze.isMarkdown}return{...ie,messages:ae,isLoading:!1}})}catch(V){console.warn("Failed to parse streaming data:",H,V)}}}catch(k){console.error("Streaming error:",k)}finally{i(k=>({...k,isLoading:!1}))}};L.useEffect(()=>{d()},[d]);const b=L.useCallback(async(x,w,P=!1)=>{if(!(!s.currentThreadId||!x.id)){i(D=>({...D,isLoading:!0,error:null}));try{const D=w?P?"edit_from_input":"edit_and_regenerate":"regenerate",T=await fetch(`${t}/stream`,{method:"POST",headers:c(),body:JSON.stringify({thread_id:s.currentThreadId,messages:s.messages,operation:D,from_message_id:x.id,edited_content:w,create_branch:!!w})});if(!T.ok){const k=await T.text();throw new Error(`HTTP ${T.status}: ${k}`)}await v(T),await Promise.all([g(s.currentThreadId),m(s.currentThreadId)])}catch(D){i(T=>({...T,isLoading:!1,error:D instanceof Error?D.message:"Failed to regenerate message"}))}}},[t,s.currentThreadId,s.messages,g,m,c]),_=L.useCallback(async(x,w,P=!1,D=!1)=>{if(!(!s.currentThreadId||!x.id)){if(P){await b(x,w,D);return}i(T=>({...T,messages:T.messages.map(k=>k.id===x.id?{...k,content:w}:k)}))}},[s.currentThreadId,b]),N=L.useCallback(async x=>{if(s.currentThreadId)try{if(!(await fetch(`${t}/threads/${s.currentThreadId}/branch`,{method:"PATCH",headers:c(),body:JSON.stringify({branch_id:x})})).ok)throw new Error("Failed to switch branch");i(P=>({...P,currentBranch:x})),await g(s.currentThreadId)}catch(w){i(P=>({...P,error:w instanceof Error?w.message:"Failed to switch branch"}))}},[t,s.currentThreadId,g,c]),I=L.useCallback(()=>{i(x=>({...x,isLoading:!1}))},[]),$=L.useCallback(()=>{i(x=>({...x,error:null}))},[]),z=L.useCallback(async()=>{await d(),s.currentThreadId&&await Promise.all([g(s.currentThreadId),m(s.currentThreadId)])},[d,g,m,s.currentThreadId]),W={...s,selectThread:y,createThread:C,deleteThread:S,updateThreadTitle:E,sendMessage:A,editMessage:_,regenerateFromMessage:b,stop:I,switchBranch:N,clearError:$,refresh:z};return a.jsx(kt.Provider,{value:W,children:e})}function pe(){const e=L.useContext(kt);if(!e)throw new Error("useChat must be used within a ChatProvider");return e}function Y(...e){return vn.twMerge(mn.clsx(e))}const Nn=Pt.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),B=u.forwardRef(({className:e,variant:t,size:r,asChild:n=!1,...o},s)=>{const i=n?Re.Slot:"button";return a.jsx(i,{className:Y(Nn({variant:t,size:r,className:e})),ref:s,...o})});B.displayName="Button";const De=u.forwardRef(({className:e,...t},r)=>a.jsx("textarea",{className:Y("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background 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",e),ref:r,...t}));De.displayName="Textarea";function rt({message:e,onRegenerate:t,onEditMessage:r,showRegenerate:n=!1,showBranches:o=!1,branches:s=[],onSwitchBranch:i}){var A;const[l,f]=L.useState(!1),[c,d]=L.useState(!1),[h,p]=L.useState(typeof e.content=="string"?e.content:JSON.stringify(e.content)),g=()=>{t&&t(e)},m=()=>{try{const v=typeof e.content=="string"?e.content:JSON.stringify(e.content),b=Te(h);b.trim()&&b!==v&&r&&r(e,b.trim(),!0)}catch(v){console.error("Error validating edit content:",v)}d(!1)},y=()=>{const v=typeof e.content=="string"?e.content:JSON.stringify(e.content);p(v),d(!1)},C=()=>{switch(e.role){case"human":return a.jsx(F.User,{size:20,className:"text-blue-600"});case"ai":return a.jsx(F.Bot,{size:20,className:"text-green-600"});case"tool":return a.jsx(F.Wrench,{size:20,className:"text-orange-600"});default:return a.jsx(F.Bot,{size:20,className:"text-gray-600"})}},S=()=>{switch(e.role){case"human":return"You";case"ai":return"Assistant";case"tool":return e.name||"Tool";default:return"Message"}},E=()=>{try{return typeof e.content=="string"?de(e.content):e.role==="tool"&&e.args?de(JSON.stringify(e.args,null,2)):de(JSON.stringify(e.content,null,2))}catch(v){return console.warn("Error formatting message content:",v),"[Content formatting error]"}};return console.log("Rendering message:",e),e.role==="human"?a.jsxs("div",{className:"flex gap-3 justify-end mb-4",children:[a.jsxs("div",{className:"max-w-[80%] rounded-lg p-4 relative group",style:{backgroundColor:"#2563eb",color:"white",border:"2px solid #1d4ed8",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1)"},children:[e.id&&r&&a.jsx("div",{className:"absolute -top-1 -right-1 flex space-x-1 opacity-0 group-hover:opacity-100 transition-opacity",children:c?a.jsxs(a.Fragment,{children:[a.jsx(B,{size:"sm",variant:"ghost",onClick:m,className:"h-6 w-6 p-0 bg-white/10 hover:bg-white/20",title:"Save changes and regenerate",children:a.jsx(F.Check,{className:"h-3 w-3"})}),a.jsx(B,{size:"sm",variant:"ghost",onClick:y,className:"h-6 w-6 p-0 bg-white/10 hover:bg-white/20",title:"Cancel editing",children:a.jsx(F.X,{className:"h-3 w-3"})})]}):a.jsx(B,{size:"sm",variant:"ghost",onClick:()=>{const v=typeof e.content=="string"?e.content:JSON.stringify(e.content);r(e,v,!1,!0)},className:"h-6 w-6 p-0 bg-white/10 hover:bg-white/20",title:"Edit message in input field and create branch",children:a.jsx(F.Edit2,{className:"h-3 w-3"})})}),a.jsx("div",{className:"whitespace-pre-wrap",style:{color:"white"},children:c?a.jsx(De,{value:h,onChange:v=>p(v.target.value),className:"w-full min-h-[60px] bg-white/10 border-white/20 text-white placeholder-white/70",placeholder:"Edit your message...",autoFocus:!0}):a.jsx("span",{style:{color:"white"},children:de(((A=e.content)==null?void 0:A.toString())||"[No content]")})}),e.timestamp&&!c&&a.jsx("div",{className:"text-xs opacity-70 mt-2",style:{color:"white"},children:new Date(e.timestamp).toLocaleTimeString()})]}),a.jsx("div",{className:"flex-shrink-0 w-8 h-8 rounded-full bg-blue-600 flex items-center justify-center",children:C()})]}):a.jsxs("div",{className:"flex gap-3 justify-start mb-4",children:[a.jsx("div",{className:"flex-shrink-0 w-8 h-8 rounded-full bg-gray-100 flex items-center justify-center",children:C()}),a.jsxs("div",{className:`
|
|
2
|
+
`).pop()||"")&&!s.includes("<ol>")&&!s.includes("<ul>")?`<ol>${s}</ol>`:s}),o=o.replace(/\[([^\]]+)\]\(([^)]+)\)/g,'<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>'),o=o.replace(/(https?:\/\/[^\s]+)/g,'<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>'),o=o.replace(/^> (.*$)/gm,"<blockquote>$1</blockquote>"),o=o.replace(/<br>\s*<br>/g,"<br>"),o.trim()}function Mt(e){return!e||typeof e!="string"?!1:[/^#+\s/m,/\*\*.*?\*\*/,/\*.*?\*/,/```[\s\S]*?```/,/`.*?`/,/^\s*[-*+]\s/m,/^\s*\d+\.\s/m,/\[.*?\]\(.*?\)/,/^>\s/m].some(r=>r.test(e))}const kt=L.createContext(null),Tn="http://localhost:8000/api/chat";function _e({children:e,apiBaseUrl:t=Tn,enableUrlSync:r=!1,getAuthHeaders:n,authToken:o}){const[s,i]=L.useState({currentThreadId:null,messages:[],isLoading:!1,isLoadingHistory:!1,error:null,interrupt:null,threads:[],loadingThreads:!1,availableBranches:[],currentBranch:null}),l=L.useCallback(()=>r?new URLSearchParams(window.location.search).get("thread"):null,[r]),f=L.useCallback(x=>{if(!r)return;const w=new URL(window.location.href);x?w.searchParams.set("thread",x):w.searchParams.delete("thread"),window.history.pushState({},"",w.toString())},[r]);L.useEffect(()=>{if(r){const x=l();x&&i(w=>({...w,currentThreadId:x}))}},[r,l]),L.useEffect(()=>{if(!r)return;const x=()=>{const w=l();i(P=>({...P,currentThreadId:w}))};return window.addEventListener("popstate",x),()=>window.removeEventListener("popstate",x)},[r,l]);const c=L.useCallback((x={})=>{const w={"Content-Type":"application/json",...x};if(n)return{...w,...n()};if(o)return{...w,Authorization:`Bearer ${o}`};const P=localStorage.getItem("authToken");return P?{...w,Authorization:`Bearer ${P}`}:w},[n,o]),d=L.useCallback(async()=>{i(x=>({...x,loadingThreads:!0}));try{const x=await fetch(`${t}/threads`,{headers:c()});if(!x.ok)throw new Error("Failed to load threads");const w=await x.json();i(P=>({...P,threads:w,loadingThreads:!1}))}catch(x){i(w=>({...w,loadingThreads:!1,error:x instanceof Error?x.message:"Failed to load threads"}))}},[t,c]),h=x=>x.map(w=>{const D=w.role==="ai"&&typeof w.content=="string"&&Mt(w.content);return{id:w.id,role:w.role==="human"?"human":w.role==="ai"?"ai":"tool",content:D?Dt(w.content,{escapeHtml:!1,breaks:!0}):w.content,timestamp:w.timestamp,name:w.name,tool_call_id:w.tool_call_id,args:w.args,branch_id:w.branch_id,sequence_number:w.sequence_number,isMarkdown:D}}),p=(x,w)=>typeof x=="string"&&Mt(x)?{content:Dt(x,{escapeHtml:!1,breaks:!0}),isMarkdown:!0}:{content:typeof x=="string"?x:String(x),isMarkdown:!1},g=L.useCallback(async x=>{i(w=>({...w,isLoadingHistory:!0}));try{const w=await fetch(`${t}/history/${x}`,{headers:c()});if(!w.ok)throw new Error("Failed to load history");const P=await w.json(),D=h(P);i(T=>({...T,messages:D,isLoadingHistory:!1}))}catch(w){i(P=>({...P,isLoadingHistory:!1,error:w instanceof Error?w.message:"Failed to load history"}))}},[t,c]),m=L.useCallback(async x=>{try{const w=await fetch(`${t}/threads/${x}/branches`,{headers:c()});if(!w.ok)return;const P=await w.json();i(D=>({...D,availableBranches:P.branches||[],currentBranch:P.current_branch}))}catch(w){console.warn("Failed to load branches:",w)}},[t,c]),y=L.useCallback(x=>{i(w=>({...w,currentThreadId:x,messages:[],availableBranches:[],currentBranch:null,error:null})),f(x),x&&Promise.all([g(x),m(x)]).catch(w=>{console.error("Failed to load thread data:",w)})},[f,g,m]),C=L.useCallback(async()=>{try{const x=await fetch(`${t}/threads`,{method:"POST",headers:c()});if(!x.ok)throw new Error("Failed to create thread");const P=(await x.json()).thread_id;return await d(),P}catch(x){throw i(w=>({...w,error:x instanceof Error?x.message:"Failed to create thread"})),x}},[t,c,d]),S=L.useCallback(async x=>{console.log("deleteThread called with threadId:",x),console.log("apiBaseUrl:",t);try{const w=`${t}/threads/${x}`;console.log("Making DELETE request to:",w);const P=await fetch(w,{method:"DELETE",headers:c()});if(console.log("Delete response status:",P.status),console.log("Delete response ok:",P.ok),!P.ok){const D=await P.text();throw console.log("Delete error response:",D),new Error(`Failed to delete thread: ${P.status} ${D}`)}console.log("Thread deleted successfully"),s.currentThreadId===x&&(console.log("Clearing current thread as it was deleted"),y(null)),console.log("Reloading threads list"),await d()}catch(w){console.error("Error deleting thread:",w),i(P=>({...P,error:w instanceof Error?w.message:"Failed to delete thread"}))}},[t,s.currentThreadId,y,d,c]),E=L.useCallback(async(x,w)=>{try{if(!(await fetch(`${t}/threads/${x}/title`,{method:"PATCH",headers:c(),body:JSON.stringify({title:w})})).ok)throw new Error("Failed to update thread title");await d()}catch(P){i(D=>({...D,error:P instanceof Error?P.message:"Failed to update thread title"}))}},[t,d,c]),A=L.useCallback(async x=>{if(s.currentThreadId)try{const w=Te(x),P={id:`temp-${Date.now()}`,role:"human",content:w,timestamp:new Date().toISOString()};i(D=>({...D,messages:[...D.messages,P],isLoading:!0,error:null}));try{const D=await fetch(`${t}/stream`,{method:"POST",headers:c(),body:JSON.stringify({thread_id:s.currentThreadId,messages:[...s.messages,{role:"human",content:w}],operation:"continue"})});if(!D.ok){const T=await D.text();throw new Error(`HTTP ${D.status}: ${T}`)}await v(D),await g(s.currentThreadId)}catch(D){i(T=>({...T,messages:T.messages.filter(k=>k.id!==P.id),isLoading:!1,error:D instanceof Error?D.message:"Failed to send message"}))}}catch(w){i(P=>({...P,error:w instanceof Error?w.message:"Invalid message content"}))}},[t,s.currentThreadId,s.messages,g,c]),v=async x=>{var T;const w=(T=x.body)==null?void 0:T.getReader();if(!w){i(k=>({...k,isLoading:!1}));return}const P=new TextDecoder;let D="";try{for(;;){const{done:k,value:M}=await w.read();if(k)break;D+=P.decode(M,{stream:!0});const j=D.split(`
|
|
3
|
+
`);D=j.pop()||"";for(const H of j)if(H.trim()&&H.startsWith("data: "))try{const V=JSON.parse(H.slice(6));V.type==="text"?i(ie=>{const ae=[...ie.messages],Z=ae[ae.length-1];return Z&&Z.role==="ai"?Z.content+=V.text:ae.push({id:`ai-${Date.now()}`,role:"ai",content:V.text,timestamp:new Date().toISOString()}),{...ie,messages:ae}}):V.type==="tool_call"?i(ie=>({...ie,messages:[...ie.messages,{id:`tool-${Date.now()}`,role:"tool",content:V.result||"",name:V.name||"unknown_function",tool_call_id:V.id,args:V.args,timestamp:new Date().toISOString()}]})):V.type==="complete"&&i(ie=>{const ae=[...ie.messages],Z=ae[ae.length-1];if(Z&&Z.role==="ai"&&typeof Z.content=="string"){const Ze=p(Z.content,"ai");Z.content=Ze.content,Z.isMarkdown=Ze.isMarkdown}return{...ie,messages:ae,isLoading:!1}})}catch(V){console.warn("Failed to parse streaming data:",H,V)}}}catch(k){console.error("Streaming error:",k)}finally{i(k=>({...k,isLoading:!1}))}};L.useEffect(()=>{d()},[d]);const b=L.useCallback(async(x,w,P=!1)=>{if(!(!s.currentThreadId||!x.id)){i(D=>({...D,isLoading:!0,error:null}));try{const D=w?P?"edit_from_input":"edit_and_regenerate":"regenerate",T=await fetch(`${t}/stream`,{method:"POST",headers:c(),body:JSON.stringify({thread_id:s.currentThreadId,messages:s.messages,operation:D,from_message_id:x.id,edited_content:w,create_branch:!!w})});if(!T.ok){const k=await T.text();throw new Error(`HTTP ${T.status}: ${k}`)}await v(T),await Promise.all([g(s.currentThreadId),m(s.currentThreadId)])}catch(D){i(T=>({...T,isLoading:!1,error:D instanceof Error?D.message:"Failed to regenerate message"}))}}},[t,s.currentThreadId,s.messages,g,m,c]),_=L.useCallback(async(x,w,P=!1,D=!1)=>{if(!(!s.currentThreadId||!x.id)){if(P){await b(x,w,D);return}i(T=>({...T,messages:T.messages.map(k=>k.id===x.id?{...k,content:w}:k)}))}},[s.currentThreadId,b]),N=L.useCallback(async x=>{if(s.currentThreadId)try{if(!(await fetch(`${t}/threads/${s.currentThreadId}/branch`,{method:"PATCH",headers:c(),body:JSON.stringify({branch_id:x})})).ok)throw new Error("Failed to switch branch");i(P=>({...P,currentBranch:x})),await g(s.currentThreadId)}catch(w){i(P=>({...P,error:w instanceof Error?w.message:"Failed to switch branch"}))}},[t,s.currentThreadId,g,c]),I=L.useCallback(()=>{i(x=>({...x,isLoading:!1}))},[]),$=L.useCallback(()=>{i(x=>({...x,error:null}))},[]),z=L.useCallback(async()=>{await d(),s.currentThreadId&&await Promise.all([g(s.currentThreadId),m(s.currentThreadId)])},[d,g,m,s.currentThreadId]),W={...s,selectThread:y,createThread:C,deleteThread:S,updateThreadTitle:E,sendMessage:A,editMessage:_,regenerateFromMessage:b,stop:I,switchBranch:N,clearError:$,refresh:z};return a.jsx(kt.Provider,{value:W,children:e})}function pe(){const e=L.useContext(kt);if(!e)throw new Error("useChat must be used within a ChatProvider");return e}function Y(...e){return vn.twMerge(mn.clsx(e))}const Nn=Pt.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),B=u.forwardRef(({className:e,variant:t,size:r,asChild:n=!1,...o},s)=>{const i=n?Re.Slot:"button";return a.jsx(i,{className:Y(Nn({variant:t,size:r,className:e})),ref:s,...o})});B.displayName="Button";const De=u.forwardRef(({className:e,...t},r)=>a.jsx("textarea",{className:Y("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background 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",e),ref:r,...t}));De.displayName="Textarea";function rt({message:e,onRegenerate:t,onEditMessage:r,showRegenerate:n=!1,showBranches:o=!1,branches:s=[],onSwitchBranch:i}){var A;const[l,f]=L.useState(!1),[c,d]=L.useState(!1),[h,p]=L.useState(typeof e.content=="string"?e.content:JSON.stringify(e.content)),g=()=>{t&&t(e)},m=()=>{try{const v=typeof e.content=="string"?e.content:JSON.stringify(e.content),b=Te(h);b.trim()&&b!==v&&r&&r(e,b.trim(),!0)}catch(v){console.error("Error validating edit content:",v)}d(!1)},y=()=>{const v=typeof e.content=="string"?e.content:JSON.stringify(e.content);p(v),d(!1)},C=()=>{switch(e.role){case"human":return a.jsx(F.User,{size:20,className:"text-blue-600"});case"ai":return a.jsx(F.Bot,{size:20,className:"text-green-600"});case"tool":return a.jsx(F.Wrench,{size:20,className:"text-orange-600"});default:return a.jsx(F.Bot,{size:20,className:"text-gray-600"})}},S=()=>{switch(e.role){case"human":return"You";case"ai":return"Assistant";case"tool":return e.name||"Tool";default:return"Message"}},E=()=>{try{return typeof e.content=="string"?e.role==="ai"&&e.isMarkdown?e.content:de(e.content):e.role==="tool"&&e.args?de(JSON.stringify(e.args,null,2)):de(JSON.stringify(e.content,null,2))}catch(v){return console.warn("Error formatting message content:",v),"[Content formatting error]"}};return console.log("Rendering message:",e),e.role==="human"?a.jsxs("div",{className:"flex gap-3 justify-end mb-4",children:[a.jsxs("div",{className:"max-w-[80%] rounded-lg p-4 relative group",style:{backgroundColor:"#2563eb",color:"white",border:"2px solid #1d4ed8",boxShadow:"0 4px 6px -1px rgba(0, 0, 0, 0.1)"},children:[e.id&&r&&a.jsx("div",{className:"absolute -top-1 -right-1 flex space-x-1 opacity-0 group-hover:opacity-100 transition-opacity",children:c?a.jsxs(a.Fragment,{children:[a.jsx(B,{size:"sm",variant:"ghost",onClick:m,className:"h-6 w-6 p-0 bg-white/10 hover:bg-white/20",title:"Save changes and regenerate",children:a.jsx(F.Check,{className:"h-3 w-3"})}),a.jsx(B,{size:"sm",variant:"ghost",onClick:y,className:"h-6 w-6 p-0 bg-white/10 hover:bg-white/20",title:"Cancel editing",children:a.jsx(F.X,{className:"h-3 w-3"})})]}):a.jsx(B,{size:"sm",variant:"ghost",onClick:()=>{const v=typeof e.content=="string"?e.content:JSON.stringify(e.content);r(e,v,!1,!0)},className:"h-6 w-6 p-0 bg-white/10 hover:bg-white/20",title:"Edit message in input field and create branch",children:a.jsx(F.Edit2,{className:"h-3 w-3"})})}),a.jsx("div",{className:"whitespace-pre-wrap",style:{color:"white"},children:c?a.jsx(De,{value:h,onChange:v=>p(v.target.value),className:"w-full min-h-[60px] bg-white/10 border-white/20 text-white placeholder-white/70",placeholder:"Edit your message...",autoFocus:!0}):a.jsx("span",{style:{color:"white"},children:de(((A=e.content)==null?void 0:A.toString())||"[No content]")})}),e.timestamp&&!c&&a.jsx("div",{className:"text-xs opacity-70 mt-2",style:{color:"white"},children:new Date(e.timestamp).toLocaleTimeString()})]}),a.jsx("div",{className:"flex-shrink-0 w-8 h-8 rounded-full bg-blue-600 flex items-center justify-center",children:C()})]}):a.jsxs("div",{className:"flex gap-3 justify-start mb-4",children:[a.jsx("div",{className:"flex-shrink-0 w-8 h-8 rounded-full bg-gray-100 flex items-center justify-center",children:C()}),a.jsxs("div",{className:`
|
|
4
4
|
max-w-[80%] rounded-lg p-3 relative group
|
|
5
5
|
${e.role==="tool"?"bg-orange-50 border border-orange-200":"bg-gray-100 text-gray-900"}
|
|
6
|
-
`,children:[a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("div",{className:"font-medium text-sm",children:S()}),e.role==="tool"&&a.jsxs(B,{variant:"ghost",size:"sm",onClick:()=>f(!l),className:"h-6 px-2 text-xs",children:[l?a.jsx(F.ChevronDown,{size:12}):a.jsx(F.ChevronRight,{size:12}),l?"Hide":"Show"," Content"]})]}),n&&t&&a.jsxs(B,{variant:"ghost",size:"sm",onClick:g,className:"h-6 px-2 text-xs",children:[a.jsx(F.RotateCcw,{size:12,className:"mr-1"}),"Regenerate"]})]}),o&&s&&s.length>1&&e.role==="ai"&&a.jsxs("div",{className:"flex items-center gap-2 mb-3 p-2 bg-white/50 rounded border text-xs",children:[a.jsx(F.GitBranch,{size:12,className:"text-gray-500"}),a.jsx("span",{className:"text-gray-600",children:"Branch:"}),a.jsxs("div",{className:"flex items-center gap-1",children:[a.jsx(B,{variant:"ghost",size:"sm",onClick:()=>{const v=s.findIndex(_=>_.is_current),b=v>0?v-1:s.length-1;i==null||i(s[b].branch_id)},className:"h-5 w-5 p-0",title:"Previous branch",children:a.jsx(F.ChevronLeft,{size:10})}),a.jsxs("span",{className:"mx-2 font-mono text-xs",children:[s.findIndex(v=>v.is_current)+1," / ",s.length]}),a.jsx(B,{variant:"ghost",size:"sm",onClick:()=>{const v=s.findIndex(_=>_.is_current),b=v<s.length-1?v+1:0;i==null||i(s[b].branch_id)},className:"h-5 w-5 p-0",title:"Next branch",children:a.jsx(F.ChevronRight,{size:10})})]}),s.map((v,b)=>a.jsx(B,{variant:v.is_current?"default":"ghost",size:"sm",onClick:()=>i==null?void 0:i(v.branch_id),className:"h-5 px-2 text-xs",title:`Switch to branch ${b+1}: ${v.preview}`,children:b+1},v.branch_id))]}),(e.role!=="tool"||l)&&a.jsx("div",{className:`whitespace-pre-wrap ${e.role==="tool"?"font-mono text-sm":""}`,children:E()}),e.timestamp&&a.jsx("div",{className:"text-xs opacity-70 mt-2",children:new Date(e.timestamp).toLocaleTimeString()})]})]})}function me({className:e="",placeholder:t="Type your message...",autoFocus:r=!0,showBranches:n=!0,maxHeight:o="600px",enableInputFieldEditing:s=!1}){const{currentThreadId:i,messages:l,isLoading:f,isLoadingHistory:c,error:d,availableBranches:h,currentBranch:p,sendMessage:g,stop:m,switchBranch:y,regenerateFromMessage:C,editMessage:S,clearError:E}=pe(),[A,v]=L.useState(""),[b,_]=L.useState(null),[N,I]=L.useState(null),$=L.useRef(null),z=L.useRef(null);L.useEffect(()=>{var T;(T=$.current)==null||T.scrollIntoView({behavior:"smooth"})},[l]),L.useEffect(()=>{r&&z.current&&z.current.focus()},[r,i]);const W=async T=>{if(T.preventDefault(),!(!A.trim()||f||!i))try{const k=Te(A.trim());v(""),I(null),b&&s?(await x(b,k),_(null)):await g(k)}catch(k){I(k instanceof Error?k.message:"Invalid input")}},x=async(T,k)=>{try{const M=l.find(H=>H.id===T);if(!M)return;const j=Te(k);await S(M,j,!0,!0)}catch(M){I(M instanceof Error?M.message:"Invalid edit content")}},w=T=>{T.key==="Enter"&&!T.shiftKey?(T.preventDefault(),W(T)):T.key==="Escape"&&b&&(_(null),v(""),I(null))},P=async T=>{await C(T)},D=async(T,k,M=!1,j=!1)=>{j?(_(T.id),v(k),setTimeout(()=>{var H;return(H=z.current)==null?void 0:H.focus()},0)):await S(T,k,M)};return i?a.jsxs("div",{className:`flex flex-col h-full ${e}`,children:[N&&a.jsx("div",{className:"bg-red-50 border-l-4 border-red-400 p-4 mb-4",children:a.jsxs("div",{className:"flex justify-between items-center",children:[a.jsx("div",{className:"text-red-700 text-sm",children:N}),a.jsx(B,{variant:"ghost",size:"sm",onClick:()=>I(null),className:"text-red-600 hover:text-red-700",children:"×"})]})}),d&&a.jsx("div",{className:"bg-red-50 border-l-4 border-red-400 p-4 mb-4",children:a.jsxs("div",{className:"flex justify-between items-center",children:[a.jsx("div",{className:"text-red-700 text-sm",children:d}),a.jsx(B,{variant:"ghost",size:"sm",onClick:E,className:"text-red-600 hover:text-red-700",children:"×"})]})}),b&&s&&a.jsx("div",{className:"bg-blue-50 border-l-4 border-blue-400 p-4 mb-4",children:a.jsxs("div",{className:"flex justify-between items-center",children:[a.jsxs("div",{className:"text-blue-700 text-sm flex items-center",children:[a.jsx(F.Edit3,{size:16,className:"mr-2"}),"Editing message - modify your text below and press Enter to create a new branch"]}),a.jsx(B,{variant:"ghost",size:"sm",onClick:()=>{_(null),v(""),I(null)},className:"text-blue-600 hover:text-blue-700",children:a.jsx(F.X,{size:16})})]})}),n&&h.length>1&&a.jsxs("div",{className:"border-b p-3 bg-gray-50",children:[a.jsx("div",{className:"text-sm font-medium mb-2",children:"Branches:"}),a.jsx("div",{className:"flex gap-2 flex-wrap",children:h.map(T=>a.jsxs(B,{size:"sm",variant:p===T.branch_id?"default":"outline",onClick:()=>y(T.branch_id),className:"text-xs",children:[T.preview,a.jsxs("span",{className:"ml-1 text-gray-500",children:["(",T.message_count,")"]})]},T.branch_id))})]}),a.jsxs("div",{className:"flex-1 overflow-y-auto p-4",style:{maxHeight:o},children:[c?a.jsxs("div",{className:"flex items-center justify-center py-8",children:[a.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"}),a.jsx("span",{className:"ml-2 text-gray-600",children:"Loading conversation..."})]}):l.length===0?a.jsxs("div",{className:"text-center text-gray-500 py-8",children:[a.jsx("div",{className:"text-lg font-medium mb-2",children:"Start a conversation"}),a.jsx("div",{className:"text-sm",children:"Type a message below to begin"})]}):a.jsx("div",{className:"space-y-4",children:l.map((T,k)=>{const M=h?h.filter(H=>H.from_message_index===k):[],j=M.length>1;return M.find(H=>H.branch_id===p),a.jsxs("div",{children:[j&&n&&a.jsxs("div",{className:"flex items-center gap-2 mb-2 p-2 bg-gray-50 rounded border text-xs",children:[a.jsx("span",{className:"text-gray-600",children:"Message versions:"}),a.jsx("div",{className:"flex items-center gap-1",children:M.map((H,V)=>a.jsx(B,{variant:p===H.branch_id?"default":"outline",size:"sm",onClick:()=>y(H.branch_id),className:"h-6 px-2 text-xs",title:`Version ${V+1}: ${H.preview}`,children:V+1},H.branch_id))}),a.jsxs("span",{className:"text-gray-500 ml-2",children:["(",M.findIndex(H=>H.branch_id===p)+1," of ",M.length,")"]})]}),a.jsx(rt,{message:T,onRegenerate:P,onEditMessage:D,showRegenerate:T.role==="ai"||T.role==="human",showBranches:!1,branches:M,onSwitchBranch:y})]},T.id||k)})}),a.jsx("div",{ref:$})]}),a.jsx("div",{className:"border-t p-4 bg-white",children:a.jsxs("form",{onSubmit:W,className:"flex gap-3",children:[a.jsx("div",{className:"flex-1",children:a.jsx(De,{ref:z,value:A,onChange:T=>{v(T.target.value),I(null)},onKeyDown:w,placeholder:b?"Edit your message and press Enter to create a new branch...":t,className:`resize-none min-h-[44px] max-h-32 ${b?"border-blue-400 bg-blue-50":""} ${N?"border-red-400":""}`,disabled:f,maxLength:et})}),a.jsx("div",{className:"flex flex-col gap-2",children:f?a.jsx(B,{type:"button",onClick:m,size:"icon",variant:"outline",className:"shrink-0",children:a.jsx(F.Square,{size:16})}):a.jsx(B,{type:"submit",disabled:!A.trim()||!i,size:"icon",className:`shrink-0 ${b?"bg-blue-600 hover:bg-blue-700":""}`,title:b?"Send edited message and create branch":"Send message",children:b?a.jsx(F.Check,{size:16}):a.jsx(F.Send,{size:16})})})]})})]}):a.jsx("div",{className:`flex items-center justify-center h-full ${e}`,children:a.jsxs("div",{className:"text-center text-gray-500",children:[a.jsx("div",{className:"text-lg font-medium mb-2",children:"No thread selected"}),a.jsx("div",{className:"text-sm",children:"Select a thread or create a new one to start chatting"})]})})}var Pn=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],q=Pn.reduce((e,t)=>{const r=Re.createSlot(`Primitive.${t}`),n=u.forwardRef((o,s)=>{const{asChild:i,...l}=o,f=i?r:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),a.jsx(f,{...l,ref:s})});return n.displayName=`Primitive.${t}`,{...e,[t]:n}},{});function An(e,t){e&&Ot.flushSync(()=>e.dispatchEvent(t))}function It(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function On(...e){return t=>{let r=!1;const n=e.map(o=>{const s=It(o,t);return!r&&typeof s=="function"&&(r=!0),s});if(r)return()=>{for(let o=0;o<n.length;o++){const s=n[o];typeof s=="function"?s():It(e[o],null)}}}}function U(...e){return u.useCallback(On(...e),e)}var fe=globalThis!=null&&globalThis.document?u.useLayoutEffect:()=>{};function Ln(e,t){return u.useReducer((r,n)=>t[r][n]??r,e)}var ve=e=>{const{present:t,children:r}=e,n=_n(t),o=typeof r=="function"?r({present:n.isPresent}):u.Children.only(r),s=U(n.ref,Dn(o));return typeof r=="function"||n.isPresent?u.cloneElement(o,{ref:s}):null};ve.displayName="Presence";function _n(e){const[t,r]=u.useState(),n=u.useRef(null),o=u.useRef(e),s=u.useRef("none"),i=e?"mounted":"unmounted",[l,f]=Ln(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return u.useEffect(()=>{const c=Me(n.current);s.current=l==="mounted"?c:"none"},[l]),fe(()=>{const c=n.current,d=o.current;if(d!==e){const p=s.current,g=Me(c);e?f("MOUNT"):g==="none"||(c==null?void 0:c.display)==="none"?f("UNMOUNT"):f(d&&p!==g?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,f]),fe(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,h=g=>{const y=Me(n.current).includes(g.animationName);if(g.target===t&&y&&(f("ANIMATION_END"),!o.current)){const C=t.style.animationFillMode;t.style.animationFillMode="forwards",c=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=C)})}},p=g=>{g.target===t&&(s.current=Me(n.current))};return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",h),t.addEventListener("animationend",h),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",h),t.removeEventListener("animationend",h)}}else f("ANIMATION_END")},[t,f]),{isPresent:["mounted","unmountSuspended"].includes(l),ref:u.useCallback(c=>{n.current=c?getComputedStyle(c):null,r(c)},[])}}function Me(e){return(e==null?void 0:e.animationName)||"none"}function Dn(e){var n,o;let t=(n=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:n.get,r=t&&"isReactWarning"in t&&t.isReactWarning;return r?e.ref:(t=(o=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:o.get,r=t&&"isReactWarning"in t&&t.isReactWarning,r?e.props.ref:e.props.ref||e.ref)}function nt(e,t=[]){let r=[];function n(s,i){const l=u.createContext(i),f=r.length;r=[...r,i];const c=h=>{var S;const{scope:p,children:g,...m}=h,y=((S=p==null?void 0:p[e])==null?void 0:S[f])||l,C=u.useMemo(()=>m,Object.values(m));return a.jsx(y.Provider,{value:C,children:g})};c.displayName=s+"Provider";function d(h,p){var y;const g=((y=p==null?void 0:p[e])==null?void 0:y[f])||l,m=u.useContext(g);if(m)return m;if(i!==void 0)return i;throw new Error(`\`${h}\` must be used within \`${s}\``)}return[c,d]}const o=()=>{const s=r.map(i=>u.createContext(i));return function(l){const f=(l==null?void 0:l[e])||s;return u.useMemo(()=>({[`__scope${e}`]:{...l,[e]:f}}),[l,f])}};return o.scopeName=e,[n,Mn(o,...t)]}function Mn(...e){const t=e[0];if(e.length===1)return t;const r=()=>{const n=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=n.reduce((l,{useScope:f,scopeName:c})=>{const h=f(s)[`__scope${c}`];return{...l,...h}},{});return u.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return r.scopeName=t.scopeName,r}function Q(e){const t=u.useRef(e);return u.useEffect(()=>{t.current=e}),u.useMemo(()=>(...r)=>{var n;return(n=t.current)==null?void 0:n.call(t,...r)},[])}var kn=u.createContext(void 0);function In(e){const t=u.useContext(kn);return e||t||"ltr"}function $n(e,[t,r]){return Math.min(r,Math.max(t,e))}function X(e,t,{checkForDefaultPrevented:r=!0}={}){return function(o){if(e==null||e(o),r===!1||!o.defaultPrevented)return t==null?void 0:t(o)}}function zn(e,t){return u.useReducer((r,n)=>t[r][n]??r,e)}var ot="ScrollArea",[$t,Ai]=nt(ot),[Hn,K]=$t(ot),zt=u.forwardRef((e,t)=>{const{__scopeScrollArea:r,type:n="hover",dir:o,scrollHideDelay:s=600,...i}=e,[l,f]=u.useState(null),[c,d]=u.useState(null),[h,p]=u.useState(null),[g,m]=u.useState(null),[y,C]=u.useState(null),[S,E]=u.useState(0),[A,v]=u.useState(0),[b,_]=u.useState(!1),[N,I]=u.useState(!1),$=U(t,W=>f(W)),z=In(o);return a.jsx(Hn,{scope:r,type:n,dir:z,scrollHideDelay:s,scrollArea:l,viewport:c,onViewportChange:d,content:h,onContentChange:p,scrollbarX:g,onScrollbarXChange:m,scrollbarXEnabled:b,onScrollbarXEnabledChange:_,scrollbarY:y,onScrollbarYChange:C,scrollbarYEnabled:N,onScrollbarYEnabledChange:I,onCornerWidthChange:E,onCornerHeightChange:v,children:a.jsx(q.div,{dir:z,...i,ref:$,style:{position:"relative","--radix-scroll-area-corner-width":S+"px","--radix-scroll-area-corner-height":A+"px",...e.style}})})});zt.displayName=ot;var Ht="ScrollAreaViewport",Ft=u.forwardRef((e,t)=>{const{__scopeScrollArea:r,children:n,nonce:o,...s}=e,i=K(Ht,r),l=u.useRef(null),f=U(t,l,i.onViewportChange);return a.jsxs(a.Fragment,{children:[a.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}),a.jsx(q.div,{"data-radix-scroll-area-viewport":"",...s,ref:f,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:a.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:n})})]})});Ft.displayName=Ht;var te="ScrollAreaScrollbar",st=u.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=K(te,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,l=e.orientation==="horizontal";return u.useEffect(()=>(l?s(!0):i(!0),()=>{l?s(!1):i(!1)}),[l,s,i]),o.type==="hover"?a.jsx(Fn,{...n,ref:t,forceMount:r}):o.type==="scroll"?a.jsx(Wn,{...n,ref:t,forceMount:r}):o.type==="auto"?a.jsx(Wt,{...n,ref:t,forceMount:r}):o.type==="always"?a.jsx(it,{...n,ref:t}):null});st.displayName=te;var Fn=u.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=K(te,e.__scopeScrollArea),[s,i]=u.useState(!1);return u.useEffect(()=>{const l=o.scrollArea;let f=0;if(l){const c=()=>{window.clearTimeout(f),i(!0)},d=()=>{f=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return l.addEventListener("pointerenter",c),l.addEventListener("pointerleave",d),()=>{window.clearTimeout(f),l.removeEventListener("pointerenter",c),l.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),a.jsx(ve,{present:r||s,children:a.jsx(Wt,{"data-state":s?"visible":"hidden",...n,ref:t})})}),Wn=u.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=K(te,e.__scopeScrollArea),s=e.orientation==="horizontal",i=ze(()=>f("SCROLL_END"),100),[l,f]=zn("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 u.useEffect(()=>{if(l==="idle"){const c=window.setTimeout(()=>f("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[l,o.scrollHideDelay,f]),u.useEffect(()=>{const c=o.viewport,d=s?"scrollLeft":"scrollTop";if(c){let h=c[d];const p=()=>{const g=c[d];h!==g&&(f("SCROLL"),i()),h=g};return c.addEventListener("scroll",p),()=>c.removeEventListener("scroll",p)}},[o.viewport,s,f,i]),a.jsx(ve,{present:r||l!=="hidden",children:a.jsx(it,{"data-state":l==="hidden"?"hidden":"visible",...n,ref:t,onPointerEnter:X(e.onPointerEnter,()=>f("POINTER_ENTER")),onPointerLeave:X(e.onPointerLeave,()=>f("POINTER_LEAVE"))})})}),Wt=u.forwardRef((e,t)=>{const r=K(te,e.__scopeScrollArea),{forceMount:n,...o}=e,[s,i]=u.useState(!1),l=e.orientation==="horizontal",f=ze(()=>{if(r.viewport){const c=r.viewport.offsetWidth<r.viewport.scrollWidth,d=r.viewport.offsetHeight<r.viewport.scrollHeight;i(l?c:d)}},10);return we(r.viewport,f),we(r.content,f),a.jsx(ve,{present:n||s,children:a.jsx(it,{"data-state":s?"visible":"hidden",...o,ref:t})})}),it=u.forwardRef((e,t)=>{const{orientation:r="vertical",...n}=e,o=K(te,e.__scopeScrollArea),s=u.useRef(null),i=u.useRef(0),[l,f]=u.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=Yt(l.viewport,l.content),d={...n,sizes:l,onSizesChange:f,hasThumb:c>0&&c<1,onThumbChange:p=>s.current=p,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:p=>i.current=p};function h(p,g){return qn(p,i.current,l,g)}return r==="horizontal"?a.jsx(Bn,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollLeft,g=qt(p,l,o.dir);s.current.style.transform=`translate3d(${g}px, 0, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollLeft=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollLeft=h(p,o.dir))}}):r==="vertical"?a.jsx(jn,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollTop,g=qt(p,l);s.current.style.transform=`translate3d(0, ${g}px, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollTop=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollTop=h(p))}}):null}),Bn=u.forwardRef((e,t)=>{const{sizes:r,onSizesChange:n,...o}=e,s=K(te,e.__scopeScrollArea),[i,l]=u.useState(),f=u.useRef(null),c=U(t,f,s.onScrollbarXChange);return u.useEffect(()=>{f.current&&l(getComputedStyle(f.current))},[f]),a.jsx(jt,{"data-orientation":"horizontal",...o,ref:c,sizes:r,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":$e(r)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,h)=>{if(s.viewport){const p=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(p),Jt(p,h)&&d.preventDefault()}},onResize:()=>{f.current&&s.viewport&&i&&n({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:f.current.clientWidth,paddingStart:Ie(i.paddingLeft),paddingEnd:Ie(i.paddingRight)}})}})}),jn=u.forwardRef((e,t)=>{const{sizes:r,onSizesChange:n,...o}=e,s=K(te,e.__scopeScrollArea),[i,l]=u.useState(),f=u.useRef(null),c=U(t,f,s.onScrollbarYChange);return u.useEffect(()=>{f.current&&l(getComputedStyle(f.current))},[f]),a.jsx(jt,{"data-orientation":"vertical",...o,ref:c,sizes:r,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":$e(r)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,h)=>{if(s.viewport){const p=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(p),Jt(p,h)&&d.preventDefault()}},onResize:()=>{f.current&&s.viewport&&i&&n({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:f.current.clientHeight,paddingStart:Ie(i.paddingTop),paddingEnd:Ie(i.paddingBottom)}})}})}),[Vn,Bt]=$t(te),jt=u.forwardRef((e,t)=>{const{__scopeScrollArea:r,sizes:n,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:l,onThumbPositionChange:f,onDragScroll:c,onWheelScroll:d,onResize:h,...p}=e,g=K(te,r),[m,y]=u.useState(null),C=U(t,$=>y($)),S=u.useRef(null),E=u.useRef(""),A=g.viewport,v=n.content-n.viewport,b=Q(d),_=Q(f),N=ze(h,10);function I($){if(S.current){const z=$.clientX-S.current.left,W=$.clientY-S.current.top;c({x:z,y:W})}}return u.useEffect(()=>{const $=z=>{const W=z.target;(m==null?void 0:m.contains(W))&&b(z,v)};return document.addEventListener("wheel",$,{passive:!1}),()=>document.removeEventListener("wheel",$,{passive:!1})},[A,m,v,b]),u.useEffect(_,[n,_]),we(m,N),we(g.content,N),a.jsx(Vn,{scope:r,scrollbar:m,hasThumb:o,onThumbChange:Q(s),onThumbPointerUp:Q(i),onThumbPositionChange:_,onThumbPointerDown:Q(l),children:a.jsx(q.div,{...p,ref:C,style:{position:"absolute",...p.style},onPointerDown:X(e.onPointerDown,$=>{$.button===0&&($.target.setPointerCapture($.pointerId),S.current=m.getBoundingClientRect(),E.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",g.viewport&&(g.viewport.style.scrollBehavior="auto"),I($))}),onPointerMove:X(e.onPointerMove,I),onPointerUp:X(e.onPointerUp,$=>{const z=$.target;z.hasPointerCapture($.pointerId)&&z.releasePointerCapture($.pointerId),document.body.style.webkitUserSelect=E.current,g.viewport&&(g.viewport.style.scrollBehavior=""),S.current=null})})})}),ke="ScrollAreaThumb",Vt=u.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=Bt(ke,e.__scopeScrollArea);return a.jsx(ve,{present:r||o.hasThumb,children:a.jsx(Xn,{ref:t,...n})})}),Xn=u.forwardRef((e,t)=>{const{__scopeScrollArea:r,style:n,...o}=e,s=K(ke,r),i=Bt(ke,r),{onThumbPositionChange:l}=i,f=U(t,h=>i.onThumbChange(h)),c=u.useRef(void 0),d=ze(()=>{c.current&&(c.current(),c.current=void 0)},100);return u.useEffect(()=>{const h=s.viewport;if(h){const p=()=>{if(d(),!c.current){const g=Un(h,l);c.current=g,l()}};return l(),h.addEventListener("scroll",p),()=>h.removeEventListener("scroll",p)}},[s.viewport,d,l]),a.jsx(q.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:f,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...n},onPointerDownCapture:X(e.onPointerDownCapture,h=>{const g=h.target.getBoundingClientRect(),m=h.clientX-g.left,y=h.clientY-g.top;i.onThumbPointerDown({x:m,y})}),onPointerUp:X(e.onPointerUp,i.onThumbPointerUp)})});Vt.displayName=ke;var at="ScrollAreaCorner",Xt=u.forwardRef((e,t)=>{const r=K(at,e.__scopeScrollArea),n=!!(r.scrollbarX&&r.scrollbarY);return r.type!=="scroll"&&n?a.jsx(Yn,{...e,ref:t}):null});Xt.displayName=at;var Yn=u.forwardRef((e,t)=>{const{__scopeScrollArea:r,...n}=e,o=K(at,r),[s,i]=u.useState(0),[l,f]=u.useState(0),c=!!(s&&l);return we(o.scrollbarX,()=>{var h;const d=((h=o.scrollbarX)==null?void 0:h.offsetHeight)||0;o.onCornerHeightChange(d),f(d)}),we(o.scrollbarY,()=>{var h;const d=((h=o.scrollbarY)==null?void 0:h.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?a.jsx(q.div,{...n,ref:t,style:{width:s,height:l,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function Ie(e){return e?parseInt(e,10):0}function Yt(e,t){const r=e/t;return isNaN(r)?0:r}function $e(e){const t=Yt(e.viewport,e.content),r=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,n=(e.scrollbar.size-r)*t;return Math.max(n,18)}function qn(e,t,r,n="ltr"){const o=$e(r),s=o/2,i=t||s,l=o-i,f=r.scrollbar.paddingStart+i,c=r.scrollbar.size-r.scrollbar.paddingEnd-l,d=r.content-r.viewport,h=n==="ltr"?[0,d]:[d*-1,0];return Ut([f,c],h)(e)}function qt(e,t,r="ltr"){const n=$e(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,l=s-n,f=r==="ltr"?[0,i]:[i*-1,0],c=$n(e,f);return Ut([0,i],[0,l])(c)}function Ut(e,t){return r=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const n=(t[1]-t[0])/(e[1]-e[0]);return t[0]+n*(r-e[0])}}function Jt(e,t){return e>0&&e<t}var Un=(e,t=()=>{})=>{let r={left:e.scrollLeft,top:e.scrollTop},n=0;return function o(){const s={left:e.scrollLeft,top:e.scrollTop},i=r.left!==s.left,l=r.top!==s.top;(i||l)&&t(),r=s,n=window.requestAnimationFrame(o)}(),()=>window.cancelAnimationFrame(n)};function ze(e,t){const r=Q(e),n=u.useRef(0);return u.useEffect(()=>()=>window.clearTimeout(n.current),[]),u.useCallback(()=>{window.clearTimeout(n.current),n.current=window.setTimeout(r,t)},[r,t])}function we(e,t){const r=Q(t);fe(()=>{let n=0;if(e){const o=new ResizeObserver(()=>{cancelAnimationFrame(n),n=window.requestAnimationFrame(r)});return o.observe(e),()=>{window.cancelAnimationFrame(n),o.unobserve(e)}}},[e,r])}var Gt=zt,Jn=Ft,Gn=Xt;const lt=u.forwardRef(({className:e,children:t,...r},n)=>a.jsxs(Gt,{ref:n,className:Y("relative overflow-hidden",e),...r,children:[a.jsx(Jn,{className:"h-full w-full rounded-[inherit]",children:t}),a.jsx(Kt,{}),a.jsx(Gn,{})]}));lt.displayName=Gt.displayName;const Kt=u.forwardRef(({className:e,orientation:t="vertical",...r},n)=>a.jsx(st,{ref:n,orientation:t,className:Y("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),...r,children:a.jsx(Vt,{className:"relative flex-1 rounded-full bg-border"})}));Kt.displayName=st.displayName;function be({className:e="",showCreateButton:t=!0,onThreadSelect:r}){const{currentThreadId:n,threads:o,loadingThreads:s,selectThread:i,createThread:l,deleteThread:f,updateThreadTitle:c}=pe();console.log("ThreadManager rendered, deleteThread available:",typeof f);const[d,h]=L.useState(null),[p,g]=L.useState(""),m=async v=>{await i(v),r==null||r(v)},y=async()=>{const v=await l();await m(v)},C=async(v,b)=>{console.log("handleDeleteThread called with threadId:",b),v.stopPropagation();const _=confirm("Are you sure you want to delete this thread?");if(console.log("User confirmed deletion:",_),_){console.log("Calling deleteThread from ChatProvider...");try{await f(b),console.log("deleteThread completed successfully")}catch(N){console.error("Error in handleDeleteThread:",N)}}},S=(v,b)=>{v.stopPropagation(),h(b.id),g(b.title||`Thread ${b.id.slice(0,8)}`)},E=async v=>{await c(v,p),h(null)},A=()=>{h(null),g("")};return s?a.jsx("div",{className:`p-4 ${e}`,children:a.jsx("div",{className:"animate-pulse space-y-2",children:[...Array(3)].map((v,b)=>a.jsx("div",{className:"h-10 bg-gray-200 rounded"},b))})}):a.jsxs("div",{className:`p-4 ${e}`,children:[t&&a.jsxs(B,{onClick:y,className:"w-full mb-4 flex items-center gap-2",variant:"outline",children:[a.jsx(F.Plus,{size:16}),"New Thread"]}),a.jsx(lt,{className:"h-[calc(100vh-12rem)]",children:a.jsxs("div",{className:"space-y-2 pr-4",children:[o.map(v=>a.jsx("div",{className:`
|
|
6
|
+
`,children:[a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("div",{className:"font-medium text-sm",children:S()}),e.role==="tool"&&a.jsxs(B,{variant:"ghost",size:"sm",onClick:()=>f(!l),className:"h-6 px-2 text-xs",children:[l?a.jsx(F.ChevronDown,{size:12}):a.jsx(F.ChevronRight,{size:12}),l?"Hide":"Show"," Content"]})]}),n&&t&&a.jsxs(B,{variant:"ghost",size:"sm",onClick:g,className:"h-6 px-2 text-xs",children:[a.jsx(F.RotateCcw,{size:12,className:"mr-1"}),"Regenerate"]})]}),o&&s&&s.length>1&&e.role==="ai"&&a.jsxs("div",{className:"flex items-center gap-2 mb-3 p-2 bg-white/50 rounded border text-xs",children:[a.jsx(F.GitBranch,{size:12,className:"text-gray-500"}),a.jsx("span",{className:"text-gray-600",children:"Branch:"}),a.jsxs("div",{className:"flex items-center gap-1",children:[a.jsx(B,{variant:"ghost",size:"sm",onClick:()=>{const v=s.findIndex(_=>_.is_current),b=v>0?v-1:s.length-1;i==null||i(s[b].branch_id)},className:"h-5 w-5 p-0",title:"Previous branch",children:a.jsx(F.ChevronLeft,{size:10})}),a.jsxs("span",{className:"mx-2 font-mono text-xs",children:[s.findIndex(v=>v.is_current)+1," / ",s.length]}),a.jsx(B,{variant:"ghost",size:"sm",onClick:()=>{const v=s.findIndex(_=>_.is_current),b=v<s.length-1?v+1:0;i==null||i(s[b].branch_id)},className:"h-5 w-5 p-0",title:"Next branch",children:a.jsx(F.ChevronRight,{size:10})})]}),s.map((v,b)=>a.jsx(B,{variant:v.is_current?"default":"ghost",size:"sm",onClick:()=>i==null?void 0:i(v.branch_id),className:"h-5 px-2 text-xs",title:`Switch to branch ${b+1}: ${v.preview}`,children:b+1},v.branch_id))]}),(e.role!=="tool"||l)&&a.jsx("div",{className:`${e.role==="tool"?"font-mono text-sm":""}`,children:e.role==="ai"&&e.isMarkdown?a.jsx("div",{className:"whitespace-pre-wrap",dangerouslySetInnerHTML:{__html:E()}}):a.jsx("div",{className:"whitespace-pre-wrap",children:E()})}),e.timestamp&&a.jsx("div",{className:"text-xs opacity-70 mt-2",children:new Date(e.timestamp).toLocaleTimeString()})]})]})}function me({className:e="",placeholder:t="Type your message...",autoFocus:r=!0,showBranches:n=!0,maxHeight:o="600px",enableInputFieldEditing:s=!1}){const{currentThreadId:i,messages:l,isLoading:f,isLoadingHistory:c,error:d,availableBranches:h,currentBranch:p,sendMessage:g,stop:m,switchBranch:y,regenerateFromMessage:C,editMessage:S,clearError:E}=pe(),[A,v]=L.useState(""),[b,_]=L.useState(null),[N,I]=L.useState(null),$=L.useRef(null),z=L.useRef(null);L.useEffect(()=>{var T;(T=$.current)==null||T.scrollIntoView({behavior:"smooth"})},[l]),L.useEffect(()=>{r&&z.current&&z.current.focus()},[r,i]);const W=async T=>{if(T.preventDefault(),!(!A.trim()||f||!i))try{const k=Te(A.trim());v(""),I(null),b&&s?(await x(b,k),_(null)):await g(k)}catch(k){I(k instanceof Error?k.message:"Invalid input")}},x=async(T,k)=>{try{const M=l.find(H=>H.id===T);if(!M)return;const j=Te(k);await S(M,j,!0,!0)}catch(M){I(M instanceof Error?M.message:"Invalid edit content")}},w=T=>{T.key==="Enter"&&!T.shiftKey?(T.preventDefault(),W(T)):T.key==="Escape"&&b&&(_(null),v(""),I(null))},P=async T=>{await C(T)},D=async(T,k,M=!1,j=!1)=>{j?(_(T.id),v(k),setTimeout(()=>{var H;return(H=z.current)==null?void 0:H.focus()},0)):await S(T,k,M)};return i?a.jsxs("div",{className:`flex flex-col h-full ${e}`,children:[N&&a.jsx("div",{className:"bg-red-50 border-l-4 border-red-400 p-4 mb-4",children:a.jsxs("div",{className:"flex justify-between items-center",children:[a.jsx("div",{className:"text-red-700 text-sm",children:N}),a.jsx(B,{variant:"ghost",size:"sm",onClick:()=>I(null),className:"text-red-600 hover:text-red-700",children:"×"})]})}),d&&a.jsx("div",{className:"bg-red-50 border-l-4 border-red-400 p-4 mb-4",children:a.jsxs("div",{className:"flex justify-between items-center",children:[a.jsx("div",{className:"text-red-700 text-sm",children:d}),a.jsx(B,{variant:"ghost",size:"sm",onClick:E,className:"text-red-600 hover:text-red-700",children:"×"})]})}),b&&s&&a.jsx("div",{className:"bg-blue-50 border-l-4 border-blue-400 p-4 mb-4",children:a.jsxs("div",{className:"flex justify-between items-center",children:[a.jsxs("div",{className:"text-blue-700 text-sm flex items-center",children:[a.jsx(F.Edit3,{size:16,className:"mr-2"}),"Editing message - modify your text below and press Enter to create a new branch"]}),a.jsx(B,{variant:"ghost",size:"sm",onClick:()=>{_(null),v(""),I(null)},className:"text-blue-600 hover:text-blue-700",children:a.jsx(F.X,{size:16})})]})}),n&&h.length>1&&a.jsxs("div",{className:"border-b p-3 bg-gray-50",children:[a.jsx("div",{className:"text-sm font-medium mb-2",children:"Branches:"}),a.jsx("div",{className:"flex gap-2 flex-wrap",children:h.map(T=>a.jsxs(B,{size:"sm",variant:p===T.branch_id?"default":"outline",onClick:()=>y(T.branch_id),className:"text-xs",children:[T.preview,a.jsxs("span",{className:"ml-1 text-gray-500",children:["(",T.message_count,")"]})]},T.branch_id))})]}),a.jsxs("div",{className:"flex-1 overflow-y-auto p-4",style:{maxHeight:o},children:[c?a.jsxs("div",{className:"flex items-center justify-center py-8",children:[a.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"}),a.jsx("span",{className:"ml-2 text-gray-600",children:"Loading conversation..."})]}):l.length===0?a.jsxs("div",{className:"text-center text-gray-500 py-8",children:[a.jsx("div",{className:"text-lg font-medium mb-2",children:"Start a conversation"}),a.jsx("div",{className:"text-sm",children:"Type a message below to begin"})]}):a.jsx("div",{className:"space-y-4",children:l.map((T,k)=>{const M=h?h.filter(H=>H.from_message_index===k):[],j=M.length>1;return M.find(H=>H.branch_id===p),a.jsxs("div",{children:[j&&n&&a.jsxs("div",{className:"flex items-center gap-2 mb-2 p-2 bg-gray-50 rounded border text-xs",children:[a.jsx("span",{className:"text-gray-600",children:"Message versions:"}),a.jsx("div",{className:"flex items-center gap-1",children:M.map((H,V)=>a.jsx(B,{variant:p===H.branch_id?"default":"outline",size:"sm",onClick:()=>y(H.branch_id),className:"h-6 px-2 text-xs",title:`Version ${V+1}: ${H.preview}`,children:V+1},H.branch_id))}),a.jsxs("span",{className:"text-gray-500 ml-2",children:["(",M.findIndex(H=>H.branch_id===p)+1," of ",M.length,")"]})]}),a.jsx(rt,{message:T,onRegenerate:P,onEditMessage:D,showRegenerate:T.role==="ai"||T.role==="human",showBranches:!1,branches:M,onSwitchBranch:y})]},T.id||k)})}),a.jsx("div",{ref:$})]}),a.jsx("div",{className:"border-t p-4 bg-white",children:a.jsxs("form",{onSubmit:W,className:"flex gap-3",children:[a.jsx("div",{className:"flex-1",children:a.jsx(De,{ref:z,value:A,onChange:T=>{v(T.target.value),I(null)},onKeyDown:w,placeholder:b?"Edit your message and press Enter to create a new branch...":t,className:`resize-none min-h-[44px] max-h-32 ${b?"border-blue-400 bg-blue-50":""} ${N?"border-red-400":""}`,disabled:f,maxLength:et})}),a.jsx("div",{className:"flex flex-col gap-2",children:f?a.jsx(B,{type:"button",onClick:m,size:"icon",variant:"outline",className:"shrink-0",children:a.jsx(F.Square,{size:16})}):a.jsx(B,{type:"submit",disabled:!A.trim()||!i,size:"icon",className:`shrink-0 ${b?"bg-blue-600 hover:bg-blue-700":""}`,title:b?"Send edited message and create branch":"Send message",children:b?a.jsx(F.Check,{size:16}):a.jsx(F.Send,{size:16})})})]})})]}):a.jsx("div",{className:`flex items-center justify-center h-full ${e}`,children:a.jsxs("div",{className:"text-center text-gray-500",children:[a.jsx("div",{className:"text-lg font-medium mb-2",children:"No thread selected"}),a.jsx("div",{className:"text-sm",children:"Select a thread or create a new one to start chatting"})]})})}var Pn=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],q=Pn.reduce((e,t)=>{const r=Re.createSlot(`Primitive.${t}`),n=u.forwardRef((o,s)=>{const{asChild:i,...l}=o,f=i?r:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),a.jsx(f,{...l,ref:s})});return n.displayName=`Primitive.${t}`,{...e,[t]:n}},{});function An(e,t){e&&Ot.flushSync(()=>e.dispatchEvent(t))}function It(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function On(...e){return t=>{let r=!1;const n=e.map(o=>{const s=It(o,t);return!r&&typeof s=="function"&&(r=!0),s});if(r)return()=>{for(let o=0;o<n.length;o++){const s=n[o];typeof s=="function"?s():It(e[o],null)}}}}function U(...e){return u.useCallback(On(...e),e)}var fe=globalThis!=null&&globalThis.document?u.useLayoutEffect:()=>{};function Ln(e,t){return u.useReducer((r,n)=>t[r][n]??r,e)}var ve=e=>{const{present:t,children:r}=e,n=_n(t),o=typeof r=="function"?r({present:n.isPresent}):u.Children.only(r),s=U(n.ref,Dn(o));return typeof r=="function"||n.isPresent?u.cloneElement(o,{ref:s}):null};ve.displayName="Presence";function _n(e){const[t,r]=u.useState(),n=u.useRef(null),o=u.useRef(e),s=u.useRef("none"),i=e?"mounted":"unmounted",[l,f]=Ln(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return u.useEffect(()=>{const c=Me(n.current);s.current=l==="mounted"?c:"none"},[l]),fe(()=>{const c=n.current,d=o.current;if(d!==e){const p=s.current,g=Me(c);e?f("MOUNT"):g==="none"||(c==null?void 0:c.display)==="none"?f("UNMOUNT"):f(d&&p!==g?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,f]),fe(()=>{if(t){let c;const d=t.ownerDocument.defaultView??window,h=g=>{const y=Me(n.current).includes(g.animationName);if(g.target===t&&y&&(f("ANIMATION_END"),!o.current)){const C=t.style.animationFillMode;t.style.animationFillMode="forwards",c=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=C)})}},p=g=>{g.target===t&&(s.current=Me(n.current))};return t.addEventListener("animationstart",p),t.addEventListener("animationcancel",h),t.addEventListener("animationend",h),()=>{d.clearTimeout(c),t.removeEventListener("animationstart",p),t.removeEventListener("animationcancel",h),t.removeEventListener("animationend",h)}}else f("ANIMATION_END")},[t,f]),{isPresent:["mounted","unmountSuspended"].includes(l),ref:u.useCallback(c=>{n.current=c?getComputedStyle(c):null,r(c)},[])}}function Me(e){return(e==null?void 0:e.animationName)||"none"}function Dn(e){var n,o;let t=(n=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:n.get,r=t&&"isReactWarning"in t&&t.isReactWarning;return r?e.ref:(t=(o=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:o.get,r=t&&"isReactWarning"in t&&t.isReactWarning,r?e.props.ref:e.props.ref||e.ref)}function nt(e,t=[]){let r=[];function n(s,i){const l=u.createContext(i),f=r.length;r=[...r,i];const c=h=>{var S;const{scope:p,children:g,...m}=h,y=((S=p==null?void 0:p[e])==null?void 0:S[f])||l,C=u.useMemo(()=>m,Object.values(m));return a.jsx(y.Provider,{value:C,children:g})};c.displayName=s+"Provider";function d(h,p){var y;const g=((y=p==null?void 0:p[e])==null?void 0:y[f])||l,m=u.useContext(g);if(m)return m;if(i!==void 0)return i;throw new Error(`\`${h}\` must be used within \`${s}\``)}return[c,d]}const o=()=>{const s=r.map(i=>u.createContext(i));return function(l){const f=(l==null?void 0:l[e])||s;return u.useMemo(()=>({[`__scope${e}`]:{...l,[e]:f}}),[l,f])}};return o.scopeName=e,[n,Mn(o,...t)]}function Mn(...e){const t=e[0];if(e.length===1)return t;const r=()=>{const n=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=n.reduce((l,{useScope:f,scopeName:c})=>{const h=f(s)[`__scope${c}`];return{...l,...h}},{});return u.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return r.scopeName=t.scopeName,r}function Q(e){const t=u.useRef(e);return u.useEffect(()=>{t.current=e}),u.useMemo(()=>(...r)=>{var n;return(n=t.current)==null?void 0:n.call(t,...r)},[])}var kn=u.createContext(void 0);function In(e){const t=u.useContext(kn);return e||t||"ltr"}function $n(e,[t,r]){return Math.min(r,Math.max(t,e))}function X(e,t,{checkForDefaultPrevented:r=!0}={}){return function(o){if(e==null||e(o),r===!1||!o.defaultPrevented)return t==null?void 0:t(o)}}function zn(e,t){return u.useReducer((r,n)=>t[r][n]??r,e)}var ot="ScrollArea",[$t,Ai]=nt(ot),[Hn,K]=$t(ot),zt=u.forwardRef((e,t)=>{const{__scopeScrollArea:r,type:n="hover",dir:o,scrollHideDelay:s=600,...i}=e,[l,f]=u.useState(null),[c,d]=u.useState(null),[h,p]=u.useState(null),[g,m]=u.useState(null),[y,C]=u.useState(null),[S,E]=u.useState(0),[A,v]=u.useState(0),[b,_]=u.useState(!1),[N,I]=u.useState(!1),$=U(t,W=>f(W)),z=In(o);return a.jsx(Hn,{scope:r,type:n,dir:z,scrollHideDelay:s,scrollArea:l,viewport:c,onViewportChange:d,content:h,onContentChange:p,scrollbarX:g,onScrollbarXChange:m,scrollbarXEnabled:b,onScrollbarXEnabledChange:_,scrollbarY:y,onScrollbarYChange:C,scrollbarYEnabled:N,onScrollbarYEnabledChange:I,onCornerWidthChange:E,onCornerHeightChange:v,children:a.jsx(q.div,{dir:z,...i,ref:$,style:{position:"relative","--radix-scroll-area-corner-width":S+"px","--radix-scroll-area-corner-height":A+"px",...e.style}})})});zt.displayName=ot;var Ht="ScrollAreaViewport",Ft=u.forwardRef((e,t)=>{const{__scopeScrollArea:r,children:n,nonce:o,...s}=e,i=K(Ht,r),l=u.useRef(null),f=U(t,l,i.onViewportChange);return a.jsxs(a.Fragment,{children:[a.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}),a.jsx(q.div,{"data-radix-scroll-area-viewport":"",...s,ref:f,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:a.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:n})})]})});Ft.displayName=Ht;var te="ScrollAreaScrollbar",st=u.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=K(te,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,l=e.orientation==="horizontal";return u.useEffect(()=>(l?s(!0):i(!0),()=>{l?s(!1):i(!1)}),[l,s,i]),o.type==="hover"?a.jsx(Fn,{...n,ref:t,forceMount:r}):o.type==="scroll"?a.jsx(Wn,{...n,ref:t,forceMount:r}):o.type==="auto"?a.jsx(Wt,{...n,ref:t,forceMount:r}):o.type==="always"?a.jsx(it,{...n,ref:t}):null});st.displayName=te;var Fn=u.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=K(te,e.__scopeScrollArea),[s,i]=u.useState(!1);return u.useEffect(()=>{const l=o.scrollArea;let f=0;if(l){const c=()=>{window.clearTimeout(f),i(!0)},d=()=>{f=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return l.addEventListener("pointerenter",c),l.addEventListener("pointerleave",d),()=>{window.clearTimeout(f),l.removeEventListener("pointerenter",c),l.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),a.jsx(ve,{present:r||s,children:a.jsx(Wt,{"data-state":s?"visible":"hidden",...n,ref:t})})}),Wn=u.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=K(te,e.__scopeScrollArea),s=e.orientation==="horizontal",i=ze(()=>f("SCROLL_END"),100),[l,f]=zn("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 u.useEffect(()=>{if(l==="idle"){const c=window.setTimeout(()=>f("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[l,o.scrollHideDelay,f]),u.useEffect(()=>{const c=o.viewport,d=s?"scrollLeft":"scrollTop";if(c){let h=c[d];const p=()=>{const g=c[d];h!==g&&(f("SCROLL"),i()),h=g};return c.addEventListener("scroll",p),()=>c.removeEventListener("scroll",p)}},[o.viewport,s,f,i]),a.jsx(ve,{present:r||l!=="hidden",children:a.jsx(it,{"data-state":l==="hidden"?"hidden":"visible",...n,ref:t,onPointerEnter:X(e.onPointerEnter,()=>f("POINTER_ENTER")),onPointerLeave:X(e.onPointerLeave,()=>f("POINTER_LEAVE"))})})}),Wt=u.forwardRef((e,t)=>{const r=K(te,e.__scopeScrollArea),{forceMount:n,...o}=e,[s,i]=u.useState(!1),l=e.orientation==="horizontal",f=ze(()=>{if(r.viewport){const c=r.viewport.offsetWidth<r.viewport.scrollWidth,d=r.viewport.offsetHeight<r.viewport.scrollHeight;i(l?c:d)}},10);return we(r.viewport,f),we(r.content,f),a.jsx(ve,{present:n||s,children:a.jsx(it,{"data-state":s?"visible":"hidden",...o,ref:t})})}),it=u.forwardRef((e,t)=>{const{orientation:r="vertical",...n}=e,o=K(te,e.__scopeScrollArea),s=u.useRef(null),i=u.useRef(0),[l,f]=u.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=Yt(l.viewport,l.content),d={...n,sizes:l,onSizesChange:f,hasThumb:c>0&&c<1,onThumbChange:p=>s.current=p,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:p=>i.current=p};function h(p,g){return qn(p,i.current,l,g)}return r==="horizontal"?a.jsx(Bn,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollLeft,g=qt(p,l,o.dir);s.current.style.transform=`translate3d(${g}px, 0, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollLeft=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollLeft=h(p,o.dir))}}):r==="vertical"?a.jsx(jn,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const p=o.viewport.scrollTop,g=qt(p,l);s.current.style.transform=`translate3d(0, ${g}px, 0)`}},onWheelScroll:p=>{o.viewport&&(o.viewport.scrollTop=p)},onDragScroll:p=>{o.viewport&&(o.viewport.scrollTop=h(p))}}):null}),Bn=u.forwardRef((e,t)=>{const{sizes:r,onSizesChange:n,...o}=e,s=K(te,e.__scopeScrollArea),[i,l]=u.useState(),f=u.useRef(null),c=U(t,f,s.onScrollbarXChange);return u.useEffect(()=>{f.current&&l(getComputedStyle(f.current))},[f]),a.jsx(jt,{"data-orientation":"horizontal",...o,ref:c,sizes:r,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":$e(r)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,h)=>{if(s.viewport){const p=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(p),Jt(p,h)&&d.preventDefault()}},onResize:()=>{f.current&&s.viewport&&i&&n({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:f.current.clientWidth,paddingStart:Ie(i.paddingLeft),paddingEnd:Ie(i.paddingRight)}})}})}),jn=u.forwardRef((e,t)=>{const{sizes:r,onSizesChange:n,...o}=e,s=K(te,e.__scopeScrollArea),[i,l]=u.useState(),f=u.useRef(null),c=U(t,f,s.onScrollbarYChange);return u.useEffect(()=>{f.current&&l(getComputedStyle(f.current))},[f]),a.jsx(jt,{"data-orientation":"vertical",...o,ref:c,sizes:r,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":$e(r)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,h)=>{if(s.viewport){const p=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(p),Jt(p,h)&&d.preventDefault()}},onResize:()=>{f.current&&s.viewport&&i&&n({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:f.current.clientHeight,paddingStart:Ie(i.paddingTop),paddingEnd:Ie(i.paddingBottom)}})}})}),[Vn,Bt]=$t(te),jt=u.forwardRef((e,t)=>{const{__scopeScrollArea:r,sizes:n,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:l,onThumbPositionChange:f,onDragScroll:c,onWheelScroll:d,onResize:h,...p}=e,g=K(te,r),[m,y]=u.useState(null),C=U(t,$=>y($)),S=u.useRef(null),E=u.useRef(""),A=g.viewport,v=n.content-n.viewport,b=Q(d),_=Q(f),N=ze(h,10);function I($){if(S.current){const z=$.clientX-S.current.left,W=$.clientY-S.current.top;c({x:z,y:W})}}return u.useEffect(()=>{const $=z=>{const W=z.target;(m==null?void 0:m.contains(W))&&b(z,v)};return document.addEventListener("wheel",$,{passive:!1}),()=>document.removeEventListener("wheel",$,{passive:!1})},[A,m,v,b]),u.useEffect(_,[n,_]),we(m,N),we(g.content,N),a.jsx(Vn,{scope:r,scrollbar:m,hasThumb:o,onThumbChange:Q(s),onThumbPointerUp:Q(i),onThumbPositionChange:_,onThumbPointerDown:Q(l),children:a.jsx(q.div,{...p,ref:C,style:{position:"absolute",...p.style},onPointerDown:X(e.onPointerDown,$=>{$.button===0&&($.target.setPointerCapture($.pointerId),S.current=m.getBoundingClientRect(),E.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",g.viewport&&(g.viewport.style.scrollBehavior="auto"),I($))}),onPointerMove:X(e.onPointerMove,I),onPointerUp:X(e.onPointerUp,$=>{const z=$.target;z.hasPointerCapture($.pointerId)&&z.releasePointerCapture($.pointerId),document.body.style.webkitUserSelect=E.current,g.viewport&&(g.viewport.style.scrollBehavior=""),S.current=null})})})}),ke="ScrollAreaThumb",Vt=u.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=Bt(ke,e.__scopeScrollArea);return a.jsx(ve,{present:r||o.hasThumb,children:a.jsx(Xn,{ref:t,...n})})}),Xn=u.forwardRef((e,t)=>{const{__scopeScrollArea:r,style:n,...o}=e,s=K(ke,r),i=Bt(ke,r),{onThumbPositionChange:l}=i,f=U(t,h=>i.onThumbChange(h)),c=u.useRef(void 0),d=ze(()=>{c.current&&(c.current(),c.current=void 0)},100);return u.useEffect(()=>{const h=s.viewport;if(h){const p=()=>{if(d(),!c.current){const g=Un(h,l);c.current=g,l()}};return l(),h.addEventListener("scroll",p),()=>h.removeEventListener("scroll",p)}},[s.viewport,d,l]),a.jsx(q.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:f,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...n},onPointerDownCapture:X(e.onPointerDownCapture,h=>{const g=h.target.getBoundingClientRect(),m=h.clientX-g.left,y=h.clientY-g.top;i.onThumbPointerDown({x:m,y})}),onPointerUp:X(e.onPointerUp,i.onThumbPointerUp)})});Vt.displayName=ke;var at="ScrollAreaCorner",Xt=u.forwardRef((e,t)=>{const r=K(at,e.__scopeScrollArea),n=!!(r.scrollbarX&&r.scrollbarY);return r.type!=="scroll"&&n?a.jsx(Yn,{...e,ref:t}):null});Xt.displayName=at;var Yn=u.forwardRef((e,t)=>{const{__scopeScrollArea:r,...n}=e,o=K(at,r),[s,i]=u.useState(0),[l,f]=u.useState(0),c=!!(s&&l);return we(o.scrollbarX,()=>{var h;const d=((h=o.scrollbarX)==null?void 0:h.offsetHeight)||0;o.onCornerHeightChange(d),f(d)}),we(o.scrollbarY,()=>{var h;const d=((h=o.scrollbarY)==null?void 0:h.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),c?a.jsx(q.div,{...n,ref:t,style:{width:s,height:l,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function Ie(e){return e?parseInt(e,10):0}function Yt(e,t){const r=e/t;return isNaN(r)?0:r}function $e(e){const t=Yt(e.viewport,e.content),r=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,n=(e.scrollbar.size-r)*t;return Math.max(n,18)}function qn(e,t,r,n="ltr"){const o=$e(r),s=o/2,i=t||s,l=o-i,f=r.scrollbar.paddingStart+i,c=r.scrollbar.size-r.scrollbar.paddingEnd-l,d=r.content-r.viewport,h=n==="ltr"?[0,d]:[d*-1,0];return Ut([f,c],h)(e)}function qt(e,t,r="ltr"){const n=$e(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,l=s-n,f=r==="ltr"?[0,i]:[i*-1,0],c=$n(e,f);return Ut([0,i],[0,l])(c)}function Ut(e,t){return r=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const n=(t[1]-t[0])/(e[1]-e[0]);return t[0]+n*(r-e[0])}}function Jt(e,t){return e>0&&e<t}var Un=(e,t=()=>{})=>{let r={left:e.scrollLeft,top:e.scrollTop},n=0;return function o(){const s={left:e.scrollLeft,top:e.scrollTop},i=r.left!==s.left,l=r.top!==s.top;(i||l)&&t(),r=s,n=window.requestAnimationFrame(o)}(),()=>window.cancelAnimationFrame(n)};function ze(e,t){const r=Q(e),n=u.useRef(0);return u.useEffect(()=>()=>window.clearTimeout(n.current),[]),u.useCallback(()=>{window.clearTimeout(n.current),n.current=window.setTimeout(r,t)},[r,t])}function we(e,t){const r=Q(t);fe(()=>{let n=0;if(e){const o=new ResizeObserver(()=>{cancelAnimationFrame(n),n=window.requestAnimationFrame(r)});return o.observe(e),()=>{window.cancelAnimationFrame(n),o.unobserve(e)}}},[e,r])}var Gt=zt,Jn=Ft,Gn=Xt;const lt=u.forwardRef(({className:e,children:t,...r},n)=>a.jsxs(Gt,{ref:n,className:Y("relative overflow-hidden",e),...r,children:[a.jsx(Jn,{className:"h-full w-full rounded-[inherit]",children:t}),a.jsx(Kt,{}),a.jsx(Gn,{})]}));lt.displayName=Gt.displayName;const Kt=u.forwardRef(({className:e,orientation:t="vertical",...r},n)=>a.jsx(st,{ref:n,orientation:t,className:Y("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),...r,children:a.jsx(Vt,{className:"relative flex-1 rounded-full bg-border"})}));Kt.displayName=st.displayName;function be({className:e="",showCreateButton:t=!0,onThreadSelect:r}){const{currentThreadId:n,threads:o,loadingThreads:s,selectThread:i,createThread:l,deleteThread:f,updateThreadTitle:c}=pe();console.log("ThreadManager rendered, deleteThread available:",typeof f);const[d,h]=L.useState(null),[p,g]=L.useState(""),m=async v=>{await i(v),r==null||r(v)},y=async()=>{const v=await l();await m(v)},C=async(v,b)=>{console.log("handleDeleteThread called with threadId:",b),v.stopPropagation();const _=confirm("Are you sure you want to delete this thread?");if(console.log("User confirmed deletion:",_),_){console.log("Calling deleteThread from ChatProvider...");try{await f(b),console.log("deleteThread completed successfully")}catch(N){console.error("Error in handleDeleteThread:",N)}}},S=(v,b)=>{v.stopPropagation(),h(b.id),g(b.title||`Thread ${b.id.slice(0,8)}`)},E=async v=>{await c(v,p),h(null)},A=()=>{h(null),g("")};return s?a.jsx("div",{className:`p-4 ${e}`,children:a.jsx("div",{className:"animate-pulse space-y-2",children:[...Array(3)].map((v,b)=>a.jsx("div",{className:"h-10 bg-gray-200 rounded"},b))})}):a.jsxs("div",{className:`p-4 ${e}`,children:[t&&a.jsxs(B,{onClick:y,className:"w-full mb-4 flex items-center gap-2",variant:"outline",children:[a.jsx(F.Plus,{size:16}),"New Thread"]}),a.jsx(lt,{className:"h-[calc(100vh-12rem)]",children:a.jsxs("div",{className:"space-y-2 pr-4",children:[o.map(v=>a.jsx("div",{className:`
|
|
7
7
|
group p-3 rounded-lg cursor-pointer transition-colors
|
|
8
8
|
${n===v.id?"bg-blue-100 border-blue-300 border":"bg-gray-50 hover:bg-gray-100 border border-transparent"}
|
|
9
9
|
`,onClick:()=>m(v.id),children:a.jsx("div",{className:"flex items-center justify-between",children:d===v.id?a.jsxs("div",{className:"flex-1 flex gap-2",children:[a.jsx("input",{value:p,onChange:b=>g(b.target.value),onKeyDown:b=>{b.key==="Enter"&&E(v.id),b.key==="Escape"&&A()},className:"flex-1 px-2 py-1 text-sm border rounded",autoFocus:!0}),a.jsx(B,{size:"sm",onClick:b=>{b.stopPropagation(),E(v.id)},children:"Save"})]}):a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsx("div",{className:"font-medium text-sm truncate",children:v.title||`Thread ${v.id.slice(0,8)}`}),a.jsx("div",{className:"text-xs text-gray-500",children:new Date(v.updated_at).toLocaleDateString()})]}),a.jsxs("div",{className:"flex gap-1 opacity-100 transition-opacity",children:[a.jsx(B,{size:"sm",variant:"ghost",onClick:b=>S(b,v),className:"p-1 h-auto",children:a.jsx(F.Edit3,{size:12})}),a.jsx(B,{size:"sm",variant:"ghost",onClick:b=>{console.log("Delete button clicked!"),C(b,v.id)},className:"p-1 h-auto text-red-600 hover:text-red-700",style:{backgroundColor:"rgba(255, 0, 0, 0.1)"},children:a.jsx(F.Trash2,{size:12})})]})]})})},v.id)),o.length===0&&a.jsx("div",{className:"text-center text-gray-500 py-8",children:"No threads yet. Create your first thread to get started!"})]})})]})}function Zt({apiBaseUrl:e,enableUrlSync:t=!0,layout:r="sidebar",className:n=""}){return a.jsx(_e,{apiBaseUrl:e,enableUrlSync:t,children:a.jsxs("div",{className:`h-full ${n}`,children:[r==="sidebar"&&a.jsx(Kn,{}),r==="tabs"&&a.jsx(Zn,{}),r==="split"&&a.jsx(Qn,{})]})})}function Kn(){return a.jsxs("div",{className:"flex h-full",children:[a.jsx("div",{className:"w-80 border-r bg-gray-50",children:a.jsx(be,{})}),a.jsx("div",{className:"flex-1",children:a.jsx(me,{})})]})}function Zn(){const[e,t]=L.useState("chat");return a.jsxs("div",{className:"flex flex-col h-full",children:[a.jsx("div",{className:"border-b",children:a.jsxs("div",{className:"flex",children:[a.jsx("button",{onClick:()=>t("chat"),className:`px-4 py-2 font-medium ${e==="chat"?"border-b-2 border-blue-500 text-blue-600":"text-gray-500 hover:text-gray-700"}`,children:"Chat"}),a.jsx("button",{onClick:()=>t("threads"),className:`px-4 py-2 font-medium ${e==="threads"?"border-b-2 border-blue-500 text-blue-600":"text-gray-500 hover:text-gray-700"}`,children:"Threads"})]})}),a.jsxs("div",{className:"flex-1",children:[e==="chat"&&a.jsx(me,{}),e==="threads"&&a.jsx(be,{onThreadSelect:()=>t("chat")})]})]})}function Qn(){return a.jsxs("div",{className:"flex flex-col h-full",children:[a.jsx("div",{className:"h-1/3 border-b",children:a.jsx(be,{})}),a.jsx("div",{className:"flex-1",children:a.jsx(me,{})})]})}function Rn({placeholder:e,showThreadHistory:t=!0}){const[r,n]=L.useState(!1);L.useEffect(()=>{const s=()=>n(i=>!i);return window.addEventListener("toggleChatThreads",s),()=>window.removeEventListener("toggleChatThreads",s)},[]);const o=()=>{n(!1)};return a.jsxs("div",{className:"flex flex-col h-full relative",children:[t&&r&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"fixed inset-0 z-40 bg-black/20",onClick:()=>n(!1)}),a.jsxs("div",{className:"absolute top-0 left-0 right-0 z-50 bg-white rounded-lg shadow-xl border border-gray-200 max-h-72 overflow-hidden",children:[a.jsx("div",{className:"p-3 border-b border-gray-100 bg-gray-50",children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("h4",{className:"font-medium text-sm text-gray-700",children:"Conversation History"}),a.jsx(B,{variant:"ghost",size:"sm",onClick:()=>n(!1),className:"h-6 w-6 p-0 text-gray-400 hover:text-gray-600",children:a.jsx(F.X,{size:12})})]})}),a.jsx("div",{className:"max-h-56 overflow-y-auto",children:a.jsx(be,{className:"p-2",onThreadSelect:o})})]})]}),a.jsx("div",{className:"flex-1 h-full",children:a.jsx(me,{placeholder:e||"Type your message...",className:"h-full flex flex-col"})})]})}const eo={sm:"w-80 h-80",md:"w-96 h-96",lg:"w-[28rem] h-[32rem]"},Qt={"bottom-right":"bottom-6 right-6","bottom-left":"bottom-6 left-6","top-right":"top-6 right-6","top-left":"top-6 left-6"};function to({apiBaseUrl:e="http://localhost:8000/api/chat",title:t="AI Assistant",subtitle:r="How can I help you?",placeholder:n="Type your message...",getAuthHeaders:o,authToken:s,className:i="",position:l="bottom-right",size:f="md",theme:c="light",enableUrlSync:d=!0,defaultOpen:h=!1,showThreadHistory:p=!0,onMessageSent:g,onThreadChanged:m,onToggle:y}){const[C,S]=L.useState(h),[E,A]=L.useState(!1),v=N=>{S(N),y==null||y(N)};L.useEffect(()=>{d&&!C&&new URLSearchParams(window.location.search).get("thread")&&v(!0)},[d,C]),L.useEffect(()=>{if(d){const I=new URLSearchParams(window.location.search).get("thread");I&&m&&m(I)}},[d,m]);const b=c==="dark"?"bg-gray-900 text-white border-gray-700":"bg-white text-gray-900 border-gray-200",_=c==="dark"?"bg-gray-800 text-white":"bg-slate-800 text-white";return C?a.jsx(_e,{apiBaseUrl:e,enableUrlSync:d,getAuthHeaders:o,authToken:s,children:a.jsx("div",{className:`fixed ${Qt[l]} z-50 transition-all duration-300 ${E?"scale-75":"scale-100"}`,children:a.jsxs("div",{className:`${eo[f]} ${b} rounded-xl shadow-2xl border overflow-hidden relative`,children:[a.jsx("div",{className:`${_} p-4 flex-shrink-0`,children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"w-8 h-8 bg-white/10 rounded-full flex items-center justify-center border border-slate-600",children:a.jsx(F.MessageCircle,{size:16,className:"text-white"})}),a.jsxs("div",{children:[a.jsx("h3",{className:"font-semibold text-sm",children:t}),a.jsx("p",{className:"text-xs text-slate-300",children:r})]})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[p&&a.jsx(B,{variant:"ghost",size:"sm",onClick:()=>{const N=new CustomEvent("toggleChatThreads");window.dispatchEvent(N)},className:"text-white hover:bg-white/10 h-8 w-8 p-0",title:"Conversation History",children:a.jsx(F.History,{size:14})}),a.jsx(B,{variant:"ghost",size:"sm",onClick:()=>A(!E),className:"text-white hover:bg-white/10 h-8 w-8 p-0",title:E?"Maximize":"Minimize",children:E?a.jsx(F.Maximize2,{size:14}):a.jsx(F.Minimize2,{size:14})}),a.jsx(B,{variant:"ghost",size:"sm",onClick:()=>v(!1),className:"text-white hover:bg-white/10 h-8 w-8 p-0",title:"Close",children:a.jsx(F.X,{size:14})})]})]})}),!E&&a.jsx("div",{className:"flex-1 h-full overflow-hidden",children:a.jsx(Rn,{placeholder:n,showThreadHistory:p})})]})})}):a.jsxs(B,{onClick:()=>v(!0),size:"lg",className:`fixed ${Qt[l]} h-14 w-14 rounded-full shadow-lg bg-slate-800 hover:bg-slate-700 z-50 transition-all duration-200 ${i}`,children:[a.jsx(F.MessageCircle,{size:24,className:"text-white"}),a.jsx("div",{className:"absolute -top-1 -right-1 w-3 h-3 bg-red-500 rounded-full animate-pulse"})]})}function Rt(){const e=pe();return{...L.useMemo(()=>({all:e.messages,human:e.messages.filter(r=>r.role==="human"),ai:e.messages.filter(r=>r.role==="ai"),tool:e.messages.filter(r=>r.role==="tool"),latest:e.messages[e.messages.length-1],latestHuman:[...e.messages].reverse().find(r=>r.role==="human"),latestAI:[...e.messages].reverse().find(r=>r.role==="ai"),latestTool:[...e.messages].reverse().find(r=>r.role==="tool")}),[e.messages]),isLoading:e.isLoading,error:e.error,refresh:e.refresh}}function ro(){const{tool:e}=Rt(),t=L.useMemo(()=>e.map(i=>{let l="",f=null,c=!1;try{if(typeof i.content=="string"){l=i.content;try{f=JSON.parse(i.content),c=!0}catch{}}else f=i.content,l=JSON.stringify(i.content,null,2),c=!0}catch{l=String(i.content||"")}return{id:i.id||"",name:i.name||"",tool_call_id:i.tool_call_id||"",args:i.args,content:i.content,timestamp:i.timestamp,textContent:l,jsonContent:f,isJson:c}}),[e]),r=L.useMemo(()=>{const i={};return t.forEach(l=>{i[l.name]||(i[l.name]=[]),i[l.name].push(l)}),i},[t]),n=i=>{const l=r[i];return l==null?void 0:l[l.length-1]},o=i=>{var l;return((l=r[i])==null?void 0:l.map(f=>f.jsonContent||f.textContent))||[]},s=()=>t.map(i=>i.jsonContent||i.textContent);return{all:t,raw:e,byToolName:r,toolNames:Object.keys(r),getLatestByTool:n,getContentByTool:o,getAllContent:s,latest:t[t.length-1],count:t.length,hasToolMessages:t.length>0}}function no(){const e=pe();return{currentThread:e.currentThreadId,isLoading:e.isLoading,error:e.error,sendMessage:e.sendMessage,createThread:e.createThread,selectThread:e.selectThread,deleteThread:e.deleteThread,clearError:e.clearError,stop:e.stop,refresh:e.refresh}}function er(){const e=pe(),[t,r]=L.useState({isStreaming:!1,events:[],latestEvent:null,error:null}),n=L.useRef(0),o=L.useRef(0);L.useEffect(()=>{r(c=>({...c,isStreaming:e.isLoading,error:e.error}))},[e.isLoading,e.error]),L.useEffect(()=>{const c=e.messages.length;c>n.current&&(e.messages.slice(n.current).forEach(h=>{const p={type:h.role==="tool"?"tool":"message",data:h,timestamp:Date.now()};r(g=>({...g,events:[...g.events,p],latestEvent:p}))}),n.current=c)},[e.messages]),L.useEffect(()=>{if(!e.isLoading&&t.isStreaming){const c={type:"complete",data:{messageCount:e.messages.length},timestamp:Date.now()};r(d=>({...d,isStreaming:!1,events:[...d.events,c],latestEvent:c}))}},[e.isLoading,t.isStreaming,e.messages.length]),L.useEffect(()=>{r(c=>({...c,events:[],latestEvent:null})),n.current=0,o.current=0},[e.currentThreadId]);const s=c=>t.events.filter(d=>d.type===c),i=c=>{const d=s(c);return d[d.length-1]||null},l=()=>t.events.filter(c=>c.type==="tool").map(c=>({...c,data:c.data}));return{...t,getEventsByType:s,getLatestEventByType:i,getToolEvents:l,clearEvents:()=>{r(c=>({...c,events:[],latestEvent:null}))},messageEvents:s("message"),toolEvents:l(),latestToolEvent:i("tool"),hasNewEvents:t.events.length>0}}function He(e,t){const{toolEvents:r,latestToolEvent:n}=er(),[o,s]=L.useState([]),[i,l]=L.useState(null);L.useEffect(()=>{const d=r.filter(h=>h.data.name===e).map(h=>{const p=h.data.jsonContent||h.data.textContent;return t?t(p):p});s(d),l(d[d.length-1]||null)},[r,e,t]);const f=(n==null?void 0:n.data.name)===e;return{data:o,latest:i,count:o.length,hasData:o.length>0,hasNewData:f}}const oo=(e="search")=>He(e,t=>Array.isArray(t)?t:t!=null&&t.results?t.results:t!=null&&t.data?t.data:t),so=(e="read_file")=>He(e,t=>typeof t=="string"?t:t!=null&&t.content?t.content:t!=null&&t.text?t.text:String(t)),io=(e="execute_code")=>He(e,t=>({output:(t==null?void 0:t.output)||(t==null?void 0:t.stdout)||t,error:(t==null?void 0:t.error)||(t==null?void 0:t.stderr)||null,exitCode:(t==null?void 0:t.exit_code)||(t==null?void 0:t.exitCode)||0})),tr=u.forwardRef(({className:e,...t},r)=>a.jsx("div",{ref:r,className:Y("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));tr.displayName="Card";const rr=u.forwardRef(({className:e,...t},r)=>a.jsx("div",{ref:r,className:Y("flex flex-col space-y-1.5 p-6",e),...t}));rr.displayName="CardHeader";const nr=u.forwardRef(({className:e,...t},r)=>a.jsx("h3",{ref:r,className:Y("text-2xl font-semibold leading-none tracking-tight",e),...t}));nr.displayName="CardTitle";const or=u.forwardRef(({className:e,...t},r)=>a.jsx("p",{ref:r,className:Y("text-sm text-muted-foreground",e),...t}));or.displayName="CardDescription";const sr=u.forwardRef(({className:e,...t},r)=>a.jsx("div",{ref:r,className:Y("p-6 pt-0",e),...t}));sr.displayName="CardContent";const ir=u.forwardRef(({className:e,...t},r)=>a.jsx("div",{ref:r,className:Y("flex items-center p-6 pt-0",e),...t}));ir.displayName="CardFooter";const ar=u.forwardRef(({className:e,type:t,...r},n)=>a.jsx("input",{type:t,className:Y("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:n,...r}));ar.displayName="Input";var ao="Label",lr=u.forwardRef((e,t)=>a.jsx(q.label,{...e,ref:t,onMouseDown:r=>{var o;r.target.closest("button, input, select, textarea")||((o=e.onMouseDown)==null||o.call(e,r),!r.defaultPrevented&&r.detail>1&&r.preventDefault())}}));lr.displayName=ao;var cr=lr;const lo=Pt.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),dr=u.forwardRef(({className:e,...t},r)=>a.jsx(cr,{ref:r,className:Y(lo(),e),...t}));dr.displayName=cr.displayName;var co="Separator",fr="horizontal",fo=["horizontal","vertical"],ur=u.forwardRef((e,t)=>{const{decorative:r,orientation:n=fr,...o}=e,s=uo(n)?n:fr,l=r?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return a.jsx(q.div,{"data-orientation":s,...l,...o,ref:t})});ur.displayName=co;function uo(e){return fo.includes(e)}var hr=ur;const pr=u.forwardRef(({className:e,orientation:t="horizontal",decorative:r=!0,...n},o)=>a.jsx(hr,{ref:o,decorative:r,orientation:t,className:Y("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...n}));pr.displayName=hr.displayName;function ho(e,t=globalThis==null?void 0:globalThis.document){const r=Q(e);u.useEffect(()=>{const n=o=>{o.key==="Escape"&&r(o)};return t.addEventListener("keydown",n,{capture:!0}),()=>t.removeEventListener("keydown",n,{capture:!0})},[r,t])}var po="DismissableLayer",ct="dismissableLayer.update",go="dismissableLayer.pointerDownOutside",mo="dismissableLayer.focusOutside",gr,mr=u.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),vr=u.forwardRef((e,t)=>{const{disableOutsidePointerEvents:r=!1,onEscapeKeyDown:n,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:l,...f}=e,c=u.useContext(mr),[d,h]=u.useState(null),p=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,g]=u.useState({}),m=U(t,N=>h(N)),y=Array.from(c.layers),[C]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),S=y.indexOf(C),E=d?y.indexOf(d):-1,A=c.layersWithOutsidePointerEventsDisabled.size>0,v=E>=S,b=bo(N=>{const I=N.target,$=[...c.branches].some(z=>z.contains(I));!v||$||(o==null||o(N),i==null||i(N),N.defaultPrevented||l==null||l())},p),_=yo(N=>{const I=N.target;[...c.branches].some(z=>z.contains(I))||(s==null||s(N),i==null||i(N),N.defaultPrevented||l==null||l())},p);return ho(N=>{E===c.layers.size-1&&(n==null||n(N),!N.defaultPrevented&&l&&(N.preventDefault(),l()))},p),u.useEffect(()=>{if(d)return r&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(gr=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(d)),c.layers.add(d),wr(),()=>{r&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=gr)}},[d,p,r,c]),u.useEffect(()=>()=>{d&&(c.layers.delete(d),c.layersWithOutsidePointerEventsDisabled.delete(d),wr())},[d,c]),u.useEffect(()=>{const N=()=>g({});return document.addEventListener(ct,N),()=>document.removeEventListener(ct,N)},[]),a.jsx(q.div,{...f,ref:m,style:{pointerEvents:A?v?"auto":"none":void 0,...e.style},onFocusCapture:X(e.onFocusCapture,_.onFocusCapture),onBlurCapture:X(e.onBlurCapture,_.onBlurCapture),onPointerDownCapture:X(e.onPointerDownCapture,b.onPointerDownCapture)})});vr.displayName=po;var vo="DismissableLayerBranch",wo=u.forwardRef((e,t)=>{const r=u.useContext(mr),n=u.useRef(null),o=U(t,n);return u.useEffect(()=>{const s=n.current;if(s)return r.branches.add(s),()=>{r.branches.delete(s)}},[r.branches]),a.jsx(q.div,{...e,ref:o})});wo.displayName=vo;function bo(e,t=globalThis==null?void 0:globalThis.document){const r=Q(e),n=u.useRef(!1),o=u.useRef(()=>{});return u.useEffect(()=>{const s=l=>{if(l.target&&!n.current){let f=function(){br(go,r,c,{discrete:!0})};const c={originalEvent:l};l.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=f,t.addEventListener("click",o.current,{once:!0})):f()}else t.removeEventListener("click",o.current);n.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,r]),{onPointerDownCapture:()=>n.current=!0}}function yo(e,t=globalThis==null?void 0:globalThis.document){const r=Q(e),n=u.useRef(!1);return u.useEffect(()=>{const o=s=>{s.target&&!n.current&&br(mo,r,{originalEvent:s},{discrete:!1})};return t.addEventListener("focusin",o),()=>t.removeEventListener("focusin",o)},[t,r]),{onFocusCapture:()=>n.current=!0,onBlurCapture:()=>n.current=!1}}function wr(){const e=new CustomEvent(ct);document.dispatchEvent(e)}function br(e,t,r,{discrete:n}){const o=r.originalEvent.target,s=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:r});t&&o.addEventListener(e,t,{once:!0}),n?An(o,s):o.dispatchEvent(s)}var xo=u[" useId ".trim().toString()]||(()=>{}),Co=0;function So(e){const[t,r]=u.useState(xo());return fe(()=>{r(n=>n??String(Co++))},[e]),t?`radix-${t}`:""}const Eo=["top","right","bottom","left"],ue=Math.min,J=Math.max,Fe=Math.round,We=Math.floor,re=e=>({x:e,y:e}),To={left:"right",right:"left",bottom:"top",top:"bottom"},No={start:"end",end:"start"};function dt(e,t,r){return J(e,ue(t,r))}function le(e,t){return typeof e=="function"?e(t):e}function ce(e){return e.split("-")[0]}function ye(e){return e.split("-")[1]}function ft(e){return e==="x"?"y":"x"}function ut(e){return e==="y"?"height":"width"}const Po=new Set(["top","bottom"]);function ne(e){return Po.has(ce(e))?"y":"x"}function ht(e){return ft(ne(e))}function Ao(e,t,r){r===void 0&&(r=!1);const n=ye(e),o=ht(e),s=ut(o);let i=o==="x"?n===(r?"end":"start")?"right":"left":n==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Be(i)),[i,Be(i)]}function Oo(e){const t=Be(e);return[pt(e),t,pt(t)]}function pt(e){return e.replace(/start|end/g,t=>No[t])}const yr=["left","right"],xr=["right","left"],Lo=["top","bottom"],_o=["bottom","top"];function Do(e,t,r){switch(e){case"top":case"bottom":return r?t?xr:yr:t?yr:xr;case"left":case"right":return t?Lo:_o;default:return[]}}function Mo(e,t,r,n){const o=ye(e);let s=Do(ce(e),r==="start",n);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(pt)))),s}function Be(e){return e.replace(/left|right|bottom|top/g,t=>To[t])}function ko(e){return{top:0,right:0,bottom:0,left:0,...e}}function Cr(e){return typeof e!="number"?ko(e):{top:e,right:e,bottom:e,left:e}}function je(e){const{x:t,y:r,width:n,height:o}=e;return{width:n,height:o,top:r,left:t,right:t+n,bottom:r+o,x:t,y:r}}function Sr(e,t,r){let{reference:n,floating:o}=e;const s=ne(t),i=ht(t),l=ut(i),f=ce(t),c=s==="y",d=n.x+n.width/2-o.width/2,h=n.y+n.height/2-o.height/2,p=n[l]/2-o[l]/2;let g;switch(f){case"top":g={x:d,y:n.y-o.height};break;case"bottom":g={x:d,y:n.y+n.height};break;case"right":g={x:n.x+n.width,y:h};break;case"left":g={x:n.x-o.width,y:h};break;default:g={x:n.x,y:n.y}}switch(ye(t)){case"start":g[i]-=p*(r&&c?-1:1);break;case"end":g[i]+=p*(r&&c?-1:1);break}return g}const Io=async(e,t,r)=>{const{placement:n="bottom",strategy:o="absolute",middleware:s=[],platform:i}=r,l=s.filter(Boolean),f=await(i.isRTL==null?void 0:i.isRTL(t));let c=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:h}=Sr(c,n,f),p=n,g={},m=0;for(let y=0;y<l.length;y++){const{name:C,fn:S}=l[y],{x:E,y:A,data:v,reset:b}=await S({x:d,y:h,initialPlacement:n,placement:p,strategy:o,middlewareData:g,rects:c,platform:i,elements:{reference:e,floating:t}});d=E??d,h=A??h,g={...g,[C]:{...g[C],...v}},b&&m<=50&&(m++,typeof b=="object"&&(b.placement&&(p=b.placement),b.rects&&(c=b.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):b.rects),{x:d,y:h}=Sr(c,p,f)),y=-1)}return{x:d,y:h,placement:p,strategy:o,middlewareData:g}};async function Ne(e,t){var r;t===void 0&&(t={});const{x:n,y:o,platform:s,rects:i,elements:l,strategy:f}=e,{boundary:c="clippingAncestors",rootBoundary:d="viewport",elementContext:h="floating",altBoundary:p=!1,padding:g=0}=le(t,e),m=Cr(g),C=l[p?h==="floating"?"reference":"floating":h],S=je(await s.getClippingRect({element:(r=await(s.isElement==null?void 0:s.isElement(C)))==null||r?C:C.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(l.floating)),boundary:c,rootBoundary:d,strategy:f})),E=h==="floating"?{x:n,y:o,width:i.floating.width,height:i.floating.height}:i.reference,A=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l.floating)),v=await(s.isElement==null?void 0:s.isElement(A))?await(s.getScale==null?void 0:s.getScale(A))||{x:1,y:1}:{x:1,y:1},b=je(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:E,offsetParent:A,strategy:f}):E);return{top:(S.top-b.top+m.top)/v.y,bottom:(b.bottom-S.bottom+m.bottom)/v.y,left:(S.left-b.left+m.left)/v.x,right:(b.right-S.right+m.right)/v.x}}const $o=e=>({name:"arrow",options:e,async fn(t){const{x:r,y:n,placement:o,rects:s,platform:i,elements:l,middlewareData:f}=t,{element:c,padding:d=0}=le(e,t)||{};if(c==null)return{};const h=Cr(d),p={x:r,y:n},g=ht(o),m=ut(g),y=await i.getDimensions(c),C=g==="y",S=C?"top":"left",E=C?"bottom":"right",A=C?"clientHeight":"clientWidth",v=s.reference[m]+s.reference[g]-p[g]-s.floating[m],b=p[g]-s.reference[g],_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let N=_?_[A]:0;(!N||!await(i.isElement==null?void 0:i.isElement(_)))&&(N=l.floating[A]||s.floating[m]);const I=v/2-b/2,$=N/2-y[m]/2-1,z=ue(h[S],$),W=ue(h[E],$),x=z,w=N-y[m]-W,P=N/2-y[m]/2+I,D=dt(x,P,w),T=!f.arrow&&ye(o)!=null&&P!==D&&s.reference[m]/2-(P<x?z:W)-y[m]/2<0,k=T?P<x?P-x:P-w:0;return{[g]:p[g]+k,data:{[g]:D,centerOffset:P-D-k,...T&&{alignmentOffset:k}},reset:T}}}),zo=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var r,n;const{placement:o,middlewareData:s,rects:i,initialPlacement:l,platform:f,elements:c}=t,{mainAxis:d=!0,crossAxis:h=!0,fallbackPlacements:p,fallbackStrategy:g="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:y=!0,...C}=le(e,t);if((r=s.arrow)!=null&&r.alignmentOffset)return{};const S=ce(o),E=ne(l),A=ce(l)===l,v=await(f.isRTL==null?void 0:f.isRTL(c.floating)),b=p||(A||!y?[Be(l)]:Oo(l)),_=m!=="none";!p&&_&&b.push(...Mo(l,y,m,v));const N=[l,...b],I=await Ne(t,C),$=[];let z=((n=s.flip)==null?void 0:n.overflows)||[];if(d&&$.push(I[S]),h){const P=Ao(o,i,v);$.push(I[P[0]],I[P[1]])}if(z=[...z,{placement:o,overflows:$}],!$.every(P=>P<=0)){var W,x;const P=(((W=s.flip)==null?void 0:W.index)||0)+1,D=N[P];if(D&&(!(h==="alignment"?E!==ne(D):!1)||z.every(M=>M.overflows[0]>0&&ne(M.placement)===E)))return{data:{index:P,overflows:z},reset:{placement:D}};let T=(x=z.filter(k=>k.overflows[0]<=0).sort((k,M)=>k.overflows[1]-M.overflows[1])[0])==null?void 0:x.placement;if(!T)switch(g){case"bestFit":{var w;const k=(w=z.filter(M=>{if(_){const j=ne(M.placement);return j===E||j==="y"}return!0}).map(M=>[M.placement,M.overflows.filter(j=>j>0).reduce((j,H)=>j+H,0)]).sort((M,j)=>M[1]-j[1])[0])==null?void 0:w[0];k&&(T=k);break}case"initialPlacement":T=l;break}if(o!==T)return{reset:{placement:T}}}return{}}}};function Er(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Tr(e){return Eo.some(t=>e[t]>=0)}const Ho=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:r}=t,{strategy:n="referenceHidden",...o}=le(e,t);switch(n){case"referenceHidden":{const s=await Ne(t,{...o,elementContext:"reference"}),i=Er(s,r.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Tr(i)}}}case"escaped":{const s=await Ne(t,{...o,altBoundary:!0}),i=Er(s,r.floating);return{data:{escapedOffsets:i,escaped:Tr(i)}}}default:return{}}}}},Nr=new Set(["left","top"]);async function Fo(e,t){const{placement:r,platform:n,elements:o}=e,s=await(n.isRTL==null?void 0:n.isRTL(o.floating)),i=ce(r),l=ye(r),f=ne(r)==="y",c=Nr.has(i)?-1:1,d=s&&f?-1:1,h=le(t,e);let{mainAxis:p,crossAxis:g,alignmentAxis:m}=typeof h=="number"?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:h.mainAxis||0,crossAxis:h.crossAxis||0,alignmentAxis:h.alignmentAxis};return l&&typeof m=="number"&&(g=l==="end"?m*-1:m),f?{x:g*d,y:p*c}:{x:p*c,y:g*d}}const Wo=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var r,n;const{x:o,y:s,placement:i,middlewareData:l}=t,f=await Fo(t,e);return i===((r=l.offset)==null?void 0:r.placement)&&(n=l.arrow)!=null&&n.alignmentOffset?{}:{x:o+f.x,y:s+f.y,data:{...f,placement:i}}}}},Bo=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:r,y:n,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:l={fn:C=>{let{x:S,y:E}=C;return{x:S,y:E}}},...f}=le(e,t),c={x:r,y:n},d=await Ne(t,f),h=ne(ce(o)),p=ft(h);let g=c[p],m=c[h];if(s){const C=p==="y"?"top":"left",S=p==="y"?"bottom":"right",E=g+d[C],A=g-d[S];g=dt(E,g,A)}if(i){const C=h==="y"?"top":"left",S=h==="y"?"bottom":"right",E=m+d[C],A=m-d[S];m=dt(E,m,A)}const y=l.fn({...t,[p]:g,[h]:m});return{...y,data:{x:y.x-r,y:y.y-n,enabled:{[p]:s,[h]:i}}}}}},jo=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:r,y:n,placement:o,rects:s,middlewareData:i}=t,{offset:l=0,mainAxis:f=!0,crossAxis:c=!0}=le(e,t),d={x:r,y:n},h=ne(o),p=ft(h);let g=d[p],m=d[h];const y=le(l,t),C=typeof y=="number"?{mainAxis:y,crossAxis:0}:{mainAxis:0,crossAxis:0,...y};if(f){const A=p==="y"?"height":"width",v=s.reference[p]-s.floating[A]+C.mainAxis,b=s.reference[p]+s.reference[A]-C.mainAxis;g<v?g=v:g>b&&(g=b)}if(c){var S,E;const A=p==="y"?"width":"height",v=Nr.has(ce(o)),b=s.reference[h]-s.floating[A]+(v&&((S=i.offset)==null?void 0:S[h])||0)+(v?0:C.crossAxis),_=s.reference[h]+s.reference[A]+(v?0:((E=i.offset)==null?void 0:E[h])||0)-(v?C.crossAxis:0);m<b?m=b:m>_&&(m=_)}return{[p]:g,[h]:m}}}},Vo=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var r,n;const{placement:o,rects:s,platform:i,elements:l}=t,{apply:f=()=>{},...c}=le(e,t),d=await Ne(t,c),h=ce(o),p=ye(o),g=ne(o)==="y",{width:m,height:y}=s.floating;let C,S;h==="top"||h==="bottom"?(C=h,S=p===(await(i.isRTL==null?void 0:i.isRTL(l.floating))?"start":"end")?"left":"right"):(S=h,C=p==="end"?"top":"bottom");const E=y-d.top-d.bottom,A=m-d.left-d.right,v=ue(y-d[C],E),b=ue(m-d[S],A),_=!t.middlewareData.shift;let N=v,I=b;if((r=t.middlewareData.shift)!=null&&r.enabled.x&&(I=A),(n=t.middlewareData.shift)!=null&&n.enabled.y&&(N=E),_&&!p){const z=J(d.left,0),W=J(d.right,0),x=J(d.top,0),w=J(d.bottom,0);g?I=m-2*(z!==0||W!==0?z+W:J(d.left,d.right)):N=y-2*(x!==0||w!==0?x+w:J(d.top,d.bottom))}await f({...t,availableWidth:I,availableHeight:N});const $=await i.getDimensions(l.floating);return m!==$.width||y!==$.height?{reset:{rects:!0}}:{}}}};function Ve(){return typeof window<"u"}function xe(e){return Pr(e)?(e.nodeName||"").toLowerCase():"#document"}function G(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function oe(e){var t;return(t=(Pr(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function Pr(e){return Ve()?e instanceof Node||e instanceof G(e).Node:!1}function R(e){return Ve()?e instanceof Element||e instanceof G(e).Element:!1}function se(e){return Ve()?e instanceof HTMLElement||e instanceof G(e).HTMLElement:!1}function Ar(e){return!Ve()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof G(e).ShadowRoot}const Xo=new Set(["inline","contents"]);function Pe(e){const{overflow:t,overflowX:r,overflowY:n,display:o}=ee(e);return/auto|scroll|overlay|hidden|clip/.test(t+n+r)&&!Xo.has(o)}const Yo=new Set(["table","td","th"]);function qo(e){return Yo.has(xe(e))}const Uo=[":popover-open",":modal"];function Xe(e){return Uo.some(t=>{try{return e.matches(t)}catch{return!1}})}const Jo=["transform","translate","scale","rotate","perspective"],Go=["transform","translate","scale","rotate","perspective","filter"],Ko=["paint","layout","strict","content"];function gt(e){const t=mt(),r=R(e)?ee(e):e;return Jo.some(n=>r[n]?r[n]!=="none":!1)||(r.containerType?r.containerType!=="normal":!1)||!t&&(r.backdropFilter?r.backdropFilter!=="none":!1)||!t&&(r.filter?r.filter!=="none":!1)||Go.some(n=>(r.willChange||"").includes(n))||Ko.some(n=>(r.contain||"").includes(n))}function Zo(e){let t=he(e);for(;se(t)&&!Ce(t);){if(gt(t))return t;if(Xe(t))return null;t=he(t)}return null}function mt(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const Qo=new Set(["html","body","#document"]);function Ce(e){return Qo.has(xe(e))}function ee(e){return G(e).getComputedStyle(e)}function Ye(e){return R(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function he(e){if(xe(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Ar(e)&&e.host||oe(e);return Ar(t)?t.host:t}function Or(e){const t=he(e);return Ce(t)?e.ownerDocument?e.ownerDocument.body:e.body:se(t)&&Pe(t)?t:Or(t)}function Ae(e,t,r){var n;t===void 0&&(t=[]),r===void 0&&(r=!0);const o=Or(e),s=o===((n=e.ownerDocument)==null?void 0:n.body),i=G(o);if(s){const l=vt(i);return t.concat(i,i.visualViewport||[],Pe(o)?o:[],l&&r?Ae(l):[])}return t.concat(o,Ae(o,[],r))}function vt(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Lr(e){const t=ee(e);let r=parseFloat(t.width)||0,n=parseFloat(t.height)||0;const o=se(e),s=o?e.offsetWidth:r,i=o?e.offsetHeight:n,l=Fe(r)!==s||Fe(n)!==i;return l&&(r=s,n=i),{width:r,height:n,$:l}}function wt(e){return R(e)?e:e.contextElement}function Se(e){const t=wt(e);if(!se(t))return re(1);const r=t.getBoundingClientRect(),{width:n,height:o,$:s}=Lr(t);let i=(s?Fe(r.width):r.width)/n,l=(s?Fe(r.height):r.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!l||!Number.isFinite(l))&&(l=1),{x:i,y:l}}const Ro=re(0);function _r(e){const t=G(e);return!mt()||!t.visualViewport?Ro:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function es(e,t,r){return t===void 0&&(t=!1),!r||t&&r!==G(e)?!1:t}function ge(e,t,r,n){t===void 0&&(t=!1),r===void 0&&(r=!1);const o=e.getBoundingClientRect(),s=wt(e);let i=re(1);t&&(n?R(n)&&(i=Se(n)):i=Se(e));const l=es(s,r,n)?_r(s):re(0);let f=(o.left+l.x)/i.x,c=(o.top+l.y)/i.y,d=o.width/i.x,h=o.height/i.y;if(s){const p=G(s),g=n&&R(n)?G(n):n;let m=p,y=vt(m);for(;y&&n&&g!==m;){const C=Se(y),S=y.getBoundingClientRect(),E=ee(y),A=S.left+(y.clientLeft+parseFloat(E.paddingLeft))*C.x,v=S.top+(y.clientTop+parseFloat(E.paddingTop))*C.y;f*=C.x,c*=C.y,d*=C.x,h*=C.y,f+=A,c+=v,m=G(y),y=vt(m)}}return je({width:d,height:h,x:f,y:c})}function bt(e,t){const r=Ye(e).scrollLeft;return t?t.left+r:ge(oe(e)).left+r}function Dr(e,t,r){r===void 0&&(r=!1);const n=e.getBoundingClientRect(),o=n.left+t.scrollLeft-(r?0:bt(e,n)),s=n.top+t.scrollTop;return{x:o,y:s}}function ts(e){let{elements:t,rect:r,offsetParent:n,strategy:o}=e;const s=o==="fixed",i=oe(n),l=t?Xe(t.floating):!1;if(n===i||l&&s)return r;let f={scrollLeft:0,scrollTop:0},c=re(1);const d=re(0),h=se(n);if((h||!h&&!s)&&((xe(n)!=="body"||Pe(i))&&(f=Ye(n)),se(n))){const g=ge(n);c=Se(n),d.x=g.x+n.clientLeft,d.y=g.y+n.clientTop}const p=i&&!h&&!s?Dr(i,f,!0):re(0);return{width:r.width*c.x,height:r.height*c.y,x:r.x*c.x-f.scrollLeft*c.x+d.x+p.x,y:r.y*c.y-f.scrollTop*c.y+d.y+p.y}}function rs(e){return Array.from(e.getClientRects())}function ns(e){const t=oe(e),r=Ye(e),n=e.ownerDocument.body,o=J(t.scrollWidth,t.clientWidth,n.scrollWidth,n.clientWidth),s=J(t.scrollHeight,t.clientHeight,n.scrollHeight,n.clientHeight);let i=-r.scrollLeft+bt(e);const l=-r.scrollTop;return ee(n).direction==="rtl"&&(i+=J(t.clientWidth,n.clientWidth)-o),{width:o,height:s,x:i,y:l}}function os(e,t){const r=G(e),n=oe(e),o=r.visualViewport;let s=n.clientWidth,i=n.clientHeight,l=0,f=0;if(o){s=o.width,i=o.height;const c=mt();(!c||c&&t==="fixed")&&(l=o.offsetLeft,f=o.offsetTop)}return{width:s,height:i,x:l,y:f}}const ss=new Set(["absolute","fixed"]);function is(e,t){const r=ge(e,!0,t==="fixed"),n=r.top+e.clientTop,o=r.left+e.clientLeft,s=se(e)?Se(e):re(1),i=e.clientWidth*s.x,l=e.clientHeight*s.y,f=o*s.x,c=n*s.y;return{width:i,height:l,x:f,y:c}}function Mr(e,t,r){let n;if(t==="viewport")n=os(e,r);else if(t==="document")n=ns(oe(e));else if(R(t))n=is(t,r);else{const o=_r(e);n={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return je(n)}function kr(e,t){const r=he(e);return r===t||!R(r)||Ce(r)?!1:ee(r).position==="fixed"||kr(r,t)}function as(e,t){const r=t.get(e);if(r)return r;let n=Ae(e,[],!1).filter(l=>R(l)&&xe(l)!=="body"),o=null;const s=ee(e).position==="fixed";let i=s?he(e):e;for(;R(i)&&!Ce(i);){const l=ee(i),f=gt(i);!f&&l.position==="fixed"&&(o=null),(s?!f&&!o:!f&&l.position==="static"&&!!o&&ss.has(o.position)||Pe(i)&&!f&&kr(e,i))?n=n.filter(d=>d!==i):o=l,i=he(i)}return t.set(e,n),n}function ls(e){let{element:t,boundary:r,rootBoundary:n,strategy:o}=e;const i=[...r==="clippingAncestors"?Xe(t)?[]:as(t,this._c):[].concat(r),n],l=i[0],f=i.reduce((c,d)=>{const h=Mr(t,d,o);return c.top=J(h.top,c.top),c.right=ue(h.right,c.right),c.bottom=ue(h.bottom,c.bottom),c.left=J(h.left,c.left),c},Mr(t,l,o));return{width:f.right-f.left,height:f.bottom-f.top,x:f.left,y:f.top}}function cs(e){const{width:t,height:r}=Lr(e);return{width:t,height:r}}function ds(e,t,r){const n=se(t),o=oe(t),s=r==="fixed",i=ge(e,!0,s,t);let l={scrollLeft:0,scrollTop:0};const f=re(0);function c(){f.x=bt(o)}if(n||!n&&!s)if((xe(t)!=="body"||Pe(o))&&(l=Ye(t)),n){const g=ge(t,!0,s,t);f.x=g.x+t.clientLeft,f.y=g.y+t.clientTop}else o&&c();s&&!n&&o&&c();const d=o&&!n&&!s?Dr(o,l):re(0),h=i.left+l.scrollLeft-f.x-d.x,p=i.top+l.scrollTop-f.y-d.y;return{x:h,y:p,width:i.width,height:i.height}}function yt(e){return ee(e).position==="static"}function Ir(e,t){if(!se(e)||ee(e).position==="fixed")return null;if(t)return t(e);let r=e.offsetParent;return oe(e)===r&&(r=r.ownerDocument.body),r}function $r(e,t){const r=G(e);if(Xe(e))return r;if(!se(e)){let o=he(e);for(;o&&!Ce(o);){if(R(o)&&!yt(o))return o;o=he(o)}return r}let n=Ir(e,t);for(;n&&qo(n)&&yt(n);)n=Ir(n,t);return n&&Ce(n)&&yt(n)&&!gt(n)?r:n||Zo(e)||r}const fs=async function(e){const t=this.getOffsetParent||$r,r=this.getDimensions,n=await r(e.floating);return{reference:ds(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:n.width,height:n.height}}};function us(e){return ee(e).direction==="rtl"}const hs={convertOffsetParentRelativeRectToViewportRelativeRect:ts,getDocumentElement:oe,getClippingRect:ls,getOffsetParent:$r,getElementRects:fs,getClientRects:rs,getDimensions:cs,getScale:Se,isElement:R,isRTL:us};function zr(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function ps(e,t){let r=null,n;const o=oe(e);function s(){var l;clearTimeout(n),(l=r)==null||l.disconnect(),r=null}function i(l,f){l===void 0&&(l=!1),f===void 0&&(f=1),s();const c=e.getBoundingClientRect(),{left:d,top:h,width:p,height:g}=c;if(l||t(),!p||!g)return;const m=We(h),y=We(o.clientWidth-(d+p)),C=We(o.clientHeight-(h+g)),S=We(d),A={rootMargin:-m+"px "+-y+"px "+-C+"px "+-S+"px",threshold:J(0,ue(1,f))||1};let v=!0;function b(_){const N=_[0].intersectionRatio;if(N!==f){if(!v)return i();N?i(!1,N):n=setTimeout(()=>{i(!1,1e-7)},1e3)}N===1&&!zr(c,e.getBoundingClientRect())&&i(),v=!1}try{r=new IntersectionObserver(b,{...A,root:o.ownerDocument})}catch{r=new IntersectionObserver(b,A)}r.observe(e)}return i(!0),s}function gs(e,t,r,n){n===void 0&&(n={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:l=typeof IntersectionObserver=="function",animationFrame:f=!1}=n,c=wt(e),d=o||s?[...c?Ae(c):[],...Ae(t)]:[];d.forEach(S=>{o&&S.addEventListener("scroll",r,{passive:!0}),s&&S.addEventListener("resize",r)});const h=c&&l?ps(c,r):null;let p=-1,g=null;i&&(g=new ResizeObserver(S=>{let[E]=S;E&&E.target===c&&g&&(g.unobserve(t),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var A;(A=g)==null||A.observe(t)})),r()}),c&&!f&&g.observe(c),g.observe(t));let m,y=f?ge(e):null;f&&C();function C(){const S=ge(e);y&&!zr(y,S)&&r(),y=S,m=requestAnimationFrame(C)}return r(),()=>{var S;d.forEach(E=>{o&&E.removeEventListener("scroll",r),s&&E.removeEventListener("resize",r)}),h==null||h(),(S=g)==null||S.disconnect(),g=null,f&&cancelAnimationFrame(m)}}const ms=Wo,vs=Bo,ws=zo,bs=Vo,ys=Ho,Hr=$o,xs=jo,Cs=(e,t,r)=>{const n=new Map,o={platform:hs,...r},s={...o.platform,_c:n};return Io(e,t,{...o,platform:s})};var Ss=typeof document<"u",Es=function(){},qe=Ss?L.useLayoutEffect:Es;function Ue(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let r,n,o;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(r=e.length,r!==t.length)return!1;for(n=r;n--!==0;)if(!Ue(e[n],t[n]))return!1;return!0}if(o=Object.keys(e),r=o.length,r!==Object.keys(t).length)return!1;for(n=r;n--!==0;)if(!{}.hasOwnProperty.call(t,o[n]))return!1;for(n=r;n--!==0;){const s=o[n];if(!(s==="_owner"&&e.$$typeof)&&!Ue(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Fr(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Wr(e,t){const r=Fr(e);return Math.round(t*r)/r}function xt(e){const t=u.useRef(e);return qe(()=>{t.current=e}),t}function Ts(e){e===void 0&&(e={});const{placement:t="bottom",strategy:r="absolute",middleware:n=[],platform:o,elements:{reference:s,floating:i}={},transform:l=!0,whileElementsMounted:f,open:c}=e,[d,h]=u.useState({x:0,y:0,strategy:r,placement:t,middlewareData:{},isPositioned:!1}),[p,g]=u.useState(n);Ue(p,n)||g(n);const[m,y]=u.useState(null),[C,S]=u.useState(null),E=u.useCallback(M=>{M!==_.current&&(_.current=M,y(M))},[]),A=u.useCallback(M=>{M!==N.current&&(N.current=M,S(M))},[]),v=s||m,b=i||C,_=u.useRef(null),N=u.useRef(null),I=u.useRef(d),$=f!=null,z=xt(f),W=xt(o),x=xt(c),w=u.useCallback(()=>{if(!_.current||!N.current)return;const M={placement:t,strategy:r,middleware:p};W.current&&(M.platform=W.current),Cs(_.current,N.current,M).then(j=>{const H={...j,isPositioned:x.current!==!1};P.current&&!Ue(I.current,H)&&(I.current=H,Ot.flushSync(()=>{h(H)}))})},[p,t,r,W,x]);qe(()=>{c===!1&&I.current.isPositioned&&(I.current.isPositioned=!1,h(M=>({...M,isPositioned:!1})))},[c]);const P=u.useRef(!1);qe(()=>(P.current=!0,()=>{P.current=!1}),[]),qe(()=>{if(v&&(_.current=v),b&&(N.current=b),v&&b){if(z.current)return z.current(v,b,w);w()}},[v,b,w,z,$]);const D=u.useMemo(()=>({reference:_,floating:N,setReference:E,setFloating:A}),[E,A]),T=u.useMemo(()=>({reference:v,floating:b}),[v,b]),k=u.useMemo(()=>{const M={position:r,left:0,top:0};if(!T.floating)return M;const j=Wr(T.floating,d.x),H=Wr(T.floating,d.y);return l?{...M,transform:"translate("+j+"px, "+H+"px)",...Fr(T.floating)>=1.5&&{willChange:"transform"}}:{position:r,left:j,top:H}},[r,l,T.floating,d.x,d.y]);return u.useMemo(()=>({...d,update:w,refs:D,elements:T,floatingStyles:k}),[d,w,D,T,k])}const Ns=e=>{function t(r){return{}.hasOwnProperty.call(r,"current")}return{name:"arrow",options:e,fn(r){const{element:n,padding:o}=typeof e=="function"?e(r):e;return n&&t(n)?n.current!=null?Hr({element:n.current,padding:o}).fn(r):{}:n?Hr({element:n,padding:o}).fn(r):{}}}},Ps=(e,t)=>({...ms(e),options:[e,t]}),As=(e,t)=>({...vs(e),options:[e,t]}),Os=(e,t)=>({...xs(e),options:[e,t]}),Ls=(e,t)=>({...ws(e),options:[e,t]}),_s=(e,t)=>({...bs(e),options:[e,t]}),Ds=(e,t)=>({...ys(e),options:[e,t]}),Ms=(e,t)=>({...Ns(e),options:[e,t]});var ks="Arrow",Br=u.forwardRef((e,t)=>{const{children:r,width:n=10,height:o=5,...s}=e;return a.jsx(q.svg,{...s,ref:t,width:n,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?r:a.jsx("polygon",{points:"0,0 30,0 15,10"})})});Br.displayName=ks;var Is=Br;function $s(e){const[t,r]=u.useState(void 0);return fe(()=>{if(e){r({width:e.offsetWidth,height:e.offsetHeight});const n=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,l;if("borderBoxSize"in s){const f=s.borderBoxSize,c=Array.isArray(f)?f[0]:f;i=c.inlineSize,l=c.blockSize}else i=e.offsetWidth,l=e.offsetHeight;r({width:i,height:l})});return n.observe(e,{box:"border-box"}),()=>n.unobserve(e)}else r(void 0)},[e]),t}var Ct="Popper",[jr,Vr]=nt(Ct),[zs,Xr]=jr(Ct),Yr=e=>{const{__scopePopper:t,children:r}=e,[n,o]=u.useState(null);return a.jsx(zs,{scope:t,anchor:n,onAnchorChange:o,children:r})};Yr.displayName=Ct;var qr="PopperAnchor",Ur=u.forwardRef((e,t)=>{const{__scopePopper:r,virtualRef:n,...o}=e,s=Xr(qr,r),i=u.useRef(null),l=U(t,i);return u.useEffect(()=>{s.onAnchorChange((n==null?void 0:n.current)||i.current)}),n?null:a.jsx(q.div,{...o,ref:l})});Ur.displayName=qr;var St="PopperContent",[Hs,Fs]=jr(St),Jr=u.forwardRef((e,t)=>{var cn,dn,fn,un,hn,pn;const{__scopePopper:r,side:n="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:l=0,avoidCollisions:f=!0,collisionBoundary:c=[],collisionPadding:d=0,sticky:h="partial",hideWhenDetached:p=!1,updatePositionStrategy:g="optimized",onPlaced:m,...y}=e,C=Xr(St,r),[S,E]=u.useState(null),A=U(t,Le=>E(Le)),[v,b]=u.useState(null),_=$s(v),N=(_==null?void 0:_.width)??0,I=(_==null?void 0:_.height)??0,$=n+(s!=="center"?"-"+s:""),z=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},W=Array.isArray(c)?c:[c],x=W.length>0,w={padding:z,boundary:W.filter(Bs),altBoundary:x},{refs:P,floatingStyles:D,placement:T,isPositioned:k,middlewareData:M}=Ts({strategy:"fixed",placement:$,whileElementsMounted:(...Le)=>gs(...Le,{animationFrame:g==="always"}),elements:{reference:C.anchor},middleware:[Ps({mainAxis:o+I,alignmentAxis:i}),f&&As({mainAxis:!0,crossAxis:!1,limiter:h==="partial"?Os():void 0,...w}),f&&Ls({...w}),_s({...w,apply:({elements:Le,rects:gn,availableWidth:Ei,availableHeight:Ti})=>{const{width:Ni,height:Pi}=gn.reference,Qe=Le.floating.style;Qe.setProperty("--radix-popper-available-width",`${Ei}px`),Qe.setProperty("--radix-popper-available-height",`${Ti}px`),Qe.setProperty("--radix-popper-anchor-width",`${Ni}px`),Qe.setProperty("--radix-popper-anchor-height",`${Pi}px`)}}),v&&Ms({element:v,padding:l}),js({arrowWidth:N,arrowHeight:I}),p&&Ds({strategy:"referenceHidden",...w})]}),[j,H]=Zr(T),V=Q(m);fe(()=>{k&&(V==null||V())},[k,V]);const ie=(cn=M.arrow)==null?void 0:cn.x,ae=(dn=M.arrow)==null?void 0:dn.y,Z=((fn=M.arrow)==null?void 0:fn.centerOffset)!==0,[Ze,Si]=u.useState();return fe(()=>{S&&Si(window.getComputedStyle(S).zIndex)},[S]),a.jsx("div",{ref:P.setFloating,"data-radix-popper-content-wrapper":"",style:{...D,transform:k?D.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Ze,"--radix-popper-transform-origin":[(un=M.transformOrigin)==null?void 0:un.x,(hn=M.transformOrigin)==null?void 0:hn.y].join(" "),...((pn=M.hide)==null?void 0:pn.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:a.jsx(Hs,{scope:r,placedSide:j,onArrowChange:b,arrowX:ie,arrowY:ae,shouldHideArrow:Z,children:a.jsx(q.div,{"data-side":j,"data-align":H,...y,ref:A,style:{...y.style,animation:k?void 0:"none"}})})})});Jr.displayName=St;var Gr="PopperArrow",Ws={top:"bottom",right:"left",bottom:"top",left:"right"},Kr=u.forwardRef(function(t,r){const{__scopePopper:n,...o}=t,s=Fs(Gr,n),i=Ws[s.placedSide];return a.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:a.jsx(Is,{...o,ref:r,style:{...o.style,display:"block"}})})});Kr.displayName=Gr;function Bs(e){return e!==null}var js=e=>({name:"transformOrigin",options:e,fn(t){var C,S,E;const{placement:r,rects:n,middlewareData:o}=t,i=((C=o.arrow)==null?void 0:C.centerOffset)!==0,l=i?0:e.arrowWidth,f=i?0:e.arrowHeight,[c,d]=Zr(r),h={start:"0%",center:"50%",end:"100%"}[d],p=(((S=o.arrow)==null?void 0:S.x)??0)+l/2,g=(((E=o.arrow)==null?void 0:E.y)??0)+f/2;let m="",y="";return c==="bottom"?(m=i?h:`${p}px`,y=`${-f}px`):c==="top"?(m=i?h:`${p}px`,y=`${n.floating.height+f}px`):c==="right"?(m=`${-f}px`,y=i?h:`${g}px`):c==="left"&&(m=`${n.floating.width+f}px`,y=i?h:`${g}px`),{data:{x:m,y}}}});function Zr(e){const[t,r="center"]=e.split("-");return[t,r]}var Vs=Yr,Xs=Ur,Ys=Jr,qs=Kr,Us=u[" useInsertionEffect ".trim().toString()]||fe;function Js({prop:e,defaultProp:t,onChange:r=()=>{},caller:n}){const[o,s,i]=Gs({defaultProp:t,onChange:r}),l=e!==void 0,f=l?e:o;{const d=u.useRef(e!==void 0);u.useEffect(()=>{const h=d.current;h!==l&&console.warn(`${n} is changing from ${h?"controlled":"uncontrolled"} to ${l?"controlled":"uncontrolled"}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`),d.current=l},[l,n])}const c=u.useCallback(d=>{var h;if(l){const p=Ks(d)?d(e):d;p!==e&&((h=i.current)==null||h.call(i,p))}else s(d)},[l,e,s,i]);return[f,c]}function Gs({defaultProp:e,onChange:t}){const[r,n]=u.useState(e),o=u.useRef(r),s=u.useRef(t);return Us(()=>{s.current=t},[t]),u.useEffect(()=>{var i;o.current!==r&&((i=s.current)==null||i.call(s,r),o.current=r)},[r,o]),[r,n,s]}function Ks(e){return typeof e=="function"}var Zs=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"}),Qs="VisuallyHidden",Qr=u.forwardRef((e,t)=>a.jsx(q.span,{...e,ref:t,style:{...Zs,...e.style}}));Qr.displayName=Qs;var Rs=Qr,[Je,Oi]=nt("Tooltip",[Vr]),Ge=Vr(),Rr="TooltipProvider",ei=700,Et="tooltip.open",[ti,Tt]=Je(Rr),en=e=>{const{__scopeTooltip:t,delayDuration:r=ei,skipDelayDuration:n=300,disableHoverableContent:o=!1,children:s}=e,i=u.useRef(!0),l=u.useRef(!1),f=u.useRef(0);return u.useEffect(()=>{const c=f.current;return()=>window.clearTimeout(c)},[]),a.jsx(ti,{scope:t,isOpenDelayedRef:i,delayDuration:r,onOpen:u.useCallback(()=>{window.clearTimeout(f.current),i.current=!1},[]),onClose:u.useCallback(()=>{window.clearTimeout(f.current),f.current=window.setTimeout(()=>i.current=!0,n)},[n]),isPointerInTransitRef:l,onPointerInTransitChange:u.useCallback(c=>{l.current=c},[]),disableHoverableContent:o,children:s})};en.displayName=Rr;var Oe="Tooltip",[ri,Ke]=Je(Oe),tn=e=>{const{__scopeTooltip:t,children:r,open:n,defaultOpen:o,onOpenChange:s,disableHoverableContent:i,delayDuration:l}=e,f=Tt(Oe,e.__scopeTooltip),c=Ge(t),[d,h]=u.useState(null),p=So(),g=u.useRef(0),m=i??f.disableHoverableContent,y=l??f.delayDuration,C=u.useRef(!1),[S,E]=Js({prop:n,defaultProp:o??!1,onChange:N=>{N?(f.onOpen(),document.dispatchEvent(new CustomEvent(Et))):f.onClose(),s==null||s(N)},caller:Oe}),A=u.useMemo(()=>S?C.current?"delayed-open":"instant-open":"closed",[S]),v=u.useCallback(()=>{window.clearTimeout(g.current),g.current=0,C.current=!1,E(!0)},[E]),b=u.useCallback(()=>{window.clearTimeout(g.current),g.current=0,E(!1)},[E]),_=u.useCallback(()=>{window.clearTimeout(g.current),g.current=window.setTimeout(()=>{C.current=!0,E(!0),g.current=0},y)},[y,E]);return u.useEffect(()=>()=>{g.current&&(window.clearTimeout(g.current),g.current=0)},[]),a.jsx(Vs,{...c,children:a.jsx(ri,{scope:t,contentId:p,open:S,stateAttribute:A,trigger:d,onTriggerChange:h,onTriggerEnter:u.useCallback(()=>{f.isOpenDelayedRef.current?_():v()},[f.isOpenDelayedRef,_,v]),onTriggerLeave:u.useCallback(()=>{m?b():(window.clearTimeout(g.current),g.current=0)},[b,m]),onOpen:v,onClose:b,disableHoverableContent:m,children:r})})};tn.displayName=Oe;var Nt="TooltipTrigger",rn=u.forwardRef((e,t)=>{const{__scopeTooltip:r,...n}=e,o=Ke(Nt,r),s=Tt(Nt,r),i=Ge(r),l=u.useRef(null),f=U(t,l,o.onTriggerChange),c=u.useRef(!1),d=u.useRef(!1),h=u.useCallback(()=>c.current=!1,[]);return u.useEffect(()=>()=>document.removeEventListener("pointerup",h),[h]),a.jsx(Xs,{asChild:!0,...i,children:a.jsx(q.button,{"aria-describedby":o.open?o.contentId:void 0,"data-state":o.stateAttribute,...n,ref:f,onPointerMove:X(e.onPointerMove,p=>{p.pointerType!=="touch"&&!d.current&&!s.isPointerInTransitRef.current&&(o.onTriggerEnter(),d.current=!0)}),onPointerLeave:X(e.onPointerLeave,()=>{o.onTriggerLeave(),d.current=!1}),onPointerDown:X(e.onPointerDown,()=>{o.open&&o.onClose(),c.current=!0,document.addEventListener("pointerup",h,{once:!0})}),onFocus:X(e.onFocus,()=>{c.current||o.onOpen()}),onBlur:X(e.onBlur,o.onClose),onClick:X(e.onClick,o.onClose)})})});rn.displayName=Nt;var ni="TooltipPortal",[Li,oi]=Je(ni,{forceMount:void 0}),Ee="TooltipContent",nn=u.forwardRef((e,t)=>{const r=oi(Ee,e.__scopeTooltip),{forceMount:n=r.forceMount,side:o="top",...s}=e,i=Ke(Ee,e.__scopeTooltip);return a.jsx(ve,{present:n||i.open,children:i.disableHoverableContent?a.jsx(on,{side:o,...s,ref:t}):a.jsx(si,{side:o,...s,ref:t})})}),si=u.forwardRef((e,t)=>{const r=Ke(Ee,e.__scopeTooltip),n=Tt(Ee,e.__scopeTooltip),o=u.useRef(null),s=U(t,o),[i,l]=u.useState(null),{trigger:f,onClose:c}=r,d=o.current,{onPointerInTransitChange:h}=n,p=u.useCallback(()=>{l(null),h(!1)},[h]),g=u.useCallback((m,y)=>{const C=m.currentTarget,S={x:m.clientX,y:m.clientY},E=di(S,C.getBoundingClientRect()),A=fi(S,E),v=ui(y.getBoundingClientRect()),b=pi([...A,...v]);l(b),h(!0)},[h]);return u.useEffect(()=>()=>p(),[p]),u.useEffect(()=>{if(f&&d){const m=C=>g(C,d),y=C=>g(C,f);return f.addEventListener("pointerleave",m),d.addEventListener("pointerleave",y),()=>{f.removeEventListener("pointerleave",m),d.removeEventListener("pointerleave",y)}}},[f,d,g,p]),u.useEffect(()=>{if(i){const m=y=>{const C=y.target,S={x:y.clientX,y:y.clientY},E=(f==null?void 0:f.contains(C))||(d==null?void 0:d.contains(C)),A=!hi(S,i);E?p():A&&(p(),c())};return document.addEventListener("pointermove",m),()=>document.removeEventListener("pointermove",m)}},[f,d,i,c,p]),a.jsx(on,{...e,ref:s})}),[ii,ai]=Je(Oe,{isInside:!1}),li=Re.createSlottable("TooltipContent"),on=u.forwardRef((e,t)=>{const{__scopeTooltip:r,children:n,"aria-label":o,onEscapeKeyDown:s,onPointerDownOutside:i,...l}=e,f=Ke(Ee,r),c=Ge(r),{onClose:d}=f;return u.useEffect(()=>(document.addEventListener(Et,d),()=>document.removeEventListener(Et,d)),[d]),u.useEffect(()=>{if(f.trigger){const h=p=>{const g=p.target;g!=null&&g.contains(f.trigger)&&d()};return window.addEventListener("scroll",h,{capture:!0}),()=>window.removeEventListener("scroll",h,{capture:!0})}},[f.trigger,d]),a.jsx(vr,{asChild:!0,disableOutsidePointerEvents:!1,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:h=>h.preventDefault(),onDismiss:d,children:a.jsxs(Ys,{"data-state":f.stateAttribute,...c,...l,ref:t,style:{...l.style,"--radix-tooltip-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-tooltip-content-available-width":"var(--radix-popper-available-width)","--radix-tooltip-content-available-height":"var(--radix-popper-available-height)","--radix-tooltip-trigger-width":"var(--radix-popper-anchor-width)","--radix-tooltip-trigger-height":"var(--radix-popper-anchor-height)"},children:[a.jsx(li,{children:n}),a.jsx(ii,{scope:r,isInside:!0,children:a.jsx(Rs,{id:f.contentId,role:"tooltip",children:o||n})})]})})});nn.displayName=Ee;var sn="TooltipArrow",ci=u.forwardRef((e,t)=>{const{__scopeTooltip:r,...n}=e,o=Ge(r);return ai(sn,r).isInside?null:a.jsx(qs,{...o,...n,ref:t})});ci.displayName=sn;function di(e,t){const r=Math.abs(t.top-e.y),n=Math.abs(t.bottom-e.y),o=Math.abs(t.right-e.x),s=Math.abs(t.left-e.x);switch(Math.min(r,n,o,s)){case s:return"left";case o:return"right";case r:return"top";case n:return"bottom";default:throw new Error("unreachable")}}function fi(e,t,r=5){const n=[];switch(t){case"top":n.push({x:e.x-r,y:e.y+r},{x:e.x+r,y:e.y+r});break;case"bottom":n.push({x:e.x-r,y:e.y-r},{x:e.x+r,y:e.y-r});break;case"left":n.push({x:e.x+r,y:e.y-r},{x:e.x+r,y:e.y+r});break;case"right":n.push({x:e.x-r,y:e.y-r},{x:e.x-r,y:e.y+r});break}return n}function ui(e){const{top:t,right:r,bottom:n,left:o}=e;return[{x:o,y:t},{x:r,y:t},{x:r,y:n},{x:o,y:n}]}function hi(e,t){const{x:r,y:n}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const l=t[s],f=t[i],c=l.x,d=l.y,h=f.x,p=f.y;d>n!=p>n&&r<(h-c)*(n-d)/(p-d)+c&&(o=!o)}return o}function pi(e){const t=e.slice();return t.sort((r,n)=>r.x<n.x?-1:r.x>n.x?1:r.y<n.y?-1:r.y>n.y?1:0),gi(t)}function gi(e){if(e.length<=1)return e.slice();const t=[];for(let n=0;n<e.length;n++){const o=e[n];for(;t.length>=2;){const s=t[t.length-1],i=t[t.length-2];if((s.x-i.x)*(o.y-i.y)>=(s.y-i.y)*(o.x-i.x))t.pop();else break}t.push(o)}t.pop();const r=[];for(let n=e.length-1;n>=0;n--){const o=e[n];for(;r.length>=2;){const s=r[r.length-1],i=r[r.length-2];if((s.x-i.x)*(o.y-i.y)>=(s.y-i.y)*(o.x-i.x))r.pop();else break}r.push(o)}return r.pop(),t.length===1&&r.length===1&&t[0].x===r[0].x&&t[0].y===r[0].y?t:t.concat(r)}var mi=en,vi=tn,wi=rn,an=nn;const bi=mi,yi=vi,xi=wi,ln=u.forwardRef(({className:e,sideOffset:t=4,...r},n)=>a.jsx(an,{ref:n,sideOffset:t,className:Y("z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-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",e),...r}));ln.displayName=an.displayName;const Ci={ChatProvider:_e,ChatInterface:me,MessageComponent:rt,ThreadManager:be,ChatApp:Zt,useChat:pe};O.Button=B,O.Card=tr,O.CardContent=sr,O.CardDescription=or,O.CardFooter=ir,O.CardHeader=rr,O.CardTitle=nr,O.ChatApp=Zt,O.ChatInterface=me,O.ChatProvider=_e,O.ChatWidget=to,O.Input=ar,O.Label=dr,O.MESSAGE_MAX_LENGTH=et,O.MessageComponent=rt,O.ScrollArea=lt,O.Separator=pr,O.THREAD_ID_PATTERN=Lt,O.TITLE_MAX_LENGTH=tt,O.Textarea=De,O.ThreadManager=be,O.Tooltip=yi,O.TooltipContent=ln,O.TooltipProvider=bi,O.TooltipTrigger=xi,O.cn=Y,O.default=Ci,O.safeJsonParse=Cn,O.sanitizeHtml=bn,O.sanitizeText=de,O.useChat=pe,O.useChatActions=no,O.useChatMessages=Rt,O.useCodeExecution=io,O.useFileContents=so,O.useSearchResults=oo,O.useStreamMonitor=er,O.useToolExtractor=He,O.useToolMessages=ro,O.validateAndSanitizeMessage=Te,O.validateAndSanitizeTitle=xn,O.validateMessageLength=_t,O.validateThreadId=yn,O.withInputValidation=Sn,Object.defineProperties(O,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/package.json
CHANGED