teodor-new-chat-ui 4.3.708 → 4.3.710

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,kt){typeof exports=="object"&&typeof module<"u"?kt(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"],kt):(J=typeof globalThis<"u"?globalThis:J||self,kt(J.NewChatUI={},J.clsx,J.tailwindMerge,J.React,J.reactSlot,J.classVarianceAuthority,J.ReactDOM,J.LucideReact))})(this,function(J,kt,Bn,v,cr,Ap,Hs,xe){"use strict";var DC=Object.defineProperty;var LC=(J,kt,Bn)=>kt in J?DC(J,kt,{enumerable:!0,configurable:!0,writable:!0,value:Bn}):J[kt]=Bn;var ol=(J,kt,Bn)=>LC(J,typeof kt!="symbol"?kt+"":kt,Bn);function sl(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 b=sl(v),il=sl(Hs);function Np(...e){return Bn.twMerge(kt.clsx(e))}function al(e,t){return function(){return e.apply(t,arguments)}}const{toString:_p}=Object.prototype,{getPrototypeOf:Ws}=Object,{iterator:So,toStringTag:ll}=Symbol,Co=(e=>t=>{const n=_p.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),Ht=e=>(e=e.toLowerCase(),t=>Co(t)===e),To=e=>t=>typeof t===e,{isArray:ur}=Array,dr=To("undefined");function Or(e){return e!==null&&!dr(e)&&e.constructor!==null&&!dr(e.constructor)&&Et(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const cl=Ht("ArrayBuffer");function jp(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&cl(e.buffer),t}const Pp=To("string"),Et=To("function"),ul=To("number"),Dr=e=>e!==null&&typeof e=="object",Rp=e=>e===!0||e===!1,ko=e=>{if(Co(e)!=="object")return!1;const t=Ws(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(ll in e)&&!(So in e)},Mp=e=>{if(!Dr(e)||Or(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Op=Ht("Date"),Dp=Ht("File"),Lp=Ht("Blob"),$p=Ht("FileList"),Fp=e=>Dr(e)&&Et(e.pipe),zp=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||Et(e.append)&&((t=Co(e))==="formdata"||t==="object"&&Et(e.toString)&&e.toString()==="[object FormData]"))},Bp=Ht("URLSearchParams"),[Up,Hp,Wp,Vp]=["ReadableStream","Request","Response","Headers"].map(Ht),Kp=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(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 dl(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 Un=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,fl=e=>!dr(e)&&e!==Un;function Vs(){const{caseless:e,skipUndefined:t}=fl(this)&&this||{},n={},r=(o,s)=>{const i=e&&dl(n,s)||s;ko(n[i])&&ko(o)?n[i]=Vs(n[i],o):ko(o)?n[i]=Vs({},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 qp=(e,t,n,{allOwnKeys:r}={})=>(Lr(t,(o,s)=>{n&&Et(o)?e[s]=al(o,n):e[s]=o},{allOwnKeys:r}),e),Gp=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),Yp=(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)},Xp=(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&&Ws(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},Jp=(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},Zp=e=>{if(!e)return null;if(ur(e))return e;let t=e.length;if(!ul(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},Qp=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Ws(Uint8Array)),em=(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])}},tm=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},nm=Ht("HTMLFormElement"),rm=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),hl=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),om=Ht("RegExp"),pl=(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)},sm=e=>{pl(e,(t,n)=>{if(Et(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(Et(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+"'")})}})},im=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return ur(e)?r(e):r(String(e).split(t)),n},am=()=>{},lm=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function cm(e){return!!(e&&Et(e.append)&&e[ll]==="FormData"&&e[So])}const um=e=>{const t=new Array(10),n=(r,o)=>{if(Dr(r)){if(t.indexOf(r)>=0)return;if(Or(r))return r;if(!("toJSON"in r)){t[o]=r;const s=ur(r)?[]:{};return Lr(r,(i,a)=>{const c=n(i,o+1);!dr(c)&&(s[a]=c)}),t[o]=void 0,s}}return r};return n(e,0)},dm=Ht("AsyncFunction"),fm=e=>e&&(Dr(e)||Et(e))&&Et(e.then)&&Et(e.catch),ml=((e,t)=>e?setImmediate:t?((n,r)=>(Un.addEventListener("message",({source:o,data:s})=>{o===Un&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),Un.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",Et(Un.postMessage)),hm=typeof queueMicrotask<"u"?queueMicrotask.bind(Un):typeof process<"u"&&process.nextTick||ml,z={isArray:ur,isArrayBuffer:cl,isBuffer:Or,isFormData:zp,isArrayBufferView:jp,isString:Pp,isNumber:ul,isBoolean:Rp,isObject:Dr,isPlainObject:ko,isEmptyObject:Mp,isReadableStream:Up,isRequest:Hp,isResponse:Wp,isHeaders:Vp,isUndefined:dr,isDate:Op,isFile:Dp,isBlob:Lp,isRegExp:om,isFunction:Et,isStream:Fp,isURLSearchParams:Bp,isTypedArray:Qp,isFileList:$p,forEach:Lr,merge:Vs,extend:qp,trim:Kp,stripBOM:Gp,inherits:Yp,toFlatObject:Xp,kindOf:Co,kindOfTest:Ht,endsWith:Jp,toArray:Zp,forEachEntry:em,matchAll:tm,isHTMLForm:nm,hasOwnProperty:hl,hasOwnProp:hl,reduceDescriptors:pl,freezeMethods:sm,toObjectSet:im,toCamelCase:rm,noop:am,toFiniteNumber:lm,findKey:dl,global:Un,isContextDefined:fl,isSpecCompliantForm:cm,toJSONObject:um,isAsyncFn:dm,isThenable:fm,setImmediate:ml,asap:hm,isIterable:e=>e!=null&&Et(e[So])};function Ce(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)}z.inherits(Ce,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:z.toJSONObject(this.config),code:this.code,status:this.status}}});const gl=Ce.prototype,xl={};["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=>{xl[e]={value:e}}),Object.defineProperties(Ce,xl),Object.defineProperty(gl,"isAxiosError",{value:!0}),Ce.from=(e,t,n,r,o,s)=>{const i=Object.create(gl);z.toFlatObject(e,i,function(u){return u!==Error.prototype},l=>l!=="isAxiosError");const a=e&&e.message?e.message:"Error",c=t==null&&e?e.code:t;return Ce.call(i,a,c,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 pm=null;function Ks(e){return z.isPlainObject(e)||z.isArray(e)}function bl(e){return z.endsWith(e,"[]")?e.slice(0,-2):e}function yl(e,t,n){return e?e.concat(t).map(function(o,s){return o=bl(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function mm(e){return z.isArray(e)&&!e.some(Ks)}const gm=z.toFlatObject(z,{},null,function(t){return/^is[A-Z]/.test(t)});function Eo(e,t,n){if(!z.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=z.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(g,x){return!z.isUndefined(x[g])});const r=n.metaTokens,o=n.visitor||u,s=n.dots,i=n.indexes,c=(n.Blob||typeof Blob<"u"&&Blob)&&z.isSpecCompliantForm(t);if(!z.isFunction(o))throw new TypeError("visitor must be a function");function l(m){if(m===null)return"";if(z.isDate(m))return m.toISOString();if(z.isBoolean(m))return m.toString();if(!c&&z.isBlob(m))throw new Ce("Blob is not supported. Use a Buffer instead.");return z.isArrayBuffer(m)||z.isTypedArray(m)?c&&typeof Blob=="function"?new Blob([m]):Buffer.from(m):m}function u(m,g,x){let y=m;if(m&&!x&&typeof m=="object"){if(z.endsWith(g,"{}"))g=r?g:g.slice(0,-2),m=JSON.stringify(m);else if(z.isArray(m)&&mm(m)||(z.isFileList(m)||z.endsWith(g,"[]"))&&(y=z.toArray(m)))return g=bl(g),y.forEach(function(k,I){!(z.isUndefined(k)||k===null)&&t.append(i===!0?yl([g],I,s):i===null?g:g+"[]",l(k))}),!1}return Ks(m)?!0:(t.append(yl(x,g,s),l(m)),!1)}const f=[],h=Object.assign(gm,{defaultVisitor:u,convertValue:l,isVisitable:Ks});function p(m,g){if(!z.isUndefined(m)){if(f.indexOf(m)!==-1)throw Error("Circular reference detected in "+g.join("."));f.push(m),z.forEach(m,function(y,w){(!(z.isUndefined(y)||y===null)&&o.call(t,y,z.isString(w)?w.trim():w,g,h))===!0&&p(y,g?g.concat(w):[w])}),f.pop()}}if(!z.isObject(e))throw new TypeError("data must be an object");return p(e),t}function wl(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function qs(e,t){this._pairs=[],e&&Eo(e,this,t)}const vl=qs.prototype;vl.append=function(t,n){this._pairs.push([t,n])},vl.toString=function(t){const n=t?function(r){return t.call(this,r,wl)}:wl;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function xm(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function Sl(e,t,n){if(!t)return e;const r=n&&n.encode||xm;z.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=z.isURLSearchParams(t)?t.toString():new qs(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class Cl{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){z.forEach(this.handlers,function(r){r!==null&&t(r)})}}const Tl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},bm={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:qs,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},Gs=typeof window<"u"&&typeof document<"u",Ys=typeof navigator=="object"&&navigator||void 0,ym=Gs&&(!Ys||["ReactNative","NativeScript","NS"].indexOf(Ys.product)<0),wm=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",vm=Gs&&window.location.href||"http://localhost",mt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:Gs,hasStandardBrowserEnv:ym,hasStandardBrowserWebWorkerEnv:wm,navigator:Ys,origin:vm},Symbol.toStringTag,{value:"Module"})),...bm};function Sm(e,t){return Eo(e,new mt.classes.URLSearchParams,{visitor:function(n,r,o,s){return mt.isNode&&z.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function Cm(e){return z.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Tm(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 kl(e){function t(n,r,o,s){let i=n[s++];if(i==="__proto__")return!0;const a=Number.isFinite(+i),c=s>=n.length;return i=!i&&z.isArray(o)?o.length:i,c?(z.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!z.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&z.isArray(o[i])&&(o[i]=Tm(o[i])),!a)}if(z.isFormData(e)&&z.isFunction(e.entries)){const n={};return z.forEachEntry(e,(r,o)=>{t(Cm(r),o,n,0)}),n}return null}function km(e,t,n){if(z.isString(e))try{return(t||JSON.parse)(e),z.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const $r={transitional:Tl,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=z.isObject(t);if(s&&z.isHTMLForm(t)&&(t=new FormData(t)),z.isFormData(t))return o?JSON.stringify(kl(t)):t;if(z.isArrayBuffer(t)||z.isBuffer(t)||z.isStream(t)||z.isFile(t)||z.isBlob(t)||z.isReadableStream(t))return t;if(z.isArrayBufferView(t))return t.buffer;if(z.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 Sm(t,this.formSerializer).toString();if((a=z.isFileList(t))||r.indexOf("multipart/form-data")>-1){const c=this.env&&this.env.FormData;return Eo(a?{"files[]":t}:t,c&&new c,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),km(t)):t}],transformResponse:[function(t){const n=this.transitional||$r.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(z.isResponse(t)||z.isReadableStream(t))return t;if(t&&z.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"?Ce.from(a,Ce.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:mt.classes.FormData,Blob:mt.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};z.forEach(["delete","get","head","post","put","patch"],e=>{$r.headers[e]={}});const Em=z.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"]),Im=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]&&Em[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},El=Symbol("internals");function Fr(e){return e&&String(e).trim().toLowerCase()}function Io(e){return e===!1||e==null?e:z.isArray(e)?e.map(Io):String(e)}function Am(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 Nm=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function Xs(e,t,n,r,o){if(z.isFunction(r))return r.call(this,t,n);if(o&&(t=n),!!z.isString(t)){if(z.isString(r))return t.indexOf(r)!==-1;if(z.isRegExp(r))return r.test(t)}}function _m(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function jm(e,t){const n=z.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 It=class{constructor(t){t&&this.set(t)}set(t,n,r){const o=this;function s(a,c,l){const u=Fr(c);if(!u)throw new Error("header name must be a non-empty string");const f=z.findKey(o,u);(!f||o[f]===void 0||l===!0||l===void 0&&o[f]!==!1)&&(o[f||c]=Io(a))}const i=(a,c)=>z.forEach(a,(l,u)=>s(l,u,c));if(z.isPlainObject(t)||t instanceof this.constructor)i(t,n);else if(z.isString(t)&&(t=t.trim())&&!Nm(t))i(Im(t),n);else if(z.isObject(t)&&z.isIterable(t)){let a={},c,l;for(const u of t){if(!z.isArray(u))throw TypeError("Object iterator must return a key-value pair");a[l=u[0]]=(c=a[l])?z.isArray(c)?[...c,u[1]]:[c,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=z.findKey(this,t);if(r){const o=this[r];if(!n)return o;if(n===!0)return Am(o);if(z.isFunction(n))return n.call(this,o,r);if(z.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=z.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||Xs(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=z.findKey(r,i);a&&(!n||Xs(r,r[a],a,n))&&(delete r[a],o=!0)}}return z.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||Xs(this,this[s],s,t,!0))&&(delete this[s],o=!0)}return o}normalize(t){const n=this,r={};return z.forEach(this,(o,s)=>{const i=z.findKey(r,s);if(i){n[i]=Io(o),delete n[s];return}const a=t?_m(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 z.forEach(this,(r,o)=>{r!=null&&r!==!1&&(n[o]=t&&z.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[El]=this[El]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Fr(i);r[a]||(jm(o,i),r[a]=!0)}return z.isArray(t)?t.forEach(s):s(t),this}};It.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),z.reduceDescriptors(It.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),z.freezeMethods(It);function Js(e,t){const n=this||$r,r=t||n,o=It.from(r.headers);let s=r.data;return z.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function Il(e){return!!(e&&e.__CANCEL__)}function fr(e,t,n){Ce.call(this,e??"canceled",Ce.ERR_CANCELED,t,n),this.name="CanceledError"}z.inherits(fr,Ce,{__CANCEL__:!0});function Al(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Ce("Request failed with status code "+n.status,[Ce.ERR_BAD_REQUEST,Ce.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function Pm(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Rm(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(c){const l=Date.now(),u=r[s];i||(i=l),n[o]=c,r[o]=l;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),l-i<t)return;const p=u&&l-u;return p?Math.round(h*1e3/p):void 0}}function Mm(e,t){let n=0,r=1e3/t,o,s;const i=(l,u=Date.now())=>{n=u,o=null,s&&(clearTimeout(s),s=null),e(...l)};return[(...l)=>{const u=Date.now(),f=u-n;f>=r?i(l,u):(o=l,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const Ao=(e,t,n=3)=>{let r=0;const o=Rm(50,250);return Mm(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,c=i-r,l=o(c),u=i<=a;r=i;const f={loaded:i,total:a,progress:a?i/a:void 0,bytes:c,rate:l||void 0,estimated:l&&a&&u?(a-i)/l:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},n)},Nl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},_l=e=>(...t)=>z.asap(()=>e(...t)),Om=mt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,mt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(mt.origin),mt.navigator&&/(msie|trident)/i.test(mt.navigator.userAgent)):()=>!0,Dm=mt.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];z.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),z.isString(r)&&i.push("path="+r),z.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 Lm(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function $m(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function jl(e,t,n){let r=!Lm(t);return e&&(r||n==!1)?$m(e,t):t}const Pl=e=>e instanceof It?{...e}:e;function Hn(e,t){t=t||{};const n={};function r(l,u,f,h){return z.isPlainObject(l)&&z.isPlainObject(u)?z.merge.call({caseless:h},l,u):z.isPlainObject(u)?z.merge({},u):z.isArray(u)?u.slice():u}function o(l,u,f,h){if(z.isUndefined(u)){if(!z.isUndefined(l))return r(void 0,l,f,h)}else return r(l,u,f,h)}function s(l,u){if(!z.isUndefined(u))return r(void 0,u)}function i(l,u){if(z.isUndefined(u)){if(!z.isUndefined(l))return r(void 0,l)}else return r(void 0,u)}function a(l,u,f){if(f in t)return r(l,u);if(f in e)return r(void 0,l)}const c={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:(l,u,f)=>o(Pl(l),Pl(u),f,!0)};return z.forEach(Object.keys({...e,...t}),function(u){const f=c[u]||o,h=f(e[u],t[u],u);z.isUndefined(h)&&f!==a||(n[u]=h)}),n}const Rl=e=>{const t=Hn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=It.from(i),t.url=Sl(jl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),z.isFormData(n)){if(mt.hasStandardBrowserEnv||mt.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(z.isFunction(n.getHeaders)){const c=n.getHeaders(),l=["content-type","content-length"];Object.entries(c).forEach(([u,f])=>{l.includes(u.toLowerCase())&&i.set(u,f)})}}if(mt.hasStandardBrowserEnv&&(r&&z.isFunction(r)&&(r=r(t)),r||r!==!1&&Om(t.url))){const c=o&&s&&Dm.read(s);c&&i.set(o,c)}return t},Fm=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=Rl(e);let s=o.data;const i=It.from(o.headers).normalize();let{responseType:a,onUploadProgress:c,onDownloadProgress:l}=o,u,f,h,p,m;function g(){p&&p(),m&&m(),o.cancelToken&&o.cancelToken.unsubscribe(u),o.signal&&o.signal.removeEventListener("abort",u)}let x=new XMLHttpRequest;x.open(o.method.toUpperCase(),o.url,!0),x.timeout=o.timeout;function y(){if(!x)return;const k=It.from("getAllResponseHeaders"in x&&x.getAllResponseHeaders()),S={data:!a||a==="text"||a==="json"?x.responseText:x.response,status:x.status,statusText:x.statusText,headers:k,config:e,request:x};Al(function(T){n(T),g()},function(T){r(T),g()},S),x=null}"onloadend"in x?x.onloadend=y:x.onreadystatechange=function(){!x||x.readyState!==4||x.status===0&&!(x.responseURL&&x.responseURL.indexOf("file:")===0)||setTimeout(y)},x.onabort=function(){x&&(r(new Ce("Request aborted",Ce.ECONNABORTED,e,x)),x=null)},x.onerror=function(I){const S=I&&I.message?I.message:"Network Error",C=new Ce(S,Ce.ERR_NETWORK,e,x);C.event=I||null,r(C),x=null},x.ontimeout=function(){let I=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const S=o.transitional||Tl;o.timeoutErrorMessage&&(I=o.timeoutErrorMessage),r(new Ce(I,S.clarifyTimeoutError?Ce.ETIMEDOUT:Ce.ECONNABORTED,e,x)),x=null},s===void 0&&i.setContentType(null),"setRequestHeader"in x&&z.forEach(i.toJSON(),function(I,S){x.setRequestHeader(S,I)}),z.isUndefined(o.withCredentials)||(x.withCredentials=!!o.withCredentials),a&&a!=="json"&&(x.responseType=o.responseType),l&&([h,m]=Ao(l,!0),x.addEventListener("progress",h)),c&&x.upload&&([f,p]=Ao(c),x.upload.addEventListener("progress",f),x.upload.addEventListener("loadend",p)),(o.cancelToken||o.signal)&&(u=k=>{x&&(r(!k||k.type?new fr(null,e,x):k),x.abort(),x=null)},o.cancelToken&&o.cancelToken.subscribe(u),o.signal&&(o.signal.aborted?u():o.signal.addEventListener("abort",u)));const w=Pm(o.url);if(w&&mt.protocols.indexOf(w)===-1){r(new Ce("Unsupported protocol "+w+":",Ce.ERR_BAD_REQUEST,e));return}x.send(s||null)})},zm=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,o;const s=function(l){if(!o){o=!0,a();const u=l instanceof Error?l:this.reason;r.abort(u instanceof Ce?u:new fr(u instanceof Error?u.message:u))}};let i=t&&setTimeout(()=>{i=null,s(new Ce(`timeout ${t} of ms exceeded`,Ce.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(l=>{l.unsubscribe?l.unsubscribe(s):l.removeEventListener("abort",s)}),e=null)};e.forEach(l=>l.addEventListener("abort",s));const{signal:c}=r;return c.unsubscribe=()=>z.asap(a),c}},Bm=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},Um=async function*(e,t){for await(const n of Hm(e))yield*Bm(n,t)},Hm=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=Um(e,t);let s=0,i,a=c=>{i||(i=!0,r&&r(c))};return new ReadableStream({async pull(c){try{const{done:l,value:u}=await o.next();if(l){a(),c.close();return}let f=u.byteLength;if(n){let h=s+=f;n(h)}c.enqueue(new Uint8Array(u))}catch(l){throw a(l),l}},cancel(c){return a(c),o.return()}},{highWaterMark:2})},Ol=64*1024,{isFunction:No}=z,Wm=(({Request:e,Response:t})=>({Request:e,Response:t}))(z.global),{ReadableStream:Dl,TextEncoder:Ll}=z.global,$l=(e,...t)=>{try{return!!e(...t)}catch{return!1}},Vm=e=>{e=z.merge.call({skipUndefined:!0},Wm,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(Dl),c=o&&(typeof Ll=="function"?(m=>g=>m.encode(g))(new Ll):async m=>new Uint8Array(await new n(m).arrayBuffer())),l=s&&a&&$l(()=>{let m=!1;const g=new n(mt.origin,{body:new Dl,method:"POST",get duplex(){return m=!0,"half"}}).headers.has("Content-Type");return m&&!g}),u=i&&a&&$l(()=>z.isReadableStream(new r("").body)),f={stream:u&&(m=>m.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(m=>{!f[m]&&(f[m]=(g,x)=>{let y=g&&g[m];if(y)return y.call(g);throw new Ce(`Response type '${m}' is not supported`,Ce.ERR_NOT_SUPPORT,x)})});const h=async m=>{if(m==null)return 0;if(z.isBlob(m))return m.size;if(z.isSpecCompliantForm(m))return(await new n(mt.origin,{method:"POST",body:m}).arrayBuffer()).byteLength;if(z.isArrayBufferView(m)||z.isArrayBuffer(m))return m.byteLength;if(z.isURLSearchParams(m)&&(m=m+""),z.isString(m))return(await c(m)).byteLength},p=async(m,g)=>{const x=z.toFiniteNumber(m.getContentLength());return x??h(g)};return async m=>{let{url:g,method:x,data:y,signal:w,cancelToken:k,timeout:I,onDownloadProgress:S,onUploadProgress:C,responseType:T,headers:A,withCredentials:j="same-origin",fetchOptions:P}=Rl(m),M=t||fetch;T=T?(T+"").toLowerCase():"text";let F=zm([w,k&&k.toAbortSignal()],I),U=null;const L=F&&F.unsubscribe&&(()=>{F.unsubscribe()});let K;try{if(C&&l&&x!=="get"&&x!=="head"&&(K=await p(A,y))!==0){let H=new n(g,{method:"POST",body:y,duplex:"half"}),O;if(z.isFormData(y)&&(O=H.headers.get("content-type"))&&A.setContentType(O),H.body){const[N,$]=Nl(K,Ao(_l(C)));y=Ml(H.body,Ol,N,$)}}z.isString(j)||(j=j?"include":"omit");const q=s&&"credentials"in n.prototype,re={...P,signal:F,method:x.toUpperCase(),headers:A.normalize().toJSON(),body:y,duplex:"half",credentials:q?j:void 0};U=s&&new n(g,re);let W=await(s?M(U,P):M(g,re));const V=u&&(T==="stream"||T==="response");if(u&&(S||V&&L)){const H={};["status","statusText","headers"].forEach(D=>{H[D]=W[D]});const O=z.toFiniteNumber(W.headers.get("content-length")),[N,$]=S&&Nl(O,Ao(_l(S),!0))||[];W=new r(Ml(W.body,Ol,N,()=>{$&&$(),L&&L()}),H)}T=T||"text";let ne=await f[z.findKey(f,T)||"text"](W,m);return!V&&L&&L(),await new Promise((H,O)=>{Al(H,O,{data:ne,headers:It.from(W.headers),status:W.status,statusText:W.statusText,config:m,request:U})})}catch(q){throw L&&L(),q&&q.name==="TypeError"&&/Load failed|fetch/i.test(q.message)?Object.assign(new Ce("Network Error",Ce.ERR_NETWORK,m,U),{cause:q.cause||q}):Ce.from(q,q&&q.code,m,U)}}},Km=new Map,Fl=e=>{let t=e?e.env:{};const{fetch:n,Request:r,Response:o}=t,s=[r,o,n];let i=s.length,a=i,c,l,u=Km;for(;a--;)c=s[a],l=u.get(c),l===void 0&&u.set(c,l=a?new Map:Vm(t)),u=l;return l};Fl();const Zs={http:pm,xhr:Fm,fetch:{get:Fl}};z.forEach(Zs,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const zl=e=>`- ${e}`,qm=e=>z.isFunction(e)||e===null||e===!1,Bl={getAdapter:(e,t)=>{e=z.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,!qm(r)&&(o=Zs[(a=String(r)).toLowerCase()],o===void 0))throw new Ce(`Unknown adapter '${a}'`);if(o&&(z.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([c,l])=>`adapter ${c} `+(l===!1?"is not supported by the environment":"is not available in the build"));let a=n?i.length>1?`since :
1
+ (function(J,kt){typeof exports=="object"&&typeof module<"u"?kt(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"],kt):(J=typeof globalThis<"u"?globalThis:J||self,kt(J.NewChatUI={},J.clsx,J.tailwindMerge,J.React,J.reactSlot,J.classVarianceAuthority,J.ReactDOM,J.LucideReact))})(this,function(J,kt,Bn,v,cr,Ap,Hs,xe){"use strict";var DC=Object.defineProperty;var LC=(J,kt,Bn)=>kt in J?DC(J,kt,{enumerable:!0,configurable:!0,writable:!0,value:Bn}):J[kt]=Bn;var ol=(J,kt,Bn)=>LC(J,typeof kt!="symbol"?kt+"":kt,Bn);function sl(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 b=sl(v),il=sl(Hs);function Np(...e){return Bn.twMerge(kt.clsx(e))}function al(e,t){return function(){return e.apply(t,arguments)}}const{toString:jp}=Object.prototype,{getPrototypeOf:Ws}=Object,{iterator:So,toStringTag:ll}=Symbol,Co=(e=>t=>{const n=jp.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),Ht=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)&&Et(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const cl=Ht("ArrayBuffer");function _p(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&cl(e.buffer),t}const Pp=To("string"),Et=To("function"),ul=To("number"),Dr=e=>e!==null&&typeof e=="object",Rp=e=>e===!0||e===!1,ko=e=>{if(Co(e)!=="object")return!1;const t=Ws(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(ll in e)&&!(So in e)},Op=e=>{if(!Dr(e)||Mr(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Mp=Ht("Date"),Dp=Ht("File"),Lp=Ht("Blob"),$p=Ht("FileList"),Fp=e=>Dr(e)&&Et(e.pipe),zp=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||Et(e.append)&&((t=Co(e))==="formdata"||t==="object"&&Et(e.toString)&&e.toString()==="[object FormData]"))},Bp=Ht("URLSearchParams"),[Up,Hp,Wp,Vp]=["ReadableStream","Request","Response","Headers"].map(Ht),Kp=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 dl(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 Un=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,fl=e=>!dr(e)&&e!==Un;function Vs(){const{caseless:e,skipUndefined:t}=fl(this)&&this||{},n={},r=(o,s)=>{const i=e&&dl(n,s)||s;ko(n[i])&&ko(o)?n[i]=Vs(n[i],o):ko(o)?n[i]=Vs({},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 qp=(e,t,n,{allOwnKeys:r}={})=>(Lr(t,(o,s)=>{n&&Et(o)?e[s]=al(o,n):e[s]=o},{allOwnKeys:r}),e),Gp=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),Yp=(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)},Xp=(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&&Ws(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},Jp=(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},Zp=e=>{if(!e)return null;if(ur(e))return e;let t=e.length;if(!ul(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},Qp=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&Ws(Uint8Array)),em=(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])}},tm=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},nm=Ht("HTMLFormElement"),rm=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),hl=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),om=Ht("RegExp"),pl=(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)},sm=e=>{pl(e,(t,n)=>{if(Et(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(Et(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+"'")})}})},im=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return ur(e)?r(e):r(String(e).split(t)),n},am=()=>{},lm=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function cm(e){return!!(e&&Et(e.append)&&e[ll]==="FormData"&&e[So])}const um=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 c=n(i,o+1);!dr(c)&&(s[a]=c)}),t[o]=void 0,s}}return r};return n(e,0)},dm=Ht("AsyncFunction"),fm=e=>e&&(Dr(e)||Et(e))&&Et(e.then)&&Et(e.catch),ml=((e,t)=>e?setImmediate:t?((n,r)=>(Un.addEventListener("message",({source:o,data:s})=>{o===Un&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),Un.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",Et(Un.postMessage)),hm=typeof queueMicrotask<"u"?queueMicrotask.bind(Un):typeof process<"u"&&process.nextTick||ml,z={isArray:ur,isArrayBuffer:cl,isBuffer:Mr,isFormData:zp,isArrayBufferView:_p,isString:Pp,isNumber:ul,isBoolean:Rp,isObject:Dr,isPlainObject:ko,isEmptyObject:Op,isReadableStream:Up,isRequest:Hp,isResponse:Wp,isHeaders:Vp,isUndefined:dr,isDate:Mp,isFile:Dp,isBlob:Lp,isRegExp:om,isFunction:Et,isStream:Fp,isURLSearchParams:Bp,isTypedArray:Qp,isFileList:$p,forEach:Lr,merge:Vs,extend:qp,trim:Kp,stripBOM:Gp,inherits:Yp,toFlatObject:Xp,kindOf:Co,kindOfTest:Ht,endsWith:Jp,toArray:Zp,forEachEntry:em,matchAll:tm,isHTMLForm:nm,hasOwnProperty:hl,hasOwnProp:hl,reduceDescriptors:pl,freezeMethods:sm,toObjectSet:im,toCamelCase:rm,noop:am,toFiniteNumber:lm,findKey:dl,global:Un,isContextDefined:fl,isSpecCompliantForm:cm,toJSONObject:um,isAsyncFn:dm,isThenable:fm,setImmediate:ml,asap:hm,isIterable:e=>e!=null&&Et(e[So])};function Ce(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)}z.inherits(Ce,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:z.toJSONObject(this.config),code:this.code,status:this.status}}});const gl=Ce.prototype,xl={};["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=>{xl[e]={value:e}}),Object.defineProperties(Ce,xl),Object.defineProperty(gl,"isAxiosError",{value:!0}),Ce.from=(e,t,n,r,o,s)=>{const i=Object.create(gl);z.toFlatObject(e,i,function(u){return u!==Error.prototype},l=>l!=="isAxiosError");const a=e&&e.message?e.message:"Error",c=t==null&&e?e.code:t;return Ce.call(i,a,c,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 pm=null;function Ks(e){return z.isPlainObject(e)||z.isArray(e)}function bl(e){return z.endsWith(e,"[]")?e.slice(0,-2):e}function yl(e,t,n){return e?e.concat(t).map(function(o,s){return o=bl(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function mm(e){return z.isArray(e)&&!e.some(Ks)}const gm=z.toFlatObject(z,{},null,function(t){return/^is[A-Z]/.test(t)});function Eo(e,t,n){if(!z.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=z.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(g,x){return!z.isUndefined(x[g])});const r=n.metaTokens,o=n.visitor||u,s=n.dots,i=n.indexes,c=(n.Blob||typeof Blob<"u"&&Blob)&&z.isSpecCompliantForm(t);if(!z.isFunction(o))throw new TypeError("visitor must be a function");function l(m){if(m===null)return"";if(z.isDate(m))return m.toISOString();if(z.isBoolean(m))return m.toString();if(!c&&z.isBlob(m))throw new Ce("Blob is not supported. Use a Buffer instead.");return z.isArrayBuffer(m)||z.isTypedArray(m)?c&&typeof Blob=="function"?new Blob([m]):Buffer.from(m):m}function u(m,g,x){let y=m;if(m&&!x&&typeof m=="object"){if(z.endsWith(g,"{}"))g=r?g:g.slice(0,-2),m=JSON.stringify(m);else if(z.isArray(m)&&mm(m)||(z.isFileList(m)||z.endsWith(g,"[]"))&&(y=z.toArray(m)))return g=bl(g),y.forEach(function(k,I){!(z.isUndefined(k)||k===null)&&t.append(i===!0?yl([g],I,s):i===null?g:g+"[]",l(k))}),!1}return Ks(m)?!0:(t.append(yl(x,g,s),l(m)),!1)}const f=[],h=Object.assign(gm,{defaultVisitor:u,convertValue:l,isVisitable:Ks});function p(m,g){if(!z.isUndefined(m)){if(f.indexOf(m)!==-1)throw Error("Circular reference detected in "+g.join("."));f.push(m),z.forEach(m,function(y,w){(!(z.isUndefined(y)||y===null)&&o.call(t,y,z.isString(w)?w.trim():w,g,h))===!0&&p(y,g?g.concat(w):[w])}),f.pop()}}if(!z.isObject(e))throw new TypeError("data must be an object");return p(e),t}function wl(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function qs(e,t){this._pairs=[],e&&Eo(e,this,t)}const vl=qs.prototype;vl.append=function(t,n){this._pairs.push([t,n])},vl.toString=function(t){const n=t?function(r){return t.call(this,r,wl)}:wl;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function xm(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function Sl(e,t,n){if(!t)return e;const r=n&&n.encode||xm;z.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=z.isURLSearchParams(t)?t.toString():new qs(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class Cl{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){z.forEach(this.handlers,function(r){r!==null&&t(r)})}}const Tl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},bm={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:qs,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},Gs=typeof window<"u"&&typeof document<"u",Ys=typeof navigator=="object"&&navigator||void 0,ym=Gs&&(!Ys||["ReactNative","NativeScript","NS"].indexOf(Ys.product)<0),wm=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",vm=Gs&&window.location.href||"http://localhost",gt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:Gs,hasStandardBrowserEnv:ym,hasStandardBrowserWebWorkerEnv:wm,navigator:Ys,origin:vm},Symbol.toStringTag,{value:"Module"})),...bm};function Sm(e,t){return Eo(e,new gt.classes.URLSearchParams,{visitor:function(n,r,o,s){return gt.isNode&&z.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function Cm(e){return z.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Tm(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 kl(e){function t(n,r,o,s){let i=n[s++];if(i==="__proto__")return!0;const a=Number.isFinite(+i),c=s>=n.length;return i=!i&&z.isArray(o)?o.length:i,c?(z.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!z.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&z.isArray(o[i])&&(o[i]=Tm(o[i])),!a)}if(z.isFormData(e)&&z.isFunction(e.entries)){const n={};return z.forEachEntry(e,(r,o)=>{t(Cm(r),o,n,0)}),n}return null}function km(e,t,n){if(z.isString(e))try{return(t||JSON.parse)(e),z.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const $r={transitional:Tl,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=z.isObject(t);if(s&&z.isHTMLForm(t)&&(t=new FormData(t)),z.isFormData(t))return o?JSON.stringify(kl(t)):t;if(z.isArrayBuffer(t)||z.isBuffer(t)||z.isStream(t)||z.isFile(t)||z.isBlob(t)||z.isReadableStream(t))return t;if(z.isArrayBufferView(t))return t.buffer;if(z.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 Sm(t,this.formSerializer).toString();if((a=z.isFileList(t))||r.indexOf("multipart/form-data")>-1){const c=this.env&&this.env.FormData;return Eo(a?{"files[]":t}:t,c&&new c,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),km(t)):t}],transformResponse:[function(t){const n=this.transitional||$r.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(z.isResponse(t)||z.isReadableStream(t))return t;if(t&&z.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"?Ce.from(a,Ce.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:gt.classes.FormData,Blob:gt.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};z.forEach(["delete","get","head","post","put","patch"],e=>{$r.headers[e]={}});const Em=z.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"]),Im=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]&&Em[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},El=Symbol("internals");function Fr(e){return e&&String(e).trim().toLowerCase()}function Io(e){return e===!1||e==null?e:z.isArray(e)?e.map(Io):String(e)}function Am(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 Nm=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function Xs(e,t,n,r,o){if(z.isFunction(r))return r.call(this,t,n);if(o&&(t=n),!!z.isString(t)){if(z.isString(r))return t.indexOf(r)!==-1;if(z.isRegExp(r))return r.test(t)}}function jm(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function _m(e,t){const n=z.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 It=class{constructor(t){t&&this.set(t)}set(t,n,r){const o=this;function s(a,c,l){const u=Fr(c);if(!u)throw new Error("header name must be a non-empty string");const f=z.findKey(o,u);(!f||o[f]===void 0||l===!0||l===void 0&&o[f]!==!1)&&(o[f||c]=Io(a))}const i=(a,c)=>z.forEach(a,(l,u)=>s(l,u,c));if(z.isPlainObject(t)||t instanceof this.constructor)i(t,n);else if(z.isString(t)&&(t=t.trim())&&!Nm(t))i(Im(t),n);else if(z.isObject(t)&&z.isIterable(t)){let a={},c,l;for(const u of t){if(!z.isArray(u))throw TypeError("Object iterator must return a key-value pair");a[l=u[0]]=(c=a[l])?z.isArray(c)?[...c,u[1]]:[c,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=z.findKey(this,t);if(r){const o=this[r];if(!n)return o;if(n===!0)return Am(o);if(z.isFunction(n))return n.call(this,o,r);if(z.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=z.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||Xs(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=z.findKey(r,i);a&&(!n||Xs(r,r[a],a,n))&&(delete r[a],o=!0)}}return z.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||Xs(this,this[s],s,t,!0))&&(delete this[s],o=!0)}return o}normalize(t){const n=this,r={};return z.forEach(this,(o,s)=>{const i=z.findKey(r,s);if(i){n[i]=Io(o),delete n[s];return}const a=t?jm(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 z.forEach(this,(r,o)=>{r!=null&&r!==!1&&(n[o]=t&&z.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[El]=this[El]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Fr(i);r[a]||(_m(o,i),r[a]=!0)}return z.isArray(t)?t.forEach(s):s(t),this}};It.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),z.reduceDescriptors(It.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),z.freezeMethods(It);function Js(e,t){const n=this||$r,r=t||n,o=It.from(r.headers);let s=r.data;return z.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function Il(e){return!!(e&&e.__CANCEL__)}function fr(e,t,n){Ce.call(this,e??"canceled",Ce.ERR_CANCELED,t,n),this.name="CanceledError"}z.inherits(fr,Ce,{__CANCEL__:!0});function Al(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Ce("Request failed with status code "+n.status,[Ce.ERR_BAD_REQUEST,Ce.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function Pm(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Rm(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(c){const l=Date.now(),u=r[s];i||(i=l),n[o]=c,r[o]=l;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),l-i<t)return;const p=u&&l-u;return p?Math.round(h*1e3/p):void 0}}function Om(e,t){let n=0,r=1e3/t,o,s;const i=(l,u=Date.now())=>{n=u,o=null,s&&(clearTimeout(s),s=null),e(...l)};return[(...l)=>{const u=Date.now(),f=u-n;f>=r?i(l,u):(o=l,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const Ao=(e,t,n=3)=>{let r=0;const o=Rm(50,250);return Om(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,c=i-r,l=o(c),u=i<=a;r=i;const f={loaded:i,total:a,progress:a?i/a:void 0,bytes:c,rate:l||void 0,estimated:l&&a&&u?(a-i)/l:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},n)},Nl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},jl=e=>(...t)=>z.asap(()=>e(...t)),Mm=gt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,gt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(gt.origin),gt.navigator&&/(msie|trident)/i.test(gt.navigator.userAgent)):()=>!0,Dm=gt.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];z.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),z.isString(r)&&i.push("path="+r),z.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 Lm(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function $m(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function _l(e,t,n){let r=!Lm(t);return e&&(r||n==!1)?$m(e,t):t}const Pl=e=>e instanceof It?{...e}:e;function Hn(e,t){t=t||{};const n={};function r(l,u,f,h){return z.isPlainObject(l)&&z.isPlainObject(u)?z.merge.call({caseless:h},l,u):z.isPlainObject(u)?z.merge({},u):z.isArray(u)?u.slice():u}function o(l,u,f,h){if(z.isUndefined(u)){if(!z.isUndefined(l))return r(void 0,l,f,h)}else return r(l,u,f,h)}function s(l,u){if(!z.isUndefined(u))return r(void 0,u)}function i(l,u){if(z.isUndefined(u)){if(!z.isUndefined(l))return r(void 0,l)}else return r(void 0,u)}function a(l,u,f){if(f in t)return r(l,u);if(f in e)return r(void 0,l)}const c={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:(l,u,f)=>o(Pl(l),Pl(u),f,!0)};return z.forEach(Object.keys({...e,...t}),function(u){const f=c[u]||o,h=f(e[u],t[u],u);z.isUndefined(h)&&f!==a||(n[u]=h)}),n}const Rl=e=>{const t=Hn({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=It.from(i),t.url=Sl(_l(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),z.isFormData(n)){if(gt.hasStandardBrowserEnv||gt.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(z.isFunction(n.getHeaders)){const c=n.getHeaders(),l=["content-type","content-length"];Object.entries(c).forEach(([u,f])=>{l.includes(u.toLowerCase())&&i.set(u,f)})}}if(gt.hasStandardBrowserEnv&&(r&&z.isFunction(r)&&(r=r(t)),r||r!==!1&&Mm(t.url))){const c=o&&s&&Dm.read(s);c&&i.set(o,c)}return t},Fm=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=Rl(e);let s=o.data;const i=It.from(o.headers).normalize();let{responseType:a,onUploadProgress:c,onDownloadProgress:l}=o,u,f,h,p,m;function g(){p&&p(),m&&m(),o.cancelToken&&o.cancelToken.unsubscribe(u),o.signal&&o.signal.removeEventListener("abort",u)}let x=new XMLHttpRequest;x.open(o.method.toUpperCase(),o.url,!0),x.timeout=o.timeout;function y(){if(!x)return;const k=It.from("getAllResponseHeaders"in x&&x.getAllResponseHeaders()),S={data:!a||a==="text"||a==="json"?x.responseText:x.response,status:x.status,statusText:x.statusText,headers:k,config:e,request:x};Al(function(T){n(T),g()},function(T){r(T),g()},S),x=null}"onloadend"in x?x.onloadend=y:x.onreadystatechange=function(){!x||x.readyState!==4||x.status===0&&!(x.responseURL&&x.responseURL.indexOf("file:")===0)||setTimeout(y)},x.onabort=function(){x&&(r(new Ce("Request aborted",Ce.ECONNABORTED,e,x)),x=null)},x.onerror=function(I){const S=I&&I.message?I.message:"Network Error",C=new Ce(S,Ce.ERR_NETWORK,e,x);C.event=I||null,r(C),x=null},x.ontimeout=function(){let I=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const S=o.transitional||Tl;o.timeoutErrorMessage&&(I=o.timeoutErrorMessage),r(new Ce(I,S.clarifyTimeoutError?Ce.ETIMEDOUT:Ce.ECONNABORTED,e,x)),x=null},s===void 0&&i.setContentType(null),"setRequestHeader"in x&&z.forEach(i.toJSON(),function(I,S){x.setRequestHeader(S,I)}),z.isUndefined(o.withCredentials)||(x.withCredentials=!!o.withCredentials),a&&a!=="json"&&(x.responseType=o.responseType),l&&([h,m]=Ao(l,!0),x.addEventListener("progress",h)),c&&x.upload&&([f,p]=Ao(c),x.upload.addEventListener("progress",f),x.upload.addEventListener("loadend",p)),(o.cancelToken||o.signal)&&(u=k=>{x&&(r(!k||k.type?new fr(null,e,x):k),x.abort(),x=null)},o.cancelToken&&o.cancelToken.subscribe(u),o.signal&&(o.signal.aborted?u():o.signal.addEventListener("abort",u)));const w=Pm(o.url);if(w&&gt.protocols.indexOf(w)===-1){r(new Ce("Unsupported protocol "+w+":",Ce.ERR_BAD_REQUEST,e));return}x.send(s||null)})},zm=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,o;const s=function(l){if(!o){o=!0,a();const u=l instanceof Error?l:this.reason;r.abort(u instanceof Ce?u:new fr(u instanceof Error?u.message:u))}};let i=t&&setTimeout(()=>{i=null,s(new Ce(`timeout ${t} of ms exceeded`,Ce.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(l=>{l.unsubscribe?l.unsubscribe(s):l.removeEventListener("abort",s)}),e=null)};e.forEach(l=>l.addEventListener("abort",s));const{signal:c}=r;return c.unsubscribe=()=>z.asap(a),c}},Bm=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},Um=async function*(e,t){for await(const n of Hm(e))yield*Bm(n,t)},Hm=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()}},Ol=(e,t,n,r)=>{const o=Um(e,t);let s=0,i,a=c=>{i||(i=!0,r&&r(c))};return new ReadableStream({async pull(c){try{const{done:l,value:u}=await o.next();if(l){a(),c.close();return}let f=u.byteLength;if(n){let h=s+=f;n(h)}c.enqueue(new Uint8Array(u))}catch(l){throw a(l),l}},cancel(c){return a(c),o.return()}},{highWaterMark:2})},Ml=64*1024,{isFunction:No}=z,Wm=(({Request:e,Response:t})=>({Request:e,Response:t}))(z.global),{ReadableStream:Dl,TextEncoder:Ll}=z.global,$l=(e,...t)=>{try{return!!e(...t)}catch{return!1}},Vm=e=>{e=z.merge.call({skipUndefined:!0},Wm,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(Dl),c=o&&(typeof Ll=="function"?(m=>g=>m.encode(g))(new Ll):async m=>new Uint8Array(await new n(m).arrayBuffer())),l=s&&a&&$l(()=>{let m=!1;const g=new n(gt.origin,{body:new Dl,method:"POST",get duplex(){return m=!0,"half"}}).headers.has("Content-Type");return m&&!g}),u=i&&a&&$l(()=>z.isReadableStream(new r("").body)),f={stream:u&&(m=>m.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(m=>{!f[m]&&(f[m]=(g,x)=>{let y=g&&g[m];if(y)return y.call(g);throw new Ce(`Response type '${m}' is not supported`,Ce.ERR_NOT_SUPPORT,x)})});const h=async m=>{if(m==null)return 0;if(z.isBlob(m))return m.size;if(z.isSpecCompliantForm(m))return(await new n(gt.origin,{method:"POST",body:m}).arrayBuffer()).byteLength;if(z.isArrayBufferView(m)||z.isArrayBuffer(m))return m.byteLength;if(z.isURLSearchParams(m)&&(m=m+""),z.isString(m))return(await c(m)).byteLength},p=async(m,g)=>{const x=z.toFiniteNumber(m.getContentLength());return x??h(g)};return async m=>{let{url:g,method:x,data:y,signal:w,cancelToken:k,timeout:I,onDownloadProgress:S,onUploadProgress:C,responseType:T,headers:A,withCredentials:j="same-origin",fetchOptions:_}=Rl(m),L=t||fetch;T=T?(T+"").toLowerCase():"text";let F=zm([w,k&&k.toAbortSignal()],I),B=null;const O=F&&F.unsubscribe&&(()=>{F.unsubscribe()});let G;try{if(C&&l&&x!=="get"&&x!=="head"&&(G=await p(A,y))!==0){let K=new n(g,{method:"POST",body:y,duplex:"half"}),M;if(z.isFormData(y)&&(M=K.headers.get("content-type"))&&A.setContentType(M),K.body){const[N,$]=Nl(G,Ao(jl(C)));y=Ol(K.body,Ml,N,$)}}z.isString(j)||(j=j?"include":"omit");const Y=s&&"credentials"in n.prototype,re={..._,signal:F,method:x.toUpperCase(),headers:A.normalize().toJSON(),body:y,duplex:"half",credentials:Y?j:void 0};B=s&&new n(g,re);let H=await(s?L(B,_):L(g,re));const W=u&&(T==="stream"||T==="response");if(u&&(S||W&&O)){const K={};["status","statusText","headers"].forEach(D=>{K[D]=H[D]});const M=z.toFiniteNumber(H.headers.get("content-length")),[N,$]=S&&Nl(M,Ao(jl(S),!0))||[];H=new r(Ol(H.body,Ml,N,()=>{$&&$(),O&&O()}),K)}T=T||"text";let ne=await f[z.findKey(f,T)||"text"](H,m);return!W&&O&&O(),await new Promise((K,M)=>{Al(K,M,{data:ne,headers:It.from(H.headers),status:H.status,statusText:H.statusText,config:m,request:B})})}catch(Y){throw O&&O(),Y&&Y.name==="TypeError"&&/Load failed|fetch/i.test(Y.message)?Object.assign(new Ce("Network Error",Ce.ERR_NETWORK,m,B),{cause:Y.cause||Y}):Ce.from(Y,Y&&Y.code,m,B)}}},Km=new Map,Fl=e=>{let t=e?e.env:{};const{fetch:n,Request:r,Response:o}=t,s=[r,o,n];let i=s.length,a=i,c,l,u=Km;for(;a--;)c=s[a],l=u.get(c),l===void 0&&u.set(c,l=a?new Map:Vm(t)),u=l;return l};Fl();const Zs={http:pm,xhr:Fm,fetch:{get:Fl}};z.forEach(Zs,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const zl=e=>`- ${e}`,qm=e=>z.isFunction(e)||e===null||e===!1,Bl={getAdapter:(e,t)=>{e=z.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,!qm(r)&&(o=Zs[(a=String(r)).toLowerCase()],o===void 0))throw new Ce(`Unknown adapter '${a}'`);if(o&&(z.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([c,l])=>`adapter ${c} `+(l===!1?"is not supported by the environment":"is not available in the build"));let a=n?i.length>1?`since :
4
4
  `+i.map(zl).join(`
5
- `):" "+zl(i[0]):"as no adapter specified";throw new Ce("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:Zs};function Qs(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new fr(null,e)}function Ul(e){return Qs(e),e.headers=It.from(e.headers),e.data=Js.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),Bl.getAdapter(e.adapter||$r.adapter,e)(e).then(function(r){return Qs(e),r.data=Js.call(e,e.transformResponse,r),r.headers=It.from(r.headers),r},function(r){return Il(r)||(Qs(e),r&&r.response&&(r.response.data=Js.call(e,e.transformResponse,r.response),r.response.headers=It.from(r.response.headers))),Promise.reject(r)})}const Hl="1.12.2",_o={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{_o[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const Wl={};_o.transitional=function(t,n,r){function o(s,i){return"[Axios v"+Hl+"] Transitional option '"+s+"'"+i+(r?". "+r:"")}return(s,i,a)=>{if(t===!1)throw new Ce(o(i," has been removed"+(n?" in "+n:"")),Ce.ERR_DEPRECATED);return n&&!Wl[i]&&(Wl[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}},_o.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function Gm(e,t,n){if(typeof e!="object")throw new Ce("options must be an object",Ce.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],c=a===void 0||i(a,s,e);if(c!==!0)throw new Ce("option "+s+" must be "+c,Ce.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new Ce("Unknown option "+s,Ce.ERR_BAD_OPTION)}}const jo={assertOptions:Gm,validators:_o},Jt=jo.validators;let Wn=class{constructor(t){this.defaults=t||{},this.interceptors={request:new Cl,response:new Cl}}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=Hn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&jo.assertOptions(r,{silentJSONParsing:Jt.transitional(Jt.boolean),forcedJSONParsing:Jt.transitional(Jt.boolean),clarifyTimeoutError:Jt.transitional(Jt.boolean)},!1),o!=null&&(z.isFunction(o)?n.paramsSerializer={serialize:o}:jo.assertOptions(o,{encode:Jt.function,serialize:Jt.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),jo.assertOptions(n,{baseUrl:Jt.spelling("baseURL"),withXsrfToken:Jt.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&z.merge(s.common,s[n.method]);s&&z.forEach(["delete","get","head","post","put","patch","common"],m=>{delete s[m]}),n.headers=It.concat(i,s);const a=[];let c=!0;this.interceptors.request.forEach(function(g){typeof g.runWhen=="function"&&g.runWhen(n)===!1||(c=c&&g.synchronous,a.unshift(g.fulfilled,g.rejected))});const l=[];this.interceptors.response.forEach(function(g){l.push(g.fulfilled,g.rejected)});let u,f=0,h;if(!c){const m=[Ul.bind(this),void 0];for(m.unshift(...a),m.push(...l),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++],g=a[f++];try{p=m(p)}catch(x){g.call(this,x);break}}try{u=Ul.call(this,p)}catch(m){return Promise.reject(m)}for(f=0,h=l.length;f<h;)u=u.then(l[f++],l[f++]);return u}getUri(t){t=Hn(this.defaults,t);const n=jl(t.baseURL,t.url,t.allowAbsoluteUrls);return Sl(n,t.params,t.paramsSerializer)}};z.forEach(["delete","get","head","options"],function(t){Wn.prototype[t]=function(n,r){return this.request(Hn(r||{},{method:t,url:n,data:(r||{}).data}))}}),z.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(Hn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Wn.prototype[t]=n(),Wn.prototype[t+"Form"]=n(!0)});let Ym=class Ip{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 Ip(function(o){t=o}),cancel:t}}};function Xm(e){return function(n){return e.apply(null,n)}}function Jm(e){return z.isObject(e)&&e.isAxiosError===!0}const ei={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(ei).forEach(([e,t])=>{ei[t]=e});function Vl(e){const t=new Wn(e),n=al(Wn.prototype.request,t);return z.extend(n,Wn.prototype,t,{allOwnKeys:!0}),z.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Vl(Hn(e,o))},n}const et=Vl($r);et.Axios=Wn,et.CanceledError=fr,et.CancelToken=Ym,et.isCancel=Il,et.VERSION=Hl,et.toFormData=Eo,et.AxiosError=Ce,et.Cancel=et.CanceledError,et.all=function(t){return Promise.all(t)},et.spread=Xm,et.isAxiosError=Jm,et.mergeConfig=Hn,et.AxiosHeaders=It,et.formToJSON=e=>kl(z.isHTMLForm(e)?new FormData(e):e),et.getAdapter=Bl.getAdapter,et.HttpStatusCode=ei,et.default=et;const{Axios:WC,AxiosError:VC,CanceledError:KC,isCancel:Kl,CancelToken:qC,VERSION:GC,all:YC,Cancel:XC,isAxiosError:JC,spread:ZC,toFormData:QC,AxiosHeaders:eT,HttpStatusCode:tT,formToJSON:nT,getAdapter:rT,mergeConfig:oT}=et,vn={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 ti=new Set;function ni(){return Ro}function Sn(e){Ro=e,ti.forEach(t=>t(e))}function ri(e){return ti.add(e),()=>ti.delete(e)}const ql=3e4,Gl=9e4,wt=et.create({timeout:ql,withCredentials:!0});wt.interceptors.request.use(e=>(Ro&&(e.headers.Authorization=`Bearer ${Ro}`),e)),wt.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(vn.authToken,r),Sn(r)),o&&localStorage.setItem(vn.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 At(e,t){return wt.defaults.baseURL?(await wt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function zr(e,t,n){return wt.defaults.baseURL?(await wt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Yl(e,t,n){return wt.defaults.baseURL?(await wt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function oi(e,t){return wt.defaults.baseURL?(await wt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function vt(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class Xl{get baseUrl(){return wt.defaults.baseURL||""}updateConfig(t){if(t.chatBaseUrl)wt.defaults.baseURL=t.chatBaseUrl;else if(t.baseUrl){const n=t.baseUrl.replace(/\/+$/,"");n.endsWith("/chat")?wt.defaults.baseURL=n:wt.defaults.baseURL=`${n}/chat`}t.apiKey!==void 0?Sn(t.apiKey):t.getToken&&Sn(t.getToken())}getAuthToken(){return ni()}setAuthToken(t){Sn(t)}onTokenChange(t){return ri(t)}async listThreads(){const t=await At("/threads"),n=vt(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async listSharedThreads(){const t=await At("/threads/shared"),n=vt(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 vt(o)}async updateThread(t,n){const r=await Yl(`/threads/${t}`,{title:n});return vt(r)}async deleteThread(t){const n=await oi(`/threads/${t}`);return vt(n)}async shareThread(t,n){const r=await zr(`/threads/${t}/share`,{shared_with_user_id:n});return vt(r)}async threadInfo(t){const n=await At(`/threads/${t}/info`);return vt(n)}async listAgents(){const t=await At("/agents"),n=vt(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await At(`/agents/${t}`);return vt(n)}async getAgentSchema(t){const n=await At(`/agents/${t}/schema`);return vt(n)}async getState(t){const n=await At(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return vt(n)}async getStateHistory(t){const n=await At(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:Gl,signal:t.signal});return vt(n)}async cancelRun(t){const n=await zr("/stream/cancel",{threadId:t});return vt(n)}async unshareThread(t,n){const r=await oi(`/threads/${t}/share/${n}`);return vt(r)}}const Cn=new Xl;class Jl{async fetchFileBlob(t,n){return await At(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 At(`/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 At(`/files/${t}`)}async listFiles(t,n=50,r=0){const o={limit:n,offset:r};return t&&(o.thread_id=t),await At("/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 si=new Jl;var ii={exports:{}},Br={};/**
5
+ `):" "+zl(i[0]):"as no adapter specified";throw new Ce("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:Zs};function Qs(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new fr(null,e)}function Ul(e){return Qs(e),e.headers=It.from(e.headers),e.data=Js.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),Bl.getAdapter(e.adapter||$r.adapter,e)(e).then(function(r){return Qs(e),r.data=Js.call(e,e.transformResponse,r),r.headers=It.from(r.headers),r},function(r){return Il(r)||(Qs(e),r&&r.response&&(r.response.data=Js.call(e,e.transformResponse,r.response),r.response.headers=It.from(r.response.headers))),Promise.reject(r)})}const Hl="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 Wl={};jo.transitional=function(t,n,r){function o(s,i){return"[Axios v"+Hl+"] Transitional option '"+s+"'"+i+(r?". "+r:"")}return(s,i,a)=>{if(t===!1)throw new Ce(o(i," has been removed"+(n?" in "+n:"")),Ce.ERR_DEPRECATED);return n&&!Wl[i]&&(Wl[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 Gm(e,t,n){if(typeof e!="object")throw new Ce("options must be an object",Ce.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],c=a===void 0||i(a,s,e);if(c!==!0)throw new Ce("option "+s+" must be "+c,Ce.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new Ce("Unknown option "+s,Ce.ERR_BAD_OPTION)}}const _o={assertOptions:Gm,validators:jo},Jt=_o.validators;let Wn=class{constructor(t){this.defaults=t||{},this.interceptors={request:new Cl,response:new Cl}}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=Hn(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&_o.assertOptions(r,{silentJSONParsing:Jt.transitional(Jt.boolean),forcedJSONParsing:Jt.transitional(Jt.boolean),clarifyTimeoutError:Jt.transitional(Jt.boolean)},!1),o!=null&&(z.isFunction(o)?n.paramsSerializer={serialize:o}:_o.assertOptions(o,{encode:Jt.function,serialize:Jt.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),_o.assertOptions(n,{baseUrl:Jt.spelling("baseURL"),withXsrfToken:Jt.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&z.merge(s.common,s[n.method]);s&&z.forEach(["delete","get","head","post","put","patch","common"],m=>{delete s[m]}),n.headers=It.concat(i,s);const a=[];let c=!0;this.interceptors.request.forEach(function(g){typeof g.runWhen=="function"&&g.runWhen(n)===!1||(c=c&&g.synchronous,a.unshift(g.fulfilled,g.rejected))});const l=[];this.interceptors.response.forEach(function(g){l.push(g.fulfilled,g.rejected)});let u,f=0,h;if(!c){const m=[Ul.bind(this),void 0];for(m.unshift(...a),m.push(...l),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++],g=a[f++];try{p=m(p)}catch(x){g.call(this,x);break}}try{u=Ul.call(this,p)}catch(m){return Promise.reject(m)}for(f=0,h=l.length;f<h;)u=u.then(l[f++],l[f++]);return u}getUri(t){t=Hn(this.defaults,t);const n=_l(t.baseURL,t.url,t.allowAbsoluteUrls);return Sl(n,t.params,t.paramsSerializer)}};z.forEach(["delete","get","head","options"],function(t){Wn.prototype[t]=function(n,r){return this.request(Hn(r||{},{method:t,url:n,data:(r||{}).data}))}}),z.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(Hn(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}Wn.prototype[t]=n(),Wn.prototype[t+"Form"]=n(!0)});let Ym=class Ip{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 Ip(function(o){t=o}),cancel:t}}};function Xm(e){return function(n){return e.apply(null,n)}}function Jm(e){return z.isObject(e)&&e.isAxiosError===!0}const ei={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(ei).forEach(([e,t])=>{ei[t]=e});function Vl(e){const t=new Wn(e),n=al(Wn.prototype.request,t);return z.extend(n,Wn.prototype,t,{allOwnKeys:!0}),z.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return Vl(Hn(e,o))},n}const rt=Vl($r);rt.Axios=Wn,rt.CanceledError=fr,rt.CancelToken=Ym,rt.isCancel=Il,rt.VERSION=Hl,rt.toFormData=Eo,rt.AxiosError=Ce,rt.Cancel=rt.CanceledError,rt.all=function(t){return Promise.all(t)},rt.spread=Xm,rt.isAxiosError=Jm,rt.mergeConfig=Hn,rt.AxiosHeaders=It,rt.formToJSON=e=>kl(z.isHTMLForm(e)?new FormData(e):e),rt.getAdapter=Bl.getAdapter,rt.HttpStatusCode=ei,rt.default=rt;const{Axios:WC,AxiosError:VC,CanceledError:KC,isCancel:Kl,CancelToken:qC,VERSION:GC,all:YC,Cancel:XC,isAxiosError:JC,spread:ZC,toFormData:QC,AxiosHeaders:eT,HttpStatusCode:tT,formToJSON:nT,getAdapter:rT,mergeConfig:oT}=rt,vn={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 ti=new Set;function ni(){return Ro}function Sn(e){Ro=e,ti.forEach(t=>t(e))}function ri(e){return ti.add(e),()=>ti.delete(e)}const ql=3e4,Gl=9e4,vt=rt.create({timeout:ql,withCredentials:!0});vt.interceptors.request.use(e=>(Ro&&(e.headers.Authorization=`Bearer ${Ro}`),e)),vt.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(vn.authToken,r),Sn(r)),o&&localStorage.setItem(vn.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 At(e,t){return vt.defaults.baseURL?(await vt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function zr(e,t,n){return vt.defaults.baseURL?(await vt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function Yl(e,t,n){return vt.defaults.baseURL?(await vt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function oi(e,t){return vt.defaults.baseURL?(await vt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function St(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class Xl{get baseUrl(){return vt.defaults.baseURL||""}updateConfig(t){if(t.chatBaseUrl)vt.defaults.baseURL=t.chatBaseUrl;else if(t.baseUrl){const n=t.baseUrl.replace(/\/+$/,"");n.endsWith("/chat")?vt.defaults.baseURL=n:vt.defaults.baseURL=`${n}/chat`}t.apiKey!==void 0?Sn(t.apiKey):t.getToken&&Sn(t.getToken())}getAuthToken(){return ni()}setAuthToken(t){Sn(t)}onTokenChange(t){return ri(t)}async listThreads(){const t=await At("/threads"),n=St(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async listSharedThreads(){const t=await At("/threads/shared"),n=St(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 St(o)}async updateThread(t,n){const r=await Yl(`/threads/${t}`,{title:n});return St(r)}async deleteThread(t){const n=await oi(`/threads/${t}`);return St(n)}async shareThread(t,n){const r=await zr(`/threads/${t}/share`,{shared_with_user_id:n});return St(r)}async threadInfo(t){const n=await At(`/threads/${t}/info`);return St(n)}async listAgents(){const t=await At("/agents"),n=St(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await At(`/agents/${t}`);return St(n)}async getAgentSchema(t){const n=await At(`/agents/${t}/schema`);return St(n)}async getState(t){const n=await At(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return St(n)}async getStateHistory(t){const n=await At(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs},timeout:Gl,signal:t.signal});return St(n)}async cancelRun(t){const n=await zr("/stream/cancel",{threadId:t});return St(n)}async unshareThread(t,n){const r=await oi(`/threads/${t}/share/${n}`);return St(r)}}const Cn=new Xl;class Jl{async fetchFileBlob(t,n){return await At(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 At(`/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 At(`/files/${t}`)}async listFiles(t,n=50,r=0){const o={limit:n,offset:r};return t&&(o.thread_id=t),await At("/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 si=new Jl;var ii={exports:{}},Br={};/**
7
7
  * @license React
8
8
  * react-jsx-runtime.production.min.js
9
9
  *
@@ -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 Ql;function Qm(){return Ql||(Ql=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"),c=Symbol.for("react.forward_ref"),l=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,g="@@iterator";function x(E){if(E===null||typeof E!="object")return null;var Z=m&&E[m]||E[g];return typeof Z=="function"?Z:null}var y=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function w(E){{for(var Z=arguments.length,oe=new Array(Z>1?Z-1:0),R=1;R<Z;R++)oe[R-1]=arguments[R];k("error",E,oe)}}function k(E,Z,oe){{var R=y.ReactDebugCurrentFrame,Y=R.getStackAddendum();Y!==""&&(Z+="%s",oe=oe.concat([Y]));var se=oe.map(function(ie){return String(ie)});se.unshift("Warning: "+Z),Function.prototype.apply.call(console[E],console,se)}}var I=!1,S=!1,C=!1,T=!1,A=!1,j;j=Symbol.for("react.module.reference");function P(E){return!!(typeof E=="string"||typeof E=="function"||E===r||E===s||A||E===o||E===l||E===u||T||E===p||I||S||C||typeof E=="object"&&E!==null&&(E.$$typeof===h||E.$$typeof===f||E.$$typeof===i||E.$$typeof===a||E.$$typeof===c||E.$$typeof===j||E.getModuleId!==void 0))}function M(E,Z,oe){var R=E.displayName;if(R)return R;var Y=Z.displayName||Z.name||"";return Y!==""?oe+"("+Y+")":oe}function F(E){return E.displayName||"Context"}function U(E){if(E==null)return null;if(typeof E.tag=="number"&&w("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof E=="function")return E.displayName||E.name||null;if(typeof E=="string")return E;switch(E){case r:return"Fragment";case n:return"Portal";case s:return"Profiler";case o:return"StrictMode";case l:return"Suspense";case u:return"SuspenseList"}if(typeof E=="object")switch(E.$$typeof){case a:var Z=E;return F(Z)+".Consumer";case i:var oe=E;return F(oe._context)+".Provider";case c:return M(E,E.render,"ForwardRef");case f:var R=E.displayName||null;return R!==null?R:U(E.type)||"Memo";case h:{var Y=E,se=Y._payload,ie=Y._init;try{return U(ie(se))}catch{return null}}}return null}var L=Object.assign,K=0,q,re,W,V,ne,H,O;function N(){}N.__reactDisabledLog=!0;function $(){{if(K===0){q=console.log,re=console.info,W=console.warn,V=console.error,ne=console.group,H=console.groupCollapsed,O=console.groupEnd;var E={configurable:!0,enumerable:!0,value:N,writable:!0};Object.defineProperties(console,{info:E,log:E,warn:E,error:E,group:E,groupCollapsed:E,groupEnd:E})}K++}}function D(){{if(K--,K===0){var E={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:L({},E,{value:q}),info:L({},E,{value:re}),warn:L({},E,{value:W}),error:L({},E,{value:V}),group:L({},E,{value:ne}),groupCollapsed:L({},E,{value:H}),groupEnd:L({},E,{value:O})})}K<0&&w("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var G=y.ReactCurrentDispatcher,ee;function _(E,Z,oe){{if(ee===void 0)try{throw Error()}catch(Y){var R=Y.stack.trim().match(/\n( *(at )?)/);ee=R&&R[1]||""}return`
23
- `+ee+E}}var B=!1,X;{var le=typeof WeakMap=="function"?WeakMap:Map;X=new le}function me(E,Z){if(!E||B)return"";{var oe=X.get(E);if(oe!==void 0)return oe}var R;B=!0;var Y=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var se;se=G.current,G.current=null,$();try{if(Z){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(Fe){R=Fe}Reflect.construct(E,[],ie)}else{try{ie.call()}catch(Fe){R=Fe}E.call(ie.prototype)}}else{try{throw Error()}catch(Fe){R=Fe}E()}}catch(Fe){if(Fe&&R&&typeof Fe.stack=="string"){for(var ue=Fe.stack.split(`
24
- `),Me=R.stack.split(`
25
- `),Oe=ue.length-1,Ee=Me.length-1;Oe>=1&&Ee>=0&&ue[Oe]!==Me[Ee];)Ee--;for(;Oe>=1&&Ee>=0;Oe--,Ee--)if(ue[Oe]!==Me[Ee]){if(Oe!==1||Ee!==1)do if(Oe--,Ee--,Ee<0||ue[Oe]!==Me[Ee]){var de=`
26
- `+ue[Oe].replace(" at new "," at ");return E.displayName&&de.includes("<anonymous>")&&(de=de.replace("<anonymous>",E.displayName)),typeof E=="function"&&X.set(E,de),de}while(Oe>=1&&Ee>=0);break}}}finally{B=!1,G.current=se,D(),Error.prepareStackTrace=Y}var Re=E?E.displayName||E.name:"",Pe=Re?_(Re):"";return typeof E=="function"&&X.set(E,Pe),Pe}function be(E,Z,oe){return me(E,!1)}function Te(E){var Z=E.prototype;return!!(Z&&Z.isReactComponent)}function Ae(E,Z,oe){if(E==null)return"";if(typeof E=="function")return me(E,Te(E));if(typeof E=="string")return _(E);switch(E){case l:return _("Suspense");case u:return _("SuspenseList")}if(typeof E=="object")switch(E.$$typeof){case c:return be(E.render);case f:return Ae(E.type,Z,oe);case h:{var R=E,Y=R._payload,se=R._init;try{return Ae(se(Y),Z,oe)}catch{}}}return""}var ze=Object.prototype.hasOwnProperty,Ze={},Ye=y.ReactDebugCurrentFrame;function Ve(E){if(E){var Z=E._owner,oe=Ae(E.type,E._source,Z?Z.type:null);Ye.setExtraStackFrame(oe)}else Ye.setExtraStackFrame(null)}function dt(E,Z,oe,R,Y){{var se=Function.call.bind(ze);for(var ie in E)if(se(E,ie)){var ue=void 0;try{if(typeof E[ie]!="function"){var Me=Error((R||"React class")+": "+oe+" type `"+ie+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof E[ie]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Me.name="Invariant Violation",Me}ue=E[ie](Z,ie,R,oe,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(Oe){ue=Oe}ue&&!(ue instanceof Error)&&(Ve(Y),w("%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).",R||"React class",oe,ie,typeof ue),Ve(null)),ue instanceof Error&&!(ue.message in Ze)&&(Ze[ue.message]=!0,Ve(Y),w("Failed %s type: %s",oe,ue.message),Ve(null))}}}var lt=Array.isArray;function nt(E){return lt(E)}function it(E){{var Z=typeof Symbol=="function"&&Symbol.toStringTag,oe=Z&&E[Symbol.toStringTag]||E.constructor.name||"Object";return oe}}function ct(E){try{return Ke(E),!1}catch{return!0}}function Ke(E){return""+E}function $e(E){if(ct(E))return w("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",it(E)),Ke(E)}var je=y.ReactCurrentOwner,rt={key:!0,ref:!0,__self:!0,__source:!0},ut,Tt;function We(E){if(ze.call(E,"ref")){var Z=Object.getOwnPropertyDescriptor(E,"ref").get;if(Z&&Z.isReactWarning)return!1}return E.ref!==void 0}function ft(E){if(ze.call(E,"key")){var Z=Object.getOwnPropertyDescriptor(E,"key").get;if(Z&&Z.isReactWarning)return!1}return E.key!==void 0}function rr(E,Z){typeof E.ref=="string"&&je.current}function Yt(E,Z){{var oe=function(){ut||(ut=!0,w("%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)",Z))};oe.isReactWarning=!0,Object.defineProperty(E,"key",{get:oe,configurable:!0})}}function Ln(E,Z){{var oe=function(){Tt||(Tt=!0,w("%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)",Z))};oe.isReactWarning=!0,Object.defineProperty(E,"ref",{get:oe,configurable:!0})}}var Xt=function(E,Z,oe,R,Y,se,ie){var ue={$$typeof:t,type:E,key:Z,ref:oe,props:ie,_owner:se};return ue._store={},Object.defineProperty(ue._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(ue,"_self",{configurable:!1,enumerable:!1,writable:!1,value:R}),Object.defineProperty(ue,"_source",{configurable:!1,enumerable:!1,writable:!1,value:Y}),Object.freeze&&(Object.freeze(ue.props),Object.freeze(ue)),ue};function Lt(E,Z,oe,R,Y){{var se,ie={},ue=null,Me=null;oe!==void 0&&($e(oe),ue=""+oe),ft(Z)&&($e(Z.key),ue=""+Z.key),We(Z)&&(Me=Z.ref,rr(Z,Y));for(se in Z)ze.call(Z,se)&&!rt.hasOwnProperty(se)&&(ie[se]=Z[se]);if(E&&E.defaultProps){var Oe=E.defaultProps;for(se in Oe)ie[se]===void 0&&(ie[se]=Oe[se])}if(ue||Me){var Ee=typeof E=="function"?E.displayName||E.name||"Unknown":E;ue&&Yt(ie,Ee),Me&&Ln(ie,Ee)}return Xt(E,ue,Me,Y,R,je.current,ie)}}var xn=y.ReactCurrentOwner,or=y.ReactDebugCurrentFrame;function ht(E){if(E){var Z=E._owner,oe=Ae(E.type,E._source,Z?Z.type:null);or.setExtraStackFrame(oe)}else or.setExtraStackFrame(null)}var $n;$n=!1;function cn(E){return typeof E=="object"&&E!==null&&E.$$typeof===t}function Be(){{if(xn.current){var E=U(xn.current.type);if(E)return`
22
+ */var Ql;function Qm(){return Ql||(Ql=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"),c=Symbol.for("react.forward_ref"),l=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,g="@@iterator";function x(E){if(E===null||typeof E!="object")return null;var Z=m&&E[m]||E[g];return typeof Z=="function"?Z:null}var y=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function w(E){{for(var Z=arguments.length,oe=new Array(Z>1?Z-1:0),R=1;R<Z;R++)oe[R-1]=arguments[R];k("error",E,oe)}}function k(E,Z,oe){{var R=y.ReactDebugCurrentFrame,X=R.getStackAddendum();X!==""&&(Z+="%s",oe=oe.concat([X]));var se=oe.map(function(ie){return String(ie)});se.unshift("Warning: "+Z),Function.prototype.apply.call(console[E],console,se)}}var I=!1,S=!1,C=!1,T=!1,A=!1,j;j=Symbol.for("react.module.reference");function _(E){return!!(typeof E=="string"||typeof E=="function"||E===r||E===s||A||E===o||E===l||E===u||T||E===p||I||S||C||typeof E=="object"&&E!==null&&(E.$$typeof===h||E.$$typeof===f||E.$$typeof===i||E.$$typeof===a||E.$$typeof===c||E.$$typeof===j||E.getModuleId!==void 0))}function L(E,Z,oe){var R=E.displayName;if(R)return R;var X=Z.displayName||Z.name||"";return X!==""?oe+"("+X+")":oe}function F(E){return E.displayName||"Context"}function B(E){if(E==null)return null;if(typeof E.tag=="number"&&w("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof E=="function")return E.displayName||E.name||null;if(typeof E=="string")return E;switch(E){case r:return"Fragment";case n:return"Portal";case s:return"Profiler";case o:return"StrictMode";case l:return"Suspense";case u:return"SuspenseList"}if(typeof E=="object")switch(E.$$typeof){case a:var Z=E;return F(Z)+".Consumer";case i:var oe=E;return F(oe._context)+".Provider";case c:return L(E,E.render,"ForwardRef");case f:var R=E.displayName||null;return R!==null?R:B(E.type)||"Memo";case h:{var X=E,se=X._payload,ie=X._init;try{return B(ie(se))}catch{return null}}}return null}var O=Object.assign,G=0,Y,re,H,W,ne,K,M;function N(){}N.__reactDisabledLog=!0;function $(){{if(G===0){Y=console.log,re=console.info,H=console.warn,W=console.error,ne=console.group,K=console.groupCollapsed,M=console.groupEnd;var E={configurable:!0,enumerable:!0,value:N,writable:!0};Object.defineProperties(console,{info:E,log:E,warn:E,error:E,group:E,groupCollapsed:E,groupEnd:E})}G++}}function D(){{if(G--,G===0){var E={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:O({},E,{value:Y}),info:O({},E,{value:re}),warn:O({},E,{value:H}),error:O({},E,{value:W}),group:O({},E,{value:ne}),groupCollapsed:O({},E,{value:K}),groupEnd:O({},E,{value:M})})}G<0&&w("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var q=y.ReactCurrentDispatcher,U;function P(E,Z,oe){{if(U===void 0)try{throw Error()}catch(X){var R=X.stack.trim().match(/\n( *(at )?)/);U=R&&R[1]||""}return`
23
+ `+U+E}}var V=!1,ee;{var ce=typeof WeakMap=="function"?WeakMap:Map;ee=new ce}function ue(E,Z){if(!E||V)return"";{var oe=ee.get(E);if(oe!==void 0)return oe}var R;V=!0;var X=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var se;se=q.current,q.current=null,$();try{if(Z){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(Fe){R=Fe}Reflect.construct(E,[],ie)}else{try{ie.call()}catch(Fe){R=Fe}E.call(ie.prototype)}}else{try{throw Error()}catch(Fe){R=Fe}E()}}catch(Fe){if(Fe&&R&&typeof Fe.stack=="string"){for(var de=Fe.stack.split(`
24
+ `),Re=R.stack.split(`
25
+ `),Oe=de.length-1,ke=Re.length-1;Oe>=1&&ke>=0&&de[Oe]!==Re[ke];)ke--;for(;Oe>=1&&ke>=0;Oe--,ke--)if(de[Oe]!==Re[ke]){if(Oe!==1||ke!==1)do if(Oe--,ke--,ke<0||de[Oe]!==Re[ke]){var fe=`
26
+ `+de[Oe].replace(" at new "," at ");return E.displayName&&fe.includes("<anonymous>")&&(fe=fe.replace("<anonymous>",E.displayName)),typeof E=="function"&&ee.set(E,fe),fe}while(Oe>=1&&ke>=0);break}}}finally{V=!1,q.current=se,D(),Error.prepareStackTrace=X}var Pe=E?E.displayName||E.name:"",_e=Pe?P(Pe):"";return typeof E=="function"&&ee.set(E,_e),_e}function be(E,Z,oe){return ue(E,!1)}function Ae(E){var Z=E.prototype;return!!(Z&&Z.isReactComponent)}function Ie(E,Z,oe){if(E==null)return"";if(typeof E=="function")return ue(E,Ae(E));if(typeof E=="string")return P(E);switch(E){case l:return P("Suspense");case u:return P("SuspenseList")}if(typeof E=="object")switch(E.$$typeof){case c:return be(E.render);case f:return Ie(E.type,Z,oe);case h:{var R=E,X=R._payload,se=R._init;try{return Ie(se(X),Z,oe)}catch{}}}return""}var Xe=Object.prototype.hasOwnProperty,ze={},Ze=y.ReactDebugCurrentFrame;function Be(E){if(E){var Z=E._owner,oe=Ie(E.type,E._source,Z?Z.type:null);Ze.setExtraStackFrame(oe)}else Ze.setExtraStackFrame(null)}function dt(E,Z,oe,R,X){{var se=Function.call.bind(Xe);for(var ie in E)if(se(E,ie)){var de=void 0;try{if(typeof E[ie]!="function"){var Re=Error((R||"React class")+": "+oe+" type `"+ie+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof E[ie]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Re.name="Invariant Violation",Re}de=E[ie](Z,ie,R,oe,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(Oe){de=Oe}de&&!(de instanceof Error)&&(Be(X),w("%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).",R||"React class",oe,ie,typeof de),Be(null)),de instanceof Error&&!(de.message in ze)&&(ze[de.message]=!0,Be(X),w("Failed %s type: %s",oe,de.message),Be(null))}}}var at=Array.isArray;function ct(E){return at(E)}function ft(E){{var Z=typeof Symbol=="function"&&Symbol.toStringTag,oe=Z&&E[Symbol.toStringTag]||E.constructor.name||"Object";return oe}}function tt(E){try{return nt(E),!1}catch{return!0}}function nt(E){return""+E}function ut(E){if(tt(E))return w("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",ft(E)),nt(E)}var qe=y.ReactCurrentOwner,Qe={key:!0,ref:!0,__self:!0,__source:!0},De,Le;function et(E){if(Xe.call(E,"ref")){var Z=Object.getOwnPropertyDescriptor(E,"ref").get;if(Z&&Z.isReactWarning)return!1}return E.ref!==void 0}function ht(E){if(Xe.call(E,"key")){var Z=Object.getOwnPropertyDescriptor(E,"key").get;if(Z&&Z.isReactWarning)return!1}return E.key!==void 0}function rr(E,Z){typeof E.ref=="string"&&qe.current}function Yt(E,Z){{var oe=function(){De||(De=!0,w("%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)",Z))};oe.isReactWarning=!0,Object.defineProperty(E,"key",{get:oe,configurable:!0})}}function Ln(E,Z){{var oe=function(){Le||(Le=!0,w("%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)",Z))};oe.isReactWarning=!0,Object.defineProperty(E,"ref",{get:oe,configurable:!0})}}var Xt=function(E,Z,oe,R,X,se,ie){var de={$$typeof:t,type:E,key:Z,ref:oe,props:ie,_owner:se};return de._store={},Object.defineProperty(de._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(de,"_self",{configurable:!1,enumerable:!1,writable:!1,value:R}),Object.defineProperty(de,"_source",{configurable:!1,enumerable:!1,writable:!1,value:X}),Object.freeze&&(Object.freeze(de.props),Object.freeze(de)),de};function Lt(E,Z,oe,R,X){{var se,ie={},de=null,Re=null;oe!==void 0&&(ut(oe),de=""+oe),ht(Z)&&(ut(Z.key),de=""+Z.key),et(Z)&&(Re=Z.ref,rr(Z,X));for(se in Z)Xe.call(Z,se)&&!Qe.hasOwnProperty(se)&&(ie[se]=Z[se]);if(E&&E.defaultProps){var Oe=E.defaultProps;for(se in Oe)ie[se]===void 0&&(ie[se]=Oe[se])}if(de||Re){var ke=typeof E=="function"?E.displayName||E.name||"Unknown":E;de&&Yt(ie,ke),Re&&Ln(ie,ke)}return Xt(E,de,Re,X,R,qe.current,ie)}}var xn=y.ReactCurrentOwner,or=y.ReactDebugCurrentFrame;function pt(E){if(E){var Z=E._owner,oe=Ie(E.type,E._source,Z?Z.type:null);or.setExtraStackFrame(oe)}else or.setExtraStackFrame(null)}var $n;$n=!1;function cn(E){return typeof E=="object"&&E!==null&&E.$$typeof===t}function Ue(){{if(xn.current){var E=B(xn.current.type);if(E)return`
27
27
 
28
- Check the render method of \``+E+"`."}return""}}function ot(E){return""}var bn={};function yn(E){{var Z=Be();if(!Z){var oe=typeof E=="string"?E:E.displayName||E.name;oe&&(Z=`
28
+ Check the render method of \``+E+"`."}return""}}function st(E){return""}var bn={};function yn(E){{var Z=Ue();if(!Z){var oe=typeof E=="string"?E:E.displayName||E.name;oe&&(Z=`
29
29
 
30
- Check the top-level render call using <`+oe+">.")}return Z}}function un(E,Z){{if(!E._store||E._store.validated||E.key!=null)return;E._store.validated=!0;var oe=yn(Z);if(bn[oe])return;bn[oe]=!0;var R="";E&&E._owner&&E._owner!==xn.current&&(R=" It was passed a child from "+U(E._owner.type)+"."),ht(E),w('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',oe,R),ht(null)}}function dn(E,Z){{if(typeof E!="object")return;if(nt(E))for(var oe=0;oe<E.length;oe++){var R=E[oe];cn(R)&&un(R,Z)}else if(cn(E))E._store&&(E._store.validated=!0);else if(E){var Y=x(E);if(typeof Y=="function"&&Y!==E.entries)for(var se=Y.call(E),ie;!(ie=se.next()).done;)cn(ie.value)&&un(ie.value,Z)}}}function sr(E){{var Z=E.type;if(Z==null||typeof Z=="string")return;var oe;if(typeof Z=="function")oe=Z.propTypes;else if(typeof Z=="object"&&(Z.$$typeof===c||Z.$$typeof===f))oe=Z.propTypes;else return;if(oe){var R=U(Z);dt(oe,E.props,"prop",R,E)}else if(Z.PropTypes!==void 0&&!$n){$n=!0;var Y=U(Z);w("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",Y||"Unknown")}typeof Z.getDefaultProps=="function"&&!Z.getDefaultProps.isReactClassApproved&&w("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Mr(E){{for(var Z=Object.keys(E.props),oe=0;oe<Z.length;oe++){var R=Z[oe];if(R!=="children"&&R!=="key"){ht(E),w("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",R),ht(null);break}}E.ref!==null&&(ht(E),w("Invalid attribute `ref` supplied to `React.Fragment`."),ht(null))}}var ir={};function Fn(E,Z,oe,R,Y,se){{var ie=P(E);if(!ie){var ue="";(E===void 0||typeof E=="object"&&E!==null&&Object.keys(E).length===0)&&(ue+=" 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 Me=ot();Me?ue+=Me:ue+=Be();var Oe;E===null?Oe="null":nt(E)?Oe="array":E!==void 0&&E.$$typeof===t?(Oe="<"+(U(E.type)||"Unknown")+" />",ue=" Did you accidentally export a JSX literal instead of a component?"):Oe=typeof E,w("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",Oe,ue)}var Ee=Lt(E,Z,oe,Y,se);if(Ee==null)return Ee;if(ie){var de=Z.children;if(de!==void 0)if(R)if(nt(de)){for(var Re=0;Re<de.length;Re++)dn(de[Re],E);Object.freeze&&Object.freeze(de)}else w("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 dn(de,E)}if(ze.call(Z,"key")){var Pe=U(E),Fe=Object.keys(Z).filter(function(lr){return lr!=="key"}),pt=Fe.length>0?"{key: someKey, "+Fe.join(": ..., ")+": ...}":"{key: someKey}";if(!ir[Pe+pt]){var fn=Fe.length>0?"{"+Fe.join(": ..., ")+": ...}":"{}";w(`A props object containing a "key" prop is being spread into JSX:
30
+ Check the top-level render call using <`+oe+">.")}return Z}}function un(E,Z){{if(!E._store||E._store.validated||E.key!=null)return;E._store.validated=!0;var oe=yn(Z);if(bn[oe])return;bn[oe]=!0;var R="";E&&E._owner&&E._owner!==xn.current&&(R=" It was passed a child from "+B(E._owner.type)+"."),pt(E),w('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',oe,R),pt(null)}}function dn(E,Z){{if(typeof E!="object")return;if(ct(E))for(var oe=0;oe<E.length;oe++){var R=E[oe];cn(R)&&un(R,Z)}else if(cn(E))E._store&&(E._store.validated=!0);else if(E){var X=x(E);if(typeof X=="function"&&X!==E.entries)for(var se=X.call(E),ie;!(ie=se.next()).done;)cn(ie.value)&&un(ie.value,Z)}}}function sr(E){{var Z=E.type;if(Z==null||typeof Z=="string")return;var oe;if(typeof Z=="function")oe=Z.propTypes;else if(typeof Z=="object"&&(Z.$$typeof===c||Z.$$typeof===f))oe=Z.propTypes;else return;if(oe){var R=B(Z);dt(oe,E.props,"prop",R,E)}else if(Z.PropTypes!==void 0&&!$n){$n=!0;var X=B(Z);w("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",X||"Unknown")}typeof Z.getDefaultProps=="function"&&!Z.getDefaultProps.isReactClassApproved&&w("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Or(E){{for(var Z=Object.keys(E.props),oe=0;oe<Z.length;oe++){var R=Z[oe];if(R!=="children"&&R!=="key"){pt(E),w("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",R),pt(null);break}}E.ref!==null&&(pt(E),w("Invalid attribute `ref` supplied to `React.Fragment`."),pt(null))}}var ir={};function Fn(E,Z,oe,R,X,se){{var ie=_(E);if(!ie){var de="";(E===void 0||typeof E=="object"&&E!==null&&Object.keys(E).length===0)&&(de+=" 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 Re=st();Re?de+=Re:de+=Ue();var Oe;E===null?Oe="null":ct(E)?Oe="array":E!==void 0&&E.$$typeof===t?(Oe="<"+(B(E.type)||"Unknown")+" />",de=" Did you accidentally export a JSX literal instead of a component?"):Oe=typeof E,w("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",Oe,de)}var ke=Lt(E,Z,oe,X,se);if(ke==null)return ke;if(ie){var fe=Z.children;if(fe!==void 0)if(R)if(ct(fe)){for(var Pe=0;Pe<fe.length;Pe++)dn(fe[Pe],E);Object.freeze&&Object.freeze(fe)}else w("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 dn(fe,E)}if(Xe.call(Z,"key")){var _e=B(E),Fe=Object.keys(Z).filter(function(lr){return lr!=="key"}),mt=Fe.length>0?"{key: someKey, "+Fe.join(": ..., ")+": ...}":"{key: someKey}";if(!ir[_e+mt]){var fn=Fe.length>0?"{"+Fe.join(": ..., ")+": ...}":"{}";w(`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} />`,pt,Pe,fn,Pe),ir[Pe+pt]=!0}}return E===r?Mr(Ee):sr(Ee),Ee}}function zn(E,Z,oe){return Fn(E,Z,oe,!0)}function wn(E,Z,oe){return Fn(E,Z,oe,!1)}var $t=wn,ar=zn;Ur.Fragment=r,Ur.jsx=$t,Ur.jsxs=ar}()),Ur}process.env.NODE_ENV==="production"?ii.exports=Zm():ii.exports=Qm();var d=ii.exports;class eg{constructor(){ol(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?Sn(t.apiKey):t.getToken&&Sn(t.getToken())}getAuthToken(){return ni()}setAuthToken(t){Sn(t)}onTokenChange(t){return ri(t)}async listUsers(){const t=await At("/users",{baseURL:this.baseUrl});return(t==null?void 0:t.users)??[]}}const tg=new eg,ec=v.createContext(null);function tc({children:e,apiConfig:t}){const n=Cn,r=tg;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:si,baseUrl:n.baseUrl};return d.jsx(ec.Provider,{value:o,children:e})}async function nc(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 c=0;c<a;c++)i+=String.fromCharCode(s[c]);t(btoa(i))}catch(o){n(o)}},r.onerror=o=>n(o),r.readAsArrayBuffer(e)})}async function rc(e=[]){const t=[],n=[];for(const r of e)try{const o=await nc(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 hr(){const e=v.useContext(ec);if(!e)throw new Error("useApi must be used within ApiProvider");return e}function ng(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 oc(e,t="user"){return typeof e=="string"?ng(t,e):e}function Vn(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 rg(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 sc(e){const t=Vn(e);if(t)return Vn(t.configurable)??t}function og(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=og(t);if(n)try{return JSON.parse(n)}catch{return null}return null}}function ic(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function sg(e){return e.replace(/[_-](\w)/g,(t,n)=>n?n.toUpperCase():"").replace(/^\w/,t=>t.toLowerCase())}function Tn(e){return!e||typeof e!="object"?e:Array.isArray(e)?e.map(Tn):Object.fromEntries(Object.entries(e).map(([t,n])=>[sg(t),Tn(n)]))}function Mo(e){var h,p;if(!e||typeof e!="object")return null;const t=Tn(e),n=lg(t);if(!n)return null;const r=Array.isArray(t.toolCalls)?t.toolCalls.map(ac):void 0,o=ag(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??((h=t.additionalKwargs)==null?void 0:h.createdAt)??new Date().toISOString(),a=t.name??void 0,c=t.model??((p=t.additionalKwargs)==null?void 0:p.model)??void 0,l=t.toolCallId??void 0,u=t.additionalKwargs??void 0,f=t.responseMetadata??void 0;return{...t,id:s,role:n,content:o,createdAt:i,name:a,model:c,toolCallId:l,toolCalls:r,additionalKwargs:u,responseMetadata:f,artifact:t.artifact??void 0}}function ig(e){if(!e||typeof e!="object")return e;const t=Tn(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 ac(e){if(!e||typeof e!="object")return e;const t=Tn(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 ag(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:ac(Tn(n)):n).filter(n=>!!(n&&typeof n=="object"&&typeof n.type=="string")):[]}function lg(e){const t=Tn(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=pr(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 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)=>cg(Tn(s),i)).filter(s=>!!s)].sort((s,i)=>lc(i.createdAt)-lc(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 cg(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=>ug(T,n)).filter(T=>!!T),i=Vn(e.metadata)??{},a=sc(e.config),c=Vn(e.parentConfig),l=sc(c),u=Hr(a,["checkpointId"]),f=Hr(a,["checkpointNs"]),h=Hr(l,["checkpointId"]),p=Vn(e.config),m=Array.isArray(e.tasks)?e.tasks.map(T=>({...T})):e.tasks??null,g=Array.isArray(e.next)?[...e.next]:e.next??null,x=typeof e.createdAt=="string"&&e.createdAt.trim()?e.createdAt:new Date(Date.now()-t).toISOString(),y={...i,step:rg(i,["step"])??0,source:Hr(i,["source"])??null},w=s.map(T=>({...T,checkpointId:u??null})),k=e.values,I=Array.isArray(e.interrupts)?e.interrupts:Array.isArray(k==null?void 0:k.interrupts)?k.interrupts:[];return{checkpointId:u??null,checkpointNs:f??null,createdAt:x,parentId:h??null,messages:w,interrupt:dg(w,I,t,u??null),metadata:y,config:p??null,parentConfig:c??null,next:g,tasks:m,values:e.values??{}}}function ug(e,t){const n=Mo(e);return n?(n.role==="assistant"&&!n.name&&t&&(n.name=t),n):null}function dg(e,t,n,r){const o=t.length,s=fg(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 c=a,l=c.value??a;if(l==null)continue;return{id:typeof c.id=="string"&&c.id.trim()?c.id:`interrupt-${r??n}-${i}`,value:l}}return null}function fg(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 lc(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function cc(e){return!!e&&typeof e=="object"&&"data"in e}function hg(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,c]=v.useState(!1),[l,u]=v.useState(null),[f,h]=v.useState(""),[p,m]=v.useState(null),[g,x]=v.useState(0),[y,w]=v.useState(!1),[k,I]=v.useState({}),[S,C]=v.useState(null),[T,A]=v.useState({}),j=v.useRef(null),P=v.useRef(!0),M=v.useRef(0),F=v.useRef(null),U=v.useRef(null),L=v.useRef(null),K=v.useRef(null),q=v.useRef({messageId:null,lastSeq:null,lastText:""}),re=v.useCallback(H=>{o(H)},[]),W=v.useCallback(()=>{h(""),m(null),u(null),U.current=null,L.current=null,K.current=null,I({}),C(null),A({}),q.current={messageId:null,lastSeq:null,lastText:""}},[]),V=v.useCallback(()=>{var $;console.debug("[use-chat] stop() invoked - aborting stream");const H=($=F.current)==null?void 0:$.threadId,O=()=>{var D;(D=j.current)==null||D.abort(),j.current=null,F.current=null,c(!1),w(!1),M.current=0,x(0)};(H?Cn.cancelRun(H).catch(D=>{console.warn("[use-chat] cancel run failed:",D)}):Promise.resolve()).finally(O)},[]),ne=v.useCallback((H,O,N)=>{j.current&&(j.current.abort(),j.current=null),c(!0),u(null),e.autoAppendAssistant!==!1&&h(""),m(null),U.current=null,L.current=null,K.current=null,I({}),C(null),A({}),q.current={messageId:null,lastSeq:null,lastText:""};const $=new AbortController;j.current=$;let D=null,G=null,ee=!1;return F.current={threadId:H.threadId??null,headers:{},isStreaming:!0},(async()=>{var _,B,X,le,me,be,Te,Ae,ze,Ze,Ye,Ve,dt,lt,nt,it,ct,Ke,$e;try{let je={};try{if(r)je={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const ot=window.__AUTH_TOKEN__,bn=((_=window.localStorage)==null?void 0:_.getItem(vn.authToken))||null;let yn=null;try{const dn=(B=window.localStorage)==null?void 0:B.getItem(vn.chatSettings);dn&&(yn=((X=JSON.parse(dn))==null?void 0:X.apiKey)||null)}catch{}const un=ot||bn||yn||null;un&&(je={Authorization:`Bearer ${un}`})}}catch{}console.debug("[use-chat] POST",t+n);let rt={};if(typeof window<"u")try{const Be=(le=window.localStorage)==null?void 0:le.getItem(vn.authSessionId);Be&&(rt={"X-Session-Id":Be})}catch{}const ut={...je,...rt,...s.current},Tt={"Content-Type":"application/json",Accept:"text/event-stream",...ut},We=await fetch(t+n,{method:"POST",headers:Tt,body:JSON.stringify(H),signal:$.signal,credentials:i});if(F.current&&(F.current.headers=ut),!We.ok||!We.body){const Be=await We.text().catch(()=>"");console.debug("[use-chat] non-OK response",We.status,Be==null?void 0:Be.slice(0,500));const ot=`stream ${We.status}${Be?": "+Be:""}`;throw(me=N==null?void 0:N.onConnectionError)==null||me.call(N,ot),ee=!0,D="error",G=ot,new Error(ot)}w(!0);const ft=We.body.getReader(),rr=new TextDecoder;let Yt="",Ln=[];M.current=0,x(0);let Xt=0,Lt=null;const xn=()=>{if(Ln.length){const Be=Ln.join("");Ln=[],P.current&&h(ot=>ot+Be)}Lt=null},or=()=>{typeof window<"u"&&Lt==null&&(Lt=requestAnimationFrame(xn))};let ht=Date.now();const $n=setInterval(()=>{var Be;if(Date.now()-ht>18e5){const ot="Stream idle timeout";u(ot),D="error",G=ot,$.abort(),(Be=N==null?void 0:N.onError)==null||Be.call(N,ot)}},5e3),cn=1024*1024;try{const Be=We.headers.get("X-Thread-Id")||We.headers.get("x-thread-id"),ot=We.headers.get("X-Thread-Created")||We.headers.get("x-thread-created"),bn=Be??null,yn=String(ot??"").toLowerCase()==="true";for(F.current&&!F.current.threadId&&(F.current={...F.current,threadId:bn}),(be=N==null?void 0:N.onOpen)==null||be.call(N,{threadId:bn,created:yn});;){const{value:un,done:dn}=await ft.read();if(dn)break;Yt+=rr.decode(un,{stream:!0}),Yt.length>cn&&(Yt="",console.warn("Stream buffer reset: exceeded 1MB"));let sr;for(;(sr=Yt.indexOf(`
35
+ <%s key={someKey} {...props} />`,mt,_e,fn,_e),ir[_e+mt]=!0}}return E===r?Or(ke):sr(ke),ke}}function zn(E,Z,oe){return Fn(E,Z,oe,!0)}function wn(E,Z,oe){return Fn(E,Z,oe,!1)}var $t=wn,ar=zn;Ur.Fragment=r,Ur.jsx=$t,Ur.jsxs=ar}()),Ur}process.env.NODE_ENV==="production"?ii.exports=Zm():ii.exports=Qm();var d=ii.exports;class eg{constructor(){ol(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?Sn(t.apiKey):t.getToken&&Sn(t.getToken())}getAuthToken(){return ni()}setAuthToken(t){Sn(t)}onTokenChange(t){return ri(t)}async listUsers(){const t=await At("/users",{baseURL:this.baseUrl});return(t==null?void 0:t.users)??[]}}const tg=new eg,ec=v.createContext(null);function tc({children:e,apiConfig:t}){const n=Cn,r=tg;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:si,baseUrl:n.baseUrl};return d.jsx(ec.Provider,{value:o,children:e})}async function nc(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 c=0;c<a;c++)i+=String.fromCharCode(s[c]);t(btoa(i))}catch(o){n(o)}},r.onerror=o=>n(o),r.readAsArrayBuffer(e)})}async function rc(e=[]){const t=[],n=[];for(const r of e)try{const o=await nc(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 hr(){const e=v.useContext(ec);if(!e)throw new Error("useApi must be used within ApiProvider");return e}function ng(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 oc(e,t="user"){return typeof e=="string"?ng(t,e):e}function Vn(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 rg(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 sc(e){const t=Vn(e);if(t)return Vn(t.configurable)??t}function og(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=og(t);if(n)try{return JSON.parse(n)}catch{return null}return null}}function ic(e){return typeof e!="string"?!1:/^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e)}function sg(e){return e.replace(/[_-](\w)/g,(t,n)=>n?n.toUpperCase():"").replace(/^\w/,t=>t.toLowerCase())}function Tn(e){return!e||typeof e!="object"?e:Array.isArray(e)?e.map(Tn):Object.fromEntries(Object.entries(e).map(([t,n])=>[sg(t),Tn(n)]))}function Oo(e){var h,p;if(!e||typeof e!="object")return null;const t=Tn(e),n=lg(t);if(!n)return null;const r=Array.isArray(t.toolCalls)?t.toolCalls.map(ac):void 0,o=ag(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??((h=t.additionalKwargs)==null?void 0:h.createdAt)??new Date().toISOString(),a=t.name??void 0,c=t.model??((p=t.additionalKwargs)==null?void 0:p.model)??void 0,l=t.toolCallId??void 0,u=t.additionalKwargs??void 0,f=t.responseMetadata??void 0;return{...t,id:s,role:n,content:o,createdAt:i,name:a,model:c,toolCallId:l,toolCalls:r,additionalKwargs:u,responseMetadata:f,artifact:t.artifact??void 0}}function ig(e){if(!e||typeof e!="object")return e;const t=Tn(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 ac(e){if(!e||typeof e!="object")return e;const t=Tn(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 ag(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:ac(Tn(n)):n).filter(n=>!!(n&&typeof n=="object"&&typeof n.type=="string")):[]}function lg(e){const t=Tn(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=pr(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 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)=>cg(Tn(s),i)).filter(s=>!!s)].sort((s,i)=>lc(i.createdAt)-lc(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 cg(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=>ug(T,n)).filter(T=>!!T),i=Vn(e.metadata)??{},a=sc(e.config),c=Vn(e.parentConfig),l=sc(c),u=Hr(a,["checkpointId"]),f=Hr(a,["checkpointNs"]),h=Hr(l,["checkpointId"]),p=Vn(e.config),m=Array.isArray(e.tasks)?e.tasks.map(T=>({...T})):e.tasks??null,g=Array.isArray(e.next)?[...e.next]:e.next??null,x=typeof e.createdAt=="string"&&e.createdAt.trim()?e.createdAt:new Date(Date.now()-t).toISOString(),y={...i,step:rg(i,["step"])??0,source:Hr(i,["source"])??null},w=s.map(T=>({...T,checkpointId:u??null})),k=e.values,I=Array.isArray(e.interrupts)?e.interrupts:Array.isArray(k==null?void 0:k.interrupts)?k.interrupts:[];return{checkpointId:u??null,checkpointNs:f??null,createdAt:x,parentId:h??null,messages:w,interrupt:dg(w,I,t,u??null),metadata:y,config:p??null,parentConfig:c??null,next:g,tasks:m,values:e.values??{}}}function ug(e,t){const n=Oo(e);return n?(n.role==="assistant"&&!n.name&&t&&(n.name=t),n):null}function dg(e,t,n,r){const o=t.length,s=fg(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 c=a,l=c.value??a;if(l==null)continue;return{id:typeof c.id=="string"&&c.id.trim()?c.id:`interrupt-${r??n}-${i}`,value:l}}return null}function fg(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 lc(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function cc(e){return!!e&&typeof e=="object"&&"data"in e}function hg(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,c]=v.useState(!1),[l,u]=v.useState(null),[f,h]=v.useState(""),[p,m]=v.useState(null),[g,x]=v.useState(0),[y,w]=v.useState(!1),[k,I]=v.useState({}),[S,C]=v.useState(null),[T,A]=v.useState({}),j=v.useRef(null),_=v.useRef(!0),L=v.useRef(0),F=v.useRef(null),B=v.useRef(null),O=v.useRef(null),G=v.useRef(null),Y=v.useRef({messageId:null,lastSeq:null,lastText:""}),re=v.useCallback(K=>{o(K)},[]),H=v.useCallback(()=>{h(""),m(null),u(null),B.current=null,O.current=null,G.current=null,I({}),C(null),A({}),Y.current={messageId:null,lastSeq:null,lastText:""}},[]),W=v.useCallback(()=>{var $;console.debug("[use-chat] stop() invoked - aborting stream");const K=($=F.current)==null?void 0:$.threadId,M=()=>{var D;(D=j.current)==null||D.abort(),j.current=null,F.current=null,c(!1),w(!1),L.current=0,x(0)};(K?Cn.cancelRun(K).catch(D=>{console.warn("[use-chat] cancel run failed:",D)}):Promise.resolve()).finally(M)},[]),ne=v.useCallback((K,M,N)=>{j.current&&(j.current.abort(),j.current=null),c(!0),u(null),e.autoAppendAssistant!==!1&&h(""),m(null),B.current=null,O.current=null,G.current=null,I({}),C(null),A({}),Y.current={messageId:null,lastSeq:null,lastText:""};const $=new AbortController;j.current=$;let D=null,q=null,U=!1;return F.current={threadId:K.threadId??null,headers:{},isStreaming:!0},(async()=>{var P,V,ee,ce,ue,be,Ae,Ie,Xe,ze,Ze,Be,dt,at,ct,ft,tt,nt,ut;try{let qe={};try{if(r)qe={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const st=window.__AUTH_TOKEN__,bn=((P=window.localStorage)==null?void 0:P.getItem(vn.authToken))||null;let yn=null;try{const dn=(V=window.localStorage)==null?void 0:V.getItem(vn.chatSettings);dn&&(yn=((ee=JSON.parse(dn))==null?void 0:ee.apiKey)||null)}catch{}const un=st||bn||yn||null;un&&(qe={Authorization:`Bearer ${un}`})}}catch{}console.debug("[use-chat] POST",t+n);let Qe={};if(typeof window<"u")try{const Ue=(ce=window.localStorage)==null?void 0:ce.getItem(vn.authSessionId);Ue&&(Qe={"X-Session-Id":Ue})}catch{}const De={...qe,...Qe,...s.current},Le={"Content-Type":"application/json",Accept:"text/event-stream",...De},et=await fetch(t+n,{method:"POST",headers:Le,body:JSON.stringify(K),signal:$.signal,credentials:i});if(F.current&&(F.current.headers=De),!et.ok||!et.body){const Ue=await et.text().catch(()=>"");console.debug("[use-chat] non-OK response",et.status,Ue==null?void 0:Ue.slice(0,500));const st=`stream ${et.status}${Ue?": "+Ue:""}`;throw(ue=N==null?void 0:N.onConnectionError)==null||ue.call(N,st),U=!0,D="error",q=st,new Error(st)}w(!0);const ht=et.body.getReader(),rr=new TextDecoder;let Yt="",Ln=[];L.current=0,x(0);let Xt=0,Lt=null;const xn=()=>{if(Ln.length){const Ue=Ln.join("");Ln=[],_.current&&h(st=>st+Ue)}Lt=null},or=()=>{typeof window<"u"&&Lt==null&&(Lt=requestAnimationFrame(xn))};let pt=Date.now();const $n=setInterval(()=>{var Ue;if(Date.now()-pt>18e5){const st="Stream idle timeout";u(st),D="error",q=st,$.abort(),(Ue=N==null?void 0:N.onError)==null||Ue.call(N,st)}},5e3),cn=1024*1024;try{const Ue=et.headers.get("X-Thread-Id")||et.headers.get("x-thread-id"),st=et.headers.get("X-Thread-Created")||et.headers.get("x-thread-created"),bn=Ue??null,yn=String(st??"").toLowerCase()==="true";for(F.current&&!F.current.threadId&&(F.current={...F.current,threadId:bn}),(be=N==null?void 0:N.onOpen)==null||be.call(N,{threadId:bn,created:yn});;){const{value:un,done:dn}=await ht.read();if(dn)break;Yt+=rr.decode(un,{stream:!0}),Yt.length>cn&&(Yt="",console.warn("Stream buffer reset: exceeded 1MB"));let sr;for(;(sr=Yt.indexOf(`
36
36
 
37
- `))>=0;){const Mr=Yt.slice(0,sr);Yt=Yt.slice(sr+2);const ir=Mr.split(/\r?\n/),Fn=[];let zn=null;for(const R of ir){if(R.startsWith(":")){R.startsWith(": heartbeat")&&console.debug("[use-chat] SSE heartbeat comment received");continue}if(R){if(R.startsWith("event:")){const Y=R.slice(6).trim();Y&&(zn=Y);continue}if(R.startsWith("data:")){const Y=R.slice(5);Fn.push(Y.startsWith(" ")?Y.slice(1):Y)}}}const wn=Fn.join(`
38
- `);if(!wn)continue;let $t;try{$t=JSON.parse(wn)}catch{console.debug("[use-chat] malformed SSE:",wn.slice(0,200));continue}zn&&typeof $t=="object"&&$t!==null&&!("type"in $t)&&($t.type=zn);const ar=cc($t)?$t.data:$t;if(!ar){console.warn("[use-chat] dropped envelope event without payload",$t);continue}const E=ig(ar),Z=E.type;ht=Date.now(),E.type==="values"&&(E.type="state_history"),E.type==="metadata"&&(E.title||E.createdAt)&&(E.type="thread_info");const oe=E.seq;if(oe!==void 0){if(oe<=Xt){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:oe,lastProcessedSeq:Xt,type:E.type});continue}Xt>0&&oe>Xt+1&&((Te=N==null?void 0:N.onGap)==null||Te.call(N,{from:Xt,to:oe})),Xt=oe,M.current=oe,x(oe)}if(E.type==="checkpoint")U.current=E.checkpointId??null,L.current=E.checkpointNs??null,m(E.checkpointId??null);else if(E.type==="state_history"){K.current=E;try{const Y=mr(E).latest;Y&&(U.current=Y.checkpointId??null,L.current=Y.checkpointNs??null,m(Y.checkpointId??null),A(Y.values??{}))}catch(R){console.warn("[use-chat] Failed to hydrate state_history payload",R)}}try{O==null||O(E)}catch(R){console.error("[use-chat] Error in onEvent callback:",R,"for event:",E.type)}try{E.type==="tool.start"&&(N!=null&&N.onToolStart)?N.onToolStart(E):E.type==="tool.end"&&(N!=null&&N.onToolEnd)?N.onToolEnd(E):E.type==="token"&&(N!=null&&N.onToken)?N.onToken(E.token):E.type==="thread_info"&&(N!=null&&N.onThreadInfo)&&N.onThreadInfo(E),Z==="updates"&&(N!=null&&N.onUpdateEvent)?N.onUpdateEvent(E):Z==="custom"&&(N!=null&&N.onCustomEvent)?N.onCustomEvent(E):Z==="metadata"&&(N!=null&&N.onMetadataEvent)&&N.onMetadataEvent(E)}catch(R){console.warn("[use-chat] Typed callback error:",R)}if(E.type==="messages/partial"){const Y=E.messages;if(Array.isArray(Y)&&Y.length>0){const se=Y.find(ue=>ue.type==="ai"),ie=Y.find(ue=>ue.type==="tool"||ue.role==="tool");if(se){const ue=se.id,Me=se.content??"",Oe=se.response_metadata??{};if(q.current.messageId!==ue){const de=Oe.model_name??Oe.model_provider??"assistant";q.current={messageId:ue,lastSeq:null,lastText:""};const Re=Mo({id:ue,role:"assistant",name:de,model:de,createdAt:new Date().toISOString(),content:[{type:"text",text:Me}]});I(Pe=>({...Pe,[ue]:Re})),C(ue)}else I(de=>{const Re=de[ue];return Re?{...de,[ue]:{...Re,content:[{type:"text",text:Me}]}}:de});const Ee=q.current.lastText||"";if(Me.length>Ee.length){const de=Me.slice(Ee.length);q.current.lastText=Me,e.autoAppendAssistant!==!1&&(Ln.push(de),or())}}if(ie){const ue=ie.id||`tool-${Date.now()}`,Me=Mo({...ie,id:ue,role:"tool",createdAt:new Date().toISOString()});I(Oe=>({...Oe,[ue]:Me}))}}}else if(E.type==="updates"){const R=E;if(R.tools){const Y=R.tools;if(Y.status==="start"){const se={type:"tool.start",id:Y.id,name:Y.name,args:Y.args,seq:R.seq,callId:Y.id};try{O==null||O(se)}catch(ie){console.error("[use-chat] Error in onEvent (tool.start polyfill):",ie)}}else if(Y.status==="end"){const se={type:"tool.end",id:Y.id,name:Y.name,content:Y.output,artifact:Y.artifact,seq:R.seq,callId:Y.id};try{O==null||O(se)}catch(ie){console.error("[use-chat] Error in onEvent (tool.end polyfill):",ie)}}}continue}else if(E.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(Ae=N==null?void 0:N.onHeartbeat)==null||Ae.call(N,E)}catch(R){console.warn("[use-chat] heartbeat callback failed",R)}}else if(Lt!==null&&cancelAnimationFrame(Lt),xn(),E.type==="checkpoint")m(E.checkpointId??null);else if(E.type==="error"){const R=E;if(u(R.message),D="error",G=R.message,R.error_type==="auth_error"||R.code==="TOKEN_EXPIRED"||((ze=R.message)==null?void 0:ze.includes("token"))||((Ze=R.message)==null?void 0:Ze.includes("401"))||((Ye=R.message)==null?void 0:Ye.includes("unauthorized"))||((Ve=R.message)==null?void 0:Ve.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",R.message);try{(dt=N==null?void 0:N.onAuthError)==null||dt.call(N,R.message)}catch(se){console.warn("[use-chat] onAuthError handler failed",se)}$.abort()}}}}xn(),D===null&&!$.signal.aborted&&(D="complete")}catch(Be){if(Be.name==="AbortError")D=D??"aborted";else{const ot=Be.message||String(Be);D="error",G=ot,u(ot),(lt=N==null?void 0:N.onError)==null||lt.call(N,ot)}}finally{try{await ft.cancel()}catch{}finally{(nt=ft.releaseLock)==null||nt.call(ft)}Lt!==null&&typeof window<"u"&&window.cancelAnimationFrame(Lt),clearInterval($n)}}catch(je){if(je.name==="AbortError")D=D??"aborted";else{const rt=je.message||String(je);D="error",G=rt,u(rt),(it=N==null?void 0:N.onError)==null||it.call(N,rt),ee||((ct=N==null?void 0:N.onConnectionError)==null||ct.call(N,rt),ee=!0)}}finally{const je=M.current,rt=U.current,ut=L.current,Tt=K.current,We=D??($.signal.aborted?"aborted":G?"error":"complete");try{(Ke=N==null?void 0:N.onClosed)==null||Ke.call(N,{reason:We,lastSeq:je,lastCheckpointId:rt,lastCheckpointNs:ut,lastStateHistory:Tt,error:G}),We==="complete"&&(($e=N==null?void 0:N.onFinish)==null||$e.call(N,{lastSeq:je,lastCheckpointId:rt,lastCheckpointNs:ut,lastStateHistory:Tt}))}catch(ft){console.warn("[use-chat] onClosed callback failed",ft)}c(!1),w(!1),j.current=null,M.current=0,x(0),F.current=null}})(),{close:()=>$.abort()}},[t,n,r,e.autoAppendAssistant]);return v.useEffect(()=>()=>{var H;P.current=!1,(H=j.current)==null||H.abort()},[]),{isStreaming:a,error:l,assistantText:f,activeMessageId:S,streamedMessages:k,lastCheckpointId:p,lastSeq:g,connected:y,stream:ne,stop:V,clear:W,setToken:re,values:T,interrupt:()=>Promise.resolve(),resume:()=>Promise.resolve(),goto:()=>Promise.resolve()}}const pg=["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 pg){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 mg(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 uc({api:e,initialThreadId:t=null,onError:n,onThreadChange:r,onCurrentThreadDeleted:o}){const[s,i]=v.useState([]),[a,c]=v.useState(t),[l,u]=v.useState(!1),[f,h]=v.useState(null),[p,m]=v.useState([]),[g,x]=v.useState(!1),[,y]=v.useState(null),[w,k]=v.useState(null),[I,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&&c(t)},[t]);const A=v.useCallback(async()=>{u(!0),h(null);try{const W=await e.listThreads();i(W??[])}catch(W){const V=String(W);h(V),n==null||n(V)}finally{u(!1)}},[e,n]),j=v.useCallback(async()=>{x(!0),y(null);try{const W=await e.listSharedThreads();m(W??[])}catch(W){const V=String(W);y(V),n==null||n(V)}finally{x(!1)}},[e,n]);v.useEffect(()=>{A()},[A]),v.useEffect(()=>{j()},[j]),v.useEffect(()=>{r==null||r(a)},[a,r]);const P=v.useCallback(async(W,V)=>{try{const ne=V&&typeof V=="object"?{id:V.id,name:V.name??""}:void 0,H=await e.createThread(W,ne);return c(H.threadId),await A(),H.threadId}catch(ne){const H=String(ne);return n==null||n(H),null}},[e,n,A]),M=v.useCallback(async W=>{const V=s;i(H=>H.filter(O=>O.threadId!==W));const ne=new AbortController;T.current.set(W,ne);try{await e.deleteThread(W),C.current===W&&(c(null),o==null||o())}catch(H){i(V);const O=String(H);n==null||n(O)}finally{T.current.delete(W)}},[e,o,n,s]),F=v.useCallback(async(W,V)=>{try{await e.updateThread(W,V),await A()}catch(ne){n==null||n(String(ne))}},[e,n,A]),U=v.useCallback(async(W,V)=>{S(!0),k("Sharing thread…");try{await e.shareThread(W,V),await j(),k("Shared successfully")}catch(ne){const H=mg(ne);throw n==null||n(H),k(`Failed to share: ${H}`),new Error(H)}finally{S(!1)}},[e,n,j]),L=v.useCallback(async(W,V)=>{try{await e.unshareThread(W,V),await j()}catch(ne){const H=String(ne);throw n==null||n(H),ne}},[e,n,j]),K=v.useMemo(()=>({createThread:P,deleteThread:M,renameThread:F,refreshThreads:A,refreshSharedThreads:j,shareThread:U,unshareThread:L}),[P,M,F,A,j,U,L]),q=v.useCallback(W=>{if(!(W!=null&&W.threadId))return;const V={threadId:W.threadId,title:W.title||`Thread ${W.threadId.slice(0,8)}`,project:W.project,createdAt:W.createdAt||new Date().toISOString(),updatedAt:W.updatedAt||new Date().toISOString(),messageCount:W.messageCount??1};i(ne=>{let H=!1;const O=ne.map(N=>N.threadId===V.threadId?(H=!0,console.debug("[useThreadsState] thread_info: updating existing thread",V.threadId),{...N,title:V.title??N.title,project:V.project??N.project,updatedAt:V.updatedAt??N.updatedAt,messageCount:V.messageCount??N.messageCount}):N);return H?O:(console.debug("[useThreadsState] thread_info: adding thread to list",V.threadId),[V,...ne])})},[]),re=v.useCallback(()=>k(null),[]);return{threads:s,currentThreadId:a,currentThreadIdRef:C,setCurrentThreadId:c,isLoadingThreads:l,threadsError:f,sharedThreads:p,isLoadingSharedThreads:g,actions:K,addThreadFromEvent:q,shareInFlight:I,shareStatus:w,clearShareStatus:re}}const dc=v.createContext(null);function fc({children:e,initialThreadId:t=null,onError:n,onThreadChange:r}){const{chatApi:o}=hr(),{threads:s,currentThreadId:i,setCurrentThreadId:a,currentThreadIdRef:c,isLoadingThreads:l,threadsError:u,sharedThreads:f,isLoadingSharedThreads:h,actions:p,addThreadFromEvent:m,shareInFlight:g,shareStatus:x,clearShareStatus:y}=uc({api:o,initialThreadId:t,onError:n,onThreadChange:r}),w=v.useMemo(()=>({threads:s,currentThreadId:i,setCurrentThreadId:a,currentThreadIdRef:c,isLoading:l,error:u,sharedThreads:f,isLoadingSharedThreads:h,actions:p,shareInFlight:g,shareStatus:x,clearShareStatus:y,addThreadFromEvent:m}),[s,i,a,c,l,u,f,h,p,g,x,y,m]);return d.jsx(dc.Provider,{value:w,children:e})}function Vr(){const e=v.useContext(dc);if(!e)throw new Error("useThreads must be used within a ThreadsProvider");return e}function gg(e){return e.type==="text"}function xg(e){return e.type==="image_url"}function bg(e){return e.type==="file"}function yg(e){return e.type==="interrupt"}function wg(e){return e.content.filter(gg).map(t=>t.text).join(`
37
+ `))>=0;){const Or=Yt.slice(0,sr);Yt=Yt.slice(sr+2);const ir=Or.split(/\r?\n/),Fn=[];let zn=null;for(const R of ir){if(R.startsWith(":")){R.startsWith(": heartbeat")&&console.debug("[use-chat] SSE heartbeat comment received");continue}if(R){if(R.startsWith("event:")){const X=R.slice(6).trim();X&&(zn=X);continue}if(R.startsWith("data:")){const X=R.slice(5);Fn.push(X.startsWith(" ")?X.slice(1):X)}}}const wn=Fn.join(`
38
+ `);if(!wn)continue;let $t;try{$t=JSON.parse(wn)}catch{console.debug("[use-chat] malformed SSE:",wn.slice(0,200));continue}zn&&typeof $t=="object"&&$t!==null&&!("type"in $t)&&($t.type=zn);const ar=cc($t)?$t.data:$t;if(!ar){console.warn("[use-chat] dropped envelope event without payload",$t);continue}const E=ig(ar),Z=E.type;pt=Date.now(),E.type==="values"&&(E.type="state_history"),E.type==="metadata"&&(E.title||E.createdAt)&&(E.type="thread_info");const oe=E.seq;if(oe!==void 0){if(oe<=Xt){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:oe,lastProcessedSeq:Xt,type:E.type});continue}Xt>0&&oe>Xt+1&&((Ae=N==null?void 0:N.onGap)==null||Ae.call(N,{from:Xt,to:oe})),Xt=oe,L.current=oe,x(oe)}if(E.type==="checkpoint")B.current=E.checkpointId??null,O.current=E.checkpointNs??null,m(E.checkpointId??null);else if(E.type==="state_history"){G.current=E;try{const X=mr(E).latest;X&&(B.current=X.checkpointId??null,O.current=X.checkpointNs??null,m(X.checkpointId??null),A(X.values??{}))}catch(R){console.warn("[use-chat] Failed to hydrate state_history payload",R)}}try{M==null||M(E)}catch(R){console.error("[use-chat] Error in onEvent callback:",R,"for event:",E.type)}try{E.type==="tool.start"&&(N!=null&&N.onToolStart)?N.onToolStart(E):E.type==="tool.end"&&(N!=null&&N.onToolEnd)?N.onToolEnd(E):E.type==="token"&&(N!=null&&N.onToken)?N.onToken(E.token):E.type==="thread_info"&&(N!=null&&N.onThreadInfo)&&N.onThreadInfo(E),Z==="updates"&&(N!=null&&N.onUpdateEvent)?N.onUpdateEvent(E):Z==="custom"&&(N!=null&&N.onCustomEvent)?N.onCustomEvent(E):Z==="metadata"&&(N!=null&&N.onMetadataEvent)&&N.onMetadataEvent(E)}catch(R){console.warn("[use-chat] Typed callback error:",R)}if(E.type==="messages/partial"){const X=E.messages;if(Array.isArray(X)&&X.length>0){const se=X.find(de=>de.type==="ai"),ie=X.find(de=>de.type==="tool"||de.role==="tool");if(se){const de=se.id,Re=se.content??"",Oe=se.response_metadata??{};if(Y.current.messageId!==de){const fe=Oe.model_name??Oe.model_provider??"assistant";Y.current={messageId:de,lastSeq:null,lastText:""};const Pe=Oo({id:de,role:"assistant",name:fe,model:fe,createdAt:new Date().toISOString(),content:[{type:"text",text:Re}]});I(_e=>({..._e,[de]:Pe})),C(de)}else I(fe=>{const Pe=fe[de];return Pe?{...fe,[de]:{...Pe,content:[{type:"text",text:Re}]}}:fe});const ke=Y.current.lastText||"";if(Re.length>ke.length){const fe=Re.slice(ke.length);Y.current.lastText=Re,e.autoAppendAssistant!==!1&&(Ln.push(fe),or())}}if(ie){const de=ie.id||`tool-${Date.now()}`,Re=Oo({...ie,id:de,role:"tool",createdAt:new Date().toISOString()});I(Oe=>({...Oe,[de]:Re}))}}}else if(E.type==="updates"){const R=E;if(R.tools){const X=R.tools;if(X.status==="start"){const se={type:"tool.start",id:X.id,name:X.name,args:X.args,seq:R.seq,callId:X.id};try{M==null||M(se)}catch(ie){console.error("[use-chat] Error in onEvent (tool.start polyfill):",ie)}}else if(X.status==="end"){const se={type:"tool.end",id:X.id,name:X.name,content:X.output,artifact:X.artifact,seq:R.seq,callId:X.id};try{M==null||M(se)}catch(ie){console.error("[use-chat] Error in onEvent (tool.end polyfill):",ie)}}}continue}else if(E.type==="heartbeat"){console.debug("[use-chat] heartbeat received");try{(Ie=N==null?void 0:N.onHeartbeat)==null||Ie.call(N,E)}catch(R){console.warn("[use-chat] heartbeat callback failed",R)}}else if(Lt!==null&&cancelAnimationFrame(Lt),xn(),E.type==="checkpoint")m(E.checkpointId??null);else if(E.type==="error"){const R=E;if(u(R.message),D="error",q=R.message,R.error_type==="auth_error"||R.code==="TOKEN_EXPIRED"||((Xe=R.message)==null?void 0:Xe.includes("token"))||((ze=R.message)==null?void 0:ze.includes("401"))||((Ze=R.message)==null?void 0:Ze.includes("unauthorized"))||((Be=R.message)==null?void 0:Be.includes("Unauthorized"))){console.error("[use-chat] Auth error detected:",R.message);try{(dt=N==null?void 0:N.onAuthError)==null||dt.call(N,R.message)}catch(se){console.warn("[use-chat] onAuthError handler failed",se)}$.abort()}}}}xn(),D===null&&!$.signal.aborted&&(D="complete")}catch(Ue){if(Ue.name==="AbortError")D=D??"aborted";else{const st=Ue.message||String(Ue);D="error",q=st,u(st),(at=N==null?void 0:N.onError)==null||at.call(N,st)}}finally{try{await ht.cancel()}catch{}finally{(ct=ht.releaseLock)==null||ct.call(ht)}Lt!==null&&typeof window<"u"&&window.cancelAnimationFrame(Lt),clearInterval($n)}}catch(qe){if(qe.name==="AbortError")D=D??"aborted";else{const Qe=qe.message||String(qe);D="error",q=Qe,u(Qe),(ft=N==null?void 0:N.onError)==null||ft.call(N,Qe),U||((tt=N==null?void 0:N.onConnectionError)==null||tt.call(N,Qe),U=!0)}}finally{const qe=L.current,Qe=B.current,De=O.current,Le=G.current,et=D??($.signal.aborted?"aborted":q?"error":"complete");try{(nt=N==null?void 0:N.onClosed)==null||nt.call(N,{reason:et,lastSeq:qe,lastCheckpointId:Qe,lastCheckpointNs:De,lastStateHistory:Le,error:q}),et==="complete"&&((ut=N==null?void 0:N.onFinish)==null||ut.call(N,{lastSeq:qe,lastCheckpointId:Qe,lastCheckpointNs:De,lastStateHistory:Le}))}catch(ht){console.warn("[use-chat] onClosed callback failed",ht)}c(!1),w(!1),j.current=null,L.current=0,x(0),F.current=null}})(),{close:()=>$.abort()}},[t,n,r,e.autoAppendAssistant]);return v.useEffect(()=>()=>{var K;_.current=!1,(K=j.current)==null||K.abort()},[]),{isStreaming:a,error:l,assistantText:f,activeMessageId:S,streamedMessages:k,lastCheckpointId:p,lastSeq:g,connected:y,stream:ne,stop:W,clear:H,setToken:re,values:T,interrupt:()=>Promise.resolve(),resume:()=>Promise.resolve(),goto:()=>Promise.resolve()}}const pg=["detail","message","error","description","title"];function Mo(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=Mo(t);if(n)return n}return null}if(typeof e=="object"){const t=e;for(const n of pg){const r=Mo(t[n]);if(r)return r}if("errors"in t){const n=Mo(t.errors);if(n)return n}}return null}function mg(e){if(!e)return"Request failed";const t=e.response,n=Mo(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 uc({api:e,initialThreadId:t=null,onError:n,onThreadChange:r,onCurrentThreadDeleted:o}){const[s,i]=v.useState([]),[a,c]=v.useState(t),[l,u]=v.useState(!1),[f,h]=v.useState(null),[p,m]=v.useState([]),[g,x]=v.useState(!1),[,y]=v.useState(null),[w,k]=v.useState(null),[I,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&&c(t)},[t]);const A=v.useCallback(async()=>{u(!0),h(null);try{const H=await e.listThreads();i(H??[])}catch(H){const W=String(H);h(W),n==null||n(W)}finally{u(!1)}},[e,n]),j=v.useCallback(async()=>{x(!0),y(null);try{const H=await e.listSharedThreads();m(H??[])}catch(H){const W=String(H);y(W),n==null||n(W)}finally{x(!1)}},[e,n]);v.useEffect(()=>{A()},[A]),v.useEffect(()=>{j()},[j]),v.useEffect(()=>{r==null||r(a)},[a,r]);const _=v.useCallback(async(H,W)=>{try{const ne=W&&typeof W=="object"?{id:W.id,name:W.name??""}:void 0,K=await e.createThread(H,ne);return c(K.threadId),await A(),K.threadId}catch(ne){const K=String(ne);return n==null||n(K),null}},[e,n,A]),L=v.useCallback(async H=>{const W=s;i(K=>K.filter(M=>M.threadId!==H));const ne=new AbortController;T.current.set(H,ne);try{await e.deleteThread(H),C.current===H&&(c(null),o==null||o())}catch(K){i(W);const M=String(K);n==null||n(M)}finally{T.current.delete(H)}},[e,o,n,s]),F=v.useCallback(async(H,W)=>{try{await e.updateThread(H,W),await A()}catch(ne){n==null||n(String(ne))}},[e,n,A]),B=v.useCallback(async(H,W)=>{S(!0),k("Sharing thread…");try{await e.shareThread(H,W),await j(),k("Shared successfully")}catch(ne){const K=mg(ne);throw n==null||n(K),k(`Failed to share: ${K}`),new Error(K)}finally{S(!1)}},[e,n,j]),O=v.useCallback(async(H,W)=>{try{await e.unshareThread(H,W),await j()}catch(ne){const K=String(ne);throw n==null||n(K),ne}},[e,n,j]),G=v.useMemo(()=>({createThread:_,deleteThread:L,renameThread:F,refreshThreads:A,refreshSharedThreads:j,shareThread:B,unshareThread:O}),[_,L,F,A,j,B,O]),Y=v.useCallback(H=>{if(!(H!=null&&H.threadId))return;const W={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(ne=>{let K=!1;const M=ne.map(N=>N.threadId===W.threadId?(K=!0,console.debug("[useThreadsState] thread_info: updating existing thread",W.threadId),{...N,title:W.title??N.title,project:W.project??N.project,updatedAt:W.updatedAt??N.updatedAt,messageCount:W.messageCount??N.messageCount}):N);return K?M:(console.debug("[useThreadsState] thread_info: adding thread to list",W.threadId),[W,...ne])})},[]),re=v.useCallback(()=>k(null),[]);return{threads:s,currentThreadId:a,currentThreadIdRef:C,setCurrentThreadId:c,isLoadingThreads:l,threadsError:f,sharedThreads:p,isLoadingSharedThreads:g,actions:G,addThreadFromEvent:Y,shareInFlight:I,shareStatus:w,clearShareStatus:re}}const dc=v.createContext(null);function fc({children:e,initialThreadId:t=null,onError:n,onThreadChange:r}){const{chatApi:o}=hr(),{threads:s,currentThreadId:i,setCurrentThreadId:a,currentThreadIdRef:c,isLoadingThreads:l,threadsError:u,sharedThreads:f,isLoadingSharedThreads:h,actions:p,addThreadFromEvent:m,shareInFlight:g,shareStatus:x,clearShareStatus:y}=uc({api:o,initialThreadId:t,onError:n,onThreadChange:r}),w=v.useMemo(()=>({threads:s,currentThreadId:i,setCurrentThreadId:a,currentThreadIdRef:c,isLoading:l,error:u,sharedThreads:f,isLoadingSharedThreads:h,actions:p,shareInFlight:g,shareStatus:x,clearShareStatus:y,addThreadFromEvent:m}),[s,i,a,c,l,u,f,h,p,g,x,y,m]);return d.jsx(dc.Provider,{value:w,children:e})}function Vr(){const e=v.useContext(dc);if(!e)throw new Error("useThreads must be used within a ThreadsProvider");return e}function gg(e){return e.type==="text"}function xg(e){return e.type==="image_url"}function bg(e){return e.type==="file"}function yg(e){return e.type==="interrupt"}function wg(e){return e.content.filter(gg).map(t=>t.text).join(`
39
39
  `).trim()}function vg(e){return e.content.filter(xg)}function Sg(e){return e.content.filter(bg)}function ai(e){return Array.isArray(e.toolCalls)?e.toolCalls:[]}function Cg(e){return e.content.filter(yg)}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 hc(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function pc(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 li(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(li(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(li(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"&&ic(e)?{content:e,isMarkdown:!0}:{content:t,isMarkdown:!1}}function mc(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(`
40
- `)):t(e)}function _g(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 gc(e){const t=xr(e.value);return t===e.value?e:{...e,value:t}}function xc(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 jg(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 bc(e){return Array.isArray(e.toolCalls)&&e.toolCalls.length>0?e.toolCalls.map(jg).filter(t=>!!t):ai(e)}function ci(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 ui(e,t=[]){if(Array.isArray(e)){const o=e.filter(i=>i.role==="assistant").flatMap(i=>bc(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=ci(i.id,e)||ci(i.id,t),c=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,l=(a==null?void 0:a.artifact)??i.artifact,u=xc(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:c,artifact:l}})}if(e.role!=="assistant")return[];const n=bc(e);return n.length===0?[]:n.map(r=>{var c,l,u;const o=ci(r.id,t)??Pg(e,r),s=Array.isArray((c=o==null?void 0:o.additionalKwargs)==null?void 0:c.toolProgress)?(l=o==null?void 0:o.additionalKwargs)==null?void 0:l.toolProgress:void 0,i=(o==null?void 0:o.artifact)??r.artifact,a=xc(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 ui(e,t).map(n=>n.artifact).filter(n=>!!n)}function Mg(e,t){return t<e.length-1}function Lo(e){var s;const t=e.map(i=>Mo(i)).filter(Boolean),n=new Map;for(const i of t)if(i.role==="tool"){const a=i.toolCallId||Array.isArray(i.toolCalls)&&((s=i.toolCalls[0])==null?void 0:s.id)||i.tool_call_id;a&&n.set(a,i)}return t.map((i,a)=>{if(i.role!=="assistant"||!Array.isArray(i.toolCalls)||i.toolCalls.length===0)return i;const c=i.toolCalls.map(l=>{var w;const u=l.id||l.toolCallId||l.tool_call_id,f=u?n.get(u):void 0,h=f&&Array.isArray(f.content)?(w=f.content.find(k=>k.type==="text"))==null?void 0:w.text:typeof(f==null?void 0:f.content)=="string"?f==null?void 0:f.content:void 0;let p=(f==null?void 0:f.artifact)??l.artifact;if(!p&&l.args){const k=l.args;typeof k=="object"&&k!==null&&(k.type||k.question)&&(p=k)}const m=f?t.indexOf(f):-1,g=Math.max(a,m),y=Mg(t,g)?"completed":l.status==="failed"?"failed":"running";return{...l,id:u||l.id,status:y,content:h,artifact:p}});return{...i,toolCalls:c}}).filter(i=>{var p;if(!i)return!1;if(i.role!=="assistant")return!0;const a=i.content,c=typeof a=="string"?a.trim().length>0:Array.isArray(a)&&a.some(m=>{var g;return m&&m.type==="text"&&((g=m.text)==null?void 0:g.trim())}),l=Array.isArray(a)&&a.some(m=>m&&m.type==="image_url"),u=i.artifact!==null&&i.artifact!==void 0,f=((p=i.toolCalls)==null?void 0:p.length)>0,h=Array.isArray(a)&&a.some(m=>m&&["file","interrupt"].includes(m.type));return!!(c||l||u||f||h)})}function di(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 Dg(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 di(e,r,s)}return e}function Lg(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 $g={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,messagesStreamMeta:{},pendingInterrupt:null,values:{}};function Fg(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 yc(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>yc(o,s),e):e}default:return e}}function zg(e=[]){const[t,n]=v.useReducer(Fg,{...$g,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]),c=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 l=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:c}),[c]);return{state:t,dispatch:n,...l}}function yc(e,t){if(t.type==="tool.start")return Bg(e,t);if(t.type==="tool.progress")return Ug(e,t);if(t.type==="tool.end")return Hg(e,t);if(t.type==="artifact.update")return Wg(e,t);if(t.type==="checkpoint"){const n=t.checkpointNs??e.lastCheckpointNs??null,r=Dg(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=Lg(n.checkpoints);let i=s.length?s:o==null?void 0:o.messages;if(i){if(e.assemblingId&&!i.some(a=>a.id===e.assemblingId)){const a=e.messages.find(c=>c.id===e.assemblingId);a&&(i=[...i,a])}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.callId??e.id??void 0}function $o(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=$o(e,t);if(r===-1)return e;const o=e[r],s=(o.toolCalls??[]).map(i=>i.id===t?{...i,...n}:i);return di(e,r,{...o,toolCalls:s})}function Bg(e,t){const n=fi(t),r=t.name??t.tool??void 0,o={type:t.type,content:`Starting ${r??"tool"}...`,seq:t.seq??null,timestamp:new Date().toISOString()};let s=e.messages;return n&&$o(s,n)!==-1&&(s=hi(s,n,{status:"running",content:o.content})),{...e,messages:s}}function Ug(e,t){var i,a;const n=t.id??t.callId??((i=t.data)==null?void 0:i.id)??fi(t);if(!n)return e;const r=t.content??((a=t.data)==null?void 0:a.content)??(typeof t.data=="string"?t.data:void 0);let o=e.messages;return $o(o,n)!==-1&&(o=hi(o,n,{content:r})),{...e,messages:o}}function Hg(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&&$o(r,n)!==-1&&(r=hi(r,n,{status:"completed",content:a,artifact:t.artifact}));const c={id:`tool-${n||Date.now()}`,role:"tool",name:t.name??t.tool??void 0,content:[{type:"text",text:a}],artifact:t.artifact,toolCallId:n??void 0,createdAt:new Date().toISOString()};return{...e,messages:[...r,c]}}function Wg(e,t){const n=t.artifactId??t.artifact_id,r=t.toolCallId??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:di(e.messages,s,i)}}const wc=120;function Vg(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>wc?`${n.slice(0,wc-3)}…`:n:""}function Kg(e){return Vg(e.content)||""}function qg(e){const t=new Map,n=[],r=new Map,o=[];for(let l=0;l<e.length;l++){const u=e[l],f=u.checkpointId,h=f??`cp-${l}`,p=u.metadata??{},m=typeof p.step=="number"?p.step:null,g=typeof p.source=="string"?p.source:null;let x=null,y=null;const w=Array.isArray(u.messages)?u.messages:[];for(const C of w)C.role==="user"&&(y||(y=C),C.id&&(x=C.id));const k=u.next&&u.next.length>0?String(u.next[0]):null,I=u.parentConfig??null,S={id:h,step:m,source:g,createdAt:u.createdAt??null,namespace:u.checkpointNs??null,parentId:u.parentId??null,next:k,parentConfig:I,userMessageId:x};if(o.push(S),f&&t.set(f,S),f&&y){const C=Kg(y);C&&r.set(f,C)}n.push({id:h,messageId:x,step:m,source:g,createdAt:u.createdAt??null,next:k,parentConfig:I})}const s=new Map;for(const l of o){if(!l.userMessageId)continue;const u=s.get(l.userMessageId)??[];u.push(l),s.set(l.userMessageId,u)}for(const l of s.values()){if(!l.length)continue;l.sort((f,h)=>{const p=f.createdAt?Date.parse(f.createdAt):0;return(h.createdAt?Date.parse(h.createdAt):0)-p});const u=l.length;for(let f=0;f<l.length;f++){const h=l[f];h.attemptCount=u,h.attemptIndex=f,h.isLatestAttempt=f===0}}return{checkpoints:e,checkpointMetaByCheckpointId:t,timeline:n,messagePreviews:r,getLatest:()=>{const l=n[0];if(l)return t.get(l.id)},getCheckpoint:l=>t.get(l),getMessageAttempts:l=>{const u=[];for(const f of t.values())f.userMessageId===l&&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 Gg(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 Yg(e){return v.useMemo(()=>qg(e),[e])}function vc({api:e,seed:t,onError:n,currentThreadId:r,initialThreadId:o=null,initialCheckpointId:s=null,initialCheckpointNs:i=null,autoLoadInitial:a=!0,isStreaming:c,getMessages:l}){const[u,f]=v.useState(null),p=v.useMemo(()=>mr(u),[u]).checkpoints,m=Yg(p),g=m.timeline,[x,y]=v.useState(!1),[w,k]=v.useState(!1),[I,S]=v.useState(null),C=v.useRef(r),T=v.useRef(null),A=v.useRef(null),j=v.useRef(null),P=v.useRef(null),M=v.useRef(null),F=v.useRef(new Map),U=v.useRef(null);v.useEffect(()=>{C.current=r},[r]);const L=v.useCallback(async $=>{var G,ee;if(!$.threadId)return;const D=$.threadId;(G=$.onStart)==null||G.call($),$.setLoading(!0);try{await $.action(D)}catch(_){if(!Kl(_)&&C.current===D){const X=String(_);(ee=$.handleError)==null||ee.call($,X),n==null||n(X)}throw _}finally{$.setLoading(!1)}},[n]),K=v.useCallback(async($,D)=>{var X;if(!$)return;const G=`${$}:${D??"latest"}`,ee=F.current.get(G);if(ee)return ee;(X=U.current)==null||X.abort();const _=new AbortController;U.current=_;const B=L({threadId:$,setLoading:y,onStart:()=>S(null),handleError:le=>S(le),action:async le=>{const me=await e.getStateHistory({threadId:le,checkpointId:D??void 0,signal:_.signal});if(C.current!==le){console.log(`[useThreadHistoryState] Thread changed during load (was ${le}, now ${C.current}), discarding stale data`);return}const{checkpoints:be,latest:Te}=mr(me),Ae=D?be.find(ze=>ze.checkpointId===D)??Te:Te;t((Ae==null?void 0:Ae.messages)??[],{checkpointId:(Ae==null?void 0:Ae.checkpointId)??null,checkpointNs:(Ae==null?void 0:Ae.checkpointNs)??null,pendingInterrupt:(Ae==null?void 0:Ae.interrupt)??null}),f(me)}});F.current.set(G,B);try{await B}finally{F.current.delete(G),U.current===_&&(U.current=null)}return C.current===$&&(M.current=G),B},[e,t,L]),q=v.useCallback(async($,D)=>{P.current=$;try{await K($,D)}catch(G){if(!Kl(G))throw G}finally{P.current===$&&(P.current=null)}},[K]),re=v.useCallback($=>{A.current=$},[]),W=v.useCallback($=>{j.current=$},[]),V=v.useCallback($=>{const D=$.threadId??C.current;if(!D||C.current&&C.current!==D)return;const{checkpoints:G,latest:ee}=mr($);if(!G.length)return;const _=ee,B=j.current===D;!c&&!B&&t((_==null?void 0:_.messages)??[],{checkpointId:(_==null?void 0:_.checkpointId)??null,checkpointNs:(_==null?void 0:_.checkpointNs)??null,pendingInterrupt:(_==null?void 0:_.interrupt)??null}),f($),M.current=`${D}:latest`,A.current=null,j.current===D&&(j.current=null)},[t,c]),ne=v.useCallback(async($,D)=>{const G=C.current;await L({threadId:G,setLoading:k,action:async ee=>{const _=await e.getStateHistory({threadId:ee,checkpointId:$,checkpointNs:D??void 0});if(C.current!==ee)return;const{checkpoints:B}=mr(_),X=B.find(le=>le.checkpointId===$&&(D?le.checkpointNs===D:!0));if(!X){console.warn("[useThreadHistoryState] Requested checkpoint not found:",{checkpointId:$,checkpointNs:D});return}f(_),t(X.messages??[],{checkpointId:X.checkpointId??null,checkpointNs:X.checkpointNs??null})}}).catch(()=>{})},[e,t,L]),H=v.useCallback(($,D)=>{t(l(),{checkpointId:$??null,checkpointNs:D??null})},[l,t]),O=v.useCallback(async()=>{C.current&&await q(C.current)},[q]);v.useEffect(()=>{if(!a||!r||x||c)return;if(A.current===r){A.current=null,T.current=r;return}if(j.current===r){T.current=r;return}if(P.current===r){P.current=null,T.current=r;return}if(T.current===r)return;T.current=r;let $;const D=`${r}:latest`;M.current!==D&&q(r,$)},[a,r,s,i,o,x,c,q]);const N=v.useCallback(()=>{f(null),y(!1),k(!1),S(null),A.current=null,j.current=null,T.current=null,M.current=null,P.current=null},[]);return{threadCheckpoints:p,threadTimeline:g,checkpointIndex:m,isLoadingThread:x,isLoadingCheckpoint:w,threadStateError:I,loadThread:q,navigateToCheckpoint:ne,setCurrentCheckpointId:H,returnToLatest:O,handleStateHistoryEvent:V,markSkipNextLoad:re,markStreamPendingThread:W,resetHistoryState:N,clearState:N}}const Sc=v.createContext(null),Cc=v.createContext(null);function qr(){const e=v.useContext(Sc);if(!e)throw new Error("useThreadState must be used within a ThreadStateProvider");return e}function Tc(){const e=v.useContext(Cc);if(!e)throw new Error("useThreadStateUpdater must be used within a ThreadStateProvider");return e}function kc({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,isStreaming:s,onError:i}){const{chatApi:a}=hr(),{currentThreadId:c}=Vr(),{state:l,seed:u,onEvent:f,dispatch:h}=zg(),{threadCheckpoints:p,threadTimeline:m,checkpointIndex:g,isLoadingThread:x,isLoadingCheckpoint:y,threadStateError:w,loadThread:k,navigateToCheckpoint:I,setCurrentCheckpointId:S,returnToLatest:C,handleStateHistoryEvent:T,markSkipNextLoad:A,markStreamPendingThread:j,resetHistoryState:P}=vc({api:a,seed:u,onError:i,currentThreadId:c,initialThreadId:t,initialCheckpointId:n,initialCheckpointNs:r,autoLoadInitial:o,isStreaming:s,getMessages:v.useCallback(()=>l.messages,[l.messages])});v.useEffect(()=>{c||(u([],{}),P())},[c,u,P]);const M=v.useRef(null),F=v.useCallback(H=>{M.current=H},[]),U=v.useRef(null),L=v.useCallback(H=>{U.current=H},[]),K=v.useMemo(()=>({assemblingMessageId:l.assemblingId??null}),[l.assemblingId]),q=v.useCallback((H,O)=>{const N=oc(H,"user");return h({type:"user_message",payload:{message:N,editingMessageId:O==null?void 0:O.editingMessageId}}),N},[h]),re=v.useCallback(async()=>{M.current?await M.current():(u([],{}),P())},[u,P]),W=v.useMemo(()=>Tg(l.messages),[l.messages]),V=v.useMemo(()=>({threadId:c,messages:l.messages,interrupt:l.pendingInterrupt,checkpoint:{id:l.lastCheckpointId??null,namespace:l.lastCheckpointNs??null},checkpoints:p,checkpointIndex:g,timelineCheckpoints:m,metadata:K,values:l.values??{},isLoading:x,isLoadingCheckpoint:y,error:w,loadOlder:async()=>{},seedFromSnapshot:H=>{u(H.messages,{checkpointId:H.checkpointId,checkpointNs:H.checkpointNs,pendingInterrupt:H.interrupt})},clearState:re,navigateToCheckpoint:I,setCurrentCheckpointId:S,returnToLatest:C,loadThread:async(H,O,N)=>{await k(H,O,{clearProgress:!1})},clearThread:re,respondToInterrupt:async(H,O,N)=>{U.current&&await U.current(H,O,N)},messagePreviews:g.messagePreviews,handleStateHistoryEvent:T,markSkipNextLoad:A,markStreamPendingThread:j,resetHistoryState:P,pushUser:q,onEvent:f,artifacts:W}),[c,l.messages,l.pendingInterrupt,l.lastCheckpointId,l.lastCheckpointNs,l.values,p,m,g,K,x,y,w,u,re,I,S,C,k,T,A,j,q,f,W]),ne=v.useMemo(()=>({registerClearThread:F,registerRespondToInterrupt:L}),[F,L]);return d.jsx(Cc.Provider,{value:ne,children:d.jsx(Sc.Provider,{value:V,children:e})})}const Ec=v.createContext(null);function Ic({children:e,...t}){return d.jsx(Ec.Provider,{value:t,children:e})}function Fo(){const e=v.useContext(Ec);if(!e)throw new Error("useChatUI must be used within a ChatUIProvider");return e}function Ac(e,t){if(!e)return null;const n=Vn(e);if(!n)return null;const r=Vn(n.configurable)??n;return Hr(r,t)??null}function Xg(e){const t=Ac(e,["checkpoint_id","checkpointId"]);if(!t)return null;const n=Ac(e,["checkpoint_ns","checkpointNs"]);return{checkpointId:t,checkpointNs:n}}function Jg(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 Zg(e,t){const n=[...e].sort(Jg);for(const r of n){if(r.messageId!==t)continue;const o=Xg(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`)}const Nc=v.createContext(null),_c=v.createContext(!1);function Qg({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,onError:s,onAuthError:i,onThreadChange:a,onConnectionError:c,onToolEnd:l,onUpdateEvent:u,onCustomEvent:f,onMetadataEvent:h,onFinish:p}){const{chatApi:m,baseUrl:g}=hr(),x=g,{stream:y,stop:w,clear:k,isStreaming:I,error:S,connected:C,streamedMessages:T,activeMessageId:A}=hg({baseUrl:x}),[j,P]=v.useState(!1);return v.useEffect(()=>{P(I)},[I]),d.jsx(fc,{initialThreadId:t,onError:s,onThreadChange:a,children:d.jsx(kc,{initialThreadId:t,initialCheckpointId:n,initialCheckpointNs:r,autoLoadInitial:o,onError:s,isStreaming:j,children:d.jsx(_c.Provider,{value:!0,children:d.jsx(ex,{api:m,streamApi:{stream:y,stop:w,clear:k,isStreaming:I,error:S,connected:C,streamedMessages:T,activeMessageId:A},onError:s,onAuthError:i,onConnectionError:c,onToolEnd:l,onUpdateEvent:u,onCustomEvent:f,onMetadataEvent:h,onFinish:p,children:e})})})})}function ex({children:e,api:t,streamApi:n,onError:r,onAuthError:o,onConnectionError:s,onToolEnd:i,onUpdateEvent:a,onCustomEvent:c,onMetadataEvent:l,onFinish:u}){const{stream:f,stop:h,clear:p,isStreaming:m,error:g,connected:x,streamedMessages:y,activeMessageId:w}=n,{setCurrentThreadId:k,currentThreadIdRef:I,addThreadFromEvent:S,currentThreadId:C}=Vr();v.useEffect(()=>{C!==void 0&&p()},[C,p]);const{interrupt:T,checkpoint:A,timelineCheckpoints:j,handleStateHistoryEvent:P,markSkipNextLoad:M,markStreamPendingThread:F,resetHistoryState:U,pushUser:L,onEvent:K,messages:q}=qr(),{registerClearThread:re,registerRespondToInterrupt:W}=Tc(),V=v.useCallback(_=>{S(_),I.current!==_.threadId&&((_.created??!I.current)&&M(_.threadId),F(_.threadId),k(_.threadId))},[S,M,F,k,I]),ne=v.useCallback(_=>{_.type==="thread_info"?V(_):_.type==="state_history"?P(_):_.type==="tool.end"?(K(_),i==null||i(_)):K(_)},[V,P,K,i]),H=v.useCallback((_,B)=>{f(_,X=>{ne(X),B==null||B(X)},{onError:X=>{console.error("[StreamingProvider] Stream error:",X),r==null||r(X)},onAuthError:X=>{console.error("[StreamingProvider] Auth error:",X),o==null||o(X)},onConnectionError:X=>{console.error("[StreamingProvider] Connection error:",X),s==null||s(X)},onUpdateEvent:a,onCustomEvent:c,onMetadataEvent:l,onFinish:u})},[f,ne,r,o,s,a,c,l,u]),O=v.useRef(A);v.useEffect(()=>{O.current=A},[A]);const N=v.useCallback(async(_,B,X)=>{const le=I.current;if(!le)throw new Error("No active thread to handle interrupt");const me=_?B??!0:!1,be=O.current,Te={threadId:le,checkpointId:be.id??void 0,checkpointNs:be.namespace??void 0,command:{kind:"resume",value:me},payload:X==null?void 0:X.payload};H(Te)},[I,H]);v.useEffect(()=>{W(N)},[N,W]);const $=v.useCallback(async()=>{h(),p(),U(),k(null)},[p,U,k,h]);v.useEffect(()=>{re($)},[$,re]);const D=v.useCallback(async(_,B)=>{m&&h();let X=I.current;const le=(_==null?void 0:_.text)??"",me=(_==null?void 0:_.attachments)??[],be=(le==null?void 0:le.trim())??"",Te={...(_==null?void 0:_.payload)??{}},Ae=Array.isArray(Te.messages)?Te.messages:void 0;Ae&&delete Te.messages;const ze=!!(Ae&&Ae.length),Ze=!!(_.contentParts&&_.contentParts.length>0);if(!X&&!be&&me.length===0&&!ze&&!Ze)return;if(!X){const We=Math.floor(Date.now()/1e3).toString(16).padStart(8,"0"),ft=Array.from({length:4},()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0")).join("").slice(0,16);X=`${We}${ft}`,M(X),k(X)}let Ye=null;_.contentParts&&_.contentParts.length>0&&(Ye=_.contentParts);const{contentParts:Ve,filesInfo:dt}=Ye?{contentParts:Ye,filesInfo:[]}:await rc(me),lt=[...Ve];be&&lt.push({type:"text",text:le});const nt=B==null?void 0:B.originalMessageId,it=!!(B!=null&&B.edit&&nt),ct=!ze&&lt.length>0;let Ke=null;if(ct){const We=it?nt:`msg-${Date.now()}`;Ke=oc({id:We,role:"user",content:lt,createdAt:new Date().toISOString()},"user"),it?L(Ke,{editingMessageId:nt}):L(Ke)}const $e=ze?Ae:Ke?[Ke]:[],je={...Te,...dt.length?{files_info:dt}:{}};$e.length?je.messages=$e:"messages"in je||(je.messages=[]);let rt=(B==null?void 0:B.checkpointId)??A.id??void 0,ut=(B==null?void 0:B.checkpointNs)??A.namespace??void 0;if(it&&nt){const We=Zg(j,nt);rt=We.checkpointId,ut=We.checkpointNs??void 0}const Tt={threadId:X,payload:je,checkpointId:rt,checkpointNs:ut,config:B==null?void 0:B.config,edit:!!(B!=null&&B.edit)};H(Tt,B==null?void 0:B.onEvent)},[A,I,m,M,L,H,h,j]),G=v.useMemo(()=>{if(!m||!w)return q;const _=y==null?void 0:y[w];if(!_)return q;const B=q.findIndex(le=>le.id===w);if(B<0)return[...q,_];const X=[...q];return X[B]=_,X},[w,m,y,q]),ee=v.useMemo(()=>({isStreaming:m,error:g,connectionState:g?"error":m?x?"connected":"connecting":"idle",messages:G,submit:D,stop:h,interrupt:T,resume:()=>Promise.resolve(),goto:(_,B)=>Promise.resolve(),clearError:()=>{}}),[m,g,D,h,T,x,G]);return d.jsx(Nc.Provider,{value:ee,children:e})}function pi(){const e=v.useContext(Nc);if(!e)throw new Error("useStream must be used within StreamingProvider");return e}function tx(){return v.useContext(_c)}function jc(e){return typeof e=="object"&&e!==null}function nx(e,t){if(Object.is(e,t))return!0;if(!jc(e)||!jc(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 Pc(e){const t=v.useRef(e),n=v.useRef(e);return nx(t.current,e)||(t.current=e,n.current=e),n.current}function Rc(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 rx(e){const{setCurrentTaskId:t,getCurrentTaskId:n,onToolEnd:r}=e;return o=>{const s=Rc(o),i=(n==null?void 0:n())??null;s&&s!==i&&t(s),r==null||r(o)}}function Gr({children:e,apiConfig:t,initialThreadId:n=null,initialCheckpointId:r=null,initialCheckpointNs:o=null,autoLoadInitial:s=!0,onConnectionError:i,onError:a,onAuthError:c,onThreadChange:l,onToolEnd:u,onUpdateEvent:f,onCustomEvent:h,onMetadataEvent:p,onFinish:m}){const g=Pc(t),x=hn(a),y=hn(c),w=hn(i),k=hn(l),I=hn(u),S=hn(f),C=hn(h),T=hn(p),A=hn(m),j=v.useMemo(()=>({initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:x,onAuthError:y,onConnectionError:w,onThreadChange:k,onToolEnd:I,onUpdateEvent:S,onCustomEvent:C,onMetadataEvent:T,onFinish:A}),[n,r,o,s]);return d.jsx(tc,{apiConfig:g,children:d.jsx(Qg,{...j,children:e})})}function hn(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 Mc(){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 Oc(){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 Dc(...e){for(const t of e)if(typeof t=="string"&&t.trim())return t.trim().replace(/\/+$/,"");return""}function Lc(){const e={},t=Mc(),n=Oc();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function $c(){const e=Lc(),t=Cn.getAuthToken(),n=Mc();return{apiBaseUrl:Dc(e.baseUrl,n),apiKey:t||e.apiKey||Oc()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const mi=vn.chatSettings;function Fc(){try{const e=localStorage.getItem(mi);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function zc(e){try{const t={...e,apiBaseUrl:e.apiBaseUrl.trim().replace(/\/+$/,"")};localStorage.setItem(mi,JSON.stringify(t)),t.apiKey&&Cn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function ox(){const e=$c(),t=Fc(),n=Cn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Dc(Cn.baseUrl,r,e.apiBaseUrl)}}function sx(e){Cn.updateConfig({baseUrl:e.apiBaseUrl,apiKey:e.apiKey??void 0}),zc(e)}function he(...e){return Bn.twMerge(kt.clsx(e))}const ix=Ap.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"}}),Qe=b.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?cr.Slot:"button";return d.jsx(i,{className:he(ix({variant:t,size:n,className:e})),ref:s,...o})});Qe.displayName="Button";const zo=0,kn=1,yr=2,Bc=4;function Uc(e){return()=>e}function ax(e){e()}function Hc(e,t){return n=>e(t(n))}function Wc(e,t){return()=>e(t)}function lx(e,t){return n=>e(t,n)}function gi(e){return e!==void 0}function cx(...e){return()=>{e.map(ax)}}function wr(){}function Bo(e,t){return t(e),e}function ux(e,t){return t(e)}function qe(...e){return e}function Le(e,t){return e(kn,t)}function ke(e,t){e(zo,t)}function xi(e){e(yr)}function tt(e){return e(Bc)}function fe(e,t){return Le(e,lx(t,zo))}function Wt(e,t){const n=e(kn,r=>{n(),t(r)});return n}function Vc(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Kc(e,t){return e===t}function Ge(e=Kc){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=>Hc(t,e)}function Zt(e){return t=>()=>{t(e)}}function Q(e,...t){const n=dx(...t);return(r,o)=>{switch(r){case yr:xi(e);return;case kn:return Le(e,n(o))}}}function Qt(e,t){return n=>r=>{n(t=e(t,r))}}function Kn(e){return t=>n=>{e>0?e--:t(n)}}function pn(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Ie(...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);Le(s,c=>{const l=n;n=n|a,t[i]=c,l!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function dx(...e){return t=>e.reduceRight(ux,t)}function fx(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case kn:return s?n===s?void 0:(r(),n=s,t=Le(e,s),t):(r(),wr);case yr:r(),n=null;return}}}function te(e){let t=e;const n=_e();return(r,o)=>{switch(r){case zo:t=o;break;case kn:{o(t);break}case Bc:return t}return n(r,o)}}function gt(e,t){return Bo(te(t),n=>fe(e,n))}function _e(){const e=[];return(t,n)=>{switch(t){case zo:e.slice().forEach(r=>{r(n)});return;case yr:e.splice(0,e.length);return;case kn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function jt(e){return Bo(_e(),t=>fe(e,t))}function De(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:hx(),singleton:n}}const hx=()=>Symbol();function px(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(c=>n(c)));return i&&t.set(s,a),a};return n(e)}function st(...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);Le(s,c=>{n[i]=c,r=r|a,r===o&&ke(t,n)})}),function(s,i){switch(s){case yr:{xi(t);return}case kn:return r===o&&i(n),Le(t,i)}}}function ye(e,t=Kc){return Q(e,Ge(t))}function bi(...e){return function(t,n){switch(t){case yr:return;case kn:return cx(...e.map(r=>Le(r,n)))}}}var Nt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Nt||{});const mx={0:"debug",3:"error",1:"log",2:"warn"},gx=()=>typeof globalThis>"u"?window:globalThis,En=De(()=>{const e=te(3);return{log:te((t,n,r=1)=>{var o;const s=(o=gx().VIRTUOSO_LOG_LEVEL)!=null?o:tt(e);r>=s&&console[mx[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function qn(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 c=i[0].target;c.offsetParent!==null&&e(c)};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 xx(e,t,n,r,o,s,i,a,c){const l=v.useCallback(u=>{const f=bx(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 g=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,x=i?a?i.scrollWidth:i.scrollHeight:p?a?m.document.documentElement.scrollWidth:m.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,y=i?a?i.offsetWidth:i.offsetHeight:p?a?m.innerWidth:m.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:x,scrollTop:Math.max(g,0),viewportHeight:y}),s==null||s(a?qc("column-gap",getComputedStyle(u).columnGap,o):qc("row-gap",getComputedStyle(u).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return yi(l,n,c)}function bx(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 c=parseInt(a.dataset.index),l=parseFloat(a.dataset.knownSize),u=t(a,n);if(u===0&&r("Zero-sized element, this should not happen",{child:a},Nt.ERROR),u===l)continue;const f=s[s.length-1];s.length===0||f.size!==u||f.endIndex!==c-1?s.push({endIndex:c,size:u,startIndex:c}):s[s.length-1].endIndex++}return s}function qc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Nt.WARN),t==="normal"?0:parseInt(t??"0",10)}function Gc(e,t,n){const r=v.useRef(null),o=v.useCallback(c=>{if(!(c!=null&&c.offsetParent))return;const l=c.getBoundingClientRect(),u=l.width;let f,h;if(t){const p=t.getBoundingClientRect(),m=l.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,l.top),f=l.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 c;if(t){t.addEventListener("scroll",a);const l=new ResizeObserver(()=>{requestAnimationFrame(a)});return l.observe(t),()=>{t.removeEventListener("scroll",a),l.unobserve(t)}}else{const l=(c=i.current)==null?void 0:c.ownerDocument.defaultView;return l==null||l.addEventListener("scroll",a),l==null||l.addEventListener("resize",a),()=>{l==null||l.removeEventListener("scroll",a),l==null||l.removeEventListener("resize",a)}}},[a,t,i]),s}const St=De(()=>{const e=_e(),t=_e(),n=te(0),r=_e(),o=te(0),s=_e(),i=_e(),a=te(0),c=te(0),l=te(0),u=te(0),f=_e(),h=_e(),p=te(!1),m=te(!1),g=te(!1);return fe(Q(e,ae(({scrollTop:x})=>x)),t),fe(Q(e,ae(({scrollHeight:x})=>x)),i),fe(t,o),{deviation:n,fixedFooterHeight:l,fixedHeaderHeight:c,footerHeight:u,headerHeight:a,horizontalDirection:m,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:g,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Yr={lvl:0};function Yc(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:c}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=c}return s.push({end:1/0,start:r,value:o}),s}function Ue(e){return e===Yr}function Xr(e,t){if(!Ue(e))return t===e.k?e.v:t<e.k?Xr(e.l,t):Xr(e.r,t)}function Vt(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=Vt(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return Vt(e.l,t,n)}function Pt(e,t,n){return Ue(e)?Zc(t,n,1):t===e.k?at(e,{k:t,v:n}):t<e.k?Qc(at(e,{l:Pt(e.l,t,n)})):Qc(at(e,{r:Pt(e.r,t,n)}))}function vr(){return Yr}function Uo(e,t,n){if(Ue(e))return[];const r=Vt(e,t)[0];return yx(vi(e,r,n))}function wi(e,t){if(Ue(e))return Yr;const{k:n,l:r,r:o}=e;if(t===n){if(Ue(r))return o;if(Ue(o))return r;{const[s,i]=Jc(r);return Ho(at(e,{k:s,l:Xc(r),v:i}))}}else return t<n?Ho(at(e,{l:wi(r,t)})):Ho(at(e,{r:wi(o,t)}))}function Gn(e){return Ue(e)?[]:[...Gn(e.l),{k:e.k,v:e.v},...Gn(e.r)]}function vi(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(vi(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(vi(s,t,n))),a}function Ho(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(Si(t))return eu(at(e,{lvl:n-1}));if(!Ue(t)&&!Ue(t.r))return at(t.r,{l:at(t,{r:t.r.l}),lvl:n,r:at(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(Si(e))return Ci(at(e,{lvl:n-1}));if(!Ue(r)&&!Ue(r.l)){const o=r.l,s=Si(o)?r.lvl-1:r.lvl;return at(o,{l:at(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:Ci(at(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function at(e,t){return Zc(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 Xc(e){return Ue(e.r)?e.l:Ho(at(e,{r:Xc(e.r)}))}function Si(e){return Ue(e)||e.lvl>e.r.lvl}function Jc(e){return Ue(e.r)?[e.k,e.v]:Jc(e.r)}function Zc(e,t,n,r=Yr,o=Yr){return{k:e,l:r,lvl:n,r:o,v:t}}function Qc(e){return Ci(eu(e))}function eu(e){const{l:t}=e;return!Ue(t)&&t.lvl===e.lvl?at(t,{r:at(e,{l:t.r})}):e}function Ci(e){const{lvl:t,r:n}=e;return!Ue(n)&&!Ue(n.r)&&n.lvl===t&&n.r.lvl===t?at(n,{l:at(e,{r:n.l}),lvl:t+1}):e}function yx(e){return Yc(e,({k:t,v:n})=>({index:t,value:n}))}function tu(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 Ti=De(()=>({recalcInProgress:te(!1)}),[],{singleton:!0});function nu(e,t,n){return e[Wo(e,t,n)]}function Wo(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 wx(e,t,n,r){const o=Wo(e,t,r),s=Wo(e,n,r,o);return e.slice(o,s+1)}function In(e,t){return Math.round(e.getBoundingClientRect()[t])}function Vo(e){return!Ue(e.groupOffsetTree)}function ki({index:e},t){return t===e?0:t<e?-1:1}function vx(){return{groupIndices:[],groupOffsetTree:vr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:vr()}}function Sx(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=Uo(e,i-1,o+1);if(a.some(Nx(r)))continue;let c=!1,l=!1;for(const{end:u,start:f,value:h}of a)c?(o>=f||s===h)&&(e=wi(e,f)):(l=h!==s,c=!0),u>o&&o>=f&&h!==s&&(e=Pt(e,o+1,h));l&&(e=Pt(e,i,s))}return[e,n]}function Cx(e){return typeof e.groupIndex<"u"}function Tx({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}=nu(t,e,ki),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function ru(e,t){if(!Vo(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function ou(e,t,n){if(Cx(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=ru(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function kx(e,t,n,r=0){return r>0&&(t=Math.max(t,nu(e,r,ki).offset)),Yc(wx(e,t,n,Tx),Ax)}function Ex(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Nt.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,g)=>Pt(Pt(m,g,h),g+1,p),i)}else[i,a]=Sx(i,t);if(i===s)return e;const{lastIndex:c,lastOffset:l,lastSize:u,offsetTree:f}=Ei(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>Pt(h,p,Zr(p,f,o)),vr()),lastIndex:c,lastOffset:l,lastSize:u,offsetTree:f,sizeTree:i}}function Ix(e){return Gn(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 su(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 Ei(e,t,n,r){let o=e,s=0,i=0,a=0,c=0;if(t!==0){c=Wo(o,t-1,ki),a=o[c].offset;const l=Vt(n,t-1);s=l[0],i=l[1],o.length&&o[c].size===Vt(n,t)[1]&&(c-=1),o=o.slice(0,c+1)}else o=[];for(const{start:l,value:u}of Uo(n,t,1/0)){const f=l-s,h=f*i+a+f*r;o.push({index:l,offset:h,size:u}),s=l,a=h,i=u}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function Ax(e){return{index:e.index,value:e}}function Nx(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 _x={offsetHeight:"height",offsetWidth:"width"},en=De(([{log:e},{recalcInProgress:t}])=>{const n=_e(),r=_e(),o=gt(r,0),s=_e(),i=_e(),a=te(0),c=te([]),l=te(void 0),u=te(void 0),f=te((S,C)=>In(S,_x[C])),h=te(void 0),p=te(0),m=vx(),g=gt(Q(n,Ie(c,e,p),Qt(Ex,m),Ge()),m),x=gt(Q(c,Ge(),Qt((S,C)=>({current:C,prev:S.current}),{current:[],prev:[]}),ae(({prev:S})=>S)),[]);fe(Q(c,we(S=>S.length>0),Ie(g,p),ae(([S,C,T])=>{const A=S.reduce((j,P,M)=>Pt(j,P,Zr(P,C.offsetTree,T)||M),vr());return{...C,groupIndices:S,groupOffsetTree:A}})),g),fe(Q(r,Ie(g),we(([S,{lastIndex:C}])=>S<C),ae(([S,{lastIndex:C,lastSize:T}])=>[{endIndex:C,size:T,startIndex:S}])),n),fe(l,u);const y=gt(Q(l,ae(S=>S===void 0)),!0);fe(Q(u,we(S=>S!==void 0&&Ue(tt(g).sizeTree)),ae(S=>[{endIndex:0,size:S,startIndex:0}])),n);const w=jt(Q(n,Ie(g),Qt(({sizes:S},[C,T])=>({changed:T!==S,sizes:T}),{changed:!1,sizes:m}),ae(S=>S.changed)));Le(Q(a,Qt((S,C)=>({diff:S.prev-C,prev:C}),{diff:0,prev:0}),ae(S=>S.diff)),S=>{const{groupIndices:C}=tt(g);if(S>0)ke(t,!0),ke(s,S+su(S,C));else if(S<0){const T=tt(x);T.length>0&&(S-=su(-S,T)),ke(i,S)}}),Le(Q(a,Ie(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},Nt.ERROR)});const k=jt(s);fe(Q(s,Ie(g),ae(([S,C])=>{const T=C.groupIndices.length>0,A=[],j=C.lastSize;if(T){const P=Xr(C.sizeTree,0);let M=0,F=0;for(;M<S;){const L=C.groupIndices[F],K=C.groupIndices.length===F+1?1/0:C.groupIndices[F+1]-L-1;A.push({endIndex:L,size:P,startIndex:L}),A.push({endIndex:L+1+K-1,size:j,startIndex:L+1}),F++,M+=K+1}const U=Gn(C.sizeTree);return M!==S&&U.shift(),U.reduce((L,{k:K,v:q})=>{let re=L.ranges;return L.prevSize!==0&&(re=[...L.ranges,{endIndex:K+S-1,size:L.prevSize,startIndex:L.prevIndex}]),{prevIndex:K+S,prevSize:q,ranges:re}},{prevIndex:S,prevSize:0,ranges:A}).ranges}return Gn(C.sizeTree).reduce((P,{k:M,v:F})=>({prevIndex:M+S,prevSize:F,ranges:[...P.ranges,{endIndex:M+S-1,size:P.prevSize,startIndex:P.prevIndex}]}),{prevIndex:0,prevSize:j,ranges:[]}).ranges})),n);const I=jt(Q(i,Ie(g,p),ae(([S,{offsetTree:C},T])=>{const A=-S;return Zr(A,C,T)})));return fe(Q(i,Ie(g,p),ae(([S,C,T])=>{if(C.groupIndices.length>0){if(Ue(C.sizeTree))return C;let A=vr();const j=tt(x);let P=0,M=0,F=0;for(;P<-S;){F=j[M];const U=j[M+1]-F-1;M++,P+=U+1}if(A=Gn(C.sizeTree).reduce((U,{k:L,v:K})=>Pt(U,Math.max(0,L+S),K),A),P!==-S){const U=Xr(C.sizeTree,F);A=Pt(A,0,U);const L=Vt(C.sizeTree,-S+1)[1];A=Pt(A,1,L)}return{...C,sizeTree:A,...Ei(C.offsetTree,0,A,T)}}else{const A=Gn(C.sizeTree).reduce((j,{k:P,v:M})=>Pt(j,Math.max(0,P+S),M),vr());return{...C,sizeTree:A,...Ei(C.offsetTree,0,A,T)}}})),g),{beforeUnshiftWith:k,data:h,defaultItemSize:u,firstItemIndex:a,fixedItemSize:l,gap:p,groupIndices:c,itemSize:f,listRefresh:w,shiftWith:i,shiftWithOffset:I,sizeRanges:n,sizes:g,statefulTotalCount:o,totalCount:r,trackItemSizes:y,unshiftWith:s}},qe(En,Ti),{singleton:!0});function jx(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const iu=De(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=_e(),i=_e(),a=jt(Q(s,ae(jx)));return fe(Q(a,ae(c=>c.totalCount)),n),fe(Q(a,ae(c=>c.groupIndices)),e),fe(Q(st(o,t,r),we(([c,l])=>Vo(l)),ae(([c,l,u])=>Vt(l.groupOffsetTree,Math.max(c-u,0),"v")[0]),Ge(),ae(c=>[c])),i),{groupCounts:s,topItemsIndexes:i}},qe(en,St)),An=De(([{log:e}])=>{const t=te(!1),n=jt(Q(t,we(r=>r),Ge()));return Le(t,r=>{r&&tt(e)("props updated",{},Nt.DEBUG)}),{didMount:n,propsReady:t}},qe(En),{singleton:!0}),Px=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function au(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Px)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Qr=De(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:c,scrollTo:l,smoothScrollTargetReached:u,viewportHeight:f},{log:h}])=>{const p=_e(),m=_e(),g=te(0);let x=null,y=null,w=null;function k(){x&&(x(),x=null),w&&(w(),w=null),y&&(clearTimeout(y),y=null),ke(c,!1)}return fe(Q(p,Ie(n,f,r,g,a,i,h),Ie(e,s,o),ae(([[I,S,C,T,A,j,P,M],F,U,L])=>{const K=au(I),{align:q,behavior:re,offset:W}=K,V=T-1,ne=ou(K,S,V);let H=Zr(ne,S.offsetTree,F)+j;q==="end"?(H+=U+Vt(S.sizeTree,ne)[1]-C+L,ne===V&&(H+=P)):q==="center"?H+=(U+Vt(S.sizeTree,ne)[1]-C+L)/2:H-=A,W&&(H+=W);const O=N=>{k(),N?(M("retrying to scroll to",{location:I},Nt.DEBUG),ke(p,I)):(ke(m,!0),M("list did not change, scroll successful",{},Nt.DEBUG))};if(k(),re==="smooth"){let N=!1;w=Le(t,$=>{N=N||$}),x=Wt(u,()=>{O(N)})}else x=Wt(Q(t,Rx(150)),O);return y=setTimeout(()=>{k()},1200),ke(c,!0),M("scrolling from index to",{behavior:re,index:ne,top:H},Nt.DEBUG),{behavior:re,top:H}})),l),{scrollTargetReached:m,scrollToIndex:p,topListHeight:g}},qe(en,St,En),{singleton:!0});function Rx(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function Ii(e,t){e==0?t():requestAnimationFrame(()=>{Ii(e-1,t)})}function Ai(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const eo=De(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=te(!0),c=te(0),l=te(!0);return fe(Q(i,Ie(c),we(([u,f])=>!!f),Zt(!1)),a),fe(Q(i,Ie(c),we(([u,f])=>!!f),Zt(!1)),l),Le(Q(st(t,i),Ie(a,n,e,l),we(([[,u],f,{sizeTree:h},p,m])=>u&&(!Ue(h)||gi(p))&&!f&&!m),Ie(c)),([,u])=>{Wt(o,()=>{ke(l,!0)}),Ii(4,()=>{Wt(r,()=>{ke(a,!0)}),ke(s,u)})}),{initialItemFinalLocationReached:l,initialTopMostItemIndex:c,scrolledToInitialItem:a}},qe(en,St,Qr,An),{singleton:!0});function lu(e,t){return Math.abs(e-t)<1.01}const to="up",no="down",Mx="none",Ox={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Dx=0,ro=De(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=te(!1),a=te(!0),c=_e(),l=_e(),u=te(4),f=te(Dx),h=gt(Q(bi(Q(ye(o),Kn(1),Zt(!0)),Q(ye(o),Kn(1),Zt(!1),Vc(100))),Ge()),!1),p=gt(Q(bi(Q(n,Zt(!0)),Q(n,Zt(!1),Vc(200))),Ge()),!1);fe(Q(st(ye(o),ye(f)),ae(([w,k])=>w<=k),Ge()),a),fe(Q(a,pn(50)),l);const m=jt(Q(st(r,ye(s),ye(t),ye(e),ye(u)),Qt((w,[{scrollHeight:k,scrollTop:I},S,C,T,A])=>{const j=I+S-k>-A,P={scrollHeight:k,scrollTop:I,viewportHeight:S};if(j){let F,U;return I>w.state.scrollTop?(F="SCROLLED_DOWN",U=w.state.scrollTop-I):(F="SIZE_DECREASED",U=w.state.scrollTop-I||w.scrollTopDelta),{atBottom:!0,atBottomBecause:F,scrollTopDelta:U,state:P}}let M;return P.scrollHeight>w.state.scrollHeight?M="SIZE_INCREASED":S<w.state.viewportHeight?M="VIEWPORT_HEIGHT_DECREASING":I<w.state.scrollTop?M="SCROLLING_UPWARDS":M="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:M,state:P}},Ox),Ge((w,k)=>w&&w.atBottom===k.atBottom))),g=gt(Q(r,Qt((w,{scrollHeight:k,scrollTop:I,viewportHeight:S})=>{if(lu(w.scrollHeight,k))return{changed:!1,jump:0,scrollHeight:k,scrollTop:I};{const C=k-(I+S)<1;return w.scrollTop!==I&&C?{changed:!0,jump:w.scrollTop-I,scrollHeight:k,scrollTop:I}:{changed:!0,jump:0,scrollHeight:k,scrollTop:I}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),we(w=>w.changed),ae(w=>w.jump)),0);fe(Q(m,ae(w=>w.atBottom)),i),fe(Q(i,pn(50)),c);const x=te(no);fe(Q(r,ae(({scrollTop:w})=>w),Ge(),Qt((w,k)=>tt(p)?{direction:w.direction,prevScrollTop:k}:{direction:k<w.prevScrollTop?to:no,prevScrollTop:k},{direction:no,prevScrollTop:0}),ae(w=>w.direction)),x),fe(Q(r,pn(50),Zt(Mx)),x);const y=te(0);return fe(Q(h,we(w=>!w),Zt(0)),y),fe(Q(o,pn(100),Ie(h),we(([w,k])=>!!k),Qt(([w,k],[I])=>[k,I],[0,0]),ae(([w,k])=>k-w)),y),{atBottomState:m,atBottomStateChange:c,atBottomThreshold:u,atTopStateChange:l,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:g,scrollDirection:x,scrollVelocity:y}},qe(St)),Ko="top",qo="bottom",cu="none";function uu(e,t,n){return typeof e=="number"?n===to&&t===Ko||n===no&&t===qo?e:0:n===to?t===Ko?e.main:e.reverse:t===qo?e.main:e.reverse}function du(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const Ni=De(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=_e(),i=te(0),a=te(0),c=te(0),l=gt(Q(st(ye(r),ye(o),ye(n),ye(s,Jr),ye(c),ye(i),ye(t),ye(e),ye(a)),ae(([u,f,h,[p,m],g,x,y,w,k])=>{const I=u-w,S=x+y,C=Math.max(h-I,0);let T=cu;const A=du(k,Ko),j=du(k,qo);return p-=w,p+=h+y,m+=h+y,m-=w,p>u+S-A&&(T=to),m<u-C+f+j&&(T=no),T!==cu?[Math.max(I-h-uu(g,Ko,T)-A,0),I-C-y+f+uu(g,qo,T)+j]:null}),we(u=>u!=null),Ge(Jr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:c,topListHeight:i,visibleRange:l}},qe(St),{singleton:!0});function Lx(e,t,n){if(Vo(t)){const r=ru(e,t);return[{index:Vt(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 Go(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:c}=o;let l=0,u=0;if(e.length>0){l=e[0].offset;const g=e[e.length-1];u=g.offset+g.size}const f=n-i,h=a+f*c+(f-1)*r,p=l,m=h-u;return{bottom:u,firstItemIndex:s,items:hu(e,o,s),offsetBottom:m,offsetTop:l,top:p,topItems:hu(t,o,s),topListHeight:t.reduce((g,x)=>x.size+g,0),totalCount:n}}function fu(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,c=Ai(t,a),l=Array.from({length:a}).map((u,f)=>({data:s[f+c],index:f+c,offset:0,size:0}));return Go(l,[],a,o,n,r)}function hu(e,t,n){if(e.length===0)return[];if(!Vo(t))return e.map(l=>({...l,index:l.index+n,originalIndex:l.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=Uo(t.groupOffsetTree,r,o);let a,c=0;for(const l of e){(!a||a.end<l.index)&&(a=i.shift(),c=t.groupIndices.indexOf(a.start));let u;l.index===a.start?u={index:c,type:"group"}:u={groupIndex:c,index:l.index-(c+1)+n},s.push({...u,data:l.data,offset:l.offset,originalIndex:l.index,size:l.size})}return s}const Yn=De(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:c},{initialTopMostItemIndex:l,scrolledToInitialItem:u},{topListHeight:f},h,{didMount:p},{recalcInProgress:m}])=>{const g=te([]),x=te(0),y=_e();fe(s.topItemsIndexes,g);const w=gt(Q(st(p,m,ye(c,Jr),ye(o),ye(r),ye(l),u,ye(g),ye(t),ye(n),e),we(([C,T,,A,,,,,,,j])=>{const P=j&&j.length!==A;return C&&!T&&!P}),ae(([,,[C,T],A,j,P,M,F,U,L,K])=>{const q=j,{offsetTree:re,sizeTree:W}=q,V=tt(x);if(A===0)return{..._i,totalCount:A};if(C===0&&T===0)return V===0?{..._i,totalCount:A}:fu(V,P,j,U,L,K||[]);if(Ue(W))return V>0?null:Go(Lx(Ai(P,A),q,K),[],A,L,q,U);const ne=[];if(F.length>0){const D=F[0],G=F[F.length-1];let ee=0;for(const _ of Uo(W,D,G)){const B=_.value,X=Math.max(_.start,D),le=Math.min(_.end,G);for(let me=X;me<=le;me++)ne.push({data:K==null?void 0:K[me],index:me,offset:ee,size:B}),ee+=B}}if(!M)return Go([],ne,A,L,q,U);const H=F.length>0?F[F.length-1]+1:0,O=kx(re,C,T,H);if(O.length===0)return null;const N=A-1,$=Bo([],D=>{for(const G of O){const ee=G.value;let _=ee.offset,B=G.start;const X=ee.size;if(ee.offset<C){B+=Math.floor((C-ee.offset+L)/(X+L));const me=B-G.start;_+=me*X+me*L}B<H&&(_+=(H-B)*X,B=H);const le=Math.min(G.end,N);for(let me=B;me<=le&&!(_>=T);me++)D.push({data:K==null?void 0:K[me],index:me,offset:_,size:X}),_+=X+L}});return Go($,ne,A,L,q,U)}),we(C=>C!==null),Ge()),_i);fe(Q(e,we(gi),ae(C=>C==null?void 0:C.length)),o),fe(Q(w,ae(C=>C.topListHeight)),f),fe(f,a),fe(Q(w,ae(C=>[C.top,C.bottom])),i),fe(Q(w,ae(C=>C.items)),y);const k=jt(Q(w,we(({items:C})=>C.length>0),Ie(o,e),we(([{items:C},T])=>C[C.length-1].originalIndex===T-1),ae(([,C,T])=>[C-1,T]),Ge(Jr),ae(([C])=>C))),I=jt(Q(w,pn(200),we(({items:C,topItems:T})=>C.length>0&&C[0].originalIndex===T.length),ae(({items:C})=>C[0].index),Ge())),S=jt(Q(w,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}}),Ge(tu)));return{endReached:k,initialItemCount:x,itemsRendered:y,listState:w,rangeChanged:S,startReached:I,topItemsIndexes:g,...h}},qe(en,iu,Ni,eo,Qr,ro,An,Ti),{singleton:!0}),pu=De(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=_e(),i=gt(Q(st(n,e,r,t,o),ae(([a,c,l,u,f])=>a+c+l+u+f.offsetBottom+f.bottom)),0);return fe(ye(i),s),{totalListHeight:i,totalListHeightChanged:s}},qe(St,Yn),{singleton:!0}),$x=De(([{viewportHeight:e},{totalListHeight:t}])=>{const n=te(!1),r=gt(Q(st(n,e,t),we(([o])=>o),ae(([,o,s])=>Math.max(0,o-s)),pn(0),Ge()),0);return{alignToBottom:n,paddingTopAddition:r}},qe(St,pu),{singleton:!0}),mu=De(()=>({context:te(null)})),Fx=({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,gu=De(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:c},{scrollToIndex:l}])=>{const u=_e();return fe(Q(u,Ie(t,c,n,s,o,r,a),Ie(e),ae(([[f,h,p,m,g,x,y,w],k])=>{const{align:I,behavior:S,calculateViewLocation:C=Fx,done:T,...A}=f,j=ou(f,h,m-1),P=Zr(j,h.offsetTree,k)+g+x,M=P+Vt(h.sizeTree,j)[1],F=w+x,U=w+p-y,L=C({itemBottom:M,itemTop:P,locationParams:{align:I,behavior:S,...A},viewportBottom:U,viewportTop:F});return L?T&&Wt(Q(i,we(K=>!K),Kn(tt(i)?1:2)),T):T&&T(),L}),we(f=>f!==null)),l),{scrollIntoView:u}},qe(en,St,Qr,Yn,En),{singleton:!0});function xu(e){return e?e==="smooth"?"smooth":"auto":!1}const zx=(e,t)=>typeof e=="function"?xu(e(t)):t&&xu(e),Bx=De(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:c,propsReady:l},{log:u},{scrollingInProgress:f},{context:h},{scrollIntoView:p}])=>{const m=te(!1),g=_e();let x=null;function y(S){ke(i,{align:"end",behavior:S,index:"LAST"})}Le(Q(st(Q(ye(t),Kn(1)),c),Ie(ye(m),s,a,f),ae(([[S,C],T,A,j,P])=>{let M=C&&j,F="auto";return M&&(F=zx(T,A||P),M=M&&!!F),{followOutputBehavior:F,shouldFollow:M,totalCount:S}}),we(({shouldFollow:S})=>S)),({followOutputBehavior:S,totalCount:C})=>{x&&(x(),x=null),tt(n)?requestAnimationFrame(()=>{tt(u)("following output to ",{totalCount:C},Nt.DEBUG),y(S)}):x=Wt(e,()=>{tt(u)("following output to ",{totalCount:C},Nt.DEBUG),y(S),x=null})});function w(S){const C=Wt(o,T=>{S&&!T.atBottom&&T.notAtBottomBecause==="SIZE_INCREASED"&&!x&&(tt(u)("scrolling to bottom due to increased size",{},Nt.DEBUG),y("auto"))});setTimeout(C,100)}Le(Q(st(ye(m),t,l),we(([S,,C])=>S&&C),Qt(({value:S},[,C])=>({refreshed:S===C,value:C}),{refreshed:!1,value:0}),we(({refreshed:S})=>S),Ie(m,t)),([,S])=>{tt(a)&&w(S!==!1)}),Le(g,()=>{w(tt(m)!==!1)}),Le(st(ye(m),o),([S,C])=>{S&&!C.atBottom&&C.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&y("auto")});const k=te(null),I=_e();return fe(bi(Q(ye(r),ae(S=>{var C;return(C=S==null?void 0:S.length)!=null?C:0})),Q(ye(t))),I),Le(Q(st(Q(I,Kn(1)),c),Ie(ye(k),a,f,h),ae(([[S,C],T,A,j,P])=>C&&A&&(T==null?void 0:T({context:P,totalCount:S,scrollingInProgress:j}))),we(S=>!!S),pn(0)),S=>{x&&(x(),x=null),tt(n)?requestAnimationFrame(()=>{tt(u)("scrolling into view",{}),ke(p,S)}):x=Wt(e,()=>{tt(u)("scrolling into view",{}),ke(p,S),x=null})}),{autoscrollToBottom:g,followOutput:m,scrollIntoViewOnChange:k}},qe(en,ro,Qr,eo,An,En,St,mu,gu)),Ux=De(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(fe(Q(a,Ie(s),we(([,c])=>c!==0),Ie(o,r,t,n,e),ae(([[,c],l,u,f,h,p=[]])=>fu(c,l,u,f,h,p))),i),{}),qe(en,eo,Yn,An),{singleton:!0}),Hx=De(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=te(0);return Le(Q(e,Ie(r),we(([,o])=>o!==0),ae(([,o])=>({top:o}))),o=>{Wt(Q(n,Kn(1),we(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{ke(t,o)})})}),{initialScrollTop:r}},qe(An,St,Yn),{singleton:!0}),bu=De(([{scrollVelocity:e}])=>{const t=te(!1),n=_e(),r=te(!1);return fe(Q(e,Ie(r,t,n),we(([o,s])=>!!s),ae(([o,s,i,a])=>{const{enter:c,exit:l}=s;if(i){if(l(o,a))return!1}else if(c(o,a))return!0;return i}),Ge()),t),Le(Q(st(t,e,n),Ie(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},qe(ro),{singleton:!0}),ji=De(([{scrollContainerState:e,scrollTo:t}])=>{const n=_e(),r=_e(),o=_e(),s=te(!1),i=te(void 0);return fe(Q(st(n,r),ae(([{scrollHeight:a,scrollTop:c,viewportHeight:l},{offsetTop:u}])=>({scrollHeight:a,scrollTop:Math.max(0,c-u),viewportHeight:l}))),e),fe(Q(t,Ie(r),ae(([a,{offsetTop:c}])=>({...a,top:a.top+c}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},qe(St)),Wx=De(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:c}])=>{const l=_e(),u=te(void 0),f=te(null),h=te(null);return fe(a,f),fe(c,h),Le(Q(l,Ie(t,r,i,f,h,n)),([p,m,g,x,y,w,k])=>{const I=Ix(m.sizeTree);x&&y!==null&&w!==null&&(g=y.scrollTop-w.offsetTop),g-=k,p({ranges:I,scrollTop:g})}),fe(Q(u,we(gi),ae(Vx)),o),fe(Q(s,Ie(u),we(([,p])=>p!==void 0),Ge(),ae(([,p])=>p.ranges)),e),{getState:l,restoreStateFrom:u}},qe(en,St,eo,An,ji));function Vx(e){return{align:"start",index:0,offset:e.scrollTop}}const Kx=De(([{topItemsIndexes:e}])=>{const t=te(0);return fe(Q(t,we(n=>n>=0),ae(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},qe(Yn));function yu(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const qx=yu(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),Gx=De(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:c},{beforeUnshiftWith:l,gap:u,shiftWithOffset:f,sizes:h},{log:p},{recalcInProgress:m}])=>{const g=jt(Q(c,Ie(i),Qt(([,y,w,k],[{bottom:I,items:S,offsetBottom:C,totalCount:T},A])=>{const j=I+C;let P=0;return w===T&&y.length>0&&S.length>0&&(S[0].originalIndex===0&&y[0].originalIndex===0||(P=j-k,P!==0&&(P+=A))),[P,S,T,j]},[0,[],0,0]),we(([y])=>y!==0),Ie(r,a,n,o,p,m),we(([,y,w,k,,,I])=>!I&&!k&&y!==0&&w===to),ae(([[y],,,,,w])=>(w("Upward scrolling compensation",{amount:y},Nt.DEBUG),y))));function x(y){y>0?(ke(t,{behavior:"auto",top:-y}),ke(e,0)):(ke(e,0),ke(t,{behavior:"auto",top:-y}))}return Le(Q(g,Ie(e,s)),([y,w,k])=>{k&&qx()?ke(e,w-y):x(-y)}),Le(Q(st(gt(s,!1),e,m),we(([y,w,k])=>!y&&!k&&w!==0),ae(([y,w])=>w),pn(1)),x),fe(Q(f,ae(y=>({top:-y}))),t),Le(Q(l,Ie(h,u),ae(([y,{groupIndices:w,lastSize:k,sizeTree:I},S])=>{function C(T){return T*(k+S)}if(w.length===0)return C(y);{let T=0;const A=Xr(I,0);let j=0,P=0;for(;j<y;){j++,T+=A;let M=w.length===P+1?1/0:w[P+1]-w[P]-1;j+M>y&&(T-=A,M=y-j+1),j+=M,T+=C(M),P++}return T}})),y=>{ke(e,y),requestAnimationFrame(()=>{ke(t,{top:y}),requestAnimationFrame(()=>{ke(e,0),ke(m,!1)})})}),{deviation:e}},qe(St,ro,Yn,en,En,Ti)),Yx=De(([e,t,n,r,o,s,i,a,c,l,u])=>({...e,...t,...n,...r,...o,...s,...i,...a,...c,...l,...u}),qe(Ni,Ux,An,bu,pu,Hx,$x,ji,gu,En,mu)),wu=De(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:c,statefulTotalCount:l,totalCount:u,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:m},g,x,y,{listState:w,topItemsIndexes:k,...I},{scrollToIndex:S},C,{topItemCount:T},{groupCounts:A},j])=>(fe(I.rangeChanged,j.scrollSeekRangeChanged),fe(Q(j.windowViewportRect,ae(P=>P.visibleHeight)),g.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,...y,groupIndices:s,itemSize:i,listState:w,scrollToIndex:S,statefulTotalCount:l,trackItemSizes:f,...I,...j,...g,sizes:c,...x}),qe(en,eo,St,Wx,Bx,Yn,Qr,Gx,Kx,iu,Yx));function Xx(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 Yo=typeof document<"u"?v.useLayoutEffect:v.useEffect;function vu(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 c(x,y){x.propsReady&&ke(x.propsReady,!1);for(const w of r){const k=x[t.required[w]];ke(k,y[w])}for(const w of o)if(w in y){const k=x[t.optional[w]];ke(k,y[w])}x.propsReady&&ke(x.propsReady,!0)}function l(x){return s.reduce((y,w)=>(y[w]=k=>{const I=x[t.methods[w]];ke(I,k)},y),{})}function u(x){return i.reduce((y,w)=>(y[w]=fx(x[t.events[w]]),y),{})}const f=v.forwardRef((x,y)=>{const{children:w,...k}=x,[I]=v.useState(()=>Bo(px(e),T=>{c(T,k)})),[S]=v.useState(Wc(u,I));Yo(()=>{for(const T of i)T in k&&Le(S[T],k[T]);return()=>{Object.values(S).map(xi)}},[k,S,I]),Yo(()=>{c(I,k)}),v.useImperativeHandle(y,Uc(l(I)));const C=n;return d.jsx(a.Provider,{value:I,children:n?d.jsx(C,{...Xx([...r,...o,...i],k),children:w}):w})}),h=x=>{const y=v.useContext(a);return v.useCallback(w=>{ke(y[x],w)},[y,x])},p=x=>{const y=v.useContext(a)[x],w=v.useCallback(k=>Le(y,k),[y]);return v.useSyncExternalStore(w,()=>tt(y),()=>tt(y))},m=x=>{const y=v.useContext(a)[x],[w,k]=v.useState(Wc(tt,y));return Yo(()=>Le(y,I=>{I!==w&&k(Uc(I))}),[y,w]),w},g=v.version.startsWith("18")?p:m;return{Component:f,useEmitter:(x,y)=>{const w=v.useContext(a)[x];Yo(()=>Le(w,y),[y,w])},useEmitterValue:g,usePublisher:h}}const Su=v.createContext(void 0),Cu=v.createContext(void 0),Tu=typeof document<"u"?v.useLayoutEffect:v.useEffect;function Pi(e){return"self"in e}function Jx(e){return"body"in e}function ku(e,t,n,r=wr,o,s){const i=v.useRef(null),a=v.useRef(null),c=v.useRef(null),l=v.useCallback(h=>{let p,m,g;const x=h.target;if(Jx(x)||Pi(x)){const w=Pi(x)?x:x.defaultView;g=s?w.scrollX:w.scrollY,p=s?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight,m=s?w.innerWidth:w.innerHeight}else g=s?x.scrollLeft:x.scrollTop,p=s?x.scrollWidth:x.scrollHeight,m=s?x.offsetWidth:x.offsetHeight;const y=()=>{e({scrollHeight:p,scrollTop:Math.max(g,0),viewportHeight:m})};h.suppressFlushSync?y():Hs.flushSync(y),a.current!==null&&(g===a.current||g<=0||g===p-m)&&(a.current=null,t(!0),c.current&&(clearTimeout(c.current),c.current=null))},[e,t,s]);v.useEffect(()=>{const h=o||i.current;return r(o||i.current),l({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",l,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",l)}},[i,l,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 g,x,y;Pi(p)?(x=Math.max(In(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),g=s?p.innerWidth:p.innerHeight,y=s?window.scrollX:window.scrollY):(x=p[s?"scrollWidth":"scrollHeight"],g=In(p,s?"width":"height"),y=p[s?"scrollLeft":"scrollTop"]);const w=x-g;if(h.top=Math.ceil(Math.max(Math.min(w,h.top),0)),lu(g,x)||h.top===y){e({scrollHeight:x,scrollTop:y,viewportHeight:g}),m&&t(!0);return}m?(a.current=h.top,c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{c.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 Ri="-webkit-sticky",Eu="sticky",Mi=yu(()=>{if(typeof document>"u")return Eu;const e=document.createElement("div");return e.style.position=Ri,e.style.position===Ri?Ri:Eu});function Oi(e){return e}const Zx=De(()=>{const e=te(a=>`Item ${a}`),t=te(a=>`Group ${a}`),n=te({}),r=te(Oi),o=te("div"),s=te(wr),i=(a,c=null)=>gt(Q(n,ae(l=>l[a]),Ge()),c);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")}}),Qx=De(([e,t])=>({...e,...t}),qe(wu,Zx)),eb=({height:e})=>d.jsx("div",{style:{height:e}}),tb={overflowAnchor:"none",position:Mi(),zIndex:1},Iu={overflowAnchor:"none"},nb={...Iu,display:"inline-block",height:"100%"},Au=v.memo(function({showTopList:e=!1}){const t=Se("listState"),n=Ft("sizeRanges"),r=Se("useWindowScroll"),o=Se("customScrollParent"),s=Ft("windowScrollContainerState"),i=Ft("scrollContainerState"),a=o||r?s:i,c=Se("itemContent"),l=Se("context"),u=Se("groupContent"),f=Se("trackItemSizes"),h=Se("itemSize"),p=Se("log"),m=Ft("gap"),g=Se("horizontalDirection"),{callbackRef:x}=xx(n,h,f,e?wr:a,p,m,o,g,Se("skipAnimationFrameInResizeObserver")),[y,w]=v.useState(0);Di("deviation",L=>{y!==L&&w(L)});const k=Se("EmptyPlaceholder"),I=Se("ScrollSeekPlaceholder")||eb,S=Se("ListComponent"),C=Se("ItemComponent"),T=Se("GroupComponent"),A=Se("computeItemKey"),j=Se("isSeeking"),P=Se("groupIndices").length>0,M=Se("alignToBottom"),F=Se("initialItemFinalLocationReached"),U=e?{}:{boxSizing:"border-box",...g?{display:"inline-block",height:"100%",marginLeft:y!==0?y:M?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:y!==0?y:M?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...F?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&k?d.jsx(k,{...xt(k,l)}):d.jsx(S,{...xt(S,l),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:x,style:U,children:(e?t.topItems:t.items).map(L=>{const K=L.originalIndex,q=A(K+t.firstItemIndex,L.data,l);return j?v.createElement(I,{...xt(I,l),height:L.size,index:L.index,key:q,type:L.type||"item",...L.type==="group"?{}:{groupIndex:L.groupIndex}}):L.type==="group"?v.createElement(T,{...xt(T,l),"data-index":K,"data-item-index":L.index,"data-known-size":L.size,key:q,style:tb},u(L.index,l)):v.createElement(C,{...xt(C,l),...ib(C,L.data),"data-index":K,"data-item-group-index":L.groupIndex,"data-item-index":L.index,"data-known-size":L.size,key:q,style:g?nb:Iu},P?c(L.index,L.groupIndex,L.data,l):c(L.index,L.data,l))})})}),rb={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},ob={outline:"none",overflowX:"auto",position:"relative"},Xo=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),sb={position:Mi(),top:0,width:"100%",zIndex:1};function xt(e,t){if(typeof e!="string")return{context:t}}function ib(e,t){return{item:typeof e=="string"?void 0:t}}const ab=v.memo(function(){const e=Se("HeaderComponent"),t=Ft("headerHeight"),n=Se("HeaderFooterTag"),r=qn(v.useMemo(()=>s=>{t(In(s,"height"))},[t]),!0,Se("skipAnimationFrameInResizeObserver")),o=Se("context");return e?d.jsx(n,{ref:r,children:d.jsx(e,{...xt(e,o)})}):null}),lb=v.memo(function(){const e=Se("FooterComponent"),t=Ft("footerHeight"),n=Se("HeaderFooterTag"),r=qn(v.useMemo(()=>s=>{t(In(s,"height"))},[t]),!0,Se("skipAnimationFrameInResizeObserver")),o=Se("context");return e?d.jsx(n,{ref:r,children:d.jsx(e,{...xt(e,o)})}):null});function Nu({useEmitter:e,useEmitterValue:t,usePublisher:n}){return v.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),c=t("ScrollerComponent"),l=n("smoothScrollTargetReached"),u=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback:m}=ku(a,l,c,u,void 0,f);return e("scrollTo",m),e("scrollBy",h),d.jsx(c,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?ob:rb,...o},tabIndex:0,...i,...xt(c,s),children:r})})}function _u({useEmitter:e,useEmitterValue:t,usePublisher:n}){return v.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),c=t("ScrollerComponent"),l=n("smoothScrollTargetReached"),u=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),p=v.useRef(null),m=t("scrollerRef"),{scrollByCallback:g,scrollerRef:x,scrollToCallback:y}=ku(a,l,c,m,h);return Tu(()=>{var w;return x.current=h||((w=p.current)==null?void 0:w.ownerDocument.defaultView),()=>{x.current=null}},[x,h]),e("windowScrollTo",y),e("scrollBy",g),d.jsx(c,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...u!==0?{height:u+f}:{}},...i,...xt(c,s),children:r})})}const cb=({children:e})=>{const t=v.useContext(Su),n=Ft("viewportHeight"),r=Ft("fixedItemHeight"),o=Se("alignToBottom"),s=Se("horizontalDirection"),i=v.useMemo(()=>Hc(n,c=>In(c,s?"width":"height")),[n,s]),a=qn(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:Xo(o),children:e})},ub=({children:e})=>{const t=v.useContext(Su),n=Ft("windowViewportRect"),r=Ft("fixedItemHeight"),o=Se("customScrollParent"),s=Gc(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:Xo(i),children:e})},db=({children:e})=>{const t=Se("TopItemListComponent")||"div",n=Se("headerHeight"),r={...sb,marginTop:`${n}px`},o=Se("context");return d.jsx(t,{style:r,...xt(t,o),children:e})},fb=v.memo(function(e){const t=Se("useWindowScroll"),n=Se("topItemsIndexes").length>0,r=Se("customScrollParent"),o=Se("context");return d.jsxs(r||t?mb:pb,{...e,context:o,children:[n&&d.jsx(db,{children:d.jsx(Au,{showTopList:!0})}),d.jsxs(r||t?ub:cb,{children:[d.jsx(ab,{}),d.jsx(Au,{}),d.jsx(lb,{})]})]})}),{Component:hb,useEmitter:Di,useEmitterValue:Se,usePublisher:Ft}=vu(Qx,{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"}},fb),pb=Nu({useEmitter:Di,useEmitterValue:Se,usePublisher:Ft}),mb=_u({useEmitter:Di,useEmitterValue:Se,usePublisher:Ft}),gb=hb;qe(wu,De(()=>{const e=te(l=>d.jsxs("td",{children:["Item $",l]})),t=te(null),n=te(l=>d.jsxs("td",{colSpan:1e3,children:["Group ",l]})),r=te(null),o=te(null),s=te({}),i=te(Oi),a=te(wr),c=(l,u=null)=>gt(Q(s,ae(f=>f[l]),Ge()),u);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:c("EmptyPlaceholder"),FillerRow:c("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:c("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder"),TableBodyComponent:c("TableBody","tbody"),TableComponent:c("Table","table"),TableFooterComponent:c("TableFoot","tfoot"),TableHeadComponent:c("TableHead","thead"),TableRowComponent:c("TableRow","tr"),GroupComponent:c("Group","tr")}})),Mi();const ju={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},xb={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Pu,floor:Jo,max:oo,min:Li,round:Ru}=Math;function Mu(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function bb(e){return{...xb,items:e}}function Zo(e,t){return e&&e.width===t.width&&e.height===t.height}function yb(e,t){return e&&e.column===t.column&&e.row===t.row}const wb=De(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:c,scrollTop:l,smoothScrollTargetReached:u,viewportHeight:f},h,p,{didMount:m,propsReady:g},{customScrollParent:x,useWindowScroll:y,windowScrollContainerState:w,windowScrollTo:k,windowViewportRect:I},S])=>{const C=te(0),T=te(0),A=te(ju),j=te({height:0,width:0}),P=te({height:0,width:0}),M=_e(),F=_e(),U=te(0),L=te(null),K=te({column:0,row:0}),q=_e(),re=_e(),W=te(!1),V=te(0),ne=te(!0),H=te(!1),O=te(!1);Le(Q(m,Ie(V),we(([_,B])=>!!B)),()=>{ke(ne,!1)}),Le(Q(st(m,ne,P,j,V,H),we(([_,B,X,le,,me])=>_&&!B&&X.height!==0&&le.height!==0&&!me)),([,,,,_])=>{ke(H,!0),Ii(1,()=>{ke(M,_)}),Wt(Q(l),()=>{ke(t,[0,0]),ke(ne,!0)})}),fe(Q(re,we(_=>_!=null&&_.scrollTop>0),Zt(0)),T),Le(Q(m,Ie(re),we(([,_])=>_!=null)),([,_])=>{_&&(ke(j,_.viewport),ke(P,_.item),ke(K,_.gap),_.scrollTop>0&&(ke(W,!0),Wt(Q(l,Kn(1)),B=>{ke(W,!1)}),ke(c,{top:_.scrollTop})))}),fe(Q(j,ae(({height:_})=>_)),f),fe(Q(st(ye(j,Zo),ye(P,Zo),ye(K,(_,B)=>_&&_.column===B.column&&_.row===B.row),ye(l)),ae(([_,B,X,le])=>({gap:X,item:B,scrollTop:le,viewport:_}))),q),fe(Q(st(ye(C),r,ye(K,yb),ye(P,Zo),ye(j,Zo),ye(L),ye(T),ye(W),ye(ne),ye(V)),we(([,,,,,,,_])=>!_),ae(([_,[B,X],le,me,be,Te,Ae,,ze,Ze])=>{const{column:Ye,row:Ve}=le,{height:dt,width:lt}=me,{width:nt}=be;if(Ae===0&&(_===0||nt===0))return ju;if(lt===0){const We=Ai(Ze,_),ft=We+Math.max(Ae-1,0);return bb(Mu(We,ft,Te))}const it=Ou(nt,lt,Ye);let ct,Ke;ze?B===0&&X===0&&Ae>0?(ct=0,Ke=Ae-1):(ct=it*Jo((B+Ve)/(dt+Ve)),Ke=it*Pu((X+Ve)/(dt+Ve))-1,Ke=Li(_-1,oo(Ke,it-1)),ct=Li(Ke,oo(0,ct))):(ct=0,Ke=-1);const $e=Mu(ct,Ke,Te),{bottom:je,top:rt}=Du(be,le,me,$e),ut=Pu(_/it),Tt=ut*dt+(ut-1)*Ve-je;return{bottom:je,itemHeight:dt,items:$e,itemWidth:lt,offsetBottom:Tt,offsetTop:rt,top:rt}})),A),fe(Q(L,we(_=>_!==null),ae(_=>_.length)),C),fe(Q(st(j,P,A,K),we(([_,B,{items:X}])=>X.length>0&&B.height!==0&&_.height!==0),ae(([_,B,{items:X},le])=>{const{bottom:me,top:be}=Du(_,le,B,X);return[be,me]}),Ge(Jr)),t);const N=te(!1);fe(Q(l,Ie(N),ae(([_,B])=>B||_!==0)),N);const $=jt(Q(st(A,C),we(([{items:_}])=>_.length>0),Ie(N),we(([[_,B],X])=>{const le=_.items[_.items.length-1].index===B-1;return(X||_.bottom>0&&_.itemHeight>0&&_.offsetBottom===0&&_.items.length===B)&&le}),ae(([[,_]])=>_-1),Ge())),D=jt(Q(ye(A),we(({items:_})=>_.length>0&&_[0].index===0),Zt(0),Ge())),G=jt(Q(ye(A),Ie(W),we(([{items:_},B])=>_.length>0&&!B),ae(([{items:_}])=>({endIndex:_[_.length-1].index,startIndex:_[0].index})),Ge(tu),pn(0)));fe(G,p.scrollSeekRangeChanged),fe(Q(M,Ie(j,P,C,K),ae(([_,B,X,le,me])=>{const be=au(_),{align:Te,behavior:Ae,offset:ze}=be;let Ze=be.index;Ze==="LAST"&&(Ze=le-1),Ze=oo(0,Ze,Li(le-1,Ze));let Ye=$i(B,me,X,Ze);return Te==="end"?Ye=Ru(Ye-B.height+X.height):Te==="center"&&(Ye=Ru(Ye-B.height/2+X.height/2)),ze&&(Ye+=ze),{behavior:Ae,top:Ye}})),c);const ee=gt(Q(A,ae(_=>_.offsetBottom+_.bottom)),0);return fe(Q(I,ae(_=>({height:_.visibleHeight,width:_.visibleWidth}))),j),{customScrollParent:x,data:L,deviation:U,footerHeight:o,gap:K,headerHeight:s,increaseViewportBy:e,initialItemCount:T,itemDimensions:P,overscan:n,restoreStateFrom:re,scrollBy:i,scrollContainerState:a,scrollHeight:F,scrollTo:c,scrollToIndex:M,scrollTop:l,smoothScrollTargetReached:u,totalCount:C,useWindowScroll:y,viewportDimensions:j,windowScrollContainerState:w,windowScrollTo:k,windowViewportRect:I,...p,gridState:A,horizontalDirection:O,initialTopMostItemIndex:V,totalListHeight:ee,...h,endReached:$,propsReady:g,rangeChanged:G,startReached:D,stateChanged:q,stateRestoreInProgress:W,...S}},qe(Ni,St,ro,bu,An,ji,En));function Ou(e,t,n){return oo(1,Jo((e+n)/(Jo(t)+n)))}function Du(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=$i(e,t,n,r[0].index);return{bottom:$i(e,t,n,r[r.length-1].index)+o,top:s}}function $i(e,t,n,r){const o=Ou(e.width,n.width,t.column),s=Jo(r/o),i=s*n.height+oo(0,s-1)*t.row;return i>0?i+t.row:i}const vb=De(()=>{const e=te(f=>`Item ${f}`),t=te({}),n=te(null),r=te("virtuoso-grid-item"),o=te("virtuoso-grid-list"),s=te(Oi),i=te("div"),a=te(wr),c=(f,h=null)=>gt(Q(t,ae(p=>p[f]),Ge()),h),l=te(!1),u=te(!1);return fe(ye(u),l),{components:t,computeItemKey:s,context:n,FooterComponent:c("Footer"),HeaderComponent:c("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:c("Item","div"),itemContent:e,listClassName:o,ListComponent:c("List","div"),readyStateChanged:l,reportReadyState:u,ScrollerComponent:c("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder","div")}}),Sb=De(([e,t])=>({...e,...t}),qe(wb,vb)),Cb=v.memo(function(){const e=Xe("gridState"),t=Xe("listClassName"),n=Xe("itemClassName"),r=Xe("itemContent"),o=Xe("computeItemKey"),s=Xe("isSeeking"),i=zt("scrollHeight"),a=Xe("ItemComponent"),c=Xe("ListComponent"),l=Xe("ScrollSeekPlaceholder"),u=Xe("context"),f=zt("itemDimensions"),h=zt("gap"),p=Xe("log"),m=Xe("stateRestoreInProgress"),g=zt("reportReadyState"),x=qn(v.useMemo(()=>y=>{const w=y.parentElement.parentElement.scrollHeight;i(w);const k=y.firstChild;if(k){const{height:I,width:S}=k.getBoundingClientRect();f({height:I,width:S})}h({column:$u("column-gap",getComputedStyle(y).columnGap,p),row:$u("row-gap",getComputedStyle(y).rowGap,p)})},[i,f,h,p]),!0,!1);return Tu(()=>{e.itemHeight>0&&e.itemWidth>0&&g(!0)},[e]),m?null:d.jsx(c,{className:t,ref:x,...xt(c,u),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(y=>{const w=o(y.index,y.data,u);return s?d.jsx(l,{...xt(l,u),height:e.itemHeight,index:y.index,width:e.itemWidth},w):v.createElement(a,{...xt(a,u),className:n,"data-index":y.index,key:w},r(y.index,y.data,u))})})}),Tb=v.memo(function(){const e=Xe("HeaderComponent"),t=zt("headerHeight"),n=Xe("headerFooterTag"),r=qn(v.useMemo(()=>s=>{t(In(s,"height"))},[t]),!0,!1),o=Xe("context");return e?d.jsx(n,{ref:r,children:d.jsx(e,{...xt(e,o)})}):null}),kb=v.memo(function(){const e=Xe("FooterComponent"),t=zt("footerHeight"),n=Xe("headerFooterTag"),r=qn(v.useMemo(()=>s=>{t(In(s,"height"))},[t]),!0,!1),o=Xe("context");return e?d.jsx(n,{ref:r,children:d.jsx(e,{...xt(e,o)})}):null}),Eb=({children:e})=>{const t=v.useContext(Cu),n=zt("itemDimensions"),r=zt("viewportDimensions"),o=qn(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:Xo(!1),children:e})},Ib=({children:e})=>{const t=v.useContext(Cu),n=zt("windowViewportRect"),r=zt("itemDimensions"),o=Xe("customScrollParent"),s=Gc(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:Xo(!1),children:e})},Ab=v.memo(function({...e}){const t=Xe("useWindowScroll"),n=Xe("customScrollParent"),r=n||t?_b:Nb,o=n||t?Ib:Eb,s=Xe("context");return d.jsx(r,{...e,...xt(r,s),children:d.jsxs(o,{children:[d.jsx(Tb,{}),d.jsx(Cb,{}),d.jsx(kb,{})]})})}),{useEmitter:Lu,useEmitterValue:Xe,usePublisher:zt}=vu(Sb,{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"}},Ab),Nb=Nu({useEmitter:Lu,useEmitterValue:Xe,usePublisher:zt}),_b=_u({useEmitter:Lu,useEmitterValue:Xe,usePublisher:zt});function $u(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Nt.WARN),t==="normal"?0:parseInt(t??"0",10)}function jb({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 Pb="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 Rb({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?d.jsx("div",{className:Pb,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 Fu="data:";function Mb(e){if(!e)return[];const t=[],n=e.split(/\r?\n/);for(const r of n){const o=r.trim();if(!o||!o.startsWith(Fu))continue;const s=o.slice(Fu.length).trim();if(!s||s.toLowerCase()==="[done]")continue;const i=pr(s);i&&typeof i=="object"&&t.push(i)}return t}function Ob(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 zu(e){return v.useMemo(()=>{const t=e.content.filter(l=>l.type==="text");if(!t.length)return null;let r=t.flatMap(l=>Mb(l.text??""));if(!r.length){const l=t.map(f=>f.text??"").join(`
41
- `),u=pr(l);u&&typeof u=="object"&&(r=[u])}if(!r.length)return null;const s=Ob(r)??r[r.length-1];if(!s)return null;const i=s.output??s.payload??s,a=xr(i),c=Wr(a);return c&&typeof c=="object"&&!Array.isArray(c)?{kind:"dict",value:c,data:c,event:s}:{kind:"generic",value:c,event:s}},[e])}function Qo({message:e,viewMode:t,isStreaming:n=!1,toolConfig:r,expandable:o=!1,artifactOverride:s=null,contentOverride:i=null}){var L;const{toolRenderers:a,toolArtifactRenderers:c}=r??{},l=pc(e),u=s??e.artifact??null,f=Array.isArray(i)?i:e.content,h=zu(e),m=(h?gc(h):null)??h,g=f.length>0?f[0]:void 0,x=K=>{if(K==null)return null;const q=typeof K=="string"?K:(()=>{try{return JSON.stringify(K,null,2)}catch{return String(K)}})();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:q})},y=K=>x(K),w=()=>{if((m==null?void 0:m.kind)==="generic")return y(m.value);if(!g)return null;if(g.type==="text"){const K=g.text??"";return K?y(K):null}return y(g)},k=()=>(m==null?void 0:m.kind)==="dict"?y(m.data):w(),S=(()=>{if(!a)return;if(l.name){const q=a[l.name];if(q)return q}const K=(m==null?void 0:m.kind)??(h==null?void 0:h.kind);if(K){const q=a[K];if(q)return q}return a.default})(),C=k(),T=!o||t==="expanded",A=(T?S==null?void 0:S({message:e,toolMeta:l,toolPayload:m,viewMode:t,isStreaming:n}):null)??null,P=(()=>{if(!c)return;const K=u==null?void 0:u.type;if(typeof K=="string"){const q=c[K];if(q)return q}return c.default})(),M=P?P({artifact:u,message:e,toolPayload:m,isStreaming:n}):null,F=A??C,U=P?M:null;return d.jsxs("div",{className:"space-y-2",children:[n&&d.jsx(jb,{artifact:u,showPartialData:!1}),u&&U,T&&(((L=r==null?void 0:r.getShowContent)==null?void 0:L.call(r,e))??!0)?F:null]})}const Fi=v.memo(function({toolCall:t,index:n,toolName:r,className:o=""}){const{onSelectToolCall:s}=Fo(),i=t.state==="pending",a=t.state==="error",c=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:c}),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((l,u)=>{const f=typeof l.content=="string"?l.content:void 0;return f?d.jsx("p",{className:"text-[9px] text-muted-foreground/50 truncate",children:f},`${t.call.id}-progress-${u}`):null})})]})]})});Fi.displayName="ToolCallCard";function Bu({messages:e,toolConfig:t,wrapperClassName:n}){var i;const r=((i=e[0])==null?void 0:i.name)??"tool",o=ui(e).filter(a=>{var c;return e.length===1&&e[0].role==="tool"?((c=t==null?void 0:t.getShowProgress)==null?void 0:c.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,c)=>d.jsx(Fi,{toolCall:a,index:c,toolName:r},a.call.id||c))});return n?d.jsx("div",{className:n,children:s}):d.jsx("div",{className:"space-y-1 py-1",children:s})}const Uu=b.forwardRef(({className:e,...t},n)=>d.jsx("div",{ref:n,className:he("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));Uu.displayName="Card";const Hu=b.forwardRef(({className:e,...t},n)=>d.jsx("div",{ref:n,className:he("flex flex-col space-y-1.5 p-6",e),...t}));Hu.displayName="CardHeader";const Wu=b.forwardRef(({className:e,...t},n)=>d.jsx("h3",{ref:n,className:he("text-2xl font-semibold leading-none tracking-tight",e),...t}));Wu.displayName="CardTitle";const Vu=b.forwardRef(({className:e,...t},n)=>d.jsx("p",{ref:n,className:he("text-sm text-muted-foreground",e),...t}));Vu.displayName="CardDescription";const zi=b.forwardRef(({className:e,...t},n)=>d.jsx("div",{ref:n,className:he("p-6 pt-0",e),...t}));zi.displayName="CardContent";const Ku=b.forwardRef(({className:e,...t},n)=>d.jsx("div",{ref:n,className:he("flex items-center p-6 pt-0",e),...t}));Ku.displayName="CardFooter";const Db=e=>!!e&&typeof e=="object"&&e.type==="user_choice"&&typeof e.question=="string"&&Array.isArray(e.alternatives);function qu({interruptPart:e,onApprove:t,onReject:n,onSelectAlternative:r,disabled:o,isActive:s,payload:i}){const a=Db(i)?i:null,c=(a==null?void 0:a.question)??e.title??"Approve the result?",l=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(Uu,{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(Hu,{className:"pb-3",children:[d.jsx(Wu,{className:"text-blue-900 dark:text-blue-100 text-base",children:c}),d.jsx(Vu,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a?d.jsx(zi,{className:"pt-0 pb-3",children:d.jsx("div",{className:"space-y-2",children:a.alternatives.map(f=>d.jsx(Qe,{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(zi,{className:"pt-0 pb-3",children:u}),!a&&d.jsx(Ku,{className:"pt-0",children:d.jsxs("div",{className:"flex gap-2 ml-auto",children:[d.jsx(Qe,{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(Qe,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:o||!s,children:"Approve"})]})})]})}function Lb({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 Gu(){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 Xn=Gu();function $b(e){Xn=e}const Yu=/[&<>"']/,Fb=new RegExp(Yu.source,"g"),Xu=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,zb=new RegExp(Xu.source,"g"),Bb={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Ju=e=>Bb[e];function bt(e,t){if(t){if(Yu.test(e))return e.replace(Fb,Ju)}else if(Xu.test(e))return e.replace(zb,Ju);return e}const Ub=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Zu(e){return e.replace(Ub,(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 Hb=/(^|[^\[])\^/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(Hb,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const Wb=/[^\w:]/g,Vb=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function Qu(e,t,n){if(e){let r;try{r=decodeURIComponent(Zu(n)).replace(Wb,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!Vb.test(n)&&(n=Yb(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const es={},Kb=/^[^:]+:\/*[^/]*$/,qb=/^([^:]+:)[\s\S]*$/,Gb=/^([^:]+:\/*[^/]*)[\s\S]*$/;function Yb(e,t){es[" "+e]||(Kb.test(e)?es[" "+e]=e+"/":es[" "+e]=ns(e,"/",!0)),e=es[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(qb,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(Gb,"$1")+t:e+t}const ts={exec:function(){}};function ed(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let c=!1,l=i;for(;--l>=0&&a[l]==="\\";)c=!c;return c?"|":" |"}),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 ns(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 Xb(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 Jb(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 td(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function nd(e,t,n,r){const o=t.href,s=t.title?bt(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:bt(i)}}function Zb(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
40
+ `)):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 gc(e){const t=xr(e.value);return t===e.value?e:{...e,value:t}}function xc(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 bc(e){return Array.isArray(e.toolCalls)&&e.toolCalls.length>0?e.toolCalls.map(_g).filter(t=>!!t):ai(e)}function ci(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 ui(e,t=[]){if(Array.isArray(e)){const o=e.filter(i=>i.role==="assistant").flatMap(i=>bc(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=ci(i.id,e)||ci(i.id,t),c=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,l=(a==null?void 0:a.artifact)??i.artifact,u=xc(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:c,artifact:l}})}if(e.role!=="assistant")return[];const n=bc(e);return n.length===0?[]:n.map(r=>{var c,l,u;const o=ci(r.id,t)??Pg(e,r),s=Array.isArray((c=o==null?void 0:o.additionalKwargs)==null?void 0:c.toolProgress)?(l=o==null?void 0:o.additionalKwargs)==null?void 0:l.toolProgress:void 0,i=(o==null?void 0:o.artifact)??r.artifact,a=xc(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 ui(e,t).map(n=>n.artifact).filter(n=>!!n)}function Og(e,t){return t<e.length-1}function Lo(e){var s;const t=e.map(i=>Oo(i)).filter(Boolean),n=new Map;for(const i of t)if(i.role==="tool"){const a=i.toolCallId||Array.isArray(i.toolCalls)&&((s=i.toolCalls[0])==null?void 0:s.id)||i.tool_call_id;a&&n.set(a,i)}return t.map((i,a)=>{if(i.role!=="assistant"||!Array.isArray(i.toolCalls)||i.toolCalls.length===0)return i;const c=i.toolCalls.map(l=>{var w;const u=l.id||l.toolCallId||l.tool_call_id,f=u?n.get(u):void 0,h=f&&Array.isArray(f.content)?(w=f.content.find(k=>k.type==="text"))==null?void 0:w.text:typeof(f==null?void 0:f.content)=="string"?f==null?void 0:f.content:void 0;let p=(f==null?void 0:f.artifact)??l.artifact;if(!p&&l.args){const k=l.args;typeof k=="object"&&k!==null&&(k.type||k.question)&&(p=k)}const m=f?t.indexOf(f):-1,g=Math.max(a,m),y=Og(t,g)?"completed":l.status==="failed"?"failed":"running";return{...l,id:u||l.id,status:y,content:h,artifact:p}});return{...i,toolCalls:c}}).filter(i=>{var p;if(!i)return!1;if(i.role!=="assistant")return!0;const a=i.content,c=typeof a=="string"?a.trim().length>0:Array.isArray(a)&&a.some(m=>{var g;return m&&m.type==="text"&&((g=m.text)==null?void 0:g.trim())}),l=Array.isArray(a)&&a.some(m=>m&&m.type==="image_url"),u=i.artifact!==null&&i.artifact!==void 0,f=((p=i.toolCalls)==null?void 0:p.length)>0,h=Array.isArray(a)&&a.some(m=>m&&["file","interrupt"].includes(m.type));return!!(c||l||u||f||h)})}function di(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Mg(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 Dg(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 di(e,r,s)}return e}function Lg(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 $g={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,messagesStreamMeta:{},pendingInterrupt:null,values:{}};function Fg(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 yc(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>yc(o,s),e):e}default:return e}}function zg(e=[]){const[t,n]=v.useReducer(Fg,{...$g,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]),c=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 l=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:c}),[c]);return{state:t,dispatch:n,...l}}function yc(e,t){if(t.type==="tool.start")return Bg(e,t);if(t.type==="tool.progress")return Ug(e,t);if(t.type==="tool.end")return Hg(e,t);if(t.type==="artifact.update")return Wg(e,t);if(t.type==="checkpoint"){const n=t.checkpointNs??e.lastCheckpointNs??null,r=Dg(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=Lg(n.checkpoints);let i=s.length?s:o==null?void 0:o.messages;if(i){if(e.assemblingId&&!i.some(a=>a.id===e.assemblingId)){const a=e.messages.find(c=>c.id===e.assemblingId);a&&(i=[...i,a])}i=Lo(i)}else i=r===null?Mg(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.callId??e.id??void 0}function $o(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=$o(e,t);if(r===-1)return e;const o=e[r],s=(o.toolCalls??[]).map(i=>i.id===t?{...i,...n}:i);return di(e,r,{...o,toolCalls:s})}function Bg(e,t){const n=fi(t),r=t.name??t.tool??void 0,o={type:t.type,content:`Starting ${r??"tool"}...`,seq:t.seq??null,timestamp:new Date().toISOString()};let s=e.messages;return n&&$o(s,n)!==-1&&(s=hi(s,n,{status:"running",content:o.content})),{...e,messages:s}}function Ug(e,t){var i,a;const n=t.id??t.callId??((i=t.data)==null?void 0:i.id)??fi(t);if(!n)return e;const r=t.content??((a=t.data)==null?void 0:a.content)??(typeof t.data=="string"?t.data:void 0);let o=e.messages;return $o(o,n)!==-1&&(o=hi(o,n,{content:r})),{...e,messages:o}}function Hg(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&&$o(r,n)!==-1&&(r=hi(r,n,{status:"completed",content:a,artifact:t.artifact}));const c={id:`tool-${n||Date.now()}`,role:"tool",name:t.name??t.tool??void 0,content:[{type:"text",text:a}],artifact:t.artifact,toolCallId:n??void 0,createdAt:new Date().toISOString()};return{...e,messages:[...r,c]}}function Wg(e,t){const n=t.artifactId??t.artifact_id,r=t.toolCallId??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:di(e.messages,s,i)}}const wc=120;function Vg(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>wc?`${n.slice(0,wc-3)}…`:n:""}function Kg(e){return Vg(e.content)||""}function qg(e){const t=new Map,n=[],r=new Map,o=[];for(let l=0;l<e.length;l++){const u=e[l],f=u.checkpointId,h=f??`cp-${l}`,p=u.metadata??{},m=typeof p.step=="number"?p.step:null,g=typeof p.source=="string"?p.source:null;let x=null,y=null;const w=Array.isArray(u.messages)?u.messages:[];for(const C of w)C.role==="user"&&(y||(y=C),C.id&&(x=C.id));const k=u.next&&u.next.length>0?String(u.next[0]):null,I=u.parentConfig??null,S={id:h,step:m,source:g,createdAt:u.createdAt??null,namespace:u.checkpointNs??null,parentId:u.parentId??null,next:k,parentConfig:I,userMessageId:x};if(o.push(S),f&&t.set(f,S),f&&y){const C=Kg(y);C&&r.set(f,C)}n.push({id:h,messageId:x,step:m,source:g,createdAt:u.createdAt??null,next:k,parentConfig:I})}const s=new Map;for(const l of o){if(!l.userMessageId)continue;const u=s.get(l.userMessageId)??[];u.push(l),s.set(l.userMessageId,u)}for(const l of s.values()){if(!l.length)continue;l.sort((f,h)=>{const p=f.createdAt?Date.parse(f.createdAt):0;return(h.createdAt?Date.parse(h.createdAt):0)-p});const u=l.length;for(let f=0;f<l.length;f++){const h=l[f];h.attemptCount=u,h.attemptIndex=f,h.isLatestAttempt=f===0}}return{checkpoints:e,checkpointMetaByCheckpointId:t,timeline:n,messagePreviews:r,getLatest:()=>{const l=n[0];if(l)return t.get(l.id)},getCheckpoint:l=>t.get(l),getMessageAttempts:l=>{const u=[];for(const f of t.values())f.userMessageId===l&&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 Gg(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 Yg(e){return v.useMemo(()=>qg(e),[e])}function vc({api:e,seed:t,onError:n,currentThreadId:r,initialThreadId:o=null,initialCheckpointId:s=null,initialCheckpointNs:i=null,autoLoadInitial:a=!0,isStreaming:c,getMessages:l}){const[u,f]=v.useState(null),p=v.useMemo(()=>mr(u),[u]).checkpoints,m=Yg(p),g=m.timeline,[x,y]=v.useState(!1),[w,k]=v.useState(!1),[I,S]=v.useState(null),C=v.useRef(r),T=v.useRef(null),A=v.useRef(null),j=v.useRef(null),_=v.useRef(null),L=v.useRef(null),F=v.useRef(new Map),B=v.useRef(null);v.useEffect(()=>{C.current=r},[r]);const O=v.useCallback(async $=>{var q,U;if(!$.threadId)return;const D=$.threadId;(q=$.onStart)==null||q.call($),$.setLoading(!0);try{await $.action(D)}catch(P){if(!Kl(P)&&C.current===D){const ee=String(P);(U=$.handleError)==null||U.call($,ee),n==null||n(ee)}throw P}finally{$.setLoading(!1)}},[n]),G=v.useCallback(async($,D)=>{var ee;if(!$)return;const q=`${$}:${D??"latest"}`,U=F.current.get(q);if(U)return U;(ee=B.current)==null||ee.abort();const P=new AbortController;B.current=P;const V=O({threadId:$,setLoading:y,onStart:()=>S(null),handleError:ce=>S(ce),action:async ce=>{const ue=await e.getStateHistory({threadId:ce,checkpointId:D??void 0,signal:P.signal});if(C.current!==ce){console.log(`[useThreadHistoryState] Thread changed during load (was ${ce}, now ${C.current}), discarding stale data`);return}const{checkpoints:be,latest:Ae}=mr(ue),Ie=D?be.find(Xe=>Xe.checkpointId===D)??Ae:Ae;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(ue)}});F.current.set(q,V);try{await V}finally{F.current.delete(q),B.current===P&&(B.current=null)}return C.current===$&&(L.current=q),V},[e,t,O]),Y=v.useCallback(async($,D)=>{_.current=$;try{await G($,D)}catch(q){if(!Kl(q))throw q}finally{_.current===$&&(_.current=null)}},[G]),re=v.useCallback($=>{A.current=$},[]),H=v.useCallback($=>{j.current=$},[]),W=v.useCallback($=>{const D=$.threadId??C.current;if(!D||C.current&&C.current!==D)return;const{checkpoints:q,latest:U}=mr($);if(!q.length)return;const P=U,V=j.current===D;!c&&!V&&t((P==null?void 0:P.messages)??[],{checkpointId:(P==null?void 0:P.checkpointId)??null,checkpointNs:(P==null?void 0:P.checkpointNs)??null,pendingInterrupt:(P==null?void 0:P.interrupt)??null}),f($),L.current=`${D}:latest`,A.current=null,j.current===D&&(j.current=null)},[t,c]),ne=v.useCallback(async($,D)=>{const q=C.current;await O({threadId:q,setLoading:k,action:async U=>{const P=await e.getStateHistory({threadId:U,checkpointId:$,checkpointNs:D??void 0});if(C.current!==U)return;const{checkpoints:V}=mr(P),ee=V.find(ce=>ce.checkpointId===$&&(D?ce.checkpointNs===D:!0));if(!ee){console.warn("[useThreadHistoryState] Requested checkpoint not found:",{checkpointId:$,checkpointNs:D});return}f(P),t(ee.messages??[],{checkpointId:ee.checkpointId??null,checkpointNs:ee.checkpointNs??null})}}).catch(()=>{})},[e,t,O]),K=v.useCallback(($,D)=>{t(l(),{checkpointId:$??null,checkpointNs:D??null})},[l,t]),M=v.useCallback(async()=>{C.current&&await Y(C.current)},[Y]);v.useEffect(()=>{if(!a||!r||x||c)return;if(A.current===r){A.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 $;const D=`${r}:latest`;L.current!==D&&Y(r,$)},[a,r,s,i,o,x,c,Y]);const N=v.useCallback(()=>{f(null),y(!1),k(!1),S(null),A.current=null,j.current=null,T.current=null,L.current=null,_.current=null},[]);return{threadCheckpoints:p,threadTimeline:g,checkpointIndex:m,isLoadingThread:x,isLoadingCheckpoint:w,threadStateError:I,loadThread:Y,navigateToCheckpoint:ne,setCurrentCheckpointId:K,returnToLatest:M,handleStateHistoryEvent:W,markSkipNextLoad:re,markStreamPendingThread:H,resetHistoryState:N,clearState:N}}const Sc=v.createContext(null),Cc=v.createContext(null);function qr(){const e=v.useContext(Sc);if(!e)throw new Error("useThreadState must be used within a ThreadStateProvider");return e}function Tc(){const e=v.useContext(Cc);if(!e)throw new Error("useThreadStateUpdater must be used within a ThreadStateProvider");return e}function kc({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,isStreaming:s,onError:i}){const{chatApi:a}=hr(),{currentThreadId:c}=Vr(),{state:l,seed:u,onEvent:f,dispatch:h}=zg(),{threadCheckpoints:p,threadTimeline:m,checkpointIndex:g,isLoadingThread:x,isLoadingCheckpoint:y,threadStateError:w,loadThread:k,navigateToCheckpoint:I,setCurrentCheckpointId:S,returnToLatest:C,handleStateHistoryEvent:T,markSkipNextLoad:A,markStreamPendingThread:j,resetHistoryState:_}=vc({api:a,seed:u,onError:i,currentThreadId:c,initialThreadId:t,initialCheckpointId:n,initialCheckpointNs:r,autoLoadInitial:o,isStreaming:s,getMessages:v.useCallback(()=>l.messages,[l.messages])});v.useEffect(()=>{c||(u([],{}),_())},[c,u,_]);const L=v.useRef(null),F=v.useCallback(K=>{L.current=K},[]),B=v.useRef(null),O=v.useCallback(K=>{B.current=K},[]),G=v.useMemo(()=>({assemblingMessageId:l.assemblingId??null}),[l.assemblingId]),Y=v.useCallback((K,M)=>{const N=oc(K,"user");return h({type:"user_message",payload:{message:N,editingMessageId:M==null?void 0:M.editingMessageId}}),N},[h]),re=v.useCallback(async()=>{L.current?await L.current():(u([],{}),_())},[u,_]),H=v.useMemo(()=>Tg(l.messages),[l.messages]),W=v.useMemo(()=>({threadId:c,messages:l.messages,interrupt:l.pendingInterrupt,checkpoint:{id:l.lastCheckpointId??null,namespace:l.lastCheckpointNs??null},checkpoints:p,checkpointIndex:g,timelineCheckpoints:m,metadata:G,values:l.values??{},isLoading:x,isLoadingCheckpoint:y,error:w,loadOlder:async()=>{},seedFromSnapshot:K=>{u(K.messages,{checkpointId:K.checkpointId,checkpointNs:K.checkpointNs,pendingInterrupt:K.interrupt})},clearState:re,navigateToCheckpoint:I,setCurrentCheckpointId:S,returnToLatest:C,loadThread:async(K,M,N)=>{await k(K,M,{clearProgress:!1})},clearThread:re,respondToInterrupt:async(K,M,N)=>{B.current&&await B.current(K,M,N)},messagePreviews:g.messagePreviews,handleStateHistoryEvent:T,markSkipNextLoad:A,markStreamPendingThread:j,resetHistoryState:_,pushUser:Y,onEvent:f,artifacts:H}),[c,l.messages,l.pendingInterrupt,l.lastCheckpointId,l.lastCheckpointNs,l.values,p,m,g,G,x,y,w,u,re,I,S,C,k,T,A,j,Y,f,H]),ne=v.useMemo(()=>({registerClearThread:F,registerRespondToInterrupt:O}),[F,O]);return d.jsx(Cc.Provider,{value:ne,children:d.jsx(Sc.Provider,{value:W,children:e})})}const Ec=v.createContext(null);function Ic({children:e,...t}){return d.jsx(Ec.Provider,{value:t,children:e})}function Fo(){const e=v.useContext(Ec);if(!e)throw new Error("useChatUI must be used within a ChatUIProvider");return e}function Ac(e,t){if(!e)return null;const n=Vn(e);if(!n)return null;const r=Vn(n.configurable)??n;return Hr(r,t)??null}function Xg(e){const t=Ac(e,["checkpoint_id","checkpointId"]);if(!t)return null;const n=Ac(e,["checkpoint_ns","checkpointNs"]);return{checkpointId:t,checkpointNs:n}}function Jg(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 Zg(e,t){const n=[...e].sort(Jg);for(const r of n){if(r.messageId!==t)continue;const o=Xg(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`)}const Nc=v.createContext(null),jc=v.createContext(!1);function Qg({children:e,initialThreadId:t=null,initialCheckpointId:n=null,initialCheckpointNs:r=null,autoLoadInitial:o=!0,onError:s,onAuthError:i,onThreadChange:a,onConnectionError:c,onToolEnd:l,onUpdateEvent:u,onCustomEvent:f,onMetadataEvent:h,onFinish:p}){const{chatApi:m,baseUrl:g}=hr(),x=g,{stream:y,stop:w,clear:k,isStreaming:I,error:S,connected:C,streamedMessages:T,activeMessageId:A}=hg({baseUrl:x}),[j,_]=v.useState(!1);return v.useEffect(()=>{_(I)},[I]),d.jsx(fc,{initialThreadId:t,onError:s,onThreadChange:a,children:d.jsx(kc,{initialThreadId:t,initialCheckpointId:n,initialCheckpointNs:r,autoLoadInitial:o,onError:s,isStreaming:j,children:d.jsx(jc.Provider,{value:!0,children:d.jsx(ex,{api:m,streamApi:{stream:y,stop:w,clear:k,isStreaming:I,error:S,connected:C,streamedMessages:T,activeMessageId:A},onError:s,onAuthError:i,onConnectionError:c,onToolEnd:l,onUpdateEvent:u,onCustomEvent:f,onMetadataEvent:h,onFinish:p,children:e})})})})}function ex({children:e,api:t,streamApi:n,onError:r,onAuthError:o,onConnectionError:s,onToolEnd:i,onUpdateEvent:a,onCustomEvent:c,onMetadataEvent:l,onFinish:u}){const{stream:f,stop:h,clear:p,isStreaming:m,error:g,connected:x,streamedMessages:y}=n,{setCurrentThreadId:w,currentThreadIdRef:k,addThreadFromEvent:I,currentThreadId:S}=Vr();v.useEffect(()=>{S!==void 0&&p()},[S,p]);const{interrupt:C,checkpoint:T,timelineCheckpoints:A,handleStateHistoryEvent:j,markSkipNextLoad:_,markStreamPendingThread:L,resetHistoryState:F,pushUser:B,onEvent:O,messages:G}=qr(),{registerClearThread:Y,registerRespondToInterrupt:re}=Tc(),H=v.useCallback(U=>{I(U),k.current!==U.threadId&&((U.created??!k.current)&&_(U.threadId),L(U.threadId),w(U.threadId))},[I,_,L,w,k]),W=v.useCallback(U=>{U.type==="thread_info"?H(U):U.type==="state_history"?j(U):U.type==="tool.end"?(O(U),i==null||i(U)):O(U)},[H,j,O,i]),ne=v.useCallback((U,P)=>{f(U,V=>{W(V),P==null||P(V)},{onError:V=>{console.error("[StreamingProvider] Stream error:",V),r==null||r(V)},onAuthError:V=>{console.error("[StreamingProvider] Auth error:",V),o==null||o(V)},onConnectionError:V=>{console.error("[StreamingProvider] Connection error:",V),s==null||s(V)},onUpdateEvent:a,onCustomEvent:c,onMetadataEvent:l,onFinish:u})},[f,W,r,o,s,a,c,l,u]),K=v.useRef(T);v.useEffect(()=>{K.current=T},[T]);const M=v.useCallback(async(U,P,V)=>{const ee=k.current;if(!ee)throw new Error("No active thread to handle interrupt");const ce=U?P??!0:!1,ue=K.current,be={threadId:ee,checkpointId:ue.id??void 0,checkpointNs:ue.namespace??void 0,command:{kind:"resume",value:ce},payload:V==null?void 0:V.payload};ne(be)},[k,ne]);v.useEffect(()=>{re(M)},[M,re]);const N=v.useCallback(async()=>{h(),p(),F(),w(null)},[p,F,w,h]);v.useEffect(()=>{Y(N)},[N,Y]);const $=v.useCallback(async(U,P)=>{m&&h();let V=k.current;const ee=(U==null?void 0:U.text)??"",ce=(U==null?void 0:U.attachments)??[],ue=(ee==null?void 0:ee.trim())??"",be={...(U==null?void 0:U.payload)??{}},Ae=Array.isArray(be.messages)?be.messages:void 0;Ae&&delete be.messages;const Ie=!!(Ae&&Ae.length),Xe=!!(U.contentParts&&U.contentParts.length>0);if(!V&&!ue&&ce.length===0&&!Ie&&!Xe)return;if(!V){const Le=Math.floor(Date.now()/1e3).toString(16).padStart(8,"0"),et=Array.from({length:4},()=>Math.floor(Math.random()*4294967295).toString(16).padStart(8,"0")).join("").slice(0,16);V=`${Le}${et}`,_(V),w(V)}let ze=null;U.contentParts&&U.contentParts.length>0&&(ze=U.contentParts);const{contentParts:Ze,filesInfo:Be}=ze?{contentParts:ze,filesInfo:[]}:await rc(ce),dt=[...Ze];ue&&dt.push({type:"text",text:ee});const at=P==null?void 0:P.originalMessageId,ct=!!(P!=null&&P.edit&&at),ft=!Ie&&dt.length>0;let tt=null;if(ft){const Le=ct?at:`msg-${Date.now()}`;tt=oc({id:Le,role:"user",content:dt,createdAt:new Date().toISOString()},"user"),ct?B(tt,{editingMessageId:at}):B(tt)}const nt=Ie?Ae:tt?[tt]:[],ut={...be,...Be.length?{files_info:Be}:{}};nt.length?ut.messages=nt:"messages"in ut||(ut.messages=[]);let qe=(P==null?void 0:P.checkpointId)??T.id??void 0,Qe=(P==null?void 0:P.checkpointNs)??T.namespace??void 0;if(ct&&at){const Le=Zg(A,at);qe=Le.checkpointId,Qe=Le.checkpointNs??void 0}const De={threadId:V,payload:ut,checkpointId:qe,checkpointNs:Qe,config:P==null?void 0:P.config,edit:!!(P!=null&&P.edit)};ne(De,P==null?void 0:P.onEvent)},[T,k,m,_,B,ne,h,A]),D=v.useMemo(()=>{if(!m||Object.keys(y).length===0)return G;let U=[...G];return Object.values(y).forEach(P=>{const V=U.findIndex(ee=>ee.id===P.id);V>=0?U[V]=P:U.push(P)}),U},[m,y,G]),q=v.useMemo(()=>({isStreaming:m,error:g,connectionState:g?"error":m?x?"connected":"connecting":"idle",messages:D,submit:$,stop:h,interrupt:C,resume:()=>Promise.resolve(),goto:(U,P)=>Promise.resolve(),clearError:()=>{}}),[m,g,$,h,C,x,D]);return d.jsx(Nc.Provider,{value:q,children:e})}function pi(){const e=v.useContext(Nc);if(!e)throw new Error("useStream must be used within StreamingProvider");return e}function tx(){return v.useContext(jc)}function _c(e){return typeof e=="object"&&e!==null}function nx(e,t){if(Object.is(e,t))return!0;if(!_c(e)||!_c(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 Pc(e){const t=v.useRef(e),n=v.useRef(e);return nx(t.current,e)||(t.current=e,n.current=e),n.current}function Rc(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 rx(e){const{setCurrentTaskId:t,getCurrentTaskId:n,onToolEnd:r}=e;return o=>{const s=Rc(o),i=(n==null?void 0:n())??null;s&&s!==i&&t(s),r==null||r(o)}}function Gr({children:e,apiConfig:t,initialThreadId:n=null,initialCheckpointId:r=null,initialCheckpointNs:o=null,autoLoadInitial:s=!0,onConnectionError:i,onError:a,onAuthError:c,onThreadChange:l,onToolEnd:u,onUpdateEvent:f,onCustomEvent:h,onMetadataEvent:p,onFinish:m}){const g=Pc(t),x=hn(a),y=hn(c),w=hn(i),k=hn(l),I=hn(u),S=hn(f),C=hn(h),T=hn(p),A=hn(m),j=v.useMemo(()=>({initialThreadId:n,initialCheckpointId:r,initialCheckpointNs:o,autoLoadInitial:s,onError:x,onAuthError:y,onConnectionError:w,onThreadChange:k,onToolEnd:I,onUpdateEvent:S,onCustomEvent:C,onMetadataEvent:T,onFinish:A}),[n,r,o,s]);return d.jsx(tc,{apiConfig:g,children:d.jsx(Qg,{...j,children:e})})}function hn(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 Oc(){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 Mc(){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 Dc(...e){for(const t of e)if(typeof t=="string"&&t.trim())return t.trim().replace(/\/+$/,"");return""}function Lc(){const e={},t=Oc(),n=Mc();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function $c(){const e=Lc(),t=Cn.getAuthToken(),n=Oc();return{apiBaseUrl:Dc(e.baseUrl,n),apiKey:t||e.apiKey||Mc()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,darkMode:!1,enableSound:!1,messageHistory:100}}const mi=vn.chatSettings;function Fc(){try{const e=localStorage.getItem(mi);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function zc(e){try{const t={...e,apiBaseUrl:e.apiBaseUrl.trim().replace(/\/+$/,"")};localStorage.setItem(mi,JSON.stringify(t)),t.apiKey&&Cn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function ox(){const e=$c(),t=Fc(),n=Cn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:Dc(Cn.baseUrl,r,e.apiBaseUrl)}}function sx(e){Cn.updateConfig({baseUrl:e.apiBaseUrl,apiKey:e.apiKey??void 0}),zc(e)}function pe(...e){return Bn.twMerge(kt.clsx(e))}const ix=Ap.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=b.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?cr.Slot:"button";return d.jsx(i,{className:pe(ix({variant:t,size:n,className:e})),ref:s,...o})});Je.displayName="Button";const zo=0,kn=1,yr=2,Bc=4;function Uc(e){return()=>e}function ax(e){e()}function Hc(e,t){return n=>e(t(n))}function Wc(e,t){return()=>e(t)}function lx(e,t){return n=>e(t,n)}function gi(e){return e!==void 0}function cx(...e){return()=>{e.map(ax)}}function wr(){}function Bo(e,t){return t(e),e}function ux(e,t){return t(e)}function Ve(...e){return e}function $e(e,t){return e(kn,t)}function Te(e,t){e(zo,t)}function xi(e){e(yr)}function ot(e){return e(Bc)}function he(e,t){return $e(e,lx(t,zo))}function Wt(e,t){const n=e(kn,r=>{n(),t(r)});return n}function Vc(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Kc(e,t){return e===t}function Ke(e=Kc){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=>Hc(t,e)}function Zt(e){return t=>()=>{t(e)}}function Q(e,...t){const n=dx(...t);return(r,o)=>{switch(r){case yr:xi(e);return;case kn:return $e(e,n(o))}}}function Qt(e,t){return n=>r=>{n(t=e(t,r))}}function Kn(e){return t=>n=>{e>0?e--:t(n)}}function pn(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);$e(s,c=>{const l=n;n=n|a,t[i]=c,l!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function dx(...e){return t=>e.reduceRight(ux,t)}function fx(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case kn:return s?n===s?void 0:(r(),n=s,t=$e(e,s),t):(r(),wr);case yr:r(),n=null;return}}}function te(e){let t=e;const n=je();return(r,o)=>{switch(r){case zo:t=o;break;case kn:{o(t);break}case Bc:return t}return n(r,o)}}function xt(e,t){return Bo(te(t),n=>he(e,n))}function je(){const e=[];return(t,n)=>{switch(t){case zo:e.slice().forEach(r=>{r(n)});return;case yr:e.splice(0,e.length);return;case kn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function _t(e){return Bo(je(),t=>he(e,t))}function Me(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:hx(),singleton:n}}const hx=()=>Symbol();function px(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(c=>n(c)));return i&&t.set(s,a),a};return n(e)}function it(...e){const t=je(),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);$e(s,c=>{n[i]=c,r=r|a,r===o&&Te(t,n)})}),function(s,i){switch(s){case yr:{xi(t);return}case kn:return r===o&&i(n),$e(t,i)}}}function ye(e,t=Kc){return Q(e,Ke(t))}function bi(...e){return function(t,n){switch(t){case yr:return;case kn:return cx(...e.map(r=>$e(r,n)))}}}var Nt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Nt||{});const mx={0:"debug",3:"error",1:"log",2:"warn"},gx=()=>typeof globalThis>"u"?window:globalThis,En=Me(()=>{const e=te(3);return{log:te((t,n,r=1)=>{var o;const s=(o=gx().VIRTUOSO_LOG_LEVEL)!=null?o:ot(e);r>=s&&console[mx[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function qn(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 c=i[0].target;c.offsetParent!==null&&e(c)};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 xx(e,t,n,r,o,s,i,a,c){const l=v.useCallback(u=>{const f=bx(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 g=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,x=i?a?i.scrollWidth:i.scrollHeight:p?a?m.document.documentElement.scrollWidth:m.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,y=i?a?i.offsetWidth:i.offsetHeight:p?a?m.innerWidth:m.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:x,scrollTop:Math.max(g,0),viewportHeight:y}),s==null||s(a?qc("column-gap",getComputedStyle(u).columnGap,o):qc("row-gap",getComputedStyle(u).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return yi(l,n,c)}function bx(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 c=parseInt(a.dataset.index),l=parseFloat(a.dataset.knownSize),u=t(a,n);if(u===0&&r("Zero-sized element, this should not happen",{child:a},Nt.ERROR),u===l)continue;const f=s[s.length-1];s.length===0||f.size!==u||f.endIndex!==c-1?s.push({endIndex:c,size:u,startIndex:c}):s[s.length-1].endIndex++}return s}function qc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Nt.WARN),t==="normal"?0:parseInt(t??"0",10)}function Gc(e,t,n){const r=v.useRef(null),o=v.useCallback(c=>{if(!(c!=null&&c.offsetParent))return;const l=c.getBoundingClientRect(),u=l.width;let f,h;if(t){const p=t.getBoundingClientRect(),m=l.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,l.top),f=l.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 c;if(t){t.addEventListener("scroll",a);const l=new ResizeObserver(()=>{requestAnimationFrame(a)});return l.observe(t),()=>{t.removeEventListener("scroll",a),l.unobserve(t)}}else{const l=(c=i.current)==null?void 0:c.ownerDocument.defaultView;return l==null||l.addEventListener("scroll",a),l==null||l.addEventListener("resize",a),()=>{l==null||l.removeEventListener("scroll",a),l==null||l.removeEventListener("resize",a)}}},[a,t,i]),s}const Ct=Me(()=>{const e=je(),t=je(),n=te(0),r=je(),o=te(0),s=je(),i=je(),a=te(0),c=te(0),l=te(0),u=te(0),f=je(),h=je(),p=te(!1),m=te(!1),g=te(!1);return he(Q(e,ae(({scrollTop:x})=>x)),t),he(Q(e,ae(({scrollHeight:x})=>x)),i),he(t,o),{deviation:n,fixedFooterHeight:l,fixedHeaderHeight:c,footerHeight:u,headerHeight:a,horizontalDirection:m,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:g,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Yr={lvl:0};function Yc(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:c}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=c}return s.push({end:1/0,start:r,value:o}),s}function He(e){return e===Yr}function Xr(e,t){if(!He(e))return t===e.k?e.v:t<e.k?Xr(e.l,t):Xr(e.r,t)}function Vt(e,t,n="k"){if(He(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=Vt(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return Vt(e.l,t,n)}function Pt(e,t,n){return He(e)?Zc(t,n,1):t===e.k?lt(e,{k:t,v:n}):t<e.k?Qc(lt(e,{l:Pt(e.l,t,n)})):Qc(lt(e,{r:Pt(e.r,t,n)}))}function vr(){return Yr}function Uo(e,t,n){if(He(e))return[];const r=Vt(e,t)[0];return yx(vi(e,r,n))}function wi(e,t){if(He(e))return Yr;const{k:n,l:r,r:o}=e;if(t===n){if(He(r))return o;if(He(o))return r;{const[s,i]=Jc(r);return Ho(lt(e,{k:s,l:Xc(r),v:i}))}}else return t<n?Ho(lt(e,{l:wi(r,t)})):Ho(lt(e,{r:wi(o,t)}))}function Gn(e){return He(e)?[]:[...Gn(e.l),{k:e.k,v:e.v},...Gn(e.r)]}function vi(e,t,n){if(He(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(vi(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(vi(s,t,n))),a}function Ho(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(Si(t))return eu(lt(e,{lvl:n-1}));if(!He(t)&&!He(t.r))return lt(t.r,{l:lt(t,{r:t.r.l}),lvl:n,r:lt(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(Si(e))return Ci(lt(e,{lvl:n-1}));if(!He(r)&&!He(r.l)){const o=r.l,s=Si(o)?r.lvl-1:r.lvl;return lt(o,{l:lt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:Ci(lt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function lt(e,t){return Zc(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 Xc(e){return He(e.r)?e.l:Ho(lt(e,{r:Xc(e.r)}))}function Si(e){return He(e)||e.lvl>e.r.lvl}function Jc(e){return He(e.r)?[e.k,e.v]:Jc(e.r)}function Zc(e,t,n,r=Yr,o=Yr){return{k:e,l:r,lvl:n,r:o,v:t}}function Qc(e){return Ci(eu(e))}function eu(e){const{l:t}=e;return!He(t)&&t.lvl===e.lvl?lt(t,{r:lt(e,{l:t.r})}):e}function Ci(e){const{lvl:t,r:n}=e;return!He(n)&&!He(n.r)&&n.lvl===t&&n.r.lvl===t?lt(n,{l:lt(e,{r:n.l}),lvl:t+1}):e}function yx(e){return Yc(e,({k:t,v:n})=>({index:t,value:n}))}function tu(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 Ti=Me(()=>({recalcInProgress:te(!1)}),[],{singleton:!0});function nu(e,t,n){return e[Wo(e,t,n)]}function Wo(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 wx(e,t,n,r){const o=Wo(e,t,r),s=Wo(e,n,r,o);return e.slice(o,s+1)}function In(e,t){return Math.round(e.getBoundingClientRect()[t])}function Vo(e){return!He(e.groupOffsetTree)}function ki({index:e},t){return t===e?0:t<e?-1:1}function vx(){return{groupIndices:[],groupOffsetTree:vr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:vr()}}function Sx(e,t){let n=He(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),He(e)){e=Pt(e,0,s);continue}const a=Uo(e,i-1,o+1);if(a.some(Nx(r)))continue;let c=!1,l=!1;for(const{end:u,start:f,value:h}of a)c?(o>=f||s===h)&&(e=wi(e,f)):(l=h!==s,c=!0),u>o&&o>=f&&h!==s&&(e=Pt(e,o+1,h));l&&(e=Pt(e,i,s))}return[e,n]}function Cx(e){return typeof e.groupIndex<"u"}function Tx({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}=nu(t,e,ki),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function ru(e,t){if(!Vo(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function ou(e,t,n){if(Cx(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=ru(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function kx(e,t,n,r=0){return r>0&&(t=Math.max(t,nu(e,r,ki).offset)),Yc(wx(e,t,n,Tx),Ax)}function Ex(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Nt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&He(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((m,g)=>Pt(Pt(m,g,h),g+1,p),i)}else[i,a]=Sx(i,t);if(i===s)return e;const{lastIndex:c,lastOffset:l,lastSize:u,offsetTree:f}=Ei(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>Pt(h,p,Zr(p,f,o)),vr()),lastIndex:c,lastOffset:l,lastSize:u,offsetTree:f,sizeTree:i}}function Ix(e){return Gn(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 su(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 Ei(e,t,n,r){let o=e,s=0,i=0,a=0,c=0;if(t!==0){c=Wo(o,t-1,ki),a=o[c].offset;const l=Vt(n,t-1);s=l[0],i=l[1],o.length&&o[c].size===Vt(n,t)[1]&&(c-=1),o=o.slice(0,c+1)}else o=[];for(const{start:l,value:u}of Uo(n,t,1/0)){const f=l-s,h=f*i+a+f*r;o.push({index:l,offset:h,size:u}),s=l,a=h,i=u}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function Ax(e){return{index:e.index,value:e}}function Nx(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 jx={offsetHeight:"height",offsetWidth:"width"},en=Me(([{log:e},{recalcInProgress:t}])=>{const n=je(),r=je(),o=xt(r,0),s=je(),i=je(),a=te(0),c=te([]),l=te(void 0),u=te(void 0),f=te((S,C)=>In(S,jx[C])),h=te(void 0),p=te(0),m=vx(),g=xt(Q(n,Ee(c,e,p),Qt(Ex,m),Ke()),m),x=xt(Q(c,Ke(),Qt((S,C)=>({current:C,prev:S.current}),{current:[],prev:[]}),ae(({prev:S})=>S)),[]);he(Q(c,we(S=>S.length>0),Ee(g,p),ae(([S,C,T])=>{const A=S.reduce((j,_,L)=>Pt(j,_,Zr(_,C.offsetTree,T)||L),vr());return{...C,groupIndices:S,groupOffsetTree:A}})),g),he(Q(r,Ee(g),we(([S,{lastIndex:C}])=>S<C),ae(([S,{lastIndex:C,lastSize:T}])=>[{endIndex:C,size:T,startIndex:S}])),n),he(l,u);const y=xt(Q(l,ae(S=>S===void 0)),!0);he(Q(u,we(S=>S!==void 0&&He(ot(g).sizeTree)),ae(S=>[{endIndex:0,size:S,startIndex:0}])),n);const w=_t(Q(n,Ee(g),Qt(({sizes:S},[C,T])=>({changed:T!==S,sizes:T}),{changed:!1,sizes:m}),ae(S=>S.changed)));$e(Q(a,Qt((S,C)=>({diff:S.prev-C,prev:C}),{diff:0,prev:0}),ae(S=>S.diff)),S=>{const{groupIndices:C}=ot(g);if(S>0)Te(t,!0),Te(s,S+su(S,C));else if(S<0){const T=ot(x);T.length>0&&(S-=su(-S,T)),Te(i,S)}}),$e(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},Nt.ERROR)});const k=_t(s);he(Q(s,Ee(g),ae(([S,C])=>{const T=C.groupIndices.length>0,A=[],j=C.lastSize;if(T){const _=Xr(C.sizeTree,0);let L=0,F=0;for(;L<S;){const O=C.groupIndices[F],G=C.groupIndices.length===F+1?1/0:C.groupIndices[F+1]-O-1;A.push({endIndex:O,size:_,startIndex:O}),A.push({endIndex:O+1+G-1,size:j,startIndex:O+1}),F++,L+=G+1}const B=Gn(C.sizeTree);return L!==S&&B.shift(),B.reduce((O,{k:G,v:Y})=>{let re=O.ranges;return O.prevSize!==0&&(re=[...O.ranges,{endIndex:G+S-1,size:O.prevSize,startIndex:O.prevIndex}]),{prevIndex:G+S,prevSize:Y,ranges:re}},{prevIndex:S,prevSize:0,ranges:A}).ranges}return Gn(C.sizeTree).reduce((_,{k:L,v:F})=>({prevIndex:L+S,prevSize:F,ranges:[..._.ranges,{endIndex:L+S-1,size:_.prevSize,startIndex:_.prevIndex}]}),{prevIndex:0,prevSize:j,ranges:[]}).ranges})),n);const I=_t(Q(i,Ee(g,p),ae(([S,{offsetTree:C},T])=>{const A=-S;return Zr(A,C,T)})));return he(Q(i,Ee(g,p),ae(([S,C,T])=>{if(C.groupIndices.length>0){if(He(C.sizeTree))return C;let A=vr();const j=ot(x);let _=0,L=0,F=0;for(;_<-S;){F=j[L];const B=j[L+1]-F-1;L++,_+=B+1}if(A=Gn(C.sizeTree).reduce((B,{k:O,v:G})=>Pt(B,Math.max(0,O+S),G),A),_!==-S){const B=Xr(C.sizeTree,F);A=Pt(A,0,B);const O=Vt(C.sizeTree,-S+1)[1];A=Pt(A,1,O)}return{...C,sizeTree:A,...Ei(C.offsetTree,0,A,T)}}else{const A=Gn(C.sizeTree).reduce((j,{k:_,v:L})=>Pt(j,Math.max(0,_+S),L),vr());return{...C,sizeTree:A,...Ei(C.offsetTree,0,A,T)}}})),g),{beforeUnshiftWith:k,data:h,defaultItemSize:u,firstItemIndex:a,fixedItemSize:l,gap:p,groupIndices:c,itemSize:f,listRefresh:w,shiftWith:i,shiftWithOffset:I,sizeRanges:n,sizes:g,statefulTotalCount:o,totalCount:r,trackItemSizes:y,unshiftWith:s}},Ve(En,Ti),{singleton:!0});function _x(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const iu=Me(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=je(),i=je(),a=_t(Q(s,ae(_x)));return he(Q(a,ae(c=>c.totalCount)),n),he(Q(a,ae(c=>c.groupIndices)),e),he(Q(it(o,t,r),we(([c,l])=>Vo(l)),ae(([c,l,u])=>Vt(l.groupOffsetTree,Math.max(c-u,0),"v")[0]),Ke(),ae(c=>[c])),i),{groupCounts:s,topItemsIndexes:i}},Ve(en,Ct)),An=Me(([{log:e}])=>{const t=te(!1),n=_t(Q(t,we(r=>r),Ke()));return $e(t,r=>{r&&ot(e)("props updated",{},Nt.DEBUG)}),{didMount:n,propsReady:t}},Ve(En),{singleton:!0}),Px=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function au(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Px)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const Qr=Me(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:c,scrollTo:l,smoothScrollTargetReached:u,viewportHeight:f},{log:h}])=>{const p=je(),m=je(),g=te(0);let x=null,y=null,w=null;function k(){x&&(x(),x=null),w&&(w(),w=null),y&&(clearTimeout(y),y=null),Te(c,!1)}return he(Q(p,Ee(n,f,r,g,a,i,h),Ee(e,s,o),ae(([[I,S,C,T,A,j,_,L],F,B,O])=>{const G=au(I),{align:Y,behavior:re,offset:H}=G,W=T-1,ne=ou(G,S,W);let K=Zr(ne,S.offsetTree,F)+j;Y==="end"?(K+=B+Vt(S.sizeTree,ne)[1]-C+O,ne===W&&(K+=_)):Y==="center"?K+=(B+Vt(S.sizeTree,ne)[1]-C+O)/2:K-=A,H&&(K+=H);const M=N=>{k(),N?(L("retrying to scroll to",{location:I},Nt.DEBUG),Te(p,I)):(Te(m,!0),L("list did not change, scroll successful",{},Nt.DEBUG))};if(k(),re==="smooth"){let N=!1;w=$e(t,$=>{N=N||$}),x=Wt(u,()=>{M(N)})}else x=Wt(Q(t,Rx(150)),M);return y=setTimeout(()=>{k()},1200),Te(c,!0),L("scrolling from index to",{behavior:re,index:ne,top:K},Nt.DEBUG),{behavior:re,top:K}})),l),{scrollTargetReached:m,scrollToIndex:p,topListHeight:g}},Ve(en,Ct,En),{singleton:!0});function Rx(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function Ii(e,t){e==0?t():requestAnimationFrame(()=>{Ii(e-1,t)})}function Ai(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const eo=Me(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=te(!0),c=te(0),l=te(!0);return he(Q(i,Ee(c),we(([u,f])=>!!f),Zt(!1)),a),he(Q(i,Ee(c),we(([u,f])=>!!f),Zt(!1)),l),$e(Q(it(t,i),Ee(a,n,e,l),we(([[,u],f,{sizeTree:h},p,m])=>u&&(!He(h)||gi(p))&&!f&&!m),Ee(c)),([,u])=>{Wt(o,()=>{Te(l,!0)}),Ii(4,()=>{Wt(r,()=>{Te(a,!0)}),Te(s,u)})}),{initialItemFinalLocationReached:l,initialTopMostItemIndex:c,scrolledToInitialItem:a}},Ve(en,Ct,Qr,An),{singleton:!0});function lu(e,t){return Math.abs(e-t)<1.01}const to="up",no="down",Ox="none",Mx={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Dx=0,ro=Me(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=te(!1),a=te(!0),c=je(),l=je(),u=te(4),f=te(Dx),h=xt(Q(bi(Q(ye(o),Kn(1),Zt(!0)),Q(ye(o),Kn(1),Zt(!1),Vc(100))),Ke()),!1),p=xt(Q(bi(Q(n,Zt(!0)),Q(n,Zt(!1),Vc(200))),Ke()),!1);he(Q(it(ye(o),ye(f)),ae(([w,k])=>w<=k),Ke()),a),he(Q(a,pn(50)),l);const m=_t(Q(it(r,ye(s),ye(t),ye(e),ye(u)),Qt((w,[{scrollHeight:k,scrollTop:I},S,C,T,A])=>{const j=I+S-k>-A,_={scrollHeight:k,scrollTop:I,viewportHeight:S};if(j){let F,B;return I>w.state.scrollTop?(F="SCROLLED_DOWN",B=w.state.scrollTop-I):(F="SIZE_DECREASED",B=w.state.scrollTop-I||w.scrollTopDelta),{atBottom:!0,atBottomBecause:F,scrollTopDelta:B,state:_}}let L;return _.scrollHeight>w.state.scrollHeight?L="SIZE_INCREASED":S<w.state.viewportHeight?L="VIEWPORT_HEIGHT_DECREASING":I<w.state.scrollTop?L="SCROLLING_UPWARDS":L="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:L,state:_}},Mx),Ke((w,k)=>w&&w.atBottom===k.atBottom))),g=xt(Q(r,Qt((w,{scrollHeight:k,scrollTop:I,viewportHeight:S})=>{if(lu(w.scrollHeight,k))return{changed:!1,jump:0,scrollHeight:k,scrollTop:I};{const C=k-(I+S)<1;return w.scrollTop!==I&&C?{changed:!0,jump:w.scrollTop-I,scrollHeight:k,scrollTop:I}:{changed:!0,jump:0,scrollHeight:k,scrollTop:I}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),we(w=>w.changed),ae(w=>w.jump)),0);he(Q(m,ae(w=>w.atBottom)),i),he(Q(i,pn(50)),c);const x=te(no);he(Q(r,ae(({scrollTop:w})=>w),Ke(),Qt((w,k)=>ot(p)?{direction:w.direction,prevScrollTop:k}:{direction:k<w.prevScrollTop?to:no,prevScrollTop:k},{direction:no,prevScrollTop:0}),ae(w=>w.direction)),x),he(Q(r,pn(50),Zt(Ox)),x);const y=te(0);return he(Q(h,we(w=>!w),Zt(0)),y),he(Q(o,pn(100),Ee(h),we(([w,k])=>!!k),Qt(([w,k],[I])=>[k,I],[0,0]),ae(([w,k])=>k-w)),y),{atBottomState:m,atBottomStateChange:c,atBottomThreshold:u,atTopStateChange:l,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:g,scrollDirection:x,scrollVelocity:y}},Ve(Ct)),Ko="top",qo="bottom",cu="none";function uu(e,t,n){return typeof e=="number"?n===to&&t===Ko||n===no&&t===qo?e:0:n===to?t===Ko?e.main:e.reverse:t===qo?e.main:e.reverse}function du(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const Ni=Me(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=je(),i=te(0),a=te(0),c=te(0),l=xt(Q(it(ye(r),ye(o),ye(n),ye(s,Jr),ye(c),ye(i),ye(t),ye(e),ye(a)),ae(([u,f,h,[p,m],g,x,y,w,k])=>{const I=u-w,S=x+y,C=Math.max(h-I,0);let T=cu;const A=du(k,Ko),j=du(k,qo);return p-=w,p+=h+y,m+=h+y,m-=w,p>u+S-A&&(T=to),m<u-C+f+j&&(T=no),T!==cu?[Math.max(I-h-uu(g,Ko,T)-A,0),I-C-y+f+uu(g,qo,T)+j]:null}),we(u=>u!=null),Ke(Jr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:c,topListHeight:i,visibleRange:l}},Ve(Ct),{singleton:!0});function Lx(e,t,n){if(Vo(t)){const r=ru(e,t);return[{index:Vt(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 ji={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function Go(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:c}=o;let l=0,u=0;if(e.length>0){l=e[0].offset;const g=e[e.length-1];u=g.offset+g.size}const f=n-i,h=a+f*c+(f-1)*r,p=l,m=h-u;return{bottom:u,firstItemIndex:s,items:hu(e,o,s),offsetBottom:m,offsetTop:l,top:p,topItems:hu(t,o,s),topListHeight:t.reduce((g,x)=>x.size+g,0),totalCount:n}}function fu(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,c=Ai(t,a),l=Array.from({length:a}).map((u,f)=>({data:s[f+c],index:f+c,offset:0,size:0}));return Go(l,[],a,o,n,r)}function hu(e,t,n){if(e.length===0)return[];if(!Vo(t))return e.map(l=>({...l,index:l.index+n,originalIndex:l.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=Uo(t.groupOffsetTree,r,o);let a,c=0;for(const l of e){(!a||a.end<l.index)&&(a=i.shift(),c=t.groupIndices.indexOf(a.start));let u;l.index===a.start?u={index:c,type:"group"}:u={groupIndex:c,index:l.index-(c+1)+n},s.push({...u,data:l.data,offset:l.offset,originalIndex:l.index,size:l.size})}return s}const Yn=Me(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:c},{initialTopMostItemIndex:l,scrolledToInitialItem:u},{topListHeight:f},h,{didMount:p},{recalcInProgress:m}])=>{const g=te([]),x=te(0),y=je();he(s.topItemsIndexes,g);const w=xt(Q(it(p,m,ye(c,Jr),ye(o),ye(r),ye(l),u,ye(g),ye(t),ye(n),e),we(([C,T,,A,,,,,,,j])=>{const _=j&&j.length!==A;return C&&!T&&!_}),ae(([,,[C,T],A,j,_,L,F,B,O,G])=>{const Y=j,{offsetTree:re,sizeTree:H}=Y,W=ot(x);if(A===0)return{...ji,totalCount:A};if(C===0&&T===0)return W===0?{...ji,totalCount:A}:fu(W,_,j,B,O,G||[]);if(He(H))return W>0?null:Go(Lx(Ai(_,A),Y,G),[],A,O,Y,B);const ne=[];if(F.length>0){const D=F[0],q=F[F.length-1];let U=0;for(const P of Uo(H,D,q)){const V=P.value,ee=Math.max(P.start,D),ce=Math.min(P.end,q);for(let ue=ee;ue<=ce;ue++)ne.push({data:G==null?void 0:G[ue],index:ue,offset:U,size:V}),U+=V}}if(!L)return Go([],ne,A,O,Y,B);const K=F.length>0?F[F.length-1]+1:0,M=kx(re,C,T,K);if(M.length===0)return null;const N=A-1,$=Bo([],D=>{for(const q of M){const U=q.value;let P=U.offset,V=q.start;const ee=U.size;if(U.offset<C){V+=Math.floor((C-U.offset+O)/(ee+O));const ue=V-q.start;P+=ue*ee+ue*O}V<K&&(P+=(K-V)*ee,V=K);const ce=Math.min(q.end,N);for(let ue=V;ue<=ce&&!(P>=T);ue++)D.push({data:G==null?void 0:G[ue],index:ue,offset:P,size:ee}),P+=ee+O}});return Go($,ne,A,O,Y,B)}),we(C=>C!==null),Ke()),ji);he(Q(e,we(gi),ae(C=>C==null?void 0:C.length)),o),he(Q(w,ae(C=>C.topListHeight)),f),he(f,a),he(Q(w,ae(C=>[C.top,C.bottom])),i),he(Q(w,ae(C=>C.items)),y);const k=_t(Q(w,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(Jr),ae(([C])=>C))),I=_t(Q(w,pn(200),we(({items:C,topItems:T})=>C.length>0&&C[0].originalIndex===T.length),ae(({items:C})=>C[0].index),Ke())),S=_t(Q(w,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}}),Ke(tu)));return{endReached:k,initialItemCount:x,itemsRendered:y,listState:w,rangeChanged:S,startReached:I,topItemsIndexes:g,...h}},Ve(en,iu,Ni,eo,Qr,ro,An,Ti),{singleton:!0}),pu=Me(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=je(),i=xt(Q(it(n,e,r,t,o),ae(([a,c,l,u,f])=>a+c+l+u+f.offsetBottom+f.bottom)),0);return he(ye(i),s),{totalListHeight:i,totalListHeightChanged:s}},Ve(Ct,Yn),{singleton:!0}),$x=Me(([{viewportHeight:e},{totalListHeight:t}])=>{const n=te(!1),r=xt(Q(it(n,e,t),we(([o])=>o),ae(([,o,s])=>Math.max(0,o-s)),pn(0),Ke()),0);return{alignToBottom:n,paddingTopAddition:r}},Ve(Ct,pu),{singleton:!0}),mu=Me(()=>({context:te(null)})),Fx=({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,gu=Me(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:c},{scrollToIndex:l}])=>{const u=je();return he(Q(u,Ee(t,c,n,s,o,r,a),Ee(e),ae(([[f,h,p,m,g,x,y,w],k])=>{const{align:I,behavior:S,calculateViewLocation:C=Fx,done:T,...A}=f,j=ou(f,h,m-1),_=Zr(j,h.offsetTree,k)+g+x,L=_+Vt(h.sizeTree,j)[1],F=w+x,B=w+p-y,O=C({itemBottom:L,itemTop:_,locationParams:{align:I,behavior:S,...A},viewportBottom:B,viewportTop:F});return O?T&&Wt(Q(i,we(G=>!G),Kn(ot(i)?1:2)),T):T&&T(),O}),we(f=>f!==null)),l),{scrollIntoView:u}},Ve(en,Ct,Qr,Yn,En),{singleton:!0});function xu(e){return e?e==="smooth"?"smooth":"auto":!1}const zx=(e,t)=>typeof e=="function"?xu(e(t)):t&&xu(e),Bx=Me(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:c,propsReady:l},{log:u},{scrollingInProgress:f},{context:h},{scrollIntoView:p}])=>{const m=te(!1),g=je();let x=null;function y(S){Te(i,{align:"end",behavior:S,index:"LAST"})}$e(Q(it(Q(ye(t),Kn(1)),c),Ee(ye(m),s,a,f),ae(([[S,C],T,A,j,_])=>{let L=C&&j,F="auto";return L&&(F=zx(T,A||_),L=L&&!!F),{followOutputBehavior:F,shouldFollow:L,totalCount:S}}),we(({shouldFollow:S})=>S)),({followOutputBehavior:S,totalCount:C})=>{x&&(x(),x=null),ot(n)?requestAnimationFrame(()=>{ot(u)("following output to ",{totalCount:C},Nt.DEBUG),y(S)}):x=Wt(e,()=>{ot(u)("following output to ",{totalCount:C},Nt.DEBUG),y(S),x=null})});function w(S){const C=Wt(o,T=>{S&&!T.atBottom&&T.notAtBottomBecause==="SIZE_INCREASED"&&!x&&(ot(u)("scrolling to bottom due to increased size",{},Nt.DEBUG),y("auto"))});setTimeout(C,100)}$e(Q(it(ye(m),t,l),we(([S,,C])=>S&&C),Qt(({value:S},[,C])=>({refreshed:S===C,value:C}),{refreshed:!1,value:0}),we(({refreshed:S})=>S),Ee(m,t)),([,S])=>{ot(a)&&w(S!==!1)}),$e(g,()=>{w(ot(m)!==!1)}),$e(it(ye(m),o),([S,C])=>{S&&!C.atBottom&&C.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&y("auto")});const k=te(null),I=je();return he(bi(Q(ye(r),ae(S=>{var C;return(C=S==null?void 0:S.length)!=null?C:0})),Q(ye(t))),I),$e(Q(it(Q(I,Kn(1)),c),Ee(ye(k),a,f,h),ae(([[S,C],T,A,j,_])=>C&&A&&(T==null?void 0:T({context:_,totalCount:S,scrollingInProgress:j}))),we(S=>!!S),pn(0)),S=>{x&&(x(),x=null),ot(n)?requestAnimationFrame(()=>{ot(u)("scrolling into view",{}),Te(p,S)}):x=Wt(e,()=>{ot(u)("scrolling into view",{}),Te(p,S),x=null})}),{autoscrollToBottom:g,followOutput:m,scrollIntoViewOnChange:k}},Ve(en,ro,Qr,eo,An,En,Ct,mu,gu)),Ux=Me(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(he(Q(a,Ee(s),we(([,c])=>c!==0),Ee(o,r,t,n,e),ae(([[,c],l,u,f,h,p=[]])=>fu(c,l,u,f,h,p))),i),{}),Ve(en,eo,Yn,An),{singleton:!0}),Hx=Me(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=te(0);return $e(Q(e,Ee(r),we(([,o])=>o!==0),ae(([,o])=>({top:o}))),o=>{Wt(Q(n,Kn(1),we(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Te(t,o)})})}),{initialScrollTop:r}},Ve(An,Ct,Yn),{singleton:!0}),bu=Me(([{scrollVelocity:e}])=>{const t=te(!1),n=je(),r=te(!1);return he(Q(e,Ee(r,t,n),we(([o,s])=>!!s),ae(([o,s,i,a])=>{const{enter:c,exit:l}=s;if(i){if(l(o,a))return!1}else if(c(o,a))return!0;return i}),Ke()),t),$e(Q(it(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(ro),{singleton:!0}),_i=Me(([{scrollContainerState:e,scrollTo:t}])=>{const n=je(),r=je(),o=je(),s=te(!1),i=te(void 0);return he(Q(it(n,r),ae(([{scrollHeight:a,scrollTop:c,viewportHeight:l},{offsetTop:u}])=>({scrollHeight:a,scrollTop:Math.max(0,c-u),viewportHeight:l}))),e),he(Q(t,Ee(r),ae(([a,{offsetTop:c}])=>({...a,top:a.top+c}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},Ve(Ct)),Wx=Me(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:c}])=>{const l=je(),u=te(void 0),f=te(null),h=te(null);return he(a,f),he(c,h),$e(Q(l,Ee(t,r,i,f,h,n)),([p,m,g,x,y,w,k])=>{const I=Ix(m.sizeTree);x&&y!==null&&w!==null&&(g=y.scrollTop-w.offsetTop),g-=k,p({ranges:I,scrollTop:g})}),he(Q(u,we(gi),ae(Vx)),o),he(Q(s,Ee(u),we(([,p])=>p!==void 0),Ke(),ae(([,p])=>p.ranges)),e),{getState:l,restoreStateFrom:u}},Ve(en,Ct,eo,An,_i));function Vx(e){return{align:"start",index:0,offset:e.scrollTop}}const Kx=Me(([{topItemsIndexes:e}])=>{const t=te(0);return he(Q(t,we(n=>n>=0),ae(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},Ve(Yn));function yu(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const qx=yu(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),Gx=Me(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:c},{beforeUnshiftWith:l,gap:u,shiftWithOffset:f,sizes:h},{log:p},{recalcInProgress:m}])=>{const g=_t(Q(c,Ee(i),Qt(([,y,w,k],[{bottom:I,items:S,offsetBottom:C,totalCount:T},A])=>{const j=I+C;let _=0;return w===T&&y.length>0&&S.length>0&&(S[0].originalIndex===0&&y[0].originalIndex===0||(_=j-k,_!==0&&(_+=A))),[_,S,T,j]},[0,[],0,0]),we(([y])=>y!==0),Ee(r,a,n,o,p,m),we(([,y,w,k,,,I])=>!I&&!k&&y!==0&&w===to),ae(([[y],,,,,w])=>(w("Upward scrolling compensation",{amount:y},Nt.DEBUG),y))));function x(y){y>0?(Te(t,{behavior:"auto",top:-y}),Te(e,0)):(Te(e,0),Te(t,{behavior:"auto",top:-y}))}return $e(Q(g,Ee(e,s)),([y,w,k])=>{k&&qx()?Te(e,w-y):x(-y)}),$e(Q(it(xt(s,!1),e,m),we(([y,w,k])=>!y&&!k&&w!==0),ae(([y,w])=>w),pn(1)),x),he(Q(f,ae(y=>({top:-y}))),t),$e(Q(l,Ee(h,u),ae(([y,{groupIndices:w,lastSize:k,sizeTree:I},S])=>{function C(T){return T*(k+S)}if(w.length===0)return C(y);{let T=0;const A=Xr(I,0);let j=0,_=0;for(;j<y;){j++,T+=A;let L=w.length===_+1?1/0:w[_+1]-w[_]-1;j+L>y&&(T-=A,L=y-j+1),j+=L,T+=C(L),_++}return T}})),y=>{Te(e,y),requestAnimationFrame(()=>{Te(t,{top:y}),requestAnimationFrame(()=>{Te(e,0),Te(m,!1)})})}),{deviation:e}},Ve(Ct,ro,Yn,en,En,Ti)),Yx=Me(([e,t,n,r,o,s,i,a,c,l,u])=>({...e,...t,...n,...r,...o,...s,...i,...a,...c,...l,...u}),Ve(Ni,Ux,An,bu,pu,Hx,$x,_i,gu,En,mu)),wu=Me(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:c,statefulTotalCount:l,totalCount:u,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:m},g,x,y,{listState:w,topItemsIndexes:k,...I},{scrollToIndex:S},C,{topItemCount:T},{groupCounts:A},j])=>(he(I.rangeChanged,j.scrollSeekRangeChanged),he(Q(j.windowViewportRect,ae(_=>_.visibleHeight)),g.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,...y,groupIndices:s,itemSize:i,listState:w,scrollToIndex:S,statefulTotalCount:l,trackItemSizes:f,...I,...j,...g,sizes:c,...x}),Ve(en,eo,Ct,Wx,Bx,Yn,Qr,Gx,Kx,iu,Yx));function Xx(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 Yo=typeof document<"u"?v.useLayoutEffect:v.useEffect;function vu(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 c(x,y){x.propsReady&&Te(x.propsReady,!1);for(const w of r){const k=x[t.required[w]];Te(k,y[w])}for(const w of o)if(w in y){const k=x[t.optional[w]];Te(k,y[w])}x.propsReady&&Te(x.propsReady,!0)}function l(x){return s.reduce((y,w)=>(y[w]=k=>{const I=x[t.methods[w]];Te(I,k)},y),{})}function u(x){return i.reduce((y,w)=>(y[w]=fx(x[t.events[w]]),y),{})}const f=v.forwardRef((x,y)=>{const{children:w,...k}=x,[I]=v.useState(()=>Bo(px(e),T=>{c(T,k)})),[S]=v.useState(Wc(u,I));Yo(()=>{for(const T of i)T in k&&$e(S[T],k[T]);return()=>{Object.values(S).map(xi)}},[k,S,I]),Yo(()=>{c(I,k)}),v.useImperativeHandle(y,Uc(l(I)));const C=n;return d.jsx(a.Provider,{value:I,children:n?d.jsx(C,{...Xx([...r,...o,...i],k),children:w}):w})}),h=x=>{const y=v.useContext(a);return v.useCallback(w=>{Te(y[x],w)},[y,x])},p=x=>{const y=v.useContext(a)[x],w=v.useCallback(k=>$e(y,k),[y]);return v.useSyncExternalStore(w,()=>ot(y),()=>ot(y))},m=x=>{const y=v.useContext(a)[x],[w,k]=v.useState(Wc(ot,y));return Yo(()=>$e(y,I=>{I!==w&&k(Uc(I))}),[y,w]),w},g=v.version.startsWith("18")?p:m;return{Component:f,useEmitter:(x,y)=>{const w=v.useContext(a)[x];Yo(()=>$e(w,y),[y,w])},useEmitterValue:g,usePublisher:h}}const Su=v.createContext(void 0),Cu=v.createContext(void 0),Tu=typeof document<"u"?v.useLayoutEffect:v.useEffect;function Pi(e){return"self"in e}function Jx(e){return"body"in e}function ku(e,t,n,r=wr,o,s){const i=v.useRef(null),a=v.useRef(null),c=v.useRef(null),l=v.useCallback(h=>{let p,m,g;const x=h.target;if(Jx(x)||Pi(x)){const w=Pi(x)?x:x.defaultView;g=s?w.scrollX:w.scrollY,p=s?w.document.documentElement.scrollWidth:w.document.documentElement.scrollHeight,m=s?w.innerWidth:w.innerHeight}else g=s?x.scrollLeft:x.scrollTop,p=s?x.scrollWidth:x.scrollHeight,m=s?x.offsetWidth:x.offsetHeight;const y=()=>{e({scrollHeight:p,scrollTop:Math.max(g,0),viewportHeight:m})};h.suppressFlushSync?y():Hs.flushSync(y),a.current!==null&&(g===a.current||g<=0||g===p-m)&&(a.current=null,t(!0),c.current&&(clearTimeout(c.current),c.current=null))},[e,t,s]);v.useEffect(()=>{const h=o||i.current;return r(o||i.current),l({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",l,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",l)}},[i,l,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 g,x,y;Pi(p)?(x=Math.max(In(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),g=s?p.innerWidth:p.innerHeight,y=s?window.scrollX:window.scrollY):(x=p[s?"scrollWidth":"scrollHeight"],g=In(p,s?"width":"height"),y=p[s?"scrollLeft":"scrollTop"]);const w=x-g;if(h.top=Math.ceil(Math.max(Math.min(w,h.top),0)),lu(g,x)||h.top===y){e({scrollHeight:x,scrollTop:y,viewportHeight:g}),m&&t(!0);return}m?(a.current=h.top,c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{c.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 Ri="-webkit-sticky",Eu="sticky",Oi=yu(()=>{if(typeof document>"u")return Eu;const e=document.createElement("div");return e.style.position=Ri,e.style.position===Ri?Ri:Eu});function Mi(e){return e}const Zx=Me(()=>{const e=te(a=>`Item ${a}`),t=te(a=>`Group ${a}`),n=te({}),r=te(Mi),o=te("div"),s=te(wr),i=(a,c=null)=>xt(Q(n,ae(l=>l[a]),Ke()),c);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")}}),Qx=Me(([e,t])=>({...e,...t}),Ve(wu,Zx)),eb=({height:e})=>d.jsx("div",{style:{height:e}}),tb={overflowAnchor:"none",position:Oi(),zIndex:1},Iu={overflowAnchor:"none"},nb={...Iu,display:"inline-block",height:"100%"},Au=v.memo(function({showTopList:e=!1}){const t=Se("listState"),n=Ft("sizeRanges"),r=Se("useWindowScroll"),o=Se("customScrollParent"),s=Ft("windowScrollContainerState"),i=Ft("scrollContainerState"),a=o||r?s:i,c=Se("itemContent"),l=Se("context"),u=Se("groupContent"),f=Se("trackItemSizes"),h=Se("itemSize"),p=Se("log"),m=Ft("gap"),g=Se("horizontalDirection"),{callbackRef:x}=xx(n,h,f,e?wr:a,p,m,o,g,Se("skipAnimationFrameInResizeObserver")),[y,w]=v.useState(0);Di("deviation",O=>{y!==O&&w(O)});const k=Se("EmptyPlaceholder"),I=Se("ScrollSeekPlaceholder")||eb,S=Se("ListComponent"),C=Se("ItemComponent"),T=Se("GroupComponent"),A=Se("computeItemKey"),j=Se("isSeeking"),_=Se("groupIndices").length>0,L=Se("alignToBottom"),F=Se("initialItemFinalLocationReached"),B=e?{}:{boxSizing:"border-box",...g?{display:"inline-block",height:"100%",marginLeft:y!==0?y:L?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:y!==0?y:L?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...F?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&k?d.jsx(k,{...bt(k,l)}):d.jsx(S,{...bt(S,l),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:x,style:B,children:(e?t.topItems:t.items).map(O=>{const G=O.originalIndex,Y=A(G+t.firstItemIndex,O.data,l);return j?v.createElement(I,{...bt(I,l),height:O.size,index:O.index,key:Y,type:O.type||"item",...O.type==="group"?{}:{groupIndex:O.groupIndex}}):O.type==="group"?v.createElement(T,{...bt(T,l),"data-index":G,"data-item-index":O.index,"data-known-size":O.size,key:Y,style:tb},u(O.index,l)):v.createElement(C,{...bt(C,l),...ib(C,O.data),"data-index":G,"data-item-group-index":O.groupIndex,"data-item-index":O.index,"data-known-size":O.size,key:Y,style:g?nb:Iu},_?c(O.index,O.groupIndex,O.data,l):c(O.index,O.data,l))})})}),rb={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},ob={outline:"none",overflowX:"auto",position:"relative"},Xo=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),sb={position:Oi(),top:0,width:"100%",zIndex:1};function bt(e,t){if(typeof e!="string")return{context:t}}function ib(e,t){return{item:typeof e=="string"?void 0:t}}const ab=v.memo(function(){const e=Se("HeaderComponent"),t=Ft("headerHeight"),n=Se("HeaderFooterTag"),r=qn(v.useMemo(()=>s=>{t(In(s,"height"))},[t]),!0,Se("skipAnimationFrameInResizeObserver")),o=Se("context");return e?d.jsx(n,{ref:r,children:d.jsx(e,{...bt(e,o)})}):null}),lb=v.memo(function(){const e=Se("FooterComponent"),t=Ft("footerHeight"),n=Se("HeaderFooterTag"),r=qn(v.useMemo(()=>s=>{t(In(s,"height"))},[t]),!0,Se("skipAnimationFrameInResizeObserver")),o=Se("context");return e?d.jsx(n,{ref:r,children:d.jsx(e,{...bt(e,o)})}):null});function Nu({useEmitter:e,useEmitterValue:t,usePublisher:n}){return v.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),c=t("ScrollerComponent"),l=n("smoothScrollTargetReached"),u=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback:m}=ku(a,l,c,u,void 0,f);return e("scrollTo",m),e("scrollBy",h),d.jsx(c,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?ob:rb,...o},tabIndex:0,...i,...bt(c,s),children:r})})}function ju({useEmitter:e,useEmitterValue:t,usePublisher:n}){return v.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),c=t("ScrollerComponent"),l=n("smoothScrollTargetReached"),u=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),p=v.useRef(null),m=t("scrollerRef"),{scrollByCallback:g,scrollerRef:x,scrollToCallback:y}=ku(a,l,c,m,h);return Tu(()=>{var w;return x.current=h||((w=p.current)==null?void 0:w.ownerDocument.defaultView),()=>{x.current=null}},[x,h]),e("windowScrollTo",y),e("scrollBy",g),d.jsx(c,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...u!==0?{height:u+f}:{}},...i,...bt(c,s),children:r})})}const cb=({children:e})=>{const t=v.useContext(Su),n=Ft("viewportHeight"),r=Ft("fixedItemHeight"),o=Se("alignToBottom"),s=Se("horizontalDirection"),i=v.useMemo(()=>Hc(n,c=>In(c,s?"width":"height")),[n,s]),a=qn(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:Xo(o),children:e})},ub=({children:e})=>{const t=v.useContext(Su),n=Ft("windowViewportRect"),r=Ft("fixedItemHeight"),o=Se("customScrollParent"),s=Gc(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:Xo(i),children:e})},db=({children:e})=>{const t=Se("TopItemListComponent")||"div",n=Se("headerHeight"),r={...sb,marginTop:`${n}px`},o=Se("context");return d.jsx(t,{style:r,...bt(t,o),children:e})},fb=v.memo(function(e){const t=Se("useWindowScroll"),n=Se("topItemsIndexes").length>0,r=Se("customScrollParent"),o=Se("context");return d.jsxs(r||t?mb:pb,{...e,context:o,children:[n&&d.jsx(db,{children:d.jsx(Au,{showTopList:!0})}),d.jsxs(r||t?ub:cb,{children:[d.jsx(ab,{}),d.jsx(Au,{}),d.jsx(lb,{})]})]})}),{Component:hb,useEmitter:Di,useEmitterValue:Se,usePublisher:Ft}=vu(Qx,{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"}},fb),pb=Nu({useEmitter:Di,useEmitterValue:Se,usePublisher:Ft}),mb=ju({useEmitter:Di,useEmitterValue:Se,usePublisher:Ft}),gb=hb;Ve(wu,Me(()=>{const e=te(l=>d.jsxs("td",{children:["Item $",l]})),t=te(null),n=te(l=>d.jsxs("td",{colSpan:1e3,children:["Group ",l]})),r=te(null),o=te(null),s=te({}),i=te(Mi),a=te(wr),c=(l,u=null)=>xt(Q(s,ae(f=>f[l]),Ke()),u);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:c("EmptyPlaceholder"),FillerRow:c("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:c("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder"),TableBodyComponent:c("TableBody","tbody"),TableComponent:c("Table","table"),TableFooterComponent:c("TableFoot","tfoot"),TableHeadComponent:c("TableHead","thead"),TableRowComponent:c("TableRow","tr"),GroupComponent:c("Group","tr")}})),Oi();const _u={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},xb={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Pu,floor:Jo,max:oo,min:Li,round:Ru}=Math;function Ou(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function bb(e){return{...xb,items:e}}function Zo(e,t){return e&&e.width===t.width&&e.height===t.height}function yb(e,t){return e&&e.column===t.column&&e.row===t.row}const wb=Me(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:c,scrollTop:l,smoothScrollTargetReached:u,viewportHeight:f},h,p,{didMount:m,propsReady:g},{customScrollParent:x,useWindowScroll:y,windowScrollContainerState:w,windowScrollTo:k,windowViewportRect:I},S])=>{const C=te(0),T=te(0),A=te(_u),j=te({height:0,width:0}),_=te({height:0,width:0}),L=je(),F=je(),B=te(0),O=te(null),G=te({column:0,row:0}),Y=je(),re=je(),H=te(!1),W=te(0),ne=te(!0),K=te(!1),M=te(!1);$e(Q(m,Ee(W),we(([P,V])=>!!V)),()=>{Te(ne,!1)}),$e(Q(it(m,ne,_,j,W,K),we(([P,V,ee,ce,,ue])=>P&&!V&&ee.height!==0&&ce.height!==0&&!ue)),([,,,,P])=>{Te(K,!0),Ii(1,()=>{Te(L,P)}),Wt(Q(l),()=>{Te(t,[0,0]),Te(ne,!0)})}),he(Q(re,we(P=>P!=null&&P.scrollTop>0),Zt(0)),T),$e(Q(m,Ee(re),we(([,P])=>P!=null)),([,P])=>{P&&(Te(j,P.viewport),Te(_,P.item),Te(G,P.gap),P.scrollTop>0&&(Te(H,!0),Wt(Q(l,Kn(1)),V=>{Te(H,!1)}),Te(c,{top:P.scrollTop})))}),he(Q(j,ae(({height:P})=>P)),f),he(Q(it(ye(j,Zo),ye(_,Zo),ye(G,(P,V)=>P&&P.column===V.column&&P.row===V.row),ye(l)),ae(([P,V,ee,ce])=>({gap:ee,item:V,scrollTop:ce,viewport:P}))),Y),he(Q(it(ye(C),r,ye(G,yb),ye(_,Zo),ye(j,Zo),ye(O),ye(T),ye(H),ye(ne),ye(W)),we(([,,,,,,,P])=>!P),ae(([P,[V,ee],ce,ue,be,Ae,Ie,,Xe,ze])=>{const{column:Ze,row:Be}=ce,{height:dt,width:at}=ue,{width:ct}=be;if(Ie===0&&(P===0||ct===0))return _u;if(at===0){const et=Ai(ze,P),ht=et+Math.max(Ie-1,0);return bb(Ou(et,ht,Ae))}const ft=Mu(ct,at,Ze);let tt,nt;Xe?V===0&&ee===0&&Ie>0?(tt=0,nt=Ie-1):(tt=ft*Jo((V+Be)/(dt+Be)),nt=ft*Pu((ee+Be)/(dt+Be))-1,nt=Li(P-1,oo(nt,ft-1)),tt=Li(nt,oo(0,tt))):(tt=0,nt=-1);const ut=Ou(tt,nt,Ae),{bottom:qe,top:Qe}=Du(be,ce,ue,ut),De=Pu(P/ft),Le=De*dt+(De-1)*Be-qe;return{bottom:qe,itemHeight:dt,items:ut,itemWidth:at,offsetBottom:Le,offsetTop:Qe,top:Qe}})),A),he(Q(O,we(P=>P!==null),ae(P=>P.length)),C),he(Q(it(j,_,A,G),we(([P,V,{items:ee}])=>ee.length>0&&V.height!==0&&P.height!==0),ae(([P,V,{items:ee},ce])=>{const{bottom:ue,top:be}=Du(P,ce,V,ee);return[be,ue]}),Ke(Jr)),t);const N=te(!1);he(Q(l,Ee(N),ae(([P,V])=>V||P!==0)),N);const $=_t(Q(it(A,C),we(([{items:P}])=>P.length>0),Ee(N),we(([[P,V],ee])=>{const ce=P.items[P.items.length-1].index===V-1;return(ee||P.bottom>0&&P.itemHeight>0&&P.offsetBottom===0&&P.items.length===V)&&ce}),ae(([[,P]])=>P-1),Ke())),D=_t(Q(ye(A),we(({items:P})=>P.length>0&&P[0].index===0),Zt(0),Ke())),q=_t(Q(ye(A),Ee(H),we(([{items:P},V])=>P.length>0&&!V),ae(([{items:P}])=>({endIndex:P[P.length-1].index,startIndex:P[0].index})),Ke(tu),pn(0)));he(q,p.scrollSeekRangeChanged),he(Q(L,Ee(j,_,C,G),ae(([P,V,ee,ce,ue])=>{const be=au(P),{align:Ae,behavior:Ie,offset:Xe}=be;let ze=be.index;ze==="LAST"&&(ze=ce-1),ze=oo(0,ze,Li(ce-1,ze));let Ze=$i(V,ue,ee,ze);return Ae==="end"?Ze=Ru(Ze-V.height+ee.height):Ae==="center"&&(Ze=Ru(Ze-V.height/2+ee.height/2)),Xe&&(Ze+=Xe),{behavior:Ie,top:Ze}})),c);const U=xt(Q(A,ae(P=>P.offsetBottom+P.bottom)),0);return he(Q(I,ae(P=>({height:P.visibleHeight,width:P.visibleWidth}))),j),{customScrollParent:x,data:O,deviation:B,footerHeight:o,gap:G,headerHeight:s,increaseViewportBy:e,initialItemCount:T,itemDimensions:_,overscan:n,restoreStateFrom:re,scrollBy:i,scrollContainerState:a,scrollHeight:F,scrollTo:c,scrollToIndex:L,scrollTop:l,smoothScrollTargetReached:u,totalCount:C,useWindowScroll:y,viewportDimensions:j,windowScrollContainerState:w,windowScrollTo:k,windowViewportRect:I,...p,gridState:A,horizontalDirection:M,initialTopMostItemIndex:W,totalListHeight:U,...h,endReached:$,propsReady:g,rangeChanged:q,startReached:D,stateChanged:Y,stateRestoreInProgress:H,...S}},Ve(Ni,Ct,ro,bu,An,_i,En));function Mu(e,t,n){return oo(1,Jo((e+n)/(Jo(t)+n)))}function Du(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=$i(e,t,n,r[0].index);return{bottom:$i(e,t,n,r[r.length-1].index)+o,top:s}}function $i(e,t,n,r){const o=Mu(e.width,n.width,t.column),s=Jo(r/o),i=s*n.height+oo(0,s-1)*t.row;return i>0?i+t.row:i}const vb=Me(()=>{const e=te(f=>`Item ${f}`),t=te({}),n=te(null),r=te("virtuoso-grid-item"),o=te("virtuoso-grid-list"),s=te(Mi),i=te("div"),a=te(wr),c=(f,h=null)=>xt(Q(t,ae(p=>p[f]),Ke()),h),l=te(!1),u=te(!1);return he(ye(u),l),{components:t,computeItemKey:s,context:n,FooterComponent:c("Footer"),HeaderComponent:c("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:c("Item","div"),itemContent:e,listClassName:o,ListComponent:c("List","div"),readyStateChanged:l,reportReadyState:u,ScrollerComponent:c("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:c("ScrollSeekPlaceholder","div")}}),Sb=Me(([e,t])=>({...e,...t}),Ve(wb,vb)),Cb=v.memo(function(){const e=Ge("gridState"),t=Ge("listClassName"),n=Ge("itemClassName"),r=Ge("itemContent"),o=Ge("computeItemKey"),s=Ge("isSeeking"),i=zt("scrollHeight"),a=Ge("ItemComponent"),c=Ge("ListComponent"),l=Ge("ScrollSeekPlaceholder"),u=Ge("context"),f=zt("itemDimensions"),h=zt("gap"),p=Ge("log"),m=Ge("stateRestoreInProgress"),g=zt("reportReadyState"),x=qn(v.useMemo(()=>y=>{const w=y.parentElement.parentElement.scrollHeight;i(w);const k=y.firstChild;if(k){const{height:I,width:S}=k.getBoundingClientRect();f({height:I,width:S})}h({column:$u("column-gap",getComputedStyle(y).columnGap,p),row:$u("row-gap",getComputedStyle(y).rowGap,p)})},[i,f,h,p]),!0,!1);return Tu(()=>{e.itemHeight>0&&e.itemWidth>0&&g(!0)},[e]),m?null:d.jsx(c,{className:t,ref:x,...bt(c,u),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(y=>{const w=o(y.index,y.data,u);return s?d.jsx(l,{...bt(l,u),height:e.itemHeight,index:y.index,width:e.itemWidth},w):v.createElement(a,{...bt(a,u),className:n,"data-index":y.index,key:w},r(y.index,y.data,u))})})}),Tb=v.memo(function(){const e=Ge("HeaderComponent"),t=zt("headerHeight"),n=Ge("headerFooterTag"),r=qn(v.useMemo(()=>s=>{t(In(s,"height"))},[t]),!0,!1),o=Ge("context");return e?d.jsx(n,{ref:r,children:d.jsx(e,{...bt(e,o)})}):null}),kb=v.memo(function(){const e=Ge("FooterComponent"),t=zt("footerHeight"),n=Ge("headerFooterTag"),r=qn(v.useMemo(()=>s=>{t(In(s,"height"))},[t]),!0,!1),o=Ge("context");return e?d.jsx(n,{ref:r,children:d.jsx(e,{...bt(e,o)})}):null}),Eb=({children:e})=>{const t=v.useContext(Cu),n=zt("itemDimensions"),r=zt("viewportDimensions"),o=qn(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:Xo(!1),children:e})},Ib=({children:e})=>{const t=v.useContext(Cu),n=zt("windowViewportRect"),r=zt("itemDimensions"),o=Ge("customScrollParent"),s=Gc(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:Xo(!1),children:e})},Ab=v.memo(function({...e}){const t=Ge("useWindowScroll"),n=Ge("customScrollParent"),r=n||t?jb:Nb,o=n||t?Ib:Eb,s=Ge("context");return d.jsx(r,{...e,...bt(r,s),children:d.jsxs(o,{children:[d.jsx(Tb,{}),d.jsx(Cb,{}),d.jsx(kb,{})]})})}),{useEmitter:Lu,useEmitterValue:Ge,usePublisher:zt}=vu(Sb,{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"}},Ab),Nb=Nu({useEmitter:Lu,useEmitterValue:Ge,usePublisher:zt}),jb=ju({useEmitter:Lu,useEmitterValue:Ge,usePublisher:zt});function $u(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Nt.WARN),t==="normal"?0:parseInt(t??"0",10)}function _b({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 Pb="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 Rb({data:e}){return Array.isArray(e)?e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?d.jsx("div",{className:Pb,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 Fu="data:";function Ob(e){if(!e)return[];const t=[],n=e.split(/\r?\n/);for(const r of n){const o=r.trim();if(!o||!o.startsWith(Fu))continue;const s=o.slice(Fu.length).trim();if(!s||s.toLowerCase()==="[done]")continue;const i=pr(s);i&&typeof i=="object"&&t.push(i)}return t}function Mb(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 zu(e){return v.useMemo(()=>{const t=e.content.filter(l=>l.type==="text");if(!t.length)return null;let r=t.flatMap(l=>Ob(l.text??""));if(!r.length){const l=t.map(f=>f.text??"").join(`
41
+ `),u=pr(l);u&&typeof u=="object"&&(r=[u])}if(!r.length)return null;const s=Mb(r)??r[r.length-1];if(!s)return null;const i=s.output??s.payload??s,a=xr(i),c=Wr(a);return c&&typeof c=="object"&&!Array.isArray(c)?{kind:"dict",value:c,data:c,event:s}:{kind:"generic",value:c,event:s}},[e])}function Qo({message:e,viewMode:t,isStreaming:n=!1,toolConfig:r,expandable:o=!1,artifactOverride:s=null,contentOverride:i=null}){var O;const{toolRenderers:a,toolArtifactRenderers:c}=r??{},l=pc(e),u=s??e.artifact??null,f=Array.isArray(i)?i:e.content,h=zu(e),m=(h?gc(h):null)??h,g=f.length>0?f[0]:void 0,x=G=>{if(G==null)return null;const Y=typeof G=="string"?G:(()=>{try{return JSON.stringify(G,null,2)}catch{return String(G)}})();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:Y})},y=G=>x(G),w=()=>{if((m==null?void 0:m.kind)==="generic")return y(m.value);if(!g)return null;if(g.type==="text"){const G=g.text??"";return G?y(G):null}return y(g)},k=()=>(m==null?void 0:m.kind)==="dict"?y(m.data):w(),S=(()=>{if(!a)return;if(l.name){const Y=a[l.name];if(Y)return Y}const G=(m==null?void 0:m.kind)??(h==null?void 0:h.kind);if(G){const Y=a[G];if(Y)return Y}return a.default})(),C=k(),T=!o||t==="expanded",A=(T?S==null?void 0:S({message:e,toolMeta:l,toolPayload:m,viewMode:t,isStreaming:n}):null)??null,_=(()=>{if(!c)return;const G=u==null?void 0:u.type;if(typeof G=="string"){const Y=c[G];if(Y)return Y}return c.default})(),L=_?_({artifact:u,message:e,toolPayload:m,isStreaming:n}):null,F=A??C,B=_?L:null;return d.jsxs("div",{className:"space-y-2",children:[n&&d.jsx(_b,{artifact:u,showPartialData:!1}),u&&B,T&&(((O=r==null?void 0:r.getShowContent)==null?void 0:O.call(r,e))??!0)?F:null]})}const Fi=v.memo(function({toolCall:t,index:n,toolName:r,className:o=""}){const{onSelectToolCall:s}=Fo(),i=t.state==="pending",a=t.state==="error",c=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:c}),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((l,u)=>{const f=typeof l.content=="string"?l.content:void 0;return f?d.jsx("p",{className:"text-[9px] text-muted-foreground/50 truncate",children:f},`${t.call.id}-progress-${u}`):null})})]})]})});Fi.displayName="ToolCallCard";function Bu({messages:e,toolConfig:t,wrapperClassName:n}){var i;const r=((i=e[0])==null?void 0:i.name)??"tool",o=ui(e).filter(a=>{var c;return e.length===1&&e[0].role==="tool"?((c=t==null?void 0:t.getShowProgress)==null?void 0:c.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,c)=>d.jsx(Fi,{toolCall:a,index:c,toolName:r},a.call.id||c))});return n?d.jsx("div",{className:n,children:s}):d.jsx("div",{className:"space-y-1 py-1",children:s})}const Uu=b.forwardRef(({className:e,...t},n)=>d.jsx("div",{ref:n,className:pe("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));Uu.displayName="Card";const Hu=b.forwardRef(({className:e,...t},n)=>d.jsx("div",{ref:n,className:pe("flex flex-col space-y-1.5 p-6",e),...t}));Hu.displayName="CardHeader";const Wu=b.forwardRef(({className:e,...t},n)=>d.jsx("h3",{ref:n,className:pe("text-2xl font-semibold leading-none tracking-tight",e),...t}));Wu.displayName="CardTitle";const Vu=b.forwardRef(({className:e,...t},n)=>d.jsx("p",{ref:n,className:pe("text-sm text-muted-foreground",e),...t}));Vu.displayName="CardDescription";const zi=b.forwardRef(({className:e,...t},n)=>d.jsx("div",{ref:n,className:pe("p-6 pt-0",e),...t}));zi.displayName="CardContent";const Ku=b.forwardRef(({className:e,...t},n)=>d.jsx("div",{ref:n,className:pe("flex items-center p-6 pt-0",e),...t}));Ku.displayName="CardFooter";const Db=e=>!!e&&typeof e=="object"&&e.type==="user_choice"&&typeof e.question=="string"&&Array.isArray(e.alternatives);function qu({interruptPart:e,onApprove:t,onReject:n,onSelectAlternative:r,disabled:o,isActive:s,payload:i}){const a=Db(i)?i:null,c=(a==null?void 0:a.question)??e.title??"Approve the result?",l=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(Uu,{className:pe("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(Hu,{className:"pb-3",children:[d.jsx(Wu,{className:"text-blue-900 dark:text-blue-100 text-base",children:c}),d.jsx(Vu,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a?d.jsx(zi,{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(zi,{className:"pt-0 pb-3",children:u}),!a&&d.jsx(Ku,{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 Lb({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:pe("inline-block text-xs opacity-70 ml-1",e),children:"Is thinking"})}function Gu(){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 Xn=Gu();function $b(e){Xn=e}const Yu=/[&<>"']/,Fb=new RegExp(Yu.source,"g"),Xu=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,zb=new RegExp(Xu.source,"g"),Bb={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Ju=e=>Bb[e];function yt(e,t){if(t){if(Yu.test(e))return e.replace(Fb,Ju)}else if(Xu.test(e))return e.replace(zb,Ju);return e}const Ub=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Zu(e){return e.replace(Ub,(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 Hb=/(^|[^\[])\^/g;function We(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(Hb,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const Wb=/[^\w:]/g,Vb=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function Qu(e,t,n){if(e){let r;try{r=decodeURIComponent(Zu(n)).replace(Wb,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!Vb.test(n)&&(n=Yb(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const es={},Kb=/^[^:]+:\/*[^/]*$/,qb=/^([^:]+:)[\s\S]*$/,Gb=/^([^:]+:\/*[^/]*)[\s\S]*$/;function Yb(e,t){es[" "+e]||(Kb.test(e)?es[" "+e]=e+"/":es[" "+e]=ns(e,"/",!0)),e=es[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(qb,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(Gb,"$1")+t:e+t}const ts={exec:function(){}};function ed(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let c=!1,l=i;for(;--l>=0&&a[l]==="\\";)c=!c;return c?"|":" |"}),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 ns(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 Xb(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 Jb(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 td(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function nd(e,t,n,r){const o=t.href,s=t.title?yt(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:yt(i)}}function Zb(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 Bi{constructor(t){this.options=t||Xn}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:ns(r,`
44
44
  `)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=Zb(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=ns(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,c,l,u,f,h,p,m,g=n[1].trim();const x=g.length>1,y={type:"list",raw:"",ordered:x,start:x?+g.slice(0,-1):"",loose:!1,items:[]};g=x?`\\d{1,9}\\${g.slice(-1)}`:`\\${g}`,this.options.pedantic&&(g=x?g:"[*+-]");const w=new RegExp(`^( {0,3}${g})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;t&&(m=!1,!(!(n=w.exec(t))||this.rules.block.hr.test(t)));){if(r=n[0],t=t.substring(r.length),u=n[2].split(`
@@ -48,10 +48,10 @@ React keys must be passed directly to JSX without using spread:
48
48
  `,1)[0],f=h,this.options.pedantic&&(f=f.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),!(C.test(f)||T.test(f)||I.test(f)||S.test(t)));){if(f.search(/[^ ]/)>=i||!f.trim())p+=`
49
49
  `+f.slice(i);else{if(c||u.search(/[^ ]/)>=4||C.test(u)||T.test(u)||S.test(u))break;p+=`
50
50
  `+f}!c&&!f.trim()&&(c=!0),r+=h+`
51
- `,t=t.substring(h.length+1),u=f.slice(i)}}y.loose||(l?y.loose=!0:/\n *\n *$/.test(r)&&(l=!0)),this.options.gfm&&(o=/^\[[ xX]\] /.exec(p),o&&(s=o[0]!=="[ ] ",p=p.replace(/^\[[ xX]\] +/,""))),y.items.push({type:"list_item",raw:r,task:!!o,checked:s,loose:!1,text:p}),y.raw+=r}y.items[y.items.length-1].raw=r.trimRight(),y.items[y.items.length-1].text=p.trimRight(),y.raw=y.raw.trimRight();const k=y.items.length;for(a=0;a<k;a++)if(this.lexer.state.top=!1,y.items[a].tokens=this.lexer.blockTokens(y.items[a].text,[]),!y.loose){const I=y.items[a].tokens.filter(C=>C.type==="space"),S=I.length>0&&I.some(C=>/\n.*\n/.test(C.raw));y.loose=S}if(y.loose)for(a=0;a<k;a++)y.items[a].loose=!0;return y}}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]):bt(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:ed(n[1]).map(o=>({text:o})),align:n[2].replace(/^ *|\| *$/g,"").split(/ *\| */),rows:n[3]&&n[3].trim()?n[3].replace(/\n[ \t]*$/,"").split(`
51
+ `,t=t.substring(h.length+1),u=f.slice(i)}}y.loose||(l?y.loose=!0:/\n *\n *$/.test(r)&&(l=!0)),this.options.gfm&&(o=/^\[[ xX]\] /.exec(p),o&&(s=o[0]!=="[ ] ",p=p.replace(/^\[[ xX]\] +/,""))),y.items.push({type:"list_item",raw:r,task:!!o,checked:s,loose:!1,text:p}),y.raw+=r}y.items[y.items.length-1].raw=r.trimRight(),y.items[y.items.length-1].text=p.trimRight(),y.raw=y.raw.trimRight();const k=y.items.length;for(a=0;a<k;a++)if(this.lexer.state.top=!1,y.items[a].tokens=this.lexer.blockTokens(y.items[a].text,[]),!y.loose){const I=y.items[a].tokens.filter(C=>C.type==="space"),S=I.length>0&&I.some(C=>/\n.*\n/.test(C.raw));y.loose=S}if(y.loose)for(a=0;a<k;a++)y.items[a].loose=!0;return y}}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]):yt(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:ed(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,c;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]=ed(r.rows[s],r.header.length).map(l=>({text:l}));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(c=r.rows[i],a=0;a<c.length;a++)c[a].tokens=this.lexer.inline(c[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:bt(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]):bt(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=ns(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=Xb(n[2],"()");if(i>-1){const c=(n[0].indexOf("!")===0?5:4)+n[1].length+i;n[2]=n[2].substring(0,i),n[0]=n[0].substring(0,c).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)),nd(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 nd(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,c,l=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(c=a.length,o[3]||o[4]){l+=c;continue}else if((o[5]||o[6])&&i%3&&!((i+c)%3)){u+=c;continue}if(l-=c,l>0)continue;c=Math.min(c,c+l+u);const h=t.slice(0,i+o.index+(o[0].length-a.length)+c);if(Math.min(i,c)%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=bt(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=bt(this.options.mangle?n(r[1]):r[1]),s="mailto:"+o):(o=bt(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=bt(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=bt(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]):bt(r[0]):r[0]:o=bt(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:ts,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:ts,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:ts,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:ts,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 Qb(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 rd(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 Nn{constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||Xn,this.options.tokenizer=this.options.tokenizer||new Bi,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 Nn(n).lex(t)}static lexInline(t,n){return new Nn(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:yt(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]):yt(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=ns(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=Xb(n[2],"()");if(i>-1){const c=(n[0].indexOf("!")===0?5:4)+n[1].length+i;n[2]=n[2].substring(0,i),n[0]=n[0].substring(0,c).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)),nd(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 nd(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,c,l=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(c=a.length,o[3]||o[4]){l+=c;continue}else if((o[5]||o[6])&&i%3&&!((i+c)%3)){u+=c;continue}if(l-=c,l>0)continue;c=Math.min(c,c+l+u);const h=t.slice(0,i+o.index+(o[0].length-a.length)+c);if(Math.min(i,c)%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=yt(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=yt(this.options.mangle?n(r[1]):r[1]),s="mailto:"+o):(o=yt(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=yt(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=yt(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]):yt(r[0]):r[0]:o=yt(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:ts,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=We(ge.def).replace("label",ge._label).replace("title",ge._title).getRegex(),ge.bullet=/(?:[*+-]|\d{1,9}[.)])/,ge.listItemStart=We(/^( *)(bull) */).replace("bull",ge.bullet).getRegex(),ge.list=We(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=We(ge.html,"i").replace("comment",ge._comment).replace("tag",ge._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),ge.paragraph=We(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=We(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=We(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=We(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:We(`^ *(?: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:ts,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:We(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 le={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:ts,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:ts,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,punctuation:/^([\spunctuation])/};le._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",le.punctuation=We(le.punctuation).replace(/punctuation/g,le._punctuation).getRegex(),le.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g,le.escapedEmSt=/(?:^|[^\\])(?:\\\\)*\\[*_]/g,le._comment=We(ge._comment).replace("(?:-->|$)","-->").getRegex(),le.emStrong.lDelim=We(le.emStrong.lDelim).replace(/punct/g,le._punctuation).getRegex(),le.emStrong.rDelimAst=We(le.emStrong.rDelimAst,"g").replace(/punct/g,le._punctuation).getRegex(),le.emStrong.rDelimUnd=We(le.emStrong.rDelimUnd,"g").replace(/punct/g,le._punctuation).getRegex(),le._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,le._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,le._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])?)+(?![-_])/,le.autolink=We(le.autolink).replace("scheme",le._scheme).replace("email",le._email).getRegex(),le._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,le.tag=We(le.tag).replace("comment",le._comment).replace("attribute",le._attribute).getRegex(),le._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,le._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/,le._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,le.link=We(le.link).replace("label",le._label).replace("href",le._href).replace("title",le._title).getRegex(),le.reflink=We(le.reflink).replace("label",le._label).replace("ref",ge._label).getRegex(),le.nolink=We(le.nolink).replace("ref",ge._label).getRegex(),le.reflinkSearch=We(le.reflinkSearch,"g").replace("reflink",le.reflink).replace("nolink",le.nolink).getRegex(),le.normal={...le},le.pedantic={...le.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:We(/^!?\[(label)\]\((.*?)\)/).replace("label",le._label).getRegex(),reflink:We(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",le._label).getRegex()},le.gfm={...le.normal,escape:We(le.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.!#$%&'*+\/=?_`{\|}~-]+@)))/},le.gfm.url=We(le.gfm.url,"i").replace("email",le.gfm._extended_email).getRegex(),le.breaks={...le.gfm,br:We(le.br).replace("{2,}","*").getRegex(),text:We(le.gfm.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()};function Qb(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 rd(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 Nn{constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||Xn,this.options.tokenizer=this.options.tokenizer||new Bi,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:le.normal};this.options.pedantic?(n.block=ge.pedantic,n.inline=le.pedantic):this.options.gfm&&(n.block=ge.gfm,this.options.breaks?n.inline=le.breaks:n.inline=le.gfm),this.tokenizer.rules=n}static get rules(){return{block:ge,inline:le}}static lex(t,n){return new Nn(n).lex(t)}static lexInline(t,n){return new Nn(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,c,l)=>c+" ".repeat(l.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+=`
@@ -62,8 +62,8 @@ React keys must be passed directly to JSX without using spread:
62
62
  `+r.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=o.text):n.push(r),i=s.length!==t.length,t=t.substring(r.raw.length);continue}if(r=this.tokenizer.text(t)){t=t.substring(r.raw.length),o=n[n.length-1],o&&o.type==="text"?(o.raw+=`
63
63
  `+r.raw,o.text+=`
64
64
  `+r.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=o.text):n.push(r);continue}if(t){const a="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(a);break}else throw new Error(a)}}return this.state.top=!0,n}inline(t,n=[]){return this.inlineQueue.push({src:t,tokens:n}),n}inlineTokens(t,n=[]){let r,o,s,i=t,a,c,l;if(this.tokens.links){const u=Object.keys(this.tokens.links);if(u.length>0)for(;(a=this.tokenizer.rules.inline.reflinkSearch.exec(i))!=null;)u.includes(a[0].slice(a[0].lastIndexOf("[")+1,-1))&&(i=i.slice(0,a.index)+"["+td("a",a[0].length-2)+"]"+i.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(a=this.tokenizer.rules.inline.blockSkip.exec(i))!=null;)i=i.slice(0,a.index)+"["+td("a",a[0].length-2)+"]"+i.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);for(;(a=this.tokenizer.rules.inline.escapedEmSt.exec(i))!=null;)i=i.slice(0,a.index+a[0].length-2)+"++"+i.slice(this.tokenizer.rules.inline.escapedEmSt.lastIndex),this.tokenizer.rules.inline.escapedEmSt.lastIndex--;for(;t;)if(c||(l=""),c=!1,!(this.options.extensions&&this.options.extensions.inline&&this.options.extensions.inline.some(u=>(r=u.call({lexer:this},t,n))?(t=t.substring(r.raw.length),n.push(r),!0):!1))){if(r=this.tokenizer.escape(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.tag(t)){t=t.substring(r.raw.length),o=n[n.length-1],o&&r.type==="text"&&o.type==="text"?(o.raw+=r.raw,o.text+=r.text):n.push(r);continue}if(r=this.tokenizer.link(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.reflink(t,this.tokens.links)){t=t.substring(r.raw.length),o=n[n.length-1],o&&r.type==="text"&&o.type==="text"?(o.raw+=r.raw,o.text+=r.text):n.push(r);continue}if(r=this.tokenizer.emStrong(t,i,l)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.codespan(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.br(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.del(t)){t=t.substring(r.raw.length),n.push(r);continue}if(r=this.tokenizer.autolink(t,rd)){t=t.substring(r.raw.length),n.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(t,rd))){t=t.substring(r.raw.length),n.push(r);continue}if(s=t,this.options.extensions&&this.options.extensions.startInline){let u=1/0;const f=t.slice(1);let h;this.options.extensions.startInline.forEach(function(p){h=p.call({lexer:this},f),typeof h=="number"&&h>=0&&(u=Math.min(u,h))}),u<1/0&&u>=0&&(s=t.substring(0,u+1))}if(r=this.tokenizer.inlineText(s,Qb)){t=t.substring(r.raw.length),r.raw.slice(-1)!=="_"&&(l=r.raw.slice(-1)),c=!0,o=n[n.length-1],o&&o.type==="text"?(o.raw+=r.raw,o.text+=r.text):n.push(r);continue}if(t){const u="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(u);break}else throw new Error(u)}}return n}}class Ui{constructor(t){this.options=t||Xn}code(t,n,r){const o=(n||"").match(/\S*/)[0];if(this.options.highlight){const s=this.options.highlight(t,o);s!=null&&s!==t&&(r=!0,t=s)}return t=t.replace(/\n$/,"")+`
65
- `,o?'<pre><code class="'+this.options.langPrefix+bt(o)+'">'+(r?t:bt(t,!0))+`</code></pre>
66
- `:"<pre><code>"+(r?t:bt(t,!0))+`</code></pre>
65
+ `,o?'<pre><code class="'+this.options.langPrefix+yt(o)+'">'+(r?t:yt(t,!0))+`</code></pre>
66
+ `:"<pre><code>"+(r?t:yt(t,!0))+`</code></pre>
67
67
  `}blockquote(t){return`<blockquote>
68
68
  ${t}</blockquote>
69
69
  `}html(t){return t}heading(t,n,r,o){if(this.options.headerIds){const s=this.options.headerPrefix+o.slug(r);return`<h${n} id="${s}">${t}</h${n}>
@@ -81,10 +81,10 @@ ${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=Qu(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=Qu(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 od{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 sd{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||Xn,this.options.renderer=this.options.renderer||new Ui,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new od,this.slugger=new sd}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,c,l,u,f,h,p,m,g,x,y,w,k,I,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,Zu(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(l=p.rows[s],u="",c=l.length,i=0;i<c;i++)u+=this.renderer.tablecell(this.parseInline(l[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,g=p.start,x=p.loose,a=p.items.length,h="",s=0;s<a;s++)w=p.items[s],k=w.checked,I=w.task,y="",w.task&&(S=this.renderer.checkbox(k),x?w.tokens.length>0&&w.tokens[0].type==="paragraph"?(w.tokens[0].text=S+" "+w.tokens[0].text,w.tokens[0].tokens&&w.tokens[0].tokens.length>0&&w.tokens[0].tokens[0].type==="text"&&(w.tokens[0].tokens[0].text=S+" "+w.tokens[0].tokens[0].text)):w.tokens.unshift({type:"text",text:S}):y+=S),y+=this.parse(w.tokens,x),h+=this.renderer.listitem(y,I,k);r+=this.renderer.list(h,m,g);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+=`
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=Qu(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=Qu(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 od{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 sd{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 jn{constructor(t){this.options=t||Xn,this.options.renderer=this.options.renderer||new Ui,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new od,this.slugger=new sd}static parse(t,n){return new jn(n).parse(t)}static parseInline(t,n){return new jn(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,c,l,u,f,h,p,m,g,x,y,w,k,I,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,Zu(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(l=p.rows[s],u="",c=l.length,i=0;i<c;i++)u+=this.renderer.tablecell(this.parseInline(l[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,g=p.start,x=p.loose,a=p.items.length,h="",s=0;s<a;s++)w=p.items[s],k=w.checked,I=w.task,y="",w.task&&(S=this.renderer.checkbox(k),x?w.tokens.length>0&&w.tokens[0].type==="paragraph"?(w.tokens[0].text=S+" "+w.tokens[0].text,w.tokens[0].tokens&&w.tokens[0].tokens.length>0&&w.tokens[0].tokens[0].type==="text"&&(w.tokens[0].tokens[0].text=S+" "+w.tokens[0].tokens[0].text)):w.tokens.unshift({type:"text",text:S}):y+=S),y+=this.parse(w.tokens,x),h+=this.renderer.listitem(y,I,k);r+=this.renderer.list(h,m,g);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
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 c='Token with "'+s.type+'" type was not found.';if(this.options.silent){console.error(c);return}else throw new Error(c)}}}return r}}class rs{constructor(t){this.options=t||Xn}preprocess(t){return t}postprocess(t){return t}}ol(rs,"passThroughHooks",new Set(["preprocess","postprocess"]));function ey(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>"+bt(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 id(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...pe.defaults,...s};const i=ey(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(Jb(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let c;try{r.hooks&&(n=r.hooks.preprocess(n)),c=e(n,r)}catch(f){return i(f)}const l=function(f){let h;if(!f)try{r.walkTokens&&pe.walkTokens(c,r.walkTokens),h=t(c,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,!c.length))return l();let u=0;pe.walkTokens(c,function(f){f.type==="code"&&(u++,setTimeout(()=>{a(f.text,f.lang,function(h,p){if(h)return l(h);p!=null&&p!==f.text&&(f.text=p,f.escaped=!0),u--,u===0&&l()})},0))}),u===0&&l();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 c=t(a,r);return r.hooks&&(c=r.hooks.postprocess(c)),c}catch(a){return i(a)}}}function pe(e,t,n){return id(Nn.lex,_n.parse)(e,t,n)}pe.options=pe.setOptions=function(e){return pe.defaults={...pe.defaults,...e},$b(pe.defaults),pe},pe.getDefaults=Gu,pe.defaults=Xn,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 Ui;for(const s in n.renderer){const i=o[s];o[s]=(...a)=>{let c=n.renderer[s].apply(o,a);return c===!1&&(c=i.apply(o,a)),c}}r.renderer=o}if(n.tokenizer){const o=pe.defaults.tokenizer||new Bi;for(const s in n.tokenizer){const i=o[s];o[s]=(...a)=>{let c=n.tokenizer[s].apply(o,a);return c===!1&&(c=i.apply(o,a)),c}}r.tokenizer=o}if(n.hooks){const o=pe.defaults.hooks||new rs;for(const s in n.hooks){const i=o[s];rs.passThroughHooks.has(s)?o[s]=a=>{if(pe.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(l=>i.call(o,l));const c=n.hooks[s].call(o,a);return i.call(o,c)}:o[s]=(...a)=>{let c=n.hooks[s].apply(o,a);return c===!1&&(c=i.apply(o,a)),c}}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=id(Nn.lexInline,_n.parseInline),pe.Parser=_n,pe.parser=_n.parse,pe.Renderer=Ui,pe.TextRenderer=od,pe.Lexer=Nn,pe.lexer=Nn.lex,pe.Tokenizer=Bi,pe.Slugger=sd,pe.Hooks=rs,pe.parse=pe,pe.options,pe.setOptions,pe.use,pe.walkTokens,pe.parseInline,_n.parse,Nn.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 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 ty({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(so,{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(Qe,{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 Hi({showTimestamp:e,showAgentName:t,isToolMessage:n,isInterruptMessage:r=!1,iconForeground:o,agentName:s,messageIcon:i,customHeaderClass:a,customActionsClass:c,isCompactLayout:l,showActions:u,isEditing:f,messageRole:h,onCopy:p,onEdit:m,onRegenerate:g,showCheckpointControls:x,attemptCount:y,attemptIndex:w,handleOlderAttemptSelect:k,handleNewerAttemptSelect:I,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",l&&"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",l?"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:[x&&y>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",w<y-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{w>=y-1||k()},"aria-label":"Older attempt (back in time)",disabled:w>=y-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:[y-w," / ",y]})}),d.jsx("button",{type:"button",className:he("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",w>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{w<=0||I()},"aria-label":"Newer attempt (forward in time)",disabled:w<=0,children:d.jsx(xe.ChevronRight,{className:"h-3 w-3"})})]}),e&&S&&d.jsx("time",{className:he("text-xs opacity-60",o,l&&"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",c),children:[d.jsx("div",{className:"relative",children:d.jsx(Qe,{variant:"ghost",size:"sm",onClick:p,className:he("h-6 w-6 p-0 hover:bg-foreground/10",o,l&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:d.jsx(xe.Copy,{className:he(C?"text-success":o,l?"h-3 w-3":"h-4 w-4")})})}),h==="user"&&m&&d.jsx(Qe,{variant:"ghost",size:"sm",onClick:m,className:he("h-6 w-6 p-0 hover:bg-foreground/10",o,l&&"h-5 w-5"),"aria-label":"Edit message",children:d.jsx(xe.Edit,{className:he(o,l?"h-3 w-3":"h-4 w-4")})}),h==="assistant"&&g&&d.jsx(Qe,{variant:"ghost",size:"sm",onClick:g,className:he("h-6 w-6 p-0 hover:bg-foreground/10",o,l&&"h-5 w-5"),"aria-label":"Regenerate response",children:d.jsx(xe.RotateCcw,{className:he(o,l?"h-3 w-3":"h-4 w-4")})})]})]})]})}function Wi(e){return v.useMemo(()=>({textContent:wg(e),imageParts:vg(e),fileParts:Sg(e),toolCalls:ai(e),interruptParts:Cg(e),contentParts:e.content}),[e])}function ad(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 os=v.memo(function({contentParts:t,textContent:n,imageParts:r,fileParts:o,messageRole:s,isCompactLayout:i=!1,truncateUserMessages:a=!1,userMessagePreviewLength:c=500,isUserExpanded:l=!1,setIsUserExpanded:u,uploadingFiles:f={},handleFileClick:h,isStreamingMessage:p=!1,renderStreamingMarkdown:m=!0,enableStreamingMarkdownBuffer:g=!0,streamingDebounceMs:x=0}){const y=ad(t,g&&p,x),w=v.useMemo(()=>y.filter(F=>F.type==="text"),[y]),k=v.useMemo(()=>w.map(F=>F.text??"").join(""),[w]),I=m&&p,S=v.useMemo(()=>{if(!I)return null;const F=ry(k);return{stablePart:k.slice(0,F),tailPart:k.slice(F)}},[k,I]),C=v.useMemo(()=>{if(!S)return null;const{stablePart:F,tailPart:U}=S;return!F&&!U?null:d.jsxs("div",{className:"space-y-2",children:[F?d.jsx(so,{content:F,allowHtml:!1}):null,U?d.jsx(so,{content:U,allowHtml:!1}):null]})},[S]),T=()=>!r||r.length===0?null:d.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:r.map((F,U)=>{const L=F;return d.jsx("div",{className:"relative group",children:d.jsx("img",{src:L.image_url.url,alt:"Image",loading:"lazy",onClick:()=>window.open(L.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-${U}`)})}),A=(F,U)=>{if(F.type==="text"){const L=F.text??"",K=L.trim(),q=pr(K);return q&&s!=="tool"?d.jsx(Rb,{data:q},U):s==="user"&&a&&K.length>c&&!l?d.jsx(ty,{text:K,expanded:l,onExpandedChange:u||(()=>{}),previewLength:c,isCompact:i},U):d.jsx(so,{content:L,allowHtml:!1},U)}if(F.type==="file"){const L=F,K=L.name||"file",q=f[U];return d.jsxs("a",{href:L.url,onClick:re=>h==null?void 0:h(re,L,U),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:[q?d.jsx(xe.Loader,{className:"h-4 w-4 animate-spin"}):null,d.jsxs("span",{className:"truncate max-w-[180px]",children:[K,q?" (processing)":""]})]},U)}return null},j=I?k:n;if(!(j.trim().length>0||r.length>0||o.length>0)&&!p)return null;const M=I?y.filter(F=>F.type!=="text"):y;return d.jsxs("div",{className:"space-y-2",children:[I?C:null,M.filter(F=>F.type==="text"||F.type==="file").map((F,U)=>A(F,U)),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"})]})});os.displayName="SharedContent";function ny(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 ry(e){if(!e)return 0;for(let t=e.length;t>=0;t-=1)if(ny(e.slice(0,t)))return t;return 0}const ld=v.memo(function({isStreamingMessage:t,interruptPart:n,handleInterruptApprove:r,handleInterruptReject:o,handleInterruptAlternative:s,disableInterruptActions:i,iconForeground:a,textContent:c=""}){if(n)return d.jsx(qu,{interruptPart:n,payload:n.value,onApprove:r||(()=>{}),onReject:o||(()=>{}),onSelectAlternative:s,disabled:i,isActive:!i});const l=c.trim().length>0;return t&&!l?d.jsx(Lb,{className:a}):null});ld.displayName="InteractiveContent";const ao=v.memo(function({role:t,header:n,content:r,actions:o,status:s,isCompactLayout:i=!1,variant:a="default",customStyles:c={}}){const l=t==="user",u=t==="system",f=he("flex w-full group py-3 md:py-4 px-2 md:px-0",l?"justify-end":"justify-start",c.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":"",l?"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",c.bubble),p=he("text-sm leading-relaxed break-words",c.content),m=he("absolute top-0 opacity-0 group-hover:opacity-100 transition-opacity flex items-center gap-1",l?"-left-10":"-right-10",i&&"hidden",c.actions);return d.jsx("div",{className:f,children:d.jsxs("div",{className:h,children:[n&&d.jsx("div",{className:he("mb-2 w-full",c.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 Vi=v.memo(function({message:t,messageIndex:n,isStreamingMessage:r=!1,streamingDebounceMs:o,renderStreamingMarkdown:s=!0,enableStreamingMarkdownBuffer:i=!0,layoutSize:a,showToolMessages:c,toolConfig:l,customStyles:u,onRegenerate:f,onCopy:h,getInterruptOptions:p,renderArtifactsInline:m,showToolProgress:g,showToolResultsInline:x,isEmbedded:y=!1,precedingMessages:w=[]}){var ct,Ke;const{layoutSize:k,toolConfig:I,renderArtifactsInline:S,streamingDebounceMs:C,onRegenerate:T,getInterruptOptions:A,showToolMessages:j,messageCustomStyles:P}=Fo(),M=l??I,F=a??k,U=m??S,L=o??C??0,K=f??T,q=p??A,re=c??j??!0,W=g??re,V=x??re,ne={...(P==null?void 0:P(t))||{},...u},H=h,[O,N]=v.useState(!1),{respondToInterrupt:$}=qr(),[D,G]=v.useState(!1),ee=F==="phone"||F==="half-screen",{contentParts:_,textContent:B,imageParts:X,fileParts:le,toolCalls:me,interruptParts:be}=Wi(t),Te=be[0]||null,Ae=v.useCallback(async()=>{const $e=B;try{await navigator.clipboard.writeText($e),N(!0),setTimeout(()=>N(!1),2e3),H==null||H($e)}catch(je){console.error("Failed to copy assistant message:",je)}},[B,H]),ze=v.useCallback(async($e,je)=>{if(!(!Te||!hc(Te.id))){G(!0);try{const ut=q==null?void 0:q(t);await $($e,je,ut)}finally{G(!1)}}},[Te,t,q,$]),Ze=v.useCallback(()=>{K==null||K(n)},[K,n]),Ye=!y&&(((ct=M==null?void 0:M.getShowHeader)==null?void 0:ct.call(M,t))??!0),Ve=t.role==="assistant"&&W?d.jsx(Bu,{messages:[...w,t],isStreaming:r,toolConfig:M}):null,dt=Ye&&d.jsx(Hi,{showTimestamp:!0,showAgentName:!0,isToolMessage:t.role==="tool",isInterruptMessage:!1,iconForeground:"text-[hsl(var(--chat-bubble-ai-text))]",agentName: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:ee,showActions:!0,isEditing:!1,messageRole:t.role,onCopy:Ae,onEdit:void 0,onRegenerate:Ze,showCheckpointControls:!1,attemptCount:1,attemptIndex:0,handleOlderAttemptSelect:()=>{},handleNewerAttemptSelect:()=>{},messageCreatedAt:t.createdAt,copied:O,customActionsClass:ne.actions}),lt=t.role==="tool",nt=lt?d.jsx(Qo,{message:t,viewMode:"expanded",isStreaming:r,toolConfig:M,expandable:(Ke=M==null?void 0:M.getToolExpandable)==null?void 0:Ke.call(M,t)}):null,it=d.jsxs("div",{className:"space-y-4",children:[w.map($e=>{var je;return d.jsx("div",{className:"space-y-2 pb-4 border-b border-border/20 last:border-0 last:pb-0",children:d.jsx(Qo,{message:$e,viewMode:"expanded",isStreaming:!1,toolConfig:M,expandable:(je=M==null?void 0:M.getToolExpandable)==null?void 0:je.call(M,$e)})},$e.id)}),lt?nt:d.jsxs(d.Fragment,{children:[d.jsx(os,{contentParts:_,textContent:B,imageParts:X,fileParts:le,messageRole:t.role,isCompactLayout:ee,isStreamingMessage:r,renderStreamingMarkdown:s,enableStreamingMarkdownBuffer:i,streamingDebounceMs:L}),t.role==="assistant"&&V&&me.map($e=>d.jsx(Qo,{message:{...t,role:"tool",name:$e.name,toolCallId:$e.id,artifact:$e.artifact,content:[{type:"text",text:JSON.stringify($e.args)}]},viewMode:"expanded",isStreaming:r,toolConfig:M},$e.id)),d.jsx(ld,{message:t,isStreamingMessage:r,toolConfig:M,interruptPart:Te,handleInterruptApprove:()=>ze(!0),handleInterruptReject:()=>ze(!1),handleInterruptAlternative:($e,je)=>ze(!0,{alternativeId:je==null?void 0:je.id}),disableInterruptActions:D,renderArtifactsInline:U,iconForeground:"text-[hsl(var(--chat-bubble-ai-text))]",textContent:B})]})]});return y?it:d.jsx(ao,{role:t.role,header:dt,status:Ve,content:it,isCompactLayout:ee,customStyles:ne})});Vi.displayName="AssistantMessageComponent";const Ki=v.memo(function({message:t,layoutSize:n="desktop",truncateUserMessages:r=!0,userMessagePreviewLength:o=500,enableMessageEditing:s=!0,onEdit:i,checkpointIndex:a,onSelectCheckpoint:c,customStyles:l={}}){const[u,f]=v.useState(!1),[h,p]=v.useState(!1),m=n==="phone"||n==="half-screen",{contentParts:g,textContent:x,imageParts:y,fileParts:w}=Wi(t),k=v.useCallback(async()=>{try{await navigator.clipboard.writeText(x),f(!0),setTimeout(()=>f(!1),2e3)}catch(U){console.error("Failed to copy user message:",U)}},[x]),I=v.useCallback(()=>{if(!i||!t.id)return;const U={checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};i(t.id,x,U)},[i,t,x]),{attemptCount:S,attemptIndex:C,attempts:T}=v.useMemo(()=>a?Gg(t.id,t.checkpointId,a):{attemptCount:1,attemptIndex:0,attempts:[]},[t.id,t.checkpointId,a]),A=S>1&&!!c,j=v.useCallback(()=>{const U=T[C+1];U&&c&&c(U.id,void 0,!!U.isLatestAttempt)},[T,C,c]),P=v.useCallback(()=>{const U=T[C-1];U&&c&&c(U.id,void 0,!!U.isLatestAttempt)},[T,C,c]),M=d.jsx(Hi,{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?I:void 0,showCheckpointControls:A,attemptCount:S,attemptIndex:C,handleOlderAttemptSelect:j,handleNewerAttemptSelect:P,messageCreatedAt:t.createdAt,copied:u,customHeaderClass:l.header,customActionsClass:l.actions}),F=d.jsx(os,{contentParts:g,textContent:x,imageParts:y,fileParts:w,messageRole:"user",truncateUserMessages:r,userMessagePreviewLength:o,isUserExpanded:h,setIsUserExpanded:p,isCompactLayout:m,handleFileClick:()=>{},uploadingFiles:{}});return d.jsx(ao,{role:"user",header:M,content:F,isCompactLayout:m,customStyles:l})});Ki.displayName="UserMessageComponent";const qi=v.memo(function({message:t,layoutSize:n="desktop",customStyles:r={}}){const o=n==="phone"||n==="half-screen",{contentParts:s,textContent:i,imageParts:a,fileParts:c}=Wi(t),l=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(os,{contentParts:s,textContent:i,imageParts:a,fileParts:c,messageRole:"system",isCompactLayout:o});return d.jsx(ao,{role:"system",header:l,content:u,isCompactLayout:o,customStyles:r})});qi.displayName="SystemMessageComponent";const ss=v.forwardRef(({messages:e=[],isStreaming:t,onStartReached:n,className:r,style:o,emptyMessage:s,onScrollAway:i,onAtBottom:a,renderMessage:c},l)=>{const{followNewMessages:u,checkpointIndex:f}=Fo(),h=!!f,p=v.useRef(null),m=v.useRef(null),g=v.useRef(!1),x=v.useRef(!1),y=v.useCallback(P=>{i&&i(!P),a&&a(P)},[i,a]),w=v.useMemo(()=>{if(n)return async()=>{if(!g.current){g.current=!0;try{await n()}finally{g.current=!1}}}},[n]),k=v.useMemo(()=>!u||h?!1:"auto",[u,h]),I=e.length===0&&s,S=["flex flex-1 flex-col min-h-0 min-w-0",r].filter(Boolean).join(" "),C=()=>I?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 P,M;if(T===0){x.current=!1;return}if(!x.current)if(x.current=!0,p.current&&e.length>0){const F=e.length-1;(M=(P=p.current).scrollToIndex)==null||M.call(P,{index:F,align:"end",behavior:"auto"})}else m.current&&(m.current.scrollTop=m.current.scrollHeight)},[T,e.length]),v.useImperativeHandle(l,()=>({scrollToLatest:()=>{var P,M;if(p.current&&e.length>0){const F=e.length-1;(M=(P=p.current).scrollToIndex)==null||M.call(P,{index:F,align:"end",behavior:"auto"})}else m.current&&(m.current.scrollTop=m.current.scrollHeight)},scrollToTop:()=>{var P,M;p.current&&e.length>0?(M=(P=p.current).scrollToIndex)==null||M.call(P,{index:0,align:"start",behavior:"auto"}):m.current&&(m.current.scrollTop=0)}}),[e]);const j=v.useCallback((P,M)=>P.role==="user"?d.jsx(Ki,{message:P,messageIndex:M}):P.role==="system"?d.jsx(qi,{message:P}):d.jsx(Vi,{message:P,messageIndex:M,isStreamingMessage:t&&M===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(gb,{ref:P=>p.current=P,scrollerRef:P=>m.current=P instanceof HTMLDivElement?P:null,data:e,followOutput:k,initialTopMostItemIndex:e.length>0?e.length-1:0,overscan:200,atBottomThreshold:50,startReached:()=>{w&&w()},atBottomStateChange:y,style:{height:"100%",width:"100%",overscrollBehavior:"contain"},computeItemKey:(P,M)=>M.id||P,itemContent:(P,M)=>c?c(M,P):j(M,P)}):C()})})});ss.displayName="MessageList";function ve(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 cd(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function jn(...e){return t=>{let n=!1;const r=e.map(o=>{const s=cd(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():cd(e[o],null)}}}}function Je(...e){return b.useCallback(jn(...e),e)}function oy(e,t){const n=b.createContext(t),r=s=>{const{children:i,...a}=s,c=b.useMemo(()=>a,Object.values(a));return d.jsx(n.Provider,{value:c,children:i})};r.displayName=e+"Provider";function o(s){const i=b.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 Pn(e,t=[]){let n=[];function r(s,i){const a=b.createContext(i),c=n.length;n=[...n,i];const l=f=>{var y;const{scope:h,children:p,...m}=f,g=((y=h==null?void 0:h[e])==null?void 0:y[c])||a,x=b.useMemo(()=>m,Object.values(m));return d.jsx(g.Provider,{value:x,children:p})};l.displayName=s+"Provider";function u(f,h){var g;const p=((g=h==null?void 0:h[e])==null?void 0:g[c])||a,m=b.useContext(p);if(m)return m;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[l,u]}const o=()=>{const s=n.map(i=>b.createContext(i));return function(a){const c=(a==null?void 0:a[e])||s;return b.useMemo(()=>({[`__scope${e}`]:{...a,[e]:c}}),[a,c])}};return o.scopeName=e,[r,sy(o,...t)]}function sy(...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:c,scopeName:l})=>{const f=c(s)[`__scope${l}`];return{...a,...f}},{});return b.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var tn=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},iy=b[" useInsertionEffect ".trim().toString()]||tn;function is({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=ay({defaultProp:t,onChange:n}),a=e!==void 0,c=a?e:o;{const u=b.useRef(e!==void 0);b.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 l=b.useCallback(u=>{var f;if(a){const h=ly(u)?u(e):u;h!==e&&((f=i.current)==null||f.call(i,h))}else s(u)},[a,e,s,i]);return[c,l]}function ay({defaultProp:e,onChange:t}){const[n,r]=b.useState(e),o=b.useRef(n),s=b.useRef(t);return iy(()=>{s.current=t},[t]),b.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function ly(e){return typeof e=="function"}var cy=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ne=cy.reduce((e,t)=>{const n=cr.createSlot(`Primitive.${t}`),r=b.forwardRef((o,s)=>{const{asChild:i,...a}=o,c=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),d.jsx(c,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function ud(e,t){e&&il.flushSync(()=>e.dispatchEvent(t))}function dd(e){const t=e+"CollectionProvider",[n,r]=Pn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=g=>{const{scope:x,children:y}=g,w=v.useRef(null),k=v.useRef(new Map).current;return d.jsx(o,{scope:x,itemMap:k,collectionRef:w,children:y})};i.displayName=t;const a=e+"CollectionSlot",c=cr.createSlot(a),l=v.forwardRef((g,x)=>{const{scope:y,children:w}=g,k=s(a,y),I=Je(x,k.collectionRef);return d.jsx(c,{ref:I,children:w})});l.displayName=a;const u=e+"CollectionItemSlot",f="data-radix-collection-item",h=cr.createSlot(u),p=v.forwardRef((g,x)=>{const{scope:y,children:w,...k}=g,I=v.useRef(null),S=Je(x,I),C=s(u,y);return v.useEffect(()=>(C.itemMap.set(I,{ref:I,...k}),()=>void C.itemMap.delete(I))),d.jsx(h,{[f]:"",ref:S,children:w})});p.displayName=u;function m(g){const x=s(e+"CollectionConsumer",g);return v.useCallback(()=>{const w=x.collectionRef.current;if(!w)return[];const k=Array.from(w.querySelectorAll(`[${f}]`));return Array.from(x.itemMap.values()).sort((C,T)=>k.indexOf(C.ref.current)-k.indexOf(T.ref.current))},[x.collectionRef,x.itemMap])}return[{Provider:i,Slot:l,ItemSlot:p},m,r]}var uy=b.createContext(void 0);function Gi(e){const t=b.useContext(uy);return e||t||"ltr"}function yt(e){const t=b.useRef(e);return b.useEffect(()=>{t.current=e}),b.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function dy(e,t=globalThis==null?void 0:globalThis.document){const n=yt(e);b.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 fy="DismissableLayer",Yi="dismissableLayer.update",hy="dismissableLayer.pointerDownOutside",py="dismissableLayer.focusOutside",fd,hd=b.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Xi=b.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...c}=e,l=b.useContext(hd),[u,f]=b.useState(null),h=(u==null?void 0:u.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=b.useState({}),m=Je(t,T=>f(T)),g=Array.from(l.layers),[x]=[...l.layersWithOutsidePointerEventsDisabled].slice(-1),y=g.indexOf(x),w=u?g.indexOf(u):-1,k=l.layersWithOutsidePointerEventsDisabled.size>0,I=w>=y,S=xy(T=>{const A=T.target,j=[...l.branches].some(P=>P.contains(A));!I||j||(o==null||o(T),i==null||i(T),T.defaultPrevented||a==null||a())},h),C=by(T=>{const A=T.target;[...l.branches].some(P=>P.contains(A))||(s==null||s(T),i==null||i(T),T.defaultPrevented||a==null||a())},h);return dy(T=>{w===l.layers.size-1&&(r==null||r(T),!T.defaultPrevented&&a&&(T.preventDefault(),a()))},h),b.useEffect(()=>{if(u)return n&&(l.layersWithOutsidePointerEventsDisabled.size===0&&(fd=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),l.layersWithOutsidePointerEventsDisabled.add(u)),l.layers.add(u),pd(),()=>{n&&l.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=fd)}},[u,h,n,l]),b.useEffect(()=>()=>{u&&(l.layers.delete(u),l.layersWithOutsidePointerEventsDisabled.delete(u),pd())},[u,l]),b.useEffect(()=>{const T=()=>p({});return document.addEventListener(Yi,T),()=>document.removeEventListener(Yi,T)},[]),d.jsx(Ne.div,{...c,ref:m,style:{pointerEvents:k?I?"auto":"none":void 0,...e.style},onFocusCapture:ve(e.onFocusCapture,C.onFocusCapture),onBlurCapture:ve(e.onBlurCapture,C.onBlurCapture),onPointerDownCapture:ve(e.onPointerDownCapture,S.onPointerDownCapture)})});Xi.displayName=fy;var my="DismissableLayerBranch",gy=b.forwardRef((e,t)=>{const n=b.useContext(hd),r=b.useRef(null),o=Je(t,r);return b.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),d.jsx(Ne.div,{...e,ref:o})});gy.displayName=my;function xy(e,t=globalThis==null?void 0:globalThis.document){const n=yt(e),r=b.useRef(!1),o=b.useRef(()=>{});return b.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let c=function(){md(hy,n,l,{discrete:!0})};const l={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=c,t.addEventListener("click",o.current,{once:!0})):c()}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 by(e,t=globalThis==null?void 0:globalThis.document){const n=yt(e),r=b.useRef(!1);return b.useEffect(()=>{const o=s=>{s.target&&!r.current&&md(py,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 pd(){const e=new CustomEvent(Yi);document.dispatchEvent(e)}function md(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?ud(o,s):o.dispatchEvent(s)}var Ji=0;function gd(){b.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??xd()),document.body.insertAdjacentElement("beforeend",e[1]??xd()),Ji++,()=>{Ji===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),Ji--}},[])}function xd(){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 Zi="focusScope.autoFocusOnMount",Qi="focusScope.autoFocusOnUnmount",bd={bubbles:!1,cancelable:!0},yy="FocusScope",ea=b.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,c]=b.useState(null),l=yt(o),u=yt(s),f=b.useRef(null),h=Je(t,g=>c(g)),p=b.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;b.useEffect(()=>{if(r){let g=function(k){if(p.paused||!a)return;const I=k.target;a.contains(I)?f.current=I:Rn(f.current,{select:!0})},x=function(k){if(p.paused||!a)return;const I=k.relatedTarget;I!==null&&(a.contains(I)||Rn(f.current,{select:!0}))},y=function(k){if(document.activeElement===document.body)for(const S of k)S.removedNodes.length>0&&Rn(a)};document.addEventListener("focusin",g),document.addEventListener("focusout",x);const w=new MutationObserver(y);return a&&w.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",g),document.removeEventListener("focusout",x),w.disconnect()}}},[r,a,p.paused]),b.useEffect(()=>{if(a){vd.add(p);const g=document.activeElement;if(!a.contains(g)){const y=new CustomEvent(Zi,bd);a.addEventListener(Zi,l),a.dispatchEvent(y),y.defaultPrevented||(wy(ky(yd(a)),{select:!0}),document.activeElement===g&&Rn(a))}return()=>{a.removeEventListener(Zi,l),setTimeout(()=>{const y=new CustomEvent(Qi,bd);a.addEventListener(Qi,u),a.dispatchEvent(y),y.defaultPrevented||Rn(g??document.body,{select:!0}),a.removeEventListener(Qi,u),vd.remove(p)},0)}}},[a,l,u,p]);const m=b.useCallback(g=>{if(!n&&!r||p.paused)return;const x=g.key==="Tab"&&!g.altKey&&!g.ctrlKey&&!g.metaKey,y=document.activeElement;if(x&&y){const w=g.currentTarget,[k,I]=vy(w);k&&I?!g.shiftKey&&y===I?(g.preventDefault(),n&&Rn(k,{select:!0})):g.shiftKey&&y===k&&(g.preventDefault(),n&&Rn(I,{select:!0})):y===w&&g.preventDefault()}},[n,r,p.paused]);return d.jsx(Ne.div,{tabIndex:-1,...i,ref:h,onKeyDown:m})});ea.displayName=yy;function wy(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Rn(r,{select:t}),document.activeElement!==n)return}function vy(e){const t=yd(e),n=wd(t,e),r=wd(t.reverse(),e);return[n,r]}function yd(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 wd(e,t){for(const n of e)if(!Sy(n,{upTo:t}))return n}function Sy(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 Cy(e){return e instanceof HTMLInputElement&&"select"in e}function Rn(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Cy(e)&&t&&e.select()}}var vd=Ty();function Ty(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Sd(e,t),e.unshift(t)},remove(t){var n;e=Sd(e,t),(n=e[0])==null||n.resume()}}}function Sd(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function ky(e){return e.filter(t=>t.tagName!=="A")}var Ey=b[" useId ".trim().toString()]||(()=>{}),Iy=0;function Rt(e){const[t,n]=b.useState(Ey());return tn(()=>{n(r=>r??String(Iy++))},[e]),e||(t?`radix-${t}`:"")}const Ay=["top","right","bottom","left"],Mn=Math.min,Mt=Math.max,as=Math.round,ls=Math.floor,nn=e=>({x:e,y:e}),Ny={left:"right",right:"left",bottom:"top",top:"bottom"},_y={start:"end",end:"start"};function ta(e,t,n){return Mt(e,Mn(t,n))}function mn(e,t){return typeof e=="function"?e(t):e}function gn(e){return e.split("-")[0]}function Sr(e){return e.split("-")[1]}function na(e){return e==="x"?"y":"x"}function ra(e){return e==="y"?"height":"width"}const jy=new Set(["top","bottom"]);function rn(e){return jy.has(gn(e))?"y":"x"}function oa(e){return na(rn(e))}function Py(e,t,n){n===void 0&&(n=!1);const r=Sr(e),o=oa(e),s=ra(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=cs(i)),[i,cs(i)]}function Ry(e){const t=cs(e);return[sa(e),t,sa(t)]}function sa(e){return e.replace(/start|end/g,t=>_y[t])}const Cd=["left","right"],Td=["right","left"],My=["top","bottom"],Oy=["bottom","top"];function Dy(e,t,n){switch(e){case"top":case"bottom":return n?t?Td:Cd:t?Cd:Td;case"left":case"right":return t?My:Oy;default:return[]}}function Ly(e,t,n,r){const o=Sr(e);let s=Dy(gn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(sa)))),s}function cs(e){return e.replace(/left|right|bottom|top/g,t=>Ny[t])}function $y(e){return{top:0,right:0,bottom:0,left:0,...e}}function kd(e){return typeof e!="number"?$y(e):{top:e,right:e,bottom:e,left:e}}function us(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 Ed(e,t,n){let{reference:r,floating:o}=e;const s=rn(t),i=oa(t),a=ra(i),c=gn(t),l=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(c){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&&l?-1:1);break;case"end":p[i]+=h*(n&&l?-1:1);break}return p}const Fy=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),c=await(i.isRTL==null?void 0:i.isRTL(t));let l=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:u,y:f}=Ed(l,r,c),h=r,p={},m=0;for(let g=0;g<a.length;g++){const{name:x,fn:y}=a[g],{x:w,y:k,data:I,reset:S}=await y({x:u,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:l,platform:i,elements:{reference:e,floating:t}});u=w??u,f=k??f,p={...p,[x]:{...p[x],...I}},S&&m<=50&&(m++,typeof S=="object"&&(S.placement&&(h=S.placement),S.rects&&(l=S.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):S.rects),{x:u,y:f}=Ed(l,h,c)),g=-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:c}=e,{boundary:l="clippingAncestors",rootBoundary:u="viewport",elementContext:f="floating",altBoundary:h=!1,padding:p=0}=mn(t,e),m=kd(p),x=a[h?f==="floating"?"reference":"floating":f],y=us(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(x)))==null||n?x:x.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:l,rootBoundary:u,strategy:c})),w=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)),I=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=us(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:w,offsetParent:k,strategy:c}):w);return{top:(y.top-S.top+m.top)/I.y,bottom:(S.bottom-y.bottom+m.bottom)/I.y,left:(y.left-S.left+m.left)/I.x,right:(S.right-y.right+m.right)/I.x}}const zy=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:c}=t,{element:l,padding:u=0}=mn(e,t)||{};if(l==null)return{};const f=kd(u),h={x:n,y:r},p=oa(o),m=ra(p),g=await i.getDimensions(l),x=p==="y",y=x?"top":"left",w=x?"bottom":"right",k=x?"clientHeight":"clientWidth",I=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(l));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=I/2-S/2,j=T/2-g[m]/2-1,P=Mn(f[y],j),M=Mn(f[w],j),F=P,U=T-g[m]-M,L=T/2-g[m]/2+A,K=ta(F,L,U),q=!c.arrow&&Sr(o)!=null&&L!==K&&s.reference[m]/2-(L<F?P:M)-g[m]/2<0,re=q?L<F?L-F:L-U:0;return{[p]:h[p]+re,data:{[p]:K,centerOffset:L-K-re,...q&&{alignmentOffset:re}},reset:q}}}),By=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:c,elements:l}=t,{mainAxis:u=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:g=!0,...x}=mn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const y=gn(o),w=rn(a),k=gn(a)===a,I=await(c.isRTL==null?void 0:c.isRTL(l.floating)),S=h||(k||!g?[cs(a)]:Ry(a)),C=m!=="none";!h&&C&&S.push(...Ly(a,g,m,I));const T=[a,...S],A=await lo(t,x),j=[];let P=((r=s.flip)==null?void 0:r.overflows)||[];if(u&&j.push(A[y]),f){const L=Py(o,i,I);j.push(A[L[0]],A[L[1]])}if(P=[...P,{placement:o,overflows:j}],!j.every(L=>L<=0)){var M,F;const L=(((M=s.flip)==null?void 0:M.index)||0)+1,K=T[L];if(K&&(!(f==="alignment"?w!==rn(K):!1)||P.every(W=>rn(W.placement)===w?W.overflows[0]>0:!0)))return{data:{index:L,overflows:P},reset:{placement:K}};let q=(F=P.filter(re=>re.overflows[0]<=0).sort((re,W)=>re.overflows[1]-W.overflows[1])[0])==null?void 0:F.placement;if(!q)switch(p){case"bestFit":{var U;const re=(U=P.filter(W=>{if(C){const V=rn(W.placement);return V===w||V==="y"}return!0}).map(W=>[W.placement,W.overflows.filter(V=>V>0).reduce((V,ne)=>V+ne,0)]).sort((W,V)=>W[1]-V[1])[0])==null?void 0:U[0];re&&(q=re);break}case"initialPlacement":q=a;break}if(o!==q)return{reset:{placement:q}}}return{}}}};function Id(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Ad(e){return Ay.some(t=>e[t]>=0)}const Uy=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=mn(e,t);switch(r){case"referenceHidden":{const s=await lo(t,{...o,elementContext:"reference"}),i=Id(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Ad(i)}}}case"escaped":{const s=await lo(t,{...o,altBoundary:!0}),i=Id(s,n.floating);return{data:{escapedOffsets:i,escaped:Ad(i)}}}default:return{}}}}},Nd=new Set(["left","top"]);async function Hy(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=gn(n),a=Sr(n),c=rn(n)==="y",l=Nd.has(i)?-1:1,u=s&&c?-1:1,f=mn(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),c?{x:p*u,y:h*l}:{x:h*l,y:p*u}}const Wy=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,c=await Hy(t,e);return i===((n=a.offset)==null?void 0:n.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:o+c.x,y:s+c.y,data:{...c,placement:i}}}}},Vy=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:x=>{let{x:y,y:w}=x;return{x:y,y:w}}},...c}=mn(e,t),l={x:n,y:r},u=await lo(t,c),f=rn(gn(o)),h=na(f);let p=l[h],m=l[f];if(s){const x=h==="y"?"top":"left",y=h==="y"?"bottom":"right",w=p+u[x],k=p-u[y];p=ta(w,p,k)}if(i){const x=f==="y"?"top":"left",y=f==="y"?"bottom":"right",w=m+u[x],k=m-u[y];m=ta(w,m,k)}const g=a.fn({...t,[h]:p,[f]:m});return{...g,data:{x:g.x-n,y:g.y-r,enabled:{[h]:s,[f]:i}}}}}},Ky=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:c=!0,crossAxis:l=!0}=mn(e,t),u={x:n,y:r},f=rn(o),h=na(f);let p=u[h],m=u[f];const g=mn(a,t),x=typeof g=="number"?{mainAxis:g,crossAxis:0}:{mainAxis:0,crossAxis:0,...g};if(c){const k=h==="y"?"height":"width",I=s.reference[h]-s.floating[k]+x.mainAxis,S=s.reference[h]+s.reference[k]-x.mainAxis;p<I?p=I:p>S&&(p=S)}if(l){var y,w;const k=h==="y"?"width":"height",I=Nd.has(gn(o)),S=s.reference[f]-s.floating[k]+(I&&((y=i.offset)==null?void 0:y[f])||0)+(I?0:x.crossAxis),C=s.reference[f]+s.reference[k]+(I?0:((w=i.offset)==null?void 0:w[f])||0)-(I?x.crossAxis:0);m<S?m=S:m>C&&(m=C)}return{[h]:p,[f]:m}}}},qy=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:c=()=>{},...l}=mn(e,t),u=await lo(t,l),f=gn(o),h=Sr(o),p=rn(o)==="y",{width:m,height:g}=s.floating;let x,y;f==="top"||f==="bottom"?(x=f,y=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(y=f,x=h==="end"?"top":"bottom");const w=g-u.top-u.bottom,k=m-u.left-u.right,I=Mn(g-u[x],w),S=Mn(m-u[y],k),C=!t.middlewareData.shift;let T=I,A=S;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(A=k),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(T=w),C&&!h){const P=Mt(u.left,0),M=Mt(u.right,0),F=Mt(u.top,0),U=Mt(u.bottom,0);p?A=m-2*(P!==0||M!==0?P+M:Mt(u.left,u.right)):T=g-2*(F!==0||U!==0?F+U:Mt(u.top,u.bottom))}await c({...t,availableWidth:A,availableHeight:T});const j=await i.getDimensions(a.floating);return m!==j.width||g!==j.height?{reset:{rects:!0}}:{}}}};function ds(){return typeof window<"u"}function Cr(e){return _d(e)?(e.nodeName||"").toLowerCase():"#document"}function Ot(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function on(e){var t;return(t=(_d(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function _d(e){return ds()?e instanceof Node||e instanceof Ot(e).Node:!1}function Kt(e){return ds()?e instanceof Element||e instanceof Ot(e).Element:!1}function sn(e){return ds()?e instanceof HTMLElement||e instanceof Ot(e).HTMLElement:!1}function jd(e){return!ds()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Ot(e).ShadowRoot}const Gy=new Set(["inline","contents"]);function co(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=qt(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!Gy.has(o)}const Yy=new Set(["table","td","th"]);function Xy(e){return Yy.has(Cr(e))}const Jy=[":popover-open",":modal"];function fs(e){return Jy.some(t=>{try{return e.matches(t)}catch{return!1}})}const Zy=["transform","translate","scale","rotate","perspective"],Qy=["transform","translate","scale","rotate","perspective","filter"],ew=["paint","layout","strict","content"];function ia(e){const t=aa(),n=Kt(e)?qt(e):e;return Zy.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)||Qy.some(r=>(n.willChange||"").includes(r))||ew.some(r=>(n.contain||"").includes(r))}function tw(e){let t=On(e);for(;sn(t)&&!Tr(t);){if(ia(t))return t;if(fs(t))return null;t=On(t)}return null}function aa(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const nw=new Set(["html","body","#document"]);function Tr(e){return nw.has(Cr(e))}function qt(e){return Ot(e).getComputedStyle(e)}function hs(e){return Kt(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function On(e){if(Cr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||jd(e)&&e.host||on(e);return jd(t)?t.host:t}function Pd(e){const t=On(e);return Tr(t)?e.ownerDocument?e.ownerDocument.body:e.body:sn(t)&&co(t)?t:Pd(t)}function uo(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Pd(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Ot(o);if(s){const a=la(i);return t.concat(i,i.visualViewport||[],co(o)?o:[],a&&n?uo(a):[])}return t.concat(o,uo(o,[],n))}function la(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Rd(e){const t=qt(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=sn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=as(n)!==s||as(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function ca(e){return Kt(e)?e:e.contextElement}function kr(e){const t=ca(e);if(!sn(t))return nn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Rd(t);let i=(s?as(n.width):n.width)/r,a=(s?as(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const rw=nn(0);function Md(e){const t=Ot(e);return!aa()||!t.visualViewport?rw:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function ow(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Ot(e)?!1:t}function Jn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=ca(e);let i=nn(1);t&&(r?Kt(r)&&(i=kr(r)):i=kr(e));const a=ow(s,n,r)?Md(s):nn(0);let c=(o.left+a.x)/i.x,l=(o.top+a.y)/i.y,u=o.width/i.x,f=o.height/i.y;if(s){const h=Ot(s),p=r&&Kt(r)?Ot(r):r;let m=h,g=la(m);for(;g&&r&&p!==m;){const x=kr(g),y=g.getBoundingClientRect(),w=qt(g),k=y.left+(g.clientLeft+parseFloat(w.paddingLeft))*x.x,I=y.top+(g.clientTop+parseFloat(w.paddingTop))*x.y;c*=x.x,l*=x.y,u*=x.x,f*=x.y,c+=k,l+=I,m=Ot(g),g=la(m)}}return us({width:u,height:f,x:c,y:l})}function ps(e,t){const n=hs(e).scrollLeft;return t?t.left+n:Jn(on(e)).left+n}function Od(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-ps(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function sw(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=on(r),a=t?fs(t.floating):!1;if(r===i||a&&s)return n;let c={scrollLeft:0,scrollTop:0},l=nn(1);const u=nn(0),f=sn(r);if((f||!f&&!s)&&((Cr(r)!=="body"||co(i))&&(c=hs(r)),sn(r))){const p=Jn(r);l=kr(r),u.x=p.x+r.clientLeft,u.y=p.y+r.clientTop}const h=i&&!f&&!s?Od(i,c):nn(0);return{width:n.width*l.x,height:n.height*l.y,x:n.x*l.x-c.scrollLeft*l.x+u.x+h.x,y:n.y*l.y-c.scrollTop*l.y+u.y+h.y}}function iw(e){return Array.from(e.getClientRects())}function aw(e){const t=on(e),n=hs(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+ps(e);const a=-n.scrollTop;return qt(r).direction==="rtl"&&(i+=Mt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const Dd=25;function lw(e,t){const n=Ot(e),r=on(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,c=0;if(o){s=o.width,i=o.height;const u=aa();(!u||u&&t==="fixed")&&(a=o.offsetLeft,c=o.offsetTop)}const l=ps(r);if(l<=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<=Dd&&(s-=m)}else l<=Dd&&(s+=l);return{width:s,height:i,x:a,y:c}}const cw=new Set(["absolute","fixed"]);function uw(e,t){const n=Jn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=sn(e)?kr(e):nn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,c=o*s.x,l=r*s.y;return{width:i,height:a,x:c,y:l}}function Ld(e,t,n){let r;if(t==="viewport")r=lw(e,n);else if(t==="document")r=aw(on(e));else if(Kt(t))r=uw(t,n);else{const o=Md(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return us(r)}function $d(e,t){const n=On(e);return n===t||!Kt(n)||Tr(n)?!1:qt(n).position==="fixed"||$d(n,t)}function dw(e,t){const n=t.get(e);if(n)return n;let r=uo(e,[],!1).filter(a=>Kt(a)&&Cr(a)!=="body"),o=null;const s=qt(e).position==="fixed";let i=s?On(e):e;for(;Kt(i)&&!Tr(i);){const a=qt(i),c=ia(i);!c&&a.position==="fixed"&&(o=null),(s?!c&&!o:!c&&a.position==="static"&&!!o&&cw.has(o.position)||co(i)&&!c&&$d(e,i))?r=r.filter(u=>u!==i):o=a,i=On(i)}return t.set(e,r),r}function fw(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?fs(t)?[]:dw(t,this._c):[].concat(n),r],a=i[0],c=i.reduce((l,u)=>{const f=Ld(t,u,o);return l.top=Mt(f.top,l.top),l.right=Mn(f.right,l.right),l.bottom=Mn(f.bottom,l.bottom),l.left=Mt(f.left,l.left),l},Ld(t,a,o));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}}function hw(e){const{width:t,height:n}=Rd(e);return{width:t,height:n}}function pw(e,t,n){const r=sn(t),o=on(t),s=n==="fixed",i=Jn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const c=nn(0);function l(){c.x=ps(o)}if(r||!r&&!s)if((Cr(t)!=="body"||co(o))&&(a=hs(t)),r){const p=Jn(t,!0,s,t);c.x=p.x+t.clientLeft,c.y=p.y+t.clientTop}else o&&l();s&&!r&&o&&l();const u=o&&!r&&!s?Od(o,a):nn(0),f=i.left+a.scrollLeft-c.x-u.x,h=i.top+a.scrollTop-c.y-u.y;return{x:f,y:h,width:i.width,height:i.height}}function ua(e){return qt(e).position==="static"}function Fd(e,t){if(!sn(e)||qt(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return on(e)===n&&(n=n.ownerDocument.body),n}function zd(e,t){const n=Ot(e);if(fs(e))return n;if(!sn(e)){let o=On(e);for(;o&&!Tr(o);){if(Kt(o)&&!ua(o))return o;o=On(o)}return n}let r=Fd(e,t);for(;r&&Xy(r)&&ua(r);)r=Fd(r,t);return r&&Tr(r)&&ua(r)&&!ia(r)?n:r||tw(e)||n}const mw=async function(e){const t=this.getOffsetParent||zd,n=this.getDimensions,r=await n(e.floating);return{reference:pw(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function gw(e){return qt(e).direction==="rtl"}const xw={convertOffsetParentRelativeRectToViewportRelativeRect:sw,getDocumentElement:on,getClippingRect:fw,getOffsetParent:zd,getElementRects:mw,getClientRects:iw,getDimensions:hw,getScale:kr,isElement:Kt,isRTL:gw};function Bd(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function bw(e,t){let n=null,r;const o=on(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,c){a===void 0&&(a=!1),c===void 0&&(c=1),s();const l=e.getBoundingClientRect(),{left:u,top:f,width:h,height:p}=l;if(a||t(),!h||!p)return;const m=ls(f),g=ls(o.clientWidth-(u+h)),x=ls(o.clientHeight-(f+p)),y=ls(u),k={rootMargin:-m+"px "+-g+"px "+-x+"px "+-y+"px",threshold:Mt(0,Mn(1,c))||1};let I=!0;function S(C){const T=C[0].intersectionRatio;if(T!==c){if(!I)return i();T?i(!1,T):r=setTimeout(()=>{i(!1,1e-7)},1e3)}T===1&&!Bd(l,e.getBoundingClientRect())&&i(),I=!1}try{n=new IntersectionObserver(S,{...k,root:o.ownerDocument})}catch{n=new IntersectionObserver(S,k)}n.observe(e)}return i(!0),s}function yw(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:c=!1}=r,l=ca(e),u=o||s?[...l?uo(l):[],...uo(t)]:[];u.forEach(y=>{o&&y.addEventListener("scroll",n,{passive:!0}),s&&y.addEventListener("resize",n)});const f=l&&a?bw(l,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(y=>{let[w]=y;w&&w.target===l&&p&&(p.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var k;(k=p)==null||k.observe(t)})),n()}),l&&!c&&p.observe(l),p.observe(t));let m,g=c?Jn(e):null;c&&x();function x(){const y=Jn(e);g&&!Bd(g,y)&&n(),g=y,m=requestAnimationFrame(x)}return n(),()=>{var y;u.forEach(w=>{o&&w.removeEventListener("scroll",n),s&&w.removeEventListener("resize",n)}),f==null||f(),(y=p)==null||y.disconnect(),p=null,c&&cancelAnimationFrame(m)}}const ww=Wy,vw=Vy,Sw=By,Cw=qy,Tw=Uy,Ud=zy,kw=Ky,Ew=(e,t,n)=>{const r=new Map,o={platform:xw,...n},s={...o.platform,_c:r};return Fy(e,t,{...o,platform:s})};var Iw=typeof document<"u",Aw=function(){},ms=Iw?v.useLayoutEffect:Aw;function gs(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(!gs(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)&&!gs(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Hd(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Wd(e,t){const n=Hd(e);return Math.round(t*n)/n}function da(e){const t=b.useRef(e);return ms(()=>{t.current=e}),t}function Nw(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:c,open:l}=e,[u,f]=b.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[h,p]=b.useState(r);gs(h,r)||p(r);const[m,g]=b.useState(null),[x,y]=b.useState(null),w=b.useCallback(W=>{W!==C.current&&(C.current=W,g(W))},[]),k=b.useCallback(W=>{W!==T.current&&(T.current=W,y(W))},[]),I=s||m,S=i||x,C=b.useRef(null),T=b.useRef(null),A=b.useRef(u),j=c!=null,P=da(c),M=da(o),F=da(l),U=b.useCallback(()=>{if(!C.current||!T.current)return;const W={placement:t,strategy:n,middleware:h};M.current&&(W.platform=M.current),Ew(C.current,T.current,W).then(V=>{const ne={...V,isPositioned:F.current!==!1};L.current&&!gs(A.current,ne)&&(A.current=ne,il.flushSync(()=>{f(ne)}))})},[h,t,n,M,F]);ms(()=>{l===!1&&A.current.isPositioned&&(A.current.isPositioned=!1,f(W=>({...W,isPositioned:!1})))},[l]);const L=b.useRef(!1);ms(()=>(L.current=!0,()=>{L.current=!1}),[]),ms(()=>{if(I&&(C.current=I),S&&(T.current=S),I&&S){if(P.current)return P.current(I,S,U);U()}},[I,S,U,P,j]);const K=b.useMemo(()=>({reference:C,floating:T,setReference:w,setFloating:k}),[w,k]),q=b.useMemo(()=>({reference:I,floating:S}),[I,S]),re=b.useMemo(()=>{const W={position:n,left:0,top:0};if(!q.floating)return W;const V=Wd(q.floating,u.x),ne=Wd(q.floating,u.y);return a?{...W,transform:"translate("+V+"px, "+ne+"px)",...Hd(q.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:V,top:ne}},[n,a,q.floating,u.x,u.y]);return b.useMemo(()=>({...u,update:U,refs:K,elements:q,floatingStyles:re}),[u,U,K,q,re])}const _w=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?Ud({element:r.current,padding:o}).fn(n):{}:r?Ud({element:r,padding:o}).fn(n):{}}}},jw=(e,t)=>({...ww(e),options:[e,t]}),Pw=(e,t)=>({...vw(e),options:[e,t]}),Rw=(e,t)=>({...kw(e),options:[e,t]}),Mw=(e,t)=>({...Sw(e),options:[e,t]}),Ow=(e,t)=>({...Cw(e),options:[e,t]}),Dw=(e,t)=>({...Tw(e),options:[e,t]}),Lw=(e,t)=>({..._w(e),options:[e,t]});var $w="Arrow",Vd=b.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return d.jsx(Ne.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"})})});Vd.displayName=$w;var Fw=Vd;function zw(e){const[t,n]=b.useState(void 0);return tn(()=>{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 c=s.borderBoxSize,l=Array.isArray(c)?c[0]:c;i=l.inlineSize,a=l.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 fa="Popper",[Kd,qd]=Pn(fa),[Bw,Gd]=Kd(fa),Yd=e=>{const{__scopePopper:t,children:n}=e,[r,o]=b.useState(null);return d.jsx(Bw,{scope:t,anchor:r,onAnchorChange:o,children:n})};Yd.displayName=fa;var Xd="PopperAnchor",Jd=b.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Gd(Xd,n),i=b.useRef(null),a=Je(t,i),c=b.useRef(null);return b.useEffect(()=>{const l=c.current;c.current=(r==null?void 0:r.current)||i.current,l!==c.current&&s.onAnchorChange(c.current)}),r?null:d.jsx(Ne.div,{...o,ref:a})});Jd.displayName=Xd;var ha="PopperContent",[Uw,Hw]=Kd(ha),Zd=b.forwardRef((e,t)=>{var ee,_,B,X,le,me;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:c=!0,collisionBoundary:l=[],collisionPadding:u=0,sticky:f="partial",hideWhenDetached:h=!1,updatePositionStrategy:p="optimized",onPlaced:m,...g}=e,x=Gd(ha,n),[y,w]=b.useState(null),k=Je(t,be=>w(be)),[I,S]=b.useState(null),C=zw(I),T=(C==null?void 0:C.width)??0,A=(C==null?void 0:C.height)??0,j=r+(s!=="center"?"-"+s:""),P=typeof u=="number"?u:{top:0,right:0,bottom:0,left:0,...u},M=Array.isArray(l)?l:[l],F=M.length>0,U={padding:P,boundary:M.filter(Vw),altBoundary:F},{refs:L,floatingStyles:K,placement:q,isPositioned:re,middlewareData:W}=Nw({strategy:"fixed",placement:j,whileElementsMounted:(...be)=>yw(...be,{animationFrame:p==="always"}),elements:{reference:x.anchor},middleware:[jw({mainAxis:o+A,alignmentAxis:i}),c&&Pw({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?Rw():void 0,...U}),c&&Mw({...U}),Ow({...U,apply:({elements:be,rects:Te,availableWidth:Ae,availableHeight:ze})=>{const{width:Ze,height:Ye}=Te.reference,Ve=be.floating.style;Ve.setProperty("--radix-popper-available-width",`${Ae}px`),Ve.setProperty("--radix-popper-available-height",`${ze}px`),Ve.setProperty("--radix-popper-anchor-width",`${Ze}px`),Ve.setProperty("--radix-popper-anchor-height",`${Ye}px`)}}),I&&Lw({element:I,padding:a}),Kw({arrowWidth:T,arrowHeight:A}),h&&Dw({strategy:"referenceHidden",...U})]}),[V,ne]=tf(q),H=yt(m);tn(()=>{re&&(H==null||H())},[re,H]);const O=(ee=W.arrow)==null?void 0:ee.x,N=(_=W.arrow)==null?void 0:_.y,$=((B=W.arrow)==null?void 0:B.centerOffset)!==0,[D,G]=b.useState();return tn(()=>{y&&G(window.getComputedStyle(y).zIndex)},[y]),d.jsx("div",{ref:L.setFloating,"data-radix-popper-content-wrapper":"",style:{...K,transform:re?K.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:D,"--radix-popper-transform-origin":[(X=W.transformOrigin)==null?void 0:X.x,(le=W.transformOrigin)==null?void 0:le.y].join(" "),...((me=W.hide)==null?void 0:me.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:d.jsx(Uw,{scope:n,placedSide:V,onArrowChange:S,arrowX:O,arrowY:N,shouldHideArrow:$,children:d.jsx(Ne.div,{"data-side":V,"data-align":ne,...g,ref:k,style:{...g.style,animation:re?void 0:"none"}})})})});Zd.displayName=ha;var Qd="PopperArrow",Ww={top:"bottom",right:"left",bottom:"top",left:"right"},ef=b.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=Hw(Qd,r),i=Ww[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(Fw,{...o,ref:n,style:{...o.style,display:"block"}})})});ef.displayName=Qd;function Vw(e){return e!==null}var Kw=e=>({name:"transformOrigin",options:e,fn(t){var x,y,w;const{placement:n,rects:r,middlewareData:o}=t,i=((x=o.arrow)==null?void 0:x.centerOffset)!==0,a=i?0:e.arrowWidth,c=i?0:e.arrowHeight,[l,u]=tf(n),f={start:"0%",center:"50%",end:"100%"}[u],h=(((y=o.arrow)==null?void 0:y.x)??0)+a/2,p=(((w=o.arrow)==null?void 0:w.y)??0)+c/2;let m="",g="";return l==="bottom"?(m=i?f:`${h}px`,g=`${-c}px`):l==="top"?(m=i?f:`${h}px`,g=`${r.floating.height+c}px`):l==="right"?(m=`${-c}px`,g=i?f:`${p}px`):l==="left"&&(m=`${r.floating.width+c}px`,g=i?f:`${p}px`),{data:{x:m,y:g}}}});function tf(e){const[t,n="center"]=e.split("-");return[t,n]}var qw=Yd,Gw=Jd,Yw=Zd,Xw=ef,Jw="Portal",pa=b.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=b.useState(!1);tn(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Hs.createPortal(d.jsx(Ne.div,{...r,ref:t}),i):null});pa.displayName=Jw;function Zw(e,t){return b.useReducer((n,r)=>t[n][r]??n,e)}var Dt=e=>{const{present:t,children:n}=e,r=Qw(t),o=typeof n=="function"?n({present:r.isPresent}):b.Children.only(n),s=Je(r.ref,ev(o));return typeof n=="function"||r.isPresent?b.cloneElement(o,{ref:s}):null};Dt.displayName="Presence";function Qw(e){const[t,n]=b.useState(),r=b.useRef(null),o=b.useRef(e),s=b.useRef("none"),i=e?"mounted":"unmounted",[a,c]=Zw(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return b.useEffect(()=>{const l=xs(r.current);s.current=a==="mounted"?l:"none"},[a]),tn(()=>{const l=r.current,u=o.current;if(u!==e){const h=s.current,p=xs(l);e?c("MOUNT"):p==="none"||(l==null?void 0:l.display)==="none"?c("UNMOUNT"):c(u&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,c]),tn(()=>{if(t){let l;const u=t.ownerDocument.defaultView??window,f=p=>{const g=xs(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&g&&(c("ANIMATION_END"),!o.current)){const x=t.style.animationFillMode;t.style.animationFillMode="forwards",l=u.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=x)})}},h=p=>{p.target===t&&(s.current=xs(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{u.clearTimeout(l),t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else c("ANIMATION_END")},[t,c]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:b.useCallback(l=>{r.current=l?getComputedStyle(l):null,n(l)},[])}}function xs(e){return(e==null?void 0:e.animationName)||"none"}function ev(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 ma="rovingFocusGroup.onEntryFocus",tv={bubbles:!1,cancelable:!0},fo="RovingFocusGroup",[ga,nf,nv]=dd(fo),[rv,rf]=Pn(fo,[nv]),[ov,sv]=rv(fo),of=b.forwardRef((e,t)=>d.jsx(ga.Provider,{scope:e.__scopeRovingFocusGroup,children:d.jsx(ga.Slot,{scope:e.__scopeRovingFocusGroup,children:d.jsx(iv,{...e,ref:t})})}));of.displayName=fo;var iv=b.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:c,onEntryFocus:l,preventScrollOnEntryFocus:u=!1,...f}=e,h=b.useRef(null),p=Je(t,h),m=Gi(s),[g,x]=is({prop:i,defaultProp:a??null,onChange:c,caller:fo}),[y,w]=b.useState(!1),k=yt(l),I=nf(n),S=b.useRef(!1),[C,T]=b.useState(0);return b.useEffect(()=>{const A=h.current;if(A)return A.addEventListener(ma,k),()=>A.removeEventListener(ma,k)},[k]),d.jsx(ov,{scope:n,orientation:r,dir:m,loop:o,currentTabStopId:g,onItemFocus:b.useCallback(A=>x(A),[x]),onItemShiftTab:b.useCallback(()=>w(!0),[]),onFocusableItemAdd:b.useCallback(()=>T(A=>A+1),[]),onFocusableItemRemove:b.useCallback(()=>T(A=>A-1),[]),children:d.jsx(Ne.div,{tabIndex:y||C===0?-1:0,"data-orientation":r,...f,ref:p,style:{outline:"none",...e.style},onMouseDown:ve(e.onMouseDown,()=>{S.current=!0}),onFocus:ve(e.onFocus,A=>{const j=!S.current;if(A.target===A.currentTarget&&j&&!y){const P=new CustomEvent(ma,tv);if(A.currentTarget.dispatchEvent(P),!P.defaultPrevented){const M=I().filter(q=>q.focusable),F=M.find(q=>q.active),U=M.find(q=>q.id===g),K=[F,U,...M].filter(Boolean).map(q=>q.ref.current);lf(K,u)}}S.current=!1}),onBlur:ve(e.onBlur,()=>w(!1))})})}),sf="RovingFocusGroupItem",af=b.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,c=Rt(),l=s||c,u=sv(sf,n),f=u.currentTabStopId===l,h=nf(n),{onFocusableItemAdd:p,onFocusableItemRemove:m,currentTabStopId:g}=u;return b.useEffect(()=>{if(r)return p(),()=>m()},[r,p,m]),d.jsx(ga.ItemSlot,{scope:n,id:l,focusable:r,active:o,children:d.jsx(Ne.span,{tabIndex:f?0:-1,"data-orientation":u.orientation,...a,ref:t,onMouseDown:ve(e.onMouseDown,x=>{r?u.onItemFocus(l):x.preventDefault()}),onFocus:ve(e.onFocus,()=>u.onItemFocus(l)),onKeyDown:ve(e.onKeyDown,x=>{if(x.key==="Tab"&&x.shiftKey){u.onItemShiftTab();return}if(x.target!==x.currentTarget)return;const y=cv(x,u.orientation,u.dir);if(y!==void 0){if(x.metaKey||x.ctrlKey||x.altKey||x.shiftKey)return;x.preventDefault();let k=h().filter(I=>I.focusable).map(I=>I.ref.current);if(y==="last")k.reverse();else if(y==="prev"||y==="next"){y==="prev"&&k.reverse();const I=k.indexOf(x.currentTarget);k=u.loop?uv(k,I+1):k.slice(I+1)}setTimeout(()=>lf(k))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:g!=null}):i})})});af.displayName=sf;var av={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function lv(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function cv(e,t,n){const r=lv(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return av[r]}function lf(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function uv(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var dv=of,fv=af,hv=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Er=new WeakMap,bs=new WeakMap,ys={},xa=0,cf=function(e){return e&&(e.host||cf(e.parentNode))},pv=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=cf(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})},mv=function(e,t,n,r){var o=pv(t,Array.isArray(e)?e:[e]);ys[n]||(ys[n]=new WeakMap);var s=ys[n],i=[],a=new Set,c=new Set(o),l=function(f){!f||a.has(f)||(a.add(f),l(f.parentNode))};o.forEach(l);var u=function(f){!f||c.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",g=(Er.get(h)||0)+1,x=(s.get(h)||0)+1;Er.set(h,g),s.set(h,x),i.push(h),g===1&&m&&bs.set(h,!0),x===1&&h.setAttribute(n,"true"),m||h.setAttribute(r,"true")}catch(y){console.error("aria-hidden: cannot operate on ",h,y)}})};return u(t),a.clear(),xa++,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||(bs.has(f)||f.removeAttribute(r),bs.delete(f)),p||f.removeAttribute(n)}),xa--,xa||(Er=new WeakMap,Er=new WeakMap,bs=new WeakMap,ys={})}},uf=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=hv(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),mv(r,o,n,"aria-hidden")):function(){return null}},an=function(){return an=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},an.apply(this,arguments)};function df(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 gv(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 ws="right-scroll-bar-position",vs="width-before-scroll-bar",xv="with-scroll-bars-hidden",bv="--removed-body-scroll-bar-size";function ba(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function yv(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 wv=typeof window<"u"?b.useLayoutEffect:b.useEffect,ff=new WeakMap;function vv(e,t){var n=yv(null,function(r){return e.forEach(function(o){return ba(o,r)})});return wv(function(){var r=ff.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||ba(a,null)}),s.forEach(function(a){o.has(a)||ba(a,i)})}ff.set(n,e)},[e]),n}function Sv(e){return e}function Cv(e,t){t===void 0&&(t=Sv);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 c=function(){var u=i;i=[],u.forEach(s)},l=function(){return Promise.resolve().then(c)};l(),n={push:function(u){i.push(u),l()},filter:function(u){return i=i.filter(u),n}}}};return o}function Tv(e){e===void 0&&(e={});var t=Cv(null);return t.options=an({async:!0,ssr:!1},e),t}var hf=function(e){var t=e.sideCar,n=df(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 b.createElement(r,an({},n))};hf.isSideCarExport=!0;function kv(e,t){return e.useMedium(t),hf}var pf=Tv(),ya=function(){},Ss=b.forwardRef(function(e,t){var n=b.useRef(null),r=b.useState({onScrollCapture:ya,onWheelCapture:ya,onTouchMoveCapture:ya}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,c=e.className,l=e.removeScrollBar,u=e.enabled,f=e.shards,h=e.sideCar,p=e.noRelative,m=e.noIsolation,g=e.inert,x=e.allowPinchZoom,y=e.as,w=y===void 0?"div":y,k=e.gapMode,I=df(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),S=h,C=vv([n,t]),T=an(an({},I),o);return b.createElement(b.Fragment,null,u&&b.createElement(S,{sideCar:pf,removeScrollBar:l,shards:f,noRelative:p,noIsolation:m,inert:g,setCallbacks:s,allowPinchZoom:!!x,lockRef:n,gapMode:k}),i?b.cloneElement(b.Children.only(a),an(an({},T),{ref:C})):b.createElement(w,an({},T,{className:c,ref:C}),a))});Ss.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Ss.classNames={fullWidth:vs,zeroRight:ws};var Ev=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Iv(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Ev();return t&&e.setAttribute("nonce",t),e}function Av(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Nv(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var _v=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Iv())&&(Av(t,n),Nv(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},jv=function(){var e=_v();return function(t,n){b.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},mf=function(){var e=jv(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Pv={left:0,top:0,right:0,gap:0},wa=function(e){return parseInt(e||"",10)||0},Rv=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[wa(n),wa(r),wa(o)]},Mv=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Pv;var t=Rv(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])}},Ov=mf(),Ir="data-scroll-locked",Dv=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
86
+ Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+yt(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 id(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...me.defaults,...s};const i=ey(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(Jb(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let c;try{r.hooks&&(n=r.hooks.preprocess(n)),c=e(n,r)}catch(f){return i(f)}const l=function(f){let h;if(!f)try{r.walkTokens&&me.walkTokens(c,r.walkTokens),h=t(c,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,!c.length))return l();let u=0;me.walkTokens(c,function(f){f.type==="code"&&(u++,setTimeout(()=>{a(f.text,f.lang,function(h,p){if(h)return l(h);p!=null&&p!==f.text&&(f.text=p,f.escaped=!0),u--,u===0&&l()})},0))}),u===0&&l();return}if(r.async)return Promise.resolve(r.hooks?r.hooks.preprocess(n):n).then(a=>e(a,r)).then(a=>r.walkTokens?Promise.all(me.walkTokens(a,r.walkTokens)).then(()=>a):a).then(a=>t(a,r)).then(a=>r.hooks?r.hooks.postprocess(a):a).catch(i);try{r.hooks&&(n=r.hooks.preprocess(n));const a=e(n,r);r.walkTokens&&me.walkTokens(a,r.walkTokens);let c=t(a,r);return r.hooks&&(c=r.hooks.postprocess(c)),c}catch(a){return i(a)}}}function me(e,t,n){return id(Nn.lex,jn.parse)(e,t,n)}me.options=me.setOptions=function(e){return me.defaults={...me.defaults,...e},$b(me.defaults),me},me.getDefaults=Gu,me.defaults=Xn,me.use=function(...e){const t=me.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=me.defaults.async||r.async||!1,n.extensions&&(n.extensions.forEach(o=>{if(!o.name)throw new Error("extension name required");if(o.renderer){const s=t.renderers[o.name];s?t.renderers[o.name]=function(...i){let a=o.renderer.apply(this,i);return a===!1&&(a=s.apply(this,i)),a}:t.renderers[o.name]=o.renderer}if(o.tokenizer){if(!o.level||o.level!=="block"&&o.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");t[o.level]?t[o.level].unshift(o.tokenizer):t[o.level]=[o.tokenizer],o.start&&(o.level==="block"?t.startBlock?t.startBlock.push(o.start):t.startBlock=[o.start]:o.level==="inline"&&(t.startInline?t.startInline.push(o.start):t.startInline=[o.start]))}o.childTokens&&(t.childTokens[o.name]=o.childTokens)}),r.extensions=t),n.renderer){const o=me.defaults.renderer||new Ui;for(const s in n.renderer){const i=o[s];o[s]=(...a)=>{let c=n.renderer[s].apply(o,a);return c===!1&&(c=i.apply(o,a)),c}}r.renderer=o}if(n.tokenizer){const o=me.defaults.tokenizer||new Bi;for(const s in n.tokenizer){const i=o[s];o[s]=(...a)=>{let c=n.tokenizer[s].apply(o,a);return c===!1&&(c=i.apply(o,a)),c}}r.tokenizer=o}if(n.hooks){const o=me.defaults.hooks||new rs;for(const s in n.hooks){const i=o[s];rs.passThroughHooks.has(s)?o[s]=a=>{if(me.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(l=>i.call(o,l));const c=n.hooks[s].call(o,a);return i.call(o,c)}:o[s]=(...a)=>{let c=n.hooks[s].apply(o,a);return c===!1&&(c=i.apply(o,a)),c}}r.hooks=o}if(n.walkTokens){const o=me.defaults.walkTokens;r.walkTokens=function(s){let i=[];return i.push(n.walkTokens.call(this,s)),o&&(i=i.concat(o.call(this,s))),i}}me.setOptions(r)})},me.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(me,r)),r.type){case"table":{for(const o of r.header)n=n.concat(me.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(me.walkTokens(s.tokens,t));break}case"list":{n=n.concat(me.walkTokens(r.items,t));break}default:me.defaults.extensions&&me.defaults.extensions.childTokens&&me.defaults.extensions.childTokens[r.type]?me.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(me.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(me.walkTokens(r.tokens,t)))}return n},me.parseInline=id(Nn.lexInline,jn.parseInline),me.Parser=jn,me.parser=jn.parse,me.Renderer=Ui,me.TextRenderer=od,me.Lexer=Nn,me.lexer=Nn.lex,me.Tokenizer=Bi,me.Slugger=sd,me.Hooks=rs,me.parse=me,me.options,me.setOptions,me.use,me.walkTokens,me.parseInline,jn.parse,Nn.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 me.parse=="function"?me.parse(i):me(i)}return typeof me.parse=="function"?me.parse(e):me(e)}catch(i){return console.error("[MarkdownContent] parse error",i),`<pre class="font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words">Error rendering markdown: ${String(i)}</pre>`}},[e,n]),s=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:pe("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 ty({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:pe("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:pe("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 Hi({showTimestamp:e,showAgentName:t,isToolMessage:n,isInterruptMessage:r=!1,iconForeground:o,agentName:s,messageIcon:i,customHeaderClass:a,customActionsClass:c,isCompactLayout:l,showActions:u,isEditing:f,messageRole:h,onCopy:p,onEdit:m,onRegenerate:g,showCheckpointControls:x,attemptCount:y,attemptIndex:w,handleOlderAttemptSelect:k,handleNewerAttemptSelect:I,messageCreatedAt:S,copied:C}){return!e&&!t&&!n&&!r?null:d.jsxs("div",{className:pe("flex items-center justify-between mb-2 pb-2",h!=="assistant"&&"border-b border-current/10",l&&"mb-1 pb-1",o,a),children:[d.jsxs("div",{className:"flex items-center gap-2",children:[i,t&&s&&d.jsx("span",{className:pe("font-medium",l?"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:[x&&y>1&&d.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[d.jsx("button",{type:"button",className:pe("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",w<y-1?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{w>=y-1||k()},"aria-label":"Older attempt (back in time)",disabled:w>=y-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:[y-w," / ",y]})}),d.jsx("button",{type:"button",className:pe("flex items-center justify-center rounded border px-1.5 py-1 transition-colors",w>0?"border-border text-foreground hover:bg-muted/60":"border-border text-muted-foreground cursor-not-allowed"),onClick:()=>{w<=0||I()},"aria-label":"Newer attempt (forward in time)",disabled:w<=0,children:d.jsx(xe.ChevronRight,{className:"h-3 w-3"})})]}),e&&S&&d.jsx("time",{className:pe("text-xs opacity-60",o,l&&"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:pe("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",c),children:[d.jsx("div",{className:"relative",children:d.jsx(Je,{variant:"ghost",size:"sm",onClick:p,className:pe("h-6 w-6 p-0 hover:bg-foreground/10",o,l&&"h-5 w-5"),"aria-label":"Copy message",title:"Copy message",children:d.jsx(xe.Copy,{className:pe(C?"text-success":o,l?"h-3 w-3":"h-4 w-4")})})}),h==="user"&&m&&d.jsx(Je,{variant:"ghost",size:"sm",onClick:m,className:pe("h-6 w-6 p-0 hover:bg-foreground/10",o,l&&"h-5 w-5"),"aria-label":"Edit message",children:d.jsx(xe.Edit,{className:pe(o,l?"h-3 w-3":"h-4 w-4")})}),h==="assistant"&&g&&d.jsx(Je,{variant:"ghost",size:"sm",onClick:g,className:pe("h-6 w-6 p-0 hover:bg-foreground/10",o,l&&"h-5 w-5"),"aria-label":"Regenerate response",children:d.jsx(xe.RotateCcw,{className:pe(o,l?"h-3 w-3":"h-4 w-4")})})]})]})]})}function Wi(e){return v.useMemo(()=>({textContent:wg(e),imageParts:vg(e),fileParts:Sg(e),toolCalls:ai(e),interruptParts:Cg(e),contentParts:e.content}),[e])}function ad(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 os=v.memo(function({contentParts:t,textContent:n,imageParts:r,fileParts:o,messageRole:s,isCompactLayout:i=!1,truncateUserMessages:a=!1,userMessagePreviewLength:c=500,isUserExpanded:l=!1,setIsUserExpanded:u,uploadingFiles:f={},handleFileClick:h,isStreamingMessage:p=!1,renderStreamingMarkdown:m=!0,enableStreamingMarkdownBuffer:g=!0,streamingDebounceMs:x=0}){const y=ad(t,g&&p,x),w=v.useMemo(()=>y.filter(F=>F.type==="text"),[y]),k=v.useMemo(()=>w.map(F=>F.text??"").join(""),[w]),I=m&&p,S=v.useMemo(()=>{if(!I)return null;const F=ry(k);return{stablePart:k.slice(0,F),tailPart:k.slice(F)}},[k,I]),C=v.useMemo(()=>{if(!S)return null;const{stablePart:F,tailPart:B}=S;return!F&&!B?null:d.jsxs("div",{className:"space-y-2",children:[F?d.jsx(so,{content:F,allowHtml:!1}):null,B?d.jsx(so,{content:B,allowHtml:!1}):null]})},[S]),T=()=>!r||r.length===0?null:d.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:r.map((F,B)=>{const O=F;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-${B}`)})}),A=(F,B)=>{if(F.type==="text"){const O=F.text??"",G=O.trim(),Y=pr(G);return Y&&s!=="tool"?d.jsx(Rb,{data:Y},B):s==="user"&&a&&G.length>c&&!l?d.jsx(ty,{text:G,expanded:l,onExpandedChange:u||(()=>{}),previewLength:c,isCompact:i},B):d.jsx(so,{content:O,allowHtml:!1},B)}if(F.type==="file"){const O=F,G=O.name||"file",Y=f[B];return d.jsxs("a",{href:O.url,onClick:re=>h==null?void 0:h(re,O,B),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:[Y?d.jsx(xe.Loader,{className:"h-4 w-4 animate-spin"}):null,d.jsxs("span",{className:"truncate max-w-[180px]",children:[G,Y?" (processing)":""]})]},B)}return null},j=I?k:n;if(!(j.trim().length>0||r.length>0||o.length>0)&&!p)return null;const L=I?y.filter(F=>F.type!=="text"):y;return d.jsxs("div",{className:"space-y-2",children:[I?C:null,L.filter(F=>F.type==="text"||F.type==="file").map((F,B)=>A(F,B)),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"})]})});os.displayName="SharedContent";function ny(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 ry(e){if(!e)return 0;for(let t=e.length;t>=0;t-=1)if(ny(e.slice(0,t)))return t;return 0}const ld=v.memo(function({isStreamingMessage:t,interruptPart:n,handleInterruptApprove:r,handleInterruptReject:o,handleInterruptAlternative:s,disableInterruptActions:i,iconForeground:a,textContent:c=""}){if(n)return d.jsx(qu,{interruptPart:n,payload:n.value,onApprove:r||(()=>{}),onReject:o||(()=>{}),onSelectAlternative:s,disabled:i,isActive:!i});const l=c.trim().length>0;return t&&!l?d.jsx(Lb,{className:a}):null});ld.displayName="InteractiveContent";const ao=v.memo(function({role:t,header:n,content:r,actions:o,status:s,isCompactLayout:i=!1,variant:a="default",customStyles:c={}}){const l=t==="user",u=t==="system",f=pe("flex w-full group py-3 md:py-4 px-2 md:px-0",l?"justify-end":"justify-start",c.container),h=pe("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":"",l?"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",c.bubble),p=pe("text-sm leading-relaxed break-words",c.content),m=pe("absolute top-0 opacity-0 group-hover:opacity-100 transition-opacity flex items-center gap-1",l?"-left-10":"-right-10",i&&"hidden",c.actions);return d.jsx("div",{className:f,children:d.jsxs("div",{className:h,children:[n&&d.jsx("div",{className:pe("mb-2 w-full",c.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 Vi=v.memo(function({message:t,messageIndex:n,isStreamingMessage:r=!1,streamingDebounceMs:o,renderStreamingMarkdown:s=!0,enableStreamingMarkdownBuffer:i=!0,layoutSize:a,showToolMessages:c,toolConfig:l,customStyles:u,onRegenerate:f,onCopy:h,getInterruptOptions:p,renderArtifactsInline:m,showToolProgress:g,showToolResultsInline:x,isEmbedded:y=!1,precedingMessages:w=[],showHeader:k,hideToolProgress:I=!1,forceAgentName:S}){var qe,Qe;const{layoutSize:C,toolConfig:T,renderArtifactsInline:A,streamingDebounceMs:j,onRegenerate:_,getInterruptOptions:L,showToolMessages:F,messageCustomStyles:B}=Fo(),O=l??T,G=a??C,Y=m??A,re=o??j??0,H=f??_,W=p??L,ne=c??F??!0,K=g??ne,M=x??ne,N={...(B==null?void 0:B(t))||{},...u},$=h,[D,q]=v.useState(!1),{respondToInterrupt:U}=qr(),[P,V]=v.useState(!1),ee=G==="phone"||G==="half-screen",{contentParts:ce,textContent:ue,imageParts:be,fileParts:Ae,toolCalls:Ie,interruptParts:Xe}=Wi(t),ze=Xe[0]||null,Ze=v.useCallback(async()=>{const De=ue;try{await navigator.clipboard.writeText(De),q(!0),setTimeout(()=>q(!1),2e3),$==null||$(De)}catch(Le){console.error("Failed to copy assistant message:",Le)}},[ue,$]),Be=v.useCallback(async(De,Le)=>{if(!(!ze||!hc(ze.id))){V(!0);try{const ht=W==null?void 0:W(t);await U(De,Le,ht)}finally{V(!1)}}},[ze,t,W,U]),dt=v.useCallback(()=>{H==null||H(n)},[H,n]),at=!y&&(k??((qe=O==null?void 0:O.getShowHeader)==null?void 0:qe.call(O,t))??!0),ct=!I&&t.role==="assistant"&&K?d.jsx(Bu,{messages:[...w,t],isStreaming:r,toolConfig:O}):null,ft=at&&d.jsx(Hi,{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:ee,showActions:!0,isEditing:!1,messageRole:t.role,onCopy:Ze,onEdit:void 0,onRegenerate:dt,showCheckpointControls:!1,attemptCount:1,attemptIndex:0,handleOlderAttemptSelect:()=>{},handleNewerAttemptSelect:()=>{},messageCreatedAt:t.createdAt,copied:D,customActionsClass:N.actions}),tt=t.role==="tool",nt=tt?d.jsx(Qo,{message:t,viewMode:"expanded",isStreaming:r,toolConfig:O,expandable:(Qe=O==null?void 0:O.getToolExpandable)==null?void 0:Qe.call(O,t)}):null,ut=d.jsxs("div",{className:"space-y-4",children:[w.map(De=>{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(Qo,{message:De,viewMode:"expanded",isStreaming:!1,toolConfig:O,expandable:(Le=O==null?void 0:O.getToolExpandable)==null?void 0:Le.call(O,De)})},De.id)}),tt?nt:d.jsxs(d.Fragment,{children:[d.jsx(os,{contentParts:ce,textContent:ue,imageParts:be,fileParts:Ae,messageRole:t.role,isCompactLayout:ee,isStreamingMessage:r,renderStreamingMarkdown:s,enableStreamingMarkdownBuffer:i,streamingDebounceMs:re}),t.role==="assistant"&&M&&Ie.map(De=>d.jsx(Qo,{message:{...t,role:"tool",name:De.name,toolCallId:De.id,artifact:De.artifact,content:[{type:"text",text:JSON.stringify(De.args)}]},viewMode:"expanded",isStreaming:r,toolConfig:O},De.id)),d.jsx(ld,{message:t,isStreamingMessage:r,toolConfig:O,interruptPart:ze,handleInterruptApprove:()=>Be(!0),handleInterruptReject:()=>Be(!1),handleInterruptAlternative:(De,Le)=>Be(!0,{alternativeId:Le==null?void 0:Le.id}),disableInterruptActions:P,renderArtifactsInline:Y,iconForeground:"text-[hsl(var(--chat-bubble-ai-text))]",textContent:ue})]})]});return y?ut:d.jsx(ao,{role:t.role,header:ft,status:ct,content:ut,isCompactLayout:ee,customStyles:N})});Vi.displayName="AssistantMessageComponent";const Ki=v.memo(function({message:t,layoutSize:n="desktop",truncateUserMessages:r=!0,userMessagePreviewLength:o=500,enableMessageEditing:s=!0,onEdit:i,checkpointIndex:a,onSelectCheckpoint:c,customStyles:l={}}){const[u,f]=v.useState(!1),[h,p]=v.useState(!1),m=n==="phone"||n==="half-screen",{contentParts:g,textContent:x,imageParts:y,fileParts:w}=Wi(t),k=v.useCallback(async()=>{try{await navigator.clipboard.writeText(x),f(!0),setTimeout(()=>f(!1),2e3)}catch(B){console.error("Failed to copy user message:",B)}},[x]),I=v.useCallback(()=>{if(!i||!t.id)return;const B={checkpointId:t.checkpointId??null,checkpointNs:t.checkpointNs??null};i(t.id,x,B)},[i,t,x]),{attemptCount:S,attemptIndex:C,attempts:T}=v.useMemo(()=>a?Gg(t.id,t.checkpointId,a):{attemptCount:1,attemptIndex:0,attempts:[]},[t.id,t.checkpointId,a]),A=S>1&&!!c,j=v.useCallback(()=>{const B=T[C+1];B&&c&&c(B.id,void 0,!!B.isLatestAttempt)},[T,C,c]),_=v.useCallback(()=>{const B=T[C-1];B&&c&&c(B.id,void 0,!!B.isLatestAttempt)},[T,C,c]),L=d.jsx(Hi,{showTimestamp:!0,showAgentName:!0,isToolMessage:!1,iconForeground:"text-[hsl(var(--chat-bubble-user-text))]",agentName:null,messageIcon:d.jsx(xe.User,{className:pe(m?"h-3 w-3":"h-4 w-4","opacity-60")}),isCompactLayout:m,showActions:!0,isEditing:!1,messageRole:"user",onCopy:k,onEdit:s?I:void 0,showCheckpointControls:A,attemptCount:S,attemptIndex:C,handleOlderAttemptSelect:j,handleNewerAttemptSelect:_,messageCreatedAt:t.createdAt,copied:u,customHeaderClass:l.header,customActionsClass:l.actions}),F=d.jsx(os,{contentParts:g,textContent:x,imageParts:y,fileParts:w,messageRole:"user",truncateUserMessages:r,userMessagePreviewLength:o,isUserExpanded:h,setIsUserExpanded:p,isCompactLayout:m,handleFileClick:()=>{},uploadingFiles:{}});return d.jsx(ao,{role:"user",header:L,content:F,isCompactLayout:m,customStyles:l})});Ki.displayName="UserMessageComponent";const qi=v.memo(function({message:t,layoutSize:n="desktop",customStyles:r={}}){const o=n==="phone"||n==="half-screen",{contentParts:s,textContent:i,imageParts:a,fileParts:c}=Wi(t),l=d.jsxs("div",{className:"flex items-center gap-2 mb-1 opacity-50",children:[d.jsx(xe.Info,{className:pe(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(os,{contentParts:s,textContent:i,imageParts:a,fileParts:c,messageRole:"system",isCompactLayout:o});return d.jsx(ao,{role:"system",header:l,content:u,isCompactLayout:o,customStyles:r})});qi.displayName="SystemMessageComponent";const ss=v.forwardRef(({messages:e=[],isStreaming:t,onStartReached:n,className:r,style:o,emptyMessage:s,onScrollAway:i,onAtBottom:a,renderMessage:c},l)=>{const{followNewMessages:u,checkpointIndex:f}=Fo(),h=!!f,p=v.useRef(null),m=v.useRef(null),g=v.useRef(!1),x=v.useRef(!1),y=v.useCallback(_=>{i&&i(!_),a&&a(_)},[i,a]),w=v.useMemo(()=>{if(n)return async()=>{if(!g.current){g.current=!0;try{await n()}finally{g.current=!1}}}},[n]),k=v.useMemo(()=>!u||h?!1:"auto",[u,h]),I=e.length===0&&s,S=["flex flex-1 flex-col min-h-0 min-w-0",r].filter(Boolean).join(" "),C=()=>I?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 _,L;if(T===0){x.current=!1;return}if(!x.current)if(x.current=!0,p.current&&e.length>0){const F=e.length-1;(L=(_=p.current).scrollToIndex)==null||L.call(_,{index:F,align:"end",behavior:"auto"})}else m.current&&(m.current.scrollTop=m.current.scrollHeight)},[T,e.length]),v.useImperativeHandle(l,()=>({scrollToLatest:()=>{var _,L;if(p.current&&e.length>0){const F=e.length-1;(L=(_=p.current).scrollToIndex)==null||L.call(_,{index:F,align:"end",behavior:"auto"})}else m.current&&(m.current.scrollTop=m.current.scrollHeight)},scrollToTop:()=>{var _,L;p.current&&e.length>0?(L=(_=p.current).scrollToIndex)==null||L.call(_,{index:0,align:"start",behavior:"auto"}):m.current&&(m.current.scrollTop=0)}}),[e]);const j=v.useCallback((_,L)=>_.role==="user"?d.jsx(Ki,{message:_,messageIndex:L}):_.role==="system"?d.jsx(qi,{message:_}):d.jsx(Vi,{message:_,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(gb,{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:()=>{w&&w()},atBottomStateChange:y,style:{height:"100%",width:"100%",overscrollBehavior:"contain"},computeItemKey:(_,L)=>L.id||_,itemContent:(_,L)=>c?c(L,_):j(L,_)}):C()})})});ss.displayName="MessageList";function ve(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 cd(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function _n(...e){return t=>{let n=!1;const r=e.map(o=>{const s=cd(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():cd(e[o],null)}}}}function Ye(...e){return b.useCallback(_n(...e),e)}function oy(e,t){const n=b.createContext(t),r=s=>{const{children:i,...a}=s,c=b.useMemo(()=>a,Object.values(a));return d.jsx(n.Provider,{value:c,children:i})};r.displayName=e+"Provider";function o(s){const i=b.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 Pn(e,t=[]){let n=[];function r(s,i){const a=b.createContext(i),c=n.length;n=[...n,i];const l=f=>{var y;const{scope:h,children:p,...m}=f,g=((y=h==null?void 0:h[e])==null?void 0:y[c])||a,x=b.useMemo(()=>m,Object.values(m));return d.jsx(g.Provider,{value:x,children:p})};l.displayName=s+"Provider";function u(f,h){var g;const p=((g=h==null?void 0:h[e])==null?void 0:g[c])||a,m=b.useContext(p);if(m)return m;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[l,u]}const o=()=>{const s=n.map(i=>b.createContext(i));return function(a){const c=(a==null?void 0:a[e])||s;return b.useMemo(()=>({[`__scope${e}`]:{...a,[e]:c}}),[a,c])}};return o.scopeName=e,[r,sy(o,...t)]}function sy(...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:c,scopeName:l})=>{const f=c(s)[`__scope${l}`];return{...a,...f}},{});return b.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var tn=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{},iy=b[" useInsertionEffect ".trim().toString()]||tn;function is({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=ay({defaultProp:t,onChange:n}),a=e!==void 0,c=a?e:o;{const u=b.useRef(e!==void 0);b.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 l=b.useCallback(u=>{var f;if(a){const h=ly(u)?u(e):u;h!==e&&((f=i.current)==null||f.call(i,h))}else s(u)},[a,e,s,i]);return[c,l]}function ay({defaultProp:e,onChange:t}){const[n,r]=b.useState(e),o=b.useRef(n),s=b.useRef(t);return iy(()=>{s.current=t},[t]),b.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function ly(e){return typeof e=="function"}var cy=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ne=cy.reduce((e,t)=>{const n=cr.createSlot(`Primitive.${t}`),r=b.forwardRef((o,s)=>{const{asChild:i,...a}=o,c=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),d.jsx(c,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function ud(e,t){e&&il.flushSync(()=>e.dispatchEvent(t))}function dd(e){const t=e+"CollectionProvider",[n,r]=Pn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=g=>{const{scope:x,children:y}=g,w=v.useRef(null),k=v.useRef(new Map).current;return d.jsx(o,{scope:x,itemMap:k,collectionRef:w,children:y})};i.displayName=t;const a=e+"CollectionSlot",c=cr.createSlot(a),l=v.forwardRef((g,x)=>{const{scope:y,children:w}=g,k=s(a,y),I=Ye(x,k.collectionRef);return d.jsx(c,{ref:I,children:w})});l.displayName=a;const u=e+"CollectionItemSlot",f="data-radix-collection-item",h=cr.createSlot(u),p=v.forwardRef((g,x)=>{const{scope:y,children:w,...k}=g,I=v.useRef(null),S=Ye(x,I),C=s(u,y);return v.useEffect(()=>(C.itemMap.set(I,{ref:I,...k}),()=>void C.itemMap.delete(I))),d.jsx(h,{[f]:"",ref:S,children:w})});p.displayName=u;function m(g){const x=s(e+"CollectionConsumer",g);return v.useCallback(()=>{const w=x.collectionRef.current;if(!w)return[];const k=Array.from(w.querySelectorAll(`[${f}]`));return Array.from(x.itemMap.values()).sort((C,T)=>k.indexOf(C.ref.current)-k.indexOf(T.ref.current))},[x.collectionRef,x.itemMap])}return[{Provider:i,Slot:l,ItemSlot:p},m,r]}var uy=b.createContext(void 0);function Gi(e){const t=b.useContext(uy);return e||t||"ltr"}function wt(e){const t=b.useRef(e);return b.useEffect(()=>{t.current=e}),b.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function dy(e,t=globalThis==null?void 0:globalThis.document){const n=wt(e);b.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 fy="DismissableLayer",Yi="dismissableLayer.update",hy="dismissableLayer.pointerDownOutside",py="dismissableLayer.focusOutside",fd,hd=b.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Xi=b.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...c}=e,l=b.useContext(hd),[u,f]=b.useState(null),h=(u==null?void 0:u.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=b.useState({}),m=Ye(t,T=>f(T)),g=Array.from(l.layers),[x]=[...l.layersWithOutsidePointerEventsDisabled].slice(-1),y=g.indexOf(x),w=u?g.indexOf(u):-1,k=l.layersWithOutsidePointerEventsDisabled.size>0,I=w>=y,S=xy(T=>{const A=T.target,j=[...l.branches].some(_=>_.contains(A));!I||j||(o==null||o(T),i==null||i(T),T.defaultPrevented||a==null||a())},h),C=by(T=>{const A=T.target;[...l.branches].some(_=>_.contains(A))||(s==null||s(T),i==null||i(T),T.defaultPrevented||a==null||a())},h);return dy(T=>{w===l.layers.size-1&&(r==null||r(T),!T.defaultPrevented&&a&&(T.preventDefault(),a()))},h),b.useEffect(()=>{if(u)return n&&(l.layersWithOutsidePointerEventsDisabled.size===0&&(fd=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),l.layersWithOutsidePointerEventsDisabled.add(u)),l.layers.add(u),pd(),()=>{n&&l.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=fd)}},[u,h,n,l]),b.useEffect(()=>()=>{u&&(l.layers.delete(u),l.layersWithOutsidePointerEventsDisabled.delete(u),pd())},[u,l]),b.useEffect(()=>{const T=()=>p({});return document.addEventListener(Yi,T),()=>document.removeEventListener(Yi,T)},[]),d.jsx(Ne.div,{...c,ref:m,style:{pointerEvents:k?I?"auto":"none":void 0,...e.style},onFocusCapture:ve(e.onFocusCapture,C.onFocusCapture),onBlurCapture:ve(e.onBlurCapture,C.onBlurCapture),onPointerDownCapture:ve(e.onPointerDownCapture,S.onPointerDownCapture)})});Xi.displayName=fy;var my="DismissableLayerBranch",gy=b.forwardRef((e,t)=>{const n=b.useContext(hd),r=b.useRef(null),o=Ye(t,r);return b.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),d.jsx(Ne.div,{...e,ref:o})});gy.displayName=my;function xy(e,t=globalThis==null?void 0:globalThis.document){const n=wt(e),r=b.useRef(!1),o=b.useRef(()=>{});return b.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let c=function(){md(hy,n,l,{discrete:!0})};const l={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=c,t.addEventListener("click",o.current,{once:!0})):c()}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 by(e,t=globalThis==null?void 0:globalThis.document){const n=wt(e),r=b.useRef(!1);return b.useEffect(()=>{const o=s=>{s.target&&!r.current&&md(py,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 pd(){const e=new CustomEvent(Yi);document.dispatchEvent(e)}function md(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?ud(o,s):o.dispatchEvent(s)}var Ji=0;function gd(){b.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??xd()),document.body.insertAdjacentElement("beforeend",e[1]??xd()),Ji++,()=>{Ji===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),Ji--}},[])}function xd(){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 Zi="focusScope.autoFocusOnMount",Qi="focusScope.autoFocusOnUnmount",bd={bubbles:!1,cancelable:!0},yy="FocusScope",ea=b.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,c]=b.useState(null),l=wt(o),u=wt(s),f=b.useRef(null),h=Ye(t,g=>c(g)),p=b.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;b.useEffect(()=>{if(r){let g=function(k){if(p.paused||!a)return;const I=k.target;a.contains(I)?f.current=I:Rn(f.current,{select:!0})},x=function(k){if(p.paused||!a)return;const I=k.relatedTarget;I!==null&&(a.contains(I)||Rn(f.current,{select:!0}))},y=function(k){if(document.activeElement===document.body)for(const S of k)S.removedNodes.length>0&&Rn(a)};document.addEventListener("focusin",g),document.addEventListener("focusout",x);const w=new MutationObserver(y);return a&&w.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",g),document.removeEventListener("focusout",x),w.disconnect()}}},[r,a,p.paused]),b.useEffect(()=>{if(a){vd.add(p);const g=document.activeElement;if(!a.contains(g)){const y=new CustomEvent(Zi,bd);a.addEventListener(Zi,l),a.dispatchEvent(y),y.defaultPrevented||(wy(ky(yd(a)),{select:!0}),document.activeElement===g&&Rn(a))}return()=>{a.removeEventListener(Zi,l),setTimeout(()=>{const y=new CustomEvent(Qi,bd);a.addEventListener(Qi,u),a.dispatchEvent(y),y.defaultPrevented||Rn(g??document.body,{select:!0}),a.removeEventListener(Qi,u),vd.remove(p)},0)}}},[a,l,u,p]);const m=b.useCallback(g=>{if(!n&&!r||p.paused)return;const x=g.key==="Tab"&&!g.altKey&&!g.ctrlKey&&!g.metaKey,y=document.activeElement;if(x&&y){const w=g.currentTarget,[k,I]=vy(w);k&&I?!g.shiftKey&&y===I?(g.preventDefault(),n&&Rn(k,{select:!0})):g.shiftKey&&y===k&&(g.preventDefault(),n&&Rn(I,{select:!0})):y===w&&g.preventDefault()}},[n,r,p.paused]);return d.jsx(Ne.div,{tabIndex:-1,...i,ref:h,onKeyDown:m})});ea.displayName=yy;function wy(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Rn(r,{select:t}),document.activeElement!==n)return}function vy(e){const t=yd(e),n=wd(t,e),r=wd(t.reverse(),e);return[n,r]}function yd(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 wd(e,t){for(const n of e)if(!Sy(n,{upTo:t}))return n}function Sy(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 Cy(e){return e instanceof HTMLInputElement&&"select"in e}function Rn(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Cy(e)&&t&&e.select()}}var vd=Ty();function Ty(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=Sd(e,t),e.unshift(t)},remove(t){var n;e=Sd(e,t),(n=e[0])==null||n.resume()}}}function Sd(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function ky(e){return e.filter(t=>t.tagName!=="A")}var Ey=b[" useId ".trim().toString()]||(()=>{}),Iy=0;function Rt(e){const[t,n]=b.useState(Ey());return tn(()=>{n(r=>r??String(Iy++))},[e]),e||(t?`radix-${t}`:"")}const Ay=["top","right","bottom","left"],On=Math.min,Ot=Math.max,as=Math.round,ls=Math.floor,nn=e=>({x:e,y:e}),Ny={left:"right",right:"left",bottom:"top",top:"bottom"},jy={start:"end",end:"start"};function ta(e,t,n){return Ot(e,On(t,n))}function mn(e,t){return typeof e=="function"?e(t):e}function gn(e){return e.split("-")[0]}function Sr(e){return e.split("-")[1]}function na(e){return e==="x"?"y":"x"}function ra(e){return e==="y"?"height":"width"}const _y=new Set(["top","bottom"]);function rn(e){return _y.has(gn(e))?"y":"x"}function oa(e){return na(rn(e))}function Py(e,t,n){n===void 0&&(n=!1);const r=Sr(e),o=oa(e),s=ra(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=cs(i)),[i,cs(i)]}function Ry(e){const t=cs(e);return[sa(e),t,sa(t)]}function sa(e){return e.replace(/start|end/g,t=>jy[t])}const Cd=["left","right"],Td=["right","left"],Oy=["top","bottom"],My=["bottom","top"];function Dy(e,t,n){switch(e){case"top":case"bottom":return n?t?Td:Cd:t?Cd:Td;case"left":case"right":return t?Oy:My;default:return[]}}function Ly(e,t,n,r){const o=Sr(e);let s=Dy(gn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(sa)))),s}function cs(e){return e.replace(/left|right|bottom|top/g,t=>Ny[t])}function $y(e){return{top:0,right:0,bottom:0,left:0,...e}}function kd(e){return typeof e!="number"?$y(e):{top:e,right:e,bottom:e,left:e}}function us(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 Ed(e,t,n){let{reference:r,floating:o}=e;const s=rn(t),i=oa(t),a=ra(i),c=gn(t),l=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(c){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&&l?-1:1);break;case"end":p[i]+=h*(n&&l?-1:1);break}return p}const Fy=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),c=await(i.isRTL==null?void 0:i.isRTL(t));let l=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:u,y:f}=Ed(l,r,c),h=r,p={},m=0;for(let g=0;g<a.length;g++){const{name:x,fn:y}=a[g],{x:w,y:k,data:I,reset:S}=await y({x:u,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:l,platform:i,elements:{reference:e,floating:t}});u=w??u,f=k??f,p={...p,[x]:{...p[x],...I}},S&&m<=50&&(m++,typeof S=="object"&&(S.placement&&(h=S.placement),S.rects&&(l=S.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):S.rects),{x:u,y:f}=Ed(l,h,c)),g=-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:c}=e,{boundary:l="clippingAncestors",rootBoundary:u="viewport",elementContext:f="floating",altBoundary:h=!1,padding:p=0}=mn(t,e),m=kd(p),x=a[h?f==="floating"?"reference":"floating":f],y=us(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(x)))==null||n?x:x.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:l,rootBoundary:u,strategy:c})),w=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)),I=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=us(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:w,offsetParent:k,strategy:c}):w);return{top:(y.top-S.top+m.top)/I.y,bottom:(S.bottom-y.bottom+m.bottom)/I.y,left:(y.left-S.left+m.left)/I.x,right:(S.right-y.right+m.right)/I.x}}const zy=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:c}=t,{element:l,padding:u=0}=mn(e,t)||{};if(l==null)return{};const f=kd(u),h={x:n,y:r},p=oa(o),m=ra(p),g=await i.getDimensions(l),x=p==="y",y=x?"top":"left",w=x?"bottom":"right",k=x?"clientHeight":"clientWidth",I=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(l));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=I/2-S/2,j=T/2-g[m]/2-1,_=On(f[y],j),L=On(f[w],j),F=_,B=T-g[m]-L,O=T/2-g[m]/2+A,G=ta(F,O,B),Y=!c.arrow&&Sr(o)!=null&&O!==G&&s.reference[m]/2-(O<F?_:L)-g[m]/2<0,re=Y?O<F?O-F:O-B:0;return{[p]:h[p]+re,data:{[p]:G,centerOffset:O-G-re,...Y&&{alignmentOffset:re}},reset:Y}}}),By=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:c,elements:l}=t,{mainAxis:u=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:g=!0,...x}=mn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const y=gn(o),w=rn(a),k=gn(a)===a,I=await(c.isRTL==null?void 0:c.isRTL(l.floating)),S=h||(k||!g?[cs(a)]:Ry(a)),C=m!=="none";!h&&C&&S.push(...Ly(a,g,m,I));const T=[a,...S],A=await lo(t,x),j=[];let _=((r=s.flip)==null?void 0:r.overflows)||[];if(u&&j.push(A[y]),f){const O=Py(o,i,I);j.push(A[O[0]],A[O[1]])}if(_=[..._,{placement:o,overflows:j}],!j.every(O=>O<=0)){var L,F;const O=(((L=s.flip)==null?void 0:L.index)||0)+1,G=T[O];if(G&&(!(f==="alignment"?w!==rn(G):!1)||_.every(H=>rn(H.placement)===w?H.overflows[0]>0:!0)))return{data:{index:O,overflows:_},reset:{placement:G}};let Y=(F=_.filter(re=>re.overflows[0]<=0).sort((re,H)=>re.overflows[1]-H.overflows[1])[0])==null?void 0:F.placement;if(!Y)switch(p){case"bestFit":{var B;const re=(B=_.filter(H=>{if(C){const W=rn(H.placement);return W===w||W==="y"}return!0}).map(H=>[H.placement,H.overflows.filter(W=>W>0).reduce((W,ne)=>W+ne,0)]).sort((H,W)=>H[1]-W[1])[0])==null?void 0:B[0];re&&(Y=re);break}case"initialPlacement":Y=a;break}if(o!==Y)return{reset:{placement:Y}}}return{}}}};function Id(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function Ad(e){return Ay.some(t=>e[t]>=0)}const Uy=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=mn(e,t);switch(r){case"referenceHidden":{const s=await lo(t,{...o,elementContext:"reference"}),i=Id(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:Ad(i)}}}case"escaped":{const s=await lo(t,{...o,altBoundary:!0}),i=Id(s,n.floating);return{data:{escapedOffsets:i,escaped:Ad(i)}}}default:return{}}}}},Nd=new Set(["left","top"]);async function Hy(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=gn(n),a=Sr(n),c=rn(n)==="y",l=Nd.has(i)?-1:1,u=s&&c?-1:1,f=mn(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),c?{x:p*u,y:h*l}:{x:h*l,y:p*u}}const Wy=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,c=await Hy(t,e);return i===((n=a.offset)==null?void 0:n.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:o+c.x,y:s+c.y,data:{...c,placement:i}}}}},Vy=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:x=>{let{x:y,y:w}=x;return{x:y,y:w}}},...c}=mn(e,t),l={x:n,y:r},u=await lo(t,c),f=rn(gn(o)),h=na(f);let p=l[h],m=l[f];if(s){const x=h==="y"?"top":"left",y=h==="y"?"bottom":"right",w=p+u[x],k=p-u[y];p=ta(w,p,k)}if(i){const x=f==="y"?"top":"left",y=f==="y"?"bottom":"right",w=m+u[x],k=m-u[y];m=ta(w,m,k)}const g=a.fn({...t,[h]:p,[f]:m});return{...g,data:{x:g.x-n,y:g.y-r,enabled:{[h]:s,[f]:i}}}}}},Ky=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:c=!0,crossAxis:l=!0}=mn(e,t),u={x:n,y:r},f=rn(o),h=na(f);let p=u[h],m=u[f];const g=mn(a,t),x=typeof g=="number"?{mainAxis:g,crossAxis:0}:{mainAxis:0,crossAxis:0,...g};if(c){const k=h==="y"?"height":"width",I=s.reference[h]-s.floating[k]+x.mainAxis,S=s.reference[h]+s.reference[k]-x.mainAxis;p<I?p=I:p>S&&(p=S)}if(l){var y,w;const k=h==="y"?"width":"height",I=Nd.has(gn(o)),S=s.reference[f]-s.floating[k]+(I&&((y=i.offset)==null?void 0:y[f])||0)+(I?0:x.crossAxis),C=s.reference[f]+s.reference[k]+(I?0:((w=i.offset)==null?void 0:w[f])||0)-(I?x.crossAxis:0);m<S?m=S:m>C&&(m=C)}return{[h]:p,[f]:m}}}},qy=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:c=()=>{},...l}=mn(e,t),u=await lo(t,l),f=gn(o),h=Sr(o),p=rn(o)==="y",{width:m,height:g}=s.floating;let x,y;f==="top"||f==="bottom"?(x=f,y=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(y=f,x=h==="end"?"top":"bottom");const w=g-u.top-u.bottom,k=m-u.left-u.right,I=On(g-u[x],w),S=On(m-u[y],k),C=!t.middlewareData.shift;let T=I,A=S;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(A=k),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(T=w),C&&!h){const _=Ot(u.left,0),L=Ot(u.right,0),F=Ot(u.top,0),B=Ot(u.bottom,0);p?A=m-2*(_!==0||L!==0?_+L:Ot(u.left,u.right)):T=g-2*(F!==0||B!==0?F+B:Ot(u.top,u.bottom))}await c({...t,availableWidth:A,availableHeight:T});const j=await i.getDimensions(a.floating);return m!==j.width||g!==j.height?{reset:{rects:!0}}:{}}}};function ds(){return typeof window<"u"}function Cr(e){return jd(e)?(e.nodeName||"").toLowerCase():"#document"}function Mt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function on(e){var t;return(t=(jd(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function jd(e){return ds()?e instanceof Node||e instanceof Mt(e).Node:!1}function Kt(e){return ds()?e instanceof Element||e instanceof Mt(e).Element:!1}function sn(e){return ds()?e instanceof HTMLElement||e instanceof Mt(e).HTMLElement:!1}function _d(e){return!ds()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Mt(e).ShadowRoot}const Gy=new Set(["inline","contents"]);function co(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=qt(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!Gy.has(o)}const Yy=new Set(["table","td","th"]);function Xy(e){return Yy.has(Cr(e))}const Jy=[":popover-open",":modal"];function fs(e){return Jy.some(t=>{try{return e.matches(t)}catch{return!1}})}const Zy=["transform","translate","scale","rotate","perspective"],Qy=["transform","translate","scale","rotate","perspective","filter"],ew=["paint","layout","strict","content"];function ia(e){const t=aa(),n=Kt(e)?qt(e):e;return Zy.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)||Qy.some(r=>(n.willChange||"").includes(r))||ew.some(r=>(n.contain||"").includes(r))}function tw(e){let t=Mn(e);for(;sn(t)&&!Tr(t);){if(ia(t))return t;if(fs(t))return null;t=Mn(t)}return null}function aa(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const nw=new Set(["html","body","#document"]);function Tr(e){return nw.has(Cr(e))}function qt(e){return Mt(e).getComputedStyle(e)}function hs(e){return Kt(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Mn(e){if(Cr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||_d(e)&&e.host||on(e);return _d(t)?t.host:t}function Pd(e){const t=Mn(e);return Tr(t)?e.ownerDocument?e.ownerDocument.body:e.body:sn(t)&&co(t)?t:Pd(t)}function uo(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=Pd(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Mt(o);if(s){const a=la(i);return t.concat(i,i.visualViewport||[],co(o)?o:[],a&&n?uo(a):[])}return t.concat(o,uo(o,[],n))}function la(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Rd(e){const t=qt(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=sn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=as(n)!==s||as(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function ca(e){return Kt(e)?e:e.contextElement}function kr(e){const t=ca(e);if(!sn(t))return nn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Rd(t);let i=(s?as(n.width):n.width)/r,a=(s?as(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const rw=nn(0);function Od(e){const t=Mt(e);return!aa()||!t.visualViewport?rw:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function ow(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Mt(e)?!1:t}function Jn(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=ca(e);let i=nn(1);t&&(r?Kt(r)&&(i=kr(r)):i=kr(e));const a=ow(s,n,r)?Od(s):nn(0);let c=(o.left+a.x)/i.x,l=(o.top+a.y)/i.y,u=o.width/i.x,f=o.height/i.y;if(s){const h=Mt(s),p=r&&Kt(r)?Mt(r):r;let m=h,g=la(m);for(;g&&r&&p!==m;){const x=kr(g),y=g.getBoundingClientRect(),w=qt(g),k=y.left+(g.clientLeft+parseFloat(w.paddingLeft))*x.x,I=y.top+(g.clientTop+parseFloat(w.paddingTop))*x.y;c*=x.x,l*=x.y,u*=x.x,f*=x.y,c+=k,l+=I,m=Mt(g),g=la(m)}}return us({width:u,height:f,x:c,y:l})}function ps(e,t){const n=hs(e).scrollLeft;return t?t.left+n:Jn(on(e)).left+n}function Md(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-ps(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function sw(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=on(r),a=t?fs(t.floating):!1;if(r===i||a&&s)return n;let c={scrollLeft:0,scrollTop:0},l=nn(1);const u=nn(0),f=sn(r);if((f||!f&&!s)&&((Cr(r)!=="body"||co(i))&&(c=hs(r)),sn(r))){const p=Jn(r);l=kr(r),u.x=p.x+r.clientLeft,u.y=p.y+r.clientTop}const h=i&&!f&&!s?Md(i,c):nn(0);return{width:n.width*l.x,height:n.height*l.y,x:n.x*l.x-c.scrollLeft*l.x+u.x+h.x,y:n.y*l.y-c.scrollTop*l.y+u.y+h.y}}function iw(e){return Array.from(e.getClientRects())}function aw(e){const t=on(e),n=hs(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+ps(e);const a=-n.scrollTop;return qt(r).direction==="rtl"&&(i+=Ot(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const Dd=25;function lw(e,t){const n=Mt(e),r=on(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,c=0;if(o){s=o.width,i=o.height;const u=aa();(!u||u&&t==="fixed")&&(a=o.offsetLeft,c=o.offsetTop)}const l=ps(r);if(l<=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<=Dd&&(s-=m)}else l<=Dd&&(s+=l);return{width:s,height:i,x:a,y:c}}const cw=new Set(["absolute","fixed"]);function uw(e,t){const n=Jn(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=sn(e)?kr(e):nn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,c=o*s.x,l=r*s.y;return{width:i,height:a,x:c,y:l}}function Ld(e,t,n){let r;if(t==="viewport")r=lw(e,n);else if(t==="document")r=aw(on(e));else if(Kt(t))r=uw(t,n);else{const o=Od(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return us(r)}function $d(e,t){const n=Mn(e);return n===t||!Kt(n)||Tr(n)?!1:qt(n).position==="fixed"||$d(n,t)}function dw(e,t){const n=t.get(e);if(n)return n;let r=uo(e,[],!1).filter(a=>Kt(a)&&Cr(a)!=="body"),o=null;const s=qt(e).position==="fixed";let i=s?Mn(e):e;for(;Kt(i)&&!Tr(i);){const a=qt(i),c=ia(i);!c&&a.position==="fixed"&&(o=null),(s?!c&&!o:!c&&a.position==="static"&&!!o&&cw.has(o.position)||co(i)&&!c&&$d(e,i))?r=r.filter(u=>u!==i):o=a,i=Mn(i)}return t.set(e,r),r}function fw(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?fs(t)?[]:dw(t,this._c):[].concat(n),r],a=i[0],c=i.reduce((l,u)=>{const f=Ld(t,u,o);return l.top=Ot(f.top,l.top),l.right=On(f.right,l.right),l.bottom=On(f.bottom,l.bottom),l.left=Ot(f.left,l.left),l},Ld(t,a,o));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}}function hw(e){const{width:t,height:n}=Rd(e);return{width:t,height:n}}function pw(e,t,n){const r=sn(t),o=on(t),s=n==="fixed",i=Jn(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const c=nn(0);function l(){c.x=ps(o)}if(r||!r&&!s)if((Cr(t)!=="body"||co(o))&&(a=hs(t)),r){const p=Jn(t,!0,s,t);c.x=p.x+t.clientLeft,c.y=p.y+t.clientTop}else o&&l();s&&!r&&o&&l();const u=o&&!r&&!s?Md(o,a):nn(0),f=i.left+a.scrollLeft-c.x-u.x,h=i.top+a.scrollTop-c.y-u.y;return{x:f,y:h,width:i.width,height:i.height}}function ua(e){return qt(e).position==="static"}function Fd(e,t){if(!sn(e)||qt(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return on(e)===n&&(n=n.ownerDocument.body),n}function zd(e,t){const n=Mt(e);if(fs(e))return n;if(!sn(e)){let o=Mn(e);for(;o&&!Tr(o);){if(Kt(o)&&!ua(o))return o;o=Mn(o)}return n}let r=Fd(e,t);for(;r&&Xy(r)&&ua(r);)r=Fd(r,t);return r&&Tr(r)&&ua(r)&&!ia(r)?n:r||tw(e)||n}const mw=async function(e){const t=this.getOffsetParent||zd,n=this.getDimensions,r=await n(e.floating);return{reference:pw(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function gw(e){return qt(e).direction==="rtl"}const xw={convertOffsetParentRelativeRectToViewportRelativeRect:sw,getDocumentElement:on,getClippingRect:fw,getOffsetParent:zd,getElementRects:mw,getClientRects:iw,getDimensions:hw,getScale:kr,isElement:Kt,isRTL:gw};function Bd(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function bw(e,t){let n=null,r;const o=on(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,c){a===void 0&&(a=!1),c===void 0&&(c=1),s();const l=e.getBoundingClientRect(),{left:u,top:f,width:h,height:p}=l;if(a||t(),!h||!p)return;const m=ls(f),g=ls(o.clientWidth-(u+h)),x=ls(o.clientHeight-(f+p)),y=ls(u),k={rootMargin:-m+"px "+-g+"px "+-x+"px "+-y+"px",threshold:Ot(0,On(1,c))||1};let I=!0;function S(C){const T=C[0].intersectionRatio;if(T!==c){if(!I)return i();T?i(!1,T):r=setTimeout(()=>{i(!1,1e-7)},1e3)}T===1&&!Bd(l,e.getBoundingClientRect())&&i(),I=!1}try{n=new IntersectionObserver(S,{...k,root:o.ownerDocument})}catch{n=new IntersectionObserver(S,k)}n.observe(e)}return i(!0),s}function yw(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:c=!1}=r,l=ca(e),u=o||s?[...l?uo(l):[],...uo(t)]:[];u.forEach(y=>{o&&y.addEventListener("scroll",n,{passive:!0}),s&&y.addEventListener("resize",n)});const f=l&&a?bw(l,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(y=>{let[w]=y;w&&w.target===l&&p&&(p.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var k;(k=p)==null||k.observe(t)})),n()}),l&&!c&&p.observe(l),p.observe(t));let m,g=c?Jn(e):null;c&&x();function x(){const y=Jn(e);g&&!Bd(g,y)&&n(),g=y,m=requestAnimationFrame(x)}return n(),()=>{var y;u.forEach(w=>{o&&w.removeEventListener("scroll",n),s&&w.removeEventListener("resize",n)}),f==null||f(),(y=p)==null||y.disconnect(),p=null,c&&cancelAnimationFrame(m)}}const ww=Wy,vw=Vy,Sw=By,Cw=qy,Tw=Uy,Ud=zy,kw=Ky,Ew=(e,t,n)=>{const r=new Map,o={platform:xw,...n},s={...o.platform,_c:r};return Fy(e,t,{...o,platform:s})};var Iw=typeof document<"u",Aw=function(){},ms=Iw?v.useLayoutEffect:Aw;function gs(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(!gs(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)&&!gs(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Hd(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Wd(e,t){const n=Hd(e);return Math.round(t*n)/n}function da(e){const t=b.useRef(e);return ms(()=>{t.current=e}),t}function Nw(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:c,open:l}=e,[u,f]=b.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[h,p]=b.useState(r);gs(h,r)||p(r);const[m,g]=b.useState(null),[x,y]=b.useState(null),w=b.useCallback(H=>{H!==C.current&&(C.current=H,g(H))},[]),k=b.useCallback(H=>{H!==T.current&&(T.current=H,y(H))},[]),I=s||m,S=i||x,C=b.useRef(null),T=b.useRef(null),A=b.useRef(u),j=c!=null,_=da(c),L=da(o),F=da(l),B=b.useCallback(()=>{if(!C.current||!T.current)return;const H={placement:t,strategy:n,middleware:h};L.current&&(H.platform=L.current),Ew(C.current,T.current,H).then(W=>{const ne={...W,isPositioned:F.current!==!1};O.current&&!gs(A.current,ne)&&(A.current=ne,il.flushSync(()=>{f(ne)}))})},[h,t,n,L,F]);ms(()=>{l===!1&&A.current.isPositioned&&(A.current.isPositioned=!1,f(H=>({...H,isPositioned:!1})))},[l]);const O=b.useRef(!1);ms(()=>(O.current=!0,()=>{O.current=!1}),[]),ms(()=>{if(I&&(C.current=I),S&&(T.current=S),I&&S){if(_.current)return _.current(I,S,B);B()}},[I,S,B,_,j]);const G=b.useMemo(()=>({reference:C,floating:T,setReference:w,setFloating:k}),[w,k]),Y=b.useMemo(()=>({reference:I,floating:S}),[I,S]),re=b.useMemo(()=>{const H={position:n,left:0,top:0};if(!Y.floating)return H;const W=Wd(Y.floating,u.x),ne=Wd(Y.floating,u.y);return a?{...H,transform:"translate("+W+"px, "+ne+"px)",...Hd(Y.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:W,top:ne}},[n,a,Y.floating,u.x,u.y]);return b.useMemo(()=>({...u,update:B,refs:G,elements:Y,floatingStyles:re}),[u,B,G,Y,re])}const jw=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?Ud({element:r.current,padding:o}).fn(n):{}:r?Ud({element:r,padding:o}).fn(n):{}}}},_w=(e,t)=>({...ww(e),options:[e,t]}),Pw=(e,t)=>({...vw(e),options:[e,t]}),Rw=(e,t)=>({...kw(e),options:[e,t]}),Ow=(e,t)=>({...Sw(e),options:[e,t]}),Mw=(e,t)=>({...Cw(e),options:[e,t]}),Dw=(e,t)=>({...Tw(e),options:[e,t]}),Lw=(e,t)=>({...jw(e),options:[e,t]});var $w="Arrow",Vd=b.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return d.jsx(Ne.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"})})});Vd.displayName=$w;var Fw=Vd;function zw(e){const[t,n]=b.useState(void 0);return tn(()=>{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 c=s.borderBoxSize,l=Array.isArray(c)?c[0]:c;i=l.inlineSize,a=l.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 fa="Popper",[Kd,qd]=Pn(fa),[Bw,Gd]=Kd(fa),Yd=e=>{const{__scopePopper:t,children:n}=e,[r,o]=b.useState(null);return d.jsx(Bw,{scope:t,anchor:r,onAnchorChange:o,children:n})};Yd.displayName=fa;var Xd="PopperAnchor",Jd=b.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Gd(Xd,n),i=b.useRef(null),a=Ye(t,i),c=b.useRef(null);return b.useEffect(()=>{const l=c.current;c.current=(r==null?void 0:r.current)||i.current,l!==c.current&&s.onAnchorChange(c.current)}),r?null:d.jsx(Ne.div,{...o,ref:a})});Jd.displayName=Xd;var ha="PopperContent",[Uw,Hw]=Kd(ha),Zd=b.forwardRef((e,t)=>{var U,P,V,ee,ce,ue;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:c=!0,collisionBoundary:l=[],collisionPadding:u=0,sticky:f="partial",hideWhenDetached:h=!1,updatePositionStrategy:p="optimized",onPlaced:m,...g}=e,x=Gd(ha,n),[y,w]=b.useState(null),k=Ye(t,be=>w(be)),[I,S]=b.useState(null),C=zw(I),T=(C==null?void 0:C.width)??0,A=(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},L=Array.isArray(l)?l:[l],F=L.length>0,B={padding:_,boundary:L.filter(Vw),altBoundary:F},{refs:O,floatingStyles:G,placement:Y,isPositioned:re,middlewareData:H}=Nw({strategy:"fixed",placement:j,whileElementsMounted:(...be)=>yw(...be,{animationFrame:p==="always"}),elements:{reference:x.anchor},middleware:[_w({mainAxis:o+A,alignmentAxis:i}),c&&Pw({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?Rw():void 0,...B}),c&&Ow({...B}),Mw({...B,apply:({elements:be,rects:Ae,availableWidth:Ie,availableHeight:Xe})=>{const{width:ze,height:Ze}=Ae.reference,Be=be.floating.style;Be.setProperty("--radix-popper-available-width",`${Ie}px`),Be.setProperty("--radix-popper-available-height",`${Xe}px`),Be.setProperty("--radix-popper-anchor-width",`${ze}px`),Be.setProperty("--radix-popper-anchor-height",`${Ze}px`)}}),I&&Lw({element:I,padding:a}),Kw({arrowWidth:T,arrowHeight:A}),h&&Dw({strategy:"referenceHidden",...B})]}),[W,ne]=tf(Y),K=wt(m);tn(()=>{re&&(K==null||K())},[re,K]);const M=(U=H.arrow)==null?void 0:U.x,N=(P=H.arrow)==null?void 0:P.y,$=((V=H.arrow)==null?void 0:V.centerOffset)!==0,[D,q]=b.useState();return tn(()=>{y&&q(window.getComputedStyle(y).zIndex)},[y]),d.jsx("div",{ref:O.setFloating,"data-radix-popper-content-wrapper":"",style:{...G,transform:re?G.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:D,"--radix-popper-transform-origin":[(ee=H.transformOrigin)==null?void 0:ee.x,(ce=H.transformOrigin)==null?void 0:ce.y].join(" "),...((ue=H.hide)==null?void 0:ue.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:d.jsx(Uw,{scope:n,placedSide:W,onArrowChange:S,arrowX:M,arrowY:N,shouldHideArrow:$,children:d.jsx(Ne.div,{"data-side":W,"data-align":ne,...g,ref:k,style:{...g.style,animation:re?void 0:"none"}})})})});Zd.displayName=ha;var Qd="PopperArrow",Ww={top:"bottom",right:"left",bottom:"top",left:"right"},ef=b.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=Hw(Qd,r),i=Ww[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(Fw,{...o,ref:n,style:{...o.style,display:"block"}})})});ef.displayName=Qd;function Vw(e){return e!==null}var Kw=e=>({name:"transformOrigin",options:e,fn(t){var x,y,w;const{placement:n,rects:r,middlewareData:o}=t,i=((x=o.arrow)==null?void 0:x.centerOffset)!==0,a=i?0:e.arrowWidth,c=i?0:e.arrowHeight,[l,u]=tf(n),f={start:"0%",center:"50%",end:"100%"}[u],h=(((y=o.arrow)==null?void 0:y.x)??0)+a/2,p=(((w=o.arrow)==null?void 0:w.y)??0)+c/2;let m="",g="";return l==="bottom"?(m=i?f:`${h}px`,g=`${-c}px`):l==="top"?(m=i?f:`${h}px`,g=`${r.floating.height+c}px`):l==="right"?(m=`${-c}px`,g=i?f:`${p}px`):l==="left"&&(m=`${r.floating.width+c}px`,g=i?f:`${p}px`),{data:{x:m,y:g}}}});function tf(e){const[t,n="center"]=e.split("-");return[t,n]}var qw=Yd,Gw=Jd,Yw=Zd,Xw=ef,Jw="Portal",pa=b.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=b.useState(!1);tn(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?Hs.createPortal(d.jsx(Ne.div,{...r,ref:t}),i):null});pa.displayName=Jw;function Zw(e,t){return b.useReducer((n,r)=>t[n][r]??n,e)}var Dt=e=>{const{present:t,children:n}=e,r=Qw(t),o=typeof n=="function"?n({present:r.isPresent}):b.Children.only(n),s=Ye(r.ref,ev(o));return typeof n=="function"||r.isPresent?b.cloneElement(o,{ref:s}):null};Dt.displayName="Presence";function Qw(e){const[t,n]=b.useState(),r=b.useRef(null),o=b.useRef(e),s=b.useRef("none"),i=e?"mounted":"unmounted",[a,c]=Zw(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return b.useEffect(()=>{const l=xs(r.current);s.current=a==="mounted"?l:"none"},[a]),tn(()=>{const l=r.current,u=o.current;if(u!==e){const h=s.current,p=xs(l);e?c("MOUNT"):p==="none"||(l==null?void 0:l.display)==="none"?c("UNMOUNT"):c(u&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,c]),tn(()=>{if(t){let l;const u=t.ownerDocument.defaultView??window,f=p=>{const g=xs(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&g&&(c("ANIMATION_END"),!o.current)){const x=t.style.animationFillMode;t.style.animationFillMode="forwards",l=u.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=x)})}},h=p=>{p.target===t&&(s.current=xs(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{u.clearTimeout(l),t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else c("ANIMATION_END")},[t,c]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:b.useCallback(l=>{r.current=l?getComputedStyle(l):null,n(l)},[])}}function xs(e){return(e==null?void 0:e.animationName)||"none"}function ev(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 ma="rovingFocusGroup.onEntryFocus",tv={bubbles:!1,cancelable:!0},fo="RovingFocusGroup",[ga,nf,nv]=dd(fo),[rv,rf]=Pn(fo,[nv]),[ov,sv]=rv(fo),of=b.forwardRef((e,t)=>d.jsx(ga.Provider,{scope:e.__scopeRovingFocusGroup,children:d.jsx(ga.Slot,{scope:e.__scopeRovingFocusGroup,children:d.jsx(iv,{...e,ref:t})})}));of.displayName=fo;var iv=b.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:c,onEntryFocus:l,preventScrollOnEntryFocus:u=!1,...f}=e,h=b.useRef(null),p=Ye(t,h),m=Gi(s),[g,x]=is({prop:i,defaultProp:a??null,onChange:c,caller:fo}),[y,w]=b.useState(!1),k=wt(l),I=nf(n),S=b.useRef(!1),[C,T]=b.useState(0);return b.useEffect(()=>{const A=h.current;if(A)return A.addEventListener(ma,k),()=>A.removeEventListener(ma,k)},[k]),d.jsx(ov,{scope:n,orientation:r,dir:m,loop:o,currentTabStopId:g,onItemFocus:b.useCallback(A=>x(A),[x]),onItemShiftTab:b.useCallback(()=>w(!0),[]),onFocusableItemAdd:b.useCallback(()=>T(A=>A+1),[]),onFocusableItemRemove:b.useCallback(()=>T(A=>A-1),[]),children:d.jsx(Ne.div,{tabIndex:y||C===0?-1:0,"data-orientation":r,...f,ref:p,style:{outline:"none",...e.style},onMouseDown:ve(e.onMouseDown,()=>{S.current=!0}),onFocus:ve(e.onFocus,A=>{const j=!S.current;if(A.target===A.currentTarget&&j&&!y){const _=new CustomEvent(ma,tv);if(A.currentTarget.dispatchEvent(_),!_.defaultPrevented){const L=I().filter(Y=>Y.focusable),F=L.find(Y=>Y.active),B=L.find(Y=>Y.id===g),G=[F,B,...L].filter(Boolean).map(Y=>Y.ref.current);lf(G,u)}}S.current=!1}),onBlur:ve(e.onBlur,()=>w(!1))})})}),sf="RovingFocusGroupItem",af=b.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,c=Rt(),l=s||c,u=sv(sf,n),f=u.currentTabStopId===l,h=nf(n),{onFocusableItemAdd:p,onFocusableItemRemove:m,currentTabStopId:g}=u;return b.useEffect(()=>{if(r)return p(),()=>m()},[r,p,m]),d.jsx(ga.ItemSlot,{scope:n,id:l,focusable:r,active:o,children:d.jsx(Ne.span,{tabIndex:f?0:-1,"data-orientation":u.orientation,...a,ref:t,onMouseDown:ve(e.onMouseDown,x=>{r?u.onItemFocus(l):x.preventDefault()}),onFocus:ve(e.onFocus,()=>u.onItemFocus(l)),onKeyDown:ve(e.onKeyDown,x=>{if(x.key==="Tab"&&x.shiftKey){u.onItemShiftTab();return}if(x.target!==x.currentTarget)return;const y=cv(x,u.orientation,u.dir);if(y!==void 0){if(x.metaKey||x.ctrlKey||x.altKey||x.shiftKey)return;x.preventDefault();let k=h().filter(I=>I.focusable).map(I=>I.ref.current);if(y==="last")k.reverse();else if(y==="prev"||y==="next"){y==="prev"&&k.reverse();const I=k.indexOf(x.currentTarget);k=u.loop?uv(k,I+1):k.slice(I+1)}setTimeout(()=>lf(k))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:g!=null}):i})})});af.displayName=sf;var av={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function lv(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function cv(e,t,n){const r=lv(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return av[r]}function lf(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function uv(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var dv=of,fv=af,hv=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Er=new WeakMap,bs=new WeakMap,ys={},xa=0,cf=function(e){return e&&(e.host||cf(e.parentNode))},pv=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=cf(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})},mv=function(e,t,n,r){var o=pv(t,Array.isArray(e)?e:[e]);ys[n]||(ys[n]=new WeakMap);var s=ys[n],i=[],a=new Set,c=new Set(o),l=function(f){!f||a.has(f)||(a.add(f),l(f.parentNode))};o.forEach(l);var u=function(f){!f||c.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",g=(Er.get(h)||0)+1,x=(s.get(h)||0)+1;Er.set(h,g),s.set(h,x),i.push(h),g===1&&m&&bs.set(h,!0),x===1&&h.setAttribute(n,"true"),m||h.setAttribute(r,"true")}catch(y){console.error("aria-hidden: cannot operate on ",h,y)}})};return u(t),a.clear(),xa++,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||(bs.has(f)||f.removeAttribute(r),bs.delete(f)),p||f.removeAttribute(n)}),xa--,xa||(Er=new WeakMap,Er=new WeakMap,bs=new WeakMap,ys={})}},uf=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=hv(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),mv(r,o,n,"aria-hidden")):function(){return null}},an=function(){return an=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},an.apply(this,arguments)};function df(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 gv(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 ws="right-scroll-bar-position",vs="width-before-scroll-bar",xv="with-scroll-bars-hidden",bv="--removed-body-scroll-bar-size";function ba(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function yv(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 wv=typeof window<"u"?b.useLayoutEffect:b.useEffect,ff=new WeakMap;function vv(e,t){var n=yv(null,function(r){return e.forEach(function(o){return ba(o,r)})});return wv(function(){var r=ff.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||ba(a,null)}),s.forEach(function(a){o.has(a)||ba(a,i)})}ff.set(n,e)},[e]),n}function Sv(e){return e}function Cv(e,t){t===void 0&&(t=Sv);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 c=function(){var u=i;i=[],u.forEach(s)},l=function(){return Promise.resolve().then(c)};l(),n={push:function(u){i.push(u),l()},filter:function(u){return i=i.filter(u),n}}}};return o}function Tv(e){e===void 0&&(e={});var t=Cv(null);return t.options=an({async:!0,ssr:!1},e),t}var hf=function(e){var t=e.sideCar,n=df(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 b.createElement(r,an({},n))};hf.isSideCarExport=!0;function kv(e,t){return e.useMedium(t),hf}var pf=Tv(),ya=function(){},Ss=b.forwardRef(function(e,t){var n=b.useRef(null),r=b.useState({onScrollCapture:ya,onWheelCapture:ya,onTouchMoveCapture:ya}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,c=e.className,l=e.removeScrollBar,u=e.enabled,f=e.shards,h=e.sideCar,p=e.noRelative,m=e.noIsolation,g=e.inert,x=e.allowPinchZoom,y=e.as,w=y===void 0?"div":y,k=e.gapMode,I=df(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),S=h,C=vv([n,t]),T=an(an({},I),o);return b.createElement(b.Fragment,null,u&&b.createElement(S,{sideCar:pf,removeScrollBar:l,shards:f,noRelative:p,noIsolation:m,inert:g,setCallbacks:s,allowPinchZoom:!!x,lockRef:n,gapMode:k}),i?b.cloneElement(b.Children.only(a),an(an({},T),{ref:C})):b.createElement(w,an({},T,{className:c,ref:C}),a))});Ss.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Ss.classNames={fullWidth:vs,zeroRight:ws};var Ev=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Iv(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Ev();return t&&e.setAttribute("nonce",t),e}function Av(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function Nv(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var jv=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Iv())&&(Av(t,n),Nv(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},_v=function(){var e=jv();return function(t,n){b.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},mf=function(){var e=_v(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Pv={left:0,top:0,right:0,gap:0},wa=function(e){return parseInt(e||"",10)||0},Rv=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[wa(n),wa(r),wa(o)]},Ov=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Pv;var t=Rv(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])}},Mv=mf(),Ir="data-scroll-locked",Dv=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(xv,` {
89
89
  overflow: hidden `).concat(r,`;
90
90
  padding-right: `).concat(a,"px ").concat(r,`;
@@ -121,12 +121,12 @@ Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An err
121
121
  body[`).concat(Ir,`] {
122
122
  `).concat(bv,": ").concat(a,`px;
123
123
  }
124
- `)},gf=function(){var e=parseInt(document.body.getAttribute(Ir)||"0",10);return isFinite(e)?e:0},Lv=function(){b.useEffect(function(){return document.body.setAttribute(Ir,(gf()+1).toString()),function(){var e=gf()-1;e<=0?document.body.removeAttribute(Ir):document.body.setAttribute(Ir,e.toString())}},[])},$v=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;Lv();var s=b.useMemo(function(){return Mv(o)},[o]);return b.createElement(Ov,{styles:Dv(s,!t,o,n?"":"!important")})},va=!1;if(typeof window<"u")try{var Cs=Object.defineProperty({},"passive",{get:function(){return va=!0,!0}});window.addEventListener("test",Cs,Cs),window.removeEventListener("test",Cs,Cs)}catch{va=!1}var Ar=va?{passive:!1}:!1,Fv=function(e){return e.tagName==="TEXTAREA"},xf=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!Fv(e)&&n[t]==="visible")},zv=function(e){return xf(e,"overflowY")},Bv=function(e){return xf(e,"overflowX")},bf=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=yf(e,r);if(o){var s=wf(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Uv=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},Hv=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},yf=function(e,t){return e==="v"?zv(t):Bv(t)},wf=function(e,t){return e==="v"?Uv(t):Hv(t)},Wv=function(e,t){return e==="h"&&t==="rtl"?-1:1},Vv=function(e,t,n,r,o){var s=Wv(e,window.getComputedStyle(t).direction),i=s*r,a=n.target,c=t.contains(a),l=!1,u=i>0,f=0,h=0;do{if(!a)break;var p=wf(e,a),m=p[0],g=p[1],x=p[2],y=g-x-s*m;(m||y)&&yf(e,a)&&(f+=y,h+=m);var w=a.parentNode;a=w&&w.nodeType===Node.DOCUMENT_FRAGMENT_NODE?w.host:w}while(!c&&a!==document.body||c&&(t.contains(a)||t===a));return(u&&Math.abs(f)<1||!u&&Math.abs(h)<1)&&(l=!0),l},Ts=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},vf=function(e){return[e.deltaX,e.deltaY]},Sf=function(e){return e&&"current"in e?e.current:e},Kv=function(e,t){return e[0]===t[0]&&e[1]===t[1]},qv=function(e){return`
124
+ `)},gf=function(){var e=parseInt(document.body.getAttribute(Ir)||"0",10);return isFinite(e)?e:0},Lv=function(){b.useEffect(function(){return document.body.setAttribute(Ir,(gf()+1).toString()),function(){var e=gf()-1;e<=0?document.body.removeAttribute(Ir):document.body.setAttribute(Ir,e.toString())}},[])},$v=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;Lv();var s=b.useMemo(function(){return Ov(o)},[o]);return b.createElement(Mv,{styles:Dv(s,!t,o,n?"":"!important")})},va=!1;if(typeof window<"u")try{var Cs=Object.defineProperty({},"passive",{get:function(){return va=!0,!0}});window.addEventListener("test",Cs,Cs),window.removeEventListener("test",Cs,Cs)}catch{va=!1}var Ar=va?{passive:!1}:!1,Fv=function(e){return e.tagName==="TEXTAREA"},xf=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!Fv(e)&&n[t]==="visible")},zv=function(e){return xf(e,"overflowY")},Bv=function(e){return xf(e,"overflowX")},bf=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=yf(e,r);if(o){var s=wf(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Uv=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},Hv=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},yf=function(e,t){return e==="v"?zv(t):Bv(t)},wf=function(e,t){return e==="v"?Uv(t):Hv(t)},Wv=function(e,t){return e==="h"&&t==="rtl"?-1:1},Vv=function(e,t,n,r,o){var s=Wv(e,window.getComputedStyle(t).direction),i=s*r,a=n.target,c=t.contains(a),l=!1,u=i>0,f=0,h=0;do{if(!a)break;var p=wf(e,a),m=p[0],g=p[1],x=p[2],y=g-x-s*m;(m||y)&&yf(e,a)&&(f+=y,h+=m);var w=a.parentNode;a=w&&w.nodeType===Node.DOCUMENT_FRAGMENT_NODE?w.host:w}while(!c&&a!==document.body||c&&(t.contains(a)||t===a));return(u&&Math.abs(f)<1||!u&&Math.abs(h)<1)&&(l=!0),l},Ts=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},vf=function(e){return[e.deltaX,e.deltaY]},Sf=function(e){return e&&"current"in e?e.current:e},Kv=function(e,t){return e[0]===t[0]&&e[1]===t[1]},qv=function(e){return`
125
125
  .block-interactivity-`.concat(e,` {pointer-events: none;}
126
126
  .allow-interactivity-`).concat(e,` {pointer-events: all;}
127
- `)},Gv=0,Nr=[];function Yv(e){var t=b.useRef([]),n=b.useRef([0,0]),r=b.useRef(),o=b.useState(Gv++)[0],s=b.useState(mf)[0],i=b.useRef(e);b.useEffect(function(){i.current=e},[e]),b.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var g=gv([e.lockRef.current],(e.shards||[]).map(Sf),!0).filter(Boolean);return g.forEach(function(x){return x.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),g.forEach(function(x){return x.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=b.useCallback(function(g,x){if("touches"in g&&g.touches.length===2||g.type==="wheel"&&g.ctrlKey)return!i.current.allowPinchZoom;var y=Ts(g),w=n.current,k="deltaX"in g?g.deltaX:w[0]-y[0],I="deltaY"in g?g.deltaY:w[1]-y[1],S,C=g.target,T=Math.abs(k)>Math.abs(I)?"h":"v";if("touches"in g&&T==="h"&&C.type==="range")return!1;var A=bf(T,C);if(!A)return!0;if(A?S=T:(S=T==="v"?"h":"v",A=bf(T,C)),!A)return!1;if(!r.current&&"changedTouches"in g&&(k||I)&&(r.current=S),!S)return!0;var j=r.current||S;return Vv(j,x,g,j==="h"?k:I)},[]),c=b.useCallback(function(g){var x=g;if(!(!Nr.length||Nr[Nr.length-1]!==s)){var y="deltaY"in x?vf(x):Ts(x),w=t.current.filter(function(S){return S.name===x.type&&(S.target===x.target||x.target===S.shadowParent)&&Kv(S.delta,y)})[0];if(w&&w.should){x.cancelable&&x.preventDefault();return}if(!w){var k=(i.current.shards||[]).map(Sf).filter(Boolean).filter(function(S){return S.contains(x.target)}),I=k.length>0?a(x,k[0]):!i.current.noIsolation;I&&x.cancelable&&x.preventDefault()}}},[]),l=b.useCallback(function(g,x,y,w){var k={name:g,delta:x,target:y,should:w,shadowParent:Xv(y)};t.current.push(k),setTimeout(function(){t.current=t.current.filter(function(I){return I!==k})},1)},[]),u=b.useCallback(function(g){n.current=Ts(g),r.current=void 0},[]),f=b.useCallback(function(g){l(g.type,vf(g),g.target,a(g,e.lockRef.current))},[]),h=b.useCallback(function(g){l(g.type,Ts(g),g.target,a(g,e.lockRef.current))},[]);b.useEffect(function(){return Nr.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:h}),document.addEventListener("wheel",c,Ar),document.addEventListener("touchmove",c,Ar),document.addEventListener("touchstart",u,Ar),function(){Nr=Nr.filter(function(g){return g!==s}),document.removeEventListener("wheel",c,Ar),document.removeEventListener("touchmove",c,Ar),document.removeEventListener("touchstart",u,Ar)}},[]);var p=e.removeScrollBar,m=e.inert;return b.createElement(b.Fragment,null,m?b.createElement(s,{styles:qv(o)}):null,p?b.createElement($v,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Xv(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Jv=kv(pf,Yv);var Sa=b.forwardRef(function(e,t){return b.createElement(Ss,an({},e,{ref:t,sideCar:Jv}))});Sa.classNames=Ss.classNames;var Ca=["Enter"," "],Zv=["ArrowDown","PageUp","Home"],Cf=["ArrowUp","PageDown","End"],Qv=[...Zv,...Cf],e0={ltr:[...Ca,"ArrowRight"],rtl:[...Ca,"ArrowLeft"]},t0={ltr:["ArrowLeft"],rtl:["ArrowRight"]},ho="Menu",[po,n0,r0]=dd(ho),[Zn,Tf]=Pn(ho,[r0,qd,rf]),ks=qd(),kf=rf(),[o0,Qn]=Zn(ho),[s0,mo]=Zn(ho),Ef=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=ks(t),[c,l]=b.useState(null),u=b.useRef(!1),f=yt(s),h=Gi(o);return b.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(qw,{...a,children:d.jsx(o0,{scope:t,open:n,onOpenChange:f,content:c,onContentChange:l,children:d.jsx(s0,{scope:t,onClose:b.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:u,dir:h,modal:i,children:r})})})};Ef.displayName=ho;var i0="MenuAnchor",Ta=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ks(n);return d.jsx(Gw,{...o,...r,ref:t})});Ta.displayName=i0;var ka="MenuPortal",[a0,If]=Zn(ka,{forceMount:void 0}),Af=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Qn(ka,t);return d.jsx(a0,{scope:t,forceMount:n,children:d.jsx(Dt,{present:n||s.open,children:d.jsx(pa,{asChild:!0,container:o,children:r})})})};Af.displayName=ka;var Bt="MenuContent",[l0,Ea]=Zn(Bt),Nf=b.forwardRef((e,t)=>{const n=If(Bt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Qn(Bt,e.__scopeMenu),i=mo(Bt,e.__scopeMenu);return d.jsx(po.Provider,{scope:e.__scopeMenu,children:d.jsx(Dt,{present:r||s.open,children:d.jsx(po.Slot,{scope:e.__scopeMenu,children:i.modal?d.jsx(c0,{...o,ref:t}):d.jsx(u0,{...o,ref:t})})})})}),c0=b.forwardRef((e,t)=>{const n=Qn(Bt,e.__scopeMenu),r=b.useRef(null),o=Je(t,r);return b.useEffect(()=>{const s=r.current;if(s)return uf(s)},[]),d.jsx(Ia,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ve(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),u0=b.forwardRef((e,t)=>{const n=Qn(Bt,e.__scopeMenu);return d.jsx(Ia,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),d0=cr.createSlot("MenuContent.ScrollLock"),Ia=b.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:c,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:f,onInteractOutside:h,onDismiss:p,disableOutsideScroll:m,...g}=e,x=Qn(Bt,n),y=mo(Bt,n),w=ks(n),k=kf(n),I=n0(n),[S,C]=b.useState(null),T=b.useRef(null),A=Je(t,T,x.onContentChange),j=b.useRef(0),P=b.useRef(""),M=b.useRef(0),F=b.useRef(null),U=b.useRef("right"),L=b.useRef(0),K=m?Sa:b.Fragment,q=m?{as:d0,allowPinchZoom:!0}:void 0,re=V=>{var ee,_;const ne=P.current+V,H=I().filter(B=>!B.disabled),O=document.activeElement,N=(ee=H.find(B=>B.ref.current===O))==null?void 0:ee.textValue,$=H.map(B=>B.textValue),D=C0($,ne,N),G=(_=H.find(B=>B.textValue===D))==null?void 0:_.ref.current;(function B(X){P.current=X,window.clearTimeout(j.current),X!==""&&(j.current=window.setTimeout(()=>B(""),1e3))})(ne),G&&setTimeout(()=>G.focus())};b.useEffect(()=>()=>window.clearTimeout(j.current),[]),gd();const W=b.useCallback(V=>{var H,O;return U.current===((H=F.current)==null?void 0:H.side)&&k0(V,(O=F.current)==null?void 0:O.area)},[]);return d.jsx(l0,{scope:n,searchRef:P,onItemEnter:b.useCallback(V=>{W(V)&&V.preventDefault()},[W]),onItemLeave:b.useCallback(V=>{var ne;W(V)||((ne=T.current)==null||ne.focus(),C(null))},[W]),onTriggerLeave:b.useCallback(V=>{W(V)&&V.preventDefault()},[W]),pointerGraceTimerRef:M,onPointerGraceIntentChange:b.useCallback(V=>{F.current=V},[]),children:d.jsx(K,{...q,children:d.jsx(ea,{asChild:!0,trapped:o,onMountAutoFocus:ve(s,V=>{var ne;V.preventDefault(),(ne=T.current)==null||ne.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:d.jsx(Xi,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:d.jsx(dv,{asChild:!0,...k,dir:y.dir,orientation:"vertical",loop:r,currentTabStopId:S,onCurrentTabStopIdChange:C,onEntryFocus:ve(c,V=>{y.isUsingKeyboardRef.current||V.preventDefault()}),preventScrollOnEntryFocus:!0,children:d.jsx(Yw,{role:"menu","aria-orientation":"vertical","data-state":Kf(x.open),"data-radix-menu-content":"",dir:y.dir,...w,...g,ref:A,style:{outline:"none",...g.style},onKeyDown:ve(g.onKeyDown,V=>{const H=V.target.closest("[data-radix-menu-content]")===V.currentTarget,O=V.ctrlKey||V.altKey||V.metaKey,N=V.key.length===1;H&&(V.key==="Tab"&&V.preventDefault(),!O&&N&&re(V.key));const $=T.current;if(V.target!==$||!Qv.includes(V.key))return;V.preventDefault();const G=I().filter(ee=>!ee.disabled).map(ee=>ee.ref.current);Cf.includes(V.key)&&G.reverse(),v0(G)}),onBlur:ve(e.onBlur,V=>{V.currentTarget.contains(V.target)||(window.clearTimeout(j.current),P.current="")}),onPointerMove:ve(e.onPointerMove,xo(V=>{const ne=V.target,H=L.current!==V.clientX;if(V.currentTarget.contains(ne)&&H){const O=V.clientX>L.current?"right":"left";U.current=O,L.current=V.clientX}}))})})})})})})});Nf.displayName=Bt;var f0="MenuGroup",Aa=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return d.jsx(Ne.div,{role:"group",...r,ref:t})});Aa.displayName=f0;var h0="MenuLabel",_f=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return d.jsx(Ne.div,{...r,ref:t})});_f.displayName=h0;var Es="MenuItem",jf="menu.itemSelect",Is=b.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=b.useRef(null),i=mo(Es,e.__scopeMenu),a=Ea(Es,e.__scopeMenu),c=Je(t,s),l=b.useRef(!1),u=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(jf,{bubbles:!0,cancelable:!0});f.addEventListener(jf,p=>r==null?void 0:r(p),{once:!0}),ud(f,h),h.defaultPrevented?l.current=!1:i.onClose()}};return d.jsx(Pf,{...o,ref:c,disabled:n,onClick:ve(e.onClick,u),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),l.current=!0},onPointerUp:ve(e.onPointerUp,f=>{var h;l.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:ve(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||Ca.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});Is.displayName=Es;var Pf=b.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=Ea(Es,n),a=kf(n),c=b.useRef(null),l=Je(t,c),[u,f]=b.useState(!1),[h,p]=b.useState("");return b.useEffect(()=>{const m=c.current;m&&p((m.textContent??"").trim())},[s.children]),d.jsx(po.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:d.jsx(fv,{asChild:!0,...a,focusable:!r,children:d.jsx(Ne.div,{role:"menuitem","data-highlighted":u?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:l,onPointerMove:ve(e.onPointerMove,xo(m=>{r?i.onItemLeave(m):(i.onItemEnter(m),m.defaultPrevented||m.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ve(e.onPointerLeave,xo(m=>i.onItemLeave(m))),onFocus:ve(e.onFocus,()=>f(!0)),onBlur:ve(e.onBlur,()=>f(!1))})})})}),p0="MenuCheckboxItem",Rf=b.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return d.jsx($f,{scope:e.__scopeMenu,checked:n,children:d.jsx(Is,{role:"menuitemcheckbox","aria-checked":As(n)?"mixed":n,...o,ref:t,"data-state":_a(n),onSelect:ve(o.onSelect,()=>r==null?void 0:r(As(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Rf.displayName=p0;var Mf="MenuRadioGroup",[m0,g0]=Zn(Mf,{value:void 0,onValueChange:()=>{}}),Of=b.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=yt(r);return d.jsx(m0,{scope:e.__scopeMenu,value:n,onValueChange:s,children:d.jsx(Aa,{...o,ref:t})})});Of.displayName=Mf;var Df="MenuRadioItem",Lf=b.forwardRef((e,t)=>{const{value:n,...r}=e,o=g0(Df,e.__scopeMenu),s=n===o.value;return d.jsx($f,{scope:e.__scopeMenu,checked:s,children:d.jsx(Is,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":_a(s),onSelect:ve(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});Lf.displayName=Df;var Na="MenuItemIndicator",[$f,x0]=Zn(Na,{checked:!1}),Ff=b.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=x0(Na,n);return d.jsx(Dt,{present:r||As(s.checked)||s.checked===!0,children:d.jsx(Ne.span,{...o,ref:t,"data-state":_a(s.checked)})})});Ff.displayName=Na;var b0="MenuSeparator",zf=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return d.jsx(Ne.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});zf.displayName=b0;var y0="MenuArrow",Bf=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ks(n);return d.jsx(Xw,{...o,...r,ref:t})});Bf.displayName=y0;var w0="MenuSub",[iT,Uf]=Zn(w0),go="MenuSubTrigger",Hf=b.forwardRef((e,t)=>{const n=Qn(go,e.__scopeMenu),r=mo(go,e.__scopeMenu),o=Uf(go,e.__scopeMenu),s=Ea(go,e.__scopeMenu),i=b.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:c}=s,l={__scopeMenu:e.__scopeMenu},u=b.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return b.useEffect(()=>u,[u]),b.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),c(null)}},[a,c]),d.jsx(Ta,{asChild:!0,...l,children:d.jsx(Pf,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Kf(n.open),...e,ref:jn(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:ve(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:ve(e.onPointerLeave,xo(f=>{var p,m;u();const h=(p=n.content)==null?void 0:p.getBoundingClientRect();if(h){const g=(m=n.content)==null?void 0:m.dataset.side,x=g==="right",y=x?-5:5,w=h[x?"left":"right"],k=h[x?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+y,y:f.clientY},{x:w,y:h.top},{x:k,y:h.top},{x:k,y:h.bottom},{x:w,y:h.bottom}],side:g}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:ve(e.onKeyDown,f=>{var p;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||e0[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});Hf.displayName=go;var Wf="MenuSubContent",Vf=b.forwardRef((e,t)=>{const n=If(Bt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Qn(Bt,e.__scopeMenu),i=mo(Bt,e.__scopeMenu),a=Uf(Wf,e.__scopeMenu),c=b.useRef(null),l=Je(t,c);return d.jsx(po.Provider,{scope:e.__scopeMenu,children:d.jsx(Dt,{present:r||s.open,children:d.jsx(po.Slot,{scope:e.__scopeMenu,children:d.jsx(Ia,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:l,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:u=>{var f;i.isUsingKeyboardRef.current&&((f=c.current)==null||f.focus()),u.preventDefault()},onCloseAutoFocus:u=>u.preventDefault(),onFocusOutside:ve(e.onFocusOutside,u=>{u.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ve(e.onEscapeKeyDown,u=>{i.onClose(),u.preventDefault()}),onKeyDown:ve(e.onKeyDown,u=>{var p;const f=u.currentTarget.contains(u.target),h=t0[i.dir].includes(u.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),u.preventDefault())})})})})})});Vf.displayName=Wf;function Kf(e){return e?"open":"closed"}function As(e){return e==="indeterminate"}function _a(e){return As(e)?"indeterminate":e?"checked":"unchecked"}function v0(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function S0(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function C0(e,t,n){const o=t.length>1&&Array.from(t).every(l=>l===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=S0(e,Math.max(s,0));o.length===1&&(i=i.filter(l=>l!==n));const c=i.find(l=>l.toLowerCase().startsWith(o.toLowerCase()));return c!==n?c:void 0}function T0(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],c=t[i],l=a.x,u=a.y,f=c.x,h=c.y;u>r!=h>r&&n<(f-l)*(r-u)/(h-u)+l&&(o=!o)}return o}function k0(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return T0(n,t)}function xo(e){return t=>t.pointerType==="mouse"?e(t):void 0}var E0=Ef,I0=Ta,A0=Af,N0=Nf,_0=Aa,j0=_f,P0=Is,R0=Rf,M0=Of,O0=Lf,D0=Ff,L0=zf,$0=Bf,F0=Hf,z0=Vf,Ns="DropdownMenu",[B0,aT]=Pn(Ns,[Tf]),Ct=Tf(),[U0,qf]=B0(Ns),Gf=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,c=Ct(t),l=b.useRef(null),[u,f]=is({prop:o,defaultProp:s??!1,onChange:i,caller:Ns});return d.jsx(U0,{scope:t,triggerId:Rt(),triggerRef:l,contentId:Rt(),open:u,onOpenChange:f,onOpenToggle:b.useCallback(()=>f(h=>!h),[f]),modal:a,children:d.jsx(E0,{...c,open:u,onOpenChange:f,dir:r,modal:a,children:n})})};Gf.displayName=Ns;var Yf="DropdownMenuTrigger",Xf=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=qf(Yf,n),i=Ct(n);return d.jsx(I0,{asChild:!0,...i,children:d.jsx(Ne.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:jn(t,s.triggerRef),onPointerDown:ve(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:ve(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});Xf.displayName=Yf;var H0="DropdownMenuPortal",Jf=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Ct(t);return d.jsx(A0,{...r,...n})};Jf.displayName=H0;var Zf="DropdownMenuContent",Qf=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=qf(Zf,n),s=Ct(n),i=b.useRef(!1);return d.jsx(N0,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:ve(e.onCloseAutoFocus,a=>{var c;i.current||(c=o.triggerRef.current)==null||c.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:ve(e.onInteractOutside,a=>{const c=a.detail.originalEvent,l=c.button===0&&c.ctrlKey===!0,u=c.button===2||l;(!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)"}})});Qf.displayName=Zf;var W0="DropdownMenuGroup",V0=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return d.jsx(_0,{...o,...r,ref:t})});V0.displayName=W0;var K0="DropdownMenuLabel",eh=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return d.jsx(j0,{...o,...r,ref:t})});eh.displayName=K0;var q0="DropdownMenuItem",th=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return d.jsx(P0,{...o,...r,ref:t})});th.displayName=q0;var G0="DropdownMenuCheckboxItem",nh=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return d.jsx(R0,{...o,...r,ref:t})});nh.displayName=G0;var Y0="DropdownMenuRadioGroup",X0=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return d.jsx(M0,{...o,...r,ref:t})});X0.displayName=Y0;var J0="DropdownMenuRadioItem",rh=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return d.jsx(O0,{...o,...r,ref:t})});rh.displayName=J0;var Z0="DropdownMenuItemIndicator",oh=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return d.jsx(D0,{...o,...r,ref:t})});oh.displayName=Z0;var Q0="DropdownMenuSeparator",sh=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return d.jsx(L0,{...o,...r,ref:t})});sh.displayName=Q0;var eS="DropdownMenuArrow",tS=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return d.jsx($0,{...o,...r,ref:t})});tS.displayName=eS;var nS="DropdownMenuSubTrigger",ih=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return d.jsx(F0,{...o,...r,ref:t})});ih.displayName=nS;var rS="DropdownMenuSubContent",ah=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ct(n);return d.jsx(z0,{...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)"}})});ah.displayName=rS;var oS=Gf,sS=Xf,iS=Jf,lh=Qf,ch=eh,uh=th,dh=nh,fh=rh,hh=oh,ph=sh,mh=ih,gh=ah;const ja=oS,Pa=sS,aS=b.forwardRef(({className:e,inset:t,children:n,...r},o)=>d.jsxs(mh,{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"})]}));aS.displayName=mh.displayName;const lS=b.forwardRef(({className:e,...t},n)=>d.jsx(gh,{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}));lS.displayName=gh.displayName;const _s=b.forwardRef(({className:e,sideOffset:t=4,...n},r)=>d.jsx(iS,{children:d.jsx(lh,{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=lh.displayName;const er=b.forwardRef(({className:e,inset:t,...n},r)=>d.jsx(uh,{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}));er.displayName=uh.displayName;const cS=b.forwardRef(({className:e,children:t,checked:n,...r},o)=>d.jsxs(dh,{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(hh,{children:d.jsx(xe.Check,{className:"h-4 w-4"})})}),t]}));cS.displayName=dh.displayName;const uS=b.forwardRef(({className:e,children:t,...n},r)=>d.jsxs(fh,{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(hh,{children:d.jsx(xe.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));uS.displayName=fh.displayName;const dS=b.forwardRef(({className:e,inset:t,...n},r)=>d.jsx(ch,{ref:r,className:he("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));dS.displayName=ch.displayName;const fS=b.forwardRef(({className:e,...t},n)=>d.jsx(ph,{ref:n,className:he("-mx-1 my-1 h-px bg-muted",e),...t}));fS.displayName=ph.displayName;const xh=b.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}));xh.displayName="Textarea";const hS=1e4;function Ra({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=hS,value:i,onValueChange:a,onSend:c,onCancelEdit:l,onStop:u,className:f="",textareaClassName:h="",allowEmptySend:p=!1,sendButtonClassName:m,validate:g,onValidationError:x}){const y=i!==void 0,[w,k]=v.useState(e),I=(y?i:w)??"",[S,C]=v.useTransition(),T=v.useRef(null),A=v.useRef(0),j=v.useRef(null),P=v.useRef("");v.useEffect(()=>{if(!y&&(k(e??""),j.current=null,T.current)){const $=!e||e.trim()==="",D=44;$?T.current.style.height=`${D}px`:(T.current.style.height="auto",T.current.style.height=`${Math.max(T.current.scrollHeight,D)}px`)}},[e,t,y]);const[M,F]=v.useState(null),U=v.useCallback($=>$.length>s?`Message too long (${$.length}/${s} characters)`:null,[s]),L=v.useMemo(()=>g??U,[g,U]),K=v.useCallback($=>{const D=L($);return F(D),x==null||x(D),P.current=$,D},[L,x]),q=v.useCallback(()=>{const $=T.current;if(!$)return;const D=!$.value||$.value.trim()==="",G=44;if(D){$.style.height=`${G}px`;return}$.style.height="auto";const ee=Math.max($.scrollHeight,G);$.style.height=`${ee}px`},[]);v.useEffect(()=>{q()},[q,I]),v.useEffect(()=>{if(!M)return;const $=(I??"").trim();P.current!==$&&K($)},[I,M,K]);const re=v.useCallback(($,{fromUser:D})=>{y||k($),D&&(a==null||a($))},[y,a]),W=v.useCallback(async $=>{$&&$.preventDefault();const D=(I??"").trim();if(!D&&!p||K(D))return;const G=++A.current;j.current={id:G,shouldClear:!0},C(()=>{var ee,_,B;try{const X=c(D);X&&typeof X.then=="function"?X.then(()=>{var le,me;((le=j.current)==null?void 0:le.id)===G&&j.current.shouldClear&&(y||(k(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((me=j.current)==null?void 0:me.id)===G&&(j.current=null)}).catch(()=>{var le;((le=j.current)==null?void 0:le.id)===G&&(j.current=null)}):(((ee=j.current)==null?void 0:ee.id)===G&&j.current.shouldClear&&(y||(k(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((_=j.current)==null?void 0:_.id)===G&&(j.current=null))}catch{((B=j.current)==null?void 0:B.id)===G&&(j.current=null)}})},[I,c,p,y,a,K]),V=v.useCallback($=>{const D=$.target.value;re(D,{fromUser:!0}),j.current&&(j.current.shouldClear=!1),T.current&&(T.current.style.height="auto",T.current.style.height=`${T.current.scrollHeight}px`),M&&K(D.trim())},[re,K,M]),ne=v.useCallback($=>{$.key==="Enter"&&!$.shiftKey?($.preventDefault(),W()):$.key==="Escape"&&t&&($.preventDefault(),l==null||l())},[W,t,l]),N=`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(xh,{ref:T,value:I,onChange:V,onKeyDown:ne,placeholder:t?"Edit your message...":n,className:N,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"}),M&&d.jsx("p",{className:"mt-1 text-xs text-destructive font-medium",children:M})]}),d.jsx("div",{children:r?d.jsx(Qe,{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(Qe,{type:"button",onClick:$=>void W($),size:"icon",className:`shrink-0 ${m??""}`,title:t?"Save changes":"Send message",disabled:o||!I.trim()&&!p||S||r,children:d.jsx(xe.Send,{size:16})})})]})})}const pS=v.memo(Ra);function js({composerValue:e,onComposerChange:t,onSend:n,onCancelEdit:r,onStop:o,editingMessageId:s=null,editingInitialValue:i="",placeholder:a="Type your message...",isStreaming:c=!1,disabled:l=!1,textareaClassName:u="",customStyles:f={},enableFileUpload:h=!1,enableExcelUpload:p=!1,onExcelUpload:m,onFilesChange:g,onError:x,allowEmptySend:y=!1,inputError:w=null}){const[k,I]=v.useState([]),S=v.useRef(null),C=v.useRef(null),[T,A]=v.useState(0),[j,P]=v.useState(0),[M,F]=v.useState(!1),[U,L]=v.useState(null),[K,q]=v.useState(null),re=v.useCallback(()=>{S.current&&(S.current.value=""),C.current&&(C.current.value=""),A(D=>D+1),P(D=>D+1)},[]),W=v.useCallback(D=>{I(G=>{const ee=[...G,...D];return g==null||g(ee),ee})},[g]),V=v.useCallback(D=>{const G=Array.from(D.target.files||[]);W(G),D.target.value=""},[W]),ne=v.useCallback(D=>{I(G=>{const ee=G.filter((_,B)=>B!==D);return ee.length===0&&re(),g==null||g(ee),ee})},[g,re]),H=v.useCallback(async D=>{const G=(D.target.files||[])[0];if(G&&(L(null),q(null),!!m)){F(!0);try{await m(G),L(`Uploaded ${G.name} - processing through chat stream`)}catch(ee){const _=ee instanceof Error?ee.message:"Failed to upload Excel file";q(_),x==null||x(_)}finally{F(!1),D.target.value="",re()}}},[m,x,re]),O=v.useMemo(()=>y||k.length>0,[y,k]),N=v.useCallback(async D=>{const ee=await n(D,k);return k.length>0&&(I([]),g==null||g([]),re()),ee},[n,re,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":""} ${w?"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((D,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(xe.Paperclip,{size:14}),d.jsx("span",{className:"truncate max-w-[150px]",children:D.name}),d.jsx(Qe,{variant:"ghost",size:"sm",onClick:()=>ne(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 ${D.name}`,children:d.jsx(xe.X,{size:12})})]},G))})]}),p&&d.jsxs(d.Fragment,{children:[d.jsx("input",{ref:C,type:"file",accept:".xls,.xlsx,.xlsm",onChange:H,className:"hidden"},j),M&&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..."]}),U&&!M&&d.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:U}),K&&!M&&d.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:K})]})]}),d.jsxs("div",{className:"flex items-end gap-2",children:[(h||p)&&d.jsxs(ja,{children:[d.jsx(Pa,{asChild:!0,children:d.jsx(Qe,{type:"button",size:"icon",variant:"outline",disabled:c||l,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(er,{onClick:()=>{var D;return(D=S.current)==null?void 0:D.click()},className:"cursor-pointer",children:[d.jsx(xe.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),p&&d.jsxs(er,{onClick:()=>{var D;M||(D=C.current)==null||D.click()},className:`cursor-pointer ${M?"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(pS,{initialValue:i,editingMessageId:s,value:e,onValueChange:t,placeholder:s?"Edit your message...":a,isStreaming:c,disabled:l,onSend:N,onCancelEdit:r,onStop:o,allowEmptySend:O,textareaClassName:$,sendButtonClassName:f.sendButton})})]})]})}v.memo(js);function bh({submit:e,chatRequest:t,lastCheckpointId:n,lastCheckpointNs:r,onMessageSent:o,onExcelUploadSuccess:s,onError:i,enableMessageEditing:a,messages:c,setPendingAssistantResponse:l,project:u,onEvent:f,activeThreadId:h}){const{messages:p}=pi(),[m,g]=v.useState(null),[x,y]=v.useState(""),[w,k]=v.useState(null),[I,S]=v.useState(null),[C,T]=v.useState(!1),[A,j]=v.useState(""),P=v.useRef(A),M=v.useRef(null);v.useEffect(()=>{if(!m)if(h){const H=localStorage.getItem(Po(h));j(H||"")}else j("")},[h,m]);const F=v.useCallback(H=>{j(H),!m&&h&&localStorage.setItem(Po(h),H)},[h,m]);v.useEffect(()=>{P.current=A},[A]),v.useEffect(()=>{if(!m){M.current=null;return}M.current===null&&(M.current=P.current),F(x??"")},[x,m,F]);const U=v.useCallback(H=>{F(H)},[F]),L=async(H,O)=>{const N=Array.isArray(O)?{files:O}:O??{},$=N.files??[],D=N.contentParts??[],G=H.trim();if(!(!G&&$.length===0&&D.length===0))try{const ee=$.map(async be=>{try{const Te=await si.uploadFile(be);return{file:be,record:Te}}catch(Te){throw console.error("Failed to upload file",be.name,Te),new Error(`Failed to upload ${be.name}`)}}),B=(await Promise.all(ee)).map(({record:be})=>{const Te=be.mime_type;return Te.startsWith("image/")?{type:"image_url",image_url:{url:be.content_url}}:{type:"file",url:be.content_url,mimeType:Te,name:be.filename,size:be.size}}),X=[...D,...B],le=m?(w==null?void 0:w.checkpointId)??n??void 0:n??void 0,me=m?(w==null?void 0:w.checkpointNs)??r??void 0:r??void 0;await e({text:G||"",contentParts:X,attachments:[],payload:t.payload},{checkpointId:le,checkpointNs:me,project:u??void 0,edit:!!m,originalMessageId:m??void 0,config:t.config,onEvent:f}),o==null||o(G),l(!0),h&&localStorage.removeItem(Po(h)),F(""),S(null),g(null),y(""),k(null)}catch(ee){const _=(ee==null?void 0:ee.message)||"Failed to send message";S(_),i==null||i(_),l(!1)}},K=(H,O)=>{O||L(H,{files:[]})},q=v.useCallback(async H=>{await e({attachments:[H],payload:t.payload},{checkpointId:n??void 0,checkpointNs:r??void 0,project:u??void 0,config:t.config,onEvent:f}),s==null||s({file:H})},[n,r,t,s,e]),re=v.useCallback((H,O,N)=>{a&&(M.current=A,g(H),y(O),k({checkpointId:(N==null?void 0:N.checkpointId)??null,checkpointNs:(N==null?void 0:N.checkpointNs)??null}),S(null))},[A,a]),W=v.useCallback(()=>{g(null),y(""),k(null),S(null);const H=M.current;H!==null&&j(H),M.current=null},[]),V=v.useCallback(H=>{let O=null;for(let G=H-1;G>=0;G--)if(c[G].role==="user"){O=c[G];break}if(!O)return;const N=Array.isArray(O.content)?O.content:[],D=N.filter(G=>(G==null?void 0:G.type)==="text").map(G=>G.text).join("")||(()=>{try{return JSON.stringify(N,null,2)}catch{return String(N)}})();D&&e({text:D,payload:t.payload},{checkpointId:n??void 0,checkpointNs:r??void 0,edit:!0,originalMessageId:O.id,config:t.config,onEvent:f})},[c,e,n,r,t]);return{editingMessageId:m,editingInitialValue:x,inputError:I,setInputError:S,dismissError:C,setDismissError:T,composerValue:A,handleComposerChange:U,handleSendMessage:L,handleQuickPrompt:K,handleExcelUpload:q,startEditing:re,cancelEditing:W,handleRegenerateCb:V,displayMessages:p}}var Ps="Dialog",[yh,lT]=Pn(Ps),[mS,Gt]=yh(Ps),wh=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=b.useRef(null),c=b.useRef(null),[l,u]=is({prop:r,defaultProp:o??!1,onChange:s,caller:Ps});return d.jsx(mS,{scope:t,triggerRef:a,contentRef:c,contentId:Rt(),titleId:Rt(),descriptionId:Rt(),open:l,onOpenChange:u,onOpenToggle:b.useCallback(()=>u(f=>!f),[u]),modal:i,children:n})};wh.displayName=Ps;var vh="DialogTrigger",gS=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Gt(vh,n),s=Je(t,o.triggerRef);return d.jsx(Ne.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Da(o.open),...r,ref:s,onClick:ve(e.onClick,o.onOpenToggle)})});gS.displayName=vh;var Ma="DialogPortal",[xS,Sh]=yh(Ma,{forceMount:void 0}),Ch=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=Gt(Ma,t);return d.jsx(xS,{scope:t,forceMount:n,children:b.Children.map(r,i=>d.jsx(Dt,{present:n||s.open,children:d.jsx(pa,{asChild:!0,container:o,children:i})}))})};Ch.displayName=Ma;var Rs="DialogOverlay",Th=b.forwardRef((e,t)=>{const n=Sh(Rs,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=Gt(Rs,e.__scopeDialog);return s.modal?d.jsx(Dt,{present:r||s.open,children:d.jsx(yS,{...o,ref:t})}):null});Th.displayName=Rs;var bS=cr.createSlot("DialogOverlay.RemoveScroll"),yS=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Gt(Rs,n);return d.jsx(Sa,{as:bS,allowPinchZoom:!0,shards:[o.contentRef],children:d.jsx(Ne.div,{"data-state":Da(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),tr="DialogContent",kh=b.forwardRef((e,t)=>{const n=Sh(tr,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=Gt(tr,e.__scopeDialog);return d.jsx(Dt,{present:r||s.open,children:s.modal?d.jsx(wS,{...o,ref:t}):d.jsx(vS,{...o,ref:t})})});kh.displayName=tr;var wS=b.forwardRef((e,t)=>{const n=Gt(tr,e.__scopeDialog),r=b.useRef(null),o=Je(t,n.contentRef,r);return b.useEffect(()=>{const s=r.current;if(s)return uf(s)},[]),d.jsx(Eh,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ve(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:ve(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:ve(e.onFocusOutside,s=>s.preventDefault())})}),vS=b.forwardRef((e,t)=>{const n=Gt(tr,e.__scopeDialog),r=b.useRef(!1),o=b.useRef(!1);return d.jsx(Eh,{...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 c,l;(c=e.onInteractOutside)==null||c.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const i=s.target;((l=n.triggerRef.current)==null?void 0:l.contains(i))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),Eh=b.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=Gt(tr,n),c=b.useRef(null),l=Je(t,c);return gd(),d.jsxs(d.Fragment,{children:[d.jsx(ea,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:d.jsx(Xi,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Da(a.open),...i,ref:l,onDismiss:()=>a.onOpenChange(!1)})}),d.jsxs(d.Fragment,{children:[d.jsx(SS,{titleId:a.titleId}),d.jsx(TS,{contentRef:c,descriptionId:a.descriptionId})]})]})}),Oa="DialogTitle",Ih=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Gt(Oa,n);return d.jsx(Ne.h2,{id:o.titleId,...r,ref:t})});Ih.displayName=Oa;var Ah="DialogDescription",Nh=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Gt(Ah,n);return d.jsx(Ne.p,{id:o.descriptionId,...r,ref:t})});Nh.displayName=Ah;var _h="DialogClose",jh=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Gt(_h,n);return d.jsx(Ne.button,{type:"button",...r,ref:t,onClick:ve(e.onClick,()=>o.onOpenChange(!1))})});jh.displayName=_h;function Da(e){return e?"open":"closed"}var Ph="DialogTitleWarning",[cT,Rh]=oy(Ph,{contentName:tr,titleName:Oa,docsSlug:"dialog"}),SS=({titleId:e})=>{const t=Rh(Ph),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
127
+ `)},Gv=0,Nr=[];function Yv(e){var t=b.useRef([]),n=b.useRef([0,0]),r=b.useRef(),o=b.useState(Gv++)[0],s=b.useState(mf)[0],i=b.useRef(e);b.useEffect(function(){i.current=e},[e]),b.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var g=gv([e.lockRef.current],(e.shards||[]).map(Sf),!0).filter(Boolean);return g.forEach(function(x){return x.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),g.forEach(function(x){return x.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=b.useCallback(function(g,x){if("touches"in g&&g.touches.length===2||g.type==="wheel"&&g.ctrlKey)return!i.current.allowPinchZoom;var y=Ts(g),w=n.current,k="deltaX"in g?g.deltaX:w[0]-y[0],I="deltaY"in g?g.deltaY:w[1]-y[1],S,C=g.target,T=Math.abs(k)>Math.abs(I)?"h":"v";if("touches"in g&&T==="h"&&C.type==="range")return!1;var A=bf(T,C);if(!A)return!0;if(A?S=T:(S=T==="v"?"h":"v",A=bf(T,C)),!A)return!1;if(!r.current&&"changedTouches"in g&&(k||I)&&(r.current=S),!S)return!0;var j=r.current||S;return Vv(j,x,g,j==="h"?k:I)},[]),c=b.useCallback(function(g){var x=g;if(!(!Nr.length||Nr[Nr.length-1]!==s)){var y="deltaY"in x?vf(x):Ts(x),w=t.current.filter(function(S){return S.name===x.type&&(S.target===x.target||x.target===S.shadowParent)&&Kv(S.delta,y)})[0];if(w&&w.should){x.cancelable&&x.preventDefault();return}if(!w){var k=(i.current.shards||[]).map(Sf).filter(Boolean).filter(function(S){return S.contains(x.target)}),I=k.length>0?a(x,k[0]):!i.current.noIsolation;I&&x.cancelable&&x.preventDefault()}}},[]),l=b.useCallback(function(g,x,y,w){var k={name:g,delta:x,target:y,should:w,shadowParent:Xv(y)};t.current.push(k),setTimeout(function(){t.current=t.current.filter(function(I){return I!==k})},1)},[]),u=b.useCallback(function(g){n.current=Ts(g),r.current=void 0},[]),f=b.useCallback(function(g){l(g.type,vf(g),g.target,a(g,e.lockRef.current))},[]),h=b.useCallback(function(g){l(g.type,Ts(g),g.target,a(g,e.lockRef.current))},[]);b.useEffect(function(){return Nr.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:h}),document.addEventListener("wheel",c,Ar),document.addEventListener("touchmove",c,Ar),document.addEventListener("touchstart",u,Ar),function(){Nr=Nr.filter(function(g){return g!==s}),document.removeEventListener("wheel",c,Ar),document.removeEventListener("touchmove",c,Ar),document.removeEventListener("touchstart",u,Ar)}},[]);var p=e.removeScrollBar,m=e.inert;return b.createElement(b.Fragment,null,m?b.createElement(s,{styles:qv(o)}):null,p?b.createElement($v,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function Xv(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Jv=kv(pf,Yv);var Sa=b.forwardRef(function(e,t){return b.createElement(Ss,an({},e,{ref:t,sideCar:Jv}))});Sa.classNames=Ss.classNames;var Ca=["Enter"," "],Zv=["ArrowDown","PageUp","Home"],Cf=["ArrowUp","PageDown","End"],Qv=[...Zv,...Cf],e0={ltr:[...Ca,"ArrowRight"],rtl:[...Ca,"ArrowLeft"]},t0={ltr:["ArrowLeft"],rtl:["ArrowRight"]},ho="Menu",[po,n0,r0]=dd(ho),[Zn,Tf]=Pn(ho,[r0,qd,rf]),ks=qd(),kf=rf(),[o0,Qn]=Zn(ho),[s0,mo]=Zn(ho),Ef=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=ks(t),[c,l]=b.useState(null),u=b.useRef(!1),f=wt(s),h=Gi(o);return b.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(qw,{...a,children:d.jsx(o0,{scope:t,open:n,onOpenChange:f,content:c,onContentChange:l,children:d.jsx(s0,{scope:t,onClose:b.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:u,dir:h,modal:i,children:r})})})};Ef.displayName=ho;var i0="MenuAnchor",Ta=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ks(n);return d.jsx(Gw,{...o,...r,ref:t})});Ta.displayName=i0;var ka="MenuPortal",[a0,If]=Zn(ka,{forceMount:void 0}),Af=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=Qn(ka,t);return d.jsx(a0,{scope:t,forceMount:n,children:d.jsx(Dt,{present:n||s.open,children:d.jsx(pa,{asChild:!0,container:o,children:r})})})};Af.displayName=ka;var Bt="MenuContent",[l0,Ea]=Zn(Bt),Nf=b.forwardRef((e,t)=>{const n=If(Bt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Qn(Bt,e.__scopeMenu),i=mo(Bt,e.__scopeMenu);return d.jsx(po.Provider,{scope:e.__scopeMenu,children:d.jsx(Dt,{present:r||s.open,children:d.jsx(po.Slot,{scope:e.__scopeMenu,children:i.modal?d.jsx(c0,{...o,ref:t}):d.jsx(u0,{...o,ref:t})})})})}),c0=b.forwardRef((e,t)=>{const n=Qn(Bt,e.__scopeMenu),r=b.useRef(null),o=Ye(t,r);return b.useEffect(()=>{const s=r.current;if(s)return uf(s)},[]),d.jsx(Ia,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ve(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),u0=b.forwardRef((e,t)=>{const n=Qn(Bt,e.__scopeMenu);return d.jsx(Ia,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),d0=cr.createSlot("MenuContent.ScrollLock"),Ia=b.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:c,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:f,onInteractOutside:h,onDismiss:p,disableOutsideScroll:m,...g}=e,x=Qn(Bt,n),y=mo(Bt,n),w=ks(n),k=kf(n),I=n0(n),[S,C]=b.useState(null),T=b.useRef(null),A=Ye(t,T,x.onContentChange),j=b.useRef(0),_=b.useRef(""),L=b.useRef(0),F=b.useRef(null),B=b.useRef("right"),O=b.useRef(0),G=m?Sa:b.Fragment,Y=m?{as:d0,allowPinchZoom:!0}:void 0,re=W=>{var U,P;const ne=_.current+W,K=I().filter(V=>!V.disabled),M=document.activeElement,N=(U=K.find(V=>V.ref.current===M))==null?void 0:U.textValue,$=K.map(V=>V.textValue),D=C0($,ne,N),q=(P=K.find(V=>V.textValue===D))==null?void 0:P.ref.current;(function V(ee){_.current=ee,window.clearTimeout(j.current),ee!==""&&(j.current=window.setTimeout(()=>V(""),1e3))})(ne),q&&setTimeout(()=>q.focus())};b.useEffect(()=>()=>window.clearTimeout(j.current),[]),gd();const H=b.useCallback(W=>{var K,M;return B.current===((K=F.current)==null?void 0:K.side)&&k0(W,(M=F.current)==null?void 0:M.area)},[]);return d.jsx(l0,{scope:n,searchRef:_,onItemEnter:b.useCallback(W=>{H(W)&&W.preventDefault()},[H]),onItemLeave:b.useCallback(W=>{var ne;H(W)||((ne=T.current)==null||ne.focus(),C(null))},[H]),onTriggerLeave:b.useCallback(W=>{H(W)&&W.preventDefault()},[H]),pointerGraceTimerRef:L,onPointerGraceIntentChange:b.useCallback(W=>{F.current=W},[]),children:d.jsx(G,{...Y,children:d.jsx(ea,{asChild:!0,trapped:o,onMountAutoFocus:ve(s,W=>{var ne;W.preventDefault(),(ne=T.current)==null||ne.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:d.jsx(Xi,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:d.jsx(dv,{asChild:!0,...k,dir:y.dir,orientation:"vertical",loop:r,currentTabStopId:S,onCurrentTabStopIdChange:C,onEntryFocus:ve(c,W=>{y.isUsingKeyboardRef.current||W.preventDefault()}),preventScrollOnEntryFocus:!0,children:d.jsx(Yw,{role:"menu","aria-orientation":"vertical","data-state":Kf(x.open),"data-radix-menu-content":"",dir:y.dir,...w,...g,ref:A,style:{outline:"none",...g.style},onKeyDown:ve(g.onKeyDown,W=>{const K=W.target.closest("[data-radix-menu-content]")===W.currentTarget,M=W.ctrlKey||W.altKey||W.metaKey,N=W.key.length===1;K&&(W.key==="Tab"&&W.preventDefault(),!M&&N&&re(W.key));const $=T.current;if(W.target!==$||!Qv.includes(W.key))return;W.preventDefault();const q=I().filter(U=>!U.disabled).map(U=>U.ref.current);Cf.includes(W.key)&&q.reverse(),v0(q)}),onBlur:ve(e.onBlur,W=>{W.currentTarget.contains(W.target)||(window.clearTimeout(j.current),_.current="")}),onPointerMove:ve(e.onPointerMove,xo(W=>{const ne=W.target,K=O.current!==W.clientX;if(W.currentTarget.contains(ne)&&K){const M=W.clientX>O.current?"right":"left";B.current=M,O.current=W.clientX}}))})})})})})})});Nf.displayName=Bt;var f0="MenuGroup",Aa=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return d.jsx(Ne.div,{role:"group",...r,ref:t})});Aa.displayName=f0;var h0="MenuLabel",jf=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return d.jsx(Ne.div,{...r,ref:t})});jf.displayName=h0;var Es="MenuItem",_f="menu.itemSelect",Is=b.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=b.useRef(null),i=mo(Es,e.__scopeMenu),a=Ea(Es,e.__scopeMenu),c=Ye(t,s),l=b.useRef(!1),u=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(_f,{bubbles:!0,cancelable:!0});f.addEventListener(_f,p=>r==null?void 0:r(p),{once:!0}),ud(f,h),h.defaultPrevented?l.current=!1:i.onClose()}};return d.jsx(Pf,{...o,ref:c,disabled:n,onClick:ve(e.onClick,u),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),l.current=!0},onPointerUp:ve(e.onPointerUp,f=>{var h;l.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:ve(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||Ca.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});Is.displayName=Es;var Pf=b.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=Ea(Es,n),a=kf(n),c=b.useRef(null),l=Ye(t,c),[u,f]=b.useState(!1),[h,p]=b.useState("");return b.useEffect(()=>{const m=c.current;m&&p((m.textContent??"").trim())},[s.children]),d.jsx(po.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:d.jsx(fv,{asChild:!0,...a,focusable:!r,children:d.jsx(Ne.div,{role:"menuitem","data-highlighted":u?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:l,onPointerMove:ve(e.onPointerMove,xo(m=>{r?i.onItemLeave(m):(i.onItemEnter(m),m.defaultPrevented||m.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ve(e.onPointerLeave,xo(m=>i.onItemLeave(m))),onFocus:ve(e.onFocus,()=>f(!0)),onBlur:ve(e.onBlur,()=>f(!1))})})})}),p0="MenuCheckboxItem",Rf=b.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return d.jsx($f,{scope:e.__scopeMenu,checked:n,children:d.jsx(Is,{role:"menuitemcheckbox","aria-checked":As(n)?"mixed":n,...o,ref:t,"data-state":ja(n),onSelect:ve(o.onSelect,()=>r==null?void 0:r(As(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Rf.displayName=p0;var Of="MenuRadioGroup",[m0,g0]=Zn(Of,{value:void 0,onValueChange:()=>{}}),Mf=b.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=wt(r);return d.jsx(m0,{scope:e.__scopeMenu,value:n,onValueChange:s,children:d.jsx(Aa,{...o,ref:t})})});Mf.displayName=Of;var Df="MenuRadioItem",Lf=b.forwardRef((e,t)=>{const{value:n,...r}=e,o=g0(Df,e.__scopeMenu),s=n===o.value;return d.jsx($f,{scope:e.__scopeMenu,checked:s,children:d.jsx(Is,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":ja(s),onSelect:ve(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});Lf.displayName=Df;var Na="MenuItemIndicator",[$f,x0]=Zn(Na,{checked:!1}),Ff=b.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=x0(Na,n);return d.jsx(Dt,{present:r||As(s.checked)||s.checked===!0,children:d.jsx(Ne.span,{...o,ref:t,"data-state":ja(s.checked)})})});Ff.displayName=Na;var b0="MenuSeparator",zf=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return d.jsx(Ne.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});zf.displayName=b0;var y0="MenuArrow",Bf=b.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=ks(n);return d.jsx(Xw,{...o,...r,ref:t})});Bf.displayName=y0;var w0="MenuSub",[iT,Uf]=Zn(w0),go="MenuSubTrigger",Hf=b.forwardRef((e,t)=>{const n=Qn(go,e.__scopeMenu),r=mo(go,e.__scopeMenu),o=Uf(go,e.__scopeMenu),s=Ea(go,e.__scopeMenu),i=b.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:c}=s,l={__scopeMenu:e.__scopeMenu},u=b.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return b.useEffect(()=>u,[u]),b.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),c(null)}},[a,c]),d.jsx(Ta,{asChild:!0,...l,children:d.jsx(Pf,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Kf(n.open),...e,ref:_n(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:ve(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:ve(e.onPointerLeave,xo(f=>{var p,m;u();const h=(p=n.content)==null?void 0:p.getBoundingClientRect();if(h){const g=(m=n.content)==null?void 0:m.dataset.side,x=g==="right",y=x?-5:5,w=h[x?"left":"right"],k=h[x?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+y,y:f.clientY},{x:w,y:h.top},{x:k,y:h.top},{x:k,y:h.bottom},{x:w,y:h.bottom}],side:g}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:ve(e.onKeyDown,f=>{var p;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||e0[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});Hf.displayName=go;var Wf="MenuSubContent",Vf=b.forwardRef((e,t)=>{const n=If(Bt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=Qn(Bt,e.__scopeMenu),i=mo(Bt,e.__scopeMenu),a=Uf(Wf,e.__scopeMenu),c=b.useRef(null),l=Ye(t,c);return d.jsx(po.Provider,{scope:e.__scopeMenu,children:d.jsx(Dt,{present:r||s.open,children:d.jsx(po.Slot,{scope:e.__scopeMenu,children:d.jsx(Ia,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:l,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:u=>{var f;i.isUsingKeyboardRef.current&&((f=c.current)==null||f.focus()),u.preventDefault()},onCloseAutoFocus:u=>u.preventDefault(),onFocusOutside:ve(e.onFocusOutside,u=>{u.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ve(e.onEscapeKeyDown,u=>{i.onClose(),u.preventDefault()}),onKeyDown:ve(e.onKeyDown,u=>{var p;const f=u.currentTarget.contains(u.target),h=t0[i.dir].includes(u.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),u.preventDefault())})})})})})});Vf.displayName=Wf;function Kf(e){return e?"open":"closed"}function As(e){return e==="indeterminate"}function ja(e){return As(e)?"indeterminate":e?"checked":"unchecked"}function v0(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function S0(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function C0(e,t,n){const o=t.length>1&&Array.from(t).every(l=>l===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=S0(e,Math.max(s,0));o.length===1&&(i=i.filter(l=>l!==n));const c=i.find(l=>l.toLowerCase().startsWith(o.toLowerCase()));return c!==n?c:void 0}function T0(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],c=t[i],l=a.x,u=a.y,f=c.x,h=c.y;u>r!=h>r&&n<(f-l)*(r-u)/(h-u)+l&&(o=!o)}return o}function k0(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return T0(n,t)}function xo(e){return t=>t.pointerType==="mouse"?e(t):void 0}var E0=Ef,I0=Ta,A0=Af,N0=Nf,j0=Aa,_0=jf,P0=Is,R0=Rf,O0=Mf,M0=Lf,D0=Ff,L0=zf,$0=Bf,F0=Hf,z0=Vf,Ns="DropdownMenu",[B0,aT]=Pn(Ns,[Tf]),Tt=Tf(),[U0,qf]=B0(Ns),Gf=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,c=Tt(t),l=b.useRef(null),[u,f]=is({prop:o,defaultProp:s??!1,onChange:i,caller:Ns});return d.jsx(U0,{scope:t,triggerId:Rt(),triggerRef:l,contentId:Rt(),open:u,onOpenChange:f,onOpenToggle:b.useCallback(()=>f(h=>!h),[f]),modal:a,children:d.jsx(E0,{...c,open:u,onOpenChange:f,dir:r,modal:a,children:n})})};Gf.displayName=Ns;var Yf="DropdownMenuTrigger",Xf=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=qf(Yf,n),i=Tt(n);return d.jsx(I0,{asChild:!0,...i,children:d.jsx(Ne.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:_n(t,s.triggerRef),onPointerDown:ve(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:ve(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});Xf.displayName=Yf;var H0="DropdownMenuPortal",Jf=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Tt(t);return d.jsx(A0,{...r,...n})};Jf.displayName=H0;var Zf="DropdownMenuContent",Qf=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=qf(Zf,n),s=Tt(n),i=b.useRef(!1);return d.jsx(N0,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:ve(e.onCloseAutoFocus,a=>{var c;i.current||(c=o.triggerRef.current)==null||c.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:ve(e.onInteractOutside,a=>{const c=a.detail.originalEvent,l=c.button===0&&c.ctrlKey===!0,u=c.button===2||l;(!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)"}})});Qf.displayName=Zf;var W0="DropdownMenuGroup",V0=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Tt(n);return d.jsx(j0,{...o,...r,ref:t})});V0.displayName=W0;var K0="DropdownMenuLabel",eh=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Tt(n);return d.jsx(_0,{...o,...r,ref:t})});eh.displayName=K0;var q0="DropdownMenuItem",th=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Tt(n);return d.jsx(P0,{...o,...r,ref:t})});th.displayName=q0;var G0="DropdownMenuCheckboxItem",nh=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Tt(n);return d.jsx(R0,{...o,...r,ref:t})});nh.displayName=G0;var Y0="DropdownMenuRadioGroup",X0=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Tt(n);return d.jsx(O0,{...o,...r,ref:t})});X0.displayName=Y0;var J0="DropdownMenuRadioItem",rh=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Tt(n);return d.jsx(M0,{...o,...r,ref:t})});rh.displayName=J0;var Z0="DropdownMenuItemIndicator",oh=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Tt(n);return d.jsx(D0,{...o,...r,ref:t})});oh.displayName=Z0;var Q0="DropdownMenuSeparator",sh=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Tt(n);return d.jsx(L0,{...o,...r,ref:t})});sh.displayName=Q0;var eS="DropdownMenuArrow",tS=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Tt(n);return d.jsx($0,{...o,...r,ref:t})});tS.displayName=eS;var nS="DropdownMenuSubTrigger",ih=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Tt(n);return d.jsx(F0,{...o,...r,ref:t})});ih.displayName=nS;var rS="DropdownMenuSubContent",ah=b.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Tt(n);return d.jsx(z0,{...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)"}})});ah.displayName=rS;var oS=Gf,sS=Xf,iS=Jf,lh=Qf,ch=eh,uh=th,dh=nh,fh=rh,hh=oh,ph=sh,mh=ih,gh=ah;const _a=oS,Pa=sS,aS=b.forwardRef(({className:e,inset:t,children:n,...r},o)=>d.jsxs(mh,{ref:o,className:pe("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"})]}));aS.displayName=mh.displayName;const lS=b.forwardRef(({className:e,...t},n)=>d.jsx(gh,{ref:n,className:pe("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}));lS.displayName=gh.displayName;const js=b.forwardRef(({className:e,sideOffset:t=4,...n},r)=>d.jsx(iS,{children:d.jsx(lh,{ref:r,sideOffset:t,className:pe("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})}));js.displayName=lh.displayName;const er=b.forwardRef(({className:e,inset:t,...n},r)=>d.jsx(uh,{ref:r,className:pe("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}));er.displayName=uh.displayName;const cS=b.forwardRef(({className:e,children:t,checked:n,...r},o)=>d.jsxs(dh,{ref:o,className:pe("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(hh,{children:d.jsx(xe.Check,{className:"h-4 w-4"})})}),t]}));cS.displayName=dh.displayName;const uS=b.forwardRef(({className:e,children:t,...n},r)=>d.jsxs(fh,{ref:r,className:pe("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(hh,{children:d.jsx(xe.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));uS.displayName=fh.displayName;const dS=b.forwardRef(({className:e,inset:t,...n},r)=>d.jsx(ch,{ref:r,className:pe("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));dS.displayName=ch.displayName;const fS=b.forwardRef(({className:e,...t},n)=>d.jsx(ph,{ref:n,className:pe("-mx-1 my-1 h-px bg-muted",e),...t}));fS.displayName=ph.displayName;const xh=b.forwardRef(({className:e,...t},n)=>d.jsx("textarea",{className:pe("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}));xh.displayName="Textarea";const hS=1e4;function Ra({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=hS,value:i,onValueChange:a,onSend:c,onCancelEdit:l,onStop:u,className:f="",textareaClassName:h="",allowEmptySend:p=!1,sendButtonClassName:m,validate:g,onValidationError:x}){const y=i!==void 0,[w,k]=v.useState(e),I=(y?i:w)??"",[S,C]=v.useTransition(),T=v.useRef(null),A=v.useRef(0),j=v.useRef(null),_=v.useRef("");v.useEffect(()=>{if(!y&&(k(e??""),j.current=null,T.current)){const $=!e||e.trim()==="",D=44;$?T.current.style.height=`${D}px`:(T.current.style.height="auto",T.current.style.height=`${Math.max(T.current.scrollHeight,D)}px`)}},[e,t,y]);const[L,F]=v.useState(null),B=v.useCallback($=>$.length>s?`Message too long (${$.length}/${s} characters)`:null,[s]),O=v.useMemo(()=>g??B,[g,B]),G=v.useCallback($=>{const D=O($);return F(D),x==null||x(D),_.current=$,D},[O,x]),Y=v.useCallback(()=>{const $=T.current;if(!$)return;const D=!$.value||$.value.trim()==="",q=44;if(D){$.style.height=`${q}px`;return}$.style.height="auto";const U=Math.max($.scrollHeight,q);$.style.height=`${U}px`},[]);v.useEffect(()=>{Y()},[Y,I]),v.useEffect(()=>{if(!L)return;const $=(I??"").trim();_.current!==$&&G($)},[I,L,G]);const re=v.useCallback(($,{fromUser:D})=>{y||k($),D&&(a==null||a($))},[y,a]),H=v.useCallback(async $=>{$&&$.preventDefault();const D=(I??"").trim();if(!D&&!p||G(D))return;const q=++A.current;j.current={id:q,shouldClear:!0},C(()=>{var U,P,V;try{const ee=c(D);ee&&typeof ee.then=="function"?ee.then(()=>{var ce,ue;((ce=j.current)==null?void 0:ce.id)===q&&j.current.shouldClear&&(y||(k(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((ue=j.current)==null?void 0:ue.id)===q&&(j.current=null)}).catch(()=>{var ce;((ce=j.current)==null?void 0:ce.id)===q&&(j.current=null)}):(((U=j.current)==null?void 0:U.id)===q&&j.current.shouldClear&&(y||(k(""),T.current&&(T.current.style.height="auto"),a==null||a(""))),((P=j.current)==null?void 0:P.id)===q&&(j.current=null))}catch{((V=j.current)==null?void 0:V.id)===q&&(j.current=null)}})},[I,c,p,y,a,G]),W=v.useCallback($=>{const D=$.target.value;re(D,{fromUser:!0}),j.current&&(j.current.shouldClear=!1),T.current&&(T.current.style.height="auto",T.current.style.height=`${T.current.scrollHeight}px`),L&&G(D.trim())},[re,G,L]),ne=v.useCallback($=>{$.key==="Enter"&&!$.shiftKey?($.preventDefault(),H()):$.key==="Escape"&&t&&($.preventDefault(),l==null||l())},[H,t,l]),N=`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(xh,{ref:T,value:I,onChange:W,onKeyDown:ne,placeholder:t?"Edit your message...":n,className:N,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(xe.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||!I.trim()&&!p||S||r,children:d.jsx(xe.Send,{size:16})})})]})})}const pS=v.memo(Ra);function _s({composerValue:e,onComposerChange:t,onSend:n,onCancelEdit:r,onStop:o,editingMessageId:s=null,editingInitialValue:i="",placeholder:a="Type your message...",isStreaming:c=!1,disabled:l=!1,textareaClassName:u="",customStyles:f={},enableFileUpload:h=!1,enableExcelUpload:p=!1,onExcelUpload:m,onFilesChange:g,onError:x,allowEmptySend:y=!1,inputError:w=null}){const[k,I]=v.useState([]),S=v.useRef(null),C=v.useRef(null),[T,A]=v.useState(0),[j,_]=v.useState(0),[L,F]=v.useState(!1),[B,O]=v.useState(null),[G,Y]=v.useState(null),re=v.useCallback(()=>{S.current&&(S.current.value=""),C.current&&(C.current.value=""),A(D=>D+1),_(D=>D+1)},[]),H=v.useCallback(D=>{I(q=>{const U=[...q,...D];return g==null||g(U),U})},[g]),W=v.useCallback(D=>{const q=Array.from(D.target.files||[]);H(q),D.target.value=""},[H]),ne=v.useCallback(D=>{I(q=>{const U=q.filter((P,V)=>V!==D);return U.length===0&&re(),g==null||g(U),U})},[g,re]),K=v.useCallback(async D=>{const q=(D.target.files||[])[0];if(q&&(O(null),Y(null),!!m)){F(!0);try{await m(q),O(`Uploaded ${q.name} - processing through chat stream`)}catch(U){const P=U instanceof Error?U.message:"Failed to upload Excel file";Y(P),x==null||x(P)}finally{F(!1),D.target.value="",re()}}},[m,x,re]),M=v.useMemo(()=>y||k.length>0,[y,k]),N=v.useCallback(async D=>{const U=await n(D,k);return k.length>0&&(I([]),g==null||g([]),re()),U},[n,re,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":""} ${w?"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((D,q)=>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:D.name}),d.jsx(Je,{variant:"ghost",size:"sm",onClick:()=>ne(q),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 ${D.name}`,children:d.jsx(xe.X,{size:12})})]},q))})]}),p&&d.jsxs(d.Fragment,{children:[d.jsx("input",{ref:C,type:"file",accept:".xls,.xlsx,.xlsm",onChange:K,className:"hidden"},j),L&&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..."]}),B&&!L&&d.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:B}),G&&!L&&d.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:G})]})]}),d.jsxs("div",{className:"flex items-end gap-2",children:[(h||p)&&d.jsxs(_a,{children:[d.jsx(Pa,{asChild:!0,children:d.jsx(Je,{type:"button",size:"icon",variant:"outline",disabled:c||l,title:"More input actions",className:f.moreButton||"",children:d.jsx(xe.Plus,{size:16})})}),d.jsxs(js,{align:"start",sideOffset:6,className:"w-52",children:[h&&d.jsxs(er,{onClick:()=>{var D;return(D=S.current)==null?void 0:D.click()},className:"cursor-pointer",children:[d.jsx(xe.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),p&&d.jsxs(er,{onClick:()=>{var D;L||(D=C.current)==null||D.click()},className:`cursor-pointer ${L?"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(pS,{initialValue:i,editingMessageId:s,value:e,onValueChange:t,placeholder:s?"Edit your message...":a,isStreaming:c,disabled:l,onSend:N,onCancelEdit:r,onStop:o,allowEmptySend:M,textareaClassName:$,sendButtonClassName:f.sendButton})})]})]})}v.memo(_s);function bh({submit:e,chatRequest:t,lastCheckpointId:n,lastCheckpointNs:r,onMessageSent:o,onExcelUploadSuccess:s,onError:i,enableMessageEditing:a,messages:c,setPendingAssistantResponse:l,project:u,onEvent:f,activeThreadId:h}){const{messages:p}=pi(),[m,g]=v.useState(null),[x,y]=v.useState(""),[w,k]=v.useState(null),[I,S]=v.useState(null),[C,T]=v.useState(!1),[A,j]=v.useState(""),_=v.useRef(A),L=v.useRef(null);v.useEffect(()=>{if(!m)if(h){const K=localStorage.getItem(Po(h));j(K||"")}else j("")},[h,m]);const F=v.useCallback(K=>{j(K),!m&&h&&localStorage.setItem(Po(h),K)},[h,m]);v.useEffect(()=>{_.current=A},[A]),v.useEffect(()=>{if(!m){L.current=null;return}L.current===null&&(L.current=_.current),F(x??"")},[x,m,F]);const B=v.useCallback(K=>{F(K)},[F]),O=async(K,M)=>{const N=Array.isArray(M)?{files:M}:M??{},$=N.files??[],D=N.contentParts??[],q=K.trim();if(!(!q&&$.length===0&&D.length===0))try{const U=$.map(async be=>{try{const Ae=await si.uploadFile(be);return{file:be,record:Ae}}catch(Ae){throw console.error("Failed to upload file",be.name,Ae),new Error(`Failed to upload ${be.name}`)}}),V=(await Promise.all(U)).map(({record:be})=>{const Ae=be.mime_type;return Ae.startsWith("image/")?{type:"image_url",image_url:{url:be.content_url}}:{type:"file",url:be.content_url,mimeType:Ae,name:be.filename,size:be.size}}),ee=[...D,...V],ce=m?(w==null?void 0:w.checkpointId)??n??void 0:n??void 0,ue=m?(w==null?void 0:w.checkpointNs)??r??void 0:r??void 0;await e({text:q||"",contentParts:ee,attachments:[],payload:t.payload},{checkpointId:ce,checkpointNs:ue,project:u??void 0,edit:!!m,originalMessageId:m??void 0,config:t.config,onEvent:f}),o==null||o(q),l(!0),h&&localStorage.removeItem(Po(h)),F(""),S(null),g(null),y(""),k(null)}catch(U){const P=(U==null?void 0:U.message)||"Failed to send message";S(P),i==null||i(P),l(!1)}},G=(K,M)=>{M||O(K,{files:[]})},Y=v.useCallback(async K=>{await e({attachments:[K],payload:t.payload},{checkpointId:n??void 0,checkpointNs:r??void 0,project:u??void 0,config:t.config,onEvent:f}),s==null||s({file:K})},[n,r,t,s,e]),re=v.useCallback((K,M,N)=>{a&&(L.current=A,g(K),y(M),k({checkpointId:(N==null?void 0:N.checkpointId)??null,checkpointNs:(N==null?void 0:N.checkpointNs)??null}),S(null))},[A,a]),H=v.useCallback(()=>{g(null),y(""),k(null),S(null);const K=L.current;K!==null&&j(K),L.current=null},[]),W=v.useCallback(K=>{let M=null;for(let q=K-1;q>=0;q--)if(c[q].role==="user"){M=c[q];break}if(!M)return;const N=Array.isArray(M.content)?M.content:[],D=N.filter(q=>(q==null?void 0:q.type)==="text").map(q=>q.text).join("")||(()=>{try{return JSON.stringify(N,null,2)}catch{return String(N)}})();D&&e({text:D,payload:t.payload},{checkpointId:n??void 0,checkpointNs:r??void 0,edit:!0,originalMessageId:M.id,config:t.config,onEvent:f})},[c,e,n,r,t]);return{editingMessageId:m,editingInitialValue:x,inputError:I,setInputError:S,dismissError:C,setDismissError:T,composerValue:A,handleComposerChange:B,handleSendMessage:O,handleQuickPrompt:G,handleExcelUpload:Y,startEditing:re,cancelEditing:H,handleRegenerateCb:W,displayMessages:p}}var Ps="Dialog",[yh,lT]=Pn(Ps),[mS,Gt]=yh(Ps),wh=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=b.useRef(null),c=b.useRef(null),[l,u]=is({prop:r,defaultProp:o??!1,onChange:s,caller:Ps});return d.jsx(mS,{scope:t,triggerRef:a,contentRef:c,contentId:Rt(),titleId:Rt(),descriptionId:Rt(),open:l,onOpenChange:u,onOpenToggle:b.useCallback(()=>u(f=>!f),[u]),modal:i,children:n})};wh.displayName=Ps;var vh="DialogTrigger",gS=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Gt(vh,n),s=Ye(t,o.triggerRef);return d.jsx(Ne.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Da(o.open),...r,ref:s,onClick:ve(e.onClick,o.onOpenToggle)})});gS.displayName=vh;var Oa="DialogPortal",[xS,Sh]=yh(Oa,{forceMount:void 0}),Ch=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=Gt(Oa,t);return d.jsx(xS,{scope:t,forceMount:n,children:b.Children.map(r,i=>d.jsx(Dt,{present:n||s.open,children:d.jsx(pa,{asChild:!0,container:o,children:i})}))})};Ch.displayName=Oa;var Rs="DialogOverlay",Th=b.forwardRef((e,t)=>{const n=Sh(Rs,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=Gt(Rs,e.__scopeDialog);return s.modal?d.jsx(Dt,{present:r||s.open,children:d.jsx(yS,{...o,ref:t})}):null});Th.displayName=Rs;var bS=cr.createSlot("DialogOverlay.RemoveScroll"),yS=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Gt(Rs,n);return d.jsx(Sa,{as:bS,allowPinchZoom:!0,shards:[o.contentRef],children:d.jsx(Ne.div,{"data-state":Da(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),tr="DialogContent",kh=b.forwardRef((e,t)=>{const n=Sh(tr,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=Gt(tr,e.__scopeDialog);return d.jsx(Dt,{present:r||s.open,children:s.modal?d.jsx(wS,{...o,ref:t}):d.jsx(vS,{...o,ref:t})})});kh.displayName=tr;var wS=b.forwardRef((e,t)=>{const n=Gt(tr,e.__scopeDialog),r=b.useRef(null),o=Ye(t,n.contentRef,r);return b.useEffect(()=>{const s=r.current;if(s)return uf(s)},[]),d.jsx(Eh,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ve(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:ve(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:ve(e.onFocusOutside,s=>s.preventDefault())})}),vS=b.forwardRef((e,t)=>{const n=Gt(tr,e.__scopeDialog),r=b.useRef(!1),o=b.useRef(!1);return d.jsx(Eh,{...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 c,l;(c=e.onInteractOutside)==null||c.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const i=s.target;((l=n.triggerRef.current)==null?void 0:l.contains(i))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),Eh=b.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=Gt(tr,n),c=b.useRef(null),l=Ye(t,c);return gd(),d.jsxs(d.Fragment,{children:[d.jsx(ea,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:d.jsx(Xi,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Da(a.open),...i,ref:l,onDismiss:()=>a.onOpenChange(!1)})}),d.jsxs(d.Fragment,{children:[d.jsx(SS,{titleId:a.titleId}),d.jsx(TS,{contentRef:c,descriptionId:a.descriptionId})]})]})}),Ma="DialogTitle",Ih=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Gt(Ma,n);return d.jsx(Ne.h2,{id:o.titleId,...r,ref:t})});Ih.displayName=Ma;var Ah="DialogDescription",Nh=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Gt(Ah,n);return d.jsx(Ne.p,{id:o.descriptionId,...r,ref:t})});Nh.displayName=Ah;var jh="DialogClose",_h=b.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=Gt(jh,n);return d.jsx(Ne.button,{type:"button",...r,ref:t,onClick:ve(e.onClick,()=>o.onOpenChange(!1))})});_h.displayName=jh;function Da(e){return e?"open":"closed"}var Ph="DialogTitleWarning",[cT,Rh]=oy(Ph,{contentName:tr,titleName:Ma,docsSlug:"dialog"}),SS=({titleId:e})=>{const t=Rh(Ph),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 b.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},CS="DialogDescriptionWarning",TS=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Rh(CS).contentName}}.`;return b.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},Mh=wh,Oh=Ch,La=Th,$a=kh,bo=Ih,Dh=Nh,kS=jh;const Lh=Mh,ES=Oh,$h=b.forwardRef(({className:e,...t},n)=>d.jsx(La,{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}));$h.displayName=La.displayName;const Fa=b.forwardRef(({className:e,children:t,...n},r)=>{const o=b.useMemo(()=>{let s=!1;function i(a){b.Children.forEach(a,c=>{if(s||!b.isValidElement(c))return;const l=c.type;if(l===bo||(l==null?void 0:l.displayName)===bo.displayName||(l==null?void 0:l.name)==="DialogTitle"){s=!0;return}c.props&&c.props.children&&i(c.props.children)})}return i(t),s},[t]);return d.jsxs(ES,{children:[d.jsx($h,{}),d.jsxs($a,{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(bo,{className:"sr-only",children:"Dialog"}),t,d.jsxs(kS,{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"})]})]})]})});Fa.displayName=$a.displayName;const za=({className:e,...t})=>d.jsx("div",{className:he("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});za.displayName="DialogHeader";const Ba=b.forwardRef(({className:e,...t},n)=>d.jsx(bo,{ref:n,className:he("text-lg font-semibold leading-none tracking-tight",e),...t}));Ba.displayName=bo.displayName;const Fh=b.forwardRef(({className:e,...t},n)=>d.jsx(Dh,{ref:n,className:he("text-sm text-muted-foreground",e),...t}));Fh.displayName=Dh.displayName;function IS(e,[t,n]){return Math.min(n,Math.max(t,e))}function AS(e,t){return b.useReducer((n,r)=>t[n][r]??n,e)}var Ua="ScrollArea",[zh,uT]=Pn(Ua),[NS,Ut]=zh(Ua),Bh=b.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,c]=b.useState(null),[l,u]=b.useState(null),[f,h]=b.useState(null),[p,m]=b.useState(null),[g,x]=b.useState(null),[y,w]=b.useState(0),[k,I]=b.useState(0),[S,C]=b.useState(!1),[T,A]=b.useState(!1),j=Je(t,M=>c(M)),P=Gi(o);return d.jsx(NS,{scope:n,type:r,dir:P,scrollHideDelay:s,scrollArea:a,viewport:l,onViewportChange:u,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:m,scrollbarXEnabled:S,onScrollbarXEnabledChange:C,scrollbarY:g,onScrollbarYChange:x,scrollbarYEnabled:T,onScrollbarYEnabledChange:A,onCornerWidthChange:w,onCornerHeightChange:I,children:d.jsx(Ne.div,{dir:P,...i,ref:j,style:{position:"relative","--radix-scroll-area-corner-width":y+"px","--radix-scroll-area-corner-height":k+"px",...e.style}})})});Bh.displayName=Ua;var Uh="ScrollAreaViewport",Hh=b.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=Ut(Uh,n),a=b.useRef(null),c=Je(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(Ne.div,{"data-radix-scroll-area-viewport":"",...s,ref:c,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})})]})});Hh.displayName=Uh;var ln="ScrollAreaScrollbar",Ha=b.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Ut(ln,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return b.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?d.jsx(_S,{...r,ref:t,forceMount:n}):o.type==="scroll"?d.jsx(jS,{...r,ref:t,forceMount:n}):o.type==="auto"?d.jsx(Wh,{...r,ref:t,forceMount:n}):o.type==="always"?d.jsx(Wa,{...r,ref:t}):null});Ha.displayName=ln;var _S=b.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Ut(ln,e.__scopeScrollArea),[s,i]=b.useState(!1);return b.useEffect(()=>{const a=o.scrollArea;let c=0;if(a){const l=()=>{window.clearTimeout(c),i(!0)},u=()=>{c=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",l),a.addEventListener("pointerleave",u),()=>{window.clearTimeout(c),a.removeEventListener("pointerenter",l),a.removeEventListener("pointerleave",u)}}},[o.scrollArea,o.scrollHideDelay]),d.jsx(Dt,{present:n||s,children:d.jsx(Wh,{"data-state":s?"visible":"hidden",...r,ref:t})})}),jS=b.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Ut(ln,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Ls(()=>c("SCROLL_END"),100),[a,c]=AS("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 b.useEffect(()=>{if(a==="idle"){const l=window.setTimeout(()=>c("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(l)}},[a,o.scrollHideDelay,c]),b.useEffect(()=>{const l=o.viewport,u=s?"scrollLeft":"scrollTop";if(l){let f=l[u];const h=()=>{const p=l[u];f!==p&&(c("SCROLL"),i()),f=p};return l.addEventListener("scroll",h),()=>l.removeEventListener("scroll",h)}},[o.viewport,s,c,i]),d.jsx(Dt,{present:n||a!=="hidden",children:d.jsx(Wa,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ve(e.onPointerEnter,()=>c("POINTER_ENTER")),onPointerLeave:ve(e.onPointerLeave,()=>c("POINTER_LEAVE"))})})}),Wh=b.forwardRef((e,t)=>{const n=Ut(ln,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=b.useState(!1),a=e.orientation==="horizontal",c=Ls(()=>{if(n.viewport){const l=n.viewport.offsetWidth<n.viewport.scrollWidth,u=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?l:u)}},10);return _r(n.viewport,c),_r(n.content,c),d.jsx(Dt,{present:r||s,children:d.jsx(Wa,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Wa=b.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=Ut(ln,e.__scopeScrollArea),s=b.useRef(null),i=b.useRef(0),[a,c]=b.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),l=Yh(a.viewport,a.content),u={...r,sizes:a,onSizesChange:c,hasThumb:l>0&&l<1,onThumbChange:h=>s.current=h,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:h=>i.current=h};function f(h,p){return LS(h,i.current,a,p)}return n==="horizontal"?d.jsx(PS,{...u,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=Xh(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(RS,{...u,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=Xh(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}),PS=b.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Ut(ln,e.__scopeScrollArea),[i,a]=b.useState(),c=b.useRef(null),l=Je(t,c,s.onScrollbarXChange);return b.useEffect(()=>{c.current&&a(getComputedStyle(c.current))},[c]),d.jsx(Kh,{"data-orientation":"horizontal",...o,ref:l,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":Ds(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),Zh(h,f)&&u.preventDefault()}},onResize:()=>{c.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:c.current.clientWidth,paddingStart:Os(i.paddingLeft),paddingEnd:Os(i.paddingRight)}})}})}),RS=b.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Ut(ln,e.__scopeScrollArea),[i,a]=b.useState(),c=b.useRef(null),l=Je(t,c,s.onScrollbarYChange);return b.useEffect(()=>{c.current&&a(getComputedStyle(c.current))},[c]),d.jsx(Kh,{"data-orientation":"vertical",...o,ref:l,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":Ds(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),Zh(h,f)&&u.preventDefault()}},onResize:()=>{c.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:c.current.clientHeight,paddingStart:Os(i.paddingTop),paddingEnd:Os(i.paddingBottom)}})}})}),[MS,Vh]=zh(ln),Kh=b.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:c,onDragScroll:l,onWheelScroll:u,onResize:f,...h}=e,p=Ut(ln,n),[m,g]=b.useState(null),x=Je(t,j=>g(j)),y=b.useRef(null),w=b.useRef(""),k=p.viewport,I=r.content-r.viewport,S=yt(u),C=yt(c),T=Ls(f,10);function A(j){if(y.current){const P=j.clientX-y.current.left,M=j.clientY-y.current.top;l({x:P,y:M})}}return b.useEffect(()=>{const j=P=>{const M=P.target;(m==null?void 0:m.contains(M))&&S(P,I)};return document.addEventListener("wheel",j,{passive:!1}),()=>document.removeEventListener("wheel",j,{passive:!1})},[k,m,I,S]),b.useEffect(C,[r,C]),_r(m,T),_r(p.content,T),d.jsx(MS,{scope:n,scrollbar:m,hasThumb:o,onThumbChange:yt(s),onThumbPointerUp:yt(i),onThumbPositionChange:C,onThumbPointerDown:yt(a),children:d.jsx(Ne.div,{...h,ref:x,style:{position:"absolute",...h.style},onPointerDown:ve(e.onPointerDown,j=>{j.button===0&&(j.target.setPointerCapture(j.pointerId),y.current=m.getBoundingClientRect(),w.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),A(j))}),onPointerMove:ve(e.onPointerMove,A),onPointerUp:ve(e.onPointerUp,j=>{const P=j.target;P.hasPointerCapture(j.pointerId)&&P.releasePointerCapture(j.pointerId),document.body.style.webkitUserSelect=w.current,p.viewport&&(p.viewport.style.scrollBehavior=""),y.current=null})})})}),Ms="ScrollAreaThumb",qh=b.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Vh(Ms,e.__scopeScrollArea);return d.jsx(Dt,{present:n||o.hasThumb,children:d.jsx(OS,{ref:t,...r})})}),OS=b.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=Ut(Ms,n),i=Vh(Ms,n),{onThumbPositionChange:a}=i,c=Je(t,f=>i.onThumbChange(f)),l=b.useRef(void 0),u=Ls(()=>{l.current&&(l.current(),l.current=void 0)},100);return b.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(u(),!l.current){const p=$S(f,a);l.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,u,a]),d.jsx(Ne.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:c,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:ve(e.onPointerDownCapture,f=>{const p=f.target.getBoundingClientRect(),m=f.clientX-p.left,g=f.clientY-p.top;i.onThumbPointerDown({x:m,y:g})}),onPointerUp:ve(e.onPointerUp,i.onThumbPointerUp)})});qh.displayName=Ms;var Va="ScrollAreaCorner",Gh=b.forwardRef((e,t)=>{const n=Ut(Va,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?d.jsx(DS,{...e,ref:t}):null});Gh.displayName=Va;var DS=b.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=Ut(Va,n),[s,i]=b.useState(0),[a,c]=b.useState(0),l=!!(s&&a);return _r(o.scrollbarX,()=>{var f;const u=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(u),c(u)}),_r(o.scrollbarY,()=>{var f;const u=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(u),i(u)}),l?d.jsx(Ne.div,{...r,ref:t,style:{width:s,height:a,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function Os(e){return e?parseInt(e,10):0}function Yh(e,t){const n=e/t;return isNaN(n)?0:n}function Ds(e){const t=Yh(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function LS(e,t,n,r="ltr"){const o=Ds(n),s=o/2,i=t||s,a=o-i,c=n.scrollbar.paddingStart+i,l=n.scrollbar.size-n.scrollbar.paddingEnd-a,u=n.content-n.viewport,f=r==="ltr"?[0,u]:[u*-1,0];return Jh([c,l],f)(e)}function Xh(e,t,n="ltr"){const r=Ds(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,c=n==="ltr"?[0,i]:[i*-1,0],l=IS(e,c);return Jh([0,i],[0,a])(l)}function Jh(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 Zh(e,t){return e>0&&e<t}var $S=(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 Ls(e,t){const n=yt(e),r=b.useRef(0);return b.useEffect(()=>()=>window.clearTimeout(r.current),[]),b.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function _r(e,t){const n=yt(t);tn(()=>{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 Qh=Bh,FS=Hh,zS=Gh;const Ka=b.forwardRef(({className:e,children:t,...n},r)=>d.jsxs(Qh,{ref:r,className:he("relative overflow-hidden",e),...n,children:[d.jsx(FS,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),d.jsx(ep,{}),d.jsx(zS,{})]}));Ka.displayName=Qh.displayName;const ep=b.forwardRef(({className:e,orientation:t="vertical",...n},r)=>d.jsx(Ha,{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(qh,{className:"relative flex-1 rounded-full bg-border"})}));ep.displayName=Ha.displayName;function BS({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(Lh,{open:e,onOpenChange:t,children:d.jsxs(Fa,{className:"max-w-2xl max-h-[85vh] flex flex-col p-0 gap-0 overflow-hidden",children:[d.jsxs(za,{className:"p-6 border-b shrink-0",children:[d.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[d.jsxs(Ba,{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(Fh,{children:["ID: ",r.id]})]}),d.jsx(Ka,{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:c=!0,toolConfig:l,toolRenderers:u,toolArtifactRenderers:f,payloadExtras:h={},customStyles:p={},messageCustomStyles:m,onMessageSent:g,onExcelUploadSuccess:x,onError:y,renderArtifactsInline:w=!0,emptyMessage:k}){var ee,_,B;const{currentThreadId:I}=Vr(),S=qr(),C=pi(),T=bh({submit:C.submit,chatRequest:{payload:h},lastCheckpointId:((ee=S.checkpoint)==null?void 0:ee.id)??null,lastCheckpointNs:((_=S.checkpoint)==null?void 0:_.namespace)??null,onMessageSent:g,onExcelUploadSuccess:x,onError:y,enableMessageEditing:a,messages:S.messages,setPendingAssistantResponse:()=>{},activeThreadId:I??null}),A=S.interrupt,j=A?hc(A.id):null,P=j!==null?{type:"interrupt",id:j}:null,[M,F]=v.useState(!1),[U,L]=v.useState("desktop"),[K,q]=v.useState(!1),[re,W]=v.useState(null),V=v.useRef(null);v.useEffect(()=>{const X=()=>{const le=window.innerWidth;L(le<640?"phone":le<1024?"tablet":"desktop")};return X(),window.addEventListener("resize",X),()=>window.removeEventListener("resize",X)},[]);const ne=v.useCallback(async(X,le,me)=>{try{F(!0),await S.respondToInterrupt(X,le,me)}catch(be){console.error("Failed to respond to interrupt:",be)}finally{F(!1)}},[S]),H=v.useCallback(async X=>{var le,me;q(!0);try{if(!X)await S.returnToLatest(),(le=V.current)==null||le.scrollToLatest();else{const be=S.checkpoints.find(Te=>Te.checkpointId===X);await S.navigateToCheckpoint(X,(be==null?void 0:be.checkpointNs)??null),(me=V.current)==null||me.scrollToTop()}}finally{q(!1)}},[S]),O=v.useMemo(()=>l??{toolRenderers:u,toolArtifactRenderers:f,getToolExpandable:X=>X.name!=="ask_user_choice"},[l,u,f]),N=!!A||M,$=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${p.container||""}`,D=`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(Qe,{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 ${D}`,style:n?{maxHeight:n}:void 0,children:[d.jsx(Ic,{layoutSize:U,customStyles:p,messageCustomStyles:m,renderArtifactsInline:w,enableMessageEditing:a,editingMessageId:T.editingMessageId,showToolMessages:c,followNewMessages:o,showThinkingIndicator:C.isStreaming,streamingDebounceMs:r,toolConfig:O,checkpointIndex:S.checkpointIndex,activeCheckpointId:(B=S.checkpoint)==null?void 0:B.id,onSelectCheckpoint:H,pendingInterrupt:A,onEdit:T.startEditing,onRegenerate:T.handleRegenerateCb,onCancelEdit:T.cancelEditing,getInterruptOptions:()=>{},selectedToolCall:re,onSelectToolCall:W,children:d.jsx(ss,{ref:V,className:"h-full",style:{height:"100%"},messages:T.displayMessages??S.messages,isStreaming:C.isStreaming,emptyMessage:k})}),d.jsx(BS,{isOpen:!!re,onOpenChange:X=>!X&&W(null),toolCall:re}),(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||K?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,A&&P&&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(qu,{interruptPart:P,onApprove:()=>ne(!0),onReject:()=>ne(!1),onSelectAlternative:(X,le)=>ne(!0,le),disabled:M,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(xe.Edit3,{size:16,className:"text-blue-600"}),d.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),d.jsx(Qe,{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(js,{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:N,enableFileUpload:s,enableExcelUpload:i,onExcelUpload:T.handleExcelUpload,onError:y,customStyles:p,textareaClassName:p.textarea||"",allowEmptySend:!1,inputError:T.inputError})]})]})}var tp=1,US=.9,HS=.8,WS=.17,qa=.1,Ga=.999,VS=.9999,KS=.99,qS=/[\\\/_+.#"@\[\(\{&]/,GS=/[\\\/_+.#"@\[\(\{&]/g,YS=/[\s-]/,np=/[\s-]/g;function Ya(e,t,n,r,o,s,i){if(s===t.length)return o===e.length?tp:KS;var a=`${o},${s}`;if(i[a]!==void 0)return i[a];for(var c=r.charAt(s),l=n.indexOf(c,o),u=0,f,h,p,m;l>=0;)f=Ya(e,t,n,r,l+1,s+1,i),f>u&&(l===o?f*=tp:qS.test(e.charAt(l-1))?(f*=HS,p=e.slice(o,l-1).match(GS),p&&o>0&&(f*=Math.pow(Ga,p.length))):YS.test(e.charAt(l-1))?(f*=US,m=e.slice(o,l-1).match(np),m&&o>0&&(f*=Math.pow(Ga,m.length))):(f*=WS,o>0&&(f*=Math.pow(Ga,l-o))),e.charAt(l)!==t.charAt(s)&&(f*=VS)),(f<qa&&n.charAt(l-1)===r.charAt(s+1)||r.charAt(s+1)===r.charAt(s)&&n.charAt(l-1)!==r.charAt(s))&&(h=Ya(e,t,n,r,l+1,s+2,i),h*qa>f&&(f=h*qa)),f>u&&(u=f),l=n.indexOf(c,l+1);return i[a]=u,u}function rp(e){return e.toLowerCase().replace(np," ")}function XS(e,t,n){return e=n&&n.length>0?`${e+" "+n.join(" ")}`:e,Ya(e,t,rp(e),rp(t),0,0,{})}var yo='[cmdk-group=""]',Xa='[cmdk-group-items=""]',JS='[cmdk-group-heading=""]',op='[cmdk-item=""]',sp=`${op}:not([aria-disabled="true"])`,Ja="cmdk-item-select",Pr="data-value",ZS=(e,t,n)=>XS(e,t,n),ip=b.createContext(void 0),wo=()=>b.useContext(ip),ap=b.createContext(void 0),Za=()=>b.useContext(ap),lp=b.createContext(void 0),cp=b.forwardRef((e,t)=>{let n=Rr(()=>{var O,N;return{search:"",value:(N=(O=e.value)!=null?O:e.defaultValue)!=null?N:"",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=up(e),{label:c,children:l,value:u,onValueChange:f,filter:h,shouldFilter:p,loop:m,disablePointerSelection:g=!1,vimBindings:x=!0,...y}=e,w=Rt(),k=Rt(),I=Rt(),S=b.useRef(null),C=cC();nr(()=>{if(u!==void 0){let O=u.trim();n.current.value=O,T.emit()}},[u]),nr(()=>{C(6,U)},[]);let T=b.useMemo(()=>({subscribe:O=>(i.current.add(O),()=>i.current.delete(O)),snapshot:()=>n.current,setState:(O,N,$)=>{var D,G,ee,_;if(!Object.is(n.current[O],N)){if(n.current[O]=N,O==="search")F(),P(),C(1,M);else if(O==="value"){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let B=document.getElementById(I);B?B.focus():(D=document.getElementById(w))==null||D.focus()}if(C(7,()=>{var B;n.current.selectedItemId=(B=L())==null?void 0:B.id,T.emit()}),$||C(5,U),((G=a.current)==null?void 0:G.value)!==void 0){let B=N??"";(_=(ee=a.current).onValueChange)==null||_.call(ee,B);return}}T.emit()}},emit:()=>{i.current.forEach(O=>O())}}),[]),A=b.useMemo(()=>({value:(O,N,$)=>{var D;N!==((D=s.current.get(O))==null?void 0:D.value)&&(s.current.set(O,{value:N,keywords:$}),n.current.filtered.items.set(O,j(N,$)),C(2,()=>{P(),T.emit()}))},item:(O,N)=>(r.current.add(O),N&&(o.current.has(N)?o.current.get(N).add(O):o.current.set(N,new Set([O]))),C(3,()=>{F(),P(),n.current.value||M(),T.emit()}),()=>{s.current.delete(O),r.current.delete(O),n.current.filtered.items.delete(O);let $=L();C(4,()=>{F(),($==null?void 0:$.getAttribute("id"))===O&&M(),T.emit()})}),group:O=>(o.current.has(O)||o.current.set(O,new Set),()=>{s.current.delete(O),o.current.delete(O)}),filter:()=>a.current.shouldFilter,label:c||e["aria-label"],getDisablePointerSelection:()=>a.current.disablePointerSelection,listId:w,inputId:I,labelId:k,listInnerRef:S}),[]);function j(O,N){var $,D;let G=(D=($=a.current)==null?void 0:$.filter)!=null?D:ZS;return O?G(O,n.current.search,N):0}function P(){if(!n.current.search||a.current.shouldFilter===!1)return;let O=n.current.filtered.items,N=[];n.current.filtered.groups.forEach(D=>{let G=o.current.get(D),ee=0;G.forEach(_=>{let B=O.get(_);ee=Math.max(B,ee)}),N.push([D,ee])});let $=S.current;K().sort((D,G)=>{var ee,_;let B=D.getAttribute("id"),X=G.getAttribute("id");return((ee=O.get(X))!=null?ee:0)-((_=O.get(B))!=null?_:0)}).forEach(D=>{let G=D.closest(Xa);G?G.appendChild(D.parentElement===G?D:D.closest(`${Xa} > *`)):$.appendChild(D.parentElement===$?D:D.closest(`${Xa} > *`))}),N.sort((D,G)=>G[1]-D[1]).forEach(D=>{var G;let ee=(G=S.current)==null?void 0:G.querySelector(`${yo}[${Pr}="${encodeURIComponent(D[0])}"]`);ee==null||ee.parentElement.appendChild(ee)})}function M(){let O=K().find($=>$.getAttribute("aria-disabled")!=="true"),N=O==null?void 0:O.getAttribute(Pr);T.setState("value",N||void 0)}function F(){var O,N,$,D;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 ee of r.current){let _=(N=(O=s.current.get(ee))==null?void 0:O.value)!=null?N:"",B=(D=($=s.current.get(ee))==null?void 0:$.keywords)!=null?D:[],X=j(_,B);n.current.filtered.items.set(ee,X),X>0&&G++}for(let[ee,_]of o.current)for(let B of _)if(n.current.filtered.items.get(B)>0){n.current.filtered.groups.add(ee);break}n.current.filtered.count=G}function U(){var O,N,$;let D=L();D&&(((O=D.parentElement)==null?void 0:O.firstChild)===D&&(($=(N=D.closest(yo))==null?void 0:N.querySelector(JS))==null||$.scrollIntoView({block:"nearest"})),D.scrollIntoView({block:"nearest"}))}function L(){var O;return(O=S.current)==null?void 0:O.querySelector(`${op}[aria-selected="true"]`)}function K(){var O;return Array.from(((O=S.current)==null?void 0:O.querySelectorAll(sp))||[])}function q(O){let N=K()[O];N&&T.setState("value",N.getAttribute(Pr))}function re(O){var N;let $=L(),D=K(),G=D.findIndex(_=>_===$),ee=D[G+O];(N=a.current)!=null&&N.loop&&(ee=G+O<0?D[D.length-1]:G+O===D.length?D[0]:D[G+O]),ee&&T.setState("value",ee.getAttribute(Pr))}function W(O){let N=L(),$=N==null?void 0:N.closest(yo),D;for(;$&&!D;)$=O>0?aC($,yo):lC($,yo),D=$==null?void 0:$.querySelector(sp);D?T.setState("value",D.getAttribute(Pr)):re(O)}let V=()=>q(K().length-1),ne=O=>{O.preventDefault(),O.metaKey?V():O.altKey?W(1):re(1)},H=O=>{O.preventDefault(),O.metaKey?q(0):O.altKey?W(-1):re(-1)};return b.createElement(Ne.div,{ref:t,tabIndex:-1,...y,"cmdk-root":"",onKeyDown:O=>{var N;(N=y.onKeyDown)==null||N.call(y,O);let $=O.nativeEvent.isComposing||O.keyCode===229;if(!(O.defaultPrevented||$))switch(O.key){case"n":case"j":{x&&O.ctrlKey&&ne(O);break}case"ArrowDown":{ne(O);break}case"p":case"k":{x&&O.ctrlKey&&H(O);break}case"ArrowUp":{H(O);break}case"Home":{O.preventDefault(),q(0);break}case"End":{O.preventDefault(),V();break}case"Enter":{O.preventDefault();let D=L();if(D){let G=new Event(Ja);D.dispatchEvent(G)}}}}},b.createElement("label",{"cmdk-label":"",htmlFor:A.inputId,id:A.labelId,style:dC},c),$s(e,O=>b.createElement(ap.Provider,{value:T},b.createElement(ip.Provider,{value:A},O))))}),QS=b.forwardRef((e,t)=>{var n,r;let o=Rt(),s=b.useRef(null),i=b.useContext(lp),a=wo(),c=up(e),l=(r=(n=c.current)==null?void 0:n.forceMount)!=null?r:i==null?void 0:i.forceMount;nr(()=>{if(!l)return a.item(o,i==null?void 0:i.id)},[l]);let u=dp(o,s,[e.value,e.children,s],e.keywords),f=Za(),h=Dn(C=>C.value&&C.value===u.current),p=Dn(C=>l||a.filter()===!1?!0:C.search?C.filtered.items.get(o)>0:!0);b.useEffect(()=>{let C=s.current;if(!(!C||e.disabled))return C.addEventListener(Ja,m),()=>C.removeEventListener(Ja,m)},[p,e.onSelect,e.disabled]);function m(){var C,T;g(),(T=(C=c.current).onSelect)==null||T.call(C,u.current)}function g(){f.setState("value",u.current,!0)}if(!p)return null;let{disabled:x,value:y,onSelect:w,forceMount:k,keywords:I,...S}=e;return b.createElement(Ne.div,{ref:jn(s,t),...S,id:o,"cmdk-item":"",role:"option","aria-disabled":!!x,"aria-selected":!!h,"data-disabled":!!x,"data-selected":!!h,onPointerMove:x||a.getDisablePointerSelection()?void 0:g,onClick:x?void 0:m},e.children)}),eC=b.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:o,...s}=e,i=Rt(),a=b.useRef(null),c=b.useRef(null),l=Rt(),u=wo(),f=Dn(p=>o||u.filter()===!1?!0:p.search?p.filtered.groups.has(i):!0);nr(()=>u.group(i),[]),dp(i,a,[e.value,e.heading,c]);let h=b.useMemo(()=>({id:i,forceMount:o}),[o]);return b.createElement(Ne.div,{ref:jn(a,t),...s,"cmdk-group":"",role:"presentation",hidden:f?void 0:!0},n&&b.createElement("div",{ref:c,"cmdk-group-heading":"","aria-hidden":!0,id:l},n),$s(e,p=>b.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?l:void 0},b.createElement(lp.Provider,{value:h},p))))}),tC=b.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,o=b.useRef(null),s=Dn(i=>!i.search);return!n&&!s?null:b.createElement(Ne.div,{ref:jn(o,t),...r,"cmdk-separator":"",role:"separator"})}),nC=b.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,o=e.value!=null,s=Za(),i=Dn(l=>l.search),a=Dn(l=>l.selectedItemId),c=wo();return b.useEffect(()=>{e.value!=null&&s.setState("search",e.value)},[e.value]),b.createElement(Ne.input,{ref:t,...r,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":c.listId,"aria-labelledby":c.labelId,"aria-activedescendant":a,id:c.inputId,type:"text",value:o?e.value:i,onChange:l=>{o||s.setState("search",l.target.value),n==null||n(l.target.value)}})}),rC=b.forwardRef((e,t)=>{let{children:n,label:r="Suggestions",...o}=e,s=b.useRef(null),i=b.useRef(null),a=Dn(l=>l.selectedItemId),c=wo();return b.useEffect(()=>{if(i.current&&s.current){let l=i.current,u=s.current,f,h=new ResizeObserver(()=>{f=requestAnimationFrame(()=>{let p=l.offsetHeight;u.style.setProperty("--cmdk-list-height",p.toFixed(1)+"px")})});return h.observe(l),()=>{cancelAnimationFrame(f),h.unobserve(l)}}},[]),b.createElement(Ne.div,{ref:jn(s,t),...o,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":a,"aria-label":r,id:c.listId},$s(e,l=>b.createElement("div",{ref:jn(i,c.listInnerRef),"cmdk-list-sizer":""},l)))}),oC=b.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:o,contentClassName:s,container:i,...a}=e;return b.createElement(Mh,{open:n,onOpenChange:r},b.createElement(Oh,{container:i},b.createElement(La,{"cmdk-overlay":"",className:o}),b.createElement($a,{"aria-label":e.label,"cmdk-dialog":"",className:s},b.createElement(cp,{ref:t,...a}))))}),sC=b.forwardRef((e,t)=>Dn(n=>n.filtered.count===0)?b.createElement(Ne.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),iC=b.forwardRef((e,t)=>{let{progress:n,children:r,label:o="Loading...",...s}=e;return b.createElement(Ne.div,{ref:t,...s,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":o},$s(e,i=>b.createElement("div",{"aria-hidden":!0},i)))}),_t=Object.assign(cp,{List:rC,Item:QS,Input:nC,Group:eC,Separator:tC,Dialog:oC,Empty:sC,Loading:iC});function aC(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function lC(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function up(e){let t=b.useRef(e);return nr(()=>{t.current=e}),t}var nr=typeof window>"u"?b.useEffect:b.useLayoutEffect;function Rr(e){let t=b.useRef();return t.current===void 0&&(t.current=e()),t}function Dn(e){let t=Za(),n=()=>e(t.snapshot());return b.useSyncExternalStore(t.subscribe,n,n)}function dp(e,t,n,r=[]){let o=b.useRef(),s=wo();return nr(()=>{var i;let a=(()=>{var l;for(let u of n){if(typeof u=="string")return u.trim();if(typeof u=="object"&&"current"in u)return u.current?(l=u.current.textContent)==null?void 0:l.trim():o.current}})(),c=r.map(l=>l.trim());s.value(e,a,c),(i=t.current)==null||i.setAttribute(Pr,a),o.current=a}),o}var cC=()=>{let[e,t]=b.useState(),n=Rr(()=>new Map);return nr(()=>{n.current.forEach(r=>r()),n.current=new Map},[e]),(r,o)=>{n.current.set(r,o),t({})}};function uC(e){let t=e.type;return typeof t=="function"?t(e.props):"render"in t?t.render(e.props):e}function $s({asChild:e,children:t},n){return e&&b.isValidElement(t)?b.cloneElement(uC(t),{ref:t.ref},n(t.props.children)):n(t)}var dC={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};const fp=b.forwardRef(({className:e,...t},n)=>d.jsx(_t,{ref:n,className:he("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",e),...t}));fp.displayName=_t.displayName;const hp=b.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(_t.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})]}));hp.displayName=_t.Input.displayName;const pp=b.forwardRef(({className:e,...t},n)=>d.jsx(_t.List,{ref:n,className:he("max-h-[300px] overflow-y-auto overflow-x-hidden",e),...t}));pp.displayName=_t.List.displayName;const mp=b.forwardRef((e,t)=>d.jsx(_t.Empty,{ref:t,className:"py-6 text-center text-sm",...e}));mp.displayName=_t.Empty.displayName;const gp=b.forwardRef(({className:e,...t},n)=>d.jsx(_t.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}));gp.displayName=_t.Group.displayName;const fC=b.forwardRef(({className:e,...t},n)=>d.jsx(_t.Separator,{ref:n,className:he("-mx-1 h-px bg-border",e),...t}));fC.displayName=_t.Separator.displayName;const xp=b.forwardRef(({className:e,...t},n)=>d.jsx(_t.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}));xp.displayName=_t.Item.displayName;function bp({thread:e,isActive:t=!1,editingThreadId:n,editingTitle:r="",onSelect:o,onStartEditing:s,onEditingTitleChange:i,onSaveEditing:a,onCancelEditing:c,onShare:l,onDelete:u,showEditTitle:f=!0,showDeleteButton:h=!0,onMenuOpenChange:p,onMenuAction:m,formatDate:g,getDisplayThreadTitle:x,itemClassName:y,activeItemClassName:w,secondaryLine:k}){const I=n===e.threadId,S=v.useMemo(()=>(x==null?void 0:x(e))??e.title??e.threadId,[x,e]),C=()=>o==null?void 0:o(e.threadId),T=A=>s==null?void 0:s(e,A);return d.jsxs("div",{className:he("flex items-center justify-between rounded px-2 py-1 text-sm hover:bg-muted cursor-pointer",y,t&&(w??"bg-muted/70")),onClick:C,children:[d.jsxs("div",{className:"flex flex-col min-w-0",children:[I?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}),g&&e.updatedAt&&d.jsx("span",{className:"text-[10px] text-muted-foreground",children:g(e.updatedAt)})]}),d.jsx("div",{className:"flex items-center gap-1",children:I?d.jsxs("div",{className:"flex items-center gap-1",children:[d.jsx(Qe,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs",onClick:A=>{A.stopPropagation(),a==null||a(e)},children:"Save"}),d.jsx(Qe,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs",onClick:A=>{A.stopPropagation(),c==null||c(e)},children:"Cancel"})]}):d.jsxs(ja,{onOpenChange:A=>p==null?void 0:p(e.threadId,A),children:[d.jsx(Pa,{asChild:!0,children:d.jsxs(Qe,{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(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(er,{onClick:A=>{A.stopPropagation(),m==null||m(e.threadId,"rename"),T(A)},children:[d.jsx(xe.Edit3,{className:"mr-2 h-4 w-4"}),d.jsx("span",{children:"Rename"})]}),l&&d.jsxs(er,{onClick:A=>{A.stopPropagation(),m==null||m(e.threadId,"share"),l(e)},children:[d.jsx(xe.Share2,{className:"mr-2 h-4 w-4"}),d.jsx("span",{children:"Share"})]}),h&&d.jsxs(er,{onClick:A=>{A.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 Fs="Collapsible",[hC,dT]=Pn(Fs),[pC,Qa]=hC(Fs),yp=b.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[c,l]=is({prop:r,defaultProp:o??!1,onChange:i,caller:Fs});return d.jsx(pC,{scope:n,disabled:s,contentId:Rt(),open:c,onOpenToggle:b.useCallback(()=>l(u=>!u),[l]),children:d.jsx(Ne.div,{"data-state":tl(c),"data-disabled":s?"":void 0,...a,ref:t})})});yp.displayName=Fs;var wp="CollapsibleTrigger",vp=b.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=Qa(wp,n);return d.jsx(Ne.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":tl(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:ve(e.onClick,o.onOpenToggle)})});vp.displayName=wp;var el="CollapsibleContent",Sp=b.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Qa(el,e.__scopeCollapsible);return d.jsx(Dt,{present:n||o.open,children:({present:s})=>d.jsx(mC,{...r,ref:t,present:s})})});Sp.displayName=el;var mC=b.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=Qa(el,n),[a,c]=b.useState(r),l=b.useRef(null),u=Je(t,l),f=b.useRef(0),h=f.current,p=b.useRef(0),m=p.current,g=i.open||a,x=b.useRef(g),y=b.useRef(void 0);return b.useEffect(()=>{const w=requestAnimationFrame(()=>x.current=!1);return()=>cancelAnimationFrame(w)},[]),tn(()=>{const w=l.current;if(w){y.current=y.current||{transitionDuration:w.style.transitionDuration,animationName:w.style.animationName},w.style.transitionDuration="0s",w.style.animationName="none";const k=w.getBoundingClientRect();f.current=k.height,p.current=k.width,x.current||(w.style.transitionDuration=y.current.transitionDuration,w.style.animationName=y.current.animationName),c(r)}},[i.open,r]),d.jsx(Ne.div,{"data-state":tl(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!g,...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:g&&o})});function tl(e){return e?"open":"closed"}var gC=yp;const xC=gC,bC=vp,yC=Sp,Cp=25,Tp=vn.threadManagerView,wC=e=>e==="default"||e==="shared",vC=()=>{if(typeof window>"u")return null;try{const e=window.localStorage.getItem(Tp);if(wC(e))return e}catch{}return null};function kp({defaultView:e}={}){const[t,n]=v.useState(()=>vC()??e??"default");v.useEffect(()=>{if(!(typeof window>"u"))try{window.localStorage.setItem(Tp,t)}catch{}},[t]);const r=v.useCallback(o=>{n(o)},[]);return{view:t,setView:r}}const SC=[{key:"default",label:"My chats"},{key:"shared",label:"Shared with you"}];function zs({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,onItemMenuOpenChange:o,onItemMenuAction:s,maxHeight:i="400px",customStyles:a={},currentThreadId:c=null,navigateToThread:l,onThreadSelect:u,onThreadCreate:f,onThreadDelete:h,view:p,defaultView:m,onViewChange:g,viewOptions:x,viewState:y,showHeader:w=!0,shareTargets:k,isLoadingShareTargets:I,shareTargetFilter:S,groupBy:C,filter:T}){const{chatApi:A,authApi:j}=hr(),{threads:P,sharedThreads:M,currentThreadId:F,setCurrentThreadId:U,isLoading:L,isLoadingSharedThreads:K,actions:q,shareInFlight:re,shareStatus:W,clearShareStatus:V}=Vr(),{createThread:ne,deleteThread:H,renameThread:O,shareThread:N}=q,{loadThread:$}=qr(),D=c??F,[G,ee]=v.useState(Array.isArray(P)?P:[]),_=v.useRef(G.length>0),B=v.useRef(null),X=v.useRef(0),[le,me]=v.useState(null),[be,Te]=v.useState(""),[Ae,ze]=v.useState(!1),[Ze,Ye]=v.useState(!1),[Ve,dt]=v.useState(null),[lt,nt]=v.useState(""),[it,ct]=v.useState([]),[Ke,$e]=v.useState(!1),je=v.useCallback(R=>Te(R),[]);v.useEffect(()=>{Ze&&!k&&it.length===0&&!Ke&&(async()=>{$e(!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}));ct(se)}catch(Y){console.error("Failed to load users for sharing:",Y)}finally{$e(!1)}})()},[Ze,k,it.length,Ke,A]);const rt=k??it,ut=I??Ke,Tt=x&&x.length>0?x:SC,We=kp({defaultView:m}),ft=y??We,rr=p??ft.view,Yt=v.useCallback(R=>{p||ft.setView(R),g==null||g(R)},[p,g,ft]),Ln=Tt.find(R=>R.key===rr)??Tt[0],Xt=R=>{dt(R),nt(""),Ye(!0)},Lt=()=>{Ye(!1),dt(null),nt(""),V()},xn=v.useCallback(async R=>{if(!(!Ve||re)&&R.id)try{await N(Ve,R.id),setTimeout(()=>Lt(),600)}catch(Y){console.error("Failed to share thread:",Y)}},[Lt,re,Ve,N]),or=v.useMemo(()=>{const R=rt,Y=lt.trim().toLowerCase();return Y?S?R.filter(se=>S(se,Y)):R.filter(se=>`${se.label} ${se.secondaryLabel??""}`.toLowerCase().includes(Y)):R},[k,lt,S]),ht=rr==="shared",$n=ht?M:G,cn=T?$n.filter(T):$n,Be=v.useMemo(()=>{const R=Array.isArray(C)?C:[];if(R.length===0||ht)return null;const Y="Default",se=de=>{if(!de)return"Older";try{const Re=de.endsWith("Z")||de.includes("+")?de:`${de}Z`,Pe=new Date(Re),Fe=new Date,pt=new Date(Fe.getFullYear(),Fe.getMonth(),Fe.getDate()),fn=new Date(Pe.getFullYear(),Pe.getMonth(),Pe.getDate()),lr=Math.floor((pt.getTime()-fn.getTime())/(1e3*60*60*24));return lr===0?"Today":lr===1?"Yesterday":lr<=7?"Last 7 Days":"Older"}catch{return"Older"}},ie=(de,Re)=>{var Fe,pt;if(Re==="project")return((Fe=de.project)==null?void 0:Fe.name)||((pt=de.project)==null?void 0:pt.id)||Y;if(Re==="menuItem")return de.menuItem||Y;if(Re==="updatedAt"||Re==="createdAt"){const fn=Re==="updatedAt"?de.updatedAt:de.createdAt;return se(fn)}const Pe=de[Re];return typeof Pe=="string"?Pe||Y:typeof Pe=="number"?String(Pe):Pe==null?Y:String(Pe)},ue=(de,Re)=>{const Pe={};return de.forEach(Fe=>{const pt=ie(Fe,Re);Pe[pt]||(Pe[pt]=[]),Pe[pt].push(Fe)}),Pe},Me=(de,Re)=>{if(Re.length===0)return de;const[Pe,...Fe]=Re,pt=ue(de,Pe);if(Fe.length===0)return pt;const fn={};return Object.entries(pt).forEach(([lr,OC])=>{fn[lr]=Me(OC,Fe)}),fn},Oe=de=>{if(Array.isArray(de)){de.sort((Re,Pe)=>new Date(Pe.updatedAt||Pe.createdAt||"").getTime()-new Date(Re.updatedAt||Re.createdAt||"").getTime());return}Object.values(de).forEach(Oe)},Ee=Me(cn,R);return Oe(Ee),{kind:"nested",groups:Ee}},[cn,C,ht]),ot=ht?K:L,bn=ht?"No shared conversations yet":"No conversations yet",yn=R=>{const Y=R.sharedAt?` • ${wn(R.sharedAt)}`:"";return`Shared by ${R.sharedByUserId}${Y}`},un=R=>"sharedByUserId"in R;v.useEffect(()=>{const R=Array.isArray(P)?P:[];if(R.length>0){_.current=!0,ee(R);return}L||(_.current=!1,ee(R))},[P,L]),v.useEffect(()=>{if(!B.current)return;const R=B.current.querySelector("[data-radix-scroll-area-viewport]");if(!R)return;let Y=null,se=null;return Y=requestAnimationFrame(()=>{se=requestAnimationFrame(()=>{R.scrollTop=X.current})}),()=>{Y!==null&&cancelAnimationFrame(Y),se!==null&&cancelAnimationFrame(se)}},[G]);const dn=async R=>{try{U(R),await $(R),l==null||l(R),u==null||u(R)}catch(Y){console.error("Failed to select thread:",Y)}},sr=async()=>{try{ze(!0);const R=await ne();R&&(f==null||f(R),l==null||l(R))}catch(R){console.error("Failed to create thread:",R)}finally{ze(!1)}},Mr=async(R,Y)=>{const se=R.threadId;if(confirm("Delete this thread?")){if(B.current){const ie=B.current.querySelector("[data-radix-scroll-area-viewport]");ie&&(X.current=ie.scrollTop)}try{await H(se),h==null||h(se)}catch(ie){console.error("Failed to delete thread:",ie)}}},ir=(R,Y)=>{Y==null||Y.stopPropagation(),me(R.threadId),Te(R.title||`Thread ${R.threadId.slice(0,8)}`)},Fn=async R=>{const Y=typeof R=="string"?R:R.threadId;if(be.trim())try{await O(Y,be.trim()),me(null),Te("")}catch(se){console.error("Failed to update title:",se)}},zn=R=>{me(null),Te("")},wn=R=>{if(!R)return"";try{const Y=R.endsWith("Z")||R.includes("+")?R:`${R}Z`,se=new Date(Y),ue=new Date().getTime()-se.getTime(),Me=Math.floor(ue/(1e3*60*60*24));return Me===0?se.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):Me===1?"Yesterday":Me<7?`${Me} days ago`:se.toLocaleDateString()}catch{return""}},$t=R=>R.title||`Thread ${R.threadId.slice(0,8)}`,ar=R=>{const Y=$t(R);return Y.length<=Cp?Y:`${Y.slice(0,Cp)}...`},E=R=>Array.isArray(R)?R.length:Object.values(R).reduce((Y,se)=>Array.isArray(se)?Y+se.length:Y+E(se),0),Z=R=>{const se=["Today","Yesterday","Last 7 Days","Older"].indexOf(R);return se===-1?null:se},oe=(R,Y,se)=>{if(Array.isArray(R))return R.map(Ee=>d.jsx(bp,{thread:Ee,isActive:D===Ee.threadId,editingThreadId:le,editingTitle:be,onSelect:dn,onStartEditing:ir,onEditingTitleChange:je,onSaveEditing:de=>void Fn(de),onCancelEditing:()=>zn(),onShare:de=>Xt(de.threadId),onDelete:de=>Mr(de),showEditTitle:r,showDeleteButton:n,onMenuOpenChange:o,onMenuAction:s,formatDate:wn,getDisplayThreadTitle:ar,secondaryLine:ht&&un(Ee)?yn(Ee):void 0,itemClassName:a.threadItem,activeItemClassName:a.activeThread},Ee.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"],ue="pl-2 border-l border-slate-100 dark:border-slate-800 ml-1.5 my-1 space-y-1",Me=ie[Y]??ie[ie.length-1],Oe=Object.entries(R);if(Oe.length===1){const[Ee,de]=Oe[0];return oe(de,Y+1,`${se}-${Ee}`)}return Oe.sort(([Ee],[de])=>{const Re="Default";if(Ee===Re)return 1;if(de===Re)return-1;const Pe=Z(Ee),Fe=Z(de);if(Pe!==null||Fe!==null){const pt=Pe??Number.MAX_SAFE_INTEGER,fn=Fe??Number.MAX_SAFE_INTEGER;return pt-fn}return Ee.localeCompare(de)}).map(([Ee,de])=>{const Re=`${se}-${Ee}`,Pe=E(de);return d.jsxs(xC,{defaultOpen:!0,className:"group/collapsible",children:[d.jsxs(bC,{className:Me,children:[d.jsx(xe.ChevronRight,{className:"w-3 h-3 mr-1 transition-transform group-data-[state=open]/collapsible:rotate-90"}),Ee,d.jsx("span",{className:"ml-auto text-[10px] text-slate-400",children:Pe})]}),d.jsx(yC,{children:d.jsx("div",{className:ue,children:oe(de,Y+1,Re)})})]},Re)})};return d.jsxs("div",{className:`thread-manager-root flex flex-col h-full ${e} ${a.container||""}`,children:[w&&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(Qe,{onClick:sr,disabled:Ae||L,className:a.createButton||"px-3 py-2 gap-1",size:"sm",variant:"ghost",title:Ae?"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(ja,{children:[d.jsx(Pa,{asChild:!0,children:d.jsx(Qe,{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:Ln.label})}),d.jsx(_s,{align:"start",sideOffset:6,className:"w-40",children:Tt.map(R=>d.jsxs(er,{className:"justify-between text-[12px]",onClick:Y=>{Y.preventDefault(),Yt(R.key)},children:[d.jsx("span",{children:R.label}),rr===R.key&&d.jsx(xe.Check,{className:"h-3 w-3"})]},R.key))})]})]})]}),d.jsx(Ka,{ref:B,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:ot?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…"})]}):cn.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:bn})]}):(Be==null?void 0:Be.kind)==="nested"?oe(Be.groups,0,"group"):cn.slice().sort((R,Y)=>new Date(Y.updatedAt||Y.createdAt||"").getTime()-new Date(R.updatedAt||R.createdAt||"").getTime()).map(R=>d.jsx(bp,{thread:R,isActive:D===R.threadId,editingThreadId:le,editingTitle:be,onSelect:dn,onStartEditing:ir,onEditingTitleChange:je,onSaveEditing:Y=>void Fn(Y),onCancelEditing:Y=>zn(),onShare:Y=>Xt(Y.threadId),onDelete:Y=>Mr(Y),showEditTitle:r,showDeleteButton:n,onMenuOpenChange:o,onMenuAction:s,formatDate:wn,getDisplayThreadTitle:ar,secondaryLine:ht&&un(R)?yn(R):void 0,itemClassName:a.threadItem,activeItemClassName:a.activeThread},R.threadId))})}),d.jsx(Lh,{open:Ze,onOpenChange:R=>!R&&Lt(),children:d.jsxs(Fa,{className:"max-w-md p-0",children:[d.jsx(za,{children:d.jsx(Ba,{children:"Share thread"})}),d.jsxs(fp,{children:[d.jsx(hp,{autoFocus:!0,value:lt,onValueChange:R=>nt(R),placeholder:"Search for recipients..."}),d.jsxs(pp,{children:[W&&d.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-muted-foreground",children:[re&&d.jsx(xe.Loader2,{className:"h-3 w-3 animate-spin"}),d.jsx("span",{className:W.startsWith("Failed")?"text-red-500":W.startsWith("Shared")?"text-emerald-500":"text-slate-600 dark:text-slate-400",children:W})]}),d.jsx(mp,{children:ut?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"}),or.length>0&&d.jsx(gp,{heading:"Recipients",children:or.map(R=>d.jsx(xp,{onSelect:()=>xn(R),children:d.jsxs("div",{className:"flex flex-col items-start text-sm",children:[d.jsx("span",{className:"font-medium",children:R.label}),R.secondaryLabel&&d.jsx("span",{className:"text-xs text-muted-foreground",children:R.secondaryLabel})]})},R.id))})]})]})]})})]})}function CC({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`}},c=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"}),l=v.useCallback(u=>{var f;(f=i.onThreadChange)==null||f.call(i,u)},[i]);return e==="fullscreen"?d.jsx(Gr,{...i,onThreadChange:l,children:d.jsx("div",{className:`${a(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:c(t),children:d.jsx(jr,{className:"flex-1",onError:i.onError,enableFileUpload:!0,payloadExtras:s})})}):e==="tabs"?d.jsx(Gr,{...i,onThreadChange:l,children:d.jsx("div",{className:`${a(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:c(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(zs,{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(Gr,{...i,onThreadChange:l,children:d.jsxs("div",{className:`${a(t)} flex overflow-hidden ${r} ${o.container||""}`,style:c(t),children:[n&&d.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:d.jsx(zs,{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 TC=1,kC=1e6;let nl=0;function EC(){return nl=(nl+1)%Number.MAX_SAFE_INTEGER,nl.toString()}const rl=new Map,Ep=e=>{if(rl.has(e))return;const t=setTimeout(()=>{rl.delete(e),vo({type:"REMOVE_TOAST",toastId:e})},kC);rl.set(e,t)},IC=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,TC)};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?Ep(n):e.toasts.forEach(r=>{Ep(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)}}},Bs=[];let Us={toasts:[]};function vo(e){Us=IC(Us,e),Bs.forEach(t=>{t(Us)})}function AC({...e}){const t=EC(),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 NC(){const[e,t]=b.useState(Us);return b.useEffect(()=>(Bs.push(t),()=>{const n=Bs.indexOf(t);n>-1&&Bs.splice(n,1)}),[e]),{...e,toast:AC,dismiss:n=>vo({type:"DISMISS_TOAST",toastId:n})}}function _C(e){const{allowFileOpen:t,currentThreadId:n}=e,{fileApi:r}=hr(),{toast:o}=NC(),[s,i]=v.useState({}),[a,c]=v.useState(null),[l,u]=v.useState(!1),f=v.useCallback(()=>{u(!1),c(null)},[]),h=v.useCallback(m=>{c(m),u(!0)},[]),p=v.useCallback(async(m,g,x)=>{var y,w;if(!t){m.preventDefault();return}if(s[x]){m.preventDefault();return}try{const k=String(g.url??""),I=k.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(I){m.preventDefault();const S=I[1],C=g.name||`file_${S}`,T=g.mimeType||"application/octet-stream";h({id:S,name:C,mimeType:T});return}if(k.startsWith("data:")){m.preventDefault(),i(C=>({...C,[x]:!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??"")===(g.name??""))?!1:typeof g.size=="number"&&typeof A.size=="number"?A.size===g.size:!0);if(!(T!=null&&T.id))throw new Error(`File "${g.name}" is not yet available on the server`);if(!T.id||!T.filename)throw new Error("Invalid file data received from server");h({id:T.id,name:g.name||T.filename||`file_${T.id}`,mimeType:g.mimeType||T.mime_type||"application/octet-stream"}),(y=S.update)==null||y.call(S,{id:S.id,title:"Success",description:`Opened ${g.name}`,open:!0})}catch(C){console.error("Failed to fetch server file:",C);const T=C instanceof Error?C.message:"Unknown error occurred";(w=S.update)==null||w.call(S,{id:S.id,title:"Failed",description:T}),o({title:"Failed to fetch file",description:T,open:!0})}finally{i(C=>({...C,[x]:!1}))}}}catch(k){console.error("File click error:",k),i(I=>({...I,[x]:!1}))}},[t,s,o,n,h]);return{uploadingFiles:s,handleFileClick:p,fileViewerOpen:l,currentFileInfo:a,closeFileViewer:f}}function jC(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:pc(t),imageParts:n.filter(o=>o.type==="image_url"),fileParts:n.filter(o=>o.type==="file"),interruptParts:n.filter(o=>o.type==="interrupt"),toolRaw:mc(n),isToolStreaming:!!r.toolStreaming}},[e])}function PC({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(zs,{showCreateButton:!0,className:"h-full",onThreadSelect:()=>r("chat")})})]})}function RC({className:e="",placeholder:t,isAuthenticated:n=!0,onMessageSent:r,widgetTitle:o="Serti AI Navigator",widgetSubtitle:s="AI-Powered Assistant",...i}){const[a,c]=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(Qe,{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(Qe,{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(Qe,{variant:"ghost",size:"sm",onClick:l=>{l.stopPropagation(),c(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(PC,{placeholder:t,onMessageSent:r})})]})})}):null}function MC({label:e="New chat",children:t,className:n,variant:r="ghost",size:o="sm",...s}){return d.jsxs(Qe,{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=tc,J.AssistantMessageComponent=Vi,J.ChatApi=Xl,J.ChatApp=CC,J.ChatContainer=jr,J.ChatInput=Ra,J.ChatInputArea=js,J.ChatInputRow=js,J.ChatInterface=jr,J.ChatMessagesArea=ss,J.ChatProviders=Gr,J.ChatUIProvider=Ic,J.ChatWidget=RC,J.Composer=Ra,J.DEFAULT_TIMEOUT_MS=ql,J.FileApi=Jl,J.HISTORY_TIMEOUT_MS=Gl,J.MarkdownContent=so,J.MessageBubble=ao,J.MessageHeader=Hi,J.MessageList=ss,J.NewChatButton=MC,J.SETTINGS_STORAGE_KEY=mi,J.STORAGE_KEYS=vn,J.SystemMessageComponent=qi,J.ThreadManager=zs,J.ThreadStateProvider=kc,J.ThreadsProvider=fc,J.ToolCallCard=Fi,J.ToolContent=Qo,J.ToolProgress=Bu,J.UserMessageComponent=Ki,J.applySettings=sx,J.chatApiClient=Cn,J.cn=Np,J.createTaskSyncToolEndHandler=rx,J.del=oi,J.draftKey=Po,J.extractTaskIdFromToolEnd=Rc,J.extractToolCalls=ai,J.extractToolContent=Wr,J.fileApiClient=si,J.fileToBase64=nc,J.formatToolOutput=Ng,J.get=At,J.getChatToken=ni,J.getCurrentSettings=ox,J.getDefaultApiConfig=Lc,J.getDefaultChatSettings=$c,J.getToolCallArtifacts=Rg,J.getToolCalls=ui,J.hasContent=_g,J.httpClient=wt,J.isEnvelope=cc,J.isFileLike=li,J.loadStoredSettings=Fc,J.looksLikeMarkdown=ic,J.normalizeToolPayload=gc,J.normalizeToolPayloadValue=xr,J.onChatTokenChanged=ri,J.parseJsonSafe=pr,J.post=zr,J.pretty=gr,J.processAttachments=rc,J.put=Yl,J.sanitizeForDisplay=Kr,J.saveSettings=zc,J.setChatToken=Sn,J.stringifyTool=mc,J.unwrap=vt,J.useApi=hr,J.useChatController=bh,J.useChatUI=Fo,J.useFilePreview=_C,J.useHasChatSession=tx,J.useParsedMessageContent=jC,J.useShallowStableValue=Pc,J.useStream=pi,J.useStreamingMarkdownBuffer=ad,J.useThreadHistoryState=vc,J.useThreadManagerViewState=kp,J.useThreadState=qr,J.useThreadStateUpdater=Tc,J.useThreads=Vr,J.useThreadsState=uc,J.useToolPayload=zu,Object.defineProperty(J,Symbol.toStringTag,{value:"Module"})});
131
+ For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return b.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},CS="DialogDescriptionWarning",TS=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Rh(CS).contentName}}.`;return b.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},Oh=wh,Mh=Ch,La=Th,$a=kh,bo=Ih,Dh=Nh,kS=_h;const Lh=Oh,ES=Mh,$h=b.forwardRef(({className:e,...t},n)=>d.jsx(La,{ref:n,className:pe("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}));$h.displayName=La.displayName;const Fa=b.forwardRef(({className:e,children:t,...n},r)=>{const o=b.useMemo(()=>{let s=!1;function i(a){b.Children.forEach(a,c=>{if(s||!b.isValidElement(c))return;const l=c.type;if(l===bo||(l==null?void 0:l.displayName)===bo.displayName||(l==null?void 0:l.name)==="DialogTitle"){s=!0;return}c.props&&c.props.children&&i(c.props.children)})}return i(t),s},[t]);return d.jsxs(ES,{children:[d.jsx($h,{}),d.jsxs($a,{ref:r,className:pe("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(kS,{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"})]})]})]})});Fa.displayName=$a.displayName;const za=({className:e,...t})=>d.jsx("div",{className:pe("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});za.displayName="DialogHeader";const Ba=b.forwardRef(({className:e,...t},n)=>d.jsx(bo,{ref:n,className:pe("text-lg font-semibold leading-none tracking-tight",e),...t}));Ba.displayName=bo.displayName;const Fh=b.forwardRef(({className:e,...t},n)=>d.jsx(Dh,{ref:n,className:pe("text-sm text-muted-foreground",e),...t}));Fh.displayName=Dh.displayName;function IS(e,[t,n]){return Math.min(n,Math.max(t,e))}function AS(e,t){return b.useReducer((n,r)=>t[n][r]??n,e)}var Ua="ScrollArea",[zh,uT]=Pn(Ua),[NS,Ut]=zh(Ua),Bh=b.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,c]=b.useState(null),[l,u]=b.useState(null),[f,h]=b.useState(null),[p,m]=b.useState(null),[g,x]=b.useState(null),[y,w]=b.useState(0),[k,I]=b.useState(0),[S,C]=b.useState(!1),[T,A]=b.useState(!1),j=Ye(t,L=>c(L)),_=Gi(o);return d.jsx(NS,{scope:n,type:r,dir:_,scrollHideDelay:s,scrollArea:a,viewport:l,onViewportChange:u,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:m,scrollbarXEnabled:S,onScrollbarXEnabledChange:C,scrollbarY:g,onScrollbarYChange:x,scrollbarYEnabled:T,onScrollbarYEnabledChange:A,onCornerWidthChange:w,onCornerHeightChange:I,children:d.jsx(Ne.div,{dir:_,...i,ref:j,style:{position:"relative","--radix-scroll-area-corner-width":y+"px","--radix-scroll-area-corner-height":k+"px",...e.style}})})});Bh.displayName=Ua;var Uh="ScrollAreaViewport",Hh=b.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=Ut(Uh,n),a=b.useRef(null),c=Ye(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(Ne.div,{"data-radix-scroll-area-viewport":"",...s,ref:c,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})})]})});Hh.displayName=Uh;var ln="ScrollAreaScrollbar",Ha=b.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Ut(ln,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return b.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?d.jsx(jS,{...r,ref:t,forceMount:n}):o.type==="scroll"?d.jsx(_S,{...r,ref:t,forceMount:n}):o.type==="auto"?d.jsx(Wh,{...r,ref:t,forceMount:n}):o.type==="always"?d.jsx(Wa,{...r,ref:t}):null});Ha.displayName=ln;var jS=b.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Ut(ln,e.__scopeScrollArea),[s,i]=b.useState(!1);return b.useEffect(()=>{const a=o.scrollArea;let c=0;if(a){const l=()=>{window.clearTimeout(c),i(!0)},u=()=>{c=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",l),a.addEventListener("pointerleave",u),()=>{window.clearTimeout(c),a.removeEventListener("pointerenter",l),a.removeEventListener("pointerleave",u)}}},[o.scrollArea,o.scrollHideDelay]),d.jsx(Dt,{present:n||s,children:d.jsx(Wh,{"data-state":s?"visible":"hidden",...r,ref:t})})}),_S=b.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Ut(ln,e.__scopeScrollArea),s=e.orientation==="horizontal",i=Ls(()=>c("SCROLL_END"),100),[a,c]=AS("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 b.useEffect(()=>{if(a==="idle"){const l=window.setTimeout(()=>c("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(l)}},[a,o.scrollHideDelay,c]),b.useEffect(()=>{const l=o.viewport,u=s?"scrollLeft":"scrollTop";if(l){let f=l[u];const h=()=>{const p=l[u];f!==p&&(c("SCROLL"),i()),f=p};return l.addEventListener("scroll",h),()=>l.removeEventListener("scroll",h)}},[o.viewport,s,c,i]),d.jsx(Dt,{present:n||a!=="hidden",children:d.jsx(Wa,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ve(e.onPointerEnter,()=>c("POINTER_ENTER")),onPointerLeave:ve(e.onPointerLeave,()=>c("POINTER_LEAVE"))})})}),Wh=b.forwardRef((e,t)=>{const n=Ut(ln,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=b.useState(!1),a=e.orientation==="horizontal",c=Ls(()=>{if(n.viewport){const l=n.viewport.offsetWidth<n.viewport.scrollWidth,u=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?l:u)}},10);return jr(n.viewport,c),jr(n.content,c),d.jsx(Dt,{present:r||s,children:d.jsx(Wa,{"data-state":s?"visible":"hidden",...o,ref:t})})}),Wa=b.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=Ut(ln,e.__scopeScrollArea),s=b.useRef(null),i=b.useRef(0),[a,c]=b.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),l=Yh(a.viewport,a.content),u={...r,sizes:a,onSizesChange:c,hasThumb:l>0&&l<1,onThumbChange:h=>s.current=h,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:h=>i.current=h};function f(h,p){return LS(h,i.current,a,p)}return n==="horizontal"?d.jsx(PS,{...u,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=Xh(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(RS,{...u,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=Xh(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}),PS=b.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Ut(ln,e.__scopeScrollArea),[i,a]=b.useState(),c=b.useRef(null),l=Ye(t,c,s.onScrollbarXChange);return b.useEffect(()=>{c.current&&a(getComputedStyle(c.current))},[c]),d.jsx(Kh,{"data-orientation":"horizontal",...o,ref:l,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":Ds(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),Zh(h,f)&&u.preventDefault()}},onResize:()=>{c.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:c.current.clientWidth,paddingStart:Ms(i.paddingLeft),paddingEnd:Ms(i.paddingRight)}})}})}),RS=b.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Ut(ln,e.__scopeScrollArea),[i,a]=b.useState(),c=b.useRef(null),l=Ye(t,c,s.onScrollbarYChange);return b.useEffect(()=>{c.current&&a(getComputedStyle(c.current))},[c]),d.jsx(Kh,{"data-orientation":"vertical",...o,ref:l,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":Ds(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),Zh(h,f)&&u.preventDefault()}},onResize:()=>{c.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:c.current.clientHeight,paddingStart:Ms(i.paddingTop),paddingEnd:Ms(i.paddingBottom)}})}})}),[OS,Vh]=zh(ln),Kh=b.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:c,onDragScroll:l,onWheelScroll:u,onResize:f,...h}=e,p=Ut(ln,n),[m,g]=b.useState(null),x=Ye(t,j=>g(j)),y=b.useRef(null),w=b.useRef(""),k=p.viewport,I=r.content-r.viewport,S=wt(u),C=wt(c),T=Ls(f,10);function A(j){if(y.current){const _=j.clientX-y.current.left,L=j.clientY-y.current.top;l({x:_,y:L})}}return b.useEffect(()=>{const j=_=>{const L=_.target;(m==null?void 0:m.contains(L))&&S(_,I)};return document.addEventListener("wheel",j,{passive:!1}),()=>document.removeEventListener("wheel",j,{passive:!1})},[k,m,I,S]),b.useEffect(C,[r,C]),jr(m,T),jr(p.content,T),d.jsx(OS,{scope:n,scrollbar:m,hasThumb:o,onThumbChange:wt(s),onThumbPointerUp:wt(i),onThumbPositionChange:C,onThumbPointerDown:wt(a),children:d.jsx(Ne.div,{...h,ref:x,style:{position:"absolute",...h.style},onPointerDown:ve(e.onPointerDown,j=>{j.button===0&&(j.target.setPointerCapture(j.pointerId),y.current=m.getBoundingClientRect(),w.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),A(j))}),onPointerMove:ve(e.onPointerMove,A),onPointerUp:ve(e.onPointerUp,j=>{const _=j.target;_.hasPointerCapture(j.pointerId)&&_.releasePointerCapture(j.pointerId),document.body.style.webkitUserSelect=w.current,p.viewport&&(p.viewport.style.scrollBehavior=""),y.current=null})})})}),Os="ScrollAreaThumb",qh=b.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Vh(Os,e.__scopeScrollArea);return d.jsx(Dt,{present:n||o.hasThumb,children:d.jsx(MS,{ref:t,...r})})}),MS=b.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=Ut(Os,n),i=Vh(Os,n),{onThumbPositionChange:a}=i,c=Ye(t,f=>i.onThumbChange(f)),l=b.useRef(void 0),u=Ls(()=>{l.current&&(l.current(),l.current=void 0)},100);return b.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(u(),!l.current){const p=$S(f,a);l.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,u,a]),d.jsx(Ne.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:c,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:ve(e.onPointerDownCapture,f=>{const p=f.target.getBoundingClientRect(),m=f.clientX-p.left,g=f.clientY-p.top;i.onThumbPointerDown({x:m,y:g})}),onPointerUp:ve(e.onPointerUp,i.onThumbPointerUp)})});qh.displayName=Os;var Va="ScrollAreaCorner",Gh=b.forwardRef((e,t)=>{const n=Ut(Va,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?d.jsx(DS,{...e,ref:t}):null});Gh.displayName=Va;var DS=b.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=Ut(Va,n),[s,i]=b.useState(0),[a,c]=b.useState(0),l=!!(s&&a);return jr(o.scrollbarX,()=>{var f;const u=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(u),c(u)}),jr(o.scrollbarY,()=>{var f;const u=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(u),i(u)}),l?d.jsx(Ne.div,{...r,ref:t,style:{width:s,height:a,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function Ms(e){return e?parseInt(e,10):0}function Yh(e,t){const n=e/t;return isNaN(n)?0:n}function Ds(e){const t=Yh(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function LS(e,t,n,r="ltr"){const o=Ds(n),s=o/2,i=t||s,a=o-i,c=n.scrollbar.paddingStart+i,l=n.scrollbar.size-n.scrollbar.paddingEnd-a,u=n.content-n.viewport,f=r==="ltr"?[0,u]:[u*-1,0];return Jh([c,l],f)(e)}function Xh(e,t,n="ltr"){const r=Ds(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,c=n==="ltr"?[0,i]:[i*-1,0],l=IS(e,c);return Jh([0,i],[0,a])(l)}function Jh(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 Zh(e,t){return e>0&&e<t}var $S=(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 Ls(e,t){const n=wt(e),r=b.useRef(0);return b.useEffect(()=>()=>window.clearTimeout(r.current),[]),b.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function jr(e,t){const n=wt(t);tn(()=>{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 Qh=Bh,FS=Hh,zS=Gh;const Ka=b.forwardRef(({className:e,children:t,...n},r)=>d.jsxs(Qh,{ref:r,className:pe("relative overflow-hidden",e),...n,children:[d.jsx(FS,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),d.jsx(ep,{}),d.jsx(zS,{})]}));Ka.displayName=Qh.displayName;const ep=b.forwardRef(({className:e,orientation:t="vertical",...n},r)=>d.jsx(Ha,{ref:r,orientation:t,className:pe("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(qh,{className:"relative flex-1 rounded-full bg-border"})}));ep.displayName=Ha.displayName;function BS({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(Lh,{open:e,onOpenChange:t,children:d.jsxs(Fa,{className:"max-w-2xl max-h-[85vh] flex flex-col p-0 gap-0 overflow-hidden",children:[d.jsxs(za,{className:"p-6 border-b shrink-0",children:[d.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[d.jsxs(Ba,{className:"text-xl font-bold",children:["Tool Usage: ",r.name]}),d.jsx("span",{className:pe("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(Fh,{children:["ID: ",r.id]})]}),d.jsx(Ka,{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:c=!0,toolConfig:l,toolRenderers:u,toolArtifactRenderers:f,payloadExtras:h={},customStyles:p={},messageCustomStyles:m,onMessageSent:g,onExcelUploadSuccess:x,onError:y,renderArtifactsInline:w=!0,emptyMessage:k}){var U,P,V;const{currentThreadId:I}=Vr(),S=qr(),C=pi(),T=bh({submit:C.submit,chatRequest:{payload:h},lastCheckpointId:((U=S.checkpoint)==null?void 0:U.id)??null,lastCheckpointNs:((P=S.checkpoint)==null?void 0:P.namespace)??null,onMessageSent:g,onExcelUploadSuccess:x,onError:y,enableMessageEditing:a,messages:S.messages,setPendingAssistantResponse:()=>{},activeThreadId:I??null}),A=S.interrupt,j=A?hc(A.id):null,_=j!==null?{type:"interrupt",id:j}:null,[L,F]=v.useState(!1),[B,O]=v.useState("desktop"),[G,Y]=v.useState(!1),[re,H]=v.useState(null),W=v.useRef(null);v.useEffect(()=>{const ee=()=>{const ce=window.innerWidth;O(ce<640?"phone":ce<1024?"tablet":"desktop")};return ee(),window.addEventListener("resize",ee),()=>window.removeEventListener("resize",ee)},[]);const ne=v.useCallback(async(ee,ce,ue)=>{try{F(!0),await S.respondToInterrupt(ee,ce,ue)}catch(be){console.error("Failed to respond to interrupt:",be)}finally{F(!1)}},[S]),K=v.useCallback(async ee=>{var ce,ue;Y(!0);try{if(!ee)await S.returnToLatest(),(ce=W.current)==null||ce.scrollToLatest();else{const be=S.checkpoints.find(Ae=>Ae.checkpointId===ee);await S.navigateToCheckpoint(ee,(be==null?void 0:be.checkpointNs)??null),(ue=W.current)==null||ue.scrollToTop()}}finally{Y(!1)}},[S]),M=v.useMemo(()=>l??{toolRenderers:u,toolArtifactRenderers:f,getToolExpandable:ee=>ee.name!=="ask_user_choice"},[l,u,f]),N=!!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||""}`,D=`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||""}`,q=`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(xe.X,{size:16})})]}),d.jsxs("div",{className:`relative ${D}`,style:n?{maxHeight:n}:void 0,children:[d.jsx(Ic,{layoutSize:B,customStyles:p,messageCustomStyles:m,renderArtifactsInline:w,enableMessageEditing:a,editingMessageId:T.editingMessageId,showToolMessages:c,followNewMessages:o,showThinkingIndicator:C.isStreaming,streamingDebounceMs:r,toolConfig:M,checkpointIndex:S.checkpointIndex,activeCheckpointId:(V=S.checkpoint)==null?void 0:V.id,onSelectCheckpoint:K,pendingInterrupt:A,onEdit:T.startEditing,onRegenerate:T.handleRegenerateCb,onCancelEdit:T.cancelEditing,getInterruptOptions:()=>{},selectedToolCall:re,onSelectToolCall:H,children:d.jsx(ss,{ref:W,className:"h-full",style:{height:"100%"},messages:T.displayMessages??S.messages,isStreaming:C.isStreaming,emptyMessage:k})}),d.jsx(BS,{isOpen:!!re,onOpenChange:ee=>!ee&&H(null),toolCall:re}),(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||G?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,A&&_&&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(qu,{interruptPart:_,onApprove:()=>ne(!0),onReject:()=>ne(!1),onSelectAlternative:(ee,ce)=>ne(!0,ce),disabled:L,isActive:!0,payload:A.value})})})]}),d.jsxs("div",{className:q,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(_s,{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:N,enableFileUpload:s,enableExcelUpload:i,onExcelUpload:T.handleExcelUpload,onError:y,customStyles:p,textareaClassName:p.textarea||"",allowEmptySend:!1,inputError:T.inputError})]})]})}var tp=1,US=.9,HS=.8,WS=.17,qa=.1,Ga=.999,VS=.9999,KS=.99,qS=/[\\\/_+.#"@\[\(\{&]/,GS=/[\\\/_+.#"@\[\(\{&]/g,YS=/[\s-]/,np=/[\s-]/g;function Ya(e,t,n,r,o,s,i){if(s===t.length)return o===e.length?tp:KS;var a=`${o},${s}`;if(i[a]!==void 0)return i[a];for(var c=r.charAt(s),l=n.indexOf(c,o),u=0,f,h,p,m;l>=0;)f=Ya(e,t,n,r,l+1,s+1,i),f>u&&(l===o?f*=tp:qS.test(e.charAt(l-1))?(f*=HS,p=e.slice(o,l-1).match(GS),p&&o>0&&(f*=Math.pow(Ga,p.length))):YS.test(e.charAt(l-1))?(f*=US,m=e.slice(o,l-1).match(np),m&&o>0&&(f*=Math.pow(Ga,m.length))):(f*=WS,o>0&&(f*=Math.pow(Ga,l-o))),e.charAt(l)!==t.charAt(s)&&(f*=VS)),(f<qa&&n.charAt(l-1)===r.charAt(s+1)||r.charAt(s+1)===r.charAt(s)&&n.charAt(l-1)!==r.charAt(s))&&(h=Ya(e,t,n,r,l+1,s+2,i),h*qa>f&&(f=h*qa)),f>u&&(u=f),l=n.indexOf(c,l+1);return i[a]=u,u}function rp(e){return e.toLowerCase().replace(np," ")}function XS(e,t,n){return e=n&&n.length>0?`${e+" "+n.join(" ")}`:e,Ya(e,t,rp(e),rp(t),0,0,{})}var yo='[cmdk-group=""]',Xa='[cmdk-group-items=""]',JS='[cmdk-group-heading=""]',op='[cmdk-item=""]',sp=`${op}:not([aria-disabled="true"])`,Ja="cmdk-item-select",Pr="data-value",ZS=(e,t,n)=>XS(e,t,n),ip=b.createContext(void 0),wo=()=>b.useContext(ip),ap=b.createContext(void 0),Za=()=>b.useContext(ap),lp=b.createContext(void 0),cp=b.forwardRef((e,t)=>{let n=Rr(()=>{var M,N;return{search:"",value:(N=(M=e.value)!=null?M:e.defaultValue)!=null?N:"",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=up(e),{label:c,children:l,value:u,onValueChange:f,filter:h,shouldFilter:p,loop:m,disablePointerSelection:g=!1,vimBindings:x=!0,...y}=e,w=Rt(),k=Rt(),I=Rt(),S=b.useRef(null),C=cC();nr(()=>{if(u!==void 0){let M=u.trim();n.current.value=M,T.emit()}},[u]),nr(()=>{C(6,B)},[]);let T=b.useMemo(()=>({subscribe:M=>(i.current.add(M),()=>i.current.delete(M)),snapshot:()=>n.current,setState:(M,N,$)=>{var D,q,U,P;if(!Object.is(n.current[M],N)){if(n.current[M]=N,M==="search")F(),_(),C(1,L);else if(M==="value"){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let V=document.getElementById(I);V?V.focus():(D=document.getElementById(w))==null||D.focus()}if(C(7,()=>{var V;n.current.selectedItemId=(V=O())==null?void 0:V.id,T.emit()}),$||C(5,B),((q=a.current)==null?void 0:q.value)!==void 0){let V=N??"";(P=(U=a.current).onValueChange)==null||P.call(U,V);return}}T.emit()}},emit:()=>{i.current.forEach(M=>M())}}),[]),A=b.useMemo(()=>({value:(M,N,$)=>{var D;N!==((D=s.current.get(M))==null?void 0:D.value)&&(s.current.set(M,{value:N,keywords:$}),n.current.filtered.items.set(M,j(N,$)),C(2,()=>{_(),T.emit()}))},item:(M,N)=>(r.current.add(M),N&&(o.current.has(N)?o.current.get(N).add(M):o.current.set(N,new Set([M]))),C(3,()=>{F(),_(),n.current.value||L(),T.emit()}),()=>{s.current.delete(M),r.current.delete(M),n.current.filtered.items.delete(M);let $=O();C(4,()=>{F(),($==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:c||e["aria-label"],getDisablePointerSelection:()=>a.current.disablePointerSelection,listId:w,inputId:I,labelId:k,listInnerRef:S}),[]);function j(M,N){var $,D;let q=(D=($=a.current)==null?void 0:$.filter)!=null?D:ZS;return M?q(M,n.current.search,N):0}function _(){if(!n.current.search||a.current.shouldFilter===!1)return;let M=n.current.filtered.items,N=[];n.current.filtered.groups.forEach(D=>{let q=o.current.get(D),U=0;q.forEach(P=>{let V=M.get(P);U=Math.max(V,U)}),N.push([D,U])});let $=S.current;G().sort((D,q)=>{var U,P;let V=D.getAttribute("id"),ee=q.getAttribute("id");return((U=M.get(ee))!=null?U:0)-((P=M.get(V))!=null?P:0)}).forEach(D=>{let q=D.closest(Xa);q?q.appendChild(D.parentElement===q?D:D.closest(`${Xa} > *`)):$.appendChild(D.parentElement===$?D:D.closest(`${Xa} > *`))}),N.sort((D,q)=>q[1]-D[1]).forEach(D=>{var q;let U=(q=S.current)==null?void 0:q.querySelector(`${yo}[${Pr}="${encodeURIComponent(D[0])}"]`);U==null||U.parentElement.appendChild(U)})}function L(){let M=G().find($=>$.getAttribute("aria-disabled")!=="true"),N=M==null?void 0:M.getAttribute(Pr);T.setState("value",N||void 0)}function F(){var M,N,$,D;if(!n.current.search||a.current.shouldFilter===!1){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let q=0;for(let U of r.current){let P=(N=(M=s.current.get(U))==null?void 0:M.value)!=null?N:"",V=(D=($=s.current.get(U))==null?void 0:$.keywords)!=null?D:[],ee=j(P,V);n.current.filtered.items.set(U,ee),ee>0&&q++}for(let[U,P]of o.current)for(let V of P)if(n.current.filtered.items.get(V)>0){n.current.filtered.groups.add(U);break}n.current.filtered.count=q}function B(){var M,N,$;let D=O();D&&(((M=D.parentElement)==null?void 0:M.firstChild)===D&&(($=(N=D.closest(yo))==null?void 0:N.querySelector(JS))==null||$.scrollIntoView({block:"nearest"})),D.scrollIntoView({block:"nearest"}))}function O(){var M;return(M=S.current)==null?void 0:M.querySelector(`${op}[aria-selected="true"]`)}function G(){var M;return Array.from(((M=S.current)==null?void 0:M.querySelectorAll(sp))||[])}function Y(M){let N=G()[M];N&&T.setState("value",N.getAttribute(Pr))}function re(M){var N;let $=O(),D=G(),q=D.findIndex(P=>P===$),U=D[q+M];(N=a.current)!=null&&N.loop&&(U=q+M<0?D[D.length-1]:q+M===D.length?D[0]:D[q+M]),U&&T.setState("value",U.getAttribute(Pr))}function H(M){let N=O(),$=N==null?void 0:N.closest(yo),D;for(;$&&!D;)$=M>0?aC($,yo):lC($,yo),D=$==null?void 0:$.querySelector(sp);D?T.setState("value",D.getAttribute(Pr)):re(M)}let W=()=>Y(G().length-1),ne=M=>{M.preventDefault(),M.metaKey?W():M.altKey?H(1):re(1)},K=M=>{M.preventDefault(),M.metaKey?Y(0):M.altKey?H(-1):re(-1)};return b.createElement(Ne.div,{ref:t,tabIndex:-1,...y,"cmdk-root":"",onKeyDown:M=>{var N;(N=y.onKeyDown)==null||N.call(y,M);let $=M.nativeEvent.isComposing||M.keyCode===229;if(!(M.defaultPrevented||$))switch(M.key){case"n":case"j":{x&&M.ctrlKey&&ne(M);break}case"ArrowDown":{ne(M);break}case"p":case"k":{x&&M.ctrlKey&&K(M);break}case"ArrowUp":{K(M);break}case"Home":{M.preventDefault(),Y(0);break}case"End":{M.preventDefault(),W();break}case"Enter":{M.preventDefault();let D=O();if(D){let q=new Event(Ja);D.dispatchEvent(q)}}}}},b.createElement("label",{"cmdk-label":"",htmlFor:A.inputId,id:A.labelId,style:dC},c),$s(e,M=>b.createElement(ap.Provider,{value:T},b.createElement(ip.Provider,{value:A},M))))}),QS=b.forwardRef((e,t)=>{var n,r;let o=Rt(),s=b.useRef(null),i=b.useContext(lp),a=wo(),c=up(e),l=(r=(n=c.current)==null?void 0:n.forceMount)!=null?r:i==null?void 0:i.forceMount;nr(()=>{if(!l)return a.item(o,i==null?void 0:i.id)},[l]);let u=dp(o,s,[e.value,e.children,s],e.keywords),f=Za(),h=Dn(C=>C.value&&C.value===u.current),p=Dn(C=>l||a.filter()===!1?!0:C.search?C.filtered.items.get(o)>0:!0);b.useEffect(()=>{let C=s.current;if(!(!C||e.disabled))return C.addEventListener(Ja,m),()=>C.removeEventListener(Ja,m)},[p,e.onSelect,e.disabled]);function m(){var C,T;g(),(T=(C=c.current).onSelect)==null||T.call(C,u.current)}function g(){f.setState("value",u.current,!0)}if(!p)return null;let{disabled:x,value:y,onSelect:w,forceMount:k,keywords:I,...S}=e;return b.createElement(Ne.div,{ref:_n(s,t),...S,id:o,"cmdk-item":"",role:"option","aria-disabled":!!x,"aria-selected":!!h,"data-disabled":!!x,"data-selected":!!h,onPointerMove:x||a.getDisablePointerSelection()?void 0:g,onClick:x?void 0:m},e.children)}),eC=b.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:o,...s}=e,i=Rt(),a=b.useRef(null),c=b.useRef(null),l=Rt(),u=wo(),f=Dn(p=>o||u.filter()===!1?!0:p.search?p.filtered.groups.has(i):!0);nr(()=>u.group(i),[]),dp(i,a,[e.value,e.heading,c]);let h=b.useMemo(()=>({id:i,forceMount:o}),[o]);return b.createElement(Ne.div,{ref:_n(a,t),...s,"cmdk-group":"",role:"presentation",hidden:f?void 0:!0},n&&b.createElement("div",{ref:c,"cmdk-group-heading":"","aria-hidden":!0,id:l},n),$s(e,p=>b.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?l:void 0},b.createElement(lp.Provider,{value:h},p))))}),tC=b.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,o=b.useRef(null),s=Dn(i=>!i.search);return!n&&!s?null:b.createElement(Ne.div,{ref:_n(o,t),...r,"cmdk-separator":"",role:"separator"})}),nC=b.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,o=e.value!=null,s=Za(),i=Dn(l=>l.search),a=Dn(l=>l.selectedItemId),c=wo();return b.useEffect(()=>{e.value!=null&&s.setState("search",e.value)},[e.value]),b.createElement(Ne.input,{ref:t,...r,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":c.listId,"aria-labelledby":c.labelId,"aria-activedescendant":a,id:c.inputId,type:"text",value:o?e.value:i,onChange:l=>{o||s.setState("search",l.target.value),n==null||n(l.target.value)}})}),rC=b.forwardRef((e,t)=>{let{children:n,label:r="Suggestions",...o}=e,s=b.useRef(null),i=b.useRef(null),a=Dn(l=>l.selectedItemId),c=wo();return b.useEffect(()=>{if(i.current&&s.current){let l=i.current,u=s.current,f,h=new ResizeObserver(()=>{f=requestAnimationFrame(()=>{let p=l.offsetHeight;u.style.setProperty("--cmdk-list-height",p.toFixed(1)+"px")})});return h.observe(l),()=>{cancelAnimationFrame(f),h.unobserve(l)}}},[]),b.createElement(Ne.div,{ref:_n(s,t),...o,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":a,"aria-label":r,id:c.listId},$s(e,l=>b.createElement("div",{ref:_n(i,c.listInnerRef),"cmdk-list-sizer":""},l)))}),oC=b.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:o,contentClassName:s,container:i,...a}=e;return b.createElement(Oh,{open:n,onOpenChange:r},b.createElement(Mh,{container:i},b.createElement(La,{"cmdk-overlay":"",className:o}),b.createElement($a,{"aria-label":e.label,"cmdk-dialog":"",className:s},b.createElement(cp,{ref:t,...a}))))}),sC=b.forwardRef((e,t)=>Dn(n=>n.filtered.count===0)?b.createElement(Ne.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),iC=b.forwardRef((e,t)=>{let{progress:n,children:r,label:o="Loading...",...s}=e;return b.createElement(Ne.div,{ref:t,...s,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":o},$s(e,i=>b.createElement("div",{"aria-hidden":!0},i)))}),jt=Object.assign(cp,{List:rC,Item:QS,Input:nC,Group:eC,Separator:tC,Dialog:oC,Empty:sC,Loading:iC});function aC(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}function lC(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}function up(e){let t=b.useRef(e);return nr(()=>{t.current=e}),t}var nr=typeof window>"u"?b.useEffect:b.useLayoutEffect;function Rr(e){let t=b.useRef();return t.current===void 0&&(t.current=e()),t}function Dn(e){let t=Za(),n=()=>e(t.snapshot());return b.useSyncExternalStore(t.subscribe,n,n)}function dp(e,t,n,r=[]){let o=b.useRef(),s=wo();return nr(()=>{var i;let a=(()=>{var l;for(let u of n){if(typeof u=="string")return u.trim();if(typeof u=="object"&&"current"in u)return u.current?(l=u.current.textContent)==null?void 0:l.trim():o.current}})(),c=r.map(l=>l.trim());s.value(e,a,c),(i=t.current)==null||i.setAttribute(Pr,a),o.current=a}),o}var cC=()=>{let[e,t]=b.useState(),n=Rr(()=>new Map);return nr(()=>{n.current.forEach(r=>r()),n.current=new Map},[e]),(r,o)=>{n.current.set(r,o),t({})}};function uC(e){let t=e.type;return typeof t=="function"?t(e.props):"render"in t?t.render(e.props):e}function $s({asChild:e,children:t},n){return e&&b.isValidElement(t)?b.cloneElement(uC(t),{ref:t.ref},n(t.props.children)):n(t)}var dC={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};const fp=b.forwardRef(({className:e,...t},n)=>d.jsx(jt,{ref:n,className:pe("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",e),...t}));fp.displayName=jt.displayName;const hp=b.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(jt.Input,{ref:n,className:pe("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})]}));hp.displayName=jt.Input.displayName;const pp=b.forwardRef(({className:e,...t},n)=>d.jsx(jt.List,{ref:n,className:pe("max-h-[300px] overflow-y-auto overflow-x-hidden",e),...t}));pp.displayName=jt.List.displayName;const mp=b.forwardRef((e,t)=>d.jsx(jt.Empty,{ref:t,className:"py-6 text-center text-sm",...e}));mp.displayName=jt.Empty.displayName;const gp=b.forwardRef(({className:e,...t},n)=>d.jsx(jt.Group,{ref:n,className:pe("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}));gp.displayName=jt.Group.displayName;const fC=b.forwardRef(({className:e,...t},n)=>d.jsx(jt.Separator,{ref:n,className:pe("-mx-1 h-px bg-border",e),...t}));fC.displayName=jt.Separator.displayName;const xp=b.forwardRef(({className:e,...t},n)=>d.jsx(jt.Item,{ref:n,className:pe("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}));xp.displayName=jt.Item.displayName;function bp({thread:e,isActive:t=!1,editingThreadId:n,editingTitle:r="",onSelect:o,onStartEditing:s,onEditingTitleChange:i,onSaveEditing:a,onCancelEditing:c,onShare:l,onDelete:u,showEditTitle:f=!0,showDeleteButton:h=!0,onMenuOpenChange:p,onMenuAction:m,formatDate:g,getDisplayThreadTitle:x,itemClassName:y,activeItemClassName:w,secondaryLine:k}){const I=n===e.threadId,S=v.useMemo(()=>(x==null?void 0:x(e))??e.title??e.threadId,[x,e]),C=()=>o==null?void 0:o(e.threadId),T=A=>s==null?void 0:s(e,A);return d.jsxs("div",{className:pe("flex items-center justify-between rounded px-2 py-1 text-sm hover:bg-muted cursor-pointer",y,t&&(w??"bg-muted/70")),onClick:C,children:[d.jsxs("div",{className:"flex flex-col min-w-0",children:[I?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}),g&&e.updatedAt&&d.jsx("span",{className:"text-[10px] text-muted-foreground",children:g(e.updatedAt)})]}),d.jsx("div",{className:"flex items-center gap-1",children:I?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(),c==null||c(e)},children:"Cancel"})]}):d.jsxs(_a,{onOpenChange:A=>p==null?void 0:p(e.threadId,A),children:[d.jsx(Pa,{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(xe.MoreVertical,{className:"h-4 w-4"}),d.jsx("span",{className:"sr-only",children:"Open menu"})]})}),d.jsxs(js,{align:"end",children:[f&&d.jsxs(er,{onClick:A=>{A.stopPropagation(),m==null||m(e.threadId,"rename"),T(A)},children:[d.jsx(xe.Edit3,{className:"mr-2 h-4 w-4"}),d.jsx("span",{children:"Rename"})]}),l&&d.jsxs(er,{onClick:A=>{A.stopPropagation(),m==null||m(e.threadId,"share"),l(e)},children:[d.jsx(xe.Share2,{className:"mr-2 h-4 w-4"}),d.jsx("span",{children:"Share"})]}),h&&d.jsxs(er,{onClick:A=>{A.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 Fs="Collapsible",[hC,dT]=Pn(Fs),[pC,Qa]=hC(Fs),yp=b.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[c,l]=is({prop:r,defaultProp:o??!1,onChange:i,caller:Fs});return d.jsx(pC,{scope:n,disabled:s,contentId:Rt(),open:c,onOpenToggle:b.useCallback(()=>l(u=>!u),[l]),children:d.jsx(Ne.div,{"data-state":tl(c),"data-disabled":s?"":void 0,...a,ref:t})})});yp.displayName=Fs;var wp="CollapsibleTrigger",vp=b.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=Qa(wp,n);return d.jsx(Ne.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":tl(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:ve(e.onClick,o.onOpenToggle)})});vp.displayName=wp;var el="CollapsibleContent",Sp=b.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Qa(el,e.__scopeCollapsible);return d.jsx(Dt,{present:n||o.open,children:({present:s})=>d.jsx(mC,{...r,ref:t,present:s})})});Sp.displayName=el;var mC=b.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=Qa(el,n),[a,c]=b.useState(r),l=b.useRef(null),u=Ye(t,l),f=b.useRef(0),h=f.current,p=b.useRef(0),m=p.current,g=i.open||a,x=b.useRef(g),y=b.useRef(void 0);return b.useEffect(()=>{const w=requestAnimationFrame(()=>x.current=!1);return()=>cancelAnimationFrame(w)},[]),tn(()=>{const w=l.current;if(w){y.current=y.current||{transitionDuration:w.style.transitionDuration,animationName:w.style.animationName},w.style.transitionDuration="0s",w.style.animationName="none";const k=w.getBoundingClientRect();f.current=k.height,p.current=k.width,x.current||(w.style.transitionDuration=y.current.transitionDuration,w.style.animationName=y.current.animationName),c(r)}},[i.open,r]),d.jsx(Ne.div,{"data-state":tl(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!g,...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:g&&o})});function tl(e){return e?"open":"closed"}var gC=yp;const xC=gC,bC=vp,yC=Sp,Cp=25,Tp=vn.threadManagerView,wC=e=>e==="default"||e==="shared",vC=()=>{if(typeof window>"u")return null;try{const e=window.localStorage.getItem(Tp);if(wC(e))return e}catch{}return null};function kp({defaultView:e}={}){const[t,n]=v.useState(()=>vC()??e??"default");v.useEffect(()=>{if(!(typeof window>"u"))try{window.localStorage.setItem(Tp,t)}catch{}},[t]);const r=v.useCallback(o=>{n(o)},[]);return{view:t,setView:r}}const SC=[{key:"default",label:"My chats"},{key:"shared",label:"Shared with you"}];function zs({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,onItemMenuOpenChange:o,onItemMenuAction:s,maxHeight:i="400px",customStyles:a={},currentThreadId:c=null,navigateToThread:l,onThreadSelect:u,onThreadCreate:f,onThreadDelete:h,view:p,defaultView:m,onViewChange:g,viewOptions:x,viewState:y,showHeader:w=!0,shareTargets:k,isLoadingShareTargets:I,shareTargetFilter:S,groupBy:C,filter:T}){const{chatApi:A,authApi:j}=hr(),{threads:_,sharedThreads:L,currentThreadId:F,setCurrentThreadId:B,isLoading:O,isLoadingSharedThreads:G,actions:Y,shareInFlight:re,shareStatus:H,clearShareStatus:W}=Vr(),{createThread:ne,deleteThread:K,renameThread:M,shareThread:N}=Y,{loadThread:$}=qr(),D=c??F,[q,U]=v.useState(Array.isArray(_)?_:[]),P=v.useRef(q.length>0),V=v.useRef(null),ee=v.useRef(0),[ce,ue]=v.useState(null),[be,Ae]=v.useState(""),[Ie,Xe]=v.useState(!1),[ze,Ze]=v.useState(!1),[Be,dt]=v.useState(null),[at,ct]=v.useState(""),[ft,tt]=v.useState([]),[nt,ut]=v.useState(!1),qe=v.useCallback(R=>Ae(R),[]);v.useEffect(()=>{ze&&!k&&ft.length===0&&!nt&&(async()=>{ut(!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}));tt(se)}catch(X){console.error("Failed to load users for sharing:",X)}finally{ut(!1)}})()},[ze,k,ft.length,nt,A]);const Qe=k??ft,De=I??nt,Le=x&&x.length>0?x:SC,et=kp({defaultView:m}),ht=y??et,rr=p??ht.view,Yt=v.useCallback(R=>{p||ht.setView(R),g==null||g(R)},[p,g,ht]),Ln=Le.find(R=>R.key===rr)??Le[0],Xt=R=>{dt(R),ct(""),Ze(!0)},Lt=()=>{Ze(!1),dt(null),ct(""),W()},xn=v.useCallback(async R=>{if(!(!Be||re)&&R.id)try{await N(Be,R.id),setTimeout(()=>Lt(),600)}catch(X){console.error("Failed to share thread:",X)}},[Lt,re,Be,N]),or=v.useMemo(()=>{const R=Qe,X=at.trim().toLowerCase();return X?S?R.filter(se=>S(se,X)):R.filter(se=>`${se.label} ${se.secondaryLabel??""}`.toLowerCase().includes(X)):R},[k,at,S]),pt=rr==="shared",$n=pt?L:q,cn=T?$n.filter(T):$n,Ue=v.useMemo(()=>{const R=Array.isArray(C)?C:[];if(R.length===0||pt)return null;const X="Default",se=fe=>{if(!fe)return"Older";try{const Pe=fe.endsWith("Z")||fe.includes("+")?fe:`${fe}Z`,_e=new Date(Pe),Fe=new Date,mt=new Date(Fe.getFullYear(),Fe.getMonth(),Fe.getDate()),fn=new Date(_e.getFullYear(),_e.getMonth(),_e.getDate()),lr=Math.floor((mt.getTime()-fn.getTime())/(1e3*60*60*24));return lr===0?"Today":lr===1?"Yesterday":lr<=7?"Last 7 Days":"Older"}catch{return"Older"}},ie=(fe,Pe)=>{var Fe,mt;if(Pe==="project")return((Fe=fe.project)==null?void 0:Fe.name)||((mt=fe.project)==null?void 0:mt.id)||X;if(Pe==="menuItem")return fe.menuItem||X;if(Pe==="updatedAt"||Pe==="createdAt"){const fn=Pe==="updatedAt"?fe.updatedAt:fe.createdAt;return se(fn)}const _e=fe[Pe];return typeof _e=="string"?_e||X:typeof _e=="number"?String(_e):_e==null?X:String(_e)},de=(fe,Pe)=>{const _e={};return fe.forEach(Fe=>{const mt=ie(Fe,Pe);_e[mt]||(_e[mt]=[]),_e[mt].push(Fe)}),_e},Re=(fe,Pe)=>{if(Pe.length===0)return fe;const[_e,...Fe]=Pe,mt=de(fe,_e);if(Fe.length===0)return mt;const fn={};return Object.entries(mt).forEach(([lr,MC])=>{fn[lr]=Re(MC,Fe)}),fn},Oe=fe=>{if(Array.isArray(fe)){fe.sort((Pe,_e)=>new Date(_e.updatedAt||_e.createdAt||"").getTime()-new Date(Pe.updatedAt||Pe.createdAt||"").getTime());return}Object.values(fe).forEach(Oe)},ke=Re(cn,R);return Oe(ke),{kind:"nested",groups:ke}},[cn,C,pt]),st=pt?G:O,bn=pt?"No shared conversations yet":"No conversations yet",yn=R=>{const X=R.sharedAt?` • ${wn(R.sharedAt)}`:"";return`Shared by ${R.sharedByUserId}${X}`},un=R=>"sharedByUserId"in R;v.useEffect(()=>{const R=Array.isArray(_)?_:[];if(R.length>0){P.current=!0,U(R);return}O||(P.current=!1,U(R))},[_,O]),v.useEffect(()=>{if(!V.current)return;const R=V.current.querySelector("[data-radix-scroll-area-viewport]");if(!R)return;let X=null,se=null;return X=requestAnimationFrame(()=>{se=requestAnimationFrame(()=>{R.scrollTop=ee.current})}),()=>{X!==null&&cancelAnimationFrame(X),se!==null&&cancelAnimationFrame(se)}},[q]);const dn=async R=>{try{B(R),await $(R),l==null||l(R),u==null||u(R)}catch(X){console.error("Failed to select thread:",X)}},sr=async()=>{try{Xe(!0);const R=await ne();R&&(f==null||f(R),l==null||l(R))}catch(R){console.error("Failed to create thread:",R)}finally{Xe(!1)}},Or=async(R,X)=>{const se=R.threadId;if(confirm("Delete this thread?")){if(V.current){const ie=V.current.querySelector("[data-radix-scroll-area-viewport]");ie&&(ee.current=ie.scrollTop)}try{await K(se),h==null||h(se)}catch(ie){console.error("Failed to delete thread:",ie)}}},ir=(R,X)=>{X==null||X.stopPropagation(),ue(R.threadId),Ae(R.title||`Thread ${R.threadId.slice(0,8)}`)},Fn=async R=>{const X=typeof R=="string"?R:R.threadId;if(be.trim())try{await M(X,be.trim()),ue(null),Ae("")}catch(se){console.error("Failed to update title:",se)}},zn=R=>{ue(null),Ae("")},wn=R=>{if(!R)return"";try{const X=R.endsWith("Z")||R.includes("+")?R:`${R}Z`,se=new Date(X),de=new Date().getTime()-se.getTime(),Re=Math.floor(de/(1e3*60*60*24));return Re===0?se.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):Re===1?"Yesterday":Re<7?`${Re} days ago`:se.toLocaleDateString()}catch{return""}},$t=R=>R.title||`Thread ${R.threadId.slice(0,8)}`,ar=R=>{const X=$t(R);return X.length<=Cp?X:`${X.slice(0,Cp)}...`},E=R=>Array.isArray(R)?R.length:Object.values(R).reduce((X,se)=>Array.isArray(se)?X+se.length:X+E(se),0),Z=R=>{const se=["Today","Yesterday","Last 7 Days","Older"].indexOf(R);return se===-1?null:se},oe=(R,X,se)=>{if(Array.isArray(R))return R.map(ke=>d.jsx(bp,{thread:ke,isActive:D===ke.threadId,editingThreadId:ce,editingTitle:be,onSelect:dn,onStartEditing:ir,onEditingTitleChange:qe,onSaveEditing:fe=>void Fn(fe),onCancelEditing:()=>zn(),onShare:fe=>Xt(fe.threadId),onDelete:fe=>Or(fe),showEditTitle:r,showDeleteButton:n,onMenuOpenChange:o,onMenuAction:s,formatDate:wn,getDisplayThreadTitle:ar,secondaryLine:pt&&un(ke)?yn(ke):void 0,itemClassName:a.threadItem,activeItemClassName:a.activeThread},ke.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"],de="pl-2 border-l border-slate-100 dark:border-slate-800 ml-1.5 my-1 space-y-1",Re=ie[X]??ie[ie.length-1],Oe=Object.entries(R);if(Oe.length===1){const[ke,fe]=Oe[0];return oe(fe,X+1,`${se}-${ke}`)}return Oe.sort(([ke],[fe])=>{const Pe="Default";if(ke===Pe)return 1;if(fe===Pe)return-1;const _e=Z(ke),Fe=Z(fe);if(_e!==null||Fe!==null){const mt=_e??Number.MAX_SAFE_INTEGER,fn=Fe??Number.MAX_SAFE_INTEGER;return mt-fn}return ke.localeCompare(fe)}).map(([ke,fe])=>{const Pe=`${se}-${ke}`,_e=E(fe);return d.jsxs(xC,{defaultOpen:!0,className:"group/collapsible",children:[d.jsxs(bC,{className:Re,children:[d.jsx(xe.ChevronRight,{className:"w-3 h-3 mr-1 transition-transform group-data-[state=open]/collapsible:rotate-90"}),ke,d.jsx("span",{className:"ml-auto text-[10px] text-slate-400",children:_e})]}),d.jsx(yC,{children:d.jsx("div",{className:de,children:oe(fe,X+1,Pe)})})]},Pe)})};return d.jsxs("div",{className:`thread-manager-root flex flex-col h-full ${e} ${a.container||""}`,children:[w&&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:sr,disabled:Ie||O,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(_a,{children:[d.jsx(Pa,{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:Ln.label})}),d.jsx(js,{align:"start",sideOffset:6,className:"w-40",children:Le.map(R=>d.jsxs(er,{className:"justify-between text-[12px]",onClick:X=>{X.preventDefault(),Yt(R.key)},children:[d.jsx("span",{children:R.label}),rr===R.key&&d.jsx(xe.Check,{className:"h-3 w-3"})]},R.key))})]})]})]}),d.jsx(Ka,{ref:V,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:st?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…"})]}):cn.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:bn})]}):(Ue==null?void 0:Ue.kind)==="nested"?oe(Ue.groups,0,"group"):cn.slice().sort((R,X)=>new Date(X.updatedAt||X.createdAt||"").getTime()-new Date(R.updatedAt||R.createdAt||"").getTime()).map(R=>d.jsx(bp,{thread:R,isActive:D===R.threadId,editingThreadId:ce,editingTitle:be,onSelect:dn,onStartEditing:ir,onEditingTitleChange:qe,onSaveEditing:X=>void Fn(X),onCancelEditing:X=>zn(),onShare:X=>Xt(X.threadId),onDelete:X=>Or(X),showEditTitle:r,showDeleteButton:n,onMenuOpenChange:o,onMenuAction:s,formatDate:wn,getDisplayThreadTitle:ar,secondaryLine:pt&&un(R)?yn(R):void 0,itemClassName:a.threadItem,activeItemClassName:a.activeThread},R.threadId))})}),d.jsx(Lh,{open:ze,onOpenChange:R=>!R&&Lt(),children:d.jsxs(Fa,{className:"max-w-md p-0",children:[d.jsx(za,{children:d.jsx(Ba,{children:"Share thread"})}),d.jsxs(fp,{children:[d.jsx(hp,{autoFocus:!0,value:at,onValueChange:R=>ct(R),placeholder:"Search for recipients..."}),d.jsxs(pp,{children:[H&&d.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 text-xs text-muted-foreground",children:[re&&d.jsx(xe.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(mp,{children:De?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"}),or.length>0&&d.jsx(gp,{heading:"Recipients",children:or.map(R=>d.jsx(xp,{onSelect:()=>xn(R),children:d.jsxs("div",{className:"flex flex-col items-start text-sm",children:[d.jsx("span",{className:"font-medium",children:R.label}),R.secondaryLabel&&d.jsx("span",{className:"text-xs text-muted-foreground",children:R.secondaryLabel})]})},R.id))})]})]})]})})]})}function CC({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`}},c=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"}),l=v.useCallback(u=>{var f;(f=i.onThreadChange)==null||f.call(i,u)},[i]);return e==="fullscreen"?d.jsx(Gr,{...i,onThreadChange:l,children:d.jsx("div",{className:`${a(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:c(t),children:d.jsx(_r,{className:"flex-1",onError:i.onError,enableFileUpload:!0,payloadExtras:s})})}):e==="tabs"?d.jsx(Gr,{...i,onThreadChange:l,children:d.jsx("div",{className:`${a(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:c(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(zs,{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:l,children:d.jsxs("div",{className:`${a(t)} flex overflow-hidden ${r} ${o.container||""}`,style:c(t),children:[n&&d.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:d.jsx(zs,{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 TC=1,kC=1e6;let nl=0;function EC(){return nl=(nl+1)%Number.MAX_SAFE_INTEGER,nl.toString()}const rl=new Map,Ep=e=>{if(rl.has(e))return;const t=setTimeout(()=>{rl.delete(e),vo({type:"REMOVE_TOAST",toastId:e})},kC);rl.set(e,t)},IC=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,TC)};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?Ep(n):e.toasts.forEach(r=>{Ep(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)}}},Bs=[];let Us={toasts:[]};function vo(e){Us=IC(Us,e),Bs.forEach(t=>{t(Us)})}function AC({...e}){const t=EC(),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 NC(){const[e,t]=b.useState(Us);return b.useEffect(()=>(Bs.push(t),()=>{const n=Bs.indexOf(t);n>-1&&Bs.splice(n,1)}),[e]),{...e,toast:AC,dismiss:n=>vo({type:"DISMISS_TOAST",toastId:n})}}function jC(e){const{allowFileOpen:t,currentThreadId:n}=e,{fileApi:r}=hr(),{toast:o}=NC(),[s,i]=v.useState({}),[a,c]=v.useState(null),[l,u]=v.useState(!1),f=v.useCallback(()=>{u(!1),c(null)},[]),h=v.useCallback(m=>{c(m),u(!0)},[]),p=v.useCallback(async(m,g,x)=>{var y,w;if(!t){m.preventDefault();return}if(s[x]){m.preventDefault();return}try{const k=String(g.url??""),I=k.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(I){m.preventDefault();const S=I[1],C=g.name||`file_${S}`,T=g.mimeType||"application/octet-stream";h({id:S,name:C,mimeType:T});return}if(k.startsWith("data:")){m.preventDefault(),i(C=>({...C,[x]:!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??"")===(g.name??""))?!1:typeof g.size=="number"&&typeof A.size=="number"?A.size===g.size:!0);if(!(T!=null&&T.id))throw new Error(`File "${g.name}" is not yet available on the server`);if(!T.id||!T.filename)throw new Error("Invalid file data received from server");h({id:T.id,name:g.name||T.filename||`file_${T.id}`,mimeType:g.mimeType||T.mime_type||"application/octet-stream"}),(y=S.update)==null||y.call(S,{id:S.id,title:"Success",description:`Opened ${g.name}`,open:!0})}catch(C){console.error("Failed to fetch server file:",C);const T=C instanceof Error?C.message:"Unknown error occurred";(w=S.update)==null||w.call(S,{id:S.id,title:"Failed",description:T}),o({title:"Failed to fetch file",description:T,open:!0})}finally{i(C=>({...C,[x]:!1}))}}}catch(k){console.error("File click error:",k),i(I=>({...I,[x]:!1}))}},[t,s,o,n,h]);return{uploadingFiles:s,handleFileClick:p,fileViewerOpen:l,currentFileInfo:a,closeFileViewer:f}}function _C(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:pc(t),imageParts:n.filter(o=>o.type==="image_url"),fileParts:n.filter(o=>o.type==="file"),interruptParts:n.filter(o=>o.type==="interrupt"),toolRaw:mc(n),isToolStreaming:!!r.toolStreaming}},[e])}function PC({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(_r,{placeholder:e??"Ask Serti AI anything...",className:"h-full",onMessageSent:t}):d.jsx(zs,{showCreateButton:!0,className:"h-full",onThreadSelect:()=>r("chat")})})]})}function RC({className:e="",placeholder:t,isAuthenticated:n=!0,onMessageSent:r,widgetTitle:o="Serti AI Navigator",widgetSubtitle:s="AI-Powered Assistant",...i}){const[a,c]=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(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:l=>{l.stopPropagation(),c(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(PC,{placeholder:t,onMessageSent:r})})]})})}):null}function OC({label:e="New chat",children:t,className:n,variant:r="ghost",size:o="sm",...s}){return d.jsxs(Je,{variant:r,size:o,className:pe("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=tc,J.AssistantMessageComponent=Vi,J.ChatApi=Xl,J.ChatApp=CC,J.ChatContainer=_r,J.ChatInput=Ra,J.ChatInputArea=_s,J.ChatInputRow=_s,J.ChatInterface=_r,J.ChatMessagesArea=ss,J.ChatProviders=Gr,J.ChatUIProvider=Ic,J.ChatWidget=RC,J.Composer=Ra,J.DEFAULT_TIMEOUT_MS=ql,J.FileApi=Jl,J.HISTORY_TIMEOUT_MS=Gl,J.MarkdownContent=so,J.MessageBubble=ao,J.MessageHeader=Hi,J.MessageList=ss,J.NewChatButton=OC,J.SETTINGS_STORAGE_KEY=mi,J.STORAGE_KEYS=vn,J.SystemMessageComponent=qi,J.ThreadManager=zs,J.ThreadStateProvider=kc,J.ThreadsProvider=fc,J.ToolCallCard=Fi,J.ToolContent=Qo,J.ToolProgress=Bu,J.UserMessageComponent=Ki,J.applySettings=sx,J.chatApiClient=Cn,J.cn=Np,J.createTaskSyncToolEndHandler=rx,J.del=oi,J.draftKey=Po,J.extractTaskIdFromToolEnd=Rc,J.extractToolCalls=ai,J.extractToolContent=Wr,J.fileApiClient=si,J.fileToBase64=nc,J.formatToolOutput=Ng,J.get=At,J.getChatToken=ni,J.getCurrentSettings=ox,J.getDefaultApiConfig=Lc,J.getDefaultChatSettings=$c,J.getToolCallArtifacts=Rg,J.getToolCalls=ui,J.hasContent=jg,J.httpClient=vt,J.isEnvelope=cc,J.isFileLike=li,J.loadStoredSettings=Fc,J.looksLikeMarkdown=ic,J.normalizeToolPayload=gc,J.normalizeToolPayloadValue=xr,J.onChatTokenChanged=ri,J.parseJsonSafe=pr,J.post=zr,J.pretty=gr,J.processAttachments=rc,J.put=Yl,J.sanitizeForDisplay=Kr,J.saveSettings=zc,J.setChatToken=Sn,J.stringifyTool=mc,J.unwrap=St,J.useApi=hr,J.useChatController=bh,J.useChatUI=Fo,J.useFilePreview=jC,J.useHasChatSession=tx,J.useParsedMessageContent=_C,J.useShallowStableValue=Pc,J.useStream=pi,J.useStreamingMarkdownBuffer=ad,J.useThreadHistoryState=vc,J.useThreadManagerViewState=kp,J.useThreadState=qr,J.useThreadStateUpdater=Tc,J.useThreads=Vr,J.useThreadsState=uc,J.useToolPayload=zu,Object.defineProperty(J,Symbol.toStringTag,{value:"Module"})});
132
132
  //# sourceMappingURL=index.umd.js.map