teodor-new-chat-ui 4.3.45 → 4.3.46
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 +4509 -4448
- package/dist/index.umd.js +39 -38
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(Ae,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):(Ae=typeof globalThis<"u"?globalThis:Ae||self,w(Ae.NewChatUI={},Ae.React,Ae.LucideReact,Ae.reactSlot,Ae.classVarianceAuthority,Ae.clsx,Ae.tailwindMerge,Ae.ReactDOM))})(this,function(Ae,w,he,rr,Po,Tm,Em,pi){"use strict";var Jk=Object.defineProperty;var Zk=(Ae,w,he)=>w in Ae?Jk(Ae,w,{enumerable:!0,configurable:!0,writable:!0,value:he}):Ae[w]=he;var Cm=(Ae,w,he)=>Zk(Ae,typeof w!="symbol"?w+"":w,he);function kl(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=kl(w),Oo=kl(pi);var mi={exports:{}},Kr={};/**
|
|
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 Tl;function Im(){if(Tl)return
|
|
9
|
+
*/var Tl;function Im(){if(Tl)return Kr;Tl=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 Kr.Fragment=n,Kr.jsx=i,Kr.jsxs=i,Kr}var qr={};/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,41 +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 El;function Am(){return El||(El=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(
|
|
18
|
-
`+
|
|
19
|
-
`),
|
|
20
|
-
`),
|
|
21
|
-
`+Oe[
|
|
17
|
+
*/var El;function Am(){return El||(El=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(C){if(C===null||typeof C!="object")return null;var P=v&&C[v]||C[x];return typeof P=="function"?P:null}var y=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(C){{for(var P=arguments.length,H=new Array(P>1?P-1:0),ie=1;ie<P;ie++)H[ie-1]=arguments[ie];S("error",C,H)}}function S(C,P,H){{var ie=y.ReactDebugCurrentFrame,ke=ie.getStackAddendum();ke!==""&&(P+="%s",H=H.concat([ke]));var Ne=H.map(function(De){return String(De)});Ne.unshift("Warning: "+P),Function.prototype.apply.call(console[C],console,Ne)}}var E=!1,k=!1,T=!1,I=!1,_=!1,O;O=Symbol.for("react.module.reference");function j(C){return!!(typeof C=="string"||typeof C=="function"||C===r||C===s||_||C===o||C===u||C===d||I||C===p||E||k||T||typeof C=="object"&&C!==null&&(C.$$typeof===h||C.$$typeof===f||C.$$typeof===i||C.$$typeof===a||C.$$typeof===l||C.$$typeof===O||C.getModuleId!==void 0))}function U(C,P,H){var ie=C.displayName;if(ie)return ie;var ke=P.displayName||P.name||"";return ke!==""?H+"("+ke+")":H}function L(C){return C.displayName||"Context"}function W(C){if(C==null)return null;if(typeof C.tag=="number"&&b("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof C=="function")return C.displayName||C.name||null;if(typeof C=="string")return C;switch(C){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 C=="object")switch(C.$$typeof){case a:var P=C;return L(P)+".Consumer";case i:var H=C;return L(H._context)+".Provider";case l:return U(C,C.render,"ForwardRef");case f:var ie=C.displayName||null;return ie!==null?ie:W(C.type)||"Memo";case h:{var ke=C,Ne=ke._payload,De=ke._init;try{return W(De(Ne))}catch{return null}}}return null}var R=Object.assign,V=0,$,ne,F,B,le,z,oe;function pe(){}pe.__reactDisabledLog=!0;function ge(){{if(V===0){$=console.log,ne=console.info,F=console.warn,B=console.error,le=console.group,z=console.groupCollapsed,oe=console.groupEnd;var C={configurable:!0,enumerable:!0,value:pe,writable:!0};Object.defineProperties(console,{info:C,log:C,warn:C,error:C,group:C,groupCollapsed:C,groupEnd:C})}V++}}function me(){{if(V--,V===0){var C={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:R({},C,{value:$}),info:R({},C,{value:ne}),warn:R({},C,{value:F}),error:R({},C,{value:B}),group:R({},C,{value:le}),groupCollapsed:R({},C,{value:z}),groupEnd:R({},C,{value:oe})})}V<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var ve=y.ReactCurrentDispatcher,Z;function D(C,P,H){{if(Z===void 0)try{throw Error()}catch(ke){var ie=ke.stack.trim().match(/\n( *(at )?)/);Z=ie&&ie[1]||""}return`
|
|
18
|
+
`+Z+C}}var J=!1,Q;{var de=typeof WeakMap=="function"?WeakMap:Map;Q=new de}function ee(C,P){if(!C||J)return"";{var H=Q.get(C);if(H!==void 0)return H}var ie;J=!0;var ke=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var Ne;Ne=ve.current,ve.current=null,ge();try{if(P){var De=function(){throw Error()};if(Object.defineProperty(De.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(De,[])}catch(Ot){ie=Ot}Reflect.construct(C,[],De)}else{try{De.call()}catch(Ot){ie=Ot}C.call(De.prototype)}}else{try{throw Error()}catch(Ot){ie=Ot}C()}}catch(Ot){if(Ot&&ie&&typeof Ot.stack=="string"){for(var Oe=Ot.stack.split(`
|
|
19
|
+
`),bt=ie.stack.split(`
|
|
20
|
+
`),at=Oe.length-1,ct=bt.length-1;at>=1&&ct>=0&&Oe[at]!==bt[ct];)ct--;for(;at>=1&&ct>=0;at--,ct--)if(Oe[at]!==bt[ct]){if(at!==1||ct!==1)do if(at--,ct--,ct<0||Oe[at]!==bt[ct]){var wt=`
|
|
21
|
+
`+Oe[at].replace(" at new "," at ");return C.displayName&&wt.includes("<anonymous>")&&(wt=wt.replace("<anonymous>",C.displayName)),typeof C=="function"&&Q.set(C,wt),wt}while(at>=1&&ct>=0);break}}}finally{J=!1,ve.current=Ne,me(),Error.prepareStackTrace=ke}var Fn=C?C.displayName||C.name:"",$n=Fn?D(Fn):"";return typeof C=="function"&&Q.set(C,$n),$n}function se(C,P,H){return ee(C,!1)}function Ge(C){var P=C.prototype;return!!(P&&P.isReactComponent)}function Ye(C,P,H){if(C==null)return"";if(typeof C=="function")return ee(C,Ge(C));if(typeof C=="string")return D(C);switch(C){case u:return D("Suspense");case d:return D("SuspenseList")}if(typeof C=="object")switch(C.$$typeof){case l:return se(C.render);case f:return Ye(C.type,P,H);case h:{var ie=C,ke=ie._payload,Ne=ie._init;try{return Ye(Ne(ke),P,H)}catch{}}}return""}var Pe=Object.prototype.hasOwnProperty,He={},nt=y.ReactDebugCurrentFrame;function Qe(C){if(C){var P=C._owner,H=Ye(C.type,C._source,P?P.type:null);nt.setExtraStackFrame(H)}else nt.setExtraStackFrame(null)}function je(C,P,H,ie,ke){{var Ne=Function.call.bind(Pe);for(var De in C)if(Ne(C,De)){var Oe=void 0;try{if(typeof C[De]!="function"){var bt=Error((ie||"React class")+": "+H+" type `"+De+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof C[De]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw bt.name="Invariant Violation",bt}Oe=C[De](P,De,ie,H,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(at){Oe=at}Oe&&!(Oe instanceof Error)&&(Qe(ke),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).",ie||"React class",H,De,typeof Oe),Qe(null)),Oe instanceof Error&&!(Oe.message in He)&&(He[Oe.message]=!0,Qe(ke),b("Failed %s type: %s",H,Oe.message),Qe(null))}}}var pt=Array.isArray;function xt(C){return pt(C)}function yt(C){{var P=typeof Symbol=="function"&&Symbol.toStringTag,H=P&&C[Symbol.toStringTag]||C.constructor.name||"Object";return H}}function st(C){try{return Xe(C),!1}catch{return!0}}function Xe(C){return""+C}function G(C){if(st(C))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",yt(C)),Xe(C)}var be=y.ReactCurrentOwner,ye={key:!0,ref:!0,__self:!0,__source:!0},Ie,Je;function Ze(C){if(Pe.call(C,"ref")){var P=Object.getOwnPropertyDescriptor(C,"ref").get;if(P&&P.isReactWarning)return!1}return C.ref!==void 0}function kt(C){if(Pe.call(C,"key")){var P=Object.getOwnPropertyDescriptor(C,"key").get;if(P&&P.isReactWarning)return!1}return C.key!==void 0}function zt(C,P){typeof C.ref=="string"&&be.current}function Ur(C,P){{var H=function(){Ie||(Ie=!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)",P))};H.isReactWarning=!0,Object.defineProperty(C,"key",{get:H,configurable:!0})}}function Ln(C,P){{var H=function(){Je||(Je=!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)",P))};H.isReactWarning=!0,Object.defineProperty(C,"ref",{get:H,configurable:!0})}}var qt=function(C,P,H,ie,ke,Ne,De){var Oe={$$typeof:t,type:C,key:P,ref:H,props:De,_owner:Ne};return Oe._store={},Object.defineProperty(Oe._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(Oe,"_self",{configurable:!1,enumerable:!1,writable:!1,value:ie}),Object.defineProperty(Oe,"_source",{configurable:!1,enumerable:!1,writable:!1,value:ke}),Object.freeze&&(Object.freeze(Oe.props),Object.freeze(Oe)),Oe};function hn(C,P,H,ie,ke){{var Ne,De={},Oe=null,bt=null;H!==void 0&&(G(H),Oe=""+H),kt(P)&&(G(P.key),Oe=""+P.key),Ze(P)&&(bt=P.ref,zt(P,ke));for(Ne in P)Pe.call(P,Ne)&&!ye.hasOwnProperty(Ne)&&(De[Ne]=P[Ne]);if(C&&C.defaultProps){var at=C.defaultProps;for(Ne in at)De[Ne]===void 0&&(De[Ne]=at[Ne])}if(Oe||bt){var ct=typeof C=="function"?C.displayName||C.name||"Unknown":C;Oe&&Ur(De,ct),bt&&Ln(De,ct)}return qt(C,Oe,bt,ke,ie,be.current,De)}}var Pt=y.ReactCurrentOwner,Qn=y.ReactDebugCurrentFrame;function nn(C){if(C){var P=C._owner,H=Ye(C.type,C._source,P?P.type:null);Qn.setExtraStackFrame(H)}else Qn.setExtraStackFrame(null)}var Tt;Tt=!1;function Cr(C){return typeof C=="object"&&C!==null&&C.$$typeof===t}function er(){{if(Pt.current){var C=W(Pt.current.type);if(C)return`
|
|
22
22
|
|
|
23
|
-
Check the render method of \``+
|
|
23
|
+
Check the render method of \``+C+"`."}return""}}function vt(C){return""}var rn={};function pn(C){{var P=er();if(!P){var H=typeof C=="string"?C:C.displayName||C.name;H&&(P=`
|
|
24
24
|
|
|
25
|
-
Check the top-level render call using <`+
|
|
25
|
+
Check the top-level render call using <`+H+">.")}return P}}function kr(C,P){{if(!C._store||C._store.validated||C.key!=null)return;C._store.validated=!0;var H=pn(P);if(rn[H])return;rn[H]=!0;var ie="";C&&C._owner&&C._owner!==Pt.current&&(ie=" It was passed a child from "+W(C._owner.type)+"."),nn(C),b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',H,ie),nn(null)}}function Gt(C,P){{if(typeof C!="object")return;if(xt(C))for(var H=0;H<C.length;H++){var ie=C[H];Cr(ie)&&kr(ie,P)}else if(Cr(C))C._store&&(C._store.validated=!0);else if(C){var ke=g(C);if(typeof ke=="function"&&ke!==C.entries)for(var Ne=ke.call(C),De;!(De=Ne.next()).done;)Cr(De.value)&&kr(De.value,P)}}}function Tr(C){{var P=C.type;if(P==null||typeof P=="string")return;var H;if(typeof P=="function")H=P.propTypes;else if(typeof P=="object"&&(P.$$typeof===l||P.$$typeof===f))H=P.propTypes;else return;if(H){var ie=W(P);je(H,C.props,"prop",ie,C)}else if(P.PropTypes!==void 0&&!Tt){Tt=!0;var ke=W(P);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",ke||"Unknown")}typeof P.getDefaultProps=="function"&&!P.getDefaultProps.isReactClassApproved&&b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Nn(C){{for(var P=Object.keys(C.props),H=0;H<P.length;H++){var ie=P[H];if(ie!=="children"&&ie!=="key"){nn(C),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",ie),nn(null);break}}C.ref!==null&&(nn(C),b("Invalid attribute `ref` supplied to `React.Fragment`."),nn(null))}}var mn={};function tr(C,P,H,ie,ke,Ne){{var De=j(C);if(!De){var Oe="";(C===void 0||typeof C=="object"&&C!==null&&Object.keys(C).length===0)&&(Oe+=" 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 bt=vt();bt?Oe+=bt:Oe+=er();var at;C===null?at="null":xt(C)?at="array":C!==void 0&&C.$$typeof===t?(at="<"+(W(C.type)||"Unknown")+" />",Oe=" Did you accidentally export a JSX literal instead of a component?"):at=typeof C,b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",at,Oe)}var ct=hn(C,P,H,ke,Ne);if(ct==null)return ct;if(De){var wt=P.children;if(wt!==void 0)if(ie)if(xt(wt)){for(var Fn=0;Fn<wt.length;Fn++)Gt(wt[Fn],C);Object.freeze&&Object.freeze(wt)}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 Gt(wt,C)}if(Pe.call(P,"key")){var $n=W(C),Ot=Object.keys(P).filter(function(N){return N!=="key"}),No=Ot.length>0?"{key: someKey, "+Ot.join(": ..., ")+": ...}":"{key: someKey}";if(!mn[$n+No]){var A=Ot.length>0?"{"+Ot.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} />`,Ao,Bn,A,Bn),xn[Bn+Ao]=!0}}return S===r?jn(ht):Tr(ht),ht}}function Io(S,R,B){return nr(S,R,B,!0)}function Ur(S,R,B){return nr(S,R,B,!1)}var Wr=Ur,rr=Io;Kr.Fragment=r,Kr.jsx=Wr,Kr.jsxs=rr}()),Kr}process.env.NODE_ENV==="production"?mi.exports=Im():mi.exports=Am();var c=mi.exports;function Il(e,t){return function(){return e.apply(t,arguments)}}const{toString:Nm}=Object.prototype,{getPrototypeOf:gi}=Object,{iterator:Oo,toStringTag:Al}=Symbol,Mo=(e=>t=>{const n=Nm.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),ln=e=>(e=e.toLowerCase(),t=>Mo(t)===e),Do=e=>t=>typeof t===e,{isArray:Er}=Array,Ir=Do("undefined");function qr(e){return e!==null&&!Ir(e)&&e.constructor!==null&&!Ir(e.constructor)&&Ht(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Nl=ln("ArrayBuffer");function _m(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Nl(e.buffer),t}const jm=Do("string"),Ht=Do("function"),_l=Do("number"),Gr=e=>e!==null&&typeof e=="object",Rm=e=>e===!0||e===!1,Lo=e=>{if(Mo(e)!=="object")return!1;const t=gi(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Al in e)&&!(Oo in e)},Pm=e=>{if(!Gr(e)||qr(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Om=ln("Date"),Mm=ln("File"),Dm=ln("Blob"),Lm=ln("FileList"),Fm=e=>Gr(e)&&Ht(e.pipe),$m=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||Ht(e.append)&&((t=Mo(e))==="formdata"||t==="object"&&Ht(e.toString)&&e.toString()==="[object FormData]"))},zm=ln("URLSearchParams"),[Bm,Hm,Um,Wm]=["ReadableStream","Request","Response","Headers"].map(ln),Vm=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Yr(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),Er(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(qr(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 jl(e,t){if(qr(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 sr=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,Rl=e=>!Ir(e)&&e!==sr;function xi(){const{caseless:e,skipUndefined:t}=Rl(this)&&this||{},n={},r=(o,s)=>{const i=e&&jl(n,s)||s;Lo(n[i])&&Lo(o)?n[i]=xi(n[i],o):Lo(o)?n[i]=xi({},o):Er(o)?n[i]=o.slice():(!t||!Ir(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&Yr(arguments[o],r);return n}const Km=(e,t,n,{allOwnKeys:r}={})=>(Yr(t,(o,s)=>{n&&Ht(o)?e[s]=Il(o,n):e[s]=o},{allOwnKeys:r}),e),qm=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),Gm=(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)},Ym=(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&&gi(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},Xm=(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},Jm=e=>{if(!e)return null;if(Er(e))return e;let t=e.length;if(!_l(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},Zm=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&gi(Uint8Array)),Qm=(e,t)=>{const r=(e&&e[Oo]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},eg=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},tg=ln("HTMLFormElement"),ng=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),Pl=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),rg=ln("RegExp"),Ol=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Yr(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},og=e=>{Ol(e,(t,n)=>{if(Ht(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=e[n];if(Ht(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+"'")})}})},sg=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return Er(e)?r(e):r(String(e).split(t)),n},ig=()=>{},ag=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function lg(e){return!!(e&&Ht(e.append)&&e[Al]==="FormData"&&e[Oo])}const cg=e=>{const t=new Array(10),n=(r,o)=>{if(Gr(r)){if(t.indexOf(r)>=0)return;if(qr(r))return r;if(!("toJSON"in r)){t[o]=r;const s=Er(r)?[]:{};return Yr(r,(i,a)=>{const l=n(i,o+1);!Ir(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},ug=ln("AsyncFunction"),dg=e=>e&&(Gr(e)||Ht(e))&&Ht(e.then)&&Ht(e.catch),Ml=((e,t)=>e?setImmediate:t?((n,r)=>(sr.addEventListener("message",({source:o,data:s})=>{o===sr&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),sr.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",Ht(sr.postMessage)),fg=typeof queueMicrotask<"u"?queueMicrotask.bind(sr):typeof process<"u"&&process.nextTick||Ml,O={isArray:Er,isArrayBuffer:Nl,isBuffer:qr,isFormData:$m,isArrayBufferView:_m,isString:jm,isNumber:_l,isBoolean:Rm,isObject:Gr,isPlainObject:Lo,isEmptyObject:Pm,isReadableStream:Bm,isRequest:Hm,isResponse:Um,isHeaders:Wm,isUndefined:Ir,isDate:Om,isFile:Mm,isBlob:Dm,isRegExp:rg,isFunction:Ht,isStream:Fm,isURLSearchParams:zm,isTypedArray:Zm,isFileList:Lm,forEach:Yr,merge:xi,extend:Km,trim:Vm,stripBOM:qm,inherits:Gm,toFlatObject:Ym,kindOf:Mo,kindOfTest:ln,endsWith:Xm,toArray:Jm,forEachEntry:Qm,matchAll:eg,isHTMLForm:tg,hasOwnProperty:Pl,hasOwnProp:Pl,reduceDescriptors:Ol,freezeMethods:og,toObjectSet:sg,toCamelCase:ng,noop:ig,toFiniteNumber:ag,findKey:jl,global:sr,isContextDefined:Rl,isSpecCompliantForm:lg,toJSONObject:cg,isAsyncFn:ug,isThenable:dg,setImmediate:Ml,asap:fg,isIterable:e=>e!=null&&Ht(e[Oo])};function Re(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)}O.inherits(Re,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:O.toJSONObject(this.config),code:this.code,status:this.status}}});const Dl=Re.prototype,Ll={};["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=>{Ll[e]={value:e}}),Object.defineProperties(Re,Ll),Object.defineProperty(Dl,"isAxiosError",{value:!0}),Re.from=(e,t,n,r,o,s)=>{const i=Object.create(Dl);O.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 Re.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 hg=null;function yi(e){return O.isPlainObject(e)||O.isArray(e)}function Fl(e){return O.endsWith(e,"[]")?e.slice(0,-2):e}function $l(e,t,n){return e?e.concat(t).map(function(o,s){return o=Fl(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function pg(e){return O.isArray(e)&&!e.some(yi)}const mg=O.toFlatObject(O,{},null,function(t){return/^is[A-Z]/.test(t)});function Fo(e,t,n){if(!O.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=O.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(x,g){return!O.isUndefined(g[x])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&O.isSpecCompliantForm(t);if(!O.isFunction(o))throw new TypeError("visitor must be a function");function u(v){if(v===null)return"";if(O.isDate(v))return v.toISOString();if(O.isBoolean(v))return v.toString();if(!l&&O.isBlob(v))throw new Re("Blob is not supported. Use a Buffer instead.");return O.isArrayBuffer(v)||O.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(O.endsWith(x,"{}"))x=r?x:x.slice(0,-2),v=JSON.stringify(v);else if(O.isArray(v)&&pg(v)||(O.isFileList(v)||O.endsWith(x,"[]"))&&(y=O.toArray(v)))return x=Fl(x),y.forEach(function(C,E){!(O.isUndefined(C)||C===null)&&t.append(i===!0?$l([x],E,s):i===null?x:x+"[]",u(C))}),!1}return yi(v)?!0:(t.append($l(g,x,s),u(v)),!1)}const f=[],h=Object.assign(mg,{defaultVisitor:d,convertValue:u,isVisitable:yi});function p(v,x){if(!O.isUndefined(v)){if(f.indexOf(v)!==-1)throw Error("Circular reference detected in "+x.join("."));f.push(v),O.forEach(v,function(y,b){(!(O.isUndefined(y)||y===null)&&o.call(t,y,O.isString(b)?b.trim():b,x,h))===!0&&p(y,x?x.concat(b):[b])}),f.pop()}}if(!O.isObject(e))throw new TypeError("data must be an object");return p(e),t}function zl(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function vi(e,t){this._pairs=[],e&&Fo(e,this,t)}const Bl=vi.prototype;Bl.append=function(t,n){this._pairs.push([t,n])},Bl.toString=function(t){const n=t?function(r){return t.call(this,r,zl)}:zl;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function gg(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function Hl(e,t,n){if(!t)return e;const r=n&&n.encode||gg;O.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=O.isURLSearchParams(t)?t.toString():new vi(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class Ul{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){O.forEach(this.handlers,function(r){r!==null&&t(r)})}}const Wl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},xg={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:vi,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},bi=typeof window<"u"&&typeof document<"u",wi=typeof navigator=="object"&&navigator||void 0,yg=bi&&(!wi||["ReactNative","NativeScript","NS"].indexOf(wi.product)<0),vg=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",bg=bi&&window.location.href||"http://localhost",Mt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:bi,hasStandardBrowserEnv:yg,hasStandardBrowserWebWorkerEnv:vg,navigator:wi,origin:bg},Symbol.toStringTag,{value:"Module"})),...xg};function wg(e,t){return Fo(e,new Mt.classes.URLSearchParams,{visitor:function(n,r,o,s){return Mt.isNode&&O.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function Sg(e){return O.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Cg(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 Vl(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&&O.isArray(o)?o.length:i,l?(O.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!O.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&O.isArray(o[i])&&(o[i]=Cg(o[i])),!a)}if(O.isFormData(e)&&O.isFunction(e.entries)){const n={};return O.forEachEntry(e,(r,o)=>{t(Sg(r),o,n,0)}),n}return null}function kg(e,t,n){if(O.isString(e))try{return(t||JSON.parse)(e),O.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const Xr={transitional:Wl,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=O.isObject(t);if(s&&O.isHTMLForm(t)&&(t=new FormData(t)),O.isFormData(t))return o?JSON.stringify(Vl(t)):t;if(O.isArrayBuffer(t)||O.isBuffer(t)||O.isStream(t)||O.isFile(t)||O.isBlob(t)||O.isReadableStream(t))return t;if(O.isArrayBufferView(t))return t.buffer;if(O.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 wg(t,this.formSerializer).toString();if((a=O.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return Fo(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),kg(t)):t}],transformResponse:[function(t){const n=this.transitional||Xr.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(O.isResponse(t)||O.isReadableStream(t))return t;if(t&&O.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"?Re.from(a,Re.ERR_BAD_RESPONSE,this,null,this.response):a}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:Mt.classes.FormData,Blob:Mt.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};O.forEach(["delete","get","head","post","put","patch"],e=>{Xr.headers[e]={}});const Tg=O.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"]),Eg=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]&&Tg[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},Kl=Symbol("internals");function
|
|
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[Kl]=this[Kl]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Jr(i);r[a]||(_g(o,i),r[a]=!0)}return O.isArray(t)?t.forEach(s):s(t),this}};Ut.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),O.reduceDescriptors(Ut.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),O.freezeMethods(Ut);function Ci(e,t){const n=this||Xr,r=t||n,o=Ut.from(r.headers);let s=r.data;return O.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function ql(e){return!!(e&&e.__CANCEL__)}function Ar(e,t,n){Re.call(this,e??"canceled",Re.ERR_CANCELED,t,n),this.name="CanceledError"}O.inherits(Ar,Re,{__CANCEL__:!0});function Gl(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Re("Request failed with status code "+n.status,[Re.ERR_BAD_REQUEST,Re.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function jg(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Rg(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 Pg(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 zo=(e,t,n=3)=>{let r=0;const o=Rg(50,250);return Pg(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)},Yl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},Xl=e=>(...t)=>O.asap(()=>e(...t)),Og=Mt.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,Mt.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(Mt.origin),Mt.navigator&&/(msie|trident)/i.test(Mt.navigator.userAgent)):()=>!0,Mg=Mt.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];O.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),O.isString(r)&&i.push("path="+r),O.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 Dg(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function Lg(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function Jl(e,t,n){let r=!Dg(t);return e&&(r||n==!1)?Lg(e,t):t}const Zl=e=>e instanceof Ut?{...e}:e;function ir(e,t){t=t||{};const n={};function r(u,d,f,h){return O.isPlainObject(u)&&O.isPlainObject(d)?O.merge.call({caseless:h},u,d):O.isPlainObject(d)?O.merge({},d):O.isArray(d)?d.slice():d}function o(u,d,f,h){if(O.isUndefined(d)){if(!O.isUndefined(u))return r(void 0,u,f,h)}else return r(u,d,f,h)}function s(u,d){if(!O.isUndefined(d))return r(void 0,d)}function i(u,d){if(O.isUndefined(d)){if(!O.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(Zl(u),Zl(d),f,!0)};return O.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,h=f(e[d],t[d],d);O.isUndefined(h)&&f!==a||(n[d]=h)}),n}const Ql=e=>{const t=ir({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=Ut.from(i),t.url=Hl(Jl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),O.isFormData(n)){if(Mt.hasStandardBrowserEnv||Mt.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(O.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(Mt.hasStandardBrowserEnv&&(r&&O.isFunction(r)&&(r=r(t)),r||r!==!1&&Og(t.url))){const l=o&&s&&Mg.read(s);l&&i.set(o,l)}return t},Fg=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=Ql(e);let s=o.data;const i=Ut.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 C=Ut.from("getAllResponseHeaders"in g&&g.getAllResponseHeaders()),k={data:!a||a==="text"||a==="json"?g.responseText:g.response,status:g.status,statusText:g.statusText,headers:C,config:e,request:g};Gl(function(I){n(I),x()},function(I){r(I),x()},k),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 Re("Request aborted",Re.ECONNABORTED,e,g)),g=null)},g.onerror=function(E){const k=E&&E.message?E.message:"Network Error",T=new Re(k,Re.ERR_NETWORK,e,g);T.event=E||null,r(T),g=null},g.ontimeout=function(){let E=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const k=o.transitional||Wl;o.timeoutErrorMessage&&(E=o.timeoutErrorMessage),r(new Re(E,k.clarifyTimeoutError?Re.ETIMEDOUT:Re.ECONNABORTED,e,g)),g=null},s===void 0&&i.setContentType(null),"setRequestHeader"in g&&O.forEach(i.toJSON(),function(E,k){g.setRequestHeader(k,E)}),O.isUndefined(o.withCredentials)||(g.withCredentials=!!o.withCredentials),a&&a!=="json"&&(g.responseType=o.responseType),u&&([h,v]=zo(u,!0),g.addEventListener("progress",h)),l&&g.upload&&([f,p]=zo(l),g.upload.addEventListener("progress",f),g.upload.addEventListener("loadend",p)),(o.cancelToken||o.signal)&&(d=C=>{g&&(r(!C||C.type?new Ar(null,e,g):C),g.abort(),g=null)},o.cancelToken&&o.cancelToken.subscribe(d),o.signal&&(o.signal.aborted?d():o.signal.addEventListener("abort",d)));const b=jg(o.url);if(b&&Mt.protocols.indexOf(b)===-1){r(new Re("Unsupported protocol "+b+":",Re.ERR_BAD_REQUEST,e));return}g.send(s||null)})},$g=(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 Re?d:new Ar(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new Re(`timeout ${t} of ms exceeded`,Re.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=()=>O.asap(a),l}},zg=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},Bg=async function*(e,t){for await(const n of Hg(e))yield*zg(n,t)},Hg=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()}},ec=(e,t,n,r)=>{const o=Bg(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})},tc=64*1024,{isFunction:Bo}=O,Ug=(({Request:e,Response:t})=>({Request:e,Response:t}))(O.global),{ReadableStream:nc,TextEncoder:rc}=O.global,oc=(e,...t)=>{try{return!!e(...t)}catch{return!1}},Wg=e=>{e=O.merge.call({skipUndefined:!0},Ug,e);const{fetch:t,Request:n,Response:r}=e,o=t?Bo(t):typeof fetch=="function",s=Bo(n),i=Bo(r);if(!o)return!1;const a=o&&Bo(nc),l=o&&(typeof rc=="function"?(v=>x=>v.encode(x))(new rc):async v=>new Uint8Array(await new n(v).arrayBuffer())),u=s&&a&&oc(()=>{let v=!1;const x=new n(Mt.origin,{body:new nc,method:"POST",get duplex(){return v=!0,"half"}}).headers.has("Content-Type");return v&&!x}),d=i&&a&&oc(()=>O.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 Re(`Response type '${v}' is not supported`,Re.ERR_NOT_SUPPORT,g)})});const h=async v=>{if(v==null)return 0;if(O.isBlob(v))return v.size;if(O.isSpecCompliantForm(v))return(await new n(Mt.origin,{method:"POST",body:v}).arrayBuffer()).byteLength;if(O.isArrayBufferView(v)||O.isArrayBuffer(v))return v.byteLength;if(O.isURLSearchParams(v)&&(v=v+""),O.isString(v))return(await l(v)).byteLength},p=async(v,x)=>{const g=O.toFiniteNumber(v.getContentLength());return g??h(x)};return async v=>{let{url:x,method:g,data:y,signal:b,cancelToken:C,timeout:E,onDownloadProgress:k,onUploadProgress:T,responseType:I,headers:_,withCredentials:P="same-origin",fetchOptions:j}=Ql(v),H=t||fetch;I=I?(I+"").toLowerCase():"text";let F=$g([b,C&&C.toAbortSignal()],E),U=null;const D=F&&F.unsubscribe&&(()=>{F.unsubscribe()});let G;try{if(T&&u&&g!=="get"&&g!=="head"&&(G=await p(_,y))!==0){let M=new n(x,{method:"POST",body:y,duplex:"half"}),Y;if(O.isFormData(y)&&(Y=M.headers.get("content-type"))&&_.setContentType(Y),M.body){const[ce,be]=Yl(G,zo(Xl(T)));y=ec(M.body,tc,ce,be)}}O.isString(P)||(P=P?"include":"omit");const W=s&&"credentials"in n.prototype,ne={...j,signal:F,method:g.toUpperCase(),headers:_.normalize().toJSON(),body:y,duplex:"half",credentials:W?P:void 0};U=s&&new n(x,ne);let $=await(s?H(U,j):H(x,ne));const z=d&&(I==="stream"||I==="response");if(d&&(k||z&&D)){const M={};["status","statusText","headers"].forEach(ge=>{M[ge]=$[ge]});const Y=O.toFiniteNumber($.headers.get("content-length")),[ce,be]=k&&Yl(Y,zo(Xl(k),!0))||[];$=new r(ec($.body,tc,ce,()=>{be&&be(),D&&D()}),M)}I=I||"text";let se=await f[O.findKey(f,I)||"text"]($,v);return!z&&D&&D(),await new Promise((M,Y)=>{Gl(M,Y,{data:se,headers:Ut.from($.headers),status:$.status,statusText:$.statusText,config:v,request:U})})}catch(W){throw D&&D(),W&&W.name==="TypeError"&&/Load failed|fetch/i.test(W.message)?Object.assign(new Re("Network Error",Re.ERR_NETWORK,v,U),{cause:W.cause||W}):Re.from(W,W&&W.code,v,U)}}},Vg=new Map,sc=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=Vg;for(;a--;)l=s[a],u=d.get(l),u===void 0&&d.set(l,u=a?new Map:Wg(t)),d=u;return u};sc();const ki={http:hg,xhr:Fg,fetch:{get:sc}};O.forEach(ki,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const ic=e=>`- ${e}`,Kg=e=>O.isFunction(e)||e===null||e===!1,ac={getAdapter:(e,t)=>{e=O.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,!Kg(r)&&(o=ki[(a=String(r)).toLowerCase()],o===void 0))throw new Re(`Unknown adapter '${a}'`);if(o&&(O.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 :
|
|
30
|
+
<%s key={someKey} {...props} />`,No,$n,A,$n),mn[$n+No]=!0}}return C===r?Nn(ct):Tr(ct),ct}}function Ao(C,P,H){return tr(C,P,H,!0)}function Wr(C,P,H){return tr(C,P,H,!1)}var Vr=Wr,nr=Ao;qr.Fragment=r,qr.jsx=Vr,qr.jsxs=nr}()),qr}process.env.NODE_ENV==="production"?mi.exports=Im():mi.exports=Am();var c=mi.exports;function Il(e,t){return function(){return e.apply(t,arguments)}}const{toString:Nm}=Object.prototype,{getPrototypeOf:gi}=Object,{iterator:Mo,toStringTag:Al}=Symbol,Do=(e=>t=>{const n=Nm.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),on=e=>(e=e.toLowerCase(),t=>Do(t)===e),Lo=e=>t=>typeof t===e,{isArray:Er}=Array,Ir=Lo("undefined");function Gr(e){return e!==null&&!Ir(e)&&e.constructor!==null&&!Ir(e.constructor)&&Lt(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Nl=on("ArrayBuffer");function _m(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Nl(e.buffer),t}const jm=Lo("string"),Lt=Lo("function"),_l=Lo("number"),Yr=e=>e!==null&&typeof e=="object",Rm=e=>e===!0||e===!1,Fo=e=>{if(Do(e)!=="object")return!1;const t=gi(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Al in e)&&!(Mo in e)},Pm=e=>{if(!Yr(e)||Gr(e))return!1;try{return Object.keys(e).length===0&&Object.getPrototypeOf(e)===Object.prototype}catch{return!1}},Om=on("Date"),Mm=on("File"),Dm=on("Blob"),Lm=on("FileList"),Fm=e=>Yr(e)&&Lt(e.pipe),$m=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||Lt(e.append)&&((t=Do(e))==="formdata"||t==="object"&&Lt(e.toString)&&e.toString()==="[object FormData]"))},zm=on("URLSearchParams"),[Bm,Hm,Um,Wm]=["ReadableStream","Request","Response","Headers"].map(on),Vm=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function Xr(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let r,o;if(typeof e!="object"&&(e=[e]),Er(e))for(r=0,o=e.length;r<o;r++)t.call(null,e[r],r,e);else{if(Gr(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 jl(e,t){if(Gr(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 or=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,Rl=e=>!Ir(e)&&e!==or;function xi(){const{caseless:e,skipUndefined:t}=Rl(this)&&this||{},n={},r=(o,s)=>{const i=e&&jl(n,s)||s;Fo(n[i])&&Fo(o)?n[i]=xi(n[i],o):Fo(o)?n[i]=xi({},o):Er(o)?n[i]=o.slice():(!t||!Ir(o))&&(n[i]=o)};for(let o=0,s=arguments.length;o<s;o++)arguments[o]&&Xr(arguments[o],r);return n}const Km=(e,t,n,{allOwnKeys:r}={})=>(Xr(t,(o,s)=>{n&&Lt(o)?e[s]=Il(o,n):e[s]=o},{allOwnKeys:r}),e),qm=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),Gm=(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)},Ym=(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&&gi(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},Xm=(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},Jm=e=>{if(!e)return null;if(Er(e))return e;let t=e.length;if(!_l(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},Zm=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&gi(Uint8Array)),Qm=(e,t)=>{const r=(e&&e[Mo]).call(e);let o;for(;(o=r.next())&&!o.done;){const s=o.value;t.call(e,s[0],s[1])}},eg=(e,t)=>{let n;const r=[];for(;(n=e.exec(t))!==null;)r.push(n);return r},tg=on("HTMLFormElement"),ng=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,o){return r.toUpperCase()+o}),Pl=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),rg=on("RegExp"),Ol=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),r={};Xr(n,(o,s)=>{let i;(i=t(o,s,e))!==!1&&(r[s]=i||o)}),Object.defineProperties(e,r)},og=e=>{Ol(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+"'")})}})},sg=(e,t)=>{const n={},r=o=>{o.forEach(s=>{n[s]=!0})};return Er(e)?r(e):r(String(e).split(t)),n},ig=()=>{},ag=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function lg(e){return!!(e&&Lt(e.append)&&e[Al]==="FormData"&&e[Mo])}const cg=e=>{const t=new Array(10),n=(r,o)=>{if(Yr(r)){if(t.indexOf(r)>=0)return;if(Gr(r))return r;if(!("toJSON"in r)){t[o]=r;const s=Er(r)?[]:{};return Xr(r,(i,a)=>{const l=n(i,o+1);!Ir(l)&&(s[a]=l)}),t[o]=void 0,s}}return r};return n(e,0)},ug=on("AsyncFunction"),dg=e=>e&&(Yr(e)||Lt(e))&&Lt(e.then)&&Lt(e.catch),Ml=((e,t)=>e?setImmediate:t?((n,r)=>(or.addEventListener("message",({source:o,data:s})=>{o===or&&s===n&&r.length&&r.shift()()},!1),o=>{r.push(o),or.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",Lt(or.postMessage)),fg=typeof queueMicrotask<"u"?queueMicrotask.bind(or):typeof process<"u"&&process.nextTick||Ml,M={isArray:Er,isArrayBuffer:Nl,isBuffer:Gr,isFormData:$m,isArrayBufferView:_m,isString:jm,isNumber:_l,isBoolean:Rm,isObject:Yr,isPlainObject:Fo,isEmptyObject:Pm,isReadableStream:Bm,isRequest:Hm,isResponse:Um,isHeaders:Wm,isUndefined:Ir,isDate:Om,isFile:Mm,isBlob:Dm,isRegExp:rg,isFunction:Lt,isStream:Fm,isURLSearchParams:zm,isTypedArray:Zm,isFileList:Lm,forEach:Xr,merge:xi,extend:Km,trim:Vm,stripBOM:qm,inherits:Gm,toFlatObject:Ym,kindOf:Do,kindOfTest:on,endsWith:Xm,toArray:Jm,forEachEntry:Qm,matchAll:eg,isHTMLForm:tg,hasOwnProperty:Pl,hasOwnProp:Pl,reduceDescriptors:Ol,freezeMethods:og,toObjectSet:sg,toCamelCase:ng,noop:ig,toFiniteNumber:ag,findKey:jl,global:or,isContextDefined:Rl,isSpecCompliantForm:lg,toJSONObject:cg,isAsyncFn:ug,isThenable:dg,setImmediate:Ml,asap:fg,isIterable:e=>e!=null&&Lt(e[Mo])};function Re(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)}M.inherits(Re,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:M.toJSONObject(this.config),code:this.code,status:this.status}}});const Dl=Re.prototype,Ll={};["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=>{Ll[e]={value:e}}),Object.defineProperties(Re,Ll),Object.defineProperty(Dl,"isAxiosError",{value:!0}),Re.from=(e,t,n,r,o,s)=>{const i=Object.create(Dl);M.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 Re.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 hg=null;function yi(e){return M.isPlainObject(e)||M.isArray(e)}function Fl(e){return M.endsWith(e,"[]")?e.slice(0,-2):e}function $l(e,t,n){return e?e.concat(t).map(function(o,s){return o=Fl(o),!n&&s?"["+o+"]":o}).join(n?".":""):t}function pg(e){return M.isArray(e)&&!e.some(yi)}const mg=M.toFlatObject(M,{},null,function(t){return/^is[A-Z]/.test(t)});function $o(e,t,n){if(!M.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=M.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(x,g){return!M.isUndefined(g[x])});const r=n.metaTokens,o=n.visitor||d,s=n.dots,i=n.indexes,l=(n.Blob||typeof Blob<"u"&&Blob)&&M.isSpecCompliantForm(t);if(!M.isFunction(o))throw new TypeError("visitor must be a function");function u(v){if(v===null)return"";if(M.isDate(v))return v.toISOString();if(M.isBoolean(v))return v.toString();if(!l&&M.isBlob(v))throw new Re("Blob is not supported. Use a Buffer instead.");return M.isArrayBuffer(v)||M.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(M.endsWith(x,"{}"))x=r?x:x.slice(0,-2),v=JSON.stringify(v);else if(M.isArray(v)&&pg(v)||(M.isFileList(v)||M.endsWith(x,"[]"))&&(y=M.toArray(v)))return x=Fl(x),y.forEach(function(S,E){!(M.isUndefined(S)||S===null)&&t.append(i===!0?$l([x],E,s):i===null?x:x+"[]",u(S))}),!1}return yi(v)?!0:(t.append($l(g,x,s),u(v)),!1)}const f=[],h=Object.assign(mg,{defaultVisitor:d,convertValue:u,isVisitable:yi});function p(v,x){if(!M.isUndefined(v)){if(f.indexOf(v)!==-1)throw Error("Circular reference detected in "+x.join("."));f.push(v),M.forEach(v,function(y,b){(!(M.isUndefined(y)||y===null)&&o.call(t,y,M.isString(b)?b.trim():b,x,h))===!0&&p(y,x?x.concat(b):[b])}),f.pop()}}if(!M.isObject(e))throw new TypeError("data must be an object");return p(e),t}function zl(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(r){return t[r]})}function vi(e,t){this._pairs=[],e&&$o(e,this,t)}const Bl=vi.prototype;Bl.append=function(t,n){this._pairs.push([t,n])},Bl.toString=function(t){const n=t?function(r){return t.call(this,r,zl)}:zl;return this._pairs.map(function(o){return n(o[0])+"="+n(o[1])},"").join("&")};function gg(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+")}function Hl(e,t,n){if(!t)return e;const r=n&&n.encode||gg;M.isFunction(n)&&(n={serialize:n});const o=n&&n.serialize;let s;if(o?s=o(t,n):s=M.isURLSearchParams(t)?t.toString():new vi(t,n).toString(r),s){const i=e.indexOf("#");i!==-1&&(e=e.slice(0,i)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class Ul{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){M.forEach(this.handlers,function(r){r!==null&&t(r)})}}const Wl={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},xg={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:vi,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},bi=typeof window<"u"&&typeof document<"u",wi=typeof navigator=="object"&&navigator||void 0,yg=bi&&(!wi||["ReactNative","NativeScript","NS"].indexOf(wi.product)<0),vg=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",bg=bi&&window.location.href||"http://localhost",Nt={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:bi,hasStandardBrowserEnv:yg,hasStandardBrowserWebWorkerEnv:vg,navigator:wi,origin:bg},Symbol.toStringTag,{value:"Module"})),...xg};function wg(e,t){return $o(e,new Nt.classes.URLSearchParams,{visitor:function(n,r,o,s){return Nt.isNode&&M.isBuffer(n)?(this.append(r,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)},...t})}function Sg(e){return M.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function Cg(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 Vl(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&&M.isArray(o)?o.length:i,l?(M.hasOwnProp(o,i)?o[i]=[o[i],r]:o[i]=r,!a):((!o[i]||!M.isObject(o[i]))&&(o[i]=[]),t(n,r,o[i],s)&&M.isArray(o[i])&&(o[i]=Cg(o[i])),!a)}if(M.isFormData(e)&&M.isFunction(e.entries)){const n={};return M.forEachEntry(e,(r,o)=>{t(Sg(r),o,n,0)}),n}return null}function kg(e,t,n){if(M.isString(e))try{return(t||JSON.parse)(e),M.trim(e)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(e)}const Jr={transitional:Wl,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const r=n.getContentType()||"",o=r.indexOf("application/json")>-1,s=M.isObject(t);if(s&&M.isHTMLForm(t)&&(t=new FormData(t)),M.isFormData(t))return o?JSON.stringify(Vl(t)):t;if(M.isArrayBuffer(t)||M.isBuffer(t)||M.isStream(t)||M.isFile(t)||M.isBlob(t)||M.isReadableStream(t))return t;if(M.isArrayBufferView(t))return t.buffer;if(M.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 wg(t,this.formSerializer).toString();if((a=M.isFileList(t))||r.indexOf("multipart/form-data")>-1){const l=this.env&&this.env.FormData;return $o(a?{"files[]":t}:t,l&&new l,this.formSerializer)}}return s||o?(n.setContentType("application/json",!1),kg(t)):t}],transformResponse:[function(t){const n=this.transitional||Jr.transitional,r=n&&n.forcedJSONParsing,o=this.responseType==="json";if(M.isResponse(t)||M.isReadableStream(t))return t;if(t&&M.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"?Re.from(a,Re.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}}};M.forEach(["delete","get","head","post","put","patch"],e=>{Jr.headers[e]={}});const Tg=M.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"]),Eg=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]&&Tg[n])&&(n==="set-cookie"?t[n]?t[n].push(r):t[n]=[r]:t[n]=t[n]?t[n]+", "+r:r)}),t},Kl=Symbol("internals");function Zr(e){return e&&String(e).trim().toLowerCase()}function zo(e){return e===!1||e==null?e:M.isArray(e)?e.map(zo):String(e)}function Ig(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 Ag=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function Si(e,t,n,r,o){if(M.isFunction(r))return r.call(this,t,n);if(o&&(t=n),!!M.isString(t)){if(M.isString(r))return t.indexOf(r)!==-1;if(M.isRegExp(r))return r.test(t)}}function Ng(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,r)=>n.toUpperCase()+r)}function _g(e,t){const n=M.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 Ft=class{constructor(t){t&&this.set(t)}set(t,n,r){const o=this;function s(a,l,u){const d=Zr(l);if(!d)throw new Error("header name must be a non-empty string");const f=M.findKey(o,d);(!f||o[f]===void 0||u===!0||u===void 0&&o[f]!==!1)&&(o[f||l]=zo(a))}const i=(a,l)=>M.forEach(a,(u,d)=>s(u,d,l));if(M.isPlainObject(t)||t instanceof this.constructor)i(t,n);else if(M.isString(t)&&(t=t.trim())&&!Ag(t))i(Eg(t),n);else if(M.isObject(t)&&M.isIterable(t)){let a={},l,u;for(const d of t){if(!M.isArray(d))throw TypeError("Object iterator must return a key-value pair");a[u=d[0]]=(l=a[u])?M.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=Zr(t),t){const r=M.findKey(this,t);if(r){const o=this[r];if(!n)return o;if(n===!0)return Ig(o);if(M.isFunction(n))return n.call(this,o,r);if(M.isRegExp(n))return n.exec(o);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,n){if(t=Zr(t),t){const r=M.findKey(this,t);return!!(r&&this[r]!==void 0&&(!n||Si(this,this[r],r,n)))}return!1}delete(t,n){const r=this;let o=!1;function s(i){if(i=Zr(i),i){const a=M.findKey(r,i);a&&(!n||Si(r,r[a],a,n))&&(delete r[a],o=!0)}}return M.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||Si(this,this[s],s,t,!0))&&(delete this[s],o=!0)}return o}normalize(t){const n=this,r={};return M.forEach(this,(o,s)=>{const i=M.findKey(r,s);if(i){n[i]=zo(o),delete n[s];return}const a=t?Ng(s):String(s).trim();a!==s&&delete n[s],n[a]=zo(o),r[a]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return M.forEach(this,(r,o)=>{r!=null&&r!==!1&&(n[o]=t&&M.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[Kl]=this[Kl]={accessors:{}}).accessors,o=this.prototype;function s(i){const a=Zr(i);r[a]||(_g(o,i),r[a]=!0)}return M.isArray(t)?t.forEach(s):s(t),this}};Ft.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),M.reduceDescriptors(Ft.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(r){this[n]=r}}}),M.freezeMethods(Ft);function Ci(e,t){const n=this||Jr,r=t||n,o=Ft.from(r.headers);let s=r.data;return M.forEach(e,function(a){s=a.call(n,s,o.normalize(),t?t.status:void 0)}),o.normalize(),s}function ql(e){return!!(e&&e.__CANCEL__)}function Ar(e,t,n){Re.call(this,e??"canceled",Re.ERR_CANCELED,t,n),this.name="CanceledError"}M.inherits(Ar,Re,{__CANCEL__:!0});function Gl(e,t,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?e(n):t(new Re("Request failed with status code "+n.status,[Re.ERR_BAD_REQUEST,Re.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function jg(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function Rg(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 Pg(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 Bo=(e,t,n=3)=>{let r=0;const o=Rg(50,250);return Pg(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)},Yl=(e,t)=>{const n=e!=null;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},Xl=e=>(...t)=>M.asap(()=>e(...t)),Og=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,Mg=Nt.hasStandardBrowserEnv?{write(e,t,n,r,o,s){const i=[e+"="+encodeURIComponent(t)];M.isNumber(n)&&i.push("expires="+new Date(n).toGMTString()),M.isString(r)&&i.push("path="+r),M.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 Dg(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function Lg(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function Jl(e,t,n){let r=!Dg(t);return e&&(r||n==!1)?Lg(e,t):t}const Zl=e=>e instanceof Ft?{...e}:e;function sr(e,t){t=t||{};const n={};function r(u,d,f,h){return M.isPlainObject(u)&&M.isPlainObject(d)?M.merge.call({caseless:h},u,d):M.isPlainObject(d)?M.merge({},d):M.isArray(d)?d.slice():d}function o(u,d,f,h){if(M.isUndefined(d)){if(!M.isUndefined(u))return r(void 0,u,f,h)}else return r(u,d,f,h)}function s(u,d){if(!M.isUndefined(d))return r(void 0,d)}function i(u,d){if(M.isUndefined(d)){if(!M.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(Zl(u),Zl(d),f,!0)};return M.forEach(Object.keys({...e,...t}),function(d){const f=l[d]||o,h=f(e[d],t[d],d);M.isUndefined(h)&&f!==a||(n[d]=h)}),n}const Ql=e=>{const t=sr({},e);let{data:n,withXSRFToken:r,xsrfHeaderName:o,xsrfCookieName:s,headers:i,auth:a}=t;if(t.headers=i=Ft.from(i),t.url=Hl(Jl(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),a&&i.set("Authorization","Basic "+btoa((a.username||"")+":"+(a.password?unescape(encodeURIComponent(a.password)):""))),M.isFormData(n)){if(Nt.hasStandardBrowserEnv||Nt.hasStandardBrowserWebWorkerEnv)i.setContentType(void 0);else if(M.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&&M.isFunction(r)&&(r=r(t)),r||r!==!1&&Og(t.url))){const l=o&&s&&Mg.read(s);l&&i.set(o,l)}return t},Fg=typeof XMLHttpRequest<"u"&&function(e){return new Promise(function(n,r){const o=Ql(e);let s=o.data;const i=Ft.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=Ft.from("getAllResponseHeaders"in g&&g.getAllResponseHeaders()),k={data:!a||a==="text"||a==="json"?g.responseText:g.response,status:g.status,statusText:g.statusText,headers:S,config:e,request:g};Gl(function(I){n(I),x()},function(I){r(I),x()},k),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 Re("Request aborted",Re.ECONNABORTED,e,g)),g=null)},g.onerror=function(E){const k=E&&E.message?E.message:"Network Error",T=new Re(k,Re.ERR_NETWORK,e,g);T.event=E||null,r(T),g=null},g.ontimeout=function(){let E=o.timeout?"timeout of "+o.timeout+"ms exceeded":"timeout exceeded";const k=o.transitional||Wl;o.timeoutErrorMessage&&(E=o.timeoutErrorMessage),r(new Re(E,k.clarifyTimeoutError?Re.ETIMEDOUT:Re.ECONNABORTED,e,g)),g=null},s===void 0&&i.setContentType(null),"setRequestHeader"in g&&M.forEach(i.toJSON(),function(E,k){g.setRequestHeader(k,E)}),M.isUndefined(o.withCredentials)||(g.withCredentials=!!o.withCredentials),a&&a!=="json"&&(g.responseType=o.responseType),u&&([h,v]=Bo(u,!0),g.addEventListener("progress",h)),l&&g.upload&&([f,p]=Bo(l),g.upload.addEventListener("progress",f),g.upload.addEventListener("loadend",p)),(o.cancelToken||o.signal)&&(d=S=>{g&&(r(!S||S.type?new Ar(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=jg(o.url);if(b&&Nt.protocols.indexOf(b)===-1){r(new Re("Unsupported protocol "+b+":",Re.ERR_BAD_REQUEST,e));return}g.send(s||null)})},$g=(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 Re?d:new Ar(d instanceof Error?d.message:d))}};let i=t&&setTimeout(()=>{i=null,s(new Re(`timeout ${t} of ms exceeded`,Re.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=()=>M.asap(a),l}},zg=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},Bg=async function*(e,t){for await(const n of Hg(e))yield*zg(n,t)},Hg=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()}},ec=(e,t,n,r)=>{const o=Bg(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})},tc=64*1024,{isFunction:Ho}=M,Ug=(({Request:e,Response:t})=>({Request:e,Response:t}))(M.global),{ReadableStream:nc,TextEncoder:rc}=M.global,oc=(e,...t)=>{try{return!!e(...t)}catch{return!1}},Wg=e=>{e=M.merge.call({skipUndefined:!0},Ug,e);const{fetch:t,Request:n,Response:r}=e,o=t?Ho(t):typeof fetch=="function",s=Ho(n),i=Ho(r);if(!o)return!1;const a=o&&Ho(nc),l=o&&(typeof rc=="function"?(v=>x=>v.encode(x))(new rc):async v=>new Uint8Array(await new n(v).arrayBuffer())),u=s&&a&&oc(()=>{let v=!1;const x=new n(Nt.origin,{body:new nc,method:"POST",get duplex(){return v=!0,"half"}}).headers.has("Content-Type");return v&&!x}),d=i&&a&&oc(()=>M.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 Re(`Response type '${v}' is not supported`,Re.ERR_NOT_SUPPORT,g)})});const h=async v=>{if(v==null)return 0;if(M.isBlob(v))return v.size;if(M.isSpecCompliantForm(v))return(await new n(Nt.origin,{method:"POST",body:v}).arrayBuffer()).byteLength;if(M.isArrayBufferView(v)||M.isArrayBuffer(v))return v.byteLength;if(M.isURLSearchParams(v)&&(v=v+""),M.isString(v))return(await l(v)).byteLength},p=async(v,x)=>{const g=M.toFiniteNumber(v.getContentLength());return g??h(x)};return async v=>{let{url:x,method:g,data:y,signal:b,cancelToken:S,timeout:E,onDownloadProgress:k,onUploadProgress:T,responseType:I,headers:_,withCredentials:O="same-origin",fetchOptions:j}=Ql(v),U=t||fetch;I=I?(I+"").toLowerCase():"text";let L=$g([b,S&&S.toAbortSignal()],E),W=null;const R=L&&L.unsubscribe&&(()=>{L.unsubscribe()});let V;try{if(T&&u&&g!=="get"&&g!=="head"&&(V=await p(_,y))!==0){let z=new n(x,{method:"POST",body:y,duplex:"half"}),oe;if(M.isFormData(y)&&(oe=z.headers.get("content-type"))&&_.setContentType(oe),z.body){const[pe,ge]=Yl(V,Bo(Xl(T)));y=ec(z.body,tc,pe,ge)}}M.isString(O)||(O=O?"include":"omit");const $=s&&"credentials"in n.prototype,ne={...j,signal:L,method:g.toUpperCase(),headers:_.normalize().toJSON(),body:y,duplex:"half",credentials:$?O:void 0};W=s&&new n(x,ne);let F=await(s?U(W,j):U(x,ne));const B=d&&(I==="stream"||I==="response");if(d&&(k||B&&R)){const z={};["status","statusText","headers"].forEach(me=>{z[me]=F[me]});const oe=M.toFiniteNumber(F.headers.get("content-length")),[pe,ge]=k&&Yl(oe,Bo(Xl(k),!0))||[];F=new r(ec(F.body,tc,pe,()=>{ge&&ge(),R&&R()}),z)}I=I||"text";let le=await f[M.findKey(f,I)||"text"](F,v);return!B&&R&&R(),await new Promise((z,oe)=>{Gl(z,oe,{data:le,headers:Ft.from(F.headers),status:F.status,statusText:F.statusText,config:v,request:W})})}catch($){throw R&&R(),$&&$.name==="TypeError"&&/Load failed|fetch/i.test($.message)?Object.assign(new Re("Network Error",Re.ERR_NETWORK,v,W),{cause:$.cause||$}):Re.from($,$&&$.code,v,W)}}},Vg=new Map,sc=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=Vg;for(;a--;)l=s[a],u=d.get(l),u===void 0&&d.set(l,u=a?new Map:Wg(t)),d=u;return u};sc();const ki={http:hg,xhr:Fg,fetch:{get:sc}};M.forEach(ki,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const ic=e=>`- ${e}`,Kg=e=>M.isFunction(e)||e===null||e===!1,ac={getAdapter:(e,t)=>{e=M.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,!Kg(r)&&(o=ki[(a=String(r)).toLowerCase()],o===void 0))throw new Re(`Unknown adapter '${a}'`);if(o&&(M.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
33
|
`+i.map(ic).join(`
|
|
34
|
-
`):" "+ic(i[0]):"as no adapter specified";throw new Re("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:ki};function Ti(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new Ar(null,e)}function lc(e){return Ti(e),e.headers=
|
|
35
|
-
`+s):r.stack=s}catch{}}throw r}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=ir(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&Uo.assertOptions(r,{silentJSONParsing:yn.transitional(yn.boolean),forcedJSONParsing:yn.transitional(yn.boolean),clarifyTimeoutError:yn.transitional(yn.boolean)},!1),o!=null&&(O.isFunction(o)?n.paramsSerializer={serialize:o}:Uo.assertOptions(o,{encode:yn.function,serialize:yn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),Uo.assertOptions(n,{baseUrl:yn.spelling("baseURL"),withXsrfToken:yn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&O.merge(s.common,s[n.method]);s&&O.forEach(["delete","get","head","post","put","patch","common"],v=>{delete s[v]}),n.headers=Ut.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=[lc.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=lc.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=ir(this.defaults,t);const n=Jl(t.baseURL,t.url,t.allowAbsoluteUrls);return Hl(n,t.params,t.paramsSerializer)}};O.forEach(["delete","get","head","options"],function(t){ar.prototype[t]=function(n,r){return this.request(ir(r||{},{method:t,url:n,data:(r||{}).data}))}}),O.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(ir(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}ar.prototype[t]=n(),ar.prototype[t+"Form"]=n(!0)});let Gg=class km{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 Ar(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 km(function(o){t=o}),cancel:t}}};function Yg(e){return function(n){return e.apply(null,n)}}function Xg(e){return O.isObject(e)&&e.isAxiosError===!0}const Ei={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(Ei).forEach(([e,t])=>{Ei[t]=e});function dc(e){const t=new ar(e),n=Il(ar.prototype.request,t);return O.extend(n,ar.prototype,t,{allOwnKeys:!0}),O.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return dc(ir(e,o))},n}const mt=dc(Xr);mt.Axios=ar,mt.CanceledError=Ar,mt.CancelToken=Gg,mt.isCancel=ql,mt.VERSION=cc,mt.toFormData=Fo,mt.AxiosError=Re,mt.Cancel=mt.CanceledError,mt.all=function(t){return Promise.all(t)},mt.spread=Yg,mt.isAxiosError=Xg,mt.mergeConfig=ir,mt.AxiosHeaders=Ut,mt.formToJSON=e=>Vl(O.isHTMLForm(e)?new FormData(e):e),mt.getAdapter=ac.getAdapter,mt.HttpStatusCode=Ei,mt.default=mt;const{Axios:nT,AxiosError:rT,CanceledError:oT,isCancel:sT,CancelToken:iT,VERSION:aT,all:lT,Cancel:cT,isAxiosError:uT,spread:dT,toFormData:fT,AxiosHeaders:hT,HttpStatusCode:pT,formToJSON:mT,getAdapter:gT,mergeConfig:xT}=mt,fc=typeof window<"u"?window.__API_BASE_URL__:void 0,hc=fc?Mn(fc):void 0;function Mn(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let Wo=null;const Ii=new Set;function pc(){return Wo}function Ai(e){Wo=e,Ii.forEach(t=>t(e))}function mc(e){return Ii.add(e),()=>Ii.delete(e)}const Zt=mt.create({...hc?{baseURL:hc}:{},timeout:3e4,withCredentials:!0});Zt.interceptors.request.use(e=>(Wo&&(e.headers.Authorization=`Bearer ${Wo}`),e)),Zt.interceptors.response.use(e=>e,e=>Promise.reject(e));async function cn(e,t){return Zt.defaults.baseURL?(await Zt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function gc(e,t,n){return Zt.defaults.baseURL?(await Zt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function xc(e,t,n){return Zt.defaults.baseURL?(await Zt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function yc(e,t){return Zt.defaults.baseURL?(await Zt.delete(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}function vn(e){return e&&typeof e=="object"&&"data"in e?e.data:e}class vc{get baseUrl(){const t=Zt.defaults.baseURL;return t?Mn(String(t)):""}updateConfig(t){t.baseUrl&&(Zt.defaults.baseURL=Mn(String(t.baseUrl))),t.authToken!==void 0&&Ai(t.authToken)}getAuthToken(){return pc()}setAuthToken(t){Ai(t)}onTokenChange(t){return mc(t)}async listThreads(){const t=await cn("/threads"),n=vn(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await gc("/threads",t?{title:t}:void 0);return vn(r)}async updateThread(t,n){const r=await xc(`/threads/${t}`,{title:n});return vn(r)}async deleteThread(t){const n=await yc(`/threads/${t}`);return vn(n)}async threadInfo(t){const n=await cn(`/threads/${t}/info`);return vn(n)}async listAgents(){const t=await cn("/agents"),n=vn(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await cn(`/agents/${t}`);return vn(n)}async getAgentSchema(t){const n=await cn(`/agents/${t}/schema`);return vn(n)}async getState(t){const n=await cn(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return vn(n)}async getStateHistory(t){const n=await cn(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return vn(n)}}const Hn=new vc,bc=w.createContext(null);function Jg({children:e,apiConfig:t}){const n=Hn;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(bc.Provider,{value:r,children:e})}function Ni(){const e=w.useContext(bc);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function Zg(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 Qg(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const u=await Zg(l);a.push({filename:l.name,data:u,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const ex={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function _i(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 Zr(e,t){return`${e??""}::${t??""}`}function ji(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(!_i(r))return{threadId:n,latest:null,checkpoints:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=nx(t),i=wc(r,0);return{threadId:n,latest:i,checkpoints:o,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function wc(e,t){if(!_i(e))return null;const n=e.values??{messages:[]},r=Array.isArray(n==null?void 0:n.messages)?n.messages:[],{messages:o,...s}=n,i=Object.keys(s).length?s:null,a=e.tasks,l=Array.isArray(a)?a.filter(P=>!!P&&typeof P=="object").map(P=>({...P})):a===null?null:void 0,u=r.map((P,j)=>ux(P,j)).filter(P=>!!P),d=Vt(e.config),f=Vt(d==null?void 0:d.configurable),h=ft(f,["checkpoint_id","checkpointId"]),p=ft(f,["checkpoint_ns","checkpointNs"]),v=Vt(e==null?void 0:e.parentConfig),x=Vt(v==null?void 0:v.configurable),g=ft(x,["checkpoint_id","checkpointId"])??null,y=ft(x,["checkpoint_ns","checkpointNs"])??null,b=e==null?void 0:e.createdAt,C=typeof b=="string"&&b.trim()?b:new Date(Date.now()-t).toISOString(),E=u[u.length-1]??null,k=Vt(e==null?void 0:e.metadata),T=ft(k,["branch_label","branchLabel"]),I=ft(x,["checkpoint_id","checkpointId"]),_=Array.isArray(e.next)?[...e.next]:(e==null?void 0:e.next)===null?null:void 0;return{messages:u,checkpointId:h??null,checkpointNs:p??null,nextCursor:g,nextCursorNs:y,interrupt:tx(a,u,t),createdAt:C,parentId:I??null,branchLabel:T??null,lastMessageId:(E==null?void 0:E.id)??null,hasMessages:u.length>0,messagesLen:u.length,metadata:k??null,config:d??null,parentConfig:v??null,next:_??null,tasks:l??null,values:i??null}}function tx(e,t,n){const r=lx(e,n);return r||ax(t,n)}function nx(e){const t=new Map;e.forEach((o,s)=>{if(!_i(o))return;const i=wc(o,s);if(!(i!=null&&i.checkpointId))return;const a=Zr(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,rx(l,i))});const n=Array.from(t.values());n.sort((o,s)=>Cc(s.createdAt??"")-Cc(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function rx(e,t){const n=Vo(e.metadata,t.metadata),r=Vo(e.config,t.config),o=Vo(e.parentConfig,t.parentConfig),s=sx(e.next,t.next),i=ix(e.tasks,t.tasks),a=ox(e.values,t.values);return{...e,metadata:n??null,config:r??null,parentConfig:o??null,next:s??null,tasks:i??null,values:a??null}}function Vo(e,t){return t&&typeof t=="object"?{...e&&typeof e=="object"?{...e}:{},...t}:t===null?e&&typeof e=="object"?{...e}:e??null:e&&typeof e=="object"?{...e}:e??void 0}function ox(e,t){return Vo(e,t)}function sx(e,t){return Array.isArray(t)?t.slice():t===null?Array.isArray(e)?e.slice():e??null:Array.isArray(e)?e.slice():e??void 0}function ix(e,t){return Array.isArray(t)?t.map(n=>({...n})):t===null?Array.isArray(e)?e.map(n=>({...n})):e??null:Array.isArray(e)?e.map(n=>({...n})):e??void 0}function ax(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 lx(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=cx(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=Qr(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=Qr(r.state,`${o}-state`);if(s)return s}}return null}function cx(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=Vt(e);if(!n)return null;const r=ft(n,["id","task_id","taskId"])??t,o=ft(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 Qr(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=Sc(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=Qr(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=Qr(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=Qr(l,t,n+1,r);if(u)return u}}return null}function Sc(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=ft(n,["type","event","kind"]),o=ft(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=Sc(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 Cc(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function ux(e,t){if(!e||typeof e!="object")return null;const n=e,r=Vt(e)??{},o=Vt(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=ex[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=Vt(o.additional_kwargs)??Vt(o.additionalKwargs),d=Vt(o.response_metadata)??Vt(o.responseMetadata),f=ft(u,["createdAt","created_at"])??ft(o,["created_at","createdAt"]),h=ft(u,["checkpointId","checkpoint_id"]),p=ft(u,["checkpointNs","checkpoint_ns"]),v=dx(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=gx(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=fx((u==null?void 0:u.tool_calls)??o.tool_calls);if(b.length&&(x.content=[...x.content,...b]),i==="tool"){const C=px(o,x.content);C&&(x.content=C)}return x}function dx(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>kc(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=kc(e);return t?[t]:[]}return[]}function kc(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=ft(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=ft(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 hx(t)??null;if(n==="tool_end"){const o=ft(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=ft(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 fx(e){return Array.isArray(e)?e.map((t,n)=>{if(!t||typeof t!="object")return null;const r=t,o=ft(r,["id","call_id"]),s=Vt(r.function),i=ft(s,["name"])??"tool",a=s==null?void 0:s.arguments,l=Tc(a);return{type:"tool_call",id:o??`tool_call_${n}`,name:i,args:l}}).filter(t=>!!t):[]}function hx(e){const t=ft(e,["id","call_id"]),n=ft(e,["name"]);if(!t||!n)return null;const r=Tc(e.args??e.arguments);return{type:"tool_call",id:t,name:n,args:r}}function px(e,t){const n=ft(e,["tool_call_id","toolCallId","id"]);if(!n)return t;const r=e.content??e.output,o=typeof r=="string"?mx(r):r,s={type:"tool_end",toolCallId:n,output:o};return typeof e.error=="string"&&(s.error=e.error),[s]}function Tc(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 mx(e){try{return JSON.parse(e)}catch{return e}}function Vt(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function ft(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function gx(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 xx(e){return e.type!=="thread_info"&&e.type!=="token"}const yx={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function vx(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:Ri(((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=Ri(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=Ri(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 Ic(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Ic(o,s),e):e}case"interrupt_response":return{...e,messages:Nc(e.messages),pendingInterrupt:null};default:return e}}function Ec(e=[]){const[t,n]=w.useReducer(vx,{...yx,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 Ic(e,t){var n,r,o,s;if(t.type==="message_start"&&t.role==="assistant"){const i=t.id,a=Tx(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??_c(e.messages);if(!i)return e;const a=e.messages,l=a.findIndex(C=>C.id===i&&C.role==="assistant");if(l===-1)return e;const u=a[l],d=e.messagesStreamMeta??{},f=d[i]??{lastSeq:null,lastText:jc(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}=Cx(u.content,t.delta,f,h);if(!x)return e;const g={...u,content:p},y=Ac(a,l,g),b={...d,[i]:v};return{...e,messages:y,messagesStreamMeta:b}}if(t.type==="message_end"){const i=e.assemblingId??_c(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?wx(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=kx(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==="state_history"){const i=ji(t),a=i.interrupt,l=i.latest,u=a===null?Nc(e.messages):e.messages;return{...e,messages:u,pendingInterrupt:a,lastCheckpointId:(l==null?void 0:l.checkpointId)??e.lastCheckpointId,lastCheckpointNs:(l==null?void 0:l.checkpointNs)??e.lastCheckpointNs}}return e}function Ri(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 Ac(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Nc(e){let t=!1;const n=e.map(r=>{const o=(r.content??[]).filter(s=>s.type!=="interrupt");return o.length!==r.content.length?(t=!0,{...r,content:o}):r});return t?n:e}function _c(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function bx(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 wx(e,t,n){return bx(e,t,r=>({...r,content:Sx(r.content,n)}))}function Sx(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=Pc(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 jc(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function Cx(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??jc(e);let l="",u=e.slice();if(s){const f=Pc(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 Rc(e){return e.replace(/\s+/g," ").trim()}function Pc(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=Rc(e),o=Rc(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 kx(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 Ac(e,r,s)}return e}function Tx(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function Oc(e={}){const t=w.useMemo(()=>Mn(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),C=w.useRef(null),E=w.useRef(!0),k=w.useRef(0),T=w.useCallback(j=>{o(j)},[]),I=w.useCallback(()=>{var j;(j=C.current)==null||j.abort(),C.current=null,l(!1),b(!1),k.current=0,g(0)},[]),_=w.useCallback(()=>{h(""),v(null),d(null)},[]),P=w.useCallback((j,H,F)=>{C.current&&(C.current.abort(),C.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&h("");const U=new AbortController;return C.current=U,(async()=>{var G,W,ne,$,z,se,M,Y;const D=ce=>{var be;try{const ge=JSON.parse(JSON.stringify(ce));return(be=ge==null?void 0:ge.payload)!=null&&be.files_info&&Array.isArray(ge.payload.files_info)&&(ge.payload.files_info=ge.payload.files_info.map(ye=>({...ye,data:ye!=null&&ye.data?`<base64 ${String(ye.data).length} chars>`:ye==null?void 0:ye.data}))),ge}catch{return ce}};try{let ce={};try{if(r)ce={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const He=window.__AUTH_TOKEN__,Qe=((G=window.localStorage)==null?void 0:G.getItem("authToken"))||null;let Ze=null;try{const wt=(W=window.localStorage)==null?void 0:W.getItem("chat-settings");wt&&(Ze=((ne=JSON.parse(wt))==null?void 0:ne.apiKey)||null)}catch{}const Pe=He||Qe||Ze||null;Pe&&(ce={Authorization:`Bearer ${Pe}`})}}catch{}console.debug("[use-chat] POST",t+n,D(j));const be=await fetch(t+n,{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream",...ce,...s.current},body:JSON.stringify(j),signal:U.signal,credentials:i});if(!be.ok||!be.body){const je=await be.text().catch(()=>"");throw console.debug("[use-chat] non-OK response",be.status,je==null?void 0:je.slice(0,500)),new Error(`stream ${be.status}${je?": "+je:""}`)}b(!0);const ge=be.body.getReader(),ye=new TextDecoder;let K="",L=[];k.current=0,g(0);let Z=0,ee=null;const pe=()=>{if(L.length){const je=L.join("");L=[],E.current&&h(He=>He+je)}ee=null},oe=()=>{typeof window<"u"&&ee==null&&(ee=requestAnimationFrame(pe))};let ie=Date.now();const Be=setInterval(()=>{var je;if(Date.now()-ie>6e4){const He="Stream idle timeout";d(He),U.abort(),(je=F==null?void 0:F.onError)==null||je.call(F,He)}},5e3),Je=1024*1024;try{const je=be.headers.get("X-Thread-Id")||be.headers.get("x-thread-id"),He=be.headers.get("X-Thread-Created")||be.headers.get("x-thread-created"),Qe=je??null,Ze=String(He??"").toLowerCase()==="true";for(($=F==null?void 0:F.onOpen)==null||$.call(F,{threadId:Qe,created:Ze});;){const{value:Pe,done:wt}=await ge.read();if(wt)break;K+=ye.decode(Pe,{stream:!0}),K.length>Je&&(K="",console.warn("Stream buffer reset: exceeded 1MB"));let Ct;for(;(Ct=K.indexOf(`
|
|
34
|
+
`):" "+ic(i[0]):"as no adapter specified";throw new Re("There is no suitable adapter to dispatch the request "+a,"ERR_NOT_SUPPORT")}return o},adapters:ki};function Ti(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new Ar(null,e)}function lc(e){return Ti(e),e.headers=Ft.from(e.headers),e.data=Ci.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),ac.getAdapter(e.adapter||Jr.adapter,e)(e).then(function(r){return Ti(e),r.data=Ci.call(e,e.transformResponse,r),r.headers=Ft.from(r.headers),r},function(r){return ql(r)||(Ti(e),r&&r.response&&(r.response.data=Ci.call(e,e.transformResponse,r.response),r.response.headers=Ft.from(r.response.headers))),Promise.reject(r)})}const cc="1.12.2",Uo={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{Uo[e]=function(r){return typeof r===e||"a"+(t<1?"n ":" ")+e}});const uc={};Uo.transitional=function(t,n,r){function o(s,i){return"[Axios v"+cc+"] Transitional option '"+s+"'"+i+(r?". "+r:"")}return(s,i,a)=>{if(t===!1)throw new Re(o(i," has been removed"+(n?" in "+n:"")),Re.ERR_DEPRECATED);return n&&!uc[i]&&(uc[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}},Uo.spelling=function(t){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${t}`),!0)};function qg(e,t,n){if(typeof e!="object")throw new Re("options must be an object",Re.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 Re("option "+s+" must be "+l,Re.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new Re("Unknown option "+s,Re.ERR_BAD_OPTION)}}const Wo={assertOptions:qg,validators:Uo},gn=Wo.validators;let ir=class{constructor(t){this.defaults=t||{},this.interceptors={request:new Ul,response:new Ul}}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=sr(this.defaults,n);const{transitional:r,paramsSerializer:o,headers:s}=n;r!==void 0&&Wo.assertOptions(r,{silentJSONParsing:gn.transitional(gn.boolean),forcedJSONParsing:gn.transitional(gn.boolean),clarifyTimeoutError:gn.transitional(gn.boolean)},!1),o!=null&&(M.isFunction(o)?n.paramsSerializer={serialize:o}:Wo.assertOptions(o,{encode:gn.function,serialize:gn.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),Wo.assertOptions(n,{baseUrl:gn.spelling("baseURL"),withXsrfToken:gn.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let i=s&&M.merge(s.common,s[n.method]);s&&M.forEach(["delete","get","head","post","put","patch","common"],v=>{delete s[v]}),n.headers=Ft.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=[lc.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=lc.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=sr(this.defaults,t);const n=Jl(t.baseURL,t.url,t.allowAbsoluteUrls);return Hl(n,t.params,t.paramsSerializer)}};M.forEach(["delete","get","head","options"],function(t){ir.prototype[t]=function(n,r){return this.request(sr(r||{},{method:t,url:n,data:(r||{}).data}))}}),M.forEach(["post","put","patch"],function(t){function n(r){return function(s,i,a){return this.request(sr(a||{},{method:t,headers:r?{"Content-Type":"multipart/form-data"}:{},url:s,data:i}))}}ir.prototype[t]=n(),ir.prototype[t+"Form"]=n(!0)});let Gg=class km{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 Ar(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 km(function(o){t=o}),cancel:t}}};function Yg(e){return function(n){return e.apply(null,n)}}function Xg(e){return M.isObject(e)&&e.isAxiosError===!0}const Ei={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(Ei).forEach(([e,t])=>{Ei[t]=e});function dc(e){const t=new ir(e),n=Il(ir.prototype.request,t);return M.extend(n,ir.prototype,t,{allOwnKeys:!0}),M.extend(n,t,null,{allOwnKeys:!0}),n.create=function(o){return dc(sr(e,o))},n}const ut=dc(Jr);ut.Axios=ir,ut.CanceledError=Ar,ut.CancelToken=Gg,ut.isCancel=ql,ut.VERSION=cc,ut.toFormData=$o,ut.AxiosError=Re,ut.Cancel=ut.CanceledError,ut.all=function(t){return Promise.all(t)},ut.spread=Yg,ut.isAxiosError=Xg,ut.mergeConfig=sr,ut.AxiosHeaders=Ft,ut.formToJSON=e=>Vl(M.isHTMLForm(e)?new FormData(e):e),ut.getAdapter=ac.getAdapter,ut.HttpStatusCode=Ei,ut.default=ut;const{Axios:sT,AxiosError:iT,CanceledError:aT,isCancel:lT,CancelToken:cT,VERSION:uT,all:dT,Cancel:fT,isAxiosError:hT,spread:pT,toFormData:mT,AxiosHeaders:gT,HttpStatusCode:xT,formToJSON:yT,getAdapter:vT,mergeConfig:bT}=ut,fc=typeof window<"u"?window.__API_BASE_URL__:void 0,hc=fc?Pn(fc):void 0;function Pn(e){const n=(e!=null&&e.trim()?e.trim():"/api/chat").replace(/\/+$/,"");return n?n.endsWith("/chat")?n:`${n}/chat`:"/api/chat"}let Vo=null;const Ii=new Set;function pc(){return Vo}function Ai(e){Vo=e,Ii.forEach(t=>t(e))}function mc(e){return Ii.add(e),()=>Ii.delete(e)}const Yt=ut.create({...hc?{baseURL:hc}:{},timeout:3e4,withCredentials:!0});Yt.interceptors.request.use(e=>(Vo&&(e.headers.Authorization=`Bearer ${Vo}`),e)),Yt.interceptors.response.use(e=>e,e=>Promise.reject(e));async function sn(e,t){return Yt.defaults.baseURL?(await Yt.get(e,t)).data:Promise.reject(new Error("API base URL is not configured"))}async function gc(e,t,n){return Yt.defaults.baseURL?(await Yt.post(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function xc(e,t,n){return Yt.defaults.baseURL?(await Yt.put(e,t,n)).data:Promise.reject(new Error("API base URL is not configured"))}async function yc(e,t){return Yt.defaults.baseURL?(await Yt.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 vc{get baseUrl(){const t=Yt.defaults.baseURL;return t?Pn(String(t)):""}updateConfig(t){t.baseUrl&&(Yt.defaults.baseURL=Pn(String(t.baseUrl))),t.authToken!==void 0&&Ai(t.authToken)}getAuthToken(){return pc()}setAuthToken(t){Ai(t)}onTokenChange(t){return mc(t)}async listThreads(){const t=await sn("/threads"),n=xn(t);return(n==null?void 0:n.items)??(t==null?void 0:t.items)??[]}async createThread(t){const r=await gc("/threads",t?{title:t}:void 0);return xn(r)}async updateThread(t,n){const r=await xc(`/threads/${t}`,{title:n});return xn(r)}async deleteThread(t){const n=await yc(`/threads/${t}`);return xn(n)}async threadInfo(t){const n=await sn(`/threads/${t}/info`);return xn(n)}async listAgents(){const t=await sn("/agents"),n=xn(t);return(n==null?void 0:n.items)??[]}async getAgent(t){const n=await sn(`/agents/${t}`);return xn(n)}async getAgentSchema(t){const n=await sn(`/agents/${t}/schema`);return xn(n)}async getState(t){const n=await sn(`/threads/${t.threadId}/state`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return xn(n)}async getStateHistory(t){const n=await sn(`/threads/${t.threadId}/state/history`,{params:{thread_id:t.threadId,checkpoint_id:t.checkpointId,checkpoint_ns:t.checkpointNs}});return xn(n)}}const zn=new vc,bc=w.createContext(null);function Jg({children:e,apiConfig:t}){const n=zn;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(bc.Provider,{value:r,children:e})}function Ni(){const e=w.useContext(bc);if(!e)throw new Error("useApi must be used within ApiProvider");return e}async function Zg(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 Qg(e,t=[],n,r,o,s){const i=[],a=[];for(const l of t)try{const u=await Zg(l);a.push({filename:l.name,data:u,mime_type:l.type||"application/octet-stream"})}catch{}return{contentParts:i,filesInfo:a}}const ex={human:"user",user:"user",ai:"assistant",assistant:"assistant",tool:"tool",function:"tool",system:"system"};function _i(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 Qr(e,t){return`${e??""}::${t??""}`}function ji(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(!_i(r))return{threadId:n,latest:null,checkpoints:[],interrupt:null,snapshots:{}};const{orderedSnapshots:o,snapshotMap:s}=nx(t),i=wc(r,0);return{threadId:n,latest:i,checkpoints:o,interrupt:(i==null?void 0:i.interrupt)??null,snapshots:s}}function wc(e,t){if(!_i(e))return null;const n=e.values??{messages:[]},r=Array.isArray(n==null?void 0:n.messages)?n.messages:[],{messages:o,...s}=n,i=Object.keys(s).length?s:null,a=e.tasks,l=Array.isArray(a)?a.filter(O=>!!O&&typeof O=="object").map(O=>({...O})):a===null?null:void 0,u=r.map((O,j)=>ux(O,j)).filter(O=>!!O),d=Bt(e.config),f=Bt(d==null?void 0:d.configurable),h=lt(f,["checkpoint_id","checkpointId"]),p=lt(f,["checkpoint_ns","checkpointNs"]),v=Bt(e==null?void 0:e.parentConfig),x=Bt(v==null?void 0:v.configurable),g=lt(x,["checkpoint_id","checkpointId"])??null,y=lt(x,["checkpoint_ns","checkpointNs"])??null,b=e==null?void 0:e.createdAt,S=typeof b=="string"&&b.trim()?b:new Date(Date.now()-t).toISOString(),E=u[u.length-1]??null,k=Bt(e==null?void 0:e.metadata),T=lt(k,["branch_label","branchLabel"]),I=lt(x,["checkpoint_id","checkpointId"]),_=Array.isArray(e.next)?[...e.next]:(e==null?void 0:e.next)===null?null:void 0;return{messages:u,checkpointId:h??null,checkpointNs:p??null,nextCursor:g,nextCursorNs:y,interrupt:tx(a,u,t),createdAt:S,parentId:I??null,branchLabel:T??null,lastMessageId:(E==null?void 0:E.id)??null,hasMessages:u.length>0,messagesLen:u.length,metadata:k??null,config:d??null,parentConfig:v??null,next:_??null,tasks:l??null,values:i??null}}function tx(e,t,n){const r=lx(e,n);return r||ax(t,n)}function nx(e){const t=new Map;e.forEach((o,s)=>{if(!_i(o))return;const i=wc(o,s);if(!(i!=null&&i.checkpointId))return;const a=Qr(i.checkpointId,i.checkpointNs??null),l=t.get(a);if(!l){t.set(a,i);return}t.set(a,rx(l,i))});const n=Array.from(t.values());n.sort((o,s)=>Cc(s.createdAt??"")-Cc(o.createdAt??""));const r={};for(const[o,s]of t.entries())r[o]=s;return{orderedSnapshots:n,snapshotMap:r}}function rx(e,t){const n=Ko(e.metadata,t.metadata),r=Ko(e.config,t.config),o=Ko(e.parentConfig,t.parentConfig),s=sx(e.next,t.next),i=ix(e.tasks,t.tasks),a=ox(e.values,t.values);return{...e,metadata:n??null,config:r??null,parentConfig:o??null,next:s??null,tasks:i??null,values:a??null}}function Ko(e,t){return t&&typeof t=="object"?{...e&&typeof e=="object"?{...e}:{},...t}:t===null?e&&typeof e=="object"?{...e}:e??null:e&&typeof e=="object"?{...e}:e??void 0}function ox(e,t){return Ko(e,t)}function sx(e,t){return Array.isArray(t)?t.slice():t===null?Array.isArray(e)?e.slice():e??null:Array.isArray(e)?e.slice():e??void 0}function ix(e,t){return Array.isArray(t)?t.map(n=>({...n})):t===null?Array.isArray(e)?e.map(n=>({...n})):e??null:Array.isArray(e)?e.map(n=>({...n})):e??void 0}function ax(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 lx(e,t){if(!Array.isArray(e)||!e.length)return null;for(let n=e.length-1;n>=0;n--){const r=cx(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=eo(r.interrupts[s],`${o}-interrupt-${s}`);if(i)return i}if(r.state!==void 0&&r.state!==null){const s=eo(r.state,`${o}-state`);if(s)return s}}return null}function cx(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=Bt(e);if(!n)return null;const r=lt(n,["id","task_id","taskId"])??t,o=lt(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 eo(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=Sc(e,t);if(o)return o;if(Array.isArray(e)){for(let s=e.length-1;s>=0;s--){const i=eo(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=eo(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=eo(l,t,n+1,r);if(u)return u}}return null}function Sc(e,t){if(!e)return null;if(typeof e=="object"&&!Array.isArray(e)){const n=e,r=lt(n,["type","event","kind"]),o=lt(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=Sc(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 Cc(e){if(!e)return 0;const t=Date.parse(e);return Number.isFinite(t)?t:0}function ux(e,t){if(!e||typeof e!="object")return null;const n=e,r=Bt(e)??{},o=Bt(n.data)??r,s=String(n.type??o.type??o.role??"").toLowerCase(),i=ex[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=Bt(o.additional_kwargs)??Bt(o.additionalKwargs),d=Bt(o.response_metadata)??Bt(o.responseMetadata),f=lt(u,["createdAt","created_at"])??lt(o,["created_at","createdAt"]),h=lt(u,["checkpointId","checkpoint_id"]),p=lt(u,["checkpointNs","checkpoint_ns"]),v=dx(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=gx(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=fx((u==null?void 0:u.tool_calls)??o.tool_calls);if(b.length&&(x.content=[...x.content,...b]),i==="tool"){const S=px(o,x.content);S&&(x.content=S)}return x}function dx(e){if(!e)return[];if(Array.isArray(e))return e.map(t=>kc(t)).filter(t=>!!t);if(typeof e=="string")return e.trim()?[{type:"text",text:e.trim()}]:[];if(typeof e=="object"){const t=kc(e);return t?[t]:[]}return[]}function kc(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=lt(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=lt(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 hx(t)??null;if(n==="tool_end"){const o=lt(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=lt(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 fx(e){return Array.isArray(e)?e.map((t,n)=>{if(!t||typeof t!="object")return null;const r=t,o=lt(r,["id","call_id"]),s=Bt(r.function),i=lt(s,["name"])??"tool",a=s==null?void 0:s.arguments,l=Tc(a);return{type:"tool_call",id:o??`tool_call_${n}`,name:i,args:l}}).filter(t=>!!t):[]}function hx(e){const t=lt(e,["id","call_id"]),n=lt(e,["name"]);if(!t||!n)return null;const r=Tc(e.args??e.arguments);return{type:"tool_call",id:t,name:n,args:r}}function px(e,t){const n=lt(e,["tool_call_id","toolCallId","id"]);if(!n)return t;const r=e.content??e.output,o=typeof r=="string"?mx(r):r,s={type:"tool_end",toolCallId:n,output:o};return typeof e.error=="string"&&(s.error=e.error),[s]}function Tc(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 mx(e){try{return JSON.parse(e)}catch{return e}}function Bt(e){if(!(!e||typeof e!="object"||Array.isArray(e)))return{...e}}function lt(e,t){if(e)for(const n of t){const r=e[n];if(typeof r=="string"&&r.trim())return r}}function gx(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 xx(e){return e.type!=="thread_info"&&e.type!=="token"}const yx={messages:[],assemblingId:null,lastCheckpointId:null,lastCheckpointNs:null,toolIndex:{},lastBranch:null,messagesStreamMeta:{},pendingInterrupt:null};function vx(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:Ri(((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=Ri(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=Ri(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 Ic(e,t.payload.ev);case"batch":{const{events:r}=t.payload;return r.length?r.reduce((o,s)=>Ic(o,s),e):e}case"interrupt_response":return{...e,messages:Nc(e.messages),pendingInterrupt:null};default:return e}}function Ec(e=[]){const[t,n]=w.useReducer(vx,{...yx,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 Ic(e,t){var n,r,o,s;if(t.type==="message_start"&&t.role==="assistant"){const i=t.id,a=Tx(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??_c(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:jc(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}=Cx(u.content,t.delta,f,h);if(!x)return e;const g={...u,content:p},y=Ac(a,l,g),b={...d,[i]:v};return{...e,messages:y,messagesStreamMeta:b}}if(t.type==="message_end"){const i=e.assemblingId??_c(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?wx(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=kx(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==="state_history"){const i=ji(t),a=i.interrupt,l=i.latest,u=a===null?Nc(e.messages):e.messages;return{...e,messages:u,pendingInterrupt:a,lastCheckpointId:(l==null?void 0:l.checkpointId)??e.lastCheckpointId,lastCheckpointNs:(l==null?void 0:l.checkpointNs)??e.lastCheckpointNs}}return e}function Ri(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 Ac(e,t,n){return t<0||t>=e.length?e:[...e.slice(0,t),n,...e.slice(t+1)]}function Nc(e){let t=!1;const n=e.map(r=>{const o=(r.content??[]).filter(s=>s.type!=="interrupt");return o.length!==r.content.length?(t=!0,{...r,content:o}):r});return t?n:e}function _c(e){for(let t=e.length-1;t>=0;t--)if(e[t].role==="assistant")return e[t].id;return null}function bx(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 wx(e,t,n){return bx(e,t,r=>({...r,content:Sx(r.content,n)}))}function Sx(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=Pc(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 jc(e){return!e||!e.length?"":e.filter(t=>t.type==="text").map(t=>t.text??"").join("")}function Cx(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??jc(e);let l="",u=e.slice();if(s){const f=Pc(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 Rc(e){return e.replace(/\s+/g," ").trim()}function Pc(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=Rc(e),o=Rc(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 kx(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 Ac(e,r,s)}return e}function Tx(e){if(!e)return null;const t=e.split("/");return t[t.length-1]||null}function Oc(e={}){const t=w.useMemo(()=>Pn(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),E=w.useRef(!0),k=w.useRef(0),T=w.useCallback(j=>{o(j)},[]),I=w.useCallback(()=>{var j;(j=S.current)==null||j.abort(),S.current=null,l(!1),b(!1),k.current=0,g(0)},[]),_=w.useCallback(()=>{h(""),v(null),d(null)},[]),O=w.useCallback((j,U,L)=>{S.current&&(S.current.abort(),S.current=null),l(!0),d(null),e.autoAppendAssistant!==!1&&h("");const W=new AbortController;return S.current=W,(async()=>{var V,$,ne,F,B,le,z,oe;const R=pe=>{var ge;try{const me=JSON.parse(JSON.stringify(pe));return(ge=me==null?void 0:me.payload)!=null&&ge.files_info&&Array.isArray(me.payload.files_info)&&(me.payload.files_info=me.payload.files_info.map(ve=>({...ve,data:ve!=null&&ve.data?`<base64 ${String(ve.data).length} chars>`:ve==null?void 0:ve.data}))),me}catch{return pe}};try{let pe={};try{if(r)pe={Authorization:`Bearer ${r}`};else if(typeof window<"u"){const He=window.__AUTH_TOKEN__,nt=((V=window.localStorage)==null?void 0:V.getItem("authToken"))||null;let Qe=null;try{const pt=($=window.localStorage)==null?void 0:$.getItem("chat-settings");pt&&(Qe=((ne=JSON.parse(pt))==null?void 0:ne.apiKey)||null)}catch{}const je=He||nt||Qe||null;je&&(pe={Authorization:`Bearer ${je}`})}}catch{}console.debug("[use-chat] POST",t+n,R(j));const ge=await fetch(t+n,{method:"POST",headers:{"Content-Type":"application/json",Accept:"text/event-stream",...pe,...s.current},body:JSON.stringify(j),signal:W.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 me=ge.body.getReader(),ve=new TextDecoder;let Z="",D=[];k.current=0,g(0);let J=0,Q=null;const de=()=>{if(D.length){const Pe=D.join("");D=[],E.current&&h(He=>He+Pe)}Q=null},ee=()=>{typeof window<"u"&&Q==null&&(Q=requestAnimationFrame(de))};let se=Date.now();const Ge=setInterval(()=>{var Pe;if(Date.now()-se>6e4){const He="Stream idle timeout";d(He),W.abort(),(Pe=L==null?void 0:L.onError)==null||Pe.call(L,He)}},5e3),Ye=1024*1024;try{const Pe=ge.headers.get("X-Thread-Id")||ge.headers.get("x-thread-id"),He=ge.headers.get("X-Thread-Created")||ge.headers.get("x-thread-created"),nt=Pe??null,Qe=String(He??"").toLowerCase()==="true";for((F=L==null?void 0:L.onOpen)==null||F.call(L,{threadId:nt,created:Qe});;){const{value:je,done:pt}=await me.read();if(pt)break;Z+=ve.decode(je,{stream:!0}),Z.length>Ye&&(Z="",console.warn("Stream buffer reset: exceeded 1MB"));let xt;for(;(xt=Z.indexOf(`
|
|
36
36
|
|
|
37
|
-
`))>=0;){const
|
|
38
|
-
`)}function Ax({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(xx(p)){n(p);return}r==null||r(p)},[n,o,t,r]),{stream:a,stop:l,isStreaming:u,error:d,setToken:f}=Oc({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])}function Pi(e){return e==null?e:{...e}}function Nx(e){return e==null?e:{...e}}function _x(e){if(Array.isArray(e))return e.slice();if(e==null)return e}function jx(e){if(Array.isArray(e))return e.map(t=>({...t}));if(e==null)return e}function Qt(e,t={}){const n=t.cloneMessages??!1,r=Array.isArray(e==null?void 0:e.messages)?e.messages:[],o=Pi(e==null?void 0:e.metadata),s=Pi(e==null?void 0:e.config),i=Pi(e==null?void 0:e.parentConfig),a=_x(e==null?void 0:e.next),l=jx(e==null?void 0:e.tasks),u=Nx(e==null?void 0:e.values),d={checkpointId:(e==null?void 0:e.checkpointId)??null,checkpointNs:(e==null?void 0:e.checkpointNs)??null,createdAt:(e==null?void 0:e.createdAt)??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};return o!==void 0&&(d.metadata=o),s!==void 0&&(d.config=s),i!==void 0&&(d.parentConfig=i),a!==void 0&&(d.next=a),l!==void 0&&(d.tasks=l),u!==void 0&&(d.values=u),d}function Rx(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 Mc(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}}const Ko=300;function Dc(e,t=Ko){if(typeof window<"u"&&"requestIdleCallback"in window)try{window.requestIdleCallback(e,{timeout:t});return}catch{}window.setTimeout(e,t)}function lr(){return typeof window<"u"&&typeof window.localStorage<"u"}function Oi(e){if(!lr())return null;try{return window.localStorage.getItem(e)}catch{return null}}function Mi(e,t){if(!lr())return!1;try{return window.localStorage.setItem(e,t),!0}catch{return!1}}function Di(e){if(lr())try{window.localStorage.removeItem(e)}catch{}}const Px="cachedThreads",Ox="v1",Li=200;function Mx(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 Fi(e,t){return`cachedThreads:v1:${e}:${Mx(t||"anon")}`}function Dx(){const e=Oi(Px);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 Lx(e){const t=Oi(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 $i(e,t){Mi(e,JSON.stringify(t))}function zi(e){const t=Lx(e);if(t.length>0)return t;const n=Dx();if(n.length>0)try{$i(e,n.slice(0,Li))}catch{}return n}function qo(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 Bi(e){return e.order.map(t=>e.byId[t]).filter(Boolean)}function Hi(e,t){return`${e}${t}`}function Fx(e,t){const n=Oi(Hi(e,t));if(!n)return null;try{const r=JSON.parse(n);return typeof(r==null?void 0:r.threadId)!="string"?null:{threadId:r.threadId,snapshot:Qt(r.snapshot,{cloneMessages:!0}),updatedAt:typeof r.updatedAt=="number"?r.updatedAt:void 0}}catch{return null}}function $x(e,t,n=100){if(!lr())return;const r=Qt(t.snapshot,{cloneMessages:!0}),o={threadId:t.threadId,snapshot:{...r,messages:r.messages.slice(-n)},updatedAt:Date.now()},s=Hi(e,t.threadId),i=JSON.stringify(o);if(!Mi(s,i))try{const a=[];for(let l=0;l<window.localStorage.length;l++){const u=window.localStorage.key(l);if(!u||u===s||!u.startsWith(e))continue;const d=window.localStorage.getItem(u);if(!d){a.push({key:u,updatedAt:0});continue}try{const f=JSON.parse(d),h=typeof(f==null?void 0:f.updatedAt)=="number"&&Number.isFinite(f.updatedAt)?f.updatedAt:0;a.push({key:u,updatedAt:h})}catch{a.push({key:u,updatedAt:0})}}a.sort((l,u)=>l.updatedAt-u.updatedAt);for(const l of a)if(window.localStorage.removeItem(l.key),Mi(s,i))break}catch{}}function zx(e,t){Di(Hi(e,t))}function Bx(e){if(lr())try{for(let t=0;t<window.localStorage.length;t++){const n=window.localStorage.key(t);n&&n.startsWith(e)&&window.localStorage.removeItem(n)}}catch{}}const Lc=w.createContext(null),Fc=w.createContext(null),$c=w.createContext(null),Hx=w.createContext(!1),zc=50,Ux=750;function Bc(e,t,n){return`${e}__${t??""}__${n??""}`}function Go(e,t){return t&&typeof t=="object"?{...e&&typeof e=="object"?{...e}:{},...t}:t===null?e&&typeof e=="object"?{...e}:e??null:e&&typeof e=="object"?{...e}:e??void 0}function Wx(e,t){return Go(e,t)}function Vx(e,t){return Array.isArray(t)?t.slice():t===null?Array.isArray(e)?e.slice():e??null:Array.isArray(e)?e.slice():e??void 0}function Kx(e,t){return Array.isArray(t)?t.map(n=>({...n})):t===null?Array.isArray(e)?e.map(n=>({...n})):e??null:Array.isArray(e)?e.map(n=>({...n})):e??void 0}function Hc(e,t){const n=Go(e.metadata,t.metadata),r=Go(e.config,t.config),o=Go(e.parentConfig,t.parentConfig),s=Vx(e.next,t.next),i=Kx(e.tasks,t.tasks),a=Wx(e.values,t.values),l={};return n!==void 0&&(l.metadata=n??null),r!==void 0&&(l.config=r??null),o!==void 0&&(l.parentConfig=o??null),s!==void 0&&(l.next=s??null),i!==void 0&&(l.tasks=i??null),a!==void 0&&(l.values=a??null),l}function qx({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}=Ni(),d=w.useMemo(()=>Mn(u),[u]),f=w.useMemo(()=>{try{return new URL(u).host}catch{return"unknown"}},[u]),h=w.useMemo(()=>`threadPayload:${Ox}:${f}:`,[f]),p=w.useCallback(A=>Fx(h,A),[h]),v=w.useCallback((A,N=100)=>{$x(h,A,N)},[h]),x=w.useCallback(A=>{zx(h,A)},[h]),g=w.useCallback(()=>{Bx(h)},[h]),[y,b]=w.useState(()=>{var A;return Fi(f,(A=l.getAuthToken)==null?void 0:A.call(l))}),[C,E]=w.useState(()=>{var N;const A=zi(Fi(f,(N=l.getAuthToken)==null?void 0:N.call(l)));return qo(A)}),k=w.useMemo(()=>Bi(C),[C]),[T,I]=w.useState(t),[_,P]=w.useState(!1),[j,H]=w.useState(!1),[F,U]=w.useState(null),[D,G]=w.useState(null),[W,ne]=w.useState(null),[$,z]=w.useState([]),se=w.useCallback(()=>{const A=zi(y);w.startTransition(()=>{E(qo(A))})},[y]),[M,Y]=w.useState(!1),[ce,be]=w.useState(!1),[ge,ye]=w.useState(null),[K,L]=w.useState(void 0),[Z,ee]=w.useState(void 0),[pe,oe]=w.useState(void 0),{state:ie,dispatch:Be,seed:Je,prepend:je,pushUser:He,onEvent:Qe,reset:Ze}=Ec(),Pe=w.useRef(T);w.useEffect(()=>{Pe.current=T},[T]);const wt=w.useRef(!1),Ct=w.useRef([]),kt=w.useRef(null),ot=w.useRef(null),et=w.useRef(new Map),$e=w.useRef(T),ct=w.useRef(!1),vt=w.useRef(null),J=w.useRef(new Map),xe=w.useRef(new Map),ue=w.useRef(new Map),_e=w.useRef(new Map),Ve=w.useCallback(A=>{if(!A){z([]);return}const N=J.current.get(A);if(!N||!N.length){z([]);return}z(N.map(q=>Qt(q,{cloneMessages:!0})))},[]);w.useEffect(()=>{Ve(T)},[T,Ve]);const at=w.useCallback(()=>{var te;const A=_e.current;if(A.size<=zc)return;const N=Array.from(A.entries()).sort((le,Q)=>le[1].timestamp-Q[1].timestamp),q=A.size-zc;for(let le=0;le<q;le++){const Q=(te=N[le])==null?void 0:te[0];Q&&A.delete(Q)}},[]),Tt=w.useCallback((A,N,q)=>{if(!A)return;const te=q==="replace"?[]:J.current.get(A)??[],le=q==="replace"?N:[...N,...te];if(!le.length){q==="replace"&&J.current.set(A,[]);return}const Q=new Map;for(const Ue of le){if(!(Ue!=null&&Ue.checkpointId))continue;const Le=`${Ue.checkpointId}::${Ue.checkpointNs??""}`,Xe=Qt(Ue,{cloneMessages:!0}),xt=Q.get(Le);if(!xt){Q.set(Le,Xe);continue}const Rt=Hc(xt,Xe);Q.set(Le,{...xt,...Rt})}const ze=Array.from(Q.values()).sort((Ue,Le)=>{const Xe=Number.isFinite(Date.parse(Ue.createdAt??""))?Date.parse(Ue.createdAt??""):0;return(Number.isFinite(Date.parse(Le.createdAt??""))?Date.parse(Le.createdAt??""):0)-Xe});J.current.set(A,ze),A===Pe.current&&Ve(A)},[Ve]),rt=w.useCallback((A,N,q)=>{if(!A)return;const te=xe.current.get(A),le=q==="replace"||!te?new Map:new Map(te);if(N&&typeof N=="object")for(const[Q,ze]of Object.entries(N)){if(!(ze!=null&&ze.checkpointId))continue;const Ue=Q||Zr(ze.checkpointId,ze.checkpointNs??null);le.set(Ue,Qt(ze,{cloneMessages:!0}))}xe.current.set(A,le)},[]),ut=w.useCallback((A,N)=>{const{threadId:q,checkpointId:te=null,checkpointNs:le=null}=A,Q=Bc(q,te,le);if(N!=null&&N.force)ue.current.delete(Q),_e.current.delete(Q);else{if(N!=null&&N.preferCache){const Xe=_e.current.get(Q);if(Xe)return Promise.resolve(Xe.payload)}const Le=ue.current.get(Q);if(Le)return Le}const Ue=l.getStateHistory({threadId:q,checkpointId:te??void 0,checkpointNs:le??void 0}).then(Le=>(_e.current.set(Q,{payload:Le,timestamp:Date.now()}),at(),Le)).finally(()=>{ue.current.get(Q)===Ue&&ue.current.delete(Q)});return ue.current.set(Q,Ue),Ue},[l,at]),pt=w.useCallback((A,N)=>new Promise((q,te)=>{const le=async()=>{wt.current=!0;try{await A(),q()}catch(Q){te(Q)}finally{wt.current=!1;const Q=Ct.current.shift();Q&&Q().catch(()=>{})}};wt.current?Ct.current.push(le):le().catch(Q=>{te(Q)})}),[]),$n=w.useRef(k.length),sn=w.useRef(!1);w.useEffect(()=>{$n.current=k.length},[k.length]),w.useEffect(()=>{const A=ie.pendingInterrupt??Rx(ie.messages);Mc(W,A)||ne(A??null)},[W,ie.messages,ie.pendingInterrupt]);const jt=w.useCallback(async()=>{const A=$n.current>0;A||P(!0);try{const N=await l.listThreads();w.startTransition(()=>{E(q=>{const te=ze=>ze.map(Ue=>`${Ue.threadId}:${Ue.updatedAt??""}:${Ue.messageCount??""}`).join("|"),le=Bi(q);return te(le)===te(N)||N.length===0&&le.length>0&&!sn.current?q:qo(N)})}),U(null),sn.current||(sn.current=!0)}catch(N){i==null||i(String(N)),console.error("[ChatSessionProvider] Failed to refresh threads:",N),U(String(N))}finally{A||P(!1)}},[l,i]),Cr=w.useRef(!1),tr=w.useRef(null),Et=w.useRef(null),an=w.useRef(""),gn=w.useCallback((A,N)=>{if(!lr())return;Et.current!==null&&(window.clearTimeout(Et.current),Et.current=null);const q=A.map(le=>`${le.threadId}:${le.updatedAt??""}:${le.messageCount??""}`).join("|");if(A.length===0){try{Di(y)}catch{}an.current="";return}if(q===an.current)return;const te=()=>{try{const le=A.slice(0,Li);$i(y,le),an.current=q}catch{}finally{Et.current=null}};if(N!=null&&N.immediate){te();return}Et.current=window.setTimeout(()=>{Dc(te)},Ko)},[y]),kr=w.useCallback(()=>{gn(k,{immediate:!0})},[gn,k]),Jt=w.useCallback((A,N,q,te)=>{var Sm;const le=q??Pe.current;if(!le)return;const Q=Qt(A),ze=le===Pe.current,Ue=(te==null?void 0:te.persist)!==!1;if(N==="replace"){if(Ue){const Nt={threadId:le,snapshot:Qt(A,{cloneMessages:!0})};et.current.set(le,Nt),$e.current=le}if(!ze)return;Je(Q.messages,{checkpointId:Q.checkpointId??null,checkpointNs:Q.checkpointNs??null,pendingInterrupt:Q.interrupt??null}),ne(Q.interrupt??null),ye(Q.nextCursor??null),Y(!!Q.nextCursor),L(Q.checkpointId??void 0),ee(Q.checkpointNs??void 0),oe(Q.nextCursorNs??void 0);return}const Le=et.current.get(le),Xe=(Le==null?void 0:Le.snapshot)??null,xt=Array.isArray(Xe==null?void 0:Xe.messages)?Xe.messages:[],Rt=Qt(Xe),Rn=Array.isArray(A==null?void 0:A.messages)?A.messages:[],Pt=new Set,Ot=[...Rn,...xt].filter(Nt=>{const Cl=Nt==null?void 0:Nt.id;return Cl?Pt.has(Cl)?!1:(Pt.add(Cl),!0):!0}),No=Hc(Rt,Q),_o={checkpointId:Rt.checkpointId??Q.checkpointId??null,checkpointNs:Rt.checkpointNs??Q.checkpointNs??null,createdAt:Q.createdAt??Rt.createdAt??null,parentId:Q.parentId??Rt.parentId??null,branchLabel:Q.branchLabel??Rt.branchLabel??null,lastMessageId:((Sm=Ot[Ot.length-1])==null?void 0:Sm.id)??null,messagesLen:Ot.length,hasMessages:Ot.length>0,messages:Ot,nextCursor:Q.nextCursor??Rt.nextCursor??null,nextCursorNs:Q.nextCursorNs??Rt.nextCursorNs??null,interrupt:Rt.interrupt??Q.interrupt??null,...No};if(et.current.set(le,{threadId:le,snapshot:Qt(_o,{cloneMessages:!0})}),!ze)return;Rn.length&&je(Rn);const Pn=A&&Object.prototype.hasOwnProperty.call(A,"checkpointId")?A.checkpointId:void 0,jo=A&&Object.prototype.hasOwnProperty.call(A,"checkpointNs")?A.checkpointNs:void 0,On=A&&Object.prototype.hasOwnProperty.call(A,"nextCursor")?A.nextCursor:void 0,Sl=A&&Object.prototype.hasOwnProperty.call(A,"nextCursorNs")?A.nextCursorNs:void 0;ye(Nt=>On!==void 0?On??Nt??null:Nt??null),Y(Nt=>On!==void 0?!!On:Nt),L(Nt=>Pn!==void 0?Pn??Nt??void 0:Nt??void 0),ee(Nt=>jo!==void 0?jo??Nt??void 0:Nt??void 0),oe(Nt=>Sl!==void 0?Sl??void 0:Nt)},[je,Je,ne]),Tr=w.useCallback(A=>{if(A.threadId!=null&&A.threadId!==Pe.current)return;const N=Qt(A.snapshot,{cloneMessages:!0});Je(N.messages,{checkpointId:N.checkpointId??null,checkpointNs:N.checkpointNs??null,pendingInterrupt:N.interrupt??null}),ne(N.interrupt??null),ye(N.nextCursor??null),Y(!!N.nextCursor),L(N.checkpointId??void 0),ee(N.checkpointNs??void 0),oe(N.nextCursorNs??void 0),$e.current=A.threadId,Ve(A.threadId??Pe.current??null)},[Je,ne,Ve]),jn=w.useCallback(A=>{if(!A)return;et.current.delete(A),x(A),J.current.delete(A),xe.current.delete(A),A===Pe.current&&z([]);const N=`${A}__`;for(const q of ue.current.keys())q.startsWith(N)&&ue.current.delete(q);for(const q of _e.current.keys())q.startsWith(N)&&_e.current.delete(q);$e.current===A&&($e.current=null)},[x]),xn=w.useCallback(()=>{const A=Pe.current;A&&jn(A),Ze([]),Y(!1),be(!1),ye(null),L(void 0),ee(void 0),oe(void 0)},[jn,Ze]),nr=w.useCallback(({from:A,to:N})=>{const q=Pe.current;q&&console.warn(`[ChatSessionProvider] Stream sequence gap detected (${A} -> ${N}) for thread ${q}`)},[]),Io=w.useCallback(A=>{const N=A.threadId;console.log("[ChatSessionProvider] 📥 Handling thread_info event:",{threadId:N,title:A.title,created:A.created,currentThreads:k.length});const q={threadId:N,title:A.title||`Thread ${N.slice(0,8)}`,createdAt:A.createdAt||new Date().toISOString(),updatedAt:A.updatedAt||new Date().toISOString(),messageCount:A.messageCount||0};Pe.current!==N&&(!Pe.current&&ie.messages.length<=1&&(ot.current=N),I(N)),w.startTransition(()=>{E(te=>{const le=te.byId[N];return le?le.title===q.title&&le.updatedAt===q.updatedAt&&le.messageCount===q.messageCount?te:{byId:{...te.byId,[N]:q},order:te.order}:{byId:{...te.byId,[N]:q},order:[N,...te.order]}})})},[ie.messages.length]),{startStream:Ur,stop:Wr,isStreaming:rr,error:S,setAuthToken:R}=Ax({baseUrl:d,onThreadInfo:Io,onMessageEvent:Qe,onUnhandledEvent:A=>{console.warn(`[ChatSessionProvider] Unhandled stream event: ${A.type}`,A)},onSequenceGap:nr});w.useEffect(()=>{Cr.current=rr},[rr]),w.useEffect(()=>{if(!lr())return;Et.current!==null&&(window.clearTimeout(Et.current),Et.current=null);const A=k.map(q=>`${q.threadId}:${q.updatedAt??""}:${q.messageCount??""}`).join("|");if(k.length===0){try{Di(y)}catch{}an.current="";return}if(A===an.current)return;const N=()=>{try{const q=k.slice(0,Li);$i(y,q),an.current=A}catch{}finally{Et.current=null}};return Et.current=window.setTimeout(()=>{Dc(N),Et.current=null},Ko),()=>{Et.current!==null&&(window.clearTimeout(Et.current),Et.current=null)}},[k,gn]),w.useEffect(()=>{var te;const A=l.getAuthToken();R(A);const N=le=>{const Q=Fi(f,le);vt.current!==Q&&(vt.current=Q,ct.current=!1),b(Q);const ze=zi(Q);w.startTransition(()=>{E(qo(ze))}),ct.current||(ct.current=!0,jt().catch(()=>{}))};N(A);const q=(te=l.onTokenChange)==null?void 0:te.call(l,le=>{R(le),g(),ue.current.clear(),_e.current.clear(),N(le)});return()=>{q==null||q()}},[l,f,R,g,jt]);const B=w.useCallback(async A=>{var te;const N=`Thread ${(te=crypto.randomUUID)==null?void 0:te.call(crypto)}`,q={threadId:N,title:A||"New Chat",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),messageCount:0};E(le=>({byId:{...le.byId,[N]:q},order:[N,...le.order]})),I(N);try{const le=await l.createThread(A),Q=typeof le=="string"?le:le.threadId;return E(ze=>{const Ue=ze.byId[N];if(!Ue)return ze;const Le={...ze.byId};delete Le[N],Le[Q]={...Ue,threadId:Q};const Xe=ze.order.map(xt=>xt===N?Q:xt);return{byId:Le,order:Xe}}),I(Q),setTimeout(()=>jt(),10),U(null),Q}catch(le){throw E(Q=>{if(!Q.byId[N])return Q;const ze={...Q.byId};delete ze[N];const Ue=Q.order.filter(Le=>Le!==N);return{byId:ze,order:Ue}}),I(null),U(String(le)),le}},[l,jt]),ae=w.useCallback(async A=>{try{await l.deleteThread(A);let N=null;E(q=>{if(!q.byId[A])return q;const te={...q.byId};delete te[A];const le=q.order.filter(ze=>ze!==A),Q={byId:te,order:le};return N=Bi(Q),Q}),N&&gn(N,{immediate:!0}),jn(A),Pe.current===A&&(ot.current=A,I(null),Pe.current=null,$e.current=null,xn()),await jt(),U(null)}catch(N){throw U(String(N)),N}},[l,xn,jn,jt,gn]),ke=w.useCallback(async(A,N)=>{try{await l.updateThread(A,N),E(q=>{const te=q.byId[A];return te?{byId:{...q.byId,[A]:{...te,title:N}},order:q.order}:q}),U(null)}catch(q){throw await jt(),U(String(q)),q}},[l,jt]),Ae=w.useCallback(async(A,N,q,te=!1)=>{await pt(async()=>{if(ot.current===A&&!te){ot.current=null;return}if(kt.current===A&&!te)return;I(Pt=>Pt===A?Pt:A),Pe.current=A;const ze=Bc(A,N??null,q??null),Ue=_e.current.get(ze),Le=!te&&!N&&!q&&Ue&&Date.now()-Ue.timestamp<Ux,Xe=!te&&!N&&!q;let xt=!1;if(Xe){const Pt=et.current.get(A);if(Pt)Tr(Pt),xt=!0;else{const Ot=p(A);Ot&&(et.current.set(A,Ot),Tr(Ot),xt=!0)}}const Rt=te||!xt||!!N||!!q,Rn=async Pt=>{Pt&&H(!0),kt.current=A;try{const Ot=await ut({threadId:A,checkpointId:N,checkpointNs:q},{force:te}),{latest:No,checkpoints:_o,snapshots:Pn}=ji(Ot);Jt(No,"replace",A),Tt(A,_o,"replace"),rt(A,Pn,"replace"),G(null)}catch(Ot){throw(!xt||te||Pt)&&(i==null||i(String(Ot))),G(String(Ot)),Ot}finally{kt.current=null,Pt&&H(!1)}};Rt?await Rn(!0):Xe&&xt&&!Le&&Rn(!1).catch(Pt=>{console.warn("[ChatSessionProvider] Background refresh failed:",Pt)})},`loadThread-${A}`)},[Tr,Jt,pt,ut,i,Tt,rt]),De=w.useCallback(async()=>{await pt(async()=>{const A=Pe.current;A&&jn(A),ot.current=null,I(null),Pe.current=null,$e.current=null,xn(),L(void 0),ee(void 0),oe(void 0),z([]);try{localStorage.removeItem("lastThreadId")}catch(N){console.warn("[ChatSessionProvider] Failed to clear lastThreadId:",N)}},"clearCurrentThread")},[xn,jn,pt]),Oe=w.useCallback(async(A,N)=>{var Q;const q=Pe.current;if(!q)throw new Error("No active thread");const te=Zr(A,N??null),le=(Q=xe.current.get(q))==null?void 0:Q.get(te);if(le){await pt(async()=>{Jt(le,"replace",q,{persist:!1})},`navigateToCheckpoint-${q}-${te}`);return}await Ae(q,A,N??void 0,!0)},[Jt,pt,Ae]),It=w.useCallback(async()=>{if(!Pe.current)throw new Error("No active thread");await Ae(Pe.current,void 0,void 0,!0)},[Ae]),dt=w.useCallback(async()=>{if(!Pe.current)throw new Error("No active thread");if(ce||!M)return;const A=ge;if(A){be(!0);try{const N=Pe.current,q=await ut({threadId:N,checkpointId:A??K??null,checkpointNs:pe??Z??null}),{latest:te,checkpoints:le,snapshots:Q}=ji(q),ze=N?xe.current.get(N):null;let Ue=le.length>0;if(Ue&&ze&&ze.size>0&&(Ue=le.some(Le=>{if(!(Le!=null&&Le.checkpointId))return!1;const Xe=Zr(Le.checkpointId,Le.checkpointNs??null);return!ze.has(Xe)})),!Ue){ye(null),oe(void 0),Y(!1),G(null);return}Jt(te,"prepend",N??void 0),N&&(Tt(N,le,"prepend"),rt(N,Q,"prepend")),G(null)}catch(N){throw G(String(N)),N}finally{be(!1)}}},[Jt,ut,M,K,Z,pe,ge,ce,Tt,rt]),ht=w.useCallback(A=>{if(A!=null&&A.threadId){if(A.checkpointId){const N=Zr(A.checkpointId,A.checkpointNs??null),q=Qt({...A,interrupt:A.interrupt??null},{cloneMessages:!0});rt(A.threadId,{[N]:q},"prepend")}Jt(A,"replace",A.threadId)}},[Jt,rt]),At=w.useCallback(async(A,N)=>{var jo;const q=Pe.current,te=(A==null?void 0:A.text)??"",le=(A==null?void 0:A.attachments)??[],Q=le.length?le:(N==null?void 0:N.attachments)??[],ze={...(N==null?void 0:N.payloadExtras)??{},...(A==null?void 0:A.payload)??{}};if(!q&&!Object.keys(ze).length&&Q.length===0&&!te.trim()){console.warn("[ChatSessionProvider] Nothing to submit - skipping");return}!q&&!ze.messages&&console.warn("[ChatSessionProvider] No thread ID - message will create new thread");const{contentParts:Ue,filesInfo:Le}=await Qg(l,Q),Xe=[...Ue];te&&te.trim()&&Xe.push({type:"text",text:te.trim()});const xt=!!q,Rt=xt?(N==null?void 0:N.checkpointId)??ie.lastCheckpointId??void 0:void 0,Rn=xt?(N==null?void 0:N.checkpointNs)??ie.lastCheckpointNs??void 0:void 0,Pt={id:((jo=crypto.randomUUID)==null?void 0:jo.call(crypto))||`user-${Date.now()}`,role:"user",content:Xe,createdAt:new Date().toISOString(),...Rt!=null?{checkpointId:Rt}:{},...Rn!=null?{checkpointNs:Rn}:{}};Xe.length>0&&He(Pt);const Ot={...Pt,content:Xe},No=Q.length>0,_o={messages:Xe.length>0?[Ot]:[],files_info:Le,...o&&No&&s?{active_agent:s}:{},...ze},Pn={threadId:q??null,payload:_o,checkpointId:Rt??null,checkpointNs:Rn??null,nodeFilter:(N==null?void 0:N.nodeFilter)??null,config:N==null?void 0:N.config,command:(N==null?void 0:N.command)??null};Pn.threadId||delete Pn.threadId,Pn.command||delete Pn.command,Ur(Pn,{onError:On=>{console.warn("[ChatSessionProvider] Stream error:",On)},onOpen:({threadId:On})=>{!Pe.current&&On&&(ie.messages.length<=1&&(ot.current=On),I(On))},onGap:nr})},[l,o,s,nr,ie.lastCheckpointId,ie.lastCheckpointNs,ie.messages.length,He,Ur]),zn=w.useCallback(async(A,N,q)=>{if(!Pe.current)throw new Error("No active thread to handle interrupt");const le=N?q??!0:!1;try{try{Be({type:"interrupt_response",payload:{interruptId:A}})}catch(Q){console.warn("[ChatSessionProvider] optimistic interrupt_response dispatch failed:",Q)}await At({payload:{}},{checkpointId:ie.lastCheckpointId??void 0,checkpointNs:ie.lastCheckpointNs??void 0,command:{kind:"resume",value:le}}),ne(null)}catch(Q){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${A}:`,Q),Q}},[Be,ie.lastCheckpointId,ie.lastCheckpointNs,At]);w.useEffect(()=>{if(a==null||a(T),T)try{localStorage.setItem("lastThreadId",T)}catch(A){console.warn("[ChatSessionProvider] Failed to persist lastThreadId:",A)}},[T,a]),w.useEffect(()=>((async()=>{try{if(jt().catch(N=>{console.error("[ChatSessionProvider] Failed to refresh threads (background):",N),i==null||i(String(N))}),!r&&!t)try{const N=localStorage.getItem("lastThreadId");N&&(I(N),n&&await Ae(N))}catch(N){console.warn("[ChatSessionProvider] Failed to restore last thread:",N)}else t&&n&&await Ae(t)}catch(N){console.error("[ChatSessionProvider] Initialization failed:",N),i==null||i(String(N))}})(),()=>{}),[]),w.useEffect(()=>{const A=Pe.current;if(!A||$e.current!==A)return;ie.messages.length&&ie.messages[ie.messages.length-1];const N=Qt({checkpointId:ie.lastCheckpointId??null,checkpointNs:ie.lastCheckpointNs??null,messages:ie.messages.slice(),nextCursor:ge??null,nextCursorNs:pe??null,interrupt:ie.pendingInterrupt??W??null}),q=et.current.get(A),te=q==null?void 0:q.snapshot,le=!te||te.messages.length!==N.messages.length||te.messages.some((Le,Xe)=>{var xt;return(Le==null?void 0:Le.id)!==((xt=N.messages[Xe])==null?void 0:xt.id)}),Q=((te==null?void 0:te.checkpointId)??null)!==N.checkpointId||((te==null?void 0:te.checkpointNs)??null)!==N.checkpointNs,ze=((te==null?void 0:te.nextCursor)??null)!==N.nextCursor||((te==null?void 0:te.nextCursorNs)??null)!==N.nextCursorNs,Ue=!Mc((te==null?void 0:te.interrupt)??null,N.interrupt??null);if(le||Q||ze||Ue){const Le={threadId:A,snapshot:N};et.current.set(A,Le),tr.current&&window.clearTimeout(tr.current),tr.current=window.setTimeout(()=>{try{v(Le,100)}catch(Xe){console.warn("[ChatSessionProvider] Failed to persist thread payload:",Xe)}},Ko)}},[ge,pe,ie.lastCheckpointId,ie.lastCheckpointNs,ie.messages,ie.pendingInterrupt,W,v]);const Bn=w.useMemo(()=>({threads:k,currentThreadId:T,setCurrentThreadId:I,isLoading:_,error:F,actions:{createThread:B,deleteThread:ae,renameThread:ke,refreshThreads:()=>jt()},persistThreadsCache:kr,hydrateFromCache:se}),[k,T,_,F,B,ae,ke,jt,kr,se,I]),$t=w.useMemo(()=>{const A=ie.lastBranch??null,N=ie.assemblingId??null,q=A||N?{branchLabel:(A==null?void 0:A.branchLabel)??null,lastBranch:A,assemblingMessageId:N}:null;return{threadId:T,messages:ie.messages,interrupt:W,checkpoint:{id:ie.lastCheckpointId??null,namespace:ie.lastCheckpointNs??null},checkpoints:$,metadata:q,isLoading:j,isHistoryLoading:ce,error:D,hasMore:M,loadOlder:dt,seedFromSnapshot:ht,clearState:xn,navigateToCheckpoint:Oe,returnToLatest:It,loadThread:Ae,clearThread:De,respondToInterrupt:zn}},[De,xn,T,W,M,ce,j,dt,Ae,ie.assemblingId,ie.lastBranch,ie.lastCheckpointId,ie.lastCheckpointNs,ie.messages,Oe,zn,It,ht,D,$]),Ao=w.useMemo(()=>({isStreaming:rr,error:S,submit:At,send:At,stop:Wr,setAuthToken:R}),[rr,S,At,Wr,R]);return c.jsx(Hx.Provider,{value:!0,children:c.jsx($c.Provider,{value:Ao,children:c.jsx(Lc.Provider,{value:Bn,children:c.jsx(Fc.Provider,{value:$t,children:e})})})})}function Yo(){const e=w.useContext(Lc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function Xo(){const e=w.useContext(Fc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function Uc(){const e=w.useContext($c);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function Jo({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(Jg,{apiConfig:t,children:c.jsx(qx,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,enableFileAgentRouting:s,fileAgentId:i,onError:a,onThreadChange:l,children:e})})}function re(...e){return Em.twMerge(Tm.clsx(e))}const Gx=Ro.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?or.Slot:"button";return c.jsx(i,{className:re(Gx({variant:t,size:n,className:e})),ref:s,...o})});Ge.displayName="Button";const Wc=m.forwardRef(({className:e,...t},n)=>c.jsx("textarea",{className:re("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}));Wc.displayName="Textarea";function Yx({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),y=w.useRef(0),b=w.useRef(null);w.useEffect(()=>{p(e??""),b.current=null,g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[e,t]);const C=w.useCallback(()=>{const j=g.current;j&&(j.style.height="auto",j.style.height=`${j.scrollHeight}px`)},[]);w.useEffect(()=>{C()},[C]);const E=w.useCallback(async j=>{j&&j.preventDefault();const H=(h??"").trim();if(!H&&!f)return;const F=++y.current;b.current={id:F,shouldClear:!0},x(()=>{var U,D,G;try{const W=i(H);W&&typeof W.then=="function"?W.then(()=>{var ne,$;((ne=b.current)==null?void 0:ne.id)===F&&b.current.shouldClear&&(p(""),g.current&&(g.current.style.height="auto")),(($=b.current)==null?void 0:$.id)===F&&(b.current=null)}).catch(()=>{var ne;((ne=b.current)==null?void 0:ne.id)===F&&(b.current=null)}):(((U=b.current)==null?void 0:U.id)===F&&b.current.shouldClear&&(p(""),g.current&&(g.current.style.height="auto")),((D=b.current)==null?void 0:D.id)===F&&(b.current=null))}catch{((G=b.current)==null?void 0:G.id)===F&&(b.current=null)}})},[h,i,f]),k=w.useCallback(j=>{p(j.target.value),b.current&&(b.current.shouldClear=!1),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[]),T=w.useCallback(j=>{j.key==="Enter"&&!j.shiftKey?(j.preventDefault(),E()):j.key==="Escape"&&t&&(j.preventDefault(),a==null||a())},[E,t,a]),P=`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${t?"border-[hsl(var(--ring))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] dark:bg-[hsl(var(--card))] dark:text-[hsl(var(--card-foreground))]":""} ${d}`;return c.jsx("form",{onSubmit:j=>void E(j),className:`w-full ${u}`,children:c.jsxs("div",{className:"flex items-end gap-2",children:[c.jsx("div",{className:"flex-1",children:c.jsx(Wc,{ref:g,value:h,onChange:k,onKeyDown:T,placeholder:t?"Edit your message...":n,className:P,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(me.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(me.Send,{size:16})})})]})})}const Xx=w.memo(Yx),Zo=0,Un=1,Nr=2,Vc=4;function Kc(e){return()=>e}function Jx(e){e()}function qc(e,t){return n=>e(t(n))}function Gc(e,t){return()=>e(t)}function Zx(e,t){return n=>e(t,n)}function Ui(e){return e!==void 0}function Qx(...e){return()=>{e.map(Jx)}}function _r(){}function Qo(e,t){return t(e),e}function ey(e,t){return t(e)}function st(...e){return e}function Ye(e,t){return e(Un,t)}function Me(e,t){e(Zo,t)}function Wi(e){e(Nr)}function gt(e){return e(Vc)}function ve(e,t){return Ye(e,Zx(t,Zo))}function un(e,t){const n=e(Un,r=>{n(),t(r)});return n}function Yc(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Xc(e,t){return e===t}function it(e=Xc){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function Te(e){return t=>n=>{e(n)&&t(n)}}function de(e){return t=>qc(t,e)}function bn(e){return t=>()=>{t(e)}}function V(e,...t){const n=ty(...t);return(r,o)=>{switch(r){case Nr:Wi(e);return;case Un:return Ye(e,n(o))}}}function wn(e,t){return n=>r=>{n(t=e(t,r))}}function cr(e){return t=>n=>{e>0?e--:t(n)}}function Dn(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Fe(...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);Ye(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 ty(...e){return t=>e.reduceRight(ey,t)}function ny(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case Un:return s?n===s?void 0:(r(),n=s,t=Ye(e,s),t):(r(),_r);case Nr:r(),n=null;return}}}function X(e){let t=e;const n=Ke();return(r,o)=>{switch(r){case Zo:t=o;break;case Un:{o(t);break}case Vc:return t}return n(r,o)}}function Dt(e,t){return Qo(X(t),n=>ve(e,n))}function Ke(){const e=[];return(t,n)=>{switch(t){case Zo:e.slice().forEach(r=>{r(n)});return;case Nr:e.splice(0,e.length);return;case Un:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Kt(e){return Qo(Ke(),t=>ve(e,t))}function qe(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:ry(),singleton:n}}const ry=()=>Symbol();function oy(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 yt(...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);Ye(s,l=>{n[i]=l,r=r|a,r===o&&Me(t,n)})}),function(s,i){switch(s){case Nr:{Wi(t);return}case Un:return r===o&&i(n),Ye(t,i)}}}function Ce(e,t=Xc){return V(e,it(t))}function Vi(...e){return function(t,n){switch(t){case Nr:return;case Un:return Qx(...e.map(r=>Ye(r,n)))}}}var Wt=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e))(Wt||{});const sy={0:"debug",3:"error",1:"log",2:"warn"},iy=()=>typeof globalThis>"u"?window:globalThis,Wn=qe(()=>{const e=X(3);return{log:X((t,n,r=1)=>{var o;const s=(o=iy().VIRTUOSO_LOG_LEVEL)!=null?o:gt(e);r>=s&&console[sy[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function ur(e,t,n){return Ki(e,t,n).callbackRef}function Ki(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 ay(e,t,n,r,o,s,i,a,l){const u=w.useCallback(d=>{const f=ly(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?Jc("column-gap",getComputedStyle(d).columnGap,o):Jc("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return Ki(u,n,l)}function ly(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},Wt.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 Jc(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Wt.WARN),t==="normal"?0:parseInt(t??"0",10)}function Zc(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}=Ki(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 zt=qe(()=>{const e=Ke(),t=Ke(),n=X(0),r=Ke(),o=X(0),s=Ke(),i=Ke(),a=X(0),l=X(0),u=X(0),d=X(0),f=Ke(),h=Ke(),p=X(!1),v=X(!1),x=X(!1);return ve(V(e,de(({scrollTop:g})=>g)),t),ve(V(e,de(({scrollHeight:g})=>g)),i),ve(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}),eo={lvl:0};function Qc(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 tt(e){return e===eo}function to(e,t){if(!tt(e))return t===e.k?e.v:t<e.k?to(e.l,t):to(e.r,t)}function dn(e,t,n="k"){if(tt(e))return[-1/0,void 0];if(Number(e[n])===t)return[e.k,e.v];if(Number(e[n])<t){const r=dn(e.r,t,n);return r[0]===-1/0?[e.k,e.v]:r}return dn(e.l,t,n)}function qt(e,t,n){return tt(e)?nu(t,n,1):t===e.k?bt(e,{k:t,v:n}):t<e.k?ru(bt(e,{l:qt(e.l,t,n)})):ru(bt(e,{r:qt(e.r,t,n)}))}function jr(){return eo}function es(e,t,n){if(tt(e))return[];const r=dn(e,t)[0];return cy(Gi(e,r,n))}function qi(e,t){if(tt(e))return eo;const{k:n,l:r,r:o}=e;if(t===n){if(tt(r))return o;if(tt(o))return r;{const[s,i]=tu(r);return ts(bt(e,{k:s,l:eu(r),v:i}))}}else return t<n?ts(bt(e,{l:qi(r,t)})):ts(bt(e,{r:qi(o,t)}))}function dr(e){return tt(e)?[]:[...dr(e.l),{k:e.k,v:e.v},...dr(e.r)]}function Gi(e,t,n){if(tt(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(Gi(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(Gi(s,t,n))),a}function ts(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(Yi(t))return ou(bt(e,{lvl:n-1}));if(!tt(t)&&!tt(t.r))return bt(t.r,{l:bt(t,{r:t.r.l}),lvl:n,r:bt(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(Yi(e))return Xi(bt(e,{lvl:n-1}));if(!tt(r)&&!tt(r.l)){const o=r.l,s=Yi(o)?r.lvl-1:r.lvl;return bt(o,{l:bt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:Xi(bt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function bt(e,t){return nu(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 eu(e){return tt(e.r)?e.l:ts(bt(e,{r:eu(e.r)}))}function Yi(e){return tt(e)||e.lvl>e.r.lvl}function tu(e){return tt(e.r)?[e.k,e.v]:tu(e.r)}function nu(e,t,n,r=eo,o=eo){return{k:e,l:r,lvl:n,r:o,v:t}}function ru(e){return Xi(ou(e))}function ou(e){const{l:t}=e;return!tt(t)&&t.lvl===e.lvl?bt(t,{r:bt(e,{l:t.r})}):e}function Xi(e){const{lvl:t,r:n}=e;return!tt(n)&&!tt(n.r)&&n.lvl===t&&n.r.lvl===t?bt(n,{l:bt(e,{r:n.l}),lvl:t+1}):e}function cy(e){return Qc(e,({k:t,v:n})=>({index:t,value:n}))}function su(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function no(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const Ji=qe(()=>({recalcInProgress:X(!1)}),[],{singleton:!0});function iu(e,t,n){return e[ns(e,t,n)]}function ns(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 uy(e,t,n,r){const o=ns(e,t,r),s=ns(e,n,r,o);return e.slice(o,s+1)}function Vn(e,t){return Math.round(e.getBoundingClientRect()[t])}function rs(e){return!tt(e.groupOffsetTree)}function Zi({index:e},t){return t===e?0:t<e?-1:1}function dy(){return{groupIndices:[],groupOffsetTree:jr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:jr()}}function fy(e,t){let n=tt(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),tt(e)){e=qt(e,0,s);continue}const a=es(e,i-1,o+1);if(a.some(vy(r)))continue;let l=!1,u=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=qi(e,f)):(u=h!==s,l=!0),d>o&&o>=f&&h!==s&&(e=qt(e,o+1,h));u&&(e=qt(e,i,s))}return[e,n]}function hy(e){return typeof e.groupIndex<"u"}function py({offset:e},t){return t===e?0:t<e?-1:1}function ro(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=iu(t,e,Zi),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function au(e,t){if(!rs(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function lu(e,t,n){if(hy(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=au(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function my(e,t,n,r=0){return r>0&&(t=Math.max(t,iu(e,r,Zi).offset)),Qc(uy(e,t,n,py),yy)}function gy(e,[t,n,r,o]){t.length>0&&r("received item sizes",t,Wt.DEBUG);const s=e.sizeTree;let i=s,a=0;if(n.length>0&&tt(s)&&t.length===2){const h=t[0].size,p=t[1].size;i=n.reduce((v,x)=>qt(qt(v,x,h),x+1,p),i)}else[i,a]=fy(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f}=Qi(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>qt(h,p,ro(p,f,o)),jr()),lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f,sizeTree:i}}function xy(e){return dr(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 cu(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 Qi(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=ns(o,t-1,Zi),a=o[l].offset;const u=dn(n,t-1);s=u[0],i=u[1],o.length&&o[l].size===dn(n,t)[1]&&(l-=1),o=o.slice(0,l+1)}else o=[];for(const{start:u,value:d}of es(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 yy(e){return{index:e.index,value:e}}function vy(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 by={offsetHeight:"height",offsetWidth:"width"},Sn=qe(([{log:e},{recalcInProgress:t}])=>{const n=Ke(),r=Ke(),o=Dt(r,0),s=Ke(),i=Ke(),a=X(0),l=X([]),u=X(void 0),d=X(void 0),f=X((k,T)=>Vn(k,by[T])),h=X(void 0),p=X(0),v=dy(),x=Dt(V(n,Fe(l,e,p),wn(gy,v),it()),v),g=Dt(V(l,it(),wn((k,T)=>({current:T,prev:k.current}),{current:[],prev:[]}),de(({prev:k})=>k)),[]);ve(V(l,Te(k=>k.length>0),Fe(x,p),de(([k,T,I])=>{const _=k.reduce((P,j,H)=>qt(P,j,ro(j,T.offsetTree,I)||H),jr());return{...T,groupIndices:k,groupOffsetTree:_}})),x),ve(V(r,Fe(x),Te(([k,{lastIndex:T}])=>k<T),de(([k,{lastIndex:T,lastSize:I}])=>[{endIndex:T,size:I,startIndex:k}])),n),ve(u,d);const y=Dt(V(u,de(k=>k===void 0)),!0);ve(V(d,Te(k=>k!==void 0&&tt(gt(x).sizeTree)),de(k=>[{endIndex:0,size:k,startIndex:0}])),n);const b=Kt(V(n,Fe(x),wn(({sizes:k},[T,I])=>({changed:I!==k,sizes:I}),{changed:!1,sizes:v}),de(k=>k.changed)));Ye(V(a,wn((k,T)=>({diff:k.prev-T,prev:T}),{diff:0,prev:0}),de(k=>k.diff)),k=>{const{groupIndices:T}=gt(x);if(k>0)Me(t,!0),Me(s,k+cu(k,T));else if(k<0){const I=gt(g);I.length>0&&(k-=cu(-k,I)),Me(i,k)}}),Ye(V(a,Fe(e)),([k,T])=>{k<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},Wt.ERROR)});const C=Kt(s);ve(V(s,Fe(x),de(([k,T])=>{const I=T.groupIndices.length>0,_=[],P=T.lastSize;if(I){const j=to(T.sizeTree,0);let H=0,F=0;for(;H<k;){const D=T.groupIndices[F],G=T.groupIndices.length===F+1?1/0:T.groupIndices[F+1]-D-1;_.push({endIndex:D,size:j,startIndex:D}),_.push({endIndex:D+1+G-1,size:P,startIndex:D+1}),F++,H+=G+1}const U=dr(T.sizeTree);return H!==k&&U.shift(),U.reduce((D,{k:G,v:W})=>{let ne=D.ranges;return D.prevSize!==0&&(ne=[...D.ranges,{endIndex:G+k-1,size:D.prevSize,startIndex:D.prevIndex}]),{prevIndex:G+k,prevSize:W,ranges:ne}},{prevIndex:k,prevSize:0,ranges:_}).ranges}return dr(T.sizeTree).reduce((j,{k:H,v:F})=>({prevIndex:H+k,prevSize:F,ranges:[...j.ranges,{endIndex:H+k-1,size:j.prevSize,startIndex:j.prevIndex}]}),{prevIndex:0,prevSize:P,ranges:[]}).ranges})),n);const E=Kt(V(i,Fe(x,p),de(([k,{offsetTree:T},I])=>{const _=-k;return ro(_,T,I)})));return ve(V(i,Fe(x,p),de(([k,T,I])=>{if(T.groupIndices.length>0){if(tt(T.sizeTree))return T;let _=jr();const P=gt(g);let j=0,H=0,F=0;for(;j<-k;){F=P[H];const U=P[H+1]-F-1;H++,j+=U+1}if(_=dr(T.sizeTree).reduce((U,{k:D,v:G})=>qt(U,Math.max(0,D+k),G),_),j!==-k){const U=to(T.sizeTree,F);_=qt(_,0,U);const D=dn(T.sizeTree,-k+1)[1];_=qt(_,1,D)}return{...T,sizeTree:_,...Qi(T.offsetTree,0,_,I)}}else{const _=dr(T.sizeTree).reduce((P,{k:j,v:H})=>qt(P,Math.max(0,j+k),H),jr());return{...T,sizeTree:_,...Qi(T.offsetTree,0,_,I)}}})),x),{beforeUnshiftWith:C,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:u,gap:p,groupIndices:l,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:E,sizeRanges:n,sizes:x,statefulTotalCount:o,totalCount:r,trackItemSizes:y,unshiftWith:s}},st(Wn,Ji),{singleton:!0});function wy(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const uu=qe(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Ke(),i=Ke(),a=Kt(V(s,de(wy)));return ve(V(a,de(l=>l.totalCount)),n),ve(V(a,de(l=>l.groupIndices)),e),ve(V(yt(o,t,r),Te(([l,u])=>rs(u)),de(([l,u,d])=>dn(u.groupOffsetTree,Math.max(l-d,0),"v")[0]),it(),de(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},st(Sn,zt)),Kn=qe(([{log:e}])=>{const t=X(!1),n=Kt(V(t,Te(r=>r),it()));return Ye(t,r=>{r&>(e)("props updated",{},Wt.DEBUG)}),{didMount:n,propsReady:t}},st(Wn),{singleton:!0}),Sy=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function du(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Sy)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const oo=qe(([{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=X(0);let g=null,y=null,b=null;function C(){g&&(g(),g=null),b&&(b(),b=null),y&&(clearTimeout(y),y=null),Me(l,!1)}return ve(V(p,Fe(n,f,r,x,a,i,h),Fe(e,s,o),de(([[E,k,T,I,_,P,j,H],F,U,D])=>{const G=du(E),{align:W,behavior:ne,offset:$}=G,z=I-1,se=lu(G,k,z);let M=ro(se,k.offsetTree,F)+P;W==="end"?(M+=U+dn(k.sizeTree,se)[1]-T+D,se===z&&(M+=j)):W==="center"?M+=(U+dn(k.sizeTree,se)[1]-T+D)/2:M-=_,$&&(M+=$);const Y=ce=>{C(),ce?(H("retrying to scroll to",{location:E},Wt.DEBUG),Me(p,E)):(Me(v,!0),H("list did not change, scroll successful",{},Wt.DEBUG))};if(C(),ne==="smooth"){let ce=!1;b=Ye(t,be=>{ce=ce||be}),g=un(d,()=>{Y(ce)})}else g=un(V(t,Cy(150)),Y);return y=setTimeout(()=>{C()},1200),Me(l,!0),H("scrolling from index to",{behavior:ne,index:se,top:M},Wt.DEBUG),{behavior:ne,top:M}})),u),{scrollTargetReached:v,scrollToIndex:p,topListHeight:x}},st(Sn,zt,Wn),{singleton:!0});function Cy(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function ea(e,t){e==0?t():requestAnimationFrame(()=>{ea(e-1,t)})}function ta(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const so=qe(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=X(!0),l=X(0),u=X(!0);return ve(V(i,Fe(l),Te(([d,f])=>!!f),bn(!1)),a),ve(V(i,Fe(l),Te(([d,f])=>!!f),bn(!1)),u),Ye(V(yt(t,i),Fe(a,n,e,u),Te(([[,d],f,{sizeTree:h},p,v])=>d&&(!tt(h)||Ui(p))&&!f&&!v),Fe(l)),([,d])=>{un(o,()=>{Me(u,!0)}),ea(4,()=>{un(r,()=>{Me(a,!0)}),Me(s,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:l,scrolledToInitialItem:a}},st(Sn,zt,oo,Kn),{singleton:!0});function fu(e,t){return Math.abs(e-t)<1.01}const io="up",ao="down",ky="none",Ty={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Ey=0,lo=qe(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=X(!1),a=X(!0),l=Ke(),u=Ke(),d=X(4),f=X(Ey),h=Dt(V(Vi(V(Ce(o),cr(1),bn(!0)),V(Ce(o),cr(1),bn(!1),Yc(100))),it()),!1),p=Dt(V(Vi(V(n,bn(!0)),V(n,bn(!1),Yc(200))),it()),!1);ve(V(yt(Ce(o),Ce(f)),de(([b,C])=>b<=C),it()),a),ve(V(a,Dn(50)),u);const v=Kt(V(yt(r,Ce(s),Ce(t),Ce(e),Ce(d)),wn((b,[{scrollHeight:C,scrollTop:E},k,T,I,_])=>{const P=E+k-C>-_,j={scrollHeight:C,scrollTop:E,viewportHeight:k};if(P){let F,U;return E>b.state.scrollTop?(F="SCROLLED_DOWN",U=b.state.scrollTop-E):(F="SIZE_DECREASED",U=b.state.scrollTop-E||b.scrollTopDelta),{atBottom:!0,atBottomBecause:F,scrollTopDelta:U,state:j}}let H;return j.scrollHeight>b.state.scrollHeight?H="SIZE_INCREASED":k<b.state.viewportHeight?H="VIEWPORT_HEIGHT_DECREASING":E<b.state.scrollTop?H="SCROLLING_UPWARDS":H="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:H,state:j}},Ty),it((b,C)=>b&&b.atBottom===C.atBottom))),x=Dt(V(r,wn((b,{scrollHeight:C,scrollTop:E,viewportHeight:k})=>{if(fu(b.scrollHeight,C))return{changed:!1,jump:0,scrollHeight:C,scrollTop:E};{const T=C-(E+k)<1;return b.scrollTop!==E&&T?{changed:!0,jump:b.scrollTop-E,scrollHeight:C,scrollTop:E}:{changed:!0,jump:0,scrollHeight:C,scrollTop:E}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),Te(b=>b.changed),de(b=>b.jump)),0);ve(V(v,de(b=>b.atBottom)),i),ve(V(i,Dn(50)),l);const g=X(ao);ve(V(r,de(({scrollTop:b})=>b),it(),wn((b,C)=>gt(p)?{direction:b.direction,prevScrollTop:C}:{direction:C<b.prevScrollTop?io:ao,prevScrollTop:C},{direction:ao,prevScrollTop:0}),de(b=>b.direction)),g),ve(V(r,Dn(50),bn(ky)),g);const y=X(0);return ve(V(h,Te(b=>!b),bn(0)),y),ve(V(o,Dn(100),Fe(h),Te(([b,C])=>!!C),wn(([b,C],[E])=>[C,E],[0,0]),de(([b,C])=>C-b)),y),{atBottomState:v,atBottomStateChange:l,atBottomThreshold:d,atTopStateChange:u,atTopThreshold:f,isAtBottom:i,isAtTop:a,isScrolling:h,lastJumpDueToItemResize:x,scrollDirection:g,scrollVelocity:y}},st(zt)),os="top",ss="bottom",hu="none";function pu(e,t,n){return typeof e=="number"?n===io&&t===os||n===ao&&t===ss?e:0:n===io?t===os?e.main:e.reverse:t===ss?e.main:e.reverse}function mu(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const na=qe(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Ke(),i=X(0),a=X(0),l=X(0),u=Dt(V(yt(Ce(r),Ce(o),Ce(n),Ce(s,no),Ce(l),Ce(i),Ce(t),Ce(e),Ce(a)),de(([d,f,h,[p,v],x,g,y,b,C])=>{const E=d-b,k=g+y,T=Math.max(h-E,0);let I=hu;const _=mu(C,os),P=mu(C,ss);return p-=b,p+=h+y,v+=h+y,v-=b,p>d+k-_&&(I=io),v<d-T+f+P&&(I=ao),I!==hu?[Math.max(E-h-pu(x,os,I)-_,0),E-T-y+f+pu(x,ss,I)+P]:null}),Te(d=>d!=null),it(no)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:u}},st(zt),{singleton:!0});function Iy(e,t,n){if(rs(t)){const r=au(e,t);return[{index:dn(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 ra={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function is(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:xu(e,o,s),offsetBottom:v,offsetTop:u,top:p,topItems:xu(t,o,s),topListHeight:t.reduce((x,g)=>g.size+x,0),totalCount:n}}function gu(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=ta(t,a),u=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return is(u,[],a,o,n,r)}function xu(e,t,n){if(e.length===0)return[];if(!rs(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=es(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 fr=qe(([{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=X([]),g=X(0),y=Ke();ve(s.topItemsIndexes,x);const b=Dt(V(yt(p,v,Ce(l,no),Ce(o),Ce(r),Ce(u),d,Ce(x),Ce(t),Ce(n),e),Te(([T,I,,_,,,,,,,P])=>{const j=P&&P.length!==_;return T&&!I&&!j}),de(([,,[T,I],_,P,j,H,F,U,D,G])=>{const W=P,{offsetTree:ne,sizeTree:$}=W,z=gt(g);if(_===0)return{...ra,totalCount:_};if(T===0&&I===0)return z===0?{...ra,totalCount:_}:gu(z,j,P,U,D,G||[]);if(tt($))return z>0?null:is(Iy(ta(j,_),W,G),[],_,D,W,U);const se=[];if(F.length>0){const ge=F[0],ye=F[F.length-1];let K=0;for(const L of es($,ge,ye)){const Z=L.value,ee=Math.max(L.start,ge),pe=Math.min(L.end,ye);for(let oe=ee;oe<=pe;oe++)se.push({data:G==null?void 0:G[oe],index:oe,offset:K,size:Z}),K+=Z}}if(!H)return is([],se,_,D,W,U);const M=F.length>0?F[F.length-1]+1:0,Y=my(ne,T,I,M);if(Y.length===0)return null;const ce=_-1,be=Qo([],ge=>{for(const ye of Y){const K=ye.value;let L=K.offset,Z=ye.start;const ee=K.size;if(K.offset<T){Z+=Math.floor((T-K.offset+D)/(ee+D));const oe=Z-ye.start;L+=oe*ee+oe*D}Z<M&&(L+=(M-Z)*ee,Z=M);const pe=Math.min(ye.end,ce);for(let oe=Z;oe<=pe&&!(L>=I);oe++)ge.push({data:G==null?void 0:G[oe],index:oe,offset:L,size:ee}),L+=ee+D}});return is(be,se,_,D,W,U)}),Te(T=>T!==null),it()),ra);ve(V(e,Te(Ui),de(T=>T==null?void 0:T.length)),o),ve(V(b,de(T=>T.topListHeight)),f),ve(f,a),ve(V(b,de(T=>[T.top,T.bottom])),i),ve(V(b,de(T=>T.items)),y);const C=Kt(V(b,Te(({items:T})=>T.length>0),Fe(o,e),Te(([{items:T},I])=>T[T.length-1].originalIndex===I-1),de(([,T,I])=>[T-1,I]),it(no),de(([T])=>T))),E=Kt(V(b,Dn(200),Te(({items:T,topItems:I})=>T.length>0&&T[0].originalIndex===I.length),de(({items:T})=>T[0].index),it())),k=Kt(V(b,Te(({items:T})=>T.length>0),de(({items:T})=>{let I=0,_=T.length-1;for(;T[I].type==="group"&&I<_;)I++;for(;T[_].type==="group"&&_>I;)_--;return{endIndex:T[_].index,startIndex:T[I].index}}),it(su)));return{endReached:C,initialItemCount:g,itemsRendered:y,listState:b,rangeChanged:k,startReached:E,topItemsIndexes:x,...h}},st(Sn,uu,na,so,oo,lo,Kn,Ji),{singleton:!0}),yu=qe(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Ke(),i=Dt(V(yt(n,e,r,t,o),de(([a,l,u,d,f])=>a+l+u+d+f.offsetBottom+f.bottom)),0);return ve(Ce(i),s),{totalListHeight:i,totalListHeightChanged:s}},st(zt,fr),{singleton:!0}),Ay=qe(([{viewportHeight:e},{totalListHeight:t}])=>{const n=X(!1),r=Dt(V(yt(n,e,t),Te(([o])=>o),de(([,o,s])=>Math.max(0,o-s)),Dn(0),it()),0);return{alignToBottom:n,paddingTopAddition:r}},st(zt,yu),{singleton:!0}),vu=qe(()=>({context:X(null)})),Ny=({itemBottom:e,itemTop:t,locationParams:{align:n,behavior:r,...o},viewportBottom:s,viewportTop:i})=>t<i?{...o,align:n??"start",behavior:r}:e>s?{...o,align:n??"end",behavior:r}:null,bu=qe(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:u}])=>{const d=Ke();return ve(V(d,Fe(t,l,n,s,o,r,a),Fe(e),de(([[f,h,p,v,x,g,y,b],C])=>{const{align:E,behavior:k,calculateViewLocation:T=Ny,done:I,..._}=f,P=lu(f,h,v-1),j=ro(P,h.offsetTree,C)+x+g,H=j+dn(h.sizeTree,P)[1],F=b+g,U=b+p-y,D=T({itemBottom:H,itemTop:j,locationParams:{align:E,behavior:k,..._},viewportBottom:U,viewportTop:F});return D?I&&un(V(i,Te(G=>!G),cr(gt(i)?1:2)),I):I&&I(),D}),Te(f=>f!==null)),u),{scrollIntoView:d}},st(Sn,zt,oo,fr,Wn),{singleton:!0});function wu(e){return e?e==="smooth"?"smooth":"auto":!1}const _y=(e,t)=>typeof e=="function"?wu(e(t)):t&&wu(e),jy=qe(([{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=X(!1),x=Ke();let g=null;function y(k){Me(i,{align:"end",behavior:k,index:"LAST"})}Ye(V(yt(V(Ce(t),cr(1)),l),Fe(Ce(v),s,a,f),de(([[k,T],I,_,P,j])=>{let H=T&&P,F="auto";return H&&(F=_y(I,_||j),H=H&&!!F),{followOutputBehavior:F,shouldFollow:H,totalCount:k}}),Te(({shouldFollow:k})=>k)),({followOutputBehavior:k,totalCount:T})=>{g&&(g(),g=null),gt(n)?requestAnimationFrame(()=>{gt(d)("following output to ",{totalCount:T},Wt.DEBUG),y(k)}):g=un(e,()=>{gt(d)("following output to ",{totalCount:T},Wt.DEBUG),y(k),g=null})});function b(k){const T=un(o,I=>{k&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(gt(d)("scrolling to bottom due to increased size",{},Wt.DEBUG),y("auto"))});setTimeout(T,100)}Ye(V(yt(Ce(v),t,u),Te(([k,,T])=>k&&T),wn(({value:k},[,T])=>({refreshed:k===T,value:T}),{refreshed:!1,value:0}),Te(({refreshed:k})=>k),Fe(v,t)),([,k])=>{gt(a)&&b(k!==!1)}),Ye(x,()=>{b(gt(v)!==!1)}),Ye(yt(Ce(v),o),([k,T])=>{k&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&y("auto")});const C=X(null),E=Ke();return ve(Vi(V(Ce(r),de(k=>{var T;return(T=k==null?void 0:k.length)!=null?T:0})),V(Ce(t))),E),Ye(V(yt(V(E,cr(1)),l),Fe(Ce(C),a,f,h),de(([[k,T],I,_,P,j])=>T&&_&&(I==null?void 0:I({context:j,totalCount:k,scrollingInProgress:P}))),Te(k=>!!k),Dn(0)),k=>{g&&(g(),g=null),gt(n)?requestAnimationFrame(()=>{gt(d)("scrolling into view",{}),Me(p,k)}):g=un(e,()=>{gt(d)("scrolling into view",{}),Me(p,k),g=null})}),{autoscrollToBottom:x,followOutput:v,scrollIntoViewOnChange:C}},st(Sn,lo,oo,so,Kn,Wn,zt,vu,bu)),Ry=qe(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(ve(V(a,Fe(s),Te(([,l])=>l!==0),Fe(o,r,t,n,e),de(([[,l],u,d,f,h,p=[]])=>gu(l,u,d,f,h,p))),i),{}),st(Sn,so,fr,Kn),{singleton:!0}),Py=qe(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=X(0);return Ye(V(e,Fe(r),Te(([,o])=>o!==0),de(([,o])=>({top:o}))),o=>{un(V(n,cr(1),Te(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Me(t,o)})})}),{initialScrollTop:r}},st(Kn,zt,fr),{singleton:!0}),Su=qe(([{scrollVelocity:e}])=>{const t=X(!1),n=Ke(),r=X(!1);return ve(V(e,Fe(r,t,n),Te(([o,s])=>!!s),de(([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}),it()),t),Ye(V(yt(t,e,n),Fe(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},st(lo),{singleton:!0}),oa=qe(([{scrollContainerState:e,scrollTo:t}])=>{const n=Ke(),r=Ke(),o=Ke(),s=X(!1),i=X(void 0);return ve(V(yt(n,r),de(([{scrollHeight:a,scrollTop:l,viewportHeight:u},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:u}))),e),ve(V(t,Fe(r),de(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},st(zt)),Oy=qe(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const u=Ke(),d=X(void 0),f=X(null),h=X(null);return ve(a,f),ve(l,h),Ye(V(u,Fe(t,r,i,f,h,n)),([p,v,x,g,y,b,C])=>{const E=xy(v.sizeTree);g&&y!==null&&b!==null&&(x=y.scrollTop-b.offsetTop),x-=C,p({ranges:E,scrollTop:x})}),ve(V(d,Te(Ui),de(My)),o),ve(V(s,Fe(d),Te(([,p])=>p!==void 0),it(),de(([,p])=>p.ranges)),e),{getState:u,restoreStateFrom:d}},st(Sn,zt,so,Kn,oa));function My(e){return{align:"start",index:0,offset:e.scrollTop}}const Dy=qe(([{topItemsIndexes:e}])=>{const t=X(0);return ve(V(t,Te(n=>n>=0),de(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},st(fr));function Cu(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const Ly=Cu(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),Fy=qe(([{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=Kt(V(l,Fe(i),wn(([,y,b,C],[{bottom:E,items:k,offsetBottom:T,totalCount:I},_])=>{const P=E+T;let j=0;return b===I&&y.length>0&&k.length>0&&(k[0].originalIndex===0&&y[0].originalIndex===0||(j=P-C,j!==0&&(j+=_))),[j,k,I,P]},[0,[],0,0]),Te(([y])=>y!==0),Fe(r,a,n,o,p,v),Te(([,y,b,C,,,E])=>!E&&!C&&y!==0&&b===io),de(([[y],,,,,b])=>(b("Upward scrolling compensation",{amount:y},Wt.DEBUG),y))));function g(y){y>0?(Me(t,{behavior:"auto",top:-y}),Me(e,0)):(Me(e,0),Me(t,{behavior:"auto",top:-y}))}return Ye(V(x,Fe(e,s)),([y,b,C])=>{C&&Ly()?Me(e,b-y):g(-y)}),Ye(V(yt(Dt(s,!1),e,v),Te(([y,b,C])=>!y&&!C&&b!==0),de(([y,b])=>b),Dn(1)),g),ve(V(f,de(y=>({top:-y}))),t),Ye(V(u,Fe(h,d),de(([y,{groupIndices:b,lastSize:C,sizeTree:E},k])=>{function T(I){return I*(C+k)}if(b.length===0)return T(y);{let I=0;const _=to(E,0);let P=0,j=0;for(;P<y;){P++,I+=_;let H=b.length===j+1?1/0:b[j+1]-b[j]-1;P+H>y&&(I-=_,H=y-P+1),P+=H,I+=T(H),j++}return I}})),y=>{Me(e,y),requestAnimationFrame(()=>{Me(t,{top:y}),requestAnimationFrame(()=>{Me(e,0),Me(v,!1)})})}),{deviation:e}},st(zt,lo,fr,Sn,Wn,Ji)),$y=qe(([e,t,n,r,o,s,i,a,l,u,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...u,...d}),st(na,Ry,Kn,Su,yu,Py,Ay,oa,bu,Wn,vu)),ku=qe(([{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:C,...E},{scrollToIndex:k},T,{topItemCount:I},{groupCounts:_},P])=>(ve(E.rangeChanged,P.scrollSeekRangeChanged),ve(V(P.windowViewportRect,de(j=>j.visibleHeight)),x.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:_,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:v,sizeRanges:a,topItemCount:I,topItemsIndexes:C,totalCount:d,...y,groupIndices:s,itemSize:i,listState:b,scrollToIndex:k,statefulTotalCount:u,trackItemSizes:f,...E,...P,...x,sizes:l,...g}),st(Sn,so,zt,Oy,jy,fr,oo,Fy,Dy,uu,$y));function zy(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 as=typeof document<"u"?w.useLayoutEffect:w.useEffect;function Tu(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&&Me(g.propsReady,!1);for(const b of r){const C=g[t.required[b]];Me(C,y[b])}for(const b of o)if(b in y){const C=g[t.optional[b]];Me(C,y[b])}g.propsReady&&Me(g.propsReady,!0)}function u(g){return s.reduce((y,b)=>(y[b]=C=>{const E=g[t.methods[b]];Me(E,C)},y),{})}function d(g){return i.reduce((y,b)=>(y[b]=ny(g[t.events[b]]),y),{})}const f=w.forwardRef((g,y)=>{const{children:b,...C}=g,[E]=w.useState(()=>Qo(oy(e),I=>{l(I,C)})),[k]=w.useState(Gc(d,E));as(()=>{for(const I of i)I in C&&Ye(k[I],C[I]);return()=>{Object.values(k).map(Wi)}},[C,k,E]),as(()=>{l(E,C)}),w.useImperativeHandle(y,Kc(u(E)));const T=n;return c.jsx(a.Provider,{value:E,children:n?c.jsx(T,{...zy([...r,...o,...i],C),children:b}):b})}),h=g=>{const y=w.useContext(a);return w.useCallback(b=>{Me(y[g],b)},[y,g])},p=g=>{const y=w.useContext(a)[g],b=w.useCallback(C=>Ye(y,C),[y]);return w.useSyncExternalStore(b,()=>gt(y),()=>gt(y))},v=g=>{const y=w.useContext(a)[g],[b,C]=w.useState(Gc(gt,y));return as(()=>Ye(y,E=>{E!==b&&C(Kc(E))}),[y,b]),b},x=w.version.startsWith("18")?p:v;return{Component:f,useEmitter:(g,y)=>{const b=w.useContext(a)[g];as(()=>Ye(b,y),[y,b])},useEmitterValue:x,usePublisher:h}}const Eu=w.createContext(void 0),Iu=w.createContext(void 0),Au=typeof document<"u"?w.useLayoutEffect:w.useEffect;function sa(e){return"self"in e}function By(e){return"body"in e}function Nu(e,t,n,r=_r,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(By(g)||sa(g)){const b=sa(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():pi.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;sa(p)?(g=Math.max(Vn(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=Vn(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)),fu(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 ia="-webkit-sticky",_u="sticky",aa=Cu(()=>{if(typeof document>"u")return _u;const e=document.createElement("div");return e.style.position=ia,e.style.position===ia?ia:_u});function la(e){return e}const Hy=qe(()=>{const e=X(a=>`Item ${a}`),t=X(a=>`Group ${a}`),n=X({}),r=X(la),o=X("div"),s=X(_r),i=(a,l=null)=>Dt(V(n,de(u=>u[a]),it()),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")}}),Uy=qe(([e,t])=>({...e,...t}),st(ku,Hy)),Wy=({height:e})=>c.jsx("div",{style:{height:e}}),Vy={overflowAnchor:"none",position:aa(),zIndex:1},ju={overflowAnchor:"none"},Ky={...ju,display:"inline-block",height:"100%"},Ru=w.memo(function({showTopList:e=!1}){const t=Ne("listState"),n=en("sizeRanges"),r=Ne("useWindowScroll"),o=Ne("customScrollParent"),s=en("windowScrollContainerState"),i=en("scrollContainerState"),a=o||r?s:i,l=Ne("itemContent"),u=Ne("context"),d=Ne("groupContent"),f=Ne("trackItemSizes"),h=Ne("itemSize"),p=Ne("log"),v=en("gap"),x=Ne("horizontalDirection"),{callbackRef:g}=ay(n,h,f,e?_r:a,p,v,o,x,Ne("skipAnimationFrameInResizeObserver")),[y,b]=w.useState(0);ca("deviation",D=>{y!==D&&b(D)});const C=Ne("EmptyPlaceholder"),E=Ne("ScrollSeekPlaceholder")||Wy,k=Ne("ListComponent"),T=Ne("ItemComponent"),I=Ne("GroupComponent"),_=Ne("computeItemKey"),P=Ne("isSeeking"),j=Ne("groupIndices").length>0,H=Ne("alignToBottom"),F=Ne("initialItemFinalLocationReached"),U=e?{}:{boxSizing:"border-box",...x?{display:"inline-block",height:"100%",marginLeft:y!==0?y:H?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:y!==0?y:H?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...F?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&C?c.jsx(C,{...Lt(C,u)}):c.jsx(k,{...Lt(k,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:g,style:U,children:(e?t.topItems:t.items).map(D=>{const G=D.originalIndex,W=_(G+t.firstItemIndex,D.data,u);return P?w.createElement(E,{...Lt(E,u),height:D.size,index:D.index,key:W,type:D.type||"item",...D.type==="group"?{}:{groupIndex:D.groupIndex}}):D.type==="group"?w.createElement(I,{...Lt(I,u),"data-index":G,"data-item-index":D.index,"data-known-size":D.size,key:W,style:Vy},d(D.index,u)):w.createElement(T,{...Lt(T,u),...Xy(T,D.data),"data-index":G,"data-item-group-index":D.groupIndex,"data-item-index":D.index,"data-known-size":D.size,key:W,style:x?Ky:ju},j?l(D.index,D.groupIndex,D.data,u):l(D.index,D.data,u))})})}),qy={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},Gy={outline:"none",overflowX:"auto",position:"relative"},ls=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),Yy={position:aa(),top:0,width:"100%",zIndex:1};function Lt(e,t){if(typeof e!="string")return{context:t}}function Xy(e,t){return{item:typeof e=="string"?void 0:t}}const Jy=w.memo(function(){const e=Ne("HeaderComponent"),t=en("headerHeight"),n=Ne("HeaderFooterTag"),r=ur(w.useMemo(()=>s=>{t(Vn(s,"height"))},[t]),!0,Ne("skipAnimationFrameInResizeObserver")),o=Ne("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...Lt(e,o)})}):null}),Zy=w.memo(function(){const e=Ne("FooterComponent"),t=en("footerHeight"),n=Ne("HeaderFooterTag"),r=ur(w.useMemo(()=>s=>{t(Vn(s,"height"))},[t]),!0,Ne("skipAnimationFrameInResizeObserver")),o=Ne("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...Lt(e,o)})}):null});function Pu({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}=Nu(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?Gy:qy,...o},tabIndex:0,...i,...Lt(l,s),children:r})})}function Ou({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}=Nu(a,u,l,v,h);return Au(()=>{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,...Lt(l,s),children:r})})}const Qy=({children:e})=>{const t=w.useContext(Eu),n=en("viewportHeight"),r=en("fixedItemHeight"),o=Ne("alignToBottom"),s=Ne("horizontalDirection"),i=w.useMemo(()=>qc(n,l=>Vn(l,s?"width":"height")),[n,s]),a=ur(i,!0,Ne("skipAnimationFrameInResizeObserver"));return w.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),c.jsx("div",{"data-viewport-type":"element",ref:a,style:ls(o),children:e})},ev=({children:e})=>{const t=w.useContext(Eu),n=en("windowViewportRect"),r=en("fixedItemHeight"),o=Ne("customScrollParent"),s=Zc(n,o,Ne("skipAnimationFrameInResizeObserver")),i=Ne("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:ls(i),children:e})},tv=({children:e})=>{const t=Ne("TopItemListComponent")||"div",n=Ne("headerHeight"),r={...Yy,marginTop:`${n}px`},o=Ne("context");return c.jsx(t,{style:r,...Lt(t,o),children:e})},nv=w.memo(function(e){const t=Ne("useWindowScroll"),n=Ne("topItemsIndexes").length>0,r=Ne("customScrollParent"),o=Ne("context");return c.jsxs(r||t?sv:ov,{...e,context:o,children:[n&&c.jsx(tv,{children:c.jsx(Ru,{showTopList:!0})}),c.jsxs(r||t?ev:Qy,{children:[c.jsx(Jy,{}),c.jsx(Ru,{}),c.jsx(Zy,{})]})]})}),{Component:rv,useEmitter:ca,useEmitterValue:Ne,usePublisher:en}=Tu(Uy,{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"}},nv),ov=Pu({useEmitter:ca,useEmitterValue:Ne,usePublisher:en}),sv=Ou({useEmitter:ca,useEmitterValue:Ne,usePublisher:en}),iv=rv;st(ku,qe(()=>{const e=X(u=>c.jsxs("td",{children:["Item $",u]})),t=X(null),n=X(u=>c.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=X(null),o=X(null),s=X({}),i=X(la),a=X(_r),l=(u,d=null)=>Dt(V(s,de(f=>f[u]),it()),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")}})),aa();const Mu={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},av={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Du,floor:cs,max:co,min:ua,round:Lu}=Math;function Fu(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function lv(e){return{...av,items:e}}function us(e,t){return e&&e.width===t.width&&e.height===t.height}function cv(e,t){return e&&e.column===t.column&&e.row===t.row}const uv=qe(([{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:C,windowViewportRect:E},k])=>{const T=X(0),I=X(0),_=X(Mu),P=X({height:0,width:0}),j=X({height:0,width:0}),H=Ke(),F=Ke(),U=X(0),D=X(null),G=X({column:0,row:0}),W=Ke(),ne=Ke(),$=X(!1),z=X(0),se=X(!0),M=X(!1),Y=X(!1);Ye(V(v,Fe(z),Te(([L,Z])=>!!Z)),()=>{Me(se,!1)}),Ye(V(yt(v,se,j,P,z,M),Te(([L,Z,ee,pe,,oe])=>L&&!Z&&ee.height!==0&&pe.height!==0&&!oe)),([,,,,L])=>{Me(M,!0),ea(1,()=>{Me(H,L)}),un(V(u),()=>{Me(t,[0,0]),Me(se,!0)})}),ve(V(ne,Te(L=>L!=null&&L.scrollTop>0),bn(0)),I),Ye(V(v,Fe(ne),Te(([,L])=>L!=null)),([,L])=>{L&&(Me(P,L.viewport),Me(j,L.item),Me(G,L.gap),L.scrollTop>0&&(Me($,!0),un(V(u,cr(1)),Z=>{Me($,!1)}),Me(l,{top:L.scrollTop})))}),ve(V(P,de(({height:L})=>L)),f),ve(V(yt(Ce(P,us),Ce(j,us),Ce(G,(L,Z)=>L&&L.column===Z.column&&L.row===Z.row),Ce(u)),de(([L,Z,ee,pe])=>({gap:ee,item:Z,scrollTop:pe,viewport:L}))),W),ve(V(yt(Ce(T),r,Ce(G,cv),Ce(j,us),Ce(P,us),Ce(D),Ce(I),Ce($),Ce(se),Ce(z)),Te(([,,,,,,,L])=>!L),de(([L,[Z,ee],pe,oe,ie,Be,Je,,je,He])=>{const{column:Qe,row:Ze}=pe,{height:Pe,width:wt}=oe,{width:Ct}=ie;if(Je===0&&(L===0||Ct===0))return Mu;if(wt===0){const ue=ta(He,L),_e=ue+Math.max(Je-1,0);return lv(Fu(ue,_e,Be))}const kt=$u(Ct,wt,Qe);let ot,et;je?Z===0&&ee===0&&Je>0?(ot=0,et=Je-1):(ot=kt*cs((Z+Ze)/(Pe+Ze)),et=kt*Du((ee+Ze)/(Pe+Ze))-1,et=ua(L-1,co(et,kt-1)),ot=ua(et,co(0,ot))):(ot=0,et=-1);const $e=Fu(ot,et,Be),{bottom:ct,top:vt}=zu(ie,pe,oe,$e),J=Du(L/kt),xe=J*Pe+(J-1)*Ze-ct;return{bottom:ct,itemHeight:Pe,items:$e,itemWidth:wt,offsetBottom:xe,offsetTop:vt,top:vt}})),_),ve(V(D,Te(L=>L!==null),de(L=>L.length)),T),ve(V(yt(P,j,_,G),Te(([L,Z,{items:ee}])=>ee.length>0&&Z.height!==0&&L.height!==0),de(([L,Z,{items:ee},pe])=>{const{bottom:oe,top:ie}=zu(L,pe,Z,ee);return[ie,oe]}),it(no)),t);const ce=X(!1);ve(V(u,Fe(ce),de(([L,Z])=>Z||L!==0)),ce);const be=Kt(V(yt(_,T),Te(([{items:L}])=>L.length>0),Fe(ce),Te(([[L,Z],ee])=>{const pe=L.items[L.items.length-1].index===Z-1;return(ee||L.bottom>0&&L.itemHeight>0&&L.offsetBottom===0&&L.items.length===Z)&&pe}),de(([[,L]])=>L-1),it())),ge=Kt(V(Ce(_),Te(({items:L})=>L.length>0&&L[0].index===0),bn(0),it())),ye=Kt(V(Ce(_),Fe($),Te(([{items:L},Z])=>L.length>0&&!Z),de(([{items:L}])=>({endIndex:L[L.length-1].index,startIndex:L[0].index})),it(su),Dn(0)));ve(ye,p.scrollSeekRangeChanged),ve(V(H,Fe(P,j,T,G),de(([L,Z,ee,pe,oe])=>{const ie=du(L),{align:Be,behavior:Je,offset:je}=ie;let He=ie.index;He==="LAST"&&(He=pe-1),He=co(0,He,ua(pe-1,He));let Qe=da(Z,oe,ee,He);return Be==="end"?Qe=Lu(Qe-Z.height+ee.height):Be==="center"&&(Qe=Lu(Qe-Z.height/2+ee.height/2)),je&&(Qe+=je),{behavior:Je,top:Qe}})),l);const K=Dt(V(_,de(L=>L.offsetBottom+L.bottom)),0);return ve(V(E,de(L=>({height:L.visibleHeight,width:L.visibleWidth}))),P),{customScrollParent:g,data:D,deviation:U,footerHeight:o,gap:G,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:j,overscan:n,restoreStateFrom:ne,scrollBy:i,scrollContainerState:a,scrollHeight:F,scrollTo:l,scrollToIndex:H,scrollTop:u,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:y,viewportDimensions:P,windowScrollContainerState:b,windowScrollTo:C,windowViewportRect:E,...p,gridState:_,horizontalDirection:Y,initialTopMostItemIndex:z,totalListHeight:K,...h,endReached:be,propsReady:x,rangeChanged:ye,startReached:ge,stateChanged:W,stateRestoreInProgress:$,...k}},st(na,zt,lo,Su,Kn,oa,Wn));function $u(e,t,n){return co(1,cs((e+n)/(cs(t)+n)))}function zu(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=da(e,t,n,r[0].index);return{bottom:da(e,t,n,r[r.length-1].index)+o,top:s}}function da(e,t,n,r){const o=$u(e.width,n.width,t.column),s=cs(r/o),i=s*n.height+co(0,s-1)*t.row;return i>0?i+t.row:i}const dv=qe(()=>{const e=X(f=>`Item ${f}`),t=X({}),n=X(null),r=X("virtuoso-grid-item"),o=X("virtuoso-grid-list"),s=X(la),i=X("div"),a=X(_r),l=(f,h=null)=>Dt(V(t,de(p=>p[f]),it()),h),u=X(!1),d=X(!1);return ve(Ce(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")}}),fv=qe(([e,t])=>({...e,...t}),st(uv,dv)),hv=w.memo(function(){const e=lt("gridState"),t=lt("listClassName"),n=lt("itemClassName"),r=lt("itemContent"),o=lt("computeItemKey"),s=lt("isSeeking"),i=tn("scrollHeight"),a=lt("ItemComponent"),l=lt("ListComponent"),u=lt("ScrollSeekPlaceholder"),d=lt("context"),f=tn("itemDimensions"),h=tn("gap"),p=lt("log"),v=lt("stateRestoreInProgress"),x=tn("reportReadyState"),g=ur(w.useMemo(()=>y=>{const b=y.parentElement.parentElement.scrollHeight;i(b);const C=y.firstChild;if(C){const{height:E,width:k}=C.getBoundingClientRect();f({height:E,width:k})}h({column:Hu("column-gap",getComputedStyle(y).columnGap,p),row:Hu("row-gap",getComputedStyle(y).rowGap,p)})},[i,f,h,p]),!0,!1);return Au(()=>{e.itemHeight>0&&e.itemWidth>0&&x(!0)},[e]),v?null:c.jsx(l,{className:t,ref:g,...Lt(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,{...Lt(u,d),height:e.itemHeight,index:y.index,width:e.itemWidth},b):w.createElement(a,{...Lt(a,d),className:n,"data-index":y.index,key:b},r(y.index,y.data,d))})})}),pv=w.memo(function(){const e=lt("HeaderComponent"),t=tn("headerHeight"),n=lt("headerFooterTag"),r=ur(w.useMemo(()=>s=>{t(Vn(s,"height"))},[t]),!0,!1),o=lt("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...Lt(e,o)})}):null}),mv=w.memo(function(){const e=lt("FooterComponent"),t=tn("footerHeight"),n=lt("headerFooterTag"),r=ur(w.useMemo(()=>s=>{t(Vn(s,"height"))},[t]),!0,!1),o=lt("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...Lt(e,o)})}):null}),gv=({children:e})=>{const t=w.useContext(Iu),n=tn("itemDimensions"),r=tn("viewportDimensions"),o=ur(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:ls(!1),children:e})},xv=({children:e})=>{const t=w.useContext(Iu),n=tn("windowViewportRect"),r=tn("itemDimensions"),o=lt("customScrollParent"),s=Zc(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:ls(!1),children:e})},yv=w.memo(function({...e}){const t=lt("useWindowScroll"),n=lt("customScrollParent"),r=n||t?bv:vv,o=n||t?xv:gv,s=lt("context");return c.jsx(r,{...e,...Lt(r,s),children:c.jsxs(o,{children:[c.jsx(pv,{}),c.jsx(hv,{}),c.jsx(mv,{})]})})}),{useEmitter:Bu,useEmitterValue:lt,usePublisher:tn}=Tu(fv,{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"}},yv),vv=Pu({useEmitter:Bu,useEmitterValue:lt,usePublisher:tn}),bv=Ou({useEmitter:Bu,useEmitterValue:lt,usePublisher:tn});function Hu(e,t,n){return t!=="normal"&&!(t!=null&&t.endsWith("px"))&&n(`${e} was not resolved to pixel value correctly`,t,Wt.WARN),t==="normal"?0:parseInt(t??"0",10)}const wv=Ro.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 Uu({className:e,variant:t,...n}){return c.jsx("div",{className:re(wv({variant:t}),e),...n})}function he(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 Sv(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 Cn(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,Cv(o,...t)]}function Cv(...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 St=globalThis!=null&&globalThis.document?m.useLayoutEffect:()=>{},kv=m[" useInsertionEffect ".trim().toString()]||St;function hr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Tv({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=Ev(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 Tv({defaultProp:e,onChange:t}){const[n,r]=m.useState(e),o=m.useRef(n),s=m.useRef(t);return kv(()=>{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 Ev(e){return typeof e=="function"}function Wu(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function fa(...e){return t=>{let n=!1;const r=e.map(o=>{const s=Wu(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():Wu(e[o],null)}}}}function We(...e){return m.useCallback(fa(...e),e)}var Iv=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ee=Iv.reduce((e,t)=>{const n=or.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 Vu(e,t){e&&Po.flushSync(()=>e.dispatchEvent(t))}function Av(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var Gt=e=>{const{present:t,children:n}=e,r=Nv(t),o=typeof n=="function"?n({present:r.isPresent}):m.Children.only(n),s=We(r.ref,_v(o));return typeof n=="function"||r.isPresent?m.cloneElement(o,{ref:s}):null};Gt.displayName="Presence";function Nv(e){const[t,n]=m.useState(),r=m.useRef(null),o=m.useRef(e),s=m.useRef("none"),i=e?"mounted":"unmounted",[a,l]=Av(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return m.useEffect(()=>{const u=ds(r.current);s.current=a==="mounted"?u:"none"},[a]),St(()=>{const u=r.current,d=o.current;if(d!==e){const h=s.current,p=ds(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]),St(()=>{if(t){let u;const d=t.ownerDocument.defaultView??window,f=p=>{const x=ds(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=ds(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 ds(e){return(e==null?void 0:e.animationName)||"none"}function _v(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 jv=m[" useId ".trim().toString()]||(()=>{}),Rv=0;function kn(e){const[t,n]=m.useState(jv());return St(()=>{n(r=>r??String(Rv++))},[e]),e||(t?`radix-${t}`:"")}var fs="Collapsible",[Pv,vT]=Cn(fs),[Ov,ha]=Pv(fs),Ku=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[l,u]=hr({prop:r,defaultProp:o??!1,onChange:i,caller:fs});return c.jsx(Ov,{scope:n,disabled:s,contentId:kn(),open:l,onOpenToggle:m.useCallback(()=>u(d=>!d),[u]),children:c.jsx(Ee.div,{"data-state":ma(l),"data-disabled":s?"":void 0,...a,ref:t})})});Ku.displayName=fs;var qu="CollapsibleTrigger",Gu=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=ha(qu,n);return c.jsx(Ee.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":ma(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:he(e.onClick,o.onOpenToggle)})});Gu.displayName=qu;var pa="CollapsibleContent",Mv=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=ha(pa,e.__scopeCollapsible);return c.jsx(Gt,{present:n||o.open,children:({present:s})=>c.jsx(Dv,{...r,ref:t,present:s})})});Mv.displayName=pa;var Dv=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=ha(pa,n),[a,l]=m.useState(r),u=m.useRef(null),d=We(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)},[]),St(()=>{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 C=b.getBoundingClientRect();f.current=C.height,p.current=C.width,g.current||(b.style.transitionDuration=y.current.transitionDuration,b.style.animationName=y.current.animationName),l(r)}},[i.open,r]),c.jsx(Ee.div,{"data-state":ma(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 ma(e){return e?"open":"closed"}var Lv=Ku;const Fv=Lv,$v=Gu,uo=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:re("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));uo.displayName="Card";const fo=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:re("flex flex-col space-y-1.5 p-6",e),...t}));fo.displayName="CardHeader";const ho=m.forwardRef(({className:e,...t},n)=>c.jsx("h3",{ref:n,className:re("text-2xl font-semibold leading-none tracking-tight",e),...t}));ho.displayName="CardTitle";const Yu=m.forwardRef(({className:e,...t},n)=>c.jsx("p",{ref:n,className:re("text-sm text-muted-foreground",e),...t}));Yu.displayName="CardDescription";const po=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:re("p-6 pt-0",e),...t}));po.displayName="CardContent";const Xu=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:re("flex items-center p-6 pt-0",e),...t}));Xu.displayName="CardFooter";function Ju(){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 pr=Ju();function zv(e){pr=e}const Zu=/[&<>"']/,Bv=new RegExp(Zu.source,"g"),Qu=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,Hv=new RegExp(Qu.source,"g"),Uv={"&":"&","<":"<",">":">",'"':""","'":"'"},ed=e=>Uv[e];function Ft(e,t){if(t){if(Zu.test(e))return e.replace(Bv,ed)}else if(Qu.test(e))return e.replace(Hv,ed);return e}const Wv=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function td(e){return e.replace(Wv,(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 Vv=/(^|[^\[])\^/g;function nt(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(Vv,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const Kv=/[^\w:]/g,qv=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function nd(e,t,n){if(e){let r;try{r=decodeURIComponent(td(n)).replace(Kv,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!qv.test(n)&&(n=Jv(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const hs={},Gv=/^[^:]+:\/*[^/]*$/,Yv=/^([^:]+:)[\s\S]*$/,Xv=/^([^:]+:\/*[^/]*)[\s\S]*$/;function Jv(e,t){hs[" "+e]||(Gv.test(e)?hs[" "+e]=e+"/":hs[" "+e]=ms(e,"/",!0)),e=hs[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(Yv,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(Xv,"$1")+t:e+t}const ps={exec:function(){}};function rd(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 ms(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 Zv(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 Qv(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 od(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function sd(e,t,n,r){const o=t.href,s=t.title?Ft(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:Ft(i)}}function eb(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
|
|
37
|
+
`))>=0;){const yt=Z.slice(0,xt);Z=Z.slice(xt+2);const st=Ix(yt);if(!st)continue;let Xe;try{Xe=JSON.parse(st)}catch{console.debug("[use-chat] malformed SSE:",st.slice(0,200));continue}const G=Ex(Xe)?Xe.data:Xe;se=Date.now();const be=G.seq;if(be!==void 0){if(be<=J){console.debug("[use-chat] drop duplicate/out-of-order event",{seq:be,lastProcessedSeq:J,type:G.type});continue}J>0&&be>J+1&&((B=L==null?void 0:L.onGap)==null||B.call(L,{from:J,to:be})),J=be,k.current=be,g(be)}if(console.debug("[use-chat] received event",{seq:G.seq,type:G.type,preview:(()=>{var ye;try{return G.type==="message_delta"?{deltaTypes:(ye=G.delta)==null?void 0:ye.map(Ie=>Ie.type),textLen:(G.delta||[]).filter(Ie=>Ie.type==="text").map(Ie=>String(Ie.text||"").length)}:G.content||G.delta?{hasContent:!0}:{}}catch(Ie){return{err:String(Ie)}}})()}),U==null||U(G),G.type==="token"&&e.autoAppendAssistant!==!1)D.push(G.content),ee();else if(G.type==="message_delta"){const ye=G.delta.filter(Ie=>Ie.type==="text").map(Ie=>Ie.text).join("");ye&&e.autoAppendAssistant!==!1&&(D.push(ye),ee())}else G.type==="heartbeat"?console.debug("[use-chat] heartbeat received"):(Q!==null&&cancelAnimationFrame(Q),de(),G.type==="checkpoint"?v(G.checkpointId):G.type==="error"&&d(G.message))}}de()}catch(Pe){if(Pe.name!=="AbortError"){const He=Pe.message||String(Pe);d(He),(le=L==null?void 0:L.onError)==null||le.call(L,He)}}finally{try{await me.cancel()}catch{}finally{(z=me.releaseLock)==null||z.call(me)}Q!==null&&typeof window<"u"&&window.cancelAnimationFrame(Q),clearInterval(Ge),l(!1),b(!1),S.current=null,k.current=0,g(0)}}catch(pe){if(pe.name!=="AbortError"){const ge=pe.message||String(pe);d(ge),(oe=L==null?void 0:L.onError)==null||oe.call(L,ge)}}finally{l(!1),b(!1),S.current=null,k.current=0,g(0)}})(),{close:()=>W.abort()}},[t,n,r,e.autoAppendAssistant]);return w.useEffect(()=>()=>{var j;E.current=!1,(j=S.current)==null||j.abort()},[]),{isStreaming:a,error:u,assistantText:f,lastCheckpointId:p,lastSeq:x,connected:y,stream:O,stop:I,clear:_,setToken:T}}function Ex(e){return!!e&&typeof e=="object"&&e.protocolVersion==="v1"&&"data"in e}function Ix(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 Ax({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(xx(p)){n(p);return}r==null||r(p)},[n,o,t,r]),{stream:a,stop:l,isStreaming:u,error:d,setToken:f}=Oc({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])}function Pi(e){return e==null?e:{...e}}function Nx(e){return e==null?e:{...e}}function _x(e){if(Array.isArray(e))return e.slice();if(e==null)return e}function jx(e){if(Array.isArray(e))return e.map(t=>({...t}));if(e==null)return e}function Xt(e,t={}){const n=t.cloneMessages??!1,r=Array.isArray(e==null?void 0:e.messages)?e.messages:[],o=Pi(e==null?void 0:e.metadata),s=Pi(e==null?void 0:e.config),i=Pi(e==null?void 0:e.parentConfig),a=_x(e==null?void 0:e.next),l=jx(e==null?void 0:e.tasks),u=Nx(e==null?void 0:e.values),d={checkpointId:(e==null?void 0:e.checkpointId)??null,checkpointNs:(e==null?void 0:e.checkpointNs)??null,createdAt:(e==null?void 0:e.createdAt)??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};return o!==void 0&&(d.metadata=o),s!==void 0&&(d.config=s),i!==void 0&&(d.parentConfig=i),a!==void 0&&(d.next=a),l!==void 0&&(d.tasks=l),u!==void 0&&(d.values=u),d}function Rx(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 Mc(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}}const qo=300;function Dc(e,t=qo){if(typeof window<"u"&&"requestIdleCallback"in window)try{window.requestIdleCallback(e,{timeout:t});return}catch{}window.setTimeout(e,t)}function ar(){return typeof window<"u"&&typeof window.localStorage<"u"}function Oi(e){if(!ar())return null;try{return window.localStorage.getItem(e)}catch{return null}}function Mi(e,t){if(!ar())return!1;try{return window.localStorage.setItem(e,t),!0}catch{return!1}}function Di(e){if(ar())try{window.localStorage.removeItem(e)}catch{}}const Px="cachedThreads",Ox="v1",Li=200;function Mx(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 Fi(e,t){return`cachedThreads:v1:${e}:${Mx(t||"anon")}`}function Dx(){const e=Oi(Px);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 Lx(e){const t=Oi(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 $i(e,t){Mi(e,JSON.stringify(t))}function zi(e){const t=Lx(e);if(t.length>0)return t;const n=Dx();if(n.length>0)try{$i(e,n.slice(0,Li))}catch{}return n}function Go(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 Bi(e){return e.order.map(t=>e.byId[t]).filter(Boolean)}function Hi(e,t){return`${e}${t}`}function Fx(e,t){const n=Oi(Hi(e,t));if(!n)return null;try{const r=JSON.parse(n);return typeof(r==null?void 0:r.threadId)!="string"?null:{threadId:r.threadId,snapshot:Xt(r.snapshot,{cloneMessages:!0}),updatedAt:typeof r.updatedAt=="number"?r.updatedAt:void 0}}catch{return null}}function $x(e,t,n=100){if(!ar())return;const r=Xt(t.snapshot,{cloneMessages:!0}),o={threadId:t.threadId,snapshot:{...r,messages:r.messages.slice(-n)},updatedAt:Date.now()},s=Hi(e,t.threadId),i=JSON.stringify(o);if(!Mi(s,i))try{const a=[];for(let l=0;l<window.localStorage.length;l++){const u=window.localStorage.key(l);if(!u||u===s||!u.startsWith(e))continue;const d=window.localStorage.getItem(u);if(!d){a.push({key:u,updatedAt:0});continue}try{const f=JSON.parse(d),h=typeof(f==null?void 0:f.updatedAt)=="number"&&Number.isFinite(f.updatedAt)?f.updatedAt:0;a.push({key:u,updatedAt:h})}catch{a.push({key:u,updatedAt:0})}}a.sort((l,u)=>l.updatedAt-u.updatedAt);for(const l of a)if(window.localStorage.removeItem(l.key),Mi(s,i))break}catch{}}function zx(e,t){Di(Hi(e,t))}function Bx(e){if(ar())try{for(let t=0;t<window.localStorage.length;t++){const n=window.localStorage.key(t);n&&n.startsWith(e)&&window.localStorage.removeItem(n)}}catch{}}const Lc=w.createContext(null),Fc=w.createContext(null),$c=w.createContext(null),Hx=w.createContext(!1),zc=50,Ux=750;function Bc(e,t,n){return`${e}__${t??""}__${n??""}`}function Yo(e,t){return t&&typeof t=="object"?{...e&&typeof e=="object"?{...e}:{},...t}:t===null?e&&typeof e=="object"?{...e}:e??null:e&&typeof e=="object"?{...e}:e??void 0}function Wx(e,t){return Yo(e,t)}function Vx(e,t){return Array.isArray(t)?t.slice():t===null?Array.isArray(e)?e.slice():e??null:Array.isArray(e)?e.slice():e??void 0}function Kx(e,t){return Array.isArray(t)?t.map(n=>({...n})):t===null?Array.isArray(e)?e.map(n=>({...n})):e??null:Array.isArray(e)?e.map(n=>({...n})):e??void 0}function Hc(e,t){const n=Yo(e.metadata,t.metadata),r=Yo(e.config,t.config),o=Yo(e.parentConfig,t.parentConfig),s=Vx(e.next,t.next),i=Kx(e.tasks,t.tasks),a=Wx(e.values,t.values),l={};return n!==void 0&&(l.metadata=n??null),r!==void 0&&(l.config=r??null),o!==void 0&&(l.parentConfig=o??null),s!==void 0&&(l.next=s??null),i!==void 0&&(l.tasks=i??null),a!==void 0&&(l.values=a??null),l}function qx({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}=Ni(),d=w.useMemo(()=>Pn(u),[u]),f=w.useMemo(()=>{try{return new URL(u).host}catch{return"unknown"}},[u]),h=w.useMemo(()=>`threadPayload:${Ox}:${f}:`,[f]),p=w.useCallback(A=>Fx(h,A),[h]),v=w.useCallback((A,N=100)=>{$x(h,A,N)},[h]),x=w.useCallback(A=>{zx(h,A)},[h]),g=w.useCallback(()=>{Bx(h)},[h]),[y,b]=w.useState(()=>{var A;return Fi(f,(A=l.getAuthToken)==null?void 0:A.call(l))}),[S,E]=w.useState(()=>{var N;const A=zi(Fi(f,(N=l.getAuthToken)==null?void 0:N.call(l)));return Go(A)}),k=w.useMemo(()=>Bi(S),[S]),[T,I]=w.useState(t),[_,O]=w.useState(!1),[j,U]=w.useState(!1),[L,W]=w.useState(null),[R,V]=w.useState(null),[$,ne]=w.useState(null),[F,B]=w.useState([]),le=w.useCallback(()=>{const A=zi(y);w.startTransition(()=>{E(Go(A))})},[y]),[z,oe]=w.useState(!1),[pe,ge]=w.useState(!1),[me,ve]=w.useState(null),[Z,D]=w.useState(void 0),[J,Q]=w.useState(void 0),[de,ee]=w.useState(void 0),{state:se,dispatch:Ge,seed:Ye,prepend:Pe,pushUser:He,onEvent:nt,reset:Qe}=Ec(),je=w.useRef(T);w.useEffect(()=>{je.current=T},[T]);const pt=w.useRef(!1),xt=w.useRef([]),yt=w.useRef(null),st=w.useRef(null),Xe=w.useRef(new Map),G=w.useRef(T),be=w.useRef(!1),ye=w.useRef(null),Ie=w.useRef(new Map),Je=w.useRef(new Map),Ze=w.useRef(new Map),kt=w.useRef(new Map),zt=w.useCallback(A=>{if(!A){B([]);return}const N=Ie.current.get(A);if(!N||!N.length){B([]);return}B(N.map(q=>Xt(q,{cloneMessages:!0})))},[]);w.useEffect(()=>{zt(T)},[T,zt]);const Ur=w.useCallback(()=>{var te;const A=kt.current;if(A.size<=zc)return;const N=Array.from(A.entries()).sort((ae,X)=>ae[1].timestamp-X[1].timestamp),q=A.size-zc;for(let ae=0;ae<q;ae++){const X=(te=N[ae])==null?void 0:te[0];X&&A.delete(X)}},[]),Ln=w.useCallback((A,N,q)=>{if(!A)return;const te=q==="replace"?[]:Ie.current.get(A)??[],ae=q==="replace"?N:[...N,...te];if(!ae.length){q==="replace"&&Ie.current.set(A,[]);return}const X=new Map;for(const ze of ae){if(!(ze!=null&&ze.checkpointId))continue;const Le=`${ze.checkpointId}::${ze.checkpointNs??""}`,qe=Xt(ze,{cloneMessages:!0}),ft=X.get(Le);if(!ft){X.set(Le,qe);continue}const Et=Hc(ft,qe);X.set(Le,{...ft,...Et})}const $e=Array.from(X.values()).sort((ze,Le)=>{const qe=Number.isFinite(Date.parse(ze.createdAt??""))?Date.parse(ze.createdAt??""):0;return(Number.isFinite(Date.parse(Le.createdAt??""))?Date.parse(Le.createdAt??""):0)-qe});Ie.current.set(A,$e),A===je.current&&zt(A)},[zt]),qt=w.useCallback((A,N,q)=>{if(!A)return;const te=Je.current.get(A),ae=q==="replace"||!te?new Map:new Map(te);if(N&&typeof N=="object")for(const[X,$e]of Object.entries(N)){if(!($e!=null&&$e.checkpointId))continue;const ze=X||Qr($e.checkpointId,$e.checkpointNs??null);ae.set(ze,Xt($e,{cloneMessages:!0}))}Je.current.set(A,ae)},[]),hn=w.useCallback((A,N)=>{const{threadId:q,checkpointId:te=null,checkpointNs:ae=null}=A,X=Bc(q,te,ae);if(N!=null&&N.force)Ze.current.delete(X),kt.current.delete(X);else{if(N!=null&&N.preferCache){const qe=kt.current.get(X);if(qe)return Promise.resolve(qe.payload)}const Le=Ze.current.get(X);if(Le)return Le}const ze=l.getStateHistory({threadId:q,checkpointId:te??void 0,checkpointNs:ae??void 0}).then(Le=>(kt.current.set(X,{payload:Le,timestamp:Date.now()}),Ur(),Le)).finally(()=>{Ze.current.get(X)===ze&&Ze.current.delete(X)});return Ze.current.set(X,ze),ze},[l,Ur]),Pt=w.useCallback((A,N)=>new Promise((q,te)=>{const ae=async()=>{pt.current=!0;try{await A(),q()}catch(X){te(X)}finally{pt.current=!1;const X=xt.current.shift();X&&X().catch(()=>{})}};pt.current?xt.current.push(ae):ae().catch(X=>{te(X)})}),[]),Qn=w.useRef(k.length),nn=w.useRef(!1);w.useEffect(()=>{Qn.current=k.length},[k.length]),w.useEffect(()=>{const A=se.pendingInterrupt??Rx(se.messages);Mc($,A)||ne(A??null)},[$,se.messages,se.pendingInterrupt]);const Tt=w.useCallback(async()=>{const A=Qn.current>0;A||O(!0);try{const N=await l.listThreads();w.startTransition(()=>{E(q=>{const te=$e=>$e.map(ze=>`${ze.threadId}:${ze.updatedAt??""}:${ze.messageCount??""}`).join("|"),ae=Bi(q);return te(ae)===te(N)||N.length===0&&ae.length>0&&!nn.current?q:Go(N)})}),W(null),nn.current||(nn.current=!0)}catch(N){i==null||i(String(N)),console.error("[ChatSessionProvider] Failed to refresh threads:",N),W(String(N))}finally{A||O(!1)}},[l,i]),Cr=w.useRef(!1),er=w.useRef(null),vt=w.useRef(null),rn=w.useRef(""),pn=w.useCallback((A,N)=>{if(!ar())return;vt.current!==null&&(window.clearTimeout(vt.current),vt.current=null);const q=A.map(ae=>`${ae.threadId}:${ae.updatedAt??""}:${ae.messageCount??""}`).join("|");if(A.length===0){try{Di(y)}catch{}rn.current="";return}if(q===rn.current)return;const te=()=>{try{const ae=A.slice(0,Li);$i(y,ae),rn.current=q}catch{}finally{vt.current=null}};if(N!=null&&N.immediate){te();return}vt.current=window.setTimeout(()=>{Dc(te)},qo)},[y]),kr=w.useCallback(()=>{pn(k,{immediate:!0})},[pn,k]),Gt=w.useCallback((A,N,q,te)=>{var Sm;const ae=q??je.current;if(!ae)return;const X=Xt(A),$e=ae===je.current,ze=(te==null?void 0:te.persist)!==!1;if(N==="replace"){if(ze){const St={threadId:ae,snapshot:Xt(A,{cloneMessages:!0})};Xe.current.set(ae,St),G.current=ae}if(!$e)return;Ye(X.messages,{checkpointId:X.checkpointId??null,checkpointNs:X.checkpointNs??null,pendingInterrupt:X.interrupt??null}),ne(X.interrupt??null),ve(X.nextCursor??null),oe(!!X.nextCursor),D(X.checkpointId??void 0),Q(X.checkpointNs??void 0),ee(X.nextCursorNs??void 0);return}const Le=Xe.current.get(ae),qe=(Le==null?void 0:Le.snapshot)??null,ft=Array.isArray(qe==null?void 0:qe.messages)?qe.messages:[],Et=Xt(qe),_n=Array.isArray(A==null?void 0:A.messages)?A.messages:[],It=new Set,At=[..._n,...ft].filter(St=>{const Cl=St==null?void 0:St.id;return Cl?It.has(Cl)?!1:(It.add(Cl),!0):!0}),_o=Hc(Et,X),jo={checkpointId:Et.checkpointId??X.checkpointId??null,checkpointNs:Et.checkpointNs??X.checkpointNs??null,createdAt:X.createdAt??Et.createdAt??null,parentId:X.parentId??Et.parentId??null,branchLabel:X.branchLabel??Et.branchLabel??null,lastMessageId:((Sm=At[At.length-1])==null?void 0:Sm.id)??null,messagesLen:At.length,hasMessages:At.length>0,messages:At,nextCursor:X.nextCursor??Et.nextCursor??null,nextCursorNs:X.nextCursorNs??Et.nextCursorNs??null,interrupt:Et.interrupt??X.interrupt??null,..._o};if(Xe.current.set(ae,{threadId:ae,snapshot:Xt(jo,{cloneMessages:!0})}),!$e)return;_n.length&&Pe(_n);const jn=A&&Object.prototype.hasOwnProperty.call(A,"checkpointId")?A.checkpointId:void 0,Ro=A&&Object.prototype.hasOwnProperty.call(A,"checkpointNs")?A.checkpointNs:void 0,Rn=A&&Object.prototype.hasOwnProperty.call(A,"nextCursor")?A.nextCursor:void 0,Sl=A&&Object.prototype.hasOwnProperty.call(A,"nextCursorNs")?A.nextCursorNs:void 0;ve(St=>Rn!==void 0?Rn??St??null:St??null),oe(St=>Rn!==void 0?!!Rn:St),D(St=>jn!==void 0?jn??St??void 0:St??void 0),Q(St=>Ro!==void 0?Ro??St??void 0:St??void 0),ee(St=>Sl!==void 0?Sl??void 0:St)},[Pe,Ye,ne]),Tr=w.useCallback(A=>{if(A.threadId!=null&&A.threadId!==je.current)return;const N=Xt(A.snapshot,{cloneMessages:!0});Ye(N.messages,{checkpointId:N.checkpointId??null,checkpointNs:N.checkpointNs??null,pendingInterrupt:N.interrupt??null}),ne(N.interrupt??null),ve(N.nextCursor??null),oe(!!N.nextCursor),D(N.checkpointId??void 0),Q(N.checkpointNs??void 0),ee(N.nextCursorNs??void 0),G.current=A.threadId,zt(A.threadId??je.current??null)},[Ye,ne,zt]),Nn=w.useCallback(A=>{if(!A)return;Xe.current.delete(A),x(A),Ie.current.delete(A),Je.current.delete(A),A===je.current&&B([]);const N=`${A}__`;for(const q of Ze.current.keys())q.startsWith(N)&&Ze.current.delete(q);for(const q of kt.current.keys())q.startsWith(N)&&kt.current.delete(q);G.current===A&&(G.current=null)},[x]),mn=w.useCallback(()=>{const A=je.current;A&&Nn(A),Qe([]),oe(!1),ge(!1),ve(null),D(void 0),Q(void 0),ee(void 0)},[Nn,Qe]),tr=w.useCallback(({from:A,to:N})=>{const q=je.current;q&&console.warn(`[ChatSessionProvider] Stream sequence gap detected (${A} -> ${N}) for thread ${q}`)},[]),Ao=w.useCallback(A=>{const N=A.threadId;console.log("[ChatSessionProvider] 📥 Handling thread_info event:",{threadId:N,title:A.title,created:A.created,currentThreads:k.length});const q={threadId:N,title:A.title||`Thread ${N.slice(0,8)}`,createdAt:A.createdAt||new Date().toISOString(),updatedAt:A.updatedAt||new Date().toISOString(),messageCount:A.messageCount||0};je.current!==N&&(!je.current&&se.messages.length<=1&&(st.current=N),I(N)),w.startTransition(()=>{E(te=>{const ae=te.byId[N];return ae?ae.title===q.title&&ae.updatedAt===q.updatedAt&&ae.messageCount===q.messageCount?te:{byId:{...te.byId,[N]:q},order:te.order}:{byId:{...te.byId,[N]:q},order:[N,...te.order]}})})},[se.messages.length]),{startStream:Wr,stop:Vr,isStreaming:nr,error:C,setAuthToken:P}=Ax({baseUrl:d,onThreadInfo:Ao,onMessageEvent:nt,onUnhandledEvent:A=>{console.warn(`[ChatSessionProvider] Unhandled stream event: ${A.type}`,A)},onSequenceGap:tr});w.useEffect(()=>{Cr.current=nr},[nr]),w.useEffect(()=>{if(!ar())return;vt.current!==null&&(window.clearTimeout(vt.current),vt.current=null);const A=k.map(q=>`${q.threadId}:${q.updatedAt??""}:${q.messageCount??""}`).join("|");if(k.length===0){try{Di(y)}catch{}rn.current="";return}if(A===rn.current)return;const N=()=>{try{const q=k.slice(0,Li);$i(y,q),rn.current=A}catch{}finally{vt.current=null}};return vt.current=window.setTimeout(()=>{Dc(N),vt.current=null},qo),()=>{vt.current!==null&&(window.clearTimeout(vt.current),vt.current=null)}},[k,pn]),w.useEffect(()=>{var te;const A=l.getAuthToken();P(A);const N=ae=>{const X=Fi(f,ae);ye.current!==X&&(ye.current=X,be.current=!1),b(X);const $e=zi(X);w.startTransition(()=>{E(Go($e))}),be.current||(be.current=!0,Tt().catch(()=>{}))};N(A);const q=(te=l.onTokenChange)==null?void 0:te.call(l,ae=>{P(ae),g(),Ze.current.clear(),kt.current.clear(),N(ae)});return()=>{q==null||q()}},[l,f,P,g,Tt]);const H=w.useCallback(async A=>{var te;const N=`Thread ${(te=crypto.randomUUID)==null?void 0:te.call(crypto)}`,q={threadId:N,title:A||"New Chat",createdAt:new Date().toISOString(),updatedAt:new Date().toISOString(),messageCount:0};E(ae=>({byId:{...ae.byId,[N]:q},order:[N,...ae.order]})),I(N);try{const ae=await l.createThread(A),X=typeof ae=="string"?ae:ae.threadId;return E($e=>{const ze=$e.byId[N];if(!ze)return $e;const Le={...$e.byId};delete Le[N],Le[X]={...ze,threadId:X};const qe=$e.order.map(ft=>ft===N?X:ft);return{byId:Le,order:qe}}),I(X),setTimeout(()=>Tt(),10),W(null),X}catch(ae){throw E(X=>{if(!X.byId[N])return X;const $e={...X.byId};delete $e[N];const ze=X.order.filter(Le=>Le!==N);return{byId:$e,order:ze}}),I(null),W(String(ae)),ae}},[l,Tt]),ie=w.useCallback(async A=>{try{await l.deleteThread(A);let N=null;E(q=>{if(!q.byId[A])return q;const te={...q.byId};delete te[A];const ae=q.order.filter($e=>$e!==A),X={byId:te,order:ae};return N=Bi(X),X}),N&&pn(N,{immediate:!0}),Nn(A),je.current===A&&(st.current=A,I(null),je.current=null,G.current=null,mn()),await Tt(),W(null)}catch(N){throw W(String(N)),N}},[l,mn,Nn,Tt,pn]),ke=w.useCallback(async(A,N)=>{try{await l.updateThread(A,N),E(q=>{const te=q.byId[A];return te?{byId:{...q.byId,[A]:{...te,title:N}},order:q.order}:q}),W(null)}catch(q){throw await Tt(),W(String(q)),q}},[l,Tt]),Ne=w.useCallback(async(A,N,q,te=!1)=>{await Pt(async()=>{if(st.current===A&&!te){st.current=null;return}if(yt.current===A&&!te)return;I(It=>It===A?It:A),je.current=A;const $e=Bc(A,N??null,q??null),ze=kt.current.get($e),Le=!te&&!N&&!q&&ze&&Date.now()-ze.timestamp<Ux,qe=!te&&!N&&!q;let ft=!1;if(qe){const It=Xe.current.get(A);if(It)Tr(It),ft=!0;else{const At=p(A);At&&(Xe.current.set(A,At),Tr(At),ft=!0)}}const Et=te||!ft||!!N||!!q,_n=async It=>{It&&U(!0),yt.current=A;try{const At=await hn({threadId:A,checkpointId:N,checkpointNs:q},{force:te}),{latest:_o,checkpoints:jo,snapshots:jn}=ji(At);Gt(_o,"replace",A),Ln(A,jo,"replace"),qt(A,jn,"replace"),V(null)}catch(At){throw(!ft||te||It)&&(i==null||i(String(At))),V(String(At)),At}finally{yt.current=null,It&&U(!1)}};Et?await _n(!0):qe&&ft&&!Le&&_n(!1).catch(It=>{console.warn("[ChatSessionProvider] Background refresh failed:",It)})},`loadThread-${A}`)},[Tr,Gt,Pt,hn,i,Ln,qt]),De=w.useCallback(async()=>{await Pt(async()=>{const A=je.current;A&&Nn(A),st.current=null,I(null),je.current=null,G.current=null,mn(),D(void 0),Q(void 0),ee(void 0),B([]);try{localStorage.removeItem("lastThreadId")}catch(N){console.warn("[ChatSessionProvider] Failed to clear lastThreadId:",N)}},"clearCurrentThread")},[mn,Nn,Pt]),Oe=w.useCallback(async(A,N)=>{var X;const q=je.current;if(!q)throw new Error("No active thread");const te=Qr(A,N??null),ae=(X=Je.current.get(q))==null?void 0:X.get(te);if(ae){await Pt(async()=>{Gt(ae,"replace",q,{persist:!1})},`navigateToCheckpoint-${q}-${te}`);return}await Ne(q,A,N??void 0,!0)},[Gt,Pt,Ne]),bt=w.useCallback(async()=>{if(!je.current)throw new Error("No active thread");await Ne(je.current,void 0,void 0,!0)},[Ne]),at=w.useCallback(async()=>{if(!je.current)throw new Error("No active thread");if(pe||!z)return;const A=me;if(A){ge(!0);try{const N=je.current,q=await hn({threadId:N,checkpointId:A??Z??null,checkpointNs:de??J??null}),{latest:te,checkpoints:ae,snapshots:X}=ji(q),$e=N?Je.current.get(N):null;let ze=ae.length>0;if(ze&&$e&&$e.size>0&&(ze=ae.some(Le=>{if(!(Le!=null&&Le.checkpointId))return!1;const qe=Qr(Le.checkpointId,Le.checkpointNs??null);return!$e.has(qe)})),!ze){ve(null),ee(void 0),oe(!1),V(null);return}Gt(te,"prepend",N??void 0),N&&(Ln(N,ae,"prepend"),qt(N,X,"prepend")),V(null)}catch(N){throw V(String(N)),N}finally{ge(!1)}}},[Gt,hn,z,Z,J,de,me,pe,Ln,qt]),ct=w.useCallback(A=>{if(A!=null&&A.threadId){if(A.checkpointId){const N=Qr(A.checkpointId,A.checkpointNs??null),q=Xt({...A,interrupt:A.interrupt??null},{cloneMessages:!0});qt(A.threadId,{[N]:q},"prepend")}Gt(A,"replace",A.threadId)}},[Gt,qt]),wt=w.useCallback(async(A,N)=>{var Ro;const q=je.current,te=(A==null?void 0:A.text)??"",ae=(A==null?void 0:A.attachments)??[],X=ae.length?ae:(N==null?void 0:N.attachments)??[],$e={...(N==null?void 0:N.payloadExtras)??{},...(A==null?void 0:A.payload)??{}};if(!q&&!Object.keys($e).length&&X.length===0&&!te.trim()){console.warn("[ChatSessionProvider] Nothing to submit - skipping");return}!q&&!$e.messages&&console.warn("[ChatSessionProvider] No thread ID - message will create new thread");const{contentParts:ze,filesInfo:Le}=await Qg(l,X),qe=[...ze];te&&te.trim()&&qe.push({type:"text",text:te.trim()});const ft=!!q,Et=ft?(N==null?void 0:N.checkpointId)??se.lastCheckpointId??void 0:void 0,_n=ft?(N==null?void 0:N.checkpointNs)??se.lastCheckpointNs??void 0:void 0,It={id:((Ro=crypto.randomUUID)==null?void 0:Ro.call(crypto))||`user-${Date.now()}`,role:"user",content:qe,createdAt:new Date().toISOString(),...Et!=null?{checkpointId:Et}:{},..._n!=null?{checkpointNs:_n}:{}};qe.length>0&&He(It);const At={...It,content:qe},_o=X.length>0,jo={messages:qe.length>0?[At]:[],files_info:Le,...o&&_o&&s?{active_agent:s}:{},...$e},jn={threadId:q??null,payload:jo,checkpointId:Et??null,checkpointNs:_n??null,nodeFilter:(N==null?void 0:N.nodeFilter)??null,config:N==null?void 0:N.config,command:(N==null?void 0:N.command)??null};jn.threadId||delete jn.threadId,jn.command||delete jn.command,Wr(jn,{onError:Rn=>{console.warn("[ChatSessionProvider] Stream error:",Rn)},onOpen:({threadId:Rn})=>{!je.current&&Rn&&(se.messages.length<=1&&(st.current=Rn),I(Rn))},onGap:tr})},[l,o,s,tr,se.lastCheckpointId,se.lastCheckpointNs,se.messages.length,He,Wr]),Fn=w.useCallback(async(A,N,q)=>{if(!je.current)throw new Error("No active thread to handle interrupt");const ae=N?q??!0:!1;try{try{Ge({type:"interrupt_response",payload:{interruptId:A}})}catch(X){console.warn("[ChatSessionProvider] optimistic interrupt_response dispatch failed:",X)}await wt({payload:{}},{checkpointId:se.lastCheckpointId??void 0,checkpointNs:se.lastCheckpointNs??void 0,command:{kind:"resume",value:ae}}),ne(null)}catch(X){throw console.error(`[ChatSessionProvider] Failed to handle interrupt ${A}:`,X),X}},[Ge,se.lastCheckpointId,se.lastCheckpointNs,wt]);w.useEffect(()=>{if(a==null||a(T),T)try{localStorage.setItem("lastThreadId",T)}catch(A){console.warn("[ChatSessionProvider] Failed to persist lastThreadId:",A)}},[T,a]),w.useEffect(()=>((async()=>{try{if(Tt().catch(N=>{console.error("[ChatSessionProvider] Failed to refresh threads (background):",N),i==null||i(String(N))}),!r&&!t)try{const N=localStorage.getItem("lastThreadId");N&&(I(N),n&&await Ne(N))}catch(N){console.warn("[ChatSessionProvider] Failed to restore last thread:",N)}else t&&n&&await Ne(t)}catch(N){console.error("[ChatSessionProvider] Initialization failed:",N),i==null||i(String(N))}})(),()=>{}),[]),w.useEffect(()=>{const A=je.current;if(!A||G.current!==A)return;se.messages.length&&se.messages[se.messages.length-1];const N=Xt({checkpointId:se.lastCheckpointId??null,checkpointNs:se.lastCheckpointNs??null,messages:se.messages.slice(),nextCursor:me??null,nextCursorNs:de??null,interrupt:se.pendingInterrupt??$??null}),q=Xe.current.get(A),te=q==null?void 0:q.snapshot,ae=!te||te.messages.length!==N.messages.length||te.messages.some((Le,qe)=>{var ft;return(Le==null?void 0:Le.id)!==((ft=N.messages[qe])==null?void 0:ft.id)}),X=((te==null?void 0:te.checkpointId)??null)!==N.checkpointId||((te==null?void 0:te.checkpointNs)??null)!==N.checkpointNs,$e=((te==null?void 0:te.nextCursor)??null)!==N.nextCursor||((te==null?void 0:te.nextCursorNs)??null)!==N.nextCursorNs,ze=!Mc((te==null?void 0:te.interrupt)??null,N.interrupt??null);if(ae||X||$e||ze){const Le={threadId:A,snapshot:N};Xe.current.set(A,Le),er.current&&window.clearTimeout(er.current),er.current=window.setTimeout(()=>{try{v(Le,100)}catch(qe){console.warn("[ChatSessionProvider] Failed to persist thread payload:",qe)}},qo)}},[me,de,se.lastCheckpointId,se.lastCheckpointNs,se.messages,se.pendingInterrupt,$,v]);const $n=w.useMemo(()=>({threads:k,currentThreadId:T,setCurrentThreadId:I,isLoading:_,error:L,actions:{createThread:H,deleteThread:ie,renameThread:ke,refreshThreads:()=>Tt()},persistThreadsCache:kr,hydrateFromCache:le}),[k,T,_,L,H,ie,ke,Tt,kr,le,I]),Ot=w.useMemo(()=>{const A=se.lastBranch??null,N=se.assemblingId??null,q=A||N?{branchLabel:(A==null?void 0:A.branchLabel)??null,lastBranch:A,assemblingMessageId:N}:null;return{threadId:T,messages:se.messages,interrupt:$,checkpoint:{id:se.lastCheckpointId??null,namespace:se.lastCheckpointNs??null},checkpoints:F,metadata:q,isLoading:j,isHistoryLoading:pe,error:R,hasMore:z,loadOlder:at,seedFromSnapshot:ct,clearState:mn,navigateToCheckpoint:Oe,returnToLatest:bt,loadThread:Ne,clearThread:De,respondToInterrupt:Fn}},[De,mn,T,$,z,pe,j,at,Ne,se.assemblingId,se.lastBranch,se.lastCheckpointId,se.lastCheckpointNs,se.messages,Oe,Fn,bt,ct,R,F]),No=w.useMemo(()=>({isStreaming:nr,error:C,submit:wt,send:wt,stop:Vr,setAuthToken:P}),[nr,C,wt,Vr,P]);return c.jsx(Hx.Provider,{value:!0,children:c.jsx($c.Provider,{value:No,children:c.jsx(Lc.Provider,{value:$n,children:c.jsx(Fc.Provider,{value:Ot,children:e})})})})}function Xo(){const e=w.useContext(Lc);if(!e)throw new Error("useThreads must be used within ChatSessionProvider");return e}function Jo(){const e=w.useContext(Fc);if(!e)throw new Error("useThreadState must be used within ChatSessionProvider");return e}function Uc(){const e=w.useContext($c);if(!e)throw new Error("useStream must be used within ChatSessionProvider");return e}function Zo({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(Jg,{apiConfig:t,children:c.jsx(qx,{initialThreadId:n,autoLoadInitial:r,disableAutoRestore:o,enableFileAgentRouting:s,fileAgentId:i,onError:a,onThreadChange:l,children:e})})}function re(...e){return Em.twMerge(Tm.clsx(e))}const Gx=Po.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"}}),Ve=m.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...o},s)=>{const i=r?rr.Slot:"button";return c.jsx(i,{className:re(Gx({variant:t,size:n,className:e})),ref:s,...o})});Ve.displayName="Button";const Wc=m.forwardRef(({className:e,...t},n)=>c.jsx("textarea",{className:re("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}));Wc.displayName="Textarea";function Yx({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),y=w.useRef(0),b=w.useRef(null);w.useEffect(()=>{p(e??""),b.current=null,g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[e,t]);const S=w.useCallback(()=>{const j=g.current;j&&(j.style.height="auto",j.style.height=`${j.scrollHeight}px`)},[]);w.useEffect(()=>{S()},[S]);const E=w.useCallback(async j=>{j&&j.preventDefault();const U=(h??"").trim();if(!U&&!f)return;const L=++y.current;b.current={id:L,shouldClear:!0},x(()=>{var W,R,V;try{const $=i(U);$&&typeof $.then=="function"?$.then(()=>{var ne,F;((ne=b.current)==null?void 0:ne.id)===L&&b.current.shouldClear&&(p(""),g.current&&(g.current.style.height="auto")),((F=b.current)==null?void 0:F.id)===L&&(b.current=null)}).catch(()=>{var ne;((ne=b.current)==null?void 0:ne.id)===L&&(b.current=null)}):(((W=b.current)==null?void 0:W.id)===L&&b.current.shouldClear&&(p(""),g.current&&(g.current.style.height="auto")),((R=b.current)==null?void 0:R.id)===L&&(b.current=null))}catch{((V=b.current)==null?void 0:V.id)===L&&(b.current=null)}})},[h,i,f]),k=w.useCallback(j=>{p(j.target.value),b.current&&(b.current.shouldClear=!1),g.current&&(g.current.style.height="auto",g.current.style.height=`${g.current.scrollHeight}px`)},[]),T=w.useCallback(j=>{j.key==="Enter"&&!j.shiftKey?(j.preventDefault(),E()):j.key==="Escape"&&t&&(j.preventDefault(),a==null||a())},[E,t,a]),O=`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:j=>void E(j),className:`w-full ${u}`,children:c.jsxs("div",{className:"flex items-end gap-2",children:[c.jsx("div",{className:"flex-1",children:c.jsx(Wc,{ref:g,value:h,onChange:k,onKeyDown:T,placeholder:t?"Edit your message...":n,className:O,disabled:o,maxLength:s,rows:1,spellCheck:!1,autoCorrect:"off"})}),c.jsx("div",{children:r?c.jsx(Ve,{type:"button",onClick:()=>{l==null||l()},size:"icon",variant:"outline",className:"shrink-0",title:"Stop generating",disabled:o||!l,children:c.jsx(he.Square,{size:16})}):c.jsx(Ve,{type:"submit",size:"icon",className:"shrink-0",title:t?"Save changes":"Send message",disabled:o||!h.trim()&&!f||v,children:c.jsx(he.Send,{size:16})})})]})})}const Xx=w.memo(Yx),Qo=0,Bn=1,Nr=2,Vc=4;function Kc(e){return()=>e}function Jx(e){e()}function qc(e,t){return n=>e(t(n))}function Gc(e,t){return()=>e(t)}function Zx(e,t){return n=>e(t,n)}function Ui(e){return e!==void 0}function Qx(...e){return()=>{e.map(Jx)}}function _r(){}function es(e,t){return t(e),e}function ey(e,t){return t(e)}function rt(...e){return e}function Ke(e,t){return e(Bn,t)}function Me(e,t){e(Qo,t)}function Wi(e){e(Nr)}function dt(e){return e(Vc)}function xe(e,t){return Ke(e,Zx(t,Qo))}function an(e,t){const n=e(Bn,r=>{n(),t(r)});return n}function Yc(e){let t,n;return r=>o=>{t=o,n&&clearTimeout(n),n=setTimeout(()=>{r(t)},e)}}function Xc(e,t){return e===t}function ot(e=Xc){let t;return n=>r=>{e(t,r)||(t=r,n(r))}}function Te(e){return t=>n=>{e(n)&&t(n)}}function ce(e){return t=>qc(t,e)}function yn(e){return t=>()=>{t(e)}}function K(e,...t){const n=ty(...t);return(r,o)=>{switch(r){case Nr:Wi(e);return;case Bn:return Ke(e,n(o))}}}function vn(e,t){return n=>r=>{n(t=e(t,r))}}function lr(e){return t=>n=>{e>0?e--:t(n)}}function On(e){let t=null,n;return r=>o=>{t=o,!n&&(n=setTimeout(()=>{n=void 0,r(t)},e))}}function Fe(...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);Ke(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 ty(...e){return t=>e.reduceRight(ey,t)}function ny(e){let t,n;const r=()=>t==null?void 0:t();return function(o,s){switch(o){case Bn:return s?n===s?void 0:(r(),n=s,t=Ke(e,s),t):(r(),_r);case Nr:r(),n=null;return}}}function Y(e){let t=e;const n=Ue();return(r,o)=>{switch(r){case Qo:t=o;break;case Bn:{o(t);break}case Vc:return t}return n(r,o)}}function _t(e,t){return es(Y(t),n=>xe(e,n))}function Ue(){const e=[];return(t,n)=>{switch(t){case Qo:e.slice().forEach(r=>{r(n)});return;case Nr:e.splice(0,e.length);return;case Bn:return e.push(n),()=>{const r=e.indexOf(n);r>-1&&e.splice(r,1)}}}}function Ht(e){return es(Ue(),t=>xe(e,t))}function We(e,t=[],{singleton:n}={singleton:!0}){return{constructor:e,dependencies:t,id:ry(),singleton:n}}const ry=()=>Symbol();function oy(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 ht(...e){const t=Ue(),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);Ke(s,l=>{n[i]=l,r=r|a,r===o&&Me(t,n)})}),function(s,i){switch(s){case Nr:{Wi(t);return}case Bn:return r===o&&i(n),Ke(t,i)}}}function Ce(e,t=Xc){return K(e,ot(t))}function Vi(...e){return function(t,n){switch(t){case Nr:return;case Bn:return Qx(...e.map(r=>Ke(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 sy={0:"debug",3:"error",1:"log",2:"warn"},iy=()=>typeof globalThis>"u"?window:globalThis,Hn=We(()=>{const e=Y(3);return{log:Y((t,n,r=1)=>{var o;const s=(o=iy().VIRTUOSO_LOG_LEVEL)!=null?o:dt(e);r>=s&&console[sy[r]]("%creact-virtuoso: %c%s %o","color: #0253b3; font-weight: bold","color: initial",t,n)}),logLevel:e}},[],{singleton:!0});function cr(e,t,n){return Ki(e,t,n).callbackRef}function Ki(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 ay(e,t,n,r,o,s,i,a,l){const u=w.useCallback(d=>{const f=ly(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?Jc("column-gap",getComputedStyle(d).columnGap,o):Jc("row-gap",getComputedStyle(d).rowGap,o)),f!==null&&e(f)},[e,t,o,s,i,r,a]);return Ki(u,n,l)}function ly(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 Jc(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 Zc(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}=Ki(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 Mt=We(()=>{const e=Ue(),t=Ue(),n=Y(0),r=Ue(),o=Y(0),s=Ue(),i=Ue(),a=Y(0),l=Y(0),u=Y(0),d=Y(0),f=Ue(),h=Ue(),p=Y(!1),v=Y(!1),x=Y(!1);return xe(K(e,ce(({scrollTop:g})=>g)),t),xe(K(e,ce(({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}),to={lvl:0};function Qc(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 et(e){return e===to}function no(e,t){if(!et(e))return t===e.k?e.v:t<e.k?no(e.l,t):no(e.r,t)}function ln(e,t,n="k"){if(et(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 Ut(e,t,n){return et(e)?nu(t,n,1):t===e.k?mt(e,{k:t,v:n}):t<e.k?ru(mt(e,{l:Ut(e.l,t,n)})):ru(mt(e,{r:Ut(e.r,t,n)}))}function jr(){return to}function ts(e,t,n){if(et(e))return[];const r=ln(e,t)[0];return cy(Gi(e,r,n))}function qi(e,t){if(et(e))return to;const{k:n,l:r,r:o}=e;if(t===n){if(et(r))return o;if(et(o))return r;{const[s,i]=tu(r);return ns(mt(e,{k:s,l:eu(r),v:i}))}}else return t<n?ns(mt(e,{l:qi(r,t)})):ns(mt(e,{r:qi(o,t)}))}function ur(e){return et(e)?[]:[...ur(e.l),{k:e.k,v:e.v},...ur(e.r)]}function Gi(e,t,n){if(et(e))return[];const{k:r,l:o,r:s,v:i}=e;let a=[];return r>t&&(a=a.concat(Gi(o,t,n))),r>=t&&r<=n&&a.push({k:r,v:i}),r<=n&&(a=a.concat(Gi(s,t,n))),a}function ns(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(Yi(t))return ou(mt(e,{lvl:n-1}));if(!et(t)&&!et(t.r))return mt(t.r,{l:mt(t,{r:t.r.l}),lvl:n,r:mt(e,{l:t.r.r,lvl:n-1})});throw new Error("Unexpected empty nodes")}else{if(Yi(e))return Xi(mt(e,{lvl:n-1}));if(!et(r)&&!et(r.l)){const o=r.l,s=Yi(o)?r.lvl-1:r.lvl;return mt(o,{l:mt(e,{lvl:n-1,r:o.l}),lvl:o.lvl+1,r:Xi(mt(r,{l:o.r,lvl:s}))})}else throw new Error("Unexpected empty nodes")}}function mt(e,t){return nu(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 eu(e){return et(e.r)?e.l:ns(mt(e,{r:eu(e.r)}))}function Yi(e){return et(e)||e.lvl>e.r.lvl}function tu(e){return et(e.r)?[e.k,e.v]:tu(e.r)}function nu(e,t,n,r=to,o=to){return{k:e,l:r,lvl:n,r:o,v:t}}function ru(e){return Xi(ou(e))}function ou(e){const{l:t}=e;return!et(t)&&t.lvl===e.lvl?mt(t,{r:mt(e,{l:t.r})}):e}function Xi(e){const{lvl:t,r:n}=e;return!et(n)&&!et(n.r)&&n.lvl===t&&n.r.lvl===t?mt(n,{l:mt(e,{r:n.l}),lvl:t+1}):e}function cy(e){return Qc(e,({k:t,v:n})=>({index:t,value:n}))}function su(e,t){return!!(e&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex)}function ro(e,t){return!!(e&&e[0]===t[0]&&e[1]===t[1])}const Ji=We(()=>({recalcInProgress:Y(!1)}),[],{singleton:!0});function iu(e,t,n){return e[rs(e,t,n)]}function rs(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 uy(e,t,n,r){const o=rs(e,t,r),s=rs(e,n,r,o);return e.slice(o,s+1)}function Un(e,t){return Math.round(e.getBoundingClientRect()[t])}function os(e){return!et(e.groupOffsetTree)}function Zi({index:e},t){return t===e?0:t<e?-1:1}function dy(){return{groupIndices:[],groupOffsetTree:jr(),lastIndex:0,lastOffset:0,lastSize:0,offsetTree:[],sizeTree:jr()}}function fy(e,t){let n=et(e)?0:1/0;for(const r of t){const{endIndex:o,size:s,startIndex:i}=r;if(n=Math.min(n,i),et(e)){e=Ut(e,0,s);continue}const a=ts(e,i-1,o+1);if(a.some(vy(r)))continue;let l=!1,u=!1;for(const{end:d,start:f,value:h}of a)l?(o>=f||s===h)&&(e=qi(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 hy(e){return typeof e.groupIndex<"u"}function py({offset:e},t){return t===e?0:t<e?-1:1}function oo(e,t,n){if(t.length===0)return 0;const{index:r,offset:o,size:s}=iu(t,e,Zi),i=e-r,a=s*i+(i-1)*n+o;return a>0?a+n:a}function au(e,t){if(!os(t))return e;let n=0;for(;t.groupIndices[n]<=e+n;)n++;return e+n}function lu(e,t,n){if(hy(e))return t.groupIndices[e.groupIndex]+1;{const r=e.index==="LAST"?n:e.index;let o=au(r,t);return o=Math.max(0,o,Math.min(n,o)),o}}function my(e,t,n,r=0){return r>0&&(t=Math.max(t,iu(e,r,Zi).offset)),Qc(uy(e,t,n,py),yy)}function gy(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&&et(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]=fy(i,t);if(i===s)return e;const{lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f}=Qi(e.offsetTree,a,i,o);return{groupIndices:n,groupOffsetTree:n.reduce((h,p)=>Ut(h,p,oo(p,f,o)),jr()),lastIndex:l,lastOffset:u,lastSize:d,offsetTree:f,sizeTree:i}}function xy(e){return ur(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 cu(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 Qi(e,t,n,r){let o=e,s=0,i=0,a=0,l=0;if(t!==0){l=rs(o,t-1,Zi),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 ts(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 yy(e){return{index:e.index,value:e}}function vy(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 by={offsetHeight:"height",offsetWidth:"width"},bn=We(([{log:e},{recalcInProgress:t}])=>{const n=Ue(),r=Ue(),o=_t(r,0),s=Ue(),i=Ue(),a=Y(0),l=Y([]),u=Y(void 0),d=Y(void 0),f=Y((k,T)=>Un(k,by[T])),h=Y(void 0),p=Y(0),v=dy(),x=_t(K(n,Fe(l,e,p),vn(gy,v),ot()),v),g=_t(K(l,ot(),vn((k,T)=>({current:T,prev:k.current}),{current:[],prev:[]}),ce(({prev:k})=>k)),[]);xe(K(l,Te(k=>k.length>0),Fe(x,p),ce(([k,T,I])=>{const _=k.reduce((O,j,U)=>Ut(O,j,oo(j,T.offsetTree,I)||U),jr());return{...T,groupIndices:k,groupOffsetTree:_}})),x),xe(K(r,Fe(x),Te(([k,{lastIndex:T}])=>k<T),ce(([k,{lastIndex:T,lastSize:I}])=>[{endIndex:T,size:I,startIndex:k}])),n),xe(u,d);const y=_t(K(u,ce(k=>k===void 0)),!0);xe(K(d,Te(k=>k!==void 0&&et(dt(x).sizeTree)),ce(k=>[{endIndex:0,size:k,startIndex:0}])),n);const b=Ht(K(n,Fe(x),vn(({sizes:k},[T,I])=>({changed:I!==k,sizes:I}),{changed:!1,sizes:v}),ce(k=>k.changed)));Ke(K(a,vn((k,T)=>({diff:k.prev-T,prev:T}),{diff:0,prev:0}),ce(k=>k.diff)),k=>{const{groupIndices:T}=dt(x);if(k>0)Me(t,!0),Me(s,k+cu(k,T));else if(k<0){const I=dt(g);I.length>0&&(k-=cu(-k,I)),Me(i,k)}}),Ke(K(a,Fe(e)),([k,T])=>{k<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(K(s,Fe(x),ce(([k,T])=>{const I=T.groupIndices.length>0,_=[],O=T.lastSize;if(I){const j=no(T.sizeTree,0);let U=0,L=0;for(;U<k;){const R=T.groupIndices[L],V=T.groupIndices.length===L+1?1/0:T.groupIndices[L+1]-R-1;_.push({endIndex:R,size:j,startIndex:R}),_.push({endIndex:R+1+V-1,size:O,startIndex:R+1}),L++,U+=V+1}const W=ur(T.sizeTree);return U!==k&&W.shift(),W.reduce((R,{k:V,v:$})=>{let ne=R.ranges;return R.prevSize!==0&&(ne=[...R.ranges,{endIndex:V+k-1,size:R.prevSize,startIndex:R.prevIndex}]),{prevIndex:V+k,prevSize:$,ranges:ne}},{prevIndex:k,prevSize:0,ranges:_}).ranges}return ur(T.sizeTree).reduce((j,{k:U,v:L})=>({prevIndex:U+k,prevSize:L,ranges:[...j.ranges,{endIndex:U+k-1,size:j.prevSize,startIndex:j.prevIndex}]}),{prevIndex:0,prevSize:O,ranges:[]}).ranges})),n);const E=Ht(K(i,Fe(x,p),ce(([k,{offsetTree:T},I])=>{const _=-k;return oo(_,T,I)})));return xe(K(i,Fe(x,p),ce(([k,T,I])=>{if(T.groupIndices.length>0){if(et(T.sizeTree))return T;let _=jr();const O=dt(g);let j=0,U=0,L=0;for(;j<-k;){L=O[U];const W=O[U+1]-L-1;U++,j+=W+1}if(_=ur(T.sizeTree).reduce((W,{k:R,v:V})=>Ut(W,Math.max(0,R+k),V),_),j!==-k){const W=no(T.sizeTree,L);_=Ut(_,0,W);const R=ln(T.sizeTree,-k+1)[1];_=Ut(_,1,R)}return{...T,sizeTree:_,...Qi(T.offsetTree,0,_,I)}}else{const _=ur(T.sizeTree).reduce((O,{k:j,v:U})=>Ut(O,Math.max(0,j+k),U),jr());return{...T,sizeTree:_,...Qi(T.offsetTree,0,_,I)}}})),x),{beforeUnshiftWith:S,data:h,defaultItemSize:d,firstItemIndex:a,fixedItemSize:u,gap:p,groupIndices:l,itemSize:f,listRefresh:b,shiftWith:i,shiftWithOffset:E,sizeRanges:n,sizes:x,statefulTotalCount:o,totalCount:r,trackItemSizes:y,unshiftWith:s}},rt(Hn,Ji),{singleton:!0});function wy(e){return e.reduce((t,n)=>(t.groupIndices.push(t.totalCount),t.totalCount+=n+1,t),{groupIndices:[],totalCount:0})}const uu=We(([{groupIndices:e,sizes:t,totalCount:n},{headerHeight:r,scrollTop:o}])=>{const s=Ue(),i=Ue(),a=Ht(K(s,ce(wy)));return xe(K(a,ce(l=>l.totalCount)),n),xe(K(a,ce(l=>l.groupIndices)),e),xe(K(ht(o,t,r),Te(([l,u])=>os(u)),ce(([l,u,d])=>ln(u.groupOffsetTree,Math.max(l-d,0),"v")[0]),ot(),ce(l=>[l])),i),{groupCounts:s,topItemsIndexes:i}},rt(bn,Mt)),Wn=We(([{log:e}])=>{const t=Y(!1),n=Ht(K(t,Te(r=>r),ot()));return Ke(t,r=>{r&&dt(e)("props updated",{},$t.DEBUG)}),{didMount:n,propsReady:t}},rt(Hn),{singleton:!0}),Sy=typeof document<"u"&&"scrollBehavior"in document.documentElement.style;function du(e){const t=typeof e=="number"?{index:e}:e;return t.align||(t.align="start"),(!t.behavior||!Sy)&&(t.behavior="auto"),t.offset||(t.offset=0),t}const so=We(([{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=Ue(),v=Ue(),x=Y(0);let g=null,y=null,b=null;function S(){g&&(g(),g=null),b&&(b(),b=null),y&&(clearTimeout(y),y=null),Me(l,!1)}return xe(K(p,Fe(n,f,r,x,a,i,h),Fe(e,s,o),ce(([[E,k,T,I,_,O,j,U],L,W,R])=>{const V=du(E),{align:$,behavior:ne,offset:F}=V,B=I-1,le=lu(V,k,B);let z=oo(le,k.offsetTree,L)+O;$==="end"?(z+=W+ln(k.sizeTree,le)[1]-T+R,le===B&&(z+=j)):$==="center"?z+=(W+ln(k.sizeTree,le)[1]-T+R)/2:z-=_,F&&(z+=F);const oe=pe=>{S(),pe?(U("retrying to scroll to",{location:E},$t.DEBUG),Me(p,E)):(Me(v,!0),U("list did not change, scroll successful",{},$t.DEBUG))};if(S(),ne==="smooth"){let pe=!1;b=Ke(t,ge=>{pe=pe||ge}),g=an(d,()=>{oe(pe)})}else g=an(K(t,Cy(150)),oe);return y=setTimeout(()=>{S()},1200),Me(l,!0),U("scrolling from index to",{behavior:ne,index:le,top:z},$t.DEBUG),{behavior:ne,top:z}})),u),{scrollTargetReached:v,scrollToIndex:p,topListHeight:x}},rt(bn,Mt,Hn),{singleton:!0});function Cy(e){return t=>{const n=setTimeout(()=>{t(!1)},e);return r=>{r&&(t(!0),clearTimeout(n))}}}function ea(e,t){e==0?t():requestAnimationFrame(()=>{ea(e-1,t)})}function ta(e,t){const n=t-1;return typeof e=="number"?e:e.index==="LAST"?n:e.index}const io=We(([{defaultItemSize:e,listRefresh:t,sizes:n},{scrollTop:r},{scrollTargetReached:o,scrollToIndex:s},{didMount:i}])=>{const a=Y(!0),l=Y(0),u=Y(!0);return xe(K(i,Fe(l),Te(([d,f])=>!!f),yn(!1)),a),xe(K(i,Fe(l),Te(([d,f])=>!!f),yn(!1)),u),Ke(K(ht(t,i),Fe(a,n,e,u),Te(([[,d],f,{sizeTree:h},p,v])=>d&&(!et(h)||Ui(p))&&!f&&!v),Fe(l)),([,d])=>{an(o,()=>{Me(u,!0)}),ea(4,()=>{an(r,()=>{Me(a,!0)}),Me(s,d)})}),{initialItemFinalLocationReached:u,initialTopMostItemIndex:l,scrolledToInitialItem:a}},rt(bn,Mt,so,Wn),{singleton:!0});function fu(e,t){return Math.abs(e-t)<1.01}const ao="up",lo="down",ky="none",Ty={atBottom:!1,notAtBottomBecause:"NOT_SHOWING_LAST_ITEM",state:{offsetBottom:0,scrollHeight:0,scrollTop:0,viewportHeight:0}},Ey=0,co=We(([{footerHeight:e,headerHeight:t,scrollBy:n,scrollContainerState:r,scrollTop:o,viewportHeight:s}])=>{const i=Y(!1),a=Y(!0),l=Ue(),u=Ue(),d=Y(4),f=Y(Ey),h=_t(K(Vi(K(Ce(o),lr(1),yn(!0)),K(Ce(o),lr(1),yn(!1),Yc(100))),ot()),!1),p=_t(K(Vi(K(n,yn(!0)),K(n,yn(!1),Yc(200))),ot()),!1);xe(K(ht(Ce(o),Ce(f)),ce(([b,S])=>b<=S),ot()),a),xe(K(a,On(50)),u);const v=Ht(K(ht(r,Ce(s),Ce(t),Ce(e),Ce(d)),vn((b,[{scrollHeight:S,scrollTop:E},k,T,I,_])=>{const O=E+k-S>-_,j={scrollHeight:S,scrollTop:E,viewportHeight:k};if(O){let L,W;return E>b.state.scrollTop?(L="SCROLLED_DOWN",W=b.state.scrollTop-E):(L="SIZE_DECREASED",W=b.state.scrollTop-E||b.scrollTopDelta),{atBottom:!0,atBottomBecause:L,scrollTopDelta:W,state:j}}let U;return j.scrollHeight>b.state.scrollHeight?U="SIZE_INCREASED":k<b.state.viewportHeight?U="VIEWPORT_HEIGHT_DECREASING":E<b.state.scrollTop?U="SCROLLING_UPWARDS":U="NOT_FULLY_SCROLLED_TO_LAST_ITEM_BOTTOM",{atBottom:!1,notAtBottomBecause:U,state:j}},Ty),ot((b,S)=>b&&b.atBottom===S.atBottom))),x=_t(K(r,vn((b,{scrollHeight:S,scrollTop:E,viewportHeight:k})=>{if(fu(b.scrollHeight,S))return{changed:!1,jump:0,scrollHeight:S,scrollTop:E};{const T=S-(E+k)<1;return b.scrollTop!==E&&T?{changed:!0,jump:b.scrollTop-E,scrollHeight:S,scrollTop:E}:{changed:!0,jump:0,scrollHeight:S,scrollTop:E}}},{changed:!1,jump:0,scrollHeight:0,scrollTop:0}),Te(b=>b.changed),ce(b=>b.jump)),0);xe(K(v,ce(b=>b.atBottom)),i),xe(K(i,On(50)),l);const g=Y(lo);xe(K(r,ce(({scrollTop:b})=>b),ot(),vn((b,S)=>dt(p)?{direction:b.direction,prevScrollTop:S}:{direction:S<b.prevScrollTop?ao:lo,prevScrollTop:S},{direction:lo,prevScrollTop:0}),ce(b=>b.direction)),g),xe(K(r,On(50),yn(ky)),g);const y=Y(0);return xe(K(h,Te(b=>!b),yn(0)),y),xe(K(o,On(100),Fe(h),Te(([b,S])=>!!S),vn(([b,S],[E])=>[S,E],[0,0]),ce(([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}},rt(Mt)),ss="top",is="bottom",hu="none";function pu(e,t,n){return typeof e=="number"?n===ao&&t===ss||n===lo&&t===is?e:0:n===ao?t===ss?e.main:e.reverse:t===is?e.main:e.reverse}function mu(e,t){var n;return typeof e=="number"?e:(n=e[t])!=null?n:0}const na=We(([{deviation:e,fixedHeaderHeight:t,headerHeight:n,scrollTop:r,viewportHeight:o}])=>{const s=Ue(),i=Y(0),a=Y(0),l=Y(0),u=_t(K(ht(Ce(r),Ce(o),Ce(n),Ce(s,ro),Ce(l),Ce(i),Ce(t),Ce(e),Ce(a)),ce(([d,f,h,[p,v],x,g,y,b,S])=>{const E=d-b,k=g+y,T=Math.max(h-E,0);let I=hu;const _=mu(S,ss),O=mu(S,is);return p-=b,p+=h+y,v+=h+y,v-=b,p>d+k-_&&(I=ao),v<d-T+f+O&&(I=lo),I!==hu?[Math.max(E-h-pu(x,ss,I)-_,0),E-T-y+f+pu(x,is,I)+O]:null}),Te(d=>d!=null),ot(ro)),[0,0]);return{increaseViewportBy:a,listBoundary:s,overscan:l,topListHeight:i,visibleRange:u}},rt(Mt),{singleton:!0});function Iy(e,t,n){if(os(t)){const r=au(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 ra={bottom:0,firstItemIndex:0,items:[],offsetBottom:0,offsetTop:0,top:0,topItems:[],topListHeight:0,totalCount:0};function as(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:xu(e,o,s),offsetBottom:v,offsetTop:u,top:p,topItems:xu(t,o,s),topListHeight:t.reduce((x,g)=>g.size+x,0),totalCount:n}}function gu(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=ta(t,a),u=Array.from({length:a}).map((d,f)=>({data:s[f+l],index:f+l,offset:0,size:0}));return as(u,[],a,o,n,r)}function xu(e,t,n){if(e.length===0)return[];if(!os(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=ts(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 dr=We(([{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=Y([]),g=Y(0),y=Ue();xe(s.topItemsIndexes,x);const b=_t(K(ht(p,v,Ce(l,ro),Ce(o),Ce(r),Ce(u),d,Ce(x),Ce(t),Ce(n),e),Te(([T,I,,_,,,,,,,O])=>{const j=O&&O.length!==_;return T&&!I&&!j}),ce(([,,[T,I],_,O,j,U,L,W,R,V])=>{const $=O,{offsetTree:ne,sizeTree:F}=$,B=dt(g);if(_===0)return{...ra,totalCount:_};if(T===0&&I===0)return B===0?{...ra,totalCount:_}:gu(B,j,O,W,R,V||[]);if(et(F))return B>0?null:as(Iy(ta(j,_),$,V),[],_,R,$,W);const le=[];if(L.length>0){const me=L[0],ve=L[L.length-1];let Z=0;for(const D of ts(F,me,ve)){const J=D.value,Q=Math.max(D.start,me),de=Math.min(D.end,ve);for(let ee=Q;ee<=de;ee++)le.push({data:V==null?void 0:V[ee],index:ee,offset:Z,size:J}),Z+=J}}if(!U)return as([],le,_,R,$,W);const z=L.length>0?L[L.length-1]+1:0,oe=my(ne,T,I,z);if(oe.length===0)return null;const pe=_-1,ge=es([],me=>{for(const ve of oe){const Z=ve.value;let D=Z.offset,J=ve.start;const Q=Z.size;if(Z.offset<T){J+=Math.floor((T-Z.offset+R)/(Q+R));const ee=J-ve.start;D+=ee*Q+ee*R}J<z&&(D+=(z-J)*Q,J=z);const de=Math.min(ve.end,pe);for(let ee=J;ee<=de&&!(D>=I);ee++)me.push({data:V==null?void 0:V[ee],index:ee,offset:D,size:Q}),D+=Q+R}});return as(ge,le,_,R,$,W)}),Te(T=>T!==null),ot()),ra);xe(K(e,Te(Ui),ce(T=>T==null?void 0:T.length)),o),xe(K(b,ce(T=>T.topListHeight)),f),xe(f,a),xe(K(b,ce(T=>[T.top,T.bottom])),i),xe(K(b,ce(T=>T.items)),y);const S=Ht(K(b,Te(({items:T})=>T.length>0),Fe(o,e),Te(([{items:T},I])=>T[T.length-1].originalIndex===I-1),ce(([,T,I])=>[T-1,I]),ot(ro),ce(([T])=>T))),E=Ht(K(b,On(200),Te(({items:T,topItems:I})=>T.length>0&&T[0].originalIndex===I.length),ce(({items:T})=>T[0].index),ot())),k=Ht(K(b,Te(({items:T})=>T.length>0),ce(({items:T})=>{let I=0,_=T.length-1;for(;T[I].type==="group"&&I<_;)I++;for(;T[_].type==="group"&&_>I;)_--;return{endIndex:T[_].index,startIndex:T[I].index}}),ot(su)));return{endReached:S,initialItemCount:g,itemsRendered:y,listState:b,rangeChanged:k,startReached:E,topItemsIndexes:x,...h}},rt(bn,uu,na,io,so,co,Wn,Ji),{singleton:!0}),yu=We(([{fixedFooterHeight:e,fixedHeaderHeight:t,footerHeight:n,headerHeight:r},{listState:o}])=>{const s=Ue(),i=_t(K(ht(n,e,r,t,o),ce(([a,l,u,d,f])=>a+l+u+d+f.offsetBottom+f.bottom)),0);return xe(Ce(i),s),{totalListHeight:i,totalListHeightChanged:s}},rt(Mt,dr),{singleton:!0}),Ay=We(([{viewportHeight:e},{totalListHeight:t}])=>{const n=Y(!1),r=_t(K(ht(n,e,t),Te(([o])=>o),ce(([,o,s])=>Math.max(0,o-s)),On(0),ot()),0);return{alignToBottom:n,paddingTopAddition:r}},rt(Mt,yu),{singleton:!0}),vu=We(()=>({context:Y(null)})),Ny=({itemBottom:e,itemTop:t,locationParams:{align:n,behavior:r,...o},viewportBottom:s,viewportTop:i})=>t<i?{...o,align:n??"start",behavior:r}:e>s?{...o,align:n??"end",behavior:r}:null,bu=We(([{gap:e,sizes:t,totalCount:n},{fixedFooterHeight:r,fixedHeaderHeight:o,headerHeight:s,scrollingInProgress:i,scrollTop:a,viewportHeight:l},{scrollToIndex:u}])=>{const d=Ue();return xe(K(d,Fe(t,l,n,s,o,r,a),Fe(e),ce(([[f,h,p,v,x,g,y,b],S])=>{const{align:E,behavior:k,calculateViewLocation:T=Ny,done:I,..._}=f,O=lu(f,h,v-1),j=oo(O,h.offsetTree,S)+x+g,U=j+ln(h.sizeTree,O)[1],L=b+g,W=b+p-y,R=T({itemBottom:U,itemTop:j,locationParams:{align:E,behavior:k,..._},viewportBottom:W,viewportTop:L});return R?I&&an(K(i,Te(V=>!V),lr(dt(i)?1:2)),I):I&&I(),R}),Te(f=>f!==null)),u),{scrollIntoView:d}},rt(bn,Mt,so,dr,Hn),{singleton:!0});function wu(e){return e?e==="smooth"?"smooth":"auto":!1}const _y=(e,t)=>typeof e=="function"?wu(e(t)):t&&wu(e),jy=We(([{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=Y(!1),x=Ue();let g=null;function y(k){Me(i,{align:"end",behavior:k,index:"LAST"})}Ke(K(ht(K(Ce(t),lr(1)),l),Fe(Ce(v),s,a,f),ce(([[k,T],I,_,O,j])=>{let U=T&&O,L="auto";return U&&(L=_y(I,_||j),U=U&&!!L),{followOutputBehavior:L,shouldFollow:U,totalCount:k}}),Te(({shouldFollow:k})=>k)),({followOutputBehavior:k,totalCount:T})=>{g&&(g(),g=null),dt(n)?requestAnimationFrame(()=>{dt(d)("following output to ",{totalCount:T},$t.DEBUG),y(k)}):g=an(e,()=>{dt(d)("following output to ",{totalCount:T},$t.DEBUG),y(k),g=null})});function b(k){const T=an(o,I=>{k&&!I.atBottom&&I.notAtBottomBecause==="SIZE_INCREASED"&&!g&&(dt(d)("scrolling to bottom due to increased size",{},$t.DEBUG),y("auto"))});setTimeout(T,100)}Ke(K(ht(Ce(v),t,u),Te(([k,,T])=>k&&T),vn(({value:k},[,T])=>({refreshed:k===T,value:T}),{refreshed:!1,value:0}),Te(({refreshed:k})=>k),Fe(v,t)),([,k])=>{dt(a)&&b(k!==!1)}),Ke(x,()=>{b(dt(v)!==!1)}),Ke(ht(Ce(v),o),([k,T])=>{k&&!T.atBottom&&T.notAtBottomBecause==="VIEWPORT_HEIGHT_DECREASING"&&y("auto")});const S=Y(null),E=Ue();return xe(Vi(K(Ce(r),ce(k=>{var T;return(T=k==null?void 0:k.length)!=null?T:0})),K(Ce(t))),E),Ke(K(ht(K(E,lr(1)),l),Fe(Ce(S),a,f,h),ce(([[k,T],I,_,O,j])=>T&&_&&(I==null?void 0:I({context:j,totalCount:k,scrollingInProgress:O}))),Te(k=>!!k),On(0)),k=>{g&&(g(),g=null),dt(n)?requestAnimationFrame(()=>{dt(d)("scrolling into view",{}),Me(p,k)}):g=an(e,()=>{dt(d)("scrolling into view",{}),Me(p,k),g=null})}),{autoscrollToBottom:x,followOutput:v,scrollIntoViewOnChange:S}},rt(bn,co,so,io,Wn,Hn,Mt,vu,bu)),Ry=We(([{data:e,firstItemIndex:t,gap:n,sizes:r},{initialTopMostItemIndex:o},{initialItemCount:s,listState:i},{didMount:a}])=>(xe(K(a,Fe(s),Te(([,l])=>l!==0),Fe(o,r,t,n,e),ce(([[,l],u,d,f,h,p=[]])=>gu(l,u,d,f,h,p))),i),{}),rt(bn,io,dr,Wn),{singleton:!0}),Py=We(([{didMount:e},{scrollTo:t},{listState:n}])=>{const r=Y(0);return Ke(K(e,Fe(r),Te(([,o])=>o!==0),ce(([,o])=>({top:o}))),o=>{an(K(n,lr(1),Te(s=>s.items.length>1)),()=>{requestAnimationFrame(()=>{Me(t,o)})})}),{initialScrollTop:r}},rt(Wn,Mt,dr),{singleton:!0}),Su=We(([{scrollVelocity:e}])=>{const t=Y(!1),n=Ue(),r=Y(!1);return xe(K(e,Fe(r,t,n),Te(([o,s])=>!!s),ce(([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}),ot()),t),Ke(K(ht(t,e,n),Fe(r)),([[o,s,i],a])=>{o&&a&&a.change&&a.change(s,i)}),{isSeeking:t,scrollSeekConfiguration:r,scrollSeekRangeChanged:n,scrollVelocity:e}},rt(co),{singleton:!0}),oa=We(([{scrollContainerState:e,scrollTo:t}])=>{const n=Ue(),r=Ue(),o=Ue(),s=Y(!1),i=Y(void 0);return xe(K(ht(n,r),ce(([{scrollHeight:a,scrollTop:l,viewportHeight:u},{offsetTop:d}])=>({scrollHeight:a,scrollTop:Math.max(0,l-d),viewportHeight:u}))),e),xe(K(t,Fe(r),ce(([a,{offsetTop:l}])=>({...a,top:a.top+l}))),o),{customScrollParent:i,useWindowScroll:s,windowScrollContainerState:n,windowScrollTo:o,windowViewportRect:r}},rt(Mt)),Oy=We(([{sizeRanges:e,sizes:t},{headerHeight:n,scrollTop:r},{initialTopMostItemIndex:o},{didMount:s},{useWindowScroll:i,windowScrollContainerState:a,windowViewportRect:l}])=>{const u=Ue(),d=Y(void 0),f=Y(null),h=Y(null);return xe(a,f),xe(l,h),Ke(K(u,Fe(t,r,i,f,h,n)),([p,v,x,g,y,b,S])=>{const E=xy(v.sizeTree);g&&y!==null&&b!==null&&(x=y.scrollTop-b.offsetTop),x-=S,p({ranges:E,scrollTop:x})}),xe(K(d,Te(Ui),ce(My)),o),xe(K(s,Fe(d),Te(([,p])=>p!==void 0),ot(),ce(([,p])=>p.ranges)),e),{getState:u,restoreStateFrom:d}},rt(bn,Mt,io,Wn,oa));function My(e){return{align:"start",index:0,offset:e.scrollTop}}const Dy=We(([{topItemsIndexes:e}])=>{const t=Y(0);return xe(K(t,Te(n=>n>=0),ce(n=>Array.from({length:n}).map((r,o)=>o))),e),{topItemCount:t}},rt(dr));function Cu(e){let t=!1,n;return()=>(t||(t=!0,n=e()),n)}const Ly=Cu(()=>/iP(ad|od|hone)/i.test(navigator.userAgent)&&/WebKit/i.test(navigator.userAgent)),Fy=We(([{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(K(l,Fe(i),vn(([,y,b,S],[{bottom:E,items:k,offsetBottom:T,totalCount:I},_])=>{const O=E+T;let j=0;return b===I&&y.length>0&&k.length>0&&(k[0].originalIndex===0&&y[0].originalIndex===0||(j=O-S,j!==0&&(j+=_))),[j,k,I,O]},[0,[],0,0]),Te(([y])=>y!==0),Fe(r,a,n,o,p,v),Te(([,y,b,S,,,E])=>!E&&!S&&y!==0&&b===ao),ce(([[y],,,,,b])=>(b("Upward scrolling compensation",{amount:y},$t.DEBUG),y))));function g(y){y>0?(Me(t,{behavior:"auto",top:-y}),Me(e,0)):(Me(e,0),Me(t,{behavior:"auto",top:-y}))}return Ke(K(x,Fe(e,s)),([y,b,S])=>{S&&Ly()?Me(e,b-y):g(-y)}),Ke(K(ht(_t(s,!1),e,v),Te(([y,b,S])=>!y&&!S&&b!==0),ce(([y,b])=>b),On(1)),g),xe(K(f,ce(y=>({top:-y}))),t),Ke(K(u,Fe(h,d),ce(([y,{groupIndices:b,lastSize:S,sizeTree:E},k])=>{function T(I){return I*(S+k)}if(b.length===0)return T(y);{let I=0;const _=no(E,0);let O=0,j=0;for(;O<y;){O++,I+=_;let U=b.length===j+1?1/0:b[j+1]-b[j]-1;O+U>y&&(I-=_,U=y-O+1),O+=U,I+=T(U),j++}return I}})),y=>{Me(e,y),requestAnimationFrame(()=>{Me(t,{top:y}),requestAnimationFrame(()=>{Me(e,0),Me(v,!1)})})}),{deviation:e}},rt(Mt,co,dr,bn,Hn,Ji)),$y=We(([e,t,n,r,o,s,i,a,l,u,d])=>({...e,...t,...n,...r,...o,...s,...i,...a,...l,...u,...d}),rt(na,Ry,Wn,Su,yu,Py,Ay,oa,bu,Hn,vu)),ku=We(([{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,...E},{scrollToIndex:k},T,{topItemCount:I},{groupCounts:_},O])=>(xe(E.rangeChanged,O.scrollSeekRangeChanged),xe(K(O.windowViewportRect,ce(j=>j.visibleHeight)),x.viewportHeight),{data:e,defaultItemHeight:t,firstItemIndex:n,fixedItemHeight:r,gap:o,groupCounts:_,initialItemFinalLocationReached:h,initialTopMostItemIndex:p,scrolledToInitialItem:v,sizeRanges:a,topItemCount:I,topItemsIndexes:S,totalCount:d,...y,groupIndices:s,itemSize:i,listState:b,scrollToIndex:k,statefulTotalCount:u,trackItemSizes:f,...E,...O,...x,sizes:l,...g}),rt(bn,io,Mt,Oy,jy,dr,so,Fy,Dy,uu,$y));function zy(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 ls=typeof document<"u"?w.useLayoutEffect:w.useEffect;function Tu(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&&Me(g.propsReady,!1);for(const b of r){const S=g[t.required[b]];Me(S,y[b])}for(const b of o)if(b in y){const S=g[t.optional[b]];Me(S,y[b])}g.propsReady&&Me(g.propsReady,!0)}function u(g){return s.reduce((y,b)=>(y[b]=S=>{const E=g[t.methods[b]];Me(E,S)},y),{})}function d(g){return i.reduce((y,b)=>(y[b]=ny(g[t.events[b]]),y),{})}const f=w.forwardRef((g,y)=>{const{children:b,...S}=g,[E]=w.useState(()=>es(oy(e),I=>{l(I,S)})),[k]=w.useState(Gc(d,E));ls(()=>{for(const I of i)I in S&&Ke(k[I],S[I]);return()=>{Object.values(k).map(Wi)}},[S,k,E]),ls(()=>{l(E,S)}),w.useImperativeHandle(y,Kc(u(E)));const T=n;return c.jsx(a.Provider,{value:E,children:n?c.jsx(T,{...zy([...r,...o,...i],S),children:b}):b})}),h=g=>{const y=w.useContext(a);return w.useCallback(b=>{Me(y[g],b)},[y,g])},p=g=>{const y=w.useContext(a)[g],b=w.useCallback(S=>Ke(y,S),[y]);return w.useSyncExternalStore(b,()=>dt(y),()=>dt(y))},v=g=>{const y=w.useContext(a)[g],[b,S]=w.useState(Gc(dt,y));return ls(()=>Ke(y,E=>{E!==b&&S(Kc(E))}),[y,b]),b},x=w.version.startsWith("18")?p:v;return{Component:f,useEmitter:(g,y)=>{const b=w.useContext(a)[g];ls(()=>Ke(b,y),[y,b])},useEmitterValue:x,usePublisher:h}}const Eu=w.createContext(void 0),Iu=w.createContext(void 0),Au=typeof document<"u"?w.useLayoutEffect:w.useEffect;function sa(e){return"self"in e}function By(e){return"body"in e}function Nu(e,t,n,r=_r,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(By(g)||sa(g)){const b=sa(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():pi.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;sa(p)?(g=Math.max(Un(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=Un(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)),fu(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 ia="-webkit-sticky",_u="sticky",aa=Cu(()=>{if(typeof document>"u")return _u;const e=document.createElement("div");return e.style.position=ia,e.style.position===ia?ia:_u});function la(e){return e}const Hy=We(()=>{const e=Y(a=>`Item ${a}`),t=Y(a=>`Group ${a}`),n=Y({}),r=Y(la),o=Y("div"),s=Y(_r),i=(a,l=null)=>_t(K(n,ce(u=>u[a]),ot()),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")}}),Uy=We(([e,t])=>({...e,...t}),rt(ku,Hy)),Wy=({height:e})=>c.jsx("div",{style:{height:e}}),Vy={overflowAnchor:"none",position:aa(),zIndex:1},ju={overflowAnchor:"none"},Ky={...ju,display:"inline-block",height:"100%"},Ru=w.memo(function({showTopList:e=!1}){const t=_e("listState"),n=Jt("sizeRanges"),r=_e("useWindowScroll"),o=_e("customScrollParent"),s=Jt("windowScrollContainerState"),i=Jt("scrollContainerState"),a=o||r?s:i,l=_e("itemContent"),u=_e("context"),d=_e("groupContent"),f=_e("trackItemSizes"),h=_e("itemSize"),p=_e("log"),v=Jt("gap"),x=_e("horizontalDirection"),{callbackRef:g}=ay(n,h,f,e?_r:a,p,v,o,x,_e("skipAnimationFrameInResizeObserver")),[y,b]=w.useState(0);ca("deviation",R=>{y!==R&&b(R)});const S=_e("EmptyPlaceholder"),E=_e("ScrollSeekPlaceholder")||Wy,k=_e("ListComponent"),T=_e("ItemComponent"),I=_e("GroupComponent"),_=_e("computeItemKey"),O=_e("isSeeking"),j=_e("groupIndices").length>0,U=_e("alignToBottom"),L=_e("initialItemFinalLocationReached"),W=e?{}:{boxSizing:"border-box",...x?{display:"inline-block",height:"100%",marginLeft:y!==0?y:U?"auto":0,paddingLeft:t.offsetTop,paddingRight:t.offsetBottom,whiteSpace:"nowrap"}:{marginTop:y!==0?y:U?"auto":0,paddingBottom:t.offsetBottom,paddingTop:t.offsetTop},...L?{}:{visibility:"hidden"}};return!e&&t.totalCount===0&&S?c.jsx(S,{...jt(S,u)}):c.jsx(k,{...jt(k,u),"data-testid":e?"virtuoso-top-item-list":"virtuoso-item-list",ref:g,style:W,children:(e?t.topItems:t.items).map(R=>{const V=R.originalIndex,$=_(V+t.firstItemIndex,R.data,u);return O?w.createElement(E,{...jt(E,u),height:R.size,index:R.index,key:$,type:R.type||"item",...R.type==="group"?{}:{groupIndex:R.groupIndex}}):R.type==="group"?w.createElement(I,{...jt(I,u),"data-index":V,"data-item-index":R.index,"data-known-size":R.size,key:$,style:Vy},d(R.index,u)):w.createElement(T,{...jt(T,u),...Xy(T,R.data),"data-index":V,"data-item-group-index":R.groupIndex,"data-item-index":R.index,"data-known-size":R.size,key:$,style:x?Ky:ju},j?l(R.index,R.groupIndex,R.data,u):l(R.index,R.data,u))})})}),qy={height:"100%",outline:"none",overflowY:"auto",position:"relative",WebkitOverflowScrolling:"touch"},Gy={outline:"none",overflowX:"auto",position:"relative"},cs=e=>({height:"100%",position:"absolute",top:0,width:"100%",...e?{display:"flex",flexDirection:"column"}:{}}),Yy={position:aa(),top:0,width:"100%",zIndex:1};function jt(e,t){if(typeof e!="string")return{context:t}}function Xy(e,t){return{item:typeof e=="string"?void 0:t}}const Jy=w.memo(function(){const e=_e("HeaderComponent"),t=Jt("headerHeight"),n=_e("HeaderFooterTag"),r=cr(w.useMemo(()=>s=>{t(Un(s,"height"))},[t]),!0,_e("skipAnimationFrameInResizeObserver")),o=_e("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...jt(e,o)})}):null}),Zy=w.memo(function(){const e=_e("FooterComponent"),t=Jt("footerHeight"),n=_e("HeaderFooterTag"),r=cr(w.useMemo(()=>s=>{t(Un(s,"height"))},[t]),!0,_e("skipAnimationFrameInResizeObserver")),o=_e("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...jt(e,o)})}):null});function Pu({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}=Nu(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?Gy:qy,...o},tabIndex:0,...i,...jt(l,s),children:r})})}function Ou({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}=Nu(a,u,l,v,h);return Au(()=>{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,...jt(l,s),children:r})})}const Qy=({children:e})=>{const t=w.useContext(Eu),n=Jt("viewportHeight"),r=Jt("fixedItemHeight"),o=_e("alignToBottom"),s=_e("horizontalDirection"),i=w.useMemo(()=>qc(n,l=>Un(l,s?"width":"height")),[n,s]),a=cr(i,!0,_e("skipAnimationFrameInResizeObserver"));return w.useEffect(()=>{t&&(n(t.viewportHeight),r(t.itemHeight))},[t,n,r]),c.jsx("div",{"data-viewport-type":"element",ref:a,style:cs(o),children:e})},ev=({children:e})=>{const t=w.useContext(Eu),n=Jt("windowViewportRect"),r=Jt("fixedItemHeight"),o=_e("customScrollParent"),s=Zc(n,o,_e("skipAnimationFrameInResizeObserver")),i=_e("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:cs(i),children:e})},tv=({children:e})=>{const t=_e("TopItemListComponent")||"div",n=_e("headerHeight"),r={...Yy,marginTop:`${n}px`},o=_e("context");return c.jsx(t,{style:r,...jt(t,o),children:e})},nv=w.memo(function(e){const t=_e("useWindowScroll"),n=_e("topItemsIndexes").length>0,r=_e("customScrollParent"),o=_e("context");return c.jsxs(r||t?sv:ov,{...e,context:o,children:[n&&c.jsx(tv,{children:c.jsx(Ru,{showTopList:!0})}),c.jsxs(r||t?ev:Qy,{children:[c.jsx(Jy,{}),c.jsx(Ru,{}),c.jsx(Zy,{})]})]})}),{Component:rv,useEmitter:ca,useEmitterValue:_e,usePublisher:Jt}=Tu(Uy,{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"}},nv),ov=Pu({useEmitter:ca,useEmitterValue:_e,usePublisher:Jt}),sv=Ou({useEmitter:ca,useEmitterValue:_e,usePublisher:Jt}),iv=rv;rt(ku,We(()=>{const e=Y(u=>c.jsxs("td",{children:["Item $",u]})),t=Y(null),n=Y(u=>c.jsxs("td",{colSpan:1e3,children:["Group ",u]})),r=Y(null),o=Y(null),s=Y({}),i=Y(la),a=Y(_r),l=(u,d=null)=>_t(K(s,ce(f=>f[u]),ot()),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")}})),aa();const Mu={bottom:0,itemHeight:0,items:[],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},av={bottom:0,itemHeight:0,items:[{index:0}],itemWidth:0,offsetBottom:0,offsetTop:0,top:0},{ceil:Du,floor:us,max:uo,min:ua,round:Lu}=Math;function Fu(e,t,n){return Array.from({length:t-e+1}).map((r,o)=>({data:n===null?null:n[o+e],index:o+e}))}function lv(e){return{...av,items:e}}function ds(e,t){return e&&e.width===t.width&&e.height===t.height}function cv(e,t){return e&&e.column===t.column&&e.row===t.row}const uv=We(([{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:E},k])=>{const T=Y(0),I=Y(0),_=Y(Mu),O=Y({height:0,width:0}),j=Y({height:0,width:0}),U=Ue(),L=Ue(),W=Y(0),R=Y(null),V=Y({column:0,row:0}),$=Ue(),ne=Ue(),F=Y(!1),B=Y(0),le=Y(!0),z=Y(!1),oe=Y(!1);Ke(K(v,Fe(B),Te(([D,J])=>!!J)),()=>{Me(le,!1)}),Ke(K(ht(v,le,j,O,B,z),Te(([D,J,Q,de,,ee])=>D&&!J&&Q.height!==0&&de.height!==0&&!ee)),([,,,,D])=>{Me(z,!0),ea(1,()=>{Me(U,D)}),an(K(u),()=>{Me(t,[0,0]),Me(le,!0)})}),xe(K(ne,Te(D=>D!=null&&D.scrollTop>0),yn(0)),I),Ke(K(v,Fe(ne),Te(([,D])=>D!=null)),([,D])=>{D&&(Me(O,D.viewport),Me(j,D.item),Me(V,D.gap),D.scrollTop>0&&(Me(F,!0),an(K(u,lr(1)),J=>{Me(F,!1)}),Me(l,{top:D.scrollTop})))}),xe(K(O,ce(({height:D})=>D)),f),xe(K(ht(Ce(O,ds),Ce(j,ds),Ce(V,(D,J)=>D&&D.column===J.column&&D.row===J.row),Ce(u)),ce(([D,J,Q,de])=>({gap:Q,item:J,scrollTop:de,viewport:D}))),$),xe(K(ht(Ce(T),r,Ce(V,cv),Ce(j,ds),Ce(O,ds),Ce(R),Ce(I),Ce(F),Ce(le),Ce(B)),Te(([,,,,,,,D])=>!D),ce(([D,[J,Q],de,ee,se,Ge,Ye,,Pe,He])=>{const{column:nt,row:Qe}=de,{height:je,width:pt}=ee,{width:xt}=se;if(Ye===0&&(D===0||xt===0))return Mu;if(pt===0){const Ze=ta(He,D),kt=Ze+Math.max(Ye-1,0);return lv(Fu(Ze,kt,Ge))}const yt=$u(xt,pt,nt);let st,Xe;Pe?J===0&&Q===0&&Ye>0?(st=0,Xe=Ye-1):(st=yt*us((J+Qe)/(je+Qe)),Xe=yt*Du((Q+Qe)/(je+Qe))-1,Xe=ua(D-1,uo(Xe,yt-1)),st=ua(Xe,uo(0,st))):(st=0,Xe=-1);const G=Fu(st,Xe,Ge),{bottom:be,top:ye}=zu(se,de,ee,G),Ie=Du(D/yt),Je=Ie*je+(Ie-1)*Qe-be;return{bottom:be,itemHeight:je,items:G,itemWidth:pt,offsetBottom:Je,offsetTop:ye,top:ye}})),_),xe(K(R,Te(D=>D!==null),ce(D=>D.length)),T),xe(K(ht(O,j,_,V),Te(([D,J,{items:Q}])=>Q.length>0&&J.height!==0&&D.height!==0),ce(([D,J,{items:Q},de])=>{const{bottom:ee,top:se}=zu(D,de,J,Q);return[se,ee]}),ot(ro)),t);const pe=Y(!1);xe(K(u,Fe(pe),ce(([D,J])=>J||D!==0)),pe);const ge=Ht(K(ht(_,T),Te(([{items:D}])=>D.length>0),Fe(pe),Te(([[D,J],Q])=>{const de=D.items[D.items.length-1].index===J-1;return(Q||D.bottom>0&&D.itemHeight>0&&D.offsetBottom===0&&D.items.length===J)&&de}),ce(([[,D]])=>D-1),ot())),me=Ht(K(Ce(_),Te(({items:D})=>D.length>0&&D[0].index===0),yn(0),ot())),ve=Ht(K(Ce(_),Fe(F),Te(([{items:D},J])=>D.length>0&&!J),ce(([{items:D}])=>({endIndex:D[D.length-1].index,startIndex:D[0].index})),ot(su),On(0)));xe(ve,p.scrollSeekRangeChanged),xe(K(U,Fe(O,j,T,V),ce(([D,J,Q,de,ee])=>{const se=du(D),{align:Ge,behavior:Ye,offset:Pe}=se;let He=se.index;He==="LAST"&&(He=de-1),He=uo(0,He,ua(de-1,He));let nt=da(J,ee,Q,He);return Ge==="end"?nt=Lu(nt-J.height+Q.height):Ge==="center"&&(nt=Lu(nt-J.height/2+Q.height/2)),Pe&&(nt+=Pe),{behavior:Ye,top:nt}})),l);const Z=_t(K(_,ce(D=>D.offsetBottom+D.bottom)),0);return xe(K(E,ce(D=>({height:D.visibleHeight,width:D.visibleWidth}))),O),{customScrollParent:g,data:R,deviation:W,footerHeight:o,gap:V,headerHeight:s,increaseViewportBy:e,initialItemCount:I,itemDimensions:j,overscan:n,restoreStateFrom:ne,scrollBy:i,scrollContainerState:a,scrollHeight:L,scrollTo:l,scrollToIndex:U,scrollTop:u,smoothScrollTargetReached:d,totalCount:T,useWindowScroll:y,viewportDimensions:O,windowScrollContainerState:b,windowScrollTo:S,windowViewportRect:E,...p,gridState:_,horizontalDirection:oe,initialTopMostItemIndex:B,totalListHeight:Z,...h,endReached:ge,propsReady:x,rangeChanged:ve,startReached:me,stateChanged:$,stateRestoreInProgress:F,...k}},rt(na,Mt,co,Su,Wn,oa,Hn));function $u(e,t,n){return uo(1,us((e+n)/(us(t)+n)))}function zu(e,t,n,r){const{height:o}=n;if(o===void 0||r.length===0)return{bottom:0,top:0};const s=da(e,t,n,r[0].index);return{bottom:da(e,t,n,r[r.length-1].index)+o,top:s}}function da(e,t,n,r){const o=$u(e.width,n.width,t.column),s=us(r/o),i=s*n.height+uo(0,s-1)*t.row;return i>0?i+t.row:i}const dv=We(()=>{const e=Y(f=>`Item ${f}`),t=Y({}),n=Y(null),r=Y("virtuoso-grid-item"),o=Y("virtuoso-grid-list"),s=Y(la),i=Y("div"),a=Y(_r),l=(f,h=null)=>_t(K(t,ce(p=>p[f]),ot()),h),u=Y(!1),d=Y(!1);return xe(Ce(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")}}),fv=We(([e,t])=>({...e,...t}),rt(uv,dv)),hv=w.memo(function(){const e=it("gridState"),t=it("listClassName"),n=it("itemClassName"),r=it("itemContent"),o=it("computeItemKey"),s=it("isSeeking"),i=Zt("scrollHeight"),a=it("ItemComponent"),l=it("ListComponent"),u=it("ScrollSeekPlaceholder"),d=it("context"),f=Zt("itemDimensions"),h=Zt("gap"),p=it("log"),v=it("stateRestoreInProgress"),x=Zt("reportReadyState"),g=cr(w.useMemo(()=>y=>{const b=y.parentElement.parentElement.scrollHeight;i(b);const S=y.firstChild;if(S){const{height:E,width:k}=S.getBoundingClientRect();f({height:E,width:k})}h({column:Hu("column-gap",getComputedStyle(y).columnGap,p),row:Hu("row-gap",getComputedStyle(y).rowGap,p)})},[i,f,h,p]),!0,!1);return Au(()=>{e.itemHeight>0&&e.itemWidth>0&&x(!0)},[e]),v?null:c.jsx(l,{className:t,ref:g,...jt(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,{...jt(u,d),height:e.itemHeight,index:y.index,width:e.itemWidth},b):w.createElement(a,{...jt(a,d),className:n,"data-index":y.index,key:b},r(y.index,y.data,d))})})}),pv=w.memo(function(){const e=it("HeaderComponent"),t=Zt("headerHeight"),n=it("headerFooterTag"),r=cr(w.useMemo(()=>s=>{t(Un(s,"height"))},[t]),!0,!1),o=it("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...jt(e,o)})}):null}),mv=w.memo(function(){const e=it("FooterComponent"),t=Zt("footerHeight"),n=it("headerFooterTag"),r=cr(w.useMemo(()=>s=>{t(Un(s,"height"))},[t]),!0,!1),o=it("context");return e?c.jsx(n,{ref:r,children:c.jsx(e,{...jt(e,o)})}):null}),gv=({children:e})=>{const t=w.useContext(Iu),n=Zt("itemDimensions"),r=Zt("viewportDimensions"),o=cr(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:cs(!1),children:e})},xv=({children:e})=>{const t=w.useContext(Iu),n=Zt("windowViewportRect"),r=Zt("itemDimensions"),o=it("customScrollParent"),s=Zc(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:cs(!1),children:e})},yv=w.memo(function({...e}){const t=it("useWindowScroll"),n=it("customScrollParent"),r=n||t?bv:vv,o=n||t?xv:gv,s=it("context");return c.jsx(r,{...e,...jt(r,s),children:c.jsxs(o,{children:[c.jsx(pv,{}),c.jsx(hv,{}),c.jsx(mv,{})]})})}),{useEmitter:Bu,useEmitterValue:it,usePublisher:Zt}=Tu(fv,{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"}},yv),vv=Pu({useEmitter:Bu,useEmitterValue:it,usePublisher:Zt}),bv=Ou({useEmitter:Bu,useEmitterValue:it,usePublisher:Zt});function Hu(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 wv=Po.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 Uu({className:e,variant:t,...n}){return c.jsx("div",{className:re(wv({variant:t}),e),...n})}function fe(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 Sv(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,Cv(o,...t)]}function Cv(...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 gt=globalThis!=null&&globalThis.document?m.useLayoutEffect:()=>{},kv=m[" useInsertionEffect ".trim().toString()]||gt;function fr({prop:e,defaultProp:t,onChange:n=()=>{},caller:r}){const[o,s,i]=Tv({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=Ev(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 Tv({defaultProp:e,onChange:t}){const[n,r]=m.useState(e),o=m.useRef(n),s=m.useRef(t);return kv(()=>{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 Ev(e){return typeof e=="function"}function Wu(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function fa(...e){return t=>{let n=!1;const r=e.map(o=>{const s=Wu(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():Wu(e[o],null)}}}}function Be(...e){return m.useCallback(fa(...e),e)}var Iv=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ee=Iv.reduce((e,t)=>{const n=rr.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 Vu(e,t){e&&Oo.flushSync(()=>e.dispatchEvent(t))}function Av(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var Wt=e=>{const{present:t,children:n}=e,r=Nv(t),o=typeof n=="function"?n({present:r.isPresent}):m.Children.only(n),s=Be(r.ref,_v(o));return typeof n=="function"||r.isPresent?m.cloneElement(o,{ref:s}):null};Wt.displayName="Presence";function Nv(e){const[t,n]=m.useState(),r=m.useRef(null),o=m.useRef(e),s=m.useRef("none"),i=e?"mounted":"unmounted",[a,l]=Av(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return m.useEffect(()=>{const u=fs(r.current);s.current=a==="mounted"?u:"none"},[a]),gt(()=>{const u=r.current,d=o.current;if(d!==e){const h=s.current,p=fs(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]),gt(()=>{if(t){let u;const d=t.ownerDocument.defaultView??window,f=p=>{const x=fs(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=fs(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 fs(e){return(e==null?void 0:e.animationName)||"none"}function _v(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 jv=m[" useId ".trim().toString()]||(()=>{}),Rv=0;function Sn(e){const[t,n]=m.useState(jv());return gt(()=>{n(r=>r??String(Rv++))},[e]),e||(t?`radix-${t}`:"")}var hs="Collapsible",[Pv,ST]=wn(hs),[Ov,ha]=Pv(hs),Ku=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,open:r,defaultOpen:o,disabled:s,onOpenChange:i,...a}=e,[l,u]=fr({prop:r,defaultProp:o??!1,onChange:i,caller:hs});return c.jsx(Ov,{scope:n,disabled:s,contentId:Sn(),open:l,onOpenToggle:m.useCallback(()=>u(d=>!d),[u]),children:c.jsx(Ee.div,{"data-state":ma(l),"data-disabled":s?"":void 0,...a,ref:t})})});Ku.displayName=hs;var qu="CollapsibleTrigger",Gu=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,...r}=e,o=ha(qu,n);return c.jsx(Ee.button,{type:"button","aria-controls":o.contentId,"aria-expanded":o.open||!1,"data-state":ma(o.open),"data-disabled":o.disabled?"":void 0,disabled:o.disabled,...r,ref:t,onClick:fe(e.onClick,o.onOpenToggle)})});Gu.displayName=qu;var pa="CollapsibleContent",Mv=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=ha(pa,e.__scopeCollapsible);return c.jsx(Wt,{present:n||o.open,children:({present:s})=>c.jsx(Dv,{...r,ref:t,present:s})})});Mv.displayName=pa;var Dv=m.forwardRef((e,t)=>{const{__scopeCollapsible:n,present:r,children:o,...s}=e,i=ha(pa,n),[a,l]=m.useState(r),u=m.useRef(null),d=Be(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)},[]),gt(()=>{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(Ee.div,{"data-state":ma(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 ma(e){return e?"open":"closed"}var Lv=Ku;const Fv=Lv,$v=Gu,fo=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:re("rounded-lg border bg-card text-card-foreground shadow-sm",e),...t}));fo.displayName="Card";const ho=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:re("flex flex-col space-y-1.5 p-6",e),...t}));ho.displayName="CardHeader";const po=m.forwardRef(({className:e,...t},n)=>c.jsx("h3",{ref:n,className:re("text-2xl font-semibold leading-none tracking-tight",e),...t}));po.displayName="CardTitle";const Yu=m.forwardRef(({className:e,...t},n)=>c.jsx("p",{ref:n,className:re("text-sm text-muted-foreground",e),...t}));Yu.displayName="CardDescription";const mo=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:re("p-6 pt-0",e),...t}));mo.displayName="CardContent";const Xu=m.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:re("flex items-center p-6 pt-0",e),...t}));Xu.displayName="CardFooter";function Ju(){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 hr=Ju();function zv(e){hr=e}const Zu=/[&<>"']/,Bv=new RegExp(Zu.source,"g"),Qu=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,Hv=new RegExp(Qu.source,"g"),Uv={"&":"&","<":"<",">":">",'"':""","'":"'"},ed=e=>Uv[e];function Rt(e,t){if(t){if(Zu.test(e))return e.replace(Bv,ed)}else if(Qu.test(e))return e.replace(Hv,ed);return e}const Wv=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function td(e){return e.replace(Wv,(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 Vv=/(^|[^\[])\^/g;function tt(e,t){e=typeof e=="string"?e:e.source,t=t||"";const n={replace:(r,o)=>(o=o.source||o,o=o.replace(Vv,"$1"),e=e.replace(r,o),n),getRegex:()=>new RegExp(e,t)};return n}const Kv=/[^\w:]/g,qv=/^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;function nd(e,t,n){if(e){let r;try{r=decodeURIComponent(td(n)).replace(Kv,"").toLowerCase()}catch{return null}if(r.indexOf("javascript:")===0||r.indexOf("vbscript:")===0||r.indexOf("data:")===0)return null}t&&!qv.test(n)&&(n=Jv(t,n));try{n=encodeURI(n).replace(/%25/g,"%")}catch{return null}return n}const ps={},Gv=/^[^:]+:\/*[^/]*$/,Yv=/^([^:]+:)[\s\S]*$/,Xv=/^([^:]+:\/*[^/]*)[\s\S]*$/;function Jv(e,t){ps[" "+e]||(Gv.test(e)?ps[" "+e]=e+"/":ps[" "+e]=gs(e,"/",!0)),e=ps[" "+e];const n=e.indexOf(":")===-1;return t.substring(0,2)==="//"?n?t:e.replace(Yv,"$1")+t:t.charAt(0)==="/"?n?t:e.replace(Xv,"$1")+t:e+t}const ms={exec:function(){}};function rd(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 gs(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 Zv(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 Qv(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 od(e,t){if(t<1)return"";let n="";for(;t>1;)t&1&&(n+=e),t>>=1,e+=e;return n+e}function sd(e,t,n,r){const o=t.href,s=t.title?Rt(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:Rt(i)}}function eb(e,t){const n=e.match(/^(\s+)(?:```)/);if(n===null)return t;const r=n[1];return t.split(`
|
|
39
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(`
|
|
40
|
-
`)}class ga{constructor(t){this.options=t||
|
|
41
|
-
`)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=eb(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 ga{constructor(t){this.options=t||hr}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:gs(r,`
|
|
41
|
+
`)}}}fences(t){const n=this.rules.block.fences.exec(t);if(n){const r=n[0],o=eb(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=gs(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(`
|
|
42
42
|
`,1)[0].replace(/^\t+/,E=>" ".repeat(3*E.length)),f=t.split(`
|
|
43
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+`
|
|
44
44
|
`,t=t.substring(f.length+1),v=!0),!v){const E=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),k=new RegExp(`^ {0,${Math.min(3,i-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),T=new RegExp(`^ {0,${Math.min(3,i-1)}}(?:\`\`\`|~~~)`),I=new RegExp(`^ {0,${Math.min(3,i-1)}}#`);for(;t&&(h=t.split(`
|
|
45
45
|
`,1)[0],f=h,this.options.pedantic&&(f=f.replace(/^ {1,4}(?=( {4})*[^ ])/g," ")),!(T.test(f)||I.test(f)||E.test(f)||k.test(t)));){if(f.search(/[^ ]/)>=i||!f.trim())p+=`
|
|
46
46
|
`+f.slice(i);else{if(l||d.search(/[^ ]/)>=4||T.test(d)||I.test(d)||k.test(d))break;p+=`
|
|
47
47
|
`+f}!l&&!f.trim()&&(l=!0),r+=h+`
|
|
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
|
|
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 E=y.items[a].tokens.filter(T=>T.type==="space"),k=E.length>0&&E.some(T=>/\n.*\n/.test(T.raw));y.loose=k}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]):Rt(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:rd(n[1]).map(o=>({text:o})),align:n[2].replace(/^ *|\| *$/g,"").split(/ *\| */),rows:n[3]&&n[3].trim()?n[3].replace(/\n[ \t]*$/,"").split(`
|
|
49
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]=rd(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)===`
|
|
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:
|
|
51
|
-
]`).replace("lheading",we.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const
|
|
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:Rt(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]):Rt(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=gs(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=Zv(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)),sd(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 sd(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=Rt(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=Rt(this.options.mangle?n(r[1]):r[1]),s="mailto:"+o):(o=Rt(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=Rt(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=Rt(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]):Rt(r[0]):r[0]:o=Rt(this.options.smartypants?n(r[0]):r[0]),{type:"text",raw:r[0],text:o}}}}const we={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:ms,lheading:/^((?:.|\n(?!\n))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,_paragraph:/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,text:/^[^\n]+/};we._label=/(?!\s*\])(?:\\.|[^\[\]\\])+/,we._title=/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/,we.def=tt(we.def).replace("label",we._label).replace("title",we._title).getRegex(),we.bullet=/(?:[*+-]|\d{1,9}[.)])/,we.listItemStart=tt(/^( *)(bull) */).replace("bull",we.bullet).getRegex(),we.list=tt(we.list).replace(/bull/g,we.bullet).replace("hr","\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def","\\n+(?="+we.def.source+")").getRegex(),we._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",we._comment=/<!--(?!-?>)[\s\S]*?(?:-->|$)/,we.html=tt(we.html,"i").replace("comment",we._comment).replace("tag",we._tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),we.paragraph=tt(we._paragraph).replace("hr",we.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",we._tag).getRegex(),we.blockquote=tt(we.blockquote).replace("paragraph",we.paragraph).getRegex(),we.normal={...we},we.gfm={...we.normal,table:"^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"},we.gfm.table=tt(we.gfm.table).replace("hr",we.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",we._tag).getRegex(),we.gfm.paragraph=tt(we._paragraph).replace("hr",we.hr).replace("heading"," {0,3}#{1,6} ").replace("|lheading","").replace("table",we.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",we._tag).getRegex(),we.pedantic={...we.normal,html:tt(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",we._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:ms,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:tt(we.normal._paragraph).replace("hr",we.hr).replace("heading",` *#{1,6} *[^
|
|
51
|
+
]`).replace("lheading",we.lheading).replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").getRegex()};const ue={escape:/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,autolink:/^<(scheme:[^\s\x00-\x1f<>]*|email)>/,url:ms,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:ms,text:/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,punctuation:/^([\spunctuation])/};ue._punctuation="!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~",ue.punctuation=tt(ue.punctuation).replace(/punctuation/g,ue._punctuation).getRegex(),ue.blockSkip=/\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g,ue.escapedEmSt=/(?:^|[^\\])(?:\\\\)*\\[*_]/g,ue._comment=tt(we._comment).replace("(?:-->|$)","-->").getRegex(),ue.emStrong.lDelim=tt(ue.emStrong.lDelim).replace(/punct/g,ue._punctuation).getRegex(),ue.emStrong.rDelimAst=tt(ue.emStrong.rDelimAst,"g").replace(/punct/g,ue._punctuation).getRegex(),ue.emStrong.rDelimUnd=tt(ue.emStrong.rDelimUnd,"g").replace(/punct/g,ue._punctuation).getRegex(),ue._escapes=/\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g,ue._scheme=/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/,ue._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])?)+(?![-_])/,ue.autolink=tt(ue.autolink).replace("scheme",ue._scheme).replace("email",ue._email).getRegex(),ue._attribute=/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/,ue.tag=tt(ue.tag).replace("comment",ue._comment).replace("attribute",ue._attribute).getRegex(),ue._label=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,ue._href=/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/,ue._title=/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/,ue.link=tt(ue.link).replace("label",ue._label).replace("href",ue._href).replace("title",ue._title).getRegex(),ue.reflink=tt(ue.reflink).replace("label",ue._label).replace("ref",we._label).getRegex(),ue.nolink=tt(ue.nolink).replace("ref",we._label).getRegex(),ue.reflinkSearch=tt(ue.reflinkSearch,"g").replace("reflink",ue.reflink).replace("nolink",ue.nolink).getRegex(),ue.normal={...ue},ue.pedantic={...ue.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:tt(/^!?\[(label)\]\((.*?)\)/).replace("label",ue._label).getRegex(),reflink:tt(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",ue._label).getRegex()},ue.gfm={...ue.normal,escape:tt(ue.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.!#$%&'*+\/=?_`{\|}~-]+@)))/},ue.gfm.url=tt(ue.gfm.url,"i").replace("email",ue.gfm._extended_email).getRegex(),ue.breaks={...ue.gfm,br:tt(ue.br).replace("{2,}","*").getRegex(),text:tt(ue.gfm.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()};function tb(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 id(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 Vn{constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||hr,this.options.tokenizer=this.options.tokenizer||new ga,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:we.normal,inline:ue.normal};this.options.pedantic?(n.block=we.pedantic,n.inline=ue.pedantic):this.options.gfm&&(n.block=we.gfm,this.options.breaks?n.inline=ue.breaks:n.inline=ue.gfm),this.tokenizer.rules=n}static get rules(){return{block:we,inline:ue}}static lex(t,n){return new Vn(n).lex(t)}static lexInline(t,n){return new Vn(n).inlineTokens(t)}lex(t){t=t.replace(/\r\n|\r/g,`
|
|
52
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+=`
|
|
53
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+=`
|
|
54
54
|
`+r.raw,o.text+=`
|
|
@@ -58,9 +58,9 @@ React keys must be passed directly to JSX without using spread:
|
|
|
58
58
|
`+r.raw,o.text+=`
|
|
59
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+=`
|
|
60
60
|
`+r.raw,o.text+=`
|
|
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)+"["+od("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)+"["+od("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,id)){t=t.substring(r.raw.length),n.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(t,id))){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,tb)){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 xa{constructor(t){this.options=t||
|
|
62
|
-
`,o?'<pre><code class="'+this.options.langPrefix+
|
|
63
|
-
`:"<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)+"["+od("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)+"["+od("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,id)){t=t.substring(r.raw.length),n.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(t,id))){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,tb)){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 xa{constructor(t){this.options=t||hr}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+Rt(o)+'">'+(r?t:Rt(t,!0))+`</code></pre>
|
|
63
|
+
`:"<pre><code>"+(r?t:Rt(t,!0))+`</code></pre>
|
|
64
64
|
`}blockquote(t){return`<blockquote>
|
|
65
65
|
${t}</blockquote>
|
|
66
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}>
|
|
@@ -78,9 +78,9 @@ ${t}</blockquote>
|
|
|
78
78
|
`}tablerow(t){return`<tr>
|
|
79
79
|
${t}</tr>
|
|
80
80
|
`}tablecell(t,n){const r=n.header?"th":"td";return(n.align?`<${r} align="${n.align}">`:`<${r}>`)+t+`</${r}>
|
|
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=nd(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=nd(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 ad{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 ld{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
|
|
82
|
-
`+(p.tokens?this.parseInline(p.tokens):p.text);r+=n?this.renderer.paragraph(h):h;continue}default:{const _='Token with "'+p.type+'" type was not found.';if(this.options.silent){console.error(_);return}else throw new Error(_)}}}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
|
|
83
|
-
Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An error occurred:</p><pre>"+Ft(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 cd(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...Se.defaults,...s};const i=nb(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(Qv(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&&Se.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;Se.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(Se.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&&Se.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function Se(e,t,n){return cd(qn.lex,Gn.parse)(e,t,n)}Se.options=Se.setOptions=function(e){return Se.defaults={...Se.defaults,...e},zv(Se.defaults),Se},Se.getDefaults=Ju,Se.defaults=pr,Se.use=function(...e){const t=Se.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=Se.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=Se.defaults.renderer||new xa;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=Se.defaults.tokenizer||new ga;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=Se.defaults.hooks||new gs;for(const s in n.hooks){const i=o[s];gs.passThroughHooks.has(s)?o[s]=a=>{if(Se.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=Se.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}}Se.setOptions(r)})},Se.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(Se,r)),r.type){case"table":{for(const o of r.header)n=n.concat(Se.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(Se.walkTokens(s.tokens,t));break}case"list":{n=n.concat(Se.walkTokens(r.items,t));break}default:Se.defaults.extensions&&Se.defaults.extensions.childTokens&&Se.defaults.extensions.childTokens[r.type]?Se.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(Se.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(Se.walkTokens(r.tokens,t)))}return n},Se.parseInline=cd(qn.lexInline,Gn.parseInline),Se.Parser=Gn,Se.parser=Gn.parse,Se.Renderer=xa,Se.TextRenderer=ad,Se.Lexer=qn,Se.lexer=qn.lex,Se.Tokenizer=ga,Se.Slugger=ld,Se.Hooks=gs,Se.parse=Se,Se.options,Se.setOptions,Se.use,Se.walkTokens,Se.parseInline,Gn.parse,qn.lex;function ya({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 Se.parse(i)}return Se.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:re("markdown prose max-w-none break-words dark:prose-invert",t),style:s,dangerouslySetInnerHTML:{__html:o}})}async function ud(e,t){return await cn(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function dd(e,t){return await(await ud(`/files/${e}/view`,t)).text()}async function rb(e,t){const n=await ud(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await cn(`/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 ob(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await cn("/files",{params:r})}const sb=1,ib=1e6;let va=0;function ab(){return va=(va+1)%Number.MAX_SAFE_INTEGER,va.toString()}const ba=new Map,fd=e=>{if(ba.has(e))return;const t=setTimeout(()=>{ba.delete(e),mo({type:"REMOVE_TOAST",toastId:e})},ib);ba.set(e,t)},lb=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,sb)};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?fd(n):e.toasts.forEach(r=>{fd(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)}}},xs=[];let ys={toasts:[]};function mo(e){ys=lb(ys,e),xs.forEach(t=>{t(ys)})}function cb({...e}){const t=ab(),n=o=>mo({type:"UPDATE_TOAST",toast:{...o,id:t}}),r=()=>mo({type:"DISMISS_TOAST",toastId:t});return mo({type:"ADD_TOAST",toast:{...e,id:t,open:!0,onOpenChange:o=>{o||r()}}}),{id:t,dismiss:r,update:n}}function wa(){const[e,t]=m.useState(ys);return m.useEffect(()=>(xs.push(t),()=>{const n=xs.indexOf(t);n>-1&&xs.splice(n,1)}),[e]),{...e,toast:cb,dismiss:n=>mo({type:"DISMISS_TOAST",toastId:n})}}function _t(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 ub(e,t=globalThis==null?void 0:globalThis.document){const n=_t(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 db="DismissableLayer",Sa="dismissableLayer.update",fb="dismissableLayer.pointerDownOutside",hb="dismissableLayer.focusOutside",hd,pd=m.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),vs=m.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,u=m.useContext(pd),[d,f]=m.useState(null),h=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=m.useState({}),v=We(t,I=>f(I)),x=Array.from(u.layers),[g]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),y=x.indexOf(g),b=d?x.indexOf(d):-1,C=u.layersWithOutsidePointerEventsDisabled.size>0,E=b>=y,k=gb(I=>{const _=I.target,P=[...u.branches].some(j=>j.contains(_));!E||P||(o==null||o(I),i==null||i(I),I.defaultPrevented||a==null||a())},h),T=xb(I=>{const _=I.target;[...u.branches].some(j=>j.contains(_))||(s==null||s(I),i==null||i(I),I.defaultPrevented||a==null||a())},h);return ub(I=>{b===u.layers.size-1&&(r==null||r(I),!I.defaultPrevented&&a&&(I.preventDefault(),a()))},h),m.useEffect(()=>{if(d)return n&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(hd=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(d)),u.layers.add(d),md(),()=>{n&&u.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=hd)}},[d,h,n,u]),m.useEffect(()=>()=>{d&&(u.layers.delete(d),u.layersWithOutsidePointerEventsDisabled.delete(d),md())},[d,u]),m.useEffect(()=>{const I=()=>p({});return document.addEventListener(Sa,I),()=>document.removeEventListener(Sa,I)},[]),c.jsx(Ee.div,{...l,ref:v,style:{pointerEvents:C?E?"auto":"none":void 0,...e.style},onFocusCapture:he(e.onFocusCapture,T.onFocusCapture),onBlurCapture:he(e.onBlurCapture,T.onBlurCapture),onPointerDownCapture:he(e.onPointerDownCapture,k.onPointerDownCapture)})});vs.displayName=db;var pb="DismissableLayerBranch",mb=m.forwardRef((e,t)=>{const n=m.useContext(pd),r=m.useRef(null),o=We(t,r);return m.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),c.jsx(Ee.div,{...e,ref:o})});mb.displayName=pb;function gb(e,t=globalThis==null?void 0:globalThis.document){const n=_t(e),r=m.useRef(!1),o=m.useRef(()=>{});return m.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){gd(fb,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 xb(e,t=globalThis==null?void 0:globalThis.document){const n=_t(e),r=m.useRef(!1);return m.useEffect(()=>{const o=s=>{s.target&&!r.current&&gd(hb,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 md(){const e=new CustomEvent(Sa);document.dispatchEvent(e)}function gd(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?Vu(o,s):o.dispatchEvent(s)}var Ca="focusScope.autoFocusOnMount",ka="focusScope.autoFocusOnUnmount",xd={bubbles:!1,cancelable:!0},yb="FocusScope",bs=m.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=m.useState(null),u=_t(o),d=_t(s),f=m.useRef(null),h=We(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(C){if(p.paused||!a)return;const E=C.target;a.contains(E)?f.current=E:Yn(f.current,{select:!0})},g=function(C){if(p.paused||!a)return;const E=C.relatedTarget;E!==null&&(a.contains(E)||Yn(f.current,{select:!0}))},y=function(C){if(document.activeElement===document.body)for(const k of C)k.removedNodes.length>0&&Yn(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){bd.add(p);const x=document.activeElement;if(!a.contains(x)){const y=new CustomEvent(Ca,xd);a.addEventListener(Ca,u),a.dispatchEvent(y),y.defaultPrevented||(vb(kb(yd(a)),{select:!0}),document.activeElement===x&&Yn(a))}return()=>{a.removeEventListener(Ca,u),setTimeout(()=>{const y=new CustomEvent(ka,xd);a.addEventListener(ka,d),a.dispatchEvent(y),y.defaultPrevented||Yn(x??document.body,{select:!0}),a.removeEventListener(ka,d),bd.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,[C,E]=bb(b);C&&E?!x.shiftKey&&y===E?(x.preventDefault(),n&&Yn(C,{select:!0})):x.shiftKey&&y===C&&(x.preventDefault(),n&&Yn(E,{select:!0})):y===b&&x.preventDefault()}},[n,r,p.paused]);return c.jsx(Ee.div,{tabIndex:-1,...i,ref:h,onKeyDown:v})});bs.displayName=yb;function vb(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(Yn(r,{select:t}),document.activeElement!==n)return}function bb(e){const t=yd(e),n=vd(t,e),r=vd(t.reverse(),e);return[n,r]}function yd(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function vd(e,t){for(const n of e)if(!wb(n,{upTo:t}))return n}function wb(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 Sb(e){return e instanceof HTMLInputElement&&"select"in e}function Yn(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Sb(e)&&t&&e.select()}}var bd=Cb();function Cb(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=wd(e,t),e.unshift(t)},remove(t){var n;e=wd(e,t),(n=e[0])==null||n.resume()}}}function wd(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function kb(e){return e.filter(t=>t.tagName!=="A")}var Tb="Portal",ws=m.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=m.useState(!1);St(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?pi.createPortal(c.jsx(Ee.div,{...r,ref:t}),i):null});ws.displayName=Tb;var Ta=0;function Ea(){m.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??Sd()),document.body.insertAdjacentElement("beforeend",e[1]??Sd()),Ta++,()=>{Ta===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),Ta--}},[])}function Sd(){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 Tn=function(){return Tn=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},Tn.apply(this,arguments)};function Cd(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 Eb(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 Ss="right-scroll-bar-position",Cs="width-before-scroll-bar",Ib="with-scroll-bars-hidden",Ab="--removed-body-scroll-bar-size";function Ia(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function Nb(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 _b=typeof window<"u"?m.useLayoutEffect:m.useEffect,kd=new WeakMap;function jb(e,t){var n=Nb(null,function(r){return e.forEach(function(o){return Ia(o,r)})});return _b(function(){var r=kd.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Ia(a,null)}),s.forEach(function(a){o.has(a)||Ia(a,i)})}kd.set(n,e)},[e]),n}function Rb(e){return e}function Pb(e,t){t===void 0&&(t=Rb);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 Ob(e){e===void 0&&(e={});var t=Pb(null);return t.options=Tn({async:!0,ssr:!1},e),t}var Td=function(e){var t=e.sideCar,n=Cd(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,Tn({},n))};Td.isSideCarExport=!0;function Mb(e,t){return e.useMedium(t),Td}var Ed=Ob(),Aa=function(){},ks=m.forwardRef(function(e,t){var n=m.useRef(null),r=m.useState({onScrollCapture:Aa,onWheelCapture:Aa,onTouchMoveCapture:Aa}),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,C=e.gapMode,E=Cd(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),k=h,T=jb([n,t]),I=Tn(Tn({},E),o);return m.createElement(m.Fragment,null,d&&m.createElement(k,{sideCar:Ed,removeScrollBar:u,shards:f,noRelative:p,noIsolation:v,inert:x,setCallbacks:s,allowPinchZoom:!!g,lockRef:n,gapMode:C}),i?m.cloneElement(m.Children.only(a),Tn(Tn({},I),{ref:T})):m.createElement(b,Tn({},I,{className:l,ref:T}),a))});ks.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},ks.classNames={fullWidth:Cs,zeroRight:Ss};var Db=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Lb(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Db();return t&&e.setAttribute("nonce",t),e}function Fb(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function $b(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var zb=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Lb())&&(Fb(t,n),$b(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Bb=function(){var e=zb();return function(t,n){m.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Id=function(){var e=Bb(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Hb={left:0,top:0,right:0,gap:0},Na=function(e){return parseInt(e||"",10)||0},Ub=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[Na(n),Na(r),Na(o)]},Wb=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Hb;var t=Ub(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])}},Vb=Id(),Rr="data-scroll-locked",Kb=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=nd(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=nd(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 ad{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 ld{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 Kn{constructor(t){this.options=t||hr,this.options.renderer=this.options.renderer||new xa,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new ad,this.slugger=new ld}static parse(t,n){return new Kn(n).parse(t)}static parseInline(t,n){return new Kn(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,E,k,T;const I=t.length;for(o=0;o<I;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,td(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,E=b.task,y="",b.task&&(k=this.renderer.checkbox(S),g?b.tokens.length>0&&b.tokens[0].type==="paragraph"?(b.tokens[0].text=k+" "+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=k+" "+b.tokens[0].tokens[0].text)):b.tokens.unshift({type:"text",text:k}):y+=k),y+=this.parse(b.tokens,g),h+=this.renderer.listitem(y,E,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<I&&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 _='Token with "'+p.type+'" type was not found.';if(this.options.silent){console.error(_);return}else throw new Error(_)}}}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 xs{constructor(t){this.options=t||hr}preprocess(t){return t}postprocess(t){return t}}Cm(xs,"passThroughHooks",new Set(["preprocess","postprocess"]));function nb(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>"+Rt(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 cd(e,t){return(n,r,o)=>{typeof r=="function"&&(o=r,r=null);const s={...r};r={...Se.defaults,...s};const i=nb(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(Qv(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&&Se.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;Se.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(Se.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&&Se.walkTokens(a,r.walkTokens);let l=t(a,r);return r.hooks&&(l=r.hooks.postprocess(l)),l}catch(a){return i(a)}}}function Se(e,t,n){return cd(Vn.lex,Kn.parse)(e,t,n)}Se.options=Se.setOptions=function(e){return Se.defaults={...Se.defaults,...e},zv(Se.defaults),Se},Se.getDefaults=Ju,Se.defaults=hr,Se.use=function(...e){const t=Se.defaults.extensions||{renderers:{},childTokens:{}};e.forEach(n=>{const r={...n};if(r.async=Se.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=Se.defaults.renderer||new xa;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=Se.defaults.tokenizer||new ga;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=Se.defaults.hooks||new xs;for(const s in n.hooks){const i=o[s];xs.passThroughHooks.has(s)?o[s]=a=>{if(Se.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=Se.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}}Se.setOptions(r)})},Se.walkTokens=function(e,t){let n=[];for(const r of e)switch(n=n.concat(t.call(Se,r)),r.type){case"table":{for(const o of r.header)n=n.concat(Se.walkTokens(o.tokens,t));for(const o of r.rows)for(const s of o)n=n.concat(Se.walkTokens(s.tokens,t));break}case"list":{n=n.concat(Se.walkTokens(r.items,t));break}default:Se.defaults.extensions&&Se.defaults.extensions.childTokens&&Se.defaults.extensions.childTokens[r.type]?Se.defaults.extensions.childTokens[r.type].forEach(function(o){n=n.concat(Se.walkTokens(r[o],t))}):r.tokens&&(n=n.concat(Se.walkTokens(r.tokens,t)))}return n},Se.parseInline=cd(Vn.lexInline,Kn.parseInline),Se.Parser=Kn,Se.parser=Kn.parse,Se.Renderer=xa,Se.TextRenderer=ad,Se.Lexer=Vn,Se.lexer=Vn.lex,Se.Tokenizer=ga,Se.Slugger=ld,Se.Hooks=xs,Se.parse=Se,Se.options,Se.setOptions,Se.use,Se.walkTokens,Se.parseInline,Kn.parse,Vn.lex;function ya({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 Se.parse(i)}return Se.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:re("markdown prose max-w-none break-words dark:prose-invert",t),style:s,dangerouslySetInnerHTML:{__html:o}})}async function ud(e,t){return await sn(e,{responseType:"blob",onDownloadProgress:r=>{try{t&&r.lengthComputable}catch{}},maxBodyLength:1/0})}async function dd(e,t){return await(await ud(`/files/${e}/view`,t)).text()}async function rb(e,t){const n=await ud(`/files/${e}/download`,t),r=URL.createObjectURL(n);let o=`file_${e}`;try{const i=await sn(`/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 ob(e,t=50,n=0){const r={limit:t,offset:n};return e&&(r.thread_id=e),await sn("/files",{params:r})}const sb=1,ib=1e6;let va=0;function ab(){return va=(va+1)%Number.MAX_SAFE_INTEGER,va.toString()}const ba=new Map,fd=e=>{if(ba.has(e))return;const t=setTimeout(()=>{ba.delete(e),go({type:"REMOVE_TOAST",toastId:e})},ib);ba.set(e,t)},lb=(e,t)=>{switch(t.type){case"ADD_TOAST":return{...e,toasts:[t.toast,...e.toasts].slice(0,sb)};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?fd(n):e.toasts.forEach(r=>{fd(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)}}},ys=[];let vs={toasts:[]};function go(e){vs=lb(vs,e),ys.forEach(t=>{t(vs)})}function cb({...e}){const t=ab(),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 wa(){const[e,t]=m.useState(vs);return m.useEffect(()=>(ys.push(t),()=>{const n=ys.indexOf(t);n>-1&&ys.splice(n,1)}),[e]),{...e,toast:cb,dismiss:n=>go({type:"DISMISS_TOAST",toastId:n})}}function Ct(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 ub(e,t=globalThis==null?void 0:globalThis.document){const n=Ct(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 db="DismissableLayer",Sa="dismissableLayer.update",fb="dismissableLayer.pointerDownOutside",hb="dismissableLayer.focusOutside",hd,pd=m.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),bs=m.forwardRef((e,t)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,u=m.useContext(pd),[d,f]=m.useState(null),h=(d==null?void 0:d.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=m.useState({}),v=Be(t,I=>f(I)),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,E=b>=y,k=gb(I=>{const _=I.target,O=[...u.branches].some(j=>j.contains(_));!E||O||(o==null||o(I),i==null||i(I),I.defaultPrevented||a==null||a())},h),T=xb(I=>{const _=I.target;[...u.branches].some(j=>j.contains(_))||(s==null||s(I),i==null||i(I),I.defaultPrevented||a==null||a())},h);return ub(I=>{b===u.layers.size-1&&(r==null||r(I),!I.defaultPrevented&&a&&(I.preventDefault(),a()))},h),m.useEffect(()=>{if(d)return n&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(hd=h.body.style.pointerEvents,h.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(d)),u.layers.add(d),md(),()=>{n&&u.layersWithOutsidePointerEventsDisabled.size===1&&(h.body.style.pointerEvents=hd)}},[d,h,n,u]),m.useEffect(()=>()=>{d&&(u.layers.delete(d),u.layersWithOutsidePointerEventsDisabled.delete(d),md())},[d,u]),m.useEffect(()=>{const I=()=>p({});return document.addEventListener(Sa,I),()=>document.removeEventListener(Sa,I)},[]),c.jsx(Ee.div,{...l,ref:v,style:{pointerEvents:S?E?"auto":"none":void 0,...e.style},onFocusCapture:fe(e.onFocusCapture,T.onFocusCapture),onBlurCapture:fe(e.onBlurCapture,T.onBlurCapture),onPointerDownCapture:fe(e.onPointerDownCapture,k.onPointerDownCapture)})});bs.displayName=db;var pb="DismissableLayerBranch",mb=m.forwardRef((e,t)=>{const n=m.useContext(pd),r=m.useRef(null),o=Be(t,r);return m.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),c.jsx(Ee.div,{...e,ref:o})});mb.displayName=pb;function gb(e,t=globalThis==null?void 0:globalThis.document){const n=Ct(e),r=m.useRef(!1),o=m.useRef(()=>{});return m.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){gd(fb,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 xb(e,t=globalThis==null?void 0:globalThis.document){const n=Ct(e),r=m.useRef(!1);return m.useEffect(()=>{const o=s=>{s.target&&!r.current&&gd(hb,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 md(){const e=new CustomEvent(Sa);document.dispatchEvent(e)}function gd(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?Vu(o,s):o.dispatchEvent(s)}var Ca="focusScope.autoFocusOnMount",ka="focusScope.autoFocusOnUnmount",xd={bubbles:!1,cancelable:!0},yb="FocusScope",ws=m.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=m.useState(null),u=Ct(o),d=Ct(s),f=m.useRef(null),h=Be(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 E=S.target;a.contains(E)?f.current=E:qn(f.current,{select:!0})},g=function(S){if(p.paused||!a)return;const E=S.relatedTarget;E!==null&&(a.contains(E)||qn(f.current,{select:!0}))},y=function(S){if(document.activeElement===document.body)for(const k of S)k.removedNodes.length>0&&qn(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){bd.add(p);const x=document.activeElement;if(!a.contains(x)){const y=new CustomEvent(Ca,xd);a.addEventListener(Ca,u),a.dispatchEvent(y),y.defaultPrevented||(vb(kb(yd(a)),{select:!0}),document.activeElement===x&&qn(a))}return()=>{a.removeEventListener(Ca,u),setTimeout(()=>{const y=new CustomEvent(ka,xd);a.addEventListener(ka,d),a.dispatchEvent(y),y.defaultPrevented||qn(x??document.body,{select:!0}),a.removeEventListener(ka,d),bd.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,E]=bb(b);S&&E?!x.shiftKey&&y===E?(x.preventDefault(),n&&qn(S,{select:!0})):x.shiftKey&&y===S&&(x.preventDefault(),n&&qn(E,{select:!0})):y===b&&x.preventDefault()}},[n,r,p.paused]);return c.jsx(Ee.div,{tabIndex:-1,...i,ref:h,onKeyDown:v})});ws.displayName=yb;function vb(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(qn(r,{select:t}),document.activeElement!==n)return}function bb(e){const t=yd(e),n=vd(t,e),r=vd(t.reverse(),e);return[n,r]}function yd(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function vd(e,t){for(const n of e)if(!wb(n,{upTo:t}))return n}function wb(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 Sb(e){return e instanceof HTMLInputElement&&"select"in e}function qn(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&Sb(e)&&t&&e.select()}}var bd=Cb();function Cb(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=wd(e,t),e.unshift(t)},remove(t){var n;e=wd(e,t),(n=e[0])==null||n.resume()}}}function wd(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function kb(e){return e.filter(t=>t.tagName!=="A")}var Tb="Portal",Ss=m.forwardRef((e,t)=>{var a;const{container:n,...r}=e,[o,s]=m.useState(!1);gt(()=>s(!0),[]);const i=n||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?pi.createPortal(c.jsx(Ee.div,{...r,ref:t}),i):null});Ss.displayName=Tb;var Ta=0;function Ea(){m.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??Sd()),document.body.insertAdjacentElement("beforeend",e[1]??Sd()),Ta++,()=>{Ta===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(t=>t.remove()),Ta--}},[])}function Sd(){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 Cd(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 Eb(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 Cs="right-scroll-bar-position",ks="width-before-scroll-bar",Ib="with-scroll-bars-hidden",Ab="--removed-body-scroll-bar-size";function Ia(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function Nb(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 _b=typeof window<"u"?m.useLayoutEffect:m.useEffect,kd=new WeakMap;function jb(e,t){var n=Nb(null,function(r){return e.forEach(function(o){return Ia(o,r)})});return _b(function(){var r=kd.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||Ia(a,null)}),s.forEach(function(a){o.has(a)||Ia(a,i)})}kd.set(n,e)},[e]),n}function Rb(e){return e}function Pb(e,t){t===void 0&&(t=Rb);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 Ob(e){e===void 0&&(e={});var t=Pb(null);return t.options=Cn({async:!0,ssr:!1},e),t}var Td=function(e){var t=e.sideCar,n=Cd(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))};Td.isSideCarExport=!0;function Mb(e,t){return e.useMedium(t),Td}var Ed=Ob(),Aa=function(){},Ts=m.forwardRef(function(e,t){var n=m.useRef(null),r=m.useState({onScrollCapture:Aa,onWheelCapture:Aa,onTouchMoveCapture:Aa}),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,E=Cd(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noRelative","noIsolation","inert","allowPinchZoom","as","gapMode"]),k=h,T=jb([n,t]),I=Cn(Cn({},E),o);return m.createElement(m.Fragment,null,d&&m.createElement(k,{sideCar:Ed,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({},I),{ref:T})):m.createElement(b,Cn({},I,{className:l,ref:T}),a))});Ts.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1},Ts.classNames={fullWidth:ks,zeroRight:Cs};var Db=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Lb(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=Db();return t&&e.setAttribute("nonce",t),e}function Fb(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function $b(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var zb=function(){var e=0,t=null;return{add:function(n){e==0&&(t=Lb())&&(Fb(t,n),$b(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},Bb=function(){var e=zb();return function(t,n){m.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},Id=function(){var e=Bb(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},Hb={left:0,top:0,right:0,gap:0},Na=function(e){return parseInt(e||"",10)||0},Ub=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[Na(n),Na(r),Na(o)]},Wb=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return Hb;var t=Ub(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])}},Vb=Id(),Rr="data-scroll-locked",Kb=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
|
|
84
84
|
.`.concat(Ib,` {
|
|
85
85
|
overflow: hidden `).concat(r,`;
|
|
86
86
|
padding-right: `).concat(a,"px ").concat(r,`;
|
|
@@ -98,36 +98,37 @@ Please report this to https://github.com/markedjs/marked.`,e){const o="<p>An err
|
|
|
98
98
|
`),n==="padding"&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),`
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
.`).concat(
|
|
101
|
+
.`).concat(Cs,` {
|
|
102
102
|
right: `).concat(a,"px ").concat(r,`;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
.`).concat(
|
|
105
|
+
.`).concat(ks,` {
|
|
106
106
|
margin-right: `).concat(a,"px ").concat(r,`;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
.`).concat(
|
|
109
|
+
.`).concat(Cs," .").concat(Cs,` {
|
|
110
110
|
right: 0 `).concat(r,`;
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
.`).concat(
|
|
113
|
+
.`).concat(ks," .").concat(ks,` {
|
|
114
114
|
margin-right: 0 `).concat(r,`;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
body[`).concat(Rr,`] {
|
|
118
118
|
`).concat(Ab,": ").concat(a,`px;
|
|
119
119
|
}
|
|
120
|
-
`)},Ad=function(){var e=parseInt(document.body.getAttribute(Rr)||"0",10);return isFinite(e)?e:0},qb=function(){m.useEffect(function(){return document.body.setAttribute(Rr,(Ad()+1).toString()),function(){var e=Ad()-1;e<=0?document.body.removeAttribute(Rr):document.body.setAttribute(Rr,e.toString())}},[])},Gb=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;qb();var s=m.useMemo(function(){return Wb(o)},[o]);return m.createElement(Vb,{styles:Kb(s,!t,o,n?"":"!important")})},_a=!1;if(typeof window<"u")try{var
|
|
120
|
+
`)},Ad=function(){var e=parseInt(document.body.getAttribute(Rr)||"0",10);return isFinite(e)?e:0},qb=function(){m.useEffect(function(){return document.body.setAttribute(Rr,(Ad()+1).toString()),function(){var e=Ad()-1;e<=0?document.body.removeAttribute(Rr):document.body.setAttribute(Rr,e.toString())}},[])},Gb=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;qb();var s=m.useMemo(function(){return Wb(o)},[o]);return m.createElement(Vb,{styles:Kb(s,!t,o,n?"":"!important")})},_a=!1;if(typeof window<"u")try{var Es=Object.defineProperty({},"passive",{get:function(){return _a=!0,!0}});window.addEventListener("test",Es,Es),window.removeEventListener("test",Es,Es)}catch{_a=!1}var Pr=_a?{passive:!1}:!1,Yb=function(e){return e.tagName==="TEXTAREA"},Nd=function(e,t){if(!(e instanceof Element))return!1;var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!Yb(e)&&n[t]==="visible")},Xb=function(e){return Nd(e,"overflowY")},Jb=function(e){return Nd(e,"overflowX")},_d=function(e,t){var n=t.ownerDocument,r=t;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=jd(e,r);if(o){var s=Rd(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==n.body);return!1},Zb=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},Qb=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},jd=function(e,t){return e==="v"?Xb(t):Jb(t)},Rd=function(e,t){return e==="v"?Zb(t):Qb(t)},ew=function(e,t){return e==="h"&&t==="rtl"?-1:1},tw=function(e,t,n,r,o){var s=ew(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=Rd(e,a),v=p[0],x=p[1],g=p[2],y=x-g-s*v;(v||y)&&jd(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},Is=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},Pd=function(e){return[e.deltaX,e.deltaY]},Od=function(e){return e&&"current"in e?e.current:e},nw=function(e,t){return e[0]===t[0]&&e[1]===t[1]},rw=function(e){return`
|
|
121
121
|
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
122
122
|
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
123
|
-
`)},ow=0,Or=[];function sw(e){var t=m.useRef([]),n=m.useRef([0,0]),r=m.useRef(),o=m.useState(ow++)[0],s=m.useState(Id)[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=Eb([e.lockRef.current],(e.shards||[]).map(Od),!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=
|
|
123
|
+
`)},ow=0,Or=[];function sw(e){var t=m.useRef([]),n=m.useRef([0,0]),r=m.useRef(),o=m.useState(ow++)[0],s=m.useState(Id)[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=Eb([e.lockRef.current],(e.shards||[]).map(Od),!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=Is(x),b=n.current,S="deltaX"in x?x.deltaX:b[0]-y[0],E="deltaY"in x?x.deltaY:b[1]-y[1],k,T=x.target,I=Math.abs(S)>Math.abs(E)?"h":"v";if("touches"in x&&I==="h"&&T.type==="range")return!1;var _=_d(I,T);if(!_)return!0;if(_?k=I:(k=I==="v"?"h":"v",_=_d(I,T)),!_)return!1;if(!r.current&&"changedTouches"in x&&(S||E)&&(r.current=k),!k)return!0;var O=r.current||k;return tw(O,g,x,O==="h"?S:E)},[]),l=m.useCallback(function(x){var g=x;if(!(!Or.length||Or[Or.length-1]!==s)){var y="deltaY"in g?Pd(g):Is(g),b=t.current.filter(function(k){return k.name===g.type&&(k.target===g.target||g.target===k.shadowParent)&&nw(k.delta,y)})[0];if(b&&b.should){g.cancelable&&g.preventDefault();return}if(!b){var S=(i.current.shards||[]).map(Od).filter(Boolean).filter(function(k){return k.contains(g.target)}),E=S.length>0?a(g,S[0]):!i.current.noIsolation;E&&g.cancelable&&g.preventDefault()}}},[]),u=m.useCallback(function(x,g,y,b){var S={name:x,delta:g,target:y,should:b,shadowParent:iw(y)};t.current.push(S),setTimeout(function(){t.current=t.current.filter(function(E){return E!==S})},1)},[]),d=m.useCallback(function(x){n.current=Is(x),r.current=void 0},[]),f=m.useCallback(function(x){u(x.type,Pd(x),x.target,a(x,e.lockRef.current))},[]),h=m.useCallback(function(x){u(x.type,Is(x),x.target,a(x,e.lockRef.current))},[]);m.useEffect(function(){return Or.push(s),e.setCallbacks({onScrollCapture:f,onWheelCapture:f,onTouchMoveCapture:h}),document.addEventListener("wheel",l,Pr),document.addEventListener("touchmove",l,Pr),document.addEventListener("touchstart",d,Pr),function(){Or=Or.filter(function(x){return x!==s}),document.removeEventListener("wheel",l,Pr),document.removeEventListener("touchmove",l,Pr),document.removeEventListener("touchstart",d,Pr)}},[]);var p=e.removeScrollBar,v=e.inert;return m.createElement(m.Fragment,null,v?m.createElement(s,{styles:rw(o)}):null,p?m.createElement(Gb,{noRelative:e.noRelative,gapMode:e.gapMode}):null)}function iw(e){for(var t=null;e!==null;)e instanceof ShadowRoot&&(t=e.host,e=e.host),e=e.parentNode;return t}const aw=Mb(Ed,sw);var As=m.forwardRef(function(e,t){return m.createElement(Ts,Cn({},e,{ref:t,sideCar:aw}))});As.classNames=Ts.classNames;var lw=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},Mr=new WeakMap,Ns=new WeakMap,_s={},ja=0,Md=function(e){return e&&(e.host||Md(e.parentNode))},cw=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=Md(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})},uw=function(e,t,n,r){var o=cw(t,Array.isArray(e)?e:[e]);_s[n]||(_s[n]=new WeakMap);var s=_s[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=(Mr.get(h)||0)+1,g=(s.get(h)||0)+1;Mr.set(h,x),s.set(h,g),i.push(h),x===1&&v&&Ns.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(),ja++,function(){i.forEach(function(f){var h=Mr.get(f)-1,p=s.get(f)-1;Mr.set(f,h),s.set(f,p),h||(Ns.has(f)||f.removeAttribute(r),Ns.delete(f)),p||f.removeAttribute(n)}),ja--,ja||(Mr=new WeakMap,Mr=new WeakMap,Ns=new WeakMap,_s={})}},Ra=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=lw(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live], script"))),uw(r,o,n,"aria-hidden")):function(){return null}},js="Dialog",[Dd,CT]=wn(js),[dw,cn]=Dd(js),Ld=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]=fr({prop:r,defaultProp:o??!1,onChange:s,caller:js});return c.jsx(dw,{scope:t,triggerRef:a,contentRef:l,contentId:Sn(),titleId:Sn(),descriptionId:Sn(),open:u,onOpenChange:d,onOpenToggle:m.useCallback(()=>d(f=>!f),[d]),modal:i,children:n})};Ld.displayName=js;var Fd="DialogTrigger",$d=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=cn(Fd,n),s=Be(t,o.triggerRef);return c.jsx(Ee.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":Ma(o.open),...r,ref:s,onClick:fe(e.onClick,o.onOpenToggle)})});$d.displayName=Fd;var Pa="DialogPortal",[fw,zd]=Dd(Pa,{forceMount:void 0}),Bd=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=cn(Pa,t);return c.jsx(fw,{scope:t,forceMount:n,children:m.Children.map(r,i=>c.jsx(Wt,{present:n||s.open,children:c.jsx(Ss,{asChild:!0,container:o,children:i})}))})};Bd.displayName=Pa;var Rs="DialogOverlay",Hd=m.forwardRef((e,t)=>{const n=zd(Rs,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=cn(Rs,e.__scopeDialog);return s.modal?c.jsx(Wt,{present:r||s.open,children:c.jsx(pw,{...o,ref:t})}):null});Hd.displayName=Rs;var hw=rr.createSlot("DialogOverlay.RemoveScroll"),pw=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=cn(Rs,n);return c.jsx(As,{as:hw,allowPinchZoom:!0,shards:[o.contentRef],children:c.jsx(Ee.div,{"data-state":Ma(o.open),...r,ref:t,style:{pointerEvents:"auto",...r.style}})})}),pr="DialogContent",Ud=m.forwardRef((e,t)=>{const n=zd(pr,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=cn(pr,e.__scopeDialog);return c.jsx(Wt,{present:r||s.open,children:s.modal?c.jsx(mw,{...o,ref:t}):c.jsx(gw,{...o,ref:t})})});Ud.displayName=pr;var mw=m.forwardRef((e,t)=>{const n=cn(pr,e.__scopeDialog),r=m.useRef(null),o=Be(t,n.contentRef,r);return m.useEffect(()=>{const s=r.current;if(s)return Ra(s)},[]),c.jsx(Wd,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:fe(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)==null||i.focus()}),onPointerDownOutside:fe(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:fe(e.onFocusOutside,s=>s.preventDefault())})}),gw=m.forwardRef((e,t)=>{const n=cn(pr,e.__scopeDialog),r=m.useRef(!1),o=m.useRef(!1);return c.jsx(Wd,{...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()}})}),Wd=m.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=cn(pr,n),l=m.useRef(null),u=Be(t,l);return Ea(),c.jsxs(c.Fragment,{children:[c.jsx(ws,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:c.jsx(bs,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":Ma(a.open),...i,ref:u,onDismiss:()=>a.onOpenChange(!1)})}),c.jsxs(c.Fragment,{children:[c.jsx(xw,{titleId:a.titleId}),c.jsx(vw,{contentRef:l,descriptionId:a.descriptionId})]})]})}),Oa="DialogTitle",Vd=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=cn(Oa,n);return c.jsx(Ee.h2,{id:o.titleId,...r,ref:t})});Vd.displayName=Oa;var Kd="DialogDescription",qd=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=cn(Kd,n);return c.jsx(Ee.p,{id:o.descriptionId,...r,ref:t})});qd.displayName=Kd;var Gd="DialogClose",Yd=m.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=cn(Gd,n);return c.jsx(Ee.button,{type:"button",...r,ref:t,onClick:fe(e.onClick,()=>o.onOpenChange(!1))})});Yd.displayName=Gd;function Ma(e){return e?"open":"closed"}var Xd="DialogTitleWarning",[kT,Jd]=Sv(Xd,{contentName:pr,titleName:Oa,docsSlug:"dialog"}),xw=({titleId:e})=>{const t=Jd(Xd),n=`\`${t.contentName}\` requires a \`${t.titleName}\` for the component to be accessible for screen reader users.
|
|
124
124
|
|
|
125
125
|
If you want to hide the \`${t.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
126
126
|
|
|
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},yw="DialogDescriptionWarning",vw=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Jd(yw).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},Zd=Ld,bw=$d,Qd=Bd,Rs=Hd,Ps=Ud,gr=Vd,Os=qd,ef=Yd;const ww=Zd,Sw=Qd,tf=m.forwardRef(({className:e,...t},n)=>c.jsx(Rs,{ref:n,className:re("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}));tf.displayName=Rs.displayName;const nf=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===gr||(u==null?void 0:u.displayName)===gr.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(Sw,{children:[c.jsx(tf,{}),c.jsxs(Ps,{ref:r,className:re("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(gr,{className:"sr-only",children:"Dialog"}),t,c.jsxs(ef,{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(me.X,{className:"h-4 w-4"}),c.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});nf.displayName=Ps.displayName;const rf=({className:e,...t})=>c.jsx("div",{className:re("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});rf.displayName="DialogHeader";const of=m.forwardRef(({className:e,...t},n)=>c.jsx(gr,{ref:n,className:re("text-lg font-semibold leading-none tracking-tight",e),...t}));of.displayName=gr.displayName;const Cw=m.forwardRef(({className:e,...t},n)=>c.jsx(Os,{ref:n,className:re("text-sm text-muted-foreground",e),...t}));Cw.displayName=Os.displayName;function kw({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}=wa(),h=w.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const y=await dd(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 rb(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 dd(n),b=new Blob([y],{type:o}),C=URL.createObjectURL(b);window.open(C,"_blank"),URL.revokeObjectURL(C)}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(me.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(Ge,{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(me.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(me.Image,{className:"h-5 w-5"}):c.jsx(me.FileText,{className:"h-5 w-5"});return c.jsx(ww,{open:e,onOpenChange:t,children:c.jsxs(nf,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[c.jsx(rf,{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(of,{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(Ge,{variant:"outline",size:"sm",onClick:v,className:"flex items-center gap-2",children:[c.jsx(me.ExternalLink,{className:"h-4 w-4"}),"External"]}),c.jsxs(Ge,{variant:"outline",size:"sm",onClick:p,className:"flex items-center gap-2",children:[c.jsx(me.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),c.jsx("div",{className:"flex-1 overflow-hidden",children:x()})]})})}function sf(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 af(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function go(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(go).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(af(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=go(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 Ms(e){if(typeof e=="string")return e;if(af(e))return"";try{const t=go(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function lf(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 lf(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 Ds="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",Ls=1e5;function Tw(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function Ew(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 Iw(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 Fs(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function Aw(e){const t=(r,o=Ls)=>{try{const s=go(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 Nw(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 _w(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function cf(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 jw({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:re("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const uf=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,activeInterrupt:b,disableInterruptActions:
|
|
129
|
-
… [truncated ${
|
|
130
|
-
dark:bg-background/10 dark:border-border/30 dark:hover:bg-background/20`,children:[G[xe]?c.jsx(me.Loader,{className:"h-4 w-4 animate-spin"}):null,c.jsxs("span",{className:"truncate max-w-[180px]",children:[_e,G[xe]?" (processing)":""]})]},xe)}if(J.type==="interrupt"){const ue=J,_e=Fs((ue==null?void 0:ue.id)??(ue==null?void 0:ue.interrupt_id)),Ve=!!(oe&&_e&&_e===oe),at=Ve?ie??(ue==null?void 0:ue.value):ue==null?void 0:ue.value,Tt=_e?{...ue,id:_e,interrupt_id:_e}:ue;return c.jsx(Ow,{interruptPart:Tt,onApprove:kt,onReject:ot,disabled:C,isActive:Ve,payload:at},xe)}return null},[Ze,G,kt,ot,Y,f,h,j,M,oe,ie,b,C,ee]),$e=w.useCallback(()=>c.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[c.jsx(me.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),c.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),ct=w.useCallback(()=>{const J=ye.trim().length>0||L.length>0||Z.length>0||ee.length>0;if(!ce&&!J&&!r)return $e();if(t.model==="reflection"){const xe=ye.trim(),ue=sf(xe);if(ue&&typeof ue=="object")return c.jsx(Mw,{data:ue})}if(ce&&K.name==="get_issues"){const xe=t.content.find(Ve=>Ve.type==="tool_end"),ue=(xe==null?void 0:xe.output)??Be,_e=lf(ue);if(_e)return c.jsx(Dw,{issues:_e})}if(ce){const xe=Iw(t.content);if(xe.length>0)return c.jsx("div",{className:"space-y-3",children:xe.map((ue,_e)=>{const Ve=typeof ue.output=="string"?ue.output:Ms(ue.output);return _==="expanded"||!u?c.jsxs("div",{className:"space-y-1",children:[c.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[c.jsx("span",{children:ue.name??"tool"}),ue.toolCallId&&c.jsxs("span",{children:["• ",ue.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:Ve})})]},ue.toolCallId??_e):null})})}if(!ce){const xe=c.jsx("div",{className:"space-y-2",children:t.content.map((ue,_e)=>c.jsx(et,{part:ue,i:_e},_e))});return r?c.jsxs("div",{"aria-busy":"true",role:"status",children:[xe,c.jsx(jw,{className:ge})]}):xe}},[ye,L.length,Z.length,ee.length,r,t.model,ce,K.name,Be,_,u,d,$e,ge]),vt=w.useMemo(()=>_w(t),[t]);return c.jsxs(c.Fragment,{children:[c.jsx("div",{className:re(wt(),p.container),children:c.jsxs("div",{className:re(Ct(),p.content),children:[(i||a||ce)&&c.jsxs("div",{className:re("flex items-center justify-between mb-2 pb-2 border-b border-current/10",M&&"mb-1 pb-1",ge,p.header),children:[c.jsxs("div",{className:"flex items-center gap-2",children:[Pe(),a&&vt&&c.jsx("span",{className:re("font-medium",M?"text-xs":"text-sm"),children:vt}),ce&&c.jsxs(Uu,{variant:"outline",className:re("text-xs flex items-center gap-1 cursor-pointer select-none",ge,"border border-current/40",M&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":_==="expanded",onClick:()=>P(J=>J==="expanded"?"preview":"expanded"),onKeyDown:J=>{(J.key==="Enter"||J.key===" ")&&(J.preventDefault(),P(xe=>xe==="expanded"?"preview":"expanded"))},children:[c.jsx("span",{children:K.name??"Tool Output"}),K.toolCallId&&c.jsx("span",{className:"opacity-70",children:K.toolCallId.slice(0,8)}),_==="expanded"?c.jsx(me.ChevronUp,{className:"h-3 w-3"}):c.jsx(me.ChevronDown,{className:"h-3 w-3"})]})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[i&&t.createdAt&&c.jsx("time",{className:re("text-xs opacity-60",ge,M&&"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:re("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:()=>je(ce?"visible":"all"),className:re("h-6 w-6 p-0 hover:bg-foreground/10",ge,M&&"h-5 w-5"),"aria-label":ce?"Copy visible":"Copy message",title:ce?"Copy visible portion":"Copy message",children:c.jsx(me.Copy,{className:re(T?"text-success":ge,M?"h-3 w-3":"h-4 w-4")})}),ce&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>je("all"),className:re("h-6 px-1 text-xs hover:bg-foreground/10",ge),"aria-label":"Copy all (may be large)",title:"Copy all (may be large)",children:"all"})]}),Y==="user"&&v&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:He,className:re("h-6 w-6 p-0 hover:bg-foreground/10",ge,M&&"h-5 w-5"),"aria-label":"Edit message",children:c.jsx(me.Edit,{className:re(ge,M?"h-3 w-3":"h-4 w-4")})}),Y==="assistant"&&x&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:Qe,className:re("h-6 w-6 p-0 hover:bg-foreground/10",ge,M&&"h-5 w-5"),"aria-label":"Regenerate response",children:c.jsx(me.RotateCcw,{className:re(ge,M?"h-3 w-3":"h-4 w-4")})})]})]})]}),c.jsx("div",{className:"relative",children:ct()}),ce&&_==="expanded"&&(K.toolCallId||K.name)&&c.jsxs("div",{className:re("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",M&&"text-xs"),children:[K.name&&c.jsxs("div",{children:["Function: ",K.name]}),K.toolCallId&&c.jsxs("div",{children:["Call ID: ",K.toolCallId]})]}),!(i||a||ce)&&s&&!o&&c.jsxs("div",{className:re("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:()=>je(),className:re("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:c.jsx(me.Copy,{className:re(T?"text-success":"text-current",M?"h-3 w-3":"h-4 w-4")})}),Y==="user"&&v&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:He,className:re("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:c.jsx(me.Edit,{className:re("text-current",M?"h-3 w-3":"h-4 w-4")})}),Y==="assistant"&&x&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:Qe,className:re("h-6 w-6 p-0 hover:bg-background/50 text-current",M&&"h-5 w-5"),children:c.jsx(me.RotateCcw,{className:re("text-current",M?"h-3 w-3":"h-4 w-4")})})]})]})}),z&&c.jsx(kw,{isOpen:ne,onClose:()=>{$(!1),se(null)},fileId:z.id,fileName:z.name,mimeType:z.mimeType})]})},(e,t)=>{var i,a,l,u,d,f,h,p;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&cf(e.message)===cf(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 Rw({data:e}){if(Array.isArray(e))return e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?c.jsx("div",{className:Ds,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:Ms(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:Ds,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:Ds,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:Pw(i)})]},s))})})}return c.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Ms(e)})}function Pw(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(go(e))})}catch{return String(e)}}function Ow({interruptPart:e,onApprove:t,onReject:n,disabled:r,isActive:o,payload:s}){const i=e.title??"Approve the result?";let a=null;if(s!=null)if(typeof s=="string")a=c.jsx("p",{className:"text-sm leading-relaxed text-blue-800/90 dark:text-blue-200/90 whitespace-pre-wrap",children:s});else{const u=Ms(s);a=c.jsx("pre",{className:"max-h-48 overflow-auto rounded bg-blue-100/60 p-2 text-xs text-blue-900/90 dark:bg-blue-900/40 dark:text-blue-100/80",children:u})}const l=o?"Please approve or reject this action to resume the workflow.":"Waiting for approval from another participant.";return c.jsxs(uo,{className:re("border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10 transition-shadow",o?"shadow-md ring-1 ring-blue-300 dark:ring-blue-500/70":"opacity-80"),children:[c.jsxs(fo,{className:"pb-3",children:[c.jsx(ho,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),c.jsx(Yu,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&c.jsx(po,{className:"pt-0 pb-3",children:a}),c.jsx(Xu,{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",disabled:r||!o,children:"Reject"}),c.jsx(Ge,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,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 Dw({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:Ds,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 df=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,Da=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,activeInterrupt:b,disableInterruptActions:C=!1,onInterruptActionStart:E,onInterruptActionEnd:k},T)=>{const I=w.useRef(null),_=w.useRef(null),P=w.useRef(!1),[j,H]=w.useState(!0),F=w.useMemo(()=>b?e.some($=>Array.isArray($==null?void 0:$.content)&&$.content.some(z=>z&&z.type==="interrupt"&&(z.id??z.interrupt_id)===b.id)):!1,[b,e]),U=w.useMemo(()=>{if(!b||F)return null;const $=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let z;const se=b.value;if(se&&typeof se=="object"&&!Array.isArray(se)){const M=se.title;typeof M=="string"&&M.trim()&&(z=M.trim())}return{id:`interrupt-${$}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:$,value:se,title:z}]}},[b,F]),D=w.useMemo(()=>U?[...e,U]:e,[e,U]),G=w.useCallback($=>{H($),g&&g(!$),y&&y($)},[g,y]),W=w.useMemo(()=>{if(a)return async()=>{if(!P.current){P.current=!0;try{await a()}finally{P.current=!1}}}},[a]),ne=w.useMemo(()=>!v||x?!1:j?"auto":!1,[j,v,x]);return D.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(iv,{ref:$=>{I.current=$},scrollerRef:$=>{_.current=$ instanceof HTMLDivElement?$:null},data:D,followOutput:ne,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{W&&W()},atBottomStateChange:G,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:($,z)=>df(z,$),itemContent:($,z)=>{const se=df(z,$);return c.jsx("div",{className:"mb-4 last:mb-0","data-message-id":se,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:c.jsx(uf,{message:z,messageIndex:$,isStreamingMessage:t&&n===z.id,streamingDebounceMs:r,isEditing:i===z.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,truncateToolMessages:!1,toolMessagePreviewLength:200,onEdit:l,onRegenerate:()=>u($),onCancelEdit:d,activeInterrupt:b,disableInterruptActions:C,onInterruptActionStart:E,onInterruptActionEnd:k})})}})})});Da.displayName="MessageList";const $s=1e4;function Lw(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},yw="DialogDescriptionWarning",vw=({contentRef:e,descriptionId:t})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${Jd(yw).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},Zd=Ld,bw=$d,Qd=Bd,Ps=Hd,Os=Ud,mr=Vd,Ms=qd,ef=Yd;const ww=Zd,Sw=Qd,tf=m.forwardRef(({className:e,...t},n)=>c.jsx(Ps,{ref:n,className:re("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}));tf.displayName=Ps.displayName;const nf=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===mr||(u==null?void 0:u.displayName)===mr.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(Sw,{children:[c.jsx(tf,{}),c.jsxs(Os,{ref:r,className:re("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(mr,{className:"sr-only",children:"Dialog"}),t,c.jsxs(ef,{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(he.X,{className:"h-4 w-4"}),c.jsx("span",{className:"sr-only",children:"Close"})]})]})]})});nf.displayName=Os.displayName;const rf=({className:e,...t})=>c.jsx("div",{className:re("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});rf.displayName="DialogHeader";const of=m.forwardRef(({className:e,...t},n)=>c.jsx(mr,{ref:n,className:re("text-lg font-semibold leading-none tracking-tight",e),...t}));of.displayName=mr.displayName;const Cw=m.forwardRef(({className:e,...t},n)=>c.jsx(Ms,{ref:n,className:re("text-sm text-muted-foreground",e),...t}));Cw.displayName=Ms.displayName;function kw({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}=wa(),h=w.useCallback(async()=>{if(n){i(!0),d(null),l(null);try{const y=await dd(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 rb(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 dd(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(he.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(Ve,{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(he.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(he.Image,{className:"h-5 w-5"}):c.jsx(he.FileText,{className:"h-5 w-5"});return c.jsx(ww,{open:e,onOpenChange:t,children:c.jsxs(nf,{className:"max-w-4xl max-h-[90vh] overflow-hidden",children:[c.jsx(rf,{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(of,{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(Ve,{variant:"outline",size:"sm",onClick:v,className:"flex items-center gap-2",children:[c.jsx(he.ExternalLink,{className:"h-4 w-4"}),"External"]}),c.jsxs(Ve,{variant:"outline",size:"sm",onClick:p,className:"flex items-center gap-2",children:[c.jsx(he.Download,{className:"h-4 w-4"}),"Download"]})]})]})}),c.jsx("div",{className:"flex-1 overflow-hidden",children:x()})]})})}function sf(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 af(e){return!!(e&&typeof e=="object"&&(e.type==="file"||e.mimeType||e.filename||e.sourceType==="base64"))}function xo(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(xo).filter(r=>r!==void 0);if(!n.length){console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined",{originalLength:e.length});return}return n}if(af(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=xo(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 Ds(e){if(typeof e=="string")return e;if(af(e))return"";try{const t=xo(e);return t===void 0?"":typeof t=="string"?t:JSON.stringify(t,null,2)}catch{return""}}function lf(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 lf(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 Ls="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",gr=1e5;function Tw(e){return e.filter(t=>t.type==="text").map(t=>t.text).join("")}function Ew(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 Iw(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 Fs(e){if(e==null)return null;const t=String(e).trim();return t.length>0?t:null}function Aw(e){const t=(r,o=gr)=>{try{const s=xo(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 Nw(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 _w(e){return e.name&&e.name.trim()?e.name:e.model&&e.model.includes("/")?e.model.split("/").pop()||null:e.model||null}function cf(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 jw({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:re("inline-block text-xs opacity-70 ml-1",e),children:["Is thinking",".".repeat(t)]})}const uf=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,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:E,onInterruptActionEnd:k}){const[T,I]=w.useState(!1),[_,O]=w.useState("preview"),[j,U]=w.useState(!1),{currentThreadId:L}=Xo(),{respondToInterrupt:W}=Jo(),R=l==="phone"||l==="half-screen",V=t.role,$=V==="tool",ne=!(r&&V!=="user"),{uploadingFiles:F,handleFileClick:B,fileViewerOpen:le,currentFileInfo:z,closeFileViewer:oe}=Dw({allowFileOpen:ne,currentThreadId:L}),pe=w.useMemo(()=>{switch(V){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))]"}},[V]),ge=w.useMemo(()=>Tw(t.content),[t.content]),me=w.useMemo(()=>Ew(t.content),[t.content]),ve=w.useMemo(()=>t.content.filter(G=>G.type==="image_url"),[t.content]),Z=w.useMemo(()=>t.content.filter(G=>G.type==="file"),[t.content]),D=w.useMemo(()=>t.content.filter(G=>G.type==="interrupt"),[t.content]),J=(b==null?void 0:b.id)??(b==null?void 0:b.interrupt_id),Q=Fs(J),de=b==null?void 0:b.value,ee=w.useMemo(()=>Aw(t.content),[t.content]);w.useMemo(()=>Nw(t.content),[t.content]);const se=w.useMemo(()=>ee.length<=gr?ee:`${ee.slice(0,gr)}
|
|
129
|
+
… [truncated ${ee.length-gr} chars]`,[ee]),Ge=w.useCallback(async(G="all")=>{const ye=G==="visible"&&$?se:$?ee:ge;async function Ie(Je){try{await navigator.clipboard.writeText(Je)}catch{try{const Ze=document.createElement("textarea");Ze.value=Je,Ze.setAttribute("readonly",""),Ze.style.position="absolute",Ze.style.left="-9999px",document.body.appendChild(Ze),Ze.select(),document.execCommand("copy"),document.body.removeChild(Ze)}catch(Ze){throw console.error("Failed to copy:",Ze),Ze}}}try{await Ie(ye),I(!0),setTimeout(()=>I(!1),2e3),y==null||y(ye)}catch(Je){console.error("Failed to copy:",Je)}},[$,ee,ge,se,y]),Ye=w.useCallback(()=>{if(!v)return;const G=$?ee:ge;v(t.id,G)},[v,t.id,$,ee,ge]),Pe=w.useCallback(()=>{x==null||x(n)},[x,n]),He=w.useCallback(()=>{const be=re(R?"h-3 w-3":"h-4 w-4","opacity-60 flex-shrink-0",pe);switch(V){case"user":return c.jsx(he.User,{className:be});case"assistant":return c.jsx(he.Bot,{className:be});case"tool":return c.jsx(he.Wrench,{className:be});default:return c.jsx(he.Bot,{className:be})}},[R,pe,V]),nt=w.useCallback(()=>{const G="group relative mb-4 flex w-full";switch(V){case"user":return re(G,"justify-end");case"assistant":case"tool":case"system":return re(G,"justify-start");default:return G}},[V]),Qe=w.useCallback(()=>{const G=re("rounded-lg px-4 py-3 relative min-w-0 max-w-full break-words",R&&"px-3 py-2 text-sm");switch(V){case"user":return re(G,"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 re(G,"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 re(G,"w-full md:max-w-[95%] bg-secondary/50 text-secondary-foreground border border-dashed");case"system":return re(G,"w-full md:max-w-[85%] bg-accent/40 text-muted-foreground border");default:return re(G,"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")}},[R,V]),je=w.useCallback(async G=>{if(S)return;const be=Fs((G==null?void 0:G.id)??(G==null?void 0:G.interrupt_id));if(!be){console.warn("Interrupt part missing id",G);return}try{E==null||E(),await W(be,!0)}catch(ye){console.error("Failed to approve interrupt:",ye)}finally{k==null||k()}},[S,k,E,W]),pt=w.useCallback(async G=>{if(S)return;const be=Fs((G==null?void 0:G.id)??(G==null?void 0:G.interrupt_id));if(!be){console.warn("Interrupt part missing id",G);return}try{E==null||E(),await W(be,!1)}catch(ye){console.error("Failed to reject interrupt:",ye)}finally{k==null||k()}},[S,k,E,W]),xt=w.useCallback(({part:G,i:be})=>{if(G.type==="text"){const ye=G.text??"",Ie=ye.trim(),Je=sf(Ie);return Je&&V!=="tool"?c.jsx(Rw,{data:Je},be):V==="user"&&f&&Ie.length>h?c.jsx(Lw,{text:Ie,expanded:j,onExpandedChange:U,previewLength:h,isCompact:R},be):c.jsx(ya,{content:ye,allowHtml:!1},be)}if(G.type==="image_url"){const ye=G;return c.jsx("div",{className:"my-2",children:c.jsx("img",{src:ye.url,alt:ye.alt??"",loading:"lazy",className:"border rounded max-h-[420px] w-auto object-contain"})},be)}if(G.type==="file"){const ye=G,Ie=ye.name||"file";return c.jsxs("a",{href:ye.url,onClick:Je=>B(Je,ye,be),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:[F[be]?c.jsx(he.Loader,{className:"h-4 w-4 animate-spin"}):null,c.jsxs("span",{className:"truncate max-w-[180px]",children:[Ie,F[be]?" (processing)":""]})]},be)}if(G.type==="interrupt"){const ye=G,Ie=Fs((ye==null?void 0:ye.id)??(ye==null?void 0:ye.interrupt_id)),Je=!!(Q&&Ie&&Ie===Q),Ze=Je?de??(ye==null?void 0:ye.value):ye==null?void 0:ye.value,kt=Ie?{...ye,id:Ie,interrupt_id:Ie}:ye;return c.jsx(Ow,{interruptPart:kt,onApprove:je,onReject:pt,disabled:S,isActive:Je,payload:Ze},be)}return null},[B,F,je,pt,V,f,h,j,R,Q,de,b,S,D]),yt=w.useCallback(()=>c.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted/30 rounded",children:[c.jsx(he.Paperclip,{className:"h-4 w-4 text-muted-foreground"}),c.jsx("span",{className:"text-sm text-muted-foreground",children:"File upload"})]}),[]),st=w.useCallback(()=>{const G=ge.trim().length>0||ve.length>0||Z.length>0||D.length>0;if(!$&&!G&&!r)return yt();if(t.model==="reflection"){const be=ge.trim(),ye=sf(be);if(ye&&typeof ye=="object")return c.jsx(Mw,{data:ye})}if($&&me.name==="get_issues"){const be=t.content.find(Je=>Je.type==="tool_end"),ye=(be==null?void 0:be.output)??ee,Ie=lf(ye);if(Ie)return c.jsx($w,{issues:Ie})}if($)return c.jsx(Fw,{message:t,viewMode:_,truncate:u,previewChars:d},t.id);if(!$){const be=c.jsx("div",{className:"space-y-2",children:t.content.map((ye,Ie)=>c.jsx(xt,{part:ye,i:Ie},Ie))});return r?c.jsxs("div",{"aria-busy":"true",role:"status",children:[be,c.jsx(jw,{className:pe})]}):be}},[ge,ve.length,Z.length,D.length,r,t.model,$,me.name,ee,_,u,d,yt,pe]),Xe=w.useMemo(()=>_w(t),[t]);return c.jsxs(c.Fragment,{children:[c.jsx("div",{className:re(nt(),p.container),children:c.jsxs("div",{className:re(Qe(),p.content),children:[(i||a||$)&&c.jsxs("div",{className:re("flex items-center justify-between mb-2 pb-2 border-b border-current/10",R&&"mb-1 pb-1",pe,p.header),children:[c.jsxs("div",{className:"flex items-center gap-2",children:[He(),a&&Xe&&c.jsx("span",{className:re("font-medium",R?"text-xs":"text-sm"),children:Xe}),$&&c.jsxs(Uu,{variant:"outline",className:re("text-xs flex items-center gap-1 cursor-pointer select-none",pe,"border border-current/40",R&&"text-xs h-4"),role:"button",tabIndex:0,"aria-expanded":_==="expanded",onClick:()=>O(G=>G==="expanded"?"preview":"expanded"),onKeyDown:G=>{(G.key==="Enter"||G.key===" ")&&(G.preventDefault(),O(be=>be==="expanded"?"preview":"expanded"))},children:[c.jsx("span",{children:me.name??"Tool Output"}),me.toolCallId&&c.jsx("span",{className:"opacity-70",children:me.toolCallId.slice(0,8)}),_==="expanded"?c.jsx(he.ChevronUp,{className:"h-3 w-3"}):c.jsx(he.ChevronDown,{className:"h-3 w-3"})]})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[i&&t.createdAt&&c.jsx("time",{className:re("text-xs opacity-60",pe,R&&"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:re("opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[c.jsxs("div",{className:"relative",children:[c.jsx(Ve,{variant:"ghost",size:"sm",onClick:()=>Ge($?"visible":"all"),className:re("h-6 w-6 p-0 hover:bg-foreground/10",pe,R&&"h-5 w-5"),"aria-label":$?"Copy visible":"Copy message",title:$?"Copy visible portion":"Copy message",children:c.jsx(he.Copy,{className:re(T?"text-success":pe,R?"h-3 w-3":"h-4 w-4")})}),$&&c.jsx(Ve,{variant:"ghost",size:"sm",onClick:()=>Ge("all"),className:re("h-6 px-1 text-xs hover:bg-foreground/10",pe),"aria-label":"Copy all (may be large)",title:"Copy all (may be large)",children:"all"})]}),V==="user"&&v&&c.jsx(Ve,{variant:"ghost",size:"sm",onClick:Ye,className:re("h-6 w-6 p-0 hover:bg-foreground/10",pe,R&&"h-5 w-5"),"aria-label":"Edit message",children:c.jsx(he.Edit,{className:re(pe,R?"h-3 w-3":"h-4 w-4")})}),V==="assistant"&&x&&c.jsx(Ve,{variant:"ghost",size:"sm",onClick:Pe,className:re("h-6 w-6 p-0 hover:bg-foreground/10",pe,R&&"h-5 w-5"),"aria-label":"Regenerate response",children:c.jsx(he.RotateCcw,{className:re(pe,R?"h-3 w-3":"h-4 w-4")})})]})]})]}),c.jsx("div",{className:"relative",children:st()}),$&&_==="expanded"&&(me.toolCallId||me.name)&&c.jsxs("div",{className:re("mt-2 pt-2 border-t border-current/10 text-xs opacity-60",R&&"text-xs"),children:[me.name&&c.jsxs("div",{children:["Function: ",me.name]}),me.toolCallId&&c.jsxs("div",{children:["Call ID: ",me.toolCallId]})]}),!(i||a||$)&&s&&!o&&c.jsxs("div",{className:re("absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity","flex items-center gap-1",p.actions),children:[c.jsx(Ve,{variant:"ghost",size:"sm",onClick:()=>Ge(),className:re("h-6 w-6 p-0 hover:bg-background/50 text-current",R&&"h-5 w-5"),children:c.jsx(he.Copy,{className:re(T?"text-success":"text-current",R?"h-3 w-3":"h-4 w-4")})}),V==="user"&&v&&c.jsx(Ve,{variant:"ghost",size:"sm",onClick:Ye,className:re("h-6 w-6 p-0 hover:bg-background/50 text-current",R&&"h-5 w-5"),children:c.jsx(he.Edit,{className:re("text-current",R?"h-3 w-3":"h-4 w-4")})}),V==="assistant"&&x&&c.jsx(Ve,{variant:"ghost",size:"sm",onClick:Pe,className:re("h-6 w-6 p-0 hover:bg-background/50 text-current",R&&"h-5 w-5"),children:c.jsx(he.RotateCcw,{className:re("text-current",R?"h-3 w-3":"h-4 w-4")})})]})]})}),z&&c.jsx(kw,{isOpen:le,onClose:oe,fileId:z.id,fileName:z.name,mimeType:z.mimeType})]})},(e,t)=>{var i,a,l,u,d,f,h,p;if(t.isStreamingMessage||e.isStreamingMessage||!(e.message.id===t.message.id&&cf(e.message)===cf(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 Rw({data:e}){if(Array.isArray(e))return e.every(n=>n===null||["string","number","boolean"].includes(typeof n))?c.jsx("div",{className:Ls,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:Ds(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:Ls,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:Ls,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:Pw(i)})]},s))})})}return c.jsx("pre",{className:"font-mono text-xs bg-background/50 rounded border p-2 whitespace-pre-wrap break-words",children:Ds(e)})}function Pw(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 Ow({interruptPart:e,onApprove:t,onReject:n,disabled:r,isActive:o,payload:s}){const i=e.title??"Approve the result?";let a=null;if(s!=null)if(typeof s=="string")a=c.jsx("p",{className:"text-sm leading-relaxed text-blue-800/90 dark:text-blue-200/90 whitespace-pre-wrap",children:s});else{const u=Ds(s);a=c.jsx("pre",{className:"max-h-48 overflow-auto rounded bg-blue-100/60 p-2 text-xs text-blue-900/90 dark:bg-blue-900/40 dark:text-blue-100/80",children:u})}const l=o?"Please approve or reject this action to resume the workflow.":"Waiting for approval from another participant.";return c.jsxs(fo,{className:re("border-blue-200 dark:border-blue-800 bg-blue-50/50 dark:bg-blue-950/10 transition-shadow",o?"shadow-md ring-1 ring-blue-300 dark:ring-blue-500/70":"opacity-80"),children:[c.jsxs(ho,{className:"pb-3",children:[c.jsx(po,{className:"text-blue-900 dark:text-blue-100 text-base",children:i}),c.jsx(Yu,{className:"text-blue-700 dark:text-blue-300 text-sm",children:l})]}),a&&c.jsx(mo,{className:"pt-0 pb-3",children:a}),c.jsx(Xu,{className:"pt-0",children:c.jsxs("div",{className:"flex gap-2 ml-auto",children:[c.jsx(Ve,{size:"sm",variant:"outline",onClick:()=>n(e),className:"border-red-300 text-red-700 hover:bg-red-50 dark:border-red-700 dark:text-red-300 dark:hover:bg-red-950/50",disabled:r||!o,children:"Reject"}),c.jsx(Ve,{size:"sm",onClick:()=>t(e),className:"bg-blue-600 hover:bg-blue-700 text-white",disabled:r||!o,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 Dw(e){const{allowFileOpen:t,currentThreadId:n}=e,{toast:r}=wa(),[o,s]=w.useState({}),[i,a]=w.useState(null),[l,u]=w.useState(!1),d=w.useCallback(()=>{u(!1),a(null)},[]),f=w.useCallback(p=>{a(p),u(!0)},[]),h=w.useCallback(async(p,v,x)=>{var g,y;if(!t){p.preventDefault();return}if(o[x]){p.preventDefault();return}try{const b=String(v.url??""),S=b.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);if(S){p.preventDefault();const E=S[1],k=v.name||`file_${E}`,T=v.mimeType||"application/octet-stream";f({id:E,name:k,mimeType:T});return}if(b.startsWith("data:")){p.preventDefault(),s(k=>({...k,[x]:!0}));const E=r({title:"Fetching file...",description:"",open:!0});try{const k=await ob(n??void 0);if(!k||!Array.isArray(k))throw new Error("Invalid file list response");const T=k.find(I=>!I||typeof I!="object"||!((I.filename??"")===(v.name??""))?!1:typeof v.size=="number"&&typeof I.size=="number"?I.size===v.size:!0);if(!(T!=null&&T.id))throw new Error(`File "${v.name}" is not yet available on the server`);if(!T.id||!T.filename)throw new Error("Invalid file data received from server");f({id:T.id,name:v.name||T.filename||`file_${T.id}`,mimeType:v.mimeType||T.mime_type||"application/octet-stream"}),(g=E.update)==null||g.call(E,{id:E.id,title:"Success",description:`Opened ${v.name}`,open:!0})}catch(k){console.error("Failed to fetch server file:",k);const T=k instanceof Error?k.message:"Unknown error occurred";(y=E.update)==null||y.call(E,{id:E.id,title:"Failed",description:T}),r({title:"Failed to fetch file",description:T,open:!0})}finally{s(k=>({...k,[x]:!1}))}}}catch(b){console.error("File click error:",b),s(S=>({...S,[x]:!1}))}},[t,o,r,n,f]);return{uploadingFiles:o,handleFileClick:h,fileViewerOpen:l,currentFileInfo:i,closeFileViewer:d}}function Lw({text:e,expanded:t,onExpandedChange:n,previewLength:r,isCompact:o}){return c.jsxs(Fv,{open:t,onOpenChange:n,children:[c.jsx("div",{className:re("text-sm text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:t?c.jsx(ya,{content:e,allowHtml:!1}):c.jsxs("pre",{className:re("font-sans whitespace-pre-wrap break-words bg-transparent p-0 m-0 text-[hsl(var(--chat-bubble-user-text))]",o&&"text-xs"),children:[e.substring(0,r),"..."]})}),c.jsx($v,{asChild:!0,children:c.jsx(Ve,{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(he.ChevronUp,{className:"h-3 w-3 mr-1"})," Show less"]}):c.jsxs(c.Fragment,{children:[c.jsx(he.ChevronDown,{className:"h-3 w-3 mr-1"})," Show more (",e.length-r," chars)"]})})})]})}function Fw({message:e,viewMode:t,truncate:n,previewChars:r}){const o=Iw(e.content);if(!(t==="expanded"||!n)||o.length===0)return null;const i=t==="expanded"?gr:Math.min(r??gr,gr);return c.jsx("div",{className:"space-y-3",children:o.map((a,l)=>{const u=typeof a.output=="string"?a.output:Ds(a.output),d=u.length>i?`${u.slice(0,i)}
|
|
131
|
+
… [truncated ${u.length-i} chars]`:u;return c.jsxs("div",{className:"space-y-1",children:[c.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[c.jsx("span",{children:a.name??"tool"}),a.toolCallId&&c.jsxs("span",{children:["• ",a.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:d})})]},a.toolCallId??l)})})}function $w({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:Ls,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 df=(e,t)=>(e==null?void 0:e.id)??`message-${t}`,Da=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,activeInterrupt:b,disableInterruptActions:S=!1,onInterruptActionStart:E,onInterruptActionEnd:k},T)=>{const I=w.useRef(null),_=w.useRef(null),O=w.useRef(!1),[j,U]=w.useState(!0),L=w.useMemo(()=>b?e.some(F=>Array.isArray(F==null?void 0:F.content)&&F.content.some(B=>B&&B.type==="interrupt"&&(B.id??B.interrupt_id)===b.id)):!1,[b,e]),W=w.useMemo(()=>{if(!b||L)return null;const F=b.id&&String(b.id).trim()?String(b.id).trim():"pending-interrupt";let B;const le=b.value;if(le&&typeof le=="object"&&!Array.isArray(le)){const z=le.title;typeof z=="string"&&z.trim()&&(B=z.trim())}return{id:`interrupt-${F}`,role:"system",createdAt:new Date().toISOString(),content:[{type:"interrupt",id:F,value:le,title:B}]}},[b,L]),R=w.useMemo(()=>W?[...e,W]:e,[e,W]),V=w.useCallback(F=>{U(F),g&&g(!F),y&&y(F)},[g,y]),$=w.useMemo(()=>{if(a)return async()=>{if(!O.current){O.current=!0;try{await a()}finally{O.current=!1}}}},[a]),ne=w.useMemo(()=>!v||x?!1:j?"auto":!1,[j,v,x]);return R.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(iv,{ref:F=>{I.current=F},scrollerRef:F=>{_.current=F instanceof HTMLDivElement?F:null},data:R,followOutput:ne,overscan:200,increaseViewportBy:{top:100,bottom:200},defaultItemHeight:80,atBottomThreshold:50,alignToBottom:!1,startReached:()=>{$&&$()},atBottomStateChange:V,style:{height:"100%",overscrollBehavior:"contain"},computeItemKey:(F,B)=>df(B,F),itemContent:(F,B)=>{const le=df(B,F);return c.jsx("div",{className:"mb-4 last:mb-0","data-message-id":le,style:{minHeight:"60px",containIntrinsicSize:"auto 120px"},children:c.jsx(uf,{message:B,messageIndex:F,isStreamingMessage:t&&n===B.id,streamingDebounceMs:r,isEditing:i===B.id,showActions:s,showTimestamp:!1,showAgentName:!0,layoutSize:o,truncateToolMessages:!1,toolMessagePreviewLength:200,onEdit:l,onRegenerate:()=>u(F),onCancelEdit:d,activeInterrupt:b,disableInterruptActions:S,onInterruptActionStart:E,onInterruptActionEnd:k})})}})})});Da.displayName="MessageList";const $s=1e4;function zw(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,`
|
|
131
132
|
`).replace(/<p>(.*?)<\/p>/gi,`$1
|
|
132
133
|
|
|
133
134
|
`).replace(/<h([1-6])>(.*?)<\/h[1-6]>/gi,(o,s,i)=>`${"#".repeat(parseInt(s))} ${i}
|
|
@@ -135,4 +136,4 @@ For more information, see https://radix-ui.com/primitives/docs/components/${t.do
|
|
|
135
136
|
`).replace(/<ul>/gi,"").replace(/<\/ul>/gi,`
|
|
136
137
|
`).replace(/<ol>/gi,"").replace(/<\/ol>/gi,`
|
|
137
138
|
`).replace(/<li>(.*?)<\/li>/gi,`- $1
|
|
138
|
-
`).trim():n.replace(/</g,"<").replace(/>/g,">").trim()}function Fw(e,t=$s){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 $w(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),Fw(t),Lw(t)}function La(e){const t=e+"CollectionProvider",[n,r]=Cn(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=x=>{const{scope:g,children:y}=x,b=w.useRef(null),C=w.useRef(new Map).current;return c.jsx(o,{scope:g,itemMap:C,collectionRef:b,children:y})};i.displayName=t;const a=e+"CollectionSlot",l=or.createSlot(a),u=w.forwardRef((x,g)=>{const{scope:y,children:b}=x,C=s(a,y),E=We(g,C.collectionRef);return c.jsx(l,{ref:E,children:b})});u.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=or.createSlot(d),p=w.forwardRef((x,g)=>{const{scope:y,children:b,...C}=x,E=w.useRef(null),k=We(g,E),T=s(d,y);return w.useEffect(()=>(T.itemMap.set(E,{ref:E,...C}),()=>void T.itemMap.delete(E))),c.jsx(h,{[f]:"",ref:k,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 C=Array.from(b.querySelectorAll(`[${f}]`));return Array.from(g.itemMap.values()).sort((T,I)=>C.indexOf(T.ref.current)-C.indexOf(I.ref.current))},[g.collectionRef,g.itemMap])}return[{Provider:i,Slot:u,ItemSlot:p},v,r]}var zw=m.createContext(void 0);function zs(e){const t=m.useContext(zw);return e||t||"ltr"}const Bw=["top","right","bottom","left"],Xn=Math.min,Yt=Math.max,Bs=Math.round,Hs=Math.floor,En=e=>({x:e,y:e}),Hw={left:"right",right:"left",bottom:"top",top:"bottom"},Uw={start:"end",end:"start"};function Fa(e,t,n){return Yt(e,Xn(t,n))}function Ln(e,t){return typeof e=="function"?e(t):e}function Fn(e){return e.split("-")[0]}function Dr(e){return e.split("-")[1]}function $a(e){return e==="x"?"y":"x"}function za(e){return e==="y"?"height":"width"}const Ww=new Set(["top","bottom"]);function In(e){return Ww.has(Fn(e))?"y":"x"}function Ba(e){return $a(In(e))}function Vw(e,t,n){n===void 0&&(n=!1);const r=Dr(e),o=Ba(e),s=za(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Us(i)),[i,Us(i)]}function Kw(e){const t=Us(e);return[Ha(e),t,Ha(t)]}function Ha(e){return e.replace(/start|end/g,t=>Uw[t])}const ff=["left","right"],hf=["right","left"],qw=["top","bottom"],Gw=["bottom","top"];function Yw(e,t,n){switch(e){case"top":case"bottom":return n?t?hf:ff:t?ff:hf;case"left":case"right":return t?qw:Gw;default:return[]}}function Xw(e,t,n,r){const o=Dr(e);let s=Yw(Fn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Ha)))),s}function Us(e){return e.replace(/left|right|bottom|top/g,t=>Hw[t])}function Jw(e){return{top:0,right:0,bottom:0,left:0,...e}}function pf(e){return typeof e!="number"?Jw(e):{top:e,right:e,bottom:e,left:e}}function Ws(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 mf(e,t,n){let{reference:r,floating:o}=e;const s=In(t),i=Ba(t),a=za(i),l=Fn(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(Dr(t)){case"start":p[i]-=h*(n&&u?-1:1);break;case"end":p[i]+=h*(n&&u?-1:1);break}return p}const Zw=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}=mf(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:C,data:E,reset:k}=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=C??f,p={...p,[g]:{...p[g],...E}},k&&v<=50&&(v++,typeof k=="object"&&(k.placement&&(h=k.placement),k.rects&&(u=k.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):k.rects),{x:d,y:f}=mf(u,h,l)),x=-1)}return{x:d,y:f,placement:h,strategy:o,middlewareData:p}};async function xo(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}=Ln(t,e),v=pf(p),g=a[h?f==="floating"?"reference":"floating":f],y=Ws(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,C=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),E=await(s.isElement==null?void 0:s.isElement(C))?await(s.getScale==null?void 0:s.getScale(C))||{x:1,y:1}:{x:1,y:1},k=Ws(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:C,strategy:l}):b);return{top:(y.top-k.top+v.top)/E.y,bottom:(k.bottom-y.bottom+v.bottom)/E.y,left:(y.left-k.left+v.left)/E.x,right:(k.right-y.right+v.right)/E.x}}const Qw=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}=Ln(e,t)||{};if(u==null)return{};const f=pf(d),h={x:n,y:r},p=Ba(o),v=za(p),x=await i.getDimensions(u),g=p==="y",y=g?"top":"left",b=g?"bottom":"right",C=g?"clientHeight":"clientWidth",E=s.reference[v]+s.reference[p]-h[p]-s.floating[v],k=h[p]-s.reference[p],T=await(i.getOffsetParent==null?void 0:i.getOffsetParent(u));let I=T?T[C]:0;(!I||!await(i.isElement==null?void 0:i.isElement(T)))&&(I=a.floating[C]||s.floating[v]);const _=E/2-k/2,P=I/2-x[v]/2-1,j=Xn(f[y],P),H=Xn(f[b],P),F=j,U=I-x[v]-H,D=I/2-x[v]/2+_,G=Fa(F,D,U),W=!l.arrow&&Dr(o)!=null&&D!==G&&s.reference[v]/2-(D<F?j:H)-x[v]/2<0,ne=W?D<F?D-F:D-U:0;return{[p]:h[p]+ne,data:{[p]:G,centerOffset:D-G-ne,...W&&{alignmentOffset:ne}},reset:W}}}),e0=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}=Ln(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const y=Fn(o),b=In(a),C=Fn(a)===a,E=await(l.isRTL==null?void 0:l.isRTL(u.floating)),k=h||(C||!x?[Us(a)]:Kw(a)),T=v!=="none";!h&&T&&k.push(...Xw(a,x,v,E));const I=[a,...k],_=await xo(t,g),P=[];let j=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&P.push(_[y]),f){const D=Vw(o,i,E);P.push(_[D[0]],_[D[1]])}if(j=[...j,{placement:o,overflows:P}],!P.every(D=>D<=0)){var H,F;const D=(((H=s.flip)==null?void 0:H.index)||0)+1,G=I[D];if(G&&(!(f==="alignment"?b!==In(G):!1)||j.every($=>In($.placement)===b?$.overflows[0]>0:!0)))return{data:{index:D,overflows:j},reset:{placement:G}};let W=(F=j.filter(ne=>ne.overflows[0]<=0).sort((ne,$)=>ne.overflows[1]-$.overflows[1])[0])==null?void 0:F.placement;if(!W)switch(p){case"bestFit":{var U;const ne=(U=j.filter($=>{if(T){const z=In($.placement);return z===b||z==="y"}return!0}).map($=>[$.placement,$.overflows.filter(z=>z>0).reduce((z,se)=>z+se,0)]).sort(($,z)=>$[1]-z[1])[0])==null?void 0:U[0];ne&&(W=ne);break}case"initialPlacement":W=a;break}if(o!==W)return{reset:{placement:W}}}return{}}}};function gf(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function xf(e){return Bw.some(t=>e[t]>=0)}const t0=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=Ln(e,t);switch(r){case"referenceHidden":{const s=await xo(t,{...o,elementContext:"reference"}),i=gf(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:xf(i)}}}case"escaped":{const s=await xo(t,{...o,altBoundary:!0}),i=gf(s,n.floating);return{data:{escapedOffsets:i,escaped:xf(i)}}}default:return{}}}}},yf=new Set(["left","top"]);async function n0(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=Fn(n),a=Dr(n),l=In(n)==="y",u=yf.has(i)?-1:1,d=s&&l?-1:1,f=Ln(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 r0=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 n0(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}}}}},o0=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}=Ln(e,t),u={x:n,y:r},d=await xo(t,l),f=In(Fn(o)),h=$a(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],C=p-d[y];p=Fa(b,p,C)}if(i){const g=f==="y"?"top":"left",y=f==="y"?"bottom":"right",b=v+d[g],C=v-d[y];v=Fa(b,v,C)}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}}}}}},s0=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}=Ln(e,t),d={x:n,y:r},f=In(o),h=$a(f);let p=d[h],v=d[f];const x=Ln(a,t),g=typeof x=="number"?{mainAxis:x,crossAxis:0}:{mainAxis:0,crossAxis:0,...x};if(l){const C=h==="y"?"height":"width",E=s.reference[h]-s.floating[C]+g.mainAxis,k=s.reference[h]+s.reference[C]-g.mainAxis;p<E?p=E:p>k&&(p=k)}if(u){var y,b;const C=h==="y"?"width":"height",E=yf.has(Fn(o)),k=s.reference[f]-s.floating[C]+(E&&((y=i.offset)==null?void 0:y[f])||0)+(E?0:g.crossAxis),T=s.reference[f]+s.reference[C]+(E?0:((b=i.offset)==null?void 0:b[f])||0)-(E?g.crossAxis:0);v<k?v=k:v>T&&(v=T)}return{[h]:p,[f]:v}}}},i0=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}=Ln(e,t),d=await xo(t,u),f=Fn(o),h=Dr(o),p=In(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,C=v-d.left-d.right,E=Xn(x-d[g],b),k=Xn(v-d[y],C),T=!t.middlewareData.shift;let I=E,_=k;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(_=C),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(I=b),T&&!h){const j=Yt(d.left,0),H=Yt(d.right,0),F=Yt(d.top,0),U=Yt(d.bottom,0);p?_=v-2*(j!==0||H!==0?j+H:Yt(d.left,d.right)):I=x-2*(F!==0||U!==0?F+U:Yt(d.top,d.bottom))}await l({...t,availableWidth:_,availableHeight:I});const P=await i.getDimensions(a.floating);return v!==P.width||x!==P.height?{reset:{rects:!0}}:{}}}};function Vs(){return typeof window<"u"}function Lr(e){return vf(e)?(e.nodeName||"").toLowerCase():"#document"}function Xt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function An(e){var t;return(t=(vf(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function vf(e){return Vs()?e instanceof Node||e instanceof Xt(e).Node:!1}function hn(e){return Vs()?e instanceof Element||e instanceof Xt(e).Element:!1}function Nn(e){return Vs()?e instanceof HTMLElement||e instanceof Xt(e).HTMLElement:!1}function bf(e){return!Vs()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Xt(e).ShadowRoot}const a0=new Set(["inline","contents"]);function yo(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=pn(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!a0.has(o)}const l0=new Set(["table","td","th"]);function c0(e){return l0.has(Lr(e))}const u0=[":popover-open",":modal"];function Ks(e){return u0.some(t=>{try{return e.matches(t)}catch{return!1}})}const d0=["transform","translate","scale","rotate","perspective"],f0=["transform","translate","scale","rotate","perspective","filter"],h0=["paint","layout","strict","content"];function Ua(e){const t=Wa(),n=hn(e)?pn(e):e;return d0.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)||f0.some(r=>(n.willChange||"").includes(r))||h0.some(r=>(n.contain||"").includes(r))}function p0(e){let t=Jn(e);for(;Nn(t)&&!Fr(t);){if(Ua(t))return t;if(Ks(t))return null;t=Jn(t)}return null}function Wa(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const m0=new Set(["html","body","#document"]);function Fr(e){return m0.has(Lr(e))}function pn(e){return Xt(e).getComputedStyle(e)}function qs(e){return hn(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Jn(e){if(Lr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||bf(e)&&e.host||An(e);return bf(t)?t.host:t}function wf(e){const t=Jn(e);return Fr(t)?e.ownerDocument?e.ownerDocument.body:e.body:Nn(t)&&yo(t)?t:wf(t)}function vo(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=wf(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Xt(o);if(s){const a=Va(i);return t.concat(i,i.visualViewport||[],yo(o)?o:[],a&&n?vo(a):[])}return t.concat(o,vo(o,[],n))}function Va(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Sf(e){const t=pn(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=Nn(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=Bs(n)!==s||Bs(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Ka(e){return hn(e)?e:e.contextElement}function $r(e){const t=Ka(e);if(!Nn(t))return En(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Sf(t);let i=(s?Bs(n.width):n.width)/r,a=(s?Bs(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const g0=En(0);function Cf(e){const t=Xt(e);return!Wa()||!t.visualViewport?g0:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function x0(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Xt(e)?!1:t}function xr(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Ka(e);let i=En(1);t&&(r?hn(r)&&(i=$r(r)):i=$r(e));const a=x0(s,n,r)?Cf(s):En(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=Xt(s),p=r&&hn(r)?Xt(r):r;let v=h,x=Va(v);for(;x&&r&&p!==v;){const g=$r(x),y=x.getBoundingClientRect(),b=pn(x),C=y.left+(x.clientLeft+parseFloat(b.paddingLeft))*g.x,E=y.top+(x.clientTop+parseFloat(b.paddingTop))*g.y;l*=g.x,u*=g.y,d*=g.x,f*=g.y,l+=C,u+=E,v=Xt(x),x=Va(v)}}return Ws({width:d,height:f,x:l,y:u})}function Gs(e,t){const n=qs(e).scrollLeft;return t?t.left+n:xr(An(e)).left+n}function kf(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Gs(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function y0(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=An(r),a=t?Ks(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},u=En(1);const d=En(0),f=Nn(r);if((f||!f&&!s)&&((Lr(r)!=="body"||yo(i))&&(l=qs(r)),Nn(r))){const p=xr(r);u=$r(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const h=i&&!f&&!s?kf(i,l):En(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 v0(e){return Array.from(e.getClientRects())}function b0(e){const t=An(e),n=qs(e),r=e.ownerDocument.body,o=Yt(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Yt(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Gs(e);const a=-n.scrollTop;return pn(r).direction==="rtl"&&(i+=Yt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const Tf=25;function w0(e,t){const n=Xt(e),r=An(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const d=Wa();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const u=Gs(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<=Tf&&(s-=v)}else u<=Tf&&(s+=u);return{width:s,height:i,x:a,y:l}}const S0=new Set(["absolute","fixed"]);function C0(e,t){const n=xr(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=Nn(e)?$r(e):En(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 Ef(e,t,n){let r;if(t==="viewport")r=w0(e,n);else if(t==="document")r=b0(An(e));else if(hn(t))r=C0(t,n);else{const o=Cf(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Ws(r)}function If(e,t){const n=Jn(e);return n===t||!hn(n)||Fr(n)?!1:pn(n).position==="fixed"||If(n,t)}function k0(e,t){const n=t.get(e);if(n)return n;let r=vo(e,[],!1).filter(a=>hn(a)&&Lr(a)!=="body"),o=null;const s=pn(e).position==="fixed";let i=s?Jn(e):e;for(;hn(i)&&!Fr(i);){const a=pn(i),l=Ua(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&S0.has(o.position)||yo(i)&&!l&&If(e,i))?r=r.filter(d=>d!==i):o=a,i=Jn(i)}return t.set(e,r),r}function T0(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Ks(t)?[]:k0(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((u,d)=>{const f=Ef(t,d,o);return u.top=Yt(f.top,u.top),u.right=Xn(f.right,u.right),u.bottom=Xn(f.bottom,u.bottom),u.left=Yt(f.left,u.left),u},Ef(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function E0(e){const{width:t,height:n}=Sf(e);return{width:t,height:n}}function I0(e,t,n){const r=Nn(t),o=An(t),s=n==="fixed",i=xr(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=En(0);function u(){l.x=Gs(o)}if(r||!r&&!s)if((Lr(t)!=="body"||yo(o))&&(a=qs(t)),r){const p=xr(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?kf(o,a):En(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 qa(e){return pn(e).position==="static"}function Af(e,t){if(!Nn(e)||pn(e).position==="fixed")return null;if(t)return t(e);let n=e.offsetParent;return An(e)===n&&(n=n.ownerDocument.body),n}function Nf(e,t){const n=Xt(e);if(Ks(e))return n;if(!Nn(e)){let o=Jn(e);for(;o&&!Fr(o);){if(hn(o)&&!qa(o))return o;o=Jn(o)}return n}let r=Af(e,t);for(;r&&c0(r)&&qa(r);)r=Af(r,t);return r&&Fr(r)&&qa(r)&&!Ua(r)?n:r||p0(e)||n}const A0=async function(e){const t=this.getOffsetParent||Nf,n=this.getDimensions,r=await n(e.floating);return{reference:I0(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function N0(e){return pn(e).direction==="rtl"}const _0={convertOffsetParentRelativeRectToViewportRelativeRect:y0,getDocumentElement:An,getClippingRect:T0,getOffsetParent:Nf,getElementRects:A0,getClientRects:v0,getDimensions:E0,getScale:$r,isElement:hn,isRTL:N0};function _f(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function j0(e,t){let n=null,r;const o=An(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const u=e.getBoundingClientRect(),{left:d,top:f,width:h,height:p}=u;if(a||t(),!h||!p)return;const v=Hs(f),x=Hs(o.clientWidth-(d+h)),g=Hs(o.clientHeight-(f+p)),y=Hs(d),C={rootMargin:-v+"px "+-x+"px "+-g+"px "+-y+"px",threshold:Yt(0,Xn(1,l))||1};let E=!0;function k(T){const I=T[0].intersectionRatio;if(I!==l){if(!E)return i();I?i(!1,I):r=setTimeout(()=>{i(!1,1e-7)},1e3)}I===1&&!_f(u,e.getBoundingClientRect())&&i(),E=!1}try{n=new IntersectionObserver(k,{...C,root:o.ownerDocument})}catch{n=new IntersectionObserver(k,C)}n.observe(e)}return i(!0),s}function R0(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=Ka(e),d=o||s?[...u?vo(u):[],...vo(t)]:[];d.forEach(y=>{o&&y.addEventListener("scroll",n,{passive:!0}),s&&y.addEventListener("resize",n)});const f=u&&a?j0(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 C;(C=p)==null||C.observe(t)})),n()}),u&&!l&&p.observe(u),p.observe(t));let v,x=l?xr(e):null;l&&g();function g(){const y=xr(e);x&&!_f(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 P0=r0,O0=o0,M0=e0,D0=i0,L0=t0,jf=Qw,F0=s0,$0=(e,t,n)=>{const r=new Map,o={platform:_0,...n},s={...o.platform,_c:r};return Zw(e,t,{...o,platform:s})};var z0=typeof document<"u",B0=function(){},Ys=z0?w.useLayoutEffect:B0;function Xs(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,o;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!Xs(e[r],t[r]))return!1;return!0}if(o=Object.keys(e),n=o.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,o[r]))return!1;for(r=n;r--!==0;){const s=o[r];if(!(s==="_owner"&&e.$$typeof)&&!Xs(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Rf(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Pf(e,t){const n=Rf(e);return Math.round(t*n)/n}function Ga(e){const t=m.useRef(e);return Ys(()=>{t.current=e}),t}function H0(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);Xs(h,r)||p(r);const[v,x]=m.useState(null),[g,y]=m.useState(null),b=m.useCallback($=>{$!==T.current&&(T.current=$,x($))},[]),C=m.useCallback($=>{$!==I.current&&(I.current=$,y($))},[]),E=s||v,k=i||g,T=m.useRef(null),I=m.useRef(null),_=m.useRef(d),P=l!=null,j=Ga(l),H=Ga(o),F=Ga(u),U=m.useCallback(()=>{if(!T.current||!I.current)return;const $={placement:t,strategy:n,middleware:h};H.current&&($.platform=H.current),$0(T.current,I.current,$).then(z=>{const se={...z,isPositioned:F.current!==!1};D.current&&!Xs(_.current,se)&&(_.current=se,Po.flushSync(()=>{f(se)}))})},[h,t,n,H,F]);Ys(()=>{u===!1&&_.current.isPositioned&&(_.current.isPositioned=!1,f($=>({...$,isPositioned:!1})))},[u]);const D=m.useRef(!1);Ys(()=>(D.current=!0,()=>{D.current=!1}),[]),Ys(()=>{if(E&&(T.current=E),k&&(I.current=k),E&&k){if(j.current)return j.current(E,k,U);U()}},[E,k,U,j,P]);const G=m.useMemo(()=>({reference:T,floating:I,setReference:b,setFloating:C}),[b,C]),W=m.useMemo(()=>({reference:E,floating:k}),[E,k]),ne=m.useMemo(()=>{const $={position:n,left:0,top:0};if(!W.floating)return $;const z=Pf(W.floating,d.x),se=Pf(W.floating,d.y);return a?{...$,transform:"translate("+z+"px, "+se+"px)",...Rf(W.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:z,top:se}},[n,a,W.floating,d.x,d.y]);return m.useMemo(()=>({...d,update:U,refs:G,elements:W,floatingStyles:ne}),[d,U,G,W,ne])}const U0=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?jf({element:r.current,padding:o}).fn(n):{}:r?jf({element:r,padding:o}).fn(n):{}}}},W0=(e,t)=>({...P0(e),options:[e,t]}),V0=(e,t)=>({...O0(e),options:[e,t]}),K0=(e,t)=>({...F0(e),options:[e,t]}),q0=(e,t)=>({...M0(e),options:[e,t]}),G0=(e,t)=>({...D0(e),options:[e,t]}),Y0=(e,t)=>({...L0(e),options:[e,t]}),X0=(e,t)=>({...U0(e),options:[e,t]});var J0="Arrow",Of=m.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return c.jsx(Ee.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"})})});Of.displayName=J0;var Z0=Of;function Mf(e){const[t,n]=m.useState(void 0);return St(()=>{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 Ya="Popper",[Df,Js]=Cn(Ya),[Q0,Lf]=Df(Ya),Ff=e=>{const{__scopePopper:t,children:n}=e,[r,o]=m.useState(null);return c.jsx(Q0,{scope:t,anchor:r,onAnchorChange:o,children:n})};Ff.displayName=Ya;var $f="PopperAnchor",zf=m.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Lf($f,n),i=m.useRef(null),a=We(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(Ee.div,{...o,ref:a})});zf.displayName=$f;var Xa="PopperContent",[eS,tS]=Df(Xa),Bf=m.forwardRef((e,t)=>{var K,L,Z,ee,pe,oe;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=Lf(Xa,n),[y,b]=m.useState(null),C=We(t,ie=>b(ie)),[E,k]=m.useState(null),T=Mf(E),I=(T==null?void 0:T.width)??0,_=(T==null?void 0:T.height)??0,P=r+(s!=="center"?"-"+s:""),j=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},H=Array.isArray(u)?u:[u],F=H.length>0,U={padding:j,boundary:H.filter(rS),altBoundary:F},{refs:D,floatingStyles:G,placement:W,isPositioned:ne,middlewareData:$}=H0({strategy:"fixed",placement:P,whileElementsMounted:(...ie)=>R0(...ie,{animationFrame:p==="always"}),elements:{reference:g.anchor},middleware:[W0({mainAxis:o+_,alignmentAxis:i}),l&&V0({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?K0():void 0,...U}),l&&q0({...U}),G0({...U,apply:({elements:ie,rects:Be,availableWidth:Je,availableHeight:je})=>{const{width:He,height:Qe}=Be.reference,Ze=ie.floating.style;Ze.setProperty("--radix-popper-available-width",`${Je}px`),Ze.setProperty("--radix-popper-available-height",`${je}px`),Ze.setProperty("--radix-popper-anchor-width",`${He}px`),Ze.setProperty("--radix-popper-anchor-height",`${Qe}px`)}}),E&&X0({element:E,padding:a}),oS({arrowWidth:I,arrowHeight:_}),h&&Y0({strategy:"referenceHidden",...U})]}),[z,se]=Wf(W),M=_t(v);St(()=>{ne&&(M==null||M())},[ne,M]);const Y=(K=$.arrow)==null?void 0:K.x,ce=(L=$.arrow)==null?void 0:L.y,be=((Z=$.arrow)==null?void 0:Z.centerOffset)!==0,[ge,ye]=m.useState();return St(()=>{y&&ye(window.getComputedStyle(y).zIndex)},[y]),c.jsx("div",{ref:D.setFloating,"data-radix-popper-content-wrapper":"",style:{...G,transform:ne?G.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:ge,"--radix-popper-transform-origin":[(ee=$.transformOrigin)==null?void 0:ee.x,(pe=$.transformOrigin)==null?void 0:pe.y].join(" "),...((oe=$.hide)==null?void 0:oe.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:c.jsx(eS,{scope:n,placedSide:z,onArrowChange:k,arrowX:Y,arrowY:ce,shouldHideArrow:be,children:c.jsx(Ee.div,{"data-side":z,"data-align":se,...x,ref:C,style:{...x.style,animation:ne?void 0:"none"}})})})});Bf.displayName=Xa;var Hf="PopperArrow",nS={top:"bottom",right:"left",bottom:"top",left:"right"},Uf=m.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=tS(Hf,r),i=nS[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(Z0,{...o,ref:n,style:{...o.style,display:"block"}})})});Uf.displayName=Hf;function rS(e){return e!==null}var oS=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]=Wf(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 Wf(e){const[t,n="center"]=e.split("-");return[t,n]}var Vf=Ff,Kf=zf,qf=Bf,Gf=Uf,Ja="rovingFocusGroup.onEntryFocus",sS={bubbles:!1,cancelable:!0},bo="RovingFocusGroup",[Za,Yf,iS]=La(bo),[aS,Xf]=Cn(bo,[iS]),[lS,cS]=aS(bo),Jf=m.forwardRef((e,t)=>c.jsx(Za.Provider,{scope:e.__scopeRovingFocusGroup,children:c.jsx(Za.Slot,{scope:e.__scopeRovingFocusGroup,children:c.jsx(uS,{...e,ref:t})})}));Jf.displayName=bo;var uS=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=We(t,h),v=zs(s),[x,g]=hr({prop:i,defaultProp:a??null,onChange:l,caller:bo}),[y,b]=m.useState(!1),C=_t(u),E=Yf(n),k=m.useRef(!1),[T,I]=m.useState(0);return m.useEffect(()=>{const _=h.current;if(_)return _.addEventListener(Ja,C),()=>_.removeEventListener(Ja,C)},[C]),c.jsx(lS,{scope:n,orientation:r,dir:v,loop:o,currentTabStopId:x,onItemFocus:m.useCallback(_=>g(_),[g]),onItemShiftTab:m.useCallback(()=>b(!0),[]),onFocusableItemAdd:m.useCallback(()=>I(_=>_+1),[]),onFocusableItemRemove:m.useCallback(()=>I(_=>_-1),[]),children:c.jsx(Ee.div,{tabIndex:y||T===0?-1:0,"data-orientation":r,...f,ref:p,style:{outline:"none",...e.style},onMouseDown:he(e.onMouseDown,()=>{k.current=!0}),onFocus:he(e.onFocus,_=>{const P=!k.current;if(_.target===_.currentTarget&&P&&!y){const j=new CustomEvent(Ja,sS);if(_.currentTarget.dispatchEvent(j),!j.defaultPrevented){const H=E().filter(W=>W.focusable),F=H.find(W=>W.active),U=H.find(W=>W.id===x),G=[F,U,...H].filter(Boolean).map(W=>W.ref.current);eh(G,d)}}k.current=!1}),onBlur:he(e.onBlur,()=>b(!1))})})}),Zf="RovingFocusGroupItem",Qf=m.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,children:i,...a}=e,l=kn(),u=s||l,d=cS(Zf,n),f=d.currentTabStopId===u,h=Yf(n),{onFocusableItemAdd:p,onFocusableItemRemove:v,currentTabStopId:x}=d;return m.useEffect(()=>{if(r)return p(),()=>v()},[r,p,v]),c.jsx(Za.ItemSlot,{scope:n,id:u,focusable:r,active:o,children:c.jsx(Ee.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:he(e.onMouseDown,g=>{r?d.onItemFocus(u):g.preventDefault()}),onFocus:he(e.onFocus,()=>d.onItemFocus(u)),onKeyDown:he(e.onKeyDown,g=>{if(g.key==="Tab"&&g.shiftKey){d.onItemShiftTab();return}if(g.target!==g.currentTarget)return;const y=hS(g,d.orientation,d.dir);if(y!==void 0){if(g.metaKey||g.ctrlKey||g.altKey||g.shiftKey)return;g.preventDefault();let C=h().filter(E=>E.focusable).map(E=>E.ref.current);if(y==="last")C.reverse();else if(y==="prev"||y==="next"){y==="prev"&&C.reverse();const E=C.indexOf(g.currentTarget);C=d.loop?pS(C,E+1):C.slice(E+1)}setTimeout(()=>eh(C))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:x!=null}):i})})});Qf.displayName=Zf;var dS={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function fS(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function hS(e,t,n){const r=fS(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return dS[r]}function eh(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function pS(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var mS=Jf,gS=Qf,Qa=["Enter"," "],xS=["ArrowDown","PageUp","Home"],th=["ArrowUp","PageDown","End"],yS=[...xS,...th],vS={ltr:[...Qa,"ArrowRight"],rtl:[...Qa,"ArrowLeft"]},bS={ltr:["ArrowLeft"],rtl:["ArrowRight"]},wo="Menu",[So,wS,SS]=La(wo),[yr,nh]=Cn(wo,[SS,Js,Xf]),Zs=Js(),rh=Xf(),[CS,vr]=yr(wo),[kS,Co]=yr(wo),oh=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=Zs(t),[l,u]=m.useState(null),d=m.useRef(!1),f=_t(s),h=zs(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(Vf,{...a,children:c.jsx(CS,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:u,children:c.jsx(kS,{scope:t,onClose:m.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};oh.displayName=wo;var TS="MenuAnchor",el=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Zs(n);return c.jsx(Kf,{...o,...r,ref:t})});el.displayName=TS;var tl="MenuPortal",[ES,sh]=yr(tl,{forceMount:void 0}),ih=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=vr(tl,t);return c.jsx(ES,{scope:t,forceMount:n,children:c.jsx(Gt,{present:n||s.open,children:c.jsx(ws,{asChild:!0,container:o,children:r})})})};ih.displayName=tl;var nn="MenuContent",[IS,nl]=yr(nn),ah=m.forwardRef((e,t)=>{const n=sh(nn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=vr(nn,e.__scopeMenu),i=Co(nn,e.__scopeMenu);return c.jsx(So.Provider,{scope:e.__scopeMenu,children:c.jsx(Gt,{present:r||s.open,children:c.jsx(So.Slot,{scope:e.__scopeMenu,children:i.modal?c.jsx(AS,{...o,ref:t}):c.jsx(NS,{...o,ref:t})})})})}),AS=m.forwardRef((e,t)=>{const n=vr(nn,e.__scopeMenu),r=m.useRef(null),o=We(t,r);return m.useEffect(()=>{const s=r.current;if(s)return Ra(s)},[]),c.jsx(rl,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:he(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),NS=m.forwardRef((e,t)=>{const n=vr(nn,e.__scopeMenu);return c.jsx(rl,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),_S=or.createSlot("MenuContent.ScrollLock"),rl=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=vr(nn,n),y=Co(nn,n),b=Zs(n),C=rh(n),E=wS(n),[k,T]=m.useState(null),I=m.useRef(null),_=We(t,I,g.onContentChange),P=m.useRef(0),j=m.useRef(""),H=m.useRef(0),F=m.useRef(null),U=m.useRef("right"),D=m.useRef(0),G=v?Is:m.Fragment,W=v?{as:_S,allowPinchZoom:!0}:void 0,ne=z=>{var K,L;const se=j.current+z,M=E().filter(Z=>!Z.disabled),Y=document.activeElement,ce=(K=M.find(Z=>Z.ref.current===Y))==null?void 0:K.textValue,be=M.map(Z=>Z.textValue),ge=HS(be,se,ce),ye=(L=M.find(Z=>Z.textValue===ge))==null?void 0:L.ref.current;(function Z(ee){j.current=ee,window.clearTimeout(P.current),ee!==""&&(P.current=window.setTimeout(()=>Z(""),1e3))})(se),ye&&setTimeout(()=>ye.focus())};m.useEffect(()=>()=>window.clearTimeout(P.current),[]),Ea();const $=m.useCallback(z=>{var M,Y;return U.current===((M=F.current)==null?void 0:M.side)&&WS(z,(Y=F.current)==null?void 0:Y.area)},[]);return c.jsx(IS,{scope:n,searchRef:j,onItemEnter:m.useCallback(z=>{$(z)&&z.preventDefault()},[$]),onItemLeave:m.useCallback(z=>{var se;$(z)||((se=I.current)==null||se.focus(),T(null))},[$]),onTriggerLeave:m.useCallback(z=>{$(z)&&z.preventDefault()},[$]),pointerGraceTimerRef:H,onPointerGraceIntentChange:m.useCallback(z=>{F.current=z},[]),children:c.jsx(G,{...W,children:c.jsx(bs,{asChild:!0,trapped:o,onMountAutoFocus:he(s,z=>{var se;z.preventDefault(),(se=I.current)==null||se.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:c.jsx(vs,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:c.jsx(mS,{asChild:!0,...C,dir:y.dir,orientation:"vertical",loop:r,currentTabStopId:k,onCurrentTabStopIdChange:T,onEntryFocus:he(l,z=>{y.isUsingKeyboardRef.current||z.preventDefault()}),preventScrollOnEntryFocus:!0,children:c.jsx(qf,{role:"menu","aria-orientation":"vertical","data-state":kh(g.open),"data-radix-menu-content":"",dir:y.dir,...b,...x,ref:_,style:{outline:"none",...x.style},onKeyDown:he(x.onKeyDown,z=>{const M=z.target.closest("[data-radix-menu-content]")===z.currentTarget,Y=z.ctrlKey||z.altKey||z.metaKey,ce=z.key.length===1;M&&(z.key==="Tab"&&z.preventDefault(),!Y&&ce&&ne(z.key));const be=I.current;if(z.target!==be||!yS.includes(z.key))return;z.preventDefault();const ye=E().filter(K=>!K.disabled).map(K=>K.ref.current);th.includes(z.key)&&ye.reverse(),zS(ye)}),onBlur:he(e.onBlur,z=>{z.currentTarget.contains(z.target)||(window.clearTimeout(P.current),j.current="")}),onPointerMove:he(e.onPointerMove,To(z=>{const se=z.target,M=D.current!==z.clientX;if(z.currentTarget.contains(se)&&M){const Y=z.clientX>D.current?"right":"left";U.current=Y,D.current=z.clientX}}))})})})})})})});ah.displayName=nn;var jS="MenuGroup",ol=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(Ee.div,{role:"group",...r,ref:t})});ol.displayName=jS;var RS="MenuLabel",lh=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(Ee.div,{...r,ref:t})});lh.displayName=RS;var Qs="MenuItem",ch="menu.itemSelect",ei=m.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=m.useRef(null),i=Co(Qs,e.__scopeMenu),a=nl(Qs,e.__scopeMenu),l=We(t,s),u=m.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(ch,{bubbles:!0,cancelable:!0});f.addEventListener(ch,p=>r==null?void 0:r(p),{once:!0}),Vu(f,h),h.defaultPrevented?u.current=!1:i.onClose()}};return c.jsx(uh,{...o,ref:l,disabled:n,onClick:he(e.onClick,d),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),u.current=!0},onPointerUp:he(e.onPointerUp,f=>{var h;u.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:he(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||Qa.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});ei.displayName=Qs;var uh=m.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=nl(Qs,n),a=rh(n),l=m.useRef(null),u=We(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(So.ItemSlot,{scope:n,disabled:r,textValue:o??h,children:c.jsx(gS,{asChild:!0,...a,focusable:!r,children:c.jsx(Ee.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:u,onPointerMove:he(e.onPointerMove,To(v=>{r?i.onItemLeave(v):(i.onItemEnter(v),v.defaultPrevented||v.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:he(e.onPointerLeave,To(v=>i.onItemLeave(v))),onFocus:he(e.onFocus,()=>f(!0)),onBlur:he(e.onBlur,()=>f(!1))})})})}),PS="MenuCheckboxItem",dh=m.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return c.jsx(gh,{scope:e.__scopeMenu,checked:n,children:c.jsx(ei,{role:"menuitemcheckbox","aria-checked":ti(n)?"mixed":n,...o,ref:t,"data-state":il(n),onSelect:he(o.onSelect,()=>r==null?void 0:r(ti(n)?!0:!n),{checkForDefaultPrevented:!1})})})});dh.displayName=PS;var fh="MenuRadioGroup",[OS,MS]=yr(fh,{value:void 0,onValueChange:()=>{}}),hh=m.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=_t(r);return c.jsx(OS,{scope:e.__scopeMenu,value:n,onValueChange:s,children:c.jsx(ol,{...o,ref:t})})});hh.displayName=fh;var ph="MenuRadioItem",mh=m.forwardRef((e,t)=>{const{value:n,...r}=e,o=MS(ph,e.__scopeMenu),s=n===o.value;return c.jsx(gh,{scope:e.__scopeMenu,checked:s,children:c.jsx(ei,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":il(s),onSelect:he(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});mh.displayName=ph;var sl="MenuItemIndicator",[gh,DS]=yr(sl,{checked:!1}),xh=m.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=DS(sl,n);return c.jsx(Gt,{present:r||ti(s.checked)||s.checked===!0,children:c.jsx(Ee.span,{...o,ref:t,"data-state":il(s.checked)})})});xh.displayName=sl;var LS="MenuSeparator",yh=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(Ee.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});yh.displayName=LS;var FS="MenuArrow",vh=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Zs(n);return c.jsx(Gf,{...o,...r,ref:t})});vh.displayName=FS;var $S="MenuSub",[ST,bh]=yr($S),ko="MenuSubTrigger",wh=m.forwardRef((e,t)=>{const n=vr(ko,e.__scopeMenu),r=Co(ko,e.__scopeMenu),o=bh(ko,e.__scopeMenu),s=nl(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(el,{asChild:!0,...u,children:c.jsx(uh,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":kh(n.open),...e,ref:fa(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:he(e.onPointerMove,To(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:he(e.onPointerLeave,To(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"],C=h[g?"right":"left"];s.onPointerGraceIntentChange({area:[{x:f.clientX+y,y:f.clientY},{x:b,y:h.top},{x:C,y:h.top},{x:C,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:he(e.onKeyDown,f=>{var p;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||vS[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});wh.displayName=ko;var Sh="MenuSubContent",Ch=m.forwardRef((e,t)=>{const n=sh(nn,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=vr(nn,e.__scopeMenu),i=Co(nn,e.__scopeMenu),a=bh(Sh,e.__scopeMenu),l=m.useRef(null),u=We(t,l);return c.jsx(So.Provider,{scope:e.__scopeMenu,children:c.jsx(Gt,{present:r||s.open,children:c.jsx(So.Slot,{scope:e.__scopeMenu,children:c.jsx(rl,{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:he(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:he(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:he(e.onKeyDown,d=>{var p;const f=d.currentTarget.contains(d.target),h=bS[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),d.preventDefault())})})})})})});Ch.displayName=Sh;function kh(e){return e?"open":"closed"}function ti(e){return e==="indeterminate"}function il(e){return ti(e)?"indeterminate":e?"checked":"unchecked"}function zS(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function BS(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function HS(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=BS(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 US(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 WS(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return US(n,t)}function To(e){return t=>t.pointerType==="mouse"?e(t):void 0}var VS=oh,KS=el,qS=ih,GS=ah,YS=ol,XS=lh,JS=ei,ZS=dh,QS=hh,eC=mh,tC=xh,nC=yh,rC=vh,oC=wh,sC=Ch,ni="DropdownMenu",[iC,CT]=Cn(ni,[nh]),Bt=nh(),[aC,Th]=iC(ni),Eh=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=Bt(t),u=m.useRef(null),[d,f]=hr({prop:o,defaultProp:s??!1,onChange:i,caller:ni});return c.jsx(aC,{scope:t,triggerId:kn(),triggerRef:u,contentId:kn(),open:d,onOpenChange:f,onOpenToggle:m.useCallback(()=>f(h=>!h),[f]),modal:a,children:c.jsx(VS,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};Eh.displayName=ni;var Ih="DropdownMenuTrigger",Ah=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Th(Ih,n),i=Bt(n);return c.jsx(KS,{asChild:!0,...i,children:c.jsx(Ee.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:fa(t,s.triggerRef),onPointerDown:he(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:he(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});Ah.displayName=Ih;var lC="DropdownMenuPortal",Nh=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Bt(t);return c.jsx(qS,{...r,...n})};Nh.displayName=lC;var _h="DropdownMenuContent",jh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Th(_h,n),s=Bt(n),i=m.useRef(!1);return c.jsx(GS,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:he(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:he(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)"}})});jh.displayName=_h;var cC="DropdownMenuGroup",uC=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Bt(n);return c.jsx(YS,{...o,...r,ref:t})});uC.displayName=cC;var dC="DropdownMenuLabel",Rh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Bt(n);return c.jsx(XS,{...o,...r,ref:t})});Rh.displayName=dC;var fC="DropdownMenuItem",Ph=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Bt(n);return c.jsx(JS,{...o,...r,ref:t})});Ph.displayName=fC;var hC="DropdownMenuCheckboxItem",Oh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Bt(n);return c.jsx(ZS,{...o,...r,ref:t})});Oh.displayName=hC;var pC="DropdownMenuRadioGroup",mC=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Bt(n);return c.jsx(QS,{...o,...r,ref:t})});mC.displayName=pC;var gC="DropdownMenuRadioItem",Mh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Bt(n);return c.jsx(eC,{...o,...r,ref:t})});Mh.displayName=gC;var xC="DropdownMenuItemIndicator",Dh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Bt(n);return c.jsx(tC,{...o,...r,ref:t})});Dh.displayName=xC;var yC="DropdownMenuSeparator",Lh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Bt(n);return c.jsx(nC,{...o,...r,ref:t})});Lh.displayName=yC;var vC="DropdownMenuArrow",bC=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Bt(n);return c.jsx(rC,{...o,...r,ref:t})});bC.displayName=vC;var wC="DropdownMenuSubTrigger",Fh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Bt(n);return c.jsx(oC,{...o,...r,ref:t})});Fh.displayName=wC;var SC="DropdownMenuSubContent",$h=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Bt(n);return c.jsx(sC,{...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)"}})});$h.displayName=SC;var CC=Eh,kC=Ah,TC=Nh,zh=jh,Bh=Rh,Hh=Ph,Uh=Oh,Wh=Mh,Vh=Dh,Kh=Lh,qh=Fh,Gh=$h;const EC=CC,IC=kC,AC=m.forwardRef(({className:e,inset:t,children:n,...r},o)=>c.jsxs(qh,{ref:o,className:re("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(me.ChevronRight,{className:"ml-auto h-4 w-4"})]}));AC.displayName=qh.displayName;const NC=m.forwardRef(({className:e,...t},n)=>c.jsx(Gh,{ref:n,className:re("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}));NC.displayName=Gh.displayName;const Yh=m.forwardRef(({className:e,sideOffset:t=4,...n},r)=>c.jsx(TC,{children:c.jsx(zh,{ref:r,sideOffset:t,className:re("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})}));Yh.displayName=zh.displayName;const al=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(Hh,{ref:r,className:re("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}));al.displayName=Hh.displayName;const _C=m.forwardRef(({className:e,children:t,checked:n,...r},o)=>c.jsxs(Uh,{ref:o,className:re("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(Vh,{children:c.jsx(me.Check,{className:"h-4 w-4"})})}),t]}));_C.displayName=Uh.displayName;const jC=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Wh,{ref:r,className:re("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(Vh,{children:c.jsx(me.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));jC.displayName=Wh.displayName;const RC=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(Bh,{ref:r,className:re("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));RC.displayName=Bh.displayName;const PC=m.forwardRef(({className:e,...t},n)=>c.jsx(Kh,{ref:n,className:re("-mx-1 my-1 h-px bg-muted",e),...t}));PC.displayName=Kh.displayName;function OC(e){var t;if(!Array.isArray(e)||!e.length)return null;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 ri({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}=Ni(),{currentThreadId:x}=Yo(),{threadId:g,messages:y,hasMore:b,isHistoryLoading:C,isLoading:E,loadOlder:k,navigateToCheckpoint:T,returnToLatest:I,checkpoint:_,checkpoints:P,interrupt:j,metadata:H}=Xo(),{isStreaming:F,error:U,submit:D,stop:G}=Uc(),W=g??x??null,ne=(_==null?void 0:_.id)??null,$=(_==null?void 0:_.namespace)??null,z=(H==null?void 0:H.assemblingMessageId)??null,se=j,[M,Y]=w.useState(!1);w.useEffect(()=>{se||Y(!1)},[se]);const ce=w.useCallback(()=>{Y(!0)},[]),be=w.useCallback(()=>{Y(!1)},[]),ge=!!se||M,[ye,K]=w.useState(null),[L,Z]=w.useState(""),[ee,pe]=w.useState(null),[oe,ie]=w.useState([]),[Be,Je]=w.useState(0),[je,He]=w.useState(0),[Qe,Ze]=w.useState(!1),[Pe,wt]=w.useState(null),[Ct,kt]=w.useState(null),[ot,et]=w.useState(!1),[$e,ct]=w.useState(null),[vt,J]=w.useState(!1),xe=w.useRef(!1),[ue,_e]=w.useState(!1),Ve=w.useCallback((S,R)=>{if(!S||typeof S!="object")return null;const B=S[R];return typeof B=="number"?B:null},[]),at=w.useCallback((S,R)=>{if(!S||typeof S!="object")return null;const B=S[R];return typeof B=="string"&&B.trim()?B:null},[]),Tt=w.useMemo(()=>{const S=Array.isArray(P)?[...P]:[];return S.some(B=>Ve(B.metadata,"step")!==null)&&S.sort((B,ae)=>{const ke=Ve(B.metadata,"step"),Ae=Ve(ae.metadata,"step");if(ke!==null||Ae!==null)return(Ae??Number.NEGATIVE_INFINITY)-(ke??Number.NEGATIVE_INFINITY);const De=Date.parse(B.createdAt??""),Oe=Date.parse(ae.createdAt??"");return Number.isNaN(De)||Number.isNaN(Oe)?0:Oe-De}),S},[P,Ve]),rt=w.useRef(null),ut=w.useRef(null),pt=w.useCallback(()=>{rt.current&&(rt.current.value=""),ut.current&&(ut.current.value=""),Je(S=>S+1),He(S=>S+1)},[]),$n=w.useRef(!1);w.useEffect(()=>{$n.current&&!F&&(ie([]),pt()),$n.current=F},[F,pt]);const[sn,jt]=w.useState("desktop");w.useEffect(()=>{const S=()=>{const R=window.innerWidth;jt(R<640?"phone":R<1024?"tablet":"desktop")};return S(),window.addEventListener("resize",S),()=>window.removeEventListener("resize",S)},[]),w.useEffect(()=>{J(!1),xe.current=!1},[W]);const Cr=w.useCallback(async()=>{if(!(!b||C||!vt))try{await k()}catch(S){console.warn("loadOlder failed",S)}},[b,vt,C,k]);w.useEffect(()=>{(async()=>{if(!v.baseUrl){ct(null);return}try{const R=await v.getAgent("default");ct(R.uiDefaultMessage||null)}catch(R){console.warn("Failed to fetch default message:",R),ct(null)}})()},[v]),w.useEffect(()=>{U&&!ot&&(p==null||p(U))},[U,ot,p]);const tr=S=>{if(S.length>$s)return`Message too long (${S.length}/${$s} characters)`;try{return $w(S),null}catch(R){return(R==null?void 0:R.message)||"Invalid message"}},Et=async S=>{const R=S.trim();if(!(!R&&oe.length===0)){if(R){const B=tr(R);if(B){pe(B);return}}try{await D({text:R||"",attachments:oe,payload:ye?{edit:!0,originalMessageId:ye}:void 0},{checkpointId:ne??void 0,checkpointNs:$??void 0}),f==null||f(R),pe(null),ie([]),pt(),K(null),Z("")}catch(B){const ae=(B==null?void 0:B.message)||"Failed to send message";pe(ae),p==null||p(ae)}}},an=w.useCallback((S,R)=>{u&&(K(S),Z(R),pe(null))},[u]),gn=w.useCallback(()=>{K(null),Z(""),pe(null)},[]),kr=w.useCallback((S,R)=>{an(S,R)},[an]),Jt=w.useCallback(S=>{const R=B=>{const ae=B.content||[],ke=ae.filter(Ae=>Ae.type==="text").map(Ae=>Ae.text).join("");if(ke)return ke;try{return JSON.stringify(ae,null,2)}catch{return String(ae)}};for(let B=S-1;B>=0;B--)if(y[B].role==="user"){const ae=R(y[B]);ae&&D({text:ae},{checkpointId:ne??void 0,checkpointNs:$??void 0});break}},[y,D,ne,$]),Tr=S=>{const R=Array.from(S.target.files||[]);ie(B=>[...B,...R]),S.target.value=""},jn=S=>{ie(R=>{const B=R.filter((ae,ke)=>S!==ke);return B.length===0&&pt(),B})},xn=async S=>{const R=(S.target.files||[])[0];if(R){wt(null),kt(null),Ze(!0);try{await D({attachments:[R]},{checkpointId:ne??void 0,checkpointNs:$??void 0});const B=`Uploaded ${R.name} - processing through chat stream`;kt(B)}catch(B){const ae=B instanceof Error?B.message:"Failed to upload Excel file";console.error("Excel upload failed",B),wt(ae),p==null||p(ae)}finally{Ze(!1),S.target.value="",pt()}}},nr=S=>{if(!S)return"Unknown";const R=Date.parse(S);return Number.isNaN(R)?S:new Date(R).toLocaleString()},Io=async S=>{if(x){_e(!0);try{if(!S){await I();return}const R=Tt.find(ae=>ae.checkpointId===S),B=(R==null?void 0:R.checkpointNs)??null;await T(S,B)}finally{_e(!1)}}},Ur=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${d.container||""}`,Wr=`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||""}`,rr=`flex-shrink-0 w-full border-t p-4 bg-transparent ${d.inputArea||""}`;return c.jsxs("div",{className:Ur,children:[!!U&&!ot&&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:U}),c.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>et(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:c.jsx(me.X,{size:16})})]}),x&&P.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:ne??"",onChange:S=>{const R=S.target.value||null;Io(R)},children:[c.jsx("option",{value:"",children:"Latest"}),Tt.map(S=>{const R=Ve(S.metadata,"step"),B=at(S.metadata,"source"),ae=OC(S.messages),ke=[];R!==null&&ke.push(`Step ${R}`),B&&ke.push(B),ae&&ke.push(ae.slice(0,40));const Ae=ke.length?` — ${ke.join(" • ")}`:"";return c.jsxs("option",{value:S.checkpointId,children:[nr(S.createdAt),Ae]},S.checkpointId)})]})]}),c.jsxs("div",{className:`relative ${Wr}`,style:r?{maxHeight:r}:void 0,children:[c.jsx(Da,{className:"h-full",style:{height:"100%"},messages:y,isStreaming:F,streamingAssistantId:z,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:sn,enableMessageEditing:u,editingMessageId:ye,onStartReached:()=>{vt&&Cr()},onScrollAway:S=>{if(!xe.current){xe.current=!0;return}S&&J(!0)},onEdit:kr,onRegenerate:Jt,onCancelEdit:gn,emptyMessage:$e??void 0,isNavigatingCheckpoint:ue,activeInterrupt:se,disableInterruptActions:M,onInterruptActionStart:ce,onInterruptActionEnd:be}),E&&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(me.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:rr,children:[ye&&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(me.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:gn,className:"text-blue-600 hover:bg-blue-100",children:c.jsx(me.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:rt,type:"file",multiple:!0,onChange:S=>Tr(S),className:"hidden"},Be),oe.length>0&&c.jsx("div",{className:"flex flex-wrap gap-2",children:oe.map((S,R)=>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(me.Paperclip,{size:14}),c.jsx("span",{className:"truncate max-w-[150px]",children:S.name}),c.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>jn(R),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 ${S.name}`,children:c.jsx(me.X,{size:12})})]},R))})]}),l&&c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:ut,type:"file",accept:".xls,.xlsx,.xlsm",onChange:xn,className:"hidden"},je),Qe&&c.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[c.jsx(me.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),Ct&&!Qe&&c.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:Ct}),Pe&&!Qe&&c.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:Pe})]})]}),ee&&c.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:ee}),c.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&c.jsxs(EC,{children:[c.jsx(IC,{asChild:!0,children:c.jsx(Ge,{type:"button",size:"icon",variant:"outline",disabled:F||ge,title:"More input actions",className:d.moreButton||"",children:c.jsx(me.Plus,{size:16})})}),c.jsxs(Yh,{align:"start",sideOffset:6,className:"w-52",children:[a&&c.jsxs(al,{onClick:()=>{var S;return(S=rt.current)==null?void 0:S.click()},className:"cursor-pointer",children:[c.jsx(me.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&c.jsxs(al,{onClick:()=>{var S;Qe||(S=ut.current)==null||S.click()},className:`cursor-pointer ${Qe?"opacity-60 pointer-events-none":""}`,children:[c.jsx(me.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),c.jsx("div",{className:"flex-1",children:c.jsx(Xx,{initialValue:L,editingMessageId:ye,placeholder:ye?"Edit your message...":t,isStreaming:F,disabled:ge,maxLength:$s,onSend:Et,onCancelEdit:gn,onStop:G,allowEmptySend:oe.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${ye?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${ee?"border-red-400":""} ${d.textarea||""}`})})]})]})]})}const oi=m.forwardRef(({className:e,type:t,...n},r)=>c.jsx("input",{type:t,className:re("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}));oi.displayName="Input";function ll(e,[t,n]){return Math.min(n,Math.max(t,e))}function MC(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var cl="ScrollArea",[Xh,kT]=Cn(cl),[DC,rn]=Xh(cl),Jh=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),[C,E]=m.useState(0),[k,T]=m.useState(!1),[I,_]=m.useState(!1),P=We(t,H=>l(H)),j=zs(o);return c.jsx(DC,{scope:n,type:r,dir:j,scrollHideDelay:s,scrollArea:a,viewport:u,onViewportChange:d,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:v,scrollbarXEnabled:k,onScrollbarXEnabledChange:T,scrollbarY:x,onScrollbarYChange:g,scrollbarYEnabled:I,onScrollbarYEnabledChange:_,onCornerWidthChange:b,onCornerHeightChange:E,children:c.jsx(Ee.div,{dir:j,...i,ref:P,style:{position:"relative","--radix-scroll-area-corner-width":y+"px","--radix-scroll-area-corner-height":C+"px",...e.style}})})});Jh.displayName=cl;var Zh="ScrollAreaViewport",Qh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=rn(Zh,n),a=m.useRef(null),l=We(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(Ee.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})})]})});Qh.displayName=Zh;var _n="ScrollAreaScrollbar",ul=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=rn(_n,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(LC,{...r,ref:t,forceMount:n}):o.type==="scroll"?c.jsx(FC,{...r,ref:t,forceMount:n}):o.type==="auto"?c.jsx(ep,{...r,ref:t,forceMount:n}):o.type==="always"?c.jsx(dl,{...r,ref:t}):null});ul.displayName=_n;var LC=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=rn(_n,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(Gt,{present:n||s,children:c.jsx(ep,{"data-state":s?"visible":"hidden",...r,ref:t})})}),FC=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=rn(_n,e.__scopeScrollArea),s=e.orientation==="horizontal",i=li(()=>l("SCROLL_END"),100),[a,l]=MC("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(Gt,{present:n||a!=="hidden",children:c.jsx(dl,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:he(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:he(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),ep=m.forwardRef((e,t)=>{const n=rn(_n,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=m.useState(!1),a=e.orientation==="horizontal",l=li(()=>{if(n.viewport){const u=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?u:d)}},10);return zr(n.viewport,l),zr(n.content,l),c.jsx(Gt,{present:r||s,children:c.jsx(dl,{"data-state":s?"visible":"hidden",...o,ref:t})})}),dl=m.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=rn(_n,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=sp(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 WC(h,i.current,a,p)}return n==="horizontal"?c.jsx($C,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=ip(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(zC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=ip(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}),$C=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=rn(_n,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),u=We(t,l,s.onScrollbarXChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),c.jsx(np,{"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":ai(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),lp(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:ii(i.paddingLeft),paddingEnd:ii(i.paddingRight)}})}})}),zC=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=rn(_n,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),u=We(t,l,s.onScrollbarYChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),c.jsx(np,{"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":ai(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),lp(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:ii(i.paddingTop),paddingEnd:ii(i.paddingBottom)}})}})}),[BC,tp]=Xh(_n),np=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=rn(_n,n),[v,x]=m.useState(null),g=We(t,P=>x(P)),y=m.useRef(null),b=m.useRef(""),C=p.viewport,E=r.content-r.viewport,k=_t(d),T=_t(l),I=li(f,10);function _(P){if(y.current){const j=P.clientX-y.current.left,H=P.clientY-y.current.top;u({x:j,y:H})}}return m.useEffect(()=>{const P=j=>{const H=j.target;(v==null?void 0:v.contains(H))&&k(j,E)};return document.addEventListener("wheel",P,{passive:!1}),()=>document.removeEventListener("wheel",P,{passive:!1})},[C,v,E,k]),m.useEffect(T,[r,T]),zr(v,I),zr(p.content,I),c.jsx(BC,{scope:n,scrollbar:v,hasThumb:o,onThumbChange:_t(s),onThumbPointerUp:_t(i),onThumbPositionChange:T,onThumbPointerDown:_t(a),children:c.jsx(Ee.div,{...h,ref:g,style:{position:"absolute",...h.style},onPointerDown:he(e.onPointerDown,P=>{P.button===0&&(P.target.setPointerCapture(P.pointerId),y.current=v.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),_(P))}),onPointerMove:he(e.onPointerMove,_),onPointerUp:he(e.onPointerUp,P=>{const j=P.target;j.hasPointerCapture(P.pointerId)&&j.releasePointerCapture(P.pointerId),document.body.style.webkitUserSelect=b.current,p.viewport&&(p.viewport.style.scrollBehavior=""),y.current=null})})})}),si="ScrollAreaThumb",rp=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=tp(si,e.__scopeScrollArea);return c.jsx(Gt,{present:n||o.hasThumb,children:c.jsx(HC,{ref:t,...r})})}),HC=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=rn(si,n),i=tp(si,n),{onThumbPositionChange:a}=i,l=We(t,f=>i.onThumbChange(f)),u=m.useRef(void 0),d=li(()=>{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=VC(f,a);u.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,d,a]),c.jsx(Ee.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:he(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:he(e.onPointerUp,i.onThumbPointerUp)})});rp.displayName=si;var fl="ScrollAreaCorner",op=m.forwardRef((e,t)=>{const n=rn(fl,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?c.jsx(UC,{...e,ref:t}):null});op.displayName=fl;var UC=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=rn(fl,n),[s,i]=m.useState(0),[a,l]=m.useState(0),u=!!(s&&a);return zr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),zr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),u?c.jsx(Ee.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 ii(e){return e?parseInt(e,10):0}function sp(e,t){const n=e/t;return isNaN(n)?0:n}function ai(e){const t=sp(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function WC(e,t,n,r="ltr"){const o=ai(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 ap([l,u],f)(e)}function ip(e,t,n="ltr"){const r=ai(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=ll(e,l);return ap([0,i],[0,a])(u)}function ap(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 lp(e,t){return e>0&&e<t}var VC=(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 li(e,t){const n=_t(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 zr(e,t){const n=_t(t);St(()=>{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 cp=Jh,KC=Qh,qC=op;const up=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(cp,{ref:r,className:re("relative overflow-hidden",e),...n,children:[c.jsx(KC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),c.jsx(dp,{}),c.jsx(qC,{})]}));up.displayName=cp.displayName;const dp=m.forwardRef(({className:e,orientation:t="vertical",...n},r)=>c.jsx(ul,{ref:r,orientation:t,className:re("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(rp,{className:"relative flex-1 rounded-full bg-border"})}));dp.displayName=ul.displayName;function hl({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}=Yo(),{loadThread:x}=Xo(),{createThread:g,deleteThread:y,renameThread:b}=v,[C,E]=w.useState(Array.isArray(f)?f:[]),k=w.useRef(C.length>0),[T,I]=w.useState(null),[_,P]=w.useState(""),[j,H]=w.useState(!1);w.useEffect(()=>{const M=Array.isArray(f)?f:[];if(M.length>0){k.current=!0,E(M);return}p||(k.current=!1,E(M))},[f,p]);const F=async M=>{try{await x(M),a==null||a(M),l==null||l(M)}catch(Y){console.error("Failed to select thread:",Y)}},U=async()=>{try{H(!0);const M=await g();u==null||u(M),a==null||a(M)}catch(M){console.error("Failed to create thread:",M)}finally{H(!1)}},D=async(M,Y)=>{if(Y.stopPropagation(),!!confirm("Delete this thread?"))try{await y(M),d==null||d(M)}catch(ce){console.error("Failed to delete thread:",ce)}},G=(M,Y)=>{Y.stopPropagation(),I(M.threadId),P(M.title||`Thread ${M.threadId.slice(0,8)}`)},W=async M=>{if(_.trim())try{await b(M,_.trim()),I(null),P("")}catch(Y){console.error("Failed to update title:",Y)}},ne=()=>{I(null),P("")},$=(M,Y)=>{M.key==="Enter"?W(Y):M.key==="Escape"&&ne()},z=M=>{if(!M)return"";try{const Y=new Date(M),be=new Date().getTime()-Y.getTime(),ge=Math.floor(be/(1e3*60*60*24));return ge===0?Y.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):ge===1?"Yesterday":ge<7?`${ge} days ago`:Y.toLocaleDateString()}catch{return""}},se=M=>M.title||`Thread ${M.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:U,disabled:j||p,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:j?"Creating...":"New Chat",children:c.jsx(me.MessageSquarePlus,{size:20})})}),c.jsx(up,{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(me.Loader2,{className:"h-5 w-5 animate-spin"}),c.jsx("span",{className:"text-sm",children:"Loading threads…"})]}):C.length===0?c.jsxs("div",{className:"text-center py-8 text-slate-400",children:[c.jsx(me.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"})]}):C.slice().sort((M,Y)=>new Date(Y.updatedAt||Y.createdAt||"").getTime()-new Date(M.updatedAt||M.createdAt||"").getTime()).map(M=>c.jsxs("div",{onClick:()=>F(M.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??h)===M.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===M.threadId?c.jsxs("div",{className:"flex items-center gap-2",onClick:Y=>Y.stopPropagation(),children:[c.jsx(oi,{value:_,onChange:Y=>P(Y.target.value),onKeyDown:Y=>$(Y,M.threadId),className:"h-6 text-sm",autoFocus:!0}),c.jsx(Ge,{variant:"ghost",size:"sm",onClick:()=>W(M.threadId),className:"h-6 w-6 p-0",children:c.jsx(me.Check,{size:12})}),c.jsx(Ge,{variant:"ghost",size:"sm",onClick:ne,className:"h-6 w-6 p-0",children:c.jsx(me.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:se(M)}),c.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[c.jsx(me.Calendar,{size:10}),c.jsx("span",{children:z(M.updatedAt||M.createdAt)})]})]})}),c.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&T!==M.threadId&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:Y=>G(M,Y),className:"h-6 w-6 p-0",title:"Edit title",children:c.jsx(me.Edit3,{size:12})}),n&&c.jsx(Ge,{variant:"ghost",size:"sm",onClick:Y=>D(M.threadId,Y),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(me.Trash2,{size:12})})]})]}),i===M.threadId&&c.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},M.threadId))})})]})}function Br(e){if(!(typeof globalThis>"u"))return globalThis[e]}function GC(e){if(typeof e!="string")return;const t=e.trim();if(t)return Mn(t)}function fp(){const e=[Br("__API_BASE_URL__"),Br("__CHAT_API_BASE_URL__"),Br("__CHAT_API_URL__")];for(const t of e){const n=GC(t);if(n)return n}}function hp(){const e=[Br("__API_AUTH_TOKEN__"),Br("__CHAT_API_KEY__"),Br("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function pp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return Mn(t);return Mn()}function mp(){const e={},t=fp(),n=hp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function gp(){const e=mp(),t=Hn.getAuthToken(),n=fp();return{apiBaseUrl:pp(e.baseUrl,Hn.baseUrl,n),apiKey:t||e.apiKey||hp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,truncateToolMessages:!0,toolMessagePreviewLength:200,darkMode:!1,enableSound:!1,messageHistory:100}}const xp="chat-settings";function YC(){try{const e=localStorage.getItem(xp);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function XC(e){try{const t={...e,apiBaseUrl:Mn(e.apiBaseUrl)};localStorage.setItem(xp,JSON.stringify(t)),t.apiKey&&Hn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function JC(){const e=gp(),t=YC(),n=Hn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:pp(Hn.baseUrl,r,e.apiBaseUrl)}}function ZC(e){Hn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),XC(e)}var QC="Label",yp=m.forwardRef((e,t)=>c.jsx(Ee.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())}}));yp.displayName=QC;var vp=yp;const ek=Ro.cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),on=m.forwardRef(({className:e,...t},n)=>c.jsx(vp,{ref:n,className:re(ek(),e),...t}));on.displayName=vp.displayName;function bp(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 ci="Switch",[tk,TT]=Cn(ci),[nk,rk]=tk(ci),wp=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=We(t,C=>p(C)),x=m.useRef(!1),g=h?d||!!h.closest("form"):!0,[y,b]=hr({prop:o,defaultProp:s??!1,onChange:u,caller:ci});return c.jsxs(nk,{scope:n,checked:y,disabled:a,children:[c.jsx(Ee.button,{type:"button",role:"switch","aria-checked":y,"aria-required":i,"data-state":Tp(y),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:v,onClick:he(e.onClick,C=>{b(E=>!E),g&&(x.current=C.isPropagationStopped(),x.current||C.stopPropagation())})}),g&&c.jsx(kp,{control:h,bubbles:!x.current,name:r,value:l,checked:y,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});wp.displayName=ci;var Sp="SwitchThumb",Cp=m.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=rk(Sp,n);return c.jsx(Ee.span,{"data-state":Tp(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Cp.displayName=Sp;var ok="SwitchBubbleInput",kp=m.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=m.useRef(null),a=We(i,s),l=bp(n),u=Mf(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}})});kp.displayName=ok;function Tp(e){return e?"checked":"unchecked"}var Ep=wp,sk=Cp;const Zn=m.forwardRef(({className:e,...t},n)=>c.jsx(Ep,{className:re("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(sk,{className:re("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")})}));Zn.displayName=Ep.displayName;var Ip=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"}),ik="VisuallyHidden",ak=m.forwardRef((e,t)=>c.jsx(Ee.span,{...e,ref:t,style:{...Ip,...e.style}}));ak.displayName=ik;var lk=[" ","Enter","ArrowUp","ArrowDown"],ck=[" ","Enter"],br="Select",[ui,di,uk]=La(br),[Hr,ET]=Cn(br,[uk,Js]),fi=Js(),[dk,Qn]=Hr(br),[fk,hk]=Hr(br),Ap=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=fi(t),[g,y]=m.useState(null),[b,C]=m.useState(null),[E,k]=m.useState(!1),T=zs(u),[I,_]=hr({prop:r,defaultProp:o??!1,onChange:s,caller:br}),[P,j]=hr({prop:i,defaultProp:a,onChange:l,caller:br}),H=m.useRef(null),F=g?v||!!g.closest("form"):!0,[U,D]=m.useState(new Set),G=Array.from(U).map(W=>W.props.value).join(";");return c.jsx(Vf,{...x,children:c.jsxs(dk,{required:p,scope:t,trigger:g,onTriggerChange:y,valueNode:b,onValueNodeChange:C,valueNodeHasChildren:E,onValueNodeHasChildrenChange:k,contentId:kn(),value:P,onValueChange:j,open:I,onOpenChange:_,dir:T,triggerPointerDownPosRef:H,disabled:h,children:[c.jsx(ui.Provider,{scope:t,children:c.jsx(fk,{scope:e.__scopeSelect,onNativeOptionAdd:m.useCallback(W=>{D(ne=>new Set(ne).add(W))},[]),onNativeOptionRemove:m.useCallback(W=>{D(ne=>{const $=new Set(ne);return $.delete(W),$})},[]),children:n})}),F?c.jsxs(Zp,{"aria-hidden":!0,required:p,tabIndex:-1,name:d,autoComplete:f,value:P,onChange:W=>j(W.target.value),disabled:h,form:v,children:[P===void 0?c.jsx("option",{value:""}):null,Array.from(U)]},G):null]})})};Ap.displayName=br;var Np="SelectTrigger",_p=m.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=fi(n),i=Qn(Np,n),a=i.disabled||r,l=We(t,i.onTriggerChange),u=di(n),d=m.useRef("touch"),[f,h,p]=em(x=>{const g=u().filter(C=>!C.disabled),y=g.find(C=>C.value===i.value),b=tm(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(Kf,{asChild:!0,...s,children:c.jsx(Ee.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":Qp(i.value)?"":void 0,...o,ref:l,onClick:he(o.onClick,x=>{x.currentTarget.focus(),d.current!=="mouse"&&v(x)}),onPointerDown:he(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:he(o.onKeyDown,x=>{const g=f.current!=="";!(x.ctrlKey||x.altKey||x.metaKey)&&x.key.length===1&&h(x.key),!(g&&x.key===" ")&&lk.includes(x.key)&&(v(),x.preventDefault())})})})});_p.displayName=Np;var jp="SelectValue",Rp=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Qn(jp,n),{onValueNodeHasChildrenChange:u}=l,d=s!==void 0,f=We(t,l.onValueNodeChange);return St(()=>{u(d)},[u,d]),c.jsx(Ee.span,{...a,ref:f,style:{pointerEvents:"none"},children:Qp(l.value)?c.jsx(c.Fragment,{children:i}):s})});Rp.displayName=jp;var pk="SelectIcon",Pp=m.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return c.jsx(Ee.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Pp.displayName=pk;var mk="SelectPortal",Op=e=>c.jsx(ws,{asChild:!0,...e});Op.displayName=mk;var wr="SelectContent",Mp=m.forwardRef((e,t)=>{const n=Qn(wr,e.__scopeSelect),[r,o]=m.useState();if(St(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?Po.createPortal(c.jsx(Dp,{scope:e.__scopeSelect,children:c.jsx(ui.Slot,{scope:e.__scopeSelect,children:c.jsx("div",{children:e.children})})}),s):null}return c.jsx(Lp,{...e,ref:t})});Mp.displayName=wr;var mn=10,[Dp,er]=Hr(wr),gk="SelectContentImpl",xk=or.createSlot("SelectContent.RemoveScroll"),Lp=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=Qn(wr,n),[C,E]=m.useState(null),[k,T]=m.useState(null),I=We(t,K=>E(K)),[_,P]=m.useState(null),[j,H]=m.useState(null),F=di(n),[U,D]=m.useState(!1),G=m.useRef(!1);m.useEffect(()=>{if(C)return Ra(C)},[C]),Ea();const W=m.useCallback(K=>{const[L,...Z]=F().map(oe=>oe.ref.current),[ee]=Z.slice(-1),pe=document.activeElement;for(const oe of K)if(oe===pe||(oe==null||oe.scrollIntoView({block:"nearest"}),oe===L&&k&&(k.scrollTop=0),oe===ee&&k&&(k.scrollTop=k.scrollHeight),oe==null||oe.focus(),document.activeElement!==pe))return},[F,k]),ne=m.useCallback(()=>W([_,C]),[W,_,C]);m.useEffect(()=>{U&&ne()},[U,ne]);const{onOpenChange:$,triggerPointerDownPosRef:z}=b;m.useEffect(()=>{if(C){let K={x:0,y:0};const L=ee=>{var pe,oe;K={x:Math.abs(Math.round(ee.pageX)-(((pe=z.current)==null?void 0:pe.x)??0)),y:Math.abs(Math.round(ee.pageY)-(((oe=z.current)==null?void 0:oe.y)??0))}},Z=ee=>{K.x<=10&&K.y<=10?ee.preventDefault():C.contains(ee.target)||$(!1),document.removeEventListener("pointermove",L),z.current=null};return z.current!==null&&(document.addEventListener("pointermove",L),document.addEventListener("pointerup",Z,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",L),document.removeEventListener("pointerup",Z,{capture:!0})}}},[C,$,z]),m.useEffect(()=>{const K=()=>$(!1);return window.addEventListener("blur",K),window.addEventListener("resize",K),()=>{window.removeEventListener("blur",K),window.removeEventListener("resize",K)}},[$]);const[se,M]=em(K=>{const L=F().filter(pe=>!pe.disabled),Z=L.find(pe=>pe.ref.current===document.activeElement),ee=tm(L,K,Z);ee&&setTimeout(()=>ee.ref.current.focus())}),Y=m.useCallback((K,L,Z)=>{const ee=!G.current&&!Z;(b.value!==void 0&&b.value===L||ee)&&(P(K),ee&&(G.current=!0))},[b.value]),ce=m.useCallback(()=>C==null?void 0:C.focus(),[C]),be=m.useCallback((K,L,Z)=>{const ee=!G.current&&!Z;(b.value!==void 0&&b.value===L||ee)&&H(K)},[b.value]),ge=r==="popper"?pl:Fp,ye=ge===pl?{side:a,sideOffset:l,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:v,hideWhenDetached:x,avoidCollisions:g}:{};return c.jsx(Dp,{scope:n,content:C,viewport:k,onViewportChange:T,itemRefCallback:Y,selectedItem:_,onItemLeave:ce,itemTextRefCallback:be,focusSelectedItem:ne,selectedItemText:j,position:r,isPositioned:U,searchRef:se,children:c.jsx(Is,{as:xk,allowPinchZoom:!0,children:c.jsx(bs,{asChild:!0,trapped:b.open,onMountAutoFocus:K=>{K.preventDefault()},onUnmountAutoFocus:he(o,K=>{var L;(L=b.trigger)==null||L.focus({preventScroll:!0}),K.preventDefault()}),children:c.jsx(vs,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:K=>K.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:c.jsx(ge,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:K=>K.preventDefault(),...y,...ye,onPlaced:()=>D(!0),ref:I,style:{display:"flex",flexDirection:"column",outline:"none",...y.style},onKeyDown:he(y.onKeyDown,K=>{const L=K.ctrlKey||K.altKey||K.metaKey;if(K.key==="Tab"&&K.preventDefault(),!L&&K.key.length===1&&M(K.key),["ArrowUp","ArrowDown","Home","End"].includes(K.key)){let ee=F().filter(pe=>!pe.disabled).map(pe=>pe.ref.current);if(["ArrowUp","End"].includes(K.key)&&(ee=ee.slice().reverse()),["ArrowUp","ArrowDown"].includes(K.key)){const pe=K.target,oe=ee.indexOf(pe);ee=ee.slice(oe+1)}setTimeout(()=>W(ee)),K.preventDefault()}})})})})})})});Lp.displayName=gk;var yk="SelectItemAlignedPosition",Fp=m.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Qn(wr,n),i=er(wr,n),[a,l]=m.useState(null),[u,d]=m.useState(null),f=We(t,I=>d(I)),h=di(n),p=m.useRef(!1),v=m.useRef(!0),{viewport:x,selectedItem:g,selectedItemText:y,focusSelectedItem:b}=i,C=m.useCallback(()=>{if(s.trigger&&s.valueNode&&a&&u&&x&&g&&y){const I=s.trigger.getBoundingClientRect(),_=u.getBoundingClientRect(),P=s.valueNode.getBoundingClientRect(),j=y.getBoundingClientRect();if(s.dir!=="rtl"){const pe=j.left-_.left,oe=P.left-pe,ie=I.left-oe,Be=I.width+ie,Je=Math.max(Be,_.width),je=window.innerWidth-mn,He=ll(oe,[mn,Math.max(mn,je-Je)]);a.style.minWidth=Be+"px",a.style.left=He+"px"}else{const pe=_.right-j.right,oe=window.innerWidth-P.right-pe,ie=window.innerWidth-I.right-oe,Be=I.width+ie,Je=Math.max(Be,_.width),je=window.innerWidth-mn,He=ll(oe,[mn,Math.max(mn,je-Je)]);a.style.minWidth=Be+"px",a.style.right=He+"px"}const H=h(),F=window.innerHeight-mn*2,U=x.scrollHeight,D=window.getComputedStyle(u),G=parseInt(D.borderTopWidth,10),W=parseInt(D.paddingTop,10),ne=parseInt(D.borderBottomWidth,10),$=parseInt(D.paddingBottom,10),z=G+W+U+$+ne,se=Math.min(g.offsetHeight*5,z),M=window.getComputedStyle(x),Y=parseInt(M.paddingTop,10),ce=parseInt(M.paddingBottom,10),be=I.top+I.height/2-mn,ge=F-be,ye=g.offsetHeight/2,K=g.offsetTop+ye,L=G+W+K,Z=z-L;if(L<=be){const pe=H.length>0&&g===H[H.length-1].ref.current;a.style.bottom="0px";const oe=u.clientHeight-x.offsetTop-x.offsetHeight,ie=Math.max(ge,ye+(pe?ce:0)+oe+ne),Be=L+ie;a.style.height=Be+"px"}else{const pe=H.length>0&&g===H[0].ref.current;a.style.top="0px";const ie=Math.max(be,G+x.offsetTop+(pe?Y:0)+ye)+Z;a.style.height=ie+"px",x.scrollTop=L-be+x.offsetTop}a.style.margin=`${mn}px 0`,a.style.minHeight=se+"px",a.style.maxHeight=F+"px",r==null||r(),requestAnimationFrame(()=>p.current=!0)}},[h,s.trigger,s.valueNode,a,u,x,g,y,s.dir,r]);St(()=>C(),[C]);const[E,k]=m.useState();St(()=>{u&&k(window.getComputedStyle(u).zIndex)},[u]);const T=m.useCallback(I=>{I&&v.current===!0&&(C(),b==null||b(),v.current=!1)},[C,b]);return c.jsx(bk,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:p,onScrollButtonChange:T,children:c.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:E},children:c.jsx(Ee.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Fp.displayName=yk;var vk="SelectPopperPosition",pl=m.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=mn,...s}=e,i=fi(n);return c.jsx(qf,{...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)"}})});pl.displayName=vk;var[bk,ml]=Hr(wr,{}),gl="SelectViewport",$p=m.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=er(gl,n),i=ml(gl,n),a=We(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(ui.Slot,{scope:n,children:c.jsx(Ee.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:he(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-mn*2,x=parseFloat(f.style.minHeight),g=parseFloat(f.style.height),y=Math.max(x,g);if(y<v){const b=y+p,C=Math.min(v,b),E=b-C;f.style.height=C+"px",f.style.bottom==="0px"&&(d.scrollTop=E>0?E:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});$p.displayName=gl;var zp="SelectGroup",[wk,Sk]=Hr(zp),Ck=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=kn();return c.jsx(wk,{scope:n,id:o,children:c.jsx(Ee.div,{role:"group","aria-labelledby":o,...r,ref:t})})});Ck.displayName=zp;var Bp="SelectLabel",Hp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Sk(Bp,n);return c.jsx(Ee.div,{id:o.id,...r,ref:t})});Hp.displayName=Bp;var hi="SelectItem",[kk,Up]=Hr(hi),Wp=m.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Qn(hi,n),l=er(hi,n),u=a.value===r,[d,f]=m.useState(s??""),[h,p]=m.useState(!1),v=We(t,b=>{var C;return(C=l.itemRefCallback)==null?void 0:C.call(l,b,r,o)}),x=kn(),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(kk,{scope:n,value:r,disabled:o,textId:x,isSelected:u,onItemTextChange:m.useCallback(b=>{f(C=>C||((b==null?void 0:b.textContent)??"").trim())},[]),children:c.jsx(ui.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:c.jsx(Ee.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:he(i.onFocus,()=>p(!0)),onBlur:he(i.onBlur,()=>p(!1)),onClick:he(i.onClick,()=>{g.current!=="mouse"&&y()}),onPointerUp:he(i.onPointerUp,()=>{g.current==="mouse"&&y()}),onPointerDown:he(i.onPointerDown,b=>{g.current=b.pointerType}),onPointerMove:he(i.onPointerMove,b=>{var C;g.current=b.pointerType,o?(C=l.onItemLeave)==null||C.call(l):g.current==="mouse"&&b.currentTarget.focus({preventScroll:!0})}),onPointerLeave:he(i.onPointerLeave,b=>{var C;b.currentTarget===document.activeElement&&((C=l.onItemLeave)==null||C.call(l))}),onKeyDown:he(i.onKeyDown,b=>{var E;((E=l.searchRef)==null?void 0:E.current)!==""&&b.key===" "||(ck.includes(b.key)&&y(),b.key===" "&&b.preventDefault())})})})})});Wp.displayName=hi;var Eo="SelectItemText",Vp=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Qn(Eo,n),a=er(Eo,n),l=Up(Eo,n),u=hk(Eo,n),[d,f]=m.useState(null),h=We(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 St(()=>(x(v),()=>g(v)),[x,g,v]),c.jsxs(c.Fragment,{children:[c.jsx(Ee.span,{id:l.textId,...s,ref:h}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?Po.createPortal(s.children,i.valueNode):null]})});Vp.displayName=Eo;var Kp="SelectItemIndicator",qp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return Up(Kp,n).isSelected?c.jsx(Ee.span,{"aria-hidden":!0,...r,ref:t}):null});qp.displayName=Kp;var xl="SelectScrollUpButton",Gp=m.forwardRef((e,t)=>{const n=er(xl,e.__scopeSelect),r=ml(xl,e.__scopeSelect),[o,s]=m.useState(!1),i=We(t,r.onScrollButtonChange);return St(()=>{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(Xp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});Gp.displayName=xl;var yl="SelectScrollDownButton",Yp=m.forwardRef((e,t)=>{const n=er(yl,e.__scopeSelect),r=ml(yl,e.__scopeSelect),[o,s]=m.useState(!1),i=We(t,r.onScrollButtonChange);return St(()=>{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(Xp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});Yp.displayName=yl;var Xp=m.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=er("SelectScrollButton",n),i=m.useRef(null),a=di(n),l=m.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return m.useEffect(()=>()=>l(),[l]),St(()=>{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(Ee.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:he(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:he(o.onPointerMove,()=>{var u;(u=s.onItemLeave)==null||u.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:he(o.onPointerLeave,()=>{l()})})}),Tk="SelectSeparator",Jp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return c.jsx(Ee.div,{"aria-hidden":!0,...r,ref:t})});Jp.displayName=Tk;var vl="SelectArrow",Ek=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=fi(n),s=Qn(vl,n),i=er(vl,n);return s.open&&i.position==="popper"?c.jsx(Gf,{...o,...r,ref:t}):null});Ek.displayName=vl;var Ik="SelectBubbleInput",Zp=m.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=m.useRef(null),s=We(r,o),i=bp(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(Ee.select,{...n,style:{...Ip,...n.style},ref:s,defaultValue:t})});Zp.displayName=Ik;function Qp(e){return e===""||e===void 0}function em(e){const t=_t(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 tm(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=Ak(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 Ak(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Nk=Ap,nm=_p,_k=Rp,jk=Pp,Rk=Op,rm=Mp,Pk=$p,om=Hp,sm=Wp,Ok=Vp,Mk=qp,im=Gp,am=Yp,lm=Jp;const cm=Nk,um=_k,bl=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(nm,{ref:r,className:re("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(jk,{asChild:!0,children:c.jsx(me.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));bl.displayName=nm.displayName;const dm=m.forwardRef(({className:e,...t},n)=>c.jsx(im,{ref:n,className:re("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(me.ChevronUp,{className:"h-4 w-4"})}));dm.displayName=im.displayName;const fm=m.forwardRef(({className:e,...t},n)=>c.jsx(am,{ref:n,className:re("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(me.ChevronDown,{className:"h-4 w-4"})}));fm.displayName=am.displayName;const wl=m.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>c.jsx(Rk,{children:c.jsxs(rm,{ref:o,className:re("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(dm,{}),c.jsx(Pk,{className:re("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),c.jsx(fm,{})]})}));wl.displayName=rm.displayName;const Dk=m.forwardRef(({className:e,...t},n)=>c.jsx(om,{ref:n,className:re("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));Dk.displayName=om.displayName;const Sr=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(sm,{ref:r,className:re("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(Mk,{children:c.jsx(me.Check,{className:"h-4 w-4"})})}),c.jsx(Ok,{children:t})]}));Sr.displayName=sm.displayName;const Lk=m.forwardRef(({className:e,...t},n)=>c.jsx(lm,{ref:n,className:re("-mx-1 my-1 h-px bg-muted",e),...t}));Lk.displayName=lm.displayName;var Fk="Separator",hm="horizontal",$k=["horizontal","vertical"],pm=m.forwardRef((e,t)=>{const{decorative:n,orientation:r=hm,...o}=e,s=zk(r)?r:hm,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return c.jsx(Ee.div,{"data-orientation":s,...a,...o,ref:t})});pm.displayName=Fk;function zk(e){return $k.includes(e)}var mm=pm;const gm=m.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>c.jsx(mm,{ref:o,decorative:n,orientation:t,className:re("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));gm.displayName=mm.displayName;const Bk=Zd,Hk=bw,Uk=Qd,xm=m.forwardRef(({className:e,...t},n)=>c.jsx(Rs,{className:re("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}));xm.displayName=Rs.displayName;const Wk=Ro.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"}}),ym=m.forwardRef(({side:e="right",className:t,children:n,...r},o)=>c.jsxs(Uk,{children:[c.jsx(xm,{}),c.jsxs(Ps,{ref:o,className:re(Wk({side:e}),t),...r,children:[n,c.jsxs(ef,{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(me.X,{className:"h-4 w-4"}),c.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));ym.displayName=Ps.displayName;const vm=({className:e,...t})=>c.jsx("div",{className:re("flex flex-col space-y-2 text-center sm:text-left",e),...t});vm.displayName="SheetHeader";const bm=m.forwardRef(({className:e,...t},n)=>c.jsx(gr,{ref:n,className:re("text-lg font-semibold text-foreground",e),...t}));bm.displayName=gr.displayName;const wm=m.forwardRef(({className:e,...t},n)=>c.jsx(Os,{ref:n,className:re("text-sm text-muted-foreground",e),...t}));wm.displayName=Os.displayName;const Vk={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 Kk({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}=wa();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(Vk),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(Bk,{open:r,onOpenChange:o,children:[c.jsx(Hk,{asChild:!0,children:c.jsxs(Ge,{variant:"outline",size:"sm",className:n,children:[c.jsx(me.Settings,{className:"h-4 w-4 mr-2"}),"Settings",u&&c.jsx(Uu,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),c.jsxs(ym,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[c.jsxs(vm,{children:[c.jsx(bm,{children:"Chat Settings"}),c.jsx(wm,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),c.jsxs("div",{className:"space-y-6 py-6",children:[c.jsxs(uo,{children:[c.jsx(fo,{className:"pb-3",children:c.jsxs(ho,{className:"text-lg flex items-center gap-2",children:[c.jsx(me.Server,{className:"h-5 w-5"}),"API Configuration"]})}),c.jsxs(po,{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(on,{htmlFor:"api-url",children:"API Base URL"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(oi,{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(on,{htmlFor:"enable-auth",children:"Enable Authentication"}),c.jsx(Zn,{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(on,{htmlFor:"auth-token",children:"Authentication Token"}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(oi,{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(me.EyeOff,{className:"h-4 w-4"}):c.jsx(me.Eye,{className:"h-4 w-4"})})]})]})]})]}),c.jsxs(uo,{children:[c.jsx(fo,{className:"pb-3",children:c.jsxs(ho,{className:"text-lg flex items-center gap-2",children:[c.jsx(me.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),c.jsxs(po,{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(on,{htmlFor:"layout",children:"Layout Style"}),c.jsxs(cm,{value:a.ui.layout,onValueChange:g=>l(y=>({...y,ui:{...y.ui,layout:g}})),children:[c.jsx(bl,{children:c.jsx(um,{})}),c.jsxs(wl,{children:[c.jsx(Sr,{value:"sidebar",children:"Sidebar Layout"}),c.jsx(Sr,{value:"fullscreen",children:"Fullscreen"}),c.jsx(Sr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(on,{htmlFor:"theme",children:"Theme"}),c.jsxs(cm,{value:a.ui.theme,onValueChange:g=>l(y=>({...y,ui:{...y.ui,theme:g}})),children:[c.jsx(bl,{children:c.jsx(um,{})}),c.jsxs(wl,{children:[c.jsx(Sr,{value:"light",children:"Light"}),c.jsx(Sr,{value:"dark",children:"Dark"}),c.jsx(Sr,{value:"system",children:"System"})]})]})]}),c.jsx(gm,{}),c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx(on,{htmlFor:"show-timestamps",children:"Show Timestamps"}),c.jsx(Zn,{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(on,{htmlFor:"show-agent-names",children:"Show Agent Names"}),c.jsx(Zn,{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(on,{htmlFor:"compact-messages",children:"Compact Messages"}),c.jsx(Zn,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:g=>l(y=>({...y,ui:{...y.ui,compactMessages:g}}))})]})]})]})]}),c.jsxs(uo,{children:[c.jsx(fo,{className:"pb-3",children:c.jsxs(ho,{className:"text-lg flex items-center gap-2",children:[c.jsx(me.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),c.jsxs(po,{className:"space-y-4",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{children:[c.jsx(on,{htmlFor:"auto-save",children:"Auto-save Conversations"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Automatically save messages to threads"})]}),c.jsx(Zn,{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(on,{htmlFor:"enable-streaming",children:"Enable Streaming"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Stream responses in real-time"})]}),c.jsx(Zn,{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(on,{htmlFor:"typing-indicator",children:"Typing Indicator"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Show typing indicator during responses"})]}),c.jsx(Zn,{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(me.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(me.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function qk({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(Jo,{...s,onThreadChange:l,children:c.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:c.jsx(ri,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?c.jsx(Jo,{...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(hl,{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(ri,{onError:s.onError,enableFileUpload:!0})})]})})}):c.jsx(Jo,{...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(hl,{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(ri,{onError:s.onError,enableFileUpload:!0})})]})})}Ie.ChatApi=vc,Ie.ChatInterface=ri,Ie.ChatProviders=Jo,Ie.ChatSettings=Kk,Ie.MarkdownContent=ya,Ie.MessageComponent=uf,Ie.MessageList=Da,Ie.ThreadManager=hl,Ie.applySettings=ZC,Ie.chatApiClient=Hn,Ie.default=qk,Ie.del=yc,Ie.get=cn,Ie.getChatToken=pc,Ie.getCurrentSettings=JC,Ie.getDefaultApiConfig=mp,Ie.getDefaultChatSettings=gp,Ie.onChatTokenChanged=mc,Ie.post=gc,Ie.put=xc,Ie.setChatToken=Ai,Ie.useApi=Ni,Ie.useChatStream=Oc,Ie.useMessagesReducer=Ec,Ie.useStream=Uc,Ie.useThreadState=Xo,Ie.useThreads=Yo,Object.defineProperties(Ie,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
139
|
+
`).trim():n.replace(/</g,"<").replace(/>/g,">").trim()}function Bw(e,t=$s){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 Hw(e){let t;return typeof e=="string"?t=e:typeof e=="object"&&e!==null?t=JSON.stringify(e):t=String(e),Bw(t),zw(t)}function La(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=rr.createSlot(a),u=w.forwardRef((x,g)=>{const{scope:y,children:b}=x,S=s(a,y),E=Be(g,S.collectionRef);return c.jsx(l,{ref:E,children:b})});u.displayName=a;const d=e+"CollectionItemSlot",f="data-radix-collection-item",h=rr.createSlot(d),p=w.forwardRef((x,g)=>{const{scope:y,children:b,...S}=x,E=w.useRef(null),k=Be(g,E),T=s(d,y);return w.useEffect(()=>(T.itemMap.set(E,{ref:E,...S}),()=>void T.itemMap.delete(E))),c.jsx(h,{[f]:"",ref:k,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,I)=>S.indexOf(T.ref.current)-S.indexOf(I.ref.current))},[g.collectionRef,g.itemMap])}return[{Provider:i,Slot:u,ItemSlot:p},v,r]}var Uw=m.createContext(void 0);function zs(e){const t=m.useContext(Uw);return e||t||"ltr"}const Ww=["top","right","bottom","left"],Gn=Math.min,Vt=Math.max,Bs=Math.round,Hs=Math.floor,kn=e=>({x:e,y:e}),Vw={left:"right",right:"left",bottom:"top",top:"bottom"},Kw={start:"end",end:"start"};function Fa(e,t,n){return Vt(e,Gn(t,n))}function Mn(e,t){return typeof e=="function"?e(t):e}function Dn(e){return e.split("-")[0]}function Dr(e){return e.split("-")[1]}function $a(e){return e==="x"?"y":"x"}function za(e){return e==="y"?"height":"width"}const qw=new Set(["top","bottom"]);function Tn(e){return qw.has(Dn(e))?"y":"x"}function Ba(e){return $a(Tn(e))}function Gw(e,t,n){n===void 0&&(n=!1);const r=Dr(e),o=Ba(e),s=za(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=Us(i)),[i,Us(i)]}function Yw(e){const t=Us(e);return[Ha(e),t,Ha(t)]}function Ha(e){return e.replace(/start|end/g,t=>Kw[t])}const ff=["left","right"],hf=["right","left"],Xw=["top","bottom"],Jw=["bottom","top"];function Zw(e,t,n){switch(e){case"top":case"bottom":return n?t?hf:ff:t?ff:hf;case"left":case"right":return t?Xw:Jw;default:return[]}}function Qw(e,t,n,r){const o=Dr(e);let s=Zw(Dn(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(Ha)))),s}function Us(e){return e.replace(/left|right|bottom|top/g,t=>Vw[t])}function e0(e){return{top:0,right:0,bottom:0,left:0,...e}}function pf(e){return typeof e!="number"?e0(e):{top:e,right:e,bottom:e,left:e}}function Ws(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 mf(e,t,n){let{reference:r,floating:o}=e;const s=Tn(t),i=Ba(t),a=za(i),l=Dn(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(Dr(t)){case"start":p[i]-=h*(n&&u?-1:1);break;case"end":p[i]+=h*(n&&u?-1:1);break}return p}const t0=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}=mf(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:E,reset:k}=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],...E}},k&&v<=50&&(v++,typeof k=="object"&&(k.placement&&(h=k.placement),k.rects&&(u=k.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):k.rects),{x:d,y:f}=mf(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}=Mn(t,e),v=pf(p),g=a[h?f==="floating"?"reference":"floating":f],y=Ws(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)),E=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},k=Ws(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:b,offsetParent:S,strategy:l}):b);return{top:(y.top-k.top+v.top)/E.y,bottom:(k.bottom-y.bottom+v.bottom)/E.y,left:(y.left-k.left+v.left)/E.x,right:(k.right-y.right+v.right)/E.x}}const n0=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}=Mn(e,t)||{};if(u==null)return{};const f=pf(d),h={x:n,y:r},p=Ba(o),v=za(p),x=await i.getDimensions(u),g=p==="y",y=g?"top":"left",b=g?"bottom":"right",S=g?"clientHeight":"clientWidth",E=s.reference[v]+s.reference[p]-h[p]-s.floating[v],k=h[p]-s.reference[p],T=await(i.getOffsetParent==null?void 0:i.getOffsetParent(u));let I=T?T[S]:0;(!I||!await(i.isElement==null?void 0:i.isElement(T)))&&(I=a.floating[S]||s.floating[v]);const _=E/2-k/2,O=I/2-x[v]/2-1,j=Gn(f[y],O),U=Gn(f[b],O),L=j,W=I-x[v]-U,R=I/2-x[v]/2+_,V=Fa(L,R,W),$=!l.arrow&&Dr(o)!=null&&R!==V&&s.reference[v]/2-(R<L?j:U)-x[v]/2<0,ne=$?R<L?R-L:R-W:0;return{[p]:h[p]+ne,data:{[p]:V,centerOffset:R-V-ne,...$&&{alignmentOffset:ne}},reset:$}}}),r0=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}=Mn(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const y=Dn(o),b=Tn(a),S=Dn(a)===a,E=await(l.isRTL==null?void 0:l.isRTL(u.floating)),k=h||(S||!x?[Us(a)]:Yw(a)),T=v!=="none";!h&&T&&k.push(...Qw(a,x,v,E));const I=[a,...k],_=await yo(t,g),O=[];let j=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&O.push(_[y]),f){const R=Gw(o,i,E);O.push(_[R[0]],_[R[1]])}if(j=[...j,{placement:o,overflows:O}],!O.every(R=>R<=0)){var U,L;const R=(((U=s.flip)==null?void 0:U.index)||0)+1,V=I[R];if(V&&(!(f==="alignment"?b!==Tn(V):!1)||j.every(F=>Tn(F.placement)===b?F.overflows[0]>0:!0)))return{data:{index:R,overflows:j},reset:{placement:V}};let $=(L=j.filter(ne=>ne.overflows[0]<=0).sort((ne,F)=>ne.overflows[1]-F.overflows[1])[0])==null?void 0:L.placement;if(!$)switch(p){case"bestFit":{var W;const ne=(W=j.filter(F=>{if(T){const B=Tn(F.placement);return B===b||B==="y"}return!0}).map(F=>[F.placement,F.overflows.filter(B=>B>0).reduce((B,le)=>B+le,0)]).sort((F,B)=>F[1]-B[1])[0])==null?void 0:W[0];ne&&($=ne);break}case"initialPlacement":$=a;break}if(o!==$)return{reset:{placement:$}}}return{}}}};function gf(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function xf(e){return Ww.some(t=>e[t]>=0)}const o0=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=Mn(e,t);switch(r){case"referenceHidden":{const s=await yo(t,{...o,elementContext:"reference"}),i=gf(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:xf(i)}}}case"escaped":{const s=await yo(t,{...o,altBoundary:!0}),i=gf(s,n.floating);return{data:{escapedOffsets:i,escaped:xf(i)}}}default:return{}}}}},yf=new Set(["left","top"]);async function s0(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=Dn(n),a=Dr(n),l=Tn(n)==="y",u=yf.has(i)?-1:1,d=s&&l?-1:1,f=Mn(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 i0=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 s0(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}}}}},a0=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}=Mn(e,t),u={x:n,y:r},d=await yo(t,l),f=Tn(Dn(o)),h=$a(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=Fa(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=Fa(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}}}}}},l0=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}=Mn(e,t),d={x:n,y:r},f=Tn(o),h=$a(f);let p=d[h],v=d[f];const x=Mn(a,t),g=typeof x=="number"?{mainAxis:x,crossAxis:0}:{mainAxis:0,crossAxis:0,...x};if(l){const S=h==="y"?"height":"width",E=s.reference[h]-s.floating[S]+g.mainAxis,k=s.reference[h]+s.reference[S]-g.mainAxis;p<E?p=E:p>k&&(p=k)}if(u){var y,b;const S=h==="y"?"width":"height",E=yf.has(Dn(o)),k=s.reference[f]-s.floating[S]+(E&&((y=i.offset)==null?void 0:y[f])||0)+(E?0:g.crossAxis),T=s.reference[f]+s.reference[S]+(E?0:((b=i.offset)==null?void 0:b[f])||0)-(E?g.crossAxis:0);v<k?v=k:v>T&&(v=T)}return{[h]:p,[f]:v}}}},c0=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}=Mn(e,t),d=await yo(t,u),f=Dn(o),h=Dr(o),p=Tn(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,E=Gn(x-d[g],b),k=Gn(v-d[y],S),T=!t.middlewareData.shift;let I=E,_=k;if((n=t.middlewareData.shift)!=null&&n.enabled.x&&(_=S),(r=t.middlewareData.shift)!=null&&r.enabled.y&&(I=b),T&&!h){const j=Vt(d.left,0),U=Vt(d.right,0),L=Vt(d.top,0),W=Vt(d.bottom,0);p?_=v-2*(j!==0||U!==0?j+U:Vt(d.left,d.right)):I=x-2*(L!==0||W!==0?L+W:Vt(d.top,d.bottom))}await l({...t,availableWidth:_,availableHeight:I});const O=await i.getDimensions(a.floating);return v!==O.width||x!==O.height?{reset:{rects:!0}}:{}}}};function Vs(){return typeof window<"u"}function Lr(e){return vf(e)?(e.nodeName||"").toLowerCase():"#document"}function Kt(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function En(e){var t;return(t=(vf(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function vf(e){return Vs()?e instanceof Node||e instanceof Kt(e).Node:!1}function un(e){return Vs()?e instanceof Element||e instanceof Kt(e).Element:!1}function In(e){return Vs()?e instanceof HTMLElement||e instanceof Kt(e).HTMLElement:!1}function bf(e){return!Vs()||typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Kt(e).ShadowRoot}const u0=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)&&!u0.has(o)}const d0=new Set(["table","td","th"]);function f0(e){return d0.has(Lr(e))}const h0=[":popover-open",":modal"];function Ks(e){return h0.some(t=>{try{return e.matches(t)}catch{return!1}})}const p0=["transform","translate","scale","rotate","perspective"],m0=["transform","translate","scale","rotate","perspective","filter"],g0=["paint","layout","strict","content"];function Ua(e){const t=Wa(),n=un(e)?dn(e):e;return p0.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)||m0.some(r=>(n.willChange||"").includes(r))||g0.some(r=>(n.contain||"").includes(r))}function x0(e){let t=Yn(e);for(;In(t)&&!Fr(t);){if(Ua(t))return t;if(Ks(t))return null;t=Yn(t)}return null}function Wa(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const y0=new Set(["html","body","#document"]);function Fr(e){return y0.has(Lr(e))}function dn(e){return Kt(e).getComputedStyle(e)}function qs(e){return un(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function Yn(e){if(Lr(e)==="html")return e;const t=e.assignedSlot||e.parentNode||bf(e)&&e.host||En(e);return bf(t)?t.host:t}function wf(e){const t=Yn(e);return Fr(t)?e.ownerDocument?e.ownerDocument.body:e.body:In(t)&&vo(t)?t:wf(t)}function bo(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=wf(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Kt(o);if(s){const a=Va(i);return t.concat(i,i.visualViewport||[],vo(o)?o:[],a&&n?bo(a):[])}return t.concat(o,bo(o,[],n))}function Va(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}function Sf(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=Bs(n)!==s||Bs(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function Ka(e){return un(e)?e:e.contextElement}function $r(e){const t=Ka(e);if(!In(t))return kn(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=Sf(t);let i=(s?Bs(n.width):n.width)/r,a=(s?Bs(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const v0=kn(0);function Cf(e){const t=Kt(e);return!Wa()||!t.visualViewport?v0:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function b0(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Kt(e)?!1:t}function xr(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=Ka(e);let i=kn(1);t&&(r?un(r)&&(i=$r(r)):i=$r(e));const a=b0(s,n,r)?Cf(s):kn(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&&un(r)?Kt(r):r;let v=h,x=Va(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,E=y.top+(x.clientTop+parseFloat(b.paddingTop))*g.y;l*=g.x,u*=g.y,d*=g.x,f*=g.y,l+=S,u+=E,v=Kt(x),x=Va(v)}}return Ws({width:d,height:f,x:l,y:u})}function Gs(e,t){const n=qs(e).scrollLeft;return t?t.left+n:xr(En(e)).left+n}function kf(e,t){const n=e.getBoundingClientRect(),r=n.left+t.scrollLeft-Gs(e,n),o=n.top+t.scrollTop;return{x:r,y:o}}function w0(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=En(r),a=t?Ks(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},u=kn(1);const d=kn(0),f=In(r);if((f||!f&&!s)&&((Lr(r)!=="body"||vo(i))&&(l=qs(r)),In(r))){const p=xr(r);u=$r(r),d.x=p.x+r.clientLeft,d.y=p.y+r.clientTop}const h=i&&!f&&!s?kf(i,l):kn(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 S0(e){return Array.from(e.getClientRects())}function C0(e){const t=En(e),n=qs(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+Gs(e);const a=-n.scrollTop;return dn(r).direction==="rtl"&&(i+=Vt(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}const Tf=25;function k0(e,t){const n=Kt(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=Wa();(!d||d&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}const u=Gs(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<=Tf&&(s-=v)}else u<=Tf&&(s+=u);return{width:s,height:i,x:a,y:l}}const T0=new Set(["absolute","fixed"]);function E0(e,t){const n=xr(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=In(e)?$r(e):kn(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 Ef(e,t,n){let r;if(t==="viewport")r=k0(e,n);else if(t==="document")r=C0(En(e));else if(un(t))r=E0(t,n);else{const o=Cf(e);r={x:t.x-o.x,y:t.y-o.y,width:t.width,height:t.height}}return Ws(r)}function If(e,t){const n=Yn(e);return n===t||!un(n)||Fr(n)?!1:dn(n).position==="fixed"||If(n,t)}function I0(e,t){const n=t.get(e);if(n)return n;let r=bo(e,[],!1).filter(a=>un(a)&&Lr(a)!=="body"),o=null;const s=dn(e).position==="fixed";let i=s?Yn(e):e;for(;un(i)&&!Fr(i);){const a=dn(i),l=Ua(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&T0.has(o.position)||vo(i)&&!l&&If(e,i))?r=r.filter(d=>d!==i):o=a,i=Yn(i)}return t.set(e,r),r}function A0(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?Ks(t)?[]:I0(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((u,d)=>{const f=Ef(t,d,o);return u.top=Vt(f.top,u.top),u.right=Gn(f.right,u.right),u.bottom=Gn(f.bottom,u.bottom),u.left=Vt(f.left,u.left),u},Ef(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function N0(e){const{width:t,height:n}=Sf(e);return{width:t,height:n}}function _0(e,t,n){const r=In(t),o=En(t),s=n==="fixed",i=xr(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=kn(0);function u(){l.x=Gs(o)}if(r||!r&&!s)if((Lr(t)!=="body"||vo(o))&&(a=qs(t)),r){const p=xr(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?kf(o,a):kn(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 qa(e){return dn(e).position==="static"}function Af(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 Nf(e,t){const n=Kt(e);if(Ks(e))return n;if(!In(e)){let o=Yn(e);for(;o&&!Fr(o);){if(un(o)&&!qa(o))return o;o=Yn(o)}return n}let r=Af(e,t);for(;r&&f0(r)&&qa(r);)r=Af(r,t);return r&&Fr(r)&&qa(r)&&!Ua(r)?n:r||x0(e)||n}const j0=async function(e){const t=this.getOffsetParent||Nf,n=this.getDimensions,r=await n(e.floating);return{reference:_0(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function R0(e){return dn(e).direction==="rtl"}const P0={convertOffsetParentRelativeRectToViewportRelativeRect:w0,getDocumentElement:En,getClippingRect:A0,getOffsetParent:Nf,getElementRects:j0,getClientRects:S0,getDimensions:N0,getScale:$r,isElement:un,isRTL:R0};function _f(e,t){return e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height}function O0(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=Hs(f),x=Hs(o.clientWidth-(d+h)),g=Hs(o.clientHeight-(f+p)),y=Hs(d),S={rootMargin:-v+"px "+-x+"px "+-g+"px "+-y+"px",threshold:Vt(0,Gn(1,l))||1};let E=!0;function k(T){const I=T[0].intersectionRatio;if(I!==l){if(!E)return i();I?i(!1,I):r=setTimeout(()=>{i(!1,1e-7)},1e3)}I===1&&!_f(u,e.getBoundingClientRect())&&i(),E=!1}try{n=new IntersectionObserver(k,{...S,root:o.ownerDocument})}catch{n=new IntersectionObserver(k,S)}n.observe(e)}return i(!0),s}function M0(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=Ka(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?O0(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?xr(e):null;l&&g();function g(){const y=xr(e);x&&!_f(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 D0=i0,L0=a0,F0=r0,$0=c0,z0=o0,jf=n0,B0=l0,H0=(e,t,n)=>{const r=new Map,o={platform:P0,...n},s={...o.platform,_c:r};return t0(e,t,{...o,platform:s})};var U0=typeof document<"u",W0=function(){},Ys=U0?w.useLayoutEffect:W0;function Xs(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,o;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!Xs(e[r],t[r]))return!1;return!0}if(o=Object.keys(e),n=o.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,o[r]))return!1;for(r=n;r--!==0;){const s=o[r];if(!(s==="_owner"&&e.$$typeof)&&!Xs(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function Rf(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function Pf(e,t){const n=Rf(e);return Math.round(t*n)/n}function Ga(e){const t=m.useRef(e);return Ys(()=>{t.current=e}),t}function V0(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);Xs(h,r)||p(r);const[v,x]=m.useState(null),[g,y]=m.useState(null),b=m.useCallback(F=>{F!==T.current&&(T.current=F,x(F))},[]),S=m.useCallback(F=>{F!==I.current&&(I.current=F,y(F))},[]),E=s||v,k=i||g,T=m.useRef(null),I=m.useRef(null),_=m.useRef(d),O=l!=null,j=Ga(l),U=Ga(o),L=Ga(u),W=m.useCallback(()=>{if(!T.current||!I.current)return;const F={placement:t,strategy:n,middleware:h};U.current&&(F.platform=U.current),H0(T.current,I.current,F).then(B=>{const le={...B,isPositioned:L.current!==!1};R.current&&!Xs(_.current,le)&&(_.current=le,Oo.flushSync(()=>{f(le)}))})},[h,t,n,U,L]);Ys(()=>{u===!1&&_.current.isPositioned&&(_.current.isPositioned=!1,f(F=>({...F,isPositioned:!1})))},[u]);const R=m.useRef(!1);Ys(()=>(R.current=!0,()=>{R.current=!1}),[]),Ys(()=>{if(E&&(T.current=E),k&&(I.current=k),E&&k){if(j.current)return j.current(E,k,W);W()}},[E,k,W,j,O]);const V=m.useMemo(()=>({reference:T,floating:I,setReference:b,setFloating:S}),[b,S]),$=m.useMemo(()=>({reference:E,floating:k}),[E,k]),ne=m.useMemo(()=>{const F={position:n,left:0,top:0};if(!$.floating)return F;const B=Pf($.floating,d.x),le=Pf($.floating,d.y);return a?{...F,transform:"translate("+B+"px, "+le+"px)",...Rf($.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:B,top:le}},[n,a,$.floating,d.x,d.y]);return m.useMemo(()=>({...d,update:W,refs:V,elements:$,floatingStyles:ne}),[d,W,V,$,ne])}const K0=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?jf({element:r.current,padding:o}).fn(n):{}:r?jf({element:r,padding:o}).fn(n):{}}}},q0=(e,t)=>({...D0(e),options:[e,t]}),G0=(e,t)=>({...L0(e),options:[e,t]}),Y0=(e,t)=>({...B0(e),options:[e,t]}),X0=(e,t)=>({...F0(e),options:[e,t]}),J0=(e,t)=>({...$0(e),options:[e,t]}),Z0=(e,t)=>({...z0(e),options:[e,t]}),Q0=(e,t)=>({...K0(e),options:[e,t]});var eS="Arrow",Of=m.forwardRef((e,t)=>{const{children:n,width:r=10,height:o=5,...s}=e;return c.jsx(Ee.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"})})});Of.displayName=eS;var tS=Of;function Mf(e){const[t,n]=m.useState(void 0);return gt(()=>{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 Ya="Popper",[Df,Js]=wn(Ya),[nS,Lf]=Df(Ya),Ff=e=>{const{__scopePopper:t,children:n}=e,[r,o]=m.useState(null);return c.jsx(nS,{scope:t,anchor:r,onAnchorChange:o,children:n})};Ff.displayName=Ya;var $f="PopperAnchor",zf=m.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=Lf($f,n),i=m.useRef(null),a=Be(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(Ee.div,{...o,ref:a})});zf.displayName=$f;var Xa="PopperContent",[rS,oS]=Df(Xa),Bf=m.forwardRef((e,t)=>{var Z,D,J,Q,de,ee;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=Lf(Xa,n),[y,b]=m.useState(null),S=Be(t,se=>b(se)),[E,k]=m.useState(null),T=Mf(E),I=(T==null?void 0:T.width)??0,_=(T==null?void 0:T.height)??0,O=r+(s!=="center"?"-"+s:""),j=typeof d=="number"?d:{top:0,right:0,bottom:0,left:0,...d},U=Array.isArray(u)?u:[u],L=U.length>0,W={padding:j,boundary:U.filter(iS),altBoundary:L},{refs:R,floatingStyles:V,placement:$,isPositioned:ne,middlewareData:F}=V0({strategy:"fixed",placement:O,whileElementsMounted:(...se)=>M0(...se,{animationFrame:p==="always"}),elements:{reference:g.anchor},middleware:[q0({mainAxis:o+_,alignmentAxis:i}),l&&G0({mainAxis:!0,crossAxis:!1,limiter:f==="partial"?Y0():void 0,...W}),l&&X0({...W}),J0({...W,apply:({elements:se,rects:Ge,availableWidth:Ye,availableHeight:Pe})=>{const{width:He,height:nt}=Ge.reference,Qe=se.floating.style;Qe.setProperty("--radix-popper-available-width",`${Ye}px`),Qe.setProperty("--radix-popper-available-height",`${Pe}px`),Qe.setProperty("--radix-popper-anchor-width",`${He}px`),Qe.setProperty("--radix-popper-anchor-height",`${nt}px`)}}),E&&Q0({element:E,padding:a}),aS({arrowWidth:I,arrowHeight:_}),h&&Z0({strategy:"referenceHidden",...W})]}),[B,le]=Wf($),z=Ct(v);gt(()=>{ne&&(z==null||z())},[ne,z]);const oe=(Z=F.arrow)==null?void 0:Z.x,pe=(D=F.arrow)==null?void 0:D.y,ge=((J=F.arrow)==null?void 0:J.centerOffset)!==0,[me,ve]=m.useState();return gt(()=>{y&&ve(window.getComputedStyle(y).zIndex)},[y]),c.jsx("div",{ref:R.setFloating,"data-radix-popper-content-wrapper":"",style:{...V,transform:ne?V.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:me,"--radix-popper-transform-origin":[(Q=F.transformOrigin)==null?void 0:Q.x,(de=F.transformOrigin)==null?void 0:de.y].join(" "),...((ee=F.hide)==null?void 0:ee.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:c.jsx(rS,{scope:n,placedSide:B,onArrowChange:k,arrowX:oe,arrowY:pe,shouldHideArrow:ge,children:c.jsx(Ee.div,{"data-side":B,"data-align":le,...x,ref:S,style:{...x.style,animation:ne?void 0:"none"}})})})});Bf.displayName=Xa;var Hf="PopperArrow",sS={top:"bottom",right:"left",bottom:"top",left:"right"},Uf=m.forwardRef(function(t,n){const{__scopePopper:r,...o}=t,s=oS(Hf,r),i=sS[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(tS,{...o,ref:n,style:{...o.style,display:"block"}})})});Uf.displayName=Hf;function iS(e){return e!==null}var aS=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]=Wf(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 Wf(e){const[t,n="center"]=e.split("-");return[t,n]}var Vf=Ff,Kf=zf,qf=Bf,Gf=Uf,Ja="rovingFocusGroup.onEntryFocus",lS={bubbles:!1,cancelable:!0},wo="RovingFocusGroup",[Za,Yf,cS]=La(wo),[uS,Xf]=wn(wo,[cS]),[dS,fS]=uS(wo),Jf=m.forwardRef((e,t)=>c.jsx(Za.Provider,{scope:e.__scopeRovingFocusGroup,children:c.jsx(Za.Slot,{scope:e.__scopeRovingFocusGroup,children:c.jsx(hS,{...e,ref:t})})}));Jf.displayName=wo;var hS=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=Be(t,h),v=zs(s),[x,g]=fr({prop:i,defaultProp:a??null,onChange:l,caller:wo}),[y,b]=m.useState(!1),S=Ct(u),E=Yf(n),k=m.useRef(!1),[T,I]=m.useState(0);return m.useEffect(()=>{const _=h.current;if(_)return _.addEventListener(Ja,S),()=>_.removeEventListener(Ja,S)},[S]),c.jsx(dS,{scope:n,orientation:r,dir:v,loop:o,currentTabStopId:x,onItemFocus:m.useCallback(_=>g(_),[g]),onItemShiftTab:m.useCallback(()=>b(!0),[]),onFocusableItemAdd:m.useCallback(()=>I(_=>_+1),[]),onFocusableItemRemove:m.useCallback(()=>I(_=>_-1),[]),children:c.jsx(Ee.div,{tabIndex:y||T===0?-1:0,"data-orientation":r,...f,ref:p,style:{outline:"none",...e.style},onMouseDown:fe(e.onMouseDown,()=>{k.current=!0}),onFocus:fe(e.onFocus,_=>{const O=!k.current;if(_.target===_.currentTarget&&O&&!y){const j=new CustomEvent(Ja,lS);if(_.currentTarget.dispatchEvent(j),!j.defaultPrevented){const U=E().filter($=>$.focusable),L=U.find($=>$.active),W=U.find($=>$.id===x),V=[L,W,...U].filter(Boolean).map($=>$.ref.current);eh(V,d)}}k.current=!1}),onBlur:fe(e.onBlur,()=>b(!1))})})}),Zf="RovingFocusGroupItem",Qf=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=fS(Zf,n),f=d.currentTabStopId===u,h=Yf(n),{onFocusableItemAdd:p,onFocusableItemRemove:v,currentTabStopId:x}=d;return m.useEffect(()=>{if(r)return p(),()=>v()},[r,p,v]),c.jsx(Za.ItemSlot,{scope:n,id:u,focusable:r,active:o,children:c.jsx(Ee.span,{tabIndex:f?0:-1,"data-orientation":d.orientation,...a,ref:t,onMouseDown:fe(e.onMouseDown,g=>{r?d.onItemFocus(u):g.preventDefault()}),onFocus:fe(e.onFocus,()=>d.onItemFocus(u)),onKeyDown:fe(e.onKeyDown,g=>{if(g.key==="Tab"&&g.shiftKey){d.onItemShiftTab();return}if(g.target!==g.currentTarget)return;const y=gS(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(E=>E.focusable).map(E=>E.ref.current);if(y==="last")S.reverse();else if(y==="prev"||y==="next"){y==="prev"&&S.reverse();const E=S.indexOf(g.currentTarget);S=d.loop?xS(S,E+1):S.slice(E+1)}setTimeout(()=>eh(S))}}),children:typeof i=="function"?i({isCurrentTabStop:f,hasTabStop:x!=null}):i})})});Qf.displayName=Zf;var pS={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function mS(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function gS(e,t,n){const r=mS(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return pS[r]}function eh(e,t=!1){const n=document.activeElement;for(const r of e)if(r===n||(r.focus({preventScroll:t}),document.activeElement!==n))return}function xS(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var yS=Jf,vS=Qf,Qa=["Enter"," "],bS=["ArrowDown","PageUp","Home"],th=["ArrowUp","PageDown","End"],wS=[...bS,...th],SS={ltr:[...Qa,"ArrowRight"],rtl:[...Qa,"ArrowLeft"]},CS={ltr:["ArrowLeft"],rtl:["ArrowRight"]},So="Menu",[Co,kS,TS]=La(So),[yr,nh]=wn(So,[TS,Js,Xf]),Zs=Js(),rh=Xf(),[ES,vr]=yr(So),[IS,ko]=yr(So),oh=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=Zs(t),[l,u]=m.useState(null),d=m.useRef(!1),f=Ct(s),h=zs(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(Vf,{...a,children:c.jsx(ES,{scope:t,open:n,onOpenChange:f,content:l,onContentChange:u,children:c.jsx(IS,{scope:t,onClose:m.useCallback(()=>f(!1),[f]),isUsingKeyboardRef:d,dir:h,modal:i,children:r})})})};oh.displayName=So;var AS="MenuAnchor",el=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Zs(n);return c.jsx(Kf,{...o,...r,ref:t})});el.displayName=AS;var tl="MenuPortal",[NS,sh]=yr(tl,{forceMount:void 0}),ih=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=vr(tl,t);return c.jsx(NS,{scope:t,forceMount:n,children:c.jsx(Wt,{present:n||s.open,children:c.jsx(Ss,{asChild:!0,container:o,children:r})})})};ih.displayName=tl;var Qt="MenuContent",[_S,nl]=yr(Qt),ah=m.forwardRef((e,t)=>{const n=sh(Qt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=vr(Qt,e.__scopeMenu),i=ko(Qt,e.__scopeMenu);return c.jsx(Co.Provider,{scope:e.__scopeMenu,children:c.jsx(Wt,{present:r||s.open,children:c.jsx(Co.Slot,{scope:e.__scopeMenu,children:i.modal?c.jsx(jS,{...o,ref:t}):c.jsx(RS,{...o,ref:t})})})})}),jS=m.forwardRef((e,t)=>{const n=vr(Qt,e.__scopeMenu),r=m.useRef(null),o=Be(t,r);return m.useEffect(()=>{const s=r.current;if(s)return Ra(s)},[]),c.jsx(rl,{...e,ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:fe(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),RS=m.forwardRef((e,t)=>{const n=vr(Qt,e.__scopeMenu);return c.jsx(rl,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),PS=rr.createSlot("MenuContent.ScrollLock"),rl=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=vr(Qt,n),y=ko(Qt,n),b=Zs(n),S=rh(n),E=kS(n),[k,T]=m.useState(null),I=m.useRef(null),_=Be(t,I,g.onContentChange),O=m.useRef(0),j=m.useRef(""),U=m.useRef(0),L=m.useRef(null),W=m.useRef("right"),R=m.useRef(0),V=v?As:m.Fragment,$=v?{as:PS,allowPinchZoom:!0}:void 0,ne=B=>{var Z,D;const le=j.current+B,z=E().filter(J=>!J.disabled),oe=document.activeElement,pe=(Z=z.find(J=>J.ref.current===oe))==null?void 0:Z.textValue,ge=z.map(J=>J.textValue),me=VS(ge,le,pe),ve=(D=z.find(J=>J.textValue===me))==null?void 0:D.ref.current;(function J(Q){j.current=Q,window.clearTimeout(O.current),Q!==""&&(O.current=window.setTimeout(()=>J(""),1e3))})(le),ve&&setTimeout(()=>ve.focus())};m.useEffect(()=>()=>window.clearTimeout(O.current),[]),Ea();const F=m.useCallback(B=>{var z,oe;return W.current===((z=L.current)==null?void 0:z.side)&&qS(B,(oe=L.current)==null?void 0:oe.area)},[]);return c.jsx(_S,{scope:n,searchRef:j,onItemEnter:m.useCallback(B=>{F(B)&&B.preventDefault()},[F]),onItemLeave:m.useCallback(B=>{var le;F(B)||((le=I.current)==null||le.focus(),T(null))},[F]),onTriggerLeave:m.useCallback(B=>{F(B)&&B.preventDefault()},[F]),pointerGraceTimerRef:U,onPointerGraceIntentChange:m.useCallback(B=>{L.current=B},[]),children:c.jsx(V,{...$,children:c.jsx(ws,{asChild:!0,trapped:o,onMountAutoFocus:fe(s,B=>{var le;B.preventDefault(),(le=I.current)==null||le.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:c.jsx(bs,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:u,onPointerDownOutside:d,onFocusOutside:f,onInteractOutside:h,onDismiss:p,children:c.jsx(yS,{asChild:!0,...S,dir:y.dir,orientation:"vertical",loop:r,currentTabStopId:k,onCurrentTabStopIdChange:T,onEntryFocus:fe(l,B=>{y.isUsingKeyboardRef.current||B.preventDefault()}),preventScrollOnEntryFocus:!0,children:c.jsx(qf,{role:"menu","aria-orientation":"vertical","data-state":kh(g.open),"data-radix-menu-content":"",dir:y.dir,...b,...x,ref:_,style:{outline:"none",...x.style},onKeyDown:fe(x.onKeyDown,B=>{const z=B.target.closest("[data-radix-menu-content]")===B.currentTarget,oe=B.ctrlKey||B.altKey||B.metaKey,pe=B.key.length===1;z&&(B.key==="Tab"&&B.preventDefault(),!oe&&pe&&ne(B.key));const ge=I.current;if(B.target!==ge||!wS.includes(B.key))return;B.preventDefault();const ve=E().filter(Z=>!Z.disabled).map(Z=>Z.ref.current);th.includes(B.key)&&ve.reverse(),US(ve)}),onBlur:fe(e.onBlur,B=>{B.currentTarget.contains(B.target)||(window.clearTimeout(O.current),j.current="")}),onPointerMove:fe(e.onPointerMove,Eo(B=>{const le=B.target,z=R.current!==B.clientX;if(B.currentTarget.contains(le)&&z){const oe=B.clientX>R.current?"right":"left";W.current=oe,R.current=B.clientX}}))})})})})})})});ah.displayName=Qt;var OS="MenuGroup",ol=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(Ee.div,{role:"group",...r,ref:t})});ol.displayName=OS;var MS="MenuLabel",lh=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(Ee.div,{...r,ref:t})});lh.displayName=MS;var Qs="MenuItem",ch="menu.itemSelect",ei=m.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=m.useRef(null),i=ko(Qs,e.__scopeMenu),a=nl(Qs,e.__scopeMenu),l=Be(t,s),u=m.useRef(!1),d=()=>{const f=s.current;if(!n&&f){const h=new CustomEvent(ch,{bubbles:!0,cancelable:!0});f.addEventListener(ch,p=>r==null?void 0:r(p),{once:!0}),Vu(f,h),h.defaultPrevented?u.current=!1:i.onClose()}};return c.jsx(uh,{...o,ref:l,disabled:n,onClick:fe(e.onClick,d),onPointerDown:f=>{var h;(h=e.onPointerDown)==null||h.call(e,f),u.current=!0},onPointerUp:fe(e.onPointerUp,f=>{var h;u.current||(h=f.currentTarget)==null||h.click()}),onKeyDown:fe(e.onKeyDown,f=>{const h=a.searchRef.current!=="";n||h&&f.key===" "||Qa.includes(f.key)&&(f.currentTarget.click(),f.preventDefault())})})});ei.displayName=Qs;var uh=m.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=nl(Qs,n),a=rh(n),l=m.useRef(null),u=Be(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(vS,{asChild:!0,...a,focusable:!r,children:c.jsx(Ee.div,{role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:u,onPointerMove:fe(e.onPointerMove,Eo(v=>{r?i.onItemLeave(v):(i.onItemEnter(v),v.defaultPrevented||v.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:fe(e.onPointerLeave,Eo(v=>i.onItemLeave(v))),onFocus:fe(e.onFocus,()=>f(!0)),onBlur:fe(e.onBlur,()=>f(!1))})})})}),DS="MenuCheckboxItem",dh=m.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return c.jsx(gh,{scope:e.__scopeMenu,checked:n,children:c.jsx(ei,{role:"menuitemcheckbox","aria-checked":ti(n)?"mixed":n,...o,ref:t,"data-state":il(n),onSelect:fe(o.onSelect,()=>r==null?void 0:r(ti(n)?!0:!n),{checkForDefaultPrevented:!1})})})});dh.displayName=DS;var fh="MenuRadioGroup",[LS,FS]=yr(fh,{value:void 0,onValueChange:()=>{}}),hh=m.forwardRef((e,t)=>{const{value:n,onValueChange:r,...o}=e,s=Ct(r);return c.jsx(LS,{scope:e.__scopeMenu,value:n,onValueChange:s,children:c.jsx(ol,{...o,ref:t})})});hh.displayName=fh;var ph="MenuRadioItem",mh=m.forwardRef((e,t)=>{const{value:n,...r}=e,o=FS(ph,e.__scopeMenu),s=n===o.value;return c.jsx(gh,{scope:e.__scopeMenu,checked:s,children:c.jsx(ei,{role:"menuitemradio","aria-checked":s,...r,ref:t,"data-state":il(s),onSelect:fe(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,n)},{checkForDefaultPrevented:!1})})})});mh.displayName=ph;var sl="MenuItemIndicator",[gh,$S]=yr(sl,{checked:!1}),xh=m.forwardRef((e,t)=>{const{__scopeMenu:n,forceMount:r,...o}=e,s=$S(sl,n);return c.jsx(Wt,{present:r||ti(s.checked)||s.checked===!0,children:c.jsx(Ee.span,{...o,ref:t,"data-state":il(s.checked)})})});xh.displayName=sl;var zS="MenuSeparator",yh=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return c.jsx(Ee.div,{role:"separator","aria-orientation":"horizontal",...r,ref:t})});yh.displayName=zS;var BS="MenuArrow",vh=m.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=Zs(n);return c.jsx(Gf,{...o,...r,ref:t})});vh.displayName=BS;var HS="MenuSub",[TT,bh]=yr(HS),To="MenuSubTrigger",wh=m.forwardRef((e,t)=>{const n=vr(To,e.__scopeMenu),r=ko(To,e.__scopeMenu),o=bh(To,e.__scopeMenu),s=nl(To,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(el,{asChild:!0,...u,children:c.jsx(uh,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":kh(n.open),...e,ref:fa(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:fe(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:fe(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:fe(e.onKeyDown,f=>{var p;const h=s.searchRef.current!=="";e.disabled||h&&f.key===" "||SS[r.dir].includes(f.key)&&(n.onOpenChange(!0),(p=n.content)==null||p.focus(),f.preventDefault())})})})});wh.displayName=To;var Sh="MenuSubContent",Ch=m.forwardRef((e,t)=>{const n=sh(Qt,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=vr(Qt,e.__scopeMenu),i=ko(Qt,e.__scopeMenu),a=bh(Sh,e.__scopeMenu),l=m.useRef(null),u=Be(t,l);return c.jsx(Co.Provider,{scope:e.__scopeMenu,children:c.jsx(Wt,{present:r||s.open,children:c.jsx(Co.Slot,{scope:e.__scopeMenu,children:c.jsx(rl,{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:fe(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:fe(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:fe(e.onKeyDown,d=>{var p;const f=d.currentTarget.contains(d.target),h=CS[i.dir].includes(d.key);f&&h&&(s.onOpenChange(!1),(p=a.trigger)==null||p.focus(),d.preventDefault())})})})})})});Ch.displayName=Sh;function kh(e){return e?"open":"closed"}function ti(e){return e==="indeterminate"}function il(e){return ti(e)?"indeterminate":e?"checked":"unchecked"}function US(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 VS(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 KS(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 qS(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return KS(n,t)}function Eo(e){return t=>t.pointerType==="mouse"?e(t):void 0}var GS=oh,YS=el,XS=ih,JS=ah,ZS=ol,QS=lh,eC=ei,tC=dh,nC=hh,rC=mh,oC=xh,sC=yh,iC=vh,aC=wh,lC=Ch,ni="DropdownMenu",[cC,ET]=wn(ni,[nh]),Dt=nh(),[uC,Th]=cC(ni),Eh=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=Dt(t),u=m.useRef(null),[d,f]=fr({prop:o,defaultProp:s??!1,onChange:i,caller:ni});return c.jsx(uC,{scope:t,triggerId:Sn(),triggerRef:u,contentId:Sn(),open:d,onOpenChange:f,onOpenToggle:m.useCallback(()=>f(h=>!h),[f]),modal:a,children:c.jsx(GS,{...l,open:d,onOpenChange:f,dir:r,modal:a,children:n})})};Eh.displayName=ni;var Ih="DropdownMenuTrigger",Ah=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=Th(Ih,n),i=Dt(n);return c.jsx(YS,{asChild:!0,...i,children:c.jsx(Ee.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:fa(t,s.triggerRef),onPointerDown:fe(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:fe(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});Ah.displayName=Ih;var dC="DropdownMenuPortal",Nh=e=>{const{__scopeDropdownMenu:t,...n}=e,r=Dt(t);return c.jsx(XS,{...r,...n})};Nh.displayName=dC;var _h="DropdownMenuContent",jh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Th(_h,n),s=Dt(n),i=m.useRef(!1);return c.jsx(JS,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:t,onCloseAutoFocus:fe(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:fe(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)"}})});jh.displayName=_h;var fC="DropdownMenuGroup",hC=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return c.jsx(ZS,{...o,...r,ref:t})});hC.displayName=fC;var pC="DropdownMenuLabel",Rh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return c.jsx(QS,{...o,...r,ref:t})});Rh.displayName=pC;var mC="DropdownMenuItem",Ph=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return c.jsx(eC,{...o,...r,ref:t})});Ph.displayName=mC;var gC="DropdownMenuCheckboxItem",Oh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return c.jsx(tC,{...o,...r,ref:t})});Oh.displayName=gC;var xC="DropdownMenuRadioGroup",yC=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return c.jsx(nC,{...o,...r,ref:t})});yC.displayName=xC;var vC="DropdownMenuRadioItem",Mh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return c.jsx(rC,{...o,...r,ref:t})});Mh.displayName=vC;var bC="DropdownMenuItemIndicator",Dh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return c.jsx(oC,{...o,...r,ref:t})});Dh.displayName=bC;var wC="DropdownMenuSeparator",Lh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return c.jsx(sC,{...o,...r,ref:t})});Lh.displayName=wC;var SC="DropdownMenuArrow",CC=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return c.jsx(iC,{...o,...r,ref:t})});CC.displayName=SC;var kC="DropdownMenuSubTrigger",Fh=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return c.jsx(aC,{...o,...r,ref:t})});Fh.displayName=kC;var TC="DropdownMenuSubContent",$h=m.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=Dt(n);return c.jsx(lC,{...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)"}})});$h.displayName=TC;var EC=Eh,IC=Ah,AC=Nh,zh=jh,Bh=Rh,Hh=Ph,Uh=Oh,Wh=Mh,Vh=Dh,Kh=Lh,qh=Fh,Gh=$h;const NC=EC,_C=IC,jC=m.forwardRef(({className:e,inset:t,children:n,...r},o)=>c.jsxs(qh,{ref:o,className:re("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(he.ChevronRight,{className:"ml-auto h-4 w-4"})]}));jC.displayName=qh.displayName;const RC=m.forwardRef(({className:e,...t},n)=>c.jsx(Gh,{ref:n,className:re("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}));RC.displayName=Gh.displayName;const Yh=m.forwardRef(({className:e,sideOffset:t=4,...n},r)=>c.jsx(AC,{children:c.jsx(zh,{ref:r,sideOffset:t,className:re("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})}));Yh.displayName=zh.displayName;const al=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(Hh,{ref:r,className:re("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}));al.displayName=Hh.displayName;const PC=m.forwardRef(({className:e,children:t,checked:n,...r},o)=>c.jsxs(Uh,{ref:o,className:re("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(Vh,{children:c.jsx(he.Check,{className:"h-4 w-4"})})}),t]}));PC.displayName=Uh.displayName;const OC=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Wh,{ref:r,className:re("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(Vh,{children:c.jsx(he.Circle,{className:"h-2 w-2 fill-current"})})}),t]}));OC.displayName=Wh.displayName;const MC=m.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(Bh,{ref:r,className:re("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));MC.displayName=Bh.displayName;const DC=m.forwardRef(({className:e,...t},n)=>c.jsx(Kh,{ref:n,className:re("-mx-1 my-1 h-px bg-muted",e),...t}));DC.displayName=Kh.displayName;function LC(e){var t;if(!Array.isArray(e)||!e.length)return null;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 ri({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}=Ni(),{currentThreadId:x}=Xo(),{threadId:g,messages:y,hasMore:b,isHistoryLoading:S,isLoading:E,loadOlder:k,navigateToCheckpoint:T,returnToLatest:I,checkpoint:_,checkpoints:O,interrupt:j,metadata:U}=Jo(),{isStreaming:L,error:W,submit:R,stop:V}=Uc(),$=g??x??null,ne=(_==null?void 0:_.id)??null,F=(_==null?void 0:_.namespace)??null,B=(U==null?void 0:U.assemblingMessageId)??null,le=j,[z,oe]=w.useState(!1);w.useEffect(()=>{le||oe(!1)},[le]);const pe=w.useCallback(()=>{oe(!0)},[]),ge=w.useCallback(()=>{oe(!1)},[]),me=!!le||z,[ve,Z]=w.useState(null),[D,J]=w.useState(""),[Q,de]=w.useState(null),[ee,se]=w.useState([]),[Ge,Ye]=w.useState(0),[Pe,He]=w.useState(0),[nt,Qe]=w.useState(!1),[je,pt]=w.useState(null),[xt,yt]=w.useState(null),[st,Xe]=w.useState(!1),[G,be]=w.useState(null),[ye,Ie]=w.useState(!1),Je=w.useRef(!1),[Ze,kt]=w.useState(!1),zt=w.useCallback((C,P)=>{if(!C||typeof C!="object")return null;const H=C[P];return typeof H=="number"?H:null},[]),Ur=w.useCallback((C,P)=>{if(!C||typeof C!="object")return null;const H=C[P];return typeof H=="string"&&H.trim()?H:null},[]),Ln=w.useMemo(()=>{const C=Array.isArray(O)?[...O]:[];return C.some(H=>zt(H.metadata,"step")!==null)&&C.sort((H,ie)=>{const ke=zt(H.metadata,"step"),Ne=zt(ie.metadata,"step");if(ke!==null||Ne!==null)return(Ne??Number.NEGATIVE_INFINITY)-(ke??Number.NEGATIVE_INFINITY);const De=Date.parse(H.createdAt??""),Oe=Date.parse(ie.createdAt??"");return Number.isNaN(De)||Number.isNaN(Oe)?0:Oe-De}),C},[O,zt]),qt=w.useRef(null),hn=w.useRef(null),Pt=w.useCallback(()=>{qt.current&&(qt.current.value=""),hn.current&&(hn.current.value=""),Ye(C=>C+1),He(C=>C+1)},[]),Qn=w.useRef(!1);w.useEffect(()=>{Qn.current&&!L&&(se([]),Pt()),Qn.current=L},[L,Pt]);const[nn,Tt]=w.useState("desktop");w.useEffect(()=>{const C=()=>{const P=window.innerWidth;Tt(P<640?"phone":P<1024?"tablet":"desktop")};return C(),window.addEventListener("resize",C),()=>window.removeEventListener("resize",C)},[]),w.useEffect(()=>{Ie(!1),Je.current=!1},[$]);const Cr=w.useCallback(async()=>{if(!(!b||S||!ye))try{await k()}catch(C){console.warn("loadOlder failed",C)}},[b,ye,S,k]);w.useEffect(()=>{(async()=>{if(!v.baseUrl){be(null);return}try{const P=await v.getAgent("default");be(P.uiDefaultMessage||null)}catch(P){console.warn("Failed to fetch default message:",P),be(null)}})()},[v]),w.useEffect(()=>{W&&!st&&(p==null||p(W))},[W,st,p]);const er=C=>{if(C.length>$s)return`Message too long (${C.length}/${$s} characters)`;try{return Hw(C),null}catch(P){return(P==null?void 0:P.message)||"Invalid message"}},vt=async C=>{const P=C.trim();if(!(!P&&ee.length===0)){if(P){const H=er(P);if(H){de(H);return}}try{await R({text:P||"",attachments:ee,payload:ve?{edit:!0,originalMessageId:ve}:void 0},{checkpointId:ne??void 0,checkpointNs:F??void 0}),f==null||f(P),de(null),se([]),Pt(),Z(null),J("")}catch(H){const ie=(H==null?void 0:H.message)||"Failed to send message";de(ie),p==null||p(ie)}}},rn=w.useCallback((C,P)=>{u&&(Z(C),J(P),de(null))},[u]),pn=w.useCallback(()=>{Z(null),J(""),de(null)},[]),kr=w.useCallback((C,P)=>{rn(C,P)},[rn]),Gt=w.useCallback(C=>{const P=H=>{const ie=H.content||[],ke=ie.filter(Ne=>Ne.type==="text").map(Ne=>Ne.text).join("");if(ke)return ke;try{return JSON.stringify(ie,null,2)}catch{return String(ie)}};for(let H=C-1;H>=0;H--)if(y[H].role==="user"){const ie=P(y[H]);ie&&R({text:ie},{checkpointId:ne??void 0,checkpointNs:F??void 0});break}},[y,R,ne,F]),Tr=C=>{const P=Array.from(C.target.files||[]);se(H=>[...H,...P]),C.target.value=""},Nn=C=>{se(P=>{const H=P.filter((ie,ke)=>C!==ke);return H.length===0&&Pt(),H})},mn=async C=>{const P=(C.target.files||[])[0];if(P){pt(null),yt(null),Qe(!0);try{await R({attachments:[P]},{checkpointId:ne??void 0,checkpointNs:F??void 0});const H=`Uploaded ${P.name} - processing through chat stream`;yt(H)}catch(H){const ie=H instanceof Error?H.message:"Failed to upload Excel file";console.error("Excel upload failed",H),pt(ie),p==null||p(ie)}finally{Qe(!1),C.target.value="",Pt()}}},tr=C=>{if(!C)return"Unknown";const P=Date.parse(C);return Number.isNaN(P)?C:new Date(P).toLocaleString()},Ao=async C=>{if(x){kt(!0);try{if(!C){await I();return}const P=Ln.find(ie=>ie.checkpointId===C),H=(P==null?void 0:P.checkpointNs)??null;await T(C,H)}finally{kt(!1)}}},Wr=`flex flex-1 w-full flex-col min-h-0 min-w-0 max-h-full overflow-hidden bg-transparent ${e} ${d.container||""}`,Vr=`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||""}`,nr=`flex-shrink-0 w-full border-t p-4 bg-transparent ${d.inputArea||""}`;return c.jsxs("div",{className:Wr,children:[!!W&&!st&&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:W}),c.jsx(Ve,{variant:"ghost",size:"sm",onClick:()=>Xe(!0),className:"text-red-800 hover:bg-red-100","aria-label":"Dismiss error",children:c.jsx(he.X,{size:16})})]}),x&&O.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:ne??"",onChange:C=>{const P=C.target.value||null;Ao(P)},children:[c.jsx("option",{value:"",children:"Latest"}),Ln.map(C=>{const P=zt(C.metadata,"step"),H=Ur(C.metadata,"source"),ie=LC(C.messages),ke=[];P!==null&&ke.push(`Step ${P}`),H&&ke.push(H),ie&&ke.push(ie.slice(0,40));const Ne=ke.length?` — ${ke.join(" • ")}`:"";return c.jsxs("option",{value:C.checkpointId,children:[tr(C.createdAt),Ne]},C.checkpointId)})]})]}),c.jsxs("div",{className:`relative ${Vr}`,style:r?{maxHeight:r}:void 0,children:[c.jsx(Da,{className:"h-full",style:{height:"100%"},messages:y,isStreaming:L,streamingAssistantId:B,streamingDebounceMs:typeof s=="number"?s:o,followNewMessages:i,layoutSize:nn,enableMessageEditing:u,editingMessageId:ve,onStartReached:()=>{ye&&Cr()},onScrollAway:C=>{if(!Je.current){Je.current=!0;return}C&&Ie(!0)},onEdit:kr,onRegenerate:Gt,onCancelEdit:pn,emptyMessage:G??void 0,isNavigatingCheckpoint:Ze,activeInterrupt:le,disableInterruptActions:z,onInterruptActionStart:pe,onInterruptActionEnd:ge}),E&&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(he.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:nr,children:[ve&&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(he.Edit3,{size:16,className:"text-blue-600"}),c.jsx("span",{className:"text-sm font-medium text-blue-800",children:"Editing message"})]}),c.jsx(Ve,{variant:"ghost",size:"sm",onClick:pn,className:"text-blue-600 hover:bg-blue-100",children:c.jsx(he.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:qt,type:"file",multiple:!0,onChange:C=>Tr(C),className:"hidden"},Ge),ee.length>0&&c.jsx("div",{className:"flex flex-wrap gap-2",children:ee.map((C,P)=>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(he.Paperclip,{size:14}),c.jsx("span",{className:"truncate max-w-[150px]",children:C.name}),c.jsx(Ve,{variant:"ghost",size:"sm",onClick:()=>Nn(P),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 ${C.name}`,children:c.jsx(he.X,{size:12})})]},P))})]}),l&&c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:hn,type:"file",accept:".xls,.xlsx,.xlsm",onChange:mn,className:"hidden"},Pe),nt&&c.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[c.jsx(he.Loader2,{className:"h-4 w-4 animate-spin"})," Uploading Excel file..."]}),xt&&!nt&&c.jsx("div",{className:"text-sm rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-emerald-700",children:xt}),je&&!nt&&c.jsx("div",{className:"text-sm rounded border border-red-200 bg-red-50 px-3 py-2 text-red-600",children:je})]})]}),Q&&c.jsx("div",{className:"mb-3 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2",children:Q}),c.jsxs("div",{className:"flex items-end gap-2",children:[(a||l)&&c.jsxs(NC,{children:[c.jsx(_C,{asChild:!0,children:c.jsx(Ve,{type:"button",size:"icon",variant:"outline",disabled:L||me,title:"More input actions",className:d.moreButton||"",children:c.jsx(he.Plus,{size:16})})}),c.jsxs(Yh,{align:"start",sideOffset:6,className:"w-52",children:[a&&c.jsxs(al,{onClick:()=>{var C;return(C=qt.current)==null?void 0:C.click()},className:"cursor-pointer",children:[c.jsx(he.Paperclip,{className:"h-4 w-4 mr-2"})," Attach files or images"]}),l&&c.jsxs(al,{onClick:()=>{var C;nt||(C=hn.current)==null||C.click()},className:`cursor-pointer ${nt?"opacity-60 pointer-events-none":""}`,children:[c.jsx(he.FileSpreadsheet,{className:"h-4 w-4 mr-2"})," Upload Excel file"]})]})]}),c.jsx("div",{className:"flex-1",children:c.jsx(Xx,{initialValue:D,editingMessageId:ve,placeholder:ve?"Edit your message...":t,isStreaming:L,disabled:me,maxLength:$s,onSend:vt,onCancelEdit:pn,onStop:V,allowEmptySend:ee.length>0,textareaClassName:`resize-none min-h-[44px] max-h-[20rem] w-full transition-colors ${ve?"border-blue-400 bg-blue-50 text-blue-900 dark:border-blue-500 dark:bg-blue-950/60 dark:text-blue-50":""} ${Q?"border-red-400":""} ${d.textarea||""}`})})]})]})]})}const oi=m.forwardRef(({className:e,type:t,...n},r)=>c.jsx("input",{type:t,className:re("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}));oi.displayName="Input";function ll(e,[t,n]){return Math.min(n,Math.max(t,e))}function FC(e,t){return m.useReducer((n,r)=>t[n][r]??n,e)}var cl="ScrollArea",[Xh,IT]=wn(cl),[$C,en]=Xh(cl),Jh=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,E]=m.useState(0),[k,T]=m.useState(!1),[I,_]=m.useState(!1),O=Be(t,U=>l(U)),j=zs(o);return c.jsx($C,{scope:n,type:r,dir:j,scrollHideDelay:s,scrollArea:a,viewport:u,onViewportChange:d,content:f,onContentChange:h,scrollbarX:p,onScrollbarXChange:v,scrollbarXEnabled:k,onScrollbarXEnabledChange:T,scrollbarY:x,onScrollbarYChange:g,scrollbarYEnabled:I,onScrollbarYEnabledChange:_,onCornerWidthChange:b,onCornerHeightChange:E,children:c.jsx(Ee.div,{dir:j,...i,ref:O,style:{position:"relative","--radix-scroll-area-corner-width":y+"px","--radix-scroll-area-corner-height":S+"px",...e.style}})})});Jh.displayName=cl;var Zh="ScrollAreaViewport",Qh=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,children:r,nonce:o,...s}=e,i=en(Zh,n),a=m.useRef(null),l=Be(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(Ee.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})})]})});Qh.displayName=Zh;var An="ScrollAreaScrollbar",ul=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=en(An,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(zC,{...r,ref:t,forceMount:n}):o.type==="scroll"?c.jsx(BC,{...r,ref:t,forceMount:n}):o.type==="auto"?c.jsx(ep,{...r,ref:t,forceMount:n}):o.type==="always"?c.jsx(dl,{...r,ref:t}):null});ul.displayName=An;var zC=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=en(An,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(ep,{"data-state":s?"visible":"hidden",...r,ref:t})})}),BC=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=en(An,e.__scopeScrollArea),s=e.orientation==="horizontal",i=li(()=>l("SCROLL_END"),100),[a,l]=FC("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(dl,{"data-state":a==="hidden"?"hidden":"visible",...r,ref:t,onPointerEnter:fe(e.onPointerEnter,()=>l("POINTER_ENTER")),onPointerLeave:fe(e.onPointerLeave,()=>l("POINTER_LEAVE"))})})}),ep=m.forwardRef((e,t)=>{const n=en(An,e.__scopeScrollArea),{forceMount:r,...o}=e,[s,i]=m.useState(!1),a=e.orientation==="horizontal",l=li(()=>{if(n.viewport){const u=n.viewport.offsetWidth<n.viewport.scrollWidth,d=n.viewport.offsetHeight<n.viewport.scrollHeight;i(a?u:d)}},10);return zr(n.viewport,l),zr(n.content,l),c.jsx(Wt,{present:r||s,children:c.jsx(dl,{"data-state":s?"visible":"hidden",...o,ref:t})})}),dl=m.forwardRef((e,t)=>{const{orientation:n="vertical",...r}=e,o=en(An,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=sp(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 qC(h,i.current,a,p)}return n==="horizontal"?c.jsx(HC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollLeft,p=ip(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(UC,{...d,ref:t,onThumbPositionChange:()=>{if(o.viewport&&s.current){const h=o.viewport.scrollTop,p=ip(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}),HC=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=en(An,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),u=Be(t,l,s.onScrollbarXChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),c.jsx(np,{"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":ai(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),lp(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:ii(i.paddingLeft),paddingEnd:ii(i.paddingRight)}})}})}),UC=m.forwardRef((e,t)=>{const{sizes:n,onSizesChange:r,...o}=e,s=en(An,e.__scopeScrollArea),[i,a]=m.useState(),l=m.useRef(null),u=Be(t,l,s.onScrollbarYChange);return m.useEffect(()=>{l.current&&a(getComputedStyle(l.current))},[l]),c.jsx(np,{"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":ai(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),lp(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:ii(i.paddingTop),paddingEnd:ii(i.paddingBottom)}})}})}),[WC,tp]=Xh(An),np=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(An,n),[v,x]=m.useState(null),g=Be(t,O=>x(O)),y=m.useRef(null),b=m.useRef(""),S=p.viewport,E=r.content-r.viewport,k=Ct(d),T=Ct(l),I=li(f,10);function _(O){if(y.current){const j=O.clientX-y.current.left,U=O.clientY-y.current.top;u({x:j,y:U})}}return m.useEffect(()=>{const O=j=>{const U=j.target;(v==null?void 0:v.contains(U))&&k(j,E)};return document.addEventListener("wheel",O,{passive:!1}),()=>document.removeEventListener("wheel",O,{passive:!1})},[S,v,E,k]),m.useEffect(T,[r,T]),zr(v,I),zr(p.content,I),c.jsx(WC,{scope:n,scrollbar:v,hasThumb:o,onThumbChange:Ct(s),onThumbPointerUp:Ct(i),onThumbPositionChange:T,onThumbPointerDown:Ct(a),children:c.jsx(Ee.div,{...h,ref:g,style:{position:"absolute",...h.style},onPointerDown:fe(e.onPointerDown,O=>{O.button===0&&(O.target.setPointerCapture(O.pointerId),y.current=v.getBoundingClientRect(),b.current=document.body.style.webkitUserSelect,document.body.style.webkitUserSelect="none",p.viewport&&(p.viewport.style.scrollBehavior="auto"),_(O))}),onPointerMove:fe(e.onPointerMove,_),onPointerUp:fe(e.onPointerUp,O=>{const j=O.target;j.hasPointerCapture(O.pointerId)&&j.releasePointerCapture(O.pointerId),document.body.style.webkitUserSelect=b.current,p.viewport&&(p.viewport.style.scrollBehavior=""),y.current=null})})})}),si="ScrollAreaThumb",rp=m.forwardRef((e,t)=>{const{forceMount:n,...r}=e,o=tp(si,e.__scopeScrollArea);return c.jsx(Wt,{present:n||o.hasThumb,children:c.jsx(VC,{ref:t,...r})})}),VC=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,style:r,...o}=e,s=en(si,n),i=tp(si,n),{onThumbPositionChange:a}=i,l=Be(t,f=>i.onThumbChange(f)),u=m.useRef(void 0),d=li(()=>{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=GC(f,a);u.current=p,a()}};return a(),f.addEventListener("scroll",h),()=>f.removeEventListener("scroll",h)}},[s.viewport,d,a]),c.jsx(Ee.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:fe(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:fe(e.onPointerUp,i.onThumbPointerUp)})});rp.displayName=si;var fl="ScrollAreaCorner",op=m.forwardRef((e,t)=>{const n=en(fl,e.__scopeScrollArea),r=!!(n.scrollbarX&&n.scrollbarY);return n.type!=="scroll"&&r?c.jsx(KC,{...e,ref:t}):null});op.displayName=fl;var KC=m.forwardRef((e,t)=>{const{__scopeScrollArea:n,...r}=e,o=en(fl,n),[s,i]=m.useState(0),[a,l]=m.useState(0),u=!!(s&&a);return zr(o.scrollbarX,()=>{var f;const d=((f=o.scrollbarX)==null?void 0:f.offsetHeight)||0;o.onCornerHeightChange(d),l(d)}),zr(o.scrollbarY,()=>{var f;const d=((f=o.scrollbarY)==null?void 0:f.offsetWidth)||0;o.onCornerWidthChange(d),i(d)}),u?c.jsx(Ee.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 ii(e){return e?parseInt(e,10):0}function sp(e,t){const n=e/t;return isNaN(n)?0:n}function ai(e){const t=sp(e.viewport,e.content),n=e.scrollbar.paddingStart+e.scrollbar.paddingEnd,r=(e.scrollbar.size-n)*t;return Math.max(r,18)}function qC(e,t,n,r="ltr"){const o=ai(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 ap([l,u],f)(e)}function ip(e,t,n="ltr"){const r=ai(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=ll(e,l);return ap([0,i],[0,a])(u)}function ap(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 lp(e,t){return e>0&&e<t}var GC=(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 li(e,t){const n=Ct(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 zr(e,t){const n=Ct(t);gt(()=>{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 cp=Jh,YC=Qh,XC=op;const up=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(cp,{ref:r,className:re("relative overflow-hidden",e),...n,children:[c.jsx(YC,{className:"h-full w-full rounded-[inherit] overflow-auto",children:t}),c.jsx(dp,{}),c.jsx(XC,{})]}));up.displayName=cp.displayName;const dp=m.forwardRef(({className:e,orientation:t="vertical",...n},r)=>c.jsx(ul,{ref:r,orientation:t,className:re("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(rp,{className:"relative flex-1 rounded-full bg-border"})}));dp.displayName=ul.displayName;function hl({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}=Xo(),{loadThread:x}=Jo(),{createThread:g,deleteThread:y,renameThread:b}=v,[S,E]=w.useState(Array.isArray(f)?f:[]),k=w.useRef(S.length>0),[T,I]=w.useState(null),[_,O]=w.useState(""),[j,U]=w.useState(!1);w.useEffect(()=>{const z=Array.isArray(f)?f:[];if(z.length>0){k.current=!0,E(z);return}p||(k.current=!1,E(z))},[f,p]);const L=async z=>{try{await x(z),a==null||a(z),l==null||l(z)}catch(oe){console.error("Failed to select thread:",oe)}},W=async()=>{try{U(!0);const z=await g();u==null||u(z),a==null||a(z)}catch(z){console.error("Failed to create thread:",z)}finally{U(!1)}},R=async(z,oe)=>{if(oe.stopPropagation(),!!confirm("Delete this thread?"))try{await y(z),d==null||d(z)}catch(pe){console.error("Failed to delete thread:",pe)}},V=(z,oe)=>{oe.stopPropagation(),I(z.threadId),O(z.title||`Thread ${z.threadId.slice(0,8)}`)},$=async z=>{if(_.trim())try{await b(z,_.trim()),I(null),O("")}catch(oe){console.error("Failed to update title:",oe)}},ne=()=>{I(null),O("")},F=(z,oe)=>{z.key==="Enter"?$(oe):z.key==="Escape"&&ne()},B=z=>{if(!z)return"";try{const oe=new Date(z),ge=new Date().getTime()-oe.getTime(),me=Math.floor(ge/(1e3*60*60*24));return me===0?oe.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):me===1?"Yesterday":me<7?`${me} days ago`:oe.toLocaleDateString()}catch{return""}},le=z=>z.title||`Thread ${z.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(Ve,{onClick:W,disabled:j||p,className:s.createButton||"p-2",size:"sm",variant:"ghost",title:j?"Creating...":"New Chat",children:c.jsx(he.MessageSquarePlus,{size:20})})}),c.jsx(up,{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(he.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(he.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((z,oe)=>new Date(oe.updatedAt||oe.createdAt||"").getTime()-new Date(z.updatedAt||z.createdAt||"").getTime()).map(z=>c.jsxs("div",{onClick:()=>L(z.threadId),className:`group relative p-3 rounded-lg cursor-pointer transition-colors border ${(i??h)===z.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===z.threadId?c.jsxs("div",{className:"flex items-center gap-2",onClick:oe=>oe.stopPropagation(),children:[c.jsx(oi,{value:_,onChange:oe=>O(oe.target.value),onKeyDown:oe=>F(oe,z.threadId),className:"h-6 text-sm",autoFocus:!0}),c.jsx(Ve,{variant:"ghost",size:"sm",onClick:()=>$(z.threadId),className:"h-6 w-6 p-0",children:c.jsx(he.Check,{size:12})}),c.jsx(Ve,{variant:"ghost",size:"sm",onClick:ne,className:"h-6 w-6 p-0",children:c.jsx(he.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:le(z)}),c.jsxs("div",{className:"flex items-center gap-2 text-xs text-gray-500 dark:text-slate-400 mt-1",children:[c.jsx(he.Calendar,{size:10}),c.jsx("span",{children:B(z.updatedAt||z.createdAt)})]})]})}),c.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity ml-2",children:[r&&T!==z.threadId&&c.jsx(Ve,{variant:"ghost",size:"sm",onClick:oe=>V(z,oe),className:"h-6 w-6 p-0",title:"Edit title",children:c.jsx(he.Edit3,{size:12})}),n&&c.jsx(Ve,{variant:"ghost",size:"sm",onClick:oe=>R(z.threadId,oe),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(he.Trash2,{size:12})})]})]}),i===z.threadId&&c.jsx("div",{className:"absolute left-0 top-1/2 -translate-y-1/2 w-1 h-8 bg-blue-400 rounded-r"})]},z.threadId))})})]})}function Br(e){if(!(typeof globalThis>"u"))return globalThis[e]}function JC(e){if(typeof e!="string")return;const t=e.trim();if(t)return Pn(t)}function fp(){const e=[Br("__API_BASE_URL__"),Br("__CHAT_API_BASE_URL__"),Br("__CHAT_API_URL__")];for(const t of e){const n=JC(t);if(n)return n}}function hp(){const e=[Br("__API_AUTH_TOKEN__"),Br("__CHAT_API_KEY__"),Br("__CHAT_AUTH_TOKEN__")];for(const t of e)if(typeof t=="string"&&t.trim())return t.trim()}function pp(...e){for(const t of e)if(typeof t=="string"&&t.trim())return Pn(t);return Pn()}function mp(){const e={},t=fp(),n=hp();return t&&(e.baseUrl=t),n&&(e.apiKey=n),e}function gp(){const e=mp(),t=zn.getAuthToken(),n=fp();return{apiBaseUrl:pp(e.baseUrl,zn.baseUrl,n),apiKey:t||e.apiKey||hp()||"",model:"gpt-4",temperature:.7,maxTokens:4096,layoutSize:"desktop",showThreads:!0,autoScrollMessages:!0,truncateToolMessages:!0,toolMessagePreviewLength:200,darkMode:!1,enableSound:!1,messageHistory:100}}const xp="chat-settings";function ZC(){try{const e=localStorage.getItem(xp);return e?JSON.parse(e):{}}catch(e){return console.error("Failed to parse stored settings:",e),{}}}function QC(e){try{const t={...e,apiBaseUrl:Pn(e.apiBaseUrl)};localStorage.setItem(xp,JSON.stringify(t)),t.apiKey&&zn.setAuthToken(t.apiKey)}catch(t){console.error("Failed to save settings:",t)}}function ek(){const e=gp(),t=ZC(),n=zn.getAuthToken(),r=typeof t.apiBaseUrl=="string"?t.apiBaseUrl:void 0;return{...e,...t,apiKey:n||t.apiKey||e.apiKey,apiBaseUrl:pp(zn.baseUrl,r,e.apiBaseUrl)}}function tk(e){zn.updateConfig({baseUrl:e.apiBaseUrl,authToken:e.apiKey??void 0}),QC(e)}var nk="Label",yp=m.forwardRef((e,t)=>c.jsx(Ee.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())}}));yp.displayName=nk;var vp=yp;const rk=Po.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(vp,{ref:n,className:re(rk(),e),...t}));tn.displayName=vp.displayName;function bp(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 ci="Switch",[ok,AT]=wn(ci),[sk,ik]=ok(ci),wp=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=Be(t,S=>p(S)),x=m.useRef(!1),g=h?d||!!h.closest("form"):!0,[y,b]=fr({prop:o,defaultProp:s??!1,onChange:u,caller:ci});return c.jsxs(sk,{scope:n,checked:y,disabled:a,children:[c.jsx(Ee.button,{type:"button",role:"switch","aria-checked":y,"aria-required":i,"data-state":Tp(y),"data-disabled":a?"":void 0,disabled:a,value:l,...f,ref:v,onClick:fe(e.onClick,S=>{b(E=>!E),g&&(x.current=S.isPropagationStopped(),x.current||S.stopPropagation())})}),g&&c.jsx(kp,{control:h,bubbles:!x.current,name:r,value:l,checked:y,required:i,disabled:a,form:d,style:{transform:"translateX(-100%)"}})]})});wp.displayName=ci;var Sp="SwitchThumb",Cp=m.forwardRef((e,t)=>{const{__scopeSwitch:n,...r}=e,o=ik(Sp,n);return c.jsx(Ee.span,{"data-state":Tp(o.checked),"data-disabled":o.disabled?"":void 0,...r,ref:t})});Cp.displayName=Sp;var ak="SwitchBubbleInput",kp=m.forwardRef(({__scopeSwitch:e,control:t,checked:n,bubbles:r=!0,...o},s)=>{const i=m.useRef(null),a=Be(i,s),l=bp(n),u=Mf(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}})});kp.displayName=ak;function Tp(e){return e?"checked":"unchecked"}var Ep=wp,lk=Cp;const Xn=m.forwardRef(({className:e,...t},n)=>c.jsx(Ep,{className:re("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(lk,{className:re("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")})}));Xn.displayName=Ep.displayName;var Ip=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"}),ck="VisuallyHidden",uk=m.forwardRef((e,t)=>c.jsx(Ee.span,{...e,ref:t,style:{...Ip,...e.style}}));uk.displayName=ck;var dk=[" ","Enter","ArrowUp","ArrowDown"],fk=[" ","Enter"],br="Select",[ui,di,hk]=La(br),[Hr,NT]=wn(br,[hk,Js]),fi=Js(),[pk,Jn]=Hr(br),[mk,gk]=Hr(br),Ap=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=fi(t),[g,y]=m.useState(null),[b,S]=m.useState(null),[E,k]=m.useState(!1),T=zs(u),[I,_]=fr({prop:r,defaultProp:o??!1,onChange:s,caller:br}),[O,j]=fr({prop:i,defaultProp:a,onChange:l,caller:br}),U=m.useRef(null),L=g?v||!!g.closest("form"):!0,[W,R]=m.useState(new Set),V=Array.from(W).map($=>$.props.value).join(";");return c.jsx(Vf,{...x,children:c.jsxs(pk,{required:p,scope:t,trigger:g,onTriggerChange:y,valueNode:b,onValueNodeChange:S,valueNodeHasChildren:E,onValueNodeHasChildrenChange:k,contentId:Sn(),value:O,onValueChange:j,open:I,onOpenChange:_,dir:T,triggerPointerDownPosRef:U,disabled:h,children:[c.jsx(ui.Provider,{scope:t,children:c.jsx(mk,{scope:e.__scopeSelect,onNativeOptionAdd:m.useCallback($=>{R(ne=>new Set(ne).add($))},[]),onNativeOptionRemove:m.useCallback($=>{R(ne=>{const F=new Set(ne);return F.delete($),F})},[]),children:n})}),L?c.jsxs(Zp,{"aria-hidden":!0,required:p,tabIndex:-1,name:d,autoComplete:f,value:O,onChange:$=>j($.target.value),disabled:h,form:v,children:[O===void 0?c.jsx("option",{value:""}):null,Array.from(W)]},V):null]})})};Ap.displayName=br;var Np="SelectTrigger",_p=m.forwardRef((e,t)=>{const{__scopeSelect:n,disabled:r=!1,...o}=e,s=fi(n),i=Jn(Np,n),a=i.disabled||r,l=Be(t,i.onTriggerChange),u=di(n),d=m.useRef("touch"),[f,h,p]=em(x=>{const g=u().filter(S=>!S.disabled),y=g.find(S=>S.value===i.value),b=tm(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(Kf,{asChild:!0,...s,children:c.jsx(Ee.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":Qp(i.value)?"":void 0,...o,ref:l,onClick:fe(o.onClick,x=>{x.currentTarget.focus(),d.current!=="mouse"&&v(x)}),onPointerDown:fe(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:fe(o.onKeyDown,x=>{const g=f.current!=="";!(x.ctrlKey||x.altKey||x.metaKey)&&x.key.length===1&&h(x.key),!(g&&x.key===" ")&&dk.includes(x.key)&&(v(),x.preventDefault())})})})});_p.displayName=Np;var jp="SelectValue",Rp=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,children:s,placeholder:i="",...a}=e,l=Jn(jp,n),{onValueNodeHasChildrenChange:u}=l,d=s!==void 0,f=Be(t,l.onValueNodeChange);return gt(()=>{u(d)},[u,d]),c.jsx(Ee.span,{...a,ref:f,style:{pointerEvents:"none"},children:Qp(l.value)?c.jsx(c.Fragment,{children:i}):s})});Rp.displayName=jp;var xk="SelectIcon",Pp=m.forwardRef((e,t)=>{const{__scopeSelect:n,children:r,...o}=e;return c.jsx(Ee.span,{"aria-hidden":!0,...o,ref:t,children:r||"▼"})});Pp.displayName=xk;var yk="SelectPortal",Op=e=>c.jsx(Ss,{asChild:!0,...e});Op.displayName=yk;var wr="SelectContent",Mp=m.forwardRef((e,t)=>{const n=Jn(wr,e.__scopeSelect),[r,o]=m.useState();if(gt(()=>{o(new DocumentFragment)},[]),!n.open){const s=r;return s?Oo.createPortal(c.jsx(Dp,{scope:e.__scopeSelect,children:c.jsx(ui.Slot,{scope:e.__scopeSelect,children:c.jsx("div",{children:e.children})})}),s):null}return c.jsx(Lp,{...e,ref:t})});Mp.displayName=wr;var fn=10,[Dp,Zn]=Hr(wr),vk="SelectContentImpl",bk=rr.createSlot("SelectContent.RemoveScroll"),Lp=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=Jn(wr,n),[S,E]=m.useState(null),[k,T]=m.useState(null),I=Be(t,Z=>E(Z)),[_,O]=m.useState(null),[j,U]=m.useState(null),L=di(n),[W,R]=m.useState(!1),V=m.useRef(!1);m.useEffect(()=>{if(S)return Ra(S)},[S]),Ea();const $=m.useCallback(Z=>{const[D,...J]=L().map(ee=>ee.ref.current),[Q]=J.slice(-1),de=document.activeElement;for(const ee of Z)if(ee===de||(ee==null||ee.scrollIntoView({block:"nearest"}),ee===D&&k&&(k.scrollTop=0),ee===Q&&k&&(k.scrollTop=k.scrollHeight),ee==null||ee.focus(),document.activeElement!==de))return},[L,k]),ne=m.useCallback(()=>$([_,S]),[$,_,S]);m.useEffect(()=>{W&&ne()},[W,ne]);const{onOpenChange:F,triggerPointerDownPosRef:B}=b;m.useEffect(()=>{if(S){let Z={x:0,y:0};const D=Q=>{var de,ee;Z={x:Math.abs(Math.round(Q.pageX)-(((de=B.current)==null?void 0:de.x)??0)),y:Math.abs(Math.round(Q.pageY)-(((ee=B.current)==null?void 0:ee.y)??0))}},J=Q=>{Z.x<=10&&Z.y<=10?Q.preventDefault():S.contains(Q.target)||F(!1),document.removeEventListener("pointermove",D),B.current=null};return B.current!==null&&(document.addEventListener("pointermove",D),document.addEventListener("pointerup",J,{capture:!0,once:!0})),()=>{document.removeEventListener("pointermove",D),document.removeEventListener("pointerup",J,{capture:!0})}}},[S,F,B]),m.useEffect(()=>{const Z=()=>F(!1);return window.addEventListener("blur",Z),window.addEventListener("resize",Z),()=>{window.removeEventListener("blur",Z),window.removeEventListener("resize",Z)}},[F]);const[le,z]=em(Z=>{const D=L().filter(de=>!de.disabled),J=D.find(de=>de.ref.current===document.activeElement),Q=tm(D,Z,J);Q&&setTimeout(()=>Q.ref.current.focus())}),oe=m.useCallback((Z,D,J)=>{const Q=!V.current&&!J;(b.value!==void 0&&b.value===D||Q)&&(O(Z),Q&&(V.current=!0))},[b.value]),pe=m.useCallback(()=>S==null?void 0:S.focus(),[S]),ge=m.useCallback((Z,D,J)=>{const Q=!V.current&&!J;(b.value!==void 0&&b.value===D||Q)&&U(Z)},[b.value]),me=r==="popper"?pl:Fp,ve=me===pl?{side:a,sideOffset:l,align:u,alignOffset:d,arrowPadding:f,collisionBoundary:h,collisionPadding:p,sticky:v,hideWhenDetached:x,avoidCollisions:g}:{};return c.jsx(Dp,{scope:n,content:S,viewport:k,onViewportChange:T,itemRefCallback:oe,selectedItem:_,onItemLeave:pe,itemTextRefCallback:ge,focusSelectedItem:ne,selectedItemText:j,position:r,isPositioned:W,searchRef:le,children:c.jsx(As,{as:bk,allowPinchZoom:!0,children:c.jsx(ws,{asChild:!0,trapped:b.open,onMountAutoFocus:Z=>{Z.preventDefault()},onUnmountAutoFocus:fe(o,Z=>{var D;(D=b.trigger)==null||D.focus({preventScroll:!0}),Z.preventDefault()}),children:c.jsx(bs,{asChild:!0,disableOutsidePointerEvents:!0,onEscapeKeyDown:s,onPointerDownOutside:i,onFocusOutside:Z=>Z.preventDefault(),onDismiss:()=>b.onOpenChange(!1),children:c.jsx(me,{role:"listbox",id:b.contentId,"data-state":b.open?"open":"closed",dir:b.dir,onContextMenu:Z=>Z.preventDefault(),...y,...ve,onPlaced:()=>R(!0),ref:I,style:{display:"flex",flexDirection:"column",outline:"none",...y.style},onKeyDown:fe(y.onKeyDown,Z=>{const D=Z.ctrlKey||Z.altKey||Z.metaKey;if(Z.key==="Tab"&&Z.preventDefault(),!D&&Z.key.length===1&&z(Z.key),["ArrowUp","ArrowDown","Home","End"].includes(Z.key)){let Q=L().filter(de=>!de.disabled).map(de=>de.ref.current);if(["ArrowUp","End"].includes(Z.key)&&(Q=Q.slice().reverse()),["ArrowUp","ArrowDown"].includes(Z.key)){const de=Z.target,ee=Q.indexOf(de);Q=Q.slice(ee+1)}setTimeout(()=>$(Q)),Z.preventDefault()}})})})})})})});Lp.displayName=vk;var wk="SelectItemAlignedPosition",Fp=m.forwardRef((e,t)=>{const{__scopeSelect:n,onPlaced:r,...o}=e,s=Jn(wr,n),i=Zn(wr,n),[a,l]=m.useState(null),[u,d]=m.useState(null),f=Be(t,I=>d(I)),h=di(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 I=s.trigger.getBoundingClientRect(),_=u.getBoundingClientRect(),O=s.valueNode.getBoundingClientRect(),j=y.getBoundingClientRect();if(s.dir!=="rtl"){const de=j.left-_.left,ee=O.left-de,se=I.left-ee,Ge=I.width+se,Ye=Math.max(Ge,_.width),Pe=window.innerWidth-fn,He=ll(ee,[fn,Math.max(fn,Pe-Ye)]);a.style.minWidth=Ge+"px",a.style.left=He+"px"}else{const de=_.right-j.right,ee=window.innerWidth-O.right-de,se=window.innerWidth-I.right-ee,Ge=I.width+se,Ye=Math.max(Ge,_.width),Pe=window.innerWidth-fn,He=ll(ee,[fn,Math.max(fn,Pe-Ye)]);a.style.minWidth=Ge+"px",a.style.right=He+"px"}const U=h(),L=window.innerHeight-fn*2,W=x.scrollHeight,R=window.getComputedStyle(u),V=parseInt(R.borderTopWidth,10),$=parseInt(R.paddingTop,10),ne=parseInt(R.borderBottomWidth,10),F=parseInt(R.paddingBottom,10),B=V+$+W+F+ne,le=Math.min(g.offsetHeight*5,B),z=window.getComputedStyle(x),oe=parseInt(z.paddingTop,10),pe=parseInt(z.paddingBottom,10),ge=I.top+I.height/2-fn,me=L-ge,ve=g.offsetHeight/2,Z=g.offsetTop+ve,D=V+$+Z,J=B-D;if(D<=ge){const de=U.length>0&&g===U[U.length-1].ref.current;a.style.bottom="0px";const ee=u.clientHeight-x.offsetTop-x.offsetHeight,se=Math.max(me,ve+(de?pe:0)+ee+ne),Ge=D+se;a.style.height=Ge+"px"}else{const de=U.length>0&&g===U[0].ref.current;a.style.top="0px";const se=Math.max(ge,V+x.offsetTop+(de?oe:0)+ve)+J;a.style.height=se+"px",x.scrollTop=D-ge+x.offsetTop}a.style.margin=`${fn}px 0`,a.style.minHeight=le+"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]);gt(()=>S(),[S]);const[E,k]=m.useState();gt(()=>{u&&k(window.getComputedStyle(u).zIndex)},[u]);const T=m.useCallback(I=>{I&&v.current===!0&&(S(),b==null||b(),v.current=!1)},[S,b]);return c.jsx(Ck,{scope:n,contentWrapper:a,shouldExpandOnScrollRef:p,onScrollButtonChange:T,children:c.jsx("div",{ref:l,style:{display:"flex",flexDirection:"column",position:"fixed",zIndex:E},children:c.jsx(Ee.div,{...o,ref:f,style:{boxSizing:"border-box",maxHeight:"100%",...o.style}})})})});Fp.displayName=wk;var Sk="SelectPopperPosition",pl=m.forwardRef((e,t)=>{const{__scopeSelect:n,align:r="start",collisionPadding:o=fn,...s}=e,i=fi(n);return c.jsx(qf,{...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)"}})});pl.displayName=Sk;var[Ck,ml]=Hr(wr,{}),gl="SelectViewport",$p=m.forwardRef((e,t)=>{const{__scopeSelect:n,nonce:r,...o}=e,s=Zn(gl,n),i=ml(gl,n),a=Be(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(ui.Slot,{scope:n,children:c.jsx(Ee.div,{"data-radix-select-viewport":"",role:"presentation",...o,ref:a,style:{position:"relative",flex:1,overflow:"hidden auto",...o.style},onScroll:fe(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),E=b-S;f.style.height=S+"px",f.style.bottom==="0px"&&(d.scrollTop=E>0?E:0,f.style.justifyContent="flex-end")}}}l.current=d.scrollTop})})})]})});$p.displayName=gl;var zp="SelectGroup",[kk,Tk]=Hr(zp),Ek=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Sn();return c.jsx(kk,{scope:n,id:o,children:c.jsx(Ee.div,{role:"group","aria-labelledby":o,...r,ref:t})})});Ek.displayName=zp;var Bp="SelectLabel",Hp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=Tk(Bp,n);return c.jsx(Ee.div,{id:o.id,...r,ref:t})});Hp.displayName=Bp;var hi="SelectItem",[Ik,Up]=Hr(hi),Wp=m.forwardRef((e,t)=>{const{__scopeSelect:n,value:r,disabled:o=!1,textValue:s,...i}=e,a=Jn(hi,n),l=Zn(hi,n),u=a.value===r,[d,f]=m.useState(s??""),[h,p]=m.useState(!1),v=Be(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(Ik,{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(ui.ItemSlot,{scope:n,value:r,disabled:o,textValue:d,children:c.jsx(Ee.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:fe(i.onFocus,()=>p(!0)),onBlur:fe(i.onBlur,()=>p(!1)),onClick:fe(i.onClick,()=>{g.current!=="mouse"&&y()}),onPointerUp:fe(i.onPointerUp,()=>{g.current==="mouse"&&y()}),onPointerDown:fe(i.onPointerDown,b=>{g.current=b.pointerType}),onPointerMove:fe(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:fe(i.onPointerLeave,b=>{var S;b.currentTarget===document.activeElement&&((S=l.onItemLeave)==null||S.call(l))}),onKeyDown:fe(i.onKeyDown,b=>{var E;((E=l.searchRef)==null?void 0:E.current)!==""&&b.key===" "||(fk.includes(b.key)&&y(),b.key===" "&&b.preventDefault())})})})})});Wp.displayName=hi;var Io="SelectItemText",Vp=m.forwardRef((e,t)=>{const{__scopeSelect:n,className:r,style:o,...s}=e,i=Jn(Io,n),a=Zn(Io,n),l=Up(Io,n),u=gk(Io,n),[d,f]=m.useState(null),h=Be(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 gt(()=>(x(v),()=>g(v)),[x,g,v]),c.jsxs(c.Fragment,{children:[c.jsx(Ee.span,{id:l.textId,...s,ref:h}),l.isSelected&&i.valueNode&&!i.valueNodeHasChildren?Oo.createPortal(s.children,i.valueNode):null]})});Vp.displayName=Io;var Kp="SelectItemIndicator",qp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return Up(Kp,n).isSelected?c.jsx(Ee.span,{"aria-hidden":!0,...r,ref:t}):null});qp.displayName=Kp;var xl="SelectScrollUpButton",Gp=m.forwardRef((e,t)=>{const n=Zn(xl,e.__scopeSelect),r=ml(xl,e.__scopeSelect),[o,s]=m.useState(!1),i=Be(t,r.onScrollButtonChange);return gt(()=>{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(Xp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop-l.offsetHeight)}}):null});Gp.displayName=xl;var yl="SelectScrollDownButton",Yp=m.forwardRef((e,t)=>{const n=Zn(yl,e.__scopeSelect),r=ml(yl,e.__scopeSelect),[o,s]=m.useState(!1),i=Be(t,r.onScrollButtonChange);return gt(()=>{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(Xp,{...e,ref:i,onAutoScroll:()=>{const{viewport:a,selectedItem:l}=n;a&&l&&(a.scrollTop=a.scrollTop+l.offsetHeight)}}):null});Yp.displayName=yl;var Xp=m.forwardRef((e,t)=>{const{__scopeSelect:n,onAutoScroll:r,...o}=e,s=Zn("SelectScrollButton",n),i=m.useRef(null),a=di(n),l=m.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null)},[]);return m.useEffect(()=>()=>l(),[l]),gt(()=>{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(Ee.div,{"aria-hidden":!0,...o,ref:t,style:{flexShrink:0,...o.style},onPointerDown:fe(o.onPointerDown,()=>{i.current===null&&(i.current=window.setInterval(r,50))}),onPointerMove:fe(o.onPointerMove,()=>{var u;(u=s.onItemLeave)==null||u.call(s),i.current===null&&(i.current=window.setInterval(r,50))}),onPointerLeave:fe(o.onPointerLeave,()=>{l()})})}),Ak="SelectSeparator",Jp=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e;return c.jsx(Ee.div,{"aria-hidden":!0,...r,ref:t})});Jp.displayName=Ak;var vl="SelectArrow",Nk=m.forwardRef((e,t)=>{const{__scopeSelect:n,...r}=e,o=fi(n),s=Jn(vl,n),i=Zn(vl,n);return s.open&&i.position==="popper"?c.jsx(Gf,{...o,...r,ref:t}):null});Nk.displayName=vl;var _k="SelectBubbleInput",Zp=m.forwardRef(({__scopeSelect:e,value:t,...n},r)=>{const o=m.useRef(null),s=Be(r,o),i=bp(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(Ee.select,{...n,style:{...Ip,...n.style},ref:s,defaultValue:t})});Zp.displayName=_k;function Qp(e){return e===""||e===void 0}function em(e){const t=Ct(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 tm(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=jk(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 jk(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var Rk=Ap,nm=_p,Pk=Rp,Ok=Pp,Mk=Op,rm=Mp,Dk=$p,om=Hp,sm=Wp,Lk=Vp,Fk=qp,im=Gp,am=Yp,lm=Jp;const cm=Rk,um=Pk,bl=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(nm,{ref:r,className:re("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(Ok,{asChild:!0,children:c.jsx(he.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));bl.displayName=nm.displayName;const dm=m.forwardRef(({className:e,...t},n)=>c.jsx(im,{ref:n,className:re("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(he.ChevronUp,{className:"h-4 w-4"})}));dm.displayName=im.displayName;const fm=m.forwardRef(({className:e,...t},n)=>c.jsx(am,{ref:n,className:re("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(he.ChevronDown,{className:"h-4 w-4"})}));fm.displayName=am.displayName;const wl=m.forwardRef(({className:e,children:t,position:n="popper",...r},o)=>c.jsx(Mk,{children:c.jsxs(rm,{ref:o,className:re("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(dm,{}),c.jsx(Dk,{className:re("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),c.jsx(fm,{})]})}));wl.displayName=rm.displayName;const $k=m.forwardRef(({className:e,...t},n)=>c.jsx(om,{ref:n,className:re("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));$k.displayName=om.displayName;const Sr=m.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(sm,{ref:r,className:re("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(Fk,{children:c.jsx(he.Check,{className:"h-4 w-4"})})}),c.jsx(Lk,{children:t})]}));Sr.displayName=sm.displayName;const zk=m.forwardRef(({className:e,...t},n)=>c.jsx(lm,{ref:n,className:re("-mx-1 my-1 h-px bg-muted",e),...t}));zk.displayName=lm.displayName;var Bk="Separator",hm="horizontal",Hk=["horizontal","vertical"],pm=m.forwardRef((e,t)=>{const{decorative:n,orientation:r=hm,...o}=e,s=Uk(r)?r:hm,a=n?{role:"none"}:{"aria-orientation":s==="vertical"?s:void 0,role:"separator"};return c.jsx(Ee.div,{"data-orientation":s,...a,...o,ref:t})});pm.displayName=Bk;function Uk(e){return Hk.includes(e)}var mm=pm;const gm=m.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},o)=>c.jsx(mm,{ref:o,decorative:n,orientation:t,className:re("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));gm.displayName=mm.displayName;const Wk=Zd,Vk=bw,Kk=Qd,xm=m.forwardRef(({className:e,...t},n)=>c.jsx(Ps,{className:re("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}));xm.displayName=Ps.displayName;const qk=Po.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"}}),ym=m.forwardRef(({side:e="right",className:t,children:n,...r},o)=>c.jsxs(Kk,{children:[c.jsx(xm,{}),c.jsxs(Os,{ref:o,className:re(qk({side:e}),t),...r,children:[n,c.jsxs(ef,{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(he.X,{className:"h-4 w-4"}),c.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));ym.displayName=Os.displayName;const vm=({className:e,...t})=>c.jsx("div",{className:re("flex flex-col space-y-2 text-center sm:text-left",e),...t});vm.displayName="SheetHeader";const bm=m.forwardRef(({className:e,...t},n)=>c.jsx(mr,{ref:n,className:re("text-lg font-semibold text-foreground",e),...t}));bm.displayName=mr.displayName;const wm=m.forwardRef(({className:e,...t},n)=>c.jsx(Ms,{ref:n,className:re("text-sm text-muted-foreground",e),...t}));wm.displayName=Ms.displayName;const Gk={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 Yk({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}=wa();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(Gk),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(Wk,{open:r,onOpenChange:o,children:[c.jsx(Vk,{asChild:!0,children:c.jsxs(Ve,{variant:"outline",size:"sm",className:n,children:[c.jsx(he.Settings,{className:"h-4 w-4 mr-2"}),"Settings",u&&c.jsx(Uu,{variant:"destructive",className:"ml-2 h-4 w-4 p-0"})]})}),c.jsxs(ym,{className:"w-[500px] sm:w-[600px] overflow-y-auto",children:[c.jsxs(vm,{children:[c.jsx(bm,{children:"Chat Settings"}),c.jsx(wm,{children:"Configure your chat interface, API connection, and behavior preferences."})]}),c.jsxs("div",{className:"space-y-6 py-6",children:[c.jsxs(fo,{children:[c.jsx(ho,{className:"pb-3",children:c.jsxs(po,{className:"text-lg flex items-center gap-2",children:[c.jsx(he.Server,{className:"h-5 w-5"}),"API Configuration"]})}),c.jsxs(mo,{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(oi,{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(Ve,{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(Xn,{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(oi,{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(Ve,{variant:"outline",size:"icon",onClick:()=>i(!s),children:s?c.jsx(he.EyeOff,{className:"h-4 w-4"}):c.jsx(he.Eye,{className:"h-4 w-4"})})]})]})]})]}),c.jsxs(fo,{children:[c.jsx(ho,{className:"pb-3",children:c.jsxs(po,{className:"text-lg flex items-center gap-2",children:[c.jsx(he.Layout,{className:"h-5 w-5"}),"Interface Settings"]})}),c.jsxs(mo,{className:"space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsx(tn,{htmlFor:"layout",children:"Layout Style"}),c.jsxs(cm,{value:a.ui.layout,onValueChange:g=>l(y=>({...y,ui:{...y.ui,layout:g}})),children:[c.jsx(bl,{children:c.jsx(um,{})}),c.jsxs(wl,{children:[c.jsx(Sr,{value:"sidebar",children:"Sidebar Layout"}),c.jsx(Sr,{value:"fullscreen",children:"Fullscreen"}),c.jsx(Sr,{value:"tabs",children:"Tabbed Interface"})]})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsx(tn,{htmlFor:"theme",children:"Theme"}),c.jsxs(cm,{value:a.ui.theme,onValueChange:g=>l(y=>({...y,ui:{...y.ui,theme:g}})),children:[c.jsx(bl,{children:c.jsx(um,{})}),c.jsxs(wl,{children:[c.jsx(Sr,{value:"light",children:"Light"}),c.jsx(Sr,{value:"dark",children:"Dark"}),c.jsx(Sr,{value:"system",children:"System"})]})]})]}),c.jsx(gm,{}),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(Xn,{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(Xn,{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(Xn,{id:"compact-messages",checked:a.ui.compactMessages,onCheckedChange:g=>l(y=>({...y,ui:{...y.ui,compactMessages:g}}))})]})]})]})]}),c.jsxs(fo,{children:[c.jsx(ho,{className:"pb-3",children:c.jsxs(po,{className:"text-lg flex items-center gap-2",children:[c.jsx(he.MessageCircle,{className:"h-5 w-5"}),"Behavior Settings"]})}),c.jsxs(mo,{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(Xn,{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(Xn,{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(Xn,{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(Ve,{variant:"outline",onClick:p,children:[c.jsx(he.RotateCcw,{className:"h-4 w-4 mr-2"}),"Reset"]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(Ve,{variant:"outline",onClick:v,children:"Cancel"}),c.jsxs(Ve,{onClick:h,disabled:!u,children:[c.jsx(he.Save,{className:"h-4 w-4 mr-2"}),"Save Changes"]})]})]})]})]})}function Xk({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(Zo,{...s,onThreadChange:l,children:c.jsx("div",{className:`${i(t)} flex flex-col overflow-hidden ${r} ${o.container||""}`,style:a(t),children:c.jsx(ri,{className:"flex-1",onError:s.onError,enableFileUpload:!0})})}):e==="tabs"?c.jsx(Zo,{...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(hl,{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(ri,{onError:s.onError,enableFileUpload:!0})})]})})}):c.jsx(Zo,{...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(hl,{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(ri,{onError:s.onError,enableFileUpload:!0})})]})})}Ae.ChatApi=vc,Ae.ChatInterface=ri,Ae.ChatProviders=Zo,Ae.ChatSettings=Yk,Ae.MarkdownContent=ya,Ae.MessageComponent=uf,Ae.MessageList=Da,Ae.ThreadManager=hl,Ae.applySettings=tk,Ae.chatApiClient=zn,Ae.default=Xk,Ae.del=yc,Ae.get=sn,Ae.getChatToken=pc,Ae.getCurrentSettings=ek,Ae.getDefaultApiConfig=mp,Ae.getDefaultChatSettings=gp,Ae.onChatTokenChanged=mc,Ae.post=gc,Ae.put=xc,Ae.setChatToken=Ai,Ae.useApi=Ni,Ae.useChatStream=Oc,Ae.useMessagesReducer=Ec,Ae.useStream=Uc,Ae.useThreadState=Jo,Ae.useThreads=Xo,Object.defineProperties(Ae,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|