teodor-new-chat-ui 2.0.39 → 2.0.41
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 +9 -11
- package/dist/index.umd.js +2 -2
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -3061,43 +3061,41 @@ function Tp({
|
|
|
3061
3061
|
return /* @__PURE__ */ c(hs, { className: ve });
|
|
3062
3062
|
}
|
|
3063
3063
|
}, le = () => {
|
|
3064
|
-
const Z = "group relative mb-4
|
|
3064
|
+
const Z = "group relative mb-4 flex w-full";
|
|
3065
3065
|
switch (P) {
|
|
3066
3066
|
case "user":
|
|
3067
|
-
return T(Z, "
|
|
3067
|
+
return T(Z, "justify-end");
|
|
3068
3068
|
case "assistant":
|
|
3069
3069
|
case "tool":
|
|
3070
3070
|
case "system":
|
|
3071
|
-
return T(Z, "
|
|
3071
|
+
return T(Z, "justify-start");
|
|
3072
3072
|
default:
|
|
3073
3073
|
return Z;
|
|
3074
3074
|
}
|
|
3075
3075
|
}, ue = () => {
|
|
3076
3076
|
const Z = T(
|
|
3077
|
-
"rounded-lg px-4 py-3 relative transition-all duration-200 min-w-0 break-words",
|
|
3077
|
+
"rounded-lg px-4 py-3 relative transition-all duration-200 min-w-0 max-w-full break-words",
|
|
3078
3078
|
A && "px-3 py-2 text-sm"
|
|
3079
3079
|
);
|
|
3080
3080
|
switch (P) {
|
|
3081
3081
|
case "user":
|
|
3082
3082
|
return T(
|
|
3083
3083
|
Z,
|
|
3084
|
-
"max-w-[95%]",
|
|
3085
|
-
u === "phone" && "max-w-[98%]",
|
|
3084
|
+
"w-full md:max-w-[95%]",
|
|
3086
3085
|
"bg-[hsl(var(--chat-bubble-user))] text-[hsl(var(--chat-bubble-user-text))]",
|
|
3087
3086
|
"border border-transparent"
|
|
3088
3087
|
);
|
|
3089
3088
|
case "assistant":
|
|
3090
3089
|
return T(
|
|
3091
3090
|
Z,
|
|
3092
|
-
"max-w-[95%]",
|
|
3093
|
-
u === "phone" && "max-w-[98%]",
|
|
3091
|
+
"w-full md:max-w-[95%]",
|
|
3094
3092
|
"bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]",
|
|
3095
3093
|
"border border-border/60 dark:border-border/40"
|
|
3096
3094
|
);
|
|
3097
3095
|
case "tool":
|
|
3098
|
-
return T(Z, "bg-secondary/50 text-secondary-foreground border border-dashed
|
|
3096
|
+
return T(Z, "w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");
|
|
3099
3097
|
case "system":
|
|
3100
|
-
return T(Z, "bg-accent/40 text-muted-foreground
|
|
3098
|
+
return T(Z, "w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");
|
|
3101
3099
|
default:
|
|
3102
3100
|
return Z;
|
|
3103
3101
|
}
|
|
@@ -7242,7 +7240,7 @@ function Fn({
|
|
|
7242
7240
|
d && (await x(I), V(I));
|
|
7243
7241
|
}, se = async () => {
|
|
7244
7242
|
await C(), V(null);
|
|
7245
|
-
}, Ae = `flex flex-col h-full min-h-0 min-w-0 overflow-hidden bg-transparent ${e} ${i.container || ""}`, Pe = `flex-1 min-h-0 min-w-0 overflow-y-auto overflow-x-
|
|
7243
|
+
}, Ae = `flex w-full flex-col h-full min-h-0 min-w-0 overflow-x-hidden bg-transparent ${e} ${i.container || ""}`, Pe = `flex-1 min-h-0 min-w-0 w-full overflow-y-auto overflow-x-auto overscroll-x-contain break-words break-anywhere p-4 space-y-4 bg-transparent ${i.messagesArea || ""}`, Ue = `flex-shrink-0 w-full border-t p-4 bg-transparent ${i.inputArea || ""}`;
|
|
7246
7244
|
return /* @__PURE__ */ E("div", { className: Ae, children: [
|
|
7247
7245
|
!!m && !L && /* @__PURE__ */ E("div", { className: "bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between", children: [
|
|
7248
7246
|
/* @__PURE__ */ c("span", { children: m }),
|
package/dist/index.umd.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
`+s):n.stack=s}catch{}}throw n}}_request(t,r){typeof t=="string"?(r=r||{},r.url=t):r=t||{},r=ht(this.defaults,r);const{transitional:n,paramsSerializer:o,headers:s}=r;n!==void 0&&Er.assertOptions(n,{silentJSONParsing:Ke.transitional(Ke.boolean),forcedJSONParsing:Ke.transitional(Ke.boolean),clarifyTimeoutError:Ke.transitional(Ke.boolean)},!1),o!=null&&(S.isFunction(o)?r.paramsSerializer={serialize:o}:Er.assertOptions(o,{encode:Ke.function,serialize:Ke.function},!0)),r.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?r.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:r.allowAbsoluteUrls=!0),Er.assertOptions(r,{baseUrl:Ke.spelling("baseURL"),withXsrfToken:Ke.spelling("withXSRFToken")},!0),r.method=(r.method||this.defaults.method||"get").toLowerCase();let a=s&&S.merge(s.common,s[r.method]);s&&S.forEach(["delete","get","head","post","put","patch","common"],g=>{delete s[g]}),r.headers=Pe.concat(a,s);const c=[];let d=!0;this.interceptors.request.forEach(function(h){typeof h.runWhen=="function"&&h.runWhen(r)===!1||(d=d&&h.synchronous,c.unshift(h.fulfilled,h.rejected))});const f=[];this.interceptors.response.forEach(function(h){f.push(h.fulfilled,h.rejected)});let u,p=0,m;if(!d){const g=[js.bind(this),void 0];for(g.unshift(...c),g.push(...f),m=g.length,u=Promise.resolve(r);p<m;)u=u.then(g[p++],g[p++]);return u}m=c.length;let v=r;for(;p<m;){const g=c[p++],h=c[p++];try{v=g(v)}catch(b){h.call(this,b);break}}try{u=js.call(this,v)}catch(g){return Promise.reject(g)}for(p=0,m=f.length;p<m;)u=u.then(f[p++],f[p++]);return u}getUri(t){t=ht(this.defaults,t);const r=Ms(t.baseURL,t.url,t.allowAbsoluteUrls);return Es(r,t.params,t.paramsSerializer)}};S.forEach(["delete","get","head","options"],function(t){gt.prototype[t]=function(r,n){return this.request(ht(n||{},{method:t,url:r,data:(n||{}).data}))}}),S.forEach(["post","put","patch"],function(t){function r(n){return function(s,a,c){return this.request(ht(c||{},{method:t,headers:n?{"Content-Type":"multipart/form-data"}:{},url:s,data:a}))}}gt.prototype[t]=r(),gt.prototype[t+"Form"]=r(!0)});let of=class Dd{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let r;this.promise=new Promise(function(s){r=s});const n=this;this.promise.then(o=>{if(!n._listeners)return;let s=n._listeners.length;for(;s-- >0;)n._listeners[s](o);n._listeners=null}),this.promise.then=o=>{let s;const a=new Promise(c=>{n.subscribe(c),s=c}).then(o);return a.cancel=function(){n.unsubscribe(s)},a},t(function(s,a,c){n.reason||(n.reason=new At(s,a,c),r(n.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const r=this._listeners.indexOf(t);r!==-1&&this._listeners.splice(r,1)}toAbortSignal(){const t=new AbortController,r=n=>{t.abort(n)};return this.subscribe(r),t.signal.unsubscribe=()=>this.unsubscribe(r),t.signal}static source(){let t;return{token:new Dd(function(o){t=o}),cancel:t}}};function sf(e){return function(r){return e.apply(null,r)}}function af(e){return S.isObject(e)&&e.isAxiosError===!0}const Fn={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(Fn).forEach(([e,t])=>{Fn[t]=e});function Gs(e){const t=new gt(e),r=ls(gt.prototype.request,t);return S.extend(r,gt.prototype,t,{allOwnKeys:!0}),S.extend(r,t,null,{allOwnKeys:!0}),r.create=function(o){return Gs(ht(e,o))},r}const we=Gs(Kt);we.Axios=gt,we.CanceledError=At,we.CancelToken=of,we.isCancel=_s,we.VERSION=Rs,we.toFormData=wr,we.AxiosError=ne,we.Cancel=we.CanceledError,we.all=function(t){return Promise.all(t)},we.spread=sf,we.isAxiosError=af,we.mergeConfig=ht,we.AxiosHeaders=Pe,we.formToJSON=e=>As(S.isHTMLForm(e)?new FormData(e):e),we.getAdapter=Vs.getAdapter,we.HttpStatusCode=Fn,we.default=we;const{Axios:Cw,AxiosError:Ew,CanceledError:Nw,isCancel:Tw,CancelToken:Aw,VERSION:Pw,all:_w,Cancel:Iw,isAxiosError:kw,spread:Ow,toFormData:Mw,AxiosHeaders:Dw,HttpStatusCode:Lw,formToJSON:Fw,getAdapter:$w,mergeConfig:Bw}=we,$n={};function qt(){var e;try{return typeof window<"u"&&((e=window.localStorage)==null?void 0:e.getItem("chat-debug"))==="1"}catch{return!1}}const qs=$n==null?void 0:$n.VITE_API_BASE_URL,Xs=qs?qs.replace(/\/+$/,""):void 0;!Xs&&typeof window<"u"&&console.warn("VITE_API_BASE_URL is not set. The API client will need to be configured via apiConfig prop.");let Nr=null;const Bn=new Set;function Un(){return Nr}function Hn(e){Nr=e,Bn.forEach(t=>t(e))}function Ys(e){return Bn.add(e),()=>Bn.delete(e)}const Ge=we.create({baseURL:Xs||"http://localhost:8000",timeout:3e4,withCredentials:!0});Ge.interceptors.request.use(e=>(Nr&&(e.headers.Authorization=`Bearer ${Nr}`),e)),Ge.interceptors.response.use(e=>e,e=>Promise.reject(e));async function mt(e,t){return(await Ge.get(e,t)).data}async function zn(e,t,r){return(await Ge.post(e,t,r)).data}async function Js(e,t,r){return(await Ge.put(e,t,r)).data}async function Zs(e,t){return(await Ge.delete(e,t)).data}async function cf(e,t){var m;if(qt()){let v=t.body;try{const g=JSON.parse(JSON.stringify(t.body));(m=g==null?void 0:g.payload)!=null&&m.files_info&&Array.isArray(g.payload.files_info)&&(g.payload.files_info=g.payload.files_info.map(h=>({...h,data:h!=null&&h.data?`<base64 ${String(h.data).length} chars>`:h==null?void 0:h.data}))),v=g}catch{}console.debug("[api.stream]",t.method,`${Ge.defaults.baseURL}${e}`,v)}const n=(Ge.defaults.baseURL||"").replace(/\/+$|^\s+|\s+$/g,""),o=t.method??"POST",s=Un(),a=t.headers??{},c=e?e.startsWith("/")?e:`/${e}`:"",d=n?`${n}${c}`:c||n,f=await fetch(d,{method:o,headers:{"Content-Type":"application/json",...s?{Authorization:`Bearer ${s}`}:{},...a},body:t.body!==void 0?JSON.stringify(t.body):void 0,credentials:"include",signal:t.signal});if(!f.ok||!f.body){const v=await f.text().catch(()=>"");throw qt()&&console.debug("[api.stream] non-OK",f.status,v==null?void 0:v.slice(0,500)),new Error(`Stream failed: ${f.status} ${f.statusText}${v?": "+v:""}`)}const u=f.body.getReader(),p=new TextDecoder;for(;;){const{done:v,value:g}=await u.read();if(v)break;const h=p.decode(g,{stream:!0});qt()&&console.debug("[api.stream] chunk",h.slice(0,200)),t.onChunk(h)}}function qe(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class Tr{get baseUrl(){const t=Ge.defaults.baseURL||"";return String(t).replace(/\/+$|^\s+|\s+$/g,"")}updateConfig(t){t.baseUrl&&(Ge.defaults.baseURL=String(t.baseUrl).replace(/\/+$/g,"")),t.authToken!==void 0&&Hn(t.authToken)}getAuthToken(){return Un()}setAuthToken(t){Hn(t)}onTokenChange(t){return Ys(t)}async listThreads(){const t=await mt("/chat/threads"),r=qe(t);return(r==null?void 0:r.items)??(t==null?void 0:t.items)??[]}async createThread(t){const n=await zn("/chat/threads",t?{title:t}:void 0);return qe(n)}async updateThread(t,r){const n=await Js(`/chat/threads/${t}`,{title:r});return qe(n)}async deleteThread(t){const r=await Zs(`/chat/threads/${t}`);return qe(r)}async threadInfo(t){const r=await mt(`/chat/threads/${t}/info`);return qe(r)}async getMessages(t){const r=await mt("/chat/messages",{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs,limit:t.limit,before_id:t.beforeId??void 0}});return qe(r)}async getState(t){const r=await mt("/chat/state",{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return qe(r)}async getStateHistory(t){const r=await mt("/chat/state/history",{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return qe(r)}async listCheckpoints(t){const r=await mt("/chat/checkpoints",{params:{thread_id:t}});return qe(r)}async uploadImage(t,r="/upload"){const n=new FormData;n.append("file",t,t.name),qt()&&console.debug("[api.uploadImage] ->",r,{name:t.name,type:t.type,size:t.size});const o=await zn(r,n,{headers:{Accept:"application/json"},maxBodyLength:1/0}),s=qe(o);if(qt()&&console.debug("[api.uploadImage] <-",s),!(s!=null&&s.url))throw new Error("Invalid upload response: missing url");return{url:s.url,mimeType:s.mimeType??t.type,name:s.name??t.name,size:s.size??t.size}}}const tt=new Tr;function Qs(e={}){const t=e.baseUrl??"/api/chat",r=e.streamPath??"/stream",[n,o]=T.useState(e.token??null),s=T.useRef(e.headers??{}),[a,c]=T.useState(!1),[d,f]=T.useState(null),[u,p]=T.useState(""),[m,v]=T.useState(null),g=T.useRef(null),h=T.useCallback(x=>{o(x)},[]),b=T.useCallback(()=>{var x;(x=g.current)==null||x.abort(),g.current=null,c(!1)},[]),w=T.useCallback(()=>{p(""),v(null),f(null)},[]),y=T.useCallback((x,C,E)=>{g.current&&(g.current.abort(),g.current=null),c(!0),f(null),e.autoAppendAssistant!==!1&&p("");const O=new AbortController;return g.current=O,(async()=>{var D,$,R,X;const N=(()=>{var B;try{return typeof window<"u"&&((B=window.localStorage)==null?void 0:B.getItem("chat-debug"))==="1"}catch{return!1}})(),L=B=>{var M;try{const J=JSON.parse(JSON.stringify(B));return(M=J==null?void 0:J.payload)!=null&&M.files_info&&Array.isArray(J.payload.files_info)&&(J.payload.files_info=J.payload.files_info.map(F=>({...F,data:F!=null&&F.data?`<base64 ${String(F.data).length} chars>`:F==null?void 0:F.data}))),J}catch{return B}};try{let B={};try{if(n)B={Authorization:`Bearer ${n}`};else if(typeof window<"u"){const _=window.__AUTH_TOKEN__,G=((D=window.localStorage)==null?void 0:D.getItem("authToken"))||null;let j=null;try{const I=($=window.localStorage)==null?void 0:$.getItem("chat-settings");I&&(j=((R=JSON.parse(I))==null?void 0:R.apiKey)||null)}catch{}const Z=_||G||j||null;Z&&(B={Authorization:`Bearer ${Z}`})}}catch{}N&&console.debug("[use-chat] POST",t+r,L(x));const M=await fetch(t+r,{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream",...B,...s.current},body:JSON.stringify(x),signal:O.signal});if(!M.ok||!M.body){const P=await M.text().catch(()=>"");throw N&&console.debug("[use-chat] non-OK response",M.status,P==null?void 0:P.slice(0,500)),new Error(`stream ${M.status}${P?": "+P:""}`)}const J=M.body.getReader(),F=new TextDecoder;let H="";for(;;){const{value:P,done:_}=await J.read();if(_)break;H+=F.decode(P,{stream:!0});let G;for(;(G=H.indexOf(`
|
|
7
7
|
|
|
8
8
|
`))>=0;){const j=H.slice(0,G);H=H.slice(G+2);const Z=df(j);if(!Z)continue;let I;try{I=JSON.parse(Z)}catch{N&&console.debug("[use-chat] skip malformed SSE data:",Z==null?void 0:Z.slice(0,200));continue}const W=lf(I)?I.data:I;if(N&&console.debug("[use-chat] event:",W==null?void 0:W.type,W),C==null||C(W),W.type==="token")e.autoAppendAssistant!==!1&&p(ge=>ge+W.content);else if(W.type==="message_delta"){const ge=W.delta.filter(he=>he.type==="text").map(he=>he.text).join("");ge&&e.autoAppendAssistant!==!1&&p(he=>he+ge)}else W.type==="checkpoint"?v(W.checkpointId):W.type==="error"&&f(W.message)}}}catch(B){if((B==null?void 0:B.name)==="AbortError")return;const M=(B==null?void 0:B.message)||String(B);N&&console.debug("[use-chat] error:",M),f(M),(X=E==null?void 0:E.onError)==null||X.call(E,M)}finally{c(!1),g.current=null}})(),{close:()=>O.abort()}},[t,n,e.autoAppendAssistant]);return T.useEffect(()=>()=>{var x;return(x=g.current)==null?void 0:x.abort()},[]),{isStreaming:a,error:d,assistantText:u,lastCheckpointId:m,stream:y,stop:b,clear:w,setToken:h}}function lf(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function df(e){const t=e.split(/\r?\n/),r=[];for(const n of t)if(n&&!n.startsWith(":")&&n.startsWith("data:")){const o=n.slice(5);r.push(o.startsWith(" ")?o.slice(1):o)}return r.length===0?null:r.join(`
|
|
9
|
-
`)}const uf={messages:[],assemblingId:null,lastCheckpointId:null,toolIndex:{}};function ff(e,t){var r,n;switch(t.type){case"reset":return{messages:Wn(((r=t.payload)==null?void 0:r.messages)??[]),assemblingId:null,lastCheckpointId:null,toolIndex:{}};case"seed":return{...e,messages:Wn(t.payload.messages)};case"prepend":{const o=Wn(t.payload.messages);if(!o.length)return e;const s=new Set(e.messages.map(c=>c.id)),a=o.filter(c=>!s.has(c.id));return a.length?{...e,messages:[...a,...e.messages]}:e}case"user_message":{const o=t.payload.message;if(e.assemblingId){const s=e.messages.findIndex(a=>a.id===e.assemblingId&&a.role==="assistant");if(s>=0){const a=e.messages.slice(0,s),c=e.messages.slice(s);return{...e,messages:[...a,o,...c]}}}return{...e,messages:[...e.messages,o]}}case"event":{const o=t.payload.ev;if(o.type==="message_start"&&o.role==="assistant"){const s=o.id,a=mf(o.model),c={id:s,role:"assistant",name:a||void 0,model:o.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:s,messages:[...e.messages,c]}}if(o.type==="token"){const s=e.assemblingId??Vn(e.messages);return s?{...e,messages:pf(e.messages,s,o.content)}:e}if(o.type==="message_delta"){const s=e.assemblingId??Vn(e.messages);return s?{...e,messages:ta(e.messages,s,o.delta)}:e}if(o.type==="message_end"){const s=e.assemblingId??Vn(e.messages);if(!s)return{...e,assemblingId:null};const a=e.messages,c=a.findIndex(d=>d.id===s&&d.role==="assistant");if(c>=0&&!((n=a[c].content)==null?void 0:n.some(u=>{var p;return(u==null?void 0:u.type)==="text"&&((p=u.text)==null?void 0:p.trim())}))){const u=[...a.slice(0,c),...a.slice(c+1)];return{...e,assemblingId:null,messages:u}}return{...e,assemblingId:null}}if(o.type==="tool_start"){const s=`tool-${o.id}`,a={type:"tool_call",id:o.id,name:o.name,args:o.args},c={id:s,role:"tool",name:o.name,createdAt:new Date().toISOString(),content:[a]};return{...e,messages:[...e.messages,c],toolIndex:{...e.toolIndex,[o.id]:s}}}if(o.type==="tool_result"){const s=e.toolIndex[o.id]??`tool-${o.id}`,a={type:"tool_result",toolCallId:o.id,output:o.output,error:o.error},c=e.messages.find(u=>u.id===s),d={id:s,role:"tool",content:[a],createdAt:new Date().toISOString()},f=c?ta(e.messages,s,[a]):[...e.messages,d];return{...e,messages:f}}if(o.type==="checkpoint"){const s=gf(e.messages,o.checkpointId);return{...e,lastCheckpointId:o.checkpointId,messages:s}}if(o.type==="error"){const s={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${o.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,s]}}return e}default:return e}}function ea(e=[]){const[t,r]=T.useReducer(ff,{...uf,messages:e}),n=T.useCallback(s=>{r({type:"event",payload:{ev:s}})},[]),o=T.useMemo(()=>({reset:s=>r({type:"reset",payload:{messages:s}}),seed:s=>r({type:"seed",payload:{messages:s}}),prepend:s=>r({type:"prepend",payload:{messages:s}}),pushUser:s=>r({type:"user_message",payload:{message:s}}),onEvent:n}),[n]);return{state:t,dispatch:r,...o}}function Wn(e){return e.filter(t=>{if(t.role!=="assistant")return!0;const r=(t.content||[]).some(o=>{var s;return o&&o.type==="text"&&((s=o.text)==null?void 0:s.trim())}),n=(t.content||[]).some(o=>o&&o.type==="image_url");return!!(r||n)})}function Vn(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function pf(e,t,r){return e.map(n=>{if(n.id!==t)return n;const o=n.content.slice(),s=o[o.length-1];return s&&s.type==="text"?s.text+=r:o.push({type:"text",text:r}),{...n,content:o}})}function ta(e,t,r){return e.map(n=>n.id===t?{...n,content:hf(n.content,r)}:n)}function hf(e,t){const r=e.slice();for(const n of t)if(n.type==="text"){const o=r[r.length-1];(o==null?void 0:o.type)==="text"?o.text+=n.text:r.push({type:"text",text:n.text})}else r.push(n);return r}function gf(e,t){for(let r=e.length-1;r>=0;r--)if(e[r].role==="assistant"){const o={...e[r],checkpointId:t};return[...e.slice(0,r),o,...e.slice(r+1)]}return e}function mf(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}const ra=T.createContext(null);function Xt({children:e,apiConfig:t,onError:r,onThreadChange:n,initialThreadId:o=null,historyPageSize:s}){const a=tt;T.useEffect(()=>{t&&a.updateConfig({baseUrl:t.baseUrl,authToken:t.apiKey})},[a,t]);const{isStreaming:c,error:d,stream:f,stop:u,setToken:p}=Qs({baseUrl:a.baseUrl,token:null,headers:t==null?void 0:t.headers,streamPath:"/chat/stream"}),[m,v]=T.useState(()=>typeof a.getAuthToken=="function"?a.getAuthToken():null);T.useEffect(()=>{p(typeof a.getAuthToken=="function"?a.getAuthToken():null);const V=a.onTokenChange(K=>{v(K),p(K)});return()=>{V()}},[a,p]);const g=T.useCallback(V=>{a.setAuthToken(V)},[a]),{state:h,seed:b,prepend:w,pushUser:y,onEvent:x,reset:C}=ea(),E=s&&s>0?s:6,[O,N]=T.useState(!1),[L,D]=T.useState(!1),[$,R]=T.useState(null),[X,B]=T.useState(void 0),M=T.useCallback((V,K)=>{const be=Array.isArray(V==null?void 0:V.messages)?V.messages:[];K==="replace"?b(be):K==="prepend"&&be.length&&w(be),R((V==null?void 0:V.nextCursor)??null),N(!!(V!=null&&V.hasMore)),B(ee=>(V==null?void 0:V.checkpointId)??ee??void 0)},[b,w]),[J,F]=T.useState([]),[H,P]=T.useState(null),_=T.useCallback(async()=>{const V=await a.listThreads();F(V)},[a]);T.useEffect(()=>{_().catch(()=>{})},[_]),T.useEffect(()=>{n==null||n(H)},[H,n]);const G=T.useRef(null);T.useEffect(()=>{o&&G.current!==o&&(G.current=o,Z(o).catch(()=>{}))},[o]);const j=T.useRef(null),Z=T.useCallback(async(V,K,be)=>{var ee;if(j.current!==V){j.current=V;try{const ye=K??((ee=(await a.listCheckpoints(V)).checkpoints.slice().sort((fe,Ne)=>new Date(Ne.createdAt).getTime()-new Date(fe.createdAt).getTime())[0])==null?void 0:ee.checkpointId);N(!1),R(null),B(void 0);const ae=await a.getMessages({threadId:V,checkpointId:ye,checkpointNs:be,limit:E});P(V),M(ae,"replace")}finally{j.current=null}}},[a,M]),I=T.useCallback(async V=>a.listCheckpoints(V),[a]),W=T.useCallback(async V=>{if(!H)throw new Error("No active thread");N(!1),R(null),B(void 0);const K=await a.getMessages({threadId:H,checkpointId:V,limit:E});M(K,"replace")},[a,H,M]),ge=T.useCallback(async()=>{if(!H)throw new Error("No active thread");await Z(H)},[H,Z]),he=T.useRef(!1);T.useEffect(()=>{const V=he.current;if(he.current=c,V&&!c&&H){const K=h.lastCheckpointId??void 0;(async()=>{try{const be=await a.getMessages({threadId:H,checkpointId:K,limit:E});M(be,"replace")}catch{}try{await _()}catch{}})()}},[c,H,h.lastCheckpointId,a,M,_]);const z=T.useCallback(async V=>{const K=await a.createThread(V);return await _(),await Z(K.threadId),K.threadId},[a,_,Z]),ce=T.useCallback(async V=>{await a.deleteThread(V),await _(),H===V&&(P(null),C([]),N(!1),R(null),B(void 0))},[a,_,H,C]),pe=T.useCallback(async(V,K)=>{await a.updateThread(V,K),await _()},[a,_]),le=T.useCallback(async(V,K)=>{var Et;if(!H)throw new Error("No active thread");async function be(ie){return await new Promise((Ie,ke)=>{const Re=new FileReader;Re.onload=()=>Ie(String(Re.result)),Re.onerror=k=>ke(k),Re.readAsDataURL(ie)})}async function ee(ie){return await new Promise((Ie,ke)=>{const Re=new FileReader;Re.onload=()=>{try{const k=Re.result;let Y="";const re=new Uint8Array(k),oe=re.byteLength;for(let ve=0;ve<oe;ve++)Y+=String.fromCharCode(re[ve]);Ie(btoa(Y))}catch(k){ke(k)}},Re.onerror=k=>ke(k),Re.readAsArrayBuffer(ie)})}const ye=[];V&&ye.push({type:"text",text:V});const ae=(K==null?void 0:K.attachments)||[];let fe=[];if(ae.length>0)for(const ie of ae)if(ie.type&&ie.type.startsWith("image/")){let Ie=null;try{const ke=await a.uploadImage(ie,(t==null?void 0:t.uploadPath)||"/upload").catch(()=>null);Ie=(ke==null?void 0:ke.url)||null}catch{}if(!Ie)try{Ie=await be(ie)}catch{Ie=null}if(Ie){const ke={type:"image_url",url:Ie,mimeType:ie.type,alt:ie.name};ye.push(ke)}try{fe.push({filename:ie.name,data:await ee(ie),mime_type:ie.type||"application/octet-stream"})}catch{}}else{const Ie=await be(ie).catch(()=>null),ke={type:"file",url:String(Ie),mimeType:ie.type||void 0,name:ie.name,size:ie.size};ye.push(ke);try{fe.push({filename:ie.name,data:await ee(ie),mime_type:ie.type||"application/octet-stream"})}catch{}}const Ne={id:((Et=crypto.randomUUID)==null?void 0:Et.call(crypto))||`user-${Date.now()}`,role:"user",content:ye,createdAt:new Date().toISOString(),checkpointId:(K==null?void 0:K.checkpointId)??h.lastCheckpointId??void 0};y(Ne);const ot={...Ne,content:Ne.content.filter(ie=>ie.type==="text"||ie.type==="image_url")},as={threadId:H,payload:{messages:[ot],attachments:Ne.content.filter(ie=>ie.type==="file").map(ie=>({type:"file",url:ie.url,mimeType:ie.mimeType,name:ie.name,size:ie.size})),files_info:fe,...(K==null?void 0:K.payloadExtras)??{}},checkpointId:(K==null?void 0:K.checkpointId)??h.lastCheckpointId??void 0,checkpointNs:K==null?void 0:K.checkpointNs,nodeFilter:K==null?void 0:K.nodeFilter,config:K==null?void 0:K.config};f(as,ie=>x(ie),{onError:ie=>console.warn("stream error",ie)})},[H,y,f,x,h.lastCheckpointId,a,t==null?void 0:t.uploadPath]),de=T.useCallback(async V=>{if(!H)throw new Error("No active thread");if(L||!O)return;const K=$;if(K){D(!0);try{const be=await a.getMessages({threadId:H,checkpointId:X,limit:(V==null?void 0:V.limit)??E,beforeId:K});M(be,"prepend")}finally{D(!1)}}},[a,H,X,$,O,L,M]),ue={baseUrl:a.baseUrl,token:m,setToken:g,api:a,threads:J,currentThreadId:H,setCurrentThreadId:P,messages:h.messages,isStreaming:c,error:d,lastCheckpointId:h.lastCheckpointId,streamingAssistantId:h.assemblingId,hasMoreHistory:O,isLoadingHistory:L,loadOlderMessages:de,historyPageSize:E,refreshThreads:_,createThread:z,deleteThread:ce,renameThread:pe,loadThread:Z,listCheckpoints:I,navigateToCheckpoint:W,returnToLatest:ge,send:le,stop:u};return i.jsx(ra.Provider,{value:ue,children:e})}function jn(){const e=T.useContext(ra);if(!e)throw new Error("useChat must be used within ChatProvider");return e}function A(...e){return Fd.twMerge(Ld.clsx(e))}const bf=Wt.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"}}),me=l.forwardRef(({className:e,variant:t,size:r,asChild:n=!1,...o},s)=>{const a=n?Oe.Slot:"button";return i.jsx(a,{className:A(bf({variant:t,size:r,className:e})),ref:s,...o})});me.displayName="Button";const na=l.forwardRef(({className:e,...t},r)=>i.jsx("textarea",{className:A("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}));na.displayName="Textarea";const vf=Wt.cva("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function oa({className:e,variant:t,...r}){return i.jsx("div",{className:A(vf({variant:t}),e),...r})}function U(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 wf(e,t){const r=l.createContext(t),n=s=>{const{children:a,...c}=s,d=l.useMemo(()=>c,Object.values(c));return i.jsx(r.Provider,{value:d,children:a})};n.displayName=e+"Provider";function o(s){const a=l.useContext(r);if(a)return a;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[n,o]}function Ue(e,t=[]){let r=[];function n(s,a){const c=l.createContext(a),d=r.length;r=[...r,a];const f=p=>{var w;const{scope:m,children:v,...g}=p,h=((w=m==null?void 0:m[e])==null?void 0:w[d])||c,b=l.useMemo(()=>g,Object.values(g));return i.jsx(h.Provider,{value:b,children:v})};f.displayName=s+"Provider";function u(p,m){var h;const v=((h=m==null?void 0:m[e])==null?void 0:h[d])||c,g=l.useContext(v);if(g)return g;if(a!==void 0)return a;throw new Error(`\`${p}\` must be used within \`${s}\``)}return[f,u]}const o=()=>{const s=r.map(a=>l.createContext(a));return function(c){const d=(c==null?void 0:c[e])||s;return l.useMemo(()=>({[`__scope${e}`]:{...c,[e]:d}}),[c,d])}};return o.scopeName=e,[n,yf(o,...t)]}function yf(...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 a=n.reduce((c,{useScope:d,scopeName:f})=>{const p=d(s)[`__scope${f}`];return{...c,...p}},{});return l.useMemo(()=>({[`__scope${t.scopeName}`]:a}),[a])}};return r.scopeName=t.scopeName,r}var xe=globalThis!=null&&globalThis.document?l.useLayoutEffect:()=>{},xf=l[" useInsertionEffect ".trim().toString()]||xe;function st({prop:e,defaultProp:t,onChange:r=()=>{},caller:n}){const[o,s,a]=Sf({defaultProp:t,onChange:r}),c=e!==void 0,d=c?e:o;{const u=l.useRef(e!==void 0);l.useEffect(()=>{const p=u.current;p!==c&&console.warn(`${n} is changing from ${p?"controlled":"uncontrolled"} to ${c?"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.`),u.current=c},[c,n])}const f=l.useCallback(u=>{var p;if(c){const m=Cf(u)?u(e):u;m!==e&&((p=a.current)==null||p.call(a,m))}else s(u)},[c,e,s,a]);return[d,f]}function Sf({defaultProp:e,onChange:t}){const[r,n]=l.useState(e),o=l.useRef(r),s=l.useRef(t);return xf(()=>{s.current=t},[t]),l.useEffect(()=>{var a;o.current!==r&&((a=s.current)==null||a.call(s,r),o.current=r)},[r,o]),[r,n,s]}function Cf(e){return typeof e=="function"}function sa(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Rn(...e){return t=>{let r=!1;const n=e.map(o=>{const s=sa(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():sa(e[o],null)}}}}function se(...e){return l.useCallback(Rn(...e),e)}var Ef=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Q=Ef.reduce((e,t)=>{const r=Oe.createSlot(`Primitive.${t}`),n=l.forwardRef((o,s)=>{const{asChild:a,...c}=o,d=a?r:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),i.jsx(d,{...c,ref:s})});return n.displayName=`Primitive.${t}`,{...e,[t]:n}},{});function aa(e,t){e&&hr.flushSync(()=>e.dispatchEvent(t))}function Nf(e,t){return l.useReducer((r,n)=>t[r][n]??r,e)}var _e=e=>{const{present:t,children:r}=e,n=Tf(t),o=typeof r=="function"?r({present:n.isPresent}):l.Children.only(r),s=se(n.ref,Af(o));return typeof r=="function"||n.isPresent?l.cloneElement(o,{ref:s}):null};_e.displayName="Presence";function Tf(e){const[t,r]=l.useState(),n=l.useRef(null),o=l.useRef(e),s=l.useRef("none"),a=e?"mounted":"unmounted",[c,d]=Nf(a,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return l.useEffect(()=>{const f=Ar(n.current);s.current=c==="mounted"?f:"none"},[c]),xe(()=>{const f=n.current,u=o.current;if(u!==e){const m=s.current,v=Ar(f);e?d("MOUNT"):v==="none"||(f==null?void 0:f.display)==="none"?d("UNMOUNT"):d(u&&m!==v?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,d]),xe(()=>{if(t){let f;const u=t.ownerDocument.defaultView??window,p=v=>{const h=Ar(n.current).includes(CSS.escape(v.animationName));if(v.target===t&&h&&(d("ANIMATION_END"),!o.current)){const b=t.style.animationFillMode;t.style.animationFillMode="forwards",f=u.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=b)})}},m=v=>{v.target===t&&(s.current=Ar(n.current))};return t.addEventListener("animationstart",m),t.addEventListener("animationcancel",p),t.addEventListener("animationend",p),()=>{u.clearTimeout(f),t.removeEventListener("animationstart",m),t.removeEventListener("animationcancel",p),t.removeEventListener("animationend",p)}}else d("ANIMATION_END")},[t,d]),{isPresent:["mounted","unmountSuspended"].includes(c),ref:l.useCallback(f=>{n.current=f?getComputedStyle(f):null,r(f)},[])}}function Ar(e){return(e==null?void 0:e.animationName)||"none"}function Af(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)}var Pf=l[" useId ".trim().toString()]||(()=>{}),_f=0;function He(e){const[t,r]=l.useState(Pf());return xe(()=>{r(n=>n??String(_f++))},[e]),t?`radix-${t}`:""}var Pr="Collapsible",[If,Uw]=Ue(Pr),[kf,Kn]=If(Pr),ia=l.forwardRef((e,t)=>{const{__scopeCollapsible:r,open:n,defaultOpen:o,disabled:s,onOpenChange:a,...c}=e,[d,f]=st({prop:n,defaultProp:o??!1,onChange:a,caller:Pr});return i.jsx(kf,{scope:r,disabled:s,contentId:He(),open:d,onOpenToggle:l.useCallback(()=>f(u=>!u),[f]),children:i.jsx(Q.div,{"data-state":qn(d),"data-disabled":s?"":void 0,...c,ref:t})})});ia.displayName=Pr;var ca="CollapsibleTrigger",la=l.forwardRef((e,t)=>{const{__scopeCollapsible:r,...n}=e,o=Kn(ca,r);return i.jsx(Q.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":qn(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...n,ref:t,onClick:U(e.onClick,o.onOpenToggle)})});la.displayName=ca;var Gn="CollapsibleContent",Of=l.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=Kn(Gn,e.__scopeCollapsible);return i.jsx(_e,{present:r||o.open,children:({present:s})=>i.jsx(Mf,{...n,ref:t,present:s})})});Of.displayName=Gn;var Mf=l.forwardRef((e,t)=>{const{__scopeCollapsible:r,present:n,children:o,...s}=e,a=Kn(Gn,r),[c,d]=l.useState(n),f=l.useRef(null),u=se(t,f),p=l.useRef(0),m=p.current,v=l.useRef(0),g=v.current,h=a.open||c,b=l.useRef(h),w=l.useRef(void 0);return l.useEffect(()=>{const y=requestAnimationFrame(()=>b.current=!1);return()=>cancelAnimationFrame(y)},[]),xe(()=>{const y=f.current;if(y){w.current=w.current||{transitionDuration:y.style.transitionDuration,animationName:y.style.animationName},y.style.transitionDuration="0s",y.style.animationName="none";const x=y.getBoundingClientRect();p.current=x.height,v.current=x.width,b.current||(y.style.transitionDuration=w.current.transitionDuration,y.style.animationName=w.current.animationName),d(n)}},[a.open,n]),i.jsx(Q.div,{"data-state":qn(a.open),"data-disabled":a.disabled?"":void 0,id:a.contentId,hidden:!h,...s,ref:u,style:{"--radix-collapsible-content-height":m?`${m}px`:void 0,"--radix-collapsible-content-width":g?`${g}px`:void 0,...e.style},children:h&&o})});function qn(e){return e?"open":"closed"}var Df=ia;const da=Df,ua=la;function Yt({content:e,className:t=""}){const r=T.useMemo(()=>({table:({node:f,className:u,...p})=>i.jsx("div",{className:"max-w-full",children:i.jsx("table",{...p,className:A("w-full table-fixed border-collapse break-words",u)})}),th:({node:f,className:u,...p})=>i.jsx("th",{...p,className:A("break-words whitespace-normal border-b border-border/60 px-3 py-2 text-left align-top",u)}),td:({node:f,className:u,...p})=>i.jsx("td",{...p,className:A("break-words whitespace-normal border-b border-border/30 px-3 py-2 align-top",u)}),pre:({node:f,className:u,...p})=>i.jsx("pre",{...p,className:A("whitespace-pre-wrap break-words",u)}),code:({node:f,className:u,children:p,...m})=>{const{inline:v,...g}=m;return v?i.jsx("code",{...g,className:A("break-words whitespace-normal",u),children:p}):i.jsx("code",{...g,className:A("block break-words whitespace-pre-wrap",u),children:p})}}),[]),n=A("prose prose-sm max-w-none break-words dark:prose-invert leading-relaxed","prose-headings:break-words prose-p:break-words prose-li:break-words prose-td:break-words prose-th:break-words","prose-a:break-all prose-blockquote:break-words prose-strong:break-words prose-em:break-words","prose-code:break-words prose-pre:rounded prose-pre:border prose-pre:bg-background/50","prose-code:bg-background/50 prose-code:px-1 prose-code:py-0.5 prose-code:rounded prose-table:my-4 prose-th:px-2 prose-td:px-2",t);return i.jsx("div",{className:n,style:{wordBreak:"break-word",overflowWrap:"anywhere"},children:i.jsx($d,{remarkPlugins:[Bd],components:r,children:e})})}const _r="prose prose-sm max-w-none break-words dark:prose-invert prose-headings:break-words prose-p:break-words prose-li:break-words prose-td:break-words prose-th:break-words prose-a:break-all prose-code:break-words prose-blockquote:break-words";function Lf({className:e}){const[t,r]=T.useState(0);return T.useEffect(()=>{const n=setInterval(()=>r(o=>(o+1)%4),500);return()=>clearInterval(n)},[]),i.jsxs("span",{"aria-live":"polite",className:A("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}function fa({message:e,messageIndex:t,isStreamingMessage:r=!1,streamingDebounceMs:n=40,isEditing:o=!1,showActions:s=!0,showTimestamp:a=!0,showAgentName:c=!0,layoutSize:d="desktop",truncateToolMessages:f=!0,toolMessagePreviewLength:u=200,truncateUserMessages:p=!0,userMessagePreviewLength:m=200,customStyles:v={},checkpointBranches:g=[],currentCheckpointId:h,onSwitchToCheckpoint:b,onReturnToMainThread:w,temporalNavigation:y,onNavigateToPreviousBranch:x,onNavigateToNextBranch:C,onEdit:E,onRegenerate:O,onEditFromCheckpoint:N,onCancelEdit:L,onCopy:D}){const[$,R]=T.useState(!1),[X,B]=T.useState(!1),[M,J]=T.useState(!1),[F,H]=T.useState(!1),P=d==="phone"||d==="half-screen",_=e.role,G=_==="tool",j=T.useMemo(()=>{switch(_){case"user":return"text-[hsl(var(--chat-bubble-user-text))]";case"assistant":return"text-[hsl(var(--chat-bubble-ai-text))]";case"tool":return"text-secondary-foreground";case"system":return"text-muted-foreground";default:return"text-foreground"}},[_]),Z=T.useMemo(()=>Ff(e.content),[e.content]),I=T.useMemo(()=>Wf(e.content),[e.content]),W=T.useMemo(()=>e.content.filter(ee=>ee.type==="image_url"),[e.content]),ge=T.useMemo(()=>e.content.filter(ee=>ee.type==="file"),[e.content]),he=Rf(Z,r?n:0),z=async()=>{try{const ee=G?Pt(e.content):Z;await navigator.clipboard.writeText(ee),R(!0),setTimeout(()=>R(!1),2e3),D==null||D(ee)}catch(ee){console.error("Failed to copy:",ee)}},ce=()=>{if(!E)return;const ee=G?Pt(e.content):Z;E(e.id,ee)},pe=()=>O==null?void 0:O(t),le=()=>{const ye=A(P?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",j);switch(_){case"user":return i.jsx(q.User,{className:ye});case"assistant":return i.jsx(q.Bot,{className:ye});case"tool":return i.jsx(q.Wrench,{className:ye});default:return i.jsx(q.Bot,{className:ye})}},de=()=>{const ee="group relative mb-4 max-w-full";switch(_){case"user":return A(ee,"flex justify-end");case"assistant":case"tool":case"system":return A(ee,"flex justify-start");default:return ee}},ue=()=>{const ee=A("rounded-lg px-4 py-3 relative transition-all duration-200 min-w-0 break-words",P&&"px-3 py-2 text-sm");switch(_){case"user":return A(ee,"max-w-[95%]",d==="phone"&&"max-w-[98%]","bg-[hsl(var(--chat-bubble-user))] text-[hsl(var(--chat-bubble-user-text))]","border border-transparent");case"assistant":return A(ee,"max-w-[95%]",d==="phone"&&"max-w-[98%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40");case"tool":return A(ee,"bg-secondary/50 text-secondary-foreground border border-dashed max-w-[95%]",d==="phone"&&"max-w-[98%]");case"system":return A(ee,"bg-accent/40 text-muted-foreground max-w-[85%] border");default:return ee}},V=ee=>{if(!ee)return"";try{return new Date(ee).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return""}},K=()=>{if(e.model==="reflection"){const ae=Z.trim(),fe=Xn(ae);if(fe&&typeof fe=="object")return i.jsx(Kf,{data:fe})}if(G&&I.name==="get_issues"){const ae=e.content.find(ot=>ot.type==="tool_result"),fe=(ae==null?void 0:ae.output)??Pt(e.content),Ne=ha(fe);if(Ne)return i.jsx(Gf,{issues:Ne})}if(G&&!M){const ae=Pt(e.content).slice(0,80).replace(/\s+/g," ");return i.jsx("div",{className:A("text-xs font-mono opacity-70 flex items-center justify-between gap-2 text-current",P&&"text-[10px]"),children:i.jsxs("span",{className:"truncate max-w-full text-current",children:[ae,ae.length>=80?"…":""]})})}if(G&&f){const ae=Pt(e.content),fe=ae.length>u;return i.jsx(da,{open:X,onOpenChange:B,children:i.jsxs("div",{className:"font-mono text-sm text-current",children:[i.jsx("pre",{className:A("whitespace-pre-wrap break-words text-current",P&&"text-xs"),children:fe&&!X?ae.substring(0,u)+"...":ae}),fe&&i.jsx(ua,{asChild:!0,children:i.jsx(me,{variant:"ghost",size:"sm",className:"h-6 text-xs text-current",children:X?i.jsxs(i.Fragment,{children:[i.jsx(q.ChevronUp,{className:"h-3 w-3 mr-1"}),"Show less"]}):i.jsxs(i.Fragment,{children:[i.jsx(q.ChevronDown,{className:"h-3 w-3 mr-1"}),"Show more (",ae.length-u," chars)"]})})})]})})}if(G&&M&&!f){const ae=zf(e.content);if(ae&&$f(ae))return i.jsx(Yt,{content:ae.trim()});const fe=Pt(e.content);return i.jsx("div",{className:"font-mono text-sm text-current",children:i.jsx("pre",{className:A("whitespace-pre-wrap break-words text-current",P&&"text-xs"),children:fe})})}const ee=W.length>0&&_!=="tool",ye=ge.length>0&&_!=="tool";return i.jsxs("div",{children:[r?i.jsxs("div",{className:"relative",children:[(()=>{const ae=Xn(he);return ae!==null?i.jsx(pa,{data:ae}):i.jsx(Yt,{content:Uf(Bf(he))})})(),i.jsx(Lf,{className:A(j,P?"text-xs":"text-sm")})]}):(()=>{const ae=Xn(Z.trim());if(ae!==null)return i.jsx(pa,{data:ae});if(_==="user"&&p){const fe=Z.trim();if(fe.length>m)return i.jsxs(da,{open:F,onOpenChange:H,children:[i.jsx("div",{className:A("text-sm text-[hsl(var(--chat-bubble-user-text))]",P&&"text-xs"),children:F?i.jsx(Yt,{content:fe}):i.jsxs("pre",{className:A("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",P&&"text-xs"),children:[fe.substring(0,m),"..."]})}),i.jsx(ua,{asChild:!0,children:i.jsx(me,{variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",children:F?i.jsxs(i.Fragment,{children:[i.jsx(q.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):i.jsxs(i.Fragment,{children:[i.jsx(q.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",fe.length-m," chars)"]})})})]})}return i.jsx(Yt,{content:Z.trim()})})(),ee&&i.jsx("div",{className:"mt-2 grid grid-cols-2 gap-2",children:W.map((ae,fe)=>i.jsxs("div",{className:"relative border rounded overflow-hidden",children:[i.jsx("img",{src:ae.url,alt:ae.alt??"image",className:"w-full h-auto"}),i.jsxs("div",{className:"absolute top-1 right-1 bg-background/70 rounded px-1 py-0.5 text-[10px] flex items-center gap-1",children:[i.jsx(q.Image,{className:"h-3 w-3"}),i.jsx("span",{children:"image"})]})]},fe))}),ye&&i.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:ge.map((ae,fe)=>{const Ne=ae,ot=Ne.name||"file";return i.jsxs("a",{href:Ne.url,download:ot,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-2 bg-gray-100 border border-gray-200 rounded px-2 py-1 text-xs hover:bg-gray-200",title:ot,children:[i.jsx("span",{className:"inline-block w-1.5 h-1.5 rounded-full bg-gray-400"}),i.jsx("span",{className:"truncate max-w-[180px]",children:ot})]},fe)})})]})},be=T.useMemo(()=>Vf(e),[e]);return T.useMemo(()=>jf(e,h),[e,h]),i.jsx("div",{className:A(de(),v.container),children:i.jsxs("div",{className:A(ue(),v.content),children:[(a||c||G)&&i.jsxs("div",{className:A("flex items-center justify-between mb-2 pb-2 border-b border-current/10",P&&"mb-1 pb-1",j,v.header),children:[i.jsxs("div",{className:"flex items-center gap-2",children:[le(),c&&be&&i.jsx("span",{className:A("font-medium",P?"text-xs":"text-sm"),children:be}),G&&I.name&&i.jsxs(oa,{variant:"outline",className:A("text-xs flex items-center gap-1 cursor-pointer",j,"border border-current/40",P&&"text-xs h-4"),onClick:()=>J(ee=>!ee),children:[i.jsx("span",{children:I.name}),i.jsx("span",{className:"inline-flex items-center",children:M?i.jsx(q.ChevronUp,{className:"h-3 w-3"}):i.jsx(q.ChevronDown,{className:"h-3 w-3"})})]}),G&&!I.name&&i.jsx(me,{variant:"ghost",size:"sm",className:A("h-6 px-1",j,"hover:bg-foreground/10"),onClick:()=>J(ee=>!ee),children:i.jsxs("span",{className:"text-xs flex items-center gap-1",children:["Tool Output ",M?i.jsx(q.ChevronUp,{className:"h-3 w-3"}):i.jsx(q.ChevronDown,{className:"h-3 w-3"})]})})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[a&&i.jsx("span",{className:A("text-xs opacity-60",j,P&&"text-xs"),children:V(e.createdAt)}),s&&!o&&i.jsxs("div",{className:A("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",v.actions),children:[i.jsx(me,{variant:"ghost",size:"sm",onClick:z,className:A("h-6 w-6 p-0 hover:bg-foreground/10",j,P&&"h-5 w-5"),children:i.jsx(q.Copy,{className:A($?"text-success":j,P?"h-3 w-3":"h-4 w-4")})}),_==="user"&&E&&i.jsx(me,{variant:"ghost",size:"sm",onClick:ce,className:A("h-6 w-6 p-0 hover:bg-foreground/10",j,P&&"h-5 w-5"),children:i.jsx(q.Edit,{className:A(j,P?"h-3 w-3":"h-4 w-4")})}),_==="assistant"&&O&&i.jsx(me,{variant:"ghost",size:"sm",onClick:pe,className:A("h-6 w-6 p-0 hover:bg-foreground/10",j,P&&"h-5 w-5"),children:i.jsx(q.RotateCcw,{className:A(j,P?"h-3 w-3":"h-4 w-4")})})]})]})]}),i.jsx("div",{className:"relative",children:K()}),G&&M&&(I.toolCallId||I.name)&&i.jsxs("div",{className:A("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",P&&"text-xs"),children:[I.name&&i.jsxs("div",{children:["Function: ",I.name]}),I.toolCallId&&i.jsxs("div",{children:["Call ID: ",I.toolCallId]})]}),s&&_==="user"&&y&&y.totalBranches>1&&i.jsxs("div",{className:"flex items-center gap-2 mt-2 p-2 bg-muted/30 rounded border",children:[i.jsx(q.GitBranch,{className:"h-3 w-3 text-muted-foreground"}),i.jsxs("span",{className:"text-xs text-muted-foreground",children:["Branch ",y.currentIndex+1," of ",y.totalBranches]}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx(me,{variant:"ghost",size:"sm",className:A("h-6 w-6 p-0",j),disabled:!y.canGoBack,onClick:()=>x==null?void 0:x(),title:"Go back to previous branch",children:i.jsx(q.ChevronLeft,{className:A("h-3 w-3",j)})}),i.jsx(me,{variant:"ghost",size:"sm",className:A("h-6 w-6 p-0",j),disabled:!y.canGoForward,onClick:()=>C==null?void 0:C(),title:"Go forward to next branch",children:i.jsx(q.ChevronRight,{className:A("h-3 w-3",j)})})]})]}),!(a||c||G)&&s&&!o&&i.jsxs("div",{className:A("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",v.actions),children:[i.jsx(me,{variant:"ghost",size:"sm",onClick:z,className:A("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:i.jsx(q.Copy,{className:A($?"text-success":"text-current",P?"h-3 w-3":"h-4 w-4")})}),_==="user"&&E&&i.jsx(me,{variant:"ghost",size:"sm",onClick:ce,className:A("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:i.jsx(q.Edit,{className:A("text-current",P?"h-3 w-3":"h-4 w-4")})}),_==="assistant"&&O&&i.jsx(me,{variant:"ghost",size:"sm",onClick:pe,className:A("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:i.jsx(q.RotateCcw,{className:A("text-current",P?"h-3 w-3":"h-4 w-4")})})]})]})})}function Ff(e){const t=e.filter(r=>r.type==="text").map(r=>r.text).join("");return t||JSON.stringify(e)}function $f(e){return e.includes(`
|
|
9
|
+
`)}const uf={messages:[],assemblingId:null,lastCheckpointId:null,toolIndex:{}};function ff(e,t){var r,n;switch(t.type){case"reset":return{messages:Wn(((r=t.payload)==null?void 0:r.messages)??[]),assemblingId:null,lastCheckpointId:null,toolIndex:{}};case"seed":return{...e,messages:Wn(t.payload.messages)};case"prepend":{const o=Wn(t.payload.messages);if(!o.length)return e;const s=new Set(e.messages.map(c=>c.id)),a=o.filter(c=>!s.has(c.id));return a.length?{...e,messages:[...a,...e.messages]}:e}case"user_message":{const o=t.payload.message;if(e.assemblingId){const s=e.messages.findIndex(a=>a.id===e.assemblingId&&a.role==="assistant");if(s>=0){const a=e.messages.slice(0,s),c=e.messages.slice(s);return{...e,messages:[...a,o,...c]}}}return{...e,messages:[...e.messages,o]}}case"event":{const o=t.payload.ev;if(o.type==="message_start"&&o.role==="assistant"){const s=o.id,a=mf(o.model),c={id:s,role:"assistant",name:a||void 0,model:o.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:s,messages:[...e.messages,c]}}if(o.type==="token"){const s=e.assemblingId??Vn(e.messages);return s?{...e,messages:pf(e.messages,s,o.content)}:e}if(o.type==="message_delta"){const s=e.assemblingId??Vn(e.messages);return s?{...e,messages:ta(e.messages,s,o.delta)}:e}if(o.type==="message_end"){const s=e.assemblingId??Vn(e.messages);if(!s)return{...e,assemblingId:null};const a=e.messages,c=a.findIndex(d=>d.id===s&&d.role==="assistant");if(c>=0&&!((n=a[c].content)==null?void 0:n.some(u=>{var p;return(u==null?void 0:u.type)==="text"&&((p=u.text)==null?void 0:p.trim())}))){const u=[...a.slice(0,c),...a.slice(c+1)];return{...e,assemblingId:null,messages:u}}return{...e,assemblingId:null}}if(o.type==="tool_start"){const s=`tool-${o.id}`,a={type:"tool_call",id:o.id,name:o.name,args:o.args},c={id:s,role:"tool",name:o.name,createdAt:new Date().toISOString(),content:[a]};return{...e,messages:[...e.messages,c],toolIndex:{...e.toolIndex,[o.id]:s}}}if(o.type==="tool_result"){const s=e.toolIndex[o.id]??`tool-${o.id}`,a={type:"tool_result",toolCallId:o.id,output:o.output,error:o.error},c=e.messages.find(u=>u.id===s),d={id:s,role:"tool",content:[a],createdAt:new Date().toISOString()},f=c?ta(e.messages,s,[a]):[...e.messages,d];return{...e,messages:f}}if(o.type==="checkpoint"){const s=gf(e.messages,o.checkpointId);return{...e,lastCheckpointId:o.checkpointId,messages:s}}if(o.type==="error"){const s={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${o.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,s]}}return e}default:return e}}function ea(e=[]){const[t,r]=T.useReducer(ff,{...uf,messages:e}),n=T.useCallback(s=>{r({type:"event",payload:{ev:s}})},[]),o=T.useMemo(()=>({reset:s=>r({type:"reset",payload:{messages:s}}),seed:s=>r({type:"seed",payload:{messages:s}}),prepend:s=>r({type:"prepend",payload:{messages:s}}),pushUser:s=>r({type:"user_message",payload:{message:s}}),onEvent:n}),[n]);return{state:t,dispatch:r,...o}}function Wn(e){return e.filter(t=>{if(t.role!=="assistant")return!0;const r=(t.content||[]).some(o=>{var s;return o&&o.type==="text"&&((s=o.text)==null?void 0:s.trim())}),n=(t.content||[]).some(o=>o&&o.type==="image_url");return!!(r||n)})}function Vn(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function pf(e,t,r){return e.map(n=>{if(n.id!==t)return n;const o=n.content.slice(),s=o[o.length-1];return s&&s.type==="text"?s.text+=r:o.push({type:"text",text:r}),{...n,content:o}})}function ta(e,t,r){return e.map(n=>n.id===t?{...n,content:hf(n.content,r)}:n)}function hf(e,t){const r=e.slice();for(const n of t)if(n.type==="text"){const o=r[r.length-1];(o==null?void 0:o.type)==="text"?o.text+=n.text:r.push({type:"text",text:n.text})}else r.push(n);return r}function gf(e,t){for(let r=e.length-1;r>=0;r--)if(e[r].role==="assistant"){const o={...e[r],checkpointId:t};return[...e.slice(0,r),o,...e.slice(r+1)]}return e}function mf(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}const ra=T.createContext(null);function Xt({children:e,apiConfig:t,onError:r,onThreadChange:n,initialThreadId:o=null,historyPageSize:s}){const a=tt;T.useEffect(()=>{t&&a.updateConfig({baseUrl:t.baseUrl,authToken:t.apiKey})},[a,t]);const{isStreaming:c,error:d,stream:f,stop:u,setToken:p}=Qs({baseUrl:a.baseUrl,token:null,headers:t==null?void 0:t.headers,streamPath:"/chat/stream"}),[m,v]=T.useState(()=>typeof a.getAuthToken=="function"?a.getAuthToken():null);T.useEffect(()=>{p(typeof a.getAuthToken=="function"?a.getAuthToken():null);const V=a.onTokenChange(K=>{v(K),p(K)});return()=>{V()}},[a,p]);const g=T.useCallback(V=>{a.setAuthToken(V)},[a]),{state:h,seed:b,prepend:w,pushUser:y,onEvent:x,reset:C}=ea(),E=s&&s>0?s:6,[O,N]=T.useState(!1),[L,D]=T.useState(!1),[$,R]=T.useState(null),[X,B]=T.useState(void 0),M=T.useCallback((V,K)=>{const be=Array.isArray(V==null?void 0:V.messages)?V.messages:[];K==="replace"?b(be):K==="prepend"&&be.length&&w(be),R((V==null?void 0:V.nextCursor)??null),N(!!(V!=null&&V.hasMore)),B(ee=>(V==null?void 0:V.checkpointId)??ee??void 0)},[b,w]),[J,F]=T.useState([]),[H,P]=T.useState(null),_=T.useCallback(async()=>{const V=await a.listThreads();F(V)},[a]);T.useEffect(()=>{_().catch(()=>{})},[_]),T.useEffect(()=>{n==null||n(H)},[H,n]);const G=T.useRef(null);T.useEffect(()=>{o&&G.current!==o&&(G.current=o,Z(o).catch(()=>{}))},[o]);const j=T.useRef(null),Z=T.useCallback(async(V,K,be)=>{var ee;if(j.current!==V){j.current=V;try{const ye=K??((ee=(await a.listCheckpoints(V)).checkpoints.slice().sort((fe,Ne)=>new Date(Ne.createdAt).getTime()-new Date(fe.createdAt).getTime())[0])==null?void 0:ee.checkpointId);N(!1),R(null),B(void 0);const ae=await a.getMessages({threadId:V,checkpointId:ye,checkpointNs:be,limit:E});P(V),M(ae,"replace")}finally{j.current=null}}},[a,M]),I=T.useCallback(async V=>a.listCheckpoints(V),[a]),W=T.useCallback(async V=>{if(!H)throw new Error("No active thread");N(!1),R(null),B(void 0);const K=await a.getMessages({threadId:H,checkpointId:V,limit:E});M(K,"replace")},[a,H,M]),ge=T.useCallback(async()=>{if(!H)throw new Error("No active thread");await Z(H)},[H,Z]),he=T.useRef(!1);T.useEffect(()=>{const V=he.current;if(he.current=c,V&&!c&&H){const K=h.lastCheckpointId??void 0;(async()=>{try{const be=await a.getMessages({threadId:H,checkpointId:K,limit:E});M(be,"replace")}catch{}try{await _()}catch{}})()}},[c,H,h.lastCheckpointId,a,M,_]);const z=T.useCallback(async V=>{const K=await a.createThread(V);return await _(),await Z(K.threadId),K.threadId},[a,_,Z]),ce=T.useCallback(async V=>{await a.deleteThread(V),await _(),H===V&&(P(null),C([]),N(!1),R(null),B(void 0))},[a,_,H,C]),pe=T.useCallback(async(V,K)=>{await a.updateThread(V,K),await _()},[a,_]),le=T.useCallback(async(V,K)=>{var Et;if(!H)throw new Error("No active thread");async function be(ie){return await new Promise((Ie,ke)=>{const Re=new FileReader;Re.onload=()=>Ie(String(Re.result)),Re.onerror=k=>ke(k),Re.readAsDataURL(ie)})}async function ee(ie){return await new Promise((Ie,ke)=>{const Re=new FileReader;Re.onload=()=>{try{const k=Re.result;let Y="";const re=new Uint8Array(k),oe=re.byteLength;for(let ve=0;ve<oe;ve++)Y+=String.fromCharCode(re[ve]);Ie(btoa(Y))}catch(k){ke(k)}},Re.onerror=k=>ke(k),Re.readAsArrayBuffer(ie)})}const ye=[];V&&ye.push({type:"text",text:V});const ae=(K==null?void 0:K.attachments)||[];let fe=[];if(ae.length>0)for(const ie of ae)if(ie.type&&ie.type.startsWith("image/")){let Ie=null;try{const ke=await a.uploadImage(ie,(t==null?void 0:t.uploadPath)||"/upload").catch(()=>null);Ie=(ke==null?void 0:ke.url)||null}catch{}if(!Ie)try{Ie=await be(ie)}catch{Ie=null}if(Ie){const ke={type:"image_url",url:Ie,mimeType:ie.type,alt:ie.name};ye.push(ke)}try{fe.push({filename:ie.name,data:await ee(ie),mime_type:ie.type||"application/octet-stream"})}catch{}}else{const Ie=await be(ie).catch(()=>null),ke={type:"file",url:String(Ie),mimeType:ie.type||void 0,name:ie.name,size:ie.size};ye.push(ke);try{fe.push({filename:ie.name,data:await ee(ie),mime_type:ie.type||"application/octet-stream"})}catch{}}const Ne={id:((Et=crypto.randomUUID)==null?void 0:Et.call(crypto))||`user-${Date.now()}`,role:"user",content:ye,createdAt:new Date().toISOString(),checkpointId:(K==null?void 0:K.checkpointId)??h.lastCheckpointId??void 0};y(Ne);const ot={...Ne,content:Ne.content.filter(ie=>ie.type==="text"||ie.type==="image_url")},as={threadId:H,payload:{messages:[ot],attachments:Ne.content.filter(ie=>ie.type==="file").map(ie=>({type:"file",url:ie.url,mimeType:ie.mimeType,name:ie.name,size:ie.size})),files_info:fe,...(K==null?void 0:K.payloadExtras)??{}},checkpointId:(K==null?void 0:K.checkpointId)??h.lastCheckpointId??void 0,checkpointNs:K==null?void 0:K.checkpointNs,nodeFilter:K==null?void 0:K.nodeFilter,config:K==null?void 0:K.config};f(as,ie=>x(ie),{onError:ie=>console.warn("stream error",ie)})},[H,y,f,x,h.lastCheckpointId,a,t==null?void 0:t.uploadPath]),de=T.useCallback(async V=>{if(!H)throw new Error("No active thread");if(L||!O)return;const K=$;if(K){D(!0);try{const be=await a.getMessages({threadId:H,checkpointId:X,limit:(V==null?void 0:V.limit)??E,beforeId:K});M(be,"prepend")}finally{D(!1)}}},[a,H,X,$,O,L,M]),ue={baseUrl:a.baseUrl,token:m,setToken:g,api:a,threads:J,currentThreadId:H,setCurrentThreadId:P,messages:h.messages,isStreaming:c,error:d,lastCheckpointId:h.lastCheckpointId,streamingAssistantId:h.assemblingId,hasMoreHistory:O,isLoadingHistory:L,loadOlderMessages:de,historyPageSize:E,refreshThreads:_,createThread:z,deleteThread:ce,renameThread:pe,loadThread:Z,listCheckpoints:I,navigateToCheckpoint:W,returnToLatest:ge,send:le,stop:u};return i.jsx(ra.Provider,{value:ue,children:e})}function jn(){const e=T.useContext(ra);if(!e)throw new Error("useChat must be used within ChatProvider");return e}function A(...e){return Fd.twMerge(Ld.clsx(e))}const bf=Wt.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"}}),me=l.forwardRef(({className:e,variant:t,size:r,asChild:n=!1,...o},s)=>{const a=n?Oe.Slot:"button";return i.jsx(a,{className:A(bf({variant:t,size:r,className:e})),ref:s,...o})});me.displayName="Button";const na=l.forwardRef(({className:e,...t},r)=>i.jsx("textarea",{className:A("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}));na.displayName="Textarea";const vf=Wt.cva("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function oa({className:e,variant:t,...r}){return i.jsx("div",{className:A(vf({variant:t}),e),...r})}function U(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 wf(e,t){const r=l.createContext(t),n=s=>{const{children:a,...c}=s,d=l.useMemo(()=>c,Object.values(c));return i.jsx(r.Provider,{value:d,children:a})};n.displayName=e+"Provider";function o(s){const a=l.useContext(r);if(a)return a;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[n,o]}function Ue(e,t=[]){let r=[];function n(s,a){const c=l.createContext(a),d=r.length;r=[...r,a];const f=p=>{var w;const{scope:m,children:v,...g}=p,h=((w=m==null?void 0:m[e])==null?void 0:w[d])||c,b=l.useMemo(()=>g,Object.values(g));return i.jsx(h.Provider,{value:b,children:v})};f.displayName=s+"Provider";function u(p,m){var h;const v=((h=m==null?void 0:m[e])==null?void 0:h[d])||c,g=l.useContext(v);if(g)return g;if(a!==void 0)return a;throw new Error(`\`${p}\` must be used within \`${s}\``)}return[f,u]}const o=()=>{const s=r.map(a=>l.createContext(a));return function(c){const d=(c==null?void 0:c[e])||s;return l.useMemo(()=>({[`__scope${e}`]:{...c,[e]:d}}),[c,d])}};return o.scopeName=e,[n,yf(o,...t)]}function yf(...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 a=n.reduce((c,{useScope:d,scopeName:f})=>{const p=d(s)[`__scope${f}`];return{...c,...p}},{});return l.useMemo(()=>({[`__scope${t.scopeName}`]:a}),[a])}};return r.scopeName=t.scopeName,r}var xe=globalThis!=null&&globalThis.document?l.useLayoutEffect:()=>{},xf=l[" useInsertionEffect ".trim().toString()]||xe;function st({prop:e,defaultProp:t,onChange:r=()=>{},caller:n}){const[o,s,a]=Sf({defaultProp:t,onChange:r}),c=e!==void 0,d=c?e:o;{const u=l.useRef(e!==void 0);l.useEffect(()=>{const p=u.current;p!==c&&console.warn(`${n} is changing from ${p?"controlled":"uncontrolled"} to ${c?"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.`),u.current=c},[c,n])}const f=l.useCallback(u=>{var p;if(c){const m=Cf(u)?u(e):u;m!==e&&((p=a.current)==null||p.call(a,m))}else s(u)},[c,e,s,a]);return[d,f]}function Sf({defaultProp:e,onChange:t}){const[r,n]=l.useState(e),o=l.useRef(r),s=l.useRef(t);return xf(()=>{s.current=t},[t]),l.useEffect(()=>{var a;o.current!==r&&((a=s.current)==null||a.call(s,r),o.current=r)},[r,o]),[r,n,s]}function Cf(e){return typeof e=="function"}function sa(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Rn(...e){return t=>{let r=!1;const n=e.map(o=>{const s=sa(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():sa(e[o],null)}}}}function se(...e){return l.useCallback(Rn(...e),e)}var Ef=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Q=Ef.reduce((e,t)=>{const r=Oe.createSlot(`Primitive.${t}`),n=l.forwardRef((o,s)=>{const{asChild:a,...c}=o,d=a?r:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),i.jsx(d,{...c,ref:s})});return n.displayName=`Primitive.${t}`,{...e,[t]:n}},{});function aa(e,t){e&&hr.flushSync(()=>e.dispatchEvent(t))}function Nf(e,t){return l.useReducer((r,n)=>t[r][n]??r,e)}var _e=e=>{const{present:t,children:r}=e,n=Tf(t),o=typeof r=="function"?r({present:n.isPresent}):l.Children.only(r),s=se(n.ref,Af(o));return typeof r=="function"||n.isPresent?l.cloneElement(o,{ref:s}):null};_e.displayName="Presence";function Tf(e){const[t,r]=l.useState(),n=l.useRef(null),o=l.useRef(e),s=l.useRef("none"),a=e?"mounted":"unmounted",[c,d]=Nf(a,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return l.useEffect(()=>{const f=Ar(n.current);s.current=c==="mounted"?f:"none"},[c]),xe(()=>{const f=n.current,u=o.current;if(u!==e){const m=s.current,v=Ar(f);e?d("MOUNT"):v==="none"||(f==null?void 0:f.display)==="none"?d("UNMOUNT"):d(u&&m!==v?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,d]),xe(()=>{if(t){let f;const u=t.ownerDocument.defaultView??window,p=v=>{const h=Ar(n.current).includes(CSS.escape(v.animationName));if(v.target===t&&h&&(d("ANIMATION_END"),!o.current)){const b=t.style.animationFillMode;t.style.animationFillMode="forwards",f=u.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=b)})}},m=v=>{v.target===t&&(s.current=Ar(n.current))};return t.addEventListener("animationstart",m),t.addEventListener("animationcancel",p),t.addEventListener("animationend",p),()=>{u.clearTimeout(f),t.removeEventListener("animationstart",m),t.removeEventListener("animationcancel",p),t.removeEventListener("animationend",p)}}else d("ANIMATION_END")},[t,d]),{isPresent:["mounted","unmountSuspended"].includes(c),ref:l.useCallback(f=>{n.current=f?getComputedStyle(f):null,r(f)},[])}}function Ar(e){return(e==null?void 0:e.animationName)||"none"}function Af(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)}var Pf=l[" useId ".trim().toString()]||(()=>{}),_f=0;function He(e){const[t,r]=l.useState(Pf());return xe(()=>{r(n=>n??String(_f++))},[e]),t?`radix-${t}`:""}var Pr="Collapsible",[If,Uw]=Ue(Pr),[kf,Kn]=If(Pr),ia=l.forwardRef((e,t)=>{const{__scopeCollapsible:r,open:n,defaultOpen:o,disabled:s,onOpenChange:a,...c}=e,[d,f]=st({prop:n,defaultProp:o??!1,onChange:a,caller:Pr});return i.jsx(kf,{scope:r,disabled:s,contentId:He(),open:d,onOpenToggle:l.useCallback(()=>f(u=>!u),[f]),children:i.jsx(Q.div,{"data-state":qn(d),"data-disabled":s?"":void 0,...c,ref:t})})});ia.displayName=Pr;var ca="CollapsibleTrigger",la=l.forwardRef((e,t)=>{const{__scopeCollapsible:r,...n}=e,o=Kn(ca,r);return i.jsx(Q.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":qn(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...n,ref:t,onClick:U(e.onClick,o.onOpenToggle)})});la.displayName=ca;var Gn="CollapsibleContent",Of=l.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=Kn(Gn,e.__scopeCollapsible);return i.jsx(_e,{present:r||o.open,children:({present:s})=>i.jsx(Mf,{...n,ref:t,present:s})})});Of.displayName=Gn;var Mf=l.forwardRef((e,t)=>{const{__scopeCollapsible:r,present:n,children:o,...s}=e,a=Kn(Gn,r),[c,d]=l.useState(n),f=l.useRef(null),u=se(t,f),p=l.useRef(0),m=p.current,v=l.useRef(0),g=v.current,h=a.open||c,b=l.useRef(h),w=l.useRef(void 0);return l.useEffect(()=>{const y=requestAnimationFrame(()=>b.current=!1);return()=>cancelAnimationFrame(y)},[]),xe(()=>{const y=f.current;if(y){w.current=w.current||{transitionDuration:y.style.transitionDuration,animationName:y.style.animationName},y.style.transitionDuration="0s",y.style.animationName="none";const x=y.getBoundingClientRect();p.current=x.height,v.current=x.width,b.current||(y.style.transitionDuration=w.current.transitionDuration,y.style.animationName=w.current.animationName),d(n)}},[a.open,n]),i.jsx(Q.div,{"data-state":qn(a.open),"data-disabled":a.disabled?"":void 0,id:a.contentId,hidden:!h,...s,ref:u,style:{"--radix-collapsible-content-height":m?`${m}px`:void 0,"--radix-collapsible-content-width":g?`${g}px`:void 0,...e.style},children:h&&o})});function qn(e){return e?"open":"closed"}var Df=ia;const da=Df,ua=la;function Yt({content:e,className:t=""}){const r=T.useMemo(()=>({table:({node:f,className:u,...p})=>i.jsx("div",{className:"max-w-full",children:i.jsx("table",{...p,className:A("w-full table-fixed border-collapse break-words",u)})}),th:({node:f,className:u,...p})=>i.jsx("th",{...p,className:A("break-words whitespace-normal border-b border-border/60 px-3 py-2 text-left align-top",u)}),td:({node:f,className:u,...p})=>i.jsx("td",{...p,className:A("break-words whitespace-normal border-b border-border/30 px-3 py-2 align-top",u)}),pre:({node:f,className:u,...p})=>i.jsx("pre",{...p,className:A("whitespace-pre-wrap break-words",u)}),code:({node:f,className:u,children:p,...m})=>{const{inline:v,...g}=m;return v?i.jsx("code",{...g,className:A("break-words whitespace-normal",u),children:p}):i.jsx("code",{...g,className:A("block break-words whitespace-pre-wrap",u),children:p})}}),[]),n=A("prose prose-sm max-w-none break-words dark:prose-invert leading-relaxed","prose-headings:break-words prose-p:break-words prose-li:break-words prose-td:break-words prose-th:break-words","prose-a:break-all prose-blockquote:break-words prose-strong:break-words prose-em:break-words","prose-code:break-words prose-pre:rounded prose-pre:border prose-pre:bg-background/50","prose-code:bg-background/50 prose-code:px-1 prose-code:py-0.5 prose-code:rounded prose-table:my-4 prose-th:px-2 prose-td:px-2",t);return i.jsx("div",{className:n,style:{wordBreak:"break-word",overflowWrap:"anywhere"},children:i.jsx($d,{remarkPlugins:[Bd],components:r,children:e})})}const _r="prose prose-sm max-w-none break-words dark:prose-invert prose-headings:break-words prose-p:break-words prose-li:break-words prose-td:break-words prose-th:break-words prose-a:break-all prose-code:break-words prose-blockquote:break-words";function Lf({className:e}){const[t,r]=T.useState(0);return T.useEffect(()=>{const n=setInterval(()=>r(o=>(o+1)%4),500);return()=>clearInterval(n)},[]),i.jsxs("span",{"aria-live":"polite",className:A("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}function fa({message:e,messageIndex:t,isStreamingMessage:r=!1,streamingDebounceMs:n=40,isEditing:o=!1,showActions:s=!0,showTimestamp:a=!0,showAgentName:c=!0,layoutSize:d="desktop",truncateToolMessages:f=!0,toolMessagePreviewLength:u=200,truncateUserMessages:p=!0,userMessagePreviewLength:m=200,customStyles:v={},checkpointBranches:g=[],currentCheckpointId:h,onSwitchToCheckpoint:b,onReturnToMainThread:w,temporalNavigation:y,onNavigateToPreviousBranch:x,onNavigateToNextBranch:C,onEdit:E,onRegenerate:O,onEditFromCheckpoint:N,onCancelEdit:L,onCopy:D}){const[$,R]=T.useState(!1),[X,B]=T.useState(!1),[M,J]=T.useState(!1),[F,H]=T.useState(!1),P=d==="phone"||d==="half-screen",_=e.role,G=_==="tool",j=T.useMemo(()=>{switch(_){case"user":return"text-[hsl(var(--chat-bubble-user-text))]";case"assistant":return"text-[hsl(var(--chat-bubble-ai-text))]";case"tool":return"text-secondary-foreground";case"system":return"text-muted-foreground";default:return"text-foreground"}},[_]),Z=T.useMemo(()=>Ff(e.content),[e.content]),I=T.useMemo(()=>Wf(e.content),[e.content]),W=T.useMemo(()=>e.content.filter(ee=>ee.type==="image_url"),[e.content]),ge=T.useMemo(()=>e.content.filter(ee=>ee.type==="file"),[e.content]),he=Rf(Z,r?n:0),z=async()=>{try{const ee=G?Pt(e.content):Z;await navigator.clipboard.writeText(ee),R(!0),setTimeout(()=>R(!1),2e3),D==null||D(ee)}catch(ee){console.error("Failed to copy:",ee)}},ce=()=>{if(!E)return;const ee=G?Pt(e.content):Z;E(e.id,ee)},pe=()=>O==null?void 0:O(t),le=()=>{const ye=A(P?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",j);switch(_){case"user":return i.jsx(q.User,{className:ye});case"assistant":return i.jsx(q.Bot,{className:ye});case"tool":return i.jsx(q.Wrench,{className:ye});default:return i.jsx(q.Bot,{className:ye})}},de=()=>{const ee="group relative mb-4 flex w-full";switch(_){case"user":return A(ee,"justify-end");case"assistant":case"tool":case"system":return A(ee,"justify-start");default:return ee}},ue=()=>{const ee=A("rounded-lg px-4 py-3 relative transition-all duration-200 min-w-0 max-w-full break-words",P&&"px-3 py-2 text-sm");switch(_){case"user":return A(ee,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-user))] text-[hsl(var(--chat-bubble-user-text))]","border border-transparent");case"assistant":return A(ee,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40");case"tool":return A(ee,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return A(ee,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return ee}},V=ee=>{if(!ee)return"";try{return new Date(ee).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return""}},K=()=>{if(e.model==="reflection"){const ae=Z.trim(),fe=Xn(ae);if(fe&&typeof fe=="object")return i.jsx(Kf,{data:fe})}if(G&&I.name==="get_issues"){const ae=e.content.find(ot=>ot.type==="tool_result"),fe=(ae==null?void 0:ae.output)??Pt(e.content),Ne=ha(fe);if(Ne)return i.jsx(Gf,{issues:Ne})}if(G&&!M){const ae=Pt(e.content).slice(0,80).replace(/\s+/g," ");return i.jsx("div",{className:A("text-xs font-mono opacity-70 flex items-center justify-between gap-2 text-current",P&&"text-[10px]"),children:i.jsxs("span",{className:"truncate max-w-full text-current",children:[ae,ae.length>=80?"…":""]})})}if(G&&f){const ae=Pt(e.content),fe=ae.length>u;return i.jsx(da,{open:X,onOpenChange:B,children:i.jsxs("div",{className:"font-mono text-sm text-current",children:[i.jsx("pre",{className:A("whitespace-pre-wrap break-words text-current",P&&"text-xs"),children:fe&&!X?ae.substring(0,u)+"...":ae}),fe&&i.jsx(ua,{asChild:!0,children:i.jsx(me,{variant:"ghost",size:"sm",className:"h-6 text-xs text-current",children:X?i.jsxs(i.Fragment,{children:[i.jsx(q.ChevronUp,{className:"h-3 w-3 mr-1"}),"Show less"]}):i.jsxs(i.Fragment,{children:[i.jsx(q.ChevronDown,{className:"h-3 w-3 mr-1"}),"Show more (",ae.length-u," chars)"]})})})]})})}if(G&&M&&!f){const ae=zf(e.content);if(ae&&$f(ae))return i.jsx(Yt,{content:ae.trim()});const fe=Pt(e.content);return i.jsx("div",{className:"font-mono text-sm text-current",children:i.jsx("pre",{className:A("whitespace-pre-wrap break-words text-current",P&&"text-xs"),children:fe})})}const ee=W.length>0&&_!=="tool",ye=ge.length>0&&_!=="tool";return i.jsxs("div",{children:[r?i.jsxs("div",{className:"relative",children:[(()=>{const ae=Xn(he);return ae!==null?i.jsx(pa,{data:ae}):i.jsx(Yt,{content:Uf(Bf(he))})})(),i.jsx(Lf,{className:A(j,P?"text-xs":"text-sm")})]}):(()=>{const ae=Xn(Z.trim());if(ae!==null)return i.jsx(pa,{data:ae});if(_==="user"&&p){const fe=Z.trim();if(fe.length>m)return i.jsxs(da,{open:F,onOpenChange:H,children:[i.jsx("div",{className:A("text-sm text-[hsl(var(--chat-bubble-user-text))]",P&&"text-xs"),children:F?i.jsx(Yt,{content:fe}):i.jsxs("pre",{className:A("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",P&&"text-xs"),children:[fe.substring(0,m),"..."]})}),i.jsx(ua,{asChild:!0,children:i.jsx(me,{variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",children:F?i.jsxs(i.Fragment,{children:[i.jsx(q.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):i.jsxs(i.Fragment,{children:[i.jsx(q.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",fe.length-m," chars)"]})})})]})}return i.jsx(Yt,{content:Z.trim()})})(),ee&&i.jsx("div",{className:"mt-2 grid grid-cols-2 gap-2",children:W.map((ae,fe)=>i.jsxs("div",{className:"relative border rounded overflow-hidden",children:[i.jsx("img",{src:ae.url,alt:ae.alt??"image",className:"w-full h-auto"}),i.jsxs("div",{className:"absolute top-1 right-1 bg-background/70 rounded px-1 py-0.5 text-[10px] flex items-center gap-1",children:[i.jsx(q.Image,{className:"h-3 w-3"}),i.jsx("span",{children:"image"})]})]},fe))}),ye&&i.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:ge.map((ae,fe)=>{const Ne=ae,ot=Ne.name||"file";return i.jsxs("a",{href:Ne.url,download:ot,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-2 bg-gray-100 border border-gray-200 rounded px-2 py-1 text-xs hover:bg-gray-200",title:ot,children:[i.jsx("span",{className:"inline-block w-1.5 h-1.5 rounded-full bg-gray-400"}),i.jsx("span",{className:"truncate max-w-[180px]",children:ot})]},fe)})})]})},be=T.useMemo(()=>Vf(e),[e]);return T.useMemo(()=>jf(e,h),[e,h]),i.jsx("div",{className:A(de(),v.container),children:i.jsxs("div",{className:A(ue(),v.content),children:[(a||c||G)&&i.jsxs("div",{className:A("flex items-center justify-between mb-2 pb-2 border-b border-current/10",P&&"mb-1 pb-1",j,v.header),children:[i.jsxs("div",{className:"flex items-center gap-2",children:[le(),c&&be&&i.jsx("span",{className:A("font-medium",P?"text-xs":"text-sm"),children:be}),G&&I.name&&i.jsxs(oa,{variant:"outline",className:A("text-xs flex items-center gap-1 cursor-pointer",j,"border border-current/40",P&&"text-xs h-4"),onClick:()=>J(ee=>!ee),children:[i.jsx("span",{children:I.name}),i.jsx("span",{className:"inline-flex items-center",children:M?i.jsx(q.ChevronUp,{className:"h-3 w-3"}):i.jsx(q.ChevronDown,{className:"h-3 w-3"})})]}),G&&!I.name&&i.jsx(me,{variant:"ghost",size:"sm",className:A("h-6 px-1",j,"hover:bg-foreground/10"),onClick:()=>J(ee=>!ee),children:i.jsxs("span",{className:"text-xs flex items-center gap-1",children:["Tool Output ",M?i.jsx(q.ChevronUp,{className:"h-3 w-3"}):i.jsx(q.ChevronDown,{className:"h-3 w-3"})]})})]}),i.jsxs("div",{className:"flex items-center gap-2",children:[a&&i.jsx("span",{className:A("text-xs opacity-60",j,P&&"text-xs"),children:V(e.createdAt)}),s&&!o&&i.jsxs("div",{className:A("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",v.actions),children:[i.jsx(me,{variant:"ghost",size:"sm",onClick:z,className:A("h-6 w-6 p-0 hover:bg-foreground/10",j,P&&"h-5 w-5"),children:i.jsx(q.Copy,{className:A($?"text-success":j,P?"h-3 w-3":"h-4 w-4")})}),_==="user"&&E&&i.jsx(me,{variant:"ghost",size:"sm",onClick:ce,className:A("h-6 w-6 p-0 hover:bg-foreground/10",j,P&&"h-5 w-5"),children:i.jsx(q.Edit,{className:A(j,P?"h-3 w-3":"h-4 w-4")})}),_==="assistant"&&O&&i.jsx(me,{variant:"ghost",size:"sm",onClick:pe,className:A("h-6 w-6 p-0 hover:bg-foreground/10",j,P&&"h-5 w-5"),children:i.jsx(q.RotateCcw,{className:A(j,P?"h-3 w-3":"h-4 w-4")})})]})]})]}),i.jsx("div",{className:"relative",children:K()}),G&&M&&(I.toolCallId||I.name)&&i.jsxs("div",{className:A("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",P&&"text-xs"),children:[I.name&&i.jsxs("div",{children:["Function: ",I.name]}),I.toolCallId&&i.jsxs("div",{children:["Call ID: ",I.toolCallId]})]}),s&&_==="user"&&y&&y.totalBranches>1&&i.jsxs("div",{className:"flex items-center gap-2 mt-2 p-2 bg-muted/30 rounded border",children:[i.jsx(q.GitBranch,{className:"h-3 w-3 text-muted-foreground"}),i.jsxs("span",{className:"text-xs text-muted-foreground",children:["Branch ",y.currentIndex+1," of ",y.totalBranches]}),i.jsxs("div",{className:"flex items-center gap-1",children:[i.jsx(me,{variant:"ghost",size:"sm",className:A("h-6 w-6 p-0",j),disabled:!y.canGoBack,onClick:()=>x==null?void 0:x(),title:"Go back to previous branch",children:i.jsx(q.ChevronLeft,{className:A("h-3 w-3",j)})}),i.jsx(me,{variant:"ghost",size:"sm",className:A("h-6 w-6 p-0",j),disabled:!y.canGoForward,onClick:()=>C==null?void 0:C(),title:"Go forward to next branch",children:i.jsx(q.ChevronRight,{className:A("h-3 w-3",j)})})]})]}),!(a||c||G)&&s&&!o&&i.jsxs("div",{className:A("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",v.actions),children:[i.jsx(me,{variant:"ghost",size:"sm",onClick:z,className:A("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:i.jsx(q.Copy,{className:A($?"text-success":"text-current",P?"h-3 w-3":"h-4 w-4")})}),_==="user"&&E&&i.jsx(me,{variant:"ghost",size:"sm",onClick:ce,className:A("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:i.jsx(q.Edit,{className:A("text-current",P?"h-3 w-3":"h-4 w-4")})}),_==="assistant"&&O&&i.jsx(me,{variant:"ghost",size:"sm",onClick:pe,className:A("h-6 w-6 p-0 hover:bg-background/50 text-current",P&&"h-5 w-5"),children:i.jsx(q.RotateCcw,{className:A("text-current",P?"h-3 w-3":"h-4 w-4")})})]})]})})}function Ff(e){const t=e.filter(r=>r.type==="text").map(r=>r.text).join("");return t||JSON.stringify(e)}function $f(e){return e.includes(`
|
|
10
10
|
`)||e.includes("```")||/[-*] /.test(e)||/#+\s/.test(e)}function Bf(e){let t=e;try{(t.match(/```/g)||[]).length%2===1&&(t+="\n```"),(t.replace(/```[\s\S]*?```/g,"").match(new RegExp("(?<!`)`(?!`)","g"))||[]).length%2===1&&(t+="`")}catch{}return t}function Uf(e){let t=e;try{const r=[],n=[],o="\0F",s="\0I";let a=t.replace(/```[\s\S]*?```/g,c=>(r.push(c),`${o}${r.length-1}\0`));a=a.replace(/`[^`]*`/g,c=>(n.push(c),`${s}${n.length-1}\0`)),a=a.replace(/\b([A-Za-z0-9_&\/-]+)\b(\s+\1\b)+/g,"$1").replace(/\b([A-Za-z0-9_&\/-]+\s+[A-Za-z0-9_&\/-]+)\b(\s+\1\b)+/g,"$1").replace(/([\.,;:!\?\-])\1+/g,"$1").replace(/([:;!\?\)])([A-Za-z])/g,"$1 $2").replace(/\s{3,}/g," "),a=a.replace(/\u0000F(\d+)\u0000/g,(c,d)=>r[Number(d)]??""),a=a.replace(/\u0000I(\d+)\u0000/g,(c,d)=>n[Number(d)]??""),t=a}catch{}return t}function Xn(e){const t=e==null?void 0:e.trim();if(!t||!(t.startsWith("{")||t.startsWith("[")))return null;try{return JSON.parse(t)}catch{return null}}function pa({data:e}){if(Array.isArray(e))return e.every(r=>r===null||["string","number","boolean"].includes(typeof r))?i.jsx("div",{className:_r,children:i.jsx("ul",{className:"list-disc pl-5",children:e.map((r,n)=>i.jsx("li",{children:String(r)},n))})}):i.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Jt(e)});if(e&&typeof e=="object"){const t=Array.isArray(e.distilled_facts)?e.distilled_facts:null,r=Array.isArray(e.follow_up_queries)?e.follow_up_queries:null,n=typeof e.is_sufficient=="boolean"?e.is_sufficient:void 0;if(t||r||typeof n=="boolean")return i.jsxs("div",{className:_r,children:[typeof n=="boolean"&&i.jsxs("p",{children:[i.jsx("strong",{children:"Is sufficient:"})," ",n?"Yes":"No"]}),r&&r.length>0&&i.jsxs("div",{children:[i.jsx("p",{children:i.jsx("strong",{children:"Follow-up queries:"})}),i.jsx("ul",{className:"list-disc pl-5",children:r.map((s,a)=>i.jsx("li",{children:String(s)},a))})]}),t&&t.length>0&&i.jsxs("div",{children:[i.jsx("p",{children:i.jsx("strong",{children:"Facts:"})}),i.jsx("ul",{className:"list-disc pl-5",children:t.map((s,a)=>i.jsx("li",{children:String(s)},a))})]})]});const o=Object.entries(e);return i.jsx("div",{className:_r,children:i.jsx("dl",{className:"mt-0",children:o.map(([s,a])=>i.jsxs("div",{className:"mb-1",children:[i.jsxs("dt",{className:"inline font-medium mr-1",children:[s,":"]}),i.jsx("dd",{className:"inline",children:Hf(a)})]},s))})})}return i.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Jt(e)})}function Hf(e){if(e==null)return String(e);const t=typeof e;if(t==="string"||t==="number"||t==="boolean")return String(e);if(Array.isArray(e)&&e.every(n=>n===null||["string","number","boolean"].includes(typeof n)))return e.join(", ");try{return i.jsx("code",{className:"text-xs",children:JSON.stringify(e)})}catch{return String(e)}}function Pt(e){const t=e.filter(r=>r.type==="tool_result");if(t.length)try{return t.length===1?Jt(t[0].output):Jt(t.map(r=>({toolCallId:r.toolCallId,output:r.output})))}catch{}return Jt(e)}function zf(e){const t=e.find(n=>n.type==="tool_result");if(!t)return null;const r=t.output;return typeof r=="string"?r:null}function Jt(e){if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function Wf(e){const t=e.find(n=>n.type==="tool_call"),r=e.find(n=>n.type==="tool_result");return{name:t==null?void 0:t.name,toolCallId:(r==null?void 0:r.toolCallId)??(t==null?void 0:t.id)}}function Vf(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function jf(e,t){return e.checkpointId||t||null}function Rf(e,t){const[r,n]=T.useState(e);return T.useEffect(()=>{if(!t){n(e);return}const o=setTimeout(()=>n(e),t);return()=>clearTimeout(o)},[e,t]),r}function Kf({data:e}){return i.jsx("dl",{className:"grid grid-cols-1 gap-y-2",children:Object.entries(e).map(([t,r])=>i.jsxs("div",{className:"flex",children:[i.jsxs("dt",{className:"font-semibold mr-2",children:[t,":"]}),i.jsx("dd",{className:"flex-1 break-words",children:Array.isArray(r)?r.map((n,o)=>i.jsxs("div",{className:"ml-4 break-words",children:["- ",String(n)]},o)):String(r)})]},t))})}function ha(e){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){if(e.desirability||e.feasibility||e.viability||e.other)return{desirability:Array.isArray(e.desirability)?e.desirability:[],feasibility:Array.isArray(e.feasibility)?e.feasibility:[],viability:Array.isArray(e.viability)?e.viability:[],other:Array.isArray(e.other)?e.other:[]};if(e.output&&typeof e.output!="object")e=e.output;else if(e.output&&typeof e.output=="object")return ha(e.output)}const t=String(e),r={desirability:[],feasibility:[],viability:[],other:[]};let n=t;const o=Math.min(...["desirability=","feasibility=","viability=","other="].map(a=>{const c=n.toLowerCase().indexOf(a);return c===-1?Number.MAX_SAFE_INTEGER:c}));o!==Number.MAX_SAFE_INTEGER&&(n=n.slice(o));for(const a of Object.keys(r)){const d=new RegExp(a+"\\s*=\\s*\\[([\\s\\S]*?)\\]","i").exec(n);if(!d)continue;const f=d[1],u=/Issue\(([\s\S]*?)\)(?:,|$)/g;let p=null;for(;(p=u.exec(f))!==null;){const m=p[1],v=/title\s*=\s*(['"])([\s\S]*?)\1/.exec(m),g=/description\s*=\s*(['"])([\s\S]*?)\1/.exec(m),h=v?v[2].trim():"",b=g?g[2].trim():"";r[a].push({title:h,description:b})}}return Object.values(r).some(a=>a.length>0)?r:null}function Gf({issues:e}){const t=[{key:"desirability",title:"Desirability"},{key:"feasibility",title:"Feasibility"},{key:"viability",title:"Viability"},{key:"other",title:"Other"}];return i.jsx("div",{className:_r,children:t.map(r=>{const n=e[r.key];return!n||!n.length?null:i.jsxs("div",{className:"mb-4",children:[i.jsxs("h4",{className:"font-semibold mb-2",children:[r.title," (",n.length,")"]}),i.jsx("ol",{className:"list-decimal pl-5 space-y-2",children:n.map((o,s)=>i.jsxs("li",{children:[i.jsx("div",{className:"font-medium",children:o.title}),i.jsx("div",{className:"text-sm text-muted-foreground",children:o.description})]},s))})]},r.key)})})}const _t=1e4;function qf(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 o of t)r=r.replace(o,"");return/<[^>]+>/.test(r)&&!/<(?!\/?(?:code|strong|em|b|i|br|p|ul|ol|li|h[1-6])\b)[^>]+>/i.test(r)?r.replace(/<code>(.*?)<\/code>/gi,"`$1`").replace(/<strong>(.*?)<\/strong>/gi,"**$1**").replace(/<b>(.*?)<\/b>/gi,"**$1**").replace(/<em>(.*?)<\/em>/gi,"*$1*").replace(/<i>(.*?)<\/i>/gi,"*$1*").replace(/<br\s*\/?>/gi,`
|
|
11
11
|
`).replace(/<p>(.*?)<\/p>/gi,`$1
|
|
12
12
|
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
`)},mi=function(){var e=parseInt(document.body.getAttribute(Ft)||"0",10);return isFinite(e)?e:0},hg=function(){l.useEffect(function(){return document.body.setAttribute(Ft,(mi()+1).toString()),function(){var e=mi()-1;e<=0?document.body.removeAttribute(Ft):document.body.setAttribute(Ft,e.toString())}},[])},gg=function(e){var t=e.noRelative,r=e.noImportant,n=e.gapMode,o=n===void 0?"margin":n;hg();var s=l.useMemo(function(){return ug(o)},[o]);return l.createElement(fg,{styles:pg(s,!t,o,r?"":"!important")})},Ao=!1;if(typeof window<"u")try{var qr=Object.defineProperty({},"passive",{get:function(){return Ao=!0,!0}});window.addEventListener("test",qr,qr),window.removeEventListener("test",qr,qr)}catch{Ao=!1}var $t=Ao?{passive:!1}:!1,mg=function(e){return e.tagName==="TEXTAREA"},bi=function(e,t){if(!(e instanceof Element))return!1;var r=window.getComputedStyle(e);return r[t]!=="hidden"&&!(r.overflowY===r.overflowX&&!mg(e)&&r[t]==="visible")},bg=function(e){return bi(e,"overflowY")},vg=function(e){return bi(e,"overflowX")},vi=function(e,t){var r=t.ownerDocument,n=t;do{typeof ShadowRoot<"u"&&n instanceof ShadowRoot&&(n=n.host);var o=wi(e,n);if(o){var s=yi(e,n),a=s[1],c=s[2];if(a>c)return!0}n=n.parentNode}while(n&&n!==r.body);return!1},wg=function(e){var t=e.scrollTop,r=e.scrollHeight,n=e.clientHeight;return[t,r,n]},yg=function(e){var t=e.scrollLeft,r=e.scrollWidth,n=e.clientWidth;return[t,r,n]},wi=function(e,t){return e==="v"?bg(t):vg(t)},yi=function(e,t){return e==="v"?wg(t):yg(t)},xg=function(e,t){return e==="h"&&t==="rtl"?-1:1},Sg=function(e,t,r,n,o){var s=xg(e,window.getComputedStyle(t).direction),a=s*n,c=r.target,d=t.contains(c),f=!1,u=a>0,p=0,m=0;do{if(!c)break;var v=yi(e,c),g=v[0],h=v[1],b=v[2],w=h-b-s*g;(g||w)&&wi(e,c)&&(p+=w,m+=g);var y=c.parentNode;c=y&&y.nodeType===Node.DOCUMENT_FRAGMENT_NODE?y.host:y}while(!d&&c!==document.body||d&&(t.contains(c)||t===c));return(u&&Math.abs(p)<1||!u&&Math.abs(m)<1)&&(f=!0),f},Xr=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},xi=function(e){return[e.deltaX,e.deltaY]},Si=function(e){return e&&"current"in e?e.current:e},Cg=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Eg=function(e){return`
|
|
56
56
|
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
57
57
|
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
58
|
-
`)},Ng=0,Bt=[];function Tg(e){var t=l.useRef([]),r=l.useRef([0,0]),n=l.useRef(),o=l.useState(Ng++)[0],s=l.useState(gi)[0],a=l.useRef(e);l.useEffect(function(){a.current=e},[e]),l.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var h=Gh([e.lockRef.current],(e.shards||[]).map(Si),!0).filter(Boolean);return h.forEach(function(b){return b.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),h.forEach(function(b){return b.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var c=l.useCallback(function(h,b){if("touches"in h&&h.touches.length===2||h.type==="wheel"&&h.ctrlKey)return!a.current.allowPinchZoom;var w=Xr(h),y=r.current,x="deltaX"in h?h.deltaX:y[0]-w[0],C="deltaY"in h?h.deltaY:y[1]-w[1],E,O=h.target,N=Math.abs(x)>Math.abs(C)?"h":"v";if("touches"in h&&N==="h"&&O.type==="range")return!1;var L=vi(N,O);if(!L)return!0;if(L?E=N:(E=N==="v"?"h":"v",L=vi(N,O)),!L)return!1;if(!n.current&&"changedTouches"in h&&(x||C)&&(n.current=E),!E)return!0;var D=n.current||E;return Sg(D,b,h,D==="h"?x:C)},[]),d=l.useCallback(function(h){var b=h;if(!(!Bt.length||Bt[Bt.length-1]!==s)){var w="deltaY"in b?xi(b):Xr(b),y=t.current.filter(function(E){return E.name===b.type&&(E.target===b.target||b.target===E.shadowParent)&&Cg(E.delta,w)})[0];if(y&&y.should){b.cancelable&&b.preventDefault();return}if(!y){var x=(a.current.shards||[]).map(Si).filter(Boolean).filter(function(E){return E.contains(b.target)}),C=x.length>0?c(b,x[0]):!a.current.noIsolation;C&&b.cancelable&&b.preventDefault()}}},[]),f=l.useCallback(function(h,b,w,y){var x={name:h,delta:b,target:w,should:y,shadowParent:Ag(w)};t.current.push(x),setTimeout(function(){t.current=t.current.filter(function(C){return C!==x})},1)},[]),u=l.useCallback(function(h){r.current=Xr(h),n.current=void 0},[]),p=l.useCallback(function(h){f(h.type,xi(h),h.target,c(h,e.lockRef.current))},[]),m=l.useCallback(function(h){f(h.type,Xr(h),h.target,c(h,e.lockRef.current))},[]);l.useEffect(function(){return Bt.push(s),e.setCallbacks({onScrollCapture:p,onWheelCapture:p,onTouchMoveCapture:m}),document.addEventListener("wheel",d,$t),document.addEventListener("touchmove",d,$t),document.addEventListener("touchstart",u,$t),function(){Bt=Bt.filter(function(h){return h!==s}),document.removeEventListener("wheel",d,$t),document.removeEventListener("touchmove",d,$t),document.removeEventListener("touchstart",u,$t)}},[]);var v=e.removeScrollBar,g=e.inert;return l.createElement(l.Fragment,null,g?l.createElement(s,{styles:Eg(o)}):null,v?l.createElement(gg,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Ag(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Pg=rg(hi,Tg);var Yr=l.forwardRef(function(e,t){return l.createElement(Gr,Qe({},e,{ref:t,sideCar:Pg}))});Yr.classNames=Gr.classNames;var Po=["Enter"," "],_g=["ArrowDown","PageUp","Home"],Ci=["ArrowUp","PageDown","End"],Ig=[..._g,...Ci],kg={ltr:[...Po,"ArrowRight"],rtl:[...Po,"ArrowLeft"]},Og={ltr:["ArrowLeft"],rtl:["ArrowRight"]},nr="Menu",[or,Mg,Dg]=Yn(nr),[vt,Ei]=Ue(nr,[Dg,Dt,si]),Jr=Dt(),Ni=si(),[Lg,wt]=vt(nr),[Fg,sr]=vt(nr),Ti=e=>{const{__scopeMenu:t,open:r=!1,children:n,dir:o,onOpenChange:s,modal:a=!0}=e,c=Jr(t),[d,f]=l.useState(null),u=l.useRef(!1),p=Se(s),m=Ir(o);return l.useEffect(()=>{const v=()=>{u.current=!0,document.addEventListener("pointerdown",g,{capture:!0,once:!0}),document.addEventListener("pointermove",g,{capture:!0,once:!0})},g=()=>u.current=!1;return document.addEventListener("keydown",v,{capture:!0}),()=>{document.removeEventListener("keydown",v,{capture:!0}),document.removeEventListener("pointerdown",g,{capture:!0}),document.removeEventListener("pointermove",g,{capture:!0})}},[]),i.jsx(mo,{...c,children:i.jsx(Lg,{scope:t,open:r,onOpenChange:p,content:d,onContentChange:f,children:i.jsx(Fg,{scope:t,onClose:l.useCallback(()=>p(!1),[p]),isUsingKeyboardRef:u,dir:m,modal:a,children:n})})})};Ti.displayName=nr;var $g="MenuAnchor",_o=l.forwardRef((e,t)=>{const{__scopeMenu:r,...n}=e,o=Jr(r);return i.jsx(bo,{...o,...n,ref:t})});_o.displayName=$g;var Io="MenuPortal",[Bg,Ai]=vt(Io,{forceMount:void 0}),Pi=e=>{const{__scopeMenu:t,forceMount:r,children:n,container:o}=e,s=wt(Io,t);return i.jsx(Bg,{scope:t,forceMount:r,children:i.jsx(_e,{present:r||s.open,children:i.jsx(Wr,{asChild:!0,container:o,children:n})})})};Pi.displayName=Io;var Le="MenuContent",[Ug,ko]=vt(Le),_i=l.forwardRef((e,t)=>{const r=Ai(Le,e.__scopeMenu),{forceMount:n=r.forceMount,...o}=e,s=wt(Le,e.__scopeMenu),a=sr(Le,e.__scopeMenu);return i.jsx(or.Provider,{scope:e.__scopeMenu,children:i.jsx(_e,{present:n||s.open,children:i.jsx(or.Slot,{scope:e.__scopeMenu,children:a.modal?i.jsx(Hg,{...o,ref:t}):i.jsx(zg,{...o,ref:t})})})})}),Hg=l.forwardRef((e,t)=>{const r=wt(Le,e.__scopeMenu),n=l.useRef(null),o=se(t,n);return l.useEffect(()=>{const s=n.current;if(s)return Co(s)},[]),i.jsx(Oo,{...e,ref:o,trapFocus:r.open,disableOutsidePointerEvents:r.open,disableOutsideScroll:!0,onFocusOutside:U(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>r.onOpenChange(!1)})}),zg=l.forwardRef((e,t)=>{const r=wt(Le,e.__scopeMenu);return i.jsx(Oo,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>r.onOpenChange(!1)})}),Wg=Oe.createSlot("MenuContent.ScrollLock"),Oo=l.forwardRef((e,t)=>{const{__scopeMenu:r,loop:n=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:a,disableOutsidePointerEvents:c,onEntryFocus:d,onEscapeKeyDown:f,onPointerDownOutside:u,onFocusOutside:p,onInteractOutside:m,onDismiss:v,disableOutsideScroll:g,...h}=e,b=wt(Le,r),w=sr(Le,r),y=Jr(r),x=Ni(r),C=Mg(r),[E,O]=l.useState(null),N=l.useRef(null),L=se(t,N,b.onContentChange),D=l.useRef(0),$=l.useRef(""),R=l.useRef(0),X=l.useRef(null),B=l.useRef("right"),M=l.useRef(0),J=g?Yr:l.Fragment,F=g?{as:Wg,allowPinchZoom:!0}:void 0,H=_=>{var z,ce;const G=$.current+_,j=C().filter(pe=>!pe.disabled),Z=document.activeElement,I=(z=j.find(pe=>pe.ref.current===Z))==null?void 0:z.textValue,W=j.map(pe=>pe.textValue),ge=em(W,G,I),he=(ce=j.find(pe=>pe.textValue===ge))==null?void 0:ce.ref.current;(function pe(le){$.current=le,window.clearTimeout(D.current),le!==""&&(D.current=window.setTimeout(()=>pe(""),1e3))})(G),he&&setTimeout(()=>he.focus())};l.useEffect(()=>()=>window.clearTimeout(D.current),[]),Qn();const P=l.useCallback(_=>{var j,Z;return B.current===((j=X.current)==null?void 0:j.side)&&rm(_,(Z=X.current)==null?void 0:Z.area)},[]);return i.jsx(Ug,{scope:r,searchRef:$,onItemEnter:l.useCallback(_=>{P(_)&&_.preventDefault()},[P]),onItemLeave:l.useCallback(_=>{var G;P(_)||((G=N.current)==null||G.focus(),O(null))},[P]),onTriggerLeave:l.useCallback(_=>{P(_)&&_.preventDefault()},[P]),pointerGraceTimerRef:R,onPointerGraceIntentChange:l.useCallback(_=>{X.current=_},[]),children:i.jsx(J,{...F,children:i.jsx(kr,{asChild:!0,trapped:o,onMountAutoFocus:U(s,_=>{var G;_.preventDefault(),(G=N.current)==null||G.focus({preventScroll:!0})}),onUnmountAutoFocus:a,children:i.jsx(Zt,{asChild:!0,disableOutsidePointerEvents:c,onEscapeKeyDown:f,onPointerDownOutside:u,onFocusOutside:p,onInteractOutside:m,onDismiss:v,children:i.jsx(Wh,{asChild:!0,...x,dir:w.dir,orientation:"vertical",loop:n,currentTabStopId:E,onCurrentTabStopIdChange:O,onEntryFocus:U(d,_=>{w.isUsingKeyboardRef.current||_.preventDefault()}),preventScrollOnEntryFocus:!0,children:i.jsx(vo,{role:"menu","aria-orientation":"vertical","data-state":Ki(b.open),"data-radix-menu-content":"",dir:w.dir,...y,...h,ref:L,style:{outline:"none",...h.style},onKeyDown:U(h.onKeyDown,_=>{const j=_.target.closest("[data-radix-menu-content]")===_.currentTarget,Z=_.ctrlKey||_.altKey||_.metaKey,I=_.key.length===1;j&&(_.key==="Tab"&&_.preventDefault(),!Z&&I&&H(_.key));const W=N.current;if(_.target!==W||!Ig.includes(_.key))return;_.preventDefault();const he=C().filter(z=>!z.disabled).map(z=>z.ref.current);Ci.includes(_.key)&&he.reverse(),Zg(he)}),onBlur:U(e.onBlur,_=>{_.currentTarget.contains(_.target)||(window.clearTimeout(D.current),$.current="")}),onPointerMove:U(e.onPointerMove,ir(_=>{const G=_.target,j=M.current!==_.clientX;if(_.currentTarget.contains(G)&&j){const Z=_.clientX>M.current?"right":"left";B.current=Z,M.current=_.clientX}}))})})})})})})});_i.displayName=Le;var Vg="MenuGroup",Mo=l.forwardRef((e,t)=>{const{__scopeMenu:r,...n}=e;return i.jsx(Q.div,{role:"group",...n,ref:t})});Mo.displayName=Vg;var jg="MenuLabel",Ii=l.forwardRef((e,t)=>{const{__scopeMenu:r,...n}=e;return i.jsx(Q.div,{...n,ref:t})});Ii.displayName=jg;var Zr="MenuItem",ki="menu.itemSelect",Qr=l.forwardRef((e,t)=>{const{disabled:r=!1,onSelect:n,...o}=e,s=l.useRef(null),a=sr(Zr,e.__scopeMenu),c=ko(Zr,e.__scopeMenu),d=se(t,s),f=l.useRef(!1),u=()=>{const p=s.current;if(!r&&p){const m=new CustomEvent(ki,{bubbles:!0,cancelable:!0});p.addEventListener(ki,v=>n==null?void 0:n(v),{once:!0}),aa(p,m),m.defaultPrevented?f.current=!1:a.onClose()}};return i.jsx(Oi,{...o,ref:d,disabled:r,onClick:U(e.onClick,u),onPointerDown:p=>{var m;(m=e.onPointerDown)==null||m.call(e,p),f.current=!0},onPointerUp:U(e.onPointerUp,p=>{var m;f.current||(m=p.currentTarget)==null||m.click()}),onKeyDown:U(e.onKeyDown,p=>{const m=c.searchRef.current!=="";r||m&&p.key===" "||Po.includes(p.key)&&(p.currentTarget.click(),p.preventDefault())})})});Qr.displayName=Zr;var Oi=l.forwardRef((e,t)=>{const{__scopeMenu:r,disabled:n=!1,textValue:o,...s}=e,a=ko(Zr,r),c=Ni(r),d=l.useRef(null),f=se(t,d),[u,p]=l.useState(!1),[m,v]=l.useState("");return l.useEffect(()=>{const g=d.current;g&&v((g.textContent??"").trim())},[s.children]),i.jsx(or.ItemSlot,{scope:r,disabled:n,textValue:o??m,children:i.jsx(Vh,{asChild:!0,...c,focusable:!n,children:i.jsx(Q.div,{role:"menuitem","data-highlighted":u?"":void 0,"aria-disabled":n||void 0,"data-disabled":n?"":void 0,...s,ref:f,onPointerMove:U(e.onPointerMove,ir(g=>{n?a.onItemLeave(g):(a.onItemEnter(g),g.defaultPrevented||g.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:U(e.onPointerLeave,ir(g=>a.onItemLeave(g))),onFocus:U(e.onFocus,()=>p(!0)),onBlur:U(e.onBlur,()=>p(!1))})})})}),Rg="MenuCheckboxItem",Mi=l.forwardRef((e,t)=>{const{checked:r=!1,onCheckedChange:n,...o}=e;return i.jsx(Bi,{scope:e.__scopeMenu,checked:r,children:i.jsx(Qr,{role:"menuitemcheckbox","aria-checked":en(r)?"mixed":r,...o,ref:t,"data-state":Lo(r),onSelect:U(o.onSelect,()=>n==null?void 0:n(en(r)?!0:!r),{checkForDefaultPrevented:!1})})})});Mi.displayName=Rg;var Di="MenuRadioGroup",[Kg,Gg]=vt(Di,{value:void 0,onValueChange:()=>{}}),Li=l.forwardRef((e,t)=>{const{value:r,onValueChange:n,...o}=e,s=Se(n);return i.jsx(Kg,{scope:e.__scopeMenu,value:r,onValueChange:s,children:i.jsx(Mo,{...o,ref:t})})});Li.displayName=Di;var Fi="MenuRadioItem",$i=l.forwardRef((e,t)=>{const{value:r,...n}=e,o=Gg(Fi,e.__scopeMenu),s=r===o.value;return i.jsx(Bi,{scope:e.__scopeMenu,checked:s,children:i.jsx(Qr,{role:"menuitemradio","aria-checked":s,...n,ref:t,"data-state":Lo(s),onSelect:U(n.onSelect,()=>{var a;return(a=o.onValueChange)==null?void 0:a.call(o,r)},{checkForDefaultPrevented:!1})})})});$i.displayName=Fi;var Do="MenuItemIndicator",[Bi,qg]=vt(Do,{checked:!1}),Ui=l.forwardRef((e,t)=>{const{__scopeMenu:r,forceMount:n,...o}=e,s=qg(Do,r);return i.jsx(_e,{present:n||en(s.checked)||s.checked===!0,children:i.jsx(Q.span,{...o,ref:t,"data-state":Lo(s.checked)})})});Ui.displayName=Do;var Xg="MenuSeparator",Hi=l.forwardRef((e,t)=>{const{__scopeMenu:r,...n}=e;return i.jsx(Q.div,{role:"separator","aria-orientation":"horizontal",...n,ref:t})});Hi.displayName=Xg;var Yg="MenuArrow",zi=l.forwardRef((e,t)=>{const{__scopeMenu:r,...n}=e,o=Jr(r);return i.jsx(wo,{...o,...n,ref:t})});zi.displayName=Yg;var Jg="MenuSub",[Hw,Wi]=vt(Jg),ar="MenuSubTrigger",Vi=l.forwardRef((e,t)=>{const r=wt(ar,e.__scopeMenu),n=sr(ar,e.__scopeMenu),o=Wi(ar,e.__scopeMenu),s=ko(ar,e.__scopeMenu),a=l.useRef(null),{pointerGraceTimerRef:c,onPointerGraceIntentChange:d}=s,f={__scopeMenu:e.__scopeMenu},u=l.useCallback(()=>{a.current&&window.clearTimeout(a.current),a.current=null},[]);return l.useEffect(()=>u,[u]),l.useEffect(()=>{const p=c.current;return()=>{window.clearTimeout(p),d(null)}},[c,d]),i.jsx(_o,{asChild:!0,...f,children:i.jsx(Oi,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":r.open,"aria-controls":o.contentId,"data-state":Ki(r.open),...e,ref:Rn(t,o.onTriggerChange),onClick:p=>{var m;(m=e.onClick)==null||m.call(e,p),!(e.disabled||p.defaultPrevented)&&(p.currentTarget.focus(),r.open||r.onOpenChange(!0))},onPointerMove:U(e.onPointerMove,ir(p=>{s.onItemEnter(p),!p.defaultPrevented&&!e.disabled&&!r.open&&!a.current&&(s.onPointerGraceIntentChange(null),a.current=window.setTimeout(()=>{r.onOpenChange(!0),u()},100))})),onPointerLeave:U(e.onPointerLeave,ir(p=>{var v,g;u();const m=(v=r.content)==null?void 0:v.getBoundingClientRect();if(m){const h=(g=r.content)==null?void 0:g.dataset.side,b=h==="right",w=b?-5:5,y=m[b?"left":"right"],x=m[b?"right":"left"];s.onPointerGraceIntentChange({area:[{x:p.clientX+w,y:p.clientY},{x:y,y:m.top},{x,y:m.top},{x,y:m.bottom},{x:y,y:m.bottom}],side:h}),window.clearTimeout(c.current),c.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(p),p.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:U(e.onKeyDown,p=>{var v;const m=s.searchRef.current!=="";e.disabled||m&&p.key===" "||kg[n.dir].includes(p.key)&&(r.onOpenChange(!0),(v=r.content)==null||v.focus(),p.preventDefault())})})})});Vi.displayName=ar;var ji="MenuSubContent",Ri=l.forwardRef((e,t)=>{const r=Ai(Le,e.__scopeMenu),{forceMount:n=r.forceMount,...o}=e,s=wt(Le,e.__scopeMenu),a=sr(Le,e.__scopeMenu),c=Wi(ji,e.__scopeMenu),d=l.useRef(null),f=se(t,d);return i.jsx(or.Provider,{scope:e.__scopeMenu,children:i.jsx(_e,{present:n||s.open,children:i.jsx(or.Slot,{scope:e.__scopeMenu,children:i.jsx(Oo,{id:c.contentId,"aria-labelledby":c.triggerId,...o,ref:f,align:"start",side:a.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:u=>{var p;a.isUsingKeyboardRef.current&&((p=d.current)==null||p.focus()),u.preventDefault()},onCloseAutoFocus:u=>u.preventDefault(),onFocusOutside:U(e.onFocusOutside,u=>{u.target!==c.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:U(e.onEscapeKeyDown,u=>{a.onClose(),u.preventDefault()}),onKeyDown:U(e.onKeyDown,u=>{var v;const p=u.currentTarget.contains(u.target),m=Og[a.dir].includes(u.key);p&&m&&(s.onOpenChange(!1),(v=c.trigger)==null||v.focus(),u.preventDefault())})})})})})});Ri.displayName=ji;function Ki(e){return e?"open":"closed"}function en(e){return e==="indeterminate"}function Lo(e){return en(e)?"indeterminate":e?"checked":"unchecked"}function Zg(e){const t=document.activeElement;for(const r of e)if(r===t||(r.focus(),document.activeElement!==t))return}function Qg(e,t){return e.map((r,n)=>e[(t+n)%e.length])}function em(e,t,r){const o=t.length>1&&Array.from(t).every(f=>f===t[0])?t[0]:t,s=r?e.indexOf(r):-1;let a=Qg(e,Math.max(s,0));o.length===1&&(a=a.filter(f=>f!==r));const d=a.find(f=>f.toLowerCase().startsWith(o.toLowerCase()));return d!==r?d:void 0}function tm(e,t){const{x:r,y:n}=e;let o=!1;for(let s=0,a=t.length-1;s<t.length;a=s++){const c=t[s],d=t[a],f=c.x,u=c.y,p=d.x,m=d.y;u>n!=m>n&&r<(p-f)*(n-u)/(m-u)+f&&(o=!o)}return o}function rm(e,t){if(!t)return!1;const r={x:e.clientX,y:e.clientY};return tm(r,t)}function ir(e){return t=>t.pointerType==="mouse"?e(t):void 0}var nm=Ti,om=_o,sm=Pi,am=_i,im=Mo,cm=Ii,lm=Qr,dm=Mi,um=Li,fm=$i,pm=Ui,hm=Hi,gm=zi,mm=Vi,bm=Ri,tn="DropdownMenu",[vm,zw]=Ue(tn,[Ei]),Ee=Ei(),[wm,Gi]=vm(tn),qi=e=>{const{__scopeDropdownMenu:t,children:r,dir:n,open:o,defaultOpen:s,onOpenChange:a,modal:c=!0}=e,d=Ee(t),f=l.useRef(null),[u,p]=st({prop:o,defaultProp:s??!1,onChange:a,caller:tn});return i.jsx(wm,{scope:t,triggerId:He(),triggerRef:f,contentId:He(),open:u,onOpenChange:p,onOpenToggle:l.useCallback(()=>p(m=>!m),[p]),modal:c,children:i.jsx(nm,{...d,open:u,onOpenChange:p,dir:n,modal:c,children:r})})};qi.displayName=tn;var Xi="DropdownMenuTrigger",Yi=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,disabled:n=!1,...o}=e,s=Gi(Xi,r),a=Ee(r);return i.jsx(om,{asChild:!0,...a,children:i.jsx(Q.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":n?"":void 0,disabled:n,...o,ref:Rn(t,s.triggerRef),onPointerDown:U(e.onPointerDown,c=>{!n&&c.button===0&&c.ctrlKey===!1&&(s.onOpenToggle(),s.open||c.preventDefault())}),onKeyDown:U(e.onKeyDown,c=>{n||(["Enter"," "].includes(c.key)&&s.onOpenToggle(),c.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(c.key)&&c.preventDefault())})})})});Yi.displayName=Xi;var ym="DropdownMenuPortal",Ji=e=>{const{__scopeDropdownMenu:t,...r}=e,n=Ee(t);return i.jsx(sm,{...n,...r})};Ji.displayName=ym;var Zi="DropdownMenuContent",Qi=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Gi(Zi,r),s=Ee(r),a=l.useRef(!1);return i.jsx(am,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...n,ref:t,onCloseAutoFocus:U(e.onCloseAutoFocus,c=>{var d;a.current||(d=o.triggerRef.current)==null||d.focus(),a.current=!1,c.preventDefault()}),onInteractOutside:U(e.onInteractOutside,c=>{const d=c.detail.originalEvent,f=d.button===0&&d.ctrlKey===!0,u=d.button===2||f;(!o.modal||u)&&(a.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});Qi.displayName=Zi;var xm="DropdownMenuGroup",Sm=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(im,{...o,...n,ref:t})});Sm.displayName=xm;var Cm="DropdownMenuLabel",ec=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(cm,{...o,...n,ref:t})});ec.displayName=Cm;var Em="DropdownMenuItem",tc=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(lm,{...o,...n,ref:t})});tc.displayName=Em;var Nm="DropdownMenuCheckboxItem",rc=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(dm,{...o,...n,ref:t})});rc.displayName=Nm;var Tm="DropdownMenuRadioGroup",Am=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(um,{...o,...n,ref:t})});Am.displayName=Tm;var Pm="DropdownMenuRadioItem",nc=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(fm,{...o,...n,ref:t})});nc.displayName=Pm;var _m="DropdownMenuItemIndicator",oc=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(pm,{...o,...n,ref:t})});oc.displayName=_m;var Im="DropdownMenuSeparator",sc=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(hm,{...o,...n,ref:t})});sc.displayName=Im;var km="DropdownMenuArrow",Om=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(gm,{...o,...n,ref:t})});Om.displayName=km;var Mm="DropdownMenuSubTrigger",ac=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(mm,{...o,...n,ref:t})});ac.displayName=Mm;var Dm="DropdownMenuSubContent",ic=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(bm,{...o,...n,ref:t,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});ic.displayName=Dm;var Lm=qi,Fm=Yi,$m=Ji,cc=Qi,lc=ec,dc=tc,uc=rc,fc=nc,pc=oc,hc=sc,gc=ac,mc=ic;const Bm=Lm,Um=Fm,Hm=l.forwardRef(({className:e,inset:t,children:r,...n},o)=>i.jsxs(gc,{ref:o,className:A("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",t&&"pl-8",e),...n,children:[r,i.jsx(q.ChevronRight,{className:"ml-auto h-4 w-4"})]}));Hm.displayName=gc.displayName;const zm=l.forwardRef(({className:e,...t},r)=>i.jsx(mc,{ref:r,className:A("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...t}));zm.displayName=mc.displayName;const bc=l.forwardRef(({className:e,sideOffset:t=4,...r},n)=>i.jsx($m,{children:i.jsx(cc,{ref:n,sideOffset:t,className:A("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...r})}));bc.displayName=cc.displayName;const vc=l.forwardRef(({className:e,inset:t,...r},n)=>i.jsx(dc,{ref:n,className:A("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...r}));vc.displayName=dc.displayName;const Wm=l.forwardRef(({className:e,children:t,checked:r,...n},o)=>i.jsxs(uc,{ref:o,className:A("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:r,...n,children:[i.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:i.jsx(pc,{children:i.jsx(q.Check,{className:"h-4 w-4"})})}),t]}));Wm.displayName=uc.displayName;const Vm=l.forwardRef(({className:e,children:t,...r},n)=>i.jsxs(fc,{ref:n,className:A("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...r,children:[i.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:i.jsx(pc,{children:i.jsx(q.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));Vm.displayName=fc.displayName;const jm=l.forwardRef(({className:e,inset:t,...r},n)=>i.jsx(lc,{ref:n,className:A("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...r}));jm.displayName=lc.displayName;const Rm=l.forwardRef(({className:e,...t},r)=>i.jsx(hc,{ref:r,className:A("-mx-1 my-1 h-px bg-muted",e),...t}));Rm.displayName=hc.displayName;function cr({className:e="",placeholder:t="Type your message...",autoFocus:r=!0,maxHeight:n=void 0,streamingDebounceMs:o=40,enableFileUpload:s=!0,enableMessageEditing:a=!0,customStyles:c={},onMessageSent:d,onError:f}){const{currentThreadId:u,messages:p,isStreaming:m,streamingAssistantId:v,error:g,send:h,stop:b,lastCheckpointId:w,listCheckpoints:y,navigateToCheckpoint:x,returnToLatest:C,hasMoreHistory:E,isLoadingHistory:O,loadOlderMessages:N}=jn(),[L,D]=T.useState(""),[$,R]=T.useState(null),[X,B]=T.useState(null),[M,J]=T.useState([]),[F,H]=T.useState(!1),[P,_]=T.useState([]),[G,j]=T.useState(null),Z=T.useRef(null),I=T.useRef(null),W=T.useRef(null),ge=T.useRef(null),he=T.useRef(!1),z=T.useRef(!0),ce=T.useRef(0),[pe,le]=T.useState("desktop");T.useEffect(()=>{const k=()=>{const Y=window.innerWidth;le(Y<640?"phone":Y<1024?"tablet":"desktop")};return k(),window.addEventListener("resize",k),()=>window.removeEventListener("resize",k)},[]);const de=T.useCallback(async()=>{if(!E||O)return;const k=ge.current;if(!k)return;const Y=k.scrollHeight,re=k.scrollTop;he.current=!0;try{await N()}catch(oe){console.warn("loadOlderMessages failed",oe)}finally{requestAnimationFrame(()=>{const oe=ge.current;if(!oe){he.current=!1;return}const ve=oe.scrollHeight;oe.scrollTop=re+(ve-Y);const ft=ve-oe.scrollTop-oe.clientHeight;z.current=ft<=32,he.current=!1})}},[E,O,N]);T.useEffect(()=>{const k=ge.current;if(!k)return;const Y=()=>{k.scrollTop<=80&&de();const ve=k.scrollHeight-k.scrollTop-k.clientHeight;z.current=ve<=80};return k.addEventListener("scroll",Y),()=>k.removeEventListener("scroll",Y)},[de]),T.useEffect(()=>{p.length<ce.current&&(z.current=!0),ce.current=p.length},[p.length]),T.useEffect(()=>{const k=ge.current;k&&(he.current||z.current&&(k.scrollTop=k.scrollHeight,z.current=!0))},[p]),T.useEffect(()=>{var k;r&&((k=I.current)==null||k.focus())},[r]),T.useEffect(()=>{g&&!F&&(f==null||f(g))},[g,F,f]),T.useEffect(()=>{let k=!0;if(!u){_([]),j(null);return}return y(u).then(Y=>{var ve;if(!k)return;const re=Y.checkpoints||[];_(re);const oe=((ve=re.slice().sort((ft,Te)=>new Date(Te.createdAt).getTime()-new Date(ft.createdAt).getTime())[0])==null?void 0:ve.checkpointId)||null;j(ft=>ft??oe)}).catch(()=>{}),()=>{k=!1}},[u,y]),T.useEffect(()=>{w&&j(w)},[w]);const ue=k=>{if(k.length>_t)return`Message too long (${k.length}/${_t} characters)`;try{return Yf(k),null}catch(Y){return(Y==null?void 0:Y.message)||"Invalid message"}},V=k=>{const Y=k.content||[],re=Y.filter(oe=>oe.type==="text").map(oe=>oe.text).join("");if(re)return re;try{return JSON.stringify(Y,null,2)}catch{return String(Y)}},K=k=>{var ft;if(!P.length)return[];const re=(((ft=p[k])==null?void 0:ft.role)??"user")==="user",oe=re?k+2:k+1;return P.filter(Te=>(Te.messagesLen??-1)>=(re?oe:0)).filter(Te=>re?(Te.messagesLen??0)>=oe:(Te.messagesLen??0)===oe).map(Te=>({checkpoint_id:Te.checkpointId,checkpoint_ns:Te.checkpointNs,message_count:Te.messagesLen??0,last_message_preview:Te.preview??void 0,ts:new Date(Te.createdAt).getTime(),isCurrent:Te.checkpointId===G})).sort((Te,mw)=>(Te.ts||0)-(mw.ts||0))},be=k=>{if(k===void 0)return{canGoBack:!1,canGoForward:!1,currentIndex:0,totalBranches:0};const Y=K(k);if(Y.length<=1)return{canGoBack:!1,canGoForward:!1,currentIndex:0,totalBranches:Y.length};const re=Math.max(0,Y.findIndex(oe=>oe.isCurrent));return{canGoBack:re>0,canGoForward:re<Y.length-1,currentIndex:re,totalBranches:Y.length}},ee=async()=>{const k=L.trim();if(!k&&M.length===0)return;const Y=ue(k);if(Y){B(Y);return}try{const re=window.__editingCheckpointId||G||void 0;await h(k,{checkpointId:re,payloadExtras:$?{edit:!0,originalMessageId:$}:void 0,attachments:M}),d==null||d(k),D(""),B(null),J([]),delete window.__editingCheckpointId,R(null),I.current&&(I.current.style.height="auto")}catch(re){const oe=(re==null?void 0:re.message)||"Failed to send message";B(oe),f==null||f(oe)}},ye=(k,Y)=>{a&&(R(k),D(Y),B(null),setTimeout(()=>{I.current&&(I.current.focus(),I.current.style.height="auto",I.current.style.height=I.current.scrollHeight+"px")},0))},ae=async(k,Y)=>{const re=p.find(ve=>ve.id===k);if(!re){B("Message not found");return}const oe=V(re);R(k),D(oe),window.__editingCheckpointId=Y,setTimeout(()=>{var ve;return(ve=I.current)==null?void 0:ve.focus()},0)},fe=()=>{R(null),D(""),B(null),delete window.__editingCheckpointId,I.current&&(I.current.style.height="auto")},Ne=k=>{k.key==="Enter"&&!k.shiftKey?(k.preventDefault(),ee()):k.key==="Escape"&&$&&(k.preventDefault(),fe())},ot=k=>{const Y=Array.from(k.target.files||[]);J(re=>[...re,...Y])},as=k=>J(Y=>Y.filter((re,oe)=>k!==oe)),Et=async k=>{u&&(await x(k),j(k))},ie=async()=>{await C(),j(null)},Ie=`flex flex-col h-full min-h-0 min-w-0 overflow-hidden bg-transparent ${e} ${c.container||""}`,ke=`flex-1 min-h-0 min-w-0 overflow-y-auto overflow-x-hidden break-words break-anywhere p-4 space-y-4 bg-transparent ${c.messagesArea||""}`,Re=`flex-shrink-0 border-t p-4 bg-transparent ${c.inputArea||""}`;return i.jsxs("div",{className:Ie,children:[!!g&&!F&&i.jsxs("div",{className:"bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[i.jsx("span",{children:g}),i.jsx(me,{variant:"ghost",size:"sm",onClick:()=>H(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:i.jsx(q.X,{size:16})})]}),u&&P.length>0&&i.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 border-b border-border bg-muted/60 text-xs dark:bg-muted/50",children:[i.jsx(q.GitBranch,{className:"h-4 w-4 opacity-70"}),i.jsx("span",{className:"opacity-70",children:"Checkpoint:"}),i.jsxs("select",{className:"border border-border rounded px-2 py-1 text-xs bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring dark:bg-secondary",value:G??"",onChange:k=>{const Y=k.target.value||null;Y?Et(Y):ie()},children:[i.jsx("option",{value:"",children:"Latest"}),P.slice().sort((k,Y)=>new Date(Y.createdAt).getTime()-new Date(k.createdAt).getTime()).map(k=>i.jsxs("option",{value:k.checkpointId,children:[new Date(k.createdAt).toLocaleString(),k.preview?` — ${k.preview.slice(0,30)}`:""]},k.checkpointId))]})]}),i.jsxs("div",{ref:ge,className:ke,style:n?{maxHeight:n}:void 0,children:[p.length===0?i.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground",children:"No messages yet. Start a conversation!"}):i.jsxs(i.Fragment,{children:[(O||!E)&&i.jsx("div",{className:"flex justify-center py-2 text-xs text-muted-foreground",children:O?i.jsx(q.Loader2,{className:"h-4 w-4 animate-spin"}):"You've reached the beginning"}),p.map((k,Y)=>i.jsx(fa,{message:k,messageIndex:Y,isStreamingMessage:m&&v===k.id,streamingDebounceMs:o,isEditing:$===k.id,showActions:a,showTimestamp:!1,showAgentName:!0,layoutSize:pe,truncateToolMessages:!1,toolMessagePreviewLength:200,checkpointBranches:K(Y),currentCheckpointId:G??void 0,temporalNavigation:be(Y),onSwitchToCheckpoint:Et,onReturnToMainThread:ie,onNavigateToPreviousBranch:()=>{const re=K(Y),oe=Math.max(0,re.findIndex(ve=>ve.isCurrent));oe>0&&Et(re[oe-1].checkpoint_id)},onNavigateToNextBranch:()=>{const re=K(Y),oe=Math.max(0,re.findIndex(ve=>ve.isCurrent));oe>=0&&oe<re.length-1&&Et(re[oe+1].checkpoint_id)},onEdit:(re,oe)=>ye(re,oe),onEditFromCheckpoint:ae,onRegenerate:()=>{const re=[...p].reverse().find(ve=>ve.role==="user"),oe=re?V(re):"";oe&&h(oe,{checkpointId:G??void 0})},onCancelEdit:fe},k.id||Y))]}),i.jsx("div",{ref:Z})]}),i.jsxs("div",{className:Re,children:[$&&i.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(q.Edit3,{size:16,className:"text-blue-600"}),i.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),i.jsx(me,{variant:"ghost",size:"sm",onClick:fe,className:"text-blue-600 hover:bg-blue-100",children:i.jsx(q.X,{size:16})})]})}),s&&i.jsxs("div",{className:"mb-3",children:[i.jsx("input",{ref:W,type:"file",multiple:!0,onChange:k=>ot(k),className:"hidden"}),M.length>0&&i.jsx("div",{className:"mb-3 flex flex-wrap gap-2",children:M.map((k,Y)=>i.jsxs("div",{className:"flex items-center gap-2 bg-gray-100 rounded-lg px-3 py-2 text-sm",children:[i.jsx(q.Paperclip,{size:14}),i.jsx("span",{className:"truncate max-w-[150px]",children:k.name}),i.jsx(me,{variant:"ghost",size:"sm",onClick:()=>as(Y),className:"h-4 w-4 p-0 text-gray-500 hover:text-red-500","aria-label":`Remove ${k.name}`,children:i.jsx(q.X,{size:12})})]},Y))})]}),X&&i.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:X}),i.jsxs("div",{className:"flex items-end gap-2",children:[s&&i.jsxs(Bm,{children:[i.jsx(Um,{asChild:!0,children:i.jsx(me,{type:"button",size:"icon",variant:"outline",disabled:m,title:"More input actions",className:c.moreButton||"",children:i.jsx(q.Plus,{size:16})})}),i.jsx(bc,{align:"start",sideOffset:6,className:"w-52",children:i.jsxs(vc,{onClick:()=>{var k;return(k=W.current)==null?void 0:k.click()},className:"cursor-pointer",children:[i.jsx(q.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]})})]}),i.jsx("div",{className:"flex-1",children:i.jsx(na,{ref:I,value:L,onChange:k=>{D(k.target.value),B(null),I.current&&(I.current.style.height="auto",I.current.style.height=`${I.current.scrollHeight}px`)},onKeyDown:Ne,placeholder:$?"Edit your message...":t,className:`resize-none min-h-[44px] max-h-[20rem] w-full ${$?"border-blue-400 bg-blue-50":""} ${X?"border-red-400":""} ${c.textarea||""}`,disabled:!1,maxLength:_t,rows:1})}),i.jsx("div",{children:m?i.jsx(me,{type:"button",onClick:b,size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",children:i.jsx(q.Square,{size:16})}):i.jsx(me,{type:"button",onClick:ee,size:"icon",disabled:!L.trim()&&M.length===0,className:`shrink-0 ${c.sendButton||""}`,title:$?"Save changes":"Send message",children:i.jsx(q.Send,{size:16})})})]}),L.length>_t*.8&&i.jsxs("div",{className:"mt-2 text-xs text-gray-500 text-right",children:[L.length,"/",_t]})]})]})}const lr=l.forwardRef(({className:e,type:t,...r},n)=>i.jsx("input",{type:t,className:A("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}));lr.displayName="Input";function Fo(e,[t,r]){return Math.min(r,Math.max(t,e))}function Km(e,t){return l.useReducer((r,n)=>t[r][n]??r,e)}var $o="ScrollArea",[wc,Ww]=Ue($o),[Gm,Fe]=wc($o),yc=l.forwardRef((e,t)=>{const{__scopeScrollArea:r,type:n="hover",dir:o,scrollHideDelay:s=600,...a}=e,[c,d]=l.useState(null),[f,u]=l.useState(null),[p,m]=l.useState(null),[v,g]=l.useState(null),[h,b]=l.useState(null),[w,y]=l.useState(0),[x,C]=l.useState(0),[E,O]=l.useState(!1),[N,L]=l.useState(!1),D=se(t,R=>d(R)),$=Ir(o);return i.jsx(Gm,{scope:r,type:n,dir:$,scrollHideDelay:s,scrollArea:c,viewport:f,onViewportChange:u,content:p,onContentChange:m,scrollbarX:v,onScrollbarXChange:g,scrollbarXEnabled:E,onScrollbarXEnabledChange:O,scrollbarY:h,onScrollbarYChange:b,scrollbarYEnabled:N,onScrollbarYEnabledChange:L,onCornerWidthChange:y,onCornerHeightChange:C,children:i.jsx(Q.div,{dir:$,...a,ref:D,style:{position:"relative","--radix-scroll-area-corner-width":w+"px","--radix-scroll-area-corner-height":x+"px",...e.style}})})});yc.displayName=$o;var xc="ScrollAreaViewport",Sc=l.forwardRef((e,t)=>{const{__scopeScrollArea:r,children:n,nonce:o,...s}=e,a=Fe(xc,r),c=l.useRef(null),d=se(t,c,a.onViewportChange);return i.jsxs(i.Fragment,{children:[i.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}),i.jsx(Q.div,{"data-radix-scroll-area-viewport":"",...s,ref:d,style:{overflowX:a.scrollbarXEnabled?"scroll":"hidden",overflowY:a.scrollbarYEnabled?"scroll":"hidden",...e.style},children:i.jsx("div",{ref:a.onContentChange,style:{minWidth:"100%",display:"table"},children:n})})]})});Sc.displayName=xc;var et="ScrollAreaScrollbar",Bo=l.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=Fe(et,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:a}=o,c=e.orientation==="horizontal";return l.useEffect(()=>(c?s(!0):a(!0),()=>{c?s(!1):a(!1)}),[c,s,a]),o.type==="hover"?i.jsx(qm,{...n,ref:t,forceMount:r}):o.type==="scroll"?i.jsx(Xm,{...n,ref:t,forceMount:r}):o.type==="auto"?i.jsx(Cc,{...n,ref:t,forceMount:r}):o.type==="always"?i.jsx(Uo,{...n,ref:t}):null});Bo.displayName=et;var qm=l.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=Fe(et,e.__scopeScrollArea),[s,a]=l.useState(!1);return l.useEffect(()=>{const c=o.scrollArea;let d=0;if(c){const f=()=>{window.clearTimeout(d),a(!0)},u=()=>{d=window.setTimeout(()=>a(!1),o.scrollHideDelay)};return c.addEventListener("pointerenter",f),c.addEventListener("pointerleave",u),()=>{window.clearTimeout(d),c.removeEventListener("pointerenter",f),c.removeEventListener("pointerleave",u)}}},[o.scrollArea,o.scrollHideDelay]),i.jsx(_e,{present:r||s,children:i.jsx(Cc,{"data-state":s?"visible":"hidden",...n,ref:t})})}),Xm=l.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=Fe(et,e.__scopeScrollArea),s=e.orientation==="horizontal",a=sn(()=>d("SCROLL_END"),100),[c,d]=Km("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 l.useEffect(()=>{if(c==="idle"){const f=window.setTimeout(()=>d("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(f)}},[c,o.scrollHideDelay,d]),l.useEffect(()=>{const f=o.viewport,u=s?"scrollLeft":"scrollTop";if(f){let p=f[u];const m=()=>{const v=f[u];p!==v&&(d("SCROLL"),a()),p=v};return f.addEventListener("scroll",m),()=>f.removeEventListener("scroll",m)}},[o.viewport,s,d,a]),i.jsx(_e,{present:r||c!=="hidden",children:i.jsx(Uo,{"data-state":c==="hidden"?"hidden":"visible",...n,ref:t,onPointerEnter:U(e.onPointerEnter,()=>d("POINTER_ENTER")),onPointerLeave:U(e.onPointerLeave,()=>d("POINTER_LEAVE"))})})}),Cc=l.forwardRef((e,t)=>{const r=Fe(et,e.__scopeScrollArea),{forceMount:n,...o}=e,[s,a]=l.useState(!1),c=e.orientation==="horizontal",d=sn(()=>{if(r.viewport){const f=r.viewport.offsetWidth<r.viewport.scrollWidth,u=r.viewport.offsetHeight<r.viewport.scrollHeight;a(c?f:u)}},10);return Ut(r.viewport,d),Ut(r.content,d),i.jsx(_e,{present:n||s,children:i.jsx(Uo,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Uo=l.forwardRef((e,t)=>{const{orientation:r="vertical",...n}=e,o=Fe(et,e.__scopeScrollArea),s=l.useRef(null),a=l.useRef(0),[c,d]=l.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),f=Pc(c.viewport,c.content),u={...n,sizes:c,onSizesChange:d,hasThumb:f>0&&f<1,onThumbChange:m=>s.current=m,onThumbPointerUp:()=>a.current=0,onThumbPointerDown:m=>a.current=m};function p(m,v){return tb(m,a.current,c,v)}return r==="horizontal"?i.jsx(Ym,{...u,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const m=o.viewport.scrollLeft,v=_c(m,c,o.dir);s.current.style.transform=`translate3d(${v}px, 0, 0)`}},onWheelScroll:m=>{o.viewport&&(o.viewport.scrollLeft=m)},onDragScroll:m=>{o.viewport&&(o.viewport.scrollLeft=p(m,o.dir))}}):r==="vertical"?i.jsx(Jm,{...u,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const m=o.viewport.scrollTop,v=_c(m,c);s.current.style.transform=`translate3d(0, ${v}px, 0)`}},onWheelScroll:m=>{o.viewport&&(o.viewport.scrollTop=m)},onDragScroll:m=>{o.viewport&&(o.viewport.scrollTop=p(m))}}):null}),Ym=l.forwardRef((e,t)=>{const{sizes:r,onSizesChange:n,...o}=e,s=Fe(et,e.__scopeScrollArea),[a,c]=l.useState(),d=l.useRef(null),f=se(t,d,s.onScrollbarXChange);return l.useEffect(()=>{d.current&&c(getComputedStyle(d.current))},[d]),i.jsx(Nc,{"data-orientation":"horizontal",...o,ref:f,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":on(r)+"px",...e.style},onThumbPointerDown:u=>e.onThumbPointerDown(u.x),onDragScroll:u=>e.onDragScroll(u.x),onWheelScroll:(u,p)=>{if(s.viewport){const m=s.viewport.scrollLeft+u.deltaX;e.onWheelScroll(m),kc(m,p)&&u.preventDefault()}},onResize:()=>{d.current&&s.viewport&&a&&n({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:d.current.clientWidth,paddingStart:nn(a.paddingLeft),paddingEnd:nn(a.paddingRight)}})}})}),Jm=l.forwardRef((e,t)=>{const{sizes:r,onSizesChange:n,...o}=e,s=Fe(et,e.__scopeScrollArea),[a,c]=l.useState(),d=l.useRef(null),f=se(t,d,s.onScrollbarYChange);return l.useEffect(()=>{d.current&&c(getComputedStyle(d.current))},[d]),i.jsx(Nc,{"data-orientation":"vertical",...o,ref:f,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":on(r)+"px",...e.style},onThumbPointerDown:u=>e.onThumbPointerDown(u.y),onDragScroll:u=>e.onDragScroll(u.y),onWheelScroll:(u,p)=>{if(s.viewport){const m=s.viewport.scrollTop+u.deltaY;e.onWheelScroll(m),kc(m,p)&&u.preventDefault()}},onResize:()=>{d.current&&s.viewport&&a&&n({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:d.current.clientHeight,paddingStart:nn(a.paddingTop),paddingEnd:nn(a.paddingBottom)}})}})}),[Zm,Ec]=wc(et),Nc=l.forwardRef((e,t)=>{const{__scopeScrollArea:r,sizes:n,hasThumb:o,onThumbChange:s,onThumbPointerUp:a,onThumbPointerDown:c,onThumbPositionChange:d,onDragScroll:f,onWheelScroll:u,onResize:p,...m}=e,v=Fe(et,r),[g,h]=l.useState(null),b=se(t,D=>h(D)),w=l.useRef(null),y=l.useRef(""),x=v.viewport,C=n.content-n.viewport,E=Se(u),O=Se(d),N=sn(p,10);function L(D){if(w.current){const $=D.clientX-w.current.left,R=D.clientY-w.current.top;f({x:$,y:R})}}return l.useEffect(()=>{const D=$=>{const R=$.target;(g==null?void 0:g.contains(R))&&E($,C)};return document.addEventListener("wheel",D,{passive:!1}),()=>document.removeEventListener("wheel",D,{passive:!1})},[x,g,C,E]),l.useEffect(O,[n,O]),Ut(g,N),Ut(v.content,N),i.jsx(Zm,{scope:r,scrollbar:g,hasThumb:o,onThumbChange:Se(s),onThumbPointerUp:Se(a),onThumbPositionChange:O,onThumbPointerDown:Se(c),children:i.jsx(Q.div,{...m,ref:b,style:{position:"absolute",...m.style},onPointerDown:U(e.onPointerDown,D=>{D.button===0&&(D.target.setPointerCapture(D.pointerId),w.current=g.getBoundingClientRect(),y.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",v.viewport&&(v.viewport.style.scrollBehavior="auto"),L(D))}),onPointerMove:U(e.onPointerMove,L),onPointerUp:U(e.onPointerUp,D=>{const $=D.target;$.hasPointerCapture(D.pointerId)&&$.releasePointerCapture(D.pointerId),document.body.style.webkitUserSelect=y.current,v.viewport&&(v.viewport.style.scrollBehavior=""),w.current=null})})})}),rn="ScrollAreaThumb",Tc=l.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=Ec(rn,e.__scopeScrollArea);return i.jsx(_e,{present:r||o.hasThumb,children:i.jsx(Qm,{ref:t,...n})})}),Qm=l.forwardRef((e,t)=>{const{__scopeScrollArea:r,style:n,...o}=e,s=Fe(rn,r),a=Ec(rn,r),{onThumbPositionChange:c}=a,d=se(t,p=>a.onThumbChange(p)),f=l.useRef(void 0),u=sn(()=>{f.current&&(f.current(),f.current=void 0)},100);return l.useEffect(()=>{const p=s.viewport;if(p){const m=()=>{if(u(),!f.current){const v=rb(p,c);f.current=v,c()}};return c(),p.addEventListener("scroll",m),()=>p.removeEventListener("scroll",m)}},[s.viewport,u,c]),i.jsx(Q.div,{"data-state":a.hasThumb?"visible":"hidden",...o,ref:d,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...n},onPointerDownCapture:U(e.onPointerDownCapture,p=>{const v=p.target.getBoundingClientRect(),g=p.clientX-v.left,h=p.clientY-v.top;a.onThumbPointerDown({x:g,y:h})}),onPointerUp:U(e.onPointerUp,a.onThumbPointerUp)})});Tc.displayName=rn;var Ho="ScrollAreaCorner",Ac=l.forwardRef((e,t)=>{const r=Fe(Ho,e.__scopeScrollArea),n=!!(r.scrollbarX&&r.scrollbarY);return r.type!=="scroll"&&n?i.jsx(eb,{...e,ref:t}):null});Ac.displayName=Ho;var eb=l.forwardRef((e,t)=>{const{__scopeScrollArea:r,...n}=e,o=Fe(Ho,r),[s,a]=l.useState(0),[c,d]=l.useState(0),f=!!(s&&c);return Ut(o.scrollbarX,()=>{var p;const u=((p=o.scrollbarX)==null?void 0:p.offsetHeight)||0;o.onCornerHeightChange(u),d(u)}),Ut(o.scrollbarY,()=>{var p;const u=((p=o.scrollbarY)==null?void 0:p.offsetWidth)||0;o.onCornerWidthChange(u),a(u)}),f?i.jsx(Q.div,{...n,ref:t,style:{width:s,height:c,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function nn(e){return e?parseInt(e,10):0}function Pc(e,t){const r=e/t;return isNaN(r)?0:r}function on(e){const t=Pc(e.viewport,e.content),r=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,n=(e.scrollbar.size-r)*t;return Math.max(n,18)}function tb(e,t,r,n="ltr"){const o=on(r),s=o/2,a=t||s,c=o-a,d=r.scrollbar.paddingStart+a,f=r.scrollbar.size-r.scrollbar.paddingEnd-c,u=r.content-r.viewport,p=n==="ltr"?[0,u]:[u*-1,0];return Ic([d,f],p)(e)}function _c(e,t,r="ltr"){const n=on(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,a=t.content-t.viewport,c=s-n,d=r==="ltr"?[0,a]:[a*-1,0],f=Fo(e,d);return Ic([0,a],[0,c])(f)}function Ic(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 kc(e,t){return e>0&&e<t}var rb=(e,t=()=>{})=>{let r={left:e.scrollLeft,top:e.scrollTop},n=0;return function o(){const s={left:e.scrollLeft,top:e.scrollTop},a=r.left!==s.left,c=r.top!==s.top;(a||c)&&t(),r=s,n=window.requestAnimationFrame(o)}(),()=>window.cancelAnimationFrame(n)};function sn(e,t){const r=Se(e),n=l.useRef(0);return l.useEffect(()=>()=>window.clearTimeout(n.current),[]),l.useCallback(()=>{window.clearTimeout(n.current),n.current=window.setTimeout(r,t)},[r,t])}function Ut(e,t){const r=Se(t);xe(()=>{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 Oc=yc,nb=Sc,ob=Ac;const Mc=l.forwardRef(({className:e,children:t,...r},n)=>i.jsxs(Oc,{ref:n,className:A("relative overflow-hidden",e),...r,children:[i.jsx(nb,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),i.jsx(Dc,{}),i.jsx(ob,{})]}));Mc.displayName=Oc.displayName;const Dc=l.forwardRef(({className:e,orientation:t="vertical",...r},n)=>i.jsx(Bo,{ref:n,orientation:t,className:A("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:i.jsx(Tc,{className:"relative flex-1 rounded-full bg-border"})}));Dc.displayName=Bo.displayName;function an({className:e="",showCreateButton:t=!0,showDeleteButton:r=!0,showEditTitle:n=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:a=null,navigateToThread:c,onThreadSelect:d,onThreadCreate:f,onThreadDelete:u}){const{loadThread:p,threads:m,refreshThreads:v,currentThreadId:g,createThread:h,deleteThread:b,renameThread:w}=jn(),[y,x]=T.useState(m??[]),[C,E]=T.useState(!1),[O,N]=T.useState(null),[L,D]=T.useState(null),[$,R]=T.useState(""),[X,B]=T.useState(!1);T.useEffect(()=>{x(m??[])},[m]);const M=async I=>{try{await p(I),c==null||c(I),d==null||d(I)}catch(W){console.error("Failed to select thread:",W)}},J=async()=>{try{B(!0);const I=await h();f==null||f(I),c==null||c(I)}catch(I){console.error("Failed to create thread:",I)}finally{B(!1)}},F=async(I,W)=>{if(W.stopPropagation(),!!confirm("Delete this thread?"))try{await b(I),u==null||u(I)}catch(ge){console.error("Failed to delete thread:",ge)}},H=(I,W)=>{W.stopPropagation(),D(I.threadId),R(I.title||`Thread ${I.threadId.slice(0,8)}`)},P=async I=>{if($.trim())try{await w(I,$.trim()),D(null),R("")}catch(W){console.error("Failed to update title:",W)}},_=()=>{D(null),R("")},G=(I,W)=>{I.key==="Enter"?P(W):I.key==="Escape"&&_()},j=I=>{if(!I)return"";try{const W=new Date(I),he=new Date().getTime()-W.getTime(),z=Math.floor(he/(1e3*60*60*24));return z===0?W.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):z===1?"Yesterday":z<7?`${z} days ago`:W.toLocaleDateString()}catch{return""}},Z=I=>I.title||`Thread ${I.threadId.slice(0,8)}`;return i.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&i.jsx("div",{className:s.header||"flex-shrink-0 p-2 border-b bg-slate-800 border-slate-700 text-slate-100 flex justify-end",children:i.jsx(me,{onClick:J,disabled:X||C,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:X?"Creating...":"New Chat",children:i.jsx(q.MessageSquarePlus,{size:20})})}),i.jsx(Mc,{className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:i.jsx("div",{className:"p-2 space-y-1 pb-4",children:C?i.jsx("div",{className:"text-center py-8 text-slate-400",children:"Loading…"}):y.length===0?i.jsxs("div",{className:"text-center py-8 text-slate-400",children:[i.jsx(q.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),i.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):y.slice().sort((I,W)=>new Date(W.updatedAt||W.createdAt||"").getTime()-new Date(I.updatedAt||I.createdAt||"").getTime()).map(I=>i.jsxs("div",{onClick:()=>M(I.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(a??g)===I.threadId?`${s.activeThread||"bg-slate-600 border-slate-500"} `:`${s.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${s.threadItem||""} text-gray-900 dark:text-slate-100`,children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("div",{className:"flex-1 min-w-0",children:L===I.threadId?i.jsxs("div",{className:"flex items-center gap-2",onClick:W=>W.stopPropagation(),children:[i.jsx(lr,{value:$,onChange:W=>R(W.target.value),onKeyDown:W=>G(W,I.threadId),className:"h-6 text-sm",autoFocus:!0}),i.jsx(me,{variant:"ghost",size:"sm",onClick:()=>P(I.threadId),className:"h-6 w-6 p-0",children:i.jsx(q.Check,{size:12})}),i.jsx(me,{variant:"ghost",size:"sm",onClick:_,className:"h-6 w-6 p-0",children:i.jsx(q.X,{size:12})})]}):i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:Z(I)}),i.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[i.jsx(q.Calendar,{size:10}),i.jsx("span",{children:j(I.updatedAt||I.createdAt)})]})]})}),i.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[n&&L!==I.threadId&&i.jsx(me,{variant:"ghost",size:"sm",onClick:W=>H(I,W),className:"h-6 w-6 p-0",title:"Edit title",children:i.jsx(q.Edit3,{size:12})}),r&&i.jsx(me,{variant:"ghost",size:"sm",onClick:W=>F(I.threadId,W),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:i.jsx(q.Trash2,{size:12})})]})]}),a===I.threadId&&i.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},I.threadId))})})]})}const Lc=T.createContext(null);function sb({children:e,basePath:t="/chat"}){const r=T.useMemo(()=>t?t==="/"?"":t.endsWith("/")?t.slice(0,-1):t:"/chat",[t]),n={basePath:r,buildThreadPath:o=>`${r}/${o}`,buildBasePath:()=>r};return i.jsx(Lc.Provider,{value:n,children:e})}function ab(){const e=T.useContext(Lc);return e||{basePath:"/chat",buildThreadPath:t=>`/chat/${t}`,buildBasePath:()=>"/chat"}}const Fc={BASE_URL:"/",DEV:!1,MODE:"library",PROD:!0,SSR:!1};function dr(e){var o;const t=typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Nn&&Nn.tagName.toUpperCase()==="SCRIPT"&&Nn.src||new URL("index.umd.js",document.baseURI).href}<"u"&&Fc?Fc[e]:void 0,r=(o=globalThis==null?void 0:globalThis.process)==null?void 0:o.env,n=r?r[e]:void 0;return(t??n)||void 0}function ib(){return dr("VITE_API_BASE_URL")||dr("NEXT_PUBLIC_API_BASE_URL")||void 0}function cb(){return dr("VITE_API_KEY")||dr("NEXT_PUBLIC_API_KEY")||dr("VITE_AUTH_TOKEN")||void 0}function $c(){const e=ib(),t=cb(),r={};return e&&(r.baseUrl=e),t&&(r.apiKey=t),r}function Bc(){const e=$c(),t=tt.getAuthToken();return{apiBaseUrl:e.baseUrl||tt.baseUrl||"http://localhost:8000",apiKey:t||e.apiKey||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,truncateToolMessages:!0,toolMessagePreviewLength:200,darkMode:!1,enableSound:!1,messageHistory:100}}const Uc="chat-settings";function lb(){try{const e=localStorage.getItem(Uc);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function db(e){try{localStorage.setItem(Uc,JSON.stringify(e)),e.apiKey&&tt.setAuthToken(e.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function ub(){const e=Bc(),t=lb(),r=tt.getAuthToken();return{...e,...t,apiKey:r||t.apiKey||e.apiKey,apiBaseUrl:tt.baseUrl||t.apiBaseUrl||e.apiBaseUrl}}function fb(e){e.apiKey&&tt.setAuthToken(e.apiKey),db(e)}const zo=768;function pb(){const[e,t]=l.useState(void 0);return l.useEffect(()=>{const r=window.matchMedia(`(max-width: ${zo-1}px)`),n=()=>{t(window.innerWidth<zo)};return r.addEventListener("change",n),t(window.innerWidth<zo),()=>r.removeEventListener("change",n)},[]),!!e}var hb="Separator",Hc="horizontal",gb=["horizontal","vertical"],zc=l.forwardRef((e,t)=>{const{decorative:r,orientation:n=Hc,...o}=e,s=mb(n)?n:Hc,c=r?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return i.jsx(Q.div,{"data-orientation":s,...c,...o,ref:t})});zc.displayName=hb;function mb(e){return gb.includes(e)}var Wc=zc;const Wo=l.forwardRef(({className:e,orientation:t="horizontal",decorative:r=!0,...n},o)=>i.jsx(Wc,{ref:o,decorative:r,orientation:t,className:A("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...n}));Wo.displayName=Wc.displayName;var cn="Dialog",[Vc,Vw]=Ue(cn),[bb,Ve]=Vc(cn),jc=e=>{const{__scopeDialog:t,children:r,open:n,defaultOpen:o,onOpenChange:s,modal:a=!0}=e,c=l.useRef(null),d=l.useRef(null),[f,u]=st({prop:n,defaultProp:o??!1,onChange:s,caller:cn});return i.jsx(bb,{scope:t,triggerRef:c,contentRef:d,contentId:He(),titleId:He(),descriptionId:He(),open:f,onOpenChange:u,onOpenToggle:l.useCallback(()=>u(p=>!p),[u]),modal:a,children:r})};jc.displayName=cn;var Rc="DialogTrigger",Kc=l.forwardRef((e,t)=>{const{__scopeDialog:r,...n}=e,o=Ve(Rc,r),s=se(t,o.triggerRef);return i.jsx(Q.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Ro(o.open),...n,ref:s,onClick:U(e.onClick,o.onOpenToggle)})});Kc.displayName=Rc;var Vo="DialogPortal",[vb,Gc]=Vc(Vo,{forceMount:void 0}),qc=e=>{const{__scopeDialog:t,forceMount:r,children:n,container:o}=e,s=Ve(Vo,t);return i.jsx(vb,{scope:t,forceMount:r,children:l.Children.map(n,a=>i.jsx(_e,{present:r||s.open,children:i.jsx(Wr,{asChild:!0,container:o,children:a})}))})};qc.displayName=Vo;var ln="DialogOverlay",Xc=l.forwardRef((e,t)=>{const r=Gc(ln,e.__scopeDialog),{forceMount:n=r.forceMount,...o}=e,s=Ve(ln,e.__scopeDialog);return s.modal?i.jsx(_e,{present:n||s.open,children:i.jsx(yb,{...o,ref:t})}):null});Xc.displayName=ln;var wb=Oe.createSlot("DialogOverlay.RemoveScroll"),yb=l.forwardRef((e,t)=>{const{__scopeDialog:r,...n}=e,o=Ve(ln,r);return i.jsx(Yr,{as:wb,allowPinchZoom:!0,shards:[o.contentRef],children:i.jsx(Q.div,{"data-state":Ro(o.open),...n,ref:t,style:{pointerEvents:"auto",...n.style}})})}),yt="DialogContent",Yc=l.forwardRef((e,t)=>{const r=Gc(yt,e.__scopeDialog),{forceMount:n=r.forceMount,...o}=e,s=Ve(yt,e.__scopeDialog);return i.jsx(_e,{present:n||s.open,children:s.modal?i.jsx(xb,{...o,ref:t}):i.jsx(Sb,{...o,ref:t})})});Yc.displayName=yt;var xb=l.forwardRef((e,t)=>{const r=Ve(yt,e.__scopeDialog),n=l.useRef(null),o=se(t,r.contentRef,n);return l.useEffect(()=>{const s=n.current;if(s)return Co(s)},[]),i.jsx(Jc,{...e,ref:o,trapFocus:r.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:U(e.onCloseAutoFocus,s=>{var a;s.preventDefault(),(a=r.triggerRef.current)==null||a.focus()}),onPointerDownOutside:U(e.onPointerDownOutside,s=>{const a=s.detail.originalEvent,c=a.button===0&&a.ctrlKey===!0;(a.button===2||c)&&s.preventDefault()}),onFocusOutside:U(e.onFocusOutside,s=>s.preventDefault())})}),Sb=l.forwardRef((e,t)=>{const r=Ve(yt,e.__scopeDialog),n=l.useRef(!1),o=l.useRef(!1);return i.jsx(Jc,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var a,c;(a=e.onCloseAutoFocus)==null||a.call(e,s),s.defaultPrevented||(n.current||(c=r.triggerRef.current)==null||c.focus(),s.preventDefault()),n.current=!1,o.current=!1},onInteractOutside:s=>{var d,f;(d=e.onInteractOutside)==null||d.call(e,s),s.defaultPrevented||(n.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const a=s.target;((f=r.triggerRef.current)==null?void 0:f.contains(a))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),Jc=l.forwardRef((e,t)=>{const{__scopeDialog:r,trapFocus:n,onOpenAutoFocus:o,onCloseAutoFocus:s,...a}=e,c=Ve(yt,r),d=l.useRef(null),f=se(t,d);return Qn(),i.jsxs(i.Fragment,{children:[i.jsx(kr,{asChild:!0,loop:!0,trapped:n,onMountAutoFocus:o,onUnmountAutoFocus:s,children:i.jsx(Zt,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionId,"aria-labelledby":c.titleId,"data-state":Ro(c.open),...a,ref:f,onDismiss:()=>c.onOpenChange(!1)})}),i.jsxs(i.Fragment,{children:[i.jsx(Cb,{titleId:c.titleId}),i.jsx(Nb,{contentRef:d,descriptionId:c.descriptionId})]})]})}),jo="DialogTitle",Zc=l.forwardRef((e,t)=>{const{__scopeDialog:r,...n}=e,o=Ve(jo,r);return i.jsx(Q.h2,{id:o.titleId,...n,ref:t})});Zc.displayName=jo;var Qc="DialogDescription",el=l.forwardRef((e,t)=>{const{__scopeDialog:r,...n}=e,o=Ve(Qc,r);return i.jsx(Q.p,{id:o.descriptionId,...n,ref:t})});el.displayName=Qc;var tl="DialogClose",rl=l.forwardRef((e,t)=>{const{__scopeDialog:r,...n}=e,o=Ve(tl,r);return i.jsx(Q.button,{type:"button",...n,ref:t,onClick:U(e.onClick,()=>o.onOpenChange(!1))})});rl.displayName=tl;function Ro(e){return e?"open":"closed"}var nl="DialogTitleWarning",[jw,ol]=wf(nl,{contentName:yt,titleName:jo,docsSlug:"dialog"}),Cb=({titleId:e})=>{const t=ol(nl),r=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
|
|
58
|
+
`)},Ng=0,Bt=[];function Tg(e){var t=l.useRef([]),r=l.useRef([0,0]),n=l.useRef(),o=l.useState(Ng++)[0],s=l.useState(gi)[0],a=l.useRef(e);l.useEffect(function(){a.current=e},[e]),l.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var h=Gh([e.lockRef.current],(e.shards||[]).map(Si),!0).filter(Boolean);return h.forEach(function(b){return b.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),h.forEach(function(b){return b.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var c=l.useCallback(function(h,b){if("touches"in h&&h.touches.length===2||h.type==="wheel"&&h.ctrlKey)return!a.current.allowPinchZoom;var w=Xr(h),y=r.current,x="deltaX"in h?h.deltaX:y[0]-w[0],C="deltaY"in h?h.deltaY:y[1]-w[1],E,O=h.target,N=Math.abs(x)>Math.abs(C)?"h":"v";if("touches"in h&&N==="h"&&O.type==="range")return!1;var L=vi(N,O);if(!L)return!0;if(L?E=N:(E=N==="v"?"h":"v",L=vi(N,O)),!L)return!1;if(!n.current&&"changedTouches"in h&&(x||C)&&(n.current=E),!E)return!0;var D=n.current||E;return Sg(D,b,h,D==="h"?x:C)},[]),d=l.useCallback(function(h){var b=h;if(!(!Bt.length||Bt[Bt.length-1]!==s)){var w="deltaY"in b?xi(b):Xr(b),y=t.current.filter(function(E){return E.name===b.type&&(E.target===b.target||b.target===E.shadowParent)&&Cg(E.delta,w)})[0];if(y&&y.should){b.cancelable&&b.preventDefault();return}if(!y){var x=(a.current.shards||[]).map(Si).filter(Boolean).filter(function(E){return E.contains(b.target)}),C=x.length>0?c(b,x[0]):!a.current.noIsolation;C&&b.cancelable&&b.preventDefault()}}},[]),f=l.useCallback(function(h,b,w,y){var x={name:h,delta:b,target:w,should:y,shadowParent:Ag(w)};t.current.push(x),setTimeout(function(){t.current=t.current.filter(function(C){return C!==x})},1)},[]),u=l.useCallback(function(h){r.current=Xr(h),n.current=void 0},[]),p=l.useCallback(function(h){f(h.type,xi(h),h.target,c(h,e.lockRef.current))},[]),m=l.useCallback(function(h){f(h.type,Xr(h),h.target,c(h,e.lockRef.current))},[]);l.useEffect(function(){return Bt.push(s),e.setCallbacks({onScrollCapture:p,onWheelCapture:p,onTouchMoveCapture:m}),document.addEventListener("wheel",d,$t),document.addEventListener("touchmove",d,$t),document.addEventListener("touchstart",u,$t),function(){Bt=Bt.filter(function(h){return h!==s}),document.removeEventListener("wheel",d,$t),document.removeEventListener("touchmove",d,$t),document.removeEventListener("touchstart",u,$t)}},[]);var v=e.removeScrollBar,g=e.inert;return l.createElement(l.Fragment,null,g?l.createElement(s,{styles:Eg(o)}):null,v?l.createElement(gg,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Ag(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Pg=rg(hi,Tg);var Yr=l.forwardRef(function(e,t){return l.createElement(Gr,Qe({},e,{ref:t,sideCar:Pg}))});Yr.classNames=Gr.classNames;var Po=["Enter"," "],_g=["ArrowDown","PageUp","Home"],Ci=["ArrowUp","PageDown","End"],Ig=[..._g,...Ci],kg={ltr:[...Po,"ArrowRight"],rtl:[...Po,"ArrowLeft"]},Og={ltr:["ArrowLeft"],rtl:["ArrowRight"]},nr="Menu",[or,Mg,Dg]=Yn(nr),[vt,Ei]=Ue(nr,[Dg,Dt,si]),Jr=Dt(),Ni=si(),[Lg,wt]=vt(nr),[Fg,sr]=vt(nr),Ti=e=>{const{__scopeMenu:t,open:r=!1,children:n,dir:o,onOpenChange:s,modal:a=!0}=e,c=Jr(t),[d,f]=l.useState(null),u=l.useRef(!1),p=Se(s),m=Ir(o);return l.useEffect(()=>{const v=()=>{u.current=!0,document.addEventListener("pointerdown",g,{capture:!0,once:!0}),document.addEventListener("pointermove",g,{capture:!0,once:!0})},g=()=>u.current=!1;return document.addEventListener("keydown",v,{capture:!0}),()=>{document.removeEventListener("keydown",v,{capture:!0}),document.removeEventListener("pointerdown",g,{capture:!0}),document.removeEventListener("pointermove",g,{capture:!0})}},[]),i.jsx(mo,{...c,children:i.jsx(Lg,{scope:t,open:r,onOpenChange:p,content:d,onContentChange:f,children:i.jsx(Fg,{scope:t,onClose:l.useCallback(()=>p(!1),[p]),isUsingKeyboardRef:u,dir:m,modal:a,children:n})})})};Ti.displayName=nr;var $g="MenuAnchor",_o=l.forwardRef((e,t)=>{const{__scopeMenu:r,...n}=e,o=Jr(r);return i.jsx(bo,{...o,...n,ref:t})});_o.displayName=$g;var Io="MenuPortal",[Bg,Ai]=vt(Io,{forceMount:void 0}),Pi=e=>{const{__scopeMenu:t,forceMount:r,children:n,container:o}=e,s=wt(Io,t);return i.jsx(Bg,{scope:t,forceMount:r,children:i.jsx(_e,{present:r||s.open,children:i.jsx(Wr,{asChild:!0,container:o,children:n})})})};Pi.displayName=Io;var Le="MenuContent",[Ug,ko]=vt(Le),_i=l.forwardRef((e,t)=>{const r=Ai(Le,e.__scopeMenu),{forceMount:n=r.forceMount,...o}=e,s=wt(Le,e.__scopeMenu),a=sr(Le,e.__scopeMenu);return i.jsx(or.Provider,{scope:e.__scopeMenu,children:i.jsx(_e,{present:n||s.open,children:i.jsx(or.Slot,{scope:e.__scopeMenu,children:a.modal?i.jsx(Hg,{...o,ref:t}):i.jsx(zg,{...o,ref:t})})})})}),Hg=l.forwardRef((e,t)=>{const r=wt(Le,e.__scopeMenu),n=l.useRef(null),o=se(t,n);return l.useEffect(()=>{const s=n.current;if(s)return Co(s)},[]),i.jsx(Oo,{...e,ref:o,trapFocus:r.open,disableOutsidePointerEvents:r.open,disableOutsideScroll:!0,onFocusOutside:U(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>r.onOpenChange(!1)})}),zg=l.forwardRef((e,t)=>{const r=wt(Le,e.__scopeMenu);return i.jsx(Oo,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>r.onOpenChange(!1)})}),Wg=Oe.createSlot("MenuContent.ScrollLock"),Oo=l.forwardRef((e,t)=>{const{__scopeMenu:r,loop:n=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:a,disableOutsidePointerEvents:c,onEntryFocus:d,onEscapeKeyDown:f,onPointerDownOutside:u,onFocusOutside:p,onInteractOutside:m,onDismiss:v,disableOutsideScroll:g,...h}=e,b=wt(Le,r),w=sr(Le,r),y=Jr(r),x=Ni(r),C=Mg(r),[E,O]=l.useState(null),N=l.useRef(null),L=se(t,N,b.onContentChange),D=l.useRef(0),$=l.useRef(""),R=l.useRef(0),X=l.useRef(null),B=l.useRef("right"),M=l.useRef(0),J=g?Yr:l.Fragment,F=g?{as:Wg,allowPinchZoom:!0}:void 0,H=_=>{var z,ce;const G=$.current+_,j=C().filter(pe=>!pe.disabled),Z=document.activeElement,I=(z=j.find(pe=>pe.ref.current===Z))==null?void 0:z.textValue,W=j.map(pe=>pe.textValue),ge=em(W,G,I),he=(ce=j.find(pe=>pe.textValue===ge))==null?void 0:ce.ref.current;(function pe(le){$.current=le,window.clearTimeout(D.current),le!==""&&(D.current=window.setTimeout(()=>pe(""),1e3))})(G),he&&setTimeout(()=>he.focus())};l.useEffect(()=>()=>window.clearTimeout(D.current),[]),Qn();const P=l.useCallback(_=>{var j,Z;return B.current===((j=X.current)==null?void 0:j.side)&&rm(_,(Z=X.current)==null?void 0:Z.area)},[]);return i.jsx(Ug,{scope:r,searchRef:$,onItemEnter:l.useCallback(_=>{P(_)&&_.preventDefault()},[P]),onItemLeave:l.useCallback(_=>{var G;P(_)||((G=N.current)==null||G.focus(),O(null))},[P]),onTriggerLeave:l.useCallback(_=>{P(_)&&_.preventDefault()},[P]),pointerGraceTimerRef:R,onPointerGraceIntentChange:l.useCallback(_=>{X.current=_},[]),children:i.jsx(J,{...F,children:i.jsx(kr,{asChild:!0,trapped:o,onMountAutoFocus:U(s,_=>{var G;_.preventDefault(),(G=N.current)==null||G.focus({preventScroll:!0})}),onUnmountAutoFocus:a,children:i.jsx(Zt,{asChild:!0,disableOutsidePointerEvents:c,onEscapeKeyDown:f,onPointerDownOutside:u,onFocusOutside:p,onInteractOutside:m,onDismiss:v,children:i.jsx(Wh,{asChild:!0,...x,dir:w.dir,orientation:"vertical",loop:n,currentTabStopId:E,onCurrentTabStopIdChange:O,onEntryFocus:U(d,_=>{w.isUsingKeyboardRef.current||_.preventDefault()}),preventScrollOnEntryFocus:!0,children:i.jsx(vo,{role:"menu","aria-orientation":"vertical","data-state":Ki(b.open),"data-radix-menu-content":"",dir:w.dir,...y,...h,ref:L,style:{outline:"none",...h.style},onKeyDown:U(h.onKeyDown,_=>{const j=_.target.closest("[data-radix-menu-content]")===_.currentTarget,Z=_.ctrlKey||_.altKey||_.metaKey,I=_.key.length===1;j&&(_.key==="Tab"&&_.preventDefault(),!Z&&I&&H(_.key));const W=N.current;if(_.target!==W||!Ig.includes(_.key))return;_.preventDefault();const he=C().filter(z=>!z.disabled).map(z=>z.ref.current);Ci.includes(_.key)&&he.reverse(),Zg(he)}),onBlur:U(e.onBlur,_=>{_.currentTarget.contains(_.target)||(window.clearTimeout(D.current),$.current="")}),onPointerMove:U(e.onPointerMove,ir(_=>{const G=_.target,j=M.current!==_.clientX;if(_.currentTarget.contains(G)&&j){const Z=_.clientX>M.current?"right":"left";B.current=Z,M.current=_.clientX}}))})})})})})})});_i.displayName=Le;var Vg="MenuGroup",Mo=l.forwardRef((e,t)=>{const{__scopeMenu:r,...n}=e;return i.jsx(Q.div,{role:"group",...n,ref:t})});Mo.displayName=Vg;var jg="MenuLabel",Ii=l.forwardRef((e,t)=>{const{__scopeMenu:r,...n}=e;return i.jsx(Q.div,{...n,ref:t})});Ii.displayName=jg;var Zr="MenuItem",ki="menu.itemSelect",Qr=l.forwardRef((e,t)=>{const{disabled:r=!1,onSelect:n,...o}=e,s=l.useRef(null),a=sr(Zr,e.__scopeMenu),c=ko(Zr,e.__scopeMenu),d=se(t,s),f=l.useRef(!1),u=()=>{const p=s.current;if(!r&&p){const m=new CustomEvent(ki,{bubbles:!0,cancelable:!0});p.addEventListener(ki,v=>n==null?void 0:n(v),{once:!0}),aa(p,m),m.defaultPrevented?f.current=!1:a.onClose()}};return i.jsx(Oi,{...o,ref:d,disabled:r,onClick:U(e.onClick,u),onPointerDown:p=>{var m;(m=e.onPointerDown)==null||m.call(e,p),f.current=!0},onPointerUp:U(e.onPointerUp,p=>{var m;f.current||(m=p.currentTarget)==null||m.click()}),onKeyDown:U(e.onKeyDown,p=>{const m=c.searchRef.current!=="";r||m&&p.key===" "||Po.includes(p.key)&&(p.currentTarget.click(),p.preventDefault())})})});Qr.displayName=Zr;var Oi=l.forwardRef((e,t)=>{const{__scopeMenu:r,disabled:n=!1,textValue:o,...s}=e,a=ko(Zr,r),c=Ni(r),d=l.useRef(null),f=se(t,d),[u,p]=l.useState(!1),[m,v]=l.useState("");return l.useEffect(()=>{const g=d.current;g&&v((g.textContent??"").trim())},[s.children]),i.jsx(or.ItemSlot,{scope:r,disabled:n,textValue:o??m,children:i.jsx(Vh,{asChild:!0,...c,focusable:!n,children:i.jsx(Q.div,{role:"menuitem","data-highlighted":u?"":void 0,"aria-disabled":n||void 0,"data-disabled":n?"":void 0,...s,ref:f,onPointerMove:U(e.onPointerMove,ir(g=>{n?a.onItemLeave(g):(a.onItemEnter(g),g.defaultPrevented||g.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:U(e.onPointerLeave,ir(g=>a.onItemLeave(g))),onFocus:U(e.onFocus,()=>p(!0)),onBlur:U(e.onBlur,()=>p(!1))})})})}),Rg="MenuCheckboxItem",Mi=l.forwardRef((e,t)=>{const{checked:r=!1,onCheckedChange:n,...o}=e;return i.jsx(Bi,{scope:e.__scopeMenu,checked:r,children:i.jsx(Qr,{role:"menuitemcheckbox","aria-checked":en(r)?"mixed":r,...o,ref:t,"data-state":Lo(r),onSelect:U(o.onSelect,()=>n==null?void 0:n(en(r)?!0:!r),{checkForDefaultPrevented:!1})})})});Mi.displayName=Rg;var Di="MenuRadioGroup",[Kg,Gg]=vt(Di,{value:void 0,onValueChange:()=>{}}),Li=l.forwardRef((e,t)=>{const{value:r,onValueChange:n,...o}=e,s=Se(n);return i.jsx(Kg,{scope:e.__scopeMenu,value:r,onValueChange:s,children:i.jsx(Mo,{...o,ref:t})})});Li.displayName=Di;var Fi="MenuRadioItem",$i=l.forwardRef((e,t)=>{const{value:r,...n}=e,o=Gg(Fi,e.__scopeMenu),s=r===o.value;return i.jsx(Bi,{scope:e.__scopeMenu,checked:s,children:i.jsx(Qr,{role:"menuitemradio","aria-checked":s,...n,ref:t,"data-state":Lo(s),onSelect:U(n.onSelect,()=>{var a;return(a=o.onValueChange)==null?void 0:a.call(o,r)},{checkForDefaultPrevented:!1})})})});$i.displayName=Fi;var Do="MenuItemIndicator",[Bi,qg]=vt(Do,{checked:!1}),Ui=l.forwardRef((e,t)=>{const{__scopeMenu:r,forceMount:n,...o}=e,s=qg(Do,r);return i.jsx(_e,{present:n||en(s.checked)||s.checked===!0,children:i.jsx(Q.span,{...o,ref:t,"data-state":Lo(s.checked)})})});Ui.displayName=Do;var Xg="MenuSeparator",Hi=l.forwardRef((e,t)=>{const{__scopeMenu:r,...n}=e;return i.jsx(Q.div,{role:"separator","aria-orientation":"horizontal",...n,ref:t})});Hi.displayName=Xg;var Yg="MenuArrow",zi=l.forwardRef((e,t)=>{const{__scopeMenu:r,...n}=e,o=Jr(r);return i.jsx(wo,{...o,...n,ref:t})});zi.displayName=Yg;var Jg="MenuSub",[Hw,Wi]=vt(Jg),ar="MenuSubTrigger",Vi=l.forwardRef((e,t)=>{const r=wt(ar,e.__scopeMenu),n=sr(ar,e.__scopeMenu),o=Wi(ar,e.__scopeMenu),s=ko(ar,e.__scopeMenu),a=l.useRef(null),{pointerGraceTimerRef:c,onPointerGraceIntentChange:d}=s,f={__scopeMenu:e.__scopeMenu},u=l.useCallback(()=>{a.current&&window.clearTimeout(a.current),a.current=null},[]);return l.useEffect(()=>u,[u]),l.useEffect(()=>{const p=c.current;return()=>{window.clearTimeout(p),d(null)}},[c,d]),i.jsx(_o,{asChild:!0,...f,children:i.jsx(Oi,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":r.open,"aria-controls":o.contentId,"data-state":Ki(r.open),...e,ref:Rn(t,o.onTriggerChange),onClick:p=>{var m;(m=e.onClick)==null||m.call(e,p),!(e.disabled||p.defaultPrevented)&&(p.currentTarget.focus(),r.open||r.onOpenChange(!0))},onPointerMove:U(e.onPointerMove,ir(p=>{s.onItemEnter(p),!p.defaultPrevented&&!e.disabled&&!r.open&&!a.current&&(s.onPointerGraceIntentChange(null),a.current=window.setTimeout(()=>{r.onOpenChange(!0),u()},100))})),onPointerLeave:U(e.onPointerLeave,ir(p=>{var v,g;u();const m=(v=r.content)==null?void 0:v.getBoundingClientRect();if(m){const h=(g=r.content)==null?void 0:g.dataset.side,b=h==="right",w=b?-5:5,y=m[b?"left":"right"],x=m[b?"right":"left"];s.onPointerGraceIntentChange({area:[{x:p.clientX+w,y:p.clientY},{x:y,y:m.top},{x,y:m.top},{x,y:m.bottom},{x:y,y:m.bottom}],side:h}),window.clearTimeout(c.current),c.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(p),p.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:U(e.onKeyDown,p=>{var v;const m=s.searchRef.current!=="";e.disabled||m&&p.key===" "||kg[n.dir].includes(p.key)&&(r.onOpenChange(!0),(v=r.content)==null||v.focus(),p.preventDefault())})})})});Vi.displayName=ar;var ji="MenuSubContent",Ri=l.forwardRef((e,t)=>{const r=Ai(Le,e.__scopeMenu),{forceMount:n=r.forceMount,...o}=e,s=wt(Le,e.__scopeMenu),a=sr(Le,e.__scopeMenu),c=Wi(ji,e.__scopeMenu),d=l.useRef(null),f=se(t,d);return i.jsx(or.Provider,{scope:e.__scopeMenu,children:i.jsx(_e,{present:n||s.open,children:i.jsx(or.Slot,{scope:e.__scopeMenu,children:i.jsx(Oo,{id:c.contentId,"aria-labelledby":c.triggerId,...o,ref:f,align:"start",side:a.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:u=>{var p;a.isUsingKeyboardRef.current&&((p=d.current)==null||p.focus()),u.preventDefault()},onCloseAutoFocus:u=>u.preventDefault(),onFocusOutside:U(e.onFocusOutside,u=>{u.target!==c.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:U(e.onEscapeKeyDown,u=>{a.onClose(),u.preventDefault()}),onKeyDown:U(e.onKeyDown,u=>{var v;const p=u.currentTarget.contains(u.target),m=Og[a.dir].includes(u.key);p&&m&&(s.onOpenChange(!1),(v=c.trigger)==null||v.focus(),u.preventDefault())})})})})})});Ri.displayName=ji;function Ki(e){return e?"open":"closed"}function en(e){return e==="indeterminate"}function Lo(e){return en(e)?"indeterminate":e?"checked":"unchecked"}function Zg(e){const t=document.activeElement;for(const r of e)if(r===t||(r.focus(),document.activeElement!==t))return}function Qg(e,t){return e.map((r,n)=>e[(t+n)%e.length])}function em(e,t,r){const o=t.length>1&&Array.from(t).every(f=>f===t[0])?t[0]:t,s=r?e.indexOf(r):-1;let a=Qg(e,Math.max(s,0));o.length===1&&(a=a.filter(f=>f!==r));const d=a.find(f=>f.toLowerCase().startsWith(o.toLowerCase()));return d!==r?d:void 0}function tm(e,t){const{x:r,y:n}=e;let o=!1;for(let s=0,a=t.length-1;s<t.length;a=s++){const c=t[s],d=t[a],f=c.x,u=c.y,p=d.x,m=d.y;u>n!=m>n&&r<(p-f)*(n-u)/(m-u)+f&&(o=!o)}return o}function rm(e,t){if(!t)return!1;const r={x:e.clientX,y:e.clientY};return tm(r,t)}function ir(e){return t=>t.pointerType==="mouse"?e(t):void 0}var nm=Ti,om=_o,sm=Pi,am=_i,im=Mo,cm=Ii,lm=Qr,dm=Mi,um=Li,fm=$i,pm=Ui,hm=Hi,gm=zi,mm=Vi,bm=Ri,tn="DropdownMenu",[vm,zw]=Ue(tn,[Ei]),Ee=Ei(),[wm,Gi]=vm(tn),qi=e=>{const{__scopeDropdownMenu:t,children:r,dir:n,open:o,defaultOpen:s,onOpenChange:a,modal:c=!0}=e,d=Ee(t),f=l.useRef(null),[u,p]=st({prop:o,defaultProp:s??!1,onChange:a,caller:tn});return i.jsx(wm,{scope:t,triggerId:He(),triggerRef:f,contentId:He(),open:u,onOpenChange:p,onOpenToggle:l.useCallback(()=>p(m=>!m),[p]),modal:c,children:i.jsx(nm,{...d,open:u,onOpenChange:p,dir:n,modal:c,children:r})})};qi.displayName=tn;var Xi="DropdownMenuTrigger",Yi=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,disabled:n=!1,...o}=e,s=Gi(Xi,r),a=Ee(r);return i.jsx(om,{asChild:!0,...a,children:i.jsx(Q.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":n?"":void 0,disabled:n,...o,ref:Rn(t,s.triggerRef),onPointerDown:U(e.onPointerDown,c=>{!n&&c.button===0&&c.ctrlKey===!1&&(s.onOpenToggle(),s.open||c.preventDefault())}),onKeyDown:U(e.onKeyDown,c=>{n||(["Enter"," "].includes(c.key)&&s.onOpenToggle(),c.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(c.key)&&c.preventDefault())})})})});Yi.displayName=Xi;var ym="DropdownMenuPortal",Ji=e=>{const{__scopeDropdownMenu:t,...r}=e,n=Ee(t);return i.jsx(sm,{...n,...r})};Ji.displayName=ym;var Zi="DropdownMenuContent",Qi=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Gi(Zi,r),s=Ee(r),a=l.useRef(!1);return i.jsx(am,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...n,ref:t,onCloseAutoFocus:U(e.onCloseAutoFocus,c=>{var d;a.current||(d=o.triggerRef.current)==null||d.focus(),a.current=!1,c.preventDefault()}),onInteractOutside:U(e.onInteractOutside,c=>{const d=c.detail.originalEvent,f=d.button===0&&d.ctrlKey===!0,u=d.button===2||f;(!o.modal||u)&&(a.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});Qi.displayName=Zi;var xm="DropdownMenuGroup",Sm=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(im,{...o,...n,ref:t})});Sm.displayName=xm;var Cm="DropdownMenuLabel",ec=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(cm,{...o,...n,ref:t})});ec.displayName=Cm;var Em="DropdownMenuItem",tc=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(lm,{...o,...n,ref:t})});tc.displayName=Em;var Nm="DropdownMenuCheckboxItem",rc=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(dm,{...o,...n,ref:t})});rc.displayName=Nm;var Tm="DropdownMenuRadioGroup",Am=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(um,{...o,...n,ref:t})});Am.displayName=Tm;var Pm="DropdownMenuRadioItem",nc=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(fm,{...o,...n,ref:t})});nc.displayName=Pm;var _m="DropdownMenuItemIndicator",oc=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(pm,{...o,...n,ref:t})});oc.displayName=_m;var Im="DropdownMenuSeparator",sc=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(hm,{...o,...n,ref:t})});sc.displayName=Im;var km="DropdownMenuArrow",Om=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(gm,{...o,...n,ref:t})});Om.displayName=km;var Mm="DropdownMenuSubTrigger",ac=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(mm,{...o,...n,ref:t})});ac.displayName=Mm;var Dm="DropdownMenuSubContent",ic=l.forwardRef((e,t)=>{const{__scopeDropdownMenu:r,...n}=e,o=Ee(r);return i.jsx(bm,{...o,...n,ref:t,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});ic.displayName=Dm;var Lm=qi,Fm=Yi,$m=Ji,cc=Qi,lc=ec,dc=tc,uc=rc,fc=nc,pc=oc,hc=sc,gc=ac,mc=ic;const Bm=Lm,Um=Fm,Hm=l.forwardRef(({className:e,inset:t,children:r,...n},o)=>i.jsxs(gc,{ref:o,className:A("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",t&&"pl-8",e),...n,children:[r,i.jsx(q.ChevronRight,{className:"ml-auto h-4 w-4"})]}));Hm.displayName=gc.displayName;const zm=l.forwardRef(({className:e,...t},r)=>i.jsx(mc,{ref:r,className:A("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...t}));zm.displayName=mc.displayName;const bc=l.forwardRef(({className:e,sideOffset:t=4,...r},n)=>i.jsx($m,{children:i.jsx(cc,{ref:n,sideOffset:t,className:A("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...r})}));bc.displayName=cc.displayName;const vc=l.forwardRef(({className:e,inset:t,...r},n)=>i.jsx(dc,{ref:n,className:A("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...r}));vc.displayName=dc.displayName;const Wm=l.forwardRef(({className:e,children:t,checked:r,...n},o)=>i.jsxs(uc,{ref:o,className:A("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:r,...n,children:[i.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:i.jsx(pc,{children:i.jsx(q.Check,{className:"h-4 w-4"})})}),t]}));Wm.displayName=uc.displayName;const Vm=l.forwardRef(({className:e,children:t,...r},n)=>i.jsxs(fc,{ref:n,className:A("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...r,children:[i.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:i.jsx(pc,{children:i.jsx(q.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));Vm.displayName=fc.displayName;const jm=l.forwardRef(({className:e,inset:t,...r},n)=>i.jsx(lc,{ref:n,className:A("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...r}));jm.displayName=lc.displayName;const Rm=l.forwardRef(({className:e,...t},r)=>i.jsx(hc,{ref:r,className:A("-mx-1 my-1 h-px bg-muted",e),...t}));Rm.displayName=hc.displayName;function cr({className:e="",placeholder:t="Type your message...",autoFocus:r=!0,maxHeight:n=void 0,streamingDebounceMs:o=40,enableFileUpload:s=!0,enableMessageEditing:a=!0,customStyles:c={},onMessageSent:d,onError:f}){const{currentThreadId:u,messages:p,isStreaming:m,streamingAssistantId:v,error:g,send:h,stop:b,lastCheckpointId:w,listCheckpoints:y,navigateToCheckpoint:x,returnToLatest:C,hasMoreHistory:E,isLoadingHistory:O,loadOlderMessages:N}=jn(),[L,D]=T.useState(""),[$,R]=T.useState(null),[X,B]=T.useState(null),[M,J]=T.useState([]),[F,H]=T.useState(!1),[P,_]=T.useState([]),[G,j]=T.useState(null),Z=T.useRef(null),I=T.useRef(null),W=T.useRef(null),ge=T.useRef(null),he=T.useRef(!1),z=T.useRef(!0),ce=T.useRef(0),[pe,le]=T.useState("desktop");T.useEffect(()=>{const k=()=>{const Y=window.innerWidth;le(Y<640?"phone":Y<1024?"tablet":"desktop")};return k(),window.addEventListener("resize",k),()=>window.removeEventListener("resize",k)},[]);const de=T.useCallback(async()=>{if(!E||O)return;const k=ge.current;if(!k)return;const Y=k.scrollHeight,re=k.scrollTop;he.current=!0;try{await N()}catch(oe){console.warn("loadOlderMessages failed",oe)}finally{requestAnimationFrame(()=>{const oe=ge.current;if(!oe){he.current=!1;return}const ve=oe.scrollHeight;oe.scrollTop=re+(ve-Y);const ft=ve-oe.scrollTop-oe.clientHeight;z.current=ft<=32,he.current=!1})}},[E,O,N]);T.useEffect(()=>{const k=ge.current;if(!k)return;const Y=()=>{k.scrollTop<=80&&de();const ve=k.scrollHeight-k.scrollTop-k.clientHeight;z.current=ve<=80};return k.addEventListener("scroll",Y),()=>k.removeEventListener("scroll",Y)},[de]),T.useEffect(()=>{p.length<ce.current&&(z.current=!0),ce.current=p.length},[p.length]),T.useEffect(()=>{const k=ge.current;k&&(he.current||z.current&&(k.scrollTop=k.scrollHeight,z.current=!0))},[p]),T.useEffect(()=>{var k;r&&((k=I.current)==null||k.focus())},[r]),T.useEffect(()=>{g&&!F&&(f==null||f(g))},[g,F,f]),T.useEffect(()=>{let k=!0;if(!u){_([]),j(null);return}return y(u).then(Y=>{var ve;if(!k)return;const re=Y.checkpoints||[];_(re);const oe=((ve=re.slice().sort((ft,Te)=>new Date(Te.createdAt).getTime()-new Date(ft.createdAt).getTime())[0])==null?void 0:ve.checkpointId)||null;j(ft=>ft??oe)}).catch(()=>{}),()=>{k=!1}},[u,y]),T.useEffect(()=>{w&&j(w)},[w]);const ue=k=>{if(k.length>_t)return`Message too long (${k.length}/${_t} characters)`;try{return Yf(k),null}catch(Y){return(Y==null?void 0:Y.message)||"Invalid message"}},V=k=>{const Y=k.content||[],re=Y.filter(oe=>oe.type==="text").map(oe=>oe.text).join("");if(re)return re;try{return JSON.stringify(Y,null,2)}catch{return String(Y)}},K=k=>{var ft;if(!P.length)return[];const re=(((ft=p[k])==null?void 0:ft.role)??"user")==="user",oe=re?k+2:k+1;return P.filter(Te=>(Te.messagesLen??-1)>=(re?oe:0)).filter(Te=>re?(Te.messagesLen??0)>=oe:(Te.messagesLen??0)===oe).map(Te=>({checkpoint_id:Te.checkpointId,checkpoint_ns:Te.checkpointNs,message_count:Te.messagesLen??0,last_message_preview:Te.preview??void 0,ts:new Date(Te.createdAt).getTime(),isCurrent:Te.checkpointId===G})).sort((Te,mw)=>(Te.ts||0)-(mw.ts||0))},be=k=>{if(k===void 0)return{canGoBack:!1,canGoForward:!1,currentIndex:0,totalBranches:0};const Y=K(k);if(Y.length<=1)return{canGoBack:!1,canGoForward:!1,currentIndex:0,totalBranches:Y.length};const re=Math.max(0,Y.findIndex(oe=>oe.isCurrent));return{canGoBack:re>0,canGoForward:re<Y.length-1,currentIndex:re,totalBranches:Y.length}},ee=async()=>{const k=L.trim();if(!k&&M.length===0)return;const Y=ue(k);if(Y){B(Y);return}try{const re=window.__editingCheckpointId||G||void 0;await h(k,{checkpointId:re,payloadExtras:$?{edit:!0,originalMessageId:$}:void 0,attachments:M}),d==null||d(k),D(""),B(null),J([]),delete window.__editingCheckpointId,R(null),I.current&&(I.current.style.height="auto")}catch(re){const oe=(re==null?void 0:re.message)||"Failed to send message";B(oe),f==null||f(oe)}},ye=(k,Y)=>{a&&(R(k),D(Y),B(null),setTimeout(()=>{I.current&&(I.current.focus(),I.current.style.height="auto",I.current.style.height=I.current.scrollHeight+"px")},0))},ae=async(k,Y)=>{const re=p.find(ve=>ve.id===k);if(!re){B("Message not found");return}const oe=V(re);R(k),D(oe),window.__editingCheckpointId=Y,setTimeout(()=>{var ve;return(ve=I.current)==null?void 0:ve.focus()},0)},fe=()=>{R(null),D(""),B(null),delete window.__editingCheckpointId,I.current&&(I.current.style.height="auto")},Ne=k=>{k.key==="Enter"&&!k.shiftKey?(k.preventDefault(),ee()):k.key==="Escape"&&$&&(k.preventDefault(),fe())},ot=k=>{const Y=Array.from(k.target.files||[]);J(re=>[...re,...Y])},as=k=>J(Y=>Y.filter((re,oe)=>k!==oe)),Et=async k=>{u&&(await x(k),j(k))},ie=async()=>{await C(),j(null)},Ie=`flex w-full flex-col h-full min-h-0 min-w-0 overflow-x-hidden bg-transparent ${e} ${c.container||""}`,ke=`flex-1 min-h-0 min-w-0 w-full overflow-y-auto overflow-x-auto overscroll-x-contain break-words break-anywhere p-4 space-y-4 bg-transparent ${c.messagesArea||""}`,Re=`flex-shrink-0 w-full border-t p-4 bg-transparent ${c.inputArea||""}`;return i.jsxs("div",{className:Ie,children:[!!g&&!F&&i.jsxs("div",{className:"bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[i.jsx("span",{children:g}),i.jsx(me,{variant:"ghost",size:"sm",onClick:()=>H(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:i.jsx(q.X,{size:16})})]}),u&&P.length>0&&i.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 border-b border-border bg-muted/60 text-xs dark:bg-muted/50",children:[i.jsx(q.GitBranch,{className:"h-4 w-4 opacity-70"}),i.jsx("span",{className:"opacity-70",children:"Checkpoint:"}),i.jsxs("select",{className:"border border-border rounded px-2 py-1 text-xs bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring dark:bg-secondary",value:G??"",onChange:k=>{const Y=k.target.value||null;Y?Et(Y):ie()},children:[i.jsx("option",{value:"",children:"Latest"}),P.slice().sort((k,Y)=>new Date(Y.createdAt).getTime()-new Date(k.createdAt).getTime()).map(k=>i.jsxs("option",{value:k.checkpointId,children:[new Date(k.createdAt).toLocaleString(),k.preview?` — ${k.preview.slice(0,30)}`:""]},k.checkpointId))]})]}),i.jsxs("div",{ref:ge,className:ke,style:n?{maxHeight:n}:void 0,children:[p.length===0?i.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground",children:"No messages yet. Start a conversation!"}):i.jsxs(i.Fragment,{children:[(O||!E)&&i.jsx("div",{className:"flex justify-center py-2 text-xs text-muted-foreground",children:O?i.jsx(q.Loader2,{className:"h-4 w-4 animate-spin"}):"You've reached the beginning"}),p.map((k,Y)=>i.jsx(fa,{message:k,messageIndex:Y,isStreamingMessage:m&&v===k.id,streamingDebounceMs:o,isEditing:$===k.id,showActions:a,showTimestamp:!1,showAgentName:!0,layoutSize:pe,truncateToolMessages:!1,toolMessagePreviewLength:200,checkpointBranches:K(Y),currentCheckpointId:G??void 0,temporalNavigation:be(Y),onSwitchToCheckpoint:Et,onReturnToMainThread:ie,onNavigateToPreviousBranch:()=>{const re=K(Y),oe=Math.max(0,re.findIndex(ve=>ve.isCurrent));oe>0&&Et(re[oe-1].checkpoint_id)},onNavigateToNextBranch:()=>{const re=K(Y),oe=Math.max(0,re.findIndex(ve=>ve.isCurrent));oe>=0&&oe<re.length-1&&Et(re[oe+1].checkpoint_id)},onEdit:(re,oe)=>ye(re,oe),onEditFromCheckpoint:ae,onRegenerate:()=>{const re=[...p].reverse().find(ve=>ve.role==="user"),oe=re?V(re):"";oe&&h(oe,{checkpointId:G??void 0})},onCancelEdit:fe},k.id||Y))]}),i.jsx("div",{ref:Z})]}),i.jsxs("div",{className:Re,children:[$&&i.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(q.Edit3,{size:16,className:"text-blue-600"}),i.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),i.jsx(me,{variant:"ghost",size:"sm",onClick:fe,className:"text-blue-600 hover:bg-blue-100",children:i.jsx(q.X,{size:16})})]})}),s&&i.jsxs("div",{className:"mb-3",children:[i.jsx("input",{ref:W,type:"file",multiple:!0,onChange:k=>ot(k),className:"hidden"}),M.length>0&&i.jsx("div",{className:"mb-3 flex flex-wrap gap-2",children:M.map((k,Y)=>i.jsxs("div",{className:"flex items-center gap-2 bg-gray-100 rounded-lg px-3 py-2 text-sm",children:[i.jsx(q.Paperclip,{size:14}),i.jsx("span",{className:"truncate max-w-[150px]",children:k.name}),i.jsx(me,{variant:"ghost",size:"sm",onClick:()=>as(Y),className:"h-4 w-4 p-0 text-gray-500 hover:text-red-500","aria-label":`Remove ${k.name}`,children:i.jsx(q.X,{size:12})})]},Y))})]}),X&&i.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:X}),i.jsxs("div",{className:"flex items-end gap-2",children:[s&&i.jsxs(Bm,{children:[i.jsx(Um,{asChild:!0,children:i.jsx(me,{type:"button",size:"icon",variant:"outline",disabled:m,title:"More input actions",className:c.moreButton||"",children:i.jsx(q.Plus,{size:16})})}),i.jsx(bc,{align:"start",sideOffset:6,className:"w-52",children:i.jsxs(vc,{onClick:()=>{var k;return(k=W.current)==null?void 0:k.click()},className:"cursor-pointer",children:[i.jsx(q.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]})})]}),i.jsx("div",{className:"flex-1",children:i.jsx(na,{ref:I,value:L,onChange:k=>{D(k.target.value),B(null),I.current&&(I.current.style.height="auto",I.current.style.height=`${I.current.scrollHeight}px`)},onKeyDown:Ne,placeholder:$?"Edit your message...":t,className:`resize-none min-h-[44px] max-h-[20rem] w-full ${$?"border-blue-400 bg-blue-50":""} ${X?"border-red-400":""} ${c.textarea||""}`,disabled:!1,maxLength:_t,rows:1})}),i.jsx("div",{children:m?i.jsx(me,{type:"button",onClick:b,size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",children:i.jsx(q.Square,{size:16})}):i.jsx(me,{type:"button",onClick:ee,size:"icon",disabled:!L.trim()&&M.length===0,className:`shrink-0 ${c.sendButton||""}`,title:$?"Save changes":"Send message",children:i.jsx(q.Send,{size:16})})})]}),L.length>_t*.8&&i.jsxs("div",{className:"mt-2 text-xs text-gray-500 text-right",children:[L.length,"/",_t]})]})]})}const lr=l.forwardRef(({className:e,type:t,...r},n)=>i.jsx("input",{type:t,className:A("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}));lr.displayName="Input";function Fo(e,[t,r]){return Math.min(r,Math.max(t,e))}function Km(e,t){return l.useReducer((r,n)=>t[r][n]??r,e)}var $o="ScrollArea",[wc,Ww]=Ue($o),[Gm,Fe]=wc($o),yc=l.forwardRef((e,t)=>{const{__scopeScrollArea:r,type:n="hover",dir:o,scrollHideDelay:s=600,...a}=e,[c,d]=l.useState(null),[f,u]=l.useState(null),[p,m]=l.useState(null),[v,g]=l.useState(null),[h,b]=l.useState(null),[w,y]=l.useState(0),[x,C]=l.useState(0),[E,O]=l.useState(!1),[N,L]=l.useState(!1),D=se(t,R=>d(R)),$=Ir(o);return i.jsx(Gm,{scope:r,type:n,dir:$,scrollHideDelay:s,scrollArea:c,viewport:f,onViewportChange:u,content:p,onContentChange:m,scrollbarX:v,onScrollbarXChange:g,scrollbarXEnabled:E,onScrollbarXEnabledChange:O,scrollbarY:h,onScrollbarYChange:b,scrollbarYEnabled:N,onScrollbarYEnabledChange:L,onCornerWidthChange:y,onCornerHeightChange:C,children:i.jsx(Q.div,{dir:$,...a,ref:D,style:{position:"relative","--radix-scroll-area-corner-width":w+"px","--radix-scroll-area-corner-height":x+"px",...e.style}})})});yc.displayName=$o;var xc="ScrollAreaViewport",Sc=l.forwardRef((e,t)=>{const{__scopeScrollArea:r,children:n,nonce:o,...s}=e,a=Fe(xc,r),c=l.useRef(null),d=se(t,c,a.onViewportChange);return i.jsxs(i.Fragment,{children:[i.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}),i.jsx(Q.div,{"data-radix-scroll-area-viewport":"",...s,ref:d,style:{overflowX:a.scrollbarXEnabled?"scroll":"hidden",overflowY:a.scrollbarYEnabled?"scroll":"hidden",...e.style},children:i.jsx("div",{ref:a.onContentChange,style:{minWidth:"100%",display:"table"},children:n})})]})});Sc.displayName=xc;var et="ScrollAreaScrollbar",Bo=l.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=Fe(et,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:a}=o,c=e.orientation==="horizontal";return l.useEffect(()=>(c?s(!0):a(!0),()=>{c?s(!1):a(!1)}),[c,s,a]),o.type==="hover"?i.jsx(qm,{...n,ref:t,forceMount:r}):o.type==="scroll"?i.jsx(Xm,{...n,ref:t,forceMount:r}):o.type==="auto"?i.jsx(Cc,{...n,ref:t,forceMount:r}):o.type==="always"?i.jsx(Uo,{...n,ref:t}):null});Bo.displayName=et;var qm=l.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=Fe(et,e.__scopeScrollArea),[s,a]=l.useState(!1);return l.useEffect(()=>{const c=o.scrollArea;let d=0;if(c){const f=()=>{window.clearTimeout(d),a(!0)},u=()=>{d=window.setTimeout(()=>a(!1),o.scrollHideDelay)};return c.addEventListener("pointerenter",f),c.addEventListener("pointerleave",u),()=>{window.clearTimeout(d),c.removeEventListener("pointerenter",f),c.removeEventListener("pointerleave",u)}}},[o.scrollArea,o.scrollHideDelay]),i.jsx(_e,{present:r||s,children:i.jsx(Cc,{"data-state":s?"visible":"hidden",...n,ref:t})})}),Xm=l.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=Fe(et,e.__scopeScrollArea),s=e.orientation==="horizontal",a=sn(()=>d("SCROLL_END"),100),[c,d]=Km("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 l.useEffect(()=>{if(c==="idle"){const f=window.setTimeout(()=>d("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(f)}},[c,o.scrollHideDelay,d]),l.useEffect(()=>{const f=o.viewport,u=s?"scrollLeft":"scrollTop";if(f){let p=f[u];const m=()=>{const v=f[u];p!==v&&(d("SCROLL"),a()),p=v};return f.addEventListener("scroll",m),()=>f.removeEventListener("scroll",m)}},[o.viewport,s,d,a]),i.jsx(_e,{present:r||c!=="hidden",children:i.jsx(Uo,{"data-state":c==="hidden"?"hidden":"visible",...n,ref:t,onPointerEnter:U(e.onPointerEnter,()=>d("POINTER_ENTER")),onPointerLeave:U(e.onPointerLeave,()=>d("POINTER_LEAVE"))})})}),Cc=l.forwardRef((e,t)=>{const r=Fe(et,e.__scopeScrollArea),{forceMount:n,...o}=e,[s,a]=l.useState(!1),c=e.orientation==="horizontal",d=sn(()=>{if(r.viewport){const f=r.viewport.offsetWidth<r.viewport.scrollWidth,u=r.viewport.offsetHeight<r.viewport.scrollHeight;a(c?f:u)}},10);return Ut(r.viewport,d),Ut(r.content,d),i.jsx(_e,{present:n||s,children:i.jsx(Uo,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Uo=l.forwardRef((e,t)=>{const{orientation:r="vertical",...n}=e,o=Fe(et,e.__scopeScrollArea),s=l.useRef(null),a=l.useRef(0),[c,d]=l.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),f=Pc(c.viewport,c.content),u={...n,sizes:c,onSizesChange:d,hasThumb:f>0&&f<1,onThumbChange:m=>s.current=m,onThumbPointerUp:()=>a.current=0,onThumbPointerDown:m=>a.current=m};function p(m,v){return tb(m,a.current,c,v)}return r==="horizontal"?i.jsx(Ym,{...u,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const m=o.viewport.scrollLeft,v=_c(m,c,o.dir);s.current.style.transform=`translate3d(${v}px, 0, 0)`}},onWheelScroll:m=>{o.viewport&&(o.viewport.scrollLeft=m)},onDragScroll:m=>{o.viewport&&(o.viewport.scrollLeft=p(m,o.dir))}}):r==="vertical"?i.jsx(Jm,{...u,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const m=o.viewport.scrollTop,v=_c(m,c);s.current.style.transform=`translate3d(0, ${v}px, 0)`}},onWheelScroll:m=>{o.viewport&&(o.viewport.scrollTop=m)},onDragScroll:m=>{o.viewport&&(o.viewport.scrollTop=p(m))}}):null}),Ym=l.forwardRef((e,t)=>{const{sizes:r,onSizesChange:n,...o}=e,s=Fe(et,e.__scopeScrollArea),[a,c]=l.useState(),d=l.useRef(null),f=se(t,d,s.onScrollbarXChange);return l.useEffect(()=>{d.current&&c(getComputedStyle(d.current))},[d]),i.jsx(Nc,{"data-orientation":"horizontal",...o,ref:f,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":on(r)+"px",...e.style},onThumbPointerDown:u=>e.onThumbPointerDown(u.x),onDragScroll:u=>e.onDragScroll(u.x),onWheelScroll:(u,p)=>{if(s.viewport){const m=s.viewport.scrollLeft+u.deltaX;e.onWheelScroll(m),kc(m,p)&&u.preventDefault()}},onResize:()=>{d.current&&s.viewport&&a&&n({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:d.current.clientWidth,paddingStart:nn(a.paddingLeft),paddingEnd:nn(a.paddingRight)}})}})}),Jm=l.forwardRef((e,t)=>{const{sizes:r,onSizesChange:n,...o}=e,s=Fe(et,e.__scopeScrollArea),[a,c]=l.useState(),d=l.useRef(null),f=se(t,d,s.onScrollbarYChange);return l.useEffect(()=>{d.current&&c(getComputedStyle(d.current))},[d]),i.jsx(Nc,{"data-orientation":"vertical",...o,ref:f,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":on(r)+"px",...e.style},onThumbPointerDown:u=>e.onThumbPointerDown(u.y),onDragScroll:u=>e.onDragScroll(u.y),onWheelScroll:(u,p)=>{if(s.viewport){const m=s.viewport.scrollTop+u.deltaY;e.onWheelScroll(m),kc(m,p)&&u.preventDefault()}},onResize:()=>{d.current&&s.viewport&&a&&n({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:d.current.clientHeight,paddingStart:nn(a.paddingTop),paddingEnd:nn(a.paddingBottom)}})}})}),[Zm,Ec]=wc(et),Nc=l.forwardRef((e,t)=>{const{__scopeScrollArea:r,sizes:n,hasThumb:o,onThumbChange:s,onThumbPointerUp:a,onThumbPointerDown:c,onThumbPositionChange:d,onDragScroll:f,onWheelScroll:u,onResize:p,...m}=e,v=Fe(et,r),[g,h]=l.useState(null),b=se(t,D=>h(D)),w=l.useRef(null),y=l.useRef(""),x=v.viewport,C=n.content-n.viewport,E=Se(u),O=Se(d),N=sn(p,10);function L(D){if(w.current){const $=D.clientX-w.current.left,R=D.clientY-w.current.top;f({x:$,y:R})}}return l.useEffect(()=>{const D=$=>{const R=$.target;(g==null?void 0:g.contains(R))&&E($,C)};return document.addEventListener("wheel",D,{passive:!1}),()=>document.removeEventListener("wheel",D,{passive:!1})},[x,g,C,E]),l.useEffect(O,[n,O]),Ut(g,N),Ut(v.content,N),i.jsx(Zm,{scope:r,scrollbar:g,hasThumb:o,onThumbChange:Se(s),onThumbPointerUp:Se(a),onThumbPositionChange:O,onThumbPointerDown:Se(c),children:i.jsx(Q.div,{...m,ref:b,style:{position:"absolute",...m.style},onPointerDown:U(e.onPointerDown,D=>{D.button===0&&(D.target.setPointerCapture(D.pointerId),w.current=g.getBoundingClientRect(),y.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",v.viewport&&(v.viewport.style.scrollBehavior="auto"),L(D))}),onPointerMove:U(e.onPointerMove,L),onPointerUp:U(e.onPointerUp,D=>{const $=D.target;$.hasPointerCapture(D.pointerId)&&$.releasePointerCapture(D.pointerId),document.body.style.webkitUserSelect=y.current,v.viewport&&(v.viewport.style.scrollBehavior=""),w.current=null})})})}),rn="ScrollAreaThumb",Tc=l.forwardRef((e,t)=>{const{forceMount:r,...n}=e,o=Ec(rn,e.__scopeScrollArea);return i.jsx(_e,{present:r||o.hasThumb,children:i.jsx(Qm,{ref:t,...n})})}),Qm=l.forwardRef((e,t)=>{const{__scopeScrollArea:r,style:n,...o}=e,s=Fe(rn,r),a=Ec(rn,r),{onThumbPositionChange:c}=a,d=se(t,p=>a.onThumbChange(p)),f=l.useRef(void 0),u=sn(()=>{f.current&&(f.current(),f.current=void 0)},100);return l.useEffect(()=>{const p=s.viewport;if(p){const m=()=>{if(u(),!f.current){const v=rb(p,c);f.current=v,c()}};return c(),p.addEventListener("scroll",m),()=>p.removeEventListener("scroll",m)}},[s.viewport,u,c]),i.jsx(Q.div,{"data-state":a.hasThumb?"visible":"hidden",...o,ref:d,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...n},onPointerDownCapture:U(e.onPointerDownCapture,p=>{const v=p.target.getBoundingClientRect(),g=p.clientX-v.left,h=p.clientY-v.top;a.onThumbPointerDown({x:g,y:h})}),onPointerUp:U(e.onPointerUp,a.onThumbPointerUp)})});Tc.displayName=rn;var Ho="ScrollAreaCorner",Ac=l.forwardRef((e,t)=>{const r=Fe(Ho,e.__scopeScrollArea),n=!!(r.scrollbarX&&r.scrollbarY);return r.type!=="scroll"&&n?i.jsx(eb,{...e,ref:t}):null});Ac.displayName=Ho;var eb=l.forwardRef((e,t)=>{const{__scopeScrollArea:r,...n}=e,o=Fe(Ho,r),[s,a]=l.useState(0),[c,d]=l.useState(0),f=!!(s&&c);return Ut(o.scrollbarX,()=>{var p;const u=((p=o.scrollbarX)==null?void 0:p.offsetHeight)||0;o.onCornerHeightChange(u),d(u)}),Ut(o.scrollbarY,()=>{var p;const u=((p=o.scrollbarY)==null?void 0:p.offsetWidth)||0;o.onCornerWidthChange(u),a(u)}),f?i.jsx(Q.div,{...n,ref:t,style:{width:s,height:c,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function nn(e){return e?parseInt(e,10):0}function Pc(e,t){const r=e/t;return isNaN(r)?0:r}function on(e){const t=Pc(e.viewport,e.content),r=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,n=(e.scrollbar.size-r)*t;return Math.max(n,18)}function tb(e,t,r,n="ltr"){const o=on(r),s=o/2,a=t||s,c=o-a,d=r.scrollbar.paddingStart+a,f=r.scrollbar.size-r.scrollbar.paddingEnd-c,u=r.content-r.viewport,p=n==="ltr"?[0,u]:[u*-1,0];return Ic([d,f],p)(e)}function _c(e,t,r="ltr"){const n=on(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,a=t.content-t.viewport,c=s-n,d=r==="ltr"?[0,a]:[a*-1,0],f=Fo(e,d);return Ic([0,a],[0,c])(f)}function Ic(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 kc(e,t){return e>0&&e<t}var rb=(e,t=()=>{})=>{let r={left:e.scrollLeft,top:e.scrollTop},n=0;return function o(){const s={left:e.scrollLeft,top:e.scrollTop},a=r.left!==s.left,c=r.top!==s.top;(a||c)&&t(),r=s,n=window.requestAnimationFrame(o)}(),()=>window.cancelAnimationFrame(n)};function sn(e,t){const r=Se(e),n=l.useRef(0);return l.useEffect(()=>()=>window.clearTimeout(n.current),[]),l.useCallback(()=>{window.clearTimeout(n.current),n.current=window.setTimeout(r,t)},[r,t])}function Ut(e,t){const r=Se(t);xe(()=>{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 Oc=yc,nb=Sc,ob=Ac;const Mc=l.forwardRef(({className:e,children:t,...r},n)=>i.jsxs(Oc,{ref:n,className:A("relative overflow-hidden",e),...r,children:[i.jsx(nb,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),i.jsx(Dc,{}),i.jsx(ob,{})]}));Mc.displayName=Oc.displayName;const Dc=l.forwardRef(({className:e,orientation:t="vertical",...r},n)=>i.jsx(Bo,{ref:n,orientation:t,className:A("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:i.jsx(Tc,{className:"relative flex-1 rounded-full bg-border"})}));Dc.displayName=Bo.displayName;function an({className:e="",showCreateButton:t=!0,showDeleteButton:r=!0,showEditTitle:n=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:a=null,navigateToThread:c,onThreadSelect:d,onThreadCreate:f,onThreadDelete:u}){const{loadThread:p,threads:m,refreshThreads:v,currentThreadId:g,createThread:h,deleteThread:b,renameThread:w}=jn(),[y,x]=T.useState(m??[]),[C,E]=T.useState(!1),[O,N]=T.useState(null),[L,D]=T.useState(null),[$,R]=T.useState(""),[X,B]=T.useState(!1);T.useEffect(()=>{x(m??[])},[m]);const M=async I=>{try{await p(I),c==null||c(I),d==null||d(I)}catch(W){console.error("Failed to select thread:",W)}},J=async()=>{try{B(!0);const I=await h();f==null||f(I),c==null||c(I)}catch(I){console.error("Failed to create thread:",I)}finally{B(!1)}},F=async(I,W)=>{if(W.stopPropagation(),!!confirm("Delete this thread?"))try{await b(I),u==null||u(I)}catch(ge){console.error("Failed to delete thread:",ge)}},H=(I,W)=>{W.stopPropagation(),D(I.threadId),R(I.title||`Thread ${I.threadId.slice(0,8)}`)},P=async I=>{if($.trim())try{await w(I,$.trim()),D(null),R("")}catch(W){console.error("Failed to update title:",W)}},_=()=>{D(null),R("")},G=(I,W)=>{I.key==="Enter"?P(W):I.key==="Escape"&&_()},j=I=>{if(!I)return"";try{const W=new Date(I),he=new Date().getTime()-W.getTime(),z=Math.floor(he/(1e3*60*60*24));return z===0?W.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):z===1?"Yesterday":z<7?`${z} days ago`:W.toLocaleDateString()}catch{return""}},Z=I=>I.title||`Thread ${I.threadId.slice(0,8)}`;return i.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&i.jsx("div",{className:s.header||"flex-shrink-0 p-2 border-b bg-slate-800 border-slate-700 text-slate-100 flex justify-end",children:i.jsx(me,{onClick:J,disabled:X||C,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:X?"Creating...":"New Chat",children:i.jsx(q.MessageSquarePlus,{size:20})})}),i.jsx(Mc,{className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:i.jsx("div",{className:"p-2 space-y-1 pb-4",children:C?i.jsx("div",{className:"text-center py-8 text-slate-400",children:"Loading…"}):y.length===0?i.jsxs("div",{className:"text-center py-8 text-slate-400",children:[i.jsx(q.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),i.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):y.slice().sort((I,W)=>new Date(W.updatedAt||W.createdAt||"").getTime()-new Date(I.updatedAt||I.createdAt||"").getTime()).map(I=>i.jsxs("div",{onClick:()=>M(I.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(a??g)===I.threadId?`${s.activeThread||"bg-slate-600 border-slate-500"} `:`${s.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${s.threadItem||""} text-gray-900 dark:text-slate-100`,children:[i.jsxs("div",{className:"flex items-center justify-between",children:[i.jsx("div",{className:"flex-1 min-w-0",children:L===I.threadId?i.jsxs("div",{className:"flex items-center gap-2",onClick:W=>W.stopPropagation(),children:[i.jsx(lr,{value:$,onChange:W=>R(W.target.value),onKeyDown:W=>G(W,I.threadId),className:"h-6 text-sm",autoFocus:!0}),i.jsx(me,{variant:"ghost",size:"sm",onClick:()=>P(I.threadId),className:"h-6 w-6 p-0",children:i.jsx(q.Check,{size:12})}),i.jsx(me,{variant:"ghost",size:"sm",onClick:_,className:"h-6 w-6 p-0",children:i.jsx(q.X,{size:12})})]}):i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:Z(I)}),i.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[i.jsx(q.Calendar,{size:10}),i.jsx("span",{children:j(I.updatedAt||I.createdAt)})]})]})}),i.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[n&&L!==I.threadId&&i.jsx(me,{variant:"ghost",size:"sm",onClick:W=>H(I,W),className:"h-6 w-6 p-0",title:"Edit title",children:i.jsx(q.Edit3,{size:12})}),r&&i.jsx(me,{variant:"ghost",size:"sm",onClick:W=>F(I.threadId,W),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:i.jsx(q.Trash2,{size:12})})]})]}),a===I.threadId&&i.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},I.threadId))})})]})}const Lc=T.createContext(null);function sb({children:e,basePath:t="/chat"}){const r=T.useMemo(()=>t?t==="/"?"":t.endsWith("/")?t.slice(0,-1):t:"/chat",[t]),n={basePath:r,buildThreadPath:o=>`${r}/${o}`,buildBasePath:()=>r};return i.jsx(Lc.Provider,{value:n,children:e})}function ab(){const e=T.useContext(Lc);return e||{basePath:"/chat",buildThreadPath:t=>`/chat/${t}`,buildBasePath:()=>"/chat"}}const Fc={BASE_URL:"/",DEV:!1,MODE:"library",PROD:!0,SSR:!1};function dr(e){var o;const t=typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Nn&&Nn.tagName.toUpperCase()==="SCRIPT"&&Nn.src||new URL("index.umd.js",document.baseURI).href}<"u"&&Fc?Fc[e]:void 0,r=(o=globalThis==null?void 0:globalThis.process)==null?void 0:o.env,n=r?r[e]:void 0;return(t??n)||void 0}function ib(){return dr("VITE_API_BASE_URL")||dr("NEXT_PUBLIC_API_BASE_URL")||void 0}function cb(){return dr("VITE_API_KEY")||dr("NEXT_PUBLIC_API_KEY")||dr("VITE_AUTH_TOKEN")||void 0}function $c(){const e=ib(),t=cb(),r={};return e&&(r.baseUrl=e),t&&(r.apiKey=t),r}function Bc(){const e=$c(),t=tt.getAuthToken();return{apiBaseUrl:e.baseUrl||tt.baseUrl||"http://localhost:8000",apiKey:t||e.apiKey||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,truncateToolMessages:!0,toolMessagePreviewLength:200,darkMode:!1,enableSound:!1,messageHistory:100}}const Uc="chat-settings";function lb(){try{const e=localStorage.getItem(Uc);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function db(e){try{localStorage.setItem(Uc,JSON.stringify(e)),e.apiKey&&tt.setAuthToken(e.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function ub(){const e=Bc(),t=lb(),r=tt.getAuthToken();return{...e,...t,apiKey:r||t.apiKey||e.apiKey,apiBaseUrl:tt.baseUrl||t.apiBaseUrl||e.apiBaseUrl}}function fb(e){e.apiKey&&tt.setAuthToken(e.apiKey),db(e)}const zo=768;function pb(){const[e,t]=l.useState(void 0);return l.useEffect(()=>{const r=window.matchMedia(`(max-width: ${zo-1}px)`),n=()=>{t(window.innerWidth<zo)};return r.addEventListener("change",n),t(window.innerWidth<zo),()=>r.removeEventListener("change",n)},[]),!!e}var hb="Separator",Hc="horizontal",gb=["horizontal","vertical"],zc=l.forwardRef((e,t)=>{const{decorative:r,orientation:n=Hc,...o}=e,s=mb(n)?n:Hc,c=r?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return i.jsx(Q.div,{"data-orientation":s,...c,...o,ref:t})});zc.displayName=hb;function mb(e){return gb.includes(e)}var Wc=zc;const Wo=l.forwardRef(({className:e,orientation:t="horizontal",decorative:r=!0,...n},o)=>i.jsx(Wc,{ref:o,decorative:r,orientation:t,className:A("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...n}));Wo.displayName=Wc.displayName;var cn="Dialog",[Vc,Vw]=Ue(cn),[bb,Ve]=Vc(cn),jc=e=>{const{__scopeDialog:t,children:r,open:n,defaultOpen:o,onOpenChange:s,modal:a=!0}=e,c=l.useRef(null),d=l.useRef(null),[f,u]=st({prop:n,defaultProp:o??!1,onChange:s,caller:cn});return i.jsx(bb,{scope:t,triggerRef:c,contentRef:d,contentId:He(),titleId:He(),descriptionId:He(),open:f,onOpenChange:u,onOpenToggle:l.useCallback(()=>u(p=>!p),[u]),modal:a,children:r})};jc.displayName=cn;var Rc="DialogTrigger",Kc=l.forwardRef((e,t)=>{const{__scopeDialog:r,...n}=e,o=Ve(Rc,r),s=se(t,o.triggerRef);return i.jsx(Q.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Ro(o.open),...n,ref:s,onClick:U(e.onClick,o.onOpenToggle)})});Kc.displayName=Rc;var Vo="DialogPortal",[vb,Gc]=Vc(Vo,{forceMount:void 0}),qc=e=>{const{__scopeDialog:t,forceMount:r,children:n,container:o}=e,s=Ve(Vo,t);return i.jsx(vb,{scope:t,forceMount:r,children:l.Children.map(n,a=>i.jsx(_e,{present:r||s.open,children:i.jsx(Wr,{asChild:!0,container:o,children:a})}))})};qc.displayName=Vo;var ln="DialogOverlay",Xc=l.forwardRef((e,t)=>{const r=Gc(ln,e.__scopeDialog),{forceMount:n=r.forceMount,...o}=e,s=Ve(ln,e.__scopeDialog);return s.modal?i.jsx(_e,{present:n||s.open,children:i.jsx(yb,{...o,ref:t})}):null});Xc.displayName=ln;var wb=Oe.createSlot("DialogOverlay.RemoveScroll"),yb=l.forwardRef((e,t)=>{const{__scopeDialog:r,...n}=e,o=Ve(ln,r);return i.jsx(Yr,{as:wb,allowPinchZoom:!0,shards:[o.contentRef],children:i.jsx(Q.div,{"data-state":Ro(o.open),...n,ref:t,style:{pointerEvents:"auto",...n.style}})})}),yt="DialogContent",Yc=l.forwardRef((e,t)=>{const r=Gc(yt,e.__scopeDialog),{forceMount:n=r.forceMount,...o}=e,s=Ve(yt,e.__scopeDialog);return i.jsx(_e,{present:n||s.open,children:s.modal?i.jsx(xb,{...o,ref:t}):i.jsx(Sb,{...o,ref:t})})});Yc.displayName=yt;var xb=l.forwardRef((e,t)=>{const r=Ve(yt,e.__scopeDialog),n=l.useRef(null),o=se(t,r.contentRef,n);return l.useEffect(()=>{const s=n.current;if(s)return Co(s)},[]),i.jsx(Jc,{...e,ref:o,trapFocus:r.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:U(e.onCloseAutoFocus,s=>{var a;s.preventDefault(),(a=r.triggerRef.current)==null||a.focus()}),onPointerDownOutside:U(e.onPointerDownOutside,s=>{const a=s.detail.originalEvent,c=a.button===0&&a.ctrlKey===!0;(a.button===2||c)&&s.preventDefault()}),onFocusOutside:U(e.onFocusOutside,s=>s.preventDefault())})}),Sb=l.forwardRef((e,t)=>{const r=Ve(yt,e.__scopeDialog),n=l.useRef(!1),o=l.useRef(!1);return i.jsx(Jc,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var a,c;(a=e.onCloseAutoFocus)==null||a.call(e,s),s.defaultPrevented||(n.current||(c=r.triggerRef.current)==null||c.focus(),s.preventDefault()),n.current=!1,o.current=!1},onInteractOutside:s=>{var d,f;(d=e.onInteractOutside)==null||d.call(e,s),s.defaultPrevented||(n.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const a=s.target;((f=r.triggerRef.current)==null?void 0:f.contains(a))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),Jc=l.forwardRef((e,t)=>{const{__scopeDialog:r,trapFocus:n,onOpenAutoFocus:o,onCloseAutoFocus:s,...a}=e,c=Ve(yt,r),d=l.useRef(null),f=se(t,d);return Qn(),i.jsxs(i.Fragment,{children:[i.jsx(kr,{asChild:!0,loop:!0,trapped:n,onMountAutoFocus:o,onUnmountAutoFocus:s,children:i.jsx(Zt,{role:"dialog",id:c.contentId,"aria-describedby":c.descriptionId,"aria-labelledby":c.titleId,"data-state":Ro(c.open),...a,ref:f,onDismiss:()=>c.onOpenChange(!1)})}),i.jsxs(i.Fragment,{children:[i.jsx(Cb,{titleId:c.titleId}),i.jsx(Nb,{contentRef:d,descriptionId:c.descriptionId})]})]})}),jo="DialogTitle",Zc=l.forwardRef((e,t)=>{const{__scopeDialog:r,...n}=e,o=Ve(jo,r);return i.jsx(Q.h2,{id:o.titleId,...n,ref:t})});Zc.displayName=jo;var Qc="DialogDescription",el=l.forwardRef((e,t)=>{const{__scopeDialog:r,...n}=e,o=Ve(Qc,r);return i.jsx(Q.p,{id:o.descriptionId,...n,ref:t})});el.displayName=Qc;var tl="DialogClose",rl=l.forwardRef((e,t)=>{const{__scopeDialog:r,...n}=e,o=Ve(tl,r);return i.jsx(Q.button,{type:"button",...n,ref:t,onClick:U(e.onClick,()=>o.onOpenChange(!1))})});rl.displayName=tl;function Ro(e){return e?"open":"closed"}var nl="DialogTitleWarning",[jw,ol]=wf(nl,{contentName:yt,titleName:jo,docsSlug:"dialog"}),Cb=({titleId:e})=>{const t=ol(nl),r=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
|
|
59
59
|
|
|
60
60
|
If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
61
61
|
|
package/package.json
CHANGED