teodor-new-chat-ui 4.3.16 → 4.3.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +3560 -3590
- package/dist/index.umd.js +42 -43
- package/dist/lib/chat-api.d.ts +1 -15
- package/dist/types/api.d.ts +28 -19
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(_e,w){typeof exports=="object"&&typeof module<"u"?w(exports,require("react"),require("lucide-react"),require("@radix-ui/react-slot"),require("class-variance-authority"),require("clsx"),require("tailwind-merge"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react","lucide-react","@radix-ui/react-slot","class-variance-authority","clsx","tailwind-merge","react-dom"],w):(_e=typeof globalThis<"u"?globalThis:_e||self,w(_e.NewChatUI={},_e.React,_e.LucideReact,_e.reactSlot,_e.classVarianceAuthority,_e.clsx,_e.tailwindMerge,_e.ReactDOM))})(this,function(_e,w,ie,tr,No,Cm,Tm,ui){"use strict";var _T=Object.defineProperty;var jT=(_e,w,ie)=>w in _e?_T(_e,w,{enumerable:!0,configurable:!0,writable:!0,value:ie}):_e[w]=ie;var wm=(_e,w,ie)=>jT(_e,typeof w!="symbol"?w+"":w,ie);function bl(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 m=bl(w),Ao=bl(ui);var di={exports:{}},Ur={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var
|
|
9
|
+
*/var wl;function km(){if(wl)return Ur;wl=1;var e=w,t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,o=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function i(a,l,u){var d,f={},h=null,p=null;u!==void 0&&(h=""+u),l.key!==void 0&&(h=""+l.key),l.ref!==void 0&&(p=l.ref);for(d in l)r.call(l,d)&&!s.hasOwnProperty(d)&&(f[d]=l[d]);if(a&&a.defaultProps)for(d in l=a.defaultProps,l)f[d]===void 0&&(f[d]=l[d]);return{$$typeof:t,type:a,key:h,ref:p,props:f,_owner:o.current}}return Ur.Fragment=n,Ur.jsx=i,Ur.jsxs=i,Ur}var Wr={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,42 +14,41 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var
|
|
18
|
-
`+G+k}}var
|
|
19
|
-
`),
|
|
20
|
-
`),nt=ze.length-1,ht=
|
|
21
|
-
`+ze[nt].replace(" at new "," at ");return k.displayName&&
|
|
17
|
+
*/var Sl;function Em(){return Sl||(Sl=1,process.env.NODE_ENV!=="production"&&function(){var e=w,t=Symbol.for("react.element"),n=Symbol.for("react.portal"),r=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),i=Symbol.for("react.provider"),a=Symbol.for("react.context"),l=Symbol.for("react.forward_ref"),u=Symbol.for("react.suspense"),d=Symbol.for("react.suspense_list"),f=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),p=Symbol.for("react.offscreen"),v=Symbol.iterator,x="@@iterator";function g(k){if(k===null||typeof k!="object")return null;var W=v&&k[v]||k[x];return typeof W=="function"?W:null}var y=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(k){{for(var W=arguments.length,oe=new Array(W>1?W-1:0),ke=1;ke<W;ke++)oe[ke-1]=arguments[ke];S("error",k,oe)}}function S(k,W,oe){{var ke=y.ReactDebugCurrentFrame,qe=ke.getStackAddendum();qe!==""&&(W+="%s",oe=oe.concat([qe]));var Ge=oe.map(function(Be){return String(Be)});Ge.unshift("Warning: "+W),Function.prototype.apply.call(console[k],console,Ge)}}var I=!1,C=!1,T=!1,E=!1,A=!1,j;j=Symbol.for("react.module.reference");function P(k){return!!(typeof k=="string"||typeof k=="function"||k===r||k===s||A||k===o||k===u||k===d||E||k===p||I||C||T||typeof k=="object"&&k!==null&&(k.$$typeof===h||k.$$typeof===f||k.$$typeof===i||k.$$typeof===a||k.$$typeof===l||k.$$typeof===j||k.getModuleId!==void 0))}function D(k,W,oe){var ke=k.displayName;if(ke)return ke;var qe=W.displayName||W.name||"";return qe!==""?oe+"("+qe+")":oe}function L(k){return k.displayName||"Context"}function V(k){if(k==null)return null;if(typeof k.tag=="number"&&b("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof k=="function")return k.displayName||k.name||null;if(typeof k=="string")return k;switch(k){case r:return"Fragment";case n:return"Portal";case s:return"Profiler";case o:return"StrictMode";case u:return"Suspense";case d:return"SuspenseList"}if(typeof k=="object")switch(k.$$typeof){case a:var W=k;return L(W)+".Consumer";case i:var oe=k;return L(oe._context)+".Provider";case l:return D(k,k.render,"ForwardRef");case f:var ke=k.displayName||null;return ke!==null?ke:V(k.type)||"Memo";case h:{var qe=k,Ge=qe._payload,Be=qe._init;try{return V(Be(Ge))}catch{return null}}}return null}var M=Object.assign,X=0,K,q,z,$,pe,F,te;function fe(){}fe.__reactDisabledLog=!0;function ge(){{if(X===0){K=console.log,q=console.info,z=console.warn,$=console.error,pe=console.group,F=console.groupCollapsed,te=console.groupEnd;var k={configurable:!0,enumerable:!0,value:fe,writable:!0};Object.defineProperties(console,{info:k,log:k,warn:k,error:k,group:k,groupCollapsed:k,groupEnd:k})}X++}}function be(){{if(X--,X===0){var k={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:M({},k,{value:K}),info:M({},k,{value:q}),warn:M({},k,{value:z}),error:M({},k,{value:$}),group:M({},k,{value:pe}),groupCollapsed:M({},k,{value:F}),groupEnd:M({},k,{value:te})})}X<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var Te=y.ReactCurrentDispatcher,G;function O(k,W,oe){{if(G===void 0)try{throw Error()}catch(qe){var ke=qe.stack.trim().match(/\n( *(at )?)/);G=ke&&ke[1]||""}return`
|
|
18
|
+
`+G+k}}var Q=!1,ne;{var de=typeof WeakMap=="function"?WeakMap:Map;ne=new de}function ae(k,W){if(!k||Q)return"";{var oe=ne.get(k);if(oe!==void 0)return oe}var ke;Q=!0;var qe=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var Ge;Ge=Te.current,Te.current=null,ge();try{if(W){var Be=function(){throw Error()};if(Object.defineProperty(Be.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(Be,[])}catch(Et){ke=Et}Reflect.construct(k,[],Be)}else{try{Be.call()}catch(Et){ke=Et}k.call(Be.prototype)}}else{try{throw Error()}catch(Et){ke=Et}k()}}catch(Et){if(Et&&ke&&typeof Et.stack=="string"){for(var ze=Et.stack.split(`
|
|
19
|
+
`),Ct=ke.stack.split(`
|
|
20
|
+
`),nt=ze.length-1,ht=Ct.length-1;nt>=1&&ht>=0&&ze[nt]!==Ct[ht];)ht--;for(;nt>=1&&ht>=0;nt--,ht--)if(ze[nt]!==Ct[ht]){if(nt!==1||ht!==1)do if(nt--,ht--,ht<0||ze[nt]!==Ct[ht]){var Mt=`
|
|
21
|
+
`+ze[nt].replace(" at new "," at ");return k.displayName&&Mt.includes("<anonymous>")&&(Mt=Mt.replace("<anonymous>",k.displayName)),typeof k=="function"&&ne.set(k,Mt),Mt}while(nt>=1&&ht>=0);break}}}finally{Q=!1,Te.current=Ge,be(),Error.prepareStackTrace=qe}var Dn=k?k.displayName||k.name:"",In=Dn?O(Dn):"";return typeof k=="function"&&ne.set(k,In),In}function Ue(k,W,oe){return ae(k,!1)}function Ze(k){var W=k.prototype;return!!(W&&W.isReactComponent)}function me(k,W,oe){if(k==null)return"";if(typeof k=="function")return ae(k,Ze(k));if(typeof k=="string")return O(k);switch(k){case u:return O("Suspense");case d:return O("SuspenseList")}if(typeof k=="object")switch(k.$$typeof){case l:return Ue(k.render);case f:return me(k.type,W,oe);case h:{var ke=k,qe=ke._payload,Ge=ke._init;try{return me(Ge(qe),W,oe)}catch{}}}return""}var Pe=Object.prototype.hasOwnProperty,Le={},ct=y.ReactDebugCurrentFrame;function rt(k){if(k){var W=k._owner,oe=me(k.type,k._source,W?W.type:null);ct.setExtraStackFrame(oe)}else ct.setExtraStackFrame(null)}function vt(k,W,oe,ke,qe){{var Ge=Function.call.bind(Pe);for(var Be in k)if(Ge(k,Be)){var ze=void 0;try{if(typeof k[Be]!="function"){var Ct=Error((ke||"React class")+": "+oe+" type `"+Be+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof k[Be]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw Ct.name="Invariant Violation",Ct}ze=k[Be](W,Be,ke,oe,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(nt){ze=nt}ze&&!(ze instanceof Error)&&(rt(qe),b("%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).",ke||"React class",oe,Be,typeof ze),rt(null)),ze instanceof Error&&!(ze.message in Le)&&(Le[ze.message]=!0,rt(qe),b("Failed %s type: %s",oe,ze.message),rt(null))}}}var wt=Array.isArray;function B(k){return wt(k)}function se(k){{var W=typeof Symbol=="function"&&Symbol.toStringTag,oe=W&&k[Symbol.toStringTag]||k.constructor.name||"Object";return oe}}function we(k){try{return Ie(k),!1}catch{return!0}}function Ie(k){return""+k}function ye(k){if(we(k))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",se(k)),Ie(k)}var je=y.ReactCurrentOwner,Qe={key:!0,ref:!0,__self:!0,__source:!0},Fe,pt;function St(k){if(Pe.call(k,"ref")){var W=Object.getOwnPropertyDescriptor(k,"ref").get;if(W&&W.isReactWarning)return!1}return k.ref!==void 0}function en(k){if(Pe.call(k,"key")){var W=Object.getOwnPropertyDescriptor(k,"key").get;if(W&&W.isReactWarning)return!1}return k.key!==void 0}function Ft(k,W){typeof k.ref=="string"&&je.current}function dn(k,W){{var oe=function(){Fe||(Fe=!0,b("%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)",W))};oe.isReactWarning=!0,Object.defineProperty(k,"key",{get:oe,configurable:!0})}}function En(k,W){{var oe=function(){pt||(pt=!0,b("%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)",W))};oe.isReactWarning=!0,Object.defineProperty(k,"ref",{get:oe,configurable:!0})}}var zr=function(k,W,oe,ke,qe,Ge,Be){var ze={$$typeof:t,type:k,key:W,ref:oe,props:Be,_owner:Ge};return ze._store={},Object.defineProperty(ze._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(ze,"_self",{configurable:!1,enumerable:!1,writable:!1,value:ke}),Object.defineProperty(ze,"_source",{configurable:!1,enumerable:!1,writable:!1,value:qe}),Object.freeze&&(Object.freeze(ze.props),Object.freeze(ze)),ze};function Jn(k,W,oe,ke,qe){{var Ge,Be={},ze=null,Ct=null;oe!==void 0&&(ye(oe),ze=""+oe),en(W)&&(ye(W.key),ze=""+W.key),St(W)&&(Ct=W.ref,Ft(W,qe));for(Ge in W)Pe.call(W,Ge)&&!Qe.hasOwnProperty(Ge)&&(Be[Ge]=W[Ge]);if(k&&k.defaultProps){var nt=k.defaultProps;for(Ge in nt)Be[Ge]===void 0&&(Be[Ge]=nt[Ge])}if(ze||Ct){var ht=typeof k=="function"?k.displayName||k.name||"Unknown":k;ze&&dn(Be,ht),Ct&&En(Be,ht)}return zr(k,ze,Ct,qe,ke,je.current,Be)}}var tn=y.ReactCurrentOwner,Mn=y.ReactDebugCurrentFrame;function Ot(k){if(k){var W=k._owner,oe=me(k.type,k._source,W?W.type:null);Mn.setExtraStackFrame(oe)}else Mn.setExtraStackFrame(null)}var Zn;Zn=!1;function Br(k){return typeof k=="object"&&k!==null&&k.$$typeof===t}function Hr(){{if(tn.current){var k=V(tn.current.type);if(k)return`
|
|
22
22
|
|
|
23
|
-
Check the render method of \``+k+"`."}return""}}function he(k){return""}var
|
|
23
|
+
Check the render method of \``+k+"`."}return""}}function he(k){return""}var ve={};function et(k){{var W=Hr();if(!W){var oe=typeof k=="string"?k:k.displayName||k.name;oe&&(W=`
|
|
24
24
|
|
|
25
|
-
Check the top-level render call using <`+oe+">.")}return W}}function dt(k,W){{if(!k._store||k._store.validated||k.key!=null)return;k._store.validated=!0;var oe=et(W);if(
|
|
25
|
+
Check the top-level render call using <`+oe+">.")}return W}}function dt(k,W){{if(!k._store||k._store.validated||k.key!=null)return;k._store.validated=!0;var oe=et(W);if(ve[oe])return;ve[oe]=!0;var ke="";k&&k._owner&&k._owner!==tn.current&&(ke=" It was passed a child from "+V(k._owner.type)+"."),Ot(k),b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',oe,ke),Ot(null)}}function ft(k,W){{if(typeof k!="object")return;if(B(k))for(var oe=0;oe<k.length;oe++){var ke=k[oe];Br(ke)&&dt(ke,W)}else if(Br(k))k._store&&(k._store.validated=!0);else if(k){var qe=g(k);if(typeof qe=="function"&&qe!==k.entries)for(var Ge=qe.call(k),Be;!(Be=Ge.next()).done;)Br(Be.value)&&dt(Be.value,W)}}}function nn(k){{var W=k.type;if(W==null||typeof W=="string")return;var oe;if(typeof W=="function")oe=W.propTypes;else if(typeof W=="object"&&(W.$$typeof===l||W.$$typeof===f))oe=W.propTypes;else return;if(oe){var ke=V(W);vt(oe,k.props,"prop",ke,k)}else if(W.PropTypes!==void 0&&!Zn){Zn=!0;var qe=V(W);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",qe||"Unknown")}typeof W.getDefaultProps=="function"&&!W.getDefaultProps.isReactClassApproved&&b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function br(k){{for(var W=Object.keys(k.props),oe=0;oe<W.length;oe++){var ke=W[oe];if(ke!=="children"&&ke!=="key"){Ot(k),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",ke),Ot(null);break}}k.ref!==null&&(Ot(k),b("Invalid attribute `ref` supplied to `React.Fragment`."),Ot(null))}}var Co={};function fn(k,W,oe,ke,qe,Ge){{var Be=P(k);if(!Be){var ze="";(k===void 0||typeof k=="object"&&k!==null&&Object.keys(k).length===0)&&(ze+=" 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 Ct=he();Ct?ze+=Ct:ze+=Hr();var nt;k===null?nt="null":B(k)?nt="array":k!==void 0&&k.$$typeof===t?(nt="<"+(V(k.type)||"Unknown")+" />",ze=" Did you accidentally export a JSX literal instead of a component?"):nt=typeof k,b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",nt,ze)}var ht=Jn(k,W,oe,qe,Ge);if(ht==null)return ht;if(Be){var Mt=W.children;if(Mt!==void 0)if(ke)if(B(Mt)){for(var Dn=0;Dn<Mt.length;Dn++)ft(Mt[Dn],k);Object.freeze&&Object.freeze(Mt)}else b("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 ft(Mt,k)}if(Pe.call(W,"key")){var In=V(k),Et=Object.keys(W).filter(function(li){return li!=="key"}),Nn=Et.length>0?"{key: someKey, "+Et.join(": ..., ")+": ...}":"{key: someKey}";if(!Co[In+Nn]){var ai=Et.length>0?"{"+Et.join(": ..., ")+": ...}":"{}";b(`A props object containing a "key" prop is being spread into JSX:
|
|
26
26
|
let props = %s;
|
|
27
27
|
<%s {...props} />
|
|
28
28
|
React keys must be passed directly to JSX without using spread:
|
|
29
29
|
let props = %s;
|
|
30
|
-
<%s key={someKey} {...props} />`,Vr,_n,Kr,_n),No[_n+Vr]=!0}}return k===r?wr(ht):on(ht),ht}}function Ao(k,W,oe){return pn(k,W,oe,!0)}function er(k,W,oe){return pn(k,W,oe,!1)}var tr=er,_o=Ao;Yr.Fragment=r,Yr.jsx=tr,Yr.jsxs=_o}()),Yr}process.env.NODE_ENV==="production"?fi.exports=km():fi.exports=Em();var c=fi.exports;function Tl(e,t){return function(){return e.apply(t,arguments)}}const{toString:Im}=Object.prototype,{getPrototypeOf:hi}=Object,{iterator:Po,toStringTag:kl}=Symbol,Oo=(e=>t=>{const n=Im.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),sn=e=>(e=e.toLowerCase(),t=>Oo(t)===e),Mo=e=>t=>typeof t===e,{isArray:Tr}=Array,kr=Mo("undefined");function Xr(e){return e!==null&&!kr(e)&&e.constructor!==null&&!kr(e.constructor)&&Lt(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const El=sn("ArrayBuffer");function Nm(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&El(e.buffer),t}const Am=Mo("string"),Lt=Mo("function"),Il=Mo("number"),Jr=e=>e!==null&&typeof e=="object",_m=e=>e===!0||e===!1,Do=e=>{if(Oo(e)!=="object")return!1;const t=hi(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(kl in e)&&!(Po in e)},jm=e=>{if(!Jr(e)||Xr(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Rm=sn("Date"),Pm=sn("File"),Om=sn("Blob"),Mm=sn("FileList"),Dm=e=>Jr(e)&&Lt(e.pipe),Lm=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||Lt(e.append)&&((t=Oo(e))==="formdata"||t==="object"&&Lt(e.toString)&&e.toString()==="[object FormData]"))},$m=sn("URLSearchParams"),[Fm,zm,Bm,Hm]=["ReadableStream","Request","Response","Headers"].map(sn),Um=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Zr(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),Tr(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(Xr(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 Nl(e,t){if(Xr(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 rr=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,Al=e=>!kr(e)&&e!==rr;function pi(){const{caseless:e,skipUndefined:t}=Al(this)&&this||{},n={},r=(o,s)=>{const i=e&&Nl(n,s)||s;Do(n[i])&&Do(o)?n[i]=pi(n[i],o):Do(o)?n[i]=pi({},o):Tr(o)?n[i]=o.slice():(!t||!kr(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&Zr(arguments[o],r);return n}const Wm=(e,t,n,{allOwnKeys:r}={})=>(Zr(t,(o,s)=>{n&&Lt(o)?e[s]=Tl(o,n):e[s]=o},{allOwnKeys:r}),e),Vm=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),Km=(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)},qm=(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&&hi(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},Gm=(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},Ym=e=>{if(!e)return null;if(Tr(e))return e;let t=e.length;if(!Il(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},Xm=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&hi(Uint8Array)),Jm=(e,t)=>{const r=(e&&e[Po]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},Zm=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},Qm=sn("HTMLFormElement"),eg=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),_l=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),tg=sn("RegExp"),jl=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Zr(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},ng=e=>{jl(e,(t,n)=>{if(Lt(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(Lt(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+"'")})}})},rg=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return Tr(e)?r(e):r(String(e).split(t)),n},og=()=>{},sg=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function ig(e){return!!(e&&Lt(e.append)&&e[kl]==="FormData"&&e[Po])}const ag=e=>{const t=new Array(10),n=(r,o)=>{if(Jr(r)){if(t.indexOf(r)>=0)return;if(Xr(r))return r;if(!("toJSON"in r)){t[o]=r;const s=Tr(r)?[]:{};return Zr(r,(i,a)=>{const l=n(i,o+1);!kr(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},lg=sn("AsyncFunction"),cg=e=>e&&(Jr(e)||Lt(e))&&Lt(e.then)&&Lt(e.catch),Rl=((e,t)=>e?setImmediate:t?((n,r)=>(rr.addEventListener("message",({source:o,data:s})=>{o===rr&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),rr.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",Lt(rr.postMessage)),ug=typeof queueMicrotask<"u"?queueMicrotask.bind(rr):typeof process<"u"&&process.nextTick||Rl,R={isArray:Tr,isArrayBuffer:El,isBuffer:Xr,isFormData:Lm,isArrayBufferView:Nm,isString:Am,isNumber:Il,isBoolean:_m,isObject:Jr,isPlainObject:Do,isEmptyObject:jm,isReadableStream:Fm,isRequest:zm,isResponse:Bm,isHeaders:Hm,isUndefined:kr,isDate:Rm,isFile:Pm,isBlob:Om,isRegExp:tg,isFunction:Lt,isStream:Dm,isURLSearchParams:$m,isTypedArray:Xm,isFileList:Mm,forEach:Zr,merge:pi,extend:Wm,trim:Um,stripBOM:Vm,inherits:Km,toFlatObject:qm,kindOf:Oo,kindOfTest:sn,endsWith:Gm,toArray:Ym,forEachEntry:Jm,matchAll:Zm,isHTMLForm:Qm,hasOwnProperty:_l,hasOwnProp:_l,reduceDescriptors:jl,freezeMethods:ng,toObjectSet:rg,toCamelCase:eg,noop:og,toFiniteNumber:sg,findKey:Nl,global:rr,isContextDefined:Al,isSpecCompliantForm:ig,toJSONObject:ag,isAsyncFn:lg,isThenable:cg,setImmediate:Rl,asap:ug,isIterable:e=>e!=null&&Lt(e[Po])};function Me(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)}R.inherits(Me,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:R.toJSONObject(this.config),code:this.code,status:this.status}}});const Pl=Me.prototype,Ol={};["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=>{Ol[e]={value:e}}),Object.defineProperties(Me,Ol),Object.defineProperty(Pl,"isAxiosError",{value:!0}),Me.from=(e,t,n,r,o,s)=>{const i=Object.create(Pl);R.toFlatObject(e,i,function(d){return d!==Error.prototype},u=>u!=="isAxiosError");const a=e&&e.message?e.message:"Error",l=t==null&&e?e.code:t;return Me.call(i,a,l,n,r,o),e&&i.cause==null&&Object.defineProperty(i,"cause",{value:e,configurable:!0}),i.name=e&&e.name||"Error",s&&Object.assign(i,s),i};const dg=null;function mi(e){return R.isPlainObject(e)||R.isArray(e)}function Ml(e){return R.endsWith(e,"[]")?e.slice(0,-2):e}function Dl(e,t,n){return e?e.concat(t).map(function(o,s){return o=Ml(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function fg(e){return R.isArray(e)&&!e.some(mi)}const hg=R.toFlatObject(R,{},null,function(t){return/^is[A-Z]/.test(t)});function Lo(e,t,n){if(!R.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=R.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(x,g){return!R.isUndefined(g[x])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&R.isSpecCompliantForm(t);if(!R.isFunction(o))throw new TypeError("visitor must be a function");function u(v){if(v===null)return"";if(R.isDate(v))return v.toISOString();if(R.isBoolean(v))return v.toString();if(!l&&R.isBlob(v))throw new Me("Blob is not supported. Use a Buffer instead.");return R.isArrayBuffer(v)||R.isTypedArray(v)?l&&typeof Blob=="function"?new Blob([v]):Buffer.from(v):v}function d(v,x,g){let y=v;if(v&&!g&&typeof v=="object"){if(R.endsWith(x,"{}"))x=r?x:x.slice(0,-2),v=JSON.stringify(v);else if(R.isArray(v)&&fg(v)||(R.isFileList(v)||R.endsWith(x,"[]"))&&(y=R.toArray(v)))return x=Ml(x),y.forEach(function(S,I){!(R.isUndefined(S)||S===null)&&t.append(i===!0?Dl([x],I,s):i===null?x:x+"[]",u(S))}),!1}return mi(v)?!0:(t.append(Dl(g,x,s),u(v)),!1)}const f=[],h=Object.assign(hg,{defaultVisitor:d,convertValue:u,isVisitable:mi});function p(v,x){if(!R.isUndefined(v)){if(f.indexOf(v)!==-1)throw Error("Circular reference detected in "+x.join("."));f.push(v),R.forEach(v,function(y,b){(!(R.isUndefined(y)||y===null)&&o.call(t,y,R.isString(b)?b.trim():b,x,h))===!0&&p(y,x?x.concat(b):[b])}),f.pop()}}if(!R.isObject(e))throw new TypeError("data must be an object");return p(e),t}function Ll(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function gi(e,t){this._pairs=[],e&&Lo(e,this,t)}const $l=gi.prototype;$l.append=function(t,n){this._pairs.push([t,n])},$l.toString=function(t){const n=t?function(r){return t.call(this,r,Ll)}:Ll;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function pg(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function Fl(e,t,n){if(!t)return e;const r=n&&n.encode||pg;R.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=R.isURLSearchParams(t)?t.toString():new gi(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class zl{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){R.forEach(this.handlers,function(r){r!==null&&t(r)})}}const Bl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},mg={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:gi,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},xi=typeof window<"u"&&typeof document<"u",yi=typeof navigator=="object"&&navigator||void 0,gg=xi&&(!yi||["ReactNative","NativeScript","NS"].indexOf(yi.product)<0),xg=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",yg=xi&&window.location.href||"http://localhost",Nt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:xi,hasStandardBrowserEnv:gg,hasStandardBrowserWebWorkerEnv:xg,navigator:yi,origin:yg},Symbol.toStringTag,{value:"Module"})),...mg};function vg(e,t){return Lo(e,new Nt.classes.URLSearchParams,{visitor:function(n,r,o,s){return Nt.isNode&&R.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function bg(e){return R.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function wg(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 Hl(e){function t(n,r,o,s){let i=n[s++];if(i==="__proto__")return!0;const a=Number.isFinite(+i),l=s>=n.length;return i=!i&&R.isArray(o)?o.length:i,l?(R.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!R.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&R.isArray(o[i])&&(o[i]=wg(o[i])),!a)}if(R.isFormData(e)&&R.isFunction(e.entries)){const n={};return R.forEachEntry(e,(r,o)=>{t(bg(r),o,n,0)}),n}return null}function Sg(e,t,n){if(R.isString(e))try{return(t||JSON.parse)(e),R.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const Qr={transitional:Bl,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=R.isObject(t);if(s&&R.isHTMLForm(t)&&(t=new FormData(t)),R.isFormData(t))return o?JSON.stringify(Hl(t)):t;if(R.isArrayBuffer(t)||R.isBuffer(t)||R.isStream(t)||R.isFile(t)||R.isBlob(t)||R.isReadableStream(t))return t;if(R.isArrayBufferView(t))return t.buffer;if(R.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 vg(t,this.formSerializer).toString();if((a=R.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return Lo(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),Sg(t)):t}],transformResponse:[function(t){const n=this.transitional||Qr.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(R.isResponse(t)||R.isReadableStream(t))return t;if(t&&R.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"?Me.from(a,Me.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:Nt.classes.FormData,Blob:Nt.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};R.forEach(["delete","get","head","post","put","patch"],e=>{Qr.headers[e]={}});const Cg=R.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"]),Tg=e=>{const t={};let n,r,o;return e&&e.split(`
|
|
31
|
-
`).forEach(function(i){o=i.indexOf(":"),n=i.substring(0,o).trim().toLowerCase(),r=i.substring(o+1).trim(),!(!n||t[n]&&Cg[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},
|
|
32
|
-
`)}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[Ul]=this[Ul]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=eo(i);r[a]||(Ng(o,i),r[a]=!0)}return R.isArray(t)?t.forEach(s):s(t),this}};$t.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),R.reduceDescriptors($t.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),R.freezeMethods($t);function bi(e,t){const n=this||Qr,r=t||n,o=$t.from(r.headers);let s=r.data;return R.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function Wl(e){return!!(e&&e.__CANCEL__)}function Er(e,t,n){Me.call(this,e??"canceled",Me.ERR_CANCELED,t,n),this.name="CanceledError"}R.inherits(Er,Me,{__CANCEL__:!0});function Vl(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Me("Request failed with status code "+n.status,[Me.ERR_BAD_REQUEST,Me.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function Ag(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function _g(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o=0,s=0,i;return t=t!==void 0?t:1e3,function(l){const u=Date.now(),d=r[s];i||(i=u),n[o]=l,r[o]=u;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),u-i<t)return;const p=d&&u-d;return p?Math.round(h*1e3/p):void 0}}function jg(e,t){let n=0,r=1e3/t,o,s;const i=(u,d=Date.now())=>{n=d,o=null,s&&(clearTimeout(s),s=null),e(...u)};return[(...u)=>{const d=Date.now(),f=d-n;f>=r?i(u,d):(o=u,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const Fo=(e,t,n=3)=>{let r=0;const o=_g(50,250);return jg(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,l=i-r,u=o(l),d=i<=a;r=i;const f={loaded:i,total:a,progress:a?i/a:void 0,bytes:l,rate:u||void 0,estimated:u&&a&&d?(a-i)/u:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},n)},Kl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},ql=e=>(...t)=>R.asap(()=>e(...t)),Rg=Nt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,Nt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(Nt.origin),Nt.navigator&&/(msie|trident)/i.test(Nt.navigator.userAgent)):()=>!0,Pg=Nt.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];R.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),R.isString(r)&&i.push("path="+r),R.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 Og(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function Mg(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function Gl(e,t,n){let r=!Og(t);return e&&(r||n==!1)?Mg(e,t):t}const Yl=e=>e instanceof $t?{...e}:e;function or(e,t){t=t||{};const n={};function r(u,d,f,h){return R.isPlainObject(u)&&R.isPlainObject(d)?R.merge.call({caseless:h},u,d):R.isPlainObject(d)?R.merge({},d):R.isArray(d)?d.slice():d}function o(u,d,f,h){if(R.isUndefined(d)){if(!R.isUndefined(u))return r(void 0,u,f,h)}else return r(u,d,f,h)}function s(u,d){if(!R.isUndefined(d))return r(void 0,d)}function i(u,d){if(R.isUndefined(d)){if(!R.isUndefined(u))return r(void 0,u)}else return r(void 0,d)}function a(u,d,f){if(f in t)return r(u,d);if(f in e)return r(void 0,u)}const l={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(u,d,f)=>o(Yl(u),Yl(d),f,!0)};return R.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,h=f(e[d],t[d],d);R.isUndefined(h)&&f!==a||(n[d]=h)}),n}const Xl=e=>{const t=or({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=$t.from(i),t.url=Fl(Gl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),R.isFormData(n)){if(Nt.hasStandardBrowserEnv||Nt.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(R.isFunction(n.getHeaders)){const l=n.getHeaders(),u=["content-type","content-length"];Object.entries(l).forEach(([d,f])=>{u.includes(d.toLowerCase())&&i.set(d,f)})}}if(Nt.hasStandardBrowserEnv&&(r&&R.isFunction(r)&&(r=r(t)),r||r!==!1&&Rg(t.url))){const l=o&&s&&Pg.read(s);l&&i.set(o,l)}return t},Dg=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=Xl(e);let s=o.data;const i=$t.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:u}=o,d,f,h,p,v;function x(){p&&p(),v&&v(),o.cancelToken&&o.cancelToken.unsubscribe(d),o.signal&&o.signal.removeEventListener("abort",d)}let g=new XMLHttpRequest;g.open(o.method.toUpperCase(),o.url,!0),g.timeout=o.timeout;function y(){if(!g)return;const S=$t.from("getAllResponseHeaders"in g&&g.getAllResponseHeaders()),C={data:!a||a==="text"||a==="json"?g.responseText:g.response,status:g.status,statusText:g.statusText,headers:S,config:e,request:g};Vl(function(E){n(E),x()},function(E){r(E),x()},C),g=null}"onloadend"in g?g.onloadend=y:g.onreadystatechange=function(){!g||g.readyState!==4||g.status===0&&!(g.responseURL&&g.responseURL.indexOf("file:")===0)||setTimeout(y)},g.onabort=function(){g&&(r(new Me("Request aborted",Me.ECONNABORTED,e,g)),g=null)},g.onerror=function(I){const C=I&&I.message?I.message:"Network Error",T=new Me(C,Me.ERR_NETWORK,e,g);T.event=I||null,r(T),g=null},g.ontimeout=function(){let I=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const C=o.transitional||Bl;o.timeoutErrorMessage&&(I=o.timeoutErrorMessage),r(new Me(I,C.clarifyTimeoutError?Me.ETIMEDOUT:Me.ECONNABORTED,e,g)),g=null},s===void 0&&i.setContentType(null),"setRequestHeader"in g&&R.forEach(i.toJSON(),function(I,C){g.setRequestHeader(C,I)}),R.isUndefined(o.withCredentials)||(g.withCredentials=!!o.withCredentials),a&&a!=="json"&&(g.responseType=o.responseType),u&&([h,v]=Fo(u,!0),g.addEventListener("progress",h)),l&&g.upload&&([f,p]=Fo(l),g.upload.addEventListener("progress",f),g.upload.addEventListener("loadend",p)),(o.cancelToken||o.signal)&&(d=S=>{g&&(r(!S||S.type?new Er(null,e,g):S),g.abort(),g=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const b=Ag(o.url);if(b&&Nt.protocols.indexOf(b)===-1){r(new Me("Unsupported protocol "+b+":",Me.ERR_BAD_REQUEST,e));return}g.send(s||null)})},Lg=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,o;const s=function(u){if(!o){o=!0,a();const d=u instanceof Error?u:this.reason;r.abort(d instanceof Me?d:new Er(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new Me(`timeout ${t} of ms exceeded`,Me.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(u=>{u.unsubscribe?u.unsubscribe(s):u.removeEventListener("abort",s)}),e=null)};e.forEach(u=>u.addEventListener("abort",s));const{signal:l}=r;return l.unsubscribe=()=>R.asap(a),l}},$g=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},Fg=async function*(e,t){for await(const n of zg(e))yield*$g(n,t)},zg=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()}},Jl=(e,t,n,r)=>{const o=Fg(e,t);let s=0,i,a=l=>{i||(i=!0,r&&r(l))};return new ReadableStream({async pull(l){try{const{done:u,value:d}=await o.next();if(u){a(),l.close();return}let f=d.byteLength;if(n){let h=s+=f;n(h)}l.enqueue(new Uint8Array(d))}catch(u){throw a(u),u}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},Zl=64*1024,{isFunction:zo}=R,Bg=(({Request:e,Response:t})=>({Request:e,Response:t}))(R.global),{ReadableStream:Ql,TextEncoder:ec}=R.global,tc=(e,...t)=>{try{return!!e(...t)}catch{return!1}},Hg=e=>{e=R.merge.call({skipUndefined:!0},Bg,e);const{fetch:t,Request:n,Response:r}=e,o=t?zo(t):typeof fetch=="function",s=zo(n),i=zo(r);if(!o)return!1;const a=o&&zo(Ql),l=o&&(typeof ec=="function"?(v=>x=>v.encode(x))(new ec):async v=>new Uint8Array(await new n(v).arrayBuffer())),u=s&&a&&tc(()=>{let v=!1;const x=new n(Nt.origin,{body:new Ql,method:"POST",get duplex(){return v=!0,"half"}}).headers.has("Content-Type");return v&&!x}),d=i&&a&&tc(()=>R.isReadableStream(new r("").body)),f={stream:d&&(v=>v.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(v=>{!f[v]&&(f[v]=(x,g)=>{let y=x&&x[v];if(y)return y.call(x);throw new Me(`Response type '${v}' is not supported`,Me.ERR_NOT_SUPPORT,g)})});const h=async v=>{if(v==null)return 0;if(R.isBlob(v))return v.size;if(R.isSpecCompliantForm(v))return(await new n(Nt.origin,{method:"POST",body:v}).arrayBuffer()).byteLength;if(R.isArrayBufferView(v)||R.isArrayBuffer(v))return v.byteLength;if(R.isURLSearchParams(v)&&(v=v+""),R.isString(v))return(await l(v)).byteLength},p=async(v,x)=>{const g=R.toFiniteNumber(v.getContentLength());return g??h(x)};return async v=>{let{url:x,method:g,data:y,signal:b,cancelToken:S,timeout:I,onDownloadProgress:C,onUploadProgress:T,responseType:E,headers:A,withCredentials:j="same-origin",fetchOptions:P}=Xl(v),D=t||fetch;E=E?(E+"").toLowerCase():"text";let L=Lg([b,S&&S.toAbortSignal()],I),V=null;const M=L&&L.unsubscribe&&(()=>{L.unsubscribe()});let Y;try{if(T&&u&&g!=="get"&&g!=="head"&&(Y=await p(A,y))!==0){let F=new n(x,{method:"POST",body:y,duplex:"half"}),te;if(R.isFormData(y)&&(te=F.headers.get("content-type"))&&A.setContentType(te),F.body){const[fe,me]=Kl(Y,Fo(ql(T)));y=Jl(F.body,Zl,fe,me)}}R.isString(j)||(j=j?"include":"omit");const K=s&&"credentials"in n.prototype,q={...P,signal:L,method:g.toUpperCase(),headers:A.normalize().toJSON(),body:y,duplex:"half",credentials:K?j:void 0};V=s&&new n(x,q);let z=await(s?D(V,P):D(x,q));const $=d&&(E==="stream"||E==="response");if(d&&(C||$&&M)){const F={};["status","statusText","headers"].forEach(be=>{F[be]=z[be]});const te=R.toFiniteNumber(z.headers.get("content-length")),[fe,me]=C&&Kl(te,Fo(ql(C),!0))||[];z=new r(Jl(z.body,Zl,fe,()=>{me&&me(),M&&M()}),F)}E=E||"text";let pe=await f[R.findKey(f,E)||"text"](z,v);return!$&&M&&M(),await new Promise((F,te)=>{Vl(F,te,{data:pe,headers:$t.from(z.headers),status:z.status,statusText:z.statusText,config:v,request:V})})}catch(K){throw M&&M(),K&&K.name==="TypeError"&&/Load failed|fetch/i.test(K.message)?Object.assign(new Me("Network Error",Me.ERR_NETWORK,v,V),{cause:K.cause||K}):Me.from(K,K&&K.code,v,V)}}},Ug=new Map,nc=e=>{let t=e?e.env:{};const{fetch:n,Request:r,Response:o}=t,s=[r,o,n];let i=s.length,a=i,l,u,d=Ug;for(;a--;)l=s[a],u=d.get(l),u===void 0&&d.set(l,u=a?new Map:Hg(t)),d=u;return u};nc();const wi={http:dg,xhr:Dg,fetch:{get:nc}};R.forEach(wi,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const rc=e=>`- ${e}`,Wg=e=>R.isFunction(e)||e===null||e===!1,oc={getAdapter:(e,t)=>{e=R.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,!Wg(r)&&(o=wi[(a=String(r)).toLowerCase()],o===void 0))throw new Me(`Unknown adapter '${a}'`);if(o&&(R.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([l,u])=>`adapter ${l} `+(u===!1?"is not supported by the environment":"is not available in the build"));let a=n?i.length>1?`since :
|
|
33
|
-
`+i.map(
|
|
34
|
-
`):" "+
|
|
35
|
-
`+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=or(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&Ho.assertOptions(r,{silentJSONParsing:mn.transitional(mn.boolean),forcedJSONParsing:mn.transitional(mn.boolean),clarifyTimeoutError:mn.transitional(mn.boolean)},!1),o!=null&&(R.isFunction(o)?n.paramsSerializer={serialize:o}:Ho.assertOptions(o,{encode:mn.function,serialize:mn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),Ho.assertOptions(n,{baseUrl:mn.spelling("baseURL"),withXsrfToken:mn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&R.merge(s.common,s[n.method]);s&&R.forEach(["delete","get","head","post","put","patch","common"],v=>{delete s[v]}),n.headers=$t.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(x){typeof x.runWhen=="function"&&x.runWhen(n)===!1||(l=l&&x.synchronous,a.unshift(x.fulfilled,x.rejected))});const u=[];this.interceptors.response.forEach(function(x){u.push(x.fulfilled,x.rejected)});let d,f=0,h;if(!l){const v=[sc.bind(this),void 0];for(v.unshift(...a),v.push(...u),h=v.length,d=Promise.resolve(n);f<h;)d=d.then(v[f++],v[f++]);return d}h=a.length;let p=n;for(;f<h;){const v=a[f++],x=a[f++];try{p=v(p)}catch(g){x.call(this,g);break}}try{d=sc.call(this,p)}catch(v){return Promise.reject(v)}for(f=0,h=u.length;f<h;)d=d.then(u[f++],u[f++]);return d}getUri(t){t=or(this.defaults,t);const n=Gl(t.baseURL,t.url,t.allowAbsoluteUrls);return Fl(n,t.params,t.paramsSerializer)}};R.forEach(["delete","get","head","options"],function(t){sr.prototype[t]=function(n,r){return this.request(or(r||{},{method:t,url:n,data:(r||{}).data}))}}),R.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(or(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}sr.prototype[t]=n(),sr.prototype[t+"Form"]=n(!0)});let Kg=class Sm{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 Er(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 Sm(function(o){t=o}),cancel:t}}};function qg(e){return function(n){return e.apply(null,n)}}function Gg(e){return R.isObject(e)&&e.isAxiosError===!0}const Ci={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(Ci).forEach(([e,t])=>{Ci[t]=e});function lc(e){const t=new sr(e),n=Tl(sr.prototype.request,t);return R.extend(n,sr.prototype,t,{allOwnKeys:!0}),R.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return lc(or(e,o))},n}const mt=lc(Qr);mt.Axios=sr,mt.CanceledError=Er,mt.CancelToken=Kg,mt.isCancel=Wl,mt.VERSION=ic,mt.toFormData=Lo,mt.AxiosError=Me,mt.Cancel=mt.CanceledError,mt.all=function(t){return Promise.all(t)},mt.spread=qg,mt.isAxiosError=Gg,mt.mergeConfig=or,mt.AxiosHeaders=$t,mt.formToJSON=e=>Hl(R.isHTMLForm(e)?new FormData(e):e),mt.getAdapter=oc.getAdapter,mt.HttpStatusCode=Ci,mt.default=mt;const{Axios:$T,AxiosError:FT,CanceledError:zT,isCancel:BT,CancelToken:HT,VERSION:UT,all:WT,Cancel:VT,isAxiosError:KT,spread:qT,toFormData:GT,AxiosHeaders:YT,HttpStatusCode:XT,formToJSON:JT,getAdapter:ZT,mergeConfig:QT}=mt,cc=typeof window<"u"?window.__API_BASE_URL__:void 0,uc=cc?jn(cc):void 0;function jn(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let Uo=null;const Ti=new Set;function dc(){return Uo}function ki(e){Uo=e,Ti.forEach(t=>t(e))}function fc(e){return Ti.add(e),()=>Ti.delete(e)}const Xt=mt.create({...uc?{baseURL:uc}:{},timeout:3e4,withCredentials:!0});Xt.interceptors.request.use(e=>(Uo&&(e.headers.Authorization=`Bearer ${Uo}`),e)),Xt.interceptors.response.use(e=>e,e=>Promise.reject(e));async function gn(e,t){return Xt.defaults.baseURL?(await Xt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function Ei(e,t,n){return Xt.defaults.baseURL?(await Xt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function hc(e,t,n){return Xt.defaults.baseURL?(await Xt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function pc(e,t){return Xt.defaults.baseURL?(await Xt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function xn(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class mc{get baseUrl(){const t=Xt.defaults.baseURL;return t?jn(String(t)):""}updateConfig(t){t.baseUrl&&(Xt.defaults.baseURL=jn(String(t.baseUrl))),t.authToken!==void 0&&ki(t.authToken)}getAuthToken(){return dc()}setAuthToken(t){ki(t)}onTokenChange(t){return fc(t)}async listThreads(){const t=await gn("/threads"),n=xn(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await Ei("/threads",t?{title:t}:void 0);return xn(r)}async updateThread(t,n){const r=await hc(`/threads/${t}`,{title:n});return xn(r)}async deleteThread(t){const n=await pc(`/threads/${t}`);return xn(n)}async threadInfo(t){const n=await gn(`/threads/${t}/info`);return xn(n)}async listAgents(){const t=await gn("/agents"),n=xn(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await gn(`/agents/${t}`);return xn(n)}async getAgentSchema(t){const n=await gn(`/agents/${t}/schema`);return xn(n)}async getStateHistory(t){const n=await gn(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return xn(n)}resumeStream(t){}async resume(t){const n=await Ei("/runs/resume",{thread_id:t.threadId,value:t.value});return xn(n)}}const Fn=new mc,gc=w.createContext(null);function Yg({children:e,apiConfig:t}){const n=Fn;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return c.jsx(gc.Provider,{value:r,children:e})}function Ii(){const e=w.useContext(gc);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function Xg(e){return await new Promise((t,n)=>{const r=new FileReader;r.onload=()=>{try{const o=r.result,s=new Uint8Array(o);let i="";const a=s.byteLength;for(let l=0;l<a;l++)i+=String.fromCharCode(s[l]);t(btoa(i))}catch(o){n(o)}},r.onerror=o=>n(o),r.readAsArrayBuffer(e)})}async function Jg(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const u=await Xg(l);a.push({filename:l.name,data:u,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const Zg={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function Ni(e){if(!e||typeof e!="object")return!1;const t=e;return"values"in t&&"config"in t&&typeof t.values=="object"&&t.values!==null&&typeof t.config=="object"&&t.config!==null}function Wo(e,t){return`${e??""}::${t??""}`}function xc(e){const t=Array.isArray(e==null?void 0:e.checkpoints)?(e==null?void 0:e.checkpoints)??[]:e!=null&&e.checkpoints?Object.values(e.checkpoints):[],n=(e==null?void 0:e.threadId)??"",r=t[0];if(!Ni(r))return{threadId:n,latest:null,checkpoints:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=ex(t),i=yc(r,0);return{threadId:n,latest:i,checkpoints:o,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function yc(e,t){var C,T;if(!Ni(e))return null;const n=e.values??{},r=Array.isArray(n==null?void 0:n.messages)?n.messages:[],o=e.tasks,s=r.map((E,A)=>sx(E,A)).filter(E=>!!E),i=Ut((C=e.config)==null?void 0:C.configurable),a=ut(i,["checkpoint_id","checkpointId"]),l=ut(i,["checkpoint_ns","checkpointNs"]),u=Ut((T=e.parentConfig)==null?void 0:T.configurable),d=ut(u,["checkpoint_id","checkpointId"])??null,f=ut(u,["checkpoint_ns","checkpointNs"])??null,h=e==null?void 0:e.createdAt,p=typeof h=="string"&&h.trim()?h:new Date(Date.now()-t).toISOString(),v=tx(s),x=s[s.length-1]??null,g=Ut(e==null?void 0:e.metadata),y=ut(g,["branch_label","branchLabel"]),b=Ut(e==null?void 0:e.parentConfig),S=Ut(b==null?void 0:b.configurable),I=ut(S,["checkpoint_id","checkpointId"]);return{messages:s,checkpointId:a??null,checkpointNs:l??null,nextCursor:d,nextCursorNs:f,interrupt:Qg(o,s,t),createdAt:p,preview:v??null,role:(x==null?void 0:x.role)??null,parentId:I??null,branchLabel:y??null,lastMessageId:(x==null?void 0:x.id)??null,hasMessages:s.length>0,messagesLen:s.length}}function Qg(e,t,n){const r=rx(e,n);return r||nx(t,n)}function ex(e){const t=new Map;e.forEach((o,s)=>{if(!Ni(o))return;const i=yc(o,s);if(!(i!=null&&i.checkpointId))return;const a=Wo(i.checkpointId,i.checkpointNs??null);t.has(a)||t.set(a,i)});const n=Array.from(t.values());n.sort((o,s)=>bc(s.createdAt??"")-bc(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function tx(e){var t;for(let n=e.length-1;n>=0;n--){const r=((t=e[n])==null?void 0:t.content)??[];for(let o=0;o<r.length;o++){const s=r[o];if(s&&s.type==="text"&&typeof s.text=="string"){const i=s.text.trim();if(i)return i}}}return null}function nx(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 rx(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=ox(e[n],`task-${t}-${n}`);if(!r)continue;const o=r.id||`task-${t}-${n}`;if(Array.isArray(r.interrupts)&&r.interrupts.length)for(let s=r.interrupts.length-1;s>=0;s--){const i=to(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=to(r.state,`${o}-state`);if(s)return s}}return null}function ox(e,t){if(!e)return null;if(Array.isArray(e)){const[a,l,u,,d,,f,...h]=e,p=typeof a=="string"&&a.trim()?a:t,v=typeof l=="string"&&l.trim()?l:Array.isArray(u)&&typeof u[0]=="string"?String(u[0]):"task",x=Array.isArray(d)?d:void 0,g=h.length?h[h.length-1]:void 0;return{id:p,name:v,interrupts:x,state:g!==void 0?g:f}}const n=Ut(e);if(!n)return null;const r=ut(n,["id","task_id","taskId"])??t,o=ut(n,["name"])??"task",s=Array.isArray(n.interrupts)?n.interrupts:void 0,i=Object.prototype.hasOwnProperty.call(n,"state")?n.state:void 0;return{id:r,name:o,interrupts:s,state:i}}function to(e,t,n=0,r=new Set){if(n>6||e==null)return null;if(typeof e=="object"){if(r.has(e))return null;r.add(e)}const o=vc(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=to(e[s],t,n+1,r);if(i)return i}return null}if(typeof e=="object"){const s=e,i=["interrupt","pending_interrupt","pendingInterrupt","value","data","payload","result","response"];for(const a of i)if(a in s){const l=to(s[a],t,n+1,r);if(l)return l}for(const[a,l]of Object.entries(s)){if(i.includes(a)||a==="messages"||a==="results")continue;const u=to(l,t,n+1,r);if(u)return u}}return null}function vc(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=ut(n,["type","event","kind"]),o=ut(n,["id","interrupt_id","interruptId","value_id"])??(r&&r.toLowerCase().includes("interrupt")?t:void 0);if(!(Object.prototype.hasOwnProperty.call(n,"value")||Object.prototype.hasOwnProperty.call(n,"data")||Object.prototype.hasOwnProperty.call(n,"payload"))&&!(r&&r.toLowerCase().includes("interrupt")))return null;const i=Object.prototype.hasOwnProperty.call(n,"value")?n.value:Object.prototype.hasOwnProperty.call(n,"data")?n.data:Object.prototype.hasOwnProperty.call(n,"payload")?n.payload:n,a=o&&o.trim()?o:t;return a?{id:a,value:i}:null}if(Array.isArray(e)){for(let n=e.length-1;n>=0;n--){const r=vc(e[n],t);if(r)return r}return e.length>=2&&typeof e[0]=="string"&&e[0].trim()?{id:e[0],value:e[1]}:null}if(typeof e=="string"){const n=e.trim();return n?{id:t||n,value:n}:null}return null}function bc(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function sx(e,t){if(!e||typeof e!="object")return null;const n=e,r=Ut(e)??{},o=Ut(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=Zg[s];if(!i)return null;const a=o.id??o.message_id??o.run_id??null,l=typeof a=="string"&&a.trim()?a:`history-${i}-${t}`,u=Ut(o.additional_kwargs)??Ut(o.additionalKwargs),d=Ut(o.response_metadata)??Ut(o.responseMetadata),f=ut(u,["createdAt","created_at"])??ut(o,["created_at","createdAt"]),h=ut(u,["checkpointId","checkpoint_id"]),p=ut(u,["checkpointNs","checkpoint_ns"]),v=ix(o.content),x={id:l,role:i,content:v};f&&(x.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(x.name=o.name),typeof(d==null?void 0:d.model_name)=="string"&&(x.model=String(d.model_name)),!x.model&&typeof o.model=="string"&&(x.model=o.model),h&&(x.checkpointId=h),p&&(x.checkpointNs=p);const g=dx(u,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),y=d?{...d}:void 0;g&&Object.keys(g).length&&(x.additionalKwargs=g),y&&Object.keys(y).length&&(x.responseMetadata=y);const b=ax((u==null?void 0:u.tool_calls)??o.tool_calls);if(b.length&&(x.content=[...x.content,...b]),i==="tool"){const S=cx(o,x.content);S&&(x.content=S)}return x}function ix(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>wc(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=wc(e);return t?[t]:[]}return[]}function wc(e){if(!e||typeof e!="object")return typeof e=="string"&&e.trim()?{type:"text",text:e}:null;const t=e,n=String(t.type??"").toLowerCase();if(!n||n==="text"){const o=typeof t.text=="string"?t.text:typeof t.value=="string"?t.value:"";return o.trim()?{type:"text",text:o}:null}if(n==="image"||n==="image_url"){const o=ut(t,["url","src"]);if(!o)return null;const s={type:"image_url",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.alt=="string"&&(s.alt=t.alt),s}if(n==="file"){const o=ut(t,["url"]);if(!o)return null;const s={type:"file",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.name=="string"&&(s.name=t.name),typeof t.size=="number"&&(s.size=t.size),typeof t.sourceType=="string"&&(s.sourceType=t.sourceType),s}if(n==="tool_call")return lx(t)??null;if(n==="tool_end"){const o=ut(t,["tool_call_id","toolCallId","id"]);if(!o)return null;const s={type:"tool_end",toolCallId:o,output:"output"in t?t.output:t.content};return typeof t.error=="string"&&(s.error=t.error),s}if(n==="interrupt")return{type:"interrupt",value:t.value,...t};if(n==="tool"){const o=ut(t,["text","content"]);if(o)return{type:"text",text:o}}const r=typeof t.content=="string"?t.content:typeof t.value=="string"?t.value:JSON.stringify(t);return r?{type:"text",text:r}:null}function ax(e){return Array.isArray(e)?e.map((t,n)=>{if(!t||typeof t!="object")return null;const r=t,o=ut(r,["id","call_id"]),s=Ut(r.function),i=ut(s,["name"])??"tool",a=s==null?void 0:s.arguments,l=Sc(a);return{type:"tool_call",id:o??`tool_call_${n}`,name:i,args:l}}).filter(t=>!!t):[]}function lx(e){const t=ut(e,["id","call_id"]),n=ut(e,["name"]);if(!t||!n)return null;const r=Sc(e.args??e.arguments);return{type:"tool_call",id:t,name:n,args:r}}function cx(e,t){const n=ut(e,["tool_call_id","toolCallId","id"]);if(!n)return t;const r=e.content??e.output,o=typeof r=="string"?ux(r):r,s={type:"tool_end",toolCallId:n,output:o};return typeof e.error=="string"&&(s.error=e.error),[s]}function Sc(e){if(!e)return{};if(typeof e=="string")try{const t=JSON.parse(e);return typeof t=="object"&&t!==null?t:{raw:e}}catch{return{raw:e}}return typeof e=="object"&&!Array.isArray(e)?{...e}:{}}function ux(e){try{return JSON.parse(e)}catch{return e}}function Ut(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function ut(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function dx(e,t){if(!e)return;const n={};let r=!1;for(const[o,s]of Object.entries(e)){if(t.includes(o)){r=!0;continue}s!==void 0&&(n[o]=s)}return r?Object.keys(n).length?n:void 0:e}function fx(e){return e.type!=="thread_info"&&e.type!=="token"}const hx={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function px(e,t){var n;switch(t.type){case"reset":{console.log("[MessageReducer] 🔄 RESET action received"),console.log("[MessageReducer] 📊 Before reset - messages count:",e.messages.length);const r={messages:Ai(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,pendingInterrupt:null};return console.log("[MessageReducer] 📊 After reset - messages count:",r.messages.length),r}case"seed":{const r=Ai(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),console.log("[MessageReducer] seed action (REPLACE mode):",{incomingCount:t.payload.messages.length,sanitizedCount:r.length,previousCount:e.messages.length,checkpointId:o.lastCheckpointId}),o}case"prepend":{const r=Ai(t.payload.messages);if(!r.length)return console.log("[MessageReducer] No incoming messages after sanitize - skipping"),e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return console.log("[MessageReducer] After dedup:",{uniqueCount:s.length,duplicates:r.length-s.length,finalTotal:s.length+e.messages.length}),s.length?{...e,messages:[...s,...e.messages]}:(console.log("[MessageReducer] All messages were duplicates - skipping"),e)}case"user_message":{const r=t.payload.message;return e.messages.some(o=>o.id===r.id)?e:{...e,messages:[...e.messages,r]}}case"event":return Tc(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Tc(o,s),e):e}case"interrupt_response":{const{interruptId:r}=t.payload,o=e.messages.map(s=>({...s,content:s.content.filter(i=>i.type!=="interrupt")}));return{...e,messages:o,pendingInterrupt:null}}default:return e}}function Cc(e=[]){const[t,n]=w.useReducer(px,{...hx,messages:e}),r=w.useRef([]),o=w.useRef(null),s=w.useRef(null),i=w.useCallback(()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),o.current=null,s.current=null;const d=r.current;d.length&&(r.current=[],n({type:"batch",payload:{events:d}}))},[]),a=w.useCallback(()=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?o.current===null&&(o.current=window.requestAnimationFrame(()=>i())):s.current===null&&(s.current=setTimeout(i,8))},[i]),l=w.useCallback(d=>{r.current.push(d),a()},[a]);w.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const u=w.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,f)=>n({type:"seed",payload:{messages:d,...f??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:l}),[l]);return{state:t,dispatch:n,...u}}function Tc(e,t){var n,r,o,s;if(t.type==="message_start"&&t.role==="assistant"){const i=t.id,a=xx(t.model);if(e.messages.some(d=>d.id===i)){const d=e.messagesStreamMeta??{},f={...d,[i]:d[i]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:i,messagesStreamMeta:f}}const u={id:i,role:"assistant",name:a||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:i,messages:[...e.messages,u]}}if(t.type==="message_delta"){const i=e.assemblingId??_i(e.messages);if(!i)return e;const a=e.messages,l=a.findIndex(S=>S.id===i&&S.role==="assistant");if(l===-1)return e;const u=a[l],d=e.messagesStreamMeta??{},f=d[i]??{lastSeq:null,lastText:Ac(u.content)},h=t.seq??null;if(h!==null&&typeof h=="number"&&typeof f.lastSeq=="number"&&h<=f.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:h,lastSeq:f.lastSeq}),e;const{newParts:p,newMeta:v,changed:x}=mx(u.content,t.delta,f,h);if(!x)return e;const g={...u,content:p},y=kc(a,l,g),b={...d,[i]:v};return{...e,messages:y,messagesStreamMeta:b}}if(t.type==="message_end"){const i=e.assemblingId??_i(e.messages);if(!i)return{...e,assemblingId:null};const a=e.messages,l=a.findIndex(u=>u.id===i&&u.role==="assistant");if(l>=0){const u=a[l];if(!((n=u.content)==null?void 0:n.some(f=>{var h;return(f==null?void 0:f.type)==="text"&&((h=f.text)==null?void 0:h.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:u.id,contentTypes:(r=u.content)==null?void 0:r.map(h=>h==null?void 0:h.type),contentPreview:(o=u.content)==null?void 0:o.map(h=>(h==null?void 0:h.type)==="text"?String(h.text).slice(0,100):h==null?void 0:h.type)});const f=[...a.slice(0,l),...a.slice(l+1)];return{...e,assemblingId:null,messages:f}}}return e}if(t.type==="tool_start"){const i=t.id??t.call_id,a=t.name??t.tool??"tool";if(!i)return e;const l=`tool-${i}`,u={type:"tool_call",id:i,name:a,args:t.args};if(e.messages.find(h=>h.id===l))return{...e,toolIndex:{...e.toolIndex,[i]:l}};const f={id:l,role:"tool",name:a,createdAt:new Date().toISOString(),content:[u]};return{...e,messages:[...e.messages,f],toolIndex:{...e.toolIndex,[i]:l}}}if(t.type==="tool_end"){const i=t.id??t.call_id;if(!i)return e;const a=e.toolIndex[i]??`tool-${i}`,l={type:"tool_end",toolCallId:i,output:t.output,error:t.error},u=e.messages.find(h=>h.id===a),d={id:a,role:"tool",name:t.name??((s=e.messages.find(h=>h.id===a))==null?void 0:s.name),content:[l],createdAt:new Date().toISOString()},f=u?Ic(e.messages,a,[l]):[...e.messages,d];return{...e,messages:f,toolIndex:{...e.toolIndex,[i]:a}}}if(t.type==="checkpoint"){const i=t.checkpointNs??e.lastCheckpointNs??null,a=gx(e.messages,t.checkpointId,i);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:i,messages:a}}if(t.type==="branch"){const i=t.checkpointId??e.lastCheckpointId,a=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:i??null,lastCheckpointNs:a??null}}if(t.type==="error"){const i={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,i]}}if(t.type==="interrupt"){const i=e.assemblingId??_i(e.messages),a={type:"interrupt",value:t.value,id:t.id};if(i)return{...e,assemblingId:null,messages:Ic(e.messages,i,[a]),pendingInterrupt:{id:t.id,value:t.value}};const l=`interrupt-${t.id}`;if(e.messages.findIndex(f=>f.id===l)!==-1)return{...e,assemblingId:null,messages:Ec(e.messages,l,f=>({...f,content:Nc(f.content??[],[a])})),pendingInterrupt:{id:t.id,value:t.value}};const d={id:l,role:"system",createdAt:new Date().toISOString(),content:[a]};return{...e,messages:[...e.messages,d],pendingInterrupt:{id:t.id,value:t.value}}}return e}function Ai(e){return e.filter(t=>{if(t.role!=="assistant")return!0;const n=(t.content||[]).some(o=>{var s;return o&&o.type==="text"&&((s=o.text)==null?void 0:s.trim())}),r=(t.content||[]).some(o=>o&&o.type==="image_url");return!!(n||r)})}function kc(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function _i(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function Ec(e,t,n){const r=e.findIndex(i=>i.id===t);if(r===-1)return e;const o=e[r],s=n(o);return s===o?e:[...e.slice(0,r),s,...e.slice(r+1)]}function Ic(e,t,n){return Ec(e,t,r=>({...r,content:Nc(r.content,n)}))}function Nc(e,t){const n=e.slice();for(const r of t)if(r.type==="text"){const o=n[n.length-1],s=r.text??"";if(!s)continue;if((o==null?void 0:o.type)==="text"){let i=function(p){return p.replace(/\s+/g," ").trim()};const a=o,l=a.text??"";if(console.debug("[MessageReducer] mergeParts",{incomingLength:s.length,previousLength:l.length,incomingSnippet:s.slice(0,100),previousSnippet:l.slice(-100)}),!l){a.text=s;continue}const u=i(s),d=i(l);if(u.startsWith(d)||s.startsWith(l)){console.debug("[MessageReducer] incoming startsWith previous (norm/raw) - replacing",{incomingLength:s.length,previousLength:l.length}),a.text=s;continue}if(u.includes(d)){console.debug("[MessageReducer] incoming includes previous (normalized) - replacing",{incomingLength:s.length,previousLength:l.length}),a.text=s;continue}if(d.includes(u)&&u.length<=3){console.debug("[MessageReducer] previous includes incoming (normalized) - skipping trivial incoming",{incomingLength:s.length,previousLength:l.length});continue}const h=jc(l,s);h?(console.debug("[MessageReducer] suffix computed",{suffixLength:h.length}),a.text=l+h):(console.debug("[MessageReducer] no overlap detected - appending incoming",{incomingLength:s.length}),a.text=l+s)}else n.push({type:"text",text:s})}else n.push(r);return n}function Ac(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function mx(e,t,n,r){const o={...n};if(r!==null&&typeof r=="number"){if(typeof o.lastSeq=="number"&&r<=o.lastSeq)return{newParts:e,newMeta:o,changed:!1};o.lastSeq=r}const s=t.filter(f=>f.type==="text").map(f=>f.text??"").join(""),i=t.filter(f=>f.type!=="text"),a=o.lastText??Ac(e);let l="",u=e.slice();if(s){const f=jc(a,s);if(f===""?l="":f===s?l=s:l=f,l){const h=u[u.length-1];if((h==null?void 0:h.type)==="text"){const p=h.text??"",v={...h,text:p+l};u=[...u.slice(0,u.length-1),v]}else u=[...u,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(u=[...u,...i]);const d=!!(l||i.length);return{newParts:u,newMeta:o,changed:d}}function _c(e){return e.replace(/\s+/g," ").trim()}function jc(e,t){if(!t)return"";if(!e)return t;if(e===t)return"";const n=Math.min(e.length,t.length);for(let i=n;i>0;i--)if(e.slice(-i)===t.slice(0,i))return t.slice(i);const r=_c(e),o=_c(t);if(r===o)return"";const s=Math.min(r.length,o.length);for(let i=s;i>0;i--)if(r.slice(-i)===o.slice(0,i))return t;return t}function gx(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 kc(e,r,s)}return e}function xx(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function Rc(e={}){const t=w.useMemo(()=>jn(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=w.useState(e.token??null),s=w.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=w.useState(!1),[u,d]=w.useState(null),[f,h]=w.useState(""),[p,v]=w.useState(null),[x,g]=w.useState(0),[y,b]=w.useState(!1),S=w.useRef(null),I=w.useRef(!0),C=w.useRef(0),T=w.useCallback(P=>{o(P)},[]),E=w.useCallback(()=>{var P;(P=S.current)==null||P.abort(),S.current=null,l(!1),b(!1),C.current=0,g(0)},[]),A=w.useCallback(()=>{h(""),v(null),d(null)},[]),j=w.useCallback((P,D,L)=>{S.current&&(S.current.abort(),S.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&h("");const V=new AbortController;return S.current=V,(async()=>{var Y,K,q,z,$,pe,F,te;const M=fe=>{var me;try{const be=JSON.parse(JSON.stringify(fe));return(me=be==null?void 0:be.payload)!=null&&me.files_info&&Array.isArray(be.payload.files_info)&&(be.payload.files_info=be.payload.files_info.map(Te=>({...Te,data:Te!=null&&Te.data?`<base64 ${String(Te.data).length} chars>`:Te==null?void 0:Te.data}))),be}catch{return fe}};try{let fe={};try{if(r)fe={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const Le=window.__AUTH_TOKEN__,ct=((Y=window.localStorage)==null?void 0:Y.getItem("authToken"))||null;let rt=null;try{const St=(K=window.localStorage)==null?void 0:K.getItem("chat-settings");St&&(rt=((q=JSON.parse(St))==null?void 0:q.apiKey)||null)}catch{}const vt=Le||ct||rt||null;vt&&(fe={Authorization:`Bearer ${vt}`})}}catch{}console.debug("[use-chat] POST",t+n,M(P));const me=await fetch(t+n,{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream",...fe,...s.current},body:JSON.stringify(P),signal:V.signal,credentials:i});if(!me.ok||!me.body){const Oe=await me.text().catch(()=>"");throw console.debug("[use-chat] non-OK response",me.status,Oe==null?void 0:Oe.slice(0,500)),new Error(`stream ${me.status}${Oe?": "+Oe:""}`)}b(!0);const be=me.body.getReader(),Te=new TextDecoder;let G="",O=[];C.current=0,g(0);let Z=0,ne=null;const de=()=>{if(O.length){const Oe=O.join("");O=[],I.current&&h(Le=>Le+Oe)}ne=null},ae=()=>{typeof window<"u"&&ne==null&&(ne=requestAnimationFrame(de))};let We=Date.now();const Ze=setInterval(()=>{var Oe;if(Date.now()-We>6e4){const Le="Stream idle timeout";d(Le),V.abort(),(Oe=L==null?void 0:L.onError)==null||Oe.call(L,Le)}},5e3),ve=1024*1024;try{const Oe=me.headers.get("X-Thread-Id")||me.headers.get("x-thread-id"),Le=me.headers.get("X-Thread-Created")||me.headers.get("x-thread-created"),ct=Oe??null,rt=String(Le??"").toLowerCase()==="true";for((z=L==null?void 0:L.onOpen)==null||z.call(L,{threadId:ct,created:rt});;){const{value:vt,done:St}=await be.read();if(St)break;G+=Te.decode(vt,{stream:!0}),G.length>ve&&(G="",console.warn("Stream buffer reset: exceeded 1MB"));let B;for(;(B=G.indexOf(`
|
|
30
|
+
<%s key={someKey} {...props} />`,Nn,In,ai,In),Co[In+Nn]=!0}}return k===r?br(ht):nn(ht),ht}}function To(k,W,oe){return fn(k,W,oe,!0)}function Qn(k,W,oe){return fn(k,W,oe,!1)}var er=Qn,ko=To;Wr.Fragment=r,Wr.jsx=er,Wr.jsxs=ko}()),Wr}process.env.NODE_ENV==="production"?di.exports=km():di.exports=Em();var c=di.exports;function Cl(e,t){return function(){return e.apply(t,arguments)}}const{toString:Im}=Object.prototype,{getPrototypeOf:fi}=Object,{iterator:_o,toStringTag:Tl}=Symbol,jo=(e=>t=>{const n=Im.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),rn=e=>(e=e.toLowerCase(),t=>jo(t)===e),Ro=e=>t=>typeof t===e,{isArray:Sr}=Array,Cr=Ro("undefined");function Vr(e){return e!==null&&!Cr(e)&&e.constructor!==null&&!Cr(e.constructor)&&Dt(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const kl=rn("ArrayBuffer");function Nm(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&kl(e.buffer),t}const Am=Ro("string"),Dt=Ro("function"),El=Ro("number"),Kr=e=>e!==null&&typeof e=="object",_m=e=>e===!0||e===!1,Po=e=>{if(jo(e)!=="object")return!1;const t=fi(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Tl in e)&&!(_o in e)},jm=e=>{if(!Kr(e)||Vr(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Rm=rn("Date"),Pm=rn("File"),Om=rn("Blob"),Mm=rn("FileList"),Dm=e=>Kr(e)&&Dt(e.pipe),Lm=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||Dt(e.append)&&((t=jo(e))==="formdata"||t==="object"&&Dt(e.toString)&&e.toString()==="[object FormData]"))},$m=rn("URLSearchParams"),[Fm,zm,Bm,Hm]=["ReadableStream","Request","Response","Headers"].map(rn),Um=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function qr(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),Sr(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(Vr(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 Il(e,t){if(Vr(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 nr=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,Nl=e=>!Cr(e)&&e!==nr;function hi(){const{caseless:e,skipUndefined:t}=Nl(this)&&this||{},n={},r=(o,s)=>{const i=e&&Il(n,s)||s;Po(n[i])&&Po(o)?n[i]=hi(n[i],o):Po(o)?n[i]=hi({},o):Sr(o)?n[i]=o.slice():(!t||!Cr(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&qr(arguments[o],r);return n}const Wm=(e,t,n,{allOwnKeys:r}={})=>(qr(t,(o,s)=>{n&&Dt(o)?e[s]=Cl(o,n):e[s]=o},{allOwnKeys:r}),e),Vm=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),Km=(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)},qm=(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&&fi(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},Gm=(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},Ym=e=>{if(!e)return null;if(Sr(e))return e;let t=e.length;if(!El(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},Xm=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&fi(Uint8Array)),Jm=(e,t)=>{const r=(e&&e[_o]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},Zm=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},Qm=rn("HTMLFormElement"),eg=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),Al=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),tg=rn("RegExp"),_l=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};qr(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},ng=e=>{_l(e,(t,n)=>{if(Dt(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(Dt(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+"'")})}})},rg=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return Sr(e)?r(e):r(String(e).split(t)),n},og=()=>{},sg=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function ig(e){return!!(e&&Dt(e.append)&&e[Tl]==="FormData"&&e[_o])}const ag=e=>{const t=new Array(10),n=(r,o)=>{if(Kr(r)){if(t.indexOf(r)>=0)return;if(Vr(r))return r;if(!("toJSON"in r)){t[o]=r;const s=Sr(r)?[]:{};return qr(r,(i,a)=>{const l=n(i,o+1);!Cr(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},lg=rn("AsyncFunction"),cg=e=>e&&(Kr(e)||Dt(e))&&Dt(e.then)&&Dt(e.catch),jl=((e,t)=>e?setImmediate:t?((n,r)=>(nr.addEventListener("message",({source:o,data:s})=>{o===nr&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),nr.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",Dt(nr.postMessage)),ug=typeof queueMicrotask<"u"?queueMicrotask.bind(nr):typeof process<"u"&&process.nextTick||jl,R={isArray:Sr,isArrayBuffer:kl,isBuffer:Vr,isFormData:Lm,isArrayBufferView:Nm,isString:Am,isNumber:El,isBoolean:_m,isObject:Kr,isPlainObject:Po,isEmptyObject:jm,isReadableStream:Fm,isRequest:zm,isResponse:Bm,isHeaders:Hm,isUndefined:Cr,isDate:Rm,isFile:Pm,isBlob:Om,isRegExp:tg,isFunction:Dt,isStream:Dm,isURLSearchParams:$m,isTypedArray:Xm,isFileList:Mm,forEach:qr,merge:hi,extend:Wm,trim:Um,stripBOM:Vm,inherits:Km,toFlatObject:qm,kindOf:jo,kindOfTest:rn,endsWith:Gm,toArray:Ym,forEachEntry:Jm,matchAll:Zm,isHTMLForm:Qm,hasOwnProperty:Al,hasOwnProp:Al,reduceDescriptors:_l,freezeMethods:ng,toObjectSet:rg,toCamelCase:eg,noop:og,toFiniteNumber:sg,findKey:Il,global:nr,isContextDefined:Nl,isSpecCompliantForm:ig,toJSONObject:ag,isAsyncFn:lg,isThenable:cg,setImmediate:jl,asap:ug,isIterable:e=>e!=null&&Dt(e[_o])};function Me(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)}R.inherits(Me,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:R.toJSONObject(this.config),code:this.code,status:this.status}}});const Rl=Me.prototype,Pl={};["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=>{Pl[e]={value:e}}),Object.defineProperties(Me,Pl),Object.defineProperty(Rl,"isAxiosError",{value:!0}),Me.from=(e,t,n,r,o,s)=>{const i=Object.create(Rl);R.toFlatObject(e,i,function(d){return d!==Error.prototype},u=>u!=="isAxiosError");const a=e&&e.message?e.message:"Error",l=t==null&&e?e.code:t;return Me.call(i,a,l,n,r,o),e&&i.cause==null&&Object.defineProperty(i,"cause",{value:e,configurable:!0}),i.name=e&&e.name||"Error",s&&Object.assign(i,s),i};const dg=null;function pi(e){return R.isPlainObject(e)||R.isArray(e)}function Ol(e){return R.endsWith(e,"[]")?e.slice(0,-2):e}function Ml(e,t,n){return e?e.concat(t).map(function(o,s){return o=Ol(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function fg(e){return R.isArray(e)&&!e.some(pi)}const hg=R.toFlatObject(R,{},null,function(t){return/^is[A-Z]/.test(t)});function Oo(e,t,n){if(!R.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=R.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(x,g){return!R.isUndefined(g[x])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&R.isSpecCompliantForm(t);if(!R.isFunction(o))throw new TypeError("visitor must be a function");function u(v){if(v===null)return"";if(R.isDate(v))return v.toISOString();if(R.isBoolean(v))return v.toString();if(!l&&R.isBlob(v))throw new Me("Blob is not supported. Use a Buffer instead.");return R.isArrayBuffer(v)||R.isTypedArray(v)?l&&typeof Blob=="function"?new Blob([v]):Buffer.from(v):v}function d(v,x,g){let y=v;if(v&&!g&&typeof v=="object"){if(R.endsWith(x,"{}"))x=r?x:x.slice(0,-2),v=JSON.stringify(v);else if(R.isArray(v)&&fg(v)||(R.isFileList(v)||R.endsWith(x,"[]"))&&(y=R.toArray(v)))return x=Ol(x),y.forEach(function(S,I){!(R.isUndefined(S)||S===null)&&t.append(i===!0?Ml([x],I,s):i===null?x:x+"[]",u(S))}),!1}return pi(v)?!0:(t.append(Ml(g,x,s),u(v)),!1)}const f=[],h=Object.assign(hg,{defaultVisitor:d,convertValue:u,isVisitable:pi});function p(v,x){if(!R.isUndefined(v)){if(f.indexOf(v)!==-1)throw Error("Circular reference detected in "+x.join("."));f.push(v),R.forEach(v,function(y,b){(!(R.isUndefined(y)||y===null)&&o.call(t,y,R.isString(b)?b.trim():b,x,h))===!0&&p(y,x?x.concat(b):[b])}),f.pop()}}if(!R.isObject(e))throw new TypeError("data must be an object");return p(e),t}function Dl(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function mi(e,t){this._pairs=[],e&&Oo(e,this,t)}const Ll=mi.prototype;Ll.append=function(t,n){this._pairs.push([t,n])},Ll.toString=function(t){const n=t?function(r){return t.call(this,r,Dl)}:Dl;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function pg(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function $l(e,t,n){if(!t)return e;const r=n&&n.encode||pg;R.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=R.isURLSearchParams(t)?t.toString():new mi(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class Fl{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){R.forEach(this.handlers,function(r){r!==null&&t(r)})}}const zl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},mg={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:mi,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},gi=typeof window<"u"&&typeof document<"u",xi=typeof navigator=="object"&&navigator||void 0,gg=gi&&(!xi||["ReactNative","NativeScript","NS"].indexOf(xi.product)<0),xg=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",yg=gi&&window.location.href||"http://localhost",It={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:gi,hasStandardBrowserEnv:gg,hasStandardBrowserWebWorkerEnv:xg,navigator:xi,origin:yg},Symbol.toStringTag,{value:"Module"})),...mg};function vg(e,t){return Oo(e,new It.classes.URLSearchParams,{visitor:function(n,r,o,s){return It.isNode&&R.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function bg(e){return R.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function wg(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 Bl(e){function t(n,r,o,s){let i=n[s++];if(i==="__proto__")return!0;const a=Number.isFinite(+i),l=s>=n.length;return i=!i&&R.isArray(o)?o.length:i,l?(R.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!R.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&R.isArray(o[i])&&(o[i]=wg(o[i])),!a)}if(R.isFormData(e)&&R.isFunction(e.entries)){const n={};return R.forEachEntry(e,(r,o)=>{t(bg(r),o,n,0)}),n}return null}function Sg(e,t,n){if(R.isString(e))try{return(t||JSON.parse)(e),R.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const Gr={transitional:zl,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=R.isObject(t);if(s&&R.isHTMLForm(t)&&(t=new FormData(t)),R.isFormData(t))return o?JSON.stringify(Bl(t)):t;if(R.isArrayBuffer(t)||R.isBuffer(t)||R.isStream(t)||R.isFile(t)||R.isBlob(t)||R.isReadableStream(t))return t;if(R.isArrayBufferView(t))return t.buffer;if(R.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 vg(t,this.formSerializer).toString();if((a=R.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return Oo(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),Sg(t)):t}],transformResponse:[function(t){const n=this.transitional||Gr.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(R.isResponse(t)||R.isReadableStream(t))return t;if(t&&R.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"?Me.from(a,Me.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:It.classes.FormData,Blob:It.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};R.forEach(["delete","get","head","post","put","patch"],e=>{Gr.headers[e]={}});const Cg=R.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"]),Tg=e=>{const t={};let n,r,o;return e&&e.split(`
|
|
31
|
+
`).forEach(function(i){o=i.indexOf(":"),n=i.substring(0,o).trim().toLowerCase(),r=i.substring(o+1).trim(),!(!n||t[n]&&Cg[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},Hl=Symbol("internals");function Yr(e){return e&&String(e).trim().toLowerCase()}function Mo(e){return e===!1||e==null?e:R.isArray(e)?e.map(Mo):String(e)}function kg(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 Eg=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function yi(e,t,n,r,o){if(R.isFunction(r))return r.call(this,t,n);if(o&&(t=n),!!R.isString(t)){if(R.isString(r))return t.indexOf(r)!==-1;if(R.isRegExp(r))return r.test(t)}}function Ig(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function Ng(e,t){const n=R.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 Lt=class{constructor(t){t&&this.set(t)}set(t,n,r){const o=this;function s(a,l,u){const d=Yr(l);if(!d)throw new Error("header name must be a non-empty string");const f=R.findKey(o,d);(!f||o[f]===void 0||u===!0||u===void 0&&o[f]!==!1)&&(o[f||l]=Mo(a))}const i=(a,l)=>R.forEach(a,(u,d)=>s(u,d,l));if(R.isPlainObject(t)||t instanceof this.constructor)i(t,n);else if(R.isString(t)&&(t=t.trim())&&!Eg(t))i(Tg(t),n);else if(R.isObject(t)&&R.isIterable(t)){let a={},l,u;for(const d of t){if(!R.isArray(d))throw TypeError("Object iterator must return a key-value pair");a[u=d[0]]=(l=a[u])?R.isArray(l)?[...l,d[1]]:[l,d[1]]:d[1]}i(a,n)}else t!=null&&s(n,t,r);return this}get(t,n){if(t=Yr(t),t){const r=R.findKey(this,t);if(r){const o=this[r];if(!n)return o;if(n===!0)return kg(o);if(R.isFunction(n))return n.call(this,o,r);if(R.isRegExp(n))return n.exec(o);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,n){if(t=Yr(t),t){const r=R.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||yi(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let o=!1;function s(i){if(i=Yr(i),i){const a=R.findKey(r,i);a&&(!n||yi(r,r[a],a,n))&&(delete r[a],o=!0)}}return R.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||yi(this,this[s],s,t,!0))&&(delete this[s],o=!0)}return o}normalize(t){const n=this,r={};return R.forEach(this,(o,s)=>{const i=R.findKey(r,s);if(i){n[i]=Mo(o),delete n[s];return}const a=t?Ig(s):String(s).trim();a!==s&&delete n[s],n[a]=Mo(o),r[a]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return R.forEach(this,(r,o)=>{r!=null&&r!==!1&&(n[o]=t&&R.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(`
|
|
32
|
+
`)}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[Hl]=this[Hl]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Yr(i);r[a]||(Ng(o,i),r[a]=!0)}return R.isArray(t)?t.forEach(s):s(t),this}};Lt.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),R.reduceDescriptors(Lt.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),R.freezeMethods(Lt);function vi(e,t){const n=this||Gr,r=t||n,o=Lt.from(r.headers);let s=r.data;return R.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function Ul(e){return!!(e&&e.__CANCEL__)}function Tr(e,t,n){Me.call(this,e??"canceled",Me.ERR_CANCELED,t,n),this.name="CanceledError"}R.inherits(Tr,Me,{__CANCEL__:!0});function Wl(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Me("Request failed with status code "+n.status,[Me.ERR_BAD_REQUEST,Me.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function Ag(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function _g(e,t){e=e||10;const n=new Array(e),r=new Array(e);let o=0,s=0,i;return t=t!==void 0?t:1e3,function(l){const u=Date.now(),d=r[s];i||(i=u),n[o]=l,r[o]=u;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),u-i<t)return;const p=d&&u-d;return p?Math.round(h*1e3/p):void 0}}function jg(e,t){let n=0,r=1e3/t,o,s;const i=(u,d=Date.now())=>{n=d,o=null,s&&(clearTimeout(s),s=null),e(...u)};return[(...u)=>{const d=Date.now(),f=d-n;f>=r?i(u,d):(o=u,s||(s=setTimeout(()=>{s=null,i(o)},r-f)))},()=>o&&i(o)]}const Do=(e,t,n=3)=>{let r=0;const o=_g(50,250);return jg(s=>{const i=s.loaded,a=s.lengthComputable?s.total:void 0,l=i-r,u=o(l),d=i<=a;r=i;const f={loaded:i,total:a,progress:a?i/a:void 0,bytes:l,rate:u||void 0,estimated:u&&a&&d?(a-i)/u:void 0,event:s,lengthComputable:a!=null,[t?"download":"upload"]:!0};e(f)},n)},Vl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},Kl=e=>(...t)=>R.asap(()=>e(...t)),Rg=It.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,It.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(It.origin),It.navigator&&/(msie|trident)/i.test(It.navigator.userAgent)):()=>!0,Pg=It.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];R.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),R.isString(r)&&i.push("path="+r),R.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 Og(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function Mg(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function ql(e,t,n){let r=!Og(t);return e&&(r||n==!1)?Mg(e,t):t}const Gl=e=>e instanceof Lt?{...e}:e;function rr(e,t){t=t||{};const n={};function r(u,d,f,h){return R.isPlainObject(u)&&R.isPlainObject(d)?R.merge.call({caseless:h},u,d):R.isPlainObject(d)?R.merge({},d):R.isArray(d)?d.slice():d}function o(u,d,f,h){if(R.isUndefined(d)){if(!R.isUndefined(u))return r(void 0,u,f,h)}else return r(u,d,f,h)}function s(u,d){if(!R.isUndefined(d))return r(void 0,d)}function i(u,d){if(R.isUndefined(d)){if(!R.isUndefined(u))return r(void 0,u)}else return r(void 0,d)}function a(u,d,f){if(f in t)return r(u,d);if(f in e)return r(void 0,u)}const l={url:s,method:s,data:s,baseURL:i,transformRequest:i,transformResponse:i,paramsSerializer:i,timeout:i,timeoutMessage:i,withCredentials:i,withXSRFToken:i,adapter:i,responseType:i,xsrfCookieName:i,xsrfHeaderName:i,onUploadProgress:i,onDownloadProgress:i,decompress:i,maxContentLength:i,maxBodyLength:i,beforeRedirect:i,transport:i,httpAgent:i,httpsAgent:i,cancelToken:i,socketPath:i,responseEncoding:i,validateStatus:a,headers:(u,d,f)=>o(Gl(u),Gl(d),f,!0)};return R.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,h=f(e[d],t[d],d);R.isUndefined(h)&&f!==a||(n[d]=h)}),n}const Yl=e=>{const t=rr({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=Lt.from(i),t.url=$l(ql(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),R.isFormData(n)){if(It.hasStandardBrowserEnv||It.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(R.isFunction(n.getHeaders)){const l=n.getHeaders(),u=["content-type","content-length"];Object.entries(l).forEach(([d,f])=>{u.includes(d.toLowerCase())&&i.set(d,f)})}}if(It.hasStandardBrowserEnv&&(r&&R.isFunction(r)&&(r=r(t)),r||r!==!1&&Rg(t.url))){const l=o&&s&&Pg.read(s);l&&i.set(o,l)}return t},Dg=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=Yl(e);let s=o.data;const i=Lt.from(o.headers).normalize();let{responseType:a,onUploadProgress:l,onDownloadProgress:u}=o,d,f,h,p,v;function x(){p&&p(),v&&v(),o.cancelToken&&o.cancelToken.unsubscribe(d),o.signal&&o.signal.removeEventListener("abort",d)}let g=new XMLHttpRequest;g.open(o.method.toUpperCase(),o.url,!0),g.timeout=o.timeout;function y(){if(!g)return;const S=Lt.from("getAllResponseHeaders"in g&&g.getAllResponseHeaders()),C={data:!a||a==="text"||a==="json"?g.responseText:g.response,status:g.status,statusText:g.statusText,headers:S,config:e,request:g};Wl(function(E){n(E),x()},function(E){r(E),x()},C),g=null}"onloadend"in g?g.onloadend=y:g.onreadystatechange=function(){!g||g.readyState!==4||g.status===0&&!(g.responseURL&&g.responseURL.indexOf("file:")===0)||setTimeout(y)},g.onabort=function(){g&&(r(new Me("Request aborted",Me.ECONNABORTED,e,g)),g=null)},g.onerror=function(I){const C=I&&I.message?I.message:"Network Error",T=new Me(C,Me.ERR_NETWORK,e,g);T.event=I||null,r(T),g=null},g.ontimeout=function(){let I=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const C=o.transitional||zl;o.timeoutErrorMessage&&(I=o.timeoutErrorMessage),r(new Me(I,C.clarifyTimeoutError?Me.ETIMEDOUT:Me.ECONNABORTED,e,g)),g=null},s===void 0&&i.setContentType(null),"setRequestHeader"in g&&R.forEach(i.toJSON(),function(I,C){g.setRequestHeader(C,I)}),R.isUndefined(o.withCredentials)||(g.withCredentials=!!o.withCredentials),a&&a!=="json"&&(g.responseType=o.responseType),u&&([h,v]=Do(u,!0),g.addEventListener("progress",h)),l&&g.upload&&([f,p]=Do(l),g.upload.addEventListener("progress",f),g.upload.addEventListener("loadend",p)),(o.cancelToken||o.signal)&&(d=S=>{g&&(r(!S||S.type?new Tr(null,e,g):S),g.abort(),g=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const b=Ag(o.url);if(b&&It.protocols.indexOf(b)===-1){r(new Me("Unsupported protocol "+b+":",Me.ERR_BAD_REQUEST,e));return}g.send(s||null)})},Lg=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let r=new AbortController,o;const s=function(u){if(!o){o=!0,a();const d=u instanceof Error?u:this.reason;r.abort(d instanceof Me?d:new Tr(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new Me(`timeout ${t} of ms exceeded`,Me.ETIMEDOUT))},t);const a=()=>{e&&(i&&clearTimeout(i),i=null,e.forEach(u=>{u.unsubscribe?u.unsubscribe(s):u.removeEventListener("abort",s)}),e=null)};e.forEach(u=>u.addEventListener("abort",s));const{signal:l}=r;return l.unsubscribe=()=>R.asap(a),l}},$g=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},Fg=async function*(e,t){for await(const n of zg(e))yield*$g(n,t)},zg=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()}},Xl=(e,t,n,r)=>{const o=Fg(e,t);let s=0,i,a=l=>{i||(i=!0,r&&r(l))};return new ReadableStream({async pull(l){try{const{done:u,value:d}=await o.next();if(u){a(),l.close();return}let f=d.byteLength;if(n){let h=s+=f;n(h)}l.enqueue(new Uint8Array(d))}catch(u){throw a(u),u}},cancel(l){return a(l),o.return()}},{highWaterMark:2})},Jl=64*1024,{isFunction:Lo}=R,Bg=(({Request:e,Response:t})=>({Request:e,Response:t}))(R.global),{ReadableStream:Zl,TextEncoder:Ql}=R.global,ec=(e,...t)=>{try{return!!e(...t)}catch{return!1}},Hg=e=>{e=R.merge.call({skipUndefined:!0},Bg,e);const{fetch:t,Request:n,Response:r}=e,o=t?Lo(t):typeof fetch=="function",s=Lo(n),i=Lo(r);if(!o)return!1;const a=o&&Lo(Zl),l=o&&(typeof Ql=="function"?(v=>x=>v.encode(x))(new Ql):async v=>new Uint8Array(await new n(v).arrayBuffer())),u=s&&a&&ec(()=>{let v=!1;const x=new n(It.origin,{body:new Zl,method:"POST",get duplex(){return v=!0,"half"}}).headers.has("Content-Type");return v&&!x}),d=i&&a&&ec(()=>R.isReadableStream(new r("").body)),f={stream:d&&(v=>v.body)};o&&["text","arrayBuffer","blob","formData","stream"].forEach(v=>{!f[v]&&(f[v]=(x,g)=>{let y=x&&x[v];if(y)return y.call(x);throw new Me(`Response type '${v}' is not supported`,Me.ERR_NOT_SUPPORT,g)})});const h=async v=>{if(v==null)return 0;if(R.isBlob(v))return v.size;if(R.isSpecCompliantForm(v))return(await new n(It.origin,{method:"POST",body:v}).arrayBuffer()).byteLength;if(R.isArrayBufferView(v)||R.isArrayBuffer(v))return v.byteLength;if(R.isURLSearchParams(v)&&(v=v+""),R.isString(v))return(await l(v)).byteLength},p=async(v,x)=>{const g=R.toFiniteNumber(v.getContentLength());return g??h(x)};return async v=>{let{url:x,method:g,data:y,signal:b,cancelToken:S,timeout:I,onDownloadProgress:C,onUploadProgress:T,responseType:E,headers:A,withCredentials:j="same-origin",fetchOptions:P}=Yl(v),D=t||fetch;E=E?(E+"").toLowerCase():"text";let L=Lg([b,S&&S.toAbortSignal()],I),V=null;const M=L&&L.unsubscribe&&(()=>{L.unsubscribe()});let X;try{if(T&&u&&g!=="get"&&g!=="head"&&(X=await p(A,y))!==0){let F=new n(x,{method:"POST",body:y,duplex:"half"}),te;if(R.isFormData(y)&&(te=F.headers.get("content-type"))&&A.setContentType(te),F.body){const[fe,ge]=Vl(X,Do(Kl(T)));y=Xl(F.body,Jl,fe,ge)}}R.isString(j)||(j=j?"include":"omit");const K=s&&"credentials"in n.prototype,q={...P,signal:L,method:g.toUpperCase(),headers:A.normalize().toJSON(),body:y,duplex:"half",credentials:K?j:void 0};V=s&&new n(x,q);let z=await(s?D(V,P):D(x,q));const $=d&&(E==="stream"||E==="response");if(d&&(C||$&&M)){const F={};["status","statusText","headers"].forEach(be=>{F[be]=z[be]});const te=R.toFiniteNumber(z.headers.get("content-length")),[fe,ge]=C&&Vl(te,Do(Kl(C),!0))||[];z=new r(Xl(z.body,Jl,fe,()=>{ge&&ge(),M&&M()}),F)}E=E||"text";let pe=await f[R.findKey(f,E)||"text"](z,v);return!$&&M&&M(),await new Promise((F,te)=>{Wl(F,te,{data:pe,headers:Lt.from(z.headers),status:z.status,statusText:z.statusText,config:v,request:V})})}catch(K){throw M&&M(),K&&K.name==="TypeError"&&/Load failed|fetch/i.test(K.message)?Object.assign(new Me("Network Error",Me.ERR_NETWORK,v,V),{cause:K.cause||K}):Me.from(K,K&&K.code,v,V)}}},Ug=new Map,tc=e=>{let t=e?e.env:{};const{fetch:n,Request:r,Response:o}=t,s=[r,o,n];let i=s.length,a=i,l,u,d=Ug;for(;a--;)l=s[a],u=d.get(l),u===void 0&&d.set(l,u=a?new Map:Hg(t)),d=u;return u};tc();const bi={http:dg,xhr:Dg,fetch:{get:tc}};R.forEach(bi,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const nc=e=>`- ${e}`,Wg=e=>R.isFunction(e)||e===null||e===!1,rc={getAdapter:(e,t)=>{e=R.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,!Wg(r)&&(o=bi[(a=String(r)).toLowerCase()],o===void 0))throw new Me(`Unknown adapter '${a}'`);if(o&&(R.isFunction(o)||(o=o.get(t))))break;s[a||"#"+i]=o}if(!o){const i=Object.entries(s).map(([l,u])=>`adapter ${l} `+(u===!1?"is not supported by the environment":"is not available in the build"));let a=n?i.length>1?`since :
|
|
33
|
+
`+i.map(nc).join(`
|
|
34
|
+
`):" "+nc(i[0]):"as no adapter specified";throw new Me("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:bi};function wi(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new Tr(null,e)}function oc(e){return wi(e),e.headers=Lt.from(e.headers),e.data=vi.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),rc.getAdapter(e.adapter||Gr.adapter,e)(e).then(function(r){return wi(e),r.data=vi.call(e,e.transformResponse,r),r.headers=Lt.from(r.headers),r},function(r){return Ul(r)||(wi(e),r&&r.response&&(r.response.data=vi.call(e,e.transformResponse,r.response),r.response.headers=Lt.from(r.response.headers))),Promise.reject(r)})}const sc="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 ic={};$o.transitional=function(t,n,r){function o(s,i){return"[Axios v"+sc+"] Transitional option '"+s+"'"+i+(r?". "+r:"")}return(s,i,a)=>{if(t===!1)throw new Me(o(i," has been removed"+(n?" in "+n:"")),Me.ERR_DEPRECATED);return n&&!ic[i]&&(ic[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 Vg(e,t,n){if(typeof e!="object")throw new Me("options must be an object",Me.ERR_BAD_OPTION_VALUE);const r=Object.keys(e);let o=r.length;for(;o-- >0;){const s=r[o],i=t[s];if(i){const a=e[s],l=a===void 0||i(a,s,e);if(l!==!0)throw new Me("option "+s+" must be "+l,Me.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new Me("Unknown option "+s,Me.ERR_BAD_OPTION)}}const Fo={assertOptions:Vg,validators:$o},hn=Fo.validators;let or=class{constructor(t){this.defaults=t||{},this.interceptors={request:new Fl,response:new Fl}}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+=`
|
|
35
|
+
`+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=rr(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&Fo.assertOptions(r,{silentJSONParsing:hn.transitional(hn.boolean),forcedJSONParsing:hn.transitional(hn.boolean),clarifyTimeoutError:hn.transitional(hn.boolean)},!1),o!=null&&(R.isFunction(o)?n.paramsSerializer={serialize:o}:Fo.assertOptions(o,{encode:hn.function,serialize:hn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),Fo.assertOptions(n,{baseUrl:hn.spelling("baseURL"),withXsrfToken:hn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&R.merge(s.common,s[n.method]);s&&R.forEach(["delete","get","head","post","put","patch","common"],v=>{delete s[v]}),n.headers=Lt.concat(i,s);const a=[];let l=!0;this.interceptors.request.forEach(function(x){typeof x.runWhen=="function"&&x.runWhen(n)===!1||(l=l&&x.synchronous,a.unshift(x.fulfilled,x.rejected))});const u=[];this.interceptors.response.forEach(function(x){u.push(x.fulfilled,x.rejected)});let d,f=0,h;if(!l){const v=[oc.bind(this),void 0];for(v.unshift(...a),v.push(...u),h=v.length,d=Promise.resolve(n);f<h;)d=d.then(v[f++],v[f++]);return d}h=a.length;let p=n;for(;f<h;){const v=a[f++],x=a[f++];try{p=v(p)}catch(g){x.call(this,g);break}}try{d=oc.call(this,p)}catch(v){return Promise.reject(v)}for(f=0,h=u.length;f<h;)d=d.then(u[f++],u[f++]);return d}getUri(t){t=rr(this.defaults,t);const n=ql(t.baseURL,t.url,t.allowAbsoluteUrls);return $l(n,t.params,t.paramsSerializer)}};R.forEach(["delete","get","head","options"],function(t){or.prototype[t]=function(n,r){return this.request(rr(r||{},{method:t,url:n,data:(r||{}).data}))}}),R.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(rr(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}or.prototype[t]=n(),or.prototype[t+"Form"]=n(!0)});let Kg=class Sm{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 Tr(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 Sm(function(o){t=o}),cancel:t}}};function qg(e){return function(n){return e.apply(null,n)}}function Gg(e){return R.isObject(e)&&e.isAxiosError===!0}const Si={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(Si).forEach(([e,t])=>{Si[t]=e});function ac(e){const t=new or(e),n=Cl(or.prototype.request,t);return R.extend(n,or.prototype,t,{allOwnKeys:!0}),R.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return ac(rr(e,o))},n}const mt=ac(Gr);mt.Axios=or,mt.CanceledError=Tr,mt.CancelToken=Kg,mt.isCancel=Ul,mt.VERSION=sc,mt.toFormData=Oo,mt.AxiosError=Me,mt.Cancel=mt.CanceledError,mt.all=function(t){return Promise.all(t)},mt.spread=qg,mt.isAxiosError=Gg,mt.mergeConfig=rr,mt.AxiosHeaders=Lt,mt.formToJSON=e=>Bl(R.isHTMLForm(e)?new FormData(e):e),mt.getAdapter=rc.getAdapter,mt.HttpStatusCode=Si,mt.default=mt;const{Axios:$T,AxiosError:FT,CanceledError:zT,isCancel:BT,CancelToken:HT,VERSION:UT,all:WT,Cancel:VT,isAxiosError:KT,spread:qT,toFormData:GT,AxiosHeaders:YT,HttpStatusCode:XT,formToJSON:JT,getAdapter:ZT,mergeConfig:QT}=mt,lc=typeof window<"u"?window.__API_BASE_URL__:void 0,cc=lc?_n(lc):void 0;function _n(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let zo=null;const Ci=new Set;function uc(){return zo}function Ti(e){zo=e,Ci.forEach(t=>t(e))}function dc(e){return Ci.add(e),()=>Ci.delete(e)}const Gt=mt.create({...cc?{baseURL:cc}:{},timeout:3e4,withCredentials:!0});Gt.interceptors.request.use(e=>(zo&&(e.headers.Authorization=`Bearer ${zo}`),e)),Gt.interceptors.response.use(e=>e,e=>Promise.reject(e));async function pn(e,t){return Gt.defaults.baseURL?(await Gt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function fc(e,t,n){return Gt.defaults.baseURL?(await Gt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function hc(e,t,n){return Gt.defaults.baseURL?(await Gt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function pc(e,t){return Gt.defaults.baseURL?(await Gt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function jn(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class mc{get baseUrl(){const t=Gt.defaults.baseURL;return t?_n(String(t)):""}updateConfig(t){t.baseUrl&&(Gt.defaults.baseURL=_n(String(t.baseUrl))),t.authToken!==void 0&&Ti(t.authToken)}getAuthToken(){return uc()}setAuthToken(t){Ti(t)}onTokenChange(t){return dc(t)}async listThreads(){const t=await pn("/threads"),n=jn(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await fc("/threads",t?{title:t}:void 0);return jn(r)}async updateThread(t,n){const r=await hc(`/threads/${t}`,{title:n});return jn(r)}async deleteThread(t){const n=await pc(`/threads/${t}`);return jn(n)}async threadInfo(t){const n=await pn(`/threads/${t}/info`);return jn(n)}async listAgents(){const t=await pn("/agents"),n=jn(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await pn(`/agents/${t}`);return jn(n)}async getAgentSchema(t){const n=await pn(`/agents/${t}/schema`);return jn(n)}async getStateHistory(t){const n=await pn(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return jn(n)}}const $n=new mc,gc=w.createContext(null);function Yg({children:e,apiConfig:t}){const n=$n;if(t){const o=n.baseUrl,s=n.getAuthToken();t.baseUrl&&t.baseUrl!==o&&n.updateConfig({baseUrl:t.baseUrl}),t.apiKey!==void 0&&t.apiKey!==s&&n.updateConfig({authToken:t.apiKey})}const r={token:n.getAuthToken(),setToken:o=>n.setAuthToken(o),api:n,baseUrl:n.baseUrl};return c.jsx(gc.Provider,{value:r,children:e})}function ki(){const e=w.useContext(gc);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function Xg(e){return await new Promise((t,n)=>{const r=new FileReader;r.onload=()=>{try{const o=r.result,s=new Uint8Array(o);let i="";const a=s.byteLength;for(let l=0;l<a;l++)i+=String.fromCharCode(s[l]);t(btoa(i))}catch(o){n(o)}},r.onerror=o=>n(o),r.readAsArrayBuffer(e)})}async function Jg(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const u=await Xg(l);a.push({filename:l.name,data:u,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const Zg={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function Ei(e){if(!e||typeof e!="object")return!1;const t=e;return"values"in t&&"config"in t&&typeof t.values=="object"&&t.values!==null&&typeof t.config=="object"&&t.config!==null}function Bo(e,t){return`${e??""}::${t??""}`}function xc(e){const t=Array.isArray(e==null?void 0:e.checkpoints)?(e==null?void 0:e.checkpoints)??[]:e!=null&&e.checkpoints?Object.values(e.checkpoints):[],n=(e==null?void 0:e.threadId)??"",r=t[0];if(!Ei(r))return{threadId:n,latest:null,checkpoints:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=ex(t),i=yc(r,0);return{threadId:n,latest:i,checkpoints:o,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function yc(e,t){var C,T;if(!Ei(e))return null;const n=e.values??{},r=Array.isArray(n==null?void 0:n.messages)?n.messages:[],o=e.tasks,s=r.map((E,A)=>sx(E,A)).filter(E=>!!E),i=zt((C=e.config)==null?void 0:C.configurable),a=ut(i,["checkpoint_id","checkpointId"]),l=ut(i,["checkpoint_ns","checkpointNs"]),u=zt((T=e.parentConfig)==null?void 0:T.configurable),d=ut(u,["checkpoint_id","checkpointId"])??null,f=ut(u,["checkpoint_ns","checkpointNs"])??null,h=e==null?void 0:e.createdAt,p=typeof h=="string"&&h.trim()?h:new Date(Date.now()-t).toISOString(),v=tx(s),x=s[s.length-1]??null,g=zt(e==null?void 0:e.metadata),y=ut(g,["branch_label","branchLabel"]),b=zt(e==null?void 0:e.parentConfig),S=zt(b==null?void 0:b.configurable),I=ut(S,["checkpoint_id","checkpointId"]);return{messages:s,checkpointId:a??null,checkpointNs:l??null,nextCursor:d,nextCursorNs:f,interrupt:Qg(o,s,t),createdAt:p,preview:v??null,role:(x==null?void 0:x.role)??null,parentId:I??null,branchLabel:y??null,lastMessageId:(x==null?void 0:x.id)??null,hasMessages:s.length>0,messagesLen:s.length}}function Qg(e,t,n){const r=rx(e,n);return r||nx(t,n)}function ex(e){const t=new Map;e.forEach((o,s)=>{if(!Ei(o))return;const i=yc(o,s);if(!(i!=null&&i.checkpointId))return;const a=Bo(i.checkpointId,i.checkpointNs??null);t.has(a)||t.set(a,i)});const n=Array.from(t.values());n.sort((o,s)=>bc(s.createdAt??"")-bc(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function tx(e){var t;for(let n=e.length-1;n>=0;n--){const r=((t=e[n])==null?void 0:t.content)??[];for(let o=0;o<r.length;o++){const s=r[o];if(s&&s.type==="text"&&typeof s.text=="string"){const i=s.text.trim();if(i)return i}}}return null}function nx(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 rx(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=ox(e[n],`task-${t}-${n}`);if(!r)continue;const o=r.id||`task-${t}-${n}`;if(Array.isArray(r.interrupts)&&r.interrupts.length)for(let s=r.interrupts.length-1;s>=0;s--){const i=Xr(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=Xr(r.state,`${o}-state`);if(s)return s}}return null}function ox(e,t){if(!e)return null;if(Array.isArray(e)){const[a,l,u,,d,,f,...h]=e,p=typeof a=="string"&&a.trim()?a:t,v=typeof l=="string"&&l.trim()?l:Array.isArray(u)&&typeof u[0]=="string"?String(u[0]):"task",x=Array.isArray(d)?d:void 0,g=h.length?h[h.length-1]:void 0;return{id:p,name:v,interrupts:x,state:g!==void 0?g:f}}const n=zt(e);if(!n)return null;const r=ut(n,["id","task_id","taskId"])??t,o=ut(n,["name"])??"task",s=Array.isArray(n.interrupts)?n.interrupts:void 0,i=Object.prototype.hasOwnProperty.call(n,"state")?n.state:void 0;return{id:r,name:o,interrupts:s,state:i}}function Xr(e,t,n=0,r=new Set){if(n>6||e==null)return null;if(typeof e=="object"){if(r.has(e))return null;r.add(e)}const o=vc(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=Xr(e[s],t,n+1,r);if(i)return i}return null}if(typeof e=="object"){const s=e,i=["interrupt","pending_interrupt","pendingInterrupt","value","data","payload","result","response"];for(const a of i)if(a in s){const l=Xr(s[a],t,n+1,r);if(l)return l}for(const[a,l]of Object.entries(s)){if(i.includes(a)||a==="messages"||a==="results")continue;const u=Xr(l,t,n+1,r);if(u)return u}}return null}function vc(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=ut(n,["type","event","kind"]),o=ut(n,["id","interrupt_id","interruptId","value_id"])??(r&&r.toLowerCase().includes("interrupt")?t:void 0);if(!(Object.prototype.hasOwnProperty.call(n,"value")||Object.prototype.hasOwnProperty.call(n,"data")||Object.prototype.hasOwnProperty.call(n,"payload"))&&!(r&&r.toLowerCase().includes("interrupt")))return null;const i=Object.prototype.hasOwnProperty.call(n,"value")?n.value:Object.prototype.hasOwnProperty.call(n,"data")?n.data:Object.prototype.hasOwnProperty.call(n,"payload")?n.payload:n,a=o&&o.trim()?o:t;return a?{id:a,value:i}:null}if(Array.isArray(e)){for(let n=e.length-1;n>=0;n--){const r=vc(e[n],t);if(r)return r}return e.length>=2&&typeof e[0]=="string"&&e[0].trim()?{id:e[0],value:e[1]}:null}if(typeof e=="string"){const n=e.trim();return n?{id:t||n,value:n}:null}return null}function bc(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function sx(e,t){if(!e||typeof e!="object")return null;const n=e,r=zt(e)??{},o=zt(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=Zg[s];if(!i)return null;const a=o.id??o.message_id??o.run_id??null,l=typeof a=="string"&&a.trim()?a:`history-${i}-${t}`,u=zt(o.additional_kwargs)??zt(o.additionalKwargs),d=zt(o.response_metadata)??zt(o.responseMetadata),f=ut(u,["createdAt","created_at"])??ut(o,["created_at","createdAt"]),h=ut(u,["checkpointId","checkpoint_id"]),p=ut(u,["checkpointNs","checkpoint_ns"]),v=ix(o.content),x={id:l,role:i,content:v};f&&(x.createdAt=f),typeof o.name=="string"&&o.name.trim()&&(x.name=o.name),typeof(d==null?void 0:d.model_name)=="string"&&(x.model=String(d.model_name)),!x.model&&typeof o.model=="string"&&(x.model=o.model),h&&(x.checkpointId=h),p&&(x.checkpointNs=p);const g=dx(u,["createdAt","created_at","checkpointId","checkpoint_id","checkpointNs","checkpoint_ns","tool_calls"]),y=d?{...d}:void 0;g&&Object.keys(g).length&&(x.additionalKwargs=g),y&&Object.keys(y).length&&(x.responseMetadata=y);const b=ax((u==null?void 0:u.tool_calls)??o.tool_calls);if(b.length&&(x.content=[...x.content,...b]),i==="tool"){const S=cx(o,x.content);S&&(x.content=S)}return x}function ix(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>wc(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=wc(e);return t?[t]:[]}return[]}function wc(e){if(!e||typeof e!="object")return typeof e=="string"&&e.trim()?{type:"text",text:e}:null;const t=e,n=String(t.type??"").toLowerCase();if(!n||n==="text"){const o=typeof t.text=="string"?t.text:typeof t.value=="string"?t.value:"";return o.trim()?{type:"text",text:o}:null}if(n==="image"||n==="image_url"){const o=ut(t,["url","src"]);if(!o)return null;const s={type:"image_url",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.alt=="string"&&(s.alt=t.alt),s}if(n==="file"){const o=ut(t,["url"]);if(!o)return null;const s={type:"file",url:o};return typeof t.mimeType=="string"&&(s.mimeType=t.mimeType),typeof t.name=="string"&&(s.name=t.name),typeof t.size=="number"&&(s.size=t.size),typeof t.sourceType=="string"&&(s.sourceType=t.sourceType),s}if(n==="tool_call")return lx(t)??null;if(n==="tool_end"){const o=ut(t,["tool_call_id","toolCallId","id"]);if(!o)return null;const s={type:"tool_end",toolCallId:o,output:"output"in t?t.output:t.content};return typeof t.error=="string"&&(s.error=t.error),s}if(n==="interrupt")return{type:"interrupt",value:t.value,...t};if(n==="tool"){const o=ut(t,["text","content"]);if(o)return{type:"text",text:o}}const r=typeof t.content=="string"?t.content:typeof t.value=="string"?t.value:JSON.stringify(t);return r?{type:"text",text:r}:null}function ax(e){return Array.isArray(e)?e.map((t,n)=>{if(!t||typeof t!="object")return null;const r=t,o=ut(r,["id","call_id"]),s=zt(r.function),i=ut(s,["name"])??"tool",a=s==null?void 0:s.arguments,l=Sc(a);return{type:"tool_call",id:o??`tool_call_${n}`,name:i,args:l}}).filter(t=>!!t):[]}function lx(e){const t=ut(e,["id","call_id"]),n=ut(e,["name"]);if(!t||!n)return null;const r=Sc(e.args??e.arguments);return{type:"tool_call",id:t,name:n,args:r}}function cx(e,t){const n=ut(e,["tool_call_id","toolCallId","id"]);if(!n)return t;const r=e.content??e.output,o=typeof r=="string"?ux(r):r,s={type:"tool_end",toolCallId:n,output:o};return typeof e.error=="string"&&(s.error=e.error),[s]}function Sc(e){if(!e)return{};if(typeof e=="string")try{const t=JSON.parse(e);return typeof t=="object"&&t!==null?t:{raw:e}}catch{return{raw:e}}return typeof e=="object"&&!Array.isArray(e)?{...e}:{}}function ux(e){try{return JSON.parse(e)}catch{return e}}function zt(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function ut(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function dx(e,t){if(!e)return;const n={};let r=!1;for(const[o,s]of Object.entries(e)){if(t.includes(o)){r=!0;continue}s!==void 0&&(n[o]=s)}return r?Object.keys(n).length?n:void 0:e}function fx(e){return e.type!=="thread_info"&&e.type!=="token"}const hx={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function px(e,t){var n;switch(t.type){case"reset":{console.log("[MessageReducer] 🔄 RESET action received"),console.log("[MessageReducer] 📊 Before reset - messages count:",e.messages.length);const r={messages:Ii(((n=t.payload)==null?void 0:n.messages)??[]),assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,pendingInterrupt:null};return console.log("[MessageReducer] 📊 After reset - messages count:",r.messages.length),r}case"seed":{const r=Ii(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),console.log("[MessageReducer] seed action (REPLACE mode):",{incomingCount:t.payload.messages.length,sanitizedCount:r.length,previousCount:e.messages.length,checkpointId:o.lastCheckpointId}),o}case"prepend":{const r=Ii(t.payload.messages);if(!r.length)return console.log("[MessageReducer] No incoming messages after sanitize - skipping"),e;const o=new Set(e.messages.map(i=>i.id)),s=r.filter(i=>!o.has(i.id));return console.log("[MessageReducer] After dedup:",{uniqueCount:s.length,duplicates:r.length-s.length,finalTotal:s.length+e.messages.length}),s.length?{...e,messages:[...s,...e.messages]}:(console.log("[MessageReducer] All messages were duplicates - skipping"),e)}case"user_message":{const r=t.payload.message;return e.messages.some(o=>o.id===r.id)?e:{...e,messages:[...e.messages,r]}}case"event":return Tc(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Tc(o,s),e):e}case"interrupt_response":{const{interruptId:r}=t.payload,o=e.messages.map(s=>({...s,content:s.content.filter(i=>i.type!=="interrupt")}));return{...e,messages:o,pendingInterrupt:null}}default:return e}}function Cc(e=[]){const[t,n]=w.useReducer(px,{...hx,messages:e}),r=w.useRef([]),o=w.useRef(null),s=w.useRef(null),i=w.useCallback(()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),o.current=null,s.current=null;const d=r.current;d.length&&(r.current=[],n({type:"batch",payload:{events:d}}))},[]),a=w.useCallback(()=>{typeof window<"u"&&typeof window.requestAnimationFrame=="function"?o.current===null&&(o.current=window.requestAnimationFrame(()=>i())):s.current===null&&(s.current=setTimeout(i,8))},[i]),l=w.useCallback(d=>{r.current.push(d),a()},[a]);w.useEffect(()=>()=>{o.current!==null&&typeof window<"u"&&window.cancelAnimationFrame(o.current),s.current!==null&&clearTimeout(s.current),r.current=[]},[]);const u=w.useMemo(()=>({reset:d=>n({type:"reset",payload:{messages:d}}),seed:(d,f)=>n({type:"seed",payload:{messages:d,...f??{}}}),prepend:d=>n({type:"prepend",payload:{messages:d}}),pushUser:d=>n({type:"user_message",payload:{message:d}}),onEvent:l}),[l]);return{state:t,dispatch:n,...u}}function Tc(e,t){var n,r,o,s;if(t.type==="message_start"&&t.role==="assistant"){const i=t.id,a=xx(t.model);if(e.messages.some(d=>d.id===i)){const d=e.messagesStreamMeta??{},f={...d,[i]:d[i]??{lastSeq:t.seq??null,lastText:""}};return{...e,assemblingId:i,messagesStreamMeta:f}}const u={id:i,role:"assistant",name:a||void 0,model:t.model,createdAt:new Date().toISOString(),content:[]};return{...e,assemblingId:i,messages:[...e.messages,u]}}if(t.type==="message_delta"){const i=e.assemblingId??Ni(e.messages);if(!i)return e;const a=e.messages,l=a.findIndex(S=>S.id===i&&S.role==="assistant");if(l===-1)return e;const u=a[l],d=e.messagesStreamMeta??{},f=d[i]??{lastSeq:null,lastText:Ac(u.content)},h=t.seq??null;if(h!==null&&typeof h=="number"&&typeof f.lastSeq=="number"&&h<=f.lastSeq)return console.debug("[MessageReducer] skipping delta - seq <= lastSeq",{seq:h,lastSeq:f.lastSeq}),e;const{newParts:p,newMeta:v,changed:x}=mx(u.content,t.delta,f,h);if(!x)return e;const g={...u,content:p},y=kc(a,l,g),b={...d,[i]:v};return{...e,messages:y,messagesStreamMeta:b}}if(t.type==="message_end"){const i=e.assemblingId??Ni(e.messages);if(!i)return{...e,assemblingId:null};const a=e.messages,l=a.findIndex(u=>u.id===i&&u.role==="assistant");if(l>=0){const u=a[l];if(!((n=u.content)==null?void 0:n.some(f=>{var h;return(f==null?void 0:f.type)==="text"&&((h=f.text)==null?void 0:h.trim())}))){console.debug("[MessageReducer] pruning assistant message with no visible text",{id:u.id,contentTypes:(r=u.content)==null?void 0:r.map(h=>h==null?void 0:h.type),contentPreview:(o=u.content)==null?void 0:o.map(h=>(h==null?void 0:h.type)==="text"?String(h.text).slice(0,100):h==null?void 0:h.type)});const f=[...a.slice(0,l),...a.slice(l+1)];return{...e,assemblingId:null,messages:f}}}return e}if(t.type==="tool_start"){const i=t.id??t.call_id,a=t.name??t.tool??"tool";if(!i)return e;const l=`tool-${i}`,u={type:"tool_call",id:i,name:a,args:t.args};if(e.messages.find(h=>h.id===l))return{...e,toolIndex:{...e.toolIndex,[i]:l}};const f={id:l,role:"tool",name:a,createdAt:new Date().toISOString(),content:[u]};return{...e,messages:[...e.messages,f],toolIndex:{...e.toolIndex,[i]:l}}}if(t.type==="tool_end"){const i=t.id??t.call_id;if(!i)return e;const a=e.toolIndex[i]??`tool-${i}`,l={type:"tool_end",toolCallId:i,output:t.output,error:t.error},u=e.messages.find(h=>h.id===a),d={id:a,role:"tool",name:t.name??((s=e.messages.find(h=>h.id===a))==null?void 0:s.name),content:[l],createdAt:new Date().toISOString()},f=u?Ic(e.messages,a,[l]):[...e.messages,d];return{...e,messages:f,toolIndex:{...e.toolIndex,[i]:a}}}if(t.type==="checkpoint"){const i=t.checkpointNs??e.lastCheckpointNs??null,a=gx(e.messages,t.checkpointId,i);return{...e,lastCheckpointId:t.checkpointId,lastCheckpointNs:i,messages:a}}if(t.type==="branch"){const i=t.checkpointId??e.lastCheckpointId,a=t.checkpointNs??e.lastCheckpointNs;return{...e,lastBranch:t,lastCheckpointId:i??null,lastCheckpointNs:a??null}}if(t.type==="error"){const i={id:`err-${Date.now()}`,role:"system",content:[{type:"text",text:`Error: ${t.message}`}],createdAt:new Date().toISOString()};return{...e,messages:[...e.messages,i]}}if(t.type==="interrupt"){const i=e.assemblingId??Ni(e.messages),a={type:"interrupt",value:t.value,id:t.id};if(i)return{...e,assemblingId:null,messages:Ic(e.messages,i,[a]),pendingInterrupt:{id:t.id,value:t.value}};const l=`interrupt-${t.id}`;if(e.messages.findIndex(f=>f.id===l)!==-1)return{...e,assemblingId:null,messages:Ec(e.messages,l,f=>({...f,content:Nc(f.content??[],[a])})),pendingInterrupt:{id:t.id,value:t.value}};const d={id:l,role:"system",createdAt:new Date().toISOString(),content:[a]};return{...e,messages:[...e.messages,d],pendingInterrupt:{id:t.id,value:t.value}}}return e}function Ii(e){return e.filter(t=>{if(t.role!=="assistant")return!0;const n=(t.content||[]).some(o=>{var s;return o&&o.type==="text"&&((s=o.text)==null?void 0:s.trim())}),r=(t.content||[]).some(o=>o&&o.type==="image_url");return!!(n||r)})}function kc(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Ni(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function Ec(e,t,n){const r=e.findIndex(i=>i.id===t);if(r===-1)return e;const o=e[r],s=n(o);return s===o?e:[...e.slice(0,r),s,...e.slice(r+1)]}function Ic(e,t,n){return Ec(e,t,r=>({...r,content:Nc(r.content,n)}))}function Nc(e,t){const n=e.slice();for(const r of t)if(r.type==="text"){const o=n[n.length-1],s=r.text??"";if(!s)continue;if((o==null?void 0:o.type)==="text"){let i=function(p){return p.replace(/\s+/g," ").trim()};const a=o,l=a.text??"";if(console.debug("[MessageReducer] mergeParts",{incomingLength:s.length,previousLength:l.length,incomingSnippet:s.slice(0,100),previousSnippet:l.slice(-100)}),!l){a.text=s;continue}const u=i(s),d=i(l);if(u.startsWith(d)||s.startsWith(l)){console.debug("[MessageReducer] incoming startsWith previous (norm/raw) - replacing",{incomingLength:s.length,previousLength:l.length}),a.text=s;continue}if(u.includes(d)){console.debug("[MessageReducer] incoming includes previous (normalized) - replacing",{incomingLength:s.length,previousLength:l.length}),a.text=s;continue}if(d.includes(u)&&u.length<=3){console.debug("[MessageReducer] previous includes incoming (normalized) - skipping trivial incoming",{incomingLength:s.length,previousLength:l.length});continue}const h=jc(l,s);h?(console.debug("[MessageReducer] suffix computed",{suffixLength:h.length}),a.text=l+h):(console.debug("[MessageReducer] no overlap detected - appending incoming",{incomingLength:s.length}),a.text=l+s)}else n.push({type:"text",text:s})}else n.push(r);return n}function Ac(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function mx(e,t,n,r){const o={...n};if(r!==null&&typeof r=="number"){if(typeof o.lastSeq=="number"&&r<=o.lastSeq)return{newParts:e,newMeta:o,changed:!1};o.lastSeq=r}const s=t.filter(f=>f.type==="text").map(f=>f.text??"").join(""),i=t.filter(f=>f.type!=="text"),a=o.lastText??Ac(e);let l="",u=e.slice();if(s){const f=jc(a,s);if(f===""?l="":f===s?l=s:l=f,l){const h=u[u.length-1];if((h==null?void 0:h.type)==="text"){const p=h.text??"",v={...h,text:p+l};u=[...u.slice(0,u.length-1),v]}else u=[...u,{type:"text",text:l}];o.lastText=a+l}else o.lastText=a}i.length&&(u=[...u,...i]);const d=!!(l||i.length);return{newParts:u,newMeta:o,changed:d}}function _c(e){return e.replace(/\s+/g," ").trim()}function jc(e,t){if(!t)return"";if(!e)return t;if(e===t)return"";const n=Math.min(e.length,t.length);for(let i=n;i>0;i--)if(e.slice(-i)===t.slice(0,i))return t.slice(i);const r=_c(e),o=_c(t);if(r===o)return"";const s=Math.min(r.length,o.length);for(let i=s;i>0;i--)if(r.slice(-i)===o.slice(0,i))return t;return t}function gx(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 kc(e,r,s)}return e}function xx(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function Rc(e={}){const t=w.useMemo(()=>_n(e.baseUrl),[e.baseUrl]),n=e.streamPath??"/runs/stream",[r,o]=w.useState(e.token??null),s=w.useRef(e.headers??{}),i=e.credentials??"include",[a,l]=w.useState(!1),[u,d]=w.useState(null),[f,h]=w.useState(""),[p,v]=w.useState(null),[x,g]=w.useState(0),[y,b]=w.useState(!1),S=w.useRef(null),I=w.useRef(!0),C=w.useRef(0),T=w.useCallback(P=>{o(P)},[]),E=w.useCallback(()=>{var P;(P=S.current)==null||P.abort(),S.current=null,l(!1),b(!1),C.current=0,g(0)},[]),A=w.useCallback(()=>{h(""),v(null),d(null)},[]),j=w.useCallback((P,D,L)=>{S.current&&(S.current.abort(),S.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&h("");const V=new AbortController;return S.current=V,(async()=>{var X,K,q,z,$,pe,F,te;const M=fe=>{var ge;try{const be=JSON.parse(JSON.stringify(fe));return(ge=be==null?void 0:be.payload)!=null&&ge.files_info&&Array.isArray(be.payload.files_info)&&(be.payload.files_info=be.payload.files_info.map(Te=>({...Te,data:Te!=null&&Te.data?`<base64 ${String(Te.data).length} chars>`:Te==null?void 0:Te.data}))),be}catch{return fe}};try{let fe={};try{if(r)fe={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const Le=window.__AUTH_TOKEN__,ct=((X=window.localStorage)==null?void 0:X.getItem("authToken"))||null;let rt=null;try{const wt=(K=window.localStorage)==null?void 0:K.getItem("chat-settings");wt&&(rt=((q=JSON.parse(wt))==null?void 0:q.apiKey)||null)}catch{}const vt=Le||ct||rt||null;vt&&(fe={Authorization:`Bearer ${vt}`})}}catch{}console.debug("[use-chat] POST",t+n,M(P));const ge=await fetch(t+n,{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream",...fe,...s.current},body:JSON.stringify(P),signal:V.signal,credentials:i});if(!ge.ok||!ge.body){const Pe=await ge.text().catch(()=>"");throw console.debug("[use-chat] non-OK response",ge.status,Pe==null?void 0:Pe.slice(0,500)),new Error(`stream ${ge.status}${Pe?": "+Pe:""}`)}b(!0);const be=ge.body.getReader(),Te=new TextDecoder;let G="",O=[];C.current=0,g(0);let Q=0,ne=null;const de=()=>{if(O.length){const Pe=O.join("");O=[],I.current&&h(Le=>Le+Pe)}ne=null},ae=()=>{typeof window<"u"&&ne==null&&(ne=requestAnimationFrame(de))};let Ue=Date.now();const Ze=setInterval(()=>{var Pe;if(Date.now()-Ue>6e4){const Le="Stream idle timeout";d(Le),V.abort(),(Pe=L==null?void 0:L.onError)==null||Pe.call(L,Le)}},5e3),me=1024*1024;try{const Pe=ge.headers.get("X-Thread-Id")||ge.headers.get("x-thread-id"),Le=ge.headers.get("X-Thread-Created")||ge.headers.get("x-thread-created"),ct=Pe??null,rt=String(Le??"").toLowerCase()==="true";for((z=L==null?void 0:L.onOpen)==null||z.call(L,{threadId:ct,created:rt});;){const{value:vt,done:wt}=await be.read();if(wt)break;G+=Te.decode(vt,{stream:!0}),G.length>me&&(G="",console.warn("Stream buffer reset: exceeded 1MB"));let B;for(;(B=G.indexOf(`
|
|
36
36
|
|
|
37
|
-
`))>=0;){const se=G.slice(0,B);G=G.slice(B+2);const we=vx(se);if(!we)continue;let Ie;try{Ie=JSON.parse(we)}catch{console.debug("[use-chat] malformed SSE:",we.slice(0,200));continue}const
|
|
38
|
-
`)}function bx({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o}){const s=w.useRef(null),i=w.useCallback(p=>{const v=p.seq??null;if(v!==null){const x=s.current;if(x!==null){if(v<=x)return;v>x+1&&(o==null||o({from:x,to:v}))}s.current=v}if(p.type==="thread_info"){console.log("[useChatStreamingService] 🎯 Received thread_info event:",p),t(p);return}if(fx(p)){n(p);return}r==null||r(p)},[n,o,t,r]),{stream:a,stop:l,isStreaming:u,error:d,setToken:f}=Rc({baseUrl:e,token:null}),h=w.useCallback((p,v)=>{s.current=null,a(p,i,{onOpen:v==null?void 0:v.onOpen,onError:x=>{var g;(g=v==null?void 0:v.onError)==null||g.call(v,x)},onGap:(v==null?void 0:v.onGap)??o})},[i,o,a]);return w.useMemo(()=>({startStream:h,stop:l,isStreaming:u,error:d,setAuthToken:f}),[h,l,u,d,f])}const Pc=w.createContext(null),Oc=w.createContext(null),Mc=w.createContext(null),wx=w.createContext(!1),Sx="cachedThreads",Cx="v1",Vo=300,ji=200,Dc=50;function Tx(e,t,n){return`${e}__${t??""}__${n??""}`}function Lc(e,t){if(!e&&!t)return!0;if(!e||!t||e.id!==t.id)return!1;try{return JSON.stringify(e.value)===JSON.stringify(t.value)}catch{return e.value===t.value}}function Wt(e,t={}){const n=t.cloneMessages??!1,r=Array.isArray(e==null?void 0:e.messages)?e.messages:[];return{checkpointId:(e==null?void 0:e.checkpointId)??null,checkpointNs:(e==null?void 0:e.checkpointNs)??null,createdAt:(e==null?void 0:e.createdAt)??null,preview:(e==null?void 0:e.preview)??null,role:(e==null?void 0:e.role)??null,parentId:(e==null?void 0:e.parentId)??null,branchLabel:(e==null?void 0:e.branchLabel)??null,lastMessageId:(e==null?void 0:e.lastMessageId)??null,messagesLen:typeof(e==null?void 0:e.messagesLen)=="number"?e.messagesLen:r.length,hasMessages:typeof(e==null?void 0:e.hasMessages)=="boolean"?e.hasMessages:r.length>0,messages:n?r.slice():r,nextCursor:(e==null?void 0:e.nextCursor)??null,nextCursorNs:(e==null?void 0:e.nextCursorNs)??null,interrupt:(e==null?void 0:e.interrupt)??null}}function kx(e){var t;for(let n=e.length-1;n>=0;n--){const r=((t=e[n])==null?void 0:t.content)??[];for(let o=r.length-1;o>=0;o--){const s=r[o];if((s==null?void 0:s.type)==="interrupt"){const i=s.id;return{id:(typeof i=="string"?i:null)??`interrupt-${e[n].id??o}`,value:s.value}}}}return null}function $c(e){if(typeof window<"u"&&"requestIdleCallback"in window)try{window.requestIdleCallback(e,{timeout:1e3});return}catch{}window.setTimeout(e,Vo)}function Ir(){return typeof window<"u"&&typeof window.localStorage<"u"}function Ri(e){if(!Ir())return null;try{return window.localStorage.getItem(e)}catch{return null}}function Fc(e,t){if(Ir())try{window.localStorage.setItem(e,t)}catch{}}function Pi(e){if(Ir())try{window.localStorage.removeItem(e)}catch{}}function Ex(){const e=Ri(Sx);if(!e)return[];try{const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>{if(!n||typeof n!="object")return!1;const r=n;return typeof r.threadId=="string"&&typeof r.title=="string"}):[]}catch{return[]}}function Ix(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t^e.charCodeAt(n);return(t>>>0).toString(36)}function Oi(e,t){return`cachedThreads:v1:${e}:${Ix(t||"anon")}`}function Nx(e){const t=Ri(e);if(!t)return[];try{const n=JSON.parse(t);return Array.isArray(n)?n.filter(r=>{if(!r||typeof r!="object")return!1;const o=r;return typeof o.threadId=="string"&&typeof o.title=="string"}):[]}catch{return[]}}function Mi(e,t){try{Fc(e,JSON.stringify(t))}catch{}}function Di(e){const t=Nx(e);if(t.length>0)return t;const n=Ex();if(n.length>0)try{Mi(e,n.slice(0,ji))}catch{}return n}function Ko(e){const t={},n=[];for(const r of e)!r||typeof r.threadId!="string"||t[r.threadId]||(t[r.threadId]=r,n.push(r.threadId));return{byId:t,order:n}}function Li(e){return e.order.map(t=>e.byId[t]).filter(Boolean)}function Ax({children:e,initialThreadId:t=null,autoLoadInitial:n=!0,disableAutoRestore:r=!1,enableFileAgentRouting:o=!1,fileAgentId:s="invoice_reader",onError:i,onThreadChange:a}){const{api:l,baseUrl:u}=Ii(),d=w.useMemo(()=>jn(u),[u]),f=w.useMemo(()=>{try{return new URL(u).host}catch{return"unknown"}},[u]),h=w.useMemo(()=>`threadPayload:${Cx}:${f}:`,[f]),p=w.useCallback(N=>`${h}${N}`,[h]),v=w.useCallback(N=>{if(!N||typeof N!="object")return null;const _=N;return typeof _.threadId!="string"?null:{threadId:_.threadId,snapshot:Wt(_.snapshot,{cloneMessages:!0})}},[]),x=w.useCallback(N=>{const _=Ri(p(N));if(!_)return null;try{const H=JSON.parse(_);return v(H)}catch{return null}},[p,v]),g=w.useCallback((N,_=100)=>{const H=Wt(N.snapshot,{cloneMessages:!0}),Q={threadId:N.threadId,snapshot:{...H,messages:H.messages.slice(-_)}};try{Fc(p(N.threadId),JSON.stringify(Q))}catch{}},[p]),y=w.useCallback(N=>{Pi(p(N))},[p]),b=w.useCallback(()=>{if(Ir())try{const N=h;for(let _=0;_<window.localStorage.length;_++){const H=window.localStorage.key(_);H&&H.startsWith(N)&&window.localStorage.removeItem(H)}}catch{}},[h]),[S,I]=w.useState(()=>{var N;return Oi(f,(N=l.getAuthToken)==null?void 0:N.call(l))}),[C,T]=w.useState(()=>{var _;const N=Di(Oi(f,(_=l.getAuthToken)==null?void 0:_.call(l)));return Ko(N)}),E=w.useMemo(()=>Li(C),[C]),[A,j]=w.useState(t),[P,D]=w.useState(!1),[L,V]=w.useState(!1),[M,Y]=w.useState(null),[K,q]=w.useState(null),[z,$]=w.useState(null),[pe,F]=w.useState([]),te=w.useCallback(()=>{const N=Di(S);w.startTransition(()=>{T(Ko(N))})},[S]),[fe,me]=w.useState(!1),[be,Te]=w.useState(!1),[G,O]=w.useState(null),[Z,ne]=w.useState(void 0),[de,ae]=w.useState(void 0),[We,Ze]=w.useState(void 0),{state:ve,dispatch:Oe,seed:Le,prepend:ct,pushUser:rt,onEvent:vt,reset:St}=Cc(),B=w.useRef(A);w.useEffect(()=>{B.current=A},[A]);const se=w.useRef(!1),we=w.useRef([]),Ie=w.useRef(null),xe=w.useRef(null),Re=w.useRef(new Map),Qe=w.useRef(A),Fe=w.useRef(!1),pt=w.useRef(null),Ct=w.useRef(new Map),nn=w.useRef(new Map),zt=w.useRef(new Map),hn=w.useRef(new Map),An=w.useCallback(N=>{if(!N){F([]);return}const _=Ct.current.get(N);if(!_||!_.length){F([]);return}F(_.map(H=>Wt(H,{cloneMessages:!0})))},[]);w.useEffect(()=>{An(A)},[A,An]);const Hr=w.useCallback(()=>{var Q;const N=hn.current;if(N.size<=Dc)return;const _=Array.from(N.entries()).sort((re,X)=>re[1].timestamp-X[1].timestamp),H=N.size-Dc;for(let re=0;re<H;re++){const X=(Q=_[re])==null?void 0:Q[0];X&&N.delete(X)}},[]),Zn=w.useCallback((N,_,H)=>{if(!N)return;const Q=H==="replace"?[]:Ct.current.get(N)??[],re=H==="replace"?_:[..._,...Q];if(!re.length){H==="replace"&&Ct.current.set(N,[]);return}const X=new Map;for(const qe of re){if(!(qe!=null&&qe.checkpointId))continue;const _e=`${qe.checkpointId}::${qe.checkpointNs??""}`;X.has(_e)||X.set(_e,Wt(qe,{cloneMessages:!0}))}const Be=Array.from(X.values()).sort((qe,_e)=>{const Ve=Number.isFinite(Date.parse(qe.createdAt??""))?Date.parse(qe.createdAt??""):0;return(Number.isFinite(Date.parse(_e.createdAt??""))?Date.parse(_e.createdAt??""):0)-Ve});Ct.current.set(N,Be),N===B.current&&An(N)},[An]),rn=w.useCallback((N,_,H)=>{if(!N)return;const Q=nn.current.get(N),re=H==="replace"||!Q?new Map:new Map(Q);if(_&&typeof _=="object")for(const[X,Be]of Object.entries(_)){if(!(Be!=null&&Be.checkpointId))continue;const qe=X||Wo(Be.checkpointId,Be.checkpointNs??null);re.set(qe,Wt(Be,{cloneMessages:!0}))}nn.current.set(N,re)},[]),Mn=w.useCallback((N,_)=>{const{threadId:H,checkpointId:Q=null,checkpointNs:re=null}=N,X=Tx(H,Q,re);if(_!=null&&_.force)zt.current.delete(X),hn.current.delete(X);else{if(_!=null&&_.preferCache){const Ve=hn.current.get(X);if(Ve)return Promise.resolve(Ve.payload)}const _e=zt.current.get(X);if(_e)return _e}const qe=l.getStateHistory({threadId:H,checkpointId:Q??void 0,checkpointNs:re??void 0}).then(_e=>(hn.current.set(X,{payload:_e,timestamp:Date.now()}),Hr(),_e)).finally(()=>{zt.current.get(X)===qe&&zt.current.delete(X)});return zt.current.set(X,qe),qe},[l,Hr]),Mt=w.useCallback((N,_)=>new Promise((H,Q)=>{const re=async()=>{se.current=!0;try{await N(),H()}catch(X){Q(X)}finally{se.current=!1;const X=we.current.shift();X&&X().catch(()=>{})}};se.current?we.current.push(re):re().catch(X=>{Q(X)})}),[]),Qn=w.useRef(E.length),[Ur,Wr]=w.useState(!1),he=w.useRef(!1);w.useEffect(()=>{Qn.current=E.length},[E.length]),w.useEffect(()=>{const N=ve.pendingInterrupt??kx(ve.messages);Lc(z,N)||$(N??null)},[z,ve.messages,ve.pendingInterrupt]);const ye=w.useCallback(async()=>{const N=Qn.current>0;N||D(!0);try{const _=await l.listThreads();w.startTransition(()=>{T(H=>{const Q=Be=>Be.map(qe=>`${qe.threadId}:${qe.updatedAt??""}:${qe.messageCount??""}`).join("|"),re=Li(H);return Q(re)===Q(_)||_.length===0&&re.length>0&&!he.current?H:Ko(_)})}),Y(null),he.current||(he.current=!0,Wr(!0))}catch(_){i==null||i(String(_)),console.error("[ChatSessionProvider] Failed to refresh threads:",_),Y(String(_))}finally{N||D(!1)}},[l,i]),et=w.useRef(!1),dt=w.useRef(null),ft=w.useRef(null),on=w.useRef(""),wr=w.useCallback((N,_)=>{if(!Ir())return;ft.current!==null&&(window.clearTimeout(ft.current),ft.current=null);const H=N.map(re=>`${re.threadId}:${re.updatedAt??""}:${re.messageCount??""}`).join("|");if(N.length===0){try{Pi(S)}catch{}on.current="";return}if(H===on.current)return;const Q=()=>{try{const re=N.slice(0,ji);Mi(S,re),on.current=H}catch{}finally{ft.current=null}};if(_!=null&&_.immediate){Q();return}ft.current=window.setTimeout(()=>{$c(Q)},Vo)},[S]),No=w.useCallback(()=>{wr(E,{immediate:!0})},[wr,E]),pn=w.useCallback((N,_,H,Q)=>{var bm;const re=H??B.current;if(!re)return;const X=Wt(N),Be=re===B.current,qe=(Q==null?void 0:Q.persist)!==!1;if(_==="replace"){if(qe){const kt={threadId:re,snapshot:Wt(N,{cloneMessages:!0})};Re.current.set(re,kt),Qe.current=re}if(!Be)return;Le(X.messages,{checkpointId:X.checkpointId??null,checkpointNs:X.checkpointNs??null,pendingInterrupt:X.interrupt??null}),$(X.interrupt??null),O(X.nextCursor??null),me(!!X.nextCursor),ne(X.checkpointId??void 0),ae(X.checkpointNs??void 0),Ze(X.nextCursorNs??void 0);return}const _e=Re.current.get(re),Ve=(_e==null?void 0:_e.snapshot)??null,Rt=Array.isArray(Ve==null?void 0:Ve.messages)?Ve.messages:[],bt=Wt(Ve),Bt=Array.isArray(N==null?void 0:N.messages)?N.messages:[],Ln=new Set,$n=[...Bt,...Rt].filter(kt=>{const bl=kt==null?void 0:kt.id;return bl?Ln.has(bl)?!1:(Ln.add(bl),!0):!0}),qr={checkpointId:bt.checkpointId??X.checkpointId??null,checkpointNs:bt.checkpointNs??X.checkpointNs??null,createdAt:X.createdAt??bt.createdAt??null,preview:X.preview??bt.preview??null,role:X.role??bt.role??null,parentId:X.parentId??bt.parentId??null,branchLabel:X.branchLabel??bt.branchLabel??null,lastMessageId:((bm=$n[$n.length-1])==null?void 0:bm.id)??null,messagesLen:$n.length,hasMessages:$n.length>0,messages:$n,nextCursor:X.nextCursor??bt.nextCursor??null,nextCursorNs:X.nextCursorNs??bt.nextCursorNs??null,interrupt:bt.interrupt??X.interrupt??null};if(Re.current.set(re,{threadId:re,snapshot:Wt(qr,{cloneMessages:!0})}),!Be)return;Bt.length&&ct(Bt);const Sr=N&&Object.prototype.hasOwnProperty.call(N,"checkpointId")?N.checkpointId:void 0,Cr=N&&Object.prototype.hasOwnProperty.call(N,"checkpointNs")?N.checkpointNs:void 0,Ht=N&&Object.prototype.hasOwnProperty.call(N,"nextCursor")?N.nextCursor:void 0,vl=N&&Object.prototype.hasOwnProperty.call(N,"nextCursorNs")?N.nextCursorNs:void 0;O(kt=>Ht!==void 0?Ht??kt??null:kt??null),me(kt=>Ht!==void 0?!!Ht:kt),ne(kt=>Sr!==void 0?Sr??kt??void 0:kt??void 0),ae(kt=>Cr!==void 0?Cr??kt??void 0:kt??void 0),Ze(kt=>vl!==void 0?vl??void 0:kt)},[ct,Le,$]),Ao=w.useCallback(N=>{if(N.threadId!=null&&N.threadId!==B.current)return;const _=Wt(N.snapshot,{cloneMessages:!0});Le(_.messages,{checkpointId:_.checkpointId??null,checkpointNs:_.checkpointNs??null,pendingInterrupt:_.interrupt??null}),$(_.interrupt??null),O(_.nextCursor??null),me(!!_.nextCursor),ne(_.checkpointId??void 0),ae(_.checkpointNs??void 0),Ze(_.nextCursorNs??void 0),Qe.current=N.threadId,An(N.threadId??B.current??null)},[Le,$,An]),er=w.useCallback(N=>{if(!N)return;Re.current.delete(N),y(N),Ct.current.delete(N),nn.current.delete(N),N===B.current&&F([]);const _=`${N}__`;for(const H of zt.current.keys())H.startsWith(_)&&zt.current.delete(H);for(const H of hn.current.keys())H.startsWith(_)&&hn.current.delete(H);Qe.current===N&&(Qe.current=null)},[y]),tr=w.useCallback(()=>{const N=B.current;N&&er(N),St([]),me(!1),Te(!1),O(null),ne(void 0),ae(void 0),Ze(void 0)},[er,St]),_o=w.useCallback(({from:N,to:_})=>{const H=B.current;H&&console.warn(`[ChatSessionProvider] Stream sequence gap detected (${N} -> ${_}) for thread ${H}`)},[]),k=w.useCallback(N=>{const _=N.threadId;console.log("[ChatSessionProvider] 📥 Handling thread_info event:",{threadId:_,title:N.title,created:N.created,currentThreads:E.length});const H={threadId:_,title:N.title||`Thread ${_.slice(0,8)}`,createdAt:N.createdAt||new Date().toISOString(),updatedAt:N.updatedAt||new Date().toISOString(),messageCount:N.messageCount||0};B.current!==_&&(!B.current&&ve.messages.length<=1&&(xe.current=_),j(_)),w.startTransition(()=>{T(Q=>{const re=Q.byId[_];return re?re.title===H.title&&re.updatedAt===H.updatedAt&&re.messageCount===H.messageCount?Q:{byId:{...Q.byId,[_]:H},order:Q.order}:{byId:{...Q.byId,[_]:H},order:[_,...Q.order]}})})},[ve.messages.length]),{startStream:W,stop:oe,isStreaming:ke,error:Ye,setAuthToken:Xe}=bx({baseUrl:d,onThreadInfo:k,onMessageEvent:vt,onUnhandledEvent:N=>{console.warn(`[ChatSessionProvider] Unhandled stream event: ${N.type}`,N)},onSequenceGap:_o});w.useEffect(()=>{et.current=ke},[ke]),w.useEffect(()=>{if(!Ir())return;ft.current!==null&&(window.clearTimeout(ft.current),ft.current=null);const N=E.map(H=>`${H.threadId}:${H.updatedAt??""}:${H.messageCount??""}`).join("|");if(E.length===0){try{Pi(S)}catch{}on.current="";return}if(N===on.current)return;const _=()=>{try{const H=E.slice(0,ji);Mi(S,H),on.current=N}catch{}finally{ft.current=null}};return ft.current=window.setTimeout(()=>{$c(_),ft.current=null},Vo),()=>{ft.current!==null&&(window.clearTimeout(ft.current),ft.current=null)}},[E,wr]),w.useEffect(()=>{var Q;const N=l.getAuthToken();Xe(N);const _=re=>{const X=Oi(f,re);pt.current!==X&&(pt.current=X,Fe.current=!1),I(X);const Be=Di(X);w.startTransition(()=>{T(Ko(Be))}),Fe.current||(Fe.current=!0,ye().catch(()=>{}))};_(N);const H=(Q=l.onTokenChange)==null?void 0:Q.call(l,re=>{Xe(re),b(),zt.current.clear(),hn.current.clear(),_(re)});return()=>{H==null||H()}},[l,f,Xe,b,ye]);const He=w.useCallback(async N=>{var Q;const _=`Thread ${(Q=crypto.randomUUID)==null?void 0:Q.call(crypto)}`,H={threadId:_,title:N||"New Chat",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),messageCount:0};T(re=>({byId:{...re.byId,[_]:H},order:[_,...re.order]})),j(_);try{const re=await l.createThread(N),X=typeof re=="string"?re:re.threadId;return T(Be=>{const qe=Be.byId[_];if(!qe)return Be;const _e={...Be.byId};delete _e[_],_e[X]={...qe,threadId:X};const Ve=Be.order.map(Rt=>Rt===_?X:Rt);return{byId:_e,order:Ve}}),j(X),setTimeout(()=>ye(),10),Y(null),X}catch(re){throw T(X=>{if(!X.byId[_])return X;const Be={...X.byId};delete Be[_];const qe=X.order.filter(_e=>_e!==_);return{byId:Be,order:qe}}),j(null),Y(String(re)),re}},[l,ye]),ze=w.useCallback(async N=>{try{await l.deleteThread(N);let _=null;T(H=>{if(!H.byId[N])return H;const Q={...H.byId};delete Q[N];const re=H.order.filter(Be=>Be!==N),X={byId:Q,order:re};return _=Li(X),X}),_&&wr(_,{immediate:!0}),er(N),B.current===N&&(xe.current=N,j(null),B.current=null,Qe.current=null,tr()),await ye(),Y(null)}catch(_){throw Y(String(_)),_}},[l,tr,er,ye,wr]),Tt=w.useCallback(async(N,_)=>{try{await l.updateThread(N,_),T(H=>{const Q=H.byId[N];return Q?{byId:{...H.byId,[N]:{...Q,title:_}},order:H.order}:H}),Y(null)}catch(H){throw await ye(),Y(String(H)),H}},[l,ye]),nt=w.useCallback(async(N,_,H,Q=!1)=>{await Mt(async()=>{if(xe.current===N&&!Q){xe.current=null;return}if(Ie.current===N&&!Q)return;j(_e=>_e===N?_e:N),B.current=N;const re=!Q&&!_&&!H;let X=!1;if(re){const _e=Re.current.get(N);if(_e)Ao(_e),X=!0;else{const Ve=x(N);Ve&&(Re.current.set(N,Ve),Ao(Ve),X=!0)}}const Be=Q||!X||!!_||!!H,qe=async _e=>{_e&&V(!0),Ie.current=N;try{const Ve=await Mn({threadId:N,checkpointId:_,checkpointNs:H},{force:Q}),{latest:Rt,checkpoints:bt,snapshots:Bt}=xc(Ve);pn(Rt,"replace",N),Zn(N,bt,"replace"),rn(N,Bt,"replace"),q(null)}catch(Ve){throw(!X||Q||_e)&&(i==null||i(String(Ve))),q(String(Ve)),Ve}finally{Ie.current=null,_e&&V(!1)}};Be?await qe(!0):re&&X&&qe(!1).catch(_e=>{console.warn("[ChatSessionProvider] Background refresh failed:",_e)})},`loadThread-${N}`)},[Ao,pn,Mt,Mn,i,Zn,rn]),ht=w.useCallback(async()=>{await Mt(async()=>{const N=B.current;N&&er(N),xe.current=null,j(null),B.current=null,Qe.current=null,tr(),ne(void 0),ae(void 0),Ze(void 0),F([]);try{localStorage.removeItem("lastThreadId")}catch(_){console.warn("[ChatSessionProvider] Failed to clear lastThreadId:",_)}},"clearCurrentThread")},[tr,er,Mt]),Dt=w.useCallback(async(N,_)=>{var X;const H=B.current;if(!H)throw new Error("No active thread");const Q=Wo(N,_??null),re=(X=nn.current.get(H))==null?void 0:X.get(Q);if(re){await Mt(async()=>{pn(re,"replace",H,{persist:!1})},`navigateToCheckpoint-${H}-${Q}`);return}await nt(H,N,_??void 0,!0)},[pn,Mt,nt]),Dn=w.useCallback(async()=>{if(!B.current)throw new Error("No active thread");await nt(B.current,void 0,void 0,!0)},[nt]),_n=w.useCallback(async()=>{if(!B.current)throw new Error("No active thread");if(be||!fe)return;const N=G;if(N){Te(!0);try{const _=B.current,H=await Mn({threadId:_,checkpointId:N??Z??null,checkpointNs:We??de??null}),{latest:Q,checkpoints:re,snapshots:X}=xc(H);pn(Q,"prepend",_??void 0),_&&(Zn(_,re,"prepend"),rn(_,X,"prepend")),q(null)}catch(_){throw q(String(_)),_}finally{Te(!1)}}},[pn,Mn,fe,Z,de,We,G,be,Zn,rn]),It=w.useCallback(N=>{if(N!=null&&N.threadId){if(N.checkpointId){const _=Wo(N.checkpointId,N.checkpointNs??null),H=Wt({...N,interrupt:N.interrupt??null},{cloneMessages:!0});rn(N.threadId,{[_]:H},"prepend")}pn(N,"replace",N.threadId)}},[pn,rn]),Vr=w.useCallback(async(N,_)=>{var Cr;const H=B.current,Q=(N==null?void 0:N.text)??"",re=(N==null?void 0:N.attachments)??[],X=re.length?re:(_==null?void 0:_.attachments)??[],Be={...(_==null?void 0:_.payloadExtras)??{},...(N==null?void 0:N.payload)??{}};if(!H&&!Object.keys(Be).length&&X.length===0&&!Q.trim()){console.warn("[ChatSessionProvider] Nothing to submit - skipping");return}!H&&!Be.messages&&console.warn("[ChatSessionProvider] No thread ID - message will create new thread");const{contentParts:qe,filesInfo:_e}=await Jg(l,X),Ve=[...qe];Q&&Q.trim()&&Ve.push({type:"text",text:Q.trim()});const Rt=!!H,bt=Rt?(_==null?void 0:_.checkpointId)??ve.lastCheckpointId??void 0:void 0,Bt=Rt?(_==null?void 0:_.checkpointNs)??ve.lastCheckpointNs??void 0:void 0,Ln={id:((Cr=crypto.randomUUID)==null?void 0:Cr.call(crypto))||`user-${Date.now()}`,role:"user",content:Ve,createdAt:new Date().toISOString(),...bt!=null?{checkpointId:bt}:{},...Bt!=null?{checkpointNs:Bt}:{}};Ve.length>0&&rt(Ln);const $n={...Ln,content:Ve},qr=X.length>0,Sr={...H?{threadId:H}:{},payload:{messages:Ve.length>0?[$n]:[],files_info:_e,...o&&qr&&s?{active_agent:s}:{},...Be},...bt!=null?{checkpointId:bt}:{},...Bt!=null?{checkpointNs:Bt}:{},nodeFilter:_==null?void 0:_.nodeFilter,config:_==null?void 0:_.config};W(Sr,{onError:Ht=>{console.warn("[ChatSessionProvider] Stream error:",Ht)},onOpen:({threadId:Ht})=>{!B.current&&Ht&&(ve.messages.length<=1&&(xe.current=Ht),j(Ht))},onGap:_o})},[l,o,s,_o,ve.lastCheckpointId,ve.lastCheckpointNs,ve.messages.length,rt,W]),Kr=w.useCallback(async(N,_,H)=>{var re,X;const Q=B.current;if(!Q)throw new Error("No active thread to handle interrupt");try{const Be=_?H??!0:!1;try{Oe({type:"interrupt_response",payload:{interruptId:N}})}catch(Ln){console.warn("[ChatSessionProvider] optimistic interrupt_response dispatch failed:",Ln)}const qe=`${d}/runs/resume`,_e=(re=l.getAuthToken)==null?void 0:re.call(l),Ve=await fetch(qe,{method:"POST",headers:{"Content-Type":"application/json",..._e?{Authorization:`Bearer ${_e}`}:{}},body:JSON.stringify({thread_id:Q,value:Be})});if(!Ve.ok)throw new Error(`Resume failed with status ${Ve.status}`);const Rt=(X=Ve.body)==null?void 0:X.getReader();if(!Rt)throw new Error("No response body for resume stream");const bt=new TextDecoder;let Bt="";for(;;){const{done:Ln,value:$n}=await Rt.read();if(Ln)break;Bt+=bt.decode($n,{stream:!0});const qr=Bt.split(`
|
|
39
|
-
`);Bt=qr.pop()||"";for(const Sr of qr)if(Sr.startsWith("data: ")){const Cr=Sr.slice(6);try{const Ht=JSON.parse(Cr);Oe({type:"event",payload:{ev:Ht}})}catch(Ht){console.warn("[ChatSessionProvider] Failed to parse resume SSE event:",Ht)}}}$(null)}catch(Be){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${N}:`,Be),Be}},[l,Oe,d]),ui=w.useCallback(N=>Kr(N.interruptId,N.approved,N.value),[Kr]);w.useEffect(()=>{if(a==null||a(A),A)try{localStorage.setItem("lastThreadId",A)}catch(N){console.warn("[ChatSessionProvider] Failed to persist lastThreadId:",N)}},[A,a]),w.useEffect(()=>((async()=>{try{if(ye().catch(_=>{console.error("[ChatSessionProvider] Failed to refresh threads (background):",_),i==null||i(String(_))}),!r&&!t)try{const _=localStorage.getItem("lastThreadId");_&&(j(_),n&&await nt(_))}catch(_){console.warn("[ChatSessionProvider] Failed to restore last thread:",_)}else t&&n&&await nt(t)}catch(_){console.error("[ChatSessionProvider] Initialization failed:",_),i==null||i(String(_))}})(),()=>{}),[]),w.useEffect(()=>{const N=B.current;if(!N||Qe.current!==N)return;const _=Wt({checkpointId:ve.lastCheckpointId??null,checkpointNs:ve.lastCheckpointNs??null,messages:ve.messages.slice(),nextCursor:G??null,nextCursorNs:We??null,interrupt:ve.pendingInterrupt??z??null}),H=Re.current.get(N),Q=H==null?void 0:H.snapshot,re=!Q||Q.messages.length!==_.messages.length||Q.messages.some((_e,Ve)=>{var Rt;return(_e==null?void 0:_e.id)!==((Rt=_.messages[Ve])==null?void 0:Rt.id)}),X=((Q==null?void 0:Q.checkpointId)??null)!==_.checkpointId||((Q==null?void 0:Q.checkpointNs)??null)!==_.checkpointNs,Be=((Q==null?void 0:Q.nextCursor)??null)!==_.nextCursor||((Q==null?void 0:Q.nextCursorNs)??null)!==_.nextCursorNs,qe=!Lc((Q==null?void 0:Q.interrupt)??null,_.interrupt??null);if(re||X||Be||qe){const _e={threadId:N,snapshot:Wt(_,{cloneMessages:!0})};Re.current.set(N,_e),dt.current&&window.clearTimeout(dt.current),dt.current=window.setTimeout(()=>{try{g(_e,100)}catch(Ve){console.warn("[ChatSessionProvider] Failed to persist thread payload:",Ve)}},Vo)}},[G,We,ve.lastCheckpointId,ve.lastCheckpointNs,ve.messages,ve.pendingInterrupt,z,g]);const IT=w.useMemo(()=>({threads:E,currentThreadId:A,setCurrentThreadId:j,isLoading:P,error:M,actions:{createThread:He,deleteThread:ze,renameThread:Tt,refreshThreads:()=>ye()},persistThreadsCache:No,hydrateFromCache:te}),[E,A,P,M,He,ze,Tt,ye,No,te,j]),NT=w.useMemo(()=>{const N=ve.lastBranch??null,_=ve.assemblingId??null,H=N||_?{branchLabel:(N==null?void 0:N.branchLabel)??null,lastBranch:N,assemblingMessageId:_}:null;return{threadId:A,messages:ve.messages,interrupt:z,checkpoint:{id:ve.lastCheckpointId??null,namespace:ve.lastCheckpointNs??null},checkpoints:pe,metadata:H,isLoading:L,isHistoryLoading:be,error:K,hasMore:fe,loadOlder:_n,seedFromSnapshot:It,clearState:tr,navigateToCheckpoint:Dt,returnToLatest:Dn,loadThread:nt,clearThread:ht,respondToInterrupt:Kr}},[ht,tr,A,z,fe,be,L,_n,nt,ve.assemblingId,ve.lastBranch,ve.lastCheckpointId,ve.lastCheckpointNs,ve.messages,Dt,Kr,Dn,It,K,pe]),AT=w.useMemo(()=>({isStreaming:ke,error:Ye,submit:Vr,stop:oe,resume:ui,setAuthToken:Xe}),[ke,Ye,Vr,oe,ui,Xe]);return c.jsx(wx.Provider,{value:!0,children:c.jsx(Mc.Provider,{value:AT,children:c.jsx(Pc.Provider,{value:IT,children:c.jsx(Oc.Provider,{value:NT,children:e})})})})}function qo(){const e=w.useContext(Pc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function Go(){const e=w.useContext(Oc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function zc(){const e=w.useContext(Mc);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function Yo({children:e,apiConfig:t,initialThreadId:n=null,autoLoadInitial:r=!0,disableAutoRestore:o=!1,enableFileAgentRouting:s=!1,fileAgentId:i="invoice_reader",onError:a,onThreadChange:l}){return c.jsx(Yg,{apiConfig:t,children:c.jsx(Ax,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,enableFileAgentRouting:s,fileAgentId:i,onError:a,onThreadChange:l,children:e})})}function ee(...e){return Tm.twMerge(Cm.clsx(e))}const _x=jo.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"}}),Ge=m.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?nr.Slot:"button";return c.jsx(i,{className:ee(_x({variant:t,size:n,className:e})),ref:s,...o})});Ge.displayName="Button";const Bc=m.forwardRef(({className:e,...t},n)=>c.jsx("textarea",{className:ee("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));Bc.displayName="Textarea";function jx({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,onSend:i,onCancelEdit:a,onStop:l,className:u="",textareaClassName:d="",allowEmptySend:f=!1}){const[h,p]=w.useState(e),[v,x]=w.useTransition(),g=w.useRef(null);w.useEffect(()=>{p(e??""),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[e,t]);const y=w.useCallback(()=>{const A=g.current;A&&(A.style.height="auto",A.style.height=`${A.scrollHeight}px`)},[]);w.useEffect(()=>{y()},[y]);const b=w.useCallback(async A=>{A&&A.preventDefault();const j=(h??"").trim();!j&&!f||x(()=>{try{const P=i(j);P&&typeof P.then=="function"?P.then(()=>{p(""),g.current&&(g.current.style.height="auto")}).catch(()=>{}):(p(""),g.current&&(g.current.style.height="auto"))}catch{}})},[h,i,f]),S=w.useCallback(A=>{p(A.target.value),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[]),I=w.useCallback(A=>{A.key==="Enter"&&!A.shiftKey?(A.preventDefault(),b()):A.key==="Escape"&&t&&(A.preventDefault(),a==null||a())},[b,t,a]),E=`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))]":""} ${d}`;return c.jsx("form",{onSubmit:A=>void b(A),className:`w-full ${u}`,children:c.jsxs("div",{className:"flex items-end gap-2",children:[c.jsx("div",{className:"flex-1",children:c.jsx(Bc,{ref:g,value:h,onChange:S,onKeyDown:I,placeholder:t?"Edit your message...":n,className:E,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),c.jsx("div",{children:r?c.jsx(Ge,{type:"button",onClick:()=>{l==null||l()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!l,children:c.jsx(ie.Square,{size:16})}):c.jsx(Ge,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!h.trim()&&!f||v,children:c.jsx(ie.Send,{size:16})})})]})})}const Rx=w.memo(jx),Xo=0,zn=1,Nr=2,Hc=4;function Uc(e){return()=>e}function Px(e){e()}function Wc(e,t){return n=>e(t(n))}function Vc(e,t){return()=>e(t)}function Ox(e,t){return n=>e(t,n)}function $i(e){return e!==void 0}function Mx(...e){return()=>{e.map(Px)}}function Ar(){}function Jo(e,t){return t(e),e}function Dx(e,t){return t(e)}function it(...e){return e}function tt(e,t){return e(zn,t)}function De(e,t){e(Xo,t)}function Fi(e){e(Nr)}function gt(e){return e(Hc)}function ge(e,t){return tt(e,Ox(t,Xo))}function an(e,t){const n=e(zn,r=>{n(),t(r)});return n}function Kc(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function qc(e,t){return e===t}function at(e=qc){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function Ne(e){return t=>n=>{e(n)&&t(n)}}function le(e){return t=>Wc(t,e)}function yn(e){return t=>()=>{t(e)}}function U(e,...t){const n=Lx(...t);return(r,o)=>{switch(r){case Nr:Fi(e);return;case zn:return tt(e,n(o))}}}function vn(e,t){return n=>r=>{n(t=e(t,r))}}function ir(e){return t=>n=>{e>0?e--:t(n)}}function Rn(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function $e(...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);tt(s,l=>{const u=n;n=n|a,t[i]=l,u!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function Lx(...e){return t=>e.reduceRight(Dx,t)}function $x(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case zn:return s?n===s?void 0:(r(),n=s,t=tt(e,s),t):(r(),Ar);case Nr:r(),n=null;return}}}function J(e){let t=e;const n=Ke();return(r,o)=>{switch(r){case Xo:t=o;break;case zn:{o(t);break}case Hc:return t}return n(r,o)}}function At(e,t){return Jo(J(t),n=>ge(e,n))}function Ke(){const e=[];return(t,n)=>{switch(t){case Xo:e.slice().forEach(r=>{r(n)});return;case Nr:e.splice(0,e.length);return;case zn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Vt(e){return Jo(Ke(),t=>ge(e,t))}function Je(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:Fx(),singleton:n}}const Fx=()=>Symbol();function zx(e){const t=new Map,n=({constructor:r,dependencies:o,id:s,singleton:i})=>{if(i&&t.has(s))return t.get(s);const a=r(o.map(l=>n(l)));return i&&t.set(s,a),a};return n(e)}function xt(...e){const t=Ke(),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);tt(s,l=>{n[i]=l,r=r|a,r===o&&De(t,n)})}),function(s,i){switch(s){case Nr:{Fi(t);return}case zn:return r===o&&i(n),tt(t,i)}}}function Ee(e,t=qc){return U(e,at(t))}function zi(...e){return function(t,n){switch(t){case Nr:return;case zn:return Mx(...e.map(r=>tt(r,n)))}}}var Ft=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Ft||{});const Bx={0:"debug",3:"error",1:"log",2:"warn"},Hx=()=>typeof globalThis>"u"?window:globalThis,Bn=Je(()=>{const e=J(3);return{log:J((t,n,r=1)=>{var o;const s=(o=Hx().VIRTUOSO_LOG_LEVEL)!=null?o:gt(e);r>=s&&console[Bx[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function ar(e,t,n){return Bi(e,t,n).callbackRef}function Bi(e,t,n){const r=w.useRef(null);let o=i=>{};const s=w.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const a=()=>{const l=i[0].target;l.offsetParent!==null&&e(l)};n?a():requestAnimationFrame(a)}):null,[e,n]);return o=i=>{i&&t?(s==null||s.observe(i),r.current=i):(r.current&&(s==null||s.unobserve(r.current)),r.current=null)},{callbackRef:o,ref:r}}function Ux(e,t,n,r,o,s,i,a,l){const u=w.useCallback(d=>{const f=Wx(d.children,t,a?"offsetWidth":"offsetHeight",o);let h=d.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const p=h.lastElementChild.dataset.viewportType==="window";let v;p&&(v=h.ownerDocument.defaultView);const x=i?a?i.scrollLeft:i.scrollTop:p?a?v.scrollX||v.document.documentElement.scrollLeft:v.scrollY||v.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,g=i?a?i.scrollWidth:i.scrollHeight:p?a?v.document.documentElement.scrollWidth:v.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,y=i?a?i.offsetWidth:i.offsetHeight:p?a?v.innerWidth:v.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:g,scrollTop:Math.max(x,0),viewportHeight:y}),s==null||s(a?Gc("column-gap",getComputedStyle(d).columnGap,o):Gc("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return Bi(u,n,l)}function Wx(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const l=parseInt(a.dataset.index),u=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},Ft.ERROR),d===u)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==l-1?s.push({endIndex:l,size:d,startIndex:l}):s[s.length-1].endIndex++}return s}function Gc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Ft.WARN),t==="normal"?0:parseInt(t??"0",10)}function Yc(e,t,n){const r=w.useRef(null),o=w.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const u=l.getBoundingClientRect(),d=u.width;let f,h;if(t){const p=t.getBoundingClientRect(),v=u.top-p.top;h=p.height-Math.max(0,v),f=v+t.scrollTop}else{const p=i.current.ownerDocument.defaultView;h=p.innerHeight-Math.max(0,u.top),f=u.top+p.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=Bi(o,!0,n),a=w.useCallback(()=>{o(i.current)},[o,i]);return w.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const u=new ResizeObserver(()=>{requestAnimationFrame(a)});return u.observe(t),()=>{t.removeEventListener("scroll",a),u.unobserve(t)}}else{const u=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return u==null||u.addEventListener("scroll",a),u==null||u.addEventListener("resize",a),()=>{u==null||u.removeEventListener("scroll",a),u==null||u.removeEventListener("resize",a)}}},[a,t,i]),s}const Pt=Je(()=>{const e=Ke(),t=Ke(),n=J(0),r=Ke(),o=J(0),s=Ke(),i=Ke(),a=J(0),l=J(0),u=J(0),d=J(0),f=Ke(),h=Ke(),p=J(!1),v=J(!1),x=J(!1);return ge(U(e,le(({scrollTop:g})=>g)),t),ge(U(e,le(({scrollHeight:g})=>g)),i),ge(t,o),{deviation:n,fixedFooterHeight:u,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:v,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:x,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),no={lvl:0};function Xc(e,t){const n=e.length;if(n===0)return[];let{index:r,value:o}=t(e[0]);const s=[];for(let i=1;i<n;i++){const{index:a,value:l}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=l}return s.push({end:1/0,start:r,value:o}),s}function ot(e){return e===no}function ro(e,t){if(!ot(e))return t===e.k?e.v:t<e.k?ro(e.l,t):ro(e.r,t)}function ln(e,t,n="k"){if(ot(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=ln(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return ln(e.l,t,n)}function Kt(e,t,n){return ot(e)?Qc(t,n,1):t===e.k?yt(e,{k:t,v:n}):t<e.k?eu(yt(e,{l:Kt(e.l,t,n)})):eu(yt(e,{r:Kt(e.r,t,n)}))}function _r(){return no}function Zo(e,t,n){if(ot(e))return[];const r=ln(e,t)[0];return Vx(Ui(e,r,n))}function Hi(e,t){if(ot(e))return no;const{k:n,l:r,r:o}=e;if(t===n){if(ot(r))return o;if(ot(o))return r;{const[s,i]=Zc(r);return Qo(yt(e,{k:s,l:Jc(r),v:i}))}}else return t<n?Qo(yt(e,{l:Hi(r,t)})):Qo(yt(e,{r:Hi(o,t)}))}function lr(e){return ot(e)?[]:[...lr(e.l),{k:e.k,v:e.v},...lr(e.r)]}function Ui(e,t,n){if(ot(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(Ui(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(Ui(s,t,n))),a}function Qo(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(Wi(t))return tu(yt(e,{lvl:n-1}));if(!ot(t)&&!ot(t.r))return yt(t.r,{l:yt(t,{r:t.r.l}),lvl:n,r:yt(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(Wi(e))return Vi(yt(e,{lvl:n-1}));if(!ot(r)&&!ot(r.l)){const o=r.l,s=Wi(o)?r.lvl-1:r.lvl;return yt(o,{l:yt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:Vi(yt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function yt(e,t){return Qc(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 Jc(e){return ot(e.r)?e.l:Qo(yt(e,{r:Jc(e.r)}))}function Wi(e){return ot(e)||e.lvl>e.r.lvl}function Zc(e){return ot(e.r)?[e.k,e.v]:Zc(e.r)}function Qc(e,t,n,r=no,o=no){return{k:e,l:r,lvl:n,r:o,v:t}}function eu(e){return Vi(tu(e))}function tu(e){const{l:t}=e;return!ot(t)&&t.lvl===e.lvl?yt(t,{r:yt(e,{l:t.r})}):e}function Vi(e){const{lvl:t,r:n}=e;return!ot(n)&&!ot(n.r)&&n.lvl===t&&n.r.lvl===t?yt(n,{l:yt(e,{r:n.l}),lvl:t+1}):e}function Vx(e){return Xc(e,({k:t,v:n})=>({index:t,value:n}))}function nu(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function oo(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const Ki=Je(()=>({recalcInProgress:J(!1)}),[],{singleton:!0});function ru(e,t,n){return e[es(e,t,n)]}function es(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 Kx(e,t,n,r){const o=es(e,t,r),s=es(e,n,r,o);return e.slice(o,s+1)}function Hn(e,t){return Math.round(e.getBoundingClientRect()[t])}function ts(e){return!ot(e.groupOffsetTree)}function qi({index:e},t){return t===e?0:t<e?-1:1}function qx(){return{groupIndices:[],groupOffsetTree:_r(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:_r()}}function Gx(e,t){let n=ot(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),ot(e)){e=Kt(e,0,s);continue}const a=Zo(e,i-1,o+1);if(a.some(ty(r)))continue;let l=!1,u=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=Hi(e,f)):(u=h!==s,l=!0),d>o&&o>=f&&h!==s&&(e=Kt(e,o+1,h));u&&(e=Kt(e,i,s))}return[e,n]}function Yx(e){return typeof e.groupIndex<"u"}function Xx({offset:e},t){return t===e?0:t<e?-1:1}function so(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=ru(t,e,qi),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function ou(e,t){if(!ts(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function su(e,t,n){if(Yx(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=ou(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function Jx(e,t,n,r=0){return r>0&&(t=Math.max(t,ru(e,r,qi).offset)),Xc(Kx(e,t,n,Xx),ey)}function Zx(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Ft.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&ot(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((v,x)=>Kt(Kt(v,x,h),x+1,p),i)}else[i,a]=Gx(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f}=Gi(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>Kt(h,p,so(p,f,o)),_r()),lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f,sizeTree:i}}function Qx(e){return lr(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 iu(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 Gi(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=es(o,t-1,qi),a=o[l].offset;const u=ln(n,t-1);s=u[0],i=u[1],o.length&&o[l].size===ln(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:u,value:d}of Zo(n,t,1/0)){const f=u-s,h=f*i+a+f*r;o.push({index:u,offset:h,size:d}),s=u,a=h,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function ey(e){return{index:e.index,value:e}}function ty(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 ny={offsetHeight:"height",offsetWidth:"width"},bn=Je(([{log:e},{recalcInProgress:t}])=>{const n=Ke(),r=Ke(),o=At(r,0),s=Ke(),i=Ke(),a=J(0),l=J([]),u=J(void 0),d=J(void 0),f=J((C,T)=>Hn(C,ny[T])),h=J(void 0),p=J(0),v=qx(),x=At(U(n,$e(l,e,p),vn(Zx,v),at()),v),g=At(U(l,at(),vn((C,T)=>({current:T,prev:C.current}),{current:[],prev:[]}),le(({prev:C})=>C)),[]);ge(U(l,Ne(C=>C.length>0),$e(x,p),le(([C,T,E])=>{const A=C.reduce((j,P,D)=>Kt(j,P,so(P,T.offsetTree,E)||D),_r());return{...T,groupIndices:C,groupOffsetTree:A}})),x),ge(U(r,$e(x),Ne(([C,{lastIndex:T}])=>C<T),le(([C,{lastIndex:T,lastSize:E}])=>[{endIndex:T,size:E,startIndex:C}])),n),ge(u,d);const y=At(U(u,le(C=>C===void 0)),!0);ge(U(d,Ne(C=>C!==void 0&&ot(gt(x).sizeTree)),le(C=>[{endIndex:0,size:C,startIndex:0}])),n);const b=Vt(U(n,$e(x),vn(({sizes:C},[T,E])=>({changed:E!==C,sizes:E}),{changed:!1,sizes:v}),le(C=>C.changed)));tt(U(a,vn((C,T)=>({diff:C.prev-T,prev:T}),{diff:0,prev:0}),le(C=>C.diff)),C=>{const{groupIndices:T}=gt(x);if(C>0)De(t,!0),De(s,C+iu(C,T));else if(C<0){const E=gt(g);E.length>0&&(C-=iu(-C,E)),De(i,C)}}),tt(U(a,$e(e)),([C,T])=>{C<0&&T("`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},Ft.ERROR)});const S=Vt(s);ge(U(s,$e(x),le(([C,T])=>{const E=T.groupIndices.length>0,A=[],j=T.lastSize;if(E){const P=ro(T.sizeTree,0);let D=0,L=0;for(;D<C;){const M=T.groupIndices[L],Y=T.groupIndices.length===L+1?1/0:T.groupIndices[L+1]-M-1;A.push({endIndex:M,size:P,startIndex:M}),A.push({endIndex:M+1+Y-1,size:j,startIndex:M+1}),L++,D+=Y+1}const V=lr(T.sizeTree);return D!==C&&V.shift(),V.reduce((M,{k:Y,v:K})=>{let q=M.ranges;return M.prevSize!==0&&(q=[...M.ranges,{endIndex:Y+C-1,size:M.prevSize,startIndex:M.prevIndex}]),{prevIndex:Y+C,prevSize:K,ranges:q}},{prevIndex:C,prevSize:0,ranges:A}).ranges}return lr(T.sizeTree).reduce((P,{k:D,v:L})=>({prevIndex:D+C,prevSize:L,ranges:[...P.ranges,{endIndex:D+C-1,size:P.prevSize,startIndex:P.prevIndex}]}),{prevIndex:0,prevSize:j,ranges:[]}).ranges})),n);const I=Vt(U(i,$e(x,p),le(([C,{offsetTree:T},E])=>{const A=-C;return so(A,T,E)})));return ge(U(i,$e(x,p),le(([C,T,E])=>{if(T.groupIndices.length>0){if(ot(T.sizeTree))return T;let A=_r();const j=gt(g);let P=0,D=0,L=0;for(;P<-C;){L=j[D];const V=j[D+1]-L-1;D++,P+=V+1}if(A=lr(T.sizeTree).reduce((V,{k:M,v:Y})=>Kt(V,Math.max(0,M+C),Y),A),P!==-C){const V=ro(T.sizeTree,L);A=Kt(A,0,V);const M=ln(T.sizeTree,-C+1)[1];A=Kt(A,1,M)}return{...T,sizeTree:A,...Gi(T.offsetTree,0,A,E)}}else{const A=lr(T.sizeTree).reduce((j,{k:P,v:D})=>Kt(j,Math.max(0,P+C),D),_r());return{...T,sizeTree:A,...Gi(T.offsetTree,0,A,E)}}})),x),{beforeUnshiftWith:S,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:u,gap:p,groupIndices:l,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:I,sizeRanges:n,sizes:x,statefulTotalCount:o,totalCount:r,trackItemSizes:y,unshiftWith:s}},it(Bn,Ki),{singleton:!0});function ry(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const au=Je(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Ke(),i=Ke(),a=Vt(U(s,le(ry)));return ge(U(a,le(l=>l.totalCount)),n),ge(U(a,le(l=>l.groupIndices)),e),ge(U(xt(o,t,r),Ne(([l,u])=>ts(u)),le(([l,u,d])=>ln(u.groupOffsetTree,Math.max(l-d,0),"v")[0]),at(),le(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},it(bn,Pt)),Un=Je(([{log:e}])=>{const t=J(!1),n=Vt(U(t,Ne(r=>r),at()));return tt(t,r=>{r&>(e)("props updated",{},Ft.DEBUG)}),{didMount:n,propsReady:t}},it(Bn),{singleton:!0}),oy=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function lu(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!oy)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const io=Je(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:u,smoothScrollTargetReached:d,viewportHeight:f},{log:h}])=>{const p=Ke(),v=Ke(),x=J(0);let g=null,y=null,b=null;function S(){g&&(g(),g=null),b&&(b(),b=null),y&&(clearTimeout(y),y=null),De(l,!1)}return ge(U(p,$e(n,f,r,x,a,i,h),$e(e,s,o),le(([[I,C,T,E,A,j,P,D],L,V,M])=>{const Y=lu(I),{align:K,behavior:q,offset:z}=Y,$=E-1,pe=su(Y,C,$);let F=so(pe,C.offsetTree,L)+j;K==="end"?(F+=V+ln(C.sizeTree,pe)[1]-T+M,pe===$&&(F+=P)):K==="center"?F+=(V+ln(C.sizeTree,pe)[1]-T+M)/2:F-=A,z&&(F+=z);const te=fe=>{S(),fe?(D("retrying to scroll to",{location:I},Ft.DEBUG),De(p,I)):(De(v,!0),D("list did not change, scroll successful",{},Ft.DEBUG))};if(S(),q==="smooth"){let fe=!1;b=tt(t,me=>{fe=fe||me}),g=an(d,()=>{te(fe)})}else g=an(U(t,sy(150)),te);return y=setTimeout(()=>{S()},1200),De(l,!0),D("scrolling from index to",{behavior:q,index:pe,top:F},Ft.DEBUG),{behavior:q,top:F}})),u),{scrollTargetReached:v,scrollToIndex:p,topListHeight:x}},it(bn,Pt,Bn),{singleton:!0});function sy(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function Yi(e,t){e==0?t():requestAnimationFrame(()=>{Yi(e-1,t)})}function Xi(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const ao=Je(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=J(!0),l=J(0),u=J(!0);return ge(U(i,$e(l),Ne(([d,f])=>!!f),yn(!1)),a),ge(U(i,$e(l),Ne(([d,f])=>!!f),yn(!1)),u),tt(U(xt(t,i),$e(a,n,e,u),Ne(([[,d],f,{sizeTree:h},p,v])=>d&&(!ot(h)||$i(p))&&!f&&!v),$e(l)),([,d])=>{an(o,()=>{De(u,!0)}),Yi(4,()=>{an(r,()=>{De(a,!0)}),De(s,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:l,scrolledToInitialItem:a}},it(bn,Pt,io,Un),{singleton:!0});function cu(e,t){return Math.abs(e-t)<1.01}const lo="up",co="down",iy="none",ay={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},ly=0,uo=Je(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=J(!1),a=J(!0),l=Ke(),u=Ke(),d=J(4),f=J(ly),h=At(U(zi(U(Ee(o),ir(1),yn(!0)),U(Ee(o),ir(1),yn(!1),Kc(100))),at()),!1),p=At(U(zi(U(n,yn(!0)),U(n,yn(!1),Kc(200))),at()),!1);ge(U(xt(Ee(o),Ee(f)),le(([b,S])=>b<=S),at()),a),ge(U(a,Rn(50)),u);const v=Vt(U(xt(r,Ee(s),Ee(t),Ee(e),Ee(d)),vn((b,[{scrollHeight:S,scrollTop:I},C,T,E,A])=>{const j=I+C-S>-A,P={scrollHeight:S,scrollTop:I,viewportHeight:C};if(j){let L,V;return I>b.state.scrollTop?(L="SCROLLED_DOWN",V=b.state.scrollTop-I):(L="SIZE_DECREASED",V=b.state.scrollTop-I||b.scrollTopDelta),{atBottom:!0,atBottomBecause:L,scrollTopDelta:V,state:P}}let D;return P.scrollHeight>b.state.scrollHeight?D="SIZE_INCREASED":C<b.state.viewportHeight?D="VIEWPORT_HEIGHT_DECREASING":I<b.state.scrollTop?D="SCROLLING_UPWARDS":D="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:D,state:P}},ay),at((b,S)=>b&&b.atBottom===S.atBottom))),x=At(U(r,vn((b,{scrollHeight:S,scrollTop:I,viewportHeight:C})=>{if(cu(b.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:I};{const T=S-(I+C)<1;return b.scrollTop!==I&&T?{changed:!0,jump:b.scrollTop-I,scrollHeight:S,scrollTop:I}:{changed:!0,jump:0,scrollHeight:S,scrollTop:I}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),Ne(b=>b.changed),le(b=>b.jump)),0);ge(U(v,le(b=>b.atBottom)),i),ge(U(i,Rn(50)),l);const g=J(co);ge(U(r,le(({scrollTop:b})=>b),at(),vn((b,S)=>gt(p)?{direction:b.direction,prevScrollTop:S}:{direction:S<b.prevScrollTop?lo:co,prevScrollTop:S},{direction:co,prevScrollTop:0}),le(b=>b.direction)),g),ge(U(r,Rn(50),yn(iy)),g);const y=J(0);return ge(U(h,Ne(b=>!b),yn(0)),y),ge(U(o,Rn(100),$e(h),Ne(([b,S])=>!!S),vn(([b,S],[I])=>[S,I],[0,0]),le(([b,S])=>S-b)),y),{atBottomState:v,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:u,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:x,scrollDirection:g,scrollVelocity:y}},it(Pt)),ns="top",rs="bottom",uu="none";function du(e,t,n){return typeof e=="number"?n===lo&&t===ns||n===co&&t===rs?e:0:n===lo?t===ns?e.main:e.reverse:t===rs?e.main:e.reverse}function fu(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const Ji=Je(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Ke(),i=J(0),a=J(0),l=J(0),u=At(U(xt(Ee(r),Ee(o),Ee(n),Ee(s,oo),Ee(l),Ee(i),Ee(t),Ee(e),Ee(a)),le(([d,f,h,[p,v],x,g,y,b,S])=>{const I=d-b,C=g+y,T=Math.max(h-I,0);let E=uu;const A=fu(S,ns),j=fu(S,rs);return p-=b,p+=h+y,v+=h+y,v-=b,p>d+C-A&&(E=lo),v<d-T+f+j&&(E=co),E!==uu?[Math.max(I-h-du(x,ns,E)-A,0),I-T-y+f+du(x,rs,E)+j]:null}),Ne(d=>d!=null),at(oo)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:u}},it(Pt),{singleton:!0});function cy(e,t,n){if(ts(t)){const r=ou(e,t);return[{index:ln(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 Zi={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function os(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let u=0,d=0;if(e.length>0){u=e[0].offset;const x=e[e.length-1];d=x.offset+x.size}const f=n-i,h=a+f*l+(f-1)*r,p=u,v=h-d;return{bottom:d,firstItemIndex:s,items:pu(e,o,s),offsetBottom:v,offsetTop:u,top:p,topItems:pu(t,o,s),topListHeight:t.reduce((x,g)=>g.size+x,0),totalCount:n}}function hu(e,t,n,r,o,s){let i=0;if(n.groupIndices.length>0)for(const d of n.groupIndices){if(d-i>=e)break;i++}const a=e+i,l=Xi(t,a),u=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return os(u,[],a,o,n,r)}function pu(e,t,n){if(e.length===0)return[];if(!ts(t))return e.map(u=>({...u,index:u.index+n,originalIndex:u.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=Zo(t.groupOffsetTree,r,o);let a,l=0;for(const u of e){(!a||a.end<u.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;u.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:u.index-(l+1)+n},s.push({...d,data:u.data,offset:u.offset,originalIndex:u.index,size:u.size})}return s}const cr=Je(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:u,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:p},{recalcInProgress:v}])=>{const x=J([]),g=J(0),y=Ke();ge(s.topItemsIndexes,x);const b=At(U(xt(p,v,Ee(l,oo),Ee(o),Ee(r),Ee(u),d,Ee(x),Ee(t),Ee(n),e),Ne(([T,E,,A,,,,,,,j])=>{const P=j&&j.length!==A;return T&&!E&&!P}),le(([,,[T,E],A,j,P,D,L,V,M,Y])=>{const K=j,{offsetTree:q,sizeTree:z}=K,$=gt(g);if(A===0)return{...Zi,totalCount:A};if(T===0&&E===0)return $===0?{...Zi,totalCount:A}:hu($,P,j,V,M,Y||[]);if(ot(z))return $>0?null:os(cy(Xi(P,A),K,Y),[],A,M,K,V);const pe=[];if(L.length>0){const be=L[0],Te=L[L.length-1];let G=0;for(const O of Zo(z,be,Te)){const Z=O.value,ne=Math.max(O.start,be),de=Math.min(O.end,Te);for(let ae=ne;ae<=de;ae++)pe.push({data:Y==null?void 0:Y[ae],index:ae,offset:G,size:Z}),G+=Z}}if(!D)return os([],pe,A,M,K,V);const F=L.length>0?L[L.length-1]+1:0,te=Jx(q,T,E,F);if(te.length===0)return null;const fe=A-1,me=Jo([],be=>{for(const Te of te){const G=Te.value;let O=G.offset,Z=Te.start;const ne=G.size;if(G.offset<T){Z+=Math.floor((T-G.offset+M)/(ne+M));const ae=Z-Te.start;O+=ae*ne+ae*M}Z<F&&(O+=(F-Z)*ne,Z=F);const de=Math.min(Te.end,fe);for(let ae=Z;ae<=de&&!(O>=E);ae++)be.push({data:Y==null?void 0:Y[ae],index:ae,offset:O,size:ne}),O+=ne+M}});return os(me,pe,A,M,K,V)}),Ne(T=>T!==null),at()),Zi);ge(U(e,Ne($i),le(T=>T==null?void 0:T.length)),o),ge(U(b,le(T=>T.topListHeight)),f),ge(f,a),ge(U(b,le(T=>[T.top,T.bottom])),i),ge(U(b,le(T=>T.items)),y);const S=Vt(U(b,Ne(({items:T})=>T.length>0),$e(o,e),Ne(([{items:T},E])=>T[T.length-1].originalIndex===E-1),le(([,T,E])=>[T-1,E]),at(oo),le(([T])=>T))),I=Vt(U(b,Rn(200),Ne(({items:T,topItems:E})=>T.length>0&&T[0].originalIndex===E.length),le(({items:T})=>T[0].index),at())),C=Vt(U(b,Ne(({items:T})=>T.length>0),le(({items:T})=>{let E=0,A=T.length-1;for(;T[E].type==="group"&&E<A;)E++;for(;T[A].type==="group"&&A>E;)A--;return{endIndex:T[A].index,startIndex:T[E].index}}),at(nu)));return{endReached:S,initialItemCount:g,itemsRendered:y,listState:b,rangeChanged:C,startReached:I,topItemsIndexes:x,...h}},it(bn,au,Ji,ao,io,uo,Un,Ki),{singleton:!0}),mu=Je(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Ke(),i=At(U(xt(n,e,r,t,o),le(([a,l,u,d,f])=>a+l+u+d+f.offsetBottom+f.bottom)),0);return ge(Ee(i),s),{totalListHeight:i,totalListHeightChanged:s}},it(Pt,cr),{singleton:!0}),uy=Je(([{viewportHeight:e},{totalListHeight:t}])=>{const n=J(!1),r=At(U(xt(n,e,t),Ne(([o])=>o),le(([,o,s])=>Math.max(0,o-s)),Rn(0),at()),0);return{alignToBottom:n,paddingTopAddition:r}},it(Pt,mu),{singleton:!0}),gu=Je(()=>({context:J(null)})),dy=({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,xu=Je(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:u}])=>{const d=Ke();return ge(U(d,$e(t,l,n,s,o,r,a),$e(e),le(([[f,h,p,v,x,g,y,b],S])=>{const{align:I,behavior:C,calculateViewLocation:T=dy,done:E,...A}=f,j=su(f,h,v-1),P=so(j,h.offsetTree,S)+x+g,D=P+ln(h.sizeTree,j)[1],L=b+g,V=b+p-y,M=T({itemBottom:D,itemTop:P,locationParams:{align:I,behavior:C,...A},viewportBottom:V,viewportTop:L});return M?E&&an(U(i,Ne(Y=>!Y),ir(gt(i)?1:2)),E):E&&E(),M}),Ne(f=>f!==null)),u),{scrollIntoView:d}},it(bn,Pt,io,cr,Bn),{singleton:!0});function yu(e){return e?e==="smooth"?"smooth":"auto":!1}const fy=(e,t)=>typeof e=="function"?yu(e(t)):t&&yu(e),hy=Je(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:u},{log:d},{scrollingInProgress:f},{context:h},{scrollIntoView:p}])=>{const v=J(!1),x=Ke();let g=null;function y(C){De(i,{align:"end",behavior:C,index:"LAST"})}tt(U(xt(U(Ee(t),ir(1)),l),$e(Ee(v),s,a,f),le(([[C,T],E,A,j,P])=>{let D=T&&j,L="auto";return D&&(L=fy(E,A||P),D=D&&!!L),{followOutputBehavior:L,shouldFollow:D,totalCount:C}}),Ne(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:T})=>{g&&(g(),g=null),gt(n)?requestAnimationFrame(()=>{gt(d)("following output to ",{totalCount:T},Ft.DEBUG),y(C)}):g=an(e,()=>{gt(d)("following output to ",{totalCount:T},Ft.DEBUG),y(C),g=null})});function b(C){const T=an(o,E=>{C&&!E.atBottom&&E.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(gt(d)("scrolling to bottom due to increased size",{},Ft.DEBUG),y("auto"))});setTimeout(T,100)}tt(U(xt(Ee(v),t,u),Ne(([C,,T])=>C&&T),vn(({value:C},[,T])=>({refreshed:C===T,value:T}),{refreshed:!1,value:0}),Ne(({refreshed:C})=>C),$e(v,t)),([,C])=>{gt(a)&&b(C!==!1)}),tt(x,()=>{b(gt(v)!==!1)}),tt(xt(Ee(v),o),([C,T])=>{C&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&y("auto")});const S=J(null),I=Ke();return ge(zi(U(Ee(r),le(C=>{var T;return(T=C==null?void 0:C.length)!=null?T:0})),U(Ee(t))),I),tt(U(xt(U(I,ir(1)),l),$e(Ee(S),a,f,h),le(([[C,T],E,A,j,P])=>T&&A&&(E==null?void 0:E({context:P,totalCount:C,scrollingInProgress:j}))),Ne(C=>!!C),Rn(0)),C=>{g&&(g(),g=null),gt(n)?requestAnimationFrame(()=>{gt(d)("scrolling into view",{}),De(p,C)}):g=an(e,()=>{gt(d)("scrolling into view",{}),De(p,C),g=null})}),{autoscrollToBottom:x,followOutput:v,scrollIntoViewOnChange:S}},it(bn,uo,io,ao,Un,Bn,Pt,gu,xu)),py=Je(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(ge(U(a,$e(s),Ne(([,l])=>l!==0),$e(o,r,t,n,e),le(([[,l],u,d,f,h,p=[]])=>hu(l,u,d,f,h,p))),i),{}),it(bn,ao,cr,Un),{singleton:!0}),my=Je(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=J(0);return tt(U(e,$e(r),Ne(([,o])=>o!==0),le(([,o])=>({top:o}))),o=>{an(U(n,ir(1),Ne(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{De(t,o)})})}),{initialScrollTop:r}},it(Un,Pt,cr),{singleton:!0}),vu=Je(([{scrollVelocity:e}])=>{const t=J(!1),n=Ke(),r=J(!1);return ge(U(e,$e(r,t,n),Ne(([o,s])=>!!s),le(([o,s,i,a])=>{const{enter:l,exit:u}=s;if(i){if(u(o,a))return!1}else if(l(o,a))return!0;return i}),at()),t),tt(U(xt(t,e,n),$e(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},it(uo),{singleton:!0}),Qi=Je(([{scrollContainerState:e,scrollTo:t}])=>{const n=Ke(),r=Ke(),o=Ke(),s=J(!1),i=J(void 0);return ge(U(xt(n,r),le(([{scrollHeight:a,scrollTop:l,viewportHeight:u},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:u}))),e),ge(U(t,$e(r),le(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},it(Pt)),gy=Je(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const u=Ke(),d=J(void 0),f=J(null),h=J(null);return ge(a,f),ge(l,h),tt(U(u,$e(t,r,i,f,h,n)),([p,v,x,g,y,b,S])=>{const I=Qx(v.sizeTree);g&&y!==null&&b!==null&&(x=y.scrollTop-b.offsetTop),x-=S,p({ranges:I,scrollTop:x})}),ge(U(d,Ne($i),le(xy)),o),ge(U(s,$e(d),Ne(([,p])=>p!==void 0),at(),le(([,p])=>p.ranges)),e),{getState:u,restoreStateFrom:d}},it(bn,Pt,ao,Un,Qi));function xy(e){return{align:"start",index:0,offset:e.scrollTop}}const yy=Je(([{topItemsIndexes:e}])=>{const t=J(0);return ge(U(t,Ne(n=>n>=0),le(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},it(cr));function bu(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const vy=bu(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),by=Je(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:u,gap:d,shiftWithOffset:f,sizes:h},{log:p},{recalcInProgress:v}])=>{const x=Vt(U(l,$e(i),vn(([,y,b,S],[{bottom:I,items:C,offsetBottom:T,totalCount:E},A])=>{const j=I+T;let P=0;return b===E&&y.length>0&&C.length>0&&(C[0].originalIndex===0&&y[0].originalIndex===0||(P=j-S,P!==0&&(P+=A))),[P,C,E,j]},[0,[],0,0]),Ne(([y])=>y!==0),$e(r,a,n,o,p,v),Ne(([,y,b,S,,,I])=>!I&&!S&&y!==0&&b===lo),le(([[y],,,,,b])=>(b("Upward scrolling compensation",{amount:y},Ft.DEBUG),y))));function g(y){y>0?(De(t,{behavior:"auto",top:-y}),De(e,0)):(De(e,0),De(t,{behavior:"auto",top:-y}))}return tt(U(x,$e(e,s)),([y,b,S])=>{S&&vy()?De(e,b-y):g(-y)}),tt(U(xt(At(s,!1),e,v),Ne(([y,b,S])=>!y&&!S&&b!==0),le(([y,b])=>b),Rn(1)),g),ge(U(f,le(y=>({top:-y}))),t),tt(U(u,$e(h,d),le(([y,{groupIndices:b,lastSize:S,sizeTree:I},C])=>{function T(E){return E*(S+C)}if(b.length===0)return T(y);{let E=0;const A=ro(I,0);let j=0,P=0;for(;j<y;){j++,E+=A;let D=b.length===P+1?1/0:b[P+1]-b[P]-1;j+D>y&&(E-=A,D=y-j+1),j+=D,E+=T(D),P++}return E}})),y=>{De(e,y),requestAnimationFrame(()=>{De(t,{top:y}),requestAnimationFrame(()=>{De(e,0),De(v,!1)})})}),{deviation:e}},it(Pt,uo,cr,bn,Bn,Ki)),wy=Je(([e,t,n,r,o,s,i,a,l,u,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...u,...d}),it(Ji,py,Un,vu,mu,my,uy,Qi,xu,Bn,gu)),wu=Je(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:u,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:v},x,g,y,{listState:b,topItemsIndexes:S,...I},{scrollToIndex:C},T,{topItemCount:E},{groupCounts:A},j])=>(ge(I.rangeChanged,j.scrollSeekRangeChanged),ge(U(j.windowViewportRect,le(P=>P.visibleHeight)),x.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:A,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:v,sizeRanges:a,topItemCount:E,topItemsIndexes:S,totalCount:d,...y,groupIndices:s,itemSize:i,listState:b,scrollToIndex:C,statefulTotalCount:u,trackItemSizes:f,...I,...j,...x,sizes:l,...g}),it(bn,ao,Pt,gy,hy,cr,io,by,yy,au,wy));function Sy(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 ss=typeof document<"u"?w.useLayoutEffect:w.useEffect;function Su(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=w.createContext({});function l(g,y){g.propsReady&&De(g.propsReady,!1);for(const b of r){const S=g[t.required[b]];De(S,y[b])}for(const b of o)if(b in y){const S=g[t.optional[b]];De(S,y[b])}g.propsReady&&De(g.propsReady,!0)}function u(g){return s.reduce((y,b)=>(y[b]=S=>{const I=g[t.methods[b]];De(I,S)},y),{})}function d(g){return i.reduce((y,b)=>(y[b]=$x(g[t.events[b]]),y),{})}const f=w.forwardRef((g,y)=>{const{children:b,...S}=g,[I]=w.useState(()=>Jo(zx(e),E=>{l(E,S)})),[C]=w.useState(Vc(d,I));ss(()=>{for(const E of i)E in S&&tt(C[E],S[E]);return()=>{Object.values(C).map(Fi)}},[S,C,I]),ss(()=>{l(I,S)}),w.useImperativeHandle(y,Uc(u(I)));const T=n;return c.jsx(a.Provider,{value:I,children:n?c.jsx(T,{...Sy([...r,...o,...i],S),children:b}):b})}),h=g=>{const y=w.useContext(a);return w.useCallback(b=>{De(y[g],b)},[y,g])},p=g=>{const y=w.useContext(a)[g],b=w.useCallback(S=>tt(y,S),[y]);return w.useSyncExternalStore(b,()=>gt(y),()=>gt(y))},v=g=>{const y=w.useContext(a)[g],[b,S]=w.useState(Vc(gt,y));return ss(()=>tt(y,I=>{I!==b&&S(Uc(I))}),[y,b]),b},x=w.version.startsWith("18")?p:v;return{Component:f,useEmitter:(g,y)=>{const b=w.useContext(a)[g];ss(()=>tt(b,y),[y,b])},useEmitterValue:x,usePublisher:h}}const Cu=w.createContext(void 0),Tu=w.createContext(void 0),ku=typeof document<"u"?w.useLayoutEffect:w.useEffect;function ea(e){return"self"in e}function Cy(e){return"body"in e}function Eu(e,t,n,r=Ar,o,s){const i=w.useRef(null),a=w.useRef(null),l=w.useRef(null),u=w.useCallback(h=>{let p,v,x;const g=h.target;if(Cy(g)||ea(g)){const b=ea(g)?g:g.defaultView;x=s?b.scrollX:b.scrollY,p=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,v=s?b.innerWidth:b.innerHeight}else x=s?g.scrollLeft:g.scrollTop,p=s?g.scrollWidth:g.scrollHeight,v=s?g.offsetWidth:g.offsetHeight;const y=()=>{e({scrollHeight:p,scrollTop:Math.max(x,0),viewportHeight:v})};h.suppressFlushSync?y():di.flushSync(y),a.current!==null&&(x===a.current||x<=0||x===p-v)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);w.useEffect(()=>{const h=o||i.current;return r(o||i.current),u({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",u,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",u)}},[i,u,n,r,o]);function d(h){const p=i.current;if(!p||(s?"offsetWidth"in p&&p.offsetWidth===0:"offsetHeight"in p&&p.offsetHeight===0))return;const v=h.behavior==="smooth";let x,g,y;ea(p)?(g=Math.max(Hn(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),x=s?p.innerWidth:p.innerHeight,y=s?window.scrollX:window.scrollY):(g=p[s?"scrollWidth":"scrollHeight"],x=Hn(p,s?"width":"height"),y=p[s?"scrollLeft":"scrollTop"]);const b=g-x;if(h.top=Math.ceil(Math.max(Math.min(b,h.top),0)),cu(x,g)||h.top===y){e({scrollHeight:g,scrollTop:y,viewportHeight:x}),v&&t(!0);return}v?(a.current=h.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),p.scrollTo(h)}function f(h){s&&(h={behavior:h.behavior,left:h.top}),i.current.scrollBy(h)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const ta="-webkit-sticky",Iu="sticky",na=bu(()=>{if(typeof document>"u")return Iu;const e=document.createElement("div");return e.style.position=ta,e.style.position===ta?ta:Iu});function ra(e){return e}const Ty=Je(()=>{const e=J(a=>`Item ${a}`),t=J(a=>`Group ${a}`),n=J({}),r=J(ra),o=J("div"),s=J(Ar),i=(a,l=null)=>At(U(n,le(u=>u[a]),at()),l);return{components:n,computeItemKey:r,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:t,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:e,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),ky=Je(([e,t])=>({...e,...t}),it(wu,Ty)),Ey=({height:e})=>c.jsx("div",{style:{height:e}}),Iy={overflowAnchor:"none",position:na(),zIndex:1},Nu={overflowAnchor:"none"},Ny={...Nu,display:"inline-block",height:"100%"},Au=w.memo(function({showTopList:e=!1}){const t=Pe("listState"),n=Jt("sizeRanges"),r=Pe("useWindowScroll"),o=Pe("customScrollParent"),s=Jt("windowScrollContainerState"),i=Jt("scrollContainerState"),a=o||r?s:i,l=Pe("itemContent"),u=Pe("context"),d=Pe("groupContent"),f=Pe("trackItemSizes"),h=Pe("itemSize"),p=Pe("log"),v=Jt("gap"),x=Pe("horizontalDirection"),{callbackRef:g}=Ux(n,h,f,e?Ar:a,p,v,o,x,Pe("skipAnimationFrameInResizeObserver")),[y,b]=w.useState(0);oa("deviation",M=>{y!==M&&b(M)});const S=Pe("EmptyPlaceholder"),I=Pe("ScrollSeekPlaceholder")||Ey,C=Pe("ListComponent"),T=Pe("ItemComponent"),E=Pe("GroupComponent"),A=Pe("computeItemKey"),j=Pe("isSeeking"),P=Pe("groupIndices").length>0,D=Pe("alignToBottom"),L=Pe("initialItemFinalLocationReached"),V=e?{}:{boxSizing:"border-box",...x?{display:"inline-block",height:"100%",marginLeft:y!==0?y:D?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:y!==0?y:D?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...L?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?c.jsx(S,{..._t(S,u)}):c.jsx(C,{..._t(C,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:g,style:V,children:(e?t.topItems:t.items).map(M=>{const Y=M.originalIndex,K=A(Y+t.firstItemIndex,M.data,u);return j?w.createElement(I,{..._t(I,u),height:M.size,index:M.index,key:K,type:M.type||"item",...M.type==="group"?{}:{groupIndex:M.groupIndex}}):M.type==="group"?w.createElement(E,{..._t(E,u),"data-index":Y,"data-item-index":M.index,"data-known-size":M.size,key:K,style:Iy},d(M.index,u)):w.createElement(T,{..._t(T,u),...Ry(T,M.data),"data-index":Y,"data-item-group-index":M.groupIndex,"data-item-index":M.index,"data-known-size":M.size,key:K,style:x?Ny:Nu},P?l(M.index,M.groupIndex,M.data,u):l(M.index,M.data,u))})})}),Ay={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},_y={outline:"none",overflowX:"auto",position:"relative"},is=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),jy={position:na(),top:0,width:"100%",zIndex:1};function _t(e,t){if(typeof e!="string")return{context:t}}function Ry(e,t){return{item:typeof e=="string"?void 0:t}}const Py=w.memo(function(){const e=Pe("HeaderComponent"),t=Jt("headerHeight"),n=Pe("HeaderFooterTag"),r=ar(w.useMemo(()=>s=>{t(Hn(s,"height"))},[t]),!0,Pe("skipAnimationFrameInResizeObserver")),o=Pe("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{..._t(e,o)})}):null}),Oy=w.memo(function(){const e=Pe("FooterComponent"),t=Jt("footerHeight"),n=Pe("HeaderFooterTag"),r=ar(w.useMemo(()=>s=>{t(Hn(s,"height"))},[t]),!0,Pe("skipAnimationFrameInResizeObserver")),o=Pe("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{..._t(e,o)})}):null});function _u({useEmitter:e,useEmitterValue:t,usePublisher:n}){return w.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback:v}=Eu(a,u,l,d,void 0,f);return e("scrollTo",v),e("scrollBy",h),c.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?_y:Ay,...o},tabIndex:0,...i,..._t(l,s),children:r})})}function ju({useEmitter:e,useEmitterValue:t,usePublisher:n}){return w.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),p=w.useRef(null),v=t("scrollerRef"),{scrollByCallback:x,scrollerRef:g,scrollToCallback:y}=Eu(a,u,l,v,h);return ku(()=>{var b;return g.current=h||((b=p.current)==null?void 0:b.ownerDocument.defaultView),()=>{g.current=null}},[g,h]),e("windowScrollTo",y),e("scrollBy",x),c.jsx(l,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,..._t(l,s),children:r})})}const My=({children:e})=>{const t=w.useContext(Cu),n=Jt("viewportHeight"),r=Jt("fixedItemHeight"),o=Pe("alignToBottom"),s=Pe("horizontalDirection"),i=w.useMemo(()=>Wc(n,l=>Hn(l,s?"width":"height")),[n,s]),a=ar(i,!0,Pe("skipAnimationFrameInResizeObserver"));return w.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),c.jsx("div",{"data-viewport-type":"element",ref:a,style:is(o),children:e})},Dy=({children:e})=>{const t=w.useContext(Cu),n=Jt("windowViewportRect"),r=Jt("fixedItemHeight"),o=Pe("customScrollParent"),s=Yc(n,o,Pe("skipAnimationFrameInResizeObserver")),i=Pe("alignToBottom");return w.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),c.jsx("div",{"data-viewport-type":"window",ref:s,style:is(i),children:e})},Ly=({children:e})=>{const t=Pe("TopItemListComponent")||"div",n=Pe("headerHeight"),r={...jy,marginTop:`${n}px`},o=Pe("context");return c.jsx(t,{style:r,..._t(t,o),children:e})},$y=w.memo(function(e){const t=Pe("useWindowScroll"),n=Pe("topItemsIndexes").length>0,r=Pe("customScrollParent"),o=Pe("context");return c.jsxs(r||t?By:zy,{...e,context:o,children:[n&&c.jsx(Ly,{children:c.jsx(Au,{showTopList:!0})}),c.jsxs(r||t?Dy:My,{children:[c.jsx(Py,{}),c.jsx(Au,{}),c.jsx(Oy,{})]})]})}),{Component:Fy,useEmitter:oa,useEmitterValue:Pe,usePublisher:Jt}=Su(ky,{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"}},$y),zy=_u({useEmitter:oa,useEmitterValue:Pe,usePublisher:Jt}),By=ju({useEmitter:oa,useEmitterValue:Pe,usePublisher:Jt}),Hy=Fy;it(wu,Je(()=>{const e=J(u=>c.jsxs("td",{children:["Item $",u]})),t=J(null),n=J(u=>c.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=J(null),o=J(null),s=J({}),i=J(ra),a=J(Ar),l=(u,d=null)=>At(U(s,le(f=>f[u]),at()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:l("EmptyPlaceholder"),FillerRow:l("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TableBodyComponent:l("TableBody","tbody"),TableComponent:l("Table","table"),TableFooterComponent:l("TableFoot","tfoot"),TableHeadComponent:l("TableHead","thead"),TableRowComponent:l("TableRow","tr"),GroupComponent:l("Group","tr")}})),na();const Ru={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},Uy={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Pu,floor:as,max:fo,min:sa,round:Ou}=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 Wy(e){return{...Uy,items:e}}function ls(e,t){return e&&e.width===t.width&&e.height===t.height}function Vy(e,t){return e&&e.column===t.column&&e.row===t.row}const Ky=Je(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:u,smoothScrollTargetReached:d,viewportHeight:f},h,p,{didMount:v,propsReady:x},{customScrollParent:g,useWindowScroll:y,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:I},C])=>{const T=J(0),E=J(0),A=J(Ru),j=J({height:0,width:0}),P=J({height:0,width:0}),D=Ke(),L=Ke(),V=J(0),M=J(null),Y=J({column:0,row:0}),K=Ke(),q=Ke(),z=J(!1),$=J(0),pe=J(!0),F=J(!1),te=J(!1);tt(U(v,$e($),Ne(([O,Z])=>!!Z)),()=>{De(pe,!1)}),tt(U(xt(v,pe,P,j,$,F),Ne(([O,Z,ne,de,,ae])=>O&&!Z&&ne.height!==0&&de.height!==0&&!ae)),([,,,,O])=>{De(F,!0),Yi(1,()=>{De(D,O)}),an(U(u),()=>{De(t,[0,0]),De(pe,!0)})}),ge(U(q,Ne(O=>O!=null&&O.scrollTop>0),yn(0)),E),tt(U(v,$e(q),Ne(([,O])=>O!=null)),([,O])=>{O&&(De(j,O.viewport),De(P,O.item),De(Y,O.gap),O.scrollTop>0&&(De(z,!0),an(U(u,ir(1)),Z=>{De(z,!1)}),De(l,{top:O.scrollTop})))}),ge(U(j,le(({height:O})=>O)),f),ge(U(xt(Ee(j,ls),Ee(P,ls),Ee(Y,(O,Z)=>O&&O.column===Z.column&&O.row===Z.row),Ee(u)),le(([O,Z,ne,de])=>({gap:ne,item:Z,scrollTop:de,viewport:O}))),K),ge(U(xt(Ee(T),r,Ee(Y,Vy),Ee(P,ls),Ee(j,ls),Ee(M),Ee(E),Ee(z),Ee(pe),Ee($)),Ne(([,,,,,,,O])=>!O),le(([O,[Z,ne],de,ae,We,Ze,ve,,Oe,Le])=>{const{column:ct,row:rt}=de,{height:vt,width:St}=ae,{width:B}=We;if(ve===0&&(O===0||B===0))return Ru;if(St===0){const Ct=Xi(Le,O),nn=Ct+Math.max(ve-1,0);return Wy(Mu(Ct,nn,Ze))}const se=Du(B,St,ct);let we,Ie;Oe?Z===0&&ne===0&&ve>0?(we=0,Ie=ve-1):(we=se*as((Z+rt)/(vt+rt)),Ie=se*Pu((ne+rt)/(vt+rt))-1,Ie=sa(O-1,fo(Ie,se-1)),we=sa(Ie,fo(0,we))):(we=0,Ie=-1);const xe=Mu(we,Ie,Ze),{bottom:Re,top:Qe}=Lu(We,de,ae,xe),Fe=Pu(O/se),pt=Fe*vt+(Fe-1)*rt-Re;return{bottom:Re,itemHeight:vt,items:xe,itemWidth:St,offsetBottom:pt,offsetTop:Qe,top:Qe}})),A),ge(U(M,Ne(O=>O!==null),le(O=>O.length)),T),ge(U(xt(j,P,A,Y),Ne(([O,Z,{items:ne}])=>ne.length>0&&Z.height!==0&&O.height!==0),le(([O,Z,{items:ne},de])=>{const{bottom:ae,top:We}=Lu(O,de,Z,ne);return[We,ae]}),at(oo)),t);const fe=J(!1);ge(U(u,$e(fe),le(([O,Z])=>Z||O!==0)),fe);const me=Vt(U(xt(A,T),Ne(([{items:O}])=>O.length>0),$e(fe),Ne(([[O,Z],ne])=>{const de=O.items[O.items.length-1].index===Z-1;return(ne||O.bottom>0&&O.itemHeight>0&&O.offsetBottom===0&&O.items.length===Z)&&de}),le(([[,O]])=>O-1),at())),be=Vt(U(Ee(A),Ne(({items:O})=>O.length>0&&O[0].index===0),yn(0),at())),Te=Vt(U(Ee(A),$e(z),Ne(([{items:O},Z])=>O.length>0&&!Z),le(([{items:O}])=>({endIndex:O[O.length-1].index,startIndex:O[0].index})),at(nu),Rn(0)));ge(Te,p.scrollSeekRangeChanged),ge(U(D,$e(j,P,T,Y),le(([O,Z,ne,de,ae])=>{const We=lu(O),{align:Ze,behavior:ve,offset:Oe}=We;let Le=We.index;Le==="LAST"&&(Le=de-1),Le=fo(0,Le,sa(de-1,Le));let ct=ia(Z,ae,ne,Le);return Ze==="end"?ct=Ou(ct-Z.height+ne.height):Ze==="center"&&(ct=Ou(ct-Z.height/2+ne.height/2)),Oe&&(ct+=Oe),{behavior:ve,top:ct}})),l);const G=At(U(A,le(O=>O.offsetBottom+O.bottom)),0);return ge(U(I,le(O=>({height:O.visibleHeight,width:O.visibleWidth}))),j),{customScrollParent:g,data:M,deviation:V,footerHeight:o,gap:Y,headerHeight:s,increaseViewportBy:e,initialItemCount:E,itemDimensions:P,overscan:n,restoreStateFrom:q,scrollBy:i,scrollContainerState:a,scrollHeight:L,scrollTo:l,scrollToIndex:D,scrollTop:u,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:y,viewportDimensions:j,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:I,...p,gridState:A,horizontalDirection:te,initialTopMostItemIndex:$,totalListHeight:G,...h,endReached:me,propsReady:x,rangeChanged:Te,startReached:be,stateChanged:K,stateRestoreInProgress:z,...C}},it(Ji,Pt,uo,vu,Un,Qi,Bn));function Du(e,t,n){return fo(1,as((e+n)/(as(t)+n)))}function Lu(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=ia(e,t,n,r[0].index);return{bottom:ia(e,t,n,r[r.length-1].index)+o,top:s}}function ia(e,t,n,r){const o=Du(e.width,n.width,t.column),s=as(r/o),i=s*n.height+fo(0,s-1)*t.row;return i>0?i+t.row:i}const qy=Je(()=>{const e=J(f=>`Item ${f}`),t=J({}),n=J(null),r=J("virtuoso-grid-item"),o=J("virtuoso-grid-list"),s=J(ra),i=J("div"),a=J(Ar),l=(f,h=null)=>At(U(t,le(p=>p[f]),at()),h),u=J(!1),d=J(!1);return ge(Ee(d),u),{components:t,computeItemKey:s,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:l("Item","div"),itemContent:e,listClassName:o,ListComponent:l("List","div"),readyStateChanged:u,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),Gy=Je(([e,t])=>({...e,...t}),it(Ky,qy)),Yy=w.memo(function(){const e=lt("gridState"),t=lt("listClassName"),n=lt("itemClassName"),r=lt("itemContent"),o=lt("computeItemKey"),s=lt("isSeeking"),i=Zt("scrollHeight"),a=lt("ItemComponent"),l=lt("ListComponent"),u=lt("ScrollSeekPlaceholder"),d=lt("context"),f=Zt("itemDimensions"),h=Zt("gap"),p=lt("log"),v=lt("stateRestoreInProgress"),x=Zt("reportReadyState"),g=ar(w.useMemo(()=>y=>{const b=y.parentElement.parentElement.scrollHeight;i(b);const S=y.firstChild;if(S){const{height:I,width:C}=S.getBoundingClientRect();f({height:I,width:C})}h({column:Fu("column-gap",getComputedStyle(y).columnGap,p),row:Fu("row-gap",getComputedStyle(y).rowGap,p)})},[i,f,h,p]),!0,!1);return ku(()=>{e.itemHeight>0&&e.itemWidth>0&&x(!0)},[e]),v?null:c.jsx(l,{className:t,ref:g,..._t(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(y=>{const b=o(y.index,y.data,d);return s?c.jsx(u,{..._t(u,d),height:e.itemHeight,index:y.index,width:e.itemWidth},b):w.createElement(a,{..._t(a,d),className:n,"data-index":y.index,key:b},r(y.index,y.data,d))})})}),Xy=w.memo(function(){const e=lt("HeaderComponent"),t=Zt("headerHeight"),n=lt("headerFooterTag"),r=ar(w.useMemo(()=>s=>{t(Hn(s,"height"))},[t]),!0,!1),o=lt("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{..._t(e,o)})}):null}),Jy=w.memo(function(){const e=lt("FooterComponent"),t=Zt("footerHeight"),n=lt("headerFooterTag"),r=ar(w.useMemo(()=>s=>{t(Hn(s,"height"))},[t]),!0,!1),o=lt("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{..._t(e,o)})}):null}),Zy=({children:e})=>{const t=w.useContext(Tu),n=Zt("itemDimensions"),r=Zt("viewportDimensions"),o=ar(w.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return w.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),c.jsx("div",{ref:o,style:is(!1),children:e})},Qy=({children:e})=>{const t=w.useContext(Tu),n=Zt("windowViewportRect"),r=Zt("itemDimensions"),o=lt("customScrollParent"),s=Yc(n,o,!1);return w.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),c.jsx("div",{ref:s,style:is(!1),children:e})},ev=w.memo(function({...e}){const t=lt("useWindowScroll"),n=lt("customScrollParent"),r=n||t?nv:tv,o=n||t?Qy:Zy,s=lt("context");return c.jsx(r,{...e,..._t(r,s),children:c.jsxs(o,{children:[c.jsx(Xy,{}),c.jsx(Yy,{}),c.jsx(Jy,{})]})})}),{useEmitter:$u,useEmitterValue:lt,usePublisher:Zt}=Su(Gy,{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"}},ev),tv=_u({useEmitter:$u,useEmitterValue:lt,usePublisher:Zt}),nv=ju({useEmitter:$u,useEmitterValue:lt,usePublisher:Zt});function Fu(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Ft.WARN),t==="normal"?0:parseInt(t??"0",10)}const rv=jo.cva("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function aa({className:e,variant:t,...n}){return c.jsx("div",{className:ee(rv({variant:t}),e),...n})}function ue(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 ov(e,t){const n=m.createContext(t),r=s=>{const{children:i,...a}=s,l=m.useMemo(()=>a,Object.values(a));return c.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=m.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 wn(e,t=[]){let n=[];function r(s,i){const a=m.createContext(i),l=n.length;n=[...n,i];const u=f=>{var y;const{scope:h,children:p,...v}=f,x=((y=h==null?void 0:h[e])==null?void 0:y[l])||a,g=m.useMemo(()=>v,Object.values(v));return c.jsx(x.Provider,{value:g,children:p})};u.displayName=s+"Provider";function d(f,h){var x;const p=((x=h==null?void 0:h[e])==null?void 0:x[l])||a,v=m.useContext(p);if(v)return v;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[u,d]}const o=()=>{const s=n.map(i=>m.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return m.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,sv(o,...t)]}function sv(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:u})=>{const f=l(s)[`__scope${u}`];return{...a,...f}},{});return m.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var wt=globalThis!=null&&globalThis.document?m.useLayoutEffect:()=>{},iv=m[" useInsertionEffect ".trim().toString()]||wt;function ur({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=av({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=m.useRef(e!==void 0);m.useEffect(()=>{const f=d.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.`),d.current=a},[a,r])}const u=m.useCallback(d=>{var f;if(a){const h=lv(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[l,u]}function av({defaultProp:e,onChange:t}){const[n,r]=m.useState(e),o=m.useRef(n),s=m.useRef(t);return iv(()=>{s.current=t},[t]),m.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function lv(e){return typeof e=="function"}function zu(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function la(...e){return t=>{let n=!1;const r=e.map(o=>{const s=zu(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():zu(e[o],null)}}}}function Ue(...e){return m.useCallback(la(...e),e)}var cv=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ae=cv.reduce((e,t)=>{const n=nr.createSlot(`Primitive.${t}`),r=m.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),c.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Bu(e,t){e&&Ro.flushSync(()=>e.dispatchEvent(t))}function uv(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var qt=e=>{const{present:t,children:n}=e,r=dv(t),o=typeof n=="function"?n({present:r.isPresent}):m.Children.only(n),s=Ue(r.ref,fv(o));return typeof n=="function"||r.isPresent?m.cloneElement(o,{ref:s}):null};qt.displayName="Presence";function dv(e){const[t,n]=m.useState(),r=m.useRef(null),o=m.useRef(e),s=m.useRef("none"),i=e?"mounted":"unmounted",[a,l]=uv(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return m.useEffect(()=>{const u=cs(r.current);s.current=a==="mounted"?u:"none"},[a]),wt(()=>{const u=r.current,d=o.current;if(d!==e){const h=s.current,p=cs(u);e?l("MOUNT"):p==="none"||(u==null?void 0:u.display)==="none"?l("UNMOUNT"):l(d&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),wt(()=>{if(t){let u;const d=t.ownerDocument.defaultView??window,f=p=>{const x=cs(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&x&&(l("ANIMATION_END"),!o.current)){const g=t.style.animationFillMode;t.style.animationFillMode="forwards",u=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=g)})}},h=p=>{p.target===t&&(s.current=cs(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(u),t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:m.useCallback(u=>{r.current=u?getComputedStyle(u):null,n(u)},[])}}function cs(e){return(e==null?void 0:e.animationName)||"none"}function fv(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 hv=m[" useId ".trim().toString()]||(()=>{}),pv=0;function Sn(e){const[t,n]=m.useState(hv());return wt(()=>{n(r=>r??String(pv++))},[e]),e||(t?`radix-${t}`:"")}var us="Collapsible",[mv,tk]=wn(us),[gv,ca]=mv(us),Hu=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[l,u]=ur({prop:r,defaultProp:o??!1,onChange:i,caller:us});return c.jsx(gv,{scope:n,disabled:s,contentId:Sn(),open:l,onOpenToggle:m.useCallback(()=>u(d=>!d),[u]),children:c.jsx(Ae.div,{"data-state":da(l),"data-disabled":s?"":void 0,...a,ref:t})})});Hu.displayName=us;var Uu="CollapsibleTrigger",Wu=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=ca(Uu,n);return c.jsx(Ae.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":da(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:ue(e.onClick,o.onOpenToggle)})});Wu.displayName=Uu;var ua="CollapsibleContent",xv=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=ca(ua,e.__scopeCollapsible);return c.jsx(qt,{present:n||o.open,children:({present:s})=>c.jsx(yv,{...r,ref:t,present:s})})});xv.displayName=ua;var yv=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=ca(ua,n),[a,l]=m.useState(r),u=m.useRef(null),d=Ue(t,u),f=m.useRef(0),h=f.current,p=m.useRef(0),v=p.current,x=i.open||a,g=m.useRef(x),y=m.useRef(void 0);return m.useEffect(()=>{const b=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(b)},[]),wt(()=>{const b=u.current;if(b){y.current=y.current||{transitionDuration:b.style.transitionDuration,animationName:b.style.animationName},b.style.transitionDuration="0s",b.style.animationName="none";const S=b.getBoundingClientRect();f.current=S.height,p.current=S.width,g.current||(b.style.transitionDuration=y.current.transitionDuration,b.style.animationName=y.current.animationName),l(r)}},[i.open,r]),c.jsx(Ae.div,{"data-state":da(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!x,...s,ref:d,style:{"--radix-collapsible-content-height":h?`${h}px`:void 0,"--radix-collapsible-content-width":v?`${v}px`:void 0,...e.style},children:x&&o})});function da(e){return e?"open":"closed"}var vv=Hu;const Vu=vv,Ku=Wu,ho=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:ee("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));ho.displayName="Card";const po=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:ee("flex flex-col space-y-1.5 p-6",e),...t}));po.displayName="CardHeader";const mo=m.forwardRef(({className:e,...t},n)=>c.jsx("h3",{ref:n,className:ee("text-2xl font-semibold leading-none tracking-tight",e),...t}));mo.displayName="CardTitle";const qu=m.forwardRef(({className:e,...t},n)=>c.jsx("p",{ref:n,className:ee("text-sm text-muted-foreground",e),...t}));qu.displayName="CardDescription";const ds=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:ee("p-6 pt-0",e),...t}));ds.displayName="CardContent";const Gu=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:ee("flex items-center p-6 pt-0",e),...t}));Gu.displayName="CardFooter";function Yu(){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 dr=Yu();function bv(e){dr=e}const Xu=/[&<>"']/,wv=new RegExp(Xu.source,"g"),Ju=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,Sv=new RegExp(Ju.source,"g"),Cv={"&":"&","<":"<",">":">",'"':""","'":"'"},Zu=e=>Cv[e];function jt(e,t){if(t){if(Xu.test(e))return e.replace(wv,Zu)}else if(Ju.test(e))return e.replace(Sv,Zu);return e}const Tv=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Qu(e){return e.replace(Tv,(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 kv=/(^|[^\[])\^/g;function st(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(kv,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const Ev=/[^\w:]/g,Iv=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function ed(e,t,n){if(e){let r;try{r=decodeURIComponent(Qu(n)).replace(Ev,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!Iv.test(n)&&(n=jv(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const fs={},Nv=/^[^:]+:\/*[^/]*$/,Av=/^([^:]+:)[\s\S]*$/,_v=/^([^:]+:\/*[^/]*)[\s\S]*$/;function jv(e,t){fs[" "+e]||(Nv.test(e)?fs[" "+e]=e+"/":fs[" "+e]=ps(e,"/",!0)),e=fs[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(Av,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(_v,"$1")+t:e+t}const hs={exec:function(){}};function td(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,u=i;for(;--u>=0&&a[u]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function ps(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 Rv(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 Pv(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 nd(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function rd(e,t,n,r){const o=t.href,s=t.title?jt(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:jt(i)}}function Ov(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
|
|
37
|
+
`))>=0;){const se=G.slice(0,B);G=G.slice(B+2);const we=vx(se);if(!we)continue;let Ie;try{Ie=JSON.parse(we)}catch{console.debug("[use-chat] malformed SSE:",we.slice(0,200));continue}const ye=yx(Ie)?Ie.data:Ie;Ue=Date.now();const je=ye.seq;if(je!==void 0){if(je<=Q){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:je,lastProcessedSeq:Q,type:ye.type});continue}Q>0&&je>Q+1&&(($=L==null?void 0:L.onGap)==null||$.call(L,{from:Q,to:je})),Q=je,C.current=je,g(je)}if(console.debug("[use-chat] received event",{seq:ye.seq,type:ye.type,preview:(()=>{var Qe;try{return ye.type==="message_delta"?{deltaTypes:(Qe=ye.delta)==null?void 0:Qe.map(Fe=>Fe.type),textLen:(ye.delta||[]).filter(Fe=>Fe.type==="text").map(Fe=>String(Fe.text||"").length)}:ye.content||ye.delta?{hasContent:!0}:{}}catch(Fe){return{err:String(Fe)}}})()}),D==null||D(ye),ye.type==="token"&&e.autoAppendAssistant!==!1)O.push(ye.content),ae();else if(ye.type==="message_delta"){const Qe=ye.delta.filter(Fe=>Fe.type==="text").map(Fe=>Fe.text).join("");Qe&&e.autoAppendAssistant!==!1&&(O.push(Qe),ae())}else ye.type==="heartbeat"?console.debug("[use-chat] heartbeat received"):(ne!==null&&cancelAnimationFrame(ne),de(),ye.type==="checkpoint"?v(ye.checkpointId):ye.type==="error"&&d(ye.message))}}de()}catch(Pe){if(Pe.name!=="AbortError"){const Le=Pe.message||String(Pe);d(Le),(pe=L==null?void 0:L.onError)==null||pe.call(L,Le)}}finally{try{await be.cancel()}catch{}finally{(F=be.releaseLock)==null||F.call(be)}ne!==null&&typeof window<"u"&&window.cancelAnimationFrame(ne),clearInterval(Ze),l(!1),b(!1),S.current=null,C.current=0,g(0)}}catch(fe){if(fe.name!=="AbortError"){const ge=fe.message||String(fe);d(ge),(te=L==null?void 0:L.onError)==null||te.call(L,ge)}}finally{l(!1),b(!1),S.current=null,C.current=0,g(0)}})(),{close:()=>V.abort()}},[t,n,r,e.autoAppendAssistant]);return w.useEffect(()=>()=>{var P;I.current=!1,(P=S.current)==null||P.abort()},[]),{isStreaming:a,error:u,assistantText:f,lastCheckpointId:p,lastSeq:x,connected:y,stream:j,stop:E,clear:A,setToken:T}}function yx(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function vx(e){const t=e.split(/\r?\n/),n=[];for(const r of t)if(r&&!r.startsWith(":")&&r.startsWith("data:")){const o=r.slice(5);n.push(o.startsWith(" ")?o.slice(1):o)}return n.length===0?null:n.join(`
|
|
38
|
+
`)}function bx({baseUrl:e,onThreadInfo:t,onMessageEvent:n,onUnhandledEvent:r,onSequenceGap:o}){const s=w.useRef(null),i=w.useCallback(p=>{const v=p.seq??null;if(v!==null){const x=s.current;if(x!==null){if(v<=x)return;v>x+1&&(o==null||o({from:x,to:v}))}s.current=v}if(p.type==="thread_info"){console.log("[useChatStreamingService] 🎯 Received thread_info event:",p),t(p);return}if(fx(p)){n(p);return}r==null||r(p)},[n,o,t,r]),{stream:a,stop:l,isStreaming:u,error:d,setToken:f}=Rc({baseUrl:e,token:null}),h=w.useCallback((p,v)=>{s.current=null,a(p,i,{onOpen:v==null?void 0:v.onOpen,onError:x=>{var g;(g=v==null?void 0:v.onError)==null||g.call(v,x)},onGap:(v==null?void 0:v.onGap)??o})},[i,o,a]);return w.useMemo(()=>({startStream:h,stop:l,isStreaming:u,error:d,setAuthToken:f}),[h,l,u,d,f])}const Pc=w.createContext(null),Oc=w.createContext(null),Mc=w.createContext(null),wx=w.createContext(!1),Sx="cachedThreads",Cx="v1",Ho=300,Ai=200,Dc=50;function Tx(e,t,n){return`${e}__${t??""}__${n??""}`}function Lc(e,t){if(!e&&!t)return!0;if(!e||!t||e.id!==t.id)return!1;try{return JSON.stringify(e.value)===JSON.stringify(t.value)}catch{return e.value===t.value}}function Bt(e,t={}){const n=t.cloneMessages??!1,r=Array.isArray(e==null?void 0:e.messages)?e.messages:[];return{checkpointId:(e==null?void 0:e.checkpointId)??null,checkpointNs:(e==null?void 0:e.checkpointNs)??null,createdAt:(e==null?void 0:e.createdAt)??null,preview:(e==null?void 0:e.preview)??null,role:(e==null?void 0:e.role)??null,parentId:(e==null?void 0:e.parentId)??null,branchLabel:(e==null?void 0:e.branchLabel)??null,lastMessageId:(e==null?void 0:e.lastMessageId)??null,messagesLen:typeof(e==null?void 0:e.messagesLen)=="number"?e.messagesLen:r.length,hasMessages:typeof(e==null?void 0:e.hasMessages)=="boolean"?e.hasMessages:r.length>0,messages:n?r.slice():r,nextCursor:(e==null?void 0:e.nextCursor)??null,nextCursorNs:(e==null?void 0:e.nextCursorNs)??null,interrupt:(e==null?void 0:e.interrupt)??null}}function kx(e){var t;for(let n=e.length-1;n>=0;n--){const r=((t=e[n])==null?void 0:t.content)??[];for(let o=r.length-1;o>=0;o--){const s=r[o];if((s==null?void 0:s.type)==="interrupt"){const i=s.id;return{id:(typeof i=="string"?i:null)??`interrupt-${e[n].id??o}`,value:s.value}}}}return null}function $c(e){if(typeof window<"u"&&"requestIdleCallback"in window)try{window.requestIdleCallback(e,{timeout:1e3});return}catch{}window.setTimeout(e,Ho)}function kr(){return typeof window<"u"&&typeof window.localStorage<"u"}function _i(e){if(!kr())return null;try{return window.localStorage.getItem(e)}catch{return null}}function Fc(e,t){if(kr())try{window.localStorage.setItem(e,t)}catch{}}function ji(e){if(kr())try{window.localStorage.removeItem(e)}catch{}}function Ex(){const e=_i(Sx);if(!e)return[];try{const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>{if(!n||typeof n!="object")return!1;const r=n;return typeof r.threadId=="string"&&typeof r.title=="string"}):[]}catch{return[]}}function Ix(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t^e.charCodeAt(n);return(t>>>0).toString(36)}function Ri(e,t){return`cachedThreads:v1:${e}:${Ix(t||"anon")}`}function Nx(e){const t=_i(e);if(!t)return[];try{const n=JSON.parse(t);return Array.isArray(n)?n.filter(r=>{if(!r||typeof r!="object")return!1;const o=r;return typeof o.threadId=="string"&&typeof o.title=="string"}):[]}catch{return[]}}function Pi(e,t){try{Fc(e,JSON.stringify(t))}catch{}}function Oi(e){const t=Nx(e);if(t.length>0)return t;const n=Ex();if(n.length>0)try{Pi(e,n.slice(0,Ai))}catch{}return n}function Uo(e){const t={},n=[];for(const r of e)!r||typeof r.threadId!="string"||t[r.threadId]||(t[r.threadId]=r,n.push(r.threadId));return{byId:t,order:n}}function Mi(e){return e.order.map(t=>e.byId[t]).filter(Boolean)}function Ax({children:e,initialThreadId:t=null,autoLoadInitial:n=!0,disableAutoRestore:r=!1,enableFileAgentRouting:o=!1,fileAgentId:s="invoice_reader",onError:i,onThreadChange:a}){const{api:l,baseUrl:u}=ki(),d=w.useMemo(()=>_n(u),[u]),f=w.useMemo(()=>{try{return new URL(u).host}catch{return"unknown"}},[u]),h=w.useMemo(()=>`threadPayload:${Cx}:${f}:`,[f]),p=w.useCallback(N=>`${h}${N}`,[h]),v=w.useCallback(N=>{if(!N||typeof N!="object")return null;const _=N;return typeof _.threadId!="string"?null:{threadId:_.threadId,snapshot:Bt(_.snapshot,{cloneMessages:!0})}},[]),x=w.useCallback(N=>{const _=_i(p(N));if(!_)return null;try{const H=JSON.parse(_);return v(H)}catch{return null}},[p,v]),g=w.useCallback((N,_=100)=>{const H=Bt(N.snapshot,{cloneMessages:!0}),Z={threadId:N.threadId,snapshot:{...H,messages:H.messages.slice(-_)}};try{Fc(p(N.threadId),JSON.stringify(Z))}catch{}},[p]),y=w.useCallback(N=>{ji(p(N))},[p]),b=w.useCallback(()=>{if(kr())try{const N=h;for(let _=0;_<window.localStorage.length;_++){const H=window.localStorage.key(_);H&&H.startsWith(N)&&window.localStorage.removeItem(H)}}catch{}},[h]),[S,I]=w.useState(()=>{var N;return Ri(f,(N=l.getAuthToken)==null?void 0:N.call(l))}),[C,T]=w.useState(()=>{var _;const N=Oi(Ri(f,(_=l.getAuthToken)==null?void 0:_.call(l)));return Uo(N)}),E=w.useMemo(()=>Mi(C),[C]),[A,j]=w.useState(t),[P,D]=w.useState(!1),[L,V]=w.useState(!1),[M,X]=w.useState(null),[K,q]=w.useState(null),[z,$]=w.useState(null),[pe,F]=w.useState([]),te=w.useCallback(()=>{const N=Oi(S);w.startTransition(()=>{T(Uo(N))})},[S]),[fe,ge]=w.useState(!1),[be,Te]=w.useState(!1),[G,O]=w.useState(null),[Q,ne]=w.useState(void 0),[de,ae]=w.useState(void 0),[Ue,Ze]=w.useState(void 0),{state:me,dispatch:Pe,seed:Le,prepend:ct,pushUser:rt,onEvent:vt,reset:wt}=Cc(),B=w.useRef(A);w.useEffect(()=>{B.current=A},[A]);const se=w.useRef(!1),we=w.useRef([]),Ie=w.useRef(null),ye=w.useRef(null),je=w.useRef(new Map),Qe=w.useRef(A),Fe=w.useRef(!1),pt=w.useRef(null),St=w.useRef(new Map),en=w.useRef(new Map),Ft=w.useRef(new Map),dn=w.useRef(new Map),En=w.useCallback(N=>{if(!N){F([]);return}const _=St.current.get(N);if(!_||!_.length){F([]);return}F(_.map(H=>Bt(H,{cloneMessages:!0})))},[]);w.useEffect(()=>{En(A)},[A,En]);const zr=w.useCallback(()=>{var Z;const N=dn.current;if(N.size<=Dc)return;const _=Array.from(N.entries()).sort((re,Y)=>re[1].timestamp-Y[1].timestamp),H=N.size-Dc;for(let re=0;re<H;re++){const Y=(Z=_[re])==null?void 0:Z[0];Y&&N.delete(Y)}},[]),Jn=w.useCallback((N,_,H)=>{if(!N)return;const Z=H==="replace"?[]:St.current.get(N)??[],re=H==="replace"?_:[..._,...Z];if(!re.length){H==="replace"&&St.current.set(N,[]);return}const Y=new Map;for(const Ye of re){if(!(Ye!=null&&Ye.checkpointId))continue;const Oe=`${Ye.checkpointId}::${Ye.checkpointNs??""}`;Y.has(Oe)||Y.set(Oe,Bt(Ye,{cloneMessages:!0}))}const Ve=Array.from(Y.values()).sort((Ye,Oe)=>{const Je=Number.isFinite(Date.parse(Ye.createdAt??""))?Date.parse(Ye.createdAt??""):0;return(Number.isFinite(Date.parse(Oe.createdAt??""))?Date.parse(Oe.createdAt??""):0)-Je});St.current.set(N,Ve),N===B.current&&En(N)},[En]),tn=w.useCallback((N,_,H)=>{if(!N)return;const Z=en.current.get(N),re=H==="replace"||!Z?new Map:new Map(Z);if(_&&typeof _=="object")for(const[Y,Ve]of Object.entries(_)){if(!(Ve!=null&&Ve.checkpointId))continue;const Ye=Y||Bo(Ve.checkpointId,Ve.checkpointNs??null);re.set(Ye,Bt(Ve,{cloneMessages:!0}))}en.current.set(N,re)},[]),Mn=w.useCallback((N,_)=>{const{threadId:H,checkpointId:Z=null,checkpointNs:re=null}=N,Y=Tx(H,Z,re);if(_!=null&&_.force)Ft.current.delete(Y),dn.current.delete(Y);else{if(_!=null&&_.preferCache){const Je=dn.current.get(Y);if(Je)return Promise.resolve(Je.payload)}const Oe=Ft.current.get(Y);if(Oe)return Oe}const Ye=l.getStateHistory({threadId:H,checkpointId:Z??void 0,checkpointNs:re??void 0}).then(Oe=>(dn.current.set(Y,{payload:Oe,timestamp:Date.now()}),zr(),Oe)).finally(()=>{Ft.current.get(Y)===Ye&&Ft.current.delete(Y)});return Ft.current.set(Y,Ye),Ye},[l,zr]),Ot=w.useCallback((N,_)=>new Promise((H,Z)=>{const re=async()=>{se.current=!0;try{await N(),H()}catch(Y){Z(Y)}finally{se.current=!1;const Y=we.current.shift();Y&&Y().catch(()=>{})}};se.current?we.current.push(re):re().catch(Y=>{Z(Y)})}),[]),Zn=w.useRef(E.length),[Br,Hr]=w.useState(!1),he=w.useRef(!1);w.useEffect(()=>{Zn.current=E.length},[E.length]),w.useEffect(()=>{const N=me.pendingInterrupt??kx(me.messages);Lc(z,N)||$(N??null)},[z,me.messages,me.pendingInterrupt]);const ve=w.useCallback(async()=>{const N=Zn.current>0;N||D(!0);try{const _=await l.listThreads();w.startTransition(()=>{T(H=>{const Z=Ve=>Ve.map(Ye=>`${Ye.threadId}:${Ye.updatedAt??""}:${Ye.messageCount??""}`).join("|"),re=Mi(H);return Z(re)===Z(_)||_.length===0&&re.length>0&&!he.current?H:Uo(_)})}),X(null),he.current||(he.current=!0,Hr(!0))}catch(_){i==null||i(String(_)),console.error("[ChatSessionProvider] Failed to refresh threads:",_),X(String(_))}finally{N||D(!1)}},[l,i]),et=w.useRef(!1),dt=w.useRef(null),ft=w.useRef(null),nn=w.useRef(""),br=w.useCallback((N,_)=>{if(!kr())return;ft.current!==null&&(window.clearTimeout(ft.current),ft.current=null);const H=N.map(re=>`${re.threadId}:${re.updatedAt??""}:${re.messageCount??""}`).join("|");if(N.length===0){try{ji(S)}catch{}nn.current="";return}if(H===nn.current)return;const Z=()=>{try{const re=N.slice(0,Ai);Pi(S,re),nn.current=H}catch{}finally{ft.current=null}};if(_!=null&&_.immediate){Z();return}ft.current=window.setTimeout(()=>{$c(Z)},Ho)},[S]),Co=w.useCallback(()=>{br(E,{immediate:!0})},[br,E]),fn=w.useCallback((N,_,H,Z)=>{var bm;const re=H??B.current;if(!re)return;const Y=Bt(N),Ve=re===B.current,Ye=(Z==null?void 0:Z.persist)!==!1;if(_==="replace"){if(Ye){const Tt={threadId:re,snapshot:Bt(N,{cloneMessages:!0})};je.current.set(re,Tt),Qe.current=re}if(!Ve)return;Le(Y.messages,{checkpointId:Y.checkpointId??null,checkpointNs:Y.checkpointNs??null,pendingInterrupt:Y.interrupt??null}),$(Y.interrupt??null),O(Y.nextCursor??null),ge(!!Y.nextCursor),ne(Y.checkpointId??void 0),ae(Y.checkpointNs??void 0),Ze(Y.nextCursorNs??void 0);return}const Oe=je.current.get(re),Je=(Oe==null?void 0:Oe.snapshot)??null,qt=Array.isArray(Je==null?void 0:Je.messages)?Je.messages:[],jt=Bt(Je),Ln=Array.isArray(N==null?void 0:N.messages)?N.messages:[],Eo=new Set,wr=[...Ln,...qt].filter(Tt=>{const vl=Tt==null?void 0:Tt.id;return vl?Eo.has(vl)?!1:(Eo.add(vl),!0):!0}),xl={checkpointId:jt.checkpointId??Y.checkpointId??null,checkpointNs:jt.checkpointNs??Y.checkpointNs??null,createdAt:Y.createdAt??jt.createdAt??null,preview:Y.preview??jt.preview??null,role:Y.role??jt.role??null,parentId:Y.parentId??jt.parentId??null,branchLabel:Y.branchLabel??jt.branchLabel??null,lastMessageId:((bm=wr[wr.length-1])==null?void 0:bm.id)??null,messagesLen:wr.length,hasMessages:wr.length>0,messages:wr,nextCursor:Y.nextCursor??jt.nextCursor??null,nextCursorNs:Y.nextCursorNs??jt.nextCursorNs??null,interrupt:jt.interrupt??Y.interrupt??null};if(je.current.set(re,{threadId:re,snapshot:Bt(xl,{cloneMessages:!0})}),!Ve)return;Ln.length&&ct(Ln);const ci=N&&Object.prototype.hasOwnProperty.call(N,"checkpointId")?N.checkpointId:void 0,Io=N&&Object.prototype.hasOwnProperty.call(N,"checkpointNs")?N.checkpointNs:void 0,An=N&&Object.prototype.hasOwnProperty.call(N,"nextCursor")?N.nextCursor:void 0,yl=N&&Object.prototype.hasOwnProperty.call(N,"nextCursorNs")?N.nextCursorNs:void 0;O(Tt=>An!==void 0?An??Tt??null:Tt??null),ge(Tt=>An!==void 0?!!An:Tt),ne(Tt=>ci!==void 0?ci??Tt??void 0:Tt??void 0),ae(Tt=>Io!==void 0?Io??Tt??void 0:Tt??void 0),Ze(Tt=>yl!==void 0?yl??void 0:Tt)},[ct,Le,$]),To=w.useCallback(N=>{if(N.threadId!=null&&N.threadId!==B.current)return;const _=Bt(N.snapshot,{cloneMessages:!0});Le(_.messages,{checkpointId:_.checkpointId??null,checkpointNs:_.checkpointNs??null,pendingInterrupt:_.interrupt??null}),$(_.interrupt??null),O(_.nextCursor??null),ge(!!_.nextCursor),ne(_.checkpointId??void 0),ae(_.checkpointNs??void 0),Ze(_.nextCursorNs??void 0),Qe.current=N.threadId,En(N.threadId??B.current??null)},[Le,$,En]),Qn=w.useCallback(N=>{if(!N)return;je.current.delete(N),y(N),St.current.delete(N),en.current.delete(N),N===B.current&&F([]);const _=`${N}__`;for(const H of Ft.current.keys())H.startsWith(_)&&Ft.current.delete(H);for(const H of dn.current.keys())H.startsWith(_)&&dn.current.delete(H);Qe.current===N&&(Qe.current=null)},[y]),er=w.useCallback(()=>{const N=B.current;N&&Qn(N),wt([]),ge(!1),Te(!1),O(null),ne(void 0),ae(void 0),Ze(void 0)},[Qn,wt]),ko=w.useCallback(({from:N,to:_})=>{const H=B.current;H&&console.warn(`[ChatSessionProvider] Stream sequence gap detected (${N} -> ${_}) for thread ${H}`)},[]),k=w.useCallback(N=>{const _=N.threadId;console.log("[ChatSessionProvider] 📥 Handling thread_info event:",{threadId:_,title:N.title,created:N.created,currentThreads:E.length});const H={threadId:_,title:N.title||`Thread ${_.slice(0,8)}`,createdAt:N.createdAt||new Date().toISOString(),updatedAt:N.updatedAt||new Date().toISOString(),messageCount:N.messageCount||0};B.current!==_&&(!B.current&&me.messages.length<=1&&(ye.current=_),j(_)),w.startTransition(()=>{T(Z=>{const re=Z.byId[_];return re?re.title===H.title&&re.updatedAt===H.updatedAt&&re.messageCount===H.messageCount?Z:{byId:{...Z.byId,[_]:H},order:Z.order}:{byId:{...Z.byId,[_]:H},order:[_,...Z.order]}})})},[me.messages.length]),{startStream:W,stop:oe,isStreaming:ke,error:qe,setAuthToken:Ge}=bx({baseUrl:d,onThreadInfo:k,onMessageEvent:vt,onUnhandledEvent:N=>{console.warn(`[ChatSessionProvider] Unhandled stream event: ${N.type}`,N)},onSequenceGap:ko});w.useEffect(()=>{et.current=ke},[ke]),w.useEffect(()=>{if(!kr())return;ft.current!==null&&(window.clearTimeout(ft.current),ft.current=null);const N=E.map(H=>`${H.threadId}:${H.updatedAt??""}:${H.messageCount??""}`).join("|");if(E.length===0){try{ji(S)}catch{}nn.current="";return}if(N===nn.current)return;const _=()=>{try{const H=E.slice(0,Ai);Pi(S,H),nn.current=N}catch{}finally{ft.current=null}};return ft.current=window.setTimeout(()=>{$c(_),ft.current=null},Ho),()=>{ft.current!==null&&(window.clearTimeout(ft.current),ft.current=null)}},[E,br]),w.useEffect(()=>{var Z;const N=l.getAuthToken();Ge(N);const _=re=>{const Y=Ri(f,re);pt.current!==Y&&(pt.current=Y,Fe.current=!1),I(Y);const Ve=Oi(Y);w.startTransition(()=>{T(Uo(Ve))}),Fe.current||(Fe.current=!0,ve().catch(()=>{}))};_(N);const H=(Z=l.onTokenChange)==null?void 0:Z.call(l,re=>{Ge(re),b(),Ft.current.clear(),dn.current.clear(),_(re)});return()=>{H==null||H()}},[l,f,Ge,b,ve]);const Be=w.useCallback(async N=>{var Z;const _=`Thread ${(Z=crypto.randomUUID)==null?void 0:Z.call(crypto)}`,H={threadId:_,title:N||"New Chat",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),messageCount:0};T(re=>({byId:{...re.byId,[_]:H},order:[_,...re.order]})),j(_);try{const re=await l.createThread(N),Y=typeof re=="string"?re:re.threadId;return T(Ve=>{const Ye=Ve.byId[_];if(!Ye)return Ve;const Oe={...Ve.byId};delete Oe[_],Oe[Y]={...Ye,threadId:Y};const Je=Ve.order.map(qt=>qt===_?Y:qt);return{byId:Oe,order:Je}}),j(Y),setTimeout(()=>ve(),10),X(null),Y}catch(re){throw T(Y=>{if(!Y.byId[_])return Y;const Ve={...Y.byId};delete Ve[_];const Ye=Y.order.filter(Oe=>Oe!==_);return{byId:Ve,order:Ye}}),j(null),X(String(re)),re}},[l,ve]),ze=w.useCallback(async N=>{try{await l.deleteThread(N);let _=null;T(H=>{if(!H.byId[N])return H;const Z={...H.byId};delete Z[N];const re=H.order.filter(Ve=>Ve!==N),Y={byId:Z,order:re};return _=Mi(Y),Y}),_&&br(_,{immediate:!0}),Qn(N),B.current===N&&(ye.current=N,j(null),B.current=null,Qe.current=null,er()),await ve(),X(null)}catch(_){throw X(String(_)),_}},[l,er,Qn,ve,br]),Ct=w.useCallback(async(N,_)=>{try{await l.updateThread(N,_),T(H=>{const Z=H.byId[N];return Z?{byId:{...H.byId,[N]:{...Z,title:_}},order:H.order}:H}),X(null)}catch(H){throw await ve(),X(String(H)),H}},[l,ve]),nt=w.useCallback(async(N,_,H,Z=!1)=>{await Ot(async()=>{if(ye.current===N&&!Z){ye.current=null;return}if(Ie.current===N&&!Z)return;j(Oe=>Oe===N?Oe:N),B.current=N;const re=!Z&&!_&&!H;let Y=!1;if(re){const Oe=je.current.get(N);if(Oe)To(Oe),Y=!0;else{const Je=x(N);Je&&(je.current.set(N,Je),To(Je),Y=!0)}}const Ve=Z||!Y||!!_||!!H,Ye=async Oe=>{Oe&&V(!0),Ie.current=N;try{const Je=await Mn({threadId:N,checkpointId:_,checkpointNs:H},{force:Z}),{latest:qt,checkpoints:jt,snapshots:Ln}=xc(Je);fn(qt,"replace",N),Jn(N,jt,"replace"),tn(N,Ln,"replace"),q(null)}catch(Je){throw(!Y||Z||Oe)&&(i==null||i(String(Je))),q(String(Je)),Je}finally{Ie.current=null,Oe&&V(!1)}};Ve?await Ye(!0):re&&Y&&Ye(!1).catch(Oe=>{console.warn("[ChatSessionProvider] Background refresh failed:",Oe)})},`loadThread-${N}`)},[To,fn,Ot,Mn,i,Jn,tn]),ht=w.useCallback(async()=>{await Ot(async()=>{const N=B.current;N&&Qn(N),ye.current=null,j(null),B.current=null,Qe.current=null,er(),ne(void 0),ae(void 0),Ze(void 0),F([]);try{localStorage.removeItem("lastThreadId")}catch(_){console.warn("[ChatSessionProvider] Failed to clear lastThreadId:",_)}},"clearCurrentThread")},[er,Qn,Ot]),Mt=w.useCallback(async(N,_)=>{var Y;const H=B.current;if(!H)throw new Error("No active thread");const Z=Bo(N,_??null),re=(Y=en.current.get(H))==null?void 0:Y.get(Z);if(re){await Ot(async()=>{fn(re,"replace",H,{persist:!1})},`navigateToCheckpoint-${H}-${Z}`);return}await nt(H,N,_??void 0,!0)},[fn,Ot,nt]),Dn=w.useCallback(async()=>{if(!B.current)throw new Error("No active thread");await nt(B.current,void 0,void 0,!0)},[nt]),In=w.useCallback(async()=>{if(!B.current)throw new Error("No active thread");if(be||!fe)return;const N=G;if(N){Te(!0);try{const _=B.current,H=await Mn({threadId:_,checkpointId:N??Q??null,checkpointNs:Ue??de??null}),{latest:Z,checkpoints:re,snapshots:Y}=xc(H);fn(Z,"prepend",_??void 0),_&&(Jn(_,re,"prepend"),tn(_,Y,"prepend")),q(null)}catch(_){throw q(String(_)),_}finally{Te(!1)}}},[fn,Mn,fe,Q,de,Ue,G,be,Jn,tn]),Et=w.useCallback(N=>{if(N!=null&&N.threadId){if(N.checkpointId){const _=Bo(N.checkpointId,N.checkpointNs??null),H=Bt({...N,interrupt:N.interrupt??null},{cloneMessages:!0});tn(N.threadId,{[_]:H},"prepend")}fn(N,"replace",N.threadId)}},[fn,tn]),Nn=w.useCallback(async(N,_)=>{const{payload:H,...Z}=N??{},re={...Z,payload:H??{}};re.threadId||delete re.threadId,re.command||delete re.command,W(re,_)},[W]),ai=w.useCallback(async(N,_)=>{var Io;const H=B.current,Z=(N==null?void 0:N.text)??"",re=(N==null?void 0:N.attachments)??[],Y=re.length?re:(_==null?void 0:_.attachments)??[],Ve={...(_==null?void 0:_.payloadExtras)??{},...(N==null?void 0:N.payload)??{}};if(!H&&!Object.keys(Ve).length&&Y.length===0&&!Z.trim()){console.warn("[ChatSessionProvider] Nothing to submit - skipping");return}!H&&!Ve.messages&&console.warn("[ChatSessionProvider] No thread ID - message will create new thread");const{contentParts:Ye,filesInfo:Oe}=await Jg(l,Y),Je=[...Ye];Z&&Z.trim()&&Je.push({type:"text",text:Z.trim()});const qt=!!H,jt=qt?(_==null?void 0:_.checkpointId)??me.lastCheckpointId??void 0:void 0,Ln=qt?(_==null?void 0:_.checkpointNs)??me.lastCheckpointNs??void 0:void 0,Eo={id:((Io=crypto.randomUUID)==null?void 0:Io.call(crypto))||`user-${Date.now()}`,role:"user",content:Je,createdAt:new Date().toISOString(),...jt!=null?{checkpointId:jt}:{},...Ln!=null?{checkpointNs:Ln}:{}};Je.length>0&&rt(Eo);const wr={...Eo,content:Je},xl=Y.length>0,ci={messages:Je.length>0?[wr]:[],files_info:Oe,...o&&xl&&s?{active_agent:s}:{},...Ve};await Nn({threadId:H??null,payload:ci,checkpointId:jt??null,checkpointNs:Ln??null,nodeFilter:(_==null?void 0:_.nodeFilter)??null,config:_==null?void 0:_.config},{onError:An=>{console.warn("[ChatSessionProvider] Stream error:",An)},onOpen:({threadId:An})=>{!B.current&&An&&(me.messages.length<=1&&(ye.current=An),j(An))},onGap:ko})},[Nn,l,o,s,ko,me.lastCheckpointId,me.lastCheckpointNs,me.messages.length,rt,W]),li=w.useCallback(async(N,_,H)=>{const Z=B.current;if(!Z)throw new Error("No active thread to handle interrupt");const re=_?H??!0:!1;try{try{Pe({type:"interrupt_response",payload:{interruptId:N}})}catch(Y){console.warn("[ChatSessionProvider] optimistic interrupt_response dispatch failed:",Y)}await Nn({threadId:Z,checkpointId:me.lastCheckpointId??null,checkpointNs:me.lastCheckpointNs??null,command:{kind:"resume",value:re},payload:{}},{onError:Y=>{console.warn("[ChatSessionProvider] Resume stream error:",Y)}}),$(null)}catch(Y){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${N}:`,Y),Y}},[Pe,me.lastCheckpointId,me.lastCheckpointNs,Nn]);w.useEffect(()=>{if(a==null||a(A),A)try{localStorage.setItem("lastThreadId",A)}catch(N){console.warn("[ChatSessionProvider] Failed to persist lastThreadId:",N)}},[A,a]),w.useEffect(()=>((async()=>{try{if(ve().catch(_=>{console.error("[ChatSessionProvider] Failed to refresh threads (background):",_),i==null||i(String(_))}),!r&&!t)try{const _=localStorage.getItem("lastThreadId");_&&(j(_),n&&await nt(_))}catch(_){console.warn("[ChatSessionProvider] Failed to restore last thread:",_)}else t&&n&&await nt(t)}catch(_){console.error("[ChatSessionProvider] Initialization failed:",_),i==null||i(String(_))}})(),()=>{}),[]),w.useEffect(()=>{const N=B.current;if(!N||Qe.current!==N)return;const _=Bt({checkpointId:me.lastCheckpointId??null,checkpointNs:me.lastCheckpointNs??null,messages:me.messages.slice(),nextCursor:G??null,nextCursorNs:Ue??null,interrupt:me.pendingInterrupt??z??null}),H=je.current.get(N),Z=H==null?void 0:H.snapshot,re=!Z||Z.messages.length!==_.messages.length||Z.messages.some((Oe,Je)=>{var qt;return(Oe==null?void 0:Oe.id)!==((qt=_.messages[Je])==null?void 0:qt.id)}),Y=((Z==null?void 0:Z.checkpointId)??null)!==_.checkpointId||((Z==null?void 0:Z.checkpointNs)??null)!==_.checkpointNs,Ve=((Z==null?void 0:Z.nextCursor)??null)!==_.nextCursor||((Z==null?void 0:Z.nextCursorNs)??null)!==_.nextCursorNs,Ye=!Lc((Z==null?void 0:Z.interrupt)??null,_.interrupt??null);if(re||Y||Ve||Ye){const Oe={threadId:N,snapshot:Bt(_,{cloneMessages:!0})};je.current.set(N,Oe),dt.current&&window.clearTimeout(dt.current),dt.current=window.setTimeout(()=>{try{g(Oe,100)}catch(Je){console.warn("[ChatSessionProvider] Failed to persist thread payload:",Je)}},Ho)}},[G,Ue,me.lastCheckpointId,me.lastCheckpointNs,me.messages,me.pendingInterrupt,z,g]);const IT=w.useMemo(()=>({threads:E,currentThreadId:A,setCurrentThreadId:j,isLoading:P,error:M,actions:{createThread:Be,deleteThread:ze,renameThread:Ct,refreshThreads:()=>ve()},persistThreadsCache:Co,hydrateFromCache:te}),[E,A,P,M,Be,ze,Ct,ve,Co,te,j]),NT=w.useMemo(()=>{const N=me.lastBranch??null,_=me.assemblingId??null,H=N||_?{branchLabel:(N==null?void 0:N.branchLabel)??null,lastBranch:N,assemblingMessageId:_}:null;return{threadId:A,messages:me.messages,interrupt:z,checkpoint:{id:me.lastCheckpointId??null,namespace:me.lastCheckpointNs??null},checkpoints:pe,metadata:H,isLoading:L,isHistoryLoading:be,error:K,hasMore:fe,loadOlder:In,seedFromSnapshot:Et,clearState:er,navigateToCheckpoint:Mt,returnToLatest:Dn,loadThread:nt,clearThread:ht,respondToInterrupt:li}},[ht,er,A,z,fe,be,L,In,nt,me.assemblingId,me.lastBranch,me.lastCheckpointId,me.lastCheckpointNs,me.messages,Mt,li,Dn,Et,K,pe]),AT=w.useMemo(()=>({isStreaming:ke,error:qe,send:Nn,submit:ai,stop:oe,setAuthToken:Ge}),[ke,Nn,qe,ai,oe,Ge]);return c.jsx(wx.Provider,{value:!0,children:c.jsx(Mc.Provider,{value:AT,children:c.jsx(Pc.Provider,{value:IT,children:c.jsx(Oc.Provider,{value:NT,children:e})})})})}function Wo(){const e=w.useContext(Pc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function Vo(){const e=w.useContext(Oc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function zc(){const e=w.useContext(Mc);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function Ko({children:e,apiConfig:t,initialThreadId:n=null,autoLoadInitial:r=!0,disableAutoRestore:o=!1,enableFileAgentRouting:s=!1,fileAgentId:i="invoice_reader",onError:a,onThreadChange:l}){return c.jsx(Yg,{apiConfig:t,children:c.jsx(Ax,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,enableFileAgentRouting:s,fileAgentId:i,onError:a,onThreadChange:l,children:e})})}function ee(...e){return Tm.twMerge(Cm.clsx(e))}const _x=No.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"}}),Ke=m.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?tr.Slot:"button";return c.jsx(i,{className:ee(_x({variant:t,size:n,className:e})),ref:s,...o})});Ke.displayName="Button";const Bc=m.forwardRef(({className:e,...t},n)=>c.jsx("textarea",{className:ee("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));Bc.displayName="Textarea";function jx({initialValue:e="",editingMessageId:t=null,placeholder:n="Type your message...",isStreaming:r=!1,disabled:o=!1,maxLength:s=2e4,onSend:i,onCancelEdit:a,onStop:l,className:u="",textareaClassName:d="",allowEmptySend:f=!1}){const[h,p]=w.useState(e),[v,x]=w.useTransition(),g=w.useRef(null);w.useEffect(()=>{p(e??""),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[e,t]);const y=w.useCallback(()=>{const A=g.current;A&&(A.style.height="auto",A.style.height=`${A.scrollHeight}px`)},[]);w.useEffect(()=>{y()},[y]);const b=w.useCallback(async A=>{A&&A.preventDefault();const j=(h??"").trim();!j&&!f||x(()=>{try{const P=i(j);P&&typeof P.then=="function"?P.then(()=>{p(""),g.current&&(g.current.style.height="auto")}).catch(()=>{}):(p(""),g.current&&(g.current.style.height="auto"))}catch{}})},[h,i,f]),S=w.useCallback(A=>{p(A.target.value),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[]),I=w.useCallback(A=>{A.key==="Enter"&&!A.shiftKey?(A.preventDefault(),b()):A.key==="Escape"&&t&&(A.preventDefault(),a==null||a())},[b,t,a]),E=`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))]":""} ${d}`;return c.jsx("form",{onSubmit:A=>void b(A),className:`w-full ${u}`,children:c.jsxs("div",{className:"flex items-end gap-2",children:[c.jsx("div",{className:"flex-1",children:c.jsx(Bc,{ref:g,value:h,onChange:S,onKeyDown:I,placeholder:t?"Edit your message...":n,className:E,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),c.jsx("div",{children:r?c.jsx(Ke,{type:"button",onClick:()=>{l==null||l()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!l,children:c.jsx(ie.Square,{size:16})}):c.jsx(Ke,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!h.trim()&&!f||v,children:c.jsx(ie.Send,{size:16})})})]})})}const Rx=w.memo(jx),qo=0,Fn=1,Er=2,Hc=4;function Uc(e){return()=>e}function Px(e){e()}function Wc(e,t){return n=>e(t(n))}function Vc(e,t){return()=>e(t)}function Ox(e,t){return n=>e(t,n)}function Di(e){return e!==void 0}function Mx(...e){return()=>{e.map(Px)}}function Ir(){}function Go(e,t){return t(e),e}function Dx(e,t){return t(e)}function it(...e){return e}function tt(e,t){return e(Fn,t)}function De(e,t){e(qo,t)}function Li(e){e(Er)}function gt(e){return e(Hc)}function xe(e,t){return tt(e,Ox(t,qo))}function on(e,t){const n=e(Fn,r=>{n(),t(r)});return n}function Kc(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function qc(e,t){return e===t}function at(e=qc){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function Ne(e){return t=>n=>{e(n)&&t(n)}}function le(e){return t=>Wc(t,e)}function mn(e){return t=>()=>{t(e)}}function U(e,...t){const n=Lx(...t);return(r,o)=>{switch(r){case Er:Li(e);return;case Fn:return tt(e,n(o))}}}function gn(e,t){return n=>r=>{n(t=e(t,r))}}function sr(e){return t=>n=>{e>0?e--:t(n)}}function Rn(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function $e(...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);tt(s,l=>{const u=n;n=n|a,t[i]=l,u!==o&&n===o&&r&&(r(),r=null)})}),s=>i=>{const a=()=>{s([i].concat(t))};n===o?a():r=a}}function Lx(...e){return t=>e.reduceRight(Dx,t)}function $x(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case Fn:return s?n===s?void 0:(r(),n=s,t=tt(e,s),t):(r(),Ir);case Er:r(),n=null;return}}}function J(e){let t=e;const n=We();return(r,o)=>{switch(r){case qo:t=o;break;case Fn:{o(t);break}case Hc:return t}return n(r,o)}}function Nt(e,t){return Go(J(t),n=>xe(e,n))}function We(){const e=[];return(t,n)=>{switch(t){case qo:e.slice().forEach(r=>{r(n)});return;case Er:e.splice(0,e.length);return;case Fn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Ht(e){return Go(We(),t=>xe(e,t))}function Xe(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:Fx(),singleton:n}}const Fx=()=>Symbol();function zx(e){const t=new Map,n=({constructor:r,dependencies:o,id:s,singleton:i})=>{if(i&&t.has(s))return t.get(s);const a=r(o.map(l=>n(l)));return i&&t.set(s,a),a};return n(e)}function xt(...e){const t=We(),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);tt(s,l=>{n[i]=l,r=r|a,r===o&&De(t,n)})}),function(s,i){switch(s){case Er:{Li(t);return}case Fn:return r===o&&i(n),tt(t,i)}}}function Ee(e,t=qc){return U(e,at(t))}function $i(...e){return function(t,n){switch(t){case Er:return;case Fn:return Mx(...e.map(r=>tt(r,n)))}}}var $t=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))($t||{});const Bx={0:"debug",3:"error",1:"log",2:"warn"},Hx=()=>typeof globalThis>"u"?window:globalThis,zn=Xe(()=>{const e=J(3);return{log:J((t,n,r=1)=>{var o;const s=(o=Hx().VIRTUOSO_LOG_LEVEL)!=null?o:gt(e);r>=s&&console[Bx[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function ir(e,t,n){return Fi(e,t,n).callbackRef}function Fi(e,t,n){const r=w.useRef(null);let o=i=>{};const s=w.useMemo(()=>typeof ResizeObserver<"u"?new ResizeObserver(i=>{const a=()=>{const l=i[0].target;l.offsetParent!==null&&e(l)};n?a():requestAnimationFrame(a)}):null,[e,n]);return o=i=>{i&&t?(s==null||s.observe(i),r.current=i):(r.current&&(s==null||s.unobserve(r.current)),r.current=null)},{callbackRef:o,ref:r}}function Ux(e,t,n,r,o,s,i,a,l){const u=w.useCallback(d=>{const f=Wx(d.children,t,a?"offsetWidth":"offsetHeight",o);let h=d.parentElement;for(;!h.dataset.virtuosoScroller;)h=h.parentElement;const p=h.lastElementChild.dataset.viewportType==="window";let v;p&&(v=h.ownerDocument.defaultView);const x=i?a?i.scrollLeft:i.scrollTop:p?a?v.scrollX||v.document.documentElement.scrollLeft:v.scrollY||v.document.documentElement.scrollTop:a?h.scrollLeft:h.scrollTop,g=i?a?i.scrollWidth:i.scrollHeight:p?a?v.document.documentElement.scrollWidth:v.document.documentElement.scrollHeight:a?h.scrollWidth:h.scrollHeight,y=i?a?i.offsetWidth:i.offsetHeight:p?a?v.innerWidth:v.innerHeight:a?h.offsetWidth:h.offsetHeight;r({scrollHeight:g,scrollTop:Math.max(x,0),viewportHeight:y}),s==null||s(a?Gc("column-gap",getComputedStyle(d).columnGap,o):Gc("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return Fi(u,n,l)}function Wx(e,t,n,r){const o=e.length;if(o===0)return null;const s=[];for(let i=0;i<o;i++){const a=e.item(i);if(a.dataset.index===void 0)continue;const l=parseInt(a.dataset.index),u=parseFloat(a.dataset.knownSize),d=t(a,n);if(d===0&&r("Zero-sized element, this should not happen",{child:a},$t.ERROR),d===u)continue;const f=s[s.length-1];s.length===0||f.size!==d||f.endIndex!==l-1?s.push({endIndex:l,size:d,startIndex:l}):s[s.length-1].endIndex++}return s}function Gc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,$t.WARN),t==="normal"?0:parseInt(t??"0",10)}function Yc(e,t,n){const r=w.useRef(null),o=w.useCallback(l=>{if(!(l!=null&&l.offsetParent))return;const u=l.getBoundingClientRect(),d=u.width;let f,h;if(t){const p=t.getBoundingClientRect(),v=u.top-p.top;h=p.height-Math.max(0,v),f=v+t.scrollTop}else{const p=i.current.ownerDocument.defaultView;h=p.innerHeight-Math.max(0,u.top),f=u.top+p.scrollY}r.current={offsetTop:f,visibleHeight:h,visibleWidth:d},e(r.current)},[e,t]),{callbackRef:s,ref:i}=Fi(o,!0,n),a=w.useCallback(()=>{o(i.current)},[o,i]);return w.useEffect(()=>{var l;if(t){t.addEventListener("scroll",a);const u=new ResizeObserver(()=>{requestAnimationFrame(a)});return u.observe(t),()=>{t.removeEventListener("scroll",a),u.unobserve(t)}}else{const u=(l=i.current)==null?void 0:l.ownerDocument.defaultView;return u==null||u.addEventListener("scroll",a),u==null||u.addEventListener("resize",a),()=>{u==null||u.removeEventListener("scroll",a),u==null||u.removeEventListener("resize",a)}}},[a,t,i]),s}const Rt=Xe(()=>{const e=We(),t=We(),n=J(0),r=We(),o=J(0),s=We(),i=We(),a=J(0),l=J(0),u=J(0),d=J(0),f=We(),h=We(),p=J(!1),v=J(!1),x=J(!1);return xe(U(e,le(({scrollTop:g})=>g)),t),xe(U(e,le(({scrollHeight:g})=>g)),i),xe(t,o),{deviation:n,fixedFooterHeight:u,fixedHeaderHeight:l,footerHeight:d,headerHeight:a,horizontalDirection:v,scrollBy:h,scrollContainerState:e,scrollHeight:i,scrollingInProgress:p,scrollTo:f,scrollTop:t,skipAnimationFrameInResizeObserver:x,smoothScrollTargetReached:r,statefulScrollTop:o,viewportHeight:s}},[],{singleton:!0}),Jr={lvl:0};function Xc(e,t){const n=e.length;if(n===0)return[];let{index:r,value:o}=t(e[0]);const s=[];for(let i=1;i<n;i++){const{index:a,value:l}=t(e[i]);s.push({end:a-1,start:r,value:o}),r=a,o=l}return s.push({end:1/0,start:r,value:o}),s}function ot(e){return e===Jr}function Zr(e,t){if(!ot(e))return t===e.k?e.v:t<e.k?Zr(e.l,t):Zr(e.r,t)}function sn(e,t,n="k"){if(ot(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=sn(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return sn(e.l,t,n)}function Ut(e,t,n){return ot(e)?Qc(t,n,1):t===e.k?yt(e,{k:t,v:n}):t<e.k?eu(yt(e,{l:Ut(e.l,t,n)})):eu(yt(e,{r:Ut(e.r,t,n)}))}function Nr(){return Jr}function Yo(e,t,n){if(ot(e))return[];const r=sn(e,t)[0];return Vx(Bi(e,r,n))}function zi(e,t){if(ot(e))return Jr;const{k:n,l:r,r:o}=e;if(t===n){if(ot(r))return o;if(ot(o))return r;{const[s,i]=Zc(r);return Xo(yt(e,{k:s,l:Jc(r),v:i}))}}else return t<n?Xo(yt(e,{l:zi(r,t)})):Xo(yt(e,{r:zi(o,t)}))}function ar(e){return ot(e)?[]:[...ar(e.l),{k:e.k,v:e.v},...ar(e.r)]}function Bi(e,t,n){if(ot(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(Bi(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(Bi(s,t,n))),a}function Xo(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(Hi(t))return tu(yt(e,{lvl:n-1}));if(!ot(t)&&!ot(t.r))return yt(t.r,{l:yt(t,{r:t.r.l}),lvl:n,r:yt(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(Hi(e))return Ui(yt(e,{lvl:n-1}));if(!ot(r)&&!ot(r.l)){const o=r.l,s=Hi(o)?r.lvl-1:r.lvl;return yt(o,{l:yt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:Ui(yt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function yt(e,t){return Qc(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 Jc(e){return ot(e.r)?e.l:Xo(yt(e,{r:Jc(e.r)}))}function Hi(e){return ot(e)||e.lvl>e.r.lvl}function Zc(e){return ot(e.r)?[e.k,e.v]:Zc(e.r)}function Qc(e,t,n,r=Jr,o=Jr){return{k:e,l:r,lvl:n,r:o,v:t}}function eu(e){return Ui(tu(e))}function tu(e){const{l:t}=e;return!ot(t)&&t.lvl===e.lvl?yt(t,{r:yt(e,{l:t.r})}):e}function Ui(e){const{lvl:t,r:n}=e;return!ot(n)&&!ot(n.r)&&n.lvl===t&&n.r.lvl===t?yt(n,{l:yt(e,{r:n.l}),lvl:t+1}):e}function Vx(e){return Xc(e,({k:t,v:n})=>({index:t,value:n}))}function nu(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function Qr(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const Wi=Xe(()=>({recalcInProgress:J(!1)}),[],{singleton:!0});function ru(e,t,n){return e[Jo(e,t,n)]}function Jo(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 Kx(e,t,n,r){const o=Jo(e,t,r),s=Jo(e,n,r,o);return e.slice(o,s+1)}function Bn(e,t){return Math.round(e.getBoundingClientRect()[t])}function Zo(e){return!ot(e.groupOffsetTree)}function Vi({index:e},t){return t===e?0:t<e?-1:1}function qx(){return{groupIndices:[],groupOffsetTree:Nr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:Nr()}}function Gx(e,t){let n=ot(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),ot(e)){e=Ut(e,0,s);continue}const a=Yo(e,i-1,o+1);if(a.some(ty(r)))continue;let l=!1,u=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=zi(e,f)):(u=h!==s,l=!0),d>o&&o>=f&&h!==s&&(e=Ut(e,o+1,h));u&&(e=Ut(e,i,s))}return[e,n]}function Yx(e){return typeof e.groupIndex<"u"}function Xx({offset:e},t){return t===e?0:t<e?-1:1}function eo(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=ru(t,e,Vi),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function ou(e,t){if(!Zo(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function su(e,t,n){if(Yx(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=ou(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function Jx(e,t,n,r=0){return r>0&&(t=Math.max(t,ru(e,r,Vi).offset)),Xc(Kx(e,t,n,Xx),ey)}function Zx(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,$t.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&ot(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((v,x)=>Ut(Ut(v,x,h),x+1,p),i)}else[i,a]=Gx(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f}=Ki(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>Ut(h,p,eo(p,f,o)),Nr()),lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f,sizeTree:i}}function Qx(e){return ar(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 iu(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 Ki(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=Jo(o,t-1,Vi),a=o[l].offset;const u=sn(n,t-1);s=u[0],i=u[1],o.length&&o[l].size===sn(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:u,value:d}of Yo(n,t,1/0)){const f=u-s,h=f*i+a+f*r;o.push({index:u,offset:h,size:d}),s=u,a=h,i=d}return{lastIndex:s,lastOffset:a,lastSize:i,offsetTree:o}}function ey(e){return{index:e.index,value:e}}function ty(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 ny={offsetHeight:"height",offsetWidth:"width"},xn=Xe(([{log:e},{recalcInProgress:t}])=>{const n=We(),r=We(),o=Nt(r,0),s=We(),i=We(),a=J(0),l=J([]),u=J(void 0),d=J(void 0),f=J((C,T)=>Bn(C,ny[T])),h=J(void 0),p=J(0),v=qx(),x=Nt(U(n,$e(l,e,p),gn(Zx,v),at()),v),g=Nt(U(l,at(),gn((C,T)=>({current:T,prev:C.current}),{current:[],prev:[]}),le(({prev:C})=>C)),[]);xe(U(l,Ne(C=>C.length>0),$e(x,p),le(([C,T,E])=>{const A=C.reduce((j,P,D)=>Ut(j,P,eo(P,T.offsetTree,E)||D),Nr());return{...T,groupIndices:C,groupOffsetTree:A}})),x),xe(U(r,$e(x),Ne(([C,{lastIndex:T}])=>C<T),le(([C,{lastIndex:T,lastSize:E}])=>[{endIndex:T,size:E,startIndex:C}])),n),xe(u,d);const y=Nt(U(u,le(C=>C===void 0)),!0);xe(U(d,Ne(C=>C!==void 0&&ot(gt(x).sizeTree)),le(C=>[{endIndex:0,size:C,startIndex:0}])),n);const b=Ht(U(n,$e(x),gn(({sizes:C},[T,E])=>({changed:E!==C,sizes:E}),{changed:!1,sizes:v}),le(C=>C.changed)));tt(U(a,gn((C,T)=>({diff:C.prev-T,prev:T}),{diff:0,prev:0}),le(C=>C.diff)),C=>{const{groupIndices:T}=gt(x);if(C>0)De(t,!0),De(s,C+iu(C,T));else if(C<0){const E=gt(g);E.length>0&&(C-=iu(-C,E)),De(i,C)}}),tt(U(a,$e(e)),([C,T])=>{C<0&&T("`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},$t.ERROR)});const S=Ht(s);xe(U(s,$e(x),le(([C,T])=>{const E=T.groupIndices.length>0,A=[],j=T.lastSize;if(E){const P=Zr(T.sizeTree,0);let D=0,L=0;for(;D<C;){const M=T.groupIndices[L],X=T.groupIndices.length===L+1?1/0:T.groupIndices[L+1]-M-1;A.push({endIndex:M,size:P,startIndex:M}),A.push({endIndex:M+1+X-1,size:j,startIndex:M+1}),L++,D+=X+1}const V=ar(T.sizeTree);return D!==C&&V.shift(),V.reduce((M,{k:X,v:K})=>{let q=M.ranges;return M.prevSize!==0&&(q=[...M.ranges,{endIndex:X+C-1,size:M.prevSize,startIndex:M.prevIndex}]),{prevIndex:X+C,prevSize:K,ranges:q}},{prevIndex:C,prevSize:0,ranges:A}).ranges}return ar(T.sizeTree).reduce((P,{k:D,v:L})=>({prevIndex:D+C,prevSize:L,ranges:[...P.ranges,{endIndex:D+C-1,size:P.prevSize,startIndex:P.prevIndex}]}),{prevIndex:0,prevSize:j,ranges:[]}).ranges})),n);const I=Ht(U(i,$e(x,p),le(([C,{offsetTree:T},E])=>{const A=-C;return eo(A,T,E)})));return xe(U(i,$e(x,p),le(([C,T,E])=>{if(T.groupIndices.length>0){if(ot(T.sizeTree))return T;let A=Nr();const j=gt(g);let P=0,D=0,L=0;for(;P<-C;){L=j[D];const V=j[D+1]-L-1;D++,P+=V+1}if(A=ar(T.sizeTree).reduce((V,{k:M,v:X})=>Ut(V,Math.max(0,M+C),X),A),P!==-C){const V=Zr(T.sizeTree,L);A=Ut(A,0,V);const M=sn(T.sizeTree,-C+1)[1];A=Ut(A,1,M)}return{...T,sizeTree:A,...Ki(T.offsetTree,0,A,E)}}else{const A=ar(T.sizeTree).reduce((j,{k:P,v:D})=>Ut(j,Math.max(0,P+C),D),Nr());return{...T,sizeTree:A,...Ki(T.offsetTree,0,A,E)}}})),x),{beforeUnshiftWith:S,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:u,gap:p,groupIndices:l,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:I,sizeRanges:n,sizes:x,statefulTotalCount:o,totalCount:r,trackItemSizes:y,unshiftWith:s}},it(zn,Wi),{singleton:!0});function ry(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const au=Xe(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=We(),i=We(),a=Ht(U(s,le(ry)));return xe(U(a,le(l=>l.totalCount)),n),xe(U(a,le(l=>l.groupIndices)),e),xe(U(xt(o,t,r),Ne(([l,u])=>Zo(u)),le(([l,u,d])=>sn(u.groupOffsetTree,Math.max(l-d,0),"v")[0]),at(),le(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},it(xn,Rt)),Hn=Xe(([{log:e}])=>{const t=J(!1),n=Ht(U(t,Ne(r=>r),at()));return tt(t,r=>{r&>(e)("props updated",{},$t.DEBUG)}),{didMount:n,propsReady:t}},it(zn),{singleton:!0}),oy=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function lu(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!oy)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const to=Xe(([{gap:e,listRefresh:t,sizes:n,totalCount:r},{fixedFooterHeight:o,fixedHeaderHeight:s,footerHeight:i,headerHeight:a,scrollingInProgress:l,scrollTo:u,smoothScrollTargetReached:d,viewportHeight:f},{log:h}])=>{const p=We(),v=We(),x=J(0);let g=null,y=null,b=null;function S(){g&&(g(),g=null),b&&(b(),b=null),y&&(clearTimeout(y),y=null),De(l,!1)}return xe(U(p,$e(n,f,r,x,a,i,h),$e(e,s,o),le(([[I,C,T,E,A,j,P,D],L,V,M])=>{const X=lu(I),{align:K,behavior:q,offset:z}=X,$=E-1,pe=su(X,C,$);let F=eo(pe,C.offsetTree,L)+j;K==="end"?(F+=V+sn(C.sizeTree,pe)[1]-T+M,pe===$&&(F+=P)):K==="center"?F+=(V+sn(C.sizeTree,pe)[1]-T+M)/2:F-=A,z&&(F+=z);const te=fe=>{S(),fe?(D("retrying to scroll to",{location:I},$t.DEBUG),De(p,I)):(De(v,!0),D("list did not change, scroll successful",{},$t.DEBUG))};if(S(),q==="smooth"){let fe=!1;b=tt(t,ge=>{fe=fe||ge}),g=on(d,()=>{te(fe)})}else g=on(U(t,sy(150)),te);return y=setTimeout(()=>{S()},1200),De(l,!0),D("scrolling from index to",{behavior:q,index:pe,top:F},$t.DEBUG),{behavior:q,top:F}})),u),{scrollTargetReached:v,scrollToIndex:p,topListHeight:x}},it(xn,Rt,zn),{singleton:!0});function sy(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function qi(e,t){e==0?t():requestAnimationFrame(()=>{qi(e-1,t)})}function Gi(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const no=Xe(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=J(!0),l=J(0),u=J(!0);return xe(U(i,$e(l),Ne(([d,f])=>!!f),mn(!1)),a),xe(U(i,$e(l),Ne(([d,f])=>!!f),mn(!1)),u),tt(U(xt(t,i),$e(a,n,e,u),Ne(([[,d],f,{sizeTree:h},p,v])=>d&&(!ot(h)||Di(p))&&!f&&!v),$e(l)),([,d])=>{on(o,()=>{De(u,!0)}),qi(4,()=>{on(r,()=>{De(a,!0)}),De(s,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:l,scrolledToInitialItem:a}},it(xn,Rt,to,Hn),{singleton:!0});function cu(e,t){return Math.abs(e-t)<1.01}const ro="up",oo="down",iy="none",ay={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},ly=0,so=Xe(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=J(!1),a=J(!0),l=We(),u=We(),d=J(4),f=J(ly),h=Nt(U($i(U(Ee(o),sr(1),mn(!0)),U(Ee(o),sr(1),mn(!1),Kc(100))),at()),!1),p=Nt(U($i(U(n,mn(!0)),U(n,mn(!1),Kc(200))),at()),!1);xe(U(xt(Ee(o),Ee(f)),le(([b,S])=>b<=S),at()),a),xe(U(a,Rn(50)),u);const v=Ht(U(xt(r,Ee(s),Ee(t),Ee(e),Ee(d)),gn((b,[{scrollHeight:S,scrollTop:I},C,T,E,A])=>{const j=I+C-S>-A,P={scrollHeight:S,scrollTop:I,viewportHeight:C};if(j){let L,V;return I>b.state.scrollTop?(L="SCROLLED_DOWN",V=b.state.scrollTop-I):(L="SIZE_DECREASED",V=b.state.scrollTop-I||b.scrollTopDelta),{atBottom:!0,atBottomBecause:L,scrollTopDelta:V,state:P}}let D;return P.scrollHeight>b.state.scrollHeight?D="SIZE_INCREASED":C<b.state.viewportHeight?D="VIEWPORT_HEIGHT_DECREASING":I<b.state.scrollTop?D="SCROLLING_UPWARDS":D="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:D,state:P}},ay),at((b,S)=>b&&b.atBottom===S.atBottom))),x=Nt(U(r,gn((b,{scrollHeight:S,scrollTop:I,viewportHeight:C})=>{if(cu(b.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:I};{const T=S-(I+C)<1;return b.scrollTop!==I&&T?{changed:!0,jump:b.scrollTop-I,scrollHeight:S,scrollTop:I}:{changed:!0,jump:0,scrollHeight:S,scrollTop:I}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),Ne(b=>b.changed),le(b=>b.jump)),0);xe(U(v,le(b=>b.atBottom)),i),xe(U(i,Rn(50)),l);const g=J(oo);xe(U(r,le(({scrollTop:b})=>b),at(),gn((b,S)=>gt(p)?{direction:b.direction,prevScrollTop:S}:{direction:S<b.prevScrollTop?ro:oo,prevScrollTop:S},{direction:oo,prevScrollTop:0}),le(b=>b.direction)),g),xe(U(r,Rn(50),mn(iy)),g);const y=J(0);return xe(U(h,Ne(b=>!b),mn(0)),y),xe(U(o,Rn(100),$e(h),Ne(([b,S])=>!!S),gn(([b,S],[I])=>[S,I],[0,0]),le(([b,S])=>S-b)),y),{atBottomState:v,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:u,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:x,scrollDirection:g,scrollVelocity:y}},it(Rt)),Qo="top",es="bottom",uu="none";function du(e,t,n){return typeof e=="number"?n===ro&&t===Qo||n===oo&&t===es?e:0:n===ro?t===Qo?e.main:e.reverse:t===es?e.main:e.reverse}function fu(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const Yi=Xe(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=We(),i=J(0),a=J(0),l=J(0),u=Nt(U(xt(Ee(r),Ee(o),Ee(n),Ee(s,Qr),Ee(l),Ee(i),Ee(t),Ee(e),Ee(a)),le(([d,f,h,[p,v],x,g,y,b,S])=>{const I=d-b,C=g+y,T=Math.max(h-I,0);let E=uu;const A=fu(S,Qo),j=fu(S,es);return p-=b,p+=h+y,v+=h+y,v-=b,p>d+C-A&&(E=ro),v<d-T+f+j&&(E=oo),E!==uu?[Math.max(I-h-du(x,Qo,E)-A,0),I-T-y+f+du(x,es,E)+j]:null}),Ne(d=>d!=null),at(Qr)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:u}},it(Rt),{singleton:!0});function cy(e,t,n){if(Zo(t)){const r=ou(e,t);return[{index:sn(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 Xi={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function ts(e,t,n,r,o,s){const{lastIndex:i,lastOffset:a,lastSize:l}=o;let u=0,d=0;if(e.length>0){u=e[0].offset;const x=e[e.length-1];d=x.offset+x.size}const f=n-i,h=a+f*l+(f-1)*r,p=u,v=h-d;return{bottom:d,firstItemIndex:s,items:pu(e,o,s),offsetBottom:v,offsetTop:u,top:p,topItems:pu(t,o,s),topListHeight:t.reduce((x,g)=>g.size+x,0),totalCount:n}}function hu(e,t,n,r,o,s){let i=0;if(n.groupIndices.length>0)for(const d of n.groupIndices){if(d-i>=e)break;i++}const a=e+i,l=Gi(t,a),u=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return ts(u,[],a,o,n,r)}function pu(e,t,n){if(e.length===0)return[];if(!Zo(t))return e.map(u=>({...u,index:u.index+n,originalIndex:u.index}));const r=e[0].index,o=e[e.length-1].index,s=[],i=Yo(t.groupOffsetTree,r,o);let a,l=0;for(const u of e){(!a||a.end<u.index)&&(a=i.shift(),l=t.groupIndices.indexOf(a.start));let d;u.index===a.start?d={index:l,type:"group"}:d={groupIndex:l,index:u.index-(l+1)+n},s.push({...d,data:u.data,offset:u.offset,originalIndex:u.index,size:u.size})}return s}const lr=Xe(([{data:e,firstItemIndex:t,gap:n,sizes:r,totalCount:o},s,{listBoundary:i,topListHeight:a,visibleRange:l},{initialTopMostItemIndex:u,scrolledToInitialItem:d},{topListHeight:f},h,{didMount:p},{recalcInProgress:v}])=>{const x=J([]),g=J(0),y=We();xe(s.topItemsIndexes,x);const b=Nt(U(xt(p,v,Ee(l,Qr),Ee(o),Ee(r),Ee(u),d,Ee(x),Ee(t),Ee(n),e),Ne(([T,E,,A,,,,,,,j])=>{const P=j&&j.length!==A;return T&&!E&&!P}),le(([,,[T,E],A,j,P,D,L,V,M,X])=>{const K=j,{offsetTree:q,sizeTree:z}=K,$=gt(g);if(A===0)return{...Xi,totalCount:A};if(T===0&&E===0)return $===0?{...Xi,totalCount:A}:hu($,P,j,V,M,X||[]);if(ot(z))return $>0?null:ts(cy(Gi(P,A),K,X),[],A,M,K,V);const pe=[];if(L.length>0){const be=L[0],Te=L[L.length-1];let G=0;for(const O of Yo(z,be,Te)){const Q=O.value,ne=Math.max(O.start,be),de=Math.min(O.end,Te);for(let ae=ne;ae<=de;ae++)pe.push({data:X==null?void 0:X[ae],index:ae,offset:G,size:Q}),G+=Q}}if(!D)return ts([],pe,A,M,K,V);const F=L.length>0?L[L.length-1]+1:0,te=Jx(q,T,E,F);if(te.length===0)return null;const fe=A-1,ge=Go([],be=>{for(const Te of te){const G=Te.value;let O=G.offset,Q=Te.start;const ne=G.size;if(G.offset<T){Q+=Math.floor((T-G.offset+M)/(ne+M));const ae=Q-Te.start;O+=ae*ne+ae*M}Q<F&&(O+=(F-Q)*ne,Q=F);const de=Math.min(Te.end,fe);for(let ae=Q;ae<=de&&!(O>=E);ae++)be.push({data:X==null?void 0:X[ae],index:ae,offset:O,size:ne}),O+=ne+M}});return ts(ge,pe,A,M,K,V)}),Ne(T=>T!==null),at()),Xi);xe(U(e,Ne(Di),le(T=>T==null?void 0:T.length)),o),xe(U(b,le(T=>T.topListHeight)),f),xe(f,a),xe(U(b,le(T=>[T.top,T.bottom])),i),xe(U(b,le(T=>T.items)),y);const S=Ht(U(b,Ne(({items:T})=>T.length>0),$e(o,e),Ne(([{items:T},E])=>T[T.length-1].originalIndex===E-1),le(([,T,E])=>[T-1,E]),at(Qr),le(([T])=>T))),I=Ht(U(b,Rn(200),Ne(({items:T,topItems:E})=>T.length>0&&T[0].originalIndex===E.length),le(({items:T})=>T[0].index),at())),C=Ht(U(b,Ne(({items:T})=>T.length>0),le(({items:T})=>{let E=0,A=T.length-1;for(;T[E].type==="group"&&E<A;)E++;for(;T[A].type==="group"&&A>E;)A--;return{endIndex:T[A].index,startIndex:T[E].index}}),at(nu)));return{endReached:S,initialItemCount:g,itemsRendered:y,listState:b,rangeChanged:C,startReached:I,topItemsIndexes:x,...h}},it(xn,au,Yi,no,to,so,Hn,Wi),{singleton:!0}),mu=Xe(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=We(),i=Nt(U(xt(n,e,r,t,o),le(([a,l,u,d,f])=>a+l+u+d+f.offsetBottom+f.bottom)),0);return xe(Ee(i),s),{totalListHeight:i,totalListHeightChanged:s}},it(Rt,lr),{singleton:!0}),uy=Xe(([{viewportHeight:e},{totalListHeight:t}])=>{const n=J(!1),r=Nt(U(xt(n,e,t),Ne(([o])=>o),le(([,o,s])=>Math.max(0,o-s)),Rn(0),at()),0);return{alignToBottom:n,paddingTopAddition:r}},it(Rt,mu),{singleton:!0}),gu=Xe(()=>({context:J(null)})),dy=({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,xu=Xe(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:u}])=>{const d=We();return xe(U(d,$e(t,l,n,s,o,r,a),$e(e),le(([[f,h,p,v,x,g,y,b],S])=>{const{align:I,behavior:C,calculateViewLocation:T=dy,done:E,...A}=f,j=su(f,h,v-1),P=eo(j,h.offsetTree,S)+x+g,D=P+sn(h.sizeTree,j)[1],L=b+g,V=b+p-y,M=T({itemBottom:D,itemTop:P,locationParams:{align:I,behavior:C,...A},viewportBottom:V,viewportTop:L});return M?E&&on(U(i,Ne(X=>!X),sr(gt(i)?1:2)),E):E&&E(),M}),Ne(f=>f!==null)),u),{scrollIntoView:d}},it(xn,Rt,to,lr,zn),{singleton:!0});function yu(e){return e?e==="smooth"?"smooth":"auto":!1}const fy=(e,t)=>typeof e=="function"?yu(e(t)):t&&yu(e),hy=Xe(([{listRefresh:e,totalCount:t,fixedItemSize:n,data:r},{atBottomState:o,isAtBottom:s},{scrollToIndex:i},{scrolledToInitialItem:a},{didMount:l,propsReady:u},{log:d},{scrollingInProgress:f},{context:h},{scrollIntoView:p}])=>{const v=J(!1),x=We();let g=null;function y(C){De(i,{align:"end",behavior:C,index:"LAST"})}tt(U(xt(U(Ee(t),sr(1)),l),$e(Ee(v),s,a,f),le(([[C,T],E,A,j,P])=>{let D=T&&j,L="auto";return D&&(L=fy(E,A||P),D=D&&!!L),{followOutputBehavior:L,shouldFollow:D,totalCount:C}}),Ne(({shouldFollow:C})=>C)),({followOutputBehavior:C,totalCount:T})=>{g&&(g(),g=null),gt(n)?requestAnimationFrame(()=>{gt(d)("following output to ",{totalCount:T},$t.DEBUG),y(C)}):g=on(e,()=>{gt(d)("following output to ",{totalCount:T},$t.DEBUG),y(C),g=null})});function b(C){const T=on(o,E=>{C&&!E.atBottom&&E.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(gt(d)("scrolling to bottom due to increased size",{},$t.DEBUG),y("auto"))});setTimeout(T,100)}tt(U(xt(Ee(v),t,u),Ne(([C,,T])=>C&&T),gn(({value:C},[,T])=>({refreshed:C===T,value:T}),{refreshed:!1,value:0}),Ne(({refreshed:C})=>C),$e(v,t)),([,C])=>{gt(a)&&b(C!==!1)}),tt(x,()=>{b(gt(v)!==!1)}),tt(xt(Ee(v),o),([C,T])=>{C&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&y("auto")});const S=J(null),I=We();return xe($i(U(Ee(r),le(C=>{var T;return(T=C==null?void 0:C.length)!=null?T:0})),U(Ee(t))),I),tt(U(xt(U(I,sr(1)),l),$e(Ee(S),a,f,h),le(([[C,T],E,A,j,P])=>T&&A&&(E==null?void 0:E({context:P,totalCount:C,scrollingInProgress:j}))),Ne(C=>!!C),Rn(0)),C=>{g&&(g(),g=null),gt(n)?requestAnimationFrame(()=>{gt(d)("scrolling into view",{}),De(p,C)}):g=on(e,()=>{gt(d)("scrolling into view",{}),De(p,C),g=null})}),{autoscrollToBottom:x,followOutput:v,scrollIntoViewOnChange:S}},it(xn,so,to,no,Hn,zn,Rt,gu,xu)),py=Xe(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(xe(U(a,$e(s),Ne(([,l])=>l!==0),$e(o,r,t,n,e),le(([[,l],u,d,f,h,p=[]])=>hu(l,u,d,f,h,p))),i),{}),it(xn,no,lr,Hn),{singleton:!0}),my=Xe(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=J(0);return tt(U(e,$e(r),Ne(([,o])=>o!==0),le(([,o])=>({top:o}))),o=>{on(U(n,sr(1),Ne(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{De(t,o)})})}),{initialScrollTop:r}},it(Hn,Rt,lr),{singleton:!0}),vu=Xe(([{scrollVelocity:e}])=>{const t=J(!1),n=We(),r=J(!1);return xe(U(e,$e(r,t,n),Ne(([o,s])=>!!s),le(([o,s,i,a])=>{const{enter:l,exit:u}=s;if(i){if(u(o,a))return!1}else if(l(o,a))return!0;return i}),at()),t),tt(U(xt(t,e,n),$e(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},it(so),{singleton:!0}),Ji=Xe(([{scrollContainerState:e,scrollTo:t}])=>{const n=We(),r=We(),o=We(),s=J(!1),i=J(void 0);return xe(U(xt(n,r),le(([{scrollHeight:a,scrollTop:l,viewportHeight:u},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:u}))),e),xe(U(t,$e(r),le(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},it(Rt)),gy=Xe(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const u=We(),d=J(void 0),f=J(null),h=J(null);return xe(a,f),xe(l,h),tt(U(u,$e(t,r,i,f,h,n)),([p,v,x,g,y,b,S])=>{const I=Qx(v.sizeTree);g&&y!==null&&b!==null&&(x=y.scrollTop-b.offsetTop),x-=S,p({ranges:I,scrollTop:x})}),xe(U(d,Ne(Di),le(xy)),o),xe(U(s,$e(d),Ne(([,p])=>p!==void 0),at(),le(([,p])=>p.ranges)),e),{getState:u,restoreStateFrom:d}},it(xn,Rt,no,Hn,Ji));function xy(e){return{align:"start",index:0,offset:e.scrollTop}}const yy=Xe(([{topItemsIndexes:e}])=>{const t=J(0);return xe(U(t,Ne(n=>n>=0),le(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},it(lr));function bu(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const vy=bu(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),by=Xe(([{deviation:e,scrollBy:t,scrollingInProgress:n,scrollTop:r},{isAtBottom:o,isScrolling:s,lastJumpDueToItemResize:i,scrollDirection:a},{listState:l},{beforeUnshiftWith:u,gap:d,shiftWithOffset:f,sizes:h},{log:p},{recalcInProgress:v}])=>{const x=Ht(U(l,$e(i),gn(([,y,b,S],[{bottom:I,items:C,offsetBottom:T,totalCount:E},A])=>{const j=I+T;let P=0;return b===E&&y.length>0&&C.length>0&&(C[0].originalIndex===0&&y[0].originalIndex===0||(P=j-S,P!==0&&(P+=A))),[P,C,E,j]},[0,[],0,0]),Ne(([y])=>y!==0),$e(r,a,n,o,p,v),Ne(([,y,b,S,,,I])=>!I&&!S&&y!==0&&b===ro),le(([[y],,,,,b])=>(b("Upward scrolling compensation",{amount:y},$t.DEBUG),y))));function g(y){y>0?(De(t,{behavior:"auto",top:-y}),De(e,0)):(De(e,0),De(t,{behavior:"auto",top:-y}))}return tt(U(x,$e(e,s)),([y,b,S])=>{S&&vy()?De(e,b-y):g(-y)}),tt(U(xt(Nt(s,!1),e,v),Ne(([y,b,S])=>!y&&!S&&b!==0),le(([y,b])=>b),Rn(1)),g),xe(U(f,le(y=>({top:-y}))),t),tt(U(u,$e(h,d),le(([y,{groupIndices:b,lastSize:S,sizeTree:I},C])=>{function T(E){return E*(S+C)}if(b.length===0)return T(y);{let E=0;const A=Zr(I,0);let j=0,P=0;for(;j<y;){j++,E+=A;let D=b.length===P+1?1/0:b[P+1]-b[P]-1;j+D>y&&(E-=A,D=y-j+1),j+=D,E+=T(D),P++}return E}})),y=>{De(e,y),requestAnimationFrame(()=>{De(t,{top:y}),requestAnimationFrame(()=>{De(e,0),De(v,!1)})})}),{deviation:e}},it(Rt,so,lr,xn,zn,Wi)),wy=Xe(([e,t,n,r,o,s,i,a,l,u,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...u,...d}),it(Yi,py,Hn,vu,mu,my,uy,Ji,xu,zn,gu)),wu=Xe(([{data:e,defaultItemSize:t,firstItemIndex:n,fixedItemSize:r,gap:o,groupIndices:s,itemSize:i,sizeRanges:a,sizes:l,statefulTotalCount:u,totalCount:d,trackItemSizes:f},{initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:v},x,g,y,{listState:b,topItemsIndexes:S,...I},{scrollToIndex:C},T,{topItemCount:E},{groupCounts:A},j])=>(xe(I.rangeChanged,j.scrollSeekRangeChanged),xe(U(j.windowViewportRect,le(P=>P.visibleHeight)),x.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:A,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:v,sizeRanges:a,topItemCount:E,topItemsIndexes:S,totalCount:d,...y,groupIndices:s,itemSize:i,listState:b,scrollToIndex:C,statefulTotalCount:u,trackItemSizes:f,...I,...j,...x,sizes:l,...g}),it(xn,no,Rt,gy,hy,lr,to,by,yy,au,wy));function Sy(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 ns=typeof document<"u"?w.useLayoutEffect:w.useEffect;function Su(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=w.createContext({});function l(g,y){g.propsReady&&De(g.propsReady,!1);for(const b of r){const S=g[t.required[b]];De(S,y[b])}for(const b of o)if(b in y){const S=g[t.optional[b]];De(S,y[b])}g.propsReady&&De(g.propsReady,!0)}function u(g){return s.reduce((y,b)=>(y[b]=S=>{const I=g[t.methods[b]];De(I,S)},y),{})}function d(g){return i.reduce((y,b)=>(y[b]=$x(g[t.events[b]]),y),{})}const f=w.forwardRef((g,y)=>{const{children:b,...S}=g,[I]=w.useState(()=>Go(zx(e),E=>{l(E,S)})),[C]=w.useState(Vc(d,I));ns(()=>{for(const E of i)E in S&&tt(C[E],S[E]);return()=>{Object.values(C).map(Li)}},[S,C,I]),ns(()=>{l(I,S)}),w.useImperativeHandle(y,Uc(u(I)));const T=n;return c.jsx(a.Provider,{value:I,children:n?c.jsx(T,{...Sy([...r,...o,...i],S),children:b}):b})}),h=g=>{const y=w.useContext(a);return w.useCallback(b=>{De(y[g],b)},[y,g])},p=g=>{const y=w.useContext(a)[g],b=w.useCallback(S=>tt(y,S),[y]);return w.useSyncExternalStore(b,()=>gt(y),()=>gt(y))},v=g=>{const y=w.useContext(a)[g],[b,S]=w.useState(Vc(gt,y));return ns(()=>tt(y,I=>{I!==b&&S(Uc(I))}),[y,b]),b},x=w.version.startsWith("18")?p:v;return{Component:f,useEmitter:(g,y)=>{const b=w.useContext(a)[g];ns(()=>tt(b,y),[y,b])},useEmitterValue:x,usePublisher:h}}const Cu=w.createContext(void 0),Tu=w.createContext(void 0),ku=typeof document<"u"?w.useLayoutEffect:w.useEffect;function Zi(e){return"self"in e}function Cy(e){return"body"in e}function Eu(e,t,n,r=Ir,o,s){const i=w.useRef(null),a=w.useRef(null),l=w.useRef(null),u=w.useCallback(h=>{let p,v,x;const g=h.target;if(Cy(g)||Zi(g)){const b=Zi(g)?g:g.defaultView;x=s?b.scrollX:b.scrollY,p=s?b.document.documentElement.scrollWidth:b.document.documentElement.scrollHeight,v=s?b.innerWidth:b.innerHeight}else x=s?g.scrollLeft:g.scrollTop,p=s?g.scrollWidth:g.scrollHeight,v=s?g.offsetWidth:g.offsetHeight;const y=()=>{e({scrollHeight:p,scrollTop:Math.max(x,0),viewportHeight:v})};h.suppressFlushSync?y():ui.flushSync(y),a.current!==null&&(x===a.current||x<=0||x===p-v)&&(a.current=null,t(!0),l.current&&(clearTimeout(l.current),l.current=null))},[e,t,s]);w.useEffect(()=>{const h=o||i.current;return r(o||i.current),u({suppressFlushSync:!0,target:h}),h.addEventListener("scroll",u,{passive:!0}),()=>{r(null),h.removeEventListener("scroll",u)}},[i,u,n,r,o]);function d(h){const p=i.current;if(!p||(s?"offsetWidth"in p&&p.offsetWidth===0:"offsetHeight"in p&&p.offsetHeight===0))return;const v=h.behavior==="smooth";let x,g,y;Zi(p)?(g=Math.max(Bn(p.document.documentElement,s?"width":"height"),s?p.document.documentElement.scrollWidth:p.document.documentElement.scrollHeight),x=s?p.innerWidth:p.innerHeight,y=s?window.scrollX:window.scrollY):(g=p[s?"scrollWidth":"scrollHeight"],x=Bn(p,s?"width":"height"),y=p[s?"scrollLeft":"scrollTop"]);const b=g-x;if(h.top=Math.ceil(Math.max(Math.min(b,h.top),0)),cu(x,g)||h.top===y){e({scrollHeight:g,scrollTop:y,viewportHeight:x}),v&&t(!0);return}v?(a.current=h.top,l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{l.current=null,a.current=null,t(!0)},1e3)):a.current=null,s&&(h={behavior:h.behavior,left:h.top}),p.scrollTo(h)}function f(h){s&&(h={behavior:h.behavior,left:h.top}),i.current.scrollBy(h)}return{scrollByCallback:f,scrollerRef:i,scrollToCallback:d}}const Qi="-webkit-sticky",Iu="sticky",ea=bu(()=>{if(typeof document>"u")return Iu;const e=document.createElement("div");return e.style.position=Qi,e.style.position===Qi?Qi:Iu});function ta(e){return e}const Ty=Xe(()=>{const e=J(a=>`Item ${a}`),t=J(a=>`Group ${a}`),n=J({}),r=J(ta),o=J("div"),s=J(Ir),i=(a,l=null)=>Nt(U(n,le(u=>u[a]),at()),l);return{components:n,computeItemKey:r,EmptyPlaceholder:i("EmptyPlaceholder"),FooterComponent:i("Footer"),GroupComponent:i("Group","div"),groupContent:t,HeaderComponent:i("Header"),HeaderFooterTag:o,ItemComponent:i("Item","div"),itemContent:e,ListComponent:i("List","div"),ScrollerComponent:i("Scroller","div"),scrollerRef:s,ScrollSeekPlaceholder:i("ScrollSeekPlaceholder"),TopItemListComponent:i("TopItemList")}}),ky=Xe(([e,t])=>({...e,...t}),it(wu,Ty)),Ey=({height:e})=>c.jsx("div",{style:{height:e}}),Iy={overflowAnchor:"none",position:ea(),zIndex:1},Nu={overflowAnchor:"none"},Ny={...Nu,display:"inline-block",height:"100%"},Au=w.memo(function({showTopList:e=!1}){const t=Re("listState"),n=Yt("sizeRanges"),r=Re("useWindowScroll"),o=Re("customScrollParent"),s=Yt("windowScrollContainerState"),i=Yt("scrollContainerState"),a=o||r?s:i,l=Re("itemContent"),u=Re("context"),d=Re("groupContent"),f=Re("trackItemSizes"),h=Re("itemSize"),p=Re("log"),v=Yt("gap"),x=Re("horizontalDirection"),{callbackRef:g}=Ux(n,h,f,e?Ir:a,p,v,o,x,Re("skipAnimationFrameInResizeObserver")),[y,b]=w.useState(0);na("deviation",M=>{y!==M&&b(M)});const S=Re("EmptyPlaceholder"),I=Re("ScrollSeekPlaceholder")||Ey,C=Re("ListComponent"),T=Re("ItemComponent"),E=Re("GroupComponent"),A=Re("computeItemKey"),j=Re("isSeeking"),P=Re("groupIndices").length>0,D=Re("alignToBottom"),L=Re("initialItemFinalLocationReached"),V=e?{}:{boxSizing:"border-box",...x?{display:"inline-block",height:"100%",marginLeft:y!==0?y:D?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:y!==0?y:D?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...L?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?c.jsx(S,{...At(S,u)}):c.jsx(C,{...At(C,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:g,style:V,children:(e?t.topItems:t.items).map(M=>{const X=M.originalIndex,K=A(X+t.firstItemIndex,M.data,u);return j?w.createElement(I,{...At(I,u),height:M.size,index:M.index,key:K,type:M.type||"item",...M.type==="group"?{}:{groupIndex:M.groupIndex}}):M.type==="group"?w.createElement(E,{...At(E,u),"data-index":X,"data-item-index":M.index,"data-known-size":M.size,key:K,style:Iy},d(M.index,u)):w.createElement(T,{...At(T,u),...Ry(T,M.data),"data-index":X,"data-item-group-index":M.groupIndex,"data-item-index":M.index,"data-known-size":M.size,key:K,style:x?Ny:Nu},P?l(M.index,M.groupIndex,M.data,u):l(M.index,M.data,u))})})}),Ay={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},_y={outline:"none",overflowX:"auto",position:"relative"},rs=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),jy={position:ea(),top:0,width:"100%",zIndex:1};function At(e,t){if(typeof e!="string")return{context:t}}function Ry(e,t){return{item:typeof e=="string"?void 0:t}}const Py=w.memo(function(){const e=Re("HeaderComponent"),t=Yt("headerHeight"),n=Re("HeaderFooterTag"),r=ir(w.useMemo(()=>s=>{t(Bn(s,"height"))},[t]),!0,Re("skipAnimationFrameInResizeObserver")),o=Re("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...At(e,o)})}):null}),Oy=w.memo(function(){const e=Re("FooterComponent"),t=Yt("footerHeight"),n=Re("HeaderFooterTag"),r=ir(w.useMemo(()=>s=>{t(Bn(s,"height"))},[t]),!0,Re("skipAnimationFrameInResizeObserver")),o=Re("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...At(e,o)})}):null});function _u({useEmitter:e,useEmitterValue:t,usePublisher:n}){return w.memo(function({children:r,style:o,context:s,...i}){const a=n("scrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("scrollerRef"),f=t("horizontalDirection")||!1,{scrollByCallback:h,scrollerRef:p,scrollToCallback:v}=Eu(a,u,l,d,void 0,f);return e("scrollTo",v),e("scrollBy",h),c.jsx(l,{"data-testid":"virtuoso-scroller","data-virtuoso-scroller":!0,ref:p,style:{...f?_y:Ay,...o},tabIndex:0,...i,...At(l,s),children:r})})}function ju({useEmitter:e,useEmitterValue:t,usePublisher:n}){return w.memo(function({children:r,style:o,context:s,...i}){const a=n("windowScrollContainerState"),l=t("ScrollerComponent"),u=n("smoothScrollTargetReached"),d=t("totalListHeight"),f=t("deviation"),h=t("customScrollParent"),p=w.useRef(null),v=t("scrollerRef"),{scrollByCallback:x,scrollerRef:g,scrollToCallback:y}=Eu(a,u,l,v,h);return ku(()=>{var b;return g.current=h||((b=p.current)==null?void 0:b.ownerDocument.defaultView),()=>{g.current=null}},[g,h]),e("windowScrollTo",y),e("scrollBy",x),c.jsx(l,{ref:p,"data-virtuoso-scroller":!0,style:{position:"relative",...o,...d!==0?{height:d+f}:{}},...i,...At(l,s),children:r})})}const My=({children:e})=>{const t=w.useContext(Cu),n=Yt("viewportHeight"),r=Yt("fixedItemHeight"),o=Re("alignToBottom"),s=Re("horizontalDirection"),i=w.useMemo(()=>Wc(n,l=>Bn(l,s?"width":"height")),[n,s]),a=ir(i,!0,Re("skipAnimationFrameInResizeObserver"));return w.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),c.jsx("div",{"data-viewport-type":"element",ref:a,style:rs(o),children:e})},Dy=({children:e})=>{const t=w.useContext(Cu),n=Yt("windowViewportRect"),r=Yt("fixedItemHeight"),o=Re("customScrollParent"),s=Yc(n,o,Re("skipAnimationFrameInResizeObserver")),i=Re("alignToBottom");return w.useEffect(()=>{t&&(r(t.itemHeight),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:100}))},[t,n,r]),c.jsx("div",{"data-viewport-type":"window",ref:s,style:rs(i),children:e})},Ly=({children:e})=>{const t=Re("TopItemListComponent")||"div",n=Re("headerHeight"),r={...jy,marginTop:`${n}px`},o=Re("context");return c.jsx(t,{style:r,...At(t,o),children:e})},$y=w.memo(function(e){const t=Re("useWindowScroll"),n=Re("topItemsIndexes").length>0,r=Re("customScrollParent"),o=Re("context");return c.jsxs(r||t?By:zy,{...e,context:o,children:[n&&c.jsx(Ly,{children:c.jsx(Au,{showTopList:!0})}),c.jsxs(r||t?Dy:My,{children:[c.jsx(Py,{}),c.jsx(Au,{}),c.jsx(Oy,{})]})]})}),{Component:Fy,useEmitter:na,useEmitterValue:Re,usePublisher:Yt}=Su(ky,{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"}},$y),zy=_u({useEmitter:na,useEmitterValue:Re,usePublisher:Yt}),By=ju({useEmitter:na,useEmitterValue:Re,usePublisher:Yt}),Hy=Fy;it(wu,Xe(()=>{const e=J(u=>c.jsxs("td",{children:["Item $",u]})),t=J(null),n=J(u=>c.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=J(null),o=J(null),s=J({}),i=J(ta),a=J(Ir),l=(u,d=null)=>Nt(U(s,le(f=>f[u]),at()),d);return{components:s,computeItemKey:i,context:t,EmptyPlaceholder:l("EmptyPlaceholder"),FillerRow:l("FillerRow"),fixedFooterContent:o,fixedHeaderContent:r,itemContent:e,groupContent:n,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder"),TableBodyComponent:l("TableBody","tbody"),TableComponent:l("Table","table"),TableFooterComponent:l("TableFoot","tfoot"),TableHeadComponent:l("TableHead","thead"),TableRowComponent:l("TableRow","tr"),GroupComponent:l("Group","tr")}})),ea();const Ru={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},Uy={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Pu,floor:os,max:io,min:ra,round:Ou}=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 Wy(e){return{...Uy,items:e}}function ss(e,t){return e&&e.width===t.width&&e.height===t.height}function Vy(e,t){return e&&e.column===t.column&&e.row===t.row}const Ky=Xe(([{increaseViewportBy:e,listBoundary:t,overscan:n,visibleRange:r},{footerHeight:o,headerHeight:s,scrollBy:i,scrollContainerState:a,scrollTo:l,scrollTop:u,smoothScrollTargetReached:d,viewportHeight:f},h,p,{didMount:v,propsReady:x},{customScrollParent:g,useWindowScroll:y,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:I},C])=>{const T=J(0),E=J(0),A=J(Ru),j=J({height:0,width:0}),P=J({height:0,width:0}),D=We(),L=We(),V=J(0),M=J(null),X=J({column:0,row:0}),K=We(),q=We(),z=J(!1),$=J(0),pe=J(!0),F=J(!1),te=J(!1);tt(U(v,$e($),Ne(([O,Q])=>!!Q)),()=>{De(pe,!1)}),tt(U(xt(v,pe,P,j,$,F),Ne(([O,Q,ne,de,,ae])=>O&&!Q&&ne.height!==0&&de.height!==0&&!ae)),([,,,,O])=>{De(F,!0),qi(1,()=>{De(D,O)}),on(U(u),()=>{De(t,[0,0]),De(pe,!0)})}),xe(U(q,Ne(O=>O!=null&&O.scrollTop>0),mn(0)),E),tt(U(v,$e(q),Ne(([,O])=>O!=null)),([,O])=>{O&&(De(j,O.viewport),De(P,O.item),De(X,O.gap),O.scrollTop>0&&(De(z,!0),on(U(u,sr(1)),Q=>{De(z,!1)}),De(l,{top:O.scrollTop})))}),xe(U(j,le(({height:O})=>O)),f),xe(U(xt(Ee(j,ss),Ee(P,ss),Ee(X,(O,Q)=>O&&O.column===Q.column&&O.row===Q.row),Ee(u)),le(([O,Q,ne,de])=>({gap:ne,item:Q,scrollTop:de,viewport:O}))),K),xe(U(xt(Ee(T),r,Ee(X,Vy),Ee(P,ss),Ee(j,ss),Ee(M),Ee(E),Ee(z),Ee(pe),Ee($)),Ne(([,,,,,,,O])=>!O),le(([O,[Q,ne],de,ae,Ue,Ze,me,,Pe,Le])=>{const{column:ct,row:rt}=de,{height:vt,width:wt}=ae,{width:B}=Ue;if(me===0&&(O===0||B===0))return Ru;if(wt===0){const St=Gi(Le,O),en=St+Math.max(me-1,0);return Wy(Mu(St,en,Ze))}const se=Du(B,wt,ct);let we,Ie;Pe?Q===0&&ne===0&&me>0?(we=0,Ie=me-1):(we=se*os((Q+rt)/(vt+rt)),Ie=se*Pu((ne+rt)/(vt+rt))-1,Ie=ra(O-1,io(Ie,se-1)),we=ra(Ie,io(0,we))):(we=0,Ie=-1);const ye=Mu(we,Ie,Ze),{bottom:je,top:Qe}=Lu(Ue,de,ae,ye),Fe=Pu(O/se),pt=Fe*vt+(Fe-1)*rt-je;return{bottom:je,itemHeight:vt,items:ye,itemWidth:wt,offsetBottom:pt,offsetTop:Qe,top:Qe}})),A),xe(U(M,Ne(O=>O!==null),le(O=>O.length)),T),xe(U(xt(j,P,A,X),Ne(([O,Q,{items:ne}])=>ne.length>0&&Q.height!==0&&O.height!==0),le(([O,Q,{items:ne},de])=>{const{bottom:ae,top:Ue}=Lu(O,de,Q,ne);return[Ue,ae]}),at(Qr)),t);const fe=J(!1);xe(U(u,$e(fe),le(([O,Q])=>Q||O!==0)),fe);const ge=Ht(U(xt(A,T),Ne(([{items:O}])=>O.length>0),$e(fe),Ne(([[O,Q],ne])=>{const de=O.items[O.items.length-1].index===Q-1;return(ne||O.bottom>0&&O.itemHeight>0&&O.offsetBottom===0&&O.items.length===Q)&&de}),le(([[,O]])=>O-1),at())),be=Ht(U(Ee(A),Ne(({items:O})=>O.length>0&&O[0].index===0),mn(0),at())),Te=Ht(U(Ee(A),$e(z),Ne(([{items:O},Q])=>O.length>0&&!Q),le(([{items:O}])=>({endIndex:O[O.length-1].index,startIndex:O[0].index})),at(nu),Rn(0)));xe(Te,p.scrollSeekRangeChanged),xe(U(D,$e(j,P,T,X),le(([O,Q,ne,de,ae])=>{const Ue=lu(O),{align:Ze,behavior:me,offset:Pe}=Ue;let Le=Ue.index;Le==="LAST"&&(Le=de-1),Le=io(0,Le,ra(de-1,Le));let ct=oa(Q,ae,ne,Le);return Ze==="end"?ct=Ou(ct-Q.height+ne.height):Ze==="center"&&(ct=Ou(ct-Q.height/2+ne.height/2)),Pe&&(ct+=Pe),{behavior:me,top:ct}})),l);const G=Nt(U(A,le(O=>O.offsetBottom+O.bottom)),0);return xe(U(I,le(O=>({height:O.visibleHeight,width:O.visibleWidth}))),j),{customScrollParent:g,data:M,deviation:V,footerHeight:o,gap:X,headerHeight:s,increaseViewportBy:e,initialItemCount:E,itemDimensions:P,overscan:n,restoreStateFrom:q,scrollBy:i,scrollContainerState:a,scrollHeight:L,scrollTo:l,scrollToIndex:D,scrollTop:u,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:y,viewportDimensions:j,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:I,...p,gridState:A,horizontalDirection:te,initialTopMostItemIndex:$,totalListHeight:G,...h,endReached:ge,propsReady:x,rangeChanged:Te,startReached:be,stateChanged:K,stateRestoreInProgress:z,...C}},it(Yi,Rt,so,vu,Hn,Ji,zn));function Du(e,t,n){return io(1,os((e+n)/(os(t)+n)))}function Lu(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=oa(e,t,n,r[0].index);return{bottom:oa(e,t,n,r[r.length-1].index)+o,top:s}}function oa(e,t,n,r){const o=Du(e.width,n.width,t.column),s=os(r/o),i=s*n.height+io(0,s-1)*t.row;return i>0?i+t.row:i}const qy=Xe(()=>{const e=J(f=>`Item ${f}`),t=J({}),n=J(null),r=J("virtuoso-grid-item"),o=J("virtuoso-grid-list"),s=J(ta),i=J("div"),a=J(Ir),l=(f,h=null)=>Nt(U(t,le(p=>p[f]),at()),h),u=J(!1),d=J(!1);return xe(Ee(d),u),{components:t,computeItemKey:s,context:n,FooterComponent:l("Footer"),HeaderComponent:l("Header"),headerFooterTag:i,itemClassName:r,ItemComponent:l("Item","div"),itemContent:e,listClassName:o,ListComponent:l("List","div"),readyStateChanged:u,reportReadyState:d,ScrollerComponent:l("Scroller","div"),scrollerRef:a,ScrollSeekPlaceholder:l("ScrollSeekPlaceholder","div")}}),Gy=Xe(([e,t])=>({...e,...t}),it(Ky,qy)),Yy=w.memo(function(){const e=lt("gridState"),t=lt("listClassName"),n=lt("itemClassName"),r=lt("itemContent"),o=lt("computeItemKey"),s=lt("isSeeking"),i=Xt("scrollHeight"),a=lt("ItemComponent"),l=lt("ListComponent"),u=lt("ScrollSeekPlaceholder"),d=lt("context"),f=Xt("itemDimensions"),h=Xt("gap"),p=lt("log"),v=lt("stateRestoreInProgress"),x=Xt("reportReadyState"),g=ir(w.useMemo(()=>y=>{const b=y.parentElement.parentElement.scrollHeight;i(b);const S=y.firstChild;if(S){const{height:I,width:C}=S.getBoundingClientRect();f({height:I,width:C})}h({column:Fu("column-gap",getComputedStyle(y).columnGap,p),row:Fu("row-gap",getComputedStyle(y).rowGap,p)})},[i,f,h,p]),!0,!1);return ku(()=>{e.itemHeight>0&&e.itemWidth>0&&x(!0)},[e]),v?null:c.jsx(l,{className:t,ref:g,...At(l,d),"data-testid":"virtuoso-item-list",style:{paddingBottom:e.offsetBottom,paddingTop:e.offsetTop},children:e.items.map(y=>{const b=o(y.index,y.data,d);return s?c.jsx(u,{...At(u,d),height:e.itemHeight,index:y.index,width:e.itemWidth},b):w.createElement(a,{...At(a,d),className:n,"data-index":y.index,key:b},r(y.index,y.data,d))})})}),Xy=w.memo(function(){const e=lt("HeaderComponent"),t=Xt("headerHeight"),n=lt("headerFooterTag"),r=ir(w.useMemo(()=>s=>{t(Bn(s,"height"))},[t]),!0,!1),o=lt("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...At(e,o)})}):null}),Jy=w.memo(function(){const e=lt("FooterComponent"),t=Xt("footerHeight"),n=lt("headerFooterTag"),r=ir(w.useMemo(()=>s=>{t(Bn(s,"height"))},[t]),!0,!1),o=lt("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...At(e,o)})}):null}),Zy=({children:e})=>{const t=w.useContext(Tu),n=Xt("itemDimensions"),r=Xt("viewportDimensions"),o=ir(w.useMemo(()=>s=>{r(s.getBoundingClientRect())},[r]),!0,!1);return w.useEffect(()=>{t&&(r({height:t.viewportHeight,width:t.viewportWidth}),n({height:t.itemHeight,width:t.itemWidth}))},[t,r,n]),c.jsx("div",{ref:o,style:rs(!1),children:e})},Qy=({children:e})=>{const t=w.useContext(Tu),n=Xt("windowViewportRect"),r=Xt("itemDimensions"),o=lt("customScrollParent"),s=Yc(n,o,!1);return w.useEffect(()=>{t&&(r({height:t.itemHeight,width:t.itemWidth}),n({offsetTop:0,visibleHeight:t.viewportHeight,visibleWidth:t.viewportWidth}))},[t,n,r]),c.jsx("div",{ref:s,style:rs(!1),children:e})},ev=w.memo(function({...e}){const t=lt("useWindowScroll"),n=lt("customScrollParent"),r=n||t?nv:tv,o=n||t?Qy:Zy,s=lt("context");return c.jsx(r,{...e,...At(r,s),children:c.jsxs(o,{children:[c.jsx(Xy,{}),c.jsx(Yy,{}),c.jsx(Jy,{})]})})}),{useEmitter:$u,useEmitterValue:lt,usePublisher:Xt}=Su(Gy,{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"}},ev),tv=_u({useEmitter:$u,useEmitterValue:lt,usePublisher:Xt}),nv=ju({useEmitter:$u,useEmitterValue:lt,usePublisher:Xt});function Fu(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,$t.WARN),t==="normal"?0:parseInt(t??"0",10)}const rv=No.cva("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function sa({className:e,variant:t,...n}){return c.jsx("div",{className:ee(rv({variant:t}),e),...n})}function ue(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 ov(e,t){const n=m.createContext(t),r=s=>{const{children:i,...a}=s,l=m.useMemo(()=>a,Object.values(a));return c.jsx(n.Provider,{value:l,children:i})};r.displayName=e+"Provider";function o(s){const i=m.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 yn(e,t=[]){let n=[];function r(s,i){const a=m.createContext(i),l=n.length;n=[...n,i];const u=f=>{var y;const{scope:h,children:p,...v}=f,x=((y=h==null?void 0:h[e])==null?void 0:y[l])||a,g=m.useMemo(()=>v,Object.values(v));return c.jsx(x.Provider,{value:g,children:p})};u.displayName=s+"Provider";function d(f,h){var x;const p=((x=h==null?void 0:h[e])==null?void 0:x[l])||a,v=m.useContext(p);if(v)return v;if(i!==void 0)return i;throw new Error(`\`${f}\` must be used within \`${s}\``)}return[u,d]}const o=()=>{const s=n.map(i=>m.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return m.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,sv(o,...t)]}function sv(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:u})=>{const f=l(s)[`__scope${u}`];return{...a,...f}},{});return m.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}var bt=globalThis!=null&&globalThis.document?m.useLayoutEffect:()=>{},iv=m[" useInsertionEffect ".trim().toString()]||bt;function cr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=av({defaultProp:t,onChange:n}),a=e!==void 0,l=a?e:o;{const d=m.useRef(e!==void 0);m.useEffect(()=>{const f=d.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.`),d.current=a},[a,r])}const u=m.useCallback(d=>{var f;if(a){const h=lv(d)?d(e):d;h!==e&&((f=i.current)==null||f.call(i,h))}else s(d)},[a,e,s,i]);return[l,u]}function av({defaultProp:e,onChange:t}){const[n,r]=m.useState(e),o=m.useRef(n),s=m.useRef(t);return iv(()=>{s.current=t},[t]),m.useEffect(()=>{var i;o.current!==n&&((i=s.current)==null||i.call(s,n),o.current=n)},[n,o]),[n,r,s]}function lv(e){return typeof e=="function"}function zu(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function ia(...e){return t=>{let n=!1;const r=e.map(o=>{const s=zu(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():zu(e[o],null)}}}}function He(...e){return m.useCallback(ia(...e),e)}var cv=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ae=cv.reduce((e,t)=>{const n=tr.createSlot(`Primitive.${t}`),r=m.forwardRef((o,s)=>{const{asChild:i,...a}=o,l=i?n:t;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),c.jsx(l,{...a,ref:s})});return r.displayName=`Primitive.${t}`,{...e,[t]:r}},{});function Bu(e,t){e&&Ao.flushSync(()=>e.dispatchEvent(t))}function uv(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var Wt=e=>{const{present:t,children:n}=e,r=dv(t),o=typeof n=="function"?n({present:r.isPresent}):m.Children.only(n),s=He(r.ref,fv(o));return typeof n=="function"||r.isPresent?m.cloneElement(o,{ref:s}):null};Wt.displayName="Presence";function dv(e){const[t,n]=m.useState(),r=m.useRef(null),o=m.useRef(e),s=m.useRef("none"),i=e?"mounted":"unmounted",[a,l]=uv(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return m.useEffect(()=>{const u=is(r.current);s.current=a==="mounted"?u:"none"},[a]),bt(()=>{const u=r.current,d=o.current;if(d!==e){const h=s.current,p=is(u);e?l("MOUNT"):p==="none"||(u==null?void 0:u.display)==="none"?l("UNMOUNT"):l(d&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),bt(()=>{if(t){let u;const d=t.ownerDocument.defaultView??window,f=p=>{const x=is(r.current).includes(CSS.escape(p.animationName));if(p.target===t&&x&&(l("ANIMATION_END"),!o.current)){const g=t.style.animationFillMode;t.style.animationFillMode="forwards",u=d.setTimeout(()=>{t.style.animationFillMode==="forwards"&&(t.style.animationFillMode=g)})}},h=p=>{p.target===t&&(s.current=is(r.current))};return t.addEventListener("animationstart",h),t.addEventListener("animationcancel",f),t.addEventListener("animationend",f),()=>{d.clearTimeout(u),t.removeEventListener("animationstart",h),t.removeEventListener("animationcancel",f),t.removeEventListener("animationend",f)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:m.useCallback(u=>{r.current=u?getComputedStyle(u):null,n(u)},[])}}function is(e){return(e==null?void 0:e.animationName)||"none"}function fv(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 hv=m[" useId ".trim().toString()]||(()=>{}),pv=0;function vn(e){const[t,n]=m.useState(hv());return bt(()=>{n(r=>r??String(pv++))},[e]),e||(t?`radix-${t}`:"")}var as="Collapsible",[mv,tk]=yn(as),[gv,aa]=mv(as),Hu=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[l,u]=cr({prop:r,defaultProp:o??!1,onChange:i,caller:as});return c.jsx(gv,{scope:n,disabled:s,contentId:vn(),open:l,onOpenToggle:m.useCallback(()=>u(d=>!d),[u]),children:c.jsx(Ae.div,{"data-state":ca(l),"data-disabled":s?"":void 0,...a,ref:t})})});Hu.displayName=as;var Uu="CollapsibleTrigger",Wu=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=aa(Uu,n);return c.jsx(Ae.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":ca(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:ue(e.onClick,o.onOpenToggle)})});Wu.displayName=Uu;var la="CollapsibleContent",xv=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=aa(la,e.__scopeCollapsible);return c.jsx(Wt,{present:n||o.open,children:({present:s})=>c.jsx(yv,{...r,ref:t,present:s})})});xv.displayName=la;var yv=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=aa(la,n),[a,l]=m.useState(r),u=m.useRef(null),d=He(t,u),f=m.useRef(0),h=f.current,p=m.useRef(0),v=p.current,x=i.open||a,g=m.useRef(x),y=m.useRef(void 0);return m.useEffect(()=>{const b=requestAnimationFrame(()=>g.current=!1);return()=>cancelAnimationFrame(b)},[]),bt(()=>{const b=u.current;if(b){y.current=y.current||{transitionDuration:b.style.transitionDuration,animationName:b.style.animationName},b.style.transitionDuration="0s",b.style.animationName="none";const S=b.getBoundingClientRect();f.current=S.height,p.current=S.width,g.current||(b.style.transitionDuration=y.current.transitionDuration,b.style.animationName=y.current.animationName),l(r)}},[i.open,r]),c.jsx(Ae.div,{"data-state":ca(i.open),"data-disabled":i.disabled?"":void 0,id:i.contentId,hidden:!x,...s,ref:d,style:{"--radix-collapsible-content-height":h?`${h}px`:void 0,"--radix-collapsible-content-width":v?`${v}px`:void 0,...e.style},children:x&&o})});function ca(e){return e?"open":"closed"}var vv=Hu;const Vu=vv,Ku=Wu,ao=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:ee("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));ao.displayName="Card";const lo=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:ee("flex flex-col space-y-1.5 p-6",e),...t}));lo.displayName="CardHeader";const co=m.forwardRef(({className:e,...t},n)=>c.jsx("h3",{ref:n,className:ee("text-2xl font-semibold leading-none tracking-tight",e),...t}));co.displayName="CardTitle";const qu=m.forwardRef(({className:e,...t},n)=>c.jsx("p",{ref:n,className:ee("text-sm text-muted-foreground",e),...t}));qu.displayName="CardDescription";const ls=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:ee("p-6 pt-0",e),...t}));ls.displayName="CardContent";const Gu=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:ee("flex items-center p-6 pt-0",e),...t}));Gu.displayName="CardFooter";function Yu(){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 ur=Yu();function bv(e){ur=e}const Xu=/[&<>"']/,wv=new RegExp(Xu.source,"g"),Ju=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,Sv=new RegExp(Ju.source,"g"),Cv={"&":"&","<":"<",">":">",'"':""","'":"'"},Zu=e=>Cv[e];function _t(e,t){if(t){if(Xu.test(e))return e.replace(wv,Zu)}else if(Ju.test(e))return e.replace(Sv,Zu);return e}const Tv=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Qu(e){return e.replace(Tv,(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 kv=/(^|[^\[])\^/g;function st(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(kv,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const Ev=/[^\w:]/g,Iv=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function ed(e,t,n){if(e){let r;try{r=decodeURIComponent(Qu(n)).replace(Ev,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!Iv.test(n)&&(n=jv(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const cs={},Nv=/^[^:]+:\/*[^/]*$/,Av=/^([^:]+:)[\s\S]*$/,_v=/^([^:]+:\/*[^/]*)[\s\S]*$/;function jv(e,t){cs[" "+e]||(Nv.test(e)?cs[" "+e]=e+"/":cs[" "+e]=ds(e,"/",!0)),e=cs[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(Av,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(_v,"$1")+t:e+t}const us={exec:function(){}};function td(e,t){const n=e.replace(/\|/g,(s,i,a)=>{let l=!1,u=i;for(;--u>=0&&a[u]==="\\";)l=!l;return l?"|":" |"}),r=n.split(/ \|/);let o=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;o<r.length;o++)r[o]=r[o].trim().replace(/\\\|/g,"|");return r}function ds(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 Rv(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 Pv(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 nd(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function rd(e,t,n,r){const o=t.href,s=t.title?_t(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:_t(i)}}function Ov(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
|
|
40
39
|
`).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(`
|
|
41
|
-
`)}class
|
|
42
|
-
`)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=Ov(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=
|
|
40
|
+
`)}class ua{constructor(t){this.options=t||ur}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:ds(r,`
|
|
41
|
+
`)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=Ov(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=ds(r,"#");(this.options.pedantic||!o||/ $/.test(o))&&(r=o.trim())}return{type:"heading",raw:n[0],depth:n[1].length,text:r,tokens:this.lexer.inline(r)}}}hr(t){const n=this.rules.block.hr.exec(t);if(n)return{type:"hr",raw:n[0]}}blockquote(t){const n=this.rules.block.blockquote.exec(t);if(n){const r=n[0].replace(/^ *>[ \t]?/gm,""),o=this.lexer.state.top;this.lexer.state.top=!0;const s=this.lexer.blockTokens(r);return this.lexer.state.top=o,{type:"blockquote",raw:n[0],tokens:s,text:r}}}list(t){let n=this.rules.block.list.exec(t);if(n){let r,o,s,i,a,l,u,d,f,h,p,v,x=n[1].trim();const g=x.length>1,y={type:"list",raw:"",ordered:g,start:g?+x.slice(0,-1):"",loose:!1,items:[]};x=g?`\\d{1,9}\\${x.slice(-1)}`:`\\${x}`,this.options.pedantic&&(x=g?x:"[*+-]");const b=new RegExp(`^( {0,3}${x})((?:[ ][^\\n]*)?(?:\\n|$))`);for(;t&&(v=!1,!(!(n=b.exec(t))||this.rules.block.hr.test(t)));){if(r=n[0],t=t.substring(r.length),d=n[2].split(`
|
|
43
42
|
`,1)[0].replace(/^\t+/,I=>" ".repeat(3*I.length)),f=t.split(`
|
|
44
43
|
`,1)[0],this.options.pedantic?(i=2,p=d.trimLeft()):(i=n[2].search(/[^ ]/),i=i>4?1:i,p=d.slice(i),i+=n[1].length),l=!1,!d&&/^ *$/.test(f)&&(r+=f+`
|
|
45
44
|
`,t=t.substring(f.length+1),v=!0),!v){const I=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),C=new RegExp(`^ {0,${Math.min(3,i-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),T=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:\`\`\`|~~~)`),E=new RegExp(`^ {0,${Math.min(3,i-1)}}#`);for(;t&&(h=t.split(`
|
|
46
45
|
`,1)[0],f=h,this.options.pedantic&&(f=f.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),!(T.test(f)||E.test(f)||I.test(f)||C.test(t)));){if(f.search(/[^ ]/)>=i||!f.trim())p+=`
|
|
47
46
|
`+f.slice(i);else{if(l||d.search(/[^ ]/)>=4||T.test(d)||E.test(d)||C.test(d))break;p+=`
|
|
48
47
|
`+f}!l&&!f.trim()&&(l=!0),r+=h+`
|
|
49
|
-
`,t=t.substring(h.length+1),d=f.slice(i)}}y.loose||(u?y.loose=!0:/\n *\n *$/.test(r)&&(u=!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 S=y.items.length;for(a=0;a<S;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(T=>T.type==="space"),C=I.length>0&&I.some(T=>/\n.*\n/.test(T.raw));y.loose=C}if(y.loose)for(a=0;a<S;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]):
|
|
48
|
+
`,t=t.substring(h.length+1),d=f.slice(i)}}y.loose||(u?y.loose=!0:/\n *\n *$/.test(r)&&(u=!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 S=y.items.length;for(a=0;a<S;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(T=>T.type==="space"),C=I.length>0&&I.some(T=>/\n.*\n/.test(T.raw));y.loose=C}if(y.loose)for(a=0;a<S;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]):_t(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:td(n[1]).map(o=>({text:o})),align:n[2].replace(/^ *|\| *$/g,"").split(/ *\| */),rows:n[3]&&n[3].trim()?n[3].replace(/\n[ \t]*$/,"").split(`
|
|
50
49
|
`):[]};if(r.header.length===r.align.length){r.raw=n[0];let o=r.align.length,s,i,a,l;for(s=0;s<o;s++)/^ *-+: *$/.test(r.align[s])?r.align[s]="right":/^ *:-+: *$/.test(r.align[s])?r.align[s]="center":/^ *:-+ *$/.test(r.align[s])?r.align[s]="left":r.align[s]=null;for(o=r.rows.length,s=0;s<o;s++)r.rows[s]=td(r.rows[s],r.header.length).map(u=>({text:u}));for(o=r.header.length,i=0;i<o;i++)r.header[i].tokens=this.lexer.inline(r.header[i].text);for(o=r.rows.length,i=0;i<o;i++)for(l=r.rows[i],a=0;a<l.length;a++)l[a].tokens=this.lexer.inline(l[a].text);return r}}}lheading(t){const n=this.rules.block.lheading.exec(t);if(n)return{type:"heading",raw:n[0],depth:n[2].charAt(0)==="="?1:2,text:n[1],tokens:this.lexer.inline(n[1])}}paragraph(t){const n=this.rules.block.paragraph.exec(t);if(n){const r=n[1].charAt(n[1].length-1)===`
|
|
51
|
-
`?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:
|
|
52
|
-
]`).replace("lheading",Se.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const ce={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:
|
|
50
|
+
`?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:_t(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]):_t(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=ds(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=Rv(n[2],"()");if(i>-1){const l=(n[0].indexOf("!")===0?5:4)+n[1].length+i;n[2]=n[2].substring(0,i),n[0]=n[0].substring(0,l).trim(),n[3]=""}}let o=n[2],s="";if(this.options.pedantic){const i=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(o);i&&(o=i[1],s=i[3])}else s=n[3]?n[3].slice(1,-1):"";return o=o.trim(),/^</.test(o)&&(this.options.pedantic&&!/>$/.test(r)?o=o.slice(1):o=o.slice(1,-1)),rd(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 rd(r,o,r[0],this.lexer)}}emStrong(t,n,r=""){let o=this.rules.inline.emStrong.lDelim.exec(t);if(!o||o[3]&&r.match(/[\p{L}\p{N}]/u))return;const s=o[1]||o[2]||"";if(!s||s&&(r===""||this.rules.inline.punctuation.exec(r))){const i=o[0].length-1;let a,l,u=i,d=0;const f=o[0][0]==="*"?this.rules.inline.emStrong.rDelimAst:this.rules.inline.emStrong.rDelimUnd;for(f.lastIndex=0,n=n.slice(-1*t.length+i);(o=f.exec(n))!=null;){if(a=o[1]||o[2]||o[3]||o[4]||o[5]||o[6],!a)continue;if(l=a.length,o[3]||o[4]){u+=l;continue}else if((o[5]||o[6])&&i%3&&!((i+l)%3)){d+=l;continue}if(u-=l,u>0)continue;l=Math.min(l,l+u+d);const h=t.slice(0,i+o.index+(o[0].length-a.length)+l);if(Math.min(i,l)%2){const v=h.slice(1,-1);return{type:"em",raw:h,text:v,tokens:this.lexer.inlineTokens(v)}}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=_t(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=_t(this.options.mangle?n(r[1]):r[1]),s="mailto:"+o):(o=_t(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=_t(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=_t(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]):_t(r[0]):r[0]:o=_t(this.options.smartypants?n(r[0]):r[0]),{type:"text",raw:r[0],text:o}}}}const Se={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:us,lheading:/^((?:.|\n(?!\n))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,text:/^[^\n]+/};Se._label=/(?!\s*\])(?:\\.|[^\[\]\\])+/,Se._title=/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/,Se.def=st(Se.def).replace("label",Se._label).replace("title",Se._title).getRegex(),Se.bullet=/(?:[*+-]|\d{1,9}[.)])/,Se.listItemStart=st(/^( *)(bull) */).replace("bull",Se.bullet).getRegex(),Se.list=st(Se.list).replace(/bull/g,Se.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+Se.def.source+")").getRegex(),Se._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",Se._comment=/<!--(?!-?>)[\s\S]*?(?:-->|$)/,Se.html=st(Se.html,"i").replace("comment",Se._comment).replace("tag",Se._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Se.paragraph=st(Se._paragraph).replace("hr",Se.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",Se._tag).getRegex(),Se.blockquote=st(Se.blockquote).replace("paragraph",Se.paragraph).getRegex(),Se.normal={...Se},Se.gfm={...Se.normal,table:"^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"},Se.gfm.table=st(Se.gfm.table).replace("hr",Se.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",Se._tag).getRegex(),Se.gfm.paragraph=st(Se._paragraph).replace("hr",Se.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("table",Se.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",Se._tag).getRegex(),Se.pedantic={...Se.normal,html:st(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",Se._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:us,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:st(Se.normal._paragraph).replace("hr",Se.hr).replace("heading",` *#{1,6} *[^
|
|
51
|
+
]`).replace("lheading",Se.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const ce={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:us,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:us,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,punctuation:/^([\spunctuation])/};ce._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",ce.punctuation=st(ce.punctuation).replace(/punctuation/g,ce._punctuation).getRegex(),ce.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g,ce.escapedEmSt=/(?:^|[^\\])(?:\\\\)*\\[*_]/g,ce._comment=st(Se._comment).replace("(?:-->|$)","-->").getRegex(),ce.emStrong.lDelim=st(ce.emStrong.lDelim).replace(/punct/g,ce._punctuation).getRegex(),ce.emStrong.rDelimAst=st(ce.emStrong.rDelimAst,"g").replace(/punct/g,ce._punctuation).getRegex(),ce.emStrong.rDelimUnd=st(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=st(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=st(ce.tag).replace("comment",ce._comment).replace("attribute",ce._attribute).getRegex(),ce._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,ce._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/,ce._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,ce.link=st(ce.link).replace("label",ce._label).replace("href",ce._href).replace("title",ce._title).getRegex(),ce.reflink=st(ce.reflink).replace("label",ce._label).replace("ref",Se._label).getRegex(),ce.nolink=st(ce.nolink).replace("ref",Se._label).getRegex(),ce.reflinkSearch=st(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:st(/^!?\[(label)\]\((.*?)\)/).replace("label",ce._label).getRegex(),reflink:st(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",ce._label).getRegex()},ce.gfm={...ce.normal,escape:st(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=st(ce.gfm.url,"i").replace("email",ce.gfm._extended_email).getRegex(),ce.breaks={...ce.gfm,br:st(ce.br).replace("{2,}","*").getRegex(),text:st(ce.gfm.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()};function Mv(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 od(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 Un{constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||ur,this.options.tokenizer=this.options.tokenizer||new ua,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:Se.normal,inline:ce.normal};this.options.pedantic?(n.block=Se.pedantic,n.inline=ce.pedantic):this.options.gfm&&(n.block=Se.gfm,this.options.breaks?n.inline=ce.breaks:n.inline=ce.gfm),this.tokenizer.rules=n}static get rules(){return{block:Se,inline:ce}}static lex(t,n){return new Un(n).lex(t)}static lexInline(t,n){return new Un(n).inlineTokens(t)}lex(t){t=t.replace(/\r\n|\r/g,`
|
|
53
52
|
`),this.blockTokens(t,this.tokens);let n;for(;n=this.inlineQueue.shift();)this.inlineTokens(n.src,n.tokens);return this.tokens}blockTokens(t,n=[]){this.options.pedantic?t=t.replace(/\t/g," ").replace(/^ +$/gm,""):t=t.replace(/^( *)(\t+)/gm,(a,l,u)=>l+" ".repeat(u.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+=`
|
|
54
53
|
`: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+=`
|
|
55
54
|
`+r.raw,o.text+=`
|
|
@@ -59,9 +58,9 @@ React keys must be passed directly to JSX without using spread:
|
|
|
59
58
|
`+r.raw,o.text+=`
|
|
60
59
|
`+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+=`
|
|
61
60
|
`+r.raw,o.text+=`
|
|
62
|
-
`+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,l,u;if(this.tokens.links){const d=Object.keys(this.tokens.links);if(d.length>0)for(;(a=this.tokenizer.rules.inline.reflinkSearch.exec(i))!=null;)d.includes(a[0].slice(a[0].lastIndexOf("[")+1,-1))&&(i=i.slice(0,a.index)+"["+nd("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)+"["+nd("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(l||(u=""),l=!1,!(this.options.extensions&&this.options.extensions.inline&&this.options.extensions.inline.some(d=>(r=d.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,u)){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,od)){t=t.substring(r.raw.length),n.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(t,od))){t=t.substring(r.raw.length),n.push(r);continue}if(s=t,this.options.extensions&&this.options.extensions.startInline){let d=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&&(d=Math.min(d,h))}),d<1/0&&d>=0&&(s=t.substring(0,d+1))}if(r=this.tokenizer.inlineText(s,Mv)){t=t.substring(r.raw.length),r.raw.slice(-1)!=="_"&&(u=r.raw.slice(-1)),l=!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 d="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(d);break}else throw new Error(d)}}return n}}class
|
|
63
|
-
`,o?'<pre><code class="'+this.options.langPrefix+
|
|
64
|
-
`:"<pre><code>"+(r?t:
|
|
61
|
+
`+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,l,u;if(this.tokens.links){const d=Object.keys(this.tokens.links);if(d.length>0)for(;(a=this.tokenizer.rules.inline.reflinkSearch.exec(i))!=null;)d.includes(a[0].slice(a[0].lastIndexOf("[")+1,-1))&&(i=i.slice(0,a.index)+"["+nd("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)+"["+nd("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(l||(u=""),l=!1,!(this.options.extensions&&this.options.extensions.inline&&this.options.extensions.inline.some(d=>(r=d.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,u)){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,od)){t=t.substring(r.raw.length),n.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(t,od))){t=t.substring(r.raw.length),n.push(r);continue}if(s=t,this.options.extensions&&this.options.extensions.startInline){let d=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&&(d=Math.min(d,h))}),d<1/0&&d>=0&&(s=t.substring(0,d+1))}if(r=this.tokenizer.inlineText(s,Mv)){t=t.substring(r.raw.length),r.raw.slice(-1)!=="_"&&(u=r.raw.slice(-1)),l=!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 d="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(d);break}else throw new Error(d)}}return n}}class da{constructor(t){this.options=t||ur}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$/,"")+`
|
|
62
|
+
`,o?'<pre><code class="'+this.options.langPrefix+_t(o)+'">'+(r?t:_t(t,!0))+`</code></pre>
|
|
63
|
+
`:"<pre><code>"+(r?t:_t(t,!0))+`</code></pre>
|
|
65
64
|
`}blockquote(t){return`<blockquote>
|
|
66
65
|
${t}</blockquote>
|
|
67
66
|
`}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}>
|
|
@@ -79,14 +78,14 @@ ${t}</blockquote>
|
|
|
79
78
|
`}tablerow(t){return`<tr>
|
|
80
79
|
${t}</tr>
|
|
81
80
|
`}tablecell(t,n){const r=n.header?"th":"td";return(n.align?`<${r} align="${n.align}">`:`<${r}>`)+t+`</${r}>
|
|
82
|
-
`}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=ed(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=ed(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 sd{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 id{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
|
|
83
|
-
`+(p.tokens?this.parseInline(p.tokens):p.text);r+=n?this.renderer.paragraph(h):h;continue}default:{const A='Token with "'+p.type+'" type was not found.';if(this.options.silent){console.error(A);return}else throw new Error(A)}}}return r}parseInline(t,n){n=n||this.renderer;let r="",o,s,i;const a=t.length;for(o=0;o<a;o++){if(s=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[s.type]&&(i=this.options.extensions.renderers[s.type].call({parser:this},s),i!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type))){r+=i||"";continue}switch(s.type){case"escape":{r+=n.text(s.text);break}case"html":{r+=n.html(s.text);break}case"link":{r+=n.link(s.href,s.title,this.parseInline(s.tokens,n));break}case"image":{r+=n.image(s.href,s.title,s.text);break}case"strong":{r+=n.strong(this.parseInline(s.tokens,n));break}case"em":{r+=n.em(this.parseInline(s.tokens,n));break}case"codespan":{r+=n.codespan(s.text);break}case"br":{r+=n.br();break}case"del":{r+=n.del(this.parseInline(s.tokens,n));break}case"text":{r+=n.text(s.text);break}default:{const l='Token with "'+s.type+'" type was not found.';if(this.options.silent){console.error(l);return}else throw new Error(l)}}}return r}}class
|
|
84
|
-
Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+jt(r.message+"",!0)+"</pre>";if(t)return Promise.resolve(o);if(n){n(null,o);return}return o}if(t)return Promise.reject(r);if(n){n(r);return}throw r}}function ad(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...Ce.defaults,...s};const i=Dv(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(Pv(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(f){return i(f)}const u=function(f){let h;if(!f)try{r.walkTokens&&Ce.walkTokens(l,r.walkTokens),h=t(l,r),r.hooks&&(h=r.hooks.postprocess(h))}catch(p){f=p}return r.highlight=a,f?i(f):o(null,h)};if(!a||a.length<3||(delete r.highlight,!l.length))return u();let d=0;Ce.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(h,p){if(h)return u(h);p!=null&&p!==f.text&&(f.text=p,f.escaped=!0),d--,d===0&&u()})},0))}),d===0&&u();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(Ce.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&&Ce.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function Ce(e,t,n){return ad(Wn.lex,Vn.parse)(e,t,n)}Ce.options=Ce.setOptions=function(e){return Ce.defaults={...Ce.defaults,...e},bv(Ce.defaults),Ce},Ce.getDefaults=Yu,Ce.defaults=dr,Ce.use=function(...e){const t=Ce.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=Ce.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=Ce.defaults.renderer||new ha;for(const s in n.renderer){const i=o[s];o[s]=(...a)=>{let l=n.renderer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.renderer=o}if(n.tokenizer){const o=Ce.defaults.tokenizer||new fa;for(const s in n.tokenizer){const i=o[s];o[s]=(...a)=>{let l=n.tokenizer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.tokenizer=o}if(n.hooks){const o=Ce.defaults.hooks||new ms;for(const s in n.hooks){const i=o[s];ms.passThroughHooks.has(s)?o[s]=a=>{if(Ce.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(u=>i.call(o,u));const l=n.hooks[s].call(o,a);return i.call(o,l)}:o[s]=(...a)=>{let l=n.hooks[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.hooks=o}if(n.walkTokens){const o=Ce.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}}Ce.setOptions(r)})},Ce.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(Ce,r)),r.type){case"table":{for(const o of r.header)n=n.concat(Ce.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(Ce.walkTokens(s.tokens,t));break}case"list":{n=n.concat(Ce.walkTokens(r.items,t));break}default:Ce.defaults.extensions&&Ce.defaults.extensions.childTokens&&Ce.defaults.extensions.childTokens[r.type]?Ce.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(Ce.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(Ce.walkTokens(r.tokens,t)))}return n},Ce.parseInline=ad(Wn.lexInline,Vn.parseInline),Ce.Parser=Vn,Ce.parser=Vn.parse,Ce.Renderer=ha,Ce.TextRenderer=sd,Ce.Lexer=Wn,Ce.lexer=Wn.lex,Ce.Tokenizer=fa,Ce.Slugger=id,Ce.Hooks=ms,Ce.parse=Ce,Ce.options,Ce.setOptions,Ce.use,Ce.walkTokens,Ce.parseInline,Vn.parse,Wn.lex;function pa({content:e,className:t="",allowHtml:n=!1,style:r}){const o=w.useMemo(()=>{try{if(!n){const i=e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,"").replace(/javascript:/gi,"").replace(/on\w+\s*=/gi,"");return Ce.parse(i)}return Ce.parse(e)}catch(i){return console.error("[MarkdownContent] parse error",i),`<pre>Error rendering markdown: ${String(i)}</pre>`}},[e,n]),s=w.useMemo(()=>{if(r&&r.color){const i=r.color;return{...r,"--tw-prose-body":i,"--tw-prose-headings":i,"--tw-prose-links":i,"--tw-prose-bold":i,"--tw-prose-counters":i,"--tw-prose-bullets":i,"--tw-prose-hr":i,"--tw-prose-quotes":i,"--tw-prose-quote-borders":i,"--tw-prose-captions":i,"--tw-prose-code":i,"--tw-prose-pre-code":i,"--tw-prose-pre-bg":"inherit","--tw-prose-th-borders":i,"--tw-prose-td-borders":i}}return r},[r]);return c.jsx("div",{className:ee("markdown prose max-w-none break-words dark:prose-invert",t),style:s,dangerouslySetInnerHTML:{__html:o}})}async function ld(e,t){return await gn(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function cd(e,t){return await(await ld(`/files/${e}/view`,t)).text()}async function Lv(e,t){const n=await ld(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await gn(`/files/${e}`);o=(i==null?void 0:i.filename)??o}catch{}const s=document.createElement("a");s.href=r,s.download=o,document.body.appendChild(s),s.click(),s.remove(),setTimeout(()=>URL.revokeObjectURL(r),6e4)}async function $v(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await gn("/files",{params:r})}const Fv=1,zv=1e6;let ma=0;function Bv(){return ma=(ma+1)%Number.MAX_SAFE_INTEGER,ma.toString()}const ga=new Map,ud=e=>{if(ga.has(e))return;const t=setTimeout(()=>{ga.delete(e),go({type:"REMOVE_TOAST",toastId:e})},zv);ga.set(e,t)},Hv=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,Fv)};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?ud(n):e.toasts.forEach(r=>{ud(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)}}},gs=[];let xs={toasts:[]};function go(e){xs=Hv(xs,e),gs.forEach(t=>{t(xs)})}function Uv({...e}){const t=Bv(),n=o=>go({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>go({type:"DISMISS_TOAST",toastId:t});return go({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function xa(){const[e,t]=m.useState(xs);return m.useEffect(()=>(gs.push(t),()=>{const n=gs.indexOf(t);n>-1&&gs.splice(n,1)}),[e]),{...e,toast:Uv,dismiss:n=>go({type:"DISMISS_TOAST",toastId:n})}}function Et(e){const t=m.useRef(e);return m.useEffect(()=>{t.current=e}),m.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function Wv(e,t=globalThis==null?void 0:globalThis.document){const n=Et(e);m.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 Vv="DismissableLayer",ya="dismissableLayer.update",Kv="dismissableLayer.pointerDownOutside",qv="dismissableLayer.focusOutside",dd,fd=m.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),ys=m.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,u=m.useContext(fd),[d,f]=m.useState(null),h=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=m.useState({}),v=Ue(t,E=>f(E)),x=Array.from(u.layers),[g]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),y=x.indexOf(g),b=d?x.indexOf(d):-1,S=u.layersWithOutsidePointerEventsDisabled.size>0,I=b>=y,C=Xv(E=>{const A=E.target,j=[...u.branches].some(P=>P.contains(A));!I||j||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},h),T=Jv(E=>{const A=E.target;[...u.branches].some(P=>P.contains(A))||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},h);return Wv(E=>{b===u.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},h),m.useEffect(()=>{if(d)return n&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(dd=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(d)),u.layers.add(d),hd(),()=>{n&&u.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=dd)}},[d,h,n,u]),m.useEffect(()=>()=>{d&&(u.layers.delete(d),u.layersWithOutsidePointerEventsDisabled.delete(d),hd())},[d,u]),m.useEffect(()=>{const E=()=>p({});return document.addEventListener(ya,E),()=>document.removeEventListener(ya,E)},[]),c.jsx(Ae.div,{...l,ref:v,style:{pointerEvents:S?I?"auto":"none":void 0,...e.style},onFocusCapture:ue(e.onFocusCapture,T.onFocusCapture),onBlurCapture:ue(e.onBlurCapture,T.onBlurCapture),onPointerDownCapture:ue(e.onPointerDownCapture,C.onPointerDownCapture)})});ys.displayName=Vv;var Gv="DismissableLayerBranch",Yv=m.forwardRef((e,t)=>{const n=m.useContext(fd),r=m.useRef(null),o=Ue(t,r);return m.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),c.jsx(Ae.div,{...e,ref:o})});Yv.displayName=Gv;function Xv(e,t=globalThis==null?void 0:globalThis.document){const n=Et(e),r=m.useRef(!1),o=m.useRef(()=>{});return m.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){pd(Kv,n,u,{discrete:!0})};const u={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function Jv(e,t=globalThis==null?void 0:globalThis.document){const n=Et(e),r=m.useRef(!1);return m.useEffect(()=>{const o=s=>{s.target&&!r.current&&pd(qv,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 hd(){const e=new CustomEvent(ya);document.dispatchEvent(e)}function pd(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?Bu(o,s):o.dispatchEvent(s)}var va="focusScope.autoFocusOnMount",ba="focusScope.autoFocusOnUnmount",md={bubbles:!1,cancelable:!0},Zv="FocusScope",vs=m.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=m.useState(null),u=Et(o),d=Et(s),f=m.useRef(null),h=Ue(t,x=>l(x)),p=m.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;m.useEffect(()=>{if(r){let x=function(S){if(p.paused||!a)return;const I=S.target;a.contains(I)?f.current=I:Kn(f.current,{select:!0})},g=function(S){if(p.paused||!a)return;const I=S.relatedTarget;I!==null&&(a.contains(I)||Kn(f.current,{select:!0}))},y=function(S){if(document.activeElement===document.body)for(const C of S)C.removedNodes.length>0&&Kn(a)};document.addEventListener("focusin",x),document.addEventListener("focusout",g);const b=new MutationObserver(y);return a&&b.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",x),document.removeEventListener("focusout",g),b.disconnect()}}},[r,a,p.paused]),m.useEffect(()=>{if(a){yd.add(p);const x=document.activeElement;if(!a.contains(x)){const y=new CustomEvent(va,md);a.addEventListener(va,u),a.dispatchEvent(y),y.defaultPrevented||(Qv(ob(gd(a)),{select:!0}),document.activeElement===x&&Kn(a))}return()=>{a.removeEventListener(va,u),setTimeout(()=>{const y=new CustomEvent(ba,md);a.addEventListener(ba,d),a.dispatchEvent(y),y.defaultPrevented||Kn(x??document.body,{select:!0}),a.removeEventListener(ba,d),yd.remove(p)},0)}}},[a,u,d,p]);const v=m.useCallback(x=>{if(!n&&!r||p.paused)return;const g=x.key==="Tab"&&!x.altKey&&!x.ctrlKey&&!x.metaKey,y=document.activeElement;if(g&&y){const b=x.currentTarget,[S,I]=eb(b);S&&I?!x.shiftKey&&y===I?(x.preventDefault(),n&&Kn(S,{select:!0})):x.shiftKey&&y===S&&(x.preventDefault(),n&&Kn(I,{select:!0})):y===b&&x.preventDefault()}},[n,r,p.paused]);return c.jsx(Ae.div,{tabIndex:-1,...i,ref:h,onKeyDown:v})});vs.displayName=Zv;function Qv(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Kn(r,{select:t}),document.activeElement!==n)return}function eb(e){const t=gd(e),n=xd(t,e),r=xd(t.reverse(),e);return[n,r]}function gd(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 xd(e,t){for(const n of e)if(!tb(n,{upTo:t}))return n}function tb(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 nb(e){return e instanceof HTMLInputElement&&"select"in e}function Kn(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&nb(e)&&t&&e.select()}}var yd=rb();function rb(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=vd(e,t),e.unshift(t)},remove(t){var n;e=vd(e,t),(n=e[0])==null||n.resume()}}}function vd(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function ob(e){return e.filter(t=>t.tagName!=="A")}var sb="Portal",bs=m.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=m.useState(!1);wt(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?di.createPortal(c.jsx(Ae.div,{...r,ref:t}),i):null});bs.displayName=sb;var wa=0;function Sa(){m.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??bd()),document.body.insertAdjacentElement("beforeend",e[1]??bd()),wa++,()=>{wa===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),wa--}},[])}function bd(){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 Cn=function(){return Cn=Object.assign||function(t){for(var n,r=1,o=arguments.length;r<o;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},Cn.apply(this,arguments)};function wd(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 ib(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",Ss="width-before-scroll-bar",ab="with-scroll-bars-hidden",lb="--removed-body-scroll-bar-size";function Ca(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function cb(e,t){var n=w.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 ub=typeof window<"u"?m.useLayoutEffect:m.useEffect,Sd=new WeakMap;function db(e,t){var n=cb(null,function(r){return e.forEach(function(o){return Ca(o,r)})});return ub(function(){var r=Sd.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Ca(a,null)}),s.forEach(function(a){o.has(a)||Ca(a,i)})}Sd.set(n,e)},[e]),n}function fb(e){return e}function hb(e,t){t===void 0&&(t=fb);var n=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var d=i;i=[],d.forEach(s)},u=function(){return Promise.resolve().then(l)};u(),n={push:function(d){i.push(d),u()},filter:function(d){return i=i.filter(d),n}}}};return o}function pb(e){e===void 0&&(e={});var t=hb(null);return t.options=Cn({async:!0,ssr:!1},e),t}var Cd=function(e){var t=e.sideCar,n=wd(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 m.createElement(r,Cn({},n))};Cd.isSideCarExport=!0;function mb(e,t){return e.useMedium(t),Cd}var Td=pb(),Ta=function(){},Cs=m.forwardRef(function(e,t){var n=m.useRef(null),r=m.useState({onScrollCapture:Ta,onWheelCapture:Ta,onTouchMoveCapture:Ta}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,u=e.removeScrollBar,d=e.enabled,f=e.shards,h=e.sideCar,p=e.noRelative,v=e.noIsolation,x=e.inert,g=e.allowPinchZoom,y=e.as,b=y===void 0?"div":y,S=e.gapMode,I=wd(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=h,T=db([n,t]),E=Cn(Cn({},I),o);return m.createElement(m.Fragment,null,d&&m.createElement(C,{sideCar:Td,removeScrollBar:u,shards:f,noRelative:p,noIsolation:v,inert:x,setCallbacks:s,allowPinchZoom:!!g,lockRef:n,gapMode:S}),i?m.cloneElement(m.Children.only(a),Cn(Cn({},E),{ref:T})):m.createElement(b,Cn({},E,{className:l,ref:T}),a))});Cs.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Cs.classNames={fullWidth:Ss,zeroRight:ws};var gb=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function xb(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=gb();return t&&e.setAttribute("nonce",t),e}function yb(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function vb(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var bb=function(){var e=0,t=null;return{add:function(n){e==0&&(t=xb())&&(yb(t,n),vb(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},wb=function(){var e=bb();return function(t,n){m.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},kd=function(){var e=wb(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Sb={left:0,top:0,right:0,gap:0},ka=function(e){return parseInt(e||"",10)||0},Cb=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[ka(n),ka(r),ka(o)]},Tb=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Sb;var t=Cb(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])}},kb=kd(),jr="data-scroll-locked",Eb=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
81
|
+
`}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=ed(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=ed(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 sd{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 id{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 Wn{constructor(t){this.options=t||ur,this.options.renderer=this.options.renderer||new da,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new sd,this.slugger=new id}static parse(t,n){return new Wn(n).parse(t)}static parseInline(t,n){return new Wn(n).parseInline(t)}parse(t,n=!0){let r="",o,s,i,a,l,u,d,f,h,p,v,x,g,y,b,S,I,C,T;const E=t.length;for(o=0;o<E;o++){if(p=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[p.type]&&(T=this.options.extensions.renderers[p.type].call({parser:this},p),T!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(p.type))){r+=T||"";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,Qu(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="",d="",a=p.header.length,s=0;s<a;s++)d+=this.renderer.tablecell(this.parseInline(p.header[s].tokens),{header:!0,align:p.align[s]});for(f+=this.renderer.tablerow(d),h="",a=p.rows.length,s=0;s<a;s++){for(u=p.rows[s],d="",l=u.length,i=0;i<l;i++)d+=this.renderer.tablecell(this.parseInline(u[i].tokens),{header:!1,align:p.align[i]});h+=this.renderer.tablerow(d)}r+=this.renderer.table(f,h);continue}case"blockquote":{h=this.parse(p.tokens),r+=this.renderer.blockquote(h);continue}case"list":{for(v=p.ordered,x=p.start,g=p.loose,a=p.items.length,h="",s=0;s<a;s++)b=p.items[s],S=b.checked,I=b.task,y="",b.task&&(C=this.renderer.checkbox(S),g?b.tokens.length>0&&b.tokens[0].type==="paragraph"?(b.tokens[0].text=C+" "+b.tokens[0].text,b.tokens[0].tokens&&b.tokens[0].tokens.length>0&&b.tokens[0].tokens[0].type==="text"&&(b.tokens[0].tokens[0].text=C+" "+b.tokens[0].tokens[0].text)):b.tokens.unshift({type:"text",text:C}):y+=C),y+=this.parse(b.tokens,g),h+=this.renderer.listitem(y,I,S);r+=this.renderer.list(h,v,x);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<E&&t[o+1].type==="text";)p=t[++o],h+=`
|
|
82
|
+
`+(p.tokens?this.parseInline(p.tokens):p.text);r+=n?this.renderer.paragraph(h):h;continue}default:{const A='Token with "'+p.type+'" type was not found.';if(this.options.silent){console.error(A);return}else throw new Error(A)}}}return r}parseInline(t,n){n=n||this.renderer;let r="",o,s,i;const a=t.length;for(o=0;o<a;o++){if(s=t[o],this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[s.type]&&(i=this.options.extensions.renderers[s.type].call({parser:this},s),i!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type))){r+=i||"";continue}switch(s.type){case"escape":{r+=n.text(s.text);break}case"html":{r+=n.html(s.text);break}case"link":{r+=n.link(s.href,s.title,this.parseInline(s.tokens,n));break}case"image":{r+=n.image(s.href,s.title,s.text);break}case"strong":{r+=n.strong(this.parseInline(s.tokens,n));break}case"em":{r+=n.em(this.parseInline(s.tokens,n));break}case"codespan":{r+=n.codespan(s.text);break}case"br":{r+=n.br();break}case"del":{r+=n.del(this.parseInline(s.tokens,n));break}case"text":{r+=n.text(s.text);break}default:{const l='Token with "'+s.type+'" type was not found.';if(this.options.silent){console.error(l);return}else throw new Error(l)}}}return r}}class fs{constructor(t){this.options=t||ur}preprocess(t){return t}postprocess(t){return t}}wm(fs,"passThroughHooks",new Set(["preprocess","postprocess"]));function Dv(e,t,n){return r=>{if(r.message+=`
|
|
83
|
+
Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+_t(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 ad(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...Ce.defaults,...s};const i=Dv(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(Pv(r),r.hooks&&(r.hooks.options=r),o){const a=r.highlight;let l;try{r.hooks&&(n=r.hooks.preprocess(n)),l=e(n,r)}catch(f){return i(f)}const u=function(f){let h;if(!f)try{r.walkTokens&&Ce.walkTokens(l,r.walkTokens),h=t(l,r),r.hooks&&(h=r.hooks.postprocess(h))}catch(p){f=p}return r.highlight=a,f?i(f):o(null,h)};if(!a||a.length<3||(delete r.highlight,!l.length))return u();let d=0;Ce.walkTokens(l,function(f){f.type==="code"&&(d++,setTimeout(()=>{a(f.text,f.lang,function(h,p){if(h)return u(h);p!=null&&p!==f.text&&(f.text=p,f.escaped=!0),d--,d===0&&u()})},0))}),d===0&&u();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(Ce.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&&Ce.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function Ce(e,t,n){return ad(Un.lex,Wn.parse)(e,t,n)}Ce.options=Ce.setOptions=function(e){return Ce.defaults={...Ce.defaults,...e},bv(Ce.defaults),Ce},Ce.getDefaults=Yu,Ce.defaults=ur,Ce.use=function(...e){const t=Ce.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=Ce.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=Ce.defaults.renderer||new da;for(const s in n.renderer){const i=o[s];o[s]=(...a)=>{let l=n.renderer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.renderer=o}if(n.tokenizer){const o=Ce.defaults.tokenizer||new ua;for(const s in n.tokenizer){const i=o[s];o[s]=(...a)=>{let l=n.tokenizer[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.tokenizer=o}if(n.hooks){const o=Ce.defaults.hooks||new fs;for(const s in n.hooks){const i=o[s];fs.passThroughHooks.has(s)?o[s]=a=>{if(Ce.defaults.async)return Promise.resolve(n.hooks[s].call(o,a)).then(u=>i.call(o,u));const l=n.hooks[s].call(o,a);return i.call(o,l)}:o[s]=(...a)=>{let l=n.hooks[s].apply(o,a);return l===!1&&(l=i.apply(o,a)),l}}r.hooks=o}if(n.walkTokens){const o=Ce.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}}Ce.setOptions(r)})},Ce.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(Ce,r)),r.type){case"table":{for(const o of r.header)n=n.concat(Ce.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(Ce.walkTokens(s.tokens,t));break}case"list":{n=n.concat(Ce.walkTokens(r.items,t));break}default:Ce.defaults.extensions&&Ce.defaults.extensions.childTokens&&Ce.defaults.extensions.childTokens[r.type]?Ce.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(Ce.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(Ce.walkTokens(r.tokens,t)))}return n},Ce.parseInline=ad(Un.lexInline,Wn.parseInline),Ce.Parser=Wn,Ce.parser=Wn.parse,Ce.Renderer=da,Ce.TextRenderer=sd,Ce.Lexer=Un,Ce.lexer=Un.lex,Ce.Tokenizer=ua,Ce.Slugger=id,Ce.Hooks=fs,Ce.parse=Ce,Ce.options,Ce.setOptions,Ce.use,Ce.walkTokens,Ce.parseInline,Wn.parse,Un.lex;function fa({content:e,className:t="",allowHtml:n=!1,style:r}){const o=w.useMemo(()=>{try{if(!n){const i=e.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi,"").replace(/javascript:/gi,"").replace(/on\w+\s*=/gi,"");return Ce.parse(i)}return Ce.parse(e)}catch(i){return console.error("[MarkdownContent] parse error",i),`<pre>Error rendering markdown: ${String(i)}</pre>`}},[e,n]),s=w.useMemo(()=>{if(r&&r.color){const i=r.color;return{...r,"--tw-prose-body":i,"--tw-prose-headings":i,"--tw-prose-links":i,"--tw-prose-bold":i,"--tw-prose-counters":i,"--tw-prose-bullets":i,"--tw-prose-hr":i,"--tw-prose-quotes":i,"--tw-prose-quote-borders":i,"--tw-prose-captions":i,"--tw-prose-code":i,"--tw-prose-pre-code":i,"--tw-prose-pre-bg":"inherit","--tw-prose-th-borders":i,"--tw-prose-td-borders":i}}return r},[r]);return c.jsx("div",{className:ee("markdown prose max-w-none break-words dark:prose-invert",t),style:s,dangerouslySetInnerHTML:{__html:o}})}async function ld(e,t){return await pn(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function cd(e,t){return await(await ld(`/files/${e}/view`,t)).text()}async function Lv(e,t){const n=await ld(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await pn(`/files/${e}`);o=(i==null?void 0:i.filename)??o}catch{}const s=document.createElement("a");s.href=r,s.download=o,document.body.appendChild(s),s.click(),s.remove(),setTimeout(()=>URL.revokeObjectURL(r),6e4)}async function $v(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await pn("/files",{params:r})}const Fv=1,zv=1e6;let ha=0;function Bv(){return ha=(ha+1)%Number.MAX_SAFE_INTEGER,ha.toString()}const pa=new Map,ud=e=>{if(pa.has(e))return;const t=setTimeout(()=>{pa.delete(e),uo({type:"REMOVE_TOAST",toastId:e})},zv);pa.set(e,t)},Hv=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,Fv)};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?ud(n):e.toasts.forEach(r=>{ud(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)}}},hs=[];let ps={toasts:[]};function uo(e){ps=Hv(ps,e),hs.forEach(t=>{t(ps)})}function Uv({...e}){const t=Bv(),n=o=>uo({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>uo({type:"DISMISS_TOAST",toastId:t});return uo({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function ma(){const[e,t]=m.useState(ps);return m.useEffect(()=>(hs.push(t),()=>{const n=hs.indexOf(t);n>-1&&hs.splice(n,1)}),[e]),{...e,toast:Uv,dismiss:n=>uo({type:"DISMISS_TOAST",toastId:n})}}function kt(e){const t=m.useRef(e);return m.useEffect(()=>{t.current=e}),m.useMemo(()=>(...n)=>{var r;return(r=t.current)==null?void 0:r.call(t,...n)},[])}function Wv(e,t=globalThis==null?void 0:globalThis.document){const n=kt(e);m.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 Vv="DismissableLayer",ga="dismissableLayer.update",Kv="dismissableLayer.pointerDownOutside",qv="dismissableLayer.focusOutside",dd,fd=m.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),ms=m.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,u=m.useContext(fd),[d,f]=m.useState(null),h=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=m.useState({}),v=He(t,E=>f(E)),x=Array.from(u.layers),[g]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),y=x.indexOf(g),b=d?x.indexOf(d):-1,S=u.layersWithOutsidePointerEventsDisabled.size>0,I=b>=y,C=Xv(E=>{const A=E.target,j=[...u.branches].some(P=>P.contains(A));!I||j||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},h),T=Jv(E=>{const A=E.target;[...u.branches].some(P=>P.contains(A))||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},h);return Wv(E=>{b===u.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},h),m.useEffect(()=>{if(d)return n&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(dd=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(d)),u.layers.add(d),hd(),()=>{n&&u.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=dd)}},[d,h,n,u]),m.useEffect(()=>()=>{d&&(u.layers.delete(d),u.layersWithOutsidePointerEventsDisabled.delete(d),hd())},[d,u]),m.useEffect(()=>{const E=()=>p({});return document.addEventListener(ga,E),()=>document.removeEventListener(ga,E)},[]),c.jsx(Ae.div,{...l,ref:v,style:{pointerEvents:S?I?"auto":"none":void 0,...e.style},onFocusCapture:ue(e.onFocusCapture,T.onFocusCapture),onBlurCapture:ue(e.onBlurCapture,T.onBlurCapture),onPointerDownCapture:ue(e.onPointerDownCapture,C.onPointerDownCapture)})});ms.displayName=Vv;var Gv="DismissableLayerBranch",Yv=m.forwardRef((e,t)=>{const n=m.useContext(fd),r=m.useRef(null),o=He(t,r);return m.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),c.jsx(Ae.div,{...e,ref:o})});Yv.displayName=Gv;function Xv(e,t=globalThis==null?void 0:globalThis.document){const n=kt(e),r=m.useRef(!1),o=m.useRef(()=>{});return m.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){pd(Kv,n,u,{discrete:!0})};const u={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=l,t.addEventListener("click",o.current,{once:!0})):l()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function Jv(e,t=globalThis==null?void 0:globalThis.document){const n=kt(e),r=m.useRef(!1);return m.useEffect(()=>{const o=s=>{s.target&&!r.current&&pd(qv,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 hd(){const e=new CustomEvent(ga);document.dispatchEvent(e)}function pd(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?Bu(o,s):o.dispatchEvent(s)}var xa="focusScope.autoFocusOnMount",ya="focusScope.autoFocusOnUnmount",md={bubbles:!1,cancelable:!0},Zv="FocusScope",gs=m.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=m.useState(null),u=kt(o),d=kt(s),f=m.useRef(null),h=He(t,x=>l(x)),p=m.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;m.useEffect(()=>{if(r){let x=function(S){if(p.paused||!a)return;const I=S.target;a.contains(I)?f.current=I:Vn(f.current,{select:!0})},g=function(S){if(p.paused||!a)return;const I=S.relatedTarget;I!==null&&(a.contains(I)||Vn(f.current,{select:!0}))},y=function(S){if(document.activeElement===document.body)for(const C of S)C.removedNodes.length>0&&Vn(a)};document.addEventListener("focusin",x),document.addEventListener("focusout",g);const b=new MutationObserver(y);return a&&b.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",x),document.removeEventListener("focusout",g),b.disconnect()}}},[r,a,p.paused]),m.useEffect(()=>{if(a){yd.add(p);const x=document.activeElement;if(!a.contains(x)){const y=new CustomEvent(xa,md);a.addEventListener(xa,u),a.dispatchEvent(y),y.defaultPrevented||(Qv(ob(gd(a)),{select:!0}),document.activeElement===x&&Vn(a))}return()=>{a.removeEventListener(xa,u),setTimeout(()=>{const y=new CustomEvent(ya,md);a.addEventListener(ya,d),a.dispatchEvent(y),y.defaultPrevented||Vn(x??document.body,{select:!0}),a.removeEventListener(ya,d),yd.remove(p)},0)}}},[a,u,d,p]);const v=m.useCallback(x=>{if(!n&&!r||p.paused)return;const g=x.key==="Tab"&&!x.altKey&&!x.ctrlKey&&!x.metaKey,y=document.activeElement;if(g&&y){const b=x.currentTarget,[S,I]=eb(b);S&&I?!x.shiftKey&&y===I?(x.preventDefault(),n&&Vn(S,{select:!0})):x.shiftKey&&y===S&&(x.preventDefault(),n&&Vn(I,{select:!0})):y===b&&x.preventDefault()}},[n,r,p.paused]);return c.jsx(Ae.div,{tabIndex:-1,...i,ref:h,onKeyDown:v})});gs.displayName=Zv;function Qv(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Vn(r,{select:t}),document.activeElement!==n)return}function eb(e){const t=gd(e),n=xd(t,e),r=xd(t.reverse(),e);return[n,r]}function gd(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 xd(e,t){for(const n of e)if(!tb(n,{upTo:t}))return n}function tb(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 nb(e){return e instanceof HTMLInputElement&&"select"in e}function Vn(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&nb(e)&&t&&e.select()}}var yd=rb();function rb(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=vd(e,t),e.unshift(t)},remove(t){var n;e=vd(e,t),(n=e[0])==null||n.resume()}}}function vd(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function ob(e){return e.filter(t=>t.tagName!=="A")}var sb="Portal",xs=m.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=m.useState(!1);bt(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?ui.createPortal(c.jsx(Ae.div,{...r,ref:t}),i):null});xs.displayName=sb;var va=0;function ba(){m.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??bd()),document.body.insertAdjacentElement("beforeend",e[1]??bd()),va++,()=>{va===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),va--}},[])}function bd(){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 bn=function(){return bn=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},bn.apply(this,arguments)};function wd(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 ib(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 ys="right-scroll-bar-position",vs="width-before-scroll-bar",ab="with-scroll-bars-hidden",lb="--removed-body-scroll-bar-size";function wa(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function cb(e,t){var n=w.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 ub=typeof window<"u"?m.useLayoutEffect:m.useEffect,Sd=new WeakMap;function db(e,t){var n=cb(null,function(r){return e.forEach(function(o){return wa(o,r)})});return ub(function(){var r=Sd.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||wa(a,null)}),s.forEach(function(a){o.has(a)||wa(a,i)})}Sd.set(n,e)},[e]),n}function fb(e){return e}function hb(e,t){t===void 0&&(t=fb);var n=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return n.length?n[n.length-1]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var d=i;i=[],d.forEach(s)},u=function(){return Promise.resolve().then(l)};u(),n={push:function(d){i.push(d),u()},filter:function(d){return i=i.filter(d),n}}}};return o}function pb(e){e===void 0&&(e={});var t=hb(null);return t.options=bn({async:!0,ssr:!1},e),t}var Cd=function(e){var t=e.sideCar,n=wd(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 m.createElement(r,bn({},n))};Cd.isSideCarExport=!0;function mb(e,t){return e.useMedium(t),Cd}var Td=pb(),Sa=function(){},bs=m.forwardRef(function(e,t){var n=m.useRef(null),r=m.useState({onScrollCapture:Sa,onWheelCapture:Sa,onTouchMoveCapture:Sa}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,u=e.removeScrollBar,d=e.enabled,f=e.shards,h=e.sideCar,p=e.noRelative,v=e.noIsolation,x=e.inert,g=e.allowPinchZoom,y=e.as,b=y===void 0?"div":y,S=e.gapMode,I=wd(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),C=h,T=db([n,t]),E=bn(bn({},I),o);return m.createElement(m.Fragment,null,d&&m.createElement(C,{sideCar:Td,removeScrollBar:u,shards:f,noRelative:p,noIsolation:v,inert:x,setCallbacks:s,allowPinchZoom:!!g,lockRef:n,gapMode:S}),i?m.cloneElement(m.Children.only(a),bn(bn({},E),{ref:T})):m.createElement(b,bn({},E,{className:l,ref:T}),a))});bs.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},bs.classNames={fullWidth:vs,zeroRight:ys};var gb=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function xb(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=gb();return t&&e.setAttribute("nonce",t),e}function yb(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function vb(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var bb=function(){var e=0,t=null;return{add:function(n){e==0&&(t=xb())&&(yb(t,n),vb(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},wb=function(){var e=bb();return function(t,n){m.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},kd=function(){var e=wb(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Sb={left:0,top:0,right:0,gap:0},Ca=function(e){return parseInt(e||"",10)||0},Cb=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[Ca(n),Ca(r),Ca(o)]},Tb=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Sb;var t=Cb(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])}},kb=kd(),Ar="data-scroll-locked",Eb=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
85
84
|
.`.concat(ab,` {
|
|
86
85
|
overflow: hidden `).concat(r,`;
|
|
87
86
|
padding-right: `).concat(a,"px ").concat(r,`;
|
|
88
87
|
}
|
|
89
|
-
body[`).concat(
|
|
88
|
+
body[`).concat(Ar,`] {
|
|
90
89
|
overflow: hidden `).concat(r,`;
|
|
91
90
|
overscroll-behavior: contain;
|
|
92
91
|
`).concat([t&&"position: relative ".concat(r,";"),n==="margin"&&`
|
|
@@ -99,37 +98,37 @@ Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An err
|
|
|
99
98
|
`),n==="padding"&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),`
|
|
100
99
|
}
|
|
101
100
|
|
|
102
|
-
.`).concat(
|
|
101
|
+
.`).concat(ys,` {
|
|
103
102
|
right: `).concat(a,"px ").concat(r,`;
|
|
104
103
|
}
|
|
105
104
|
|
|
106
|
-
.`).concat(
|
|
105
|
+
.`).concat(vs,` {
|
|
107
106
|
margin-right: `).concat(a,"px ").concat(r,`;
|
|
108
107
|
}
|
|
109
108
|
|
|
110
|
-
.`).concat(
|
|
109
|
+
.`).concat(ys," .").concat(ys,` {
|
|
111
110
|
right: 0 `).concat(r,`;
|
|
112
111
|
}
|
|
113
112
|
|
|
114
|
-
.`).concat(
|
|
113
|
+
.`).concat(vs," .").concat(vs,` {
|
|
115
114
|
margin-right: 0 `).concat(r,`;
|
|
116
115
|
}
|
|
117
116
|
|
|
118
|
-
body[`).concat(
|
|
117
|
+
body[`).concat(Ar,`] {
|
|
119
118
|
`).concat(lb,": ").concat(a,`px;
|
|
120
119
|
}
|
|
121
|
-
`)},Ed=function(){var e=parseInt(document.body.getAttribute(
|
|
120
|
+
`)},Ed=function(){var e=parseInt(document.body.getAttribute(Ar)||"0",10);return isFinite(e)?e:0},Ib=function(){m.useEffect(function(){return document.body.setAttribute(Ar,(Ed()+1).toString()),function(){var e=Ed()-1;e<=0?document.body.removeAttribute(Ar):document.body.setAttribute(Ar,e.toString())}},[])},Nb=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;Ib();var s=m.useMemo(function(){return Tb(o)},[o]);return m.createElement(kb,{styles:Eb(s,!t,o,n?"":"!important")})},Ta=!1;if(typeof window<"u")try{var ws=Object.defineProperty({},"passive",{get:function(){return Ta=!0,!0}});window.addEventListener("test",ws,ws),window.removeEventListener("test",ws,ws)}catch{Ta=!1}var _r=Ta?{passive:!1}:!1,Ab=function(e){return e.tagName==="TEXTAREA"},Id=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!Ab(e)&&n[t]==="visible")},_b=function(e){return Id(e,"overflowY")},jb=function(e){return Id(e,"overflowX")},Nd=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=Ad(e,r);if(o){var s=_d(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Rb=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},Pb=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},Ad=function(e,t){return e==="v"?_b(t):jb(t)},_d=function(e,t){return e==="v"?Rb(t):Pb(t)},Ob=function(e,t){return e==="h"&&t==="rtl"?-1:1},Mb=function(e,t,n,r,o){var s=Ob(e,window.getComputedStyle(t).direction),i=s*r,a=n.target,l=t.contains(a),u=!1,d=i>0,f=0,h=0;do{if(!a)break;var p=_d(e,a),v=p[0],x=p[1],g=p[2],y=x-g-s*v;(v||y)&&Ad(e,a)&&(f+=y,h+=v);var b=a.parentNode;a=b&&b.nodeType===Node.DOCUMENT_FRAGMENT_NODE?b.host:b}while(!l&&a!==document.body||l&&(t.contains(a)||t===a));return(d&&Math.abs(f)<1||!d&&Math.abs(h)<1)&&(u=!0),u},Ss=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},jd=function(e){return[e.deltaX,e.deltaY]},Rd=function(e){return e&&"current"in e?e.current:e},Db=function(e,t){return e[0]===t[0]&&e[1]===t[1]},Lb=function(e){return`
|
|
122
121
|
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
123
122
|
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
124
|
-
`)},$b=0,
|
|
123
|
+
`)},$b=0,jr=[];function Fb(e){var t=m.useRef([]),n=m.useRef([0,0]),r=m.useRef(),o=m.useState($b++)[0],s=m.useState(kd)[0],i=m.useRef(e);m.useEffect(function(){i.current=e},[e]),m.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var x=ib([e.lockRef.current],(e.shards||[]).map(Rd),!0).filter(Boolean);return x.forEach(function(g){return g.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),x.forEach(function(g){return g.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=m.useCallback(function(x,g){if("touches"in x&&x.touches.length===2||x.type==="wheel"&&x.ctrlKey)return!i.current.allowPinchZoom;var y=Ss(x),b=n.current,S="deltaX"in x?x.deltaX:b[0]-y[0],I="deltaY"in x?x.deltaY:b[1]-y[1],C,T=x.target,E=Math.abs(S)>Math.abs(I)?"h":"v";if("touches"in x&&E==="h"&&T.type==="range")return!1;var A=Nd(E,T);if(!A)return!0;if(A?C=E:(C=E==="v"?"h":"v",A=Nd(E,T)),!A)return!1;if(!r.current&&"changedTouches"in x&&(S||I)&&(r.current=C),!C)return!0;var j=r.current||C;return Mb(j,g,x,j==="h"?S:I)},[]),l=m.useCallback(function(x){var g=x;if(!(!jr.length||jr[jr.length-1]!==s)){var y="deltaY"in g?jd(g):Ss(g),b=t.current.filter(function(C){return C.name===g.type&&(C.target===g.target||g.target===C.shadowParent)&&Db(C.delta,y)})[0];if(b&&b.should){g.cancelable&&g.preventDefault();return}if(!b){var S=(i.current.shards||[]).map(Rd).filter(Boolean).filter(function(C){return C.contains(g.target)}),I=S.length>0?a(g,S[0]):!i.current.noIsolation;I&&g.cancelable&&g.preventDefault()}}},[]),u=m.useCallback(function(x,g,y,b){var S={name:x,delta:g,target:y,should:b,shadowParent:zb(y)};t.current.push(S),setTimeout(function(){t.current=t.current.filter(function(I){return I!==S})},1)},[]),d=m.useCallback(function(x){n.current=Ss(x),r.current=void 0},[]),f=m.useCallback(function(x){u(x.type,jd(x),x.target,a(x,e.lockRef.current))},[]),h=m.useCallback(function(x){u(x.type,Ss(x),x.target,a(x,e.lockRef.current))},[]);m.useEffect(function(){return jr.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:h}),document.addEventListener("wheel",l,_r),document.addEventListener("touchmove",l,_r),document.addEventListener("touchstart",d,_r),function(){jr=jr.filter(function(x){return x!==s}),document.removeEventListener("wheel",l,_r),document.removeEventListener("touchmove",l,_r),document.removeEventListener("touchstart",d,_r)}},[]);var p=e.removeScrollBar,v=e.inert;return m.createElement(m.Fragment,null,v?m.createElement(s,{styles:Lb(o)}):null,p?m.createElement(Nb,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function zb(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const Bb=mb(Td,Fb);var Cs=m.forwardRef(function(e,t){return m.createElement(bs,bn({},e,{ref:t,sideCar:Bb}))});Cs.classNames=bs.classNames;var Hb=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Rr=new WeakMap,Ts=new WeakMap,ks={},ka=0,Pd=function(e){return e&&(e.host||Pd(e.parentNode))},Ub=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=Pd(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})},Wb=function(e,t,n,r){var o=Ub(t,Array.isArray(e)?e:[e]);ks[n]||(ks[n]=new WeakMap);var s=ks[n],i=[],a=new Set,l=new Set(o),u=function(f){!f||a.has(f)||(a.add(f),u(f.parentNode))};o.forEach(u);var d=function(f){!f||l.has(f)||Array.prototype.forEach.call(f.children,function(h){if(a.has(h))d(h);else try{var p=h.getAttribute(r),v=p!==null&&p!=="false",x=(Rr.get(h)||0)+1,g=(s.get(h)||0)+1;Rr.set(h,x),s.set(h,g),i.push(h),x===1&&v&&Ts.set(h,!0),g===1&&h.setAttribute(n,"true"),v||h.setAttribute(r,"true")}catch(y){console.error("aria-hidden: cannot operate on ",h,y)}})};return d(t),a.clear(),ka++,function(){i.forEach(function(f){var h=Rr.get(f)-1,p=s.get(f)-1;Rr.set(f,h),s.set(f,p),h||(Ts.has(f)||f.removeAttribute(r),Ts.delete(f)),p||f.removeAttribute(n)}),ka--,ka||(Rr=new WeakMap,Rr=new WeakMap,Ts=new WeakMap,ks={})}},Ea=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=Hb(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),Wb(r,o,n,"aria-hidden")):function(){return null}},Es="Dialog",[Od,nk]=yn(Es),[Vb,an]=Od(Es),Md=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=m.useRef(null),l=m.useRef(null),[u,d]=cr({prop:r,defaultProp:o??!1,onChange:s,caller:Es});return c.jsx(Vb,{scope:t,triggerRef:a,contentRef:l,contentId:vn(),titleId:vn(),descriptionId:vn(),open:u,onOpenChange:d,onOpenToggle:m.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};Md.displayName=Es;var Dd="DialogTrigger",Ld=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=an(Dd,n),s=He(t,o.triggerRef);return c.jsx(Ae.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Aa(o.open),...r,ref:s,onClick:ue(e.onClick,o.onOpenToggle)})});Ld.displayName=Dd;var Ia="DialogPortal",[Kb,$d]=Od(Ia,{forceMount:void 0}),Fd=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=an(Ia,t);return c.jsx(Kb,{scope:t,forceMount:n,children:m.Children.map(r,i=>c.jsx(Wt,{present:n||s.open,children:c.jsx(xs,{asChild:!0,container:o,children:i})}))})};Fd.displayName=Ia;var Is="DialogOverlay",zd=m.forwardRef((e,t)=>{const n=$d(Is,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=an(Is,e.__scopeDialog);return s.modal?c.jsx(Wt,{present:r||s.open,children:c.jsx(Gb,{...o,ref:t})}):null});zd.displayName=Is;var qb=tr.createSlot("DialogOverlay.RemoveScroll"),Gb=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=an(Is,n);return c.jsx(Cs,{as:qb,allowPinchZoom:!0,shards:[o.contentRef],children:c.jsx(Ae.div,{"data-state":Aa(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),dr="DialogContent",Bd=m.forwardRef((e,t)=>{const n=$d(dr,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=an(dr,e.__scopeDialog);return c.jsx(Wt,{present:r||s.open,children:s.modal?c.jsx(Yb,{...o,ref:t}):c.jsx(Xb,{...o,ref:t})})});Bd.displayName=dr;var Yb=m.forwardRef((e,t)=>{const n=an(dr,e.__scopeDialog),r=m.useRef(null),o=He(t,n.contentRef,r);return m.useEffect(()=>{const s=r.current;if(s)return Ea(s)},[]),c.jsx(Hd,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ue(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:ue(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:ue(e.onFocusOutside,s=>s.preventDefault())})}),Xb=m.forwardRef((e,t)=>{const n=an(dr,e.__scopeDialog),r=m.useRef(!1),o=m.useRef(!1);return c.jsx(Hd,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i,a;(i=e.onCloseAutoFocus)==null||i.call(e,s),s.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),s.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:s=>{var l,u;(l=e.onInteractOutside)==null||l.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const i=s.target;((u=n.triggerRef.current)==null?void 0:u.contains(i))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),Hd=m.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=an(dr,n),l=m.useRef(null),u=He(t,l);return ba(),c.jsxs(c.Fragment,{children:[c.jsx(gs,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:c.jsx(ms,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Aa(a.open),...i,ref:u,onDismiss:()=>a.onOpenChange(!1)})}),c.jsxs(c.Fragment,{children:[c.jsx(Jb,{titleId:a.titleId}),c.jsx(Qb,{contentRef:l,descriptionId:a.descriptionId})]})]})}),Na="DialogTitle",Ud=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=an(Na,n);return c.jsx(Ae.h2,{id:o.titleId,...r,ref:t})});Ud.displayName=Na;var Wd="DialogDescription",Vd=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=an(Wd,n);return c.jsx(Ae.p,{id:o.descriptionId,...r,ref:t})});Vd.displayName=Wd;var Kd="DialogClose",qd=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=an(Kd,n);return c.jsx(Ae.button,{type:"button",...r,ref:t,onClick:ue(e.onClick,()=>o.onOpenChange(!1))})});qd.displayName=Kd;function Aa(e){return e?"open":"closed"}var Gd="DialogTitleWarning",[rk,Yd]=ov(Gd,{contentName:dr,titleName:Na,docsSlug:"dialog"}),Jb=({titleId:e})=>{const t=Yd(Gd),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
|
|
125
124
|
|
|
126
125
|
If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
127
126
|
|
|
128
|
-
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return m.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},Zb="DialogDescriptionWarning",Qb=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Yd(Zb).contentName}}.`;return m.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},Xd=Md,ew=Ld,Jd=Fd,
|
|
129
|
-
… [truncated ${i.length-o} chars]`}catch{return""}},n=e.filter(r=>r.type==="tool_end");if(n.length)try{return n.length===1?t(n[0].output):t(n.map(r=>({toolCallId:r.toolCallId,output:r.output})))}catch{}return t(e)}function cw(e){const t=e.find(r=>r.type==="tool_end");if(!t)return null;const n=t.output;return typeof n=="string"?n:null}function uw(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function af(e){const t=e.updatedAt??e.createdAt??"",n=Array.isArray(e.content)?e.content.map(r=>{switch(r.type){case"text":return`t:${r.text.length}`;case"image_url":return"img";case"file":return"file";case"tool_call":return"call";case"tool_end":return"end";default:return"unknown"}}).join("|"):"";return`${e.id}:${t}:${n}`}function dw({className:e}){const[t,n]=w.useState(0);return w.useEffect(()=>{const r=setInterval(()=>n(o=>(o+1)%4),500);return()=>clearInterval(r)},[]),c.jsxs("span",{"aria-live":"polite",className:ee("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const lf=w.memo(function({message:t,messageIndex:n,isStreamingMessage:r=!1,isEditing:o=!1,showActions:s=!0,showTimestamp:i=!0,showAgentName:a=!0,layoutSize:l="desktop",truncateToolMessages:u=!0,toolMessagePreviewLength:d=200,truncateUserMessages:f=!0,userMessagePreviewLength:h=200,customStyles:p={},onEdit:v,onRegenerate:x,onCancelEdit:g,onCopy:y}){const[b,S]=w.useState(!1),[I,C]=w.useState("collapsed"),[T,E]=w.useState(!1),{currentThreadId:A}=
|
|
130
|
-
… [truncated ${G.length-
|
|
131
|
-
dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[D[se]?c.jsx(ie.Loader,{className:"h-4 w-4 animate-spin"}):null,c.jsxs("span",{className:"truncate max-w-[180px]",children:[Ie,D[se]?" (processing)":""]})]},se)}return B.type==="interrupt"?c.jsx(pw,{interruptPart:B,onApprove:
|
|
132
|
-
… [truncated ${xe.length-pr} chars]`:xe,Qe=I==="expanded";return c.jsxs(Vu,{open:Qe,onOpenChange:Fe=>C(Fe?"expanded":"preview"),children:[c.jsx("div",{className:"flex items-center gap-2 text-xs",children:c.jsx(aa,{variant:"outline",children:(we.name??"tool")+(we.toolCallId?` • ${we.toolCallId.slice(0,8)}`:"")})}),c.jsx("div",{className:"font-mono text-sm mt-1",children:c.jsx("pre",{className:"whitespace-pre-wrap break-words",children:Qe?Re:Re.slice(0,d)+(Re.length>d?"...":"")})}),c.jsx(Ku,{asChild:!0,children:c.jsx(Ge,{variant:"ghost",size:"sm",className:"h-6 text-xs",children:Qe?c.jsxs(c.Fragment,{children:[" ",c.jsx(ie.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):c.jsxs(c.Fragment,{children:[c.jsx(ie.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more"]})})})]},we.toolCallId??Ie)})})}if(!$){const se=c.jsx("div",{className:"space-y-2",children:t.content.map((we,Ie)=>c.jsx(ct,{part:we,i:Ie},Ie))});return r?c.jsxs("div",{"aria-busy":"true",role:"status",children:[se,c.jsx(dw,{className:F})]}):se}},[te,me.length,be.length,Te.length,r,t.model,$,fe.name,G,I,u,rt,F]),St=w.useMemo(()=>uw(t),[t]);return c.jsxs(c.Fragment,{children:[c.jsx("div",{className:ee(Ze(),p.container),children:c.jsxs("div",{className:ee(ve(),p.content),children:[(i||a||$)&&c.jsxs("div",{className:ee("flex items-center justify-between mb-2 pb-2 border-b border-current/10",q&&"mb-1 pb-1",F,p.header),children:[c.jsxs("div",{className:"flex items-center gap-2",children:[We(),a&&St&&c.jsx("span",{className:ee("font-medium",q?"text-xs":"text-sm"),children:St}),$&&fe.name&&c.jsxs(aa,{variant:"outline",className:ee("text-xs flex items-center gap-1 cursor-pointer",F,"border border-current/40",q&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":I!=="collapsed",onKeyDown:B=>{(B.key==="Enter"||B.key===" ")&&(B.preventDefault(),C(se=>se==="collapsed"?"preview":"collapsed"))},onClick:()=>C(B=>B==="collapsed"?"preview":"collapsed"),children:[c.jsx("span",{children:fe.name}),c.jsx("span",{className:"inline-flex items-center",children:I!=="collapsed"?c.jsx(ie.ChevronUp,{className:"h-3 w-3"}):c.jsx(ie.ChevronDown,{className:"h-3 w-3"})})]}),$&&!fe.name&&c.jsx(Ge,{variant:"ghost",size:"sm",className:ee("h-6 px-1",F,"hover:bg-foreground/10"),onClick:()=>C(B=>B==="collapsed"?"preview":"collapsed"),children:c.jsxs("span",{className:"text-xs flex items-center gap-1",children:["Tool Output ",I!=="collapsed"?c.jsx(ie.ChevronUp,{className:"h-3 w-3"}):c.jsx(ie.ChevronDown,{className:"h-3 w-3"})]})})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[i&&t.createdAt&&c.jsx("time",{className:ee("text-xs opacity-60",F,q&&"text-xs"),dateTime:new Date(t.createdAt).toISOString(),title:new Date(t.createdAt).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t.createdAt))}),s&&!o&&c.jsxs("div",{className:ee("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[c.jsxs("div",{className:"relative",children:[c.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>Z($?"visible":"all"),className:ee("h-6 w-6 p-0 hover:bg-foreground/10",F,q&&"h-5 w-5"),"aria-label":$?"Copy visible":"Copy message",title:$?"Copy visible portion":"Copy message",children:c.jsx(ie.Copy,{className:ee(b?"text-success":F,q?"h-3 w-3":"h-4 w-4")})}),$&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>Z("all"),className:ee("h-6 px-1 text-xs hover:bg-foreground/10",F),"aria-label":"Copy all (may be large)",title:"Copy all (may be large)",children:"all"})]}),z==="user"&&v&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:ne,className:ee("h-6 w-6 p-0 hover:bg-foreground/10",F,q&&"h-5 w-5"),"aria-label":"Edit message",children:c.jsx(ie.Edit,{className:ee(F,q?"h-3 w-3":"h-4 w-4")})}),z==="assistant"&&x&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:de,className:ee("h-6 w-6 p-0 hover:bg-foreground/10",F,q&&"h-5 w-5"),"aria-label":"Regenerate response",children:c.jsx(ie.RotateCcw,{className:ee(F,q?"h-3 w-3":"h-4 w-4")})})]})]})]}),c.jsx("div",{className:"relative",children:vt()}),$&&I==="expanded"&&(fe.toolCallId||fe.name)&&c.jsxs("div",{className:ee("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",q&&"text-xs"),children:[fe.name&&c.jsxs("div",{children:["Function: ",fe.name]}),fe.toolCallId&&c.jsxs("div",{children:["Call ID: ",fe.toolCallId]})]}),!(i||a||$)&&s&&!o&&c.jsxs("div",{className:ee("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[c.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>Z(),className:ee("h-6 w-6 p-0 hover:bg-background/50 text-current",q&&"h-5 w-5"),children:c.jsx(ie.Copy,{className:ee(b?"text-success":"text-current",q?"h-3 w-3":"h-4 w-4")})}),z==="user"&&v&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:ne,className:ee("h-6 w-6 p-0 hover:bg-background/50 text-current",q&&"h-5 w-5"),children:c.jsx(ie.Edit,{className:ee("text-current",q?"h-3 w-3":"h-4 w-4")})}),z==="assistant"&&x&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:de,className:ee("h-6 w-6 p-0 hover:bg-background/50 text-current",q&&"h-5 w-5"),children:c.jsx(ie.RotateCcw,{className:ee("text-current",q?"h-3 w-3":"h-4 w-4")})})]})]})}),Y&&c.jsx(ow,{isOpen:V,onClose:()=>{M(!1),K(null)},fileId:Y.id,fileName:Y.name,mimeType:Y.mimeType})]})},(e,t)=>{var i,a,l,u,d,f,h,p;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&af(e.message)===af(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateToolMessages","toolMessagePreviewLength","truncateUserMessages","userMessagePreviewLength"].every(v=>e[v]===t[v]),s=((i=e.customStyles)==null?void 0:i.container)===((a=t.customStyles)==null?void 0:a.container)&&((l=e.customStyles)==null?void 0:l.content)===((u=t.customStyles)==null?void 0:u.content)&&((d=e.customStyles)==null?void 0:d.actions)===((f=t.customStyles)==null?void 0:f.actions)&&((h=e.customStyles)==null?void 0:h.header)===((p=t.customStyles)==null?void 0:p.header);return o&&s});function fw({data:e}){if(Array.isArray(e))return e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?c.jsx("div",{className:Os,children:c.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>c.jsx("li",{children:String(n)},r))})}):c.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Ra(e)});if(e&&typeof e=="object"){const t=Array.isArray(e.distilled_facts)?e.distilled_facts:null,n=Array.isArray(e.follow_up_queries)?e.follow_up_queries:null,r=typeof e.is_sufficient=="boolean"?e.is_sufficient:void 0;if(t||n||typeof r=="boolean")return c.jsxs("div",{className:Os,children:[typeof r=="boolean"&&c.jsxs("p",{children:[c.jsx("strong",{children:"Is sufficient:"})," ",r?"Yes":"No"]}),n&&n.length>0&&c.jsxs("div",{children:[c.jsx("p",{children:c.jsx("strong",{children:"Follow-up queries:"})}),c.jsx("ul",{className:"list-disc pl-5",children:n.map((s,i)=>c.jsx("li",{children:String(s)},i))})]}),t&&t.length>0&&c.jsxs("div",{children:[c.jsx("p",{children:c.jsx("strong",{children:"Facts:"})}),c.jsx("ul",{className:"list-disc pl-5",children:t.map((s,i)=>c.jsx("li",{children:String(s)},i))})]})]});const o=Object.entries(e);return c.jsx("div",{className:Os,children:c.jsx("dl",{className:"mt-0",children:o.map(([s,i])=>c.jsxs("div",{className:"mb-1",children:[c.jsxs("dt",{className:"inline font-medium mr-1",children:[s,":"]}),c.jsx("dd",{className:"inline",children:hw(i)})]},s))})})}return c.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Ra(e)})}function hw(e){if(e==null)return String(e);const t=typeof e;if(t==="string"||t==="number"||t==="boolean")return String(e);if(Array.isArray(e)&&e.every(r=>r===null||["string","number","boolean"].includes(typeof r)))return e.join(", ");try{return c.jsx("code",{className:"text-xs",children:JSON.stringify(xo(e))})}catch{return String(e)}}function pw({interruptPart:e,onApprove:t,onReject:n}){const r=e.title??"Approve the result?";return c.jsxs(ho,{className:"border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10",children:[c.jsxs(po,{className:"pb-3",children:[c.jsx(mo,{className:"text-blue-900 dark:text-blue-100 text-base",children:r}),c.jsx(qu,{className:"text-blue-700 dark:text-blue-300",children:"Please approve or reject this action to continue."})]}),c.jsx(Gu,{className:"pt-0",children:c.jsxs("div",{className:"flex gap-2 ml-auto",children:[c.jsx(Ge,{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",children:"Reject"}),c.jsx(Ge,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",children:"Approve"})]})})]})}function mw({data:e}){return c.jsx("dl",{className:"grid grid-cols-1 gap-y-2",children:Object.entries(e).map(([t,n])=>c.jsxs("div",{className:"flex",children:[c.jsxs("dt",{className:"font-semibold mr-2",children:[t,":"]}),c.jsx("dd",{className:"flex-1 break-words",children:Array.isArray(n)?n.map((r,o)=>c.jsxs("div",{className:"ml-4 break-words",children:["- ",String(r)]},o)):String(n)})]},t))})}function gw({issues:e}){const t=[{key:"desirability",title:"Desirability"},{key:"feasibility",title:"Feasibility"},{key:"viability",title:"Viability"},{key:"other",title:"Other"}];return c.jsx("div",{className:Os,children:t.map(n=>{const r=e[n.key];return!r||!r.length?null:c.jsxs("div",{className:"mb-4",children:[c.jsxs("h4",{className:"font-semibold mb-2",children:[n.title," (",r.length,")"]}),c.jsx("ol",{className:"list-decimal pl-5 space-y-2",children:r.map((o,s)=>c.jsxs("li",{children:[c.jsx("div",{className:"font-medium",children:o.title}),c.jsx("div",{className:"text-sm text-muted-foreground",children:o.description})]},s))})]},n.key)})})}const cf=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,Pa=w.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:u,onCancelEdit:d,className:f,style:h,emptyMessage:p,followNewMessages:v=!0,isNavigatingCheckpoint:x=!1,onScrollAway:g,onAtBottom:y},b)=>{const S=w.useRef(null),I=w.useRef(null),C=w.useRef(!1),[T,E]=w.useState(!0),A=w.useCallback(D=>{E(D),g&&g(!D),y&&y(D)},[g,y]),j=w.useMemo(()=>{if(a)return async()=>{if(!C.current){C.current=!0;try{await a()}finally{C.current=!1}}}},[a]),P=w.useMemo(()=>!v||x?!1:T?"auto":!1,[T,v,x]);return e.length===0?c.jsx("div",{className:f,style:h,children:c.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-center max-w-md mx-auto",children:p||"No messages yet. Start a conversation!"})}):c.jsx("div",{className:f,style:h,children:c.jsx(Hy,{ref:D=>{S.current=D},scrollerRef:D=>{I.current=D instanceof HTMLDivElement?D:null},data:e,followOutput:P,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{j&&j()},atBottomStateChange:A,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(D,L)=>cf(L,D),itemContent:(D,L)=>{const V=cf(L,D);return c.jsx("div",{className:"mb-4 last:mb-0","data-message-id":V,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:c.jsx(lf,{message:L,messageIndex:D,isStreamingMessage:t&&n===L.id,streamingDebounceMs:r,isEditing:i===L.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,truncateToolMessages:!1,toolMessagePreviewLength:200,onEdit:l,onRegenerate:()=>u(D),onCancelEdit:d})})}})})});Pa.displayName="MessageList";const Ms=1e4;function xw(e){if(typeof e!="string")return String(e);const t=[/<script[^>]*>.*?<\/script>/gi,/<iframe[^>]*>.*?<\/iframe>/gi,/javascript:/gi,/vbscript:/gi,/on\w+\s*=/gi,/<object[^>]*>.*?<\/object>/gi,/<embed[^>]*>.*?<\/embed>/gi,/<form[^>]*>.*?<\/form>/gi];let n=e;for(const o of t)n=n.replace(o,"");return/<[^>]+>/.test(n)&&!/<(?!\/?(?:code|strong|em|b|i|br|p|ul|ol|li|h[1-6])\b)[^>]+>/i.test(n)?n.replace(/<code>(.*?)<\/code>/gi,"`$1`").replace(/<strong>(.*?)<\/strong>/gi,"**$1**").replace(/<b>(.*?)<\/b>/gi,"**$1**").replace(/<em>(.*?)<\/em>/gi,"*$1*").replace(/<i>(.*?)<\/i>/gi,"*$1*").replace(/<br\s*\/?>/gi,`
|
|
127
|
+
For more information, see https://radix-ui.com/primitives/docs/components/${t.docsSlug}`;return m.useEffect(()=>{e&&(document.getElementById(e)||console.error(n))},[n,e]),null},Zb="DialogDescriptionWarning",Qb=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Yd(Zb).contentName}}.`;return m.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},Xd=Md,ew=Ld,Jd=Fd,Ns=zd,As=Bd,fr=Ud,_s=Vd,Zd=qd;const tw=Xd,nw=Jd,Qd=m.forwardRef(({className:e,...t},n)=>c.jsx(Ns,{ref:n,className:ee("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}));Qd.displayName=Ns.displayName;const ef=m.forwardRef(({className:e,children:t,...n},r)=>{const o=m.useMemo(()=>{let s=!1;function i(a){m.Children.forEach(a,l=>{if(s||!m.isValidElement(l))return;const u=l.type;if(u===fr||(u==null?void 0:u.displayName)===fr.displayName||(u==null?void 0:u.name)==="DialogTitle"){s=!0;return}l.props&&l.props.children&&i(l.props.children)})}return i(t),s},[t]);return c.jsxs(nw,{children:[c.jsx(Qd,{}),c.jsxs(As,{ref:r,className:ee("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&&c.jsx(fr,{className:"sr-only",children:"Dialog"}),t,c.jsxs(Zd,{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:[c.jsx(ie.X,{className:"h-4 w-4"}),c.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});ef.displayName=As.displayName;const tf=({className:e,...t})=>c.jsx("div",{className:ee("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});tf.displayName="DialogHeader";const nf=m.forwardRef(({className:e,...t},n)=>c.jsx(fr,{ref:n,className:ee("text-lg font-semibold leading-none tracking-tight",e),...t}));nf.displayName=fr.displayName;const rw=m.forwardRef(({className:e,...t},n)=>c.jsx(_s,{ref:n,className:ee("text-sm text-muted-foreground",e),...t}));rw.displayName=_s.displayName;function ow({isOpen:e,onClose:t,fileId:n,fileName:r,mimeType:o}){const[s,i]=w.useState(!1),[a,l]=w.useState(null),[u,d]=w.useState(null),{toast:f}=ma(),h=w.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const y=await cd(n);l(y)}catch(y){console.error("Failed to load file:",y),d(y instanceof Error?y.message:"Failed to load file")}finally{i(!1)}}},[n]);w.useEffect(()=>{e&&n&&h()},[e,n,h]);const p=async()=>{if(n)try{await Lv(n),f({title:"Download started",description:`Downloading ${r}`})}catch(y){console.error("Failed to download file:",y),f({title:"Download failed",description:String(y),variant:"destructive"})}},v=async()=>{if(n)try{const y=await cd(n),b=new Blob([y],{type:o}),S=URL.createObjectURL(b);window.open(S,"_blank"),URL.revokeObjectURL(S)}catch(y){console.error("Failed to open file externally:",y),f({title:"Failed to open file",description:String(y),variant:"destructive"})}},x=()=>s?c.jsxs("div",{className:"flex items-center justify-center py-12",children:[c.jsx(ie.Loader,{className:"h-8 w-8 animate-spin mr-3"}),c.jsx("span",{children:"Loading file..."})]}):u?c.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[c.jsx("div",{className:"text-red-500 mb-4",children:"⚠️"}),c.jsx("p",{className:"text-red-600 mb-4",children:u}),c.jsx(Ke,{onClick:h,variant:"outline",children:"Try Again"})]}):a?o.startsWith("image/")?c.jsx("div",{className:"flex justify-center",children:c.jsx("img",{src:`data:${o};base64,${a}`,alt:r,className:"max-w-full max-h-[70vh] object-contain rounded-lg"})}):o==="application/pdf"?c.jsx("div",{className:"w-full h-[70vh] border rounded-lg overflow-hidden",children:c.jsx("iframe",{src:`data:application/pdf;base64,${a}`,className:"w-full h-full",title:r})}):o.startsWith("text/")||o.includes("json")||o.includes("xml")?c.jsx("div",{className:"bg-gray-50 dark:bg-gray-900 rounded-lg p-4 max-h-[70vh] overflow-auto",children:c.jsx("pre",{className:"whitespace-pre-wrap font-mono text-sm",children:a})}):c.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[c.jsx(ie.FileText,{className:"h-16 w-16 text-gray-400 mb-4"}),c.jsx("p",{className:"text-lg font-medium mb-2",children:r}),c.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:[o," • ",a.length," bytes"]}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"This file type cannot be previewed. Use download or external view."})]}):c.jsx("div",{className:"flex items-center justify-center py-12",children:c.jsx("p",{className:"text-muted-foreground",children:"No content to display"})}),g=()=>o.startsWith("image/")?c.jsx(ie.Image,{className:"h-5 w-5"}):c.jsx(ie.FileText,{className:"h-5 w-5"});return c.jsx(tw,{open:e,onOpenChange:t,children:c.jsxs(ef,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[c.jsx(tf,{children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[g(),c.jsxs("div",{children:[c.jsx(nf,{className:"text-left",children:r}),c.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[o," • Click download or external view for full access"]})]})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs(Ke,{variant:"outline",size:"sm",onClick:v,className:"flex items-center gap-2",children:[c.jsx(ie.ExternalLink,{className:"h-4 w-4"}),"External"]}),c.jsxs(Ke,{variant:"outline",size:"sm",onClick:p,className:"flex items-center gap-2",children:[c.jsx(ie.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),c.jsx("div",{className:"flex-1 overflow-hidden",children:x()})]})})}function rf(e){const t=e==null?void 0:e.trim();if(!t||!(t.startsWith("{")||t.startsWith("[")))return null;try{return JSON.parse(t)}catch{return null}}function of(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function fo(e){if(typeof e=="string")return e.length>2e3?e.slice(0,2e3)+"... [truncated]":e;if(e&&typeof e=="object"){if(Array.isArray(e)){const n=e.map(fo).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(of(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=fo(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 _a(e){if(typeof e=="string")return e;if(of(e))return"";try{const t=fo(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function sf(e){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){if(e.desirability||e.feasibility||e.viability||e.other)return{desirability:Array.isArray(e.desirability)?e.desirability:[],feasibility:Array.isArray(e.feasibility)?e.feasibility:[],viability:Array.isArray(e.viability)?e.viability:[],other:Array.isArray(e.other)?e.other:[]};if(e.output&&typeof e.output!="object")e=e.output;else if(e.output&&typeof e.output=="object")return sf(e.output)}const t=String(e),n={desirability:[],feasibility:[],viability:[],other:[]};let r=t;const o=Math.min(...["desirability=","feasibility=","viability=","other="].map(i=>{const a=r.toLowerCase().indexOf(i);return a===-1?Number.MAX_SAFE_INTEGER:a}));o!==Number.MAX_SAFE_INTEGER&&(r=r.slice(o));for(const i of Object.keys(n)){const l=new RegExp(i+"\\s*=\\s*\\[([\\s\\S]*?)\\]","i").exec(r);if(!l)continue;const u=l[1],d=/Issue\(([\s\S]*?)\)(?:,|$)/g;let f=null;for(;(f=d.exec(u))!==null;){const h=f[1],p=/title\s*=\s*(['"])([\s\S]*?)\1/.exec(h),v=/description\s*=\s*(['"])([\s\S]*?)\1/.exec(h),x=p?p[2].trim():"",g=v?v[2].trim():"";n[i].push({title:x,description:g})}}return Object.values(n).some(i=>i.length>0)?n:null}const js="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",hr=1e5;function sw(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function iw(e){const t=e.find(r=>r.type==="tool_call"),n=e.find(r=>r.type==="tool_end");return{name:t==null?void 0:t.name,toolCallId:(n==null?void 0:n.toolCallId)??(t==null?void 0:t.id)}}function aw(e){const t=e.filter(r=>r.type==="tool_call");return e.filter(r=>r.type==="tool_end").map(r=>{var o;return{name:(o=t.find(s=>s.id===r.toolCallId))==null?void 0:o.name,toolCallId:r.toolCallId,output:r.output}})}function lw(e){const t=(r,o=hr)=>{try{const s=fo(r),i=typeof s=="string"?s:JSON.stringify(s??"");return i.length<=o?i:i.slice(0,o)+`
|
|
128
|
+
… [truncated ${i.length-o} chars]`}catch{return""}},n=e.filter(r=>r.type==="tool_end");if(n.length)try{return n.length===1?t(n[0].output):t(n.map(r=>({toolCallId:r.toolCallId,output:r.output})))}catch{}return t(e)}function cw(e){const t=e.find(r=>r.type==="tool_end");if(!t)return null;const n=t.output;return typeof n=="string"?n:null}function uw(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function af(e){const t=e.updatedAt??e.createdAt??"",n=Array.isArray(e.content)?e.content.map(r=>{switch(r.type){case"text":return`t:${r.text.length}`;case"image_url":return"img";case"file":return"file";case"tool_call":return"call";case"tool_end":return"end";default:return"unknown"}}).join("|"):"";return`${e.id}:${t}:${n}`}function dw({className:e}){const[t,n]=w.useState(0);return w.useEffect(()=>{const r=setInterval(()=>n(o=>(o+1)%4),500);return()=>clearInterval(r)},[]),c.jsxs("span",{"aria-live":"polite",className:ee("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const lf=w.memo(function({message:t,messageIndex:n,isStreamingMessage:r=!1,isEditing:o=!1,showActions:s=!0,showTimestamp:i=!0,showAgentName:a=!0,layoutSize:l="desktop",truncateToolMessages:u=!0,toolMessagePreviewLength:d=200,truncateUserMessages:f=!0,userMessagePreviewLength:h=200,customStyles:p={},onEdit:v,onRegenerate:x,onCancelEdit:g,onCopy:y}){const[b,S]=w.useState(!1),[I,C]=w.useState("collapsed"),[T,E]=w.useState(!1),{currentThreadId:A}=Wo(),{respondToInterrupt:j}=Vo(),{toast:P}=ma(),[D,L]=w.useState({}),[V,M]=w.useState(!1),[X,K]=w.useState(null),q=l==="phone"||l==="half-screen",z=t.role,$=z==="tool",pe=!(r&&z!=="user"),F=w.useMemo(()=>{switch(z){case"user":return"text-[hsl(var(--chat-bubble-user-text))]";case"assistant":return"text-[hsl(var(--chat-bubble-ai-text))]";case"tool":return"text-secondary-foreground";case"system":return"text-muted-foreground";default:return"text-[hsl(var(--chat-bubble-ai-text))]"}},[z]),te=w.useMemo(()=>sw(t.content),[t.content]),fe=w.useMemo(()=>iw(t.content),[t.content]),ge=w.useMemo(()=>t.content.filter(B=>B.type==="image_url"),[t.content]),be=w.useMemo(()=>t.content.filter(B=>B.type==="file"),[t.content]),Te=w.useMemo(()=>t.content.filter(B=>B.type==="interrupt"),[t.content]),G=w.useMemo(()=>lw(t.content),[t.content]);w.useMemo(()=>cw(t.content),[t.content]);const O=w.useMemo(()=>G.length<=hr?G:`${G.slice(0,hr)}
|
|
129
|
+
… [truncated ${G.length-hr} chars]`,[G]),Q=w.useCallback(async(B="all")=>{const we=B==="visible"&&$?O:$?G:te;async function Ie(ye){try{await navigator.clipboard.writeText(ye)}catch{try{const je=document.createElement("textarea");je.value=ye,je.setAttribute("readonly",""),je.style.position="absolute",je.style.left="-9999px",document.body.appendChild(je),je.select(),document.execCommand("copy"),document.body.removeChild(je)}catch(je){throw console.error("Failed to copy:",je),je}}}try{await Ie(we),S(!0),setTimeout(()=>S(!1),2e3),y==null||y(we)}catch(ye){console.error("Failed to copy:",ye)}},[$,G,te,O,y]),ne=w.useCallback(()=>{if(!v)return;const B=$?G:te;v(t.id,B)},[v,t.id,$,G,te]),de=w.useCallback(()=>{x==null||x(n)},[x,n]),ae=w.useCallback(async(B,se,we)=>{if(!pe){B.preventDefault();return}if(D[we]){B.preventDefault();return}try{const Ie=String(se.url??""),ye=Ie.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(ye){B.preventDefault();const je=ye[1],Qe=se.name||`file_${je}`,Fe=se.mimeType||"application/octet-stream";K({id:je,name:Qe,mimeType:Fe}),M(!0);return}if(Ie.startsWith("data:")){B.preventDefault(),L(Fe=>({...Fe,[we]:!0}));const je=`${se.name}_${se.size}_${Date.now()}`,Qe=P({title:"Fetching file...",description:"",open:!0});try{const Fe=await $v(A??void 0);if(!Fe||!Array.isArray(Fe))throw new Error("Invalid file list response");const pt=Fe.find(St=>!St||typeof St!="object"||!((St.filename??"")===(se.name??""))?!1:typeof se.size=="number"&&typeof St.size=="number"?St.size===se.size:!0);if(!(pt!=null&&pt.id))throw new Error(`File "${se.name}" is not yet available on the server`);if(!pt.id||!pt.filename)throw new Error("Invalid file data received from server");K({id:pt.id,name:se.name||pt.filename||`file_${pt.id}`,mimeType:se.mimeType||pt.mime_type||"application/octet-stream"}),M(!0),Qe.update({id:Qe.id,title:"Success",description:`Opened ${se.name}`,open:!0})}catch(Fe){console.error("Failed to fetch server file:",Fe);const pt=Fe instanceof Error?Fe.message:"Unknown error occurred";Qe.update({id:Qe.id,title:"Failed",description:pt}),P({title:"Failed to fetch file",description:pt,open:!0})}finally{L(Fe=>({...Fe,[we]:!1}))}}}catch(Ie){console.error("File click error:",Ie),L(ye=>({...ye,[we]:!1}))}},[pe,D,P,A]),Ue=w.useCallback(()=>{const se=ee(q?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",F);switch(z){case"user":return c.jsx(ie.User,{className:se});case"assistant":return c.jsx(ie.Bot,{className:se});case"tool":return c.jsx(ie.Wrench,{className:se});default:return c.jsx(ie.Bot,{className:se})}},[q,F,z]),Ze=w.useCallback(()=>{const B="group relative mb-4 flex w-full";switch(z){case"user":return ee(B,"justify-end");case"assistant":case"tool":case"system":return ee(B,"justify-start");default:return B}},[z]),me=w.useCallback(()=>{const B=ee("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",q&&"px-3 py-2 text-sm");switch(z){case"user":return ee(B,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-user))] text-[hsl(var(--chat-bubble-user-text))]","border border-transparent");case"assistant":return ee(B,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40");case"tool":return ee(B,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return ee(B,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return ee(B,"w-full md:max-w-[95%]","bg-[hsl(var(--chat-bubble-ai))] text-[hsl(var(--chat-bubble-ai-text))]","border border-border/60 dark:border-border/40")}},[q,z]),Pe=w.useCallback(async B=>{try{const se=(B==null?void 0:B.id)||(B==null?void 0:B.interrupt_id);if(!se){console.warn("Interrupt part missing id",B);return}await j(se,!0)}catch(se){console.error("Failed to approve interrupt:",se)}},[j]),Le=w.useCallback(async B=>{try{const se=(B==null?void 0:B.id)||(B==null?void 0:B.interrupt_id);if(!se){console.warn("Interrupt part missing id",B);return}await j(se,!1)}catch(se){console.error("Failed to reject interrupt:",se)}},[j]),ct=w.useCallback(({part:B,i:se})=>{if(B.type==="text"){const we=B.text??"",Ie=we.trim(),ye=rf(Ie);return ye&&z!=="tool"?c.jsx(fw,{data:ye},se):z==="user"&&f&&Ie.length>h?c.jsxs(Vu,{open:T,onOpenChange:E,children:[c.jsx("div",{className:ee("text-sm text-[hsl(var(--chat-bubble-user-text))]",q&&"text-xs"),children:T?c.jsx(fa,{content:Ie,allowHtml:!1}):c.jsxs("pre",{className:ee("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",q&&"text-xs"),children:[Ie.substring(0,h),"..."]})}),c.jsx(Ku,{asChild:!0,children:c.jsx(Ke,{variant:"ghost",size:"sm",className:"h-6 text-xs !text-[hsl(var(--chat-bubble-user-text))]",children:T?c.jsxs(c.Fragment,{children:[c.jsx(ie.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):c.jsxs(c.Fragment,{children:[c.jsx(ie.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",Ie.length-h," chars)"]})})})]},se):c.jsx(fa,{content:we,allowHtml:!1},se)}if(B.type==="image_url"){const we=B;return c.jsx("div",{className:"my-2",children:c.jsx("img",{src:we.url,alt:we.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},se)}if(B.type==="file"){const we=B,Ie=we.name||"file";return c.jsxs("a",{href:we.url,onClick:ye=>ae(ye,we,se),className:`inline-flex items-center gap-2 rounded px-2 py-1 text-xs bg-gray-100 border hover:bg-gray-200
|
|
130
|
+
dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[D[se]?c.jsx(ie.Loader,{className:"h-4 w-4 animate-spin"}):null,c.jsxs("span",{className:"truncate max-w-[180px]",children:[Ie,D[se]?" (processing)":""]})]},se)}return B.type==="interrupt"?c.jsx(pw,{interruptPart:B,onApprove:Pe,onReject:Le},se):null},[ae,D,Pe,Le,z,f,h,T,q]),rt=w.useCallback(()=>c.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[c.jsx(ie.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),c.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),vt=w.useCallback(()=>{const B=te.trim().length>0||ge.length>0||be.length>0||Te.length>0;if(!$&&!B&&!r)return rt();if(t.model==="reflection"){const se=te.trim(),we=rf(se);if(we&&typeof we=="object")return c.jsx(mw,{data:we})}if($&&fe.name==="get_issues"){const se=t.content.find(ye=>ye.type==="tool_end"),we=(se==null?void 0:se.output)??G,Ie=sf(we);if(Ie)return c.jsx(gw,{issues:Ie})}if($){const se=aw(t.content);if(se.length>0)return c.jsx("div",{className:"space-y-2",children:se.map((we,Ie)=>{const ye=typeof we.output=="string"?we.output:_a(we.output),je=ye.length>hr?`${ye.slice(0,hr)}
|
|
131
|
+
… [truncated ${ye.length-hr} chars]`:ye,Qe=I==="expanded";return c.jsxs(Vu,{open:Qe,onOpenChange:Fe=>C(Fe?"expanded":"preview"),children:[c.jsx("div",{className:"flex items-center gap-2 text-xs",children:c.jsx(sa,{variant:"outline",children:(we.name??"tool")+(we.toolCallId?` • ${we.toolCallId.slice(0,8)}`:"")})}),c.jsx("div",{className:"font-mono text-sm mt-1",children:c.jsx("pre",{className:"whitespace-pre-wrap break-words",children:Qe?je:je.slice(0,d)+(je.length>d?"...":"")})}),c.jsx(Ku,{asChild:!0,children:c.jsx(Ke,{variant:"ghost",size:"sm",className:"h-6 text-xs",children:Qe?c.jsxs(c.Fragment,{children:[" ",c.jsx(ie.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):c.jsxs(c.Fragment,{children:[c.jsx(ie.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more"]})})})]},we.toolCallId??Ie)})})}if(!$){const se=c.jsx("div",{className:"space-y-2",children:t.content.map((we,Ie)=>c.jsx(ct,{part:we,i:Ie},Ie))});return r?c.jsxs("div",{"aria-busy":"true",role:"status",children:[se,c.jsx(dw,{className:F})]}):se}},[te,ge.length,be.length,Te.length,r,t.model,$,fe.name,G,I,u,rt,F]),wt=w.useMemo(()=>uw(t),[t]);return c.jsxs(c.Fragment,{children:[c.jsx("div",{className:ee(Ze(),p.container),children:c.jsxs("div",{className:ee(me(),p.content),children:[(i||a||$)&&c.jsxs("div",{className:ee("flex items-center justify-between mb-2 pb-2 border-b border-current/10",q&&"mb-1 pb-1",F,p.header),children:[c.jsxs("div",{className:"flex items-center gap-2",children:[Ue(),a&&wt&&c.jsx("span",{className:ee("font-medium",q?"text-xs":"text-sm"),children:wt}),$&&fe.name&&c.jsxs(sa,{variant:"outline",className:ee("text-xs flex items-center gap-1 cursor-pointer",F,"border border-current/40",q&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":I!=="collapsed",onKeyDown:B=>{(B.key==="Enter"||B.key===" ")&&(B.preventDefault(),C(se=>se==="collapsed"?"preview":"collapsed"))},onClick:()=>C(B=>B==="collapsed"?"preview":"collapsed"),children:[c.jsx("span",{children:fe.name}),c.jsx("span",{className:"inline-flex items-center",children:I!=="collapsed"?c.jsx(ie.ChevronUp,{className:"h-3 w-3"}):c.jsx(ie.ChevronDown,{className:"h-3 w-3"})})]}),$&&!fe.name&&c.jsx(Ke,{variant:"ghost",size:"sm",className:ee("h-6 px-1",F,"hover:bg-foreground/10"),onClick:()=>C(B=>B==="collapsed"?"preview":"collapsed"),children:c.jsxs("span",{className:"text-xs flex items-center gap-1",children:["Tool Output ",I!=="collapsed"?c.jsx(ie.ChevronUp,{className:"h-3 w-3"}):c.jsx(ie.ChevronDown,{className:"h-3 w-3"})]})})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[i&&t.createdAt&&c.jsx("time",{className:ee("text-xs opacity-60",F,q&&"text-xs"),dateTime:new Date(t.createdAt).toISOString(),title:new Date(t.createdAt).toLocaleString(),children:new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"}).format(new Date(t.createdAt))}),s&&!o&&c.jsxs("div",{className:ee("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[c.jsxs("div",{className:"relative",children:[c.jsx(Ke,{variant:"ghost",size:"sm",onClick:()=>Q($?"visible":"all"),className:ee("h-6 w-6 p-0 hover:bg-foreground/10",F,q&&"h-5 w-5"),"aria-label":$?"Copy visible":"Copy message",title:$?"Copy visible portion":"Copy message",children:c.jsx(ie.Copy,{className:ee(b?"text-success":F,q?"h-3 w-3":"h-4 w-4")})}),$&&c.jsx(Ke,{variant:"ghost",size:"sm",onClick:()=>Q("all"),className:ee("h-6 px-1 text-xs hover:bg-foreground/10",F),"aria-label":"Copy all (may be large)",title:"Copy all (may be large)",children:"all"})]}),z==="user"&&v&&c.jsx(Ke,{variant:"ghost",size:"sm",onClick:ne,className:ee("h-6 w-6 p-0 hover:bg-foreground/10",F,q&&"h-5 w-5"),"aria-label":"Edit message",children:c.jsx(ie.Edit,{className:ee(F,q?"h-3 w-3":"h-4 w-4")})}),z==="assistant"&&x&&c.jsx(Ke,{variant:"ghost",size:"sm",onClick:de,className:ee("h-6 w-6 p-0 hover:bg-foreground/10",F,q&&"h-5 w-5"),"aria-label":"Regenerate response",children:c.jsx(ie.RotateCcw,{className:ee(F,q?"h-3 w-3":"h-4 w-4")})})]})]})]}),c.jsx("div",{className:"relative",children:vt()}),$&&I==="expanded"&&(fe.toolCallId||fe.name)&&c.jsxs("div",{className:ee("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",q&&"text-xs"),children:[fe.name&&c.jsxs("div",{children:["Function: ",fe.name]}),fe.toolCallId&&c.jsxs("div",{children:["Call ID: ",fe.toolCallId]})]}),!(i||a||$)&&s&&!o&&c.jsxs("div",{className:ee("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[c.jsx(Ke,{variant:"ghost",size:"sm",onClick:()=>Q(),className:ee("h-6 w-6 p-0 hover:bg-background/50 text-current",q&&"h-5 w-5"),children:c.jsx(ie.Copy,{className:ee(b?"text-success":"text-current",q?"h-3 w-3":"h-4 w-4")})}),z==="user"&&v&&c.jsx(Ke,{variant:"ghost",size:"sm",onClick:ne,className:ee("h-6 w-6 p-0 hover:bg-background/50 text-current",q&&"h-5 w-5"),children:c.jsx(ie.Edit,{className:ee("text-current",q?"h-3 w-3":"h-4 w-4")})}),z==="assistant"&&x&&c.jsx(Ke,{variant:"ghost",size:"sm",onClick:de,className:ee("h-6 w-6 p-0 hover:bg-background/50 text-current",q&&"h-5 w-5"),children:c.jsx(ie.RotateCcw,{className:ee("text-current",q?"h-3 w-3":"h-4 w-4")})})]})]})}),X&&c.jsx(ow,{isOpen:V,onClose:()=>{M(!1),K(null)},fileId:X.id,fileName:X.name,mimeType:X.mimeType})]})},(e,t)=>{var i,a,l,u,d,f,h,p;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&af(e.message)===af(t.message)))return!1;const o=["isEditing","showActions","layoutSize","showTimestamp","showAgentName","truncateToolMessages","toolMessagePreviewLength","truncateUserMessages","userMessagePreviewLength"].every(v=>e[v]===t[v]),s=((i=e.customStyles)==null?void 0:i.container)===((a=t.customStyles)==null?void 0:a.container)&&((l=e.customStyles)==null?void 0:l.content)===((u=t.customStyles)==null?void 0:u.content)&&((d=e.customStyles)==null?void 0:d.actions)===((f=t.customStyles)==null?void 0:f.actions)&&((h=e.customStyles)==null?void 0:h.header)===((p=t.customStyles)==null?void 0:p.header);return o&&s});function fw({data:e}){if(Array.isArray(e))return e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?c.jsx("div",{className:js,children:c.jsx("ul",{className:"list-disc pl-5",children:e.map((n,r)=>c.jsx("li",{children:String(n)},r))})}):c.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:_a(e)});if(e&&typeof e=="object"){const t=Array.isArray(e.distilled_facts)?e.distilled_facts:null,n=Array.isArray(e.follow_up_queries)?e.follow_up_queries:null,r=typeof e.is_sufficient=="boolean"?e.is_sufficient:void 0;if(t||n||typeof r=="boolean")return c.jsxs("div",{className:js,children:[typeof r=="boolean"&&c.jsxs("p",{children:[c.jsx("strong",{children:"Is sufficient:"})," ",r?"Yes":"No"]}),n&&n.length>0&&c.jsxs("div",{children:[c.jsx("p",{children:c.jsx("strong",{children:"Follow-up queries:"})}),c.jsx("ul",{className:"list-disc pl-5",children:n.map((s,i)=>c.jsx("li",{children:String(s)},i))})]}),t&&t.length>0&&c.jsxs("div",{children:[c.jsx("p",{children:c.jsx("strong",{children:"Facts:"})}),c.jsx("ul",{className:"list-disc pl-5",children:t.map((s,i)=>c.jsx("li",{children:String(s)},i))})]})]});const o=Object.entries(e);return c.jsx("div",{className:js,children:c.jsx("dl",{className:"mt-0",children:o.map(([s,i])=>c.jsxs("div",{className:"mb-1",children:[c.jsxs("dt",{className:"inline font-medium mr-1",children:[s,":"]}),c.jsx("dd",{className:"inline",children:hw(i)})]},s))})})}return c.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:_a(e)})}function hw(e){if(e==null)return String(e);const t=typeof e;if(t==="string"||t==="number"||t==="boolean")return String(e);if(Array.isArray(e)&&e.every(r=>r===null||["string","number","boolean"].includes(typeof r)))return e.join(", ");try{return c.jsx("code",{className:"text-xs",children:JSON.stringify(fo(e))})}catch{return String(e)}}function pw({interruptPart:e,onApprove:t,onReject:n}){const r=e.title??"Approve the result?";return c.jsxs(ao,{className:"border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10",children:[c.jsxs(lo,{className:"pb-3",children:[c.jsx(co,{className:"text-blue-900 dark:text-blue-100 text-base",children:r}),c.jsx(qu,{className:"text-blue-700 dark:text-blue-300",children:"Please approve or reject this action to continue."})]}),c.jsx(Gu,{className:"pt-0",children:c.jsxs("div",{className:"flex gap-2 ml-auto",children:[c.jsx(Ke,{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",children:"Reject"}),c.jsx(Ke,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",children:"Approve"})]})})]})}function mw({data:e}){return c.jsx("dl",{className:"grid grid-cols-1 gap-y-2",children:Object.entries(e).map(([t,n])=>c.jsxs("div",{className:"flex",children:[c.jsxs("dt",{className:"font-semibold mr-2",children:[t,":"]}),c.jsx("dd",{className:"flex-1 break-words",children:Array.isArray(n)?n.map((r,o)=>c.jsxs("div",{className:"ml-4 break-words",children:["- ",String(r)]},o)):String(n)})]},t))})}function gw({issues:e}){const t=[{key:"desirability",title:"Desirability"},{key:"feasibility",title:"Feasibility"},{key:"viability",title:"Viability"},{key:"other",title:"Other"}];return c.jsx("div",{className:js,children:t.map(n=>{const r=e[n.key];return!r||!r.length?null:c.jsxs("div",{className:"mb-4",children:[c.jsxs("h4",{className:"font-semibold mb-2",children:[n.title," (",r.length,")"]}),c.jsx("ol",{className:"list-decimal pl-5 space-y-2",children:r.map((o,s)=>c.jsxs("li",{children:[c.jsx("div",{className:"font-medium",children:o.title}),c.jsx("div",{className:"text-sm text-muted-foreground",children:o.description})]},s))})]},n.key)})})}const cf=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,ja=w.forwardRef(({messages:e,isStreaming:t,streamingAssistantId:n,streamingDebounceMs:r,layoutSize:o,enableMessageEditing:s,editingMessageId:i,onStartReached:a,onEdit:l,onRegenerate:u,onCancelEdit:d,className:f,style:h,emptyMessage:p,followNewMessages:v=!0,isNavigatingCheckpoint:x=!1,onScrollAway:g,onAtBottom:y},b)=>{const S=w.useRef(null),I=w.useRef(null),C=w.useRef(!1),[T,E]=w.useState(!0),A=w.useCallback(D=>{E(D),g&&g(!D),y&&y(D)},[g,y]),j=w.useMemo(()=>{if(a)return async()=>{if(!C.current){C.current=!0;try{await a()}finally{C.current=!1}}}},[a]),P=w.useMemo(()=>!v||x?!1:T?"auto":!1,[T,v,x]);return e.length===0?c.jsx("div",{className:f,style:h,children:c.jsx("div",{className:"flex items-center justify-center py-8 text-muted-foreground text-center max-w-md mx-auto",children:p||"No messages yet. Start a conversation!"})}):c.jsx("div",{className:f,style:h,children:c.jsx(Hy,{ref:D=>{S.current=D},scrollerRef:D=>{I.current=D instanceof HTMLDivElement?D:null},data:e,followOutput:P,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{j&&j()},atBottomStateChange:A,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(D,L)=>cf(L,D),itemContent:(D,L)=>{const V=cf(L,D);return c.jsx("div",{className:"mb-4 last:mb-0","data-message-id":V,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:c.jsx(lf,{message:L,messageIndex:D,isStreamingMessage:t&&n===L.id,streamingDebounceMs:r,isEditing:i===L.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,truncateToolMessages:!1,toolMessagePreviewLength:200,onEdit:l,onRegenerate:()=>u(D),onCancelEdit:d})})}})})});ja.displayName="MessageList";const Rs=1e4;function xw(e){if(typeof e!="string")return String(e);const t=[/<script[^>]*>.*?<\/script>/gi,/<iframe[^>]*>.*?<\/iframe>/gi,/javascript:/gi,/vbscript:/gi,/on\w+\s*=/gi,/<object[^>]*>.*?<\/object>/gi,/<embed[^>]*>.*?<\/embed>/gi,/<form[^>]*>.*?<\/form>/gi];let n=e;for(const o of t)n=n.replace(o,"");return/<[^>]+>/.test(n)&&!/<(?!\/?(?:code|strong|em|b|i|br|p|ul|ol|li|h[1-6])\b)[^>]+>/i.test(n)?n.replace(/<code>(.*?)<\/code>/gi,"`$1`").replace(/<strong>(.*?)<\/strong>/gi,"**$1**").replace(/<b>(.*?)<\/b>/gi,"**$1**").replace(/<em>(.*?)<\/em>/gi,"*$1*").replace(/<i>(.*?)<\/i>/gi,"*$1*").replace(/<br\s*\/?>/gi,`
|
|
133
132
|
`).replace(/<p>(.*?)<\/p>/gi,`$1
|
|
134
133
|
|
|
135
134
|
`).replace(/<h([1-6])>(.*?)<\/h[1-6]>/gi,(o,s,i)=>`${"#".repeat(parseInt(s))} ${i}
|
|
@@ -137,4 +136,4 @@ For more information, see https://radix-ui.com/primitives/docs/components/${t.do
|
|
|
137
136
|
`).replace(/<ul>/gi,"").replace(/<\/ul>/gi,`
|
|
138
137
|
`).replace(/<ol>/gi,"").replace(/<\/ol>/gi,`
|
|
139
138
|
`).replace(/<li>(.*?)<\/li>/gi,`- $1
|
|
140
|
-
`).trim():n.replace(/</g,"<").replace(/>/g,">").trim()}function yw(e,t=Ms){if(!e||typeof e!="string")throw new Error("Invalid content: must be a non-empty string");if(e.length>t)throw new Error(`Message exceeds maximum length of ${t} characters`);return e}function vw(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),yw(t),xw(t)}function Oa(e){const t=e+"CollectionProvider",[n,r]=wn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=x=>{const{scope:g,children:y}=x,b=w.useRef(null),S=w.useRef(new Map).current;return c.jsx(o,{scope:g,itemMap:S,collectionRef:b,children:y})};i.displayName=t;const a=e+"CollectionSlot",l=nr.createSlot(a),u=w.forwardRef((x,g)=>{const{scope:y,children:b}=x,S=s(a,y),I=Ue(g,S.collectionRef);return c.jsx(l,{ref:I,children:b})});u.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=nr.createSlot(d),p=w.forwardRef((x,g)=>{const{scope:y,children:b,...S}=x,I=w.useRef(null),C=Ue(g,I),T=s(d,y);return w.useEffect(()=>(T.itemMap.set(I,{ref:I,...S}),()=>void T.itemMap.delete(I))),c.jsx(h,{[f]:"",ref:C,children:b})});p.displayName=d;function v(x){const g=s(e+"CollectionConsumer",x);return w.useCallback(()=>{const b=g.collectionRef.current;if(!b)return[];const S=Array.from(b.querySelectorAll(`[${f}]`));return Array.from(g.itemMap.values()).sort((T,E)=>S.indexOf(T.ref.current)-S.indexOf(E.ref.current))},[g.collectionRef,g.itemMap])}return[{Provider:i,Slot:u,ItemSlot:p},v,r]}var bw=m.createContext(void 0);function Ds(e){const t=m.useContext(bw);return e||t||"ltr"}const ww=["top","right","bottom","left"],qn=Math.min,Gt=Math.max,Ls=Math.round,$s=Math.floor,Tn=e=>({x:e,y:e}),Sw={left:"right",right:"left",bottom:"top",top:"bottom"},Cw={start:"end",end:"start"};function Ma(e,t,n){return Gt(e,qn(t,n))}function Pn(e,t){return typeof e=="function"?e(t):e}function On(e){return e.split("-")[0]}function Mr(e){return e.split("-")[1]}function Da(e){return e==="x"?"y":"x"}function La(e){return e==="y"?"height":"width"}const Tw=new Set(["top","bottom"]);function kn(e){return Tw.has(On(e))?"y":"x"}function $a(e){return Da(kn(e))}function kw(e,t,n){n===void 0&&(n=!1);const r=Mr(e),o=$a(e),s=La(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Fs(i)),[i,Fs(i)]}function Ew(e){const t=Fs(e);return[Fa(e),t,Fa(t)]}function Fa(e){return e.replace(/start|end/g,t=>Cw[t])}const uf=["left","right"],df=["right","left"],Iw=["top","bottom"],Nw=["bottom","top"];function Aw(e,t,n){switch(e){case"top":case"bottom":return n?t?df:uf:t?uf:df;case"left":case"right":return t?Iw:Nw;default:return[]}}function _w(e,t,n,r){const o=Mr(e);let s=Aw(On(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Fa)))),s}function Fs(e){return e.replace(/left|right|bottom|top/g,t=>Sw[t])}function jw(e){return{top:0,right:0,bottom:0,left:0,...e}}function ff(e){return typeof e!="number"?jw(e):{top:e,right:e,bottom:e,left:e}}function zs(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 hf(e,t,n){let{reference:r,floating:o}=e;const s=kn(t),i=$a(t),a=La(i),l=On(t),u=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,h=r[a]/2-o[a]/2;let p;switch(l){case"top":p={x:d,y:r.y-o.height};break;case"bottom":p={x:d,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(Mr(t)){case"start":p[i]-=h*(n&&u?-1:1);break;case"end":p[i]+=h*(n&&u?-1:1);break}return p}const Rw=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let u=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:f}=hf(u,r,l),h=r,p={},v=0;for(let x=0;x<a.length;x++){const{name:g,fn:y}=a[x],{x:b,y:S,data:I,reset:C}=await y({x:d,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:u,platform:i,elements:{reference:e,floating:t}});d=b??d,f=S??f,p={...p,[g]:{...p[g],...I}},C&&v<=50&&(v++,typeof C=="object"&&(C.placement&&(h=C.placement),C.rects&&(u=C.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):C.rects),{x:d,y:f}=hf(u,h,l)),x=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:p}};async function yo(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:u="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:h=!1,padding:p=0}=Pn(t,e),v=ff(p),g=a[h?f==="floating"?"reference":"floating":f],y=zs(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(g)))==null||n?g:g.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:u,rootBoundary:d,strategy:l})),b=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,S=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),I=await(s.isElement==null?void 0:s.isElement(S))?await(s.getScale==null?void 0:s.getScale(S))||{x:1,y:1}:{x:1,y:1},C=zs(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:S,strategy:l}):b);return{top:(y.top-C.top+v.top)/I.y,bottom:(C.bottom-y.bottom+v.bottom)/I.y,left:(y.left-C.left+v.left)/I.x,right:(C.right-y.right+v.right)/I.x}}const Pw=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:u,padding:d=0}=Pn(e,t)||{};if(u==null)return{};const f=ff(d),h={x:n,y:r},p=$a(o),v=La(p),x=await i.getDimensions(u),g=p==="y",y=g?"top":"left",b=g?"bottom":"right",S=g?"clientHeight":"clientWidth",I=s.reference[v]+s.reference[p]-h[p]-s.floating[v],C=h[p]-s.reference[p],T=await(i.getOffsetParent==null?void 0:i.getOffsetParent(u));let E=T?T[S]:0;(!E||!await(i.isElement==null?void 0:i.isElement(T)))&&(E=a.floating[S]||s.floating[v]);const A=I/2-C/2,j=E/2-x[v]/2-1,P=qn(f[y],j),D=qn(f[b],j),L=P,V=E-x[v]-D,M=E/2-x[v]/2+A,Y=Ma(L,M,V),K=!l.arrow&&Mr(o)!=null&&M!==Y&&s.reference[v]/2-(M<L?P:D)-x[v]/2<0,q=K?M<L?M-L:M-V:0;return{[p]:h[p]+q,data:{[p]:Y,centerOffset:M-Y-q,...K&&{alignmentOffset:q}},reset:K}}}),Ow=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:u}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:v="none",flipAlignment:x=!0,...g}=Pn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const y=On(o),b=kn(a),S=On(a)===a,I=await(l.isRTL==null?void 0:l.isRTL(u.floating)),C=h||(S||!x?[Fs(a)]:Ew(a)),T=v!=="none";!h&&T&&C.push(..._w(a,x,v,I));const E=[a,...C],A=await yo(t,g),j=[];let P=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&j.push(A[y]),f){const M=kw(o,i,I);j.push(A[M[0]],A[M[1]])}if(P=[...P,{placement:o,overflows:j}],!j.every(M=>M<=0)){var D,L;const M=(((D=s.flip)==null?void 0:D.index)||0)+1,Y=E[M];if(Y&&(!(f==="alignment"?b!==kn(Y):!1)||P.every(z=>kn(z.placement)===b?z.overflows[0]>0:!0)))return{data:{index:M,overflows:P},reset:{placement:Y}};let K=(L=P.filter(q=>q.overflows[0]<=0).sort((q,z)=>q.overflows[1]-z.overflows[1])[0])==null?void 0:L.placement;if(!K)switch(p){case"bestFit":{var V;const q=(V=P.filter(z=>{if(T){const $=kn(z.placement);return $===b||$==="y"}return!0}).map(z=>[z.placement,z.overflows.filter($=>$>0).reduce(($,pe)=>$+pe,0)]).sort((z,$)=>z[1]-$[1])[0])==null?void 0:V[0];q&&(K=q);break}case"initialPlacement":K=a;break}if(o!==K)return{reset:{placement:K}}}return{}}}};function pf(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function mf(e){return ww.some(t=>e[t]>=0)}const Mw=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=Pn(e,t);switch(r){case"referenceHidden":{const s=await yo(t,{...o,elementContext:"reference"}),i=pf(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:mf(i)}}}case"escaped":{const s=await yo(t,{...o,altBoundary:!0}),i=pf(s,n.floating);return{data:{escapedOffsets:i,escaped:mf(i)}}}default:return{}}}}},gf=new Set(["left","top"]);async function Dw(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=On(n),a=Mr(n),l=kn(n)==="y",u=gf.has(i)?-1:1,d=s&&l?-1:1,f=Pn(t,e);let{mainAxis:h,crossAxis:p,alignmentAxis:v}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof v=="number"&&(p=a==="end"?v*-1:v),l?{x:p*d,y:h*u}:{x:h*u,y:p*d}}const Lw=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var n,r;const{x:o,y:s,placement:i,middlewareData:a}=t,l=await Dw(t,e);return i===((n=a.offset)==null?void 0:n.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:o+l.x,y:s+l.y,data:{...l,placement:i}}}}},$w=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:g=>{let{x:y,y:b}=g;return{x:y,y:b}}},...l}=Pn(e,t),u={x:n,y:r},d=await yo(t,l),f=kn(On(o)),h=Da(f);let p=u[h],v=u[f];if(s){const g=h==="y"?"top":"left",y=h==="y"?"bottom":"right",b=p+d[g],S=p-d[y];p=Ma(b,p,S)}if(i){const g=f==="y"?"top":"left",y=f==="y"?"bottom":"right",b=v+d[g],S=v-d[y];v=Ma(b,v,S)}const x=a.fn({...t,[h]:p,[f]:v});return{...x,data:{x:x.x-n,y:x.y-r,enabled:{[h]:s,[f]:i}}}}}},Fw=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:u=!0}=Pn(e,t),d={x:n,y:r},f=kn(o),h=Da(f);let p=d[h],v=d[f];const x=Pn(a,t),g=typeof x=="number"?{mainAxis:x,crossAxis:0}:{mainAxis:0,crossAxis:0,...x};if(l){const S=h==="y"?"height":"width",I=s.reference[h]-s.floating[S]+g.mainAxis,C=s.reference[h]+s.reference[S]-g.mainAxis;p<I?p=I:p>C&&(p=C)}if(u){var y,b;const S=h==="y"?"width":"height",I=gf.has(On(o)),C=s.reference[f]-s.floating[S]+(I&&((y=i.offset)==null?void 0:y[f])||0)+(I?0:g.crossAxis),T=s.reference[f]+s.reference[S]+(I?0:((b=i.offset)==null?void 0:b[f])||0)-(I?g.crossAxis:0);v<C?v=C:v>T&&(v=T)}return{[h]:p,[f]:v}}}},zw=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:o,rects:s,platform:i,elements:a}=t,{apply:l=()=>{},...u}=Pn(e,t),d=await yo(t,u),f=On(o),h=Mr(o),p=kn(o)==="y",{width:v,height:x}=s.floating;let g,y;f==="top"||f==="bottom"?(g=f,y=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(y=f,g=h==="end"?"top":"bottom");const b=x-d.top-d.bottom,S=v-d.left-d.right,I=qn(x-d[g],b),C=qn(v-d[y],S),T=!t.middlewareData.shift;let E=I,A=C;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(A=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=b),T&&!h){const P=Gt(d.left,0),D=Gt(d.right,0),L=Gt(d.top,0),V=Gt(d.bottom,0);p?A=v-2*(P!==0||D!==0?P+D:Gt(d.left,d.right)):E=x-2*(L!==0||V!==0?L+V:Gt(d.top,d.bottom))}await l({...t,availableWidth:A,availableHeight:E});const j=await i.getDimensions(a.floating);return v!==j.width||x!==j.height?{reset:{rects:!0}}:{}}}};function Bs(){return typeof window<"u"}function Dr(e){return xf(e)?(e.nodeName||"").toLowerCase():"#document"}function Yt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function En(e){var t;return(t=(xf(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function xf(e){return Bs()?e instanceof Node||e instanceof Yt(e).Node:!1}function un(e){return Bs()?e instanceof Element||e instanceof Yt(e).Element:!1}function In(e){return Bs()?e instanceof HTMLElement||e instanceof Yt(e).HTMLElement:!1}function yf(e){return!Bs()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Yt(e).ShadowRoot}const Bw=new Set(["inline","contents"]);function vo(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=dn(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!Bw.has(o)}const Hw=new Set(["table","td","th"]);function Uw(e){return Hw.has(Dr(e))}const Ww=[":popover-open",":modal"];function Hs(e){return Ww.some(t=>{try{return e.matches(t)}catch{return!1}})}const Vw=["transform","translate","scale","rotate","perspective"],Kw=["transform","translate","scale","rotate","perspective","filter"],qw=["paint","layout","strict","content"];function za(e){const t=Ba(),n=un(e)?dn(e):e;return Vw.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)||Kw.some(r=>(n.willChange||"").includes(r))||qw.some(r=>(n.contain||"").includes(r))}function Gw(e){let t=Gn(e);for(;In(t)&&!Lr(t);){if(za(t))return t;if(Hs(t))return null;t=Gn(t)}return null}function Ba(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const Yw=new Set(["html","body","#document"]);function Lr(e){return Yw.has(Dr(e))}function dn(e){return Yt(e).getComputedStyle(e)}function Us(e){return un(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Gn(e){if(Dr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||yf(e)&&e.host||En(e);return yf(t)?t.host:t}function vf(e){const t=Gn(e);return Lr(t)?e.ownerDocument?e.ownerDocument.body:e.body:In(t)&&vo(t)?t:vf(t)}function bo(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=vf(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Yt(o);if(s){const a=Ha(i);return t.concat(i,i.visualViewport||[],vo(o)?o:[],a&&n?bo(a):[])}return t.concat(o,bo(o,[],n))}function Ha(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function bf(e){const t=dn(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=In(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=Ls(n)!==s||Ls(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Ua(e){return un(e)?e:e.contextElement}function $r(e){const t=Ua(e);if(!In(t))return Tn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=bf(t);let i=(s?Ls(n.width):n.width)/r,a=(s?Ls(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const Xw=Tn(0);function wf(e){const t=Yt(e);return!Ba()||!t.visualViewport?Xw:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Jw(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Yt(e)?!1:t}function mr(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Ua(e);let i=Tn(1);t&&(r?un(r)&&(i=$r(r)):i=$r(e));const a=Jw(s,n,r)?wf(s):Tn(0);let l=(o.left+a.x)/i.x,u=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const h=Yt(s),p=r&&un(r)?Yt(r):r;let v=h,x=Ha(v);for(;x&&r&&p!==v;){const g=$r(x),y=x.getBoundingClientRect(),b=dn(x),S=y.left+(x.clientLeft+parseFloat(b.paddingLeft))*g.x,I=y.top+(x.clientTop+parseFloat(b.paddingTop))*g.y;l*=g.x,u*=g.y,d*=g.x,f*=g.y,l+=S,u+=I,v=Yt(x),x=Ha(v)}}return zs({width:d,height:f,x:l,y:u})}function Ws(e,t){const n=Us(e).scrollLeft;return t?t.left+n:mr(En(e)).left+n}function Sf(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Ws(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function Zw(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=En(r),a=t?Hs(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},u=Tn(1);const d=Tn(0),f=In(r);if((f||!f&&!s)&&((Dr(r)!=="body"||vo(i))&&(l=Us(r)),In(r))){const p=mr(r);u=$r(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const h=i&&!f&&!s?Sf(i,l):Tn(0);return{width:n.width*u.x,height:n.height*u.y,x:n.x*u.x-l.scrollLeft*u.x+d.x+h.x,y:n.y*u.y-l.scrollTop*u.y+d.y+h.y}}function Qw(e){return Array.from(e.getClientRects())}function e0(e){const t=En(e),n=Us(e),r=e.ownerDocument.body,o=Gt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Gt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Ws(e);const a=-n.scrollTop;return dn(r).direction==="rtl"&&(i+=Gt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const Cf=25;function t0(e,t){const n=Yt(e),r=En(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const d=Ba();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const u=Ws(r);if(u<=0){const d=r.ownerDocument,f=d.body,h=getComputedStyle(f),p=d.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,v=Math.abs(r.clientWidth-f.clientWidth-p);v<=Cf&&(s-=v)}else u<=Cf&&(s+=u);return{width:s,height:i,x:a,y:l}}const n0=new Set(["absolute","fixed"]);function r0(e,t){const n=mr(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=In(e)?$r(e):Tn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,u=r*s.y;return{width:i,height:a,x:l,y:u}}function Tf(e,t,n){let r;if(t==="viewport")r=t0(e,n);else if(t==="document")r=e0(En(e));else if(un(t))r=r0(t,n);else{const o=wf(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return zs(r)}function kf(e,t){const n=Gn(e);return n===t||!un(n)||Lr(n)?!1:dn(n).position==="fixed"||kf(n,t)}function o0(e,t){const n=t.get(e);if(n)return n;let r=bo(e,[],!1).filter(a=>un(a)&&Dr(a)!=="body"),o=null;const s=dn(e).position==="fixed";let i=s?Gn(e):e;for(;un(i)&&!Lr(i);){const a=dn(i),l=za(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&n0.has(o.position)||vo(i)&&!l&&kf(e,i))?r=r.filter(d=>d!==i):o=a,i=Gn(i)}return t.set(e,r),r}function s0(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Hs(t)?[]:o0(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((u,d)=>{const f=Tf(t,d,o);return u.top=Gt(f.top,u.top),u.right=qn(f.right,u.right),u.bottom=qn(f.bottom,u.bottom),u.left=Gt(f.left,u.left),u},Tf(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function i0(e){const{width:t,height:n}=bf(e);return{width:t,height:n}}function a0(e,t,n){const r=In(t),o=En(t),s=n==="fixed",i=mr(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=Tn(0);function u(){l.x=Ws(o)}if(r||!r&&!s)if((Dr(t)!=="body"||vo(o))&&(a=Us(t)),r){const p=mr(t,!0,s,t);l.x=p.x+t.clientLeft,l.y=p.y+t.clientTop}else o&&u();s&&!r&&o&&u();const d=o&&!r&&!s?Sf(o,a):Tn(0),f=i.left+a.scrollLeft-l.x-d.x,h=i.top+a.scrollTop-l.y-d.y;return{x:f,y:h,width:i.width,height:i.height}}function Wa(e){return dn(e).position==="static"}function Ef(e,t){if(!In(e)||dn(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return En(e)===n&&(n=n.ownerDocument.body),n}function If(e,t){const n=Yt(e);if(Hs(e))return n;if(!In(e)){let o=Gn(e);for(;o&&!Lr(o);){if(un(o)&&!Wa(o))return o;o=Gn(o)}return n}let r=Ef(e,t);for(;r&&Uw(r)&&Wa(r);)r=Ef(r,t);return r&&Lr(r)&&Wa(r)&&!za(r)?n:r||Gw(e)||n}const l0=async function(e){const t=this.getOffsetParent||If,n=this.getDimensions,r=await n(e.floating);return{reference:a0(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function c0(e){return dn(e).direction==="rtl"}const u0={convertOffsetParentRelativeRectToViewportRelativeRect:Zw,getDocumentElement:En,getClippingRect:s0,getOffsetParent:If,getElementRects:l0,getClientRects:Qw,getDimensions:i0,getScale:$r,isElement:un,isRTL:c0};function Nf(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function d0(e,t){let n=null,r;const o=En(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const u=e.getBoundingClientRect(),{left:d,top:f,width:h,height:p}=u;if(a||t(),!h||!p)return;const v=$s(f),x=$s(o.clientWidth-(d+h)),g=$s(o.clientHeight-(f+p)),y=$s(d),S={rootMargin:-v+"px "+-x+"px "+-g+"px "+-y+"px",threshold:Gt(0,qn(1,l))||1};let I=!0;function C(T){const E=T[0].intersectionRatio;if(E!==l){if(!I)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!Nf(u,e.getBoundingClientRect())&&i(),I=!1}try{n=new IntersectionObserver(C,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(C,S)}n.observe(e)}return i(!0),s}function f0(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,u=Ua(e),d=o||s?[...u?bo(u):[],...bo(t)]:[];d.forEach(y=>{o&&y.addEventListener("scroll",n,{passive:!0}),s&&y.addEventListener("resize",n)});const f=u&&a?d0(u,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(y=>{let[b]=y;b&&b.target===u&&p&&(p.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var S;(S=p)==null||S.observe(t)})),n()}),u&&!l&&p.observe(u),p.observe(t));let v,x=l?mr(e):null;l&&g();function g(){const y=mr(e);x&&!Nf(x,y)&&n(),x=y,v=requestAnimationFrame(g)}return n(),()=>{var y;d.forEach(b=>{o&&b.removeEventListener("scroll",n),s&&b.removeEventListener("resize",n)}),f==null||f(),(y=p)==null||y.disconnect(),p=null,l&&cancelAnimationFrame(v)}}const h0=Lw,p0=$w,m0=Ow,g0=zw,x0=Mw,Af=Pw,y0=Fw,v0=(e,t,n)=>{const r=new Map,o={platform:u0,...n},s={...o.platform,_c:r};return Rw(e,t,{...o,platform:s})};var b0=typeof document<"u",w0=function(){},Vs=b0?w.useLayoutEffect:w0;function Ks(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(!Ks(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)&&!Ks(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function _f(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function jf(e,t){const n=_f(e);return Math.round(t*n)/n}function Va(e){const t=m.useRef(e);return Vs(()=>{t.current=e}),t}function S0(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:u}=e,[d,f]=m.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[h,p]=m.useState(r);Ks(h,r)||p(r);const[v,x]=m.useState(null),[g,y]=m.useState(null),b=m.useCallback(z=>{z!==T.current&&(T.current=z,x(z))},[]),S=m.useCallback(z=>{z!==E.current&&(E.current=z,y(z))},[]),I=s||v,C=i||g,T=m.useRef(null),E=m.useRef(null),A=m.useRef(d),j=l!=null,P=Va(l),D=Va(o),L=Va(u),V=m.useCallback(()=>{if(!T.current||!E.current)return;const z={placement:t,strategy:n,middleware:h};D.current&&(z.platform=D.current),v0(T.current,E.current,z).then($=>{const pe={...$,isPositioned:L.current!==!1};M.current&&!Ks(A.current,pe)&&(A.current=pe,Ro.flushSync(()=>{f(pe)}))})},[h,t,n,D,L]);Vs(()=>{u===!1&&A.current.isPositioned&&(A.current.isPositioned=!1,f(z=>({...z,isPositioned:!1})))},[u]);const M=m.useRef(!1);Vs(()=>(M.current=!0,()=>{M.current=!1}),[]),Vs(()=>{if(I&&(T.current=I),C&&(E.current=C),I&&C){if(P.current)return P.current(I,C,V);V()}},[I,C,V,P,j]);const Y=m.useMemo(()=>({reference:T,floating:E,setReference:b,setFloating:S}),[b,S]),K=m.useMemo(()=>({reference:I,floating:C}),[I,C]),q=m.useMemo(()=>{const z={position:n,left:0,top:0};if(!K.floating)return z;const $=jf(K.floating,d.x),pe=jf(K.floating,d.y);return a?{...z,transform:"translate("+$+"px, "+pe+"px)",..._f(K.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:$,top:pe}},[n,a,K.floating,d.x,d.y]);return m.useMemo(()=>({...d,update:V,refs:Y,elements:K,floatingStyles:q}),[d,V,Y,K,q])}const C0=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?Af({element:r.current,padding:o}).fn(n):{}:r?Af({element:r,padding:o}).fn(n):{}}}},T0=(e,t)=>({...h0(e),options:[e,t]}),k0=(e,t)=>({...p0(e),options:[e,t]}),E0=(e,t)=>({...y0(e),options:[e,t]}),I0=(e,t)=>({...m0(e),options:[e,t]}),N0=(e,t)=>({...g0(e),options:[e,t]}),A0=(e,t)=>({...x0(e),options:[e,t]}),_0=(e,t)=>({...C0(e),options:[e,t]});var j0="Arrow",Rf=m.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return c.jsx(Ae.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:c.jsx("polygon",{points:"0,0 30,0 15,10"})})});Rf.displayName=j0;var R0=Rf;function Pf(e){const[t,n]=m.useState(void 0);return wt(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,u=Array.isArray(l)?l[0]:l;i=u.inlineSize,a=u.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 Ka="Popper",[Of,qs]=wn(Ka),[P0,Mf]=Of(Ka),Df=e=>{const{__scopePopper:t,children:n}=e,[r,o]=m.useState(null);return c.jsx(P0,{scope:t,anchor:r,onAnchorChange:o,children:n})};Df.displayName=Ka;var Lf="PopperAnchor",$f=m.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Mf(Lf,n),i=m.useRef(null),a=Ue(t,i),l=m.useRef(null);return m.useEffect(()=>{const u=l.current;l.current=(r==null?void 0:r.current)||i.current,u!==l.current&&s.onAnchorChange(l.current)}),r?null:c.jsx(Ae.div,{...o,ref:a})});$f.displayName=Lf;var qa="PopperContent",[O0,M0]=Of(qa),Ff=m.forwardRef((e,t)=>{var G,O,Z,ne,de,ae;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:u=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:h=!1,updatePositionStrategy:p="optimized",onPlaced:v,...x}=e,g=Mf(qa,n),[y,b]=m.useState(null),S=Ue(t,We=>b(We)),[I,C]=m.useState(null),T=Pf(I),E=(T==null?void 0:T.width)??0,A=(T==null?void 0:T.height)??0,j=r+(s!=="center"?"-"+s:""),P=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},D=Array.isArray(u)?u:[u],L=D.length>0,V={padding:P,boundary:D.filter(L0),altBoundary:L},{refs:M,floatingStyles:Y,placement:K,isPositioned:q,middlewareData:z}=S0({strategy:"fixed",placement:j,whileElementsMounted:(...We)=>f0(...We,{animationFrame:p==="always"}),elements:{reference:g.anchor},middleware:[T0({mainAxis:o+A,alignmentAxis:i}),l&&k0({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?E0():void 0,...V}),l&&I0({...V}),N0({...V,apply:({elements:We,rects:Ze,availableWidth:ve,availableHeight:Oe})=>{const{width:Le,height:ct}=Ze.reference,rt=We.floating.style;rt.setProperty("--radix-popper-available-width",`${ve}px`),rt.setProperty("--radix-popper-available-height",`${Oe}px`),rt.setProperty("--radix-popper-anchor-width",`${Le}px`),rt.setProperty("--radix-popper-anchor-height",`${ct}px`)}}),I&&_0({element:I,padding:a}),$0({arrowWidth:E,arrowHeight:A}),h&&A0({strategy:"referenceHidden",...V})]}),[$,pe]=Hf(K),F=Et(v);wt(()=>{q&&(F==null||F())},[q,F]);const te=(G=z.arrow)==null?void 0:G.x,fe=(O=z.arrow)==null?void 0:O.y,me=((Z=z.arrow)==null?void 0:Z.centerOffset)!==0,[be,Te]=m.useState();return wt(()=>{y&&Te(window.getComputedStyle(y).zIndex)},[y]),c.jsx("div",{ref:M.setFloating,"data-radix-popper-content-wrapper":"",style:{...Y,transform:q?Y.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:be,"--radix-popper-transform-origin":[(ne=z.transformOrigin)==null?void 0:ne.x,(de=z.transformOrigin)==null?void 0:de.y].join(" "),...((ae=z.hide)==null?void 0:ae.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:c.jsx(O0,{scope:n,placedSide:$,onArrowChange:C,arrowX:te,arrowY:fe,shouldHideArrow:me,children:c.jsx(Ae.div,{"data-side":$,"data-align":pe,...x,ref:S,style:{...x.style,animation:q?void 0:"none"}})})})});Ff.displayName=qa;var zf="PopperArrow",D0={top:"bottom",right:"left",bottom:"top",left:"right"},Bf=m.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=M0(zf,r),i=D0[s.placedSide];return c.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:c.jsx(R0,{...o,ref:n,style:{...o.style,display:"block"}})})});Bf.displayName=zf;function L0(e){return e!==null}var $0=e=>({name:"transformOrigin",options:e,fn(t){var g,y,b;const{placement:n,rects:r,middlewareData:o}=t,i=((g=o.arrow)==null?void 0:g.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[u,d]=Hf(n),f={start:"0%",center:"50%",end:"100%"}[d],h=(((y=o.arrow)==null?void 0:y.x)??0)+a/2,p=(((b=o.arrow)==null?void 0:b.y)??0)+l/2;let v="",x="";return u==="bottom"?(v=i?f:`${h}px`,x=`${-l}px`):u==="top"?(v=i?f:`${h}px`,x=`${r.floating.height+l}px`):u==="right"?(v=`${-l}px`,x=i?f:`${p}px`):u==="left"&&(v=`${r.floating.width+l}px`,x=i?f:`${p}px`),{data:{x:v,y:x}}}});function Hf(e){const[t,n="center"]=e.split("-");return[t,n]}var Uf=Df,Wf=$f,Vf=Ff,Kf=Bf,Ga="rovingFocusGroup.onEntryFocus",F0={bubbles:!1,cancelable:!0},wo="RovingFocusGroup",[Ya,qf,z0]=Oa(wo),[B0,Gf]=wn(wo,[z0]),[H0,U0]=B0(wo),Yf=m.forwardRef((e,t)=>c.jsx(Ya.Provider,{scope:e.__scopeRovingFocusGroup,children:c.jsx(Ya.Slot,{scope:e.__scopeRovingFocusGroup,children:c.jsx(W0,{...e,ref:t})})}));Yf.displayName=wo;var W0=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:u,preventScrollOnEntryFocus:d=!1,...f}=e,h=m.useRef(null),p=Ue(t,h),v=Ds(s),[x,g]=ur({prop:i,defaultProp:a??null,onChange:l,caller:wo}),[y,b]=m.useState(!1),S=Et(u),I=qf(n),C=m.useRef(!1),[T,E]=m.useState(0);return m.useEffect(()=>{const A=h.current;if(A)return A.addEventListener(Ga,S),()=>A.removeEventListener(Ga,S)},[S]),c.jsx(H0,{scope:n,orientation:r,dir:v,loop:o,currentTabStopId:x,onItemFocus:m.useCallback(A=>g(A),[g]),onItemShiftTab:m.useCallback(()=>b(!0),[]),onFocusableItemAdd:m.useCallback(()=>E(A=>A+1),[]),onFocusableItemRemove:m.useCallback(()=>E(A=>A-1),[]),children:c.jsx(Ae.div,{tabIndex:y||T===0?-1:0,"data-orientation":r,...f,ref:p,style:{outline:"none",...e.style},onMouseDown:ue(e.onMouseDown,()=>{C.current=!0}),onFocus:ue(e.onFocus,A=>{const j=!C.current;if(A.target===A.currentTarget&&j&&!y){const P=new CustomEvent(Ga,F0);if(A.currentTarget.dispatchEvent(P),!P.defaultPrevented){const D=I().filter(K=>K.focusable),L=D.find(K=>K.active),V=D.find(K=>K.id===x),Y=[L,V,...D].filter(Boolean).map(K=>K.ref.current);Zf(Y,d)}}C.current=!1}),onBlur:ue(e.onBlur,()=>b(!1))})})}),Xf="RovingFocusGroupItem",Jf=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=Sn(),u=s||l,d=U0(Xf,n),f=d.currentTabStopId===u,h=qf(n),{onFocusableItemAdd:p,onFocusableItemRemove:v,currentTabStopId:x}=d;return m.useEffect(()=>{if(r)return p(),()=>v()},[r,p,v]),c.jsx(Ya.ItemSlot,{scope:n,id:u,focusable:r,active:o,children:c.jsx(Ae.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:ue(e.onMouseDown,g=>{r?d.onItemFocus(u):g.preventDefault()}),onFocus:ue(e.onFocus,()=>d.onItemFocus(u)),onKeyDown:ue(e.onKeyDown,g=>{if(g.key==="Tab"&&g.shiftKey){d.onItemShiftTab();return}if(g.target!==g.currentTarget)return;const y=q0(g,d.orientation,d.dir);if(y!==void 0){if(g.metaKey||g.ctrlKey||g.altKey||g.shiftKey)return;g.preventDefault();let S=h().filter(I=>I.focusable).map(I=>I.ref.current);if(y==="last")S.reverse();else if(y==="prev"||y==="next"){y==="prev"&&S.reverse();const I=S.indexOf(g.currentTarget);S=d.loop?G0(S,I+1):S.slice(I+1)}setTimeout(()=>Zf(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:x!=null}):i})})});Jf.displayName=Xf;var V0={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function K0(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function q0(e,t,n){const r=K0(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return V0[r]}function Zf(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function G0(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Y0=Yf,X0=Jf,Xa=["Enter"," "],J0=["ArrowDown","PageUp","Home"],Qf=["ArrowUp","PageDown","End"],Z0=[...J0,...Qf],Q0={ltr:[...Xa,"ArrowRight"],rtl:[...Xa,"ArrowLeft"]},eS={ltr:["ArrowLeft"],rtl:["ArrowRight"]},So="Menu",[Co,tS,nS]=Oa(So),[gr,eh]=wn(So,[nS,qs,Gf]),Gs=qs(),th=Gf(),[rS,xr]=gr(So),[oS,To]=gr(So),nh=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=Gs(t),[l,u]=m.useState(null),d=m.useRef(!1),f=Et(s),h=Ds(o);return m.useEffect(()=>{const p=()=>{d.current=!0,document.addEventListener("pointerdown",v,{capture:!0,once:!0}),document.addEventListener("pointermove",v,{capture:!0,once:!0})},v=()=>d.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",v,{capture:!0}),document.removeEventListener("pointermove",v,{capture:!0})}},[]),c.jsx(Uf,{...a,children:c.jsx(rS,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:u,children:c.jsx(oS,{scope:t,onClose:m.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};nh.displayName=So;var sS="MenuAnchor",Ja=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Gs(n);return c.jsx(Wf,{...o,...r,ref:t})});Ja.displayName=sS;var Za="MenuPortal",[iS,rh]=gr(Za,{forceMount:void 0}),oh=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=xr(Za,t);return c.jsx(iS,{scope:t,forceMount:n,children:c.jsx(qt,{present:n||s.open,children:c.jsx(bs,{asChild:!0,container:o,children:r})})})};oh.displayName=Za;var Qt="MenuContent",[aS,Qa]=gr(Qt),sh=m.forwardRef((e,t)=>{const n=rh(Qt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=xr(Qt,e.__scopeMenu),i=To(Qt,e.__scopeMenu);return c.jsx(Co.Provider,{scope:e.__scopeMenu,children:c.jsx(qt,{present:r||s.open,children:c.jsx(Co.Slot,{scope:e.__scopeMenu,children:i.modal?c.jsx(lS,{...o,ref:t}):c.jsx(cS,{...o,ref:t})})})})}),lS=m.forwardRef((e,t)=>{const n=xr(Qt,e.__scopeMenu),r=m.useRef(null),o=Ue(t,r);return m.useEffect(()=>{const s=r.current;if(s)return Na(s)},[]),c.jsx(el,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ue(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),cS=m.forwardRef((e,t)=>{const n=xr(Qt,e.__scopeMenu);return c.jsx(el,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),uS=nr.createSlot("MenuContent.ScrollLock"),el=m.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,disableOutsideScroll:v,...x}=e,g=xr(Qt,n),y=To(Qt,n),b=Gs(n),S=th(n),I=tS(n),[C,T]=m.useState(null),E=m.useRef(null),A=Ue(t,E,g.onContentChange),j=m.useRef(0),P=m.useRef(""),D=m.useRef(0),L=m.useRef(null),V=m.useRef("right"),M=m.useRef(0),Y=v?Es:m.Fragment,K=v?{as:uS,allowPinchZoom:!0}:void 0,q=$=>{var G,O;const pe=P.current+$,F=I().filter(Z=>!Z.disabled),te=document.activeElement,fe=(G=F.find(Z=>Z.ref.current===te))==null?void 0:G.textValue,me=F.map(Z=>Z.textValue),be=SS(me,pe,fe),Te=(O=F.find(Z=>Z.textValue===be))==null?void 0:O.ref.current;(function Z(ne){P.current=ne,window.clearTimeout(j.current),ne!==""&&(j.current=window.setTimeout(()=>Z(""),1e3))})(pe),Te&&setTimeout(()=>Te.focus())};m.useEffect(()=>()=>window.clearTimeout(j.current),[]),Sa();const z=m.useCallback($=>{var F,te;return V.current===((F=L.current)==null?void 0:F.side)&&TS($,(te=L.current)==null?void 0:te.area)},[]);return c.jsx(aS,{scope:n,searchRef:P,onItemEnter:m.useCallback($=>{z($)&&$.preventDefault()},[z]),onItemLeave:m.useCallback($=>{var pe;z($)||((pe=E.current)==null||pe.focus(),T(null))},[z]),onTriggerLeave:m.useCallback($=>{z($)&&$.preventDefault()},[z]),pointerGraceTimerRef:D,onPointerGraceIntentChange:m.useCallback($=>{L.current=$},[]),children:c.jsx(Y,{...K,children:c.jsx(vs,{asChild:!0,trapped:o,onMountAutoFocus:ue(s,$=>{var pe;$.preventDefault(),(pe=E.current)==null||pe.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:c.jsx(ys,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:c.jsx(Y0,{asChild:!0,...S,dir:y.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:T,onEntryFocus:ue(l,$=>{y.isUsingKeyboardRef.current||$.preventDefault()}),preventScrollOnEntryFocus:!0,children:c.jsx(Vf,{role:"menu","aria-orientation":"vertical","data-state":Sh(g.open),"data-radix-menu-content":"",dir:y.dir,...b,...x,ref:A,style:{outline:"none",...x.style},onKeyDown:ue(x.onKeyDown,$=>{const F=$.target.closest("[data-radix-menu-content]")===$.currentTarget,te=$.ctrlKey||$.altKey||$.metaKey,fe=$.key.length===1;F&&($.key==="Tab"&&$.preventDefault(),!te&&fe&&q($.key));const me=E.current;if($.target!==me||!Z0.includes($.key))return;$.preventDefault();const Te=I().filter(G=>!G.disabled).map(G=>G.ref.current);Qf.includes($.key)&&Te.reverse(),bS(Te)}),onBlur:ue(e.onBlur,$=>{$.currentTarget.contains($.target)||(window.clearTimeout(j.current),P.current="")}),onPointerMove:ue(e.onPointerMove,Eo($=>{const pe=$.target,F=M.current!==$.clientX;if($.currentTarget.contains(pe)&&F){const te=$.clientX>M.current?"right":"left";V.current=te,M.current=$.clientX}}))})})})})})})});sh.displayName=Qt;var dS="MenuGroup",tl=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(Ae.div,{role:"group",...r,ref:t})});tl.displayName=dS;var fS="MenuLabel",ih=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(Ae.div,{...r,ref:t})});ih.displayName=fS;var Ys="MenuItem",ah="menu.itemSelect",Xs=m.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=m.useRef(null),i=To(Ys,e.__scopeMenu),a=Qa(Ys,e.__scopeMenu),l=Ue(t,s),u=m.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(ah,{bubbles:!0,cancelable:!0});f.addEventListener(ah,p=>r==null?void 0:r(p),{once:!0}),Bu(f,h),h.defaultPrevented?u.current=!1:i.onClose()}};return c.jsx(lh,{...o,ref:l,disabled:n,onClick:ue(e.onClick,d),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),u.current=!0},onPointerUp:ue(e.onPointerUp,f=>{var h;u.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:ue(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||Xa.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});Xs.displayName=Ys;var lh=m.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=Qa(Ys,n),a=th(n),l=m.useRef(null),u=Ue(t,l),[d,f]=m.useState(!1),[h,p]=m.useState("");return m.useEffect(()=>{const v=l.current;v&&p((v.textContent??"").trim())},[s.children]),c.jsx(Co.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:c.jsx(X0,{asChild:!0,...a,focusable:!r,children:c.jsx(Ae.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:u,onPointerMove:ue(e.onPointerMove,Eo(v=>{r?i.onItemLeave(v):(i.onItemEnter(v),v.defaultPrevented||v.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ue(e.onPointerLeave,Eo(v=>i.onItemLeave(v))),onFocus:ue(e.onFocus,()=>f(!0)),onBlur:ue(e.onBlur,()=>f(!1))})})})}),hS="MenuCheckboxItem",ch=m.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return c.jsx(ph,{scope:e.__scopeMenu,checked:n,children:c.jsx(Xs,{role:"menuitemcheckbox","aria-checked":Js(n)?"mixed":n,...o,ref:t,"data-state":rl(n),onSelect:ue(o.onSelect,()=>r==null?void 0:r(Js(n)?!0:!n),{checkForDefaultPrevented:!1})})})});ch.displayName=hS;var uh="MenuRadioGroup",[pS,mS]=gr(uh,{value:void 0,onValueChange:()=>{}}),dh=m.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=Et(r);return c.jsx(pS,{scope:e.__scopeMenu,value:n,onValueChange:s,children:c.jsx(tl,{...o,ref:t})})});dh.displayName=uh;var fh="MenuRadioItem",hh=m.forwardRef((e,t)=>{const{value:n,...r}=e,o=mS(fh,e.__scopeMenu),s=n===o.value;return c.jsx(ph,{scope:e.__scopeMenu,checked:s,children:c.jsx(Xs,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":rl(s),onSelect:ue(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});hh.displayName=fh;var nl="MenuItemIndicator",[ph,gS]=gr(nl,{checked:!1}),mh=m.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=gS(nl,n);return c.jsx(qt,{present:r||Js(s.checked)||s.checked===!0,children:c.jsx(Ae.span,{...o,ref:t,"data-state":rl(s.checked)})})});mh.displayName=nl;var xS="MenuSeparator",gh=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(Ae.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});gh.displayName=xS;var yS="MenuArrow",xh=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Gs(n);return c.jsx(Kf,{...o,...r,ref:t})});xh.displayName=yS;var vS="MenuSub",[ok,yh]=gr(vS),ko="MenuSubTrigger",vh=m.forwardRef((e,t)=>{const n=xr(ko,e.__scopeMenu),r=To(ko,e.__scopeMenu),o=yh(ko,e.__scopeMenu),s=Qa(ko,e.__scopeMenu),i=m.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,u={__scopeMenu:e.__scopeMenu},d=m.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return m.useEffect(()=>d,[d]),m.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),c.jsx(Ja,{asChild:!0,...u,children:c.jsx(lh,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Sh(n.open),...e,ref:la(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:ue(e.onPointerMove,Eo(f=>{s.onItemEnter(f),!f.defaultPrevented&&!e.disabled&&!n.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{n.onOpenChange(!0),d()},100))})),onPointerLeave:ue(e.onPointerLeave,Eo(f=>{var p,v;d();const h=(p=n.content)==null?void 0:p.getBoundingClientRect();if(h){const x=(v=n.content)==null?void 0:v.dataset.side,g=x==="right",y=g?-5:5,b=h[g?"left":"right"],S=h[g?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+y,y:f.clientY},{x:b,y:h.top},{x:S,y:h.top},{x:S,y:h.bottom},{x:b,y:h.bottom}],side:x}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:ue(e.onKeyDown,f=>{var p;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||Q0[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});vh.displayName=ko;var bh="MenuSubContent",wh=m.forwardRef((e,t)=>{const n=rh(Qt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=xr(Qt,e.__scopeMenu),i=To(Qt,e.__scopeMenu),a=yh(bh,e.__scopeMenu),l=m.useRef(null),u=Ue(t,l);return c.jsx(Co.Provider,{scope:e.__scopeMenu,children:c.jsx(qt,{present:r||s.open,children:c.jsx(Co.Slot,{scope:e.__scopeMenu,children:c.jsx(el,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:u,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var f;i.isUsingKeyboardRef.current&&((f=l.current)==null||f.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside:ue(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ue(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:ue(e.onKeyDown,d=>{var p;const f=d.currentTarget.contains(d.target),h=eS[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),d.preventDefault())})})})})})});wh.displayName=bh;function Sh(e){return e?"open":"closed"}function Js(e){return e==="indeterminate"}function rl(e){return Js(e)?"indeterminate":e?"checked":"unchecked"}function bS(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function wS(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function SS(e,t,n){const o=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=wS(e,Math.max(s,0));o.length===1&&(i=i.filter(u=>u!==n));const l=i.find(u=>u.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function CS(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],u=a.x,d=a.y,f=l.x,h=l.y;d>r!=h>r&&n<(f-u)*(r-d)/(h-d)+u&&(o=!o)}return o}function TS(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return CS(n,t)}function Eo(e){return t=>t.pointerType==="mouse"?e(t):void 0}var kS=nh,ES=Ja,IS=oh,NS=sh,AS=tl,_S=ih,jS=Xs,RS=ch,PS=dh,OS=hh,MS=mh,DS=gh,LS=xh,$S=vh,FS=wh,Zs="DropdownMenu",[zS,sk]=wn(Zs,[eh]),Ot=eh(),[BS,Ch]=zS(Zs),Th=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=Ot(t),u=m.useRef(null),[d,f]=ur({prop:o,defaultProp:s??!1,onChange:i,caller:Zs});return c.jsx(BS,{scope:t,triggerId:Sn(),triggerRef:u,contentId:Sn(),open:d,onOpenChange:f,onOpenToggle:m.useCallback(()=>f(h=>!h),[f]),modal:a,children:c.jsx(kS,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};Th.displayName=Zs;var kh="DropdownMenuTrigger",Eh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Ch(kh,n),i=Ot(n);return c.jsx(ES,{asChild:!0,...i,children:c.jsx(Ae.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...o,ref:la(t,s.triggerRef),onPointerDown:ue(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:ue(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});Eh.displayName=kh;var HS="DropdownMenuPortal",Ih=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Ot(t);return c.jsx(IS,{...r,...n})};Ih.displayName=HS;var Nh="DropdownMenuContent",Ah=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ch(Nh,n),s=Ot(n),i=m.useRef(!1);return c.jsx(NS,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:ue(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:ue(e.onInteractOutside,a=>{const l=a.detail.originalEvent,u=l.button===0&&l.ctrlKey===!0,d=l.button===2||u;(!o.modal||d)&&(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)"}})});Ah.displayName=Nh;var US="DropdownMenuGroup",WS=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return c.jsx(AS,{...o,...r,ref:t})});WS.displayName=US;var VS="DropdownMenuLabel",_h=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return c.jsx(_S,{...o,...r,ref:t})});_h.displayName=VS;var KS="DropdownMenuItem",jh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return c.jsx(jS,{...o,...r,ref:t})});jh.displayName=KS;var qS="DropdownMenuCheckboxItem",Rh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return c.jsx(RS,{...o,...r,ref:t})});Rh.displayName=qS;var GS="DropdownMenuRadioGroup",YS=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return c.jsx(PS,{...o,...r,ref:t})});YS.displayName=GS;var XS="DropdownMenuRadioItem",Ph=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return c.jsx(OS,{...o,...r,ref:t})});Ph.displayName=XS;var JS="DropdownMenuItemIndicator",Oh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return c.jsx(MS,{...o,...r,ref:t})});Oh.displayName=JS;var ZS="DropdownMenuSeparator",Mh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return c.jsx(DS,{...o,...r,ref:t})});Mh.displayName=ZS;var QS="DropdownMenuArrow",eC=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return c.jsx(LS,{...o,...r,ref:t})});eC.displayName=QS;var tC="DropdownMenuSubTrigger",Dh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return c.jsx($S,{...o,...r,ref:t})});Dh.displayName=tC;var nC="DropdownMenuSubContent",Lh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ot(n);return c.jsx(FS,{...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)"}})});Lh.displayName=nC;var rC=Th,oC=Eh,sC=Ih,$h=Ah,Fh=_h,zh=jh,Bh=Rh,Hh=Ph,Uh=Oh,Wh=Mh,Vh=Dh,Kh=Lh;const iC=rC,aC=oC,lC=m.forwardRef(({className:e,inset:t,children:n,...r},o)=>c.jsxs(Vh,{ref:o,className:ee("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,c.jsx(ie.ChevronRight,{className:"ml-auto h-4 w-4"})]}));lC.displayName=Vh.displayName;const cC=m.forwardRef(({className:e,...t},n)=>c.jsx(Kh,{ref:n,className:ee("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}));cC.displayName=Kh.displayName;const qh=m.forwardRef(({className:e,sideOffset:t=4,...n},r)=>c.jsx(sC,{children:c.jsx($h,{ref:r,sideOffset:t,className:ee("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})}));qh.displayName=$h.displayName;const ol=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(zh,{ref:r,className:ee("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}));ol.displayName=zh.displayName;const uC=m.forwardRef(({className:e,children:t,checked:n,...r},o)=>c.jsxs(Bh,{ref:o,className:ee("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:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(Uh,{children:c.jsx(ie.Check,{className:"h-4 w-4"})})}),t]}));uC.displayName=Bh.displayName;const dC=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Hh,{ref:r,className:ee("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:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(Uh,{children:c.jsx(ie.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));dC.displayName=Hh.displayName;const fC=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(Fh,{ref:r,className:ee("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));fC.displayName=Fh.displayName;const hC=m.forwardRef(({className:e,...t},n)=>c.jsx(Wh,{ref:n,className:ee("-mx-1 my-1 h-px bg-muted",e),...t}));hC.displayName=Wh.displayName;function Qs({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:u=!0,customStyles:d={},onMessageSent:f,onExcelUploadSuccess:h,onError:p}){const{api:v}=Ii(),{currentThreadId:x}=qo(),{threadId:g,messages:y,hasMore:b,isHistoryLoading:S,isLoading:I,loadOlder:C,navigateToCheckpoint:T,returnToLatest:E,checkpoint:A,checkpoints:j,respondToInterrupt:P,metadata:D}=Go(),{isStreaming:L,error:V,submit:M,stop:Y}=zc(),K=(A==null?void 0:A.id)??null,q=(A==null?void 0:A.namespace)??null,z=(D==null?void 0:D.assemblingMessageId)??null,[$,pe]=w.useState(null),[F,te]=w.useState(""),[fe,me]=w.useState(null),[be,Te]=w.useState([]),[G,O]=w.useState(0),[Z,ne]=w.useState(0),[de,ae]=w.useState(!1),[We,Ze]=w.useState(null),[ve,Oe]=w.useState(null),[Le,ct]=w.useState(!1),[rt,vt]=w.useState(null),[St,B]=w.useState(!1),se=w.useRef(null),we=w.useRef(null),Ie=w.useCallback(()=>{se.current&&(se.current.value=""),we.current&&(we.current.value=""),O(he=>he+1),ne(he=>he+1)},[]),xe=w.useRef(!1);w.useEffect(()=>{xe.current&&!L&&(Te([]),Ie()),xe.current=L},[L,Ie]);const[Re,Qe]=w.useState("desktop");w.useEffect(()=>{const he=()=>{const ye=window.innerWidth;Qe(ye<640?"phone":ye<1024?"tablet":"desktop")};return he(),window.addEventListener("resize",he),()=>window.removeEventListener("resize",he)},[]);const Fe=w.useCallback(async()=>{if(!(!b||S))try{await C()}catch(he){console.warn("loadOlder failed",he)}},[b,S,C]);w.useEffect(()=>{(async()=>{if(!v.baseUrl){vt(null);return}try{const ye=await v.getAgent("default");vt(ye.uiDefaultMessage||null)}catch(ye){console.warn("Failed to fetch default message:",ye),vt(null)}})()},[v]),w.useEffect(()=>{V&&!Le&&(p==null||p(V))},[V,Le,p]);const pt=he=>{if(he.length>Ms)return`Message too long (${he.length}/${Ms} characters)`;try{return vw(he),null}catch(ye){return(ye==null?void 0:ye.message)||"Invalid message"}},Ct=async he=>{const ye=he.trim();if(!(!ye&&be.length===0)){if(ye){const et=pt(ye);if(et){me(et);return}}try{await M({text:ye||"",attachments:be,payload:$?{edit:!0,originalMessageId:$}:void 0},{checkpointId:K??void 0,checkpointNs:q??void 0}),f==null||f(ye),me(null),Te([]),Ie(),pe(null),te("")}catch(et){const dt=(et==null?void 0:et.message)||"Failed to send message";me(dt),p==null||p(dt)}}},nn=w.useCallback((he,ye)=>{u&&(pe(he),te(ye),me(null))},[u]),zt=w.useCallback(()=>{pe(null),te(""),me(null)},[]),hn=w.useCallback((he,ye)=>{nn(he,ye)},[nn]),An=w.useCallback(he=>{const ye=et=>{const dt=et.content||[],ft=dt.filter(on=>on.type==="text").map(on=>on.text).join("");if(ft)return ft;try{return JSON.stringify(dt,null,2)}catch{return String(dt)}};for(let et=he-1;et>=0;et--)if(y[et].role==="user"){const dt=ye(y[et]);dt&&M({text:dt},{checkpointId:K??void 0,checkpointNs:q??void 0});break}},[y,M,K,q]),Hr=he=>{const ye=Array.from(he.target.files||[]);Te(et=>[...et,...ye]),he.target.value=""},Zn=he=>{Te(ye=>{const et=ye.filter((dt,ft)=>he!==ft);return et.length===0&&Ie(),et})},rn=async he=>{const ye=(he.target.files||[])[0];if(ye){Ze(null),Oe(null),ae(!0);try{await M({attachments:[ye]},{checkpointId:K??void 0,checkpointNs:q??void 0});const et=`Uploaded ${ye.name} - processing through chat stream`;Oe(et)}catch(et){const dt=et instanceof Error?et.message:"Failed to upload Excel file";console.error("Excel upload failed",et),Ze(dt),p==null||p(dt)}finally{ae(!1),he.target.value="",Ie()}}},Mn=he=>{if(!he)return"Unknown";const ye=Date.parse(he);return Number.isNaN(ye)?he:new Date(ye).toLocaleString()},Mt=async he=>{if(x){B(!0);try{if(!he){await E();return}const ye=j.find(dt=>dt.checkpointId===he),et=(ye==null?void 0:ye.checkpointNs)??null;await T(he,et)}finally{B(!1)}}},Qn=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${d.container||""}`,Ur=`flex-1 min-h-0 min-w-0 max-h-full w-full overflow-hidden overscroll-contain break-words break-anywhere p-4 bg-transparent ${d.messagesArea||""}`,Wr=`flex-shrink-0 w-full border-t p-4 bg-transparent ${d.inputArea||""}`;return c.jsxs("div",{className:Qn,children:[!!V&&!Le&&c.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:[c.jsx("span",{children:V}),c.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>ct(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:c.jsx(ie.X,{size:16})})]}),x&&j.length>0&&c.jsxs("div",{className:"flex-shrink-0 flex items-center gap-2 px-4 py-2 border-b border-border bg-muted/60 text-xs dark:bg-muted/50",children:[c.jsx("span",{className:"opacity-70",children:"Checkpoint:"}),c.jsxs("select",{className:"border border-border rounded px-2 py-1 text-xs bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring dark:bg-secondary",value:K??"",onChange:he=>{const ye=he.target.value||null;Mt(ye)},children:[c.jsx("option",{value:"",children:"Latest"}),j.map(he=>c.jsxs("option",{value:he.checkpointId,children:[Mn(he.createdAt),he.preview?` — ${he.preview.slice(0,40)}`:""]},he.checkpointId))]})]}),c.jsxs("div",{className:`relative ${Ur}`,style:r?{maxHeight:r}:void 0,children:[c.jsx(Pa,{className:"h-full",style:{height:"100%"},messages:y,isStreaming:L,streamingAssistantId:z,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:Re,enableMessageEditing:u,editingMessageId:$,onStartReached:()=>{Fe()},onEdit:hn,onRegenerate:An,onCancelEdit:zt,emptyMessage:rt??void 0,isNavigatingCheckpoint:St}),I&&c.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:[c.jsx(ie.Loader2,{className:"h-6 w-6 animate-spin"}),c.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]})]}),c.jsxs("div",{className:Wr,children:[$&&c.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ie.Edit3,{size:16,className:"text-blue-600"}),c.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),c.jsx(Ge,{variant:"ghost",size:"sm",onClick:zt,className:"text-blue-600 hover:bg-blue-100",children:c.jsx(ie.X,{size:16})})]})}),(a||l)&&c.jsxs("div",{className:"mb-3 space-y-3",children:[a&&c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:se,type:"file",multiple:!0,onChange:he=>Hr(he),className:"hidden"},G),be.length>0&&c.jsx("div",{className:"flex flex-wrap gap-2",children:be.map((he,ye)=>c.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:[c.jsx(ie.Paperclip,{size:14}),c.jsx("span",{className:"truncate max-w-[150px]",children:he.name}),c.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>Zn(ye),className:"h-4 w-4 p-0 text-gray-500 dark:text-gray-400 hover:text-red-500 dark:hover:text-red-400","aria-label":`Remove ${he.name}`,children:c.jsx(ie.X,{size:12})})]},ye))})]}),l&&c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:we,type:"file",accept:".xls,.xlsx,.xlsm",onChange:rn,className:"hidden"},Z),de&&c.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[c.jsx(ie.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),ve&&!de&&c.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:ve}),We&&!de&&c.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:We})]})]}),fe&&c.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:fe}),c.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&c.jsxs(iC,{children:[c.jsx(aC,{asChild:!0,children:c.jsx(Ge,{type:"button",size:"icon",variant:"outline",disabled:L,title:"More input actions",className:d.moreButton||"",children:c.jsx(ie.Plus,{size:16})})}),c.jsxs(qh,{align:"start",sideOffset:6,className:"w-52",children:[a&&c.jsxs(ol,{onClick:()=>{var he;return(he=se.current)==null?void 0:he.click()},className:"cursor-pointer",children:[c.jsx(ie.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&c.jsxs(ol,{onClick:()=>{var he;de||(he=we.current)==null||he.click()},className:`cursor-pointer ${de?"opacity-60 pointer-events-none":""}`,children:[c.jsx(ie.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),c.jsx("div",{className:"flex-1",children:c.jsx(Rx,{initialValue:F,editingMessageId:$,placeholder:$?"Edit your message...":t,isStreaming:L,disabled:!1,maxLength:Ms,onSend:Ct,onCancelEdit:zt,onStop:Y,allowEmptySend:be.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${$?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${fe?"border-red-400":""} ${d.textarea||""}`})})]})]})]})}const ei=m.forwardRef(({className:e,type:t,...n},r)=>c.jsx("input",{type:t,className:ee("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),ref:r,...n}));ei.displayName="Input";function sl(e,[t,n]){return Math.min(n,Math.max(t,e))}function pC(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var il="ScrollArea",[Gh,ik]=wn(il),[mC,en]=Gh(il),Yh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=m.useState(null),[u,d]=m.useState(null),[f,h]=m.useState(null),[p,v]=m.useState(null),[x,g]=m.useState(null),[y,b]=m.useState(0),[S,I]=m.useState(0),[C,T]=m.useState(!1),[E,A]=m.useState(!1),j=Ue(t,D=>l(D)),P=Ds(o);return c.jsx(mC,{scope:n,type:r,dir:P,scrollHideDelay:s,scrollArea:a,viewport:u,onViewportChange:d,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:v,scrollbarXEnabled:C,onScrollbarXEnabledChange:T,scrollbarY:x,onScrollbarYChange:g,scrollbarYEnabled:E,onScrollbarYEnabledChange:A,onCornerWidthChange:b,onCornerHeightChange:I,children:c.jsx(Ae.div,{dir:P,...i,ref:j,style:{position:"relative","--radix-scroll-area-corner-width":y+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});Yh.displayName=il;var Xh="ScrollAreaViewport",Jh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=en(Xh,n),a=m.useRef(null),l=Ue(t,a,i.onViewportChange);return c.jsxs(c.Fragment,{children:[c.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}),c.jsx(Ae.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:c.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});Jh.displayName=Xh;var Nn="ScrollAreaScrollbar",al=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=en(Nn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return m.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?c.jsx(gC,{...r,ref:t,forceMount:n}):o.type==="scroll"?c.jsx(xC,{...r,ref:t,forceMount:n}):o.type==="auto"?c.jsx(Zh,{...r,ref:t,forceMount:n}):o.type==="always"?c.jsx(ll,{...r,ref:t}):null});al.displayName=Nn;var gC=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=en(Nn,e.__scopeScrollArea),[s,i]=m.useState(!1);return m.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const u=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",u),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",u),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),c.jsx(qt,{present:n||s,children:c.jsx(Zh,{"data-state":s?"visible":"hidden",...r,ref:t})})}),xC=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=en(Nn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=oi(()=>l("SCROLL_END"),100),[a,l]=pC("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 m.useEffect(()=>{if(a==="idle"){const u=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(u)}},[a,o.scrollHideDelay,l]),m.useEffect(()=>{const u=o.viewport,d=s?"scrollLeft":"scrollTop";if(u){let f=u[d];const h=()=>{const p=u[d];f!==p&&(l("SCROLL"),i()),f=p};return u.addEventListener("scroll",h),()=>u.removeEventListener("scroll",h)}},[o.viewport,s,l,i]),c.jsx(qt,{present:n||a!=="hidden",children:c.jsx(ll,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ue(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:ue(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),Zh=m.forwardRef((e,t)=>{const n=en(Nn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=m.useState(!1),a=e.orientation==="horizontal",l=oi(()=>{if(n.viewport){const u=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?u:d)}},10);return Fr(n.viewport,l),Fr(n.content,l),c.jsx(qt,{present:r||s,children:c.jsx(ll,{"data-state":s?"visible":"hidden",...o,ref:t})})}),ll=m.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=en(Nn,e.__scopeScrollArea),s=m.useRef(null),i=m.useRef(0),[a,l]=m.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),u=rp(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:u>0&&u<1,onThumbChange:h=>s.current=h,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:h=>i.current=h};function f(h,p){return CC(h,i.current,a,p)}return n==="horizontal"?c.jsx(yC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=op(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"?c.jsx(vC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=op(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}),yC=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=en(Nn,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),u=Ue(t,l,s.onScrollbarXChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),c.jsx(ep,{"data-orientation":"horizontal",...o,ref:u,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":ri(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(h),ip(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:ni(i.paddingLeft),paddingEnd:ni(i.paddingRight)}})}})}),vC=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=en(Nn,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),u=Ue(t,l,s.onScrollbarYChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),c.jsx(ep,{"data-orientation":"vertical",...o,ref:u,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":ri(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(h),ip(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:ni(i.paddingTop),paddingEnd:ni(i.paddingBottom)}})}})}),[bC,Qh]=Gh(Nn),ep=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:u,onWheelScroll:d,onResize:f,...h}=e,p=en(Nn,n),[v,x]=m.useState(null),g=Ue(t,j=>x(j)),y=m.useRef(null),b=m.useRef(""),S=p.viewport,I=r.content-r.viewport,C=Et(d),T=Et(l),E=oi(f,10);function A(j){if(y.current){const P=j.clientX-y.current.left,D=j.clientY-y.current.top;u({x:P,y:D})}}return m.useEffect(()=>{const j=P=>{const D=P.target;(v==null?void 0:v.contains(D))&&C(P,I)};return document.addEventListener("wheel",j,{passive:!1}),()=>document.removeEventListener("wheel",j,{passive:!1})},[S,v,I,C]),m.useEffect(T,[r,T]),Fr(v,E),Fr(p.content,E),c.jsx(bC,{scope:n,scrollbar:v,hasThumb:o,onThumbChange:Et(s),onThumbPointerUp:Et(i),onThumbPositionChange:T,onThumbPointerDown:Et(a),children:c.jsx(Ae.div,{...h,ref:g,style:{position:"absolute",...h.style},onPointerDown:ue(e.onPointerDown,j=>{j.button===0&&(j.target.setPointerCapture(j.pointerId),y.current=v.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),A(j))}),onPointerMove:ue(e.onPointerMove,A),onPointerUp:ue(e.onPointerUp,j=>{const P=j.target;P.hasPointerCapture(j.pointerId)&&P.releasePointerCapture(j.pointerId),document.body.style.webkitUserSelect=b.current,p.viewport&&(p.viewport.style.scrollBehavior=""),y.current=null})})})}),ti="ScrollAreaThumb",tp=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Qh(ti,e.__scopeScrollArea);return c.jsx(qt,{present:n||o.hasThumb,children:c.jsx(wC,{ref:t,...r})})}),wC=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=en(ti,n),i=Qh(ti,n),{onThumbPositionChange:a}=i,l=Ue(t,f=>i.onThumbChange(f)),u=m.useRef(void 0),d=oi(()=>{u.current&&(u.current(),u.current=void 0)},100);return m.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(d(),!u.current){const p=TC(f,a);u.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,d,a]),c.jsx(Ae.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:l,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:ue(e.onPointerDownCapture,f=>{const p=f.target.getBoundingClientRect(),v=f.clientX-p.left,x=f.clientY-p.top;i.onThumbPointerDown({x:v,y:x})}),onPointerUp:ue(e.onPointerUp,i.onThumbPointerUp)})});tp.displayName=ti;var cl="ScrollAreaCorner",np=m.forwardRef((e,t)=>{const n=en(cl,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?c.jsx(SC,{...e,ref:t}):null});np.displayName=cl;var SC=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=en(cl,n),[s,i]=m.useState(0),[a,l]=m.useState(0),u=!!(s&&a);return Fr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),Fr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),u?c.jsx(Ae.div,{...r,ref:t,style:{width:s,height:a,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function ni(e){return e?parseInt(e,10):0}function rp(e,t){const n=e/t;return isNaN(n)?0:n}function ri(e){const t=rp(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function CC(e,t,n,r="ltr"){const o=ri(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,u=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,f=r==="ltr"?[0,d]:[d*-1,0];return sp([l,u],f)(e)}function op(e,t,n="ltr"){const r=ri(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],u=sl(e,l);return sp([0,i],[0,a])(u)}function sp(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 ip(e,t){return e>0&&e<t}var TC=(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 oi(e,t){const n=Et(e),r=m.useRef(0);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),m.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function Fr(e,t){const n=Et(t);wt(()=>{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 ap=Yh,kC=Jh,EC=np;const lp=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(ap,{ref:r,className:ee("relative overflow-hidden",e),...n,children:[c.jsx(kC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),c.jsx(cp,{}),c.jsx(EC,{})]}));lp.displayName=ap.displayName;const cp=m.forwardRef(({className:e,orientation:t="vertical",...n},r)=>c.jsx(al,{ref:r,orientation:t,className:ee("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:c.jsx(tp,{className:"relative flex-1 rounded-full bg-border"})}));cp.displayName=al.displayName;function ul({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:u,onThreadDelete:d}){const{threads:f,currentThreadId:h,isLoading:p,actions:v}=qo(),{loadThread:x}=Go(),{createThread:g,deleteThread:y,renameThread:b}=v,[S,I]=w.useState(Array.isArray(f)?f:[]),C=w.useRef(S.length>0),[T,E]=w.useState(null),[A,j]=w.useState(""),[P,D]=w.useState(!1);w.useEffect(()=>{const F=Array.isArray(f)?f:[];if(F.length>0){C.current=!0,I(F);return}p||(C.current=!1,I(F))},[f,p]);const L=async F=>{try{await x(F),a==null||a(F),l==null||l(F)}catch(te){console.error("Failed to select thread:",te)}},V=async()=>{try{D(!0);const F=await g();u==null||u(F),a==null||a(F)}catch(F){console.error("Failed to create thread:",F)}finally{D(!1)}},M=async(F,te)=>{if(te.stopPropagation(),!!confirm("Delete this thread?"))try{await y(F),d==null||d(F)}catch(fe){console.error("Failed to delete thread:",fe)}},Y=(F,te)=>{te.stopPropagation(),E(F.threadId),j(F.title||`Thread ${F.threadId.slice(0,8)}`)},K=async F=>{if(A.trim())try{await b(F,A.trim()),E(null),j("")}catch(te){console.error("Failed to update title:",te)}},q=()=>{E(null),j("")},z=(F,te)=>{F.key==="Enter"?K(te):F.key==="Escape"&&q()},$=F=>{if(!F)return"";try{const te=new Date(F),me=new Date().getTime()-te.getTime(),be=Math.floor(me/(1e3*60*60*24));return be===0?te.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):be===1?"Yesterday":be<7?`${be} days ago`:te.toLocaleDateString()}catch{return""}},pe=F=>F.title||`Thread ${F.threadId.slice(0,8)}`;return c.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&c.jsx("div",{className:s.header||"flex-shrink-0 p-2 border-b bg-slate-800 border-slate-700 text-slate-100 flex justify-end",children:c.jsx(Ge,{onClick:V,disabled:P||p,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:P?"Creating...":"New Chat",children:c.jsx(ie.MessageSquarePlus,{size:20})})}),c.jsx(lp,{className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:c.jsx("div",{className:"p-2 space-y-1 pb-4",children:p?c.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[c.jsx(ie.Loader2,{className:"h-5 w-5 animate-spin"}),c.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):S.length===0?c.jsxs("div",{className:"text-center py-8 text-slate-400",children:[c.jsx(ie.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),c.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):S.slice().sort((F,te)=>new Date(te.updatedAt||te.createdAt||"").getTime()-new Date(F.updatedAt||F.createdAt||"").getTime()).map(F=>c.jsxs("div",{onClick:()=>L(F.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??h)===F.threadId?`${s.activeThread||"bg-slate-600 border-slate-500"} `:`${s.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${s.threadItem||""} text-gray-900 dark:text-slate-100`,children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("div",{className:"flex-1 min-w-0",children:T===F.threadId?c.jsxs("div",{className:"flex items-center gap-2",onClick:te=>te.stopPropagation(),children:[c.jsx(ei,{value:A,onChange:te=>j(te.target.value),onKeyDown:te=>z(te,F.threadId),className:"h-6 text-sm",autoFocus:!0}),c.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>K(F.threadId),className:"h-6 w-6 p-0",children:c.jsx(ie.Check,{size:12})}),c.jsx(Ge,{variant:"ghost",size:"sm",onClick:q,className:"h-6 w-6 p-0",children:c.jsx(ie.X,{size:12})})]}):c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:pe(F)}),c.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[c.jsx(ie.Calendar,{size:10}),c.jsx("span",{children:$(F.updatedAt||F.createdAt)})]})]})}),c.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&T!==F.threadId&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:te=>Y(F,te),className:"h-6 w-6 p-0",title:"Edit title",children:c.jsx(ie.Edit3,{size:12})}),n&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:te=>M(F.threadId,te),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:c.jsx(ie.Trash2,{size:12})})]})]}),i===F.threadId&&c.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},F.threadId))})})]})}function zr(e){if(!(typeof globalThis>"u"))return globalThis[e]}function IC(e){if(typeof e!="string")return;const t=e.trim();if(t)return jn(t)}function up(){const e=[zr("__API_BASE_URL__"),zr("__CHAT_API_BASE_URL__"),zr("__CHAT_API_URL__")];for(const t of e){const n=IC(t);if(n)return n}}function dp(){const e=[zr("__API_AUTH_TOKEN__"),zr("__CHAT_API_KEY__"),zr("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function fp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return jn(t);return jn()}function hp(){const e={},t=up(),n=dp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function pp(){const e=hp(),t=Fn.getAuthToken(),n=up();return{apiBaseUrl:fp(e.baseUrl,Fn.baseUrl,n),apiKey:t||e.apiKey||dp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,truncateToolMessages:!0,toolMessagePreviewLength:200,darkMode:!1,enableSound:!1,messageHistory:100}}const mp="chat-settings";function NC(){try{const e=localStorage.getItem(mp);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function AC(e){try{const t={...e,apiBaseUrl:jn(e.apiBaseUrl)};localStorage.setItem(mp,JSON.stringify(t)),t.apiKey&&Fn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function _C(){const e=pp(),t=NC(),n=Fn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:fp(Fn.baseUrl,r,e.apiBaseUrl)}}function jC(e){Fn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),AC(e)}var RC="Label",gp=m.forwardRef((e,t)=>c.jsx(Ae.label,{...e,ref:t,onMouseDown:n=>{var o;n.target.closest("button, input, select, textarea")||((o=e.onMouseDown)==null||o.call(e,n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));gp.displayName=RC;var xp=gp;const PC=jo.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),tn=m.forwardRef(({className:e,...t},n)=>c.jsx(xp,{ref:n,className:ee(PC(),e),...t}));tn.displayName=xp.displayName;function yp(e){const t=m.useRef({value:e,previous:e});return m.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var si="Switch",[OC,ak]=wn(si),[MC,DC]=OC(si),vp=m.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:u,form:d,...f}=e,[h,p]=m.useState(null),v=Ue(t,S=>p(S)),x=m.useRef(!1),g=h?d||!!h.closest("form"):!0,[y,b]=ur({prop:o,defaultProp:s??!1,onChange:u,caller:si});return c.jsxs(MC,{scope:n,checked:y,disabled:a,children:[c.jsx(Ae.button,{type:"button",role:"switch","aria-checked":y,"aria-required":i,"data-state":Cp(y),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:v,onClick:ue(e.onClick,S=>{b(I=>!I),g&&(x.current=S.isPropagationStopped(),x.current||S.stopPropagation())})}),g&&c.jsx(Sp,{control:h,bubbles:!x.current,name:r,value:l,checked:y,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});vp.displayName=si;var bp="SwitchThumb",wp=m.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=DC(bp,n);return c.jsx(Ae.span,{"data-state":Cp(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});wp.displayName=bp;var LC="SwitchBubbleInput",Sp=m.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=m.useRef(null),a=Ue(i,s),l=yp(n),u=Pf(t);return m.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&p){const v=new Event("click",{bubbles:r});p.call(d,n),d.dispatchEvent(v)}},[l,n,r]),c.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...u,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});Sp.displayName=LC;function Cp(e){return e?"checked":"unchecked"}var Tp=vp,$C=wp;const Yn=m.forwardRef(({className:e,...t},n)=>c.jsx(Tp,{className:ee("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:n,children:c.jsx($C,{className:ee("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));Yn.displayName=Tp.displayName;var kp=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),FC="VisuallyHidden",zC=m.forwardRef((e,t)=>c.jsx(Ae.span,{...e,ref:t,style:{...kp,...e.style}}));zC.displayName=FC;var BC=[" ","Enter","ArrowUp","ArrowDown"],HC=[" ","Enter"],yr="Select",[ii,ai,UC]=Oa(yr),[Br,lk]=wn(yr,[UC,qs]),li=qs(),[WC,Xn]=Br(yr),[VC,KC]=Br(yr),Ep=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:u,name:d,autoComplete:f,disabled:h,required:p,form:v}=e,x=li(t),[g,y]=m.useState(null),[b,S]=m.useState(null),[I,C]=m.useState(!1),T=Ds(u),[E,A]=ur({prop:r,defaultProp:o??!1,onChange:s,caller:yr}),[j,P]=ur({prop:i,defaultProp:a,onChange:l,caller:yr}),D=m.useRef(null),L=g?v||!!g.closest("form"):!0,[V,M]=m.useState(new Set),Y=Array.from(V).map(K=>K.props.value).join(";");return c.jsx(Uf,{...x,children:c.jsxs(WC,{required:p,scope:t,trigger:g,onTriggerChange:y,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:I,onValueNodeHasChildrenChange:C,contentId:Sn(),value:j,onValueChange:P,open:E,onOpenChange:A,dir:T,triggerPointerDownPosRef:D,disabled:h,children:[c.jsx(ii.Provider,{scope:t,children:c.jsx(VC,{scope:e.__scopeSelect,onNativeOptionAdd:m.useCallback(K=>{M(q=>new Set(q).add(K))},[]),onNativeOptionRemove:m.useCallback(K=>{M(q=>{const z=new Set(q);return z.delete(K),z})},[]),children:n})}),L?c.jsxs(Xp,{"aria-hidden":!0,required:p,tabIndex:-1,name:d,autoComplete:f,value:j,onChange:K=>P(K.target.value),disabled:h,form:v,children:[j===void 0?c.jsx("option",{value:""}):null,Array.from(V)]},Y):null]})})};Ep.displayName=yr;var Ip="SelectTrigger",Np=m.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=li(n),i=Xn(Ip,n),a=i.disabled||r,l=Ue(t,i.onTriggerChange),u=ai(n),d=m.useRef("touch"),[f,h,p]=Zp(x=>{const g=u().filter(S=>!S.disabled),y=g.find(S=>S.value===i.value),b=Qp(g,x,y);b!==void 0&&i.onValueChange(b.value)}),v=x=>{a||(i.onOpenChange(!0),p()),x&&(i.triggerPointerDownPosRef.current={x:Math.round(x.pageX),y:Math.round(x.pageY)})};return c.jsx(Wf,{asChild:!0,...s,children:c.jsx(Ae.button,{type:"button",role:"combobox","aria-controls":i.contentId,"aria-expanded":i.open,"aria-required":i.required,"aria-autocomplete":"none",dir:i.dir,"data-state":i.open?"open":"closed",disabled:a,"data-disabled":a?"":void 0,"data-placeholder":Jp(i.value)?"":void 0,...o,ref:l,onClick:ue(o.onClick,x=>{x.currentTarget.focus(),d.current!=="mouse"&&v(x)}),onPointerDown:ue(o.onPointerDown,x=>{d.current=x.pointerType;const g=x.target;g.hasPointerCapture(x.pointerId)&&g.releasePointerCapture(x.pointerId),x.button===0&&x.ctrlKey===!1&&x.pointerType==="mouse"&&(v(x),x.preventDefault())}),onKeyDown:ue(o.onKeyDown,x=>{const g=f.current!=="";!(x.ctrlKey||x.altKey||x.metaKey)&&x.key.length===1&&h(x.key),!(g&&x.key===" ")&&BC.includes(x.key)&&(v(),x.preventDefault())})})})});Np.displayName=Ip;var Ap="SelectValue",_p=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Xn(Ap,n),{onValueNodeHasChildrenChange:u}=l,d=s!==void 0,f=Ue(t,l.onValueNodeChange);return wt(()=>{u(d)},[u,d]),c.jsx(Ae.span,{...a,ref:f,style:{pointerEvents:"none"},children:Jp(l.value)?c.jsx(c.Fragment,{children:i}):s})});_p.displayName=Ap;var qC="SelectIcon",jp=m.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return c.jsx(Ae.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});jp.displayName=qC;var GC="SelectPortal",Rp=e=>c.jsx(bs,{asChild:!0,...e});Rp.displayName=GC;var vr="SelectContent",Pp=m.forwardRef((e,t)=>{const n=Xn(vr,e.__scopeSelect),[r,o]=m.useState();if(wt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?Ro.createPortal(c.jsx(Op,{scope:e.__scopeSelect,children:c.jsx(ii.Slot,{scope:e.__scopeSelect,children:c.jsx("div",{children:e.children})})}),s):null}return c.jsx(Mp,{...e,ref:t})});Pp.displayName=vr;var fn=10,[Op,Jn]=Br(vr),YC="SelectContentImpl",XC=nr.createSlot("SelectContent.RemoveScroll"),Mp=m.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:v,hideWhenDetached:x,avoidCollisions:g,...y}=e,b=Xn(vr,n),[S,I]=m.useState(null),[C,T]=m.useState(null),E=Ue(t,G=>I(G)),[A,j]=m.useState(null),[P,D]=m.useState(null),L=ai(n),[V,M]=m.useState(!1),Y=m.useRef(!1);m.useEffect(()=>{if(S)return Na(S)},[S]),Sa();const K=m.useCallback(G=>{const[O,...Z]=L().map(ae=>ae.ref.current),[ne]=Z.slice(-1),de=document.activeElement;for(const ae of G)if(ae===de||(ae==null||ae.scrollIntoView({block:"nearest"}),ae===O&&C&&(C.scrollTop=0),ae===ne&&C&&(C.scrollTop=C.scrollHeight),ae==null||ae.focus(),document.activeElement!==de))return},[L,C]),q=m.useCallback(()=>K([A,S]),[K,A,S]);m.useEffect(()=>{V&&q()},[V,q]);const{onOpenChange:z,triggerPointerDownPosRef:$}=b;m.useEffect(()=>{if(S){let G={x:0,y:0};const O=ne=>{var de,ae;G={x:Math.abs(Math.round(ne.pageX)-(((de=$.current)==null?void 0:de.x)??0)),y:Math.abs(Math.round(ne.pageY)-(((ae=$.current)==null?void 0:ae.y)??0))}},Z=ne=>{G.x<=10&&G.y<=10?ne.preventDefault():S.contains(ne.target)||z(!1),document.removeEventListener("pointermove",O),$.current=null};return $.current!==null&&(document.addEventListener("pointermove",O),document.addEventListener("pointerup",Z,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",O),document.removeEventListener("pointerup",Z,{capture:!0})}}},[S,z,$]),m.useEffect(()=>{const G=()=>z(!1);return window.addEventListener("blur",G),window.addEventListener("resize",G),()=>{window.removeEventListener("blur",G),window.removeEventListener("resize",G)}},[z]);const[pe,F]=Zp(G=>{const O=L().filter(de=>!de.disabled),Z=O.find(de=>de.ref.current===document.activeElement),ne=Qp(O,G,Z);ne&&setTimeout(()=>ne.ref.current.focus())}),te=m.useCallback((G,O,Z)=>{const ne=!Y.current&&!Z;(b.value!==void 0&&b.value===O||ne)&&(j(G),ne&&(Y.current=!0))},[b.value]),fe=m.useCallback(()=>S==null?void 0:S.focus(),[S]),me=m.useCallback((G,O,Z)=>{const ne=!Y.current&&!Z;(b.value!==void 0&&b.value===O||ne)&&D(G)},[b.value]),be=r==="popper"?dl:Dp,Te=be===dl?{side:a,sideOffset:l,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:v,hideWhenDetached:x,avoidCollisions:g}:{};return c.jsx(Op,{scope:n,content:S,viewport:C,onViewportChange:T,itemRefCallback:te,selectedItem:A,onItemLeave:fe,itemTextRefCallback:me,focusSelectedItem:q,selectedItemText:P,position:r,isPositioned:V,searchRef:pe,children:c.jsx(Es,{as:XC,allowPinchZoom:!0,children:c.jsx(vs,{asChild:!0,trapped:b.open,onMountAutoFocus:G=>{G.preventDefault()},onUnmountAutoFocus:ue(o,G=>{var O;(O=b.trigger)==null||O.focus({preventScroll:!0}),G.preventDefault()}),children:c.jsx(ys,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:G=>G.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:c.jsx(be,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:G=>G.preventDefault(),...y,...Te,onPlaced:()=>M(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...y.style},onKeyDown:ue(y.onKeyDown,G=>{const O=G.ctrlKey||G.altKey||G.metaKey;if(G.key==="Tab"&&G.preventDefault(),!O&&G.key.length===1&&F(G.key),["ArrowUp","ArrowDown","Home","End"].includes(G.key)){let ne=L().filter(de=>!de.disabled).map(de=>de.ref.current);if(["ArrowUp","End"].includes(G.key)&&(ne=ne.slice().reverse()),["ArrowUp","ArrowDown"].includes(G.key)){const de=G.target,ae=ne.indexOf(de);ne=ne.slice(ae+1)}setTimeout(()=>K(ne)),G.preventDefault()}})})})})})})});Mp.displayName=YC;var JC="SelectItemAlignedPosition",Dp=m.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Xn(vr,n),i=Jn(vr,n),[a,l]=m.useState(null),[u,d]=m.useState(null),f=Ue(t,E=>d(E)),h=ai(n),p=m.useRef(!1),v=m.useRef(!0),{viewport:x,selectedItem:g,selectedItemText:y,focusSelectedItem:b}=i,S=m.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&u&&x&&g&&y){const E=s.trigger.getBoundingClientRect(),A=u.getBoundingClientRect(),j=s.valueNode.getBoundingClientRect(),P=y.getBoundingClientRect();if(s.dir!=="rtl"){const de=P.left-A.left,ae=j.left-de,We=E.left-ae,Ze=E.width+We,ve=Math.max(Ze,A.width),Oe=window.innerWidth-fn,Le=sl(ae,[fn,Math.max(fn,Oe-ve)]);a.style.minWidth=Ze+"px",a.style.left=Le+"px"}else{const de=A.right-P.right,ae=window.innerWidth-j.right-de,We=window.innerWidth-E.right-ae,Ze=E.width+We,ve=Math.max(Ze,A.width),Oe=window.innerWidth-fn,Le=sl(ae,[fn,Math.max(fn,Oe-ve)]);a.style.minWidth=Ze+"px",a.style.right=Le+"px"}const D=h(),L=window.innerHeight-fn*2,V=x.scrollHeight,M=window.getComputedStyle(u),Y=parseInt(M.borderTopWidth,10),K=parseInt(M.paddingTop,10),q=parseInt(M.borderBottomWidth,10),z=parseInt(M.paddingBottom,10),$=Y+K+V+z+q,pe=Math.min(g.offsetHeight*5,$),F=window.getComputedStyle(x),te=parseInt(F.paddingTop,10),fe=parseInt(F.paddingBottom,10),me=E.top+E.height/2-fn,be=L-me,Te=g.offsetHeight/2,G=g.offsetTop+Te,O=Y+K+G,Z=$-O;if(O<=me){const de=D.length>0&&g===D[D.length-1].ref.current;a.style.bottom="0px";const ae=u.clientHeight-x.offsetTop-x.offsetHeight,We=Math.max(be,Te+(de?fe:0)+ae+q),Ze=O+We;a.style.height=Ze+"px"}else{const de=D.length>0&&g===D[0].ref.current;a.style.top="0px";const We=Math.max(me,Y+x.offsetTop+(de?te:0)+Te)+Z;a.style.height=We+"px",x.scrollTop=O-me+x.offsetTop}a.style.margin=`${fn}px 0`,a.style.minHeight=pe+"px",a.style.maxHeight=L+"px",r==null||r(),requestAnimationFrame(()=>p.current=!0)}},[h,s.trigger,s.valueNode,a,u,x,g,y,s.dir,r]);wt(()=>S(),[S]);const[I,C]=m.useState();wt(()=>{u&&C(window.getComputedStyle(u).zIndex)},[u]);const T=m.useCallback(E=>{E&&v.current===!0&&(S(),b==null||b(),v.current=!1)},[S,b]);return c.jsx(QC,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:p,onScrollButtonChange:T,children:c.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:I},children:c.jsx(Ae.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Dp.displayName=JC;var ZC="SelectPopperPosition",dl=m.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=fn,...s}=e,i=li(n);return c.jsx(Vf,{...i,...s,ref:t,align:r,collisionPadding:o,style:{boxSizing:"border-box",...s.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});dl.displayName=ZC;var[QC,fl]=Br(vr,{}),hl="SelectViewport",Lp=m.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Jn(hl,n),i=fl(hl,n),a=Ue(t,s.onViewportChange),l=m.useRef(0);return c.jsxs(c.Fragment,{children:[c.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),c.jsx(ii.Slot,{scope:n,children:c.jsx(Ae.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:ue(o.onScroll,u=>{const d=u.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:h}=i;if(h!=null&&h.current&&f){const p=Math.abs(l.current-d.scrollTop);if(p>0){const v=window.innerHeight-fn*2,x=parseFloat(f.style.minHeight),g=parseFloat(f.style.height),y=Math.max(x,g);if(y<v){const b=y+p,S=Math.min(v,b),I=b-S;f.style.height=S+"px",f.style.bottom==="0px"&&(d.scrollTop=I>0?I:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});Lp.displayName=hl;var $p="SelectGroup",[eT,tT]=Br($p),nT=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Sn();return c.jsx(eT,{scope:n,id:o,children:c.jsx(Ae.div,{role:"group","aria-labelledby":o,...r,ref:t})})});nT.displayName=$p;var Fp="SelectLabel",zp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=tT(Fp,n);return c.jsx(Ae.div,{id:o.id,...r,ref:t})});zp.displayName=Fp;var ci="SelectItem",[rT,Bp]=Br(ci),Hp=m.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Xn(ci,n),l=Jn(ci,n),u=a.value===r,[d,f]=m.useState(s??""),[h,p]=m.useState(!1),v=Ue(t,b=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,b,r,o)}),x=Sn(),g=m.useRef("touch"),y=()=>{o||(a.onValueChange(r),a.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return c.jsx(rT,{scope:n,value:r,disabled:o,textId:x,isSelected:u,onItemTextChange:m.useCallback(b=>{f(S=>S||((b==null?void 0:b.textContent)??"").trim())},[]),children:c.jsx(ii.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:c.jsx(Ae.div,{role:"option","aria-labelledby":x,"data-highlighted":h?"":void 0,"aria-selected":u&&h,"data-state":u?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:v,onFocus:ue(i.onFocus,()=>p(!0)),onBlur:ue(i.onBlur,()=>p(!1)),onClick:ue(i.onClick,()=>{g.current!=="mouse"&&y()}),onPointerUp:ue(i.onPointerUp,()=>{g.current==="mouse"&&y()}),onPointerDown:ue(i.onPointerDown,b=>{g.current=b.pointerType}),onPointerMove:ue(i.onPointerMove,b=>{var S;g.current=b.pointerType,o?(S=l.onItemLeave)==null||S.call(l):g.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:ue(i.onPointerLeave,b=>{var S;b.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:ue(i.onKeyDown,b=>{var I;((I=l.searchRef)==null?void 0:I.current)!==""&&b.key===" "||(HC.includes(b.key)&&y(),b.key===" "&&b.preventDefault())})})})})});Hp.displayName=ci;var Io="SelectItemText",Up=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Xn(Io,n),a=Jn(Io,n),l=Bp(Io,n),u=KC(Io,n),[d,f]=m.useState(null),h=Ue(t,y=>f(y),l.onItemTextChange,y=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,y,l.value,l.disabled)}),p=d==null?void 0:d.textContent,v=m.useMemo(()=>c.jsx("option",{value:l.value,disabled:l.disabled,children:p},l.value),[l.disabled,l.value,p]),{onNativeOptionAdd:x,onNativeOptionRemove:g}=u;return wt(()=>(x(v),()=>g(v)),[x,g,v]),c.jsxs(c.Fragment,{children:[c.jsx(Ae.span,{id:l.textId,...s,ref:h}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?Ro.createPortal(s.children,i.valueNode):null]})});Up.displayName=Io;var Wp="SelectItemIndicator",Vp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return Bp(Wp,n).isSelected?c.jsx(Ae.span,{"aria-hidden":!0,...r,ref:t}):null});Vp.displayName=Wp;var pl="SelectScrollUpButton",Kp=m.forwardRef((e,t)=>{const n=Jn(pl,e.__scopeSelect),r=fl(pl,e.__scopeSelect),[o,s]=m.useState(!1),i=Ue(t,r.onScrollButtonChange);return wt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const u=l.scrollTop>0;s(u)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?c.jsx(Gp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});Kp.displayName=pl;var ml="SelectScrollDownButton",qp=m.forwardRef((e,t)=>{const n=Jn(ml,e.__scopeSelect),r=fl(ml,e.__scopeSelect),[o,s]=m.useState(!1),i=Ue(t,r.onScrollButtonChange);return wt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const u=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<u;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?c.jsx(Gp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});qp.displayName=ml;var Gp=m.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Jn("SelectScrollButton",n),i=m.useRef(null),a=ai(n),l=m.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return m.useEffect(()=>()=>l(),[l]),wt(()=>{var d;const u=a().find(f=>f.ref.current===document.activeElement);(d=u==null?void 0:u.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),c.jsx(Ae.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:ue(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:ue(o.onPointerMove,()=>{var u;(u=s.onItemLeave)==null||u.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:ue(o.onPointerLeave,()=>{l()})})}),oT="SelectSeparator",Yp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return c.jsx(Ae.div,{"aria-hidden":!0,...r,ref:t})});Yp.displayName=oT;var gl="SelectArrow",sT=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=li(n),s=Xn(gl,n),i=Jn(gl,n);return s.open&&i.position==="popper"?c.jsx(Kf,{...o,...r,ref:t}):null});sT.displayName=gl;var iT="SelectBubbleInput",Xp=m.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=m.useRef(null),s=Ue(r,o),i=yp(t);return m.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),c.jsx(Ae.select,{...n,style:{...kp,...n.style},ref:s,defaultValue:t})});Xp.displayName=iT;function Jp(e){return e===""||e===void 0}function Zp(e){const t=Et(e),n=m.useRef(""),r=m.useRef(0),o=m.useCallback(i=>{const a=n.current+i;t(a),function l(u){n.current=u,window.clearTimeout(r.current),u!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(a)},[t]),s=m.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function Qp(e,t,n){const o=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=aT(e,Math.max(s,0));o.length===1&&(i=i.filter(u=>u!==n));const l=i.find(u=>u.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function aT(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var lT=Ep,em=Np,cT=_p,uT=jp,dT=Rp,tm=Pp,fT=Lp,nm=zp,rm=Hp,hT=Up,pT=Vp,om=Kp,sm=qp,im=Yp;const am=lT,lm=cT,xl=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(em,{ref:r,className:ee("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",e),...n,children:[t,c.jsx(uT,{asChild:!0,children:c.jsx(ie.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));xl.displayName=em.displayName;const cm=m.forwardRef(({className:e,...t},n)=>c.jsx(om,{ref:n,className:ee("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(ie.ChevronUp,{className:"h-4 w-4"})}));cm.displayName=om.displayName;const um=m.forwardRef(({className:e,...t},n)=>c.jsx(sm,{ref:n,className:ee("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(ie.ChevronDown,{className:"h-4 w-4"})}));um.displayName=sm.displayName;const yl=m.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>c.jsx(dT,{children:c.jsxs(tm,{ref:o,className:ee("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[c.jsx(cm,{}),c.jsx(fT,{className:ee("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),c.jsx(um,{})]})}));yl.displayName=tm.displayName;const mT=m.forwardRef(({className:e,...t},n)=>c.jsx(nm,{ref:n,className:ee("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));mT.displayName=nm.displayName;const br=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(rm,{ref:r,className:ee("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(pT,{children:c.jsx(ie.Check,{className:"h-4 w-4"})})}),c.jsx(hT,{children:t})]}));br.displayName=rm.displayName;const gT=m.forwardRef(({className:e,...t},n)=>c.jsx(im,{ref:n,className:ee("-mx-1 my-1 h-px bg-muted",e),...t}));gT.displayName=im.displayName;var xT="Separator",dm="horizontal",yT=["horizontal","vertical"],fm=m.forwardRef((e,t)=>{const{decorative:n,orientation:r=dm,...o}=e,s=vT(r)?r:dm,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return c.jsx(Ae.div,{"data-orientation":s,...a,...o,ref:t})});fm.displayName=xT;function vT(e){return yT.includes(e)}var hm=fm;const pm=m.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>c.jsx(hm,{ref:o,decorative:n,orientation:t,className:ee("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));pm.displayName=hm.displayName;const bT=Xd,wT=ew,ST=Jd,mm=m.forwardRef(({className:e,...t},n)=>c.jsx(js,{className:ee("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t,ref:n}));mm.displayName=js.displayName;const CT=jo.cva("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm"}},defaultVariants:{side:"right"}}),gm=m.forwardRef(({side:e="right",className:t,children:n,...r},o)=>c.jsxs(ST,{children:[c.jsx(mm,{}),c.jsxs(Rs,{ref:o,className:ee(CT({side:e}),t),...r,children:[n,c.jsxs(Zd,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[c.jsx(ie.X,{className:"h-4 w-4"}),c.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));gm.displayName=Rs.displayName;const xm=({className:e,...t})=>c.jsx("div",{className:ee("flex flex-col space-y-2 text-center sm:text-left",e),...t});xm.displayName="SheetHeader";const ym=m.forwardRef(({className:e,...t},n)=>c.jsx(hr,{ref:n,className:ee("text-lg font-semibold text-foreground",e),...t}));ym.displayName=hr.displayName;const vm=m.forwardRef(({className:e,...t},n)=>c.jsx(Ps,{ref:n,className:ee("text-sm text-muted-foreground",e),...t}));vm.displayName=Ps.displayName;const TT={api:{baseUrl:"http://localhost:8000/api",authToken:"",enableAuth:!1},ui:{layout:"sidebar",theme:"light",showTimestamps:!0,showAgentNames:!0,compactMessages:!1},behavior:{autoSave:!0,enableStreaming:!0,showTypingIndicator:!0}};function kT({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=w.useState(!1),[s,i]=w.useState(!1),[a,l]=w.useState(e),[u,d]=w.useState(!1),{toast:f}=xa();w.useEffect(()=>{const g=JSON.stringify(a)!==JSON.stringify(e);d(g)},[a,e]),w.useEffect(()=>{l(e)},[e]);const h=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},p=()=>{l(TT),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},v=()=>{l(e),d(!1),o(!1)},x=async()=>{try{const y=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${y.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return c.jsxs(bT,{open:r,onOpenChange:o,children:[c.jsx(wT,{asChild:!0,children:c.jsxs(Ge,{variant:"outline",size:"sm",className:n,children:[c.jsx(ie.Settings,{className:"h-4 w-4 mr-2"}),"Settings",u&&c.jsx(aa,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),c.jsxs(gm,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[c.jsxs(xm,{children:[c.jsx(ym,{children:"Chat Settings"}),c.jsx(vm,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),c.jsxs("div",{className:"space-y-6 py-6",children:[c.jsxs(ho,{children:[c.jsx(po,{className:"pb-3",children:c.jsxs(mo,{className:"text-lg flex items-center gap-2",children:[c.jsx(ie.Server,{className:"h-5 w-5"}),"API Configuration"]})}),c.jsxs(ds,{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(tn,{htmlFor:"api-url",children:"API Base URL"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(ei,{id:"api-url",value:a.api.baseUrl,onChange:g=>l(y=>({...y,api:{...y.api,baseUrl:g.target.value}})),placeholder:"http://localhost:8000/api"}),c.jsx(Ge,{variant:"outline",onClick:x,children:"Test"})]})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(tn,{htmlFor:"enable-auth",children:"Enable Authentication"}),c.jsx(Yn,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:g=>l(y=>({...y,api:{...y.api,enableAuth:g}}))})]}),a.api.enableAuth&&c.jsxs("div",{className:"space-y-2",children:[c.jsx(tn,{htmlFor:"auth-token",children:"Authentication Token"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(ei,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:g=>l(y=>({...y,api:{...y.api,authToken:g.target.value}})),placeholder:"Enter your Bearer token"}),c.jsx(Ge,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?c.jsx(ie.EyeOff,{className:"h-4 w-4"}):c.jsx(ie.Eye,{className:"h-4 w-4"})})]})]})]})]}),c.jsxs(ho,{children:[c.jsx(po,{className:"pb-3",children:c.jsxs(mo,{className:"text-lg flex items-center gap-2",children:[c.jsx(ie.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),c.jsxs(ds,{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(tn,{htmlFor:"layout",children:"Layout Style"}),c.jsxs(am,{value:a.ui.layout,onValueChange:g=>l(y=>({...y,ui:{...y.ui,layout:g}})),children:[c.jsx(xl,{children:c.jsx(lm,{})}),c.jsxs(yl,{children:[c.jsx(br,{value:"sidebar",children:"Sidebar Layout"}),c.jsx(br,{value:"fullscreen",children:"Fullscreen"}),c.jsx(br,{value:"tabs",children:"Tabbed Interface"})]})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(tn,{htmlFor:"theme",children:"Theme"}),c.jsxs(am,{value:a.ui.theme,onValueChange:g=>l(y=>({...y,ui:{...y.ui,theme:g}})),children:[c.jsx(xl,{children:c.jsx(lm,{})}),c.jsxs(yl,{children:[c.jsx(br,{value:"light",children:"Light"}),c.jsx(br,{value:"dark",children:"Dark"}),c.jsx(br,{value:"system",children:"System"})]})]})]}),c.jsx(pm,{}),c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(tn,{htmlFor:"show-timestamps",children:"Show Timestamps"}),c.jsx(Yn,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:g=>l(y=>({...y,ui:{...y.ui,showTimestamps:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(tn,{htmlFor:"show-agent-names",children:"Show Agent Names"}),c.jsx(Yn,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:g=>l(y=>({...y,ui:{...y.ui,showAgentNames:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(tn,{htmlFor:"compact-messages",children:"Compact Messages"}),c.jsx(Yn,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:g=>l(y=>({...y,ui:{...y.ui,compactMessages:g}}))})]})]})]})]}),c.jsxs(ho,{children:[c.jsx(po,{className:"pb-3",children:c.jsxs(mo,{className:"text-lg flex items-center gap-2",children:[c.jsx(ie.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),c.jsxs(ds,{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(tn,{htmlFor:"auto-save",children:"Auto-save Conversations"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),c.jsx(Yn,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:g=>l(y=>({...y,behavior:{...y.behavior,autoSave:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(tn,{htmlFor:"enable-streaming",children:"Enable Streaming"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),c.jsx(Yn,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:g=>l(y=>({...y,behavior:{...y.behavior,enableStreaming:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(tn,{htmlFor:"typing-indicator",children:"Typing Indicator"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),c.jsx(Yn,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:g=>l(y=>({...y,behavior:{...y.behavior,showTypingIndicator:g}}))})]})]})]})]}),c.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[c.jsxs(Ge,{variant:"outline",onClick:p,children:[c.jsx(ie.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Ge,{variant:"outline",onClick:v,children:"Cancel"}),c.jsxs(Ge,{onClick:h,disabled:!u,children:[c.jsx(ie.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function ET({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=u=>{const d="h-full";switch(u){case"phone":return`${d} max-w-none`;case"tablet":return`${d} max-w-4xl mx-auto`;case"half-screen":return`${d} max-w-2xl`;case"desktop":default:return`${d} max-w-7xl mx-auto`}},a=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=w.useCallback(u=>{var d;(d=s.onThreadChange)==null||d.call(s,u)},[s]);return e==="fullscreen"?c.jsx(Yo,{...s,onThreadChange:l,children:c.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:c.jsx(Qs,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?c.jsx(Yo,{...s,onThreadChange:l,children:c.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:c.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&c.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:c.jsx(ul,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),c.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:c.jsx(Qs,{onError:s.onError,enableFileUpload:!0})})]})})}):c.jsx(Yo,{...s,onThreadChange:l,children:c.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&c.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:c.jsx(ul,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),c.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:c.jsx(Qs,{onError:s.onError,enableFileUpload:!0})})]})})}je.ChatApi=mc,je.ChatInterface=Qs,je.ChatProviders=Yo,je.ChatSettings=kT,je.MarkdownContent=pa,je.MessageComponent=lf,je.MessageList=Pa,je.ThreadManager=ul,je.applySettings=jC,je.chatApiClient=Fn,je.default=ET,je.del=pc,je.get=gn,je.getChatToken=dc,je.getCurrentSettings=_C,je.getDefaultApiConfig=hp,je.getDefaultChatSettings=pp,je.onChatTokenChanged=fc,je.post=Ei,je.put=hc,je.setChatToken=ki,je.useApi=Ii,je.useChatStream=Rc,je.useMessagesReducer=Cc,je.useStream=zc,je.useThreadState=Go,je.useThreads=qo,Object.defineProperties(je,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
139
|
+
`).trim():n.replace(/</g,"<").replace(/>/g,">").trim()}function yw(e,t=Rs){if(!e||typeof e!="string")throw new Error("Invalid content: must be a non-empty string");if(e.length>t)throw new Error(`Message exceeds maximum length of ${t} characters`);return e}function vw(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),yw(t),xw(t)}function Ra(e){const t=e+"CollectionProvider",[n,r]=yn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=x=>{const{scope:g,children:y}=x,b=w.useRef(null),S=w.useRef(new Map).current;return c.jsx(o,{scope:g,itemMap:S,collectionRef:b,children:y})};i.displayName=t;const a=e+"CollectionSlot",l=tr.createSlot(a),u=w.forwardRef((x,g)=>{const{scope:y,children:b}=x,S=s(a,y),I=He(g,S.collectionRef);return c.jsx(l,{ref:I,children:b})});u.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=tr.createSlot(d),p=w.forwardRef((x,g)=>{const{scope:y,children:b,...S}=x,I=w.useRef(null),C=He(g,I),T=s(d,y);return w.useEffect(()=>(T.itemMap.set(I,{ref:I,...S}),()=>void T.itemMap.delete(I))),c.jsx(h,{[f]:"",ref:C,children:b})});p.displayName=d;function v(x){const g=s(e+"CollectionConsumer",x);return w.useCallback(()=>{const b=g.collectionRef.current;if(!b)return[];const S=Array.from(b.querySelectorAll(`[${f}]`));return Array.from(g.itemMap.values()).sort((T,E)=>S.indexOf(T.ref.current)-S.indexOf(E.ref.current))},[g.collectionRef,g.itemMap])}return[{Provider:i,Slot:u,ItemSlot:p},v,r]}var bw=m.createContext(void 0);function Ps(e){const t=m.useContext(bw);return e||t||"ltr"}const ww=["top","right","bottom","left"],Kn=Math.min,Vt=Math.max,Os=Math.round,Ms=Math.floor,wn=e=>({x:e,y:e}),Sw={left:"right",right:"left",bottom:"top",top:"bottom"},Cw={start:"end",end:"start"};function Pa(e,t,n){return Vt(e,Kn(t,n))}function Pn(e,t){return typeof e=="function"?e(t):e}function On(e){return e.split("-")[0]}function Pr(e){return e.split("-")[1]}function Oa(e){return e==="x"?"y":"x"}function Ma(e){return e==="y"?"height":"width"}const Tw=new Set(["top","bottom"]);function Sn(e){return Tw.has(On(e))?"y":"x"}function Da(e){return Oa(Sn(e))}function kw(e,t,n){n===void 0&&(n=!1);const r=Pr(e),o=Da(e),s=Ma(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Ds(i)),[i,Ds(i)]}function Ew(e){const t=Ds(e);return[La(e),t,La(t)]}function La(e){return e.replace(/start|end/g,t=>Cw[t])}const uf=["left","right"],df=["right","left"],Iw=["top","bottom"],Nw=["bottom","top"];function Aw(e,t,n){switch(e){case"top":case"bottom":return n?t?df:uf:t?uf:df;case"left":case"right":return t?Iw:Nw;default:return[]}}function _w(e,t,n,r){const o=Pr(e);let s=Aw(On(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(La)))),s}function Ds(e){return e.replace(/left|right|bottom|top/g,t=>Sw[t])}function jw(e){return{top:0,right:0,bottom:0,left:0,...e}}function ff(e){return typeof e!="number"?jw(e):{top:e,right:e,bottom:e,left:e}}function Ls(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 hf(e,t,n){let{reference:r,floating:o}=e;const s=Sn(t),i=Da(t),a=Ma(i),l=On(t),u=s==="y",d=r.x+r.width/2-o.width/2,f=r.y+r.height/2-o.height/2,h=r[a]/2-o[a]/2;let p;switch(l){case"top":p={x:d,y:r.y-o.height};break;case"bottom":p={x:d,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(Pr(t)){case"start":p[i]-=h*(n&&u?-1:1);break;case"end":p[i]+=h*(n&&u?-1:1);break}return p}const Rw=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let u=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:d,y:f}=hf(u,r,l),h=r,p={},v=0;for(let x=0;x<a.length;x++){const{name:g,fn:y}=a[x],{x:b,y:S,data:I,reset:C}=await y({x:d,y:f,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:u,platform:i,elements:{reference:e,floating:t}});d=b??d,f=S??f,p={...p,[g]:{...p[g],...I}},C&&v<=50&&(v++,typeof C=="object"&&(C.placement&&(h=C.placement),C.rects&&(u=C.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):C.rects),{x:d,y:f}=hf(u,h,l)),x=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:p}};async function ho(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:u="clippingAncestors",rootBoundary:d="viewport",elementContext:f="floating",altBoundary:h=!1,padding:p=0}=Pn(t,e),v=ff(p),g=a[h?f==="floating"?"reference":"floating":f],y=Ls(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(g)))==null||n?g:g.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:u,rootBoundary:d,strategy:l})),b=f==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,S=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),I=await(s.isElement==null?void 0:s.isElement(S))?await(s.getScale==null?void 0:s.getScale(S))||{x:1,y:1}:{x:1,y:1},C=Ls(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:S,strategy:l}):b);return{top:(y.top-C.top+v.top)/I.y,bottom:(C.bottom-y.bottom+v.bottom)/I.y,left:(y.left-C.left+v.left)/I.x,right:(C.right-y.right+v.right)/I.x}}const Pw=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:u,padding:d=0}=Pn(e,t)||{};if(u==null)return{};const f=ff(d),h={x:n,y:r},p=Da(o),v=Ma(p),x=await i.getDimensions(u),g=p==="y",y=g?"top":"left",b=g?"bottom":"right",S=g?"clientHeight":"clientWidth",I=s.reference[v]+s.reference[p]-h[p]-s.floating[v],C=h[p]-s.reference[p],T=await(i.getOffsetParent==null?void 0:i.getOffsetParent(u));let E=T?T[S]:0;(!E||!await(i.isElement==null?void 0:i.isElement(T)))&&(E=a.floating[S]||s.floating[v]);const A=I/2-C/2,j=E/2-x[v]/2-1,P=Kn(f[y],j),D=Kn(f[b],j),L=P,V=E-x[v]-D,M=E/2-x[v]/2+A,X=Pa(L,M,V),K=!l.arrow&&Pr(o)!=null&&M!==X&&s.reference[v]/2-(M<L?P:D)-x[v]/2<0,q=K?M<L?M-L:M-V:0;return{[p]:h[p]+q,data:{[p]:X,centerOffset:M-X-q,...K&&{alignmentOffset:q}},reset:K}}}),Ow=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:u}=t,{mainAxis:d=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:v="none",flipAlignment:x=!0,...g}=Pn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const y=On(o),b=Sn(a),S=On(a)===a,I=await(l.isRTL==null?void 0:l.isRTL(u.floating)),C=h||(S||!x?[Ds(a)]:Ew(a)),T=v!=="none";!h&&T&&C.push(..._w(a,x,v,I));const E=[a,...C],A=await ho(t,g),j=[];let P=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&j.push(A[y]),f){const M=kw(o,i,I);j.push(A[M[0]],A[M[1]])}if(P=[...P,{placement:o,overflows:j}],!j.every(M=>M<=0)){var D,L;const M=(((D=s.flip)==null?void 0:D.index)||0)+1,X=E[M];if(X&&(!(f==="alignment"?b!==Sn(X):!1)||P.every(z=>Sn(z.placement)===b?z.overflows[0]>0:!0)))return{data:{index:M,overflows:P},reset:{placement:X}};let K=(L=P.filter(q=>q.overflows[0]<=0).sort((q,z)=>q.overflows[1]-z.overflows[1])[0])==null?void 0:L.placement;if(!K)switch(p){case"bestFit":{var V;const q=(V=P.filter(z=>{if(T){const $=Sn(z.placement);return $===b||$==="y"}return!0}).map(z=>[z.placement,z.overflows.filter($=>$>0).reduce(($,pe)=>$+pe,0)]).sort((z,$)=>z[1]-$[1])[0])==null?void 0:V[0];q&&(K=q);break}case"initialPlacement":K=a;break}if(o!==K)return{reset:{placement:K}}}return{}}}};function pf(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function mf(e){return ww.some(t=>e[t]>=0)}const Mw=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=Pn(e,t);switch(r){case"referenceHidden":{const s=await ho(t,{...o,elementContext:"reference"}),i=pf(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:mf(i)}}}case"escaped":{const s=await ho(t,{...o,altBoundary:!0}),i=pf(s,n.floating);return{data:{escapedOffsets:i,escaped:mf(i)}}}default:return{}}}}},gf=new Set(["left","top"]);async function Dw(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=On(n),a=Pr(n),l=Sn(n)==="y",u=gf.has(i)?-1:1,d=s&&l?-1:1,f=Pn(t,e);let{mainAxis:h,crossAxis:p,alignmentAxis:v}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return a&&typeof v=="number"&&(p=a==="end"?v*-1:v),l?{x:p*d,y:h*u}:{x:h*u,y:p*d}}const Lw=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var n,r;const{x:o,y:s,placement:i,middlewareData:a}=t,l=await Dw(t,e);return i===((n=a.offset)==null?void 0:n.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:o+l.x,y:s+l.y,data:{...l,placement:i}}}}},$w=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:g=>{let{x:y,y:b}=g;return{x:y,y:b}}},...l}=Pn(e,t),u={x:n,y:r},d=await ho(t,l),f=Sn(On(o)),h=Oa(f);let p=u[h],v=u[f];if(s){const g=h==="y"?"top":"left",y=h==="y"?"bottom":"right",b=p+d[g],S=p-d[y];p=Pa(b,p,S)}if(i){const g=f==="y"?"top":"left",y=f==="y"?"bottom":"right",b=v+d[g],S=v-d[y];v=Pa(b,v,S)}const x=a.fn({...t,[h]:p,[f]:v});return{...x,data:{x:x.x-n,y:x.y-r,enabled:{[h]:s,[f]:i}}}}}},Fw=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:u=!0}=Pn(e,t),d={x:n,y:r},f=Sn(o),h=Oa(f);let p=d[h],v=d[f];const x=Pn(a,t),g=typeof x=="number"?{mainAxis:x,crossAxis:0}:{mainAxis:0,crossAxis:0,...x};if(l){const S=h==="y"?"height":"width",I=s.reference[h]-s.floating[S]+g.mainAxis,C=s.reference[h]+s.reference[S]-g.mainAxis;p<I?p=I:p>C&&(p=C)}if(u){var y,b;const S=h==="y"?"width":"height",I=gf.has(On(o)),C=s.reference[f]-s.floating[S]+(I&&((y=i.offset)==null?void 0:y[f])||0)+(I?0:g.crossAxis),T=s.reference[f]+s.reference[S]+(I?0:((b=i.offset)==null?void 0:b[f])||0)-(I?g.crossAxis:0);v<C?v=C:v>T&&(v=T)}return{[h]:p,[f]:v}}}},zw=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){var n,r;const{placement:o,rects:s,platform:i,elements:a}=t,{apply:l=()=>{},...u}=Pn(e,t),d=await ho(t,u),f=On(o),h=Pr(o),p=Sn(o)==="y",{width:v,height:x}=s.floating;let g,y;f==="top"||f==="bottom"?(g=f,y=h===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(y=f,g=h==="end"?"top":"bottom");const b=x-d.top-d.bottom,S=v-d.left-d.right,I=Kn(x-d[g],b),C=Kn(v-d[y],S),T=!t.middlewareData.shift;let E=I,A=C;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(A=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(E=b),T&&!h){const P=Vt(d.left,0),D=Vt(d.right,0),L=Vt(d.top,0),V=Vt(d.bottom,0);p?A=v-2*(P!==0||D!==0?P+D:Vt(d.left,d.right)):E=x-2*(L!==0||V!==0?L+V:Vt(d.top,d.bottom))}await l({...t,availableWidth:A,availableHeight:E});const j=await i.getDimensions(a.floating);return v!==j.width||x!==j.height?{reset:{rects:!0}}:{}}}};function $s(){return typeof window<"u"}function Or(e){return xf(e)?(e.nodeName||"").toLowerCase():"#document"}function Kt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function Cn(e){var t;return(t=(xf(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function xf(e){return $s()?e instanceof Node||e instanceof Kt(e).Node:!1}function ln(e){return $s()?e instanceof Element||e instanceof Kt(e).Element:!1}function Tn(e){return $s()?e instanceof HTMLElement||e instanceof Kt(e).HTMLElement:!1}function yf(e){return!$s()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Kt(e).ShadowRoot}const Bw=new Set(["inline","contents"]);function po(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=cn(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!Bw.has(o)}const Hw=new Set(["table","td","th"]);function Uw(e){return Hw.has(Or(e))}const Ww=[":popover-open",":modal"];function Fs(e){return Ww.some(t=>{try{return e.matches(t)}catch{return!1}})}const Vw=["transform","translate","scale","rotate","perspective"],Kw=["transform","translate","scale","rotate","perspective","filter"],qw=["paint","layout","strict","content"];function $a(e){const t=Fa(),n=ln(e)?cn(e):e;return Vw.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)||Kw.some(r=>(n.willChange||"").includes(r))||qw.some(r=>(n.contain||"").includes(r))}function Gw(e){let t=qn(e);for(;Tn(t)&&!Mr(t);){if($a(t))return t;if(Fs(t))return null;t=qn(t)}return null}function Fa(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const Yw=new Set(["html","body","#document"]);function Mr(e){return Yw.has(Or(e))}function cn(e){return Kt(e).getComputedStyle(e)}function zs(e){return ln(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function qn(e){if(Or(e)==="html")return e;const t=e.assignedSlot||e.parentNode||yf(e)&&e.host||Cn(e);return yf(t)?t.host:t}function vf(e){const t=qn(e);return Mr(t)?e.ownerDocument?e.ownerDocument.body:e.body:Tn(t)&&po(t)?t:vf(t)}function mo(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=vf(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Kt(o);if(s){const a=za(i);return t.concat(i,i.visualViewport||[],po(o)?o:[],a&&n?mo(a):[])}return t.concat(o,mo(o,[],n))}function za(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function bf(e){const t=cn(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=Tn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=Os(n)!==s||Os(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Ba(e){return ln(e)?e:e.contextElement}function Dr(e){const t=Ba(e);if(!Tn(t))return wn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=bf(t);let i=(s?Os(n.width):n.width)/r,a=(s?Os(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const Xw=wn(0);function wf(e){const t=Kt(e);return!Fa()||!t.visualViewport?Xw:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function Jw(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Kt(e)?!1:t}function pr(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Ba(e);let i=wn(1);t&&(r?ln(r)&&(i=Dr(r)):i=Dr(e));const a=Jw(s,n,r)?wf(s):wn(0);let l=(o.left+a.x)/i.x,u=(o.top+a.y)/i.y,d=o.width/i.x,f=o.height/i.y;if(s){const h=Kt(s),p=r&&ln(r)?Kt(r):r;let v=h,x=za(v);for(;x&&r&&p!==v;){const g=Dr(x),y=x.getBoundingClientRect(),b=cn(x),S=y.left+(x.clientLeft+parseFloat(b.paddingLeft))*g.x,I=y.top+(x.clientTop+parseFloat(b.paddingTop))*g.y;l*=g.x,u*=g.y,d*=g.x,f*=g.y,l+=S,u+=I,v=Kt(x),x=za(v)}}return Ls({width:d,height:f,x:l,y:u})}function Bs(e,t){const n=zs(e).scrollLeft;return t?t.left+n:pr(Cn(e)).left+n}function Sf(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Bs(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function Zw(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=Cn(r),a=t?Fs(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},u=wn(1);const d=wn(0),f=Tn(r);if((f||!f&&!s)&&((Or(r)!=="body"||po(i))&&(l=zs(r)),Tn(r))){const p=pr(r);u=Dr(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const h=i&&!f&&!s?Sf(i,l):wn(0);return{width:n.width*u.x,height:n.height*u.y,x:n.x*u.x-l.scrollLeft*u.x+d.x+h.x,y:n.y*u.y-l.scrollTop*u.y+d.y+h.y}}function Qw(e){return Array.from(e.getClientRects())}function e0(e){const t=Cn(e),n=zs(e),r=e.ownerDocument.body,o=Vt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Vt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Bs(e);const a=-n.scrollTop;return cn(r).direction==="rtl"&&(i+=Vt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const Cf=25;function t0(e,t){const n=Kt(e),r=Cn(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const d=Fa();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const u=Bs(r);if(u<=0){const d=r.ownerDocument,f=d.body,h=getComputedStyle(f),p=d.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,v=Math.abs(r.clientWidth-f.clientWidth-p);v<=Cf&&(s-=v)}else u<=Cf&&(s+=u);return{width:s,height:i,x:a,y:l}}const n0=new Set(["absolute","fixed"]);function r0(e,t){const n=pr(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=Tn(e)?Dr(e):wn(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,u=r*s.y;return{width:i,height:a,x:l,y:u}}function Tf(e,t,n){let r;if(t==="viewport")r=t0(e,n);else if(t==="document")r=e0(Cn(e));else if(ln(t))r=r0(t,n);else{const o=wf(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Ls(r)}function kf(e,t){const n=qn(e);return n===t||!ln(n)||Mr(n)?!1:cn(n).position==="fixed"||kf(n,t)}function o0(e,t){const n=t.get(e);if(n)return n;let r=mo(e,[],!1).filter(a=>ln(a)&&Or(a)!=="body"),o=null;const s=cn(e).position==="fixed";let i=s?qn(e):e;for(;ln(i)&&!Mr(i);){const a=cn(i),l=$a(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&n0.has(o.position)||po(i)&&!l&&kf(e,i))?r=r.filter(d=>d!==i):o=a,i=qn(i)}return t.set(e,r),r}function s0(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Fs(t)?[]:o0(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((u,d)=>{const f=Tf(t,d,o);return u.top=Vt(f.top,u.top),u.right=Kn(f.right,u.right),u.bottom=Kn(f.bottom,u.bottom),u.left=Vt(f.left,u.left),u},Tf(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function i0(e){const{width:t,height:n}=bf(e);return{width:t,height:n}}function a0(e,t,n){const r=Tn(t),o=Cn(t),s=n==="fixed",i=pr(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=wn(0);function u(){l.x=Bs(o)}if(r||!r&&!s)if((Or(t)!=="body"||po(o))&&(a=zs(t)),r){const p=pr(t,!0,s,t);l.x=p.x+t.clientLeft,l.y=p.y+t.clientTop}else o&&u();s&&!r&&o&&u();const d=o&&!r&&!s?Sf(o,a):wn(0),f=i.left+a.scrollLeft-l.x-d.x,h=i.top+a.scrollTop-l.y-d.y;return{x:f,y:h,width:i.width,height:i.height}}function Ha(e){return cn(e).position==="static"}function Ef(e,t){if(!Tn(e)||cn(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return Cn(e)===n&&(n=n.ownerDocument.body),n}function If(e,t){const n=Kt(e);if(Fs(e))return n;if(!Tn(e)){let o=qn(e);for(;o&&!Mr(o);){if(ln(o)&&!Ha(o))return o;o=qn(o)}return n}let r=Ef(e,t);for(;r&&Uw(r)&&Ha(r);)r=Ef(r,t);return r&&Mr(r)&&Ha(r)&&!$a(r)?n:r||Gw(e)||n}const l0=async function(e){const t=this.getOffsetParent||If,n=this.getDimensions,r=await n(e.floating);return{reference:a0(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function c0(e){return cn(e).direction==="rtl"}const u0={convertOffsetParentRelativeRectToViewportRelativeRect:Zw,getDocumentElement:Cn,getClippingRect:s0,getOffsetParent:If,getElementRects:l0,getClientRects:Qw,getDimensions:i0,getScale:Dr,isElement:ln,isRTL:c0};function Nf(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function d0(e,t){let n=null,r;const o=Cn(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const u=e.getBoundingClientRect(),{left:d,top:f,width:h,height:p}=u;if(a||t(),!h||!p)return;const v=Ms(f),x=Ms(o.clientWidth-(d+h)),g=Ms(o.clientHeight-(f+p)),y=Ms(d),S={rootMargin:-v+"px "+-x+"px "+-g+"px "+-y+"px",threshold:Vt(0,Kn(1,l))||1};let I=!0;function C(T){const E=T[0].intersectionRatio;if(E!==l){if(!I)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!Nf(u,e.getBoundingClientRect())&&i(),I=!1}try{n=new IntersectionObserver(C,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(C,S)}n.observe(e)}return i(!0),s}function f0(e,t,n,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,u=Ba(e),d=o||s?[...u?mo(u):[],...mo(t)]:[];d.forEach(y=>{o&&y.addEventListener("scroll",n,{passive:!0}),s&&y.addEventListener("resize",n)});const f=u&&a?d0(u,n):null;let h=-1,p=null;i&&(p=new ResizeObserver(y=>{let[b]=y;b&&b.target===u&&p&&(p.unobserve(t),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var S;(S=p)==null||S.observe(t)})),n()}),u&&!l&&p.observe(u),p.observe(t));let v,x=l?pr(e):null;l&&g();function g(){const y=pr(e);x&&!Nf(x,y)&&n(),x=y,v=requestAnimationFrame(g)}return n(),()=>{var y;d.forEach(b=>{o&&b.removeEventListener("scroll",n),s&&b.removeEventListener("resize",n)}),f==null||f(),(y=p)==null||y.disconnect(),p=null,l&&cancelAnimationFrame(v)}}const h0=Lw,p0=$w,m0=Ow,g0=zw,x0=Mw,Af=Pw,y0=Fw,v0=(e,t,n)=>{const r=new Map,o={platform:u0,...n},s={...o.platform,_c:r};return Rw(e,t,{...o,platform:s})};var b0=typeof document<"u",w0=function(){},Hs=b0?w.useLayoutEffect:w0;function Us(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(!Us(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)&&!Us(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function _f(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function jf(e,t){const n=_f(e);return Math.round(t*n)/n}function Ua(e){const t=m.useRef(e);return Hs(()=>{t.current=e}),t}function S0(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:u}=e,[d,f]=m.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[h,p]=m.useState(r);Us(h,r)||p(r);const[v,x]=m.useState(null),[g,y]=m.useState(null),b=m.useCallback(z=>{z!==T.current&&(T.current=z,x(z))},[]),S=m.useCallback(z=>{z!==E.current&&(E.current=z,y(z))},[]),I=s||v,C=i||g,T=m.useRef(null),E=m.useRef(null),A=m.useRef(d),j=l!=null,P=Ua(l),D=Ua(o),L=Ua(u),V=m.useCallback(()=>{if(!T.current||!E.current)return;const z={placement:t,strategy:n,middleware:h};D.current&&(z.platform=D.current),v0(T.current,E.current,z).then($=>{const pe={...$,isPositioned:L.current!==!1};M.current&&!Us(A.current,pe)&&(A.current=pe,Ao.flushSync(()=>{f(pe)}))})},[h,t,n,D,L]);Hs(()=>{u===!1&&A.current.isPositioned&&(A.current.isPositioned=!1,f(z=>({...z,isPositioned:!1})))},[u]);const M=m.useRef(!1);Hs(()=>(M.current=!0,()=>{M.current=!1}),[]),Hs(()=>{if(I&&(T.current=I),C&&(E.current=C),I&&C){if(P.current)return P.current(I,C,V);V()}},[I,C,V,P,j]);const X=m.useMemo(()=>({reference:T,floating:E,setReference:b,setFloating:S}),[b,S]),K=m.useMemo(()=>({reference:I,floating:C}),[I,C]),q=m.useMemo(()=>{const z={position:n,left:0,top:0};if(!K.floating)return z;const $=jf(K.floating,d.x),pe=jf(K.floating,d.y);return a?{...z,transform:"translate("+$+"px, "+pe+"px)",..._f(K.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:$,top:pe}},[n,a,K.floating,d.x,d.y]);return m.useMemo(()=>({...d,update:V,refs:X,elements:K,floatingStyles:q}),[d,V,X,K,q])}const C0=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?Af({element:r.current,padding:o}).fn(n):{}:r?Af({element:r,padding:o}).fn(n):{}}}},T0=(e,t)=>({...h0(e),options:[e,t]}),k0=(e,t)=>({...p0(e),options:[e,t]}),E0=(e,t)=>({...y0(e),options:[e,t]}),I0=(e,t)=>({...m0(e),options:[e,t]}),N0=(e,t)=>({...g0(e),options:[e,t]}),A0=(e,t)=>({...x0(e),options:[e,t]}),_0=(e,t)=>({...C0(e),options:[e,t]});var j0="Arrow",Rf=m.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return c.jsx(Ae.svg,{...s,ref:t,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?n:c.jsx("polygon",{points:"0,0 30,0 15,10"})})});Rf.displayName=j0;var R0=Rf;function Pf(e){const[t,n]=m.useState(void 0);return bt(()=>{if(e){n({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,u=Array.isArray(l)?l[0]:l;i=u.inlineSize,a=u.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 Wa="Popper",[Of,Ws]=yn(Wa),[P0,Mf]=Of(Wa),Df=e=>{const{__scopePopper:t,children:n}=e,[r,o]=m.useState(null);return c.jsx(P0,{scope:t,anchor:r,onAnchorChange:o,children:n})};Df.displayName=Wa;var Lf="PopperAnchor",$f=m.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Mf(Lf,n),i=m.useRef(null),a=He(t,i),l=m.useRef(null);return m.useEffect(()=>{const u=l.current;l.current=(r==null?void 0:r.current)||i.current,u!==l.current&&s.onAnchorChange(l.current)}),r?null:c.jsx(Ae.div,{...o,ref:a})});$f.displayName=Lf;var Va="PopperContent",[O0,M0]=Of(Va),Ff=m.forwardRef((e,t)=>{var G,O,Q,ne,de,ae;const{__scopePopper:n,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:u=[],collisionPadding:d=0,sticky:f="partial",hideWhenDetached:h=!1,updatePositionStrategy:p="optimized",onPlaced:v,...x}=e,g=Mf(Va,n),[y,b]=m.useState(null),S=He(t,Ue=>b(Ue)),[I,C]=m.useState(null),T=Pf(I),E=(T==null?void 0:T.width)??0,A=(T==null?void 0:T.height)??0,j=r+(s!=="center"?"-"+s:""),P=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},D=Array.isArray(u)?u:[u],L=D.length>0,V={padding:P,boundary:D.filter(L0),altBoundary:L},{refs:M,floatingStyles:X,placement:K,isPositioned:q,middlewareData:z}=S0({strategy:"fixed",placement:j,whileElementsMounted:(...Ue)=>f0(...Ue,{animationFrame:p==="always"}),elements:{reference:g.anchor},middleware:[T0({mainAxis:o+A,alignmentAxis:i}),l&&k0({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?E0():void 0,...V}),l&&I0({...V}),N0({...V,apply:({elements:Ue,rects:Ze,availableWidth:me,availableHeight:Pe})=>{const{width:Le,height:ct}=Ze.reference,rt=Ue.floating.style;rt.setProperty("--radix-popper-available-width",`${me}px`),rt.setProperty("--radix-popper-available-height",`${Pe}px`),rt.setProperty("--radix-popper-anchor-width",`${Le}px`),rt.setProperty("--radix-popper-anchor-height",`${ct}px`)}}),I&&_0({element:I,padding:a}),$0({arrowWidth:E,arrowHeight:A}),h&&A0({strategy:"referenceHidden",...V})]}),[$,pe]=Hf(K),F=kt(v);bt(()=>{q&&(F==null||F())},[q,F]);const te=(G=z.arrow)==null?void 0:G.x,fe=(O=z.arrow)==null?void 0:O.y,ge=((Q=z.arrow)==null?void 0:Q.centerOffset)!==0,[be,Te]=m.useState();return bt(()=>{y&&Te(window.getComputedStyle(y).zIndex)},[y]),c.jsx("div",{ref:M.setFloating,"data-radix-popper-content-wrapper":"",style:{...X,transform:q?X.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:be,"--radix-popper-transform-origin":[(ne=z.transformOrigin)==null?void 0:ne.x,(de=z.transformOrigin)==null?void 0:de.y].join(" "),...((ae=z.hide)==null?void 0:ae.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:c.jsx(O0,{scope:n,placedSide:$,onArrowChange:C,arrowX:te,arrowY:fe,shouldHideArrow:ge,children:c.jsx(Ae.div,{"data-side":$,"data-align":pe,...x,ref:S,style:{...x.style,animation:q?void 0:"none"}})})})});Ff.displayName=Va;var zf="PopperArrow",D0={top:"bottom",right:"left",bottom:"top",left:"right"},Bf=m.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=M0(zf,r),i=D0[s.placedSide];return c.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:c.jsx(R0,{...o,ref:n,style:{...o.style,display:"block"}})})});Bf.displayName=zf;function L0(e){return e!==null}var $0=e=>({name:"transformOrigin",options:e,fn(t){var g,y,b;const{placement:n,rects:r,middlewareData:o}=t,i=((g=o.arrow)==null?void 0:g.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[u,d]=Hf(n),f={start:"0%",center:"50%",end:"100%"}[d],h=(((y=o.arrow)==null?void 0:y.x)??0)+a/2,p=(((b=o.arrow)==null?void 0:b.y)??0)+l/2;let v="",x="";return u==="bottom"?(v=i?f:`${h}px`,x=`${-l}px`):u==="top"?(v=i?f:`${h}px`,x=`${r.floating.height+l}px`):u==="right"?(v=`${-l}px`,x=i?f:`${p}px`):u==="left"&&(v=`${r.floating.width+l}px`,x=i?f:`${p}px`),{data:{x:v,y:x}}}});function Hf(e){const[t,n="center"]=e.split("-");return[t,n]}var Uf=Df,Wf=$f,Vf=Ff,Kf=Bf,Ka="rovingFocusGroup.onEntryFocus",F0={bubbles:!1,cancelable:!0},go="RovingFocusGroup",[qa,qf,z0]=Ra(go),[B0,Gf]=yn(go,[z0]),[H0,U0]=B0(go),Yf=m.forwardRef((e,t)=>c.jsx(qa.Provider,{scope:e.__scopeRovingFocusGroup,children:c.jsx(qa.Slot,{scope:e.__scopeRovingFocusGroup,children:c.jsx(W0,{...e,ref:t})})}));Yf.displayName=go;var W0=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:u,preventScrollOnEntryFocus:d=!1,...f}=e,h=m.useRef(null),p=He(t,h),v=Ps(s),[x,g]=cr({prop:i,defaultProp:a??null,onChange:l,caller:go}),[y,b]=m.useState(!1),S=kt(u),I=qf(n),C=m.useRef(!1),[T,E]=m.useState(0);return m.useEffect(()=>{const A=h.current;if(A)return A.addEventListener(Ka,S),()=>A.removeEventListener(Ka,S)},[S]),c.jsx(H0,{scope:n,orientation:r,dir:v,loop:o,currentTabStopId:x,onItemFocus:m.useCallback(A=>g(A),[g]),onItemShiftTab:m.useCallback(()=>b(!0),[]),onFocusableItemAdd:m.useCallback(()=>E(A=>A+1),[]),onFocusableItemRemove:m.useCallback(()=>E(A=>A-1),[]),children:c.jsx(Ae.div,{tabIndex:y||T===0?-1:0,"data-orientation":r,...f,ref:p,style:{outline:"none",...e.style},onMouseDown:ue(e.onMouseDown,()=>{C.current=!0}),onFocus:ue(e.onFocus,A=>{const j=!C.current;if(A.target===A.currentTarget&&j&&!y){const P=new CustomEvent(Ka,F0);if(A.currentTarget.dispatchEvent(P),!P.defaultPrevented){const D=I().filter(K=>K.focusable),L=D.find(K=>K.active),V=D.find(K=>K.id===x),X=[L,V,...D].filter(Boolean).map(K=>K.ref.current);Zf(X,d)}}C.current=!1}),onBlur:ue(e.onBlur,()=>b(!1))})})}),Xf="RovingFocusGroupItem",Jf=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=vn(),u=s||l,d=U0(Xf,n),f=d.currentTabStopId===u,h=qf(n),{onFocusableItemAdd:p,onFocusableItemRemove:v,currentTabStopId:x}=d;return m.useEffect(()=>{if(r)return p(),()=>v()},[r,p,v]),c.jsx(qa.ItemSlot,{scope:n,id:u,focusable:r,active:o,children:c.jsx(Ae.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:ue(e.onMouseDown,g=>{r?d.onItemFocus(u):g.preventDefault()}),onFocus:ue(e.onFocus,()=>d.onItemFocus(u)),onKeyDown:ue(e.onKeyDown,g=>{if(g.key==="Tab"&&g.shiftKey){d.onItemShiftTab();return}if(g.target!==g.currentTarget)return;const y=q0(g,d.orientation,d.dir);if(y!==void 0){if(g.metaKey||g.ctrlKey||g.altKey||g.shiftKey)return;g.preventDefault();let S=h().filter(I=>I.focusable).map(I=>I.ref.current);if(y==="last")S.reverse();else if(y==="prev"||y==="next"){y==="prev"&&S.reverse();const I=S.indexOf(g.currentTarget);S=d.loop?G0(S,I+1):S.slice(I+1)}setTimeout(()=>Zf(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:x!=null}):i})})});Jf.displayName=Xf;var V0={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function K0(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function q0(e,t,n){const r=K0(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return V0[r]}function Zf(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function G0(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Y0=Yf,X0=Jf,Ga=["Enter"," "],J0=["ArrowDown","PageUp","Home"],Qf=["ArrowUp","PageDown","End"],Z0=[...J0,...Qf],Q0={ltr:[...Ga,"ArrowRight"],rtl:[...Ga,"ArrowLeft"]},eS={ltr:["ArrowLeft"],rtl:["ArrowRight"]},xo="Menu",[yo,tS,nS]=Ra(xo),[mr,eh]=yn(xo,[nS,Ws,Gf]),Vs=Ws(),th=Gf(),[rS,gr]=mr(xo),[oS,vo]=mr(xo),nh=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=Vs(t),[l,u]=m.useState(null),d=m.useRef(!1),f=kt(s),h=Ps(o);return m.useEffect(()=>{const p=()=>{d.current=!0,document.addEventListener("pointerdown",v,{capture:!0,once:!0}),document.addEventListener("pointermove",v,{capture:!0,once:!0})},v=()=>d.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",v,{capture:!0}),document.removeEventListener("pointermove",v,{capture:!0})}},[]),c.jsx(Uf,{...a,children:c.jsx(rS,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:u,children:c.jsx(oS,{scope:t,onClose:m.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};nh.displayName=xo;var sS="MenuAnchor",Ya=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Vs(n);return c.jsx(Wf,{...o,...r,ref:t})});Ya.displayName=sS;var Xa="MenuPortal",[iS,rh]=mr(Xa,{forceMount:void 0}),oh=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=gr(Xa,t);return c.jsx(iS,{scope:t,forceMount:n,children:c.jsx(Wt,{present:n||s.open,children:c.jsx(xs,{asChild:!0,container:o,children:r})})})};oh.displayName=Xa;var Jt="MenuContent",[aS,Ja]=mr(Jt),sh=m.forwardRef((e,t)=>{const n=rh(Jt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=gr(Jt,e.__scopeMenu),i=vo(Jt,e.__scopeMenu);return c.jsx(yo.Provider,{scope:e.__scopeMenu,children:c.jsx(Wt,{present:r||s.open,children:c.jsx(yo.Slot,{scope:e.__scopeMenu,children:i.modal?c.jsx(lS,{...o,ref:t}):c.jsx(cS,{...o,ref:t})})})})}),lS=m.forwardRef((e,t)=>{const n=gr(Jt,e.__scopeMenu),r=m.useRef(null),o=He(t,r);return m.useEffect(()=>{const s=r.current;if(s)return Ea(s)},[]),c.jsx(Za,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:ue(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),cS=m.forwardRef((e,t)=>{const n=gr(Jt,e.__scopeMenu);return c.jsx(Za,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),uS=tr.createSlot("MenuContent.ScrollLock"),Za=m.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,disableOutsideScroll:v,...x}=e,g=gr(Jt,n),y=vo(Jt,n),b=Vs(n),S=th(n),I=tS(n),[C,T]=m.useState(null),E=m.useRef(null),A=He(t,E,g.onContentChange),j=m.useRef(0),P=m.useRef(""),D=m.useRef(0),L=m.useRef(null),V=m.useRef("right"),M=m.useRef(0),X=v?Cs:m.Fragment,K=v?{as:uS,allowPinchZoom:!0}:void 0,q=$=>{var G,O;const pe=P.current+$,F=I().filter(Q=>!Q.disabled),te=document.activeElement,fe=(G=F.find(Q=>Q.ref.current===te))==null?void 0:G.textValue,ge=F.map(Q=>Q.textValue),be=SS(ge,pe,fe),Te=(O=F.find(Q=>Q.textValue===be))==null?void 0:O.ref.current;(function Q(ne){P.current=ne,window.clearTimeout(j.current),ne!==""&&(j.current=window.setTimeout(()=>Q(""),1e3))})(pe),Te&&setTimeout(()=>Te.focus())};m.useEffect(()=>()=>window.clearTimeout(j.current),[]),ba();const z=m.useCallback($=>{var F,te;return V.current===((F=L.current)==null?void 0:F.side)&&TS($,(te=L.current)==null?void 0:te.area)},[]);return c.jsx(aS,{scope:n,searchRef:P,onItemEnter:m.useCallback($=>{z($)&&$.preventDefault()},[z]),onItemLeave:m.useCallback($=>{var pe;z($)||((pe=E.current)==null||pe.focus(),T(null))},[z]),onTriggerLeave:m.useCallback($=>{z($)&&$.preventDefault()},[z]),pointerGraceTimerRef:D,onPointerGraceIntentChange:m.useCallback($=>{L.current=$},[]),children:c.jsx(X,{...K,children:c.jsx(gs,{asChild:!0,trapped:o,onMountAutoFocus:ue(s,$=>{var pe;$.preventDefault(),(pe=E.current)==null||pe.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:c.jsx(ms,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:c.jsx(Y0,{asChild:!0,...S,dir:y.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:T,onEntryFocus:ue(l,$=>{y.isUsingKeyboardRef.current||$.preventDefault()}),preventScrollOnEntryFocus:!0,children:c.jsx(Vf,{role:"menu","aria-orientation":"vertical","data-state":Sh(g.open),"data-radix-menu-content":"",dir:y.dir,...b,...x,ref:A,style:{outline:"none",...x.style},onKeyDown:ue(x.onKeyDown,$=>{const F=$.target.closest("[data-radix-menu-content]")===$.currentTarget,te=$.ctrlKey||$.altKey||$.metaKey,fe=$.key.length===1;F&&($.key==="Tab"&&$.preventDefault(),!te&&fe&&q($.key));const ge=E.current;if($.target!==ge||!Z0.includes($.key))return;$.preventDefault();const Te=I().filter(G=>!G.disabled).map(G=>G.ref.current);Qf.includes($.key)&&Te.reverse(),bS(Te)}),onBlur:ue(e.onBlur,$=>{$.currentTarget.contains($.target)||(window.clearTimeout(j.current),P.current="")}),onPointerMove:ue(e.onPointerMove,wo($=>{const pe=$.target,F=M.current!==$.clientX;if($.currentTarget.contains(pe)&&F){const te=$.clientX>M.current?"right":"left";V.current=te,M.current=$.clientX}}))})})})})})})});sh.displayName=Jt;var dS="MenuGroup",Qa=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(Ae.div,{role:"group",...r,ref:t})});Qa.displayName=dS;var fS="MenuLabel",ih=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(Ae.div,{...r,ref:t})});ih.displayName=fS;var Ks="MenuItem",ah="menu.itemSelect",qs=m.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=m.useRef(null),i=vo(Ks,e.__scopeMenu),a=Ja(Ks,e.__scopeMenu),l=He(t,s),u=m.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(ah,{bubbles:!0,cancelable:!0});f.addEventListener(ah,p=>r==null?void 0:r(p),{once:!0}),Bu(f,h),h.defaultPrevented?u.current=!1:i.onClose()}};return c.jsx(lh,{...o,ref:l,disabled:n,onClick:ue(e.onClick,d),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),u.current=!0},onPointerUp:ue(e.onPointerUp,f=>{var h;u.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:ue(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||Ga.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});qs.displayName=Ks;var lh=m.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=Ja(Ks,n),a=th(n),l=m.useRef(null),u=He(t,l),[d,f]=m.useState(!1),[h,p]=m.useState("");return m.useEffect(()=>{const v=l.current;v&&p((v.textContent??"").trim())},[s.children]),c.jsx(yo.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:c.jsx(X0,{asChild:!0,...a,focusable:!r,children:c.jsx(Ae.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:u,onPointerMove:ue(e.onPointerMove,wo(v=>{r?i.onItemLeave(v):(i.onItemEnter(v),v.defaultPrevented||v.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:ue(e.onPointerLeave,wo(v=>i.onItemLeave(v))),onFocus:ue(e.onFocus,()=>f(!0)),onBlur:ue(e.onBlur,()=>f(!1))})})})}),hS="MenuCheckboxItem",ch=m.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return c.jsx(ph,{scope:e.__scopeMenu,checked:n,children:c.jsx(qs,{role:"menuitemcheckbox","aria-checked":Gs(n)?"mixed":n,...o,ref:t,"data-state":tl(n),onSelect:ue(o.onSelect,()=>r==null?void 0:r(Gs(n)?!0:!n),{checkForDefaultPrevented:!1})})})});ch.displayName=hS;var uh="MenuRadioGroup",[pS,mS]=mr(uh,{value:void 0,onValueChange:()=>{}}),dh=m.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=kt(r);return c.jsx(pS,{scope:e.__scopeMenu,value:n,onValueChange:s,children:c.jsx(Qa,{...o,ref:t})})});dh.displayName=uh;var fh="MenuRadioItem",hh=m.forwardRef((e,t)=>{const{value:n,...r}=e,o=mS(fh,e.__scopeMenu),s=n===o.value;return c.jsx(ph,{scope:e.__scopeMenu,checked:s,children:c.jsx(qs,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":tl(s),onSelect:ue(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});hh.displayName=fh;var el="MenuItemIndicator",[ph,gS]=mr(el,{checked:!1}),mh=m.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=gS(el,n);return c.jsx(Wt,{present:r||Gs(s.checked)||s.checked===!0,children:c.jsx(Ae.span,{...o,ref:t,"data-state":tl(s.checked)})})});mh.displayName=el;var xS="MenuSeparator",gh=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(Ae.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});gh.displayName=xS;var yS="MenuArrow",xh=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Vs(n);return c.jsx(Kf,{...o,...r,ref:t})});xh.displayName=yS;var vS="MenuSub",[ok,yh]=mr(vS),bo="MenuSubTrigger",vh=m.forwardRef((e,t)=>{const n=gr(bo,e.__scopeMenu),r=vo(bo,e.__scopeMenu),o=yh(bo,e.__scopeMenu),s=Ja(bo,e.__scopeMenu),i=m.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,u={__scopeMenu:e.__scopeMenu},d=m.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return m.useEffect(()=>d,[d]),m.useEffect(()=>{const f=a.current;return()=>{window.clearTimeout(f),l(null)}},[a,l]),c.jsx(Ya,{asChild:!0,...u,children:c.jsx(lh,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":Sh(n.open),...e,ref:ia(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:ue(e.onPointerMove,wo(f=>{s.onItemEnter(f),!f.defaultPrevented&&!e.disabled&&!n.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{n.onOpenChange(!0),d()},100))})),onPointerLeave:ue(e.onPointerLeave,wo(f=>{var p,v;d();const h=(p=n.content)==null?void 0:p.getBoundingClientRect();if(h){const x=(v=n.content)==null?void 0:v.dataset.side,g=x==="right",y=g?-5:5,b=h[g?"left":"right"],S=h[g?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+y,y:f.clientY},{x:b,y:h.top},{x:S,y:h.top},{x:S,y:h.bottom},{x:b,y:h.bottom}],side:x}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(f),f.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:ue(e.onKeyDown,f=>{var p;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||Q0[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});vh.displayName=bo;var bh="MenuSubContent",wh=m.forwardRef((e,t)=>{const n=rh(Jt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=gr(Jt,e.__scopeMenu),i=vo(Jt,e.__scopeMenu),a=yh(bh,e.__scopeMenu),l=m.useRef(null),u=He(t,l);return c.jsx(yo.Provider,{scope:e.__scopeMenu,children:c.jsx(Wt,{present:r||s.open,children:c.jsx(yo.Slot,{scope:e.__scopeMenu,children:c.jsx(Za,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:u,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var f;i.isUsingKeyboardRef.current&&((f=l.current)==null||f.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside:ue(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ue(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:ue(e.onKeyDown,d=>{var p;const f=d.currentTarget.contains(d.target),h=eS[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),d.preventDefault())})})})})})});wh.displayName=bh;function Sh(e){return e?"open":"closed"}function Gs(e){return e==="indeterminate"}function tl(e){return Gs(e)?"indeterminate":e?"checked":"unchecked"}function bS(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function wS(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function SS(e,t,n){const o=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=wS(e,Math.max(s,0));o.length===1&&(i=i.filter(u=>u!==n));const l=i.find(u=>u.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function CS(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s],l=t[i],u=a.x,d=a.y,f=l.x,h=l.y;d>r!=h>r&&n<(f-u)*(r-d)/(h-d)+u&&(o=!o)}return o}function TS(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return CS(n,t)}function wo(e){return t=>t.pointerType==="mouse"?e(t):void 0}var kS=nh,ES=Ya,IS=oh,NS=sh,AS=Qa,_S=ih,jS=qs,RS=ch,PS=dh,OS=hh,MS=mh,DS=gh,LS=xh,$S=vh,FS=wh,Ys="DropdownMenu",[zS,sk]=yn(Ys,[eh]),Pt=eh(),[BS,Ch]=zS(Ys),Th=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=Pt(t),u=m.useRef(null),[d,f]=cr({prop:o,defaultProp:s??!1,onChange:i,caller:Ys});return c.jsx(BS,{scope:t,triggerId:vn(),triggerRef:u,contentId:vn(),open:d,onOpenChange:f,onOpenToggle:m.useCallback(()=>f(h=>!h),[f]),modal:a,children:c.jsx(kS,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};Th.displayName=Ys;var kh="DropdownMenuTrigger",Eh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Ch(kh,n),i=Pt(n);return c.jsx(ES,{asChild:!0,...i,children:c.jsx(Ae.button,{type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r,...o,ref:ia(t,s.triggerRef),onPointerDown:ue(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:ue(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});Eh.displayName=kh;var HS="DropdownMenuPortal",Ih=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Pt(t);return c.jsx(IS,{...r,...n})};Ih.displayName=HS;var Nh="DropdownMenuContent",Ah=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Ch(Nh,n),s=Pt(n),i=m.useRef(!1);return c.jsx(NS,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:ue(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:ue(e.onInteractOutside,a=>{const l=a.detail.originalEvent,u=l.button===0&&l.ctrlKey===!0,d=l.button===2||u;(!o.modal||d)&&(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)"}})});Ah.displayName=Nh;var US="DropdownMenuGroup",WS=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Pt(n);return c.jsx(AS,{...o,...r,ref:t})});WS.displayName=US;var VS="DropdownMenuLabel",_h=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Pt(n);return c.jsx(_S,{...o,...r,ref:t})});_h.displayName=VS;var KS="DropdownMenuItem",jh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Pt(n);return c.jsx(jS,{...o,...r,ref:t})});jh.displayName=KS;var qS="DropdownMenuCheckboxItem",Rh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Pt(n);return c.jsx(RS,{...o,...r,ref:t})});Rh.displayName=qS;var GS="DropdownMenuRadioGroup",YS=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Pt(n);return c.jsx(PS,{...o,...r,ref:t})});YS.displayName=GS;var XS="DropdownMenuRadioItem",Ph=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Pt(n);return c.jsx(OS,{...o,...r,ref:t})});Ph.displayName=XS;var JS="DropdownMenuItemIndicator",Oh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Pt(n);return c.jsx(MS,{...o,...r,ref:t})});Oh.displayName=JS;var ZS="DropdownMenuSeparator",Mh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Pt(n);return c.jsx(DS,{...o,...r,ref:t})});Mh.displayName=ZS;var QS="DropdownMenuArrow",eC=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Pt(n);return c.jsx(LS,{...o,...r,ref:t})});eC.displayName=QS;var tC="DropdownMenuSubTrigger",Dh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Pt(n);return c.jsx($S,{...o,...r,ref:t})});Dh.displayName=tC;var nC="DropdownMenuSubContent",Lh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Pt(n);return c.jsx(FS,{...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)"}})});Lh.displayName=nC;var rC=Th,oC=Eh,sC=Ih,$h=Ah,Fh=_h,zh=jh,Bh=Rh,Hh=Ph,Uh=Oh,Wh=Mh,Vh=Dh,Kh=Lh;const iC=rC,aC=oC,lC=m.forwardRef(({className:e,inset:t,children:n,...r},o)=>c.jsxs(Vh,{ref:o,className:ee("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,c.jsx(ie.ChevronRight,{className:"ml-auto h-4 w-4"})]}));lC.displayName=Vh.displayName;const cC=m.forwardRef(({className:e,...t},n)=>c.jsx(Kh,{ref:n,className:ee("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}));cC.displayName=Kh.displayName;const qh=m.forwardRef(({className:e,sideOffset:t=4,...n},r)=>c.jsx(sC,{children:c.jsx($h,{ref:r,sideOffset:t,className:ee("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})}));qh.displayName=$h.displayName;const nl=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(zh,{ref:r,className:ee("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}));nl.displayName=zh.displayName;const uC=m.forwardRef(({className:e,children:t,checked:n,...r},o)=>c.jsxs(Bh,{ref:o,className:ee("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:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(Uh,{children:c.jsx(ie.Check,{className:"h-4 w-4"})})}),t]}));uC.displayName=Bh.displayName;const dC=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Hh,{ref:r,className:ee("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:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(Uh,{children:c.jsx(ie.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));dC.displayName=Hh.displayName;const fC=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(Fh,{ref:r,className:ee("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));fC.displayName=Fh.displayName;const hC=m.forwardRef(({className:e,...t},n)=>c.jsx(Wh,{ref:n,className:ee("-mx-1 my-1 h-px bg-muted",e),...t}));hC.displayName=Wh.displayName;function Xs({className:e="",placeholder:t="Type your message...",autoFocus:n=!0,maxHeight:r=void 0,streamingDebounceMs:o=500,streamingThrottleMs:s,followNewMessages:i=!0,enableFileUpload:a=!0,enableExcelUpload:l=!1,enableMessageEditing:u=!0,customStyles:d={},onMessageSent:f,onExcelUploadSuccess:h,onError:p}){const{api:v}=ki(),{currentThreadId:x}=Wo(),{threadId:g,messages:y,hasMore:b,isHistoryLoading:S,isLoading:I,loadOlder:C,navigateToCheckpoint:T,returnToLatest:E,checkpoint:A,checkpoints:j,respondToInterrupt:P,metadata:D}=Vo(),{isStreaming:L,error:V,submit:M,stop:X}=zc(),K=(A==null?void 0:A.id)??null,q=(A==null?void 0:A.namespace)??null,z=(D==null?void 0:D.assemblingMessageId)??null,[$,pe]=w.useState(null),[F,te]=w.useState(""),[fe,ge]=w.useState(null),[be,Te]=w.useState([]),[G,O]=w.useState(0),[Q,ne]=w.useState(0),[de,ae]=w.useState(!1),[Ue,Ze]=w.useState(null),[me,Pe]=w.useState(null),[Le,ct]=w.useState(!1),[rt,vt]=w.useState(null),[wt,B]=w.useState(!1),se=w.useRef(null),we=w.useRef(null),Ie=w.useCallback(()=>{se.current&&(se.current.value=""),we.current&&(we.current.value=""),O(he=>he+1),ne(he=>he+1)},[]),ye=w.useRef(!1);w.useEffect(()=>{ye.current&&!L&&(Te([]),Ie()),ye.current=L},[L,Ie]);const[je,Qe]=w.useState("desktop");w.useEffect(()=>{const he=()=>{const ve=window.innerWidth;Qe(ve<640?"phone":ve<1024?"tablet":"desktop")};return he(),window.addEventListener("resize",he),()=>window.removeEventListener("resize",he)},[]);const Fe=w.useCallback(async()=>{if(!(!b||S))try{await C()}catch(he){console.warn("loadOlder failed",he)}},[b,S,C]);w.useEffect(()=>{(async()=>{if(!v.baseUrl){vt(null);return}try{const ve=await v.getAgent("default");vt(ve.uiDefaultMessage||null)}catch(ve){console.warn("Failed to fetch default message:",ve),vt(null)}})()},[v]),w.useEffect(()=>{V&&!Le&&(p==null||p(V))},[V,Le,p]);const pt=he=>{if(he.length>Rs)return`Message too long (${he.length}/${Rs} characters)`;try{return vw(he),null}catch(ve){return(ve==null?void 0:ve.message)||"Invalid message"}},St=async he=>{const ve=he.trim();if(!(!ve&&be.length===0)){if(ve){const et=pt(ve);if(et){ge(et);return}}try{await M({text:ve||"",attachments:be,payload:$?{edit:!0,originalMessageId:$}:void 0},{checkpointId:K??void 0,checkpointNs:q??void 0}),f==null||f(ve),ge(null),Te([]),Ie(),pe(null),te("")}catch(et){const dt=(et==null?void 0:et.message)||"Failed to send message";ge(dt),p==null||p(dt)}}},en=w.useCallback((he,ve)=>{u&&(pe(he),te(ve),ge(null))},[u]),Ft=w.useCallback(()=>{pe(null),te(""),ge(null)},[]),dn=w.useCallback((he,ve)=>{en(he,ve)},[en]),En=w.useCallback(he=>{const ve=et=>{const dt=et.content||[],ft=dt.filter(nn=>nn.type==="text").map(nn=>nn.text).join("");if(ft)return ft;try{return JSON.stringify(dt,null,2)}catch{return String(dt)}};for(let et=he-1;et>=0;et--)if(y[et].role==="user"){const dt=ve(y[et]);dt&&M({text:dt},{checkpointId:K??void 0,checkpointNs:q??void 0});break}},[y,M,K,q]),zr=he=>{const ve=Array.from(he.target.files||[]);Te(et=>[...et,...ve]),he.target.value=""},Jn=he=>{Te(ve=>{const et=ve.filter((dt,ft)=>he!==ft);return et.length===0&&Ie(),et})},tn=async he=>{const ve=(he.target.files||[])[0];if(ve){Ze(null),Pe(null),ae(!0);try{await M({attachments:[ve]},{checkpointId:K??void 0,checkpointNs:q??void 0});const et=`Uploaded ${ve.name} - processing through chat stream`;Pe(et)}catch(et){const dt=et instanceof Error?et.message:"Failed to upload Excel file";console.error("Excel upload failed",et),Ze(dt),p==null||p(dt)}finally{ae(!1),he.target.value="",Ie()}}},Mn=he=>{if(!he)return"Unknown";const ve=Date.parse(he);return Number.isNaN(ve)?he:new Date(ve).toLocaleString()},Ot=async he=>{if(x){B(!0);try{if(!he){await E();return}const ve=j.find(dt=>dt.checkpointId===he),et=(ve==null?void 0:ve.checkpointNs)??null;await T(he,et)}finally{B(!1)}}},Zn=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${d.container||""}`,Br=`flex-1 min-h-0 min-w-0 max-h-full w-full overflow-hidden overscroll-contain break-words break-anywhere p-4 bg-transparent ${d.messagesArea||""}`,Hr=`flex-shrink-0 w-full border-t p-4 bg-transparent ${d.inputArea||""}`;return c.jsxs("div",{className:Zn,children:[!!V&&!Le&&c.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:[c.jsx("span",{children:V}),c.jsx(Ke,{variant:"ghost",size:"sm",onClick:()=>ct(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:c.jsx(ie.X,{size:16})})]}),x&&j.length>0&&c.jsxs("div",{className:"flex-shrink-0 flex items-center gap-2 px-4 py-2 border-b border-border bg-muted/60 text-xs dark:bg-muted/50",children:[c.jsx("span",{className:"opacity-70",children:"Checkpoint:"}),c.jsxs("select",{className:"border border-border rounded px-2 py-1 text-xs bg-card text-foreground focus:outline-none focus:ring-1 focus:ring-ring dark:bg-secondary",value:K??"",onChange:he=>{const ve=he.target.value||null;Ot(ve)},children:[c.jsx("option",{value:"",children:"Latest"}),j.map(he=>c.jsxs("option",{value:he.checkpointId,children:[Mn(he.createdAt),he.preview?` — ${he.preview.slice(0,40)}`:""]},he.checkpointId))]})]}),c.jsxs("div",{className:`relative ${Br}`,style:r?{maxHeight:r}:void 0,children:[c.jsx(ja,{className:"h-full",style:{height:"100%"},messages:y,isStreaming:L,streamingAssistantId:z,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:je,enableMessageEditing:u,editingMessageId:$,onStartReached:()=>{Fe()},onEdit:dn,onRegenerate:En,onCancelEdit:Ft,emptyMessage:rt??void 0,isNavigatingCheckpoint:wt}),I&&c.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:[c.jsx(ie.Loader2,{className:"h-6 w-6 animate-spin"}),c.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide",children:"Loading messages…"})]})]}),c.jsxs("div",{className:Hr,children:[$&&c.jsx("div",{className:"mb-3 p-3 bg-blue-50 border border-blue-200 rounded-lg",children:c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(ie.Edit3,{size:16,className:"text-blue-600"}),c.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),c.jsx(Ke,{variant:"ghost",size:"sm",onClick:Ft,className:"text-blue-600 hover:bg-blue-100",children:c.jsx(ie.X,{size:16})})]})}),(a||l)&&c.jsxs("div",{className:"mb-3 space-y-3",children:[a&&c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:se,type:"file",multiple:!0,onChange:he=>zr(he),className:"hidden"},G),be.length>0&&c.jsx("div",{className:"flex flex-wrap gap-2",children:be.map((he,ve)=>c.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:[c.jsx(ie.Paperclip,{size:14}),c.jsx("span",{className:"truncate max-w-[150px]",children:he.name}),c.jsx(Ke,{variant:"ghost",size:"sm",onClick:()=>Jn(ve),className:"h-4 w-4 p-0 text-gray-500 dark:text-gray-400 hover:text-red-500 dark:hover:text-red-400","aria-label":`Remove ${he.name}`,children:c.jsx(ie.X,{size:12})})]},ve))})]}),l&&c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:we,type:"file",accept:".xls,.xlsx,.xlsm",onChange:tn,className:"hidden"},Q),de&&c.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[c.jsx(ie.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),me&&!de&&c.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:me}),Ue&&!de&&c.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:Ue})]})]}),fe&&c.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:fe}),c.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&c.jsxs(iC,{children:[c.jsx(aC,{asChild:!0,children:c.jsx(Ke,{type:"button",size:"icon",variant:"outline",disabled:L,title:"More input actions",className:d.moreButton||"",children:c.jsx(ie.Plus,{size:16})})}),c.jsxs(qh,{align:"start",sideOffset:6,className:"w-52",children:[a&&c.jsxs(nl,{onClick:()=>{var he;return(he=se.current)==null?void 0:he.click()},className:"cursor-pointer",children:[c.jsx(ie.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&c.jsxs(nl,{onClick:()=>{var he;de||(he=we.current)==null||he.click()},className:`cursor-pointer ${de?"opacity-60 pointer-events-none":""}`,children:[c.jsx(ie.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),c.jsx("div",{className:"flex-1",children:c.jsx(Rx,{initialValue:F,editingMessageId:$,placeholder:$?"Edit your message...":t,isStreaming:L,disabled:!1,maxLength:Rs,onSend:St,onCancelEdit:Ft,onStop:X,allowEmptySend:be.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${$?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${fe?"border-red-400":""} ${d.textarea||""}`})})]})]})]})}const Js=m.forwardRef(({className:e,type:t,...n},r)=>c.jsx("input",{type:t,className:ee("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",e),ref:r,...n}));Js.displayName="Input";function rl(e,[t,n]){return Math.min(n,Math.max(t,e))}function pC(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var ol="ScrollArea",[Gh,ik]=yn(ol),[mC,Zt]=Gh(ol),Yh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,type:r="hover",dir:o,scrollHideDelay:s=600,...i}=e,[a,l]=m.useState(null),[u,d]=m.useState(null),[f,h]=m.useState(null),[p,v]=m.useState(null),[x,g]=m.useState(null),[y,b]=m.useState(0),[S,I]=m.useState(0),[C,T]=m.useState(!1),[E,A]=m.useState(!1),j=He(t,D=>l(D)),P=Ps(o);return c.jsx(mC,{scope:n,type:r,dir:P,scrollHideDelay:s,scrollArea:a,viewport:u,onViewportChange:d,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:v,scrollbarXEnabled:C,onScrollbarXEnabledChange:T,scrollbarY:x,onScrollbarYChange:g,scrollbarYEnabled:E,onScrollbarYEnabledChange:A,onCornerWidthChange:b,onCornerHeightChange:I,children:c.jsx(Ae.div,{dir:P,...i,ref:j,style:{position:"relative","--radix-scroll-area-corner-width":y+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});Yh.displayName=ol;var Xh="ScrollAreaViewport",Jh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=Zt(Xh,n),a=m.useRef(null),l=He(t,a,i.onViewportChange);return c.jsxs(c.Fragment,{children:[c.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}),c.jsx(Ae.div,{"data-radix-scroll-area-viewport":"",...s,ref:l,style:{overflowX:i.scrollbarXEnabled?"scroll":"hidden",overflowY:i.scrollbarYEnabled?"scroll":"hidden",...e.style},children:c.jsx("div",{ref:i.onContentChange,style:{minWidth:"100%",display:"table"},children:r})})]})});Jh.displayName=Xh;var kn="ScrollAreaScrollbar",sl=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Zt(kn,e.__scopeScrollArea),{onScrollbarXEnabledChange:s,onScrollbarYEnabledChange:i}=o,a=e.orientation==="horizontal";return m.useEffect(()=>(a?s(!0):i(!0),()=>{a?s(!1):i(!1)}),[a,s,i]),o.type==="hover"?c.jsx(gC,{...r,ref:t,forceMount:n}):o.type==="scroll"?c.jsx(xC,{...r,ref:t,forceMount:n}):o.type==="auto"?c.jsx(Zh,{...r,ref:t,forceMount:n}):o.type==="always"?c.jsx(il,{...r,ref:t}):null});sl.displayName=kn;var gC=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Zt(kn,e.__scopeScrollArea),[s,i]=m.useState(!1);return m.useEffect(()=>{const a=o.scrollArea;let l=0;if(a){const u=()=>{window.clearTimeout(l),i(!0)},d=()=>{l=window.setTimeout(()=>i(!1),o.scrollHideDelay)};return a.addEventListener("pointerenter",u),a.addEventListener("pointerleave",d),()=>{window.clearTimeout(l),a.removeEventListener("pointerenter",u),a.removeEventListener("pointerleave",d)}}},[o.scrollArea,o.scrollHideDelay]),c.jsx(Wt,{present:n||s,children:c.jsx(Zh,{"data-state":s?"visible":"hidden",...r,ref:t})})}),xC=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Zt(kn,e.__scopeScrollArea),s=e.orientation==="horizontal",i=ti(()=>l("SCROLL_END"),100),[a,l]=pC("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 m.useEffect(()=>{if(a==="idle"){const u=window.setTimeout(()=>l("HIDE"),o.scrollHideDelay);return()=>window.clearTimeout(u)}},[a,o.scrollHideDelay,l]),m.useEffect(()=>{const u=o.viewport,d=s?"scrollLeft":"scrollTop";if(u){let f=u[d];const h=()=>{const p=u[d];f!==p&&(l("SCROLL"),i()),f=p};return u.addEventListener("scroll",h),()=>u.removeEventListener("scroll",h)}},[o.viewport,s,l,i]),c.jsx(Wt,{present:n||a!=="hidden",children:c.jsx(il,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:ue(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:ue(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),Zh=m.forwardRef((e,t)=>{const n=Zt(kn,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=m.useState(!1),a=e.orientation==="horizontal",l=ti(()=>{if(n.viewport){const u=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?u:d)}},10);return Lr(n.viewport,l),Lr(n.content,l),c.jsx(Wt,{present:r||s,children:c.jsx(il,{"data-state":s?"visible":"hidden",...o,ref:t})})}),il=m.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=Zt(kn,e.__scopeScrollArea),s=m.useRef(null),i=m.useRef(0),[a,l]=m.useState({content:0,viewport:0,scrollbar:{size:0,paddingStart:0,paddingEnd:0}}),u=rp(a.viewport,a.content),d={...r,sizes:a,onSizesChange:l,hasThumb:u>0&&u<1,onThumbChange:h=>s.current=h,onThumbPointerUp:()=>i.current=0,onThumbPointerDown:h=>i.current=h};function f(h,p){return CC(h,i.current,a,p)}return n==="horizontal"?c.jsx(yC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=op(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"?c.jsx(vC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=op(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}),yC=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Zt(kn,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),u=He(t,l,s.onScrollbarXChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),c.jsx(ep,{"data-orientation":"horizontal",...o,ref:u,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":ei(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.x),onDragScroll:d=>e.onDragScroll(d.x),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollLeft+d.deltaX;e.onWheelScroll(h),ip(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollWidth,viewport:s.viewport.offsetWidth,scrollbar:{size:l.current.clientWidth,paddingStart:Qs(i.paddingLeft),paddingEnd:Qs(i.paddingRight)}})}})}),vC=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=Zt(kn,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),u=He(t,l,s.onScrollbarYChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),c.jsx(ep,{"data-orientation":"vertical",...o,ref:u,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":ei(n)+"px",...e.style},onThumbPointerDown:d=>e.onThumbPointerDown(d.y),onDragScroll:d=>e.onDragScroll(d.y),onWheelScroll:(d,f)=>{if(s.viewport){const h=s.viewport.scrollTop+d.deltaY;e.onWheelScroll(h),ip(h,f)&&d.preventDefault()}},onResize:()=>{l.current&&s.viewport&&i&&r({content:s.viewport.scrollHeight,viewport:s.viewport.offsetHeight,scrollbar:{size:l.current.clientHeight,paddingStart:Qs(i.paddingTop),paddingEnd:Qs(i.paddingBottom)}})}})}),[bC,Qh]=Gh(kn),ep=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,sizes:r,hasThumb:o,onThumbChange:s,onThumbPointerUp:i,onThumbPointerDown:a,onThumbPositionChange:l,onDragScroll:u,onWheelScroll:d,onResize:f,...h}=e,p=Zt(kn,n),[v,x]=m.useState(null),g=He(t,j=>x(j)),y=m.useRef(null),b=m.useRef(""),S=p.viewport,I=r.content-r.viewport,C=kt(d),T=kt(l),E=ti(f,10);function A(j){if(y.current){const P=j.clientX-y.current.left,D=j.clientY-y.current.top;u({x:P,y:D})}}return m.useEffect(()=>{const j=P=>{const D=P.target;(v==null?void 0:v.contains(D))&&C(P,I)};return document.addEventListener("wheel",j,{passive:!1}),()=>document.removeEventListener("wheel",j,{passive:!1})},[S,v,I,C]),m.useEffect(T,[r,T]),Lr(v,E),Lr(p.content,E),c.jsx(bC,{scope:n,scrollbar:v,hasThumb:o,onThumbChange:kt(s),onThumbPointerUp:kt(i),onThumbPositionChange:T,onThumbPointerDown:kt(a),children:c.jsx(Ae.div,{...h,ref:g,style:{position:"absolute",...h.style},onPointerDown:ue(e.onPointerDown,j=>{j.button===0&&(j.target.setPointerCapture(j.pointerId),y.current=v.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),A(j))}),onPointerMove:ue(e.onPointerMove,A),onPointerUp:ue(e.onPointerUp,j=>{const P=j.target;P.hasPointerCapture(j.pointerId)&&P.releasePointerCapture(j.pointerId),document.body.style.webkitUserSelect=b.current,p.viewport&&(p.viewport.style.scrollBehavior=""),y.current=null})})})}),Zs="ScrollAreaThumb",tp=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=Qh(Zs,e.__scopeScrollArea);return c.jsx(Wt,{present:n||o.hasThumb,children:c.jsx(wC,{ref:t,...r})})}),wC=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=Zt(Zs,n),i=Qh(Zs,n),{onThumbPositionChange:a}=i,l=He(t,f=>i.onThumbChange(f)),u=m.useRef(void 0),d=ti(()=>{u.current&&(u.current(),u.current=void 0)},100);return m.useEffect(()=>{const f=s.viewport;if(f){const h=()=>{if(d(),!u.current){const p=TC(f,a);u.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,d,a]),c.jsx(Ae.div,{"data-state":i.hasThumb?"visible":"hidden",...o,ref:l,style:{width:"var(--radix-scroll-area-thumb-width)",height:"var(--radix-scroll-area-thumb-height)",...r},onPointerDownCapture:ue(e.onPointerDownCapture,f=>{const p=f.target.getBoundingClientRect(),v=f.clientX-p.left,x=f.clientY-p.top;i.onThumbPointerDown({x:v,y:x})}),onPointerUp:ue(e.onPointerUp,i.onThumbPointerUp)})});tp.displayName=Zs;var al="ScrollAreaCorner",np=m.forwardRef((e,t)=>{const n=Zt(al,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?c.jsx(SC,{...e,ref:t}):null});np.displayName=al;var SC=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=Zt(al,n),[s,i]=m.useState(0),[a,l]=m.useState(0),u=!!(s&&a);return Lr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),Lr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),u?c.jsx(Ae.div,{...r,ref:t,style:{width:s,height:a,position:"absolute",right:o.dir==="ltr"?0:void 0,left:o.dir==="rtl"?0:void 0,bottom:0,...e.style}}):null});function Qs(e){return e?parseInt(e,10):0}function rp(e,t){const n=e/t;return isNaN(n)?0:n}function ei(e){const t=rp(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function CC(e,t,n,r="ltr"){const o=ei(n),s=o/2,i=t||s,a=o-i,l=n.scrollbar.paddingStart+i,u=n.scrollbar.size-n.scrollbar.paddingEnd-a,d=n.content-n.viewport,f=r==="ltr"?[0,d]:[d*-1,0];return sp([l,u],f)(e)}function op(e,t,n="ltr"){const r=ei(t),o=t.scrollbar.paddingStart+t.scrollbar.paddingEnd,s=t.scrollbar.size-o,i=t.content-t.viewport,a=s-r,l=n==="ltr"?[0,i]:[i*-1,0],u=rl(e,l);return sp([0,i],[0,a])(u)}function sp(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 ip(e,t){return e>0&&e<t}var TC=(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 ti(e,t){const n=kt(e),r=m.useRef(0);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),m.useCallback(()=>{window.clearTimeout(r.current),r.current=window.setTimeout(n,t)},[n,t])}function Lr(e,t){const n=kt(t);bt(()=>{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 ap=Yh,kC=Jh,EC=np;const lp=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(ap,{ref:r,className:ee("relative overflow-hidden",e),...n,children:[c.jsx(kC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),c.jsx(cp,{}),c.jsx(EC,{})]}));lp.displayName=ap.displayName;const cp=m.forwardRef(({className:e,orientation:t="vertical",...n},r)=>c.jsx(sl,{ref:r,orientation:t,className:ee("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:c.jsx(tp,{className:"relative flex-1 rounded-full bg-border"})}));cp.displayName=sl.displayName;function ll({className:e="",showCreateButton:t=!0,showDeleteButton:n=!0,showEditTitle:r=!0,maxHeight:o="400px",customStyles:s={},currentThreadId:i=null,navigateToThread:a,onThreadSelect:l,onThreadCreate:u,onThreadDelete:d}){const{threads:f,currentThreadId:h,isLoading:p,actions:v}=Wo(),{loadThread:x}=Vo(),{createThread:g,deleteThread:y,renameThread:b}=v,[S,I]=w.useState(Array.isArray(f)?f:[]),C=w.useRef(S.length>0),[T,E]=w.useState(null),[A,j]=w.useState(""),[P,D]=w.useState(!1);w.useEffect(()=>{const F=Array.isArray(f)?f:[];if(F.length>0){C.current=!0,I(F);return}p||(C.current=!1,I(F))},[f,p]);const L=async F=>{try{await x(F),a==null||a(F),l==null||l(F)}catch(te){console.error("Failed to select thread:",te)}},V=async()=>{try{D(!0);const F=await g();u==null||u(F),a==null||a(F)}catch(F){console.error("Failed to create thread:",F)}finally{D(!1)}},M=async(F,te)=>{if(te.stopPropagation(),!!confirm("Delete this thread?"))try{await y(F),d==null||d(F)}catch(fe){console.error("Failed to delete thread:",fe)}},X=(F,te)=>{te.stopPropagation(),E(F.threadId),j(F.title||`Thread ${F.threadId.slice(0,8)}`)},K=async F=>{if(A.trim())try{await b(F,A.trim()),E(null),j("")}catch(te){console.error("Failed to update title:",te)}},q=()=>{E(null),j("")},z=(F,te)=>{F.key==="Enter"?K(te):F.key==="Escape"&&q()},$=F=>{if(!F)return"";try{const te=new Date(F),ge=new Date().getTime()-te.getTime(),be=Math.floor(ge/(1e3*60*60*24));return be===0?te.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):be===1?"Yesterday":be<7?`${be} days ago`:te.toLocaleDateString()}catch{return""}},pe=F=>F.title||`Thread ${F.threadId.slice(0,8)}`;return c.jsxs("div",{className:`flex flex-col h-full ${e} ${s.container||""}`,children:[t&&c.jsx("div",{className:s.header||"flex-shrink-0 p-2 border-b bg-slate-800 border-slate-700 text-slate-100 flex justify-end",children:c.jsx(Ke,{onClick:V,disabled:P||p,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:P?"Creating...":"New Chat",children:c.jsx(ie.MessageSquarePlus,{size:20})})}),c.jsx(lp,{className:`flex-1 min-h-0 ${s.threadList||""}`,style:o?{maxHeight:o}:void 0,children:c.jsx("div",{className:"p-2 space-y-1 pb-4",children:p?c.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-8 text-slate-400",children:[c.jsx(ie.Loader2,{className:"h-5 w-5 animate-spin"}),c.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):S.length===0?c.jsxs("div",{className:"text-center py-8 text-slate-400",children:[c.jsx(ie.MessageSquare,{className:"w-8 h-8 mx-auto mb-2 opacity-40 text-slate-500"}),c.jsx("p",{className:"text-sm text-slate-500",children:"No conversations yet"})]}):S.slice().sort((F,te)=>new Date(te.updatedAt||te.createdAt||"").getTime()-new Date(F.updatedAt||F.createdAt||"").getTime()).map(F=>c.jsxs("div",{onClick:()=>L(F.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??h)===F.threadId?`${s.activeThread||"bg-slate-600 border-slate-500"} `:`${s.threadItem||"bg-slate-700 border-slate-600 hover:bg-slate-600 text-gray-900 dark:text-slate-100"}`} ${s.threadItem||""} text-gray-900 dark:text-slate-100`,children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("div",{className:"flex-1 min-w-0",children:T===F.threadId?c.jsxs("div",{className:"flex items-center gap-2",onClick:te=>te.stopPropagation(),children:[c.jsx(Js,{value:A,onChange:te=>j(te.target.value),onKeyDown:te=>z(te,F.threadId),className:"h-6 text-sm",autoFocus:!0}),c.jsx(Ke,{variant:"ghost",size:"sm",onClick:()=>K(F.threadId),className:"h-6 w-6 p-0",children:c.jsx(ie.Check,{size:12})}),c.jsx(Ke,{variant:"ghost",size:"sm",onClick:q,className:"h-6 w-6 p-0",children:c.jsx(ie.X,{size:12})})]}):c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"font-medium text-sm truncate text-gray-900 dark:text-slate-100",children:pe(F)}),c.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[c.jsx(ie.Calendar,{size:10}),c.jsx("span",{children:$(F.updatedAt||F.createdAt)})]})]})}),c.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&T!==F.threadId&&c.jsx(Ke,{variant:"ghost",size:"sm",onClick:te=>X(F,te),className:"h-6 w-6 p-0",title:"Edit title",children:c.jsx(ie.Edit3,{size:12})}),n&&c.jsx(Ke,{variant:"ghost",size:"sm",onClick:te=>M(F.threadId,te),className:"h-6 w-6 p-0 text-red-400 hover:text-red-300 hover:bg-red-900/20",title:"Delete thread",children:c.jsx(ie.Trash2,{size:12})})]})]}),i===F.threadId&&c.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},F.threadId))})})]})}function $r(e){if(!(typeof globalThis>"u"))return globalThis[e]}function IC(e){if(typeof e!="string")return;const t=e.trim();if(t)return _n(t)}function up(){const e=[$r("__API_BASE_URL__"),$r("__CHAT_API_BASE_URL__"),$r("__CHAT_API_URL__")];for(const t of e){const n=IC(t);if(n)return n}}function dp(){const e=[$r("__API_AUTH_TOKEN__"),$r("__CHAT_API_KEY__"),$r("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function fp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return _n(t);return _n()}function hp(){const e={},t=up(),n=dp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function pp(){const e=hp(),t=$n.getAuthToken(),n=up();return{apiBaseUrl:fp(e.baseUrl,$n.baseUrl,n),apiKey:t||e.apiKey||dp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,truncateToolMessages:!0,toolMessagePreviewLength:200,darkMode:!1,enableSound:!1,messageHistory:100}}const mp="chat-settings";function NC(){try{const e=localStorage.getItem(mp);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function AC(e){try{const t={...e,apiBaseUrl:_n(e.apiBaseUrl)};localStorage.setItem(mp,JSON.stringify(t)),t.apiKey&&$n.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function _C(){const e=pp(),t=NC(),n=$n.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:fp($n.baseUrl,r,e.apiBaseUrl)}}function jC(e){$n.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),AC(e)}var RC="Label",gp=m.forwardRef((e,t)=>c.jsx(Ae.label,{...e,ref:t,onMouseDown:n=>{var o;n.target.closest("button, input, select, textarea")||((o=e.onMouseDown)==null||o.call(e,n),!n.defaultPrevented&&n.detail>1&&n.preventDefault())}}));gp.displayName=RC;var xp=gp;const PC=No.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Qt=m.forwardRef(({className:e,...t},n)=>c.jsx(xp,{ref:n,className:ee(PC(),e),...t}));Qt.displayName=xp.displayName;function yp(e){const t=m.useRef({value:e,previous:e});return m.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}var ni="Switch",[OC,ak]=yn(ni),[MC,DC]=OC(ni),vp=m.forwardRef((e,t)=>{const{__scopeSwitch:n,name:r,checked:o,defaultChecked:s,required:i,disabled:a,value:l="on",onCheckedChange:u,form:d,...f}=e,[h,p]=m.useState(null),v=He(t,S=>p(S)),x=m.useRef(!1),g=h?d||!!h.closest("form"):!0,[y,b]=cr({prop:o,defaultProp:s??!1,onChange:u,caller:ni});return c.jsxs(MC,{scope:n,checked:y,disabled:a,children:[c.jsx(Ae.button,{type:"button",role:"switch","aria-checked":y,"aria-required":i,"data-state":Cp(y),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:v,onClick:ue(e.onClick,S=>{b(I=>!I),g&&(x.current=S.isPropagationStopped(),x.current||S.stopPropagation())})}),g&&c.jsx(Sp,{control:h,bubbles:!x.current,name:r,value:l,checked:y,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});vp.displayName=ni;var bp="SwitchThumb",wp=m.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=DC(bp,n);return c.jsx(Ae.span,{"data-state":Cp(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});wp.displayName=bp;var LC="SwitchBubbleInput",Sp=m.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=m.useRef(null),a=He(i,s),l=yp(n),u=Pf(t);return m.useEffect(()=>{const d=i.current;if(!d)return;const f=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(f,"checked").set;if(l!==n&&p){const v=new Event("click",{bubbles:r});p.call(d,n),d.dispatchEvent(v)}},[l,n,r]),c.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:n,...o,tabIndex:-1,ref:a,style:{...o.style,...u,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});Sp.displayName=LC;function Cp(e){return e?"checked":"unchecked"}var Tp=vp,$C=wp;const Gn=m.forwardRef(({className:e,...t},n)=>c.jsx(Tp,{className:ee("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,ref:n,children:c.jsx($C,{className:ee("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}));Gn.displayName=Tp.displayName;var kp=Object.freeze({position:"absolute",border:0,width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",wordWrap:"normal"}),FC="VisuallyHidden",zC=m.forwardRef((e,t)=>c.jsx(Ae.span,{...e,ref:t,style:{...kp,...e.style}}));zC.displayName=FC;var BC=[" ","Enter","ArrowUp","ArrowDown"],HC=[" ","Enter"],xr="Select",[ri,oi,UC]=Ra(xr),[Fr,lk]=yn(xr,[UC,Ws]),si=Ws(),[WC,Yn]=Fr(xr),[VC,KC]=Fr(xr),Ep=e=>{const{__scopeSelect:t,children:n,open:r,defaultOpen:o,onOpenChange:s,value:i,defaultValue:a,onValueChange:l,dir:u,name:d,autoComplete:f,disabled:h,required:p,form:v}=e,x=si(t),[g,y]=m.useState(null),[b,S]=m.useState(null),[I,C]=m.useState(!1),T=Ps(u),[E,A]=cr({prop:r,defaultProp:o??!1,onChange:s,caller:xr}),[j,P]=cr({prop:i,defaultProp:a,onChange:l,caller:xr}),D=m.useRef(null),L=g?v||!!g.closest("form"):!0,[V,M]=m.useState(new Set),X=Array.from(V).map(K=>K.props.value).join(";");return c.jsx(Uf,{...x,children:c.jsxs(WC,{required:p,scope:t,trigger:g,onTriggerChange:y,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:I,onValueNodeHasChildrenChange:C,contentId:vn(),value:j,onValueChange:P,open:E,onOpenChange:A,dir:T,triggerPointerDownPosRef:D,disabled:h,children:[c.jsx(ri.Provider,{scope:t,children:c.jsx(VC,{scope:e.__scopeSelect,onNativeOptionAdd:m.useCallback(K=>{M(q=>new Set(q).add(K))},[]),onNativeOptionRemove:m.useCallback(K=>{M(q=>{const z=new Set(q);return z.delete(K),z})},[]),children:n})}),L?c.jsxs(Xp,{"aria-hidden":!0,required:p,tabIndex:-1,name:d,autoComplete:f,value:j,onChange:K=>P(K.target.value),disabled:h,form:v,children:[j===void 0?c.jsx("option",{value:""}):null,Array.from(V)]},X):null]})})};Ep.displayName=xr;var Ip="SelectTrigger",Np=m.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=si(n),i=Yn(Ip,n),a=i.disabled||r,l=He(t,i.onTriggerChange),u=oi(n),d=m.useRef("touch"),[f,h,p]=Zp(x=>{const g=u().filter(S=>!S.disabled),y=g.find(S=>S.value===i.value),b=Qp(g,x,y);b!==void 0&&i.onValueChange(b.value)}),v=x=>{a||(i.onOpenChange(!0),p()),x&&(i.triggerPointerDownPosRef.current={x:Math.round(x.pageX),y:Math.round(x.pageY)})};return c.jsx(Wf,{asChild:!0,...s,children:c.jsx(Ae.button,{type:"button",role:"combobox","aria-controls":i.contentId,"aria-expanded":i.open,"aria-required":i.required,"aria-autocomplete":"none",dir:i.dir,"data-state":i.open?"open":"closed",disabled:a,"data-disabled":a?"":void 0,"data-placeholder":Jp(i.value)?"":void 0,...o,ref:l,onClick:ue(o.onClick,x=>{x.currentTarget.focus(),d.current!=="mouse"&&v(x)}),onPointerDown:ue(o.onPointerDown,x=>{d.current=x.pointerType;const g=x.target;g.hasPointerCapture(x.pointerId)&&g.releasePointerCapture(x.pointerId),x.button===0&&x.ctrlKey===!1&&x.pointerType==="mouse"&&(v(x),x.preventDefault())}),onKeyDown:ue(o.onKeyDown,x=>{const g=f.current!=="";!(x.ctrlKey||x.altKey||x.metaKey)&&x.key.length===1&&h(x.key),!(g&&x.key===" ")&&BC.includes(x.key)&&(v(),x.preventDefault())})})})});Np.displayName=Ip;var Ap="SelectValue",_p=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Yn(Ap,n),{onValueNodeHasChildrenChange:u}=l,d=s!==void 0,f=He(t,l.onValueNodeChange);return bt(()=>{u(d)},[u,d]),c.jsx(Ae.span,{...a,ref:f,style:{pointerEvents:"none"},children:Jp(l.value)?c.jsx(c.Fragment,{children:i}):s})});_p.displayName=Ap;var qC="SelectIcon",jp=m.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return c.jsx(Ae.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});jp.displayName=qC;var GC="SelectPortal",Rp=e=>c.jsx(xs,{asChild:!0,...e});Rp.displayName=GC;var yr="SelectContent",Pp=m.forwardRef((e,t)=>{const n=Yn(yr,e.__scopeSelect),[r,o]=m.useState();if(bt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?Ao.createPortal(c.jsx(Op,{scope:e.__scopeSelect,children:c.jsx(ri.Slot,{scope:e.__scopeSelect,children:c.jsx("div",{children:e.children})})}),s):null}return c.jsx(Mp,{...e,ref:t})});Pp.displayName=yr;var un=10,[Op,Xn]=Fr(yr),YC="SelectContentImpl",XC=tr.createSlot("SelectContent.RemoveScroll"),Mp=m.forwardRef((e,t)=>{const{__scopeSelect:n,position:r="item-aligned",onCloseAutoFocus:o,onEscapeKeyDown:s,onPointerDownOutside:i,side:a,sideOffset:l,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:v,hideWhenDetached:x,avoidCollisions:g,...y}=e,b=Yn(yr,n),[S,I]=m.useState(null),[C,T]=m.useState(null),E=He(t,G=>I(G)),[A,j]=m.useState(null),[P,D]=m.useState(null),L=oi(n),[V,M]=m.useState(!1),X=m.useRef(!1);m.useEffect(()=>{if(S)return Ea(S)},[S]),ba();const K=m.useCallback(G=>{const[O,...Q]=L().map(ae=>ae.ref.current),[ne]=Q.slice(-1),de=document.activeElement;for(const ae of G)if(ae===de||(ae==null||ae.scrollIntoView({block:"nearest"}),ae===O&&C&&(C.scrollTop=0),ae===ne&&C&&(C.scrollTop=C.scrollHeight),ae==null||ae.focus(),document.activeElement!==de))return},[L,C]),q=m.useCallback(()=>K([A,S]),[K,A,S]);m.useEffect(()=>{V&&q()},[V,q]);const{onOpenChange:z,triggerPointerDownPosRef:$}=b;m.useEffect(()=>{if(S){let G={x:0,y:0};const O=ne=>{var de,ae;G={x:Math.abs(Math.round(ne.pageX)-(((de=$.current)==null?void 0:de.x)??0)),y:Math.abs(Math.round(ne.pageY)-(((ae=$.current)==null?void 0:ae.y)??0))}},Q=ne=>{G.x<=10&&G.y<=10?ne.preventDefault():S.contains(ne.target)||z(!1),document.removeEventListener("pointermove",O),$.current=null};return $.current!==null&&(document.addEventListener("pointermove",O),document.addEventListener("pointerup",Q,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",O),document.removeEventListener("pointerup",Q,{capture:!0})}}},[S,z,$]),m.useEffect(()=>{const G=()=>z(!1);return window.addEventListener("blur",G),window.addEventListener("resize",G),()=>{window.removeEventListener("blur",G),window.removeEventListener("resize",G)}},[z]);const[pe,F]=Zp(G=>{const O=L().filter(de=>!de.disabled),Q=O.find(de=>de.ref.current===document.activeElement),ne=Qp(O,G,Q);ne&&setTimeout(()=>ne.ref.current.focus())}),te=m.useCallback((G,O,Q)=>{const ne=!X.current&&!Q;(b.value!==void 0&&b.value===O||ne)&&(j(G),ne&&(X.current=!0))},[b.value]),fe=m.useCallback(()=>S==null?void 0:S.focus(),[S]),ge=m.useCallback((G,O,Q)=>{const ne=!X.current&&!Q;(b.value!==void 0&&b.value===O||ne)&&D(G)},[b.value]),be=r==="popper"?cl:Dp,Te=be===cl?{side:a,sideOffset:l,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:v,hideWhenDetached:x,avoidCollisions:g}:{};return c.jsx(Op,{scope:n,content:S,viewport:C,onViewportChange:T,itemRefCallback:te,selectedItem:A,onItemLeave:fe,itemTextRefCallback:ge,focusSelectedItem:q,selectedItemText:P,position:r,isPositioned:V,searchRef:pe,children:c.jsx(Cs,{as:XC,allowPinchZoom:!0,children:c.jsx(gs,{asChild:!0,trapped:b.open,onMountAutoFocus:G=>{G.preventDefault()},onUnmountAutoFocus:ue(o,G=>{var O;(O=b.trigger)==null||O.focus({preventScroll:!0}),G.preventDefault()}),children:c.jsx(ms,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:G=>G.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:c.jsx(be,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:G=>G.preventDefault(),...y,...Te,onPlaced:()=>M(!0),ref:E,style:{display:"flex",flexDirection:"column",outline:"none",...y.style},onKeyDown:ue(y.onKeyDown,G=>{const O=G.ctrlKey||G.altKey||G.metaKey;if(G.key==="Tab"&&G.preventDefault(),!O&&G.key.length===1&&F(G.key),["ArrowUp","ArrowDown","Home","End"].includes(G.key)){let ne=L().filter(de=>!de.disabled).map(de=>de.ref.current);if(["ArrowUp","End"].includes(G.key)&&(ne=ne.slice().reverse()),["ArrowUp","ArrowDown"].includes(G.key)){const de=G.target,ae=ne.indexOf(de);ne=ne.slice(ae+1)}setTimeout(()=>K(ne)),G.preventDefault()}})})})})})})});Mp.displayName=YC;var JC="SelectItemAlignedPosition",Dp=m.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Yn(yr,n),i=Xn(yr,n),[a,l]=m.useState(null),[u,d]=m.useState(null),f=He(t,E=>d(E)),h=oi(n),p=m.useRef(!1),v=m.useRef(!0),{viewport:x,selectedItem:g,selectedItemText:y,focusSelectedItem:b}=i,S=m.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&u&&x&&g&&y){const E=s.trigger.getBoundingClientRect(),A=u.getBoundingClientRect(),j=s.valueNode.getBoundingClientRect(),P=y.getBoundingClientRect();if(s.dir!=="rtl"){const de=P.left-A.left,ae=j.left-de,Ue=E.left-ae,Ze=E.width+Ue,me=Math.max(Ze,A.width),Pe=window.innerWidth-un,Le=rl(ae,[un,Math.max(un,Pe-me)]);a.style.minWidth=Ze+"px",a.style.left=Le+"px"}else{const de=A.right-P.right,ae=window.innerWidth-j.right-de,Ue=window.innerWidth-E.right-ae,Ze=E.width+Ue,me=Math.max(Ze,A.width),Pe=window.innerWidth-un,Le=rl(ae,[un,Math.max(un,Pe-me)]);a.style.minWidth=Ze+"px",a.style.right=Le+"px"}const D=h(),L=window.innerHeight-un*2,V=x.scrollHeight,M=window.getComputedStyle(u),X=parseInt(M.borderTopWidth,10),K=parseInt(M.paddingTop,10),q=parseInt(M.borderBottomWidth,10),z=parseInt(M.paddingBottom,10),$=X+K+V+z+q,pe=Math.min(g.offsetHeight*5,$),F=window.getComputedStyle(x),te=parseInt(F.paddingTop,10),fe=parseInt(F.paddingBottom,10),ge=E.top+E.height/2-un,be=L-ge,Te=g.offsetHeight/2,G=g.offsetTop+Te,O=X+K+G,Q=$-O;if(O<=ge){const de=D.length>0&&g===D[D.length-1].ref.current;a.style.bottom="0px";const ae=u.clientHeight-x.offsetTop-x.offsetHeight,Ue=Math.max(be,Te+(de?fe:0)+ae+q),Ze=O+Ue;a.style.height=Ze+"px"}else{const de=D.length>0&&g===D[0].ref.current;a.style.top="0px";const Ue=Math.max(ge,X+x.offsetTop+(de?te:0)+Te)+Q;a.style.height=Ue+"px",x.scrollTop=O-ge+x.offsetTop}a.style.margin=`${un}px 0`,a.style.minHeight=pe+"px",a.style.maxHeight=L+"px",r==null||r(),requestAnimationFrame(()=>p.current=!0)}},[h,s.trigger,s.valueNode,a,u,x,g,y,s.dir,r]);bt(()=>S(),[S]);const[I,C]=m.useState();bt(()=>{u&&C(window.getComputedStyle(u).zIndex)},[u]);const T=m.useCallback(E=>{E&&v.current===!0&&(S(),b==null||b(),v.current=!1)},[S,b]);return c.jsx(QC,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:p,onScrollButtonChange:T,children:c.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:I},children:c.jsx(Ae.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Dp.displayName=JC;var ZC="SelectPopperPosition",cl=m.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=un,...s}=e,i=si(n);return c.jsx(Vf,{...i,...s,ref:t,align:r,collisionPadding:o,style:{boxSizing:"border-box",...s.style,"--radix-select-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-select-content-available-width":"var(--radix-popper-available-width)","--radix-select-content-available-height":"var(--radix-popper-available-height)","--radix-select-trigger-width":"var(--radix-popper-anchor-width)","--radix-select-trigger-height":"var(--radix-popper-anchor-height)"}})});cl.displayName=ZC;var[QC,ul]=Fr(yr,{}),dl="SelectViewport",Lp=m.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Xn(dl,n),i=ul(dl,n),a=He(t,s.onViewportChange),l=m.useRef(0);return c.jsxs(c.Fragment,{children:[c.jsx("style",{dangerouslySetInnerHTML:{__html:"[data-radix-select-viewport]{scrollbar-width:none;-ms-overflow-style:none;-webkit-overflow-scrolling:touch;}[data-radix-select-viewport]::-webkit-scrollbar{display:none}"},nonce:r}),c.jsx(ri.Slot,{scope:n,children:c.jsx(Ae.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:ue(o.onScroll,u=>{const d=u.currentTarget,{contentWrapper:f,shouldExpandOnScrollRef:h}=i;if(h!=null&&h.current&&f){const p=Math.abs(l.current-d.scrollTop);if(p>0){const v=window.innerHeight-un*2,x=parseFloat(f.style.minHeight),g=parseFloat(f.style.height),y=Math.max(x,g);if(y<v){const b=y+p,S=Math.min(v,b),I=b-S;f.style.height=S+"px",f.style.bottom==="0px"&&(d.scrollTop=I>0?I:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});Lp.displayName=dl;var $p="SelectGroup",[eT,tT]=Fr($p),nT=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=vn();return c.jsx(eT,{scope:n,id:o,children:c.jsx(Ae.div,{role:"group","aria-labelledby":o,...r,ref:t})})});nT.displayName=$p;var Fp="SelectLabel",zp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=tT(Fp,n);return c.jsx(Ae.div,{id:o.id,...r,ref:t})});zp.displayName=Fp;var ii="SelectItem",[rT,Bp]=Fr(ii),Hp=m.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Yn(ii,n),l=Xn(ii,n),u=a.value===r,[d,f]=m.useState(s??""),[h,p]=m.useState(!1),v=He(t,b=>{var S;return(S=l.itemRefCallback)==null?void 0:S.call(l,b,r,o)}),x=vn(),g=m.useRef("touch"),y=()=>{o||(a.onValueChange(r),a.onOpenChange(!1))};if(r==="")throw new Error("A <Select.Item /> must have a value prop that is not an empty string. This is because the Select value can be set to an empty string to clear the selection and show the placeholder.");return c.jsx(rT,{scope:n,value:r,disabled:o,textId:x,isSelected:u,onItemTextChange:m.useCallback(b=>{f(S=>S||((b==null?void 0:b.textContent)??"").trim())},[]),children:c.jsx(ri.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:c.jsx(Ae.div,{role:"option","aria-labelledby":x,"data-highlighted":h?"":void 0,"aria-selected":u&&h,"data-state":u?"checked":"unchecked","aria-disabled":o||void 0,"data-disabled":o?"":void 0,tabIndex:o?void 0:-1,...i,ref:v,onFocus:ue(i.onFocus,()=>p(!0)),onBlur:ue(i.onBlur,()=>p(!1)),onClick:ue(i.onClick,()=>{g.current!=="mouse"&&y()}),onPointerUp:ue(i.onPointerUp,()=>{g.current==="mouse"&&y()}),onPointerDown:ue(i.onPointerDown,b=>{g.current=b.pointerType}),onPointerMove:ue(i.onPointerMove,b=>{var S;g.current=b.pointerType,o?(S=l.onItemLeave)==null||S.call(l):g.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:ue(i.onPointerLeave,b=>{var S;b.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:ue(i.onKeyDown,b=>{var I;((I=l.searchRef)==null?void 0:I.current)!==""&&b.key===" "||(HC.includes(b.key)&&y(),b.key===" "&&b.preventDefault())})})})})});Hp.displayName=ii;var So="SelectItemText",Up=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Yn(So,n),a=Xn(So,n),l=Bp(So,n),u=KC(So,n),[d,f]=m.useState(null),h=He(t,y=>f(y),l.onItemTextChange,y=>{var b;return(b=a.itemTextRefCallback)==null?void 0:b.call(a,y,l.value,l.disabled)}),p=d==null?void 0:d.textContent,v=m.useMemo(()=>c.jsx("option",{value:l.value,disabled:l.disabled,children:p},l.value),[l.disabled,l.value,p]),{onNativeOptionAdd:x,onNativeOptionRemove:g}=u;return bt(()=>(x(v),()=>g(v)),[x,g,v]),c.jsxs(c.Fragment,{children:[c.jsx(Ae.span,{id:l.textId,...s,ref:h}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?Ao.createPortal(s.children,i.valueNode):null]})});Up.displayName=So;var Wp="SelectItemIndicator",Vp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return Bp(Wp,n).isSelected?c.jsx(Ae.span,{"aria-hidden":!0,...r,ref:t}):null});Vp.displayName=Wp;var fl="SelectScrollUpButton",Kp=m.forwardRef((e,t)=>{const n=Xn(fl,e.__scopeSelect),r=ul(fl,e.__scopeSelect),[o,s]=m.useState(!1),i=He(t,r.onScrollButtonChange);return bt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const u=l.scrollTop>0;s(u)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?c.jsx(Gp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});Kp.displayName=fl;var hl="SelectScrollDownButton",qp=m.forwardRef((e,t)=>{const n=Xn(hl,e.__scopeSelect),r=ul(hl,e.__scopeSelect),[o,s]=m.useState(!1),i=He(t,r.onScrollButtonChange);return bt(()=>{if(n.viewport&&n.isPositioned){let a=function(){const u=l.scrollHeight-l.clientHeight,d=Math.ceil(l.scrollTop)<u;s(d)};const l=n.viewport;return a(),l.addEventListener("scroll",a),()=>l.removeEventListener("scroll",a)}},[n.viewport,n.isPositioned]),o?c.jsx(Gp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});qp.displayName=hl;var Gp=m.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Xn("SelectScrollButton",n),i=m.useRef(null),a=oi(n),l=m.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return m.useEffect(()=>()=>l(),[l]),bt(()=>{var d;const u=a().find(f=>f.ref.current===document.activeElement);(d=u==null?void 0:u.ref.current)==null||d.scrollIntoView({block:"nearest"})},[a]),c.jsx(Ae.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:ue(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:ue(o.onPointerMove,()=>{var u;(u=s.onItemLeave)==null||u.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:ue(o.onPointerLeave,()=>{l()})})}),oT="SelectSeparator",Yp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return c.jsx(Ae.div,{"aria-hidden":!0,...r,ref:t})});Yp.displayName=oT;var pl="SelectArrow",sT=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=si(n),s=Yn(pl,n),i=Xn(pl,n);return s.open&&i.position==="popper"?c.jsx(Kf,{...o,...r,ref:t}):null});sT.displayName=pl;var iT="SelectBubbleInput",Xp=m.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=m.useRef(null),s=He(r,o),i=yp(t);return m.useEffect(()=>{const a=o.current;if(!a)return;const l=window.HTMLSelectElement.prototype,d=Object.getOwnPropertyDescriptor(l,"value").set;if(i!==t&&d){const f=new Event("change",{bubbles:!0});d.call(a,t),a.dispatchEvent(f)}},[i,t]),c.jsx(Ae.select,{...n,style:{...kp,...n.style},ref:s,defaultValue:t})});Xp.displayName=iT;function Jp(e){return e===""||e===void 0}function Zp(e){const t=kt(e),n=m.useRef(""),r=m.useRef(0),o=m.useCallback(i=>{const a=n.current+i;t(a),function l(u){n.current=u,window.clearTimeout(r.current),u!==""&&(r.current=window.setTimeout(()=>l(""),1e3))}(a)},[t]),s=m.useCallback(()=>{n.current="",window.clearTimeout(r.current)},[]);return m.useEffect(()=>()=>window.clearTimeout(r.current),[]),[n,o,s]}function Qp(e,t,n){const o=t.length>1&&Array.from(t).every(u=>u===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=aT(e,Math.max(s,0));o.length===1&&(i=i.filter(u=>u!==n));const l=i.find(u=>u.textValue.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function aT(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var lT=Ep,em=Np,cT=_p,uT=jp,dT=Rp,tm=Pp,fT=Lp,nm=zp,rm=Hp,hT=Up,pT=Vp,om=Kp,sm=qp,im=Yp;const am=lT,lm=cT,ml=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(em,{ref:r,className:ee("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",e),...n,children:[t,c.jsx(uT,{asChild:!0,children:c.jsx(ie.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));ml.displayName=em.displayName;const cm=m.forwardRef(({className:e,...t},n)=>c.jsx(om,{ref:n,className:ee("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(ie.ChevronUp,{className:"h-4 w-4"})}));cm.displayName=om.displayName;const um=m.forwardRef(({className:e,...t},n)=>c.jsx(sm,{ref:n,className:ee("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(ie.ChevronDown,{className:"h-4 w-4"})}));um.displayName=sm.displayName;const gl=m.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>c.jsx(dT,{children:c.jsxs(tm,{ref:o,className:ee("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[c.jsx(cm,{}),c.jsx(fT,{className:ee("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),c.jsx(um,{})]})}));gl.displayName=tm.displayName;const mT=m.forwardRef(({className:e,...t},n)=>c.jsx(nm,{ref:n,className:ee("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));mT.displayName=nm.displayName;const vr=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(rm,{ref:r,className:ee("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(pT,{children:c.jsx(ie.Check,{className:"h-4 w-4"})})}),c.jsx(hT,{children:t})]}));vr.displayName=rm.displayName;const gT=m.forwardRef(({className:e,...t},n)=>c.jsx(im,{ref:n,className:ee("-mx-1 my-1 h-px bg-muted",e),...t}));gT.displayName=im.displayName;var xT="Separator",dm="horizontal",yT=["horizontal","vertical"],fm=m.forwardRef((e,t)=>{const{decorative:n,orientation:r=dm,...o}=e,s=vT(r)?r:dm,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return c.jsx(Ae.div,{"data-orientation":s,...a,...o,ref:t})});fm.displayName=xT;function vT(e){return yT.includes(e)}var hm=fm;const pm=m.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>c.jsx(hm,{ref:o,decorative:n,orientation:t,className:ee("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));pm.displayName=hm.displayName;const bT=Xd,wT=ew,ST=Jd,mm=m.forwardRef(({className:e,...t},n)=>c.jsx(Ns,{className:ee("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",e),...t,ref:n}));mm.displayName=Ns.displayName;const CT=No.cva("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm"}},defaultVariants:{side:"right"}}),gm=m.forwardRef(({side:e="right",className:t,children:n,...r},o)=>c.jsxs(ST,{children:[c.jsx(mm,{}),c.jsxs(As,{ref:o,className:ee(CT({side:e}),t),...r,children:[n,c.jsxs(Zd,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[c.jsx(ie.X,{className:"h-4 w-4"}),c.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));gm.displayName=As.displayName;const xm=({className:e,...t})=>c.jsx("div",{className:ee("flex flex-col space-y-2 text-center sm:text-left",e),...t});xm.displayName="SheetHeader";const ym=m.forwardRef(({className:e,...t},n)=>c.jsx(fr,{ref:n,className:ee("text-lg font-semibold text-foreground",e),...t}));ym.displayName=fr.displayName;const vm=m.forwardRef(({className:e,...t},n)=>c.jsx(_s,{ref:n,className:ee("text-sm text-muted-foreground",e),...t}));vm.displayName=_s.displayName;const TT={api:{baseUrl:"http://localhost:8000/api",authToken:"",enableAuth:!1},ui:{layout:"sidebar",theme:"light",showTimestamps:!0,showAgentNames:!0,compactMessages:!1},behavior:{autoSave:!0,enableStreaming:!0,showTypingIndicator:!0}};function kT({settings:e,onSettingsChange:t,className:n=""}){const[r,o]=w.useState(!1),[s,i]=w.useState(!1),[a,l]=w.useState(e),[u,d]=w.useState(!1),{toast:f}=ma();w.useEffect(()=>{const g=JSON.stringify(a)!==JSON.stringify(e);d(g)},[a,e]),w.useEffect(()=>{l(e)},[e]);const h=()=>{t(a),d(!1),f({title:"Settings saved",description:"Your chat configuration has been updated successfully."})},p=()=>{l(TT),d(!0),f({title:"Settings reset",description:"Configuration has been reset to defaults."})},v=()=>{l(e),d(!1),o(!1)},x=async()=>{try{const y=await(await fetch(`${a.api.baseUrl}/health`)).json();f({title:"Connection successful",description:`API is ${y.status||"healthy"}`})}catch{f({title:"Connection failed",description:"Unable to connect to the API endpoint.",variant:"destructive"})}};return c.jsxs(bT,{open:r,onOpenChange:o,children:[c.jsx(wT,{asChild:!0,children:c.jsxs(Ke,{variant:"outline",size:"sm",className:n,children:[c.jsx(ie.Settings,{className:"h-4 w-4 mr-2"}),"Settings",u&&c.jsx(sa,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),c.jsxs(gm,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[c.jsxs(xm,{children:[c.jsx(ym,{children:"Chat Settings"}),c.jsx(vm,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),c.jsxs("div",{className:"space-y-6 py-6",children:[c.jsxs(ao,{children:[c.jsx(lo,{className:"pb-3",children:c.jsxs(co,{className:"text-lg flex items-center gap-2",children:[c.jsx(ie.Server,{className:"h-5 w-5"}),"API Configuration"]})}),c.jsxs(ls,{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(Qt,{htmlFor:"api-url",children:"API Base URL"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Js,{id:"api-url",value:a.api.baseUrl,onChange:g=>l(y=>({...y,api:{...y.api,baseUrl:g.target.value}})),placeholder:"http://localhost:8000/api"}),c.jsx(Ke,{variant:"outline",onClick:x,children:"Test"})]})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Qt,{htmlFor:"enable-auth",children:"Enable Authentication"}),c.jsx(Gn,{id:"enable-auth",checked:a.api.enableAuth,onCheckedChange:g=>l(y=>({...y,api:{...y.api,enableAuth:g}}))})]}),a.api.enableAuth&&c.jsxs("div",{className:"space-y-2",children:[c.jsx(Qt,{htmlFor:"auth-token",children:"Authentication Token"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Js,{id:"auth-token",type:s?"text":"password",value:a.api.authToken,onChange:g=>l(y=>({...y,api:{...y.api,authToken:g.target.value}})),placeholder:"Enter your Bearer token"}),c.jsx(Ke,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?c.jsx(ie.EyeOff,{className:"h-4 w-4"}):c.jsx(ie.Eye,{className:"h-4 w-4"})})]})]})]})]}),c.jsxs(ao,{children:[c.jsx(lo,{className:"pb-3",children:c.jsxs(co,{className:"text-lg flex items-center gap-2",children:[c.jsx(ie.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),c.jsxs(ls,{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(Qt,{htmlFor:"layout",children:"Layout Style"}),c.jsxs(am,{value:a.ui.layout,onValueChange:g=>l(y=>({...y,ui:{...y.ui,layout:g}})),children:[c.jsx(ml,{children:c.jsx(lm,{})}),c.jsxs(gl,{children:[c.jsx(vr,{value:"sidebar",children:"Sidebar Layout"}),c.jsx(vr,{value:"fullscreen",children:"Fullscreen"}),c.jsx(vr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(Qt,{htmlFor:"theme",children:"Theme"}),c.jsxs(am,{value:a.ui.theme,onValueChange:g=>l(y=>({...y,ui:{...y.ui,theme:g}})),children:[c.jsx(ml,{children:c.jsx(lm,{})}),c.jsxs(gl,{children:[c.jsx(vr,{value:"light",children:"Light"}),c.jsx(vr,{value:"dark",children:"Dark"}),c.jsx(vr,{value:"system",children:"System"})]})]})]}),c.jsx(pm,{}),c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Qt,{htmlFor:"show-timestamps",children:"Show Timestamps"}),c.jsx(Gn,{id:"show-timestamps",checked:a.ui.showTimestamps,onCheckedChange:g=>l(y=>({...y,ui:{...y.ui,showTimestamps:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Qt,{htmlFor:"show-agent-names",children:"Show Agent Names"}),c.jsx(Gn,{id:"show-agent-names",checked:a.ui.showAgentNames,onCheckedChange:g=>l(y=>({...y,ui:{...y.ui,showAgentNames:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(Qt,{htmlFor:"compact-messages",children:"Compact Messages"}),c.jsx(Gn,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:g=>l(y=>({...y,ui:{...y.ui,compactMessages:g}}))})]})]})]})]}),c.jsxs(ao,{children:[c.jsx(lo,{className:"pb-3",children:c.jsxs(co,{className:"text-lg flex items-center gap-2",children:[c.jsx(ie.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),c.jsxs(ls,{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(Qt,{htmlFor:"auto-save",children:"Auto-save Conversations"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),c.jsx(Gn,{id:"auto-save",checked:a.behavior.autoSave,onCheckedChange:g=>l(y=>({...y,behavior:{...y.behavior,autoSave:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(Qt,{htmlFor:"enable-streaming",children:"Enable Streaming"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),c.jsx(Gn,{id:"enable-streaming",checked:a.behavior.enableStreaming,onCheckedChange:g=>l(y=>({...y,behavior:{...y.behavior,enableStreaming:g}}))})]}),c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(Qt,{htmlFor:"typing-indicator",children:"Typing Indicator"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),c.jsx(Gn,{id:"typing-indicator",checked:a.behavior.showTypingIndicator,onCheckedChange:g=>l(y=>({...y,behavior:{...y.behavior,showTypingIndicator:g}}))})]})]})]})]}),c.jsxs("div",{className:"flex items-center justify-between pt-6 border-t",children:[c.jsxs(Ke,{variant:"outline",onClick:p,children:[c.jsx(ie.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Ke,{variant:"outline",onClick:v,children:"Cancel"}),c.jsxs(Ke,{onClick:h,disabled:!u,children:[c.jsx(ie.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function ET({layout:e="sidebar",layoutSize:t="desktop",showThreads:n=!0,className:r="",customStyles:o={},...s}){const i=u=>{const d="h-full";switch(u){case"phone":return`${d} max-w-none`;case"tablet":return`${d} max-w-4xl mx-auto`;case"half-screen":return`${d} max-w-2xl`;case"desktop":default:return`${d} max-w-7xl mx-auto`}},a=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=w.useCallback(u=>{var d;(d=s.onThreadChange)==null||d.call(s,u)},[s]);return e==="fullscreen"?c.jsx(Ko,{...s,onThreadChange:l,children:c.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:c.jsx(Xs,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?c.jsx(Ko,{...s,onThreadChange:l,children:c.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:c.jsxs("div",{className:"flex-1 flex min-h-0 overflow-hidden",children:[n&&c.jsx("div",{className:`w-80 border-r flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:c.jsx(ll,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),c.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:c.jsx(Xs,{onError:s.onError,enableFileUpload:!0})})]})})}):c.jsx(Ko,{...s,onThreadChange:l,children:c.jsxs("div",{className:`${i(t)} flex overflow-hidden ${r} ${o.container||""}`,style:a(t),children:[n&&c.jsx("div",{className:`w-80 border-r bg-gray-50 flex-shrink-0 overflow-hidden ${o.sidebar||""}`,children:c.jsx(ll,{showCreateButton:!0,showDeleteButton:!0,showEditTitle:!0,className:"h-full"})}),c.jsx("div",{className:`flex-1 min-w-0 overflow-hidden ${o.chatArea||""}`,children:c.jsx(Xs,{onError:s.onError,enableFileUpload:!0})})]})})}_e.ChatApi=mc,_e.ChatInterface=Xs,_e.ChatProviders=Ko,_e.ChatSettings=kT,_e.MarkdownContent=fa,_e.MessageComponent=lf,_e.MessageList=ja,_e.ThreadManager=ll,_e.applySettings=jC,_e.chatApiClient=$n,_e.default=ET,_e.del=pc,_e.get=pn,_e.getChatToken=uc,_e.getCurrentSettings=_C,_e.getDefaultApiConfig=hp,_e.getDefaultChatSettings=pp,_e.onChatTokenChanged=dc,_e.post=fc,_e.put=hc,_e.setChatToken=Ti,_e.useApi=ki,_e.useChatStream=Rc,_e.useMessagesReducer=Cc,_e.useStream=zc,_e.useThreadState=Vo,_e.useThreads=Wo,Object.defineProperties(_e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|