teodor-new-chat-ui 4.3.721 → 4.3.722

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.umd.js CHANGED
@@ -1,9 +1,9 @@
1
- (function(J,vt){typeof exports=="object"&&typeof module<"u"?vt(exports,require("clsx"),require("tailwind-merge"),require("react"),require("@radix-ui/react-slot"),require("class-variance-authority"),require("react-dom"),require("lucide-react")):typeof define=="function"&&define.amd?define(["exports","clsx","tailwind-merge","react","@radix-ui/react-slot","class-variance-authority","react-dom","lucide-react"],vt):(J=typeof globalThis<"u"?globalThis:J||self,vt(J.NewChatUI={},J.clsx,J.tailwindMerge,J.React,J.reactSlot,J.classVarianceAuthority,J.ReactDOM,J.LucideReact))})(this,function(J,vt,Un,v,cr,jp,Ws,me){"use strict";var qC=Object.defineProperty;var GC=(J,vt,Un)=>vt in J?qC(J,vt,{enumerable:!0,configurable:!0,writable:!0,value:Un}):J[vt]=Un;var sl=(J,vt,Un)=>GC(J,typeof vt!="symbol"?vt+"":vt,Un);function il(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const x=il(v),al=il(Ws);function _p(...e){return Un.twMerge(vt.clsx(e))}function ll(e,t){return function(){return e.apply(t,arguments)}}const{toString:Pp}=Object.prototype,{getPrototypeOf:Vs}=Object,{iterator:So,toStringTag:cl}=Symbol,Co=(e=>t=>{const n=Pp.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),Kt=e=>(e=e.toLowerCase(),t=>Co(t)===e),To=e=>t=>typeof t===e,{isArray:ur}=Array,dr=To("undefined");function Mr(e){return e!==null&&!dr(e)&&e.constructor!==null&&!dr(e.constructor)&&St(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const ul=Kt("ArrayBuffer");function Rp(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&ul(e.buffer),t}const Op=To("string"),St=To("function"),dl=To("number"),Dr=e=>e!==null&&typeof e=="object",Mp=e=>e===!0||e===!1,ko=e=>{if(Co(e)!=="object")return!1;const t=Vs(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(cl in e)&&!(So in e)},Dp=e=>{if(!Dr(e)||Mr(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Lp=Kt("Date"),$p=Kt("File"),Fp=Kt("Blob"),zp=Kt("FileList"),Bp=e=>Dr(e)&&St(e.pipe),Up=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||St(e.append)&&((t=Co(e))==="formdata"||t==="object"&&St(e.toString)&&e.toString()==="[object FormData]"))},Hp=Kt("URLSearchParams"),[Wp,Vp,Kp,qp]=["ReadableStream","Request","Response","Headers"].map(Kt),Gp=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Lr(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),ur(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(Mr(e))return;const s=n?Object.getOwnPropertyNames(e):Object.keys(e),i=s.length;let a;for(r=0;r<i;r++)a=s[r],t.call(null,e[a],a,e)}}function fl(e,t){if(Mr(e))return null;t=t.toLowerCase();const n=Object.keys(e);let r=n.length,o;for(;r-- >0;)if(o=n[r],t===o.toLowerCase())return o;return null}const Hn=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,hl=e=>!dr(e)&&e!==Hn;function Ks(){const{caseless:e,skipUndefined:t}=hl(this)&&this||{},n={},r=(o,s)=>{const i=e&&fl(n,s)||s;ko(n[i])&&ko(o)?n[i]=Ks(n[i],o):ko(o)?n[i]=Ks({},o):ur(o)?n[i]=o.slice():(!t||!dr(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&Lr(arguments[o],r);return n}const Yp=(e,t,n,{allOwnKeys:r}={})=>(Lr(t,(o,s)=>{n&&St(o)?e[s]=ll(o,n):e[s]=o},{allOwnKeys:r}),e),Xp=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),Jp=(e,t,n,r)=>{e.prototype=Object.create(t.prototype,r),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},Zp=(e,t,n,r)=>{let o,s,i;const a={};if(t=t||{},e==null)return t;do{for(o=Object.getOwnPropertyNames(e),s=o.length;s-- >0;)i=o[s],(!r||r(i,e,t))&&!a[i]&&(t[i]=e[i],a[i]=!0);e=n!==!1&&Vs(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},Qp=(e,t,n)=>{e=String(e),(n===void 0||n>e.length)&&(n=e.length),n-=t.length;const r=e.indexOf(t,n);return r!==-1&&r===n},em=e=>{if(!e)return null;if(ur(e))return e;let t=e.length;if(!dl(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},tm=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Vs(Uint8Array)),nm=(e,t)=>{const r=(e&&e[So]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},rm=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},om=Kt("HTMLFormElement"),sm=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),pl=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),im=Kt("RegExp"),ml=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Lr(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},am=e=>{ml(e,(t,n)=>{if(St(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(St(r)){if(t.enumerable=!1,"writable"in t){t.writable=!1;return}t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")})}})},lm=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return ur(e)?r(e):r(String(e).split(t)),n},cm=()=>{},um=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function dm(e){return!!(e&&St(e.append)&&e[cl]==="FormData"&&e[So])}const fm=e=>{const t=new Array(10),n=(r,o)=>{if(Dr(r)){if(t.indexOf(r)>=0)return;if(Mr(r))return r;if(!("toJSON"in r)){t[o]=r;const s=ur(r)?[]:{};return Lr(r,(i,a)=>{const l=n(i,o+1);!dr(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},hm=Kt("AsyncFunction"),pm=e=>e&&(Dr(e)||St(e))&&St(e.then)&&St(e.catch),gl=((e,t)=>e?setImmediate:t?((n,r)=>(Hn.addEventListener("message",({source:o,data:s})=>{o===Hn&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),Hn.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",St(Hn.postMessage)),mm=typeof queueMicrotask<"u"?queueMicrotask.bind(Hn):typeof process<"u"&&process.nextTick||gl,U={isArray:ur,isArrayBuffer:ul,isBuffer:Mr,isFormData:Up,isArrayBufferView:Rp,isString:Op,isNumber:dl,isBoolean:Mp,isObject:Dr,isPlainObject:ko,isEmptyObject:Dp,isReadableStream:Wp,isRequest:Vp,isResponse:Kp,isHeaders:qp,isUndefined:dr,isDate:Lp,isFile:$p,isBlob:Fp,isRegExp:im,isFunction:St,isStream:Bp,isURLSearchParams:Hp,isTypedArray:tm,isFileList:zp,forEach:Lr,merge:Ks,extend:Yp,trim:Gp,stripBOM:Xp,inherits:Jp,toFlatObject:Zp,kindOf:Co,kindOfTest:Kt,endsWith:Qp,toArray:em,forEachEntry:nm,matchAll:rm,isHTMLForm:om,hasOwnProperty:pl,hasOwnProp:pl,reduceDescriptors:ml,freezeMethods:am,toObjectSet:lm,toCamelCase:sm,noop:cm,toFiniteNumber:um,findKey:fl,global:Hn,isContextDefined:hl,isSpecCompliantForm:dm,toJSONObject:fm,isAsyncFn:hm,isThenable:pm,setImmediate:gl,asap:mm,isIterable:e=>e!=null&&St(e[So])};function Te(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o,this.status=o.status?o.status:null)}U.inherits(Te,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:U.toJSONObject(this.config),code:this.code,status:this.status}}});const xl=Te.prototype,bl={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(e=>{bl[e]={value:e}}),Object.defineProperties(Te,bl),Object.defineProperty(xl,"isAxiosError",{value:!0}),Te.from=(e,t,n,r,o,s)=>{const i=Object.create(xl);U.toFlatObject(e,i,function(u){return u!==Error.prototype},c=>c!=="isAxiosError");const a=e&&e.message?e.message:"Error",l=t==null&&e?e.code:t;return Te.call(i,a,l,n,r,o),e&&i.cause==null&&Object.defineProperty(i,"cause",{value:e,configurable:!0}),i.name=e&&e.name||"Error",s&&Object.assign(i,s),i};const gm=null;function qs(e){return U.isPlainObject(e)||U.isArray(e)}function wl(e){return U.endsWith(e,"[]")?e.slice(0,-2):e}function yl(e,t,n){return e?e.concat(t).map(function(o,s){return o=wl(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function xm(e){return U.isArray(e)&&!e.some(qs)}const bm=U.toFlatObject(U,{},null,function(t){return/^is[A-Z]/.test(t)});function Eo(e,t,n){if(!U.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=U.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(b,g){return!U.isUndefined(g[b])});const r=n.metaTokens,o=n.visitor||u,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&U.isSpecCompliantForm(t);if(!U.isFunction(o))throw new TypeError("visitor must be a function");function c(m){if(m===null)return"";if(U.isDate(m))return m.toISOString();if(U.isBoolean(m))return m.toString();if(!l&&U.isBlob(m))throw new Te("Blob is not supported. Use a Buffer instead.");return U.isArrayBuffer(m)||U.isTypedArray(m)?l&&typeof Blob=="function"?new Blob([m]):Buffer.from(m):m}function u(m,b,g){let w=m;if(m&&!g&&typeof m=="object"){if(U.endsWith(b,"{}"))b=r?b:b.slice(0,-2),m=JSON.stringify(m);else if(U.isArray(m)&&xm(m)||(U.isFileList(m)||U.endsWith(b,"[]"))&&(w=U.toArray(m)))return b=wl(b),w.forEach(function(k,E){!(U.isUndefined(k)||k===null)&&t.append(i===!0?yl([b],E,s):i===null?b:b+"[]",c(k))}),!1}return qs(m)?!0:(t.append(yl(g,b,s),c(m)),!1)}const f=[],h=Object.assign(bm,{defaultVisitor:u,convertValue:c,isVisitable:qs});function p(m,b){if(!U.isUndefined(m)){if(f.indexOf(m)!==-1)throw Error("Circular reference detected in "+b.join("."));f.push(m),U.forEach(m,function(w,y){(!(U.isUndefined(w)||w===null)&&o.call(t,w,U.isString(y)?y.trim():y,b,h))===!0&&p(w,b?b.concat(y):[y])}),f.pop()}}if(!U.isObject(e))throw new TypeError("data must be an object");return p(e),t}function vl(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function Gs(e,t){this._pairs=[],e&&Eo(e,this,t)}const Sl=Gs.prototype;Sl.append=function(t,n){this._pairs.push([t,n])},Sl.toString=function(t){const n=t?function(r){return t.call(this,r,vl)}:vl;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function wm(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function Cl(e,t,n){if(!t)return e;const r=n&&n.encode||wm;U.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=U.isURLSearchParams(t)?t.toString():new Gs(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class Tl{constructor(){this.handlers=[]}use(t,n,r){return this.handlers.push({fulfilled:t,rejected:n,synchronous:r?r.synchronous:!1,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){U.forEach(this.handlers,function(r){r!==null&&t(r)})}}const kl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},ym={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:Gs,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},Ys=typeof window<"u"&&typeof document<"u",Xs=typeof navigator=="object"&&navigator||void 0,vm=Ys&&(!Xs||["ReactNative","NativeScript","NS"].indexOf(Xs.product)<0),Sm=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",Cm=Ys&&window.location.href||"http://localhost",lt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:Ys,hasStandardBrowserEnv:vm,hasStandardBrowserWebWorkerEnv:Sm,navigator:Xs,origin:Cm},Symbol.toStringTag,{value:"Module"})),...ym};function Tm(e,t){return Eo(e,new lt.classes.URLSearchParams,{visitor:function(n,r,o,s){return lt.isNode&&U.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function km(e){return U.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Em(e){const t={},n=Object.keys(e);let r;const o=n.length;let s;for(r=0;r<o;r++)s=n[r],t[s]=e[s];return t}function El(e){function t(n,r,o,s){let i=n[s++];if(i==="__proto__")return!0;const a=Number.isFinite(+i),l=s>=n.length;return i=!i&&U.isArray(o)?o.length:i,l?(U.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!U.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&U.isArray(o[i])&&(o[i]=Em(o[i])),!a)}if(U.isFormData(e)&&U.isFunction(e.entries)){const n={};return U.forEachEntry(e,(r,o)=>{t(km(r),o,n,0)}),n}return null}function Im(e,t,n){if(U.isString(e))try{return(t||JSON.parse)(e),U.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const $r={transitional:kl,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=U.isObject(t);if(s&&U.isHTMLForm(t)&&(t=new FormData(t)),U.isFormData(t))return o?JSON.stringify(El(t)):t;if(U.isArrayBuffer(t)||U.isBuffer(t)||U.isStream(t)||U.isFile(t)||U.isBlob(t)||U.isReadableStream(t))return t;if(U.isArrayBufferView(t))return t.buffer;if(U.isURLSearchParams(t))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let a;if(s){if(r.indexOf("application/x-www-form-urlencoded")>-1)return Tm(t,this.formSerializer).toString();if((a=U.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return Eo(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),Im(t)):t}],transformResponse:[function(t){const n=this.transitional||$r.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(U.isResponse(t)||U.isReadableStream(t))return t;if(t&&U.isString(t)&&(r&&!this.responseType||o)){const i=!(n&&n.silentJSONParsing)&&o;try{return JSON.parse(t,this.parseReviver)}catch(a){if(i)throw a.name==="SyntaxError"?Te.from(a,Te.ERR_BAD_RESPONSE,this,null,this.response):a}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:lt.classes.FormData,Blob:lt.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};U.forEach(["delete","get","head","post","put","patch"],e=>{$r.headers[e]={}});const Am=U.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),Nm=e=>{const t={};let n,r,o;return e&&e.split(`
2
- `).forEach(function(i){o=i.indexOf(":"),n=i.substring(0,o).trim().toLowerCase(),r=i.substring(o+1).trim(),!(!n||t[n]&&Am[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},Il=Symbol("internals");function Fr(e){return e&&String(e).trim().toLowerCase()}function Io(e){return e===!1||e==null?e:U.isArray(e)?e.map(Io):String(e)}function jm(e){const t=Object.create(null),n=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let r;for(;r=n.exec(e);)t[r[1]]=r[2];return t}const _m=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function Js(e,t,n,r,o){if(U.isFunction(r))return r.call(this,t,n);if(o&&(t=n),!!U.isString(t)){if(U.isString(r))return t.indexOf(r)!==-1;if(U.isRegExp(r))return r.test(t)}}function Pm(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function Rm(e,t){const n=U.toCamelCase(" "+t);["get","set","has"].forEach(r=>{Object.defineProperty(e,r+n,{value:function(o,s,i){return this[r].call(this,t,o,s,i)},configurable:!0})})}let Ct=class{constructor(t){t&&this.set(t)}set(t,n,r){const o=this;function s(a,l,c){const u=Fr(l);if(!u)throw new Error("header name must be a non-empty string");const f=U.findKey(o,u);(!f||o[f]===void 0||c===!0||c===void 0&&o[f]!==!1)&&(o[f||l]=Io(a))}const i=(a,l)=>U.forEach(a,(c,u)=>s(c,u,l));if(U.isPlainObject(t)||t instanceof this.constructor)i(t,n);else if(U.isString(t)&&(t=t.trim())&&!_m(t))i(Nm(t),n);else if(U.isObject(t)&&U.isIterable(t)){let a={},l,c;for(const u of t){if(!U.isArray(u))throw TypeError("Object iterator must return a key-value pair");a[c=u[0]]=(l=a[c])?U.isArray(l)?[...l,u[1]]:[l,u[1]]:u[1]}i(a,n)}else t!=null&&s(n,t,r);return this}get(t,n){if(t=Fr(t),t){const r=U.findKey(this,t);if(r){const o=this[r];if(!n)return o;if(n===!0)return jm(o);if(U.isFunction(n))return n.call(this,o,r);if(U.isRegExp(n))return n.exec(o);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,n){if(t=Fr(t),t){const r=U.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||Js(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let o=!1;function s(i){if(i=Fr(i),i){const a=U.findKey(r,i);a&&(!n||Js(r,r[a],a,n))&&(delete r[a],o=!0)}}return U.isArray(t)?t.forEach(s):s(t),o}clear(t){const n=Object.keys(this);let r=n.length,o=!1;for(;r--;){const s=n[r];(!t||Js(this,this[s],s,t,!0))&&(delete this[s],o=!0)}return o}normalize(t){const n=this,r={};return U.forEach(this,(o,s)=>{const i=U.findKey(r,s);if(i){n[i]=Io(o),delete n[s];return}const a=t?Pm(s):String(s).trim();a!==s&&delete n[s],n[a]=Io(o),r[a]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return U.forEach(this,(r,o)=>{r!=null&&r!==!1&&(n[o]=t&&U.isArray(r)?r.join(", "):r)}),n}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([t,n])=>t+": "+n).join(`
3
- `)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const r=new this(t);return n.forEach(o=>r.set(o)),r}static accessor(t){const r=(this[Il]=this[Il]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Fr(i);r[a]||(Rm(o,i),r[a]=!0)}return U.isArray(t)?t.forEach(s):s(t),this}};Ct.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),U.reduceDescriptors(Ct.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),U.freezeMethods(Ct);function Zs(e,t){const n=this||$r,r=t||n,o=Ct.from(r.headers);let s=r.data;return U.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function Al(e){return!!(e&&e.__CANCEL__)}function fr(e,t,n){Te.call(this,e??"canceled",Te.ERR_CANCELED,t,n),this.name="CanceledError"}U.inherits(fr,Te,{__CANCEL__:!0});function Nl(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Te("Request failed with status code "+n.status,[Te.ERR_BAD_REQUEST,Te.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function Om(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Mm(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o=0,s=0,i;return t=t!==void 0?t:1e3,function(l){const c=Date.now(),u=r[s];i||(i=c),n[o]=l,r[o]=c;let f=s,h=0;for(;f!==o;)h+=n[f++],f=f%e;if(o=(o+1)%e,o===s&&(s=(s+1)%e),c-i<t)return;const p=u&&c-u;return p?Math.round(h*1e3/p):void 0}}function Dm(e,t){let n=0,r=1e3/t,o,s;const i=(c,u=Date.now())=>{n=u,o=null,s&&(clearTimeout(s),s=null),e(...c)};return[(...c)=>{const u=Date.now(),f=u-n;f>=r?i(c,u):(o=c,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const Ao=(e,t,n=3)=>{let r=0;const o=Mm(50,250);return Dm(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,l=i-r,c=o(l),u=i<=a;r=i;const f={loaded:i,total:a,progress:a?i/a:void 0,bytes:l,rate:c||void 0,estimated:c&&a&&u?(a-i)/c:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},n)},jl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},_l=e=>(...t)=>U.asap(()=>e(...t)),Lm=lt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,lt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(lt.origin),lt.navigator&&/(msie|trident)/i.test(lt.navigator.userAgent)):()=>!0,$m=lt.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];U.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),U.isString(r)&&i.push("path="+r),U.isString(o)&&i.push("domain="+o),s===!0&&i.push("secure"),document.cookie=i.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function Fm(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function zm(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function Pl(e,t,n){let r=!Fm(t);return e&&(r||n==!1)?zm(e,t):t}const Rl=e=>e instanceof Ct?{...e}:e;function Wn(e,t){t=t||{};const n={};function r(c,u,f,h){return U.isPlainObject(c)&&U.isPlainObject(u)?U.merge.call({caseless:h},c,u):U.isPlainObject(u)?U.merge({},u):U.isArray(u)?u.slice():u}function o(c,u,f,h){if(U.isUndefined(u)){if(!U.isUndefined(c))return r(void 0,c,f,h)}else return r(c,u,f,h)}function s(c,u){if(!U.isUndefined(u))return r(void 0,u)}function i(c,u){if(U.isUndefined(u)){if(!U.isUndefined(c))return r(void 0,c)}else return r(void 0,u)}function a(c,u,f){if(f in t)return r(c,u);if(f in e)return r(void 0,c)}const l={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(c,u,f)=>o(Rl(c),Rl(u),f,!0)};return U.forEach(Object.keys({...e,...t}),function(u){const f=l[u]||o,h=f(e[u],t[u],u);U.isUndefined(h)&&f!==a||(n[u]=h)}),n}const Ol=e=>{const t=Wn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=Ct.from(i),t.url=Cl(Pl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),U.isFormData(n)){if(lt.hasStandardBrowserEnv||lt.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(U.isFunction(n.getHeaders)){const l=n.getHeaders(),c=["content-type","content-length"];Object.entries(l).forEach(([u,f])=>{c.includes(u.toLowerCase())&&i.set(u,f)})}}if(lt.hasStandardBrowserEnv&&(r&&U.isFunction(r)&&(r=r(t)),r||r!==!1&&Lm(t.url))){const l=o&&s&&$m.read(s);l&&i.set(o,l)}return t},Bm=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=Ol(e);let s=o.data;const i=Ct.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:c}=o,u,f,h,p,m;function b(){p&&p(),m&&m(),o.cancelToken&&o.cancelToken.unsubscribe(u),o.signal&&o.signal.removeEventListener("abort",u)}let g=new XMLHttpRequest;g.open(o.method.toUpperCase(),o.url,!0),g.timeout=o.timeout;function w(){if(!g)return;const k=Ct.from("getAllResponseHeaders"in g&&g.getAllResponseHeaders()),S={data:!a||a==="text"||a==="json"?g.responseText:g.response,status:g.status,statusText:g.statusText,headers:k,config:e,request:g};Nl(function(T){n(T),b()},function(T){r(T),b()},S),g=null}"onloadend"in g?g.onloadend=w:g.onreadystatechange=function(){!g||g.readyState!==4||g.status===0&&!(g.responseURL&&g.responseURL.indexOf("file:")===0)||setTimeout(w)},g.onabort=function(){g&&(r(new Te("Request aborted",Te.ECONNABORTED,e,g)),g=null)},g.onerror=function(E){const S=E&&E.message?E.message:"Network Error",C=new Te(S,Te.ERR_NETWORK,e,g);C.event=E||null,r(C),g=null},g.ontimeout=function(){let E=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const S=o.transitional||kl;o.timeoutErrorMessage&&(E=o.timeoutErrorMessage),r(new Te(E,S.clarifyTimeoutError?Te.ETIMEDOUT:Te.ECONNABORTED,e,g)),g=null},s===void 0&&i.setContentType(null),"setRequestHeader"in g&&U.forEach(i.toJSON(),function(E,S){g.setRequestHeader(S,E)}),U.isUndefined(o.withCredentials)||(g.withCredentials=!!o.withCredentials),a&&a!=="json"&&(g.responseType=o.responseType),c&&([h,m]=Ao(c,!0),g.addEventListener("progress",h)),l&&g.upload&&([f,p]=Ao(l),g.upload.addEventListener("progress",f),g.upload.addEventListener("loadend",p)),(o.cancelToken||o.signal)&&(u=k=>{g&&(r(!k||k.type?new fr(null,e,g):k),g.abort(),g=null)},o.cancelToken&&o.cancelToken.subscribe(u),o.signal&&(o.signal.aborted?u():o.signal.addEventListener("abort",u)));const y=Om(o.url);if(y&&lt.protocols.indexOf(y)===-1){r(new Te("Unsupported protocol "+y+":",Te.ERR_BAD_REQUEST,e));return}g.send(s||null)})},Um=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,o;const s=function(c){if(!o){o=!0,a();const u=c instanceof Error?c:this.reason;r.abort(u instanceof Te?u:new fr(u instanceof Error?u.message:u))}};let i=t&&setTimeout(()=>{i=null,s(new Te(`timeout ${t} of ms exceeded`,Te.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(c=>{c.unsubscribe?c.unsubscribe(s):c.removeEventListener("abort",s)}),e=null)};e.forEach(c=>c.addEventListener("abort",s));const{signal:l}=r;return l.unsubscribe=()=>U.asap(a),l}},Hm=function*(e,t){let n=e.byteLength;if(n<t){yield e;return}let r=0,o;for(;r<n;)o=r+t,yield e.slice(r,o),r=o},Wm=async function*(e,t){for await(const n of Vm(e))yield*Hm(n,t)},Vm=async function*(e){if(e[Symbol.asyncIterator]){yield*e;return}const t=e.getReader();try{for(;;){const{done:n,value:r}=await t.read();if(n)break;yield r}}finally{await t.cancel()}},Ml=(e,t,n,r)=>{const o=Wm(e,t);let s=0,i,a=l=>{i||(i=!0,r&&r(l))};return new ReadableStream({async pull(l){try{const{done:c,value:u}=await o.next();if(c){a(),l.close();return}let f=u.byteLength;if(n){let h=s+=f;n(h)}l.enqueue(new Uint8Array(u))}catch(c){throw a(c),c}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},Dl=64*1024,{isFunction:No}=U,Km=(({Request:e,Response:t})=>({Request:e,Response:t}))(U.global),{ReadableStream:Ll,TextEncoder:$l}=U.global,Fl=(e,...t)=>{try{return!!e(...t)}catch{return!1}},qm=e=>{e=U.merge.call({skipUndefined:!0},Km,e);const{fetch:t,Request:n,Response:r}=e,o=t?No(t):typeof fetch=="function",s=No(n),i=No(r);if(!o)return!1;const a=o&&No(Ll),l=o&&(typeof $l=="function"?(m=>b=>m.encode(b))(new $l):async m=>new Uint8Array(await new n(m).arrayBuffer())),c=s&&a&&Fl(()=>{let m=!1;const b=new n(lt.origin,{body:new Ll,method:"POST",get duplex(){return m=!0,"half"}}).headers.has("Content-Type");return m&&!b}),u=i&&a&&Fl(()=>U.isReadableStream(new r("").body)),f={stream:u&&(m=>m.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(m=>{!f[m]&&(f[m]=(b,g)=>{let w=b&&b[m];if(w)return w.call(b);throw new Te(`Response type '${m}' is not supported`,Te.ERR_NOT_SUPPORT,g)})});const h=async m=>{if(m==null)return 0;if(U.isBlob(m))return m.size;if(U.isSpecCompliantForm(m))return(await new n(lt.origin,{method:"POST",body:m}).arrayBuffer()).byteLength;if(U.isArrayBufferView(m)||U.isArrayBuffer(m))return m.byteLength;if(U.isURLSearchParams(m)&&(m=m+""),U.isString(m))return(await l(m)).byteLength},p=async(m,b)=>{const g=U.toFiniteNumber(m.getContentLength());return g??h(b)};return async m=>{let{url:b,method:g,data:w,signal:y,cancelToken:k,timeout:E,onDownloadProgress:S,onUploadProgress:C,responseType:T,headers:A,withCredentials:N="same-origin",fetchOptions:j}=Ol(m),L=t||fetch;T=T?(T+"").toLowerCase():"text";let B=Um([y,k&&k.toAbortSignal()],E),W=null;const O=B&&B.unsubscribe&&(()=>{B.unsubscribe()});let D;try{if(C&&c&&g!=="get"&&g!=="head"&&(D=await p(A,w))!==0){let q=new n(b,{method:"POST",body:w,duplex:"half"}),M;if(U.isFormData(w)&&(M=q.headers.get("content-type"))&&A.setContentType(M),q.body){const[P,$]=jl(D,Ao(_l(C)));w=Ml(q.body,Dl,P,$)}}U.isString(N)||(N=N?"include":"omit");const z=s&&"credentials"in n.prototype,ee={...j,signal:B,method:g.toUpperCase(),headers:A.normalize().toJSON(),body:w,duplex:"half",credentials:z?N:void 0};W=s&&new n(b,ee);let H=await(s?L(W,j):L(b,ee));const V=u&&(T==="stream"||T==="response");if(u&&(S||V&&O)){const q={};["status","statusText","headers"].forEach(R=>{q[R]=H[R]});const M=U.toFiniteNumber(H.headers.get("content-length")),[P,$]=S&&jl(M,Ao(_l(S),!0))||[];H=new r(Ml(H.body,Dl,P,()=>{$&&$(),O&&O()}),q)}T=T||"text";let Y=await f[U.findKey(f,T)||"text"](H,m);return!V&&O&&O(),await new Promise((q,M)=>{Nl(q,M,{data:Y,headers:Ct.from(H.headers),status:H.status,statusText:H.statusText,config:m,request:W})})}catch(z){throw O&&O(),z&&z.name==="TypeError"&&/Load failed|fetch/i.test(z.message)?Object.assign(new Te("Network Error",Te.ERR_NETWORK,m,W),{cause:z.cause||z}):Te.from(z,z&&z.code,m,W)}}},Gm=new Map,zl=e=>{let t=e?e.env:{};const{fetch:n,Request:r,Response:o}=t,s=[r,o,n];let i=s.length,a=i,l,c,u=Gm;for(;a--;)l=s[a],c=u.get(l),c===void 0&&u.set(l,c=a?new Map:qm(t)),u=c;return c};zl();const Qs={http:gm,xhr:Bm,fetch:{get:zl}};U.forEach(Qs,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Bl=e=>`- ${e}`,Ym=e=>U.isFunction(e)||e===null||e===!1,Ul={getAdapter:(e,t)=>{e=U.isArray(e)?e:[e];const{length:n}=e;let r,o;const s={};for(let i=0;i<n;i++){r=e[i];let a;if(o=r,!Ym(r)&&(o=Qs[(a=String(r)).toLowerCase()],o===void 0))throw new Te(`Unknown adapter '${a}'`);if(o&&(U.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([l,c])=>`adapter ${l} `+(c===!1?"is not supported by the environment":"is not available in the build"));let a=n?i.length>1?`since :
1
+ (function(J,vt){typeof exports=="object"&&typeof module<"u"?vt(exports,require("clsx"),require("tailwind-merge"),require("react"),require("@radix-ui/react-slot"),require("class-variance-authority"),require("react-dom"),require("lucide-react")):typeof define=="function"&&define.amd?define(["exports","clsx","tailwind-merge","react","@radix-ui/react-slot","class-variance-authority","react-dom","lucide-react"],vt):(J=typeof globalThis<"u"?globalThis:J||self,vt(J.NewChatUI={},J.clsx,J.tailwindMerge,J.React,J.reactSlot,J.classVarianceAuthority,J.ReactDOM,J.LucideReact))})(this,function(J,vt,Un,v,lr,jp,Ws,xe){"use strict";var qC=Object.defineProperty;var GC=(J,vt,Un)=>vt in J?qC(J,vt,{enumerable:!0,configurable:!0,writable:!0,value:Un}):J[vt]=Un;var sl=(J,vt,Un)=>GC(J,typeof vt!="symbol"?vt+"":vt,Un);function il(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const x=il(v),al=il(Ws);function _p(...e){return Un.twMerge(vt.clsx(e))}function ll(e,t){return function(){return e.apply(t,arguments)}}const{toString:Pp}=Object.prototype,{getPrototypeOf:Vs}=Object,{iterator:So,toStringTag:cl}=Symbol,Co=(e=>t=>{const n=Pp.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),Kt=e=>(e=e.toLowerCase(),t=>Co(t)===e),To=e=>t=>typeof t===e,{isArray:cr}=Array,ur=To("undefined");function Or(e){return e!==null&&!ur(e)&&e.constructor!==null&&!ur(e.constructor)&&St(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const ul=Kt("ArrayBuffer");function Rp(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&ul(e.buffer),t}const Op=To("string"),St=To("function"),dl=To("number"),Mr=e=>e!==null&&typeof e=="object",Mp=e=>e===!0||e===!1,ko=e=>{if(Co(e)!=="object")return!1;const t=Vs(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(cl in e)&&!(So in e)},Dp=e=>{if(!Mr(e)||Or(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Lp=Kt("Date"),$p=Kt("File"),Fp=Kt("Blob"),zp=Kt("FileList"),Bp=e=>Mr(e)&&St(e.pipe),Up=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||St(e.append)&&((t=Co(e))==="formdata"||t==="object"&&St(e.toString)&&e.toString()==="[object FormData]"))},Hp=Kt("URLSearchParams"),[Wp,Vp,Kp,qp]=["ReadableStream","Request","Response","Headers"].map(Kt),Gp=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Dr(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),cr(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(Or(e))return;const s=n?Object.getOwnPropertyNames(e):Object.keys(e),i=s.length;let a;for(r=0;r<i;r++)a=s[r],t.call(null,e[a],a,e)}}function fl(e,t){if(Or(e))return null;t=t.toLowerCase();const n=Object.keys(e);let r=n.length,o;for(;r-- >0;)if(o=n[r],t===o.toLowerCase())return o;return null}const Hn=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,hl=e=>!ur(e)&&e!==Hn;function Ks(){const{caseless:e,skipUndefined:t}=hl(this)&&this||{},n={},r=(o,s)=>{const i=e&&fl(n,s)||s;ko(n[i])&&ko(o)?n[i]=Ks(n[i],o):ko(o)?n[i]=Ks({},o):cr(o)?n[i]=o.slice():(!t||!ur(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&Dr(arguments[o],r);return n}const Yp=(e,t,n,{allOwnKeys:r}={})=>(Dr(t,(o,s)=>{n&&St(o)?e[s]=ll(o,n):e[s]=o},{allOwnKeys:r}),e),Xp=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),Jp=(e,t,n,r)=>{e.prototype=Object.create(t.prototype,r),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},Zp=(e,t,n,r)=>{let o,s,i;const a={};if(t=t||{},e==null)return t;do{for(o=Object.getOwnPropertyNames(e),s=o.length;s-- >0;)i=o[s],(!r||r(i,e,t))&&!a[i]&&(t[i]=e[i],a[i]=!0);e=n!==!1&&Vs(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},Qp=(e,t,n)=>{e=String(e),(n===void 0||n>e.length)&&(n=e.length),n-=t.length;const r=e.indexOf(t,n);return r!==-1&&r===n},em=e=>{if(!e)return null;if(cr(e))return e;let t=e.length;if(!dl(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},tm=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Vs(Uint8Array)),nm=(e,t)=>{const r=(e&&e[So]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},rm=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},om=Kt("HTMLFormElement"),sm=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),pl=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),im=Kt("RegExp"),ml=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Dr(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},am=e=>{ml(e,(t,n)=>{if(St(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(St(r)){if(t.enumerable=!1,"writable"in t){t.writable=!1;return}t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")})}})},lm=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return cr(e)?r(e):r(String(e).split(t)),n},cm=()=>{},um=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function dm(e){return!!(e&&St(e.append)&&e[cl]==="FormData"&&e[So])}const fm=e=>{const t=new Array(10),n=(r,o)=>{if(Mr(r)){if(t.indexOf(r)>=0)return;if(Or(r))return r;if(!("toJSON"in r)){t[o]=r;const s=cr(r)?[]:{};return Dr(r,(i,a)=>{const l=n(i,o+1);!ur(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},hm=Kt("AsyncFunction"),pm=e=>e&&(Mr(e)||St(e))&&St(e.then)&&St(e.catch),gl=((e,t)=>e?setImmediate:t?((n,r)=>(Hn.addEventListener("message",({source:o,data:s})=>{o===Hn&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),Hn.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",St(Hn.postMessage)),mm=typeof queueMicrotask<"u"?queueMicrotask.bind(Hn):typeof process<"u"&&process.nextTick||gl,B={isArray:cr,isArrayBuffer:ul,isBuffer:Or,isFormData:Up,isArrayBufferView:Rp,isString:Op,isNumber:dl,isBoolean:Mp,isObject:Mr,isPlainObject:ko,isEmptyObject:Dp,isReadableStream:Wp,isRequest:Vp,isResponse:Kp,isHeaders:qp,isUndefined:ur,isDate:Lp,isFile:$p,isBlob:Fp,isRegExp:im,isFunction:St,isStream:Bp,isURLSearchParams:Hp,isTypedArray:tm,isFileList:zp,forEach:Dr,merge:Ks,extend:Yp,trim:Gp,stripBOM:Xp,inherits:Jp,toFlatObject:Zp,kindOf:Co,kindOfTest:Kt,endsWith:Qp,toArray:em,forEachEntry:nm,matchAll:rm,isHTMLForm:om,hasOwnProperty:pl,hasOwnProp:pl,reduceDescriptors:ml,freezeMethods:am,toObjectSet:lm,toCamelCase:sm,noop:cm,toFiniteNumber:um,findKey:fl,global:Hn,isContextDefined:hl,isSpecCompliantForm:dm,toJSONObject:fm,isAsyncFn:hm,isThenable:pm,setImmediate:gl,asap:mm,isIterable:e=>e!=null&&St(e[So])};function Te(e,t,n,r,o){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),r&&(this.request=r),o&&(this.response=o,this.status=o.status?o.status:null)}B.inherits(Te,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:B.toJSONObject(this.config),code:this.code,status:this.status}}});const xl=Te.prototype,bl={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(e=>{bl[e]={value:e}}),Object.defineProperties(Te,bl),Object.defineProperty(xl,"isAxiosError",{value:!0}),Te.from=(e,t,n,r,o,s)=>{const i=Object.create(xl);B.toFlatObject(e,i,function(u){return u!==Error.prototype},c=>c!=="isAxiosError");const a=e&&e.message?e.message:"Error",l=t==null&&e?e.code:t;return Te.call(i,a,l,n,r,o),e&&i.cause==null&&Object.defineProperty(i,"cause",{value:e,configurable:!0}),i.name=e&&e.name||"Error",s&&Object.assign(i,s),i};const gm=null;function qs(e){return B.isPlainObject(e)||B.isArray(e)}function wl(e){return B.endsWith(e,"[]")?e.slice(0,-2):e}function yl(e,t,n){return e?e.concat(t).map(function(o,s){return o=wl(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function xm(e){return B.isArray(e)&&!e.some(qs)}const bm=B.toFlatObject(B,{},null,function(t){return/^is[A-Z]/.test(t)});function Eo(e,t,n){if(!B.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=B.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(b,g){return!B.isUndefined(g[b])});const r=n.metaTokens,o=n.visitor||u,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&B.isSpecCompliantForm(t);if(!B.isFunction(o))throw new TypeError("visitor must be a function");function c(m){if(m===null)return"";if(B.isDate(m))return m.toISOString();if(B.isBoolean(m))return m.toString();if(!l&&B.isBlob(m))throw new Te("Blob is not supported. Use a Buffer instead.");return B.isArrayBuffer(m)||B.isTypedArray(m)?l&&typeof Blob=="function"?new Blob([m]):Buffer.from(m):m}function u(m,b,g){let w=m;if(m&&!g&&typeof m=="object"){if(B.endsWith(b,"{}"))b=r?b:b.slice(0,-2),m=JSON.stringify(m);else if(B.isArray(m)&&xm(m)||(B.isFileList(m)||B.endsWith(b,"[]"))&&(w=B.toArray(m)))return b=wl(b),w.forEach(function(k,E){!(B.isUndefined(k)||k===null)&&t.append(i===!0?yl([b],E,s):i===null?b:b+"[]",c(k))}),!1}return qs(m)?!0:(t.append(yl(g,b,s),c(m)),!1)}const f=[],h=Object.assign(bm,{defaultVisitor:u,convertValue:c,isVisitable:qs});function p(m,b){if(!B.isUndefined(m)){if(f.indexOf(m)!==-1)throw Error("Circular reference detected in "+b.join("."));f.push(m),B.forEach(m,function(w,y){(!(B.isUndefined(w)||w===null)&&o.call(t,w,B.isString(y)?y.trim():y,b,h))===!0&&p(w,b?b.concat(y):[y])}),f.pop()}}if(!B.isObject(e))throw new TypeError("data must be an object");return p(e),t}function vl(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function Gs(e,t){this._pairs=[],e&&Eo(e,this,t)}const Sl=Gs.prototype;Sl.append=function(t,n){this._pairs.push([t,n])},Sl.toString=function(t){const n=t?function(r){return t.call(this,r,vl)}:vl;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function wm(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function Cl(e,t,n){if(!t)return e;const r=n&&n.encode||wm;B.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=B.isURLSearchParams(t)?t.toString():new Gs(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class Tl{constructor(){this.handlers=[]}use(t,n,r){return this.handlers.push({fulfilled:t,rejected:n,synchronous:r?r.synchronous:!1,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){B.forEach(this.handlers,function(r){r!==null&&t(r)})}}const kl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},ym={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:Gs,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},Ys=typeof window<"u"&&typeof document<"u",Xs=typeof navigator=="object"&&navigator||void 0,vm=Ys&&(!Xs||["ReactNative","NativeScript","NS"].indexOf(Xs.product)<0),Sm=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",Cm=Ys&&window.location.href||"http://localhost",lt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:Ys,hasStandardBrowserEnv:vm,hasStandardBrowserWebWorkerEnv:Sm,navigator:Xs,origin:Cm},Symbol.toStringTag,{value:"Module"})),...ym};function Tm(e,t){return Eo(e,new lt.classes.URLSearchParams,{visitor:function(n,r,o,s){return lt.isNode&&B.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function km(e){return B.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Em(e){const t={},n=Object.keys(e);let r;const o=n.length;let s;for(r=0;r<o;r++)s=n[r],t[s]=e[s];return t}function El(e){function t(n,r,o,s){let i=n[s++];if(i==="__proto__")return!0;const a=Number.isFinite(+i),l=s>=n.length;return i=!i&&B.isArray(o)?o.length:i,l?(B.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!B.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&B.isArray(o[i])&&(o[i]=Em(o[i])),!a)}if(B.isFormData(e)&&B.isFunction(e.entries)){const n={};return B.forEachEntry(e,(r,o)=>{t(km(r),o,n,0)}),n}return null}function Im(e,t,n){if(B.isString(e))try{return(t||JSON.parse)(e),B.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const Lr={transitional:kl,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=B.isObject(t);if(s&&B.isHTMLForm(t)&&(t=new FormData(t)),B.isFormData(t))return o?JSON.stringify(El(t)):t;if(B.isArrayBuffer(t)||B.isBuffer(t)||B.isStream(t)||B.isFile(t)||B.isBlob(t)||B.isReadableStream(t))return t;if(B.isArrayBufferView(t))return t.buffer;if(B.isURLSearchParams(t))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let a;if(s){if(r.indexOf("application/x-www-form-urlencoded")>-1)return Tm(t,this.formSerializer).toString();if((a=B.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return Eo(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),Im(t)):t}],transformResponse:[function(t){const n=this.transitional||Lr.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(B.isResponse(t)||B.isReadableStream(t))return t;if(t&&B.isString(t)&&(r&&!this.responseType||o)){const i=!(n&&n.silentJSONParsing)&&o;try{return JSON.parse(t,this.parseReviver)}catch(a){if(i)throw a.name==="SyntaxError"?Te.from(a,Te.ERR_BAD_RESPONSE,this,null,this.response):a}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:lt.classes.FormData,Blob:lt.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};B.forEach(["delete","get","head","post","put","patch"],e=>{Lr.headers[e]={}});const Am=B.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),Nm=e=>{const t={};let n,r,o;return e&&e.split(`
2
+ `).forEach(function(i){o=i.indexOf(":"),n=i.substring(0,o).trim().toLowerCase(),r=i.substring(o+1).trim(),!(!n||t[n]&&Am[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},Il=Symbol("internals");function $r(e){return e&&String(e).trim().toLowerCase()}function Io(e){return e===!1||e==null?e:B.isArray(e)?e.map(Io):String(e)}function jm(e){const t=Object.create(null),n=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let r;for(;r=n.exec(e);)t[r[1]]=r[2];return t}const _m=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function Js(e,t,n,r,o){if(B.isFunction(r))return r.call(this,t,n);if(o&&(t=n),!!B.isString(t)){if(B.isString(r))return t.indexOf(r)!==-1;if(B.isRegExp(r))return r.test(t)}}function Pm(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function Rm(e,t){const n=B.toCamelCase(" "+t);["get","set","has"].forEach(r=>{Object.defineProperty(e,r+n,{value:function(o,s,i){return this[r].call(this,t,o,s,i)},configurable:!0})})}let Ct=class{constructor(t){t&&this.set(t)}set(t,n,r){const o=this;function s(a,l,c){const u=$r(l);if(!u)throw new Error("header name must be a non-empty string");const f=B.findKey(o,u);(!f||o[f]===void 0||c===!0||c===void 0&&o[f]!==!1)&&(o[f||l]=Io(a))}const i=(a,l)=>B.forEach(a,(c,u)=>s(c,u,l));if(B.isPlainObject(t)||t instanceof this.constructor)i(t,n);else if(B.isString(t)&&(t=t.trim())&&!_m(t))i(Nm(t),n);else if(B.isObject(t)&&B.isIterable(t)){let a={},l,c;for(const u of t){if(!B.isArray(u))throw TypeError("Object iterator must return a key-value pair");a[c=u[0]]=(l=a[c])?B.isArray(l)?[...l,u[1]]:[l,u[1]]:u[1]}i(a,n)}else t!=null&&s(n,t,r);return this}get(t,n){if(t=$r(t),t){const r=B.findKey(this,t);if(r){const o=this[r];if(!n)return o;if(n===!0)return jm(o);if(B.isFunction(n))return n.call(this,o,r);if(B.isRegExp(n))return n.exec(o);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,n){if(t=$r(t),t){const r=B.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||Js(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let o=!1;function s(i){if(i=$r(i),i){const a=B.findKey(r,i);a&&(!n||Js(r,r[a],a,n))&&(delete r[a],o=!0)}}return B.isArray(t)?t.forEach(s):s(t),o}clear(t){const n=Object.keys(this);let r=n.length,o=!1;for(;r--;){const s=n[r];(!t||Js(this,this[s],s,t,!0))&&(delete this[s],o=!0)}return o}normalize(t){const n=this,r={};return B.forEach(this,(o,s)=>{const i=B.findKey(r,s);if(i){n[i]=Io(o),delete n[s];return}const a=t?Pm(s):String(s).trim();a!==s&&delete n[s],n[a]=Io(o),r[a]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return B.forEach(this,(r,o)=>{r!=null&&r!==!1&&(n[o]=t&&B.isArray(r)?r.join(", "):r)}),n}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([t,n])=>t+": "+n).join(`
3
+ `)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const r=new this(t);return n.forEach(o=>r.set(o)),r}static accessor(t){const r=(this[Il]=this[Il]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=$r(i);r[a]||(Rm(o,i),r[a]=!0)}return B.isArray(t)?t.forEach(s):s(t),this}};Ct.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),B.reduceDescriptors(Ct.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),B.freezeMethods(Ct);function Zs(e,t){const n=this||Lr,r=t||n,o=Ct.from(r.headers);let s=r.data;return B.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function Al(e){return!!(e&&e.__CANCEL__)}function dr(e,t,n){Te.call(this,e??"canceled",Te.ERR_CANCELED,t,n),this.name="CanceledError"}B.inherits(dr,Te,{__CANCEL__:!0});function Nl(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Te("Request failed with status code "+n.status,[Te.ERR_BAD_REQUEST,Te.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function Om(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Mm(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o=0,s=0,i;return t=t!==void 0?t:1e3,function(l){const c=Date.now(),u=r[s];i||(i=c),n[o]=l,r[o]=c;let f=s,h=0;for(;f!==o;)h+=n[f++],f=f%e;if(o=(o+1)%e,o===s&&(s=(s+1)%e),c-i<t)return;const p=u&&c-u;return p?Math.round(h*1e3/p):void 0}}function Dm(e,t){let n=0,r=1e3/t,o,s;const i=(c,u=Date.now())=>{n=u,o=null,s&&(clearTimeout(s),s=null),e(...c)};return[(...c)=>{const u=Date.now(),f=u-n;f>=r?i(c,u):(o=c,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const Ao=(e,t,n=3)=>{let r=0;const o=Mm(50,250);return Dm(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,l=i-r,c=o(l),u=i<=a;r=i;const f={loaded:i,total:a,progress:a?i/a:void 0,bytes:l,rate:c||void 0,estimated:c&&a&&u?(a-i)/c:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},n)},jl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},_l=e=>(...t)=>B.asap(()=>e(...t)),Lm=lt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,lt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(lt.origin),lt.navigator&&/(msie|trident)/i.test(lt.navigator.userAgent)):()=>!0,$m=lt.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];B.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),B.isString(r)&&i.push("path="+r),B.isString(o)&&i.push("domain="+o),s===!0&&i.push("secure"),document.cookie=i.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function Fm(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function zm(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function Pl(e,t,n){let r=!Fm(t);return e&&(r||n==!1)?zm(e,t):t}const Rl=e=>e instanceof Ct?{...e}:e;function Wn(e,t){t=t||{};const n={};function r(c,u,f,h){return B.isPlainObject(c)&&B.isPlainObject(u)?B.merge.call({caseless:h},c,u):B.isPlainObject(u)?B.merge({},u):B.isArray(u)?u.slice():u}function o(c,u,f,h){if(B.isUndefined(u)){if(!B.isUndefined(c))return r(void 0,c,f,h)}else return r(c,u,f,h)}function s(c,u){if(!B.isUndefined(u))return r(void 0,u)}function i(c,u){if(B.isUndefined(u)){if(!B.isUndefined(c))return r(void 0,c)}else return r(void 0,u)}function a(c,u,f){if(f in t)return r(c,u);if(f in e)return r(void 0,c)}const l={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(c,u,f)=>o(Rl(c),Rl(u),f,!0)};return B.forEach(Object.keys({...e,...t}),function(u){const f=l[u]||o,h=f(e[u],t[u],u);B.isUndefined(h)&&f!==a||(n[u]=h)}),n}const Ol=e=>{const t=Wn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=Ct.from(i),t.url=Cl(Pl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),B.isFormData(n)){if(lt.hasStandardBrowserEnv||lt.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(B.isFunction(n.getHeaders)){const l=n.getHeaders(),c=["content-type","content-length"];Object.entries(l).forEach(([u,f])=>{c.includes(u.toLowerCase())&&i.set(u,f)})}}if(lt.hasStandardBrowserEnv&&(r&&B.isFunction(r)&&(r=r(t)),r||r!==!1&&Lm(t.url))){const l=o&&s&&$m.read(s);l&&i.set(o,l)}return t},Bm=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=Ol(e);let s=o.data;const i=Ct.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:c}=o,u,f,h,p,m;function b(){p&&p(),m&&m(),o.cancelToken&&o.cancelToken.unsubscribe(u),o.signal&&o.signal.removeEventListener("abort",u)}let g=new XMLHttpRequest;g.open(o.method.toUpperCase(),o.url,!0),g.timeout=o.timeout;function w(){if(!g)return;const k=Ct.from("getAllResponseHeaders"in g&&g.getAllResponseHeaders()),S={data:!a||a==="text"||a==="json"?g.responseText:g.response,status:g.status,statusText:g.statusText,headers:k,config:e,request:g};Nl(function(T){n(T),b()},function(T){r(T),b()},S),g=null}"onloadend"in g?g.onloadend=w:g.onreadystatechange=function(){!g||g.readyState!==4||g.status===0&&!(g.responseURL&&g.responseURL.indexOf("file:")===0)||setTimeout(w)},g.onabort=function(){g&&(r(new Te("Request aborted",Te.ECONNABORTED,e,g)),g=null)},g.onerror=function(E){const S=E&&E.message?E.message:"Network Error",C=new Te(S,Te.ERR_NETWORK,e,g);C.event=E||null,r(C),g=null},g.ontimeout=function(){let E=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const S=o.transitional||kl;o.timeoutErrorMessage&&(E=o.timeoutErrorMessage),r(new Te(E,S.clarifyTimeoutError?Te.ETIMEDOUT:Te.ECONNABORTED,e,g)),g=null},s===void 0&&i.setContentType(null),"setRequestHeader"in g&&B.forEach(i.toJSON(),function(E,S){g.setRequestHeader(S,E)}),B.isUndefined(o.withCredentials)||(g.withCredentials=!!o.withCredentials),a&&a!=="json"&&(g.responseType=o.responseType),c&&([h,m]=Ao(c,!0),g.addEventListener("progress",h)),l&&g.upload&&([f,p]=Ao(l),g.upload.addEventListener("progress",f),g.upload.addEventListener("loadend",p)),(o.cancelToken||o.signal)&&(u=k=>{g&&(r(!k||k.type?new dr(null,e,g):k),g.abort(),g=null)},o.cancelToken&&o.cancelToken.subscribe(u),o.signal&&(o.signal.aborted?u():o.signal.addEventListener("abort",u)));const y=Om(o.url);if(y&&lt.protocols.indexOf(y)===-1){r(new Te("Unsupported protocol "+y+":",Te.ERR_BAD_REQUEST,e));return}g.send(s||null)})},Um=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,o;const s=function(c){if(!o){o=!0,a();const u=c instanceof Error?c:this.reason;r.abort(u instanceof Te?u:new dr(u instanceof Error?u.message:u))}};let i=t&&setTimeout(()=>{i=null,s(new Te(`timeout ${t} of ms exceeded`,Te.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(c=>{c.unsubscribe?c.unsubscribe(s):c.removeEventListener("abort",s)}),e=null)};e.forEach(c=>c.addEventListener("abort",s));const{signal:l}=r;return l.unsubscribe=()=>B.asap(a),l}},Hm=function*(e,t){let n=e.byteLength;if(n<t){yield e;return}let r=0,o;for(;r<n;)o=r+t,yield e.slice(r,o),r=o},Wm=async function*(e,t){for await(const n of Vm(e))yield*Hm(n,t)},Vm=async function*(e){if(e[Symbol.asyncIterator]){yield*e;return}const t=e.getReader();try{for(;;){const{done:n,value:r}=await t.read();if(n)break;yield r}}finally{await t.cancel()}},Ml=(e,t,n,r)=>{const o=Wm(e,t);let s=0,i,a=l=>{i||(i=!0,r&&r(l))};return new ReadableStream({async pull(l){try{const{done:c,value:u}=await o.next();if(c){a(),l.close();return}let f=u.byteLength;if(n){let h=s+=f;n(h)}l.enqueue(new Uint8Array(u))}catch(c){throw a(c),c}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},Dl=64*1024,{isFunction:No}=B,Km=(({Request:e,Response:t})=>({Request:e,Response:t}))(B.global),{ReadableStream:Ll,TextEncoder:$l}=B.global,Fl=(e,...t)=>{try{return!!e(...t)}catch{return!1}},qm=e=>{e=B.merge.call({skipUndefined:!0},Km,e);const{fetch:t,Request:n,Response:r}=e,o=t?No(t):typeof fetch=="function",s=No(n),i=No(r);if(!o)return!1;const a=o&&No(Ll),l=o&&(typeof $l=="function"?(m=>b=>m.encode(b))(new $l):async m=>new Uint8Array(await new n(m).arrayBuffer())),c=s&&a&&Fl(()=>{let m=!1;const b=new n(lt.origin,{body:new Ll,method:"POST",get duplex(){return m=!0,"half"}}).headers.has("Content-Type");return m&&!b}),u=i&&a&&Fl(()=>B.isReadableStream(new r("").body)),f={stream:u&&(m=>m.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(m=>{!f[m]&&(f[m]=(b,g)=>{let w=b&&b[m];if(w)return w.call(b);throw new Te(`Response type '${m}' is not supported`,Te.ERR_NOT_SUPPORT,g)})});const h=async m=>{if(m==null)return 0;if(B.isBlob(m))return m.size;if(B.isSpecCompliantForm(m))return(await new n(lt.origin,{method:"POST",body:m}).arrayBuffer()).byteLength;if(B.isArrayBufferView(m)||B.isArrayBuffer(m))return m.byteLength;if(B.isURLSearchParams(m)&&(m=m+""),B.isString(m))return(await l(m)).byteLength},p=async(m,b)=>{const g=B.toFiniteNumber(m.getContentLength());return g??h(b)};return async m=>{let{url:b,method:g,data:w,signal:y,cancelToken:k,timeout:E,onDownloadProgress:S,onUploadProgress:C,responseType:T,headers:N,withCredentials:j="same-origin",fetchOptions:_}=Ol(m),D=t||fetch;T=T?(T+"").toLowerCase():"text";let z=Um([y,k&&k.toAbortSignal()],E),H=null;const P=z&&z.unsubscribe&&(()=>{z.unsubscribe()});let M;try{if(C&&c&&g!=="get"&&g!=="head"&&(M=await p(N,w))!==0){let q=new n(b,{method:"POST",body:w,duplex:"half"}),R;if(B.isFormData(w)&&(R=q.headers.get("content-type"))&&N.setContentType(R),q.body){const[G,A]=jl(M,Ao(_l(C)));w=Ml(q.body,Dl,G,A)}}B.isString(j)||(j=j?"include":"omit");const F=s&&"credentials"in n.prototype,ne={..._,signal:z,method:g.toUpperCase(),headers:N.normalize().toJSON(),body:w,duplex:"half",credentials:F?j:void 0};H=s&&new n(b,ne);let U=await(s?D(H,_):D(b,ne));const W=u&&(T==="stream"||T==="response");if(u&&(S||W&&P)){const q={};["status","statusText","headers"].forEach(O=>{q[O]=U[O]});const R=B.toFiniteNumber(U.headers.get("content-length")),[G,A]=S&&jl(R,Ao(_l(S),!0))||[];U=new r(Ml(U.body,Dl,G,()=>{A&&A(),P&&P()}),q)}T=T||"text";let Y=await f[B.findKey(f,T)||"text"](U,m);return!W&&P&&P(),await new Promise((q,R)=>{Nl(q,R,{data:Y,headers:Ct.from(U.headers),status:U.status,statusText:U.statusText,config:m,request:H})})}catch(F){throw P&&P(),F&&F.name==="TypeError"&&/Load failed|fetch/i.test(F.message)?Object.assign(new Te("Network Error",Te.ERR_NETWORK,m,H),{cause:F.cause||F}):Te.from(F,F&&F.code,m,H)}}},Gm=new Map,zl=e=>{let t=e?e.env:{};const{fetch:n,Request:r,Response:o}=t,s=[r,o,n];let i=s.length,a=i,l,c,u=Gm;for(;a--;)l=s[a],c=u.get(l),c===void 0&&u.set(l,c=a?new Map:qm(t)),u=c;return c};zl();const Qs={http:gm,xhr:Bm,fetch:{get:zl}};B.forEach(Qs,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Bl=e=>`- ${e}`,Ym=e=>B.isFunction(e)||e===null||e===!1,Ul={getAdapter:(e,t)=>{e=B.isArray(e)?e:[e];const{length:n}=e;let r,o;const s={};for(let i=0;i<n;i++){r=e[i];let a;if(o=r,!Ym(r)&&(o=Qs[(a=String(r)).toLowerCase()],o===void 0))throw new Te(`Unknown adapter '${a}'`);if(o&&(B.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([l,c])=>`adapter ${l} `+(c===!1?"is not supported by the environment":"is not available in the build"));let a=n?i.length>1?`since :
4
4
  `+i.map(Bl).join(`
5
- `):" "+Bl(i[0]):"as no adapter specified";throw new Te("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:Qs};function ei(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new fr(null,e)}function Hl(e){return ei(e),e.headers=Ct.from(e.headers),e.data=Zs.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),Ul.getAdapter(e.adapter||$r.adapter,e)(e).then(function(r){return ei(e),r.data=Zs.call(e,e.transformResponse,r),r.headers=Ct.from(r.headers),r},function(r){return Al(r)||(ei(e),r&&r.response&&(r.response.data=Zs.call(e,e.transformResponse,r.response),r.response.headers=Ct.from(r.response.headers))),Promise.reject(r)})}const Wl="1.12.2",jo={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{jo[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const Vl={};jo.transitional=function(t,n,r){function o(s,i){return"[Axios v"+Wl+"] Transitional option '"+s+"'"+i+(r?". "+r:"")}return(s,i,a)=>{if(t===!1)throw new Te(o(i," has been removed"+(n?" in "+n:"")),Te.ERR_DEPRECATED);return n&&!Vl[i]&&(Vl[i]=!0,console.warn(o(i," has been deprecated since v"+n+" and will be removed in the near future"))),t?t(s,i,a):!0}},jo.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function Xm(e,t,n){if(typeof e!="object")throw new Te("options must be an object",Te.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let o=r.length;for(;o-- >0;){const s=r[o],i=t[s];if(i){const a=e[s],l=a===void 0||i(a,s,e);if(l!==!0)throw new Te("option "+s+" must be "+l,Te.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new Te("Unknown option "+s,Te.ERR_BAD_OPTION)}}const _o={assertOptions:Xm,validators:jo},Qt=_o.validators;let Vn=class{constructor(t){this.defaults=t||{},this.interceptors={request:new Tl,response:new Tl}}async request(t,n){try{return await this._request(t,n)}catch(r){if(r instanceof Error){let o={};Error.captureStackTrace?Error.captureStackTrace(o):o=new Error;const s=o.stack?o.stack.replace(/^.+\n/,""):"";try{r.stack?s&&!String(r.stack).endsWith(s.replace(/^.+\n.+\n/,""))&&(r.stack+=`
6
- `+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Wn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&_o.assertOptions(r,{silentJSONParsing:Qt.transitional(Qt.boolean),forcedJSONParsing:Qt.transitional(Qt.boolean),clarifyTimeoutError:Qt.transitional(Qt.boolean)},!1),o!=null&&(U.isFunction(o)?n.paramsSerializer={serialize:o}:_o.assertOptions(o,{encode:Qt.function,serialize:Qt.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),_o.assertOptions(n,{baseUrl:Qt.spelling("baseURL"),withXsrfToken:Qt.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&U.merge(s.common,s[n.method]);s&&U.forEach(["delete","get","head","post","put","patch","common"],m=>{delete s[m]}),n.headers=Ct.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(b){typeof b.runWhen=="function"&&b.runWhen(n)===!1||(l=l&&b.synchronous,a.unshift(b.fulfilled,b.rejected))});const c=[];this.interceptors.response.forEach(function(b){c.push(b.fulfilled,b.rejected)});let u,f=0,h;if(!l){const m=[Hl.bind(this),void 0];for(m.unshift(...a),m.push(...c),h=m.length,u=Promise.resolve(n);f<h;)u=u.then(m[f++],m[f++]);return u}h=a.length;let p=n;for(;f<h;){const m=a[f++],b=a[f++];try{p=m(p)}catch(g){b.call(this,g);break}}try{u=Hl.call(this,p)}catch(m){return Promise.reject(m)}for(f=0,h=c.length;f<h;)u=u.then(c[f++],c[f++]);return u}getUri(t){t=Wn(this.defaults,t);const n=Pl(t.baseURL,t.url,t.allowAbsoluteUrls);return Cl(n,t.params,t.paramsSerializer)}};U.forEach(["delete","get","head","options"],function(t){Vn.prototype[t]=function(n,r){return this.request(Wn(r||{},{method:t,url:n,data:(r||{}).data}))}}),U.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(Wn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Vn.prototype[t]=n(),Vn.prototype[t+"Form"]=n(!0)});let Jm=class Np{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(s){n=s});const r=this;this.promise.then(o=>{if(!r._listeners)return;let s=r._listeners.length;for(;s-- >0;)r._listeners[s](o);r._listeners=null}),this.promise.then=o=>{let s;const i=new Promise(a=>{r.subscribe(a),s=a}).then(o);return i.cancel=function(){r.unsubscribe(s)},i},t(function(s,i,a){r.reason||(r.reason=new fr(s,i,a),n(r.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 n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new Np(function(o){t=o}),cancel:t}}};function Zm(e){return function(n){return e.apply(null,n)}}function Qm(e){return U.isObject(e)&&e.isAxiosError===!0}const ti={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(ti).forEach(([e,t])=>{ti[t]=e});function Kl(e){const t=new Vn(e),n=ll(Vn.prototype.request,t);return U.extend(n,Vn.prototype,t,{allOwnKeys:!0}),U.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Kl(Wn(e,o))},n}const Qe=Kl($r);Qe.Axios=Vn,Qe.CanceledError=fr,Qe.CancelToken=Jm,Qe.isCancel=Al,Qe.VERSION=Wl,Qe.toFormData=Eo,Qe.AxiosError=Te,Qe.Cancel=Qe.CanceledError,Qe.all=function(t){return Promise.all(t)},Qe.spread=Zm,Qe.isAxiosError=Qm,Qe.mergeConfig=Wn,Qe.AxiosHeaders=Ct,Qe.formToJSON=e=>El(U.isHTMLForm(e)?new FormData(e):e),Qe.getAdapter=Ul.getAdapter,Qe.HttpStatusCode=ti,Qe.default=Qe;const{Axios:tT,AxiosError:nT,CanceledError:rT,isCancel:ql,CancelToken:oT,VERSION:sT,all:iT,Cancel:aT,isAxiosError:lT,spread:cT,toFormData:uT,AxiosHeaders:dT,HttpStatusCode:fT,formToJSON:hT,getAdapter:pT,mergeConfig:mT}=Qe,Tn={authToken:"authToken",authTokenExpiresAt:"authTokenExpiresAt",authSessionId:"authSessionId",chatSettings:"chat-settings",threadManagerView:"thread-manager-view",playgroundSettings:"new-chat-ui-chat-settings",debugLogs:"app:debugLogs"};function Po(e){return`draft:${e}`}let Ro=null;const ni=new Set;function ri(){return Ro}function kn(e){Ro=e,ni.forEach(t=>t(e))}function oi(e){return ni.add(e),()=>ni.delete(e)}const Gl=3e4,Yl=9e4,mt=Qe.create({timeout:Gl,withCredentials:!0});mt.interceptors.request.use(e=>(Ro&&(e.headers.Authorization=`Bearer ${Ro}`),e)),mt.interceptors.response.use(e=>{if(typeof window<"u"&&(e!=null&&e.data))try{const t=e.data,n=t.data||{},r=typeof t.token=="string"&&t.token||typeof n.token=="string"&&n.token||null,o=typeof t.expires_at=="number"&&t.expires_at||typeof n.expires_at=="number"&&n.expires_at||typeof t.expiresAt=="number"&&t.expiresAt||typeof n.expiresAt=="number"&&n.expiresAt||null;r&&(localStorage.setItem(Tn.authToken,r),kn(r)),o&&localStorage.setItem(Tn.authTokenExpiresAt,o.toString()),(r||o)&&window.dispatchEvent(new CustomEvent("smartorg:chat-token-updated",{detail:{token:r,expiresAt:o}}))}catch(t){console.warn("[chat-api] Error storing token:",t)}return e},e=>Promise.reject(e));async function Tt(e,t){return mt.defaults.baseURL?(await mt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function zr(e,t,n){return mt.defaults.baseURL?(await mt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Xl(e,t,n){return mt.defaults.baseURL?(await mt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function si(e,t){return mt.defaults.baseURL?(await mt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function gt(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class Jl{get baseUrl(){return mt.defaults.baseURL||""}updateConfig(t){if(t.chatBaseUrl)mt.defaults.baseURL=t.chatBaseUrl;else if(t.baseUrl){const n=t.baseUrl.replace(/\/+$/,"");n.endsWith("/chat")?mt.defaults.baseURL=n:mt.defaults.baseURL=`${n}/chat`}t.apiKey!==void 0?kn(t.apiKey):t.getToken&&kn(t.getToken())}getAuthToken(){return ri()}setAuthToken(t){kn(t)}onTokenChange(t){return oi(t)}async listThreads(){const t=await Tt("/threads"),n=gt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async listSharedThreads(){const t=await Tt("/threads/shared"),n=gt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t,n){const r={};t&&(r.title=t),n&&(r.project=n);const o=await zr("/threads",Object.keys(r).length?r:void 0);return gt(o)}async updateThread(t,n){const r=await Xl(`/threads/${t}`,{title:n});return gt(r)}async deleteThread(t){const n=await si(`/threads/${t}`);return gt(n)}async shareThread(t,n){const r=await zr(`/threads/${t}/share`,{shared_with_user_id:n});return gt(r)}async threadInfo(t){const n=await Tt(`/threads/${t}/info`);return gt(n)}async listAgents(){const t=await Tt("/agents"),n=gt(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Tt(`/agents/${t}`);return gt(n)}async getAgentSchema(t){const n=await Tt(`/agents/${t}/schema`);return gt(n)}async getState(t){const n=await Tt(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return gt(n)}async getStateHistory(t){const n=await Tt(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:Yl,signal:t.signal});return gt(n)}async cancelRun(t){const n=await zr("/stream/cancel",{threadId:t});return gt(n)}async unshareThread(t,n){const r=await si(`/threads/${t}/share/${n}`);return gt(r)}}const En=new Jl;class Zl{async fetchFileBlob(t,n){return await Tt(t,{responseType:"blob",onDownloadProgress:o=>{try{if(n&&o.lengthComputable){const s=o.loaded/o.total;n(s)}}catch{}},maxBodyLength:1/0})}async viewFileById(t,n){const r=await this.fetchFileBlob(`/files/${t}/view`,n),o=URL.createObjectURL(r);window.open(o,"_blank"),setTimeout(()=>URL.revokeObjectURL(o),6e4)}async getFileBlob(t,n){return await this.fetchFileBlob(`/files/${t}/view`,n)}async getFileContent(t,n){return await(await this.fetchFileBlob(`/files/${t}/view`,n)).text()}async downloadFileById(t,n){const r=await this.fetchFileBlob(`/files/${t}/download`,n),o=URL.createObjectURL(r);let s=`file_${t}`;try{const a=await Tt(`/files/${t}`);s=(a==null?void 0:a.filename)??s}catch{}const i=document.createElement("a");i.href=o,i.download=s,document.body.appendChild(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(o),6e4)}async getFileInfo(t){return await Tt(`/files/${t}`)}async listFiles(t,n=50,r=0){const o={limit:n,offset:r};return t&&(o.thread_id=t),await Tt("/files",{params:o})}async uploadFile(t,n,r){const o=new FormData;return o.append("file",t),n&&o.append("thread_id",n),await zr("/files/upload-form",o,{onUploadProgress:s=>{try{if(r&&s.lengthComputable){const i=s.loaded/s.total;r(i)}}catch{}}})}}const ii=new Zl;var ai={exports:{}},Br={};/**
5
+ `):" "+Bl(i[0]):"as no adapter specified";throw new Te("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:Qs};function ei(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new dr(null,e)}function Hl(e){return ei(e),e.headers=Ct.from(e.headers),e.data=Zs.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),Ul.getAdapter(e.adapter||Lr.adapter,e)(e).then(function(r){return ei(e),r.data=Zs.call(e,e.transformResponse,r),r.headers=Ct.from(r.headers),r},function(r){return Al(r)||(ei(e),r&&r.response&&(r.response.data=Zs.call(e,e.transformResponse,r.response),r.response.headers=Ct.from(r.response.headers))),Promise.reject(r)})}const Wl="1.12.2",jo={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{jo[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const Vl={};jo.transitional=function(t,n,r){function o(s,i){return"[Axios v"+Wl+"] Transitional option '"+s+"'"+i+(r?". "+r:"")}return(s,i,a)=>{if(t===!1)throw new Te(o(i," has been removed"+(n?" in "+n:"")),Te.ERR_DEPRECATED);return n&&!Vl[i]&&(Vl[i]=!0,console.warn(o(i," has been deprecated since v"+n+" and will be removed in the near future"))),t?t(s,i,a):!0}},jo.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function Xm(e,t,n){if(typeof e!="object")throw new Te("options must be an object",Te.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let o=r.length;for(;o-- >0;){const s=r[o],i=t[s];if(i){const a=e[s],l=a===void 0||i(a,s,e);if(l!==!0)throw new Te("option "+s+" must be "+l,Te.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new Te("Unknown option "+s,Te.ERR_BAD_OPTION)}}const _o={assertOptions:Xm,validators:jo},en=_o.validators;let Vn=class{constructor(t){this.defaults=t||{},this.interceptors={request:new Tl,response:new Tl}}async request(t,n){try{return await this._request(t,n)}catch(r){if(r instanceof Error){let o={};Error.captureStackTrace?Error.captureStackTrace(o):o=new Error;const s=o.stack?o.stack.replace(/^.+\n/,""):"";try{r.stack?s&&!String(r.stack).endsWith(s.replace(/^.+\n.+\n/,""))&&(r.stack+=`
6
+ `+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=Wn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&_o.assertOptions(r,{silentJSONParsing:en.transitional(en.boolean),forcedJSONParsing:en.transitional(en.boolean),clarifyTimeoutError:en.transitional(en.boolean)},!1),o!=null&&(B.isFunction(o)?n.paramsSerializer={serialize:o}:_o.assertOptions(o,{encode:en.function,serialize:en.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),_o.assertOptions(n,{baseUrl:en.spelling("baseURL"),withXsrfToken:en.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&B.merge(s.common,s[n.method]);s&&B.forEach(["delete","get","head","post","put","patch","common"],m=>{delete s[m]}),n.headers=Ct.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(b){typeof b.runWhen=="function"&&b.runWhen(n)===!1||(l=l&&b.synchronous,a.unshift(b.fulfilled,b.rejected))});const c=[];this.interceptors.response.forEach(function(b){c.push(b.fulfilled,b.rejected)});let u,f=0,h;if(!l){const m=[Hl.bind(this),void 0];for(m.unshift(...a),m.push(...c),h=m.length,u=Promise.resolve(n);f<h;)u=u.then(m[f++],m[f++]);return u}h=a.length;let p=n;for(;f<h;){const m=a[f++],b=a[f++];try{p=m(p)}catch(g){b.call(this,g);break}}try{u=Hl.call(this,p)}catch(m){return Promise.reject(m)}for(f=0,h=c.length;f<h;)u=u.then(c[f++],c[f++]);return u}getUri(t){t=Wn(this.defaults,t);const n=Pl(t.baseURL,t.url,t.allowAbsoluteUrls);return Cl(n,t.params,t.paramsSerializer)}};B.forEach(["delete","get","head","options"],function(t){Vn.prototype[t]=function(n,r){return this.request(Wn(r||{},{method:t,url:n,data:(r||{}).data}))}}),B.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(Wn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Vn.prototype[t]=n(),Vn.prototype[t+"Form"]=n(!0)});let Jm=class Np{constructor(t){if(typeof t!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(s){n=s});const r=this;this.promise.then(o=>{if(!r._listeners)return;let s=r._listeners.length;for(;s-- >0;)r._listeners[s](o);r._listeners=null}),this.promise.then=o=>{let s;const i=new Promise(a=>{r.subscribe(a),s=a}).then(o);return i.cancel=function(){r.unsubscribe(s)},i},t(function(s,i,a){r.reason||(r.reason=new dr(s,i,a),n(r.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 n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=r=>{t.abort(r)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new Np(function(o){t=o}),cancel:t}}};function Zm(e){return function(n){return e.apply(null,n)}}function Qm(e){return B.isObject(e)&&e.isAxiosError===!0}const ti={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(ti).forEach(([e,t])=>{ti[t]=e});function Kl(e){const t=new Vn(e),n=ll(Vn.prototype.request,t);return B.extend(n,Vn.prototype,t,{allOwnKeys:!0}),B.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Kl(Wn(e,o))},n}const et=Kl(Lr);et.Axios=Vn,et.CanceledError=dr,et.CancelToken=Jm,et.isCancel=Al,et.VERSION=Wl,et.toFormData=Eo,et.AxiosError=Te,et.Cancel=et.CanceledError,et.all=function(t){return Promise.all(t)},et.spread=Zm,et.isAxiosError=Qm,et.mergeConfig=Wn,et.AxiosHeaders=Ct,et.formToJSON=e=>El(B.isHTMLForm(e)?new FormData(e):e),et.getAdapter=Ul.getAdapter,et.HttpStatusCode=ti,et.default=et;const{Axios:tT,AxiosError:nT,CanceledError:rT,isCancel:ql,CancelToken:oT,VERSION:sT,all:iT,Cancel:aT,isAxiosError:lT,spread:cT,toFormData:uT,AxiosHeaders:dT,HttpStatusCode:fT,formToJSON:hT,getAdapter:pT,mergeConfig:mT}=et,Sn={authToken:"authToken",authTokenExpiresAt:"authTokenExpiresAt",authSessionId:"authSessionId",chatSettings:"chat-settings",threadManagerView:"thread-manager-view",playgroundSettings:"new-chat-ui-chat-settings",debugLogs:"app:debugLogs"};function Po(e){return`draft:${e}`}let Ro=null;const ni=new Set;function ri(){return Ro}function Cn(e){Ro=e,ni.forEach(t=>t(e))}function oi(e){return ni.add(e),()=>ni.delete(e)}const Gl=3e4,Yl=9e4,pt=et.create({timeout:Gl,withCredentials:!0});pt.interceptors.request.use(e=>(Ro&&(e.headers.Authorization=`Bearer ${Ro}`),e)),pt.interceptors.response.use(e=>{if(typeof window<"u"&&(e!=null&&e.data))try{const t=e.data,n=t.data||{},r=typeof t.token=="string"&&t.token||typeof n.token=="string"&&n.token||null,o=typeof t.expires_at=="number"&&t.expires_at||typeof n.expires_at=="number"&&n.expires_at||typeof t.expiresAt=="number"&&t.expiresAt||typeof n.expiresAt=="number"&&n.expiresAt||null;r&&(localStorage.setItem(Sn.authToken,r),Cn(r)),o&&localStorage.setItem(Sn.authTokenExpiresAt,o.toString()),(r||o)&&window.dispatchEvent(new CustomEvent("smartorg:chat-token-updated",{detail:{token:r,expiresAt:o}}))}catch(t){console.warn("[chat-api] Error storing token:",t)}return e},e=>Promise.reject(e));async function Tt(e,t){return pt.defaults.baseURL?(await pt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function Fr(e,t,n){return pt.defaults.baseURL?(await pt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Xl(e,t,n){return pt.defaults.baseURL?(await pt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function si(e,t){return pt.defaults.baseURL?(await pt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function mt(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class Jl{get baseUrl(){return pt.defaults.baseURL||""}updateConfig(t){if(t.chatBaseUrl)pt.defaults.baseURL=t.chatBaseUrl;else if(t.baseUrl){const n=t.baseUrl.replace(/\/+$/,"");n.endsWith("/chat")?pt.defaults.baseURL=n:pt.defaults.baseURL=`${n}/chat`}t.apiKey!==void 0?Cn(t.apiKey):t.getToken&&Cn(t.getToken())}getAuthToken(){return ri()}setAuthToken(t){Cn(t)}onTokenChange(t){return oi(t)}async listThreads(){const t=await Tt("/threads"),n=mt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async listSharedThreads(){const t=await Tt("/threads/shared"),n=mt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t,n){const r={};t&&(r.title=t),n&&(r.project=n);const o=await Fr("/threads",Object.keys(r).length?r:void 0);return mt(o)}async updateThread(t,n){const r=await Xl(`/threads/${t}`,{title:n});return mt(r)}async deleteThread(t){const n=await si(`/threads/${t}`);return mt(n)}async shareThread(t,n){const r=await Fr(`/threads/${t}/share`,{shared_with_user_id:n});return mt(r)}async threadInfo(t){const n=await Tt(`/threads/${t}/info`);return mt(n)}async listAgents(){const t=await Tt("/agents"),n=mt(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await Tt(`/agents/${t}`);return mt(n)}async getAgentSchema(t){const n=await Tt(`/agents/${t}/schema`);return mt(n)}async getState(t){const n=await Tt(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return mt(n)}async getStateHistory(t){const n=await Tt(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:Yl,signal:t.signal});return mt(n)}async cancelRun(t){const n=await Fr("/stream/cancel",{threadId:t});return mt(n)}async unshareThread(t,n){const r=await si(`/threads/${t}/share/${n}`);return mt(r)}}const Tn=new Jl;class Zl{async fetchFileBlob(t,n){return await Tt(t,{responseType:"blob",onDownloadProgress:o=>{try{if(n&&o.lengthComputable){const s=o.loaded/o.total;n(s)}}catch{}},maxBodyLength:1/0})}async viewFileById(t,n){const r=await this.fetchFileBlob(`/files/${t}/view`,n),o=URL.createObjectURL(r);window.open(o,"_blank"),setTimeout(()=>URL.revokeObjectURL(o),6e4)}async getFileBlob(t,n){return await this.fetchFileBlob(`/files/${t}/view`,n)}async getFileContent(t,n){return await(await this.fetchFileBlob(`/files/${t}/view`,n)).text()}async downloadFileById(t,n){const r=await this.fetchFileBlob(`/files/${t}/download`,n),o=URL.createObjectURL(r);let s=`file_${t}`;try{const a=await Tt(`/files/${t}`);s=(a==null?void 0:a.filename)??s}catch{}const i=document.createElement("a");i.href=o,i.download=s,document.body.appendChild(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(o),6e4)}async getFileInfo(t){return await Tt(`/files/${t}`)}async listFiles(t,n=50,r=0){const o={limit:n,offset:r};return t&&(o.thread_id=t),await Tt("/files",{params:o})}async uploadFile(t,n,r){const o=new FormData;return o.append("file",t),n&&o.append("thread_id",n),await Fr("/files/upload-form",o,{onUploadProgress:s=>{try{if(r&&s.lengthComputable){const i=s.loaded/s.total;r(i)}}catch{}}})}}const ii=new Zl;var ai={exports:{}},zr={};/**
7
7
  * @license React
8
8
  * react-jsx-runtime.production.min.js
9
9
  *
@@ -11,7 +11,7 @@
11
11
  *
12
12
  * This source code is licensed under the MIT license found in the
13
13
  * LICENSE file in the root directory of this source tree.
14
- */var Ql;function eg(){if(Ql)return Br;Ql=1;var e=v,t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,o=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function i(a,l,c){var u,f={},h=null,p=null;c!==void 0&&(h=""+c),l.key!==void 0&&(h=""+l.key),l.ref!==void 0&&(p=l.ref);for(u in l)r.call(l,u)&&!s.hasOwnProperty(u)&&(f[u]=l[u]);if(a&&a.defaultProps)for(u in l=a.defaultProps,l)f[u]===void 0&&(f[u]=l[u]);return{$$typeof:t,type:a,key:h,ref:p,props:f,_owner:o.current}}return Br.Fragment=n,Br.jsx=i,Br.jsxs=i,Br}var Ur={};/**
14
+ */var Ql;function eg(){if(Ql)return zr;Ql=1;var e=v,t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,o=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function i(a,l,c){var u,f={},h=null,p=null;c!==void 0&&(h=""+c),l.key!==void 0&&(h=""+l.key),l.ref!==void 0&&(p=l.ref);for(u in l)r.call(l,u)&&!s.hasOwnProperty(u)&&(f[u]=l[u]);if(a&&a.defaultProps)for(u in l=a.defaultProps,l)f[u]===void 0&&(f[u]=l[u]);return{$$typeof:t,type:a,key:h,ref:p,props:f,_owner:o.current}}return zr.Fragment=n,zr.jsx=i,zr.jsxs=i,zr}var Br={};/**
15
15
  * @license React
16
16
  * react-jsx-runtime.development.js
17
17
  *
@@ -19,26 +19,26 @@
19
19
  *
20
20
  * This source code is licensed under the MIT license found in the
21
21
  * LICENSE file in the root directory of this source tree.
22
- */var ec;function tg(){return ec||(ec=1,process.env.NODE_ENV!=="production"&&function(){var e=v,t=Symbol.for("react.element"),n=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),i=Symbol.for("react.provider"),a=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),c=Symbol.for("react.suspense"),u=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),p=Symbol.for("react.offscreen"),m=Symbol.iterator,b="@@iterator";function g(I){if(I===null||typeof I!="object")return null;var K=m&&I[m]||I[b];return typeof K=="function"?K:null}var w=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function y(I){{for(var K=arguments.length,oe=new Array(K>1?K-1:0),_=1;_<K;_++)oe[_-1]=arguments[_];k("error",I,oe)}}function k(I,K,oe){{var _=w.ReactDebugCurrentFrame,Z=_.getStackAddendum();Z!==""&&(K+="%s",oe=oe.concat([Z]));var ie=oe.map(function(se){return String(se)});ie.unshift("Warning: "+K),Function.prototype.apply.call(console[I],console,ie)}}var E=!1,S=!1,C=!1,T=!1,A=!1,N;N=Symbol.for("react.module.reference");function j(I){return!!(typeof I=="string"||typeof I=="function"||I===r||I===s||A||I===o||I===c||I===u||T||I===p||E||S||C||typeof I=="object"&&I!==null&&(I.$$typeof===h||I.$$typeof===f||I.$$typeof===i||I.$$typeof===a||I.$$typeof===l||I.$$typeof===N||I.getModuleId!==void 0))}function L(I,K,oe){var _=I.displayName;if(_)return _;var Z=K.displayName||K.name||"";return Z!==""?oe+"("+Z+")":oe}function B(I){return I.displayName||"Context"}function W(I){if(I==null)return null;if(typeof I.tag=="number"&&y("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof I=="function")return I.displayName||I.name||null;if(typeof I=="string")return I;switch(I){case r:return"Fragment";case n:return"Portal";case s:return"Profiler";case o:return"StrictMode";case c:return"Suspense";case u:return"SuspenseList"}if(typeof I=="object")switch(I.$$typeof){case a:var K=I;return B(K)+".Consumer";case i:var oe=I;return B(oe._context)+".Provider";case l:return L(I,I.render,"ForwardRef");case f:var _=I.displayName||null;return _!==null?_:W(I.type)||"Memo";case h:{var Z=I,ie=Z._payload,se=Z._init;try{return W(se(ie))}catch{return null}}}return null}var O=Object.assign,D=0,z,ee,H,V,Y,q,M;function P(){}P.__reactDisabledLog=!0;function $(){{if(D===0){z=console.log,ee=console.info,H=console.warn,V=console.error,Y=console.group,q=console.groupCollapsed,M=console.groupEnd;var I={configurable:!0,enumerable:!0,value:P,writable:!0};Object.defineProperties(console,{info:I,log:I,warn:I,error:I,group:I,groupCollapsed:I,groupEnd:I})}D++}}function R(){{if(D--,D===0){var I={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:O({},I,{value:z}),info:O({},I,{value:ee}),warn:O({},I,{value:H}),error:O({},I,{value:V}),group:O({},I,{value:Y}),groupCollapsed:O({},I,{value:q}),groupEnd:O({},I,{value:M})})}D<0&&y("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var G=w.ReactCurrentDispatcher,te;function F(I,K,oe){{if(te===void 0)try{throw Error()}catch(Z){var _=Z.stack.trim().match(/\n( *(at )?)/);te=_&&_[1]||""}return`
23
- `+te+I}}var X=!1,re;{var ue=typeof WeakMap=="function"?WeakMap:Map;re=new ue}function le(I,K){if(!I||X)return"";{var oe=re.get(I);if(oe!==void 0)return oe}var _;X=!0;var Z=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var ie;ie=G.current,G.current=null,$();try{if(K){var se=function(){throw Error()};if(Object.defineProperty(se.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(se,[])}catch(Le){_=Le}Reflect.construct(I,[],se)}else{try{se.call()}catch(Le){_=Le}I.call(se.prototype)}}else{try{throw Error()}catch(Le){_=Le}I()}}catch(Le){if(Le&&_&&typeof Le.stack=="string"){for(var xe=Le.stack.split(`
24
- `),De=_.stack.split(`
25
- `),Ne=xe.length-1,Ce=De.length-1;Ne>=1&&Ce>=0&&xe[Ne]!==De[Ce];)Ce--;for(;Ne>=1&&Ce>=0;Ne--,Ce--)if(xe[Ne]!==De[Ce]){if(Ne!==1||Ce!==1)do if(Ne--,Ce--,Ce<0||xe[Ne]!==De[Ce]){var ge=`
26
- `+xe[Ne].replace(" at new "," at ");return I.displayName&&ge.includes("<anonymous>")&&(ge=ge.replace("<anonymous>",I.displayName)),typeof I=="function"&&re.set(I,ge),ge}while(Ne>=1&&Ce>=0);break}}}finally{X=!1,G.current=ie,R(),Error.prepareStackTrace=Z}var $e=I?I.displayName||I.name:"",Pe=$e?F($e):"";return typeof I=="function"&&re.set(I,Pe),Pe}function Se(I,K,oe){return le(I,!1)}function Me(I){var K=I.prototype;return!!(K&&K.isReactComponent)}function Ie(I,K,oe){if(I==null)return"";if(typeof I=="function")return le(I,Me(I));if(typeof I=="string")return F(I);switch(I){case c:return F("Suspense");case u:return F("SuspenseList")}if(typeof I=="object")switch(I.$$typeof){case l:return Se(I.render);case f:return Ie(I.type,K,oe);case h:{var _=I,Z=_._payload,ie=_._init;try{return Ie(ie(Z),K,oe)}catch{}}}return""}var Ke=Object.prototype.hasOwnProperty,He={},Fe=w.ReactDebugCurrentFrame;function ze(I){if(I){var K=I._owner,oe=Ie(I.type,I._source,K?K.type:null);Fe.setExtraStackFrame(oe)}else Fe.setExtraStackFrame(null)}function It(I,K,oe,_,Z){{var ie=Function.call.bind(Ke);for(var se in I)if(ie(I,se)){var xe=void 0;try{if(typeof I[se]!="function"){var De=Error((_||"React class")+": "+oe+" type `"+se+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof I[se]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw De.name="Invariant Violation",De}xe=I[se](K,se,_,oe,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(Ne){xe=Ne}xe&&!(xe instanceof Error)&&(ze(Z),y("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",_||"React class",oe,se,typeof xe),ze(null)),xe instanceof Error&&!(xe.message in He)&&(He[xe.message]=!0,ze(Z),y("Failed %s type: %s",oe,xe.message),ze(null))}}}var At=Array.isArray;function wt(I){return At(I)}function yt(I){{var K=typeof Symbol=="function"&&Symbol.toStringTag,oe=K&&I[Symbol.toStringTag]||I.constructor.name||"Object";return oe}}function ht(I){try{return st(I),!1}catch{return!0}}function st(I){return""+I}function Nt(I){if(ht(I))return y("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",yt(I)),st(I)}var jt=w.ReactCurrentOwner,rt={key:!0,ref:!0,__self:!0,__source:!0},tt,it;function _t(I){if(Ke.call(I,"ref")){var K=Object.getOwnPropertyDescriptor(I,"ref").get;if(K&&K.isReactWarning)return!1}return I.ref!==void 0}function Ae(I){if(Ke.call(I,"key")){var K=Object.getOwnPropertyDescriptor(I,"key").get;if(K&&K.isReactWarning)return!1}return I.key!==void 0}function Ye(I,K){typeof I.ref=="string"&&jt.current}function Or(I,K){{var oe=function(){tt||(tt=!0,y("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",K))};oe.isReactWarning=!0,Object.defineProperty(I,"key",{get:oe,configurable:!0})}}function $t(I,K){{var oe=function(){it||(it=!0,y("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",K))};oe.isReactWarning=!0,Object.defineProperty(I,"ref",{get:oe,configurable:!0})}}var bn=function(I,K,oe,_,Z,ie,se){var xe={$$typeof:t,type:I,key:K,ref:oe,props:se,_owner:ie};return xe._store={},Object.defineProperty(xe._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(xe,"_self",{configurable:!1,enumerable:!1,writable:!1,value:_}),Object.defineProperty(xe,"_source",{configurable:!1,enumerable:!1,writable:!1,value:Z}),Object.freeze&&(Object.freeze(xe.props),Object.freeze(xe)),xe};function Vt(I,K,oe,_,Z){{var ie,se={},xe=null,De=null;oe!==void 0&&(Nt(oe),xe=""+oe),Ae(K)&&(Nt(K.key),xe=""+K.key),_t(K)&&(De=K.ref,Ye(K,Z));for(ie in K)Ke.call(K,ie)&&!rt.hasOwnProperty(ie)&&(se[ie]=K[ie]);if(I&&I.defaultProps){var Ne=I.defaultProps;for(ie in Ne)se[ie]===void 0&&(se[ie]=Ne[ie])}if(xe||De){var Ce=typeof I=="function"?I.displayName||I.name||"Unknown":I;xe&&Or(se,Ce),De&&$t(se,Ce)}return bn(I,xe,De,Z,_,jt.current,se)}}var Ft=w.ReactCurrentOwner,wn=w.ReactDebugCurrentFrame;function pt(I){if(I){var K=I._owner,oe=Ie(I.type,I._source,K?K.type:null);wn.setExtraStackFrame(oe)}else wn.setExtraStackFrame(null)}var yn;yn=!1;function dn(I){return typeof I=="object"&&I!==null&&I.$$typeof===t}function vn(){{if(Ft.current){var I=W(Ft.current.type);if(I)return`
22
+ */var ec;function tg(){return ec||(ec=1,process.env.NODE_ENV!=="production"&&function(){var e=v,t=Symbol.for("react.element"),n=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),i=Symbol.for("react.provider"),a=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),c=Symbol.for("react.suspense"),u=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),p=Symbol.for("react.offscreen"),m=Symbol.iterator,b="@@iterator";function g(I){if(I===null||typeof I!="object")return null;var ee=m&&I[m]||I[b];return typeof ee=="function"?ee:null}var w=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function y(I){{for(var ee=arguments.length,Q=new Array(ee>1?ee-1:0),L=1;L<ee;L++)Q[L-1]=arguments[L];k("error",I,Q)}}function k(I,ee,Q){{var L=w.ReactDebugCurrentFrame,K=L.getStackAddendum();K!==""&&(ee+="%s",Q=Q.concat([K]));var se=Q.map(function(ie){return String(ie)});se.unshift("Warning: "+ee),Function.prototype.apply.call(console[I],console,se)}}var E=!1,S=!1,C=!1,T=!1,N=!1,j;j=Symbol.for("react.module.reference");function _(I){return!!(typeof I=="string"||typeof I=="function"||I===r||I===s||N||I===o||I===c||I===u||T||I===p||E||S||C||typeof I=="object"&&I!==null&&(I.$$typeof===h||I.$$typeof===f||I.$$typeof===i||I.$$typeof===a||I.$$typeof===l||I.$$typeof===j||I.getModuleId!==void 0))}function D(I,ee,Q){var L=I.displayName;if(L)return L;var K=ee.displayName||ee.name||"";return K!==""?Q+"("+K+")":Q}function z(I){return I.displayName||"Context"}function H(I){if(I==null)return null;if(typeof I.tag=="number"&&y("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof I=="function")return I.displayName||I.name||null;if(typeof I=="string")return I;switch(I){case r:return"Fragment";case n:return"Portal";case s:return"Profiler";case o:return"StrictMode";case c:return"Suspense";case u:return"SuspenseList"}if(typeof I=="object")switch(I.$$typeof){case a:var ee=I;return z(ee)+".Consumer";case i:var Q=I;return z(Q._context)+".Provider";case l:return D(I,I.render,"ForwardRef");case f:var L=I.displayName||null;return L!==null?L:H(I.type)||"Memo";case h:{var K=I,se=K._payload,ie=K._init;try{return H(ie(se))}catch{return null}}}return null}var P=Object.assign,M=0,F,ne,U,W,Y,q,R;function G(){}G.__reactDisabledLog=!0;function A(){{if(M===0){F=console.log,ne=console.info,U=console.warn,W=console.error,Y=console.group,q=console.groupCollapsed,R=console.groupEnd;var I={configurable:!0,enumerable:!0,value:G,writable:!0};Object.defineProperties(console,{info:I,log:I,warn:I,error:I,group:I,groupCollapsed:I,groupEnd:I})}M++}}function O(){{if(M--,M===0){var I={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:P({},I,{value:F}),info:P({},I,{value:ne}),warn:P({},I,{value:U}),error:P({},I,{value:W}),group:P({},I,{value:Y}),groupCollapsed:P({},I,{value:q}),groupEnd:P({},I,{value:R})})}M<0&&y("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var V=w.ReactCurrentDispatcher,Z;function $(I,ee,Q){{if(Z===void 0)try{throw Error()}catch(K){var L=K.stack.trim().match(/\n( *(at )?)/);Z=L&&L[1]||""}return`
23
+ `+Z+I}}var X=!1,oe;{var ue=typeof WeakMap=="function"?WeakMap:Map;oe=new ue}function le(I,ee){if(!I||X)return"";{var Q=oe.get(I);if(Q!==void 0)return Q}var L;X=!0;var K=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var se;se=V.current,V.current=null,A();try{if(ee){var ie=function(){throw Error()};if(Object.defineProperty(ie.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(ie,[])}catch($e){L=$e}Reflect.construct(I,[],ie)}else{try{ie.call()}catch($e){L=$e}I.call(ie.prototype)}}else{try{throw Error()}catch($e){L=$e}I()}}catch($e){if($e&&L&&typeof $e.stack=="string"){for(var fe=$e.stack.split(`
24
+ `),je=L.stack.split(`
25
+ `),_e=fe.length-1,ve=je.length-1;_e>=1&&ve>=0&&fe[_e]!==je[ve];)ve--;for(;_e>=1&&ve>=0;_e--,ve--)if(fe[_e]!==je[ve]){if(_e!==1||ve!==1)do if(_e--,ve--,ve<0||fe[_e]!==je[ve]){var me=`
26
+ `+fe[_e].replace(" at new "," at ");return I.displayName&&me.includes("<anonymous>")&&(me=me.replace("<anonymous>",I.displayName)),typeof I=="function"&&oe.set(I,me),me}while(_e>=1&&ve>=0);break}}}finally{X=!1,V.current=se,O(),Error.prepareStackTrace=K}var Oe=I?I.displayName||I.name:"",Pe=Oe?$(Oe):"";return typeof I=="function"&&oe.set(I,Pe),Pe}function Ce(I,ee,Q){return le(I,!1)}function De(I){var ee=I.prototype;return!!(ee&&ee.isReactComponent)}function Ie(I,ee,Q){if(I==null)return"";if(typeof I=="function")return le(I,De(I));if(typeof I=="string")return $(I);switch(I){case c:return $("Suspense");case u:return $("SuspenseList")}if(typeof I=="object")switch(I.$$typeof){case l:return Ce(I.render);case f:return Ie(I.type,ee,Q);case h:{var L=I,K=L._payload,se=L._init;try{return Ie(se(K),ee,Q)}catch{}}}return""}var qe=Object.prototype.hasOwnProperty,We={},Fe=w.ReactDebugCurrentFrame;function ze(I){if(I){var ee=I._owner,Q=Ie(I.type,I._source,ee?ee.type:null);Fe.setExtraStackFrame(Q)}else Fe.setExtraStackFrame(null)}function It(I,ee,Q,L,K){{var se=Function.call.bind(qe);for(var ie in I)if(se(I,ie)){var fe=void 0;try{if(typeof I[ie]!="function"){var je=Error((L||"React class")+": "+Q+" type `"+ie+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof I[ie]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw je.name="Invariant Violation",je}fe=I[ie](ee,ie,L,Q,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(_e){fe=_e}fe&&!(fe instanceof Error)&&(ze(K),y("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",L||"React class",Q,ie,typeof fe),ze(null)),fe instanceof Error&&!(fe.message in We)&&(We[fe.message]=!0,ze(K),y("Failed %s type: %s",Q,fe.message),ze(null))}}}var At=Array.isArray;function bt(I){return At(I)}function wt(I){{var ee=typeof Symbol=="function"&&Symbol.toStringTag,Q=ee&&I[Symbol.toStringTag]||I.constructor.name||"Object";return Q}}function ht(I){try{return st(I),!1}catch{return!0}}function st(I){return""+I}function Nt(I){if(ht(I))return y("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",wt(I)),st(I)}var jt=w.ReactCurrentOwner,Ut={key:!0,ref:!0,__self:!0,__source:!0},nt,Ze;function yt(I){if(qe.call(I,"ref")){var ee=Object.getOwnPropertyDescriptor(I,"ref").get;if(ee&&ee.isReactWarning)return!1}return I.ref!==void 0}function Be(I){if(qe.call(I,"key")){var ee=Object.getOwnPropertyDescriptor(I,"key").get;if(ee&&ee.isReactWarning)return!1}return I.key!==void 0}function Le(I,ee){typeof I.ref=="string"&&jt.current}function Ht(I,ee){{var Q=function(){nt||(nt=!0,y("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",ee))};Q.isReactWarning=!0,Object.defineProperty(I,"key",{get:Q,configurable:!0})}}function or(I,ee){{var Q=function(){Ze||(Ze=!0,y("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",ee))};Q.isReactWarning=!0,Object.defineProperty(I,"ref",{get:Q,configurable:!0})}}var Wt=function(I,ee,Q,L,K,se,ie){var fe={$$typeof:t,type:I,key:ee,ref:Q,props:ie,_owner:se};return fe._store={},Object.defineProperty(fe._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(fe,"_self",{configurable:!1,enumerable:!1,writable:!1,value:L}),Object.defineProperty(fe,"_source",{configurable:!1,enumerable:!1,writable:!1,value:K}),Object.freeze&&(Object.freeze(fe.props),Object.freeze(fe)),fe};function fn(I,ee,Q,L,K){{var se,ie={},fe=null,je=null;Q!==void 0&&(Nt(Q),fe=""+Q),Be(ee)&&(Nt(ee.key),fe=""+ee.key),yt(ee)&&(je=ee.ref,Le(ee,K));for(se in ee)qe.call(ee,se)&&!Ut.hasOwnProperty(se)&&(ie[se]=ee[se]);if(I&&I.defaultProps){var _e=I.defaultProps;for(se in _e)ie[se]===void 0&&(ie[se]=_e[se])}if(fe||je){var ve=typeof I=="function"?I.displayName||I.name||"Unknown":I;fe&&Ht(ie,ve),je&&or(ie,ve)}return Wt(I,fe,je,K,L,jt.current,ie)}}var Vt=w.ReactCurrentOwner,Lt=w.ReactDebugCurrentFrame;function it(I){if(I){var ee=I._owner,Q=Ie(I.type,I._source,ee?ee.type:null);Lt.setExtraStackFrame(Q)}else Lt.setExtraStackFrame(null)}var $n;$n=!1;function Qt(I){return typeof I=="object"&&I!==null&&I.$$typeof===t}function wn(){{if(Vt.current){var I=H(Vt.current.type);if(I)return`
27
27
 
28
- Check the render method of \``+I+"`."}return""}}function Xe(I){return""}var Ze={};function Sn(I){{var K=vn();if(!K){var oe=typeof I=="string"?I:I.displayName||I.name;oe&&(K=`
28
+ Check the render method of \``+I+"`."}return""}}function vo(I){return""}var Ge={};function Qe(I){{var ee=wn();if(!ee){var Q=typeof I=="string"?I:I.displayName||I.name;Q&&(ee=`
29
29
 
30
- Check the top-level render call using <`+oe+">.")}return K}}function fn(I,K){{if(!I._store||I._store.validated||I.key!=null)return;I._store.validated=!0;var oe=Sn(K);if(Ze[oe])return;Ze[oe]=!0;var _="";I&&I._owner&&I._owner!==Ft.current&&(_=" It was passed a child from "+W(I._owner.type)+"."),pt(I),y('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',oe,_),pt(null)}}function hn(I,K){{if(typeof I!="object")return;if(wt(I))for(var oe=0;oe<I.length;oe++){var _=I[oe];dn(_)&&fn(_,K)}else if(dn(I))I._store&&(I._store.validated=!0);else if(I){var Z=g(I);if(typeof Z=="function"&&Z!==I.entries)for(var ie=Z.call(I),se;!(se=ie.next()).done;)dn(se.value)&&fn(se.value,K)}}}function zn(I){{var K=I.type;if(K==null||typeof K=="string")return;var oe;if(typeof K=="function")oe=K.propTypes;else if(typeof K=="object"&&(K.$$typeof===l||K.$$typeof===f))oe=K.propTypes;else return;if(oe){var _=W(K);It(oe,I.props,"prop",_,I)}else if(K.PropTypes!==void 0&&!yn){yn=!0;var Z=W(K);y("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",Z||"Unknown")}typeof K.getDefaultProps=="function"&&!K.getDefaultProps.isReactClassApproved&&y("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Bn(I){{for(var K=Object.keys(I.props),oe=0;oe<K.length;oe++){var _=K[oe];if(_!=="children"&&_!=="key"){pt(I),y("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",_),pt(null);break}}I.ref!==null&&(pt(I),y("Invalid attribute `ref` supplied to `React.Fragment`."),pt(null))}}var or={};function sr(I,K,oe,_,Z,ie){{var se=j(I);if(!se){var xe="";(I===void 0||typeof I=="object"&&I!==null&&Object.keys(I).length===0)&&(xe+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var De=Xe();De?xe+=De:xe+=vn();var Ne;I===null?Ne="null":wt(I)?Ne="array":I!==void 0&&I.$$typeof===t?(Ne="<"+(W(I.type)||"Unknown")+" />",xe=" Did you accidentally export a JSX literal instead of a component?"):Ne=typeof I,y("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",Ne,xe)}var Ce=Vt(I,K,oe,Z,ie);if(Ce==null)return Ce;if(se){var ge=K.children;if(ge!==void 0)if(_)if(wt(ge)){for(var $e=0;$e<ge.length;$e++)hn(ge[$e],I);Object.freeze&&Object.freeze(ge)}else y("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else hn(ge,I)}if(Ke.call(K,"key")){var Pe=W(I),Le=Object.keys(K).filter(function(lr){return lr!=="key"}),at=Le.length>0?"{key: someKey, "+Le.join(": ..., ")+": ...}":"{key: someKey}";if(!or[Pe+at]){var pn=Le.length>0?"{"+Le.join(": ..., ")+": ...}":"{}";y(`A props object containing a "key" prop is being spread into JSX:
30
+ Check the top-level render call using <`+Q+">.")}return ee}}function hn(I,ee){{if(!I._store||I._store.validated||I.key!=null)return;I._store.validated=!0;var Q=Qe(ee);if(Ge[Q])return;Ge[Q]=!0;var L="";I&&I._owner&&I._owner!==Vt.current&&(L=" It was passed a child from "+H(I._owner.type)+"."),it(I),y('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',Q,L),it(null)}}function pn(I,ee){{if(typeof I!="object")return;if(bt(I))for(var Q=0;Q<I.length;Q++){var L=I[Q];Qt(L)&&hn(L,ee)}else if(Qt(I))I._store&&(I._store.validated=!0);else if(I){var K=g(I);if(typeof K=="function"&&K!==I.entries)for(var se=K.call(I),ie;!(ie=se.next()).done;)Qt(ie.value)&&hn(ie.value,ee)}}}function Fn(I){{var ee=I.type;if(ee==null||typeof ee=="string")return;var Q;if(typeof ee=="function")Q=ee.propTypes;else if(typeof ee=="object"&&(ee.$$typeof===l||ee.$$typeof===f))Q=ee.propTypes;else return;if(Q){var L=H(ee);It(Q,I.props,"prop",L,I)}else if(ee.PropTypes!==void 0&&!$n){$n=!0;var K=H(ee);y("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",K||"Unknown")}typeof ee.getDefaultProps=="function"&&!ee.getDefaultProps.isReactClassApproved&&y("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function yn(I){{for(var ee=Object.keys(I.props),Q=0;Q<ee.length;Q++){var L=ee[Q];if(L!=="children"&&L!=="key"){it(I),y("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",L),it(null);break}}I.ref!==null&&(it(I),y("Invalid attribute `ref` supplied to `React.Fragment`."),it(null))}}var vn={};function sr(I,ee,Q,L,K,se){{var ie=_(I);if(!ie){var fe="";(I===void 0||typeof I=="object"&&I!==null&&Object.keys(I).length===0)&&(fe+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var je=vo();je?fe+=je:fe+=wn();var _e;I===null?_e="null":bt(I)?_e="array":I!==void 0&&I.$$typeof===t?(_e="<"+(H(I.type)||"Unknown")+" />",fe=" Did you accidentally export a JSX literal instead of a component?"):_e=typeof I,y("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",_e,fe)}var ve=fn(I,ee,Q,K,se);if(ve==null)return ve;if(ie){var me=ee.children;if(me!==void 0)if(L)if(bt(me)){for(var Oe=0;Oe<me.length;Oe++)pn(me[Oe],I);Object.freeze&&Object.freeze(me)}else y("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else pn(me,I)}if(qe.call(ee,"key")){var Pe=H(I),$e=Object.keys(ee).filter(function(ar){return ar!=="key"}),at=$e.length>0?"{key: someKey, "+$e.join(": ..., ")+": ...}":"{key: someKey}";if(!vn[Pe+at]){var mn=$e.length>0?"{"+$e.join(": ..., ")+": ...}":"{}";y(`A props object containing a "key" prop is being spread into JSX:
31
31
  let props = %s;
32
32
  <%s {...props} />
33
33
  React keys must be passed directly to JSX without using spread:
34
34
  let props = %s;
35
- <%s key={someKey} {...props} />`,at,Pe,pn,Pe),or[Pe+at]=!0}}return I===r?Bn(Ce):zn(Ce),Ce}}function ir(I,K,oe){return sr(I,K,oe,!0)}function Cn(I,K,oe){return sr(I,K,oe,!1)}var ar=Cn,zt=ir;Ur.Fragment=r,Ur.jsx=ar,Ur.jsxs=zt}()),Ur}process.env.NODE_ENV==="production"?ai.exports=eg():ai.exports=tg();var d=ai.exports;class ng{constructor(){sl(this,"_authBaseUrl","")}get baseUrl(){return this._authBaseUrl}updateConfig(t){if(t.authBaseUrl)this._authBaseUrl=t.authBaseUrl;else if(t.baseUrl){const n=t.baseUrl.replace(/\/+$/,"");this._authBaseUrl=`${n}/auth`}t.apiKey!==void 0?kn(t.apiKey):t.getToken&&kn(t.getToken())}getAuthToken(){return ri()}setAuthToken(t){kn(t)}onTokenChange(t){return oi(t)}async listUsers(){const t=await Tt("/users",{baseURL:this.baseUrl});return(t==null?void 0:t.users)??[]}}const rg=new ng,tc=v.createContext(null);function nc({children:e,apiConfig:t}){const n=En,r=rg;if(t){const s=n.baseUrl,i=r.baseUrl,a=n.getAuthToken();(t.baseUrl||t.chatBaseUrl)&&(t.chatBaseUrl&&t.chatBaseUrl!==s||t.baseUrl&&!s.startsWith(t.baseUrl))&&n.updateConfig(t),(t.baseUrl||t.authBaseUrl)&&(t.authBaseUrl&&t.authBaseUrl!==i||t.baseUrl&&!i.startsWith(t.baseUrl))&&r.updateConfig(t),t.apiKey!==void 0&&t.apiKey!==a&&(n.updateConfig({apiKey:t.apiKey}),r.updateConfig({apiKey:t.apiKey}))}const o={token:n.getAuthToken(),setToken:s=>{n.setAuthToken(s),r.setAuthToken(s)},chatApi:n,authApi:r,fileApi:ii,baseUrl:n.baseUrl};return d.jsx(tc.Provider,{value:o,children:e})}function hr(){const e=v.useContext(tc);if(!e)throw new Error("useApi must be used within ApiProvider");return e}const og=["detail","message","error","description","title"];function Oo(e){if(!e)return null;if(typeof e=="string"){const t=e.trim();return t.length?t:null}if(Array.isArray(e)){for(const t of e){const n=Oo(t);if(n)return n}return null}if(typeof e=="object"){const t=e;for(const n of og){const r=Oo(t[n]);if(r)return r}if("errors"in t){const n=Oo(t.errors);if(n)return n}}return null}function sg(e){if(!e)return"Request failed";const t=e.response,n=Oo(t==null?void 0:t.data);if(n)return n;if(t!=null&&t.statusText)return t.statusText;if(e instanceof Error&&e.message)return e.message;if(typeof e=="string"){const r=e.trim();if(r.length)return r}return t!=null&&t.status?`Request failed with status code ${t.status}`:"Request failed"}function rc({api:e,initialThreadId:t=null,onError:n,onThreadChange:r,onCurrentThreadDeleted:o}){const[s,i]=v.useState([]),[a,l]=v.useState(t),[c,u]=v.useState(!1),[f,h]=v.useState(null),[p,m]=v.useState([]),[b,g]=v.useState(!1),[,w]=v.useState(null),[y,k]=v.useState(null),[E,S]=v.useState(!1),C=v.useRef(a),T=v.useRef(new Map);v.useEffect(()=>{C.current=a},[a]),v.useEffect(()=>{t!==void 0&&t!==C.current&&l(t)},[t]);const A=v.useCallback(async()=>{u(!0),h(null);try{const H=await e.listThreads();i(H??[])}catch(H){const V=String(H);h(V),n==null||n(V)}finally{u(!1)}},[e,n]),N=v.useCallback(async()=>{g(!0),w(null);try{const H=await e.listSharedThreads();m(H??[])}catch(H){const V=String(H);w(V),n==null||n(V)}finally{g(!1)}},[e,n]);v.useEffect(()=>{A()},[A]),v.useEffect(()=>{N()},[N]),v.useEffect(()=>{r==null||r(a)},[a,r]);const j=v.useCallback(async(H,V)=>{try{const Y=V&&typeof V=="object"?{id:V.id,name:V.name??""}:void 0,q=await e.createThread(H,Y);return l(q.threadId),await A(),q.threadId}catch(Y){const q=String(Y);return n==null||n(q),null}},[e,n,A]),L=v.useCallback(async H=>{const V=s;i(q=>q.filter(M=>M.threadId!==H));const Y=new AbortController;T.current.set(H,Y);try{await e.deleteThread(H),C.current===H&&(l(null),o==null||o())}catch(q){i(V);const M=String(q);n==null||n(M)}finally{T.current.delete(H)}},[e,o,n,s]),B=v.useCallback(async(H,V)=>{try{await e.updateThread(H,V),await A()}catch(Y){n==null||n(String(Y))}},[e,n,A]),W=v.useCallback(async(H,V)=>{S(!0),k("Sharing thread…");try{await e.shareThread(H,V),await N(),k("Shared successfully")}catch(Y){const q=sg(Y);throw n==null||n(q),k(`Failed to share: ${q}`),new Error(q)}finally{S(!1)}},[e,n,N]),O=v.useCallback(async(H,V)=>{try{await e.unshareThread(H,V),await N()}catch(Y){const q=String(Y);throw n==null||n(q),Y}},[e,n,N]),D=v.useMemo(()=>({createThread:j,deleteThread:L,renameThread:B,refreshThreads:A,refreshSharedThreads:N,shareThread:W,unshareThread:O}),[j,L,B,A,N,W,O]),z=v.useCallback(H=>{if(!(H!=null&&H.threadId))return;const V={threadId:H.threadId,title:H.title||`Thread ${H.threadId.slice(0,8)}`,project:H.project,createdAt:H.createdAt||new Date().toISOString(),updatedAt:H.updatedAt||new Date().toISOString(),messageCount:H.messageCount??1};i(Y=>{let q=!1;const M=Y.map(P=>P.threadId===V.threadId?(q=!0,console.debug("[useThreadsState] thread_info: updating existing thread",V.threadId),{...P,title:V.title??P.title,project:V.project??P.project,updatedAt:V.updatedAt??P.updatedAt,messageCount:V.messageCount??P.messageCount}):P);return q?M:(console.debug("[useThreadsState] thread_info: adding thread to list",V.threadId),[V,...Y])})},[]),ee=v.useCallback(()=>k(null),[]);return{threads:s,currentThreadId:a,currentThreadIdRef:C,setCurrentThreadId:l,isLoadingThreads:c,threadsError:f,sharedThreads:p,isLoadingSharedThreads:b,actions:D,addThreadFromEvent:z,shareInFlight:E,shareStatus:y,clearShareStatus:ee}}const oc=v.createContext(null);function sc({children:e,initialThreadId:t=null,onError:n,onThreadChange:r}){const{chatApi:o}=hr(),{threads:s,currentThreadId:i,setCurrentThreadId:a,currentThreadIdRef:l,isLoadingThreads:c,threadsError:u,sharedThreads:f,isLoadingSharedThreads:h,actions:p,addThreadFromEvent:m,shareInFlight:b,shareStatus:g,clearShareStatus:w}=rc({api:o,initialThreadId:t,onError:n,onThreadChange:r}),y=v.useMemo(()=>({threads:s,currentThreadId:i,setCurrentThreadId:a,currentThreadIdRef:l,isLoading:c,error:u,sharedThreads:f,isLoadingSharedThreads:h,actions:p,shareInFlight:b,shareStatus:g,clearShareStatus:w,addThreadFromEvent:m}),[s,i,a,l,c,u,f,h,p,b,g,w,m]);return d.jsx(oc.Provider,{value:y,children:e})}function Hr(){const e=v.useContext(oc);if(!e)throw new Error("useThreads must be used within a ThreadsProvider");return e}function Kn(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function Wr(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r.trim()}}function ig(e,t){if(!e)return null;for(const n of t){const r=e[n];if(typeof r=="number"&&Number.isFinite(r))return r}return null}function ic(e){const t=Kn(e);if(t)return Kn(t.configurable)??t}function ag(e){let t=!1,n="";for(const o of e){if(o==="\\"){n+=o,t=!t;continue}if(o==="'"&&!t){n+='"';continue}n+=o,t=!1}return n.replace(/\bTrue\b/g,"true").replace(/\bFalse\b/g,"false").replace(/\bNone\b/g,"null")}function pr(e){const t=e==null?void 0:e.trim();if(!t||!(t.startsWith("{")||t.startsWith("[")))return null;try{return JSON.parse(t)}catch{const n=ag(t);if(n)try{return JSON.parse(n)}catch{return null}return null}}function ac(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function lg(e){return e.replace(/[_-](\w)/g,(t,n)=>n?n.toUpperCase():"").replace(/^\w/,t=>t.toLowerCase())}function In(e){return!e||typeof e!="object"?e:Array.isArray(e)?e.map(In):Object.fromEntries(Object.entries(e).map(([t,n])=>[lg(t),In(n)]))}function Mo(e){var g,w,y,k,E,S;if(!e||typeof e!="object")return null;const t=In(e),n=dg(t);if(!n)return null;const r=Array.isArray(t.toolCalls)?t.toolCalls.map(lc):void 0,o=ug(t.content??t.parts,!!(r!=null&&r.length)),s=t.id??`msg-${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`,i=t.createdAt??((g=t.additionalKwargs)==null?void 0:g.createdAt)??new Date().toISOString(),a=((w=t.additionalKwargs)==null?void 0:w.agent_name)??((y=t.additionalKwargs)==null?void 0:y.agentName)??((k=t.args)==null?void 0:k.agent_name)??((E=t.args)==null?void 0:E.agentName),l=t.name??void 0,u=(!l||l.toLowerCase()==="assistant"||l.toLowerCase()==="model"||l.toLowerCase()==="agent")&&a?a:l||a||void 0,f=t.model??((S=t.additionalKwargs)==null?void 0:S.model)??void 0,h=t.toolCallId??void 0,p=t.additionalKwargs??void 0,m=t.responseMetadata??void 0;return{...t,id:s,role:n,content:o,createdAt:i,name:u,model:f,toolCallId:h,toolCalls:r,additionalKwargs:p,responseMetadata:m,artifact:t.artifact??void 0}}function cg(e){if(!e||typeof e!="object")return e;const t=In(e);if(t.tool&&!t.name&&(t.name=t.tool),t.type==="artifact.update"&&t.artifact&&typeof t.artifact=="object"){const n=t.artifact;!n.id&&n.artifactId&&(n.id=n.artifactId),!n.type&&n.artifactType&&(n.type=n.artifactType)}return t}function lc(e){if(!e||typeof e!="object")return e;const t=In(e);return{...t,type:"tool_call",id:t.id??t.callId,name:t.name??t.tool??void 0,args:t.args??t.arguments??void 0}}function ug(e,t){return typeof e=="string"?[{type:"text",text:e}]:Array.isArray(e)?e.map(n=>n.type==="tool_call"||n.type==="tool"?t?null:lc(In(n)):n).filter(n=>!!(n&&typeof n=="object"&&typeof n.type=="string")):[]}function dg(e){const t=In(e),n=t.role;if(n&&(n==="assistant"||n==="user"||n==="system"||n==="tool"||n==="interrupt"||n==="default_message"))return n;const r=t.type;return r==="human"?"user":r==="ai"?"assistant":r==="tool"?"tool":r==="system"?"system":null}function Vr(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=pr(t);if(n!==null)return Vr(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?Vr(e.content):e}function mr(e){const r=[...(Array.isArray(e==null?void 0:e.checkpoints)?(e==null?void 0:e.checkpoints)??[]:e!=null&&e.checkpoints?Object.values(e.checkpoints):[]).map((s,i)=>fg(In(s),i)).filter(s=>!!s)].sort((s,i)=>cc(i.createdAt)-cc(s.createdAt)),o=r[0]??null;return{threadId:(e==null?void 0:e.threadId)??"",latest:o,checkpoints:r,interrupt:(o==null?void 0:o.interrupt)??null}}function fg(e,t){var S,C;if(!e)return null;const n=((S=e.values)==null?void 0:S.activeAgent)??null,r=(C=e.values)==null?void 0:C.messages,s=(Array.isArray(r)?r:[]).map(T=>hg(T,n)).filter(T=>!!T),i=Kn(e.metadata)??{},a=ic(e.config),l=Kn(e.parentConfig),c=ic(l),u=Wr(a,["checkpointId"]),f=Wr(a,["checkpointNs"]),h=Wr(c,["checkpointId"]),p=Kn(e.config),m=Array.isArray(e.tasks)?e.tasks.map(T=>({...T})):e.tasks??null,b=Array.isArray(e.next)?[...e.next]:e.next??null,g=typeof e.createdAt=="string"&&e.createdAt.trim()?e.createdAt:new Date(Date.now()-t).toISOString(),w={...i,step:ig(i,["step"])??0,source:Wr(i,["source"])??null},y=s.map(T=>({...T,checkpointId:u??null})),k=e.values,E=Array.isArray(e.interrupts)?e.interrupts:Array.isArray(k==null?void 0:k.interrupts)?k.interrupts:[];return{checkpointId:u??null,checkpointNs:f??null,createdAt:g,parentId:h??null,messages:y,interrupt:pg(y,E,t,u??null),metadata:w,config:p??null,parentConfig:l??null,next:b,tasks:m,values:e.values??{}}}function hg(e,t){const n=Mo(e);return n?(n.role==="assistant"&&!n.name&&t&&(n.name=t),n):null}function pg(e,t,n,r){const o=t.length,s=mg(e,n);if(s)return s;for(let i=o-1;i>=0;i-=1){const a=t[i];if(!a||typeof a!="object")continue;const l=a,c=l.value??a;if(c==null)continue;return{id:typeof l.id=="string"&&l.id.trim()?l.id:`interrupt-${r??n}-${i}`,value:c}}return null}function mg(e,t){var n;for(let r=e.length-1;r>=0;r--){const o=((n=e[r])==null?void 0:n.content)??[];for(let s=o.length-1;s>=0;s--){const i=o[s];if((i==null?void 0:i.type)==="interrupt"){const a=i;return{id:typeof a.id=="string"&&a.id.trim()?a.id:`interrupt-${t}-${r}-${s}`,value:a.value}}}}return null}function cc(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function gg(e){return e.type==="text"}function xg(e){return e.type==="image_url"}function bg(e){return e.type==="file"}function wg(e){return e.type==="interrupt"}function yg(e){return typeof e.content=="string"?e.content.trim():Array.isArray(e.content)?e.content.filter(t=>gg(t)||typeof t=="object"&&t&&t.type==="text").map(t=>t.text||"").join(`
36
- `).trim():""}function vg(e){return e.content.filter(xg)}function Sg(e){return e.content.filter(bg)}function li(e){return Array.isArray(e.toolCalls)?e.toolCalls:[]}function Cg(e){return e.content.filter(wg)}function Tg(e){const t=[];return e.forEach(n=>{n.artifact&&t.push(n.artifact),Array.isArray(n.toolCalls)&&n.toolCalls.forEach(r=>{r!=null&&r.artifact&&t.push(r.artifact)})}),t}function kg(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function uc(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function dc(e){const t=e.toolCallId??(e.role==="tool"?e.id:void 0);return e.role==="tool"&&!t&&console.error("[meta-utils] CRITICAL: Tool message missing toolCallId!",e),{toolCallId:t??void 0,name:e.name??void 0}}function Do(e){const t=e.artifact;return!t||typeof t!="object"?null:"metadata"in t&&t.metadata?t.metadata:{id:t.id??e.id??`artifact-${Date.now()}`,type:t.type??"unknown",createdAt:e.createdAt??new Date().toISOString(),status:t.status??"completed",progress:t.progress??void 0}}function Eg(e){if(!e||typeof e!="object")return!1;const t=Do({artifact:e});return!!(t&&t.status==="in_progress"&&(t.progress??0)<100)}function Ig(e,t){const n=Do(e);if(!n)return e;const r={...n,...t,updatedAt:new Date().toISOString()};return{...e,artifact:{...typeof e.artifact=="object"&&e.artifact?e.artifact:{},metadata:r}}}function Ag(e,t,n){return e.find(r=>{const o=Do(r);return!!((o==null?void 0:o.id)===t||n&&r.toolCallId===n)})??null}function ci(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function Kr(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(Kr).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(ci(e)){try{console.debug("[message-utils] sanitizeForDisplay - dropping file-like object",{sampleFilename:e&&(e.filename||e.name)?e.filename||e.name:void 0,keys:Object.keys(e||{})})}catch(n){console.debug("[message-utils] sanitizeForDisplay - dropped file-like (unable to inspect)",{err:String(n)})}return}const t={};for(const n of Object.keys(e)){const r=e[n];if(n==="data"&&typeof r=="string"&&r.length>100)t[n]=`[base64 ${r.length} chars omitted]`;else{const o=Kr(r);o!==void 0&&(t[n]=o)}}if(Object.keys(t).length)return t;try{console.debug("[message-utils] sanitizeForDisplay - object emptied -> returning undefined",{originalKeys:Object.keys(e||{})})}catch(n){console.debug("[message-utils] sanitizeForDisplay - object emptied -> returning undefined (inspect failed)",{err:String(n)})}return}return e}function gr(e){if(typeof e=="string")return e;if(ci(e))return"";try{const t=Kr(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function Ng(e){const t=gr(e);return typeof e=="string"&&ac(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function fc(e){const t=r=>{try{const o=Kr(r);return typeof o=="string"?o:JSON.stringify(o??"")}catch{return""}},n=e.filter(r=>r.type==="text");return n.length?t(n.map(r=>r.text).join(`
37
- `)):t(e)}function jg(e){return e.content.some(t=>t.type==="text"?t.text.trim().length>0:t.type==="image_url"||t.type==="file")}function xr(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim(),n=pr(t);return n!==null?xr(n):t}if(Array.isArray(e))return e.map(t=>xr(t));if(typeof e=="object"){const t=e.value;if(t!==void 0)return xr(t)}return e}function hc(e){const t=xr(e.value);return t===e.value?e:{...e,value:t}}function pc(e){if(!e)return null;const t=String(e).toLowerCase();return t==="running"||t==="pending"?"pending":t==="completed"||t==="success"?"completed":t==="error"||t==="failed"||t==="failure"?"error":null}function _g(e){if(!e||typeof e!="object")return null;const t=e.id??e.callId,n=e.name??e.tool,r=e.args??e.arguments;return!t||!n?null:{type:"tool_call",...e,id:t,name:n,args:r??{}}}function mc(e){return Array.isArray(e.toolCalls)&&e.toolCalls.length>0?e.toolCalls.map(_g).filter(t=>!!t):li(e)}function ui(e,t){return t.find(n=>n.role==="tool"&&(n.toolCallId===e||n.id===e))}function Pg(e,t){const n=t.response??t.content;if(!n)return;const r=typeof n=="string"?n:gr(n);if(!r.trim())return;const o=[{type:"text",text:r}];return{id:`tool-${t.id}`,role:"tool",content:o,name:t.name,toolCallId:t.id,artifact:t.artifact,createdAt:e.createdAt}}function di(e,t=[]){if(Array.isArray(e)){const o=e.filter(i=>i.role==="assistant").flatMap(i=>mc(i)),s=new Map;return o.forEach(i=>s.set(i.id,i)),Array.from(s.values()).map(i=>{var f,h,p;const a=ui(i.id,e)||ui(i.id,t),l=Array.isArray((f=a==null?void 0:a.additionalKwargs)==null?void 0:f.toolProgress)?(h=a==null?void 0:a.additionalKwargs)==null?void 0:h.toolProgress:void 0,c=(a==null?void 0:a.artifact)??i.artifact,u=pc(i.status)??((p=a==null?void 0:a.additionalKwargs)!=null&&p.toolStreaming?"pending":null)??(a?"completed":"pending");return{call:i,result:a,state:u,progress:l,artifact:c}})}if(e.role!=="assistant")return[];const n=mc(e);return n.length===0?[]:n.map(r=>{var l,c,u;const o=ui(r.id,t)??Pg(e,r),s=Array.isArray((l=o==null?void 0:o.additionalKwargs)==null?void 0:l.toolProgress)?(c=o==null?void 0:o.additionalKwargs)==null?void 0:c.toolProgress:void 0,i=(o==null?void 0:o.artifact)??r.artifact,a=pc(r.status)??((u=o==null?void 0:o.additionalKwargs)!=null&&u.toolStreaming?"pending":null)??(o?"completed":"pending");return{call:r,result:o,state:a,progress:s,artifact:i}})}function Rg(e,t=[]){return di(e,t).map(n=>n.artifact).filter(n=>!!n)}function Lo(e){return e.map(t=>Mo(t)).filter(t=>!!t)}function $o(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Og(e){let t=!1;const n=e.map(r=>{const o=(r.content??[]).filter(s=>s.type!=="interrupt");return o.length!==r.content.length?(t=!0,{...r,content:o}):r});return t?n:e}function Mg(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function Dg(e,t,n,r){const o={...n};if(r!==null&&typeof r=="number"){if(typeof o.lastSeq=="number"&&r<=o.lastSeq)return{newParts:e,newMeta:o,changed:!1};o.lastSeq=r}const s=t.filter(f=>f.type==="text").map(f=>f.text??"").join(""),i=t.filter(f=>f.type!=="text"),a=o.lastText??Mg(e);let l="",c=e.slice();if(s){const f=Lg(a,s);if(f===""?l="":f===s?l=s:l=f,$g(a,l)&&(l=` ${l}`),l){const h=c[c.length-1];if((h==null?void 0:h.type)==="text"){const p=h.text??"",m={...h,text:p+l};c=[...c.slice(0,c.length-1),m]}else c=[...c,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(c=[...c,...i]);const u=!!(l||i.length);return{newParts:c,newMeta:o,changed:u}}function Lg(e,t){if(!t)return"";if(!e)return t;if(e===t)return"";const n=Math.min(e.length,t.length);for(let r=n;r>0;r--)if(e.slice(-r)===t.slice(0,r))return t.slice(r);return t}function $g(e,t){if(!e||!t)return!1;const n=e.slice(-1),r=t[0];if(!n||!r||/\s/.test(n)||/\s/.test(r))return!1;const o=a=>/[A-Za-z0-9]/.test(a),s=a=>/[A-Za-z]/.test(a);return(a=>/[.,;:!?]/.test(a))(n)&&o(r)||/[A-Z]/.test(r)&&!/[\s\(\[\{]/.test(n)?!0:o(n)&&s(r)}function Fg(e,t,n){for(let r=e.length-1;r>=0;r--)if(e[r].role==="assistant"){const s={...e[r],checkpointId:t,checkpointNs:n??void 0};return $o(e,r,s)}return e}function zg(e){const t=new Map,n=[];return e.slice().sort((r,o)=>{const s=r.createdAt?Date.parse(r.createdAt):0,i=o.createdAt?Date.parse(o.createdAt):0;return s-i}).forEach(r=>{const o=Array.isArray(r.messages)?r.messages:[];for(const s of o)!(s!=null&&s.id)||t.has(s.id)||(t.set(s.id,s),n.push(s))}),n.sort((r,o)=>{const s=r.createdAt?Date.parse(r.createdAt):0,i=o.createdAt?Date.parse(o.createdAt):0;return s-i}),n}const Bg={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,messagesStreamMeta:{},pendingInterrupt:null,values:{}};function Ug(e,t){var n;switch(t.type){case"reset":return{messages:Lo(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,pendingInterrupt:null,messagesStreamMeta:{},values:{}};case"user_message":{const{message:r,editingMessageId:o}=t.payload;if(o){const s=e.messages.findIndex(i=>i.id===o);if(s>=0){const i=e.messages.slice(0,s);return{...e,messages:[...i,r],assemblingId:null}}}return{...e,messages:[...e.messages,r],assemblingId:null}}case"seed":{const r=Lo(t.payload.messages),o={...e,messages:r,assemblingId:null,pendingInterrupt:t.payload.pendingInterrupt??null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),o}case"prepend":{const r=Lo(t.payload.messages);if(!r.length)return e;const o=new Set(e.messages.map(a=>a.id)),s=r.filter(a=>!o.has(a.id));if(!s.length)return e;const i=[...s,...e.messages];return{...e,messages:i}}case"event":return gc(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>gc(o,s),e):e}default:return e}}function Hg(e=[]){const[t,n]=v.useReducer(Ug,{...Bg,messages:e}),r=v.useRef([]),o=v.useRef(null),s=v.useRef(null),i=v.useCallback(()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),o.current=null,s.current=null;const u=r.current;u.length&&(r.current=[],n({type:"batch",payload:{events:u}}))},[]),a=v.useCallback(()=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?o.current===null&&(o.current=window.requestAnimationFrame(()=>i())):s.current===null&&(s.current=setTimeout(i,8))},[i]),l=v.useCallback(u=>{r.current.push(u),a()},[a]);v.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const c=v.useMemo(()=>({reset:u=>n({type:"reset",payload:{messages:u}}),seed:(u,f)=>n({type:"seed",payload:{messages:u,...f??{}}}),prepend:u=>n({type:"prepend",payload:{messages:u}}),pushUser:(u,f)=>n({type:"user_message",payload:{message:u,editingMessageId:f}}),onEvent:l}),[l]);return{state:t,dispatch:n,...c}}function gc(e,t){if(t.type==="tool.start")return Wg(e,t);if(t.type==="tool.progress")return Vg(e,t);if(t.type==="tool.end")return Kg(e,t);if(t.type==="artifact.update")return qg(e,t);if(t.type==="message.start")return{...e,assemblingId:t.id};if(t.type==="message.delta"){const n=e.assemblingId;if(!n)return e;const r=t.delta,o=t.seq,s=e.messages.findIndex(l=>l.id===n);let i=e.messages;const a=r.map(l=>l.text?{type:"text",text:l.text}:l);if(s!==-1){const l=e.messages[s],c=(e.messagesStreamMeta||{})[n]||{},{newParts:u,newMeta:f,changed:h}=Dg(Array.isArray(l.content)?l.content:[],a,c,o);return h?(i=$o(i,s,{...l,content:u}),{...e,messages:i,messagesStreamMeta:{...e.messagesStreamMeta,[n]:f}}):e}else{const l={id:n,role:"assistant",content:a,createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,l],assemblingId:n}}}if(t.type==="message.end")return{...e,assemblingId:null};if(t.type==="checkpoint"){const n=t.checkpointNs??e.lastCheckpointNs??null,r=Fg(e.messages,t.checkpointId,n);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:n,messages:r}}if(t.type==="error"){const n={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,n]}}if(t.type==="state_history"){const n=mr(t),r=n.interrupt,o=n.latest,s=zg(n.checkpoints);let i=s.length?s:o==null?void 0:o.messages;if(i){const a=new Set(i.map(c=>c.id)),l=e.messages.filter(c=>!a.has(c.id));if(l.length&&(i=[...i,...l]),e.assemblingId&&!i.some(c=>c.id===e.assemblingId)){const c=e.messages.find(u=>u.id===e.assemblingId);c&&(i=[...i,c])}i=Lo(i)}else i=r===null?Og(e.messages):e.messages;return{...e,messages:i,pendingInterrupt:r,lastCheckpointId:(o==null?void 0:o.checkpointId)??e.lastCheckpointId,lastCheckpointNs:(o==null?void 0:o.checkpointNs)??e.lastCheckpointNs,values:(o==null?void 0:o.values)??e.values}}return t.type==="thread_info",e}function fi(e){return e.id??void 0}function Fo(e,t){var n;if(!t)return-1;for(let r=e.length-1;r>=0;r--){const o=e[r];if(o.role==="assistant"&&((n=o.toolCalls)!=null&&n.some(s=>s.id===t)))return r}return-1}function hi(e,t,n){const r=Fo(e,t);if(r===-1)return e;const o=e[r],s=(o.toolCalls??[]).map(i=>i.id===t?{...i,...n}:i);return $o(e,r,{...o,toolCalls:s})}function Wg(e,t){const n=fi(t),r=t.name??void 0,o={type:t.type,content:`Starting ${r??"tool"}...`,seq:t.seq??null,timestamp:new Date().toISOString()};let s=e.messages;return n&&Fo(s,n)!==-1&&(s=hi(s,n,{status:"running",content:o.content})),{...e,messages:s}}function Vg(e,t){const n=t.id??fi(t);if(!n)return e;const r=t.content??void 0;let o=e.messages;return Fo(o,n)!==-1&&(o=hi(o,n,{content:r})),{...e,messages:o}}function Kg(e,t){const n=fi(t);let r=e.messages;const o=t.content??t.error??null,s=typeof o=="string"?o:JSON.stringify(o),i=Vr(o),a=typeof i=="string"?i:s;n&&Fo(r,n)!==-1&&(r=hi(r,n,{status:"completed",content:a,artifact:t.artifact}));const l={id:`tool-${n||Date.now()}`,role:"tool",name:t.name??void 0,content:[{type:"text",text:a}],artifact:t.artifact,toolCallId:n??void 0,createdAt:new Date().toISOString()};return{...e,messages:[...r,l]}}function qg(e,t){const n=t.artifactId,r=t.callId,o=Ag(e.messages,n,r);if(!o){const a={id:`artifact-${n}`,role:"tool",name:"artifact_updater",content:[],createdAt:new Date().toISOString(),artifact:{type:"unknown",metadata:{id:n,type:"unknown",createdAt:new Date().toISOString(),status:t.status,progress:t.progress},...t.partial_data}};return{...e,messages:[...e.messages,a]}}const s=e.messages.indexOf(o),i=Ig(o,{status:t.status,progress:t.progress,error:t.error});return t.partial_data&&i.artifact&&(i.artifact={...i.artifact,...t.partial_data}),{...e,messages:$o(e.messages,s,i)}}const xc=120;function Gg(e){if(!Array.isArray(e))return"";const t=e.filter(r=>!!(r&&r.type==="text")).map(r=>(r.text??"").trim()).filter(Boolean);if(!t.length)return"";const n=t.join(" ").replace(/\s+/g," ").trim();return n?n.length>xc?`${n.slice(0,xc-3)}…`:n:""}function Yg(e){return Gg(e.content)||""}function Xg(e){const t=new Map,n=[],r=new Map,o=[];for(let c=0;c<e.length;c++){const u=e[c],f=u.checkpointId,h=f??`cp-${c}`,p=u.metadata??{},m=typeof p.step=="number"?p.step:null,b=typeof p.source=="string"?p.source:null;let g=null,w=null;const y=Array.isArray(u.messages)?u.messages:[];for(const C of y)C.role==="user"&&(w||(w=C),C.id&&(g=C.id));const k=u.next&&u.next.length>0?String(u.next[0]):null,E=u.parentConfig??null,S={id:h,step:m,source:b,createdAt:u.createdAt??null,namespace:u.checkpointNs??null,parentId:u.parentId??null,next:k,parentConfig:E,userMessageId:g};if(o.push(S),f&&t.set(f,S),f&&w){const C=Yg(w);C&&r.set(f,C)}n.push({id:h,messageId:g,step:m,source:b,createdAt:u.createdAt??null,next:k,parentConfig:E})}const s=new Map;for(const c of o){if(!c.userMessageId)continue;const u=s.get(c.userMessageId)??[];u.push(c),s.set(c.userMessageId,u)}for(const c of s.values()){if(!c.length)continue;c.sort((f,h)=>{const p=f.createdAt?Date.parse(f.createdAt):0;return(h.createdAt?Date.parse(h.createdAt):0)-p});const u=c.length;for(let f=0;f<c.length;f++){const h=c[f];h.attemptCount=u,h.attemptIndex=f,h.isLatestAttempt=f===0}}return{checkpoints:e,checkpointMetaByCheckpointId:t,timeline:n,messagePreviews:r,getLatest:()=>{const c=n[0];if(c)return t.get(c.id)},getCheckpoint:c=>t.get(c),getMessageAttempts:c=>{const u=[];for(const f of t.values())f.userMessageId===c&&u.push(f);return u.length?(u.sort((f,h)=>{const p=typeof f.attemptIndex=="number"?f.attemptIndex:Number.MAX_SAFE_INTEGER,m=typeof h.attemptIndex=="number"?h.attemptIndex:Number.MAX_SAFE_INTEGER;return p-m}),u):[]}}}function Jg(e,t,n){if(!e)return{attemptCount:1,attemptIndex:0,attempts:[]};const r=n.getMessageAttempts(e);if(!r.length)return{attemptCount:1,attemptIndex:0,attempts:[]};let o=0;if(t){const s=r.findIndex(i=>i.id===t);s>=0&&(o=s)}return{attemptCount:r.length,attemptIndex:o,attempts:r}}function Zg(e){return v.useMemo(()=>Xg(e),[e])}function bc({api:e,seed:t,onError:n,currentThreadId:r,initialThreadId:o=null,initialCheckpointId:s=null,initialCheckpointNs:i=null,autoLoadInitial:a=!0,isStreaming:l,getMessages:c}){const[u,f]=v.useState(null),p=v.useMemo(()=>mr(u),[u]).checkpoints,m=Zg(p),b=m.timeline,[g,w]=v.useState(!1),[y,k]=v.useState(!1),[E,S]=v.useState(null),C=v.useRef(r),T=v.useRef(null),A=v.useRef(null),N=v.useRef(null),j=v.useRef(null),L=v.useRef(null),B=v.useRef(new Map),W=v.useRef(null);v.useEffect(()=>{C.current=r},[r]);const O=v.useCallback(async $=>{var G,te;if(!$.threadId)return;const R=$.threadId;(G=$.onStart)==null||G.call($),$.setLoading(!0);try{await $.action(R)}catch(F){if(!ql(F)&&C.current===R){const re=String(F);(te=$.handleError)==null||te.call($,re),n==null||n(re)}throw F}finally{$.setLoading(!1)}},[n]),D=v.useCallback(async($,R)=>{var re;if(!$)return;const G=`${$}:${R??"latest"}`,te=B.current.get(G);if(te)return te;(re=W.current)==null||re.abort();const F=new AbortController;W.current=F;const X=O({threadId:$,setLoading:w,onStart:()=>S(null),handleError:ue=>S(ue),action:async ue=>{const le=await e.getStateHistory({threadId:ue,checkpointId:R??void 0,signal:F.signal});if(C.current!==ue){console.log(`[useThreadHistoryState] Thread changed during load (was ${ue}, now ${C.current}), discarding stale data`);return}const{checkpoints:Se,latest:Me}=mr(le),Ie=R?Se.find(Ke=>Ke.checkpointId===R)??Me:Me;t((Ie==null?void 0:Ie.messages)??[],{checkpointId:(Ie==null?void 0:Ie.checkpointId)??null,checkpointNs:(Ie==null?void 0:Ie.checkpointNs)??null,pendingInterrupt:(Ie==null?void 0:Ie.interrupt)??null}),f(le)}});B.current.set(G,X);try{await X}finally{B.current.delete(G),W.current===F&&(W.current=null)}return C.current===$&&(L.current=G),X},[e,t,O]),z=v.useCallback(async($,R)=>{j.current=$;try{await D($,R)}catch(G){if(!ql(G))throw G}finally{j.current===$&&(j.current=null)}},[D]),ee=v.useCallback($=>{A.current=$},[]),H=v.useCallback($=>{N.current=$},[]),V=v.useCallback($=>{const R=$.threadId??C.current;if(!R||C.current&&C.current!==R)return;const{checkpoints:G,latest:te}=mr($);if(!G.length)return;const F=te,X=N.current===R;!l&&!X&&t((F==null?void 0:F.messages)??[],{checkpointId:(F==null?void 0:F.checkpointId)??null,checkpointNs:(F==null?void 0:F.checkpointNs)??null,pendingInterrupt:(F==null?void 0:F.interrupt)??null}),f($),L.current=`${R}:latest`,A.current=null,N.current===R&&(N.current=null)},[t,l]),Y=v.useCallback(async($,R)=>{const G=C.current;await O({threadId:G,setLoading:k,action:async te=>{const F=await e.getStateHistory({threadId:te,checkpointId:$,checkpointNs:R??void 0});if(C.current!==te)return;const{checkpoints:X}=mr(F),re=X.find(ue=>ue.checkpointId===$&&(R?ue.checkpointNs===R:!0));if(!re){console.warn("[useThreadHistoryState] Requested checkpoint not found:",{checkpointId:$,checkpointNs:R});return}f(F),t(re.messages??[],{checkpointId:re.checkpointId??null,checkpointNs:re.checkpointNs??null})}}).catch(()=>{})},[e,t,O]),q=v.useCallback(($,R)=>{t(c(),{checkpointId:$??null,checkpointNs:R??null})},[c,t]),M=v.useCallback(async()=>{C.current&&await z(C.current)},[z]);v.useEffect(()=>{if(!a||!r||g||l)return;if(A.current===r){A.current=null,T.current=r;return}if(N.current===r){T.current=r;return}if(j.current===r){j.current=null,T.current=r;return}if(T.current===r)return;T.current=r;let $;const R=`${r}:latest`;L.current!==R&&z(r,$)},[a,r,s,i,o,g,l,z]);const P=v.useCallback(()=>{f(null),w(!1),k(!1),S(null),A.current=null,N.current=null,T.current=null,L.current=null,j.current=null},[]);return{threadCheckpoints:p,threadTimeline:b,checkpointIndex:m,isLoadingThread:g,isLoadingCheckpoint:y,threadStateError:E,loadThread:z,navigateToCheckpoint:Y,setCurrentCheckpointId:q,returnToLatest:M,handleStateHistoryEvent:V,markSkipNextLoad:ee,markStreamPendingThread:H,resetHistoryState:P,clearState:P}}function Qg(e,t,n){const r=typeof t=="string"?[{type:"text",text:t}]:t;return{id:`msg-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,role:e,content:r,createdAt:new Date().toISOString(),...n}}function wc(e,t="user"){return typeof e=="string"?Qg(t,e):e}function yc(e){return!!e&&typeof e=="object"&&"data"in e}function ex(e){return e&&e.type==="messages/partial"}let pi={isStreaming:!1};const mi=new Set;function tx(e){pi.isStreaming!==e.isStreaming&&(pi=e,mi.forEach(t=>t()))}function nx(e){return mi.add(e),()=>mi.delete(e)}function rx(){return v.useSyncExternalStore(nx,()=>pi.isStreaming,()=>!1)}function ox(e={}){const t=e.baseUrl||"",n=e.streamPath??"/stream",[r,o]=v.useState(e.token??null),s=v.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=v.useState(!1),[c,u]=v.useState(null),[f,h]=v.useState(""),[p,m]=v.useState(null),[b,g]=v.useState(0),[w,y]=v.useState(!1),[k,E]=v.useState({}),[S,C]=v.useState(null),[T,A]=v.useState({}),N=v.useRef(null),j=v.useRef(!0),L=v.useRef(0),B=v.useRef(null),W=v.useRef(null),O=v.useRef(null),D=v.useRef(null),z=v.useRef({messageId:null,lastSeq:null,lastText:""}),ee=v.useCallback(q=>{o(q)},[]);v.useEffect(()=>{tx({isStreaming:a})},[a]);const H=v.useCallback(()=>{h(""),m(null),u(null),W.current=null,O.current=null,D.current=null,E({}),C(null),A({}),z.current={messageId:null,lastSeq:null,lastText:""}},[]),V=v.useCallback(()=>{var $;console.debug("[use-chat] stop() invoked - aborting stream");const q=($=B.current)==null?void 0:$.threadId,M=()=>{var R;(R=N.current)==null||R.abort(),N.current=null,B.current=null,l(!1),y(!1),L.current=0,g(0)};(q?En.cancelRun(q).catch(R=>{console.warn("[use-chat] cancel run failed:",R)}):Promise.resolve()).finally(M)},[]),Y=v.useCallback((q,M,P)=>{N.current&&(N.current.abort(),N.current=null),l(!0),u(null),e.autoAppendAssistant!==!1&&h(""),m(null),W.current=null,O.current=null,D.current=null,E({}),C(null),A({}),z.current={messageId:null,lastSeq:null,lastText:""};const $=new AbortController;N.current=$;let R=null,G=null,te=!1;return B.current={threadId:q.threadId??null,headers:{},isStreaming:!0},(async()=>{var F,X,re,ue,le,Se,Me,Ie,Ke,He,Fe,ze,It,At,wt,yt,ht,st,Nt,jt;try{let rt={};try{if(r)rt={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const Ze=window.__AUTH_TOKEN__,Sn=((F=window.localStorage)==null?void 0:F.getItem(Tn.authToken))||null;let fn=null;try{const zn=(X=window.localStorage)==null?void 0:X.getItem(Tn.chatSettings);zn&&(fn=((re=JSON.parse(zn))==null?void 0:re.apiKey)||null)}catch{}const hn=Ze||Sn||fn||null;hn&&(rt={Authorization:`Bearer ${hn}`})}}catch{}console.debug("[use-chat] POST",t+n);let tt={};if(typeof window<"u")try{const Xe=(ue=window.localStorage)==null?void 0:ue.getItem(Tn.authSessionId);Xe&&(tt={"X-Session-Id":Xe})}catch{}const it={...rt,...tt,...s.current},_t={"Content-Type":"application/json",Accept:"text/event-stream",...it},Ae=await fetch(t+n,{method:"POST",headers:_t,body:JSON.stringify(q),signal:$.signal,credentials:i});if(B.current&&(B.current.headers=it),!Ae.ok||!Ae.body){const Xe=await Ae.text().catch(()=>"");console.debug("[use-chat] non-OK response",Ae.status,Xe==null?void 0:Xe.slice(0,500));const Ze=`stream ${Ae.status}${Xe?": "+Xe:""}`;throw(le=P==null?void 0:P.onConnectionError)==null||le.call(P,Ze),te=!0,R="error",G=Ze,new Error(Ze)}y(!0);const Ye=Ae.body.getReader(),Or=new TextDecoder;let $t="",bn=[];L.current=0,g(0);let Vt=0,Ft=null;const wn=()=>{if(bn.length){const Xe=bn.join("");bn=[],j.current&&h(Ze=>Ze+Xe)}Ft=null},pt=()=>{typeof window<"u"&&Ft==null&&(Ft=requestAnimationFrame(wn))};let yn=Date.now();const dn=setInterval(()=>{var Xe;if(Date.now()-yn>18e5){const Ze="Stream idle timeout";u(Ze),R="error",G=Ze,$.abort(),(Xe=P==null?void 0:P.onError)==null||Xe.call(P,Ze)}},5e3),vn=1024*1024;try{const Xe=Ae.headers.get("X-Thread-Id")||Ae.headers.get("x-thread-id"),Ze=Ae.headers.get("X-Thread-Created")||Ae.headers.get("x-thread-created"),Sn=Xe??null,fn=String(Ze??"").toLowerCase()==="true";for(B.current&&!B.current.threadId&&(B.current={...B.current,threadId:Sn}),(Se=P==null?void 0:P.onOpen)==null||Se.call(P,{threadId:Sn,created:fn});;){const{value:hn,done:zn}=await Ye.read();if(zn)break;$t+=Or.decode(hn,{stream:!0}),$t.length>vn&&($t="",console.warn("Stream buffer reset: exceeded 1MB"));let Bn;for(;(Bn=$t.indexOf(`
35
+ <%s key={someKey} {...props} />`,at,Pe,mn,Pe),vn[Pe+at]=!0}}return I===r?yn(ve):Fn(ve),ve}}function Rr(I,ee,Q){return sr(I,ee,Q,!0)}function zn(I,ee,Q){return sr(I,ee,Q,!1)}var ir=zn,Bn=Rr;Br.Fragment=r,Br.jsx=ir,Br.jsxs=Bn}()),Br}process.env.NODE_ENV==="production"?ai.exports=eg():ai.exports=tg();var d=ai.exports;class ng{constructor(){sl(this,"_authBaseUrl","")}get baseUrl(){return this._authBaseUrl}updateConfig(t){if(t.authBaseUrl)this._authBaseUrl=t.authBaseUrl;else if(t.baseUrl){const n=t.baseUrl.replace(/\/+$/,"");this._authBaseUrl=`${n}/auth`}t.apiKey!==void 0?Cn(t.apiKey):t.getToken&&Cn(t.getToken())}getAuthToken(){return ri()}setAuthToken(t){Cn(t)}onTokenChange(t){return oi(t)}async listUsers(){const t=await Tt("/users",{baseURL:this.baseUrl});return(t==null?void 0:t.users)??[]}}const rg=new ng,tc=v.createContext(null);function nc({children:e,apiConfig:t}){const n=Tn,r=rg;if(t){const s=n.baseUrl,i=r.baseUrl,a=n.getAuthToken();(t.baseUrl||t.chatBaseUrl)&&(t.chatBaseUrl&&t.chatBaseUrl!==s||t.baseUrl&&!s.startsWith(t.baseUrl))&&n.updateConfig(t),(t.baseUrl||t.authBaseUrl)&&(t.authBaseUrl&&t.authBaseUrl!==i||t.baseUrl&&!i.startsWith(t.baseUrl))&&r.updateConfig(t),t.apiKey!==void 0&&t.apiKey!==a&&(n.updateConfig({apiKey:t.apiKey}),r.updateConfig({apiKey:t.apiKey}))}const o={token:n.getAuthToken(),setToken:s=>{n.setAuthToken(s),r.setAuthToken(s)},chatApi:n,authApi:r,fileApi:ii,baseUrl:n.baseUrl};return d.jsx(tc.Provider,{value:o,children:e})}function fr(){const e=v.useContext(tc);if(!e)throw new Error("useApi must be used within ApiProvider");return e}const og=["detail","message","error","description","title"];function Oo(e){if(!e)return null;if(typeof e=="string"){const t=e.trim();return t.length?t:null}if(Array.isArray(e)){for(const t of e){const n=Oo(t);if(n)return n}return null}if(typeof e=="object"){const t=e;for(const n of og){const r=Oo(t[n]);if(r)return r}if("errors"in t){const n=Oo(t.errors);if(n)return n}}return null}function sg(e){if(!e)return"Request failed";const t=e.response,n=Oo(t==null?void 0:t.data);if(n)return n;if(t!=null&&t.statusText)return t.statusText;if(e instanceof Error&&e.message)return e.message;if(typeof e=="string"){const r=e.trim();if(r.length)return r}return t!=null&&t.status?`Request failed with status code ${t.status}`:"Request failed"}function rc({api:e,initialThreadId:t=null,onError:n,onThreadChange:r,onCurrentThreadDeleted:o}){const[s,i]=v.useState([]),[a,l]=v.useState(t),[c,u]=v.useState(!1),[f,h]=v.useState(null),[p,m]=v.useState([]),[b,g]=v.useState(!1),[,w]=v.useState(null),[y,k]=v.useState(null),[E,S]=v.useState(!1),C=v.useRef(a),T=v.useRef(new Map);v.useEffect(()=>{C.current=a},[a]),v.useEffect(()=>{t!==void 0&&t!==C.current&&l(t)},[t]);const N=v.useCallback(async()=>{u(!0),h(null);try{const U=await e.listThreads();i(U??[])}catch(U){const W=String(U);h(W),n==null||n(W)}finally{u(!1)}},[e,n]),j=v.useCallback(async()=>{g(!0),w(null);try{const U=await e.listSharedThreads();m(U??[])}catch(U){const W=String(U);w(W),n==null||n(W)}finally{g(!1)}},[e,n]);v.useEffect(()=>{N()},[N]),v.useEffect(()=>{j()},[j]),v.useEffect(()=>{r==null||r(a)},[a,r]);const _=v.useCallback(async(U,W)=>{try{const Y=W&&typeof W=="object"?{id:W.id,name:W.name??""}:void 0,q=await e.createThread(U,Y);return l(q.threadId),await N(),q.threadId}catch(Y){const q=String(Y);return n==null||n(q),null}},[e,n,N]),D=v.useCallback(async U=>{const W=s;i(q=>q.filter(R=>R.threadId!==U));const Y=new AbortController;T.current.set(U,Y);try{await e.deleteThread(U),C.current===U&&(l(null),o==null||o())}catch(q){i(W);const R=String(q);n==null||n(R)}finally{T.current.delete(U)}},[e,o,n,s]),z=v.useCallback(async(U,W)=>{try{await e.updateThread(U,W),await N()}catch(Y){n==null||n(String(Y))}},[e,n,N]),H=v.useCallback(async(U,W)=>{S(!0),k("Sharing thread…");try{await e.shareThread(U,W),await j(),k("Shared successfully")}catch(Y){const q=sg(Y);throw n==null||n(q),k(`Failed to share: ${q}`),new Error(q)}finally{S(!1)}},[e,n,j]),P=v.useCallback(async(U,W)=>{try{await e.unshareThread(U,W),await j()}catch(Y){const q=String(Y);throw n==null||n(q),Y}},[e,n,j]),M=v.useMemo(()=>({createThread:_,deleteThread:D,renameThread:z,refreshThreads:N,refreshSharedThreads:j,shareThread:H,unshareThread:P}),[_,D,z,N,j,H,P]),F=v.useCallback(U=>{if(!(U!=null&&U.threadId))return;const W={threadId:U.threadId,title:U.title||`Thread ${U.threadId.slice(0,8)}`,project:U.project,createdAt:U.createdAt||new Date().toISOString(),updatedAt:U.updatedAt||new Date().toISOString(),messageCount:U.messageCount??1};i(Y=>{let q=!1;const R=Y.map(G=>G.threadId===W.threadId?(q=!0,console.debug("[useThreadsState] thread_info: updating existing thread",W.threadId),{...G,title:W.title??G.title,project:W.project??G.project,updatedAt:W.updatedAt??G.updatedAt,messageCount:W.messageCount??G.messageCount}):G);return q?R:(console.debug("[useThreadsState] thread_info: adding thread to list",W.threadId),[W,...Y])})},[]),ne=v.useCallback(()=>k(null),[]);return{threads:s,currentThreadId:a,currentThreadIdRef:C,setCurrentThreadId:l,isLoadingThreads:c,threadsError:f,sharedThreads:p,isLoadingSharedThreads:b,actions:M,addThreadFromEvent:F,shareInFlight:E,shareStatus:y,clearShareStatus:ne}}const oc=v.createContext(null);function sc({children:e,initialThreadId:t=null,onError:n,onThreadChange:r}){const{chatApi:o}=fr(),{threads:s,currentThreadId:i,setCurrentThreadId:a,currentThreadIdRef:l,isLoadingThreads:c,threadsError:u,sharedThreads:f,isLoadingSharedThreads:h,actions:p,addThreadFromEvent:m,shareInFlight:b,shareStatus:g,clearShareStatus:w}=rc({api:o,initialThreadId:t,onError:n,onThreadChange:r}),y=v.useMemo(()=>({threads:s,currentThreadId:i,setCurrentThreadId:a,currentThreadIdRef:l,isLoading:c,error:u,sharedThreads:f,isLoadingSharedThreads:h,actions:p,shareInFlight:b,shareStatus:g,clearShareStatus:w,addThreadFromEvent:m}),[s,i,a,l,c,u,f,h,p,b,g,w,m]);return d.jsx(oc.Provider,{value:y,children:e})}function Ur(){const e=v.useContext(oc);if(!e)throw new Error("useThreads must be used within a ThreadsProvider");return e}function Kn(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function Hr(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r.trim()}}function ig(e,t){if(!e)return null;for(const n of t){const r=e[n];if(typeof r=="number"&&Number.isFinite(r))return r}return null}function ic(e){const t=Kn(e);if(t)return Kn(t.configurable)??t}function ag(e){let t=!1,n="";for(const o of e){if(o==="\\"){n+=o,t=!t;continue}if(o==="'"&&!t){n+='"';continue}n+=o,t=!1}return n.replace(/\bTrue\b/g,"true").replace(/\bFalse\b/g,"false").replace(/\bNone\b/g,"null")}function hr(e){const t=e==null?void 0:e.trim();if(!t||!(t.startsWith("{")||t.startsWith("[")))return null;try{return JSON.parse(t)}catch{const n=ag(t);if(n)try{return JSON.parse(n)}catch{return null}return null}}function ac(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function lg(e){return e.replace(/[_-](\w)/g,(t,n)=>n?n.toUpperCase():"").replace(/^\w/,t=>t.toLowerCase())}function kn(e){return!e||typeof e!="object"?e:Array.isArray(e)?e.map(kn):Object.fromEntries(Object.entries(e).map(([t,n])=>[lg(t),kn(n)]))}function Mo(e){var g,w,y,k,E,S;if(!e||typeof e!="object")return null;const t=kn(e),n=dg(t);if(!n)return null;const r=Array.isArray(t.toolCalls)?t.toolCalls.map(lc):void 0,o=ug(t.content??t.parts,!!(r!=null&&r.length)),s=t.id??`msg-${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`,i=t.createdAt??((g=t.additionalKwargs)==null?void 0:g.createdAt)??new Date().toISOString(),a=((w=t.additionalKwargs)==null?void 0:w.agent_name)??((y=t.additionalKwargs)==null?void 0:y.agentName)??((k=t.args)==null?void 0:k.agent_name)??((E=t.args)==null?void 0:E.agentName),l=t.name??void 0,u=(!l||l.toLowerCase()==="assistant"||l.toLowerCase()==="model"||l.toLowerCase()==="agent")&&a?a:l||a||void 0,f=t.model??((S=t.additionalKwargs)==null?void 0:S.model)??void 0,h=t.toolCallId??void 0,p=t.additionalKwargs??void 0,m=t.responseMetadata??void 0;return{...t,id:s,role:n,content:o,createdAt:i,name:u,model:f,toolCallId:h,toolCalls:r,additionalKwargs:p,responseMetadata:m,artifact:t.artifact??void 0}}function cg(e){if(!e||typeof e!="object")return e;const t=kn(e);if(t.tool&&!t.name&&(t.name=t.tool),t.type==="artifact.update"&&t.artifact&&typeof t.artifact=="object"){const n=t.artifact;!n.id&&n.artifactId&&(n.id=n.artifactId),!n.type&&n.artifactType&&(n.type=n.artifactType)}return t}function lc(e){if(!e||typeof e!="object")return e;const t=kn(e);return{...t,type:"tool_call",id:t.id??t.callId,name:t.name??t.tool??void 0,args:t.args??t.arguments??void 0}}function ug(e,t){return typeof e=="string"?[{type:"text",text:e}]:Array.isArray(e)?e.map(n=>n.type==="tool_call"||n.type==="tool"?t?null:lc(kn(n)):n).filter(n=>!!(n&&typeof n=="object"&&typeof n.type=="string")):[]}function dg(e){const t=kn(e),n=t.role;if(n&&(n==="assistant"||n==="user"||n==="system"||n==="tool"||n==="interrupt"||n==="default_message"))return n;const r=t.type;return r==="human"?"user":r==="ai"?"assistant":r==="tool"?"tool":r==="system"?"system":null}function Wr(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim();if(t.startsWith("{")||t.startsWith("[")){const n=hr(t);if(n!==null)return Wr(n)}return e}return typeof e=="object"&&!Array.isArray(e)&&e.content!==void 0?Wr(e.content):e}function pr(e){const r=[...(Array.isArray(e==null?void 0:e.checkpoints)?(e==null?void 0:e.checkpoints)??[]:e!=null&&e.checkpoints?Object.values(e.checkpoints):[]).map((s,i)=>fg(kn(s),i)).filter(s=>!!s)].sort((s,i)=>cc(i.createdAt)-cc(s.createdAt)),o=r[0]??null;return{threadId:(e==null?void 0:e.threadId)??"",latest:o,checkpoints:r,interrupt:(o==null?void 0:o.interrupt)??null}}function fg(e,t){var S,C;if(!e)return null;const n=((S=e.values)==null?void 0:S.activeAgent)??null,r=(C=e.values)==null?void 0:C.messages,s=(Array.isArray(r)?r:[]).map(T=>hg(T,n)).filter(T=>!!T),i=Kn(e.metadata)??{},a=ic(e.config),l=Kn(e.parentConfig),c=ic(l),u=Hr(a,["checkpointId"]),f=Hr(a,["checkpointNs"]),h=Hr(c,["checkpointId"]),p=Kn(e.config),m=Array.isArray(e.tasks)?e.tasks.map(T=>({...T})):e.tasks??null,b=Array.isArray(e.next)?[...e.next]:e.next??null,g=typeof e.createdAt=="string"&&e.createdAt.trim()?e.createdAt:new Date(Date.now()-t).toISOString(),w={...i,step:ig(i,["step"])??0,source:Hr(i,["source"])??null},y=s.map(T=>({...T,checkpointId:u??null})),k=e.values,E=Array.isArray(e.interrupts)?e.interrupts:Array.isArray(k==null?void 0:k.interrupts)?k.interrupts:[];return{checkpointId:u??null,checkpointNs:f??null,createdAt:g,parentId:h??null,messages:y,interrupt:pg(y,E,t,u??null),metadata:w,config:p??null,parentConfig:l??null,next:b,tasks:m,values:e.values??{}}}function hg(e,t){const n=Mo(e);return n?(n.role==="assistant"&&!n.name&&t&&(n.name=t),n):null}function pg(e,t,n,r){const o=t.length,s=mg(e,n);if(s)return s;for(let i=o-1;i>=0;i-=1){const a=t[i];if(!a||typeof a!="object")continue;const l=a,c=l.value??a;if(c==null)continue;return{id:typeof l.id=="string"&&l.id.trim()?l.id:`interrupt-${r??n}-${i}`,value:c}}return null}function mg(e,t){var n;for(let r=e.length-1;r>=0;r--){const o=((n=e[r])==null?void 0:n.content)??[];for(let s=o.length-1;s>=0;s--){const i=o[s];if((i==null?void 0:i.type)==="interrupt"){const a=i;return{id:typeof a.id=="string"&&a.id.trim()?a.id:`interrupt-${t}-${r}-${s}`,value:a.value}}}}return null}function cc(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function gg(e){return e.type==="text"}function xg(e){return e.type==="image_url"}function bg(e){return e.type==="file"}function wg(e){return e.type==="interrupt"}function yg(e){return typeof e.content=="string"?e.content.trim():Array.isArray(e.content)?e.content.filter(t=>gg(t)||typeof t=="object"&&t&&t.type==="text").map(t=>t.text||"").join(`
36
+ `).trim():""}function vg(e){return e.content.filter(xg)}function Sg(e){return e.content.filter(bg)}function li(e){return Array.isArray(e.toolCalls)?e.toolCalls:[]}function Cg(e){return e.content.filter(wg)}function Tg(e){const t=[];return e.forEach(n=>{n.artifact&&t.push(n.artifact),Array.isArray(n.toolCalls)&&n.toolCalls.forEach(r=>{r!=null&&r.artifact&&t.push(r.artifact)})}),t}function kg(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function uc(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function dc(e){const t=e.toolCallId??(e.role==="tool"?e.id:void 0);return e.role==="tool"&&!t&&console.error("[meta-utils] CRITICAL: Tool message missing toolCallId!",e),{toolCallId:t??void 0,name:e.name??void 0}}function Do(e){const t=e.artifact;return!t||typeof t!="object"?null:"metadata"in t&&t.metadata?t.metadata:{id:t.id??e.id??`artifact-${Date.now()}`,type:t.type??"unknown",createdAt:e.createdAt??new Date().toISOString(),status:t.status??"completed",progress:t.progress??void 0}}function Eg(e){if(!e||typeof e!="object")return!1;const t=Do({artifact:e});return!!(t&&t.status==="in_progress"&&(t.progress??0)<100)}function Ig(e,t){const n=Do(e);if(!n)return e;const r={...n,...t,updatedAt:new Date().toISOString()};return{...e,artifact:{...typeof e.artifact=="object"&&e.artifact?e.artifact:{},metadata:r}}}function Ag(e,t,n){return e.find(r=>{const o=Do(r);return!!((o==null?void 0:o.id)===t||n&&r.toolCallId===n)})??null}function ci(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function Vr(e){if(typeof e=="string")return e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(Vr).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(ci(e)){try{console.debug("[message-utils] sanitizeForDisplay - dropping file-like object",{sampleFilename:e&&(e.filename||e.name)?e.filename||e.name:void 0,keys:Object.keys(e||{})})}catch(n){console.debug("[message-utils] sanitizeForDisplay - dropped file-like (unable to inspect)",{err:String(n)})}return}const t={};for(const n of Object.keys(e)){const r=e[n];if(n==="data"&&typeof r=="string"&&r.length>100)t[n]=`[base64 ${r.length} chars omitted]`;else{const o=Vr(r);o!==void 0&&(t[n]=o)}}if(Object.keys(t).length)return t;try{console.debug("[message-utils] sanitizeForDisplay - object emptied -> returning undefined",{originalKeys:Object.keys(e||{})})}catch(n){console.debug("[message-utils] sanitizeForDisplay - object emptied -> returning undefined (inspect failed)",{err:String(n)})}return}return e}function mr(e){if(typeof e=="string")return e;if(ci(e))return"";try{const t=Vr(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function Ng(e){const t=mr(e);return typeof e=="string"&&ac(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function fc(e){const t=r=>{try{const o=Vr(r);return typeof o=="string"?o:JSON.stringify(o??"")}catch{return""}},n=e.filter(r=>r.type==="text");return n.length?t(n.map(r=>r.text).join(`
37
+ `)):t(e)}function jg(e){return e.content.some(t=>t.type==="text"?t.text.trim().length>0:t.type==="image_url"||t.type==="file")}function gr(e){if(e==null)return e;if(typeof e=="string"){const t=e.trim(),n=hr(t);return n!==null?gr(n):t}if(Array.isArray(e))return e.map(t=>gr(t));if(typeof e=="object"){const t=e.value;if(t!==void 0)return gr(t)}return e}function hc(e){const t=gr(e.value);return t===e.value?e:{...e,value:t}}function pc(e){if(!e)return null;const t=String(e).toLowerCase();return t==="running"||t==="pending"?"pending":t==="completed"||t==="success"?"completed":t==="error"||t==="failed"||t==="failure"?"error":null}function _g(e){if(!e||typeof e!="object")return null;const t=e.id??e.callId,n=e.name??e.tool,r=e.args??e.arguments;return!t||!n?null:{type:"tool_call",...e,id:t,name:n,args:r??{}}}function mc(e){return Array.isArray(e.toolCalls)&&e.toolCalls.length>0?e.toolCalls.map(_g).filter(t=>!!t):li(e)}function ui(e,t){return t.find(n=>n.role==="tool"&&(n.toolCallId===e||n.id===e))}function Pg(e,t){const n=t.response??t.content;if(!n)return;const r=typeof n=="string"?n:mr(n);if(!r.trim())return;const o=[{type:"text",text:r}];return{id:`tool-${t.id}`,role:"tool",content:o,name:t.name,toolCallId:t.id,artifact:t.artifact,createdAt:e.createdAt}}function di(e,t=[]){if(Array.isArray(e)){const o=e.filter(i=>i.role==="assistant").flatMap(i=>mc(i)),s=new Map;return o.forEach(i=>s.set(i.id,i)),Array.from(s.values()).map(i=>{var f,h,p;const a=ui(i.id,e)||ui(i.id,t),l=Array.isArray((f=a==null?void 0:a.additionalKwargs)==null?void 0:f.toolProgress)?(h=a==null?void 0:a.additionalKwargs)==null?void 0:h.toolProgress:void 0,c=(a==null?void 0:a.artifact)??i.artifact,u=pc(i.status)??((p=a==null?void 0:a.additionalKwargs)!=null&&p.toolStreaming?"pending":null)??(a?"completed":"pending");return{call:i,result:a,state:u,progress:l,artifact:c}})}if(e.role!=="assistant")return[];const n=mc(e);return n.length===0?[]:n.map(r=>{var l,c,u;const o=ui(r.id,t)??Pg(e,r),s=Array.isArray((l=o==null?void 0:o.additionalKwargs)==null?void 0:l.toolProgress)?(c=o==null?void 0:o.additionalKwargs)==null?void 0:c.toolProgress:void 0,i=(o==null?void 0:o.artifact)??r.artifact,a=pc(r.status)??((u=o==null?void 0:o.additionalKwargs)!=null&&u.toolStreaming?"pending":null)??(o?"completed":"pending");return{call:r,result:o,state:a,progress:s,artifact:i}})}function Rg(e,t=[]){return di(e,t).map(n=>n.artifact).filter(n=>!!n)}function Lo(e){return e.map(t=>Mo(t)).filter(t=>!!t)}function $o(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Og(e){let t=!1;const n=e.map(r=>{const o=(r.content??[]).filter(s=>s.type!=="interrupt");return o.length!==r.content.length?(t=!0,{...r,content:o}):r});return t?n:e}function Mg(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function Dg(e,t,n,r){const o={...n};if(r!==null&&typeof r=="number"){if(typeof o.lastSeq=="number"&&r<=o.lastSeq)return{newParts:e,newMeta:o,changed:!1};o.lastSeq=r}const s=t.filter(f=>f.type==="text").map(f=>f.text??"").join(""),i=t.filter(f=>f.type!=="text"),a=o.lastText??Mg(e);let l="",c=e.slice();if(s){const f=Lg(a,s);if(f===""?l="":f===s?l=s:l=f,$g(a,l)&&(l=` ${l}`),l){const h=c[c.length-1];if((h==null?void 0:h.type)==="text"){const p=h.text??"",m={...h,text:p+l};c=[...c.slice(0,c.length-1),m]}else c=[...c,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(c=[...c,...i]);const u=!!(l||i.length);return{newParts:c,newMeta:o,changed:u}}function Lg(e,t){if(!t)return"";if(!e)return t;if(e===t)return"";const n=Math.min(e.length,t.length);for(let r=n;r>0;r--)if(e.slice(-r)===t.slice(0,r))return t.slice(r);return t}function $g(e,t){if(!e||!t)return!1;const n=e.slice(-1),r=t[0];if(!n||!r||/\s/.test(n)||/\s/.test(r))return!1;const o=a=>/[A-Za-z0-9]/.test(a),s=a=>/[A-Za-z]/.test(a);return(a=>/[.,;:!?]/.test(a))(n)&&o(r)||/[A-Z]/.test(r)&&!/[\s\(\[\{]/.test(n)?!0:o(n)&&s(r)}function Fg(e,t,n){for(let r=e.length-1;r>=0;r--)if(e[r].role==="assistant"){const s={...e[r],checkpointId:t,checkpointNs:n??void 0};return $o(e,r,s)}return e}function zg(e){const t=new Map,n=[];return e.slice().sort((r,o)=>{const s=r.createdAt?Date.parse(r.createdAt):0,i=o.createdAt?Date.parse(o.createdAt):0;return s-i}).forEach(r=>{const o=Array.isArray(r.messages)?r.messages:[];for(const s of o)!(s!=null&&s.id)||t.has(s.id)||(t.set(s.id,s),n.push(s))}),n.sort((r,o)=>{const s=r.createdAt?Date.parse(r.createdAt):0,i=o.createdAt?Date.parse(o.createdAt):0;return s-i}),n}const Bg={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,messagesStreamMeta:{},pendingInterrupt:null,values:{}};function Ug(e,t){var n;switch(t.type){case"reset":return{messages:Lo(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,pendingInterrupt:null,messagesStreamMeta:{},values:{}};case"user_message":{const{message:r,editingMessageId:o}=t.payload;if(o){const s=e.messages.findIndex(i=>i.id===o);if(s>=0){const i=e.messages.slice(0,s);return{...e,messages:[...i,r],assemblingId:null}}}return{...e,messages:[...e.messages,r],assemblingId:null}}case"seed":{const r=Lo(t.payload.messages),o={...e,messages:r,assemblingId:null,pendingInterrupt:t.payload.pendingInterrupt??null};return Object.prototype.hasOwnProperty.call(t.payload,"checkpointId")&&(o.lastCheckpointId=t.payload.checkpointId??null),Object.prototype.hasOwnProperty.call(t.payload,"checkpointNs")&&(o.lastCheckpointNs=t.payload.checkpointNs??null),o}case"prepend":{const r=Lo(t.payload.messages);if(!r.length)return e;const o=new Set(e.messages.map(a=>a.id)),s=r.filter(a=>!o.has(a.id));if(!s.length)return e;const i=[...s,...e.messages];return{...e,messages:i}}case"event":return gc(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>gc(o,s),e):e}default:return e}}function Hg(e=[]){const[t,n]=v.useReducer(Ug,{...Bg,messages:e}),r=v.useRef([]),o=v.useRef(null),s=v.useRef(null),i=v.useCallback(()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),o.current=null,s.current=null;const u=r.current;u.length&&(r.current=[],n({type:"batch",payload:{events:u}}))},[]),a=v.useCallback(()=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?o.current===null&&(o.current=window.requestAnimationFrame(()=>i())):s.current===null&&(s.current=setTimeout(i,8))},[i]),l=v.useCallback(u=>{r.current.push(u),a()},[a]);v.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const c=v.useMemo(()=>({reset:u=>n({type:"reset",payload:{messages:u}}),seed:(u,f)=>n({type:"seed",payload:{messages:u,...f??{}}}),prepend:u=>n({type:"prepend",payload:{messages:u}}),pushUser:(u,f)=>n({type:"user_message",payload:{message:u,editingMessageId:f}}),onEvent:l}),[l]);return{state:t,dispatch:n,...c}}function gc(e,t){if(t.type==="tool.start")return Wg(e,t);if(t.type==="tool.progress")return Vg(e,t);if(t.type==="tool.end")return Kg(e,t);if(t.type==="artifact.update")return qg(e,t);if(t.type==="message.start")return{...e,assemblingId:t.id};if(t.type==="message.delta"){const n=e.assemblingId;if(!n)return e;const r=t.delta,o=t.seq,s=e.messages.findIndex(l=>l.id===n);let i=e.messages;const a=r.map(l=>l.text?{type:"text",text:l.text}:l);if(s!==-1){const l=e.messages[s],c=(e.messagesStreamMeta||{})[n]||{},{newParts:u,newMeta:f,changed:h}=Dg(Array.isArray(l.content)?l.content:[],a,c,o);return h?(i=$o(i,s,{...l,content:u}),{...e,messages:i,messagesStreamMeta:{...e.messagesStreamMeta,[n]:f}}):e}else{const l={id:n,role:"assistant",content:a,createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,l],assemblingId:n}}}if(t.type==="message.end")return{...e,assemblingId:null};if(t.type==="checkpoint"){const n=t.checkpointNs??e.lastCheckpointNs??null,r=Fg(e.messages,t.checkpointId,n);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:n,messages:r}}if(t.type==="error"){const n={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,n]}}if(t.type==="state_history"){const n=pr(t),r=n.interrupt,o=n.latest,s=zg(n.checkpoints);let i=s.length?s:o==null?void 0:o.messages;if(i){const a=new Set(i.map(c=>c.id)),l=e.messages.filter(c=>!a.has(c.id));if(l.length&&(i=[...i,...l]),e.assemblingId&&!i.some(c=>c.id===e.assemblingId)){const c=e.messages.find(u=>u.id===e.assemblingId);c&&(i=[...i,c])}i=Lo(i)}else i=r===null?Og(e.messages):e.messages;return{...e,messages:i,pendingInterrupt:r,lastCheckpointId:(o==null?void 0:o.checkpointId)??e.lastCheckpointId,lastCheckpointNs:(o==null?void 0:o.checkpointNs)??e.lastCheckpointNs,values:(o==null?void 0:o.values)??e.values}}return t.type==="thread_info",e}function fi(e){return e.id??void 0}function Fo(e,t){var n;if(!t)return-1;for(let r=e.length-1;r>=0;r--){const o=e[r];if(o.role==="assistant"&&((n=o.toolCalls)!=null&&n.some(s=>s.id===t)))return r}return-1}function hi(e,t,n){const r=Fo(e,t);if(r===-1)return e;const o=e[r],s=(o.toolCalls??[]).map(i=>i.id===t?{...i,...n}:i);return $o(e,r,{...o,toolCalls:s})}function Wg(e,t){const n=fi(t),r=t.name??void 0,o={type:t.type,content:`Starting ${r??"tool"}...`,seq:t.seq??null,timestamp:new Date().toISOString()};let s=e.messages;return n&&Fo(s,n)!==-1&&(s=hi(s,n,{status:"running",content:o.content})),{...e,messages:s}}function Vg(e,t){const n=t.id??fi(t);if(!n)return e;const r=t.content??void 0;let o=e.messages;return Fo(o,n)!==-1&&(o=hi(o,n,{content:r})),{...e,messages:o}}function Kg(e,t){const n=fi(t);let r=e.messages;const o=t.content??t.error??null,s=typeof o=="string"?o:JSON.stringify(o),i=Wr(o),a=typeof i=="string"?i:s;n&&Fo(r,n)!==-1&&(r=hi(r,n,{status:"completed",content:a,artifact:t.artifact}));const l={id:`tool-${n||Date.now()}`,role:"tool",name:t.name??void 0,content:[{type:"text",text:a}],artifact:t.artifact,toolCallId:n??void 0,createdAt:new Date().toISOString()};return{...e,messages:[...r,l]}}function qg(e,t){const n=t.artifactId,r=t.callId,o=Ag(e.messages,n,r);if(!o){const a={id:`artifact-${n}`,role:"tool",name:"artifact_updater",content:[],createdAt:new Date().toISOString(),artifact:{type:"unknown",metadata:{id:n,type:"unknown",createdAt:new Date().toISOString(),status:t.status,progress:t.progress},...t.partial_data}};return{...e,messages:[...e.messages,a]}}const s=e.messages.indexOf(o),i=Ig(o,{status:t.status,progress:t.progress,error:t.error});return t.partial_data&&i.artifact&&(i.artifact={...i.artifact,...t.partial_data}),{...e,messages:$o(e.messages,s,i)}}const xc=120;function Gg(e){if(!Array.isArray(e))return"";const t=e.filter(r=>!!(r&&r.type==="text")).map(r=>(r.text??"").trim()).filter(Boolean);if(!t.length)return"";const n=t.join(" ").replace(/\s+/g," ").trim();return n?n.length>xc?`${n.slice(0,xc-3)}…`:n:""}function Yg(e){return Gg(e.content)||""}function Xg(e){const t=new Map,n=[],r=new Map,o=[];for(let c=0;c<e.length;c++){const u=e[c],f=u.checkpointId,h=f??`cp-${c}`,p=u.metadata??{},m=typeof p.step=="number"?p.step:null,b=typeof p.source=="string"?p.source:null;let g=null,w=null;const y=Array.isArray(u.messages)?u.messages:[];for(const C of y)C.role==="user"&&(w||(w=C),C.id&&(g=C.id));const k=u.next&&u.next.length>0?String(u.next[0]):null,E=u.parentConfig??null,S={id:h,step:m,source:b,createdAt:u.createdAt??null,namespace:u.checkpointNs??null,parentId:u.parentId??null,next:k,parentConfig:E,userMessageId:g};if(o.push(S),f&&t.set(f,S),f&&w){const C=Yg(w);C&&r.set(f,C)}n.push({id:h,messageId:g,step:m,source:b,createdAt:u.createdAt??null,next:k,parentConfig:E})}const s=new Map;for(const c of o){if(!c.userMessageId)continue;const u=s.get(c.userMessageId)??[];u.push(c),s.set(c.userMessageId,u)}for(const c of s.values()){if(!c.length)continue;c.sort((f,h)=>{const p=f.createdAt?Date.parse(f.createdAt):0;return(h.createdAt?Date.parse(h.createdAt):0)-p});const u=c.length;for(let f=0;f<c.length;f++){const h=c[f];h.attemptCount=u,h.attemptIndex=f,h.isLatestAttempt=f===0}}return{checkpoints:e,checkpointMetaByCheckpointId:t,timeline:n,messagePreviews:r,getLatest:()=>{const c=n[0];if(c)return t.get(c.id)},getCheckpoint:c=>t.get(c),getMessageAttempts:c=>{const u=[];for(const f of t.values())f.userMessageId===c&&u.push(f);return u.length?(u.sort((f,h)=>{const p=typeof f.attemptIndex=="number"?f.attemptIndex:Number.MAX_SAFE_INTEGER,m=typeof h.attemptIndex=="number"?h.attemptIndex:Number.MAX_SAFE_INTEGER;return p-m}),u):[]}}}function Jg(e,t,n){if(!e)return{attemptCount:1,attemptIndex:0,attempts:[]};const r=n.getMessageAttempts(e);if(!r.length)return{attemptCount:1,attemptIndex:0,attempts:[]};let o=0;if(t){const s=r.findIndex(i=>i.id===t);s>=0&&(o=s)}return{attemptCount:r.length,attemptIndex:o,attempts:r}}function Zg(e){return v.useMemo(()=>Xg(e),[e])}function bc({api:e,seed:t,onError:n,currentThreadId:r,initialThreadId:o=null,initialCheckpointId:s=null,initialCheckpointNs:i=null,autoLoadInitial:a=!0,isStreaming:l,getMessages:c}){const[u,f]=v.useState(null),p=v.useMemo(()=>pr(u),[u]).checkpoints,m=Zg(p),b=m.timeline,[g,w]=v.useState(!1),[y,k]=v.useState(!1),[E,S]=v.useState(null),C=v.useRef(r),T=v.useRef(null),N=v.useRef(null),j=v.useRef(null),_=v.useRef(null),D=v.useRef(null),z=v.useRef(new Map),H=v.useRef(null);v.useEffect(()=>{C.current=r},[r]);const P=v.useCallback(async A=>{var V,Z;if(!A.threadId)return;const O=A.threadId;(V=A.onStart)==null||V.call(A),A.setLoading(!0);try{await A.action(O)}catch($){if(!ql($)&&C.current===O){const oe=String($);(Z=A.handleError)==null||Z.call(A,oe),n==null||n(oe)}throw $}finally{A.setLoading(!1)}},[n]),M=v.useCallback(async(A,O)=>{var oe;if(!A)return;const V=`${A}:${O??"latest"}`,Z=z.current.get(V);if(Z)return Z;(oe=H.current)==null||oe.abort();const $=new AbortController;H.current=$;const X=P({threadId:A,setLoading:w,onStart:()=>S(null),handleError:ue=>S(ue),action:async ue=>{const le=await e.getStateHistory({threadId:ue,checkpointId:O??void 0,signal:$.signal});if(C.current!==ue){console.log(`[useThreadHistoryState] Thread changed during load (was ${ue}, now ${C.current}), discarding stale data`);return}const{checkpoints:Ce,latest:De}=pr(le),Ie=O?Ce.find(qe=>qe.checkpointId===O)??De:De;t((Ie==null?void 0:Ie.messages)??[],{checkpointId:(Ie==null?void 0:Ie.checkpointId)??null,checkpointNs:(Ie==null?void 0:Ie.checkpointNs)??null,pendingInterrupt:(Ie==null?void 0:Ie.interrupt)??null}),f(le)}});z.current.set(V,X);try{await X}finally{z.current.delete(V),H.current===$&&(H.current=null)}return C.current===A&&(D.current=V),X},[e,t,P]),F=v.useCallback(async(A,O)=>{_.current=A;try{await M(A,O)}catch(V){if(!ql(V))throw V}finally{_.current===A&&(_.current=null)}},[M]),ne=v.useCallback(A=>{N.current=A},[]),U=v.useCallback(A=>{j.current=A},[]),W=v.useCallback(A=>{const O=A.threadId??C.current;if(!O||C.current&&C.current!==O)return;const{checkpoints:V,latest:Z}=pr(A);if(!V.length)return;const $=Z,X=j.current===O;!l&&!X&&t(($==null?void 0:$.messages)??[],{checkpointId:($==null?void 0:$.checkpointId)??null,checkpointNs:($==null?void 0:$.checkpointNs)??null,pendingInterrupt:($==null?void 0:$.interrupt)??null}),f(A),D.current=`${O}:latest`,N.current=null,j.current===O&&(j.current=null)},[t,l]),Y=v.useCallback(async(A,O)=>{const V=C.current;await P({threadId:V,setLoading:k,action:async Z=>{const $=await e.getStateHistory({threadId:Z,checkpointId:A,checkpointNs:O??void 0});if(C.current!==Z)return;const{checkpoints:X}=pr($),oe=X.find(ue=>ue.checkpointId===A&&(O?ue.checkpointNs===O:!0));if(!oe){console.warn("[useThreadHistoryState] Requested checkpoint not found:",{checkpointId:A,checkpointNs:O});return}f($),t(oe.messages??[],{checkpointId:oe.checkpointId??null,checkpointNs:oe.checkpointNs??null})}}).catch(()=>{})},[e,t,P]),q=v.useCallback((A,O)=>{t(c(),{checkpointId:A??null,checkpointNs:O??null})},[c,t]),R=v.useCallback(async()=>{C.current&&await F(C.current)},[F]);v.useEffect(()=>{if(!a||!r||g||l)return;if(N.current===r){N.current=null,T.current=r;return}if(j.current===r){T.current=r;return}if(_.current===r){_.current=null,T.current=r;return}if(T.current===r)return;T.current=r;let A;const O=`${r}:latest`;D.current!==O&&F(r,A)},[a,r,s,i,o,g,l,F]);const G=v.useCallback(()=>{f(null),w(!1),k(!1),S(null),N.current=null,j.current=null,T.current=null,D.current=null,_.current=null},[]);return{threadCheckpoints:p,threadTimeline:b,checkpointIndex:m,isLoadingThread:g,isLoadingCheckpoint:y,threadStateError:E,loadThread:F,navigateToCheckpoint:Y,setCurrentCheckpointId:q,returnToLatest:R,handleStateHistoryEvent:W,markSkipNextLoad:ne,markStreamPendingThread:U,resetHistoryState:G,clearState:G}}function Qg(e,t,n){const r=typeof t=="string"?[{type:"text",text:t}]:t;return{id:`msg-${Date.now()}-${Math.random().toString(36).slice(2,9)}`,role:e,content:r,createdAt:new Date().toISOString(),...n}}function wc(e,t="user"){return typeof e=="string"?Qg(t,e):e}function yc(e){return!!e&&typeof e=="object"&&"data"in e}function ex(e){return e&&e.type==="messages/partial"}let pi={isStreaming:!1};const mi=new Set;function tx(e){pi.isStreaming!==e.isStreaming&&(pi=e,mi.forEach(t=>t()))}function nx(e){return mi.add(e),()=>mi.delete(e)}function rx(){return v.useSyncExternalStore(nx,()=>pi.isStreaming,()=>!1)}function ox(e={}){const t=e.baseUrl||"",n=e.streamPath??"/stream",[r,o]=v.useState(e.token??null),s=v.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=v.useState(!1),[c,u]=v.useState(null),[f,h]=v.useState(""),[p,m]=v.useState(null),[b,g]=v.useState(0),[w,y]=v.useState(!1),[k,E]=v.useState({}),[S,C]=v.useState(null),[T,N]=v.useState({}),j=v.useRef(null),_=v.useRef(!0),D=v.useRef(0),z=v.useRef(null),H=v.useRef(null),P=v.useRef(null),M=v.useRef(null),F=v.useRef({messageId:null,lastSeq:null,lastText:""}),ne=v.useCallback(R=>{o(R)},[]);v.useEffect(()=>{tx({isStreaming:a})},[a]);const U=v.useCallback(()=>{h(""),m(null),u(null),H.current=null,P.current=null,M.current=null,E({}),C(null),N({}),F.current={messageId:null,lastSeq:null,lastText:""}},[]),W=v.useCallback(R=>{var V;console.debug(`[use-chat] stop("${R}") invoked - aborting stream`),console.trace("stop() call stack");const G=(V=z.current)==null?void 0:V.threadId,A=()=>{var Z;(Z=j.current)==null||Z.abort(),j.current=null,z.current=null,l(!1),y(!1),D.current=0,g(0)};(G?Tn.cancelRun(G).catch(Z=>{console.warn("[use-chat] cancel run failed:",Z)}):Promise.resolve()).finally(A)},[]),Y=v.useCallback(R=>W(R??"manual"),[W]),q=v.useCallback((R,G,A)=>{j.current&&(j.current.abort(),j.current=null),l(!0),u(null),e.autoAppendAssistant!==!1&&h(""),m(null),H.current=null,P.current=null,M.current=null,E({}),C(null),N({}),F.current={messageId:null,lastSeq:null,lastText:""};const O=new AbortController;j.current=O;let V=null,Z=null,$=!1;return z.current={threadId:R.threadId??null,headers:{},isStreaming:!0},(async()=>{var X,oe,ue,le,Ce,De,Ie,qe,We,Fe,ze,It,At,bt,wt,ht,st,Nt,jt,Ut;try{let nt={};try{if(r)nt={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const Qe=window.__AUTH_TOKEN__,hn=((X=window.localStorage)==null?void 0:X.getItem(Sn.authToken))||null;let pn=null;try{const yn=(oe=window.localStorage)==null?void 0:oe.getItem(Sn.chatSettings);yn&&(pn=((ue=JSON.parse(yn))==null?void 0:ue.apiKey)||null)}catch{}const Fn=Qe||hn||pn||null;Fn&&(nt={Authorization:`Bearer ${Fn}`})}}catch{}console.debug("[use-chat] POST",t+n);let Ze={};if(typeof window<"u")try{const Ge=(le=window.localStorage)==null?void 0:le.getItem(Sn.authSessionId);Ge&&(Ze={"X-Session-Id":Ge})}catch{}const yt={...nt,...Ze,...s.current},Be={"Content-Type":"application/json",Accept:"text/event-stream",...yt},Le=await fetch(t+n,{method:"POST",headers:Be,body:JSON.stringify(R),signal:O.signal,credentials:i});if(z.current&&(z.current.headers=yt),!Le.ok||!Le.body){const Ge=await Le.text().catch(()=>"");console.debug("[use-chat] non-OK response",Le.status,Ge==null?void 0:Ge.slice(0,500));const Qe=`stream ${Le.status}${Ge?": "+Ge:""}`;throw(Ce=A==null?void 0:A.onConnectionError)==null||Ce.call(A,Qe),$=!0,V="error",Z=Qe,new Error(Qe)}y(!0);const Ht=Le.body.getReader(),or=new TextDecoder;let Wt="",fn=[];D.current=0,g(0);let Vt=0,Lt=null;const it=()=>{if(fn.length){const Ge=fn.join("");fn=[],_.current&&h(Qe=>Qe+Ge)}Lt=null},$n=()=>{typeof window<"u"&&Lt==null&&(Lt=requestAnimationFrame(it))};let Qt=Date.now();const wn=setInterval(()=>{var Ge;if(Date.now()-Qt>18e5){const Qe="Stream idle timeout";u(Qe),V="error",Z=Qe,O.abort(),(Ge=A==null?void 0:A.onError)==null||Ge.call(A,Qe)}},5e3),vo=1024*1024;try{const Ge=Le.headers.get("X-Thread-Id")||Le.headers.get("x-thread-id"),Qe=Le.headers.get("X-Thread-Created")||Le.headers.get("x-thread-created"),hn=Ge??null,pn=String(Qe??"").toLowerCase()==="true";for(z.current&&!z.current.threadId&&(z.current={...z.current,threadId:hn}),(De=A==null?void 0:A.onOpen)==null||De.call(A,{threadId:hn,created:pn});;){const{value:Fn,done:yn}=await Ht.read();if(yn)break;Wt+=or.decode(Fn,{stream:!0}),Wt.length>vo&&(Wt="",console.warn("Stream buffer reset: exceeded 1MB"));let vn;for(;(vn=Wt.indexOf(`
38
38
 
39
- `))>=0;){const or=$t.slice(0,Bn);$t=$t.slice(Bn+2);const sr=or.split(/\r?\n/),ir=[];let Cn=null;for(const _ of sr){if(_.startsWith(":")){_.startsWith(": heartbeat")&&console.debug("[use-chat] SSE heartbeat comment received");continue}if(_){if(_.startsWith("event:")){const Z=_.slice(6).trim();Z&&(Cn=Z);continue}if(_.startsWith("data:")){const Z=_.slice(5);ir.push(Z.startsWith(" ")?Z.slice(1):Z)}}}const ar=ir.join(`
40
- `);if(!ar)continue;let zt;try{zt=JSON.parse(ar)}catch{console.debug("[use-chat] malformed SSE:",ar.slice(0,200));continue}if(Cn&&typeof zt=="object"&&zt!==null){const _=zt;"type"in _||(_.type=Cn)}const I=yc(zt)?zt.data:zt;if(!I){console.warn("[use-chat] dropped envelope event without payload",zt);continue}const K=cg(I);yn=Date.now();const oe=typeof K.seq=="number"?K.seq:void 0;if(oe!==void 0){if(oe<=Vt){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:oe,lastProcessedSeq:Vt,type:K.type});continue}Vt>0&&oe>Vt+1&&((Me=P==null?void 0:P.onGap)==null||Me.call(P,{from:Vt,to:oe})),Vt=oe,L.current=oe,g(oe)}if(K.type==="checkpoint")W.current=K.checkpointId??null,O.current=K.checkpointNs??null,m(K.checkpointId??null);else if(K.type==="state_history"){const _=K;D.current=_;try{const ie=mr(_).latest;ie&&(W.current=ie.checkpointId??null,O.current=ie.checkpointNs??null,m(ie.checkpointId??null),A(ie.values??{}))}catch(Z){console.warn("[use-chat] Failed to hydrate state_history payload",Z)}}try{M==null||M(K)}catch(_){console.error("[use-chat] Error in onEvent callback:",_,"for event:",K.type)}try{K.type==="tool.start"&&(P!=null&&P.onToolStart)?P.onToolStart(K):K.type==="tool.end"&&(P!=null&&P.onToolEnd)?P.onToolEnd(K):K.type==="updates"&&(P!=null&&P.onUpdateEvent)?P.onUpdateEvent(K):K.type==="custom"&&(P!=null&&P.onCustomEvent)?P.onCustomEvent(K):K.type==="thread_info"&&(P!=null&&P.onThreadInfoEvent)&&P.onThreadInfoEvent(K)}catch(_){console.warn("[use-chat] Typed callback error:",_)}if(ex(K)){const{messages:_}=K;if(_.length>0){const Z=_.find(se=>se.type==="ai"),ie=_.find(se=>se.type==="tool");if(Z){const se=Z.id,xe=Z.content??"";if(z.current.messageId!==se){const Ne=Z.name??((Ie=Z.additionalKwargs)==null?void 0:Ie.agentName)??"assistant";z.current={messageId:se,lastSeq:null,lastText:""};const Ce=Mo({id:se,role:"assistant",name:Ne,model:Ne,createdAt:new Date().toISOString(),content:[{type:"text",text:xe}]});E(ge=>({...ge,[se]:Ce})),C(se)}else E(Ne=>{const Ce=Ne[se];return Ce?{...Ne,[se]:{...Ce,content:[{type:"text",text:xe}]}}:Ne});const De=z.current.lastText||"";if(xe.length>De.length){const Ne=xe.slice(De.length);z.current.lastText=xe,e.autoAppendAssistant!==!1&&(bn.push(Ne),pt())}}if(ie){const se=ie.id||`tool-${Date.now()}`,xe=Mo({id:se,role:"tool",content:ie.content??"",createdAt:new Date().toISOString()});E(De=>({...De,[se]:xe}))}}}else if(K.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(Ke=P==null?void 0:P.onHeartbeat)==null||Ke.call(P,K)}catch(_){console.warn("[use-chat] heartbeat callback failed",_)}}else if(Ft!==null&&cancelAnimationFrame(Ft),wn(),K.type==="checkpoint")m(K.checkpointId??null);else if(K.type==="error"){const _=K;if(u(_.message),R="error",G=_.message,_.error_type==="auth_error"||_.code==="TOKEN_EXPIRED"||((He=_.message)==null?void 0:He.includes("token"))||((Fe=_.message)==null?void 0:Fe.includes("401"))||((ze=_.message)==null?void 0:ze.includes("unauthorized"))||((It=_.message)==null?void 0:It.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",_.message);try{(At=P==null?void 0:P.onAuthError)==null||At.call(P,_.message)}catch(ie){console.warn("[use-chat] onAuthError handler failed",ie)}$.abort()}}}}wn(),R===null&&!$.signal.aborted&&(R="complete")}catch(Xe){if(Xe.name==="AbortError")R=R??"aborted";else{const Ze=Xe.message||String(Xe);R="error",G=Ze,u(Ze),(wt=P==null?void 0:P.onError)==null||wt.call(P,Ze)}}finally{try{await Ye.cancel()}catch{}finally{(yt=Ye.releaseLock)==null||yt.call(Ye)}Ft!==null&&typeof window<"u"&&window.cancelAnimationFrame(Ft),clearInterval(dn)}}catch(rt){if(rt.name==="AbortError")R=R??"aborted";else{const tt=rt.message||String(rt);R="error",G=tt,u(tt),(ht=P==null?void 0:P.onError)==null||ht.call(P,tt),te||((st=P==null?void 0:P.onConnectionError)==null||st.call(P,tt),te=!0)}}finally{const rt=L.current,tt=W.current,it=O.current,_t=D.current,Ae=R??($.signal.aborted?"aborted":G?"error":"complete");try{(Nt=P==null?void 0:P.onClosed)==null||Nt.call(P,{reason:Ae,lastSeq:rt,lastCheckpointId:tt,lastCheckpointNs:it,lastStateHistory:_t,error:G}),Ae==="complete"&&((jt=P==null?void 0:P.onFinish)==null||jt.call(P,{lastSeq:rt,lastCheckpointId:tt,lastCheckpointNs:it,lastStateHistory:_t}))}catch(Ye){console.warn("[use-chat] onClosed callback failed",Ye)}l(!1),y(!1),N.current=null,L.current=0,g(0),B.current=null}})(),{close:()=>$.abort()}},[t,n,r,e.autoAppendAssistant]);return v.useEffect(()=>()=>{var q;j.current=!1,(q=N.current)==null||q.abort()},[]),{isStreaming:a,error:c,assistantText:f,activeMessageId:S,streamedMessages:k,lastCheckpointId:p,lastSeq:b,connected:w,stream:Y,stop:V,clear:H,setToken:ee,values:T,interrupt:()=>Promise.resolve(),resume:()=>Promise.resolve(),goto:()=>Promise.resolve()}}const vc=v.createContext(null);function sx({options:e,children:t}){return v.createElement(vc.Provider,{value:e},t)}function ix(){return v.useContext(vc)||{}}const Sc=v.createContext(null);function ax({children:e}){const{baseUrl:t}=hr(),n=ix(),r=ox({...n,baseUrl:t});return d.jsx(Sc.Provider,{value:r,children:e})}function lx(){const e=v.useContext(Sc);if(!e)throw new Error("useStream must be used within a StreamStateProvider");return e}async function Cc(e){return await new Promise((t,n)=>{const r=new FileReader;r.onload=()=>{try{const o=r.result,s=new Uint8Array(o);let i="";const a=s.byteLength;for(let l=0;l<a;l++)i+=String.fromCharCode(s[l]);t(btoa(i))}catch(o){n(o)}},r.onerror=o=>n(o),r.readAsArrayBuffer(e)})}async function Tc(e=[]){const t=[],n=[];for(const r of e)try{const o=await Cc(r),s=r.type||"application/octet-stream";n.push({filename:r.name,data:o,mime_type:s}),s.startsWith("image/")?t.push({type:"image_url",image_url:{url:`data:${s};base64,${o}`}}):t.push({type:"file",url:`data:${s};base64,${o}`,mimeType:s,name:r.name,size:r.size})}catch{}return{contentParts:t,filesInfo:n}}function kc(e,t){if(!e)return null;const n=Kn(e);if(!n)return null;const r=Kn(n.configurable)??n;return Wr(r,t)??null}function cx(e){const t=kc(e,["checkpoint_id","checkpointId"]);if(!t)return null;const n=kc(e,["checkpoint_ns","checkpointNs"]);return{checkpointId:t,checkpointNs:n}}function ux(e,t){const n=typeof e.step=="number"?e.step:Number.POSITIVE_INFINITY,r=typeof t.step=="number"?t.step:Number.POSITIVE_INFINITY;if(n!==r)return n-r;const o=e.createdAt?Date.parse(e.createdAt):0,s=t.createdAt?Date.parse(t.createdAt):0;return o-s}function dx(e,t){const n=[...e].sort(ux);for(const r of n){if(r.messageId!==t)continue;const o=cx(r.parentConfig);if(!o)throw new Error(`Parent checkpoint info missing for message ${t}`);return o}throw new Error(`Message ${t} not found in timeline`)}function Ec(){const{stream:e,stop:t,clear:n,isStreaming:r,error:o,connected:s,streamedMessages:i}=lx(),{setCurrentThreadId:a,currentThreadIdRef:l,addThreadFromEvent:c,currentThreadId:u}=Hr(),{interrupt:f,checkpoint:h,timelineCheckpoints:p,handleStateHistoryEvent:m,markSkipNextLoad:b,markStreamPendingThread:g,resetHistoryState:w,pushUser:y,onEvent:k,messages:E}=qr(),{registerClearThread:S,registerRespondToInterrupt:C}=jc();v.useEffect(()=>{u!==void 0&&n()},[u,n]);const T=v.useCallback(D=>{c(D),l.current!==D.threadId&&((D.created??!l.current)&&b(D.threadId),g(D.threadId),a(D.threadId))},[c,b,g,a,l]),A=v.useCallback(D=>{D.type==="thread_info"?T(D):D.type==="state_history"?m(D):(D.type,k(D))},[T,m,k]),N=v.useCallback((D,z)=>{e(D,ee=>{A(ee),z==null||z(ee)},{})},[e,A]),j=v.useRef(h);v.useEffect(()=>{j.current=h},[h]);const L=v.useCallback(async(D,z,ee)=>{const H=l.current;if(!H)throw new Error("No active thread to handle interrupt");const V=D?z??!0:!1,Y=j.current,q={threadId:H,checkpointId:Y.id??void 0,checkpointNs:Y.namespace??void 0,command:{kind:"resume",value:V},payload:ee==null?void 0:ee.payload};N(q)},[l,N]);v.useEffect(()=>{C(L)},[L,C]);const B=v.useCallback(async()=>{t(),n(),w(),a(null)},[n,w,a,t]);v.useEffect(()=>{S(B)},[B,S]);const W=v.useCallback(async(D,z)=>{r&&t();let ee=l.current;const H=(D==null?void 0:D.text)??"",V=(D==null?void 0:D.attachments)??[],Y=(H==null?void 0:H.trim())??"",q={...(D==null?void 0:D.payload)??{}},M=Array.isArray(q.messages)?q.messages:void 0;M&&delete q.messages;const P=!!(M&&M.length),$=!!(D.contentParts&&D.contentParts.length>0);if(!ee&&!Y&&V.length===0&&!P&&!$)return;if(!ee){const Fe=Math.floor(Date.now()/1e3).toString(16).padStart(8,"0"),ze=Array.from({length:4},()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0")).join("").slice(0,16);ee=`${Fe}${ze}`,b(ee),a(ee)}let R=null;D.contentParts&&D.contentParts.length>0&&(R=D.contentParts);const{contentParts:G,filesInfo:te}=R?{contentParts:R,filesInfo:[]}:await Tc(V),F=[...G];Y&&F.push({type:"text",text:H});const X=z==null?void 0:z.originalMessageId,re=!!(z!=null&&z.edit&&X),ue=!P&&F.length>0;let le=null;if(ue){const Fe=re?X:`msg-${Date.now()}`;le=wc({id:Fe,role:"user",content:F,createdAt:new Date().toISOString()},"user"),re?y(le,{editingMessageId:X}):y(le)}const Se=P?M:le?[le]:[],Me={...q,...te.length?{files_info:te}:{}};Se.length?Me.messages=Se:"messages"in Me||(Me.messages=[]);let Ie=(z==null?void 0:z.checkpointId)??h.id??void 0,Ke=(z==null?void 0:z.checkpointNs)??h.namespace??void 0;if(re&&X){const Fe=dx(p,X);Ie=Fe.checkpointId,Ke=Fe.checkpointNs??void 0}const He={threadId:ee,payload:Me,checkpointId:Ie,checkpointNs:Ke,config:z==null?void 0:z.config,edit:!!(z!=null&&z.edit)};N(He,z==null?void 0:z.onEvent)},[h,l,r,b,y,N,t,p]),O=v.useMemo(()=>{if(!r||Object.keys(i).length===0)return E;const D=[...E];return Object.values(i).forEach(z=>{const ee=D.findIndex(H=>H.id===z.id);ee>=0?D[ee]=z:D.push(z)}),D},[r,i,E]);return{isStreaming:r,error:o,connectionState:o?"error":r?s?"connected":"connecting":"idle",messages:O,submit:W,stop:t,interrupt:f,resume:()=>Promise.resolve(),goto:(D,z)=>Promise.resolve(),clearError:()=>{}}}function fx(){return!0}function Ic(e){const t=e.artifact&&typeof e.artifact=="object"?e.artifact:null,n=!t&&e.content&&typeof e.content=="object"?e.content:null,r=t??n,o=(r==null?void 0:r.task_id)??(r==null?void 0:r.taskId)??null;return typeof o=="string"?o:null}function hx(e){const{setCurrentTaskId:t,getCurrentTaskId:n,onToolEnd:r}=e;return o=>{const s=Ic(o),i=(n==null?void 0:n())??null;s&&s!==i&&t(s),r==null||r(o)}}const Ac=v.createContext(null),Nc=v.createContext(null);function qr(){const e=v.useContext(Ac);if(!e)throw new Error("useThreadState must be used within a ThreadStateProvider");return e}function jc(){const e=v.useContext(Nc);if(!e)throw new Error("useThreadStateUpdater must be used within a ThreadStateProvider");return e}function _c({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,onError:s}){const{chatApi:i}=hr(),{currentThreadId:a}=Hr(),l=rx(),{state:c,seed:u,onEvent:f,dispatch:h}=Hg(),{threadCheckpoints:p,threadTimeline:m,checkpointIndex:b,isLoadingThread:g,isLoadingCheckpoint:w,threadStateError:y,loadThread:k,navigateToCheckpoint:E,setCurrentCheckpointId:S,returnToLatest:C,handleStateHistoryEvent:T,markSkipNextLoad:A,markStreamPendingThread:N,resetHistoryState:j}=bc({api:i,seed:u,onError:s,currentThreadId:a,initialThreadId:t,initialCheckpointId:n,initialCheckpointNs:r,autoLoadInitial:o,isStreaming:l,getMessages:v.useCallback(()=>c.messages,[c.messages])});v.useEffect(()=>{a||(u([],{}),j())},[a,u,j]);const L=v.useRef(null),B=v.useCallback(q=>{L.current=q},[]),W=v.useRef(null),O=v.useCallback(q=>{W.current=q},[]),D=v.useMemo(()=>({assemblingMessageId:c.assemblingId??null}),[c.assemblingId]),z=v.useCallback((q,M)=>{const P=wc(q,"user");return h({type:"user_message",payload:{message:P,editingMessageId:M==null?void 0:M.editingMessageId}}),P},[h]),ee=v.useCallback(async()=>{L.current?await L.current():(u([],{}),j())},[u,j]),H=v.useMemo(()=>Tg(c.messages),[c.messages]),V=v.useMemo(()=>({threadId:a,messages:c.messages,interrupt:c.pendingInterrupt,checkpoint:{id:c.lastCheckpointId??null,namespace:c.lastCheckpointNs??null},checkpoints:p,checkpointIndex:b,timelineCheckpoints:m,metadata:D,values:c.values??{},isLoading:g,isLoadingCheckpoint:w,error:y,loadOlder:async()=>{},seedFromSnapshot:q=>{u(q.messages,{checkpointId:q.checkpointId,checkpointNs:q.checkpointNs,pendingInterrupt:q.interrupt})},clearState:ee,navigateToCheckpoint:E,setCurrentCheckpointId:S,returnToLatest:C,loadThread:async(q,M,P)=>{await k(q,M,{clearProgress:!1})},clearThread:ee,respondToInterrupt:async(q,M,P)=>{W.current&&await W.current(q,M,P)},messagePreviews:b.messagePreviews,handleStateHistoryEvent:T,markSkipNextLoad:A,markStreamPendingThread:N,resetHistoryState:j,pushUser:z,onEvent:f,artifacts:H}),[a,c.messages,c.pendingInterrupt,c.lastCheckpointId,c.lastCheckpointNs,c.values,p,m,b,D,g,w,y,u,ee,E,S,C,k,T,A,N,z,f,H]),Y=v.useMemo(()=>({registerClearThread:B,registerRespondToInterrupt:O}),[B,O]);return d.jsx(Nc.Provider,{value:Y,children:d.jsx(Ac.Provider,{value:V,children:e})})}const Pc=v.createContext(null);function Rc({children:e,...t}){return d.jsx(Pc.Provider,{value:t,children:e})}function zo(){const e=v.useContext(Pc);if(!e)throw new Error("useChatUI must be used within a ChatUIProvider");return e}function Oc(e){return typeof e=="object"&&e!==null}function px(e,t){if(Object.is(e,t))return!0;if(!Oc(e)||!Oc(t))return!1;const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const o of n)if(!Object.prototype.hasOwnProperty.call(t,o)||!Object.is(e[o],t[o]))return!1;return!0}function Mc(e){const t=v.useRef(e),n=v.useRef(e);return px(t.current,e)||(t.current=e,n.current=e),n.current}function Gr({children:e,apiConfig:t,initialThreadId:n=null,initialCheckpointId:r=null,initialCheckpointNs:o=null,autoLoadInitial:s=!0,onError:i,onThreadChange:a,onFinish:l,onAuthError:c,onConnectionError:u,onToolEnd:f,onThreadInfoEvent:h,onToolStart:p,onUpdateEvent:m,onCustomEvent:b,onEvent:g}){const w=Mc(t),y=qt(i),k=qt(a),E=qt(l),S=qt(c),C=qt(u),T=qt(f),A=qt(h),N=qt(p),j=qt(m),L=qt(b),B=qt(g),W=v.useMemo(()=>({onError:y,onAuthError:S,onConnectionError:C,onToolEnd:T,onToolStart:N,onEvent:B,onUpdateEvent:j,onCustomEvent:L,onThreadInfoEvent:A,onFinish:E}),[y,S,C,T,N,B,j,L,A,E]);return d.jsx(nc,{apiConfig:w,children:d.jsx(sx,{options:W,children:d.jsx(ax,{children:d.jsx(sc,{initialThreadId:n,onError:y,onThreadChange:k,children:d.jsx(_c,{initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:y,children:e})})})})})}function qt(e){const t=v.useRef(e);return t.current=e,v.useCallback((...n)=>{const r=t.current;if(r)return r(...n)},[])}function br(e){if(!(typeof globalThis>"u"))return globalThis[e]}function Dc(){const e=[br("__API_BASE_URL__"),br("__CHAT_API_BASE_URL__"),br("__CHAT_API_URL__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim().replace(/\/+$/,"")}function Lc(){const e=[br("__API_AUTH_TOKEN__"),br("__CHAT_API_KEY__"),br("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function $c(...e){for(const t of e)if(typeof t=="string"&&t.trim())return t.trim().replace(/\/+$/,"");return""}function Fc(){const e={},t=Dc(),n=Lc();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function zc(){const e=Fc(),t=En.getAuthToken(),n=Dc();return{apiBaseUrl:$c(e.baseUrl,n),apiKey:t||e.apiKey||Lc()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const gi=Tn.chatSettings;function Bc(){try{const e=localStorage.getItem(gi);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function Uc(e){try{const t={...e,apiBaseUrl:e.apiBaseUrl.trim().replace(/\/+$/,"")};localStorage.setItem(gi,JSON.stringify(t)),t.apiKey&&En.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function mx(){const e=zc(),t=Bc(),n=En.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:$c(En.baseUrl,r,e.apiBaseUrl)}}function gx(e){En.updateConfig({baseUrl:e.apiBaseUrl,apiKey:e.apiKey??void 0}),Uc(e)}function fe(...e){return Un.twMerge(vt.clsx(e))}const xx=jp.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"}}),Je=x.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?cr.Slot:"button";return d.jsx(i,{className:fe(xx({variant:t,size:n,className:e})),ref:s,...o})});Je.displayName="Button";const Bo=0,An=1,wr=2,Hc=4;function Wc(e){return()=>e}function bx(e){e()}function Vc(e,t){return n=>e(t(n))}function Kc(e,t){return()=>e(t)}function wx(e,t){return n=>e(t,n)}function xi(e){return e!==void 0}function yx(...e){return()=>{e.map(bx)}}function yr(){}function Uo(e,t){return t(e),e}function vx(e,t){return t(e)}function We(...e){return e}function Oe(e,t){return e(An,t)}function ke(e,t){e(Bo,t)}function bi(e){e(wr)}function et(e){return e(Hc)}function de(e,t){return Oe(e,wx(t,Bo))}function Gt(e,t){const n=e(An,r=>{n(),t(r)});return n}function qc(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Gc(e,t){return e===t}function Ve(e=Gc){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function we(e){return t=>n=>{e(n)&&t(n)}}function ae(e){return t=>Vc(t,e)}function en(e){return t=>()=>{t(e)}}function Q(e,...t){const n=Sx(...t);return(r,o)=>{switch(r){case wr:bi(e);return;case An:return Oe(e,n(o))}}}function tn(e,t){return n=>r=>{n(t=e(t,r))}}function qn(e){return t=>n=>{e>0?e--:t(n)}}function mn(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Ee(...e){const t=new Array(e.length);let n=0,r=null;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Oe(s,l=>{const c=n;n=n|a,t[i]=l,c!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function Sx(...e){return t=>e.reduceRight(vx,t)}function Cx(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case An:return s?n===s?void 0:(r(),n=s,t=Oe(e,s),t):(r(),yr);case wr:r(),n=null;return}}}function ne(e){let t=e;const n=_e();return(r,o)=>{switch(r){case Bo:t=o;break;case An:{o(t);break}case Hc:return t}return n(r,o)}}function ct(e,t){return Uo(ne(t),n=>de(e,n))}function _e(){const e=[];return(t,n)=>{switch(t){case Bo:e.slice().forEach(r=>{r(n)});return;case wr:e.splice(0,e.length);return;case An:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Pt(e){return Uo(_e(),t=>de(e,t))}function Re(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:Tx(),singleton:n}}const Tx=()=>Symbol();function kx(e){const t=new Map,n=({constructor:r,dependencies:o,id:s,singleton:i})=>{if(i&&t.has(s))return t.get(s);const a=r(o.map(l=>n(l)));return i&&t.set(s,a),a};return n(e)}function nt(...e){const t=_e(),n=new Array(e.length);let r=0;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Oe(s,l=>{n[i]=l,r=r|a,r===o&&ke(t,n)})}),function(s,i){switch(s){case wr:{bi(t);return}case An:return r===o&&i(n),Oe(t,i)}}}function be(e,t=Gc){return Q(e,Ve(t))}function wi(...e){return function(t,n){switch(t){case wr:return;case An:return yx(...e.map(r=>Oe(r,n)))}}}var kt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(kt||{});const Ex={0:"debug",3:"error",1:"log",2:"warn"},Ix=()=>typeof globalThis>"u"?window:globalThis,Nn=Re(()=>{const e=ne(3);return{log:ne((t,n,r=1)=>{var o;const s=(o=Ix().VIRTUOSO_LOG_LEVEL)!=null?o:et(e);r>=s&&console[Ex[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function Gn(e,t,n){return yi(e,t,n).callbackRef}function yi(e,t,n){const r=v.useRef(null);let o=i=>{};const s=v.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const a=()=>{const l=i[0].target;l.offsetParent!==null&&e(l)};n?a():requestAnimationFrame(a)}):null,[e,n]);return o=i=>{i&&t?(s==null||s.observe(i),r.current=i):(r.current&&(s==null||s.unobserve(r.current)),r.current=null)},{callbackRef:o,ref:r}}function Ax(e,t,n,r,o,s,i,a,l){const c=v.useCallback(u=>{const f=Nx(u.children,t,a?"offsetWidth":"offsetHeight",o);let h=u.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const p=h.lastElementChild.dataset.viewportType==="window";let m;p&&(m=h.ownerDocument.defaultView);const b=i?a?i.scrollLeft:i.scrollTop:p?a?m.scrollX||m.document.documentElement.scrollLeft:m.scrollY||m.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,g=i?a?i.scrollWidth:i.scrollHeight:p?a?m.document.documentElement.scrollWidth:m.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,w=i?a?i.offsetWidth:i.offsetHeight:p?a?m.innerWidth:m.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:g,scrollTop:Math.max(b,0),viewportHeight:w}),s==null||s(a?Yc("column-gap",getComputedStyle(u).columnGap,o):Yc("row-gap",getComputedStyle(u).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return yi(c,n,l)}function Nx(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const l=parseInt(a.dataset.index),c=parseFloat(a.dataset.knownSize),u=t(a,n);if(u===0&&r("Zero-sized element, this should not happen",{child:a},kt.ERROR),u===c)continue;const f=s[s.length-1];s.length===0||f.size!==u||f.endIndex!==l-1?s.push({endIndex:l,size:u,startIndex:l}):s[s.length-1].endIndex++}return s}function Yc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,kt.WARN),t==="normal"?0:parseInt(t??"0",10)}function Xc(e,t,n){const r=v.useRef(null),o=v.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const c=l.getBoundingClientRect(),u=c.width;let f,h;if(t){const p=t.getBoundingClientRect(),m=c.top-p.top;h=p.height-Math.max(0,m),f=m+t.scrollTop}else{const p=i.current.ownerDocument.defaultView;h=p.innerHeight-Math.max(0,c.top),f=c.top+p.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:u},e(r.current)},[e,t]),{callbackRef:s,ref:i}=yi(o,!0,n),a=v.useCallback(()=>{o(i.current)},[o,i]);return v.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const c=new ResizeObserver(()=>{requestAnimationFrame(a)});return c.observe(t),()=>{t.removeEventListener("scroll",a),c.unobserve(t)}}else{const c=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return c==null||c.addEventListener("scroll",a),c==null||c.addEventListener("resize",a),()=>{c==null||c.removeEventListener("scroll",a),c==null||c.removeEventListener("resize",a)}}},[a,t,i]),s}const xt=Re(()=>{const e=_e(),t=_e(),n=ne(0),r=_e(),o=ne(0),s=_e(),i=_e(),a=ne(0),l=ne(0),c=ne(0),u=ne(0),f=_e(),h=_e(),p=ne(!1),m=ne(!1),b=ne(!1);return de(Q(e,ae(({scrollTop:g})=>g)),t),de(Q(e,ae(({scrollHeight:g})=>g)),i),de(t,o),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:u,headerHeight:a,horizontalDirection:m,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:b,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Yr={lvl:0};function Jc(e,t){const n=e.length;if(n===0)return[];let{index:r,value:o}=t(e[0]);const s=[];for(let i=1;i<n;i++){const{index:a,value:l}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=l}return s.push({end:1/0,start:r,value:o}),s}function Be(e){return e===Yr}function Xr(e,t){if(!Be(e))return t===e.k?e.v:t<e.k?Xr(e.l,t):Xr(e.r,t)}function Yt(e,t,n="k"){if(Be(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=Yt(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return Yt(e.l,t,n)}function Rt(e,t,n){return Be(e)?eu(t,n,1):t===e.k?ot(e,{k:t,v:n}):t<e.k?tu(ot(e,{l:Rt(e.l,t,n)})):tu(ot(e,{r:Rt(e.r,t,n)}))}function vr(){return Yr}function Ho(e,t,n){if(Be(e))return[];const r=Yt(e,t)[0];return jx(Si(e,r,n))}function vi(e,t){if(Be(e))return Yr;const{k:n,l:r,r:o}=e;if(t===n){if(Be(r))return o;if(Be(o))return r;{const[s,i]=Qc(r);return Wo(ot(e,{k:s,l:Zc(r),v:i}))}}else return t<n?Wo(ot(e,{l:vi(r,t)})):Wo(ot(e,{r:vi(o,t)}))}function Yn(e){return Be(e)?[]:[...Yn(e.l),{k:e.k,v:e.v},...Yn(e.r)]}function Si(e,t,n){if(Be(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(Si(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(Si(s,t,n))),a}function Wo(e){const{l:t,lvl:n,r}=e;if(r.lvl>=n-1&&t.lvl>=n-1)return e;if(n>r.lvl+1){if(Ci(t))return nu(ot(e,{lvl:n-1}));if(!Be(t)&&!Be(t.r))return ot(t.r,{l:ot(t,{r:t.r.l}),lvl:n,r:ot(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(Ci(e))return Ti(ot(e,{lvl:n-1}));if(!Be(r)&&!Be(r.l)){const o=r.l,s=Ci(o)?r.lvl-1:r.lvl;return ot(o,{l:ot(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:Ti(ot(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function ot(e,t){return eu(t.k!==void 0?t.k:e.k,t.v!==void 0?t.v:e.v,t.lvl!==void 0?t.lvl:e.lvl,t.l!==void 0?t.l:e.l,t.r!==void 0?t.r:e.r)}function Zc(e){return Be(e.r)?e.l:Wo(ot(e,{r:Zc(e.r)}))}function Ci(e){return Be(e)||e.lvl>e.r.lvl}function Qc(e){return Be(e.r)?[e.k,e.v]:Qc(e.r)}function eu(e,t,n,r=Yr,o=Yr){return{k:e,l:r,lvl:n,r:o,v:t}}function tu(e){return Ti(nu(e))}function nu(e){const{l:t}=e;return!Be(t)&&t.lvl===e.lvl?ot(t,{r:ot(e,{l:t.r})}):e}function Ti(e){const{lvl:t,r:n}=e;return!Be(n)&&!Be(n.r)&&n.lvl===t&&n.r.lvl===t?ot(n,{l:ot(e,{r:n.l}),lvl:t+1}):e}function jx(e){return Jc(e,({k:t,v:n})=>({index:t,value:n}))}function ru(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Jr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const ki=Re(()=>({recalcInProgress:ne(!1)}),[],{singleton:!0});function ou(e,t,n){return e[Vo(e,t,n)]}function Vo(e,t,n,r=0){let o=e.length-1;for(;r<=o;){const s=Math.floor((r+o)/2),i=e[s],a=n(i,t);if(a===0)return s;if(a===-1){if(o-r<2)return s-1;o=s-1}else{if(o===r)return s;r=s+1}}throw new Error(`Failed binary finding record in array - ${e.join(",")}, searched for ${t}`)}function _x(e,t,n,r){const o=Vo(e,t,r),s=Vo(e,n,r,o);return e.slice(o,s+1)}function jn(e,t){return Math.round(e.getBoundingClientRect()[t])}function Ko(e){return!Be(e.groupOffsetTree)}function Ei({index:e},t){return t===e?0:t<e?-1:1}function Px(){return{groupIndices:[],groupOffsetTree:vr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:vr()}}function Rx(e,t){let n=Be(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),Be(e)){e=Rt(e,0,s);continue}const a=Ho(e,i-1,o+1);if(a.some(zx(r)))continue;let l=!1,c=!1;for(const{end:u,start:f,value:h}of a)l?(o>=f||s===h)&&(e=vi(e,f)):(c=h!==s,l=!0),u>o&&o>=f&&h!==s&&(e=Rt(e,o+1,h));c&&(e=Rt(e,i,s))}return[e,n]}function Ox(e){return typeof e.groupIndex<"u"}function Mx({offset:e},t){return t===e?0:t<e?-1:1}function Zr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=ou(t,e,Ei),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function su(e,t){if(!Ko(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function iu(e,t,n){if(Ox(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=su(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function Dx(e,t,n,r=0){return r>0&&(t=Math.max(t,ou(e,r,Ei).offset)),Jc(_x(e,t,n,Mx),Fx)}function Lx(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,kt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&Be(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((m,b)=>Rt(Rt(m,b,h),b+1,p),i)}else[i,a]=Rx(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:u,offsetTree:f}=Ii(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>Rt(h,p,Zr(p,f,o)),vr()),lastIndex:l,lastOffset:c,lastSize:u,offsetTree:f,sizeTree:i}}function $x(e){return Yn(e).map(({k:t,v:n},r,o)=>{const s=o[r+1];return{endIndex:s?s.k-1:1/0,size:n,startIndex:t}})}function au(e,t){let n=0,r=0;for(;n<e;)n+=t[r+1]-t[r]-1,r++;return r-(n===e?0:1)}function Ii(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=Vo(o,t-1,Ei),a=o[l].offset;const c=Yt(n,t-1);s=c[0],i=c[1],o.length&&o[l].size===Yt(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:c,value:u}of Ho(n,t,1/0)){const f=c-s,h=f*i+a+f*r;o.push({index:c,offset:h,size:u}),s=c,a=h,i=u}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function Fx(e){return{index:e.index,value:e}}function zx(e){const{endIndex:t,size:n,startIndex:r}=e;return o=>o.start===r&&(o.end===t||o.end===1/0)&&o.value===n}const Bx={offsetHeight:"height",offsetWidth:"width"},nn=Re(([{log:e},{recalcInProgress:t}])=>{const n=_e(),r=_e(),o=ct(r,0),s=_e(),i=_e(),a=ne(0),l=ne([]),c=ne(void 0),u=ne(void 0),f=ne((S,C)=>jn(S,Bx[C])),h=ne(void 0),p=ne(0),m=Px(),b=ct(Q(n,Ee(l,e,p),tn(Lx,m),Ve()),m),g=ct(Q(l,Ve(),tn((S,C)=>({current:C,prev:S.current}),{current:[],prev:[]}),ae(({prev:S})=>S)),[]);de(Q(l,we(S=>S.length>0),Ee(b,p),ae(([S,C,T])=>{const A=S.reduce((N,j,L)=>Rt(N,j,Zr(j,C.offsetTree,T)||L),vr());return{...C,groupIndices:S,groupOffsetTree:A}})),b),de(Q(r,Ee(b),we(([S,{lastIndex:C}])=>S<C),ae(([S,{lastIndex:C,lastSize:T}])=>[{endIndex:C,size:T,startIndex:S}])),n),de(c,u);const w=ct(Q(c,ae(S=>S===void 0)),!0);de(Q(u,we(S=>S!==void 0&&Be(et(b).sizeTree)),ae(S=>[{endIndex:0,size:S,startIndex:0}])),n);const y=Pt(Q(n,Ee(b),tn(({sizes:S},[C,T])=>({changed:T!==S,sizes:T}),{changed:!1,sizes:m}),ae(S=>S.changed)));Oe(Q(a,tn((S,C)=>({diff:S.prev-C,prev:C}),{diff:0,prev:0}),ae(S=>S.diff)),S=>{const{groupIndices:C}=et(b);if(S>0)ke(t,!0),ke(s,S+au(S,C));else if(S<0){const T=et(g);T.length>0&&(S-=au(-S,T)),ke(i,S)}}),Oe(Q(a,Ee(e)),([S,C])=>{S<0&&C("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:a},kt.ERROR)});const k=Pt(s);de(Q(s,Ee(b),ae(([S,C])=>{const T=C.groupIndices.length>0,A=[],N=C.lastSize;if(T){const j=Xr(C.sizeTree,0);let L=0,B=0;for(;L<S;){const O=C.groupIndices[B],D=C.groupIndices.length===B+1?1/0:C.groupIndices[B+1]-O-1;A.push({endIndex:O,size:j,startIndex:O}),A.push({endIndex:O+1+D-1,size:N,startIndex:O+1}),B++,L+=D+1}const W=Yn(C.sizeTree);return L!==S&&W.shift(),W.reduce((O,{k:D,v:z})=>{let ee=O.ranges;return O.prevSize!==0&&(ee=[...O.ranges,{endIndex:D+S-1,size:O.prevSize,startIndex:O.prevIndex}]),{prevIndex:D+S,prevSize:z,ranges:ee}},{prevIndex:S,prevSize:0,ranges:A}).ranges}return Yn(C.sizeTree).reduce((j,{k:L,v:B})=>({prevIndex:L+S,prevSize:B,ranges:[...j.ranges,{endIndex:L+S-1,size:j.prevSize,startIndex:j.prevIndex}]}),{prevIndex:0,prevSize:N,ranges:[]}).ranges})),n);const E=Pt(Q(i,Ee(b,p),ae(([S,{offsetTree:C},T])=>{const A=-S;return Zr(A,C,T)})));return de(Q(i,Ee(b,p),ae(([S,C,T])=>{if(C.groupIndices.length>0){if(Be(C.sizeTree))return C;let A=vr();const N=et(g);let j=0,L=0,B=0;for(;j<-S;){B=N[L];const W=N[L+1]-B-1;L++,j+=W+1}if(A=Yn(C.sizeTree).reduce((W,{k:O,v:D})=>Rt(W,Math.max(0,O+S),D),A),j!==-S){const W=Xr(C.sizeTree,B);A=Rt(A,0,W);const O=Yt(C.sizeTree,-S+1)[1];A=Rt(A,1,O)}return{...C,sizeTree:A,...Ii(C.offsetTree,0,A,T)}}else{const A=Yn(C.sizeTree).reduce((N,{k:j,v:L})=>Rt(N,Math.max(0,j+S),L),vr());return{...C,sizeTree:A,...Ii(C.offsetTree,0,A,T)}}})),b),{beforeUnshiftWith:k,data:h,defaultItemSize:u,firstItemIndex:a,fixedItemSize:c,gap:p,groupIndices:l,itemSize:f,listRefresh:y,shiftWith:i,shiftWithOffset:E,sizeRanges:n,sizes:b,statefulTotalCount:o,totalCount:r,trackItemSizes:w,unshiftWith:s}},We(Nn,ki),{singleton:!0});function Ux(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const lu=Re(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=_e(),i=_e(),a=Pt(Q(s,ae(Ux)));return de(Q(a,ae(l=>l.totalCount)),n),de(Q(a,ae(l=>l.groupIndices)),e),de(Q(nt(o,t,r),we(([l,c])=>Ko(c)),ae(([l,c,u])=>Yt(c.groupOffsetTree,Math.max(l-u,0),"v")[0]),Ve(),ae(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},We(nn,xt)),_n=Re(([{log:e}])=>{const t=ne(!1),n=Pt(Q(t,we(r=>r),Ve()));return Oe(t,r=>{r&&et(e)("props updated",{},kt.DEBUG)}),{didMount:n,propsReady:t}},We(Nn),{singleton:!0}),Hx=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function cu(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Hx)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Qr=Re(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:c,smoothScrollTargetReached:u,viewportHeight:f},{log:h}])=>{const p=_e(),m=_e(),b=ne(0);let g=null,w=null,y=null;function k(){g&&(g(),g=null),y&&(y(),y=null),w&&(clearTimeout(w),w=null),ke(l,!1)}return de(Q(p,Ee(n,f,r,b,a,i,h),Ee(e,s,o),ae(([[E,S,C,T,A,N,j,L],B,W,O])=>{const D=cu(E),{align:z,behavior:ee,offset:H}=D,V=T-1,Y=iu(D,S,V);let q=Zr(Y,S.offsetTree,B)+N;z==="end"?(q+=W+Yt(S.sizeTree,Y)[1]-C+O,Y===V&&(q+=j)):z==="center"?q+=(W+Yt(S.sizeTree,Y)[1]-C+O)/2:q-=A,H&&(q+=H);const M=P=>{k(),P?(L("retrying to scroll to",{location:E},kt.DEBUG),ke(p,E)):(ke(m,!0),L("list did not change, scroll successful",{},kt.DEBUG))};if(k(),ee==="smooth"){let P=!1;y=Oe(t,$=>{P=P||$}),g=Gt(u,()=>{M(P)})}else g=Gt(Q(t,Wx(150)),M);return w=setTimeout(()=>{k()},1200),ke(l,!0),L("scrolling from index to",{behavior:ee,index:Y,top:q},kt.DEBUG),{behavior:ee,top:q}})),c),{scrollTargetReached:m,scrollToIndex:p,topListHeight:b}},We(nn,xt,Nn),{singleton:!0});function Wx(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function Ai(e,t){e==0?t():requestAnimationFrame(()=>{Ai(e-1,t)})}function Ni(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const eo=Re(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=ne(!0),l=ne(0),c=ne(!0);return de(Q(i,Ee(l),we(([u,f])=>!!f),en(!1)),a),de(Q(i,Ee(l),we(([u,f])=>!!f),en(!1)),c),Oe(Q(nt(t,i),Ee(a,n,e,c),we(([[,u],f,{sizeTree:h},p,m])=>u&&(!Be(h)||xi(p))&&!f&&!m),Ee(l)),([,u])=>{Gt(o,()=>{ke(c,!0)}),Ai(4,()=>{Gt(r,()=>{ke(a,!0)}),ke(s,u)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},We(nn,xt,Qr,_n),{singleton:!0});function uu(e,t){return Math.abs(e-t)<1.01}const to="up",no="down",Vx="none",Kx={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},qx=0,ro=Re(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=ne(!1),a=ne(!0),l=_e(),c=_e(),u=ne(4),f=ne(qx),h=ct(Q(wi(Q(be(o),qn(1),en(!0)),Q(be(o),qn(1),en(!1),qc(100))),Ve()),!1),p=ct(Q(wi(Q(n,en(!0)),Q(n,en(!1),qc(200))),Ve()),!1);de(Q(nt(be(o),be(f)),ae(([y,k])=>y<=k),Ve()),a),de(Q(a,mn(50)),c);const m=Pt(Q(nt(r,be(s),be(t),be(e),be(u)),tn((y,[{scrollHeight:k,scrollTop:E},S,C,T,A])=>{const N=E+S-k>-A,j={scrollHeight:k,scrollTop:E,viewportHeight:S};if(N){let B,W;return E>y.state.scrollTop?(B="SCROLLED_DOWN",W=y.state.scrollTop-E):(B="SIZE_DECREASED",W=y.state.scrollTop-E||y.scrollTopDelta),{atBottom:!0,atBottomBecause:B,scrollTopDelta:W,state:j}}let L;return j.scrollHeight>y.state.scrollHeight?L="SIZE_INCREASED":S<y.state.viewportHeight?L="VIEWPORT_HEIGHT_DECREASING":E<y.state.scrollTop?L="SCROLLING_UPWARDS":L="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:L,state:j}},Kx),Ve((y,k)=>y&&y.atBottom===k.atBottom))),b=ct(Q(r,tn((y,{scrollHeight:k,scrollTop:E,viewportHeight:S})=>{if(uu(y.scrollHeight,k))return{changed:!1,jump:0,scrollHeight:k,scrollTop:E};{const C=k-(E+S)<1;return y.scrollTop!==E&&C?{changed:!0,jump:y.scrollTop-E,scrollHeight:k,scrollTop:E}:{changed:!0,jump:0,scrollHeight:k,scrollTop:E}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),we(y=>y.changed),ae(y=>y.jump)),0);de(Q(m,ae(y=>y.atBottom)),i),de(Q(i,mn(50)),l);const g=ne(no);de(Q(r,ae(({scrollTop:y})=>y),Ve(),tn((y,k)=>et(p)?{direction:y.direction,prevScrollTop:k}:{direction:k<y.prevScrollTop?to:no,prevScrollTop:k},{direction:no,prevScrollTop:0}),ae(y=>y.direction)),g),de(Q(r,mn(50),en(Vx)),g);const w=ne(0);return de(Q(h,we(y=>!y),en(0)),w),de(Q(o,mn(100),Ee(h),we(([y,k])=>!!k),tn(([y,k],[E])=>[k,E],[0,0]),ae(([y,k])=>k-y)),w),{atBottomState:m,atBottomStateChange:l,atBottomThreshold:u,atTopStateChange:c,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:b,scrollDirection:g,scrollVelocity:w}},We(xt)),qo="top",Go="bottom",du="none";function fu(e,t,n){return typeof e=="number"?n===to&&t===qo||n===no&&t===Go?e:0:n===to?t===qo?e.main:e.reverse:t===Go?e.main:e.reverse}function hu(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const ji=Re(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=_e(),i=ne(0),a=ne(0),l=ne(0),c=ct(Q(nt(be(r),be(o),be(n),be(s,Jr),be(l),be(i),be(t),be(e),be(a)),ae(([u,f,h,[p,m],b,g,w,y,k])=>{const E=u-y,S=g+w,C=Math.max(h-E,0);let T=du;const A=hu(k,qo),N=hu(k,Go);return p-=y,p+=h+w,m+=h+w,m-=y,p>u+S-A&&(T=to),m<u-C+f+N&&(T=no),T!==du?[Math.max(E-h-fu(b,qo,T)-A,0),E-C-w+f+fu(b,Go,T)+N]:null}),we(u=>u!=null),Ve(Jr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},We(xt),{singleton:!0});function Gx(e,t,n){if(Ko(t)){const r=su(e,t);return[{index:Yt(t.groupOffsetTree,r)[0],offset:0,size:0},{data:n==null?void 0:n[0],index:r,offset:0,size:0}]}return[{data:n==null?void 0:n[0],index:e,offset:0,size:0}]}const _i={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function Yo(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let c=0,u=0;if(e.length>0){c=e[0].offset;const b=e[e.length-1];u=b.offset+b.size}const f=n-i,h=a+f*l+(f-1)*r,p=c,m=h-u;return{bottom:u,firstItemIndex:s,items:mu(e,o,s),offsetBottom:m,offsetTop:c,top:p,topItems:mu(t,o,s),topListHeight:t.reduce((b,g)=>g.size+b,0),totalCount:n}}function pu(e,t,n,r,o,s){let i=0;if(n.groupIndices.length>0)for(const u of n.groupIndices){if(u-i>=e)break;i++}const a=e+i,l=Ni(t,a),c=Array.from({length:a}).map((u,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return Yo(c,[],a,o,n,r)}function mu(e,t,n){if(e.length===0)return[];if(!Ko(t))return e.map(c=>({...c,index:c.index+n,originalIndex:c.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=Ho(t.groupOffsetTree,r,o);let a,l=0;for(const c of e){(!a||a.end<c.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let u;c.index===a.start?u={index:l,type:"group"}:u={groupIndex:l,index:c.index-(l+1)+n},s.push({...u,data:c.data,offset:c.offset,originalIndex:c.index,size:c.size})}return s}const Xn=Re(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:c,scrolledToInitialItem:u},{topListHeight:f},h,{didMount:p},{recalcInProgress:m}])=>{const b=ne([]),g=ne(0),w=_e();de(s.topItemsIndexes,b);const y=ct(Q(nt(p,m,be(l,Jr),be(o),be(r),be(c),u,be(b),be(t),be(n),e),we(([C,T,,A,,,,,,,N])=>{const j=N&&N.length!==A;return C&&!T&&!j}),ae(([,,[C,T],A,N,j,L,B,W,O,D])=>{const z=N,{offsetTree:ee,sizeTree:H}=z,V=et(g);if(A===0)return{..._i,totalCount:A};if(C===0&&T===0)return V===0?{..._i,totalCount:A}:pu(V,j,N,W,O,D||[]);if(Be(H))return V>0?null:Yo(Gx(Ni(j,A),z,D),[],A,O,z,W);const Y=[];if(B.length>0){const R=B[0],G=B[B.length-1];let te=0;for(const F of Ho(H,R,G)){const X=F.value,re=Math.max(F.start,R),ue=Math.min(F.end,G);for(let le=re;le<=ue;le++)Y.push({data:D==null?void 0:D[le],index:le,offset:te,size:X}),te+=X}}if(!L)return Yo([],Y,A,O,z,W);const q=B.length>0?B[B.length-1]+1:0,M=Dx(ee,C,T,q);if(M.length===0)return null;const P=A-1,$=Uo([],R=>{for(const G of M){const te=G.value;let F=te.offset,X=G.start;const re=te.size;if(te.offset<C){X+=Math.floor((C-te.offset+O)/(re+O));const le=X-G.start;F+=le*re+le*O}X<q&&(F+=(q-X)*re,X=q);const ue=Math.min(G.end,P);for(let le=X;le<=ue&&!(F>=T);le++)R.push({data:D==null?void 0:D[le],index:le,offset:F,size:re}),F+=re+O}});return Yo($,Y,A,O,z,W)}),we(C=>C!==null),Ve()),_i);de(Q(e,we(xi),ae(C=>C==null?void 0:C.length)),o),de(Q(y,ae(C=>C.topListHeight)),f),de(f,a),de(Q(y,ae(C=>[C.top,C.bottom])),i),de(Q(y,ae(C=>C.items)),w);const k=Pt(Q(y,we(({items:C})=>C.length>0),Ee(o,e),we(([{items:C},T])=>C[C.length-1].originalIndex===T-1),ae(([,C,T])=>[C-1,T]),Ve(Jr),ae(([C])=>C))),E=Pt(Q(y,mn(200),we(({items:C,topItems:T})=>C.length>0&&C[0].originalIndex===T.length),ae(({items:C})=>C[0].index),Ve())),S=Pt(Q(y,we(({items:C})=>C.length>0),ae(({items:C})=>{let T=0,A=C.length-1;for(;C[T].type==="group"&&T<A;)T++;for(;C[A].type==="group"&&A>T;)A--;return{endIndex:C[A].index,startIndex:C[T].index}}),Ve(ru)));return{endReached:k,initialItemCount:g,itemsRendered:w,listState:y,rangeChanged:S,startReached:E,topItemsIndexes:b,...h}},We(nn,lu,ji,eo,Qr,ro,_n,ki),{singleton:!0}),gu=Re(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=_e(),i=ct(Q(nt(n,e,r,t,o),ae(([a,l,c,u,f])=>a+l+c+u+f.offsetBottom+f.bottom)),0);return de(be(i),s),{totalListHeight:i,totalListHeightChanged:s}},We(xt,Xn),{singleton:!0}),Yx=Re(([{viewportHeight:e},{totalListHeight:t}])=>{const n=ne(!1),r=ct(Q(nt(n,e,t),we(([o])=>o),ae(([,o,s])=>Math.max(0,o-s)),mn(0),Ve()),0);return{alignToBottom:n,paddingTopAddition:r}},We(xt,gu),{singleton:!0}),xu=Re(()=>({context:ne(null)})),Xx=({itemBottom:e,itemTop:t,locationParams:{align:n,behavior:r,...o},viewportBottom:s,viewportTop:i})=>t<i?{...o,align:n??"start",behavior:r}:e>s?{...o,align:n??"end",behavior:r}:null,bu=Re(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:c}])=>{const u=_e();return de(Q(u,Ee(t,l,n,s,o,r,a),Ee(e),ae(([[f,h,p,m,b,g,w,y],k])=>{const{align:E,behavior:S,calculateViewLocation:C=Xx,done:T,...A}=f,N=iu(f,h,m-1),j=Zr(N,h.offsetTree,k)+b+g,L=j+Yt(h.sizeTree,N)[1],B=y+g,W=y+p-w,O=C({itemBottom:L,itemTop:j,locationParams:{align:E,behavior:S,...A},viewportBottom:W,viewportTop:B});return O?T&&Gt(Q(i,we(D=>!D),qn(et(i)?1:2)),T):T&&T(),O}),we(f=>f!==null)),c),{scrollIntoView:u}},We(nn,xt,Qr,Xn,Nn),{singleton:!0});function wu(e){return e?e==="smooth"?"smooth":"auto":!1}const Jx=(e,t)=>typeof e=="function"?wu(e(t)):t&&wu(e),Zx=Re(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:c},{log:u},{scrollingInProgress:f},{context:h},{scrollIntoView:p}])=>{const m=ne(!1),b=_e();let g=null;function w(S){ke(i,{align:"end",behavior:S,index:"LAST"})}Oe(Q(nt(Q(be(t),qn(1)),l),Ee(be(m),s,a,f),ae(([[S,C],T,A,N,j])=>{let L=C&&N,B="auto";return L&&(B=Jx(T,A||j),L=L&&!!B),{followOutputBehavior:B,shouldFollow:L,totalCount:S}}),we(({shouldFollow:S})=>S)),({followOutputBehavior:S,totalCount:C})=>{g&&(g(),g=null),et(n)?requestAnimationFrame(()=>{et(u)("following output to ",{totalCount:C},kt.DEBUG),w(S)}):g=Gt(e,()=>{et(u)("following output to ",{totalCount:C},kt.DEBUG),w(S),g=null})});function y(S){const C=Gt(o,T=>{S&&!T.atBottom&&T.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(et(u)("scrolling to bottom due to increased size",{},kt.DEBUG),w("auto"))});setTimeout(C,100)}Oe(Q(nt(be(m),t,c),we(([S,,C])=>S&&C),tn(({value:S},[,C])=>({refreshed:S===C,value:C}),{refreshed:!1,value:0}),we(({refreshed:S})=>S),Ee(m,t)),([,S])=>{et(a)&&y(S!==!1)}),Oe(b,()=>{y(et(m)!==!1)}),Oe(nt(be(m),o),([S,C])=>{S&&!C.atBottom&&C.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&w("auto")});const k=ne(null),E=_e();return de(wi(Q(be(r),ae(S=>{var C;return(C=S==null?void 0:S.length)!=null?C:0})),Q(be(t))),E),Oe(Q(nt(Q(E,qn(1)),l),Ee(be(k),a,f,h),ae(([[S,C],T,A,N,j])=>C&&A&&(T==null?void 0:T({context:j,totalCount:S,scrollingInProgress:N}))),we(S=>!!S),mn(0)),S=>{g&&(g(),g=null),et(n)?requestAnimationFrame(()=>{et(u)("scrolling into view",{}),ke(p,S)}):g=Gt(e,()=>{et(u)("scrolling into view",{}),ke(p,S),g=null})}),{autoscrollToBottom:b,followOutput:m,scrollIntoViewOnChange:k}},We(nn,ro,Qr,eo,_n,Nn,xt,xu,bu)),Qx=Re(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(de(Q(a,Ee(s),we(([,l])=>l!==0),Ee(o,r,t,n,e),ae(([[,l],c,u,f,h,p=[]])=>pu(l,c,u,f,h,p))),i),{}),We(nn,eo,Xn,_n),{singleton:!0}),eb=Re(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=ne(0);return Oe(Q(e,Ee(r),we(([,o])=>o!==0),ae(([,o])=>({top:o}))),o=>{Gt(Q(n,qn(1),we(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{ke(t,o)})})}),{initialScrollTop:r}},We(_n,xt,Xn),{singleton:!0}),yu=Re(([{scrollVelocity:e}])=>{const t=ne(!1),n=_e(),r=ne(!1);return de(Q(e,Ee(r,t,n),we(([o,s])=>!!s),ae(([o,s,i,a])=>{const{enter:l,exit:c}=s;if(i){if(c(o,a))return!1}else if(l(o,a))return!0;return i}),Ve()),t),Oe(Q(nt(t,e,n),Ee(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},We(ro),{singleton:!0}),Pi=Re(([{scrollContainerState:e,scrollTo:t}])=>{const n=_e(),r=_e(),o=_e(),s=ne(!1),i=ne(void 0);return de(Q(nt(n,r),ae(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:u}])=>({scrollHeight:a,scrollTop:Math.max(0,l-u),viewportHeight:c}))),e),de(Q(t,Ee(r),ae(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},We(xt)),tb=Re(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=_e(),u=ne(void 0),f=ne(null),h=ne(null);return de(a,f),de(l,h),Oe(Q(c,Ee(t,r,i,f,h,n)),([p,m,b,g,w,y,k])=>{const E=$x(m.sizeTree);g&&w!==null&&y!==null&&(b=w.scrollTop-y.offsetTop),b-=k,p({ranges:E,scrollTop:b})}),de(Q(u,we(xi),ae(nb)),o),de(Q(s,Ee(u),we(([,p])=>p!==void 0),Ve(),ae(([,p])=>p.ranges)),e),{getState:c,restoreStateFrom:u}},We(nn,xt,eo,_n,Pi));function nb(e){return{align:"start",index:0,offset:e.scrollTop}}const rb=Re(([{topItemsIndexes:e}])=>{const t=ne(0);return de(Q(t,we(n=>n>=0),ae(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},We(Xn));function vu(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const ob=vu(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),sb=Re(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:c,gap:u,shiftWithOffset:f,sizes:h},{log:p},{recalcInProgress:m}])=>{const b=Pt(Q(l,Ee(i),tn(([,w,y,k],[{bottom:E,items:S,offsetBottom:C,totalCount:T},A])=>{const N=E+C;let j=0;return y===T&&w.length>0&&S.length>0&&(S[0].originalIndex===0&&w[0].originalIndex===0||(j=N-k,j!==0&&(j+=A))),[j,S,T,N]},[0,[],0,0]),we(([w])=>w!==0),Ee(r,a,n,o,p,m),we(([,w,y,k,,,E])=>!E&&!k&&w!==0&&y===to),ae(([[w],,,,,y])=>(y("Upward scrolling compensation",{amount:w},kt.DEBUG),w))));function g(w){w>0?(ke(t,{behavior:"auto",top:-w}),ke(e,0)):(ke(e,0),ke(t,{behavior:"auto",top:-w}))}return Oe(Q(b,Ee(e,s)),([w,y,k])=>{k&&ob()?ke(e,y-w):g(-w)}),Oe(Q(nt(ct(s,!1),e,m),we(([w,y,k])=>!w&&!k&&y!==0),ae(([w,y])=>y),mn(1)),g),de(Q(f,ae(w=>({top:-w}))),t),Oe(Q(c,Ee(h,u),ae(([w,{groupIndices:y,lastSize:k,sizeTree:E},S])=>{function C(T){return T*(k+S)}if(y.length===0)return C(w);{let T=0;const A=Xr(E,0);let N=0,j=0;for(;N<w;){N++,T+=A;let L=y.length===j+1?1/0:y[j+1]-y[j]-1;N+L>w&&(T-=A,L=w-N+1),N+=L,T+=C(L),j++}return T}})),w=>{ke(e,w),requestAnimationFrame(()=>{ke(t,{top:w}),requestAnimationFrame(()=>{ke(e,0),ke(m,!1)})})}),{deviation:e}},We(xt,ro,Xn,nn,Nn,ki)),ib=Re(([e,t,n,r,o,s,i,a,l,c,u])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...u}),We(ji,Qx,_n,yu,gu,eb,Yx,Pi,bu,Nn,xu)),Su=Re(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:c,totalCount:u,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:m},b,g,w,{listState:y,topItemsIndexes:k,...E},{scrollToIndex:S},C,{topItemCount:T},{groupCounts:A},N])=>(de(E.rangeChanged,N.scrollSeekRangeChanged),de(Q(N.windowViewportRect,ae(j=>j.visibleHeight)),b.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:A,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:m,sizeRanges:a,topItemCount:T,topItemsIndexes:k,totalCount:u,...w,groupIndices:s,itemSize:i,listState:y,scrollToIndex:S,statefulTotalCount:c,trackItemSizes:f,...E,...N,...b,sizes:l,...g}),We(nn,eo,xt,tb,Zx,Xn,Qr,sb,rb,lu,ib));function ab(e,t){const n={},r={};let o=0;const s=e.length;for(;o<s;)r[e[o]]=1,o+=1;for(const i in t)Object.hasOwn(r,i)||(n[i]=t[i]);return n}const Xo=typeof document<"u"?v.useLayoutEffect:v.useEffect;function Cu(e,t,n){const r=Object.keys(t.required||{}),o=Object.keys(t.optional||{}),s=Object.keys(t.methods||{}),i=Object.keys(t.events||{}),a=v.createContext({});function l(g,w){g.propsReady&&ke(g.propsReady,!1);for(const y of r){const k=g[t.required[y]];ke(k,w[y])}for(const y of o)if(y in w){const k=g[t.optional[y]];ke(k,w[y])}g.propsReady&&ke(g.propsReady,!0)}function c(g){return s.reduce((w,y)=>(w[y]=k=>{const E=g[t.methods[y]];ke(E,k)},w),{})}function u(g){return i.reduce((w,y)=>(w[y]=Cx(g[t.events[y]]),w),{})}const f=v.forwardRef((g,w)=>{const{children:y,...k}=g,[E]=v.useState(()=>Uo(kx(e),T=>{l(T,k)})),[S]=v.useState(Kc(u,E));Xo(()=>{for(const T of i)T in k&&Oe(S[T],k[T]);return()=>{Object.values(S).map(bi)}},[k,S,E]),Xo(()=>{l(E,k)}),v.useImperativeHandle(w,Wc(c(E)));const C=n;return d.jsx(a.Provider,{value:E,children:n?d.jsx(C,{...ab([...r,...o,...i],k),children:y}):y})}),h=g=>{const w=v.useContext(a);return v.useCallback(y=>{ke(w[g],y)},[w,g])},p=g=>{const w=v.useContext(a)[g],y=v.useCallback(k=>Oe(w,k),[w]);return v.useSyncExternalStore(y,()=>et(w),()=>et(w))},m=g=>{const w=v.useContext(a)[g],[y,k]=v.useState(Kc(et,w));return Xo(()=>Oe(w,E=>{E!==y&&k(Wc(E))}),[w,y]),y},b=v.version.startsWith("18")?p:m;return{Component:f,useEmitter:(g,w)=>{const y=v.useContext(a)[g];Xo(()=>Oe(y,w),[w,y])},useEmitterValue:b,usePublisher:h}}const Tu=v.createContext(void 0),ku=v.createContext(void 0),Eu=typeof document<"u"?v.useLayoutEffect:v.useEffect;function Ri(e){return"self"in e}function lb(e){return"body"in e}function Iu(e,t,n,r=yr,o,s){const i=v.useRef(null),a=v.useRef(null),l=v.useRef(null),c=v.useCallback(h=>{let p,m,b;const g=h.target;if(lb(g)||Ri(g)){const y=Ri(g)?g:g.defaultView;b=s?y.scrollX:y.scrollY,p=s?y.document.documentElement.scrollWidth:y.document.documentElement.scrollHeight,m=s?y.innerWidth:y.innerHeight}else b=s?g.scrollLeft:g.scrollTop,p=s?g.scrollWidth:g.scrollHeight,m=s?g.offsetWidth:g.offsetHeight;const w=()=>{e({scrollHeight:p,scrollTop:Math.max(b,0),viewportHeight:m})};h.suppressFlushSync?w():Ws.flushSync(w),a.current!==null&&(b===a.current||b<=0||b===p-m)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);v.useEffect(()=>{const h=o||i.current;return r(o||i.current),c({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",c,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",c)}},[i,c,n,r,o]);function u(h){const p=i.current;if(!p||(s?"offsetWidth"in p&&p.offsetWidth===0:"offsetHeight"in p&&p.offsetHeight===0))return;const m=h.behavior==="smooth";let b,g,w;Ri(p)?(g=Math.max(jn(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),b=s?p.innerWidth:p.innerHeight,w=s?window.scrollX:window.scrollY):(g=p[s?"scrollWidth":"scrollHeight"],b=jn(p,s?"width":"height"),w=p[s?"scrollLeft":"scrollTop"]);const y=g-b;if(h.top=Math.ceil(Math.max(Math.min(y,h.top),0)),uu(b,g)||h.top===w){e({scrollHeight:g,scrollTop:w,viewportHeight:b}),m&&t(!0);return}m?(a.current=h.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),p.scrollTo(h)}function f(h){s&&(h={behavior:h.behavior,left:h.top}),i.current.scrollBy(h)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:u}}const Oi="-webkit-sticky",Au="sticky",Mi=vu(()=>{if(typeof document>"u")return Au;const e=document.createElement("div");return e.style.position=Oi,e.style.position===Oi?Oi:Au});function Di(e){return e}const cb=Re(()=>{const e=ne(a=>`Item ${a}`),t=ne(a=>`Group ${a}`),n=ne({}),r=ne(Di),o=ne("div"),s=ne(yr),i=(a,l=null)=>ct(Q(n,ae(c=>c[a]),Ve()),l);return{components:n,computeItemKey:r,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:t,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:e,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),ub=Re(([e,t])=>({...e,...t}),We(Su,cb)),db=({height:e})=>d.jsx("div",{style:{height:e}}),fb={overflowAnchor:"none",position:Mi(),zIndex:1},Nu={overflowAnchor:"none"},hb={...Nu,display:"inline-block",height:"100%"},ju=v.memo(function({showTopList:e=!1}){const t=ve("listState"),n=Bt("sizeRanges"),r=ve("useWindowScroll"),o=ve("customScrollParent"),s=Bt("windowScrollContainerState"),i=Bt("scrollContainerState"),a=o||r?s:i,l=ve("itemContent"),c=ve("context"),u=ve("groupContent"),f=ve("trackItemSizes"),h=ve("itemSize"),p=ve("log"),m=Bt("gap"),b=ve("horizontalDirection"),{callbackRef:g}=Ax(n,h,f,e?yr:a,p,m,o,b,ve("skipAnimationFrameInResizeObserver")),[w,y]=v.useState(0);Li("deviation",O=>{w!==O&&y(O)});const k=ve("EmptyPlaceholder"),E=ve("ScrollSeekPlaceholder")||db,S=ve("ListComponent"),C=ve("ItemComponent"),T=ve("GroupComponent"),A=ve("computeItemKey"),N=ve("isSeeking"),j=ve("groupIndices").length>0,L=ve("alignToBottom"),B=ve("initialItemFinalLocationReached"),W=e?{}:{boxSizing:"border-box",...b?{display:"inline-block",height:"100%",marginLeft:w!==0?w:L?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:w!==0?w:L?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...B?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&k?d.jsx(k,{...ut(k,c)}):d.jsx(S,{...ut(S,c),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:g,style:W,children:(e?t.topItems:t.items).map(O=>{const D=O.originalIndex,z=A(D+t.firstItemIndex,O.data,c);return N?v.createElement(E,{...ut(E,c),height:O.size,index:O.index,key:z,type:O.type||"item",...O.type==="group"?{}:{groupIndex:O.groupIndex}}):O.type==="group"?v.createElement(T,{...ut(T,c),"data-index":D,"data-item-index":O.index,"data-known-size":O.size,key:z,style:fb},u(O.index,c)):v.createElement(C,{...ut(C,c),...xb(C,O.data),"data-index":D,"data-item-group-index":O.groupIndex,"data-item-index":O.index,"data-known-size":O.size,key:z,style:b?hb:Nu},j?l(O.index,O.groupIndex,O.data,c):l(O.index,O.data,c))})})}),pb={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},mb={outline:"none",overflowX:"auto",position:"relative"},Jo=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),gb={position:Mi(),top:0,width:"100%",zIndex:1};function ut(e,t){if(typeof e!="string")return{context:t}}function xb(e,t){return{item:typeof e=="string"?void 0:t}}const bb=v.memo(function(){const e=ve("HeaderComponent"),t=Bt("headerHeight"),n=ve("HeaderFooterTag"),r=Gn(v.useMemo(()=>s=>{t(jn(s,"height"))},[t]),!0,ve("skipAnimationFrameInResizeObserver")),o=ve("context");return e?d.jsx(n,{ref:r,children:d.jsx(e,{...ut(e,o)})}):null}),wb=v.memo(function(){const e=ve("FooterComponent"),t=Bt("footerHeight"),n=ve("HeaderFooterTag"),r=Gn(v.useMemo(()=>s=>{t(jn(s,"height"))},[t]),!0,ve("skipAnimationFrameInResizeObserver")),o=ve("context");return e?d.jsx(n,{ref:r,children:d.jsx(e,{...ut(e,o)})}):null});function _u({useEmitter:e,useEmitterValue:t,usePublisher:n}){return v.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),u=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback:m}=Iu(a,c,l,u,void 0,f);return e("scrollTo",m),e("scrollBy",h),d.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?mb:pb,...o},tabIndex:0,...i,...ut(l,s),children:r})})}function Pu({useEmitter:e,useEmitterValue:t,usePublisher:n}){return v.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),u=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),p=v.useRef(null),m=t("scrollerRef"),{scrollByCallback:b,scrollerRef:g,scrollToCallback:w}=Iu(a,c,l,m,h);return Eu(()=>{var y;return g.current=h||((y=p.current)==null?void 0:y.ownerDocument.defaultView),()=>{g.current=null}},[g,h]),e("windowScrollTo",w),e("scrollBy",b),d.jsx(l,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...u!==0?{height:u+f}:{}},...i,...ut(l,s),children:r})})}const yb=({children:e})=>{const t=v.useContext(Tu),n=Bt("viewportHeight"),r=Bt("fixedItemHeight"),o=ve("alignToBottom"),s=ve("horizontalDirection"),i=v.useMemo(()=>Vc(n,l=>jn(l,s?"width":"height")),[n,s]),a=Gn(i,!0,ve("skipAnimationFrameInResizeObserver"));return v.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),d.jsx("div",{"data-viewport-type":"element",ref:a,style:Jo(o),children:e})},vb=({children:e})=>{const t=v.useContext(Tu),n=Bt("windowViewportRect"),r=Bt("fixedItemHeight"),o=ve("customScrollParent"),s=Xc(n,o,ve("skipAnimationFrameInResizeObserver")),i=ve("alignToBottom");return v.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),d.jsx("div",{"data-viewport-type":"window",ref:s,style:Jo(i),children:e})},Sb=({children:e})=>{const t=ve("TopItemListComponent")||"div",n=ve("headerHeight"),r={...gb,marginTop:`${n}px`},o=ve("context");return d.jsx(t,{style:r,...ut(t,o),children:e})},Cb=v.memo(function(e){const t=ve("useWindowScroll"),n=ve("topItemsIndexes").length>0,r=ve("customScrollParent"),o=ve("context");return d.jsxs(r||t?Eb:kb,{...e,context:o,children:[n&&d.jsx(Sb,{children:d.jsx(ju,{showTopList:!0})}),d.jsxs(r||t?vb:yb,{children:[d.jsx(bb,{}),d.jsx(ju,{}),d.jsx(wb,{})]})]})}),{Component:Tb,useEmitter:Li,useEmitterValue:ve,usePublisher:Bt}=Cu(ub,{required:{},optional:{restoreStateFrom:"restoreStateFrom",context:"context",followOutput:"followOutput",scrollIntoViewOnChange:"scrollIntoViewOnChange",itemContent:"itemContent",groupContent:"groupContent",overscan:"overscan",increaseViewportBy:"increaseViewportBy",totalCount:"totalCount",groupCounts:"groupCounts",topItemCount:"topItemCount",firstItemIndex:"firstItemIndex",initialTopMostItemIndex:"initialTopMostItemIndex",components:"components",atBottomThreshold:"atBottomThreshold",atTopThreshold:"atTopThreshold",computeItemKey:"computeItemKey",defaultItemHeight:"defaultItemHeight",fixedItemHeight:"fixedItemHeight",itemSize:"itemSize",scrollSeekConfiguration:"scrollSeekConfiguration",headerFooterTag:"HeaderFooterTag",data:"data",initialItemCount:"initialItemCount",initialScrollTop:"initialScrollTop",alignToBottom:"alignToBottom",useWindowScroll:"useWindowScroll",customScrollParent:"customScrollParent",scrollerRef:"scrollerRef",logLevel:"logLevel",horizontalDirection:"horizontalDirection",skipAnimationFrameInResizeObserver:"skipAnimationFrameInResizeObserver"},methods:{scrollToIndex:"scrollToIndex",scrollIntoView:"scrollIntoView",scrollTo:"scrollTo",scrollBy:"scrollBy",autoscrollToBottom:"autoscrollToBottom",getState:"getState"},events:{isScrolling:"isScrolling",endReached:"endReached",startReached:"startReached",rangeChanged:"rangeChanged",atBottomStateChange:"atBottomStateChange",atTopStateChange:"atTopStateChange",totalListHeightChanged:"totalListHeightChanged",itemsRendered:"itemsRendered",groupIndices:"groupIndices"}},Cb),kb=_u({useEmitter:Li,useEmitterValue:ve,usePublisher:Bt}),Eb=Pu({useEmitter:Li,useEmitterValue:ve,usePublisher:Bt}),Ib=Tb;We(Su,Re(()=>{const e=ne(c=>d.jsxs("td",{children:["Item $",c]})),t=ne(null),n=ne(c=>d.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=ne(null),o=ne(null),s=ne({}),i=ne(Di),a=ne(yr),l=(c,u=null)=>ct(Q(s,ae(f=>f[c]),Ve()),u);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:l("EmptyPlaceholder"),FillerRow:l("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TableBodyComponent:l("TableBody","tbody"),TableComponent:l("Table","table"),TableFooterComponent:l("TableFoot","tfoot"),TableHeadComponent:l("TableHead","thead"),TableRowComponent:l("TableRow","tr"),GroupComponent:l("Group","tr")}})),Mi();const Ru={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},Ab={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Ou,floor:Zo,max:oo,min:$i,round:Mu}=Math;function Du(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function Nb(e){return{...Ab,items:e}}function Qo(e,t){return e&&e.width===t.width&&e.height===t.height}function jb(e,t){return e&&e.column===t.column&&e.row===t.row}const _b=Re(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:c,smoothScrollTargetReached:u,viewportHeight:f},h,p,{didMount:m,propsReady:b},{customScrollParent:g,useWindowScroll:w,windowScrollContainerState:y,windowScrollTo:k,windowViewportRect:E},S])=>{const C=ne(0),T=ne(0),A=ne(Ru),N=ne({height:0,width:0}),j=ne({height:0,width:0}),L=_e(),B=_e(),W=ne(0),O=ne(null),D=ne({column:0,row:0}),z=_e(),ee=_e(),H=ne(!1),V=ne(0),Y=ne(!0),q=ne(!1),M=ne(!1);Oe(Q(m,Ee(V),we(([F,X])=>!!X)),()=>{ke(Y,!1)}),Oe(Q(nt(m,Y,j,N,V,q),we(([F,X,re,ue,,le])=>F&&!X&&re.height!==0&&ue.height!==0&&!le)),([,,,,F])=>{ke(q,!0),Ai(1,()=>{ke(L,F)}),Gt(Q(c),()=>{ke(t,[0,0]),ke(Y,!0)})}),de(Q(ee,we(F=>F!=null&&F.scrollTop>0),en(0)),T),Oe(Q(m,Ee(ee),we(([,F])=>F!=null)),([,F])=>{F&&(ke(N,F.viewport),ke(j,F.item),ke(D,F.gap),F.scrollTop>0&&(ke(H,!0),Gt(Q(c,qn(1)),X=>{ke(H,!1)}),ke(l,{top:F.scrollTop})))}),de(Q(N,ae(({height:F})=>F)),f),de(Q(nt(be(N,Qo),be(j,Qo),be(D,(F,X)=>F&&F.column===X.column&&F.row===X.row),be(c)),ae(([F,X,re,ue])=>({gap:re,item:X,scrollTop:ue,viewport:F}))),z),de(Q(nt(be(C),r,be(D,jb),be(j,Qo),be(N,Qo),be(O),be(T),be(H),be(Y),be(V)),we(([,,,,,,,F])=>!F),ae(([F,[X,re],ue,le,Se,Me,Ie,,Ke,He])=>{const{column:Fe,row:ze}=ue,{height:It,width:At}=le,{width:wt}=Se;if(Ie===0&&(F===0||wt===0))return Ru;if(At===0){const _t=Ni(He,F),Ae=_t+Math.max(Ie-1,0);return Nb(Du(_t,Ae,Me))}const yt=Lu(wt,At,Fe);let ht,st;Ke?X===0&&re===0&&Ie>0?(ht=0,st=Ie-1):(ht=yt*Zo((X+ze)/(It+ze)),st=yt*Ou((re+ze)/(It+ze))-1,st=$i(F-1,oo(st,yt-1)),ht=$i(st,oo(0,ht))):(ht=0,st=-1);const Nt=Du(ht,st,Me),{bottom:jt,top:rt}=$u(Se,ue,le,Nt),tt=Ou(F/yt),it=tt*It+(tt-1)*ze-jt;return{bottom:jt,itemHeight:It,items:Nt,itemWidth:At,offsetBottom:it,offsetTop:rt,top:rt}})),A),de(Q(O,we(F=>F!==null),ae(F=>F.length)),C),de(Q(nt(N,j,A,D),we(([F,X,{items:re}])=>re.length>0&&X.height!==0&&F.height!==0),ae(([F,X,{items:re},ue])=>{const{bottom:le,top:Se}=$u(F,ue,X,re);return[Se,le]}),Ve(Jr)),t);const P=ne(!1);de(Q(c,Ee(P),ae(([F,X])=>X||F!==0)),P);const $=Pt(Q(nt(A,C),we(([{items:F}])=>F.length>0),Ee(P),we(([[F,X],re])=>{const ue=F.items[F.items.length-1].index===X-1;return(re||F.bottom>0&&F.itemHeight>0&&F.offsetBottom===0&&F.items.length===X)&&ue}),ae(([[,F]])=>F-1),Ve())),R=Pt(Q(be(A),we(({items:F})=>F.length>0&&F[0].index===0),en(0),Ve())),G=Pt(Q(be(A),Ee(H),we(([{items:F},X])=>F.length>0&&!X),ae(([{items:F}])=>({endIndex:F[F.length-1].index,startIndex:F[0].index})),Ve(ru),mn(0)));de(G,p.scrollSeekRangeChanged),de(Q(L,Ee(N,j,C,D),ae(([F,X,re,ue,le])=>{const Se=cu(F),{align:Me,behavior:Ie,offset:Ke}=Se;let He=Se.index;He==="LAST"&&(He=ue-1),He=oo(0,He,$i(ue-1,He));let Fe=Fi(X,le,re,He);return Me==="end"?Fe=Mu(Fe-X.height+re.height):Me==="center"&&(Fe=Mu(Fe-X.height/2+re.height/2)),Ke&&(Fe+=Ke),{behavior:Ie,top:Fe}})),l);const te=ct(Q(A,ae(F=>F.offsetBottom+F.bottom)),0);return de(Q(E,ae(F=>({height:F.visibleHeight,width:F.visibleWidth}))),N),{customScrollParent:g,data:O,deviation:W,footerHeight:o,gap:D,headerHeight:s,increaseViewportBy:e,initialItemCount:T,itemDimensions:j,overscan:n,restoreStateFrom:ee,scrollBy:i,scrollContainerState:a,scrollHeight:B,scrollTo:l,scrollToIndex:L,scrollTop:c,smoothScrollTargetReached:u,totalCount:C,useWindowScroll:w,viewportDimensions:N,windowScrollContainerState:y,windowScrollTo:k,windowViewportRect:E,...p,gridState:A,horizontalDirection:M,initialTopMostItemIndex:V,totalListHeight:te,...h,endReached:$,propsReady:b,rangeChanged:G,startReached:R,stateChanged:z,stateRestoreInProgress:H,...S}},We(ji,xt,ro,yu,_n,Pi,Nn));function Lu(e,t,n){return oo(1,Zo((e+n)/(Zo(t)+n)))}function $u(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=Fi(e,t,n,r[0].index);return{bottom:Fi(e,t,n,r[r.length-1].index)+o,top:s}}function Fi(e,t,n,r){const o=Lu(e.width,n.width,t.column),s=Zo(r/o),i=s*n.height+oo(0,s-1)*t.row;return i>0?i+t.row:i}const Pb=Re(()=>{const e=ne(f=>`Item ${f}`),t=ne({}),n=ne(null),r=ne("virtuoso-grid-item"),o=ne("virtuoso-grid-list"),s=ne(Di),i=ne("div"),a=ne(yr),l=(f,h=null)=>ct(Q(t,ae(p=>p[f]),Ve()),h),c=ne(!1),u=ne(!1);return de(be(u),c),{components:t,computeItemKey:s,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:l("Item","div"),itemContent:e,listClassName:o,ListComponent:l("List","div"),readyStateChanged:c,reportReadyState:u,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),Rb=Re(([e,t])=>({...e,...t}),We(_b,Pb)),Ob=v.memo(function(){const e=qe("gridState"),t=qe("listClassName"),n=qe("itemClassName"),r=qe("itemContent"),o=qe("computeItemKey"),s=qe("isSeeking"),i=Ut("scrollHeight"),a=qe("ItemComponent"),l=qe("ListComponent"),c=qe("ScrollSeekPlaceholder"),u=qe("context"),f=Ut("itemDimensions"),h=Ut("gap"),p=qe("log"),m=qe("stateRestoreInProgress"),b=Ut("reportReadyState"),g=Gn(v.useMemo(()=>w=>{const y=w.parentElement.parentElement.scrollHeight;i(y);const k=w.firstChild;if(k){const{height:E,width:S}=k.getBoundingClientRect();f({height:E,width:S})}h({column:zu("column-gap",getComputedStyle(w).columnGap,p),row:zu("row-gap",getComputedStyle(w).rowGap,p)})},[i,f,h,p]),!0,!1);return Eu(()=>{e.itemHeight>0&&e.itemWidth>0&&b(!0)},[e]),m?null:d.jsx(l,{className:t,ref:g,...ut(l,u),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(w=>{const y=o(w.index,w.data,u);return s?d.jsx(c,{...ut(c,u),height:e.itemHeight,index:w.index,width:e.itemWidth},y):v.createElement(a,{...ut(a,u),className:n,"data-index":w.index,key:y},r(w.index,w.data,u))})})}),Mb=v.memo(function(){const e=qe("HeaderComponent"),t=Ut("headerHeight"),n=qe("headerFooterTag"),r=Gn(v.useMemo(()=>s=>{t(jn(s,"height"))},[t]),!0,!1),o=qe("context");return e?d.jsx(n,{ref:r,children:d.jsx(e,{...ut(e,o)})}):null}),Db=v.memo(function(){const e=qe("FooterComponent"),t=Ut("footerHeight"),n=qe("headerFooterTag"),r=Gn(v.useMemo(()=>s=>{t(jn(s,"height"))},[t]),!0,!1),o=qe("context");return e?d.jsx(n,{ref:r,children:d.jsx(e,{...ut(e,o)})}):null}),Lb=({children:e})=>{const t=v.useContext(ku),n=Ut("itemDimensions"),r=Ut("viewportDimensions"),o=Gn(v.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return v.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),d.jsx("div",{ref:o,style:Jo(!1),children:e})},$b=({children:e})=>{const t=v.useContext(ku),n=Ut("windowViewportRect"),r=Ut("itemDimensions"),o=qe("customScrollParent"),s=Xc(n,o,!1);return v.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),d.jsx("div",{ref:s,style:Jo(!1),children:e})},Fb=v.memo(function({...e}){const t=qe("useWindowScroll"),n=qe("customScrollParent"),r=n||t?Bb:zb,o=n||t?$b:Lb,s=qe("context");return d.jsx(r,{...e,...ut(r,s),children:d.jsxs(o,{children:[d.jsx(Mb,{}),d.jsx(Ob,{}),d.jsx(Db,{})]})})}),{useEmitter:Fu,useEmitterValue:qe,usePublisher:Ut}=Cu(Rb,{optional:{context:"context",totalCount:"totalCount",overscan:"overscan",itemContent:"itemContent",components:"components",computeItemKey:"computeItemKey",data:"data",initialItemCount:"initialItemCount",scrollSeekConfiguration:"scrollSeekConfiguration",headerFooterTag:"headerFooterTag",listClassName:"listClassName",itemClassName:"itemClassName",useWindowScroll:"useWindowScroll",customScrollParent:"customScrollParent",scrollerRef:"scrollerRef",logLevel:"logLevel",restoreStateFrom:"restoreStateFrom",initialTopMostItemIndex:"initialTopMostItemIndex",increaseViewportBy:"increaseViewportBy"},methods:{scrollTo:"scrollTo",scrollBy:"scrollBy",scrollToIndex:"scrollToIndex"},events:{isScrolling:"isScrolling",endReached:"endReached",startReached:"startReached",rangeChanged:"rangeChanged",atBottomStateChange:"atBottomStateChange",atTopStateChange:"atTopStateChange",stateChanged:"stateChanged",readyStateChanged:"readyStateChanged"}},Fb),zb=_u({useEmitter:Fu,useEmitterValue:qe,usePublisher:Ut}),Bb=Pu({useEmitter:Fu,useEmitterValue:qe,usePublisher:Ut});function zu(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,kt.WARN),t==="normal"?0:parseInt(t??"0",10)}function Ub({artifact:e,showPartialData:t=!1}){if(!e||typeof e!="object")return null;const n=Do({artifact:e});if(!n)return null;const r=Eg(e),o=n.progress??0,s=n.status??"completed";if(s==="completed"&&!t)return null;const i=()=>{switch(s){case"pending":case"in_progress":return d.jsx(me.Loader2,{className:"h-4 w-4 animate-spin text-blue-500"});case"completed":return d.jsx(me.CheckCircle2,{className:"h-4 w-4 text-green-500"});case"failed":return d.jsx(me.XCircle,{className:"h-4 w-4 text-red-500"});default:return null}},a=()=>{switch(s){case"pending":return"Preparing...";case"in_progress":return o>0?`${o}% complete`:"Processing...";case"completed":return"Complete";case"failed":return n.error??"Failed";default:return""}};return d.jsxs("div",{className:"rounded-md border border-border/40 bg-muted/30 p-3 space-y-2",children:[d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsxs("div",{className:"flex items-center gap-2",children:[i(),d.jsx("span",{className:"text-sm font-medium capitalize",children:n.type.replace(/_/g," ")})]}),d.jsx("span",{className:"text-xs text-muted-foreground",children:a()})]}),r&&o>0&&d.jsx("div",{className:"w-full bg-muted rounded-full h-1.5",children:d.jsx("div",{className:"bg-blue-500 h-1.5 rounded-full transition-all duration-300 ease-out",style:{width:`${o}%`}})}),s==="failed"&&n.error&&d.jsx("div",{className:"text-xs text-red-600 dark:text-red-400 bg-red-50 dark:bg-red-950/20 p-2 rounded",children:n.error}),t&&s==="in_progress"&&e.partial_data&&d.jsxs("div",{className:"text-xs text-muted-foreground",children:[d.jsx("div",{className:"font-medium mb-1",children:"Preview:"}),d.jsx("pre",{className:"bg-background/50 rounded p-2 overflow-auto max-h-32",children:JSON.stringify(e.partial_data,null,2)})]})]})}const Hb="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 Wb({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?d.jsx("div",{className:Hb,children:d.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>d.jsx("li",{children:String(n)},r))})}):d.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:gr(e)}):d.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:gr(e)})}const Bu="data:";function Vb(e){if(!e)return[];const t=[],n=e.split(/\r?\n/);for(const r of n){const o=r.trim();if(!o||!o.startsWith(Bu))continue;const s=o.slice(Bu.length).trim();if(!s||s.toLowerCase()==="[done]")continue;const i=pr(s);i&&typeof i=="object"&&t.push(i)}return t}function Kb(e){for(let t=e.length-1;t>=0;t-=1){const n=e[t];if(n&&typeof n=="object"&&n.type==="tool.end")return n}return null}function Uu(e){return v.useMemo(()=>{const t=e.content.filter(c=>c.type==="text");if(!t.length)return null;let r=t.flatMap(c=>Vb(c.text??""));if(!r.length){const c=t.map(f=>f.text??"").join(`
41
- `),u=pr(c);u&&typeof u=="object"&&(r=[u])}if(!r.length)return null;const s=Kb(r)??r[r.length-1];if(!s)return null;const i=s.output??s.payload??s,a=xr(i),l=Vr(a);return l&&typeof l=="object"&&!Array.isArray(l)?{kind:"dict",value:l,data:l,event:s}:{kind:"generic",value:l,event:s}},[e])}function es({message:e,viewMode:t,isStreaming:n=!1,toolConfig:r,expandable:o=!1,artifactOverride:s=null,contentOverride:i=null}){var O;const{toolRenderers:a,toolArtifactRenderers:l}=r??{},c=dc(e),u=s??e.artifact??null,f=Array.isArray(i)?i:e.content,h=Uu(e),m=(h?hc(h):null)??h,b=f.length>0?f[0]:void 0,g=D=>{if(D==null)return null;const z=typeof D=="string"?D:(()=>{try{return JSON.stringify(D,null,2)}catch{return String(D)}})();return d.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-xs text-muted-foreground/80 bg-muted/30 p-2 rounded border border-border/50",children:z})},w=D=>g(D),y=()=>{if((m==null?void 0:m.kind)==="generic")return w(m.value);if(!b)return null;if(b.type==="text"){const D=b.text??"";return D?w(D):null}return w(b)},k=()=>(m==null?void 0:m.kind)==="dict"?w(m.data):y(),S=(()=>{if(!a)return;if(c.name){const z=a[c.name];if(z)return z}const D=(m==null?void 0:m.kind)??(h==null?void 0:h.kind);if(D){const z=a[D];if(z)return z}return a.default})(),C=k(),T=!o||t==="expanded",A=(T?S==null?void 0:S({message:e,toolMeta:c,toolPayload:m,viewMode:t,isStreaming:n}):null)??null,j=(()=>{if(!l)return;const D=u==null?void 0:u.type;if(typeof D=="string"){const z=l[D];if(z)return z}return l.default})(),L=j?j({artifact:u,message:e,toolPayload:m,isStreaming:n}):null,B=A??C,W=j?L:null;return d.jsxs("div",{className:"space-y-2",children:[n&&d.jsx(Ub,{artifact:u,showPartialData:!1}),u&&W,T&&(((O=r==null?void 0:r.getShowContent)==null?void 0:O.call(r,e))??!0)?B:null]})}const zi=v.memo(function({toolCall:t,index:n,toolName:r,className:o=""}){const{onSelectToolCall:s}=zo(),i=t.state==="pending",a=t.state==="error",l=t.call.name||r||"tool";return d.jsxs("div",{onClick:()=>s==null?void 0:s(t),className:`group/call flex items-start gap-3 px-2 py-1.5 rounded-md hover:bg-muted/30 transition-colors cursor-pointer ${o}`,children:[d.jsx("div",{className:"shrink-0 flex items-center justify-center h-4 mt-0.5",children:d.jsx("span",{className:"text-[10px] font-mono font-medium text-muted-foreground/40 group-hover/call:text-muted-foreground/60 transition-colors",children:n!==void 0?(n+1).toString().padStart(2,"0"):"●"})}),d.jsxs("div",{className:"flex-1 min-w-0",children:[d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx("span",{className:"text-[11px] font-medium text-muted-foreground/70 group-hover/call:text-foreground/80 transition-colors truncate",children:l}),i?d.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[d.jsx("span",{className:"flex h-1.5 w-1.5 rounded-full bg-blue-500 animate-pulse"}),d.jsx("span",{className:"text-[9px] text-blue-500 font-medium lowercase",children:"running"})]}):a?d.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[d.jsx("span",{className:"flex h-1.5 w-1.5 rounded-full bg-red-500"}),d.jsx("span",{className:"text-[9px] text-red-500 font-medium lowercase",children:"error"})]}):d.jsx("div",{className:"flex items-center gap-1 shrink-0 opacity-0 group-hover/call:opacity-100 transition-opacity",children:d.jsx("span",{className:"text-[9px] text-muted-foreground/50 font-medium lowercase",children:"completed"})}),!!t.artifact&&d.jsx("span",{className:"shrink-0 text-[8px] px-1 py-0 rounded bg-primary/10 text-primary/70 font-semibold border border-primary/20 leading-none",children:"Artifact Created"})]}),t.call.content&&d.jsx("p",{className:"text-[10px] text-muted-foreground/60 truncate group-hover/call:text-muted-foreground/80 transition-colors",children:t.call.content}),Array.isArray(t.progress)&&t.progress.length>0&&d.jsx("div",{className:"mt-1 space-y-0.5",children:t.progress.map((c,u)=>{const f=typeof c.content=="string"?c.content:void 0;return f?d.jsx("p",{className:"text-[9px] text-muted-foreground/50 truncate",children:f},`${t.call.id}-progress-${u}`):null})})]})]})});zi.displayName="ToolCallCard";function Hu({messages:e,toolConfig:t,wrapperClassName:n}){var i;const r=((i=e[0])==null?void 0:i.name)??"tool",o=di(e).filter(a=>{var l;return e.length===1&&e[0].role==="tool"?((l=t==null?void 0:t.getShowProgress)==null?void 0:l.call(t,e[0]))??!0:!!a});if(o.length===0)return null;const s=d.jsx("div",{className:"space-y-1",children:o.map((a,l)=>d.jsx(zi,{toolCall:a,index:l,toolName:r},a.call.id||l))});return n?d.jsx("div",{className:n,children:s}):d.jsx("div",{className:"space-y-1 py-1",children:s})}const Wu=x.forwardRef(({className:e,...t},n)=>d.jsx("div",{ref:n,className:fe("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));Wu.displayName="Card";const Vu=x.forwardRef(({className:e,...t},n)=>d.jsx("div",{ref:n,className:fe("flex flex-col space-y-1.5 p-6",e),...t}));Vu.displayName="CardHeader";const Ku=x.forwardRef(({className:e,...t},n)=>d.jsx("h3",{ref:n,className:fe("text-2xl font-semibold leading-none tracking-tight",e),...t}));Ku.displayName="CardTitle";const qu=x.forwardRef(({className:e,...t},n)=>d.jsx("p",{ref:n,className:fe("text-sm text-muted-foreground",e),...t}));qu.displayName="CardDescription";const Bi=x.forwardRef(({className:e,...t},n)=>d.jsx("div",{ref:n,className:fe("p-6 pt-0",e),...t}));Bi.displayName="CardContent";const Gu=x.forwardRef(({className:e,...t},n)=>d.jsx("div",{ref:n,className:fe("flex items-center p-6 pt-0",e),...t}));Gu.displayName="CardFooter";const qb=e=>!!e&&typeof e=="object"&&e.type==="user_choice"&&typeof e.question=="string"&&Array.isArray(e.alternatives);function Yu({interruptPart:e,onApprove:t,onReject:n,onSelectAlternative:r,disabled:o,isActive:s,payload:i}){const a=qb(i)?i:null,l=(a==null?void 0:a.question)??e.title??"Approve the result?",c=a?s?"Select one of the alternatives to continue.":"Waiting for approval from another participant.":s?"Please approve or reject this action to resume the workflow.":"Waiting for approval from another participant.";let u=null;if(!a&&i!==void 0&&i!==null)if(typeof i=="string")u=d.jsx("p",{className:"text-sm leading-relaxed text-blue-800/90 dark:text-blue-200/90 whitespace-pre-wrap",children:i});else{const f=gr(i);u=d.jsx("pre",{className:"max-h-48 overflow-auto rounded bg-blue-100/60 p-2 text-xs text-blue-900/90 dark:bg-blue-900/40 dark:text-blue-100/80",children:f})}return d.jsxs(Wu,{className:fe("border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10 transition-shadow",s?"shadow-md ring-1 ring-blue-300 dark:ring-blue-500/70":"opacity-80"),children:[d.jsxs(Vu,{className:"pb-3",children:[d.jsx(Ku,{className:"text-blue-900 dark:text-blue-100 text-base",children:l}),d.jsx(qu,{className:"text-blue-700 dark:text-blue-300 text-sm",children:c})]}),a?d.jsx(Bi,{className:"pt-0 pb-3",children:d.jsx("div",{className:"space-y-2",children:a.alternatives.map(f=>d.jsx(Je,{size:"sm",variant:"outline",onClick:()=>r==null?void 0:r(e,f),className:"w-full justify-start text-left",disabled:o||!s,children:d.jsxs("div",{className:"flex flex-col items-start gap-1",children:[d.jsx("span",{className:"font-semibold",children:f.label}),f.description?d.jsx("span",{className:"text-xs text-muted-foreground leading-snug",children:f.description}):null]})},f.id))})}):u&&d.jsx(Bi,{className:"pt-0 pb-3",children:u}),!a&&d.jsx(Gu,{className:"pt-0",children:d.jsxs("div",{className:"flex gap-2 ml-auto",children:[d.jsx(Je,{size:"sm",variant:"outline",onClick:()=>n(e),className:"border-red-300 text-red-700 hover:bg-red-50 dark:border-red-700 dark:text-red-300 dark:hover:bg-red-950/50",disabled:o||!s,children:"Reject"}),d.jsx(Je,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:o||!s,children:"Approve"})]})})]})}function Gb({className:e}){const t=v.useRef(null);return v.useEffect(()=>{let n=0;const r=()=>{if(n=(n+1)%4,t.current){const s=".".repeat(n);t.current.textContent=`Is thinking${s}`}};r();const o=setInterval(r,500);return()=>clearInterval(o)},[]),d.jsx("span",{ref:t,"aria-live":"polite",className:fe("inline-block text-xs opacity-70 ml-1",e),children:"Is thinking"})}function Xu(){return{async:!1,baseUrl:null,breaks:!1,extensions:null,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,hooks:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartypants:!1,tokenizer:null,walkTokens:null,xhtml:!1}}let Jn=Xu();function Yb(e){Jn=e}const Ju=/[&<>"']/,Xb=new RegExp(Ju.source,"g"),Zu=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,Jb=new RegExp(Zu.source,"g"),Zb={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Qu=e=>Zb[e];function dt(e,t){if(t){if(Ju.test(e))return e.replace(Xb,Qu)}else if(Zu.test(e))return e.replace(Jb,Qu);return e}const Qb=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function ed(e){return e.replace(Qb,(t,n)=>(n=n.toLowerCase(),n==="colon"?":":n.charAt(0)==="#"?n.charAt(1)==="x"?String.fromCharCode(parseInt(n.substring(2),16)):String.fromCharCode(+n.substring(1)):""))}const ew=/(^|[^\[])\^/g;function Ue(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(ew,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const tw=/[^\w:]/g,nw=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function td(e,t,n){if(e){let r;try{r=decodeURIComponent(ed(n)).replace(tw,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!nw.test(n)&&(n=iw(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const ts={},rw=/^[^:]+:\/*[^/]*$/,ow=/^([^:]+:)[\s\S]*$/,sw=/^([^:]+:\/*[^/]*)[\s\S]*$/;function iw(e,t){ts[" "+e]||(rw.test(e)?ts[" "+e]=e+"/":ts[" "+e]=rs(e,"/",!0)),e=ts[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(ow,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(sw,"$1")+t:e+t}const ns={exec:function(){}};function nd(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,c=i;for(;--c>=0&&a[c]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function rs(e,t,n){const r=e.length;if(r===0)return"";let o=0;for(;o<r;){const s=e.charAt(r-o-1);if(s===t&&!n)o++;else if(s!==t&&n)o++;else break}return e.slice(0,r-o)}function aw(e,t){if(e.indexOf(t[1])===-1)return-1;const n=e.length;let r=0,o=0;for(;o<n;o++)if(e[o]==="\\")o++;else if(e[o]===t[0])r++;else if(e[o]===t[1]&&(r--,r<0))return o;return-1}function lw(e){e&&e.sanitize&&!e.silent&&console.warn("marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options")}function rd(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function od(e,t,n,r){const o=t.href,s=t.title?dt(t.title):null,i=e[1].replace(/\\([\[\]])/g,"$1");if(e[0].charAt(0)!=="!"){r.state.inLink=!0;const a={type:"link",raw:n,href:o,title:s,text:i,tokens:r.inlineTokens(i)};return r.state.inLink=!1,a}return{type:"image",raw:n,href:o,title:s,text:dt(i)}}function cw(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
39
+ `))>=0;){const sr=Wt.slice(0,vn);Wt=Wt.slice(vn+2);const Rr=sr.split(/\r?\n/),zn=[];let ir=null;for(const K of Rr){if(K.startsWith(":")){K.startsWith(": heartbeat")&&console.debug("[use-chat] SSE heartbeat comment received");continue}if(K){if(K.startsWith("event:")){const se=K.slice(6).trim();se&&(ir=se);continue}if(K.startsWith("data:")){const se=K.slice(5);zn.push(se.startsWith(" ")?se.slice(1):se)}}}const Bn=zn.join(`
40
+ `);if(!Bn)continue;let I;try{I=JSON.parse(Bn)}catch{console.debug("[use-chat] malformed SSE:",Bn.slice(0,200));continue}if(ir&&typeof I=="object"&&I!==null){const K=I;"type"in K||(K.type=ir)}const ee=yc(I)?I.data:I;if(!ee){console.warn("[use-chat] dropped envelope event without payload",I);continue}const Q=cg(ee);Qt=Date.now();const L=typeof Q.seq=="number"?Q.seq:void 0;if(L!==void 0){if(L<=Vt){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:L,lastProcessedSeq:Vt,type:Q.type});continue}Vt>0&&L>Vt+1&&((Ie=A==null?void 0:A.onGap)==null||Ie.call(A,{from:Vt,to:L})),Vt=L,D.current=L,g(L)}if(Q.type==="checkpoint")H.current=Q.checkpointId??null,P.current=Q.checkpointNs??null,m(Q.checkpointId??null);else if(Q.type==="state_history"){const K=Q;M.current=K;try{const ie=pr(K).latest;ie&&(H.current=ie.checkpointId??null,P.current=ie.checkpointNs??null,m(ie.checkpointId??null),N(ie.values??{}))}catch(se){console.warn("[use-chat] Failed to hydrate state_history payload",se)}}try{G==null||G(Q)}catch(K){console.error("[use-chat] Error in onEvent callback:",K,"for event:",Q.type)}try{Q.type==="tool.start"&&(A!=null&&A.onToolStart)?A.onToolStart(Q):Q.type==="tool.end"&&(A!=null&&A.onToolEnd)?A.onToolEnd(Q):Q.type==="updates"&&(A!=null&&A.onUpdateEvent)?A.onUpdateEvent(Q):Q.type==="custom"&&(A!=null&&A.onCustomEvent)?A.onCustomEvent(Q):Q.type==="thread_info"&&(A!=null&&A.onThreadInfoEvent)&&A.onThreadInfoEvent(Q)}catch(K){console.warn("[use-chat] Typed callback error:",K)}if(ex(Q)){const{messages:K}=Q;if(K.length>0){const se=K.find(fe=>fe.type==="ai"),ie=K.find(fe=>fe.type==="tool");if(se){const fe=se.id,je=se.content??"";if(F.current.messageId!==fe){const ve=se.name??((qe=se.additionalKwargs)==null?void 0:qe.agentName)??"assistant";F.current={messageId:fe,lastSeq:null,lastText:""};const me=Mo({id:fe,role:"assistant",name:ve,model:ve,createdAt:new Date().toISOString(),content:[{type:"text",text:je}]});E(Oe=>({...Oe,[fe]:me})),C(fe)}else E(ve=>{const me=ve[fe];return me?{...ve,[fe]:{...me,content:[{type:"text",text:je}]}}:ve});const _e=F.current.lastText||"";if(je.length>_e.length){const ve=je.slice(_e.length);F.current.lastText=je,e.autoAppendAssistant!==!1&&(fn.push(ve),$n())}}if(ie){const fe=ie.id||`tool-${Date.now()}`,je=Mo({id:fe,role:"tool",content:ie.content??"",createdAt:new Date().toISOString()});E(_e=>({..._e,[fe]:je}))}}}else if(Q.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(We=A==null?void 0:A.onHeartbeat)==null||We.call(A,Q)}catch(K){console.warn("[use-chat] heartbeat callback failed",K)}}else if(Lt!==null&&cancelAnimationFrame(Lt),it(),Q.type==="checkpoint")m(Q.checkpointId??null);else if(Q.type==="error"){const K=Q;if(u(K.message),V="error",Z=K.message,K.error_type==="auth_error"||K.code==="TOKEN_EXPIRED"||((Fe=K.message)==null?void 0:Fe.includes("token"))||((ze=K.message)==null?void 0:ze.includes("401"))||((It=K.message)==null?void 0:It.includes("unauthorized"))||((At=K.message)==null?void 0:At.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",K.message);try{(bt=A==null?void 0:A.onAuthError)==null||bt.call(A,K.message)}catch(ie){console.warn("[use-chat] onAuthError handler failed",ie)}O.abort()}}}}it(),V===null&&!O.signal.aborted&&(V="complete")}catch(Ge){if(Ge.name==="AbortError")V=V??"aborted";else{const Qe=Ge.message||String(Ge);V="error",Z=Qe,u(Qe),(wt=A==null?void 0:A.onError)==null||wt.call(A,Qe)}}finally{try{await Ht.cancel()}catch{}finally{(ht=Ht.releaseLock)==null||ht.call(Ht)}Lt!==null&&typeof window<"u"&&window.cancelAnimationFrame(Lt),clearInterval(wn)}}catch(nt){if(nt.name==="AbortError")V=V??"aborted";else{const Ze=nt.message||String(nt);V="error",Z=Ze,u(Ze),(st=A==null?void 0:A.onError)==null||st.call(A,Ze),$||((Nt=A==null?void 0:A.onConnectionError)==null||Nt.call(A,Ze),$=!0)}}finally{const nt=D.current,Ze=H.current,yt=P.current,Be=M.current,Le=V??(O.signal.aborted?"aborted":Z?"error":"complete");try{(jt=A==null?void 0:A.onClosed)==null||jt.call(A,{reason:Le,lastSeq:nt,lastCheckpointId:Ze,lastCheckpointNs:yt,lastStateHistory:Be,error:Z}),Le==="complete"&&((Ut=A==null?void 0:A.onFinish)==null||Ut.call(A,{lastSeq:nt,lastCheckpointId:Ze,lastCheckpointNs:yt,lastStateHistory:Be}))}catch(Ht){console.warn("[use-chat] onClosed callback failed",Ht)}l(!1),y(!1),j.current=null,D.current=0,g(0),z.current=null}})(),{close:()=>O.abort()}},[t,n,r,e.autoAppendAssistant]);return v.useEffect(()=>()=>{var R;_.current=!1,(R=j.current)==null||R.abort()},[]),{isStreaming:a,error:c,assistantText:f,activeMessageId:S,streamedMessages:k,lastCheckpointId:p,lastSeq:b,connected:w,stream:q,stop:Y,clear:U,setToken:ne,values:T,interrupt:()=>Promise.resolve(),resume:()=>Promise.resolve(),goto:()=>Promise.resolve()}}const vc=v.createContext(null);function sx({options:e,children:t}){return v.createElement(vc.Provider,{value:e},t)}function ix(){return v.useContext(vc)||{}}const Sc=v.createContext(null);function ax({children:e}){const{baseUrl:t}=fr(),n=ix(),r=ox({...n,baseUrl:t});return d.jsx(Sc.Provider,{value:r,children:e})}function lx(){const e=v.useContext(Sc);if(!e)throw new Error("useStream must be used within a StreamStateProvider");return e}async function Cc(e){return await new Promise((t,n)=>{const r=new FileReader;r.onload=()=>{try{const o=r.result,s=new Uint8Array(o);let i="";const a=s.byteLength;for(let l=0;l<a;l++)i+=String.fromCharCode(s[l]);t(btoa(i))}catch(o){n(o)}},r.onerror=o=>n(o),r.readAsArrayBuffer(e)})}async function Tc(e=[]){const t=[],n=[];for(const r of e)try{const o=await Cc(r),s=r.type||"application/octet-stream";n.push({filename:r.name,data:o,mime_type:s}),s.startsWith("image/")?t.push({type:"image_url",image_url:{url:`data:${s};base64,${o}`}}):t.push({type:"file",url:`data:${s};base64,${o}`,mimeType:s,name:r.name,size:r.size})}catch{}return{contentParts:t,filesInfo:n}}function kc(e,t){if(!e)return null;const n=Kn(e);if(!n)return null;const r=Kn(n.configurable)??n;return Hr(r,t)??null}function cx(e){const t=kc(e,["checkpoint_id","checkpointId"]);if(!t)return null;const n=kc(e,["checkpoint_ns","checkpointNs"]);return{checkpointId:t,checkpointNs:n}}function ux(e,t){const n=typeof e.step=="number"?e.step:Number.POSITIVE_INFINITY,r=typeof t.step=="number"?t.step:Number.POSITIVE_INFINITY;if(n!==r)return n-r;const o=e.createdAt?Date.parse(e.createdAt):0,s=t.createdAt?Date.parse(t.createdAt):0;return o-s}function dx(e,t){const n=[...e].sort(ux);for(const r of n){if(r.messageId!==t)continue;const o=cx(r.parentConfig);if(!o)throw new Error(`Parent checkpoint info missing for message ${t}`);return o}throw new Error(`Message ${t} not found in timeline`)}function Ec(){const{stream:e,stop:t,clear:n,isStreaming:r,error:o,connected:s,streamedMessages:i}=lx(),{setCurrentThreadId:a,currentThreadIdRef:l,addThreadFromEvent:c,currentThreadId:u}=Ur(),{interrupt:f,checkpoint:h,timelineCheckpoints:p,handleStateHistoryEvent:m,markSkipNextLoad:b,markStreamPendingThread:g,resetHistoryState:w,pushUser:y,onEvent:k,messages:E}=Kr(),{registerClearThread:S,registerRespondToInterrupt:C}=jc();v.useEffect(()=>{u!==void 0&&n()},[u,n]);const T=v.useCallback(M=>{c(M),l.current!==M.threadId&&((M.created??!l.current)&&b(M.threadId),g(M.threadId),a(M.threadId))},[c,b,g,a,l]),N=v.useCallback(M=>{M.type==="thread_info"?T(M):M.type==="state_history"?m(M):(M.type,k(M))},[T,m,k]),j=v.useCallback((M,F)=>{e(M,ne=>{N(ne),F==null||F(ne)},{})},[e,N]),_=v.useRef(h);v.useEffect(()=>{_.current=h},[h]);const D=v.useCallback(async(M,F,ne)=>{const U=l.current;if(!U)throw new Error("No active thread to handle interrupt");const W=M?F??!0:!1,Y=_.current,q={threadId:U,checkpointId:Y.id??void 0,checkpointNs:Y.namespace??void 0,command:{kind:"resume",value:W},payload:ne==null?void 0:ne.payload};j(q)},[l,j]);v.useEffect(()=>{C(D)},[D,C]);const z=v.useCallback(async()=>{n(),w(),a(null)},[n,w,a]);v.useEffect(()=>{S(z)},[z,S]);const H=v.useCallback(async(M,F)=>{r&&t("submit");let ne=l.current;const U=(M==null?void 0:M.text)??"",W=(M==null?void 0:M.attachments)??[],Y=(U==null?void 0:U.trim())??"",q={...(M==null?void 0:M.payload)??{}},R=Array.isArray(q.messages)?q.messages:void 0;R&&delete q.messages;const G=!!(R&&R.length),A=!!(M.contentParts&&M.contentParts.length>0);if(!ne&&!Y&&W.length===0&&!G&&!A)return;if(!ne){const Fe=Math.floor(Date.now()/1e3).toString(16).padStart(8,"0"),ze=Array.from({length:4},()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0")).join("").slice(0,16);ne=`${Fe}${ze}`,b(ne),a(ne)}let O=null;M.contentParts&&M.contentParts.length>0&&(O=M.contentParts);const{contentParts:V,filesInfo:Z}=O?{contentParts:O,filesInfo:[]}:await Tc(W),$=[...V];Y&&$.push({type:"text",text:U});const X=F==null?void 0:F.originalMessageId,oe=!!(F!=null&&F.edit&&X),ue=!G&&$.length>0;let le=null;if(ue){const Fe=oe?X:`msg-${Date.now()}`;le=wc({id:Fe,role:"user",content:$,createdAt:new Date().toISOString()},"user"),oe?y(le,{editingMessageId:X}):y(le)}const Ce=G?R:le?[le]:[],De={...q,...Z.length?{files_info:Z}:{}};Ce.length?De.messages=Ce:"messages"in De||(De.messages=[]);let Ie=(F==null?void 0:F.checkpointId)??h.id??void 0,qe=(F==null?void 0:F.checkpointNs)??h.namespace??void 0;if(oe&&X){const Fe=dx(p,X);Ie=Fe.checkpointId,qe=Fe.checkpointNs??void 0}const We={threadId:ne,payload:De,checkpointId:Ie,checkpointNs:qe,config:F==null?void 0:F.config,edit:!!(F!=null&&F.edit)};j(We,F==null?void 0:F.onEvent)},[h,l,r,b,y,j,t,p]),P=v.useMemo(()=>{if(!r||Object.keys(i).length===0)return E;const M=[...E];return Object.values(i).forEach(F=>{const ne=M.findIndex(U=>U.id===F.id);ne>=0?M[ne]=F:M.push(F)}),M},[r,i,E]);return{isStreaming:r,error:o,connectionState:o?"error":r?s?"connected":"connecting":"idle",messages:P,submit:H,stop:t,interrupt:f,resume:()=>Promise.resolve(),goto:(M,F)=>Promise.resolve(),clearError:()=>{}}}function fx(){return!0}function Ic(e){const t=e.artifact&&typeof e.artifact=="object"?e.artifact:null,n=!t&&e.content&&typeof e.content=="object"?e.content:null,r=t??n,o=(r==null?void 0:r.task_id)??(r==null?void 0:r.taskId)??null;return typeof o=="string"?o:null}function hx(e){const{setCurrentTaskId:t,getCurrentTaskId:n,onToolEnd:r}=e;return o=>{const s=Ic(o),i=(n==null?void 0:n())??null;s&&s!==i&&t(s),r==null||r(o)}}const Ac=v.createContext(null),Nc=v.createContext(null);function Kr(){const e=v.useContext(Ac);if(!e)throw new Error("useThreadState must be used within a ThreadStateProvider");return e}function jc(){const e=v.useContext(Nc);if(!e)throw new Error("useThreadStateUpdater must be used within a ThreadStateProvider");return e}function _c({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,onError:s}){const{chatApi:i}=fr(),{currentThreadId:a}=Ur(),l=rx(),{state:c,seed:u,onEvent:f,dispatch:h}=Hg(),{threadCheckpoints:p,threadTimeline:m,checkpointIndex:b,isLoadingThread:g,isLoadingCheckpoint:w,threadStateError:y,loadThread:k,navigateToCheckpoint:E,setCurrentCheckpointId:S,returnToLatest:C,handleStateHistoryEvent:T,markSkipNextLoad:N,markStreamPendingThread:j,resetHistoryState:_}=bc({api:i,seed:u,onError:s,currentThreadId:a,initialThreadId:t,initialCheckpointId:n,initialCheckpointNs:r,autoLoadInitial:o,isStreaming:l,getMessages:v.useCallback(()=>c.messages,[c.messages])});v.useEffect(()=>{a||(u([],{}),_())},[a,u,_]);const D=v.useRef(null),z=v.useCallback(q=>{D.current=q},[]),H=v.useRef(null),P=v.useCallback(q=>{H.current=q},[]),M=v.useMemo(()=>({assemblingMessageId:c.assemblingId??null}),[c.assemblingId]),F=v.useCallback((q,R)=>{const G=wc(q,"user");return h({type:"user_message",payload:{message:G,editingMessageId:R==null?void 0:R.editingMessageId}}),G},[h]),ne=v.useCallback(async()=>{D.current?await D.current():(u([],{}),_())},[u,_]),U=v.useMemo(()=>Tg(c.messages),[c.messages]),W=v.useMemo(()=>({threadId:a,messages:c.messages,interrupt:c.pendingInterrupt,checkpoint:{id:c.lastCheckpointId??null,namespace:c.lastCheckpointNs??null},checkpoints:p,checkpointIndex:b,timelineCheckpoints:m,metadata:M,values:c.values??{},isLoading:g,isLoadingCheckpoint:w,error:y,loadOlder:async()=>{},seedFromSnapshot:q=>{u(q.messages,{checkpointId:q.checkpointId,checkpointNs:q.checkpointNs,pendingInterrupt:q.interrupt})},clearState:ne,navigateToCheckpoint:E,setCurrentCheckpointId:S,returnToLatest:C,loadThread:async(q,R,G)=>{await k(q,R,{clearProgress:!1})},clearThread:ne,respondToInterrupt:async(q,R,G)=>{H.current&&await H.current(q,R,G)},messagePreviews:b.messagePreviews,handleStateHistoryEvent:T,markSkipNextLoad:N,markStreamPendingThread:j,resetHistoryState:_,pushUser:F,onEvent:f,artifacts:U}),[a,c.messages,c.pendingInterrupt,c.lastCheckpointId,c.lastCheckpointNs,c.values,p,m,b,M,g,w,y,u,ne,E,S,C,k,T,N,j,F,f,U]),Y=v.useMemo(()=>({registerClearThread:z,registerRespondToInterrupt:P}),[z,P]);return d.jsx(Nc.Provider,{value:Y,children:d.jsx(Ac.Provider,{value:W,children:e})})}const Pc=v.createContext(null);function Rc({children:e,...t}){return d.jsx(Pc.Provider,{value:t,children:e})}function zo(){const e=v.useContext(Pc);if(!e)throw new Error("useChatUI must be used within a ChatUIProvider");return e}function Oc(e){return typeof e=="object"&&e!==null}function px(e,t){if(Object.is(e,t))return!0;if(!Oc(e)||!Oc(t))return!1;const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const o of n)if(!Object.prototype.hasOwnProperty.call(t,o)||!Object.is(e[o],t[o]))return!1;return!0}function Mc(e){const t=v.useRef(e),n=v.useRef(e);return px(t.current,e)||(t.current=e,n.current=e),n.current}function qr({children:e,apiConfig:t,initialThreadId:n=null,initialCheckpointId:r=null,initialCheckpointNs:o=null,autoLoadInitial:s=!0,onError:i,onThreadChange:a,onFinish:l,onAuthError:c,onConnectionError:u,onToolEnd:f,onThreadInfoEvent:h,onToolStart:p,onUpdateEvent:m,onCustomEvent:b,onEvent:g}){const w=Mc(t),y=qt(i),k=qt(a),E=qt(l),S=qt(c),C=qt(u),T=qt(f),N=qt(h),j=qt(p),_=qt(m),D=qt(b),z=qt(g),H=v.useMemo(()=>({onError:y,onAuthError:S,onConnectionError:C,onToolEnd:T,onToolStart:j,onEvent:z,onUpdateEvent:_,onCustomEvent:D,onThreadInfoEvent:N,onFinish:E}),[y,S,C,T,j,z,_,D,N,E]);return d.jsx(nc,{apiConfig:w,children:d.jsx(sx,{options:H,children:d.jsx(ax,{children:d.jsx(sc,{initialThreadId:n,onError:y,onThreadChange:k,children:d.jsx(_c,{initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:y,children:e})})})})})}function qt(e){const t=v.useRef(e);return t.current=e,v.useCallback((...n)=>{const r=t.current;if(r)return r(...n)},[])}function xr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function Dc(){const e=[xr("__API_BASE_URL__"),xr("__CHAT_API_BASE_URL__"),xr("__CHAT_API_URL__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim().replace(/\/+$/,"")}function Lc(){const e=[xr("__API_AUTH_TOKEN__"),xr("__CHAT_API_KEY__"),xr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function $c(...e){for(const t of e)if(typeof t=="string"&&t.trim())return t.trim().replace(/\/+$/,"");return""}function Fc(){const e={},t=Dc(),n=Lc();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function zc(){const e=Fc(),t=Tn.getAuthToken(),n=Dc();return{apiBaseUrl:$c(e.baseUrl,n),apiKey:t||e.apiKey||Lc()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const gi=Sn.chatSettings;function Bc(){try{const e=localStorage.getItem(gi);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function Uc(e){try{const t={...e,apiBaseUrl:e.apiBaseUrl.trim().replace(/\/+$/,"")};localStorage.setItem(gi,JSON.stringify(t)),t.apiKey&&Tn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function mx(){const e=zc(),t=Bc(),n=Tn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:$c(Tn.baseUrl,r,e.apiBaseUrl)}}function gx(e){Tn.updateConfig({baseUrl:e.apiBaseUrl,apiKey:e.apiKey??void 0}),Uc(e)}function he(...e){return Un.twMerge(vt.clsx(e))}const xx=jp.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"}}),Je=x.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?lr.Slot:"button";return d.jsx(i,{className:he(xx({variant:t,size:n,className:e})),ref:s,...o})});Je.displayName="Button";const Bo=0,En=1,br=2,Hc=4;function Wc(e){return()=>e}function bx(e){e()}function Vc(e,t){return n=>e(t(n))}function Kc(e,t){return()=>e(t)}function wx(e,t){return n=>e(t,n)}function xi(e){return e!==void 0}function yx(...e){return()=>{e.map(bx)}}function wr(){}function Uo(e,t){return t(e),e}function vx(e,t){return t(e)}function Ve(...e){return e}function Me(e,t){return e(En,t)}function ke(e,t){e(Bo,t)}function bi(e){e(br)}function tt(e){return e(Hc)}function de(e,t){return Me(e,wx(t,Bo))}function Gt(e,t){const n=e(En,r=>{n(),t(r)});return n}function qc(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Gc(e,t){return e===t}function Ke(e=Gc){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function we(e){return t=>n=>{e(n)&&t(n)}}function ae(e){return t=>Vc(t,e)}function tn(e){return t=>()=>{t(e)}}function te(e,...t){const n=Sx(...t);return(r,o)=>{switch(r){case br:bi(e);return;case En:return Me(e,n(o))}}}function nn(e,t){return n=>r=>{n(t=e(t,r))}}function qn(e){return t=>n=>{e>0?e--:t(n)}}function gn(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Ee(...e){const t=new Array(e.length);let n=0,r=null;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Me(s,l=>{const c=n;n=n|a,t[i]=l,c!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function Sx(...e){return t=>e.reduceRight(vx,t)}function Cx(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case En:return s?n===s?void 0:(r(),n=s,t=Me(e,s),t):(r(),wr);case br:r(),n=null;return}}}function re(e){let t=e;const n=Ne();return(r,o)=>{switch(r){case Bo:t=o;break;case En:{o(t);break}case Hc:return t}return n(r,o)}}function ct(e,t){return Uo(re(t),n=>de(e,n))}function Ne(){const e=[];return(t,n)=>{switch(t){case Bo:e.slice().forEach(r=>{r(n)});return;case br:e.splice(0,e.length);return;case En:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function _t(e){return Uo(Ne(),t=>de(e,t))}function Re(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:Tx(),singleton:n}}const Tx=()=>Symbol();function kx(e){const t=new Map,n=({constructor:r,dependencies:o,id:s,singleton:i})=>{if(i&&t.has(s))return t.get(s);const a=r(o.map(l=>n(l)));return i&&t.set(s,a),a};return n(e)}function rt(...e){const t=Ne(),n=new Array(e.length);let r=0;const o=Math.pow(2,e.length)-1;return e.forEach((s,i)=>{const a=Math.pow(2,i);Me(s,l=>{n[i]=l,r=r|a,r===o&&ke(t,n)})}),function(s,i){switch(s){case br:{bi(t);return}case En:return r===o&&i(n),Me(t,i)}}}function be(e,t=Gc){return te(e,Ke(t))}function wi(...e){return function(t,n){switch(t){case br:return;case En:return yx(...e.map(r=>Me(r,n)))}}}var kt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(kt||{});const Ex={0:"debug",3:"error",1:"log",2:"warn"},Ix=()=>typeof globalThis>"u"?window:globalThis,In=Re(()=>{const e=re(3);return{log:re((t,n,r=1)=>{var o;const s=(o=Ix().VIRTUOSO_LOG_LEVEL)!=null?o:tt(e);r>=s&&console[Ex[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function Gn(e,t,n){return yi(e,t,n).callbackRef}function yi(e,t,n){const r=v.useRef(null);let o=i=>{};const s=v.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const a=()=>{const l=i[0].target;l.offsetParent!==null&&e(l)};n?a():requestAnimationFrame(a)}):null,[e,n]);return o=i=>{i&&t?(s==null||s.observe(i),r.current=i):(r.current&&(s==null||s.unobserve(r.current)),r.current=null)},{callbackRef:o,ref:r}}function Ax(e,t,n,r,o,s,i,a,l){const c=v.useCallback(u=>{const f=Nx(u.children,t,a?"offsetWidth":"offsetHeight",o);let h=u.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const p=h.lastElementChild.dataset.viewportType==="window";let m;p&&(m=h.ownerDocument.defaultView);const b=i?a?i.scrollLeft:i.scrollTop:p?a?m.scrollX||m.document.documentElement.scrollLeft:m.scrollY||m.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,g=i?a?i.scrollWidth:i.scrollHeight:p?a?m.document.documentElement.scrollWidth:m.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,w=i?a?i.offsetWidth:i.offsetHeight:p?a?m.innerWidth:m.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:g,scrollTop:Math.max(b,0),viewportHeight:w}),s==null||s(a?Yc("column-gap",getComputedStyle(u).columnGap,o):Yc("row-gap",getComputedStyle(u).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return yi(c,n,l)}function Nx(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const l=parseInt(a.dataset.index),c=parseFloat(a.dataset.knownSize),u=t(a,n);if(u===0&&r("Zero-sized element, this should not happen",{child:a},kt.ERROR),u===c)continue;const f=s[s.length-1];s.length===0||f.size!==u||f.endIndex!==l-1?s.push({endIndex:l,size:u,startIndex:l}):s[s.length-1].endIndex++}return s}function Yc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,kt.WARN),t==="normal"?0:parseInt(t??"0",10)}function Xc(e,t,n){const r=v.useRef(null),o=v.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const c=l.getBoundingClientRect(),u=c.width;let f,h;if(t){const p=t.getBoundingClientRect(),m=c.top-p.top;h=p.height-Math.max(0,m),f=m+t.scrollTop}else{const p=i.current.ownerDocument.defaultView;h=p.innerHeight-Math.max(0,c.top),f=c.top+p.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:u},e(r.current)},[e,t]),{callbackRef:s,ref:i}=yi(o,!0,n),a=v.useCallback(()=>{o(i.current)},[o,i]);return v.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const c=new ResizeObserver(()=>{requestAnimationFrame(a)});return c.observe(t),()=>{t.removeEventListener("scroll",a),c.unobserve(t)}}else{const c=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return c==null||c.addEventListener("scroll",a),c==null||c.addEventListener("resize",a),()=>{c==null||c.removeEventListener("scroll",a),c==null||c.removeEventListener("resize",a)}}},[a,t,i]),s}const gt=Re(()=>{const e=Ne(),t=Ne(),n=re(0),r=Ne(),o=re(0),s=Ne(),i=Ne(),a=re(0),l=re(0),c=re(0),u=re(0),f=Ne(),h=Ne(),p=re(!1),m=re(!1),b=re(!1);return de(te(e,ae(({scrollTop:g})=>g)),t),de(te(e,ae(({scrollHeight:g})=>g)),i),de(t,o),{deviation:n,fixedFooterHeight:c,fixedHeaderHeight:l,footerHeight:u,headerHeight:a,horizontalDirection:m,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:b,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Gr={lvl:0};function Jc(e,t){const n=e.length;if(n===0)return[];let{index:r,value:o}=t(e[0]);const s=[];for(let i=1;i<n;i++){const{index:a,value:l}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=l}return s.push({end:1/0,start:r,value:o}),s}function Ue(e){return e===Gr}function Yr(e,t){if(!Ue(e))return t===e.k?e.v:t<e.k?Yr(e.l,t):Yr(e.r,t)}function Yt(e,t,n="k"){if(Ue(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=Yt(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return Yt(e.l,t,n)}function Pt(e,t,n){return Ue(e)?eu(t,n,1):t===e.k?ot(e,{k:t,v:n}):t<e.k?tu(ot(e,{l:Pt(e.l,t,n)})):tu(ot(e,{r:Pt(e.r,t,n)}))}function yr(){return Gr}function Ho(e,t,n){if(Ue(e))return[];const r=Yt(e,t)[0];return jx(Si(e,r,n))}function vi(e,t){if(Ue(e))return Gr;const{k:n,l:r,r:o}=e;if(t===n){if(Ue(r))return o;if(Ue(o))return r;{const[s,i]=Qc(r);return Wo(ot(e,{k:s,l:Zc(r),v:i}))}}else return t<n?Wo(ot(e,{l:vi(r,t)})):Wo(ot(e,{r:vi(o,t)}))}function Yn(e){return Ue(e)?[]:[...Yn(e.l),{k:e.k,v:e.v},...Yn(e.r)]}function Si(e,t,n){if(Ue(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(Si(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(Si(s,t,n))),a}function Wo(e){const{l:t,lvl:n,r}=e;if(r.lvl>=n-1&&t.lvl>=n-1)return e;if(n>r.lvl+1){if(Ci(t))return nu(ot(e,{lvl:n-1}));if(!Ue(t)&&!Ue(t.r))return ot(t.r,{l:ot(t,{r:t.r.l}),lvl:n,r:ot(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(Ci(e))return Ti(ot(e,{lvl:n-1}));if(!Ue(r)&&!Ue(r.l)){const o=r.l,s=Ci(o)?r.lvl-1:r.lvl;return ot(o,{l:ot(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:Ti(ot(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function ot(e,t){return eu(t.k!==void 0?t.k:e.k,t.v!==void 0?t.v:e.v,t.lvl!==void 0?t.lvl:e.lvl,t.l!==void 0?t.l:e.l,t.r!==void 0?t.r:e.r)}function Zc(e){return Ue(e.r)?e.l:Wo(ot(e,{r:Zc(e.r)}))}function Ci(e){return Ue(e)||e.lvl>e.r.lvl}function Qc(e){return Ue(e.r)?[e.k,e.v]:Qc(e.r)}function eu(e,t,n,r=Gr,o=Gr){return{k:e,l:r,lvl:n,r:o,v:t}}function tu(e){return Ti(nu(e))}function nu(e){const{l:t}=e;return!Ue(t)&&t.lvl===e.lvl?ot(t,{r:ot(e,{l:t.r})}):e}function Ti(e){const{lvl:t,r:n}=e;return!Ue(n)&&!Ue(n.r)&&n.lvl===t&&n.r.lvl===t?ot(n,{l:ot(e,{r:n.l}),lvl:t+1}):e}function jx(e){return Jc(e,({k:t,v:n})=>({index:t,value:n}))}function ru(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Xr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const ki=Re(()=>({recalcInProgress:re(!1)}),[],{singleton:!0});function ou(e,t,n){return e[Vo(e,t,n)]}function Vo(e,t,n,r=0){let o=e.length-1;for(;r<=o;){const s=Math.floor((r+o)/2),i=e[s],a=n(i,t);if(a===0)return s;if(a===-1){if(o-r<2)return s-1;o=s-1}else{if(o===r)return s;r=s+1}}throw new Error(`Failed binary finding record in array - ${e.join(",")}, searched for ${t}`)}function _x(e,t,n,r){const o=Vo(e,t,r),s=Vo(e,n,r,o);return e.slice(o,s+1)}function An(e,t){return Math.round(e.getBoundingClientRect()[t])}function Ko(e){return!Ue(e.groupOffsetTree)}function Ei({index:e},t){return t===e?0:t<e?-1:1}function Px(){return{groupIndices:[],groupOffsetTree:yr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:yr()}}function Rx(e,t){let n=Ue(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),Ue(e)){e=Pt(e,0,s);continue}const a=Ho(e,i-1,o+1);if(a.some(zx(r)))continue;let l=!1,c=!1;for(const{end:u,start:f,value:h}of a)l?(o>=f||s===h)&&(e=vi(e,f)):(c=h!==s,l=!0),u>o&&o>=f&&h!==s&&(e=Pt(e,o+1,h));c&&(e=Pt(e,i,s))}return[e,n]}function Ox(e){return typeof e.groupIndex<"u"}function Mx({offset:e},t){return t===e?0:t<e?-1:1}function Jr(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=ou(t,e,Ei),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function su(e,t){if(!Ko(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function iu(e,t,n){if(Ox(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=su(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function Dx(e,t,n,r=0){return r>0&&(t=Math.max(t,ou(e,r,Ei).offset)),Jc(_x(e,t,n,Mx),Fx)}function Lx(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,kt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&Ue(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((m,b)=>Pt(Pt(m,b,h),b+1,p),i)}else[i,a]=Rx(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:c,lastSize:u,offsetTree:f}=Ii(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>Pt(h,p,Jr(p,f,o)),yr()),lastIndex:l,lastOffset:c,lastSize:u,offsetTree:f,sizeTree:i}}function $x(e){return Yn(e).map(({k:t,v:n},r,o)=>{const s=o[r+1];return{endIndex:s?s.k-1:1/0,size:n,startIndex:t}})}function au(e,t){let n=0,r=0;for(;n<e;)n+=t[r+1]-t[r]-1,r++;return r-(n===e?0:1)}function Ii(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=Vo(o,t-1,Ei),a=o[l].offset;const c=Yt(n,t-1);s=c[0],i=c[1],o.length&&o[l].size===Yt(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:c,value:u}of Ho(n,t,1/0)){const f=c-s,h=f*i+a+f*r;o.push({index:c,offset:h,size:u}),s=c,a=h,i=u}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function Fx(e){return{index:e.index,value:e}}function zx(e){const{endIndex:t,size:n,startIndex:r}=e;return o=>o.start===r&&(o.end===t||o.end===1/0)&&o.value===n}const Bx={offsetHeight:"height",offsetWidth:"width"},rn=Re(([{log:e},{recalcInProgress:t}])=>{const n=Ne(),r=Ne(),o=ct(r,0),s=Ne(),i=Ne(),a=re(0),l=re([]),c=re(void 0),u=re(void 0),f=re((S,C)=>An(S,Bx[C])),h=re(void 0),p=re(0),m=Px(),b=ct(te(n,Ee(l,e,p),nn(Lx,m),Ke()),m),g=ct(te(l,Ke(),nn((S,C)=>({current:C,prev:S.current}),{current:[],prev:[]}),ae(({prev:S})=>S)),[]);de(te(l,we(S=>S.length>0),Ee(b,p),ae(([S,C,T])=>{const N=S.reduce((j,_,D)=>Pt(j,_,Jr(_,C.offsetTree,T)||D),yr());return{...C,groupIndices:S,groupOffsetTree:N}})),b),de(te(r,Ee(b),we(([S,{lastIndex:C}])=>S<C),ae(([S,{lastIndex:C,lastSize:T}])=>[{endIndex:C,size:T,startIndex:S}])),n),de(c,u);const w=ct(te(c,ae(S=>S===void 0)),!0);de(te(u,we(S=>S!==void 0&&Ue(tt(b).sizeTree)),ae(S=>[{endIndex:0,size:S,startIndex:0}])),n);const y=_t(te(n,Ee(b),nn(({sizes:S},[C,T])=>({changed:T!==S,sizes:T}),{changed:!1,sizes:m}),ae(S=>S.changed)));Me(te(a,nn((S,C)=>({diff:S.prev-C,prev:C}),{diff:0,prev:0}),ae(S=>S.diff)),S=>{const{groupIndices:C}=tt(b);if(S>0)ke(t,!0),ke(s,S+au(S,C));else if(S<0){const T=tt(g);T.length>0&&(S-=au(-S,T)),ke(i,S)}}),Me(te(a,Ee(e)),([S,C])=>{S<0&&C("`firstItemIndex` prop should not be set to less than zero. If you don't know the total count, just use a very high value",{firstItemIndex:a},kt.ERROR)});const k=_t(s);de(te(s,Ee(b),ae(([S,C])=>{const T=C.groupIndices.length>0,N=[],j=C.lastSize;if(T){const _=Yr(C.sizeTree,0);let D=0,z=0;for(;D<S;){const P=C.groupIndices[z],M=C.groupIndices.length===z+1?1/0:C.groupIndices[z+1]-P-1;N.push({endIndex:P,size:_,startIndex:P}),N.push({endIndex:P+1+M-1,size:j,startIndex:P+1}),z++,D+=M+1}const H=Yn(C.sizeTree);return D!==S&&H.shift(),H.reduce((P,{k:M,v:F})=>{let ne=P.ranges;return P.prevSize!==0&&(ne=[...P.ranges,{endIndex:M+S-1,size:P.prevSize,startIndex:P.prevIndex}]),{prevIndex:M+S,prevSize:F,ranges:ne}},{prevIndex:S,prevSize:0,ranges:N}).ranges}return Yn(C.sizeTree).reduce((_,{k:D,v:z})=>({prevIndex:D+S,prevSize:z,ranges:[..._.ranges,{endIndex:D+S-1,size:_.prevSize,startIndex:_.prevIndex}]}),{prevIndex:0,prevSize:j,ranges:[]}).ranges})),n);const E=_t(te(i,Ee(b,p),ae(([S,{offsetTree:C},T])=>{const N=-S;return Jr(N,C,T)})));return de(te(i,Ee(b,p),ae(([S,C,T])=>{if(C.groupIndices.length>0){if(Ue(C.sizeTree))return C;let N=yr();const j=tt(g);let _=0,D=0,z=0;for(;_<-S;){z=j[D];const H=j[D+1]-z-1;D++,_+=H+1}if(N=Yn(C.sizeTree).reduce((H,{k:P,v:M})=>Pt(H,Math.max(0,P+S),M),N),_!==-S){const H=Yr(C.sizeTree,z);N=Pt(N,0,H);const P=Yt(C.sizeTree,-S+1)[1];N=Pt(N,1,P)}return{...C,sizeTree:N,...Ii(C.offsetTree,0,N,T)}}else{const N=Yn(C.sizeTree).reduce((j,{k:_,v:D})=>Pt(j,Math.max(0,_+S),D),yr());return{...C,sizeTree:N,...Ii(C.offsetTree,0,N,T)}}})),b),{beforeUnshiftWith:k,data:h,defaultItemSize:u,firstItemIndex:a,fixedItemSize:c,gap:p,groupIndices:l,itemSize:f,listRefresh:y,shiftWith:i,shiftWithOffset:E,sizeRanges:n,sizes:b,statefulTotalCount:o,totalCount:r,trackItemSizes:w,unshiftWith:s}},Ve(In,ki),{singleton:!0});function Ux(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const lu=Re(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Ne(),i=Ne(),a=_t(te(s,ae(Ux)));return de(te(a,ae(l=>l.totalCount)),n),de(te(a,ae(l=>l.groupIndices)),e),de(te(rt(o,t,r),we(([l,c])=>Ko(c)),ae(([l,c,u])=>Yt(c.groupOffsetTree,Math.max(l-u,0),"v")[0]),Ke(),ae(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},Ve(rn,gt)),Nn=Re(([{log:e}])=>{const t=re(!1),n=_t(te(t,we(r=>r),Ke()));return Me(t,r=>{r&&tt(e)("props updated",{},kt.DEBUG)}),{didMount:n,propsReady:t}},Ve(In),{singleton:!0}),Hx=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function cu(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Hx)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Zr=Re(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:c,smoothScrollTargetReached:u,viewportHeight:f},{log:h}])=>{const p=Ne(),m=Ne(),b=re(0);let g=null,w=null,y=null;function k(){g&&(g(),g=null),y&&(y(),y=null),w&&(clearTimeout(w),w=null),ke(l,!1)}return de(te(p,Ee(n,f,r,b,a,i,h),Ee(e,s,o),ae(([[E,S,C,T,N,j,_,D],z,H,P])=>{const M=cu(E),{align:F,behavior:ne,offset:U}=M,W=T-1,Y=iu(M,S,W);let q=Jr(Y,S.offsetTree,z)+j;F==="end"?(q+=H+Yt(S.sizeTree,Y)[1]-C+P,Y===W&&(q+=_)):F==="center"?q+=(H+Yt(S.sizeTree,Y)[1]-C+P)/2:q-=N,U&&(q+=U);const R=G=>{k(),G?(D("retrying to scroll to",{location:E},kt.DEBUG),ke(p,E)):(ke(m,!0),D("list did not change, scroll successful",{},kt.DEBUG))};if(k(),ne==="smooth"){let G=!1;y=Me(t,A=>{G=G||A}),g=Gt(u,()=>{R(G)})}else g=Gt(te(t,Wx(150)),R);return w=setTimeout(()=>{k()},1200),ke(l,!0),D("scrolling from index to",{behavior:ne,index:Y,top:q},kt.DEBUG),{behavior:ne,top:q}})),c),{scrollTargetReached:m,scrollToIndex:p,topListHeight:b}},Ve(rn,gt,In),{singleton:!0});function Wx(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function Ai(e,t){e==0?t():requestAnimationFrame(()=>{Ai(e-1,t)})}function Ni(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const Qr=Re(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=re(!0),l=re(0),c=re(!0);return de(te(i,Ee(l),we(([u,f])=>!!f),tn(!1)),a),de(te(i,Ee(l),we(([u,f])=>!!f),tn(!1)),c),Me(te(rt(t,i),Ee(a,n,e,c),we(([[,u],f,{sizeTree:h},p,m])=>u&&(!Ue(h)||xi(p))&&!f&&!m),Ee(l)),([,u])=>{Gt(o,()=>{ke(c,!0)}),Ai(4,()=>{Gt(r,()=>{ke(a,!0)}),ke(s,u)})}),{initialItemFinalLocationReached:c,initialTopMostItemIndex:l,scrolledToInitialItem:a}},Ve(rn,gt,Zr,Nn),{singleton:!0});function uu(e,t){return Math.abs(e-t)<1.01}const eo="up",to="down",Vx="none",Kx={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},qx=0,no=Re(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=re(!1),a=re(!0),l=Ne(),c=Ne(),u=re(4),f=re(qx),h=ct(te(wi(te(be(o),qn(1),tn(!0)),te(be(o),qn(1),tn(!1),qc(100))),Ke()),!1),p=ct(te(wi(te(n,tn(!0)),te(n,tn(!1),qc(200))),Ke()),!1);de(te(rt(be(o),be(f)),ae(([y,k])=>y<=k),Ke()),a),de(te(a,gn(50)),c);const m=_t(te(rt(r,be(s),be(t),be(e),be(u)),nn((y,[{scrollHeight:k,scrollTop:E},S,C,T,N])=>{const j=E+S-k>-N,_={scrollHeight:k,scrollTop:E,viewportHeight:S};if(j){let z,H;return E>y.state.scrollTop?(z="SCROLLED_DOWN",H=y.state.scrollTop-E):(z="SIZE_DECREASED",H=y.state.scrollTop-E||y.scrollTopDelta),{atBottom:!0,atBottomBecause:z,scrollTopDelta:H,state:_}}let D;return _.scrollHeight>y.state.scrollHeight?D="SIZE_INCREASED":S<y.state.viewportHeight?D="VIEWPORT_HEIGHT_DECREASING":E<y.state.scrollTop?D="SCROLLING_UPWARDS":D="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:D,state:_}},Kx),Ke((y,k)=>y&&y.atBottom===k.atBottom))),b=ct(te(r,nn((y,{scrollHeight:k,scrollTop:E,viewportHeight:S})=>{if(uu(y.scrollHeight,k))return{changed:!1,jump:0,scrollHeight:k,scrollTop:E};{const C=k-(E+S)<1;return y.scrollTop!==E&&C?{changed:!0,jump:y.scrollTop-E,scrollHeight:k,scrollTop:E}:{changed:!0,jump:0,scrollHeight:k,scrollTop:E}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),we(y=>y.changed),ae(y=>y.jump)),0);de(te(m,ae(y=>y.atBottom)),i),de(te(i,gn(50)),l);const g=re(to);de(te(r,ae(({scrollTop:y})=>y),Ke(),nn((y,k)=>tt(p)?{direction:y.direction,prevScrollTop:k}:{direction:k<y.prevScrollTop?eo:to,prevScrollTop:k},{direction:to,prevScrollTop:0}),ae(y=>y.direction)),g),de(te(r,gn(50),tn(Vx)),g);const w=re(0);return de(te(h,we(y=>!y),tn(0)),w),de(te(o,gn(100),Ee(h),we(([y,k])=>!!k),nn(([y,k],[E])=>[k,E],[0,0]),ae(([y,k])=>k-y)),w),{atBottomState:m,atBottomStateChange:l,atBottomThreshold:u,atTopStateChange:c,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:b,scrollDirection:g,scrollVelocity:w}},Ve(gt)),qo="top",Go="bottom",du="none";function fu(e,t,n){return typeof e=="number"?n===eo&&t===qo||n===to&&t===Go?e:0:n===eo?t===qo?e.main:e.reverse:t===Go?e.main:e.reverse}function hu(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const ji=Re(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Ne(),i=re(0),a=re(0),l=re(0),c=ct(te(rt(be(r),be(o),be(n),be(s,Xr),be(l),be(i),be(t),be(e),be(a)),ae(([u,f,h,[p,m],b,g,w,y,k])=>{const E=u-y,S=g+w,C=Math.max(h-E,0);let T=du;const N=hu(k,qo),j=hu(k,Go);return p-=y,p+=h+w,m+=h+w,m-=y,p>u+S-N&&(T=eo),m<u-C+f+j&&(T=to),T!==du?[Math.max(E-h-fu(b,qo,T)-N,0),E-C-w+f+fu(b,Go,T)+j]:null}),we(u=>u!=null),Ke(Xr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:c}},Ve(gt),{singleton:!0});function Gx(e,t,n){if(Ko(t)){const r=su(e,t);return[{index:Yt(t.groupOffsetTree,r)[0],offset:0,size:0},{data:n==null?void 0:n[0],index:r,offset:0,size:0}]}return[{data:n==null?void 0:n[0],index:e,offset:0,size:0}]}const _i={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function Yo(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let c=0,u=0;if(e.length>0){c=e[0].offset;const b=e[e.length-1];u=b.offset+b.size}const f=n-i,h=a+f*l+(f-1)*r,p=c,m=h-u;return{bottom:u,firstItemIndex:s,items:mu(e,o,s),offsetBottom:m,offsetTop:c,top:p,topItems:mu(t,o,s),topListHeight:t.reduce((b,g)=>g.size+b,0),totalCount:n}}function pu(e,t,n,r,o,s){let i=0;if(n.groupIndices.length>0)for(const u of n.groupIndices){if(u-i>=e)break;i++}const a=e+i,l=Ni(t,a),c=Array.from({length:a}).map((u,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return Yo(c,[],a,o,n,r)}function mu(e,t,n){if(e.length===0)return[];if(!Ko(t))return e.map(c=>({...c,index:c.index+n,originalIndex:c.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=Ho(t.groupOffsetTree,r,o);let a,l=0;for(const c of e){(!a||a.end<c.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let u;c.index===a.start?u={index:l,type:"group"}:u={groupIndex:l,index:c.index-(l+1)+n},s.push({...u,data:c.data,offset:c.offset,originalIndex:c.index,size:c.size})}return s}const Xn=Re(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:c,scrolledToInitialItem:u},{topListHeight:f},h,{didMount:p},{recalcInProgress:m}])=>{const b=re([]),g=re(0),w=Ne();de(s.topItemsIndexes,b);const y=ct(te(rt(p,m,be(l,Xr),be(o),be(r),be(c),u,be(b),be(t),be(n),e),we(([C,T,,N,,,,,,,j])=>{const _=j&&j.length!==N;return C&&!T&&!_}),ae(([,,[C,T],N,j,_,D,z,H,P,M])=>{const F=j,{offsetTree:ne,sizeTree:U}=F,W=tt(g);if(N===0)return{..._i,totalCount:N};if(C===0&&T===0)return W===0?{..._i,totalCount:N}:pu(W,_,j,H,P,M||[]);if(Ue(U))return W>0?null:Yo(Gx(Ni(_,N),F,M),[],N,P,F,H);const Y=[];if(z.length>0){const O=z[0],V=z[z.length-1];let Z=0;for(const $ of Ho(U,O,V)){const X=$.value,oe=Math.max($.start,O),ue=Math.min($.end,V);for(let le=oe;le<=ue;le++)Y.push({data:M==null?void 0:M[le],index:le,offset:Z,size:X}),Z+=X}}if(!D)return Yo([],Y,N,P,F,H);const q=z.length>0?z[z.length-1]+1:0,R=Dx(ne,C,T,q);if(R.length===0)return null;const G=N-1,A=Uo([],O=>{for(const V of R){const Z=V.value;let $=Z.offset,X=V.start;const oe=Z.size;if(Z.offset<C){X+=Math.floor((C-Z.offset+P)/(oe+P));const le=X-V.start;$+=le*oe+le*P}X<q&&($+=(q-X)*oe,X=q);const ue=Math.min(V.end,G);for(let le=X;le<=ue&&!($>=T);le++)O.push({data:M==null?void 0:M[le],index:le,offset:$,size:oe}),$+=oe+P}});return Yo(A,Y,N,P,F,H)}),we(C=>C!==null),Ke()),_i);de(te(e,we(xi),ae(C=>C==null?void 0:C.length)),o),de(te(y,ae(C=>C.topListHeight)),f),de(f,a),de(te(y,ae(C=>[C.top,C.bottom])),i),de(te(y,ae(C=>C.items)),w);const k=_t(te(y,we(({items:C})=>C.length>0),Ee(o,e),we(([{items:C},T])=>C[C.length-1].originalIndex===T-1),ae(([,C,T])=>[C-1,T]),Ke(Xr),ae(([C])=>C))),E=_t(te(y,gn(200),we(({items:C,topItems:T})=>C.length>0&&C[0].originalIndex===T.length),ae(({items:C})=>C[0].index),Ke())),S=_t(te(y,we(({items:C})=>C.length>0),ae(({items:C})=>{let T=0,N=C.length-1;for(;C[T].type==="group"&&T<N;)T++;for(;C[N].type==="group"&&N>T;)N--;return{endIndex:C[N].index,startIndex:C[T].index}}),Ke(ru)));return{endReached:k,initialItemCount:g,itemsRendered:w,listState:y,rangeChanged:S,startReached:E,topItemsIndexes:b,...h}},Ve(rn,lu,ji,Qr,Zr,no,Nn,ki),{singleton:!0}),gu=Re(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Ne(),i=ct(te(rt(n,e,r,t,o),ae(([a,l,c,u,f])=>a+l+c+u+f.offsetBottom+f.bottom)),0);return de(be(i),s),{totalListHeight:i,totalListHeightChanged:s}},Ve(gt,Xn),{singleton:!0}),Yx=Re(([{viewportHeight:e},{totalListHeight:t}])=>{const n=re(!1),r=ct(te(rt(n,e,t),we(([o])=>o),ae(([,o,s])=>Math.max(0,o-s)),gn(0),Ke()),0);return{alignToBottom:n,paddingTopAddition:r}},Ve(gt,gu),{singleton:!0}),xu=Re(()=>({context:re(null)})),Xx=({itemBottom:e,itemTop:t,locationParams:{align:n,behavior:r,...o},viewportBottom:s,viewportTop:i})=>t<i?{...o,align:n??"start",behavior:r}:e>s?{...o,align:n??"end",behavior:r}:null,bu=Re(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:c}])=>{const u=Ne();return de(te(u,Ee(t,l,n,s,o,r,a),Ee(e),ae(([[f,h,p,m,b,g,w,y],k])=>{const{align:E,behavior:S,calculateViewLocation:C=Xx,done:T,...N}=f,j=iu(f,h,m-1),_=Jr(j,h.offsetTree,k)+b+g,D=_+Yt(h.sizeTree,j)[1],z=y+g,H=y+p-w,P=C({itemBottom:D,itemTop:_,locationParams:{align:E,behavior:S,...N},viewportBottom:H,viewportTop:z});return P?T&&Gt(te(i,we(M=>!M),qn(tt(i)?1:2)),T):T&&T(),P}),we(f=>f!==null)),c),{scrollIntoView:u}},Ve(rn,gt,Zr,Xn,In),{singleton:!0});function wu(e){return e?e==="smooth"?"smooth":"auto":!1}const Jx=(e,t)=>typeof e=="function"?wu(e(t)):t&&wu(e),Zx=Re(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:c},{log:u},{scrollingInProgress:f},{context:h},{scrollIntoView:p}])=>{const m=re(!1),b=Ne();let g=null;function w(S){ke(i,{align:"end",behavior:S,index:"LAST"})}Me(te(rt(te(be(t),qn(1)),l),Ee(be(m),s,a,f),ae(([[S,C],T,N,j,_])=>{let D=C&&j,z="auto";return D&&(z=Jx(T,N||_),D=D&&!!z),{followOutputBehavior:z,shouldFollow:D,totalCount:S}}),we(({shouldFollow:S})=>S)),({followOutputBehavior:S,totalCount:C})=>{g&&(g(),g=null),tt(n)?requestAnimationFrame(()=>{tt(u)("following output to ",{totalCount:C},kt.DEBUG),w(S)}):g=Gt(e,()=>{tt(u)("following output to ",{totalCount:C},kt.DEBUG),w(S),g=null})});function y(S){const C=Gt(o,T=>{S&&!T.atBottom&&T.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(tt(u)("scrolling to bottom due to increased size",{},kt.DEBUG),w("auto"))});setTimeout(C,100)}Me(te(rt(be(m),t,c),we(([S,,C])=>S&&C),nn(({value:S},[,C])=>({refreshed:S===C,value:C}),{refreshed:!1,value:0}),we(({refreshed:S})=>S),Ee(m,t)),([,S])=>{tt(a)&&y(S!==!1)}),Me(b,()=>{y(tt(m)!==!1)}),Me(rt(be(m),o),([S,C])=>{S&&!C.atBottom&&C.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&w("auto")});const k=re(null),E=Ne();return de(wi(te(be(r),ae(S=>{var C;return(C=S==null?void 0:S.length)!=null?C:0})),te(be(t))),E),Me(te(rt(te(E,qn(1)),l),Ee(be(k),a,f,h),ae(([[S,C],T,N,j,_])=>C&&N&&(T==null?void 0:T({context:_,totalCount:S,scrollingInProgress:j}))),we(S=>!!S),gn(0)),S=>{g&&(g(),g=null),tt(n)?requestAnimationFrame(()=>{tt(u)("scrolling into view",{}),ke(p,S)}):g=Gt(e,()=>{tt(u)("scrolling into view",{}),ke(p,S),g=null})}),{autoscrollToBottom:b,followOutput:m,scrollIntoViewOnChange:k}},Ve(rn,no,Zr,Qr,Nn,In,gt,xu,bu)),Qx=Re(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(de(te(a,Ee(s),we(([,l])=>l!==0),Ee(o,r,t,n,e),ae(([[,l],c,u,f,h,p=[]])=>pu(l,c,u,f,h,p))),i),{}),Ve(rn,Qr,Xn,Nn),{singleton:!0}),eb=Re(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=re(0);return Me(te(e,Ee(r),we(([,o])=>o!==0),ae(([,o])=>({top:o}))),o=>{Gt(te(n,qn(1),we(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{ke(t,o)})})}),{initialScrollTop:r}},Ve(Nn,gt,Xn),{singleton:!0}),yu=Re(([{scrollVelocity:e}])=>{const t=re(!1),n=Ne(),r=re(!1);return de(te(e,Ee(r,t,n),we(([o,s])=>!!s),ae(([o,s,i,a])=>{const{enter:l,exit:c}=s;if(i){if(c(o,a))return!1}else if(l(o,a))return!0;return i}),Ke()),t),Me(te(rt(t,e,n),Ee(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},Ve(no),{singleton:!0}),Pi=Re(([{scrollContainerState:e,scrollTo:t}])=>{const n=Ne(),r=Ne(),o=Ne(),s=re(!1),i=re(void 0);return de(te(rt(n,r),ae(([{scrollHeight:a,scrollTop:l,viewportHeight:c},{offsetTop:u}])=>({scrollHeight:a,scrollTop:Math.max(0,l-u),viewportHeight:c}))),e),de(te(t,Ee(r),ae(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},Ve(gt)),tb=Re(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const c=Ne(),u=re(void 0),f=re(null),h=re(null);return de(a,f),de(l,h),Me(te(c,Ee(t,r,i,f,h,n)),([p,m,b,g,w,y,k])=>{const E=$x(m.sizeTree);g&&w!==null&&y!==null&&(b=w.scrollTop-y.offsetTop),b-=k,p({ranges:E,scrollTop:b})}),de(te(u,we(xi),ae(nb)),o),de(te(s,Ee(u),we(([,p])=>p!==void 0),Ke(),ae(([,p])=>p.ranges)),e),{getState:c,restoreStateFrom:u}},Ve(rn,gt,Qr,Nn,Pi));function nb(e){return{align:"start",index:0,offset:e.scrollTop}}const rb=Re(([{topItemsIndexes:e}])=>{const t=re(0);return de(te(t,we(n=>n>=0),ae(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},Ve(Xn));function vu(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const ob=vu(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),sb=Re(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:c,gap:u,shiftWithOffset:f,sizes:h},{log:p},{recalcInProgress:m}])=>{const b=_t(te(l,Ee(i),nn(([,w,y,k],[{bottom:E,items:S,offsetBottom:C,totalCount:T},N])=>{const j=E+C;let _=0;return y===T&&w.length>0&&S.length>0&&(S[0].originalIndex===0&&w[0].originalIndex===0||(_=j-k,_!==0&&(_+=N))),[_,S,T,j]},[0,[],0,0]),we(([w])=>w!==0),Ee(r,a,n,o,p,m),we(([,w,y,k,,,E])=>!E&&!k&&w!==0&&y===eo),ae(([[w],,,,,y])=>(y("Upward scrolling compensation",{amount:w},kt.DEBUG),w))));function g(w){w>0?(ke(t,{behavior:"auto",top:-w}),ke(e,0)):(ke(e,0),ke(t,{behavior:"auto",top:-w}))}return Me(te(b,Ee(e,s)),([w,y,k])=>{k&&ob()?ke(e,y-w):g(-w)}),Me(te(rt(ct(s,!1),e,m),we(([w,y,k])=>!w&&!k&&y!==0),ae(([w,y])=>y),gn(1)),g),de(te(f,ae(w=>({top:-w}))),t),Me(te(c,Ee(h,u),ae(([w,{groupIndices:y,lastSize:k,sizeTree:E},S])=>{function C(T){return T*(k+S)}if(y.length===0)return C(w);{let T=0;const N=Yr(E,0);let j=0,_=0;for(;j<w;){j++,T+=N;let D=y.length===_+1?1/0:y[_+1]-y[_]-1;j+D>w&&(T-=N,D=w-j+1),j+=D,T+=C(D),_++}return T}})),w=>{ke(e,w),requestAnimationFrame(()=>{ke(t,{top:w}),requestAnimationFrame(()=>{ke(e,0),ke(m,!1)})})}),{deviation:e}},Ve(gt,no,Xn,rn,In,ki)),ib=Re(([e,t,n,r,o,s,i,a,l,c,u])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...c,...u}),Ve(ji,Qx,Nn,yu,gu,eb,Yx,Pi,bu,In,xu)),Su=Re(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:c,totalCount:u,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:m},b,g,w,{listState:y,topItemsIndexes:k,...E},{scrollToIndex:S},C,{topItemCount:T},{groupCounts:N},j])=>(de(E.rangeChanged,j.scrollSeekRangeChanged),de(te(j.windowViewportRect,ae(_=>_.visibleHeight)),b.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:N,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:m,sizeRanges:a,topItemCount:T,topItemsIndexes:k,totalCount:u,...w,groupIndices:s,itemSize:i,listState:y,scrollToIndex:S,statefulTotalCount:c,trackItemSizes:f,...E,...j,...b,sizes:l,...g}),Ve(rn,Qr,gt,tb,Zx,Xn,Zr,sb,rb,lu,ib));function ab(e,t){const n={},r={};let o=0;const s=e.length;for(;o<s;)r[e[o]]=1,o+=1;for(const i in t)Object.hasOwn(r,i)||(n[i]=t[i]);return n}const Xo=typeof document<"u"?v.useLayoutEffect:v.useEffect;function Cu(e,t,n){const r=Object.keys(t.required||{}),o=Object.keys(t.optional||{}),s=Object.keys(t.methods||{}),i=Object.keys(t.events||{}),a=v.createContext({});function l(g,w){g.propsReady&&ke(g.propsReady,!1);for(const y of r){const k=g[t.required[y]];ke(k,w[y])}for(const y of o)if(y in w){const k=g[t.optional[y]];ke(k,w[y])}g.propsReady&&ke(g.propsReady,!0)}function c(g){return s.reduce((w,y)=>(w[y]=k=>{const E=g[t.methods[y]];ke(E,k)},w),{})}function u(g){return i.reduce((w,y)=>(w[y]=Cx(g[t.events[y]]),w),{})}const f=v.forwardRef((g,w)=>{const{children:y,...k}=g,[E]=v.useState(()=>Uo(kx(e),T=>{l(T,k)})),[S]=v.useState(Kc(u,E));Xo(()=>{for(const T of i)T in k&&Me(S[T],k[T]);return()=>{Object.values(S).map(bi)}},[k,S,E]),Xo(()=>{l(E,k)}),v.useImperativeHandle(w,Wc(c(E)));const C=n;return d.jsx(a.Provider,{value:E,children:n?d.jsx(C,{...ab([...r,...o,...i],k),children:y}):y})}),h=g=>{const w=v.useContext(a);return v.useCallback(y=>{ke(w[g],y)},[w,g])},p=g=>{const w=v.useContext(a)[g],y=v.useCallback(k=>Me(w,k),[w]);return v.useSyncExternalStore(y,()=>tt(w),()=>tt(w))},m=g=>{const w=v.useContext(a)[g],[y,k]=v.useState(Kc(tt,w));return Xo(()=>Me(w,E=>{E!==y&&k(Wc(E))}),[w,y]),y},b=v.version.startsWith("18")?p:m;return{Component:f,useEmitter:(g,w)=>{const y=v.useContext(a)[g];Xo(()=>Me(y,w),[w,y])},useEmitterValue:b,usePublisher:h}}const Tu=v.createContext(void 0),ku=v.createContext(void 0),Eu=typeof document<"u"?v.useLayoutEffect:v.useEffect;function Ri(e){return"self"in e}function lb(e){return"body"in e}function Iu(e,t,n,r=wr,o,s){const i=v.useRef(null),a=v.useRef(null),l=v.useRef(null),c=v.useCallback(h=>{let p,m,b;const g=h.target;if(lb(g)||Ri(g)){const y=Ri(g)?g:g.defaultView;b=s?y.scrollX:y.scrollY,p=s?y.document.documentElement.scrollWidth:y.document.documentElement.scrollHeight,m=s?y.innerWidth:y.innerHeight}else b=s?g.scrollLeft:g.scrollTop,p=s?g.scrollWidth:g.scrollHeight,m=s?g.offsetWidth:g.offsetHeight;const w=()=>{e({scrollHeight:p,scrollTop:Math.max(b,0),viewportHeight:m})};h.suppressFlushSync?w():Ws.flushSync(w),a.current!==null&&(b===a.current||b<=0||b===p-m)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);v.useEffect(()=>{const h=o||i.current;return r(o||i.current),c({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",c,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",c)}},[i,c,n,r,o]);function u(h){const p=i.current;if(!p||(s?"offsetWidth"in p&&p.offsetWidth===0:"offsetHeight"in p&&p.offsetHeight===0))return;const m=h.behavior==="smooth";let b,g,w;Ri(p)?(g=Math.max(An(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),b=s?p.innerWidth:p.innerHeight,w=s?window.scrollX:window.scrollY):(g=p[s?"scrollWidth":"scrollHeight"],b=An(p,s?"width":"height"),w=p[s?"scrollLeft":"scrollTop"]);const y=g-b;if(h.top=Math.ceil(Math.max(Math.min(y,h.top),0)),uu(b,g)||h.top===w){e({scrollHeight:g,scrollTop:w,viewportHeight:b}),m&&t(!0);return}m?(a.current=h.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),p.scrollTo(h)}function f(h){s&&(h={behavior:h.behavior,left:h.top}),i.current.scrollBy(h)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:u}}const Oi="-webkit-sticky",Au="sticky",Mi=vu(()=>{if(typeof document>"u")return Au;const e=document.createElement("div");return e.style.position=Oi,e.style.position===Oi?Oi:Au});function Di(e){return e}const cb=Re(()=>{const e=re(a=>`Item ${a}`),t=re(a=>`Group ${a}`),n=re({}),r=re(Di),o=re("div"),s=re(wr),i=(a,l=null)=>ct(te(n,ae(c=>c[a]),Ke()),l);return{components:n,computeItemKey:r,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:t,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:e,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),ub=Re(([e,t])=>({...e,...t}),Ve(Su,cb)),db=({height:e})=>d.jsx("div",{style:{height:e}}),fb={overflowAnchor:"none",position:Mi(),zIndex:1},Nu={overflowAnchor:"none"},hb={...Nu,display:"inline-block",height:"100%"},ju=v.memo(function({showTopList:e=!1}){const t=Se("listState"),n=$t("sizeRanges"),r=Se("useWindowScroll"),o=Se("customScrollParent"),s=$t("windowScrollContainerState"),i=$t("scrollContainerState"),a=o||r?s:i,l=Se("itemContent"),c=Se("context"),u=Se("groupContent"),f=Se("trackItemSizes"),h=Se("itemSize"),p=Se("log"),m=$t("gap"),b=Se("horizontalDirection"),{callbackRef:g}=Ax(n,h,f,e?wr:a,p,m,o,b,Se("skipAnimationFrameInResizeObserver")),[w,y]=v.useState(0);Li("deviation",P=>{w!==P&&y(P)});const k=Se("EmptyPlaceholder"),E=Se("ScrollSeekPlaceholder")||db,S=Se("ListComponent"),C=Se("ItemComponent"),T=Se("GroupComponent"),N=Se("computeItemKey"),j=Se("isSeeking"),_=Se("groupIndices").length>0,D=Se("alignToBottom"),z=Se("initialItemFinalLocationReached"),H=e?{}:{boxSizing:"border-box",...b?{display:"inline-block",height:"100%",marginLeft:w!==0?w:D?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:w!==0?w:D?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...z?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&k?d.jsx(k,{...ut(k,c)}):d.jsx(S,{...ut(S,c),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:g,style:H,children:(e?t.topItems:t.items).map(P=>{const M=P.originalIndex,F=N(M+t.firstItemIndex,P.data,c);return j?v.createElement(E,{...ut(E,c),height:P.size,index:P.index,key:F,type:P.type||"item",...P.type==="group"?{}:{groupIndex:P.groupIndex}}):P.type==="group"?v.createElement(T,{...ut(T,c),"data-index":M,"data-item-index":P.index,"data-known-size":P.size,key:F,style:fb},u(P.index,c)):v.createElement(C,{...ut(C,c),...xb(C,P.data),"data-index":M,"data-item-group-index":P.groupIndex,"data-item-index":P.index,"data-known-size":P.size,key:F,style:b?hb:Nu},_?l(P.index,P.groupIndex,P.data,c):l(P.index,P.data,c))})})}),pb={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},mb={outline:"none",overflowX:"auto",position:"relative"},Jo=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),gb={position:Mi(),top:0,width:"100%",zIndex:1};function ut(e,t){if(typeof e!="string")return{context:t}}function xb(e,t){return{item:typeof e=="string"?void 0:t}}const bb=v.memo(function(){const e=Se("HeaderComponent"),t=$t("headerHeight"),n=Se("HeaderFooterTag"),r=Gn(v.useMemo(()=>s=>{t(An(s,"height"))},[t]),!0,Se("skipAnimationFrameInResizeObserver")),o=Se("context");return e?d.jsx(n,{ref:r,children:d.jsx(e,{...ut(e,o)})}):null}),wb=v.memo(function(){const e=Se("FooterComponent"),t=$t("footerHeight"),n=Se("HeaderFooterTag"),r=Gn(v.useMemo(()=>s=>{t(An(s,"height"))},[t]),!0,Se("skipAnimationFrameInResizeObserver")),o=Se("context");return e?d.jsx(n,{ref:r,children:d.jsx(e,{...ut(e,o)})}):null});function _u({useEmitter:e,useEmitterValue:t,usePublisher:n}){return v.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),u=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback:m}=Iu(a,c,l,u,void 0,f);return e("scrollTo",m),e("scrollBy",h),d.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?mb:pb,...o},tabIndex:0,...i,...ut(l,s),children:r})})}function Pu({useEmitter:e,useEmitterValue:t,usePublisher:n}){return v.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),c=n("smoothScrollTargetReached"),u=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),p=v.useRef(null),m=t("scrollerRef"),{scrollByCallback:b,scrollerRef:g,scrollToCallback:w}=Iu(a,c,l,m,h);return Eu(()=>{var y;return g.current=h||((y=p.current)==null?void 0:y.ownerDocument.defaultView),()=>{g.current=null}},[g,h]),e("windowScrollTo",w),e("scrollBy",b),d.jsx(l,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...u!==0?{height:u+f}:{}},...i,...ut(l,s),children:r})})}const yb=({children:e})=>{const t=v.useContext(Tu),n=$t("viewportHeight"),r=$t("fixedItemHeight"),o=Se("alignToBottom"),s=Se("horizontalDirection"),i=v.useMemo(()=>Vc(n,l=>An(l,s?"width":"height")),[n,s]),a=Gn(i,!0,Se("skipAnimationFrameInResizeObserver"));return v.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),d.jsx("div",{"data-viewport-type":"element",ref:a,style:Jo(o),children:e})},vb=({children:e})=>{const t=v.useContext(Tu),n=$t("windowViewportRect"),r=$t("fixedItemHeight"),o=Se("customScrollParent"),s=Xc(n,o,Se("skipAnimationFrameInResizeObserver")),i=Se("alignToBottom");return v.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),d.jsx("div",{"data-viewport-type":"window",ref:s,style:Jo(i),children:e})},Sb=({children:e})=>{const t=Se("TopItemListComponent")||"div",n=Se("headerHeight"),r={...gb,marginTop:`${n}px`},o=Se("context");return d.jsx(t,{style:r,...ut(t,o),children:e})},Cb=v.memo(function(e){const t=Se("useWindowScroll"),n=Se("topItemsIndexes").length>0,r=Se("customScrollParent"),o=Se("context");return d.jsxs(r||t?Eb:kb,{...e,context:o,children:[n&&d.jsx(Sb,{children:d.jsx(ju,{showTopList:!0})}),d.jsxs(r||t?vb:yb,{children:[d.jsx(bb,{}),d.jsx(ju,{}),d.jsx(wb,{})]})]})}),{Component:Tb,useEmitter:Li,useEmitterValue:Se,usePublisher:$t}=Cu(ub,{required:{},optional:{restoreStateFrom:"restoreStateFrom",context:"context",followOutput:"followOutput",scrollIntoViewOnChange:"scrollIntoViewOnChange",itemContent:"itemContent",groupContent:"groupContent",overscan:"overscan",increaseViewportBy:"increaseViewportBy",totalCount:"totalCount",groupCounts:"groupCounts",topItemCount:"topItemCount",firstItemIndex:"firstItemIndex",initialTopMostItemIndex:"initialTopMostItemIndex",components:"components",atBottomThreshold:"atBottomThreshold",atTopThreshold:"atTopThreshold",computeItemKey:"computeItemKey",defaultItemHeight:"defaultItemHeight",fixedItemHeight:"fixedItemHeight",itemSize:"itemSize",scrollSeekConfiguration:"scrollSeekConfiguration",headerFooterTag:"HeaderFooterTag",data:"data",initialItemCount:"initialItemCount",initialScrollTop:"initialScrollTop",alignToBottom:"alignToBottom",useWindowScroll:"useWindowScroll",customScrollParent:"customScrollParent",scrollerRef:"scrollerRef",logLevel:"logLevel",horizontalDirection:"horizontalDirection",skipAnimationFrameInResizeObserver:"skipAnimationFrameInResizeObserver"},methods:{scrollToIndex:"scrollToIndex",scrollIntoView:"scrollIntoView",scrollTo:"scrollTo",scrollBy:"scrollBy",autoscrollToBottom:"autoscrollToBottom",getState:"getState"},events:{isScrolling:"isScrolling",endReached:"endReached",startReached:"startReached",rangeChanged:"rangeChanged",atBottomStateChange:"atBottomStateChange",atTopStateChange:"atTopStateChange",totalListHeightChanged:"totalListHeightChanged",itemsRendered:"itemsRendered",groupIndices:"groupIndices"}},Cb),kb=_u({useEmitter:Li,useEmitterValue:Se,usePublisher:$t}),Eb=Pu({useEmitter:Li,useEmitterValue:Se,usePublisher:$t}),Ib=Tb;Ve(Su,Re(()=>{const e=re(c=>d.jsxs("td",{children:["Item $",c]})),t=re(null),n=re(c=>d.jsxs("td",{colSpan:1e3,children:["Group ",c]})),r=re(null),o=re(null),s=re({}),i=re(Di),a=re(wr),l=(c,u=null)=>ct(te(s,ae(f=>f[c]),Ke()),u);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:l("EmptyPlaceholder"),FillerRow:l("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TableBodyComponent:l("TableBody","tbody"),TableComponent:l("Table","table"),TableFooterComponent:l("TableFoot","tfoot"),TableHeadComponent:l("TableHead","thead"),TableRowComponent:l("TableRow","tr"),GroupComponent:l("Group","tr")}})),Mi();const Ru={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},Ab={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Ou,floor:Zo,max:ro,min:$i,round:Mu}=Math;function Du(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function Nb(e){return{...Ab,items:e}}function Qo(e,t){return e&&e.width===t.width&&e.height===t.height}function jb(e,t){return e&&e.column===t.column&&e.row===t.row}const _b=Re(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:c,smoothScrollTargetReached:u,viewportHeight:f},h,p,{didMount:m,propsReady:b},{customScrollParent:g,useWindowScroll:w,windowScrollContainerState:y,windowScrollTo:k,windowViewportRect:E},S])=>{const C=re(0),T=re(0),N=re(Ru),j=re({height:0,width:0}),_=re({height:0,width:0}),D=Ne(),z=Ne(),H=re(0),P=re(null),M=re({column:0,row:0}),F=Ne(),ne=Ne(),U=re(!1),W=re(0),Y=re(!0),q=re(!1),R=re(!1);Me(te(m,Ee(W),we(([$,X])=>!!X)),()=>{ke(Y,!1)}),Me(te(rt(m,Y,_,j,W,q),we(([$,X,oe,ue,,le])=>$&&!X&&oe.height!==0&&ue.height!==0&&!le)),([,,,,$])=>{ke(q,!0),Ai(1,()=>{ke(D,$)}),Gt(te(c),()=>{ke(t,[0,0]),ke(Y,!0)})}),de(te(ne,we($=>$!=null&&$.scrollTop>0),tn(0)),T),Me(te(m,Ee(ne),we(([,$])=>$!=null)),([,$])=>{$&&(ke(j,$.viewport),ke(_,$.item),ke(M,$.gap),$.scrollTop>0&&(ke(U,!0),Gt(te(c,qn(1)),X=>{ke(U,!1)}),ke(l,{top:$.scrollTop})))}),de(te(j,ae(({height:$})=>$)),f),de(te(rt(be(j,Qo),be(_,Qo),be(M,($,X)=>$&&$.column===X.column&&$.row===X.row),be(c)),ae(([$,X,oe,ue])=>({gap:oe,item:X,scrollTop:ue,viewport:$}))),F),de(te(rt(be(C),r,be(M,jb),be(_,Qo),be(j,Qo),be(P),be(T),be(U),be(Y),be(W)),we(([,,,,,,,$])=>!$),ae(([$,[X,oe],ue,le,Ce,De,Ie,,qe,We])=>{const{column:Fe,row:ze}=ue,{height:It,width:At}=le,{width:bt}=Ce;if(Ie===0&&($===0||bt===0))return Ru;if(At===0){const yt=Ni(We,$),Be=yt+Math.max(Ie-1,0);return Nb(Du(yt,Be,De))}const wt=Lu(bt,At,Fe);let ht,st;qe?X===0&&oe===0&&Ie>0?(ht=0,st=Ie-1):(ht=wt*Zo((X+ze)/(It+ze)),st=wt*Ou((oe+ze)/(It+ze))-1,st=$i($-1,ro(st,wt-1)),ht=$i(st,ro(0,ht))):(ht=0,st=-1);const Nt=Du(ht,st,De),{bottom:jt,top:Ut}=$u(Ce,ue,le,Nt),nt=Ou($/wt),Ze=nt*It+(nt-1)*ze-jt;return{bottom:jt,itemHeight:It,items:Nt,itemWidth:At,offsetBottom:Ze,offsetTop:Ut,top:Ut}})),N),de(te(P,we($=>$!==null),ae($=>$.length)),C),de(te(rt(j,_,N,M),we(([$,X,{items:oe}])=>oe.length>0&&X.height!==0&&$.height!==0),ae(([$,X,{items:oe},ue])=>{const{bottom:le,top:Ce}=$u($,ue,X,oe);return[Ce,le]}),Ke(Xr)),t);const G=re(!1);de(te(c,Ee(G),ae(([$,X])=>X||$!==0)),G);const A=_t(te(rt(N,C),we(([{items:$}])=>$.length>0),Ee(G),we(([[$,X],oe])=>{const ue=$.items[$.items.length-1].index===X-1;return(oe||$.bottom>0&&$.itemHeight>0&&$.offsetBottom===0&&$.items.length===X)&&ue}),ae(([[,$]])=>$-1),Ke())),O=_t(te(be(N),we(({items:$})=>$.length>0&&$[0].index===0),tn(0),Ke())),V=_t(te(be(N),Ee(U),we(([{items:$},X])=>$.length>0&&!X),ae(([{items:$}])=>({endIndex:$[$.length-1].index,startIndex:$[0].index})),Ke(ru),gn(0)));de(V,p.scrollSeekRangeChanged),de(te(D,Ee(j,_,C,M),ae(([$,X,oe,ue,le])=>{const Ce=cu($),{align:De,behavior:Ie,offset:qe}=Ce;let We=Ce.index;We==="LAST"&&(We=ue-1),We=ro(0,We,$i(ue-1,We));let Fe=Fi(X,le,oe,We);return De==="end"?Fe=Mu(Fe-X.height+oe.height):De==="center"&&(Fe=Mu(Fe-X.height/2+oe.height/2)),qe&&(Fe+=qe),{behavior:Ie,top:Fe}})),l);const Z=ct(te(N,ae($=>$.offsetBottom+$.bottom)),0);return de(te(E,ae($=>({height:$.visibleHeight,width:$.visibleWidth}))),j),{customScrollParent:g,data:P,deviation:H,footerHeight:o,gap:M,headerHeight:s,increaseViewportBy:e,initialItemCount:T,itemDimensions:_,overscan:n,restoreStateFrom:ne,scrollBy:i,scrollContainerState:a,scrollHeight:z,scrollTo:l,scrollToIndex:D,scrollTop:c,smoothScrollTargetReached:u,totalCount:C,useWindowScroll:w,viewportDimensions:j,windowScrollContainerState:y,windowScrollTo:k,windowViewportRect:E,...p,gridState:N,horizontalDirection:R,initialTopMostItemIndex:W,totalListHeight:Z,...h,endReached:A,propsReady:b,rangeChanged:V,startReached:O,stateChanged:F,stateRestoreInProgress:U,...S}},Ve(ji,gt,no,yu,Nn,Pi,In));function Lu(e,t,n){return ro(1,Zo((e+n)/(Zo(t)+n)))}function $u(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=Fi(e,t,n,r[0].index);return{bottom:Fi(e,t,n,r[r.length-1].index)+o,top:s}}function Fi(e,t,n,r){const o=Lu(e.width,n.width,t.column),s=Zo(r/o),i=s*n.height+ro(0,s-1)*t.row;return i>0?i+t.row:i}const Pb=Re(()=>{const e=re(f=>`Item ${f}`),t=re({}),n=re(null),r=re("virtuoso-grid-item"),o=re("virtuoso-grid-list"),s=re(Di),i=re("div"),a=re(wr),l=(f,h=null)=>ct(te(t,ae(p=>p[f]),Ke()),h),c=re(!1),u=re(!1);return de(be(u),c),{components:t,computeItemKey:s,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:l("Item","div"),itemContent:e,listClassName:o,ListComponent:l("List","div"),readyStateChanged:c,reportReadyState:u,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),Rb=Re(([e,t])=>({...e,...t}),Ve(_b,Pb)),Ob=v.memo(function(){const e=Ye("gridState"),t=Ye("listClassName"),n=Ye("itemClassName"),r=Ye("itemContent"),o=Ye("computeItemKey"),s=Ye("isSeeking"),i=Ft("scrollHeight"),a=Ye("ItemComponent"),l=Ye("ListComponent"),c=Ye("ScrollSeekPlaceholder"),u=Ye("context"),f=Ft("itemDimensions"),h=Ft("gap"),p=Ye("log"),m=Ye("stateRestoreInProgress"),b=Ft("reportReadyState"),g=Gn(v.useMemo(()=>w=>{const y=w.parentElement.parentElement.scrollHeight;i(y);const k=w.firstChild;if(k){const{height:E,width:S}=k.getBoundingClientRect();f({height:E,width:S})}h({column:zu("column-gap",getComputedStyle(w).columnGap,p),row:zu("row-gap",getComputedStyle(w).rowGap,p)})},[i,f,h,p]),!0,!1);return Eu(()=>{e.itemHeight>0&&e.itemWidth>0&&b(!0)},[e]),m?null:d.jsx(l,{className:t,ref:g,...ut(l,u),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(w=>{const y=o(w.index,w.data,u);return s?d.jsx(c,{...ut(c,u),height:e.itemHeight,index:w.index,width:e.itemWidth},y):v.createElement(a,{...ut(a,u),className:n,"data-index":w.index,key:y},r(w.index,w.data,u))})})}),Mb=v.memo(function(){const e=Ye("HeaderComponent"),t=Ft("headerHeight"),n=Ye("headerFooterTag"),r=Gn(v.useMemo(()=>s=>{t(An(s,"height"))},[t]),!0,!1),o=Ye("context");return e?d.jsx(n,{ref:r,children:d.jsx(e,{...ut(e,o)})}):null}),Db=v.memo(function(){const e=Ye("FooterComponent"),t=Ft("footerHeight"),n=Ye("headerFooterTag"),r=Gn(v.useMemo(()=>s=>{t(An(s,"height"))},[t]),!0,!1),o=Ye("context");return e?d.jsx(n,{ref:r,children:d.jsx(e,{...ut(e,o)})}):null}),Lb=({children:e})=>{const t=v.useContext(ku),n=Ft("itemDimensions"),r=Ft("viewportDimensions"),o=Gn(v.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return v.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),d.jsx("div",{ref:o,style:Jo(!1),children:e})},$b=({children:e})=>{const t=v.useContext(ku),n=Ft("windowViewportRect"),r=Ft("itemDimensions"),o=Ye("customScrollParent"),s=Xc(n,o,!1);return v.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),d.jsx("div",{ref:s,style:Jo(!1),children:e})},Fb=v.memo(function({...e}){const t=Ye("useWindowScroll"),n=Ye("customScrollParent"),r=n||t?Bb:zb,o=n||t?$b:Lb,s=Ye("context");return d.jsx(r,{...e,...ut(r,s),children:d.jsxs(o,{children:[d.jsx(Mb,{}),d.jsx(Ob,{}),d.jsx(Db,{})]})})}),{useEmitter:Fu,useEmitterValue:Ye,usePublisher:Ft}=Cu(Rb,{optional:{context:"context",totalCount:"totalCount",overscan:"overscan",itemContent:"itemContent",components:"components",computeItemKey:"computeItemKey",data:"data",initialItemCount:"initialItemCount",scrollSeekConfiguration:"scrollSeekConfiguration",headerFooterTag:"headerFooterTag",listClassName:"listClassName",itemClassName:"itemClassName",useWindowScroll:"useWindowScroll",customScrollParent:"customScrollParent",scrollerRef:"scrollerRef",logLevel:"logLevel",restoreStateFrom:"restoreStateFrom",initialTopMostItemIndex:"initialTopMostItemIndex",increaseViewportBy:"increaseViewportBy"},methods:{scrollTo:"scrollTo",scrollBy:"scrollBy",scrollToIndex:"scrollToIndex"},events:{isScrolling:"isScrolling",endReached:"endReached",startReached:"startReached",rangeChanged:"rangeChanged",atBottomStateChange:"atBottomStateChange",atTopStateChange:"atTopStateChange",stateChanged:"stateChanged",readyStateChanged:"readyStateChanged"}},Fb),zb=_u({useEmitter:Fu,useEmitterValue:Ye,usePublisher:Ft}),Bb=Pu({useEmitter:Fu,useEmitterValue:Ye,usePublisher:Ft});function zu(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,kt.WARN),t==="normal"?0:parseInt(t??"0",10)}function Ub({artifact:e,showPartialData:t=!1}){if(!e||typeof e!="object")return null;const n=Do({artifact:e});if(!n)return null;const r=Eg(e),o=n.progress??0,s=n.status??"completed";if(s==="completed"&&!t)return null;const i=()=>{switch(s){case"pending":case"in_progress":return d.jsx(xe.Loader2,{className:"h-4 w-4 animate-spin text-blue-500"});case"completed":return d.jsx(xe.CheckCircle2,{className:"h-4 w-4 text-green-500"});case"failed":return d.jsx(xe.XCircle,{className:"h-4 w-4 text-red-500"});default:return null}},a=()=>{switch(s){case"pending":return"Preparing...";case"in_progress":return o>0?`${o}% complete`:"Processing...";case"completed":return"Complete";case"failed":return n.error??"Failed";default:return""}};return d.jsxs("div",{className:"rounded-md border border-border/40 bg-muted/30 p-3 space-y-2",children:[d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsxs("div",{className:"flex items-center gap-2",children:[i(),d.jsx("span",{className:"text-sm font-medium capitalize",children:n.type.replace(/_/g," ")})]}),d.jsx("span",{className:"text-xs text-muted-foreground",children:a()})]}),r&&o>0&&d.jsx("div",{className:"w-full bg-muted rounded-full h-1.5",children:d.jsx("div",{className:"bg-blue-500 h-1.5 rounded-full transition-all duration-300 ease-out",style:{width:`${o}%`}})}),s==="failed"&&n.error&&d.jsx("div",{className:"text-xs text-red-600 dark:text-red-400 bg-red-50 dark:bg-red-950/20 p-2 rounded",children:n.error}),t&&s==="in_progress"&&e.partial_data&&d.jsxs("div",{className:"text-xs text-muted-foreground",children:[d.jsx("div",{className:"font-medium mb-1",children:"Preview:"}),d.jsx("pre",{className:"bg-background/50 rounded p-2 overflow-auto max-h-32",children:JSON.stringify(e.partial_data,null,2)})]})]})}const Hb="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 Wb({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?d.jsx("div",{className:Hb,children:d.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>d.jsx("li",{children:String(n)},r))})}):d.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:mr(e)}):d.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:mr(e)})}const Bu="data:";function Vb(e){if(!e)return[];const t=[],n=e.split(/\r?\n/);for(const r of n){const o=r.trim();if(!o||!o.startsWith(Bu))continue;const s=o.slice(Bu.length).trim();if(!s||s.toLowerCase()==="[done]")continue;const i=hr(s);i&&typeof i=="object"&&t.push(i)}return t}function Kb(e){for(let t=e.length-1;t>=0;t-=1){const n=e[t];if(n&&typeof n=="object"&&n.type==="tool.end")return n}return null}function Uu(e){return v.useMemo(()=>{const t=e.content.filter(c=>c.type==="text");if(!t.length)return null;let r=t.flatMap(c=>Vb(c.text??""));if(!r.length){const c=t.map(f=>f.text??"").join(`
41
+ `),u=hr(c);u&&typeof u=="object"&&(r=[u])}if(!r.length)return null;const s=Kb(r)??r[r.length-1];if(!s)return null;const i=s.output??s.payload??s,a=gr(i),l=Wr(a);return l&&typeof l=="object"&&!Array.isArray(l)?{kind:"dict",value:l,data:l,event:s}:{kind:"generic",value:l,event:s}},[e])}function es({message:e,viewMode:t,isStreaming:n=!1,toolConfig:r,expandable:o=!1,artifactOverride:s=null,contentOverride:i=null}){var P;const{toolRenderers:a,toolArtifactRenderers:l}=r??{},c=dc(e),u=s??e.artifact??null,f=Array.isArray(i)?i:e.content,h=Uu(e),m=(h?hc(h):null)??h,b=f.length>0?f[0]:void 0,g=M=>{if(M==null)return null;const F=typeof M=="string"?M:(()=>{try{return JSON.stringify(M,null,2)}catch{return String(M)}})();return d.jsx("pre",{className:"whitespace-pre-wrap break-words font-sans text-xs text-muted-foreground/80 bg-muted/30 p-2 rounded border border-border/50",children:F})},w=M=>g(M),y=()=>{if((m==null?void 0:m.kind)==="generic")return w(m.value);if(!b)return null;if(b.type==="text"){const M=b.text??"";return M?w(M):null}return w(b)},k=()=>(m==null?void 0:m.kind)==="dict"?w(m.data):y(),S=(()=>{if(!a)return;if(c.name){const F=a[c.name];if(F)return F}const M=(m==null?void 0:m.kind)??(h==null?void 0:h.kind);if(M){const F=a[M];if(F)return F}return a.default})(),C=k(),T=!o||t==="expanded",N=(T?S==null?void 0:S({message:e,toolMeta:c,toolPayload:m,viewMode:t,isStreaming:n}):null)??null,_=(()=>{if(!l)return;const M=u==null?void 0:u.type;if(typeof M=="string"){const F=l[M];if(F)return F}return l.default})(),D=_?_({artifact:u,message:e,toolPayload:m,isStreaming:n}):null,z=N??C,H=_?D:null;return d.jsxs("div",{className:"space-y-2",children:[n&&d.jsx(Ub,{artifact:u,showPartialData:!1}),u&&H,T&&(((P=r==null?void 0:r.getShowContent)==null?void 0:P.call(r,e))??!0)?z:null]})}const zi=v.memo(function({toolCall:t,index:n,toolName:r,className:o=""}){const{onSelectToolCall:s}=zo(),i=t.state==="pending",a=t.state==="error",l=t.call.name||r||"tool";return d.jsxs("div",{onClick:()=>s==null?void 0:s(t),className:`group/call flex items-start gap-3 px-2 py-1.5 rounded-md hover:bg-muted/30 transition-colors cursor-pointer ${o}`,children:[d.jsx("div",{className:"shrink-0 flex items-center justify-center h-4 mt-0.5",children:d.jsx("span",{className:"text-[10px] font-mono font-medium text-muted-foreground/40 group-hover/call:text-muted-foreground/60 transition-colors",children:n!==void 0?(n+1).toString().padStart(2,"0"):"●"})}),d.jsxs("div",{className:"flex-1 min-w-0",children:[d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx("span",{className:"text-[11px] font-medium text-muted-foreground/70 group-hover/call:text-foreground/80 transition-colors truncate",children:l}),i?d.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[d.jsx("span",{className:"flex h-1.5 w-1.5 rounded-full bg-blue-500 animate-pulse"}),d.jsx("span",{className:"text-[9px] text-blue-500 font-medium lowercase",children:"running"})]}):a?d.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[d.jsx("span",{className:"flex h-1.5 w-1.5 rounded-full bg-red-500"}),d.jsx("span",{className:"text-[9px] text-red-500 font-medium lowercase",children:"error"})]}):d.jsx("div",{className:"flex items-center gap-1 shrink-0 opacity-0 group-hover/call:opacity-100 transition-opacity",children:d.jsx("span",{className:"text-[9px] text-muted-foreground/50 font-medium lowercase",children:"completed"})}),!!t.artifact&&d.jsx("span",{className:"shrink-0 text-[8px] px-1 py-0 rounded bg-primary/10 text-primary/70 font-semibold border border-primary/20 leading-none",children:"Artifact Created"})]}),t.call.content&&d.jsx("p",{className:"text-[10px] text-muted-foreground/60 truncate group-hover/call:text-muted-foreground/80 transition-colors",children:t.call.content}),Array.isArray(t.progress)&&t.progress.length>0&&d.jsx("div",{className:"mt-1 space-y-0.5",children:t.progress.map((c,u)=>{const f=typeof c.content=="string"?c.content:void 0;return f?d.jsx("p",{className:"text-[9px] text-muted-foreground/50 truncate",children:f},`${t.call.id}-progress-${u}`):null})})]})]})});zi.displayName="ToolCallCard";function Hu({messages:e,toolConfig:t,wrapperClassName:n}){var i;const r=((i=e[0])==null?void 0:i.name)??"tool",o=di(e).filter(a=>{var l;return e.length===1&&e[0].role==="tool"?((l=t==null?void 0:t.getShowProgress)==null?void 0:l.call(t,e[0]))??!0:!!a});if(o.length===0)return null;const s=d.jsx("div",{className:"space-y-1",children:o.map((a,l)=>d.jsx(zi,{toolCall:a,index:l,toolName:r},a.call.id||l))});return n?d.jsx("div",{className:n,children:s}):d.jsx("div",{className:"space-y-1 py-1",children:s})}const Wu=x.forwardRef(({className:e,...t},n)=>d.jsx("div",{ref:n,className:he("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));Wu.displayName="Card";const Vu=x.forwardRef(({className:e,...t},n)=>d.jsx("div",{ref:n,className:he("flex flex-col space-y-1.5 p-6",e),...t}));Vu.displayName="CardHeader";const Ku=x.forwardRef(({className:e,...t},n)=>d.jsx("h3",{ref:n,className:he("text-2xl font-semibold leading-none tracking-tight",e),...t}));Ku.displayName="CardTitle";const qu=x.forwardRef(({className:e,...t},n)=>d.jsx("p",{ref:n,className:he("text-sm text-muted-foreground",e),...t}));qu.displayName="CardDescription";const Bi=x.forwardRef(({className:e,...t},n)=>d.jsx("div",{ref:n,className:he("p-6 pt-0",e),...t}));Bi.displayName="CardContent";const Gu=x.forwardRef(({className:e,...t},n)=>d.jsx("div",{ref:n,className:he("flex items-center p-6 pt-0",e),...t}));Gu.displayName="CardFooter";const qb=e=>!!e&&typeof e=="object"&&e.type==="user_choice"&&typeof e.question=="string"&&Array.isArray(e.alternatives);function Yu({interruptPart:e,onApprove:t,onReject:n,onSelectAlternative:r,disabled:o,isActive:s,payload:i}){const a=qb(i)?i:null,l=(a==null?void 0:a.question)??e.title??"Approve the result?",c=a?s?"Select one of the alternatives to continue.":"Waiting for approval from another participant.":s?"Please approve or reject this action to resume the workflow.":"Waiting for approval from another participant.";let u=null;if(!a&&i!==void 0&&i!==null)if(typeof i=="string")u=d.jsx("p",{className:"text-sm leading-relaxed text-blue-800/90 dark:text-blue-200/90 whitespace-pre-wrap",children:i});else{const f=mr(i);u=d.jsx("pre",{className:"max-h-48 overflow-auto rounded bg-blue-100/60 p-2 text-xs text-blue-900/90 dark:bg-blue-900/40 dark:text-blue-100/80",children:f})}return d.jsxs(Wu,{className:he("border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10 transition-shadow",s?"shadow-md ring-1 ring-blue-300 dark:ring-blue-500/70":"opacity-80"),children:[d.jsxs(Vu,{className:"pb-3",children:[d.jsx(Ku,{className:"text-blue-900 dark:text-blue-100 text-base",children:l}),d.jsx(qu,{className:"text-blue-700 dark:text-blue-300 text-sm",children:c})]}),a?d.jsx(Bi,{className:"pt-0 pb-3",children:d.jsx("div",{className:"space-y-2",children:a.alternatives.map(f=>d.jsx(Je,{size:"sm",variant:"outline",onClick:()=>r==null?void 0:r(e,f),className:"w-full justify-start text-left",disabled:o||!s,children:d.jsxs("div",{className:"flex flex-col items-start gap-1",children:[d.jsx("span",{className:"font-semibold",children:f.label}),f.description?d.jsx("span",{className:"text-xs text-muted-foreground leading-snug",children:f.description}):null]})},f.id))})}):u&&d.jsx(Bi,{className:"pt-0 pb-3",children:u}),!a&&d.jsx(Gu,{className:"pt-0",children:d.jsxs("div",{className:"flex gap-2 ml-auto",children:[d.jsx(Je,{size:"sm",variant:"outline",onClick:()=>n(e),className:"border-red-300 text-red-700 hover:bg-red-50 dark:border-red-700 dark:text-red-300 dark:hover:bg-red-950/50",disabled:o||!s,children:"Reject"}),d.jsx(Je,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:o||!s,children:"Approve"})]})})]})}function Gb({className:e}){const t=v.useRef(null);return v.useEffect(()=>{let n=0;const r=()=>{if(n=(n+1)%4,t.current){const s=".".repeat(n);t.current.textContent=`Is thinking${s}`}};r();const o=setInterval(r,500);return()=>clearInterval(o)},[]),d.jsx("span",{ref:t,"aria-live":"polite",className:he("inline-block text-xs opacity-70 ml-1",e),children:"Is thinking"})}function Xu(){return{async:!1,baseUrl:null,breaks:!1,extensions:null,gfm:!0,headerIds:!0,headerPrefix:"",highlight:null,hooks:null,langPrefix:"language-",mangle:!0,pedantic:!1,renderer:null,sanitize:!1,sanitizer:null,silent:!1,smartypants:!1,tokenizer:null,walkTokens:null,xhtml:!1}}let Jn=Xu();function Yb(e){Jn=e}const Ju=/[&<>"']/,Xb=new RegExp(Ju.source,"g"),Zu=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,Jb=new RegExp(Zu.source,"g"),Zb={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Qu=e=>Zb[e];function dt(e,t){if(t){if(Ju.test(e))return e.replace(Xb,Qu)}else if(Zu.test(e))return e.replace(Jb,Qu);return e}const Qb=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function ed(e){return e.replace(Qb,(t,n)=>(n=n.toLowerCase(),n==="colon"?":":n.charAt(0)==="#"?n.charAt(1)==="x"?String.fromCharCode(parseInt(n.substring(2),16)):String.fromCharCode(+n.substring(1)):""))}const ew=/(^|[^\[])\^/g;function He(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(ew,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const tw=/[^\w:]/g,nw=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function td(e,t,n){if(e){let r;try{r=decodeURIComponent(ed(n)).replace(tw,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!nw.test(n)&&(n=iw(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const ts={},rw=/^[^:]+:\/*[^/]*$/,ow=/^([^:]+:)[\s\S]*$/,sw=/^([^:]+:\/*[^/]*)[\s\S]*$/;function iw(e,t){ts[" "+e]||(rw.test(e)?ts[" "+e]=e+"/":ts[" "+e]=rs(e,"/",!0)),e=ts[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(ow,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(sw,"$1")+t:e+t}const ns={exec:function(){}};function nd(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,c=i;for(;--c>=0&&a[c]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function rs(e,t,n){const r=e.length;if(r===0)return"";let o=0;for(;o<r;){const s=e.charAt(r-o-1);if(s===t&&!n)o++;else if(s!==t&&n)o++;else break}return e.slice(0,r-o)}function aw(e,t){if(e.indexOf(t[1])===-1)return-1;const n=e.length;let r=0,o=0;for(;o<n;o++)if(e[o]==="\\")o++;else if(e[o]===t[0])r++;else if(e[o]===t[1]&&(r--,r<0))return o;return-1}function lw(e){e&&e.sanitize&&!e.silent&&console.warn("marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options")}function rd(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function od(e,t,n,r){const o=t.href,s=t.title?dt(t.title):null,i=e[1].replace(/\\([\[\]])/g,"$1");if(e[0].charAt(0)!=="!"){r.state.inLink=!0;const a={type:"link",raw:n,href:o,title:s,text:i,tokens:r.inlineTokens(i)};return r.state.inLink=!1,a}return{type:"image",raw:n,href:o,title:s,text:dt(i)}}function cw(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
42
42
  `).map(o=>{const s=o.match(/^\s+/);if(s===null)return o;const[i]=s;return i.length>=r.length?o.slice(r.length):o}).join(`
43
43
  `)}class Ui{constructor(t){this.options=t||Jn}space(t){const n=this.rules.block.newline.exec(t);if(n&&n[0].length>0)return{type:"space",raw:n[0]}}code(t){const n=this.rules.block.code.exec(t);if(n){const r=n[0].replace(/^ {1,4}/gm,"");return{type:"code",raw:n[0],codeBlockStyle:"indented",text:this.options.pedantic?r:rs(r,`
44
44
  `)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=cw(r,n[3]||"");return{type:"code",raw:r,lang:n[2]?n[2].trim().replace(this.rules.inline._escapes,"$1"):n[2],text:o}}}heading(t){const n=this.rules.block.heading.exec(t);if(n){let r=n[2].trim();if(/#$/.test(r)){const o=rs(r,"#");(this.options.pedantic||!o||/ $/.test(o))&&(r=o.trim())}return{type:"heading",raw:n[0],depth:n[1].length,text:r,tokens:this.lexer.inline(r)}}}hr(t){const n=this.rules.block.hr.exec(t);if(n)return{type:"hr",raw:n[0]}}blockquote(t){const n=this.rules.block.blockquote.exec(t);if(n){const r=n[0].replace(/^ *>[ \t]?/gm,""),o=this.lexer.state.top;this.lexer.state.top=!0;const s=this.lexer.blockTokens(r);return this.lexer.state.top=o,{type:"blockquote",raw:n[0],tokens:s,text:r}}}list(t){let n=this.rules.block.list.exec(t);if(n){let r,o,s,i,a,l,c,u,f,h,p,m,b=n[1].trim();const g=b.length>1,w={type:"list",raw:"",ordered:g,start:g?+b.slice(0,-1):"",loose:!1,items:[]};b=g?`\\d{1,9}\\${b.slice(-1)}`:`\\${b}`,this.options.pedantic&&(b=g?b:"[*+-]");const y=new RegExp(`^( {0,3}${b})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;t&&(m=!1,!(!(n=y.exec(t))||this.rules.block.hr.test(t)));){if(r=n[0],t=t.substring(r.length),u=n[2].split(`
@@ -50,8 +50,8 @@ React keys must be passed directly to JSX without using spread:
50
50
  `+f}!l&&!f.trim()&&(l=!0),r+=h+`
51
51
  `,t=t.substring(h.length+1),u=f.slice(i)}}w.loose||(c?w.loose=!0:/\n *\n *$/.test(r)&&(c=!0)),this.options.gfm&&(o=/^\[[ xX]\] /.exec(p),o&&(s=o[0]!=="[ ] ",p=p.replace(/^\[[ xX]\] +/,""))),w.items.push({type:"list_item",raw:r,task:!!o,checked:s,loose:!1,text:p}),w.raw+=r}w.items[w.items.length-1].raw=r.trimRight(),w.items[w.items.length-1].text=p.trimRight(),w.raw=w.raw.trimRight();const k=w.items.length;for(a=0;a<k;a++)if(this.lexer.state.top=!1,w.items[a].tokens=this.lexer.blockTokens(w.items[a].text,[]),!w.loose){const E=w.items[a].tokens.filter(C=>C.type==="space"),S=E.length>0&&E.some(C=>/\n.*\n/.test(C.raw));w.loose=S}if(w.loose)for(a=0;a<k;a++)w.items[a].loose=!0;return w}}html(t){const n=this.rules.block.html.exec(t);if(n){const r={type:"html",raw:n[0],pre:!this.options.sanitizer&&(n[1]==="pre"||n[1]==="script"||n[1]==="style"),text:n[0]};if(this.options.sanitize){const o=this.options.sanitizer?this.options.sanitizer(n[0]):dt(n[0]);r.type="paragraph",r.text=o,r.tokens=this.lexer.inline(o)}return r}}def(t){const n=this.rules.block.def.exec(t);if(n){const r=n[1].toLowerCase().replace(/\s+/g," "),o=n[2]?n[2].replace(/^<(.*)>$/,"$1").replace(this.rules.inline._escapes,"$1"):"",s=n[3]?n[3].substring(1,n[3].length-1).replace(this.rules.inline._escapes,"$1"):n[3];return{type:"def",tag:r,raw:n[0],href:o,title:s}}}table(t){const n=this.rules.block.table.exec(t);if(n){const r={type:"table",header:nd(n[1]).map(o=>({text:o})),align:n[2].replace(/^ *|\| *$/g,"").split(/ *\| */),rows:n[3]&&n[3].trim()?n[3].replace(/\n[ \t]*$/,"").split(`
52
52
  `):[]};if(r.header.length===r.align.length){r.raw=n[0];let o=r.align.length,s,i,a,l;for(s=0;s<o;s++)/^ *-+: *$/.test(r.align[s])?r.align[s]="right":/^ *:-+: *$/.test(r.align[s])?r.align[s]="center":/^ *:-+ *$/.test(r.align[s])?r.align[s]="left":r.align[s]=null;for(o=r.rows.length,s=0;s<o;s++)r.rows[s]=nd(r.rows[s],r.header.length).map(c=>({text:c}));for(o=r.header.length,i=0;i<o;i++)r.header[i].tokens=this.lexer.inline(r.header[i].text);for(o=r.rows.length,i=0;i<o;i++)for(l=r.rows[i],a=0;a<l.length;a++)l[a].tokens=this.lexer.inline(l[a].text);return r}}}lheading(t){const n=this.rules.block.lheading.exec(t);if(n)return{type:"heading",raw:n[0],depth:n[2].charAt(0)==="="?1:2,text:n[1],tokens:this.lexer.inline(n[1])}}paragraph(t){const n=this.rules.block.paragraph.exec(t);if(n){const r=n[1].charAt(n[1].length-1)===`
53
- `?n[1].slice(0,-1):n[1];return{type:"paragraph",raw:n[0],text:r,tokens:this.lexer.inline(r)}}}text(t){const n=this.rules.block.text.exec(t);if(n)return{type:"text",raw:n[0],text:n[0],tokens:this.lexer.inline(n[0])}}escape(t){const n=this.rules.inline.escape.exec(t);if(n)return{type:"escape",raw:n[0],text:dt(n[1])}}tag(t){const n=this.rules.inline.tag.exec(t);if(n)return!this.lexer.state.inLink&&/^<a /i.test(n[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&/^<\/a>/i.test(n[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(n[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(n[0])&&(this.lexer.state.inRawBlock=!1),{type:this.options.sanitize?"text":"html",raw:n[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,text:this.options.sanitize?this.options.sanitizer?this.options.sanitizer(n[0]):dt(n[0]):n[0]}}link(t){const n=this.rules.inline.link.exec(t);if(n){const r=n[2].trim();if(!this.options.pedantic&&/^</.test(r)){if(!/>$/.test(r))return;const i=rs(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=aw(n[2],"()");if(i>-1){const l=(n[0].indexOf("!")===0?5:4)+n[1].length+i;n[2]=n[2].substring(0,i),n[0]=n[0].substring(0,l).trim(),n[3]=""}}let o=n[2],s="";if(this.options.pedantic){const i=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(o);i&&(o=i[1],s=i[3])}else s=n[3]?n[3].slice(1,-1):"";return o=o.trim(),/^</.test(o)&&(this.options.pedantic&&!/>$/.test(r)?o=o.slice(1):o=o.slice(1,-1)),od(n,{href:o&&o.replace(this.rules.inline._escapes,"$1"),title:s&&s.replace(this.rules.inline._escapes,"$1")},n[0],this.lexer)}}reflink(t,n){let r;if((r=this.rules.inline.reflink.exec(t))||(r=this.rules.inline.nolink.exec(t))){let o=(r[2]||r[1]).replace(/\s+/g," ");if(o=n[o.toLowerCase()],!o){const s=r[0].charAt(0);return{type:"text",raw:s,text:s}}return od(r,o,r[0],this.lexer)}}emStrong(t,n,r=""){let o=this.rules.inline.emStrong.lDelim.exec(t);if(!o||o[3]&&r.match(/[\p{L}\p{N}]/u))return;const s=o[1]||o[2]||"";if(!s||s&&(r===""||this.rules.inline.punctuation.exec(r))){const i=o[0].length-1;let a,l,c=i,u=0;const f=o[0][0]==="*"?this.rules.inline.emStrong.rDelimAst:this.rules.inline.emStrong.rDelimUnd;for(f.lastIndex=0,n=n.slice(-1*t.length+i);(o=f.exec(n))!=null;){if(a=o[1]||o[2]||o[3]||o[4]||o[5]||o[6],!a)continue;if(l=a.length,o[3]||o[4]){c+=l;continue}else if((o[5]||o[6])&&i%3&&!((i+l)%3)){u+=l;continue}if(c-=l,c>0)continue;l=Math.min(l,l+c+u);const h=t.slice(0,i+o.index+(o[0].length-a.length)+l);if(Math.min(i,l)%2){const m=h.slice(1,-1);return{type:"em",raw:h,text:m,tokens:this.lexer.inlineTokens(m)}}const p=h.slice(2,-2);return{type:"strong",raw:h,text:p,tokens:this.lexer.inlineTokens(p)}}}}codespan(t){const n=this.rules.inline.code.exec(t);if(n){let r=n[2].replace(/\n/g," ");const o=/[^ ]/.test(r),s=/^ /.test(r)&&/ $/.test(r);return o&&s&&(r=r.substring(1,r.length-1)),r=dt(r,!0),{type:"codespan",raw:n[0],text:r}}}br(t){const n=this.rules.inline.br.exec(t);if(n)return{type:"br",raw:n[0]}}del(t){const n=this.rules.inline.del.exec(t);if(n)return{type:"del",raw:n[0],text:n[2],tokens:this.lexer.inlineTokens(n[2])}}autolink(t,n){const r=this.rules.inline.autolink.exec(t);if(r){let o,s;return r[2]==="@"?(o=dt(this.options.mangle?n(r[1]):r[1]),s="mailto:"+o):(o=dt(r[1]),s=o),{type:"link",raw:r[0],text:o,href:s,tokens:[{type:"text",raw:o,text:o}]}}}url(t,n){let r;if(r=this.rules.inline.url.exec(t)){let o,s;if(r[2]==="@")o=dt(this.options.mangle?n(r[0]):r[0]),s="mailto:"+o;else{let i;do i=r[0],r[0]=this.rules.inline._backpedal.exec(r[0])[0];while(i!==r[0]);o=dt(r[0]),r[1]==="www."?s="http://"+r[0]:s=r[0]}return{type:"link",raw:r[0],text:o,href:s,tokens:[{type:"text",raw:o,text:o}]}}}inlineText(t,n){const r=this.rules.inline.text.exec(t);if(r){let o;return this.lexer.state.inRawBlock?o=this.options.sanitize?this.options.sanitizer?this.options.sanitizer(r[0]):dt(r[0]):r[0]:o=dt(this.options.smartypants?n(r[0]):r[0]),{type:"text",raw:r[0],text:o}}}}const pe={newline:/^(?: *(?:\n|$))+/,code:/^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,hr:/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,blockquote:/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,list:/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/,html:"^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$))",def:/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/,table:ns,lheading:/^((?:.|\n(?!\n))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,text:/^[^\n]+/};pe._label=/(?!\s*\])(?:\\.|[^\[\]\\])+/,pe._title=/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/,pe.def=Ue(pe.def).replace("label",pe._label).replace("title",pe._title).getRegex(),pe.bullet=/(?:[*+-]|\d{1,9}[.)])/,pe.listItemStart=Ue(/^( *)(bull) */).replace("bull",pe.bullet).getRegex(),pe.list=Ue(pe.list).replace(/bull/g,pe.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+pe.def.source+")").getRegex(),pe._tag="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",pe._comment=/<!--(?!-?>)[\s\S]*?(?:-->|$)/,pe.html=Ue(pe.html,"i").replace("comment",pe._comment).replace("tag",pe._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),pe.paragraph=Ue(pe._paragraph).replace("hr",pe.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",pe._tag).getRegex(),pe.blockquote=Ue(pe.blockquote).replace("paragraph",pe.paragraph).getRegex(),pe.normal={...pe},pe.gfm={...pe.normal,table:"^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"},pe.gfm.table=Ue(pe.gfm.table).replace("hr",pe.hr).replace("heading"," {0,3}#{1,6} ").replace("blockquote"," {0,3}>").replace("code"," {4}[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",pe._tag).getRegex(),pe.gfm.paragraph=Ue(pe._paragraph).replace("hr",pe.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("table",pe.gfm.table).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",pe._tag).getRegex(),pe.pedantic={...pe.normal,html:Ue(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",pe._comment).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:ns,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:Ue(pe.normal._paragraph).replace("hr",pe.hr).replace("heading",` *#{1,6} *[^
54
- ]`).replace("lheading",pe.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const ce={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:ns,tag:"^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>",link:/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,reflink:/^!?\[(label)\]\[(ref)\]/,nolink:/^!?\[(ref)\](?:\[\])?/,reflinkSearch:"reflink|nolink(?!\\()",emStrong:{lDelim:/^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/,rDelimAst:/^(?:[^_*\\]|\\.)*?\_\_(?:[^_*\\]|\\.)*?\*(?:[^_*\\]|\\.)*?(?=\_\_)|(?:[^*\\]|\\.)+(?=[^*])|[punct_](\*+)(?=[\s]|$)|(?:[^punct*_\s\\]|\\.)(\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|(?:[^punct*_\s\\]|\\.)(\*+)(?=[^punct*_\s])/,rDelimUnd:/^(?:[^_*\\]|\\.)*?\*\*(?:[^_*\\]|\\.)*?\_(?:[^_*\\]|\\.)*?(?=\*\*)|(?:[^_\\]|\\.)+(?=[^_])|[punct*](\_+)(?=[\s]|$)|(?:[^punct*_\s\\]|\\.)(\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/},code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,br:/^( {2,}|\\)\n(?!\s*$)/,del:ns,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,punctuation:/^([\spunctuation])/};ce._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",ce.punctuation=Ue(ce.punctuation).replace(/punctuation/g,ce._punctuation).getRegex(),ce.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g,ce.escapedEmSt=/(?:^|[^\\])(?:\\\\)*\\[*_]/g,ce._comment=Ue(pe._comment).replace("(?:-->|$)","-->").getRegex(),ce.emStrong.lDelim=Ue(ce.emStrong.lDelim).replace(/punct/g,ce._punctuation).getRegex(),ce.emStrong.rDelimAst=Ue(ce.emStrong.rDelimAst,"g").replace(/punct/g,ce._punctuation).getRegex(),ce.emStrong.rDelimUnd=Ue(ce.emStrong.rDelimUnd,"g").replace(/punct/g,ce._punctuation).getRegex(),ce._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,ce._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,ce._email=/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/,ce.autolink=Ue(ce.autolink).replace("scheme",ce._scheme).replace("email",ce._email).getRegex(),ce._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,ce.tag=Ue(ce.tag).replace("comment",ce._comment).replace("attribute",ce._attribute).getRegex(),ce._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,ce._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/,ce._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,ce.link=Ue(ce.link).replace("label",ce._label).replace("href",ce._href).replace("title",ce._title).getRegex(),ce.reflink=Ue(ce.reflink).replace("label",ce._label).replace("ref",pe._label).getRegex(),ce.nolink=Ue(ce.nolink).replace("ref",pe._label).getRegex(),ce.reflinkSearch=Ue(ce.reflinkSearch,"g").replace("reflink",ce.reflink).replace("nolink",ce.nolink).getRegex(),ce.normal={...ce},ce.pedantic={...ce.normal,strong:{start:/^__|\*\*/,middle:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,endAst:/\*\*(?!\*)/g,endUnd:/__(?!_)/g},em:{start:/^_|\*/,middle:/^()\*(?=\S)([\s\S]*?\S)\*(?!\*)|^_(?=\S)([\s\S]*?\S)_(?!_)/,endAst:/\*(?!\*)/g,endUnd:/_(?!_)/g},link:Ue(/^!?\[(label)\]\((.*?)\)/).replace("label",ce._label).getRegex(),reflink:Ue(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",ce._label).getRegex()},ce.gfm={...ce.normal,escape:Ue(ce.escape).replace("])","~|])").getRegex(),_extended_email:/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,url:/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},ce.gfm.url=Ue(ce.gfm.url,"i").replace("email",ce.gfm._extended_email).getRegex(),ce.breaks={...ce.gfm,br:Ue(ce.br).replace("{2,}","*").getRegex(),text:Ue(ce.gfm.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()};function uw(e){return e.replace(/---/g,"—").replace(/--/g,"–").replace(/(^|[-\u2014/(\[{"\s])'/g,"$1‘").replace(/'/g,"’").replace(/(^|[-\u2014/(\[{\u2018\s])"/g,"$1“").replace(/"/g,"”").replace(/\.{3}/g,"…")}function sd(e){let t="",n,r;const o=e.length;for(n=0;n<o;n++)r=e.charCodeAt(n),Math.random()>.5&&(r="x"+r.toString(16)),t+="&#"+r+";";return t}class Pn{constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||Jn,this.options.tokenizer=this.options.tokenizer||new Ui,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const n={block:pe.normal,inline:ce.normal};this.options.pedantic?(n.block=pe.pedantic,n.inline=ce.pedantic):this.options.gfm&&(n.block=pe.gfm,this.options.breaks?n.inline=ce.breaks:n.inline=ce.gfm),this.tokenizer.rules=n}static get rules(){return{block:pe,inline:ce}}static lex(t,n){return new Pn(n).lex(t)}static lexInline(t,n){return new Pn(n).inlineTokens(t)}lex(t){t=t.replace(/\r\n|\r/g,`
53
+ `?n[1].slice(0,-1):n[1];return{type:"paragraph",raw:n[0],text:r,tokens:this.lexer.inline(r)}}}text(t){const n=this.rules.block.text.exec(t);if(n)return{type:"text",raw:n[0],text:n[0],tokens:this.lexer.inline(n[0])}}escape(t){const n=this.rules.inline.escape.exec(t);if(n)return{type:"escape",raw:n[0],text:dt(n[1])}}tag(t){const n=this.rules.inline.tag.exec(t);if(n)return!this.lexer.state.inLink&&/^<a /i.test(n[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&/^<\/a>/i.test(n[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(n[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(n[0])&&(this.lexer.state.inRawBlock=!1),{type:this.options.sanitize?"text":"html",raw:n[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,text:this.options.sanitize?this.options.sanitizer?this.options.sanitizer(n[0]):dt(n[0]):n[0]}}link(t){const n=this.rules.inline.link.exec(t);if(n){const r=n[2].trim();if(!this.options.pedantic&&/^</.test(r)){if(!/>$/.test(r))return;const i=rs(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=aw(n[2],"()");if(i>-1){const l=(n[0].indexOf("!")===0?5:4)+n[1].length+i;n[2]=n[2].substring(0,i),n[0]=n[0].substring(0,l).trim(),n[3]=""}}let o=n[2],s="";if(this.options.pedantic){const i=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(o);i&&(o=i[1],s=i[3])}else s=n[3]?n[3].slice(1,-1):"";return o=o.trim(),/^</.test(o)&&(this.options.pedantic&&!/>$/.test(r)?o=o.slice(1):o=o.slice(1,-1)),od(n,{href:o&&o.replace(this.rules.inline._escapes,"$1"),title:s&&s.replace(this.rules.inline._escapes,"$1")},n[0],this.lexer)}}reflink(t,n){let r;if((r=this.rules.inline.reflink.exec(t))||(r=this.rules.inline.nolink.exec(t))){let o=(r[2]||r[1]).replace(/\s+/g," ");if(o=n[o.toLowerCase()],!o){const s=r[0].charAt(0);return{type:"text",raw:s,text:s}}return od(r,o,r[0],this.lexer)}}emStrong(t,n,r=""){let o=this.rules.inline.emStrong.lDelim.exec(t);if(!o||o[3]&&r.match(/[\p{L}\p{N}]/u))return;const s=o[1]||o[2]||"";if(!s||s&&(r===""||this.rules.inline.punctuation.exec(r))){const i=o[0].length-1;let a,l,c=i,u=0;const f=o[0][0]==="*"?this.rules.inline.emStrong.rDelimAst:this.rules.inline.emStrong.rDelimUnd;for(f.lastIndex=0,n=n.slice(-1*t.length+i);(o=f.exec(n))!=null;){if(a=o[1]||o[2]||o[3]||o[4]||o[5]||o[6],!a)continue;if(l=a.length,o[3]||o[4]){c+=l;continue}else if((o[5]||o[6])&&i%3&&!((i+l)%3)){u+=l;continue}if(c-=l,c>0)continue;l=Math.min(l,l+c+u);const h=t.slice(0,i+o.index+(o[0].length-a.length)+l);if(Math.min(i,l)%2){const m=h.slice(1,-1);return{type:"em",raw:h,text:m,tokens:this.lexer.inlineTokens(m)}}const p=h.slice(2,-2);return{type:"strong",raw:h,text:p,tokens:this.lexer.inlineTokens(p)}}}}codespan(t){const n=this.rules.inline.code.exec(t);if(n){let r=n[2].replace(/\n/g," ");const o=/[^ ]/.test(r),s=/^ /.test(r)&&/ $/.test(r);return o&&s&&(r=r.substring(1,r.length-1)),r=dt(r,!0),{type:"codespan",raw:n[0],text:r}}}br(t){const n=this.rules.inline.br.exec(t);if(n)return{type:"br",raw:n[0]}}del(t){const n=this.rules.inline.del.exec(t);if(n)return{type:"del",raw:n[0],text:n[2],tokens:this.lexer.inlineTokens(n[2])}}autolink(t,n){const r=this.rules.inline.autolink.exec(t);if(r){let o,s;return r[2]==="@"?(o=dt(this.options.mangle?n(r[1]):r[1]),s="mailto:"+o):(o=dt(r[1]),s=o),{type:"link",raw:r[0],text:o,href:s,tokens:[{type:"text",raw:o,text:o}]}}}url(t,n){let r;if(r=this.rules.inline.url.exec(t)){let o,s;if(r[2]==="@")o=dt(this.options.mangle?n(r[0]):r[0]),s="mailto:"+o;else{let i;do i=r[0],r[0]=this.rules.inline._backpedal.exec(r[0])[0];while(i!==r[0]);o=dt(r[0]),r[1]==="www."?s="http://"+r[0]:s=r[0]}return{type:"link",raw:r[0],text:o,href:s,tokens:[{type:"text",raw:o,text:o}]}}}inlineText(t,n){const r=this.rules.inline.text.exec(t);if(r){let o;return this.lexer.state.inRawBlock?o=this.options.sanitize?this.options.sanitizer?this.options.sanitizer(r[0]):dt(r[0]):r[0]:o=dt(this.options.smartypants?n(r[0]):r[0]),{type:"text",raw:r[0],text:o}}}}const ge={newline:/^(?: *(?:\n|$))+/,code:/^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,fences:/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,hr:/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,heading:/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,blockquote:/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,list:/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/,html:"^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$))",def:/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/,table:ns,lheading:/^((?:.|\n(?!\n))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,text:/^[^\n]+/};ge._label=/(?!\s*\])(?:\\.|[^\[\]\\])+/,ge._title=/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/,ge.def=He(ge.def).replace("label",ge._label).replace("title",ge._title).getRegex(),ge.bullet=/(?:[*+-]|\d{1,9}[.)])/,ge.listItemStart=He(/^( *)(bull) */).replace("bull",ge.bullet).getRegex(),ge.list=He(ge.list).replace(/bull/g,ge.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+ge.def.source+")").getRegex(),ge._tag="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",ge._comment=/<!--(?!-?>)[\s\S]*?(?:-->|$)/,ge.html=He(ge.html,"i").replace("comment",ge._comment).replace("tag",ge._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),ge.paragraph=He(ge._paragraph).replace("hr",ge.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ge._tag).getRegex(),ge.blockquote=He(ge.blockquote).replace("paragraph",ge.paragraph).getRegex(),ge.normal={...ge},ge.gfm={...ge.normal,table:"^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"},ge.gfm.table=He(ge.gfm.table).replace("hr",ge.hr).replace("heading"," {0,3}#{1,6} ").replace("blockquote"," {0,3}>").replace("code"," {4}[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ge._tag).getRegex(),ge.gfm.paragraph=He(ge._paragraph).replace("hr",ge.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("table",ge.gfm.table).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ge._tag).getRegex(),ge.pedantic={...ge.normal,html:He(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",ge._comment).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:ns,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:He(ge.normal._paragraph).replace("hr",ge.hr).replace("heading",` *#{1,6} *[^
54
+ ]`).replace("lheading",ge.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const ce={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:ns,tag:"^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>",link:/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,reflink:/^!?\[(label)\]\[(ref)\]/,nolink:/^!?\[(ref)\](?:\[\])?/,reflinkSearch:"reflink|nolink(?!\\()",emStrong:{lDelim:/^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/,rDelimAst:/^(?:[^_*\\]|\\.)*?\_\_(?:[^_*\\]|\\.)*?\*(?:[^_*\\]|\\.)*?(?=\_\_)|(?:[^*\\]|\\.)+(?=[^*])|[punct_](\*+)(?=[\s]|$)|(?:[^punct*_\s\\]|\\.)(\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|(?:[^punct*_\s\\]|\\.)(\*+)(?=[^punct*_\s])/,rDelimUnd:/^(?:[^_*\\]|\\.)*?\*\*(?:[^_*\\]|\\.)*?\_(?:[^_*\\]|\\.)*?(?=\*\*)|(?:[^_\\]|\\.)+(?=[^_])|[punct*](\_+)(?=[\s]|$)|(?:[^punct*_\s\\]|\\.)(\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/},code:/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,br:/^( {2,}|\\)\n(?!\s*$)/,del:ns,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,punctuation:/^([\spunctuation])/};ce._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",ce.punctuation=He(ce.punctuation).replace(/punctuation/g,ce._punctuation).getRegex(),ce.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g,ce.escapedEmSt=/(?:^|[^\\])(?:\\\\)*\\[*_]/g,ce._comment=He(ge._comment).replace("(?:-->|$)","-->").getRegex(),ce.emStrong.lDelim=He(ce.emStrong.lDelim).replace(/punct/g,ce._punctuation).getRegex(),ce.emStrong.rDelimAst=He(ce.emStrong.rDelimAst,"g").replace(/punct/g,ce._punctuation).getRegex(),ce.emStrong.rDelimUnd=He(ce.emStrong.rDelimUnd,"g").replace(/punct/g,ce._punctuation).getRegex(),ce._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,ce._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,ce._email=/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/,ce.autolink=He(ce.autolink).replace("scheme",ce._scheme).replace("email",ce._email).getRegex(),ce._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,ce.tag=He(ce.tag).replace("comment",ce._comment).replace("attribute",ce._attribute).getRegex(),ce._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,ce._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/,ce._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,ce.link=He(ce.link).replace("label",ce._label).replace("href",ce._href).replace("title",ce._title).getRegex(),ce.reflink=He(ce.reflink).replace("label",ce._label).replace("ref",ge._label).getRegex(),ce.nolink=He(ce.nolink).replace("ref",ge._label).getRegex(),ce.reflinkSearch=He(ce.reflinkSearch,"g").replace("reflink",ce.reflink).replace("nolink",ce.nolink).getRegex(),ce.normal={...ce},ce.pedantic={...ce.normal,strong:{start:/^__|\*\*/,middle:/^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,endAst:/\*\*(?!\*)/g,endUnd:/__(?!_)/g},em:{start:/^_|\*/,middle:/^()\*(?=\S)([\s\S]*?\S)\*(?!\*)|^_(?=\S)([\s\S]*?\S)_(?!_)/,endAst:/\*(?!\*)/g,endUnd:/_(?!_)/g},link:He(/^!?\[(label)\]\((.*?)\)/).replace("label",ce._label).getRegex(),reflink:He(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",ce._label).getRegex()},ce.gfm={...ce.normal,escape:He(ce.escape).replace("])","~|])").getRegex(),_extended_email:/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,url:/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},ce.gfm.url=He(ce.gfm.url,"i").replace("email",ce.gfm._extended_email).getRegex(),ce.breaks={...ce.gfm,br:He(ce.br).replace("{2,}","*").getRegex(),text:He(ce.gfm.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()};function uw(e){return e.replace(/---/g,"—").replace(/--/g,"–").replace(/(^|[-\u2014/(\[{"\s])'/g,"$1‘").replace(/'/g,"’").replace(/(^|[-\u2014/(\[{\u2018\s])"/g,"$1“").replace(/"/g,"”").replace(/\.{3}/g,"…")}function sd(e){let t="",n,r;const o=e.length;for(n=0;n<o;n++)r=e.charCodeAt(n),Math.random()>.5&&(r="x"+r.toString(16)),t+="&#"+r+";";return t}class jn{constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||Jn,this.options.tokenizer=this.options.tokenizer||new Ui,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const n={block:ge.normal,inline:ce.normal};this.options.pedantic?(n.block=ge.pedantic,n.inline=ce.pedantic):this.options.gfm&&(n.block=ge.gfm,this.options.breaks?n.inline=ce.breaks:n.inline=ce.gfm),this.tokenizer.rules=n}static get rules(){return{block:ge,inline:ce}}static lex(t,n){return new jn(n).lex(t)}static lexInline(t,n){return new jn(n).inlineTokens(t)}lex(t){t=t.replace(/\r\n|\r/g,`
55
55
  `),this.blockTokens(t,this.tokens);let n;for(;n=this.inlineQueue.shift();)this.inlineTokens(n.src,n.tokens);return this.tokens}blockTokens(t,n=[]){this.options.pedantic?t=t.replace(/\t/g," ").replace(/^ +$/gm,""):t=t.replace(/^( *)(\t+)/gm,(a,l,c)=>l+" ".repeat(c.length));let r,o,s,i;for(;t;)if(!(this.options.extensions&&this.options.extensions.block&&this.options.extensions.block.some(a=>(r=a.call({lexer:this},t,n))?(t=t.substring(r.raw.length),n.push(r),!0):!1))){if(r=this.tokenizer.space(t)){t=t.substring(r.raw.length),r.raw.length===1&&n.length>0?n[n.length-1].raw+=`
56
56
  `:n.push(r);continue}if(r=this.tokenizer.code(t)){t=t.substring(r.raw.length),o=n[n.length-1],o&&(o.type==="paragraph"||o.type==="text")?(o.raw+=`
57
57
  `+r.raw,o.text+=`
@@ -81,15 +81,15 @@ ${t}</blockquote>
81
81
  `}tablerow(t){return`<tr>
82
82
  ${t}</tr>
83
83
  `}tablecell(t,n){const r=n.header?"th":"td";return(n.align?`<${r} align="${n.align}">`:`<${r}>`)+t+`</${r}>
84
- `}strong(t){return`<strong>${t}</strong>`}em(t){return`<em>${t}</em>`}codespan(t){return`<code>${t}</code>`}br(){return this.options.xhtml?"<br/>":"<br>"}del(t){return`<del>${t}</del>`}link(t,n,r){if(t=td(this.options.sanitize,this.options.baseUrl,t),t===null)return r;let o='<a href="'+t+'"';return n&&(o+=' title="'+n+'"'),o+=">"+r+"</a>",o}image(t,n,r){if(t=td(this.options.sanitize,this.options.baseUrl,t),t===null)return r;let o=`<img src="${t}" alt="${r}"`;return n&&(o+=` title="${n}"`),o+=this.options.xhtml?"/>":">",o}text(t){return t}}class id{strong(t){return t}em(t){return t}codespan(t){return t}del(t){return t}html(t){return t}text(t){return t}link(t,n,r){return""+r}image(t,n,r){return""+r}br(){return""}}class ad{constructor(){this.seen={}}serialize(t){return t.toLowerCase().trim().replace(/<[!\/a-z].*?>/ig,"").replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g,"").replace(/\s/g,"-")}getNextSafeSlug(t,n){let r=t,o=0;if(this.seen.hasOwnProperty(r)){o=this.seen[t];do o++,r=t+"-"+o;while(this.seen.hasOwnProperty(r))}return n||(this.seen[t]=o,this.seen[r]=0),r}slug(t,n={}){const r=this.serialize(t);return this.getNextSafeSlug(r,n.dryrun)}}class Rn{constructor(t){this.options=t||Jn,this.options.renderer=this.options.renderer||new Hi,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new id,this.slugger=new ad}static parse(t,n){return new Rn(n).parse(t)}static parseInline(t,n){return new Rn(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,c,u,f,h,p,m,b,g,w,y,k,E,S,C;const T=t.length;for(o=0;o<T;o++){if(p=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[p.type]&&(C=this.options.extensions.renderers[p.type].call({parser:this},p),C!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(p.type))){r+=C||"";continue}switch(p.type){case"space":continue;case"hr":{r+=this.renderer.hr();continue}case"heading":{r+=this.renderer.heading(this.parseInline(p.tokens),p.depth,ed(this.parseInline(p.tokens,this.textRenderer)),this.slugger);continue}case"code":{r+=this.renderer.code(p.text,p.lang,p.escaped);continue}case"table":{for(f="",u="",a=p.header.length,s=0;s<a;s++)u+=this.renderer.tablecell(this.parseInline(p.header[s].tokens),{header:!0,align:p.align[s]});for(f+=this.renderer.tablerow(u),h="",a=p.rows.length,s=0;s<a;s++){for(c=p.rows[s],u="",l=c.length,i=0;i<l;i++)u+=this.renderer.tablecell(this.parseInline(c[i].tokens),{header:!1,align:p.align[i]});h+=this.renderer.tablerow(u)}r+=this.renderer.table(f,h);continue}case"blockquote":{h=this.parse(p.tokens),r+=this.renderer.blockquote(h);continue}case"list":{for(m=p.ordered,b=p.start,g=p.loose,a=p.items.length,h="",s=0;s<a;s++)y=p.items[s],k=y.checked,E=y.task,w="",y.task&&(S=this.renderer.checkbox(k),g?y.tokens.length>0&&y.tokens[0].type==="paragraph"?(y.tokens[0].text=S+" "+y.tokens[0].text,y.tokens[0].tokens&&y.tokens[0].tokens.length>0&&y.tokens[0].tokens[0].type==="text"&&(y.tokens[0].tokens[0].text=S+" "+y.tokens[0].tokens[0].text)):y.tokens.unshift({type:"text",text:S}):w+=S),w+=this.parse(y.tokens,g),h+=this.renderer.listitem(w,E,k);r+=this.renderer.list(h,m,b);continue}case"html":{r+=this.renderer.html(p.text);continue}case"paragraph":{r+=this.renderer.paragraph(this.parseInline(p.tokens));continue}case"text":{for(h=p.tokens?this.parseInline(p.tokens):p.text;o+1<T&&t[o+1].type==="text";)p=t[++o],h+=`
85
- `+(p.tokens?this.parseInline(p.tokens):p.text);r+=n?this.renderer.paragraph(h):h;continue}default:{const A='Token with "'+p.type+'" type was not found.';if(this.options.silent){console.error(A);return}else throw new Error(A)}}}return r}parseInline(t,n){n=n||this.renderer;let r="",o,s,i;const a=t.length;for(o=0;o<a;o++){if(s=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[s.type]&&(i=this.options.extensions.renderers[s.type].call({parser:this},s),i!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type))){r+=i||"";continue}switch(s.type){case"escape":{r+=n.text(s.text);break}case"html":{r+=n.html(s.text);break}case"link":{r+=n.link(s.href,s.title,this.parseInline(s.tokens,n));break}case"image":{r+=n.image(s.href,s.title,s.text);break}case"strong":{r+=n.strong(this.parseInline(s.tokens,n));break}case"em":{r+=n.em(this.parseInline(s.tokens,n));break}case"codespan":{r+=n.codespan(s.text);break}case"br":{r+=n.br();break}case"del":{r+=n.del(this.parseInline(s.tokens,n));break}case"text":{r+=n.text(s.text);break}default:{const l='Token with "'+s.type+'" type was not found.';if(this.options.silent){console.error(l);return}else throw new Error(l)}}}return r}}class os{constructor(t){this.options=t||Jn}preprocess(t){return t}postprocess(t){return t}}sl(os,"passThroughHooks",new Set(["preprocess","postprocess"]));function dw(e,t,n){return r=>{if(r.message+=`
86
- Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+dt(r.message+"",!0)+"</pre>";if(t)return Promise.resolve(o);if(n){n(null,o);return}return o}if(t)return Promise.reject(r);if(n){n(r);return}throw r}}function ld(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...he.defaults,...s};const i=dw(r.silent,r.async,o);if(typeof n>"u"||n===null)return i(new Error("marked(): input parameter is undefined or null"));if(typeof n!="string")return i(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(n)+", string expected"));if(lw(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(f){return i(f)}const c=function(f){let h;if(!f)try{r.walkTokens&&he.walkTokens(l,r.walkTokens),h=t(l,r),r.hooks&&(h=r.hooks.postprocess(h))}catch(p){f=p}return r.highlight=a,f?i(f):o(null,h)};if(!a||a.length<3||(delete r.highlight,!l.length))return c();let u=0;he.walkTokens(l,function(f){f.type==="code"&&(u++,setTimeout(()=>{a(f.text,f.lang,function(h,p){if(h)return c(h);p!=null&&p!==f.text&&(f.text=p,f.escaped=!0),u--,u===0&&c()})},0))}),u===0&&c();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(he.walkTokens(a,r.walkTokens)).then(()=>a):a).then(a=>t(a,r)).then(a=>r.hooks?r.hooks.postprocess(a):a).catch(i);try{r.hooks&&(n=r.hooks.preprocess(n));const a=e(n,r);r.walkTokens&&he.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function he(e,t,n){return ld(Pn.lex,Rn.parse)(e,t,n)}he.options=he.setOptions=function(e){return he.defaults={...he.defaults,...e},Yb(he.defaults),he},he.getDefaults=Xu,he.defaults=Jn,he.use=function(...e){const t=he.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=he.defaults.async||r.async||!1,n.extensions&&(n.extensions.forEach(o=>{if(!o.name)throw new Error("extension name required");if(o.renderer){const s=t.renderers[o.name];s?t.renderers[o.name]=function(...i){let a=o.renderer.apply(this,i);return a===!1&&(a=s.apply(this,i)),a}:t.renderers[o.name]=o.renderer}if(o.tokenizer){if(!o.level||o.level!=="block"&&o.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");t[o.level]?t[o.level].unshift(o.tokenizer):t[o.level]=[o.tokenizer],o.start&&(o.level==="block"?t.startBlock?t.startBlock.push(o.start):t.startBlock=[o.start]:o.level==="inline"&&(t.startInline?t.startInline.push(o.start):t.startInline=[o.start]))}o.childTokens&&(t.childTokens[o.name]=o.childTokens)}),r.extensions=t),n.renderer){const o=he.defaults.renderer||new Hi;for(const s in n.renderer){const i=o[s];o[s]=(...a)=>{let l=n.renderer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.renderer=o}if(n.tokenizer){const o=he.defaults.tokenizer||new Ui;for(const s in n.tokenizer){const i=o[s];o[s]=(...a)=>{let l=n.tokenizer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.tokenizer=o}if(n.hooks){const o=he.defaults.hooks||new os;for(const s in n.hooks){const i=o[s];os.passThroughHooks.has(s)?o[s]=a=>{if(he.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(c=>i.call(o,c));const l=n.hooks[s].call(o,a);return i.call(o,l)}:o[s]=(...a)=>{let l=n.hooks[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.hooks=o}if(n.walkTokens){const o=he.defaults.walkTokens;r.walkTokens=function(s){let i=[];return i.push(n.walkTokens.call(this,s)),o&&(i=i.concat(o.call(this,s))),i}}he.setOptions(r)})},he.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(he,r)),r.type){case"table":{for(const o of r.header)n=n.concat(he.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(he.walkTokens(s.tokens,t));break}case"list":{n=n.concat(he.walkTokens(r.items,t));break}default:he.defaults.extensions&&he.defaults.extensions.childTokens&&he.defaults.extensions.childTokens[r.type]?he.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(he.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(he.walkTokens(r.tokens,t)))}return n},he.parseInline=ld(Pn.lexInline,Rn.parseInline),he.Parser=Rn,he.parser=Rn.parse,he.Renderer=Hi,he.TextRenderer=id,he.Lexer=Pn,he.lexer=Pn.lex,he.Tokenizer=Ui,he.Slugger=ad,he.Hooks=os,he.parse=he,he.options,he.setOptions,he.use,he.walkTokens,he.parseInline,Rn.parse,Pn.lex;function so({content:e,className:t="",allowHtml:n=!1,style:r}){const o=v.useMemo(()=>{if(!e||typeof e!="string"||e.trim().length===0)return"";try{if(!n){const i=e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,"").replace(/javascript:/gi,"").replace(/on\w+\s*=/gi,"");return typeof he.parse=="function"?he.parse(i):he(i)}return typeof he.parse=="function"?he.parse(e):he(e)}catch(i){return console.error("[MarkdownContent] parse error",i),`<pre class="font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words">Error rendering markdown: ${String(i)}</pre>`}},[e,n]),s=v.useMemo(()=>{const i={color:"currentColor",...r};if(r&&r.color){const a=r.color;return{...i,"--tw-prose-body":a,"--tw-prose-headings":a,"--tw-prose-links":a,"--tw-prose-bold":a,"--tw-prose-counters":a,"--tw-prose-bullets":a,"--tw-prose-hr":a,"--tw-prose-quotes":a,"--tw-prose-quote-borders":a,"--tw-prose-captions":a,"--tw-prose-code":a,"--tw-prose-pre-code":a,"--tw-prose-pre-bg":"inherit","--tw-prose-th-borders":a,"--tw-prose-td-borders":a}}return i},[r]);return d.jsx("div",{className:fe("markdown prose prose-sm max-w-none break-words","dark:prose-invert","text-current","prose-headings:text-current prose-p:text-current prose-li:text-current prose-a:text-current prose-strong:text-current","prose-em:text-current prose-blockquote:text-current prose-table:text-current prose-td:text-current prose-th:text-current","prose-pre:font-mono prose-pre:text-xs prose-pre:bg-background/50 prose-pre:border prose-pre:rounded prose-pre:p-3 prose-pre:whitespace-pre prose-pre:overflow-x-auto","prose-code:font-mono prose-code:text-sm prose-code:bg-background/50 prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:text-current",t),style:s,dangerouslySetInnerHTML:{__html:o}})}function fw({text:e,expanded:t,onExpandedChange:n,previewLength:r,isCompact:o}){const s=Math.max(e.length-r,0),i=e.substring(0,r);return d.jsxs("div",{className:"flex flex-col gap-1",children:[d.jsx("div",{className:fe("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?d.jsx(so,{content:e,allowHtml:!1}):d.jsxs("pre",{className:fe("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:[i,"..."]})}),d.jsx(Je,{type:"button",variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",onClick:()=>n(!t),children:t?d.jsxs(d.Fragment,{children:[d.jsx(me.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):d.jsxs(d.Fragment,{children:[d.jsx(me.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function Wi({showTimestamp:e,showAgentName:t,isToolMessage:n,isInterruptMessage:r=!1,iconForeground:o,agentName:s,messageIcon:i,customHeaderClass:a,customActionsClass:l,isCompactLayout:c,showActions:u,isEditing:f,messageRole:h,onCopy:p,onEdit:m,onRegenerate:b,showCheckpointControls:g,attemptCount:w,attemptIndex:y,handleOlderAttemptSelect:k,handleNewerAttemptSelect:E,messageCreatedAt:S,copied:C}){return!e&&!t&&!n&&!r?null:d.jsxs("div",{className:fe("flex items-center justify-between mb-2 pb-2",h!=="assistant"&&"border-b border-current/10",c&&"mb-1 pb-1",o,a),children:[d.jsxs("div",{className:"flex items-center gap-2",children:[i,t&&s&&d.jsx("span",{className:fe("font-medium",c?"text-xs":"text-sm"),children:s}),r&&d.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Interrupt"})]}),d.jsxs("div",{className:"flex items-center gap-2",children:[g&&w>1&&d.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[d.jsx("button",{type:"button",className:fe("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",y<w-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{y>=w-1||k()},"aria-label":"Older attempt (back in time)",disabled:y>=w-1,children:d.jsx(me.ChevronLeft,{className:"h-3 w-3"})}),d.jsx("div",{className:"flex items-center gap-2",children:d.jsxs("span",{className:"whitespace-nowrap",children:[w-y," / ",w]})}),d.jsx("button",{type:"button",className:fe("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",y>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{y<=0||E()},"aria-label":"Newer attempt (forward in time)",disabled:y<=0,children:d.jsx(me.ChevronRight,{className:"h-3 w-3"})})]}),e&&S&&d.jsx("time",{className:fe("text-xs opacity-60",o,c&&"text-xs"),dateTime:new Date(S.endsWith("Z")||S.includes("+")?S:`${S}Z`).toISOString(),title:new Date(S.endsWith("Z")||S.includes("+")?S:`${S}Z`).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(S.endsWith("Z")||S.includes("+")?S:`${S}Z`))}),u&&!f&&d.jsxs("div",{className:fe("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",l),children:[d.jsx("div",{className:"relative",children:d.jsx(Je,{variant:"ghost",size:"sm",onClick:p,className:fe("h-6 w-6 p-0 hover:bg-foreground/10",o,c&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:d.jsx(me.Copy,{className:fe(C?"text-success":o,c?"h-3 w-3":"h-4 w-4")})})}),h==="user"&&m&&d.jsx(Je,{variant:"ghost",size:"sm",onClick:m,className:fe("h-6 w-6 p-0 hover:bg-foreground/10",o,c&&"h-5 w-5"),"aria-label":"Edit message",children:d.jsx(me.Edit,{className:fe(o,c?"h-3 w-3":"h-4 w-4")})}),h==="assistant"&&b&&d.jsx(Je,{variant:"ghost",size:"sm",onClick:b,className:fe("h-6 w-6 p-0 hover:bg-foreground/10",o,c&&"h-5 w-5"),"aria-label":"Regenerate response",children:d.jsx(me.RotateCcw,{className:fe(o,c?"h-3 w-3":"h-4 w-4")})})]})]})]})}function Vi(e){return v.useMemo(()=>({textContent:yg(e),imageParts:vg(e),fileParts:Sg(e),toolCalls:li(e),interruptParts:Cg(e),contentParts:e.content}),[e])}function cd(e,t,n){const[r,o]=v.useState(e),s=v.useRef(e),i=v.useRef(null);return v.useEffect(()=>{s.current=e;const a=()=>{o(s.current),i.current&&(clearTimeout(i.current),i.current=null)};if(!t||n<=0){a();return}return i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{a()},n),()=>{i.current&&(clearTimeout(i.current),i.current=null)}},[e,t,n]),r}const ss=v.memo(function({contentParts:t,textContent:n,imageParts:r,fileParts:o,messageRole:s,isCompactLayout:i=!1,truncateUserMessages:a=!1,userMessagePreviewLength:l=500,isUserExpanded:c=!1,setIsUserExpanded:u,uploadingFiles:f={},handleFileClick:h,isStreamingMessage:p=!1,renderStreamingMarkdown:m=!0,enableStreamingMarkdownBuffer:b=!0,streamingDebounceMs:g=0}){const w=cd(t,b&&p,g),y=v.useMemo(()=>w.filter(B=>B.type==="text"),[w]),k=v.useMemo(()=>y.map(B=>B.text??"").join(""),[y]),E=m&&p,S=v.useMemo(()=>{if(!E)return null;const B=pw(k);return{stablePart:k.slice(0,B),tailPart:k.slice(B)}},[k,E]),C=v.useMemo(()=>{if(!S)return null;const{stablePart:B,tailPart:W}=S;return!B&&!W?null:d.jsxs("div",{className:"space-y-2",children:[B?d.jsx(so,{content:B,allowHtml:!1}):null,W?d.jsx(so,{content:W,allowHtml:!1}):null]})},[S]),T=()=>!r||r.length===0?null:d.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:r.map((B,W)=>{const O=B;return d.jsx("div",{className:"relative group",children:d.jsx("img",{src:O.image_url.url,alt:"Image",loading:"lazy",onClick:()=>window.open(O.image_url.url,"_blank"),className:"h-20 w-20 object-cover rounded-md border border-border/50 cursor-pointer hover:opacity-90 transition-opacity"})},`img-${W}`)})}),A=(B,W)=>{if(B.type==="text"){const O=B.text??"",D=O.trim(),z=pr(D);return z&&s!=="tool"?d.jsx(Wb,{data:z},W):s==="user"&&a&&D.length>l&&!c?d.jsx(fw,{text:D,expanded:c,onExpandedChange:u||(()=>{}),previewLength:l,isCompact:i},W):d.jsx(so,{content:O,allowHtml:!1},W)}if(B.type==="file"){const O=B,D=O.name||"file",z=f[W];return d.jsxs("a",{href:O.url,onClick:ee=>h==null?void 0:h(ee,O,W),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
87
- dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[z?d.jsx(me.Loader,{className:"h-4 w-4 animate-spin"}):null,d.jsxs("span",{className:"truncate max-w-[180px]",children:[D,z?" (processing)":""]})]},W)}return null},N=E?k:n;if(!(N.trim().length>0||r.length>0||o.length>0)&&!p)return null;const L=E?w.filter(B=>B.type!=="text"):w;return d.jsxs("div",{className:"space-y-2",children:[E?C:null,L.filter(B=>B.type==="text"||B.type==="file").map((B,W)=>A(B,W)),T(),p&&N.trim().length>0&&d.jsx("span",{className:"inline-block w-2 h-4 ml-0.5 bg-current opacity-70 animate-pulse align-middle","aria-hidden":"true"})]})});ss.displayName="SharedContent";function hw(e){return e?!(io(e,/```/g)||io(e,/`/g)||io(e,/\*\*/g)||io(e,/__/g)||io(e,/~~/g)||/[^\\]\[[^\]]*$/.test(e)||/\[[^\]]*\]\([^)]*$/.test(e)):!0}function io(e,t){const n=e.match(t);return((n==null?void 0:n.length)??0)%2!==0}function pw(e){if(!e)return 0;for(let t=e.length;t>=0;t-=1)if(hw(e.slice(0,t)))return t;return 0}const ud=v.memo(function({isStreamingMessage:t,interruptPart:n,handleInterruptApprove:r,handleInterruptReject:o,handleInterruptAlternative:s,disableInterruptActions:i,iconForeground:a,textContent:l=""}){if(n)return d.jsx(Yu,{interruptPart:n,payload:n.value,onApprove:r||(()=>{}),onReject:o||(()=>{}),onSelectAlternative:s,disabled:i,isActive:!i});const c=l.trim().length>0;return t&&!c?d.jsx(Gb,{className:a}):null});ud.displayName="InteractiveContent";const ao=v.memo(function({role:t,header:n,content:r,actions:o,status:s,isCompactLayout:i=!1,variant:a="default",customStyles:l={}}){const c=t==="user",u=t==="system",f=fe("flex w-full group py-3 md:py-4 px-2 md:px-0",c?"justify-end":"justify-start",l.container),h=fe("relative flex flex-col rounded-2xl transition-all duration-200",a==="minimal"?"bg-transparent border border-border/50 shadow-none":a==="accent"?"ring-2 ring-primary/20":"",c?"bg-[hsl(var(--chat-bubble-user-bg,210_40%_96%))] text-[hsl(var(--chat-bubble-user-text,222_47%_11%))] shadow-sm border border-border/40 w-full max-w-full":"bg-[hsl(var(--chat-bubble-ai-bg))] text-[hsl(var(--chat-bubble-ai-text))] w-full max-w-full",u&&"bg-transparent border-none shadow-none text-muted-foreground max-w-full opacity-80",i?"px-3 py-2":"px-4 py-3 md:px-5 md:py-4",l.bubble),p=fe("text-sm leading-relaxed break-words",l.content),m=fe("absolute top-0 opacity-0 group-hover:opacity-100 transition-opacity flex items-center gap-1",c?"-left-10":"-right-10",i&&"hidden",l.actions);return d.jsx("div",{className:f,children:d.jsxs("div",{className:h,children:[n&&d.jsx("div",{className:fe("mb-2 w-full",l.header),children:n}),s&&d.jsx("div",{className:"mb-2 w-full",children:s}),d.jsx("div",{className:p,children:r}),o&&d.jsx("div",{className:m,children:o})]})})});ao.displayName="MessageBubble";const Ki=v.memo(function({message:t,messageIndex:n,isStreamingMessage:r=!1,streamingDebounceMs:o,renderStreamingMarkdown:s=!0,enableStreamingMarkdownBuffer:i=!0,layoutSize:a,showToolMessages:l,toolConfig:c,customStyles:u,onRegenerate:f,onCopy:h,getInterruptOptions:p,renderArtifactsInline:m,showToolProgress:b,showToolResultsInline:g,isEmbedded:w=!1,precedingMessages:y=[],showHeader:k,hideToolProgress:E=!1,forceAgentName:S}){var jt,rt,tt,it,_t;const{layoutSize:C,toolConfig:T,renderArtifactsInline:A,streamingDebounceMs:N,onRegenerate:j,getInterruptOptions:L,showToolMessages:B,messageCustomStyles:W}=zo(),O=c??T,D=a??C,z=m??A,ee=o??N??0,H=f??j,V=p??L,Y=l??B??!0,q=b??Y,M=g??Y,P={...(W==null?void 0:W(t))||{},...u},$=h;console.debug("[AssistantMessageComponent] Render",{id:t.id,role:t.role,name:t.name,contentParts:t.content,precedingCount:y.length,isStreamingMessage:r,textContentLength:(tt=(rt=(jt=t.content)==null?void 0:jt[0])==null?void 0:rt.text)==null?void 0:tt.length});const[R,G]=v.useState(!1),{respondToInterrupt:te}=qr(),[F,X]=v.useState(!1),re=D==="phone"||D==="half-screen",{contentParts:ue,textContent:le,imageParts:Se,fileParts:Me,toolCalls:Ie,interruptParts:Ke}=Vi(t),He=Ke[0]||null,Fe=v.useCallback(async()=>{const Ae=le;try{await navigator.clipboard.writeText(Ae),G(!0),setTimeout(()=>G(!1),2e3),$==null||$(Ae)}catch(Ye){console.error("Failed to copy assistant message:",Ye)}},[le,$]),ze=v.useCallback(async(Ae,Ye)=>{if(!(!He||!uc(He.id))){X(!0);try{const $t=V==null?void 0:V(t);await te(Ae,Ye,$t)}finally{X(!1)}}},[He,t,V,te]),It=v.useCallback(()=>{H==null||H(n)},[H,n]),At=!w&&(k??((it=O==null?void 0:O.getShowHeader)==null?void 0:it.call(O,t))??!0),wt=!E&&t.role==="assistant"&&q?d.jsx(Hu,{messages:[...y,t],isStreaming:r,toolConfig:O}):null,yt=At&&d.jsx(Wi,{showTimestamp:!0,showAgentName:!0,isToolMessage:t.role==="tool",isInterruptMessage:!1,iconForeground:"text-[hsl(var(--chat-bubble-ai-text))]",agentName:S||t.name||t.model||"Agent",messageIcon:t.role==="tool"?d.jsx(me.Wrench,{className:"h-4 w-4 opacity-60"}):d.jsx(me.Bot,{className:"h-4 w-4 opacity-60"}),isCompactLayout:re,showActions:!0,isEditing:!1,messageRole:t.role,onCopy:Fe,onEdit:void 0,onRegenerate:It,showCheckpointControls:!1,attemptCount:1,attemptIndex:0,handleOlderAttemptSelect:()=>{},handleNewerAttemptSelect:()=>{},messageCreatedAt:t.createdAt,copied:R,customActionsClass:P.actions}),ht=t.role==="tool",st=ht?d.jsx(es,{message:t,viewMode:"expanded",isStreaming:r,toolConfig:O,expandable:(_t=O==null?void 0:O.getToolExpandable)==null?void 0:_t.call(O,t)}):null,Nt=d.jsxs("div",{className:"space-y-4",children:[y.map(Ae=>{var Ye;return d.jsx("div",{className:"space-y-2 pb-4 border-b border-border/20 last:border-0 last:pb-0",children:d.jsx(es,{message:Ae,viewMode:"expanded",isStreaming:!1,toolConfig:O,expandable:(Ye=O==null?void 0:O.getToolExpandable)==null?void 0:Ye.call(O,Ae)})},Ae.id)}),ht?st:d.jsxs(d.Fragment,{children:[d.jsx(ss,{contentParts:ue,textContent:le,imageParts:Se,fileParts:Me,messageRole:t.role,isCompactLayout:re,isStreamingMessage:r,renderStreamingMarkdown:s,enableStreamingMarkdownBuffer:i,streamingDebounceMs:ee}),t.role==="assistant"&&M&&Ie.map(Ae=>d.jsx(es,{message:{...t,role:"tool",name:Ae.name,toolCallId:Ae.id,artifact:Ae.artifact,content:[{type:"text",text:JSON.stringify(Ae.args)}]},viewMode:"expanded",isStreaming:r,toolConfig:O},Ae.id)),d.jsx(ud,{message:t,isStreamingMessage:r,toolConfig:O,interruptPart:He,handleInterruptApprove:()=>ze(!0),handleInterruptReject:()=>ze(!1),handleInterruptAlternative:(Ae,Ye)=>ze(!0,{alternativeId:Ye==null?void 0:Ye.id}),disableInterruptActions:F,renderArtifactsInline:z,iconForeground:"text-[hsl(var(--chat-bubble-ai-text))]",textContent:le})]})]});return w?Nt:d.jsx(ao,{role:t.role,header:yt,status:wt,content:Nt,isCompactLayout:re,customStyles:P})});Ki.displayName="AssistantMessageComponent";const qi=v.memo(function({message:t,layoutSize:n="desktop",truncateUserMessages:r=!0,userMessagePreviewLength:o=500,enableMessageEditing:s=!0,onEdit:i,checkpointIndex:a,onSelectCheckpoint:l,customStyles:c={}}){const[u,f]=v.useState(!1),[h,p]=v.useState(!1),m=n==="phone"||n==="half-screen",{contentParts:b,textContent:g,imageParts:w,fileParts:y}=Vi(t),k=v.useCallback(async()=>{try{await navigator.clipboard.writeText(g),f(!0),setTimeout(()=>f(!1),2e3)}catch(W){console.error("Failed to copy user message:",W)}},[g]),E=v.useCallback(()=>{if(!i||!t.id)return;const W={checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};i(t.id,g,W)},[i,t,g]),{attemptCount:S,attemptIndex:C,attempts:T}=v.useMemo(()=>a?Jg(t.id,t.checkpointId,a):{attemptCount:1,attemptIndex:0,attempts:[]},[t.id,t.checkpointId,a]),A=S>1&&!!l,N=v.useCallback(()=>{const W=T[C+1];W&&l&&l(W.id,void 0,!!W.isLatestAttempt)},[T,C,l]),j=v.useCallback(()=>{const W=T[C-1];W&&l&&l(W.id,void 0,!!W.isLatestAttempt)},[T,C,l]),L=d.jsx(Wi,{showTimestamp:!0,showAgentName:!0,isToolMessage:!1,iconForeground:"text-[hsl(var(--chat-bubble-user-text))]",agentName:null,messageIcon:d.jsx(me.User,{className:fe(m?"h-3 w-3":"h-4 w-4","opacity-60")}),isCompactLayout:m,showActions:!0,isEditing:!1,messageRole:"user",onCopy:k,onEdit:s?E:void 0,showCheckpointControls:A,attemptCount:S,attemptIndex:C,handleOlderAttemptSelect:N,handleNewerAttemptSelect:j,messageCreatedAt:t.createdAt,copied:u,customHeaderClass:c.header,customActionsClass:c.actions}),B=d.jsx(ss,{contentParts:b,textContent:g,imageParts:w,fileParts:y,messageRole:"user",truncateUserMessages:r,userMessagePreviewLength:o,isUserExpanded:h,setIsUserExpanded:p,isCompactLayout:m,handleFileClick:()=>{},uploadingFiles:{}});return d.jsx(ao,{role:"user",header:L,content:B,isCompactLayout:m,customStyles:c})});qi.displayName="UserMessageComponent";const Gi=v.memo(function({message:t,layoutSize:n="desktop",customStyles:r={}}){const o=n==="phone"||n==="half-screen",{contentParts:s,textContent:i,imageParts:a,fileParts:l}=Vi(t),c=d.jsxs("div",{className:"flex items-center gap-2 mb-1 opacity-50",children:[d.jsx(me.Info,{className:fe(o?"h-3 w-3":"h-4 w-4")}),d.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wider",children:"System Message"})]}),u=d.jsx(ss,{contentParts:s,textContent:i,imageParts:a,fileParts:l,messageRole:"system",isCompactLayout:o});return d.jsx(ao,{role:"system",header:c,content:u,isCompactLayout:o,customStyles:r})});Gi.displayName="SystemMessageComponent";const is=v.forwardRef(({messages:e=[],isStreaming:t,onStartReached:n,className:r,style:o,emptyMessage:s,onScrollAway:i,onAtBottom:a,renderMessage:l},c)=>{const{followNewMessages:u,checkpointIndex:f}=zo(),h=!!f,p=v.useRef(null),m=v.useRef(null),b=v.useRef(!1),g=v.useRef(!1),w=v.useCallback(j=>{i&&i(!j),a&&a(j)},[i,a]),y=v.useMemo(()=>{if(n)return async()=>{if(!b.current){b.current=!0;try{await n()}finally{b.current=!1}}}},[n]),k=v.useMemo(()=>!u||h?!1:"auto",[u,h]),E=e.length===0&&s,S=["flex flex-1 flex-col min-h-0 min-w-0",r].filter(Boolean).join(" "),C=()=>E?d.jsx("div",{className:"h-full w-full",children:s}):d.jsx("div",{className:"flex h-full items-center justify-center py-8 text-center text-muted-foreground",children:"No messages yet. Start a conversation!"}),T=e.length,A=T>0;v.useEffect(()=>{var j,L;if(T===0){g.current=!1;return}if(!g.current)if(g.current=!0,p.current&&e.length>0){const B=e.length-1;(L=(j=p.current).scrollToIndex)==null||L.call(j,{index:B,align:"end",behavior:"auto"})}else m.current&&(m.current.scrollTop=m.current.scrollHeight)},[T,e.length]),v.useImperativeHandle(c,()=>({scrollToLatest:()=>{var j,L;if(p.current&&e.length>0){const B=e.length-1;(L=(j=p.current).scrollToIndex)==null||L.call(j,{index:B,align:"end",behavior:"auto"})}else m.current&&(m.current.scrollTop=m.current.scrollHeight)},scrollToTop:()=>{var j,L;p.current&&e.length>0?(L=(j=p.current).scrollToIndex)==null||L.call(j,{index:0,align:"start",behavior:"auto"}):m.current&&(m.current.scrollTop=0)}}),[e]);const N=v.useCallback((j,L)=>j.role==="user"?d.jsx(qi,{message:j,messageIndex:L}):j.role==="system"?d.jsx(Gi,{message:j}):d.jsx(Ki,{message:j,messageIndex:L,isStreamingMessage:t&&L===e.length-1}),[t,e.length]);return d.jsx("div",{className:S,style:o,children:d.jsx("div",{className:"relative flex-1 min-h-0 min-w-0",children:A?d.jsx(Ib,{ref:j=>p.current=j,scrollerRef:j=>m.current=j instanceof HTMLDivElement?j:null,data:e,followOutput:k,initialTopMostItemIndex:e.length>0?e.length-1:0,overscan:200,atBottomThreshold:50,startReached:()=>{y&&y()},atBottomStateChange:w,style:{height:"100%",width:"100%",overscrollBehavior:"contain"},computeItemKey:(j,L)=>L.id||j,itemContent:(j,L)=>l?l(L,j):N(L,j)}):C()})})});is.displayName="MessageList";function ye(e,t,{checkForDefaultPrevented:n=!0}={}){return function(o){if(e==null||e(o),n===!1||!o.defaultPrevented)return t==null?void 0:t(o)}}function dd(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function On(...e){return t=>{let n=!1;const r=e.map(o=>{const s=dd(o,t);return!n&&typeof s=="function"&&(n=!0),s});if(n)return()=>{for(let o=0;o<r.length;o++){const s=r[o];typeof s=="function"?s():dd(e[o],null)}}}}function Ge(...e){return x.useCallback(On(...e),e)}function mw(e,t){const n=x.createContext(t),r=s=>{const{children:i,...a}=s,l=x.useMemo(()=>a,Object.values(a));return d.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=x.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function Mn(e,t=[]){let n=[];function r(s,i){const a=x.createContext(i),l=n.length;n=[...n,i];const c=f=>{var w;const{scope:h,children:p,...m}=f,b=((w=h==null?void 0:h[e])==null?void 0:w[l])||a,g=x.useMemo(()=>m,Object.values(m));return d.jsx(b.Provider,{value:g,children:p})};c.displayName=s+"Provider";function u(f,h){var b;const p=((b=h==null?void 0:h[e])==null?void 0:b[l])||a,m=x.useContext(p);if(m)return m;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[c,u]}const o=()=>{const s=n.map(i=>x.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return x.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,gw(o,...t)]}function gw(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const f=l(s)[`__scope${c}`];return{...a,...f}},{});return x.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var rn=globalThis!=null&&globalThis.document?x.useLayoutEffect:()=>{},xw=x[" useInsertionEffect ".trim().toString()]||rn;function as({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=bw({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const u=x.useRef(e!==void 0);x.useEffect(()=>{const f=u.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"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=a},[a,r])}const c=x.useCallback(u=>{var f;if(a){const h=ww(u)?u(e):u;h!==e&&((f=i.current)==null||f.call(i,h))}else s(u)},[a,e,s,i]);return[l,c]}function bw({defaultProp:e,onChange:t}){const[n,r]=x.useState(e),o=x.useRef(n),s=x.useRef(t);return xw(()=>{s.current=t},[t]),x.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function ww(e){return typeof e=="function"}var yw=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],je=yw.reduce((e,t)=>{const n=cr.createSlot(`Primitive.${t}`),r=x.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),d.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function fd(e,t){e&&al.flushSync(()=>e.dispatchEvent(t))}function hd(e){const t=e+"CollectionProvider",[n,r]=Mn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=b=>{const{scope:g,children:w}=b,y=v.useRef(null),k=v.useRef(new Map).current;return d.jsx(o,{scope:g,itemMap:k,collectionRef:y,children:w})};i.displayName=t;const a=e+"CollectionSlot",l=cr.createSlot(a),c=v.forwardRef((b,g)=>{const{scope:w,children:y}=b,k=s(a,w),E=Ge(g,k.collectionRef);return d.jsx(l,{ref:E,children:y})});c.displayName=a;const u=e+"CollectionItemSlot",f="data-radix-collection-item",h=cr.createSlot(u),p=v.forwardRef((b,g)=>{const{scope:w,children:y,...k}=b,E=v.useRef(null),S=Ge(g,E),C=s(u,w);return v.useEffect(()=>(C.itemMap.set(E,{ref:E,...k}),()=>void C.itemMap.delete(E))),d.jsx(h,{[f]:"",ref:S,children:y})});p.displayName=u;function m(b){const g=s(e+"CollectionConsumer",b);return v.useCallback(()=>{const y=g.collectionRef.current;if(!y)return[];const k=Array.from(y.querySelectorAll(`[${f}]`));return Array.from(g.itemMap.values()).sort((C,T)=>k.indexOf(C.ref.current)-k.indexOf(T.ref.current))},[g.collectionRef,g.itemMap])}return[{Provider:i,Slot:c,ItemSlot:p},m,r]}var vw=x.createContext(void 0);function Yi(e){const t=x.useContext(vw);return e||t||"ltr"}function ft(e){const t=x.useRef(e);return x.useEffect(()=>{t.current=e}),x.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function Sw(e,t=globalThis==null?void 0:globalThis.document){const n=ft(e);x.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var Cw="DismissableLayer",Xi="dismissableLayer.update",Tw="dismissableLayer.pointerDownOutside",kw="dismissableLayer.focusOutside",pd,md=x.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Ji=x.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=x.useContext(md),[u,f]=x.useState(null),h=(u==null?void 0:u.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=x.useState({}),m=Ge(t,T=>f(T)),b=Array.from(c.layers),[g]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),w=b.indexOf(g),y=u?b.indexOf(u):-1,k=c.layersWithOutsidePointerEventsDisabled.size>0,E=y>=w,S=Aw(T=>{const A=T.target,N=[...c.branches].some(j=>j.contains(A));!E||N||(o==null||o(T),i==null||i(T),T.defaultPrevented||a==null||a())},h),C=Nw(T=>{const A=T.target;[...c.branches].some(j=>j.contains(A))||(s==null||s(T),i==null||i(T),T.defaultPrevented||a==null||a())},h);return Sw(T=>{y===c.layers.size-1&&(r==null||r(T),!T.defaultPrevented&&a&&(T.preventDefault(),a()))},h),x.useEffect(()=>{if(u)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(pd=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(u)),c.layers.add(u),gd(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=pd)}},[u,h,n,c]),x.useEffect(()=>()=>{u&&(c.layers.delete(u),c.layersWithOutsidePointerEventsDisabled.delete(u),gd())},[u,c]),x.useEffect(()=>{const T=()=>p({});return document.addEventListener(Xi,T),()=>document.removeEventListener(Xi,T)},[]),d.jsx(je.div,{...l,ref:m,style:{pointerEvents:k?E?"auto":"none":void 0,...e.style},onFocusCapture:ye(e.onFocusCapture,C.onFocusCapture),onBlurCapture:ye(e.onBlurCapture,C.onBlurCapture),onPointerDownCapture:ye(e.onPointerDownCapture,S.onPointerDownCapture)})});Ji.displayName=Cw;var Ew="DismissableLayerBranch",Iw=x.forwardRef((e,t)=>{const n=x.useContext(md),r=x.useRef(null),o=Ge(t,r);return x.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),d.jsx(je.div,{...e,ref:o})});Iw.displayName=Ew;function Aw(e,t=globalThis==null?void 0:globalThis.document){const n=ft(e),r=x.useRef(!1),o=x.useRef(()=>{});return x.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){xd(Tw,n,c,{discrete:!0})};const c={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function Nw(e,t=globalThis==null?void 0:globalThis.document){const n=ft(e),r=x.useRef(!1);return x.useEffect(()=>{const o=s=>{s.target&&!r.current&&xd(kw,n,{originalEvent:s},{discrete:!1})};return t.addEventListener("focusin",o),()=>t.removeEventListener("focusin",o)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function gd(){const e=new CustomEvent(Xi);document.dispatchEvent(e)}function xd(e,t,n,{discrete:r}){const o=n.originalEvent.target,s=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&o.addEventListener(e,t,{once:!0}),r?fd(o,s):o.dispatchEvent(s)}var Zi=0;function bd(){x.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??wd()),document.body.insertAdjacentElement("beforeend",e[1]??wd()),Zi++,()=>{Zi===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),Zi--}},[])}function wd(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}var Qi="focusScope.autoFocusOnMount",ea="focusScope.autoFocusOnUnmount",yd={bubbles:!1,cancelable:!0},jw="FocusScope",ta=x.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=x.useState(null),c=ft(o),u=ft(s),f=x.useRef(null),h=Ge(t,b=>l(b)),p=x.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;x.useEffect(()=>{if(r){let b=function(k){if(p.paused||!a)return;const E=k.target;a.contains(E)?f.current=E:Dn(f.current,{select:!0})},g=function(k){if(p.paused||!a)return;const E=k.relatedTarget;E!==null&&(a.contains(E)||Dn(f.current,{select:!0}))},w=function(k){if(document.activeElement===document.body)for(const S of k)S.removedNodes.length>0&&Dn(a)};document.addEventListener("focusin",b),document.addEventListener("focusout",g);const y=new MutationObserver(w);return a&&y.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",b),document.removeEventListener("focusout",g),y.disconnect()}}},[r,a,p.paused]),x.useEffect(()=>{if(a){Cd.add(p);const b=document.activeElement;if(!a.contains(b)){const w=new CustomEvent(Qi,yd);a.addEventListener(Qi,c),a.dispatchEvent(w),w.defaultPrevented||(_w(Dw(vd(a)),{select:!0}),document.activeElement===b&&Dn(a))}return()=>{a.removeEventListener(Qi,c),setTimeout(()=>{const w=new CustomEvent(ea,yd);a.addEventListener(ea,u),a.dispatchEvent(w),w.defaultPrevented||Dn(b??document.body,{select:!0}),a.removeEventListener(ea,u),Cd.remove(p)},0)}}},[a,c,u,p]);const m=x.useCallback(b=>{if(!n&&!r||p.paused)return;const g=b.key==="Tab"&&!b.altKey&&!b.ctrlKey&&!b.metaKey,w=document.activeElement;if(g&&w){const y=b.currentTarget,[k,E]=Pw(y);k&&E?!b.shiftKey&&w===E?(b.preventDefault(),n&&Dn(k,{select:!0})):b.shiftKey&&w===k&&(b.preventDefault(),n&&Dn(E,{select:!0})):w===y&&b.preventDefault()}},[n,r,p.paused]);return d.jsx(je.div,{tabIndex:-1,...i,ref:h,onKeyDown:m})});ta.displayName=jw;function _w(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Dn(r,{select:t}),document.activeElement!==n)return}function Pw(e){const t=vd(e),n=Sd(t,e),r=Sd(t.reverse(),e);return[n,r]}function vd(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function Sd(e,t){for(const n of e)if(!Rw(n,{upTo:t}))return n}function Rw(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function Ow(e){return e instanceof HTMLInputElement&&"select"in e}function Dn(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Ow(e)&&t&&e.select()}}var Cd=Mw();function Mw(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Td(e,t),e.unshift(t)},remove(t){var n;e=Td(e,t),(n=e[0])==null||n.resume()}}}function Td(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Dw(e){return e.filter(t=>t.tagName!=="A")}var Lw=x[" useId ".trim().toString()]||(()=>{}),$w=0;function Ot(e){const[t,n]=x.useState(Lw());return rn(()=>{n(r=>r??String($w++))},[e]),e||(t?`radix-${t}`:"")}const Fw=["top","right","bottom","left"],Ln=Math.min,Mt=Math.max,ls=Math.round,cs=Math.floor,on=e=>({x:e,y:e}),zw={left:"right",right:"left",bottom:"top",top:"bottom"},Bw={start:"end",end:"start"};function na(e,t,n){return Mt(e,Ln(t,n))}function gn(e,t){return typeof e=="function"?e(t):e}function xn(e){return e.split("-")[0]}function Sr(e){return e.split("-")[1]}function ra(e){return e==="x"?"y":"x"}function oa(e){return e==="y"?"height":"width"}const Uw=new Set(["top","bottom"]);function sn(e){return Uw.has(xn(e))?"y":"x"}function sa(e){return ra(sn(e))}function Hw(e,t,n){n===void 0&&(n=!1);const r=Sr(e),o=sa(e),s=oa(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=us(i)),[i,us(i)]}function Ww(e){const t=us(e);return[ia(e),t,ia(t)]}function ia(e){return e.replace(/start|end/g,t=>Bw[t])}const kd=["left","right"],Ed=["right","left"],Vw=["top","bottom"],Kw=["bottom","top"];function qw(e,t,n){switch(e){case"top":case"bottom":return n?t?Ed:kd:t?kd:Ed;case"left":case"right":return t?Vw:Kw;default:return[]}}function Gw(e,t,n,r){const o=Sr(e);let s=qw(xn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(ia)))),s}function us(e){return e.replace(/left|right|bottom|top/g,t=>zw[t])}function Yw(e){return{top:0,right:0,bottom:0,left:0,...e}}function Id(e){return typeof e!="number"?Yw(e):{top:e,right:e,bottom:e,left:e}}function ds(e){const{x:t,y:n,width:r,height:o}=e;return{width:r,height:o,top:n,left:t,right:t+r,bottom:n+o,x:t,y:n}}function Ad(e,t,n){let{reference:r,floating:o}=e;const s=sn(t),i=sa(t),a=oa(i),l=xn(t),c=s==="y",u=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,h=r[a]/2-o[a]/2;let p;switch(l){case"top":p={x:u,y:r.y-o.height};break;case"bottom":p={x:u,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:f};break;case"left":p={x:r.x-o.width,y:f};break;default:p={x:r.x,y:r.y}}switch(Sr(t)){case"start":p[i]-=h*(n&&c?-1:1);break;case"end":p[i]+=h*(n&&c?-1:1);break}return p}const Xw=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let c=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:u,y:f}=Ad(c,r,l),h=r,p={},m=0;for(let b=0;b<a.length;b++){const{name:g,fn:w}=a[b],{x:y,y:k,data:E,reset:S}=await w({x:u,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:c,platform:i,elements:{reference:e,floating:t}});u=y??u,f=k??f,p={...p,[g]:{...p[g],...E}},S&&m<=50&&(m++,typeof S=="object"&&(S.placement&&(h=S.placement),S.rects&&(c=S.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):S.rects),{x:u,y:f}=Ad(c,h,l)),b=-1)}return{x:u,y:f,placement:h,strategy:o,middlewareData:p}};async function lo(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:c="clippingAncestors",rootBoundary:u="viewport",elementContext:f="floating",altBoundary:h=!1,padding:p=0}=gn(t,e),m=Id(p),g=a[h?f==="floating"?"reference":"floating":f],w=ds(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(g)))==null||n?g:g.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:u,strategy:l})),y=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,k=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),E=await(s.isElement==null?void 0:s.isElement(k))?await(s.getScale==null?void 0:s.getScale(k))||{x:1,y:1}:{x:1,y:1},S=ds(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:y,offsetParent:k,strategy:l}):y);return{top:(w.top-S.top+m.top)/E.y,bottom:(S.bottom-w.bottom+m.bottom)/E.y,left:(w.left-S.left+m.left)/E.x,right:(S.right-w.right+m.right)/E.x}}const Jw=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:c,padding:u=0}=gn(e,t)||{};if(c==null)return{};const f=Id(u),h={x:n,y:r},p=sa(o),m=oa(p),b=await i.getDimensions(c),g=p==="y",w=g?"top":"left",y=g?"bottom":"right",k=g?"clientHeight":"clientWidth",E=s.reference[m]+s.reference[p]-h[p]-s.floating[m],S=h[p]-s.reference[p],C=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let T=C?C[k]:0;(!T||!await(i.isElement==null?void 0:i.isElement(C)))&&(T=a.floating[k]||s.floating[m]);const A=E/2-S/2,N=T/2-b[m]/2-1,j=Ln(f[w],N),L=Ln(f[y],N),B=j,W=T-b[m]-L,O=T/2-b[m]/2+A,D=na(B,O,W),z=!l.arrow&&Sr(o)!=null&&O!==D&&s.reference[m]/2-(O<B?j:L)-b[m]/2<0,ee=z?O<B?O-B:O-W:0;return{[p]:h[p]+ee,data:{[p]:D,centerOffset:O-D-ee,...z&&{alignmentOffset:ee}},reset:z}}}),Zw=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:c}=t,{mainAxis:u=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:b=!0,...g}=gn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const w=xn(o),y=sn(a),k=xn(a)===a,E=await(l.isRTL==null?void 0:l.isRTL(c.floating)),S=h||(k||!b?[us(a)]:Ww(a)),C=m!=="none";!h&&C&&S.push(...Gw(a,b,m,E));const T=[a,...S],A=await lo(t,g),N=[];let j=((r=s.flip)==null?void 0:r.overflows)||[];if(u&&N.push(A[w]),f){const O=Hw(o,i,E);N.push(A[O[0]],A[O[1]])}if(j=[...j,{placement:o,overflows:N}],!N.every(O=>O<=0)){var L,B;const O=(((L=s.flip)==null?void 0:L.index)||0)+1,D=T[O];if(D&&(!(f==="alignment"?y!==sn(D):!1)||j.every(H=>sn(H.placement)===y?H.overflows[0]>0:!0)))return{data:{index:O,overflows:j},reset:{placement:D}};let z=(B=j.filter(ee=>ee.overflows[0]<=0).sort((ee,H)=>ee.overflows[1]-H.overflows[1])[0])==null?void 0:B.placement;if(!z)switch(p){case"bestFit":{var W;const ee=(W=j.filter(H=>{if(C){const V=sn(H.placement);return V===y||V==="y"}return!0}).map(H=>[H.placement,H.overflows.filter(V=>V>0).reduce((V,Y)=>V+Y,0)]).sort((H,V)=>H[1]-V[1])[0])==null?void 0:W[0];ee&&(z=ee);break}case"initialPlacement":z=a;break}if(o!==z)return{reset:{placement:z}}}return{}}}};function Nd(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function jd(e){return Fw.some(t=>e[t]>=0)}const Qw=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=gn(e,t);switch(r){case"referenceHidden":{const s=await lo(t,{...o,elementContext:"reference"}),i=Nd(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:jd(i)}}}case"escaped":{const s=await lo(t,{...o,altBoundary:!0}),i=Nd(s,n.floating);return{data:{escapedOffsets:i,escaped:jd(i)}}}default:return{}}}}},_d=new Set(["left","top"]);async function ey(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=xn(n),a=Sr(n),l=sn(n)==="y",c=_d.has(i)?-1:1,u=s&&l?-1:1,f=gn(t,e);let{mainAxis:h,crossAxis:p,alignmentAxis:m}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof m=="number"&&(p=a==="end"?m*-1:m),l?{x:p*u,y:h*c}:{x:h*c,y:p*u}}const ty=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var n,r;const{x:o,y:s,placement:i,middlewareData:a}=t,l=await ey(t,e);return i===((n=a.offset)==null?void 0:n.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:o+l.x,y:s+l.y,data:{...l,placement:i}}}}},ny=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:g=>{let{x:w,y}=g;return{x:w,y}}},...l}=gn(e,t),c={x:n,y:r},u=await lo(t,l),f=sn(xn(o)),h=ra(f);let p=c[h],m=c[f];if(s){const g=h==="y"?"top":"left",w=h==="y"?"bottom":"right",y=p+u[g],k=p-u[w];p=na(y,p,k)}if(i){const g=f==="y"?"top":"left",w=f==="y"?"bottom":"right",y=m+u[g],k=m-u[w];m=na(y,m,k)}const b=a.fn({...t,[h]:p,[f]:m});return{...b,data:{x:b.x-n,y:b.y-r,enabled:{[h]:s,[f]:i}}}}}},ry=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=gn(e,t),u={x:n,y:r},f=sn(o),h=ra(f);let p=u[h],m=u[f];const b=gn(a,t),g=typeof b=="number"?{mainAxis:b,crossAxis:0}:{mainAxis:0,crossAxis:0,...b};if(l){const k=h==="y"?"height":"width",E=s.reference[h]-s.floating[k]+g.mainAxis,S=s.reference[h]+s.reference[k]-g.mainAxis;p<E?p=E:p>S&&(p=S)}if(c){var w,y;const k=h==="y"?"width":"height",E=_d.has(xn(o)),S=s.reference[f]-s.floating[k]+(E&&((w=i.offset)==null?void 0:w[f])||0)+(E?0:g.crossAxis),C=s.reference[f]+s.reference[k]+(E?0:((y=i.offset)==null?void 0:y[f])||0)-(E?g.crossAxis:0);m<S?m=S:m>C&&(m=C)}return{[h]:p,[f]:m}}}},oy=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:o,rects:s,platform:i,elements:a}=t,{apply:l=()=>{},...c}=gn(e,t),u=await lo(t,c),f=xn(o),h=Sr(o),p=sn(o)==="y",{width:m,height:b}=s.floating;let g,w;f==="top"||f==="bottom"?(g=f,w=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(w=f,g=h==="end"?"top":"bottom");const y=b-u.top-u.bottom,k=m-u.left-u.right,E=Ln(b-u[g],y),S=Ln(m-u[w],k),C=!t.middlewareData.shift;let T=E,A=S;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(A=k),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(T=y),C&&!h){const j=Mt(u.left,0),L=Mt(u.right,0),B=Mt(u.top,0),W=Mt(u.bottom,0);p?A=m-2*(j!==0||L!==0?j+L:Mt(u.left,u.right)):T=b-2*(B!==0||W!==0?B+W:Mt(u.top,u.bottom))}await l({...t,availableWidth:A,availableHeight:T});const N=await i.getDimensions(a.floating);return m!==N.width||b!==N.height?{reset:{rects:!0}}:{}}}};function fs(){return typeof window<"u"}function Cr(e){return Pd(e)?(e.nodeName||"").toLowerCase():"#document"}function Dt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function an(e){var t;return(t=(Pd(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function Pd(e){return fs()?e instanceof Node||e instanceof Dt(e).Node:!1}function Xt(e){return fs()?e instanceof Element||e instanceof Dt(e).Element:!1}function ln(e){return fs()?e instanceof HTMLElement||e instanceof Dt(e).HTMLElement:!1}function Rd(e){return!fs()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Dt(e).ShadowRoot}const sy=new Set(["inline","contents"]);function co(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=Jt(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!sy.has(o)}const iy=new Set(["table","td","th"]);function ay(e){return iy.has(Cr(e))}const ly=[":popover-open",":modal"];function hs(e){return ly.some(t=>{try{return e.matches(t)}catch{return!1}})}const cy=["transform","translate","scale","rotate","perspective"],uy=["transform","translate","scale","rotate","perspective","filter"],dy=["paint","layout","strict","content"];function aa(e){const t=la(),n=Xt(e)?Jt(e):e;return cy.some(r=>n[r]?n[r]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!t&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!t&&(n.filter?n.filter!=="none":!1)||uy.some(r=>(n.willChange||"").includes(r))||dy.some(r=>(n.contain||"").includes(r))}function fy(e){let t=$n(e);for(;ln(t)&&!Tr(t);){if(aa(t))return t;if(hs(t))return null;t=$n(t)}return null}function la(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const hy=new Set(["html","body","#document"]);function Tr(e){return hy.has(Cr(e))}function Jt(e){return Dt(e).getComputedStyle(e)}function ps(e){return Xt(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function $n(e){if(Cr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Rd(e)&&e.host||an(e);return Rd(t)?t.host:t}function Od(e){const t=$n(e);return Tr(t)?e.ownerDocument?e.ownerDocument.body:e.body:ln(t)&&co(t)?t:Od(t)}function uo(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Od(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Dt(o);if(s){const a=ca(i);return t.concat(i,i.visualViewport||[],co(o)?o:[],a&&n?uo(a):[])}return t.concat(o,uo(o,[],n))}function ca(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Md(e){const t=Jt(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=ln(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=ls(n)!==s||ls(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function ua(e){return Xt(e)?e:e.contextElement}function kr(e){const t=ua(e);if(!ln(t))return on(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Md(t);let i=(s?ls(n.width):n.width)/r,a=(s?ls(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const py=on(0);function Dd(e){const t=Dt(e);return!la()||!t.visualViewport?py:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function my(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Dt(e)?!1:t}function Zn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=ua(e);let i=on(1);t&&(r?Xt(r)&&(i=kr(r)):i=kr(e));const a=my(s,n,r)?Dd(s):on(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,u=o.width/i.x,f=o.height/i.y;if(s){const h=Dt(s),p=r&&Xt(r)?Dt(r):r;let m=h,b=ca(m);for(;b&&r&&p!==m;){const g=kr(b),w=b.getBoundingClientRect(),y=Jt(b),k=w.left+(b.clientLeft+parseFloat(y.paddingLeft))*g.x,E=w.top+(b.clientTop+parseFloat(y.paddingTop))*g.y;l*=g.x,c*=g.y,u*=g.x,f*=g.y,l+=k,c+=E,m=Dt(b),b=ca(m)}}return ds({width:u,height:f,x:l,y:c})}function ms(e,t){const n=ps(e).scrollLeft;return t?t.left+n:Zn(an(e)).left+n}function Ld(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-ms(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function gy(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=an(r),a=t?hs(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=on(1);const u=on(0),f=ln(r);if((f||!f&&!s)&&((Cr(r)!=="body"||co(i))&&(l=ps(r)),ln(r))){const p=Zn(r);c=kr(r),u.x=p.x+r.clientLeft,u.y=p.y+r.clientTop}const h=i&&!f&&!s?Ld(i,l):on(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+u.x+h.x,y:n.y*c.y-l.scrollTop*c.y+u.y+h.y}}function xy(e){return Array.from(e.getClientRects())}function by(e){const t=an(e),n=ps(e),r=e.ownerDocument.body,o=Mt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Mt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+ms(e);const a=-n.scrollTop;return Jt(r).direction==="rtl"&&(i+=Mt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const $d=25;function wy(e,t){const n=Dt(e),r=an(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const u=la();(!u||u&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=ms(r);if(c<=0){const u=r.ownerDocument,f=u.body,h=getComputedStyle(f),p=u.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,m=Math.abs(r.clientWidth-f.clientWidth-p);m<=$d&&(s-=m)}else c<=$d&&(s+=c);return{width:s,height:i,x:a,y:l}}const yy=new Set(["absolute","fixed"]);function vy(e,t){const n=Zn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=ln(e)?kr(e):on(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,c=r*s.y;return{width:i,height:a,x:l,y:c}}function Fd(e,t,n){let r;if(t==="viewport")r=wy(e,n);else if(t==="document")r=by(an(e));else if(Xt(t))r=vy(t,n);else{const o=Dd(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return ds(r)}function zd(e,t){const n=$n(e);return n===t||!Xt(n)||Tr(n)?!1:Jt(n).position==="fixed"||zd(n,t)}function Sy(e,t){const n=t.get(e);if(n)return n;let r=uo(e,[],!1).filter(a=>Xt(a)&&Cr(a)!=="body"),o=null;const s=Jt(e).position==="fixed";let i=s?$n(e):e;for(;Xt(i)&&!Tr(i);){const a=Jt(i),l=aa(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&yy.has(o.position)||co(i)&&!l&&zd(e,i))?r=r.filter(u=>u!==i):o=a,i=$n(i)}return t.set(e,r),r}function Cy(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?hs(t)?[]:Sy(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,u)=>{const f=Fd(t,u,o);return c.top=Mt(f.top,c.top),c.right=Ln(f.right,c.right),c.bottom=Ln(f.bottom,c.bottom),c.left=Mt(f.left,c.left),c},Fd(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function Ty(e){const{width:t,height:n}=Md(e);return{width:t,height:n}}function ky(e,t,n){const r=ln(t),o=an(t),s=n==="fixed",i=Zn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=on(0);function c(){l.x=ms(o)}if(r||!r&&!s)if((Cr(t)!=="body"||co(o))&&(a=ps(t)),r){const p=Zn(t,!0,s,t);l.x=p.x+t.clientLeft,l.y=p.y+t.clientTop}else o&&c();s&&!r&&o&&c();const u=o&&!r&&!s?Ld(o,a):on(0),f=i.left+a.scrollLeft-l.x-u.x,h=i.top+a.scrollTop-l.y-u.y;return{x:f,y:h,width:i.width,height:i.height}}function da(e){return Jt(e).position==="static"}function Bd(e,t){if(!ln(e)||Jt(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return an(e)===n&&(n=n.ownerDocument.body),n}function Ud(e,t){const n=Dt(e);if(hs(e))return n;if(!ln(e)){let o=$n(e);for(;o&&!Tr(o);){if(Xt(o)&&!da(o))return o;o=$n(o)}return n}let r=Bd(e,t);for(;r&&ay(r)&&da(r);)r=Bd(r,t);return r&&Tr(r)&&da(r)&&!aa(r)?n:r||fy(e)||n}const Ey=async function(e){const t=this.getOffsetParent||Ud,n=this.getDimensions,r=await n(e.floating);return{reference:ky(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Iy(e){return Jt(e).direction==="rtl"}const Ay={convertOffsetParentRelativeRectToViewportRelativeRect:gy,getDocumentElement:an,getClippingRect:Cy,getOffsetParent:Ud,getElementRects:Ey,getClientRects:xy,getDimensions:Ty,getScale:kr,isElement:Xt,isRTL:Iy};function Hd(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Ny(e,t){let n=null,r;const o=an(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const c=e.getBoundingClientRect(),{left:u,top:f,width:h,height:p}=c;if(a||t(),!h||!p)return;const m=cs(f),b=cs(o.clientWidth-(u+h)),g=cs(o.clientHeight-(f+p)),w=cs(u),k={rootMargin:-m+"px "+-b+"px "+-g+"px "+-w+"px",threshold:Mt(0,Ln(1,l))||1};let E=!0;function S(C){const T=C[0].intersectionRatio;if(T!==l){if(!E)return i();T?i(!1,T):r=setTimeout(()=>{i(!1,1e-7)},1e3)}T===1&&!Hd(c,e.getBoundingClientRect())&&i(),E=!1}try{n=new IntersectionObserver(S,{...k,root:o.ownerDocument})}catch{n=new IntersectionObserver(S,k)}n.observe(e)}return i(!0),s}function jy(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=ua(e),u=o||s?[...c?uo(c):[],...uo(t)]:[];u.forEach(w=>{o&&w.addEventListener("scroll",n,{passive:!0}),s&&w.addEventListener("resize",n)});const f=c&&a?Ny(c,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(w=>{let[y]=w;y&&y.target===c&&p&&(p.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var k;(k=p)==null||k.observe(t)})),n()}),c&&!l&&p.observe(c),p.observe(t));let m,b=l?Zn(e):null;l&&g();function g(){const w=Zn(e);b&&!Hd(b,w)&&n(),b=w,m=requestAnimationFrame(g)}return n(),()=>{var w;u.forEach(y=>{o&&y.removeEventListener("scroll",n),s&&y.removeEventListener("resize",n)}),f==null||f(),(w=p)==null||w.disconnect(),p=null,l&&cancelAnimationFrame(m)}}const _y=ty,Py=ny,Ry=Zw,Oy=oy,My=Qw,Wd=Jw,Dy=ry,Ly=(e,t,n)=>{const r=new Map,o={platform:Ay,...n},s={...o.platform,_c:r};return Xw(e,t,{...o,platform:s})};var $y=typeof document<"u",Fy=function(){},gs=$y?v.useLayoutEffect:Fy;function xs(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,o;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!xs(e[r],t[r]))return!1;return!0}if(o=Object.keys(e),n=o.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,o[r]))return!1;for(r=n;r--!==0;){const s=o[r];if(!(s==="_owner"&&e.$$typeof)&&!xs(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Vd(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Kd(e,t){const n=Vd(e);return Math.round(t*n)/n}function fa(e){const t=x.useRef(e);return gs(()=>{t.current=e}),t}function zy(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=e,[u,f]=x.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[h,p]=x.useState(r);xs(h,r)||p(r);const[m,b]=x.useState(null),[g,w]=x.useState(null),y=x.useCallback(H=>{H!==C.current&&(C.current=H,b(H))},[]),k=x.useCallback(H=>{H!==T.current&&(T.current=H,w(H))},[]),E=s||m,S=i||g,C=x.useRef(null),T=x.useRef(null),A=x.useRef(u),N=l!=null,j=fa(l),L=fa(o),B=fa(c),W=x.useCallback(()=>{if(!C.current||!T.current)return;const H={placement:t,strategy:n,middleware:h};L.current&&(H.platform=L.current),Ly(C.current,T.current,H).then(V=>{const Y={...V,isPositioned:B.current!==!1};O.current&&!xs(A.current,Y)&&(A.current=Y,al.flushSync(()=>{f(Y)}))})},[h,t,n,L,B]);gs(()=>{c===!1&&A.current.isPositioned&&(A.current.isPositioned=!1,f(H=>({...H,isPositioned:!1})))},[c]);const O=x.useRef(!1);gs(()=>(O.current=!0,()=>{O.current=!1}),[]),gs(()=>{if(E&&(C.current=E),S&&(T.current=S),E&&S){if(j.current)return j.current(E,S,W);W()}},[E,S,W,j,N]);const D=x.useMemo(()=>({reference:C,floating:T,setReference:y,setFloating:k}),[y,k]),z=x.useMemo(()=>({reference:E,floating:S}),[E,S]),ee=x.useMemo(()=>{const H={position:n,left:0,top:0};if(!z.floating)return H;const V=Kd(z.floating,u.x),Y=Kd(z.floating,u.y);return a?{...H,transform:"translate("+V+"px, "+Y+"px)",...Vd(z.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:V,top:Y}},[n,a,z.floating,u.x,u.y]);return x.useMemo(()=>({...u,update:W,refs:D,elements:z,floatingStyles:ee}),[u,W,D,z,ee])}const By=e=>{function t(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:e,fn(n){const{element:r,padding:o}=typeof e=="function"?e(n):e;return r&&t(r)?r.current!=null?Wd({element:r.current,padding:o}).fn(n):{}:r?Wd({element:r,padding:o}).fn(n):{}}}},Uy=(e,t)=>({..._y(e),options:[e,t]}),Hy=(e,t)=>({...Py(e),options:[e,t]}),Wy=(e,t)=>({...Dy(e),options:[e,t]}),Vy=(e,t)=>({...Ry(e),options:[e,t]}),Ky=(e,t)=>({...Oy(e),options:[e,t]}),qy=(e,t)=>({...My(e),options:[e,t]}),Gy=(e,t)=>({...By(e),options:[e,t]});var Yy="Arrow",qd=x.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return d.jsx(je.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:d.jsx("polygon",{points:"0,0 30,0 15,10"})})});qd.displayName=Yy;var Xy=qd;function Jy(e){const[t,n]=x.useState(void 0);return rn(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var ha="Popper",[Gd,Yd]=Mn(ha),[Zy,Xd]=Gd(ha),Jd=e=>{const{__scopePopper:t,children:n}=e,[r,o]=x.useState(null);return d.jsx(Zy,{scope:t,anchor:r,onAnchorChange:o,children:n})};Jd.displayName=ha;var Zd="PopperAnchor",Qd=x.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Xd(Zd,n),i=x.useRef(null),a=Ge(t,i),l=x.useRef(null);return x.useEffect(()=>{const c=l.current;l.current=(r==null?void 0:r.current)||i.current,c!==l.current&&s.onAnchorChange(l.current)}),r?null:d.jsx(je.div,{...o,ref:a})});Qd.displayName=Zd;var pa="PopperContent",[Qy,ev]=Gd(pa),ef=x.forwardRef((e,t)=>{var te,F,X,re,ue,le;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:u=0,sticky:f="partial",hideWhenDetached:h=!1,updatePositionStrategy:p="optimized",onPlaced:m,...b}=e,g=Xd(pa,n),[w,y]=x.useState(null),k=Ge(t,Se=>y(Se)),[E,S]=x.useState(null),C=Jy(E),T=(C==null?void 0:C.width)??0,A=(C==null?void 0:C.height)??0,N=r+(s!=="center"?"-"+s:""),j=typeof u=="number"?u:{top:0,right:0,bottom:0,left:0,...u},L=Array.isArray(c)?c:[c],B=L.length>0,W={padding:j,boundary:L.filter(nv),altBoundary:B},{refs:O,floatingStyles:D,placement:z,isPositioned:ee,middlewareData:H}=zy({strategy:"fixed",placement:N,whileElementsMounted:(...Se)=>jy(...Se,{animationFrame:p==="always"}),elements:{reference:g.anchor},middleware:[Uy({mainAxis:o+A,alignmentAxis:i}),l&&Hy({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?Wy():void 0,...W}),l&&Vy({...W}),Ky({...W,apply:({elements:Se,rects:Me,availableWidth:Ie,availableHeight:Ke})=>{const{width:He,height:Fe}=Me.reference,ze=Se.floating.style;ze.setProperty("--radix-popper-available-width",`${Ie}px`),ze.setProperty("--radix-popper-available-height",`${Ke}px`),ze.setProperty("--radix-popper-anchor-width",`${He}px`),ze.setProperty("--radix-popper-anchor-height",`${Fe}px`)}}),E&&Gy({element:E,padding:a}),rv({arrowWidth:T,arrowHeight:A}),h&&qy({strategy:"referenceHidden",...W})]}),[V,Y]=rf(z),q=ft(m);rn(()=>{ee&&(q==null||q())},[ee,q]);const M=(te=H.arrow)==null?void 0:te.x,P=(F=H.arrow)==null?void 0:F.y,$=((X=H.arrow)==null?void 0:X.centerOffset)!==0,[R,G]=x.useState();return rn(()=>{w&&G(window.getComputedStyle(w).zIndex)},[w]),d.jsx("div",{ref:O.setFloating,"data-radix-popper-content-wrapper":"",style:{...D,transform:ee?D.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:R,"--radix-popper-transform-origin":[(re=H.transformOrigin)==null?void 0:re.x,(ue=H.transformOrigin)==null?void 0:ue.y].join(" "),...((le=H.hide)==null?void 0:le.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:d.jsx(Qy,{scope:n,placedSide:V,onArrowChange:S,arrowX:M,arrowY:P,shouldHideArrow:$,children:d.jsx(je.div,{"data-side":V,"data-align":Y,...b,ref:k,style:{...b.style,animation:ee?void 0:"none"}})})})});ef.displayName=pa;var tf="PopperArrow",tv={top:"bottom",right:"left",bottom:"top",left:"right"},nf=x.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=ev(tf,r),i=tv[s.placedSide];return d.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:d.jsx(Xy,{...o,ref:n,style:{...o.style,display:"block"}})})});nf.displayName=tf;function nv(e){return e!==null}var rv=e=>({name:"transformOrigin",options:e,fn(t){var g,w,y;const{placement:n,rects:r,middlewareData:o}=t,i=((g=o.arrow)==null?void 0:g.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[c,u]=rf(n),f={start:"0%",center:"50%",end:"100%"}[u],h=(((w=o.arrow)==null?void 0:w.x)??0)+a/2,p=(((y=o.arrow)==null?void 0:y.y)??0)+l/2;let m="",b="";return c==="bottom"?(m=i?f:`${h}px`,b=`${-l}px`):c==="top"?(m=i?f:`${h}px`,b=`${r.floating.height+l}px`):c==="right"?(m=`${-l}px`,b=i?f:`${p}px`):c==="left"&&(m=`${r.floating.width+l}px`,b=i?f:`${p}px`),{data:{x:m,y:b}}}});function rf(e){const[t,n="center"]=e.split("-");return[t,n]}var ov=Jd,sv=Qd,iv=ef,av=nf,lv="Portal",ma=x.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=x.useState(!1);rn(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Ws.createPortal(d.jsx(je.div,{...r,ref:t}),i):null});ma.displayName=lv;function cv(e,t){return x.useReducer((n,r)=>t[n][r]??n,e)}var Lt=e=>{const{present:t,children:n}=e,r=uv(t),o=typeof n=="function"?n({present:r.isPresent}):x.Children.only(n),s=Ge(r.ref,dv(o));return typeof n=="function"||r.isPresent?x.cloneElement(o,{ref:s}):null};Lt.displayName="Presence";function uv(e){const[t,n]=x.useState(),r=x.useRef(null),o=x.useRef(e),s=x.useRef("none"),i=e?"mounted":"unmounted",[a,l]=cv(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return x.useEffect(()=>{const c=bs(r.current);s.current=a==="mounted"?c:"none"},[a]),rn(()=>{const c=r.current,u=o.current;if(u!==e){const h=s.current,p=bs(c);e?l("MOUNT"):p==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(u&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),rn(()=>{if(t){let c;const u=t.ownerDocument.defaultView??window,f=p=>{const b=bs(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&b&&(l("ANIMATION_END"),!o.current)){const g=t.style.animationFillMode;t.style.animationFillMode="forwards",c=u.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=g)})}},h=p=>{p.target===t&&(s.current=bs(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{u.clearTimeout(c),t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:x.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function bs(e){return(e==null?void 0:e.animationName)||"none"}function dv(e){var r,o;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(o=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:o.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var ga="rovingFocusGroup.onEntryFocus",fv={bubbles:!1,cancelable:!0},fo="RovingFocusGroup",[xa,of,hv]=hd(fo),[pv,sf]=Mn(fo,[hv]),[mv,gv]=pv(fo),af=x.forwardRef((e,t)=>d.jsx(xa.Provider,{scope:e.__scopeRovingFocusGroup,children:d.jsx(xa.Slot,{scope:e.__scopeRovingFocusGroup,children:d.jsx(xv,{...e,ref:t})})}));af.displayName=fo;var xv=x.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:u=!1,...f}=e,h=x.useRef(null),p=Ge(t,h),m=Yi(s),[b,g]=as({prop:i,defaultProp:a??null,onChange:l,caller:fo}),[w,y]=x.useState(!1),k=ft(c),E=of(n),S=x.useRef(!1),[C,T]=x.useState(0);return x.useEffect(()=>{const A=h.current;if(A)return A.addEventListener(ga,k),()=>A.removeEventListener(ga,k)},[k]),d.jsx(mv,{scope:n,orientation:r,dir:m,loop:o,currentTabStopId:b,onItemFocus:x.useCallback(A=>g(A),[g]),onItemShiftTab:x.useCallback(()=>y(!0),[]),onFocusableItemAdd:x.useCallback(()=>T(A=>A+1),[]),onFocusableItemRemove:x.useCallback(()=>T(A=>A-1),[]),children:d.jsx(je.div,{tabIndex:w||C===0?-1:0,"data-orientation":r,...f,ref:p,style:{outline:"none",...e.style},onMouseDown:ye(e.onMouseDown,()=>{S.current=!0}),onFocus:ye(e.onFocus,A=>{const N=!S.current;if(A.target===A.currentTarget&&N&&!w){const j=new CustomEvent(ga,fv);if(A.currentTarget.dispatchEvent(j),!j.defaultPrevented){const L=E().filter(z=>z.focusable),B=L.find(z=>z.active),W=L.find(z=>z.id===b),D=[B,W,...L].filter(Boolean).map(z=>z.ref.current);uf(D,u)}}S.current=!1}),onBlur:ye(e.onBlur,()=>y(!1))})})}),lf="RovingFocusGroupItem",cf=x.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=Ot(),c=s||l,u=gv(lf,n),f=u.currentTabStopId===c,h=of(n),{onFocusableItemAdd:p,onFocusableItemRemove:m,currentTabStopId:b}=u;return x.useEffect(()=>{if(r)return p(),()=>m()},[r,p,m]),d.jsx(xa.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:d.jsx(je.span,{tabIndex:f?0:-1,"data-orientation":u.orientation,...a,ref:t,onMouseDown:ye(e.onMouseDown,g=>{r?u.onItemFocus(c):g.preventDefault()}),onFocus:ye(e.onFocus,()=>u.onItemFocus(c)),onKeyDown:ye(e.onKeyDown,g=>{if(g.key==="Tab"&&g.shiftKey){u.onItemShiftTab();return}if(g.target!==g.currentTarget)return;const w=yv(g,u.orientation,u.dir);if(w!==void 0){if(g.metaKey||g.ctrlKey||g.altKey||g.shiftKey)return;g.preventDefault();let k=h().filter(E=>E.focusable).map(E=>E.ref.current);if(w==="last")k.reverse();else if(w==="prev"||w==="next"){w==="prev"&&k.reverse();const E=k.indexOf(g.currentTarget);k=u.loop?vv(k,E+1):k.slice(E+1)}setTimeout(()=>uf(k))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:b!=null}):i})})});cf.displayName=lf;var bv={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function wv(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function yv(e,t,n){const r=wv(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return bv[r]}function uf(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function vv(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Sv=af,Cv=cf,Tv=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Er=new WeakMap,ws=new WeakMap,ys={},ba=0,df=function(e){return e&&(e.host||df(e.parentNode))},kv=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=df(n);return r&&e.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",e,". Doing nothing"),null)}).filter(function(n){return!!n})},Ev=function(e,t,n,r){var o=kv(t,Array.isArray(e)?e:[e]);ys[n]||(ys[n]=new WeakMap);var s=ys[n],i=[],a=new Set,l=new Set(o),c=function(f){!f||a.has(f)||(a.add(f),c(f.parentNode))};o.forEach(c);var u=function(f){!f||l.has(f)||Array.prototype.forEach.call(f.children,function(h){if(a.has(h))u(h);else try{var p=h.getAttribute(r),m=p!==null&&p!=="false",b=(Er.get(h)||0)+1,g=(s.get(h)||0)+1;Er.set(h,b),s.set(h,g),i.push(h),b===1&&m&&ws.set(h,!0),g===1&&h.setAttribute(n,"true"),m||h.setAttribute(r,"true")}catch(w){console.error("aria-hidden: cannot operate on ",h,w)}})};return u(t),a.clear(),ba++,function(){i.forEach(function(f){var h=Er.get(f)-1,p=s.get(f)-1;Er.set(f,h),s.set(f,p),h||(ws.has(f)||f.removeAttribute(r),ws.delete(f)),p||f.removeAttribute(n)}),ba--,ba||(Er=new WeakMap,Er=new WeakMap,ws=new WeakMap,ys={})}},ff=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=Tv(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),Ev(r,o,n,"aria-hidden")):function(){return null}},cn=function(){return cn=Object.assign||function(t){for(var n,r=1,o=arguments.length;r<o;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},cn.apply(this,arguments)};function hf(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]]);return n}function Iv(e,t,n){if(n||arguments.length===2)for(var r=0,o=t.length,s;r<o;r++)(s||!(r in t))&&(s||(s=Array.prototype.slice.call(t,0,r)),s[r]=t[r]);return e.concat(s||Array.prototype.slice.call(t))}typeof SuppressedError=="function"&&SuppressedError;var vs="right-scroll-bar-position",Ss="width-before-scroll-bar",Av="with-scroll-bars-hidden",Nv="--removed-body-scroll-bar-size";function wa(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function jv(e,t){var n=v.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var o=n.value;o!==r&&(n.value=r,n.callback(r,o))}}}})[0];return n.callback=t,n.facade}var _v=typeof window<"u"?x.useLayoutEffect:x.useEffect,pf=new WeakMap;function Pv(e,t){var n=jv(null,function(r){return e.forEach(function(o){return wa(o,r)})});return _v(function(){var r=pf.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||wa(a,null)}),s.forEach(function(a){o.has(a)||wa(a,i)})}pf.set(n,e)},[e]),n}function Rv(e){return e}function Ov(e,t){t===void 0&&(t=Rv);var n=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var u=i;i=[],u.forEach(s)},c=function(){return Promise.resolve().then(l)};c(),n={push:function(u){i.push(u),c()},filter:function(u){return i=i.filter(u),n}}}};return o}function Mv(e){e===void 0&&(e={});var t=Ov(null);return t.options=cn({async:!0,ssr:!1},e),t}var mf=function(e){var t=e.sideCar,n=hf(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return x.createElement(r,cn({},n))};mf.isSideCarExport=!0;function Dv(e,t){return e.useMedium(t),mf}var gf=Mv(),ya=function(){},Cs=x.forwardRef(function(e,t){var n=x.useRef(null),r=x.useState({onScrollCapture:ya,onWheelCapture:ya,onTouchMoveCapture:ya}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,u=e.enabled,f=e.shards,h=e.sideCar,p=e.noRelative,m=e.noIsolation,b=e.inert,g=e.allowPinchZoom,w=e.as,y=w===void 0?"div":w,k=e.gapMode,E=hf(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),S=h,C=Pv([n,t]),T=cn(cn({},E),o);return x.createElement(x.Fragment,null,u&&x.createElement(S,{sideCar:gf,removeScrollBar:c,shards:f,noRelative:p,noIsolation:m,inert:b,setCallbacks:s,allowPinchZoom:!!g,lockRef:n,gapMode:k}),i?x.cloneElement(x.Children.only(a),cn(cn({},T),{ref:C})):x.createElement(y,cn({},T,{className:l,ref:C}),a))});Cs.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Cs.classNames={fullWidth:Ss,zeroRight:vs};var Lv=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function $v(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Lv();return t&&e.setAttribute("nonce",t),e}function Fv(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function zv(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Bv=function(){var e=0,t=null;return{add:function(n){e==0&&(t=$v())&&(Fv(t,n),zv(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Uv=function(){var e=Bv();return function(t,n){x.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},xf=function(){var e=Uv(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Hv={left:0,top:0,right:0,gap:0},va=function(e){return parseInt(e||"",10)||0},Wv=function(e){var t=window.getComputedStyle(document.body),n=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],o=t[e==="padding"?"paddingRight":"marginRight"];return[va(n),va(r),va(o)]},Vv=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Hv;var t=Wv(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},Kv=xf(),Ir="data-scroll-locked",qv=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
84
+ `}strong(t){return`<strong>${t}</strong>`}em(t){return`<em>${t}</em>`}codespan(t){return`<code>${t}</code>`}br(){return this.options.xhtml?"<br/>":"<br>"}del(t){return`<del>${t}</del>`}link(t,n,r){if(t=td(this.options.sanitize,this.options.baseUrl,t),t===null)return r;let o='<a href="'+t+'"';return n&&(o+=' title="'+n+'"'),o+=">"+r+"</a>",o}image(t,n,r){if(t=td(this.options.sanitize,this.options.baseUrl,t),t===null)return r;let o=`<img src="${t}" alt="${r}"`;return n&&(o+=` title="${n}"`),o+=this.options.xhtml?"/>":">",o}text(t){return t}}class id{strong(t){return t}em(t){return t}codespan(t){return t}del(t){return t}html(t){return t}text(t){return t}link(t,n,r){return""+r}image(t,n,r){return""+r}br(){return""}}class ad{constructor(){this.seen={}}serialize(t){return t.toLowerCase().trim().replace(/<[!\/a-z].*?>/ig,"").replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g,"").replace(/\s/g,"-")}getNextSafeSlug(t,n){let r=t,o=0;if(this.seen.hasOwnProperty(r)){o=this.seen[t];do o++,r=t+"-"+o;while(this.seen.hasOwnProperty(r))}return n||(this.seen[t]=o,this.seen[r]=0),r}slug(t,n={}){const r=this.serialize(t);return this.getNextSafeSlug(r,n.dryrun)}}class _n{constructor(t){this.options=t||Jn,this.options.renderer=this.options.renderer||new Hi,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new id,this.slugger=new ad}static parse(t,n){return new _n(n).parse(t)}static parseInline(t,n){return new _n(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,c,u,f,h,p,m,b,g,w,y,k,E,S,C;const T=t.length;for(o=0;o<T;o++){if(p=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[p.type]&&(C=this.options.extensions.renderers[p.type].call({parser:this},p),C!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(p.type))){r+=C||"";continue}switch(p.type){case"space":continue;case"hr":{r+=this.renderer.hr();continue}case"heading":{r+=this.renderer.heading(this.parseInline(p.tokens),p.depth,ed(this.parseInline(p.tokens,this.textRenderer)),this.slugger);continue}case"code":{r+=this.renderer.code(p.text,p.lang,p.escaped);continue}case"table":{for(f="",u="",a=p.header.length,s=0;s<a;s++)u+=this.renderer.tablecell(this.parseInline(p.header[s].tokens),{header:!0,align:p.align[s]});for(f+=this.renderer.tablerow(u),h="",a=p.rows.length,s=0;s<a;s++){for(c=p.rows[s],u="",l=c.length,i=0;i<l;i++)u+=this.renderer.tablecell(this.parseInline(c[i].tokens),{header:!1,align:p.align[i]});h+=this.renderer.tablerow(u)}r+=this.renderer.table(f,h);continue}case"blockquote":{h=this.parse(p.tokens),r+=this.renderer.blockquote(h);continue}case"list":{for(m=p.ordered,b=p.start,g=p.loose,a=p.items.length,h="",s=0;s<a;s++)y=p.items[s],k=y.checked,E=y.task,w="",y.task&&(S=this.renderer.checkbox(k),g?y.tokens.length>0&&y.tokens[0].type==="paragraph"?(y.tokens[0].text=S+" "+y.tokens[0].text,y.tokens[0].tokens&&y.tokens[0].tokens.length>0&&y.tokens[0].tokens[0].type==="text"&&(y.tokens[0].tokens[0].text=S+" "+y.tokens[0].tokens[0].text)):y.tokens.unshift({type:"text",text:S}):w+=S),w+=this.parse(y.tokens,g),h+=this.renderer.listitem(w,E,k);r+=this.renderer.list(h,m,b);continue}case"html":{r+=this.renderer.html(p.text);continue}case"paragraph":{r+=this.renderer.paragraph(this.parseInline(p.tokens));continue}case"text":{for(h=p.tokens?this.parseInline(p.tokens):p.text;o+1<T&&t[o+1].type==="text";)p=t[++o],h+=`
85
+ `+(p.tokens?this.parseInline(p.tokens):p.text);r+=n?this.renderer.paragraph(h):h;continue}default:{const N='Token with "'+p.type+'" type was not found.';if(this.options.silent){console.error(N);return}else throw new Error(N)}}}return r}parseInline(t,n){n=n||this.renderer;let r="",o,s,i;const a=t.length;for(o=0;o<a;o++){if(s=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[s.type]&&(i=this.options.extensions.renderers[s.type].call({parser:this},s),i!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type))){r+=i||"";continue}switch(s.type){case"escape":{r+=n.text(s.text);break}case"html":{r+=n.html(s.text);break}case"link":{r+=n.link(s.href,s.title,this.parseInline(s.tokens,n));break}case"image":{r+=n.image(s.href,s.title,s.text);break}case"strong":{r+=n.strong(this.parseInline(s.tokens,n));break}case"em":{r+=n.em(this.parseInline(s.tokens,n));break}case"codespan":{r+=n.codespan(s.text);break}case"br":{r+=n.br();break}case"del":{r+=n.del(this.parseInline(s.tokens,n));break}case"text":{r+=n.text(s.text);break}default:{const l='Token with "'+s.type+'" type was not found.';if(this.options.silent){console.error(l);return}else throw new Error(l)}}}return r}}class os{constructor(t){this.options=t||Jn}preprocess(t){return t}postprocess(t){return t}}sl(os,"passThroughHooks",new Set(["preprocess","postprocess"]));function dw(e,t,n){return r=>{if(r.message+=`
86
+ Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+dt(r.message+"",!0)+"</pre>";if(t)return Promise.resolve(o);if(n){n(null,o);return}return o}if(t)return Promise.reject(r);if(n){n(r);return}throw r}}function ld(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...pe.defaults,...s};const i=dw(r.silent,r.async,o);if(typeof n>"u"||n===null)return i(new Error("marked(): input parameter is undefined or null"));if(typeof n!="string")return i(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(n)+", string expected"));if(lw(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(f){return i(f)}const c=function(f){let h;if(!f)try{r.walkTokens&&pe.walkTokens(l,r.walkTokens),h=t(l,r),r.hooks&&(h=r.hooks.postprocess(h))}catch(p){f=p}return r.highlight=a,f?i(f):o(null,h)};if(!a||a.length<3||(delete r.highlight,!l.length))return c();let u=0;pe.walkTokens(l,function(f){f.type==="code"&&(u++,setTimeout(()=>{a(f.text,f.lang,function(h,p){if(h)return c(h);p!=null&&p!==f.text&&(f.text=p,f.escaped=!0),u--,u===0&&c()})},0))}),u===0&&c();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(pe.walkTokens(a,r.walkTokens)).then(()=>a):a).then(a=>t(a,r)).then(a=>r.hooks?r.hooks.postprocess(a):a).catch(i);try{r.hooks&&(n=r.hooks.preprocess(n));const a=e(n,r);r.walkTokens&&pe.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function pe(e,t,n){return ld(jn.lex,_n.parse)(e,t,n)}pe.options=pe.setOptions=function(e){return pe.defaults={...pe.defaults,...e},Yb(pe.defaults),pe},pe.getDefaults=Xu,pe.defaults=Jn,pe.use=function(...e){const t=pe.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=pe.defaults.async||r.async||!1,n.extensions&&(n.extensions.forEach(o=>{if(!o.name)throw new Error("extension name required");if(o.renderer){const s=t.renderers[o.name];s?t.renderers[o.name]=function(...i){let a=o.renderer.apply(this,i);return a===!1&&(a=s.apply(this,i)),a}:t.renderers[o.name]=o.renderer}if(o.tokenizer){if(!o.level||o.level!=="block"&&o.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");t[o.level]?t[o.level].unshift(o.tokenizer):t[o.level]=[o.tokenizer],o.start&&(o.level==="block"?t.startBlock?t.startBlock.push(o.start):t.startBlock=[o.start]:o.level==="inline"&&(t.startInline?t.startInline.push(o.start):t.startInline=[o.start]))}o.childTokens&&(t.childTokens[o.name]=o.childTokens)}),r.extensions=t),n.renderer){const o=pe.defaults.renderer||new Hi;for(const s in n.renderer){const i=o[s];o[s]=(...a)=>{let l=n.renderer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.renderer=o}if(n.tokenizer){const o=pe.defaults.tokenizer||new Ui;for(const s in n.tokenizer){const i=o[s];o[s]=(...a)=>{let l=n.tokenizer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.tokenizer=o}if(n.hooks){const o=pe.defaults.hooks||new os;for(const s in n.hooks){const i=o[s];os.passThroughHooks.has(s)?o[s]=a=>{if(pe.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(c=>i.call(o,c));const l=n.hooks[s].call(o,a);return i.call(o,l)}:o[s]=(...a)=>{let l=n.hooks[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.hooks=o}if(n.walkTokens){const o=pe.defaults.walkTokens;r.walkTokens=function(s){let i=[];return i.push(n.walkTokens.call(this,s)),o&&(i=i.concat(o.call(this,s))),i}}pe.setOptions(r)})},pe.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(pe,r)),r.type){case"table":{for(const o of r.header)n=n.concat(pe.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(pe.walkTokens(s.tokens,t));break}case"list":{n=n.concat(pe.walkTokens(r.items,t));break}default:pe.defaults.extensions&&pe.defaults.extensions.childTokens&&pe.defaults.extensions.childTokens[r.type]?pe.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(pe.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(pe.walkTokens(r.tokens,t)))}return n},pe.parseInline=ld(jn.lexInline,_n.parseInline),pe.Parser=_n,pe.parser=_n.parse,pe.Renderer=Hi,pe.TextRenderer=id,pe.Lexer=jn,pe.lexer=jn.lex,pe.Tokenizer=Ui,pe.Slugger=ad,pe.Hooks=os,pe.parse=pe,pe.options,pe.setOptions,pe.use,pe.walkTokens,pe.parseInline,_n.parse,jn.lex;function oo({content:e,className:t="",allowHtml:n=!1,style:r}){const o=v.useMemo(()=>{if(!e||typeof e!="string"||e.trim().length===0)return"";try{if(!n){const i=e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,"").replace(/javascript:/gi,"").replace(/on\w+\s*=/gi,"");return typeof pe.parse=="function"?pe.parse(i):pe(i)}return typeof pe.parse=="function"?pe.parse(e):pe(e)}catch(i){return console.error("[MarkdownContent] parse error",i),`<pre class="font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words">Error rendering markdown: ${String(i)}</pre>`}},[e,n]),s=v.useMemo(()=>{const i={color:"currentColor",...r};if(r&&r.color){const a=r.color;return{...i,"--tw-prose-body":a,"--tw-prose-headings":a,"--tw-prose-links":a,"--tw-prose-bold":a,"--tw-prose-counters":a,"--tw-prose-bullets":a,"--tw-prose-hr":a,"--tw-prose-quotes":a,"--tw-prose-quote-borders":a,"--tw-prose-captions":a,"--tw-prose-code":a,"--tw-prose-pre-code":a,"--tw-prose-pre-bg":"inherit","--tw-prose-th-borders":a,"--tw-prose-td-borders":a}}return i},[r]);return d.jsx("div",{className:he("markdown prose prose-sm max-w-none break-words","dark:prose-invert","text-current","prose-headings:text-current prose-p:text-current prose-li:text-current prose-a:text-current prose-strong:text-current","prose-em:text-current prose-blockquote:text-current prose-table:text-current prose-td:text-current prose-th:text-current","prose-pre:font-mono prose-pre:text-xs prose-pre:bg-background/50 prose-pre:border prose-pre:rounded prose-pre:p-3 prose-pre:whitespace-pre prose-pre:overflow-x-auto","prose-code:font-mono prose-code:text-sm prose-code:bg-background/50 prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:text-current",t),style:s,dangerouslySetInnerHTML:{__html:o}})}function fw({text:e,expanded:t,onExpandedChange:n,previewLength:r,isCompact:o}){const s=Math.max(e.length-r,0),i=e.substring(0,r);return d.jsxs("div",{className:"flex flex-col gap-1",children:[d.jsx("div",{className:he("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?d.jsx(oo,{content:e,allowHtml:!1}):d.jsxs("pre",{className:he("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:[i,"..."]})}),d.jsx(Je,{type:"button",variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",onClick:()=>n(!t),children:t?d.jsxs(d.Fragment,{children:[d.jsx(xe.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):d.jsxs(d.Fragment,{children:[d.jsx(xe.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",s," chars)"]})})]})}function Wi({showTimestamp:e,showAgentName:t,isToolMessage:n,isInterruptMessage:r=!1,iconForeground:o,agentName:s,messageIcon:i,customHeaderClass:a,customActionsClass:l,isCompactLayout:c,showActions:u,isEditing:f,messageRole:h,onCopy:p,onEdit:m,onRegenerate:b,showCheckpointControls:g,attemptCount:w,attemptIndex:y,handleOlderAttemptSelect:k,handleNewerAttemptSelect:E,messageCreatedAt:S,copied:C}){return!e&&!t&&!n&&!r?null:d.jsxs("div",{className:he("flex items-center justify-between mb-2 pb-2",h!=="assistant"&&"border-b border-current/10",c&&"mb-1 pb-1",o,a),children:[d.jsxs("div",{className:"flex items-center gap-2",children:[i,t&&s&&d.jsx("span",{className:he("font-medium",c?"text-xs":"text-sm"),children:s}),r&&d.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Interrupt"})]}),d.jsxs("div",{className:"flex items-center gap-2",children:[g&&w>1&&d.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[d.jsx("button",{type:"button",className:he("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",y<w-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{y>=w-1||k()},"aria-label":"Older attempt (back in time)",disabled:y>=w-1,children:d.jsx(xe.ChevronLeft,{className:"h-3 w-3"})}),d.jsx("div",{className:"flex items-center gap-2",children:d.jsxs("span",{className:"whitespace-nowrap",children:[w-y," / ",w]})}),d.jsx("button",{type:"button",className:he("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",y>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{y<=0||E()},"aria-label":"Newer attempt (forward in time)",disabled:y<=0,children:d.jsx(xe.ChevronRight,{className:"h-3 w-3"})})]}),e&&S&&d.jsx("time",{className:he("text-xs opacity-60",o,c&&"text-xs"),dateTime:new Date(S.endsWith("Z")||S.includes("+")?S:`${S}Z`).toISOString(),title:new Date(S.endsWith("Z")||S.includes("+")?S:`${S}Z`).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(S.endsWith("Z")||S.includes("+")?S:`${S}Z`))}),u&&!f&&d.jsxs("div",{className:he("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",l),children:[d.jsx("div",{className:"relative",children:d.jsx(Je,{variant:"ghost",size:"sm",onClick:p,className:he("h-6 w-6 p-0 hover:bg-foreground/10",o,c&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:d.jsx(xe.Copy,{className:he(C?"text-success":o,c?"h-3 w-3":"h-4 w-4")})})}),h==="user"&&m&&d.jsx(Je,{variant:"ghost",size:"sm",onClick:m,className:he("h-6 w-6 p-0 hover:bg-foreground/10",o,c&&"h-5 w-5"),"aria-label":"Edit message",children:d.jsx(xe.Edit,{className:he(o,c?"h-3 w-3":"h-4 w-4")})}),h==="assistant"&&b&&d.jsx(Je,{variant:"ghost",size:"sm",onClick:b,className:he("h-6 w-6 p-0 hover:bg-foreground/10",o,c&&"h-5 w-5"),"aria-label":"Regenerate response",children:d.jsx(xe.RotateCcw,{className:he(o,c?"h-3 w-3":"h-4 w-4")})})]})]})]})}function Vi(e){return v.useMemo(()=>({textContent:yg(e),imageParts:vg(e),fileParts:Sg(e),toolCalls:li(e),interruptParts:Cg(e),contentParts:e.content}),[e])}function cd(e,t,n){const[r,o]=v.useState(e),s=v.useRef(e),i=v.useRef(null);return v.useEffect(()=>{s.current=e;const a=()=>{o(s.current),i.current&&(clearTimeout(i.current),i.current=null)};if(!t||n<=0){a();return}return i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{a()},n),()=>{i.current&&(clearTimeout(i.current),i.current=null)}},[e,t,n]),r}const ss=v.memo(function({contentParts:t,textContent:n,imageParts:r,fileParts:o,messageRole:s,isCompactLayout:i=!1,truncateUserMessages:a=!1,userMessagePreviewLength:l=500,isUserExpanded:c=!1,setIsUserExpanded:u,uploadingFiles:f={},handleFileClick:h,isStreamingMessage:p=!1,renderStreamingMarkdown:m=!0,enableStreamingMarkdownBuffer:b=!0,streamingDebounceMs:g=0}){const w=cd(t,b&&p,g),y=v.useMemo(()=>w.filter(z=>z.type==="text"),[w]),k=v.useMemo(()=>y.map(z=>z.text??"").join(""),[y]),E=m&&p,S=v.useMemo(()=>{if(!E)return null;const z=pw(k);return{stablePart:k.slice(0,z),tailPart:k.slice(z)}},[k,E]),C=v.useMemo(()=>{if(!S)return null;const{stablePart:z,tailPart:H}=S;return!z&&!H?null:d.jsxs("div",{className:"space-y-2",children:[z?d.jsx(oo,{content:z,allowHtml:!1}):null,H?d.jsx(oo,{content:H,allowHtml:!1}):null]})},[S]),T=()=>!r||r.length===0?null:d.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:r.map((z,H)=>{const P=z;return d.jsx("div",{className:"relative group",children:d.jsx("img",{src:P.image_url.url,alt:"Image",loading:"lazy",onClick:()=>window.open(P.image_url.url,"_blank"),className:"h-20 w-20 object-cover rounded-md border border-border/50 cursor-pointer hover:opacity-90 transition-opacity"})},`img-${H}`)})}),N=(z,H)=>{if(z.type==="text"){const P=z.text??"",M=P.trim(),F=hr(M);return F&&s!=="tool"?d.jsx(Wb,{data:F},H):s==="user"&&a&&M.length>l&&!c?d.jsx(fw,{text:M,expanded:c,onExpandedChange:u||(()=>{}),previewLength:l,isCompact:i},H):d.jsx(oo,{content:P,allowHtml:!1},H)}if(z.type==="file"){const P=z,M=P.name||"file",F=f[H];return d.jsxs("a",{href:P.url,onClick:ne=>h==null?void 0:h(ne,P,H),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
87
+ dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[F?d.jsx(xe.Loader,{className:"h-4 w-4 animate-spin"}):null,d.jsxs("span",{className:"truncate max-w-[180px]",children:[M,F?" (processing)":""]})]},H)}return null},j=E?k:n;if(!(j.trim().length>0||r.length>0||o.length>0)&&!p)return null;const D=E?w.filter(z=>z.type!=="text"):w;return d.jsxs("div",{className:"space-y-2",children:[E?C:null,D.filter(z=>z.type==="text"||z.type==="file").map((z,H)=>N(z,H)),T(),p&&j.trim().length>0&&d.jsx("span",{className:"inline-block w-2 h-4 ml-0.5 bg-current opacity-70 animate-pulse align-middle","aria-hidden":"true"})]})});ss.displayName="SharedContent";function hw(e){return e?!(so(e,/```/g)||so(e,/`/g)||so(e,/\*\*/g)||so(e,/__/g)||so(e,/~~/g)||/[^\\]\[[^\]]*$/.test(e)||/\[[^\]]*\]\([^)]*$/.test(e)):!0}function so(e,t){const n=e.match(t);return((n==null?void 0:n.length)??0)%2!==0}function pw(e){if(!e)return 0;for(let t=e.length;t>=0;t-=1)if(hw(e.slice(0,t)))return t;return 0}const ud=v.memo(function({isStreamingMessage:t,interruptPart:n,handleInterruptApprove:r,handleInterruptReject:o,handleInterruptAlternative:s,disableInterruptActions:i,iconForeground:a,textContent:l=""}){if(n)return d.jsx(Yu,{interruptPart:n,payload:n.value,onApprove:r||(()=>{}),onReject:o||(()=>{}),onSelectAlternative:s,disabled:i,isActive:!i});const c=l.trim().length>0;return t&&!c?d.jsx(Gb,{className:a}):null});ud.displayName="InteractiveContent";const io=v.memo(function({role:t,header:n,content:r,actions:o,status:s,isCompactLayout:i=!1,variant:a="default",customStyles:l={}}){const c=t==="user",u=t==="system",f=he("flex w-full group py-3 md:py-4 px-2 md:px-0",c?"justify-end":"justify-start",l.container),h=he("relative flex flex-col rounded-2xl transition-all duration-200",a==="minimal"?"bg-transparent border border-border/50 shadow-none":a==="accent"?"ring-2 ring-primary/20":"",c?"bg-[hsl(var(--chat-bubble-user-bg,210_40%_96%))] text-[hsl(var(--chat-bubble-user-text,222_47%_11%))] shadow-sm border border-border/40 w-full max-w-full":"bg-[hsl(var(--chat-bubble-ai-bg))] text-[hsl(var(--chat-bubble-ai-text))] w-full max-w-full",u&&"bg-transparent border-none shadow-none text-muted-foreground max-w-full opacity-80",i?"px-3 py-2":"px-4 py-3 md:px-5 md:py-4",l.bubble),p=he("text-sm leading-relaxed break-words",l.content),m=he("absolute top-0 opacity-0 group-hover:opacity-100 transition-opacity flex items-center gap-1",c?"-left-10":"-right-10",i&&"hidden",l.actions);return d.jsx("div",{className:f,children:d.jsxs("div",{className:h,children:[n&&d.jsx("div",{className:he("mb-2 w-full",l.header),children:n}),s&&d.jsx("div",{className:"mb-2 w-full",children:s}),d.jsx("div",{className:p,children:r}),o&&d.jsx("div",{className:m,children:o})]})})});io.displayName="MessageBubble";const Ki=v.memo(function({message:t,messageIndex:n,isStreamingMessage:r=!1,streamingDebounceMs:o,renderStreamingMarkdown:s=!0,enableStreamingMarkdownBuffer:i=!0,layoutSize:a,showToolMessages:l,toolConfig:c,customStyles:u,onRegenerate:f,onCopy:h,getInterruptOptions:p,renderArtifactsInline:m,showToolProgress:b,showToolResultsInline:g,isEmbedded:w=!1,precedingMessages:y=[],showHeader:k,hideToolProgress:E=!1,forceAgentName:S}){var jt,Ut,nt,Ze,yt;const{layoutSize:C,toolConfig:T,renderArtifactsInline:N,streamingDebounceMs:j,onRegenerate:_,getInterruptOptions:D,showToolMessages:z,messageCustomStyles:H}=zo(),P=c??T,M=a??C,F=m??N,ne=o??j??0,U=f??_,W=p??D,Y=l??z??!0,q=b??Y,R=g??Y,G={...(H==null?void 0:H(t))||{},...u},A=h;console.debug("[AssistantMessageComponent] Render",{id:t.id,role:t.role,name:t.name,contentParts:t.content,precedingCount:y.length,isStreamingMessage:r,textContentLength:(nt=(Ut=(jt=t.content)==null?void 0:jt[0])==null?void 0:Ut.text)==null?void 0:nt.length});const[O,V]=v.useState(!1),{respondToInterrupt:Z}=Kr(),[$,X]=v.useState(!1),oe=M==="phone"||M==="half-screen",{contentParts:ue,textContent:le,imageParts:Ce,fileParts:De,toolCalls:Ie,interruptParts:qe}=Vi(t),We=qe[0]||null,Fe=v.useCallback(async()=>{const Be=le;try{await navigator.clipboard.writeText(Be),V(!0),setTimeout(()=>V(!1),2e3),A==null||A(Be)}catch(Le){console.error("Failed to copy assistant message:",Le)}},[le,A]),ze=v.useCallback(async(Be,Le)=>{if(!(!We||!uc(We.id))){X(!0);try{const or=W==null?void 0:W(t);await Z(Be,Le,or)}finally{X(!1)}}},[We,t,W,Z]),It=v.useCallback(()=>{U==null||U(n)},[U,n]),At=!w&&(k??((Ze=P==null?void 0:P.getShowHeader)==null?void 0:Ze.call(P,t))??!0),bt=!E&&t.role==="assistant"&&q?d.jsx(Hu,{messages:[...y,t],isStreaming:r,toolConfig:P}):null,wt=At&&d.jsx(Wi,{showTimestamp:!0,showAgentName:!0,isToolMessage:t.role==="tool",isInterruptMessage:!1,iconForeground:"text-[hsl(var(--chat-bubble-ai-text))]",agentName:S||t.name||t.model||"Agent",messageIcon:t.role==="tool"?d.jsx(xe.Wrench,{className:"h-4 w-4 opacity-60"}):d.jsx(xe.Bot,{className:"h-4 w-4 opacity-60"}),isCompactLayout:oe,showActions:!0,isEditing:!1,messageRole:t.role,onCopy:Fe,onEdit:void 0,onRegenerate:It,showCheckpointControls:!1,attemptCount:1,attemptIndex:0,handleOlderAttemptSelect:()=>{},handleNewerAttemptSelect:()=>{},messageCreatedAt:t.createdAt,copied:O,customActionsClass:G.actions}),ht=t.role==="tool",st=ht?d.jsx(es,{message:t,viewMode:"expanded",isStreaming:r,toolConfig:P,expandable:(yt=P==null?void 0:P.getToolExpandable)==null?void 0:yt.call(P,t)}):null,Nt=d.jsxs("div",{className:"space-y-4",children:[y.map(Be=>{var Le;return d.jsx("div",{className:"space-y-2 pb-4 border-b border-border/20 last:border-0 last:pb-0",children:d.jsx(es,{message:Be,viewMode:"expanded",isStreaming:!1,toolConfig:P,expandable:(Le=P==null?void 0:P.getToolExpandable)==null?void 0:Le.call(P,Be)})},Be.id)}),ht?st:d.jsxs(d.Fragment,{children:[d.jsx(ss,{contentParts:ue,textContent:le,imageParts:Ce,fileParts:De,messageRole:t.role,isCompactLayout:oe,isStreamingMessage:r,renderStreamingMarkdown:s,enableStreamingMarkdownBuffer:i,streamingDebounceMs:ne}),t.role==="assistant"&&R&&Ie.map(Be=>d.jsx(es,{message:{...t,role:"tool",name:Be.name,toolCallId:Be.id,artifact:Be.artifact,content:[{type:"text",text:JSON.stringify(Be.args)}]},viewMode:"expanded",isStreaming:r,toolConfig:P},Be.id)),d.jsx(ud,{message:t,isStreamingMessage:r,toolConfig:P,interruptPart:We,handleInterruptApprove:()=>ze(!0),handleInterruptReject:()=>ze(!1),handleInterruptAlternative:(Be,Le)=>ze(!0,{alternativeId:Le==null?void 0:Le.id}),disableInterruptActions:$,renderArtifactsInline:F,iconForeground:"text-[hsl(var(--chat-bubble-ai-text))]",textContent:le})]})]});return w?Nt:d.jsx(io,{role:t.role,header:wt,status:bt,content:Nt,isCompactLayout:oe,customStyles:G})});Ki.displayName="AssistantMessageComponent";const qi=v.memo(function({message:t,layoutSize:n="desktop",truncateUserMessages:r=!0,userMessagePreviewLength:o=500,enableMessageEditing:s=!0,onEdit:i,checkpointIndex:a,onSelectCheckpoint:l,customStyles:c={}}){const[u,f]=v.useState(!1),[h,p]=v.useState(!1),m=n==="phone"||n==="half-screen",{contentParts:b,textContent:g,imageParts:w,fileParts:y}=Vi(t),k=v.useCallback(async()=>{try{await navigator.clipboard.writeText(g),f(!0),setTimeout(()=>f(!1),2e3)}catch(H){console.error("Failed to copy user message:",H)}},[g]),E=v.useCallback(()=>{if(!i||!t.id)return;const H={checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};i(t.id,g,H)},[i,t,g]),{attemptCount:S,attemptIndex:C,attempts:T}=v.useMemo(()=>a?Jg(t.id,t.checkpointId,a):{attemptCount:1,attemptIndex:0,attempts:[]},[t.id,t.checkpointId,a]),N=S>1&&!!l,j=v.useCallback(()=>{const H=T[C+1];H&&l&&l(H.id,void 0,!!H.isLatestAttempt)},[T,C,l]),_=v.useCallback(()=>{const H=T[C-1];H&&l&&l(H.id,void 0,!!H.isLatestAttempt)},[T,C,l]),D=d.jsx(Wi,{showTimestamp:!0,showAgentName:!0,isToolMessage:!1,iconForeground:"text-[hsl(var(--chat-bubble-user-text))]",agentName:null,messageIcon:d.jsx(xe.User,{className:he(m?"h-3 w-3":"h-4 w-4","opacity-60")}),isCompactLayout:m,showActions:!0,isEditing:!1,messageRole:"user",onCopy:k,onEdit:s?E:void 0,showCheckpointControls:N,attemptCount:S,attemptIndex:C,handleOlderAttemptSelect:j,handleNewerAttemptSelect:_,messageCreatedAt:t.createdAt,copied:u,customHeaderClass:c.header,customActionsClass:c.actions}),z=d.jsx(ss,{contentParts:b,textContent:g,imageParts:w,fileParts:y,messageRole:"user",truncateUserMessages:r,userMessagePreviewLength:o,isUserExpanded:h,setIsUserExpanded:p,isCompactLayout:m,handleFileClick:()=>{},uploadingFiles:{}});return d.jsx(io,{role:"user",header:D,content:z,isCompactLayout:m,customStyles:c})});qi.displayName="UserMessageComponent";const Gi=v.memo(function({message:t,layoutSize:n="desktop",customStyles:r={}}){const o=n==="phone"||n==="half-screen",{contentParts:s,textContent:i,imageParts:a,fileParts:l}=Vi(t),c=d.jsxs("div",{className:"flex items-center gap-2 mb-1 opacity-50",children:[d.jsx(xe.Info,{className:he(o?"h-3 w-3":"h-4 w-4")}),d.jsx("span",{className:"text-[10px] font-bold uppercase tracking-wider",children:"System Message"})]}),u=d.jsx(ss,{contentParts:s,textContent:i,imageParts:a,fileParts:l,messageRole:"system",isCompactLayout:o});return d.jsx(io,{role:"system",header:c,content:u,isCompactLayout:o,customStyles:r})});Gi.displayName="SystemMessageComponent";const is=v.forwardRef(({messages:e=[],isStreaming:t,onStartReached:n,className:r,style:o,emptyMessage:s,onScrollAway:i,onAtBottom:a,renderMessage:l},c)=>{const{followNewMessages:u,checkpointIndex:f}=zo(),h=!!f,p=v.useRef(null),m=v.useRef(null),b=v.useRef(!1),g=v.useRef(!1),w=v.useCallback(_=>{i&&i(!_),a&&a(_)},[i,a]),y=v.useMemo(()=>{if(n)return async()=>{if(!b.current){b.current=!0;try{await n()}finally{b.current=!1}}}},[n]),k=v.useMemo(()=>!u||h?!1:"auto",[u,h]),E=e.length===0&&s,S=["flex flex-1 flex-col min-h-0 min-w-0",r].filter(Boolean).join(" "),C=()=>E?d.jsx("div",{className:"h-full w-full",children:s}):d.jsx("div",{className:"flex h-full items-center justify-center py-8 text-center text-muted-foreground",children:"No messages yet. Start a conversation!"}),T=e.length,N=T>0;v.useEffect(()=>{var _,D;if(T===0){g.current=!1;return}if(!g.current)if(g.current=!0,p.current&&e.length>0){const z=e.length-1;(D=(_=p.current).scrollToIndex)==null||D.call(_,{index:z,align:"end",behavior:"auto"})}else m.current&&(m.current.scrollTop=m.current.scrollHeight)},[T,e.length]),v.useImperativeHandle(c,()=>({scrollToLatest:()=>{var _,D;if(p.current&&e.length>0){const z=e.length-1;(D=(_=p.current).scrollToIndex)==null||D.call(_,{index:z,align:"end",behavior:"auto"})}else m.current&&(m.current.scrollTop=m.current.scrollHeight)},scrollToTop:()=>{var _,D;p.current&&e.length>0?(D=(_=p.current).scrollToIndex)==null||D.call(_,{index:0,align:"start",behavior:"auto"}):m.current&&(m.current.scrollTop=0)}}),[e]);const j=v.useCallback((_,D)=>_.role==="user"?d.jsx(qi,{message:_,messageIndex:D}):_.role==="system"?d.jsx(Gi,{message:_}):d.jsx(Ki,{message:_,messageIndex:D,isStreamingMessage:t&&D===e.length-1}),[t,e.length]);return d.jsx("div",{className:S,style:o,children:d.jsx("div",{className:"relative flex-1 min-h-0 min-w-0",children:N?d.jsx(Ib,{ref:_=>p.current=_,scrollerRef:_=>m.current=_ instanceof HTMLDivElement?_:null,data:e,followOutput:k,initialTopMostItemIndex:e.length>0?e.length-1:0,overscan:200,atBottomThreshold:50,startReached:()=>{y&&y()},atBottomStateChange:w,style:{height:"100%",width:"100%",overscrollBehavior:"contain"},computeItemKey:(_,D)=>D.id||_,itemContent:(_,D)=>l?l(D,_):j(D,_)}):C()})})});is.displayName="MessageList";function ye(e,t,{checkForDefaultPrevented:n=!0}={}){return function(o){if(e==null||e(o),n===!1||!o.defaultPrevented)return t==null?void 0:t(o)}}function dd(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Pn(...e){return t=>{let n=!1;const r=e.map(o=>{const s=dd(o,t);return!n&&typeof s=="function"&&(n=!0),s});if(n)return()=>{for(let o=0;o<r.length;o++){const s=r[o];typeof s=="function"?s():dd(e[o],null)}}}}function Xe(...e){return x.useCallback(Pn(...e),e)}function mw(e,t){const n=x.createContext(t),r=s=>{const{children:i,...a}=s,l=x.useMemo(()=>a,Object.values(a));return d.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=x.useContext(n);if(i)return i;if(t!==void 0)return t;throw new Error(`\`${s}\` must be used within \`${e}\``)}return[r,o]}function Rn(e,t=[]){let n=[];function r(s,i){const a=x.createContext(i),l=n.length;n=[...n,i];const c=f=>{var w;const{scope:h,children:p,...m}=f,b=((w=h==null?void 0:h[e])==null?void 0:w[l])||a,g=x.useMemo(()=>m,Object.values(m));return d.jsx(b.Provider,{value:g,children:p})};c.displayName=s+"Provider";function u(f,h){var b;const p=((b=h==null?void 0:h[e])==null?void 0:b[l])||a,m=x.useContext(p);if(m)return m;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[c,u]}const o=()=>{const s=n.map(i=>x.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return x.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,gw(o,...t)]}function gw(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const f=l(s)[`__scope${c}`];return{...a,...f}},{});return x.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var on=globalThis!=null&&globalThis.document?x.useLayoutEffect:()=>{},xw=x[" useInsertionEffect ".trim().toString()]||on;function as({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=bw({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const u=x.useRef(e!==void 0);x.useEffect(()=>{const f=u.current;f!==a&&console.warn(`${r} is changing from ${f?"controlled":"uncontrolled"} to ${a?"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=a},[a,r])}const c=x.useCallback(u=>{var f;if(a){const h=ww(u)?u(e):u;h!==e&&((f=i.current)==null||f.call(i,h))}else s(u)},[a,e,s,i]);return[l,c]}function bw({defaultProp:e,onChange:t}){const[n,r]=x.useState(e),o=x.useRef(n),s=x.useRef(t);return xw(()=>{s.current=t},[t]),x.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function ww(e){return typeof e=="function"}var yw=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ae=yw.reduce((e,t)=>{const n=lr.createSlot(`Primitive.${t}`),r=x.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),d.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function fd(e,t){e&&al.flushSync(()=>e.dispatchEvent(t))}function hd(e){const t=e+"CollectionProvider",[n,r]=Rn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=b=>{const{scope:g,children:w}=b,y=v.useRef(null),k=v.useRef(new Map).current;return d.jsx(o,{scope:g,itemMap:k,collectionRef:y,children:w})};i.displayName=t;const a=e+"CollectionSlot",l=lr.createSlot(a),c=v.forwardRef((b,g)=>{const{scope:w,children:y}=b,k=s(a,w),E=Xe(g,k.collectionRef);return d.jsx(l,{ref:E,children:y})});c.displayName=a;const u=e+"CollectionItemSlot",f="data-radix-collection-item",h=lr.createSlot(u),p=v.forwardRef((b,g)=>{const{scope:w,children:y,...k}=b,E=v.useRef(null),S=Xe(g,E),C=s(u,w);return v.useEffect(()=>(C.itemMap.set(E,{ref:E,...k}),()=>void C.itemMap.delete(E))),d.jsx(h,{[f]:"",ref:S,children:y})});p.displayName=u;function m(b){const g=s(e+"CollectionConsumer",b);return v.useCallback(()=>{const y=g.collectionRef.current;if(!y)return[];const k=Array.from(y.querySelectorAll(`[${f}]`));return Array.from(g.itemMap.values()).sort((C,T)=>k.indexOf(C.ref.current)-k.indexOf(T.ref.current))},[g.collectionRef,g.itemMap])}return[{Provider:i,Slot:c,ItemSlot:p},m,r]}var vw=x.createContext(void 0);function Yi(e){const t=x.useContext(vw);return e||t||"ltr"}function ft(e){const t=x.useRef(e);return x.useEffect(()=>{t.current=e}),x.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function Sw(e,t=globalThis==null?void 0:globalThis.document){const n=ft(e);x.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return t.addEventListener("keydown",r,{capture:!0}),()=>t.removeEventListener("keydown",r,{capture:!0})},[n,t])}var Cw="DismissableLayer",Xi="dismissableLayer.update",Tw="dismissableLayer.pointerDownOutside",kw="dismissableLayer.focusOutside",pd,md=x.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Ji=x.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=x.useContext(md),[u,f]=x.useState(null),h=(u==null?void 0:u.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=x.useState({}),m=Xe(t,T=>f(T)),b=Array.from(c.layers),[g]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),w=b.indexOf(g),y=u?b.indexOf(u):-1,k=c.layersWithOutsidePointerEventsDisabled.size>0,E=y>=w,S=Aw(T=>{const N=T.target,j=[...c.branches].some(_=>_.contains(N));!E||j||(o==null||o(T),i==null||i(T),T.defaultPrevented||a==null||a())},h),C=Nw(T=>{const N=T.target;[...c.branches].some(_=>_.contains(N))||(s==null||s(T),i==null||i(T),T.defaultPrevented||a==null||a())},h);return Sw(T=>{y===c.layers.size-1&&(r==null||r(T),!T.defaultPrevented&&a&&(T.preventDefault(),a()))},h),x.useEffect(()=>{if(u)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(pd=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(u)),c.layers.add(u),gd(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=pd)}},[u,h,n,c]),x.useEffect(()=>()=>{u&&(c.layers.delete(u),c.layersWithOutsidePointerEventsDisabled.delete(u),gd())},[u,c]),x.useEffect(()=>{const T=()=>p({});return document.addEventListener(Xi,T),()=>document.removeEventListener(Xi,T)},[]),d.jsx(Ae.div,{...l,ref:m,style:{pointerEvents:k?E?"auto":"none":void 0,...e.style},onFocusCapture:ye(e.onFocusCapture,C.onFocusCapture),onBlurCapture:ye(e.onBlurCapture,C.onBlurCapture),onPointerDownCapture:ye(e.onPointerDownCapture,S.onPointerDownCapture)})});Ji.displayName=Cw;var Ew="DismissableLayerBranch",Iw=x.forwardRef((e,t)=>{const n=x.useContext(md),r=x.useRef(null),o=Xe(t,r);return x.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),d.jsx(Ae.div,{...e,ref:o})});Iw.displayName=Ew;function Aw(e,t=globalThis==null?void 0:globalThis.document){const n=ft(e),r=x.useRef(!1),o=x.useRef(()=>{});return x.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){xd(Tw,n,c,{discrete:!0})};const c={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function Nw(e,t=globalThis==null?void 0:globalThis.document){const n=ft(e),r=x.useRef(!1);return x.useEffect(()=>{const o=s=>{s.target&&!r.current&&xd(kw,n,{originalEvent:s},{discrete:!1})};return t.addEventListener("focusin",o),()=>t.removeEventListener("focusin",o)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function gd(){const e=new CustomEvent(Xi);document.dispatchEvent(e)}function xd(e,t,n,{discrete:r}){const o=n.originalEvent.target,s=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&o.addEventListener(e,t,{once:!0}),r?fd(o,s):o.dispatchEvent(s)}var Zi=0;function bd(){x.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??wd()),document.body.insertAdjacentElement("beforeend",e[1]??wd()),Zi++,()=>{Zi===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),Zi--}},[])}function wd(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}var Qi="focusScope.autoFocusOnMount",ea="focusScope.autoFocusOnUnmount",yd={bubbles:!1,cancelable:!0},jw="FocusScope",ta=x.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=x.useState(null),c=ft(o),u=ft(s),f=x.useRef(null),h=Xe(t,b=>l(b)),p=x.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;x.useEffect(()=>{if(r){let b=function(k){if(p.paused||!a)return;const E=k.target;a.contains(E)?f.current=E:On(f.current,{select:!0})},g=function(k){if(p.paused||!a)return;const E=k.relatedTarget;E!==null&&(a.contains(E)||On(f.current,{select:!0}))},w=function(k){if(document.activeElement===document.body)for(const S of k)S.removedNodes.length>0&&On(a)};document.addEventListener("focusin",b),document.addEventListener("focusout",g);const y=new MutationObserver(w);return a&&y.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",b),document.removeEventListener("focusout",g),y.disconnect()}}},[r,a,p.paused]),x.useEffect(()=>{if(a){Cd.add(p);const b=document.activeElement;if(!a.contains(b)){const w=new CustomEvent(Qi,yd);a.addEventListener(Qi,c),a.dispatchEvent(w),w.defaultPrevented||(_w(Dw(vd(a)),{select:!0}),document.activeElement===b&&On(a))}return()=>{a.removeEventListener(Qi,c),setTimeout(()=>{const w=new CustomEvent(ea,yd);a.addEventListener(ea,u),a.dispatchEvent(w),w.defaultPrevented||On(b??document.body,{select:!0}),a.removeEventListener(ea,u),Cd.remove(p)},0)}}},[a,c,u,p]);const m=x.useCallback(b=>{if(!n&&!r||p.paused)return;const g=b.key==="Tab"&&!b.altKey&&!b.ctrlKey&&!b.metaKey,w=document.activeElement;if(g&&w){const y=b.currentTarget,[k,E]=Pw(y);k&&E?!b.shiftKey&&w===E?(b.preventDefault(),n&&On(k,{select:!0})):b.shiftKey&&w===k&&(b.preventDefault(),n&&On(E,{select:!0})):w===y&&b.preventDefault()}},[n,r,p.paused]);return d.jsx(Ae.div,{tabIndex:-1,...i,ref:h,onKeyDown:m})});ta.displayName=jw;function _w(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(On(r,{select:t}),document.activeElement!==n)return}function Pw(e){const t=vd(e),n=Sd(t,e),r=Sd(t.reverse(),e);return[n,r]}function vd(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function Sd(e,t){for(const n of e)if(!Rw(n,{upTo:t}))return n}function Rw(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function Ow(e){return e instanceof HTMLInputElement&&"select"in e}function On(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Ow(e)&&t&&e.select()}}var Cd=Mw();function Mw(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Td(e,t),e.unshift(t)},remove(t){var n;e=Td(e,t),(n=e[0])==null||n.resume()}}}function Td(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function Dw(e){return e.filter(t=>t.tagName!=="A")}var Lw=x[" useId ".trim().toString()]||(()=>{}),$w=0;function Rt(e){const[t,n]=x.useState(Lw());return on(()=>{n(r=>r??String($w++))},[e]),e||(t?`radix-${t}`:"")}const Fw=["top","right","bottom","left"],Mn=Math.min,Ot=Math.max,ls=Math.round,cs=Math.floor,sn=e=>({x:e,y:e}),zw={left:"right",right:"left",bottom:"top",top:"bottom"},Bw={start:"end",end:"start"};function na(e,t,n){return Ot(e,Mn(t,n))}function xn(e,t){return typeof e=="function"?e(t):e}function bn(e){return e.split("-")[0]}function vr(e){return e.split("-")[1]}function ra(e){return e==="x"?"y":"x"}function oa(e){return e==="y"?"height":"width"}const Uw=new Set(["top","bottom"]);function an(e){return Uw.has(bn(e))?"y":"x"}function sa(e){return ra(an(e))}function Hw(e,t,n){n===void 0&&(n=!1);const r=vr(e),o=sa(e),s=oa(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=us(i)),[i,us(i)]}function Ww(e){const t=us(e);return[ia(e),t,ia(t)]}function ia(e){return e.replace(/start|end/g,t=>Bw[t])}const kd=["left","right"],Ed=["right","left"],Vw=["top","bottom"],Kw=["bottom","top"];function qw(e,t,n){switch(e){case"top":case"bottom":return n?t?Ed:kd:t?kd:Ed;case"left":case"right":return t?Vw:Kw;default:return[]}}function Gw(e,t,n,r){const o=vr(e);let s=qw(bn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(ia)))),s}function us(e){return e.replace(/left|right|bottom|top/g,t=>zw[t])}function Yw(e){return{top:0,right:0,bottom:0,left:0,...e}}function Id(e){return typeof e!="number"?Yw(e):{top:e,right:e,bottom:e,left:e}}function ds(e){const{x:t,y:n,width:r,height:o}=e;return{width:r,height:o,top:n,left:t,right:t+r,bottom:n+o,x:t,y:n}}function Ad(e,t,n){let{reference:r,floating:o}=e;const s=an(t),i=sa(t),a=oa(i),l=bn(t),c=s==="y",u=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,h=r[a]/2-o[a]/2;let p;switch(l){case"top":p={x:u,y:r.y-o.height};break;case"bottom":p={x:u,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:f};break;case"left":p={x:r.x-o.width,y:f};break;default:p={x:r.x,y:r.y}}switch(vr(t)){case"start":p[i]-=h*(n&&c?-1:1);break;case"end":p[i]+=h*(n&&c?-1:1);break}return p}const Xw=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let c=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:u,y:f}=Ad(c,r,l),h=r,p={},m=0;for(let b=0;b<a.length;b++){const{name:g,fn:w}=a[b],{x:y,y:k,data:E,reset:S}=await w({x:u,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:c,platform:i,elements:{reference:e,floating:t}});u=y??u,f=k??f,p={...p,[g]:{...p[g],...E}},S&&m<=50&&(m++,typeof S=="object"&&(S.placement&&(h=S.placement),S.rects&&(c=S.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):S.rects),{x:u,y:f}=Ad(c,h,l)),b=-1)}return{x:u,y:f,placement:h,strategy:o,middlewareData:p}};async function ao(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:c="clippingAncestors",rootBoundary:u="viewport",elementContext:f="floating",altBoundary:h=!1,padding:p=0}=xn(t,e),m=Id(p),g=a[h?f==="floating"?"reference":"floating":f],w=ds(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(g)))==null||n?g:g.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:u,strategy:l})),y=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,k=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),E=await(s.isElement==null?void 0:s.isElement(k))?await(s.getScale==null?void 0:s.getScale(k))||{x:1,y:1}:{x:1,y:1},S=ds(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:y,offsetParent:k,strategy:l}):y);return{top:(w.top-S.top+m.top)/E.y,bottom:(S.bottom-w.bottom+m.bottom)/E.y,left:(w.left-S.left+m.left)/E.x,right:(S.right-w.right+m.right)/E.x}}const Jw=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:c,padding:u=0}=xn(e,t)||{};if(c==null)return{};const f=Id(u),h={x:n,y:r},p=sa(o),m=oa(p),b=await i.getDimensions(c),g=p==="y",w=g?"top":"left",y=g?"bottom":"right",k=g?"clientHeight":"clientWidth",E=s.reference[m]+s.reference[p]-h[p]-s.floating[m],S=h[p]-s.reference[p],C=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let T=C?C[k]:0;(!T||!await(i.isElement==null?void 0:i.isElement(C)))&&(T=a.floating[k]||s.floating[m]);const N=E/2-S/2,j=T/2-b[m]/2-1,_=Mn(f[w],j),D=Mn(f[y],j),z=_,H=T-b[m]-D,P=T/2-b[m]/2+N,M=na(z,P,H),F=!l.arrow&&vr(o)!=null&&P!==M&&s.reference[m]/2-(P<z?_:D)-b[m]/2<0,ne=F?P<z?P-z:P-H:0;return{[p]:h[p]+ne,data:{[p]:M,centerOffset:P-M-ne,...F&&{alignmentOffset:ne}},reset:F}}}),Zw=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:c}=t,{mainAxis:u=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:b=!0,...g}=xn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const w=bn(o),y=an(a),k=bn(a)===a,E=await(l.isRTL==null?void 0:l.isRTL(c.floating)),S=h||(k||!b?[us(a)]:Ww(a)),C=m!=="none";!h&&C&&S.push(...Gw(a,b,m,E));const T=[a,...S],N=await ao(t,g),j=[];let _=((r=s.flip)==null?void 0:r.overflows)||[];if(u&&j.push(N[w]),f){const P=Hw(o,i,E);j.push(N[P[0]],N[P[1]])}if(_=[..._,{placement:o,overflows:j}],!j.every(P=>P<=0)){var D,z;const P=(((D=s.flip)==null?void 0:D.index)||0)+1,M=T[P];if(M&&(!(f==="alignment"?y!==an(M):!1)||_.every(U=>an(U.placement)===y?U.overflows[0]>0:!0)))return{data:{index:P,overflows:_},reset:{placement:M}};let F=(z=_.filter(ne=>ne.overflows[0]<=0).sort((ne,U)=>ne.overflows[1]-U.overflows[1])[0])==null?void 0:z.placement;if(!F)switch(p){case"bestFit":{var H;const ne=(H=_.filter(U=>{if(C){const W=an(U.placement);return W===y||W==="y"}return!0}).map(U=>[U.placement,U.overflows.filter(W=>W>0).reduce((W,Y)=>W+Y,0)]).sort((U,W)=>U[1]-W[1])[0])==null?void 0:H[0];ne&&(F=ne);break}case"initialPlacement":F=a;break}if(o!==F)return{reset:{placement:F}}}return{}}}};function Nd(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function jd(e){return Fw.some(t=>e[t]>=0)}const Qw=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=xn(e,t);switch(r){case"referenceHidden":{const s=await ao(t,{...o,elementContext:"reference"}),i=Nd(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:jd(i)}}}case"escaped":{const s=await ao(t,{...o,altBoundary:!0}),i=Nd(s,n.floating);return{data:{escapedOffsets:i,escaped:jd(i)}}}default:return{}}}}},_d=new Set(["left","top"]);async function ey(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=bn(n),a=vr(n),l=an(n)==="y",c=_d.has(i)?-1:1,u=s&&l?-1:1,f=xn(t,e);let{mainAxis:h,crossAxis:p,alignmentAxis:m}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof m=="number"&&(p=a==="end"?m*-1:m),l?{x:p*u,y:h*c}:{x:h*c,y:p*u}}const ty=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var n,r;const{x:o,y:s,placement:i,middlewareData:a}=t,l=await ey(t,e);return i===((n=a.offset)==null?void 0:n.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:o+l.x,y:s+l.y,data:{...l,placement:i}}}}},ny=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:g=>{let{x:w,y}=g;return{x:w,y}}},...l}=xn(e,t),c={x:n,y:r},u=await ao(t,l),f=an(bn(o)),h=ra(f);let p=c[h],m=c[f];if(s){const g=h==="y"?"top":"left",w=h==="y"?"bottom":"right",y=p+u[g],k=p-u[w];p=na(y,p,k)}if(i){const g=f==="y"?"top":"left",w=f==="y"?"bottom":"right",y=m+u[g],k=m-u[w];m=na(y,m,k)}const b=a.fn({...t,[h]:p,[f]:m});return{...b,data:{x:b.x-n,y:b.y-r,enabled:{[h]:s,[f]:i}}}}}},ry=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=xn(e,t),u={x:n,y:r},f=an(o),h=ra(f);let p=u[h],m=u[f];const b=xn(a,t),g=typeof b=="number"?{mainAxis:b,crossAxis:0}:{mainAxis:0,crossAxis:0,...b};if(l){const k=h==="y"?"height":"width",E=s.reference[h]-s.floating[k]+g.mainAxis,S=s.reference[h]+s.reference[k]-g.mainAxis;p<E?p=E:p>S&&(p=S)}if(c){var w,y;const k=h==="y"?"width":"height",E=_d.has(bn(o)),S=s.reference[f]-s.floating[k]+(E&&((w=i.offset)==null?void 0:w[f])||0)+(E?0:g.crossAxis),C=s.reference[f]+s.reference[k]+(E?0:((y=i.offset)==null?void 0:y[f])||0)-(E?g.crossAxis:0);m<S?m=S:m>C&&(m=C)}return{[h]:p,[f]:m}}}},oy=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:o,rects:s,platform:i,elements:a}=t,{apply:l=()=>{},...c}=xn(e,t),u=await ao(t,c),f=bn(o),h=vr(o),p=an(o)==="y",{width:m,height:b}=s.floating;let g,w;f==="top"||f==="bottom"?(g=f,w=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(w=f,g=h==="end"?"top":"bottom");const y=b-u.top-u.bottom,k=m-u.left-u.right,E=Mn(b-u[g],y),S=Mn(m-u[w],k),C=!t.middlewareData.shift;let T=E,N=S;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(N=k),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(T=y),C&&!h){const _=Ot(u.left,0),D=Ot(u.right,0),z=Ot(u.top,0),H=Ot(u.bottom,0);p?N=m-2*(_!==0||D!==0?_+D:Ot(u.left,u.right)):T=b-2*(z!==0||H!==0?z+H:Ot(u.top,u.bottom))}await l({...t,availableWidth:N,availableHeight:T});const j=await i.getDimensions(a.floating);return m!==j.width||b!==j.height?{reset:{rects:!0}}:{}}}};function fs(){return typeof window<"u"}function Sr(e){return Pd(e)?(e.nodeName||"").toLowerCase():"#document"}function Mt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function ln(e){var t;return(t=(Pd(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function Pd(e){return fs()?e instanceof Node||e instanceof Mt(e).Node:!1}function Xt(e){return fs()?e instanceof Element||e instanceof Mt(e).Element:!1}function cn(e){return fs()?e instanceof HTMLElement||e instanceof Mt(e).HTMLElement:!1}function Rd(e){return!fs()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Mt(e).ShadowRoot}const sy=new Set(["inline","contents"]);function lo(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=Jt(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!sy.has(o)}const iy=new Set(["table","td","th"]);function ay(e){return iy.has(Sr(e))}const ly=[":popover-open",":modal"];function hs(e){return ly.some(t=>{try{return e.matches(t)}catch{return!1}})}const cy=["transform","translate","scale","rotate","perspective"],uy=["transform","translate","scale","rotate","perspective","filter"],dy=["paint","layout","strict","content"];function aa(e){const t=la(),n=Xt(e)?Jt(e):e;return cy.some(r=>n[r]?n[r]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!t&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!t&&(n.filter?n.filter!=="none":!1)||uy.some(r=>(n.willChange||"").includes(r))||dy.some(r=>(n.contain||"").includes(r))}function fy(e){let t=Dn(e);for(;cn(t)&&!Cr(t);){if(aa(t))return t;if(hs(t))return null;t=Dn(t)}return null}function la(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const hy=new Set(["html","body","#document"]);function Cr(e){return hy.has(Sr(e))}function Jt(e){return Mt(e).getComputedStyle(e)}function ps(e){return Xt(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Dn(e){if(Sr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||Rd(e)&&e.host||ln(e);return Rd(t)?t.host:t}function Od(e){const t=Dn(e);return Cr(t)?e.ownerDocument?e.ownerDocument.body:e.body:cn(t)&&lo(t)?t:Od(t)}function co(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Od(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Mt(o);if(s){const a=ca(i);return t.concat(i,i.visualViewport||[],lo(o)?o:[],a&&n?co(a):[])}return t.concat(o,co(o,[],n))}function ca(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Md(e){const t=Jt(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=cn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=ls(n)!==s||ls(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function ua(e){return Xt(e)?e:e.contextElement}function Tr(e){const t=ua(e);if(!cn(t))return sn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Md(t);let i=(s?ls(n.width):n.width)/r,a=(s?ls(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const py=sn(0);function Dd(e){const t=Mt(e);return!la()||!t.visualViewport?py:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function my(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Mt(e)?!1:t}function Zn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=ua(e);let i=sn(1);t&&(r?Xt(r)&&(i=Tr(r)):i=Tr(e));const a=my(s,n,r)?Dd(s):sn(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,u=o.width/i.x,f=o.height/i.y;if(s){const h=Mt(s),p=r&&Xt(r)?Mt(r):r;let m=h,b=ca(m);for(;b&&r&&p!==m;){const g=Tr(b),w=b.getBoundingClientRect(),y=Jt(b),k=w.left+(b.clientLeft+parseFloat(y.paddingLeft))*g.x,E=w.top+(b.clientTop+parseFloat(y.paddingTop))*g.y;l*=g.x,c*=g.y,u*=g.x,f*=g.y,l+=k,c+=E,m=Mt(b),b=ca(m)}}return ds({width:u,height:f,x:l,y:c})}function ms(e,t){const n=ps(e).scrollLeft;return t?t.left+n:Zn(ln(e)).left+n}function Ld(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-ms(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function gy(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=ln(r),a=t?hs(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=sn(1);const u=sn(0),f=cn(r);if((f||!f&&!s)&&((Sr(r)!=="body"||lo(i))&&(l=ps(r)),cn(r))){const p=Zn(r);c=Tr(r),u.x=p.x+r.clientLeft,u.y=p.y+r.clientTop}const h=i&&!f&&!s?Ld(i,l):sn(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+u.x+h.x,y:n.y*c.y-l.scrollTop*c.y+u.y+h.y}}function xy(e){return Array.from(e.getClientRects())}function by(e){const t=ln(e),n=ps(e),r=e.ownerDocument.body,o=Ot(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Ot(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+ms(e);const a=-n.scrollTop;return Jt(r).direction==="rtl"&&(i+=Ot(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const $d=25;function wy(e,t){const n=Mt(e),r=ln(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const u=la();(!u||u&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const c=ms(r);if(c<=0){const u=r.ownerDocument,f=u.body,h=getComputedStyle(f),p=u.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,m=Math.abs(r.clientWidth-f.clientWidth-p);m<=$d&&(s-=m)}else c<=$d&&(s+=c);return{width:s,height:i,x:a,y:l}}const yy=new Set(["absolute","fixed"]);function vy(e,t){const n=Zn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=cn(e)?Tr(e):sn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,c=r*s.y;return{width:i,height:a,x:l,y:c}}function Fd(e,t,n){let r;if(t==="viewport")r=wy(e,n);else if(t==="document")r=by(ln(e));else if(Xt(t))r=vy(t,n);else{const o=Dd(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return ds(r)}function zd(e,t){const n=Dn(e);return n===t||!Xt(n)||Cr(n)?!1:Jt(n).position==="fixed"||zd(n,t)}function Sy(e,t){const n=t.get(e);if(n)return n;let r=co(e,[],!1).filter(a=>Xt(a)&&Sr(a)!=="body"),o=null;const s=Jt(e).position==="fixed";let i=s?Dn(e):e;for(;Xt(i)&&!Cr(i);){const a=Jt(i),l=aa(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&yy.has(o.position)||lo(i)&&!l&&zd(e,i))?r=r.filter(u=>u!==i):o=a,i=Dn(i)}return t.set(e,r),r}function Cy(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?hs(t)?[]:Sy(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,u)=>{const f=Fd(t,u,o);return c.top=Ot(f.top,c.top),c.right=Mn(f.right,c.right),c.bottom=Mn(f.bottom,c.bottom),c.left=Ot(f.left,c.left),c},Fd(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function Ty(e){const{width:t,height:n}=Md(e);return{width:t,height:n}}function ky(e,t,n){const r=cn(t),o=ln(t),s=n==="fixed",i=Zn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=sn(0);function c(){l.x=ms(o)}if(r||!r&&!s)if((Sr(t)!=="body"||lo(o))&&(a=ps(t)),r){const p=Zn(t,!0,s,t);l.x=p.x+t.clientLeft,l.y=p.y+t.clientTop}else o&&c();s&&!r&&o&&c();const u=o&&!r&&!s?Ld(o,a):sn(0),f=i.left+a.scrollLeft-l.x-u.x,h=i.top+a.scrollTop-l.y-u.y;return{x:f,y:h,width:i.width,height:i.height}}function da(e){return Jt(e).position==="static"}function Bd(e,t){if(!cn(e)||Jt(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return ln(e)===n&&(n=n.ownerDocument.body),n}function Ud(e,t){const n=Mt(e);if(hs(e))return n;if(!cn(e)){let o=Dn(e);for(;o&&!Cr(o);){if(Xt(o)&&!da(o))return o;o=Dn(o)}return n}let r=Bd(e,t);for(;r&&ay(r)&&da(r);)r=Bd(r,t);return r&&Cr(r)&&da(r)&&!aa(r)?n:r||fy(e)||n}const Ey=async function(e){const t=this.getOffsetParent||Ud,n=this.getDimensions,r=await n(e.floating);return{reference:ky(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Iy(e){return Jt(e).direction==="rtl"}const Ay={convertOffsetParentRelativeRectToViewportRelativeRect:gy,getDocumentElement:ln,getClippingRect:Cy,getOffsetParent:Ud,getElementRects:Ey,getClientRects:xy,getDimensions:Ty,getScale:Tr,isElement:Xt,isRTL:Iy};function Hd(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function Ny(e,t){let n=null,r;const o=ln(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const c=e.getBoundingClientRect(),{left:u,top:f,width:h,height:p}=c;if(a||t(),!h||!p)return;const m=cs(f),b=cs(o.clientWidth-(u+h)),g=cs(o.clientHeight-(f+p)),w=cs(u),k={rootMargin:-m+"px "+-b+"px "+-g+"px "+-w+"px",threshold:Ot(0,Mn(1,l))||1};let E=!0;function S(C){const T=C[0].intersectionRatio;if(T!==l){if(!E)return i();T?i(!1,T):r=setTimeout(()=>{i(!1,1e-7)},1e3)}T===1&&!Hd(c,e.getBoundingClientRect())&&i(),E=!1}try{n=new IntersectionObserver(S,{...k,root:o.ownerDocument})}catch{n=new IntersectionObserver(S,k)}n.observe(e)}return i(!0),s}function jy(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=ua(e),u=o||s?[...c?co(c):[],...co(t)]:[];u.forEach(w=>{o&&w.addEventListener("scroll",n,{passive:!0}),s&&w.addEventListener("resize",n)});const f=c&&a?Ny(c,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(w=>{let[y]=w;y&&y.target===c&&p&&(p.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var k;(k=p)==null||k.observe(t)})),n()}),c&&!l&&p.observe(c),p.observe(t));let m,b=l?Zn(e):null;l&&g();function g(){const w=Zn(e);b&&!Hd(b,w)&&n(),b=w,m=requestAnimationFrame(g)}return n(),()=>{var w;u.forEach(y=>{o&&y.removeEventListener("scroll",n),s&&y.removeEventListener("resize",n)}),f==null||f(),(w=p)==null||w.disconnect(),p=null,l&&cancelAnimationFrame(m)}}const _y=ty,Py=ny,Ry=Zw,Oy=oy,My=Qw,Wd=Jw,Dy=ry,Ly=(e,t,n)=>{const r=new Map,o={platform:Ay,...n},s={...o.platform,_c:r};return Xw(e,t,{...o,platform:s})};var $y=typeof document<"u",Fy=function(){},gs=$y?v.useLayoutEffect:Fy;function xs(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,o;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!xs(e[r],t[r]))return!1;return!0}if(o=Object.keys(e),n=o.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,o[r]))return!1;for(r=n;r--!==0;){const s=o[r];if(!(s==="_owner"&&e.$$typeof)&&!xs(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Vd(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Kd(e,t){const n=Vd(e);return Math.round(t*n)/n}function fa(e){const t=x.useRef(e);return gs(()=>{t.current=e}),t}function zy(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=e,[u,f]=x.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[h,p]=x.useState(r);xs(h,r)||p(r);const[m,b]=x.useState(null),[g,w]=x.useState(null),y=x.useCallback(U=>{U!==C.current&&(C.current=U,b(U))},[]),k=x.useCallback(U=>{U!==T.current&&(T.current=U,w(U))},[]),E=s||m,S=i||g,C=x.useRef(null),T=x.useRef(null),N=x.useRef(u),j=l!=null,_=fa(l),D=fa(o),z=fa(c),H=x.useCallback(()=>{if(!C.current||!T.current)return;const U={placement:t,strategy:n,middleware:h};D.current&&(U.platform=D.current),Ly(C.current,T.current,U).then(W=>{const Y={...W,isPositioned:z.current!==!1};P.current&&!xs(N.current,Y)&&(N.current=Y,al.flushSync(()=>{f(Y)}))})},[h,t,n,D,z]);gs(()=>{c===!1&&N.current.isPositioned&&(N.current.isPositioned=!1,f(U=>({...U,isPositioned:!1})))},[c]);const P=x.useRef(!1);gs(()=>(P.current=!0,()=>{P.current=!1}),[]),gs(()=>{if(E&&(C.current=E),S&&(T.current=S),E&&S){if(_.current)return _.current(E,S,H);H()}},[E,S,H,_,j]);const M=x.useMemo(()=>({reference:C,floating:T,setReference:y,setFloating:k}),[y,k]),F=x.useMemo(()=>({reference:E,floating:S}),[E,S]),ne=x.useMemo(()=>{const U={position:n,left:0,top:0};if(!F.floating)return U;const W=Kd(F.floating,u.x),Y=Kd(F.floating,u.y);return a?{...U,transform:"translate("+W+"px, "+Y+"px)",...Vd(F.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:W,top:Y}},[n,a,F.floating,u.x,u.y]);return x.useMemo(()=>({...u,update:H,refs:M,elements:F,floatingStyles:ne}),[u,H,M,F,ne])}const By=e=>{function t(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:e,fn(n){const{element:r,padding:o}=typeof e=="function"?e(n):e;return r&&t(r)?r.current!=null?Wd({element:r.current,padding:o}).fn(n):{}:r?Wd({element:r,padding:o}).fn(n):{}}}},Uy=(e,t)=>({..._y(e),options:[e,t]}),Hy=(e,t)=>({...Py(e),options:[e,t]}),Wy=(e,t)=>({...Dy(e),options:[e,t]}),Vy=(e,t)=>({...Ry(e),options:[e,t]}),Ky=(e,t)=>({...Oy(e),options:[e,t]}),qy=(e,t)=>({...My(e),options:[e,t]}),Gy=(e,t)=>({...By(e),options:[e,t]});var Yy="Arrow",qd=x.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return d.jsx(Ae.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:d.jsx("polygon",{points:"0,0 30,0 15,10"})})});qd.displayName=Yy;var Xy=qd;function Jy(e){const[t,n]=x.useState(void 0);return on(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=e.offsetWidth,a=e.offsetHeight;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}var ha="Popper",[Gd,Yd]=Rn(ha),[Zy,Xd]=Gd(ha),Jd=e=>{const{__scopePopper:t,children:n}=e,[r,o]=x.useState(null);return d.jsx(Zy,{scope:t,anchor:r,onAnchorChange:o,children:n})};Jd.displayName=ha;var Zd="PopperAnchor",Qd=x.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Xd(Zd,n),i=x.useRef(null),a=Xe(t,i),l=x.useRef(null);return x.useEffect(()=>{const c=l.current;l.current=(r==null?void 0:r.current)||i.current,c!==l.current&&s.onAnchorChange(l.current)}),r?null:d.jsx(Ae.div,{...o,ref:a})});Qd.displayName=Zd;var pa="PopperContent",[Qy,ev]=Gd(pa),ef=x.forwardRef((e,t)=>{var Z,$,X,oe,ue,le;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:u=0,sticky:f="partial",hideWhenDetached:h=!1,updatePositionStrategy:p="optimized",onPlaced:m,...b}=e,g=Xd(pa,n),[w,y]=x.useState(null),k=Xe(t,Ce=>y(Ce)),[E,S]=x.useState(null),C=Jy(E),T=(C==null?void 0:C.width)??0,N=(C==null?void 0:C.height)??0,j=r+(s!=="center"?"-"+s:""),_=typeof u=="number"?u:{top:0,right:0,bottom:0,left:0,...u},D=Array.isArray(c)?c:[c],z=D.length>0,H={padding:_,boundary:D.filter(nv),altBoundary:z},{refs:P,floatingStyles:M,placement:F,isPositioned:ne,middlewareData:U}=zy({strategy:"fixed",placement:j,whileElementsMounted:(...Ce)=>jy(...Ce,{animationFrame:p==="always"}),elements:{reference:g.anchor},middleware:[Uy({mainAxis:o+N,alignmentAxis:i}),l&&Hy({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?Wy():void 0,...H}),l&&Vy({...H}),Ky({...H,apply:({elements:Ce,rects:De,availableWidth:Ie,availableHeight:qe})=>{const{width:We,height:Fe}=De.reference,ze=Ce.floating.style;ze.setProperty("--radix-popper-available-width",`${Ie}px`),ze.setProperty("--radix-popper-available-height",`${qe}px`),ze.setProperty("--radix-popper-anchor-width",`${We}px`),ze.setProperty("--radix-popper-anchor-height",`${Fe}px`)}}),E&&Gy({element:E,padding:a}),rv({arrowWidth:T,arrowHeight:N}),h&&qy({strategy:"referenceHidden",...H})]}),[W,Y]=rf(F),q=ft(m);on(()=>{ne&&(q==null||q())},[ne,q]);const R=(Z=U.arrow)==null?void 0:Z.x,G=($=U.arrow)==null?void 0:$.y,A=((X=U.arrow)==null?void 0:X.centerOffset)!==0,[O,V]=x.useState();return on(()=>{w&&V(window.getComputedStyle(w).zIndex)},[w]),d.jsx("div",{ref:P.setFloating,"data-radix-popper-content-wrapper":"",style:{...M,transform:ne?M.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:O,"--radix-popper-transform-origin":[(oe=U.transformOrigin)==null?void 0:oe.x,(ue=U.transformOrigin)==null?void 0:ue.y].join(" "),...((le=U.hide)==null?void 0:le.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:d.jsx(Qy,{scope:n,placedSide:W,onArrowChange:S,arrowX:R,arrowY:G,shouldHideArrow:A,children:d.jsx(Ae.div,{"data-side":W,"data-align":Y,...b,ref:k,style:{...b.style,animation:ne?void 0:"none"}})})})});ef.displayName=pa;var tf="PopperArrow",tv={top:"bottom",right:"left",bottom:"top",left:"right"},nf=x.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=ev(tf,r),i=tv[s.placedSide];return d.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:d.jsx(Xy,{...o,ref:n,style:{...o.style,display:"block"}})})});nf.displayName=tf;function nv(e){return e!==null}var rv=e=>({name:"transformOrigin",options:e,fn(t){var g,w,y;const{placement:n,rects:r,middlewareData:o}=t,i=((g=o.arrow)==null?void 0:g.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[c,u]=rf(n),f={start:"0%",center:"50%",end:"100%"}[u],h=(((w=o.arrow)==null?void 0:w.x)??0)+a/2,p=(((y=o.arrow)==null?void 0:y.y)??0)+l/2;let m="",b="";return c==="bottom"?(m=i?f:`${h}px`,b=`${-l}px`):c==="top"?(m=i?f:`${h}px`,b=`${r.floating.height+l}px`):c==="right"?(m=`${-l}px`,b=i?f:`${p}px`):c==="left"&&(m=`${r.floating.width+l}px`,b=i?f:`${p}px`),{data:{x:m,y:b}}}});function rf(e){const[t,n="center"]=e.split("-");return[t,n]}var ov=Jd,sv=Qd,iv=ef,av=nf,lv="Portal",ma=x.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=x.useState(!1);on(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Ws.createPortal(d.jsx(Ae.div,{...r,ref:t}),i):null});ma.displayName=lv;function cv(e,t){return x.useReducer((n,r)=>t[n][r]??n,e)}var Dt=e=>{const{present:t,children:n}=e,r=uv(t),o=typeof n=="function"?n({present:r.isPresent}):x.Children.only(n),s=Xe(r.ref,dv(o));return typeof n=="function"||r.isPresent?x.cloneElement(o,{ref:s}):null};Dt.displayName="Presence";function uv(e){const[t,n]=x.useState(),r=x.useRef(null),o=x.useRef(e),s=x.useRef("none"),i=e?"mounted":"unmounted",[a,l]=cv(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return x.useEffect(()=>{const c=bs(r.current);s.current=a==="mounted"?c:"none"},[a]),on(()=>{const c=r.current,u=o.current;if(u!==e){const h=s.current,p=bs(c);e?l("MOUNT"):p==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(u&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),on(()=>{if(t){let c;const u=t.ownerDocument.defaultView??window,f=p=>{const b=bs(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&b&&(l("ANIMATION_END"),!o.current)){const g=t.style.animationFillMode;t.style.animationFillMode="forwards",c=u.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=g)})}},h=p=>{p.target===t&&(s.current=bs(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{u.clearTimeout(c),t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:x.useCallback(c=>{r.current=c?getComputedStyle(c):null,n(c)},[])}}function bs(e){return(e==null?void 0:e.animationName)||"none"}function dv(e){var r,o;let t=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,n=t&&"isReactWarning"in t&&t.isReactWarning;return n?e.ref:(t=(o=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:o.get,n=t&&"isReactWarning"in t&&t.isReactWarning,n?e.props.ref:e.props.ref||e.ref)}var ga="rovingFocusGroup.onEntryFocus",fv={bubbles:!1,cancelable:!0},uo="RovingFocusGroup",[xa,of,hv]=hd(uo),[pv,sf]=Rn(uo,[hv]),[mv,gv]=pv(uo),af=x.forwardRef((e,t)=>d.jsx(xa.Provider,{scope:e.__scopeRovingFocusGroup,children:d.jsx(xa.Slot,{scope:e.__scopeRovingFocusGroup,children:d.jsx(xv,{...e,ref:t})})}));af.displayName=uo;var xv=x.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:u=!1,...f}=e,h=x.useRef(null),p=Xe(t,h),m=Yi(s),[b,g]=as({prop:i,defaultProp:a??null,onChange:l,caller:uo}),[w,y]=x.useState(!1),k=ft(c),E=of(n),S=x.useRef(!1),[C,T]=x.useState(0);return x.useEffect(()=>{const N=h.current;if(N)return N.addEventListener(ga,k),()=>N.removeEventListener(ga,k)},[k]),d.jsx(mv,{scope:n,orientation:r,dir:m,loop:o,currentTabStopId:b,onItemFocus:x.useCallback(N=>g(N),[g]),onItemShiftTab:x.useCallback(()=>y(!0),[]),onFocusableItemAdd:x.useCallback(()=>T(N=>N+1),[]),onFocusableItemRemove:x.useCallback(()=>T(N=>N-1),[]),children:d.jsx(Ae.div,{tabIndex:w||C===0?-1:0,"data-orientation":r,...f,ref:p,style:{outline:"none",...e.style},onMouseDown:ye(e.onMouseDown,()=>{S.current=!0}),onFocus:ye(e.onFocus,N=>{const j=!S.current;if(N.target===N.currentTarget&&j&&!w){const _=new CustomEvent(ga,fv);if(N.currentTarget.dispatchEvent(_),!_.defaultPrevented){const D=E().filter(F=>F.focusable),z=D.find(F=>F.active),H=D.find(F=>F.id===b),M=[z,H,...D].filter(Boolean).map(F=>F.ref.current);uf(M,u)}}S.current=!1}),onBlur:ye(e.onBlur,()=>y(!1))})})}),lf="RovingFocusGroupItem",cf=x.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=Rt(),c=s||l,u=gv(lf,n),f=u.currentTabStopId===c,h=of(n),{onFocusableItemAdd:p,onFocusableItemRemove:m,currentTabStopId:b}=u;return x.useEffect(()=>{if(r)return p(),()=>m()},[r,p,m]),d.jsx(xa.ItemSlot,{scope:n,id:c,focusable:r,active:o,children:d.jsx(Ae.span,{tabIndex:f?0:-1,"data-orientation":u.orientation,...a,ref:t,onMouseDown:ye(e.onMouseDown,g=>{r?u.onItemFocus(c):g.preventDefault()}),onFocus:ye(e.onFocus,()=>u.onItemFocus(c)),onKeyDown:ye(e.onKeyDown,g=>{if(g.key==="Tab"&&g.shiftKey){u.onItemShiftTab();return}if(g.target!==g.currentTarget)return;const w=yv(g,u.orientation,u.dir);if(w!==void 0){if(g.metaKey||g.ctrlKey||g.altKey||g.shiftKey)return;g.preventDefault();let k=h().filter(E=>E.focusable).map(E=>E.ref.current);if(w==="last")k.reverse();else if(w==="prev"||w==="next"){w==="prev"&&k.reverse();const E=k.indexOf(g.currentTarget);k=u.loop?vv(k,E+1):k.slice(E+1)}setTimeout(()=>uf(k))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:b!=null}):i})})});cf.displayName=lf;var bv={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function wv(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function yv(e,t,n){const r=wv(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return bv[r]}function uf(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function vv(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Sv=af,Cv=cf,Tv=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},kr=new WeakMap,ws=new WeakMap,ys={},ba=0,df=function(e){return e&&(e.host||df(e.parentNode))},kv=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=df(n);return r&&e.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",e,". Doing nothing"),null)}).filter(function(n){return!!n})},Ev=function(e,t,n,r){var o=kv(t,Array.isArray(e)?e:[e]);ys[n]||(ys[n]=new WeakMap);var s=ys[n],i=[],a=new Set,l=new Set(o),c=function(f){!f||a.has(f)||(a.add(f),c(f.parentNode))};o.forEach(c);var u=function(f){!f||l.has(f)||Array.prototype.forEach.call(f.children,function(h){if(a.has(h))u(h);else try{var p=h.getAttribute(r),m=p!==null&&p!=="false",b=(kr.get(h)||0)+1,g=(s.get(h)||0)+1;kr.set(h,b),s.set(h,g),i.push(h),b===1&&m&&ws.set(h,!0),g===1&&h.setAttribute(n,"true"),m||h.setAttribute(r,"true")}catch(w){console.error("aria-hidden: cannot operate on ",h,w)}})};return u(t),a.clear(),ba++,function(){i.forEach(function(f){var h=kr.get(f)-1,p=s.get(f)-1;kr.set(f,h),s.set(f,p),h||(ws.has(f)||f.removeAttribute(r),ws.delete(f)),p||f.removeAttribute(n)}),ba--,ba||(kr=new WeakMap,kr=new WeakMap,ws=new WeakMap,ys={})}},ff=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=Tv(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),Ev(r,o,n,"aria-hidden")):function(){return null}},un=function(){return un=Object.assign||function(t){for(var n,r=1,o=arguments.length;r<o;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},un.apply(this,arguments)};function hf(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]]);return n}function Iv(e,t,n){if(n||arguments.length===2)for(var r=0,o=t.length,s;r<o;r++)(s||!(r in t))&&(s||(s=Array.prototype.slice.call(t,0,r)),s[r]=t[r]);return e.concat(s||Array.prototype.slice.call(t))}typeof SuppressedError=="function"&&SuppressedError;var vs="right-scroll-bar-position",Ss="width-before-scroll-bar",Av="with-scroll-bars-hidden",Nv="--removed-body-scroll-bar-size";function wa(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function jv(e,t){var n=v.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var o=n.value;o!==r&&(n.value=r,n.callback(r,o))}}}})[0];return n.callback=t,n.facade}var _v=typeof window<"u"?x.useLayoutEffect:x.useEffect,pf=new WeakMap;function Pv(e,t){var n=jv(null,function(r){return e.forEach(function(o){return wa(o,r)})});return _v(function(){var r=pf.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||wa(a,null)}),s.forEach(function(a){o.has(a)||wa(a,i)})}pf.set(n,e)},[e]),n}function Rv(e){return e}function Ov(e,t){t===void 0&&(t=Rv);var n=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var u=i;i=[],u.forEach(s)},c=function(){return Promise.resolve().then(l)};c(),n={push:function(u){i.push(u),c()},filter:function(u){return i=i.filter(u),n}}}};return o}function Mv(e){e===void 0&&(e={});var t=Ov(null);return t.options=un({async:!0,ssr:!1},e),t}var mf=function(e){var t=e.sideCar,n=hf(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return x.createElement(r,un({},n))};mf.isSideCarExport=!0;function Dv(e,t){return e.useMedium(t),mf}var gf=Mv(),ya=function(){},Cs=x.forwardRef(function(e,t){var n=x.useRef(null),r=x.useState({onScrollCapture:ya,onWheelCapture:ya,onTouchMoveCapture:ya}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,u=e.enabled,f=e.shards,h=e.sideCar,p=e.noRelative,m=e.noIsolation,b=e.inert,g=e.allowPinchZoom,w=e.as,y=w===void 0?"div":w,k=e.gapMode,E=hf(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),S=h,C=Pv([n,t]),T=un(un({},E),o);return x.createElement(x.Fragment,null,u&&x.createElement(S,{sideCar:gf,removeScrollBar:c,shards:f,noRelative:p,noIsolation:m,inert:b,setCallbacks:s,allowPinchZoom:!!g,lockRef:n,gapMode:k}),i?x.cloneElement(x.Children.only(a),un(un({},T),{ref:C})):x.createElement(y,un({},T,{className:l,ref:C}),a))});Cs.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Cs.classNames={fullWidth:Ss,zeroRight:vs};var Lv=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function $v(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Lv();return t&&e.setAttribute("nonce",t),e}function Fv(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function zv(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var Bv=function(){var e=0,t=null;return{add:function(n){e==0&&(t=$v())&&(Fv(t,n),zv(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Uv=function(){var e=Bv();return function(t,n){x.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},xf=function(){var e=Uv(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Hv={left:0,top:0,right:0,gap:0},va=function(e){return parseInt(e||"",10)||0},Wv=function(e){var t=window.getComputedStyle(document.body),n=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],o=t[e==="padding"?"paddingRight":"marginRight"];return[va(n),va(r),va(o)]},Vv=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Hv;var t=Wv(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},Kv=xf(),Er="data-scroll-locked",qv=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
88
88
  .`.concat(Av,` {
89
89
  overflow: hidden `).concat(r,`;
90
90
  padding-right: `).concat(a,"px ").concat(r,`;
91
91
  }
92
- body[`).concat(Ir,`] {
92
+ body[`).concat(Er,`] {
93
93
  overflow: hidden `).concat(r,`;
94
94
  overscroll-behavior: contain;
95
95
  `).concat([t&&"position: relative ".concat(r,";"),n==="margin"&&`
@@ -118,15 +118,15 @@ Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An err
118
118
  margin-right: 0 `).concat(r,`;
119
119
  }
120
120
 
121
- body[`).concat(Ir,`] {
121
+ body[`).concat(Er,`] {
122
122
  `).concat(Nv,": ").concat(a,`px;
123
123
  }
124
- `)},bf=function(){var e=parseInt(document.body.getAttribute(Ir)||"0",10);return isFinite(e)?e:0},Gv=function(){x.useEffect(function(){return document.body.setAttribute(Ir,(bf()+1).toString()),function(){var e=bf()-1;e<=0?document.body.removeAttribute(Ir):document.body.setAttribute(Ir,e.toString())}},[])},Yv=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;Gv();var s=x.useMemo(function(){return Vv(o)},[o]);return x.createElement(Kv,{styles:qv(s,!t,o,n?"":"!important")})},Sa=!1;if(typeof window<"u")try{var Ts=Object.defineProperty({},"passive",{get:function(){return Sa=!0,!0}});window.addEventListener("test",Ts,Ts),window.removeEventListener("test",Ts,Ts)}catch{Sa=!1}var Ar=Sa?{passive:!1}:!1,Xv=function(e){return e.tagName==="TEXTAREA"},wf=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!Xv(e)&&n[t]==="visible")},Jv=function(e){return wf(e,"overflowY")},Zv=function(e){return wf(e,"overflowX")},yf=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=vf(e,r);if(o){var s=Sf(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Qv=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},e0=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},vf=function(e,t){return e==="v"?Jv(t):Zv(t)},Sf=function(e,t){return e==="v"?Qv(t):e0(t)},t0=function(e,t){return e==="h"&&t==="rtl"?-1:1},n0=function(e,t,n,r,o){var s=t0(e,window.getComputedStyle(t).direction),i=s*r,a=n.target,l=t.contains(a),c=!1,u=i>0,f=0,h=0;do{if(!a)break;var p=Sf(e,a),m=p[0],b=p[1],g=p[2],w=b-g-s*m;(m||w)&&vf(e,a)&&(f+=w,h+=m);var y=a.parentNode;a=y&&y.nodeType===Node.DOCUMENT_FRAGMENT_NODE?y.host:y}while(!l&&a!==document.body||l&&(t.contains(a)||t===a));return(u&&Math.abs(f)<1||!u&&Math.abs(h)<1)&&(c=!0),c},ks=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Cf=function(e){return[e.deltaX,e.deltaY]},Tf=function(e){return e&&"current"in e?e.current:e},r0=function(e,t){return e[0]===t[0]&&e[1]===t[1]},o0=function(e){return`
124
+ `)},bf=function(){var e=parseInt(document.body.getAttribute(Er)||"0",10);return isFinite(e)?e:0},Gv=function(){x.useEffect(function(){return document.body.setAttribute(Er,(bf()+1).toString()),function(){var e=bf()-1;e<=0?document.body.removeAttribute(Er):document.body.setAttribute(Er,e.toString())}},[])},Yv=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;Gv();var s=x.useMemo(function(){return Vv(o)},[o]);return x.createElement(Kv,{styles:qv(s,!t,o,n?"":"!important")})},Sa=!1;if(typeof window<"u")try{var Ts=Object.defineProperty({},"passive",{get:function(){return Sa=!0,!0}});window.addEventListener("test",Ts,Ts),window.removeEventListener("test",Ts,Ts)}catch{Sa=!1}var Ir=Sa?{passive:!1}:!1,Xv=function(e){return e.tagName==="TEXTAREA"},wf=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!Xv(e)&&n[t]==="visible")},Jv=function(e){return wf(e,"overflowY")},Zv=function(e){return wf(e,"overflowX")},yf=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=vf(e,r);if(o){var s=Sf(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Qv=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},e0=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},vf=function(e,t){return e==="v"?Jv(t):Zv(t)},Sf=function(e,t){return e==="v"?Qv(t):e0(t)},t0=function(e,t){return e==="h"&&t==="rtl"?-1:1},n0=function(e,t,n,r,o){var s=t0(e,window.getComputedStyle(t).direction),i=s*r,a=n.target,l=t.contains(a),c=!1,u=i>0,f=0,h=0;do{if(!a)break;var p=Sf(e,a),m=p[0],b=p[1],g=p[2],w=b-g-s*m;(m||w)&&vf(e,a)&&(f+=w,h+=m);var y=a.parentNode;a=y&&y.nodeType===Node.DOCUMENT_FRAGMENT_NODE?y.host:y}while(!l&&a!==document.body||l&&(t.contains(a)||t===a));return(u&&Math.abs(f)<1||!u&&Math.abs(h)<1)&&(c=!0),c},ks=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Cf=function(e){return[e.deltaX,e.deltaY]},Tf=function(e){return e&&"current"in e?e.current:e},r0=function(e,t){return e[0]===t[0]&&e[1]===t[1]},o0=function(e){return`
125
125
  .block-interactivity-`.concat(e,` {pointer-events: none;}
126
126
  .allow-interactivity-`).concat(e,` {pointer-events: all;}
127
- `)},s0=0,Nr=[];function i0(e){var t=x.useRef([]),n=x.useRef([0,0]),r=x.useRef(),o=x.useState(s0++)[0],s=x.useState(xf)[0],i=x.useRef(e);x.useEffect(function(){i.current=e},[e]),x.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var b=Iv([e.lockRef.current],(e.shards||[]).map(Tf),!0).filter(Boolean);return b.forEach(function(g){return g.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),b.forEach(function(g){return g.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=x.useCallback(function(b,g){if("touches"in b&&b.touches.length===2||b.type==="wheel"&&b.ctrlKey)return!i.current.allowPinchZoom;var w=ks(b),y=n.current,k="deltaX"in b?b.deltaX:y[0]-w[0],E="deltaY"in b?b.deltaY:y[1]-w[1],S,C=b.target,T=Math.abs(k)>Math.abs(E)?"h":"v";if("touches"in b&&T==="h"&&C.type==="range")return!1;var A=yf(T,C);if(!A)return!0;if(A?S=T:(S=T==="v"?"h":"v",A=yf(T,C)),!A)return!1;if(!r.current&&"changedTouches"in b&&(k||E)&&(r.current=S),!S)return!0;var N=r.current||S;return n0(N,g,b,N==="h"?k:E)},[]),l=x.useCallback(function(b){var g=b;if(!(!Nr.length||Nr[Nr.length-1]!==s)){var w="deltaY"in g?Cf(g):ks(g),y=t.current.filter(function(S){return S.name===g.type&&(S.target===g.target||g.target===S.shadowParent)&&r0(S.delta,w)})[0];if(y&&y.should){g.cancelable&&g.preventDefault();return}if(!y){var k=(i.current.shards||[]).map(Tf).filter(Boolean).filter(function(S){return S.contains(g.target)}),E=k.length>0?a(g,k[0]):!i.current.noIsolation;E&&g.cancelable&&g.preventDefault()}}},[]),c=x.useCallback(function(b,g,w,y){var k={name:b,delta:g,target:w,should:y,shadowParent:a0(w)};t.current.push(k),setTimeout(function(){t.current=t.current.filter(function(E){return E!==k})},1)},[]),u=x.useCallback(function(b){n.current=ks(b),r.current=void 0},[]),f=x.useCallback(function(b){c(b.type,Cf(b),b.target,a(b,e.lockRef.current))},[]),h=x.useCallback(function(b){c(b.type,ks(b),b.target,a(b,e.lockRef.current))},[]);x.useEffect(function(){return Nr.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:h}),document.addEventListener("wheel",l,Ar),document.addEventListener("touchmove",l,Ar),document.addEventListener("touchstart",u,Ar),function(){Nr=Nr.filter(function(b){return b!==s}),document.removeEventListener("wheel",l,Ar),document.removeEventListener("touchmove",l,Ar),document.removeEventListener("touchstart",u,Ar)}},[]);var p=e.removeScrollBar,m=e.inert;return x.createElement(x.Fragment,null,m?x.createElement(s,{styles:o0(o)}):null,p?x.createElement(Yv,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function a0(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const l0=Dv(gf,i0);var Ca=x.forwardRef(function(e,t){return x.createElement(Cs,cn({},e,{ref:t,sideCar:l0}))});Ca.classNames=Cs.classNames;var Ta=["Enter"," "],c0=["ArrowDown","PageUp","Home"],kf=["ArrowUp","PageDown","End"],u0=[...c0,...kf],d0={ltr:[...Ta,"ArrowRight"],rtl:[...Ta,"ArrowLeft"]},f0={ltr:["ArrowLeft"],rtl:["ArrowRight"]},ho="Menu",[po,h0,p0]=hd(ho),[Qn,Ef]=Mn(ho,[p0,Yd,sf]),Es=Yd(),If=sf(),[m0,er]=Qn(ho),[g0,mo]=Qn(ho),Af=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=Es(t),[l,c]=x.useState(null),u=x.useRef(!1),f=ft(s),h=Yi(o);return x.useEffect(()=>{const p=()=>{u.current=!0,document.addEventListener("pointerdown",m,{capture:!0,once:!0}),document.addEventListener("pointermove",m,{capture:!0,once:!0})},m=()=>u.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",m,{capture:!0}),document.removeEventListener("pointermove",m,{capture:!0})}},[]),d.jsx(ov,{...a,children:d.jsx(m0,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:d.jsx(g0,{scope:t,onClose:x.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:u,dir:h,modal:i,children:r})})})};Af.displayName=ho;var x0="MenuAnchor",ka=x.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Es(n);return d.jsx(sv,{...o,...r,ref:t})});ka.displayName=x0;var Ea="MenuPortal",[b0,Nf]=Qn(Ea,{forceMount:void 0}),jf=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=er(Ea,t);return d.jsx(b0,{scope:t,forceMount:n,children:d.jsx(Lt,{present:n||s.open,children:d.jsx(ma,{asChild:!0,container:o,children:r})})})};jf.displayName=Ea;var Ht="MenuContent",[w0,Ia]=Qn(Ht),_f=x.forwardRef((e,t)=>{const n=Nf(Ht,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=er(Ht,e.__scopeMenu),i=mo(Ht,e.__scopeMenu);return d.jsx(po.Provider,{scope:e.__scopeMenu,children:d.jsx(Lt,{present:r||s.open,children:d.jsx(po.Slot,{scope:e.__scopeMenu,children:i.modal?d.jsx(y0,{...o,ref:t}):d.jsx(v0,{...o,ref:t})})})})}),y0=x.forwardRef((e,t)=>{const n=er(Ht,e.__scopeMenu),r=x.useRef(null),o=Ge(t,r);return x.useEffect(()=>{const s=r.current;if(s)return ff(s)},[]),d.jsx(Aa,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ye(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),v0=x.forwardRef((e,t)=>{const n=er(Ht,e.__scopeMenu);return d.jsx(Aa,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),S0=cr.createSlot("MenuContent.ScrollLock"),Aa=x.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:f,onInteractOutside:h,onDismiss:p,disableOutsideScroll:m,...b}=e,g=er(Ht,n),w=mo(Ht,n),y=Es(n),k=If(n),E=h0(n),[S,C]=x.useState(null),T=x.useRef(null),A=Ge(t,T,g.onContentChange),N=x.useRef(0),j=x.useRef(""),L=x.useRef(0),B=x.useRef(null),W=x.useRef("right"),O=x.useRef(0),D=m?Ca:x.Fragment,z=m?{as:S0,allowPinchZoom:!0}:void 0,ee=V=>{var te,F;const Y=j.current+V,q=E().filter(X=>!X.disabled),M=document.activeElement,P=(te=q.find(X=>X.ref.current===M))==null?void 0:te.textValue,$=q.map(X=>X.textValue),R=O0($,Y,P),G=(F=q.find(X=>X.textValue===R))==null?void 0:F.ref.current;(function X(re){j.current=re,window.clearTimeout(N.current),re!==""&&(N.current=window.setTimeout(()=>X(""),1e3))})(Y),G&&setTimeout(()=>G.focus())};x.useEffect(()=>()=>window.clearTimeout(N.current),[]),bd();const H=x.useCallback(V=>{var q,M;return W.current===((q=B.current)==null?void 0:q.side)&&D0(V,(M=B.current)==null?void 0:M.area)},[]);return d.jsx(w0,{scope:n,searchRef:j,onItemEnter:x.useCallback(V=>{H(V)&&V.preventDefault()},[H]),onItemLeave:x.useCallback(V=>{var Y;H(V)||((Y=T.current)==null||Y.focus(),C(null))},[H]),onTriggerLeave:x.useCallback(V=>{H(V)&&V.preventDefault()},[H]),pointerGraceTimerRef:L,onPointerGraceIntentChange:x.useCallback(V=>{B.current=V},[]),children:d.jsx(D,{...z,children:d.jsx(ta,{asChild:!0,trapped:o,onMountAutoFocus:ye(s,V=>{var Y;V.preventDefault(),(Y=T.current)==null||Y.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:d.jsx(Ji,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:d.jsx(Sv,{asChild:!0,...k,dir:w.dir,orientation:"vertical",loop:r,currentTabStopId:S,onCurrentTabStopIdChange:C,onEntryFocus:ye(l,V=>{w.isUsingKeyboardRef.current||V.preventDefault()}),preventScrollOnEntryFocus:!0,children:d.jsx(iv,{role:"menu","aria-orientation":"vertical","data-state":Gf(g.open),"data-radix-menu-content":"",dir:w.dir,...y,...b,ref:A,style:{outline:"none",...b.style},onKeyDown:ye(b.onKeyDown,V=>{const q=V.target.closest("[data-radix-menu-content]")===V.currentTarget,M=V.ctrlKey||V.altKey||V.metaKey,P=V.key.length===1;q&&(V.key==="Tab"&&V.preventDefault(),!M&&P&&ee(V.key));const $=T.current;if(V.target!==$||!u0.includes(V.key))return;V.preventDefault();const G=E().filter(te=>!te.disabled).map(te=>te.ref.current);kf.includes(V.key)&&G.reverse(),P0(G)}),onBlur:ye(e.onBlur,V=>{V.currentTarget.contains(V.target)||(window.clearTimeout(N.current),j.current="")}),onPointerMove:ye(e.onPointerMove,xo(V=>{const Y=V.target,q=O.current!==V.clientX;if(V.currentTarget.contains(Y)&&q){const M=V.clientX>O.current?"right":"left";W.current=M,O.current=V.clientX}}))})})})})})})});_f.displayName=Ht;var C0="MenuGroup",Na=x.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return d.jsx(je.div,{role:"group",...r,ref:t})});Na.displayName=C0;var T0="MenuLabel",Pf=x.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return d.jsx(je.div,{...r,ref:t})});Pf.displayName=T0;var Is="MenuItem",Rf="menu.itemSelect",As=x.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=x.useRef(null),i=mo(Is,e.__scopeMenu),a=Ia(Is,e.__scopeMenu),l=Ge(t,s),c=x.useRef(!1),u=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(Rf,{bubbles:!0,cancelable:!0});f.addEventListener(Rf,p=>r==null?void 0:r(p),{once:!0}),fd(f,h),h.defaultPrevented?c.current=!1:i.onClose()}};return d.jsx(Of,{...o,ref:l,disabled:n,onClick:ye(e.onClick,u),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),c.current=!0},onPointerUp:ye(e.onPointerUp,f=>{var h;c.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:ye(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||Ta.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});As.displayName=Is;var Of=x.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=Ia(Is,n),a=If(n),l=x.useRef(null),c=Ge(t,l),[u,f]=x.useState(!1),[h,p]=x.useState("");return x.useEffect(()=>{const m=l.current;m&&p((m.textContent??"").trim())},[s.children]),d.jsx(po.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:d.jsx(Cv,{asChild:!0,...a,focusable:!r,children:d.jsx(je.div,{role:"menuitem","data-highlighted":u?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:ye(e.onPointerMove,xo(m=>{r?i.onItemLeave(m):(i.onItemEnter(m),m.defaultPrevented||m.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ye(e.onPointerLeave,xo(m=>i.onItemLeave(m))),onFocus:ye(e.onFocus,()=>f(!0)),onBlur:ye(e.onBlur,()=>f(!1))})})})}),k0="MenuCheckboxItem",Mf=x.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return d.jsx(zf,{scope:e.__scopeMenu,checked:n,children:d.jsx(As,{role:"menuitemcheckbox","aria-checked":Ns(n)?"mixed":n,...o,ref:t,"data-state":_a(n),onSelect:ye(o.onSelect,()=>r==null?void 0:r(Ns(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Mf.displayName=k0;var Df="MenuRadioGroup",[E0,I0]=Qn(Df,{value:void 0,onValueChange:()=>{}}),Lf=x.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=ft(r);return d.jsx(E0,{scope:e.__scopeMenu,value:n,onValueChange:s,children:d.jsx(Na,{...o,ref:t})})});Lf.displayName=Df;var $f="MenuRadioItem",Ff=x.forwardRef((e,t)=>{const{value:n,...r}=e,o=I0($f,e.__scopeMenu),s=n===o.value;return d.jsx(zf,{scope:e.__scopeMenu,checked:s,children:d.jsx(As,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":_a(s),onSelect:ye(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});Ff.displayName=$f;var ja="MenuItemIndicator",[zf,A0]=Qn(ja,{checked:!1}),Bf=x.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=A0(ja,n);return d.jsx(Lt,{present:r||Ns(s.checked)||s.checked===!0,children:d.jsx(je.span,{...o,ref:t,"data-state":_a(s.checked)})})});Bf.displayName=ja;var N0="MenuSeparator",Uf=x.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return d.jsx(je.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});Uf.displayName=N0;var j0="MenuArrow",Hf=x.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Es(n);return d.jsx(av,{...o,...r,ref:t})});Hf.displayName=j0;var _0="MenuSub",[xT,Wf]=Qn(_0),go="MenuSubTrigger",Vf=x.forwardRef((e,t)=>{const n=er(go,e.__scopeMenu),r=mo(go,e.__scopeMenu),o=Wf(go,e.__scopeMenu),s=Ia(go,e.__scopeMenu),i=x.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},u=x.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return x.useEffect(()=>u,[u]),x.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),d.jsx(ka,{asChild:!0,...c,children:d.jsx(Of,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Gf(n.open),...e,ref:On(t,o.onTriggerChange),onClick:f=>{var h;(h=e.onClick)==null||h.call(e,f),!(e.disabled||f.defaultPrevented)&&(f.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:ye(e.onPointerMove,xo(f=>{s.onItemEnter(f),!f.defaultPrevented&&!e.disabled&&!n.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{n.onOpenChange(!0),u()},100))})),onPointerLeave:ye(e.onPointerLeave,xo(f=>{var p,m;u();const h=(p=n.content)==null?void 0:p.getBoundingClientRect();if(h){const b=(m=n.content)==null?void 0:m.dataset.side,g=b==="right",w=g?-5:5,y=h[g?"left":"right"],k=h[g?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+w,y:f.clientY},{x:y,y:h.top},{x:k,y:h.top},{x:k,y:h.bottom},{x:y,y:h.bottom}],side:b}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:ye(e.onKeyDown,f=>{var p;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||d0[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});Vf.displayName=go;var Kf="MenuSubContent",qf=x.forwardRef((e,t)=>{const n=Nf(Ht,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=er(Ht,e.__scopeMenu),i=mo(Ht,e.__scopeMenu),a=Wf(Kf,e.__scopeMenu),l=x.useRef(null),c=Ge(t,l);return d.jsx(po.Provider,{scope:e.__scopeMenu,children:d.jsx(Lt,{present:r||s.open,children:d.jsx(po.Slot,{scope:e.__scopeMenu,children:d.jsx(Aa,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:c,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:u=>{var f;i.isUsingKeyboardRef.current&&((f=l.current)==null||f.focus()),u.preventDefault()},onCloseAutoFocus:u=>u.preventDefault(),onFocusOutside:ye(e.onFocusOutside,u=>{u.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ye(e.onEscapeKeyDown,u=>{i.onClose(),u.preventDefault()}),onKeyDown:ye(e.onKeyDown,u=>{var p;const f=u.currentTarget.contains(u.target),h=f0[i.dir].includes(u.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),u.preventDefault())})})})})})});qf.displayName=Kf;function Gf(e){return e?"open":"closed"}function Ns(e){return e==="indeterminate"}function _a(e){return Ns(e)?"indeterminate":e?"checked":"unchecked"}function P0(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function R0(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function O0(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=R0(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function M0(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],c=a.x,u=a.y,f=l.x,h=l.y;u>r!=h>r&&n<(f-c)*(r-u)/(h-u)+c&&(o=!o)}return o}function D0(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return M0(n,t)}function xo(e){return t=>t.pointerType==="mouse"?e(t):void 0}var L0=Af,$0=ka,F0=jf,z0=_f,B0=Na,U0=Pf,H0=As,W0=Mf,V0=Lf,K0=Ff,q0=Bf,G0=Uf,Y0=Hf,X0=Vf,J0=qf,js="DropdownMenu",[Z0,bT]=Mn(js,[Ef]),bt=Ef(),[Q0,Yf]=Z0(js),Xf=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=bt(t),c=x.useRef(null),[u,f]=as({prop:o,defaultProp:s??!1,onChange:i,caller:js});return d.jsx(Q0,{scope:t,triggerId:Ot(),triggerRef:c,contentId:Ot(),open:u,onOpenChange:f,onOpenToggle:x.useCallback(()=>f(h=>!h),[f]),modal:a,children:d.jsx(L0,{...l,open:u,onOpenChange:f,dir:r,modal:a,children:n})})};Xf.displayName=js;var Jf="DropdownMenuTrigger",Zf=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Yf(Jf,n),i=bt(n);return d.jsx($0,{asChild:!0,...i,children:d.jsx(je.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":r?"":void 0,disabled:r,...o,ref:On(t,s.triggerRef),onPointerDown:ye(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:ye(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});Zf.displayName=Jf;var eS="DropdownMenuPortal",Qf=e=>{const{__scopeDropdownMenu:t,...n}=e,r=bt(t);return d.jsx(F0,{...r,...n})};Qf.displayName=eS;var eh="DropdownMenuContent",th=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Yf(eh,n),s=bt(n),i=x.useRef(!1);return d.jsx(z0,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:ye(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:ye(e.onInteractOutside,a=>{const l=a.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,u=l.button===2||c;(!o.modal||u)&&(i.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)"}})});th.displayName=eh;var tS="DropdownMenuGroup",nS=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return d.jsx(B0,{...o,...r,ref:t})});nS.displayName=tS;var rS="DropdownMenuLabel",nh=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return d.jsx(U0,{...o,...r,ref:t})});nh.displayName=rS;var oS="DropdownMenuItem",rh=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return d.jsx(H0,{...o,...r,ref:t})});rh.displayName=oS;var sS="DropdownMenuCheckboxItem",oh=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return d.jsx(W0,{...o,...r,ref:t})});oh.displayName=sS;var iS="DropdownMenuRadioGroup",aS=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return d.jsx(V0,{...o,...r,ref:t})});aS.displayName=iS;var lS="DropdownMenuRadioItem",sh=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return d.jsx(K0,{...o,...r,ref:t})});sh.displayName=lS;var cS="DropdownMenuItemIndicator",ih=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return d.jsx(q0,{...o,...r,ref:t})});ih.displayName=cS;var uS="DropdownMenuSeparator",ah=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return d.jsx(G0,{...o,...r,ref:t})});ah.displayName=uS;var dS="DropdownMenuArrow",fS=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return d.jsx(Y0,{...o,...r,ref:t})});fS.displayName=dS;var hS="DropdownMenuSubTrigger",lh=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return d.jsx(X0,{...o,...r,ref:t})});lh.displayName=hS;var pS="DropdownMenuSubContent",ch=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=bt(n);return d.jsx(J0,{...o,...r,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)"}})});ch.displayName=pS;var mS=Xf,gS=Zf,xS=Qf,uh=th,dh=nh,fh=rh,hh=oh,ph=sh,mh=ih,gh=ah,xh=lh,bh=ch;const Pa=mS,Ra=gS,bS=x.forwardRef(({className:e,inset:t,children:n,...r},o)=>d.jsxs(xh,{ref:o,className:fe("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),...r,children:[n,d.jsx(me.ChevronRight,{className:"ml-auto h-4 w-4"})]}));bS.displayName=xh.displayName;const wS=x.forwardRef(({className:e,...t},n)=>d.jsx(bh,{ref:n,className:fe("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}));wS.displayName=bh.displayName;const _s=x.forwardRef(({className:e,sideOffset:t=4,...n},r)=>d.jsx(xS,{children:d.jsx(uh,{ref:r,sideOffset:t,className:fe("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),...n})}));_s.displayName=uh.displayName;const tr=x.forwardRef(({className:e,inset:t,...n},r)=>d.jsx(fh,{ref:r,className:fe("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),...n}));tr.displayName=fh.displayName;const yS=x.forwardRef(({className:e,children:t,checked:n,...r},o)=>d.jsxs(hh,{ref:o,className:fe("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:n,...r,children:[d.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:d.jsx(mh,{children:d.jsx(me.Check,{className:"h-4 w-4"})})}),t]}));yS.displayName=hh.displayName;const vS=x.forwardRef(({className:e,children:t,...n},r)=>d.jsxs(ph,{ref:r,className:fe("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),...n,children:[d.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:d.jsx(mh,{children:d.jsx(me.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));vS.displayName=ph.displayName;const SS=x.forwardRef(({className:e,inset:t,...n},r)=>d.jsx(dh,{ref:r,className:fe("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));SS.displayName=dh.displayName;const CS=x.forwardRef(({className:e,...t},n)=>d.jsx(gh,{ref:n,className:fe("-mx-1 my-1 h-px bg-muted",e),...t}));CS.displayName=gh.displayName;const wh=x.forwardRef(({className:e,...t},n)=>d.jsx("textarea",{className:fe("flex min-h-[40px] 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:n,...t}));wh.displayName="Textarea";const TS=1e4;function Oa({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=TS,value:i,onValueChange:a,onSend:l,onCancelEdit:c,onStop:u,className:f="",textareaClassName:h="",allowEmptySend:p=!1,sendButtonClassName:m,validate:b,onValidationError:g}){const w=i!==void 0,[y,k]=v.useState(e),E=(w?i:y)??"",[S,C]=v.useTransition(),T=v.useRef(null),A=v.useRef(0),N=v.useRef(null),j=v.useRef("");v.useEffect(()=>{if(!w&&(k(e??""),N.current=null,T.current)){const $=!e||e.trim()==="",R=44;$?T.current.style.height=`${R}px`:(T.current.style.height="auto",T.current.style.height=`${Math.max(T.current.scrollHeight,R)}px`)}},[e,t,w]);const[L,B]=v.useState(null),W=v.useCallback($=>$.length>s?`Message too long (${$.length}/${s} characters)`:null,[s]),O=v.useMemo(()=>b??W,[b,W]),D=v.useCallback($=>{const R=O($);return B(R),g==null||g(R),j.current=$,R},[O,g]),z=v.useCallback(()=>{const $=T.current;if(!$)return;const R=!$.value||$.value.trim()==="",G=44;if(R){$.style.height=`${G}px`;return}$.style.height="auto";const te=Math.max($.scrollHeight,G);$.style.height=`${te}px`},[]);v.useEffect(()=>{z()},[z,E]),v.useEffect(()=>{if(!L)return;const $=(E??"").trim();j.current!==$&&D($)},[E,L,D]);const ee=v.useCallback(($,{fromUser:R})=>{w||k($),R&&(a==null||a($))},[w,a]),H=v.useCallback(async $=>{$&&$.preventDefault();const R=(E??"").trim();if(!R&&!p||D(R))return;const G=++A.current;N.current={id:G,shouldClear:!0},C(()=>{var te,F,X;try{const re=l(R);re&&typeof re.then=="function"?re.then(()=>{var ue,le;((ue=N.current)==null?void 0:ue.id)===G&&N.current.shouldClear&&(w||(k(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((le=N.current)==null?void 0:le.id)===G&&(N.current=null)}).catch(()=>{var ue;((ue=N.current)==null?void 0:ue.id)===G&&(N.current=null)}):(((te=N.current)==null?void 0:te.id)===G&&N.current.shouldClear&&(w||(k(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((F=N.current)==null?void 0:F.id)===G&&(N.current=null))}catch{((X=N.current)==null?void 0:X.id)===G&&(N.current=null)}})},[E,l,p,w,a,D]),V=v.useCallback($=>{const R=$.target.value;ee(R,{fromUser:!0}),N.current&&(N.current.shouldClear=!1),T.current&&(T.current.style.height="auto",T.current.style.height=`${T.current.scrollHeight}px`),L&&D(R.trim())},[ee,D,L]),Y=v.useCallback($=>{$.key==="Enter"&&!$.shiftKey?($.preventDefault(),H()):$.key==="Escape"&&t&&($.preventDefault(),c==null||c())},[H,t,c]),P=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${h}`;return d.jsx("div",{className:`w-full ${f}`,children:d.jsxs("div",{className:"flex items-end gap-2",children:[d.jsxs("div",{className:"flex-1",children:[d.jsx(wh,{ref:T,value:E,onChange:V,onKeyDown:Y,placeholder:t?"Edit your message...":n,className:P,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"}),L&&d.jsx("p",{className:"mt-1 text-xs text-destructive font-medium",children:L})]}),d.jsx("div",{children:r?d.jsx(Je,{type:"button",onClick:()=>{u==null||u()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!u,children:d.jsx(me.Square,{size:16})}):d.jsx(Je,{type:"button",onClick:$=>void H($),size:"icon",className:`shrink-0 ${m??""}`,title:t?"Save changes":"Send message",disabled:o||!E.trim()&&!p||S||r,children:d.jsx(me.Send,{size:16})})})]})})}const kS=v.memo(Oa);function Ps({composerValue:e,onComposerChange:t,onSend:n,onCancelEdit:r,onStop:o,editingMessageId:s=null,editingInitialValue:i="",placeholder:a="Type your message...",isStreaming:l=!1,disabled:c=!1,textareaClassName:u="",customStyles:f={},enableFileUpload:h=!1,enableExcelUpload:p=!1,onExcelUpload:m,onFilesChange:b,onError:g,allowEmptySend:w=!1,inputError:y=null}){const[k,E]=v.useState([]),S=v.useRef(null),C=v.useRef(null),[T,A]=v.useState(0),[N,j]=v.useState(0),[L,B]=v.useState(!1),[W,O]=v.useState(null),[D,z]=v.useState(null),ee=v.useCallback(()=>{S.current&&(S.current.value=""),C.current&&(C.current.value=""),A(R=>R+1),j(R=>R+1)},[]),H=v.useCallback(R=>{E(G=>{const te=[...G,...R];return b==null||b(te),te})},[b]),V=v.useCallback(R=>{const G=Array.from(R.target.files||[]);H(G),R.target.value=""},[H]),Y=v.useCallback(R=>{E(G=>{const te=G.filter((F,X)=>X!==R);return te.length===0&&ee(),b==null||b(te),te})},[b,ee]),q=v.useCallback(async R=>{const G=(R.target.files||[])[0];if(G&&(O(null),z(null),!!m)){B(!0);try{await m(G),O(`Uploaded ${G.name} - processing through chat stream`)}catch(te){const F=te instanceof Error?te.message:"Failed to upload Excel file";z(F),g==null||g(F)}finally{B(!1),R.target.value="",ee()}}},[m,g,ee]),M=v.useMemo(()=>w||k.length>0,[w,k]),P=v.useCallback(async R=>{const te=await n(R,k);return k.length>0&&(E([]),b==null||b([]),ee()),te},[n,ee,k]),$=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${s?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${y?"border-red-400":""} ${f.textarea||""} ${u}`;return d.jsxs(d.Fragment,{children:[(h||p)&&d.jsxs("div",{className:"mb-3 space-y-3",children:[h&&d.jsxs(d.Fragment,{children:[d.jsx("input",{ref:S,type:"file",multiple:!0,onChange:V,className:"hidden"},T),k.length>0&&d.jsx("div",{className:"flex flex-wrap gap-2",children:k.map((R,G)=>d.jsxs("div",{className:"flex items-center gap-2 bg-gray-100 dark:bg-gray-800 rounded-lg px-3 py-2 text-sm text-gray-900 dark:text-gray-100",children:[d.jsx(me.Paperclip,{size:14}),d.jsx("span",{className:"truncate max-w-[150px]",children:R.name}),d.jsx(Je,{variant:"ghost",size:"sm",onClick:()=>Y(G),className:"h-4 w-4 p-0 text-gray-500 dark:text-gray-400 hover:text-red-500 dark:hover:text-red-400","aria-label":`Remove ${R.name}`,children:d.jsx(me.X,{size:12})})]},G))})]}),p&&d.jsxs(d.Fragment,{children:[d.jsx("input",{ref:C,type:"file",accept:".xls,.xlsx,.xlsm",onChange:q,className:"hidden"},N),L&&d.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[d.jsx(me.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),W&&!L&&d.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:W}),D&&!L&&d.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:D})]})]}),d.jsxs("div",{className:"flex items-end gap-2",children:[(h||p)&&d.jsxs(Pa,{children:[d.jsx(Ra,{asChild:!0,children:d.jsx(Je,{type:"button",size:"icon",variant:"outline",disabled:l||c,title:"More input actions",className:f.moreButton||"",children:d.jsx(me.Plus,{size:16})})}),d.jsxs(_s,{align:"start",sideOffset:6,className:"w-52",children:[h&&d.jsxs(tr,{onClick:()=>{var R;return(R=S.current)==null?void 0:R.click()},className:"cursor-pointer",children:[d.jsx(me.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),p&&d.jsxs(tr,{onClick:()=>{var R;L||(R=C.current)==null||R.click()},className:`cursor-pointer ${L?"opacity-60 pointer-events-none":""}`,children:[d.jsx(me.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),d.jsx("div",{className:"flex-1",children:d.jsx(kS,{initialValue:i,editingMessageId:s,value:e,onValueChange:t,placeholder:s?"Edit your message...":a,isStreaming:l,disabled:c,onSend:P,onCancelEdit:r,onStop:o,allowEmptySend:M,textareaClassName:$,sendButtonClassName:f.sendButton})})]})]})}v.memo(Ps);function yh({submit:e,chatRequest:t,lastCheckpointId:n,lastCheckpointNs:r,onMessageSent:o,onExcelUploadSuccess:s,onError:i,enableMessageEditing:a,messages:l,unifiedMessages:c,setPendingAssistantResponse:u,project:f,onEvent:h,activeThreadId:p}){const[m,b]=v.useState(null),[g,w]=v.useState(""),[y,k]=v.useState(null),[E,S]=v.useState(null),[C,T]=v.useState(!1),[A,N]=v.useState(""),j=v.useRef(A),L=v.useRef(null);v.useEffect(()=>{if(!m)if(p){const Y=localStorage.getItem(Po(p));N(Y||"")}else N("")},[p,m]);const B=v.useCallback(Y=>{N(Y),!m&&p&&localStorage.setItem(Po(p),Y)},[p,m]);v.useEffect(()=>{j.current=A},[A]),v.useEffect(()=>{if(!m){L.current=null;return}L.current===null&&(L.current=j.current),B(g??"")},[g,m,B]);const W=v.useCallback(Y=>{B(Y)},[B]),O=async(Y,q)=>{const M=Array.isArray(q)?{files:q}:q??{},P=M.files??[],$=M.contentParts??[],R=Y.trim();if(!(!R&&P.length===0&&$.length===0))try{const G=P.map(async le=>{try{const Se=await ii.uploadFile(le);return{file:le,record:Se}}catch(Se){throw console.error("Failed to upload file",le.name,Se),new Error(`Failed to upload ${le.name}`)}}),F=(await Promise.all(G)).map(({record:le})=>{const Se=le.mime_type;return Se.startsWith("image/")?{type:"image_url",image_url:{url:le.content_url}}:{type:"file",url:le.content_url,mimeType:Se,name:le.filename,size:le.size}}),X=[...$,...F],re=m?(y==null?void 0:y.checkpointId)??n??void 0:n??void 0,ue=m?(y==null?void 0:y.checkpointNs)??r??void 0:r??void 0;await e({text:R||"",contentParts:X,attachments:[],payload:t.payload},{checkpointId:re,checkpointNs:ue,project:f??void 0,edit:!!m,originalMessageId:m??void 0,config:t.config,onEvent:h}),o==null||o(R),u(!0),p&&localStorage.removeItem(Po(p)),B(""),S(null),b(null),w(""),k(null)}catch(G){const te=(G==null?void 0:G.message)||"Failed to send message";S(te),i==null||i(te),u(!1)}},D=(Y,q)=>{q||O(Y,{files:[]})},z=v.useCallback(async Y=>{await e({attachments:[Y],payload:t.payload},{checkpointId:n??void 0,checkpointNs:r??void 0,project:f??void 0,config:t.config,onEvent:h}),s==null||s({file:Y})},[n,r,t,s,e]),ee=v.useCallback((Y,q,M)=>{a&&(L.current=A,b(Y),w(q),k({checkpointId:(M==null?void 0:M.checkpointId)??null,checkpointNs:(M==null?void 0:M.checkpointNs)??null}),S(null))},[A,a]),H=v.useCallback(()=>{b(null),w(""),k(null),S(null);const Y=L.current;Y!==null&&N(Y),L.current=null},[]),V=v.useCallback(Y=>{let q=null;for(let R=Y-1;R>=0;R--)if(l[R].role==="user"){q=l[R];break}if(!q)return;const M=Array.isArray(q.content)?q.content:[],$=M.filter(R=>(R==null?void 0:R.type)==="text").map(R=>R.text).join("")||(()=>{try{return JSON.stringify(M,null,2)}catch{return String(M)}})();$&&e({text:$,payload:t.payload},{checkpointId:n??void 0,checkpointNs:r??void 0,edit:!0,originalMessageId:q.id,config:t.config,onEvent:h})},[l,e,n,r,t]);return{editingMessageId:m,editingInitialValue:g,inputError:E,setInputError:S,dismissError:C,setDismissError:T,composerValue:A,handleComposerChange:W,handleSendMessage:O,handleQuickPrompt:D,handleExcelUpload:z,startEditing:ee,cancelEditing:H,handleRegenerateCb:V,messages:c??l}}var Rs="Dialog",[vh,wT]=Mn(Rs),[ES,Zt]=vh(Rs),Sh=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=x.useRef(null),l=x.useRef(null),[c,u]=as({prop:r,defaultProp:o??!1,onChange:s,caller:Rs});return d.jsx(ES,{scope:t,triggerRef:a,contentRef:l,contentId:Ot(),titleId:Ot(),descriptionId:Ot(),open:c,onOpenChange:u,onOpenToggle:x.useCallback(()=>u(f=>!f),[u]),modal:i,children:n})};Sh.displayName=Rs;var Ch="DialogTrigger",IS=x.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Zt(Ch,n),s=Ge(t,o.triggerRef);return d.jsx(je.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":La(o.open),...r,ref:s,onClick:ye(e.onClick,o.onOpenToggle)})});IS.displayName=Ch;var Ma="DialogPortal",[AS,Th]=vh(Ma,{forceMount:void 0}),kh=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=Zt(Ma,t);return d.jsx(AS,{scope:t,forceMount:n,children:x.Children.map(r,i=>d.jsx(Lt,{present:n||s.open,children:d.jsx(ma,{asChild:!0,container:o,children:i})}))})};kh.displayName=Ma;var Os="DialogOverlay",Eh=x.forwardRef((e,t)=>{const n=Th(Os,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=Zt(Os,e.__scopeDialog);return s.modal?d.jsx(Lt,{present:r||s.open,children:d.jsx(jS,{...o,ref:t})}):null});Eh.displayName=Os;var NS=cr.createSlot("DialogOverlay.RemoveScroll"),jS=x.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Zt(Os,n);return d.jsx(Ca,{as:NS,allowPinchZoom:!0,shards:[o.contentRef],children:d.jsx(je.div,{"data-state":La(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),nr="DialogContent",Ih=x.forwardRef((e,t)=>{const n=Th(nr,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=Zt(nr,e.__scopeDialog);return d.jsx(Lt,{present:r||s.open,children:s.modal?d.jsx(_S,{...o,ref:t}):d.jsx(PS,{...o,ref:t})})});Ih.displayName=nr;var _S=x.forwardRef((e,t)=>{const n=Zt(nr,e.__scopeDialog),r=x.useRef(null),o=Ge(t,n.contentRef,r);return x.useEffect(()=>{const s=r.current;if(s)return ff(s)},[]),d.jsx(Ah,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ye(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:ye(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:ye(e.onFocusOutside,s=>s.preventDefault())})}),PS=x.forwardRef((e,t)=>{const n=Zt(nr,e.__scopeDialog),r=x.useRef(!1),o=x.useRef(!1);return d.jsx(Ah,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i,a;(i=e.onCloseAutoFocus)==null||i.call(e,s),s.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),s.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:s=>{var l,c;(l=e.onInteractOutside)==null||l.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const i=s.target;((c=n.triggerRef.current)==null?void 0:c.contains(i))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),Ah=x.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=Zt(nr,n),l=x.useRef(null),c=Ge(t,l);return bd(),d.jsxs(d.Fragment,{children:[d.jsx(ta,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:d.jsx(Ji,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":La(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),d.jsxs(d.Fragment,{children:[d.jsx(RS,{titleId:a.titleId}),d.jsx(MS,{contentRef:l,descriptionId:a.descriptionId})]})]})}),Da="DialogTitle",Nh=x.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Zt(Da,n);return d.jsx(je.h2,{id:o.titleId,...r,ref:t})});Nh.displayName=Da;var jh="DialogDescription",_h=x.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Zt(jh,n);return d.jsx(je.p,{id:o.descriptionId,...r,ref:t})});_h.displayName=jh;var Ph="DialogClose",Rh=x.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Zt(Ph,n);return d.jsx(je.button,{type:"button",...r,ref:t,onClick:ye(e.onClick,()=>o.onOpenChange(!1))})});Rh.displayName=Ph;function La(e){return e?"open":"closed"}var Oh="DialogTitleWarning",[yT,Mh]=mw(Oh,{contentName:nr,titleName:Da,docsSlug:"dialog"}),RS=({titleId:e})=>{const t=Mh(Oh),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
127
+ `)},s0=0,Ar=[];function i0(e){var t=x.useRef([]),n=x.useRef([0,0]),r=x.useRef(),o=x.useState(s0++)[0],s=x.useState(xf)[0],i=x.useRef(e);x.useEffect(function(){i.current=e},[e]),x.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var b=Iv([e.lockRef.current],(e.shards||[]).map(Tf),!0).filter(Boolean);return b.forEach(function(g){return g.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),b.forEach(function(g){return g.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=x.useCallback(function(b,g){if("touches"in b&&b.touches.length===2||b.type==="wheel"&&b.ctrlKey)return!i.current.allowPinchZoom;var w=ks(b),y=n.current,k="deltaX"in b?b.deltaX:y[0]-w[0],E="deltaY"in b?b.deltaY:y[1]-w[1],S,C=b.target,T=Math.abs(k)>Math.abs(E)?"h":"v";if("touches"in b&&T==="h"&&C.type==="range")return!1;var N=yf(T,C);if(!N)return!0;if(N?S=T:(S=T==="v"?"h":"v",N=yf(T,C)),!N)return!1;if(!r.current&&"changedTouches"in b&&(k||E)&&(r.current=S),!S)return!0;var j=r.current||S;return n0(j,g,b,j==="h"?k:E)},[]),l=x.useCallback(function(b){var g=b;if(!(!Ar.length||Ar[Ar.length-1]!==s)){var w="deltaY"in g?Cf(g):ks(g),y=t.current.filter(function(S){return S.name===g.type&&(S.target===g.target||g.target===S.shadowParent)&&r0(S.delta,w)})[0];if(y&&y.should){g.cancelable&&g.preventDefault();return}if(!y){var k=(i.current.shards||[]).map(Tf).filter(Boolean).filter(function(S){return S.contains(g.target)}),E=k.length>0?a(g,k[0]):!i.current.noIsolation;E&&g.cancelable&&g.preventDefault()}}},[]),c=x.useCallback(function(b,g,w,y){var k={name:b,delta:g,target:w,should:y,shadowParent:a0(w)};t.current.push(k),setTimeout(function(){t.current=t.current.filter(function(E){return E!==k})},1)},[]),u=x.useCallback(function(b){n.current=ks(b),r.current=void 0},[]),f=x.useCallback(function(b){c(b.type,Cf(b),b.target,a(b,e.lockRef.current))},[]),h=x.useCallback(function(b){c(b.type,ks(b),b.target,a(b,e.lockRef.current))},[]);x.useEffect(function(){return Ar.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:h}),document.addEventListener("wheel",l,Ir),document.addEventListener("touchmove",l,Ir),document.addEventListener("touchstart",u,Ir),function(){Ar=Ar.filter(function(b){return b!==s}),document.removeEventListener("wheel",l,Ir),document.removeEventListener("touchmove",l,Ir),document.removeEventListener("touchstart",u,Ir)}},[]);var p=e.removeScrollBar,m=e.inert;return x.createElement(x.Fragment,null,m?x.createElement(s,{styles:o0(o)}):null,p?x.createElement(Yv,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function a0(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const l0=Dv(gf,i0);var Ca=x.forwardRef(function(e,t){return x.createElement(Cs,un({},e,{ref:t,sideCar:l0}))});Ca.classNames=Cs.classNames;var Ta=["Enter"," "],c0=["ArrowDown","PageUp","Home"],kf=["ArrowUp","PageDown","End"],u0=[...c0,...kf],d0={ltr:[...Ta,"ArrowRight"],rtl:[...Ta,"ArrowLeft"]},f0={ltr:["ArrowLeft"],rtl:["ArrowRight"]},fo="Menu",[ho,h0,p0]=hd(fo),[Qn,Ef]=Rn(fo,[p0,Yd,sf]),Es=Yd(),If=sf(),[m0,er]=Qn(fo),[g0,po]=Qn(fo),Af=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=Es(t),[l,c]=x.useState(null),u=x.useRef(!1),f=ft(s),h=Yi(o);return x.useEffect(()=>{const p=()=>{u.current=!0,document.addEventListener("pointerdown",m,{capture:!0,once:!0}),document.addEventListener("pointermove",m,{capture:!0,once:!0})},m=()=>u.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",m,{capture:!0}),document.removeEventListener("pointermove",m,{capture:!0})}},[]),d.jsx(ov,{...a,children:d.jsx(m0,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:c,children:d.jsx(g0,{scope:t,onClose:x.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:u,dir:h,modal:i,children:r})})})};Af.displayName=fo;var x0="MenuAnchor",ka=x.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Es(n);return d.jsx(sv,{...o,...r,ref:t})});ka.displayName=x0;var Ea="MenuPortal",[b0,Nf]=Qn(Ea,{forceMount:void 0}),jf=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=er(Ea,t);return d.jsx(b0,{scope:t,forceMount:n,children:d.jsx(Dt,{present:n||s.open,children:d.jsx(ma,{asChild:!0,container:o,children:r})})})};jf.displayName=Ea;var zt="MenuContent",[w0,Ia]=Qn(zt),_f=x.forwardRef((e,t)=>{const n=Nf(zt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=er(zt,e.__scopeMenu),i=po(zt,e.__scopeMenu);return d.jsx(ho.Provider,{scope:e.__scopeMenu,children:d.jsx(Dt,{present:r||s.open,children:d.jsx(ho.Slot,{scope:e.__scopeMenu,children:i.modal?d.jsx(y0,{...o,ref:t}):d.jsx(v0,{...o,ref:t})})})})}),y0=x.forwardRef((e,t)=>{const n=er(zt,e.__scopeMenu),r=x.useRef(null),o=Xe(t,r);return x.useEffect(()=>{const s=r.current;if(s)return ff(s)},[]),d.jsx(Aa,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ye(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),v0=x.forwardRef((e,t)=>{const n=er(zt,e.__scopeMenu);return d.jsx(Aa,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),S0=lr.createSlot("MenuContent.ScrollLock"),Aa=x.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:f,onInteractOutside:h,onDismiss:p,disableOutsideScroll:m,...b}=e,g=er(zt,n),w=po(zt,n),y=Es(n),k=If(n),E=h0(n),[S,C]=x.useState(null),T=x.useRef(null),N=Xe(t,T,g.onContentChange),j=x.useRef(0),_=x.useRef(""),D=x.useRef(0),z=x.useRef(null),H=x.useRef("right"),P=x.useRef(0),M=m?Ca:x.Fragment,F=m?{as:S0,allowPinchZoom:!0}:void 0,ne=W=>{var Z,$;const Y=_.current+W,q=E().filter(X=>!X.disabled),R=document.activeElement,G=(Z=q.find(X=>X.ref.current===R))==null?void 0:Z.textValue,A=q.map(X=>X.textValue),O=O0(A,Y,G),V=($=q.find(X=>X.textValue===O))==null?void 0:$.ref.current;(function X(oe){_.current=oe,window.clearTimeout(j.current),oe!==""&&(j.current=window.setTimeout(()=>X(""),1e3))})(Y),V&&setTimeout(()=>V.focus())};x.useEffect(()=>()=>window.clearTimeout(j.current),[]),bd();const U=x.useCallback(W=>{var q,R;return H.current===((q=z.current)==null?void 0:q.side)&&D0(W,(R=z.current)==null?void 0:R.area)},[]);return d.jsx(w0,{scope:n,searchRef:_,onItemEnter:x.useCallback(W=>{U(W)&&W.preventDefault()},[U]),onItemLeave:x.useCallback(W=>{var Y;U(W)||((Y=T.current)==null||Y.focus(),C(null))},[U]),onTriggerLeave:x.useCallback(W=>{U(W)&&W.preventDefault()},[U]),pointerGraceTimerRef:D,onPointerGraceIntentChange:x.useCallback(W=>{z.current=W},[]),children:d.jsx(M,{...F,children:d.jsx(ta,{asChild:!0,trapped:o,onMountAutoFocus:ye(s,W=>{var Y;W.preventDefault(),(Y=T.current)==null||Y.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:d.jsx(Ji,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:d.jsx(Sv,{asChild:!0,...k,dir:w.dir,orientation:"vertical",loop:r,currentTabStopId:S,onCurrentTabStopIdChange:C,onEntryFocus:ye(l,W=>{w.isUsingKeyboardRef.current||W.preventDefault()}),preventScrollOnEntryFocus:!0,children:d.jsx(iv,{role:"menu","aria-orientation":"vertical","data-state":Gf(g.open),"data-radix-menu-content":"",dir:w.dir,...y,...b,ref:N,style:{outline:"none",...b.style},onKeyDown:ye(b.onKeyDown,W=>{const q=W.target.closest("[data-radix-menu-content]")===W.currentTarget,R=W.ctrlKey||W.altKey||W.metaKey,G=W.key.length===1;q&&(W.key==="Tab"&&W.preventDefault(),!R&&G&&ne(W.key));const A=T.current;if(W.target!==A||!u0.includes(W.key))return;W.preventDefault();const V=E().filter(Z=>!Z.disabled).map(Z=>Z.ref.current);kf.includes(W.key)&&V.reverse(),P0(V)}),onBlur:ye(e.onBlur,W=>{W.currentTarget.contains(W.target)||(window.clearTimeout(j.current),_.current="")}),onPointerMove:ye(e.onPointerMove,go(W=>{const Y=W.target,q=P.current!==W.clientX;if(W.currentTarget.contains(Y)&&q){const R=W.clientX>P.current?"right":"left";H.current=R,P.current=W.clientX}}))})})})})})})});_f.displayName=zt;var C0="MenuGroup",Na=x.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return d.jsx(Ae.div,{role:"group",...r,ref:t})});Na.displayName=C0;var T0="MenuLabel",Pf=x.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return d.jsx(Ae.div,{...r,ref:t})});Pf.displayName=T0;var Is="MenuItem",Rf="menu.itemSelect",As=x.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=x.useRef(null),i=po(Is,e.__scopeMenu),a=Ia(Is,e.__scopeMenu),l=Xe(t,s),c=x.useRef(!1),u=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(Rf,{bubbles:!0,cancelable:!0});f.addEventListener(Rf,p=>r==null?void 0:r(p),{once:!0}),fd(f,h),h.defaultPrevented?c.current=!1:i.onClose()}};return d.jsx(Of,{...o,ref:l,disabled:n,onClick:ye(e.onClick,u),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),c.current=!0},onPointerUp:ye(e.onPointerUp,f=>{var h;c.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:ye(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||Ta.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});As.displayName=Is;var Of=x.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=Ia(Is,n),a=If(n),l=x.useRef(null),c=Xe(t,l),[u,f]=x.useState(!1),[h,p]=x.useState("");return x.useEffect(()=>{const m=l.current;m&&p((m.textContent??"").trim())},[s.children]),d.jsx(ho.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:d.jsx(Cv,{asChild:!0,...a,focusable:!r,children:d.jsx(Ae.div,{role:"menuitem","data-highlighted":u?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:ye(e.onPointerMove,go(m=>{r?i.onItemLeave(m):(i.onItemEnter(m),m.defaultPrevented||m.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ye(e.onPointerLeave,go(m=>i.onItemLeave(m))),onFocus:ye(e.onFocus,()=>f(!0)),onBlur:ye(e.onBlur,()=>f(!1))})})})}),k0="MenuCheckboxItem",Mf=x.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return d.jsx(zf,{scope:e.__scopeMenu,checked:n,children:d.jsx(As,{role:"menuitemcheckbox","aria-checked":Ns(n)?"mixed":n,...o,ref:t,"data-state":_a(n),onSelect:ye(o.onSelect,()=>r==null?void 0:r(Ns(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Mf.displayName=k0;var Df="MenuRadioGroup",[E0,I0]=Qn(Df,{value:void 0,onValueChange:()=>{}}),Lf=x.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=ft(r);return d.jsx(E0,{scope:e.__scopeMenu,value:n,onValueChange:s,children:d.jsx(Na,{...o,ref:t})})});Lf.displayName=Df;var $f="MenuRadioItem",Ff=x.forwardRef((e,t)=>{const{value:n,...r}=e,o=I0($f,e.__scopeMenu),s=n===o.value;return d.jsx(zf,{scope:e.__scopeMenu,checked:s,children:d.jsx(As,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":_a(s),onSelect:ye(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});Ff.displayName=$f;var ja="MenuItemIndicator",[zf,A0]=Qn(ja,{checked:!1}),Bf=x.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=A0(ja,n);return d.jsx(Dt,{present:r||Ns(s.checked)||s.checked===!0,children:d.jsx(Ae.span,{...o,ref:t,"data-state":_a(s.checked)})})});Bf.displayName=ja;var N0="MenuSeparator",Uf=x.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return d.jsx(Ae.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});Uf.displayName=N0;var j0="MenuArrow",Hf=x.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Es(n);return d.jsx(av,{...o,...r,ref:t})});Hf.displayName=j0;var _0="MenuSub",[xT,Wf]=Qn(_0),mo="MenuSubTrigger",Vf=x.forwardRef((e,t)=>{const n=er(mo,e.__scopeMenu),r=po(mo,e.__scopeMenu),o=Wf(mo,e.__scopeMenu),s=Ia(mo,e.__scopeMenu),i=x.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},u=x.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return x.useEffect(()=>u,[u]),x.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),d.jsx(ka,{asChild:!0,...c,children:d.jsx(Of,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Gf(n.open),...e,ref:Pn(t,o.onTriggerChange),onClick:f=>{var h;(h=e.onClick)==null||h.call(e,f),!(e.disabled||f.defaultPrevented)&&(f.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:ye(e.onPointerMove,go(f=>{s.onItemEnter(f),!f.defaultPrevented&&!e.disabled&&!n.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{n.onOpenChange(!0),u()},100))})),onPointerLeave:ye(e.onPointerLeave,go(f=>{var p,m;u();const h=(p=n.content)==null?void 0:p.getBoundingClientRect();if(h){const b=(m=n.content)==null?void 0:m.dataset.side,g=b==="right",w=g?-5:5,y=h[g?"left":"right"],k=h[g?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+w,y:f.clientY},{x:y,y:h.top},{x:k,y:h.top},{x:k,y:h.bottom},{x:y,y:h.bottom}],side:b}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:ye(e.onKeyDown,f=>{var p;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||d0[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});Vf.displayName=mo;var Kf="MenuSubContent",qf=x.forwardRef((e,t)=>{const n=Nf(zt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=er(zt,e.__scopeMenu),i=po(zt,e.__scopeMenu),a=Wf(Kf,e.__scopeMenu),l=x.useRef(null),c=Xe(t,l);return d.jsx(ho.Provider,{scope:e.__scopeMenu,children:d.jsx(Dt,{present:r||s.open,children:d.jsx(ho.Slot,{scope:e.__scopeMenu,children:d.jsx(Aa,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:c,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:u=>{var f;i.isUsingKeyboardRef.current&&((f=l.current)==null||f.focus()),u.preventDefault()},onCloseAutoFocus:u=>u.preventDefault(),onFocusOutside:ye(e.onFocusOutside,u=>{u.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ye(e.onEscapeKeyDown,u=>{i.onClose(),u.preventDefault()}),onKeyDown:ye(e.onKeyDown,u=>{var p;const f=u.currentTarget.contains(u.target),h=f0[i.dir].includes(u.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),u.preventDefault())})})})})})});qf.displayName=Kf;function Gf(e){return e?"open":"closed"}function Ns(e){return e==="indeterminate"}function _a(e){return Ns(e)?"indeterminate":e?"checked":"unchecked"}function P0(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function R0(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function O0(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=R0(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function M0(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],c=a.x,u=a.y,f=l.x,h=l.y;u>r!=h>r&&n<(f-c)*(r-u)/(h-u)+c&&(o=!o)}return o}function D0(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return M0(n,t)}function go(e){return t=>t.pointerType==="mouse"?e(t):void 0}var L0=Af,$0=ka,F0=jf,z0=_f,B0=Na,U0=Pf,H0=As,W0=Mf,V0=Lf,K0=Ff,q0=Bf,G0=Uf,Y0=Hf,X0=Vf,J0=qf,js="DropdownMenu",[Z0,bT]=Rn(js,[Ef]),xt=Ef(),[Q0,Yf]=Z0(js),Xf=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=xt(t),c=x.useRef(null),[u,f]=as({prop:o,defaultProp:s??!1,onChange:i,caller:js});return d.jsx(Q0,{scope:t,triggerId:Rt(),triggerRef:c,contentId:Rt(),open:u,onOpenChange:f,onOpenToggle:x.useCallback(()=>f(h=>!h),[f]),modal:a,children:d.jsx(L0,{...l,open:u,onOpenChange:f,dir:r,modal:a,children:n})})};Xf.displayName=js;var Jf="DropdownMenuTrigger",Zf=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Yf(Jf,n),i=xt(n);return d.jsx($0,{asChild:!0,...i,children:d.jsx(Ae.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":r?"":void 0,disabled:r,...o,ref:Pn(t,s.triggerRef),onPointerDown:ye(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:ye(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});Zf.displayName=Jf;var eS="DropdownMenuPortal",Qf=e=>{const{__scopeDropdownMenu:t,...n}=e,r=xt(t);return d.jsx(F0,{...r,...n})};Qf.displayName=eS;var eh="DropdownMenuContent",th=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Yf(eh,n),s=xt(n),i=x.useRef(!1);return d.jsx(z0,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:ye(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:ye(e.onInteractOutside,a=>{const l=a.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,u=l.button===2||c;(!o.modal||u)&&(i.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)"}})});th.displayName=eh;var tS="DropdownMenuGroup",nS=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=xt(n);return d.jsx(B0,{...o,...r,ref:t})});nS.displayName=tS;var rS="DropdownMenuLabel",nh=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=xt(n);return d.jsx(U0,{...o,...r,ref:t})});nh.displayName=rS;var oS="DropdownMenuItem",rh=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=xt(n);return d.jsx(H0,{...o,...r,ref:t})});rh.displayName=oS;var sS="DropdownMenuCheckboxItem",oh=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=xt(n);return d.jsx(W0,{...o,...r,ref:t})});oh.displayName=sS;var iS="DropdownMenuRadioGroup",aS=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=xt(n);return d.jsx(V0,{...o,...r,ref:t})});aS.displayName=iS;var lS="DropdownMenuRadioItem",sh=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=xt(n);return d.jsx(K0,{...o,...r,ref:t})});sh.displayName=lS;var cS="DropdownMenuItemIndicator",ih=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=xt(n);return d.jsx(q0,{...o,...r,ref:t})});ih.displayName=cS;var uS="DropdownMenuSeparator",ah=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=xt(n);return d.jsx(G0,{...o,...r,ref:t})});ah.displayName=uS;var dS="DropdownMenuArrow",fS=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=xt(n);return d.jsx(Y0,{...o,...r,ref:t})});fS.displayName=dS;var hS="DropdownMenuSubTrigger",lh=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=xt(n);return d.jsx(X0,{...o,...r,ref:t})});lh.displayName=hS;var pS="DropdownMenuSubContent",ch=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=xt(n);return d.jsx(J0,{...o,...r,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)"}})});ch.displayName=pS;var mS=Xf,gS=Zf,xS=Qf,uh=th,dh=nh,fh=rh,hh=oh,ph=sh,mh=ih,gh=ah,xh=lh,bh=ch;const Pa=mS,Ra=gS,bS=x.forwardRef(({className:e,inset:t,children:n,...r},o)=>d.jsxs(xh,{ref:o,className:he("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),...r,children:[n,d.jsx(xe.ChevronRight,{className:"ml-auto h-4 w-4"})]}));bS.displayName=xh.displayName;const wS=x.forwardRef(({className:e,...t},n)=>d.jsx(bh,{ref:n,className:he("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}));wS.displayName=bh.displayName;const _s=x.forwardRef(({className:e,sideOffset:t=4,...n},r)=>d.jsx(xS,{children:d.jsx(uh,{ref:r,sideOffset:t,className:he("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),...n})}));_s.displayName=uh.displayName;const tr=x.forwardRef(({className:e,inset:t,...n},r)=>d.jsx(fh,{ref:r,className:he("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),...n}));tr.displayName=fh.displayName;const yS=x.forwardRef(({className:e,children:t,checked:n,...r},o)=>d.jsxs(hh,{ref:o,className:he("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:n,...r,children:[d.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:d.jsx(mh,{children:d.jsx(xe.Check,{className:"h-4 w-4"})})}),t]}));yS.displayName=hh.displayName;const vS=x.forwardRef(({className:e,children:t,...n},r)=>d.jsxs(ph,{ref:r,className:he("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),...n,children:[d.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:d.jsx(mh,{children:d.jsx(xe.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));vS.displayName=ph.displayName;const SS=x.forwardRef(({className:e,inset:t,...n},r)=>d.jsx(dh,{ref:r,className:he("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));SS.displayName=dh.displayName;const CS=x.forwardRef(({className:e,...t},n)=>d.jsx(gh,{ref:n,className:he("-mx-1 my-1 h-px bg-muted",e),...t}));CS.displayName=gh.displayName;const wh=x.forwardRef(({className:e,...t},n)=>d.jsx("textarea",{className:he("flex min-h-[40px] 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:n,...t}));wh.displayName="Textarea";const TS=1e4;function Oa({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=TS,value:i,onValueChange:a,onSend:l,onCancelEdit:c,onStop:u,className:f="",textareaClassName:h="",allowEmptySend:p=!1,sendButtonClassName:m,validate:b,onValidationError:g}){const w=i!==void 0,[y,k]=v.useState(e),E=(w?i:y)??"",[S,C]=v.useTransition(),T=v.useRef(null),N=v.useRef(0),j=v.useRef(null),_=v.useRef("");v.useEffect(()=>{if(!w&&(k(e??""),j.current=null,T.current)){const A=!e||e.trim()==="",O=44;A?T.current.style.height=`${O}px`:(T.current.style.height="auto",T.current.style.height=`${Math.max(T.current.scrollHeight,O)}px`)}},[e,t,w]);const[D,z]=v.useState(null),H=v.useCallback(A=>A.length>s?`Message too long (${A.length}/${s} characters)`:null,[s]),P=v.useMemo(()=>b??H,[b,H]),M=v.useCallback(A=>{const O=P(A);return z(O),g==null||g(O),_.current=A,O},[P,g]),F=v.useCallback(()=>{const A=T.current;if(!A)return;const O=!A.value||A.value.trim()==="",V=44;if(O){A.style.height=`${V}px`;return}A.style.height="auto";const Z=Math.max(A.scrollHeight,V);A.style.height=`${Z}px`},[]);v.useEffect(()=>{F()},[F,E]),v.useEffect(()=>{if(!D)return;const A=(E??"").trim();_.current!==A&&M(A)},[E,D,M]);const ne=v.useCallback((A,{fromUser:O})=>{w||k(A),O&&(a==null||a(A))},[w,a]),U=v.useCallback(async A=>{A&&A.preventDefault();const O=(E??"").trim();if(!O&&!p||M(O))return;const V=++N.current;j.current={id:V,shouldClear:!0},C(()=>{var Z,$,X;try{const oe=l(O);oe&&typeof oe.then=="function"?oe.then(()=>{var ue,le;((ue=j.current)==null?void 0:ue.id)===V&&j.current.shouldClear&&(w||(k(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((le=j.current)==null?void 0:le.id)===V&&(j.current=null)}).catch(()=>{var ue;((ue=j.current)==null?void 0:ue.id)===V&&(j.current=null)}):(((Z=j.current)==null?void 0:Z.id)===V&&j.current.shouldClear&&(w||(k(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),(($=j.current)==null?void 0:$.id)===V&&(j.current=null))}catch{((X=j.current)==null?void 0:X.id)===V&&(j.current=null)}})},[E,l,p,w,a,M]),W=v.useCallback(A=>{const O=A.target.value;ne(O,{fromUser:!0}),j.current&&(j.current.shouldClear=!1),T.current&&(T.current.style.height="auto",T.current.style.height=`${T.current.scrollHeight}px`),D&&M(O.trim())},[ne,M,D]),Y=v.useCallback(A=>{A.key==="Enter"&&!A.shiftKey?(A.preventDefault(),U()):A.key==="Escape"&&t&&(A.preventDefault(),c==null||c())},[U,t,c]),G=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${h}`;return d.jsx("div",{className:`w-full ${f}`,children:d.jsxs("div",{className:"flex items-end gap-2",children:[d.jsxs("div",{className:"flex-1",children:[d.jsx(wh,{ref:T,value:E,onChange:W,onKeyDown:Y,placeholder:t?"Edit your message...":n,className:G,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"}),D&&d.jsx("p",{className:"mt-1 text-xs text-destructive font-medium",children:D})]}),d.jsx("div",{children:r?d.jsx(Je,{type:"button",onClick:()=>{u==null||u()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!u,children:d.jsx(xe.Square,{size:16})}):d.jsx(Je,{type:"button",onClick:A=>void U(A),size:"icon",className:`shrink-0 ${m??""}`,title:t?"Save changes":"Send message",disabled:o||!E.trim()&&!p||S||r,children:d.jsx(xe.Send,{size:16})})})]})})}const kS=v.memo(Oa);function Ps({composerValue:e,onComposerChange:t,onSend:n,onCancelEdit:r,onStop:o,editingMessageId:s=null,editingInitialValue:i="",placeholder:a="Type your message...",isStreaming:l=!1,disabled:c=!1,textareaClassName:u="",customStyles:f={},enableFileUpload:h=!1,enableExcelUpload:p=!1,onExcelUpload:m,onFilesChange:b,onError:g,allowEmptySend:w=!1,inputError:y=null}){const[k,E]=v.useState([]),S=v.useRef(null),C=v.useRef(null),[T,N]=v.useState(0),[j,_]=v.useState(0),[D,z]=v.useState(!1),[H,P]=v.useState(null),[M,F]=v.useState(null),ne=v.useCallback(()=>{S.current&&(S.current.value=""),C.current&&(C.current.value=""),N(O=>O+1),_(O=>O+1)},[]),U=v.useCallback(O=>{E(V=>{const Z=[...V,...O];return b==null||b(Z),Z})},[b]),W=v.useCallback(O=>{const V=Array.from(O.target.files||[]);U(V),O.target.value=""},[U]),Y=v.useCallback(O=>{E(V=>{const Z=V.filter(($,X)=>X!==O);return Z.length===0&&ne(),b==null||b(Z),Z})},[b,ne]),q=v.useCallback(async O=>{const V=(O.target.files||[])[0];if(V&&(P(null),F(null),!!m)){z(!0);try{await m(V),P(`Uploaded ${V.name} - processing through chat stream`)}catch(Z){const $=Z instanceof Error?Z.message:"Failed to upload Excel file";F($),g==null||g($)}finally{z(!1),O.target.value="",ne()}}},[m,g,ne]),R=v.useMemo(()=>w||k.length>0,[w,k]),G=v.useCallback(async O=>{const Z=await n(O,k);return k.length>0&&(E([]),b==null||b([]),ne()),Z},[n,ne,k]),A=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${s?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${y?"border-red-400":""} ${f.textarea||""} ${u}`;return d.jsxs(d.Fragment,{children:[(h||p)&&d.jsxs("div",{className:"mb-3 space-y-3",children:[h&&d.jsxs(d.Fragment,{children:[d.jsx("input",{ref:S,type:"file",multiple:!0,onChange:W,className:"hidden"},T),k.length>0&&d.jsx("div",{className:"flex flex-wrap gap-2",children:k.map((O,V)=>d.jsxs("div",{className:"flex items-center gap-2 bg-gray-100 dark:bg-gray-800 rounded-lg px-3 py-2 text-sm text-gray-900 dark:text-gray-100",children:[d.jsx(xe.Paperclip,{size:14}),d.jsx("span",{className:"truncate max-w-[150px]",children:O.name}),d.jsx(Je,{variant:"ghost",size:"sm",onClick:()=>Y(V),className:"h-4 w-4 p-0 text-gray-500 dark:text-gray-400 hover:text-red-500 dark:hover:text-red-400","aria-label":`Remove ${O.name}`,children:d.jsx(xe.X,{size:12})})]},V))})]}),p&&d.jsxs(d.Fragment,{children:[d.jsx("input",{ref:C,type:"file",accept:".xls,.xlsx,.xlsm",onChange:q,className:"hidden"},j),D&&d.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[d.jsx(xe.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),H&&!D&&d.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:H}),M&&!D&&d.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:M})]})]}),d.jsxs("div",{className:"flex items-end gap-2",children:[(h||p)&&d.jsxs(Pa,{children:[d.jsx(Ra,{asChild:!0,children:d.jsx(Je,{type:"button",size:"icon",variant:"outline",disabled:l||c,title:"More input actions",className:f.moreButton||"",children:d.jsx(xe.Plus,{size:16})})}),d.jsxs(_s,{align:"start",sideOffset:6,className:"w-52",children:[h&&d.jsxs(tr,{onClick:()=>{var O;return(O=S.current)==null?void 0:O.click()},className:"cursor-pointer",children:[d.jsx(xe.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),p&&d.jsxs(tr,{onClick:()=>{var O;D||(O=C.current)==null||O.click()},className:`cursor-pointer ${D?"opacity-60 pointer-events-none":""}`,children:[d.jsx(xe.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),d.jsx("div",{className:"flex-1",children:d.jsx(kS,{initialValue:i,editingMessageId:s,value:e,onValueChange:t,placeholder:s?"Edit your message...":a,isStreaming:l,disabled:c,onSend:G,onCancelEdit:r,onStop:o,allowEmptySend:R,textareaClassName:A,sendButtonClassName:f.sendButton})})]})]})}v.memo(Ps);function yh({submit:e,chatRequest:t,lastCheckpointId:n,lastCheckpointNs:r,onMessageSent:o,onExcelUploadSuccess:s,onError:i,enableMessageEditing:a,messages:l,unifiedMessages:c,setPendingAssistantResponse:u,project:f,onEvent:h,activeThreadId:p}){const[m,b]=v.useState(null),[g,w]=v.useState(""),[y,k]=v.useState(null),[E,S]=v.useState(null),[C,T]=v.useState(!1),[N,j]=v.useState(""),_=v.useRef(N),D=v.useRef(null);v.useEffect(()=>{if(!m)if(p){const Y=localStorage.getItem(Po(p));j(Y||"")}else j("")},[p,m]);const z=v.useCallback(Y=>{j(Y),!m&&p&&localStorage.setItem(Po(p),Y)},[p,m]);v.useEffect(()=>{_.current=N},[N]),v.useEffect(()=>{if(!m){D.current=null;return}D.current===null&&(D.current=_.current),z(g??"")},[g,m,z]);const H=v.useCallback(Y=>{z(Y)},[z]),P=async(Y,q)=>{const R=Array.isArray(q)?{files:q}:q??{},G=R.files??[],A=R.contentParts??[],O=Y.trim();if(!(!O&&G.length===0&&A.length===0))try{const V=G.map(async le=>{try{const Ce=await ii.uploadFile(le);return{file:le,record:Ce}}catch(Ce){throw console.error("Failed to upload file",le.name,Ce),new Error(`Failed to upload ${le.name}`)}}),$=(await Promise.all(V)).map(({record:le})=>{const Ce=le.mime_type;return Ce.startsWith("image/")?{type:"image_url",image_url:{url:le.content_url}}:{type:"file",url:le.content_url,mimeType:Ce,name:le.filename,size:le.size}}),X=[...A,...$],oe=m?(y==null?void 0:y.checkpointId)??n??void 0:n??void 0,ue=m?(y==null?void 0:y.checkpointNs)??r??void 0:r??void 0;await e({text:O||"",contentParts:X,attachments:[],payload:t.payload},{checkpointId:oe,checkpointNs:ue,project:f??void 0,edit:!!m,originalMessageId:m??void 0,config:t.config,onEvent:h}),o==null||o(O),u(!0),p&&localStorage.removeItem(Po(p)),z(""),S(null),b(null),w(""),k(null)}catch(V){const Z=(V==null?void 0:V.message)||"Failed to send message";S(Z),i==null||i(Z),u(!1)}},M=(Y,q)=>{q||P(Y,{files:[]})},F=v.useCallback(async Y=>{await e({attachments:[Y],payload:t.payload},{checkpointId:n??void 0,checkpointNs:r??void 0,project:f??void 0,config:t.config,onEvent:h}),s==null||s({file:Y})},[n,r,t,s,e]),ne=v.useCallback((Y,q,R)=>{a&&(D.current=N,b(Y),w(q),k({checkpointId:(R==null?void 0:R.checkpointId)??null,checkpointNs:(R==null?void 0:R.checkpointNs)??null}),S(null))},[N,a]),U=v.useCallback(()=>{b(null),w(""),k(null),S(null);const Y=D.current;Y!==null&&j(Y),D.current=null},[]),W=v.useCallback(Y=>{let q=null;for(let O=Y-1;O>=0;O--)if(l[O].role==="user"){q=l[O];break}if(!q)return;const R=Array.isArray(q.content)?q.content:[],A=R.filter(O=>(O==null?void 0:O.type)==="text").map(O=>O.text).join("")||(()=>{try{return JSON.stringify(R,null,2)}catch{return String(R)}})();A&&e({text:A,payload:t.payload},{checkpointId:n??void 0,checkpointNs:r??void 0,edit:!0,originalMessageId:q.id,config:t.config,onEvent:h})},[l,e,n,r,t]);return{editingMessageId:m,editingInitialValue:g,inputError:E,setInputError:S,dismissError:C,setDismissError:T,composerValue:N,handleComposerChange:H,handleSendMessage:P,handleQuickPrompt:M,handleExcelUpload:F,startEditing:ne,cancelEditing:U,handleRegenerateCb:W,messages:c??l}}var Rs="Dialog",[vh,wT]=Rn(Rs),[ES,Zt]=vh(Rs),Sh=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=x.useRef(null),l=x.useRef(null),[c,u]=as({prop:r,defaultProp:o??!1,onChange:s,caller:Rs});return d.jsx(ES,{scope:t,triggerRef:a,contentRef:l,contentId:Rt(),titleId:Rt(),descriptionId:Rt(),open:c,onOpenChange:u,onOpenToggle:x.useCallback(()=>u(f=>!f),[u]),modal:i,children:n})};Sh.displayName=Rs;var Ch="DialogTrigger",IS=x.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Zt(Ch,n),s=Xe(t,o.triggerRef);return d.jsx(Ae.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":La(o.open),...r,ref:s,onClick:ye(e.onClick,o.onOpenToggle)})});IS.displayName=Ch;var Ma="DialogPortal",[AS,Th]=vh(Ma,{forceMount:void 0}),kh=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=Zt(Ma,t);return d.jsx(AS,{scope:t,forceMount:n,children:x.Children.map(r,i=>d.jsx(Dt,{present:n||s.open,children:d.jsx(ma,{asChild:!0,container:o,children:i})}))})};kh.displayName=Ma;var Os="DialogOverlay",Eh=x.forwardRef((e,t)=>{const n=Th(Os,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=Zt(Os,e.__scopeDialog);return s.modal?d.jsx(Dt,{present:r||s.open,children:d.jsx(jS,{...o,ref:t})}):null});Eh.displayName=Os;var NS=lr.createSlot("DialogOverlay.RemoveScroll"),jS=x.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Zt(Os,n);return d.jsx(Ca,{as:NS,allowPinchZoom:!0,shards:[o.contentRef],children:d.jsx(Ae.div,{"data-state":La(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),nr="DialogContent",Ih=x.forwardRef((e,t)=>{const n=Th(nr,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=Zt(nr,e.__scopeDialog);return d.jsx(Dt,{present:r||s.open,children:s.modal?d.jsx(_S,{...o,ref:t}):d.jsx(PS,{...o,ref:t})})});Ih.displayName=nr;var _S=x.forwardRef((e,t)=>{const n=Zt(nr,e.__scopeDialog),r=x.useRef(null),o=Xe(t,n.contentRef,r);return x.useEffect(()=>{const s=r.current;if(s)return ff(s)},[]),d.jsx(Ah,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ye(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:ye(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:ye(e.onFocusOutside,s=>s.preventDefault())})}),PS=x.forwardRef((e,t)=>{const n=Zt(nr,e.__scopeDialog),r=x.useRef(!1),o=x.useRef(!1);return d.jsx(Ah,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i,a;(i=e.onCloseAutoFocus)==null||i.call(e,s),s.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),s.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:s=>{var l,c;(l=e.onInteractOutside)==null||l.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const i=s.target;((c=n.triggerRef.current)==null?void 0:c.contains(i))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),Ah=x.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=Zt(nr,n),l=x.useRef(null),c=Xe(t,l);return bd(),d.jsxs(d.Fragment,{children:[d.jsx(ta,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:d.jsx(Ji,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":La(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),d.jsxs(d.Fragment,{children:[d.jsx(RS,{titleId:a.titleId}),d.jsx(MS,{contentRef:l,descriptionId:a.descriptionId})]})]})}),Da="DialogTitle",Nh=x.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Zt(Da,n);return d.jsx(Ae.h2,{id:o.titleId,...r,ref:t})});Nh.displayName=Da;var jh="DialogDescription",_h=x.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Zt(jh,n);return d.jsx(Ae.p,{id:o.descriptionId,...r,ref:t})});_h.displayName=jh;var Ph="DialogClose",Rh=x.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Zt(Ph,n);return d.jsx(Ae.button,{type:"button",...r,ref:t,onClick:ye(e.onClick,()=>o.onOpenChange(!1))})});Rh.displayName=Ph;function La(e){return e?"open":"closed"}var Oh="DialogTitleWarning",[yT,Mh]=mw(Oh,{contentName:nr,titleName:Da,docsSlug:"dialog"}),RS=({titleId:e})=>{const t=Mh(Oh),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
128
128
 
129
129
  If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
130
130
 
131
- For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return x.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},OS="DialogDescriptionWarning",MS=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Mh(OS).contentName}}.`;return x.useEffect(()=>{var s;const o=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&o&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},Dh=Sh,Lh=kh,$a=Eh,Fa=Ih,bo=Nh,$h=_h,DS=Rh;const Fh=Dh,LS=Lh,zh=x.forwardRef(({className:e,...t},n)=>d.jsx($a,{ref:n,className:fe("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t}));zh.displayName=$a.displayName;const za=x.forwardRef(({className:e,children:t,...n},r)=>{const o=x.useMemo(()=>{let s=!1;function i(a){x.Children.forEach(a,l=>{if(s||!x.isValidElement(l))return;const c=l.type;if(c===bo||(c==null?void 0:c.displayName)===bo.displayName||(c==null?void 0:c.name)==="DialogTitle"){s=!0;return}l.props&&l.props.children&&i(l.props.children)})}return i(t),s},[t]);return d.jsxs(LS,{children:[d.jsx(zh,{}),d.jsxs(Fa,{ref:r,className:fe("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 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-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",e),...n,children:[!o&&d.jsx(bo,{className:"sr-only",children:"Dialog"}),t,d.jsxs(DS,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[d.jsx(me.X,{className:"h-4 w-4"}),d.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});za.displayName=Fa.displayName;const Ba=({className:e,...t})=>d.jsx("div",{className:fe("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Ba.displayName="DialogHeader";const Ua=x.forwardRef(({className:e,...t},n)=>d.jsx(bo,{ref:n,className:fe("text-lg font-semibold leading-none tracking-tight",e),...t}));Ua.displayName=bo.displayName;const Bh=x.forwardRef(({className:e,...t},n)=>d.jsx($h,{ref:n,className:fe("text-sm text-muted-foreground",e),...t}));Bh.displayName=$h.displayName;function $S(e,[t,n]){return Math.min(n,Math.max(t,e))}function FS(e,t){return x.useReducer((n,r)=>t[n][r]??n,e)}var Ha="ScrollArea",[Uh,vT]=Mn(Ha),[zS,Wt]=Uh(Ha),Hh=x.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=x.useState(null),[c,u]=x.useState(null),[f,h]=x.useState(null),[p,m]=x.useState(null),[b,g]=x.useState(null),[w,y]=x.useState(0),[k,E]=x.useState(0),[S,C]=x.useState(!1),[T,A]=x.useState(!1),N=Ge(t,L=>l(L)),j=Yi(o);return d.jsx(zS,{scope:n,type:r,dir:j,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:u,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:m,scrollbarXEnabled:S,onScrollbarXEnabledChange:C,scrollbarY:b,onScrollbarYChange:g,scrollbarYEnabled:T,onScrollbarYEnabledChange:A,onCornerWidthChange:y,onCornerHeightChange:E,children:d.jsx(je.div,{dir:j,...i,ref:N,style:{position:"relative","--radix-scroll-area-corner-width":w+"px","--radix-scroll-area-corner-height":k+"px",...e.style}})})});Hh.displayName=Ha;var Wh="ScrollAreaViewport",Vh=x.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=Wt(Wh,n),a=x.useRef(null),l=Ge(t,a,i.onViewportChange);return d.jsxs(d.Fragment,{children:[d.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}),d.jsx(je.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:d.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});Vh.displayName=Wh;var un="ScrollAreaScrollbar",Wa=x.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Wt(un,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return x.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?d.jsx(BS,{...r,ref:t,forceMount:n}):o.type==="scroll"?d.jsx(US,{...r,ref:t,forceMount:n}):o.type==="auto"?d.jsx(Kh,{...r,ref:t,forceMount:n}):o.type==="always"?d.jsx(Va,{...r,ref:t}):null});Wa.displayName=un;var BS=x.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Wt(un,e.__scopeScrollArea),[s,i]=x.useState(!1);return x.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const c=()=>{window.clearTimeout(l),i(!0)},u=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",c),a.addEventListener("pointerleave",u),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",c),a.removeEventListener("pointerleave",u)}}},[o.scrollArea,o.scrollHideDelay]),d.jsx(Lt,{present:n||s,children:d.jsx(Kh,{"data-state":s?"visible":"hidden",...r,ref:t})})}),US=x.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Wt(un,e.__scopeScrollArea),s=e.orientation==="horizontal",i=$s(()=>l("SCROLL_END"),100),[a,l]=FS("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 x.useEffect(()=>{if(a==="idle"){const c=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[a,o.scrollHideDelay,l]),x.useEffect(()=>{const c=o.viewport,u=s?"scrollLeft":"scrollTop";if(c){let f=c[u];const h=()=>{const p=c[u];f!==p&&(l("SCROLL"),i()),f=p};return c.addEventListener("scroll",h),()=>c.removeEventListener("scroll",h)}},[o.viewport,s,l,i]),d.jsx(Lt,{present:n||a!=="hidden",children:d.jsx(Va,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ye(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:ye(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),Kh=x.forwardRef((e,t)=>{const n=Wt(un,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=x.useState(!1),a=e.orientation==="horizontal",l=$s(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,u=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:u)}},10);return jr(n.viewport,l),jr(n.content,l),d.jsx(Lt,{present:r||s,children:d.jsx(Va,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Va=x.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=Wt(un,e.__scopeScrollArea),s=x.useRef(null),i=x.useRef(0),[a,l]=x.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=Jh(a.viewport,a.content),u={...r,sizes:a,onSizesChange:l,hasThumb:c>0&&c<1,onThumbChange:h=>s.current=h,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:h=>i.current=h};function f(h,p){return GS(h,i.current,a,p)}return n==="horizontal"?d.jsx(HS,{...u,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=Zh(h,a,o.dir);s.current.style.transform=`translate3d(${p}px, 0, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollLeft=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollLeft=f(h,o.dir))}}):n==="vertical"?d.jsx(WS,{...u,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=Zh(h,a);s.current.style.transform=`translate3d(0, ${p}px, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollTop=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollTop=f(h))}}):null}),HS=x.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Wt(un,e.__scopeScrollArea),[i,a]=x.useState(),l=x.useRef(null),c=Ge(t,l,s.onScrollbarXChange);return x.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),d.jsx(Gh,{"data-orientation":"horizontal",...o,ref:c,sizes:n,style:{bottom:0,left:s.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:s.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":Ls(n)+"px",...e.style},onThumbPointerDown:u=>e.onThumbPointerDown(u.x),onDragScroll:u=>e.onDragScroll(u.x),onWheelScroll:(u,f)=>{if(s.viewport){const h=s.viewport.scrollLeft+u.deltaX;e.onWheelScroll(h),ep(h,f)&&u.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:Ds(i.paddingLeft),paddingEnd:Ds(i.paddingRight)}})}})}),WS=x.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Wt(un,e.__scopeScrollArea),[i,a]=x.useState(),l=x.useRef(null),c=Ge(t,l,s.onScrollbarYChange);return x.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),d.jsx(Gh,{"data-orientation":"vertical",...o,ref:c,sizes:n,style:{top:0,right:s.dir==="ltr"?0:void 0,left:s.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":Ls(n)+"px",...e.style},onThumbPointerDown:u=>e.onThumbPointerDown(u.y),onDragScroll:u=>e.onDragScroll(u.y),onWheelScroll:(u,f)=>{if(s.viewport){const h=s.viewport.scrollTop+u.deltaY;e.onWheelScroll(h),ep(h,f)&&u.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:Ds(i.paddingTop),paddingEnd:Ds(i.paddingBottom)}})}})}),[VS,qh]=Uh(un),Gh=x.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:c,onWheelScroll:u,onResize:f,...h}=e,p=Wt(un,n),[m,b]=x.useState(null),g=Ge(t,N=>b(N)),w=x.useRef(null),y=x.useRef(""),k=p.viewport,E=r.content-r.viewport,S=ft(u),C=ft(l),T=$s(f,10);function A(N){if(w.current){const j=N.clientX-w.current.left,L=N.clientY-w.current.top;c({x:j,y:L})}}return x.useEffect(()=>{const N=j=>{const L=j.target;(m==null?void 0:m.contains(L))&&S(j,E)};return document.addEventListener("wheel",N,{passive:!1}),()=>document.removeEventListener("wheel",N,{passive:!1})},[k,m,E,S]),x.useEffect(C,[r,C]),jr(m,T),jr(p.content,T),d.jsx(VS,{scope:n,scrollbar:m,hasThumb:o,onThumbChange:ft(s),onThumbPointerUp:ft(i),onThumbPositionChange:C,onThumbPointerDown:ft(a),children:d.jsx(je.div,{...h,ref:g,style:{position:"absolute",...h.style},onPointerDown:ye(e.onPointerDown,N=>{N.button===0&&(N.target.setPointerCapture(N.pointerId),w.current=m.getBoundingClientRect(),y.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),A(N))}),onPointerMove:ye(e.onPointerMove,A),onPointerUp:ye(e.onPointerUp,N=>{const j=N.target;j.hasPointerCapture(N.pointerId)&&j.releasePointerCapture(N.pointerId),document.body.style.webkitUserSelect=y.current,p.viewport&&(p.viewport.style.scrollBehavior=""),w.current=null})})})}),Ms="ScrollAreaThumb",Yh=x.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=qh(Ms,e.__scopeScrollArea);return d.jsx(Lt,{present:n||o.hasThumb,children:d.jsx(KS,{ref:t,...r})})}),KS=x.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=Wt(Ms,n),i=qh(Ms,n),{onThumbPositionChange:a}=i,l=Ge(t,f=>i.onThumbChange(f)),c=x.useRef(void 0),u=$s(()=>{c.current&&(c.current(),c.current=void 0)},100);return x.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(u(),!c.current){const p=YS(f,a);c.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,u,a]),d.jsx(je.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:l,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:ye(e.onPointerDownCapture,f=>{const p=f.target.getBoundingClientRect(),m=f.clientX-p.left,b=f.clientY-p.top;i.onThumbPointerDown({x:m,y:b})}),onPointerUp:ye(e.onPointerUp,i.onThumbPointerUp)})});Yh.displayName=Ms;var Ka="ScrollAreaCorner",Xh=x.forwardRef((e,t)=>{const n=Wt(Ka,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?d.jsx(qS,{...e,ref:t}):null});Xh.displayName=Ka;var qS=x.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=Wt(Ka,n),[s,i]=x.useState(0),[a,l]=x.useState(0),c=!!(s&&a);return jr(o.scrollbarX,()=>{var f;const u=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(u),l(u)}),jr(o.scrollbarY,()=>{var f;const u=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(u),i(u)}),c?d.jsx(je.div,{...r,ref:t,style:{width:s,height:a,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function Ds(e){return e?parseInt(e,10):0}function Jh(e,t){const n=e/t;return isNaN(n)?0:n}function Ls(e){const t=Jh(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function GS(e,t,n,r="ltr"){const o=Ls(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,c=n.scrollbar.size-n.scrollbar.paddingEnd-a,u=n.content-n.viewport,f=r==="ltr"?[0,u]:[u*-1,0];return Qh([l,c],f)(e)}function Zh(e,t,n="ltr"){const r=Ls(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],c=$S(e,l);return Qh([0,i],[0,a])(c)}function Qh(e,t){return n=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const r=(t[1]-t[0])/(e[1]-e[0]);return t[0]+r*(n-e[0])}}function ep(e,t){return e>0&&e<t}var YS=(e,t=()=>{})=>{let n={left:e.scrollLeft,top:e.scrollTop},r=0;return function o(){const s={left:e.scrollLeft,top:e.scrollTop},i=n.left!==s.left,a=n.top!==s.top;(i||a)&&t(),n=s,r=window.requestAnimationFrame(o)}(),()=>window.cancelAnimationFrame(r)};function $s(e,t){const n=ft(e),r=x.useRef(0);return x.useEffect(()=>()=>window.clearTimeout(r.current),[]),x.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function jr(e,t){const n=ft(t);rn(()=>{let r=0;if(e){const o=new ResizeObserver(()=>{cancelAnimationFrame(r),r=window.requestAnimationFrame(n)});return o.observe(e),()=>{window.cancelAnimationFrame(r),o.unobserve(e)}}},[e,n])}var tp=Hh,XS=Vh,JS=Xh;const qa=x.forwardRef(({className:e,children:t,...n},r)=>d.jsxs(tp,{ref:r,className:fe("relative overflow-hidden",e),...n,children:[d.jsx(XS,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),d.jsx(np,{}),d.jsx(JS,{})]}));qa.displayName=tp.displayName;const np=x.forwardRef(({className:e,orientation:t="vertical",...n},r)=>d.jsx(Wa,{ref:r,orientation:t,className:fe("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:d.jsx(Yh,{className:"relative flex-1 rounded-full bg-border"})}));np.displayName=Wa.displayName;function ZS({isOpen:e,onOpenChange:t,toolCall:n}){if(!n)return null;const{call:r,result:o,state:s}=n,i=r.args,a=o==null?void 0:o.content;return d.jsx(Fh,{open:e,onOpenChange:t,children:d.jsxs(za,{className:"max-w-2xl max-h-[85vh] flex flex-col p-0 gap-0 overflow-hidden",children:[d.jsxs(Ba,{className:"p-6 border-b shrink-0",children:[d.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[d.jsxs(Ua,{className:"text-xl font-bold",children:["Tool Usage: ",r.name]}),d.jsx("span",{className:fe("text-[10px] px-2 py-0.5 rounded-full font-bold uppercase tracking-wider",s==="pending"?"bg-blue-100 text-blue-700":s==="error"?"bg-red-100 text-red-700":"bg-green-100 text-green-700"),children:s})]}),d.jsxs(Bh,{children:["ID: ",r.id]})]}),d.jsx(qa,{className:"flex-1 min-h-0 bg-muted/30",children:d.jsxs("div",{className:"p-6 space-y-6 pb-12",children:[d.jsxs("section",{className:"space-y-2",children:[d.jsx("h3",{className:"text-xs font-bold uppercase tracking-widest text-muted-foreground",children:"Input Arguments"}),d.jsx("div",{className:"rounded-lg border bg-background/50 shadow-sm overflow-hidden",children:d.jsx("pre",{className:"p-4 text-xs font-mono leading-relaxed overflow-x-auto whitespace-pre-wrap break-words",children:JSON.stringify(i,null,2)})})]}),d.jsxs("section",{className:"space-y-2",children:[d.jsxs("h3",{className:"text-xs font-bold uppercase tracking-widest text-muted-foreground flex items-center justify-between",children:[d.jsx("span",{children:"Output Result"}),(o==null?void 0:o.createdAt)&&d.jsx("span",{className:"font-normal normal-case text-[10px] opacity-60",children:new Date(o.createdAt).toLocaleTimeString()})]}),d.jsx("div",{className:"rounded-lg border bg-background/50 shadow-sm overflow-hidden min-h-[100px] flex",children:a?d.jsx("pre",{className:"p-4 text-xs font-mono leading-relaxed overflow-x-auto whitespace-pre-wrap break-words w-full",children:typeof a=="string"?a:JSON.stringify(a,null,2)}):d.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground/40 text-xs italic",children:s==="pending"?"Tool is currently executing...":"No output returned."})})]})]})})]})})}function _r({className:e="",placeholder:t="Type your message...",maxHeight:n=void 0,streamingDebounceMs:r=500,followNewMessages:o=!0,enableFileUpload:s=!0,enableExcelUpload:i=!1,enableMessageEditing:a=!0,showToolMessages:l=!0,toolConfig:c,toolRenderers:u,toolArtifactRenderers:f,payloadExtras:h={},customStyles:p={},messageCustomStyles:m,onMessageSent:b,onExcelUploadSuccess:g,onError:w,renderArtifactsInline:y=!0,emptyMessage:k}){var te,F,X;const{currentThreadId:E}=Hr(),S=qr(),C=Ec(),T=yh({submit:C.submit,chatRequest:{payload:h},lastCheckpointId:((te=S.checkpoint)==null?void 0:te.id)??null,lastCheckpointNs:((F=S.checkpoint)==null?void 0:F.namespace)??null,onMessageSent:b,onExcelUploadSuccess:g,onError:w,enableMessageEditing:a,messages:S.messages,unifiedMessages:C.messages,setPendingAssistantResponse:()=>{},activeThreadId:E??null}),A=S.interrupt,N=A?uc(A.id):null,j=N!==null?{type:"interrupt",id:N}:null,[L,B]=v.useState(!1),[W,O]=v.useState("desktop"),[D,z]=v.useState(!1),[ee,H]=v.useState(null),V=v.useRef(null);v.useEffect(()=>{const re=()=>{const ue=window.innerWidth;O(ue<640?"phone":ue<1024?"tablet":"desktop")};return re(),window.addEventListener("resize",re),()=>window.removeEventListener("resize",re)},[]);const Y=v.useCallback(async(re,ue,le)=>{try{B(!0),await S.respondToInterrupt(re,ue,le)}catch(Se){console.error("Failed to respond to interrupt:",Se)}finally{B(!1)}},[S]),q=v.useCallback(async re=>{var ue,le;z(!0);try{if(!re)await S.returnToLatest(),(ue=V.current)==null||ue.scrollToLatest();else{const Se=S.checkpoints.find(Me=>Me.checkpointId===re);await S.navigateToCheckpoint(re,(Se==null?void 0:Se.checkpointNs)??null),(le=V.current)==null||le.scrollToTop()}}finally{z(!1)}},[S]),M=v.useMemo(()=>c??{toolRenderers:u,toolArtifactRenderers:f,getToolExpandable:re=>re.name!=="ask_user_choice"},[c,u,f]),P=!!A||L,$=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${p.container||""}`,R=`flex-1 min-h-0 min-w-0 max-h-full w-full overflow-hidden overscroll-contain break-words break-anywhere p-4 ${A?"pb-32":""} bg-transparent ${p.messagesArea||""}`,G=`relative flex-shrink-0 w-full border-t p-4 bg-transparent ${p.inputArea||""}`;return d.jsxs("div",{className:$,children:[!!C.error&&!T.dismissError&&d.jsxs("div",{className:"flex-shrink-0 bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[d.jsx("span",{children:C.error}),d.jsx(Je,{variant:"ghost",size:"sm",onClick:()=>T.setDismissError(!0),className:"text-red-800 hover:bg-red-100",children:d.jsx(me.X,{size:16})})]}),d.jsxs("div",{className:`relative ${R}`,style:n?{maxHeight:n}:void 0,children:[d.jsx(Rc,{layoutSize:W,customStyles:p,messageCustomStyles:m,renderArtifactsInline:y,enableMessageEditing:a,editingMessageId:T.editingMessageId,showToolMessages:l,followNewMessages:o,showThinkingIndicator:C.isStreaming,streamingDebounceMs:r,toolConfig:M,checkpointIndex:S.checkpointIndex,activeCheckpointId:(X=S.checkpoint)==null?void 0:X.id,onSelectCheckpoint:q,pendingInterrupt:A,onEdit:T.startEditing,onRegenerate:T.handleRegenerateCb,onCancelEdit:T.cancelEditing,getInterruptOptions:()=>{},selectedToolCall:ee,onSelectToolCall:H,children:d.jsx(is,{ref:V,className:"h-full",style:{height:"100%"},messages:T.messages,isStreaming:C.isStreaming,emptyMessage:k})}),d.jsx(ZS,{isOpen:!!ee,onOpenChange:re=>!re&&H(null),toolCall:ee}),(C.connectionState==="reconnecting"||C.connectionState==="connecting")&&d.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-muted/80 px-3 py-1 text-xs font-medium text-foreground shadow-sm backdrop-blur-sm dark:bg-muted/60",children:d.jsxs("span",{className:"flex items-center gap-2",children:[d.jsx(me.Loader2,{className:"h-3 w-3 animate-spin"}),C.connectionState==="reconnecting"?"Reconnecting…":"Connecting…"]})}),S.isLoading||D?d.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[d.jsx(me.Loader2,{className:"h-6 w-6 animate-spin"}),d.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:S.isLoading?"Loading messages…":"Loading checkpoint…"})]}):null,A&&j&&d.jsx("div",{className:"pointer-events-auto absolute inset-x-0 bottom-6 z-30 flex justify-center px-4",children:d.jsx("div",{className:"w-full max-w-3xl",children:d.jsx(Yu,{interruptPart:j,onApprove:()=>Y(!0),onReject:()=>Y(!1),onSelectAlternative:(re,ue)=>Y(!0,ue),disabled:L,isActive:!0,payload:A.value})})})]}),d.jsxs("div",{className:G,children:[T.editingMessageId&&d.jsxs("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg flex items-center justify-between",children:[d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(me.Edit3,{size:16,className:"text-blue-600"}),d.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),d.jsx(Je,{variant:"ghost",size:"sm",onClick:T.cancelEditing,className:"text-blue-600 hover:bg-blue-100",children:d.jsx(me.X,{size:16})})]}),T.inputError&&d.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:T.inputError}),d.jsx(Ps,{composerValue:T.composerValue,onComposerChange:T.handleComposerChange,onSend:T.handleSendMessage,onCancelEdit:T.cancelEditing,onStop:C.stop,editingMessageId:T.editingMessageId,editingInitialValue:T.editingInitialValue,placeholder:T.editingMessageId?"Edit your message...":t,isStreaming:C.isStreaming,disabled:P,enableFileUpload:s,enableExcelUpload:i,onExcelUpload:T.handleExcelUpload,onError:w,customStyles:p,textareaClassName:p.textarea||"",allowEmptySend:!1,inputError:T.inputError})]})]})}var rp=1,QS=.9,eC=.8,tC=.17,Ga=.1,Ya=.999,nC=.9999,rC=.99,oC=/[\\\/_+.#"@\[\(\{&]/,sC=/[\\\/_+.#"@\[\(\{&]/g,iC=/[\s-]/,op=/[\s-]/g;function Xa(e,t,n,r,o,s,i){if(s===t.length)return o===e.length?rp:rC;var a=`${o},${s}`;if(i[a]!==void 0)return i[a];for(var l=r.charAt(s),c=n.indexOf(l,o),u=0,f,h,p,m;c>=0;)f=Xa(e,t,n,r,c+1,s+1,i),f>u&&(c===o?f*=rp:oC.test(e.charAt(c-1))?(f*=eC,p=e.slice(o,c-1).match(sC),p&&o>0&&(f*=Math.pow(Ya,p.length))):iC.test(e.charAt(c-1))?(f*=QS,m=e.slice(o,c-1).match(op),m&&o>0&&(f*=Math.pow(Ya,m.length))):(f*=tC,o>0&&(f*=Math.pow(Ya,c-o))),e.charAt(c)!==t.charAt(s)&&(f*=nC)),(f<Ga&&n.charAt(c-1)===r.charAt(s+1)||r.charAt(s+1)===r.charAt(s)&&n.charAt(c-1)!==r.charAt(s))&&(h=Xa(e,t,n,r,c+1,s+2,i),h*Ga>f&&(f=h*Ga)),f>u&&(u=f),c=n.indexOf(l,c+1);return i[a]=u,u}function sp(e){return e.toLowerCase().replace(op," ")}function aC(e,t,n){return e=n&&n.length>0?`${e+" "+n.join(" ")}`:e,Xa(e,t,sp(e),sp(t),0,0,{})}var wo='[cmdk-group=""]',Ja='[cmdk-group-items=""]',lC='[cmdk-group-heading=""]',ip='[cmdk-item=""]',ap=`${ip}:not([aria-disabled="true"])`,Za="cmdk-item-select",Pr="data-value",cC=(e,t,n)=>aC(e,t,n),lp=x.createContext(void 0),yo=()=>x.useContext(lp),cp=x.createContext(void 0),Qa=()=>x.useContext(cp),up=x.createContext(void 0),dp=x.forwardRef((e,t)=>{let n=Rr(()=>{var M,P;return{search:"",value:(P=(M=e.value)!=null?M:e.defaultValue)!=null?P:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),r=Rr(()=>new Set),o=Rr(()=>new Map),s=Rr(()=>new Map),i=Rr(()=>new Set),a=fp(e),{label:l,children:c,value:u,onValueChange:f,filter:h,shouldFilter:p,loop:m,disablePointerSelection:b=!1,vimBindings:g=!0,...w}=e,y=Ot(),k=Ot(),E=Ot(),S=x.useRef(null),C=yC();rr(()=>{if(u!==void 0){let M=u.trim();n.current.value=M,T.emit()}},[u]),rr(()=>{C(6,W)},[]);let T=x.useMemo(()=>({subscribe:M=>(i.current.add(M),()=>i.current.delete(M)),snapshot:()=>n.current,setState:(M,P,$)=>{var R,G,te,F;if(!Object.is(n.current[M],P)){if(n.current[M]=P,M==="search")B(),j(),C(1,L);else if(M==="value"){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let X=document.getElementById(E);X?X.focus():(R=document.getElementById(y))==null||R.focus()}if(C(7,()=>{var X;n.current.selectedItemId=(X=O())==null?void 0:X.id,T.emit()}),$||C(5,W),((G=a.current)==null?void 0:G.value)!==void 0){let X=P??"";(F=(te=a.current).onValueChange)==null||F.call(te,X);return}}T.emit()}},emit:()=>{i.current.forEach(M=>M())}}),[]),A=x.useMemo(()=>({value:(M,P,$)=>{var R;P!==((R=s.current.get(M))==null?void 0:R.value)&&(s.current.set(M,{value:P,keywords:$}),n.current.filtered.items.set(M,N(P,$)),C(2,()=>{j(),T.emit()}))},item:(M,P)=>(r.current.add(M),P&&(o.current.has(P)?o.current.get(P).add(M):o.current.set(P,new Set([M]))),C(3,()=>{B(),j(),n.current.value||L(),T.emit()}),()=>{s.current.delete(M),r.current.delete(M),n.current.filtered.items.delete(M);let $=O();C(4,()=>{B(),($==null?void 0:$.getAttribute("id"))===M&&L(),T.emit()})}),group:M=>(o.current.has(M)||o.current.set(M,new Set),()=>{s.current.delete(M),o.current.delete(M)}),filter:()=>a.current.shouldFilter,label:l||e["aria-label"],getDisablePointerSelection:()=>a.current.disablePointerSelection,listId:y,inputId:E,labelId:k,listInnerRef:S}),[]);function N(M,P){var $,R;let G=(R=($=a.current)==null?void 0:$.filter)!=null?R:cC;return M?G(M,n.current.search,P):0}function j(){if(!n.current.search||a.current.shouldFilter===!1)return;let M=n.current.filtered.items,P=[];n.current.filtered.groups.forEach(R=>{let G=o.current.get(R),te=0;G.forEach(F=>{let X=M.get(F);te=Math.max(X,te)}),P.push([R,te])});let $=S.current;D().sort((R,G)=>{var te,F;let X=R.getAttribute("id"),re=G.getAttribute("id");return((te=M.get(re))!=null?te:0)-((F=M.get(X))!=null?F:0)}).forEach(R=>{let G=R.closest(Ja);G?G.appendChild(R.parentElement===G?R:R.closest(`${Ja} > *`)):$.appendChild(R.parentElement===$?R:R.closest(`${Ja} > *`))}),P.sort((R,G)=>G[1]-R[1]).forEach(R=>{var G;let te=(G=S.current)==null?void 0:G.querySelector(`${wo}[${Pr}="${encodeURIComponent(R[0])}"]`);te==null||te.parentElement.appendChild(te)})}function L(){let M=D().find($=>$.getAttribute("aria-disabled")!=="true"),P=M==null?void 0:M.getAttribute(Pr);T.setState("value",P||void 0)}function B(){var M,P,$,R;if(!n.current.search||a.current.shouldFilter===!1){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let G=0;for(let te of r.current){let F=(P=(M=s.current.get(te))==null?void 0:M.value)!=null?P:"",X=(R=($=s.current.get(te))==null?void 0:$.keywords)!=null?R:[],re=N(F,X);n.current.filtered.items.set(te,re),re>0&&G++}for(let[te,F]of o.current)for(let X of F)if(n.current.filtered.items.get(X)>0){n.current.filtered.groups.add(te);break}n.current.filtered.count=G}function W(){var M,P,$;let R=O();R&&(((M=R.parentElement)==null?void 0:M.firstChild)===R&&(($=(P=R.closest(wo))==null?void 0:P.querySelector(lC))==null||$.scrollIntoView({block:"nearest"})),R.scrollIntoView({block:"nearest"}))}function O(){var M;return(M=S.current)==null?void 0:M.querySelector(`${ip}[aria-selected="true"]`)}function D(){var M;return Array.from(((M=S.current)==null?void 0:M.querySelectorAll(ap))||[])}function z(M){let P=D()[M];P&&T.setState("value",P.getAttribute(Pr))}function ee(M){var P;let $=O(),R=D(),G=R.findIndex(F=>F===$),te=R[G+M];(P=a.current)!=null&&P.loop&&(te=G+M<0?R[R.length-1]:G+M===R.length?R[0]:R[G+M]),te&&T.setState("value",te.getAttribute(Pr))}function H(M){let P=O(),$=P==null?void 0:P.closest(wo),R;for(;$&&!R;)$=M>0?bC($,wo):wC($,wo),R=$==null?void 0:$.querySelector(ap);R?T.setState("value",R.getAttribute(Pr)):ee(M)}let V=()=>z(D().length-1),Y=M=>{M.preventDefault(),M.metaKey?V():M.altKey?H(1):ee(1)},q=M=>{M.preventDefault(),M.metaKey?z(0):M.altKey?H(-1):ee(-1)};return x.createElement(je.div,{ref:t,tabIndex:-1,...w,"cmdk-root":"",onKeyDown:M=>{var P;(P=w.onKeyDown)==null||P.call(w,M);let $=M.nativeEvent.isComposing||M.keyCode===229;if(!(M.defaultPrevented||$))switch(M.key){case"n":case"j":{g&&M.ctrlKey&&Y(M);break}case"ArrowDown":{Y(M);break}case"p":case"k":{g&&M.ctrlKey&&q(M);break}case"ArrowUp":{q(M);break}case"Home":{M.preventDefault(),z(0);break}case"End":{M.preventDefault(),V();break}case"Enter":{M.preventDefault();let R=O();if(R){let G=new Event(Za);R.dispatchEvent(G)}}}}},x.createElement("label",{"cmdk-label":"",htmlFor:A.inputId,id:A.labelId,style:SC},l),Fs(e,M=>x.createElement(cp.Provider,{value:T},x.createElement(lp.Provider,{value:A},M))))}),uC=x.forwardRef((e,t)=>{var n,r;let o=Ot(),s=x.useRef(null),i=x.useContext(up),a=yo(),l=fp(e),c=(r=(n=l.current)==null?void 0:n.forceMount)!=null?r:i==null?void 0:i.forceMount;rr(()=>{if(!c)return a.item(o,i==null?void 0:i.id)},[c]);let u=hp(o,s,[e.value,e.children,s],e.keywords),f=Qa(),h=Fn(C=>C.value&&C.value===u.current),p=Fn(C=>c||a.filter()===!1?!0:C.search?C.filtered.items.get(o)>0:!0);x.useEffect(()=>{let C=s.current;if(!(!C||e.disabled))return C.addEventListener(Za,m),()=>C.removeEventListener(Za,m)},[p,e.onSelect,e.disabled]);function m(){var C,T;b(),(T=(C=l.current).onSelect)==null||T.call(C,u.current)}function b(){f.setState("value",u.current,!0)}if(!p)return null;let{disabled:g,value:w,onSelect:y,forceMount:k,keywords:E,...S}=e;return x.createElement(je.div,{ref:On(s,t),...S,id:o,"cmdk-item":"",role:"option","aria-disabled":!!g,"aria-selected":!!h,"data-disabled":!!g,"data-selected":!!h,onPointerMove:g||a.getDisablePointerSelection()?void 0:b,onClick:g?void 0:m},e.children)}),dC=x.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:o,...s}=e,i=Ot(),a=x.useRef(null),l=x.useRef(null),c=Ot(),u=yo(),f=Fn(p=>o||u.filter()===!1?!0:p.search?p.filtered.groups.has(i):!0);rr(()=>u.group(i),[]),hp(i,a,[e.value,e.heading,l]);let h=x.useMemo(()=>({id:i,forceMount:o}),[o]);return x.createElement(je.div,{ref:On(a,t),...s,"cmdk-group":"",role:"presentation",hidden:f?void 0:!0},n&&x.createElement("div",{ref:l,"cmdk-group-heading":"","aria-hidden":!0,id:c},n),Fs(e,p=>x.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?c:void 0},x.createElement(up.Provider,{value:h},p))))}),fC=x.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,o=x.useRef(null),s=Fn(i=>!i.search);return!n&&!s?null:x.createElement(je.div,{ref:On(o,t),...r,"cmdk-separator":"",role:"separator"})}),hC=x.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,o=e.value!=null,s=Qa(),i=Fn(c=>c.search),a=Fn(c=>c.selectedItemId),l=yo();return x.useEffect(()=>{e.value!=null&&s.setState("search",e.value)},[e.value]),x.createElement(je.input,{ref:t,...r,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":l.listId,"aria-labelledby":l.labelId,"aria-activedescendant":a,id:l.inputId,type:"text",value:o?e.value:i,onChange:c=>{o||s.setState("search",c.target.value),n==null||n(c.target.value)}})}),pC=x.forwardRef((e,t)=>{let{children:n,label:r="Suggestions",...o}=e,s=x.useRef(null),i=x.useRef(null),a=Fn(c=>c.selectedItemId),l=yo();return x.useEffect(()=>{if(i.current&&s.current){let c=i.current,u=s.current,f,h=new ResizeObserver(()=>{f=requestAnimationFrame(()=>{let p=c.offsetHeight;u.style.setProperty("--cmdk-list-height",p.toFixed(1)+"px")})});return h.observe(c),()=>{cancelAnimationFrame(f),h.unobserve(c)}}},[]),x.createElement(je.div,{ref:On(s,t),...o,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":a,"aria-label":r,id:l.listId},Fs(e,c=>x.createElement("div",{ref:On(i,l.listInnerRef),"cmdk-list-sizer":""},c)))}),mC=x.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:o,contentClassName:s,container:i,...a}=e;return x.createElement(Dh,{open:n,onOpenChange:r},x.createElement(Lh,{container:i},x.createElement($a,{"cmdk-overlay":"",className:o}),x.createElement(Fa,{"aria-label":e.label,"cmdk-dialog":"",className:s},x.createElement(dp,{ref:t,...a}))))}),gC=x.forwardRef((e,t)=>Fn(n=>n.filtered.count===0)?x.createElement(je.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),xC=x.forwardRef((e,t)=>{let{progress:n,children:r,label:o="Loading...",...s}=e;return x.createElement(je.div,{ref:t,...s,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":o},Fs(e,i=>x.createElement("div",{"aria-hidden":!0},i)))}),Et=Object.assign(dp,{List:pC,Item:uC,Input:hC,Group:dC,Separator:fC,Dialog:mC,Empty:gC,Loading:xC});function bC(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function wC(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function fp(e){let t=x.useRef(e);return rr(()=>{t.current=e}),t}var rr=typeof window>"u"?x.useEffect:x.useLayoutEffect;function Rr(e){let t=x.useRef();return t.current===void 0&&(t.current=e()),t}function Fn(e){let t=Qa(),n=()=>e(t.snapshot());return x.useSyncExternalStore(t.subscribe,n,n)}function hp(e,t,n,r=[]){let o=x.useRef(),s=yo();return rr(()=>{var i;let a=(()=>{var c;for(let u of n){if(typeof u=="string")return u.trim();if(typeof u=="object"&&"current"in u)return u.current?(c=u.current.textContent)==null?void 0:c.trim():o.current}})(),l=r.map(c=>c.trim());s.value(e,a,l),(i=t.current)==null||i.setAttribute(Pr,a),o.current=a}),o}var yC=()=>{let[e,t]=x.useState(),n=Rr(()=>new Map);return rr(()=>{n.current.forEach(r=>r()),n.current=new Map},[e]),(r,o)=>{n.current.set(r,o),t({})}};function vC(e){let t=e.type;return typeof t=="function"?t(e.props):"render"in t?t.render(e.props):e}function Fs({asChild:e,children:t},n){return e&&x.isValidElement(t)?x.cloneElement(vC(t),{ref:t.ref},n(t.props.children)):n(t)}var SC={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};const pp=x.forwardRef(({className:e,...t},n)=>d.jsx(Et,{ref:n,className:fe("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",e),...t}));pp.displayName=Et.displayName;const mp=x.forwardRef(({className:e,...t},n)=>d.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[d.jsx(me.Search,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),d.jsx(Et.Input,{ref:n,className:fe("flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",e),...t})]}));mp.displayName=Et.Input.displayName;const gp=x.forwardRef(({className:e,...t},n)=>d.jsx(Et.List,{ref:n,className:fe("max-h-[300px] overflow-y-auto overflow-x-hidden",e),...t}));gp.displayName=Et.List.displayName;const xp=x.forwardRef((e,t)=>d.jsx(Et.Empty,{ref:t,className:"py-6 text-center text-sm",...e}));xp.displayName=Et.Empty.displayName;const bp=x.forwardRef(({className:e,...t},n)=>d.jsx(Et.Group,{ref:n,className:fe("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",e),...t}));bp.displayName=Et.Group.displayName;const CC=x.forwardRef(({className:e,...t},n)=>d.jsx(Et.Separator,{ref:n,className:fe("-mx-1 h-px bg-border",e),...t}));CC.displayName=Et.Separator.displayName;const wp=x.forwardRef(({className:e,...t},n)=>d.jsx(Et.Item,{ref:n,className:fe("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected='true']:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50",e),...t}));wp.displayName=Et.Item.displayName;function yp({thread:e,isActive:t=!1,editingThreadId:n,editingTitle:r="",onSelect:o,onStartEditing:s,onEditingTitleChange:i,onSaveEditing:a,onCancelEditing:l,onShare:c,onDelete:u,showEditTitle:f=!0,showDeleteButton:h=!0,onMenuOpenChange:p,onMenuAction:m,formatDate:b,getDisplayThreadTitle:g,itemClassName:w,activeItemClassName:y,secondaryLine:k}){const E=n===e.threadId,S=v.useMemo(()=>(g==null?void 0:g(e))??e.title??e.threadId,[g,e]),C=()=>o==null?void 0:o(e.threadId),T=A=>s==null?void 0:s(e,A);return d.jsxs("div",{className:fe("flex items-center justify-between rounded px-2 py-1 text-sm hover:bg-muted cursor-pointer",w,t&&(y??"bg-muted/70")),onClick:C,children:[d.jsxs("div",{className:"flex flex-col min-w-0",children:[E?d.jsx("input",{className:"text-sm px-2 py-1 border rounded",value:r,onChange:A=>i==null?void 0:i(A.target.value)}):d.jsx("span",{className:"font-medium truncate",children:S}),k&&d.jsx("span",{className:"text-xs text-muted-foreground truncate",children:k}),b&&e.updatedAt&&d.jsx("span",{className:"text-[10px] text-muted-foreground",children:b(e.updatedAt)})]}),d.jsx("div",{className:"flex items-center gap-1",children:E?d.jsxs("div",{className:"flex items-center gap-1",children:[d.jsx(Je,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs",onClick:A=>{A.stopPropagation(),a==null||a(e)},children:"Save"}),d.jsx(Je,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs",onClick:A=>{A.stopPropagation(),l==null||l(e)},children:"Cancel"})]}):d.jsxs(Pa,{onOpenChange:A=>p==null?void 0:p(e.threadId,A),children:[d.jsx(Ra,{asChild:!0,children:d.jsxs(Je,{size:"sm",variant:"ghost",className:"h-8 w-8 p-0 opacity-0 group-hover:opacity-100 data-[state=open]:opacity-100 transition-opacity",onClick:A=>A.stopPropagation(),children:[d.jsx(me.MoreVertical,{className:"h-4 w-4"}),d.jsx("span",{className:"sr-only",children:"Open menu"})]})}),d.jsxs(_s,{align:"end",children:[f&&d.jsxs(tr,{onClick:A=>{A.stopPropagation(),m==null||m(e.threadId,"rename"),T(A)},children:[d.jsx(me.Edit3,{className:"mr-2 h-4 w-4"}),d.jsx("span",{children:"Rename"})]}),c&&d.jsxs(tr,{onClick:A=>{A.stopPropagation(),m==null||m(e.threadId,"share"),c(e)},children:[d.jsx(me.Share2,{className:"mr-2 h-4 w-4"}),d.jsx("span",{children:"Share"})]}),h&&d.jsxs(tr,{onClick:A=>{A.stopPropagation(),m==null||m(e.threadId,"delete"),u==null||u(e)},className:"text-destructive focus:text-destructive",children:[d.jsx(me.Trash2,{className:"mr-2 h-4 w-4"}),d.jsx("span",{children:"Delete"})]})]})]})})]})}var zs="Collapsible",[TC,ST]=Mn(zs),[kC,el]=TC(zs),vp=x.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[l,c]=as({prop:r,defaultProp:o??!1,onChange:i,caller:zs});return d.jsx(kC,{scope:n,disabled:s,contentId:Ot(),open:l,onOpenToggle:x.useCallback(()=>c(u=>!u),[c]),children:d.jsx(je.div,{"data-state":nl(l),"data-disabled":s?"":void 0,...a,ref:t})})});vp.displayName=zs;var Sp="CollapsibleTrigger",Cp=x.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=el(Sp,n);return d.jsx(je.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":nl(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:ye(e.onClick,o.onOpenToggle)})});Cp.displayName=Sp;var tl="CollapsibleContent",Tp=x.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=el(tl,e.__scopeCollapsible);return d.jsx(Lt,{present:n||o.open,children:({present:s})=>d.jsx(EC,{...r,ref:t,present:s})})});Tp.displayName=tl;var EC=x.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=el(tl,n),[a,l]=x.useState(r),c=x.useRef(null),u=Ge(t,c),f=x.useRef(0),h=f.current,p=x.useRef(0),m=p.current,b=i.open||a,g=x.useRef(b),w=x.useRef(void 0);return x.useEffect(()=>{const y=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(y)},[]),rn(()=>{const y=c.current;if(y){w.current=w.current||{transitionDuration:y.style.transitionDuration,animationName:y.style.animationName},y.style.transitionDuration="0s",y.style.animationName="none";const k=y.getBoundingClientRect();f.current=k.height,p.current=k.width,g.current||(y.style.transitionDuration=w.current.transitionDuration,y.style.animationName=w.current.animationName),l(r)}},[i.open,r]),d.jsx(je.div,{"data-state":nl(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!b,...s,ref:u,style:{"--radix-collapsible-content-height":h?`${h}px`:void 0,"--radix-collapsible-content-width":m?`${m}px`:void 0,...e.style},children:b&&o})});function nl(e){return e?"open":"closed"}var IC=vp;const AC=IC,NC=Cp,jC=Tp,kp=25,Ep=Tn.threadManagerView,_C=e=>e==="default"||e==="shared",PC=()=>{if(typeof window>"u")return null;try{const e=window.localStorage.getItem(Ep);if(_C(e))return e}catch{}return null};function Ip({defaultView:e}={}){const[t,n]=v.useState(()=>PC()??e??"default");v.useEffect(()=>{if(!(typeof window>"u"))try{window.localStorage.setItem(Ep,t)}catch{}},[t]);const r=v.useCallback(o=>{n(o)},[]);return{view:t,setView:r}}const RC=[{key:"default",label:"My chats"},{key:"shared",label:"Shared with you"}];function Bs({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,onItemMenuOpenChange:o,onItemMenuAction:s,maxHeight:i="400px",customStyles:a={},currentThreadId:l=null,navigateToThread:c,onThreadSelect:u,onThreadCreate:f,onThreadDelete:h,view:p,defaultView:m,onViewChange:b,viewOptions:g,viewState:w,showHeader:y=!0,shareTargets:k,isLoadingShareTargets:E,shareTargetFilter:S,groupBy:C,filter:T}){const{chatApi:A,authApi:N}=hr(),{threads:j,sharedThreads:L,currentThreadId:B,setCurrentThreadId:W,isLoading:O,isLoadingSharedThreads:D,actions:z,shareInFlight:ee,shareStatus:H,clearShareStatus:V}=Hr(),{createThread:Y,deleteThread:q,renameThread:M,shareThread:P}=z,{loadThread:$}=qr(),R=l??B,[G,te]=v.useState(Array.isArray(j)?j:[]),F=v.useRef(G.length>0),X=v.useRef(null),re=v.useRef(0),[ue,le]=v.useState(null),[Se,Me]=v.useState(""),[Ie,Ke]=v.useState(!1),[He,Fe]=v.useState(!1),[ze,It]=v.useState(null),[At,wt]=v.useState(""),[yt,ht]=v.useState([]),[st,Nt]=v.useState(!1),jt=v.useCallback(_=>Me(_),[]);v.useEffect(()=>{He&&!k&&yt.length===0&&!st&&(async()=>{Nt(!0);try{const ie=(await N.listUsers()).filter(se=>se.id||se.user_id).map(se=>({type:"user",value:se.user_id||se.id||"",id:se.user_id||se.id||"",label:se.name||se.username||se.email||"Unknown User",secondaryLabel:se.name||se.username?se.email:void 0}));ht(ie)}catch(Z){console.error("Failed to load users for sharing:",Z)}finally{Nt(!1)}})()},[He,k,yt.length,st,A]);const rt=k??yt,tt=E??st,it=g&&g.length>0?g:RC,_t=Ip({defaultView:m}),Ae=w??_t,Ye=p??Ae.view,Or=v.useCallback(_=>{p||Ae.setView(_),b==null||b(_)},[p,b,Ae]),$t=it.find(_=>_.key===Ye)??it[0],bn=_=>{It(_),wt(""),Fe(!0)},Vt=()=>{Fe(!1),It(null),wt(""),V()},Ft=v.useCallback(async _=>{if(!(!ze||ee)&&_.id)try{await P(ze,_.id),setTimeout(()=>Vt(),600)}catch(Z){console.error("Failed to share thread:",Z)}},[Vt,ee,ze,P]),wn=v.useMemo(()=>{const _=rt,Z=At.trim().toLowerCase();return Z?S?_.filter(ie=>S(ie,Z)):_.filter(ie=>`${ie.label} ${ie.secondaryLabel??""}`.toLowerCase().includes(Z)):_},[k,At,S]),pt=Ye==="shared",yn=pt?L:G,dn=T?yn.filter(T):yn,vn=v.useMemo(()=>{const _=Array.isArray(C)?C:[];if(_.length===0||pt)return null;const Z="Default",ie=ge=>{if(!ge)return"Older";try{const $e=ge.endsWith("Z")||ge.includes("+")?ge:`${ge}Z`,Pe=new Date($e),Le=new Date,at=new Date(Le.getFullYear(),Le.getMonth(),Le.getDate()),pn=new Date(Pe.getFullYear(),Pe.getMonth(),Pe.getDate()),lr=Math.floor((at.getTime()-pn.getTime())/(1e3*60*60*24));return lr===0?"Today":lr===1?"Yesterday":lr<=7?"Last 7 Days":"Older"}catch{return"Older"}},se=(ge,$e)=>{var Le,at;if($e==="project")return((Le=ge.project)==null?void 0:Le.name)||((at=ge.project)==null?void 0:at.id)||Z;if($e==="menuItem")return ge.menuItem||Z;if($e==="updatedAt"||$e==="createdAt"){const pn=$e==="updatedAt"?ge.updatedAt:ge.createdAt;return ie(pn)}const Pe=ge[$e];return typeof Pe=="string"?Pe||Z:typeof Pe=="number"?String(Pe):Pe==null?Z:String(Pe)},xe=(ge,$e)=>{const Pe={};return ge.forEach(Le=>{const at=se(Le,$e);Pe[at]||(Pe[at]=[]),Pe[at].push(Le)}),Pe},De=(ge,$e)=>{if($e.length===0)return ge;const[Pe,...Le]=$e,at=xe(ge,Pe);if(Le.length===0)return at;const pn={};return Object.entries(at).forEach(([lr,KC])=>{pn[lr]=De(KC,Le)}),pn},Ne=ge=>{if(Array.isArray(ge)){ge.sort(($e,Pe)=>new Date(Pe.updatedAt||Pe.createdAt||"").getTime()-new Date($e.updatedAt||$e.createdAt||"").getTime());return}Object.values(ge).forEach(Ne)},Ce=De(dn,_);return Ne(Ce),{kind:"nested",groups:Ce}},[dn,C,pt]),Xe=pt?D:O,Ze=pt?"No shared conversations yet":"No conversations yet",Sn=_=>{const Z=_.sharedAt?` • ${Cn(_.sharedAt)}`:"";return`Shared by ${_.sharedByUserId}${Z}`},fn=_=>"sharedByUserId"in _;v.useEffect(()=>{const _=Array.isArray(j)?j:[];if(_.length>0){F.current=!0,te(_);return}O||(F.current=!1,te(_))},[j,O]),v.useEffect(()=>{if(!X.current)return;const _=X.current.querySelector("[data-radix-scroll-area-viewport]");if(!_)return;let Z=null,ie=null;return Z=requestAnimationFrame(()=>{ie=requestAnimationFrame(()=>{_.scrollTop=re.current})}),()=>{Z!==null&&cancelAnimationFrame(Z),ie!==null&&cancelAnimationFrame(ie)}},[G]);const hn=async _=>{try{W(_),await $(_),c==null||c(_),u==null||u(_)}catch(Z){console.error("Failed to select thread:",Z)}},zn=async()=>{try{Ke(!0);const _=await Y();_&&(f==null||f(_),c==null||c(_))}catch(_){console.error("Failed to create thread:",_)}finally{Ke(!1)}},Bn=async(_,Z)=>{const ie=_.threadId;if(confirm("Delete this thread?")){if(X.current){const se=X.current.querySelector("[data-radix-scroll-area-viewport]");se&&(re.current=se.scrollTop)}try{await q(ie),h==null||h(ie)}catch(se){console.error("Failed to delete thread:",se)}}},or=(_,Z)=>{Z==null||Z.stopPropagation(),le(_.threadId),Me(_.title||`Thread ${_.threadId.slice(0,8)}`)},sr=async _=>{const Z=typeof _=="string"?_:_.threadId;if(Se.trim())try{await M(Z,Se.trim()),le(null),Me("")}catch(ie){console.error("Failed to update title:",ie)}},ir=_=>{le(null),Me("")},Cn=_=>{if(!_)return"";try{const Z=_.endsWith("Z")||_.includes("+")?_:`${_}Z`,ie=new Date(Z),xe=new Date().getTime()-ie.getTime(),De=Math.floor(xe/(1e3*60*60*24));return De===0?ie.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):De===1?"Yesterday":De<7?`${De} days ago`:ie.toLocaleDateString()}catch{return""}},ar=_=>_.title||`Thread ${_.threadId.slice(0,8)}`,zt=_=>{const Z=ar(_);return Z.length<=kp?Z:`${Z.slice(0,kp)}...`},I=_=>Array.isArray(_)?_.length:Object.values(_).reduce((Z,ie)=>Array.isArray(ie)?Z+ie.length:Z+I(ie),0),K=_=>{const ie=["Today","Yesterday","Last 7 Days","Older"].indexOf(_);return ie===-1?null:ie},oe=(_,Z,ie)=>{if(Array.isArray(_))return _.map(Ce=>d.jsx(yp,{thread:Ce,isActive:R===Ce.threadId,editingThreadId:ue,editingTitle:Se,onSelect:hn,onStartEditing:or,onEditingTitleChange:jt,onSaveEditing:ge=>void sr(ge),onCancelEditing:()=>ir(),onShare:ge=>bn(ge.threadId),onDelete:ge=>Bn(ge),showEditTitle:r,showDeleteButton:n,onMenuOpenChange:o,onMenuAction:s,formatDate:Cn,getDisplayThreadTitle:zt,secondaryLine:pt&&fn(Ce)?Sn(Ce):void 0,itemClassName:a.threadItem,activeItemClassName:a.activeThread},Ce.threadId));const se=["flex items-center w-full px-2 py-1 text-xs font-semibold text-slate-600 hover:text-slate-900 dark:hover:text-slate-200","flex items-center w-full px-2 py-1 text-[11px] font-medium text-slate-500 hover:text-slate-800 dark:hover:text-slate-200","flex items-center w-full px-2 py-1 text-[10px] font-medium text-slate-400 hover:text-slate-600 dark:hover:text-slate-300"],xe="pl-2 border-l border-slate-100 dark:border-slate-800 ml-1.5 my-1 space-y-1",De=se[Z]??se[se.length-1],Ne=Object.entries(_);if(Ne.length===1){const[Ce,ge]=Ne[0];return oe(ge,Z+1,`${ie}-${Ce}`)}return Ne.sort(([Ce],[ge])=>{const $e="Default";if(Ce===$e)return 1;if(ge===$e)return-1;const Pe=K(Ce),Le=K(ge);if(Pe!==null||Le!==null){const at=Pe??Number.MAX_SAFE_INTEGER,pn=Le??Number.MAX_SAFE_INTEGER;return at-pn}return Ce.localeCompare(ge)}).map(([Ce,ge])=>{const $e=`${ie}-${Ce}`,Pe=I(ge);return d.jsxs(AC,{defaultOpen:!0,className:"group/collapsible",children:[d.jsxs(NC,{className:De,children:[d.jsx(me.ChevronRight,{className:"w-3 h-3 mr-1 transition-transform group-data-[state=open]/collapsible:rotate-90"}),Ce,d.jsx("span",{className:"ml-auto text-[10px] text-slate-400",children:Pe})]}),d.jsx(jC,{children:d.jsx("div",{className:xe,children:oe(ge,Z+1,$e)})})]},$e)})};return d.jsxs("div",{className:`thread-manager-root flex flex-col h-full ${e} ${a.container||""}`,children:[y&&d.jsxs("div",{className:a.header||"flex flex-col gap-2 px-1 py-0 border border-slate-200 bg-white dark:border-slate-700 dark:bg-slate-900 shadow-sm",children:[t&&d.jsx("div",{className:"flex justify-end",children:d.jsxs(Je,{onClick:zn,disabled:Ie||O,className:a.createButton||"px-3 py-2 gap-1",size:"sm",variant:"ghost",title:Ie?"Creating...":"New Chat",children:[d.jsx(me.Edit3,{size:16}),d.jsx("span",{children:"New chat"})]})}),d.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-slate-700 dark:text-slate-200 uppercase tracking-wide leading-tight",children:[d.jsx("span",{children:"Current View"}),d.jsxs(Pa,{children:[d.jsx(Ra,{asChild:!0,children:d.jsx(Je,{variant:"outline",size:"sm",className:"text-[11px] text-slate-700 dark:text-slate-200 border border-slate-300 dark:border-slate-600 bg-white dark:bg-slate-900 hover:bg-slate-50 dark:hover:bg-slate-800 px-2 py-0",children:$t.label})}),d.jsx(_s,{align:"start",sideOffset:6,className:"w-40",children:it.map(_=>d.jsxs(tr,{className:"justify-between text-[12px]",onClick:Z=>{Z.preventDefault(),Or(_.key)},children:[d.jsx("span",{children:_.label}),Ye===_.key&&d.jsx(me.Check,{className:"h-3 w-3"})]},_.key))})]})]})]}),d.jsx(qa,{ref:X,className:`flex-1 min-h-0 ${a.threadList||""}`,style:i?{maxHeight:i}:void 0,children:d.jsx("div",{className:"p-2 space-y-1 pb-4",children:Xe?d.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[d.jsx(me.Loader2,{className:"h-5 w-5 animate-spin"}),d.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):dn.length===0?d.jsxs("div",{className:"text-center py-8 text-slate-400",children:[d.jsx(me.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),d.jsx("p",{className:"text-sm text-slate-500",children:Ze})]}):(vn==null?void 0:vn.kind)==="nested"?oe(vn.groups,0,"group"):dn.slice().sort((_,Z)=>new Date(Z.updatedAt||Z.createdAt||"").getTime()-new Date(_.updatedAt||_.createdAt||"").getTime()).map(_=>d.jsx(yp,{thread:_,isActive:R===_.threadId,editingThreadId:ue,editingTitle:Se,onSelect:hn,onStartEditing:or,onEditingTitleChange:jt,onSaveEditing:Z=>void sr(Z),onCancelEditing:Z=>ir(),onShare:Z=>bn(Z.threadId),onDelete:Z=>Bn(Z),showEditTitle:r,showDeleteButton:n,onMenuOpenChange:o,onMenuAction:s,formatDate:Cn,getDisplayThreadTitle:zt,secondaryLine:pt&&fn(_)?Sn(_):void 0,itemClassName:a.threadItem,activeItemClassName:a.activeThread},_.threadId))})}),d.jsx(Fh,{open:He,onOpenChange:_=>!_&&Vt(),children:d.jsxs(za,{className:"max-w-md p-0",children:[d.jsx(Ba,{children:d.jsx(Ua,{children:"Share thread"})}),d.jsxs(pp,{children:[d.jsx(mp,{autoFocus:!0,value:At,onValueChange:_=>wt(_),placeholder:"Search for recipients..."}),d.jsxs(gp,{children:[H&&d.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-muted-foreground",children:[ee&&d.jsx(me.Loader2,{className:"h-3 w-3 animate-spin"}),d.jsx("span",{className:H.startsWith("Failed")?"text-red-500":H.startsWith("Shared")?"text-emerald-500":"text-slate-600 dark:text-slate-400",children:H})]}),d.jsx(xp,{children:tt?d.jsxs("span",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[d.jsx(me.Loader2,{className:"h-4 w-4 animate-spin"}),"Loading recipients…"]}):"No matching recipients found"}),wn.length>0&&d.jsx(bp,{heading:"Recipients",children:wn.map(_=>d.jsx(wp,{onSelect:()=>Ft(_),children:d.jsxs("div",{className:"flex flex-col items-start text-sm",children:[d.jsx("span",{className:"font-medium",children:_.label}),_.secondaryLabel&&d.jsx("span",{className:"text-xs text-muted-foreground",children:_.secondaryLabel})]})},_.id))})]})]})]})})]})}function OC({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},payloadExtras:s={},...i}){const a=u=>{const f="h-full";switch(u){case"phone":return`${f} max-w-none`;case"tablet":return`${f} max-w-4xl mx-auto`;case"half-screen":return`${f} max-w-2xl`;case"desktop":default:return`${f} max-w-7xl mx-auto`}},l=u=>({"--chat-sidebar-width":u==="phone"?"100%":u==="tablet"?"280px":u==="half-screen"?"240px":"320px","--chat-message-max-width":u==="phone"?"95%":u==="tablet"?"90%":u==="half-screen"?"85%":"80%","--chat-input-height":u==="phone"?"120px":"100px"}),c=v.useCallback(u=>{var f;(f=i.onThreadChange)==null||f.call(i,u)},[i]);return e==="fullscreen"?d.jsx(Gr,{...i,onThreadChange:c,children:d.jsx("div",{className:`${a(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:l(t),children:d.jsx(_r,{className:"flex-1",onError:i.onError,enableFileUpload:!0,payloadExtras:s})})}):e==="tabs"?d.jsx(Gr,{...i,onThreadChange:c,children:d.jsx("div",{className:`${a(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:l(t),children:d.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&d.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:d.jsx(Bs,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),d.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:d.jsx(_r,{onError:i.onError,enableFileUpload:!0,payloadExtras:s})})]})})}):d.jsx(Gr,{...i,onThreadChange:c,children:d.jsxs("div",{className:`${a(t)} flex overflow-hidden ${r} ${o.container||""}`,style:l(t),children:[n&&d.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:d.jsx(Bs,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),d.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:d.jsx(_r,{onError:i.onError,enableFileUpload:!0,payloadExtras:s})})]})})}const MC=1,DC=1e6;let rl=0;function LC(){return rl=(rl+1)%Number.MAX_SAFE_INTEGER,rl.toString()}const ol=new Map,Ap=e=>{if(ol.has(e))return;const t=setTimeout(()=>{ol.delete(e),vo({type:"REMOVE_TOAST",toastId:e})},DC);ol.set(e,t)},$C=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,MC)};case"UPDATE_TOAST":return{...e,toasts:e.toasts.map(n=>n.id===t.toast.id?{...n,...t.toast}:n)};case"DISMISS_TOAST":{const{toastId:n}=t;return n?Ap(n):e.toasts.forEach(r=>{Ap(r.id)}),{...e,toasts:e.toasts.map(r=>r.id===n||n===void 0?{...r,open:!1}:r)}}case"REMOVE_TOAST":return t.toastId===void 0?{...e,toasts:[]}:{...e,toasts:e.toasts.filter(n=>n.id!==t.toastId)}}},Us=[];let Hs={toasts:[]};function vo(e){Hs=$C(Hs,e),Us.forEach(t=>{t(Hs)})}function FC({...e}){const t=LC(),n=o=>vo({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>vo({type:"DISMISS_TOAST",toastId:t});return vo({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function zC(){const[e,t]=x.useState(Hs);return x.useEffect(()=>(Us.push(t),()=>{const n=Us.indexOf(t);n>-1&&Us.splice(n,1)}),[e]),{...e,toast:FC,dismiss:n=>vo({type:"DISMISS_TOAST",toastId:n})}}function BC(e){const{allowFileOpen:t,currentThreadId:n}=e,{fileApi:r}=hr(),{toast:o}=zC(),[s,i]=v.useState({}),[a,l]=v.useState(null),[c,u]=v.useState(!1),f=v.useCallback(()=>{u(!1),l(null)},[]),h=v.useCallback(m=>{l(m),u(!0)},[]),p=v.useCallback(async(m,b,g)=>{var w,y;if(!t){m.preventDefault();return}if(s[g]){m.preventDefault();return}try{const k=String(b.url??""),E=k.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(E){m.preventDefault();const S=E[1],C=b.name||`file_${S}`,T=b.mimeType||"application/octet-stream";h({id:S,name:C,mimeType:T});return}if(k.startsWith("data:")){m.preventDefault(),i(C=>({...C,[g]:!0}));const S=o({title:"Fetching file...",description:"",open:!0});try{const C=await r.listFiles(n??void 0);if(!C||!Array.isArray(C))throw new Error("Invalid file list response");const T=C.find(A=>!A||typeof A!="object"||!((A.filename??"")===(b.name??""))?!1:typeof b.size=="number"&&typeof A.size=="number"?A.size===b.size:!0);if(!(T!=null&&T.id))throw new Error(`File "${b.name}" is not yet available on the server`);if(!T.id||!T.filename)throw new Error("Invalid file data received from server");h({id:T.id,name:b.name||T.filename||`file_${T.id}`,mimeType:b.mimeType||T.mime_type||"application/octet-stream"}),(w=S.update)==null||w.call(S,{id:S.id,title:"Success",description:`Opened ${b.name}`,open:!0})}catch(C){console.error("Failed to fetch server file:",C);const T=C instanceof Error?C.message:"Unknown error occurred";(y=S.update)==null||y.call(S,{id:S.id,title:"Failed",description:T}),o({title:"Failed to fetch file",description:T,open:!0})}finally{i(C=>({...C,[g]:!1}))}}}catch(k){console.error("File click error:",k),i(E=>({...E,[g]:!1}))}},[t,s,o,n,h]);return{uploadingFiles:s,handleFileClick:p,fileViewerOpen:c,currentFileInfo:a,closeFileViewer:f}}function UC(e){return v.useMemo(()=>{const t=e;let n=Array.isArray(t.content)?t.content:[];typeof t.content=="string"&&(n=[{type:"text",text:t.content}]);const r=t.additionalKwargs??{};return{contentParts:n,textContent:kg(n),toolMeta:dc(t),imageParts:n.filter(o=>o.type==="image_url"),fileParts:n.filter(o=>o.type==="file"),interruptParts:n.filter(o=>o.type==="interrupt"),toolRaw:fc(n),isToolStreaming:!!r.toolStreaming}},[e])}function HC({placeholder:e,onMessageSent:t}){const[n,r]=v.useState("chat");return d.jsxs("div",{className:"flex flex-col h-full",children:[d.jsxs("div",{className:"flex border-b border-gray-200 bg-gray-50",children:[d.jsx("button",{onClick:()=>r("chat"),className:`flex-1 px-3 py-2 text-sm font-medium transition-colors ${n==="chat"?"border-b-2 border-slate-800 text-slate-800 bg-white":"text-gray-600 hover:text-gray-800"}`,children:d.jsxs("div",{className:"flex items-center justify-center gap-2",children:[d.jsx(me.MessageSquare,{size:14}),"Chat"]})}),d.jsx("button",{onClick:()=>r("threads"),className:`flex-1 px-3 py-2 text-sm font-medium transition-colors ${n==="threads"?"border-b-2 border-slate-800 text-slate-800 bg-white":"text-gray-600 hover:text-gray-800"}`,children:d.jsxs("div",{className:"flex items-center justify-center gap-2",children:[d.jsx(me.History,{size:14}),"History"]})})]}),d.jsx("div",{className:"flex-1 min-h-0",children:n==="chat"?d.jsx(_r,{placeholder:e??"Ask Serti AI anything...",className:"h-full",onMessageSent:t}):d.jsx(Bs,{showCreateButton:!0,className:"h-full",onThreadSelect:()=>r("chat")})})]})}function WC({className:e="",placeholder:t,isAuthenticated:n=!0,onMessageSent:r,widgetTitle:o="Serti AI Navigator",widgetSubtitle:s="AI-Powered Assistant",...i}){const[a,l]=v.useState(!1);return n?d.jsx(Gr,{...i,children:d.jsx("div",{className:`fixed bottom-6 right-6 z-[9999] transition-all duration-300 ${e}`,children:d.jsxs("div",{className:`w-96 bg-white rounded-xl shadow-2xl border border-gray-200 overflow-hidden relative ${a?"scale-75":"scale-100"}`,children:[d.jsx("div",{className:"bg-slate-800 text-white p-4 flex-shrink-0",children:d.jsxs("div",{className:"flex items-center justify-between gap-3",children:[d.jsxs("div",{className:"flex items-center gap-3",children:[d.jsxs("div",{className:"relative h-10 w-10 rounded-full bg-gradient-to-br from-slate-500 to-slate-700 border border-white/30 flex items-center justify-center text-white text-sm font-bold",children:["S",d.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 h-3 w-3 rounded-full border-2 border-slate-800 bg-emerald-400"})]}),d.jsxs("div",{className:"flex flex-col",children:[d.jsx("h3",{className:"text-lg font-semibold leading-tight",children:o}),d.jsx("p",{className:"text-xs text-white/70",children:s})]}),d.jsx("span",{className:"ml-2 inline-flex items-center justify-center rounded-full bg-red-500 px-2 py-0.5 text-[11px] font-semibold leading-none text-white",children:"1"})]}),d.jsxs("div",{className:"flex items-center gap-1",children:[d.jsx(Je,{variant:"ghost",size:"sm",className:"text-white hover:bg-white/10 h-8 w-8 p-0",title:"Options",children:d.jsx(me.MoreHorizontal,{size:16})}),d.jsx(Je,{variant:"ghost",size:"sm",className:"text-white hover:bg-white/10 h-8 w-8 p-0",title:"Compose",children:d.jsx(me.Edit3,{size:16})}),d.jsx(Je,{variant:"ghost",size:"sm",onClick:c=>{c.stopPropagation(),l(u=>!u)},className:"text-white hover:bg-white/10 h-8 w-8 p-0",title:a?"Maximize":"Minimize",children:a?d.jsx(me.Maximize2,{size:14}):d.jsx(me.Minimize2,{size:14})})]})]})}),!a&&d.jsx("div",{className:"h-96 flex flex-col",children:d.jsx(HC,{placeholder:t,onMessageSent:r})})]})})}):null}function VC({label:e="New chat",children:t,className:n,variant:r="ghost",size:o="sm",...s}){return d.jsxs(Je,{variant:r,size:o,className:fe("gap-2 rounded-full px-3 font-semibold transition-all hover:scale-[1.01]",n),...s,children:[d.jsx(me.Edit3,{size:16}),t??e]})}J.ApiProvider=nc,J.AssistantMessageComponent=Ki,J.ChatApi=Jl,J.ChatApp=OC,J.ChatContainer=_r,J.ChatInput=Oa,J.ChatInputArea=Ps,J.ChatInputRow=Ps,J.ChatInterface=_r,J.ChatMessagesArea=is,J.ChatProviders=Gr,J.ChatUIProvider=Rc,J.ChatWidget=WC,J.Composer=Oa,J.DEFAULT_TIMEOUT_MS=Gl,J.FileApi=Zl,J.HISTORY_TIMEOUT_MS=Yl,J.MarkdownContent=so,J.MessageBubble=ao,J.MessageHeader=Wi,J.MessageList=is,J.NewChatButton=VC,J.SETTINGS_STORAGE_KEY=gi,J.STORAGE_KEYS=Tn,J.SystemMessageComponent=Gi,J.ThreadManager=Bs,J.ThreadStateProvider=_c,J.ThreadsProvider=sc,J.ToolCallCard=zi,J.ToolContent=es,J.ToolProgress=Hu,J.UserMessageComponent=qi,J.applySettings=gx,J.chatApiClient=En,J.cn=_p,J.createTaskSyncToolEndHandler=hx,J.del=si,J.draftKey=Po,J.extractTaskIdFromToolEnd=Ic,J.extractToolCalls=li,J.extractToolContent=Vr,J.fileApiClient=ii,J.fileToBase64=Cc,J.formatToolOutput=Ng,J.get=Tt,J.getChatToken=ri,J.getCurrentSettings=mx,J.getDefaultApiConfig=Fc,J.getDefaultChatSettings=zc,J.getToolCallArtifacts=Rg,J.getToolCalls=di,J.hasContent=jg,J.httpClient=mt,J.isEnvelope=yc,J.isFileLike=ci,J.loadStoredSettings=Bc,J.looksLikeMarkdown=ac,J.normalizeToolPayload=hc,J.normalizeToolPayloadValue=xr,J.onChatTokenChanged=oi,J.parseJsonSafe=pr,J.post=zr,J.pretty=gr,J.processAttachments=Tc,J.put=Xl,J.sanitizeForDisplay=Kr,J.saveSettings=Uc,J.setChatToken=kn,J.stringifyTool=fc,J.unwrap=gt,J.useApi=hr,J.useChatController=yh,J.useChatUI=zo,J.useFilePreview=BC,J.useHasChatSession=fx,J.useParsedMessageContent=UC,J.useShallowStableValue=Mc,J.useStream=Ec,J.useStreamingMarkdownBuffer=cd,J.useThreadHistoryState=bc,J.useThreadManagerViewState=Ip,J.useThreadState=qr,J.useThreadStateUpdater=jc,J.useThreads=Hr,J.useThreadsState=rc,J.useToolPayload=Uu,Object.defineProperty(J,Symbol.toStringTag,{value:"Module"})});
131
+ For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return x.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},OS="DialogDescriptionWarning",MS=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Mh(OS).contentName}}.`;return x.useEffect(()=>{var s;const o=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");t&&o&&(document.getElementById(t)||console.warn(r))},[r,e,t]),null},Dh=Sh,Lh=kh,$a=Eh,Fa=Ih,xo=Nh,$h=_h,DS=Rh;const Fh=Dh,LS=Lh,zh=x.forwardRef(({className:e,...t},n)=>d.jsx($a,{ref:n,className:he("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t}));zh.displayName=$a.displayName;const za=x.forwardRef(({className:e,children:t,...n},r)=>{const o=x.useMemo(()=>{let s=!1;function i(a){x.Children.forEach(a,l=>{if(s||!x.isValidElement(l))return;const c=l.type;if(c===xo||(c==null?void 0:c.displayName)===xo.displayName||(c==null?void 0:c.name)==="DialogTitle"){s=!0;return}l.props&&l.props.children&&i(l.props.children)})}return i(t),s},[t]);return d.jsxs(LS,{children:[d.jsx(zh,{}),d.jsxs(Fa,{ref:r,className:he("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 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-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",e),...n,children:[!o&&d.jsx(xo,{className:"sr-only",children:"Dialog"}),t,d.jsxs(DS,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[d.jsx(xe.X,{className:"h-4 w-4"}),d.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});za.displayName=Fa.displayName;const Ba=({className:e,...t})=>d.jsx("div",{className:he("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Ba.displayName="DialogHeader";const Ua=x.forwardRef(({className:e,...t},n)=>d.jsx(xo,{ref:n,className:he("text-lg font-semibold leading-none tracking-tight",e),...t}));Ua.displayName=xo.displayName;const Bh=x.forwardRef(({className:e,...t},n)=>d.jsx($h,{ref:n,className:he("text-sm text-muted-foreground",e),...t}));Bh.displayName=$h.displayName;function $S(e,[t,n]){return Math.min(n,Math.max(t,e))}function FS(e,t){return x.useReducer((n,r)=>t[n][r]??n,e)}var Ha="ScrollArea",[Uh,vT]=Rn(Ha),[zS,Bt]=Uh(Ha),Hh=x.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=x.useState(null),[c,u]=x.useState(null),[f,h]=x.useState(null),[p,m]=x.useState(null),[b,g]=x.useState(null),[w,y]=x.useState(0),[k,E]=x.useState(0),[S,C]=x.useState(!1),[T,N]=x.useState(!1),j=Xe(t,D=>l(D)),_=Yi(o);return d.jsx(zS,{scope:n,type:r,dir:_,scrollHideDelay:s,scrollArea:a,viewport:c,onViewportChange:u,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:m,scrollbarXEnabled:S,onScrollbarXEnabledChange:C,scrollbarY:b,onScrollbarYChange:g,scrollbarYEnabled:T,onScrollbarYEnabledChange:N,onCornerWidthChange:y,onCornerHeightChange:E,children:d.jsx(Ae.div,{dir:_,...i,ref:j,style:{position:"relative","--radix-scroll-area-corner-width":w+"px","--radix-scroll-area-corner-height":k+"px",...e.style}})})});Hh.displayName=Ha;var Wh="ScrollAreaViewport",Vh=x.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=Bt(Wh,n),a=x.useRef(null),l=Xe(t,a,i.onViewportChange);return d.jsxs(d.Fragment,{children:[d.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}),d.jsx(Ae.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:d.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});Vh.displayName=Wh;var dn="ScrollAreaScrollbar",Wa=x.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Bt(dn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return x.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?d.jsx(BS,{...r,ref:t,forceMount:n}):o.type==="scroll"?d.jsx(US,{...r,ref:t,forceMount:n}):o.type==="auto"?d.jsx(Kh,{...r,ref:t,forceMount:n}):o.type==="always"?d.jsx(Va,{...r,ref:t}):null});Wa.displayName=dn;var BS=x.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Bt(dn,e.__scopeScrollArea),[s,i]=x.useState(!1);return x.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const c=()=>{window.clearTimeout(l),i(!0)},u=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",c),a.addEventListener("pointerleave",u),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",c),a.removeEventListener("pointerleave",u)}}},[o.scrollArea,o.scrollHideDelay]),d.jsx(Dt,{present:n||s,children:d.jsx(Kh,{"data-state":s?"visible":"hidden",...r,ref:t})})}),US=x.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Bt(dn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=$s(()=>l("SCROLL_END"),100),[a,l]=FS("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 x.useEffect(()=>{if(a==="idle"){const c=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(c)}},[a,o.scrollHideDelay,l]),x.useEffect(()=>{const c=o.viewport,u=s?"scrollLeft":"scrollTop";if(c){let f=c[u];const h=()=>{const p=c[u];f!==p&&(l("SCROLL"),i()),f=p};return c.addEventListener("scroll",h),()=>c.removeEventListener("scroll",h)}},[o.viewport,s,l,i]),d.jsx(Dt,{present:n||a!=="hidden",children:d.jsx(Va,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ye(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:ye(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),Kh=x.forwardRef((e,t)=>{const n=Bt(dn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=x.useState(!1),a=e.orientation==="horizontal",l=$s(()=>{if(n.viewport){const c=n.viewport.offsetWidth<n.viewport.scrollWidth,u=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?c:u)}},10);return Nr(n.viewport,l),Nr(n.content,l),d.jsx(Dt,{present:r||s,children:d.jsx(Va,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Va=x.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=Bt(dn,e.__scopeScrollArea),s=x.useRef(null),i=x.useRef(0),[a,l]=x.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),c=Jh(a.viewport,a.content),u={...r,sizes:a,onSizesChange:l,hasThumb:c>0&&c<1,onThumbChange:h=>s.current=h,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:h=>i.current=h};function f(h,p){return GS(h,i.current,a,p)}return n==="horizontal"?d.jsx(HS,{...u,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=Zh(h,a,o.dir);s.current.style.transform=`translate3d(${p}px, 0, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollLeft=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollLeft=f(h,o.dir))}}):n==="vertical"?d.jsx(WS,{...u,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=Zh(h,a);s.current.style.transform=`translate3d(0, ${p}px, 0)`}},onWheelScroll:h=>{o.viewport&&(o.viewport.scrollTop=h)},onDragScroll:h=>{o.viewport&&(o.viewport.scrollTop=f(h))}}):null}),HS=x.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Bt(dn,e.__scopeScrollArea),[i,a]=x.useState(),l=x.useRef(null),c=Xe(t,l,s.onScrollbarXChange);return x.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),d.jsx(Gh,{"data-orientation":"horizontal",...o,ref:c,sizes:n,style:{bottom:0,left:s.dir==="rtl"?"var(--radix-scroll-area-corner-width)":0,right:s.dir==="ltr"?"var(--radix-scroll-area-corner-width)":0,"--radix-scroll-area-thumb-width":Ls(n)+"px",...e.style},onThumbPointerDown:u=>e.onThumbPointerDown(u.x),onDragScroll:u=>e.onDragScroll(u.x),onWheelScroll:(u,f)=>{if(s.viewport){const h=s.viewport.scrollLeft+u.deltaX;e.onWheelScroll(h),ep(h,f)&&u.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:Ds(i.paddingLeft),paddingEnd:Ds(i.paddingRight)}})}})}),WS=x.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Bt(dn,e.__scopeScrollArea),[i,a]=x.useState(),l=x.useRef(null),c=Xe(t,l,s.onScrollbarYChange);return x.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),d.jsx(Gh,{"data-orientation":"vertical",...o,ref:c,sizes:n,style:{top:0,right:s.dir==="ltr"?0:void 0,left:s.dir==="rtl"?0:void 0,bottom:"var(--radix-scroll-area-corner-height)","--radix-scroll-area-thumb-height":Ls(n)+"px",...e.style},onThumbPointerDown:u=>e.onThumbPointerDown(u.y),onDragScroll:u=>e.onDragScroll(u.y),onWheelScroll:(u,f)=>{if(s.viewport){const h=s.viewport.scrollTop+u.deltaY;e.onWheelScroll(h),ep(h,f)&&u.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:Ds(i.paddingTop),paddingEnd:Ds(i.paddingBottom)}})}})}),[VS,qh]=Uh(dn),Gh=x.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:c,onWheelScroll:u,onResize:f,...h}=e,p=Bt(dn,n),[m,b]=x.useState(null),g=Xe(t,j=>b(j)),w=x.useRef(null),y=x.useRef(""),k=p.viewport,E=r.content-r.viewport,S=ft(u),C=ft(l),T=$s(f,10);function N(j){if(w.current){const _=j.clientX-w.current.left,D=j.clientY-w.current.top;c({x:_,y:D})}}return x.useEffect(()=>{const j=_=>{const D=_.target;(m==null?void 0:m.contains(D))&&S(_,E)};return document.addEventListener("wheel",j,{passive:!1}),()=>document.removeEventListener("wheel",j,{passive:!1})},[k,m,E,S]),x.useEffect(C,[r,C]),Nr(m,T),Nr(p.content,T),d.jsx(VS,{scope:n,scrollbar:m,hasThumb:o,onThumbChange:ft(s),onThumbPointerUp:ft(i),onThumbPositionChange:C,onThumbPointerDown:ft(a),children:d.jsx(Ae.div,{...h,ref:g,style:{position:"absolute",...h.style},onPointerDown:ye(e.onPointerDown,j=>{j.button===0&&(j.target.setPointerCapture(j.pointerId),w.current=m.getBoundingClientRect(),y.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),N(j))}),onPointerMove:ye(e.onPointerMove,N),onPointerUp:ye(e.onPointerUp,j=>{const _=j.target;_.hasPointerCapture(j.pointerId)&&_.releasePointerCapture(j.pointerId),document.body.style.webkitUserSelect=y.current,p.viewport&&(p.viewport.style.scrollBehavior=""),w.current=null})})})}),Ms="ScrollAreaThumb",Yh=x.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=qh(Ms,e.__scopeScrollArea);return d.jsx(Dt,{present:n||o.hasThumb,children:d.jsx(KS,{ref:t,...r})})}),KS=x.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=Bt(Ms,n),i=qh(Ms,n),{onThumbPositionChange:a}=i,l=Xe(t,f=>i.onThumbChange(f)),c=x.useRef(void 0),u=$s(()=>{c.current&&(c.current(),c.current=void 0)},100);return x.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(u(),!c.current){const p=YS(f,a);c.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,u,a]),d.jsx(Ae.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:l,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:ye(e.onPointerDownCapture,f=>{const p=f.target.getBoundingClientRect(),m=f.clientX-p.left,b=f.clientY-p.top;i.onThumbPointerDown({x:m,y:b})}),onPointerUp:ye(e.onPointerUp,i.onThumbPointerUp)})});Yh.displayName=Ms;var Ka="ScrollAreaCorner",Xh=x.forwardRef((e,t)=>{const n=Bt(Ka,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?d.jsx(qS,{...e,ref:t}):null});Xh.displayName=Ka;var qS=x.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=Bt(Ka,n),[s,i]=x.useState(0),[a,l]=x.useState(0),c=!!(s&&a);return Nr(o.scrollbarX,()=>{var f;const u=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(u),l(u)}),Nr(o.scrollbarY,()=>{var f;const u=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(u),i(u)}),c?d.jsx(Ae.div,{...r,ref:t,style:{width:s,height:a,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function Ds(e){return e?parseInt(e,10):0}function Jh(e,t){const n=e/t;return isNaN(n)?0:n}function Ls(e){const t=Jh(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function GS(e,t,n,r="ltr"){const o=Ls(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,c=n.scrollbar.size-n.scrollbar.paddingEnd-a,u=n.content-n.viewport,f=r==="ltr"?[0,u]:[u*-1,0];return Qh([l,c],f)(e)}function Zh(e,t,n="ltr"){const r=Ls(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],c=$S(e,l);return Qh([0,i],[0,a])(c)}function Qh(e,t){return n=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const r=(t[1]-t[0])/(e[1]-e[0]);return t[0]+r*(n-e[0])}}function ep(e,t){return e>0&&e<t}var YS=(e,t=()=>{})=>{let n={left:e.scrollLeft,top:e.scrollTop},r=0;return function o(){const s={left:e.scrollLeft,top:e.scrollTop},i=n.left!==s.left,a=n.top!==s.top;(i||a)&&t(),n=s,r=window.requestAnimationFrame(o)}(),()=>window.cancelAnimationFrame(r)};function $s(e,t){const n=ft(e),r=x.useRef(0);return x.useEffect(()=>()=>window.clearTimeout(r.current),[]),x.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function Nr(e,t){const n=ft(t);on(()=>{let r=0;if(e){const o=new ResizeObserver(()=>{cancelAnimationFrame(r),r=window.requestAnimationFrame(n)});return o.observe(e),()=>{window.cancelAnimationFrame(r),o.unobserve(e)}}},[e,n])}var tp=Hh,XS=Vh,JS=Xh;const qa=x.forwardRef(({className:e,children:t,...n},r)=>d.jsxs(tp,{ref:r,className:he("relative overflow-hidden",e),...n,children:[d.jsx(XS,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),d.jsx(np,{}),d.jsx(JS,{})]}));qa.displayName=tp.displayName;const np=x.forwardRef(({className:e,orientation:t="vertical",...n},r)=>d.jsx(Wa,{ref:r,orientation:t,className:he("flex touch-none select-none transition-colors",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:d.jsx(Yh,{className:"relative flex-1 rounded-full bg-border"})}));np.displayName=Wa.displayName;function ZS({isOpen:e,onOpenChange:t,toolCall:n}){if(!n)return null;const{call:r,result:o,state:s}=n,i=r.args,a=o==null?void 0:o.content;return d.jsx(Fh,{open:e,onOpenChange:t,children:d.jsxs(za,{className:"max-w-2xl max-h-[85vh] flex flex-col p-0 gap-0 overflow-hidden",children:[d.jsxs(Ba,{className:"p-6 border-b shrink-0",children:[d.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[d.jsxs(Ua,{className:"text-xl font-bold",children:["Tool Usage: ",r.name]}),d.jsx("span",{className:he("text-[10px] px-2 py-0.5 rounded-full font-bold uppercase tracking-wider",s==="pending"?"bg-blue-100 text-blue-700":s==="error"?"bg-red-100 text-red-700":"bg-green-100 text-green-700"),children:s})]}),d.jsxs(Bh,{children:["ID: ",r.id]})]}),d.jsx(qa,{className:"flex-1 min-h-0 bg-muted/30",children:d.jsxs("div",{className:"p-6 space-y-6 pb-12",children:[d.jsxs("section",{className:"space-y-2",children:[d.jsx("h3",{className:"text-xs font-bold uppercase tracking-widest text-muted-foreground",children:"Input Arguments"}),d.jsx("div",{className:"rounded-lg border bg-background/50 shadow-sm overflow-hidden",children:d.jsx("pre",{className:"p-4 text-xs font-mono leading-relaxed overflow-x-auto whitespace-pre-wrap break-words",children:JSON.stringify(i,null,2)})})]}),d.jsxs("section",{className:"space-y-2",children:[d.jsxs("h3",{className:"text-xs font-bold uppercase tracking-widest text-muted-foreground flex items-center justify-between",children:[d.jsx("span",{children:"Output Result"}),(o==null?void 0:o.createdAt)&&d.jsx("span",{className:"font-normal normal-case text-[10px] opacity-60",children:new Date(o.createdAt).toLocaleTimeString()})]}),d.jsx("div",{className:"rounded-lg border bg-background/50 shadow-sm overflow-hidden min-h-[100px] flex",children:a?d.jsx("pre",{className:"p-4 text-xs font-mono leading-relaxed overflow-x-auto whitespace-pre-wrap break-words w-full",children:typeof a=="string"?a:JSON.stringify(a,null,2)}):d.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground/40 text-xs italic",children:s==="pending"?"Tool is currently executing...":"No output returned."})})]})]})})]})})}function jr({className:e="",placeholder:t="Type your message...",maxHeight:n=void 0,streamingDebounceMs:r=500,followNewMessages:o=!0,enableFileUpload:s=!0,enableExcelUpload:i=!1,enableMessageEditing:a=!0,showToolMessages:l=!0,toolConfig:c,toolRenderers:u,toolArtifactRenderers:f,payloadExtras:h={},customStyles:p={},messageCustomStyles:m,onMessageSent:b,onExcelUploadSuccess:g,onError:w,renderArtifactsInline:y=!0,emptyMessage:k}){var Z,$,X;const{currentThreadId:E}=Ur(),S=Kr(),C=Ec(),T=yh({submit:C.submit,chatRequest:{payload:h},lastCheckpointId:((Z=S.checkpoint)==null?void 0:Z.id)??null,lastCheckpointNs:(($=S.checkpoint)==null?void 0:$.namespace)??null,onMessageSent:b,onExcelUploadSuccess:g,onError:w,enableMessageEditing:a,messages:S.messages,unifiedMessages:C.messages,setPendingAssistantResponse:()=>{},activeThreadId:E??null}),N=S.interrupt,j=N?uc(N.id):null,_=j!==null?{type:"interrupt",id:j}:null,[D,z]=v.useState(!1),[H,P]=v.useState("desktop"),[M,F]=v.useState(!1),[ne,U]=v.useState(null),W=v.useRef(null);v.useEffect(()=>{const oe=()=>{const ue=window.innerWidth;P(ue<640?"phone":ue<1024?"tablet":"desktop")};return oe(),window.addEventListener("resize",oe),()=>window.removeEventListener("resize",oe)},[]);const Y=v.useCallback(async(oe,ue,le)=>{try{z(!0),await S.respondToInterrupt(oe,ue,le)}catch(Ce){console.error("Failed to respond to interrupt:",Ce)}finally{z(!1)}},[S]),q=v.useCallback(async oe=>{var ue,le;F(!0);try{if(!oe)await S.returnToLatest(),(ue=W.current)==null||ue.scrollToLatest();else{const Ce=S.checkpoints.find(De=>De.checkpointId===oe);await S.navigateToCheckpoint(oe,(Ce==null?void 0:Ce.checkpointNs)??null),(le=W.current)==null||le.scrollToTop()}}finally{F(!1)}},[S]),R=v.useMemo(()=>c??{toolRenderers:u,toolArtifactRenderers:f,getToolExpandable:oe=>oe.name!=="ask_user_choice"},[c,u,f]),G=!!N||D,A=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${p.container||""}`,O=`flex-1 min-h-0 min-w-0 max-h-full w-full overflow-hidden overscroll-contain break-words break-anywhere p-4 ${N?"pb-32":""} bg-transparent ${p.messagesArea||""}`,V=`relative flex-shrink-0 w-full border-t p-4 bg-transparent ${p.inputArea||""}`;return d.jsxs("div",{className:A,children:[!!C.error&&!T.dismissError&&d.jsxs("div",{className:"flex-shrink-0 bg-red-50 border border-red-200 text-red-800 px-4 py-2 text-sm flex items-center justify-between",children:[d.jsx("span",{children:C.error}),d.jsx(Je,{variant:"ghost",size:"sm",onClick:()=>T.setDismissError(!0),className:"text-red-800 hover:bg-red-100",children:d.jsx(xe.X,{size:16})})]}),d.jsxs("div",{className:`relative ${O}`,style:n?{maxHeight:n}:void 0,children:[d.jsx(Rc,{layoutSize:H,customStyles:p,messageCustomStyles:m,renderArtifactsInline:y,enableMessageEditing:a,editingMessageId:T.editingMessageId,showToolMessages:l,followNewMessages:o,showThinkingIndicator:C.isStreaming,streamingDebounceMs:r,toolConfig:R,checkpointIndex:S.checkpointIndex,activeCheckpointId:(X=S.checkpoint)==null?void 0:X.id,onSelectCheckpoint:q,pendingInterrupt:N,onEdit:T.startEditing,onRegenerate:T.handleRegenerateCb,onCancelEdit:T.cancelEditing,getInterruptOptions:()=>{},selectedToolCall:ne,onSelectToolCall:U,children:d.jsx(is,{ref:W,className:"h-full",style:{height:"100%"},messages:T.messages,isStreaming:C.isStreaming,emptyMessage:k})}),d.jsx(ZS,{isOpen:!!ne,onOpenChange:oe=>!oe&&U(null),toolCall:ne}),(C.connectionState==="reconnecting"||C.connectionState==="connecting")&&d.jsx("div",{className:"pointer-events-none absolute top-3 right-3 z-20 rounded-full bg-muted/80 px-3 py-1 text-xs font-medium text-foreground shadow-sm backdrop-blur-sm dark:bg-muted/60",children:d.jsxs("span",{className:"flex items-center gap-2",children:[d.jsx(xe.Loader2,{className:"h-3 w-3 animate-spin"}),C.connectionState==="reconnecting"?"Reconnecting…":"Connecting…"]})}),S.isLoading||M?d.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center gap-2 bg-background/80 backdrop-blur-sm text-muted-foreground",children:[d.jsx(xe.Loader2,{className:"h-6 w-6 animate-spin"}),d.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:S.isLoading?"Loading messages…":"Loading checkpoint…"})]}):null,N&&_&&d.jsx("div",{className:"pointer-events-auto absolute inset-x-0 bottom-6 z-30 flex justify-center px-4",children:d.jsx("div",{className:"w-full max-w-3xl",children:d.jsx(Yu,{interruptPart:_,onApprove:()=>Y(!0),onReject:()=>Y(!1),onSelectAlternative:(oe,ue)=>Y(!0,ue),disabled:D,isActive:!0,payload:N.value})})})]}),d.jsxs("div",{className:V,children:[T.editingMessageId&&d.jsxs("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg flex items-center justify-between",children:[d.jsxs("div",{className:"flex items-center gap-2",children:[d.jsx(xe.Edit3,{size:16,className:"text-blue-600"}),d.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),d.jsx(Je,{variant:"ghost",size:"sm",onClick:T.cancelEditing,className:"text-blue-600 hover:bg-blue-100",children:d.jsx(xe.X,{size:16})})]}),T.inputError&&d.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:T.inputError}),d.jsx(Ps,{composerValue:T.composerValue,onComposerChange:T.handleComposerChange,onSend:T.handleSendMessage,onCancelEdit:T.cancelEditing,onStop:C.stop,editingMessageId:T.editingMessageId,editingInitialValue:T.editingInitialValue,placeholder:T.editingMessageId?"Edit your message...":t,isStreaming:C.isStreaming,disabled:G,enableFileUpload:s,enableExcelUpload:i,onExcelUpload:T.handleExcelUpload,onError:w,customStyles:p,textareaClassName:p.textarea||"",allowEmptySend:!1,inputError:T.inputError})]})]})}var rp=1,QS=.9,eC=.8,tC=.17,Ga=.1,Ya=.999,nC=.9999,rC=.99,oC=/[\\\/_+.#"@\[\(\{&]/,sC=/[\\\/_+.#"@\[\(\{&]/g,iC=/[\s-]/,op=/[\s-]/g;function Xa(e,t,n,r,o,s,i){if(s===t.length)return o===e.length?rp:rC;var a=`${o},${s}`;if(i[a]!==void 0)return i[a];for(var l=r.charAt(s),c=n.indexOf(l,o),u=0,f,h,p,m;c>=0;)f=Xa(e,t,n,r,c+1,s+1,i),f>u&&(c===o?f*=rp:oC.test(e.charAt(c-1))?(f*=eC,p=e.slice(o,c-1).match(sC),p&&o>0&&(f*=Math.pow(Ya,p.length))):iC.test(e.charAt(c-1))?(f*=QS,m=e.slice(o,c-1).match(op),m&&o>0&&(f*=Math.pow(Ya,m.length))):(f*=tC,o>0&&(f*=Math.pow(Ya,c-o))),e.charAt(c)!==t.charAt(s)&&(f*=nC)),(f<Ga&&n.charAt(c-1)===r.charAt(s+1)||r.charAt(s+1)===r.charAt(s)&&n.charAt(c-1)!==r.charAt(s))&&(h=Xa(e,t,n,r,c+1,s+2,i),h*Ga>f&&(f=h*Ga)),f>u&&(u=f),c=n.indexOf(l,c+1);return i[a]=u,u}function sp(e){return e.toLowerCase().replace(op," ")}function aC(e,t,n){return e=n&&n.length>0?`${e+" "+n.join(" ")}`:e,Xa(e,t,sp(e),sp(t),0,0,{})}var bo='[cmdk-group=""]',Ja='[cmdk-group-items=""]',lC='[cmdk-group-heading=""]',ip='[cmdk-item=""]',ap=`${ip}:not([aria-disabled="true"])`,Za="cmdk-item-select",_r="data-value",cC=(e,t,n)=>aC(e,t,n),lp=x.createContext(void 0),wo=()=>x.useContext(lp),cp=x.createContext(void 0),Qa=()=>x.useContext(cp),up=x.createContext(void 0),dp=x.forwardRef((e,t)=>{let n=Pr(()=>{var R,G;return{search:"",value:(G=(R=e.value)!=null?R:e.defaultValue)!=null?G:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),r=Pr(()=>new Set),o=Pr(()=>new Map),s=Pr(()=>new Map),i=Pr(()=>new Set),a=fp(e),{label:l,children:c,value:u,onValueChange:f,filter:h,shouldFilter:p,loop:m,disablePointerSelection:b=!1,vimBindings:g=!0,...w}=e,y=Rt(),k=Rt(),E=Rt(),S=x.useRef(null),C=yC();rr(()=>{if(u!==void 0){let R=u.trim();n.current.value=R,T.emit()}},[u]),rr(()=>{C(6,H)},[]);let T=x.useMemo(()=>({subscribe:R=>(i.current.add(R),()=>i.current.delete(R)),snapshot:()=>n.current,setState:(R,G,A)=>{var O,V,Z,$;if(!Object.is(n.current[R],G)){if(n.current[R]=G,R==="search")z(),_(),C(1,D);else if(R==="value"){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let X=document.getElementById(E);X?X.focus():(O=document.getElementById(y))==null||O.focus()}if(C(7,()=>{var X;n.current.selectedItemId=(X=P())==null?void 0:X.id,T.emit()}),A||C(5,H),((V=a.current)==null?void 0:V.value)!==void 0){let X=G??"";($=(Z=a.current).onValueChange)==null||$.call(Z,X);return}}T.emit()}},emit:()=>{i.current.forEach(R=>R())}}),[]),N=x.useMemo(()=>({value:(R,G,A)=>{var O;G!==((O=s.current.get(R))==null?void 0:O.value)&&(s.current.set(R,{value:G,keywords:A}),n.current.filtered.items.set(R,j(G,A)),C(2,()=>{_(),T.emit()}))},item:(R,G)=>(r.current.add(R),G&&(o.current.has(G)?o.current.get(G).add(R):o.current.set(G,new Set([R]))),C(3,()=>{z(),_(),n.current.value||D(),T.emit()}),()=>{s.current.delete(R),r.current.delete(R),n.current.filtered.items.delete(R);let A=P();C(4,()=>{z(),(A==null?void 0:A.getAttribute("id"))===R&&D(),T.emit()})}),group:R=>(o.current.has(R)||o.current.set(R,new Set),()=>{s.current.delete(R),o.current.delete(R)}),filter:()=>a.current.shouldFilter,label:l||e["aria-label"],getDisablePointerSelection:()=>a.current.disablePointerSelection,listId:y,inputId:E,labelId:k,listInnerRef:S}),[]);function j(R,G){var A,O;let V=(O=(A=a.current)==null?void 0:A.filter)!=null?O:cC;return R?V(R,n.current.search,G):0}function _(){if(!n.current.search||a.current.shouldFilter===!1)return;let R=n.current.filtered.items,G=[];n.current.filtered.groups.forEach(O=>{let V=o.current.get(O),Z=0;V.forEach($=>{let X=R.get($);Z=Math.max(X,Z)}),G.push([O,Z])});let A=S.current;M().sort((O,V)=>{var Z,$;let X=O.getAttribute("id"),oe=V.getAttribute("id");return((Z=R.get(oe))!=null?Z:0)-(($=R.get(X))!=null?$:0)}).forEach(O=>{let V=O.closest(Ja);V?V.appendChild(O.parentElement===V?O:O.closest(`${Ja} > *`)):A.appendChild(O.parentElement===A?O:O.closest(`${Ja} > *`))}),G.sort((O,V)=>V[1]-O[1]).forEach(O=>{var V;let Z=(V=S.current)==null?void 0:V.querySelector(`${bo}[${_r}="${encodeURIComponent(O[0])}"]`);Z==null||Z.parentElement.appendChild(Z)})}function D(){let R=M().find(A=>A.getAttribute("aria-disabled")!=="true"),G=R==null?void 0:R.getAttribute(_r);T.setState("value",G||void 0)}function z(){var R,G,A,O;if(!n.current.search||a.current.shouldFilter===!1){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let V=0;for(let Z of r.current){let $=(G=(R=s.current.get(Z))==null?void 0:R.value)!=null?G:"",X=(O=(A=s.current.get(Z))==null?void 0:A.keywords)!=null?O:[],oe=j($,X);n.current.filtered.items.set(Z,oe),oe>0&&V++}for(let[Z,$]of o.current)for(let X of $)if(n.current.filtered.items.get(X)>0){n.current.filtered.groups.add(Z);break}n.current.filtered.count=V}function H(){var R,G,A;let O=P();O&&(((R=O.parentElement)==null?void 0:R.firstChild)===O&&((A=(G=O.closest(bo))==null?void 0:G.querySelector(lC))==null||A.scrollIntoView({block:"nearest"})),O.scrollIntoView({block:"nearest"}))}function P(){var R;return(R=S.current)==null?void 0:R.querySelector(`${ip}[aria-selected="true"]`)}function M(){var R;return Array.from(((R=S.current)==null?void 0:R.querySelectorAll(ap))||[])}function F(R){let G=M()[R];G&&T.setState("value",G.getAttribute(_r))}function ne(R){var G;let A=P(),O=M(),V=O.findIndex($=>$===A),Z=O[V+R];(G=a.current)!=null&&G.loop&&(Z=V+R<0?O[O.length-1]:V+R===O.length?O[0]:O[V+R]),Z&&T.setState("value",Z.getAttribute(_r))}function U(R){let G=P(),A=G==null?void 0:G.closest(bo),O;for(;A&&!O;)A=R>0?bC(A,bo):wC(A,bo),O=A==null?void 0:A.querySelector(ap);O?T.setState("value",O.getAttribute(_r)):ne(R)}let W=()=>F(M().length-1),Y=R=>{R.preventDefault(),R.metaKey?W():R.altKey?U(1):ne(1)},q=R=>{R.preventDefault(),R.metaKey?F(0):R.altKey?U(-1):ne(-1)};return x.createElement(Ae.div,{ref:t,tabIndex:-1,...w,"cmdk-root":"",onKeyDown:R=>{var G;(G=w.onKeyDown)==null||G.call(w,R);let A=R.nativeEvent.isComposing||R.keyCode===229;if(!(R.defaultPrevented||A))switch(R.key){case"n":case"j":{g&&R.ctrlKey&&Y(R);break}case"ArrowDown":{Y(R);break}case"p":case"k":{g&&R.ctrlKey&&q(R);break}case"ArrowUp":{q(R);break}case"Home":{R.preventDefault(),F(0);break}case"End":{R.preventDefault(),W();break}case"Enter":{R.preventDefault();let O=P();if(O){let V=new Event(Za);O.dispatchEvent(V)}}}}},x.createElement("label",{"cmdk-label":"",htmlFor:N.inputId,id:N.labelId,style:SC},l),Fs(e,R=>x.createElement(cp.Provider,{value:T},x.createElement(lp.Provider,{value:N},R))))}),uC=x.forwardRef((e,t)=>{var n,r;let o=Rt(),s=x.useRef(null),i=x.useContext(up),a=wo(),l=fp(e),c=(r=(n=l.current)==null?void 0:n.forceMount)!=null?r:i==null?void 0:i.forceMount;rr(()=>{if(!c)return a.item(o,i==null?void 0:i.id)},[c]);let u=hp(o,s,[e.value,e.children,s],e.keywords),f=Qa(),h=Ln(C=>C.value&&C.value===u.current),p=Ln(C=>c||a.filter()===!1?!0:C.search?C.filtered.items.get(o)>0:!0);x.useEffect(()=>{let C=s.current;if(!(!C||e.disabled))return C.addEventListener(Za,m),()=>C.removeEventListener(Za,m)},[p,e.onSelect,e.disabled]);function m(){var C,T;b(),(T=(C=l.current).onSelect)==null||T.call(C,u.current)}function b(){f.setState("value",u.current,!0)}if(!p)return null;let{disabled:g,value:w,onSelect:y,forceMount:k,keywords:E,...S}=e;return x.createElement(Ae.div,{ref:Pn(s,t),...S,id:o,"cmdk-item":"",role:"option","aria-disabled":!!g,"aria-selected":!!h,"data-disabled":!!g,"data-selected":!!h,onPointerMove:g||a.getDisablePointerSelection()?void 0:b,onClick:g?void 0:m},e.children)}),dC=x.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:o,...s}=e,i=Rt(),a=x.useRef(null),l=x.useRef(null),c=Rt(),u=wo(),f=Ln(p=>o||u.filter()===!1?!0:p.search?p.filtered.groups.has(i):!0);rr(()=>u.group(i),[]),hp(i,a,[e.value,e.heading,l]);let h=x.useMemo(()=>({id:i,forceMount:o}),[o]);return x.createElement(Ae.div,{ref:Pn(a,t),...s,"cmdk-group":"",role:"presentation",hidden:f?void 0:!0},n&&x.createElement("div",{ref:l,"cmdk-group-heading":"","aria-hidden":!0,id:c},n),Fs(e,p=>x.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?c:void 0},x.createElement(up.Provider,{value:h},p))))}),fC=x.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,o=x.useRef(null),s=Ln(i=>!i.search);return!n&&!s?null:x.createElement(Ae.div,{ref:Pn(o,t),...r,"cmdk-separator":"",role:"separator"})}),hC=x.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,o=e.value!=null,s=Qa(),i=Ln(c=>c.search),a=Ln(c=>c.selectedItemId),l=wo();return x.useEffect(()=>{e.value!=null&&s.setState("search",e.value)},[e.value]),x.createElement(Ae.input,{ref:t,...r,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":l.listId,"aria-labelledby":l.labelId,"aria-activedescendant":a,id:l.inputId,type:"text",value:o?e.value:i,onChange:c=>{o||s.setState("search",c.target.value),n==null||n(c.target.value)}})}),pC=x.forwardRef((e,t)=>{let{children:n,label:r="Suggestions",...o}=e,s=x.useRef(null),i=x.useRef(null),a=Ln(c=>c.selectedItemId),l=wo();return x.useEffect(()=>{if(i.current&&s.current){let c=i.current,u=s.current,f,h=new ResizeObserver(()=>{f=requestAnimationFrame(()=>{let p=c.offsetHeight;u.style.setProperty("--cmdk-list-height",p.toFixed(1)+"px")})});return h.observe(c),()=>{cancelAnimationFrame(f),h.unobserve(c)}}},[]),x.createElement(Ae.div,{ref:Pn(s,t),...o,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":a,"aria-label":r,id:l.listId},Fs(e,c=>x.createElement("div",{ref:Pn(i,l.listInnerRef),"cmdk-list-sizer":""},c)))}),mC=x.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:o,contentClassName:s,container:i,...a}=e;return x.createElement(Dh,{open:n,onOpenChange:r},x.createElement(Lh,{container:i},x.createElement($a,{"cmdk-overlay":"",className:o}),x.createElement(Fa,{"aria-label":e.label,"cmdk-dialog":"",className:s},x.createElement(dp,{ref:t,...a}))))}),gC=x.forwardRef((e,t)=>Ln(n=>n.filtered.count===0)?x.createElement(Ae.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),xC=x.forwardRef((e,t)=>{let{progress:n,children:r,label:o="Loading...",...s}=e;return x.createElement(Ae.div,{ref:t,...s,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":o},Fs(e,i=>x.createElement("div",{"aria-hidden":!0},i)))}),Et=Object.assign(dp,{List:pC,Item:uC,Input:hC,Group:dC,Separator:fC,Dialog:mC,Empty:gC,Loading:xC});function bC(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function wC(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function fp(e){let t=x.useRef(e);return rr(()=>{t.current=e}),t}var rr=typeof window>"u"?x.useEffect:x.useLayoutEffect;function Pr(e){let t=x.useRef();return t.current===void 0&&(t.current=e()),t}function Ln(e){let t=Qa(),n=()=>e(t.snapshot());return x.useSyncExternalStore(t.subscribe,n,n)}function hp(e,t,n,r=[]){let o=x.useRef(),s=wo();return rr(()=>{var i;let a=(()=>{var c;for(let u of n){if(typeof u=="string")return u.trim();if(typeof u=="object"&&"current"in u)return u.current?(c=u.current.textContent)==null?void 0:c.trim():o.current}})(),l=r.map(c=>c.trim());s.value(e,a,l),(i=t.current)==null||i.setAttribute(_r,a),o.current=a}),o}var yC=()=>{let[e,t]=x.useState(),n=Pr(()=>new Map);return rr(()=>{n.current.forEach(r=>r()),n.current=new Map},[e]),(r,o)=>{n.current.set(r,o),t({})}};function vC(e){let t=e.type;return typeof t=="function"?t(e.props):"render"in t?t.render(e.props):e}function Fs({asChild:e,children:t},n){return e&&x.isValidElement(t)?x.cloneElement(vC(t),{ref:t.ref},n(t.props.children)):n(t)}var SC={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};const pp=x.forwardRef(({className:e,...t},n)=>d.jsx(Et,{ref:n,className:he("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",e),...t}));pp.displayName=Et.displayName;const mp=x.forwardRef(({className:e,...t},n)=>d.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[d.jsx(xe.Search,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),d.jsx(Et.Input,{ref:n,className:he("flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",e),...t})]}));mp.displayName=Et.Input.displayName;const gp=x.forwardRef(({className:e,...t},n)=>d.jsx(Et.List,{ref:n,className:he("max-h-[300px] overflow-y-auto overflow-x-hidden",e),...t}));gp.displayName=Et.List.displayName;const xp=x.forwardRef((e,t)=>d.jsx(Et.Empty,{ref:t,className:"py-6 text-center text-sm",...e}));xp.displayName=Et.Empty.displayName;const bp=x.forwardRef(({className:e,...t},n)=>d.jsx(Et.Group,{ref:n,className:he("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",e),...t}));bp.displayName=Et.Group.displayName;const CC=x.forwardRef(({className:e,...t},n)=>d.jsx(Et.Separator,{ref:n,className:he("-mx-1 h-px bg-border",e),...t}));CC.displayName=Et.Separator.displayName;const wp=x.forwardRef(({className:e,...t},n)=>d.jsx(Et.Item,{ref:n,className:he("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected='true']:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50",e),...t}));wp.displayName=Et.Item.displayName;function yp({thread:e,isActive:t=!1,editingThreadId:n,editingTitle:r="",onSelect:o,onStartEditing:s,onEditingTitleChange:i,onSaveEditing:a,onCancelEditing:l,onShare:c,onDelete:u,showEditTitle:f=!0,showDeleteButton:h=!0,onMenuOpenChange:p,onMenuAction:m,formatDate:b,getDisplayThreadTitle:g,itemClassName:w,activeItemClassName:y,secondaryLine:k}){const E=n===e.threadId,S=v.useMemo(()=>(g==null?void 0:g(e))??e.title??e.threadId,[g,e]),C=()=>o==null?void 0:o(e.threadId),T=N=>s==null?void 0:s(e,N);return d.jsxs("div",{className:he("flex items-center justify-between rounded px-2 py-1 text-sm hover:bg-muted cursor-pointer",w,t&&(y??"bg-muted/70")),onClick:C,children:[d.jsxs("div",{className:"flex flex-col min-w-0",children:[E?d.jsx("input",{className:"text-sm px-2 py-1 border rounded",value:r,onChange:N=>i==null?void 0:i(N.target.value)}):d.jsx("span",{className:"font-medium truncate",children:S}),k&&d.jsx("span",{className:"text-xs text-muted-foreground truncate",children:k}),b&&e.updatedAt&&d.jsx("span",{className:"text-[10px] text-muted-foreground",children:b(e.updatedAt)})]}),d.jsx("div",{className:"flex items-center gap-1",children:E?d.jsxs("div",{className:"flex items-center gap-1",children:[d.jsx(Je,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs",onClick:N=>{N.stopPropagation(),a==null||a(e)},children:"Save"}),d.jsx(Je,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs",onClick:N=>{N.stopPropagation(),l==null||l(e)},children:"Cancel"})]}):d.jsxs(Pa,{onOpenChange:N=>p==null?void 0:p(e.threadId,N),children:[d.jsx(Ra,{asChild:!0,children:d.jsxs(Je,{size:"sm",variant:"ghost",className:"h-8 w-8 p-0 opacity-0 group-hover:opacity-100 data-[state=open]:opacity-100 transition-opacity",onClick:N=>N.stopPropagation(),children:[d.jsx(xe.MoreVertical,{className:"h-4 w-4"}),d.jsx("span",{className:"sr-only",children:"Open menu"})]})}),d.jsxs(_s,{align:"end",children:[f&&d.jsxs(tr,{onClick:N=>{N.stopPropagation(),m==null||m(e.threadId,"rename"),T(N)},children:[d.jsx(xe.Edit3,{className:"mr-2 h-4 w-4"}),d.jsx("span",{children:"Rename"})]}),c&&d.jsxs(tr,{onClick:N=>{N.stopPropagation(),m==null||m(e.threadId,"share"),c(e)},children:[d.jsx(xe.Share2,{className:"mr-2 h-4 w-4"}),d.jsx("span",{children:"Share"})]}),h&&d.jsxs(tr,{onClick:N=>{N.stopPropagation(),m==null||m(e.threadId,"delete"),u==null||u(e)},className:"text-destructive focus:text-destructive",children:[d.jsx(xe.Trash2,{className:"mr-2 h-4 w-4"}),d.jsx("span",{children:"Delete"})]})]})]})})]})}var zs="Collapsible",[TC,ST]=Rn(zs),[kC,el]=TC(zs),vp=x.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[l,c]=as({prop:r,defaultProp:o??!1,onChange:i,caller:zs});return d.jsx(kC,{scope:n,disabled:s,contentId:Rt(),open:l,onOpenToggle:x.useCallback(()=>c(u=>!u),[c]),children:d.jsx(Ae.div,{"data-state":nl(l),"data-disabled":s?"":void 0,...a,ref:t})})});vp.displayName=zs;var Sp="CollapsibleTrigger",Cp=x.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=el(Sp,n);return d.jsx(Ae.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":nl(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:ye(e.onClick,o.onOpenToggle)})});Cp.displayName=Sp;var tl="CollapsibleContent",Tp=x.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=el(tl,e.__scopeCollapsible);return d.jsx(Dt,{present:n||o.open,children:({present:s})=>d.jsx(EC,{...r,ref:t,present:s})})});Tp.displayName=tl;var EC=x.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=el(tl,n),[a,l]=x.useState(r),c=x.useRef(null),u=Xe(t,c),f=x.useRef(0),h=f.current,p=x.useRef(0),m=p.current,b=i.open||a,g=x.useRef(b),w=x.useRef(void 0);return x.useEffect(()=>{const y=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(y)},[]),on(()=>{const y=c.current;if(y){w.current=w.current||{transitionDuration:y.style.transitionDuration,animationName:y.style.animationName},y.style.transitionDuration="0s",y.style.animationName="none";const k=y.getBoundingClientRect();f.current=k.height,p.current=k.width,g.current||(y.style.transitionDuration=w.current.transitionDuration,y.style.animationName=w.current.animationName),l(r)}},[i.open,r]),d.jsx(Ae.div,{"data-state":nl(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!b,...s,ref:u,style:{"--radix-collapsible-content-height":h?`${h}px`:void 0,"--radix-collapsible-content-width":m?`${m}px`:void 0,...e.style},children:b&&o})});function nl(e){return e?"open":"closed"}var IC=vp;const AC=IC,NC=Cp,jC=Tp,kp=25,Ep=Sn.threadManagerView,_C=e=>e==="default"||e==="shared",PC=()=>{if(typeof window>"u")return null;try{const e=window.localStorage.getItem(Ep);if(_C(e))return e}catch{}return null};function Ip({defaultView:e}={}){const[t,n]=v.useState(()=>PC()??e??"default");v.useEffect(()=>{if(!(typeof window>"u"))try{window.localStorage.setItem(Ep,t)}catch{}},[t]);const r=v.useCallback(o=>{n(o)},[]);return{view:t,setView:r}}const RC=[{key:"default",label:"My chats"},{key:"shared",label:"Shared with you"}];function Bs({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,onItemMenuOpenChange:o,onItemMenuAction:s,maxHeight:i="400px",customStyles:a={},currentThreadId:l=null,navigateToThread:c,onThreadSelect:u,onThreadCreate:f,onThreadDelete:h,view:p,defaultView:m,onViewChange:b,viewOptions:g,viewState:w,showHeader:y=!0,shareTargets:k,isLoadingShareTargets:E,shareTargetFilter:S,groupBy:C,filter:T}){const{chatApi:N,authApi:j}=fr(),{threads:_,sharedThreads:D,currentThreadId:z,setCurrentThreadId:H,isLoading:P,isLoadingSharedThreads:M,actions:F,shareInFlight:ne,shareStatus:U,clearShareStatus:W}=Ur(),{createThread:Y,deleteThread:q,renameThread:R,shareThread:G}=F,{loadThread:A}=Kr(),O=l??z,[V,Z]=v.useState(Array.isArray(_)?_:[]),$=v.useRef(V.length>0),X=v.useRef(null),oe=v.useRef(0),[ue,le]=v.useState(null),[Ce,De]=v.useState(""),[Ie,qe]=v.useState(!1),[We,Fe]=v.useState(!1),[ze,It]=v.useState(null),[At,bt]=v.useState(""),[wt,ht]=v.useState([]),[st,Nt]=v.useState(!1),jt=v.useCallback(L=>De(L),[]);v.useEffect(()=>{We&&!k&&wt.length===0&&!st&&(async()=>{Nt(!0);try{const se=(await j.listUsers()).filter(ie=>ie.id||ie.user_id).map(ie=>({type:"user",value:ie.user_id||ie.id||"",id:ie.user_id||ie.id||"",label:ie.name||ie.username||ie.email||"Unknown User",secondaryLabel:ie.name||ie.username?ie.email:void 0}));ht(se)}catch(K){console.error("Failed to load users for sharing:",K)}finally{Nt(!1)}})()},[We,k,wt.length,st,N]);const Ut=k??wt,nt=E??st,Ze=g&&g.length>0?g:RC,yt=Ip({defaultView:m}),Be=w??yt,Le=p??Be.view,Ht=v.useCallback(L=>{p||Be.setView(L),b==null||b(L)},[p,b,Be]),or=Ze.find(L=>L.key===Le)??Ze[0],Wt=L=>{It(L),bt(""),Fe(!0)},fn=()=>{Fe(!1),It(null),bt(""),W()},Vt=v.useCallback(async L=>{if(!(!ze||ne)&&L.id)try{await G(ze,L.id),setTimeout(()=>fn(),600)}catch(K){console.error("Failed to share thread:",K)}},[fn,ne,ze,G]),Lt=v.useMemo(()=>{const L=Ut,K=At.trim().toLowerCase();return K?S?L.filter(se=>S(se,K)):L.filter(se=>`${se.label} ${se.secondaryLabel??""}`.toLowerCase().includes(K)):L},[k,At,S]),it=Le==="shared",$n=it?D:V,Qt=T?$n.filter(T):$n,wn=v.useMemo(()=>{const L=Array.isArray(C)?C:[];if(L.length===0||it)return null;const K="Default",se=me=>{if(!me)return"Older";try{const Oe=me.endsWith("Z")||me.includes("+")?me:`${me}Z`,Pe=new Date(Oe),$e=new Date,at=new Date($e.getFullYear(),$e.getMonth(),$e.getDate()),mn=new Date(Pe.getFullYear(),Pe.getMonth(),Pe.getDate()),ar=Math.floor((at.getTime()-mn.getTime())/(1e3*60*60*24));return ar===0?"Today":ar===1?"Yesterday":ar<=7?"Last 7 Days":"Older"}catch{return"Older"}},ie=(me,Oe)=>{var $e,at;if(Oe==="project")return(($e=me.project)==null?void 0:$e.name)||((at=me.project)==null?void 0:at.id)||K;if(Oe==="menuItem")return me.menuItem||K;if(Oe==="updatedAt"||Oe==="createdAt"){const mn=Oe==="updatedAt"?me.updatedAt:me.createdAt;return se(mn)}const Pe=me[Oe];return typeof Pe=="string"?Pe||K:typeof Pe=="number"?String(Pe):Pe==null?K:String(Pe)},fe=(me,Oe)=>{const Pe={};return me.forEach($e=>{const at=ie($e,Oe);Pe[at]||(Pe[at]=[]),Pe[at].push($e)}),Pe},je=(me,Oe)=>{if(Oe.length===0)return me;const[Pe,...$e]=Oe,at=fe(me,Pe);if($e.length===0)return at;const mn={};return Object.entries(at).forEach(([ar,KC])=>{mn[ar]=je(KC,$e)}),mn},_e=me=>{if(Array.isArray(me)){me.sort((Oe,Pe)=>new Date(Pe.updatedAt||Pe.createdAt||"").getTime()-new Date(Oe.updatedAt||Oe.createdAt||"").getTime());return}Object.values(me).forEach(_e)},ve=je(Qt,L);return _e(ve),{kind:"nested",groups:ve}},[Qt,C,it]),vo=it?M:P,Ge=it?"No shared conversations yet":"No conversations yet",Qe=L=>{const K=L.sharedAt?` • ${zn(L.sharedAt)}`:"";return`Shared by ${L.sharedByUserId}${K}`},hn=L=>"sharedByUserId"in L;v.useEffect(()=>{const L=Array.isArray(_)?_:[];if(L.length>0){$.current=!0,Z(L);return}P||($.current=!1,Z(L))},[_,P]),v.useEffect(()=>{if(!X.current)return;const L=X.current.querySelector("[data-radix-scroll-area-viewport]");if(!L)return;let K=null,se=null;return K=requestAnimationFrame(()=>{se=requestAnimationFrame(()=>{L.scrollTop=oe.current})}),()=>{K!==null&&cancelAnimationFrame(K),se!==null&&cancelAnimationFrame(se)}},[V]);const pn=async L=>{try{H(L),await A(L),c==null||c(L),u==null||u(L)}catch(K){console.error("Failed to select thread:",K)}},Fn=async()=>{try{qe(!0);const L=await Y();L&&(f==null||f(L),c==null||c(L))}catch(L){console.error("Failed to create thread:",L)}finally{qe(!1)}},yn=async(L,K)=>{const se=L.threadId;if(confirm("Delete this thread?")){if(X.current){const ie=X.current.querySelector("[data-radix-scroll-area-viewport]");ie&&(oe.current=ie.scrollTop)}try{await q(se),h==null||h(se)}catch(ie){console.error("Failed to delete thread:",ie)}}},vn=(L,K)=>{K==null||K.stopPropagation(),le(L.threadId),De(L.title||`Thread ${L.threadId.slice(0,8)}`)},sr=async L=>{const K=typeof L=="string"?L:L.threadId;if(Ce.trim())try{await R(K,Ce.trim()),le(null),De("")}catch(se){console.error("Failed to update title:",se)}},Rr=L=>{le(null),De("")},zn=L=>{if(!L)return"";try{const K=L.endsWith("Z")||L.includes("+")?L:`${L}Z`,se=new Date(K),fe=new Date().getTime()-se.getTime(),je=Math.floor(fe/(1e3*60*60*24));return je===0?se.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):je===1?"Yesterday":je<7?`${je} days ago`:se.toLocaleDateString()}catch{return""}},ir=L=>L.title||`Thread ${L.threadId.slice(0,8)}`,Bn=L=>{const K=ir(L);return K.length<=kp?K:`${K.slice(0,kp)}...`},I=L=>Array.isArray(L)?L.length:Object.values(L).reduce((K,se)=>Array.isArray(se)?K+se.length:K+I(se),0),ee=L=>{const se=["Today","Yesterday","Last 7 Days","Older"].indexOf(L);return se===-1?null:se},Q=(L,K,se)=>{if(Array.isArray(L))return L.map(ve=>d.jsx(yp,{thread:ve,isActive:O===ve.threadId,editingThreadId:ue,editingTitle:Ce,onSelect:pn,onStartEditing:vn,onEditingTitleChange:jt,onSaveEditing:me=>void sr(me),onCancelEditing:()=>Rr(),onShare:me=>Wt(me.threadId),onDelete:me=>yn(me),showEditTitle:r,showDeleteButton:n,onMenuOpenChange:o,onMenuAction:s,formatDate:zn,getDisplayThreadTitle:Bn,secondaryLine:it&&hn(ve)?Qe(ve):void 0,itemClassName:a.threadItem,activeItemClassName:a.activeThread},ve.threadId));const ie=["flex items-center w-full px-2 py-1 text-xs font-semibold text-slate-600 hover:text-slate-900 dark:hover:text-slate-200","flex items-center w-full px-2 py-1 text-[11px] font-medium text-slate-500 hover:text-slate-800 dark:hover:text-slate-200","flex items-center w-full px-2 py-1 text-[10px] font-medium text-slate-400 hover:text-slate-600 dark:hover:text-slate-300"],fe="pl-2 border-l border-slate-100 dark:border-slate-800 ml-1.5 my-1 space-y-1",je=ie[K]??ie[ie.length-1],_e=Object.entries(L);if(_e.length===1){const[ve,me]=_e[0];return Q(me,K+1,`${se}-${ve}`)}return _e.sort(([ve],[me])=>{const Oe="Default";if(ve===Oe)return 1;if(me===Oe)return-1;const Pe=ee(ve),$e=ee(me);if(Pe!==null||$e!==null){const at=Pe??Number.MAX_SAFE_INTEGER,mn=$e??Number.MAX_SAFE_INTEGER;return at-mn}return ve.localeCompare(me)}).map(([ve,me])=>{const Oe=`${se}-${ve}`,Pe=I(me);return d.jsxs(AC,{defaultOpen:!0,className:"group/collapsible",children:[d.jsxs(NC,{className:je,children:[d.jsx(xe.ChevronRight,{className:"w-3 h-3 mr-1 transition-transform group-data-[state=open]/collapsible:rotate-90"}),ve,d.jsx("span",{className:"ml-auto text-[10px] text-slate-400",children:Pe})]}),d.jsx(jC,{children:d.jsx("div",{className:fe,children:Q(me,K+1,Oe)})})]},Oe)})};return d.jsxs("div",{className:`thread-manager-root flex flex-col h-full ${e} ${a.container||""}`,children:[y&&d.jsxs("div",{className:a.header||"flex flex-col gap-2 px-1 py-0 border border-slate-200 bg-white dark:border-slate-700 dark:bg-slate-900 shadow-sm",children:[t&&d.jsx("div",{className:"flex justify-end",children:d.jsxs(Je,{onClick:Fn,disabled:Ie||P,className:a.createButton||"px-3 py-2 gap-1",size:"sm",variant:"ghost",title:Ie?"Creating...":"New Chat",children:[d.jsx(xe.Edit3,{size:16}),d.jsx("span",{children:"New chat"})]})}),d.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-slate-700 dark:text-slate-200 uppercase tracking-wide leading-tight",children:[d.jsx("span",{children:"Current View"}),d.jsxs(Pa,{children:[d.jsx(Ra,{asChild:!0,children:d.jsx(Je,{variant:"outline",size:"sm",className:"text-[11px] text-slate-700 dark:text-slate-200 border border-slate-300 dark:border-slate-600 bg-white dark:bg-slate-900 hover:bg-slate-50 dark:hover:bg-slate-800 px-2 py-0",children:or.label})}),d.jsx(_s,{align:"start",sideOffset:6,className:"w-40",children:Ze.map(L=>d.jsxs(tr,{className:"justify-between text-[12px]",onClick:K=>{K.preventDefault(),Ht(L.key)},children:[d.jsx("span",{children:L.label}),Le===L.key&&d.jsx(xe.Check,{className:"h-3 w-3"})]},L.key))})]})]})]}),d.jsx(qa,{ref:X,className:`flex-1 min-h-0 ${a.threadList||""}`,style:i?{maxHeight:i}:void 0,children:d.jsx("div",{className:"p-2 space-y-1 pb-4",children:vo?d.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[d.jsx(xe.Loader2,{className:"h-5 w-5 animate-spin"}),d.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):Qt.length===0?d.jsxs("div",{className:"text-center py-8 text-slate-400",children:[d.jsx(xe.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),d.jsx("p",{className:"text-sm text-slate-500",children:Ge})]}):(wn==null?void 0:wn.kind)==="nested"?Q(wn.groups,0,"group"):Qt.slice().sort((L,K)=>new Date(K.updatedAt||K.createdAt||"").getTime()-new Date(L.updatedAt||L.createdAt||"").getTime()).map(L=>d.jsx(yp,{thread:L,isActive:O===L.threadId,editingThreadId:ue,editingTitle:Ce,onSelect:pn,onStartEditing:vn,onEditingTitleChange:jt,onSaveEditing:K=>void sr(K),onCancelEditing:K=>Rr(),onShare:K=>Wt(K.threadId),onDelete:K=>yn(K),showEditTitle:r,showDeleteButton:n,onMenuOpenChange:o,onMenuAction:s,formatDate:zn,getDisplayThreadTitle:Bn,secondaryLine:it&&hn(L)?Qe(L):void 0,itemClassName:a.threadItem,activeItemClassName:a.activeThread},L.threadId))})}),d.jsx(Fh,{open:We,onOpenChange:L=>!L&&fn(),children:d.jsxs(za,{className:"max-w-md p-0",children:[d.jsx(Ba,{children:d.jsx(Ua,{children:"Share thread"})}),d.jsxs(pp,{children:[d.jsx(mp,{autoFocus:!0,value:At,onValueChange:L=>bt(L),placeholder:"Search for recipients..."}),d.jsxs(gp,{children:[U&&d.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-muted-foreground",children:[ne&&d.jsx(xe.Loader2,{className:"h-3 w-3 animate-spin"}),d.jsx("span",{className:U.startsWith("Failed")?"text-red-500":U.startsWith("Shared")?"text-emerald-500":"text-slate-600 dark:text-slate-400",children:U})]}),d.jsx(xp,{children:nt?d.jsxs("span",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[d.jsx(xe.Loader2,{className:"h-4 w-4 animate-spin"}),"Loading recipients…"]}):"No matching recipients found"}),Lt.length>0&&d.jsx(bp,{heading:"Recipients",children:Lt.map(L=>d.jsx(wp,{onSelect:()=>Vt(L),children:d.jsxs("div",{className:"flex flex-col items-start text-sm",children:[d.jsx("span",{className:"font-medium",children:L.label}),L.secondaryLabel&&d.jsx("span",{className:"text-xs text-muted-foreground",children:L.secondaryLabel})]})},L.id))})]})]})]})})]})}function OC({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},payloadExtras:s={},...i}){const a=u=>{const f="h-full";switch(u){case"phone":return`${f} max-w-none`;case"tablet":return`${f} max-w-4xl mx-auto`;case"half-screen":return`${f} max-w-2xl`;case"desktop":default:return`${f} max-w-7xl mx-auto`}},l=u=>({"--chat-sidebar-width":u==="phone"?"100%":u==="tablet"?"280px":u==="half-screen"?"240px":"320px","--chat-message-max-width":u==="phone"?"95%":u==="tablet"?"90%":u==="half-screen"?"85%":"80%","--chat-input-height":u==="phone"?"120px":"100px"}),c=v.useCallback(u=>{var f;(f=i.onThreadChange)==null||f.call(i,u)},[i]);return e==="fullscreen"?d.jsx(qr,{...i,onThreadChange:c,children:d.jsx("div",{className:`${a(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:l(t),children:d.jsx(jr,{className:"flex-1",onError:i.onError,enableFileUpload:!0,payloadExtras:s})})}):e==="tabs"?d.jsx(qr,{...i,onThreadChange:c,children:d.jsx("div",{className:`${a(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:l(t),children:d.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&d.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:d.jsx(Bs,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),d.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:d.jsx(jr,{onError:i.onError,enableFileUpload:!0,payloadExtras:s})})]})})}):d.jsx(qr,{...i,onThreadChange:c,children:d.jsxs("div",{className:`${a(t)} flex overflow-hidden ${r} ${o.container||""}`,style:l(t),children:[n&&d.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:d.jsx(Bs,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),d.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:d.jsx(jr,{onError:i.onError,enableFileUpload:!0,payloadExtras:s})})]})})}const MC=1,DC=1e6;let rl=0;function LC(){return rl=(rl+1)%Number.MAX_SAFE_INTEGER,rl.toString()}const ol=new Map,Ap=e=>{if(ol.has(e))return;const t=setTimeout(()=>{ol.delete(e),yo({type:"REMOVE_TOAST",toastId:e})},DC);ol.set(e,t)},$C=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,MC)};case"UPDATE_TOAST":return{...e,toasts:e.toasts.map(n=>n.id===t.toast.id?{...n,...t.toast}:n)};case"DISMISS_TOAST":{const{toastId:n}=t;return n?Ap(n):e.toasts.forEach(r=>{Ap(r.id)}),{...e,toasts:e.toasts.map(r=>r.id===n||n===void 0?{...r,open:!1}:r)}}case"REMOVE_TOAST":return t.toastId===void 0?{...e,toasts:[]}:{...e,toasts:e.toasts.filter(n=>n.id!==t.toastId)}}},Us=[];let Hs={toasts:[]};function yo(e){Hs=$C(Hs,e),Us.forEach(t=>{t(Hs)})}function FC({...e}){const t=LC(),n=o=>yo({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>yo({type:"DISMISS_TOAST",toastId:t});return yo({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function zC(){const[e,t]=x.useState(Hs);return x.useEffect(()=>(Us.push(t),()=>{const n=Us.indexOf(t);n>-1&&Us.splice(n,1)}),[e]),{...e,toast:FC,dismiss:n=>yo({type:"DISMISS_TOAST",toastId:n})}}function BC(e){const{allowFileOpen:t,currentThreadId:n}=e,{fileApi:r}=fr(),{toast:o}=zC(),[s,i]=v.useState({}),[a,l]=v.useState(null),[c,u]=v.useState(!1),f=v.useCallback(()=>{u(!1),l(null)},[]),h=v.useCallback(m=>{l(m),u(!0)},[]),p=v.useCallback(async(m,b,g)=>{var w,y;if(!t){m.preventDefault();return}if(s[g]){m.preventDefault();return}try{const k=String(b.url??""),E=k.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(E){m.preventDefault();const S=E[1],C=b.name||`file_${S}`,T=b.mimeType||"application/octet-stream";h({id:S,name:C,mimeType:T});return}if(k.startsWith("data:")){m.preventDefault(),i(C=>({...C,[g]:!0}));const S=o({title:"Fetching file...",description:"",open:!0});try{const C=await r.listFiles(n??void 0);if(!C||!Array.isArray(C))throw new Error("Invalid file list response");const T=C.find(N=>!N||typeof N!="object"||!((N.filename??"")===(b.name??""))?!1:typeof b.size=="number"&&typeof N.size=="number"?N.size===b.size:!0);if(!(T!=null&&T.id))throw new Error(`File "${b.name}" is not yet available on the server`);if(!T.id||!T.filename)throw new Error("Invalid file data received from server");h({id:T.id,name:b.name||T.filename||`file_${T.id}`,mimeType:b.mimeType||T.mime_type||"application/octet-stream"}),(w=S.update)==null||w.call(S,{id:S.id,title:"Success",description:`Opened ${b.name}`,open:!0})}catch(C){console.error("Failed to fetch server file:",C);const T=C instanceof Error?C.message:"Unknown error occurred";(y=S.update)==null||y.call(S,{id:S.id,title:"Failed",description:T}),o({title:"Failed to fetch file",description:T,open:!0})}finally{i(C=>({...C,[g]:!1}))}}}catch(k){console.error("File click error:",k),i(E=>({...E,[g]:!1}))}},[t,s,o,n,h]);return{uploadingFiles:s,handleFileClick:p,fileViewerOpen:c,currentFileInfo:a,closeFileViewer:f}}function UC(e){return v.useMemo(()=>{const t=e;let n=Array.isArray(t.content)?t.content:[];typeof t.content=="string"&&(n=[{type:"text",text:t.content}]);const r=t.additionalKwargs??{};return{contentParts:n,textContent:kg(n),toolMeta:dc(t),imageParts:n.filter(o=>o.type==="image_url"),fileParts:n.filter(o=>o.type==="file"),interruptParts:n.filter(o=>o.type==="interrupt"),toolRaw:fc(n),isToolStreaming:!!r.toolStreaming}},[e])}function HC({placeholder:e,onMessageSent:t}){const[n,r]=v.useState("chat");return d.jsxs("div",{className:"flex flex-col h-full",children:[d.jsxs("div",{className:"flex border-b border-gray-200 bg-gray-50",children:[d.jsx("button",{onClick:()=>r("chat"),className:`flex-1 px-3 py-2 text-sm font-medium transition-colors ${n==="chat"?"border-b-2 border-slate-800 text-slate-800 bg-white":"text-gray-600 hover:text-gray-800"}`,children:d.jsxs("div",{className:"flex items-center justify-center gap-2",children:[d.jsx(xe.MessageSquare,{size:14}),"Chat"]})}),d.jsx("button",{onClick:()=>r("threads"),className:`flex-1 px-3 py-2 text-sm font-medium transition-colors ${n==="threads"?"border-b-2 border-slate-800 text-slate-800 bg-white":"text-gray-600 hover:text-gray-800"}`,children:d.jsxs("div",{className:"flex items-center justify-center gap-2",children:[d.jsx(xe.History,{size:14}),"History"]})})]}),d.jsx("div",{className:"flex-1 min-h-0",children:n==="chat"?d.jsx(jr,{placeholder:e??"Ask Serti AI anything...",className:"h-full",onMessageSent:t}):d.jsx(Bs,{showCreateButton:!0,className:"h-full",onThreadSelect:()=>r("chat")})})]})}function WC({className:e="",placeholder:t,isAuthenticated:n=!0,onMessageSent:r,widgetTitle:o="Serti AI Navigator",widgetSubtitle:s="AI-Powered Assistant",...i}){const[a,l]=v.useState(!1);return n?d.jsx(qr,{...i,children:d.jsx("div",{className:`fixed bottom-6 right-6 z-[9999] transition-all duration-300 ${e}`,children:d.jsxs("div",{className:`w-96 bg-white rounded-xl shadow-2xl border border-gray-200 overflow-hidden relative ${a?"scale-75":"scale-100"}`,children:[d.jsx("div",{className:"bg-slate-800 text-white p-4 flex-shrink-0",children:d.jsxs("div",{className:"flex items-center justify-between gap-3",children:[d.jsxs("div",{className:"flex items-center gap-3",children:[d.jsxs("div",{className:"relative h-10 w-10 rounded-full bg-gradient-to-br from-slate-500 to-slate-700 border border-white/30 flex items-center justify-center text-white text-sm font-bold",children:["S",d.jsx("span",{className:"absolute -bottom-0.5 -right-0.5 h-3 w-3 rounded-full border-2 border-slate-800 bg-emerald-400"})]}),d.jsxs("div",{className:"flex flex-col",children:[d.jsx("h3",{className:"text-lg font-semibold leading-tight",children:o}),d.jsx("p",{className:"text-xs text-white/70",children:s})]}),d.jsx("span",{className:"ml-2 inline-flex items-center justify-center rounded-full bg-red-500 px-2 py-0.5 text-[11px] font-semibold leading-none text-white",children:"1"})]}),d.jsxs("div",{className:"flex items-center gap-1",children:[d.jsx(Je,{variant:"ghost",size:"sm",className:"text-white hover:bg-white/10 h-8 w-8 p-0",title:"Options",children:d.jsx(xe.MoreHorizontal,{size:16})}),d.jsx(Je,{variant:"ghost",size:"sm",className:"text-white hover:bg-white/10 h-8 w-8 p-0",title:"Compose",children:d.jsx(xe.Edit3,{size:16})}),d.jsx(Je,{variant:"ghost",size:"sm",onClick:c=>{c.stopPropagation(),l(u=>!u)},className:"text-white hover:bg-white/10 h-8 w-8 p-0",title:a?"Maximize":"Minimize",children:a?d.jsx(xe.Maximize2,{size:14}):d.jsx(xe.Minimize2,{size:14})})]})]})}),!a&&d.jsx("div",{className:"h-96 flex flex-col",children:d.jsx(HC,{placeholder:t,onMessageSent:r})})]})})}):null}function VC({label:e="New chat",children:t,className:n,variant:r="ghost",size:o="sm",...s}){return d.jsxs(Je,{variant:r,size:o,className:he("gap-2 rounded-full px-3 font-semibold transition-all hover:scale-[1.01]",n),...s,children:[d.jsx(xe.Edit3,{size:16}),t??e]})}J.ApiProvider=nc,J.AssistantMessageComponent=Ki,J.ChatApi=Jl,J.ChatApp=OC,J.ChatContainer=jr,J.ChatInput=Oa,J.ChatInputArea=Ps,J.ChatInputRow=Ps,J.ChatInterface=jr,J.ChatMessagesArea=is,J.ChatProviders=qr,J.ChatUIProvider=Rc,J.ChatWidget=WC,J.Composer=Oa,J.DEFAULT_TIMEOUT_MS=Gl,J.FileApi=Zl,J.HISTORY_TIMEOUT_MS=Yl,J.MarkdownContent=oo,J.MessageBubble=io,J.MessageHeader=Wi,J.MessageList=is,J.NewChatButton=VC,J.SETTINGS_STORAGE_KEY=gi,J.STORAGE_KEYS=Sn,J.SystemMessageComponent=Gi,J.ThreadManager=Bs,J.ThreadStateProvider=_c,J.ThreadsProvider=sc,J.ToolCallCard=zi,J.ToolContent=es,J.ToolProgress=Hu,J.UserMessageComponent=qi,J.applySettings=gx,J.chatApiClient=Tn,J.cn=_p,J.createTaskSyncToolEndHandler=hx,J.del=si,J.draftKey=Po,J.extractTaskIdFromToolEnd=Ic,J.extractToolCalls=li,J.extractToolContent=Wr,J.fileApiClient=ii,J.fileToBase64=Cc,J.formatToolOutput=Ng,J.get=Tt,J.getChatToken=ri,J.getCurrentSettings=mx,J.getDefaultApiConfig=Fc,J.getDefaultChatSettings=zc,J.getToolCallArtifacts=Rg,J.getToolCalls=di,J.hasContent=jg,J.httpClient=pt,J.isEnvelope=yc,J.isFileLike=ci,J.loadStoredSettings=Bc,J.looksLikeMarkdown=ac,J.normalizeToolPayload=hc,J.normalizeToolPayloadValue=gr,J.onChatTokenChanged=oi,J.parseJsonSafe=hr,J.post=Fr,J.pretty=mr,J.processAttachments=Tc,J.put=Xl,J.sanitizeForDisplay=Vr,J.saveSettings=Uc,J.setChatToken=Cn,J.stringifyTool=fc,J.unwrap=mt,J.useApi=fr,J.useChatController=yh,J.useChatUI=zo,J.useFilePreview=BC,J.useHasChatSession=fx,J.useParsedMessageContent=UC,J.useShallowStableValue=Mc,J.useStream=Ec,J.useStreamingMarkdownBuffer=cd,J.useThreadHistoryState=bc,J.useThreadManagerViewState=Ip,J.useThreadState=Kr,J.useThreadStateUpdater=jc,J.useThreads=Ur,J.useThreadsState=rc,J.useToolPayload=Uu,Object.defineProperty(J,Symbol.toStringTag,{value:"Module"})});
132
132
  //# sourceMappingURL=index.umd.js.map